Commit 77dfe99f authored by Josh Durgin's avatar Josh Durgin Committed by Alex Elder

rbd: store snapshot id instead of index

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: default avatarJosh Durgin <josh.durgin@dreamhost.com>
Reviewed-by: default avatarAlex Elder <elder@dreamhost.com>
Reviewed-by: default avatarYehuda Sadeh <yehuda@hq.newdream.net>
parent 403f24d3
...@@ -175,8 +175,7 @@ struct rbd_device { ...@@ -175,8 +175,7 @@ struct rbd_device {
/* protects updating the header */ /* protects updating the header */
struct rw_semaphore header_rwsem; struct rw_semaphore header_rwsem;
char snap_name[RBD_MAX_SNAP_NAME_LEN]; char snap_name[RBD_MAX_SNAP_NAME_LEN];
u32 cur_snap; /* index+1 of current snapshot within snap context u64 snap_id; /* current snapshot id */
0 - for the head */
int read_only; int read_only;
struct list_head node; struct list_head node;
...@@ -554,21 +553,6 @@ static int rbd_header_from_disk(struct rbd_image_header *header, ...@@ -554,21 +553,6 @@ static int rbd_header_from_disk(struct rbd_image_header *header,
return -ENOMEM; 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, static int snap_by_name(struct rbd_image_header *header, const char *snap_name,
u64 *seq, u64 *size) u64 *seq, u64 *size)
{ {
...@@ -607,7 +591,7 @@ static int rbd_header_set_snap(struct rbd_device *dev, u64 *size) ...@@ -607,7 +591,7 @@ static int rbd_header_set_snap(struct rbd_device *dev, u64 *size)
snapc->seq = header->snap_seq; snapc->seq = header->snap_seq;
else else
snapc->seq = 0; snapc->seq = 0;
dev->cur_snap = 0; dev->snap_id = CEPH_NOSNAP;
dev->read_only = 0; dev->read_only = 0;
if (size) if (size)
*size = header->image_size; *size = header->image_size;
...@@ -615,8 +599,7 @@ static int rbd_header_set_snap(struct rbd_device *dev, u64 *size) ...@@ -615,8 +599,7 @@ static int rbd_header_set_snap(struct rbd_device *dev, u64 *size)
ret = snap_by_name(header, dev->snap_name, &snapc->seq, size); ret = snap_by_name(header, dev->snap_name, &snapc->seq, size);
if (ret < 0) if (ret < 0)
goto done; goto done;
dev->snap_id = snapc->seq;
dev->cur_snap = header->total_snaps - ret;
dev->read_only = 1; dev->read_only = 1;
} }
...@@ -1522,7 +1505,7 @@ static void rbd_rq_fn(struct request_queue *q) ...@@ -1522,7 +1505,7 @@ static void rbd_rq_fn(struct request_queue *q)
coll, cur_seg); coll, cur_seg);
else else
rbd_req_read(rq, rbd_dev, rbd_req_read(rq, rbd_dev,
cur_snap_id(rbd_dev), rbd_dev->snap_id,
ofs, ofs,
op_size, bio, op_size, bio,
coll, cur_seg); coll, cur_seg);
...@@ -1657,7 +1640,7 @@ static int rbd_header_add_snap(struct rbd_device *dev, ...@@ -1657,7 +1640,7 @@ static int rbd_header_add_snap(struct rbd_device *dev,
struct ceph_mon_client *monc; struct ceph_mon_client *monc;
/* we should create a snapshot only if we're pointing at the head */ /* 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; return -EINVAL;
monc = &dev->rbd_client->client->monc; monc = &dev->rbd_client->client->monc;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment