Add write metadata API to ust-ctl.h
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 25 Feb 2013 19:05:15 +0000 (14:05 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 1 Mar 2013 18:06:48 +0000 (13:06 -0500)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
include/lttng/ust-ctl.h
liblttng-ust-ctl/ustctl.c

index ae4f3089bd41f5d1347763266725adc7cfe973ba..3171b3151dd6a3122762f5b316567021672e896f 100644 (file)
@@ -146,6 +146,12 @@ void ustctl_destroy_channel(struct ustctl_consumer_channel *chan);
 
 int ustctl_send_channel_to_sessiond(int sock,
                struct ustctl_consumer_channel *channel);
+
+int ustctl_write_metadata_to_channel(
+               struct ustctl_consumer_channel *channel,
+               const char *metadata_str,       /* NOT null-terminated */
+               size_t len);                    /* metadata length */
+
 /*
  * Send a NULL stream to finish iteration over all streams of a given
  * channel.
index d47a5b5055facc83c9ae01f7dbfb711cfcbc3040..ff4a537b540b71e0b58a97fd24a029bfd8447af3 100644 (file)
 
 #include "../libringbuffer/backend.h"
 #include "../libringbuffer/frontend.h"
+#include "../liblttng-ust/wait.h"
+
+/*
+ * Number of milliseconds to retry before failing metadata writes on
+ * buffer full condition. (10 seconds)
+ */
+#define LTTNG_METADATA_TIMEOUT_MSEC    10000
 
 /*
  * Channel representation within consumer.
@@ -844,6 +851,50 @@ int ustctl_send_stream_to_sessiond(int sock,
                        0);
 }
 
+int ustctl_write_metadata_to_channel(
+               struct ustctl_consumer_channel *channel,
+               const char *metadata_str,       /* NOT null-terminated */
+               size_t len)                     /* metadata length */
+{
+       struct lttng_ust_lib_ring_buffer_ctx ctx;
+       struct lttng_channel *chan = channel->chan;
+       const char *str = metadata_str;
+       int ret = 0, waitret;
+       size_t reserve_len, pos;
+
+       for (pos = 0; pos < len; pos += reserve_len) {
+               reserve_len = min_t(size_t,
+                               chan->ops->packet_avail_size(chan->chan, chan->handle),
+                               len - pos);
+               lib_ring_buffer_ctx_init(&ctx, chan->chan, NULL, reserve_len,
+                                        sizeof(char), -1, chan->handle);
+               /*
+                * We don't care about metadata buffer's records lost
+                * count, because we always retry here. Report error if
+                * we need to bail out after timeout or being
+                * interrupted.
+                */
+               waitret = wait_cond_interruptible_timeout(
+                       ({
+                               ret = chan->ops->event_reserve(&ctx, 0);
+                               ret != -ENOBUFS || !ret;
+                       }),
+                       LTTNG_METADATA_TIMEOUT_MSEC);
+               if (waitret == -ETIMEDOUT || waitret == -EINTR || ret) {
+                       DBG("LTTng: Failure to write metadata to buffers (%s)\n",
+                               waitret == -EINTR ? "interrupted" :
+                                       (ret == -ENOBUFS ? "timeout" : "I/O error"));
+                       if (waitret == -EINTR)
+                               ret = waitret;
+                       goto end;
+               }
+               chan->ops->event_write(&ctx, &str[pos], reserve_len);
+               chan->ops->event_commit(&ctx);
+       }
+end:
+       return ret;
+}
+
 int ustctl_stream_close_wait_fd(struct ustctl_consumer_stream *stream)
 {
        struct channel *chan;
This page took 0.02735 seconds and 4 git commands to generate.