From patchwork Fri Aug 17 08:40:39 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junichi Nomura X-Patchwork-Id: 1338041 Return-Path: X-Original-To: patchwork-dm-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from mx4-phx2.redhat.com (mx4-phx2.redhat.com [209.132.183.25]) by patchwork1.kernel.org (Postfix) with ESMTP id 0DC023FC33 for ; Fri, 17 Aug 2012 08:47:19 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx4-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q7H8hsE2001813; Fri, 17 Aug 2012 04:43:56 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q7H8hqkn020568 for ; Fri, 17 Aug 2012 04:43:52 -0400 Received: from mx1.redhat.com (ext-mx15.extmail.prod.ext.phx2.redhat.com [10.5.110.20]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q7H8hlm1028883; Fri, 17 Aug 2012 04:43:47 -0400 Received: from tyo202.gate.nec.co.jp (TYO202.gate.nec.co.jp [202.32.8.206]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q7H8hjHO022222; Fri, 17 Aug 2012 04:43:46 -0400 Received: from mailgate4.nec.co.jp ([10.7.69.184]) by tyo202.gate.nec.co.jp (8.13.8/8.13.4) with ESMTP id q7H8hhb3024372; Fri, 17 Aug 2012 17:43:43 +0900 (JST) Received: (from root@localhost) by mailgate4.nec.co.jp (8.11.7/3.7W-MAILGATE-NEC) id q7H8hg719002; Fri, 17 Aug 2012 17:43:42 +0900 (JST) Received: from mail03.kamome.nec.co.jp (mail03.kamome.nec.co.jp [10.25.43.7]) by mailsv3.nec.co.jp (8.13.8/8.13.4) with ESMTP id q7H8hgam019244; Fri, 17 Aug 2012 17:43:42 +0900 (JST) Received: from genzui.jp.nec.com ([10.26.220.13] [10.26.220.13]) by mail02.kamome.nec.co.jp with ESMTP id BT-MMP-955509; Fri, 17 Aug 2012 17:40:39 +0900 Received: from xzibit.linux.bs1.fc.nec.co.jp ([10.34.125.175] [10.34.125.175]) by mail.jp.nec.com with ESMTPA id BT-MMP-34710; Fri, 17 Aug 2012 17:40:39 +0900 Message-ID: <502E0387.5070808@ce.jp.nec.com> Date: Fri, 17 Aug 2012 17:40:39 +0900 From: "Jun'ichi Nomura" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120717 Thunderbird/14.0 MIME-Version: 1.0 To: dm-devel@redhat.com, christophe.varoqui@gmail.com References: <5007C043.4000006@ce.jp.nec.com> In-Reply-To: <5007C043.4000006@ce.jp.nec.com> X-RedHat-Spam-Score: -4.202 (BAYES_00, RCVD_IN_DNSWL_MED, SPF_HELO_PASS, SPF_PASS) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-Scanned-By: MIMEDefang 2.68 on 10.5.110.20 X-loop: dm-devel@redhat.com Subject: [dm-devel] [PATCH] multipath-tools: prevent unexpected swapping of underlying LUNs 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: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com When you want to rename a multipath device but the new alias is already used by other multipath device, multipath-tools mistakenly reload a table for the original multipath device to the other multipath device. That could lead to very bad result, such as I/O error and data corruption. This patch checks such a condition and gives up renaming with error log. For example, suppose you have following 'bindings' file: # cat /etc/multipath/bindings mpatha 212140084abcd0000 mpathb 212150084abcd0000 and a logical volume 'VG/LV0' on top of mpathb, which is on top of /dev/sde(8:64) and /dev/sdk(8:160): # dmsetup ls --tree mpatha (253:1) ?? (8:144) ?? (8:48) VG-LV0 (253:2) ??mpathb (253:0) ?? (8:160) ?? (8:64) Then you decide to swap their names and change the 'bindings' as follows: # cat /etc/multipath/bindings mpathb 212140084abcd0000 mpatha 212150084abcd0000 you'll get this after 'service multipathd reload': # dmsetup ls --tree mpatha (253:1) ?? (8:160) ?? (8:64) VG-LV0 (253:2) ??mpathb (253:0) ?? (8:144) ?? (8:48) Now you suddenly have 'VG/LV0' on top of /dev/sdd(8:48) and /dev/sdj(8:144), that is obviously wrong and will corrupt data if you write to 'VG/LV0'. --- dm-devel mailing list dm-devel@redhat.com https://www.redhat.com/mailman/listinfo/dm-devel diff -urpN multipath-tools.orig/libmultipath/configure.c multipath-tools.new/libmultipath/configure.c --- multipath-tools.orig/libmultipath/configure.c 2012-07-19 15:17:40.368622358 +0900 +++ multipath-tools.new/libmultipath/configure.c 2012-08-17 17:11:07.691898774 +0900 @@ -150,12 +150,12 @@ static void select_action (struct multipath * mpp, vector curmp, int force_reload) { struct multipath * cmpp; + struct multipath * cmpp_by_name; - cmpp = find_mp_by_alias(curmp, mpp->alias); - - if (!cmpp) { - cmpp = find_mp_by_wwid(curmp, mpp->wwid); + cmpp = find_mp_by_wwid(curmp, mpp->wwid); + cmpp_by_name = find_mp_by_alias(curmp, mpp->alias); + if (!cmpp_by_name) { if (cmpp) { condlog(2, "%s: rename %s to %s", mpp->wwid, cmpp->alias, mpp->alias); @@ -169,17 +169,25 @@ select_action (struct multipath * mpp, v return; } - if (!find_mp_by_wwid(curmp, mpp->wwid)) { - condlog(2, "%s: remove (wwid changed)", cmpp->alias); + if (!cmpp) { + condlog(2, "%s: remove (wwid changed)", mpp->alias); dm_flush_map(mpp->alias); - strncpy(cmpp->wwid, mpp->wwid, WWID_SIZE); - drop_multipath(curmp, cmpp->wwid, KEEP_PATHS); + strncpy(cmpp_by_name->wwid, mpp->wwid, WWID_SIZE); + drop_multipath(curmp, cmpp_by_name->wwid, KEEP_PATHS); mpp->action = ACT_CREATE; condlog(3, "%s: set ACT_CREATE (map wwid change)", mpp->alias); return; } + if (cmpp != cmpp_by_name) { + condlog(2, "%s: unable to rename %s to %s (%s is used by %s)", + mpp->wwid, cmpp->alias, mpp->alias, + mpp->alias, cmpp_by_name->wwid); + mpp->action = ACT_NOTHING; + return; + } + if (pathcount(mpp, PATH_UP) == 0) { mpp->action = ACT_NOTHING; condlog(3, "%s: set ACT_NOTHING (no usable path)",