Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
lxc
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
lxc
Commits
041d1e30
Unverified
Commit
041d1e30
authored
Feb 05, 2021
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mount_utils: add support for bind-mounts through the new mount api
fd_bind_mount() Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
ca9055b4
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
0 deletions
+66
-0
mount_utils.c
src/lxc/mount_utils.c
+55
-0
mount_utils.h
src/lxc/mount_utils.h
+11
-0
No files found.
src/lxc/mount_utils.c
View file @
041d1e30
...
@@ -4,6 +4,7 @@
...
@@ -4,6 +4,7 @@
#define _GNU_SOURCE 1
#define _GNU_SOURCE 1
#endif
#endif
#include <fcntl.h>
#include <fcntl.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <sys/mount.h>
#include <sys/mount.h>
...
@@ -302,3 +303,57 @@ int mount_from_at(int dfd_from, const char *path_from,
...
@@ -302,3 +303,57 @@ int mount_from_at(int dfd_from, const char *path_from,
return
ret
;
return
ret
;
}
}
int
fd_bind_mount
(
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
,
unsigned
int
attr_flags
,
bool
recursive
)
{
__do_close
int
__fd_from
=
-
EBADF
,
__fd_to
=
-
EBADF
;
__do_close
int
fd_tree_from
=
-
EBADF
;
unsigned
int
open_tree_flags
=
AT_EMPTY_PATH
|
OPEN_TREE_CLONE
|
OPEN_TREE_CLONE
;
int
fd_from
,
fd_to
,
ret
;
if
(
!
is_empty_string
(
path_from
))
{
struct
lxc_open_how
how
=
{
.
flags
=
o_flags_from
,
.
resolve
=
resolve_flags_from
,
};
__fd_from
=
openat2
(
dfd_from
,
path_from
,
&
how
,
sizeof
(
how
));
if
(
__fd_from
<
0
)
return
-
errno
;
fd_from
=
__fd_from
;
}
else
{
fd_from
=
dfd_from
;
}
if
(
recursive
)
open_tree_flags
|=
AT_RECURSIVE
;
fd_tree_from
=
open_tree
(
fd_from
,
""
,
open_tree_flags
);
if
(
fd_tree_from
<
0
)
return
log_error_errno
(
-
errno
,
errno
,
"Failed to create detached mount"
);
if
(
!
is_empty_string
(
path_to
))
{
struct
lxc_open_how
how
=
{
.
flags
=
o_flags_to
,
.
resolve
=
resolve_flags_to
,
};
__fd_to
=
openat2
(
dfd_to
,
path_to
,
&
how
,
sizeof
(
how
));
if
(
__fd_to
<
0
)
return
-
errno
;
fd_to
=
__fd_to
;
}
else
{
fd_to
=
dfd_to
;
}
ret
=
move_mount
(
fd_tree_from
,
""
,
fd_to
,
""
,
MOVE_MOUNT_F_EMPTY_PATH
|
MOVE_MOUNT_T_EMPTY_PATH
);
if
(
ret
)
return
log_error_errno
(
-
errno
,
errno
,
"Failed to attach detached mount %d to filesystem at %d"
,
fd_tree_from
,
fd_to
);
TRACE
(
"Attach detached mount %d to filesystem at %d"
,
fd_tree_from
,
fd_to
);
return
0
;
}
src/lxc/mount_utils.h
View file @
041d1e30
...
@@ -12,6 +12,11 @@
...
@@ -12,6 +12,11 @@
#include "memory_utils.h"
#include "memory_utils.h"
/* open_tree() flags */
/* open_tree() flags */
#ifndef AT_RECURSIVE
#define AT_RECURSIVE 0x8000
/* Apply to the entire subtree */
#endif
#ifndef OPEN_TREE_CLONE
#ifndef OPEN_TREE_CLONE
#define OPEN_TREE_CLONE 1
#define OPEN_TREE_CLONE 1
#endif
#endif
...
@@ -181,4 +186,10 @@ static inline int fs_mount(const char *fs_name, int dfd_from,
...
@@ -181,4 +186,10 @@ static inline int fs_mount(const char *fs_name, int dfd_from,
return
fs_attach
(
fd_fs
,
dfd_to
,
path_to
,
o_flags_to
,
resolve_flags_to
,
attr_flags
);
return
fs_attach
(
fd_fs
,
dfd_to
,
path_to
,
o_flags_to
,
resolve_flags_to
,
attr_flags
);
}
}
__hidden
extern
int
fd_bind_mount
(
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
,
unsigned
int
attr_flags
,
bool
recursive
);
#endif
/* __LXC_MOUNT_UTILS_H */
#endif
/* __LXC_MOUNT_UTILS_H */
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment