[libvirt] [PATCH 9/9] Rename 'direction' to 'type' in remote_message_header

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

 



The 'remote_message_header' struct has a mis-leadingly named
field 'direction'. It is really a reflection of the type of
message, and some types can be sent in either direction. Thus
the field is more accurately named 'type'. No function change.

* qemud/remote_protocol.x: Rename 'direction' to 'type' in
  'remote_message_header. Write better docs describing the
  message header field semantics & usage
* qemud/remote_protocol.c, qemud/remote_protocol.h: Regenerate
* qemud/remote.c, qemud/dispatch.c, src/remote_internal.c
  Update to reflect rename of 'direction' to 'type'

Signed-off-by: Daniel P. Berrange <berrange@xxxxxxxxxx>
---
 qemud/dispatch.c        |   14 +++++-----
 qemud/remote.c          |    2 +-
 qemud/remote_protocol.c |    4 +-
 qemud/remote_protocol.h |   10 +++---
 qemud/remote_protocol.x |   64 +++++++++++++++++++++++++++++++++++-----------
 src/remote_internal.c   |    6 ++--
 6 files changed, 66 insertions(+), 34 deletions(-)

diff --git a/qemud/dispatch.c b/qemud/dispatch.c
index 1ccca10..886aa5e 100644
--- a/qemud/dispatch.c
+++ b/qemud/dispatch.c
@@ -129,7 +129,7 @@ remoteSerializeError(struct qemud_client *client,
                      int program,
                      int version,
                      int procedure,
-                     int direction,
+                     int type,
                      int serial)
 {
     XDR xdr;
@@ -143,7 +143,7 @@ remoteSerializeError(struct qemud_client *client,
     msg->hdr.prog = program;
     msg->hdr.vers = version;
     msg->hdr.proc = procedure;
-    msg->hdr.direction = direction;
+    msg->hdr.type = type;
     msg->hdr.serial = serial;
     msg->hdr.status = REMOTE_ERROR;
 
@@ -359,13 +359,13 @@ remoteDispatchClientRequest (struct qemud_server *server,
         goto error;
     }
 
-    switch (msg->hdr.direction) {
+    switch (msg->hdr.type) {
     case REMOTE_CALL:
         return remoteDispatchClientCall(server, client, msg);
 
     default:
-        remoteDispatchFormatError (&rerr, _("direction (%d) != REMOTE_CALL"),
-                                   (int) msg->hdr.direction);
+        remoteDispatchFormatError (&rerr, _("type (%d) != REMOTE_CALL"),
+                                   (int) msg->hdr.type);
     }
 
 error:
@@ -467,11 +467,11 @@ remoteDispatchClientCall (struct qemud_server *server,
         goto rpc_error;
 
     /* Return header. We're re-using same message object, so
-     * only need to tweak direction/status fields */
+     * only need to tweak type/status fields */
     /*msg->hdr.prog = msg->hdr.prog;*/
     /*msg->hdr.vers = msg->hdr.vers;*/
     /*msg->hdr.proc = msg->hdr.proc;*/
-    msg->hdr.direction = REMOTE_REPLY;
+    msg->hdr.type = REMOTE_REPLY;
     /*msg->hdr.serial = msg->hdr.serial;*/
     msg->hdr.status = REMOTE_OK;
 
diff --git a/qemud/remote.c b/qemud/remote.c
index 4d6ddef..92ab21f 100644
--- a/qemud/remote.c
+++ b/qemud/remote.c
@@ -4422,7 +4422,7 @@ remoteDispatchDomainEventSend (struct qemud_client *client,
     msg->hdr.prog = REMOTE_PROGRAM;
     msg->hdr.vers = REMOTE_PROTOCOL_VERSION;
     msg->hdr.proc = REMOTE_PROC_DOMAIN_EVENT;
-    msg->hdr.direction = REMOTE_MESSAGE;
+    msg->hdr.type = REMOTE_MESSAGE;
     msg->hdr.serial = 1;
     msg->hdr.status = REMOTE_OK;
 
diff --git a/qemud/remote_protocol.c b/qemud/remote_protocol.c
index f6dac7a..65f9a73 100644
--- a/qemud/remote_protocol.c
+++ b/qemud/remote_protocol.c
@@ -2514,7 +2514,7 @@ xdr_remote_procedure (XDR *xdrs, remote_procedure *objp)
 }
 
 bool_t
-xdr_remote_message_direction (XDR *xdrs, remote_message_direction *objp)
+xdr_remote_message_type (XDR *xdrs, remote_message_type *objp)
 {
 
          if (!xdr_enum (xdrs, (enum_t *) objp))
@@ -2541,7 +2541,7 @@ xdr_remote_message_header (XDR *xdrs, remote_message_header *objp)
                  return FALSE;
          if (!xdr_remote_procedure (xdrs, &objp->proc))
                  return FALSE;
-         if (!xdr_remote_message_direction (xdrs, &objp->direction))
+         if (!xdr_remote_message_type (xdrs, &objp->type))
                  return FALSE;
          if (!xdr_u_int (xdrs, &objp->serial))
                  return FALSE;
diff --git a/qemud/remote_protocol.h b/qemud/remote_protocol.h
index 21eae07..dae304e 100644
--- a/qemud/remote_protocol.h
+++ b/qemud/remote_protocol.h
@@ -1551,12 +1551,12 @@ enum remote_procedure {
 };
 typedef enum remote_procedure remote_procedure;
 
-enum remote_message_direction {
+enum remote_message_type {
         REMOTE_CALL = 0,
         REMOTE_REPLY = 1,
         REMOTE_MESSAGE = 2,
 };
-typedef enum remote_message_direction remote_message_direction;
+typedef enum remote_message_type remote_message_type;
 
 enum remote_message_status {
         REMOTE_OK = 0,
@@ -1569,7 +1569,7 @@ struct remote_message_header {
         u_int prog;
         u_int vers;
         remote_procedure proc;
-        remote_message_direction direction;
+        remote_message_type type;
         u_int serial;
         remote_message_status status;
 };
@@ -1808,7 +1808,7 @@ extern  bool_t xdr_remote_domain_xml_from_native_ret (XDR *, remote_domain_xml_f
 extern  bool_t xdr_remote_domain_xml_to_native_args (XDR *, remote_domain_xml_to_native_args*);
 extern  bool_t xdr_remote_domain_xml_to_native_ret (XDR *, remote_domain_xml_to_native_ret*);
 extern  bool_t xdr_remote_procedure (XDR *, remote_procedure*);
-extern  bool_t xdr_remote_message_direction (XDR *, remote_message_direction*);
+extern  bool_t xdr_remote_message_type (XDR *, remote_message_type*);
 extern  bool_t xdr_remote_message_status (XDR *, remote_message_status*);
 extern  bool_t xdr_remote_message_header (XDR *, remote_message_header*);
 
@@ -2043,7 +2043,7 @@ extern bool_t xdr_remote_domain_xml_from_native_ret ();
 extern bool_t xdr_remote_domain_xml_to_native_args ();
 extern bool_t xdr_remote_domain_xml_to_native_ret ();
 extern bool_t xdr_remote_procedure ();
-extern bool_t xdr_remote_message_direction ();
+extern bool_t xdr_remote_message_type ();
 extern bool_t xdr_remote_message_status ();
 extern bool_t xdr_remote_message_header ();
 
diff --git a/qemud/remote_protocol.x b/qemud/remote_protocol.x
index 1fb826b..9e75c59 100644
--- a/qemud/remote_protocol.x
+++ b/qemud/remote_protocol.x
@@ -1409,23 +1409,55 @@ enum remote_procedure {
     REMOTE_PROC_DOMAIN_XML_TO_NATIVE = 136
 };
 
-/* Custom RPC structure. */
-/* Each message consists of:
- *    int length               Number of bytes in message _including_ length.
- *    remote_message_header    Header.
- * then either: args           Arguments (for REMOTE_CALL).
- *          or: ret            Return (for REMOTE_REPLY, status = REMOTE_OK)
- *          or: remote_error   Error (for REMOTE_REPLY, status = REMOTE_ERROR)
+
+/*
+ * RPC wire format
+ *
+ * Each message consists of:
+ *
+ *    Name    | Type                  | Description
+ * -----------+-----------------------+------------------
+ *    Length  | int                   | Total number of bytes in message _including_ length.
+ *    Header  | remote_message_header | Control information about procedure call
+ *    Payload | -                     | Variable payload data per procedure
+ *
+ * In header, the 'serial' field varies according to:
+ *
+ *  - type == REMOTE_CALL
+ *      * serial is set by client, incrementing by 1 each time
+ *
+ *  - type == REMOTE_REPLY
+ *      * serial matches that from the corresponding REMOTE_CALL
+ *
+ *  - type == REMOTE_MESSAGE
+ *      * serial matches that from the corresponding REMOTE_CALL, or zero
+ *
+ *
+ * Payload varies according to type and status:
+ *
+ *  - type == REMOTE_CALL
+ *          XXX_args  for procedure
+ *
+ *  - type == REMOTE_REPLY
+ *     * status == REMOTE_OK
+ *          XXX_ret         for procedure
+ *     * status == REMOTE_ERROR
+ *          remote_error    Error information
+ *
+ *  - type == REMOTE_MESSAGE
+ *     * status == REMOTE_OK
+ *          XXX_args        for procedure
+ *     * status == REMOTE_ERROR
+ *          remote_error    Error information
  *
- * The first two words (length, program number) are meant to be compatible
- * with the qemud protocol (qemud/protocol.x), although the rest of the
- * messages are completely different.
  */
-
-enum remote_message_direction {
-    REMOTE_CALL = 0,            /* client -> server */
-    REMOTE_REPLY = 1,           /* server -> client */
-    REMOTE_MESSAGE = 2          /* server -> client, asynchronous [NYI] */
+enum remote_message_type {
+    /* client -> server. args from a method call */
+    REMOTE_CALL = 0,
+    /* server -> client. reply/error from a method call */
+    REMOTE_REPLY = 1,
+    /* either direction. async notification */
+    REMOTE_MESSAGE = 2
 };
 
 enum remote_message_status {
@@ -1447,7 +1479,7 @@ struct remote_message_header {
     unsigned prog;              /* REMOTE_PROGRAM */
     unsigned vers;              /* REMOTE_PROTOCOL_VERSION */
     remote_procedure proc;      /* REMOTE_PROC_x */
-    remote_message_direction direction;
+    remote_message_type type;
     unsigned serial;            /* Serial number of message. */
     remote_message_status status;
 };
diff --git a/src/remote_internal.c b/src/remote_internal.c
index e7beb49..91e111e 100644
--- a/src/remote_internal.c
+++ b/src/remote_internal.c
@@ -6263,7 +6263,7 @@ prepareCall(virConnectPtr conn,
     hdr.prog = REMOTE_PROGRAM;
     hdr.vers = REMOTE_PROTOCOL_VERSION;
     hdr.proc = proc_nr;
-    hdr.direction = REMOTE_CALL;
+    hdr.type = REMOTE_CALL;
     hdr.serial = rv->serial;
     hdr.status = REMOTE_OK;
 
@@ -6658,14 +6658,14 @@ processCallRecvMsg(virConnectPtr conn, struct private_data *priv,
     }
 
     /* Async events from server need special handling */
-    if (hdr.direction == REMOTE_MESSAGE) {
+    if (hdr.type == REMOTE_MESSAGE) {
         processCallAsyncEvent(conn, priv, in_open,
                               &hdr, &xdr);
         xdr_destroy(&xdr);
         return 0;
     }
 
-    if (hdr.direction != REMOTE_REPLY) {
+    if (hdr.type != REMOTE_REPLY) {
         virRaiseError (in_open ? NULL : conn,
                        NULL, NULL, VIR_FROM_REMOTE,
                        VIR_ERR_RPC, VIR_ERR_ERROR, NULL, NULL, NULL, 0, 0,
-- 
1.6.2.5


-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

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

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]