aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/block/rbd.c
diff options
context:
space:
mode:
authorJosh Durgin <josh.durgin@dreamhost.com>2011-11-21 21:19:13 -0500
committerAlex Elder <elder@dreamhost.com>2012-03-22 11:47:47 -0400
commitcc9d734c3d1b39c6a557673469aea26364060226 (patch)
tree67cc35424a31e6be289f118732f45e15c9432dad /drivers/block/rbd.c
parent1dbb439913f0fc0bc30d36411a4a3b3202c0aab1 (diff)
rbd: use a single value of snap_name to mean no snap
There's already a constant for this anyway. Since rbd_header_set_snap() is only used to set the rbd device snap_name field, just do that within that function rather than having it take the snap_name as an argument. Signed-off-by: Alex Elder <elder@dreamhost.com> Signed-off-by: Sage Weil <sage@newdream.net> v2: Changed interface rbd_header_set_snap() so it explicitly updates the snap_name in the rbd_device. Also added a BUILD_BUG_ON() to verify the size of the snap_name field is sufficient for SNAP_HEAD_NAME.
Diffstat (limited to 'drivers/block/rbd.c')
-rw-r--r--drivers/block/rbd.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index dcdfe8dbf4f1..d8d052d42258 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -553,20 +553,18 @@ static int snap_by_name(struct rbd_image_header *header, const char *snap_name,
553 return i; 553 return i;
554} 554}
555 555
556static int rbd_header_set_snap(struct rbd_device *dev, 556static int rbd_header_set_snap(struct rbd_device *dev, u64 *size)
557 const char *snap_name,
558 u64 *size)
559{ 557{
560 struct rbd_image_header *header = &dev->header; 558 struct rbd_image_header *header = &dev->header;
561 struct ceph_snap_context *snapc = header->snapc; 559 struct ceph_snap_context *snapc = header->snapc;
562 int ret = -ENOENT; 560 int ret = -ENOENT;
563 561
562 BUILD_BUG_ON(sizeof (dev->snap_name) < sizeof (RBD_SNAP_HEAD_NAME));
563
564 down_write(&header->snap_rwsem); 564 down_write(&header->snap_rwsem);
565 565
566 if (!snap_name || 566 if (!memcmp(dev->snap_name, RBD_SNAP_HEAD_NAME,
567 !*snap_name || 567 sizeof (RBD_SNAP_HEAD_NAME))) {
568 strcmp(snap_name, "-") == 0 ||
569 strcmp(snap_name, RBD_SNAP_HEAD_NAME) == 0) {
570 if (header->total_snaps) 568 if (header->total_snaps)
571 snapc->seq = header->snap_seq; 569 snapc->seq = header->snap_seq;
572 else 570 else
@@ -576,7 +574,7 @@ static int rbd_header_set_snap(struct rbd_device *dev,
576 if (size) 574 if (size)
577 *size = header->image_size; 575 *size = header->image_size;
578 } else { 576 } else {
579 ret = snap_by_name(header, snap_name, &snapc->seq, size); 577 ret = snap_by_name(header, dev->snap_name, &snapc->seq, size);
580 if (ret < 0) 578 if (ret < 0)
581 goto done; 579 goto done;
582 580
@@ -1729,7 +1727,7 @@ static int rbd_init_disk(struct rbd_device *rbd_dev)
1729 if (rc) 1727 if (rc)
1730 return rc; 1728 return rc;
1731 1729
1732 rc = rbd_header_set_snap(rbd_dev, rbd_dev->snap_name, &total_size); 1730 rc = rbd_header_set_snap(rbd_dev, &total_size);
1733 if (rc) 1731 if (rc)
1734 return rc; 1732 return rc;
1735 1733
@@ -2215,7 +2213,8 @@ static ssize_t rbd_add(struct bus_type *bus,
2215 } 2213 }
2216 2214
2217 if (rbd_dev->snap_name[0] == 0) 2215 if (rbd_dev->snap_name[0] == 0)
2218 rbd_dev->snap_name[0] = '-'; 2216 memcpy(rbd_dev->snap_name, RBD_SNAP_HEAD_NAME,
2217 sizeof (RBD_SNAP_HEAD_NAME));
2219 2218
2220 rbd_dev->obj_len = strlen(rbd_dev->obj); 2219 rbd_dev->obj_len = strlen(rbd_dev->obj);
2221 snprintf(rbd_dev->obj_md_name, sizeof(rbd_dev->obj_md_name), "%s%s", 2220 snprintf(rbd_dev->obj_md_name, sizeof(rbd_dev->obj_md_name), "%s%s",