rbd: introduce rbd_is_snap()

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
Reviewed-by: Jason Dillaman <dillaman@redhat.com>
Reviewed-by: Dongsheng Yang <dongsheng.yang@easystack.cn>
This commit is contained in:
Ilya Dryomov 2019-11-07 16:22:10 +01:00
parent 2def865a81
commit f3c0e45900
1 changed files with 13 additions and 8 deletions

View File

@ -514,6 +514,11 @@ static int minor_to_rbd_dev_id(int minor)
return minor >> RBD_SINGLE_MAJOR_PART_SHIFT; return minor >> RBD_SINGLE_MAJOR_PART_SHIFT;
} }
static bool rbd_is_snap(struct rbd_device *rbd_dev)
{
return rbd_dev->spec->snap_id != CEPH_NOSNAP;
}
static bool __rbd_is_lock_owner(struct rbd_device *rbd_dev) static bool __rbd_is_lock_owner(struct rbd_device *rbd_dev)
{ {
lockdep_assert_held(&rbd_dev->lock_rwsem); lockdep_assert_held(&rbd_dev->lock_rwsem);
@ -696,7 +701,7 @@ static int rbd_ioctl_set_ro(struct rbd_device *rbd_dev, unsigned long arg)
return -EFAULT; return -EFAULT;
/* Snapshots can't be marked read-write */ /* Snapshots can't be marked read-write */
if (rbd_dev->spec->snap_id != CEPH_NOSNAP && !ro) if (rbd_is_snap(rbd_dev) && !ro)
return -EROFS; return -EROFS;
/* Let blkdev_roset() handle it */ /* Let blkdev_roset() handle it */
@ -3555,7 +3560,7 @@ static bool need_exclusive_lock(struct rbd_img_request *img_req)
if (!(rbd_dev->header.features & RBD_FEATURE_EXCLUSIVE_LOCK)) if (!(rbd_dev->header.features & RBD_FEATURE_EXCLUSIVE_LOCK))
return false; return false;
if (rbd_dev->spec->snap_id != CEPH_NOSNAP) if (rbd_is_snap(rbd_dev))
return false; return false;
rbd_assert(!test_bit(IMG_REQ_CHILD, &img_req->flags)); rbd_assert(!test_bit(IMG_REQ_CHILD, &img_req->flags));
@ -4826,7 +4831,7 @@ static void rbd_queue_workfn(struct work_struct *work)
goto err_rq; goto err_rq;
} }
if (op_type != OBJ_OP_READ && rbd_dev->spec->snap_id != CEPH_NOSNAP) { if (op_type != OBJ_OP_READ && rbd_is_snap(rbd_dev)) {
rbd_warn(rbd_dev, "%s on read-only snapshot", rbd_warn(rbd_dev, "%s on read-only snapshot",
obj_op_name(op_type)); obj_op_name(op_type));
result = -EIO; result = -EIO;
@ -4841,7 +4846,7 @@ static void rbd_queue_workfn(struct work_struct *work)
*/ */
if (!test_bit(RBD_DEV_FLAG_EXISTS, &rbd_dev->flags)) { if (!test_bit(RBD_DEV_FLAG_EXISTS, &rbd_dev->flags)) {
dout("request for non-existent snapshot"); dout("request for non-existent snapshot");
rbd_assert(rbd_dev->spec->snap_id != CEPH_NOSNAP); rbd_assert(rbd_is_snap(rbd_dev));
result = -ENXIO; result = -ENXIO;
goto err_rq; goto err_rq;
} }
@ -5084,7 +5089,7 @@ static int rbd_dev_refresh(struct rbd_device *rbd_dev)
goto out; goto out;
} }
if (rbd_dev->spec->snap_id == CEPH_NOSNAP) { if (!rbd_is_snap(rbd_dev)) {
rbd_dev->mapping.size = rbd_dev->header.image_size; rbd_dev->mapping.size = rbd_dev->header.image_size;
} else { } else {
/* validate mapped snapshot's EXISTS flag */ /* validate mapped snapshot's EXISTS flag */
@ -6632,7 +6637,7 @@ static int rbd_add_acquire_lock(struct rbd_device *rbd_dev)
return -EINVAL; return -EINVAL;
} }
if (rbd_dev->spec->snap_id != CEPH_NOSNAP) if (rbd_is_snap(rbd_dev))
return 0; return 0;
rbd_assert(!rbd_is_lock_owner(rbd_dev)); rbd_assert(!rbd_is_lock_owner(rbd_dev));
@ -7003,7 +7008,7 @@ static int rbd_dev_image_probe(struct rbd_device *rbd_dev, int depth)
if (ret) if (ret)
goto err_out_probe; goto err_out_probe;
if (rbd_dev->spec->snap_id != CEPH_NOSNAP && if (rbd_is_snap(rbd_dev) &&
(rbd_dev->header.features & RBD_FEATURE_OBJECT_MAP)) { (rbd_dev->header.features & RBD_FEATURE_OBJECT_MAP)) {
ret = rbd_object_map_load(rbd_dev); ret = rbd_object_map_load(rbd_dev);
if (ret) if (ret)
@ -7093,7 +7098,7 @@ static ssize_t do_rbd_add(struct bus_type *bus,
} }
/* If we are mapping a snapshot it must be marked read-only */ /* If we are mapping a snapshot it must be marked read-only */
if (rbd_dev->spec->snap_id != CEPH_NOSNAP) if (rbd_is_snap(rbd_dev))
rbd_dev->opts->read_only = true; rbd_dev->opts->read_only = true;
if (rbd_dev->opts->alloc_size > rbd_dev->layout.object_size) { if (rbd_dev->opts->alloc_size > rbd_dev->layout.object_size) {