conf: switch mount_autodev() to new mount api

parent 1f3eb959
...@@ -1060,16 +1060,15 @@ on_error: ...@@ -1060,16 +1060,15 @@ on_error:
static int mount_autodev(const char *name, const struct lxc_rootfs *rootfs, static int mount_autodev(const char *name, const struct lxc_rootfs *rootfs,
int autodevtmpfssize, const char *lxcpath) int autodevtmpfssize, const char *lxcpath)
{ {
__do_close int fd_fs = -EBADF;
const char *path = rootfs->path ? rootfs->mount : NULL; const char *path = rootfs->path ? rootfs->mount : NULL;
size_t tmpfs_size = (autodevtmpfssize != 0) ? autodevtmpfssize : 500000;
int ret; int ret;
mode_t cur_mask; mode_t cur_mask;
char mount_options[128]; char mount_options[128];
INFO("Preparing \"/dev\""); INFO("Preparing \"/dev\"");
sprintf(mount_options, "size=%d,mode=755", (autodevtmpfssize != 0) ? autodevtmpfssize : 500000);
DEBUG("Using mount options: %s", mount_options);
cur_mask = umask(S_IXUSR | S_IXGRP | S_IXOTH); cur_mask = umask(S_IXUSR | S_IXGRP | S_IXOTH);
ret = mkdirat(rootfs->dfd_mnt, "dev" , S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); ret = mkdirat(rootfs->dfd_mnt, "dev" , S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
if (ret < 0 && errno != EEXIST) { if (ret < 0 && errno != EEXIST) {
...@@ -1078,14 +1077,12 @@ static int mount_autodev(const char *name, const struct lxc_rootfs *rootfs, ...@@ -1078,14 +1077,12 @@ static int mount_autodev(const char *name, const struct lxc_rootfs *rootfs,
goto reset_umask; goto reset_umask;
} }
ret = safe_mount_beneath_at(rootfs->dfd_mnt, "none", "dev", "tmpfs", 0, mount_options); fd_fs = fs_prepare("tmpfs", -EBADF, "", 0, 0);
if (ret < 0) { if (fd_fs < 0) {
__do_free char *fallback_path = NULL; __do_free char *fallback_path = NULL;
if (errno != ENOSYS) { sprintf(mount_options, "size=%zu,mode=755", tmpfs_size);
SYSERROR("Failed to mount tmpfs on \"%s\"", path); DEBUG("Using mount options: %s", mount_options);
goto reset_umask;
}
if (path) { if (path) {
fallback_path = must_make_path(path, "/dev", NULL); fallback_path = must_make_path(path, "/dev", NULL);
...@@ -1093,19 +1090,31 @@ static int mount_autodev(const char *name, const struct lxc_rootfs *rootfs, ...@@ -1093,19 +1090,31 @@ static int mount_autodev(const char *name, const struct lxc_rootfs *rootfs,
} else { } else {
ret = safe_mount("none", "dev", "tmpfs", 0, mount_options, NULL); ret = safe_mount("none", "dev", "tmpfs", 0, mount_options, NULL);
} }
} else {
sprintf(mount_options, "%zu", tmpfs_size);
ret = fs_set_property(fd_fs, "mode", "0755");
if (ret < 0)
return log_error_errno(-errno, errno, "Failed to mount tmpfs onto %d(dev)", fd_fs);
ret = fs_set_property(fd_fs, "size", mount_options);
if (ret < 0)
return log_error_errno(-errno, errno, "Failed to mount tmpfs onto %d(dev)", fd_fs);
ret = fs_attach(fd_fs, rootfs->dfd_mnt, "dev", PROTECT_OPATH_DIRECTORY, PROTECT_LOOKUP_BENEATH, 0);
}
if (ret < 0) { if (ret < 0) {
SYSERROR("Failed to mount tmpfs on \"%s\"", path); SYSERROR("Failed to mount tmpfs on \"%s\"", path);
goto reset_umask; goto reset_umask;
} }
}
TRACE("Mounted tmpfs on \"%s\"", path);
/* If we are running on a devtmpfs mapping, dev/pts may already exist. /* If we are running on a devtmpfs mapping, dev/pts may already exist.
* If not, then create it and exit if that fails... * If not, then create it and exit if that fails...
*/ */
ret = mkdirat(rootfs->dfd_mnt, "dev/pts", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); ret = mkdirat(rootfs->dfd_mnt, "dev/pts", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
if (ret < 0 && errno != EEXIST) { if (ret < 0 && errno != EEXIST) {
SYSERROR("Failed to create directory \"%s\"", path); SYSERROR("Failed to create directory \"dev/pts\"");
ret = -errno; ret = -errno;
goto reset_umask; goto reset_umask;
} }
......
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