Fix: use "flush empty" ioctl for snapshots
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 11 May 2017 21:53:58 +0000 (17:53 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 22 May 2017 15:02:13 +0000 (11:02 -0400)
When the flush empty ioctl is available, use it to produce an empty
packet at the end of the snapshot, which ensures the stream intersection
feature works.

If this specific ioctl is not available, fallback on the "flush" ioctl,
which does not produce empty packets.

In that situation, there were two prior behaviors possible for
lttng-modules: earlier versions implement a "snapshot" command which
does not perform an implicit "flush_empty". In that case, the stream
intersection feature may not be reliable. In more recent lttng-modules
versions (included stable branch) which did not implement the
flush_empty ioctl, the snapshot ioctl implicitly performed a
flush_empty, which makes the stream intersection feature work, but has
side-effects on the snapshot ioctl performed by the live timer (produces
a stream of empty packets in live mode).

[ Please apply to master, 2.10, 2.9, 2.8 branches. ]

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/common/kernel-consumer/kernel-consumer.c
src/common/kernel-ctl/kernel-ctl.c
src/common/kernel-ctl/kernel-ctl.h
src/common/kernel-ctl/kernel-ioctl.h

index d9c4d2685f6cc7e1da9a6c0ccac0b0a56757ace3..57656dcc8794891dd81e8120330353b398bf6a19 100644 (file)
@@ -188,11 +188,20 @@ int lttng_kconsumer_snapshot_channel(uint64_t key, char *path,
                        channel->streams_sent_to_relayd = true;
                }
 
-               ret = kernctl_buffer_flush(stream->wait_fd);
+               ret = kernctl_buffer_flush_empty(stream->wait_fd);
                if (ret < 0) {
-                       ERR("Failed to flush kernel stream");
-                       ret = -errno;
-                       goto end_unlock;
+                       /*
+                        * Doing a buffer flush which does not take into
+                        * account empty packets. This is not perfect
+                        * for stream intersection, but required as a
+                        * fall-back when "flush_empty" is not
+                        * implemented by lttng-modules.
+                        */
+                       ret = kernctl_buffer_flush(stream->wait_fd);
+                       if (ret < 0) {
+                               ERR("Failed to flush kernel stream");
+                               goto end_unlock;
+                       }
                }
 
                ret = lttng_kconsumer_take_snapshot(stream);
index 610a3c53b4cce80dec3fa3896eb3b5b7dd313b5b..144dbf04d8d7ff5ec1a5956d916981584788535f 100644 (file)
@@ -426,6 +426,11 @@ int kernctl_buffer_flush(int fd)
        return LTTNG_IOCTL(fd, RING_BUFFER_FLUSH);
 }
 
+int kernctl_buffer_flush_empty(int fd)
+{
+       return LTTNG_IOCTL(fd, RING_BUFFER_FLUSH_EMPTY);
+}
+
 /* returns the version of the metadata. */
 int kernctl_get_metadata_version(int fd, uint64_t *version)
 {
index 6736937d0dbbb987bb8c4bc011e01388fef464a9..2a448e0ecb40e75be8d9c792b7732a5cd24c2b70 100644 (file)
@@ -92,6 +92,7 @@ int kernctl_get_subbuf(int fd, unsigned long *pos);
 int kernctl_put_subbuf(int fd);
 
 int kernctl_buffer_flush(int fd);
+int kernctl_buffer_flush_empty(int fd);
 int kernctl_get_metadata_version(int fd, uint64_t *version);
 
 /* index */
index 68056dcf1279521e9fa6ed0a73fb8b2fc246a450..cddea3fc44a021925128e37d8d0280e6be8bf21a 100644 (file)
 #define RING_BUFFER_GET_MMAP_LEN            _IOR(0xF6, 0x0A, unsigned long)
 /* returns the offset of the subbuffer belonging to the mmap reader. */
 #define RING_BUFFER_GET_MMAP_READ_OFFSET    _IOR(0xF6, 0x0B, unsigned long)
-/* flush the current sub-buffer */
+/* Flush the current sub-buffer, if non-empty. */
 #define RING_BUFFER_FLUSH                   _IO(0xF6, 0x0C)
 /* Get the current version of the metadata cache (after a get_next). */
 #define RING_BUFFER_GET_METADATA_VERSION    _IOR(0xF6, 0x0D, uint64_t)
+/* Flush the current sub-buffer, even if empty. */
+#define RING_BUFFER_FLUSH_EMPTY                        _IO(0xF6, 0x0F)
 
 /* returns the timestamp begin of the current sub-buffer */
 #define LTTNG_RING_BUFFER_GET_TIMESTAMP_BEGIN     _IOR(0xF6, 0x20, uint64_t)
This page took 0.028523 seconds and 4 git commands to generate.