[libvirt] [PATCH v2 08/12] Make bhyveMonitor a virClass
Daniel P. Berrangé
berrange at redhat.com
Fri Jan 3 14:50:38 UTC 2020
On Thu, Jan 02, 2020 at 05:46:31PM +0000, Ryan Moeller wrote:
> Signed-off-by: Ryan Moeller <ryan at iXsystems.com>
> ---
> src/bhyve/bhyve_monitor.c | 144 ++++++++++++++++++++++++++------------
> 1 file changed, 98 insertions(+), 46 deletions(-)
FWIW, we're aiming to replace virClass with GObject, but since
you've already done the work here I'm not going to reject it
for that reason.
>
> diff --git a/src/bhyve/bhyve_monitor.c b/src/bhyve/bhyve_monitor.c
> index 0e55e19772..566c672ba0 100644
> --- a/src/bhyve/bhyve_monitor.c
> +++ b/src/bhyve/bhyve_monitor.c
> @@ -32,24 +32,82 @@
> #include "virerror.h"
> #include "virfile.h"
> #include "virlog.h"
> +#include "virobject.h"
>
> #define VIR_FROM_THIS VIR_FROM_BHYVE
>
> VIR_LOG_INIT("bhyve.bhyve_monitor");
>
> struct _bhyveMonitor {
> + virObject parent;
> +
> int kq;
> int watch;
> bhyveConnPtr driver;
> + virDomainObjPtr vm;
> };
>
> +static virClassPtr bhyveMonitorClass;
> +
> +static void
> +bhyveMonitorDispose(void *obj)
> +{
> + bhyveMonitorPtr mon = obj;
> +
> + VIR_FORCE_CLOSE(mon->kq);
> + virObjectUnref(mon->vm);
> +}
> +
> +static int
> +bhyveMonitorOnceInit(void)
> +{
> + if (!VIR_CLASS_NEW(bhyveMonitor, virClassForObject()))
> + return -1;
> +
> + return 0;
> +}
> +
> +VIR_ONCE_GLOBAL_INIT(bhyveMonitor);
> +
> +static void bhyveMonitorIO(int, int, int, void *);
> +
> +static bool
> +bhyveMonitorRegister(bhyveMonitorPtr mon)
> +{
> + virObjectRef(mon);
> + mon->watch = virEventAddHandle(mon->kq,
> + VIR_EVENT_HANDLE_READABLE |
> + VIR_EVENT_HANDLE_ERROR |
> + VIR_EVENT_HANDLE_HANGUP,
> + bhyveMonitorIO,
> + mon,
> + virObjectFreeCallback);
> + if (mon->watch < 0) {
> + VIR_DEBUG("failed to add event handle for mon %p", mon);
> + virObjectUnref(mon);
> + return false;
> + }
> + return true;
> +}
> +
> +static void
> +bhyveMonitorUnregister(bhyveMonitorPtr mon)
> +{
> + if (mon->watch < 0)
> + return;
> +
> + virEventRemoveHandle(mon->watch);
> + mon->watch = -1;
> +}
These two new methods are really separate refactoring from
the introduction of virClass. So as a future note, we'd generally
prefer if this had been two patches, but I'm fine merging this
one now.
Reviewed-by: Daniel P. Berrangé <berrange at redhat.com>
Regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
More information about the libvir-list
mailing list