render / rpms / qemu

Forked from rpms/qemu 9 months ago
Clone

Blame 0081-virtiofsd-extract-root-inode-init-into-setup_root.patch

1d442b
From: Miklos Szeredi <mszeredi@redhat.com>
1d442b
Date: Mon, 27 Jan 2020 19:01:50 +0000
1d442b
Subject: [PATCH] virtiofsd: extract root inode init into setup_root()
1d442b
1d442b
Inititialize the root inode in a single place.
1d442b
1d442b
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
1d442b
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
1d442b
dgilbert:
1d442b
with fix suggested by Misono Tomohiro <misono.tomohiro@jp.fujitsu.com>
1d442b
Reviewed-by: Misono Tomohiro <misono.tomohiro@jp.fujitsu.com>
1d442b
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
1d442b
(cherry picked from commit 3ca8a2b1c83eb185c232a4e87abbb65495263756)
1d442b
---
1d442b
 tools/virtiofsd/passthrough_ll.c | 35 +++++++++++++++++++++++---------
1d442b
 1 file changed, 25 insertions(+), 10 deletions(-)
1d442b
1d442b
diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c
1d442b
index 33bfb4d1f4..9e7191eb75 100644
1d442b
--- a/tools/virtiofsd/passthrough_ll.c
1d442b
+++ b/tools/virtiofsd/passthrough_ll.c
1d442b
@@ -2351,6 +2351,30 @@ static void log_func(enum fuse_log_level level, const char *fmt, va_list ap)
1d442b
     }
1d442b
 }
1d442b
 
1d442b
+static void setup_root(struct lo_data *lo, struct lo_inode *root)
1d442b
+{
1d442b
+    int fd, res;
1d442b
+    struct stat stat;
1d442b
+
1d442b
+    fd = open("/", O_PATH);
1d442b
+    if (fd == -1) {
1d442b
+        fuse_log(FUSE_LOG_ERR, "open(%s, O_PATH): %m\n", lo->source);
1d442b
+        exit(1);
1d442b
+    }
1d442b
+
1d442b
+    res = fstatat(fd, "", &stat, AT_EMPTY_PATH | AT_SYMLINK_NOFOLLOW);
1d442b
+    if (res == -1) {
1d442b
+        fuse_log(FUSE_LOG_ERR, "fstatat(%s): %m\n", lo->source);
1d442b
+        exit(1);
1d442b
+    }
1d442b
+
1d442b
+    root->is_symlink = false;
1d442b
+    root->fd = fd;
1d442b
+    root->ino = stat.st_ino;
1d442b
+    root->dev = stat.st_dev;
1d442b
+    root->refcount = 2;
1d442b
+}
1d442b
+
1d442b
 int main(int argc, char *argv[])
1d442b
 {
1d442b
     struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
1d442b
@@ -2426,8 +2450,6 @@ int main(int argc, char *argv[])
1d442b
     if (lo.debug) {
1d442b
         current_log_level = FUSE_LOG_DEBUG;
1d442b
     }
1d442b
-    lo.root.refcount = 2;
1d442b
-
1d442b
     if (lo.source) {
1d442b
         struct stat stat;
1d442b
         int res;
1d442b
@@ -2446,7 +2468,6 @@ int main(int argc, char *argv[])
1d442b
     } else {
1d442b
         lo.source = "/";
1d442b
     }
1d442b
-    lo.root.is_symlink = false;
1d442b
     if (!lo.timeout_set) {
1d442b
         switch (lo.cache) {
1d442b
         case CACHE_NEVER:
1d442b
@@ -2466,13 +2487,6 @@ int main(int argc, char *argv[])
1d442b
         exit(1);
1d442b
     }
1d442b
 
1d442b
-    lo.root.fd = open(lo.source, O_PATH);
1d442b
-
1d442b
-    if (lo.root.fd == -1) {
1d442b
-        fuse_log(FUSE_LOG_ERR, "open(\"%s\", O_PATH): %m\n", lo.source);
1d442b
-        exit(1);
1d442b
-    }
1d442b
-
1d442b
     se = fuse_session_new(&args, &lo_oper, sizeof(lo_oper), &lo);
1d442b
     if (se == NULL) {
1d442b
         goto err_out1;
1d442b
@@ -2495,6 +2509,7 @@ int main(int argc, char *argv[])
1d442b
 
1d442b
     setup_sandbox(&lo, se, opts.syslog);
1d442b
 
1d442b
+    setup_root(&lo, &lo.root);
1d442b
     /* Block until ctrl+c or fusermount -u */
1d442b
     ret = virtio_loop(se);
1d442b