[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 2/4] Define remote wire protocol & impls for virDomainQemuAttach



* daemon/remote.c: Server side dispatcher
* src/remote/remote_driver.c: Client side dispatcher
* src/remote/qemu_protocol.x: Wire protocol definition
---
 daemon/qemu_dispatch_args.h       |    1 +
 daemon/qemu_dispatch_prototypes.h |    8 ++++++++
 daemon/qemu_dispatch_ret.h        |    1 +
 daemon/qemu_dispatch_table.h      |    5 +++++
 daemon/remote.c                   |   35 +++++++++++++++++++++++++++++++++++
 src/remote/qemu_protocol.c        |   20 ++++++++++++++++++++
 src/remote/qemu_protocol.h        |   16 ++++++++++++++++
 src/remote/qemu_protocol.x        |   13 ++++++++++++-
 src/remote/remote_driver.c        |   30 +++++++++++++++++++++++++++++-
 9 files changed, 127 insertions(+), 2 deletions(-)

diff --git a/daemon/qemu_dispatch_args.h b/daemon/qemu_dispatch_args.h
index e278fa4..c85b20e 100644
--- a/daemon/qemu_dispatch_args.h
+++ b/daemon/qemu_dispatch_args.h
@@ -3,3 +3,4 @@
  */
 
     qemu_monitor_command_args val_qemu_monitor_command_args;
+    qemu_attach_args val_qemu_attach_args;
diff --git a/daemon/qemu_dispatch_prototypes.h b/daemon/qemu_dispatch_prototypes.h
index 4ec1ab4..d22e1d8 100644
--- a/daemon/qemu_dispatch_prototypes.h
+++ b/daemon/qemu_dispatch_prototypes.h
@@ -2,6 +2,14 @@
  * Do not edit this file.  Any changes you make will be lost.
  */
 
+static int qemuDispatchAttach(
+    struct qemud_server *server,
+    struct qemud_client *client,
+    virConnectPtr conn,
+    remote_message_header *hdr,
+    remote_error *rerr,
+    qemu_attach_args *args,
+    qemu_attach_ret *ret);
 static int qemuDispatchMonitorCommand(
     struct qemud_server *server,
     struct qemud_client *client,
diff --git a/daemon/qemu_dispatch_ret.h b/daemon/qemu_dispatch_ret.h
index 492dcf9..20392c4 100644
--- a/daemon/qemu_dispatch_ret.h
+++ b/daemon/qemu_dispatch_ret.h
@@ -3,3 +3,4 @@
  */
 
     qemu_monitor_command_ret val_qemu_monitor_command_ret;
+    qemu_attach_ret val_qemu_attach_ret;
diff --git a/daemon/qemu_dispatch_table.h b/daemon/qemu_dispatch_table.h
index c196a3c..9084a74 100644
--- a/daemon/qemu_dispatch_table.h
+++ b/daemon/qemu_dispatch_table.h
@@ -12,3 +12,8 @@
     .args_filter = (xdrproc_t) xdr_qemu_monitor_command_args,
     .ret_filter = (xdrproc_t) xdr_qemu_monitor_command_ret,
 },
+{   /* Attach => 2 */
+    .fn = (dispatch_fn) qemuDispatchAttach,
+    .args_filter = (xdrproc_t) xdr_qemu_attach_args,
+    .ret_filter = (xdrproc_t) xdr_qemu_attach_ret,
+},
diff --git a/daemon/remote.c b/daemon/remote.c
index 214f7a4..d3b7401 100644
--- a/daemon/remote.c
+++ b/daemon/remote.c
@@ -8693,6 +8693,41 @@ cleanup:
 
 
 static int
+qemuDispatchAttach(struct qemud_server *server ATTRIBUTE_UNUSED,
+                   struct qemud_client *client ATTRIBUTE_UNUSED,
+                   virConnectPtr conn,
+                   remote_message_header *hdr ATTRIBUTE_UNUSED,
+                   remote_error *rerr,
+                   qemu_attach_args *args,
+                   qemu_attach_ret *ret)
+{
+    virDomainPtr dom = NULL;
+    int rv = -1;
+
+    if (!conn) {
+        virNetError(VIR_ERR_INTERNAL_ERROR, "%s", _("connection not open"));
+        goto cleanup;
+    }
+
+    if (!(dom = virDomainQemuAttach(conn,
+                                    args->pid,
+                                    args->flags)))
+        goto cleanup;
+
+    make_nonnull_domain(&ret->dom, dom);
+
+    rv = 0;
+
+cleanup:
+    if (rv < 0)
+        remoteDispatchError(rerr);
+    if (dom)
+        virDomainFree(dom);
+    return rv;
+}
+
+
+static int
 remoteDispatchDomainOpenConsole(struct qemud_server *server ATTRIBUTE_UNUSED,
                                 struct qemud_client *client,
                                 virConnectPtr conn,
diff --git a/src/remote/qemu_protocol.c b/src/remote/qemu_protocol.c
index 81916ed..b1a8d9f 100644
--- a/src/remote/qemu_protocol.c
+++ b/src/remote/qemu_protocol.c
@@ -32,6 +32,26 @@ xdr_qemu_monitor_command_ret (XDR *xdrs, qemu_monitor_command_ret *objp)
 }
 
 bool_t
+xdr_qemu_attach_args (XDR *xdrs, qemu_attach_args *objp)
+{
+
+         if (!xdr_int (xdrs, &objp->pid))
+                 return FALSE;
+         if (!xdr_u_int (xdrs, &objp->flags))
+                 return FALSE;
+        return TRUE;
+}
+
+bool_t
+xdr_qemu_attach_ret (XDR *xdrs, qemu_attach_ret *objp)
+{
+
+         if (!xdr_remote_nonnull_domain (xdrs, &objp->dom))
+                 return FALSE;
+        return TRUE;
+}
+
+bool_t
 xdr_qemu_procedure (XDR *xdrs, qemu_procedure *objp)
 {
 
diff --git a/src/remote/qemu_protocol.h b/src/remote/qemu_protocol.h
index b822187..1654450 100644
--- a/src/remote/qemu_protocol.h
+++ b/src/remote/qemu_protocol.h
@@ -28,11 +28,23 @@ struct qemu_monitor_command_ret {
         remote_nonnull_string result;
 };
 typedef struct qemu_monitor_command_ret qemu_monitor_command_ret;
+
+struct qemu_attach_args {
+        int pid;
+        u_int flags;
+};
+typedef struct qemu_attach_args qemu_attach_args;
+
+struct qemu_attach_ret {
+        remote_nonnull_domain dom;
+};
+typedef struct qemu_attach_ret qemu_attach_ret;
 #define QEMU_PROGRAM 0x20008087
 #define QEMU_PROTOCOL_VERSION 1
 
 enum qemu_procedure {
         QEMU_PROC_MONITOR_COMMAND = 1,
+        QEMU_PROC_ATTACH = 2,
 };
 typedef enum qemu_procedure qemu_procedure;
 
@@ -41,11 +53,15 @@ typedef enum qemu_procedure qemu_procedure;
 #if defined(__STDC__) || defined(__cplusplus)
 extern  bool_t xdr_qemu_monitor_command_args (XDR *, qemu_monitor_command_args*);
 extern  bool_t xdr_qemu_monitor_command_ret (XDR *, qemu_monitor_command_ret*);
+extern  bool_t xdr_qemu_attach_args (XDR *, qemu_attach_args*);
+extern  bool_t xdr_qemu_attach_ret (XDR *, qemu_attach_ret*);
 extern  bool_t xdr_qemu_procedure (XDR *, qemu_procedure*);
 
 #else /* K&R C */
 extern bool_t xdr_qemu_monitor_command_args ();
 extern bool_t xdr_qemu_monitor_command_ret ();
+extern bool_t xdr_qemu_attach_args ();
+extern bool_t xdr_qemu_attach_ret ();
 extern bool_t xdr_qemu_procedure ();
 
 #endif /* K&R C */
diff --git a/src/remote/qemu_protocol.x b/src/remote/qemu_protocol.x
index 1d07895..33b3c53 100644
--- a/src/remote/qemu_protocol.x
+++ b/src/remote/qemu_protocol.x
@@ -37,10 +37,21 @@ struct qemu_monitor_command_ret {
     remote_nonnull_string result;
 };
 
+
+struct qemu_attach_args {
+    int pid;
+    unsigned int flags;
+};
+
+struct qemu_attach_ret {
+    remote_nonnull_domain dom;
+};
+
 /* Define the program number, protocol version and procedure numbers here. */
 const QEMU_PROGRAM = 0x20008087;
 const QEMU_PROTOCOL_VERSION = 1;
 
 enum qemu_procedure {
-    QEMU_PROC_MONITOR_COMMAND = 1
+    QEMU_PROC_MONITOR_COMMAND = 1,
+    QEMU_PROC_ATTACH = 2
 };
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index 8137faa..0f0ad6c 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -9770,6 +9770,34 @@ done:
     return rv;
 }
 
+static virDomainPtr
+remoteQemuDomainAttach(virConnectPtr conn, int pid,
+                       unsigned int flags)
+{
+    virDomainPtr dom = NULL;
+    qemu_attach_args args;
+    qemu_attach_ret ret;
+    struct private_data *priv = conn->privateData;
+
+    remoteDriverLock(priv);
+
+    args.pid = pid;
+    args.flags = flags;
+
+    memset (&ret, 0, sizeof ret);
+    if (call (conn, priv, REMOTE_CALL_QEMU, QEMU_PROC_ATTACH,
+              (xdrproc_t) xdr_qemu_attach_args, (char *) &args,
+              (xdrproc_t) xdr_qemu_attach_ret, (char *) &ret) == -1)
+        goto done;
+
+    dom = get_nonnull_domain(conn, ret.dom);
+    xdr_free((xdrproc_t) &xdr_qemu_attach_ret, (char *) &ret);
+
+done:
+    remoteDriverUnlock(priv);
+    return dom;
+}
+
 /*----------------------------------------------------------------------*/
 
 static struct remote_thread_call *
@@ -11297,7 +11325,7 @@ static virDriver remote_driver = {
     remoteDomainRevertToSnapshot, /* domainRevertToSnapshot */
     remoteDomainSnapshotDelete, /* domainSnapshotDelete */
     remoteQemuDomainMonitorCommand, /* qemuDomainMonitorCommand */
-    NULL, /* qemuDomainAttach */
+    remoteQemuDomainAttach, /* qemuDomainAttach */
     remoteDomainOpenConsole, /* domainOpenConsole */
 };
 
-- 
1.7.4.4


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]