From patchwork Mon Nov 6 15:49:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Dryomov X-Patchwork-Id: 10043739 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id ADDF9603FF for ; Mon, 6 Nov 2017 15:49:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4B593290F1 for ; Mon, 6 Nov 2017 15:49:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3EC3329BD3; Mon, 6 Nov 2017 15:49:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D1634290F1 for ; Mon, 6 Nov 2017 15:49:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753043AbdKFPtz (ORCPT ); Mon, 6 Nov 2017 10:49:55 -0500 Received: from mail-wm0-f68.google.com ([74.125.82.68]:53516 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752322AbdKFPty (ORCPT ); Mon, 6 Nov 2017 10:49:54 -0500 Received: by mail-wm0-f68.google.com with SMTP id r196so15203880wmf.2 for ; Mon, 06 Nov 2017 07:49:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=D0lvmpHB5jurIZ5QUrah1wtaClC2gErpk9H9iyoZfjc=; b=CLJYRDsSizc+yqoIM+LImEgfxvhDPM6Q7hqnKXdcAf1adSvp4YwFM1BfxhtwYY7Gj6 o/CZ39PIST7FtYPaXVEESZ/WN0JAIPh+Uwy2ZA9T5qZzi/Q/T5i1F7KJ41YDP1ksY9ZC 6wx/zQ5xjZ16VkajHZLPLorKB408nLVzeEypdJPJXpoy5IYv3eebgP0MeFq2Fvk1Y+he 2RM/DQlSjEvgMYbPK8EQuTHkniUyGkhGb8iliGfnW4ubj3JlQPvFxX7lSmrTarq6EBMZ x8TRLBTEIsJr01MBw45vWoiUbvuSpeGKuVSM+PQiECJkrxkzhtKcJLJ/QISCZK4IKmef a+1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=D0lvmpHB5jurIZ5QUrah1wtaClC2gErpk9H9iyoZfjc=; b=qJvdH/ovBhHhf/UNdmjDm/qYrCs057Zb4oiyP0kJrIH4GyiQh1I/2VfAbxCUZbdrUt szTBRAT7dGtMs56MX6mReY+4ramcBxpaZ5ah61u/fwPorunp5ObRa0xguUvp8B/IkfU9 J10zFuHomzGIjoCKyrthOk4/UqmxGabH7RIlu2rfkxaOoNCZVia34AwvlfilVywdJim3 aPaondKsjEejWGLcMqOuQqpKpeHcxz/6cqmzb5x6tOO/6KRSLj3tt3nWFFRl0blbWJz6 aJJqxTLCURmAor1cYuiI5aEhP9KXD+yQBzpdNfI3gWnTmfFVIL2UYRmfg+z8oqhU2Amo hVgA== X-Gm-Message-State: AJaThX5tu5eKXtZr3/IPfAFatK2xrlJX5J8y1ondrO4uJfVGH1ySrDHk c97ZUsZ6zoqA40Y1UuH7wSio/VLs X-Google-Smtp-Source: ABhQp+SrFJixIdahowBJAoy+aypSFla9KQNBFa32OoUnFqu2/cH6wfGqu76UOKGrqE1ScnK1EHxOTA== X-Received: by 10.28.216.5 with SMTP id p5mr6227676wmg.155.1509983392909; Mon, 06 Nov 2017 07:49:52 -0800 (PST) Received: from orange.brq.redhat.com. (nat-pool-brq-t.redhat.com. [213.175.37.10]) by smtp.gmail.com with ESMTPSA id t66sm3349198wme.33.2017.11.06.07.49.52 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Nov 2017 07:49:52 -0800 (PST) From: Ilya Dryomov To: ceph-devel@vger.kernel.org Subject: [PATCH 1/2] rbd: fix and simplify rbd_ioctl_set_ro() Date: Mon, 6 Nov 2017 16:49:29 +0100 Message-Id: <1509983370-1853-1-git-send-email-idryomov@gmail.com> X-Mailer: git-send-email 2.4.3 Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP ->open_count/-EBUSY check is bogus and wrong: when an open device is set read-only, blkdev_write_iter() refuses further writes with -EPERM. This is standard behaviour and all other block devices allow this. set_disk_ro() call is also problematic: we affect the entire device when called on a single partition. All rbd_ioctl_set_ro() needs to do is refuse ro -> rw transition for mapped snapshots. Everything else can be handled by generic code. Signed-off-by: Ilya Dryomov --- drivers/block/rbd.c | 34 ++++++---------------------------- 1 file changed, 6 insertions(+), 28 deletions(-) diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index 6347ac194e90..832b235b2dc3 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -640,46 +640,24 @@ static void rbd_release(struct gendisk *disk, fmode_t mode) static int rbd_ioctl_set_ro(struct rbd_device *rbd_dev, unsigned long arg) { - int ret = 0; - int val; - bool ro; - bool ro_changed = false; + int ro; - /* get_user() may sleep, so call it before taking rbd_dev->lock */ - if (get_user(val, (int __user *)(arg))) + if (get_user(ro, (int __user *)arg)) return -EFAULT; - ro = val ? true : false; - /* Snapshot doesn't allow to write*/ + /* Snapshots can't be marked read-write */ if (rbd_dev->spec->snap_id != CEPH_NOSNAP && !ro) return -EROFS; - spin_lock_irq(&rbd_dev->lock); - /* prevent others open this device */ - if (rbd_dev->open_count > 1) { - ret = -EBUSY; - goto out; - } - - if (rbd_dev->mapping.read_only != ro) { - rbd_dev->mapping.read_only = ro; - ro_changed = true; - } - -out: - spin_unlock_irq(&rbd_dev->lock); - /* set_disk_ro() may sleep, so call it after releasing rbd_dev->lock */ - if (ret == 0 && ro_changed) - set_disk_ro(rbd_dev->disk, ro ? 1 : 0); - - return ret; + /* Let blkdev_roset() handle it */ + return -ENOTTY; } static int rbd_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd, unsigned long arg) { struct rbd_device *rbd_dev = bdev->bd_disk->private_data; - int ret = 0; + int ret; switch (cmd) { case BLKROSET: