If there is unsupported feature enabled after rbd map, we will noticed it in refreshing, then we need to set the disk readonly. For example, if we enabled the object-map feature after rbd map, as we don't support object-map in kernel rbd currently, we should avoid user to write rbd device. And set dist to read-write when we disable the unsupported features. Signed-off-by: Dongsheng Yang <dongsheng.yang@xxxxxxxxxxxx> --- V1: - set disk to read-write when we disabled the unsupported features. drivers/block/rbd.c | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index eb59b93..cf9c27a 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -753,6 +753,7 @@ enum { struct rbd_options { int queue_depth; bool read_only; + bool read_only_need_restore; bool lock_on_read; bool exclusive; }; @@ -4463,17 +4464,6 @@ static int _rbd_dev_v2_snap_features(struct rbd_device *rbd_dev, u64 snap_id, return 0; } -static int rbd_dev_v2_features(struct rbd_device *rbd_dev) -{ - u64 features = 0; - int ret = _rbd_dev_v2_snap_features(rbd_dev, CEPH_NOSNAP, features); - if (ret) - return ret - - rbd_dev->header.features = features - return 0; -} - static int rbd_dev_v2_parent_info(struct rbd_device *rbd_dev) { struct rbd_spec *parent_spec; @@ -4938,12 +4928,35 @@ static const char *rbd_dev_v2_snap_name(struct rbd_device *rbd_dev, static int rbd_dev_v2_header_info(struct rbd_device *rbd_dev) { bool first_time = rbd_dev->header.object_prefix == NULL; + u64 features = 0; int ret; ret = rbd_dev_v2_image_size(rbd_dev); if (ret) return ret; + ret = _rbd_dev_v2_snap_features(rbd_dev, CEPH_NOSNAP, + &features); + if (ret) { + if (-ENXIO == ret && !first_time) { + if (!rbd_dev->opts->read_only) { + rbd_dev->opts->read_only = true; + rbd_dev->opts->read_only_need_restore = true; + set_disk_ro(rbd_dev->disk, + rbd_dev->opts->read_only); + } + } else { + return ret; + } + } else { + if (rbd_dev->opts->read_only_need_restore) { + rbd_dev->opts->read_only = false; + rbd_dev->opts->read_only_need_restore = false; + set_disk_ro(rbd_dev->disk, rbd_dev->opts->read_only); + } + } + rbd_dev->mapping.features = rbd_dev->header.features = features; + if (first_time) { ret = rbd_dev_v2_header_onetime(rbd_dev); if (ret) @@ -5143,6 +5156,7 @@ static int rbd_add_parse_args(const char *buf, goto out_mem; rbd_opts->read_only = RBD_READ_ONLY_DEFAULT; + rbd_opts->read_only_need_restore = false; rbd_opts->queue_depth = RBD_QUEUE_DEPTH_DEFAULT; rbd_opts->lock_on_read = RBD_LOCK_ON_READ_DEFAULT; rbd_opts->exclusive = RBD_EXCLUSIVE_DEFAULT; @@ -5344,14 +5358,6 @@ static int rbd_dev_v2_header_onetime(struct rbd_device *rbd_dev) if (ret) goto out_err; - /* - * Get the and check features for the image. Currently the - * features are assumed to never change. - */ - ret = rbd_dev_v2_features(rbd_dev); - if (ret) - goto out_err; - /* If the image supports fancy striping, get its parameters */ if (rbd_dev->header.features & RBD_FEATURE_STRIPINGV2) { -- 1.8.3.1 -- To unsubscribe from this list: send the line "unsubscribe ceph-devel" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html