From patchwork Mon Jul 6 11:56:59 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Risto Kankkunen X-Patchwork-Id: 6731361 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: X-Original-To: patchwork-dm-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id DFCDC9F319 for ; Tue, 7 Jul 2015 08:59:39 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 07CC3206A5 for ; Tue, 7 Jul 2015 08:59:39 +0000 (UTC) Received: from mx3-phx2.redhat.com (mx3-phx2.redhat.com [209.132.183.24]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id AEA9D206B7 for ; Tue, 7 Jul 2015 08:59:37 +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 t678tvT1001274; Tue, 7 Jul 2015 04:55:57 -0400 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 t66Bv4f0014187 for ; Mon, 6 Jul 2015 07:57:04 -0400 Received: from mx1.redhat.com (ext-mx03.extmail.prod.ext.phx2.redhat.com [10.5.110.27]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t66Bv429026041 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Mon, 6 Jul 2015 07:57:04 -0400 Received: from helmsgmaster01.f-secure.com (helmsgmaster01.f-secure.com [193.110.108.20]) by mx1.redhat.com (Postfix) with ESMTPS id A9194371B7A for ; Mon, 6 Jul 2015 11:57:02 +0000 (UTC) Received: from pps.filterd (helmsgmaster01.f-secure.com [127.0.0.1]) by helmsgmaster01.f-secure.com (8.14.7/8.14.7) with SMTP id t66BuXnV003929 for ; Mon, 6 Jul 2015 14:57:00 +0300 Received: from helex02.fi.f-secure.com ([10.190.48.73]) by helmsgmaster01.f-secure.com with ESMTP id 1vdrcsjk0y-1 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 06 Jul 2015 14:57:00 +0300 Received: from [10.128.133.97] (10.128.133.97) by helex01.FI.F-Secure.com (10.190.48.70) with Microsoft SMTP Server id 15.0.1044.25; Mon, 6 Jul 2015 14:56:59 +0300 Message-ID: <559A6D0B.5090602@f-secure.com> Date: Mon, 6 Jul 2015 14:56:59 +0300 From: Risto Kankkunen User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1) Gecko/20060918 Thunderbird/2.0b1pre Mnenhy/0.7.4.0 MIME-Version: 1.0 To: X-Originating-IP: [10.128.133.97] X-RedHat-Spam-Score: -7.563 (BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, SPF_PASS, URIBL_BLOCKED) 193.110.108.20 helmsgmaster01.f-secure.com 193.110.108.20 helmsgmaster01.f-secure.com X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Scanned-By: MIMEDefang 2.76 on 10.5.110.27 X-loop: dm-devel@redhat.com X-Mailman-Approved-At: Tue, 07 Jul 2015 04:54:27 -0400 Cc: Risto Kankkunen Subject: [dm-devel] [PATCH] kpartx: use inode to identify loopback mounts 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 X-Spam-Status: No, score=-7.7 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 This is a patch which I submitted to Launchpad (https://bugs.launchpad.net/ubuntu/+source/multipath-tools/+bug/1469143). I was told to submit it to this list instead. Currently kpartx doesn't work correctly with relative path names, hardlinks, symlinks or paths longer than 63 characters. This is because it tries to identify mounts by a non-unique name it gives to the mount. The loopinfo struct contains the device and inode information of the backing image, it is better to identify mounts by those. From: Risto Kankkunen Date: Mon, 29 Jun 2015 18:39:48 +0300 Subject: Use image file device/inode to find the correct loop device in kpartx Previously kpartx used the "lo_name" field of struct loop_info to store and match the image file name. That field is not intended to store path names (it's not big enough). Therefore kpartx was unable to delete mappings to file paths longer than 63 characters. It also didn't properly handle relative file paths: two different files with identical relative path names could not be mapped. Instead kpartx would modify the existing mapping when seeing a new file with the same relative path. The "loopinfo" structure contains the image file device and inode numbers. Use those to uniquely identify the correct loop device. --- dm-devel mailing list dm-devel@redhat.com https://www.redhat.com/mailman/listinfo/dm-devel --- a/kpartx/lopart.c +++ b/kpartx/lopart.c @@ -103,6 +103,14 @@ int i, j, fd; struct stat statbuf; struct loop_info loopinfo; + dev_t file_dev; + ino_t file_ino; + + if (stat (filename, &statbuf) != 0) { + return NULL; + } + file_dev = statbuf.st_dev; + file_ino = statbuf.st_ino; for (j = 0; j < SIZE(loop_formats); j++) { @@ -123,7 +131,7 @@ continue; } - if (0 == strcmp(filename, loopinfo.lo_name)) { + if (loopinfo.lo_device == file_dev && loopinfo.lo_inode == file_ino) { close (fd); return xstrdup(dev); /*found */ }