diff mbox

[1/2] rbd: clear EXISTS flag if mapped snapshot disappears

Message ID 518189F9.3070603@inktank.com (mailing list archive)
State New, archived
Headers show

Commit Message

Alex Elder May 1, 2013, 9:32 p.m. UTC
This functionality inadvertently disappeared in the last patch.

Image snapshots can get removed at just about any time.  In
particular it can disappear even if it is in use by an rbd
client as a mapped image.

The rbd client deals with such a disappearance by responding to new
requests with ENXIO.  This is implemented by each rbd device
maintaining an EXISTS flag, which is normally set but cleared if a
snapshot disappears.

This patch (re-)implements the clearing of that flag.

Whenever mapped image header information is refreshed, if the
mapping is for a snapshot, verify the mapped snapshot is still
present in the updated snapshot context.  If it is not, clear the
flag.

It is not necessary to check this in the initial probe, because the
probe will not succeed if the snapshot doesn't exist.

This resolves:
    http://tracker.ceph.com/issues/4880

Signed-off-by: Alex Elder <elder@inktank.com>
---
 drivers/block/rbd.c |   23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

 	u64 image_size;
@@ -3126,6 +3145,10 @@ static int rbd_dev_refresh(struct rbd_device
*rbd_dev)
 		ret = rbd_dev_v1_refresh(rbd_dev);
 	else
 		ret = rbd_dev_v2_refresh(rbd_dev);
+
+	/* If it's a mapped snapshot, validate its EXISTS flag */
+
+	rbd_exists_validate(rbd_dev);
 	mutex_unlock(&ctl_mutex);
 	if (ret)
 		rbd_warn(rbd_dev, "got notification but failed to "

Comments

Josh Durgin May 2, 2013, 4:41 p.m. UTC | #1
Reviewed-by: Josh Durgin <josh.durgin@inktank.com>

On 05/01/2013 02:32 PM, Alex Elder wrote:
> This functionality inadvertently disappeared in the last patch.
>
> Image snapshots can get removed at just about any time.  In
> particular it can disappear even if it is in use by an rbd
> client as a mapped image.
>
> The rbd client deals with such a disappearance by responding to new
> requests with ENXIO.  This is implemented by each rbd device
> maintaining an EXISTS flag, which is normally set but cleared if a
> snapshot disappears.
>
> This patch (re-)implements the clearing of that flag.
>
> Whenever mapped image header information is refreshed, if the
> mapping is for a snapshot, verify the mapped snapshot is still
> present in the updated snapshot context.  If it is not, clear the
> flag.
>
> It is not necessary to check this in the initial probe, because the
> probe will not succeed if the snapshot doesn't exist.
>
> This resolves:
>      http://tracker.ceph.com/issues/4880
>
> Signed-off-by: Alex Elder <elder@inktank.com>
> ---
>   drivers/block/rbd.c |   23 +++++++++++++++++++++++
>   1 file changed, 23 insertions(+)
>
> diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
> index 0ca959f..3f58aba 100644
> --- a/drivers/block/rbd.c
> +++ b/drivers/block/rbd.c
> @@ -3114,6 +3114,25 @@ static int rbd_dev_v1_refresh(struct rbd_device
> *rbd_dev)
>   	return ret;
>   }
>
> +/*
> + * Clear the rbd device's EXISTS flag if the snapshot it's mapped to
> + * has disappeared from the (just updated) snapshot context.
> + */
> +static void rbd_exists_validate(struct rbd_device *rbd_dev)
> +{
> +	u64 snap_id;
> +
> +	if (!test_bit(RBD_DEV_FLAG_EXISTS, &rbd_dev->flags))
> +		return;
> +
> +	snap_id = rbd_dev->spec->snap_id;
> +	if (snap_id == CEPH_NOSNAP)
> +		return;
> +
> +	if (rbd_dev_snap_index(rbd_dev, snap_id) == BAD_SNAP_INDEX)
> +		clear_bit(RBD_DEV_FLAG_EXISTS, &rbd_dev->flags);
> +}
> +
>   static int rbd_dev_refresh(struct rbd_device *rbd_dev)
>   {
>   	u64 image_size;
> @@ -3126,6 +3145,10 @@ static int rbd_dev_refresh(struct rbd_device
> *rbd_dev)
>   		ret = rbd_dev_v1_refresh(rbd_dev);
>   	else
>   		ret = rbd_dev_v2_refresh(rbd_dev);
> +
> +	/* If it's a mapped snapshot, validate its EXISTS flag */
> +
> +	rbd_exists_validate(rbd_dev);
>   	mutex_unlock(&ctl_mutex);
>   	if (ret)
>   		rbd_warn(rbd_dev, "got notification but failed to "
>

--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index 0ca959f..3f58aba 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -3114,6 +3114,25 @@  static int rbd_dev_v1_refresh(struct rbd_device
*rbd_dev)
 	return ret;
 }

+/*
+ * Clear the rbd device's EXISTS flag if the snapshot it's mapped to
+ * has disappeared from the (just updated) snapshot context.
+ */
+static void rbd_exists_validate(struct rbd_device *rbd_dev)
+{
+	u64 snap_id;
+
+	if (!test_bit(RBD_DEV_FLAG_EXISTS, &rbd_dev->flags))
+		return;
+
+	snap_id = rbd_dev->spec->snap_id;
+	if (snap_id == CEPH_NOSNAP)
+		return;
+
+	if (rbd_dev_snap_index(rbd_dev, snap_id) == BAD_SNAP_INDEX)
+		clear_bit(RBD_DEV_FLAG_EXISTS, &rbd_dev->flags);
+}
+
 static int rbd_dev_refresh(struct rbd_device *rbd_dev)
 {