From patchwork Mon Sep 16 05:42:33 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guangliang Zhao X-Patchwork-Id: 2895531 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 EBB8B9F1C0 for ; Mon, 16 Sep 2013 05:42:44 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0F35C201F9 for ; Mon, 16 Sep 2013 05:42:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7D1AC201DC for ; Mon, 16 Sep 2013 05:42:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753044Ab3IPFml (ORCPT ); Mon, 16 Sep 2013 01:42:41 -0400 Received: from mail-pa0-f41.google.com ([209.85.220.41]:37202 "EHLO mail-pa0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752384Ab3IPFmk (ORCPT ); Mon, 16 Sep 2013 01:42:40 -0400 Received: by mail-pa0-f41.google.com with SMTP id bj1so4957652pad.0 for ; Sun, 15 Sep 2013 22:42:37 -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=+aO7sKEUCi3vpBzQHwEm6n7/qOQcpq2qBVt8ZHfIBCY=; b=bWfROXZ51rdn6PKaSCRLBgGGN/JT1fAOygJIJOuwFISJmSUGkKx6xSj46T1TEMf4Oc JAILfxeoEA0XFB7HGRfmmjad82WwpOpsh5ZoCtupA5DGD1bCIZlTl9KgJ0qnSdt0H5ut vAanUGLO8pdk4Bf2YOBE81x1j/jOtBRjt7onToLopy9oZwo0Dh2V+mWkBGfBuNtR+AzO 1/3ibZzE9JXjj255N3BbGyEL8gPU+MxFr/BykJjcCxLFfWd+JG1txFUrJiSBDWU8sEq7 wDT0Nq+LFQG7W6kFUIvDzDvVn+ytTyUVB+pN4wCYcv05ohuAuuTIwOjcyWPsnz3yVwSb vM1g== X-Gm-Message-State: ALoCoQnOVj6wHy50BeF0RinEWlRST2F9nqZT/YNtxx6jwbtXkTsp5fKXzkHzpapswfO1JNkfkEFz X-Received: by 10.66.163.164 with SMTP id yj4mr29447700pab.91.1379310157789; Sun, 15 Sep 2013 22:42:37 -0700 (PDT) Received: from localhost ([202.108.52.206]) by mx.google.com with ESMTPSA id h8sm1343483pbh.38.1969.12.31.16.00.00 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sun, 15 Sep 2013 22:42:37 -0700 (PDT) From: Guangliang Zhao To: ceph-devel@vger.kernel.org Cc: josh.durgin@inktank.com, alex.elder@linaro.org, lucienchao@gmail.com Subject: [PATCH] rbd: add ioctl for rbd Date: Mon, 16 Sep 2013 13:42:33 +0800 Message-Id: <1379310153-8799-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. This resolves: http://tracker.ceph.com/issues/6265 Signed-off-by: Guangliang Zhao --- drivers/block/rbd.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index 2f00778..9f2057a 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -508,10 +508,64 @@ 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; + 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 }; /*