From nobody Thu Nov 28 11:02:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1694137120; cv=none; d=zohomail.com; s=zohoarc; b=KvTSbyV6Hhryrqv6FGgTH5QOEQX/hqlqBsOTvrg4W3lhntX/R9Xtd7ey5odAP0JpjW1EhcYpB6vxnR4wHi4BiXIDTFsln6BW1gsOx8JOK29zEeqPGor3y2soLPq08kLeenpK4XpIfSW8zMpNBGTlbp2FkJy89oOpyiDHcc1zlp4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694137120; 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=63Ix7Q5D9PN9ujxdrnZSPehQvT/Y89bchGCE2+919r0=; b=H2asRAHIWdz/OidF9IEOKF3XBX6Qe2fMbu4LQZuGfjKkEwQ8BZy/coguIp1XVjjW01ggieAw0r7FSmy4iNg8kwxlTyllLahYV5Tzs8ZuBVHiwvgOTjzZgyaPkGkKTFnY8KYPW8IbPt9cp8bgoVahw3QZCG0e5kIqRwoOcM19kSg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1694137120468137.47316300149976; Thu, 7 Sep 2023 18:38:40 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qeQQ6-0008Uq-Lc; Thu, 07 Sep 2023 21:36:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qeQQ4-0008TE-AH for qemu-devel@nongnu.org; Thu, 07 Sep 2023 21:36:24 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qeQQ0-0007to-5v for qemu-devel@nongnu.org; Thu, 07 Sep 2023 21:36:24 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-473-vH5j-FoAPuuyBdjWvUmXmA-1; Thu, 07 Sep 2023 21:36:17 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D3A5C948C01; Fri, 8 Sep 2023 01:36:16 +0000 (UTC) Received: from green.redhat.com (unknown [10.2.16.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7007240C2070; Fri, 8 Sep 2023 01:36:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694136979; 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=63Ix7Q5D9PN9ujxdrnZSPehQvT/Y89bchGCE2+919r0=; b=LnJxqoYT+3wn8gOMhQPqeUplpJbsWACI3apaJ2IQISMwua2UI+ERMaahPzVKVynaQC/DB5 W3HxVZ3mqqnld+OcKTpOl6mnweOZPeoQ5vQBBtlRCY5Laf42tKF709qoqQRmrnJ65YXVwL MEZrZan2EPzLMIPyqzsGiTEC5sALfA8= X-MC-Unique: vH5j-FoAPuuyBdjWvUmXmA-1 From: Eric Blake To: qemu-devel@nongnu.org Cc: "Denis V. Lunev" , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org (open list:Network Block Dev...) Subject: [PULL 08/13] qemu-nbd: define struct NbdClientOpts when HAVE_NBD_DEVICE is not defined Date: Thu, 7 Sep 2023 20:35:44 -0500 Message-ID: <20230908013535.990731-23-eblake@redhat.com> In-Reply-To: <20230908013535.990731-15-eblake@redhat.com> References: <20230908013535.990731-15-eblake@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 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=170.10.129.124; envelope-from=eblake@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1694137120713100001 Content-Type: text/plain; charset="utf-8" From: "Denis V. Lunev" This patch also drops definition of some locals in main() to avoid useless data copy. Signed-off-by: Denis V. Lunev CC: Eric Blake CC: Vladimir Sementsov-Ogievskiy Message-ID: <20230906093210.339585-3-den@openvz.org> Reviewed-by: Eric Blake Signed-off-by: Eric Blake --- qemu-nbd.c | 60 ++++++++++++++++++++++++------------------------------ 1 file changed, 27 insertions(+), 33 deletions(-) diff --git a/qemu-nbd.c b/qemu-nbd.c index e2480061a16..acbdc0cd8fd 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -253,6 +253,12 @@ static int qemu_nbd_client_list(SocketAddress *saddr, = QCryptoTLSCreds *tls, } +struct NbdClientOpts { + char *device; + bool fork_process; + bool verbose; +}; + #if HAVE_NBD_DEVICE static void *show_parts(void *arg) { @@ -271,12 +277,6 @@ static void *show_parts(void *arg) return NULL; } -struct NbdClientOpts { - char *device; - bool fork_process; - bool verbose; -}; - static void *nbd_client_thread(void *arg) { struct NbdClientOpts *opts =3D arg; @@ -519,7 +519,6 @@ int main(int argc, char **argv) const char *bindto =3D NULL; const char *port =3D NULL; char *sockpath =3D NULL; - char *device =3D NULL; QemuOpts *sn_opts =3D NULL; const char *sn_id_or_name =3D NULL; const char *sopt =3D "hVb:o:p:rsnc:dvk:e:f:tl:x:T:D:AB:L"; @@ -582,16 +581,16 @@ int main(int argc, char **argv) const char *tlshostname =3D NULL; bool imageOpts =3D false; bool writethrough =3D false; /* Client will flush as needed. */ - bool verbose =3D false; - bool fork_process =3D false; bool list =3D false; unsigned socket_activation; const char *pid_file_name =3D NULL; const char *selinux_label =3D NULL; BlockExportOptions *export_opts; -#if HAVE_NBD_DEVICE - struct NbdClientOpts opts; -#endif + struct NbdClientOpts opts =3D { + .fork_process =3D false, + .verbose =3D false, + .device =3D NULL, + }; #ifdef CONFIG_POSIX os_setup_early_signal_handling(); @@ -719,7 +718,7 @@ int main(int argc, char **argv) disconnect =3D true; break; case 'c': - device =3D optarg; + opts.device =3D optarg; break; case 'e': if (qemu_strtoi(optarg, NULL, 0, &shared) < 0 || @@ -750,7 +749,7 @@ int main(int argc, char **argv) } break; case 'v': - verbose =3D true; + opts.verbose =3D true; break; case 'V': version(argv[0]); @@ -782,7 +781,7 @@ int main(int argc, char **argv) tlsauthz =3D optarg; break; case QEMU_NBD_OPT_FORK: - fork_process =3D true; + opts.fork_process =3D true; break; case 'L': list =3D true; @@ -802,12 +801,12 @@ int main(int argc, char **argv) exit(EXIT_FAILURE); } if (export_name || export_description || dev_offset || - device || disconnect || fmt || sn_id_or_name || bitmaps || + opts.device || disconnect || fmt || sn_id_or_name || bitmaps || alloc_depth || seen_aio || seen_discard || seen_cache) { error_report("List mode is incompatible with per-device settin= gs"); exit(EXIT_FAILURE); } - if (fork_process) { + if (opts.fork_process) { error_report("List mode is incompatible with forking"); exit(EXIT_FAILURE); } @@ -832,7 +831,8 @@ int main(int argc, char **argv) } } else { /* Using socket activation - check user didn't use -p etc. */ - const char *err_msg =3D socket_activation_validate_opts(device, so= ckpath, + const char *err_msg =3D socket_activation_validate_opts(opts.devic= e, + sockpath, bindto, port, selinux_labe= l, list); @@ -850,7 +850,7 @@ int main(int argc, char **argv) } if (tlscredsid) { - if (device) { + if (opts.device) { error_report("TLS is not supported with a host device"); exit(EXIT_FAILURE); } @@ -880,7 +880,7 @@ int main(int argc, char **argv) if (selinux_label) { #ifdef CONFIG_SELINUX - if (sockpath =3D=3D NULL && device =3D=3D NULL) { + if (sockpath =3D=3D NULL && opts.device =3D=3D NULL) { error_report("--selinux-label is not permitted without --socke= t"); exit(EXIT_FAILURE); } @@ -897,7 +897,7 @@ int main(int argc, char **argv) } #if !HAVE_NBD_DEVICE - if (disconnect || device) { + if (disconnect || opts.device) { error_report("Kernel /dev/nbdN support not available"); exit(EXIT_FAILURE); } @@ -919,7 +919,7 @@ int main(int argc, char **argv) } #endif - if ((device && !verbose) || fork_process) { + if ((opts.device && !opts.verbose) || opts.fork_process) { #ifndef WIN32 g_autoptr(GError) err =3D NULL; int stderr_fd[2]; @@ -1002,9 +1002,9 @@ int main(int argc, char **argv) #endif /* WIN32 */ } - if (device !=3D NULL && sockpath =3D=3D NULL) { + if (opts.device !=3D NULL && sockpath =3D=3D NULL) { sockpath =3D g_malloc(128); - snprintf(sockpath, 128, SOCKET_PATH, basename(device)); + snprintf(sockpath, 128, SOCKET_PATH, basename(opts.device)); } server =3D qio_net_listener_new(); @@ -1145,15 +1145,9 @@ int main(int argc, char **argv) blk_exp_add(export_opts, &error_fatal); qapi_free_BlockExportOptions(export_opts); - if (device) { + if (opts.device) { #if HAVE_NBD_DEVICE int ret; - opts =3D (struct NbdClientOpts) { - .device =3D device, - .fork_process =3D fork_process, - .verbose =3D verbose, - }; - ret =3D pthread_create(&client_thread, NULL, nbd_client_thread, &o= pts); if (ret !=3D 0) { error_report("Failed to create client thread: %s", strerror(re= t)); @@ -1179,7 +1173,7 @@ int main(int argc, char **argv) exit(EXIT_FAILURE); } - if (fork_process) { + if (opts.fork_process) { if (dup2(STDOUT_FILENO, STDERR_FILENO) < 0) { error_report("Could not release pipe to parent: %s", strerror(errno)); @@ -1203,7 +1197,7 @@ int main(int argc, char **argv) qemu_opts_del(sn_opts); - if (device) { + if (opts.device) { void *ret; pthread_join(client_thread, &ret); exit(ret !=3D NULL); --=20 2.41.0