From patchwork Wed Feb 28 07:33:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 10247021 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 1A51B60212 for ; Wed, 28 Feb 2018 08:51:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 094F228C74 for ; Wed, 28 Feb 2018 08:51:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F1E8228C77; Wed, 28 Feb 2018 08:51:34 +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=ham 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 59FEE28C74 for ; Wed, 28 Feb 2018 08:51:34 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 78E1F5D5ED; Wed, 28 Feb 2018 08:51:33 +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 18AE45D6A5; Wed, 28 Feb 2018 08:51:33 +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 26C8318033EC; Wed, 28 Feb 2018 08:51:32 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w1S7XhVr004614 for ; Wed, 28 Feb 2018 02:33:43 -0500 Received: by smtp.corp.redhat.com (Postfix) id 788DA5D70B; Wed, 28 Feb 2018 07:33:43 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx01.extmail.prod.ext.phx2.redhat.com [10.5.110.25]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 729F45D6A5 for ; Wed, 28 Feb 2018 07:33:40 +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 C721281DF4 for ; Wed, 28 Feb 2018 07:33:39 +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 00:33:29 -0700 From: Qu Wenruo To: dm-devel@redhat.com, jbacik@fb.com Date: Wed, 28 Feb 2018 15:33:25 +0800 Message-Id: <20180228073326.30106-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.25]); Wed, 28 Feb 2018 07:33:40 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 28 Feb 2018 07:33:40 +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.83 on 10.5.110.25 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: dm-devel@redhat.com X-Mailman-Approved-At: Wed, 28 Feb 2018 03:51:00 -0500 Subject: [dm-devel] [PATCH 1/2] 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 28 Feb 2018 08:51:33 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Qu Wenruo --- 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);