On Wed, Feb 12, 2025 at 15:46:44 +0000, Daniel P. Berrangé wrote: > This eliminates some duplicated code patterns aross drivers. > > Signed-off-by: Daniel P. Berrangé <berrange@xxxxxxxxxx> > --- > src/bhyve/bhyve_driver.c | 41 ++++++++++++------------------ > src/libxl/libxl_driver.c | 36 ++++++++------------------- > src/lxc/lxc_driver.c | 13 +++++----- > src/lxc/lxc_process.c | 18 ++------------ > src/lxc/lxc_process.h | 2 ++ > src/qemu/qemu_driver.c | 54 ++++++++++++---------------------------- > 6 files changed, 53 insertions(+), 111 deletions(-) > > diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c > index f6b0417014..4d83a0dd8a 100644 > --- a/src/bhyve/bhyve_driver.c > +++ b/src/bhyve/bhyve_driver.c > @@ -54,6 +54,7 @@ > #include "virportallocator.h" > #include "conf/domain_capabilities.h" > #include "virutil.h" > +#include "domain_driver.h" > > #include "bhyve_conf.h" > #include "bhyve_device.h" > @@ -70,29 +71,18 @@ VIR_LOG_INIT("bhyve.bhyve_driver"); > > struct _bhyveConn *bhyve_driver = NULL; > > -static int > +static void > bhyveAutostartDomain(virDomainObj *vm, void *opaque G_GNUC_UNUSED) > { So ultimately opaque will be set to 'bhyve_driver'. > int ret = 0; > - VIR_LOCK_GUARD lock = virObjectLockGuard(vm); > - > - if (vm->autostart && !virDomainObjIsActive(vm)) { > - virResetLastError(); > - ret = virBhyveProcessStart(bhyve_driver, NULL, vm, > - VIR_DOMAIN_RUNNING_BOOTED, 0); > - if (ret < 0) { > - virReportError(VIR_ERR_INTERNAL_ERROR, > - _("Failed to autostart VM '%1$s': %2$s"), > - vm->def->name, virGetLastErrorMessage()); > - } > - } > - return ret; > -} > > -static void > -bhyveAutostartDomains(struct _bhyveConn *driver) > -{ > - virDomainObjListForEach(driver->domains, false, bhyveAutostartDomain, NULL); > + ret = virBhyveProcessStart(bhyve_driver, NULL, vm, ... so you could use that instead ... > + VIR_DOMAIN_RUNNING_BOOTED, 0); > + if (ret < 0) { > + virReportError(VIR_ERR_INTERNAL_ERROR, > + _("Failed to autostart VM '%1$s': %2$s"), > + vm->def->name, virGetLastErrorMessage()); > + } > } > > /** > @@ -1168,7 +1158,7 @@ bhyveStateInitialize(bool privileged, > virStateInhibitCallback callback G_GNUC_UNUSED, > void *opaque G_GNUC_UNUSED) > { > - bool autostart = true; > + virDomainDriverAutoStartConfig autostartCfg; > > if (root != NULL) { > virReportError(VIR_ERR_INVALID_ARG, "%s", > @@ -1253,11 +1243,12 @@ bhyveStateInitialize(bool privileged, > > virBhyveProcessReconnectAll(bhyve_driver); > > - if (virDriverShouldAutostart(BHYVE_STATE_DIR, &autostart) < 0) > - goto cleanup; > - > - if (autostart) > - bhyveAutostartDomains(bhyve_driver); > + autostartCfg = (virDomainDriverAutoStartConfig) { > + .stateDir = BHYVE_STATE_DIR, > + .callback = bhyveAutostartDomain, > + .opaque = bhyve_driver, ... so that this is not useless. > + }; > + virDomainDriverAutoStart(bhyve_driver->domains, &autostartCfg); > > return VIR_DRV_STATE_INIT_COMPLETE; > Reviewed-by: Peter Krempa <pkrempa@xxxxxxxxxx>