]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
Refactor and factorize mount entries
authorNicolas Cornu <ncornu@aldebaran.com>
Thu, 6 Aug 2015 08:37:15 +0000 (10:37 +0200)
committerStéphane Graber <stgraber@ubuntu.com>
Fri, 28 Aug 2015 22:05:37 +0000 (18:05 -0400)
Signed-off-by: Nicolas Cornu <ncornu@aldebaran.com>
src/lxc/conf.c

index 41a39eb83ba2be90f252d99e08e17e8769072661..bd11d507f712f278e14a78fa8d2e83d61da2b2b0 100644 (file)
@@ -2167,14 +2167,15 @@ static int mount_entry_create_dir_file(const struct mntent *mntent,
        return ret;
 }
 
-static inline int mount_entry_on_systemfs(struct mntent *mntent)
+static inline int mount_entry_on_generic(struct mntent *mntent,
+                 const char* path)
 {
        unsigned long mntflags;
        char *mntdata;
        int ret;
        bool optional = hasmntopt(mntent, "optional") != NULL;
 
-       ret = mount_entry_create_dir_file(mntent, mntent->mnt_dir);
+       ret = mount_entry_create_dir_file(mntent, path);
 
        cull_mntent_opt(mntent);
 
@@ -2183,25 +2184,27 @@ static inline int mount_entry_on_systemfs(struct mntent *mntent)
                return -1;
        }
 
-       ret = mount_entry(mntent->mnt_fsname, mntent->mnt_dir,
-                         mntent->mnt_type, mntflags, mntdata, optional);
+       ret = mount_entry(mntent->mnt_fsname, path, mntent->mnt_type,
+                         mntflags, mntdata, optional);
 
        free(mntdata);
 
        return ret;
 }
 
+static inline int mount_entry_on_systemfs(struct mntent *mntent)
+{
+  return mount_entry_on_generic(mntent, mntent->mnt_dir);
+}
+
 static int mount_entry_on_absolute_rootfs(struct mntent *mntent,
                                          const struct lxc_rootfs *rootfs,
                                          const char *lxc_name)
 {
        char *aux;
        char path[MAXPATHLEN];
-       unsigned long mntflags;
-       char *mntdata;
        int r, ret = 0, offset;
        const char *lxcpath;
-       bool optional = hasmntopt(mntent, "optional") != NULL;
 
        lxcpath = lxc_global_config_value("lxc.lxcpath");
        if (!lxcpath) {
@@ -2225,7 +2228,7 @@ skipvarlib:
        aux = strstr(mntent->mnt_dir, rootfs->path);
        if (!aux) {
                WARN("ignoring mount point '%s'", mntent->mnt_dir);
-               goto out;
+               return ret;
        }
        offset = strlen(rootfs->path);
 
@@ -2235,36 +2238,17 @@ skipabs:
                 aux + offset);
        if (r < 0 || r >= MAXPATHLEN) {
                WARN("pathnme too long for '%s'", mntent->mnt_dir);
-               ret = -1;
-               goto out;
-       }
-
-       ret = mount_entry_create_dir_file(mntent, path);
-
-       cull_mntent_opt(mntent);
-
-       if (parse_mntopts(mntent->mnt_opts, &mntflags, &mntdata) < 0) {
-               free(mntdata);
                return -1;
        }
 
-       ret = mount_entry(mntent->mnt_fsname, path, mntent->mnt_type,
-                         mntflags, mntdata, optional);
-
-       free(mntdata);
-
-out:
-       return ret;
+       return mount_entry_on_generic(mntent, path);
 }
 
 static int mount_entry_on_relative_rootfs(struct mntent *mntent,
                                          const char *rootfs)
 {
        char path[MAXPATHLEN];
-       unsigned long mntflags;
-       char *mntdata;
        int ret;
-       bool optional = hasmntopt(mntent, "optional") != NULL;
 
        /* relative to root mount point */
        ret = snprintf(path, sizeof(path), "%s/%s", rootfs, mntent->mnt_dir);
@@ -2273,21 +2257,7 @@ static int mount_entry_on_relative_rootfs(struct mntent *mntent,
                return -1;
        }
 
-       ret = mount_entry_create_dir_file(mntent, path);
-
-       cull_mntent_opt(mntent);
-
-       if (parse_mntopts(mntent->mnt_opts, &mntflags, &mntdata) < 0) {
-               free(mntdata);
-               return -1;
-       }
-
-       ret = mount_entry(mntent->mnt_fsname, path, mntent->mnt_type,
-                         mntflags, mntdata, optional);
-
-       free(mntdata);
-
-       return ret;
+       return mount_entry_on_generic(mntent, path);
 }
 
 static int mount_file_entries(const struct lxc_rootfs *rootfs, FILE *file,