[PATCH 7/8] qemu: Move and export qemuDomainStorageUpdatePhysical and dependencies

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

 



Move qemuDomainStorageUpdatePhysical, qemuDomainStorageOpenStat,
qemuDomainStorageCloseStat to qemu_domain.c and export them. They'll be
reused in the migration code.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/qemu/qemu_domain.c | 114 +++++++++++++++++++++++++++++++++++++++++
 src/qemu/qemu_domain.h |  15 ++++++
 src/qemu/qemu_driver.c | 114 -----------------------------------------
 3 files changed, 129 insertions(+), 114 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 953808fcfe..734d63f8a4 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -12675,3 +12675,117 @@ qemuDomainNumatuneMaybeFormatNodesetUnion(virDomainObj *vm,
     if (nodeset)
         *nodeset = g_steal_pointer(&unionMask);
 }
+
+
+/**
+ * @cfg: driver configuration data
+ * @vm: domain object
+ * @src: storage source data
+ * @ret_fd: pointer to return open'd file descriptor
+ * @ret_sb: pointer to return stat buffer (local or remote)
+ * @skipInaccessible: Don't report error if files are not accessible
+ *
+ * For local storage, open the file using qemuDomainOpenFile and then use
+ * fstat() to grab the stat struct data for the caller.
+ *
+ * For remote storage, attempt to access the file and grab the stat
+ * struct data if the remote connection supports it.
+ *
+ * Returns 1 if @src was successfully opened (@ret_fd and @ret_sb is populated),
+ * 0 if @src can't be opened and @skipInaccessible is true (no errors are
+ * reported) or -1 otherwise (errors are reported).
+ */
+int
+qemuDomainStorageOpenStat(virQEMUDriverConfig *cfg,
+                          virDomainObj *vm,
+                          virStorageSource *src,
+                          int *ret_fd,
+                          struct stat *ret_sb,
+                          bool skipInaccessible)
+{
+    if (virStorageSourceIsLocalStorage(src)) {
+        if (skipInaccessible && !virFileExists(src->path))
+            return 0;
+
+        if ((*ret_fd = qemuDomainOpenFile(cfg, vm->def, src->path, O_RDONLY,
+                                          NULL)) < 0)
+            return -1;
+
+        if (fstat(*ret_fd, ret_sb) < 0) {
+            virReportSystemError(errno, _("cannot stat file '%1$s'"), src->path);
+            VIR_FORCE_CLOSE(*ret_fd);
+            return -1;
+        }
+    } else {
+        if (skipInaccessible && virStorageSourceSupportsBackingChainTraversal(src) <= 0)
+            return 0;
+
+        if (virStorageSourceInitAs(src, cfg->user, cfg->group) < 0)
+            return -1;
+
+        if (virStorageSourceStat(src, ret_sb) < 0) {
+            virStorageSourceDeinit(src);
+            virReportSystemError(errno, _("failed to stat remote file '%1$s'"),
+                                 NULLSTR(src->path));
+            return -1;
+        }
+    }
+
+    return 1;
+}
+
+
+/**
+ * @src: storage source data
+ * @fd: file descriptor to close for local
+ *
+ * If local, then just close the file descriptor.
+ * else remote, then tear down the storage driver backend connection.
+ */
+void
+qemuDomainStorageCloseStat(virStorageSource *src,
+                           int *fd)
+{
+    if (virStorageSourceIsLocalStorage(src))
+        VIR_FORCE_CLOSE(*fd);
+    else
+        virStorageSourceDeinit(src);
+}
+
+
+/**
+ * qemuDomainStorageUpdatePhysical:
+ * @cfg: qemu driver configuration object
+ * @vm: domain object
+ * @src: storage source to update
+ *
+ * Update the physical size of the disk by reading the actual size of the image
+ * on disk.
+ *
+ * Returns 0 on successful update and -1 otherwise (some uncommon errors may be
+ * reported but are reset (thus only logged)).
+ */
+int
+qemuDomainStorageUpdatePhysical(virQEMUDriverConfig *cfg,
+                                virDomainObj *vm,
+                                virStorageSource *src)
+{
+    int ret;
+    int fd = -1;
+    struct stat sb;
+
+    if (virStorageSourceIsEmpty(src))
+        return 0;
+
+    if ((ret = qemuDomainStorageOpenStat(cfg, vm, src, &fd, &sb, true)) <= 0) {
+        if (ret < 0)
+            virResetLastError();
+        return -1;
+    }
+
+    ret = virStorageSourceUpdatePhysicalSize(src, fd, &sb);
+
+    qemuDomainStorageCloseStat(src, &fd);
+
+    return ret;
+}
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index 1e56e50672..b8331a32d3 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -1129,3 +1129,18 @@ void
 qemuDomainNumatuneMaybeFormatNodesetUnion(virDomainObj *vm,
                                           virBitmap **nodeset,
                                           char **nodesetStr);
+
+int
+qemuDomainStorageOpenStat(virQEMUDriverConfig *cfg,
+                          virDomainObj *vm,
+                          virStorageSource *src,
+                          int *ret_fd,
+                          struct stat *ret_sb,
+                          bool skipInaccessible);
+void
+qemuDomainStorageCloseStat(virStorageSource *src,
+                           int *fd);
+int
+qemuDomainStorageUpdatePhysical(virQEMUDriverConfig *cfg,
+                                virDomainObj *vm,
+                                virStorageSource *src);
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index f4c2fbfb45..9331369d4d 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -10216,120 +10216,6 @@ qemuDomainMemoryPeek(virDomainPtr dom,
 }


-/**
- * @cfg: driver configuration data
- * @vm: domain object
- * @src: storage source data
- * @ret_fd: pointer to return open'd file descriptor
- * @ret_sb: pointer to return stat buffer (local or remote)
- * @skipInaccessible: Don't report error if files are not accessible
- *
- * For local storage, open the file using qemuDomainOpenFile and then use
- * fstat() to grab the stat struct data for the caller.
- *
- * For remote storage, attempt to access the file and grab the stat
- * struct data if the remote connection supports it.
- *
- * Returns 1 if @src was successfully opened (@ret_fd and @ret_sb is populated),
- * 0 if @src can't be opened and @skipInaccessible is true (no errors are
- * reported) or -1 otherwise (errors are reported).
- */
-static int
-qemuDomainStorageOpenStat(virQEMUDriverConfig *cfg,
-                          virDomainObj *vm,
-                          virStorageSource *src,
-                          int *ret_fd,
-                          struct stat *ret_sb,
-                          bool skipInaccessible)
-{
-    if (virStorageSourceIsLocalStorage(src)) {
-        if (skipInaccessible && !virFileExists(src->path))
-            return 0;
-
-        if ((*ret_fd = qemuDomainOpenFile(cfg, vm->def, src->path, O_RDONLY,
-                                          NULL)) < 0)
-            return -1;
-
-        if (fstat(*ret_fd, ret_sb) < 0) {
-            virReportSystemError(errno, _("cannot stat file '%1$s'"), src->path);
-            VIR_FORCE_CLOSE(*ret_fd);
-            return -1;
-        }
-    } else {
-        if (skipInaccessible && virStorageSourceSupportsBackingChainTraversal(src) <= 0)
-            return 0;
-
-        if (virStorageSourceInitAs(src, cfg->user, cfg->group) < 0)
-            return -1;
-
-        if (virStorageSourceStat(src, ret_sb) < 0) {
-            virStorageSourceDeinit(src);
-            virReportSystemError(errno, _("failed to stat remote file '%1$s'"),
-                                 NULLSTR(src->path));
-            return -1;
-        }
-    }
-
-    return 1;
-}
-
-
-/**
- * @src: storage source data
- * @fd: file descriptor to close for local
- *
- * If local, then just close the file descriptor.
- * else remote, then tear down the storage driver backend connection.
- */
-static void
-qemuDomainStorageCloseStat(virStorageSource *src,
-                           int *fd)
-{
-    if (virStorageSourceIsLocalStorage(src))
-        VIR_FORCE_CLOSE(*fd);
-    else
-        virStorageSourceDeinit(src);
-}
-
-
-/**
- * qemuDomainStorageUpdatePhysical:
- * @cfg: qemu driver configuration object
- * @vm: domain object
- * @src: storage source to update
- *
- * Update the physical size of the disk by reading the actual size of the image
- * on disk.
- *
- * Returns 0 on successful update and -1 otherwise (some uncommon errors may be
- * reported but are reset (thus only logged)).
- */
-static int
-qemuDomainStorageUpdatePhysical(virQEMUDriverConfig *cfg,
-                                virDomainObj *vm,
-                                virStorageSource *src)
-{
-    int ret;
-    int fd = -1;
-    struct stat sb;
-
-    if (virStorageSourceIsEmpty(src))
-        return 0;
-
-    if ((ret = qemuDomainStorageOpenStat(cfg, vm, src, &fd, &sb, true)) <= 0) {
-        if (ret < 0)
-            virResetLastError();
-        return -1;
-    }
-
-    ret = virStorageSourceUpdatePhysicalSize(src, fd, &sb);
-
-    qemuDomainStorageCloseStat(src, &fd);
-
-    return ret;
-}
-
-
 /**
  * @cfg: driver configuration data
  * @vm: domain object
-- 
2.43.0
_______________________________________________
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