Commit 12a253be authored by Stanislav Kinsburskiy's avatar Stanislav Kinsburskiy Committed by Pavel Emelyanov

mount: create target directory for AutoFS indirect mounts.

In case of mounting AutoFS indirect mount points, target dentry doesn't exist
and has to be created.
Signed-off-by: 's avatarStanislav Kinsburskiy <skinsbursky@virtuozzo.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
parent dca4f4f2
...@@ -511,6 +511,49 @@ static int autofs_mnt_open(const char *mnt_path, dev_t devid) ...@@ -511,6 +511,49 @@ static int autofs_mnt_open(const char *mnt_path, dev_t devid)
return fd; 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;
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, static int autofs_post_mount(const char *mnt_path, dev_t mnt_dev,
time_t timeout) time_t timeout)
{ {
...@@ -836,6 +879,11 @@ int autofs_mount(struct mount_info *mi, const char *source, const ...@@ -836,6 +879,11 @@ int autofs_mount(struct mount_info *mi, const char *source, const
} }
info->mnt_dev = buf.st_dev; 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 */ /* In case of catatonic mounts all we need as the function call below */
ret = autofs_post_mount(mi->mountpoint, buf.st_dev, entry->timeout); ret = autofs_post_mount(mi->mountpoint, buf.st_dev, entry->timeout);
if (ret < 0) if (ret < 0)
......
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