[CRIU] [PATCH v6 13/13] mount: create target directory for AutoFS indirect mounts.
Stanislav Kinsburskiy
skinsbursky at virtuozzo.com
Wed Jan 27 09:58:08 PST 2016
In case of mounting AutoFS indirect mount points, target dentry doesn't exist
and has to be created.
Signed-off-by: Stanislav Kinsburskiy <skinsbursky at virtuozzo.com>
---
autofs.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 49 insertions(+)
diff --git a/autofs.c b/autofs.c
index 4dc75ba..8150163 100644
--- a/autofs.c
+++ b/autofs.c
@@ -513,6 +513,50 @@ static int autofs_mnt_open(const char *mnt_path, dev_t devid)
return fd;
}
+static int autofs_create_dentries(const struct mount_info *mi, char *mnt_path)
+{
+ struct mount_info *c;
+
+ list_for_each_entry(c, &mi->children, siblings) {
+ char *path, *basename;
+
+ basename = strrchr(c->mountpoint, '/');
+ if (!basename) {
+ pr_info("%s: mount path \"%s\" doesn't have '/'\n",
+ __func__, c->mountpoint);
+ return -1;
+ }
+ path = xsprintf("%s%s", mnt_path, basename);
+ if (!path)
+ return -1;
+ if (mkdir(path, 0555) < 0) {
+ pr_perror("Failed to create autofs dentry %s", path);
+ return -1;
+ }
+ free(path);
+ }
+ return 0;
+}
+
+static int autofs_populate_mount(const struct mount_info *mi,
+ const AutofsEntry *entry)
+{
+ struct mount_info *b;
+
+ pr_info("%s: mode: %d\n", __func__, entry->mode);
+ if (entry->mode != AUTOFS_MODE_INDIRECT)
+ return 0;
+
+ if (autofs_create_dentries(mi, mi->mountpoint) < 0)
+ return -1;
+
+ list_for_each_entry(b, &mi->mnt_bind, mnt_bind) {
+ if (autofs_create_dentries(b, mi->mountpoint) < 0)
+ return -1;
+ }
+ return 0;
+}
+
static int autofs_post_mount(const char *mnt_path, dev_t mnt_dev,
time_t timeout)
{
@@ -838,6 +882,11 @@ int autofs_mount(struct mount_info *mi, const char *source, const
}
info->mnt_dev = buf.st_dev;
+ /* We need to create dentries for nested mounts */
+ ret = autofs_populate_mount(mi, entry);
+ if (ret < 0)
+ goto umount;
+
/* In case of catatonic mounts all we need as the function call below */
ret = autofs_post_mount(mi->mountpoint, buf.st_dev, entry->timeout);
if (ret < 0)
More information about the CRIU
mailing list