From patchwork Tue Sep 24 03:25:36 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guangliang Zhao X-Patchwork-Id: 2931461 Return-Path: X-Original-To: patchwork-ceph-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 9436B9F2B8 for ; Tue, 24 Sep 2013 03:25:45 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id ADD73203B4 for ; Tue, 24 Sep 2013 03:25:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 746D62039E for ; Tue, 24 Sep 2013 03:25:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753091Ab3IXDZl (ORCPT ); Mon, 23 Sep 2013 23:25:41 -0400 Received: from mail-pb0-f41.google.com ([209.85.160.41]:43615 "EHLO mail-pb0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752912Ab3IXDZk (ORCPT ); Mon, 23 Sep 2013 23:25:40 -0400 Received: by mail-pb0-f41.google.com with SMTP id rp2so4038084pbb.28 for ; Mon, 23 Sep 2013 20:25:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=BnhDEqm4cadjOZSSsiHsdPd4KWL6gRIq4M6dfOhQ6ZM=; b=garsgVHc+Dr2gGvjVL1ZLl5hIOWW7SPK2tew2XXhI2xyu9zoouZ7RFfkbwnanBQ13H jBoAM3NDk6J3YMYRPISaaOaLhMh+fnjKUE69PwrzC4himtImDksftnnCVX/FD9a0Xo2E aCJyDSK0o5acXshFLCsbL5HRZv/Zj3dpoLc+wDR2gy6sEl6UPEWmHYYy3bTVNSVVLC04 ra4RC2IR+ic65w1IjbBPeyqDDwa0uC/IYawOL4clvZIFbL/TtsGVgbMam6oY8c9jTMQT uYQ8xxVZKgfnu4z7P5ukhnXwJg1nl7CErkkU9gNcFr7uUSkhjs0e0VqPeEySBD5jTdx9 NkNg== X-Gm-Message-State: ALoCoQlj/eqLBm3bHrAVbR9nt5ZtFg+2Hp0tO7kXQxH8qH/1uShAbzerDuAOSXZkCHoqT8oOB+tJ X-Received: by 10.68.29.36 with SMTP id g4mr4716501pbh.145.1379993140099; Mon, 23 Sep 2013 20:25:40 -0700 (PDT) Received: from localhost ([202.108.52.204]) by mx.google.com with ESMTPSA id im2sm37523110pbd.31.1969.12.31.16.00.00 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 23 Sep 2013 20:25:39 -0700 (PDT) From: Guangliang Zhao To: ceph-devel@vger.kernel.org Cc: josh.durgin@inktank.com, alex.elder@linaro.org, lucienchao@gmail.com, sage@inktank.com Subject: [PATCH v4] rbd: add ioctl for rbd Date: Tue, 24 Sep 2013 11:25:36 +0800 Message-Id: <1379993136-29246-1-git-send-email-guangliang@unitedstack.com> X-Mailer: git-send-email 1.7.9.5 Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org X-Spam-Status: No, score=-9.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When running the following commands: [root@ceph0 mnt]# blockdev --setro /dev/rbd1 [root@ceph0 mnt]# blockdev --getro /dev/rbd1 0 The block setro didn't take effect, it is because the rbd doesn't support ioctl of block driver. This resolves: http://tracker.ceph.com/issues/6265 Signed-off-by: Guangliang Zhao Reviewed-by: Alex Elder Reviewed-by: Josh Durgin --- drivers/block/rbd.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 2 deletions(-) diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index 2f00778..34bcdb7 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -508,10 +508,69 @@ static void rbd_release(struct gendisk *disk, fmode_t mode) put_device(&rbd_dev->dev); } +static int rbd_ioctl_set_ro(struct rbd_device *rbd_dev, unsigned long arg) +{ + int val; + bool ro; + + if (get_user(val, (int __user *)(arg))) + return -EFAULT; + + ro = val ? true : false; + /* Snapshot doesn't allow to write*/ + if (rbd_dev->spec->snap_id != CEPH_NOSNAP && !ro) + return -EROFS; + + if (rbd_dev->mapping.read_only != ro) { + rbd_dev->mapping.read_only = ro; + set_disk_ro(rbd_dev->disk, ro ? 1 : 0); + } + + return 0; +} + +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; + + spin_lock_irq(&rbd_dev->lock); + /* prevent others open this device */ + if (rbd_dev->open_count > 1) { + ret = -EBUSY; + goto out; + } + + switch (cmd) { + case BLKROSET: + ret = rbd_ioctl_set_ro(rbd_dev, arg); + break; + default: + ret = -ENOTTY; + } + +out: + spin_unlock_irq(&rbd_dev->lock); + return ret; +} + +#ifdef CONFIG_COMPAT +static int rbd_compat_ioctl(struct block_device *bdev, fmode_t mode, + unsigned int cmd, unsigned long arg) +{ + return rbd_ioctl(bdev, mode, cmd, arg); +} +#endif /* CONFIG_COMPAT */ + static const struct block_device_operations rbd_bd_ops = { .owner = THIS_MODULE, .open = rbd_open, .release = rbd_release, + .ioctl = rbd_ioctl, +#ifdef CONFIG_COMPAT + .compat_ioctl = rbd_compat_ioctl, +#endif }; /* @@ -3027,7 +3086,6 @@ static void rbd_request_fn(struct request_queue *q) __releases(q->queue_lock) __acquires(q->queue_lock) { struct rbd_device *rbd_dev = q->queuedata; - bool read_only = rbd_dev->mapping.read_only; struct request *rq; int result; @@ -3063,7 +3121,7 @@ static void rbd_request_fn(struct request_queue *q) if (write_request) { result = -EROFS; - if (read_only) + if (rbd_dev->mapping.read_only) goto end_request; rbd_assert(rbd_dev->spec->snap_id == CEPH_NOSNAP); }