qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 071/104] virtiofsd: extract root inode init into setup_root()


From: Dr. David Alan Gilbert (git)
Subject: [PATCH 071/104] virtiofsd: extract root inode init into setup_root()
Date: Thu, 12 Dec 2019 16:38:31 +0000

From: Miklos Szeredi <address@hidden>

Inititialize the root inode in a single place.

Signed-off-by: Miklos Szeredi <address@hidden>
Signed-off-by: Stefan Hajnoczi <address@hidden>
---
 tools/virtiofsd/passthrough_ll.c | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)

diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c
index ef8b88e3d1..0f33c3c5e9 100644
--- a/tools/virtiofsd/passthrough_ll.c
+++ b/tools/virtiofsd/passthrough_ll.c
@@ -2336,6 +2336,29 @@ static void log_func(enum fuse_log_level level, const 
char *_fmt, va_list ap)
     }
 }
 
+static void setup_root(struct lo_data *lo, struct lo_inode *root)
+{
+    int fd, res;
+    struct stat stat;
+
+    fd = open("/", O_PATH);
+    if (fd == -1) {
+        fuse_log(FUSE_LOG_ERR, "open(%s, O_PATH): %m\n", lo->source);
+        exit(1);
+    }
+
+    res = fstatat(fd, "", &stat, AT_EMPTY_PATH | AT_SYMLINK_NOFOLLOW);
+    if (res == -1) {
+        fuse_log(FUSE_LOG_ERR, "fstatat(%s): %m\n", lo->source);
+        exit(1);
+    }
+
+    root->fd = fd;
+    root->ino = stat.st_ino;
+    root->dev = stat.st_dev;
+    root->refcount = 2;
+}
+
 int main(int argc, char *argv[])
 {
     struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
@@ -2411,8 +2434,6 @@ int main(int argc, char *argv[])
     if (lo.debug) {
         current_log_level = FUSE_LOG_DEBUG;
     }
-    lo.root.refcount = 2;
-
     if (lo.source) {
         struct stat stat;
         int res;
@@ -2480,6 +2501,7 @@ int main(int argc, char *argv[])
 
     setup_sandbox(&lo, se, opts.syslog);
 
+    setup_root(&lo, &lo.root);
     /* Block until ctrl+c or fusermount -u */
     ret = virtio_loop(se);
 
-- 
2.23.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]