From patchwork Mon Jun 17 07:59:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 10998279 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BBC70924 for ; Mon, 17 Jun 2019 07:59:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B273128716 for ; Mon, 17 Jun 2019 07:59:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A6DB828732; Mon, 17 Jun 2019 07:59:45 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4F27828716 for ; Mon, 17 Jun 2019 07:59:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726711AbfFQH7o (ORCPT ); Mon, 17 Jun 2019 03:59:44 -0400 Received: from mx2.suse.de ([195.135.220.15]:43778 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725791AbfFQH7n (ORCPT ); Mon, 17 Jun 2019 03:59:43 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id B9CC4AE89 for ; Mon, 17 Jun 2019 07:59:42 +0000 (UTC) From: Qu Wenruo To: linux-btrfs@vger.kernel.org Subject: [PATCH 1/4] btrfs-progs: constify extent buffer reader Date: Mon, 17 Jun 2019 15:59:33 +0800 Message-Id: <20190617075936.12113-2-wqu@suse.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190617075936.12113-1-wqu@suse.com> References: <20190617075936.12113-1-wqu@suse.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add const prefix for the following parameters: - @eb of memcmp_extent_buffer() - @eb of read_extent_buffer() This backports kernel commit 1cbb1f454e53 ("btrfs: struct-funcs, constify readers") to btrfs-progs. Signed-off-by: Qu Wenruo --- extent_io.c | 4 ++-- extent_io.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/extent_io.c b/extent_io.c index c57f62829bf7..a9ceff5111fb 100644 --- a/extent_io.c +++ b/extent_io.c @@ -963,13 +963,13 @@ int clear_extent_buffer_dirty(struct extent_buffer *eb) return 0; } -int memcmp_extent_buffer(struct extent_buffer *eb, const void *ptrv, +int memcmp_extent_buffer(const struct extent_buffer *eb, const void *ptrv, unsigned long start, unsigned long len) { return memcmp(eb->data + start, ptrv, len); } -void read_extent_buffer(struct extent_buffer *eb, void *dst, +void read_extent_buffer(const struct extent_buffer *eb, void *dst, unsigned long start, unsigned long len) { memcpy(dst, eb->data + start, len); diff --git a/extent_io.h b/extent_io.h index 9587528bbefb..874cbca1d436 100644 --- a/extent_io.h +++ b/extent_io.h @@ -154,9 +154,9 @@ void free_extent_buffer_nocache(struct extent_buffer *eb); int read_extent_from_disk(struct extent_buffer *eb, unsigned long offset, unsigned long len); int write_extent_to_disk(struct extent_buffer *eb); -int memcmp_extent_buffer(struct extent_buffer *eb, const void *ptrv, +int memcmp_extent_buffer(const struct extent_buffer *eb, const void *ptrv, unsigned long start, unsigned long len); -void read_extent_buffer(struct extent_buffer *eb, void *dst, +void read_extent_buffer(const struct extent_buffer *eb, void *dst, unsigned long start, unsigned long len); void write_extent_buffer(struct extent_buffer *eb, const void *src, unsigned long start, unsigned long len); From patchwork Mon Jun 17 07:59:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 10998281 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 076636C5 for ; Mon, 17 Jun 2019 07:59:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F173128716 for ; Mon, 17 Jun 2019 07:59:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E62F028732; Mon, 17 Jun 2019 07:59:48 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4344528716 for ; Mon, 17 Jun 2019 07:59:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726871AbfFQH7r (ORCPT ); Mon, 17 Jun 2019 03:59:47 -0400 Received: from mx2.suse.de ([195.135.220.15]:43800 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725791AbfFQH7r (ORCPT ); Mon, 17 Jun 2019 03:59:47 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 3D160AE89 for ; Mon, 17 Jun 2019 07:59:45 +0000 (UTC) From: Qu Wenruo 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 Message-Id: <20190617075936.12113-3-wqu@suse.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190617075936.12113-1-wqu@suse.com> References: <20190617075936.12113-1-wqu@suse.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP [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 --- 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)); } } } From patchwork Mon Jun 17 07:59:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 10998283 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5096A6C5 for ; Mon, 17 Jun 2019 07:59:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 478BC28716 for ; Mon, 17 Jun 2019 07:59:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3C19428732; Mon, 17 Jun 2019 07:59:50 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F276E28716 for ; Mon, 17 Jun 2019 07:59:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726957AbfFQH7t (ORCPT ); Mon, 17 Jun 2019 03:59:49 -0400 Received: from mx2.suse.de ([195.135.220.15]:43826 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725791AbfFQH7s (ORCPT ); Mon, 17 Jun 2019 03:59:48 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id D56DFAE89 for ; Mon, 17 Jun 2019 07:59:47 +0000 (UTC) From: Qu Wenruo To: linux-btrfs@vger.kernel.org Subject: [PATCH 3/4] btrfs-progs: Remove unnecessary fallthrough attribute in test_num_disk_vs_raid() Date: Mon, 17 Jun 2019 15:59:35 +0800 Message-Id: <20190617075936.12113-4-wqu@suse.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190617075936.12113-1-wqu@suse.com> References: <20190617075936.12113-1-wqu@suse.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Qu Wenruo --- utils.c | 1 - 1 file changed, 1 deletion(-) diff --git a/utils.c b/utils.c index 0b271517551b..2709ced97f97 100644 --- a/utils.c +++ b/utils.c @@ -1928,7 +1928,6 @@ int test_num_disk_vs_raid(u64 metadata_profile, u64 data_profile, __attribute__ ((fallthrough)); case 1: allowed |= BTRFS_BLOCK_GROUP_DUP; - __attribute__ ((fallthrough)); } if (dev_cnt > 1 && profile & BTRFS_BLOCK_GROUP_DUP) { From patchwork Mon Jun 17 07:59:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 10998285 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EA17B924 for ; Mon, 17 Jun 2019 07:59:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DFE3628716 for ; Mon, 17 Jun 2019 07:59:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D4A6B28732; Mon, 17 Jun 2019 07:59:52 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7CC9228716 for ; Mon, 17 Jun 2019 07:59:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727059AbfFQH7v (ORCPT ); Mon, 17 Jun 2019 03:59:51 -0400 Received: from mx2.suse.de ([195.135.220.15]:43844 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727020AbfFQH7v (ORCPT ); Mon, 17 Jun 2019 03:59:51 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 4D172AE89 for ; Mon, 17 Jun 2019 07:59:50 +0000 (UTC) From: Qu Wenruo To: linux-btrfs@vger.kernel.org Subject: [PATCH 4/4] btrfs-progs: Fix Wformat-overflow warning in cmds-receive.c Date: Mon, 17 Jun 2019 15:59:36 +0800 Message-Id: <20190617075936.12113-5-wqu@suse.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190617075936.12113-1-wqu@suse.com> References: <20190617075936.12113-1-wqu@suse.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP [BUG] When compiling btrfs-progs with GCC 9 (9.1.0), we got the following warnings: In file included from utils.h:30, from cmds-receive.c:45: cmds-receive.c: In function 'process_subvol': messages.h:42:3: warning: '%s' directive argument is null [-Wformat-overflow=] 42 | __btrfs_error((fmt), ##__VA_ARGS__); \ | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cmds-receive.c:178:3: note: in expansion of macro 'error' 178 | error("subvol: another one already started, path buf: %s", | ^~~~~ [CC] cmds-inspect-tree-stats.o cmds-receive.c: In function 'process_snapshot': messages.h:42:3: warning: '%s' directive argument is null [-Wformat-overflow=] 42 | __btrfs_error((fmt), ##__VA_ARGS__); \ | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cmds-receive.c:248:3: note: in expansion of macro 'error' 248 | error("snapshot: another one already started, path buf: %s", | ^~~~~ [FIX] We're using wrong member for the error output. Fix the member to output. Signed-off-by: Qu Wenruo --- cmds-receive.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmds-receive.c b/cmds-receive.c index fe5c3a5b05c5..07f05101f921 100644 --- a/cmds-receive.c +++ b/cmds-receive.c @@ -176,7 +176,7 @@ static int process_subvol(const char *path, const u8 *uuid, u64 ctransid, } if (rctx->cur_subvol_path[0]) { error("subvol: another one already started, path buf: %s", - rctx->cur_subvol.path); + rctx->cur_subvol_path); ret = -EINVAL; goto out; } @@ -246,7 +246,7 @@ static int process_snapshot(const char *path, const u8 *uuid, u64 ctransid, } if (rctx->cur_subvol_path[0]) { error("snapshot: another one already started, path buf: %s", - rctx->cur_subvol.path); + rctx->cur_subvol_path); ret = -EINVAL; goto out; }