Commit 32f58742 authored by Pavel Emelyanov's avatar Pavel Emelyanov

mnt: Introduce and use issubpath helper

When we validate the mount tree not to have overmounts we need to
check one path to be the sub-path of another. Here's a helper for
this.
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
Acked-by: 's avatarAndrew Vagin <avagin@parallels.com>
parent b3f64457
...@@ -192,13 +192,17 @@ extern int read_fd_link(int lfd, char *buf, size_t size); ...@@ -192,13 +192,17 @@ extern int read_fd_link(int lfd, char *buf, size_t size);
int vaddr_to_pfn(unsigned long vaddr, u64 *pfn); int vaddr_to_pfn(unsigned long vaddr, u64 *pfn);
/* /*
* Check whether @str starts with @sub * Check whether @str starts with @sub and report the
* next character of @str in @end
*/ */
static inline bool strstartswith(const char *str, const char *sub) static inline bool strstartswith2(const char *str, const char *sub, char *end)
{ {
while (1) { while (1) {
if (*sub == '\0') /* end of sub -- match */ if (*sub == '\0') /* end of sub -- match */ {
if (end)
*end = *str;
return true; return true;
}
if (*str == '\0') /* end of str, sub is NOT ended -- miss */ if (*str == '\0') /* end of str, sub is NOT ended -- miss */
return false; return false;
if (*str != *sub) if (*str != *sub)
...@@ -209,6 +213,24 @@ static inline bool strstartswith(const char *str, const char *sub) ...@@ -209,6 +213,24 @@ static inline bool strstartswith(const char *str, const char *sub)
} }
} }
static inline bool strstartswith(const char *str, const char *sub)
{
return strstartswith2(str, sub, NULL);
}
/*
* Checks whether the @path has @sub_path as a sub path, i.e.
* sub_path is the beginning of path and the last component
* match is full (next character terminates path component).
*/
static inline bool issubpath(const char *path, const char *sub_path)
{
char end;
return strstartswith2(path, sub_path, &end) &&
(end == '/' || end == '\0');
}
/* /*
* mkdir -p * mkdir -p
*/ */
......
...@@ -479,19 +479,11 @@ static int validate_mounts(struct mount_info *info, bool for_dump) ...@@ -479,19 +479,11 @@ static int validate_mounts(struct mount_info *info, bool for_dump)
} }
list_for_each_entry(t, &m->parent->children, siblings) { list_for_each_entry(t, &m->parent->children, siblings) {
int tlen, mlen;
if (m == t) if (m == t)
continue; continue;
if (!issubpath(m->mountpoint, t->mountpoint))
tlen = strlen(t->mountpoint);
mlen = strlen(m->mountpoint);
if (mlen < tlen)
continue;
if (strncmp(t->mountpoint, m->mountpoint, tlen))
continue;
if (mlen > tlen && m->mountpoint[tlen] != '/')
continue; continue;
pr_err("%d:%s is overmounted\n", m->mnt_id, m->mountpoint); pr_err("%d:%s is overmounted\n", m->mnt_id, m->mountpoint);
return -1; return -1;
} }
......
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