Re: [PATCH 2/6] Btrfs-progs: add btrfsck functionality to btrfs

2013-06-02 Thread Dieter Ries
Hi everybody,

Am 08.02.2013 01:36, schrieb Ian Kumlien:
 diff --git a/cmds-check.c b/cmds-check.c
 index 71e98de..8e4cce0 100644
 --- a/cmds-check.c
 +++ b/cmds-check.c

[...]

 @@ -3574,7 +3579,8 @@ int main(int ac, char **av)
  (unsigned long long)bytenr);
   break;
   case '?':
 - print_usage();
 + case 'h':
 + usage(cmd_check_usage);
   }
   if (option_index == 1) {
   printf(enabling repair mode\n);

For this to have any effect, 'h' must be added to getopt_long(), see
attached patch 1.

However, this results in btrfsck -h and --help doing different things:

--help prints the usage message to stdout and exits with exit(0).
-h prints the usage message to stderr and exits with exit(129).

I made a patch to fix this, see attached patch 2.
What it doesn't fix though is, that -h/--help and -? don't do the same
thing. This is more complicated, as getop_long returns '?' for unknown
options.

Cheers,

Dieter
From 11aabdb018aed3c5b6a1616178883fd879152856 Mon Sep 17 00:00:00 2001
From: Dieter Ries m...@dieterries.net
Date: Sun, 2 Jun 2013 17:30:09 +0200
Subject: [PATCH 1/2] Btrfs-progs: Fix 'btrfsck/btrfs check -h'

For the '-h' option to be usable, getopts_long() has to know it.

Signed-off-by: Dieter Ries m...@dieterries.net
---
 cmds-check.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/cmds-check.c b/cmds-check.c
index 1e5e005..ff9298d 100644
--- a/cmds-check.c
+++ b/cmds-check.c
@@ -4065,7 +4065,7 @@ int cmd_check(int argc, char **argv)
 
 	while(1) {
 		int c;
-		c = getopt_long(argc, argv, as:, long_options,
+		c = getopt_long(argc, argv, ahs:, long_options,
 option_index);
 		if (c  0)
 			break;
-- 
1.8.1.3

From 52d9e47bfa0936a14baa48e8ad6ecdd820295809 Mon Sep 17 00:00:00 2001
From: Dieter Ries m...@dieterries.net
Date: Sun, 2 Jun 2013 17:32:15 +0200
Subject: [PATCH 2/2] Btrfs-progs: Fix '--help' to '-h' inconsistency in
 btrfsck/btrfs check

This patch fixes the following inconsistency between calling
btrfsck/btrfs check with the -h or --help options:
--help prints the usage message to stdout and exits with exit(0).
-h prints the usage message to stderr and exits with exit(129).

To achieve this, usage_command_usagestr() is made avalilable via
commands.h.

Signed-off-by: Dieter Ries m...@dieterries.net
---
 cmds-check.c | 5 -
 commands.h   | 2 ++
 help.c   | 2 +-
 3 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/cmds-check.c b/cmds-check.c
index ff9298d..093c859 100644
--- a/cmds-check.c
+++ b/cmds-check.c
@@ -4078,8 +4078,11 @@ int cmd_check(int argc, char **argv)
    (unsigned long long)bytenr);
 break;
 			case '?':
-			case 'h':
 usage(cmd_check_usage);
+break;
+			case 'h':
+usage_command_usagestr(cmd_check_usage, check, 1, 0);
+exit(0);
 		}
 		if (option_index == 1) {
 			printf(enabling repair mode\n);
diff --git a/commands.h b/commands.h
index 15c616d..814452f 100644
--- a/commands.h
+++ b/commands.h
@@ -73,6 +73,8 @@ extern const char * const generic_cmd_help_usage[];
 void usage(const char * const *usagestr);
 void usage_command(const struct cmd_struct *cmd, int full, int err);
 void usage_command_group(const struct cmd_group *grp, int all, int err);
+void usage_command_usagestr(const char * const *usagestr,
+const char *token, int full, int err);
 
 void help_unknown_token(const char *arg, const struct cmd_group *grp);
 void help_ambiguous_token(const char *arg, const struct cmd_group *grp);
diff --git a/help.c b/help.c
index 6d04293..effb72e 100644
--- a/help.c
+++ b/help.c
@@ -102,7 +102,7 @@ static int usage_command_internal(const char * const *usagestr,
 	return ret;
 }
 
-static void usage_command_usagestr(const char * const *usagestr,
+void usage_command_usagestr(const char * const *usagestr,
    const char *token, int full, int err)
 {
 	FILE *outf = err ? stderr : stdout;
-- 
1.8.1.3



[PATCH 2/4] btrfs-progs: btrfsck: Print which filesystem to be checked to stdout

2012-10-14 Thread Dieter Ries
This patch makes btrfsck print the filesystem, which is to be checked,
to stdout, as well as the UUID of the corresponding partition.
This should be helpful when analyzing (copied and pasted) output of
btrfsck.

Signed-off-by: Dieter Ries m...@dieterries.net
---
 btrfsck.c |7 +--
 1 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/btrfsck.c b/btrfsck.c
index 67f4a9d..ea654de 100644
--- a/btrfsck.c
+++ b/btrfsck.c
@@ -20,6 +20,7 @@
 #define _GNU_SOURCE 1
 #include stdio.h
 #include stdlib.h
+#include uuid/uuid.h
 #include unistd.h
 #include fcntl.h
 #include sys/stat.h
@@ -3492,6 +3493,7 @@ int main(int ac, char **av)
struct btrfs_fs_info *info;
struct btrfs_trans_handle *trans = NULL;
u64 bytenr = 0;
+   char uuidbuf[37];
int ret;
int num;
int repair = 0;
@@ -3540,9 +3542,10 @@ int main(int ac, char **av)
} else if(ret) {
fprintf(stderr, %s is currently mounted. Aborting.\n, 
av[optind]);
return -EBUSY;
-   }
-
+   } 
info = open_ctree_fs_info(av[optind], bytenr, rw, 1);
+   uuid_unparse(info-super_copy.fsid, uuidbuf);
+   printf(Checking filesystem on %s\nUUID: %s\n,av[optind],uuidbuf);
 
if (info == NULL)
return 1;
-- 
1.7.3.GIT

--
To unsubscribe from this list: send the line unsubscribe linux-btrfs in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 0/4] Resend: btrfs-progs: Some cosmetic changes (mainly) to btrfsck

2012-10-08 Thread Dieter Ries
Hi,

I sent an earlier version of this patchset before, and didn't get any response,
so here is the next try:

This patch series implements some mainly cosmetic changes to.
btrfs-progs, most in btrfsck.

As this is my first contribution here, I'd kindly ask you for feedback,
and if work like this is appreciated in general.

Cheers,

Dieter

Dieter Ries (4):
  btrfs-progs: Remove redundant Btrfs string from version string
  btrfs-progs: btrfsck: Print which filesystem to be checked to stdout
  btrfs-progs: btrfsck: Print feedback about fscking to stdout.
  btrfs-progs: btrfsck: Remove binary error code output

 btrfsck.c  |   29 ++---
 version.sh |2 +-
 2 files changed, 23 insertions(+), 8 deletions(-)

-- 
1.7.3.GIT

--
To unsubscribe from this list: send the line unsubscribe linux-btrfs in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 4/4] btrfs-progs: btrfsck: Remove binary error code output

2012-10-08 Thread Dieter Ries
This patch changes the output after checking a filesystem. Before, the
default output was found x bytes used err is 0, where the last integer
corresponds to the return value of check_root_refs(), which is either 1
or 0. Now this value is evaluated, and a message saying if errors were
found or not is printed.

Signed-off-by: Dieter Ries m...@dieterries.net
---
 btrfsck.c |7 +--
 1 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/btrfsck.c b/btrfsck.c
index 83275cd..45ce681 100644
--- a/btrfsck.c
+++ b/btrfsck.c
@@ -3613,8 +3613,11 @@ out:
   backup data and re-format the FS. *\n\n);
ret = 1;
}
-   printf(found %llu bytes used err is %d\n,
-  (unsigned long long)bytes_used, ret);
+   if (ret)
+   printf(Filesystem is damaged! One or more errors found.\n);
+   else
+   printf(Filesystem is clean! No errors found.\n);
+   printf(%llu bytes used\n,(unsigned long long)bytes_used);
printf(total csum bytes: %llu\n,(unsigned long long)total_csum_bytes);
printf(total tree bytes: %llu\n,
   (unsigned long long)total_btree_bytes);
-- 
1.7.3.GIT

--
To unsubscribe from this list: send the line unsubscribe linux-btrfs in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 3/4] btrfs-progs: btrfsck: Print feedback about fscking to stdout.

2012-10-08 Thread Dieter Ries
Status reports of the checking process should be printed to stdout
instead of stderr, as that is normal program output and not related to
problems in btrfsck. This patch changes this behaviour and adds the
output Done! after each of the parts.

Signed-off-by: Dieter Ries m...@dieterries.net
---
 btrfsck.c |   20 +++-
 1 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/btrfsck.c b/btrfsck.c
index 516bcdf..83275cd 100644
--- a/btrfsck.c
+++ b/btrfsck.c
@@ -3559,7 +3559,7 @@ int main(int ac, char **av)
 
root = info-fs_root;
 
-   fprintf(stderr, checking extents\n);
+   printf(checking extents... );
if (rw)
trans = btrfs_start_transaction(root, 1);
 
@@ -3567,22 +3567,32 @@ int main(int ac, char **av)
fprintf(stderr, Reinit crc root\n);
ret = btrfs_fsck_reinit_root(trans, info-csum_root);
if (ret) {
+   printf(\n);
fprintf(stderr, crc root initialization failed\n);
return -EIO;
}
goto out;
}
ret = check_extents(trans, root, repair);
-   if (ret)
+   if (ret) {
fprintf(stderr, Errors found in extent allocation tree\n);
+   printf(\n);
+   }
+   else
+   printf(Done!\n);
 
-   fprintf(stderr, checking fs roots\n);
+   printf(checking fs roots... );
ret = check_fs_roots(root, root_cache);
-   if (ret)
+   if (ret) {
+   printf(\n);
goto out;
+   }
+   else
+   printf(Done!\n);
 
-   fprintf(stderr, checking root refs\n);
+   printf(checking root refs... );
ret = check_root_refs(root, root_cache);
+   printf(Done!\n);
 out:
free_root_recs(root_cache);
if (rw) {
-- 
1.7.3.GIT

--
To unsubscribe from this list: send the line unsubscribe linux-btrfs in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1/4] btrfs-progs: Remove redundant Btrfs string from version string

2012-10-08 Thread Dieter Ries
In the first line of version.sh, $v was set to Btrfs vx.yy, and in
the end Btrfs $v was echoed to the version.h file. This resulted in
the version string Btrfs Btrfs vx.yy. This patch removes the second
occurrence of Btrfs.

Signed-off-by: Dieter Ries m...@dieterries.net
---
 version.sh |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/version.sh b/version.sh
index af3e441..2c1aff1 100644
--- a/version.sh
+++ b/version.sh
@@ -46,7 +46,7 @@ fi
  
 echo #ifndef __BUILD_VERSION  .build-version.h
 echo #define __BUILD_VERSION  .build-version.h
-echo #define BTRFS_BUILD_VERSION \Btrfs $v\  .build-version.h
+echo #define BTRFS_BUILD_VERSION \$v\  .build-version.h
 echo #endif  .build-version.h
 
 diff -q version.h .build-version.h  /dev/null
-- 
1.7.3.GIT

--
To unsubscribe from this list: send the line unsubscribe linux-btrfs in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 3/3] btrfs-progs: btrfsck: Print feedback about fscking to stdout.

2012-09-30 Thread Dieter Ries
Status reports of the checking process should be printed to stdout
instead of stderr, as that is normal program output and not related to
problems in btrfsck. This patch changes this behaviour and adds the
output Done! after each of the parts.

Signed-off-by: Dieter Ries m...@dieterries.net
---
 btrfsck.c |   19 ++-
 1 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/btrfsck.c b/btrfsck.c
index dde63e7..245ba7d 100644
--- a/btrfsck.c
+++ b/btrfsck.c
@@ -3557,7 +3557,7 @@ int main(int ac, char **av)
 
root = info-fs_root;
 
-   fprintf(stderr, checking extents\n);
+   printf(checking extents... );
if (rw)
trans = btrfs_start_transaction(root, 1);
 
@@ -3565,22 +3565,31 @@ int main(int ac, char **av)
fprintf(stderr, Reinit crc root\n);
ret = btrfs_fsck_reinit_root(trans, info-csum_root);
if (ret) {
+   printf(\n);
fprintf(stderr, crc root initialization failed\n);
return -EIO;
}
goto out;
}
ret = check_extents(trans, root, repair);
-   if (ret)
+   if (ret) {
fprintf(stderr, Errors found in extent allocation tree\n);
+   printf(\n);
+   }
+   else
+   printf(Done!\n);
 
-   fprintf(stderr, checking fs roots\n);
+   printf(checking fs roots... );
ret = check_fs_roots(root, root_cache);
-   if (ret)
+   if (ret) {
+   printf(\n);
goto out;
+   else
+   printf(Done!\n);
 
-   fprintf(stderr, checking root refs\n);
+   printf(checking root refs... );
ret = check_root_refs(root, root_cache);
+   printf(Done!\n);
 out:
free_root_recs(root_cache);
if (rw) {
-- 
1.7.3.GIT

--
To unsubscribe from this list: send the line unsubscribe linux-btrfs in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1/3] btrfs-progs: Remove redundant Btrfs string from version string

2012-09-30 Thread Dieter Ries
In the first line of version.sh, $v was set to Btrfs vx.yy, and in
the end Btrfs $v was echoed to the version.h file. This resulted in
the version string Btrfs Btrfs vx.yy. This patch removes the second
occurrence of Btrfs.

Signed-off-by: Dieter Ries m...@dieterries.net
---
 version.sh |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/version.sh b/version.sh
index af3e441..2c1aff1 100644
--- a/version.sh
+++ b/version.sh
@@ -46,7 +46,7 @@ fi
  
 echo #ifndef __BUILD_VERSION  .build-version.h
 echo #define __BUILD_VERSION  .build-version.h
-echo #define BTRFS_BUILD_VERSION \Btrfs $v\  .build-version.h
+echo #define BTRFS_BUILD_VERSION \$v\  .build-version.h
 echo #endif  .build-version.h
 
 diff -q version.h .build-version.h  /dev/null
-- 
1.7.3.GIT

--
To unsubscribe from this list: send the line unsubscribe linux-btrfs in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 2/3] btrfs-progs: btrfsck: Print which filesystem to be checked to stdout

2012-09-30 Thread Dieter Ries
This patch makes btrfsck print the filesystem, which is to be checked,
to stdout. This should be helpful when analyzing (copied and pasted)
output of btrfsck.

Signed-off-by: Dieter Ries m...@dieterries.net
---
 btrfsck.c |2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/btrfsck.c b/btrfsck.c
index 088b9f4..dde63e7 100644
--- a/btrfsck.c
+++ b/btrfsck.c
@@ -3538,6 +3538,8 @@ int main(int ac, char **av)
} else if(ret) {
fprintf(stderr, %s is currently mounted. Aborting.\n, 
av[optind]);
return -EBUSY;
+   } else {
+   printf(Checking filesystem on %s\n,av[optind]);
}
 
info = open_ctree_fs_info(av[optind], bytenr, rw, 1);
-- 
1.7.3.GIT

--
To unsubscribe from this list: send the line unsubscribe linux-btrfs in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 0/3] btrfs-progs: Some cosmetic changes (mainly) to btrfsck

2012-09-30 Thread Dieter Ries
Hi,

this patch series implements some mainly cosmetic changes to 
btrfs-progs, most in btrfsck.

As this is my first contribution here, I'd kindly ask you for feedback,
and if work like this is appreciated in general.

Cheers,

Dieter

Dieter Ries (3):
  btrfs-progs: Remove redundant Btrfs string from version string
  btrfs-progs: btrfsck: Print which filesystem to be checked to stdout
  btrfs-progs: btrfsck: Print feedback about fscking to stdout.

 btrfsck.c  |   21 -
 version.sh |2 +-
 2 files changed, 17 insertions(+), 6 deletions(-)

-- 
1.7.3.GIT

--
To unsubscribe from this list: send the line unsubscribe linux-btrfs in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html