diff options
author | Alex Elder <elder@dreamhost.com> | 2012-01-29 14:57:44 -0500 |
---|---|---|
committer | Alex Elder <elder@dreamhost.com> | 2012-03-22 11:47:48 -0400 |
commit | f0f8cef5a30504eaeba5588a9115b46c824d91a3 (patch) | |
tree | fa7e9d2a8dfb9e15ab85bf92420527deea0bd3ef /drivers/block | |
parent | 432b858749631dc011ac919dace4b0705ba8cecf (diff) |
rbd: a few simple changes
Here are a few very simple cleanups:
- Add a "RBD_" prefix to the two driver name string definitions.
- Move the definition of struct rbd_request below struct rbd_req_coll
to avoid the need for an empty declaration of the latter.
- Move and group the definitions of rbd_root_dev_release() and
rbd_root_dev, as well as rbd_bus_type and rbd_bus_attrs[],
close to the top of the file. Arrange the latter so
rbd_bus_type.bus_attrs can be initialized statically.
- Get rid of an unnecessary local variable in rbd_open().
- Rework some hokey logic in rbd_bus_add_dev(), so the value of
"ret" at the end is either 0 or -ENOENT to avoid the need for
the code duplication that was there.
- Rename a goto target in rbd_add().
Signed-off-by: Alex Elder <elder@dreamhost.com>
Signed-off-by: Sage Weil <sage@newdream.net>
Diffstat (limited to 'drivers/block')
-rw-r--r-- | drivers/block/rbd.c | 107 |
1 files changed, 53 insertions, 54 deletions
diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index 92b8c374d84d..812fd38cba3d 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c | |||
@@ -41,8 +41,8 @@ | |||
41 | 41 | ||
42 | #include "rbd_types.h" | 42 | #include "rbd_types.h" |
43 | 43 | ||
44 | #define DRV_NAME "rbd" | 44 | #define RBD_DRV_NAME "rbd" |
45 | #define DRV_NAME_LONG "rbd (rados block device)" | 45 | #define RBD_DRV_NAME_LONG "rbd (rados block device)" |
46 | 46 | ||
47 | #define RBD_MINORS_PER_MAJOR 256 /* max minors per blkdev */ | 47 | #define RBD_MINORS_PER_MAJOR 256 /* max minors per blkdev */ |
48 | 48 | ||
@@ -83,7 +83,7 @@ struct rbd_options { | |||
83 | }; | 83 | }; |
84 | 84 | ||
85 | /* | 85 | /* |
86 | * an instance of the client. multiple devices may share a client. | 86 | * an instance of the client. multiple devices may share an rbd client. |
87 | */ | 87 | */ |
88 | struct rbd_client { | 88 | struct rbd_client { |
89 | struct ceph_client *client; | 89 | struct ceph_client *client; |
@@ -92,20 +92,9 @@ struct rbd_client { | |||
92 | struct list_head node; | 92 | struct list_head node; |
93 | }; | 93 | }; |
94 | 94 | ||
95 | struct rbd_req_coll; | ||
96 | |||
97 | /* | 95 | /* |
98 | * a single io request | 96 | * a request completion status |
99 | */ | 97 | */ |
100 | struct rbd_request { | ||
101 | struct request *rq; /* blk layer request */ | ||
102 | struct bio *bio; /* cloned bio */ | ||
103 | struct page **pages; /* list of used pages */ | ||
104 | u64 len; | ||
105 | int coll_index; | ||
106 | struct rbd_req_coll *coll; | ||
107 | }; | ||
108 | |||
109 | struct rbd_req_status { | 98 | struct rbd_req_status { |
110 | int done; | 99 | int done; |
111 | int rc; | 100 | int rc; |
@@ -122,6 +111,18 @@ struct rbd_req_coll { | |||
122 | struct rbd_req_status status[0]; | 111 | struct rbd_req_status status[0]; |
123 | }; | 112 | }; |
124 | 113 | ||
114 | /* | ||
115 | * a single io request | ||
116 | */ | ||
117 | struct rbd_request { | ||
118 | struct request *rq; /* blk layer request */ | ||
119 | struct bio *bio; /* cloned bio */ | ||
120 | struct page **pages; /* list of used pages */ | ||
121 | u64 len; | ||
122 | int coll_index; | ||
123 | struct rbd_req_coll *coll; | ||
124 | }; | ||
125 | |||
125 | struct rbd_snap { | 126 | struct rbd_snap { |
126 | struct device dev; | 127 | struct device dev; |
127 | const char *name; | 128 | const char *name; |
@@ -170,10 +171,6 @@ struct rbd_device { | |||
170 | struct device dev; | 171 | struct device dev; |
171 | }; | 172 | }; |
172 | 173 | ||
173 | static struct bus_type rbd_bus_type = { | ||
174 | .name = "rbd", | ||
175 | }; | ||
176 | |||
177 | static DEFINE_MUTEX(ctl_mutex); /* Serialize open/close/setup/teardown */ | 174 | static DEFINE_MUTEX(ctl_mutex); /* Serialize open/close/setup/teardown */ |
178 | 175 | ||
179 | static LIST_HEAD(rbd_dev_list); /* devices */ | 176 | static LIST_HEAD(rbd_dev_list); /* devices */ |
@@ -191,6 +188,31 @@ static ssize_t rbd_snap_add(struct device *dev, | |||
191 | static void __rbd_remove_snap_dev(struct rbd_device *rbd_dev, | 188 | static void __rbd_remove_snap_dev(struct rbd_device *rbd_dev, |
192 | struct rbd_snap *snap); | 189 | struct rbd_snap *snap); |
193 | 190 | ||
191 | static ssize_t rbd_add(struct bus_type *bus, const char *buf, | ||
192 | size_t count); | ||
193 | static ssize_t rbd_remove(struct bus_type *bus, const char *buf, | ||
194 | size_t count); | ||
195 | |||
196 | static struct bus_attribute rbd_bus_attrs[] = { | ||
197 | __ATTR(add, S_IWUSR, NULL, rbd_add), | ||
198 | __ATTR(remove, S_IWUSR, NULL, rbd_remove), | ||
199 | __ATTR_NULL | ||
200 | }; | ||
201 | |||
202 | static struct bus_type rbd_bus_type = { | ||
203 | .name = "rbd", | ||
204 | .bus_attrs = rbd_bus_attrs, | ||
205 | }; | ||
206 | |||
207 | static void rbd_root_dev_release(struct device *dev) | ||
208 | { | ||
209 | } | ||
210 | |||
211 | static struct device rbd_root_dev = { | ||
212 | .init_name = "rbd", | ||
213 | .release = rbd_root_dev_release, | ||
214 | }; | ||
215 | |||
194 | 216 | ||
195 | static struct rbd_device *dev_to_rbd(struct device *dev) | 217 | static struct rbd_device *dev_to_rbd(struct device *dev) |
196 | { | 218 | { |
@@ -211,8 +233,7 @@ static int __rbd_update_snaps(struct rbd_device *rbd_dev); | |||
211 | 233 | ||
212 | static int rbd_open(struct block_device *bdev, fmode_t mode) | 234 | static int rbd_open(struct block_device *bdev, fmode_t mode) |
213 | { | 235 | { |
214 | struct gendisk *disk = bdev->bd_disk; | 236 | struct rbd_device *rbd_dev = bdev->bd_disk->private_data; |
215 | struct rbd_device *rbd_dev = disk->private_data; | ||
216 | 237 | ||
217 | rbd_get_dev(rbd_dev); | 238 | rbd_get_dev(rbd_dev); |
218 | 239 | ||
@@ -1216,8 +1237,8 @@ static void rbd_watch_cb(u64 ver, u64 notify_id, u8 opcode, void *data) | |||
1216 | rc = __rbd_update_snaps(dev); | 1237 | rc = __rbd_update_snaps(dev); |
1217 | mutex_unlock(&ctl_mutex); | 1238 | mutex_unlock(&ctl_mutex); |
1218 | if (rc) | 1239 | if (rc) |
1219 | pr_warning(DRV_NAME "%d got notification but failed to update" | 1240 | pr_warning(RBD_DRV_NAME "%d got notification but failed to " |
1220 | " snaps: %d\n", dev->major, rc); | 1241 | " update snaps: %d\n", dev->major, rc); |
1221 | 1242 | ||
1222 | rbd_req_sync_notify_ack(dev, ver, notify_id, dev->obj_md_name); | 1243 | rbd_req_sync_notify_ack(dev, ver, notify_id, dev->obj_md_name); |
1223 | } | 1244 | } |
@@ -1747,7 +1768,7 @@ static int rbd_init_disk(struct rbd_device *rbd_dev) | |||
1747 | if (!disk) | 1768 | if (!disk) |
1748 | goto out; | 1769 | goto out; |
1749 | 1770 | ||
1750 | snprintf(disk->disk_name, sizeof(disk->disk_name), DRV_NAME "%d", | 1771 | snprintf(disk->disk_name, sizeof(disk->disk_name), RBD_DRV_NAME "%d", |
1751 | rbd_dev->id); | 1772 | rbd_dev->id); |
1752 | disk->major = rbd_dev->major; | 1773 | disk->major = rbd_dev->major; |
1753 | disk->first_minor = 0; | 1774 | disk->first_minor = 0; |
@@ -2093,19 +2114,9 @@ static int __rbd_init_snaps_header(struct rbd_device *rbd_dev) | |||
2093 | return 0; | 2114 | return 0; |
2094 | } | 2115 | } |
2095 | 2116 | ||
2096 | |||
2097 | static void rbd_root_dev_release(struct device *dev) | ||
2098 | { | ||
2099 | } | ||
2100 | |||
2101 | static struct device rbd_root_dev = { | ||
2102 | .init_name = "rbd", | ||
2103 | .release = rbd_root_dev_release, | ||
2104 | }; | ||
2105 | |||
2106 | static int rbd_bus_add_dev(struct rbd_device *rbd_dev) | 2117 | static int rbd_bus_add_dev(struct rbd_device *rbd_dev) |
2107 | { | 2118 | { |
2108 | int ret = -ENOMEM; | 2119 | int ret; |
2109 | struct device *dev; | 2120 | struct device *dev; |
2110 | struct rbd_snap *snap; | 2121 | struct rbd_snap *snap; |
2111 | 2122 | ||
@@ -2119,7 +2130,7 @@ static int rbd_bus_add_dev(struct rbd_device *rbd_dev) | |||
2119 | dev_set_name(dev, "%d", rbd_dev->id); | 2130 | dev_set_name(dev, "%d", rbd_dev->id); |
2120 | ret = device_register(dev); | 2131 | ret = device_register(dev); |
2121 | if (ret < 0) | 2132 | if (ret < 0) |
2122 | goto done_free; | 2133 | goto out; |
2123 | 2134 | ||
2124 | list_for_each_entry(snap, &rbd_dev->snaps, node) { | 2135 | list_for_each_entry(snap, &rbd_dev->snaps, node) { |
2125 | ret = rbd_register_snap_dev(rbd_dev, snap, | 2136 | ret = rbd_register_snap_dev(rbd_dev, snap, |
@@ -2127,10 +2138,7 @@ static int rbd_bus_add_dev(struct rbd_device *rbd_dev) | |||
2127 | if (ret < 0) | 2138 | if (ret < 0) |
2128 | break; | 2139 | break; |
2129 | } | 2140 | } |
2130 | 2141 | out: | |
2131 | mutex_unlock(&ctl_mutex); | ||
2132 | return 0; | ||
2133 | done_free: | ||
2134 | mutex_unlock(&ctl_mutex); | 2142 | mutex_unlock(&ctl_mutex); |
2135 | return ret; | 2143 | return ret; |
2136 | } | 2144 | } |
@@ -2268,7 +2276,7 @@ static ssize_t rbd_add(struct bus_type *bus, | |||
2268 | mon_dev_name, options, rbd_dev->pool_name, | 2276 | mon_dev_name, options, rbd_dev->pool_name, |
2269 | rbd_dev->obj, rbd_dev->snap_name) < 4) { | 2277 | rbd_dev->obj, rbd_dev->snap_name) < 4) { |
2270 | rc = -EINVAL; | 2278 | rc = -EINVAL; |
2271 | goto err_out_slot; | 2279 | goto err_put_id; |
2272 | } | 2280 | } |
2273 | 2281 | ||
2274 | if (rbd_dev->snap_name[0] == 0) | 2282 | if (rbd_dev->snap_name[0] == 0) |
@@ -2280,11 +2288,11 @@ static ssize_t rbd_add(struct bus_type *bus, | |||
2280 | rbd_dev->obj, RBD_SUFFIX); | 2288 | rbd_dev->obj, RBD_SUFFIX); |
2281 | 2289 | ||
2282 | /* initialize rest of new object */ | 2290 | /* initialize rest of new object */ |
2283 | snprintf(rbd_dev->name, DEV_NAME_LEN, DRV_NAME "%d", rbd_dev->id); | 2291 | snprintf(rbd_dev->name, DEV_NAME_LEN, RBD_DRV_NAME "%d", rbd_dev->id); |
2284 | 2292 | ||
2285 | rc = rbd_get_client(rbd_dev, mon_dev_name, options); | 2293 | rc = rbd_get_client(rbd_dev, mon_dev_name, options); |
2286 | if (rc < 0) | 2294 | if (rc < 0) |
2287 | goto err_out_slot; | 2295 | goto err_put_id; |
2288 | 2296 | ||
2289 | /* pick the pool */ | 2297 | /* pick the pool */ |
2290 | osdc = &rbd_dev->rbd_client->client->osdc; | 2298 | osdc = &rbd_dev->rbd_client->client->osdc; |
@@ -2330,9 +2338,8 @@ err_out_blkdev: | |||
2330 | unregister_blkdev(rbd_dev->major, rbd_dev->name); | 2338 | unregister_blkdev(rbd_dev->major, rbd_dev->name); |
2331 | err_out_client: | 2339 | err_out_client: |
2332 | rbd_put_client(rbd_dev); | 2340 | rbd_put_client(rbd_dev); |
2333 | err_out_slot: | 2341 | err_put_id: |
2334 | rbd_id_put(rbd_dev); | 2342 | rbd_id_put(rbd_dev); |
2335 | |||
2336 | kfree(rbd_dev); | 2343 | kfree(rbd_dev); |
2337 | err_out_opt: | 2344 | err_out_opt: |
2338 | kfree(options); | 2345 | kfree(options); |
@@ -2463,12 +2470,6 @@ err_unlock: | |||
2463 | return ret; | 2470 | return ret; |
2464 | } | 2471 | } |
2465 | 2472 | ||
2466 | static struct bus_attribute rbd_bus_attrs[] = { | ||
2467 | __ATTR(add, S_IWUSR, NULL, rbd_add), | ||
2468 | __ATTR(remove, S_IWUSR, NULL, rbd_remove), | ||
2469 | __ATTR_NULL | ||
2470 | }; | ||
2471 | |||
2472 | /* | 2473 | /* |
2473 | * create control files in sysfs | 2474 | * create control files in sysfs |
2474 | * /sys/bus/rbd/... | 2475 | * /sys/bus/rbd/... |
@@ -2477,8 +2478,6 @@ static int rbd_sysfs_init(void) | |||
2477 | { | 2478 | { |
2478 | int ret; | 2479 | int ret; |
2479 | 2480 | ||
2480 | rbd_bus_type.bus_attrs = rbd_bus_attrs; | ||
2481 | |||
2482 | ret = bus_register(&rbd_bus_type); | 2481 | ret = bus_register(&rbd_bus_type); |
2483 | if (ret < 0) | 2482 | if (ret < 0) |
2484 | return ret; | 2483 | return ret; |
@@ -2501,7 +2500,7 @@ int __init rbd_init(void) | |||
2501 | rc = rbd_sysfs_init(); | 2500 | rc = rbd_sysfs_init(); |
2502 | if (rc) | 2501 | if (rc) |
2503 | return rc; | 2502 | return rc; |
2504 | pr_info("loaded " DRV_NAME_LONG "\n"); | 2503 | pr_info("loaded " RBD_DRV_NAME_LONG "\n"); |
2505 | return 0; | 2504 | return 0; |
2506 | } | 2505 | } |
2507 | 2506 | ||