Blame SOURCES/kvm-virtiofsd-passthrough_ll-cleanup-getxattr-listxattr.patch

22c213
From f93ea308351cbe2630d7ecf637c3b69894d84a11 Mon Sep 17 00:00:00 2001
22c213
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
22c213
Date: Tue, 3 Mar 2020 18:43:13 +0000
22c213
Subject: [PATCH 17/18] virtiofsd: passthrough_ll: cleanup getxattr/listxattr
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: <20200303184314.155564-7-dgilbert@redhat.com>
22c213
Patchwork-id: 94125
22c213
O-Subject: [RHEL-AV-8.2.0 qemu-kvm PATCH 6/7] virtiofsd: passthrough_ll: cleanup getxattr/listxattr
22c213
Bugzilla: 1797064
22c213
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
22c213
RH-Acked-by: Sergio Lopez Pascual <slp@redhat.com>
22c213
RH-Acked-by: Ján Tomko <jtomko@redhat.com>
22c213
22c213
From: Misono Tomohiro <misono.tomohiro@jp.fujitsu.com>
22c213
22c213
This is a cleanup patch to simplify the following xattr fix and
22c213
there is no functional changes.
22c213
22c213
- Move memory allocation to head of the function
22c213
- Unify fgetxattr/flistxattr call for both size == 0 and
22c213
  size != 0 case
22c213
- Remove redundant lo_inode_put call in error path
22c213
  (Note: second call is ignored now since @inode is already NULL)
22c213
22c213
Signed-off-by: Misono Tomohiro <misono.tomohiro@jp.fujitsu.com>
22c213
Message-Id: <20200227055927.24566-2-misono.tomohiro@jp.fujitsu.com>
22c213
Acked-by: Vivek Goyal <vgoyal@redhat.com>
22c213
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
22c213
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
22c213
(cherry picked from commit 16e15a73089102c3d8846792d514e769300fcc3c)
22c213
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
22c213
---
22c213
 tools/virtiofsd/passthrough_ll.c | 54 ++++++++++++++++------------------------
22c213
 1 file changed, 22 insertions(+), 32 deletions(-)
22c213
22c213
diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c
22c213
index c635fc8..50c7273 100644
22c213
--- a/tools/virtiofsd/passthrough_ll.c
22c213
+++ b/tools/virtiofsd/passthrough_ll.c
22c213
@@ -2199,34 +2199,30 @@ static void lo_getxattr(fuse_req_t req, fuse_ino_t ino, const char *name,
22c213
         goto out;
22c213
     }
22c213
 
22c213
+    if (size) {
22c213
+        value = malloc(size);
22c213
+        if (!value) {
22c213
+            goto out_err;
22c213
+        }
22c213
+    }
22c213
+
22c213
     sprintf(procname, "%i", inode->fd);
22c213
     fd = openat(lo->proc_self_fd, procname, O_RDONLY);
22c213
     if (fd < 0) {
22c213
         goto out_err;
22c213
     }
22c213
 
22c213
+    ret = fgetxattr(fd, name, value, size);
22c213
+    if (ret == -1) {
22c213
+        goto out_err;
22c213
+    }
22c213
     if (size) {
22c213
-        value = malloc(size);
22c213
-        if (!value) {
22c213
-            goto out_err;
22c213
-        }
22c213
-
22c213
-        ret = fgetxattr(fd, name, value, size);
22c213
-        if (ret == -1) {
22c213
-            goto out_err;
22c213
-        }
22c213
         saverr = 0;
22c213
         if (ret == 0) {
22c213
             goto out;
22c213
         }
22c213
-
22c213
         fuse_reply_buf(req, value, ret);
22c213
     } else {
22c213
-        ret = fgetxattr(fd, name, NULL, 0);
22c213
-        if (ret == -1) {
22c213
-            goto out_err;
22c213
-        }
22c213
-
22c213
         fuse_reply_xattr(req, ret);
22c213
     }
22c213
 out_free:
22c213
@@ -2242,7 +2238,6 @@ out_free:
22c213
 out_err:
22c213
     saverr = errno;
22c213
 out:
22c213
-    lo_inode_put(lo, &inode;;
22c213
     fuse_reply_err(req, saverr);
22c213
     goto out_free;
22c213
 }
22c213
@@ -2277,34 +2272,30 @@ static void lo_listxattr(fuse_req_t req, fuse_ino_t ino, size_t size)
22c213
         goto out;
22c213
     }
22c213
 
22c213
+    if (size) {
22c213
+        value = malloc(size);
22c213
+        if (!value) {
22c213
+            goto out_err;
22c213
+        }
22c213
+    }
22c213
+
22c213
     sprintf(procname, "%i", inode->fd);
22c213
     fd = openat(lo->proc_self_fd, procname, O_RDONLY);
22c213
     if (fd < 0) {
22c213
         goto out_err;
22c213
     }
22c213
 
22c213
+    ret = flistxattr(fd, value, size);
22c213
+    if (ret == -1) {
22c213
+        goto out_err;
22c213
+    }
22c213
     if (size) {
22c213
-        value = malloc(size);
22c213
-        if (!value) {
22c213
-            goto out_err;
22c213
-        }
22c213
-
22c213
-        ret = flistxattr(fd, value, size);
22c213
-        if (ret == -1) {
22c213
-            goto out_err;
22c213
-        }
22c213
         saverr = 0;
22c213
         if (ret == 0) {
22c213
             goto out;
22c213
         }
22c213
-
22c213
         fuse_reply_buf(req, value, ret);
22c213
     } else {
22c213
-        ret = flistxattr(fd, NULL, 0);
22c213
-        if (ret == -1) {
22c213
-            goto out_err;
22c213
-        }
22c213
-
22c213
         fuse_reply_xattr(req, ret);
22c213
     }
22c213
 out_free:
22c213
@@ -2320,7 +2311,6 @@ out_free:
22c213
 out_err:
22c213
     saverr = errno;
22c213
 out:
22c213
-    lo_inode_put(lo, &inode;;
22c213
     fuse_reply_err(req, saverr);
22c213
     goto out_free;
22c213
 }
22c213
-- 
22c213
1.8.3.1
22c213