linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] btrfs: convert while loop to list_for_each_entry
@ 2017-06-27  7:02 Nikolay Borisov
  2017-06-27  7:02 ` [PATCH 2/3] btrfs: Use explicit round_down call rather than open-coding it Nikolay Borisov
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Nikolay Borisov @ 2017-06-27  7:02 UTC (permalink / raw)
  To: dsterba; +Cc: linux-btrfs, Nikolay Borisov

No functional changes, just make the loop a bit more readable

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
---
 fs/btrfs/volumes.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index adf32f46a73f..9f4426014490 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -4619,7 +4619,7 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
 {
 	struct btrfs_fs_info *info = trans->fs_info;
 	struct btrfs_fs_devices *fs_devices = info->fs_devices;
-	struct list_head *cur;
+	struct btrfs_device *device;
 	struct map_lookup *map = NULL;
 	struct extent_map_tree *em_tree;
 	struct extent_map *em;
@@ -4693,22 +4693,15 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
 	if (!devices_info)
 		return -ENOMEM;
 
-	cur = fs_devices->alloc_list.next;
-
 	/*
 	 * in the first pass through the devices list, we gather information
 	 * about the available holes on each device.
 	 */
 	ndevs = 0;
-	while (cur != &fs_devices->alloc_list) {
-		struct btrfs_device *device;
+	list_for_each_entry(device, &fs_devices->alloc_list, dev_alloc_list) {
 		u64 max_avail;
 		u64 dev_offset;
 
-		device = list_entry(cur, struct btrfs_device, dev_alloc_list);
-
-		cur = cur->next;
-
 		if (!device->writeable) {
 			WARN(1, KERN_ERR
 			       "BTRFS: read-only device in alloc_list\n");
-- 
2.7.4


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

* [PATCH 2/3] btrfs: Use explicit round_down call rather than open-coding it
  2017-06-27  7:02 [PATCH 1/3] btrfs: convert while loop to list_for_each_entry Nikolay Borisov
@ 2017-06-27  7:02 ` Nikolay Borisov
  2017-06-27  7:02 ` [PATCH 3/3] btrfs: Be explicit about usage of min() Nikolay Borisov
  2017-06-30  8:09 ` [PATCH 1/3] btrfs: convert while loop to list_for_each_entry David Sterba
  2 siblings, 0 replies; 4+ messages in thread
From: Nikolay Borisov @ 2017-06-27  7:02 UTC (permalink / raw)
  To: dsterba; +Cc: linux-btrfs, Nikolay Borisov

No functional changes

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
---
 fs/btrfs/volumes.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 9f4426014490..07cfcc507ba6 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -4752,7 +4752,7 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
 	     btrfs_cmp_device_info, NULL);
 
 	/* round down to number of usable stripes */
-	ndevs -= ndevs % devs_increment;
+	ndevs = round_down(ndevs, devs_increment);
 
 	if (ndevs < devs_increment * sub_stripes || ndevs < devs_min) {
 		ret = -ENOSPC;
-- 
2.7.4


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

* [PATCH 3/3] btrfs: Be explicit about usage of min()
  2017-06-27  7:02 [PATCH 1/3] btrfs: convert while loop to list_for_each_entry Nikolay Borisov
  2017-06-27  7:02 ` [PATCH 2/3] btrfs: Use explicit round_down call rather than open-coding it Nikolay Borisov
@ 2017-06-27  7:02 ` Nikolay Borisov
  2017-06-30  8:09 ` [PATCH 1/3] btrfs: convert while loop to list_for_each_entry David Sterba
  2 siblings, 0 replies; 4+ messages in thread
From: Nikolay Borisov @ 2017-06-27  7:02 UTC (permalink / raw)
  To: dsterba; +Cc: linux-btrfs, Nikolay Borisov

__btrfs_alloc_chunk contains code which boils down to:

    ndevs = min(ndevs, devs_max)

It's conditional upon devs_max not being 0. However, it cannot really be 0
since it's always set to either BTRFS_MAX_DEVS_SYS_CHUNK or
BTRFS_MAX_DEVS(fs_info->chunk_root). So eliminate the condition check and use
min explicitly. This has no functional changes

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
---
 fs/btrfs/volumes.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 07cfcc507ba6..12d4e3c4bd2b 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -4759,8 +4759,8 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
 		goto error;
 	}
 
-	if (devs_max && ndevs > devs_max)
-		ndevs = devs_max;
+	ndevs = min(ndevs, devs_max);
+
 	/*
 	 * the primary goal is to maximize the number of stripes, so use as many
 	 * devices as possible, even if the stripes are not maximum sized.
-- 
2.7.4


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

* Re: [PATCH 1/3] btrfs: convert while loop to list_for_each_entry
  2017-06-27  7:02 [PATCH 1/3] btrfs: convert while loop to list_for_each_entry Nikolay Borisov
  2017-06-27  7:02 ` [PATCH 2/3] btrfs: Use explicit round_down call rather than open-coding it Nikolay Borisov
  2017-06-27  7:02 ` [PATCH 3/3] btrfs: Be explicit about usage of min() Nikolay Borisov
@ 2017-06-30  8:09 ` David Sterba
  2 siblings, 0 replies; 4+ messages in thread
From: David Sterba @ 2017-06-30  8:09 UTC (permalink / raw)
  To: Nikolay Borisov; +Cc: dsterba, linux-btrfs

On Tue, Jun 27, 2017 at 10:02:24AM +0300, Nikolay Borisov wrote:
> No functional changes, just make the loop a bit more readable
> 
> Signed-off-by: Nikolay Borisov <nborisov@suse.com>

1-3 reviewed and added.

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

end of thread, other threads:[~2017-06-30  8:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-06-27  7:02 [PATCH 1/3] btrfs: convert while loop to list_for_each_entry Nikolay Borisov
2017-06-27  7:02 ` [PATCH 2/3] btrfs: Use explicit round_down call rather than open-coding it Nikolay Borisov
2017-06-27  7:02 ` [PATCH 3/3] btrfs: Be explicit about usage of min() Nikolay Borisov
2017-06-30  8:09 ` [PATCH 1/3] btrfs: convert while loop to list_for_each_entry 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).