From nobody Mon Feb 9 13:01:03 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=1560157978; cv=none; d=zoho.com; s=zohoarc; b=hLjIgxZDdT0Nrh1DURN+FYLsZag1CRUHnWbdJLrjDBJ3d+V9JtGmlrkHlEoU0oDBkvdhxnnkpJ0pBzwNGZISk0tFCZMWpQETK3bLWtZVAUT6oKorTfms30nV3dWHJH9ROlZ2+PHAJ6mZAYs6YqRXVMr9Ys7L3zrhFMC149L0l8g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560157978; 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=nYdLr8+seyjfmc3QvYnjqelAkeqjosMin5elWg131XQ=; b=aCMNzaL4UgNftA9sh/vs4TKGRWG5gqaDdioUR87DrLZUUVGahFBR/7tTj5wL0lTAoP4sLbj0qBgdaJi9GuKYM56I9vlBBoArKrEyJ8bJUHjvRipMFgOY3p3OwwAcn52rULfZXYs9BuaWTu33xAx049z8wmwAZlWGfmiLBLXIQcY= 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 1560157978889156.44816345896947; Mon, 10 Jun 2019 02:12:58 -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 887A331628EF; Mon, 10 Jun 2019 09:12:49 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5668F6062D; Mon, 10 Jun 2019 09:12:47 +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 0A1F224F19; Mon, 10 Jun 2019 09:12:46 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x5A96BI0003298 for ; Mon, 10 Jun 2019 05:06:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5C5E012C85; Mon, 10 Jun 2019 09:06:11 +0000 (UTC) Received: from mx1.redhat.com (ext-mx08.extmail.prod.ext.phx2.redhat.com [10.5.110.32]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 55C115DDA3 for ; Mon, 10 Jun 2019 09:06:08 +0000 (UTC) Received: from mail-ed1-f66.google.com (mail-ed1-f66.google.com [209.85.208.66]) (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 041CCC1EB214 for ; Mon, 10 Jun 2019 09:06:03 +0000 (UTC) Received: by mail-ed1-f66.google.com with SMTP id g13so13484327edu.5 for ; Mon, 10 Jun 2019 02:06:02 -0700 (PDT) Received: from archpc.localdomain (x8d1ee222.agdsn.tu-dresden.de. [141.30.226.34]) by smtp.gmail.com with ESMTPSA id b10sm1724334eje.29.2019.06.10.02.06.00 for (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 10 Jun 2019 02:06:00 -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=PXW6o3XjaembSWblwvEmyu4XkzXF6qKgpOKWXhKv5Lo=; b=iJFsb6lHgA2kIY1K8PfdN5DKbZHN3c3CQN7AOLq4OW73DvUDUFjMfK3FmfbNDmnEl1 9Js7LVkOVs8ztBXT06KGPs9+7ffmOUkxuOaR8kXWsioex77I5hj3Q23RhAlS5oNvvOJd Cae8AEtdwJV7NH8UFVnssJy2A2OKH1PzErp8/LAWhKC09Eyl98zE+QxRaZyFiT66lEub fCpNZcoZz1/wNb4bqDT7gdrIGHSlOvexfYi/it0YoSBH2RlF0BRZWCVYFeztIT5Da4pC E15jqu77EMNh+IOx236Pv4Ee7hxAkub1FuIb4ew1LJCIq00Fq282G+mEXxSv2ctsFsp5 615Q== 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=PXW6o3XjaembSWblwvEmyu4XkzXF6qKgpOKWXhKv5Lo=; b=MMHnD3LoUntX8by1Mdppd1neZu4Mml0dJ620F3gDmRUjjdXtBVn+IxRC6uP3itNEkU KCShxgkanH9g4vhXVKZFaSmcIdlPG9uQ+xisqY/9d0YKXiO8aI8z7zz1XyYVjq+QtIRP zs8u9tMb4KcUHwY91POrJ6M2aEXJ5ZikUwbMspN8eZLiCsuGCTcLBOzTlarPZy3A7R5T eWKkiCQ2jFbx2gppIkCbMeulHLKRYbjACoXVhFZWtYhOL8c1LT+10LZeXPj66qEsxmR+ brycCDhEIvY71m7FEhOmFaZ6i7FV9OzciZ98t/vDxrSHvxaNnQHfmSQ8dtedBK6sy+sg +/3w== X-Gm-Message-State: APjAAAXTJUkAG9671VpL9BJMx3HxftMKsXJ9KTUY0BJkR0Mqv8nvAdw2 J9ZWrtuR9rbbBWwJyZ2jY5Hh0+0N X-Google-Smtp-Source: APXvYqyBkRxRLxqmySzllnnKiy1nZsfTCbI42u2wyFKQIlWPDF/SaFvaLZkwrDBeaMvP23JlEC3WEA== X-Received: by 2002:a50:be03:: with SMTP id a3mr72019774edi.5.1560157561322; Mon, 10 Jun 2019 02:06:01 -0700 (PDT) From: Ilias Stamatis To: libvir-list@redhat.com Date: Mon, 10 Jun 2019 11:04:59 +0200 Message-Id: <20190610090501.2274-3-stamatis.iliass@gmail.com> In-Reply-To: <20190610090501.2274-1-stamatis.iliass@gmail.com> References: <20190610090501.2274-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.32]); Mon, 10 Jun 2019 09:06:03 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Mon, 10 Jun 2019 09:06:03 +0000 (UTC) for IP:'209.85.208.66' DOMAIN:'mail-ed1-f66.google.com' HELO:'mail-ed1-f66.google.com' FROM:'stamatis.iliass@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.109 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS) 209.85.208.66 mail-ed1-f66.google.com 209.85.208.66 mail-ed1-f66.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.32 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 2/4] test_driver: extract image loading 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.41]); Mon, 10 Jun 2019 09:12:57 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Extracting the code logic for opening and parsing a test image from testDomainRestoreFlags into a separate function, allows us to reuse this code in other functions such as testDomainSaveImageGetXMLDesc. Signed-off-by: Ilias Stamatis --- src/test/test_driver.c | 116 ++++++++++++++++++++++++++--------------- 1 file changed, 73 insertions(+), 43 deletions(-) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 3331ed5495..1b92cb43dd 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -2075,6 +2075,78 @@ testDomainSaveImageWrite(testDriverPtr driver, } +/** + * testDomainSaveImageOpen: + * @driver: test driver data + * @path: path of the saved image + * @ret_def: returns domain definition created from the XML stored in the = image + * + * Returns the opened fd of the save image file and fills ret_def on succe= ss. + * Returns -1, on error. + */ +static int ATTRIBUTE_NONNULL(3) +testDomainSaveImageOpen(testDriverPtr driver, + const char *path, + virDomainDefPtr *ret_def) +{ + char magic[15]; + int fd =3D -1; + int len; + virDomainDefPtr def =3D NULL; + VIR_AUTOFREE(char *) xml =3D NULL; + + if ((fd =3D open(path, O_RDONLY)) < 0) { + virReportSystemError(errno, _("cannot read domain image '%s'"), pa= th); + goto error; + } + + if (saferead(fd, magic, sizeof(magic)) !=3D sizeof(magic)) { + virReportSystemError(errno, _("incomplete save header in '%s'"), p= ath); + goto error; + } + + if (memcmp(magic, TEST_SAVE_MAGIC, sizeof(magic))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("mismatched header = magic")); + goto error; + } + + if (saferead(fd, (char*)&len, sizeof(len)) !=3D sizeof(len)) { + virReportSystemError(errno, + _("failed to read metadata length in '%s'"), + path); + goto error; + } + + if (len < 1 || len > 8192) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "%s", _("length of metadata out of range")); + goto error; + } + + if (VIR_ALLOC_N(xml, len+1) < 0) + goto error; + + if (saferead(fd, xml, len) !=3D len) { + virReportSystemError(errno, _("incomplete metadata in '%s'"), path= ); + goto error; + } + xml[len] =3D '\0'; + + if (!(def =3D virDomainDefParseString(xml, driver->caps, driver->xmlop= t, NULL, + VIR_DOMAIN_DEF_PARSE_INACTIVE | + VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE= ))) + goto error; + + VIR_STEAL_PTR(*ret_def, def); + return fd; + + error: + virDomainDefFree(def); + VIR_FORCE_CLOSE(fd); + return -1; +} + + static int testDomainSaveFlags(virDomainPtr domain, const char *path, const char *dxml, unsigned int flags) @@ -2130,14 +2202,11 @@ testDomainRestoreFlags(virConnectPtr conn, unsigned int flags) { testDriverPtr privconn =3D conn->privateData; - char magic[15]; int fd =3D -1; - int len; virDomainDefPtr def =3D NULL; virDomainObjPtr dom =3D NULL; virObjectEventPtr event =3D NULL; int ret =3D -1; - VIR_AUTOFREE(char *) xml =3D NULL; virCheckFlags(0, -1); if (dxml) { @@ -2146,46 +2215,7 @@ testDomainRestoreFlags(virConnectPtr conn, return -1; } - if ((fd =3D open(path, O_RDONLY)) < 0) { - virReportSystemError(errno, - _("cannot read domain image '%s'"), - path); - goto cleanup; - } - if (saferead(fd, magic, sizeof(magic)) !=3D sizeof(magic)) { - virReportSystemError(errno, - _("incomplete save header in '%s'"), - path); - goto cleanup; - } - if (memcmp(magic, TEST_SAVE_MAGIC, sizeof(magic))) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("mismatched header magic")); - goto cleanup; - } - if (saferead(fd, (char*)&len, sizeof(len)) !=3D sizeof(len)) { - virReportSystemError(errno, - _("failed to read metadata length in '%s'"), - path); - goto cleanup; - } - if (len < 1 || len > 8192) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("length of metadata out of range")); - goto cleanup; - } - if (VIR_ALLOC_N(xml, len+1) < 0) - goto cleanup; - if (saferead(fd, xml, len) !=3D len) { - virReportSystemError(errno, - _("incomplete metadata in '%s'"), path); - goto cleanup; - } - xml[len] =3D '\0'; - - def =3D virDomainDefParseString(xml, privconn->caps, privconn->xmlopt, - NULL, VIR_DOMAIN_DEF_PARSE_INACTIVE); - if (!def) + if ((fd =3D testDomainSaveImageOpen(privconn, path, &def)) < 0) goto cleanup; if (testDomainGenerateIfnames(def) < 0) -- 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list