linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] btrfs-progs: fix uninitialized number count in chunk-recover
@ 2014-05-28 10:49 Gui Hecheng
  2014-05-28 10:49 ` [PATCH 2/2] btrfs-progs: fix blindly goto failure for chunk-recover Gui Hecheng
  0 siblings, 1 reply; 2+ messages in thread
From: Gui Hecheng @ 2014-05-28 10:49 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Gui Hecheng

When count the number of unordered device extents in chunk-recover,
the counter should be reinitialized to be used.
Also, introduce a new function for the counting job.

Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
---
 chunk-recover.c | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/chunk-recover.c b/chunk-recover.c
index 84fd8b7..924b2f6 100644
--- a/chunk-recover.c
+++ b/chunk-recover.c
@@ -1795,6 +1795,17 @@ static int insert_stripe(struct list_head *devexts,
 	return 0;
 }
 
+static inline int count_devext_records(struct list_head *record_list)
+{
+	int num_of_records = 0;
+	struct device_extent_record *devext;
+
+	list_for_each_entry(devext, record_list, chunk_list)
+		num_of_records++;
+
+	return num_of_records;
+}
+
 #define EQUAL_STRIPE (1 << 0)
 
 static int rebuild_raid_data_chunk_stripes(struct recover_control *rc,
@@ -1898,8 +1909,7 @@ next_csum:
 		fprintf(stderr, "Fetch csum failed\n");
 		goto fail_out;
 	} else if (ret == 1) {
-		list_for_each_entry(devext, &unordered, chunk_list)
-			num_unordered++;
+		num_unordered = count_devext_records(&unordered);
 		if (!(*flags & EQUAL_STRIPE))
 			*flags |= EQUAL_STRIPE;
 		goto out;
@@ -1927,8 +1937,7 @@ next_csum:
 	}
 
 	if (list_empty(&candidates)) {
-		list_for_each_entry(devext, &unordered, chunk_list)
-			num_unordered++;
+		num_unordered = count_devext_records(&unordered);
 		if (chunk->type_flags & BTRFS_BLOCK_GROUP_RAID6
 					&& num_unordered == 2) {
 			list_splice_init(&unordered, &chunk->dextents);
@@ -1963,8 +1972,7 @@ next_stripe:
 out:
 	ret = 0;
 	list_splice_init(&candidates, &unordered);
-	list_for_each_entry(devext, &unordered, chunk_list)
-		num_unordered++;
+	num_unordered = count_devext_records(&unordered);
 	if (num_unordered == 1) {
 		for (i = 0; i < chunk->num_stripes; i++) {
 			if (!chunk->stripes[i].devid) {
-- 
1.8.1.4


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

end of thread, other threads:[~2014-05-28 10:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-28 10:49 [PATCH 1/2] btrfs-progs: fix uninitialized number count in chunk-recover Gui Hecheng
2014-05-28 10:49 ` [PATCH 2/2] btrfs-progs: fix blindly goto failure for chunk-recover Gui Hecheng

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