thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone

Blame SOURCES/kvm-virtiofsd-extract-root-inode-init-into-setup_root.patch

902636
From 983b383bc4a92a9f7ecff0332cadefed2f58f502 Mon Sep 17 00:00:00 2001
902636
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
902636
Date: Mon, 27 Jan 2020 19:01:50 +0100
902636
Subject: [PATCH 079/116] virtiofsd: extract root inode init into setup_root()
902636
MIME-Version: 1.0
902636
Content-Type: text/plain; charset=UTF-8
902636
Content-Transfer-Encoding: 8bit
902636
902636
RH-Author: Dr. David Alan Gilbert <dgilbert@redhat.com>
902636
Message-id: <20200127190227.40942-76-dgilbert@redhat.com>
902636
Patchwork-id: 93527
902636
O-Subject: [RHEL-AV-8.2 qemu-kvm PATCH 075/112] virtiofsd: extract root inode init into setup_root()
902636
Bugzilla: 1694164
902636
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
902636
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
902636
RH-Acked-by: Sergio Lopez Pascual <slp@redhat.com>
902636
902636
From: Miklos Szeredi <mszeredi@redhat.com>
902636
902636
Inititialize the root inode in a single place.
902636
902636
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
902636
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
902636
dgilbert:
902636
with fix suggested by Misono Tomohiro <misono.tomohiro@jp.fujitsu.com>
902636
Reviewed-by: Misono Tomohiro <misono.tomohiro@jp.fujitsu.com>
902636
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
902636
(cherry picked from commit 3ca8a2b1c83eb185c232a4e87abbb65495263756)
902636
902636
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
902636
---
902636
 tools/virtiofsd/passthrough_ll.c | 35 +++++++++++++++++++++++++----------
902636
 1 file changed, 25 insertions(+), 10 deletions(-)
902636
902636
diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c
902636
index 33bfb4d..9e7191e 100644
902636
--- a/tools/virtiofsd/passthrough_ll.c
902636
+++ b/tools/virtiofsd/passthrough_ll.c
902636
@@ -2351,6 +2351,30 @@ static void log_func(enum fuse_log_level level, const char *fmt, va_list ap)
902636
     }
902636
 }
902636
 
902636
+static void setup_root(struct lo_data *lo, struct lo_inode *root)
902636
+{
902636
+    int fd, res;
902636
+    struct stat stat;
902636
+
902636
+    fd = open("/", O_PATH);
902636
+    if (fd == -1) {
902636
+        fuse_log(FUSE_LOG_ERR, "open(%s, O_PATH): %m\n", lo->source);
902636
+        exit(1);
902636
+    }
902636
+
902636
+    res = fstatat(fd, "", &stat, AT_EMPTY_PATH | AT_SYMLINK_NOFOLLOW);
902636
+    if (res == -1) {
902636
+        fuse_log(FUSE_LOG_ERR, "fstatat(%s): %m\n", lo->source);
902636
+        exit(1);
902636
+    }
902636
+
902636
+    root->is_symlink = false;
902636
+    root->fd = fd;
902636
+    root->ino = stat.st_ino;
902636
+    root->dev = stat.st_dev;
902636
+    root->refcount = 2;
902636
+}
902636
+
902636
 int main(int argc, char *argv[])
902636
 {
902636
     struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
902636
@@ -2426,8 +2450,6 @@ int main(int argc, char *argv[])
902636
     if (lo.debug) {
902636
         current_log_level = FUSE_LOG_DEBUG;
902636
     }
902636
-    lo.root.refcount = 2;
902636
-
902636
     if (lo.source) {
902636
         struct stat stat;
902636
         int res;
902636
@@ -2446,7 +2468,6 @@ int main(int argc, char *argv[])
902636
     } else {
902636
         lo.source = "/";
902636
     }
902636
-    lo.root.is_symlink = false;
902636
     if (!lo.timeout_set) {
902636
         switch (lo.cache) {
902636
         case CACHE_NEVER:
902636
@@ -2466,13 +2487,6 @@ int main(int argc, char *argv[])
902636
         exit(1);
902636
     }
902636
 
902636
-    lo.root.fd = open(lo.source, O_PATH);
902636
-
902636
-    if (lo.root.fd == -1) {
902636
-        fuse_log(FUSE_LOG_ERR, "open(\"%s\", O_PATH): %m\n", lo.source);
902636
-        exit(1);
902636
-    }
902636
-
902636
     se = fuse_session_new(&args, &lo_oper, sizeof(lo_oper), &lo);
902636
     if (se == NULL) {
902636
         goto err_out1;
902636
@@ -2495,6 +2509,7 @@ int main(int argc, char *argv[])
902636
 
902636
     setup_sandbox(&lo, se, opts.syslog);
902636
 
902636
+    setup_root(&lo, &lo.root);
902636
     /* Block until ctrl+c or fusermount -u */
902636
     ret = virtio_loop(se);
902636
 
902636
-- 
902636
1.8.3.1
902636