From nobody Fri May 16 04:42:46 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1499688472425770.3759902838177; Mon, 10 Jul 2017 05:07:52 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 62AB5C062CE7; Mon, 10 Jul 2017 12:07:47 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 34E747D4F6; Mon, 10 Jul 2017 12:07:47 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id B34DB157C2; Mon, 10 Jul 2017 12:07:46 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v6AC7ijh018562 for ; Mon, 10 Jul 2017 08:07:44 -0400 Received: by smtp.corp.redhat.com (Postfix) id D4898182F6; Mon, 10 Jul 2017 12:07:44 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.201]) by smtp.corp.redhat.com (Postfix) with ESMTP id 330F6182E0; Mon, 10 Jul 2017 12:07:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 62AB5C062CE7 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 62AB5C062CE7 From: Peter Krempa To: libvir-list@redhat.com Date: Mon, 10 Jul 2017 14:07:34 +0200 Message-Id: <0d939d9b9ccea56c2f2df416aa5812b64008baaf.1499688409.git.pkrempa@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH 02/10] util: Extract helper to retrieve default port for network protocol X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Mon, 10 Jul 2017 12:07:48 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Make the stuff hardcoded in qemu a global helper so that other parts of the code can determine the default port too. --- src/libvirt_private.syms | 1 + src/qemu/qemu_command.c | 55 ++++++++-----------------------------------= ---- src/util/virstoragefile.c | 43 ++++++++++++++++++++++++++++++++++++ src/util/virstoragefile.h | 3 +++ 4 files changed, 56 insertions(+), 46 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 888412ac7..44b5dc1e0 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2614,6 +2614,7 @@ virStorageSourceIsBlockLocal; virStorageSourceIsEmpty; virStorageSourceIsLocalStorage; virStorageSourceIsRelative; +virStorageSourceNetworkDefaultPort; virStorageSourceNewFromBacking; virStorageSourceNewFromBackingAbsolute; virStorageSourceParseRBDColonString; diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index f77ae91c3..e5f4bdab7 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -482,55 +482,18 @@ qemuNetworkDriveGetPort(int protocol, { int ret =3D 0; - if (port) { - if (virStrToLong_i(port, NULL, 10, &ret) < 0 || ret < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("failed to parse port number '%s'"), - port); - return -1; - } - - return ret; - } - - switch ((virStorageNetProtocol) protocol) { - case VIR_STORAGE_NET_PROTOCOL_HTTP: - return 80; - - case VIR_STORAGE_NET_PROTOCOL_HTTPS: - return 443; - - case VIR_STORAGE_NET_PROTOCOL_FTP: - return 21; - - case VIR_STORAGE_NET_PROTOCOL_FTPS: - return 990; - - case VIR_STORAGE_NET_PROTOCOL_TFTP: - return 69; - - case VIR_STORAGE_NET_PROTOCOL_SHEEPDOG: - return 7000; - - case VIR_STORAGE_NET_PROTOCOL_NBD: - return 10809; - - case VIR_STORAGE_NET_PROTOCOL_SSH: - return 22; - - case VIR_STORAGE_NET_PROTOCOL_ISCSI: - case VIR_STORAGE_NET_PROTOCOL_GLUSTER: - /* no default port specified */ - return 0; + if (!port && + !(port =3D virStorageSourceNetworkDefaultPort(protocol))) + return -1; - case VIR_STORAGE_NET_PROTOCOL_RBD: - case VIR_STORAGE_NET_PROTOCOL_LAST: - case VIR_STORAGE_NET_PROTOCOL_NONE: - /* not applicable */ - return -1; + if (virStrToLong_i(port, NULL, 10, &ret) < 0 || ret < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("failed to parse port number '%s'"), + port); + return -1; } - return -1; + return ret; } diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index f0ed5c6bd..cae20eccc 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -4018,3 +4018,46 @@ virStorageSourceFindByNodeName(virStorageSourcePtr t= op, *idx =3D 0; return NULL; } + + +const char * +virStorageSourceNetworkDefaultPort(virStorageNetProtocol protocol) +{ + switch (protocol) { + case VIR_STORAGE_NET_PROTOCOL_HTTP: + return "80"; + + case VIR_STORAGE_NET_PROTOCOL_HTTPS: + return "443"; + + case VIR_STORAGE_NET_PROTOCOL_FTP: + return "21"; + + case VIR_STORAGE_NET_PROTOCOL_FTPS: + return "990"; + + case VIR_STORAGE_NET_PROTOCOL_TFTP: + return "69"; + + case VIR_STORAGE_NET_PROTOCOL_SHEEPDOG: + return "7000"; + + case VIR_STORAGE_NET_PROTOCOL_NBD: + return "10809"; + + case VIR_STORAGE_NET_PROTOCOL_SSH: + return "22"; + + case VIR_STORAGE_NET_PROTOCOL_ISCSI: + case VIR_STORAGE_NET_PROTOCOL_GLUSTER: + /* no default port specified */ + return "0"; + + case VIR_STORAGE_NET_PROTOCOL_RBD: + case VIR_STORAGE_NET_PROTOCOL_LAST: + case VIR_STORAGE_NET_PROTOCOL_NONE: + return NULL; + } + + return NULL; +} diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h index 0bff8671f..877c3af4d 100644 --- a/src/util/virstoragefile.h +++ b/src/util/virstoragefile.h @@ -406,4 +406,7 @@ virStorageSourceFindByNodeName(virStorageSourcePtr top, unsigned int *index) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); +const char * +virStorageSourceNetworkDefaultPort(virStorageNetProtocol protocol); + #endif /* __VIR_STORAGE_FILE_H__ */ --=20 2.12.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list