[PATCH v2] btrfs-progs: misc-tests: Superblock corruption and recovery using backup.

2017-02-15 Thread Lakshmipathi.G
Signed-off-by: Lakshmipathi.G <lakshmipath...@giis.co.in>
---
 .../019-fix-superblock-corruption/test.sh  | 38 ++
 1 file changed, 38 insertions(+)
 create mode 100755 tests/misc-tests/019-fix-superblock-corruption/test.sh

diff --git a/tests/misc-tests/019-fix-superblock-corruption/test.sh 
b/tests/misc-tests/019-fix-superblock-corruption/test.sh
new file mode 100755
index 000..55159dc
--- /dev/null
+++ b/tests/misc-tests/019-fix-superblock-corruption/test.sh
@@ -0,0 +1,38 @@
+#!/bin/bash
+#
+# Corrupt primary superblock and restore it using backup superblock.
+#
+
+source $TOP/tests/common
+
+check_prereq btrfs-select-super
+check_prereq btrfs
+
+setup_root_helper
+prepare_test_dev 512M
+
+FIRST_SUPERBLOCK_OFFSET=65536
+
+test_superblock_restore()
+{
+   run_check $SUDO_HELPER $TOP/mkfs.btrfs -f $TEST_DEV
+
+   # Corrupt superblock checksum
+dd if=/dev/zero of=$TEST_DEV seek=$FIRST_SUPERBLOCK_OFFSET bs=1 \
+count=4  conv=notrunc &> /dev/null
+   
+   # Run btrfs check to detect corruption
+   $TOP/btrfs check $TEST_DEV >& /dev/null && \
+   _fail "btrfs check should detect corruption"
+
+   # Copy backup superblock to primary
+   run_check $TOP/btrfs-select-super -s 1 $TEST_DEV
+   
+   echo "Performing btrfs check" &>> $RESULTS
+   $TOP/btrfs check $TEST_DEV &>> $RESULTS
+if [ $? -ne 0 ]; then
+   _fail "Failed to fix superblock."
+fi 
+}
+
+test_superblock_restore
-- 
2.7.4

--
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] btrfs-progs: misc-tests: Primary Superblock corruption and recovery using backup Superblock.

2017-02-15 Thread Lakshmipathi.G
On Wed, Feb 15, 2017 at 09:36:03AM +0800, Qu Wenruo wrote:
> 
> 
> >+# Corrupt superblock checksum
> >+dd if=/dev/zero of=$TEST_DEV seek=$superblock_offset bs=1 \
> >+count=4  conv=notrunc &> /dev/null
> >+run_check_stdout $SUDO_HELPER mount $TEST_DEV $TEST_MNT | \
> >+grep -q 'wrong fs type'
> 
> What about using btrfs check instead of trying to mount it?
> 
> This could emit the need to use $SUDO_HELPER, and could catch super error
> more accurate.
> 
> >+if [ $? -ne 0 ]; then
> >+_fail "Failed to corrupt superblock."
> >+fi
> >+
> >+# Copy backup superblock to primary
> >+run_check $TOP/btrfs-select-super -s 1 $TEST_DEV
> >+run_check $SUDO_HELPER mount $TEST_DEV $TEST_MNT
> Same here.
I started with 'btrfs check' and 'btrfs check --repair' but it seems like
--repair don't fix the corruption. So just moved away from using it.

After you mentioned, now I see 'btrfs check' will be helpful. Will make
these changes. 

Cheers.
Lakshmipathi.G
--
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] btrfs-progs: RAID5:Inject data stripe corruption and verify scrub fixes it.

2017-02-15 Thread Lakshmipathi.G
Signed-off-by: Lakshmipathi.G <lakshmipath...@giis.co.in>
---
 .../020-raid5-datastripe-corruption/test.sh| 224 +
 1 file changed, 224 insertions(+)
 create mode 100755 tests/misc-tests/020-raid5-datastripe-corruption/test.sh

diff --git a/tests/misc-tests/020-raid5-datastripe-corruption/test.sh 
b/tests/misc-tests/020-raid5-datastripe-corruption/test.sh
new file mode 100755
index 000..d04c430
--- /dev/null
+++ b/tests/misc-tests/020-raid5-datastripe-corruption/test.sh
@@ -0,0 +1,224 @@
+#!/bin/bash
+#
+# Raid5: Inject data stripe corruption and fix them using scrub.
+# 
+# Script will perform the following:
+# 1) Create Raid5 using 3 loopback devices.
+# 2) Ensure file layout is created in a predictable manner. 
+#Each data stripe(64KB) should uniquely start with 'DN',   
+#where N represents the data stripe number.(ex:D0,D1 etc)
+# 3) Once file is created with specific layout, gather data stripe details 
+#like devicename, position and actual on-disk data.
+# 4) Now use 'dd' to verify the data-stripe against its expected value
+#and inject corruption by zero'ing out contents.
+# 5) After injecting corruption, running online-scrub is expected to fix 
+#the corrupted data stripe with the help of parity block and 
+#corresponding data stripe.
+# 6) Finally, validate the data stripe has original un-corrupted value.
+#
+#  Note: This script doesn't handle parity block corruption.
+
+source $TOP/tests/common
+
+check_prereq btrfs
+check_prereq mkfs.btrfs
+
+setup_root_helper
+prepare_test_dev 512M
+
+ndevs=3
+declare -a devs
+device_name=""
+stripe_offset=""
+stripe_content=""
+
+LAYOUT_TMP=$(mktemp --tmpdir btrfs-progs-raid5-file.layoutXX)
+STRIPEINFO_TMP=$(mktemp --tmpdir btrfs-progs-raid5-file.infoXX)
+
+prepare_devices()
+{
+   for i in `seq $ndevs`; do
+   touch img$i
+   chmod a+rw img$i
+   truncate -s0 img$i
+   truncate -s512M img$i
+   devs[$i]=`run_check_stdout $SUDO_HELPER losetup --find --show 
img$i`
+   done
+}
+
+cleanup_devices()
+{
+   for dev in ${devs[@]}; do
+   run_check $SUDO_HELPER losetup -d $dev
+   done
+   for i in `seq $ndevs`; do
+   truncate -s0 img$i
+   done
+   run_check $SUDO_HELPER losetup --all
+}
+
+test_do_mkfs()
+{
+   run_check $SUDO_HELPER $TOP/mkfs.btrfs -f   \
+   $@
+}
+
+test_mkfs_multi()
+{
+   test_do_mkfs $@ ${devs[@]}
+}
+
+#$1 Filename
+#$2 Expected no.of data stripes for the file.
+create_layout(){
+   fname=$1
+   size=$(( $2 * 65536 ))
+   n=0
+   bs_value=1
+   stripe=0
+   while (( $n < $size ))
+   do
+   if [ $(( $n % 65536 )) -eq 0 ]; then
+   val='D'$stripe
+   echo -n $val
+   stripe=$(( $stripe+1 ))
+   # ensure proper value   
+   bs_value=`echo "${#val}"` 
+   else
+   echo -n 'x'
+   bs_value=1
+   fi
+n=$(( $n+$bs_value ))
+   done | dd of="$TEST_MNT"/$fname bs=$bs_value conv=notrunc &> /dev/null
+}
+
+find_data_stripe_details(){
+   for dev in ${devs[@]}; do
+   echo $dev >> $LAYOUT_TMP
+   $SUDO_HELPER cat $dev | hexdump -e '"%010_ad|" 16/1 "%_p" 
"|\n"' |
+   grep -P 'D[0-9]+xx'  >> $LAYOUT_TMP
+   done
+}
+
+#Collect data stripe information in a readable manner.
+save_data_stripe_details(){
+   devname=""
+   for entry in `cat $LAYOUT_TMP`; do  
+   echo $entry | grep -q '^\/dev\/loop' > /dev/null
+
+   if [ $? -eq 0 ]; then
+   devname=$entry  
+   else
+   echo $devname"|"$entry >> $STRIPEINFO_TMP
+   fi
+   done
+   #Order by data stripe. D0 comes before D1.
+   sort -t'|'  -k3 $STRIPEINFO_TMP -o $STRIPEINFO_TMP
+}
+
+#Corrupt given data stripe
+corrupt_data_stripe(){
+
+   data_stripe_num=$1
+   data_stripe_entry="D"${data_stripe_num}""
+   stripe_entry=`grep "${data_stripe_entry}" $STRIPEINFO_TMP`
+
+   #Each entry will have format like "device|position|16-byte content"
+   #Example: /dev/loop1|0063176704|D0xx|
+   device_name=$(echo $stripe_entry | awk -F"|" '{print $1}')
+   stripe_offset=$(echo $stripe_entry | awk -F"|" '{print $2}')
+   #Remove leading zeros
+   stripe_offset=$(echo $stripe_offset | sed 's/^0*//')
+   stripe_content=$(echo $stripe_entry | awk -F"|" '{print $3}')
+
+   echo "Corrupting $device_name at position $stripe_offset \
+   which has $stripe_content" >&g

[PATCH] btrfs-progs: misc-tests: Primary Superblock corruption and recovery using backup Superblock.

2017-02-14 Thread Lakshmipathi.G
Signed-off-by: Lakshmipathi.G <lakshmipath...@giis.co.in>
---
 .../019-fix-corrupted-superblock/test.sh   | 37 ++
 1 file changed, 37 insertions(+)
 create mode 100755 tests/misc-tests/019-fix-corrupted-superblock/test.sh

diff --git a/tests/misc-tests/019-fix-corrupted-superblock/test.sh 
b/tests/misc-tests/019-fix-corrupted-superblock/test.sh
new file mode 100755
index 000..806c775
--- /dev/null
+++ b/tests/misc-tests/019-fix-corrupted-superblock/test.sh
@@ -0,0 +1,37 @@
+#!/bin/bash
+#
+# Corrupt primary superblock and restore it using backup superblock.
+#
+
+source $TOP/tests/common
+
+check_prereq btrfs-select-super
+
+setup_root_helper
+prepare_test_dev 512M
+
+superblock_offset=65536
+
+test_superblock_restore()
+{
+   run_check $SUDO_HELPER $TOP/mkfs.btrfs -f $TEST_DEV
+
+   # Corrupt superblock checksum
+dd if=/dev/zero of=$TEST_DEV seek=$superblock_offset bs=1 \
+count=4  conv=notrunc &> /dev/null
+   run_check_stdout $SUDO_HELPER mount $TEST_DEV $TEST_MNT | \
+   grep -q 'wrong fs type'
+if [ $? -ne 0 ]; then
+   _fail "Failed to corrupt superblock."
+fi 
+
+   # Copy backup superblock to primary
+   run_check $TOP/btrfs-select-super -s 1 $TEST_DEV
+   run_check $SUDO_HELPER mount $TEST_DEV $TEST_MNT
+if [ $? -ne 0 ]; then
+   _fail "Failed to fix superblock."
+fi 
+   run_check_umount_test_dev
+}
+
+test_superblock_restore
-- 
2.7.4

--
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: How to dump/find parity of RAID-5 file?

2017-02-14 Thread Lakshmipathi.G
On Mon, Feb 06, 2017 at 09:40:47PM +0100, Goffredo Baroncelli wrote:
> 
> IIRC, the parity is spread across the disk stripes of the chunk.
> 
> So first you have to find the logical-offset [LO] where the the file begins. 
> Then you have to map this offset to the chunk which holds the data. The chunk 
> has the following info:
> - chunk start [CS], chunk length [CL]
> - for each stripe:
>   where the stripe starts
> 
> If you subtract the chunk-start from the logical-offset [ CO == LO-CS], you 
> will find the offset where the data belongs in the chunk.
> 
> As stated above, the PARITY is spread across the chunk stripes. So (supposing 
> that the stripe size is 64K, the raid level is 5, the disks are three), 
> 
> - the first 64k of stripe 0, is data [0..64K)
> - the first 64k of stripe 1, is data [64..128K)
> - the first 64k of stripe 2 is parity, 
> 
> - the 2nd 64k of stripe 0 is parity, 
> - the 2nd 64k of stripe 1, is data [128..196K)
> - the 2nd 64k of stripe 2, is data [192..256K)
> 
> - the 3rd 64k of stripe 0, is data [256..320K)
> - the 3rd 64k of stripe 1 is parity, 
> - the 3rd 64k of stripe 2, is data [320..384K)
> and so on,
> 
> To find the data, You have to compare the CO to the data [...) range.
> 
> If you look to an my old patch (unfinished :-( ), you can find some example 
> to dump the different stripe
> 
> [BTRFS-PROGS][PATCH][V2] Add two new commands: 'btrfs insp physical-find' and 
> 'btrfs insp physical-dump'
> 
> 
Sorry for the delay, I was offline. Thanks for the details. I can understood 
"partiy spread across the chunk stripes" part.
But unable to figure-out the first part regarding calculations.

Raid5 With 3-devices each 512MB. Create single 128KB file("print 
'Ab'+'a'*65534+'aB'+'b'*65533"). 'debug-tree' shows chunk tree as:

item 5 key (FIRST_CHUNK_TREE CHUNK_ITEM 145096704) itemoff 15557 
itemsize 144
length 134217728 owner 2 stripe_len 65536 type DATA|RAID5
io_align 65536 io_width 65536 sector_size 4096
num_stripes 3 sub_stripes 0
stripe 0 devid 3 offset 6368
dev_uuid 9a2a18f1-6193-44b9-aafc-23d161d66110
stripe 1 devid 2 offset 6368
dev_uuid e45ab907-c3a8-4dff-af9f-2ae5fd38ffd6
stripe 2 devid 1 offset 83034112
dev_uuid 428c04d9-37da-454a-b7b2-f6fe88580de2
and fs-tree shows:
item 13 key (145227776 EXTENT_ITEM 131072) itemoff 15788 itemsize 53
extent refs 1 gen 7 flags DATA
extent data backref root 5 objectid 257 offset 0 count 1

>From above, I assume: 
LO=145227776  CS=145096704 and CL=134217728
CO=145227776 - 145096704  => CO = 131072

Quite confused from here :s  I'll look into your patches to understand more. I 
hope sometime in future we will 
have your finished patches :) 'physical-find' and 'physical-find' commands will 
be really useful for debugging/testing and 
learning purposes. thanks.

Cheers.
Lakshmipathi.G
--
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: How to dump/find parity of RAID-5 file?

2017-02-14 Thread Lakshmipathi.G
On Mon, Feb 06, 2017 at 09:36:58AM +0800, Qu Wenruo wrote:
> 
> Please note the following things when calculating RAID5/6 data and P/Q
> location:
> 
> 1) Basic layout
> The chunk stripe only shows the *first* full stripe layout.
> And it always follows the sequence of "Data0, Data1, ... Data N, Parity"
> 
> And one full stripe is consistent of N * 64K (fixed yet).
> 
> 
> 2) Device rotation
> RAID5/6 do device rotation.
> So the *second* full stripe will have the following layout:
> "Data 1, Data2, ... Data N, Parity, Data 0"
> 
> 
> You can refer to my offline-scrub patchset to see how it assemble the
> RAID5/6 mapping, which I believe it is easier than current btrfs_map_block()
> implementation.
> [PATCH v2 19/19] btrfs-progs: fsck: Introduce offline scrub function
> 
> Thanks,
> Qu
Sorry for the delay in response, I was offline. Thanks for the details. I think 
now I have 
better idea about (1)Basic layout  and (2)Device rotation. Will look into 
offline-scrub patches 
to explore more about exact mapping and on-disk layouts. I'm trying to 
understand layout for
simple Raid-5 with 3-drives with 128KB file-size. Will try to understand Raid-6 
little later. 
thanks.

Cheers.
Lakshmipathi.G
--
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: Very slow balance / btrfs-transaction

2017-02-03 Thread Lakshmipathi.G
>Should quota support generally be disabled during balances?

If this true and quota impacts balance throughput, at-least there
should an alert message like "Running Balance with quota will affect
performance" or similar before starting.


Cheers,
Lakshmipathi.G
--
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


How to dump/find parity of RAID-5 file?

2017-02-03 Thread Lakshmipathi.G
Hi.

Came across this thread 
https://www.mail-archive.com/linux-btrfs@vger.kernel.org/msg55161.html 
Exploring possibility of adding test-scripts around these area using dump-tree 
& corrupt-block.But
unable to figure-out how to get parity of file or find its location.  dump-tree 
output gave,

item 5 key (FIRST_CHUNK_TREE CHUNK_ITEM 145096704) itemoff 15557 itemsize 
144
length 134217728 owner 2 stripe_len 65536 type DATA|RAID5
io_align 65536 io_width 65536 sector_size 4096
num_stripes 3 sub_stripes 0
stripe 0 devid 3 offset 6368 # Is this 
parity?Seems empty?
dev_uuid f62df114-186c-4e48-8152-9ed15aa078b4
stripe 1 devid 2 offset 6368 # Contains file 
data-stripe-1
dev_uuid c0aeaab0-e57e-4f7a-9356-db1878876d9f
stripe 2 devid 1 offset 83034112 # Contains file 
data-stripe-2
dev_uuid 637b3666-9d8f-4ec4-9969-53b0b933b9b1
thanks.

Cheers.
Lakshmipathi.G
--
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 v3] btrfs-progs: fsck-tests: verify 'btrfs check --repair' fixes corrupted nlink field

2017-02-02 Thread Lakshmipathi.G
Signed-off-by: Lakshmipathi.G <lakshmipath...@giis.co.in>
---
 tests/fsck-tests/026-check-inode-link/test.sh | 30 +++
 1 file changed, 30 insertions(+)
 create mode 100755 tests/fsck-tests/026-check-inode-link/test.sh

diff --git a/tests/fsck-tests/026-check-inode-link/test.sh 
b/tests/fsck-tests/026-check-inode-link/test.sh
new file mode 100755
index 000..6822ee2
--- /dev/null
+++ b/tests/fsck-tests/026-check-inode-link/test.sh
@@ -0,0 +1,30 @@
+#!/bin/bash
+# verify that 'btrfs check --repair' fixes corrupted inode nlink field
+
+source $TOP/tests/common
+
+check_prereq btrfs-corrupt-block
+check_prereq mkfs.btrfs
+
+setup_root_helper
+prepare_test_dev 512M
+
+test_inode_nlink_field()
+{
+   run_check $SUDO_HELPER $TOP/mkfs.btrfs -f $TEST_DEV
+
+   run_check_mount_test_dev
+   run_check $SUDO_HELPER touch $TEST_MNT/test_nlink.txt
+
+   # find inode_number
+   inode_number=`stat -c%i $TEST_MNT/test_nlink.txt`
+   run_check_umount_test_dev
+
+   # corrupt nlink field of inode object
+run_check $SUDO_HELPER $TOP/btrfs-corrupt-block -i $inode_number \
+   -f nlink $TEST_DEV
+
+   check_image $TEST_DEV
+}
+
+test_inode_nlink_field
-- 
2.7.4

--
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] btrfs-progs: fsck-tests: verify 'btrfs check --repair' fixes corrupted nlink field

2017-02-01 Thread Lakshmipathi.G
> 
> apply anymore, but I'm expecting some more changes to it so please adapt
> it to the new file

Not sure what went wrong, will test the next patch with git apply and send it.

> 
> I prefer 'inode_number' or simple 'ino' for the variable name.
> 

Okay, will use inode_number.

> >+
> >+$SUDO_HELPER $TOP/btrfs check $TEST_DEV &>> $RESULTS && \
> >+_fail "btrfs check failed to detect nlink corruption"
> >+run_check $SUDO_HELPER $TOP/btrfs check --repair $TEST_DEV
> >+run_check $SUDO_HELPER $TOP/btrfs check $TEST_DEV
> 
> What about using check_image() here?

I didn't know about check_image(), looks like above 3 lines can be replaced
with check_image. Will make the change.

> 
> Thanks,
> Qu
> 

Cheers.
Lakshmipathi.G
--
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: Fresh Raid-1 setup, dump-tree shows invalid owner id

2017-01-30 Thread Lakshmipathi.G
>
> Yes, the owner is the number of the tree.
>
> DATA_RELOC_TREE is -9, but then unsigned 64 bits.
>
>>>> -9 + 2**64
> 18446744073709551607L
>
> So the result is a number that's close to the max or 64 bits.
>
> You can find those numbers in the kernel source in
>   include/uapi/linux/btrfs_tree.h
>
> e.g.:
>
> #define BTRFS_DATA_RELOC_TREE_OBJECTID -9ULL
>

Thanks for the details. This owner number looked different from other
owner ids, so wanted to check on the same, now understood.

Cheers.
Lakshmipathi.G
--
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: Fresh Raid-1 setup, dump-tree shows invalid owner id

2017-01-30 Thread Lakshmipathi.G
Raid1 is irrelevant, looks like this happen with simple case too.
$./mkfs.btrfs tests/test.img
$./btrfs-debug-tree tests/test.img

possible issue with ./btrfs-debug-tree stdout?

On Mon, Jan 30, 2017 at 7:24 AM, Lakshmipathi.G
<lakshmipath...@giis.co.in> wrote:
> After creating raid1:
> $./mkfs.btrfs -f -d raid1 -m raid1 /dev/sda6 /dev/sda7
>
> and using
> $./btrfs inspect-internal dump-tree /dev/sda6  #./btrfs-debug-tree /dev/sda6
>
> shows possible wrong value for 'owner'?
> --
> checksum tree key (CSUM_TREE ROOT_ITEM 0)
> leaf 29425664 items 0 free space 16283 generation 4 owner 7
> fs uuid 94fee00b-00aa-4d69-b947-347f743117f2
> chunk uuid 6477561c-cbca-45e4-980d-56727a8dc9d9
> data reloc tree key (DATA_RELOC_TREE ROOT_ITEM 0)
> leaf 29442048 items 2 free space 16061 generation 4 owner 
> 18446744073709551607 <<< owner id?
> fs uuid 94fee00b-00aa-4d69-b947-347f743117f2
> chunk uuid 6477561c-cbca-45e4-980d-56727a8dc9d9
> --
>
> or is that expected output?
>
> Cheers.
> Lakshmipathi.G
> --
> 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
--
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


Fresh Raid-1 setup, dump-tree shows invalid owner id

2017-01-29 Thread Lakshmipathi.G
After creating raid1:
$./mkfs.btrfs -f -d raid1 -m raid1 /dev/sda6 /dev/sda7

and using
$./btrfs inspect-internal dump-tree /dev/sda6  #./btrfs-debug-tree /dev/sda6

shows possible wrong value for 'owner'? 
--
checksum tree key (CSUM_TREE ROOT_ITEM 0) 
leaf 29425664 items 0 free space 16283 generation 4 owner 7
fs uuid 94fee00b-00aa-4d69-b947-347f743117f2
chunk uuid 6477561c-cbca-45e4-980d-56727a8dc9d9
data reloc tree key (DATA_RELOC_TREE ROOT_ITEM 0) 
leaf 29442048 items 2 free space 16061 generation 4 owner 18446744073709551607 
<<< owner id?
fs uuid 94fee00b-00aa-4d69-b947-347f743117f2
chunk uuid 6477561c-cbca-45e4-980d-56727a8dc9d9
--

or is that expected output?

Cheers.
Lakshmipathi.G
--
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: Raid1 won't mount degraded

2017-01-29 Thread Lakshmipathi.G
>powered off the system added a
>new disk

>root@NAS:~# btrfs fi show
>Label: none  uuid: f89c12fb-2304-4dce-bed5-fda008b86bde
>   Total devices 2 FS bytes used 2.49TiB
>  devid1 size 2.73TiB used 2.52TiB path /dev/sdb1
> *** Some devices missing

Are you sure 'device add' was successful? Whats the new  device name?
'btrfs fi show' shows only device (sdb1).




Cheers,
Lakshmipathi.G
--
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] btrfs-progs: cli-tests: Convert non-raid filesystem to raid

2017-01-29 Thread Lakshmipathi.G
Simple script to verify non-raid filesystem conversion.

Signed-off-by: Lakshmipathi.G <lakshmipath...@giis.co.in>
---
 tests/cli-tests/005-convert-btrfs-to-raid/test.sh | 32 +++
 1 file changed, 32 insertions(+)
 create mode 100755 tests/cli-tests/005-convert-btrfs-to-raid/test.sh

diff --git a/tests/cli-tests/005-convert-btrfs-to-raid/test.sh 
b/tests/cli-tests/005-convert-btrfs-to-raid/test.sh
new file mode 100755
index 000..96772de
--- /dev/null
+++ b/tests/cli-tests/005-convert-btrfs-to-raid/test.sh
@@ -0,0 +1,32 @@
+#!/bin/bash
+#
+# convert non-raid btrfs to raid
+
+source $TOP/tests/common
+
+check_prereq mkfs.btrfs
+check_prereq btrfs
+
+setup_root_helper
+prepare_test_dev 1g
+run_check truncate -s1g img
+
+run_check $TOP/mkfs.btrfs -f $IMAGE
+run_check_mount_test_dev
+
+loopdev=$(run_check_stdout $SUDO_HELPER losetup --partscan --find --show img)
+
+run_check $SUDO_HELPER $TOP/btrfs device add $loopdev $TEST_MNT
+run_check $SUDO_HELPER $TOP/btrfs balance start -dconvert=raid1 
-mconvert=raid1 $TEST_MNT
+
+run_check_stdout $SUDO_HELPER $TOP/btrfs filesystem show $loopdev | grep 
"Total devices 2" -q
+if [ $? -ne 0 ]; then
+   run_check $SUDO_HELPER losetup -d $loopdev
+   rm -f img
+_fail "Conversion from non-raid filesystem to raid failed."
+fi
+run_check_umount_test_dev
+
+# cleanup
+run_check $SUDO_HELPER losetup -d $loopdev
+rm -f img
-- 
2.7.4

--
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] btrfs-progs: fsck-tests: verify 'btrfs check --repair' fixes corrupted nlink field

2017-01-28 Thread Lakshmipathi.G
Signed-off-by: Lakshmipathi.G <lakshmipath...@giis.co.in>
---
 tests/fsck-tests/026-check-inode-link/test.sh | 34 +++
 1 file changed, 34 insertions(+)
 create mode 100755 tests/fsck-tests/026-check-inode-link/test.sh

diff --git a/tests/fsck-tests/026-check-inode-link/test.sh 
b/tests/fsck-tests/026-check-inode-link/test.sh
new file mode 100755
index 000..9e75ef4
--- /dev/null
+++ b/tests/fsck-tests/026-check-inode-link/test.sh
@@ -0,0 +1,34 @@
+#!/bin/bash
+
+source $TOP/tests/common
+
+check_prereq btrfs-corrupt-block
+check_prereq mkfs.btrfs
+check_prereq btrfs
+
+setup_root_helper
+prepare_test_dev 512M
+
+# verify that 'btrfs check --repair' fixes corrupted inode nlink field.
+test_inode_nlink_field()
+{
+   run_check $SUDO_HELPER $TOP/mkfs.btrfs -f $TEST_DEV
+
+   run_check_mount_test_dev
+   run_check $SUDO_HELPER touch $TEST_MNT/test_nlink.txt
+
+   # find inode_item id
+   inode_item=`stat -c%i $TEST_MNT/test_nlink.txt`
+   run_check_umount_test_dev
+
+   # corrupt nlink field of inode object
+run_check $SUDO_HELPER $TOP/btrfs-corrupt-block -i $inode_item \
+   -f nlink $TEST_DEV
+
+   $SUDO_HELPER $TOP/btrfs check $TEST_DEV &>> $RESULTS && \
+   _fail "btrfs check failed to detect nlink corruption"
+   run_check $SUDO_HELPER $TOP/btrfs check --repair $TEST_DEV
+   run_check $SUDO_HELPER $TOP/btrfs check $TEST_DEV
+}
+
+test_inode_nlink_field
-- 
2.7.4

--
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] xfstests: btrfs/047: check btrfs-convert with extent and non-extent source

2017-01-27 Thread Lakshmipathi.G
This is used to check the source which contains combination of Ext3 files
in non-extent format and  Ext4 extent-files. And validate the file md5sums
before and after conversion.

btrfs/012: BTRFS_CONVERT_PROG,E2FSCK_PROG definitions reused from common/config

Signed-off-by: Lakshmipathi.G <lakshmipath...@giis.co.in>
---
 common/config   |   3 ++
 tests/btrfs/012 |   3 --
 tests/btrfs/047 | 122 
 tests/btrfs/047.out |   2 +
 tests/btrfs/group   |   1 +
 5 files changed, 128 insertions(+), 3 deletions(-)
 create mode 100755 tests/btrfs/047
 create mode 100644 tests/btrfs/047.out

diff --git a/common/config b/common/config
index 0706aca..fa89f42 100644
--- a/common/config
+++ b/common/config
@@ -240,11 +240,14 @@ case "$HOSTOS" in
 export DUMP_F2FS_PROG="`set_prog_path dump.f2fs`"
 export BTRFS_UTIL_PROG="`set_prog_path btrfs`"
 export BTRFS_SHOW_SUPER_PROG="`set_prog_path btrfs-show-super`"
+   export BTRFS_CONVERT_PROG="`set_prog_path btrfs-convert`"
 export XFS_FSR_PROG="`set_prog_path xfs_fsr`"
 export MKFS_NFS_PROG="false"
 export MKFS_CIFS_PROG="false"
 export MKFS_OVERLAY_PROG="false"
 export MKFS_REISER4_PROG="`set_prog_path mkfs.reiser4`"
+   export E2FSCK_PROG="`set_prog_path e2fsck`"
+   export TUNE2FS_PROG="`set_prog_path tune2fs`"
 ;;
 esac
 
diff --git a/tests/btrfs/012 b/tests/btrfs/012
index 6a3cb81..85c82f0 100755
--- a/tests/btrfs/012
+++ b/tests/btrfs/012
@@ -54,9 +54,6 @@ _supported_fs btrfs
 _supported_os Linux
 _require_scratch_nocheck
 
-BTRFS_CONVERT_PROG="`set_prog_path btrfs-convert`"
-E2FSCK_PROG="`set_prog_path e2fsck`"
-
 _require_command "$BTRFS_CONVERT_PROG" btrfs-convert
 _require_command "$MKFS_EXT4_PROG" mkfs.ext4
 _require_command "$E2FSCK_PROG" e2fsck
diff --git a/tests/btrfs/047 b/tests/btrfs/047
new file mode 100755
index 000..d349d12
--- /dev/null
+++ b/tests/btrfs/047
@@ -0,0 +1,122 @@
+#! /bin/bash
+# FS QA Test 047
+#
+# Test btrfs-convert
+#
+# 1) create ext3 filesystem & populate it.
+# 2) upgrade ext3 filesystem to ext4.
+# 3) populate data.
+# 4) source has combination of non-extent and extent files.
+# 5) convert it to btrfs, mount and verify contents.
+#---
+# Copyright (c) 2017 Lakshmipathi.G  All Rights Reserved.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write the Free Software Foundation,
+# Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+#---
+#
+
+seq=`basename $0`
+seqres=$RESULT_DIR/$seq
+echo "QA output created by $seq"
+
+here=`pwd`
+tmp=/tmp/$$
+status=1   # failure is the default!
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+_cleanup()
+{
+   cd /
+   rm -f $tmp.*
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# real QA test starts here
+
+# Modify as appropriate.
+_supported_fs btrfs
+_supported_os Linux
+_require_scratch_nocheck
+
+_require_command "$BTRFS_CONVERT_PROG" btrfs-convert
+_require_command "$MKFS_EXT4_PROG" mkfs.ext4
+_require_command "$E2FSCK_PROG" e2fsck
+_require_command "$TUNE2FS_PROG" tune2fs
+
+rm -f $seqres.full
+
+BLOCK_SIZE=`_get_block_size $TEST_DIR`
+EXT_MD5SUM="$tmp.ext43"
+BTRFS_MD5SUM="$tmp.btrfs"
+
+_populate_data(){
+   data_path=$1
+   mkdir -p $data_path
+   args=`_scale_fsstress_args -p 20 -n 100 $FSSTRESS_AVOID -d $data_path`
+   echo "Run fsstress $args" >>$seqres.full
+   $FSSTRESS_PROG $args >/dev/null 2>&1 &
+   fsstress_pid=$!
+   wait $fsstress_pid
+}
+
+# Create & populate an ext3 filesystem
+$MKFS_EXT4_PROG -F -t ext3 -b $BLOCK_SIZE $SCRATCH_DEV > $seqres.full 2>&1 || \
+   _notrun "Could not create ext3 filesystem"
+
+# mount and populate non-extent file
+mount -t ext3 $SCRATCH_DEV $SCRATCH_MNT
+_populate_data "$SCRATCH_MNT/ext3_ext4_data/ext3"
+_scratch_unmount
+
+# Upgrade it to ext4.
+$TUNE2FS_PROG -O extents,uninit_bg,dir_index $SCRATCH_DEV >>

[PATCH] btrfs-progs: fsck-tests: script to verify init-csum-tree

2017-01-26 Thread Lakshmipathi.G
Corrupt csum entry of a file and re-create csum tree using --init-csum

Signed-off-by: Lakshmipathi.G <lakshmipath...@giis.co.in>
---
 .../fsck-tests/025-verify-init-csum-option/test.sh | 38 ++
 1 file changed, 38 insertions(+)
 create mode 100755 tests/fsck-tests/025-verify-init-csum-option/test.sh

diff --git a/tests/fsck-tests/025-verify-init-csum-option/test.sh 
b/tests/fsck-tests/025-verify-init-csum-option/test.sh
new file mode 100755
index 000..f496b33
--- /dev/null
+++ b/tests/fsck-tests/025-verify-init-csum-option/test.sh
@@ -0,0 +1,38 @@
+#!/bin/bash
+# This is a basic script to verify --init-csum recreates the csum tree.
+
+source $TOP/tests/common
+
+check_prereq btrfs-corrupt-block
+check_prereq mkfs.btrfs
+check_prereq btrfs
+
+setup_root_helper
+prepare_test_dev 512M
+
+
+# simulate missing csum error and repair using init-csum option
+test_csum_corruption()
+{
+   run_check $SUDO_HELPER $TOP/mkfs.btrfs -f $TEST_DEV
+
+   run_check_mount_test_dev
+
+   export DATASET_SIZE=1
+   generate_dataset small
+
+   run_check_umount_test_dev
+
+   # find bytenr
+   bytenr=`$SUDO_HELPER $TOP/btrfs inspect-internal dump-tree -t csum 
$TEST_DEV | \
+sed -n -r 's/.*EXTENT_CSUM (.*)\) itemoff .*/\1/p'`
+
+   # corrupt csum bytenr
+   run_check $SUDO_HELPER $TOP/btrfs-corrupt-block -C $bytenr $TEST_DEV
+   $SUDO_HELPER $TOP/btrfs check $TEST_DEV &>> $RESULTS && \
+   _fail "btrfs check failed to detect missing csum."
+   run_check $SUDO_HELPER $TOP/btrfs check --repair --init-csum $TEST_DEV
+   run_check $SUDO_HELPER $TOP/btrfs check  $TEST_DEV
+}
+
+test_csum_corruption
-- 
2.7.4

--
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: [RFC] btrfs-progs: btrfs-corrupt-block refactor

2017-01-25 Thread Lakshmipathi.G
Hi Qu,

I think it will be a good idea to have corruption log. It should take
--log or --verbose

btrfs-corrupt-block --log=/path/to/logfile

it should record original state of target object before the
corruption. For ex: when we try to corrupt nlink field of
/data/file.txt Log should have entries like:

--
Found /data/file.txt with inode:257
Found field:nlink value:1
Corruption done.
--

This will make debugging easier if debug-tree shows same output before
and after the corruption. We can check the logs figure-out whether
corruption exactly happened on specific object/field or not.


>"data" options are:
>  "--bytenr BYTENR"
> Mandatory, logical address
>  "--length LENGTH"
> Optional, default to sectorsize of the fs
>  "--mirror"
> Optional, default to all mirror
>
--mirror  option  Is this referring to file-data alone?. If so,
including an option to target meta-data from specific mirror will be
helpful.

For example:
Setup: RAID-1 with 3 drives (both data/meta-data mirrored)
Corrupt an inode from drive-2.
Running Btrfs-check figures out drive-1,drive-3 are valid entries and
updates/fixes drive-2 entries.

Something like that possible or i miss understood something?


Cheers.
Lakshmipathi.G
--
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] xfstests: btrfs/047: check btrfs-convert with extent and non-extent source

2017-01-25 Thread Lakshmipathi.G
On Wed, Jan 18, 2017 at 02:39:53PM +0800, Eryu Guan wrote:
> On Wed, Jan 18, 2017 at 07:17:02AM +0530, Lakshmipathi.G wrote:
> > Signed-off-by: Lakshmipathi.G <lakshmipath...@giis.co.in>
> 
> Need detailed test description in commit log too.

Okay will include them.

> 
> 
> Trailing whitespace in above line.
> 

> > +BTRFS_CONVERT_PROG="`set_prog_path btrfs-convert`"
> > +E2FSCK_PROG="`set_prog_path e2fsck`"
> > +TUNE2FS_PROG="`set_prog_path tune2fs`"
> 
> These should go to common/config. Can you please update btrfs/012 as
> well to move such defines to common/config?
> 

> > +# Create & populate an ext3 filesystem
> > +$MKFS_EXT4_PROG -t ext3 -b $BLOCK_SIZE $SCRATCH_DEV > $seqres.full 2>&1 || 
> > \
> > +   _notrun "Could not create ext3 filesystem"
> 
> Better to add "-F" option to mkfs to force mkfs so it won't stop when
> there's an existing fs on SCRATCH_DEV.
> 
> > +
> > +# mount and populate non-extent file
> > +mount -t ext3 $SCRATCH_DEV $SCRATCH_MNT
> > +dd if=/dev/urandom of=$SCRATCH_MNT/f1.txt bs=1MB count=10 >> $seqres.full 
> > 2>&1
> > +NON_EXTENT_MD5=`md5sum $SCRATCH_MNT/f1.txt  | awk '{print $1}' `
> 
> Better to have different files with different file sizes and different
> types, e.g. run fsstress to create such a fs structure.
> 

Will look into fsstress tool or else simply copy files from hosts machine. (ex: 
/usr/lib)

> > +_scratch_unmount
> > +
> > +# Upgrade it to ext4.
> > +$TUNE2FS_PROG -O extents,uninit_bg,dir_index $SCRATCH_DEV >> $seqres.full 
> > 2>&1
> > +$E2FSCK_PROG -fyD $SCRATCH_DEV >> $seqres.full 2>&1
> 
> Why is this e2fsck needed? Add some comments? Or it just can be removed?
> 
It recommended to run e2fsck after conversion as per 
https://ext4.wiki.kernel.org/index.php/UpgradeToExt4

> > +
> > +if [ $NON_EXTENT_MD5 != $F1_MD5 ] ; then 
> 
> Trailing whitespace in above line.
> 
> > +_fail "ext3 file mismatch."
> 
> No need to _fail, just echo this message to break golden image.
> 
> And need indention inside "if-then-fi"
> 
> > +fi
> > +
> > +if [ $EXTENT_MD5 != $F2_MD5 ] ; then 
> 
> Trailing whitespace.
> 
> > +_fail "ext4 file mismatch."
> 
> Same here. Use echo and indention.
> 
> > +fi
> > +   
> 
> Trailing whitespace.
> 
> > +# success, all done
> > +status=0
> > +exit
> > diff --git a/tests/btrfs/047.out b/tests/btrfs/047.out
> > new file mode 100644
> > index 000..58e2353
> > --- /dev/null
> > +++ b/tests/btrfs/047.out
> > @@ -0,0 +1 @@
> > +QA output created by 047
> 
> Usually we print a message "Silence is golden" to indicate that this
> test doesn't expect any output.
> 
> Thanks,
> Eryu
> 
Will modify the script to reflect above review comments.

Cheers.
Lakshmipathi.G 
--
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] btrfs-progs: fsck-tests: missing csum test script

2017-01-25 Thread Lakshmipathi.G
On Tue, Jan 17, 2017 at 04:06:27PM +0100, David Sterba wrote:
> It's not clear from the test what's the purpose. There's one corrupted
> csum but the whole csum tree rebuild option is used. This is a pretty
> basic check that the --init-csum-tree works, so it should be mentioned
> somewhere in the test script.

I'll rename directory to 027-verify-init-csum-tree instead of current one.

Is it possible, to fix only the corrupted csum instead of re-building the 
csum-tree?

> 
> Please don't use btrfs-debug-tree, it's been obsoleted by the dump-tree
> subcommand. And you can use the '-t csum' option to dump just the csum
> tree.

> 
> This can be simplified to one sed command.
> 

> 
> Here we want to capture the output from 'check' for analysis in case of
> problems.
> 
Will fix above three issues with next patch.
--
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] btfs-progs: fsck-tests: corrupt nlink value test

2017-01-25 Thread Lakshmipathi.G
> Both approaches have their pros and cons so I'll accept both. The
> functionality provided by the corrupt block utility can be used, any
> changes to the command line UI will be also applied to the test scripts.

okay, I'll continue mixing both approaches. 
--
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] xfstests: btrfs/047: check btrfs-convert with extent and non-extent source

2017-01-17 Thread Lakshmipathi.G
Signed-off-by: Lakshmipathi.G <lakshmipath...@giis.co.in>
---
 tests/btrfs/047 | 108 
 tests/btrfs/047.out |   1 +
 tests/btrfs/group   |   1 +
 3 files changed, 110 insertions(+)
 create mode 100755 tests/btrfs/047
 create mode 100644 tests/btrfs/047.out

diff --git a/tests/btrfs/047 b/tests/btrfs/047
new file mode 100755
index 000..0c4b2c7
--- /dev/null
+++ b/tests/btrfs/047
@@ -0,0 +1,108 @@
+#! /bin/bash
+# FS QA Test 047
+#
+# Test btrfs-convert
+# 
+# 1) create ext3 filesystem & populate it.
+# 2) update ext3 filesystem to ext4.
+# 3) populate data.
+# 4) source has combination of non-extent and extent files.
+# 5) convert it btrfs, mount and verify contents.
+#---
+# Copyright (c) 2017 Lakshmipathi.G  All Rights Reserved.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write the Free Software Foundation,
+# Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+#---
+#
+
+seq=`basename $0`
+seqres=$RESULT_DIR/$seq
+echo "QA output created by $seq"
+
+here=`pwd`
+tmp=/tmp/$$
+status=1   # failure is the default!
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+_cleanup()
+{
+   cd /
+   rm -f $tmp.*
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# real QA test starts here
+
+# Modify as appropriate.
+_supported_fs btrfs
+_supported_os Linux
+_require_scratch_nocheck
+
+BTRFS_CONVERT_PROG="`set_prog_path btrfs-convert`"
+E2FSCK_PROG="`set_prog_path e2fsck`"
+TUNE2FS_PROG="`set_prog_path tune2fs`"
+
+_require_command "$BTRFS_CONVERT_PROG" btrfs-convert
+_require_command "$MKFS_EXT4_PROG" mkfs.ext4
+_require_command "$E2FSCK_PROG" e2fsck
+_require_command "$TUNE2FS_PROG" tune2fs
+
+rm -f $seqres.full
+
+BLOCK_SIZE=`_get_block_size $TEST_DIR`
+
+# Create & populate an ext3 filesystem
+$MKFS_EXT4_PROG -t ext3 -b $BLOCK_SIZE $SCRATCH_DEV > $seqres.full 2>&1 || \
+   _notrun "Could not create ext3 filesystem"
+
+# mount and populate non-extent file
+mount -t ext3 $SCRATCH_DEV $SCRATCH_MNT
+dd if=/dev/urandom of=$SCRATCH_MNT/f1.txt bs=1MB count=10 >> $seqres.full 2>&1
+NON_EXTENT_MD5=`md5sum $SCRATCH_MNT/f1.txt  | awk '{print $1}' `
+_scratch_unmount
+
+# Upgrade it to ext4.
+$TUNE2FS_PROG -O extents,uninit_bg,dir_index $SCRATCH_DEV >> $seqres.full 2>&1
+$E2FSCK_PROG -fyD $SCRATCH_DEV >> $seqres.full 2>&1
+
+# mount and populate extent file
+mount -t ext4 $SCRATCH_DEV $SCRATCH_MNT
+dd if=/dev/urandom of=$SCRATCH_MNT/f2.txt bs=1MB count=10 >> $seqres.full 2>&1
+EXTENT_MD5=`md5sum $SCRATCH_MNT/f2.txt  | awk '{print $1}'`
+_scratch_unmount
+
+# Convert non-extent & extent data to btrfs, mount it, verify the data
+$BTRFS_CONVERT_PROG $SCRATCH_DEV >> $seqres.full 2>&1 || \
+   _fail "btrfs-convert failed"
+_scratch_mount || _fail "Could not mount new btrfs fs"
+
+F1_MD5=`md5sum $SCRATCH_MNT/f1.txt  | awk '{print $1}'`
+F2_MD5=`md5sum $SCRATCH_MNT/f2.txt  | awk '{print $1}'`
+if [ $NON_EXTENT_MD5 != $F1_MD5 ] ; then 
+_fail "ext3 file mismatch."
+fi
+
+if [ $EXTENT_MD5 != $F2_MD5 ] ; then 
+_fail "ext4 file mismatch."
+fi
+   
+# success, all done
+status=0
+exit
diff --git a/tests/btrfs/047.out b/tests/btrfs/047.out
new file mode 100644
index 000..58e2353
--- /dev/null
+++ b/tests/btrfs/047.out
@@ -0,0 +1 @@
+QA output created by 047
diff --git a/tests/btrfs/group b/tests/btrfs/group
index 3fbf706..224a082 100644
--- a/tests/btrfs/group
+++ b/tests/btrfs/group
@@ -49,6 +49,7 @@
 044 auto quick send
 045 auto quick send
 046 auto quick send
+047 auto convert
 048 auto quick
 049 auto quick
 050 auto quick send
-- 
2.7.4

--
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] btfs-progs: fsck-tests: corrupt nlink value test

2017-01-07 Thread Lakshmipathi.G
Signed-off-by: Lakshmipathi.G <lakshmipath...@giis.co.in>
---
 tests/fsck-tests/025-wrong-inode-nlink/test.sh | 37 ++
 1 file changed, 37 insertions(+)
 create mode 100755 tests/fsck-tests/025-wrong-inode-nlink/test.sh

diff --git a/tests/fsck-tests/025-wrong-inode-nlink/test.sh 
b/tests/fsck-tests/025-wrong-inode-nlink/test.sh
new file mode 100755
index 000..15f1b84
--- /dev/null
+++ b/tests/fsck-tests/025-wrong-inode-nlink/test.sh
@@ -0,0 +1,37 @@
+#!/bin/bash
+
+source $TOP/tests/common
+
+check_prereq btrfs-corrupt-block
+check_prereq mkfs.btrfs
+check_prereq btrfs
+
+setup_root_helper
+prepare_test_dev 512M
+
+# test whether fsck can fix a corrupted inode nlink
+test_inode_nlink_field()
+{
+   run_check $SUDO_HELPER $TOP/mkfs.btrfs -f $TEST_DEV
+
+   run_check_mount_test_dev
+   run_check $SUDO_HELPER touch $TEST_MNT/test_nlink.txt
+
+   run_check_umount_test_dev
+
+   # find inode_item id
+   inode_item=`$SUDO_HELPER $TOP/btrfs-debug-tree -t FS_TREE $TEST_DEV | \
+   grep -B3 "test_nlink.txt" |  grep INODE_ITEM | \
+   cut -f2 -d'(' | cut -f1 -d' ' | head -n1`
+
+   # corrupt nlink field of inode object:257
+run_check $SUDO_HELPER $TOP/btrfs-corrupt-block -i $inode_item \
+   -f nlink $TEST_DEV
+
+   $SUDO_HELPER $TOP/btrfs check $TEST_DEV >& /dev/null && \
+   _fail "btrfs check failed to detect nlink corruption"
+   run_check $SUDO_HELPER $TOP/btrfs check --repair $TEST_DEV
+   run_check $SUDO_HELPER $TOP/btrfs check $TEST_DEV
+}
+
+test_inode_nlink_field
-- 
2.7.4

--
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] btrfs-progs: Corruption-framework: Include inode fields

2017-01-05 Thread Lakshmipathi.G
Signed-off-by: Lakshmipathi.G <lakshmipath...@giis.co.in>
---
 btrfs-corrupt-block.c | 48 
 1 file changed, 48 insertions(+)

diff --git a/btrfs-corrupt-block.c b/btrfs-corrupt-block.c
index a2f35ab..0e1eb52 100644
--- a/btrfs-corrupt-block.c
+++ b/btrfs-corrupt-block.c
@@ -309,6 +309,12 @@ enum btrfs_inode_field {
BTRFS_INODE_FIELD_ISIZE,
BTRFS_INODE_FIELD_NBYTES,
BTRFS_INODE_FIELD_NLINK,
+   BTRFS_INODE_FIELD_GENERATION,
+   BTRFS_INODE_FIELD_TRANSID,
+   BTRFS_INODE_FIELD_BLOCK_GROUP,
+   BTRFS_INODE_FIELD_MODE,
+   BTRFS_INODE_FIELD_UID,
+   BTRFS_INODE_FIELD_GID,
BTRFS_INODE_FIELD_BAD,
 };
 
@@ -349,6 +355,18 @@ static enum btrfs_inode_field convert_inode_field(char 
*field)
return BTRFS_INODE_FIELD_NBYTES;
if (!strncmp(field, "nlink", FIELD_BUF_LEN))
return BTRFS_INODE_FIELD_NLINK;
+   if (!strncmp(field, "generation", FIELD_BUF_LEN))
+   return BTRFS_INODE_FIELD_GENERATION;
+   if (!strncmp(field, "transid", FIELD_BUF_LEN))
+   return BTRFS_INODE_FIELD_TRANSID;
+   if (!strncmp(field, "block_group", FIELD_BUF_LEN))
+   return BTRFS_INODE_FIELD_BLOCK_GROUP;
+   if (!strncmp(field, "mode", FIELD_BUF_LEN))
+   return BTRFS_INODE_FIELD_MODE;
+   if (!strncmp(field, "uid", FIELD_BUF_LEN))
+   return BTRFS_INODE_FIELD_UID;
+   if (!strncmp(field, "gid", FIELD_BUF_LEN))
+   return BTRFS_INODE_FIELD_GID;
return BTRFS_INODE_FIELD_BAD;
 }
 
@@ -611,6 +629,36 @@ static int corrupt_inode(struct btrfs_trans_handle *trans,
bogus = generate_u32(orig);
btrfs_set_inode_nlink(path->nodes[0], ei, bogus);
break;
+   case BTRFS_INODE_FIELD_GENERATION:
+   orig = btrfs_inode_generation(path->nodes[0], ei);
+   bogus = generate_u64(orig);
+   btrfs_set_inode_generation(path->nodes[0], ei, bogus);
+   break;
+   case BTRFS_INODE_FIELD_TRANSID:
+   orig = btrfs_inode_transid(path->nodes[0], ei);
+   bogus = generate_u64(orig);
+   btrfs_set_inode_transid(path->nodes[0], ei, bogus);
+   break;
+   case BTRFS_INODE_FIELD_BLOCK_GROUP:
+   orig = btrfs_inode_block_group(path->nodes[0], ei);
+   bogus = generate_u64(orig);
+   btrfs_set_inode_block_group(path->nodes[0], ei, bogus);
+   break;
+   case BTRFS_INODE_FIELD_MODE:
+   orig = btrfs_inode_mode(path->nodes[0], ei);
+   bogus = generate_u32(orig);
+   btrfs_set_inode_mode(path->nodes[0], ei, bogus);
+   break;
+   case BTRFS_INODE_FIELD_UID:
+   orig = btrfs_inode_uid(path->nodes[0], ei);
+   bogus = generate_u32(orig);
+   btrfs_set_inode_uid(path->nodes[0], ei, bogus);
+   break;
+   case BTRFS_INODE_FIELD_GID:
+   orig = btrfs_inode_gid(path->nodes[0], ei);
+   bogus = generate_u32(orig);
+   btrfs_set_inode_gid(path->nodes[0], ei, bogus);
+   break;
default:
ret = -EINVAL;
break;
-- 
2.7.4

--
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] btrfs-progs: fsck-tests: missing csum test script

2017-01-05 Thread Lakshmipathi.G
Signed-off-by: Lakshmipathi.G <lakshmipath...@giis.co.in>
---
 tests/fsck-tests/027-missing-data-csum/test.sh | 39 ++
 1 file changed, 39 insertions(+)
 create mode 100755 tests/fsck-tests/027-missing-data-csum/test.sh

diff --git a/tests/fsck-tests/027-missing-data-csum/test.sh 
b/tests/fsck-tests/027-missing-data-csum/test.sh
new file mode 100755
index 000..6d1dc97
--- /dev/null
+++ b/tests/fsck-tests/027-missing-data-csum/test.sh
@@ -0,0 +1,39 @@
+#!/bin/bash
+
+source $TOP/tests/common
+
+check_prereq btrfs-corrupt-block
+check_prereq mkfs.btrfs
+check_prereq btrfs
+
+setup_root_helper
+prepare_test_dev 512M
+
+
+# simulate missing csum error and repair using init-csum option
+test_csum_corruption()
+{
+   run_check $SUDO_HELPER $TOP/mkfs.btrfs -f $TEST_DEV
+
+   run_check_mount_test_dev
+
+   export DATASET_SIZE=1
+   generate_dataset small
+
+   run_check_umount_test_dev
+
+   # find bytenr
+   bytenr=`$SUDO_HELPER $TOP/btrfs-debug-tree $TEST_DEV | \
+   grep "EXTENT_CSUM EXTENT_CSUM" | \
+   cut -f1 -d')' | awk '{print $6}'`
+
+   # corrupt csum bytenr
+   run_check $SUDO_HELPER $TOP/btrfs-corrupt-block -C $bytenr $TEST_DEV
+
+   $SUDO_HELPER $TOP/btrfs check $TEST_DEV >& /dev/null && \
+   _fail "btrfs check failed to detect missing csum."
+   run_check $SUDO_HELPER $TOP/btrfs check --repair --init-csum $TEST_DEV
+   run_check $SUDO_HELPER $TOP/btrfs check  $TEST_DEV
+}
+
+test_csum_corruption
-- 
2.7.4

--
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] btrfs-progs: Corruption-framework: Include inode nlink field

2017-01-05 Thread Lakshmipathi.G
Patch with fix for David Sterba review comment.

Signed-off-by: Lakshmipathi.G <lakshmipath...@giis.co.in>
---
 btrfs-corrupt-block.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/btrfs-corrupt-block.c b/btrfs-corrupt-block.c
index 16680df..a2f35ab 100644
--- a/btrfs-corrupt-block.c
+++ b/btrfs-corrupt-block.c
@@ -308,6 +308,7 @@ static void btrfs_corrupt_extent_tree(struct 
btrfs_trans_handle *trans,
 enum btrfs_inode_field {
BTRFS_INODE_FIELD_ISIZE,
BTRFS_INODE_FIELD_NBYTES,
+   BTRFS_INODE_FIELD_NLINK,
BTRFS_INODE_FIELD_BAD,
 };
 
@@ -346,6 +347,8 @@ static enum btrfs_inode_field convert_inode_field(char 
*field)
return BTRFS_INODE_FIELD_ISIZE;
if (!strncmp(field, "nbytes", FIELD_BUF_LEN))
return BTRFS_INODE_FIELD_NBYTES;
+   if (!strncmp(field, "nlink", FIELD_BUF_LEN))
+   return BTRFS_INODE_FIELD_NLINK;
return BTRFS_INODE_FIELD_BAD;
 }
 
@@ -603,6 +606,11 @@ static int corrupt_inode(struct btrfs_trans_handle *trans,
bogus = generate_u64(orig);
btrfs_set_inode_nbytes(path->nodes[0], ei, bogus);
break;
+   case BTRFS_INODE_FIELD_NLINK:
+   orig = btrfs_inode_nlink(path->nodes[0], ei);
+   bogus = generate_u32(orig);
+   btrfs_set_inode_nlink(path->nodes[0], ei, bogus);
+   break;
default:
ret = -EINVAL;
break;
-- 
2.7.4

--
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] btrfs-progs: btrfs-debugfs: Display usage hint with no arguments

2017-01-04 Thread Lakshmipathi.G
I think we can achieve above help string with the help of custom usage
function instead of using argparse default usage.  I'll check and send
a new patch.


Cheers,
Lakshmipathi.G
FOSS Programmer.
www.giis.co.in


On Wed, Jan 4, 2017 at 6:14 AM, Qu Wenruo <quwen...@cn.fujitsu.com> wrote:
> What about changing current help string to:
>
> btrfs-debugfs -b|-f path
> or
> btrfs-debugfs -h
>
> Thanks,
> Qu
--
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] btrfs-progs: Corruption-framework: Include inode nlink field

2017-01-03 Thread Lakshmipathi.G
Will include other fields, if this gets accepted.


Signed-off-by: Lakshmipathi.G <lakshmipath...@giis.co.in>
---
 btrfs-corrupt-block.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/btrfs-corrupt-block.c b/btrfs-corrupt-block.c
index 16680df..64376ca 100644
--- a/btrfs-corrupt-block.c
+++ b/btrfs-corrupt-block.c
@@ -309,6 +309,7 @@ enum btrfs_inode_field {
BTRFS_INODE_FIELD_ISIZE,
BTRFS_INODE_FIELD_NBYTES,
BTRFS_INODE_FIELD_BAD,
+   BTRFS_INODE_FIELD_NLINK,
 };
 
 enum btrfs_file_extent_field {
@@ -346,6 +347,8 @@ static enum btrfs_inode_field convert_inode_field(char 
*field)
return BTRFS_INODE_FIELD_ISIZE;
if (!strncmp(field, "nbytes", FIELD_BUF_LEN))
return BTRFS_INODE_FIELD_NBYTES;
+   if (!strncmp(field, "nlink", FIELD_BUF_LEN))
+   return BTRFS_INODE_FIELD_NLINK;
return BTRFS_INODE_FIELD_BAD;
 }
 
@@ -603,6 +606,11 @@ static int corrupt_inode(struct btrfs_trans_handle *trans,
bogus = generate_u64(orig);
btrfs_set_inode_nbytes(path->nodes[0], ei, bogus);
break;
+   case BTRFS_INODE_FIELD_NLINK:
+   orig = btrfs_inode_nlink(path->nodes[0], ei);
+   bogus = generate_u32(orig);
+   btrfs_set_inode_nlink(path->nodes[0], ei, bogus);
+   break;
default:
ret = -EINVAL;
break;
-- 
2.7.4

--
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] btrfs-progs: Corruption-framework: Include inode nlink field

2017-01-03 Thread Lakshmipathi.G
Will include other fields, if this gets accepted.

Signed-off-by: Lakshmipathi.G <lakshmipath...@giis.co.in>
---
 btrfs-corrupt-block.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/btrfs-corrupt-block.c b/btrfs-corrupt-block.c
index 16680df..64376ca 100644
--- a/btrfs-corrupt-block.c
+++ b/btrfs-corrupt-block.c
@@ -309,6 +309,7 @@ enum btrfs_inode_field {
BTRFS_INODE_FIELD_ISIZE,
BTRFS_INODE_FIELD_NBYTES,
BTRFS_INODE_FIELD_BAD,
+   BTRFS_INODE_FIELD_NLINK,
 };
 
 enum btrfs_file_extent_field {
@@ -346,6 +347,8 @@ static enum btrfs_inode_field convert_inode_field(char 
*field)
return BTRFS_INODE_FIELD_ISIZE;
if (!strncmp(field, "nbytes", FIELD_BUF_LEN))
return BTRFS_INODE_FIELD_NBYTES;
+   if (!strncmp(field, "nlink", FIELD_BUF_LEN))
+   return BTRFS_INODE_FIELD_NLINK;
return BTRFS_INODE_FIELD_BAD;
 }
 
@@ -603,6 +606,11 @@ static int corrupt_inode(struct btrfs_trans_handle *trans,
bogus = generate_u64(orig);
btrfs_set_inode_nbytes(path->nodes[0], ei, bogus);
break;
+   case BTRFS_INODE_FIELD_NLINK:
+   orig = btrfs_inode_nlink(path->nodes[0], ei);
+   bogus = generate_u32(orig);
+   btrfs_set_inode_nlink(path->nodes[0], ei, bogus);
+   break;
default:
ret = -EINVAL;
break;
-- 
2.7.4

--
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] btrfs-progs: btrfs-debugfs: Display usage hint with no arguments

2017-01-03 Thread Lakshmipathi.G
Yes. /mnt/file.txt is a mandatory argument. And -h/-b/-f are optional 
arugments. But the issue is, one of these optional argument is must. If we run:

btrfs-debugfs /mnt/file.txt

doesn't produce any output at all. From time to time, I run 'btrfs-debugfs 
/path/to/file'  and wonder why no output received then realize I must pass 
either -f or -b.  (May be '-f' needs be to set as 'default' when  no optional 
argument is provided.)

Overall, the current patch provides verbose message and does nothing more, it 
can be ignored. End user needs to remember -f or -b must be passed for valid 
outputs.
--
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] btrfs-progs: btrfs-debugfs: Display usage hint with no arguments

2017-01-03 Thread Lakshmipathi.G
Sorry about the misleading subject line. This patch is for missing
optional arguments.

Before the patch:
$ ./btrfs-debugfs /mnt/file.txt   # Does nothing and silently fails.

After the patch:
$ ./btrfs-debugfs /mnt/file.txt
No arguments passed. Type 'btrfs-debugfs -h' for usage.



Cheers,
Lakshmipathi.G
FOSS Programmer.
www.giis.co.in


On Tue, Jan 3, 2017 at 8:16 PM, David Sterba <dste...@suse.cz> wrote:
> This is what I see when no arguments pare passed:
>
> $ ./btrfs-debugfs
> usage: btrfs-debugfs [-h] [-b] [-f] path [path ...]
> btrfs-debugfs: error: too few arguments
>
> And that's exactly the same output as with this patch applied. Am I missing
> something?
--
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] btrfs-progs: btrfs-debugfs: Display usage hint with no arguments

2017-01-03 Thread Lakshmipathi.G
Signed-off-by: Lakshmipathi.G <lakshmipath...@giis.co.in>
---
 btrfs-debugfs | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/btrfs-debugfs b/btrfs-debugfs
index dfb8853..70419fa 100755
--- a/btrfs-debugfs
+++ b/btrfs-debugfs
@@ -392,7 +392,9 @@ parser.add_argument('-f', '--file', action='store_const', 
const=1, help='get fil
 
 args = parser.parse_args()
 
-if args.block_group:
+if not (args.block_group or args.file):
+print "No arguments passed. Type 'btrfs-debugfs -h' for usage."
+elif args.block_group:
 for i in args.path[0:]:
 print_block_groups(i)
 elif args.file:
-- 
2.7.4

--
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] btrfs-progs: btrfs-debugfs: Display usage hint with no arguments

2017-01-03 Thread Lakshmipathi.G
---
 btrfs-debugfs | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/btrfs-debugfs b/btrfs-debugfs
index dfb8853..70419fa 100755
--- a/btrfs-debugfs
+++ b/btrfs-debugfs
@@ -392,7 +392,9 @@ parser.add_argument('-f', '--file', action='store_const', 
const=1, help='get fil
 
 args = parser.parse_args()
 
-if args.block_group:
+if not (args.block_group or args.file):
+print "No arguments passed. Type 'btrfs-debugfs -h' for usage."
+elif args.block_group:
 for i in args.path[0:]:
 print_block_groups(i)
 elif args.file:
-- 
2.7.4

--
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]btrfs-progs: btrfs-debugfs: cleanup unused variables reported by pylint

2016-10-10 Thread Lakshmipathi.G
Signed-off-by: Lakshmipathi.G <lakshmipath...@giis.co.in>
---
 btrfs-debugfs | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/btrfs-debugfs b/btrfs-debugfs
index 0a654a6..dfb8853 100755
--- a/btrfs-debugfs
+++ b/btrfs-debugfs
@@ -4,7 +4,7 @@
 # LGPLv2 license
 # Copyright Facebook 2014
 
-import sys,os,struct,fcntl,ctypes,stat,argparse
+import sys, os, fcntl, ctypes, stat, argparse
 
 # helpers for max ints
 maxu64 = (1L << 64) - 1
@@ -233,7 +233,6 @@ def print_file_extents(filename):
 s.args.min_objectid = st.st_ino
 s.args.max_objectid = st.st_ino
 
-size = st.st_size
 
 while True:
 try:
@@ -314,7 +313,7 @@ def print_block_groups(mountpoint):
 
 try:
 fd = os.open(mountpoint, os.O_RDONLY)
-st = os.fstat(fd)
+os.fstat(fd)
 except Exception, e:
 sys.stderr.write("Failed to open %s (%s)\n" % (mountpoint, e))
 return -1
@@ -336,7 +335,7 @@ def print_block_groups(mountpoint):
 h = ctypes.addressof(header)
 p_left = args_buffer_size
 
-for x in xrange(0, s.args.nr_items):
+for _ in xrange(0, s.args.nr_items):
 # for each itme, copy the header from the buffer into
 # our header struct
 ctypes.memmove(h, p, header_size)
-- 
1.9.3

--
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: btrfs-convert: migrating files with flags set using chattr

2016-10-10 Thread Lakshmipathi.G
Hi Qu,

Thanks for resolving the issue and update. I'll re-use your testcase
with common.convert/generate_dataset() when it becomes
available on master branch.


Cheers,
Lakshmipathi.G



On Mon, Oct 10, 2016 at 6:54 AM, Qu Wenruo <quwen...@cn.fujitsu.com> wrote:
> Thanks for the report.
>
> I first thought it's a convert rewrite regression again, but I checked out
> v4.5.3(the last version without convert rewrite) and just found it's still
> the same problem.
>
> So the good news is, it's not a regression(at least for me), and the bad
> news is, attr copy never works from the beginning.
>
> I'll fix it in recent days, and enrich the convert test framework to prevent
> such problem happens again.
>
> Thanks,
> Qu
>
>
> At 10/10/2016 01:51 AM, Lakshmipathi.G wrote:
>>
>> Hi.
>>
>> Looks like btrfs-progs/btrfs-convert doesn't retain file attributes
>> like immutable flags, is this expected behavior ?
>>
>> //  test.img is ext2
>> [root@ mnt]# touch a b
>> [root@ mnt]# chattr +a a
>> [root@ mnt]# chattr +i b
>> [root@ mnt]# lsattr a b
>> -a-- a
>> i--- b
>>
>>
>> // after btrfs-convert  test.img
>>
>> [root@ mnt]# lsattr a b
>>  a
>>  b
>>
>>
>>
>> 
>> Cheers,
>> Lakshmipathi.G
>> --
>> 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
>>
>>
>
>
--
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


btrfs-convert: migrating files with flags set using chattr

2016-10-09 Thread Lakshmipathi.G
Hi.

Looks like btrfs-progs/btrfs-convert doesn't retain file attributes
like immutable flags, is this expected behavior ?

//  test.img is ext2
[root@ mnt]# touch a b
[root@ mnt]# chattr +a a
[root@ mnt]# chattr +i b
[root@ mnt]# lsattr a b
-a-- a
i--- b


// after btrfs-convert  test.img

[root@ mnt]# lsattr a b
 a
 b




Cheers,
Lakshmipathi.G
--
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]btrfs-progs: Add fast,slow symlinks,fifo types to convert test

2016-10-09 Thread Lakshmipathi.G
Signed-off-by: Lakshmipathi.G <lakshmipath...@giis.co.in>
---
 tests/common.convert | 20 +---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/tests/common.convert b/tests/common.convert
index 1e00d38..5083e65 100644
--- a/tests/common.convert
+++ b/tests/common.convert
@@ -25,10 +25,10 @@ generate_dataset() {
done
;;
 
-   symlink)
+   fast_symlink)
for num in $(seq 1 $DATASET_SIZE); do
run_check $SUDO_HELPER touch 
$dirpath/$dataset_type.$num
-   run_check $SUDO_HELPER ln -s 
$dirpath/$dataset_type.$num $dirpath/slink.$num
+   run_check $SUDO_HELPER cd $dirpath && ln -s 
$dataset_type.$num $dirpath/slink.$num && cd /
done
;;
 
@@ -71,12 +71,26 @@ generate_dataset() {
run_check $SUDO_HELPER setfattr -n user.foo -v 
bar$num $dirpath/$dataset_type.$num
done
;;
+
+   fifo)
+   for num in $(seq 1 $DATASET_SIZE); do
+   run_check $SUDO_HELPER mkfifo 
$dirpath/$dataset_type.$num
+   done
+   ;;
+
+   slow_symlink)
+   long_filename=`date +%s | sha256sum | cut -f1 -d'-'`
+   run_check $SUDO_HELPER touch $dirpath/$long_filename
+   for num in $(seq 1 $DATASET_SIZE); do
+   run_check $SUDO_HELPER ln -s 
$dirpath/$long_filename $dirpath/slow_slink.$num
+   done
+   ;;
esac
 }
 
 populate_fs() {
 
-for dataset_type in 'small' 'hardlink' 'symlink' 'brokenlink' 'perm' 
'sparse' 'acls'; do
+for dataset_type in 'small' 'hardlink' 'fast_symlink' 'brokenlink' 
'perm' 'sparse' 'acls' 'fifo' 'slow_symlink'; do
generate_dataset "$dataset_type"
done
 }
-- 
1.9.3

--
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]btrfs-progs: btrfs-convert.c : check source file system state

2016-09-15 Thread Lakshmipathi.G
Signed-off-by: Lakshmipathi.G <lakshmipath...@giis.co.in>
---
 btrfs-convert.c | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/btrfs-convert.c b/btrfs-convert.c
index c10dc17..27da9ce 100644
--- a/btrfs-convert.c
+++ b/btrfs-convert.c
@@ -2171,6 +2171,17 @@ static void ext2_copy_inode_item(struct btrfs_inode_item 
*dst,
}
memset(>reserved, 0, sizeof(dst->reserved));
 }
+static int check_filesystem_state(struct btrfs_convert_context *cctx)
+{
+   ext2_filsys fs = cctx->fs_data;
+
+if (!(fs->super->s_state & EXT2_VALID_FS))
+   return 1;
+   else if (fs->super->s_state & EXT2_ERROR_FS)
+   return 1;
+   else
+   return 0;
+}
 
 /*
  * copy a single inode. do all the required works, such as cloning
@@ -2340,6 +2351,10 @@ static int do_convert(const char *devname, int datacsum, 
int packing,
ret = convert_open_fs(devname, );
if (ret)
goto fail;
+   ret = check_filesystem_state();
+   if (ret) 
+   warning("Source Filesystem is not clean, \
+running e2fsck is recommended.");
ret = convert_read_used_space();
if (ret)
goto fail;
-- 
1.9.3

--
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]btrfs-progs: Add fast,slow symlinks and fifo types to convert test

2016-09-15 Thread Lakshmipathi.G
Signed-off-by: Lakshmipathi.G <lakshmipath...@giis.co.in>
---
 tests/common.convert | 18 +++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/tests/common.convert b/tests/common.convert
index 67c99b1..2790be5 100644
--- a/tests/common.convert
+++ b/tests/common.convert
@@ -25,10 +25,10 @@ generate_dataset() {
done
;;
 
-   symlink)
+   fast_symlink)
for num in $(seq 1 $DATASET_SIZE); do
run_check $SUDO_HELPER touch 
$dirpath/$dataset_type.$num
-   run_check $SUDO_HELPER ln -s 
$dirpath/$dataset_type.$num $dirpath/slink.$num
+   run_check $SUDO_HELPER cd $dirpath && ln -s 
$dataset_type.$num $dirpath/slink.$num && cd /
done
;;
 
@@ -71,12 +71,24 @@ generate_dataset() {
run_check $SUDO_HELPER setfattr -n user.foo -v 
bar$num $dirpath/$dataset_type.$num
done
;;
+   fifo)
+   for num in $(seq 1 $DATASET_SIZE); do
+   run_check $SUDO_HELPER mkfifo 
$dirpath/$dataset_type.$num
+   done
+   ;;
+   slow_symlink)
+   for num in $(seq 1 $DATASET_SIZE); do
+   fname64=`date +%s | sha256sum | cut -f1 -d'-'`
+   run_check $SUDO_HELPER touch $dirpath/$fname64
+   run_check $SUDO_HELPER ln -s $dirpath/$fname64 
$dirpath/slow_slink.$num
+   done
+   ;;
esac
 }
 
 populate_fs() {
 
-for dataset_type in 'small' 'hardlink' 'symlink' 'brokenlink' 'perm' 
'sparse' 'acls'; do
+for dataset_type in 'small' 'hardlink' 'fast_symlink' 'brokenlink' 
'perm' 'sparse' 'acls' 'fifo' 'slow_symlink'; do
generate_dataset "$dataset_type"
done
 }
-- 
1.9.3

--
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]btrfs-progs: Post btrfs-convert verify permissions and acls

2016-09-05 Thread Lakshmipathi.G
Signed-off-by: Lakshmipathi.G <lakshmipath...@giis.co.in>
---
 tests/common.convert | 95 +++-
 1 file changed, 94 insertions(+), 1 deletion(-)

diff --git a/tests/common.convert b/tests/common.convert
index 4e3d49c..67c99b1 100644
--- a/tests/common.convert
+++ b/tests/common.convert
@@ -123,6 +123,38 @@ convert_test_gen_checksums() {
count=1 >/dev/null 2>&1
run_check_stdout $SUDO_HELPER find $TEST_MNT -type f ! -name 'image' 
-exec md5sum {} \+ > "$CHECKSUMTMP"
 }
+# list $TEST_MNT data set file permissions.
+# $1: path where the permissions will be stored
+convert_test_perm() {
+   local PERMTMP
+   PERMTMP="$1"
+   FILES_LIST=$(mktemp --tmpdir btrfs-progs-convert.fileslistXX)
+
+   run_check $SUDO_HELPER dd if=/dev/zero of=$TEST_MNT/test bs=$nodesize \
+   count=1 >/dev/null 2>&1
+   run_check_stdout $SUDO_HELPER find $TEST_MNT -type f ! -name 'image' 
-fprint $FILES_LIST
+   #Fix directory entries order.
+   sort $FILES_LIST -o $FILES_LIST
+   for file in `cat $FILES_LIST` ;do
+   run_check_stdout $SUDO_HELPER getfacl --absolute-names $file >> 
"$PERMTMP"
+   done
+   rm $FILES_LIST
+}
+# list acls of files on $TEST_MNT
+# $1: path where the acls will be stored
+convert_test_acl() {
+   local ACLSTMP
+   ACLTMP="$1"
+   FILES_LIST=$(mktemp --tmpdir btrfs-progs-convert.fileslistXX)
+
+   run_check_stdout $SUDO_HELPER find $TEST_MNT/acls -type f -fprint 
$FILES_LIST
+   #Fix directory entries order.
+   sort $FILES_LIST -o $FILES_LIST
+   for file in `cat $FILES_LIST`;do
+   run_check_stdout $SUDO_HELPER getfattr --absolute-names -d 
$file >> "$ACLTMP"
+   done
+   rm $FILES_LIST
+}
 
 # do conversion with given features and nodesize, fsck afterwards
 # $1: features, argument of -O, can be empty
@@ -133,15 +165,68 @@ convert_test_do_convert() {
run_check $TOP/btrfs-show-super -Ffa $TEST_DEV
 }
 
+# post conversion check, verify file permissions.
+# $1: file with ext permissions.
+convert_test_post_check_permissions() {
+   local EXT_PERMTMP
+   local BTRFS_PERMTMP
+
+   EXT_PERMTMP="$1"
+   BTRFS_PERMTMP=$(mktemp --tmpdir btrfs-progs-convert.permXX)
+   convert_test_perm "$BTRFS_PERMTMP"
+
+   btrfs_perm=`md5sum $BTRFS_PERMTMP | cut -f1 -d' '`
+   ext_perm=`md5sum $EXT_PERMTMP | cut -f1 -d' '`
+
+   if [ "$btrfs_perm" != "$ext_perm" ];
+   then
+   btrfs_perm_file=`md5sum $BTRFS_PERMTMP | cut -f2 -d' '`
+   ext_perm_file=`md5sum $EXT_PERMTMP | cut -f2 -d' '`
+   _fail "file permission failed. Mismatched 
BTRFS:$btrfs_perm_file:$btrfs_perm EXT:$ext_perm_file:$ext_perm"
+   fi
+
+   rm $BTRFS_PERMTMP
+}
+# post conversion check, compare BTRFS file acls against EXT.
+# $1: file with ext acls.
+convert_test_post_check_acl() {
+   local EXT_ACLTMP
+   local BTRFS_ACLTMP
+
+   EXT_ACLTMP="$1"
+   BTRFS_ACLTMP=$(mktemp --tmpdir btrfs-progs-convert.aclsXXX)
+   convert_test_acl "$BTRFS_ACLTMP"
+
+   btrfs_acl=`md5sum $BTRFS_ACLTMP | cut -f1 -d' '`
+   ext_acl=`md5sum $EXT_ACLTMP | cut -f1 -d' '`
+
+   if [ "$btrfs_acl" != "$ext_acl" ]
+   then
+   btrfs_acl_file=`md5sum $BTRFS_ACLTMP | cut -f2 -d' '`
+   ext_acl_file=`md5sum $EXT_ACLTMP | cut -f2 -d' '`
+   _fail "file acl failed. Mismatched 
BTRFS:$btrfs_acl_file:$btrfs_acl EXT:$ext_acl_file:$ext_acl"
+   fi
+
+   rm $BTRFS_ACLTMP
+}
 # post conversion checks, verify md5sums
 # $1: file with checksums
+# $2: file with permissions.
+# $3: file with acl entries.
 convert_test_post_check() {
local CHECKSUMTMP
+   local EXT_PERMTMP
+   local EXT_ACLTMP
+
CHECKSUMTMP="$1"
+   EXT_PERMTMP="$2"
+   EXT_ACLTMP="$3"
 
run_check_mount_test_dev
run_check_stdout $SUDO_HELPER md5sum -c "$CHECKSUMTMP" |
grep -q 'FAILED' && _fail "file validation failed"
+   convert_test_post_check_permissions "$EXT_PERMTMP"
+   convert_test_post_check_acl "$EXT_ACLTMP"
run_check_umount_test_dev
 }
 
@@ -161,6 +246,8 @@ convert_test() {
local nodesize
local msg
local CHECKSUMTMP
+   local EXT_PERMTMP
+   local EXT_ACLTMP
 
features="$1"
msg="$2"
@@ -170,13 +257,19 @@ convert_test() {
convert_test_prep_fs "$@"
populate_fs
CHECKSUMTMP=$(mktemp --tmpdir btrfs-progs-convert.XX)
+   EXT_PERMTMP=$(mktemp --tmpdir btrfs-progs-convert.permXX)
+   EXT_ACLTMP=$(mktem

[PATCH][btrfs-progs] populate fs with small dataset for convert-tests

2016-03-08 Thread Lakshmipathi.G
Signed-off-by: Lakshmipathi.G <lakshmipath...@giis.co.in>
---
 tests/convert-tests.sh | 84 +++---
 1 file changed, 80 insertions(+), 4 deletions(-)

diff --git a/tests/convert-tests.sh b/tests/convert-tests.sh
index 0bfb41f..c1f3de0 100644
--- a/tests/convert-tests.sh
+++ b/tests/convert-tests.sh
@@ -10,16 +10,91 @@ LANG=C
 SCRIPT_DIR=$(dirname $(readlink -f $0))
 TOP=$(readlink -f $SCRIPT_DIR/../)
 RESULTS="$TOP/tests/convert-tests-results.txt"
+DATASET_SIZE="50" # how many files to create.
 
 source $TOP/tests/common
 
 rm -f $RESULTS
 
 setup_root_helper
-prepare_test_dev 256M
+prepare_test_dev 512M
 
 CHECKSUMTMP=$(mktemp --tmpdir btrfs-progs-convert.XX)
 
+generate_dataset() {
+
+   dataset_type="$1"
+   dirpath=$TEST_MNT/$dataset_type
+   mkdir -p $dirpath
+
+   case $dataset_type in
+   small)
+   for num in $(seq 1 $DATASET_SIZE);do
+   run_check $SUDO_HELPER dd if=/dev/urandom 
of=$dirpath/$dataset_type.$num bs=10K \
+   count=1 1>/dev/null 2>&1
+   done
+   ;;
+
+   hardlink)
+   for num in $(seq 1 $DATASET_SIZE);do
+   run_check $SUDO_HELPER touch 
$dirpath/$dataset_type.$num
+   run_check $SUDO_HELPER ln 
$dirpath/$dataset_type.$num $dirpath/hlink.$num
+   done
+   ;;
+
+   symlink)
+   for num in $(seq 1 $DATASET_SIZE);do
+   run_check $SUDO_HELPER touch 
$dirpath/$dataset_type.$num
+   run_check $SUDO_HELPER ln -s 
$dirpath/$dataset_type.$num $dirpath/slink.$num
+   done
+   ;;
+
+   brokenlink)
+   for num in $(seq 1 $DATASET_SIZE);do
+   run_check $SUDO_HELPER ln -s 
$dirpath/$dataset_type.$num $dirpath/blink.$num
+   done
+   ;;
+
+   perm)
+   for modes in $(seq 1 );do
+   if [[ "$modes" == *9* ]] || [[ "$modes" == *8* 
]]
+   then
+   continue;
+   else
+   run_check $SUDO_HELPER touch 
$dirpath/$dataset_type.$modes
+   run_check $SUDO_HELPER chmod $modes 
$dirpath/$dataset_type.$modes
+   fi
+   done
+   ;;
+
+   sparse)
+   for num in $(seq 1 $DATASET_SIZE);do
+   run_check $SUDO_HELPER dd if=/dev/urandom 
of=$dirpath/$dataset_type.$num bs=10K \
+   count=1 1>/dev/null 2>&1
+   run_check $SUDO_HELPER truncate -s 500K 
$dirpath/$dataset_type.$num
+   run_check $SUDO_HELPER dd if=/dev/urandom 
of=$dirpath/$dataset_type.$num bs=10K \
+   oflag=append conv=notrunc count=1 1>/dev/null 
2>&1
+   run_check $SUDO_HELPER truncate -s 800K 
$dirpath/$dataset_type.$num
+   done
+   ;;
+
+   acls)
+   for num in $(seq 1 $DATASET_SIZE);do
+   run_check $SUDO_HELPER touch 
$dirpath/$dataset_type.$num
+   run_check $SUDO_HELPER setfacl -m "u:root:x" 
$dirpath/$dataset_type.$num
+   run_check $SUDO_HELPER setfattr -n user.foo -v 
bar$num $dirpath/$dataset_type.$num
+   done
+   ;;
+   esac
+}
+
+populate_fs() {
+
+for dataset_type in 'small' 'hardlink' 'symlink' 'brokenlink' 'perm' 
'sparse' 'acls' ; do
+   generate_dataset "$dataset_type"
+   done
+}
+
 convert_test() {
local features
local nodesize
@@ -39,15 +114,16 @@ convert_test() {
# when test image is on NFS and would not be writable for root
run_check truncate -s 0 $TEST_DEV
# 256MB is the smallest acceptable btrfs image.
-   run_check truncate -s 256M $TEST_DEV
+   run_check truncate -s 512M $TEST_DEV
run_check $* -F $TEST_DEV
 
# create a file to check btrfs-convert can convert regular file
# correct
run_check_mount_test_dev
+   populate_fs;
run_check $SUDO_HELPER dd if=/dev/zero of=$TEST_MNT/test bs=$nodesize \
count=1 1>/dev/null 2>&1
-   run_check_stdout md5sum $TEST_MNT/test > $CHECKSUMTMP
+   run_check_stdout find $TEST_MNT -type f ! -name 'image' -ex

Re: [PATCH][btrfs-progs] Include file verification with convert-tests

2016-02-17 Thread Lakshmipathi.G
I think its a good idea to populate fs and verify them after conversion.
I'm not sure about existing tools, simply we can create local script to
this testsuite. Some thoughts on possible data set:

--
a) regular files
   - empty files (touch)
   - smaller files dd if=/dev/zero 
   - smaller files dd if=/dev/urandom 
   
b) directory
   - empty dirs.
   - dir with files 
   - dir depth upto N
   - dir with no file but lot of unlinked entries.
   
c) fast/slow symlink
   - to dir
   - to file

d) hardlink :
   - between files
   - between files in different sub-dir

e) fifo files and sparsefile, broken symlink

f) file and dir with special inode attribute: 
- immutable flag
- sticky bit etc

g) file/directory acls:
   - large no.of acls

--
fs images with debugfs tool:

a) an valid image with bad blocks.

b) corrupted images:
Ex: Create duplicate blocks and convert it & expect btrfs-check to catch issue?

Any thoughts on above list, suggestions/comments? thanks!


Cheers,
Lakshmipathi.G 
--
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: Pointers to Btrfs Testplan/Testcases

2016-02-01 Thread Lakshmipathi.G
I didn't know that xfstests covers more than xfs. Will look into their 
repo for btrfs specific cases. thanks for the response.

Cheers,
Lakshmipathi.G 
--
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


understanding csum tree

2015-11-12 Thread Lakshmipathi.G
Hi -

I trying to understand csum tree and its entries.

1) create a filenamed 'ab' with 100KB of data.  I can see csum entry for
this:

item 0 key (EXTENT_CSUM EXTENT_CSUM 4239360) itemoff 3895 itemsize 100

2) created another named 'zb1' with 100KB of data. I can't find csum
entry for this.Looks like item-0 is extended with csum of zb1.

item 0 key (EXTENT_CSUM EXTENT_CSUM 4239360) itemoff 3795 itemsize 200

If I need to read/print only the csum of 'zb1' file - how to achieve
that? thanks!

btrfs-debug-tree output : http://pastebin.com/tzKLX2ZU
after creating zb1 file : http://pastebin.com/WzjJuzFB

Cheers,
Lakshmipathi.G 

--
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] btrfs-progs: print root item's last_snapshot value.

2015-10-07 Thread Lakshmipathi.G


Include last_snapshot value in print_root(). With btrfs-debug-tree, it 
helps to identify whether its a snapshot-ed subvolume or not.

Signed-off-by: Lakshmipathi.G <lakshmipath...@giis.co.in>
---
 print-tree.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/print-tree.c b/print-tree.c
index dc1d276..7ddf400 100644
--- a/print-tree.c
+++ b/print-tree.c
@@ -481,12 +481,13 @@ static void print_root(struct extent_buffer *leaf, int 
slot)
memset(_item, 0, sizeof(root_item));
read_extent_buffer(leaf, _item, (unsigned long)ri, len);
 
-   printf("\t\troot data bytenr %llu level %d dirid %llu refs %u gen 
%llu\n",
+   printf("\t\troot data bytenr %llu level %d dirid %llu refs %u gen %llu 
lastsnap %llu\n",
(unsigned long long)btrfs_root_bytenr(_item),
btrfs_root_level(_item),
(unsigned long long)btrfs_root_dirid(_item),
btrfs_root_refs(_item),
-   (unsigned long long)btrfs_root_generation(_item));
+   (unsigned long long)btrfs_root_generation(_item),
+   (unsigned long long)btrfs_root_last_snapshot(_item));
 
if (root_item.generation == root_item.generation_v2) {
uuid_unparse(root_item.uuid, uuid_str);
-- 
1.8.3.1

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


<    1   2