[CRIU] [PATCH 2/3] mount: Move btrfs checks into callback
Pavel Emelyanov
xemul at virtuozzo.com
Wed Jan 11 00:32:38 PST 2017
Introduce fstype->sb_equal and move btrfs-specific checks
into it.
Signed-off-by: Pavel Emelyanov <xemul at virtuozzo.com>
---
criu/filesystems.c | 35 +++++++++++++++++++++++++++++++++++
criu/include/filesystems.h | 1 +
criu/mount.c | 35 ++++-------------------------------
3 files changed, 40 insertions(+), 31 deletions(-)
diff --git a/criu/filesystems.c b/criu/filesystems.c
index e640096..c79cf91 100644
--- a/criu/filesystems.c
+++ b/criu/filesystems.c
@@ -590,6 +590,40 @@ static int cgroup_parse(struct mount_info *pm)
return 0;
}
+static bool btrfs_sb_equal(struct mount_info *a, struct mount_info *b)
+{
+ /* 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
+ */
+
+ 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;
+
+ return true;
+}
+
static int dump_empty_fs(struct mount_info *pm)
{
int fd, ret = -1;
@@ -658,6 +692,7 @@ static struct fstype fstypes[] = {
}, {
.name = "btrfs",
.code = FSTYPE__UNSUPPORTED,
+ .sb_equal = btrfs_sb_equal,
}, {
.name = "pstore",
.dump = dump_empty_fs,
diff --git a/criu/include/filesystems.h b/criu/include/filesystems.h
index 1e8d2aa..08c824c 100644
--- a/criu/include/filesystems.h
+++ b/criu/include/filesystems.h
@@ -14,6 +14,7 @@ struct fstype {
int (*dump)(struct mount_info *pm);
int (*restore)(struct mount_info *pm);
int (*parse)(struct mount_info *pm);
+ bool (*sb_equal)(struct mount_info *a, struct mount_info *b);
mount_fn_t mount;
};
diff --git a/criu/mount.c b/criu/mount.c
index f356a01..473631c 100644
--- a/criu/mount.c
+++ b/criu/mount.c
@@ -300,38 +300,11 @@ static bool mounts_sb_equal(struct mount_info *a, struct mount_info *b)
if (strcmp(a->source, b->source) != 0)
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 (a->fstype->sb_equal) /* :) */
+ return b->fstype->sb_equal(a, b);
- if ((posa && !posb) || (!posa && posb))
- return false;
-
- if (posa && strcmp(posa, posb))
- return false;
- } else {
- if (strcmp(a->options, b->options))
- return false;
- }
+ if (strcmp(a->options, b->options))
+ return false;
if (a->fstype->code == FSTYPE__CGROUP &&
a->private && b->private &&
--
2.5.0
More information about the CRIU
mailing list