qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [for-2.8 0/4] 9p patches for 2.8 20161123
@ 2016-11-23 16:58 Greg Kurz
  2016-11-23 16:58 ` [Qemu-devel] [for-2.8 1/4] 9pfs: adjust the order of resource cleanup in device unrealize Greg Kurz
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Greg Kurz @ 2016-11-23 16:58 UTC (permalink / raw)
  To: qemu-devel; +Cc: Stefan Hajnoczi, Aneesh Kumar K.V, Greg Kurz

The following changes since commit 00227fefd2059464cd2f59aed29944874c630e2f:

  Update version for v2.8.0-rc1 release (2016-11-22 22:29:08 +0000)

are available in the git repository at:

  https://github.com/gkurz/qemu.git tags/for-upstream

for you to fetch changes up to 898ae90a44551d25b8e956fd87372d303c82fe68:

  9pfs: add cleanup operation for proxy backend driver (2016-11-23 13:53:34 +0100)

----------------------------------------------------------------
This pull request fixes some leaks (memory, fd) in the handle and proxy
backends.

----------------------------------------------------------------
Li Qiang (4):
      9pfs: adjust the order of resource cleanup in device unrealize
      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 |  9 +++++++++
 hw/9pfs/9p-proxy.c  | 13 +++++++++++++
 hw/9pfs/9p.c        | 10 ++++++++--
 4 files changed, 31 insertions(+), 2 deletions(-)
-- 
2.7.4

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

* [Qemu-devel] [for-2.8 1/4] 9pfs: adjust the order of resource cleanup in device unrealize
  2016-11-23 16:58 [Qemu-devel] [for-2.8 0/4] 9p patches for 2.8 20161123 Greg Kurz
@ 2016-11-23 16:58 ` Greg Kurz
  2016-11-23 16:58 ` [Qemu-devel] [for-2.8 2/4] 9pfs: add cleanup operation in FileOperations Greg Kurz
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Greg Kurz @ 2016-11-23 16:58 UTC (permalink / raw)
  To: qemu-devel; +Cc: Stefan Hajnoczi, Aneesh Kumar K.V, Greg Kurz, Li Qiang

From: Li Qiang <liq3ea@gmail.com>

Unrealize should undo things that were set during realize in
reverse order. So should do in the error path in realize.

Signed-off-by: Li Qiang <liq3ea@gmail.com>
Reviewed-by: Greg Kurz <groug@kaod.org>
Signed-off-by: Greg Kurz <groug@kaod.org>
---
 hw/9pfs/9p.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
index aea7e9d39206..087b5c98eec1 100644
--- a/hw/9pfs/9p.c
+++ b/hw/9pfs/9p.c
@@ -3521,8 +3521,8 @@ int v9fs_device_realize_common(V9fsState *s, Error **errp)
     rc = 0;
 out:
     if (rc) {
-        g_free(s->ctx.fs_root);
         g_free(s->tag);
+        g_free(s->ctx.fs_root);
         v9fs_path_free(&path);
     }
     return rc;
@@ -3530,8 +3530,8 @@ out:
 
 void v9fs_device_unrealize_common(V9fsState *s, Error **errp)
 {
-    g_free(s->ctx.fs_root);
     g_free(s->tag);
+    g_free(s->ctx.fs_root);
 }
 
 typedef struct VirtfsCoResetData {
-- 
2.7.4

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

* [Qemu-devel] [for-2.8 2/4] 9pfs: add cleanup operation in FileOperations
  2016-11-23 16:58 [Qemu-devel] [for-2.8 0/4] 9p patches for 2.8 20161123 Greg Kurz
  2016-11-23 16:58 ` [Qemu-devel] [for-2.8 1/4] 9pfs: adjust the order of resource cleanup in device unrealize Greg Kurz
@ 2016-11-23 16:58 ` Greg Kurz
  2016-11-23 16:58 ` [Qemu-devel] [for-2.8 3/4] 9pfs: add cleanup operation for handle backend driver Greg Kurz
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Greg Kurz @ 2016-11-23 16:58 UTC (permalink / raw)
  To: qemu-devel; +Cc: Stefan Hajnoczi, Aneesh Kumar K.V, Greg Kurz, 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>
Reviewed-by: Greg Kurz <groug@kaod.org>
Signed-off-by: Greg Kurz <groug@kaod.org>
---
 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 6db9feac8f1c..a56dc8488dfc 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 087b5c98eec1..faebd91f5fab 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->tag);
         g_free(s->ctx.fs_root);
         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);
 }
-- 
2.7.4

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

* [Qemu-devel] [for-2.8 3/4] 9pfs: add cleanup operation for handle backend driver
  2016-11-23 16:58 [Qemu-devel] [for-2.8 0/4] 9p patches for 2.8 20161123 Greg Kurz
  2016-11-23 16:58 ` [Qemu-devel] [for-2.8 1/4] 9pfs: adjust the order of resource cleanup in device unrealize Greg Kurz
  2016-11-23 16:58 ` [Qemu-devel] [for-2.8 2/4] 9pfs: add cleanup operation in FileOperations Greg Kurz
@ 2016-11-23 16:58 ` Greg Kurz
  2016-11-23 16:58 ` [Qemu-devel] [for-2.8 4/4] 9pfs: add cleanup operation for proxy " Greg Kurz
  2016-11-24 10:19 ` [Qemu-devel] [for-2.8 0/4] 9p patches for 2.8 20161123 Stefan Hajnoczi
  4 siblings, 0 replies; 8+ messages in thread
From: Greg Kurz @ 2016-11-23 16:58 UTC (permalink / raw)
  To: qemu-devel; +Cc: Stefan Hajnoczi, Aneesh Kumar K.V, Greg Kurz, 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>
Reviewed-by: Greg Kurz <groug@kaod.org>
Signed-off-by: Greg Kurz <groug@kaod.org>
---
 hw/9pfs/9p-handle.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/hw/9pfs/9p-handle.c b/hw/9pfs/9p-handle.c
index 3d77594f9245..1687661bc95a 100644
--- a/hw/9pfs/9p-handle.c
+++ b/hw/9pfs/9p-handle.c
@@ -649,6 +649,14 @@ 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 +679,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,
-- 
2.7.4

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

* [Qemu-devel] [for-2.8 4/4] 9pfs: add cleanup operation for proxy backend driver
  2016-11-23 16:58 [Qemu-devel] [for-2.8 0/4] 9p patches for 2.8 20161123 Greg Kurz
                   ` (2 preceding siblings ...)
  2016-11-23 16:58 ` [Qemu-devel] [for-2.8 3/4] 9pfs: add cleanup operation for handle backend driver Greg Kurz
@ 2016-11-23 16:58 ` Greg Kurz
  2016-11-24 10:19 ` [Qemu-devel] [for-2.8 0/4] 9p patches for 2.8 20161123 Stefan Hajnoczi
  4 siblings, 0 replies; 8+ messages in thread
From: Greg Kurz @ 2016-11-23 16:58 UTC (permalink / raw)
  To: qemu-devel; +Cc: Stefan Hajnoczi, Aneesh Kumar K.V, Greg Kurz, 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>
Reviewed-by: Greg Kurz <groug@kaod.org>
Signed-off-by: Greg Kurz <groug@kaod.org>
---
 hw/9pfs/9p-proxy.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/hw/9pfs/9p-proxy.c b/hw/9pfs/9p-proxy.c
index f2417b7fd73d..f4aa7a9d70f8 100644
--- a/hw/9pfs/9p-proxy.c
+++ b/hw/9pfs/9p-proxy.c
@@ -1168,9 +1168,22 @@ static int proxy_init(FsContext *ctx)
     return 0;
 }
 
+static void proxy_cleanup(FsContext *ctx)
+{
+    V9fsProxy *proxy = ctx->private;
+
+    g_free(proxy->out_iovec.iov_base);
+    g_free(proxy->in_iovec.iov_base);
+    if (ctx->export_flags & V9FS_PROXY_SOCK_NAME) {
+        close(proxy->sockfd);
+    }
+    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,
-- 
2.7.4

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

* Re: [Qemu-devel] [for-2.8 0/4] 9p patches for 2.8 20161123
  2016-11-23 16:58 [Qemu-devel] [for-2.8 0/4] 9p patches for 2.8 20161123 Greg Kurz
                   ` (3 preceding siblings ...)
  2016-11-23 16:58 ` [Qemu-devel] [for-2.8 4/4] 9pfs: add cleanup operation for proxy " Greg Kurz
@ 2016-11-24 10:19 ` Stefan Hajnoczi
  2016-11-24 10:36   ` Greg Kurz
  4 siblings, 1 reply; 8+ messages in thread
From: Stefan Hajnoczi @ 2016-11-24 10:19 UTC (permalink / raw)
  To: Greg Kurz; +Cc: qemu-devel, Aneesh Kumar K.V

[-- Attachment #1: Type: text/plain, Size: 1030 bytes --]

On Wed, Nov 23, 2016 at 05:58:14PM +0100, Greg Kurz wrote:
> The following changes since commit 00227fefd2059464cd2f59aed29944874c630e2f:
> 
>   Update version for v2.8.0-rc1 release (2016-11-22 22:29:08 +0000)
> 
> are available in the git repository at:
> 
>   https://github.com/gkurz/qemu.git tags/for-upstream
> 
> for you to fetch changes up to 898ae90a44551d25b8e956fd87372d303c82fe68:
> 
>   9pfs: add cleanup operation for proxy backend driver (2016-11-23 13:53:34 +0100)
> 
> ----------------------------------------------------------------
> This pull request fixes some leaks (memory, fd) in the handle and proxy
> backends.

Hi Greg,
Please make sure to aways use the "[PULL]" tag in the Subject so tools
can track your pull requests.

I have applied this pull request manually to my staging tree:
https://github.com/stefanha/qemu/commits/staging

Your PGP key has only one signature.  Can you key sign with other
IBMers?  That may allow us to get the Web of Trust going.

Thanks,
Stefan

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 455 bytes --]

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

* Re: [Qemu-devel] [for-2.8 0/4] 9p patches for 2.8 20161123
  2016-11-24 10:19 ` [Qemu-devel] [for-2.8 0/4] 9p patches for 2.8 20161123 Stefan Hajnoczi
@ 2016-11-24 10:36   ` Greg Kurz
  2016-11-24 15:24     ` Stefan Hajnoczi
  0 siblings, 1 reply; 8+ messages in thread
From: Greg Kurz @ 2016-11-24 10:36 UTC (permalink / raw)
  To: Stefan Hajnoczi; +Cc: qemu-devel, Aneesh Kumar K.V

[-- Attachment #1: Type: text/plain, Size: 1448 bytes --]

On Thu, 24 Nov 2016 10:19:58 +0000
Stefan Hajnoczi <stefanha@redhat.com> wrote:

> On Wed, Nov 23, 2016 at 05:58:14PM +0100, Greg Kurz wrote:
> > The following changes since commit 00227fefd2059464cd2f59aed29944874c630e2f:
> > 
> >   Update version for v2.8.0-rc1 release (2016-11-22 22:29:08 +0000)
> > 
> > are available in the git repository at:
> > 
> >   https://github.com/gkurz/qemu.git tags/for-upstream
> > 
> > for you to fetch changes up to 898ae90a44551d25b8e956fd87372d303c82fe68:
> > 
> >   9pfs: add cleanup operation for proxy backend driver (2016-11-23 13:53:34 +0100)
> > 
> > ----------------------------------------------------------------
> > This pull request fixes some leaks (memory, fd) in the handle and proxy
> > backends.  
> 
> Hi Greg,
> Please make sure to aways use the "[PULL]" tag in the Subject so tools
> can track your pull requests.
> 

Hi Stefan,

Damn... I wanted to add for-2.8 and forgot PULL :(

I'll fix my script to add this or at least to yell at me.

> I have applied this pull request manually to my staging tree:
> https://github.com/stefanha/qemu/commits/staging
> 

Thanks.

> Your PGP key has only one signature.  Can you key sign with other
> IBMers?  That may allow us to get the Web of Trust going.
> 

We're only a few IBMers in my area (Toulouse, France), but I guess this
is better than nothing. :)

Cheers.

--
Greg

> Thanks,
> Stefan


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]

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

* Re: [Qemu-devel] [for-2.8 0/4] 9p patches for 2.8 20161123
  2016-11-24 10:36   ` Greg Kurz
@ 2016-11-24 15:24     ` Stefan Hajnoczi
  0 siblings, 0 replies; 8+ messages in thread
From: Stefan Hajnoczi @ 2016-11-24 15:24 UTC (permalink / raw)
  To: Greg Kurz; +Cc: qemu-devel, Aneesh Kumar K.V

[-- Attachment #1: Type: text/plain, Size: 585 bytes --]

On Thu, Nov 24, 2016 at 11:36:29AM +0100, Greg Kurz wrote:
> On Thu, 24 Nov 2016 10:19:58 +0000
> Stefan Hajnoczi <stefanha@redhat.com> wrote:
> > On Wed, Nov 23, 2016 at 05:58:14PM +0100, Greg Kurz wrote:
> > Your PGP key has only one signature.  Can you key sign with other
> > IBMers?  That may allow us to get the Web of Trust going.
> > 
> 
> We're only a few IBMers in my area (Toulouse, France), but I guess this
> is better than nothing. :)

Will you attend FOSDEM (https://fosdem.org/2017/) this year?  There will
be good opportunities for key signing.

Stefan

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 455 bytes --]

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

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

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-11-23 16:58 [Qemu-devel] [for-2.8 0/4] 9p patches for 2.8 20161123 Greg Kurz
2016-11-23 16:58 ` [Qemu-devel] [for-2.8 1/4] 9pfs: adjust the order of resource cleanup in device unrealize Greg Kurz
2016-11-23 16:58 ` [Qemu-devel] [for-2.8 2/4] 9pfs: add cleanup operation in FileOperations Greg Kurz
2016-11-23 16:58 ` [Qemu-devel] [for-2.8 3/4] 9pfs: add cleanup operation for handle backend driver Greg Kurz
2016-11-23 16:58 ` [Qemu-devel] [for-2.8 4/4] 9pfs: add cleanup operation for proxy " Greg Kurz
2016-11-24 10:19 ` [Qemu-devel] [for-2.8 0/4] 9p patches for 2.8 20161123 Stefan Hajnoczi
2016-11-24 10:36   ` Greg Kurz
2016-11-24 15:24     ` Stefan Hajnoczi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).