yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

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

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