Re: [PATCH v2 4/5] utils: Use overrides in virFileIsSharedFS()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





On 4/17/24 09:29, Andrea Bolognani wrote:
If the local admin has explicitly declared that a certain
filesystem is to be considered shared, we should treat it as
such.

Signed-off-by: Andrea Bolognani <abologna@xxxxxxxxxx>

---
  src/util/virfile.c | 42 +++++++++++++++++++++++++++++++++++++++++-
  1 file changed, 41 insertions(+), 1 deletion(-)

diff --git a/src/util/virfile.c b/src/util/virfile.c
index 3268866f8b..45815919d6 100644
--- a/src/util/virfile.c
+++ b/src/util/virfile.c
@@ -3801,9 +3801,49 @@ virFileGetDefaultHugepage(virHugeTLBFS *fs,
      return NULL;
  }
+static bool
+virFileIsSharedFSOverride(const char *path,
+                          char *const *overrides)
+{
+    g_autofree char *dirpath = NULL;
+    char *p = NULL;
+
+    if (!path || path[0] != '/' || !overrides)
+        return false;
+
+    if (g_strv_contains((const char *const *) overrides, path))
+        return true;
+
+    dirpath = g_strdup(path);
+
+    /* Continue until we've scanned the entire path */
+    while (p != dirpath) {
+
+        /* Find the last slash */
+        if ((p = strrchr(dirpath, '/')) == NULL)
+            break;
+
+        /* Truncate the path by overwriting the slash that we've just
+         * found with a null byte. If it is the very first slash in
+         * the path, we need to handle things slightly differently */
+        if (p == dirpath)
+            *(p+1) = '\0';
+        else
+            *p = '\0';

When admins declare a path as shared they must omit the trailing '/' then. It may be wroth mentioning this in 2/5.

Reviewed-by: Stefan Berger <stefanb@xxxxxxxxxxxxx>


+
+        if (g_strv_contains((const char *const *) overrides, dirpath))
+            return true;
+    }
+
+    return false;
+}
+
  int virFileIsSharedFS(const char *path,
-                      char *const *overrides G_GNUC_UNUSED)
+                      char *const *overrides)
  {
+    if (virFileIsSharedFSOverride(path, overrides))
+        return 1;
+
      return virFileIsSharedFSType(path,
                                   VIR_FILE_SHFS_NFS |
                                   VIR_FILE_SHFS_GFS2 |
_______________________________________________
Devel mailing list -- devel@xxxxxxxxxxxxxxxxx
To unsubscribe send an email to devel-leave@xxxxxxxxxxxxxxxxx




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux