From patchwork Tue Nov 15 02:13:52 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Qiang X-Patchwork-Id: 9428801 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4758B6047D for ; Tue, 15 Nov 2016 02:14:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3D17D28B40 for ; Tue, 15 Nov 2016 02:14:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 30B9E28B42; Tue, 15 Nov 2016 02:14:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D12C228B40 for ; Tue, 15 Nov 2016 02:14:45 +0000 (UTC) Received: from localhost ([::1]:43634 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c6TGn-0004sf-2K for patchwork-qemu-devel@patchwork.kernel.org; Mon, 14 Nov 2016 21:14:45 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58860) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c6TGJ-0004rv-LY for qemu-devel@nongnu.org; Mon, 14 Nov 2016 21:14:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c6TGI-0006ib-Qo for qemu-devel@nongnu.org; Mon, 14 Nov 2016 21:14:15 -0500 Received: from mail-it0-x244.google.com ([2607:f8b0:4001:c0b::244]:33173) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1c6TGI-0006iS-Lf for qemu-devel@nongnu.org; Mon, 14 Nov 2016 21:14:14 -0500 Received: by mail-it0-x244.google.com with SMTP id c20so16289360itb.0 for ; Mon, 14 Nov 2016 18:14:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=EA/AceuXAK/YRQRn89VjvM2kzw1xTbEP/0Yf/xHx+aY=; b=g/+Q9Rjog+eo4O/NvvUFRzoAi9NFemqmbY+/FpbVAHE8+oq3xl3f6dIR/blOTTLdjv iqySu++YKAWwlLcKkTvCbyhgdzWBA1ISWbh+cfHRQizlwTjOQOqFvPvWIWKyBaHGnXw7 FjY3ge7RTW3zcVT2D4JQM2GA4fbfc0XeLTDZgRujkLZApbj+kbq0xA37JUwjxNslDuFi aI7V/m/wbNnfdolhAopmgq15rt/S6V37vDV+2GseDnRiCU62HwlBUzeOlC05Em7hakEk y7bXftOoUQtNAhpUqQxZyEBJz/SwMHE0nJkF7TPO0nYAXGn9zFVvfh8eEBCjqIe2JuaK PkFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=EA/AceuXAK/YRQRn89VjvM2kzw1xTbEP/0Yf/xHx+aY=; b=ixSqhdoaet88oCerZqCAUclZYErDqcL53ohPqrMrYgZ0KYL2tWAEOSZzC8EWFiXOtJ SOh1J8wvzvZJ4jVGDSHLjOPzEufAqFjWb7qYA7i+C0boLqVzvDNApfT+7wuhwBQnvebb abloVr69fo2poSZen9HFdUZPwT8m1wXETRrS7s87TWtywmdN6Hmq/8MEja0osjCvdnNG EnT6aas8He2m4VmbcWxlnOqJWKCSqGIwdHLU0Qdf+M6ag/BW9aUSDYJ4xzWm9pThRdr4 J6viWozUwTucTPUca9zTk0LxI9zk//XMLAZ9lky8fy0UX3pfL88tc3Y47j3xkxM6jAh+ 1Rzg== X-Gm-Message-State: ABUngvedXAzdT6qo6pynpTbWyD+gV4WGAtogAKSA7J4sC+wKNO/Iq0CX6czUK7nVzvVWUA== X-Received: by 10.107.17.38 with SMTP id z38mr5973716ioi.48.1479176054159; Mon, 14 Nov 2016 18:14:14 -0800 (PST) Received: from localhost.localdomain ([104.192.110.250]) by smtp.gmail.com with ESMTPSA id x99sm10496707ioi.17.2016.11.14.18.14.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 Nov 2016 18:14:13 -0800 (PST) From: Li Qiang To: groug@kaod.org, qemu-devel@nongnu.org Date: Mon, 14 Nov 2016 21:13:52 -0500 Message-Id: <1479176033-36604-3-git-send-email-liq3ea@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1479176033-36604-1-git-send-email-liq3ea@gmail.com> References: <1479176033-36604-1-git-send-email-liq3ea@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:4001:c0b::244 Subject: [Qemu-devel] [PATCH v2 2/3] 9pfs: add cleanup operation for handle backend driver X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Li Qiang , liqiang6-s@360.cn Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 Reviewed-by: Greg Kurz --- 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,