From: Alex Elder <elder@dreamhost.com>
To: ceph-devel@vger.kernel.org
Subject: [PATCH 2/6] rbd: store snapshot id instead of index
Date: Wed, 18 Apr 2012 09:41:02 -0500 [thread overview]
Message-ID: <4F8ED27E.8020901@dreamhost.com> (raw)
In-Reply-To: <4F8ED154.6050500@dreamhost.com>
When a device was open at a snapshot, and snapshots were deleted or
added, data from the wrong snapshot could be read. Instead of
assuming the snap context is constant, store the actual snap id when
the device is initialized, and rely on the OSDs to signal an error
if we try reading from a snapshot that was deleted.
Signed-off-by: Josh Durgin <josh.durgin@dreamhost.com>
Reviewed-by: Alex Elder <elder@dreamhost.com>
---
drivers/block/rbd.c | 27 +++++----------------------
1 file changed, 5 insertions(+), 22 deletions(-)
Index: b/drivers/block/rbd.c
===================================================================
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -175,8 +175,7 @@
/* protects updating the header */
struct rw_semaphore header_rwsem;
char snap_name[RBD_MAX_SNAP_NAME_LEN];
- u32 cur_snap; /* index+1 of current snapshot within snap context
- 0 - for the head */
+ u64 snap_id; /* current snapshot id */
int read_only;
struct list_head node;
@@ -554,21 +553,6 @@
return -ENOMEM;
}
-static int snap_index(struct rbd_image_header *header, int snap_num)
-{
- return header->total_snaps - snap_num;
-}
-
-static u64 cur_snap_id(struct rbd_device *rbd_dev)
-{
- struct rbd_image_header *header = &rbd_dev->header;
-
- if (!rbd_dev->cur_snap)
- return 0;
-
- return header->snapc->snaps[snap_index(header, rbd_dev->cur_snap)];
-}
-
static int snap_by_name(struct rbd_image_header *header, const char
*snap_name,
u64 *seq, u64 *size)
{
@@ -607,7 +591,7 @@
snapc->seq = header->snap_seq;
else
snapc->seq = 0;
- dev->cur_snap = 0;
+ dev->snap_id = CEPH_NOSNAP;
dev->read_only = 0;
if (size)
*size = header->image_size;
@@ -615,8 +599,7 @@
ret = snap_by_name(header, dev->snap_name, &snapc->seq, size);
if (ret < 0)
goto done;
-
- dev->cur_snap = header->total_snaps - ret;
+ dev->snap_id = snapc->seq;
dev->read_only = 1;
}
@@ -1523,7 +1506,7 @@
coll, cur_seg);
else
rbd_req_read(rq, rbd_dev,
- cur_snap_id(rbd_dev),
+ rbd_dev->snap_id,
ofs,
op_size, bio,
coll, cur_seg);
@@ -1658,7 +1641,7 @@
struct ceph_mon_client *monc;
/* we should create a snapshot only if we're pointing at the head */
- if (dev->cur_snap)
+ if (dev->snap_id != CEPH_NOSNAP)
return -EINVAL;
monc = &dev->rbd_client->client->monc;
next prev parent reply other threads:[~2012-04-18 14:41 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-04-18 14:36 [PATCH 0/6] rbd: updates from Josh Durgin Alex Elder
2012-04-18 14:40 ` [PATCH 1/6] rbd: protect read of snapshot sequence number Alex Elder
2012-04-19 17:35 ` Yehuda Sadeh Weinraub
2012-04-18 14:41 ` Alex Elder [this message]
2012-04-19 17:41 ` [PATCH 2/6] rbd: store snapshot id instead of index Yehuda Sadeh Weinraub
2012-04-18 14:41 ` [PATCH 3/6] rbd: remove conditional snapid parameters Alex Elder
2012-04-19 17:58 ` Yehuda Sadeh Weinraub
2012-04-18 14:41 ` [PATCH 4/6] rbd: fix snapshot size type Alex Elder
2012-04-19 18:04 ` Yehuda Sadeh Weinraub
2012-04-18 14:41 ` [PATCH 5/6] rbd: rename __rbd_update_snaps to __rbd_refresh_header Alex Elder
2012-04-19 18:06 ` Yehuda Sadeh Weinraub
2012-04-18 14:41 ` [PATCH 6/6] rbd: correct sysfs snap attribute documentation Alex Elder
2012-04-19 18:07 ` Yehuda Sadeh Weinraub
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=4F8ED27E.8020901@dreamhost.com \
--to=elder@dreamhost.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.