@@ -4463,17 +4463,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 +4927,25 @@ 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) {
+ rbd_dev->opts->read_only = true;
+ set_disk_ro(rbd_dev->disk, rbd_dev->opts->read_only);
+ } else {
+ return ret;
+ }
+ }
+ rbd_dev->mapping.features = rbd_dev->header.features = features;
+
if (first_time) {
ret = rbd_dev_v2_header_onetime(rbd_dev);
if (ret)
@@ -5344,14 +5346,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) {
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. Signed-off-by: Dongsheng Yang <dongsheng.yang@easystack.cn> --- drivers/block/rbd.c | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-)