mount_utils: move mount_at() and mount_from_at() over from utils.{c,h}

parent b5daeddc
...@@ -356,6 +356,7 @@ lxc_attach_SOURCES += af_unix.c af_unix.h \ ...@@ -356,6 +356,7 @@ lxc_attach_SOURCES += af_unix.c af_unix.h \
lxclock.c lxclock.h \ lxclock.c lxclock.h \
mainloop.c mainloop.h \ mainloop.c mainloop.h \
monitor.c monitor.h \ monitor.c monitor.h \
mount_utils.c mount_utils.h \
namespace.c namespace.h \ namespace.c namespace.h \
network.c network.h \ network.c network.h \
nl.c nl.h \ nl.c nl.h \
...@@ -413,6 +414,7 @@ lxc_autostart_SOURCES += af_unix.c af_unix.h \ ...@@ -413,6 +414,7 @@ lxc_autostart_SOURCES += af_unix.c af_unix.h \
lxclock.c lxclock.h \ lxclock.c lxclock.h \
mainloop.c mainloop.h \ mainloop.c mainloop.h \
monitor.c monitor.h \ monitor.c monitor.h \
mount_utils.c mount_utils.h \
namespace.c namespace.h \ namespace.c namespace.h \
network.c network.h \ network.c network.h \
nl.c nl.h \ nl.c nl.h \
...@@ -469,6 +471,7 @@ lxc_cgroup_SOURCES += af_unix.c af_unix.h \ ...@@ -469,6 +471,7 @@ lxc_cgroup_SOURCES += af_unix.c af_unix.h \
lxclock.c lxclock.h \ lxclock.c lxclock.h \
mainloop.c mainloop.h \ mainloop.c mainloop.h \
monitor.c monitor.h \ monitor.c monitor.h \
mount_utils.c mount_utils.h \
namespace.c namespace.h \ namespace.c namespace.h \
network.c network.h \ network.c network.h \
nl.c nl.h \ nl.c nl.h \
...@@ -525,6 +528,7 @@ lxc_config_SOURCES += af_unix.c af_unix.h \ ...@@ -525,6 +528,7 @@ lxc_config_SOURCES += af_unix.c af_unix.h \
lxclock.c lxclock.h \ lxclock.c lxclock.h \
mainloop.c mainloop.h \ mainloop.c mainloop.h \
monitor.c monitor.h \ monitor.c monitor.h \
mount_utils.c mount_utils.h \
namespace.c namespace.h \ namespace.c namespace.h \
network.c network.h \ network.c network.h \
nl.c nl.h \ nl.c nl.h \
...@@ -581,6 +585,7 @@ lxc_console_SOURCES += af_unix.c af_unix.h \ ...@@ -581,6 +585,7 @@ lxc_console_SOURCES += af_unix.c af_unix.h \
lxclock.c lxclock.h \ lxclock.c lxclock.h \
mainloop.c mainloop.h \ mainloop.c mainloop.h \
monitor.c monitor.h \ monitor.c monitor.h \
mount_utils.c mount_utils.h \
namespace.c namespace.h \ namespace.c namespace.h \
network.c network.h \ network.c network.h \
nl.c nl.h \ nl.c nl.h \
...@@ -637,6 +642,7 @@ lxc_destroy_SOURCES += af_unix.c af_unix.h \ ...@@ -637,6 +642,7 @@ lxc_destroy_SOURCES += af_unix.c af_unix.h \
lxclock.c lxclock.h \ lxclock.c lxclock.h \
mainloop.c mainloop.h \ mainloop.c mainloop.h \
monitor.c monitor.h \ monitor.c monitor.h \
mount_utils.c mount_utils.h \
namespace.c namespace.h \ namespace.c namespace.h \
network.c network.h \ network.c network.h \
nl.c nl.h \ nl.c nl.h \
...@@ -693,6 +699,7 @@ lxc_device_SOURCES += af_unix.c af_unix.h \ ...@@ -693,6 +699,7 @@ lxc_device_SOURCES += af_unix.c af_unix.h \
lxclock.c lxclock.h \ lxclock.c lxclock.h \
mainloop.c mainloop.h \ mainloop.c mainloop.h \
monitor.c monitor.h \ monitor.c monitor.h \
mount_utils.c mount_utils.h \
namespace.c namespace.h \ namespace.c namespace.h \
network.c network.h \ network.c network.h \
nl.c nl.h \ nl.c nl.h \
...@@ -749,6 +756,7 @@ lxc_execute_SOURCES += af_unix.c af_unix.h \ ...@@ -749,6 +756,7 @@ lxc_execute_SOURCES += af_unix.c af_unix.h \
lxclock.c lxclock.h \ lxclock.c lxclock.h \
mainloop.c mainloop.h \ mainloop.c mainloop.h \
monitor.c monitor.h \ monitor.c monitor.h \
mount_utils.c mount_utils.h \
namespace.c namespace.h \ namespace.c namespace.h \
network.c network.h \ network.c network.h \
nl.c nl.h \ nl.c nl.h \
...@@ -805,6 +813,7 @@ lxc_freeze_SOURCES += af_unix.c af_unix.h \ ...@@ -805,6 +813,7 @@ lxc_freeze_SOURCES += af_unix.c af_unix.h \
lxclock.c lxclock.h \ lxclock.c lxclock.h \
mainloop.c mainloop.h \ mainloop.c mainloop.h \
monitor.c monitor.h \ monitor.c monitor.h \
mount_utils.c mount_utils.h \
namespace.c namespace.h \ namespace.c namespace.h \
network.c network.h \ network.c network.h \
nl.c nl.h \ nl.c nl.h \
...@@ -861,6 +870,7 @@ lxc_info_SOURCES += af_unix.c af_unix.h \ ...@@ -861,6 +870,7 @@ lxc_info_SOURCES += af_unix.c af_unix.h \
lxclock.c lxclock.h \ lxclock.c lxclock.h \
mainloop.c mainloop.h \ mainloop.c mainloop.h \
monitor.c monitor.h \ monitor.c monitor.h \
mount_utils.c mount_utils.h \
namespace.c namespace.h \ namespace.c namespace.h \
network.c network.h \ network.c network.h \
nl.c nl.h \ nl.c nl.h \
...@@ -918,6 +928,7 @@ lxc_monitor_SOURCES += af_unix.c af_unix.h \ ...@@ -918,6 +928,7 @@ lxc_monitor_SOURCES += af_unix.c af_unix.h \
macro.h \ macro.h \
mainloop.c mainloop.h \ mainloop.c mainloop.h \
monitor.c monitor.h \ monitor.c monitor.h \
mount_utils.c mount_utils.h \
namespace.c namespace.h \ namespace.c namespace.h \
network.c network.h \ network.c network.h \
nl.c nl.h \ nl.c nl.h \
...@@ -975,6 +986,7 @@ lxc_ls_SOURCES += af_unix.c af_unix.h \ ...@@ -975,6 +986,7 @@ lxc_ls_SOURCES += af_unix.c af_unix.h \
mainloop.c mainloop.h \ mainloop.c mainloop.h \
memory_utils.h \ memory_utils.h \
monitor.c monitor.h \ monitor.c monitor.h \
mount_utils.c mount_utils.h \
namespace.c namespace.h \ namespace.c namespace.h \
network.c network.h \ network.c network.h \
nl.c nl.h \ nl.c nl.h \
...@@ -1031,6 +1043,7 @@ lxc_copy_SOURCES += af_unix.c af_unix.h \ ...@@ -1031,6 +1043,7 @@ lxc_copy_SOURCES += af_unix.c af_unix.h \
lxclock.c lxclock.h \ lxclock.c lxclock.h \
mainloop.c mainloop.h \ mainloop.c mainloop.h \
monitor.c monitor.h \ monitor.c monitor.h \
mount_utils.c mount_utils.h \
namespace.c namespace.h \ namespace.c namespace.h \
network.c network.h \ network.c network.h \
nl.c nl.h \ nl.c nl.h \
...@@ -1087,6 +1100,7 @@ lxc_start_SOURCES += af_unix.c af_unix.h \ ...@@ -1087,6 +1100,7 @@ lxc_start_SOURCES += af_unix.c af_unix.h \
lxclock.c lxclock.h \ lxclock.c lxclock.h \
mainloop.c mainloop.h \ mainloop.c mainloop.h \
monitor.c monitor.h \ monitor.c monitor.h \
mount_utils.c mount_utils.h \
namespace.c namespace.h \ namespace.c namespace.h \
network.c network.h \ network.c network.h \
nl.c nl.h \ nl.c nl.h \
...@@ -1143,6 +1157,7 @@ lxc_stop_SOURCES += af_unix.c af_unix.h \ ...@@ -1143,6 +1157,7 @@ lxc_stop_SOURCES += af_unix.c af_unix.h \
lxclock.c lxclock.h \ lxclock.c lxclock.h \
mainloop.c mainloop.h \ mainloop.c mainloop.h \
monitor.c monitor.h \ monitor.c monitor.h \
mount_utils.c mount_utils.h \
namespace.c namespace.h \ namespace.c namespace.h \
network.c network.h \ network.c network.h \
nl.c nl.h \ nl.c nl.h \
...@@ -1199,6 +1214,7 @@ lxc_top_SOURCES += af_unix.c af_unix.h \ ...@@ -1199,6 +1214,7 @@ lxc_top_SOURCES += af_unix.c af_unix.h \
lxclock.c lxclock.h \ lxclock.c lxclock.h \
mainloop.c mainloop.h \ mainloop.c mainloop.h \
monitor.c monitor.h \ monitor.c monitor.h \
mount_utils.c mount_utils.h \
namespace.c namespace.h \ namespace.c namespace.h \
network.c network.h \ network.c network.h \
nl.c nl.h \ nl.c nl.h \
...@@ -1255,6 +1271,7 @@ lxc_unfreeze_SOURCES += af_unix.c af_unix.h \ ...@@ -1255,6 +1271,7 @@ lxc_unfreeze_SOURCES += af_unix.c af_unix.h \
lxclock.c lxclock.h \ lxclock.c lxclock.h \
mainloop.c mainloop.h \ mainloop.c mainloop.h \
monitor.c monitor.h \ monitor.c monitor.h \
mount_utils.c mount_utils.h \
namespace.c namespace.h \ namespace.c namespace.h \
network.c network.h \ network.c network.h \
nl.c nl.h \ nl.c nl.h \
...@@ -1311,6 +1328,7 @@ lxc_unshare_SOURCES += af_unix.c af_unix.h \ ...@@ -1311,6 +1328,7 @@ lxc_unshare_SOURCES += af_unix.c af_unix.h \
lxclock.c lxclock.h \ lxclock.c lxclock.h \
mainloop.c mainloop.h \ mainloop.c mainloop.h \
monitor.c monitor.h \ monitor.c monitor.h \
mount_utils.c mount_utils.h \
namespace.c namespace.h \ namespace.c namespace.h \
network.c network.h \ network.c network.h \
nl.c nl.h \ nl.c nl.h \
...@@ -1369,6 +1387,7 @@ lxc_wait_SOURCES += af_unix.c af_unix.h \ ...@@ -1369,6 +1387,7 @@ lxc_wait_SOURCES += af_unix.c af_unix.h \
lxclock.c lxclock.h \ lxclock.c lxclock.h \
mainloop.c mainloop.h \ mainloop.c mainloop.h \
monitor.c monitor.h \ monitor.c monitor.h \
mount_utils.c mount_utils.h \
namespace.c namespace.h \ namespace.c namespace.h \
network.c network.h \ network.c network.h \
nl.c nl.h \ nl.c nl.h \
...@@ -1425,6 +1444,7 @@ lxc_create_SOURCES += af_unix.c af_unix.h \ ...@@ -1425,6 +1444,7 @@ lxc_create_SOURCES += af_unix.c af_unix.h \
lxclock.c lxclock.h \ lxclock.c lxclock.h \
mainloop.c mainloop.h \ mainloop.c mainloop.h \
monitor.c monitor.h \ monitor.c monitor.h \
mount_utils.c mount_utils.h \
namespace.c namespace.h \ namespace.c namespace.h \
network.c network.h \ network.c network.h \
nl.c nl.h \ nl.c nl.h \
...@@ -1481,6 +1501,7 @@ lxc_snapshot_SOURCES += af_unix.c af_unix.h \ ...@@ -1481,6 +1501,7 @@ lxc_snapshot_SOURCES += af_unix.c af_unix.h \
lxclock.c lxclock.h \ lxclock.c lxclock.h \
mainloop.c mainloop.h \ mainloop.c mainloop.h \
monitor.c monitor.h \ monitor.c monitor.h \
mount_utils.c mount_utils.h \
namespace.c namespace.h \ namespace.c namespace.h \
network.c network.h \ network.c network.h \
nl.c nl.h \ nl.c nl.h \
...@@ -1537,6 +1558,7 @@ lxc_checkpoint_SOURCES += af_unix.c af_unix.h \ ...@@ -1537,6 +1558,7 @@ lxc_checkpoint_SOURCES += af_unix.c af_unix.h \
lxclock.c lxclock.h \ lxclock.c lxclock.h \
mainloop.c mainloop.h \ mainloop.c mainloop.h \
monitor.c monitor.h \ monitor.c monitor.h \
mount_utils.c mount_utils.h \
namespace.c namespace.h \ namespace.c namespace.h \
network.c network.h \ network.c network.h \
nl.c nl.h \ nl.c nl.h \
...@@ -1608,6 +1630,7 @@ lxc_monitord_SOURCES += af_unix.c af_unix.h \ ...@@ -1608,6 +1630,7 @@ lxc_monitord_SOURCES += af_unix.c af_unix.h \
lxclock.c lxclock.h \ lxclock.c lxclock.h \
mainloop.c mainloop.h \ mainloop.c mainloop.h \
monitor.c monitor.h \ monitor.c monitor.h \
mount_utils.c mount_utils.h \
namespace.c namespace.h \ namespace.c namespace.h \
network.c network.h \ network.c network.h \
nl.c nl.h \ nl.c nl.h \
...@@ -1665,6 +1688,7 @@ lxc_user_nic_SOURCES += af_unix.c af_unix.h \ ...@@ -1665,6 +1688,7 @@ lxc_user_nic_SOURCES += af_unix.c af_unix.h \
mainloop.c mainloop.h \ mainloop.c mainloop.h \
memory_utils.h \ memory_utils.h \
monitor.c monitor.h \ monitor.c monitor.h \
mount_utils.c mount_utils.h \
namespace.c namespace.h \ namespace.c namespace.h \
network.c network.h \ network.c network.h \
nl.c nl.h \ nl.c nl.h \
...@@ -1725,6 +1749,7 @@ lxc_usernsexec_SOURCES += af_unix.c af_unix.h \ ...@@ -1725,6 +1749,7 @@ lxc_usernsexec_SOURCES += af_unix.c af_unix.h \
mainloop.c mainloop.h \ mainloop.c mainloop.h \
memory_utils.h \ memory_utils.h \
monitor.c monitor.h \ monitor.c monitor.h \
mount_utils.c mount_utils.h \
namespace.c namespace.h \ namespace.c namespace.h \
network.c network.h \ network.c network.h \
nl.c nl.h \ nl.c nl.h \
......
...@@ -44,6 +44,7 @@ ...@@ -44,6 +44,7 @@
#include "macro.h" #include "macro.h"
#include "mainloop.h" #include "mainloop.h"
#include "memory_utils.h" #include "memory_utils.h"
#include "mount_utils.h"
#include "storage/storage.h" #include "storage/storage.h"
#include "syscall_wrappers.h" #include "syscall_wrappers.h"
#include "utils.h" #include "utils.h"
......
...@@ -138,3 +138,107 @@ int mount_filesystem(const char *fs_name, const char *path, unsigned int attr_fl ...@@ -138,3 +138,107 @@ int mount_filesystem(const char *fs_name, const char *path, unsigned int attr_fl
mnt_attributes_old(attr_flags, &old_flags); mnt_attributes_old(attr_flags, &old_flags);
return mount("none", path, fs_name, old_flags, NULL); return mount("none", path, fs_name, old_flags, NULL);
} }
int mount_at(int dfd,
const char *src_under_dfd,
const char *dst_under_dfd,
__u64 o_flags,
__u64 resolve_flags,
const char *fstype,
unsigned int mnt_flags,
const void *data)
{
__do_close int source_fd = -EBADF, target_fd = -EBADF;
struct lxc_open_how how = {
.flags = o_flags,
.resolve = resolve_flags,
};
int ret;
char src_buf[LXC_PROC_PID_FD_LEN], dst_buf[LXC_PROC_PID_FD_LEN];
if (dfd < 0)
return ret_errno(EINVAL);
if (!is_empty_string(src_buf) && *src_buf == '/')
return log_error_errno(-EINVAL, EINVAL, "Absolute path specified");
if (!is_empty_string(src_under_dfd)) {
source_fd = openat2(dfd, src_under_dfd, &how, sizeof(how));
if (source_fd < 0)
return -errno;
ret = snprintf(src_buf, sizeof(src_buf), "/proc/self/fd/%d", source_fd);
if (ret < 0 || ret >= sizeof(src_buf))
return -EIO;
}
if (!is_empty_string(dst_under_dfd)) {
target_fd = openat2(dfd, dst_under_dfd, &how, sizeof(how));
if (target_fd < 0)
return log_error_errno(-errno, errno, "Failed to open %d(%s)", dfd, dst_under_dfd);
TRACE("Mounting %d(%s) through /proc/self/fd/%d", target_fd, dst_under_dfd, target_fd);
ret = snprintf(dst_buf, sizeof(dst_buf), "/proc/self/fd/%d", target_fd);
} else {
TRACE("Mounting %d through /proc/self/fd/%d", dfd, dfd);
ret = snprintf(dst_buf, sizeof(dst_buf), "/proc/self/fd/%d", dfd);
}
if (ret < 0 || ret >= sizeof(dst_buf))
return -EIO;
if (!is_empty_string(src_buf))
ret = mount(src_buf, dst_buf, fstype, mnt_flags, data);
else
ret = mount(NULL, dst_buf, fstype, mnt_flags, data);
return ret;
}
int mount_from_at(int dfd_from, const char *path_from,
__u64 o_flags_from,
__u64 resolve_flags_from,
int dfd_to, const char *path_to,
__u64 o_flags_to,
__u64 resolve_flags_to,
const char *fstype, unsigned int mnt_flags, const void *data)
{
__do_close int fd_from = -EBADF, fd_to = -EBADF;
struct lxc_open_how how = {};
int ret;
char src_buf[LXC_PROC_PID_FD_LEN], dst_buf[LXC_PROC_PID_FD_LEN];
if (is_empty_string(path_from)) {
ret = snprintf(src_buf, sizeof(src_buf), "/proc/self/fd/%d", dfd_from);
} else {
how.flags = o_flags_from;
how.resolve = resolve_flags_from;
fd_from = openat2(dfd_from, path_from, &how, sizeof(how));
if (fd_from < 0)
return -errno;
ret = snprintf(src_buf, sizeof(src_buf), "/proc/self/fd/%d", fd_from);
}
if (ret < 0 || ret >= sizeof(src_buf))
return -EIO;
if (is_empty_string(path_to)) {
ret = snprintf(dst_buf, sizeof(dst_buf), "/proc/self/fd/%d", dfd_to);
} else {
how.flags = o_flags_to;
how.resolve = resolve_flags_to;
fd_to = openat2(dfd_to, path_to, &how, sizeof(how));
if (fd_to < 0)
return -errno;
ret = snprintf(dst_buf, sizeof(dst_buf), "/proc/self/fd/%d", fd_to);
}
if (ret < 0 || ret >= sizeof(src_buf))
return -EIO;
if (is_empty_string(src_buf))
ret = mount(NULL, dst_buf, fstype, mnt_flags, data);
else
ret = mount(src_buf, dst_buf, fstype, mnt_flags, data);
return ret;
}
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#ifndef __LXC_MOUNT_UTILS_H #ifndef __LXC_MOUNT_UTILS_H
#define __LXC_MOUNT_UTILS_H #define __LXC_MOUNT_UTILS_H
#include <linux/types.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <sys/mount.h> #include <sys/mount.h>
...@@ -150,4 +151,16 @@ __hidden extern int mnt_attributes_old(unsigned int new_flags, unsigned int *old ...@@ -150,4 +151,16 @@ __hidden extern int mnt_attributes_old(unsigned int new_flags, unsigned int *old
__hidden extern int mount_filesystem(const char *fs_name, const char *path, unsigned int attr_flags); __hidden extern int mount_filesystem(const char *fs_name, const char *path, unsigned int attr_flags);
__hidden extern int mount_at(int dfd, const char *src_under_dfd,
const char *dst_under_dfd, __u64 o_flags,
__u64 resolve_flags, const char *fstype,
unsigned int mnt_flags, const void *data);
__hidden extern int mount_from_at(int dfd_from, const char *path_from,
__u64 o_flags_from, __u64 resolve_flags_from,
int dfd_to, const char *path_to,
__u64 o_flags_to, __u64 resolve_flags_to,
const char *fstype, unsigned int mnt_flags,
const void *data);
#endif /* __LXC_MOUNT_UTILS_H */ #endif /* __LXC_MOUNT_UTILS_H */
...@@ -1208,110 +1208,6 @@ int safe_mount(const char *src, const char *dest, const char *fstype, ...@@ -1208,110 +1208,6 @@ int safe_mount(const char *src, const char *dest, const char *fstype,
return 0; return 0;
} }
int mount_at(int dfd,
const char *src_under_dfd,
const char *dst_under_dfd,
__u64 o_flags,
__u64 resolve_flags,
const char *fstype,
unsigned int mnt_flags,
const void *data)
{
__do_close int source_fd = -EBADF, target_fd = -EBADF;
struct lxc_open_how how = {
.flags = o_flags,
.resolve = resolve_flags,
};
int ret;
char src_buf[LXC_PROC_PID_FD_LEN], dst_buf[LXC_PROC_PID_FD_LEN];
if (dfd < 0)
return ret_errno(EINVAL);
if (!is_empty_string(src_buf) && *src_buf == '/')
return log_error_errno(-EINVAL, EINVAL, "Absolute path specified");
if (!is_empty_string(src_under_dfd)) {
source_fd = openat2(dfd, src_under_dfd, &how, sizeof(how));
if (source_fd < 0)
return -errno;
ret = snprintf(src_buf, sizeof(src_buf), "/proc/self/fd/%d", source_fd);
if (ret < 0 || ret >= sizeof(src_buf))
return -EIO;
}
if (!is_empty_string(dst_under_dfd)) {
target_fd = openat2(dfd, dst_under_dfd, &how, sizeof(how));
if (target_fd < 0)
return log_error_errno(-errno, errno, "Failed to open %d(%s)", dfd, dst_under_dfd);
TRACE("Mounting %d(%s) through /proc/self/fd/%d", target_fd, dst_under_dfd, target_fd);
ret = snprintf(dst_buf, sizeof(dst_buf), "/proc/self/fd/%d", target_fd);
} else {
TRACE("Mounting %d through /proc/self/fd/%d", dfd, dfd);
ret = snprintf(dst_buf, sizeof(dst_buf), "/proc/self/fd/%d", dfd);
}
if (ret < 0 || ret >= sizeof(dst_buf))
return -EIO;
if (!is_empty_string(src_buf))
ret = mount(src_buf, dst_buf, fstype, mnt_flags, data);
else
ret = mount(NULL, dst_buf, fstype, mnt_flags, data);
return ret;
}
int mount_from_at(int dfd_from, const char *path_from,
__u64 o_flags_from,
__u64 resolve_flags_from,
int dfd_to, const char *path_to,
__u64 o_flags_to,
__u64 resolve_flags_to,
const char *fstype, unsigned int mnt_flags, const void *data)
{
__do_close int fd_from = -EBADF, fd_to = -EBADF;
struct lxc_open_how how = {};
int ret;
char src_buf[LXC_PROC_PID_FD_LEN], dst_buf[LXC_PROC_PID_FD_LEN];
if (is_empty_string(path_from)) {
ret = snprintf(src_buf, sizeof(src_buf), "/proc/self/fd/%d", dfd_from);
} else {
how.flags = o_flags_from;
how.resolve = resolve_flags_from;
fd_from = openat2(dfd_from, path_from, &how, sizeof(how));
if (fd_from < 0)
return -errno;
ret = snprintf(src_buf, sizeof(src_buf), "/proc/self/fd/%d", fd_from);
}
if (ret < 0 || ret >= sizeof(src_buf))
return -EIO;
if (is_empty_string(path_to)) {
ret = snprintf(dst_buf, sizeof(dst_buf), "/proc/self/fd/%d", dfd_to);
} else {
how.flags = o_flags_to;
how.resolve = resolve_flags_to;
fd_to = openat2(dfd_to, path_to, &how, sizeof(how));
if (fd_to < 0)
return -errno;
ret = snprintf(dst_buf, sizeof(dst_buf), "/proc/self/fd/%d", fd_to);
}
if (ret < 0 || ret >= sizeof(src_buf))
return -EIO;
if (is_empty_string(src_buf))
ret = mount(NULL, dst_buf, fstype, mnt_flags, data);
else
ret = mount(src_buf, dst_buf, fstype, mnt_flags, data);
return ret;
}
int open_devnull(void) int open_devnull(void)
{ {
int fd = open("/dev/null", O_RDWR); int fd = open("/dev/null", O_RDWR);
......
...@@ -244,15 +244,5 @@ __hidden extern int safe_mount_beneath(const char *beneath, const char *src, con ...@@ -244,15 +244,5 @@ __hidden extern int safe_mount_beneath(const char *beneath, const char *src, con
const char *fstype, unsigned int flags, const void *data); const char *fstype, unsigned int flags, const void *data);
__hidden extern int safe_mount_beneath_at(int beneat_fd, const char *src, const char *dst, __hidden extern int safe_mount_beneath_at(int beneat_fd, const char *src, const char *dst,
const char *fstype, unsigned int flags, const void *data); const char *fstype, unsigned int flags, const void *data);
__hidden extern int mount_at(int dfd, const char *src_under_dfd,
const char *dst_under_dfd, __u64 o_flags,
__u64 resolve_flags, const char *fstype,
unsigned int mnt_flags, const void *data);
__hidden extern int mount_from_at(int dfd_from, const char *path_from,
__u64 o_flags_from, __u64 resolve_flags_from,
int dfd_to, const char *path_to,
__u64 o_flags_to, __u64 resolve_flags_to,
const char *fstype, unsigned int mnt_flags,
const void *data);
#endif /* __LXC_UTILS_H */ #endif /* __LXC_UTILS_H */
...@@ -39,6 +39,7 @@ lxc_test_api_reboot_SOURCES = api_reboot.c \ ...@@ -39,6 +39,7 @@ lxc_test_api_reboot_SOURCES = api_reboot.c \
../lxc/lxclock.c ../lxc/lxclock.h \ ../lxc/lxclock.c ../lxc/lxclock.h \
../lxc/mainloop.c ../lxc/mainloop.h \ ../lxc/mainloop.c ../lxc/mainloop.h \
../lxc/monitor.c ../lxc/monitor.h \ ../lxc/monitor.c ../lxc/monitor.h \
../lxc/mount_utils.c ../lxc/mount_utils.h \
../lxc/namespace.c ../lxc/namespace.h \ ../lxc/namespace.c ../lxc/namespace.h \
../lxc/network.c ../lxc/network.h \ ../lxc/network.c ../lxc/network.h \
../lxc/nl.c ../lxc/nl.h \ ../lxc/nl.c ../lxc/nl.h \
...@@ -88,6 +89,7 @@ lxc_test_apparmor_SOURCES = aa.c \ ...@@ -88,6 +89,7 @@ lxc_test_apparmor_SOURCES = aa.c \
../lxc/lxclock.c ../lxc/lxclock.h \ ../lxc/lxclock.c ../lxc/lxclock.h \
../lxc/mainloop.c ../lxc/mainloop.h \ ../lxc/mainloop.c ../lxc/mainloop.h \
../lxc/monitor.c ../lxc/monitor.h \ ../lxc/monitor.c ../lxc/monitor.h \
../lxc/mount_utils.c ../lxc/mount_utils.h \
../lxc/namespace.c ../lxc/namespace.h \ ../lxc/namespace.c ../lxc/namespace.h \
../lxc/network.c ../lxc/network.h \ ../lxc/network.c ../lxc/network.h \
../lxc/nl.c ../lxc/nl.h \ ../lxc/nl.c ../lxc/nl.h \
...@@ -137,6 +139,7 @@ lxc_test_attach_SOURCES = attach.c \ ...@@ -137,6 +139,7 @@ lxc_test_attach_SOURCES = attach.c \
../lxc/lxclock.c ../lxc/lxclock.h \ ../lxc/lxclock.c ../lxc/lxclock.h \
../lxc/mainloop.c ../lxc/mainloop.h \ ../lxc/mainloop.c ../lxc/mainloop.h \
../lxc/monitor.c ../lxc/monitor.h \ ../lxc/monitor.c ../lxc/monitor.h \
../lxc/mount_utils.c ../lxc/mount_utils.h \
../lxc/namespace.c ../lxc/namespace.h \ ../lxc/namespace.c ../lxc/namespace.h \
../lxc/network.c ../lxc/network.h \ ../lxc/network.c ../lxc/network.h \
../lxc/nl.c ../lxc/nl.h \ ../lxc/nl.c ../lxc/nl.h \
...@@ -187,6 +190,7 @@ lxc_test_cgpath_SOURCES = cgpath.c \ ...@@ -187,6 +190,7 @@ lxc_test_cgpath_SOURCES = cgpath.c \
../lxc/lxclock.c ../lxc/lxclock.h \ ../lxc/lxclock.c ../lxc/lxclock.h \
../lxc/mainloop.c ../lxc/mainloop.h \ ../lxc/mainloop.c ../lxc/mainloop.h \
../lxc/monitor.c ../lxc/monitor.h \ ../lxc/monitor.c ../lxc/monitor.h \
../lxc/mount_utils.c ../lxc/mount_utils.h \
../lxc/namespace.c ../lxc/namespace.h \ ../lxc/namespace.c ../lxc/namespace.h \
../lxc/network.c ../lxc/network.h \ ../lxc/network.c ../lxc/network.h \
../lxc/nl.c ../lxc/nl.h \ ../lxc/nl.c ../lxc/nl.h \
...@@ -239,6 +243,7 @@ lxc_test_config_jump_table_SOURCES = config_jump_table.c \ ...@@ -239,6 +243,7 @@ lxc_test_config_jump_table_SOURCES = config_jump_table.c \
../lxc/lxclock.c ../lxc/lxclock.h \ ../lxc/lxclock.c ../lxc/lxclock.h \
../lxc/mainloop.c ../lxc/mainloop.h \ ../lxc/mainloop.c ../lxc/mainloop.h \
../lxc/monitor.c ../lxc/monitor.h \ ../lxc/monitor.c ../lxc/monitor.h \
../lxc/mount_utils.c ../lxc/mount_utils.h \
../lxc/namespace.c ../lxc/namespace.h \ ../lxc/namespace.c ../lxc/namespace.h \
../lxc/network.c ../lxc/network.h \ ../lxc/network.c ../lxc/network.h \
../lxc/nl.c ../lxc/nl.h \ ../lxc/nl.c ../lxc/nl.h \
...@@ -295,6 +300,7 @@ lxc_test_device_add_remove_SOURCES = device_add_remove.c \ ...@@ -295,6 +300,7 @@ lxc_test_device_add_remove_SOURCES = device_add_remove.c \
../lxc/lxclock.c ../lxc/lxclock.h \ ../lxc/lxclock.c ../lxc/lxclock.h \
../lxc/mainloop.c ../lxc/mainloop.h \ ../lxc/mainloop.c ../lxc/mainloop.h \
../lxc/monitor.c ../lxc/monitor.h \ ../lxc/monitor.c ../lxc/monitor.h \
../lxc/mount_utils.c ../lxc/mount_utils.h \
../lxc/namespace.c ../lxc/namespace.h \ ../lxc/namespace.c ../lxc/namespace.h \
../lxc/network.c ../lxc/network.h \ ../lxc/network.c ../lxc/network.h \
../lxc/nl.c ../lxc/nl.h \ ../lxc/nl.c ../lxc/nl.h \
...@@ -344,6 +350,7 @@ lxc_test_get_item_SOURCES = get_item.c \ ...@@ -344,6 +350,7 @@ lxc_test_get_item_SOURCES = get_item.c \
../lxc/lxclock.c ../lxc/lxclock.h \ ../lxc/lxclock.c ../lxc/lxclock.h \
../lxc/mainloop.c ../lxc/mainloop.h \ ../lxc/mainloop.c ../lxc/mainloop.h \
../lxc/monitor.c ../lxc/monitor.h \ ../lxc/monitor.c ../lxc/monitor.h \
../lxc/mount_utils.c ../lxc/mount_utils.h \
../lxc/namespace.c ../lxc/namespace.h \ ../lxc/namespace.c ../lxc/namespace.h \
../lxc/network.c ../lxc/network.h \ ../lxc/network.c ../lxc/network.h \
../lxc/nl.c ../lxc/nl.h \ ../lxc/nl.c ../lxc/nl.h \
...@@ -393,6 +400,7 @@ lxc_test_locktests_SOURCES = locktests.c \ ...@@ -393,6 +400,7 @@ lxc_test_locktests_SOURCES = locktests.c \
../lxc/lxclock.c ../lxc/lxclock.h \ ../lxc/lxclock.c ../lxc/lxclock.h \
../lxc/mainloop.c ../lxc/mainloop.h \ ../lxc/mainloop.c ../lxc/mainloop.h \
../lxc/monitor.c ../lxc/monitor.h \ ../lxc/monitor.c ../lxc/monitor.h \
../lxc/mount_utils.c ../lxc/mount_utils.h \
../lxc/namespace.c ../lxc/namespace.h \ ../lxc/namespace.c ../lxc/namespace.h \
../lxc/network.c ../lxc/network.h \ ../lxc/network.c ../lxc/network.h \
../lxc/nl.c ../lxc/nl.h \ ../lxc/nl.c ../lxc/nl.h \
...@@ -445,6 +453,7 @@ lxc_test_mount_injection_SOURCES = mount_injection.c \ ...@@ -445,6 +453,7 @@ lxc_test_mount_injection_SOURCES = mount_injection.c \
../lxc/lxclock.c ../lxc/lxclock.h \ ../lxc/lxclock.c ../lxc/lxclock.h \
../lxc/mainloop.c ../lxc/mainloop.h \ ../lxc/mainloop.c ../lxc/mainloop.h \
../lxc/monitor.c ../lxc/monitor.h \ ../lxc/monitor.c ../lxc/monitor.h \
../lxc/mount_utils.c ../lxc/mount_utils.h \
../lxc/namespace.c ../lxc/namespace.h \ ../lxc/namespace.c ../lxc/namespace.h \
../lxc/network.c ../lxc/network.h \ ../lxc/network.c ../lxc/network.h \
../lxc/nl.c ../lxc/nl.h \ ../lxc/nl.c ../lxc/nl.h \
...@@ -495,6 +504,7 @@ lxc_test_parse_config_file_SOURCES = parse_config_file.c \ ...@@ -495,6 +504,7 @@ lxc_test_parse_config_file_SOURCES = parse_config_file.c \
../lxc/lxclock.c ../lxc/lxclock.h \ ../lxc/lxclock.c ../lxc/lxclock.h \
../lxc/mainloop.c ../lxc/mainloop.h \ ../lxc/mainloop.c ../lxc/mainloop.h \
../lxc/monitor.c ../lxc/monitor.h \ ../lxc/monitor.c ../lxc/monitor.h \
../lxc/mount_utils.c ../lxc/mount_utils.h \
../lxc/namespace.c ../lxc/namespace.h \ ../lxc/namespace.c ../lxc/namespace.h \
../lxc/network.c ../lxc/network.h \ ../lxc/network.c ../lxc/network.h \
../lxc/nl.c ../lxc/nl.h \ ../lxc/nl.c ../lxc/nl.h \
...@@ -545,6 +555,7 @@ lxc_test_raw_clone_SOURCES = lxc_raw_clone.c \ ...@@ -545,6 +555,7 @@ lxc_test_raw_clone_SOURCES = lxc_raw_clone.c \
../lxc/lxclock.c ../lxc/lxclock.h \ ../lxc/lxclock.c ../lxc/lxclock.h \
../lxc/mainloop.c ../lxc/mainloop.h \ ../lxc/mainloop.c ../lxc/mainloop.h \
../lxc/monitor.c ../lxc/monitor.h \ ../lxc/monitor.c ../lxc/monitor.h \
../lxc/mount_utils.c ../lxc/mount_utils.h \
../lxc/namespace.c ../lxc/namespace.h \ ../lxc/namespace.c ../lxc/namespace.h \
../lxc/network.c ../lxc/network.h \ ../lxc/network.c ../lxc/network.h \
../lxc/nl.c ../lxc/nl.h \ ../lxc/nl.c ../lxc/nl.h \
...@@ -609,6 +620,7 @@ lxc_test_utils_SOURCES = lxc-test-utils.c \ ...@@ -609,6 +620,7 @@ lxc_test_utils_SOURCES = lxc-test-utils.c \
../lxc/lxclock.c ../lxc/lxclock.h \ ../lxc/lxclock.c ../lxc/lxclock.h \
../lxc/mainloop.c ../lxc/mainloop.h \ ../lxc/mainloop.c ../lxc/mainloop.h \
../lxc/monitor.c ../lxc/monitor.h \ ../lxc/monitor.c ../lxc/monitor.h \
../lxc/mount_utils.c ../lxc/mount_utils.h \
../lxc/namespace.c ../lxc/namespace.h \ ../lxc/namespace.c ../lxc/namespace.h \
../lxc/network.c ../lxc/network.h \ ../lxc/network.c ../lxc/network.h \
../lxc/nl.c ../lxc/nl.h \ ../lxc/nl.c ../lxc/nl.h \
......
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