All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v2 0/3] 9pfs: add cleanup operation in handle/proxy backend
@ 2016-11-15  2:13 Li Qiang
  2016-11-15  2:13 ` [Qemu-devel] [PATCH v2 1/3] 9pfs: add cleanup operation in FileOperations Li Qiang
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Li Qiang @ 2016-11-15  2:13 UTC (permalink / raw)
  To: groug, qemu-devel; +Cc: liqiang6-s, Li Qiang

Currently, the backend of VirtFS doesn't have a cleanup
function. This will leak some resources in handle and proxy
backend driver. This patchset addresses this issue.

Li Qiang (3):
  9pfs: add cleanup operation in FileOperations
  9pfs: add cleanup operation for handle backend driver
  9pfs: add cleanup operation for proxy backend driver

 fsdev/file-op-9p.h  |  1 +
 hw/9pfs/9p-handle.c |  8 ++++++++
 hw/9pfs/9p-proxy.c  | 10 ++++++++++
 hw/9pfs/9p.c        |  6 ++++++
 4 files changed, 25 insertions(+)

-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v2 1/3] 9pfs: add cleanup operation in FileOperations
  2016-11-15  2:13 [Qemu-devel] [PATCH v2 0/3] 9pfs: add cleanup operation in handle/proxy backend Li Qiang
@ 2016-11-15  2:13 ` Li Qiang
  2016-11-15  2:13 ` [Qemu-devel] [PATCH v2 2/3] 9pfs: add cleanup operation for handle backend driver Li Qiang
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 8+ messages in thread
From: Li Qiang @ 2016-11-15  2:13 UTC (permalink / raw)
  To: groug, qemu-devel; +Cc: liqiang6-s, Li Qiang

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

Changes since the v1:
-move the cleanup stuff above calls to g_free
-add cleanup call in the error path of realize if init was called

 fsdev/file-op-9p.h | 1 +
 hw/9pfs/9p.c       | 6 ++++++
 2 files changed, 7 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 f7e14ac..70361a2 100644
--- a/hw/9pfs/9p.c
+++ b/hw/9pfs/9p.c
@@ -3521,6 +3521,9 @@ int v9fs_device_realize_common(V9fsState *s, Error **errp)
     rc = 0;
 out:
     if (rc) {
+        if (s->ops->cleanup && s->ctx.private) {
+            s->ops->cleanup(&s->ctx);
+        }
         g_free(s->ctx.fs_root);
         g_free(s->tag);
         v9fs_path_free(&path);
@@ -3530,6 +3533,9 @@ out:
 
 void v9fs_device_unrealize_common(V9fsState *s, Error **errp)
 {
+    if (s->ops->cleanup) {
+        s->ops->cleanup(&s->ctx);
+    }
     g_free(s->tag);
     g_free(s->ctx.fs_root);
 }
-- 
1.8.3.1

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

* [Qemu-devel] [PATCH v2 2/3] 9pfs: add cleanup operation for handle backend driver
  2016-11-15  2:13 [Qemu-devel] [PATCH v2 0/3] 9pfs: add cleanup operation in handle/proxy backend Li Qiang
  2016-11-15  2:13 ` [Qemu-devel] [PATCH v2 1/3] 9pfs: add cleanup operation in FileOperations Li Qiang
@ 2016-11-15  2:13 ` Li Qiang
  2016-11-15 10:22   ` Greg Kurz
  2016-11-15  2:13 ` [Qemu-devel] [PATCH v2 3/3] 9pfs: add cleanup operation for proxy " Li Qiang
  2016-11-15 10:16 ` [Qemu-devel] [PATCH v2 0/3] 9pfs: add cleanup operation in handle/proxy backend Greg Kurz
  3 siblings, 1 reply; 8+ messages in thread
From: Li Qiang @ 2016-11-15  2:13 UTC (permalink / raw)
  To: groug, qemu-devel; +Cc: liqiang6-s, Li Qiang

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] 8+ messages in thread

* [Qemu-devel] [PATCH v2 3/3] 9pfs: add cleanup operation for proxy backend driver
  2016-11-15  2:13 [Qemu-devel] [PATCH v2 0/3] 9pfs: add cleanup operation in handle/proxy backend Li Qiang
  2016-11-15  2:13 ` [Qemu-devel] [PATCH v2 1/3] 9pfs: add cleanup operation in FileOperations Li Qiang
  2016-11-15  2:13 ` [Qemu-devel] [PATCH v2 2/3] 9pfs: add cleanup operation for handle backend driver Li Qiang
@ 2016-11-15  2:13 ` Li Qiang
  2016-11-15 10:26   ` Greg Kurz
  2016-11-15 10:16 ` [Qemu-devel] [PATCH v2 0/3] 9pfs: add cleanup operation in handle/proxy backend Greg Kurz
  3 siblings, 1 reply; 8+ messages in thread
From: Li Qiang @ 2016-11-15  2:13 UTC (permalink / raw)
  To: groug, qemu-devel; +Cc: liqiang6-s, Li Qiang

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] 8+ messages in thread

* Re: [Qemu-devel] [PATCH v2 0/3] 9pfs: add cleanup operation in handle/proxy backend
  2016-11-15  2:13 [Qemu-devel] [PATCH v2 0/3] 9pfs: add cleanup operation in handle/proxy backend Li Qiang
                   ` (2 preceding siblings ...)
  2016-11-15  2:13 ` [Qemu-devel] [PATCH v2 3/3] 9pfs: add cleanup operation for proxy " Li Qiang
@ 2016-11-15 10:16 ` Greg Kurz
  2016-11-15 10:21   ` Li Qiang
  3 siblings, 1 reply; 8+ messages in thread
From: Greg Kurz @ 2016-11-15 10:16 UTC (permalink / raw)
  To: Li Qiang; +Cc: qemu-devel, liqiang6-s

On Mon, 14 Nov 2016 21:13:50 -0500
Li Qiang <liq3ea@gmail.com> wrote:

> Currently, the backend of VirtFS doesn't have a cleanup
> function. This will leak some resources in handle and proxy
> backend driver. This patchset addresses this issue.
> 
> Li Qiang (3):
>   9pfs: add cleanup operation in FileOperations
>   9pfs: add cleanup operation for handle backend driver
>   9pfs: add cleanup operation for proxy backend driver
> 
>  fsdev/file-op-9p.h  |  1 +
>  hw/9pfs/9p-handle.c |  8 ++++++++
>  hw/9pfs/9p-proxy.c  | 10 ++++++++++
>  hw/9pfs/9p.c        |  6 ++++++
>  4 files changed, 25 insertions(+)
> 

Cool, you fixed the message ID issue :)

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

* Re: [Qemu-devel] [PATCH v2 0/3] 9pfs: add cleanup operation in handle/proxy backend
  2016-11-15 10:16 ` [Qemu-devel] [PATCH v2 0/3] 9pfs: add cleanup operation in handle/proxy backend Greg Kurz
@ 2016-11-15 10:21   ` Li Qiang
  0 siblings, 0 replies; 8+ messages in thread
From: Li Qiang @ 2016-11-15 10:21 UTC (permalink / raw)
  To: Greg Kurz; +Cc: qemu-devel, Li Qiang

It is caused by the git config.
remove the "From xxxxx" section in git [sendemail] will solve the message
ID issue.

2016-11-15 18:16 GMT+08:00 Greg Kurz <groug@kaod.org>:

> On Mon, 14 Nov 2016 21:13:50 -0500
> Li Qiang <liq3ea@gmail.com> wrote:
>
> > Currently, the backend of VirtFS doesn't have a cleanup
> > function. This will leak some resources in handle and proxy
> > backend driver. This patchset addresses this issue.
> >
> > Li Qiang (3):
> >   9pfs: add cleanup operation in FileOperations
> >   9pfs: add cleanup operation for handle backend driver
> >   9pfs: add cleanup operation for proxy backend driver
> >
> >  fsdev/file-op-9p.h  |  1 +
> >  hw/9pfs/9p-handle.c |  8 ++++++++
> >  hw/9pfs/9p-proxy.c  | 10 ++++++++++
> >  hw/9pfs/9p.c        |  6 ++++++
> >  4 files changed, 25 insertions(+)
> >
>
> Cool, you fixed the message ID issue :)
>

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

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

On Mon, 14 Nov 2016 21:13:52 -0500
Li Qiang <liq3ea@gmail.com> wrote:

> 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] 8+ messages in thread

* Re: [Qemu-devel] [PATCH v2 3/3] 9pfs: add cleanup operation for proxy backend driver
  2016-11-15  2:13 ` [Qemu-devel] [PATCH v2 3/3] 9pfs: add cleanup operation for proxy " Li Qiang
@ 2016-11-15 10:26   ` Greg Kurz
  0 siblings, 0 replies; 8+ messages in thread
From: Greg Kurz @ 2016-11-15 10:26 UTC (permalink / raw)
  To: Li Qiang; +Cc: qemu-devel, liqiang6-s

On Mon, 14 Nov 2016 21:13:53 -0500
Li Qiang <liq3ea@gmail.com> wrote:

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

Oops I gave my R-b tag a bit to fast because...

>  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);

... this should only be done if QEMU opened the fd (i.e. V9FS_PROXY_SOCK_NAME)

> +    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] 8+ messages in thread

end of thread, other threads:[~2016-11-15 10:26 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-15  2:13 [Qemu-devel] [PATCH v2 0/3] 9pfs: add cleanup operation in handle/proxy backend Li Qiang
2016-11-15  2:13 ` [Qemu-devel] [PATCH v2 1/3] 9pfs: add cleanup operation in FileOperations Li Qiang
2016-11-15  2:13 ` [Qemu-devel] [PATCH v2 2/3] 9pfs: add cleanup operation for handle backend driver Li Qiang
2016-11-15 10:22   ` Greg Kurz
2016-11-15  2:13 ` [Qemu-devel] [PATCH v2 3/3] 9pfs: add cleanup operation for proxy " Li Qiang
2016-11-15 10:26   ` Greg Kurz
2016-11-15 10:16 ` [Qemu-devel] [PATCH v2 0/3] 9pfs: add cleanup operation in handle/proxy backend Greg Kurz
2016-11-15 10:21   ` Li Qiang

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.