]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
use virStorageFileIsSharedFS utility function in qemudDomainSaveFlag
authorLaine Stump <laine@laine.org>
Fri, 25 Jun 2010 00:56:45 +0000 (20:56 -0400)
committerLaine Stump <laine@laine.org>
Mon, 28 Jun 2010 15:55:53 +0000 (11:55 -0400)
Previously, this function had it's own bit of code performing the same
function. Since there's now an equivalent utility function, let's use it.

src/qemu/qemu_driver.c

index acbec7a52556762a55e05d7806a95deced7259dd..6ef75d0b184fb6cf45c5f38466d9adf6f2b92a7e 100644 (file)
 #include <sys/ioctl.h>
 #include <sys/un.h>
 
-#ifdef __linux__
-# include <sys/vfs.h>
-# ifndef NFS_SUPER_MAGIC
-#  define NFS_SUPER_MAGIC 0x6969
-# endif /* NFS_SUPER_MAGIC */
-#endif /* __linux__ */
-
 #include "virterror_internal.h"
 #include "logging.h"
 #include "datatypes.h"
@@ -5129,62 +5122,32 @@ static int qemudDomainSaveFlag(virDomainPtr dom, const char *path,
                 goto endjob;
             }
 
-#ifdef __linux__
             /* On Linux we can also verify the FS-type of the directory. */
-            char *dirpath, *p;
-            struct statfs st;
-            int statfs_ret;
-
-            if ((dirpath = strdup(path)) == NULL) {
-                virReportOOMError();
-                goto endjob;
-            }
-
-            do {
-                // Try less and less of the path until we get to a
-                // directory we can stat. Even if we don't have 'x'
-                // permission on any directory in the path on the NFS
-                // server (assuming it's NFS), we will be able to stat the
-                // mount point, and that will properly tell us if the
-                // fstype is NFS.
-
-                if ((p = strrchr(dirpath, '/')) == NULL) {
-                    qemuReportError(VIR_ERR_INVALID_ARG,
-                                    _("Invalid relative path '%s' for domain save file"),
-                                    path);
-                    VIR_FREE(dirpath);
-                    goto endjob;
-                }
-
-                if (p == dirpath)
-                    *(p+1) = '\0';
-                else
-                    *p = '\0';
-
-                statfs_ret = statfs(dirpath, &st);
-
-            } while ((statfs_ret == -1) && (p != dirpath));
-
-            if (statfs_ret == -1) {
-                virReportSystemError(errno,
-                                     _("Failed to create domain save file "
-                                       "'%s': statfs of all elements of path "
-                                       "failed"),
-                                     path);
-                VIR_FREE(dirpath);
-                goto endjob;
-            }
+            switch (virStorageFileIsSharedFS(path)) {
+                case 1:
+                   /* it was on a network share, so we'll continue
+                    * as outlined above
+                    */
+                   break;
+
+                case -1:
+                   virReportSystemError(errno,
+                                        _("Failed to create domain save file "
+                                          "'%s': couldn't determine fs type"),
+                                        path);
+                   goto endjob;
+                   break;
+
+                case 0:
+                default:
+                   /* local file - log the error returned by virFileOperation */
+                   virReportSystemError(rc,
+                                        _("Failed to create domain save file '%s'"),
+                                        path);
+                   goto endjob;
+                   break;
 
-            if (st.f_type != NFS_SUPER_MAGIC) {
-                virReportSystemError(rc,
-                                     _("Failed to create domain save file '%s'"
-                                       " (fstype of '%s' is 0x%X"),
-                                     path, dirpath, (unsigned int) st.f_type);
-                VIR_FREE(dirpath);
-                goto endjob;
             }
-            VIR_FREE(dirpath);
-#endif
 
             /* Retry creating the file as driver->user */