]>
Commit | Line | Data |
---|---|---|
f262231e WB |
1 | From f2ef9ae2a512fca1df0d56c226adc24ddf002b8b Mon Sep 17 00:00:00 2001 |
2 | From: Li Qiang <liq3ea@gmail.com> | |
3 | Date: Wed, 23 Nov 2016 13:53:34 +0100 | |
4 | Subject: [PATCH 07/12] 9pfs: add cleanup operation in FileOperations | |
5 | ||
6 | Currently, the backend of VirtFS doesn't have a cleanup | |
7 | function. This will lead resource leak issues if the backed | |
8 | driver allocates resources. This patch addresses this issue. | |
9 | ||
10 | Signed-off-by: Li Qiang <liq3ea@gmail.com> | |
11 | Reviewed-by: Greg Kurz <groug@kaod.org> | |
12 | Signed-off-by: Greg Kurz <groug@kaod.org> | |
13 | --- | |
14 | fsdev/file-op-9p.h | 1 + | |
15 | hw/9pfs/9p.c | 6 ++++++ | |
16 | 2 files changed, 7 insertions(+) | |
17 | ||
18 | diff --git a/fsdev/file-op-9p.h b/fsdev/file-op-9p.h | |
19 | index 6db9fea..a56dc84 100644 | |
20 | --- a/fsdev/file-op-9p.h | |
21 | +++ b/fsdev/file-op-9p.h | |
22 | @@ -100,6 +100,7 @@ struct FileOperations | |
23 | { | |
24 | int (*parse_opts)(QemuOpts *, struct FsDriverEntry *); | |
25 | int (*init)(struct FsContext *); | |
26 | + void (*cleanup)(struct FsContext *); | |
27 | int (*lstat)(FsContext *, V9fsPath *, struct stat *); | |
28 | ssize_t (*readlink)(FsContext *, V9fsPath *, char *, size_t); | |
29 | int (*chmod)(FsContext *, V9fsPath *, FsCred *); | |
30 | diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c | |
31 | index ced7b4c..f2a90d4 100644 | |
32 | --- a/hw/9pfs/9p.c | |
33 | +++ b/hw/9pfs/9p.c | |
34 | @@ -3490,6 +3490,9 @@ int v9fs_device_realize_common(V9fsState *s, Error **errp) | |
35 | rc = 0; | |
36 | out: | |
37 | if (rc) { | |
38 | + if (s->ops->cleanup && s->ctx.private) { | |
39 | + s->ops->cleanup(&s->ctx); | |
40 | + } | |
41 | g_free(s->tag); | |
42 | g_free(s->ctx.fs_root); | |
43 | v9fs_path_free(&path); | |
44 | @@ -3499,6 +3502,9 @@ out: | |
45 | ||
46 | void v9fs_device_unrealize_common(V9fsState *s, Error **errp) | |
47 | { | |
48 | + if (s->ops->cleanup) { | |
49 | + s->ops->cleanup(&s->ctx); | |
50 | + } | |
51 | g_free(s->tag); | |
52 | g_free(s->ctx.fs_root); | |
53 | } | |
54 | -- | |
55 | 2.1.4 | |
56 |