All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 1/3] 9pfs: add cleanup operation in FileOperations
       [not found] <1479126778-125867-1-git-send-email-Qiang(liqiang6-s@360.cn)>
@ 2016-11-14 12:32 ` Li Qiang
  2016-11-14 17:32   ` Greg Kurz
  2016-11-14 12:32 ` [Qemu-devel] [PATCH 2/3] 9pfs: add cleanup operation for handle backend driver Li Qiang
  2016-11-14 12:32 ` [Qemu-devel] [PATCH 3/3] 9pfs: add cleanup operation for proxy " Li Qiang
  2 siblings, 1 reply; 6+ messages in thread
From: Li Qiang @ 2016-11-14 12:32 UTC (permalink / raw)
  To: groug, qemu-devel; +Cc: liqiang6-s, Li Qiang

From: Li Qiang <liq3ea@gmail.com>

Currently, the backend of VirtFS doesn't have a cleanup
function. This will lead resource leak issues if the backed
driver allocates resources. This patch addresses this issue.

Signed-off-by: Li Qiang <liq3ea@gmail.com>
---
 fsdev/file-op-9p.h | 1 +
 hw/9pfs/9p.c       | 3 +++
 2 files changed, 4 insertions(+)

diff --git a/fsdev/file-op-9p.h b/fsdev/file-op-9p.h
index 6db9fea..a56dc84 100644
--- a/fsdev/file-op-9p.h
+++ b/fsdev/file-op-9p.h
@@ -100,6 +100,7 @@ struct FileOperations
 {
     int (*parse_opts)(QemuOpts *, struct FsDriverEntry *);
     int (*init)(struct FsContext *);
+    void (*cleanup)(struct FsContext *);
     int (*lstat)(FsContext *, V9fsPath *, struct stat *);
     ssize_t (*readlink)(FsContext *, V9fsPath *, char *, size_t);
     int (*chmod)(FsContext *, V9fsPath *, FsCred *);
diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
index aea7e9d..166b5a7 100644
--- a/hw/9pfs/9p.c
+++ b/hw/9pfs/9p.c
@@ -3532,6 +3532,9 @@ void v9fs_device_unrealize_common(V9fsState *s, Error **errp)
 {
     g_free(s->ctx.fs_root);
     g_free(s->tag);
+    if (s->ops->cleanup) {
+        s->ops->cleanup(&s->ctx);
+    }
 }
 
 typedef struct VirtfsCoResetData {
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [Qemu-devel] [PATCH 2/3] 9pfs: add cleanup operation for handle backend driver
       [not found] <1479126778-125867-1-git-send-email-Qiang(liqiang6-s@360.cn)>
  2016-11-14 12:32 ` [Qemu-devel] [PATCH 1/3] 9pfs: add cleanup operation in FileOperations Li Qiang
@ 2016-11-14 12:32 ` Li Qiang
  2016-11-14 17:36   ` Greg Kurz
  2016-11-14 12:32 ` [Qemu-devel] [PATCH 3/3] 9pfs: add cleanup operation for proxy " Li Qiang
  2 siblings, 1 reply; 6+ messages in thread
From: Li Qiang @ 2016-11-14 12:32 UTC (permalink / raw)
  To: groug, qemu-devel; +Cc: liqiang6-s, Li Qiang

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(+)

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,
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [Qemu-devel] [PATCH 3/3] 9pfs: add cleanup operation for proxy backend driver
       [not found] <1479126778-125867-1-git-send-email-Qiang(liqiang6-s@360.cn)>
  2016-11-14 12:32 ` [Qemu-devel] [PATCH 1/3] 9pfs: add cleanup operation in FileOperations Li Qiang
  2016-11-14 12:32 ` [Qemu-devel] [PATCH 2/3] 9pfs: add cleanup operation for handle backend driver Li Qiang
@ 2016-11-14 12:32 ` Li Qiang
  2016-11-14 17:36   ` Greg Kurz
  2 siblings, 1 reply; 6+ messages in thread
From: Li Qiang @ 2016-11-14 12:32 UTC (permalink / raw)
  To: groug, qemu-devel; +Cc: liqiang6-s, Li Qiang

From: Li Qiang <liq3ea@gmail.com>

In the init operation of proxy backend dirver, it allocates a
V9fsProxy struct and some other resources. 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-proxy.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/hw/9pfs/9p-proxy.c b/hw/9pfs/9p-proxy.c
index f2417b7..4b22f57 100644
--- a/hw/9pfs/9p-proxy.c
+++ b/hw/9pfs/9p-proxy.c
@@ -1168,9 +1168,19 @@ static int proxy_init(FsContext *ctx)
     return 0;
 }
 
+static void proxy_cleanup(FsContext *ctx)
+{
+    V9fsProxy *proxy = ctx->private;
+    close(proxy->sockfd);
+    g_free(proxy->in_iovec.iov_base);
+    g_free(proxy->out_iovec.iov_base);
+    g_free(proxy);
+}
+
 FileOperations proxy_ops = {
     .parse_opts   = proxy_parse_opts,
     .init         = proxy_init,
+    .cleanup      = proxy_cleanup,
     .lstat        = proxy_lstat,
     .readlink     = proxy_readlink,
     .close        = proxy_close,
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [PATCH 1/3] 9pfs: add cleanup operation in FileOperations
  2016-11-14 12:32 ` [Qemu-devel] [PATCH 1/3] 9pfs: add cleanup operation in FileOperations Li Qiang
@ 2016-11-14 17:32   ` Greg Kurz
  0 siblings, 0 replies; 6+ messages in thread
From: Greg Kurz @ 2016-11-14 17:32 UTC (permalink / raw)
  To: Li Qiang; +Cc: qemu-devel, liqiang6-s

On Mon, 14 Nov 2016 07:32:56 -0500
Li Qiang <liq3ea@gmail.com> wrote:

> From: Li Qiang <liq3ea@gmail.com>
> 
> Currently, the backend of VirtFS doesn't have a cleanup
> function. This will lead resource leak issues if the backed
> driver allocates resources. This patch addresses this issue.
> 
> Signed-off-by: Li Qiang <liq3ea@gmail.com>
> ---
>  fsdev/file-op-9p.h | 1 +
>  hw/9pfs/9p.c       | 3 +++
>  2 files changed, 4 insertions(+)
> 
> diff --git a/fsdev/file-op-9p.h b/fsdev/file-op-9p.h
> index 6db9fea..a56dc84 100644
> --- a/fsdev/file-op-9p.h
> +++ b/fsdev/file-op-9p.h
> @@ -100,6 +100,7 @@ struct FileOperations
>  {
>      int (*parse_opts)(QemuOpts *, struct FsDriverEntry *);
>      int (*init)(struct FsContext *);
> +    void (*cleanup)(struct FsContext *);
>      int (*lstat)(FsContext *, V9fsPath *, struct stat *);
>      ssize_t (*readlink)(FsContext *, V9fsPath *, char *, size_t);
>      int (*chmod)(FsContext *, V9fsPath *, FsCred *);
> diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
> index aea7e9d..166b5a7 100644
> --- a/hw/9pfs/9p.c
> +++ b/hw/9pfs/9p.c
> @@ -3532,6 +3532,9 @@ void v9fs_device_unrealize_common(V9fsState *s, Error **errp)
>  {
>      g_free(s->ctx.fs_root);
>      g_free(s->tag);
> +    if (s->ops->cleanup) {
> +        s->ops->cleanup(&s->ctx);
> +    }

Unrealize should undo things that were set during realize in reverse order: 
please move the cleanup stuff above calls to g_free() (which are actually
misordered since tag is allocated after fs_root... maybe you can fix that
too in a preparatory patch).

You also have to call cleanup in the error path of realize if init was
called.

>  }
>  
>  typedef struct VirtfsCoResetData {

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [PATCH 2/3] 9pfs: add cleanup operation for handle backend driver
  2016-11-14 12:32 ` [Qemu-devel] [PATCH 2/3] 9pfs: add cleanup operation for handle backend driver Li Qiang
@ 2016-11-14 17:36   ` Greg Kurz
  0 siblings, 0 replies; 6+ messages in thread
From: Greg Kurz @ 2016-11-14 17:36 UTC (permalink / raw)
  To: Li Qiang; +Cc: qemu-devel, liqiang6-s

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,

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [PATCH 3/3] 9pfs: add cleanup operation for proxy backend driver
  2016-11-14 12:32 ` [Qemu-devel] [PATCH 3/3] 9pfs: add cleanup operation for proxy " Li Qiang
@ 2016-11-14 17:36   ` Greg Kurz
  0 siblings, 0 replies; 6+ messages in thread
From: Greg Kurz @ 2016-11-14 17:36 UTC (permalink / raw)
  To: Li Qiang; +Cc: qemu-devel, liqiang6-s

On Mon, 14 Nov 2016 07:32:58 -0500
Li Qiang <liq3ea@gmail.com> wrote:

> From: Li Qiang <liq3ea@gmail.com>
> 
> In the init operation of proxy backend dirver, it allocates a
> V9fsProxy struct and some other resources. 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-proxy.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/hw/9pfs/9p-proxy.c b/hw/9pfs/9p-proxy.c
> index f2417b7..4b22f57 100644
> --- a/hw/9pfs/9p-proxy.c
> +++ b/hw/9pfs/9p-proxy.c
> @@ -1168,9 +1168,19 @@ static int proxy_init(FsContext *ctx)
>      return 0;
>  }
>  
> +static void proxy_cleanup(FsContext *ctx)
> +{
> +    V9fsProxy *proxy = ctx->private;
> +    close(proxy->sockfd);
> +    g_free(proxy->in_iovec.iov_base);
> +    g_free(proxy->out_iovec.iov_base);
> +    g_free(proxy);
> +}
> +
>  FileOperations proxy_ops = {
>      .parse_opts   = proxy_parse_opts,
>      .init         = proxy_init,
> +    .cleanup      = proxy_cleanup,
>      .lstat        = proxy_lstat,
>      .readlink     = proxy_readlink,
>      .close        = proxy_close,

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2016-11-14 17:36 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <1479126778-125867-1-git-send-email-Qiang(liqiang6-s@360.cn)>
2016-11-14 12:32 ` [Qemu-devel] [PATCH 1/3] 9pfs: add cleanup operation in FileOperations Li Qiang
2016-11-14 17:32   ` Greg Kurz
2016-11-14 12:32 ` [Qemu-devel] [PATCH 2/3] 9pfs: add cleanup operation for handle backend driver Li Qiang
2016-11-14 17:36   ` Greg Kurz
2016-11-14 12:32 ` [Qemu-devel] [PATCH 3/3] 9pfs: add cleanup operation for proxy " Li Qiang
2016-11-14 17:36   ` Greg Kurz

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.