forked from Mirrors/btrfs-progs
btrfs-progs: fix gcc9 warning and potentially unaligned access to dev stats
GCC9 9.1.1 with -Waddress-of-packed-member warns about passing an unaligned pointer from btrfs_dev_stats_values. It is up to the caller to access the array properly, which does happen in print_dev_stats. 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; Drop the helper as print-tree.c is the only user and access the dev stat values using the unaligned helper. Signed-off-by: David Sterba <dsterba@suse.com>master
parent
2570cff076
commit
691656abdc
13
ctree.h
13
ctree.h
|
@ -2395,19 +2395,6 @@ static inline struct btrfs_disk_balance_args* btrfs_balance_item_sys(
|
|||
return &p->sys;
|
||||
}
|
||||
|
||||
/*
|
||||
* btrfs_dev_stats_item helper, returns pointer to the raw array, do the
|
||||
* endianness conversion, @dsi is offset to eb data
|
||||
*/
|
||||
static inline __le64* btrfs_dev_stats_values(struct extent_buffer *eb,
|
||||
struct btrfs_dev_stats_item *dsi)
|
||||
{
|
||||
unsigned long offset = (unsigned long)dsi;
|
||||
struct btrfs_dev_stats_item *p;
|
||||
p = (struct btrfs_dev_stats_item *)(eb->data + offset);
|
||||
return p->values;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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
|
||||
|
|
24
print-tree.c
24
print-tree.c
|
@ -953,24 +953,32 @@ 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)
|
||||
{
|
||||
int i;
|
||||
struct btrfs_dev_stats_item *item;
|
||||
const unsigned long offset = (unsigned long)stats;
|
||||
u32 known = BTRFS_DEV_STAT_VALUES_MAX * sizeof(__le64);
|
||||
__le64 *values = btrfs_dev_stats_values(eb, stats);
|
||||
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)le64_to_cpu(values[BTRFS_DEV_STAT_WRITE_ERRS]),
|
||||
(unsigned long long)le64_to_cpu(values[BTRFS_DEV_STAT_READ_ERRS]),
|
||||
(unsigned long long)le64_to_cpu(values[BTRFS_DEV_STAT_FLUSH_ERRS]),
|
||||
(unsigned long long)le64_to_cpu(values[BTRFS_DEV_STAT_CORRUPTION_ERRS]),
|
||||
(unsigned long long)le64_to_cpu(values[BTRFS_DEV_STAT_GENERATION_ERRS]));
|
||||
(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]));
|
||||
|
||||
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(values[i]));
|
||||
(unsigned long long)le64_to_cpu(&item->values[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue