[Virtio-fs] [PATCH] virtiofsd: Prevent multiply running with same vhost_user_socket

Masayoshi Mizuma msys.mizuma at gmail.com
Thu Aug 1 15:13:48 UTC 2019


From: Masayoshi Mizuma <m.mizuma at jp.fujitsu.com>

virtiofsd can run multiply even if the vhost_user_socket is
same path.

  ]# ./virtiofsd -o vhost_user_socket=/tmp/vhostqemu -o source=/tmp/share &
  [1] 244965
  virtio_session_mount: Waiting for vhost-user socket connection...
  ]# ./virtiofsd -o vhost_user_socket=/tmp/vhostqemu -o source=/tmp/share &
  [2] 244966
  virtio_session_mount: Waiting for vhost-user socket connection...
  ]#

The file access from the guest works because the second virtiofsd
handles that, however, the user will get confused the situation
and may be the cause of unexpected problem. So it's better to
prevent the multiple running.

Change unlink() of the socket to the exit of virtiofsd so that the
latter virtiofsd can fail on bind() as EADDRINUSE.

Signed-off-by: Masayoshi Mizuma <m.mizuma at jp.fujitsu.com>
---
 contrib/virtiofsd/fuse_lowlevel.c | 1 +
 contrib/virtiofsd/fuse_virtio.c   | 1 -
 2 files changed, 1 insertion(+), 1 deletion(-)

diff --git a/contrib/virtiofsd/fuse_lowlevel.c b/contrib/virtiofsd/fuse_lowlevel.c
index 8adc4b1ab8..0624d26ffc 100644
--- a/contrib/virtiofsd/fuse_lowlevel.c
+++ b/contrib/virtiofsd/fuse_lowlevel.c
@@ -2584,6 +2584,7 @@ void fuse_session_destroy(struct fuse_session *se)
 		virtio_session_close(se);
 	}
 
+	unlink(se->vu_socket_path);
 	free(se->vu_socket_path);
 	se->vu_socket_path = NULL;
 
diff --git a/contrib/virtiofsd/fuse_virtio.c b/contrib/virtiofsd/fuse_virtio.c
index 083e4fc317..54ba7cbbcb 100644
--- a/contrib/virtiofsd/fuse_virtio.c
+++ b/contrib/virtiofsd/fuse_virtio.c
@@ -879,7 +879,6 @@ static int fv_create_listen_socket(struct fuse_session *se)
         /* Create the Unix socket to communicate with qemu
          * based on QEMU's vhost-user-bridge
          */
-        unlink(se->vu_socket_path);
         strcpy(un.sun_path, se->vu_socket_path);
         size_t addr_len = sizeof(un.sun_family) + strlen(se->vu_socket_path);
 
-- 
2.18.1




More information about the Virtio-fs mailing list