From patchwork Thu Mar 1 05:38:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 10250583 X-Patchwork-Delegate: snitzer@redhat.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1C4E960211 for ; Thu, 1 Mar 2018 09:12:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0D39128C87 for ; Thu, 1 Mar 2018 09:12:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 01D0428D0F; Thu, 1 Mar 2018 09:12:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 62BF028C87 for ; Thu, 1 Mar 2018 09:12:43 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3B62BC0587C1; Thu, 1 Mar 2018 09:12:42 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C551E60479; Thu, 1 Mar 2018 09:12:41 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id C2F4E18033ED; Thu, 1 Mar 2018 09:12:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w215ccxU024113 for ; Thu, 1 Mar 2018 00:38:38 -0500 Received: by smtp.corp.redhat.com (Postfix) id 60AC65DA2A; Thu, 1 Mar 2018 05:38:38 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx05.extmail.prod.ext.phx2.redhat.com [10.5.110.29]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5A9BF5D9C7 for ; Thu, 1 Mar 2018 05:38:35 +0000 (UTC) Received: from prv3-mh.provo.novell.com (prv3-mh.provo.novell.com [137.65.250.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BB4862D0FA9 for ; Thu, 1 Mar 2018 05:38:33 +0000 (UTC) Received: from adam-pc.lan (prv-ext-foundry1int.gns.novell.com [137.65.251.240]) by prv3-mh.provo.novell.com with ESMTP (NOT encrypted); Wed, 28 Feb 2018 22:38:25 -0700 From: Qu Wenruo To: fstests@vger.kernel.org Date: Thu, 1 Mar 2018 13:38:20 +0800 Message-Id: <20180301053821.18718-2-wqu@suse.com> In-Reply-To: <20180301053821.18718-1-wqu@suse.com> References: <20180301053821.18718-1-wqu@suse.com> X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 207 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 01 Mar 2018 05:38:34 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 01 Mar 2018 05:38:34 +0000 (UTC) for IP:'137.65.250.26' DOMAIN:'prv3-mh.provo.novell.com' HELO:'prv3-mh.provo.novell.com' FROM:'wqu@suse.com' RCPT:'' X-RedHat-Spam-Score: -2.301 (RCVD_IN_DNSWL_MED, SPF_PASS) 137.65.250.26 prv3-mh.provo.novell.com 137.65.250.26 prv3-mh.provo.novell.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.29 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: dm-devel@redhat.com X-Mailman-Approved-At: Thu, 01 Mar 2018 04:12:01 -0500 Cc: dm-devel@redhat.com Subject: [dm-devel] [PATCH 1/2] fstests: log-writes: Add support to output human readable flags X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 01 Mar 2018 09:12:42 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Qu Wenruo --- src/log-writes/log-writes.c | 68 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 62 insertions(+), 6 deletions(-) diff --git a/src/log-writes/log-writes.c b/src/log-writes/log-writes.c index 09391574c4d2..181dabf442de 100644 --- a/src/log-writes/log-writes.c +++ b/src/log-writes/log-writes.c @@ -120,6 +120,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: entry to be replayed. @@ -179,6 +231,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; int skip = 0; @@ -210,19 +263,20 @@ int log_replay_next_entry(struct log *log, struct log_write_entry *entry, log->cur_pos += read_size; } + flags = le64_to_cpu(entry->flags); + entry_flags_to_str(flags, flags_buf); skip = log_should_skip(log, entry); if (log_writes_verbose > 1 || (log_writes_verbose && !skip)) { - printf("%s %d@%llu: sector %llu, size %llu, flags %llu\n", + printf("%s %d@%llu: sector %llu, size %llu, flags %llu(%s)\n", skip ? "skipping" : "replaying", (int)log->cur_entry - 1, log->cur_pos / log->sectorsize, (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); @@ -339,6 +393,7 @@ int log_seek_next_entry(struct log *log, struct log_write_entry *entry, size_t read_size = read_data ? log->sectorsize : sizeof(struct log_write_entry); u64 flags; + char flags_buf[LOG_FLAGS_BUF_SIZE]; ssize_t ret; if (log->cur_entry >= log->nr_entries) @@ -366,14 +421,15 @@ int log_seek_next_entry(struct log *log, struct log_write_entry *entry, } else { log->cur_pos += read_size; } + flags = le64_to_cpu(entry->flags); + entry_flags_to_str(flags, flags_buf); if (log_writes_verbose > 1) - printf("seek entry %d@%llu: %llu, size %llu, flags %llu\n", + printf("seek entry %d@%llu: %llu, size %llu, flags %llu(%s)\n", (int)log->cur_entry - 1, log->cur_pos / log->sectorsize, (unsigned long long)le64_to_cpu(entry->sector), (unsigned long long)le64_to_cpu(entry->nr_sectors), - (unsigned long long)le64_to_cpu(entry->flags)); + (unsigned long long)flags, flags_buf); - flags = le64_to_cpu(entry->flags); read_size = le64_to_cpu(entry->nr_sectors) * log->sectorsize; if (!read_size || (flags & LOG_DISCARD_FLAG)) return 0;