From nobody Wed Apr 24 22:47:05 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 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=1652368669; cv=none; d=zohomail.com; s=zohoarc; b=TZFkPXSXbgYmuAC7cmgxaiI+EXsNmX3up1X7YMxGxv3Ds/bLKUhcaUVyU/87aF5+EUZf+azkHsmqnqjdjyhG5fc9tJ281dVtWGeb5hgTm4ZGCdjdbWNNNskQm+V825O2x2Wg2dOWLlbmIOVtAENK9qSwrIHvZxQk0n3fYwzBl8c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1652368669; 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=ZMihiPW1+RuCn7QotZeSHpBI76YOKwg1eLcX+ixbt1I=; b=T3k27NbigX92flplSoBAcjN2iblxN/u/bLkCOjZhSGR3YunFmx1uXKSgFsg7Hd6ROuwKS6EmMC5Lyn3CB3cdNld05P6YacFA7uM6vA2+uaznuI4YvUBDFvNX+zUxo8nHWwZw/zP4C41tEDxxZSYTiInNFDg8LS4w/ynrTzaQXZ0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1652368669073243.63817769814307; Thu, 12 May 2022 08:17:49 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-330-erAR_I9TOBqA4ohc5ZItgQ-1; Thu, 12 May 2022 11:17:46 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8D5CB811E90; Thu, 12 May 2022 15:17:43 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7A0FF4010A19; Thu, 12 May 2022 15:17:43 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 53647193220C; Thu, 12 May 2022 15:17:43 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id AED381947058 for ; Thu, 12 May 2022 15:17:41 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id A357741476E; Thu, 12 May 2022 15:17:41 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.180]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4AC6340D1C3 for ; Thu, 12 May 2022 15:17:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1652368668; 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=ZMihiPW1+RuCn7QotZeSHpBI76YOKwg1eLcX+ixbt1I=; b=ULstGQtO32RiPT/uJ6CQJ3xYNTQ6bKtNyTWvhviM5jHwOZbil7QAb7yr8IcIyn8D2DmJeo siN+HvjT/gBzEnlrCc/1RURK4Porh0rUk3TFYFGyamrZzK6OHzGWjleOwdNLj59c2/z47N 0b7O3RElSJ6Q5+Srpyj3sXEIitNL5FM= X-MC-Unique: erAR_I9TOBqA4ohc5ZItgQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 1/3] qemu: Separate out save code from qemuDomainManagedSave() Date: Thu, 12 May 2022 17:17:35 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 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 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1652368670613100002 Content-Type: text/plain; charset="utf-8"; x-default="true" The code that actually does managed save within qemuDomainManagedSave() is going to be reused shortly. Move it out into a separate helper. Signed-off-by: Michal Privoznik --- src/qemu/qemu_driver.c | 82 ++++++++++++++++++++++++------------------ 1 file changed, 48 insertions(+), 34 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 4b690a520b..7d8c7176d9 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -2760,6 +2760,53 @@ qemuDomainSaveInternal(virQEMUDriver *driver, } =20 =20 +static char * +qemuDomainManagedSavePath(virQEMUDriver *driver, virDomainObj *vm) +{ + g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(driver); + + return g_strdup_printf("%s/%s.save", cfg->saveDir, vm->def->name); +} + + +static int +qemuDomainManagedSaveHelper(virQEMUDriver *driver, + virDomainObj *vm, + unsigned int flags) +{ + g_autoptr(virQEMUDriverConfig) cfg =3D NULL; + g_autoptr(virCommand) compressor =3D NULL; + g_autofree char *path =3D NULL; + int compressed; + + if (virDomainObjCheckActive(vm) < 0) + return -1; + + if (!vm->persistent) { + virReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("cannot do managed save for transient domain")); + return -1; + } + + cfg =3D virQEMUDriverGetConfig(driver); + if ((compressed =3D qemuSaveImageGetCompressionProgram(cfg->saveImageF= ormat, + &compressor, + "save", false)) <= 0) + return -1; + + path =3D qemuDomainManagedSavePath(driver, vm); + + VIR_INFO("Saving state of domain '%s' to '%s'", vm->def->name, path); + + if (qemuDomainSaveInternal(driver, vm, path, compressed, + compressor, NULL, flags) < 0) + return -1; + + vm->hasManagedSave =3D true; + return 0; +} + + static int qemuDomainSaveFlags(virDomainPtr dom, const char *path, const char *dxml, unsigned int flags) @@ -2860,23 +2907,12 @@ qemuDomainSaveParams(virDomainPtr dom, return ret; } =20 -static char * -qemuDomainManagedSavePath(virQEMUDriver *driver, virDomainObj *vm) -{ - g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(driver); - - return g_strdup_printf("%s/%s.save", cfg->saveDir, vm->def->name); -} =20 static int qemuDomainManagedSave(virDomainPtr dom, unsigned int flags) { virQEMUDriver *driver =3D dom->conn->privateData; - g_autoptr(virQEMUDriverConfig) cfg =3D NULL; - int compressed; - g_autoptr(virCommand) compressor =3D NULL; virDomainObj *vm; - g_autofree char *name =3D NULL; int ret =3D -1; =20 virCheckFlags(VIR_DOMAIN_SAVE_BYPASS_CACHE | @@ -2889,29 +2925,7 @@ qemuDomainManagedSave(virDomainPtr dom, unsigned int= flags) if (virDomainManagedSaveEnsureACL(dom->conn, vm->def) < 0) goto cleanup; =20 - if (virDomainObjCheckActive(vm) < 0) - goto cleanup; - - if (!vm->persistent) { - virReportError(VIR_ERR_OPERATION_INVALID, "%s", - _("cannot do managed save for transient domain")); - goto cleanup; - } - - cfg =3D virQEMUDriverGetConfig(driver); - if ((compressed =3D qemuSaveImageGetCompressionProgram(cfg->saveImageF= ormat, - &compressor, - "save", false)) <= 0) - goto cleanup; - - name =3D qemuDomainManagedSavePath(driver, vm); - - VIR_INFO("Saving state of domain '%s' to '%s'", vm->def->name, name); - - ret =3D qemuDomainSaveInternal(driver, vm, name, compressed, - compressor, NULL, flags); - if (ret =3D=3D 0) - vm->hasManagedSave =3D true; + ret =3D qemuDomainManagedSaveHelper(driver, vm, flags); =20 cleanup: virDomainObjEndAPI(&vm); --=20 2.35.1 From nobody Wed Apr 24 22:47:05 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 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=1652368682; cv=none; d=zohomail.com; s=zohoarc; b=j80MM0O2OGwmcA01ROa8s1rlM00YiDIpiYw/Gv+T4p0ntR1vDwjcHvhQLUoDmrX5W3orYchm0m5LFZimo3T0ymQmBNDrZe+6UmRP3HA9zbhY+qElmOiE4ZqZUEstqP5n34EQBxJkAVTQH1Aoq/qHhWBg/GyVDRLlIPTO6prYzWE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1652368682; 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=ZG8j3vlMKHXoSSw9uGcjS+ojqmTh9WiJXxKz1pjQPi0=; b=Z2vF6145V6kS0Zg/dfgrlruiDt9HEAINrPPr0YJdU6LkDZlkdqpIKibd3c1ozuURPvfO+8yB2Kn5YhXj0MPIpA9I8AEJwf0Hj8FGgBO1iX2oEGWYXRfxLEuXcZ78fsgECOGKpg6F65u/QeHQtV0zP7rU/bu5ixXiWAEUPJMuGJo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 165236868266651.524653139259385; Thu, 12 May 2022 08:18:02 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-625-0VbxY7bfODGRoC_e1EDrdg-1; Thu, 12 May 2022 11:17:52 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D83B318A6658; Thu, 12 May 2022 15:17:44 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id B24B17C4E; Thu, 12 May 2022 15:17:44 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id E0CD11932226; Thu, 12 May 2022 15:17:43 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 7041E1947058 for ; Thu, 12 May 2022 15:17:42 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 41F64414768; Thu, 12 May 2022 15:17:42 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.180]) by smtp.corp.redhat.com (Postfix) with ESMTP id DD36240D1C3 for ; Thu, 12 May 2022 15:17:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1652368681; 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=ZG8j3vlMKHXoSSw9uGcjS+ojqmTh9WiJXxKz1pjQPi0=; b=QMjdjWNu0B45goXeEkKkchMiZxQLAW6iq0nAk6gU/zCKLue3p9UgKeV+XCaueMCfO6jsI7 lgFtWHvFRaXB+YsIB4gGO8wVDFK9Z4OZJCutdIx9+dBlExtr1KE9AD0r0oFoXQki/RKW2g BlWKsN91ccumWtLt10mSwClH8BqUHgU= X-MC-Unique: 0VbxY7bfODGRoC_e1EDrdg-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 2/3] lib: Repurpose virDomainSaveParams() with no VIR_DOMAIN_SAVE_PARAM_FILE Date: Thu, 12 May 2022 17:17:36 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 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 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1652368684727100001 Content-Type: text/plain; charset="utf-8"; x-default="true" When no VIR_DOMAIN_SAVE_PARAM_FILE typed param is set when calling virDomainSaveParams() then in turn virQEMUFileOpenAs() tries to open a NULL path. We have two options now: 1) require the typed param, which in turn may be promoted to a regular argument, or 2) use this opportunity to make the API behave like virDomainManagedSave() and use typed params to pass extra arguments, instead of having to invent new managed save API with typed params. Let's go with option 2, as it is more future proof. Signed-off-by: Michal Privoznik --- src/libvirt-domain.c | 2 ++ src/qemu/qemu_driver.c | 33 ++++++++++++++++++++------------- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c index d1d62daa71..208c2438fe 100644 --- a/src/libvirt-domain.c +++ b/src/libvirt-domain.c @@ -1007,6 +1007,8 @@ virDomainSaveFlags(virDomainPtr domain, const char *t= o, * @flags: bitwise-OR of virDomainSaveRestoreFlags * * This method extends virDomainSaveFlags by adding parameters. + * If VIR_DOMAIN_SAVE_PARAM_FILE is not provided then a managed save is + * performed (see virDomainManagedSave). * * Returns 0 in case of success and -1 in case of failure. * diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 7d8c7176d9..0b31c73bb9 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -2772,6 +2772,7 @@ qemuDomainManagedSavePath(virQEMUDriver *driver, virD= omainObj *vm) static int qemuDomainManagedSaveHelper(virQEMUDriver *driver, virDomainObj *vm, + const char *dxml, unsigned int flags) { g_autoptr(virQEMUDriverConfig) cfg =3D NULL; @@ -2799,7 +2800,7 @@ qemuDomainManagedSaveHelper(virQEMUDriver *driver, VIR_INFO("Saving state of domain '%s' to '%s'", vm->def->name, path); =20 if (qemuDomainSaveInternal(driver, vm, path, compressed, - compressor, NULL, flags) < 0) + compressor, dxml, flags) < 0) return -1; =20 vm->hasManagedSave =3D true; @@ -2853,17 +2854,18 @@ qemuDomainSave(virDomainPtr dom, const char *path) =20 static int qemuDomainSaveParams(virDomainPtr dom, - virTypedParameterPtr params, int nparams, + virTypedParameterPtr params, + int nparams, unsigned int flags) { + virQEMUDriver *driver =3D dom->conn->privateData; + g_autoptr(virQEMUDriverConfig) cfg =3D NULL; + virDomainObj *vm =3D NULL; + g_autoptr(virCommand) compressor =3D NULL; const char *to =3D NULL; const char *dxml =3D NULL; - virQEMUDriver *driver =3D dom->conn->privateData; int compressed; - g_autoptr(virCommand) compressor =3D NULL; int ret =3D -1; - virDomainObj *vm =3D NULL; - g_autoptr(virQEMUDriverConfig) cfg =3D NULL; =20 virCheckFlags(VIR_DOMAIN_SAVE_BYPASS_CACHE | VIR_DOMAIN_SAVE_RUNNING | @@ -2884,18 +2886,23 @@ qemuDomainSaveParams(virDomainPtr dom, VIR_DOMAIN_SAVE_PARAM_DXML, &dxml) < 0) return -1; =20 - cfg =3D virQEMUDriverGetConfig(driver); - if ((compressed =3D qemuSaveImageGetCompressionProgram(cfg->saveImageF= ormat, - &compressor, - "save", false)) <= 0) - goto cleanup; - if (!(vm =3D qemuDomainObjFromDomain(dom))) goto cleanup; =20 if (virDomainSaveParamsEnsureACL(dom->conn, vm->def) < 0) goto cleanup; =20 + if (!to) { + /* If no save path was provided then this behaves as managed save.= */ + return qemuDomainManagedSaveHelper(driver, vm, dxml, flags); + } + + cfg =3D virQEMUDriverGetConfig(driver); + if ((compressed =3D qemuSaveImageGetCompressionProgram(cfg->saveImageF= ormat, + &compressor, + "save", false)) <= 0) + goto cleanup; + if (virDomainObjCheckActive(vm) < 0) goto cleanup; =20 @@ -2925,7 +2932,7 @@ qemuDomainManagedSave(virDomainPtr dom, unsigned int = flags) if (virDomainManagedSaveEnsureACL(dom->conn, vm->def) < 0) goto cleanup; =20 - ret =3D qemuDomainManagedSaveHelper(driver, vm, flags); + ret =3D qemuDomainManagedSaveHelper(driver, vm, NULL, flags); =20 cleanup: virDomainObjEndAPI(&vm); --=20 2.35.1 From nobody Wed Apr 24 22:47:05 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 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=1652368674; cv=none; d=zohomail.com; s=zohoarc; b=YhONfOE2UbIIv5yEJQi06b0U/RN7qw3iWEWo7fNsbIvK1YFvPnJY5ta1qkyrn3qTOaqhMA1Tt4pS0jBtm5ViKufXdCUY4N7Oq9CpiPZZEgtAqLm7j+JAn9Df2qbvowBkBi0UC+/XUDOJnj+a7uIVxzh4x474TPqDP1veplMsEpM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1652368674; 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=Fmr2hOT/6b1dK7iWx2tRujyk+jYvpRkFDVjftC/dfBM=; b=j69GMmiE9sc/sYH1it1K79Mm56vDjQB54uyaUtevTjDQmjrdCHfmLRqQC/MJN+uwPkuQpfv75+rjw+RQe0lZn8JU1hLg0tQm2k+8gOZH8vO2bK3sbAnsDTxr/cpUne3ZILxSiJGXtclVOGnE3uqK0hJ6mShOL+R7uYYiJNzwks0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1652368674094886.5590850517667; Thu, 12 May 2022 08:17:54 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-428-VPItyohBPRuC3FD4aftWNg-1; Thu, 12 May 2022 11:17:47 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8FD219425E6; Thu, 12 May 2022 15:17:44 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7968340C1257; Thu, 12 May 2022 15:17:44 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 9A7E7193222C; Thu, 12 May 2022 15:17:43 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id EF5D91947058 for ; Thu, 12 May 2022 15:17:42 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id D2C9041476D; Thu, 12 May 2022 15:17:42 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.180]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7B272414770 for ; Thu, 12 May 2022 15:17:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1652368673; 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=Fmr2hOT/6b1dK7iWx2tRujyk+jYvpRkFDVjftC/dfBM=; b=e78F6Z67STMCQ4w/A+ekLzMhGiShMWZj8o+/7BPO91r0pVssaRa2dzE5YIAyKJ/gcMZ34h ARGA6LJFNCBx2dMMTQuoZ9fNIC57DHHX8DlMk7Bv0Yo2ygk6M70nC3QV0V7dhHZkFIqd09 EEBlMMjOE1JQTENWpCGr/lTeaparAvQ= X-MC-Unique: VPItyohBPRuC3FD4aftWNg-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 3/3] lib: Require path in virDomainRestoreParams() Date: Thu, 12 May 2022 17:17:37 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 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 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1652368674707100001 Content-Type: text/plain; charset="utf-8"; x-default="true" After seeing previous commit one might think that virDomainRestoreParams() would get the similar treatment. Well, it can't. The problem here is: without any indication what domain to restore we don't really know what domain to restore (shocking, right?). Therefore, we have to require path to restore domain from, at which point, we can save callers couple of lines and let them pass the path as a regular argument instead of requiring it in typed params. Signed-off-by: Michal Privoznik --- include/libvirt/libvirt-domain.h | 1 + src/driver-hypervisor.h | 1 + src/libvirt-domain.c | 25 +++++++++++++++++++++---- src/qemu/qemu_driver.c | 9 +++------ src/remote/remote_protocol.x | 1 + src/remote_protocol-structs | 1 + src/rpc/gendispatch.pl | 2 +- 7 files changed, 29 insertions(+), 11 deletions(-) diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-dom= ain.h index 24846046aa..08082627e5 100644 --- a/include/libvirt/libvirt-domain.h +++ b/include/libvirt/libvirt-domain.h @@ -1574,6 +1574,7 @@ int virDomainRestoreFlags (virC= onnectPtr conn, const char *dxml, unsigned int flags); int virDomainRestoreParams (virConnectPtr conn, + const char *path, virTypedParameterPtr para= ms, int nparams, unsigned int flags); diff --git a/src/driver-hypervisor.h b/src/driver-hypervisor.h index 69516e8fea..81c20a749e 100644 --- a/src/driver-hypervisor.h +++ b/src/driver-hypervisor.h @@ -258,6 +258,7 @@ typedef int =20 typedef int (*virDrvDomainRestoreParams)(virConnectPtr conn, + const char *path, virTypedParameterPtr params, int nparams, unsigned int flags); diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c index 208c2438fe..481886eb02 100644 --- a/src/libvirt-domain.c +++ b/src/libvirt-domain.c @@ -1186,11 +1186,14 @@ virDomainRestoreFlags(virConnectPtr conn, const cha= r *from, const char *dxml, /** * virDomainRestoreParams: * @conn: pointer to the hypervisor connection + * @path: path to the input file * @params: restore parameters * @nparams: number of restore parameters * @flags: bitwise-OR of virDomainSaveRestoreFlags * * This method extends virDomainRestoreFlags by adding parameters. + * Please note that VIR_DOMAIN_SAVE_PARAM_FILE is not supported for this A= PI as + * @path serves the same purpose. * * Returns 0 in case of success and -1 in case of failure. * @@ -1198,25 +1201,39 @@ virDomainRestoreFlags(virConnectPtr conn, const cha= r *from, const char *dxml, */ int virDomainRestoreParams(virConnectPtr conn, - virTypedParameterPtr params, int nparams, + const char *path, + virTypedParameterPtr params, + int nparams, unsigned int flags) { - VIR_DEBUG("conn=3D%p, params=3D%p, nparams=3D%d, flags=3D0x%x", - conn, params, nparams, flags); + VIR_DEBUG("conn=3D%p, path=3D%s, params=3D%p, nparams=3D%d, flags=3D0x= %x", + conn, path, params, nparams, flags); VIR_TYPED_PARAMS_DEBUG(params, nparams); =20 virResetLastError(); =20 virCheckConnectReturn(conn, -1); virCheckReadOnlyGoto(conn->flags, error); + virCheckNonNullArgGoto(path, error); =20 VIR_EXCLUSIVE_FLAGS_GOTO(VIR_DOMAIN_SAVE_RUNNING, VIR_DOMAIN_SAVE_PAUSED, error); =20 if (conn->driver->domainRestoreParams) { - if (conn->driver->domainRestoreParams(conn, params, nparams, flags= ) < 0) + g_autofree char *absolute_path =3D NULL; + + /* We must absolutize the file path as the restore is done out of = process */ + if (!(absolute_path =3D g_canonicalize_filename(path, NULL))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("could not build absolute input file path")); goto error; + } + + if (conn->driver->domainRestoreParams(conn, absolute_path, + params, nparams, flags) < 0) + goto error; + return 0; } =20 diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 0b31c73bb9..debf96db19 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -5947,22 +5947,19 @@ qemuDomainRestore(virConnectPtr conn, =20 static int qemuDomainRestoreParams(virConnectPtr conn, - virTypedParameterPtr params, int nparams, + const char *path, + virTypedParameterPtr params, + int nparams, unsigned int flags) { - const char *path =3D NULL; const char *dxml =3D NULL; int ret =3D -1; =20 if (virTypedParamsValidate(params, nparams, - VIR_DOMAIN_SAVE_PARAM_FILE, VIR_TYPED_PARAM= _STRING, VIR_DOMAIN_SAVE_PARAM_DXML, VIR_TYPED_PARAM= _STRING, NULL) < 0) return -1; =20 - if (virTypedParamsGetString(params, nparams, - VIR_DOMAIN_SAVE_PARAM_FILE, &path) < 0) - return -1; if (virTypedParamsGetString(params, nparams, VIR_DOMAIN_SAVE_PARAM_DXML, &dxml) < 0) return -1; diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x index 085631c11b..2c7327c1e4 100644 --- a/src/remote/remote_protocol.x +++ b/src/remote/remote_protocol.x @@ -1000,6 +1000,7 @@ struct remote_domain_restore_flags_args { }; =20 struct remote_domain_restore_params_args { + remote_nonnull_string path; remote_typed_param params; unsigned int flags; }; diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs index 4ffdce5679..75e86d48f4 100644 --- a/src/remote_protocol-structs +++ b/src/remote_protocol-structs @@ -580,6 +580,7 @@ struct remote_domain_restore_flags_args { u_int flags; }; struct remote_domain_restore_params_args { + remote_nonnull_string path; struct { u_int params_len; remote_typed_param * params_val; diff --git a/src/rpc/gendispatch.pl b/src/rpc/gendispatch.pl index a64ff3e73f..6acefa6b98 100755 --- a/src/rpc/gendispatch.pl +++ b/src/rpc/gendispatch.pl @@ -640,7 +640,7 @@ elsif ($mode eq "server") { =20 # NB: if your new API starts with remote_typed_params,= enter it here if you need # the conn arg to be passed first! - if ($call->{ProcName} eq "NodeSetMemoryParameters" || = $call->{ProcName} eq "DomainRestoreParams") { + if ($call->{ProcName} eq "NodeSetMemoryParameters") { push(@args_list, $conn_var); } push(@args_list, "$1"); --=20 2.35.1