From nobody Mon Feb 9 10:33:23 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1617285298; cv=none; d=zohomail.com; s=zohoarc; b=EFCHmjVho9AAYRu0rjCiAF0h67kEoyy6BDxOZl9MiiUuiHC4siLw9viNtUWP6PYBsfcfZuZq9Z4i1YuN3o0bdO0vgqqGga9f837yi6k6/bJNaifxaJXPjfQT8HoIs6nPSl5mKYhCO8twGbYG805d6mg/afGmFp1Y1AY0nNKS01Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617285298; 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=BjRgYi0KjjWLwnpEOgORojgAlWopjXw4Fx8X5UVRcRQ=; b=hwnCU2Ta0TcAD4CsifLrlPigoPM34HLqKDDShtKUfBEWz1wXpgk5yjas8QBdXMKXUCzyNKuEl25k6pPCxgurqKU2M2WRej2HbGjb5o3KTeBdj2kqSarLpdoKBeAvd6qpNuldtkZE2yTT6TD4JW/t2MY35qd5nJEBvzM0laW1L0A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1617285298142284.9716143713159; Thu, 1 Apr 2021 06:54:58 -0700 (PDT) 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-88-r7YRgl03MGi5TmKbLhE2EQ-1; Thu, 01 Apr 2021 09:54:53 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 18BE21026F73; Thu, 1 Apr 2021 13:54:38 +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 E0A715D6B1; Thu, 1 Apr 2021 13:54:37 +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 9A6E5180B452; Thu, 1 Apr 2021 13:54:37 +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 131Dr268023091 for ; Thu, 1 Apr 2021 09:53:02 -0400 Received: by smtp.corp.redhat.com (Postfix) id 548D95C238; Thu, 1 Apr 2021 13:53:02 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.33]) by smtp.corp.redhat.com (Postfix) with ESMTP id A90605C1A1 for ; Thu, 1 Apr 2021 13:52:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617285297; 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=BjRgYi0KjjWLwnpEOgORojgAlWopjXw4Fx8X5UVRcRQ=; b=Zu/dbvAX1Nfel3Zdc5QZX+x/BseKzfogewX4YFdhINxjahL/nDzwaOaP8LhoNpwfvqk+vv vNzwWZXIkG+pzVy+Pz4Z7fN2X58UGncUHLQPnImlAqowzCQcePxtdXYSeBzGrXmQ8zi9mB 5o5tqBp5J5Djtiuc2CflUv7/jOMTGdk= X-MC-Unique: r7YRgl03MGi5TmKbLhE2EQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 07/39] Remove virStorageFileCanonicalizePath Date: Thu, 1 Apr 2021 15:52:06 +0200 Message-Id: <9f2e44de4589bff9839369eb141036c4f088ecdb.1617285119.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 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.15 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: Peter Krempa --- src/libvirt_private.syms | 1 - src/util/virstoragefile.c | 210 -------------------------------------- src/util/virstoragefile.h | 8 -- 3 files changed, 219 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 62ccda467f..9208db2056 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3231,7 +3231,6 @@ virSocketAddrSetPort; # util/virstoragefile.h -virStorageFileCanonicalizePath; virStorageFileGetNPIVKey; virStorageFileGetSCSIKey; virStorageFileParseBackingStoreStr; diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 9df891b57c..e6bc723d1e 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -214,213 +214,3 @@ virStorageFileParseBackingStoreStr(const char *str, *chainIndex =3D idx; return 0; } - - -static char * -virStorageFileCanonicalizeFormatPath(char **components, - size_t ncomponents, - bool beginSlash, - bool beginDoubleSlash) -{ - g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; - size_t i; - char *ret =3D NULL; - - if (beginSlash) - virBufferAddLit(&buf, "/"); - - if (beginDoubleSlash) - virBufferAddLit(&buf, "/"); - - for (i =3D 0; i < ncomponents; i++) { - if (i !=3D 0) - virBufferAddLit(&buf, "/"); - - virBufferAdd(&buf, components[i], -1); - } - - /* if the output string is empty just return an empty string */ - if (!(ret =3D virBufferContentAndReset(&buf))) - ret =3D g_strdup(""); - - return ret; -} - - -static int -virStorageFileCanonicalizeInjectSymlink(const char *path, - size_t at, - char ***components, - size_t *ncomponents) -{ - char **tmp =3D NULL; - char **next; - size_t ntmp =3D 0; - int ret =3D -1; - - if (!(tmp =3D virStringSplitCount(path, "/", 0, &ntmp))) - goto cleanup; - - /* prepend */ - for (next =3D tmp; *next; next++) { - if (VIR_INSERT_ELEMENT(*components, at, *ncomponents, *next) < 0) - goto cleanup; - - at++; - } - - ret =3D 0; - - cleanup: - virStringListFreeCount(tmp, ntmp); - return ret; -} - - -char * -virStorageFileCanonicalizePath(const char *path, - virStorageFileSimplifyPathReadlinkCallback = cb, - void *cbdata) -{ - GHashTable *cycle =3D NULL; - bool beginSlash =3D false; - bool beginDoubleSlash =3D false; - char **components =3D NULL; - size_t ncomponents =3D 0; - size_t i =3D 0; - size_t j =3D 0; - int rc; - char *ret =3D NULL; - g_autofree char *linkpath =3D NULL; - g_autofree char *currentpath =3D NULL; - - if (path[0] =3D=3D '/') { - beginSlash =3D true; - - if (path[1] =3D=3D '/' && path[2] !=3D '/') - beginDoubleSlash =3D true; - } - - if (!(cycle =3D virHashNew(NULL))) - goto cleanup; - - if (!(components =3D virStringSplitCount(path, "/", 0, &ncomponents))) - goto cleanup; - - j =3D 0; - while (j < ncomponents) { - /* skip slashes */ - if (STREQ(components[j], "")) { - VIR_FREE(components[j]); - VIR_DELETE_ELEMENT(components, j, ncomponents); - continue; - } - j++; - } - - while (i < ncomponents) { - /* skip '.'s unless it's the last one remaining */ - if (STREQ(components[i], ".") && - (beginSlash || ncomponents > 1)) { - VIR_FREE(components[i]); - VIR_DELETE_ELEMENT(components, i, ncomponents); - continue; - } - - /* resolve changes to parent directory */ - if (STREQ(components[i], "..")) { - if (!beginSlash && - (i =3D=3D 0 || STREQ(components[i - 1], ".."))) { - i++; - continue; - } - - VIR_FREE(components[i]); - VIR_DELETE_ELEMENT(components, i, ncomponents); - - if (i !=3D 0) { - VIR_FREE(components[i - 1]); - VIR_DELETE_ELEMENT(components, i - 1, ncomponents); - i--; - } - - continue; - } - - /* check if the actual path isn't resulting into a symlink */ - if (!(currentpath =3D virStorageFileCanonicalizeFormatPath(compone= nts, - i + 1, - beginSlas= h, - beginDoub= leSlash))) - goto cleanup; - - if ((rc =3D cb(currentpath, &linkpath, cbdata)) < 0) - goto cleanup; - - if (rc =3D=3D 0) { - if (virHashLookup(cycle, currentpath)) { - virReportSystemError(ELOOP, - _("Failed to canonicalize path '%s'")= , path); - goto cleanup; - } - - if (virHashAddEntry(cycle, currentpath, (void *) 1) < 0) - goto cleanup; - - if (linkpath[0] =3D=3D '/') { - /* kill everything from the beginning including the actual= component */ - i++; - while (i--) { - VIR_FREE(components[0]); - VIR_DELETE_ELEMENT(components, 0, ncomponents); - } - beginSlash =3D true; - - if (linkpath[1] =3D=3D '/' && linkpath[2] !=3D '/') - beginDoubleSlash =3D true; - else - beginDoubleSlash =3D false; - - i =3D 0; - } else { - VIR_FREE(components[i]); - VIR_DELETE_ELEMENT(components, i, ncomponents); - } - - if (virStorageFileCanonicalizeInjectSymlink(linkpath, - i, - &components, - &ncomponents) < 0) - goto cleanup; - - j =3D 0; - while (j < ncomponents) { - /* skip slashes */ - if (STREQ(components[j], "")) { - VIR_FREE(components[j]); - VIR_DELETE_ELEMENT(components, j, ncomponents); - continue; - } - j++; - } - - VIR_FREE(linkpath); - VIR_FREE(currentpath); - - continue; - } - - VIR_FREE(currentpath); - - i++; - } - - ret =3D virStorageFileCanonicalizeFormatPath(components, ncomponents, - beginSlash, beginDoubleSlas= h); - - cleanup: - virHashFree(cycle); - virStringListFreeCount(components, ncomponents); - - return ret; -} diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h index 6b198858cc..62185e6f4f 100644 --- a/src/util/virstoragefile.h +++ b/src/util/virstoragefile.h @@ -33,11 +33,3 @@ int virStorageFileGetSCSIKey(const char *path, bool ignoreError); int virStorageFileGetNPIVKey(const char *path, char **key); - -typedef int -(*virStorageFileSimplifyPathReadlinkCallback)(const char *path, - char **link, - void *data); -char *virStorageFileCanonicalizePath(const char *path, - virStorageFileSimplifyPathReadlinkCal= lback cb, - void *cbdata); --=20 2.29.2