Blame SOURCES/0071-findmnt-don-t-rely-on-st_dev-for-target.patch

531551
From 0f66811659aa8fd8b14ade8a80bfecd580962b2d Mon Sep 17 00:00:00 2001
531551
From: Karel Zak <kzak@redhat.com>
531551
Date: Tue, 10 Mar 2015 12:51:44 +0100
531551
Subject: [PATCH 71/84] findmnt: don't rely on st_dev for --target
531551
531551
The overlay filesystem does not provide usable st_dev (in traditional
531551
UNIX way). It's necessary to search in /proc/self/mountinfo to detect
531551
which path element is mountpoint.
531551
531551
$ findmnt --target /mnt/merged/dir-a/foo
531551
TARGET      SOURCE  FSTYPE  OPTIONS
531551
/mnt/merged overlay overlay rw,relatime,lowerdir=/mnt/low,upperdir=/mnt/high/data,workdir=/mnt/high/work
531551
531551
Upstream: http://github.com/karelzak/util-linux/commit/cd41b385a06dde70bb45c3143d3459157bda58f8
531551
Addresses: http://bugzilla.redhat.com/show_bug.cgi?id=587393
531551
Signed-off-by: Karel Zak <kzak@redhat.com>
531551
---
531551
 libmount/src/utils.c |  6 +++++-
531551
 misc-utils/findmnt.8 |  8 ++++++--
531551
 misc-utils/findmnt.c | 17 +++++++++++------
531551
 3 files changed, 22 insertions(+), 9 deletions(-)
531551
531551
diff --git a/libmount/src/utils.c b/libmount/src/utils.c
531551
index 7c6f5b1..5783d88 100644
531551
--- a/libmount/src/utils.c
531551
+++ b/libmount/src/utils.c
531551
@@ -859,7 +859,11 @@ int mnt_open_uniq_filename(const char *filename, char **name)
531551
  * This function finds the mountpoint that a given path resides in. @path
531551
  * should be canonicalized. The returned pointer should be freed by the caller.
531551
  *
531551
- * Returns: allocated string with target of the mounted device or NULL on error
531551
+ * WARNING: the function compares st_dev of the @path elements. This traditional
531551
+ * way maybe be insufficient on filesystems like Linux "overlay". See also
531551
+ * mnt_table_find_target().
531551
+ *
531551
+ * Returns: allocated string with the target of the mounted device or NULL on error
531551
  */
531551
 char *mnt_get_mountpoint(const char *path)
531551
 {
531551
diff --git a/misc-utils/findmnt.8 b/misc-utils/findmnt.8
531551
index 407636e..54739b7 100644
531551
--- a/misc-utils/findmnt.8
531551
+++ b/misc-utils/findmnt.8
531551
@@ -179,8 +179,12 @@ Search in
531551
 .IR /etc/fstab .
531551
 The output is in the list format (see \fB--list\fR).
531551
 .TP
531551
-.BR \-T , " \-\-target \fIdir\fP"
531551
-Explicitly define the mount target (mountpoint directory).
531551
+.BR \-T , " \-\-target \fIpath\fP"
531551
+Explicitly define the mount target (mountpoint directory). If the \fIpath\fR
531551
+is not a mountpoint file or directory than
531551
+.B findmnt
531551
+checks \fIpath\fR elements in reverse order for get the mountpoint (this feature is 
531551
+supported only if search in kernel files and unsupported for \fB\-\-fstab\fP).
531551
 .TP
531551
 .BR \-t , " \-\-types \fIlist\fP"
531551
 Limit the set of printed filesystems.  More than one type may be
531551
diff --git a/misc-utils/findmnt.c b/misc-utils/findmnt.c
531551
index f16da91..fe899db 100644
531551
--- a/misc-utils/findmnt.c
531551
+++ b/misc-utils/findmnt.c
531551
@@ -236,9 +236,12 @@ static void set_source_match(const char *data)
531551
 		set_match(COL_SOURCE, data);
531551
 }
531551
 
531551
-static void enable_extra_target_match(void)
531551
+/* @tb has to be from kernel (so no fstab or so)! */
531551
+static void enable_extra_target_match(struct libmnt_table *tb)
531551
 {
531551
-	char *cn = NULL, *mnt = NULL;
531551
+	char *cn = NULL;
531551
+	const char *tgt = NULL, *mnt = NULL;
531551
+	struct libmnt_fs *fs;
531551
 
531551
 	/*
531551
 	 * Check if match pattern is mountpoint, if not use the
531551
@@ -248,9 +251,11 @@ static void enable_extra_target_match(void)
531551
 	if (!cn)
531551
 		return;
531551
 
531551
-	mnt = mnt_get_mountpoint(cn);
531551
-	if (!mnt || strcmp(mnt, cn) == 0)
531551
-		return;
531551
+	fs = mnt_table_find_mountpoint(tb, tgt, MNT_ITER_BACKWARD);
531551
+	if (fs)
531551
+		mnt = mnt_fs_get_target(fs);
531551
+	if (mnt && strcmp(mnt, tgt) != 0)
531551
+		set_match(COL_TARGET, xstrdup(mnt));	/* replace the current setting */
531551
 
531551
 	/* replace the current setting with the real mountpoint */
531551
 	set_match(COL_TARGET, mnt);
531551
@@ -1484,7 +1489,7 @@ int main(int argc, char *argv[])
531551
 			 * try it again with extra functionality for target
531551
 			 * match
531551
 			 */
531551
-			enable_extra_target_match();
531551
+			enable_extra_target_match(tb);
531551
 			rc = add_matching_lines(tb, tt, direction);
531551
 		}
531551
 	}
531551
-- 
531551
2.7.4
531551