cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

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

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