diff options
author | Alex Elder <elder@inktank.com> | 2012-10-26 00:34:41 -0400 |
---|---|---|
committer | Alex Elder <elder@inktank.com> | 2012-10-30 09:34:29 -0400 |
commit | 0ddebc0c6c518ae42c376151e34d9d4b84443ba5 (patch) | |
tree | c1e410f8b491832d0151967cb403638bee44c45d /drivers/block/rbd.c | |
parent | 78cea76e0580befaf561c6989f4fc985bc66c8f7 (diff) |
rbd: do all argument parsing in one place
This patch makes rbd_add_parse_args() be the single place all
argument parsing occurs for an image map request:
- Move the ceph_parse_options() call into that function
- Use local variables rather than parameters to hold the list
of monitor addresses supplied
- Rather than returning it, pass the snapshot name (and its
length) back via parameters
- Have the function return a ceph_options structure pointer
Signed-off-by: Alex Elder <elder@inktank.com>
Reviewed-by: Josh Durgin <josh.durgin@inktank.com>
Diffstat (limited to 'drivers/block/rbd.c')
-rw-r--r-- | drivers/block/rbd.c | 77 |
1 files changed, 37 insertions, 40 deletions
diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index e83bddcca34e..68447d83288c 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c | |||
@@ -2845,24 +2845,27 @@ static inline char *dup_token(const char **buf, size_t *lenp) | |||
2845 | * | 2845 | * |
2846 | * Note: rbd_dev is assumed to have been initially zero-filled. | 2846 | * Note: rbd_dev is assumed to have been initially zero-filled. |
2847 | */ | 2847 | */ |
2848 | static char *rbd_add_parse_args(struct rbd_device *rbd_dev, | 2848 | static struct ceph_options *rbd_add_parse_args(struct rbd_device *rbd_dev, |
2849 | const char *buf, | 2849 | const char *buf, |
2850 | const char **mon_addrs, | 2850 | char *options, |
2851 | size_t *mon_addrs_size, | 2851 | size_t options_size, |
2852 | char *options, | 2852 | char **snap_name, |
2853 | size_t options_size) | 2853 | size_t *snap_name_len) |
2854 | { | 2854 | { |
2855 | size_t len; | 2855 | size_t len; |
2856 | char *err_ptr = ERR_PTR(-EINVAL); | 2856 | const char *mon_addrs; |
2857 | char *snap_name; | 2857 | size_t mon_addrs_size; |
2858 | struct rbd_options rbd_opts; | ||
2859 | struct ceph_options *ceph_opts; | ||
2860 | struct ceph_options *err_ptr = ERR_PTR(-EINVAL); | ||
2858 | 2861 | ||
2859 | /* The first four tokens are required */ | 2862 | /* The first four tokens are required */ |
2860 | 2863 | ||
2861 | len = next_token(&buf); | 2864 | len = next_token(&buf); |
2862 | if (!len) | 2865 | if (!len) |
2863 | return err_ptr; | 2866 | return err_ptr; |
2864 | *mon_addrs_size = len + 1; | 2867 | mon_addrs_size = len + 1; |
2865 | *mon_addrs = buf; | 2868 | mon_addrs = buf; |
2866 | 2869 | ||
2867 | buf += len; | 2870 | buf += len; |
2868 | 2871 | ||
@@ -2890,14 +2893,27 @@ static char *rbd_add_parse_args(struct rbd_device *rbd_dev, | |||
2890 | buf = RBD_SNAP_HEAD_NAME; /* No snapshot supplied */ | 2893 | buf = RBD_SNAP_HEAD_NAME; /* No snapshot supplied */ |
2891 | len = sizeof (RBD_SNAP_HEAD_NAME) - 1; | 2894 | len = sizeof (RBD_SNAP_HEAD_NAME) - 1; |
2892 | } | 2895 | } |
2893 | snap_name = kmalloc(len + 1, GFP_KERNEL); | 2896 | *snap_name = kmalloc(len + 1, GFP_KERNEL); |
2894 | if (!snap_name) | 2897 | if (!*snap_name) |
2895 | goto out_err; | 2898 | goto out_err; |
2896 | memcpy(snap_name, buf, len); | 2899 | memcpy(*snap_name, buf, len); |
2897 | *(snap_name + len) = '\0'; | 2900 | *(*snap_name + len) = '\0'; |
2901 | *snap_name_len = len; | ||
2902 | /* Initialize all rbd options to the defaults */ | ||
2898 | 2903 | ||
2899 | return snap_name; | 2904 | rbd_opts.read_only = RBD_READ_ONLY_DEFAULT; |
2900 | 2905 | ||
2906 | ceph_opts = ceph_parse_options(options, mon_addrs, | ||
2907 | mon_addrs + mon_addrs_size - 1, | ||
2908 | parse_rbd_opts_token, &rbd_opts); | ||
2909 | |||
2910 | /* Record the parsed rbd options */ | ||
2911 | |||
2912 | if (!IS_ERR(ceph_opts)) { | ||
2913 | rbd_dev->mapping.read_only = rbd_opts.read_only; | ||
2914 | } | ||
2915 | |||
2916 | return ceph_opts; | ||
2901 | out_err: | 2917 | out_err: |
2902 | kfree(rbd_dev->image_name); | 2918 | kfree(rbd_dev->image_name); |
2903 | rbd_dev->image_name = NULL; | 2919 | rbd_dev->image_name = NULL; |
@@ -3114,10 +3130,8 @@ static ssize_t rbd_add(struct bus_type *bus, | |||
3114 | { | 3130 | { |
3115 | char *options; | 3131 | char *options; |
3116 | struct rbd_device *rbd_dev = NULL; | 3132 | struct rbd_device *rbd_dev = NULL; |
3117 | const char *mon_addrs = NULL; | ||
3118 | size_t mon_addrs_size = 0; | ||
3119 | char *snap_name; | 3133 | char *snap_name; |
3120 | struct rbd_options rbd_opts; | 3134 | size_t snap_name_len = 0; |
3121 | struct ceph_options *ceph_opts; | 3135 | struct ceph_options *ceph_opts; |
3122 | struct ceph_osd_client *osdc; | 3136 | struct ceph_osd_client *osdc; |
3123 | int rc = -ENOMEM; | 3137 | int rc = -ENOMEM; |
@@ -3139,32 +3153,16 @@ static ssize_t rbd_add(struct bus_type *bus, | |||
3139 | init_rwsem(&rbd_dev->header_rwsem); | 3153 | init_rwsem(&rbd_dev->header_rwsem); |
3140 | 3154 | ||
3141 | /* parse add command */ | 3155 | /* parse add command */ |
3142 | snap_name = rbd_add_parse_args(rbd_dev, buf, | 3156 | ceph_opts = rbd_add_parse_args(rbd_dev, buf, options, count, |
3143 | &mon_addrs, &mon_addrs_size, options, count); | 3157 | &snap_name, &snap_name_len); |
3144 | if (IS_ERR(snap_name)) { | ||
3145 | rc = PTR_ERR(snap_name); | ||
3146 | goto err_out_mem; | ||
3147 | } | ||
3148 | |||
3149 | /* Initialize all rbd options to the defaults */ | ||
3150 | |||
3151 | rbd_opts.read_only = RBD_READ_ONLY_DEFAULT; | ||
3152 | |||
3153 | ceph_opts = ceph_parse_options(options, mon_addrs, | ||
3154 | mon_addrs + mon_addrs_size - 1, | ||
3155 | parse_rbd_opts_token, &rbd_opts); | ||
3156 | if (IS_ERR(ceph_opts)) { | 3158 | if (IS_ERR(ceph_opts)) { |
3157 | rc = PTR_ERR(ceph_opts); | 3159 | rc = PTR_ERR(ceph_opts); |
3158 | goto err_out_args; | 3160 | goto err_out_mem; |
3159 | } | 3161 | } |
3160 | 3162 | ||
3161 | /* Record the parsed rbd options */ | ||
3162 | |||
3163 | rbd_dev->mapping.read_only = rbd_opts.read_only; | ||
3164 | |||
3165 | rc = rbd_get_client(rbd_dev, ceph_opts); | 3163 | rc = rbd_get_client(rbd_dev, ceph_opts); |
3166 | if (rc < 0) | 3164 | if (rc < 0) |
3167 | goto err_out_opts; | 3165 | goto err_out_args; |
3168 | ceph_opts = NULL; /* ceph_opts now owned by rbd_dev client */ | 3166 | ceph_opts = NULL; /* ceph_opts now owned by rbd_dev client */ |
3169 | 3167 | ||
3170 | /* pick the pool */ | 3168 | /* pick the pool */ |
@@ -3257,10 +3255,9 @@ err_out_client: | |||
3257 | kfree(rbd_dev->header_name); | 3255 | kfree(rbd_dev->header_name); |
3258 | rbd_put_client(rbd_dev); | 3256 | rbd_put_client(rbd_dev); |
3259 | kfree(rbd_dev->image_id); | 3257 | kfree(rbd_dev->image_id); |
3260 | err_out_opts: | 3258 | err_out_args: |
3261 | if (ceph_opts) | 3259 | if (ceph_opts) |
3262 | ceph_destroy_options(ceph_opts); | 3260 | ceph_destroy_options(ceph_opts); |
3263 | err_out_args: | ||
3264 | kfree(rbd_dev->snap_name); | 3261 | kfree(rbd_dev->snap_name); |
3265 | kfree(rbd_dev->image_name); | 3262 | kfree(rbd_dev->image_name); |
3266 | kfree(rbd_dev->pool_name); | 3263 | kfree(rbd_dev->pool_name); |