* [Virtio-fs] [PATCH] virtiofsd: simplify setup_remount_slave
@ 2019-08-14 2:27 Peng Tao
2019-08-14 6:22 ` Liu Bo
2019-08-14 12:36 ` Stefan Hajnoczi
0 siblings, 2 replies; 4+ messages in thread
From: Peng Tao @ 2019-08-14 2:27 UTC (permalink / raw)
To: virtio-fs; +Cc: Peng Tao
We can just use MS_REC to propagate MS_SLAVE. This would also allow us
to close a race window between reading proc mountinfo and calling
mount(MS_SLAVE) for each entry, vs. others umounting the mount point in
parallel.
Signed-off-by: Peng Tao <tao.peng@linux.alibaba.com>
---
contrib/virtiofsd/passthrough_ll.c | 53 ++----------------------------
1 file changed, 3 insertions(+), 50 deletions(-)
diff --git a/contrib/virtiofsd/passthrough_ll.c b/contrib/virtiofsd/passthrough_ll.c
index 6662cc237a..d1ce369071 100644
--- a/contrib/virtiofsd/passthrough_ll.c
+++ b/contrib/virtiofsd/passthrough_ll.c
@@ -2032,55 +2032,6 @@ static struct fuse_lowlevel_ops lo_oper = {
.removemapping = lo_removemapping,
};
-/* Remount with MS_SLAVE so our mounts don't affect the outside world */
-static void setup_remount_slave(void)
-{
- gchar *mountinfo = NULL;
- gchar *line;
- gchar *nextline;
-
- if (!g_file_get_contents("/proc/self/mountinfo", &mountinfo, NULL, NULL)) {
- fprintf(stderr, "unable to read /proc/self/mountinfo\n");
- exit(EXIT_FAILURE);
- }
-
- for (line = mountinfo; line; line = nextline) {
- gchar **fields = NULL;
- char *eol;
-
- nextline = NULL;
-
- eol = strchr(line, '\n');
- if (eol) {
- *eol = '\0';
- nextline = eol + 1;
- }
-
- /*
- * The line format is:
- * 442 441 253:4 / / rw,relatime shared:1 - xfs /dev/sda1 rw
- */
- fields = g_strsplit(line, " ", -1);
- if (!fields[0] || !fields[1] || !fields[2] || !fields[3] ||
- !fields[4] || !fields[5] || !fields[6]) {
- goto next; /* parsing failed, skip line */
- }
-
- if (!strstr(fields[6], "shared")) {
- goto next; /* not shared, skip line */
- }
-
- if (mount(NULL, fields[4], NULL, MS_SLAVE, NULL) < 0) {
- err(1, "mount(%s, MS_SLAVE)", fields[4]);
- }
-
-next:
- g_strfreev(fields);
- }
-
- g_free(mountinfo);
-}
-
/* This magic is based on lxc's lxc_pivot_root() */
static void setup_pivot_root(const char *source)
{
@@ -2135,7 +2086,9 @@ static void setup_mount_namespace(const char *source)
err(1, "unshare(CLONE_NEWNS)");
}
- setup_remount_slave();
+ if (mount(NULL, "/", NULL, MS_REC|MS_SLAVE, NULL) < 0) {
+ err(1, "mount(/, MS_REC|MS_PRIVATE)");
+ }
if (mount(source, source, NULL, MS_BIND, NULL) < 0) {
err(1, "mount(%s, %s, MS_BIND)", source, source);
--
2.17.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [Virtio-fs] [PATCH] virtiofsd: simplify setup_remount_slave
2019-08-14 2:27 [Virtio-fs] [PATCH] virtiofsd: simplify setup_remount_slave Peng Tao
@ 2019-08-14 6:22 ` Liu Bo
2019-08-14 12:36 ` Stefan Hajnoczi
1 sibling, 0 replies; 4+ messages in thread
From: Liu Bo @ 2019-08-14 6:22 UTC (permalink / raw)
To: Peng Tao; +Cc: virtio-fs
On Wed, Aug 14, 2019 at 10:27:51AM +0800, Peng Tao wrote:
> We can just use MS_REC to propagate MS_SLAVE. This would also allow us
> to close a race window between reading proc mountinfo and calling
> mount(MS_SLAVE) for each entry, vs. others umounting the mount point in
> parallel.
>
Reviewed-by: Liu Bo <bo.liu@linux.alibaba.com>
thanks,
-liubo
> Signed-off-by: Peng Tao <tao.peng@linux.alibaba.com>
> ---
> contrib/virtiofsd/passthrough_ll.c | 53 ++----------------------------
> 1 file changed, 3 insertions(+), 50 deletions(-)
>
> diff --git a/contrib/virtiofsd/passthrough_ll.c b/contrib/virtiofsd/passthrough_ll.c
> index 6662cc237a..d1ce369071 100644
> --- a/contrib/virtiofsd/passthrough_ll.c
> +++ b/contrib/virtiofsd/passthrough_ll.c
> @@ -2032,55 +2032,6 @@ static struct fuse_lowlevel_ops lo_oper = {
> .removemapping = lo_removemapping,
> };
>
> -/* Remount with MS_SLAVE so our mounts don't affect the outside world */
> -static void setup_remount_slave(void)
> -{
> - gchar *mountinfo = NULL;
> - gchar *line;
> - gchar *nextline;
> -
> - if (!g_file_get_contents("/proc/self/mountinfo", &mountinfo, NULL, NULL)) {
> - fprintf(stderr, "unable to read /proc/self/mountinfo\n");
> - exit(EXIT_FAILURE);
> - }
> -
> - for (line = mountinfo; line; line = nextline) {
> - gchar **fields = NULL;
> - char *eol;
> -
> - nextline = NULL;
> -
> - eol = strchr(line, '\n');
> - if (eol) {
> - *eol = '\0';
> - nextline = eol + 1;
> - }
> -
> - /*
> - * The line format is:
> - * 442 441 253:4 / / rw,relatime shared:1 - xfs /dev/sda1 rw
> - */
> - fields = g_strsplit(line, " ", -1);
> - if (!fields[0] || !fields[1] || !fields[2] || !fields[3] ||
> - !fields[4] || !fields[5] || !fields[6]) {
> - goto next; /* parsing failed, skip line */
> - }
> -
> - if (!strstr(fields[6], "shared")) {
> - goto next; /* not shared, skip line */
> - }
> -
> - if (mount(NULL, fields[4], NULL, MS_SLAVE, NULL) < 0) {
> - err(1, "mount(%s, MS_SLAVE)", fields[4]);
> - }
> -
> -next:
> - g_strfreev(fields);
> - }
> -
> - g_free(mountinfo);
> -}
> -
> /* This magic is based on lxc's lxc_pivot_root() */
> static void setup_pivot_root(const char *source)
> {
> @@ -2135,7 +2086,9 @@ static void setup_mount_namespace(const char *source)
> err(1, "unshare(CLONE_NEWNS)");
> }
>
> - setup_remount_slave();
> + if (mount(NULL, "/", NULL, MS_REC|MS_SLAVE, NULL) < 0) {
> + err(1, "mount(/, MS_REC|MS_PRIVATE)");
> + }
>
> if (mount(source, source, NULL, MS_BIND, NULL) < 0) {
> err(1, "mount(%s, %s, MS_BIND)", source, source);
> --
> 2.17.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Virtio-fs] [PATCH] virtiofsd: simplify setup_remount_slave
2019-08-14 2:27 [Virtio-fs] [PATCH] virtiofsd: simplify setup_remount_slave Peng Tao
2019-08-14 6:22 ` Liu Bo
@ 2019-08-14 12:36 ` Stefan Hajnoczi
2019-08-14 12:57 ` Dr. David Alan Gilbert
1 sibling, 1 reply; 4+ messages in thread
From: Stefan Hajnoczi @ 2019-08-14 12:36 UTC (permalink / raw)
To: Peng Tao; +Cc: virtio-fs
[-- Attachment #1: Type: text/plain, Size: 556 bytes --]
On Wed, Aug 14, 2019 at 10:27:51AM +0800, Peng Tao wrote:
> We can just use MS_REC to propagate MS_SLAVE. This would also allow us
> to close a race window between reading proc mountinfo and calling
> mount(MS_SLAVE) for each entry, vs. others umounting the mount point in
> parallel.
>
> Signed-off-by: Peng Tao <tao.peng@linux.alibaba.com>
> ---
> contrib/virtiofsd/passthrough_ll.c | 53 ++----------------------------
> 1 file changed, 3 insertions(+), 50 deletions(-)
Let's try it!
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Virtio-fs] [PATCH] virtiofsd: simplify setup_remount_slave
2019-08-14 12:36 ` Stefan Hajnoczi
@ 2019-08-14 12:57 ` Dr. David Alan Gilbert
0 siblings, 0 replies; 4+ messages in thread
From: Dr. David Alan Gilbert @ 2019-08-14 12:57 UTC (permalink / raw)
To: Stefan Hajnoczi; +Cc: virtio-fs, Peng Tao
* Stefan Hajnoczi (stefanha@redhat.com) wrote:
> On Wed, Aug 14, 2019 at 10:27:51AM +0800, Peng Tao wrote:
> > We can just use MS_REC to propagate MS_SLAVE. This would also allow us
> > to close a race window between reading proc mountinfo and calling
> > mount(MS_SLAVE) for each entry, vs. others umounting the mount point in
> > parallel.
> >
> > Signed-off-by: Peng Tao <tao.peng@linux.alibaba.com>
> > ---
> > contrib/virtiofsd/passthrough_ll.c | 53 ++----------------------------
> > 1 file changed, 3 insertions(+), 50 deletions(-)
>
> Let's try it!
>
> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
OK thanks, merged in my local world
> _______________________________________________
> Virtio-fs mailing list
> Virtio-fs@redhat.com
> https://www.redhat.com/mailman/listinfo/virtio-fs
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-08-14 12:57 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-08-14 2:27 [Virtio-fs] [PATCH] virtiofsd: simplify setup_remount_slave Peng Tao
2019-08-14 6:22 ` Liu Bo
2019-08-14 12:36 ` Stefan Hajnoczi
2019-08-14 12:57 ` Dr. David Alan Gilbert
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.