From nobody Sun Oct 5 21:12:42 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1582768672; cv=none; d=zohomail.com; s=zohoarc; b=LWUpSlNGcFHsolNIRqtbvRsAKtiSYBTb1qlMg/xA9VjkgTyGM2ZjD+el/vx7asfGYlKAQnQ1uqQe0wws46ndcdg/76yZjmcWPPIbA+RByo6nquH2lM1IoSjCmpMxHlS2UWtIM7muzLeMmesAbzUDCwWeVCDjm5fzrji0diYEg4Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582768672; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=rsUu0Tkg4IjYGzEi8JY5J1KyolilE13RDr+tqC7JBSE=; b=DIperlobnsazc0kQbrfP3uSF8bjHlbbaPAbPlK459+dDZrFttSmRfsZVYvROpfHpw1o9pJiJVm/VJyeP7Sr9awNe0ZtqPYXLbbIzJDKCcr2K9WJxfBapr+szrmeSzifeOHV4oAqJ/SCjpFIEQfGy9ucRrVUvK8kRy6V8KUUsDfQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1582768672927939.0675702882388; Wed, 26 Feb 2020 17:57:52 -0800 (PST) Received: from localhost ([::1]:52702 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j78Qx-0000LW-RK for importer@patchew.org; Wed, 26 Feb 2020 20:57:51 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:36343) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j78OA-0004c5-NT for qemu-devel@nongnu.org; Wed, 26 Feb 2020 20:54:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j78O9-0002ZF-6v for qemu-devel@nongnu.org; Wed, 26 Feb 2020 20:54:58 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:53569 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j78O9-0002Ww-2y for qemu-devel@nongnu.org; Wed, 26 Feb 2020 20:54:57 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-88-MFB1uurqO6GzKwFcH6BciA-1; Wed, 26 Feb 2020 20:54:54 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E9A7413E5; Thu, 27 Feb 2020 01:54:52 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-57.phx2.redhat.com [10.3.116.57]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2161A5C578; Thu, 27 Feb 2020 01:54:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582768496; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rsUu0Tkg4IjYGzEi8JY5J1KyolilE13RDr+tqC7JBSE=; b=Jlks9anUsxJ1oIQIqlRtHdRuInKFEV5b1j6SnDgDro6fpmsN5kWugRPAMV2CmhypHElHLY +GFfmXby1Tcbca1Ep3WpALJBf1R/MZMKicG97LqAQniE7m/JGG/1d5Iq55a0qJJUZwUUwW ZfkkvMIxrK6IqJ56Y973VvnxKyJLHQA= X-MC-Unique: MFB1uurqO6GzKwFcH6BciA-1 From: Eric Blake To: qemu-devel@nongnu.org Subject: [PULL 3/4] block/nbd: extract the common cleanup code Date: Wed, 26 Feb 2020 19:54:47 -0600 Message-Id: <20200227015448.960538-4-eblake@redhat.com> In-Reply-To: <20200227015448.960538-1-eblake@redhat.com> References: <20200227015448.960538-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , "open list:Network Block Dev..." , Pan Nengyuan , Max Reitz , Stefano Garzarella Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Pan Nengyuan The BDRVNBDState cleanup code is common in two places, add nbd_clear_bdrvstate() function to do these cleanups. Suggested-by: Stefano Garzarella Signed-off-by: Pan Nengyuan Reviewed-by: Vladimir Sementsov-Ogievskiy Message-Id: <1575517528-44312-2-git-send-email-pannengyuan@huawei.com> Reviewed-by: Eric Blake [eblake: fix compilation error and commit message] Signed-off-by: Eric Blake --- block/nbd.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/block/nbd.c b/block/nbd.c index f69e61e68ad6..ed0f93ab27a9 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -95,6 +95,19 @@ typedef struct BDRVNBDState { static int nbd_client_connect(BlockDriverState *bs, Error **errp); +static void nbd_clear_bdrvstate(BDRVNBDState *s) +{ + object_unref(OBJECT(s->tlscreds)); + qapi_free_SocketAddress(s->saddr); + s->saddr =3D NULL; + g_free(s->export); + s->export =3D NULL; + g_free(s->tlscredsid); + s->tlscredsid =3D NULL; + g_free(s->x_dirty_bitmap); + s->x_dirty_bitmap =3D NULL; +} + static void nbd_channel_error(BDRVNBDState *s, int ret) { if (ret =3D=3D -EIO) { @@ -1879,11 +1892,7 @@ static int nbd_process_options(BlockDriverState *bs,= QDict *options, error: if (ret < 0) { - object_unref(OBJECT(s->tlscreds)); - qapi_free_SocketAddress(s->saddr); - g_free(s->export); - g_free(s->tlscredsid); - g_free(s->x_dirty_bitmap); + nbd_clear_bdrvstate(s); } qemu_opts_del(opts); return ret; @@ -1962,12 +1971,7 @@ static void nbd_close(BlockDriverState *bs) BDRVNBDState *s =3D bs->opaque; nbd_client_close(bs); - - object_unref(OBJECT(s->tlscreds)); - qapi_free_SocketAddress(s->saddr); - g_free(s->export); - g_free(s->tlscredsid); - g_free(s->x_dirty_bitmap); + nbd_clear_bdrvstate(s); } static int64_t nbd_getlength(BlockDriverState *bs) --=20 2.24.1