From nobody Sun May 12 15:15:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1609862107; cv=none; d=zohomail.com; s=zohoarc; b=aWBLSEIf3iycpGKz0CWZ1WPG7jeOGRh49fFOfcFzjanNbPvj481g0ctUpR3gkR2Kxngks5m/jh9klpEAEBp3r503yc7VwaRtbFwxeW7B0CGPMqWvHYqR/p1JfYwCdoIpzLO0Vij8wbyGxIdUG16tU/lVeZOmX3S7a0kIehFNrSA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609862107; 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=Zvkpmr/NEv6x+5uTzOkFAEdG8CqFLSUMmpjFtPcMk5Q=; b=T6TsZwSeWNaBdeq3bMY/RwCDcCyarVUEBy+gvp/Iclqmj5KC0oYdGVhVX+tvraK303SDhTRIugGoN+Drbkt1la3tebtbbSulgnbnBRzDOaET6qIuWZ+G8YGJRZnHwyFKvwyI71ekYJSuHMFrg4u0R72On7GEbssredum/kSW7VM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 160986210734184.21174871501103; Tue, 5 Jan 2021 07:55:07 -0800 (PST) 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-272-Wpse5AjlNCmYTzhnmEFUIw-1; Tue, 05 Jan 2021 10:55:03 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B0D7B100C676; Tue, 5 Jan 2021 15:54:57 +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 7E1CE1002391; Tue, 5 Jan 2021 15:54:57 +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 0136D4A7C6; Tue, 5 Jan 2021 15:54:53 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 105FsqZV020933 for ; Tue, 5 Jan 2021 10:54:52 -0500 Received: by smtp.corp.redhat.com (Postfix) id A34311001B2C; Tue, 5 Jan 2021 15:54:52 +0000 (UTC) Received: from carol.localdomain (unknown [10.40.193.241]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4DCDB10016DB for ; Tue, 5 Jan 2021 15:54:49 +0000 (UTC) Received: from carol.redhat.com (carol.k8r.cz [127.0.0.1]) by carol.localdomain (Postfix) with ESMTP id D8D1EC20022 for ; Tue, 5 Jan 2021 16:54:47 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1609862106; 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=Zvkpmr/NEv6x+5uTzOkFAEdG8CqFLSUMmpjFtPcMk5Q=; b=Wsb2vJWnM5EV6YBlbyY7hVYcDAa4CxfYtNlS53wRIqtBoCb84Hp0zKB3WalEbPrqjlkZNV 6BclaL//6+/yw3bXUXwyxTSn6r44S5IPrZpcWLqN4RH6rSLH/tCCaOPUkJi5OFyz/tJwfV wi2FLRUS/hEKYsouR44SA+RwTlVV2ck= X-MC-Unique: Wpse5AjlNCmYTzhnmEFUIw-1 From: Martin Kletzander To: libvir-list@redhat.com Subject: [libvirt PATCH v3 1/8] esx: Unindent unnecessary conditional branch Date: Tue, 5 Jan 2021 16:54:40 +0100 Message-Id: <22eea866384b579aa5f1b3673f222bf79fc68d41.1609862070.git.mkletzan@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Clacks-Overhead: GNU Terry Pratchett X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com 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.22 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) Content-Type: text/plain; charset="utf-8" The positive branch can just return and the huge negative part does not nee= d to be indented an extra level. Best viewed with `-w`. Signed-off-by: Martin Kletzander Reviewed-by: Michal Privoznik --- src/esx/esx_driver.c | 144 +++++++++++++++++++++---------------------- 1 file changed, 72 insertions(+), 72 deletions(-) diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c index a17bf58a5124..51c26e29c65e 100644 --- a/src/esx/esx_driver.c +++ b/src/esx/esx_driver.c @@ -143,100 +143,100 @@ esxParseVMXFileName(const char *fileName, void *opa= que) =20 if (!strchr(fileName, '/') && !strchr(fileName, '\\')) { /* Plain file name, use same directory as for the .vmx file */ - result =3D g_strdup_printf("%s/%s", data->datastorePathWithoutFile= Name, - fileName); - } else { - if (esxVI_String_AppendValueToList(&propertyNameList, - "summary.name") < 0 || - esxVI_LookupDatastoreList(data->ctx, propertyNameList, - &datastoreList) < 0) { - return NULL; - } + return g_strdup_printf("%s/%s", data->datastorePathWithoutFileName, + fileName); + } =20 - /* Search for datastore by mount path */ - for (datastore =3D datastoreList; datastore; - datastore =3D datastore->_next) { - esxVI_DatastoreHostMount_Free(&hostMount); - datastoreName =3D NULL; - - if (esxVI_LookupDatastoreHostMount(data->ctx, datastore->obj, - &hostMount, - esxVI_Occurrence_RequiredIt= em) < 0 || - esxVI_GetStringValue(datastore, "summary.name", &datastore= Name, - esxVI_Occurrence_RequiredItem) < 0) { - goto cleanup; - } + if (esxVI_String_AppendValueToList(&propertyNameList, + "summary.name") < 0 || + esxVI_LookupDatastoreList(data->ctx, propertyNameList, + &datastoreList) < 0) { + return NULL; + } =20 - tmp =3D (char *)STRSKIP(fileName, hostMount->mountInfo->path); + /* Search for datastore by mount path */ + for (datastore =3D datastoreList; datastore; + datastore =3D datastore->_next) { + esxVI_DatastoreHostMount_Free(&hostMount); + datastoreName =3D NULL; =20 - if (!tmp) - continue; + if (esxVI_LookupDatastoreHostMount(data->ctx, datastore->obj, + &hostMount, + esxVI_Occurrence_RequiredItem) = < 0 || + esxVI_GetStringValue(datastore, "summary.name", &datastoreName, + esxVI_Occurrence_RequiredItem) < 0) { + goto cleanup; + } =20 - /* Found a match. Strip leading separators */ - while (*tmp =3D=3D '/' || *tmp =3D=3D '\\') - ++tmp; + tmp =3D (char *)STRSKIP(fileName, hostMount->mountInfo->path); =20 - strippedFileName =3D g_strdup(tmp); + if (!tmp) + continue; =20 - tmp =3D strippedFileName; + /* Found a match. Strip leading separators */ + while (*tmp =3D=3D '/' || *tmp =3D=3D '\\') + ++tmp; =20 - /* Convert \ to / */ - while (*tmp !=3D '\0') { - if (*tmp =3D=3D '\\') - *tmp =3D '/'; + strippedFileName =3D g_strdup(tmp); =20 - ++tmp; - } + tmp =3D strippedFileName; =20 - result =3D g_strdup_printf("[%s] %s", datastoreName, strippedF= ileName); + /* Convert \ to / */ + while (*tmp !=3D '\0') { + if (*tmp =3D=3D '\\') + *tmp =3D '/'; =20 - break; + ++tmp; } =20 - /* Fallback to direct datastore name match */ - if (!result && STRPREFIX(fileName, "/vmfs/volumes/")) { - copyOfFileName =3D g_strdup(fileName); - - /* Expected format: '/vmfs/volumes//' */ - if (!(tmp =3D STRSKIP(copyOfFileName, "/vmfs/volumes/")) || - !(datastoreName =3D strtok_r(tmp, "/", &saveptr)) || - !(directoryAndFileName =3D strtok_r(NULL, "", &saveptr))) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("File name '%s' doesn't have expected for= mat " - "'/vmfs/volumes//'"), fi= leName); - goto cleanup; - } - - esxVI_ObjectContent_Free(&datastoreList); + result =3D g_strdup_printf("[%s] %s", datastoreName, strippedFileN= ame); =20 - if (esxVI_LookupDatastoreByName(data->ctx, datastoreName, - NULL, &datastoreList, - esxVI_Occurrence_OptionalItem)= < 0) { - goto cleanup; - } + break; + } =20 - if (!datastoreList) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("File name '%s' refers to non-existing da= tastore '%s'"), - fileName, datastoreName); - goto cleanup; - } + /* Fallback to direct datastore name match */ + if (!result && STRPREFIX(fileName, "/vmfs/volumes/")) { + copyOfFileName =3D g_strdup(fileName); =20 - result =3D g_strdup_printf("[%s] %s", datastoreName, - directoryAndFileName); + /* Expected format: '/vmfs/volumes//' */ + if (!(tmp =3D STRSKIP(copyOfFileName, "/vmfs/volumes/")) || + !(datastoreName =3D strtok_r(tmp, "/", &saveptr)) || + !(directoryAndFileName =3D strtok_r(NULL, "", &saveptr))) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("File name '%s' doesn't have expected format " + "'/vmfs/volumes//'"), fileNa= me); + goto cleanup; } =20 - /* If it's an absolute path outside of a datastore just use it as = is */ - if (!result && *fileName =3D=3D '/') { - /* FIXME: need to deal with Windows paths here too */ - result =3D g_strdup(fileName); + esxVI_ObjectContent_Free(&datastoreList); + + if (esxVI_LookupDatastoreByName(data->ctx, datastoreName, + NULL, &datastoreList, + esxVI_Occurrence_OptionalItem) < 0= ) { + goto cleanup; } =20 - if (!result) { + if (!datastoreList) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("Could not handle file name '%s'"), fileName); + _("File name '%s' refers to non-existing datast= ore '%s'"), + fileName, datastoreName); goto cleanup; } + + result =3D g_strdup_printf("[%s] %s", datastoreName, + directoryAndFileName); + } + + /* If it's an absolute path outside of a datastore just use it as is */ + if (!result && *fileName =3D=3D '/') { + /* FIXME: need to deal with Windows paths here too */ + result =3D g_strdup(fileName); + } + + if (!result) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Could not handle file name '%s'"), fileName); + goto cleanup; } =20 cleanup: --=20 2.30.0 From nobody Sun May 12 15:15:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1609862129; cv=none; d=zohomail.com; s=zohoarc; b=c1Vzh16yg9suGGOBvlzoPViMTtWVFQ01xVuL+r86QJ+kJ/QamrmbrSSbGkXbBspxA3P97LAAqetFv2+CqcWUWZNy4opX/f3ydRrJ/pimZLuXAyEqmD+FHhWreXavqqbcKqT4wo4MQebeWx0UjogJ6k1D2vVnK6DKoBm6xUZBcOg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609862129; 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=rlif+pkfGhz0Bo7m/yreRpxe0QOcPBJYIrEdVvAcP6w=; b=YPXqcY4O09Bbb9vsdJ280/j1NLG6SFYgUVSAFODjkTybMmSbSUsMgcO5vcb0vKcho0wy9zYLT5W4WiKoR8eLjNUBUhs6flVjAfBgYmv9lbpArHrJZYITHNySUC8fPaAOl89JOM1zh9QnAyjxYp6x3SD0hVpX9XFBGwfYq9RgODE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 16098621297911009.8125036271414; Tue, 5 Jan 2021 07:55:29 -0800 (PST) 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-107-CJmPf-N9Oe2v3nUqIxO8pg-1; Tue, 05 Jan 2021 10:55:26 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0A9FA1005513; Tue, 5 Jan 2021 15:55:19 +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 D8A8971C96; Tue, 5 Jan 2021 15:55:18 +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 9B51C4EDB6; Tue, 5 Jan 2021 15:55:18 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 105FsqpB020944 for ; Tue, 5 Jan 2021 10:54:52 -0500 Received: by smtp.corp.redhat.com (Postfix) id BE8DD55770; Tue, 5 Jan 2021 15:54:52 +0000 (UTC) Received: from carol.localdomain (unknown [10.40.193.241]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 902B55D6CF for ; Tue, 5 Jan 2021 15:54:49 +0000 (UTC) Received: from carol.redhat.com (carol.k8r.cz [127.0.0.1]) by carol.localdomain (Postfix) with ESMTP id D9D98C201BC for ; Tue, 5 Jan 2021 16:54:47 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1609862128; 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=rlif+pkfGhz0Bo7m/yreRpxe0QOcPBJYIrEdVvAcP6w=; b=ZIjAkfGeDtaBBQEjDR5m/sXNEX+EHNpkLz9APcWxN2rMpk4WTuk4xCwJROgtefG7qek9KL fPcwsNJPpb5AES22oyTK4RVl2PK2FmBQH3p4MPwMEYwNJAIe62BSGeQok8L8Zn6e9L2ZsX 4UTbRD9edfyyNF3cvDu18rL5hHzWWM4= X-MC-Unique: CJmPf-N9Oe2v3nUqIxO8pg-1 From: Martin Kletzander To: libvir-list@redhat.com Subject: [libvirt PATCH v3 2/8] tests: Use g_autofree in testParseVMXFileName Date: Tue, 5 Jan 2021 16:54:41 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Clacks-Overhead: GNU Terry Pratchett X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com 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.79 on 10.5.11.16 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) Content-Type: text/plain; charset="utf-8" There's only one variable to clean-up, others are just tokens inside that variable, but it is nicer anyway. Positive returns have not been converted because the function will change soon and it would not make much sense. Signed-off-by: Martin Kletzander Reviewed-by: Michal Privoznik --- tests/vmx2xmltest.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/tests/vmx2xmltest.c b/tests/vmx2xmltest.c index 376116bb750a..8cc227bbedfc 100644 --- a/tests/vmx2xmltest.c +++ b/tests/vmx2xmltest.c @@ -130,7 +130,7 @@ testCompareHelper(const void *data) static char * testParseVMXFileName(const char *fileName, void *opaque G_GNUC_UNUSED) { - char *copyOfFileName =3D NULL; + g_autofree char *copyOfFileName =3D NULL; char *tmp =3D NULL; char *saveptr =3D NULL; char *datastoreName =3D NULL; @@ -145,7 +145,7 @@ testParseVMXFileName(const char *fileName, void *opaque= G_GNUC_UNUSED) if ((tmp =3D STRSKIP(copyOfFileName, "/vmfs/volumes/")) =3D=3D NUL= L || (datastoreName =3D strtok_r(tmp, "/", &saveptr)) =3D=3D NULL || (directoryAndFileName =3D strtok_r(NULL, "", &saveptr)) =3D=3D= NULL) { - goto cleanup; + return NULL; } =20 src =3D g_strdup_printf("[%s] %s", datastoreName, directoryAndFile= Name); @@ -154,15 +154,12 @@ testParseVMXFileName(const char *fileName, void *opaq= ue G_GNUC_UNUSED) src =3D g_strdup(fileName); } else if (strchr(fileName, '/') !=3D NULL) { /* Found relative path, this is not supported */ - src =3D NULL; + return NULL; } else { /* Found single file name referencing a file inside a datastore */ src =3D g_strdup_printf("[datastore] directory/%s", fileName); } =20 - cleanup: - VIR_FREE(copyOfFileName); - return src; } =20 --=20 2.30.0 From nobody Sun May 12 15:15:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1609862129; cv=none; d=zohomail.com; s=zohoarc; b=SFmacAw6dHEcUN1rYGikV+GwCPG04/wwRVugIJmOTPw2yOhv6jgbkZik3AskI1GNW2wxZiAY9smu36mmpt1SezE40EE+KISKa5vV70/HJRaST361gHxa3G+6bn68M+jPX9Z/gO/5wFpp1wSBqJeaE5mGw0FfKZ2s2/nSftXmD2A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609862129; 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=pLcZQWIe9paDDId4CM617P7krrELrnn8OyWKxr41fLU=; b=iLX2yp2M1AZ7AIFmOVJHIyzzM6TN0O7L1jNXpC+2FixXa/W4OyXPYl5Rm5ojeetxh4PHKxtE3x4QmLkdeamt8ZhfTc4ASPTN2Qg7JQWoO2Dxv8XPInOuiOzJAdgkCW/vLDjtKMIbKj8hhRMynw2wPwl5l5NshFZzb2GFnYujjB0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1609862129065334.18542292250186; Tue, 5 Jan 2021 07:55:29 -0800 (PST) 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-78-haOctMUfNHaiJCu48__5HA-1; Tue, 05 Jan 2021 10:55:23 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B5EA680362B; Tue, 5 Jan 2021 15:55:17 +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 92F5760C15; Tue, 5 Jan 2021 15:55:17 +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 5B4C44E590; Tue, 5 Jan 2021 15:55:17 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 105FsrCH020953 for ; Tue, 5 Jan 2021 10:54:53 -0500 Received: by smtp.corp.redhat.com (Postfix) id 1BA845D6CF; Tue, 5 Jan 2021 15:54:53 +0000 (UTC) Received: from carol.localdomain (unknown [10.40.193.241]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9060D5D6D3 for ; Tue, 5 Jan 2021 15:54:49 +0000 (UTC) Received: from carol.redhat.com (carol.k8r.cz [127.0.0.1]) by carol.localdomain (Postfix) with ESMTP id DA922C201C4 for ; Tue, 5 Jan 2021 16:54:47 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1609862126; 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=pLcZQWIe9paDDId4CM617P7krrELrnn8OyWKxr41fLU=; b=O3Too5T05YMFwxBZhI596adC/I2G4iaRuCwDBBJsBl6W+a3beagySjFif5qLKLYxXFOmz1 czIKLhcxx4Q7unmGEpzZN0KDllO3tDERPuepOxokt5S1LYIxHBNTl8ZJNuCstNImoeuZ21 yZoMDuKrOwVB7ZtkIzmx/Y0tC/qR4GA= X-MC-Unique: haOctMUfNHaiJCu48__5HA-1 From: Martin Kletzander To: libvir-list@redhat.com Subject: [libvirt PATCH v3 3/8] vmx: Make virVMXParseFileName return an integer Date: Tue, 5 Jan 2021 16:54:42 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Clacks-Overhead: GNU Terry Pratchett X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com 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.79 on 10.5.11.12 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) Content-Type: text/plain; charset="utf-8" And return the actual extracted value in a parameter. This way we can later return success even without any extracted value. Signed-off-by: Martin Kletzander Reviewed-by: Michal Privoznik --- src/esx/esx_driver.c | 31 ++++++++++++++++++------------- src/vmware/vmware_conf.c | 20 ++++++++++++++------ src/vmware/vmware_conf.h | 9 ++++++++- src/vmware/vmware_driver.c | 6 +++--- src/vmx/vmx.c | 25 ++++++++++++------------- src/vmx/vmx.h | 2 +- tests/vmx2xmltest.c | 21 ++++++++++++--------- 7 files changed, 68 insertions(+), 46 deletions(-) diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c index 51c26e29c65e..86d5396147a3 100644 --- a/src/esx/esx_driver.c +++ b/src/esx/esx_driver.c @@ -125,10 +125,11 @@ esxFreePrivate(esxPrivate **priv) * exception and need special handling. Parse the datastore name and use it * to lookup the datastore by name to verify that it exists. */ -static char * -esxParseVMXFileName(const char *fileName, void *opaque) +static int +esxParseVMXFileName(const char *fileName, + void *opaque, + char **out) { - char *result =3D NULL; esxVMX_Data *data =3D opaque; esxVI_String *propertyNameList =3D NULL; esxVI_ObjectContent *datastoreList =3D NULL; @@ -140,18 +141,22 @@ esxParseVMXFileName(const char *fileName, void *opaqu= e) char *strippedFileName =3D NULL; char *copyOfFileName =3D NULL; char *directoryAndFileName; + int ret =3D -1; + + *out =3D NULL; =20 if (!strchr(fileName, '/') && !strchr(fileName, '\\')) { /* Plain file name, use same directory as for the .vmx file */ - return g_strdup_printf("%s/%s", data->datastorePathWithoutFileName, + *out =3D g_strdup_printf("%s/%s", data->datastorePathWithoutFileNa= me, fileName); + return 0; } =20 if (esxVI_String_AppendValueToList(&propertyNameList, "summary.name") < 0 || esxVI_LookupDatastoreList(data->ctx, propertyNameList, &datastoreList) < 0) { - return NULL; + return -1; } =20 /* Search for datastore by mount path */ @@ -189,13 +194,13 @@ esxParseVMXFileName(const char *fileName, void *opaqu= e) ++tmp; } =20 - result =3D g_strdup_printf("[%s] %s", datastoreName, strippedFileN= ame); + *out =3D g_strdup_printf("[%s] %s", datastoreName, strippedFileNam= e); =20 break; } =20 /* Fallback to direct datastore name match */ - if (!result && STRPREFIX(fileName, "/vmfs/volumes/")) { + if (!*out && STRPREFIX(fileName, "/vmfs/volumes/")) { copyOfFileName =3D g_strdup(fileName); =20 /* Expected format: '/vmfs/volumes//' */ @@ -223,22 +228,22 @@ esxParseVMXFileName(const char *fileName, void *opaqu= e) goto cleanup; } =20 - result =3D g_strdup_printf("[%s] %s", datastoreName, - directoryAndFileName); + *out =3D g_strdup_printf("[%s] %s", datastoreName, directoryAndFil= eName); } =20 /* If it's an absolute path outside of a datastore just use it as is */ - if (!result && *fileName =3D=3D '/') { + if (!*out && *fileName =3D=3D '/') { /* FIXME: need to deal with Windows paths here too */ - result =3D g_strdup(fileName); + *out =3D g_strdup(fileName); } =20 - if (!result) { + if (!*out) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not handle file name '%s'"), fileName); goto cleanup; } =20 + ret =3D 0; cleanup: esxVI_String_Free(&propertyNameList); esxVI_ObjectContent_Free(&datastoreList); @@ -246,7 +251,7 @@ esxParseVMXFileName(const char *fileName, void *opaque) VIR_FREE(strippedFileName); VIR_FREE(copyOfFileName); =20 - return result; + return ret; } =20 =20 diff --git a/src/vmware/vmware_conf.c b/src/vmware/vmware_conf.c index e44673247ff1..4f7dc3001d2b 100644 --- a/src/vmware/vmware_conf.c +++ b/src/vmware/vmware_conf.c @@ -139,7 +139,7 @@ vmwareLoadDomains(struct vmware_driver *driver) char *saveptr =3D NULL; virCommandPtr cmd; =20 - ctx.parseFileName =3D vmwareCopyVMXFileName; + ctx.parseFileName =3D vmwareParseVMXFileName; ctx.formatFileName =3D NULL; ctx.autodetectSCSIControllerModel =3D NULL; ctx.datacenterPath =3D NULL; @@ -507,11 +507,19 @@ vmwareExtractPid(const char * vmxPath) return pid_value; } =20 -char * -vmwareCopyVMXFileName(const char *datastorePath, void *opaque G_GNUC_UNUSE= D) +int +vmwareParseVMXFileName(const char *datastorePath, + void *opaque G_GNUC_UNUSED, + char **out) { - char *path; + *out =3D g_strdup(datastorePath); + + return *out ? 0 : -1; +} =20 - path =3D g_strdup(datastorePath); - return path; +char * +vmwareFormatVMXFileName(const char *datastorePath, + void *opaque G_GNUC_UNUSED) +{ + return g_strdup(datastorePath); } diff --git a/src/vmware/vmware_conf.h b/src/vmware/vmware_conf.h index 5e0ef3744f76..6f86983f511f 100644 --- a/src/vmware/vmware_conf.h +++ b/src/vmware/vmware_conf.h @@ -83,4 +83,11 @@ int vmwareMakePath(char *srcDir, char *srcName, char *sr= cExt, =20 int vmwareExtractPid(const char * vmxPath); =20 -char *vmwareCopyVMXFileName(const char *datastorePath, void *opaque); +int +vmwareParseVMXFileName(const char *datastorePath, + void *opaque, + char **out); + +char * +vmwareFormatVMXFileName(const char *datastorePath, + void *opaque); diff --git a/src/vmware/vmware_driver.c b/src/vmware/vmware_driver.c index 087664a34185..481c59ef3cce 100644 --- a/src/vmware/vmware_driver.c +++ b/src/vmware/vmware_driver.c @@ -409,7 +409,7 @@ vmwareDomainDefineXMLFlags(virConnectPtr conn, const ch= ar *xml, unsigned int fla parse_flags |=3D VIR_DOMAIN_DEF_PARSE_VALIDATE_SCHEMA; =20 ctx.parseFileName =3D NULL; - ctx.formatFileName =3D vmwareCopyVMXFileName; + ctx.formatFileName =3D vmwareFormatVMXFileName; ctx.autodetectSCSIControllerModel =3D NULL; ctx.datacenterPath =3D NULL; =20 @@ -662,7 +662,7 @@ vmwareDomainCreateXML(virConnectPtr conn, const char *x= ml, parse_flags |=3D VIR_DOMAIN_DEF_PARSE_VALIDATE_SCHEMA; =20 ctx.parseFileName =3D NULL; - ctx.formatFileName =3D vmwareCopyVMXFileName; + ctx.formatFileName =3D vmwareFormatVMXFileName; ctx.autodetectSCSIControllerModel =3D NULL; ctx.datacenterPath =3D NULL; =20 @@ -950,7 +950,7 @@ vmwareConnectDomainXMLFromNative(virConnectPtr conn, co= nst char *nativeFormat, return NULL; } =20 - ctx.parseFileName =3D vmwareCopyVMXFileName; + ctx.parseFileName =3D vmwareParseVMXFileName; ctx.formatFileName =3D NULL; ctx.autodetectSCSIControllerModel =3D NULL; ctx.datacenterPath =3D NULL; diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c index b86dbe9ca267..97591842f789 100644 --- a/src/vmx/vmx.c +++ b/src/vmx/vmx.c @@ -2388,7 +2388,7 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptio= nPtr xmlopt, virConfPtr con */ goto ignore; } else if (virStringHasCaseSuffix(fileName, ".vmdk")) { - char *tmp; + char *tmp =3D NULL; =20 if (deviceType !=3D NULL) { if (busType =3D=3D VIR_DOMAIN_DISK_BUS_SCSI && @@ -2411,7 +2411,7 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptio= nPtr xmlopt, virConfPtr con } =20 virDomainDiskSetType(*def, VIR_STORAGE_TYPE_FILE); - if (!(tmp =3D ctx->parseFileName(fileName, ctx->opaque))) + if (ctx->parseFileName(fileName, ctx->opaque, &tmp) < 0) goto cleanup; virDomainDiskSetSource(*def, tmp); VIR_FREE(tmp); @@ -2438,7 +2438,7 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptio= nPtr xmlopt, virConfPtr con */ goto ignore; } else if (fileName && virStringHasCaseSuffix(fileName, ".iso")) { - char *tmp; + char *tmp =3D NULL; =20 if (deviceType && STRCASENEQ(deviceType, "cdrom-image")) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -2448,7 +2448,7 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptio= nPtr xmlopt, virConfPtr con } =20 virDomainDiskSetType(*def, VIR_STORAGE_TYPE_FILE); - if (!(tmp =3D ctx->parseFileName(fileName, ctx->opaque))) + if (ctx->parseFileName(fileName, ctx->opaque, &tmp) < 0) goto cleanup; virDomainDiskSetSource(*def, tmp); VIR_FREE(tmp); @@ -2514,7 +2514,8 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptio= nPtr xmlopt, virConfPtr con char *tmp =3D NULL; =20 virDomainDiskSetType(*def, VIR_STORAGE_TYPE_FILE); - if (fileName && !(tmp =3D ctx->parseFileName(fileName, ctx->op= aque))) + if (fileName && + ctx->parseFileName(fileName, ctx->opaque, &tmp) < 0) goto cleanup; virDomainDiskSetSource(*def, tmp); VIR_FREE(tmp); @@ -2974,10 +2975,9 @@ virVMXParseSerial(virVMXContext *ctx, virConfPtr con= f, int port, } else if (STRCASEEQ(fileType, "file")) { (*def)->target.port =3D port; (*def)->source->type =3D VIR_DOMAIN_CHR_TYPE_FILE; - (*def)->source->data.file.path =3D ctx->parseFileName(fileName, - ctx->opaque); - - if ((*def)->source->data.file.path =3D=3D NULL) + if (ctx->parseFileName(fileName, + ctx->opaque, + &(*def)->source->data.file.path) < 0) goto cleanup; } else if (STRCASEEQ(fileType, "pipe")) { /* @@ -3140,10 +3140,9 @@ virVMXParseParallel(virVMXContext *ctx, virConfPtr c= onf, int port, } else if (STRCASEEQ(fileType, "file")) { (*def)->target.port =3D port; (*def)->source->type =3D VIR_DOMAIN_CHR_TYPE_FILE; - (*def)->source->data.file.path =3D ctx->parseFileName(fileName, - ctx->opaque); - - if ((*def)->source->data.file.path =3D=3D NULL) + if (ctx->parseFileName(fileName, + ctx->opaque, + &(*def)->source->data.file.path) < 0) goto cleanup; } else { virReportError(VIR_ERR_INTERNAL_ERROR, diff --git a/src/vmx/vmx.h b/src/vmx/vmx.h index df5d39157b99..e5420c970a4b 100644 --- a/src/vmx/vmx.h +++ b/src/vmx/vmx.h @@ -36,7 +36,7 @@ virDomainXMLOptionPtr virVMXDomainXMLConfInit(virCapsPtr = caps); * Context */ =20 -typedef char * (*virVMXParseFileName)(const char *fileName, void *opaque); +typedef int (*virVMXParseFileName)(const char *fileName, void *opaque, cha= r **src); typedef char * (*virVMXFormatFileName)(const char *src, void *opaque); typedef int (*virVMXAutodetectSCSIControllerModel)(virDomainDiskDefPtr def, int *model, void *opaqu= e); diff --git a/tests/vmx2xmltest.c b/tests/vmx2xmltest.c index 8cc227bbedfc..bb7c498d1b41 100644 --- a/tests/vmx2xmltest.c +++ b/tests/vmx2xmltest.c @@ -127,15 +127,18 @@ testCompareHelper(const void *data) return ret; } =20 -static char * -testParseVMXFileName(const char *fileName, void *opaque G_GNUC_UNUSED) +static int +testParseVMXFileName(const char *fileName, + void *opaque G_GNUC_UNUSED, + char **src) { g_autofree char *copyOfFileName =3D NULL; char *tmp =3D NULL; char *saveptr =3D NULL; char *datastoreName =3D NULL; char *directoryAndFileName =3D NULL; - char *src =3D NULL; + + *src =3D NULL; =20 if (STRPREFIX(fileName, "/vmfs/volumes/")) { /* Found absolute path referencing a file inside a datastore */ @@ -145,22 +148,22 @@ testParseVMXFileName(const char *fileName, void *opaq= ue G_GNUC_UNUSED) if ((tmp =3D STRSKIP(copyOfFileName, "/vmfs/volumes/")) =3D=3D NUL= L || (datastoreName =3D strtok_r(tmp, "/", &saveptr)) =3D=3D NULL || (directoryAndFileName =3D strtok_r(NULL, "", &saveptr)) =3D=3D= NULL) { - return NULL; + return -1; } =20 - src =3D g_strdup_printf("[%s] %s", datastoreName, directoryAndFile= Name); + *src =3D g_strdup_printf("[%s] %s", datastoreName, directoryAndFil= eName); } else if (STRPREFIX(fileName, "/")) { /* Found absolute path referencing a file outside a datastore */ - src =3D g_strdup(fileName); + *src =3D g_strdup(fileName); } else if (strchr(fileName, '/') !=3D NULL) { /* Found relative path, this is not supported */ - return NULL; + return -1; } else { /* Found single file name referencing a file inside a datastore */ - src =3D g_strdup_printf("[datastore] directory/%s", fileName); + *src =3D g_strdup_printf("[datastore] directory/%s", fileName); } =20 - return src; + return 0; } =20 static int --=20 2.30.0 From nobody Sun May 12 15:15:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1609862107; cv=none; d=zohomail.com; s=zohoarc; b=gxApwA59Vb/8HdEfe5ELatBAfyCt5zaqV02tO6NuQjjihgJmn1f+dbFzCgrh6EgqjY+xNJw4PgSr7OQBq21py7ZIa9QRE3CZNnF0OZEdBHqIPm0l5mNUT3Xb4MJkGMDWy+Rfpgmwm6of8ZErybGYvYYIRrhu65ZhZpfyGSlAQvk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609862107; 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=p6NkV+HLwynjYSjOW7d91pW6Tq34U8EY3EEULeDW3vM=; b=OQa7qMRc4Qt8Sp7mDq1Hms9bIWlsraN0mKU0igi3sIs4rnNS/4xLugZBLWtsomvmxanCzn0cU78xoar3Sm830js+61aUSXN1d9ST1ViRimxYbbY4EZwFQr+KuKx1dR81aykhvKis/5WjEGl5E7bFlEotOaANc6XDMlqqPEKingA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1609862107659388.1495183420092; Tue, 5 Jan 2021 07:55:07 -0800 (PST) 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-149-3IFdnWdpOrW5qxTrBNiuxw-1; Tue, 05 Jan 2021 10:55:04 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B10B218C89DA; Tue, 5 Jan 2021 15:54:57 +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 05D7A10023AD; Tue, 5 Jan 2021 15:54:57 +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 4A6F0180954D; Tue, 5 Jan 2021 15:54:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 105Fsq2L020943 for ; Tue, 5 Jan 2021 10:54:52 -0500 Received: by smtp.corp.redhat.com (Postfix) id BEFA962460; Tue, 5 Jan 2021 15:54:52 +0000 (UTC) Received: from carol.localdomain (unknown [10.40.193.241]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 907DC2CFAB for ; Tue, 5 Jan 2021 15:54:49 +0000 (UTC) Received: from carol.redhat.com (carol.k8r.cz [127.0.0.1]) by carol.localdomain (Postfix) with ESMTP id DBCC5C201FF for ; Tue, 5 Jan 2021 16:54:47 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1609862106; 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=p6NkV+HLwynjYSjOW7d91pW6Tq34U8EY3EEULeDW3vM=; b=Gkrl0ASCAPOd+AM7jQxwsipGKFIkGoP/x14lDBf4B1VDLISUuiFBz4oZWPzlXe6HxT37Ei VubwpVuDh/m57VkobGtdtiQaOFnKAVM03DgBnsnvsVUUR+Z6KDs4yVtxRQPKol/yHxB6BD DXTedrvFIpLybYpFXq6xd3fIgQaKfY8= X-MC-Unique: 3IFdnWdpOrW5qxTrBNiuxw-1 From: Martin Kletzander To: libvir-list@redhat.com Subject: [libvirt PATCH v3 4/8] tests: Allow testing for parse failures in vmx2xmltest Date: Tue, 5 Jan 2021 16:54:43 +0100 Message-Id: <5b4664a7f71aafb2329b0e7b26bc7c611d94465f.1609862070.git.mkletzan@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Clacks-Overhead: GNU Terry Pratchett X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com 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.22 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) Content-Type: text/plain; charset="utf-8" Signed-off-by: Martin Kletzander Reviewed-by: Michal Privoznik --- tests/vmx2xmltest.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/tests/vmx2xmltest.c b/tests/vmx2xmltest.c index bb7c498d1b41..7db2edb12c27 100644 --- a/tests/vmx2xmltest.c +++ b/tests/vmx2xmltest.c @@ -66,7 +66,7 @@ testCapsInit(void) } =20 static int -testCompareFiles(const char *vmx, const char *xml) +testCompareFiles(const char *vmx, const char *xml, bool should_fail_parse) { int ret =3D -1; char *vmxData =3D NULL; @@ -74,9 +74,17 @@ testCompareFiles(const char *vmx, const char *xml) virDomainDefPtr def =3D NULL; =20 if (virTestLoadFile(vmx, &vmxData) < 0) - goto cleanup; + return -1; =20 - if (!(def =3D virVMXParseConfig(&ctx, xmlopt, caps, vmxData))) + def =3D virVMXParseConfig(&ctx, xmlopt, caps, vmxData); + if (should_fail_parse) { + if (!def) + ret =3D 0; + else + VIR_TEST_DEBUG("passed instead of expected failure"); + goto cleanup; + } + if (!def) goto cleanup; =20 if (!virDomainDefCheckABIStability(def, def, xmlopt)) { @@ -104,6 +112,7 @@ testCompareFiles(const char *vmx, const char *xml) struct testInfo { const char *input; const char *output; + bool should_fail; }; =20 static int @@ -119,7 +128,7 @@ testCompareHelper(const void *data) xml =3D g_strdup_printf("%s/vmx2xmldata/vmx2xml-%s.xml", abs_srcdir, info->output); =20 - ret =3D testCompareFiles(vmx, xml); + ret =3D testCompareFiles(vmx, xml, info->should_fail); =20 VIR_FREE(vmx); VIR_FREE(xml); @@ -171,9 +180,9 @@ mymain(void) { int ret =3D 0; =20 -# define DO_TEST(_in, _out) \ +# define DO_TEST_FULL(_in, _out, _should_fail) \ do { \ - struct testInfo info =3D { _in, _out }; \ + struct testInfo info =3D { _in, _out, _should_fail }; \ virResetLastError(); \ if (virTestRun("VMware VMX-2-XML "_in" -> "_out, \ testCompareHelper, &info) < 0) { \ @@ -181,6 +190,9 @@ mymain(void) } \ } while (0) =20 +# define DO_TEST(_in, _out) DO_TEST_FULL(_in, _out, false) +# define DO_TEST_FAIL(_in, _out) DO_TEST_FULL(_in, _out, true) + testCapsInit(); =20 if (caps =3D=3D NULL) --=20 2.30.0 From nobody Sun May 12 15:15:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1609862131; cv=none; d=zohomail.com; s=zohoarc; b=CgR+Q0oMa9pS3147rK3PR1DBSNdsGgSy+pINdBGGPbDMcO7SWwG4HQ16exY89uZOISk1DxYr9xyKZ5wds832qZ0kpn/VyxfMkYNEj+3V4yOJjRjfwwusER3ymqDZAOKqNK4KAI/9QDP8mTNSsBrNKl5Ohz8pxJyALRN9DgYmnXQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609862131; 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=Qeopg4nB9TtvnOoOJOqWiul4W9c8UED2NhUJQ+jky/I=; b=LQ06CQahSE4K7lpq8Rqhk3VTp9hQltYMy7lyuUcJlU8AbvaLPTbJA/000IQ7nLKLehjMASJxCdU8UPsyx1U10mCnsDA/eg/JWFp8+1cU5B5ovuWfn4uqEaSotRlk1xpsBbjWcOClSTfhkSGwgcRu3sqpMU3oivkkRm1/zd3Dwwo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1609862131168681.5739132041953; Tue, 5 Jan 2021 07:55:31 -0800 (PST) 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-188-_AMpq94GNL6kEcwBwNnXVg-1; Tue, 05 Jan 2021 10:55:28 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 14D03A0CB1; Tue, 5 Jan 2021 15:55:22 +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 E6CF160BE5; Tue, 5 Jan 2021 15:55:21 +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 A55C050032; Tue, 5 Jan 2021 15:55:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 105FsvaC020989 for ; Tue, 5 Jan 2021 10:54:57 -0500 Received: by smtp.corp.redhat.com (Postfix) id B678418F0A; Tue, 5 Jan 2021 15:54:57 +0000 (UTC) Received: from carol.localdomain (unknown [10.40.193.241]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6104E70464 for ; Tue, 5 Jan 2021 15:54:53 +0000 (UTC) Received: from carol.redhat.com (carol.k8r.cz [127.0.0.1]) by carol.localdomain (Postfix) with ESMTP id E72B7C2020C for ; Tue, 5 Jan 2021 16:54:47 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1609862130; 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=Qeopg4nB9TtvnOoOJOqWiul4W9c8UED2NhUJQ+jky/I=; b=ViJJThVQ/UKzYsHSPKAJjlPV2i2JbL6oLq6q144ttlBeMgAWb6QHOvvpYlhTRtkBEgJTSx i++xbHOv1ZDpbVCzbSie9gPk7Yx7sirrBDViI5sN3KdC0SN6MVL6JtTGlzKYf+V5hkclFn caqVK+FubsF1vCsHY+kZp0QMsroc72I= X-MC-Unique: _AMpq94GNL6kEcwBwNnXVg-1 From: Martin Kletzander To: libvir-list@redhat.com Subject: [libvirt PATCH v3 5/8] vmx: Allow missing cdrom image file in virVMXParseFileName Date: Tue, 5 Jan 2021 16:54:44 +0100 Message-Id: <7f7bf68761676f1c6befc343696f9cc57db9dd39.1609862070.git.mkletzan@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Clacks-Overhead: GNU Terry Pratchett X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com 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.79 on 10.5.11.12 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) Content-Type: text/plain; charset="utf-8" This will be used later. Signed-off-by: Martin Kletzander Reviewed-by: Michal Privoznik --- src/esx/esx_driver.c | 3 ++- src/vmware/vmware_conf.c | 3 ++- src/vmware/vmware_conf.h | 3 ++- src/vmx/vmx.c | 12 +++++++----- src/vmx/vmx.h | 5 ++++- tests/vmx2xmltest.c | 13 ++++++++++++- 6 files changed, 29 insertions(+), 10 deletions(-) diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c index 86d5396147a3..dde51688f72f 100644 --- a/src/esx/esx_driver.c +++ b/src/esx/esx_driver.c @@ -128,7 +128,8 @@ esxFreePrivate(esxPrivate **priv) static int esxParseVMXFileName(const char *fileName, void *opaque, - char **out) + char **out, + bool allow_missing G_GNUC_UNUSED) { esxVMX_Data *data =3D opaque; esxVI_String *propertyNameList =3D NULL; diff --git a/src/vmware/vmware_conf.c b/src/vmware/vmware_conf.c index 4f7dc3001d2b..55cd1d6f2d36 100644 --- a/src/vmware/vmware_conf.c +++ b/src/vmware/vmware_conf.c @@ -510,7 +510,8 @@ vmwareExtractPid(const char * vmxPath) int vmwareParseVMXFileName(const char *datastorePath, void *opaque G_GNUC_UNUSED, - char **out) + char **out, + bool allow_missing G_GNUC_UNUSED) { *out =3D g_strdup(datastorePath); =20 diff --git a/src/vmware/vmware_conf.h b/src/vmware/vmware_conf.h index 6f86983f511f..4974260e68f6 100644 --- a/src/vmware/vmware_conf.h +++ b/src/vmware/vmware_conf.h @@ -86,7 +86,8 @@ int vmwareExtractPid(const char * vmxPath); int vmwareParseVMXFileName(const char *datastorePath, void *opaque, - char **out); + char **out, + bool allow_missing); =20 char * vmwareFormatVMXFileName(const char *datastorePath, diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c index 97591842f789..aa5d1d4eedea 100644 --- a/src/vmx/vmx.c +++ b/src/vmx/vmx.c @@ -2411,7 +2411,7 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptio= nPtr xmlopt, virConfPtr con } =20 virDomainDiskSetType(*def, VIR_STORAGE_TYPE_FILE); - if (ctx->parseFileName(fileName, ctx->opaque, &tmp) < 0) + if (ctx->parseFileName(fileName, ctx->opaque, &tmp, false) < 0) goto cleanup; virDomainDiskSetSource(*def, tmp); VIR_FREE(tmp); @@ -2448,7 +2448,7 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptio= nPtr xmlopt, virConfPtr con } =20 virDomainDiskSetType(*def, VIR_STORAGE_TYPE_FILE); - if (ctx->parseFileName(fileName, ctx->opaque, &tmp) < 0) + if (ctx->parseFileName(fileName, ctx->opaque, &tmp, false) < 0) goto cleanup; virDomainDiskSetSource(*def, tmp); VIR_FREE(tmp); @@ -2515,7 +2515,7 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptio= nPtr xmlopt, virConfPtr con =20 virDomainDiskSetType(*def, VIR_STORAGE_TYPE_FILE); if (fileName && - ctx->parseFileName(fileName, ctx->opaque, &tmp) < 0) + ctx->parseFileName(fileName, ctx->opaque, &tmp, false) < 0) goto cleanup; virDomainDiskSetSource(*def, tmp); VIR_FREE(tmp); @@ -2977,7 +2977,8 @@ virVMXParseSerial(virVMXContext *ctx, virConfPtr conf= , int port, (*def)->source->type =3D VIR_DOMAIN_CHR_TYPE_FILE; if (ctx->parseFileName(fileName, ctx->opaque, - &(*def)->source->data.file.path) < 0) + &(*def)->source->data.file.path, + false) < 0) goto cleanup; } else if (STRCASEEQ(fileType, "pipe")) { /* @@ -3142,7 +3143,8 @@ virVMXParseParallel(virVMXContext *ctx, virConfPtr co= nf, int port, (*def)->source->type =3D VIR_DOMAIN_CHR_TYPE_FILE; if (ctx->parseFileName(fileName, ctx->opaque, - &(*def)->source->data.file.path) < 0) + &(*def)->source->data.file.path, + false) < 0) goto cleanup; } else { virReportError(VIR_ERR_INTERNAL_ERROR, diff --git a/src/vmx/vmx.h b/src/vmx/vmx.h index e5420c970a4b..550c1264f3b8 100644 --- a/src/vmx/vmx.h +++ b/src/vmx/vmx.h @@ -36,7 +36,10 @@ virDomainXMLOptionPtr virVMXDomainXMLConfInit(virCapsPtr= caps); * Context */ =20 -typedef int (*virVMXParseFileName)(const char *fileName, void *opaque, cha= r **src); +typedef int (*virVMXParseFileName)(const char *fileName, + void *opaque, + char **src, + bool allow_missing); typedef char * (*virVMXFormatFileName)(const char *src, void *opaque); typedef int (*virVMXAutodetectSCSIControllerModel)(virDomainDiskDefPtr def, int *model, void *opaqu= e); diff --git a/tests/vmx2xmltest.c b/tests/vmx2xmltest.c index 7db2edb12c27..3a11dfb41ce8 100644 --- a/tests/vmx2xmltest.c +++ b/tests/vmx2xmltest.c @@ -139,7 +139,8 @@ testCompareHelper(const void *data) static int testParseVMXFileName(const char *fileName, void *opaque G_GNUC_UNUSED, - char **src) + char **src, + bool allow_missing) { g_autofree char *copyOfFileName =3D NULL; char *tmp =3D NULL; @@ -160,6 +161,16 @@ testParseVMXFileName(const char *fileName, return -1; } =20 + if (STREQ(datastoreName, "missing") || + STRPREFIX(directoryAndFileName, "missing")) { + if (allow_missing) + return 0; + + virReportError(VIR_ERR_INTERNAL_ERROR, + "Referenced missing file '%s'", fileName); + return -1; + } + *src =3D g_strdup_printf("[%s] %s", datastoreName, directoryAndFil= eName); } else if (STRPREFIX(fileName, "/")) { /* Found absolute path referencing a file outside a datastore */ --=20 2.30.0 From nobody Sun May 12 15:15:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1609862137; cv=none; d=zohomail.com; s=zohoarc; b=heMaSwjkR6ITWZEGI3kKM5dPbTwjFUToTuNo8omQp7PosXlXTtPlLvHf6FYkiHMm0Tp/QKaSweaHKi1of2c3KkdhVzf2TfCkxxrq/r5BLj697PsIyo3qXBFTW26ABXOA5f2oru1mrqOnZYgPYk+LJuEAJ5rUc8MlY5aW6ML/uV0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609862137; 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=e9RPK3vkKJjChWF4wQ+ez5qgzcYQkDHWwZw4qZN4l1M=; b=FyBo+PSJCe7o+hdONgAstzTY1v4qj1WoBMwt05Z0EFBBR5R90pfc+Id2lb3B1rnabpB7nscxu/pO+SHRMUwOOi2VJUYVbjrwYWH/4OGcpS7SX1/Yf4kQAmPVYYKCM8bFc9re7+fg7jClDKrx3Yu4DCx7AxteQiHWeD33noZNHfU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 160986213791281.40372322781195; Tue, 5 Jan 2021 07:55:37 -0800 (PST) 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-27-RgJLzZj8N-mUP8X_4wCAYg-1; Tue, 05 Jan 2021 10:55:33 -0500 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 9ED87A0CA4; Tue, 5 Jan 2021 15:55:27 +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 73AC719714; Tue, 5 Jan 2021 15:55:27 +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 3D1D45002F; Tue, 5 Jan 2021 15:55:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 105FswEt020995 for ; Tue, 5 Jan 2021 10:54:58 -0500 Received: by smtp.corp.redhat.com (Postfix) id 1960B25274; Tue, 5 Jan 2021 15:54:58 +0000 (UTC) Received: from carol.localdomain (unknown [10.40.193.241]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DE04519714 for ; Tue, 5 Jan 2021 15:54:54 +0000 (UTC) Received: from carol.redhat.com (carol.k8r.cz [127.0.0.1]) by carol.localdomain (Postfix) with ESMTP id E7EC6C2020E for ; Tue, 5 Jan 2021 16:54:47 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1609862136; 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=e9RPK3vkKJjChWF4wQ+ez5qgzcYQkDHWwZw4qZN4l1M=; b=KW1PAJC2KB71oSxjc2NbC3GpXMEbm1L+XX6a0IxNj+HiZg8mx0KEmcjQxS36nJYwky44oP 4CFih+Rfjg/d7WYWLnbg9GRk+E1cbpOfPoHDi+bsgs86wHJCEh4r+Df9C3kVSxfONZMmhF AK+sqFd7h09PV0wnddCltToiz3f2zIw= X-MC-Unique: RgJLzZj8N-mUP8X_4wCAYg-1 From: Martin Kletzander To: libvir-list@redhat.com Subject: [libvirt PATCH v3 6/8] tests: Test vmx files with missing images Date: Tue, 5 Jan 2021 16:54:45 +0100 Message-Id: <9bfb5921c1c20a8942a43ec41d69a333c8e5df4c.1609862070.git.mkletzan@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Clacks-Overhead: GNU Terry Pratchett X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com 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 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Signed-off-by: Martin Kletzander Reviewed-by: Michal Privoznik --- .../vmx2xml-cdrom-ide-file-missing-datastore.vmx | 6 ++++++ tests/vmx2xmldata/vmx2xml-cdrom-ide-file-missing-file.vmx | 6 ++++++ .../vmx2xml-harddisk-ide-file-missing-datastore.vmx | 6 ++++++ .../vmx2xml-harddisk-scsi-file-missing-file.vmx | 7 +++++++ tests/vmx2xmltest.c | 6 ++++++ 5 files changed, 31 insertions(+) create mode 100644 tests/vmx2xmldata/vmx2xml-cdrom-ide-file-missing-datast= ore.vmx create mode 100644 tests/vmx2xmldata/vmx2xml-cdrom-ide-file-missing-file.v= mx create mode 100644 tests/vmx2xmldata/vmx2xml-harddisk-ide-file-missing-dat= astore.vmx create mode 100644 tests/vmx2xmldata/vmx2xml-harddisk-scsi-file-missing-fi= le.vmx diff --git a/tests/vmx2xmldata/vmx2xml-cdrom-ide-file-missing-datastore.vmx= b/tests/vmx2xmldata/vmx2xml-cdrom-ide-file-missing-datastore.vmx new file mode 100644 index 000000000000..8a8de892c88a --- /dev/null +++ b/tests/vmx2xmldata/vmx2xml-cdrom-ide-file-missing-datastore.vmx @@ -0,0 +1,6 @@ +config.version =3D "8" +virtualHW.version =3D "4" +ide0:0.present =3D "true" +ide0:0.deviceType =3D "cdrom-image" +ide0:0.fileName =3D "/vmfs/volumes/missing/cdrom.iso" +displayName =3D "test" diff --git a/tests/vmx2xmldata/vmx2xml-cdrom-ide-file-missing-file.vmx b/te= sts/vmx2xmldata/vmx2xml-cdrom-ide-file-missing-file.vmx new file mode 100644 index 000000000000..6ee2fb553ae4 --- /dev/null +++ b/tests/vmx2xmldata/vmx2xml-cdrom-ide-file-missing-file.vmx @@ -0,0 +1,6 @@ +config.version =3D "8" +virtualHW.version =3D "4" +ide0:0.present =3D "true" +ide0:0.deviceType =3D "cdrom-image" +ide0:0.fileName =3D "/vmfs/volumes/ds/missing.iso" +displayName =3D "test" diff --git a/tests/vmx2xmldata/vmx2xml-harddisk-ide-file-missing-datastore.= vmx b/tests/vmx2xmldata/vmx2xml-harddisk-ide-file-missing-datastore.vmx new file mode 100644 index 000000000000..9d89ce7158a8 --- /dev/null +++ b/tests/vmx2xmldata/vmx2xml-harddisk-ide-file-missing-datastore.vmx @@ -0,0 +1,6 @@ +config.version =3D "8" +virtualHW.version =3D "4" +ide0:0.present =3D "true" +ide0:0.deviceType =3D "ata-hardDisk" +ide0:0.fileName =3D "/vmfs/volumes/missing/harddisk.vmdk" +displayName =3D "test" diff --git a/tests/vmx2xmldata/vmx2xml-harddisk-scsi-file-missing-file.vmx = b/tests/vmx2xmldata/vmx2xml-harddisk-scsi-file-missing-file.vmx new file mode 100644 index 000000000000..d39f657e437f --- /dev/null +++ b/tests/vmx2xmldata/vmx2xml-harddisk-scsi-file-missing-file.vmx @@ -0,0 +1,7 @@ +config.version =3D "8" +virtualHW.version =3D "4" +scsi0.present =3D "true" +scsi0:0.present =3D "true" +scsi0:0.deviceType =3D "scsi-hardDisk" +scsi0:0.fileName =3D "/vmfs/volumes/ds/missing.vmdk" +displayName =3D "test" diff --git a/tests/vmx2xmltest.c b/tests/vmx2xmltest.c index 3a11dfb41ce8..d622e46fd563 100644 --- a/tests/vmx2xmltest.c +++ b/tests/vmx2xmltest.c @@ -247,6 +247,12 @@ mymain(void) DO_TEST("cdrom-ide-raw-auto-detect", "cdrom-ide-raw-auto-detect"); DO_TEST("cdrom-ide-raw-auto-detect", "cdrom-ide-raw-auto-detect"); =20 + DO_TEST_FAIL("cdrom-ide-file-missing-datastore", "cdrom-ide-empty"); + DO_TEST_FAIL("cdrom-ide-file-missing-file", "cdrom-ide-empty"); + + DO_TEST_FAIL("harddisk-ide-file-missing-datastore", "harddisk-ide-file= "); + DO_TEST_FAIL("harddisk-scsi-file-missing-file", "harddisk-scsi-file"); + DO_TEST("floppy-file", "floppy-file"); DO_TEST("floppy-device", "floppy-device"); =20 --=20 2.30.0 From nobody Sun May 12 15:15:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1609862129; cv=none; d=zohomail.com; s=zohoarc; b=hssytwJXgvHfLsnl1CYdXD7XfruIA6Zjzoii4A4kNu5YaQeDdkparL3VQ2vhDO105czXLrT06xDw/GGy+GFAMfyf8wpTj2sQvNTX8Ihh/lGq2IRPvkDlcdLvom1ViudWJgEOWgBJ+shhmeCgsyb3zC2vhIq+PlrfHqkCj+2BSns= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609862129; 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=tZ0XE3YGxiiXKQjWZ8lPWP463UttXTKJO0ob77eodxU=; b=gw+RAkvp/PjpuUoGGjyhLSWzIr2b+u02R+6zq4t/RAgY3LY6ksREWB2zbSBTimvtiBFS3DmU1p8ojbi3HKHXMCxKs5A1/MWAthlbkMjJnwJAgusAwyR7NtaSoynUcIAsmzG+y7uUf3MW/OssSNV0DTOuoXvasYTRTuzA6wYprlk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1609862129780529.1214587015534; Tue, 5 Jan 2021 07:55:29 -0800 (PST) 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-228-6PYgxzCkNfiCxosHcyJgVg-1; Tue, 05 Jan 2021 10:55:26 -0500 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 D842CA0CAC; Tue, 5 Jan 2021 15:55:20 +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 ABAC919713; Tue, 5 Jan 2021 15:55:20 +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 706B35002F; Tue, 5 Jan 2021 15:55:20 +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 105Fsvwm020984 for ; Tue, 5 Jan 2021 10:54:57 -0500 Received: by smtp.corp.redhat.com (Postfix) id 72D335D9D7; Tue, 5 Jan 2021 15:54:57 +0000 (UTC) Received: from carol.localdomain (unknown [10.40.193.241]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 45CFF5D9D2 for ; Tue, 5 Jan 2021 15:54:54 +0000 (UTC) Received: from carol.redhat.com (carol.k8r.cz [127.0.0.1]) by carol.localdomain (Postfix) with ESMTP id E87F4C20210 for ; Tue, 5 Jan 2021 16:54:47 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1609862128; 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=tZ0XE3YGxiiXKQjWZ8lPWP463UttXTKJO0ob77eodxU=; b=Zh8rEQhg9hbj/IfQZJ+G2+TN93XelS5Ig6CwonkmEZiNVkfDhu6Wpdh/Pcvfe+ivGZcan6 GRTT2Zo6Tq4niRDfz4fhLP50Ec5qKB1xdMe4vRq+aqLtB+nfDARGBDeye0kM7CF+1gJJWb 68LotRjEeXBtacoNoAEclGc4qEoJn5A= X-MC-Unique: 6PYgxzCkNfiCxosHcyJgVg-1 From: Martin Kletzander To: libvir-list@redhat.com Subject: [libvirt PATCH v3 7/8] esx: Handle missing images in esxParseVMXFileName Date: Tue, 5 Jan 2021 16:54:46 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Clacks-Overhead: GNU Terry Pratchett X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com 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 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Signed-off-by: Martin Kletzander Reviewed-by: Michal Privoznik --- src/esx/esx_driver.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c index dde51688f72f..0271f81a5655 100644 --- a/src/esx/esx_driver.c +++ b/src/esx/esx_driver.c @@ -129,7 +129,7 @@ static int esxParseVMXFileName(const char *fileName, void *opaque, char **out, - bool allow_missing G_GNUC_UNUSED) + bool allow_missing) { esxVMX_Data *data =3D opaque; esxVI_String *propertyNameList =3D NULL; @@ -223,9 +223,13 @@ esxParseVMXFileName(const char *fileName, } =20 if (!datastoreList) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("File name '%s' refers to non-existing datast= ore '%s'"), - fileName, datastoreName); + if (allow_missing) { + ret =3D 0; + } else { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("File name '%s' refers to non-existing da= tastore '%s'"), + fileName, datastoreName); + } goto cleanup; } =20 --=20 2.30.0 From nobody Sun May 12 15:15:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1609862136; cv=none; d=zohomail.com; s=zohoarc; b=TOWhFrjn9gXDq1qdUX9MKmnNY67Z9q2pAPxOVMdUP5DnHWRC+4LbnrHy6oQXG4FEPzq8hWUCF6LlSMzIyZw4ZRPZ+qVXMM7MuIidiO78Lt8rjWoQa4P7dbCTRfpzEFuVW8QrXnuU0BscosOowquY+JN4T5Y+bn4giKrU4MZIKfE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609862136; 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=cGZE3RyOoogGmkuVbGAn5P/MQ3OOceQfHPfE8uFHh+M=; b=Q7aNVW86yRjJD2306Q1BWeM0xhjeIriLQ/5gx7YgA7HyS8Y50CeXPNItgkLoWZdmhuHGZkG1rZLIZGI6HV6YFPUkffkSMhjtbFlJ2Qk36LKV7Tv0eSn3rw7XiPwFsm46mO7xC8IHTkI5/KG6glzIuH3ZuVs4c6hLUxaBuWWoTSQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1609862136536978.9866646727138; Tue, 5 Jan 2021 07:55:36 -0800 (PST) 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-550-azJEiCsqMz6VUoJhiZMAAA-1; Tue, 05 Jan 2021 10:55:32 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D231B18C89E1; Tue, 5 Jan 2021 15:55:24 +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 B1AB860BFA; Tue, 5 Jan 2021 15:55:24 +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 7DB521809CA1; Tue, 5 Jan 2021 15:55:24 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 105FswdG020994 for ; Tue, 5 Jan 2021 10:54:58 -0500 Received: by smtp.corp.redhat.com (Postfix) id 1904A1F471; Tue, 5 Jan 2021 15:54:58 +0000 (UTC) Received: from carol.localdomain (unknown [10.40.193.241]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DE0F11F46F for ; Tue, 5 Jan 2021 15:54:54 +0000 (UTC) Received: from carol.redhat.com (carol.k8r.cz [127.0.0.1]) by carol.localdomain (Postfix) with ESMTP id E8F92C20212 for ; Tue, 5 Jan 2021 16:54:47 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1609862135; 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=cGZE3RyOoogGmkuVbGAn5P/MQ3OOceQfHPfE8uFHh+M=; b=KR5r8jiHwNfdPFCr4lrXIuzIhJEaJtwRL8odtrfVpcXz4UEJsnjkkbEkqytSs2ZhFoB9jv 6YeQgUWw0FOpSTQ4SekU07PGGbO4j2TNiPRx4IutTs9o5aPB6tvqYu/UHQic/k0/ZJeUJp lCjt73xnd6KP/X2F6+EyX4ZDNlwI5Xs= X-MC-Unique: azJEiCsqMz6VUoJhiZMAAA-1 From: Martin Kletzander To: libvir-list@redhat.com Subject: [libvirt PATCH v3 8/8] vmx: Treat missing cdrom-image as empty drive Date: Tue, 5 Jan 2021 16:54:47 +0100 Message-Id: <63f05c25f54c2409db775b006f0823d9e5b673a4.1609862070.git.mkletzan@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Clacks-Overhead: GNU Terry Pratchett X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com 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.79 on 10.5.11.12 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) Content-Type: text/plain; charset="utf-8" This is perfectly valid in VMWare and the VM just boots with an empty drive= . We used to just skip the whole drive before, but since we changed how we parse empty cdrom drives this results in an error. Make it behave more closer to VMWare. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=3D1903953 Signed-off-by: Martin Kletzander Reviewed-by: Michal Privoznik --- src/vmx/vmx.c | 2 +- tests/vmx2xmltest.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c index aa5d1d4eedea..56318fc8b285 100644 --- a/src/vmx/vmx.c +++ b/src/vmx/vmx.c @@ -2448,7 +2448,7 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptio= nPtr xmlopt, virConfPtr con } =20 virDomainDiskSetType(*def, VIR_STORAGE_TYPE_FILE); - if (ctx->parseFileName(fileName, ctx->opaque, &tmp, false) < 0) + if (ctx->parseFileName(fileName, ctx->opaque, &tmp, true) < 0) goto cleanup; virDomainDiskSetSource(*def, tmp); VIR_FREE(tmp); diff --git a/tests/vmx2xmltest.c b/tests/vmx2xmltest.c index d622e46fd563..11739e6f3f51 100644 --- a/tests/vmx2xmltest.c +++ b/tests/vmx2xmltest.c @@ -247,8 +247,8 @@ mymain(void) DO_TEST("cdrom-ide-raw-auto-detect", "cdrom-ide-raw-auto-detect"); DO_TEST("cdrom-ide-raw-auto-detect", "cdrom-ide-raw-auto-detect"); =20 - DO_TEST_FAIL("cdrom-ide-file-missing-datastore", "cdrom-ide-empty"); - DO_TEST_FAIL("cdrom-ide-file-missing-file", "cdrom-ide-empty"); + DO_TEST("cdrom-ide-file-missing-datastore", "cdrom-ide-empty"); + DO_TEST("cdrom-ide-file-missing-file", "cdrom-ide-empty"); =20 DO_TEST_FAIL("harddisk-ide-file-missing-datastore", "harddisk-ide-file= "); DO_TEST_FAIL("harddisk-scsi-file-missing-file", "harddisk-scsi-file"); --=20 2.30.0