From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37447) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c9at2-0005RI-P1 for qemu-devel@nongnu.org; Wed, 23 Nov 2016 11:59:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c9asz-0005bI-Lt for qemu-devel@nongnu.org; Wed, 23 Nov 2016 11:59:08 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:38310 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1c9asz-0005aV-Fd for qemu-devel@nongnu.org; Wed, 23 Nov 2016 11:59:05 -0500 Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.17/8.16.0.17) with SMTP id uANGwkLm017464 for ; Wed, 23 Nov 2016 11:59:04 -0500 Received: from e06smtp08.uk.ibm.com (e06smtp08.uk.ibm.com [195.75.94.104]) by mx0a-001b2d01.pphosted.com with ESMTP id 26wcr2255w-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 23 Nov 2016 11:59:04 -0500 Received: from localhost by e06smtp08.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 23 Nov 2016 16:59:02 -0000 From: Greg Kurz Date: Wed, 23 Nov 2016 17:58:16 +0100 In-Reply-To: <1479920298-24983-1-git-send-email-groug@kaod.org> References: <1479920298-24983-1-git-send-email-groug@kaod.org> Message-Id: <1479920298-24983-3-git-send-email-groug@kaod.org> Subject: [Qemu-devel] [for-2.8 2/4] 9pfs: add cleanup operation in FileOperations List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Stefan Hajnoczi , "Aneesh Kumar K.V" , Greg Kurz , Li Qiang From: 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 Reviewed-by: Greg Kurz Signed-off-by: Greg Kurz --- 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