From: Benjamin Marzinski <bmarzins@redhat.com> Date: Wed, 22 Apr 2009 15:57:22 -0500 Subject: [md] dm-mpath: propagate ioctl error codes Message-id: 20090422205722.GX15911@ether.msp.redhat.com O-Subject: [RHEL-5.4 PATCH] BZ#461469 dm-mpath: propagate ioctl error codes Bugzilla: 461469 RH-Acked-by: Rik van Riel <riel@redhat.com> RH-Acked-by: Alasdair G Kergon <agk@redhat.com> This is a trivial backport of an upstream patch that propagates errors from the multipath ctr function up to userspace. The multipath userspace tools can use them to make intelligent decisions if it fails to create a device. commit 01460f3520c100010aacc8f8500cafcb17ce4665 I verified that with this patch applied, attempts to create multipath devices on top of read-only block devices failed with errno=EROFS, which is helpful, instead of the generic errno=EINVAL, which isn't. -Ben Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com> diff --git a/drivers/md/dm-mpath.c b/drivers/md/dm-mpath.c index 54d7d8e..d466fd6 100644 --- a/drivers/md/dm-mpath.c +++ b/drivers/md/dm-mpath.c @@ -571,12 +571,12 @@ static struct pgpath *parse_path(struct arg_set *as, struct path_selector *ps, /* we need at least a path arg */ if (as->argc < 1) { ti->error = "no device given"; - return NULL; + return ERR_PTR(-EINVAL); } p = alloc_pgpath(); if (!p) - return NULL; + return ERR_PTR(-ENOMEM); r = dm_get_device(ti, shift(as), ti->begin, ti->len, dm_table_get_mode(ti->table), &p->path.dev); @@ -604,7 +604,7 @@ static struct pgpath *parse_path(struct arg_set *as, struct path_selector *ps, bad: free_pgpath(p); - return NULL; + return ERR_PTR(r); } static struct priority_group *parse_priority_group(struct arg_set *as, @@ -622,14 +622,14 @@ static struct priority_group *parse_priority_group(struct arg_set *as, if (as->argc < 2) { as->argc = 0; - ti->error = "not enough priority group aruments"; - return NULL; + ti->error = "not enough priority group arguments"; + return ERR_PTR(-EINVAL); } pg = alloc_priority_group(); if (!pg) { ti->error = "couldn't allocate priority group"; - return NULL; + return ERR_PTR(-ENOMEM); } pg->m = m; @@ -662,8 +662,10 @@ static struct priority_group *parse_priority_group(struct arg_set *as, path_args.argv = as->argv; pgpath = parse_path(&path_args, &pg->ps, ti); - if (!pgpath) + if (IS_ERR(pgpath)) { + r = PTR_ERR(pgpath); goto bad; + } pgpath->pg = pg; list_add_tail(&pgpath->list, &pg->pgpaths); @@ -674,7 +676,7 @@ static struct priority_group *parse_priority_group(struct arg_set *as, bad: free_priority_group(pg, ti); - return NULL; + return ERR_PTR(r); } static int parse_hw_handler(struct arg_set *as, struct multipath *m, @@ -824,8 +826,8 @@ static int multipath_ctr(struct dm_target *ti, unsigned int argc, struct priority_group *pg; pg = parse_priority_group(&as, m, ti); - if (!pg) { - r = -EINVAL; + if (IS_ERR(pg)) { + r = PTR_ERR(pg); goto bad; }