return NULL;
*d = (DriveInfo) {
+ .n_ref = 1,
.fd = -EBADF,
.overlay_fd = -EBADF,
};
return d;
}
-DriveInfo* drive_info_free(DriveInfo *d) {
- if (!d)
- return NULL;
+static DriveInfo* drive_info_free(DriveInfo *d) {
+ assert(d);
free(d->path);
free(d->format);
return mfree(d);
}
+DEFINE_TRIVIAL_REF_UNREF_FUNC(DriveInfo, drive_info, drive_info_free);
+
void drive_infos_done(DriveInfos *infos) {
assert(infos);
FOREACH_ARRAY(d, infos->drives, infos->n_drives)
- drive_info_free(*d);
+ drive_info_unref(*d);
infos->drives = mfree(infos->drives);
infos->n_drives = 0;
infos->scsi_pcie_port = mfree(infos->scsi_pcie_port);
* Each DriveInfo is individually heap-allocated so it can be handed off
* to the block device registry via TAKE_PTR. */
typedef struct DriveInfo {
+ unsigned n_ref;
char *path; /* original path (for logging; not passed to QEMU) */
char *format; /* "raw" or "qcow2" */
char *disk_driver; /* "virtio-blk-pci", "scsi-hd", "scsi-cd", "nvme" */
} DriveInfo;
DriveInfo* drive_info_new(void);
-DriveInfo* drive_info_free(DriveInfo *d);
-DEFINE_TRIVIAL_CLEANUP_FUNC(DriveInfo *, drive_info_free);
+DECLARE_TRIVIAL_REF_UNREF_FUNC(DriveInfo, drive_info);
+DEFINE_TRIVIAL_CLEANUP_FUNC(DriveInfo *, drive_info_unref);
typedef struct DriveInfos {
DriveInfo **drives; /* array of individually heap-allocated entries */
if (r < 0)
return log_error_errno(r, "Failed to extract filename from path '%s': %m", arg_image);
- _cleanup_(drive_info_freep) DriveInfo *d = drive_info_new();
+ _cleanup_(drive_info_unrefp) DriveInfo *d = drive_info_new();
if (!d)
return log_oom();
DiskType dt = drive->disk_type >= 0 ? drive->disk_type : arg_image_disk_type;
- _cleanup_(drive_info_freep) DriveInfo *d = drive_info_new();
+ _cleanup_(drive_info_unrefp) DriveInfo *d = drive_info_new();
if (!d)
return log_oom();