From patchwork Sun Mar 8 03:31:32 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 5961171 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.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 02D81BF440 for ; Sun, 8 Mar 2015 04:40:04 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id EA91A2025B for ; Sun, 8 Mar 2015 04:40:02 +0000 (UTC) Received: from mx6-phx2.redhat.com (mx6-phx2.redhat.com [209.132.183.39]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C27A220251 for ; Sun, 8 Mar 2015 04:40:01 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx6-phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t284aKKv008753; Sat, 7 Mar 2015 23:36:21 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id t284ZNsb009325 for ; Sat, 7 Mar 2015 23:35:23 -0500 Received: from redhat.com (ask-08.lab.msp.redhat.com [10.15.85.8]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with SMTP id t284ZLvs013266; Sat, 7 Mar 2015 23:35:21 -0500 Received: by redhat.com (sSMTP sendmail emulation); Sat, 07 Mar 2015 21:31:48 -0600 From: "Benjamin Marzinski" To: device-mapper development Date: Sat, 7 Mar 2015 21:31:32 -0600 Message-Id: <1425785506-20419-2-git-send-email-bmarzins@redhat.com> In-Reply-To: <1425785506-20419-1-git-send-email-bmarzins@redhat.com> References: <1425785506-20419-1-git-send-email-bmarzins@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-loop: dm-devel@redhat.com Cc: Christophe Varoqui Subject: [dm-devel] [PATCH 01/15] correctly set partition delimiter on rename 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=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, 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 When multipath renames a device and the name switches from ending in a number to ending in a letter or vice versa, it currently just keeps any existing delimiter between the device name and partition number. However the default behaviour in kpartx is to only use the 'p' delimiter when the name ends in a number. Unfortunately, without adding a kpartx.conf that kpartx uses to set the delimiter behavior, there's no way for multipath to know how kpartx was run for certain device names (ones ending in a number with a 'p' delimiter). The patch adds a new multipath.conf defaults parameter, "partition_delimiter". If this value is not set, when multipath renames a device, it will act just like the kpartx default does, only adding a 'p' to names ending in a number. If this parameter is set, multipath will act like kpartx does with the -p option is used, and always add delimiter. Signed-off-by: Benjamin Marzinski --- libmultipath/config.c | 3 +++ libmultipath/config.h | 1 + libmultipath/devmapper.c | 14 ++++++++++++-- libmultipath/dict.c | 4 ++++ 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/libmultipath/config.c b/libmultipath/config.c index 7f7bd5a..cbc8e4b 100644 --- a/libmultipath/config.c +++ b/libmultipath/config.c @@ -502,6 +502,8 @@ free_config (struct config * conf) if (conf->alias_prefix) FREE(conf->alias_prefix); + if (conf->partition_delim) + FREE(conf->partition_delim); if (conf->prio_args) FREE(conf->prio_args); @@ -563,6 +565,7 @@ load_config (char * file, struct udev *udev) conf->retain_hwhandler = DEFAULT_RETAIN_HWHANDLER; conf->detect_prio = DEFAULT_DETECT_PRIO; conf->force_sync = 0; + conf->partition_delim = NULL; /* * preload default hwtable diff --git a/libmultipath/config.h b/libmultipath/config.h index ef1d7c3..b942a27 100644 --- a/libmultipath/config.h +++ b/libmultipath/config.h @@ -140,6 +140,7 @@ struct config { char * prio_args; char * checker_name; char * alias_prefix; + char * partition_delim; unsigned char * reservation_key; vector keywords; diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index 3d4c111..9e585f9 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -1142,6 +1142,8 @@ dm_rename_partmaps (char * old, char * new) unsigned long long size; char dev_t[32]; int r = 1; + int offset; + char *delim; if (!(dmt = dm_task_create(DM_DEVICE_LIST))) return 1; @@ -1162,6 +1164,13 @@ dm_rename_partmaps (char * old, char * new) if (dm_dev_t(old, &dev_t[0], 32)) goto out; + if (conf->partition_delim) + delim = conf->partition_delim; + if (isdigit(new[strlen(new)-1])) + delim = "p"; + else + delim = ""; + do { if ( /* @@ -1189,8 +1198,9 @@ dm_rename_partmaps (char * old, char * new) * then it's a kpartx generated partition. * Rename it. */ - snprintf(buff, PARAMS_SIZE, "%s%s", - new, names->name + strlen(old)); + for (offset = strlen(old); names->name[offset] && !(isdigit(names->name[offset])); offset++); /* do nothing */ + snprintf(buff, PARAMS_SIZE, "%s%s%s", + new, delim, names->name + offset); dm_rename(names->name, buff); condlog(4, "partition map %s renamed", names->name); diff --git a/libmultipath/dict.c b/libmultipath/dict.c index 737c9b0..ab313f3 100644 --- a/libmultipath/dict.c +++ b/libmultipath/dict.c @@ -230,6 +230,9 @@ declare_def_snprint(reassign_maps, print_yes_no) declare_def_handler(multipath_dir, set_str) declare_def_snprint(multipath_dir, print_str) +declare_def_handler(partition_delim, set_str) +declare_def_snprint(partition_delim, print_str) + declare_def_handler(selector, set_str) declare_def_snprint_defstr(selector, print_str, DEFAULT_SELECTOR) declare_hw_handler(selector, set_str) @@ -1242,6 +1245,7 @@ init_keywords(void) install_keyword("retain_attached_hw_handler", &def_retain_hwhandler_handler, &snprint_def_retain_hwhandler); install_keyword("detect_prio", &def_detect_prio_handler, &snprint_def_detect_prio); install_keyword("force_sync", &def_force_sync_handler, &snprint_def_force_sync); + install_keyword("partition_delimiter", &def_partition_delim_handler, &snprint_def_partition_delim); __deprecated install_keyword("default_selector", &def_selector_handler, NULL); __deprecated install_keyword("default_path_grouping_policy", &def_pgpolicy_handler, NULL); __deprecated install_keyword("default_uid_attribute", &def_uid_attribute_handler, NULL);