diff mbox

[2/3] 9pfs: add cleanup operation for handle backend driver

Message ID 5829af0f.84f4420a.a436f.4a73@mx.google.com (mailing list archive)
State New, archived
Headers show

Commit Message

Li Qiang Nov. 14, 2016, 12:32 p.m. UTC
From: Li Qiang <liq3ea@gmail.com>

In the init operation of handle backend dirver, it allocates a
handle_data struct and opens a mount file. We should free these
resources when the 9pfs device is unrealized. This is what this
patch does.

Signed-off-by: Li Qiang <liq3ea@gmail.com>
---
 hw/9pfs/9p-handle.c | 8 ++++++++
 1 file changed, 8 insertions(+)

Comments

Greg Kurz Nov. 14, 2016, 5:36 p.m. UTC | #1
On Mon, 14 Nov 2016 07:32:57 -0500
Li Qiang <liq3ea@gmail.com> wrote:

> From: Li Qiang <liq3ea@gmail.com>
> 
> In the init operation of handle backend dirver, it allocates a
> handle_data struct and opens a mount file. We should free these
> resources when the 9pfs device is unrealized. This is what this
> patch does.
> 
> Signed-off-by: Li Qiang <liq3ea@gmail.com>
> ---

Reviewed-by: Greg Kurz <groug@kaod.org>

>  hw/9pfs/9p-handle.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/hw/9pfs/9p-handle.c b/hw/9pfs/9p-handle.c
> index 3d77594..9b50f40 100644
> --- a/hw/9pfs/9p-handle.c
> +++ b/hw/9pfs/9p-handle.c
> @@ -649,6 +649,13 @@ out:
>      return ret;
>  }
>  
> +static void handle_cleanup(FsContext *ctx)
> +{
> +    struct handle_data *data = ctx->private;
> +    close(data->mountfd);
> +    g_free(data);
> +}
> +
>  static int handle_parse_opts(QemuOpts *opts, struct FsDriverEntry *fse)
>  {
>      const char *sec_model = qemu_opt_get(opts, "security_model");
> @@ -671,6 +678,7 @@ static int handle_parse_opts(QemuOpts *opts, struct FsDriverEntry *fse)
>  FileOperations handle_ops = {
>      .parse_opts   = handle_parse_opts,
>      .init         = handle_init,
> +    .cleanup      = handle_cleanup,
>      .lstat        = handle_lstat,
>      .readlink     = handle_readlink,
>      .close        = handle_close,
diff mbox

Patch

diff --git a/hw/9pfs/9p-handle.c b/hw/9pfs/9p-handle.c
index 3d77594..9b50f40 100644
--- a/hw/9pfs/9p-handle.c
+++ b/hw/9pfs/9p-handle.c
@@ -649,6 +649,13 @@  out:
     return ret;
 }
 
+static void handle_cleanup(FsContext *ctx)
+{
+    struct handle_data *data = ctx->private;
+    close(data->mountfd);
+    g_free(data);
+}
+
 static int handle_parse_opts(QemuOpts *opts, struct FsDriverEntry *fse)
 {
     const char *sec_model = qemu_opt_get(opts, "security_model");
@@ -671,6 +678,7 @@  static int handle_parse_opts(QemuOpts *opts, struct FsDriverEntry *fse)
 FileOperations handle_ops = {
     .parse_opts   = handle_parse_opts,
     .init         = handle_init,
+    .cleanup      = handle_cleanup,
     .lstat        = handle_lstat,
     .readlink     = handle_readlink,
     .close        = handle_close,