[libvirt] [PATCH 3/7] add virAgentCommand()

2012-08-14 Thread MATSUDA Daiki

 Add virDrvAgentCommand prototype for drivers.
 Add virAgentCommand() for virDrvAgentCommand.


Signed-off-by: MATSUDA Daiki 
---
 include/libvirt/libvirt-qemu.h |3 ++
 python/generator.py|1 +
 src/driver.h   |4 +++
 src/libvirt-qemu.c |   51 
 src/libvirt_qemu.syms  |5 
 5 files changed, 64 insertions(+), 0 deletions(-)

diff --git a/include/libvirt/libvirt-qemu.h b/include/libvirt/libvirt-qemu.h
index 013ed5a..60b83ef 100644
--- a/include/libvirt/libvirt-qemu.h
+++ b/include/libvirt/libvirt-qemu.h
@@ -50,6 +50,9 @@ typedef enum {
 VIR_DOMAIN_QEMU_AGENT_COMMAND_NOWAIT = 0,
 } virDomainQemuAgentCommandTimeoutValues;
 
+char *virAgentCommand(virDomainPtr domain, const char *cmd,
+  int timeout, unsigned int flags);
+
 # ifdef __cplusplus
 }
 # endif
diff --git a/python/generator.py b/python/generator.py
index 6559ece..68758ad 100755
--- a/python/generator.py
+++ b/python/generator.py
@@ -431,6 +431,7 @@ skip_impl = (
 
 qemu_skip_impl = (
 'virDomainQemuMonitorCommand',
+'virAgentCommand',
 )
 
 
diff --git a/src/driver.h b/src/driver.h
index aab9766..b780e45 100644
--- a/src/driver.h
+++ b/src/driver.h
@@ -688,6 +688,9 @@ typedef int
 typedef int
 (*virDrvDomainQemuMonitorCommand)(virDomainPtr domain, const char *cmd,
   char **result, unsigned int flags);
+typedef char *
+(*virDrvAgentCommand)(virDomainPtr domain, const char *cmd,
+  int timeout, unsigned int flags);
 
 /* Choice of unsigned int rather than pid_t is intentional.  */
 typedef virDomainPtr
@@ -1048,6 +1051,7 @@ struct _virDriver {
 virDrvDomainGetDiskErrors   domainGetDiskErrors;
 virDrvDomainSetMetadata domainSetMetadata;
 virDrvDomainGetMetadata domainGetMetadata;
+virDrvAgentCommand  qemuAgentCommand;
 };
 
 typedef int
diff --git a/src/libvirt-qemu.c b/src/libvirt-qemu.c
index 78480bb..49dfc20 100644
--- a/src/libvirt-qemu.c
+++ b/src/libvirt-qemu.c
@@ -185,3 +185,54 @@ error:
 virDispatchError(conn);
 return NULL;
 }
+
+/**
+ * virAgentCommand:
+ * @domain: a domain object
+ * @cmd: the guest agent command string
+ * @timeout: timeout seconds
+ * @flags: execution flags
+ *
+ * Execute an arbitrary Guest Agent command.
+ *
+ * Issue @cmd to the guest agent running in @domain.
+ * If @result is NULL, then don't wait for a result (and @timeout
+ * must be 0).  Otherwise, wait for @timeout seconds for a
+ * @timeout must be -2, -1, 0 or positive.
+ * VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK(-2): meaning to block forever waiting 
for
+ * a result.
+ * VIR_DOMAIN_QEMU_AGENT_COMMAND_DEFAULT(-1): use default timeout value.
+ * VIR_DOMAIN_QEMU_AGENT_COMMAND_NOWAIT(0): does not wait.
+ * positive value: wait for @timeout seconds
+ *
+ * Returns strings if success, NULL in failure.
+ */
+char *
+virAgentCommand(virDomainPtr domain,
+const char *cmd,
+int timeout,
+unsigned int flags)
+{
+virConnectPtr conn;
+
+VIR_DEBUG("domain=%p, cmd=%s, timeout=%d, flags=%x",
+  domain, cmd, timeout, flags);
+
+if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
+virLibDomainError(NULL, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
+virDispatchError(NULL);
+return NULL;
+}
+
+conn = domain->conn;
+
+if (conn->driver->qemuAgentCommand) {
+return conn->driver->qemuAgentCommand(domain, cmd, timeout, flags);
+}
+
+virLibConnError(conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
+
+/* Copy to connection error object for back compatability */
+virDispatchError(domain->conn);
+return NULL;
+}
diff --git a/src/libvirt_qemu.syms b/src/libvirt_qemu.syms
index 8447730..f1a4bb4 100644
--- a/src/libvirt_qemu.syms
+++ b/src/libvirt_qemu.syms
@@ -19,3 +19,8 @@ LIBVIRT_QEMU_0.9.4 {
 global:
 virDomainQemuAttach;
 } LIBVIRT_QEMU_0.8.3;
+
+LIBVIRT_QEMU_0.10.0 {
+global:
+virAgentCommand;
+} LIBVIRT_QEMU_0.9.4;
-- 
1.7.1

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


Re: [libvirt] [PATCH 3/7] add virAgentCommand()

2012-08-16 Thread Martin Kletzander
On 08/15/2012 03:36 AM, MATSUDA Daiki wrote:
> diff --git a/include/libvirt/libvirt-qemu.h b/include/libvirt/libvirt-qemu.h
> index 013ed5a..60b83ef 100644
> --- a/include/libvirt/libvirt-qemu.h
> +++ b/include/libvirt/libvirt-qemu.h
> @@ -50,6 +50,9 @@ typedef enum {
>  VIR_DOMAIN_QEMU_AGENT_COMMAND_NOWAIT = 0,
>  } virDomainQemuAgentCommandTimeoutValues;
>  
> +char *virAgentCommand(virDomainPtr domain, const char *cmd,
> +  int timeout, unsigned int flags);
> +

I wondered why this is type 'char *', when we can use 'int' as usual and
have '**result' (same as monitor command does).

> diff --git a/src/libvirt-qemu.c b/src/libvirt-qemu.c
> index 78480bb..49dfc20 100644
> --- a/src/libvirt-qemu.c
> +++ b/src/libvirt-qemu.c
> @@ -185,3 +185,54 @@ error:
>  virDispatchError(conn);
>  return NULL;
>  }
> +
> +/**
> + * virAgentCommand:
> + * @domain: a domain object
> + * @cmd: the guest agent command string
> + * @timeout: timeout seconds
> + * @flags: execution flags
> + *
> + * Execute an arbitrary Guest Agent command.
> + *
> + * Issue @cmd to the guest agent running in @domain.
> + * If @result is NULL, then don't wait for a result (and @timeout

And then I noticed that there is no @result here, so maybe you wanted to
make it that way and didn't change something?

> + * must be 0).  Otherwise, wait for @timeout seconds for a
> + * @timeout must be -2, -1, 0 or positive.
> + * VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK(-2): meaning to block forever waiting 
> for
> + * a result.
> + * VIR_DOMAIN_QEMU_AGENT_COMMAND_DEFAULT(-1): use default timeout value.
> + * VIR_DOMAIN_QEMU_AGENT_COMMAND_NOWAIT(0): does not wait.
> + * positive value: wait for @timeout seconds
> + *
> + * Returns strings if success, NULL in failure.
> + */
> +char *
> +virAgentCommand(virDomainPtr domain,
> +const char *cmd,
> +int timeout,
> +unsigned int flags)
> +{
> +virConnectPtr conn;
> +
> +VIR_DEBUG("domain=%p, cmd=%s, timeout=%d, flags=%x",
> +  domain, cmd, timeout, flags);
> +
> +if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
> +virLibDomainError(NULL, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
> +virDispatchError(NULL);
> +return NULL;
> +}
> +
> +conn = domain->conn;
> +
> +if (conn->driver->qemuAgentCommand) {
> +return conn->driver->qemuAgentCommand(domain, cmd, timeout, flags);

Shouldn't this be allowed only for read-only connections?

> +}
> +
> +virLibConnError(conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
> +
> +/* Copy to connection error object for back compatability */

s/compatability/compatibility/

> +virDispatchError(domain->conn);

You have 'domain->conn' in 'conn' already.

Martin

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


Re: [libvirt] [PATCH 3/7] add virAgentCommand()

2012-08-19 Thread MATSUDA, Daiki

(2012/08/16 22:13), Martin Kletzander wrote:

On 08/15/2012 03:36 AM, MATSUDA Daiki wrote:

diff --git a/include/libvirt/libvirt-qemu.h b/include/libvirt/libvirt-qemu.h
index 013ed5a..60b83ef 100644
--- a/include/libvirt/libvirt-qemu.h
+++ b/include/libvirt/libvirt-qemu.h
@@ -50,6 +50,9 @@ typedef enum {
  VIR_DOMAIN_QEMU_AGENT_COMMAND_NOWAIT = 0,
  } virDomainQemuAgentCommandTimeoutValues;

+char *virAgentCommand(virDomainPtr domain, const char *cmd,
+  int timeout, unsigned int flags);
+


I wondered why this is type 'char *', when we can use 'int' as usual and
have '**result' (same as monitor command does).


It depends on generating the code automatically Eric suggested.
It decides the returning type.


diff --git a/src/libvirt-qemu.c b/src/libvirt-qemu.c
index 78480bb..49dfc20 100644
--- a/src/libvirt-qemu.c
+++ b/src/libvirt-qemu.c
@@ -185,3 +185,54 @@ error:
  virDispatchError(conn);
  return NULL;
  }
+
+/**
+ * virAgentCommand:
+ * @domain: a domain object
+ * @cmd: the guest agent command string
+ * @timeout: timeout seconds
+ * @flags: execution flags
+ *
+ * Execute an arbitrary Guest Agent command.
+ *
+ * Issue @cmd to the guest agent running in @domain.
+ * If @result is NULL, then don't wait for a result (and @timeout


And then I noticed that there is no @result here, so maybe you wanted to
make it that way and didn't change something?


It is my mistake.


+ * must be 0).  Otherwise, wait for @timeout seconds for a
+ * @timeout must be -2, -1, 0 or positive.
+ * VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK(-2): meaning to block forever waiting 
for
+ * a result.
+ * VIR_DOMAIN_QEMU_AGENT_COMMAND_DEFAULT(-1): use default timeout value.
+ * VIR_DOMAIN_QEMU_AGENT_COMMAND_NOWAIT(0): does not wait.
+ * positive value: wait for @timeout seconds
+ *
+ * Returns strings if success, NULL in failure.
+ */
+char *
+virAgentCommand(virDomainPtr domain,
+const char *cmd,
+int timeout,
+unsigned int flags)
+{
+virConnectPtr conn;
+
+VIR_DEBUG("domain=%p, cmd=%s, timeout=%d, flags=%x",
+  domain, cmd, timeout, flags);
+
+if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
+virLibDomainError(NULL, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
+virDispatchError(NULL);
+return NULL;
+}
+
+conn = domain->conn;
+
+if (conn->driver->qemuAgentCommand) {
+return conn->driver->qemuAgentCommand(domain, cmd, timeout, flags);


Shouldn't this be allowed only for read-only connections?


I do not uderstand what you say.


+}
+
+virLibConnError(conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
+
+/* Copy to connection error object for back compatability */


s/compatability/compatibility/


+virDispatchError(domain->conn);


You have 'domain->conn' in 'conn' already.

Martin






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


Re: [libvirt] [PATCH 3/7] add virAgentCommand()

2012-08-20 Thread Martin Kletzander
On 08/20/2012 02:16 AM, MATSUDA, Daiki wrote:
> (2012/08/16 22:13), Martin Kletzander wrote:
>> On 08/15/2012 03:36 AM, MATSUDA Daiki wrote:
[...]
>>> +char *
>>> +virAgentCommand(virDomainPtr domain,
>>> +const char *cmd,
>>> +int timeout,
>>> +unsigned int flags)
>>> +{
>>> +virConnectPtr conn;
>>> +
>>> +VIR_DEBUG("domain=%p, cmd=%s, timeout=%d, flags=%x",
>>> +  domain, cmd, timeout, flags);
>>> +
>>> +if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
>>> +virLibDomainError(NULL, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
>>> +virDispatchError(NULL);
>>> +return NULL;
>>> +}
>>> +
>>> +conn = domain->conn;
>>> +
>>> +if (conn->driver->qemuAgentCommand) {
>>> +return conn->driver->qemuAgentCommand(domain, cmd, timeout,
>>> flags);
>>
>> Shouldn't this be allowed only for read-only connections?
> 
> I do not uderstand what you say.
> 

I meant a check similar to this:

if (conn->flags & VIR_CONNECT_RO)
 virLibDomainError(domain, VIR_ERR_OPERATION_DENIED, __FUNCTION__);

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