From nobody Wed May 15 01:56:52 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=1608568007; cv=none; d=zohomail.com; s=zohoarc; b=dTYa+6jJYOooqSDQy50r3uit7XU9RrphDGVLNRyT+jtqlY5u165sTdsGZuItRCMBOLEXlSDyhYaBwGJK9Py5q0DcbTV/zhhtuU1a0ziLYmhUjdif4xamUr2BBjzfF+zQbI6iR7Zrr1nVgum5PVcN53UWiohPSYsCN6BMc7z7aeI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608568007; 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=Z8bGHxvkYFIf8OK2etOxAkB2AmEhAIucX9jWhQ0yKuQ=; b=WvWM4rINxAQ6aq+JwY1uztwJcfn3fQ/hyFzMcJNBQmHJW/lHeSn9EHcq+sJXL/WL2d1M1zMFWT6uK3Y8HapPqGJoPD7ewlmzzBPiTPO1ai/1sdUJlkTSRwNv47Uao8AaIW9Od7GD1u8YZueeofe2U6lpmndVl6Y7aGmnbm5pXtQ= 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 160856800763562.62613002470823; Mon, 21 Dec 2020 08:26:47 -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-523-H71vxe8FMIu3dhoUHhx1ng-1; Mon, 21 Dec 2020 11:21:43 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 34B6A9CC3F; Mon, 21 Dec 2020 16:21:34 +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 11BE26F96F; Mon, 21 Dec 2020 16:21:34 +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 CB43F5002C; Mon, 21 Dec 2020 16:21:33 +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 0BLGJMnw010609 for ; Mon, 21 Dec 2020 11:19:22 -0500 Received: by smtp.corp.redhat.com (Postfix) id 974AE5D9D3; Mon, 21 Dec 2020 16:19:22 +0000 (UTC) Received: from carol.localdomain (ovpn-117-30.ams2.redhat.com [10.36.117.30]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 44A325D9D7 for ; Mon, 21 Dec 2020 16:19:19 +0000 (UTC) Received: from carol.redhat.com (carol.k8r.cz [127.0.0.1]) by carol.localdomain (Postfix) with ESMTP id C58A4C227B1 for ; Mon, 21 Dec 2020 17:19:17 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608567706; 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=Z8bGHxvkYFIf8OK2etOxAkB2AmEhAIucX9jWhQ0yKuQ=; b=DYtVSC1+150Plv+nnJpVLR2YYLMgnV0HKuRJoMzpoUBpp7vzH/fEZ1zBrUillWaxRP0gj3 h9MO8mEK8aakvYV8efE9koAoIebzkR9I+2Jnx+pPbiBgNhHzfG3+Jq64hWvyvq35bm21ld FCHtu+g1iJrw4R9ep7ov8MgSL7sqyh8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608568006; 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=Z8bGHxvkYFIf8OK2etOxAkB2AmEhAIucX9jWhQ0yKuQ=; b=GL2OFg9imVmwQsG8mwG6B6aLU6+vuCLtECHZvGvL2BXfTegdOMuyLCK+Ez3ZCYshOIt8jk 6MPKkTzmxVmmqikRdCI71ZSW72GtqcxPbek0TPAwEtOwmlVpNzQLUVayitJZ/0GrgjKDtH 3Cj8TUpREWr3SodzbAlmrb1FmAwq1IY= X-MC-Unique: H71vxe8FMIu3dhoUHhx1ng-1 From: Martin Kletzander To: libvir-list@redhat.com Subject: [libvirt PATCH v2 1/5] esx: Unindent unnecessary conditional branch Date: Mon, 21 Dec 2020 17:19:13 +0100 Message-Id: <8ef595e1e6ab812687e0280e1f4cbc638892d455.1608567530.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.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.79 on 10.5.11.13 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) (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 --- 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.29.2 From nobody Wed May 15 01:56:52 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=1608567941; cv=none; d=zohomail.com; s=zohoarc; b=MdY2PhrMmaz/LY9SZofOfcuBo39khGUv0VyNXuwDmLy5PJrF1reyroSh719s3iIe2naCd6xNl3aV44BRvHsMsWLM4rOGymdbuVWBD7QjgSYMuvHAMViwXK5k7CoUcmtdOuYMsSnMsFw6eT8bnlz2dsFnypjHrMcPpzs4B2VTejI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608567941; 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=PCc5XNsi2jzet2OuVP8SVM7DlKRAefRmjRsRnxP68cw=; b=nCSZzo0NyAbh1KWl8W8n2GM9Uf0t7kdArdFsUOUhnkdH4AlffUP/tqRqtCmzXssBrLI0AMes/6cNBGKtbAqyT5fkS1tuP4/wu9eWaS3uSR7PNvEjB9yhpXa3miYar4QiNjdkWHCDdg5u+DyGn/JKuGW+vNuNB/Fi415QYwFPQ2Q= 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 1608567941418418.38526675099274; Mon, 21 Dec 2020 08:25:41 -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-519-PK40Rel9MTeDxFgD6A6wug-1; Mon, 21 Dec 2020 11:21:31 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EDF6F1922985; Mon, 21 Dec 2020 16:21:12 +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 2D8215D9CA; Mon, 21 Dec 2020 16:21:10 +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 2B6F6180954D; Mon, 21 Dec 2020 16:21:05 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0BLGJM9G010598 for ; Mon, 21 Dec 2020 11:19:22 -0500 Received: by smtp.corp.redhat.com (Postfix) id 31DA960C61; Mon, 21 Dec 2020 16:19:22 +0000 (UTC) Received: from carol.localdomain (ovpn-117-30.ams2.redhat.com [10.36.117.30]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 059C060C0F for ; Mon, 21 Dec 2020 16:19:19 +0000 (UTC) Received: from carol.redhat.com (carol.k8r.cz [127.0.0.1]) by carol.localdomain (Postfix) with ESMTP id C6759C227B4 for ; Mon, 21 Dec 2020 17:19:17 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608567695; 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=PCc5XNsi2jzet2OuVP8SVM7DlKRAefRmjRsRnxP68cw=; b=WVuneDEyWfYpMKNTG07n7RXYqBBjZOTCcADNPimUst0oeWrz0zWHP6pwKvNg1/i4uK/cFe vmiwqd51vsXJWXGCjtwMOelNGpvliU8JGM5VZt8j3PsU46a1c6mCLXr0L+bNDc+XdRO3h3 P5/+WQrim3r1/7DJwUP+Sm0/xv8CrBw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608567939; 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=PCc5XNsi2jzet2OuVP8SVM7DlKRAefRmjRsRnxP68cw=; b=hG6qSba45u+My0rAAXMw/5Fzm3apAMyo2gdV9vHZrB2VEy3ATjuEfHirQZyaQzxtZhUuK/ lPxkeS/c0zQ6VvbdAqNh4gIZls7g1OuLe5ivfBs1u21ebs0keqYgKGpzCy5bGH6gg+cCs/ 1DgmxYDDK/p7+XBOuVMTy+aGvLKx6Xk= X-MC-Unique: PK40Rel9MTeDxFgD6A6wug-1 From: Martin Kletzander To: libvir-list@redhat.com Subject: [libvirt PATCH v2 2/5] tests: Use g_autofree in testParseVMXFileName Date: Mon, 21 Dec 2020 17:19:14 +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.12 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.14 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) (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 --- 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.29.2 From nobody Wed May 15 01:56:52 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=1608567772; cv=none; d=zohomail.com; s=zohoarc; b=byEaBCksqYwxhKHpbesoIkE0Ne4dbNAiLNJkly2MA2d2Ri6VMB4L670I+unxmgE4RvXuQb4yskm/WqKRTzkt15nGGotNV6GcsVTHOEs/9/bOdz4mccsjDtXt2ZzVqUa9kqLRn27Wtq8uIsgj3uix71AOB7cU+QwbZ028N18LRTc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608567772; 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=ddIr9ofPHz5hJ/3ssM3Lw1EX6P49xMYAg1K7Yk5hUxI=; b=hdDiUunC+NLmfNutQv+Cx8wr2lgiHdMGkKXWws6TIaz1ozQk/WRfkFKa8dzfI0lrghtzHDyXfO+UAh14txmpvudkIaqtIarx92dhscBdVGjYghnUbwn7LjlRAH+JsMId5s82SMdZjQ75C8uhNZzyZZGGGF+LvlUHXIWPenioboY= 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 1608567772435960.8639560228861; Mon, 21 Dec 2020 08:22:52 -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-246-EZxkwHZ3NAWDUsmckL7MwA-1; Mon, 21 Dec 2020 11:21:42 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3EB3A8018A9; Mon, 21 Dec 2020 16:21:37 +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 EF6B05D9E2; Mon, 21 Dec 2020 16:21:36 +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 B360D5002C; Mon, 21 Dec 2020 16:21:36 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0BLGJMxE010614 for ; Mon, 21 Dec 2020 11:19:22 -0500 Received: by smtp.corp.redhat.com (Postfix) id B1FEE5C1D1; Mon, 21 Dec 2020 16:19:22 +0000 (UTC) Received: from carol.localdomain (ovpn-117-30.ams2.redhat.com [10.36.117.30]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5F9865C728 for ; Mon, 21 Dec 2020 16:19:19 +0000 (UTC) Received: from carol.redhat.com (carol.k8r.cz [127.0.0.1]) by carol.localdomain (Postfix) with ESMTP id C75ECC227B5 for ; Mon, 21 Dec 2020 17:19:17 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608567771; 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=ddIr9ofPHz5hJ/3ssM3Lw1EX6P49xMYAg1K7Yk5hUxI=; b=Cbq7DV+RWL2pEyHnj0hjNO9clfRlMuy3Ve1hLSwhc/Y0gbaJnLVxiZe1jtN10W3Ct6YI9A c2D55KezQ6/d5jbdZSTCKeT7D4svomBdtzMLUfzu0yeMxIlLxTRXKR78aJ6XD8anKU+uXw BbNx4dTsJ5ldQgVB63ArjA0Nj05v+DU= X-MC-Unique: EZxkwHZ3NAWDUsmckL7MwA-1 From: Martin Kletzander To: libvir-list@redhat.com Subject: [libvirt PATCH v2 3/5] vmx: Make virVMXParseFileName return an integer Date: Mon, 21 Dec 2020 17:19:15 +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.16 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.14 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 --- src/esx/esx_driver.c | 31 ++++++++++++++++++------------- src/vmware/vmware_conf.c | 10 +++++----- src/vmx/vmx.c | 21 ++++++++++----------- src/vmx/vmx.h | 2 +- tests/vmx2xmltest.c | 19 ++++++++++--------- 5 files changed, 44 insertions(+), 39 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..c90cb10faf7c 100644 --- a/src/vmware/vmware_conf.c +++ b/src/vmware/vmware_conf.c @@ -507,11 +507,11 @@ vmwareExtractPid(const char * vmxPath) return pid_value; } =20 -char * -vmwareCopyVMXFileName(const char *datastorePath, void *opaque G_GNUC_UNUSE= D) +int +vmwareCopyVMXFileName(const char *datastorePath, void *opaque G_GNUC_UNUSE= D, + char **out) { - char *path; + *out =3D g_strdup(datastorePath); =20 - path =3D g_strdup(datastorePath); - return path; + return *out ? 0 : -1; } diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c index b86dbe9ca267..b2b2244415a1 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 (!(tmp =3D ctx->parseFileName(fileName, ctx->opaque))) + if (ctx->parseFileName(fileName, ctx->opaque, &tmp) < 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 (!(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..412b201f0242 100644 --- a/tests/vmx2xmltest.c +++ b/tests/vmx2xmltest.c @@ -127,15 +127,16 @@ 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; =20 if (STRPREFIX(fileName, "/vmfs/volumes/")) { /* Found absolute path referencing a file inside a datastore */ @@ -145,22 +146,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.29.2 From nobody Wed May 15 01:56:52 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=1608567701; cv=none; d=zohomail.com; s=zohoarc; b=lMbm0zRRByJl4nB9l512pH0Ly7ARH81xAJb1xnYf4Cwaq5mndAyH8wde7IA+P2w1SWoXD800NP/aimYEhw9IqALCB/lhFwAedcT1MzpzfCFeGXn9JD3cvOBQI02aY7lyTjRKsXalUAW/j7B6xh9K0CWWUoQHjraYVLvOfHExtok= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608567701; 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=g9pJ5YARsnuAH0jBHzsW30S4ae0//5VqAHHZzwIoUMI=; b=n7LJEyE2DcObsYFUv27vTQuFUBC2tUobVhfXqqdrume+90JJNifTEfzkWjT+ndal7nbMYyQfe+OWMPexZSQs059DN5ud9AfT8EiN9qKGljyl6Hp7Vg9Y3asBp44jPOjhatrFCfT4YrZjlQ20OBV+bSNCDtPrTF4c7j1LKOuPI7o= 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 1608567701079248.54079694323843; Mon, 21 Dec 2020 08:21:41 -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-496-gPXt1XcwPt-egrSQTj-TJg-1; Mon, 21 Dec 2020 11:21:33 -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 EED928914F7; Mon, 21 Dec 2020 16:21:16 +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 916B960C0F; Mon, 21 Dec 2020 16:21:16 +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 E85AB4BB7B; Mon, 21 Dec 2020 16:21:15 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0BLGJMOr010615 for ; Mon, 21 Dec 2020 11:19:22 -0500 Received: by smtp.corp.redhat.com (Postfix) id B24475C26D; Mon, 21 Dec 2020 16:19:22 +0000 (UTC) Received: from carol.localdomain (ovpn-117-30.ams2.redhat.com [10.36.117.30]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5F6155C6C1 for ; Mon, 21 Dec 2020 16:19:19 +0000 (UTC) Received: from carol.redhat.com (carol.k8r.cz [127.0.0.1]) by carol.localdomain (Postfix) with ESMTP id C9172C227BB for ; Mon, 21 Dec 2020 17:19:17 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608567696; 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=g9pJ5YARsnuAH0jBHzsW30S4ae0//5VqAHHZzwIoUMI=; b=BZpaVp5W8GiSmXr6N+GJdSEy0YOHya6kk7jOQpX3RvklCew/8KvksEwT+vo7wpQmo9q0TV mUY/WuzeC2W3VRcoLuGqqhrdaI/61JS/9M54XUvy6btYlyqlay5CuZsN0Gabq1HrZ4tg4u rltBp4fiP7hwZxzPhSNe338ThE7H0JM= X-MC-Unique: gPXt1XcwPt-egrSQTj-TJg-1 From: Martin Kletzander To: libvir-list@redhat.com Subject: [libvirt PATCH v2 4/5] vmx: Allow missing cdrom image file in virVMXParseFileName Date: Mon, 21 Dec 2020 17:19:16 +0100 Message-Id: <5a37312b9dfc0949b3c7a1ea93060f23137778f7.1608567530.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.16 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 --- src/esx/esx_driver.c | 13 +++++++++---- src/vmware/vmware_conf.c | 2 +- src/vmx/vmx.c | 12 +++++++----- src/vmx/vmx.h | 5 ++++- tests/vmx2xmltest.c | 13 ++++++++++++- 5 files changed, 33 insertions(+), 12 deletions(-) diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c index 86d5396147a3..0271f81a5655 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) { esxVMX_Data *data =3D opaque; esxVI_String *propertyNameList =3D NULL; @@ -222,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 diff --git a/src/vmware/vmware_conf.c b/src/vmware/vmware_conf.c index c90cb10faf7c..4b0832f50b3c 100644 --- a/src/vmware/vmware_conf.c +++ b/src/vmware/vmware_conf.c @@ -509,7 +509,7 @@ vmwareExtractPid(const char * vmxPath) =20 int vmwareCopyVMXFileName(const char *datastorePath, void *opaque G_GNUC_UNUSE= D, - char **out) + char **out, bool allow_missing G_GNUC_UNUSED) { *out =3D g_strdup(datastorePath); =20 diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c index b2b2244415a1..4d098a5fa4d6 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, true) < 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 412b201f0242..116d729a0147 100644 --- a/tests/vmx2xmltest.c +++ b/tests/vmx2xmltest.c @@ -130,7 +130,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; @@ -149,6 +150,16 @@ testParseVMXFileName(const char *fileName, return -1; } =20 + if (STREQ(datastoreName, "missing") || + STREQ(directoryAndFileName, "missing")) { + if (allow_missing) + return 0; + + virReportError(VIR_ERR_INTERNAL_ERROR, + "Missing file name '%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.29.2 From nobody Wed May 15 01:56:52 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=1608567703; cv=none; d=zohomail.com; s=zohoarc; b=ZGoir+2O8Ayfe8pDHbeYtX53HXXP731wT96N14Orw7HdpDVegwiiX5sRb/CA3D88XsbzrZSff/z/C2aWy208Htk3kJfUimCM4c6QUu0LIOEL16RcS1ii8GSCtlyN46mRbAHjpgEM0pmxgzGukxuRUHrFj+XLlJK4OPNihH4eEA4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608567703; 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=FtbdUrZA8Nl+qYgNjaS2OY7h0JoDC+jVzAdQNZzsCGo=; b=h7DkMXozCLZqG6iC/9LWch5oDzT99fQXuPK06zCHpQZ+rBK21INIwpx+lBPiZMMPtGRq8wKPMVbvF9+dVuLwtj0xGz7tOpb+8lyRAtyrB4msFTaTx8qMFFo7OTlbpfqkgf93a5UL5ohcmiAuNje/bYlleiOkB3BWN45+RiDYkbE= 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 1608567702792325.4792789933143; Mon, 21 Dec 2020 08:21:42 -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-235-ak4D2g4LM0yPlTngesD1xg-1; Mon, 21 Dec 2020 11:21:37 -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 553089CC1F; Mon, 21 Dec 2020 16:21:30 +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 312365C3F8; Mon, 21 Dec 2020 16:21:30 +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 E867785F0; Mon, 21 Dec 2020 16:21:29 +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 0BLGJTGx010671 for ; Mon, 21 Dec 2020 11:19:29 -0500 Received: by smtp.corp.redhat.com (Postfix) id 40BCC6E522; Mon, 21 Dec 2020 16:19:29 +0000 (UTC) Received: from carol.localdomain (ovpn-117-30.ams2.redhat.com [10.36.117.30]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 148F36F96F for ; Mon, 21 Dec 2020 16:19:23 +0000 (UTC) Received: from carol.redhat.com (carol.k8r.cz [127.0.0.1]) by carol.localdomain (Postfix) with ESMTP id CA540C227BC for ; Mon, 21 Dec 2020 17:19:17 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608567700; 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=FtbdUrZA8Nl+qYgNjaS2OY7h0JoDC+jVzAdQNZzsCGo=; b=Ua+uGP9pfjVGPb6MlfvOgso790rd+TjOpPA7u79sbKVRWZzCCN8gr+NTon4JG9IPt0+zkb uJ3qFl2klbcq9ullysse2402w4cYd2u5GMXlmCaZ9K0bKU44IM4wrn2ii5tYrLGH9c+Tya Q5kXQGZ6ksDNVIzv4s9yV/17poj0HjI= X-MC-Unique: ak4D2g4LM0yPlTngesD1xg-1 From: Martin Kletzander To: libvir-list@redhat.com Subject: [libvirt PATCH v2 5/5] vmx: Treat missing cdrom-image as empty drive Date: Mon, 21 Dec 2020 17:19:17 +0100 Message-Id: <772c0ad64ff48e1f7d90a7ef8cb9eba6cece761b.1608567530.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.13 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" 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 --- src/vmx/vmx.c | 2 +- tests/vmx2xmldata/vmx2xml-cdrom-ide-missing.vmx | 6 ++++++ tests/vmx2xmltest.c | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 tests/vmx2xmldata/vmx2xml-cdrom-ide-missing.vmx diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c index 4d098a5fa4d6..2c631e32e7df 100644 --- a/src/vmx/vmx.c +++ b/src/vmx/vmx.c @@ -2447,10 +2447,10 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOpt= ionPtr xmlopt, virConfPtr con goto cleanup; } =20 - virDomainDiskSetType(*def, VIR_STORAGE_TYPE_FILE); if (ctx->parseFileName(fileName, ctx->opaque, &tmp, true) < 0) goto cleanup; virDomainDiskSetSource(*def, tmp); + virDomainDiskSetType(*def, VIR_STORAGE_TYPE_FILE); VIR_FREE(tmp); } else if (deviceType && STRCASEEQ(deviceType, "atapi-cdrom")) { virDomainDiskSetType(*def, VIR_STORAGE_TYPE_BLOCK); diff --git a/tests/vmx2xmldata/vmx2xml-cdrom-ide-missing.vmx b/tests/vmx2xm= ldata/vmx2xml-cdrom-ide-missing.vmx new file mode 100644 index 000000000000..bef1ebbba272 --- /dev/null +++ b/tests/vmx2xmldata/vmx2xml-cdrom-ide-missing.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/dir/file.iso" +displayName =3D "test" diff --git a/tests/vmx2xmltest.c b/tests/vmx2xmltest.c index 116d729a0147..624ee14ece12 100644 --- a/tests/vmx2xmltest.c +++ b/tests/vmx2xmltest.c @@ -232,6 +232,7 @@ mymain(void) DO_TEST("cdrom-ide-raw-device", "cdrom-ide-raw-device"); DO_TEST("cdrom-ide-raw-auto-detect", "cdrom-ide-raw-auto-detect"); DO_TEST("cdrom-ide-raw-auto-detect", "cdrom-ide-raw-auto-detect"); + DO_TEST("cdrom-ide-missing", "cdrom-ide-empty"); =20 DO_TEST("floppy-file", "floppy-file"); DO_TEST("floppy-device", "floppy-device"); --=20 2.29.2