aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/block/rbd.c
diff options
context:
space:
mode:
authorAlex Elder <elder@dreamhost.com>2012-01-24 11:08:36 -0500
committerAlex Elder <elder@dreamhost.com>2012-03-22 11:47:46 -0400
commit2107978668de13da484f7abc3f03516494c7fca9 (patch)
tree0b3d054845849b221ffed4aad38a3e7449121e79 /drivers/block/rbd.c
parent18fa8b3feaac772925263b04b1429d80e2dfd779 (diff)
rbd: a few small cleanups
Some minor cleanups in "drivers/block/rbd.c: - Use the more meaningful "RBD_MAX_OBJ_NAME_LEN" in place if "96" in the definition of RBD_MAX_MD_NAME_LEN. - Use DEFINE_SPINLOCK() to define and initialize node_lock. - Drop a needless (char *) cast in parse_rbd_opts_token(). - Make a few minor formatting changes. Signed-off-by: Alex Elder <elder@dreamhost.com> Signed-off-by: Sage Weil <sage@newdream.net>
Diffstat (limited to 'drivers/block/rbd.c')
-rw-r--r--drivers/block/rbd.c21
1 files changed, 9 insertions, 12 deletions
diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index a6278e7e61a0..b9371f0b9532 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -46,7 +46,7 @@
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
49#define RBD_MAX_MD_NAME_LEN (96 + sizeof(RBD_SUFFIX)) 49#define RBD_MAX_MD_NAME_LEN (RBD_MAX_OBJ_NAME_LEN + sizeof(RBD_SUFFIX))
50#define RBD_MAX_POOL_NAME_LEN 64 50#define RBD_MAX_POOL_NAME_LEN 64
51#define RBD_MAX_SNAP_NAME_LEN 32 51#define RBD_MAX_SNAP_NAME_LEN 32
52#define RBD_MAX_OPT_LEN 1024 52#define RBD_MAX_OPT_LEN 1024
@@ -175,7 +175,7 @@ static struct bus_type rbd_bus_type = {
175 .name = "rbd", 175 .name = "rbd",
176}; 176};
177 177
178static spinlock_t node_lock; /* protects client get/put */ 178static DEFINE_SPINLOCK(node_lock); /* protects client get/put */
179 179
180static DEFINE_MUTEX(ctl_mutex); /* Serialize open/close/setup/teardown */ 180static DEFINE_MUTEX(ctl_mutex); /* Serialize open/close/setup/teardown */
181static LIST_HEAD(rbd_dev_list); /* devices */ 181static LIST_HEAD(rbd_dev_list); /* devices */
@@ -324,7 +324,7 @@ static int parse_rbd_opts_token(char *c, void *private)
324 substring_t argstr[MAX_OPT_ARGS]; 324 substring_t argstr[MAX_OPT_ARGS];
325 int token, intval, ret; 325 int token, intval, ret;
326 326
327 token = match_token((char *)c, rbdopt_tokens, argstr); 327 token = match_token(c, rbdopt_tokens, argstr);
328 if (token < 0) 328 if (token < 0)
329 return -EINVAL; 329 return -EINVAL;
330 330
@@ -372,7 +372,8 @@ static int rbd_get_client(struct rbd_device *rbd_dev, const char *mon_addr,
372 rbd_opts->notify_timeout = RBD_NOTIFY_TIMEOUT_DEFAULT; 372 rbd_opts->notify_timeout = RBD_NOTIFY_TIMEOUT_DEFAULT;
373 373
374 ret = ceph_parse_options(&opt, options, mon_addr, 374 ret = ceph_parse_options(&opt, options, mon_addr,
375 mon_addr + strlen(mon_addr), parse_rbd_opts_token, rbd_opts); 375 mon_addr + strlen(mon_addr),
376 parse_rbd_opts_token, rbd_opts);
376 if (ret < 0) 377 if (ret < 0)
377 goto done_err; 378 goto done_err;
378 379
@@ -460,15 +461,13 @@ static int rbd_header_from_disk(struct rbd_image_header *header,
460 u32 snap_count = le32_to_cpu(ondisk->snap_count); 461 u32 snap_count = le32_to_cpu(ondisk->snap_count);
461 int ret = -ENOMEM; 462 int ret = -ENOMEM;
462 463
463 if (memcmp(ondisk, RBD_HEADER_TEXT, sizeof(RBD_HEADER_TEXT))) { 464 if (memcmp(ondisk, RBD_HEADER_TEXT, sizeof(RBD_HEADER_TEXT)))
464 return -ENXIO; 465 return -ENXIO;
465 }
466 466
467 init_rwsem(&header->snap_rwsem); 467 init_rwsem(&header->snap_rwsem);
468 header->snap_names_len = le64_to_cpu(ondisk->snap_names_len); 468 header->snap_names_len = le64_to_cpu(ondisk->snap_names_len);
469 header->snapc = kmalloc(sizeof(struct ceph_snap_context) + 469 header->snapc = kmalloc(sizeof(struct ceph_snap_context) +
470 snap_count * 470 snap_count * sizeof (*ondisk),
471 sizeof(struct rbd_image_snap_ondisk),
472 gfp_flags); 471 gfp_flags);
473 if (!header->snapc) 472 if (!header->snapc)
474 return -ENOMEM; 473 return -ENOMEM;
@@ -498,8 +497,7 @@ static int rbd_header_from_disk(struct rbd_image_header *header,
498 header->snapc->num_snaps = snap_count; 497 header->snapc->num_snaps = snap_count;
499 header->total_snaps = snap_count; 498 header->total_snaps = snap_count;
500 499
501 if (snap_count && 500 if (snap_count && allocated_snaps == snap_count) {
502 allocated_snaps == snap_count) {
503 for (i = 0; i < snap_count; i++) { 501 for (i = 0; i < snap_count; i++) {
504 header->snapc->snaps[i] = 502 header->snapc->snaps[i] =
505 le64_to_cpu(ondisk->snaps[i].id); 503 le64_to_cpu(ondisk->snaps[i].id);
@@ -2423,7 +2421,7 @@ static int rbd_sysfs_init(void)
2423 rbd_bus_type.bus_attrs = rbd_bus_attrs; 2421 rbd_bus_type.bus_attrs = rbd_bus_attrs;
2424 2422
2425 ret = bus_register(&rbd_bus_type); 2423 ret = bus_register(&rbd_bus_type);
2426 if (ret < 0) 2424 if (ret < 0)
2427 return ret; 2425 return ret;
2428 2426
2429 ret = device_register(&rbd_root_dev); 2427 ret = device_register(&rbd_root_dev);
@@ -2444,7 +2442,6 @@ int __init rbd_init(void)
2444 rc = rbd_sysfs_init(); 2442 rc = rbd_sysfs_init();
2445 if (rc) 2443 if (rc)
2446 return rc; 2444 return rc;
2447 spin_lock_init(&node_lock);
2448 pr_info("loaded " DRV_NAME_LONG "\n"); 2445 pr_info("loaded " DRV_NAME_LONG "\n");
2449 return 0; 2446 return 0;
2450} 2447}