From nobody Sun Feb 8 22:48:54 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1559132736; cv=none; d=zoho.com; s=zohoarc; b=NfiHRiP1HQNUqNGPqo+aMx8s1FNSModklMVkeueHlZLpTao6lWcDwJJ2/s4Et3R6ps4gZmoSnQsAQ6ZGj3omzLNT/M8/2DzewsRcJQoABtelbRd4xBL5/Lj6ugnIngoaENkMW9hXhlZhmWfALHLg9HhLTH3ZQj1DXGNToQCuAE0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559132736; 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:ARC-Authentication-Results; bh=Lqd5Sqjd4N2hfFogRg203LF1K6bHLGkY/3JA8O9zPSo=; b=Xxyn2deWO4WNeZCuyT/2k+YuS0DQLbxy+Pfe82TUsbJgJjPwYisOqCcuV1SDbUM+sHcT35/NjYkO9QiG7xAT3hbZbTlolXAiJ7u7KChEHNMCE8tUz4B0HfezuffyiggEW9CdimQche2QWBcf43B4JZSd8SEa9c+tInfDa4falFk= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1559132736544195.23320133908896; Wed, 29 May 2019 05:25:36 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5633E30C3192; Wed, 29 May 2019 12:25:16 +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 22D436B8C0; Wed, 29 May 2019 12:25:14 +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 D56551806B19; Wed, 29 May 2019 12:25:09 +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 x4TCOIdp025693 for ; Wed, 29 May 2019 08:24:18 -0400 Received: by smtp.corp.redhat.com (Postfix) id C9F376B8C4; Wed, 29 May 2019 12:24:18 +0000 (UTC) Received: from mx1.redhat.com (ext-mx16.extmail.prod.ext.phx2.redhat.com [10.5.110.45]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5DBBE60852; Wed, 29 May 2019 12:24:16 +0000 (UTC) Received: from mail-ed1-f68.google.com (mail-ed1-f68.google.com [209.85.208.68]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 87DDC30C1325; Wed, 29 May 2019 12:24:02 +0000 (UTC) Received: by mail-ed1-f68.google.com with SMTP id n17so3542526edb.0; Wed, 29 May 2019 05:24:02 -0700 (PDT) Received: from archpc.localdomain (x8d1ee222.agdsn.tu-dresden.de. [141.30.226.34]) by smtp.gmail.com with ESMTPSA id p37sm5214857edc.14.2019.05.29.05.23.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 May 2019 05:23:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=rrlp31/rseDh7nL5ed++wNX8uf14ffh8DDjN7ejo9LQ=; b=KZIHkloQB5phfIzEYiHXhema6tPrjoK96yKre1veKsBJoaU2v683twilsSICCpmLFQ 2gzCGs/QSoCjNOwRpePHaeO/2FmbDIicVT4UjcWsKSrhoCMhKg8ttblR+PS5pzc9/PfD Joq5WTAvfFdK980ZyT68dDf6r8hlzxxE73hpK3ELf1hXd7EVSSaWlwqWXMBE4547zX3T 1Usf6bOuAQ05mua0KuHPnJlCK4xC1ZdgI0h5JYlBK/IbLdf19FWAHF2fIgTiqQGnFKIB bhOI9ef7kQ/mR7d6ZV7grTfaNqwHvPV2EPFt+CZEcApfHRHsG8i+CkVtNaD2ZBh/94Hq Be8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rrlp31/rseDh7nL5ed++wNX8uf14ffh8DDjN7ejo9LQ=; b=i2N5rRuwqe+BVtBAwrX3OINj3e+OTUMW8CPN+Awvypah0+2yOPTPQE4wc/LdInG10p FXYyeUQyOhk6DJswC4nH02OWnW0LUI4NjsqNonTeM5FoQKjZm6IoCVOBmBBa8FtPsRsn QtUrQMt03Es1wOW8WscvOb5fxGdeE9vS9ccbhlSnSj1ldXlfjz4lH9OyACRx8ZFYko8u klYHacRe0Yf90sihcep/p4ihlfTdir4qUTZsEtRm2rQ9kZSeOn7tnNu8L3r/Lry/KQJi /HvmDrF3Hh+Q1lo6MWfU+nE+X7w431lTm8C6C7uuWkoTmdkqcHA7E+7ZDgXpcldZgX41 rKAQ== X-Gm-Message-State: APjAAAU1ekXUgVfus37123Zhm6R9xkaxlaNRBJUgRrxFpqCn4xGt793v qkutvJ5fh3AI3VnILWQnQM3xk53o X-Google-Smtp-Source: APXvYqwbqY5iBJRjZCUJb+vmqOZE/9BjIepLKfjtZuyOpAmrvvNkq9ySqmL0UHCrFKZzjC3tq/1Hog== X-Received: by 2002:a50:aed8:: with SMTP id f24mr134801610edd.214.1559132640765; Wed, 29 May 2019 05:24:00 -0700 (PDT) From: Ilias Stamatis To: libvir-list@redhat.com Date: Wed, 29 May 2019 14:22:56 +0200 Message-Id: <20190529122259.14979-2-stamatis.iliass@gmail.com> In-Reply-To: <20190529122259.14979-1-stamatis.iliass@gmail.com> References: <20190529122259.14979-1-stamatis.iliass@gmail.com> MIME-Version: 1.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Wed, 29 May 2019 12:24:02 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Wed, 29 May 2019 12:24:02 +0000 (UTC) for IP:'209.85.208.68' DOMAIN:'mail-ed1-f68.google.com' HELO:'mail-ed1-f68.google.com' FROM:'stamatis.iliass@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.108 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE) 209.85.208.68 mail-ed1-f68.google.com 209.85.208.68 mail-ed1-f68.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.45 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/4] test_driver: extract image saving code into a separate function 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Wed, 29 May 2019 12:25:25 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Extracting the code logic for writing a test image to disk from testDomainSaveFlags into a separate function, allows us to reuse this code in other functions such as testDomainSaveImageDefineXML. Signed-off-by: Ilias Stamatis Reviewed-by: Erik Skultety --- src/test/test_driver.c | 114 +++++++++++++++++++++++++---------------- 1 file changed, 69 insertions(+), 45 deletions(-) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 2f58a1da95..e71b931790 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -1974,75 +1974,106 @@ testDomainGetTime(virDomainPtr dom ATTRIBUTE_UNUSE= D, #define TEST_SAVE_MAGIC "TestGuestMagic" -static int -testDomainSaveFlags(virDomainPtr domain, const char *path, - const char *dxml, unsigned int flags) + +/** + * testDomainSaveImageWrite: + * @driver: test driver data + * @def: domain definition whose XML will be stored in the image + * @path: path of the save image + * + * Returns true on success, else false. + */ +static bool +testDomainSaveImageWrite(testDriverPtr driver, + virDomainDefPtr def, + const char *path) { - testDriverPtr privconn =3D domain->conn->privateData; - int fd =3D -1; int len; - virDomainObjPtr privdom; - virObjectEventPtr event =3D NULL; - int ret =3D -1; + int fd =3D -1; VIR_AUTOFREE(char *) xml =3D NULL; - virCheckFlags(0, -1); - if (dxml) { - virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s", - _("xml modification unsupported")); - return -1; - } - - - if (!(privdom =3D testDomObjFromDomain(domain))) - goto cleanup; - - if (virDomainObjCheckActive(privdom) < 0) - goto cleanup; - - xml =3D virDomainDefFormat(privdom->def, privconn->caps, - VIR_DOMAIN_DEF_FORMAT_SECURE); + xml =3D virDomainDefFormat(def, driver->caps, VIR_DOMAIN_DEF_FORMAT_SE= CURE); if (xml =3D=3D NULL) { virReportSystemError(errno, _("saving domain '%s' failed to allocate spac= e for metadata"), - domain->name); - goto cleanup; + def->name); + goto error; } if ((fd =3D open(path, O_CREAT|O_TRUNC|O_WRONLY, S_IRUSR|S_IWUSR)) < 0= ) { virReportSystemError(errno, _("saving domain '%s' to '%s': open failed"), - domain->name, path); - goto cleanup; + def->name, path); + goto error; } - len =3D strlen(xml); + if (safewrite(fd, TEST_SAVE_MAGIC, sizeof(TEST_SAVE_MAGIC)) < 0) { virReportSystemError(errno, _("saving domain '%s' to '%s': write failed"), - domain->name, path); - goto cleanup; + def->name, path); + goto error; } + + len =3D strlen(xml); if (safewrite(fd, (char*)&len, sizeof(len)) < 0) { virReportSystemError(errno, _("saving domain '%s' to '%s': write failed"), - domain->name, path); - goto cleanup; + def->name, path); + goto error; } + if (safewrite(fd, xml, len) < 0) { virReportSystemError(errno, _("saving domain '%s' to '%s': write failed"), - domain->name, path); - goto cleanup; + def->name, path); + goto error; } if (VIR_CLOSE(fd) < 0) { virReportSystemError(errno, _("saving domain '%s' to '%s': write failed"), - domain->name, path); - goto cleanup; + def->name, path); + goto error; } - fd =3D -1; + + return true; + + error: + /* Don't report failure in close or unlink, because + * in either case we're already in a failure scenario + * and have reported an earlier error */ + VIR_FORCE_CLOSE(fd); + unlink(path); + + return false; +} + +static int +testDomainSaveFlags(virDomainPtr domain, const char *path, + const char *dxml, unsigned int flags) +{ + testDriverPtr privconn =3D domain->conn->privateData; + virDomainObjPtr privdom; + virObjectEventPtr event =3D NULL; + int ret =3D -1; + + virCheckFlags(0, -1); + + if (dxml) { + virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s", + _("xml modification unsupported")); + return -1; + } + + if (!(privdom =3D testDomObjFromDomain(domain))) + goto cleanup; + + if (virDomainObjCheckActive(privdom) < 0) + goto cleanup; + + if (!testDomainSaveImageWrite(privconn, privdom->def, path)) + goto cleanup; testDomainShutdownState(domain, privdom, VIR_DOMAIN_SHUTOFF_SAVED); event =3D virDomainEventLifecycleNewFromObj(privdom, @@ -2054,13 +2085,6 @@ testDomainSaveFlags(virDomainPtr domain, const char = *path, ret =3D 0; cleanup: - /* Don't report failure in close or unlink, because - * in either case we're already in a failure scenario - * and have reported an earlier error */ - if (ret !=3D 0) { - VIR_FORCE_CLOSE(fd); - unlink(path); - } virDomainObjEndAPI(&privdom); virObjectEventStateQueue(privconn->eventState, event); return ret; -- 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list