From patchwork Wed Mar 12 11:34:54 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannes Reinecke X-Patchwork-Id: 3816691 Return-Path: X-Original-To: patchwork-dm-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id D375DBF540 for ; Wed, 12 Mar 2014 11:39:14 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 01E322020A for ; Wed, 12 Mar 2014 11:39:14 +0000 (UTC) Received: from mx3-phx2.redhat.com (mx3-phx2.redhat.com [209.132.183.24]) by mail.kernel.org (Postfix) with ESMTP id 16F8420203 for ; Wed, 12 Mar 2014 11:39:13 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx3-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id s2CBZ08c022362; Wed, 12 Mar 2014 07:35:01 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id s2CBYwIU004744 for ; Wed, 12 Mar 2014 07:34:58 -0400 Received: from mx1.redhat.com (ext-mx15.extmail.prod.ext.phx2.redhat.com [10.5.110.20]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id s2CBYwKs017622; Wed, 12 Mar 2014 07:34:58 -0400 Received: from mx2.suse.de (cantor2.suse.de [195.135.220.15]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s2CBYuav031681; Wed, 12 Mar 2014 07:34:56 -0400 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 3CEFF75017; Wed, 12 Mar 2014 11:34:56 +0000 (UTC) From: Hannes Reinecke To: Alasdair Kergon Date: Wed, 12 Mar 2014 12:34:54 +0100 Message-Id: <1394624094-118695-1-git-send-email-hare@suse.de> X-RedHat-Spam-Score: -7.31 (BAYES_00, DCC_REPUT_00_12, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-Scanned-By: MIMEDefang 2.68 on 10.5.110.20 X-loop: dm-devel@redhat.com Cc: Christoph Hellwig , dm-devel@redhat.com, Mike Snitzer Subject: [dm-devel] [PATCH] multipath devices are not getting created for readonly devices X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk Reply-To: device-mapper development List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable 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 Currently we cannot create device-mapper tables for multipath devices whenever the underlying devices are read-only. This patch modifies the device-mapper to set the 'READ-ONLY' flag automatically whenever a read-only device is added to the table. Signed-off-by: Hannes Reinecke --- drivers/md/dm-table.c | 11 ++++++++++- drivers/md/dm.c | 17 +++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c index 6a7f2b8..44ea2b3 100644 --- a/drivers/md/dm-table.c +++ b/drivers/md/dm-table.c @@ -443,11 +443,20 @@ int dm_get_device(struct dm_target *ti, const char *path, fmode_t mode, dd->dm_dev.mode = mode; dd->dm_dev.bdev = NULL; - if ((r = open_dev(dd, dev, t->md))) { + r = open_dev(dd, dev, t->md); + if (r == -EROFS) { + dd->dm_dev.mode &= ~FMODE_WRITE; + r = open_dev(dd, dev, t->md); + } + if (r) { kfree(dd); return r; } + /* Modify the table mode, too */ + if (dd->dm_dev.mode != mode) + t->mode = dd->dm_dev.mode; + format_dev_t(dd->dm_dev.name, dev); atomic_set(&dd->count, 0); diff --git a/drivers/md/dm.c b/drivers/md/dm.c index 8c53b09..0f7b441 100644 --- a/drivers/md/dm.c +++ b/drivers/md/dm.c @@ -384,16 +384,25 @@ int dm_deleting_md(struct mapped_device *md) static int dm_blk_open(struct block_device *bdev, fmode_t mode) { struct mapped_device *md; + int retval = 0; spin_lock(&_minor_lock); md = bdev->bd_disk->private_data; - if (!md) + if (!md) { + retval = -ENXIO; goto out; + } if (test_bit(DMF_FREEING, &md->flags) || dm_deleting_md(md)) { md = NULL; + retval = -ENXIO; + goto out; + } + if (get_disk_ro(md->disk) && (mode & FMODE_WRITE)) { + md = NULL; + retval = -EROFS; goto out; } @@ -403,7 +412,7 @@ static int dm_blk_open(struct block_device *bdev, fmode_t mode) out: spin_unlock(&_minor_lock); - return md ? 0 : -ENXIO; + return retval; } static void dm_blk_close(struct gendisk *disk, fmode_t mode) @@ -2156,6 +2165,10 @@ static struct dm_table *__bind(struct mapped_device *md, struct dm_table *t, set_bit(DMF_MERGE_IS_OPTIONAL, &md->flags); else clear_bit(DMF_MERGE_IS_OPTIONAL, &md->flags); + if (!(dm_table_get_mode(t) & FMODE_WRITE)) + set_disk_ro(md->disk, 1); + else + set_disk_ro(md->disk, 0); dm_sync_table(md); return old_map;