From patchwork Mon Oct 12 17:08:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Cole Robinson X-Patchwork-Id: 317695 Delivered-To: patch@linaro.org Received: by 2002:a92:d603:0:0:0:0:0 with SMTP id w3csp4797450ilm; Mon, 12 Oct 2020 10:10:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwBCEqHdi5n43Qm2DfZbxZNujyRzcutH908E08YL+TzP24EYGDgdY4pIehWFqWQhl8b06oG X-Received: by 2002:a17:906:5f96:: with SMTP id a22mr28740746eju.168.1602522607193; Mon, 12 Oct 2020 10:10:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602522607; cv=none; d=google.com; s=arc-20160816; b=gjO+2WWXIcFwnAPRhSPv6l7lu868iWNOP7QRGMhfyTmA0r3q+TTT7hDU7OqTG7bvK5 F8yTVfNdLqV8AkQX6KMEugr6YnMFUbJhXoq3esujMht8dtz9UspOtpd8o5+jW4/pNyeZ nr9Yr3ew0Qrc5+PdOcB5zOCgEcIKvkIf/Xh9FQ2vrGELamXVWdmPpgzr4UXkYHdDTMY3 klu1IIjbI6JKHChltzRytV2xbZA7v7zPjPOGeZv4MkqJ5Jq/XOSe+LqlBPA9PlIDtVQD NEAeMbFu2BDQmJwiMEuyB4N+zKXuJiTKzc/5aMnbYBzS+gq5gxfXfDNdfJZl9H30AwuC imqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:errors-to:sender:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:cc :mime-version:message-id:date:subject:to:from:delivered-to :dkim-signature; bh=dm+ddmH3OyuqoBp2p3EkWLZir1x4gcpyNeToBfmge5U=; b=KtihRfRFP1Mv/vllqeL/JTM3YY8EvQNtPN5ACwGqWJtM4LtQoN6hR7mA+mo/lAFvrq ivEDrrOPTE8ZW41aIX4qkrYrnhgDugwxZafAFMixUeAiclEFPg/7ij6JXE/3+Klyf6X3 cnKmWsc5zMWviMH+4eN+5BAwRRAM8qB79+vwvCooTyMIr9YPtSYPa0nxpqKGsrdLe77E zUKr7RmKHXdy2uPaDbd1gltCIKX4sH4a1i3EEkRWlAkGH1FUpCbW5VxXqrUlqlBg4wZ0 uflAU+GogOfi5ZT/DcpeI5tQGM/jum6g+9grkQ55pQKnriJLGjTQt+cBL7894jHgkS1i oVHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=RG8a86xE; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com. [216.205.24.124]) by mx.google.com with ESMTPS id dp15si5658535ejc.59.2020.10.12.10.10.06 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Oct 2020 10:10:07 -0700 (PDT) Received-SPF: pass (google.com: domain of libvir-list-bounces@redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=RG8a86xE; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602522606; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=dm+ddmH3OyuqoBp2p3EkWLZir1x4gcpyNeToBfmge5U=; b=RG8a86xE3UuARO9hT30TQuqxUkKlec1N6240lzX7oaJaGMLR2TH54iW7o0isF7gTkxUkHB vN7TZfSwO+pxm3DHuY3guGIsxA8qPh+I8ocSq/qPgM5Xj+clHGNB2TNVRdwkkCmlbemjsc MKWwsSJBFtlxmGAurPdYLoPTfvXrdE8= 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-485-oko1HYruM7CQUK3CX9AydA-1; Mon, 12 Oct 2020 13:10:02 -0400 X-MC-Unique: oko1HYruM7CQUK3CX9AydA-1 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 058D710A0821; Mon, 12 Oct 2020 17:09:29 +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 51ED027BB1; Mon, 12 Oct 2020 17:09:28 +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 66C21183D021; Mon, 12 Oct 2020 17:09:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 09CH9QnY027803 for ; Mon, 12 Oct 2020 13:09:26 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7C17C73676; Mon, 12 Oct 2020 17:09:26 +0000 (UTC) Delivered-To: libvirt-list@redhat.com Received: from colepc.home (ovpn-113-130.rdu2.redhat.com [10.10.113.130]) by smtp.corp.redhat.com (Postfix) with ESMTP id AF70173667; Mon, 12 Oct 2020 17:09:18 +0000 (UTC) From: Cole Robinson To: libvirt-list@redhat.com Subject: [PATCH v2] qemu: migration: don't open storage driver too early Date: Mon, 12 Oct 2020 13:08:58 -0400 Message-Id: <626e6103f22c78262f5cf0c1bd421c252a6bffca.1602522367.git.crobinso@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: Michal Privoznik , Cole Robinson 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 X-Mimecast-Originator: redhat.com If storage migration is requested, and the destination storage does not exist on the remote host, qemu's migration support will call into the libvirt storage driver to precreate the destination storage. The storage driver virConnectPtr is opened too early though, adding an unnecessary dependency on the storage driver for several cases that don't require it. This currently requires kubevirt to install the storage driver even though they aren't actually using it. Push the virGetConnectStorage calls to right before the cases they are actually needed. Signed-off-by: Cole Robinson --- v2: Only open the connection once per VM via qemuMigrationDstPrecreateStorage src/qemu/qemu_migration.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) -- 2.28.0 Reviewed-by: Daniel P. Berrangé diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 2000c86640..4e959abebf 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -169,7 +169,7 @@ qemuMigrationSrcRestoreDomainState(virQEMUDriverPtr driver, virDomainObjPtr vm) static int -qemuMigrationDstPrecreateDisk(virConnectPtr conn, +qemuMigrationDstPrecreateDisk(virConnectPtr *conn, virDomainDiskDefPtr disk, unsigned long long capacity) { @@ -204,7 +204,12 @@ qemuMigrationDstPrecreateDisk(virConnectPtr conn, *volName = '\0'; volName++; - if (!(pool = virStoragePoolLookupByTargetPath(conn, basePath))) + if (!*conn) { + if (!(*conn = virGetConnectStorage())) + goto cleanup; + } + + if (!(pool = virStoragePoolLookupByTargetPath(*conn, basePath))) goto cleanup; format = virStorageFileFormatTypeToString(disk->src->format); if (disk->src->format == VIR_STORAGE_FILE_QCOW2) @@ -212,7 +217,12 @@ qemuMigrationDstPrecreateDisk(virConnectPtr conn, break; case VIR_STORAGE_TYPE_VOLUME: - if (!(pool = virStoragePoolLookupByName(conn, disk->src->srcpool->pool))) + if (!*conn) { + if (!(*conn = virGetConnectStorage())) + goto cleanup; + } + + if (!(pool = virStoragePoolLookupByName(*conn, disk->src->srcpool->pool))) goto cleanup; format = virStorageFileFormatTypeToString(disk->src->format); volName = disk->src->srcpool->volume; @@ -304,14 +314,11 @@ qemuMigrationDstPrecreateStorage(virDomainObjPtr vm, { int ret = -1; size_t i = 0; - virConnectPtr conn; + virConnectPtr conn = NULL; if (!nbd || !nbd->ndisks) return 0; - if (!(conn = virGetConnectStorage())) - return -1; - for (i = 0; i < nbd->ndisks; i++) { virDomainDiskDefPtr disk; const char *diskSrcPath; @@ -349,7 +356,8 @@ qemuMigrationDstPrecreateStorage(virDomainObjPtr vm, VIR_DEBUG("Proceeding with disk source %s", NULLSTR(diskSrcPath)); - if (qemuMigrationDstPrecreateDisk(conn, disk, nbd->disks[i].capacity) < 0) + if (qemuMigrationDstPrecreateDisk(&conn, + disk, nbd->disks[i].capacity) < 0) goto cleanup; }