Commit b66728ef authored by Oleg Nesterov's avatar Oleg Nesterov Committed by Pavel Emelyanov

parse_mountinfo: fix and simplify the usage of r_fstype

1. parse_mountinfo() forgets to free(fst) if parse_mountinfo_ent()
   succeeds.

2. The usage of fst/r_fstype is ovecomplicated for no reason.

Just change the parse_mountinfo() paths to populate/use/free this
fsname unconditionally, and move the ownership to the caller. There
is no reason to check FSTYPE__UNSUPPORTED and/or fallback to ->name.

Better yet, we could even turn fsname into the local "char []" and
avoid %ms and free(), but then we would need to pass the length of
this buffer to parse_mountinfo_ent().
Signed-off-by: 's avatarOleg Nesterov <oleg@redhat.com>
Reviewed-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 2cfeeac4
...@@ -943,12 +943,11 @@ static int parse_mnt_opt(char *str, struct mount_info *mi, int *off) ...@@ -943,12 +943,11 @@ static int parse_mnt_opt(char *str, struct mount_info *mi, int *off)
return 0; return 0;
} }
static int parse_mountinfo_ent(char *str, struct mount_info *new, char **r_fstype) static int parse_mountinfo_ent(char *str, struct mount_info *new, char **fsname)
{ {
unsigned int kmaj, kmin; unsigned int kmaj, kmin;
int ret, n; int ret, n;
char *opt; char *opt;
char *fstype;
new->mountpoint = xmalloc(PATH_MAX); new->mountpoint = xmalloc(PATH_MAX);
if (new->mountpoint == NULL) if (new->mountpoint == NULL)
...@@ -978,15 +977,13 @@ static int parse_mountinfo_ent(char *str, struct mount_info *new, char **r_fstyp ...@@ -978,15 +977,13 @@ static int parse_mountinfo_ent(char *str, struct mount_info *new, char **r_fstyp
return -1; return -1;
str += n; str += n;
ret = sscanf(str, "%ms %ms %ms", &fstype, &new->source, &opt); ret = sscanf(str, "%ms %ms %ms", fsname, &new->source, &opt);
if (ret != 3) if (ret != 3)
return -1; return -1;
ret = -1; new->fstype = find_fstype_by_name(*fsname);
new->fstype = find_fstype_by_name(fstype);
if (new->fstype->code == FSTYPE__UNSUPPORTED)
*r_fstype = fstype; /* keep for logging */
ret = -1;
new->options = xmalloc(strlen(opt) + 1); new->options = xmalloc(strlen(opt) + 1);
if (!new->options) if (!new->options)
goto err; goto err;
...@@ -997,8 +994,6 @@ static int parse_mountinfo_ent(char *str, struct mount_info *new, char **r_fstyp ...@@ -997,8 +994,6 @@ static int parse_mountinfo_ent(char *str, struct mount_info *new, char **r_fstyp
ret = 0; ret = 0;
err: err:
free(opt); free(opt);
if (!*r_fstype)
free(fstype);
return ret; return ret;
} }
...@@ -1017,7 +1012,7 @@ struct mount_info *parse_mountinfo(pid_t pid, struct ns_id *nsid) ...@@ -1017,7 +1012,7 @@ struct mount_info *parse_mountinfo(pid_t pid, struct ns_id *nsid)
while (fgets(str, sizeof(str), f)) { while (fgets(str, sizeof(str), f)) {
struct mount_info *new; struct mount_info *new;
int ret = -1; int ret = -1;
char *fst = NULL; char *fsname = NULL;
new = mnt_entry_alloc(); new = mnt_entry_alloc();
if (!new) if (!new)
...@@ -1025,14 +1020,14 @@ struct mount_info *parse_mountinfo(pid_t pid, struct ns_id *nsid) ...@@ -1025,14 +1020,14 @@ struct mount_info *parse_mountinfo(pid_t pid, struct ns_id *nsid)
new->nsid = nsid; new->nsid = nsid;
ret = parse_mountinfo_ent(str, new, &fst); ret = parse_mountinfo_ent(str, new, &fsname);
if (ret < 0) { if (ret < 0) {
pr_err("Bad format in %d mountinfo\n", pid); pr_err("Bad format in %d mountinfo\n", pid);
goto end; goto end;
} }
pr_info("\ttype %s source %s mnt_id %d s_dev %#x %s @ %s flags %#x options %s\n", pr_info("\ttype %s source %s mnt_id %d s_dev %#x %s @ %s flags %#x options %s\n",
fst ? : new->fstype->name, new->source, fsname, new->source,
new->mnt_id, new->s_dev, new->root, new->mountpoint, new->mnt_id, new->s_dev, new->root, new->mountpoint,
new->flags, new->options); new->flags, new->options);
...@@ -1045,6 +1040,9 @@ struct mount_info *parse_mountinfo(pid_t pid, struct ns_id *nsid) ...@@ -1045,6 +1040,9 @@ struct mount_info *parse_mountinfo(pid_t pid, struct ns_id *nsid)
} }
} }
end: end:
if (fsname)
free(fsname);
if (new) { if (new) {
new->next = list; new->next = list;
list = new; list = new;
......
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