From nobody Sun Oct 5 01:49:59 2025 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=1757512831; cv=none; d=zohomail.com; s=zohoarc; b=Wo0cf/RGO/QTK22BTWLYZ1rQ4DdMQMDZJfGv/Em7YnKh24xvRxSdROFb5Lvup4y79g2YVTLhG05Xpfaw9frs9HYa+cOuhr3Wens6bP1BMEmhxptj+7c9ZDq86oCKidxU2LqGNUHnr9zhzz5MZjmWWDzqlZFAmHJF0pl2hn2TQeI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757512831; h=Content-Type:Content-Transfer-Encoding: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:Cc; bh=dhKC7sAh8rsvu9H3wWQ1xmh9eb3/5IBrqJFC8KjeY3w=; b=cfN8gP3kfwSbIiP1/ps7MsqU5RHWoth+Igdq/aEKi46Qchy+GOSpRj6tB5TadzA2uQ0Zt3avraL2v3DnPwaaTQxJzAazQ62CfmYM9tns4xMolEdiH7ex7Vir0cEiSAnvRsx2oTQ2/W62Auj3auTFrVUu2v4ntVnMh6aBk633RcI= 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 1757512831352856.8942373742649; Wed, 10 Sep 2025 07:00:31 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 4959343DEA; Wed, 10 Sep 2025 10:00:30 -0400 (EDT) Received: from [172.19.199.3] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 749C841CA1; Wed, 10 Sep 2025 09:58:04 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 993) id C44E141B96; Wed, 10 Sep 2025 09:57:49 -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 0356441B9A for ; Wed, 10 Sep 2025 09:57:48 -0400 (EDT) Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-558-NZmeQzXhPteJ03pjaTTanQ-1; Wed, 10 Sep 2025 09:57:47 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 865D3180034D for ; Wed, 10 Sep 2025 13:57:46 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.45.242.8]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id CBEEB300018D for ; Wed, 10 Sep 2025 13:57:45 +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=-1.5 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW, 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=1757512668; h=from:from: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; bh=dhKC7sAh8rsvu9H3wWQ1xmh9eb3/5IBrqJFC8KjeY3w=; b=WjY2vCQS69/gVgeyV/sRTaxk6iM1nA3G0LDesZNaCFbMJ0FFhEygpFYDeK0EnkBo+qtF0I pxMHPv5VNuIK46zDayWKD9Uy8XW2hID98a44hqsz8815yQLQaly4QW5s1WQOdmtWQr1lpe JkGjsTglF4jSLJO3TS3i2Dt5cRplsHI= X-MC-Unique: NZmeQzXhPteJ03pjaTTanQ-1 X-Mimecast-MFC-AGG-ID: NZmeQzXhPteJ03pjaTTanQ_1757512666 To: devel@lists.libvirt.org Subject: [PATCH 2/6] qemuMigrationSrcIsSafe: Extract code for checking safe migrability of one disk Date: Wed, 10 Sep 2025 15:57:37 +0200 Message-ID: <367f2a92f8121dea6a94ada66be147d829c3f823.1757512552.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 6AymPFa4o9RhXnSeyjcopzRo03dWrbu1Tgeh7k5-W9I_1757512666 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: LLKS4NSR2WFODZDQNJWSX37RW7CWLTEZ X-Message-ID-Hash: LLKS4NSR2WFODZDQNJWSX37RW7CWLTEZ 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 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: 1757512833328116600 Content-Type: text/plain; charset="utf-8" From: Peter Krempa Extract the code which checks a source of a single disk for safe migratability into 'qemuMigrationSrcIsSafeDisk'. Signed-off-by: Peter Krempa --- src/qemu/qemu_migration.c | 132 ++++++++++++++++++++------------------ 1 file changed, 71 insertions(+), 61 deletions(-) diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index dd171f953c..96709dfcdd 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -1732,6 +1732,74 @@ qemuMigrationSrcIsAllowed(virDomainObj *vm, return true; } + +static bool +qemuMigrationSrcIsSafeDisk(virDomainDiskDef *disk, + virQEMUCaps *qemuCaps, + virQEMUDriverConfig *cfg) +{ + virStorageType actualType =3D virStorageSourceGetActualType(disk->src); + bool unsafe =3D false; + int rc; + + /* Disks without any source (i.e. floppies and CD-ROMs) OR readonly ar= e safe. */ + if (virStorageSourceIsEmpty(disk->src) || + disk->src->readonly) + return true; + + /* However, disks on local FS (e.g. ext4) are not safe. */ + switch (actualType) { + case VIR_STORAGE_TYPE_FILE: + if ((rc =3D virFileIsSharedFS(disk->src->path, cfg->sharedFilesyst= ems)) < 0) { + return false; + } else if (rc =3D=3D 0) { + unsafe =3D true; + } + + if ((rc =3D virFileIsClusterFS(disk->src->path)) < 0) + return false; + else if (rc =3D=3D 1) + return true; + break; + + case VIR_STORAGE_TYPE_NETWORK: + return true; + + case VIR_STORAGE_TYPE_NVME: + unsafe =3D true; + break; + + case VIR_STORAGE_TYPE_VHOST_USER: + case VIR_STORAGE_TYPE_VHOST_VDPA: + case VIR_STORAGE_TYPE_NONE: + case VIR_STORAGE_TYPE_BLOCK: + case VIR_STORAGE_TYPE_DIR: + case VIR_STORAGE_TYPE_VOLUME: + case VIR_STORAGE_TYPE_LAST: + break; + } + + if (unsafe) { + virReportError(VIR_ERR_MIGRATE_UNSAFE, "%s", + _("Migration without shared storage is unsafe")); + return false; + } + + /* Our code elsewhere guarantees shared disks are either readonly (in + * which case cache mode doesn't matter) or used with cache=3Dnone or = used with cache=3Ddirectsync */ + if (!(disk->src->shared || + disk->cachemode =3D=3D VIR_DOMAIN_DISK_CACHE_DISABLE || + disk->cachemode =3D=3D VIR_DOMAIN_DISK_CACHE_DIRECTSYNC || + virQEMUCapsGet(qemuCaps, QEMU_CAPS_MIGRATION_FILE_DROP_CACHE))) { + virReportError(VIR_ERR_MIGRATE_UNSAFE, "%s", + _("Migration may lead to data corruption if disks u= se cache other than none or directsync")); + return false; + } + + return true; +} + + static bool qemuMigrationSrcIsSafe(virDomainObj *vm, const char **migrate_disks, @@ -1739,79 +1807,21 @@ qemuMigrationSrcIsSafe(virDomainObj *vm, { qemuDomainObjPrivate *priv =3D vm->privateData; - virQEMUCaps *qemuCaps =3D priv->qemuCaps; - virQEMUDriver *driver =3D priv->driver; - g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(driver); + g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(priv->dr= iver); bool storagemigration =3D flags & (VIR_MIGRATE_NON_SHARED_DISK | VIR_MIGRATE_NON_SHARED_INC); size_t i; - int rc; for (i =3D 0; i < vm->def->ndisks; i++) { virDomainDiskDef *disk =3D vm->def->disks[i]; - const char *src =3D virDomainDiskGetSource(disk); - virStorageType actualType =3D virStorageSourceGetActualType(disk->= src); - bool unsafe =3D false; - - /* Disks without any source (i.e. floppies and CD-ROMs) - * OR readonly are safe. */ - if (virStorageSourceIsEmpty(disk->src) || - disk->src->readonly) - continue; - /* Disks which are migrated by qemu are safe too. */ + /* Disks which are migrated by qemu are safe */ if (storagemigration && qemuMigrationAnyCopyDisk(disk, migrate_disks)) continue; - /* However, disks on local FS (e.g. ext4) are not safe. */ - switch (actualType) { - case VIR_STORAGE_TYPE_FILE: - if ((rc =3D virFileIsSharedFS(src, cfg->sharedFilesystems)) < = 0) { - return false; - } else if (rc =3D=3D 0) { - unsafe =3D true; - } - if ((rc =3D virFileIsClusterFS(src)) < 0) - return false; - else if (rc =3D=3D 1) - continue; - break; - case VIR_STORAGE_TYPE_NETWORK: - /* But network disks are safe again. */ - continue; - - case VIR_STORAGE_TYPE_NVME: - unsafe =3D true; - break; - - case VIR_STORAGE_TYPE_VHOST_USER: - case VIR_STORAGE_TYPE_VHOST_VDPA: - case VIR_STORAGE_TYPE_NONE: - case VIR_STORAGE_TYPE_BLOCK: - case VIR_STORAGE_TYPE_DIR: - case VIR_STORAGE_TYPE_VOLUME: - case VIR_STORAGE_TYPE_LAST: - break; - } - - if (unsafe) { - virReportError(VIR_ERR_MIGRATE_UNSAFE, "%s", - _("Migration without shared storage is unsafe")= ); + if (!qemuMigrationSrcIsSafeDisk(disk, priv->qemuCaps, cfg)) return false; - } - - /* Our code elsewhere guarantees shared disks are either readonly = (in - * which case cache mode doesn't matter) or used with cache=3Dnone= or used with cache=3Ddirectsync */ - if (disk->src->shared || - disk->cachemode =3D=3D VIR_DOMAIN_DISK_CACHE_DISABLE || - disk->cachemode =3D=3D VIR_DOMAIN_DISK_CACHE_DIRECTSYNC || - virQEMUCapsGet(qemuCaps, QEMU_CAPS_MIGRATION_FILE_DROP_CACHE)) - continue; - - virReportError(VIR_ERR_MIGRATE_UNSAFE, "%s", - _("Migration may lead to data corruption if disks u= se cache other than none or directsync")); - return false; } return true; --=20 2.51.0