[libvirt PATCH 09/17] virstoragefile: move virStorageIsFile into virfile

Pavel Hrdina phrdina at redhat.com
Mon Dec 14 15:55:29 UTC 2020


Signed-off-by: Pavel Hrdina <phrdina at redhat.com>
---
 src/libvirt_private.syms  |  2 +-
 src/util/virfile.c        | 21 +++++++++++++++++++++
 src/util/virfile.h        |  1 +
 src/util/virstoragefile.c | 26 +++-----------------------
 src/util/virstoragefile.h |  1 -
 5 files changed, 26 insertions(+), 25 deletions(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 57f3b12000..0b560dfe45 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2090,6 +2090,7 @@ virFileIsCDROM;
 virFileIsClusterFS;
 virFileIsDir;
 virFileIsExecutable;
+virFileIsFile;
 virFileIsLink;
 virFileIsMountPoint;
 virFileIsRegular;
@@ -3156,7 +3157,6 @@ virStorageFileSupportsBackingChainTraversal;
 virStorageFileSupportsCreate;
 virStorageFileSupportsSecurityDriver;
 virStorageFileUnlink;
-virStorageIsFile;
 virStorageIsRelative;
 virStorageNetHostDefClear;
 virStorageNetHostDefCopy;
diff --git a/src/util/virfile.c b/src/util/virfile.c
index 3f58b98248..7a7468b202 100644
--- a/src/util/virfile.c
+++ b/src/util/virfile.c
@@ -1995,6 +1995,27 @@ virFileIsCDROM(const char *path)
 #endif /* defined(__linux__) */
 
 
+bool
+virFileIsFile(const char *backing)
+{
+    char *colon;
+    char *slash;
+
+    if (!backing)
+        return false;
+
+    colon = strchr(backing, ':');
+    slash = strchr(backing, '/');
+
+    /* Reject anything that looks like a protocol (such as nbd: or
+     * rbd:); if someone really does want a relative file name that
+     * includes ':', they can always prefix './'.  */
+    if (colon && (!slash || colon < slash))
+        return false;
+    return true;
+}
+
+
 #if defined WITH_MNTENT_H && defined WITH_GETMNTENT_R
 static int
 virFileGetMountSubtreeImpl(const char *mtabpath,
diff --git a/src/util/virfile.h b/src/util/virfile.h
index 733d652ac9..dfd3188ff2 100644
--- a/src/util/virfile.h
+++ b/src/util/virfile.h
@@ -227,6 +227,7 @@ int virFileIsClusterFS(const char *path) ATTRIBUTE_NONNULL(1);
 int virFileIsMountPoint(const char *file) ATTRIBUTE_NONNULL(1);
 int virFileIsCDROM(const char *path)
     ATTRIBUTE_NONNULL(1) G_GNUC_WARN_UNUSED_RESULT;
+bool virFileIsFile(const char *path);
 
 int virFileGetMountSubtree(const char *mtabpath,
                            const char *prefix,
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index 3db85d8b89..f37802260b 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -756,26 +756,6 @@ virStorageFileMatchesVersion(int versionOffset,
     return false;
 }
 
-bool
-virStorageIsFile(const char *backing)
-{
-    char *colon;
-    char *slash;
-
-    if (!backing)
-        return false;
-
-    colon = strchr(backing, ':');
-    slash = strchr(backing, '/');
-
-    /* Reject anything that looks like a protocol (such as nbd: or
-     * rbd:); if someone really does want a relative file name that
-     * includes ':', they can always prefix './'.  */
-    if (colon && (!slash || colon < slash))
-        return false;
-    return true;
-}
-
 
 bool
 virStorageIsRelative(const char *backing)
@@ -783,7 +763,7 @@ virStorageIsRelative(const char *backing)
     if (backing[0] == '/')
         return false;
 
-    if (!virStorageIsFile(backing))
+    if (!virFileIsFile(backing))
         return false;
 
     return true;
@@ -1450,7 +1430,7 @@ virStorageFileChainLookup(virStorageSourcePtr chain,
 {
     virStorageSourcePtr prev;
     const char *start = chain->path;
-    bool nameIsFile = virStorageIsFile(name);
+    bool nameIsFile = virFileIsFile(name);
 
     if (!parent)
         parent = &prev;
@@ -3794,7 +3774,7 @@ virStorageSourceNewFromBackingAbsolute(const char *path,
 
     *src = NULL;
 
-    if (virStorageIsFile(path)) {
+    if (virFileIsFile(path)) {
         def->type = VIR_STORAGE_TYPE_FILE;
 
         def->path = g_strdup(path);
diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h
index 2452b967b2..2a44a535a1 100644
--- a/src/util/virstoragefile.h
+++ b/src/util/virstoragefile.h
@@ -420,7 +420,6 @@ virStorageSourcePtr virStorageFileChainLookup(virStorageSourcePtr chain,
                                               virStorageSourcePtr *parent)
     ATTRIBUTE_NONNULL(1);
 
-bool virStorageIsFile(const char *path);
 bool virStorageIsRelative(const char *backing);
 
 int virStorageFileGetSCSIKey(const char *path,
-- 
2.28.0




More information about the libvir-list mailing list