From: Alex Elder <elder@inktank.com>
To: ceph-devel@vger.kernel.org
Subject: [PATCH 4/4] rbd: use snaps list in rbd_snap_by_name()
Date: Fri, 07 Sep 2012 09:50:34 -0500 [thread overview]
Message-ID: <504A09BA.5030203@inktank.com> (raw)
In-Reply-To: <504A090F.7000706@inktank.com>
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.
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. To do this,
change rbd_snap_by_name() to take an rbd_dev rather than
rbd_image_header structure pointer as its first argument.
No caller ever passes a null pointer to snap_by_name() for the
snapshot id or the size, so just assign using those pointers
unconditionally.
Signed-off-by: Alex Elder <elder@inktank.com>
---
drivers/block/rbd.c | 19 +++++++------------
1 file changed, 7 insertions(+), 12 deletions(-)
diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index e922989..4dff92f 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -623,23 +623,18 @@ out_err:
static int snap_by_name(struct rbd_device *rbd_dev, const char *snap_name)
{
- int i;
- struct rbd_image_header *header = &rbd_dev->header;
- char *p = header->snap_names;
-
- rbd_assert(header->snapc != NULL);
- for (i = 0; i < header->snapc->num_snaps; i++) {
- if (!strcmp(snap_name, p)) {
- /* Found it. Pass back its id and/or size */
+ struct rbd_snap *snap;
- rbd_dev->mapping.snap_id = header->snapc->snaps[i];
- rbd_dev->mapping.size = header->snap_sizes[i];
+ list_for_each_entry(snap, &rbd_dev->snaps, node) {
+ if (!strcmp(snap_name, snap->name)) {
+ rbd_dev->mapping.snap_id = snap->id;
+ rbd_dev->mapping.size = snap->size;
- return i;
+ return 0;
}
- p += strlen(p) + 1; /* Skip ahead to the next name */
}
+
return -ENOENT;
}
--
1.7.9.5
next prev parent reply other threads:[~2012-09-07 14:50 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-07 14:47 [PATCH 0/4] rbd: locking, snapshot registration, snap_by_name() Alex Elder
2012-09-07 14:50 ` [PATCH 1/4] rbd: move locking out of rbd_header_set_snap() Alex Elder
2012-09-10 21:57 ` Josh Durgin
2012-09-07 14:50 ` [PATCH 2/4] rbd: expand lock protection in rbd_add() Alex Elder
2012-09-10 22:05 ` Josh Durgin
2012-09-11 13:52 ` Alex Elder
2012-09-11 14:33 ` Josh Durgin
2012-09-07 14:50 ` [PATCH 3/4] rbd: don't register snapshots in bus_add_dev() Alex Elder
2012-09-10 22:21 ` Josh Durgin
2012-09-07 14:50 ` Alex Elder [this message]
2012-09-10 22:32 ` [PATCH 4/4] rbd: use snaps list in rbd_snap_by_name() Josh Durgin
2012-09-11 14:05 ` Alex Elder
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=504A09BA.5030203@inktank.com \
--to=elder@inktank.com \
--cc=ceph-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox