Message ID | 20191118133816.3963-5-idryomov@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | wip-krbd-readonly | expand |
On 11/18/2019 09:38 PM, Ilya Dryomov wrote: > If an image is mapped read-only, don't allow setting its partition(s) > to read-write via BLKROSET: with the previous patch all writes to such > images are failed anyway. > > If an image is mapped read-write, its partition(s) can be set to > read-only (and back to read-write) as before. Note that at the rbd > level the image will remain writeable: anything sent down by the block > layer will be executed, including any write from internal kernel users. > > Signed-off-by: Ilya Dryomov <idryomov@gmail.com> Reviewed-by: Dongsheng Yang <dongsheng.yang@easystack.cn> > --- > drivers/block/rbd.c | 13 ++++++++++--- > 1 file changed, 10 insertions(+), 3 deletions(-) > > diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c > index 842b92ef2c06..979203cd934c 100644 > --- a/drivers/block/rbd.c > +++ b/drivers/block/rbd.c > @@ -706,9 +706,16 @@ static int rbd_ioctl_set_ro(struct rbd_device *rbd_dev, unsigned long arg) > if (get_user(ro, (int __user *)arg)) > return -EFAULT; > > - /* Snapshots can't be marked read-write */ > - if (rbd_is_snap(rbd_dev) && !ro) > - return -EROFS; > + /* > + * Both images mapped read-only and snapshots can't be marked > + * read-write. > + */ > + if (!ro) { > + if (rbd_is_ro(rbd_dev)) > + return -EROFS; > + > + rbd_assert(!rbd_is_snap(rbd_dev)); > + } > > /* Let blkdev_roset() handle it */ > return -ENOTTY;
diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index 842b92ef2c06..979203cd934c 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -706,9 +706,16 @@ static int rbd_ioctl_set_ro(struct rbd_device *rbd_dev, unsigned long arg) if (get_user(ro, (int __user *)arg)) return -EFAULT; - /* Snapshots can't be marked read-write */ - if (rbd_is_snap(rbd_dev) && !ro) - return -EROFS; + /* + * Both images mapped read-only and snapshots can't be marked + * read-write. + */ + if (!ro) { + if (rbd_is_ro(rbd_dev)) + return -EROFS; + + rbd_assert(!rbd_is_snap(rbd_dev)); + } /* Let blkdev_roset() handle it */ return -ENOTTY;
If an image is mapped read-only, don't allow setting its partition(s) to read-write via BLKROSET: with the previous patch all writes to such images are failed anyway. If an image is mapped read-write, its partition(s) can be set to read-only (and back to read-write) as before. Note that at the rbd level the image will remain writeable: anything sent down by the block layer will be executed, including any write from internal kernel users. Signed-off-by: Ilya Dryomov <idryomov@gmail.com> --- drivers/block/rbd.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)