]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: Move and export qemuDomainStorageUpdatePhysical and dependencies
authorPeter Krempa <pkrempa@redhat.com>
Wed, 6 Dec 2023 14:42:29 +0000 (15:42 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 13 Dec 2023 19:15:49 +0000 (20:15 +0100)
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@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/qemu/qemu_domain.c
src/qemu/qemu_domain.h
src/qemu/qemu_driver.c

index 953808fcfe798be190d37fd510591dd472efd156..734d63f8a49d0c64c0f339eea6f6ddf90878c85b 100644 (file)
@@ -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;
+}
index 1e56e50672a447c94e90fb77d05a5e2c5fe6cf93..b8331a32d34c3947b10f1e93d74edacb072c602c 100644 (file)
@@ -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);
index f4c2fbfb454f77229281bac40aeb7a56f3f0b97e..9331369d4dfc38796075208cf68b37bc5aa57edc 100644 (file)
@@ -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