4d7edd7
From: Li Qiang <liq3ea@gmail.com>
4d7edd7
Date: Wed, 23 Nov 2016 13:53:34 +0100
4d7edd7
Subject: [PATCH] 9pfs: add cleanup operation for handle backend driver
4d7edd7
4d7edd7
In the init operation of handle backend dirver, it allocates a
4d7edd7
handle_data struct and opens a mount file. We should free these
4d7edd7
resources when the 9pfs device is unrealized. This is what this
4d7edd7
patch does.
4d7edd7
4d7edd7
Signed-off-by: Li Qiang <liq3ea@gmail.com>
4d7edd7
Reviewed-by: Greg Kurz <groug@kaod.org>
4d7edd7
Signed-off-by: Greg Kurz <groug@kaod.org>
4d7edd7
(cherry picked from commit 971f406b77a6eb84e0ad27dcc416b663765aee30)
4d7edd7
---
4d7edd7
 hw/9pfs/9p-handle.c | 9 +++++++++
4d7edd7
 1 file changed, 9 insertions(+)
4d7edd7
4d7edd7
diff --git a/hw/9pfs/9p-handle.c b/hw/9pfs/9p-handle.c
4d7edd7
index 8940414..6ce923d 100644
4d7edd7
--- a/hw/9pfs/9p-handle.c
4d7edd7
+++ b/hw/9pfs/9p-handle.c
4d7edd7
@@ -651,6 +651,14 @@ out:
4d7edd7
     return ret;
4d7edd7
 }
4d7edd7
 
4d7edd7
+static void handle_cleanup(FsContext *ctx)
4d7edd7
+{
4d7edd7
+    struct handle_data *data = ctx->private;
4d7edd7
+
4d7edd7
+    close(data->mountfd);
4d7edd7
+    g_free(data);
4d7edd7
+}
4d7edd7
+
4d7edd7
 static int handle_parse_opts(QemuOpts *opts, struct FsDriverEntry *fse)
4d7edd7
 {
4d7edd7
     const char *sec_model = qemu_opt_get(opts, "security_model");
4d7edd7
@@ -673,6 +681,7 @@ static int handle_parse_opts(QemuOpts *opts, struct FsDriverEntry *fse)
4d7edd7
 FileOperations handle_ops = {
4d7edd7
     .parse_opts   = handle_parse_opts,
4d7edd7
     .init         = handle_init,
4d7edd7
+    .cleanup      = handle_cleanup,
4d7edd7
     .lstat        = handle_lstat,
4d7edd7
     .readlink     = handle_readlink,
4d7edd7
     .close        = handle_close,