Message ID | 1509983370-1853-2-git-send-email-idryomov@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Hi Ilya, On Mon, 6 Nov 2017 16:49:30 +0100, Ilya Dryomov wrote: > - /* Only reads are allowed to a read-only device */ > - > - if (op_type != OBJ_OP_READ) { > - if (rbd_dev->mapping.read_only) { > - result = -EROFS; > - goto err_rq; > - } > - rbd_assert(rbd_dev->spec->snap_id == CEPH_NOSNAP); > - } > + rbd_assert(op_type == OBJ_OP_READ || > + rbd_dev->spec->snap_id == CEPH_NOSNAP); AFAICT, the block layer can still queue non-read requests, despite the block device read-only policy flag, so I think an -EROFS handler needs to stay. The following was run on mainline (e4880bc5dfb1f02b152e62a894b5c6f3e995) with these two patches applied: RBD mapped at: /dev/rbd/rbd/img@snap rapido1:/# blockdev --getro /dev/rbd/rbd/img@snap 1 rapido1:/# mkfs.xfs /dev/rbd/rbd/img@snap [ 12.346216] [ 12.346216] Assertion failure in rbd_queue_workfn() at line 4028: [ 12.346216] [ 12.346216] rbd_assert(op_type == OBJ_OP_READ || rbd_dev->spec->snap_id == CEPH_NOSNAP); [ 12.346216] [ 12.347529] ------------[ cut here ]------------ [ 12.347910] kernel BUG at drivers/block/rbd.c:4028! [ 12.348479] invalid opcode: 0000 [#1] SMP [ 12.349044] Modules linked in: [ 12.349499] CPU: 1 PID: 17 Comm: kworker/1:0 Not tainted 4.14.0-rc8+ #405 [ 12.350407] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.0.0-prebuilt.qemu-project.org 04/01/2014 [ 12.352001] Workqueue: rbd rbd_queue_workfn [ 12.352498] task: ffff88001d27b480 task.stack: ffffc90000090000 [ 12.353058] RIP: 0010:rbd_queue_workfn+0x4f9/0x500 [ 12.353527] RSP: 0018:ffffc90000093e08 EFLAGS: 00010282 [ 12.354036] RAX: 0000000000000086 RBX: ffff88001a7c7980 RCX: ffffffff81829398 [ 12.354890] RDX: 0000000000000001 RSI: 0000000000000086 RDI: ffffffff819f9f6c [ 12.355580] RBP: ffffc90000093e60 R08: 00000000fffffffe R09: 000000000000048f [ 12.356285] R10: 0000000000000005 R11: 000000000000048e R12: ffff88001ca6f000 [ 12.356964] R13: 0000000000000000 R14: 0000000000000002 R15: ffff88001a7c7ac0 [ 12.357650] FS: 0000000000000000(0000) GS:ffff88001e500000(0000) knlGS:0000000000000000 [ 12.358443] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 12.359031] CR2: 00007fcd19a14000 CR3: 000000001f069000 CR4: 00000000000006a0 [ 12.359806] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 [ 12.360604] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 [ 12.361397] Call Trace: [ 12.361686] process_one_work+0x11e/0x280 [ 12.362145] worker_thread+0x45/0x3b0 [ 12.362564] kthread+0xff/0x140 [ 12.362935] ? process_one_work+0x280/0x280 [ 12.363409] ? kthread_create_on_node+0x40/0x40 [ 12.363936] ret_from_fork+0x22/0x30 [ 12.364338] Code: 85 e1 fb ff ff e9 99 fb ff ff 48 c7 c1 e8 af 71 81 ba bc 0f 00 00 48 c7 c6 f0 bb 64 81 48 c7 c7 40 9d 71 81 31 c0 e8 65 df d5 ff <0f> 0b 0f 1f 44 00 00 55 48 89 e5 41 56 41 55 41 54 49 89 fc 53 [ 12.366440] RIP: rbd_queue_workfn+0x4f9/0x500 RSP: ffffc90000093e08 [ 12.367147] ---[ end trace 75c22000d1a0b248 ]--- Cheers, David -- To unsubscribe from this list: send the line "unsubscribe ceph-devel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Tue, Nov 7, 2017 at 2:26 PM, David Disseldorp <ddiss@suse.de> wrote: > Hi Ilya, > > On Mon, 6 Nov 2017 16:49:30 +0100, Ilya Dryomov wrote: > >> - /* Only reads are allowed to a read-only device */ >> - >> - if (op_type != OBJ_OP_READ) { >> - if (rbd_dev->mapping.read_only) { >> - result = -EROFS; >> - goto err_rq; >> - } >> - rbd_assert(rbd_dev->spec->snap_id == CEPH_NOSNAP); >> - } >> + rbd_assert(op_type == OBJ_OP_READ || >> + rbd_dev->spec->snap_id == CEPH_NOSNAP); > > AFAICT, the block layer can still queue non-read requests, despite the > block device read-only policy flag, so I think an -EROFS handler needs > to stay. > The following was run on mainline (e4880bc5dfb1f02b152e62a894b5c6f3e995) > with these two patches applied: > > RBD mapped at: /dev/rbd/rbd/img@snap > rapido1:/# blockdev --getro /dev/rbd/rbd/img@snap > 1 > rapido1:/# mkfs.xfs /dev/rbd/rbd/img@snap > [ 12.346216] > [ 12.346216] Assertion failure in rbd_queue_workfn() at line 4028: > [ 12.346216] > [ 12.346216] rbd_assert(op_type == OBJ_OP_READ || rbd_dev->spec->snap_id == CEPH_NOSNAP); > [ 12.346216] > [ 12.347529] ------------[ cut here ]------------ > [ 12.347910] kernel BUG at drivers/block/rbd.c:4028! > [ 12.348479] invalid opcode: 0000 [#1] SMP > [ 12.349044] Modules linked in: > [ 12.349499] CPU: 1 PID: 17 Comm: kworker/1:0 Not tainted 4.14.0-rc8+ #405 > [ 12.350407] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.0.0-prebuilt.qemu-project.org 04/01/2014 > [ 12.352001] Workqueue: rbd rbd_queue_workfn > [ 12.352498] task: ffff88001d27b480 task.stack: ffffc90000090000 > [ 12.353058] RIP: 0010:rbd_queue_workfn+0x4f9/0x500 > [ 12.353527] RSP: 0018:ffffc90000093e08 EFLAGS: 00010282 > [ 12.354036] RAX: 0000000000000086 RBX: ffff88001a7c7980 RCX: ffffffff81829398 > [ 12.354890] RDX: 0000000000000001 RSI: 0000000000000086 RDI: ffffffff819f9f6c > [ 12.355580] RBP: ffffc90000093e60 R08: 00000000fffffffe R09: 000000000000048f > [ 12.356285] R10: 0000000000000005 R11: 000000000000048e R12: ffff88001ca6f000 > [ 12.356964] R13: 0000000000000000 R14: 0000000000000002 R15: ffff88001a7c7ac0 > [ 12.357650] FS: 0000000000000000(0000) GS:ffff88001e500000(0000) knlGS:0000000000000000 > [ 12.358443] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 > [ 12.359031] CR2: 00007fcd19a14000 CR3: 000000001f069000 CR4: 00000000000006a0 > [ 12.359806] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 > [ 12.360604] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 > [ 12.361397] Call Trace: > [ 12.361686] process_one_work+0x11e/0x280 > [ 12.362145] worker_thread+0x45/0x3b0 > [ 12.362564] kthread+0xff/0x140 > [ 12.362935] ? process_one_work+0x280/0x280 > [ 12.363409] ? kthread_create_on_node+0x40/0x40 > [ 12.363936] ret_from_fork+0x22/0x30 > [ 12.364338] Code: 85 e1 fb ff ff e9 99 fb ff ff 48 c7 c1 e8 af 71 81 ba bc 0f 00 00 48 c7 c6 f0 bb 64 81 48 c7 c7 40 9d 71 81 31 c0 e8 65 df d5 ff <0f> 0b 0f 1f 44 00 00 55 48 89 e5 41 56 41 55 41 54 49 89 fc 53 > [ 12.366440] RIP: rbd_queue_workfn+0x4f9/0x500 RSP: ffffc90000093e08 > [ 12.367147] ---[ end trace 75c22000d1a0b248 ]--- Hi David, Heh, apparently I only tested writes and didn't do discards... Writes go through blkdev_write_iter() but zeroout/discards seem to rely solely on FMODE_WRITE checks, which the block layer doesn't enforce. I'd rather try to fix it in the block layer before working around it in krbd. I'll work up a patch tomorrow. Thanks, Ilya -- To unsubscribe from this list: send the line "unsubscribe ceph-devel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Tue, 7 Nov 2017 17:56:51 +0100, Ilya Dryomov wrote: > Heh, apparently I only tested writes and didn't do discards... Writes > go through blkdev_write_iter() but zeroout/discards seem to rely solely > on FMODE_WRITE checks, which the block layer doesn't enforce. > > I'd rather try to fix it in the block layer before working around it in > krbd. I'll work up a patch tomorrow. FWIW I've pushed a blktests regression test for this to the wip_ro_get_set_discard branch of my repo at: https://github.com/ddiss/blktests.git Cheers, David -- To unsubscribe from this list: send the line "unsubscribe ceph-devel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index 832b235b2dc3..8a39c399e4ae 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -348,7 +348,6 @@ struct rbd_client_id { struct rbd_mapping { u64 size; u64 features; - bool read_only; }; /* @@ -608,9 +607,6 @@ static int rbd_open(struct block_device *bdev, fmode_t mode) struct rbd_device *rbd_dev = bdev->bd_disk->private_data; bool removing = false; - if ((mode & FMODE_WRITE) && rbd_dev->mapping.read_only) - return -EROFS; - spin_lock_irq(&rbd_dev->lock); if (test_bit(RBD_DEV_FLAG_REMOVING, &rbd_dev->flags)) removing = true; @@ -4028,15 +4024,8 @@ static void rbd_queue_workfn(struct work_struct *work) goto err_rq; } - /* Only reads are allowed to a read-only device */ - - if (op_type != OBJ_OP_READ) { - if (rbd_dev->mapping.read_only) { - result = -EROFS; - goto err_rq; - } - rbd_assert(rbd_dev->spec->snap_id == CEPH_NOSNAP); - } + rbd_assert(op_type == OBJ_OP_READ || + rbd_dev->spec->snap_id == CEPH_NOSNAP); /* * Quit early if the mapped snapshot no longer exists. It's @@ -5972,7 +5961,7 @@ static int rbd_dev_device_setup(struct rbd_device *rbd_dev) goto err_out_disk; set_capacity(rbd_dev->disk, rbd_dev->mapping.size / SECTOR_SIZE); - set_disk_ro(rbd_dev->disk, rbd_dev->mapping.read_only); + set_disk_ro(rbd_dev->disk, rbd_dev->opts->read_only); ret = dev_set_name(&rbd_dev->dev, "%d", rbd_dev->dev_id); if (ret) @@ -6123,7 +6112,6 @@ static ssize_t do_rbd_add(struct bus_type *bus, struct rbd_options *rbd_opts = NULL; struct rbd_spec *spec = NULL; struct rbd_client *rbdc; - bool read_only; int rc; if (!try_module_get(THIS_MODULE)) @@ -6172,11 +6160,8 @@ static ssize_t do_rbd_add(struct bus_type *bus, } /* If we are mapping a snapshot it must be marked read-only */ - - read_only = rbd_dev->opts->read_only; if (rbd_dev->spec->snap_id != CEPH_NOSNAP) - read_only = true; - rbd_dev->mapping.read_only = read_only; + rbd_dev->opts->read_only = true; rc = rbd_dev_device_setup(rbd_dev); if (rc)
It is redundant -- rw/ro state is stored in hd_struct and managed by the block layer. Signed-off-by: Ilya Dryomov <idryomov@gmail.com> --- drivers/block/rbd.c | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-)