All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] log-writes: Add support to output human readable flags
@ 2018-02-28  7:33 Qu Wenruo
  2018-02-28  7:33 ` [PATCH 2/2] log-writes: Add support for METADATA flag Qu Wenruo
  2018-02-28 15:09 ` [PATCH 1/2] log-writes: Add support to output human readable flags Josef Bacik
  0 siblings, 2 replies; 3+ messages in thread
From: Qu Wenruo @ 2018-02-28  7:33 UTC (permalink / raw)
  To: dm-devel, jbacik

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 log-writes.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 57 insertions(+), 3 deletions(-)

diff --git a/log-writes.c b/log-writes.c
index fa4f3f3b42d6..5ef328656c89 100644
--- a/log-writes.c
+++ b/log-writes.c
@@ -117,6 +117,58 @@ int log_discard(struct log *log, struct log_write_entry *entry)
 	return 0;
 }
 
+#define DEFINE_LOG_FLAGS_STR_ENTRY(x)	\
+	{LOG_##x##_FLAG, #x}
+
+struct flags_to_str_entry {
+	u64 flags;
+	const char *str;
+} log_flags_table[] = {
+	DEFINE_LOG_FLAGS_STR_ENTRY(FLUSH),
+	DEFINE_LOG_FLAGS_STR_ENTRY(FUA),
+	DEFINE_LOG_FLAGS_STR_ENTRY(DISCARD),
+	DEFINE_LOG_FLAGS_STR_ENTRY(MARK)
+};
+
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+#define LOG_FLAGS_BUF_SIZE	128
+/*
+ * Convert numeric flags to human readable flags.
+ * @flags:	numeric flags
+ * @buf:	output buffer for human readable string.
+ * 		must have enough space (LOG_FLAGS_BUF_SIZE) to contain all
+ * 		the string
+ */
+static void entry_flags_to_str(u64 flags, char *buf)
+{
+	int empty = 1;
+	int left_len;
+	int i;
+
+	buf[0] = '\0';
+	for (i = 0; i < ARRAY_SIZE(log_flags_table); i++) {
+		if (flags & log_flags_table[i].flags) {
+			if (!empty)
+				strncat(buf, "|", LOG_FLAGS_BUF_SIZE);
+			empty = 0;
+			strncat(buf, log_flags_table[i].str, LOG_FLAGS_BUF_SIZE);
+			flags &= ~log_flags_table[i].flags;
+		}
+	}
+	if (flags) {
+		if (!empty)
+			strncat(buf, "|", LOG_FLAGS_BUF_SIZE);
+		empty = 0;
+		left_len = LOG_FLAGS_BUF_SIZE - strnlen(buf,
+						        LOG_FLAGS_BUF_SIZE);
+		if (left_len > 0)
+			snprintf(buf + strnlen(buf, LOG_FLAGS_BUF_SIZE),
+				 left_len, "UNKNOWN.%llu", flags);
+	}
+	if (empty)
+		strncpy(buf, "NONE", LOG_FLAGS_BUF_SIZE);
+}
+
 /*
  * @log: the log we are replaying.
  * @entry: where we put the entry.
@@ -135,6 +187,7 @@ int log_replay_next_entry(struct log *log, struct log_write_entry *entry,
 	size_t read_size = read_data ? log->sectorsize :
 		sizeof(struct log_write_entry);
 	char *buf;
+	char flags_buf[LOG_FLAGS_BUF_SIZE];
 	ssize_t ret;
 	off_t offset;
 
@@ -158,16 +211,17 @@ int log_replay_next_entry(struct log *log, struct log_write_entry *entry,
 		}
 	}
 
+	flags = le64_to_cpu(entry->flags);
+	entry_flags_to_str(flags, flags_buf);
 	if (log_writes_verbose)
-		printf("replaying %d: sector %llu, size %llu, flags %llu\n",
+		printf("replaying %d: sector %llu, size %llu, flags %llu(%s)\n",
 		       (int)log->cur_entry - 1,
 		       (unsigned long long)le64_to_cpu(entry->sector),
 		       (unsigned long long)size,
-		       (unsigned long long)le64_to_cpu(entry->flags));
+		       (unsigned long long)flags, flags_buf);
 	if (!size)
 		return 0;
 
-	flags = le64_to_cpu(entry->flags);
 	if (flags & LOG_DISCARD_FLAG)
 		return log_discard(log, entry);
 
-- 
2.16.2

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] log-writes: Add support for METADATA flag
  2018-02-28  7:33 [PATCH 1/2] log-writes: Add support to output human readable flags Qu Wenruo
@ 2018-02-28  7:33 ` Qu Wenruo
  2018-02-28 15:09 ` [PATCH 1/2] log-writes: Add support to output human readable flags Josef Bacik
  1 sibling, 0 replies; 3+ messages in thread
From: Qu Wenruo @ 2018-02-28  7:33 UTC (permalink / raw)
  To: dm-devel, jbacik

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 log-writes.c | 3 ++-
 log-writes.h | 9 +++++----
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/log-writes.c b/log-writes.c
index 5ef328656c89..651db43383ba 100644
--- a/log-writes.c
+++ b/log-writes.c
@@ -127,7 +127,8 @@ struct flags_to_str_entry {
 	DEFINE_LOG_FLAGS_STR_ENTRY(FLUSH),
 	DEFINE_LOG_FLAGS_STR_ENTRY(FUA),
 	DEFINE_LOG_FLAGS_STR_ENTRY(DISCARD),
-	DEFINE_LOG_FLAGS_STR_ENTRY(MARK)
+	DEFINE_LOG_FLAGS_STR_ENTRY(MARK),
+	DEFINE_LOG_FLAGS_STR_ENTRY(METADATA)
 };
 
 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
diff --git a/log-writes.h b/log-writes.h
index 13f98ffe1730..ce41262f6aaa 100644
--- a/log-writes.h
+++ b/log-writes.h
@@ -12,10 +12,11 @@ extern int log_writes_verbose;
 typedef __u64 u64;
 typedef __u32 u32;
 
-#define LOG_FLUSH_FLAG (1 << 0)
-#define LOG_FUA_FLAG (1 << 1)
-#define LOG_DISCARD_FLAG (1 << 2)
-#define LOG_MARK_FLAG (1 << 3)
+#define LOG_FLUSH_FLAG		(1 << 0)
+#define LOG_FUA_FLAG		(1 << 1)
+#define LOG_DISCARD_FLAG	(1 << 2)
+#define LOG_MARK_FLAG		(1 << 3)
+#define LOG_METADATA_FLAG	(1 << 4)
 
 #define WRITE_LOG_VERSION 1
 #define WRITE_LOG_MAGIC 0x6a736677736872
-- 
2.16.2

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] log-writes: Add support to output human readable flags
  2018-02-28  7:33 [PATCH 1/2] log-writes: Add support to output human readable flags Qu Wenruo
  2018-02-28  7:33 ` [PATCH 2/2] log-writes: Add support for METADATA flag Qu Wenruo
@ 2018-02-28 15:09 ` Josef Bacik
  1 sibling, 0 replies; 3+ messages in thread
From: Josef Bacik @ 2018-02-28 15:09 UTC (permalink / raw)
  To: Qu Wenruo; +Cc: jbacik, dm-devel

I merged the pull request for these, but you should maybe send them up for the
xfstests version of log-writes.  Thanks,

Josef

On Wed, Feb 28, 2018 at 03:33:25PM +0800, Qu Wenruo wrote:
> Signed-off-by: Qu Wenruo <wqu@suse.com>
> ---
>  log-writes.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
>  1 file changed, 57 insertions(+), 3 deletions(-)
> 
> diff --git a/log-writes.c b/log-writes.c
> index fa4f3f3b42d6..5ef328656c89 100644
> --- a/log-writes.c
> +++ b/log-writes.c
> @@ -117,6 +117,58 @@ int log_discard(struct log *log, struct log_write_entry *entry)
>  	return 0;
>  }
>  
> +#define DEFINE_LOG_FLAGS_STR_ENTRY(x)	\
> +	{LOG_##x##_FLAG, #x}
> +
> +struct flags_to_str_entry {
> +	u64 flags;
> +	const char *str;
> +} log_flags_table[] = {
> +	DEFINE_LOG_FLAGS_STR_ENTRY(FLUSH),
> +	DEFINE_LOG_FLAGS_STR_ENTRY(FUA),
> +	DEFINE_LOG_FLAGS_STR_ENTRY(DISCARD),
> +	DEFINE_LOG_FLAGS_STR_ENTRY(MARK)
> +};
> +
> +#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
> +#define LOG_FLAGS_BUF_SIZE	128
> +/*
> + * Convert numeric flags to human readable flags.
> + * @flags:	numeric flags
> + * @buf:	output buffer for human readable string.
> + * 		must have enough space (LOG_FLAGS_BUF_SIZE) to contain all
> + * 		the string
> + */
> +static void entry_flags_to_str(u64 flags, char *buf)
> +{
> +	int empty = 1;
> +	int left_len;
> +	int i;
> +
> +	buf[0] = '\0';
> +	for (i = 0; i < ARRAY_SIZE(log_flags_table); i++) {
> +		if (flags & log_flags_table[i].flags) {
> +			if (!empty)
> +				strncat(buf, "|", LOG_FLAGS_BUF_SIZE);
> +			empty = 0;
> +			strncat(buf, log_flags_table[i].str, LOG_FLAGS_BUF_SIZE);
> +			flags &= ~log_flags_table[i].flags;
> +		}
> +	}
> +	if (flags) {
> +		if (!empty)
> +			strncat(buf, "|", LOG_FLAGS_BUF_SIZE);
> +		empty = 0;
> +		left_len = LOG_FLAGS_BUF_SIZE - strnlen(buf,
> +						        LOG_FLAGS_BUF_SIZE);
> +		if (left_len > 0)
> +			snprintf(buf + strnlen(buf, LOG_FLAGS_BUF_SIZE),
> +				 left_len, "UNKNOWN.%llu", flags);
> +	}
> +	if (empty)
> +		strncpy(buf, "NONE", LOG_FLAGS_BUF_SIZE);
> +}
> +
>  /*
>   * @log: the log we are replaying.
>   * @entry: where we put the entry.
> @@ -135,6 +187,7 @@ int log_replay_next_entry(struct log *log, struct log_write_entry *entry,
>  	size_t read_size = read_data ? log->sectorsize :
>  		sizeof(struct log_write_entry);
>  	char *buf;
> +	char flags_buf[LOG_FLAGS_BUF_SIZE];
>  	ssize_t ret;
>  	off_t offset;
>  
> @@ -158,16 +211,17 @@ int log_replay_next_entry(struct log *log, struct log_write_entry *entry,
>  		}
>  	}
>  
> +	flags = le64_to_cpu(entry->flags);
> +	entry_flags_to_str(flags, flags_buf);
>  	if (log_writes_verbose)
> -		printf("replaying %d: sector %llu, size %llu, flags %llu\n",
> +		printf("replaying %d: sector %llu, size %llu, flags %llu(%s)\n",
>  		       (int)log->cur_entry - 1,
>  		       (unsigned long long)le64_to_cpu(entry->sector),
>  		       (unsigned long long)size,
> -		       (unsigned long long)le64_to_cpu(entry->flags));
> +		       (unsigned long long)flags, flags_buf);
>  	if (!size)
>  		return 0;
>  
> -	flags = le64_to_cpu(entry->flags);
>  	if (flags & LOG_DISCARD_FLAG)
>  		return log_discard(log, entry);
>  
> -- 
> 2.16.2
> 
> --
> dm-devel mailing list
> dm-devel@redhat.com
> https://www.redhat.com/mailman/listinfo/dm-devel

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-02-28 15:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-28  7:33 [PATCH 1/2] log-writes: Add support to output human readable flags Qu Wenruo
2018-02-28  7:33 ` [PATCH 2/2] log-writes: Add support for METADATA flag Qu Wenruo
2018-02-28 15:09 ` [PATCH 1/2] log-writes: Add support to output human readable flags Josef Bacik

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.