aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/block
diff options
context:
space:
mode:
authorAlex Elder <elder@inktank.com>2013-04-26 00:15:08 -0400
committerSage Weil <sage@inktank.com>2013-05-02 00:19:35 -0400
commit8b0241f85ab11c87075f9de0191acd8b546c6f6a (patch)
tree27c74b91be800ef974732473960bd4c3a7471c20 /drivers/block
parent5655c4d940ba8dd32250ab1e4ba3db785943a28e (diff)
rbd: have snap_by_name() return a snapshot
A function called snap_by_name() ought to just look up a snapshot by name. It does that, but then it assigns some stuff to the rbd device structure as well. Change the function to do just the lookup, and have the caller do the assignments that follow. Signed-off-by: Alex Elder <elder@inktank.com> Reviewed-by: Josh Durgin <josh.durgin@inktank.com>
Diffstat (limited to 'drivers/block')
-rw-r--r--drivers/block/rbd.c35
1 files changed, 15 insertions, 20 deletions
diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index 815c174661a8..6b1e9a9f2f72 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -830,44 +830,39 @@ static const char *rbd_snap_name(struct rbd_device *rbd_dev, u64 snap_id)
830 return NULL; 830 return NULL;
831} 831}
832 832
833static int snap_by_name(struct rbd_device *rbd_dev, const char *snap_name) 833static struct rbd_snap *snap_by_name(struct rbd_device *rbd_dev,
834 const char *snap_name)
834{ 835{
835
836 struct rbd_snap *snap; 836 struct rbd_snap *snap;
837 837
838 list_for_each_entry(snap, &rbd_dev->snaps, node) { 838 list_for_each_entry(snap, &rbd_dev->snaps, node)
839 if (!strcmp(snap_name, snap->name)) { 839 if (!strcmp(snap_name, snap->name))
840 rbd_dev->spec->snap_id = snap->id; 840 return snap;
841 rbd_dev->mapping.size = snap->size;
842 rbd_dev->mapping.features = snap->features;
843
844 return 0;
845 }
846 }
847 841
848 return -ENOENT; 842 return NULL;
849} 843}
850 844
851static int rbd_dev_set_mapping(struct rbd_device *rbd_dev) 845static int rbd_dev_set_mapping(struct rbd_device *rbd_dev)
852{ 846{
853 int ret;
854
855 if (!memcmp(rbd_dev->spec->snap_name, RBD_SNAP_HEAD_NAME, 847 if (!memcmp(rbd_dev->spec->snap_name, RBD_SNAP_HEAD_NAME,
856 sizeof (RBD_SNAP_HEAD_NAME))) { 848 sizeof (RBD_SNAP_HEAD_NAME))) {
857 rbd_dev->spec->snap_id = CEPH_NOSNAP; 849 rbd_dev->spec->snap_id = CEPH_NOSNAP;
858 rbd_dev->mapping.size = rbd_dev->header.image_size; 850 rbd_dev->mapping.size = rbd_dev->header.image_size;
859 rbd_dev->mapping.features = rbd_dev->header.features; 851 rbd_dev->mapping.features = rbd_dev->header.features;
860 ret = 0;
861 } else { 852 } else {
862 ret = snap_by_name(rbd_dev, rbd_dev->spec->snap_name); 853 struct rbd_snap *snap;
863 if (ret < 0) 854
864 goto done; 855 snap = snap_by_name(rbd_dev, rbd_dev->spec->snap_name);
856 if (!snap)
857 return -ENOENT;
858 rbd_dev->spec->snap_id = snap->id;
859 rbd_dev->mapping.size = snap->size;
860 rbd_dev->mapping.features = snap->features;
865 rbd_dev->mapping.read_only = true; 861 rbd_dev->mapping.read_only = true;
866 } 862 }
867 set_bit(RBD_DEV_FLAG_EXISTS, &rbd_dev->flags); 863 set_bit(RBD_DEV_FLAG_EXISTS, &rbd_dev->flags);
868 864
869done: 865 return 0;
870 return ret;
871} 866}
872 867
873static void rbd_header_free(struct rbd_image_header *header) 868static void rbd_header_free(struct rbd_image_header *header)