diff options
author | Alex Elder <elder@inktank.com> | 2012-07-10 21:30:11 -0400 |
---|---|---|
committer | Alex Elder <elder@inktank.com> | 2012-10-01 15:30:52 -0400 |
commit | e86924a8092fda66b859f12a4d7d37a4a458d74a (patch) | |
tree | f6b012ea7de1127798d08969e4f9b09cf9989175 /drivers/block/rbd.c | |
parent | cd789ab9cacbda1aad43304b89cff29004b793ea (diff) |
rbd: use snaps list in rbd_snap_by_name()
An rbd_dev structure maintains a list of current snapshots that have
already been fully initialized. The entries on the list have type
struct rbd_snap, and each entry contains a copy of information
that's found in the rbd_dev's snapshot context and header.
The only caller of snap_by_name() is rbd_header_set_snap(). In that
call site any positive return value (the index in the snapshot
array) is ignored, so there's no need to return the index in
the snapshot context's id array when it's found.
rbd_header_set_snap() also has only one caller--rbd_add()--and that
call is made after a call to rbd_dev_snap_devs_update(). Because
the rbd_snap structures are initialized in that function, the
current snapshot list can be used instead of the snapshot context to
look up a snapshot's information by name.
Change snap_by_name() so it uses the snapshot list rather than the
rbd_dev's snapshot context in looking up snapshot information.
Return 0 if it's found rather than the snapshot id.
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 | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index 144694ee03a5..1ecdeb15b618 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c | |||
@@ -623,23 +623,18 @@ out_err: | |||
623 | 623 | ||
624 | static int snap_by_name(struct rbd_device *rbd_dev, const char *snap_name) | 624 | static int snap_by_name(struct rbd_device *rbd_dev, const char *snap_name) |
625 | { | 625 | { |
626 | int i; | ||
627 | struct rbd_image_header *header = &rbd_dev->header; | ||
628 | char *p = header->snap_names; | ||
629 | |||
630 | rbd_assert(header->snapc != NULL); | ||
631 | for (i = 0; i < header->snapc->num_snaps; i++) { | ||
632 | if (!strcmp(snap_name, p)) { | ||
633 | 626 | ||
634 | /* Found it. Pass back its id and/or size */ | 627 | struct rbd_snap *snap; |
635 | 628 | ||
636 | rbd_dev->mapping.snap_id = header->snapc->snaps[i]; | 629 | list_for_each_entry(snap, &rbd_dev->snaps, node) { |
637 | rbd_dev->mapping.size = header->snap_sizes[i]; | 630 | if (!strcmp(snap_name, snap->name)) { |
631 | rbd_dev->mapping.snap_id = snap->id; | ||
632 | rbd_dev->mapping.size = snap->size; | ||
638 | 633 | ||
639 | return i; | 634 | return 0; |
640 | } | 635 | } |
641 | p += strlen(p) + 1; /* Skip ahead to the next name */ | ||
642 | } | 636 | } |
637 | |||
643 | return -ENOENT; | 638 | return -ENOENT; |
644 | } | 639 | } |
645 | 640 | ||
@@ -653,6 +648,7 @@ static int rbd_header_set_snap(struct rbd_device *rbd_dev, char *snap_name) | |||
653 | rbd_dev->mapping.size = rbd_dev->header.image_size; | 648 | rbd_dev->mapping.size = rbd_dev->header.image_size; |
654 | rbd_dev->mapping.snap_exists = false; | 649 | rbd_dev->mapping.snap_exists = false; |
655 | rbd_dev->mapping.read_only = rbd_dev->rbd_opts.read_only; | 650 | rbd_dev->mapping.read_only = rbd_dev->rbd_opts.read_only; |
651 | ret = 0; | ||
656 | } else { | 652 | } else { |
657 | ret = snap_by_name(rbd_dev, snap_name); | 653 | ret = snap_by_name(rbd_dev, snap_name); |
658 | if (ret < 0) | 654 | if (ret < 0) |
@@ -661,8 +657,6 @@ static int rbd_header_set_snap(struct rbd_device *rbd_dev, char *snap_name) | |||
661 | rbd_dev->mapping.read_only = true; | 657 | rbd_dev->mapping.read_only = true; |
662 | } | 658 | } |
663 | rbd_dev->mapping.snap_name = snap_name; | 659 | rbd_dev->mapping.snap_name = snap_name; |
664 | |||
665 | ret = 0; | ||
666 | done: | 660 | done: |
667 | return ret; | 661 | return ret; |
668 | } | 662 | } |