Skip to contentSkip to conversation

bcache paches for Linux v5.16 (2nd wave)

PATCH Applied Coly Li 2 participants 4 messages Oct 29, 2021

Subsystems (2)
lore
Share & tools
lore

Coly Li

author
#0 lore raw

cover bcache paches for Linux v5.16 (2nd wave)

Hi Jens,

This is the second wave of bcache patches for Linux v5.16.

The first patch is suggested by Arnd Bergmann and Christoph Hellwig that the bcache.h should not belong to include/uapi/ directory, and I compose the change.

The second patch is code cleanup to remove coccicheck warning which suggests to use scnprintf to replace snprintf(), Qing Wang posts the change to remove the warning by using sysfs_emit().

Please take them for Linux v5.16 and thanks in advance.

Coly Li
---

Coly Li (1):
bcache: move uapi header bcache.h to bcache code directory

Qing Wang (1):
bcache: replace snprintf in show functions with sysfs_emit

 drivers/md/bcache/bcache.h                     |  2 +-
 .../md/bcache/bcache_ondisk.h                  |  0
 drivers/md/bcache/bset.h                       |  2 +-
 drivers/md/bcache/features.c                   |  2 +-
 drivers/md/bcache/features.h                   |  3 ++-
 drivers/md/bcache/sysfs.h                      | 18 ++++++++++++++++--
 drivers/md/bcache/util.h                       | 17 -----------------
 7 files changed, 21 insertions(+), 23 deletions(-)
 rename include/uapi/linux/bcache.h => drivers/md/bcache/bcache_ondisk.h (100%)
Signature · 1 line
2.31.1
author
#1 lore raw

PATCH 1/2 bcache: move uapi header bcache.h to bcache code directory

The header file include/uapi/linux/bcache.h is not really a user space API heaer. This file defines the ondisk format of bcache internal meta data but no one includes it from user space, bcache-tools has its own copy of this header with minor modification.

Therefore, this patch moves include/uapi/linux/bcache.h to bcache code directory as drivers/md/bcache/bcache_ondisk.h.

---
 drivers/md/bcache/bcache.h                                     | 2 +-
 .../uapi/linux/bcache.h => drivers/md/bcache/bcache_ondisk.h   | 0
 drivers/md/bcache/bset.h                                       | 2 +-
 drivers/md/bcache/features.c                                   | 2 +-
 drivers/md/bcache/features.h                                   | 3 ++-
 5 files changed, 5 insertions(+), 4 deletions(-)
 rename include/uapi/linux/bcache.h => drivers/md/bcache/bcache_ondisk.h (100%)
drivers/md/bcache/bcache.h +1 -1
index 941685409c68..9ed9c955add7 100644
@@ -178,7 +178,6 @@
 
 #define pr_fmt(fmt) "bcache: %s() " fmt, __func__
 
-#include <linux/bcache.h>
 #include <linux/bio.h>
 #include <linux/kobject.h>
 #include <linux/list.h>
@@ -190,6 +189,7 @@
 #include <linux/workqueue.h>
 #include <linux/kthread.h>
 
+#include "bcache_ondisk.h"
 #include "bset.h"
 #include "util.h"
 #include "closure.h"
drivers/md/bcache/bcache_ondisk.h renamed from include/uapi/linux/bcache.h +0 -0
similarity index 100%
rename from include/uapi/linux/bcache.h
rename to drivers/md/bcache/bcache_ondisk.h
drivers/md/bcache/bset.h +1 -1
index a50dcfda656f..d795c84246b0 100644
@@ -2,10 +2,10 @@
 #ifndef _BCACHE_BSET_H
 #define _BCACHE_BSET_H
 
-#include <linux/bcache.h>
 #include <linux/kernel.h>
 #include <linux/types.h>
 
+#include "bcache_ondisk.h"
 #include "util.h" /* for time_stats */
 
 /*
drivers/md/bcache/features.c +1 -1
index 6d2b7b84a7b7..634922c5601d 100644
@@ -6,7 +6,7 @@
  * Copyright 2020 Coly Li <[email protected]>
  *
  */
-#include <linux/bcache.h>
+#include "bcache_ondisk.h"
 #include "bcache.h"
 #include "features.h"
 
drivers/md/bcache/features.h +2 -1
index d1c8fd3977fc..09161b89c63e 100644
@@ -2,10 +2,11 @@
 #ifndef _BCACHE_FEATURES_H
 #define _BCACHE_FEATURES_H
 
-#include <linux/bcache.h>
 #include <linux/kernel.h>
 #include <linux/types.h>
 
+#include "bcache_ondisk.h"
+
 #define BCH_FEATURE_COMPAT		0
 #define BCH_FEATURE_RO_COMPAT		1
 #define BCH_FEATURE_INCOMPAT		2
Signature · 1 line
2.31.1
author
#2 lore raw

PATCH 2/2 bcache: replace snprintf in show functions with sysfs_emit

In reply to Coly Li

From: Qing Wang <[email protected]>

coccicheck complains about the use of snprintf() in sysfs show functions.

Fix the following coccicheck warning:
drivers/md/bcache/sysfs.h:54:12-20: WARNING: use scnprintf or sprintf.

Implement sysfs_print() by sysfs_emit() and remove snprint() since no one uses it any more.

---
 drivers/md/bcache/sysfs.h | 18 ++++++++++++++++--
 drivers/md/bcache/util.h  | 17 -----------------
 2 files changed, 16 insertions(+), 19 deletions(-)
drivers/md/bcache/sysfs.h +16 -2
index 215df32f567b..c1752ba2e05b 100644
@@ -51,13 +51,27 @@ STORE(fn)								\
 #define sysfs_printf(file, fmt, ...)					\
 do {									\
 	if (attr == &sysfs_ ## file)					\
-		return snprintf(buf, PAGE_SIZE, fmt "\n", __VA_ARGS__);	\
+		return sysfs_emit(buf, fmt "\n", __VA_ARGS__);	\
 } while (0)
 
 #define sysfs_print(file, var)						\
 do {									\
 	if (attr == &sysfs_ ## file)					\
-		return snprint(buf, PAGE_SIZE, var);			\
+		return sysfs_emit(buf,						\
+				__builtin_types_compatible_p(typeof(var), int)		\
+					 ? "%i\n" :				\
+				__builtin_types_compatible_p(typeof(var), unsigned int)	\
+					 ? "%u\n" :				\
+				__builtin_types_compatible_p(typeof(var), long)		\
+					 ? "%li\n" :			\
+				__builtin_types_compatible_p(typeof(var), unsigned long)\
+					 ? "%lu\n" :			\
+				__builtin_types_compatible_p(typeof(var), int64_t)	\
+					 ? "%lli\n" :			\
+				__builtin_types_compatible_p(typeof(var), uint64_t)	\
+					 ? "%llu\n" :			\
+				__builtin_types_compatible_p(typeof(var), const char *)	\
+					 ? "%s\n" : "%i\n", var);	\
 } while (0)
 
 #define sysfs_hprint(file, val)						\
drivers/md/bcache/util.h +0 -17
index 6274d6a17e5e..cdb165517d0b 100644
@@ -340,23 +340,6 @@ static inline int bch_strtoul_h(const char *cp, long *res)
 	_r;								\
 })
 
-#define snprint(buf, size, var)						\
-	snprintf(buf, size,						\
-		__builtin_types_compatible_p(typeof(var), int)		\
-		     ? "%i\n" :						\
-		__builtin_types_compatible_p(typeof(var), unsigned int)	\
-		     ? "%u\n" :						\
-		__builtin_types_compatible_p(typeof(var), long)		\
-		     ? "%li\n" :					\
-		__builtin_types_compatible_p(typeof(var), unsigned long)\
-		     ? "%lu\n" :					\
-		__builtin_types_compatible_p(typeof(var), int64_t)	\
-		     ? "%lli\n" :					\
-		__builtin_types_compatible_p(typeof(var), uint64_t)	\
-		     ? "%llu\n" :					\
-		__builtin_types_compatible_p(typeof(var), const char *)	\
-		     ? "%s\n" : "%i\n", var)
-
 ssize_t bch_hprint(char *buf, int64_t v);
 
 bool bch_is_zero(const char *p, size_t n);
Signature · 1 line
2.31.1
maintainer Applied
#3 lore raw
In reply to Coly Li
Quoted 11 lines · Coly Li

This is the second wave of bcache patches for Linux v5.16.

The first patch is suggested by Arnd Bergmann and Christoph Hellwig that the bcache.h should not belong to include/uapi/ directory, and I compose the change.

The second patch is code cleanup to remove coccicheck warning which suggests to use scnprintf to replace snprintf(), Qing Wang posts the change to remove the warning by using sysfs_emit().

[...]

Applied, thanks!

[1/2] bcache: move uapi header bcache.h to bcache code directory

      commit: cf2197ca4b8c199d188593ca6800ea1827c42171
[2/2] bcache: replace snprintf in show functions with sysfs_emit
      commit: 1b86db5f4e025840e0bf7cef2b10e84531954386

Best regards,

Signature · 1 line
Jens Axboe