Commit da60bf30 authored by Pavel Emelyanov's avatar Pavel Emelyanov

mount: Move btrfs checks into callback

Introduce fstype->sb_equal and move btrfs-specific checks
into it.

travis-ci: success for mount: Sanitize sb comparison code
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
parent 02b67161
...@@ -590,6 +590,40 @@ static int cgroup_parse(struct mount_info *pm) ...@@ -590,6 +590,40 @@ static int cgroup_parse(struct mount_info *pm)
return 0; 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) static int dump_empty_fs(struct mount_info *pm)
{ {
int fd, ret = -1; int fd, ret = -1;
...@@ -658,6 +692,7 @@ static struct fstype fstypes[] = { ...@@ -658,6 +692,7 @@ static struct fstype fstypes[] = {
}, { }, {
.name = "btrfs", .name = "btrfs",
.code = FSTYPE__UNSUPPORTED, .code = FSTYPE__UNSUPPORTED,
.sb_equal = btrfs_sb_equal,
}, { }, {
.name = "pstore", .name = "pstore",
.dump = dump_empty_fs, .dump = dump_empty_fs,
......
...@@ -14,6 +14,7 @@ struct fstype { ...@@ -14,6 +14,7 @@ struct fstype {
int (*dump)(struct mount_info *pm); int (*dump)(struct mount_info *pm);
int (*restore)(struct mount_info *pm); int (*restore)(struct mount_info *pm);
int (*parse)(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; mount_fn_t mount;
}; };
......
...@@ -300,38 +300,11 @@ static bool mounts_sb_equal(struct mount_info *a, struct mount_info *b) ...@@ -300,38 +300,11 @@ static bool mounts_sb_equal(struct mount_info *a, struct mount_info *b)
if (strcmp(a->source, b->source) != 0) if (strcmp(a->source, b->source) != 0)
return false; return false;
/* There is a btrfs bug where it doesn't emit subvol= correctly when if (a->fstype->sb_equal) /* :) */
* files are bind mounted, so let's ignore it for now. return b->fstype->sb_equal(a, b);
* 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)) if (strcmp(a->options, b->options))
return false; return false;
}
if (a->fstype->code == FSTYPE__CGROUP && if (a->fstype->code == FSTYPE__CGROUP &&
a->private && b->private && a->private && b->private &&
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment