All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/6] Btrfs-progs: fsck: switch to is_fstree()
@ 2014-06-19  1:27 Wang Shilong
  2014-06-19  1:27 ` [PATCH 2/6] Btrfs-progs: btrfs-restore,check if specified root is fs/file tree firstly Wang Shilong
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Wang Shilong @ 2014-06-19  1:27 UTC (permalink / raw)
  To: linux-btrfs

Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
---
 cmds-check.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/cmds-check.c b/cmds-check.c
index c56da2a..26baab0 100644
--- a/cmds-check.c
+++ b/cmds-check.c
@@ -2049,13 +2049,10 @@ skip_walking:
 
 static int fs_root_objectid(u64 objectid)
 {
-	if (objectid == BTRFS_FS_TREE_OBJECTID ||
-	    objectid == BTRFS_TREE_RELOC_OBJECTID ||
-	    objectid == BTRFS_DATA_RELOC_TREE_OBJECTID ||
-	    (objectid >= BTRFS_FIRST_FREE_OBJECTID &&
-	     objectid <= BTRFS_LAST_FREE_OBJECTID))
+	if (objectid == BTRFS_TREE_RELOC_OBJECTID ||
+	    objectid == BTRFS_DATA_RELOC_TREE_OBJECTID)
 		return 1;
-	return 0;
+	return is_fstree(objectid);
 }
 
 static int check_fs_roots(struct btrfs_root *root,
-- 
1.9.0


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

* [PATCH 2/6] Btrfs-progs: btrfs-restore,check if specified root is fs/file tree firstly
  2014-06-19  1:27 [PATCH 1/6] Btrfs-progs: fsck: switch to is_fstree() Wang Shilong
@ 2014-06-19  1:27 ` Wang Shilong
  2014-06-19  1:27 ` [PATCH 3/6] Btrfs-progs: btrfs-restore, fix wrong return value if it fails to read specified fs root Wang Shilong
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Wang Shilong @ 2014-06-19  1:27 UTC (permalink / raw)
  To: linux-btrfs

Steps to reproduce:
 # mkfs.btrfs -f /dev/sda9
 # mount /dev/sda9 /mnt
 # dd if=/dev/zero of=/mnt/data bs=1M count=1
 # btrfs restore -r /dev/sda9 -r 2 -o /tmp

If users don't input a valid fs/file root objectid, btrfs restore still
continue and don't restore anything, this is unfriendly, we could
check it firstly.

Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
---
 cmds-restore.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/cmds-restore.c b/cmds-restore.c
index 96b97e1..934755a 100644
--- a/cmds-restore.c
+++ b/cmds-restore.c
@@ -1180,6 +1180,11 @@ int cmd_restore(int argc, char **argv)
 				break;
 			case 'r':
 				root_objectid = arg_strtou64(optarg);
+				if (!is_fstree(root_objectid)) {
+					fprintf(stderr, "objectid %llu is not a valid fs/file tree\n",
+							root_objectid);
+					exit(1);
+				}
 				break;
 			case 'l':
 				list_roots = 1;
-- 
1.9.0


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

* [PATCH 3/6] Btrfs-progs: btrfs-restore, fix wrong return value if it fails to read specified fs root
  2014-06-19  1:27 [PATCH 1/6] Btrfs-progs: fsck: switch to is_fstree() Wang Shilong
  2014-06-19  1:27 ` [PATCH 2/6] Btrfs-progs: btrfs-restore,check if specified root is fs/file tree firstly Wang Shilong
@ 2014-06-19  1:27 ` Wang Shilong
  2014-06-19  1:27 ` [PATCH 4/6] Btrfs-progs: btrfs-restore,output resason why it fails to read root Wang Shilong
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Wang Shilong @ 2014-06-19  1:27 UTC (permalink / raw)
  To: linux-btrfs

Steps to reproduce:
 # mkfs.btrfs -f /dev/sda9
 # btrfs restore -f 1 -o /tmp /dev/sda9
 # echo $?

Fix to return 1 in this failure path.

Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
---
 cmds-restore.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/cmds-restore.c b/cmds-restore.c
index 934755a..48c46ff 100644
--- a/cmds-restore.c
+++ b/cmds-restore.c
@@ -1233,6 +1233,7 @@ int cmd_restore(int argc, char **argv)
 		root->node = read_tree_block(root, fs_location, root->leafsize, 0);
 		if (!root->node) {
 			fprintf(stderr, "Failed to read fs location\n");
+			ret = 1;
 			goto out;
 		}
 	}
-- 
1.9.0


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

* [PATCH 4/6] Btrfs-progs: btrfs-restore,output resason why it fails to read root
  2014-06-19  1:27 [PATCH 1/6] Btrfs-progs: fsck: switch to is_fstree() Wang Shilong
  2014-06-19  1:27 ` [PATCH 2/6] Btrfs-progs: btrfs-restore,check if specified root is fs/file tree firstly Wang Shilong
  2014-06-19  1:27 ` [PATCH 3/6] Btrfs-progs: btrfs-restore, fix wrong return value if it fails to read specified fs root Wang Shilong
@ 2014-06-19  1:27 ` Wang Shilong
  2014-06-19  1:27 ` [PATCH 5/6] Btrfs-progs: btrfs-restore, don't allow users to specify -r and -f at the same time Wang Shilong
  2014-06-19  1:27 ` [PATCH 6/6] Btrfs-progs: btrfs-restore, document updates Wang Shilong
  4 siblings, 0 replies; 6+ messages in thread
From: Wang Shilong @ 2014-06-19  1:27 UTC (permalink / raw)
  To: linux-btrfs

Previously if restore could not read users specified fs root, it would
output following message:

 Error reading root

With this patch, it will output message like:

 Fail to read root 1000: No such file or directory

Signed-off-byr Wang Shilong <wangsl.fnst@cn.fujitsu.com>
---
 cmds-restore.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/cmds-restore.c b/cmds-restore.c
index 48c46ff..8267ab6 100644
--- a/cmds-restore.c
+++ b/cmds-restore.c
@@ -1257,7 +1257,8 @@ int cmd_restore(int argc, char **argv)
 		key.offset = (u64)-1;
 		root = btrfs_read_fs_root(orig_root->fs_info, &key);
 		if (IS_ERR(root)) {
-			fprintf(stderr, "Error reading root\n");
+			fprintf(stderr, "fail to read root %llu: %s\n",
+					root_objectid, strerror(-PTR_ERR(root)));
 			root = orig_root;
 			ret = 1;
 			goto out;
-- 
1.9.0


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

* [PATCH 5/6] Btrfs-progs: btrfs-restore, don't allow users to specify -r and -f at the same time
  2014-06-19  1:27 [PATCH 1/6] Btrfs-progs: fsck: switch to is_fstree() Wang Shilong
                   ` (2 preceding siblings ...)
  2014-06-19  1:27 ` [PATCH 4/6] Btrfs-progs: btrfs-restore,output resason why it fails to read root Wang Shilong
@ 2014-06-19  1:27 ` Wang Shilong
  2014-06-19  1:27 ` [PATCH 6/6] Btrfs-progs: btrfs-restore, document updates Wang Shilong
  4 siblings, 0 replies; 6+ messages in thread
From: Wang Shilong @ 2014-06-19  1:27 UTC (permalink / raw)
  To: linux-btrfs

These two options are used for same purpose, but they are exclusive with
each other. Make it clear to common users.

Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
---
 cmds-restore.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/cmds-restore.c b/cmds-restore.c
index 8267ab6..3a29ed6 100644
--- a/cmds-restore.c
+++ b/cmds-restore.c
@@ -1212,6 +1212,11 @@ int cmd_restore(int argc, char **argv)
 	else if (list_roots && optind >= argc)
 		usage(cmd_restore_usage);
 
+	if (fs_location && root_objectid) {
+		fprintf(stderr, "don't use -f and -r at the same time.\n");
+		return 1;
+	}
+
 	if ((ret = check_mounted(argv[optind])) < 0) {
 		fprintf(stderr, "Could not check mount status: %s\n",
 			strerror(-ret));
-- 
1.9.0


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

* [PATCH 6/6] Btrfs-progs: btrfs-restore, document updates
  2014-06-19  1:27 [PATCH 1/6] Btrfs-progs: fsck: switch to is_fstree() Wang Shilong
                   ` (3 preceding siblings ...)
  2014-06-19  1:27 ` [PATCH 5/6] Btrfs-progs: btrfs-restore, don't allow users to specify -r and -f at the same time Wang Shilong
@ 2014-06-19  1:27 ` Wang Shilong
  4 siblings, 0 replies; 6+ messages in thread
From: Wang Shilong @ 2014-06-19  1:27 UTC (permalink / raw)
  To: linux-btrfs

Add some missing options, also improve some confusing
expressions.

Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
---
 Documentation/btrfs-restore.txt | 26 ++++++++++++++++++--------
 cmds-restore.c                  |  7 ++++---
 2 files changed, 22 insertions(+), 11 deletions(-)

diff --git a/Documentation/btrfs-restore.txt b/Documentation/btrfs-restore.txt
index d774343..85b0797 100644
--- a/Documentation/btrfs-restore.txt
+++ b/Documentation/btrfs-restore.txt
@@ -24,7 +24,7 @@ https://btrfs.wiki.kernel.org/index.php/Restore
 OPTIONS
 -------
 -s::
-get snapshots.
+get snapshots, btrfs restore skips snapshots in default.
 
 -x::
 get extended attributes.
@@ -38,17 +38,17 @@ ignore errors.
 -o::
 overwrite directories/files in <path>.
 
--t <location>::
-use <location> to read root tree.
+-t <bytenr>::
+use <bytenr> to read root tree.
 
--f <offset>::
-use <offset> to read fs tree.
+-f <bytenr>::
+only restore files that are under specified root whose root bytenr is <bytenr>.
 
--u <block>::
-use given superblock mirror identified by <block>.
+-u <mirror>::
+use given superblock mirror identified by <mirror>, it can be 0,1,2.
 
 -r <rootid>::
-use <rootid> as root objectid.
+only restore files that are under specified root whose objectid is <rootid>.
 
 -d::
 find dir.
@@ -56,6 +56,16 @@ find dir.
 -l::
 list tree roots.
 
+-D|--dry-run::
+dry run (only list files that would be recovered).
+
+--path-regex <regex>::
+restore only filenames matching regex, you have to use following syntax (possibly quoted):
+^/(|home(|/username(|/Desktop(|/.*))))$
+
+-c::
+ignore case(--path-regrex only).
+
 EXIT STATUS
 -----------
 *btrfs restore* returns a zero exist status if it succeeds. Non zero is
diff --git a/cmds-restore.c b/cmds-restore.c
index 3a29ed6..74f35a4 100644
--- a/cmds-restore.c
+++ b/cmds-restore.c
@@ -1111,9 +1111,9 @@ const char * const cmd_restore_usage[] = {
 	"-v              verbose",
 	"-i              ignore errors",
 	"-o              overwrite",
-	"-t <location>   tree location",
-	"-f <offset>     filesystem location",
-	"-u <block>      super mirror",
+	"-t <bytenr>     tree location",
+	"-f <bytenr>     filesystem location",
+	"-u <mirror>     super mirror",
 	"-r <rootid>     root objectid",
 	"-d              find dir",
 	"-l              list tree roots",
@@ -1122,6 +1122,7 @@ const char * const cmd_restore_usage[] = {
 	"                restore only filenames matching regex,",
 	"                you have to use following syntax (possibly quoted):",
 	"                ^/(|home(|/username(|/Desktop(|/.*))))$",
+	"-c              ignore case(--path-regrex only)",
 	NULL
 };
 
-- 
1.9.0


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

end of thread, other threads:[~2014-06-19  1:32 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-19  1:27 [PATCH 1/6] Btrfs-progs: fsck: switch to is_fstree() Wang Shilong
2014-06-19  1:27 ` [PATCH 2/6] Btrfs-progs: btrfs-restore,check if specified root is fs/file tree firstly Wang Shilong
2014-06-19  1:27 ` [PATCH 3/6] Btrfs-progs: btrfs-restore, fix wrong return value if it fails to read specified fs root Wang Shilong
2014-06-19  1:27 ` [PATCH 4/6] Btrfs-progs: btrfs-restore,output resason why it fails to read root Wang Shilong
2014-06-19  1:27 ` [PATCH 5/6] Btrfs-progs: btrfs-restore, don't allow users to specify -r and -f at the same time Wang Shilong
2014-06-19  1:27 ` [PATCH 6/6] Btrfs-progs: btrfs-restore, document updates Wang Shilong

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.