From nobody Mon Feb 9 06:50:44 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1598334530; cv=none; d=zohomail.com; s=zohoarc; b=ngIMWC+PMf12xXLkl0ssdmbToJZ1sMc40hcA+5WuAa9pOPZMwwoqY+QSQTowICS3ymkQcdjniIjn22seCYyjPOEF6kXVs4MAYmILrmfkYHHrsiBE5QnrSRbxBWI7unCK3DdCH2/8sskmlWR+sjrAMZJciKbGyqFwCwv2SRhjdDM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598334530; h=Content-Type:Content-Transfer-Encoding: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=ZT4yys1uXf1ZNpTHGrBV0DO7GCw/C5v0bjhUx6+XZ00=; b=Q7obCcSgmR8EevR4g3+WoTEuF0E4Cc+1/ulvVq+jH0CijkTgS1foXVGB0U9B/lZ6uXN72NEyfhDsBllPs9FLClv3ilNvVVY68L4ALNtYSNx2H8x0sGb+wIc5KuGR5+2dyftodStLbs7CdjvVsCVi6HQjfMlaw50B95YkVMQKP78= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1598334530792577.4522051993692; Mon, 24 Aug 2020 22:48:50 -0700 (PDT) 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-171-5eLDLbVqPoG7w4e615fNoA-1; Tue, 25 Aug 2020 01:48:46 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6A3B581F021; Tue, 25 Aug 2020 05:48:41 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DA99C3C89; Tue, 25 Aug 2020 05:48:40 +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 934A7181A06D; Tue, 25 Aug 2020 05:48:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 07P5lJqE008048 for ; Tue, 25 Aug 2020 01:47:19 -0400 Received: by smtp.corp.redhat.com (Postfix) id B690A5C22A; Tue, 25 Aug 2020 05:47:19 +0000 (UTC) Received: from carol.localdomain (unknown [10.40.192.44]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 88F265C6D9 for ; Tue, 25 Aug 2020 05:47:16 +0000 (UTC) Received: from carol.redhat.com (carol.k8r.cz [127.0.0.1]) by carol.localdomain (Postfix) with ESMTP id 643B1C2009E for ; Tue, 25 Aug 2020 07:47:15 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1598334529; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=ZT4yys1uXf1ZNpTHGrBV0DO7GCw/C5v0bjhUx6+XZ00=; b=TzWU0fnXozz+Ig4MJcgnNVAwVmGWH00bw0gZKc6AJP1FOM/jd6OkJHZxg9bjg5gz4vcCc6 v/b9xm+ZvHKnwEn0ZZz9cCzkpXotS+eY0BUm69AJoP+8B8ryI3rfikkcjLUvWvbQeTZyxm DJqoTLOShCDexLtqPjcF6Dov3df2TVQ= X-MC-Unique: 5eLDLbVqPoG7w4e615fNoA-1 From: Martin Kletzander To: libvir-list@redhat.com Subject: [libvirt PATCH 4/9] qemu: Rework starting NBD server for migration Date: Tue, 25 Aug 2020 07:47:10 +0200 Message-Id: <871522a71aac8ae52f0e5a9306db99002621a258.1598334400.git.mkletzan@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Clacks-Overhead: GNU Terry Pratchett X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0.001 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Clean up the semantics by using one extra self-describing variable. This also fixes the port allocation when the port is specified. Signed-off-by: Martin Kletzander Reviewed-by: Jiri Denemark --- src/qemu/qemu_migration.c | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 1a3cdb71f424..b887185d012d 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -383,12 +383,13 @@ qemuMigrationDstStartNBDServer(virQEMUDriverPtr drive= r, { int ret =3D -1; qemuDomainObjPrivatePtr priv =3D vm->privateData; - unsigned short port =3D 0; size_t i; virStorageNetHostDef server =3D { .name =3D (char *)listenAddr, /* cast away const */ .transport =3D VIR_STORAGE_NET_HOST_TRANS_TCP, + .port =3D nbdPort, }; + bool server_started =3D false; =20 if (nbdPort < 0 || nbdPort > USHRT_MAX) { virReportError(VIR_ERR_INVALID_ARG, "%s", @@ -424,20 +425,27 @@ qemuMigrationDstStartNBDServer(virQEMUDriverPtr drive= r, devicename =3D diskAlias; } =20 + if (!server_started) { + if (server.port) { + if (virPortAllocatorSetUsed(server.port) < 0) + goto cleanup; + } else { + unsigned short port =3D 0; + + if (virPortAllocatorAcquire(driver->migrationPorts, &port)= < 0) + goto cleanup; + + server.port =3D port; + } + } + if (qemuDomainObjEnterMonitorAsync(driver, vm, QEMU_ASYNC_JOB_MIGRATION_IN) < = 0) goto cleanup; =20 - if (port =3D=3D 0) { - if (nbdPort) - port =3D nbdPort; - else if (virPortAllocatorAcquire(driver->migrationPorts, &port= ) < 0) - goto exit_monitor; - - server.port =3D port; - if (qemuMonitorNBDServerStart(priv->mon, &server, tls_alias) <= 0) - goto exit_monitor; - } + if (!server_started && + qemuMonitorNBDServerStart(priv->mon, &server, tls_alias) < 0) + goto exit_monitor; =20 if (qemuMonitorNBDServerAdd(priv->mon, devicename, exportname, tru= e, NULL) < 0) goto exit_monitor; @@ -445,12 +453,13 @@ qemuMigrationDstStartNBDServer(virQEMUDriverPtr drive= r, goto cleanup; } =20 - priv->nbdPort =3D port; + priv->nbdPort =3D server.port; + ret =3D 0; =20 cleanup: - if (ret < 0 && nbdPort =3D=3D 0) - virPortAllocatorRelease(port); + if (ret < 0) + virPortAllocatorRelease(server.port); return ret; =20 exit_monitor: --=20 2.28.0