From nobody Mon Feb 9 00:19:36 2026 Delivered-To: importer@patchew.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=1599503128; cv=none; d=zohomail.com; s=zohoarc; b=DZazn5ZFbujxXPYomlxWOvl7s2rVRKHwBueve1ri8d8uyBM0J3N39lnxjFx1KWljFB5bZMwaIsCkG7bO4TpYOb7dHOjMpAfB8BCrqXNlt7TYg1Px8GPi4+J3LG062EqCksQD7hKYc5E6lEBOxE6YmmMZJl1xZqHAAW3GlpDCv9M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599503128; 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=798l8+hFqVoamxgVw7ZgCRsaMCCCrno9HHmFjmK7mOM=; b=Td22ePPJg1BoPFbmcoT788jQCz+yY8UkP/LiVPY8MWheNvxEkPcNktGmmuf0BhDjgRVXtAZTAbDoerVBhEJrsOuex5gG7BPEf9jlaHjubq5QgIk3BNXY1m08TJE3eeUprhwZIscCbzxJ/dpjIlabckGHPfKSr23Nc9XPBjirhAY= 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 1599503128412188.67462204306594; Mon, 7 Sep 2020 11:25:28 -0700 (PDT) Received: from localhost ([::1]:53642 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kFLpX-0005g2-5V for importer@patchew.org; Mon, 07 Sep 2020 14:25:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42460) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kFLl7-0005Hg-4N for qemu-devel@nongnu.org; Mon, 07 Sep 2020 14:20:53 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:26872 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kFLkx-0004U3-Eo for qemu-devel@nongnu.org; Mon, 07 Sep 2020 14:20:52 -0400 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-259-dkhMTY0HM9OZf1F6ug1bHw-1; Mon, 07 Sep 2020 14:20:41 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4B2AF1084C85; Mon, 7 Sep 2020 18:20:40 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-114-154.ams2.redhat.com [10.36.114.154]) by smtp.corp.redhat.com (Postfix) with ESMTP id 336EB60BF3; Mon, 7 Sep 2020 18:20:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1599502842; 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=798l8+hFqVoamxgVw7ZgCRsaMCCCrno9HHmFjmK7mOM=; b=b6fFqxWFjmmQUVK3wXLK/RrZrsxBnhJzcUEskuaW3CcT61yU6oCXkoCDOtzMS3vIJ2BGZu MaqXd95uWL7t/dozQWXT/jVFmyXaM0sfrGrCBfV0AYV9mSKaoYtMgU+oqcqAK6K2NvtY26 RUyT1ysp5us328VFhoYoeCbcLGVrSLE= X-MC-Unique: dkhMTY0HM9OZf1F6ug1bHw-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PATCH 11/29] qemu-nbd: Use blk_exp_add() to create the export Date: Mon, 7 Sep 2020 20:19:53 +0200 Message-Id: <20200907182011.521007-12-kwolf@redhat.com> In-Reply-To: <20200907182011.521007-1-kwolf@redhat.com> References: <20200907182011.521007-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0.002 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=207.211.31.120; envelope-from=kwolf@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/07 02:54:37 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: kwolf@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com 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" With this change, NBD exports are now only created through the BlockExport interface. This allows us finally to move things from the NBD layer to the BlockExport layer if they make sense for other export types, too. blk_exp_add() returns only a weak reference, so the explicit nbd_export_put() goes away. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- include/block/nbd.h | 1 + blockdev-nbd.c | 8 +++++++- qemu-nbd.c | 28 ++++++++++++++++++++++------ 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/include/block/nbd.h b/include/block/nbd.h index 9449b3dac4..1dafe70615 100644 --- a/include/block/nbd.h +++ b/include/block/nbd.h @@ -352,6 +352,7 @@ void nbd_client_new(QIOChannelSocket *sioc, void nbd_client_get(NBDClient *client); void nbd_client_put(NBDClient *client); =20 +void nbd_server_is_qemu_nbd(bool value); void nbd_server_start(SocketAddress *addr, const char *tls_creds, const char *tls_authz, uint32_t max_connections, Error **errp); diff --git a/blockdev-nbd.c b/blockdev-nbd.c index 3a51b3e792..7bb0b09697 100644 --- a/blockdev-nbd.c +++ b/blockdev-nbd.c @@ -28,9 +28,15 @@ typedef struct NBDServerData { } NBDServerData; =20 static NBDServerData *nbd_server; +static bool is_qemu_nbd; =20 static void nbd_update_server_watch(NBDServerData *s); =20 +void nbd_server_is_qemu_nbd(bool value) +{ + is_qemu_nbd =3D value; +} + static void nbd_blockdev_client_closed(NBDClient *client, bool ignored) { nbd_client_put(client); @@ -176,7 +182,7 @@ BlockExport *nbd_export_create(BlockExportOptions *exp_= args, Error **errp) =20 assert(exp_args->type =3D=3D BLOCK_EXPORT_TYPE_NBD); =20 - if (!nbd_server) { + if (!nbd_server && !is_qemu_nbd) { error_setg(errp, "NBD server not running"); return NULL; } diff --git a/qemu-nbd.c b/qemu-nbd.c index cab65529a5..a863741e8f 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -65,7 +65,6 @@ =20 #define MBR_SIZE 512 =20 -static NBDExport *export; static int verbose; static char *srcpath; static SocketAddress *saddr; @@ -580,6 +579,7 @@ int main(int argc, char **argv) int old_stderr =3D -1; unsigned socket_activation; const char *pid_file_name =3D NULL; + BlockExportOptions *export_opts; =20 #if HAVE_NBD_DEVICE /* The client thread uses SIGTERM to interrupt the server. A signal @@ -1059,9 +1059,27 @@ int main(int argc, char **argv) =20 bs->detect_zeroes =3D detect_zeroes; =20 - export =3D nbd_export_new(bs, export_name, - export_description, bitmap, readonly, shared >= 1, - writethrough, &error_fatal); + nbd_server_is_qemu_nbd(true); + + export_opts =3D g_new(BlockExportOptions, 1); + *export_opts =3D (BlockExportOptions) { + .type =3D BLOCK_EXPORT_TYPE_NBD, + .has_writethrough =3D true, + .writethrough =3D writethrough, + .u.nbd =3D { + .device =3D g_strdup(bdrv_get_node_name(bs)), + .has_name =3D true, + .name =3D g_strdup(export_name), + .has_description =3D !!export_description, + .description =3D g_strdup(export_description), + .has_writable =3D true, + .writable =3D !readonly, + .has_bitmap =3D !!bitmap, + .bitmap =3D g_strdup(bitmap), + }, + }; + blk_exp_add(export_opts, &error_fatal); + qapi_free_BlockExportOptions(export_opts); =20 if (device) { #if HAVE_NBD_DEVICE @@ -1101,9 +1119,7 @@ int main(int argc, char **argv) do { main_loop_wait(false); if (state =3D=3D TERMINATE) { - nbd_export_put(export); nbd_export_close_all(); - export =3D NULL; state =3D TERMINATED; } } while (state !=3D TERMINATED); --=20 2.25.4