From 5430d27d59bfb54fd0ef575804345cfa14c90ce1 Mon Sep 17 00:00:00 2001 From: Patrick McLean Date: Wed, 27 Mar 2019 14:07:23 -0700 Subject: [PATCH] rbd: avoid an assert fail on DISCARD with a mapped snap If a user maps/mounts a snapshot currently, then attempts to fstrim on that filesystem, current there is an assertion failure: Assertion failure in rbd_queue_workfn() at line 3664: rbd_assert(op_type == OBJ_OP_READ || rbd_dev->spec->snap_id == CEPH_NOSNAP); This is probably not the right reaction in this case, rather an error should just be bubbled up to user space. This patch checks for this case and returns -EBADF. This error was selected since that is the error the block layer returns when DISCARD is attempted on a read-only block device. --- drivers/block/rbd.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index 585378bc988c..89c78be308a7 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -3652,6 +3652,12 @@ static void rbd_queue_workfn(struct work_struct *work) goto err; } + /* snapshot mounts are readonly, so don't allow discards */ + if (rbd_dev->spec->snap_id == CEPH_NOSNAP && op_type == OBJ_OP_DISCARD) { + result = -EBADF; + goto err; + } + /* Ignore/skip any zero-length requests */ if (!length) { -- 2.21.0