From: Qu Wenruo <wqu@suse.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH 2/4] btrfs-progs: Fix -Waddress-of-packed-member warning in btrfs_dev_stats_values callers
Date: Mon, 17 Jun 2019 15:59:34 +0800 [thread overview]
Message-ID: <20190617075936.12113-3-wqu@suse.com> (raw)
In-Reply-To: <20190617075936.12113-1-wqu@suse.com>
[BUG]
GCC 9.1.0 will report the following error when compiling btrfs-progs:
In file included from print-tree.c:24:
ctree.h: In function 'btrfs_dev_stats_values':
ctree.h:2408:9: warning: taking address of packed member of 'struct btrfs_dev_stats_item' may result in an unaligned pointer value [-Waddress-of-packed-member]
2408 | return p->values;
| ^
[FIX]
Follow the kernel way of accessing dev stats by using
btrfs_dev_stats_value(eb, ptr, index).
So that we don't need to bother accessing the packed member.
This also unifies the helper function in kernel and btrfs-progs.
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
ctree.h | 13 +++++++++++++
print-tree.c | 21 ++++++---------------
2 files changed, 19 insertions(+), 15 deletions(-)
diff --git a/ctree.h b/ctree.h
index 8d710fcb5f72..d5ef1064a45a 100644
--- a/ctree.h
+++ b/ctree.h
@@ -2395,6 +2395,19 @@ static inline struct btrfs_disk_balance_args* btrfs_balance_item_sys(
return &p->sys;
}
+static inline u64 btrfs_dev_stats_value(const struct extent_buffer *eb,
+ const struct btrfs_dev_stats_item *ptr,
+ int index)
+{
+ u64 val;
+
+ read_extent_buffer(eb, &val,
+ offsetof(struct btrfs_dev_stats_item, values) +
+ ((unsigned long)ptr) + (index * sizeof(u64)),
+ sizeof(val));
+ return val;
+}
+
/*
* this returns the number of bytes used by the item on disk, minus the
* size of any extent headers. If a file is compressed on disk, this is
diff --git a/print-tree.c b/print-tree.c
index b5e0587d0b96..1ca683a61c35 100644
--- a/print-tree.c
+++ b/print-tree.c
@@ -953,32 +953,23 @@ static void print_balance_item(struct extent_buffer *eb,
static void print_dev_stats(struct extent_buffer *eb,
struct btrfs_dev_stats_item *stats, u32 size)
{
- struct btrfs_dev_stats_item *item;
- const unsigned long offset = (unsigned long)stats;
u32 known = BTRFS_DEV_STAT_VALUES_MAX * sizeof(__le64);
int i;
- item = (struct btrfs_dev_stats_item *)(eb->data + offset);
-
printf("\t\tdevice stats\n");
printf("\t\twrite_errs %llu read_errs %llu flush_errs %llu corruption_errs %llu generation %llu\n",
- (unsigned long long)get_unaligned_le64(
- &item->values[BTRFS_DEV_STAT_WRITE_ERRS]),
- (unsigned long long)get_unaligned_le64(
- &item->values[BTRFS_DEV_STAT_READ_ERRS]),
- (unsigned long long)get_unaligned_le64(
- &item->values[BTRFS_DEV_STAT_FLUSH_ERRS]),
- (unsigned long long)get_unaligned_le64(
- &item->values[BTRFS_DEV_STAT_CORRUPTION_ERRS]),
- (unsigned long long)get_unaligned_le64(
- &item->values[BTRFS_DEV_STAT_GENERATION_ERRS]));
+ btrfs_dev_stats_value(eb, stats, BTRFS_DEV_STAT_WRITE_ERRS),
+ btrfs_dev_stats_value(eb, stats, BTRFS_DEV_STAT_READ_ERRS),
+ btrfs_dev_stats_value(eb, stats, BTRFS_DEV_STAT_FLUSH_ERRS),
+ btrfs_dev_stats_value(eb, stats, BTRFS_DEV_STAT_CORRUPTION_ERRS),
+ btrfs_dev_stats_value(eb, stats, BTRFS_DEV_STAT_GENERATION_ERRS));
if (known < size) {
printf("\t\tunknown stats item bytes %u", size - known);
for (i = BTRFS_DEV_STAT_VALUES_MAX; i * sizeof(__le64) < size; i++) {
printf("\t\tunknown item %u offset %zu value %llu\n",
i, i * sizeof(__le64),
- (unsigned long long)le64_to_cpu(&item->values[i]));
+ btrfs_dev_stats_value(eb, stats, i));
}
}
}
--
2.22.0
next prev parent reply other threads:[~2019-06-17 7:59 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-17 7:59 [PATCH 0/4] btrfs-progs: GCC9 fixes Qu Wenruo
2019-06-17 7:59 ` [PATCH 1/4] btrfs-progs: constify extent buffer reader Qu Wenruo
2019-06-17 7:59 ` Qu Wenruo [this message]
2019-06-17 7:59 ` [PATCH 3/4] btrfs-progs: Remove unnecessary fallthrough attribute in test_num_disk_vs_raid() Qu Wenruo
2019-06-18 13:14 ` David Sterba
2019-06-17 7:59 ` [PATCH 4/4] btrfs-progs: Fix Wformat-overflow warning in cmds-receive.c Qu Wenruo
2019-06-18 13:20 ` [PATCH 0/4] btrfs-progs: GCC9 fixes David Sterba
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190617075936.12113-3-wqu@suse.com \
--to=wqu@suse.com \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).