From patchwork Tue Sep 17 07:04:03 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guangliang Zhao X-Patchwork-Id: 2901031 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 B93389F1C0 for ; Tue, 17 Sep 2013 07:06:12 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 219F220334 for ; Tue, 17 Sep 2013 07:06:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 871F7201F5 for ; Tue, 17 Sep 2013 07:06:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751863Ab3IQHGF (ORCPT ); Tue, 17 Sep 2013 03:06:05 -0400 Received: from mail-pd0-f175.google.com ([209.85.192.175]:35878 "EHLO mail-pd0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751475Ab3IQHGD (ORCPT ); Tue, 17 Sep 2013 03:06:03 -0400 Received: by mail-pd0-f175.google.com with SMTP id q10so5184974pdj.34 for ; Tue, 17 Sep 2013 00:06:03 -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=GrQu9HOAtj5Bh7h1vj0GsQnC9efD/hZXQLx1baE5qLg=; b=lxd1Duot8DYXkV2ZTcALk64ylTWzr86ri3j9X8t/U8/Xiz4bdkMvfbc4nK9VhaDQVx cqrDRnrNpH0vWF4baycjNHjxi73A+en2wzzIyqNFTJhDGxGVXKGjZGuflKyxYf+oaIr2 kHQyIwqwXFAeqwBVG2MQ9vhvgT7nPN4uH4WGBT+YVtGyEaG65JpfNBgYEEvqOaHBLAyk +5ubBwrzLFpa81jZWpuSaOqSaluYplUUZcN0ecIjn4BOS76Z0La6iwGKC3vCFQxbKrxj VrAJEmMWcioh7iebZvEx6b2wXdGZ9R22kAJQzvoeYHUXpgEicgyO0dRZuCj5algL6E1B wrxg== X-Gm-Message-State: ALoCoQk6kFBw7DKkwaFsN3EIWxNnE0QbGII582+PzNuyrJPAfzGAvZQEna44+qEmtetrl48xegRR X-Received: by 10.68.143.131 with SMTP id se3mr32806605pbb.39.1379401563154; Tue, 17 Sep 2013 00:06:03 -0700 (PDT) Received: from localhost ([211.155.113.239]) by mx.google.com with ESMTPSA id os4sm36056913pbb.25.1969.12.31.16.00.00 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 17 Sep 2013 00:06:02 -0700 (PDT) From: Guangliang Zhao To: ceph-devel@vger.kernel.org Cc: sage@inktank.com, josh.durgin@inktank.com, alex.elder@linaro.org, lucienchao@gmail.com Subject: [PATCH v2] rbd: add ioctl for rbd Date: Tue, 17 Sep 2013 15:04:03 +0800 Message-Id: <1379401443-13569-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=-7.6 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/rbd2 [root@ceph0 mnt]# blockdev --getro /dev/rbd2 0 The block setro didn't take effect, it is because the rbd doesn't support ioctl of block driver. The results with this patch: root@ceph-client01:~# rbd map img root@ceph-client01:~# blockdev --getro /dev/rbd1 0 root@ceph-client01:~# cat /sys/block/rbd1/ro 0 root@ceph-client01:~# blockdev --setro /dev/rbd1 root@ceph-client01:~# blockdev --getro /dev/rbd1 1 root@ceph-client01:~# cat /sys/block/rbd1/ro 1 root@ceph-client01:~# dd if=/dev/zero of=/dev/rbd1 count=1 dd: opening `/dev/rbd1': Read-only file system` root@ceph-client01:~# blockdev --setrw /dev/rbd1 root@ceph-client01:~# blockdev --getro /dev/rbd1 0 root@ceph-client01:~# cat /sys/block/rbd1/ro 0 root@ceph-client01:~# dd if=/dev/zero of=/dev/rbd1 count=1 1+0 records in 1+0 records out 512 bytes (512 B) copied, 0.14989 s, 3.4 kB/s This resolves: http://tracker.ceph.com/issues/6265 Signed-off-by: Guangliang Zhao --- drivers/block/rbd.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index 2f00778..f700f7c 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -508,10 +508,65 @@ static void rbd_release(struct gendisk *disk, fmode_t mode) put_device(&rbd_dev->dev); } +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 ro, ret = 0; + + BUG_ON(!rbd_dev); + spin_lock_irq(&rbd_dev->lock); + if (rbd_dev->open_count > 1) { + spin_unlock_irq(&rbd_dev->lock); + ret = -EBUSY; + goto out; + } + spin_unlock_irq(&rbd_dev->lock); + + switch (cmd) { + case BLKROSET: + if (get_user(ro, (int __user *)(arg))) { + ret = -EFAULT; + goto out; + } + + /* Snapshot doesn't allow to write*/ + if (rbd_dev->spec->snap_id != CEPH_NOSNAP && ro) { + ret = -EROFS; + goto out; + } + + if (rbd_dev->mapping.read_only != ro) { + rbd_dev->mapping.read_only = ro; + set_disk_ro(rbd_dev->disk, ro); + goto out; + } + + break; + default: + ret = -EINVAL; + } + +out: + 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 }; /*