add APIs to Create, Close and Free MultiFD files to associate with
multifd channels.
Signed-off-by: Claudio Fontana <cfontana(a)suse.de>
---
src/qemu/qemu_saveimage.c | 87 +++++++++++++++++++++++++++++++++++++++
src/qemu/qemu_saveimage.h | 11 +++++
2 files changed, 98 insertions(+)
diff --git a/src/qemu/qemu_saveimage.c b/src/qemu/qemu_saveimage.c
index 5a569fa52e..38ebc7dd66 100644
--- a/src/qemu/qemu_saveimage.c
+++ b/src/qemu/qemu_saveimage.c
@@ -365,6 +365,93 @@ int virQEMUSaveFdFini(virQEMUSaveFd *saveFd, virDomainObj *vm, int
ret)
return ret;
}
+/*
+ * qemuSaveImageFreeMultiFd: free all multifd virQEMUSaveFds.
+ * @multiFd: the array of saveFds
+ * @vm: the virDomainObj, to release lock
+ * @nconn: number of multifd channels
+ * @ret: the current operation result (< 0 is failure)
+ *
+ * If multiFd is NULL, the return value will be unchanged.
+ *
+ * Returns ret, or -1 if an error is detected.
+ */
+int qemuSaveImageFreeMultiFd(virQEMUSaveFd *multiFd, virDomainObj *vm, int nconn, int
ret)
+{
+ int idx;
+
+ if (!multiFd)
+ return ret;
+
+ for (idx = 0; idx < nconn; idx++) {
+ ret = virQEMUSaveFdFini(&multiFd[idx], vm, ret);
+ }
+ /*
+ * do it again to unlink all in the error case,
+ * if error happened in the middle of previous loop.
+ */
+ for (idx = 0; idx < nconn; idx++) {
+ ret = virQEMUSaveFdFini(&multiFd[idx], vm, ret);
+ }
+ g_free(multiFd);
+ return ret;
+}
+
+/*
+ * qemuSaveImageCloseMultiFd: perform normal close on all multifd virQEMUSaveFds.
+ * If multiFd is NULL, the function will return success.
+ *
+ * Returns -1 on error, 0 on success.
+ */
+
+int qemuSaveImageCloseMultiFd(virQEMUSaveFd *multiFd, int nconn, virDomainObj *vm)
+{
+ int idx;
+
+ if (!multiFd)
+ return 0;
+
+ for (idx = 0; idx < nconn; idx++) {
+ if (virQEMUSaveFdClose(&multiFd[idx], vm) < 0) {
+ return -1;
+ }
+ }
+ return 0;
+}
+
+/*
+ * qemuSaveImageCreateMultiFd: allocate and initialize all multifd virQEMUSaveFds.
+ *
+ * Returns the new array of virQEMUSaveFds, or NULL on error.
+ */
+
+virQEMUSaveFd *
+qemuSaveImageCreateMultiFd(virQEMUDriver *driver, virDomainObj *vm,
+ virCommand *cmd, const char *path,
+ int oflags, virQEMUDriverConfig *cfg,
+ int nconn)
+{
+ virQEMUSaveFd *multiFd = g_new0(virQEMUSaveFd, nconn);
+ int idx;
+
+ for (idx = 0; idx < nconn; idx++) {
+ virQEMUSaveFd *m = &multiFd[idx];
+ if (virQEMUSaveFdInit(m, path, idx + 1, oflags, cfg) < 0 ||
+ qemuSecuritySetImageFDLabel(driver->securityManager, vm->def, m->fd)
< 0) {
+
+ virQEMUSaveFdFini(m, vm, -1);
+ goto error;
+ }
+ virCommandAddArgFormat(cmd, "%d", m->fd);
+ virCommandPassFD(cmd, m->fd, 0);
+ }
+ return multiFd;
+
+ error:
+ qemuSaveImageFreeMultiFd(multiFd, vm, nconn, -1);
+ return NULL;
+}
+
/* Helper function to execute a migration to file with a correct save header
* the caller needs to make sure that the processors are stopped and do all other
diff --git a/src/qemu/qemu_saveimage.h b/src/qemu/qemu_saveimage.h
index 5dc63f3661..b775c5eb08 100644
--- a/src/qemu/qemu_saveimage.h
+++ b/src/qemu/qemu_saveimage.h
@@ -72,6 +72,17 @@ int virQEMUSaveFdClose(virQEMUSaveFd *saveFd, virDomainObj *vm);
int virQEMUSaveFdFini(virQEMUSaveFd *saveFd, virDomainObj *vm, int ret);
+virQEMUSaveFd *
+qemuSaveImageCreateMultiFd(virQEMUDriver *driver, virDomainObj *vm,
+ virCommand *cmd, const char *path,
+ int oflags, virQEMUDriverConfig *cfg,
+ int nconn)
+ ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(4)
ATTRIBUTE_NONNULL(6);
+
+int qemuSaveImageCloseMultiFd(virQEMUSaveFd *multiFd, int nconn, virDomainObj *vm);
+
+int qemuSaveImageFreeMultiFd(virQEMUSaveFd *multiFd, virDomainObj *vm, int nconn, int
ret);
+
virDomainDef *
qemuSaveImageUpdateDef(virQEMUDriver *driver,
virDomainDef *def,
--
2.35.3