aboutsummaryrefslogtreecommitdiffstats
path: root/libmount/src/hook_subdir.c
diff options
context:
space:
mode:
Diffstat (limited to 'libmount/src/hook_subdir.c')
-rw-r--r--libmount/src/hook_subdir.c31
1 files changed, 19 insertions, 12 deletions
diff --git a/libmount/src/hook_subdir.c b/libmount/src/hook_subdir.c
index 65674aa9e8..99c30e1738 100644
--- a/libmount/src/hook_subdir.c
+++ b/libmount/src/hook_subdir.c
@@ -165,17 +165,29 @@ static int tmptgt_cleanup(struct hookset_data *hsd)
static int do_mount_subdir(
struct libmnt_context *cxt,
struct hookset_data *hsd,
- const char *root,
- const char *target)
+ const char *root)
{
int rc = 0;
const char *subdir = hsd->subdir;
+ const char *target;
#ifdef USE_LIBMOUNT_MOUNTFD_SUPPORT
- struct libmnt_sysapi *api;
+ struct libmnt_sysapi *api = mnt_context_get_sysapi(cxt);
+
+ /* fallback only; necessary when hook_mount.c during preparation
+ * cannot open the tree -- for example when we call /sbin/mount.<type> */
+ if (api && api->fd_tree < 0) {
+ api->fd_tree = mnt_context_open_tree(cxt, NULL, (unsigned long) -1);
+ if (api->fd_tree < 0)
+ return api->fd_tree;
+ }
+#endif
+ /* reset to the original mountpoint */
+ mnt_fs_set_target(cxt->fs, hsd->org_target);
+ target = mnt_fs_get_target(cxt->fs);
- api = mnt_context_get_sysapi(cxt);
- if (api) {
+#ifdef USE_LIBMOUNT_MOUNTFD_SUPPORT
+ if (api && api->fd_tree >= 0) {
/* FD based way - unfortunately, it's impossible to open
* sub-directory on not-yet attached mount. It means
* hook_mount.c attaches FS to temporary directory, and we
@@ -186,7 +198,7 @@ static int do_mount_subdir(
*/
int fd;
- DBG(HOOK, ul_debug("attach subdir %s", subdir));
+ DBG(HOOK, ul_debug("attach subdir '%s'", subdir));
fd = open_tree(api->fd_tree, subdir,
OPEN_TREE_CLOEXEC | OPEN_TREE_CLONE);
mnt_context_syscall_save_status(cxt, "open_tree", fd >= 0);
@@ -255,13 +267,8 @@ static int hook_mount_post(
if (!hsd || !hsd->subdir)
return 0;
- /* reset to the original mountpoint */
- mnt_fs_set_target(cxt->fs, hsd->org_target);
-
/* bind subdir to the real target, umount temporary target */
- rc = do_mount_subdir(cxt, hsd,
- MNT_PATH_TMPTGT,
- mnt_fs_get_target(cxt->fs));
+ rc = do_mount_subdir(cxt, hsd, MNT_PATH_TMPTGT);
if (rc)
return rc;