From: Julien Desfossez Date: Fri, 7 Aug 2015 21:07:28 +0000 (-0400) Subject: Command to regenerate the metadata of a session X-Git-Tag: v2.8.0-rc1~72 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=9616f0bf9524fc6b8ad184e87f4935c97f78a8bc;p=lttng-modules.git Command to regenerate the metadata of a session Signed-off-by: Julien Desfossez Signed-off-by: Mathieu Desnoyers --- diff --git a/lib/ringbuffer/vfs.h b/lib/ringbuffer/vfs.h index ea317a1e..5444a4b2 100644 --- a/lib/ringbuffer/vfs.h +++ b/lib/ringbuffer/vfs.h @@ -113,6 +113,8 @@ ssize_t vfs_lib_ring_buffer_splice_read(struct file *in, loff_t *ppos, #define RING_BUFFER_GET_MMAP_READ_OFFSET _IOR(0xF6, 0x0B, unsigned long) /* flush the current sub-buffer */ #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) #ifdef CONFIG_COMPAT /* Get a snapshot of the current ring buffer producer and consumer positions */ @@ -145,6 +147,8 @@ ssize_t vfs_lib_ring_buffer_splice_read(struct file *in, loff_t *ppos, #define RING_BUFFER_COMPAT_GET_MMAP_READ_OFFSET _IOR(0xF6, 0x0B, compat_ulong_t) /* flush the current sub-buffer */ #define RING_BUFFER_COMPAT_FLUSH RING_BUFFER_FLUSH +/* Get the current version of the metadata cache (after a get_next). */ +#define RING_BUFFER_COMPAT_GET_METADATA_VERSION RING_BUFFER_GET_METADATA_VERSION #endif /* CONFIG_COMPAT */ #endif /* _LIB_RING_BUFFER_VFS_H */ diff --git a/lttng-abi.c b/lttng-abi.c index 4178d877..d47280f5 100644 --- a/lttng-abi.c +++ b/lttng-abi.c @@ -69,6 +69,8 @@ static const struct file_operations lttng_metadata_fops; static const struct file_operations lttng_event_fops; static struct file_operations lttng_stream_ring_buffer_file_operations; +static int put_u64(uint64_t val, unsigned long arg); + /* * Teardown management: opened file descriptors keep a refcount on the module, * so it can only exit when all file descriptors are closed. @@ -551,6 +553,8 @@ long lttng_session_ioctl(struct file *file, unsigned int cmd, unsigned long arg) return lttng_session_untrack_pid(session, (int) arg); case LTTNG_KERNEL_SESSION_LIST_TRACKER_PIDS: return lttng_session_list_tracker_pids(session); + case LTTNG_KERNEL_SESSION_METADATA_REGEN: + return lttng_session_metadata_regenerate(session); default: return -ENOIOCTLCMD; } @@ -678,6 +682,12 @@ long lttng_metadata_ring_buffer_ioctl(struct file *filp, goto err; break; } + case RING_BUFFER_GET_METADATA_VERSION: + { + struct lttng_metadata_stream *stream = filp->private_data; + + return put_u64(stream->version, arg); + } default: break; } @@ -750,6 +760,12 @@ long lttng_metadata_ring_buffer_compat_ioctl(struct file *filp, cmd, arg); break; } + case RING_BUFFER_GET_METADATA_VERSION: + { + struct lttng_metadata_stream *stream = filp->private_data; + + return put_u64(stream->version, arg); + } default: break; } diff --git a/lttng-abi.h b/lttng-abi.h index 994d2805..a40b58f5 100644 --- a/lttng-abi.h +++ b/lttng-abi.h @@ -194,6 +194,7 @@ struct lttng_kernel_filter_bytecode { #define LTTNG_KERNEL_SESSION_UNTRACK_PID \ _IOR(0xF6, 0x59, int32_t) #define LTTNG_KERNEL_SESSION_LIST_TRACKER_PIDS _IO(0xF6, 0x58) +#define LTTNG_KERNEL_SESSION_METADATA_REGEN _IO(0xF6, 0x59) /* Channel FD ioctl */ #define LTTNG_KERNEL_STREAM _IO(0xF6, 0x62) diff --git a/lttng-events.c b/lttng-events.c index bd7b4efe..f648feb6 100644 --- a/lttng-events.c +++ b/lttng-events.c @@ -270,6 +270,48 @@ end: return ret; } +int lttng_session_metadata_regenerate(struct lttng_session *session) +{ + int ret = 0; + struct lttng_channel *chan; + struct lttng_event *event; + struct lttng_metadata_cache *cache = session->metadata_cache; + struct lttng_metadata_stream *stream; + + mutex_lock(&sessions_mutex); + if (!session->active) { + ret = -EBUSY; + goto end; + } + + mutex_lock(&cache->lock); + memset(cache->data, 0, cache->cache_alloc); + cache->metadata_written = 0; + cache->version++; + list_for_each_entry(stream, &session->metadata_cache->metadata_stream, list) { + stream->metadata_out = 0; + stream->metadata_in = 0; + } + mutex_unlock(&cache->lock); + + session->metadata_dumped = 0; + list_for_each_entry(chan, &session->chan, list) { + chan->metadata_dumped = 0; + } + + list_for_each_entry(event, &session->events, list) { + event->metadata_dumped = 0; + } + + ret = _lttng_session_metadata_statedump(session); + +end: + mutex_unlock(&sessions_mutex); + return ret; +} + + + int lttng_channel_enable(struct lttng_channel *channel) { int ret = 0; @@ -1517,6 +1559,10 @@ int lttng_metadata_output_channel(struct lttng_metadata_stream *stream, if (stream->metadata_in != stream->metadata_out) goto end; + /* Metadata regenerated, change the version. */ + if (stream->metadata_cache->version != stream->version) + stream->version = stream->metadata_cache->version; + len = stream->metadata_cache->metadata_written - stream->metadata_in; if (!len) diff --git a/lttng-events.h b/lttng-events.h index 82b88e85..4bf8920f 100644 --- a/lttng-events.h +++ b/lttng-events.h @@ -421,6 +421,7 @@ struct lttng_metadata_stream { wait_queue_head_t read_wait; /* Reader buffer-level wait queue */ struct list_head list; /* Stream list */ struct lttng_transport *transport; + uint64_t version; /* Current version of the metadata cache */ }; @@ -466,7 +467,8 @@ struct lttng_metadata_cache { struct kref refcount; /* Metadata cache usage */ struct list_head metadata_stream; /* Metadata stream list */ uuid_le uuid; /* Trace session unique ID (copy) */ - struct mutex lock; + struct mutex lock; /* Produce/consume lock */ + uint64_t version; /* Current version of the metadata */ }; void lttng_lock_sessions(void); @@ -487,6 +489,7 @@ struct lttng_session *lttng_session_create(void); int lttng_session_enable(struct lttng_session *session); int lttng_session_disable(struct lttng_session *session); void lttng_session_destroy(struct lttng_session *session); +int lttng_session_metadata_regenerate(struct lttng_session *session); void metadata_cache_destroy(struct kref *kref); struct lttng_channel *lttng_channel_create(struct lttng_session *session,