linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/3] btrfs: remove unnecessary hash_init()
@ 2019-10-10  7:59 Chengguang Xu
  2019-10-10  7:59 ` [PATCH v2 2/3] btrfs: code cleanup for compression type Chengguang Xu
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Chengguang Xu @ 2019-10-10  7:59 UTC (permalink / raw)
  To: clm, josef, dsterba; +Cc: linux-btrfs, Chengguang Xu

DEFINE_HASHTABLE itself has already included initialization code,
we don't have to call hash_init() again, so remove it.

Signed-off-by: Chengguang Xu <cgxu519@mykernel.net>
---
v1->v2:
- Modify change log to explain why hash_init() is not needed.

 fs/btrfs/props.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/fs/btrfs/props.c b/fs/btrfs/props.c
index 1e664e0b59b8..68508db3dc65 100644
--- a/fs/btrfs/props.c
+++ b/fs/btrfs/props.c
@@ -437,8 +437,6 @@ void __init btrfs_props_init(void)
 {
 	int i;
 
-	hash_init(prop_handlers_ht);
-
 	for (i = 0; i < ARRAY_SIZE(prop_handlers); i++) {
 		struct prop_handler *p = &prop_handlers[i];
 		u64 h = btrfs_name_hash(p->xattr_name, strlen(p->xattr_name));
-- 
2.20.1




^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v2 2/3] btrfs: code cleanup for compression type
  2019-10-10  7:59 [PATCH v2 1/3] btrfs: remove unnecessary hash_init() Chengguang Xu
@ 2019-10-10  7:59 ` Chengguang Xu
  2019-10-10  7:59 ` [PATCH v2 3/3] btrfs: using enum to replace macro Chengguang Xu
  2019-10-10 16:58 ` [PATCH v2 1/3] btrfs: remove unnecessary hash_init() David Sterba
  2 siblings, 0 replies; 4+ messages in thread
From: Chengguang Xu @ 2019-10-10  7:59 UTC (permalink / raw)
  To: clm, josef, dsterba; +Cc: linux-btrfs, Chengguang Xu

In order to keep coding style consistency,
set BTRFS_NR_COMPRESS_TYPES to the total number
of cmpressoin type and fix related calling places.

Signed-off-by: Chengguang Xu <cgxu519@mykernel.net>
---
v1->v2:
- Modify change log.
- Explicitly specify value for enum.
- Change the BTRFS_COMPRESS_TYPES to BTRFS_NR_COMPRESS_TYPES.

 fs/btrfs/compression.c  | 2 ++
 fs/btrfs/compression.h  | 4 ++--
 fs/btrfs/ioctl.c        | 2 +-
 fs/btrfs/tree-checker.c | 5 +++--
 4 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c
index b05b361e2062..45d49f207989 100644
--- a/fs/btrfs/compression.c
+++ b/fs/btrfs/compression.c
@@ -39,6 +39,8 @@ const char* btrfs_compress_type2str(enum btrfs_compression_type type)
 	case BTRFS_COMPRESS_ZSTD:
 	case BTRFS_COMPRESS_NONE:
 		return btrfs_compress_types[type];
+	default:
+		break;
 	}
 
 	return NULL;
diff --git a/fs/btrfs/compression.h b/fs/btrfs/compression.h
index 4cb8be9ff88b..e64336b98358 100644
--- a/fs/btrfs/compression.h
+++ b/fs/btrfs/compression.h
@@ -104,7 +104,7 @@ enum btrfs_compression_type {
 	BTRFS_COMPRESS_ZLIB  = 1,
 	BTRFS_COMPRESS_LZO   = 2,
 	BTRFS_COMPRESS_ZSTD  = 3,
-	BTRFS_COMPRESS_TYPES = 3,
+	BTRFS_NR_COMPRESS_TYPES = 4,
 };
 
 struct workspace_manager {
@@ -162,7 +162,7 @@ struct btrfs_compress_op {
 };
 
 /* The heuristic workspaces are managed via the 0th workspace manager */
-#define BTRFS_NR_WORKSPACE_MANAGERS	(BTRFS_COMPRESS_TYPES + 1)
+#define BTRFS_NR_WORKSPACE_MANAGERS	BTRFS_NR_COMPRESS_TYPES
 
 extern const struct btrfs_compress_op btrfs_heuristic_compress;
 extern const struct btrfs_compress_op btrfs_zlib_compress;
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index de730e56d3f5..cea3bc6a23ce 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -1411,7 +1411,7 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,
 		return -EINVAL;
 
 	if (do_compress) {
-		if (range->compress_type > BTRFS_COMPRESS_TYPES)
+		if (range->compress_type >= BTRFS_NR_COMPRESS_TYPES)
 			return -EINVAL;
 		if (range->compress_type)
 			compress_type = range->compress_type;
diff --git a/fs/btrfs/tree-checker.c b/fs/btrfs/tree-checker.c
index 43e488f5d063..92bde1d5b5d7 100644
--- a/fs/btrfs/tree-checker.c
+++ b/fs/btrfs/tree-checker.c
@@ -155,11 +155,12 @@ static int check_extent_data_item(struct extent_buffer *leaf,
 	 * Support for new compression/encryption must introduce incompat flag,
 	 * and must be caught in open_ctree().
 	 */
-	if (btrfs_file_extent_compression(leaf, fi) > BTRFS_COMPRESS_TYPES) {
+	if (btrfs_file_extent_compression(leaf, fi) >=
+						BTRFS_NR_COMPRESS_TYPES) {
 		file_extent_err(leaf, slot,
 	"invalid compression for file extent, have %u expect range [0, %u]",
 			btrfs_file_extent_compression(leaf, fi),
-			BTRFS_COMPRESS_TYPES);
+			BTRFS_NR_COMPRESS_TYPES - 1);
 		return -EUCLEAN;
 	}
 	if (btrfs_file_extent_encryption(leaf, fi)) {
-- 
2.20.1




^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v2 3/3] btrfs: using enum to replace macro
  2019-10-10  7:59 [PATCH v2 1/3] btrfs: remove unnecessary hash_init() Chengguang Xu
  2019-10-10  7:59 ` [PATCH v2 2/3] btrfs: code cleanup for compression type Chengguang Xu
@ 2019-10-10  7:59 ` Chengguang Xu
  2019-10-10 16:58 ` [PATCH v2 1/3] btrfs: remove unnecessary hash_init() David Sterba
  2 siblings, 0 replies; 4+ messages in thread
From: Chengguang Xu @ 2019-10-10  7:59 UTC (permalink / raw)
  To: clm, josef, dsterba; +Cc: linux-btrfs, Chengguang Xu

Using enum to replace macro definition
of extent types.

Signed-off-by: Chengguang Xu <cgxu519@mykernel.net>
---
v1->v2:
- Explicitly specify value for enum.
- Change the name BTRFS_FILE_EXTENT_TYPES to BTRFS_NR_FILE_EXTENT_TYPES.

 fs/btrfs/tree-checker.c         |  4 ++--
 include/uapi/linux/btrfs_tree.h | 10 ++++++----
 2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/fs/btrfs/tree-checker.c b/fs/btrfs/tree-checker.c
index 92bde1d5b5d7..0e71085c008a 100644
--- a/fs/btrfs/tree-checker.c
+++ b/fs/btrfs/tree-checker.c
@@ -143,11 +143,11 @@ static int check_extent_data_item(struct extent_buffer *leaf,
 
 	fi = btrfs_item_ptr(leaf, slot, struct btrfs_file_extent_item);
 
-	if (btrfs_file_extent_type(leaf, fi) > BTRFS_FILE_EXTENT_TYPES) {
+	if (btrfs_file_extent_type(leaf, fi) >= BTRFS_NR_FILE_EXTENT_TYPES) {
 		file_extent_err(leaf, slot,
 		"invalid type for file extent, have %u expect range [0, %u]",
 			btrfs_file_extent_type(leaf, fi),
-			BTRFS_FILE_EXTENT_TYPES);
+			BTRFS_NR_FILE_EXTENT_TYPES - 1);
 		return -EUCLEAN;
 	}
 
diff --git a/include/uapi/linux/btrfs_tree.h b/include/uapi/linux/btrfs_tree.h
index b65c7ee75bc7..4c8f9ea73191 100644
--- a/include/uapi/linux/btrfs_tree.h
+++ b/include/uapi/linux/btrfs_tree.h
@@ -737,10 +737,12 @@ struct btrfs_balance_item {
 	__le64 unused[4];
 } __attribute__ ((__packed__));
 
-#define BTRFS_FILE_EXTENT_INLINE 0
-#define BTRFS_FILE_EXTENT_REG 1
-#define BTRFS_FILE_EXTENT_PREALLOC 2
-#define BTRFS_FILE_EXTENT_TYPES	2
+enum {
+	BTRFS_FILE_EXTENT_INLINE = 0,
+	BTRFS_FILE_EXTENT_REG = 1,
+	BTRFS_FILE_EXTENT_PREALLOC = 2,
+	BTRFS_NR_FILE_EXTENT_TYPES = 3
+};
 
 struct btrfs_file_extent_item {
 	/*
-- 
2.20.1




^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 1/3] btrfs: remove unnecessary hash_init()
  2019-10-10  7:59 [PATCH v2 1/3] btrfs: remove unnecessary hash_init() Chengguang Xu
  2019-10-10  7:59 ` [PATCH v2 2/3] btrfs: code cleanup for compression type Chengguang Xu
  2019-10-10  7:59 ` [PATCH v2 3/3] btrfs: using enum to replace macro Chengguang Xu
@ 2019-10-10 16:58 ` David Sterba
  2 siblings, 0 replies; 4+ messages in thread
From: David Sterba @ 2019-10-10 16:58 UTC (permalink / raw)
  To: Chengguang Xu; +Cc: clm, josef, dsterba, linux-btrfs

On Thu, Oct 10, 2019 at 03:59:56PM +0800, Chengguang Xu wrote:
> DEFINE_HASHTABLE itself has already included initialization code,
> we don't have to call hash_init() again, so remove it.
> 
> Signed-off-by: Chengguang Xu <cgxu519@mykernel.net>

1-3 added to misc-next, with minor updates. Thanks.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-10-10 16:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-10  7:59 [PATCH v2 1/3] btrfs: remove unnecessary hash_init() Chengguang Xu
2019-10-10  7:59 ` [PATCH v2 2/3] btrfs: code cleanup for compression type Chengguang Xu
2019-10-10  7:59 ` [PATCH v2 3/3] btrfs: using enum to replace macro Chengguang Xu
2019-10-10 16:58 ` [PATCH v2 1/3] btrfs: remove unnecessary hash_init() David Sterba

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).