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

[PATCH] tools/xenstored: potentially split trace_io() out message



Today write_messages() will call trace_io() after having written the
complete message to the ring buffer or socket.

In case the message can't be written in one go, split it by writing
one trace entry when starting the write and one when finishing it.

Signed-off-by: Juergen Gross <jgross@xxxxxxxx>
---
This patch is meant to go on top of the patch "tools/xenstored: remove
\"-V\" command line option" in order to not lose any possible debug
information.
---
 tools/xenstored/core.c | 30 ++++++++++++++++++++----------
 1 file changed, 20 insertions(+), 10 deletions(-)

diff --git a/tools/xenstored/core.c b/tools/xenstored/core.c
index 9046b200bc..a14b240ed9 100644
--- a/tools/xenstored/core.c
+++ b/tools/xenstored/core.c
@@ -121,7 +121,7 @@ void trace(const char *fmt, ...)
 
 static void trace_io(const struct connection *conn,
                     const struct buffered_data *data,
-                    int out)
+                    const char *type)
 {
        unsigned int i;
        time_t now;
@@ -134,8 +134,7 @@ static void trace_io(const struct connection *conn,
        tm = localtime(&now);
 
        trace("io: %s %p (d%u) %04d%02d%02d %02d:%02d:%02d %s (",
-             out ? "OUT" : "IN", conn, conn->id,
-             tm->tm_year + 1900, tm->tm_mon + 1,
+             type, conn, conn->id, tm->tm_year + 1900, tm->tm_mon + 1,
              tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec,
              sockmsg_string(data->hdr.msg.type));
        
@@ -321,43 +320,54 @@ static bool write_messages(struct connection *conn)
 {
        int ret;
        struct buffered_data *out;
+       bool started = false;
 
        out = list_top(&conn->out_list, struct buffered_data, list);
        if (out == NULL)
                return true;
 
        if (out->inhdr) {
+               started = !out->used;
                ret = conn->funcs->write(conn, out->hdr.raw + out->used,
                                         sizeof(out->hdr) - out->used);
                if (ret < 0)
-                       return false;
+                       goto err;
 
                out->used += ret;
                if (out->used < sizeof(out->hdr))
-                       return true;
+                       goto start;
 
                out->inhdr = false;
                out->used = 0;
 
                /* Second write might block if non-zero. */
                if (out->hdr.msg.len && !conn->domain)
-                       return true;
+                       goto start;
        }
 
        ret = conn->funcs->write(conn, out->buffer + out->used,
                                 out->hdr.msg.len - out->used);
        if (ret < 0)
-               return false;
+               goto err;
 
        out->used += ret;
        if (out->used != out->hdr.msg.len)
-               return true;
+               goto start;
 
-       trace_io(conn, out, 1);
+       trace_io(conn, out, started ? "OUT" : "OUT(END)");
 
        free_buffered_data(out, conn);
 
        return true;
+
+ err:
+       trace_io(conn, out, "OUT(ERR)");
+       return false;
+
+ start:
+       if (started)
+               trace_io(conn, out, "OUT(START)");
+       return true;
 }
 
 static int undelay_request(void *_req)
@@ -2067,7 +2077,7 @@ static void process_message(struct connection *conn, 
struct buffered_data *in)
 
        /* At least send_error() and send_reply() expects conn->in == in */
        assert(conn->in == in);
-       trace_io(conn, in, 0);
+       trace_io(conn, in, "IN");
 
        if ((unsigned int)type >= XS_TYPE_COUNT || !wire_funcs[type].func) {
                eprintf("Client unknown operation %i", type);
-- 
2.35.3




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.