Re: [libvirt] [PATCH 1/9] Add support for event tray moved of removable disks

2012-03-12 Thread Daniel Veillard
On Fri, Mar 09, 2012 at 06:49:20PM +0800, Osier Yang wrote:
 On 2012年03月09日 16:55, Daniel Veillard wrote:
 On Mon, Mar 05, 2012 at 06:25:39PM +0800, Osier Yang wrote:
 This patch introduces a new event type for the QMP event
 DEVICE_TRAY_MOVED, which occurs when the tray of a removable
 disk is moved (i.e opened or closed):
 
  VIR_DOMAIN_EVENT_ID_TRAY_MOVED
 
 The event's data includes the device alias and the tray's
 status, which indicates whether the tray has been opened
 or closed.  Thus the callback definition for the event is:
 
 typedef void
 (*virConnectDomainEventTrayMovedCallback)(virConnectPtr conn,
virDomainPtr dom,
const char *devAlias,
unsigned int trayOpened,
void *opaque);
 
Hum ... could we make that slightly more generic.
 Instead of just being able to report on tray opened or not (i.e. closed)
 Let's report TrayChangeCallback,  and have an 'int reason' instead.
 
 Hmm, yes, 'int reason' is good idea.
 
 But for the name, TrayMoved might describe the real action more
 precisely. Unlike DiskChange, it says there was some medium was
 changed, TrayMoved only intends to report the tray status changeing
 event, nothing really changed, or we can rename it to TrayStatusChange
 to indicate the tray status is changed, but IMO it's not much
 difference except getting a longer name. :-)
 
 Then for example the API would be able to cope with more set of events,
 one of the thing I can think of now would be the ability to emulate
 multiple device in one as disk changers,
 
 What does emulate multiple device mean? is it s/device/event/?

  Nahh, I was thinking of thinks like cdrom changers, where the
  enclosure can hold multiple disks and swap them. But in retrospect
  I dould we will have much need to emulate such hardware ever...

 and also possibly be able to
 provide invormations about the kind of media, i.e. switch from a CD-ROM
 to a DVD-WR in the tray.
 
 IMHO we should seperate the events for tray change and
 medium change, the info such as the kind of media should handled
 by DiskChange instead,

  yes, reasonnable.

 How about defining the callback like:
 
 /**
  * virConnectDomainEventTrayMovedReason:
  *
  * The reason describing why the callback was called
  */
 enum {
 VIR_DOMAIN_EVENT_TRAY_MOVED_OPEN = 0,
 VIR_DOMAIN_EVENT_TRAY_MOVED_CLOSE,
 
 /* Something else such as other driver only emits a
  * event for OPEN+CLOSE.
  */
 
 #ifdef VIR_ENUM_SENTINELS
 VIR_DOMAIN_EVENT_TRAY_MOVED_LAST
 #endif
 } virDomainEventTrayMovedReason;
 
 
 /**
  * virConnectDomainEventTrayMovedCallback:
  * @conn: connection object
  * @dom: domain on which the event occurred
  * @devAlias: device alias
  * @reason: reason why this callback was called, any of
 virDomainEventTrayMovedReason
  * @opaque: application specified data
  *
  * This callback occurs when the tray of a removable device is moved.
  *
  * The callback signature to use when registering for an event of type
  * VIR_DOMAIN_EVENT_ID_TRAY_MOVED wit virConnectDomainEventRegisterAny()
  */
 typedef void
 (*virConnectDomainEventTrayMovedCallback)(virConnectPtr conn,
 virDomainPtr dom,
 const char *devAlias,
 int reason,
 void *opaque);

  I think I would still feel a bit better with Changed rather than Moved
which is more specific, but not a blocker.

Daniel

-- 
Daniel Veillard  | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
dan...@veillard.com  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH 1/9] Add support for event tray moved of removable disks

2012-03-12 Thread Osier Yang

On 03/12/2012 04:31 PM, Daniel Veillard wrote:

On Fri, Mar 09, 2012 at 06:49:20PM +0800, Osier Yang wrote:

On 2012年03月09日 16:55, Daniel Veillard wrote:

On Mon, Mar 05, 2012 at 06:25:39PM +0800, Osier Yang wrote:

This patch introduces a new event type for the QMP event
DEVICE_TRAY_MOVED, which occurs when the tray of a removable
disk is moved (i.e opened or closed):

 VIR_DOMAIN_EVENT_ID_TRAY_MOVED

The event's data includes the device alias and the tray's
status, which indicates whether the tray has been opened
or closed.  Thus the callback definition for the event is:

typedef void
(*virConnectDomainEventTrayMovedCallback)(virConnectPtr conn,
   virDomainPtr dom,
   const char *devAlias,
   unsigned int trayOpened,
   void *opaque);


   Hum ... could we make that slightly more generic.
Instead of just being able to report on tray opened or not (i.e. closed)
Let's report TrayChangeCallback,  and have an 'int reason' instead.


Hmm, yes, 'int reason' is good idea.

But for the name, TrayMoved might describe the real action more
precisely. Unlike DiskChange, it says there was some medium was
changed, TrayMoved only intends to report the tray status changeing
event, nothing really changed, or we can rename it to TrayStatusChange
to indicate the tray status is changed, but IMO it's not much
difference except getting a longer name. :-)


Then for example the API would be able to cope with more set of events,
one of the thing I can think of now would be the ability to emulate
multiple device in one as disk changers,


What does emulate multiple device mean? is it s/device/event/?


   Nahh, I was thinking of thinks like cdrom changers, where the
   enclosure can hold multiple disks and swap them. But in retrospect
   I dould we will have much need to emulate such hardware ever...



I see, :-)

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH 1/9] Add support for event tray moved of removable disks

2012-03-09 Thread Daniel Veillard
On Mon, Mar 05, 2012 at 06:25:39PM +0800, Osier Yang wrote:
 This patch introduces a new event type for the QMP event
 DEVICE_TRAY_MOVED, which occurs when the tray of a removable
 disk is moved (i.e opened or closed):
 
 VIR_DOMAIN_EVENT_ID_TRAY_MOVED
 
 The event's data includes the device alias and the tray's
 status, which indicates whether the tray has been opened
 or closed.  Thus the callback definition for the event is:
 
 typedef void
 (*virConnectDomainEventTrayMovedCallback)(virConnectPtr conn,
   virDomainPtr dom,
   const char *devAlias,
   unsigned int trayOpened,
   void *opaque);

  Hum ... could we make that slightly more generic.
Instead of just being able to report on tray opened or not (i.e. closed)
Let's report TrayChangeCallback,  and have an 'int reason' instead.
Then for example the API would be able to cope with more set of events,
one of the thing I can think of now would be the ability to emulate
multiple device in one as disk changers, and also possibly be able to
provide invormations about the kind of media, i.e. switch from a CD-ROM
to a DVD-WR in the tray.

 ---
  daemon/remote.c|   33 +++
  examples/domain-events/events-c/event-test.c   |   21 +++-
  examples/domain-events/events-python/event-test.py |4 ++
  include/libvirt/libvirt.h.in   |   20 +++
  python/libvirt-override-virConnect.py  |   10 
  python/libvirt-override.c  |   50 +
  src/conf/domain_event.c|   58 
 
  src/conf/domain_event.h|6 ++
  src/libvirt_private.syms   |2 +
  src/qemu/qemu_monitor.c|   13 +
  src/qemu/qemu_monitor.h|7 +++
  src/qemu/qemu_monitor_json.c   |   18 ++
  src/qemu/qemu_process.c|   32 +++
  src/remote/remote_driver.c |   34 
  src/remote/remote_protocol.x   |9 +++-
  src/remote_protocol-structs|5 ++
  16 files changed, 320 insertions(+), 2 deletions(-)
 
 diff --git a/daemon/remote.c b/daemon/remote.c
 index 74a5f16..cc464fd 100644
 --- a/daemon/remote.c
 +++ b/daemon/remote.c
 @@ -505,6 +505,38 @@ mem_error:
  }
  
  
 +static int remoteRelayDomainEventTrayMoved(virConnectPtr conn 
 ATTRIBUTE_UNUSED,
 +   virDomainPtr dom,
 +   const char *devAlias,
 +   unsigned int trayOpened,
 +   void *opaque) {
 +virNetServerClientPtr client = opaque;
 +remote_domain_event_tray_moved_msg data;
 +
 +if (!client)
 +return -1;
 +
 +VIR_DEBUG(Relaying domain %s %d tray moved devAlias: %s trayOpened: %s,
 +  dom-name, dom-id, devAlias, trayOpened ? yes: no);
 +
 +/* build return data */
 +memset(data, 0, sizeof data);
 +
 +if (!(data.devAlias = strdup(devAlias))) {
 +virReportOOMError();
 +return -1;
 +}
 +data.trayOpened = trayOpened;
 +
 +make_nonnull_domain(data.dom, dom);
 +
 +remoteDispatchDomainEventSend(client, remoteProgram,
 +  REMOTE_PROC_DOMAIN_EVENT_TRAY_MOVED,
 +  
 (xdrproc_t)xdr_remote_domain_event_tray_moved_msg, data);
 +
 +return 0;
 +}
 +
  static virConnectDomainEventGenericCallback domainEventCallbacks[] = {
  VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventLifecycle),
  VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventReboot),
 @@ -516,6 +548,7 @@ static virConnectDomainEventGenericCallback 
 domainEventCallbacks[] = {
  VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventControlError),
  VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventBlockJob),
  VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventDiskChange),
 +VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventTrayMoved),
  };
  
  verify(ARRAY_CARDINALITY(domainEventCallbacks) == VIR_DOMAIN_EVENT_ID_LAST);
 diff --git a/examples/domain-events/events-c/event-test.c 
 b/examples/domain-events/events-c/event-test.c
 index f4938c4..c7bcaeb 100644
 --- a/examples/domain-events/events-c/event-test.c
 +++ b/examples/domain-events/events-c/event-test.c
 @@ -313,6 +313,17 @@ static int myDomainEventDiskChangeCallback(virConnectPtr 
 conn ATTRIBUTE_UNUSED,
  return 0;
  }
  
 +static int myDomainEventTrayMovedCallback(virConnectPtr conn 
 ATTRIBUTE_UNUSED,
 +  virDomainPtr dom,
 +  const char *devAlias,
 +

Re: [libvirt] [PATCH 1/9] Add support for event tray moved of removable disks

2012-03-09 Thread Osier Yang

On 2012年03月09日 16:55, Daniel Veillard wrote:

On Mon, Mar 05, 2012 at 06:25:39PM +0800, Osier Yang wrote:

This patch introduces a new event type for the QMP event
DEVICE_TRAY_MOVED, which occurs when the tray of a removable
disk is moved (i.e opened or closed):

 VIR_DOMAIN_EVENT_ID_TRAY_MOVED

The event's data includes the device alias and the tray's
status, which indicates whether the tray has been opened
or closed.  Thus the callback definition for the event is:

typedef void
(*virConnectDomainEventTrayMovedCallback)(virConnectPtr conn,
   virDomainPtr dom,
   const char *devAlias,
   unsigned int trayOpened,
   void *opaque);


   Hum ... could we make that slightly more generic.
Instead of just being able to report on tray opened or not (i.e. closed)
Let's report TrayChangeCallback,  and have an 'int reason' instead.


Hmm, yes, 'int reason' is good idea.

But for the name, TrayMoved might describe the real action more 
precisely. Unlike DiskChange, it says there was some medium was

changed, TrayMoved only intends to report the tray status changeing
event, nothing really changed, or we can rename it to TrayStatusChange
to indicate the tray status is changed, but IMO it's not much
difference except getting a longer name. :-)


Then for example the API would be able to cope with more set of events,
one of the thing I can think of now would be the ability to emulate
multiple device in one as disk changers,


What does emulate multiple device mean? is it s/device/event/?

and also possibly be able to

provide invormations about the kind of media, i.e. switch from a CD-ROM
to a DVD-WR in the tray.


IMHO we should seperate the events for tray change and
medium change, the info such as the kind of media should handled
by DiskChange instead,

How about defining the callback like:

/**
 * virConnectDomainEventTrayMovedReason:
 *
 * The reason describing why the callback was called
 */
enum {
VIR_DOMAIN_EVENT_TRAY_MOVED_OPEN = 0,
VIR_DOMAIN_EVENT_TRAY_MOVED_CLOSE,

/* Something else such as other driver only emits a
 * event for OPEN+CLOSE.
 */

#ifdef VIR_ENUM_SENTINELS
VIR_DOMAIN_EVENT_TRAY_MOVED_LAST
#endif
} virDomainEventTrayMovedReason;


/**
 * virConnectDomainEventTrayMovedCallback:
 * @conn: connection object
 * @dom: domain on which the event occurred
 * @devAlias: device alias
 * @reason: reason why this callback was called, any of
virDomainEventTrayMovedReason
 * @opaque: application specified data
 *
 * This callback occurs when the tray of a removable device is moved.
 *
 * The callback signature to use when registering for an event of type
 * VIR_DOMAIN_EVENT_ID_TRAY_MOVED wit virConnectDomainEventRegisterAny()
 */
typedef void
(*virConnectDomainEventTrayMovedCallback)(virConnectPtr conn,
virDomainPtr dom,
const char *devAlias,
int reason,
void *opaque);


Thanks
Osier

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

[libvirt] [PATCH 1/9] Add support for event tray moved of removable disks

2012-03-05 Thread Osier Yang
This patch introduces a new event type for the QMP event
DEVICE_TRAY_MOVED, which occurs when the tray of a removable
disk is moved (i.e opened or closed):

VIR_DOMAIN_EVENT_ID_TRAY_MOVED

The event's data includes the device alias and the tray's
status, which indicates whether the tray has been opened
or closed.  Thus the callback definition for the event is:

typedef void
(*virConnectDomainEventTrayMovedCallback)(virConnectPtr conn,
  virDomainPtr dom,
  const char *devAlias,
  unsigned int trayOpened,
  void *opaque);
---
 daemon/remote.c|   33 +++
 examples/domain-events/events-c/event-test.c   |   21 +++-
 examples/domain-events/events-python/event-test.py |4 ++
 include/libvirt/libvirt.h.in   |   20 +++
 python/libvirt-override-virConnect.py  |   10 
 python/libvirt-override.c  |   50 +
 src/conf/domain_event.c|   58 
 src/conf/domain_event.h|6 ++
 src/libvirt_private.syms   |2 +
 src/qemu/qemu_monitor.c|   13 +
 src/qemu/qemu_monitor.h|7 +++
 src/qemu/qemu_monitor_json.c   |   18 ++
 src/qemu/qemu_process.c|   32 +++
 src/remote/remote_driver.c |   34 
 src/remote/remote_protocol.x   |9 +++-
 src/remote_protocol-structs|5 ++
 16 files changed, 320 insertions(+), 2 deletions(-)

diff --git a/daemon/remote.c b/daemon/remote.c
index 74a5f16..cc464fd 100644
--- a/daemon/remote.c
+++ b/daemon/remote.c
@@ -505,6 +505,38 @@ mem_error:
 }
 
 
+static int remoteRelayDomainEventTrayMoved(virConnectPtr conn ATTRIBUTE_UNUSED,
+   virDomainPtr dom,
+   const char *devAlias,
+   unsigned int trayOpened,
+   void *opaque) {
+virNetServerClientPtr client = opaque;
+remote_domain_event_tray_moved_msg data;
+
+if (!client)
+return -1;
+
+VIR_DEBUG(Relaying domain %s %d tray moved devAlias: %s trayOpened: %s,
+  dom-name, dom-id, devAlias, trayOpened ? yes: no);
+
+/* build return data */
+memset(data, 0, sizeof data);
+
+if (!(data.devAlias = strdup(devAlias))) {
+virReportOOMError();
+return -1;
+}
+data.trayOpened = trayOpened;
+
+make_nonnull_domain(data.dom, dom);
+
+remoteDispatchDomainEventSend(client, remoteProgram,
+  REMOTE_PROC_DOMAIN_EVENT_TRAY_MOVED,
+  
(xdrproc_t)xdr_remote_domain_event_tray_moved_msg, data);
+
+return 0;
+}
+
 static virConnectDomainEventGenericCallback domainEventCallbacks[] = {
 VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventLifecycle),
 VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventReboot),
@@ -516,6 +548,7 @@ static virConnectDomainEventGenericCallback 
domainEventCallbacks[] = {
 VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventControlError),
 VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventBlockJob),
 VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventDiskChange),
+VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventTrayMoved),
 };
 
 verify(ARRAY_CARDINALITY(domainEventCallbacks) == VIR_DOMAIN_EVENT_ID_LAST);
diff --git a/examples/domain-events/events-c/event-test.c 
b/examples/domain-events/events-c/event-test.c
index f4938c4..c7bcaeb 100644
--- a/examples/domain-events/events-c/event-test.c
+++ b/examples/domain-events/events-c/event-test.c
@@ -313,6 +313,17 @@ static int myDomainEventDiskChangeCallback(virConnectPtr 
conn ATTRIBUTE_UNUSED,
 return 0;
 }
 
+static int myDomainEventTrayMovedCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
+  virDomainPtr dom,
+  const char *devAlias,
+  unsigned int trayOpened,
+  void *opaque ATTRIBUTE_UNUSED)
+{
+printf(%s EVENT: Domain %s(%d) removable disk's tray moved devAlias: %s 
trayOpened: %s\n,
+   __func__, virDomainGetName(dom), virDomainGetID(dom),
+   devAlias, trayOpened ? yes : no);
+return 0;
+}
 
 static void myFreeFunc(void *opaque)
 {
@@ -349,6 +360,7 @@ int main(int argc, char **argv)
 int callback7ret = -1;
 int callback8ret = -1;
 int callback9ret = -1;
+int callback10ret = -1;
 struct sigaction action_stop;
 
 memset(action_stop, 0, sizeof action_stop);
@@ -419,6 +431,11 @@ int main(int