Re: New btrfs sub command: btrfs inspect physical-find

2016-07-15 Thread Goffredo Baroncelli
On 2016-07-14 23:45, Chris Mason wrote:
> 
> 
> On 07/12/2016 05:40 PM, Goffredo Baroncelli wrote:
>> Hi All,
>> 
>> the enclosed patch adds a new btrfs sub command: "btrfs inspect
>> physical-find". The aim of this new command is to show the physical
>> placement on the disk of a file. Currently it handles all the
>> profiles (single, dup, raid1/10/5/6). I develop this command in
>> order to show some bug in btrfs RAID5 profile (see next email).
> 
> I've done this manually from time to time, and love the idea of
> having a helper for it.  Can I talk you into adding a way to save the
> contents of the block without having to use dd?  btrfs-map-logical
> does this now, but not via the search ioctl and not by filename.
> 
> say:
> 
> btrfs inspect physical-find -c  -o   
> offset

I prefer to add another command to do that (like btrfs insp physical-dump). And 
I will add as constraint like 
offset % blocksize == 0
this in order to avoid handling data spread different stripes/chunks.

However  has different meaning:

single/raid0 -> means nothing
raid1/raid10 -> means the copy #
raid5/raid6  -> could mean the parity: i.e.
-1 -> first parity (raid5/raid6)
-2 -> 2nd parity (raid6 only)
 
> Looks like you've open coded btrfs_map_logical() below, getting
> output from the search ioctl.  Dave might want that in a more
> centralized place.

I will give a look 

 
> Also, please turn:
> 
> for(;;) if (foo) { statements }
> 
> Into
> 
> for(;;) { if (foo) { statements } }
> 
> I find that much less error prone.

Ok

> 
> -chris
> 
BR
G.Baroncelli

-- 
gpg @keyserver.linux.it: Goffredo Baroncelli 
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: New btrfs sub command: btrfs inspect physical-find

2016-07-14 Thread Liu Bo
On Thu, Jul 14, 2016 at 04:05:00PM -0700, Liu Bo wrote:
> On Tue, Jul 12, 2016 at 11:40:13PM +0200, Goffredo Baroncelli wrote:
> > Hi All,
> > 
> > the enclosed patch adds a new btrfs sub command: "btrfs inspect 
> > physical-find". The aim of this new command is to show the physical 
> > placement on the disk of a file. Currently it handles all the profiles 
> > (single, dup, raid1/10/5/6). 
> > I develop this command in order to show some bug in btrfs RAID5 profile 
> > (see next email).
> > 
> > You can pull the code from:
> > 
> > https://github.com/kreijack/btrfs-progs.git
> > 
> > branch
> > 
> > insp-phy
> 
> The tool looks similar to the existing 'btrfs-map-logical', yes,
> btrfs-map-logical has some problems on raid56, and a quick glance shows
> that it's due to that btrfs_num_copies() can only return 2 copies for
> raid5 and 3 copies for raid6.

I was wrong about btrfs_num_copies(), for raid56 it returns certain
value to control which stripe __btrfs_map_block() needs to be return.
Thus, btrfs-map-logical doesn't work for raid56 since everytime it will
return the required-offset data stripe and the parity stripe.

Thanks,

-liubo

> 
> Thanks,
> 
> -liubo
> 
> > 
> > The syntax of this new command is simple:
> > 
> > # btrfs inspect physical-find  []
> > 
> > where:
> >is the file to inspect
> >is the offset of the file to inspect (default 0)
> > 
> > Below some examples:
> > 
> > ** Single
> > 
> > $ sudo mkfs.btrfs -f -d single -m single /dev/loop0
> > $ sudo mount /dev/loop0 mnt/
> > $ python -c "print 'ad'+'a'*65534+'bd'+'b'*65533" | sudo tee mnt/out.txt 
> > >/dev/null
> > $ sudo ../btrfs-progs/btrfs inspect physical-find mnt/out.txt
> > mnt/out.txt: 0
> > devid 1, /dev/loop0 : 12582912 LINEAR
> > $ dd 2>/dev/null if=/dev/loop0 skip=12582912 bs=1 count=5; echo
> > adaaa
> > 
> > ** Dup
> > 
> > The command shows both the copies
> > 
> > $ sudo mkfs.btrfs -f -d single -m single /dev/loop0
> > $ sudo mount /dev/loop0 mnt/
> > $ python -c "print 'ad'+'a'*65534+'bd'+'b'*65533" | sudo tee mnt/out.txt 
> > >/dev/null
> > $ sudo ../btrfs-progs/btrfs inspect physical-find mnt/out.txt
> > $ sudo ../btrfs-progs/btrfs inspect physical-find mnt/out.txt
> > mnt/out.txt: 0
> > devid 1, /dev/loop0 : 71303168 DUP
> > devid 1, /dev/loop0 : 104857600 DUP
> > $ dd 2>/dev/null if=/dev/loop0 skip=104857600 bs=1 count=5 ; echo
> > adaaa
> > 
> > 
> > ** Raid1
> > 
> > The command shows both the copies
> > 
> > $ sudo mkfs.btrfs -f -d raid1 -m raid1 /dev/loop0 /dev/loop1
> > $ sudo mount /dev/loop0 mnt/
> > $ python -c "print 'ad'+'a'*65534+'bd'+'b'*65533" | sudo tee mnt/out.txt 
> > >/dev/null
> > $ sudo ../btrfs-progs/btrfs inspect physical-find mnt/out.txt mnt/out.txt: 0
> > devid 2, /dev/loop1 : 61865984 RAID1
> > devid 1, /dev/loop0 : 81788928 RAID1
> > $ dd 2>/dev/null if=/dev/loop0 skip=81788928 bs=1 count=5; echo
> > adaaa
> > 
> > 
> > ** Raid10
> > 
> > The command show both the copies; if you set an offset to the next 
> > disk-stripe, you can see the next pair of disk-stripe
> > 
> > $ sudo mkfs.btrfs -f -d raid10 -m raid10 /dev/loop[0123]
> > $ sudo mount /dev/loop0 mnt/
> > $ python -c "print 'ad'+'a'*65534+'bd'+'b'*65533" | sudo tee mnt/out.txt 
> > >/dev/null
> > $ sudo ../btrfs-progs/btrfs inspect physical-find mnt/out.txt mnt/out.txt: 0
> > devid 4, /dev/loop3 : 61931520 RAID10
> > devid 3, /dev/loop2 : 61931520 RAID10
> > $ dd 2>/dev/null if=/dev/loop2 skip=61931520 bs=1 count=5; echo
> > adaaa
> > $ sudo ../btrfs-progs/btrfs inspect physical-find mnt/out.txt 65536
> > mnt/out.txt: 65536
> > devid 2, /dev/loop1 : 61931520 RAID10
> > devid 1, /dev/loop0 : 81854464 RAID10
> > $ dd 2>/dev/null if=/dev/loop0 skip=81854464 bs=1 count=5; echo
> > bdbbb
> > 
> > 
> > ** Raid5
> > 
> > Depending by the offset, you can see which disk-stripe is used.
> > 
> > $ sudo mkfs.btrfs -f -d raid5 -m raid5 /dev/loop[012]
> > $ sudo mount /dev/loop0 mnt/
> > $ python -c "print 'ad'+'a'*65534+'bd'+'b'*65533" | sudo tee mnt/out.txt 
> > >/dev/null
> > $ sudo ../btrfs-progs/btrfs inspect physical-find mnt/out.txt
> > mnt/out.txt: 0
> > devid 2, /dev/loop1 : 61931520 DATA
> > d

Re: New btrfs sub command: btrfs inspect physical-find

2016-07-14 Thread Liu Bo
On Tue, Jul 12, 2016 at 11:40:13PM +0200, Goffredo Baroncelli wrote:
> Hi All,
> 
> the enclosed patch adds a new btrfs sub command: "btrfs inspect 
> physical-find". The aim of this new command is to show the physical placement 
> on the disk of a file. Currently it handles all the profiles (single, dup, 
> raid1/10/5/6). 
> I develop this command in order to show some bug in btrfs RAID5 profile (see 
> next email).
> 
> You can pull the code from:
> 
>   https://github.com/kreijack/btrfs-progs.git
> 
> branch
> 
>   insp-phy

The tool looks similar to the existing 'btrfs-map-logical', yes,
btrfs-map-logical has some problems on raid56, and a quick glance shows
that it's due to that btrfs_num_copies() can only return 2 copies for
raid5 and 3 copies for raid6.

Thanks,

-liubo

> 
> The syntax of this new command is simple:
> 
> # btrfs inspect physical-find  []
> 
> where:
>is the file to inspect
>is the offset of the file to inspect (default 0)
> 
> Below some examples:
> 
> ** Single
> 
> $ sudo mkfs.btrfs -f -d single -m single /dev/loop0
> $ sudo mount /dev/loop0 mnt/
> $ python -c "print 'ad'+'a'*65534+'bd'+'b'*65533" | sudo tee mnt/out.txt 
> >/dev/null
> $ sudo ../btrfs-progs/btrfs inspect physical-find mnt/out.txt
> mnt/out.txt: 0
> devid 1, /dev/loop0 : 12582912 LINEAR
> $ dd 2>/dev/null if=/dev/loop0 skip=12582912 bs=1 count=5; echo
> adaaa
> 
> ** Dup
> 
> The command shows both the copies
> 
> $ sudo mkfs.btrfs -f -d single -m single /dev/loop0
> $ sudo mount /dev/loop0 mnt/
> $ python -c "print 'ad'+'a'*65534+'bd'+'b'*65533" | sudo tee mnt/out.txt 
> >/dev/null
> $ sudo ../btrfs-progs/btrfs inspect physical-find mnt/out.txt
> $ sudo ../btrfs-progs/btrfs inspect physical-find mnt/out.txt
> mnt/out.txt: 0
> devid 1, /dev/loop0 : 71303168 DUP
> devid 1, /dev/loop0 : 104857600 DUP
> $ dd 2>/dev/null if=/dev/loop0 skip=104857600 bs=1 count=5 ; echo
> adaaa
> 
> 
> ** Raid1
> 
> The command shows both the copies
> 
> $ sudo mkfs.btrfs -f -d raid1 -m raid1 /dev/loop0 /dev/loop1
> $ sudo mount /dev/loop0 mnt/
> $ python -c "print 'ad'+'a'*65534+'bd'+'b'*65533" | sudo tee mnt/out.txt 
> >/dev/null
> $ sudo ../btrfs-progs/btrfs inspect physical-find mnt/out.txt mnt/out.txt: 0
> devid 2, /dev/loop1 : 61865984 RAID1
> devid 1, /dev/loop0 : 81788928 RAID1
> $ dd 2>/dev/null if=/dev/loop0 skip=81788928 bs=1 count=5; echo
> adaaa
> 
> 
> ** Raid10
> 
> The command show both the copies; if you set an offset to the next 
> disk-stripe, you can see the next pair of disk-stripe
> 
> $ sudo mkfs.btrfs -f -d raid10 -m raid10 /dev/loop[0123]
> $ sudo mount /dev/loop0 mnt/
> $ python -c "print 'ad'+'a'*65534+'bd'+'b'*65533" | sudo tee mnt/out.txt 
> >/dev/null
> $ sudo ../btrfs-progs/btrfs inspect physical-find mnt/out.txt mnt/out.txt: 0
> devid 4, /dev/loop3 : 61931520 RAID10
> devid 3, /dev/loop2 : 61931520 RAID10
> $ dd 2>/dev/null if=/dev/loop2 skip=61931520 bs=1 count=5; echo
> adaaa
> $ sudo ../btrfs-progs/btrfs inspect physical-find mnt/out.txt 65536
> mnt/out.txt: 65536
> devid 2, /dev/loop1 : 61931520 RAID10
> devid 1, /dev/loop0 : 81854464 RAID10
> $ dd 2>/dev/null if=/dev/loop0 skip=81854464 bs=1 count=5; echo
> bdbbb
> 
> 
> ** Raid5
> 
> Depending by the offset, you can see which disk-stripe is used.
> 
> $ sudo mkfs.btrfs -f -d raid5 -m raid5 /dev/loop[012]
> $ sudo mount /dev/loop0 mnt/
> $ python -c "print 'ad'+'a'*65534+'bd'+'b'*65533" | sudo tee mnt/out.txt 
> >/dev/null
> $ sudo ../btrfs-progs/btrfs inspect physical-find mnt/out.txt
> mnt/out.txt: 0
> devid 2, /dev/loop1 : 61931520 DATA
> devid 1, /dev/loop0 : 81854464 OTHER
> devid 3, /dev/loop2 : 61931520 PARITY
> $ sudo ../btrfs-progs/btrfs inspect physical-find mnt/out.txt 
> 65536mnt/out.txt: 65536
> devid 2, /dev/loop1 : 61931520 OTHER
> devid 1, /dev/loop0 : 81854464 DATA
> devid 3, /dev/loop2 : 61931520 PARITY
> $ dd 2>/dev/null if=/dev/loop1 skip=61931520 bs=1 count=5; echo
> adaaa
> $ dd 2>/dev/null if=/dev/loop0 skip=81854464 bs=1 count=5; echo
> bdbbb
> $ dd 2>/dev/null if=/dev/loop2 skip=61931520 bs=1 count=5 | xxd
> : 0300 0303 03 .
> 
> The parity is computed as: parity=disk1^disk2. So "adaa" ^ "bdbb" == 
> "\x03\x00\x03\x03
> 
> ** Raid6
> $ sudo mkfs.btrfs -f -mraid6 -draid6 /dev/loop[0-4]^C
> $ sudo mount /dev/loop0 mnt/
> $ python -c "print 'ad'+'a'*65534

Re: New btrfs sub command: btrfs inspect physical-find

2016-07-14 Thread Chris Mason



On 07/12/2016 05:40 PM, Goffredo Baroncelli wrote:

Hi All,

the enclosed patch adds a new btrfs sub command: "btrfs inspect physical-find". 
The aim of this new command is to show the physical placement on the disk of a file. 
Currently it handles all the profiles (single, dup, raid1/10/5/6).
I develop this command in order to show some bug in btrfs RAID5 profile (see 
next email).


I've done this manually from time to time, and love the idea of having a 
helper for it.  Can I talk you into adding a way to save the contents of 
the block without having to use dd?  btrfs-map-logical does this now, 
but not via the search ioctl and not by filename.


say:

btrfs inspect physical-find -c  -o   
offset


Looks like you've open coded btrfs_map_logical() below, getting output 
from the search ioctl.  Dave might want that in a more centralized place.


Also, please turn:

for(;;)
if (foo) {
statements
}

Into

for(;;) {
if (foo) {
statements
}
}

I find that much less error prone.

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


New btrfs sub command: btrfs inspect physical-find

2016-07-12 Thread Goffredo Baroncelli
Hi All,

the enclosed patch adds a new btrfs sub command: "btrfs inspect physical-find". 
The aim of this new command is to show the physical placement on the disk of a 
file. Currently it handles all the profiles (single, dup, raid1/10/5/6). 
I develop this command in order to show some bug in btrfs RAID5 profile (see 
next email).

You can pull the code from:

https://github.com/kreijack/btrfs-progs.git

branch

insp-phy

The syntax of this new command is simple:

# btrfs inspect physical-find  []

where:
   is the file to inspect
   is the offset of the file to inspect (default 0)

Below some examples:

** Single

$ sudo mkfs.btrfs -f -d single -m single /dev/loop0
$ sudo mount /dev/loop0 mnt/
$ python -c "print 'ad'+'a'*65534+'bd'+'b'*65533" | sudo tee mnt/out.txt 
>/dev/null
$ sudo ../btrfs-progs/btrfs inspect physical-find mnt/out.txt
mnt/out.txt: 0
devid 1, /dev/loop0 : 12582912 LINEAR
$ dd 2>/dev/null if=/dev/loop0 skip=12582912 bs=1 count=5; echo
adaaa

** Dup

The command shows both the copies

$ sudo mkfs.btrfs -f -d single -m single /dev/loop0
$ sudo mount /dev/loop0 mnt/
$ python -c "print 'ad'+'a'*65534+'bd'+'b'*65533" | sudo tee mnt/out.txt 
>/dev/null
$ sudo ../btrfs-progs/btrfs inspect physical-find mnt/out.txt
$ sudo ../btrfs-progs/btrfs inspect physical-find mnt/out.txt
mnt/out.txt: 0
devid 1, /dev/loop0 : 71303168 DUP
devid 1, /dev/loop0 : 104857600 DUP
$ dd 2>/dev/null if=/dev/loop0 skip=104857600 bs=1 count=5 ; echo
adaaa


** Raid1

The command shows both the copies

$ sudo mkfs.btrfs -f -d raid1 -m raid1 /dev/loop0 /dev/loop1
$ sudo mount /dev/loop0 mnt/
$ python -c "print 'ad'+'a'*65534+'bd'+'b'*65533" | sudo tee mnt/out.txt 
>/dev/null
$ sudo ../btrfs-progs/btrfs inspect physical-find mnt/out.txt mnt/out.txt: 0
devid 2, /dev/loop1 : 61865984 RAID1
devid 1, /dev/loop0 : 81788928 RAID1
$ dd 2>/dev/null if=/dev/loop0 skip=81788928 bs=1 count=5; echo
adaaa


** Raid10

The command show both the copies; if you set an offset to the next disk-stripe, 
you can see the next pair of disk-stripe

$ sudo mkfs.btrfs -f -d raid10 -m raid10 /dev/loop[0123]
$ sudo mount /dev/loop0 mnt/
$ python -c "print 'ad'+'a'*65534+'bd'+'b'*65533" | sudo tee mnt/out.txt 
>/dev/null
$ sudo ../btrfs-progs/btrfs inspect physical-find mnt/out.txt mnt/out.txt: 0
devid 4, /dev/loop3 : 61931520 RAID10
devid 3, /dev/loop2 : 61931520 RAID10
$ dd 2>/dev/null if=/dev/loop2 skip=61931520 bs=1 count=5; echo
adaaa
$ sudo ../btrfs-progs/btrfs inspect physical-find mnt/out.txt 65536
mnt/out.txt: 65536
devid 2, /dev/loop1 : 61931520 RAID10
devid 1, /dev/loop0 : 81854464 RAID10
$ dd 2>/dev/null if=/dev/loop0 skip=81854464 bs=1 count=5; echo
bdbbb


** Raid5

Depending by the offset, you can see which disk-stripe is used.

$ sudo mkfs.btrfs -f -d raid5 -m raid5 /dev/loop[012]
$ sudo mount /dev/loop0 mnt/
$ python -c "print 'ad'+'a'*65534+'bd'+'b'*65533" | sudo tee mnt/out.txt 
>/dev/null
$ sudo ../btrfs-progs/btrfs inspect physical-find mnt/out.txt
mnt/out.txt: 0
devid 2, /dev/loop1 : 61931520 DATA
devid 1, /dev/loop0 : 81854464 OTHER
devid 3, /dev/loop2 : 61931520 PARITY
$ sudo ../btrfs-progs/btrfs inspect physical-find mnt/out.txt 65536mnt/out.txt: 
65536
devid 2, /dev/loop1 : 61931520 OTHER
devid 1, /dev/loop0 : 81854464 DATA
devid 3, /dev/loop2 : 61931520 PARITY
$ dd 2>/dev/null if=/dev/loop1 skip=61931520 bs=1 count=5; echo
adaaa
$ dd 2>/dev/null if=/dev/loop0 skip=81854464 bs=1 count=5; echo
bdbbb
$ dd 2>/dev/null if=/dev/loop2 skip=61931520 bs=1 count=5 | xxd
: 0300 0303 03 .

The parity is computed as: parity=disk1^disk2. So "adaa" ^ "bdbb" == 
"\x03\x00\x03\x03

** Raid6
$ sudo mkfs.btrfs -f -mraid6 -draid6 /dev/loop[0-4]^C
$ sudo mount /dev/loop0 mnt/
$ python -c "print 'ad'+'a'*65534+'bd'+'b'*65533" | sudo tee mnt/out.txt 
>/dev/null
$ sudo ../btrfs-progs/btrfs inspect physical-find mnt/out.txt
mnt/out.txt: 0
devid 3, /dev/loop2 : 61931520 DATA
devid 2, /dev/loop1 : 61931520 OTHER
devid 1, /dev/loop0 : 81854464 PARITY
devid 4, /dev/loop3 : 61931520 PARITY

$ dd 2>/dev/null if=/dev/loop2 skip=61931520 bs=1 count=5 ; echo
adaaa

--

diff --git a/cmds-inspect.c b/cmds-inspect.c
index dd7b9dd..a604c2b 100644
--- a/cmds-inspect.c
+++ b/cmds-inspect.c
@@ -22,6 +22,11 @@
 #include 
 #include 
 #include 
+#include 
+#include 
+#include 
+#include 
+#include 
 
 #include "kerncompat.h"
 #include "ioctl.h"
@@ -623,6 +628,450 @@ out:
return !!ret;
 }
 
+
+static const char* const cmd_inspect_physical_find_usage[] = {
+   "btrfs inspect-internal physical-find [options]  [...]",
+   "Show the physical address of each blocks"