From nobody Tue Mar 24 00:58:49 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1774015178; cv=none; d=zohomail.com; s=zohoarc; b=ed7WcVnWyT4tbOqAvhtJhU/1kAJuUtg1bKbug8NsT7/YEfnP0C3K+K/tEHNgw5OEf/YfbiJsCU+RnlsHnVYc3vTIpZRRHLC96OIl8r6O4G+R5DU8ofpJpo37i6Jmjnh0AnrSj6FwKaQI6eWfyJ79F0WISGGqduKuu9oUUzb4c2Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1774015178; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id; bh=RVhHcPf2/GdfBXRsIRnb7h/sgFW184beBCa26FcWANc=; b=HROGnqdbIVHVCzFAU+HIQvMIgLhoyn941+bYb5HOgG5Mx/UQA+TYg7JtgaS9LO8zTN2TsxTpWX9bjJFUBLfdQMso3Yc4/3xrGwtl1UMlzj+XOJDBZawbIvdlGaGCtHmM2SoUpmmG6M+gSN+E2WUlLjcY+Qybuwr+zhiY5rftgVs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1774015178074732.3971474975851; Fri, 20 Mar 2026 06:59:38 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 53DE04184D; Fri, 20 Mar 2026 09:59:37 -0400 (EDT) Received: from [172.19.199.12] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 317F541B73; Fri, 20 Mar 2026 09:57:42 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 6651A4198E; Fri, 20 Mar 2026 09:57:36 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 2C9424188C for ; Fri, 20 Mar 2026 09:56:57 -0400 (EDT) Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-146-QoRgDZgrPPqfzx5vhhmOTg-1; Fri, 20 Mar 2026 09:56:53 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A2FDE19560AA; Fri, 20 Mar 2026 13:56:52 +0000 (UTC) Received: from speedmetal.openshiftapps.com (unknown [10.45.242.5]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1565E1955D84; Fri, 20 Mar 2026 13:56:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HELO_MISC_IP,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1774015016; 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=RVhHcPf2/GdfBXRsIRnb7h/sgFW184beBCa26FcWANc=; b=MjHs+VA0Y8/DMziGbhKjW+IXhxZPZnnRhnTjwILiVncCVS4pGs7JcKaKbLM39e3bgVrZPg M6rCQ0hchpdG3B/MlLkdXsbTH/IaJ4E/AbAl1wk9OFhPTCBabQcYeMmeMOpd+5lAX7GHIn sDgUgnrl36XWVD/PRTimNPLmorCTVIg= X-MC-Unique: QoRgDZgrPPqfzx5vhhmOTg-1 X-Mimecast-MFC-AGG-ID: QoRgDZgrPPqfzx5vhhmOTg_1774015012 To: devel@lists.libvirt.org Subject: [PATCH v2 3/3] qemu: add automatic port allocation for pull-mode backup NBD servers Date: Fri, 20 Mar 2026 14:56:44 +0100 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: ptCx96OBd6BaS5J8TpOnx2we7BwlcoSRjW4h_L5_agg_1774015012 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: IB5RSANAHTM4E6HXGYS22JSFDNVBGDK3 X-Message-ID-Hash: IB5RSANAHTM4E6HXGYS22JSFDNVBGDK3 X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Peter Krempa , Lucas Amaral X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Peter Krempa via Devel Reply-To: Peter Krempa X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1774015179121158500 Content-Type: text/plain; charset="utf-8" From: Lucas Amaral Previously, users had to manually specify a TCP port when starting a pull-mode backup with an NBD server. A TODO comment in qemuBackupPrepare() noted this limitation and pointed toward using virPortAllocator, as done for migration, VNC, and SPICE ports. When a pull-mode backup is started without specifying a TCP port, a port is now acquired automatically from the configured range via virPortAllocatorAcquire(). The port is released when the backup ends or if startup fails. Signed-off-by: Lucas Amaral Signed-off-by: Peter Krempa Reviewed-by: Peter Krempa --- docs/formatbackup.rst | 3 ++- src/qemu/qemu_backup.c | 30 ++++++++++++++++++++---------- src/qemu/qemu_domain.h | 1 + 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/docs/formatbackup.rst b/docs/formatbackup.rst index df6392e3bd..24857eaf72 100644 --- a/docs/formatbackup.rst +++ b/docs/formatbackup.rst @@ -42,7 +42,8 @@ were supplied). The following child elements and attribut= es are supported: ```protocol`` element of a disk `__ attached via NBD in the domain (such as transport, socket, name, port, or tls), necessary to set up an NBD server that exposes the content of each disk= at - the time the backup is started. + the time the backup is started. For TCP transport, if ``port`` is omitt= ed, a + port is allocated automatically from the range configured in ``/etc/lib= virt/qemu.conf``. In addition to the above the NBD server used for backups allows using ``transport=3D'fd' fdgroup=3D'NAME'`` where ``NAME`` is the name used w= ith diff --git a/src/qemu/qemu_backup.c b/src/qemu/qemu_backup.c index d380dd3a63..ddab4be34b 100644 --- a/src/qemu/qemu_backup.c +++ b/src/qemu/qemu_backup.c @@ -32,6 +32,7 @@ #include "storage_source.h" #include "storage_source_conf.h" #include "virerror.h" +#include "virportallocator.h" #include "virlog.h" #include "virbuffer.h" #include "backup_conf.h" @@ -58,7 +59,8 @@ qemuDomainGetBackup(virDomainObj *vm) static int -qemuBackupPrepare(virDomainBackupDef *def) +qemuBackupPrepare(qemuDomainObjPrivate *priv, + virDomainBackupDef *def) { if (def->type =3D=3D VIR_DOMAIN_BACKUP_TYPE_PULL) { @@ -71,15 +73,12 @@ qemuBackupPrepare(virDomainBackupDef *def) switch (def->server->transport) { case VIR_STORAGE_NET_HOST_TRANS_TCP: - /* TODO: Update qemu.conf to provide a port range, - * probably starting at 10809, for obtaining automatic - * port via virPortAllocatorAcquire, as well as store - * somewhere if we need to call virPortAllocatorRelease - * during BackupEnd. Until then, user must provide port */ if (!def->server->port) { - virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", - _(" must specify TCP port for= now")); - return -1; + if (virPortAllocatorAcquire(priv->driver->backupPorts, + &priv->backupNBDPort) < 0) + return -1; + + def->server->port =3D priv->backupNBDPort; } break; @@ -838,7 +837,7 @@ qemuBackupBegin(virDomainObj *vm, goto endjob; } - if (qemuBackupPrepare(def) < 0) + if (qemuBackupPrepare(priv, def) < 0) goto endjob; if (qemuBackupBeginPrepareTLS(vm, cfg, def, &tlsProps, &tlsSecretProps= ) < 0) @@ -969,6 +968,11 @@ qemuBackupBegin(virDomainObj *vm, qemuDomainObjExitMonitor(vm); } + if (ret < 0 && priv->backupNBDPort) { + virPortAllocatorRelease(priv->backupNBDPort); + priv->backupNBDPort =3D 0; + } + if (ret < 0 && !job_started && priv->backup) def =3D g_steal_pointer(&priv->backup); @@ -1026,6 +1030,12 @@ qemuBackupNotifyBlockjobEndStopNBD(virDomainObj *vm, qemuDomainObjExitMonitor(vm); backup->nbdStopped =3D true; + + if (priv->backupNBDPort) { + virPortAllocatorRelease(priv->backupNBDPort); + priv->backupNBDPort =3D 0; + backup->server->port =3D 0; + } } diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index f797542a87..b321a64e96 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -147,6 +147,7 @@ struct _qemuDomainObjPrivate { char *origname; int nbdPort; /* Port used for migration with NBD */ unsigned short migrationPort; + unsigned short backupNBDPort; int preMigrationState; unsigned long long preMigrationMemlock; /* Original RLIMIT_MEMLOCK in = case it was changed for the curr= ent --=20 2.53.0