Re: [libvirt] [PATCH 2/4] Add new virDomainShutdownFlags API

2012-01-19 Thread Eric Blake
On 01/17/2012 04:44 AM, Michal Privoznik wrote:
 Add a new API virDomainShutdownFlags and define:
 
 VIR_DOMAIN_SHUTDOWN_DEFAULT= 0,
 VIR_DOMAIN_SHUTDOWN_ACPI_POWER_BTN = (1  0),
 VIR_DOMAIN_SHUTDOWN_GUEST_AGENT= (1  1),
 
 Also define some flags for the reboot API
 
 VIR_DOMAIN_REBOOT_DEFAULT= 0,
 VIR_DOMAIN_REBOOT_ACPI_POWER_BTN = (1  0),
 VIR_DOMAIN_REBOOT_GUEST_AGENT= (1  1),
 
 Although these two APIs currently have the same flags, using
 separate enums allows them to expand separately in the future.

Fair enough.

 
 Add stub impls of the new API for all existing drivers
 ---

I might have split this into several patches, but I think doing it in
one go is okay since the stubs are trivial.

  include/libvirt/libvirt.h.in |   15 +
  src/driver.h |5 +++
  src/libvirt.c|   65 
 +-
  src/libvirt_public.syms  |4 ++

That is, I might have done part 1 (the public API),

  src/remote/remote_driver.c   |1 +
  src/remote/remote_protocol.x |8 -
  src/remote_protocol-structs  |5 +++

part 2 (the RPC),

  src/esx/esx_driver.c |   11 ++-
  src/libxl/libxl_driver.c |   12 +++-
  src/openvz/openvz_driver.c   |1 +
  src/test/test_driver.c   |   11 ++-
  src/uml/uml_driver.c |   11 ++-
  src/vbox/vbox_tmpl.c |   11 ++-
  src/vmware/vmware_driver.c   |1 +
  src/xen/xen_driver.c |   14 -
  src/xenapi/xenapi_driver.c   |   12 +++-

and part 3 (the stubs).

 +++ b/include/libvirt/libvirt.h.in
 @@ -1148,7 +1148,22 @@ virDomainPtrvirDomainLookupByUUID   
 (virConnectPtr conn,
  virDomainPtrvirDomainLookupByUUIDString (virConnectPtr conn,
  const char *uuid);
  
 +typedef enum {
 +VIR_DOMAIN_SHUTDOWN_DEFAULT= 0,
 +VIR_DOMAIN_SHUTDOWN_ACPI_POWER_BTN = (1  0),
 +VIR_DOMAIN_SHUTDOWN_GUEST_AGENT= (1  1),
 +} virDomainShutdownFlagValues;

No documentation comments?  Even a /** doc */ prior to the typedef that
mentions virDomainShutdownFlagValues might be helpful to the doc
generation process.

 +++ b/src/libvirt.c
 @@ -3106,14 +3106,77 @@ error:
  }
  
  /**
 + * virDomainShutdownFlags:
 + * @domain: a domain object
 + * @flags: bitwise-OR of virDomainShutdownFlagValues
 + *
 + * Shutdown a domain, the domain object is still usable thereafter but
 + * the domain OS is being stopped. Note that the guest OS may ignore the
 + * request.  For guests that react to a shutdown request, the differences
 + * from virDomainDestroy() are that the guest's disk storage will be in a
 + * stable state rather than having the (virtual) power cord pulled, and
 + * this command returns as soon as the shutdown request is issued rather
 + * than blocking until the guest is no longer running.
 + *
 + * If the domain is transient and has any snapshot metadata (see
 + * virDomainSnapshotNum()), then that metadata will automatically
 + * be deleted when the domain quits.
 + *
 + * If @flags is set to zero, then the hypervisor will chose the
 + * method of shutdown it considers best. To have greater control
 + * pass one of the virDomainShutdownFlagValues.

Maybe mention the existing flag names:

Use VIR_DOMAIN_SHUTDOWN_ACPI_POWER_BTN to trigger a shutdown through an
ACPI interrupt, and VIR_DOMAIN_SHUTDOWN_GUEST_AGENT to trigger a
shutdown through a guest agent call (this requires that the domain have
a channel device appropriately wired to a guest agent).

Is it an error if multiple flags are requested at once?

 +/**
   * virDomainReboot:
   * @domain: a domain object
 - * @flags: extra flags; not used yet, so callers should always pass 0
 + * @flags: bitwise-OR of virDomainRebootFlagValues
   *
   * Reboot a domain, the domain object is still usable there after but
   * the domain OS is being stopped for a restart.
   * Note that the guest OS may ignore the request.
   *
 + * If @flags is set to zero, then the hypervisor will chose the
 + * method of shutdown it considers best. To have greater control
 + * pass one of the virDomainRebootFlagValues.

Again, mention the possible flag values, and that an agent request
requires additional support from the XML.

 +++ b/src/openvz/openvz_driver.c
 @@ -1693,6 +1693,7 @@ static virDriver openvzDriver = {
  .domainSuspend = openvzDomainSuspend, /* 0.8.3 */
  .domainResume = openvzDomainResume, /* 0.8.3 */
  .domainShutdown = openvzDomainShutdown, /* 0.3.1 */
 +.domainShutdownFlags = openvzDomainShutdownFlags, /* 0.9.10 */

Hmm.  Are we setting ourselves up for issues down the road by sharing
shutdown and destroy implementations for openvz?  But it's a
pre-existing problem, not made worse by the patch, and okay as long as
we reject all flag values.

 +++ b/src/vmware/vmware_driver.c
 @@ -980,6 +980,7 @@ static virDriver vmwareDriver = {
  .domainSuspend = 

[libvirt] [PATCH 2/4] Add new virDomainShutdownFlags API

2012-01-17 Thread Michal Privoznik
Add a new API virDomainShutdownFlags and define:

VIR_DOMAIN_SHUTDOWN_DEFAULT= 0,
VIR_DOMAIN_SHUTDOWN_ACPI_POWER_BTN = (1  0),
VIR_DOMAIN_SHUTDOWN_GUEST_AGENT= (1  1),

Also define some flags for the reboot API

VIR_DOMAIN_REBOOT_DEFAULT= 0,
VIR_DOMAIN_REBOOT_ACPI_POWER_BTN = (1  0),
VIR_DOMAIN_REBOOT_GUEST_AGENT= (1  1),

Although these two APIs currently have the same flags, using
separate enums allows them to expand separately in the future.

Add stub impls of the new API for all existing drivers
---
 include/libvirt/libvirt.h.in |   15 +
 src/driver.h |5 +++
 src/esx/esx_driver.c |   11 ++-
 src/libvirt.c|   65 +-
 src/libvirt_public.syms  |4 ++
 src/libxl/libxl_driver.c |   12 +++-
 src/openvz/openvz_driver.c   |1 +
 src/remote/remote_driver.c   |1 +
 src/remote/remote_protocol.x |8 -
 src/remote_protocol-structs  |5 +++
 src/test/test_driver.c   |   11 ++-
 src/uml/uml_driver.c |   11 ++-
 src/vbox/vbox_tmpl.c |   11 ++-
 src/vmware/vmware_driver.c   |1 +
 src/xen/xen_driver.c |   14 -
 src/xenapi/xenapi_driver.c   |   12 +++-
 16 files changed, 177 insertions(+), 10 deletions(-)

diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index e436f3c..27546af 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -1148,7 +1148,22 @@ virDomainPtrvirDomainLookupByUUID   
(virConnectPtr conn,
 virDomainPtrvirDomainLookupByUUIDString (virConnectPtr conn,
 const char *uuid);
 
+typedef enum {
+VIR_DOMAIN_SHUTDOWN_DEFAULT= 0,
+VIR_DOMAIN_SHUTDOWN_ACPI_POWER_BTN = (1  0),
+VIR_DOMAIN_SHUTDOWN_GUEST_AGENT= (1  1),
+} virDomainShutdownFlagValues;
+
 int virDomainShutdown   (virDomainPtr domain);
+int virDomainShutdownFlags  (virDomainPtr domain,
+ unsigned int flags);
+
+typedef enum {
+VIR_DOMAIN_REBOOT_DEFAULT= 0,
+VIR_DOMAIN_REBOOT_ACPI_POWER_BTN = (1  0),
+VIR_DOMAIN_REBOOT_GUEST_AGENT= (1  1),
+} virDomainRebootFlagValues;
+
 int virDomainReboot (virDomainPtr domain,
  unsigned int flags);
 int virDomainReset  (virDomainPtr domain,
diff --git a/src/driver.h b/src/driver.h
index 24636a4..6222bed 100644
--- a/src/driver.h
+++ b/src/driver.h
@@ -793,6 +793,10 @@ typedef int
   virTypedParameterPtr params,
   int *nparams,
   unsigned int flags);
+typedef int
+(*virDrvDomainShutdownFlags)(virDomainPtr domain,
+ unsigned int flags);
+
 
 /**
  * _virDriver:
@@ -829,6 +833,7 @@ struct _virDriver {
 virDrvDomainSuspenddomainSuspend;
 virDrvDomainResume domainResume;
 virDrvDomainShutdown   domainShutdown;
+virDrvDomainShutdownFlags   domainShutdownFlags;
 virDrvDomainReboot domainReboot;
 virDrvDomainReset   domainReset;
 virDrvDomainDestroydomainDestroy;
diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
index 1e424eb..4ad7a37 100644
--- a/src/esx/esx_driver.c
+++ b/src/esx/esx_driver.c
@@ -1886,7 +1886,7 @@ esxDomainResume(virDomainPtr domain)
 
 
 static int
-esxDomainShutdown(virDomainPtr domain)
+esxDomainShutdownFlags(virDomainPtr domain, unsigned int flags)
 {
 int result = -1;
 esxPrivate *priv = domain-conn-privateData;
@@ -1894,6 +1894,8 @@ esxDomainShutdown(virDomainPtr domain)
 esxVI_String *propertyNameList = NULL;
 esxVI_VirtualMachinePowerState powerState;
 
+virCheckFlags(0, -1);
+
 if (esxVI_EnsureSession(priv-primary)  0) {
 return -1;
 }
@@ -1927,6 +1929,12 @@ esxDomainShutdown(virDomainPtr domain)
 }
 
 
+static int
+esxDomainShutdown(virDomainPtr domain)
+{
+return esxDomainShutdownFlags(domain, 0);
+}
+
 
 static int
 esxDomainReboot(virDomainPtr domain, unsigned int flags)
@@ -4960,6 +4968,7 @@ static virDriver esxDriver = {
 .domainSuspend = esxDomainSuspend, /* 0.7.0 */
 .domainResume = esxDomainResume, /* 0.7.0 */
 .domainShutdown = esxDomainShutdown, /* 0.7.0 */
+.domainShutdownFlags = esxDomainShutdownFlags, /* 0.9.10 */
 .domainReboot = esxDomainReboot, /* 0.7.0 */
 .domainDestroy = esxDomainDestroy, /* 0.7.0 */
 .domainDestroyFlags = esxDomainDestroyFlags, /* 0.9.4 */
diff --git a/src/libvirt.c b/src/libvirt.c
index a540424..9409a24 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -3106,14 +3106,77 @@ error:
 }
 
 /**
+ * virDomainShutdownFlags:
+ * @domain: a domain object
+ * @flags: 

Re: [libvirt] [PATCH 2/4] Add new virDomainShutdownFlags API

2011-10-19 Thread MATSUDA, Daiki

diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index 83f4f3c..eaf8bbd 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -4312,6 +4312,7 @@ static virDriver remote_driver = {
  .domainSuspend = remoteDomainSuspend, /* 0.3.0 */
  .domainResume = remoteDomainResume, /* 0.3.0 */
  .domainShutdown = remoteDomainShutdown, /* 0.3.0 */
+.domainShutdownFlags = remoteDomainShutdownFlags, /* 0.9.7 */
  .domainReboot = remoteDomainReboot, /* 0.3.0 */
  .domainReset = remoteDomainReset, /* 0.9.7 */
  .domainDestroy = remoteDomainDestroy, /* 0.3.0 */
diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x
index c8a92fd..34e4b2a 100644
--- a/src/remote/remote_protocol.x
+++ b/src/remote/remote_protocol.x
@@ -2234,6 +2234,12 @@ struct remote_domain_get_control_info_ret { /* insert@1 
*/
  unsigned hyper stateTime;
  };

+struct remote_domain_shutdown_flags_args {
+remote_nonnull_domain dom;
+unsigned int flags;
+};
+
+
  /*- Protocol. -*/

  /* Define the program number, protocol version and procedure numbers here. */
@@ -2525,7 +2531,8 @@ enum remote_procedure {
  REMOTE_PROC_DOMAIN_MIGRATE_GET_MAX_SPEED = 242, /* autogen autogen */
  REMOTE_PROC_DOMAIN_BLOCK_STATS_FLAGS = 243, /* skipgen skipgen */
  REMOTE_PROC_DOMAIN_SNAPSHOT_GET_PARENT = 244, /* autogen autogen */
-REMOTE_PROC_DOMAIN_RESET = 245 /* autogen autogen */
+REMOTE_PROC_DOMAIN_RESET = 245, /* autogen autogen */
+REMOTE_PROC_DOMAIN_SHUTDOWN_FLAGS = 246 /* autogen autogen */

  /*
   * Notice how the entries are grouped in sets of 10 ?


I think it does not works well if target is localhost or not, because 
remoteDomainShutdownFlags() function is not implemented. So, do you have 
a plan ?


MATSUDA Daiki

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


Re: [libvirt] [PATCH 2/4] Add new virDomainShutdownFlags API

2011-10-19 Thread Eric Blake

On 10/19/2011 06:22 PM, MATSUDA, Daiki wrote:

diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index 83f4f3c..eaf8bbd 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -4312,6 +4312,7 @@ static virDriver remote_driver = {
.domainSuspend = remoteDomainSuspend, /* 0.3.0 */
.domainResume = remoteDomainResume, /* 0.3.0 */
.domainShutdown = remoteDomainShutdown, /* 0.3.0 */
+ .domainShutdownFlags = remoteDomainShutdownFlags, /* 0.9.7 */



+ REMOTE_PROC_DOMAIN_SHUTDOWN_FLAGS = 246 /* autogen autogen */

/*
* Notice how the entries are grouped in sets of 10 ?


I think it does not works well if target is localhost or not, because
remoteDomainShutdownFlags() function is not implemented. So, do you have
a plan ?


The notation autogen autogen after REMOTE_PROC_DOMAIN_SHUTDOWN_FLAGS 
_is_ what implements remoteDomainShutdownFlags().  See 
src/rpc/genprotocol.pl.


--
Eric Blake   ebl...@redhat.com+1-801-349-2682
Libvirt virtualization library http://libvirt.org

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


[libvirt] [PATCH 2/4] Add new virDomainShutdownFlags API

2011-10-05 Thread Daniel P. Berrange
From: Daniel P. Berrange berra...@redhat.com

Add a new API virDomainShutdownFlags and define:

VIR_DOMAIN_SHUTDOWN_DEFAULT= 0,
VIR_DOMAIN_SHUTDOWN_ACPI_POWER_BTN = (1  0),
VIR_DOMAIN_SHUTDOWN_GUEST_AGENT= (1  1),

Also define some flags for the reboot API

VIR_DOMAIN_REBOOT_DEFAULT= 0,
VIR_DOMAIN_REBOOT_ACPI_POWER_BTN = (1  0),
VIR_DOMAIN_REBOOT_GUEST_AGENT= (1  1),

Although these two APIs currently have the same flags, using
separate enums allows them to expand seperately in the future.

Add stub impls of the new API for all existing drivers
---
 include/libvirt/libvirt.h.in |   15 ++
 src/driver.h |5 +++
 src/esx/esx_driver.c |   11 +++-
 src/libvirt.c|   59 ++
 src/libvirt_public.syms  |1 +
 src/libxl/libxl_driver.c |   12 -
 src/openvz/openvz_driver.c   |1 +
 src/remote/remote_driver.c   |1 +
 src/remote/remote_protocol.x |9 +-
 src/test/test_driver.c   |   11 +++-
 src/uml/uml_driver.c |   11 +++-
 src/vbox/vbox_tmpl.c |   10 ++-
 src/vmware/vmware_driver.c   |1 +
 src/xen/xen_driver.c |   13 -
 src/xenapi/xenapi_driver.c   |   11 +++-
 15 files changed, 162 insertions(+), 9 deletions(-)

diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index bd7a0f7..dba2099 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -1028,7 +1028,22 @@ virDomainPtrvirDomainLookupByUUID   
(virConnectPtr conn,
 virDomainPtrvirDomainLookupByUUIDString (virConnectPtr conn,
 const char *uuid);
 
+typedef enum {
+VIR_DOMAIN_SHUTDOWN_DEFAULT= 0,
+VIR_DOMAIN_SHUTDOWN_ACPI_POWER_BTN = (1  0),
+VIR_DOMAIN_SHUTDOWN_GUEST_AGENT= (1  1),
+} virDomainShutdownFlagValues;
+
 int virDomainShutdown   (virDomainPtr domain);
+int virDomainShutdownFlags  (virDomainPtr domain,
+ unsigned int flags);
+
+typedef enum {
+VIR_DOMAIN_REBOOT_DEFAULT= 0,
+VIR_DOMAIN_REBOOT_ACPI_POWER_BTN = (1  0),
+VIR_DOMAIN_REBOOT_GUEST_AGENT= (1  1),
+} virDomainRebootFlagValues;
+
 int virDomainReboot (virDomainPtr domain,
  unsigned int flags);
 int virDomainReset  (virDomainPtr domain,
diff --git a/src/driver.h b/src/driver.h
index f85a1b1..86857d5 100644
--- a/src/driver.h
+++ b/src/driver.h
@@ -725,6 +725,10 @@ typedef int
 (*virDrvDomainBlockPull)(virDomainPtr dom, const char *path,
  unsigned long bandwidth, unsigned int flags);
 
+typedef int
+(*virDrvDomainShutdownFlags)(virDomainPtr domain,
+ unsigned int flags);
+
 
 /**
  * _virDriver:
@@ -881,6 +885,7 @@ struct _virDriver {
 virDrvDomainGetBlockJobInfo domainGetBlockJobInfo;
 virDrvDomainBlockJobSetSpeed domainBlockJobSetSpeed;
 virDrvDomainBlockPull domainBlockPull;
+virDrvDomainShutdownFlags domainShutdownFlags;
 };
 
 typedef int
diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
index 3f26557..b206239 100644
--- a/src/esx/esx_driver.c
+++ b/src/esx/esx_driver.c
@@ -1870,7 +1870,7 @@ esxDomainResume(virDomainPtr domain)
 
 
 static int
-esxDomainShutdown(virDomainPtr domain)
+esxDomainShutdownFlags(virDomainPtr domain, unsigned int flags)
 {
 int result = -1;
 esxPrivate *priv = domain-conn-privateData;
@@ -1878,6 +1878,8 @@ esxDomainShutdown(virDomainPtr domain)
 esxVI_String *propertyNameList = NULL;
 esxVI_VirtualMachinePowerState powerState;
 
+virCheckFlags(0, -1);
+
 if (esxVI_EnsureSession(priv-primary)  0) {
 return -1;
 }
@@ -1911,6 +1913,12 @@ esxDomainShutdown(virDomainPtr domain)
 }
 
 
+static int
+esxDomainShutdown(virDomainPtr domain)
+{
+return esxDomainShutdownFlags(domain, 0);
+}
+
 
 static int
 esxDomainReboot(virDomainPtr domain, unsigned int flags)
@@ -4829,6 +4837,7 @@ static virDriver esxDriver = {
 .domainSuspend = esxDomainSuspend, /* 0.7.0 */
 .domainResume = esxDomainResume, /* 0.7.0 */
 .domainShutdown = esxDomainShutdown, /* 0.7.0 */
+.domainShutdownFlags = esxDomainShutdownFlags, /* 0.9.7 */
 .domainReboot = esxDomainReboot, /* 0.7.0 */
 .domainDestroy = esxDomainDestroy, /* 0.7.0 */
 .domainDestroyFlags = esxDomainDestroyFlags, /* 0.9.4 */
diff --git a/src/libvirt.c b/src/libvirt.c
index 9080b2f..1607b99 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -2970,6 +2970,65 @@ error:
 }
 
 /**
+ * virDomainShutdownFlags:
+ * @domain: a domain object
+ * @flags: optional flags
+ *
+ * Shutdown a domain, the domain object is still usable thereafter but
+ * the domain OS is being stopped. Note that the guest OS