[libvirt] [PATCH v2] virFileIsSharedFixFUSE: Copy mnt_dir when browsing mount table

Han Han posted 1 patch 5 years, 6 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20181009071017.23977-1-hhan@redhat.com
Test syntax-check failed
src/util/virfile.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
[libvirt] [PATCH v2] virFileIsSharedFixFUSE: Copy mnt_dir when browsing mount table
Posted by Han Han 5 years, 6 months ago
Fix typos of function name in commit msg.
v1 version: https://www.redhat.com/archives/libvir-list/2018-October/msg00511.html

virFileIsSharedFixFUSE doesn't fix f_type when "fuse.glusterfs"
is not the last row of mount table. For example, it doesn't works on
the mount table like following:
10.XX.XX.XX:/gv0 /mnt fuse.glusterfs rw 0 0
root@XX.XX.XX:/tmp/mkdir /tmp/br0 fuse.sshfs rw 0 0

Copy mnt_dir of struct mntent in case its mnt_dir is changed by
getmntent_r in the loop later.

Signed-off-by: Han Han <hhan@redhat.com>
---
 src/util/virfile.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/util/virfile.c b/src/util/virfile.c
index 2a7e87102a..c503462633 100644
--- a/src/util/virfile.c
+++ b/src/util/virfile.c
@@ -3469,7 +3469,7 @@ virFileIsSharedFixFUSE(const char *path,
                        long *f_type)
 {
     char *dirpath = NULL;
-    const char **mounts = NULL;
+    char **mounts = NULL;
     size_t nmounts = 0;
     char *p;
     FILE *f = NULL;
@@ -3491,8 +3491,12 @@ virFileIsSharedFixFUSE(const char *path,
         if (STRNEQ("fuse.glusterfs", mb.mnt_type))
             continue;
 
-        if (VIR_APPEND_ELEMENT_COPY(mounts, nmounts, mb.mnt_dir) < 0)
+        char *mnt_dir;
+        if (VIR_STRDUP(mnt_dir, mb.mnt_dir) < 0 ||
+                VIR_APPEND_ELEMENT_COPY(mounts, nmounts, mnt_dir) < 0) {
+            VIR_FREE(mnt_dir);
             goto cleanup;
+        }
     }
 
     /* Add NULL sentinel so that this is a virStringList */
@@ -3512,7 +3516,7 @@ virFileIsSharedFixFUSE(const char *path,
         else
             *p = '\0';
 
-        if (virStringListHasString(mounts, dirpath)) {
+        if (virStringListHasString((const char **)mounts, dirpath)) {
             VIR_DEBUG("Found gluster FUSE mountpoint=%s for path=%s. "
                       "Fixing shared FS type", dirpath, path);
             *f_type = GFS2_MAGIC;
@@ -3523,7 +3527,7 @@ virFileIsSharedFixFUSE(const char *path,
     ret = 0;
  cleanup:
     endmntent(f);
-    VIR_FREE(mounts);
+    virStringListFree(mounts);
     VIR_FREE(dirpath);
     return ret;
 }
-- 
2.19.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v2] virFileIsSharedFixFUSE: Copy mnt_dir when browsing mount table
Posted by Michal Privoznik 5 years, 6 months ago
On 10/09/2018 09:10 AM, Han Han wrote:
> Fix typos of function name in commit msg.
> v1 version: https://www.redhat.com/archives/libvir-list/2018-October/msg00511.html
> 
> virFileIsSharedFixFUSE doesn't fix f_type when "fuse.glusterfs"
> is not the last row of mount table. For example, it doesn't works on
> the mount table like following:
> 10.XX.XX.XX:/gv0 /mnt fuse.glusterfs rw 0 0
> root@XX.XX.XX:/tmp/mkdir /tmp/br0 fuse.sshfs rw 0 0
> 
> Copy mnt_dir of struct mntent in case its mnt_dir is changed by
> getmntent_r in the loop later.
> 
> Signed-off-by: Han Han <hhan@redhat.com>
> ---
>  src/util/virfile.c | 12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)


Ah, thanks for catching this. In fact, we can do way better. I will post
my patches shortly.

Michal

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list