[CRIU] [PATCH] mount: ignore subvol argument in btrfs sb

Tycho Andersen tycho.andersen at canonical.com
Mon Mar 21 16:13:56 PDT 2016


See comment for details, but basically this mountopt can be completely
wrong in some cases.

Signed-off-by: Tycho Andersen <tycho.andersen at canonical.com>
---
 criu/mount.c | 39 +++++++++++++++++++++++++++++++++++++--
 1 file changed, 37 insertions(+), 2 deletions(-)

diff --git a/criu/mount.c b/criu/mount.c
index d5d7663..7560505 100644
--- a/criu/mount.c
+++ b/criu/mount.c
@@ -283,8 +283,43 @@ bool phys_stat_dev_match(dev_t st_dev, dev_t phys_dev,
  */
 static bool mounts_sb_equal(struct mount_info *a, struct mount_info *b)
 {
-	return a->s_dev == b->s_dev && a->fstype == b->fstype &&
-		!strcmp(a->source, b->source) && !strcmp(a->options, b->options);
+	if (a->fstype != b->fstype)
+		return false;
+
+	/* There is a btrfs bug where it doesn't emit subvol= correctly when
+	 * files are bind mounted, so let's ignore it for now.
+	 * https://marc.info/?l=linux-btrfs&m=145857372803614&w=2
+	 */
+	if (!strcmp(a->fstype->name, "btrfs")) {
+		char *posa = strstr(a->options, "subvol="), *posb = strstr(b->options, "subvol=");
+		bool equal;
+
+		if (!posa || !posb) {
+			pr_err("invalid btrfs options, no subvol argument");
+			return false;
+		}
+
+		*posa = *posb = 0;
+		equal = !strcmp(a->options, b->options);
+		*posa = *posb = 's';
+
+		if (!equal)
+			return false;
+
+		posa = strchr(posa, ',');
+		posb = strchr(posb, ',');
+
+		if ((posa && !posb) || (!posa && posb))
+			return false;
+
+		if (posa && strcmp(posa, posb))
+			return false;
+	} else {
+		if (strcmp(a->options, b->options))
+			return false;
+	}
+
+	return a->s_dev == b->s_dev && !strcmp(a->source, b->source);
 }
 
 /*
-- 
2.7.0



More information about the CRIU mailing list