rbd: make ceph_parse_options() return a pointer
authorAlex Elder <elder@dreamhost.com>
Tue, 24 Jan 2012 16:08:36 +0000 (10:08 -0600)
committerAlex Elder <elder@dreamhost.com>
Thu, 22 Mar 2012 15:47:47 +0000 (10:47 -0500)
ceph_parse_options() takes the address of a pointer as an argument
and uses it to return the address of an allocated structure if
successful.  With this interface is not evident at call sites that
the pointer is always initialized.  Change the interface to return
the address instead (or a pointer-coded error code) to make the
validity of the returned pointer obvious.

Signed-off-by: Alex Elder <elder@dreamhost.com>
Signed-off-by: Sage Weil <sage@newdream.net>
drivers/block/rbd.c
fs/ceph/super.c
include/linux/ceph/libceph.h
net/ceph/ceph_common.c

index b9371f0b9532f293ad9eb702d4a52850813f3dba..ed6711e35323e9e2aa40b3808237a5143e92554c 100644 (file)
@@ -371,11 +371,13 @@ static int rbd_get_client(struct rbd_device *rbd_dev, const char *mon_addr,
 
        rbd_opts->notify_timeout = RBD_NOTIFY_TIMEOUT_DEFAULT;
 
-       ret = ceph_parse_options(&opt, options, mon_addr,
+       opt = ceph_parse_options(options, mon_addr,
                                mon_addr + strlen(mon_addr),
                                parse_rbd_opts_token, rbd_opts);
-       if (ret < 0)
+       if (IS_ERR(opt)) {
+               ret = PTR_ERR(opt);
                goto done_err;
+       }
 
        spin_lock(&node_lock);
        rbdc = __rbd_client_find(opt);
index c3da3b32bddedcaa3b9eb551b0acfae017d47cd1..4fab1fdcfa6a9521aba7bf14032001c0c3256e98 100644 (file)
@@ -334,10 +334,12 @@ static int parse_mount_options(struct ceph_mount_options **pfsopt,
        *path += 2;
        dout("server path '%s'\n", *path);
 
-       err = ceph_parse_options(popt, options, dev_name, dev_name_end,
+       *popt = ceph_parse_options(options, dev_name, dev_name_end,
                                 parse_fsopt_token, (void *)fsopt);
-       if (err)
+       if (IS_ERR(*popt)) {
+               err = PTR_ERR(*popt);
                goto out;
+       }
 
        /* success */
        *pfsopt = fsopt;
index 95bd8502e715e48f8222345e1274761fee030662..92eef7c3d3c5e4b983fdcf1815b8a4d07b335d4b 100644 (file)
@@ -207,7 +207,7 @@ extern struct kmem_cache *ceph_cap_cachep;
 extern struct kmem_cache *ceph_dentry_cachep;
 extern struct kmem_cache *ceph_file_cachep;
 
-extern int ceph_parse_options(struct ceph_options **popt, char *options,
+extern struct ceph_options *ceph_parse_options(char *options,
                              const char *dev_name, const char *dev_name_end,
                              int (*parse_extra_token)(char *c, void *private),
                              void *private);
index 761ad9d6cc3b12fc4d6d8c10022e4c877559f5c8..621c3221b3938c4452bb0e8d078e7bf77d2f0482 100644 (file)
@@ -277,10 +277,11 @@ out:
        return err;
 }
 
-int ceph_parse_options(struct ceph_options **popt, char *options,
-                      const char *dev_name, const char *dev_name_end,
-                      int (*parse_extra_token)(char *c, void *private),
-                      void *private)
+struct ceph_options *
+ceph_parse_options(char *options, const char *dev_name,
+                       const char *dev_name_end,
+                       int (*parse_extra_token)(char *c, void *private),
+                       void *private)
 {
        struct ceph_options *opt;
        const char *c;
@@ -289,7 +290,7 @@ int ceph_parse_options(struct ceph_options **popt, char *options,
 
        opt = kzalloc(sizeof(*opt), GFP_KERNEL);
        if (!opt)
-               return err;
+               return ERR_PTR(-ENOMEM);
        opt->mon_addr = kcalloc(CEPH_MAX_MON, sizeof(*opt->mon_addr),
                                GFP_KERNEL);
        if (!opt->mon_addr)
@@ -412,12 +413,11 @@ int ceph_parse_options(struct ceph_options **popt, char *options,
        }
 
        /* success */
-       *popt = opt;
-       return 0;
+       return opt;
 
 out:
        ceph_destroy_options(opt);
-       return err;
+       return ERR_PTR(err);
 }
 EXPORT_SYMBOL(ceph_parse_options);