conf: storage_source: Introduce type for storing FDs associated for storage

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>
This commit is contained in:
Peter Krempa 2023-01-04 15:25:21 +01:00
parent 3ea4170551
commit e2670a63d2
3 changed files with 59 additions and 0 deletions

View 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);
}

View 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

View File

@ -1117,6 +1117,7 @@ virStorageSourceChainHasManagedPR;
virStorageSourceChainHasNVMe;
virStorageSourceClear;
virStorageSourceCopy;
virStorageSourceFDTupleNew;
virStorageSourceGetActualType;
virStorageSourceGetSecurityLabelDef;
virStorageSourceHasBacking;