All of lore.kernel.org
 help / color / mirror / Atom feed
From: Risto Kankkunen <risto.kankkunen@f-secure.com>
To: dm-devel@redhat.com
Cc: Risto Kankkunen <Risto.Kankkunen@f-secure.com>
Subject: [PATCH] kpartx: use inode to identify loopback mounts
Date: Mon, 6 Jul 2015 14:56:59 +0300	[thread overview]
Message-ID: <559A6D0B.5090602@f-secure.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 510 bytes --]

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.

[-- Attachment #2: 0014-kpartx-long-path.patch --]
[-- Type: text/plain, Size: 1366 bytes --]

From: Risto Kankkunen <risto.kankkunen@f-secure.com>
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.

--- 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 */
 			}

[-- Attachment #3: Type: text/plain, Size: 0 bytes --]



             reply	other threads:[~2015-07-06 11:56 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-06 11:56 Risto Kankkunen [this message]
2015-10-06  7:14 ` [PATCH] kpartx: use inode to identify loopback mounts Christophe Varoqui

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=559A6D0B.5090602@f-secure.com \
    --to=risto.kankkunen@f-secure.com \
    --cc=dm-devel@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.