Re: [PATCH 6/6] Btrfs-progs: add the rescue section to btrfs

2013-02-12 Thread David Sterba
On Fri, Feb 08, 2013 at 01:37:02AM +0100, Ian Kumlien wrote:
 the btrfs command now lists:
 btrfs rescue select-super -s number device
 Select a superblock
 btrfs rescue dump-super device
 Dump a superblock to disk
 btrfs rescue debug-tree [options] device
 Debug the filesystem

The only candidate into rescue section I currently see is 'zero-log'.

david
--
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


Re: [PATCH 6/6] Btrfs-progs: add the rescue section to btrfs

2013-02-08 Thread Goffredo Baroncelli
On 02/08/2013 01:37 AM, Ian Kumlien wrote:
 the btrfs command now lists:
 btrfs rescue select-super -s number device
 Select a superblock
 btrfs rescue dump-super device
 Dump a superblock to disk
 btrfs rescue debug-tree [options] device
 Debug the filesystem
 
 btrfs-dump-super.c was imported in to cmds-rescue-super-ops.c
 
 This patch integrates all the functionality...
 
 cmds-rescue.c is used to glue cmds-rescue-debug-tree.c,
 cmds-rescue-restore.c and cmds-rescue-super-ops.c together to
 make the source files more managable.
[...]
 -int main(int ac, char **av)
 +const char * const cmd_dump_super_usage[] = {
 + btrfs rescue dump-super device,
 + Dump a superblock to disk,
 + NULL
 +};
[...]
 +int cmd_dump_super(int argc, char **argv)
 +{
 +int i;
 +
 +if (argc != 2)
 +usage(cmd_dump_super_usage);
 +
 +for (i = 0; i  BTRFS_SUPER_MIRROR_MAX; i++) {
 +u64 bytenr = btrfs_sb_offset(i);
 +int fd;
 +struct btrfs_super_block sb;
 +int block_size = sizeof(struct btrfs_super_block);
 +char filename[1024];
 +int bytes_read = read_block(argv[optind], bytenr, sb);
 +if (bytes_read  block_size)
 +continue;
I think that we should also implement a check of the superblock checksum.

 +
 +sprintf(filename, /tmp/block.%s.%llu,
 +strrchr(argv[optind], '/') + 1, bytenr);
 +fd = open(filename, O_CREAT|O_WRONLY, 0644);

This is the part that I don't like. The output file name should be
passed via the command line. It should not be defined by some obscure
logic. The user is able to understand where the sb is written only after.

 +if (block_size != pwrite(fd, sb, block_size, 0)) {
 +fprintf(stderr, Failed to dump superblock %d, i);
 +continue;
 +}
 +fprintf(stderr, Dumped superblock %s:%d, gen %llu to %s.\n,
 +argv[optind], i, sb.generation, filename);
 +close(fd);
 +}
[...]

-- 
gpg @keyserver.linux.it: Goffredo Baroncelli (kreijackATinwind.it
Key fingerprint BBF5 1610 0B64 DAC6 5F7D  17B2 0EDA 9B37 8B82 E0B5
--
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


Re: [PATCH 6/6] Btrfs-progs: add the rescue section to btrfs

2013-02-08 Thread Ian Kumlien
On Fri, Feb 08, 2013 at 06:39:12PM +0100, Goffredo Baroncelli wrote:
 On 02/08/2013 01:37 AM, Ian Kumlien wrote:
  the btrfs command now lists:
  btrfs rescue select-super -s number device
  Select a superblock
  btrfs rescue dump-super device
  Dump a superblock to disk
  btrfs rescue debug-tree [options] device
  Debug the filesystem
  
  btrfs-dump-super.c was imported in to cmds-rescue-super-ops.c
  
  This patch integrates all the functionality...
  
  cmds-rescue.c is used to glue cmds-rescue-debug-tree.c,
  cmds-rescue-restore.c and cmds-rescue-super-ops.c together to
  make the source files more managable.
 [...]
  -int main(int ac, char **av)
  +const char * const cmd_dump_super_usage[] = {
  +   btrfs rescue dump-super device,
  +   Dump a superblock to disk,
  +   NULL
  +};
 [...]
  +int cmd_dump_super(int argc, char **argv)
  +{
  +int i;
  +
  +if (argc != 2)
  +usage(cmd_dump_super_usage);
  +
  +for (i = 0; i  BTRFS_SUPER_MIRROR_MAX; i++) {
  +u64 bytenr = btrfs_sb_offset(i);
  +int fd;
  +struct btrfs_super_block sb;
  +int block_size = sizeof(struct btrfs_super_block);
  +char filename[1024];
  +int bytes_read = read_block(argv[optind], bytenr, sb);
  +if (bytes_read  block_size)
  +continue;
 I think that we should also implement a check of the superblock checksum.
 
  +
  +sprintf(filename, /tmp/block.%s.%llu,
  +strrchr(argv[optind], '/') + 1, bytenr);
  +fd = open(filename, O_CREAT|O_WRONLY, 0644);
 
 This is the part that I don't like. The output file name should be
 passed via the command line. It should not be defined by some obscure
 logic. The user is able to understand where the sb is written only after.

This is only the import of the command, we can add anything we want
after that.

Josef also said that it could use some better usability - right now it's
only there since the functionality is good to have when something hits
the fan =)

  +if (block_size != pwrite(fd, sb, block_size, 0)) {
  +fprintf(stderr, Failed to dump superblock %d, i);
  +continue;
  +}
  +fprintf(stderr, Dumped superblock %s:%d, gen %llu to 
  %s.\n,
  +argv[optind], i, sb.generation, filename);
  +close(fd);
  +}
 [...]
 
 -- 
 gpg @keyserver.linux.it: Goffredo Baroncelli (kreijackATinwind.it
 Key fingerprint BBF5 1610 0B64 DAC6 5F7D  17B2 0EDA 9B37 8B82 E0B5
--
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


Re: [PATCH 6/6] Btrfs-progs: add the rescue section to btrfs

2013-02-08 Thread Ilya Dryomov
On Fri, Feb 08, 2013 at 01:37:02AM +0100, Ian Kumlien wrote:
 the btrfs command now lists:
 btrfs rescue select-super -s number device
 Select a superblock
 btrfs rescue dump-super device
 Dump a superblock to disk
 btrfs rescue debug-tree [options] device
 Debug the filesystem
 
 btrfs-dump-super.c was imported in to cmds-rescue-super-ops.c
 
 This patch integrates all the functionality...
 
 cmds-rescue.c is used to glue cmds-rescue-debug-tree.c,
 cmds-rescue-restore.c and cmds-rescue-super-ops.c together to
 make the source files more managable.

I think btrfs-debug-tree should go under debug -- btrfs debug dump-tree.
Same goes for btrfs-dump-super -- btrfs debug dump-super.  These
commands won't help an average user to rescue a single byte, they are
there to help developers.  I suppose you can also import btrfs-image
under btrfs debug dump-image.

This leaves the question of whether we want select-super under rescue.
Given that it can easily do more harm than good, it might not be the
best place for it..

Thanks,

Ilya
--
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


Re: [PATCH 6/6] Btrfs-progs: add the rescue section to btrfs

2013-02-08 Thread Hugo Mills
On Fri, Feb 08, 2013 at 09:57:17PM +0200, Ilya Dryomov wrote:
 On Fri, Feb 08, 2013 at 01:37:02AM +0100, Ian Kumlien wrote:
  the btrfs command now lists:
  btrfs rescue select-super -s number device
  Select a superblock
  btrfs rescue dump-super device
  Dump a superblock to disk
  btrfs rescue debug-tree [options] device
  Debug the filesystem
  
  btrfs-dump-super.c was imported in to cmds-rescue-super-ops.c
  
  This patch integrates all the functionality...
  
  cmds-rescue.c is used to glue cmds-rescue-debug-tree.c,
  cmds-rescue-restore.c and cmds-rescue-super-ops.c together to
  make the source files more managable.
 
 I think btrfs-debug-tree should go under debug -- btrfs debug dump-tree.
 Same goes for btrfs-dump-super -- btrfs debug dump-super.  These
 commands won't help an average user to rescue a single byte, they are
 there to help developers.  I suppose you can also import btrfs-image
 under btrfs debug dump-image.

   Can I put in a suggestion of using inspect-internal instead? Since
we've already got that one already? (But I'm not bothered about debug;
either is good).

   Hugo.

 This leaves the question of whether we want select-super under rescue.
 Given that it can easily do more harm than good, it might not be the
 best place for it..
 
 Thanks,
 
   Ilya

-- 
=== Hugo Mills: hugo@... carfax.org.uk | darksatanic.net | lug.org.uk ===
  PGP key: 515C238D from wwwkeys.eu.pgp.net or http://www.carfax.org.uk
   --- The early bird gets the worm,  but the second mouse ---   
gets the cheese. 


signature.asc
Description: Digital signature


Re: [PATCH 6/6] Btrfs-progs: add the rescue section to btrfs

2013-02-08 Thread David Sterba
On Fri, Feb 08, 2013 at 01:37:02AM +0100, Ian Kumlien wrote:
 the btrfs command now lists:
 btrfs rescue select-super -s number device
 Select a superblock
 btrfs rescue dump-super device
 Dump a superblock to disk
 btrfs rescue debug-tree [options] device
 Debug the filesystem

Let me summarize here the comments I've read so far and what we disussed
with Ilya on irc:

* btrfs check -- seems to be accepted
* btrfs restore -- seems to be accepted

* btrfs rescue
  * select-super -- it is a command that can make
things bad and should be used with caution, thus not very suitable
to put under 'rescue' command, let's keep it as a standalone utitly
for now

  * show-super +
  * dump-super -- they do basically the same thing, the output is
different, Ilya suggests to keep only 'dump-super' with 2 output
modes, and I agree with him

  * debug-tree -- suggested name is 'dump-tree'

Then, the namespace 'rescue' does not fit the purpose, these are
debugging commands, so the proposed name is 'debug'.

They do not seem to fit into 'inspect-internal' which is supposed to
work on a mounted filesystem, and  I think this should contain commands
for infrequent but useful things.

Let's focus on the above commands for start, we can add more later (eg.
the repair subcommand).


thanks,
david
--
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 6/6] Btrfs-progs: add the rescue section to btrfs

2013-02-07 Thread Ian Kumlien
the btrfs command now lists:
btrfs rescue select-super -s number device
Select a superblock
btrfs rescue dump-super device
Dump a superblock to disk
btrfs rescue debug-tree [options] device
Debug the filesystem

btrfs-dump-super.c was imported in to cmds-rescue-super-ops.c

This patch integrates all the functionality...

cmds-rescue.c is used to glue cmds-rescue-debug-tree.c,
cmds-rescue-restore.c and cmds-rescue-super-ops.c together to
make the source files more managable.

Signed-off-by: Ian Kumlien po...@demius.net
---
 Makefile |  34 +---
 btrfs-dump-super.c   |  87 ---
 btrfs.c  |   2 +
 cmds-rescue-debug-tree.c |  44 ++--
 cmds-rescue-super-ops.c  | 103 +--
 cmds-rescue.c|  48 ++
 cmds-restore.c   |  42 +++
 commands.h   |   8 +++-
 8 files changed, 195 insertions(+), 173 deletions(-)
 delete mode 100644 btrfs-dump-super.c
 create mode 100644 cmds-rescue.c

diff --git a/Makefile b/Makefile
index 94541b2..7e2db76 100644
--- a/Makefile
+++ b/Makefile
@@ -8,7 +8,9 @@ objects = ctree.o disk-io.o radix-tree.o extent-tree.o 
print-tree.o \
  send-stream.o send-utils.o qgroup.o raid6.o
 cmds_objects = cmds-subvolume.o cmds-filesystem.o cmds-device.o cmds-scrub.o \
   cmds-inspect.o cmds-balance.o cmds-send.o cmds-receive.o \
-  cmds-quota.o cmds-qgroup.o cmds-replace.o cmds-check.o
+  cmds-quota.o cmds-qgroup.o cmds-replace.o cmds-check.o \
+  cmds-rescue.o cmds-rescue-super-ops.o \
+  cmds-rescue-debug-tree.o cmds-restore.o
 
 CHECKFLAGS= -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ -Wbitwise \
-Wuninitialized -Wshadow -Wundef
@@ -17,8 +19,7 @@ DEPFLAGS = -Wp,-MMD,$(@D)/.$(@F).d,-MT,$@
 INSTALL = install
 prefix ?= /usr/local
 bindir = $(prefix)/bin
-LIBS=-luuid -lm
-RESTORE_LIBS=-lz -llzo2
+LIBS=-luuid -lm -lz -llzo2
 
 ifeq ($(origin V), command line)
   BUILD_VERBOSE = $(V)
@@ -35,10 +36,9 @@ endif
 
 MAKEOPTS = --no-print-directory Q=$(Q)
 
-progs = btrfsctl mkfs.btrfs btrfs-debug-tree btrfs-show btrfs-vol \
-   btrfs btrfs-map-logical btrfs-image btrfs-zero-log btrfs-convert \
-   btrfs-find-root btrfs-restore btrfstune btrfs-show-super \
-   btrfs-dump-super
+progs = btrfsctl mkfs.btrfs btrfs-show btrfs-vol btrfs \
+   btrfs-map-logical btrfs-image btrfs-zero-log btrfs-convert \
+   btrfs-find-root btrfstune \
 
 # Create all the static targets
 static_objects = $(patsubst %.o, %.static.o, $(objects))
@@ -95,10 +95,6 @@ btrfs-find-root: $(objects) find-root.o
@echo [LD] $@
$(Q)$(CC) $(CFLAGS) -o btrfs-find-root find-root.o $(objects) 
$(LDFLAGS) $(LIBS)
 
-btrfs-restore: $(objects) restore.o
-   @echo [LD] $@
-   $(Q)$(CC) $(CFLAGS) -o btrfs-restore restore.o $(objects) $(LDFLAGS) 
$(LIBS) $(RESTORE_LIBS)
-
 btrfsctl: $(objects) btrfsctl.o
@echo [LD] $@
$(Q)$(CC) $(CFLAGS) -o btrfsctl btrfsctl.o $(objects) $(LDFLAGS) $(LIBS)
@@ -115,10 +111,6 @@ mkfs.btrfs: $(objects) mkfs.o
@echo [LD] $@
$(Q)$(CC) $(CFLAGS) -o mkfs.btrfs $(objects) mkfs.o $(LDFLAGS) $(LIBS) 
-lblkid
 
-btrfs-debug-tree: $(objects) debug-tree.o
-   @echo [LD] $@
-   $(Q)$(CC) $(CFLAGS) -o btrfs-debug-tree $(objects) debug-tree.o 
$(LDFLAGS) $(LIBS)
-
 btrfs-zero-log: $(objects) btrfs-zero-log.o
@echo [LD] $@
$(Q)$(CC) $(CFLAGS) -o btrfs-zero-log $(objects) btrfs-zero-log.o 
$(LDFLAGS) $(LIBS)
@@ -127,14 +119,6 @@ btrfs-show-super: $(objects) btrfs-show-super.o
@echo [LD] $@
$(Q)$(CC) $(CFLAGS) -o btrfs-show-super $(objects) btrfs-show-super.o 
$(LDFLAGS) $(LIBS)
 
-btrfs-select-super: $(objects) btrfs-select-super.o
-   @echo [LD] $@
-   $(Q)$(CC) $(CFLAGS) -o btrfs-select-super $(objects) 
btrfs-select-super.o $(LDFLAGS) $(LIBS)
-
-btrfs-dump-super: $(objects) btrfs-dump-super.o
-   @echo [LD] $@
-   $(Q)$(CC) $(CFLAGS) -o btrfs-dump-super $(objects) btrfs-dump-super.o 
$(LDFLAGS) $(LIBS)
-
 btrfstune: $(objects) btrfstune.o
@echo [LD] $@
$(Q)$(CC) $(CFLAGS) -o btrfstune $(objects) btrfstune.o $(LDFLAGS) 
$(LIBS)
@@ -175,8 +159,8 @@ install-man:
 
 clean :
@echo Cleaning
-   $(Q)rm -f $(progs) cscope.out *.o .*.d btrfs-convert btrfs-image 
btrfs-select-super \
- btrfs-zero-log btrfstune btrfs-dump-super dir-test ioctl-test 
quick-test \
+   $(Q)rm -f $(progs) cscope.out *.o .*.d btrfs-convert btrfs-image \
+ btrfs-zero-log btrfstune dir-test ioctl-test quick-test \
  version.h
$(Q)$(MAKE) $(MAKEOPTS) -C man $@
 
diff --git a/btrfs-dump-super.c b/btrfs-dump-super.c
deleted file mode 100644
index 033140c..000
---