device/storage: use flex array instead of calculated ptr

pull/9939/head
Victor Julien 1 year ago committed by Victor Julien
parent 11d73e284c
commit f10233fecf

@ -75,7 +75,7 @@ LiveDevStorageId LiveDevStorageRegister(const char *name, const unsigned int siz
int LiveDevSetStorageById(LiveDevice *d, LiveDevStorageId id, void *ptr) int LiveDevSetStorageById(LiveDevice *d, LiveDevStorageId id, void *ptr)
{ {
return StorageSetById((Storage *)((void *)d + sizeof(LiveDevice)), STORAGE_DEVICE, id.id, ptr); return StorageSetById(d->storage, STORAGE_DEVICE, id.id, ptr);
} }
/** /**
@ -88,7 +88,7 @@ int LiveDevSetStorageById(LiveDevice *d, LiveDevStorageId id, void *ptr)
void *LiveDevGetStorageById(LiveDevice *d, LiveDevStorageId id) void *LiveDevGetStorageById(LiveDevice *d, LiveDevStorageId id)
{ {
return StorageGetById((Storage *)((void *)d + sizeof(LiveDevice)), STORAGE_DEVICE, id.id); return StorageGetById(d->storage, STORAGE_DEVICE, id.id);
} }
/** /**
@ -99,19 +99,18 @@ void *LiveDevGetStorageById(LiveDevice *d, LiveDevStorageId id)
void *LiveDevAllocStorageById(LiveDevice *d, LiveDevStorageId id) void *LiveDevAllocStorageById(LiveDevice *d, LiveDevStorageId id)
{ {
return StorageAllocByIdPrealloc( return StorageAllocByIdPrealloc(d->storage, STORAGE_DEVICE, id.id);
(Storage *)((void *)d + sizeof(LiveDevice)), STORAGE_DEVICE, id.id);
} }
void LiveDevFreeStorageById(LiveDevice *d, LiveDevStorageId id) void LiveDevFreeStorageById(LiveDevice *d, LiveDevStorageId id)
{ {
StorageFreeById((Storage *)((void *)d + sizeof(LiveDevice)), STORAGE_DEVICE, id.id); StorageFreeById(d->storage, STORAGE_DEVICE, id.id);
} }
void LiveDevFreeStorage(LiveDevice *d) void LiveDevFreeStorage(LiveDevice *d)
{ {
if (LiveDevStorageSize() > 0) if (LiveDevStorageSize() > 0)
StorageFreeAll((Storage *)((void *)d + sizeof(LiveDevice)), STORAGE_DEVICE); StorageFreeAll(d->storage, STORAGE_DEVICE);
} }

@ -23,6 +23,7 @@
#endif /* HAVE_DPDK */ #endif /* HAVE_DPDK */
#include "queue.h" #include "queue.h"
#include "util-storage.h"
#define OFFLOAD_FLAG_SG (1<<0) #define OFFLOAD_FLAG_SG (1<<0)
#define OFFLOAD_FLAG_TSO (1<<1) #define OFFLOAD_FLAG_TSO (1<<1)
@ -66,6 +67,8 @@ typedef struct LiveDevice_ {
// DPDK resources that needs to be cleaned after workers are stopped and devices closed // DPDK resources that needs to be cleaned after workers are stopped and devices closed
DPDKDeviceResources dpdk_vars; DPDKDeviceResources dpdk_vars;
#endif #endif
/** storage handle as a flex array member */
Storage storage[];
} LiveDevice; } LiveDevice;
typedef struct LiveDeviceName_ { typedef struct LiveDeviceName_ {

Loading…
Cancel
Save