On 10/14/2014 03:29 AM, Peter Krempa wrote: > To allow live modification of device backends in qemu libvirt needs to > be able to hot-add/remove "objects". Add monitor backend functions to > allow this. Could add a short list of "known" objects that could make use of this... IOThreads, RNG, etc. > --- > src/qemu/qemu_monitor.c | 48 +++++++++++++++++++++++++++++++++++++ > src/qemu/qemu_monitor.h | 8 +++++++ > src/qemu/qemu_monitor_json.c | 56 ++++++++++++++++++++++++++++++++++++++++++++ > src/qemu/qemu_monitor_json.h | 8 +++++++ > 4 files changed, 120 insertions(+) > > diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c > index 5dff9ff..dfcd4ed 100644 > --- a/src/qemu/qemu_monitor.c > +++ b/src/qemu/qemu_monitor.c > @@ -3132,6 +3132,54 @@ int qemuMonitorAddDevice(qemuMonitorPtr mon, > return qemuMonitorAddDeviceWithFd(mon, devicestr, -1, NULL); > } > > + > +/** > + * qemuMonitorAddObject: > + * @mon: Pointer to monitor object > + * @type: Type of object to add Seems this could have been an 'int' typed value which would have ToString type function to convert into "expected" strings; otherwise, how does one know what to pass and what's valid or not. I'm assuming it's device specific, but there must be "something" that qemu expects. oh...hmm... are you modeling this after qemuMonitorGetObjectProps usage of 'type' and that'll be the callers problem? > + * @objalias: Alias of the new object > + * @props: Optional arguments for the given type. The object is consumed and > + * should not be referenced by the caller after this function returs. s/returs/returns > + * > + * Returns 0 on success -1 on error. > + */ > +int > +qemuMonitorAddObject(qemuMonitorPtr mon, > + const char *type, > + const char *objalias, > + virJSONValuePtr props) > +{ > + VIR_DEBUG("mon=%p type=%s objalias=%s props=%p", > + mon, type, objalias, props); > + int ret = -1; > + > + if (mon->json) > + ret = qemuMonitorJSONAddObject(mon, type, objalias, props); > + else > + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", > + _("object adding requires JSON monitor")); > + > + return ret; > +} > + > + > +int > +qemuMonitorDelObject(qemuMonitorPtr mon, > + const char *objalias) > +{ > + VIR_DEBUG("mon=%p objalias=%s", mon, objalias); > + int ret = -1; > + > + if (mon->json) > + ret = qemuMonitorJSONDelObject(mon, objalias); > + else > + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", > + _("object deletion requires JSON monitor")); > + > + return ret; > +} > + > + > int qemuMonitorAddDrive(qemuMonitorPtr mon, > const char *drivestr) > { > diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h > index fd145a7..750b3dc 100644 > --- a/src/qemu/qemu_monitor.h > +++ b/src/qemu/qemu_monitor.h > @@ -672,6 +672,14 @@ int qemuMonitorAddDeviceWithFd(qemuMonitorPtr mon, > int qemuMonitorDelDevice(qemuMonitorPtr mon, > const char *devalias); > > +int qemuMonitorAddObject(qemuMonitorPtr mon, > + const char *type, > + const char *objalias, > + virJSONValuePtr props); > + > +int qemuMonitorDelObject(qemuMonitorPtr mon, > + const char *objalias); > + > int qemuMonitorAddDrive(qemuMonitorPtr mon, > const char *drivestr); > > diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c > index 2967193..ff1fa45 100644 > --- a/src/qemu/qemu_monitor_json.c > +++ b/src/qemu/qemu_monitor_json.c > @@ -3561,6 +3561,62 @@ int qemuMonitorJSONAddDevice(qemuMonitorPtr mon, > } > > > +int qemuMonitorJSONAddObject(qemuMonitorPtr mon, > + const char *type, > + const char *objalias, > + virJSONValuePtr props) > +{ > + int ret = -1; > + virJSONValuePtr cmd; > + virJSONValuePtr reply = NULL; > + > + cmd = qemuMonitorJSONMakeCommand("object-add", > + "s:qom-type", type, > + "s:id", objalias, > + "A:props", props, > + NULL); > + if (!cmd) > + goto cleanup; > + Like another place in the code, make it clear why... /* @props is part of @cmd now. Avoid double free */ > + props = NULL; > + > + ret = qemuMonitorJSONCommand(mon, cmd, &reply); > + > + if (ret == 0) > + ret = qemuMonitorJSONCheckError(cmd, reply); > + > + cleanup: > + virJSONValueFree(cmd); > + virJSONValueFree(reply); > + virJSONValueFree(props); > + return ret; > +} > + Whether you use an 'int' type for AddObject or not is your call. I wasn't clear what the parameter was or how it should be used/filled in since there is no consumer of this API yet. ACK John > + > +int qemuMonitorJSONDelObject(qemuMonitorPtr mon, > + const char *objalias) > +{ > + int ret; > + virJSONValuePtr cmd; > + virJSONValuePtr reply = NULL; > + > + cmd = qemuMonitorJSONMakeCommand("object-del", > + "s:id", objalias, > + NULL); > + if (!cmd) > + return -1; > + > + ret = qemuMonitorJSONCommand(mon, cmd, &reply); > + > + if (ret == 0) > + ret = qemuMonitorJSONCheckError(cmd, reply); > + > + virJSONValueFree(cmd); > + virJSONValueFree(reply); > + return ret; > +} > + > + > int qemuMonitorJSONAddDrive(qemuMonitorPtr mon, > const char *drivestr) > { > diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h > index c898382..6cdaf18 100644 > --- a/src/qemu/qemu_monitor_json.h > +++ b/src/qemu/qemu_monitor_json.h > @@ -229,6 +229,14 @@ int qemuMonitorJSONAddDevice(qemuMonitorPtr mon, > int qemuMonitorJSONDelDevice(qemuMonitorPtr mon, > const char *devalias); > > +int qemuMonitorJSONAddObject(qemuMonitorPtr mon, > + const char *type, > + const char *objalias, > + virJSONValuePtr props); > + > +int qemuMonitorJSONDelObject(qemuMonitorPtr mon, > + const char *objalias); > + > int qemuMonitorJSONAddDrive(qemuMonitorPtr mon, > const char *drivestr); > -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list