Skip to contentSkip to conversation

Bool return cleanups

PATCH In review David Sterba 3 participants 7 messages Apr 23, 2025 – Apr 25, 2025 Btrfs file system

lore
Share & tools
lore

David Sterba

author maintainer
#0 lore raw

cover Bool return cleanups

We have old code that uses int in place of bool, unify it to bool. The rest are collateral fixups.

David Sterba (3):
btrfs: trivial conversion to return bool instead of int
btrfs: switch int dev_replace_is_ongoing variables/parameters to bool
btrfs: reformat comments in acls_after_inode_item()

 fs/btrfs/block-group.c   |  12 ++---
 fs/btrfs/defrag.c        |   8 +--
 fs/btrfs/delayed-inode.c |   8 +--
 fs/btrfs/dev-replace.c   |   8 +--
 fs/btrfs/dev-replace.h   |   2 +-
 fs/btrfs/extent-tree.c   |  10 ++--
 fs/btrfs/file.c          |  33 ++++++-------
 fs/btrfs/inode.c         |  51 +++++++++++--------
 fs/btrfs/ioctl.c         |  10 ++--
 fs/btrfs/locking.c       |   8 +--
 fs/btrfs/locking.h       |   2 +-
 fs/btrfs/super.c         |   6 +--
 fs/btrfs/transaction.c   |   8 +--
 fs/btrfs/volumes.c       | 104 ++++++++++++++++++---------------------
 14 files changed, 136 insertions(+), 134 deletions(-)
Signature · 1 line
2.49.0
author maintainer
#1 lore raw

PATCH 1/3 btrfs: trivial conversion to return bool instead of int

Old code has a lot of int for bool return values, bool is recommended and done in new code. Convert the trivial cases that do simple 0/false and 1/true. Functions comment are updated if needed.

---
 fs/btrfs/block-group.c   |  12 ++---
 fs/btrfs/defrag.c        |   8 ++--
 fs/btrfs/delayed-inode.c |   8 ++--
 fs/btrfs/dev-replace.c   |   8 ++--
 fs/btrfs/dev-replace.h   |   2 +-
 fs/btrfs/extent-tree.c   |  10 ++--
 fs/btrfs/file.c          |  33 +++++++------
 fs/btrfs/inode.c         |  14 +++---
 fs/btrfs/ioctl.c         |  10 ++--
 fs/btrfs/locking.c       |   8 ++--
 fs/btrfs/locking.h       |   2 +-
 fs/btrfs/super.c         |   6 +--
 fs/btrfs/transaction.c   |   8 ++--
 fs/btrfs/volumes.c       | 100 ++++++++++++++++++---------------------
 14 files changed, 111 insertions(+), 118 deletions(-)
fs/btrfs/block-group.c +6 -6
index bdde09f74fe282..4dbcba817ee4d7 100644
@@ -3873,14 +3873,14 @@ static void force_metadata_allocation(struct btrfs_fs_info *info)
 	}
 }
 
-static int should_alloc_chunk(const struct btrfs_fs_info *fs_info,
-			      const struct btrfs_space_info *sinfo, int force)
+static bool should_alloc_chunk(const struct btrfs_fs_info *fs_info,
+			       const struct btrfs_space_info *sinfo, int force)
 {
 	u64 bytes_used = btrfs_space_info_used(sinfo, false);
 	u64 thresh;
 
 	if (force == CHUNK_ALLOC_FORCE)
-		return 1;
+		return true;
 
 	/*
 	 * in limited mode, we want to have some free space up to
@@ -3891,12 +3891,12 @@ static int should_alloc_chunk(const struct btrfs_fs_info *fs_info,
 		thresh = max_t(u64, SZ_64M, mult_perc(thresh, 1));
 
 		if (sinfo->total_bytes - bytes_used < thresh)
-			return 1;
+			return true;
 	}
 
 	if (bytes_used + SZ_2M < mult_perc(sinfo->total_bytes, 80))
-		return 0;
-	return 1;
+		return false;
+	return true;
 }
 
 int btrfs_force_chunk_alloc(struct btrfs_trans_handle *trans, u64 type)
fs/btrfs/defrag.c +4 -4
index 3741a56e21145f..a3b6d49950eba4 100644
@@ -105,15 +105,15 @@ static int btrfs_insert_inode_defrag(struct btrfs_inode *inode,
 	return 0;
 }
 
-static inline int need_auto_defrag(struct btrfs_fs_info *fs_info)
+static inline bool need_auto_defrag(struct btrfs_fs_info *fs_info)
 {
 	if (!btrfs_test_opt(fs_info, AUTO_DEFRAG))
-		return 0;
+		return false;
 
 	if (btrfs_fs_closing(fs_info))
-		return 0;
+		return false;
 
-	return 1;
+	return true;
 }
 
 /*
fs/btrfs/delayed-inode.c +4 -4
index 4aa7e4dd34fa11..6ba1b60aba8875 100644
@@ -1384,17 +1384,17 @@ void btrfs_assert_delayed_root_empty(struct btrfs_fs_info *fs_info)
 	WARN_ON(btrfs_first_delayed_node(fs_info->delayed_root));
 }
 
-static int could_end_wait(struct btrfs_delayed_root *delayed_root, int seq)
+static bool could_end_wait(struct btrfs_delayed_root *delayed_root, int seq)
 {
 	int val = atomic_read(&delayed_root->items_seq);
 
 	if (val < seq || val >= seq + BTRFS_DELAYED_BATCH)
-		return 1;
+		return true;
 
 	if (atomic_read(&delayed_root->items) < BTRFS_DELAYED_BACKGROUND)
-		return 1;
+		return true;
 
-	return 0;
+	return false;
 }
 
 void btrfs_balance_delayed_items(struct btrfs_fs_info *fs_info)
fs/btrfs/dev-replace.c +4 -4
index 5c26f0fcf0d500..2decb9fff44519 100644
@@ -1265,16 +1265,16 @@ static int btrfs_dev_replace_kthread(void *data)
 	return 0;
 }
 
-int __pure btrfs_dev_replace_is_ongoing(struct btrfs_dev_replace *dev_replace)
+bool __pure btrfs_dev_replace_is_ongoing(struct btrfs_dev_replace *dev_replace)
 {
 	if (!dev_replace->is_valid)
-		return 0;
+		return false;
 
 	switch (dev_replace->replace_state) {
 	case BTRFS_IOCTL_DEV_REPLACE_STATE_NEVER_STARTED:
 	case BTRFS_IOCTL_DEV_REPLACE_STATE_FINISHED:
 	case BTRFS_IOCTL_DEV_REPLACE_STATE_CANCELED:
-		return 0;
+		return false;
 	case BTRFS_IOCTL_DEV_REPLACE_STATE_STARTED:
 	case BTRFS_IOCTL_DEV_REPLACE_STATE_SUSPENDED:
 		/*
@@ -1289,7 +1289,7 @@ int __pure btrfs_dev_replace_is_ongoing(struct btrfs_dev_replace *dev_replace)
 		 */
 		break;
 	}
-	return 1;
+	return true;
 }
 
 void btrfs_bio_counter_sub(struct btrfs_fs_info *fs_info, s64 amount)
fs/btrfs/dev-replace.h +1 -1
index 23e480efe5e6e4..b35cecf388f295 100644
@@ -25,7 +25,7 @@ void btrfs_dev_replace_status(struct btrfs_fs_info *fs_info,
 int btrfs_dev_replace_cancel(struct btrfs_fs_info *fs_info);
 void btrfs_dev_replace_suspend_for_unmount(struct btrfs_fs_info *fs_info);
 int btrfs_resume_dev_replace_async(struct btrfs_fs_info *fs_info);
-int __pure btrfs_dev_replace_is_ongoing(struct btrfs_dev_replace *dev_replace);
+bool __pure btrfs_dev_replace_is_ongoing(struct btrfs_dev_replace *dev_replace);
 bool btrfs_finish_block_group_to_copy(struct btrfs_device *srcdev,
 				      struct btrfs_block_group *cache,
 				      u64 physical);
fs/btrfs/extent-tree.c +5 -5
index e0811a86d0cbdd..f27cd3b41104ef 100644
@@ -409,15 +409,15 @@ static u64 hash_extent_data_ref_item(struct extent_buffer *leaf,
 				    btrfs_extent_data_ref_offset(leaf, ref));
 }
 
-static int match_extent_data_ref(struct extent_buffer *leaf,
-				 struct btrfs_extent_data_ref *ref,
-				 u64 root_objectid, u64 owner, u64 offset)
+static bool match_extent_data_ref(struct extent_buffer *leaf,
+				  struct btrfs_extent_data_ref *ref,
+				  u64 root_objectid, u64 owner, u64 offset)
 {
 	if (btrfs_extent_data_ref_root(leaf, ref) != root_objectid ||
 	    btrfs_extent_data_ref_objectid(leaf, ref) != owner ||
 	    btrfs_extent_data_ref_offset(leaf, ref) != offset)
-		return 0;
-	return 1;
+		return false;
+	return true;
 }
 
 static noinline int lookup_extent_data_ref(struct btrfs_trans_handle *trans,
fs/btrfs/file.c +16 -17
index 1e164530d9dc2a..5898d17041e822 100644
@@ -508,20 +508,19 @@ int btrfs_drop_extents(struct btrfs_trans_handle *trans,
 	return ret;
 }
 
-static int extent_mergeable(struct extent_buffer *leaf, int slot,
-			    u64 objectid, u64 bytenr, u64 orig_offset,
-			    u64 *start, u64 *end)
+static bool extent_mergeable(struct extent_buffer *leaf, int slot, u64 objectid,
+			     u64 bytenr, u64 orig_offset, u64 *start, u64 *end)
 {
 	struct btrfs_file_extent_item *fi;
 	struct btrfs_key key;
 	u64 extent_end;
 
 	if (slot < 0 || slot >= btrfs_header_nritems(leaf))
-		return 0;
+		return false;
 
 	btrfs_item_key_to_cpu(leaf, &key, slot);
 	if (key.objectid != objectid || key.type != BTRFS_EXTENT_DATA_KEY)
-		return 0;
+		return false;
 
 	fi = btrfs_item_ptr(leaf, slot, struct btrfs_file_extent_item);
 	if (btrfs_file_extent_type(leaf, fi) != BTRFS_FILE_EXTENT_REG ||
@@ -530,15 +529,15 @@ static int extent_mergeable(struct extent_buffer *leaf, int slot,
 	    btrfs_file_extent_compression(leaf, fi) ||
 	    btrfs_file_extent_encryption(leaf, fi) ||
 	    btrfs_file_extent_other_encoding(leaf, fi))
-		return 0;
+		return false;
 
 	extent_end = key.offset + btrfs_file_extent_num_bytes(leaf, fi);
 	if ((*start && *start != key.offset) || (*end && *end != extent_end))
-		return 0;
+		return false;
 
 	*start = key.offset;
 	*end = extent_end;
-	return 1;
+	return true;
 }
 
 /*
@@ -2004,33 +2003,33 @@ static int btrfs_file_mmap(struct file	*filp, struct vm_area_struct *vma)
 	return 0;
 }
 
-static int hole_mergeable(struct btrfs_inode *inode, struct extent_buffer *leaf,
-			  int slot, u64 start, u64 end)
+static bool hole_mergeable(struct btrfs_inode *inode, struct extent_buffer *leaf,
+			   int slot, u64 start, u64 end)
 {
 	struct btrfs_file_extent_item *fi;
 	struct btrfs_key key;
 
 	if (slot < 0 || slot >= btrfs_header_nritems(leaf))
-		return 0;
+		return false;
 
 	btrfs_item_key_to_cpu(leaf, &key, slot);
 	if (key.objectid != btrfs_ino(inode) ||
 	    key.type != BTRFS_EXTENT_DATA_KEY)
-		return 0;
+		return false;
 
 	fi = btrfs_item_ptr(leaf, slot, struct btrfs_file_extent_item);
 
 	if (btrfs_file_extent_type(leaf, fi) != BTRFS_FILE_EXTENT_REG)
-		return 0;
+		return false;
 
 	if (btrfs_file_extent_disk_bytenr(leaf, fi))
-		return 0;
+		return false;
 
 	if (key.offset == end)
-		return 1;
+		return true;
 	if (key.offset + btrfs_file_extent_num_bytes(leaf, fi) == start)
-		return 1;
-	return 0;
+		return true;
+	return false;
 }
 
 static int fill_holes(struct btrfs_trans_handle *trans,
fs/btrfs/inode.c +7 -7
index 9186729a00308f..e3bbe348ac91e2 100644
@@ -3726,9 +3726,9 @@ int btrfs_orphan_cleanup(struct btrfs_root *root)
  *
  * slot is the slot the inode is in, objectid is the objectid of the inode
  */
-static noinline int acls_after_inode_item(struct extent_buffer *leaf,
-					  int slot, u64 objectid,
-					  int *first_xattr_slot)
+static noinline bool acls_after_inode_item(struct extent_buffer *leaf,
+					   int slot, u64 objectid,
+					   int *first_xattr_slot)
 {
 	u32 nritems = btrfs_header_nritems(leaf);
 	struct btrfs_key found_key;
@@ -3750,7 +3750,7 @@ static noinline int acls_after_inode_item(struct extent_buffer *leaf,
 
 		/* we found a different objectid, there must not be acls */
 		if (found_key.objectid != objectid)
-			return 0;
+			return false;
 
 		/* we found an xattr, assume we've got an acl */
 		if (found_key.type == BTRFS_XATTR_ITEM_KEY) {
@@ -3758,7 +3758,7 @@ static noinline int acls_after_inode_item(struct extent_buffer *leaf,
 				*first_xattr_slot = slot;
 			if (found_key.offset == xattr_access ||
 			    found_key.offset == xattr_default)
-				return 1;
+				return true;
 		}
 
 		/*
@@ -3766,7 +3766,7 @@ static noinline int acls_after_inode_item(struct extent_buffer *leaf,
 		 * be any acls later on
 		 */
 		if (found_key.type > BTRFS_XATTR_ITEM_KEY)
-			return 0;
+			return false;
 
 		slot++;
 		scanned++;
@@ -3786,7 +3786,7 @@ static noinline int acls_after_inode_item(struct extent_buffer *leaf,
 	 */
 	if (*first_xattr_slot == -1)
 		*first_xattr_slot = slot;
-	return 1;
+	return true;
 }
 
 static int btrfs_init_file_extent_tree(struct btrfs_inode *inode)
fs/btrfs/ioctl.c +5 -5
index 68fac77fb95d1d..6bfb0a8c40af53 100644
@@ -1446,8 +1446,8 @@ static noinline int btrfs_ioctl_subvol_setflags(struct file *file,
 	return ret;
 }
 
-static noinline int key_in_sk(const struct btrfs_key *key,
-			      const struct btrfs_ioctl_search_key *sk)
+static noinline bool key_in_sk(const struct btrfs_key *key,
+			       const struct btrfs_ioctl_search_key *sk)
 {
 	struct btrfs_key test;
 	int ret;
@@ -1458,7 +1458,7 @@ static noinline int key_in_sk(const struct btrfs_key *key,
 
 	ret = btrfs_comp_cpu_keys(key, &test);
 	if (ret < 0)
-		return 0;
+		return false;
 
 	test.objectid = sk->max_objectid;
 	test.type = sk->max_type;
@@ -1466,8 +1466,8 @@ static noinline int key_in_sk(const struct btrfs_key *key,
 
 	ret = btrfs_comp_cpu_keys(key, &test);
 	if (ret > 0)
-		return 0;
-	return 1;
+		return false;
+	return true;
 }
 
 static noinline int copy_to_sk(struct btrfs_path *path,
fs/btrfs/locking.c +4 -4
index 81e62b652e2104..a3e6d9616e60bf 100644
@@ -149,15 +149,15 @@ void btrfs_tree_read_lock_nested(struct extent_buffer *eb, enum btrfs_lock_nesti
 /*
  * Try-lock for read.
  *
- * Return 1 if the rwlock has been taken, 0 otherwise
+ * Return true if the rwlock has been taken, false otherwise
  */
-int btrfs_try_tree_read_lock(struct extent_buffer *eb)
+bool btrfs_try_tree_read_lock(struct extent_buffer *eb)
 {
 	if (down_read_trylock(&eb->lock)) {
 		trace_btrfs_try_tree_read_lock(eb);
-		return 1;
+		return true;
 	}
-	return 0;
+	return false;
 }
 
 /*
fs/btrfs/locking.h +1 -1
index c69e57ff804bcf..af29df98ac1454 100644
@@ -189,7 +189,7 @@ static inline void btrfs_tree_read_lock(struct extent_buffer *eb)
 }
 
 void btrfs_tree_read_unlock(struct extent_buffer *eb);
-int btrfs_try_tree_read_lock(struct extent_buffer *eb);
+bool btrfs_try_tree_read_lock(struct extent_buffer *eb);
 struct extent_buffer *btrfs_lock_root_node(struct btrfs_root *root);
 struct extent_buffer *btrfs_read_lock_root_node(struct btrfs_root *root);
 struct extent_buffer *btrfs_try_read_lock_root_node(struct btrfs_root *root);
fs/btrfs/super.c +3 -3
index eb92465536f36d..ed9173d5eefbe4 100644
@@ -1148,11 +1148,11 @@ static int btrfs_show_options(struct seq_file *seq, struct dentry *dentry)
 /*
  * subvolumes are identified by ino 256
  */
-static inline int is_subvolume_inode(struct inode *inode)
+static inline bool is_subvolume_inode(struct inode *inode)
 {
 	if (inode && inode->i_ino == BTRFS_FIRST_FREE_OBJECTID)
-		return 1;
-	return 0;
+		return true;
+	return false;
 }
 
 static struct dentry *mount_subvol(const char *subvol_name, u64 subvol_objectid,
fs/btrfs/transaction.c +4 -4
index 2a8e0ce859edb2..7f6ea4abcdd7b6 100644
@@ -538,15 +538,15 @@ static void wait_current_trans(struct btrfs_fs_info *fs_info)
 	}
 }
 
-static int may_wait_transaction(struct btrfs_fs_info *fs_info, int type)
+static bool may_wait_transaction(struct btrfs_fs_info *fs_info, int type)
 {
 	if (test_bit(BTRFS_FS_LOG_RECOVERING, &fs_info->flags))
-		return 0;
+		return false;
 
 	if (type == TRANS_START)
-		return 1;
+		return true;
 
-	return 0;
+	return false;
 }
 
 static inline bool need_reserve_reloc_root(struct btrfs_root *root)
fs/btrfs/volumes.c +47 -53

260 lines not on this page · raw message

Signature · 1 line
2.49.0
author maintainer
#2 lore raw

PATCH 2/3 btrfs: switch int dev_replace_is_ongoing variables/parameters to bool

In reply to David Sterba

Both the variable and the parameter are used as logical indicators so convert them to bool.

---
 fs/btrfs/volumes.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/btrfs/volumes.c +2 -2
index c120f82dccdf59..5aa16f5016a9dd 100644
@@ -6079,7 +6079,7 @@ static int btrfs_read_rr(const struct btrfs_chunk_map *map, int first, int num_s
 
 static int find_live_mirror(struct btrfs_fs_info *fs_info,
 			    struct btrfs_chunk_map *map, int first,
-			    int dev_replace_is_ongoing)
+			    bool dev_replace_is_ongoing)
 {
 	const enum btrfs_read_policy policy = READ_ONCE(fs_info->fs_devices->read_policy);
 	int i;
@@ -6687,7 +6687,7 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op,
 	int num_copies;
 	struct btrfs_io_context *bioc = NULL;
 	struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace;
-	int dev_replace_is_ongoing = 0;
+	bool dev_replace_is_ongoing = false;
 	u16 num_alloc_stripes;
 	u64 max_len;
 
Signature · 1 line
2.49.0
author maintainer
#3 lore raw

PATCH 3/3 btrfs: reformat comments in acls_after_inode_item()

In reply to David Sterba
---
 fs/btrfs/inode.c | 37 +++++++++++++++++++++++--------------
 1 file changed, 23 insertions(+), 14 deletions(-)
fs/btrfs/inode.c +23 -14
index e3bbe348ac91e2..e18967a14d6419 100644
@@ -3721,10 +3721,14 @@ int btrfs_orphan_cleanup(struct btrfs_root *root)
 }
 
 /*
- * very simple check to peek ahead in the leaf looking for xattrs.  If we
- * don't find any xattrs, we know there can't be any acls.
+ * Look ahead in the leaf for xattrs. If we don't find any then we know there
+ * can be any ACLs.
  *
- * slot is the slot the inode is in, objectid is the objectid of the inode
+ * @leaf:       the eb leaf where to search
+ * @slot:       the slot the inode is in
+ * @objectid:   the objectid of the inode
+ *
+ * Retrun true if there is a xattr, false otherwise.
  */
 static noinline bool acls_after_inode_item(struct extent_buffer *leaf,
 					   int slot, u64 objectid,
@@ -3748,11 +3752,11 @@ static noinline bool acls_after_inode_item(struct extent_buffer *leaf,
 	while (slot < nritems) {
 		btrfs_item_key_to_cpu(leaf, &found_key, slot);
 
-		/* we found a different objectid, there must not be acls */
+		/* We found a different objectid, there must be no ACLs. */
 		if (found_key.objectid != objectid)
 			return false;
 
-		/* we found an xattr, assume we've got an acl */
+		/* We found an xattr, assume we've got an ACL. */
 		if (found_key.type == BTRFS_XATTR_ITEM_KEY) {
 			if (*first_xattr_slot == -1)
 				*first_xattr_slot = slot;
@@ -3762,8 +3766,8 @@ static noinline bool acls_after_inode_item(struct extent_buffer *leaf,
 		}
 
 		/*
-		 * we found a key greater than an xattr key, there can't
-		 * be any acls later on
+		 * We found a key greater than an xattr key, there can't be any
+		 * ACLs later on.
 		 */
 		if (found_key.type > BTRFS_XATTR_ITEM_KEY)
 			return false;
@@ -3772,17 +3776,22 @@ static noinline bool acls_after_inode_item(struct extent_buffer *leaf,
 		scanned++;
 
 		/*
-		 * it goes inode, inode backrefs, xattrs, extents,
-		 * so if there are a ton of hard links to an inode there can
-		 * be a lot of backrefs.  Don't waste time searching too hard,
-		 * this is just an optimization
+		 * The item order goes like:
+		 * - inode
+		 * - inode backrefs
+		 * - xattrs
+		 * - extents,
+		 *
+		 * so if there are lots of hard links to an inode there can be
+		 * a lot of backrefs.  Don't waste time searching too hard,
+		 * this is just an optimization.
 		 */
 		if (scanned >= 8)
 			break;
 	}
-	/* we hit the end of the leaf before we found an xattr or
-	 * something larger than an xattr.  We have to assume the inode
-	 * has acls
+	/*
+	 * We hit the end of the leaf before we found an xattr or something
+	 * larger than an xattr.  We have to assume the inode has ACLs.
 	 */
 	if (*first_xattr_slot == -1)
 		*first_xattr_slot = slot;
Signature · 1 line
2.49.0
#4 lore raw

Re: [PATCH 3/3] btrfs: reformat comments in acls_after_inode_item()

Quoted 10 lines · David Sterba
---
 fs/btrfs/inode.c | 37 +++++++++++++++++++++++--------------
 1 file changed, 23 insertions(+), 14 deletions(-)
fs/btrfs/inode.c +0 -0
index e3bbe348ac91e2..e18967a14d6419 100644

fs/btrfs/inode.c int btrfs_orphan_cleanup(struct btrfs_root *root) · line 3725

Quoted 7 lines
fs/btrfs/inode.c +2 -2
@@ -3721,10 +3721,14 @@ int btrfs_orphan_cleanup(struct btrfs_root *root)
 }
 
 /*
- * very simple check to peek ahead in the leaf looking for xattrs.  If we
- * don't find any xattrs, we know there can't be any acls.
+ * Look ahead in the leaf for xattrs. If we don't find any then we know there
+ * can be any ACLs.

can't be ?

fs/btrfs/inode.c int btrfs_orphan_cleanup(struct btrfs_root *root) · line 3731

Quoted 7 lines
fs/btrfs/inode.c +5 -1
  *
- * slot is the slot the inode is in, objectid is the objectid of the inode
+ * @leaf:       the eb leaf where to search
+ * @slot:       the slot the inode is in
+ * @objectid:   the objectid of the inode
+ *
+ * Retrun true if there is a xattr, false otherwise.

nit: typo: Return
Also, should it be "an xattr" ?

Quoted 58 lines
fs/btrfs/inode.c +16 -11
  */
 static noinline bool acls_after_inode_item(struct extent_buffer *leaf,
 					   int slot, u64 objectid,
@@ -3748,11 +3752,11 @@ static noinline bool acls_after_inode_item(struct extent_buffer *leaf,
 	while (slot < nritems) {
 		btrfs_item_key_to_cpu(leaf, &found_key, slot);
 
-		/* we found a different objectid, there must not be acls */
+		/* We found a different objectid, there must be no ACLs. */
 		if (found_key.objectid != objectid)
 			return false;
 
-		/* we found an xattr, assume we've got an acl */
+		/* We found an xattr, assume we've got an ACL. */
 		if (found_key.type == BTRFS_XATTR_ITEM_KEY) {
 			if (*first_xattr_slot == -1)
 				*first_xattr_slot = slot;
@@ -3762,8 +3766,8 @@ static noinline bool acls_after_inode_item(struct extent_buffer *leaf,
 		}
 
 		/*
-		 * we found a key greater than an xattr key, there can't
-		 * be any acls later on
+		 * We found a key greater than an xattr key, there can't be any
+		 * ACLs later on.
 		 */
 		if (found_key.type > BTRFS_XATTR_ITEM_KEY)
 			return false;
@@ -3772,17 +3776,22 @@ static noinline bool acls_after_inode_item(struct extent_buffer *leaf,
 		scanned++;
 
 		/*
-		 * it goes inode, inode backrefs, xattrs, extents,
-		 * so if there are a ton of hard links to an inode there can
-		 * be a lot of backrefs.  Don't waste time searching too hard,
-		 * this is just an optimization
+		 * The item order goes like:
+		 * - inode
+		 * - inode backrefs
+		 * - xattrs
+		 * - extents,
+		 *
+		 * so if there are lots of hard links to an inode there can be
+		 * a lot of backrefs.  Don't waste time searching too hard,
+		 * this is just an optimization.
 		 */
 		if (scanned >= 8)
 			break;
 	}
-	/* we hit the end of the leaf before we found an xattr or
-	 * something larger than an xattr.  We have to assume the inode
-	 * has acls
+	/*
+	 * We hit the end of the leaf before we found an xattr or something
+	 * larger than an xattr.  We have to assume the inode has ACLs.
 	 */
 	if (*first_xattr_slot == -1)
 		*first_xattr_slot = slot;
Reviewed-by on the v1 series
#6 lore raw
In reply to David Sterba
Quoted 7 lines · David Sterba

We have old code that uses int in place of bool, unify it to bool. The rest are collateral fixups.

David Sterba (3):
btrfs: trivial conversion to return bool instead of int
btrfs: switch int dev_replace_is_ongoing variables/parameters to bool
btrfs: reformat comments in acls_after_inode_item()

Other than some trivial nits on the patch 3, for the series

Quoted 16 lines
 fs/btrfs/block-group.c   |  12 ++---
 fs/btrfs/defrag.c        |   8 +--
 fs/btrfs/delayed-inode.c |   8 +--
 fs/btrfs/dev-replace.c   |   8 +--
 fs/btrfs/dev-replace.h   |   2 +-
 fs/btrfs/extent-tree.c   |  10 ++--
 fs/btrfs/file.c          |  33 ++++++-------
 fs/btrfs/inode.c         |  51 +++++++++++--------
 fs/btrfs/ioctl.c         |  10 ++--
 fs/btrfs/locking.c       |   8 +--
 fs/btrfs/locking.h       |   2 +-
 fs/btrfs/super.c         |   6 +--
 fs/btrfs/transaction.c   |   8 +--
 fs/btrfs/volumes.c       | 104 ++++++++++++++++++---------------------
 14 files changed, 136 insertions(+), 134 deletions(-)
#5 lore raw

Re: [PATCH 3/3] btrfs: reformat comments in acls_after_inode_item()

In reply to Naohiro Aota
Quoted 13 lines · Naohiro Aota
Quoted 12 lines · David Sterba
---
 fs/btrfs/inode.c | 37 +++++++++++++++++++++++--------------
 1 file changed, 23 insertions(+), 14 deletions(-)
fs/btrfs/inode.c +0 -0
index e3bbe348ac91e2..e18967a14d6419 100644
@@ -3721,10 +3721,14 @@ int btrfs_orphan_cleanup(struct btrfs_root *root)
 }
 
Quoted 7 lines

fs/btrfs/inode.c int btrfs_orphan_cleanup(struct btrfs_root *root) · line 3725

Quoted 5 lines
fs/btrfs/inode.c +2 -2
 /*
- * very simple check to peek ahead in the leaf looking for xattrs.  If we
- * don't find any xattrs, we know there can't be any acls.
+ * Look ahead in the leaf for xattrs. If we don't find any then we know there
+ * can be any ACLs.

can't be ?

Fixed, thanks.

Quoted 10 lines

fs/btrfs/inode.c int btrfs_orphan_cleanup(struct btrfs_root *root) · line 3731

Quoted 7 lines
fs/btrfs/inode.c +5 -1
  *
- * slot is the slot the inode is in, objectid is the objectid of the inode
+ * @leaf:       the eb leaf where to search
+ * @slot:       the slot the inode is in
+ * @objectid:   the objectid of the inode
+ *
+ * Retrun true if there is a xattr, false otherwise.

nit: typo: Return
Also, should it be "an xattr" ?

I don't know, I've changed it to 'xattr/ACL' without a/an, the reason is to make it clear that the xattr implies potential ACL.