2023-09-13 04:31:56

by Thomas Weißschuh

[permalink] [raw]
Subject: [PATCH 0/5] bcachefs: Fixes for various compiler warnings

Some fixes for warnings found by "make W=1".

Note: This was only compile-tested.

Signed-off-by: Thomas Weißschuh <[email protected]>
---
Thomas Weißschuh (5):
bcachefs: Delete dead code
bcachefs: Mark bch2_snapshot_node_delete() static
bcachefs: Delete set but not used variables
bcachefs: Add printf function attributes
bcachefs: Avoid unused symbol warnings from headers

fs/bcachefs/alloc_foreground.c | 3 --
fs/bcachefs/backpointers.c | 3 --
fs/bcachefs/bcachefs.h | 3 +-
fs/bcachefs/bcachefs_format.h | 15 +++++-----
fs/bcachefs/btree_io.c | 4 +--
fs/bcachefs/btree_trans_commit.c | 4 ---
fs/bcachefs/btree_types.h | 63 +++++++++++++++++++++-------------------
fs/bcachefs/btree_update.c | 13 ++-------
fs/bcachefs/btree_update.h | 4 ++-
fs/bcachefs/compress.c | 4 ---
fs/bcachefs/data_update.c | 4 ---
fs/bcachefs/fs-io-pagecache.c | 7 -----
fs/bcachefs/fs-ioctl.h | 8 +++--
fs/bcachefs/opts.h | 3 +-
fs/bcachefs/reflink.c | 8 -----
fs/bcachefs/snapshot.c | 2 +-
16 files changed, 58 insertions(+), 90 deletions(-)
---
base-commit: e7e6c4189f70ab2d7c21eaec5b9e9c34527ef349
change-id: 20230912-bcachefs-cleanup-a3f3ab958320

Best regards,
--
Thomas Weißschuh <[email protected]>


2023-09-13 06:00:25

by Kent Overstreet

[permalink] [raw]
Subject: Re: [PATCH 0/5] bcachefs: Fixes for various compiler warnings

On Tue, Sep 12, 2023 at 11:24:39PM +0200, Thomas Weißschuh wrote:
> Some fixes for warnings found by "make W=1".
>
> Note: This was only compile-tested.

I've been working on these fixes too, most of them are already in the
bcachefs-testing branch or about to be.

2023-09-13 08:25:37

by Thomas Weißschuh

[permalink] [raw]
Subject: [PATCH 5/5] bcachefs: Avoid unused symbol warnings from headers

Static variables defined in headers generate unused variable compiler
warnings in CUs that do not use said functions.
Avoid the warnings by either replacing the variables by enums and by
explicitly inhibiting the warning.

Signed-off-by: Thomas Weißschuh <[email protected]>
---
fs/bcachefs/bcachefs.h | 3 ++-
fs/bcachefs/bcachefs_format.h | 15 ++++++-----
fs/bcachefs/btree_types.h | 63 ++++++++++++++++++++++---------------------
fs/bcachefs/fs-ioctl.h | 8 +++---
fs/bcachefs/opts.h | 3 ++-
5 files changed, 50 insertions(+), 42 deletions(-)

diff --git a/fs/bcachefs/bcachefs.h b/fs/bcachefs/bcachefs.h
index 30b3d7b9f9dc..b5a8ea44f9ef 100644
--- a/fs/bcachefs/bcachefs.h
+++ b/fs/bcachefs/bcachefs.h
@@ -186,6 +186,7 @@
#include <linux/backing-dev-defs.h>
#include <linux/bug.h>
#include <linux/bio.h>
+#include <linux/compiler.h>
#include <linux/closure.h>
#include <linux/kobject.h>
#include <linux/list.h>
@@ -371,7 +372,7 @@ BCH_DEBUG_PARAMS()
#undef BCH_DEBUG_PARAM

#ifndef CONFIG_BCACHEFS_DEBUG
-#define BCH_DEBUG_PARAM(name, description) static const bool bch2_##name;
+#define BCH_DEBUG_PARAM(name, description) static const __used bool bch2_##name;
BCH_DEBUG_PARAMS_DEBUG()
#undef BCH_DEBUG_PARAM
#endif
diff --git a/fs/bcachefs/bcachefs_format.h b/fs/bcachefs/bcachefs_format.h
index 1cce2504bca6..a13455dbb32c 100644
--- a/fs/bcachefs/bcachefs_format.h
+++ b/fs/bcachefs/bcachefs_format.h
@@ -74,6 +74,7 @@

#include <asm/types.h>
#include <asm/byteorder.h>
+#include <linux/compiler.h>
#include <linux/kernel.h>
#include <linux/uuid.h>
#include "vstructs.h"
@@ -83,8 +84,8 @@ typedef uuid_t __uuid_t;
#endif

#define BITMASK(name, type, field, offset, end) \
-static const unsigned name##_OFFSET = offset; \
-static const unsigned name##_BITS = (end - offset); \
+static const __used unsigned name##_OFFSET = offset; \
+static const __used unsigned name##_BITS = (end - offset); \
\
static inline __u64 name(const type *k) \
{ \
@@ -98,9 +99,9 @@ static inline void SET_##name(type *k, __u64 v) \
}

#define LE_BITMASK(_bits, name, type, field, offset, end) \
-static const unsigned name##_OFFSET = offset; \
-static const unsigned name##_BITS = (end - offset); \
-static const __u##_bits name##_MAX = (1ULL << (end - offset)) - 1; \
+static const __used unsigned name##_OFFSET = offset; \
+static const __used unsigned name##_BITS = (end - offset); \
+static const __used __u##_bits name##_MAX = (1ULL << (end - offset)) - 1; \
\
static inline __u64 name(const type *k) \
{ \
@@ -1639,7 +1640,7 @@ enum bcachefs_metadata_version {
bcachefs_metadata_version_max
};

-static const unsigned bcachefs_metadata_required_upgrade_below = bcachefs_metadata_version_major_minor;
+static const __used unsigned bcachefs_metadata_required_upgrade_below = bcachefs_metadata_version_major_minor;

#define bcachefs_metadata_version_current (bcachefs_metadata_version_max - 1)

@@ -1946,7 +1947,7 @@ enum bch_csum_type {
BCH_CSUM_NR
};

-static const unsigned bch_crc_bytes[] = {
+static const __used unsigned bch_crc_bytes[] = {
[BCH_CSUM_none] = 0,
[BCH_CSUM_crc32c_nonzero] = 4,
[BCH_CSUM_crc32c] = 4,
diff --git a/fs/bcachefs/btree_types.h b/fs/bcachefs/btree_types.h
index 70398aaa095e..a9ab52e8f9d9 100644
--- a/fs/bcachefs/btree_types.h
+++ b/fs/bcachefs/btree_types.h
@@ -181,36 +181,39 @@ struct btree_node_iter {
} data[MAX_BSETS];
};

-/*
- * Iterate over all possible positions, synthesizing deleted keys for holes:
- */
-static const u16 BTREE_ITER_SLOTS = 1 << 0;
-static const u16 BTREE_ITER_ALL_LEVELS = 1 << 1;
-/*
- * Indicates that intent locks should be taken on leaf nodes, because we expect
- * to be doing updates:
- */
-static const u16 BTREE_ITER_INTENT = 1 << 2;
-/*
- * Causes the btree iterator code to prefetch additional btree nodes from disk:
- */
-static const u16 BTREE_ITER_PREFETCH = 1 << 3;
-/*
- * Used in bch2_btree_iter_traverse(), to indicate whether we're searching for
- * @pos or the first key strictly greater than @pos
- */
-static const u16 BTREE_ITER_IS_EXTENTS = 1 << 4;
-static const u16 BTREE_ITER_NOT_EXTENTS = 1 << 5;
-static const u16 BTREE_ITER_CACHED = 1 << 6;
-static const u16 BTREE_ITER_WITH_KEY_CACHE = 1 << 7;
-static const u16 BTREE_ITER_WITH_UPDATES = 1 << 8;
-static const u16 BTREE_ITER_WITH_JOURNAL = 1 << 9;
-static const u16 __BTREE_ITER_ALL_SNAPSHOTS = 1 << 10;
-static const u16 BTREE_ITER_ALL_SNAPSHOTS = 1 << 11;
-static const u16 BTREE_ITER_FILTER_SNAPSHOTS = 1 << 12;
-static const u16 BTREE_ITER_NOPRESERVE = 1 << 13;
-static const u16 BTREE_ITER_CACHED_NOFILL = 1 << 14;
-static const u16 BTREE_ITER_KEY_CACHE_FILL = 1 << 15;
+enum {
+ /*
+ * Iterate over all possible positions, synthesizing deleted keys for holes:
+ */
+ BTREE_ITER_SLOTS = 1 << 0,
+ BTREE_ITER_ALL_LEVELS = 1 << 1,
+ /*
+ * Indicates that intent locks should be taken on leaf nodes, because we expect
+ * to be doing updates:
+ */
+ BTREE_ITER_INTENT = 1 << 2,
+ /*
+ * Causes the btree iterator code to prefetch additional btree nodes from disk:
+ */
+ BTREE_ITER_PREFETCH = 1 << 3,
+
+ /*
+ * Used in bch2_btree_iter_traverse(), to indicate whether we're searching for
+ * @pos or the first key strictly greater than @pos
+ */
+ BTREE_ITER_IS_EXTENTS = 1 << 4,
+ BTREE_ITER_NOT_EXTENTS = 1 << 5,
+ BTREE_ITER_CACHED = 1 << 6,
+ BTREE_ITER_WITH_KEY_CACHE = 1 << 7,
+ BTREE_ITER_WITH_UPDATES = 1 << 8,
+ BTREE_ITER_WITH_JOURNAL = 1 << 9,
+ __BTREE_ITER_ALL_SNAPSHOTS = 1 << 10,
+ BTREE_ITER_ALL_SNAPSHOTS = 1 << 11,
+ BTREE_ITER_FILTER_SNAPSHOTS = 1 << 12,
+ BTREE_ITER_NOPRESERVE = 1 << 13,
+ BTREE_ITER_CACHED_NOFILL = 1 << 14,
+ BTREE_ITER_KEY_CACHE_FILL = 1 << 15,
+};
#define __BTREE_ITER_FLAGS_END 16

enum btree_path_uptodate {
diff --git a/fs/bcachefs/fs-ioctl.h b/fs/bcachefs/fs-ioctl.h
index f201980ef2c3..0ebf4106ed2f 100644
--- a/fs/bcachefs/fs-ioctl.h
+++ b/fs/bcachefs/fs-ioctl.h
@@ -2,10 +2,12 @@
#ifndef _BCACHEFS_FS_IOCTL_H
#define _BCACHEFS_FS_IOCTL_H

+#include <linux/compiler.h>
+
/* Inode flags: */

/* bcachefs inode flags -> vfs inode flags: */
-static const unsigned bch_flags_to_vfs[] = {
+static const __used unsigned bch_flags_to_vfs[] = {
[__BCH_INODE_SYNC] = S_SYNC,
[__BCH_INODE_IMMUTABLE] = S_IMMUTABLE,
[__BCH_INODE_APPEND] = S_APPEND,
@@ -13,7 +15,7 @@ static const unsigned bch_flags_to_vfs[] = {
};

/* bcachefs inode flags -> FS_IOC_GETFLAGS: */
-static const unsigned bch_flags_to_uflags[] = {
+static const __used unsigned bch_flags_to_uflags[] = {
[__BCH_INODE_SYNC] = FS_SYNC_FL,
[__BCH_INODE_IMMUTABLE] = FS_IMMUTABLE_FL,
[__BCH_INODE_APPEND] = FS_APPEND_FL,
@@ -22,7 +24,7 @@ static const unsigned bch_flags_to_uflags[] = {
};

/* bcachefs inode flags -> FS_IOC_FSGETXATTR: */
-static const unsigned bch_flags_to_xflags[] = {
+static const __used unsigned bch_flags_to_xflags[] = {
[__BCH_INODE_SYNC] = FS_XFLAG_SYNC,
[__BCH_INODE_IMMUTABLE] = FS_XFLAG_IMMUTABLE,
[__BCH_INODE_APPEND] = FS_XFLAG_APPEND,
diff --git a/fs/bcachefs/opts.h b/fs/bcachefs/opts.h
index 8a9db110d64f..35831159e207 100644
--- a/fs/bcachefs/opts.h
+++ b/fs/bcachefs/opts.h
@@ -3,6 +3,7 @@
#define _BCACHEFS_OPTS_H

#include <linux/bug.h>
+#include <linux/compiler.h>
#include <linux/log2.h>
#include <linux/string.h>
#include <linux/sysfs.h>
@@ -469,7 +470,7 @@ struct bch_opts {
#undef x
};

-static const struct bch_opts bch2_opts_default = {
+static const __used struct bch_opts bch2_opts_default = {
#define x(_name, _bits, _mode, _type, _sb_opt, _default, ...) \
._name##_defined = true, \
._name = _default, \

--
2.42.0

2023-09-14 01:44:34

by Thomas Weißschuh

[permalink] [raw]
Subject: [PATCH 4/5] bcachefs: Add printf function attributes

These help the compiler detect incorrect use of format strings and their
arguments.

Signed-off-by: Thomas Weißschuh <[email protected]>
---
fs/bcachefs/btree_io.c | 1 +
fs/bcachefs/btree_update.c | 2 ++
fs/bcachefs/btree_update.h | 3 +++
3 files changed, 6 insertions(+)

diff --git a/fs/bcachefs/btree_io.c b/fs/bcachefs/btree_io.c
index 8655a07456e6..bfaaa6b612ad 100644
--- a/fs/bcachefs/btree_io.c
+++ b/fs/bcachefs/btree_io.c
@@ -542,6 +542,7 @@ static void btree_err_msg(struct printbuf *out, struct bch_fs *c,
prt_str(out, ": ");
}

+__printf(8, 9)
static int __btree_err(int ret,
struct bch_fs *c,
struct bch_dev *ca,
diff --git a/fs/bcachefs/btree_update.c b/fs/bcachefs/btree_update.c
index 3dcb05b51e2d..cf0415e93feb 100644
--- a/fs/bcachefs/btree_update.c
+++ b/fs/bcachefs/btree_update.c
@@ -818,6 +818,7 @@ int bch2_btree_bit_mod(struct btree_trans *trans, enum btree_id btree,
return bch2_trans_update_buffered(trans, btree, k);
}

+__printf(2, 0)
static int __bch2_trans_log_msg(darray_u64 *entries, const char *fmt, va_list args)
{
struct printbuf buf = PRINTBUF;
@@ -854,6 +855,7 @@ static int __bch2_trans_log_msg(darray_u64 *entries, const char *fmt, va_list ar
return ret;
}

+__printf(3, 0)
static int
__bch2_fs_log_msg(struct bch_fs *c, unsigned commit_flags, const char *fmt,
va_list args)
diff --git a/fs/bcachefs/btree_update.h b/fs/bcachefs/btree_update.h
index c6ab11c76cc3..13a47aac9b81 100644
--- a/fs/bcachefs/btree_update.h
+++ b/fs/bcachefs/btree_update.h
@@ -2,6 +2,8 @@
#ifndef _BCACHEFS_BTREE_UPDATE_H
#define _BCACHEFS_BTREE_UPDATE_H

+#include <linux/compiler.h>
+
#include "btree_iter.h"
#include "journal.h"
#include "journal.h"
@@ -114,6 +116,7 @@ void bch2_trans_commit_hook(struct btree_trans *,
struct btree_trans_commit_hook *);
int __bch2_trans_commit(struct btree_trans *, unsigned);

+__printf(2, 3)
int bch2_journal_log_msg(struct bch_fs *, const char *, ...);

/**

--
2.42.0