From patchwork Wed Dec 11 06:42:59 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 3322591 X-Patchwork-Delegate: christophe.varoqui@free.fr 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 695AEC0D4A for ; Wed, 11 Dec 2013 06:47:19 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6EFFC20761 for ; Wed, 11 Dec 2013 06:47:18 +0000 (UTC) Received: from mx3-phx2.redhat.com (mx3-phx2.redhat.com [209.132.183.24]) by mail.kernel.org (Postfix) with ESMTP id 4D33D2074E for ; Wed, 11 Dec 2013 06:47:17 +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 rBB6i0CL018605; Wed, 11 Dec 2013 01:44:01 -0500 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 rBB6hOOc013964 for ; Wed, 11 Dec 2013 01:43:24 -0500 Received: from dhcp80-209.msp.redhat.com (octiron.msp.redhat.com [10.15.80.209]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id rBB6hNqX004995 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 11 Dec 2013 01:43:23 -0500 Received: from dhcp80-209.msp.redhat.com (localhost [127.0.0.1]) by dhcp80-209.msp.redhat.com (8.14.7/8.14.7) with ESMTP id rBB6hMxb001353; Wed, 11 Dec 2013 00:43:22 -0600 Received: (from bmarzins@localhost) by dhcp80-209.msp.redhat.com (8.14.7/8.14.7/Submit) id rBB6hMiw001352; Wed, 11 Dec 2013 00:43:22 -0600 From: Benjamin Marzinski To: device-mapper development Date: Wed, 11 Dec 2013 00:42:59 -0600 Message-Id: <1386744190-1295-6-git-send-email-bmarzins@redhat.com> In-Reply-To: <1386744190-1295-1-git-send-email-bmarzins@redhat.com> References: <1386744190-1295-1-git-send-email-bmarzins@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-loop: dm-devel@redhat.com Cc: Christophe Varoqui Subject: [dm-devel] [PATCH 05/16] Only load a multipath device RO if RW load fails with EROFS 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=-7.1 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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 If a transient error keeps multipath from being able to reload a multipath device read/write, it will retry the reload with the device set to read-only. This can suddenly turn a read/write multipath device read-only. If device-mapper cannot load the device read/write because a path device can't be opened for writing, it will return EROFS. This is the only time it makes sense to reload the device read-only. Signed-off-by: Benjamin Marzinski --- libmultipath/configure.c | 7 ------- libmultipath/devmapper.c | 53 +++++++++++++++++++++++------------------------- libmultipath/devmapper.h | 2 -- 3 files changed, 25 insertions(+), 37 deletions(-) diff --git a/libmultipath/configure.c b/libmultipath/configure.c index aad3c9f..8c09791 100644 --- a/libmultipath/configure.c +++ b/libmultipath/configure.c @@ -383,24 +383,17 @@ domap (struct multipath * mpp, char * params) r = dm_addmap_create(mpp, params); - if (!r) - r = dm_addmap_create_ro(mpp, params); - lock_multipath(mpp, 0); break; case ACT_RELOAD: r = dm_addmap_reload(mpp, params); - if (!r) - r = dm_addmap_reload_ro(mpp, params); if (r) r = dm_simplecmd_noflush(DM_DEVICE_RESUME, mpp->alias); break; case ACT_RESIZE: r = dm_addmap_reload(mpp, params); - if (!r) - r = dm_addmap_reload_ro(mpp, params); if (r) r = dm_simplecmd_flush(DM_DEVICE_RESUME, mpp->alias, 1); break; diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index 3da109c..6eb2d96 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -300,42 +300,39 @@ dm_addmap (int task, const char *target, struct multipath *mpp, char * params, return r; } -static int -_dm_addmap_create (struct multipath *mpp, char * params, int ro) { - int r; - r = dm_addmap(DM_DEVICE_CREATE, TGT_MPATH, mpp, params, 1, ro); - /* - * DM_DEVICE_CREATE is actually DM_DEV_CREATE + DM_TABLE_LOAD. - * Failing the second part leaves an empty map. Clean it up. - */ - if (!r && dm_map_present(mpp->alias)) { - condlog(3, "%s: failed to load map (a path might be in use)", - mpp->alias); - dm_flush_map_nosync(mpp->alias); +extern int +dm_addmap_create (struct multipath *mpp, char * params) { + int ro; + + for (ro = 0; ro <= 1; ro++) { + int err; + + if (dm_addmap(DM_DEVICE_CREATE, TGT_MPATH, mpp, params, 1, ro)) + return 1; + /* + * DM_DEVICE_CREATE is actually DM_DEV_CREATE + DM_TABLE_LOAD. + * Failing the second part leaves an empty map. Clean it up. + */ + err = errno; + if (dm_map_present(mpp->alias)) { + condlog(3, "%s: failed to load map (a path might be in use)", mpp->alias); + dm_flush_map_nosync(mpp->alias); + } + if (err != EROFS) + break; } - return r; + return 0; } #define ADDMAP_RW 0 #define ADDMAP_RO 1 extern int -dm_addmap_create (struct multipath *mpp, char *params) { - return _dm_addmap_create(mpp, params, ADDMAP_RW); -} - -extern int -dm_addmap_create_ro (struct multipath *mpp, char *params) { - return _dm_addmap_create(mpp, params, ADDMAP_RO); -} - -extern int dm_addmap_reload (struct multipath *mpp, char *params) { - return dm_addmap(DM_DEVICE_RELOAD, TGT_MPATH, mpp, params, 0, ADDMAP_RW); -} - -extern int -dm_addmap_reload_ro (struct multipath *mpp, char *params) { + if (dm_addmap(DM_DEVICE_RELOAD, TGT_MPATH, mpp, params, 0, ADDMAP_RW)) + return 1; + if (errno != EROFS) + return 0; return dm_addmap(DM_DEVICE_RELOAD, TGT_MPATH, mpp, params, 0, ADDMAP_RO); } diff --git a/libmultipath/devmapper.h b/libmultipath/devmapper.h index a144bfb..58cd718 100644 --- a/libmultipath/devmapper.h +++ b/libmultipath/devmapper.h @@ -12,9 +12,7 @@ int dm_drv_version (unsigned int * version, char * str); int dm_simplecmd_flush (int, const char *, int); int dm_simplecmd_noflush (int, const char *); int dm_addmap_create (struct multipath *mpp, char *params); -int dm_addmap_create_ro (struct multipath *mpp, char *params); int dm_addmap_reload (struct multipath *mpp, char *params); -int dm_addmap_reload_ro (struct multipath *mpp, char *params); int dm_map_present (const char *); int dm_get_map(const char *, unsigned long long *, char *); int dm_get_status(char *, char *);