yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
22c213
From 2b921f7162b53204051955228bf99bbed55d2457 Mon Sep 17 00:00:00 2001
22c213
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
22c213
Date: Mon, 27 Jan 2020 19:01:53 +0100
22c213
Subject: [PATCH 082/116] virtiofsd: Clean up inodes on destroy
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-79-dgilbert@redhat.com>
22c213
Patchwork-id: 93532
22c213
O-Subject: [RHEL-AV-8.2 qemu-kvm PATCH 078/112] virtiofsd: Clean up inodes on destroy
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: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
22c213
22c213
Clear out our inodes and fd's on a 'destroy' - so we get rid
22c213
of them if we reboot the guest.
22c213
22c213
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
22c213
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
22c213
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
22c213
(cherry picked from commit 771b01eb76ff480fee984bd1d21727147cc3e702)
22c213
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
22c213
---
22c213
 tools/virtiofsd/passthrough_ll.c | 26 ++++++++++++++++++++++++++
22c213
 1 file changed, 26 insertions(+)
22c213
22c213
diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c
22c213
index b176a31..9ed77a1 100644
22c213
--- a/tools/virtiofsd/passthrough_ll.c
22c213
+++ b/tools/virtiofsd/passthrough_ll.c
22c213
@@ -1169,6 +1169,25 @@ static void unref_inode_lolocked(struct lo_data *lo, struct lo_inode *inode,
22c213
     }
22c213
 }
22c213
 
22c213
+static int unref_all_inodes_cb(gpointer key, gpointer value, gpointer user_data)
22c213
+{
22c213
+    struct lo_inode *inode = value;
22c213
+    struct lo_data *lo = user_data;
22c213
+
22c213
+    inode->refcount = 0;
22c213
+    lo_map_remove(&lo->ino_map, inode->fuse_ino);
22c213
+    close(inode->fd);
22c213
+
22c213
+    return TRUE;
22c213
+}
22c213
+
22c213
+static void unref_all_inodes(struct lo_data *lo)
22c213
+{
22c213
+    pthread_mutex_lock(&lo->mutex);
22c213
+    g_hash_table_foreach_remove(lo->inodes, unref_all_inodes_cb, lo);
22c213
+    pthread_mutex_unlock(&lo->mutex);
22c213
+}
22c213
+
22c213
 static void lo_forget_one(fuse_req_t req, fuse_ino_t ino, uint64_t nlookup)
22c213
 {
22c213
     struct lo_data *lo = lo_data(req);
22c213
@@ -2035,6 +2054,12 @@ static void lo_lseek(fuse_req_t req, fuse_ino_t ino, off_t off, int whence,
22c213
     }
22c213
 }
22c213
 
22c213
+static void lo_destroy(void *userdata)
22c213
+{
22c213
+    struct lo_data *lo = (struct lo_data *)userdata;
22c213
+    unref_all_inodes(lo);
22c213
+}
22c213
+
22c213
 static struct fuse_lowlevel_ops lo_oper = {
22c213
     .init = lo_init,
22c213
     .lookup = lo_lookup,
22c213
@@ -2073,6 +2098,7 @@ static struct fuse_lowlevel_ops lo_oper = {
22c213
     .copy_file_range = lo_copy_file_range,
22c213
 #endif
22c213
     .lseek = lo_lseek,
22c213
+    .destroy = lo_destroy,
22c213
 };
22c213
 
22c213
 /* Print vhost-user.json backend program capabilities */
22c213
-- 
22c213
1.8.3.1
22c213