]> xenbits.xensource.com Git - libvirt.git/commitdiff
conf: storage_source: Introduce type for storing FDs associated for storage
authorPeter Krempa <pkrempa@redhat.com>
Wed, 4 Jan 2023 14:25:21 +0000 (15:25 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 9 Jan 2023 13:59:42 +0000 (14:59 +0100)
For FD-passing of disk sources we'll need to keep the FDs around.
Introduce a data type helper based on a g_object so that we get
reference counting.

One instance will (due to security labelling) will need to be part of
the virStorageSource struct thus it's declared in the storage_source_conf
module.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
src/conf/storage_source_conf.c
src/conf/storage_source_conf.h
src/libvirt_private.syms

index 6ab9ed6ac518db9130fbd924cd78692161a3983a..8e2a85968dc86c9de6838005a886d06aa6336507 100644 (file)
@@ -28,6 +28,7 @@
 #include "virerror.h"
 #include "virlog.h"
 #include "virstring.h"
+#include "virfile.h"
 
 #define VIR_FROM_THIS VIR_FROM_STORAGE
 
@@ -1361,3 +1362,43 @@ virStorageSourceInitiatorClear(virStorageSourceInitiatorDef *initiator)
 {
     VIR_FREE(initiator->iqn);
 }
+
+G_DEFINE_TYPE(virStorageSourceFDTuple, vir_storage_source_fd_tuple, G_TYPE_OBJECT);
+
+static void
+vir_storage_source_fd_tuple_init(virStorageSourceFDTuple *fdt G_GNUC_UNUSED)
+{
+}
+
+
+static void
+virStorageSourceFDTupleFinalize(GObject *object)
+{
+    virStorageSourceFDTuple *fdt = VIR_STORAGE_SOURCE_FD_TUPLE(object);
+    size_t i;
+
+    if (!fdt)
+        return;
+
+    for (i = 0; i < fdt->nfds; i++)
+        VIR_FORCE_CLOSE(fdt->fds[i]);
+
+    g_free(fdt->fds);
+    G_OBJECT_CLASS(vir_storage_source_fd_tuple_parent_class)->finalize(object);
+}
+
+
+static void
+vir_storage_source_fd_tuple_class_init(virStorageSourceFDTupleClass *klass)
+{
+    GObjectClass *obj = G_OBJECT_CLASS(klass);
+
+    obj->finalize = virStorageSourceFDTupleFinalize;
+}
+
+
+virStorageSourceFDTuple *
+virStorageSourceFDTupleNew(void)
+{
+    return g_object_new(vir_storage_source_fd_tuple_get_type(), NULL);
+}
index f2440cec6acccaa8e1c0567113b838b612ab2e71..9cd1a0c137a31349bc793c1a32d4f83ec1ec15ad 100644 (file)
@@ -258,6 +258,23 @@ struct _virStorageSourceSlice {
 };
 
 
+struct _virStorageSourceFDTuple {
+    GObject parent;
+    int *fds;
+    size_t nfds;
+
+    bool writable;
+    bool tryRestoreLabel;
+
+    /* connection this FD tuple is associated with for auto-closing */
+    virConnect *conn;
+};
+G_DECLARE_FINAL_TYPE(virStorageSourceFDTuple, vir_storage_source_fd_tuple, VIR, STORAGE_SOURCE_FD_TUPLE, GObject);
+
+virStorageSourceFDTuple *
+virStorageSourceFDTupleNew(void);
+
+
 typedef struct _virStorageSource virStorageSource;
 
 /* Stores information related to a host resource.  In the case of backing
index 0aef539dc83bfe6c36a372bd666f3380195a502e..c3fff7fc2a20188d490b9eb7f2983b5e2a904964 100644 (file)
@@ -1117,6 +1117,7 @@ virStorageSourceChainHasManagedPR;
 virStorageSourceChainHasNVMe;
 virStorageSourceClear;
 virStorageSourceCopy;
+virStorageSourceFDTupleNew;
 virStorageSourceGetActualType;
 virStorageSourceGetSecurityLabelDef;
 virStorageSourceHasBacking;