Skip to contentSkip to conversation

btrfs-progs: stat info for btrfs rescue chunk-recover

PATCH Superseded Zhao Lei 1 participant 4 messages Sep 2, 2015 Btrfs file system

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Zhao Lei

author
#0 lore raw

cover btrfs-progs: stat info for btrfs rescue chunk-recover

chunk-recover need to use many many time in scan_devices(), and no output in screen:

 # btrfs rescue chunk-recover /dev/sda6
 (no output here, but need long time)

To notice user that "the command is not hang", this patch add dynamic updated stat information in above period:

 # btrfs rescue chunk-recover /dev/sda6
 Scanning: DONE in dev[0], 19998441472 in dev[1], DONE in dev[2]
 (until)
 Scanning: DONE in dev0, DONE in dev1, DONE in dev2
 Check chunks successfully with no orphans
 Recover the chunk tree successfully.

Zhao Lei (3):
btrfs-progs: use for loop for scan_devices
btrfs-progs: stat info for btrfs rescue chunk-recover
btrfs-progs: Fix some spelling typo in chunk-recover.c

 chunk-recover.c | 80 ++++++++++++++++++++++++++++++++++++++++-----------------
 1 file changed, 57 insertions(+), 23 deletions(-)
Signature · 1 line
1.8.5.1
author
#1 lore raw

PATCH 1/3 btrfs-progs: use for loop for scan_devices

for() is more suitable than while() in this code block.

---
 chunk-recover.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
chunk-recover.c +1 -3
index 832b3b1..66a4ce6 100644
@@ -871,8 +871,7 @@ static int scan_devices(struct recover_control *rc)
 		devidx++;
 	}
 
-	i = 0;
-	while (i < devidx) {
+	for (i = 0; i < devidx; i++) {
 		ret = pthread_join(t_scans[i], (void **)&t_rets[i]);
 		if (ret || t_rets[i]) {
 			ret = 1;
@@ -880,7 +879,6 @@ static int scan_devices(struct recover_control *rc)
 			cancel_to = devnr - 1;
 			goto out1;
 		}
-		i++;
 	}
 out1:
 	while (ret && (cancel_from <= cancel_to)) {
Signature · 1 line
1.8.5.1
author
#2 lore raw

PATCH 2/3 btrfs-progs: stat info for btrfs rescue chunk-recover

In reply to Zhao Lei

chunk-recover need to use many many time in scan_devices(), and no output in screen:

 # btrfs rescue chunk-recover /dev/sda6
 (no output here, but need long time)

To notice user that "the command is not hang", this patch add dynamic updated stat information in above period:

 # btrfs rescue chunk-recover /dev/sda6
 Scanning: DONE in dev[0], 19998441472 in dev[1], DONE in dev[2]
 (until)
 Scanning: DONE in dev0, DONE in dev1, DONE in dev2
 Check chunks successfully with no orphans
 Recover the chunk tree successfully.
---
 chunk-recover.c | 72 ++++++++++++++++++++++++++++++++++++++++++---------------
 1 file changed, 54 insertions(+), 18 deletions(-)
chunk-recover.c +54 -18
index 66a4ce6..7698ee0 100644
@@ -76,6 +76,7 @@ struct device_scan {
 	struct recover_control *rc;
 	struct btrfs_device *dev;
 	int fd;
+	u64 bytenr;
 };
 
 static struct extent_record *btrfs_new_extent_record(struct extent_buffer *eb)
@@ -766,6 +767,8 @@ static int scan_one_device(void *dev_scan_struct)
 
 	bytenr = 0;
 	while (1) {
+		dev_scan->bytenr = bytenr;
+
 		if (is_super_block_address(bytenr))
 			bytenr += rc->sectorsize;
 
@@ -832,9 +835,8 @@ static int scan_devices(struct recover_control *rc)
 	int *t_rets;
 	int devnr = 0;
 	int devidx = 0;
-	int cancel_from = 0;
-	int cancel_to = 0;
 	int i;
+	int all_done;
 
 	list_for_each_entry(dev, &rc->fs_devices->devices, dev_list)
 		devnr++;
@@ -860,30 +862,64 @@ static int scan_devices(struct recover_control *rc)
 		dev_scans[devidx].rc = rc;
 		dev_scans[devidx].dev = dev;
 		dev_scans[devidx].fd = fd;
-		ret = pthread_create(&t_scans[devidx], NULL,
-				     (void *)scan_one_device,
-				     (void *)&dev_scans[devidx]);
-		if (ret) {
-			cancel_from = 0;
-			cancel_to = devidx - 1;
-			goto out1;
-		}
+		dev_scans[devidx].bytenr = -1;
 		devidx++;
 	}
 
 	for (i = 0; i < devidx; i++) {
-		ret = pthread_join(t_scans[i], (void **)&t_rets[i]);
-		if (ret || t_rets[i]) {
-			ret = 1;
-			cancel_from = i + 1;
-			cancel_to = devnr - 1;
+		ret = pthread_create(&t_scans[i], NULL,
+				     (void *)scan_one_device,
+				     (void *)&dev_scans[i]);
+		if (ret)
 			goto out1;
+
+		dev_scans[i].bytenr = 0;
+	}
+
+	while (1) {
+		all_done = 1;
+		for (i = 0; i < devidx; i++) {
+			if (dev_scans[i].bytenr == -1)
+				continue;
+			ret = pthread_tryjoin_np(t_scans[i],
+						 (void **)&t_rets[i]);
+			if (ret == EBUSY) {
+				all_done = 0;
+				continue;
+			}
+			if (ret || t_rets[i]) {
+				ret = 1;
+				goto out1;
+			}
+			dev_scans[i].bytenr = -1;
+		}
+
+		printf("\rScanning: ");
+		for (i = 0; i < devidx; i++) {
+			if (dev_scans[i].bytenr == -1)
+				printf("%sDONE in dev%d",
+				       i ? ", " : "", i);
+			else
+				printf("%s%llu in dev%d",
+				       i ? ", " : "", dev_scans[i].bytenr, i);
 		}
+		/* clear chars if exist in tail */
+		printf("                ");
+		printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b");
+		fflush(stdout);
+
+		if (all_done) {
+			printf("\n");
+			break;
+		}
+
+		sleep(1);
 	}
 out1:
-	while (ret && (cancel_from <= cancel_to)) {
-		pthread_cancel(t_scans[cancel_from]);
-		cancel_from++;
+	for (i = 0; i < devidx; i++) {
+		if (dev_scans[i].bytenr == -1)
+			continue;
+		pthread_cancel(t_scans[i]);
 	}
 out2:
 	free(dev_scans);
Signature · 1 line
1.8.5.1
author
#3 lore raw

PATCH 3/3 btrfs-progs: Fix some spelling typo in chunk-recover.c

In reply to Zhao Lei

Only comment, not big issue.

And remove no-use aggument in block_group_free_all_extent().

---
 chunk-recover.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
chunk-recover.c +2 -2
index 7698ee0..d9d777a 100644
@@ -259,7 +259,7 @@ again:
 		list_del_init(&exist->list);
 		free(exist);
 		/*
-		 * We must do seach again to avoid the following cache.
+		 * We must do search again to avoid the following cache.
 		 * /--old bg 1--//--old bg 2--/
 		 *        /--new bg--/
 		 */
@@ -2310,7 +2310,7 @@ static void validate_rebuild_chunks(struct recover_control *rc)
 }
 
 /*
- * Return 0 when succesful, < 0 on error and > 0 if aborted by user
+ * Return 0 when successful, < 0 on error and > 0 if aborted by user
  */
 int btrfs_recover_chunk_tree(char *path, int verbose, int yes)
 {
Signature · 1 line
1.8.5.1