Skip to contentSkip to conversation

Command to dump the metadata cache again

PATCH Mathieu Desnoyers 1 participant 1 message Feb 20, 2018 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Mathieu Desnoyers

author Applied
#1 lore raw

Merged into master, thanks!

Mathieu

Quoted 115 lines · ----- On Oct 18, 2017, at 11:14 AM, Julien Desfossez [email protected]…

This command allows the consumer to ask for the metadata cache to be dumped entirely another time. This is used by the session rotation feature to get a new copy of what was in the metadata cache without regenerating it and re-sampling the offset from epoch.

---

lib/ringbuffer/vfs.h |  5 +++++
lttng-abi.c          | 44 ++++++++++++++++++++++++++++++++++++++++++++
lttng-events.c       |  2 --
3 files changed, 49 insertions(+), 2 deletions(-)
lib/ringbuffer/vfs.h +5 -0
index b2e5b1c..e2bc401 100644
@@ -123,6 +123,11 @@ ssize_t vfs_lib_ring_buffer_splice_read(struct file *in,
 loff_t *ppos,
 #define RING_BUFFER_SNAPSHOT_SAMPLE_POSITIONS	_IO(0xF6, 0x0E)
 /* Flush the current sub-buffer, even if empty. */
 #define RING_BUFFER_FLUSH_EMPTY			_IO(0xF6, 0x0F)
+/*
+ * Reset the position of what has been consumed from the metadata cache to 0
+ * so it can be read again.
+ */
+#define RING_BUFFER_METADATA_CACHE_DUMP		_IO(0xF6, 0x10)
 
 #ifdef CONFIG_COMPAT

/* Get a snapshot of the current ring buffer producer and consumer positions */

lttng-abi.c +32 -0
index 77e5e98..d202b72 100644
@@ -654,6 +654,38 @@ void
 lttng_metadata_ring_buffer_ioctl_put_next_subbuf(struct file *filp,
 	stream->metadata_out = stream->metadata_in;
 }
 
+/*
+ * Reset the counter of how much metadata has been consumed to 0. That way,
+ * the consumer receives the content of the metadata cache unchanged. This is
+ * different from the metadata_regenerate where the offset from epoch is
+ * resampled, here we want the exact same content as the last time the metadata
+ * was generated. This command is only possible if all the metadata written
+ * in the cache has been output to the metadata stream to avoid corrupting the
+ * metadata file.
+ *
+ * Return 0 on success, a negative value on error.
+ */
+static
+int lttng_metadata_cache_dump(struct lttng_metadata_stream *stream)
+{
+	int ret;
+	struct lttng_metadata_cache *cache = stream->metadata_cache;
+
+	mutex_lock(&cache->lock);
+	if (stream->metadata_out != cache->metadata_written) {
+		ret = -EBUSY;
+		goto end;
+	}
+	stream->metadata_out = 0;
+	stream->metadata_in = 0;
+	wake_up_interruptible(&stream->read_wait);
+	ret = 0;
+
+end:
+	mutex_unlock(&cache->lock);
+	return ret;
+}
+

static
long lttng_metadata_ring_buffer_ioctl(struct file *filp,
unsigned int cmd, unsigned long arg)

lttng-abi.c +12 -0
@@ -706,6 +738,12 @@ long lttng_metadata_ring_buffer_ioctl(struct file *filp,
 
 		return put_u64(stream->version, arg);
 	}
+	case RING_BUFFER_METADATA_CACHE_DUMP:
+	{
+		struct lttng_metadata_stream *stream = filp->private_data;
+
+		return lttng_metadata_cache_dump(stream);
+	}
 	default:
 		break;
 	}
@@ -783,6 +821,12 @@ long lttng_metadata_ring_buffer_compat_ioctl(struct file
 *filp,
 
 		return put_u64(stream->version, arg);
 	}
+	case RING_BUFFER_METADATA_CACHE_DUMP:
+	{
+		struct lttng_metadata_stream *stream = filp->private_data;
+
+		return lttng_metadata_cache_dump(stream);
+	}
 	default:
 		break;
	}
lttng-events.c +0 -3
index 21c4113..8719173 100644
@@ -342,8 +342,6 @@ end:
 	return ret;
 }
 
-
-
 int lttng_channel_enable(struct lttng_channel *channel)
 {
 	int ret = 0;
--

2.7.4

Signature · 7 lines
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev