[PATCH 05/12] Btrfc: sysfs: fix, check if device_dir_kobj is init before destroy

2015-02-01 Thread Anand Jain
Since the failure code in the btrfs_sysfs_add_one() can
call btrfs_sysfs_remove_one() even before device_dir_kobj
has been created we need to check if its null.

Signed-off-by: Anand Jain anand.j...@oracle.com
---
 fs/btrfs/sysfs.c | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index 15fead2..506f7e4 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -522,10 +522,12 @@ void btrfs_sysfs_remove_one(struct btrfs_fs_info *fs_info)
kobject_del(fs_info-space_info_kobj);
kobject_put(fs_info-space_info_kobj);
}
-   btrfs_kobj_rm_device(fs_info, NULL);
-   kobject_del(fs_info-device_dir_kobj);
-   kobject_put(fs_info-device_dir_kobj);
-   fs_info-device_dir_kobj = NULL;
+   if (fs_info-device_dir_kobj) {
+   btrfs_kobj_rm_device(fs_info, NULL);
+   kobject_del(fs_info-device_dir_kobj);
+   kobject_put(fs_info-device_dir_kobj);
+   fs_info-device_dir_kobj = NULL;
+   }
addrm_unknown_feature_attrs(fs_info, false);
sysfs_remove_group(fs_info-super_kobj, btrfs_feature_attr_group);
__btrfs_sysfs_remove_one(fs_info);
-- 
1.9.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


[PATCH 06/12] Btrfs: sysfs: reorder the kobject creations

2015-02-01 Thread Anand Jain
As of now the order in which the kobjects are created
at btrfs_sysfs_add_one() is..
 fsid
 features
 unknown features (dynamic features)
 devices.

Since we would move fsid and device kobject to fs_devices
from fs_info structure, this patch will reorder in which
the kobjects are created as below.
 fsid
 devices
 features
 unknown features (dynamic features)

And hence the btrfs_sysfs_remove_one() will follow the same
in reverse order. and the device kobject destroy now can
be moved into the function __btrfs_sysfs_remove_one()

Signed-off-by: Anand Jain anand.j...@oracle.com
---
 fs/btrfs/sysfs.c | 23 +--
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index 506f7e4..c3e7f06 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -510,6 +510,13 @@ static int addrm_unknown_feature_attrs(struct 
btrfs_fs_info *fs_info, bool add)
 
 static void __btrfs_sysfs_remove_one(struct btrfs_fs_info *fs_info)
 {
+   if (fs_info-device_dir_kobj) {
+   btrfs_kobj_rm_device(fs_info, NULL);
+   kobject_del(fs_info-device_dir_kobj);
+   kobject_put(fs_info-device_dir_kobj);
+   fs_info-device_dir_kobj = NULL;
+   }
+
kobject_del(fs_info-super_kobj);
kobject_put(fs_info-super_kobj);
wait_for_completion(fs_info-kobj_unregister);
@@ -522,12 +529,6 @@ void btrfs_sysfs_remove_one(struct btrfs_fs_info *fs_info)
kobject_del(fs_info-space_info_kobj);
kobject_put(fs_info-space_info_kobj);
}
-   if (fs_info-device_dir_kobj) {
-   btrfs_kobj_rm_device(fs_info, NULL);
-   kobject_del(fs_info-device_dir_kobj);
-   kobject_put(fs_info-device_dir_kobj);
-   fs_info-device_dir_kobj = NULL;
-   }
addrm_unknown_feature_attrs(fs_info, false);
sysfs_remove_group(fs_info-super_kobj, btrfs_feature_attr_group);
__btrfs_sysfs_remove_one(fs_info);
@@ -700,6 +701,12 @@ int btrfs_sysfs_add_one(struct btrfs_fs_info *fs_info)
if (error)
return error;
 
+   error = btrfs_kobj_add_device(fs_info, NULL);
+   if (error) {
+   __btrfs_sysfs_remove_one(fs_info);
+   return error;
+   }
+
error = sysfs_create_group(fs_info-super_kobj,
   btrfs_feature_attr_group);
if (error) {
@@ -711,10 +718,6 @@ int btrfs_sysfs_add_one(struct btrfs_fs_info *fs_info)
if (error)
goto failure;
 
-   error = btrfs_kobj_add_device(fs_info, NULL);
-   if (error)
-   goto failure;
-
fs_info-space_info_kobj = kobject_create_and_add(allocation,
  fs_info-super_kobj);
if (!fs_info-space_info_kobj) {
-- 
1.9.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


[PATCH 08/12] Btrfs: sysfs: introduce function btrfs_sysfs_add_fsid() to create sysfs fsid

2015-02-01 Thread Anand Jain
We need it in a seperate function so that it can be called from the
device discovery thread as well.

Signed-off-by: Anand Jain anand.j...@oracle.com
---
 fs/btrfs/sysfs.c | 15 ++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index c923e8b..f42d8fd 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -690,7 +690,12 @@ static struct dentry *btrfs_debugfs_root_dentry;
 /* Debugging tunables and exported data */
 u64 btrfs_debugfs_test;
 
-int btrfs_sysfs_add_one(struct btrfs_fs_info *fs_info)
+/*
+ * Can be called by the device discovery thread.
+ * And parent can be specified for seed device
+ */
+int btrfs_sysfs_add_fsid(struct btrfs_fs_info *fs_info,
+   struct kobject *parent)
 {
int error;
 
@@ -698,6 +703,14 @@ int btrfs_sysfs_add_one(struct btrfs_fs_info *fs_info)
fs_info-super_kobj.kset = btrfs_kset;
error = kobject_init_and_add(fs_info-super_kobj, btrfs_ktype, NULL,
 %pU, fs_info-fsid);
+   return error;
+}
+
+int btrfs_sysfs_add_one(struct btrfs_fs_info *fs_info)
+{
+   int error;
+
+   error = btrfs_sysfs_add_fsid(fs_info, NULL);
if (error)
return error;
 
-- 
1.9.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


[PATCH 12/12] Btrfs: sysfs: add pointer to access fs_info from fs_devices

2015-02-01 Thread Anand Jain
adds fs_info pointer with struct btrfs_fs_devices.

Signed-off-by: Anand Jain anand.j...@oracle.com
---
 fs/btrfs/sysfs.c   | 4 
 fs/btrfs/volumes.h | 1 +
 2 files changed, 5 insertions(+)

diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index ac15fbb..4b5bac6 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -530,6 +530,8 @@ static void btrfs_sysfs_remove_fsid(struct btrfs_fs_devices 
*fs_devs)
 
 void btrfs_sysfs_remove_one(struct btrfs_fs_info *fs_info)
 {
+   fs_info-fs_devices-fs_info = NULL;
+
if (fs_info-space_info_kobj) {
sysfs_remove_files(fs_info-space_info_kobj, allocation_attrs);
kobject_del(fs_info-space_info_kobj);
@@ -729,6 +731,8 @@ int btrfs_sysfs_add_one(struct btrfs_fs_info *fs_info)
struct btrfs_fs_devices *fs_devs = fs_info-fs_devices;
struct kobject *super_kobj = fs_devs-super_kobj;
 
+   fs_devs-fs_info = fs_info;
+
error = btrfs_sysfs_add_fsid(fs_devs, NULL);
if (error)
return error;
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
index a1df344..40c38ab 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -254,6 +254,7 @@ struct btrfs_fs_devices {
 */
int rotating;
 
+   struct btrfs_fs_info *fs_info;
/* sysfs kobjects */
struct kobject super_kobj;
struct kobject *device_dir_kobj;
-- 
1.9.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


[PATCH] Btrfs-progs: add regression tests for sysfs contents during btrfs device management

2015-02-01 Thread Anand Jain
This contains a series of btrfs device operations and at each operation
the btrfs sysfs contents are logged.  This helps to check if the patch
is affecting any of the btrfs sysfs contents.

OR This script can be used to test the only the device operations.

as of now there are 32 test cases

Signed-off-by: Anand Jain anand.j...@oracle.com
---
 tests/test-btrfs-devmgt.sh | 863 +
 1 file changed, 863 insertions(+)
 create mode 100755 tests/test-btrfs-devmgt.sh

diff --git a/tests/test-btrfs-devmgt.sh b/tests/test-btrfs-devmgt.sh
new file mode 100755
index 000..2f75200
--- /dev/null
+++ b/tests/test-btrfs-devmgt.sh
@@ -0,0 +1,863 @@
+# * GNU General Public License v2. Copyright Oracle 2015
+
+
+# Series of btrfs device operation test cases.
+#
+
+# sysfs: test
+# sysfs contents are taken at reasonable places (but you may disable it).
+# So to compare with the next iteration with your kernel patch. so
+# you can check for the sysfs changes by running diff of TMP_FILE(s)
+
+# Changelog:
+# v1.0 init asj
+
+
+   #When you change something related to device
+   #remember to test on btrfs boot separately
+ #test0: btrfs boot test
+
+   #Replace:
+ #test1: raid1, replace normal
+ #test2: raid1, replace missing
+ #test3: NOP
+ #test4: raid1, replace missing, replace normal
+ #test5: raid1, replace dev2, replace dev1
+
+   #Add sprout, replace:
+ #test6: add sprout, replace seed
+ #test7: raid1 seed, add sprout, replace seed, replace sprout
+ #test8: 3 level nested seeds, add sprout, replace mid level seed
+ #test9: raid1, degraded seed mount, add sprout, replace missing, replace non 
missing seed
+ #test10: add sprout, replace sprout
+ #test11: raid1 seed, add sprout, replace sprout, replace sprout again
+ #test12: 3 level nested seeds, add sprout, replace sprout
+ #test13: degraded raid1 seed, add sprout, replace sprout
+
+   #Mount sprout, replace:
+ #test14: NOP
+ #test15: mount sprout, replace sprout
+ #test16: mount sprout, replace seed
+ #test17: Raid1, mount sprout, replace sprout
+ #test18: Raid1, mount sprout, replace seed
+ #test19: Raid1 degraded, mount sprout, replace sprout
+ #test20: Raid1 degraded, mount sprout, replace missing
+ #test21: 3 level nested seeds, mount sprout, replace mid level seed
+
+   #seed sprout test:
+ #test22: mount sprout, mount seed
+ #test23: clean, mount -o device sprout
+ #test24: raid1, mount sprout
+ #test25: clean, scan, mount sprout
+ #test26: raid1, clean, mount -o device sprout
+ #test26: raid1, clean, scan, mount sprout
+
+   #dev add del test:
+ #test27: dev add
+ #test28: dev del
+
+   #dev scan test:
+ #test29: scan mount
+ #test30: use -o mount
+
+   #subvol mount test:
+ #test31: mount, mount subvol
+
+   #remount test:
+ #test32: mount, remount
+
+
+
+
+# Devices are hard coded. sorry
+
+DEV0=/dev/sdb
+x=0
+if [ $x -eq 1 ]; then
+DEV1=/dev/sdc
+DEV2=/dev/sdd
+DEV3=/dev/sde
+DEV4=/dev/sdf
+DEV5=/dev/sdg
+else
+DEV1=/dev/sdd
+DEV2=/dev/sde
+DEV3=/dev/sdf
+DEV4=/dev/sdg
+DEV5=/dev/sdc
+fi
+
+TEST_FSID=1c52f894-0ead-43d6-847a-d42359f78370
+
+#Enable or disable sysfs data collection by set/unset the below
+#TMP_FILE=''
+TMP_FILE=`mktemp`
+
+ent_cont()
+{
+   echo -n Enter to continue: 
+   #read
+   echo wait for input is disabled, uncomment above to wait.
+}
+
+erase()
+{
+   for i in $DEV0 $DEV1 $DEV2 $DEV3 $DEV4 $DEV5; do wipefs -a $i  
/dev/null; done
+}
+
+clean()
+{
+   modprobe -r btrfs  modprobe btrfs
+}
+
+collect_sysfs()
+{
+   # see above to disable sysfs data collection
+   [[ -z $TMP_FILE ]]  return
+
+   echo  $1 -  $TMP_FILE
+   find /sys/fs/btrfs -type f -exec cat {} \; -print  $TMP_FILE
+}
+
+_mkfs.btrfs()
+{
+   mkfs.btrfs $*  /dev/null
+}
+
+
+test1()
+{
+   TEST=test1
+   erase
+   echo -e \n$TEST
+_mkfs.btrfs -L $TEST -U $TEST_FSID -d raid1 -m raid1 $DEV1 $DEV2 -f
+   collect_sysfs $TEST
+mount $DEV2 /btrfs
+   collect_sysfs $TEST
+btrfs rep start -B $DEV2 $DEV3 /btrfs -f
+   collect_sysfs $TEST
+umount /btrfs
+   collect_sysfs $TEST
+   clean
+   ent_cont
+}
+
+test2()
+{
+   TEST=test2
+   erase
+   echo -e \n$TEST
+_mkfs.btrfs -L $TEST -U $TEST_FSID -d raid1 -m raid1 $DEV1 $DEV2 -f
+   clean
+mount -o degraded $DEV1 /btrfs
+   collect_sysfs $TEST
+btrfs rep start -B 2 $DEV3 /btrfs -f
+   collect_sysfs $TEST
+umount /btrfs
+   collect_sysfs $TEST
+   clean
+   ent_cont
+}
+
+test4()
+{
+   TEST=test4
+   erase
+   echo -e \n$TEST
+_mkfs.btrfs -L $TEST -U $TEST_FSID -d raid1 -m raid1 $DEV1 $DEV2 -f
+   clean
+mount -o degraded $DEV1 /btrfs
+   collect_sysfs $TEST
+btrfs rep start -B 2 $DEV3 /btrfs -f
+   collect_sysfs $TEST
+btrfs rep start -B $DEV1 $DEV4 /btrfs -f
+   collect_sysfs $TEST
+umount /btrfs
+   

[PATCH 07/12] Btrfs: sysfs: rename __btrfs_sysfs_remove_one to btrfs_sysfs_remove_fsid

2015-02-01 Thread Anand Jain
Signed-off-by: Anand Jain anand.j...@oracle.com
---
 fs/btrfs/sysfs.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index c3e7f06..c923e8b 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -508,7 +508,7 @@ static int addrm_unknown_feature_attrs(struct btrfs_fs_info 
*fs_info, bool add)
return 0;
 }
 
-static void __btrfs_sysfs_remove_one(struct btrfs_fs_info *fs_info)
+static void btrfs_sysfs_remove_fsid(struct btrfs_fs_info *fs_info)
 {
if (fs_info-device_dir_kobj) {
btrfs_kobj_rm_device(fs_info, NULL);
@@ -531,7 +531,7 @@ void btrfs_sysfs_remove_one(struct btrfs_fs_info *fs_info)
}
addrm_unknown_feature_attrs(fs_info, false);
sysfs_remove_group(fs_info-super_kobj, btrfs_feature_attr_group);
-   __btrfs_sysfs_remove_one(fs_info);
+   btrfs_sysfs_remove_fsid(fs_info);
 }
 
 const char * const btrfs_feature_set_names[3] = {
@@ -703,14 +703,14 @@ int btrfs_sysfs_add_one(struct btrfs_fs_info *fs_info)
 
error = btrfs_kobj_add_device(fs_info, NULL);
if (error) {
-   __btrfs_sysfs_remove_one(fs_info);
+   btrfs_sysfs_remove_fsid(fs_info);
return error;
}
 
error = sysfs_create_group(fs_info-super_kobj,
   btrfs_feature_attr_group);
if (error) {
-   __btrfs_sysfs_remove_one(fs_info);
+   btrfs_sysfs_remove_fsid(fs_info);
return error;
}
 
-- 
1.9.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


[PATCH 11/12] Btrfs: sysfs: move super_kobj and device_dir_kobj from fs_info to btrfs_fs_devices

2015-02-01 Thread Anand Jain
This patch will provide a framework and help to create attributes
from the structure btrfs_fs_devices which are available even before
fs_info is created. So by moving the parent kobject super_kobj from
fs_info to btrfs_fs_devices, it will help to create attributes
from the btrfs_fs_devices as well.

Patches on top of this patch now will be able to create the
sys/fs/btrfs/fsid kobject and attributes from btrfs_fs_devices
when devices are scanned and registered to the kernel.

Just to note, this does not change any of the existing btrfs sysfs
external kobject names and its attributes and not even the life
cycle of them. Changes are internal only. And to ensure the same,
this path has been tested with various device operations and,
checking and comparing the sysfs kobjects and attributes with
sysfs kobject and attributes with out this patch, and they remain
same.

Signed-off-by: Anand Jain anand.j...@oracle.com
---
 fs/btrfs/ctree.h   |  3 --
 fs/btrfs/sysfs.c   | 88 ++
 fs/btrfs/volumes.c |  3 +-
 fs/btrfs/volumes.h |  5 
 4 files changed, 56 insertions(+), 43 deletions(-)

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 85c697d..ef66d13 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -1584,10 +1584,7 @@ struct btrfs_fs_info {
struct task_struct *cleaner_kthread;
int thread_pool_size;
 
-   struct kobject super_kobj;
struct kobject *space_info_kobj;
-   struct kobject *device_dir_kobj;
-   struct completion kobj_unregister;
int do_barriers;
int closing;
int log_root_recovering;
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index 2cb4c69..ac15fbb 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -33,6 +33,7 @@
 #include volumes.h
 
 static inline struct btrfs_fs_info *to_fs_info(struct kobject *kobj);
+static inline struct btrfs_fs_devices *to_fs_devs(struct kobject *kobj);
 
 static u64 get_features(struct btrfs_fs_info *fs_info,
enum btrfs_feature_set set)
@@ -438,10 +439,10 @@ static const struct attribute *btrfs_attrs[] = {
 
 static void btrfs_release_super_kobj(struct kobject *kobj)
 {
-   struct btrfs_fs_info *fs_info = to_fs_info(kobj);
+   struct btrfs_fs_devices *fs_devs = to_fs_devs(kobj);
 
-   memset(fs_info-super_kobj, 0, sizeof(struct kobject));
-   complete(fs_info-kobj_unregister);
+   memset(fs_devs-super_kobj, 0, sizeof(struct kobject));
+   complete(fs_devs-kobj_unregister);
 }
 
 static struct kobj_type btrfs_ktype = {
@@ -449,11 +450,18 @@ static struct kobj_type btrfs_ktype = {
.release= btrfs_release_super_kobj,
 };
 
+static inline struct btrfs_fs_devices *to_fs_devs(struct kobject *kobj)
+{
+   if (kobj-ktype != btrfs_ktype)
+   return NULL;
+   return container_of(kobj, struct btrfs_fs_devices, super_kobj);
+}
+
 static inline struct btrfs_fs_info *to_fs_info(struct kobject *kobj)
 {
if (kobj-ktype != btrfs_ktype)
return NULL;
-   return container_of(kobj, struct btrfs_fs_info, super_kobj);
+   return to_fs_devs(kobj)-fs_info;
 }
 
 #define NUM_FEATURE_BITS 64
@@ -494,12 +502,12 @@ static int addrm_unknown_feature_attrs(struct 
btrfs_fs_info *fs_info, bool add)
attrs[0] = fa-kobj_attr.attr;
if (add) {
int ret;
-   ret = sysfs_merge_group(fs_info-super_kobj,
+   ret = 
sysfs_merge_group(fs_info-fs_devices-super_kobj,
agroup);
if (ret)
return ret;
} else
-   sysfs_unmerge_group(fs_info-super_kobj,
+   
sysfs_unmerge_group(fs_info-fs_devices-super_kobj,
agroup);
}
 
@@ -507,18 +515,17 @@ static int addrm_unknown_feature_attrs(struct 
btrfs_fs_info *fs_info, bool add)
return 0;
 }
 
-static void btrfs_sysfs_remove_fsid(struct btrfs_fs_info *fs_info)
+static void btrfs_sysfs_remove_fsid(struct btrfs_fs_devices *fs_devs)
 {
-   if (fs_info-device_dir_kobj) {
-   btrfs_kobj_rm_device(fs_info, NULL);
-   kobject_del(fs_info-device_dir_kobj);
-   kobject_put(fs_info-device_dir_kobj);
-   fs_info-device_dir_kobj = NULL;
+   if (fs_devs-device_dir_kobj) {
+   kobject_del(fs_devs-device_dir_kobj);
+   kobject_put(fs_devs-device_dir_kobj);
+   fs_devs-device_dir_kobj = NULL;
}
 
-   kobject_del(fs_info-super_kobj);
-   kobject_put(fs_info-super_kobj);
-   wait_for_completion(fs_info-kobj_unregister);
+   kobject_del(fs_devs-super_kobj);
+   kobject_put(fs_devs-super_kobj);
+   

[PATCH 03/12] Btrfs: sysfs: fix, undo sysfs device links

2015-02-01 Thread Anand Jain
Theoritically need to remove the device links attributes, but since its entire 
device
kobject was removed, so there wasn't any issue of about it. Just do it nicely.

Signed-off-by: Anand Jain anand.j...@oracle.com
---
 fs/btrfs/sysfs.c | 17 +
 1 file changed, 17 insertions(+)

diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index 68dcd17..adfac3e 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -522,6 +522,7 @@ void btrfs_sysfs_remove_one(struct btrfs_fs_info *fs_info)
kobject_del(fs_info-space_info_kobj);
kobject_put(fs_info-space_info_kobj);
}
+   btrfs_kobj_rm_device(fs_info, NULL);
kobject_del(fs_info-device_dir_kobj);
kobject_put(fs_info-device_dir_kobj);
addrm_unknown_feature_attrs(fs_info, false);
@@ -604,6 +605,8 @@ static void init_feature_attrs(void)
}
 }
 
+/* when one_device is NULL, it removes all device links */
+
 int btrfs_kobj_rm_device(struct btrfs_fs_info *fs_info,
struct btrfs_device *one_device)
 {
@@ -621,6 +624,20 @@ int btrfs_kobj_rm_device(struct btrfs_fs_info *fs_info,
disk_kobj-name);
}
 
+   if (one_device)
+   return 0;
+
+   list_for_each_entry(one_device,
+   fs_info-fs_devices-devices, dev_list) {
+   if (!one_device-bdev)
+   continue;
+   disk = one_device-bdev-bd_part;
+   disk_kobj = part_to_dev(disk)-kobj;
+
+   sysfs_remove_link(fs_info-device_dir_kobj,
+   disk_kobj-name);
+   }
+
return 0;
 }
 
-- 
1.9.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


[PATCH 09/12] Btrfs: sysfs: let default_attrs be separate from the kset

2015-02-01 Thread Anand Jain
As of now btrfs_attrs are provided using the default_attrs through
the kset. Separate them and create the default_attrs using the
sysfs_create_files instead. By doing this we will have the
flexibility that device discovery thread could create fsid
kobject.

Signed-off-by: Anand Jain anand.j...@oracle.com
---
 fs/btrfs/sysfs.c | 12 
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index f42d8fd..5208a49 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -428,7 +428,7 @@ static ssize_t btrfs_clone_alignment_show(struct kobject 
*kobj,
 
 BTRFS_ATTR(clone_alignment, btrfs_clone_alignment_show);
 
-static struct attribute *btrfs_attrs[] = {
+static const struct attribute *btrfs_attrs[] = {
BTRFS_ATTR_PTR(label),
BTRFS_ATTR_PTR(nodesize),
BTRFS_ATTR_PTR(sectorsize),
@@ -447,7 +447,6 @@ static void btrfs_release_super_kobj(struct kobject *kobj)
 static struct kobj_type btrfs_ktype = {
.sysfs_ops  = kobj_sysfs_ops,
.release= btrfs_release_super_kobj,
-   .default_attrs  = btrfs_attrs,
 };
 
 static inline struct btrfs_fs_info *to_fs_info(struct kobject *kobj)
@@ -531,6 +530,7 @@ void btrfs_sysfs_remove_one(struct btrfs_fs_info *fs_info)
}
addrm_unknown_feature_attrs(fs_info, false);
sysfs_remove_group(fs_info-super_kobj, btrfs_feature_attr_group);
+   sysfs_remove_files(fs_info-super_kobj, btrfs_attrs);
btrfs_sysfs_remove_fsid(fs_info);
 }
 
@@ -720,13 +720,17 @@ int btrfs_sysfs_add_one(struct btrfs_fs_info *fs_info)
return error;
}
 
-   error = sysfs_create_group(fs_info-super_kobj,
-  btrfs_feature_attr_group);
+   error = sysfs_create_files(fs_info-super_kobj, btrfs_attrs);
if (error) {
btrfs_sysfs_remove_fsid(fs_info);
return error;
}
 
+   error = sysfs_create_group(fs_info-super_kobj,
+  btrfs_feature_attr_group);
+   if (error)
+   goto failure;
+
error = addrm_unknown_feature_attrs(fs_info, true);
if (error)
goto failure;
-- 
1.9.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


[PATCH 10/12] Btrfs: sysfs: separate device kobject and its attribute creation

2015-02-01 Thread Anand Jain
Separate device kobject and its attribute creation so that device
kobject can be created from the device discovery thread.

Signed-off-by: Anand Jain anand.j...@oracle.com
---
 fs/btrfs/sysfs.c | 21 +++--
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index 5208a49..2cb4c69 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -645,13 +645,8 @@ int btrfs_kobj_rm_device(struct btrfs_fs_info *fs_info,
return 0;
 }
 
-int btrfs_kobj_add_device(struct btrfs_fs_info *fs_info,
-   struct btrfs_device *one_device)
+int btrfs_sysfs_add_device(struct btrfs_fs_info *fs_info)
 {
-   int error = 0;
-   struct btrfs_fs_devices *fs_devices = fs_info-fs_devices;
-   struct btrfs_device *dev;
-
if (!fs_info-device_dir_kobj)
fs_info-device_dir_kobj = kobject_create_and_add(devices,
fs_info-super_kobj);
@@ -659,6 +654,20 @@ int btrfs_kobj_add_device(struct btrfs_fs_info *fs_info,
if (!fs_info-device_dir_kobj)
return -ENOMEM;
 
+   return 0;
+}
+
+int btrfs_kobj_add_device(struct btrfs_fs_info *fs_info,
+   struct btrfs_device *one_device)
+{
+   int error = 0;
+   struct btrfs_fs_devices *fs_devices = fs_info-fs_devices;
+   struct btrfs_device *dev;
+
+   error = btrfs_sysfs_add_device(fs_info);
+   if (error)
+   return error;
+
list_for_each_entry(dev, fs_devices-devices, dev_list) {
struct hd_struct *disk;
struct kobject *disk_kobj;
-- 
1.9.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


[PATCH 04/12] Btrfs: sysfs: fix, kobject pointer clean up needed after kobject release

2015-02-01 Thread Anand Jain
The sysfs clean up self test like in the below code fails, since
fs_info-device_dir_kobject still points to its stale kobject.
Reseting this pointer will help to fix this.

open_ctree()
{

ret = btrfs_sysfs_add_one(fs_info);
::
+   btrfs_sysfs_remove_one(fs_info);
+   ret = btrfs_sysfs_add_one(fs_info);
+   if (ret) {
+   pr_err(BTRFS: failed to init sysfs interface: %d\n, ret);
+   goto fail_block_groups;
+   }

Signed-off-by: Anand Jain anand.j...@oracle.com
---
 fs/btrfs/sysfs.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index adfac3e..15fead2 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -525,6 +525,7 @@ void btrfs_sysfs_remove_one(struct btrfs_fs_info *fs_info)
btrfs_kobj_rm_device(fs_info, NULL);
kobject_del(fs_info-device_dir_kobj);
kobject_put(fs_info-device_dir_kobj);
+   fs_info-device_dir_kobj = NULL;
addrm_unknown_feature_attrs(fs_info, false);
sysfs_remove_group(fs_info-super_kobj, btrfs_feature_attr_group);
__btrfs_sysfs_remove_one(fs_info);
-- 
1.9.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


[PATCH 01/12] Btrfs: sysfs: fix, btrfs_release_super_kobj() should to clean up the kobject data

2015-02-01 Thread Anand Jain
The following test case fails indicating that, thread tried to init an 
initialized object.

kernel: [232104.016513] kobject (880006c1c980): tried to init an 
initialized object, something is seriously wrong.

btrfs_sysfs_remove_one() self test code:

open_tree()
{
 ::
ret = btrfs_sysfs_add_one(fs_info);
if (ret) {
  pr_err(BTRFS: failed to init sysfs interface: %d\n, ret);
goto fail_block_groups;
}
+   btrfs_sysfs_remove_one(fs_info);
+   ret = btrfs_sysfs_add_one(fs_info);
+   if (ret) {
+   pr_err(BTRFS: failed to init sysfs interface: %d\n, ret);
+   goto fail_block_groups;
+   }

cleaning up the unregistered kobject fixes this.

Signed-off-by: Anand Jain anand.j...@oracle.com
---
 fs/btrfs/sysfs.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index 92db3f6..68dcd17 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -439,6 +439,8 @@ static struct attribute *btrfs_attrs[] = {
 static void btrfs_release_super_kobj(struct kobject *kobj)
 {
struct btrfs_fs_info *fs_info = to_fs_info(kobj);
+
+   memset(fs_info-super_kobj, 0, sizeof(struct kobject));
complete(fs_info-kobj_unregister);
 }
 
-- 
1.9.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


[PATCH 00/12] provide frame work so that sysfs attributs from the fs_devices can be added

2015-02-01 Thread Anand Jain
This patch set will provide a framework and help to create attributes
from the structure btrfs_fs_devices which are available even before
fs_info is created. So by moving the parent kobject super_kobj from
fs_info to btrfs_fs_devices, it will help to create attributes
from the btrfs_fs_devices as well.

Just to note, this does not change any of the existing btrfs sysfs
external kobject names and its attributes and not even the life
cycle of them. Changes are internal only. And to ensure the same,
this path has been tested with various device operations and,
checking and comparing the sysfs kobjects and attributes with
sysfs kobject and attributes with out this patch, and they remain
same. These test cases are added to the progs as test-btrfs-devmgt.sh,
its patch is below as well.


Anand Jain (12):
  Btrfs: sysfs: fix, btrfs_release_super_kobj() should to clean up the
kobject data
  Btrfs: sysfs: fix, fs_info kobject_unregister has init_completion()
twice
  Btrfs: sysfs: fix, undo sysfs device links
  Btrfs: sysfs: fix, kobject pointer clean up needed after kobject
release
  Btrfc: sysfs: fix, check if device_dir_kobj is init before destroy
  Btrfs: sysfs: reorder the kobject creations
  Btrfs: sysfs: rename __btrfs_sysfs_remove_one to
btrfs_sysfs_remove_fsid
  Btrfs: sysfs: introduce function btrfs_sysfs_add_fsid() to create
sysfs fsid
  Btrfs: sysfs: let default_attrs be separate from the kset
  Btrfs: sysfs: separate device kobject and its attribute creation
  Btrfs: sysfs: move super_kobj and device_dir_kobj from fs_info to
btrfs_fs_devices
  Btrfs: sysfs: add pointer to access fs_info from fs_devices

 fs/btrfs/ctree.h   |   3 --
 fs/btrfs/disk-io.c |   1 -
 fs/btrfs/sysfs.c   | 133 +++--
 fs/btrfs/volumes.c |   3 +-
 fs/btrfs/volumes.h |   6 +++
 5 files changed, 107 insertions(+), 39 deletions(-)


Anand Jain (1):
  Btrfs-progs: add regression tests for sysfs contents during btrfs
device management

 tests/test-btrfs-devmgt.sh | 863 +
 1 file changed, 863 insertions(+)
 create mode 100755 tests/test-btrfs-devmgt.sh
-- 
1.9.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


[PATCH 02/12] Btrfs: sysfs: fix, fs_info kobject_unregister has init_completion() twice

2015-02-01 Thread Anand Jain
kobject_unregister is to handle the release of the kobject,
its completion init is being called in btrfs_sysfs_add_one(),
so we don't have to do the same in the open_ctree() again.

Signed-off-by: Anand Jain anand.j...@oracle.com
---
 fs/btrfs/disk-io.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 612d46e..2e076b2 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -2247,7 +2247,6 @@ int open_ctree(struct super_block *sb,
mutex_init(fs_info-delalloc_root_mutex);
seqlock_init(fs_info-profiles_lock);
 
-   init_completion(fs_info-kobj_unregister);
INIT_LIST_HEAD(fs_info-dirty_cowonly_roots);
INIT_LIST_HEAD(fs_info-space_info);
INIT_LIST_HEAD(fs_info-tree_mod_seq_list);
-- 
1.9.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


security.capability xattr missing after btrfs send/receive

2015-02-01 Thread Jan Andres
I found that the security.capability xattr gets lost when cloning a
subvolume via btrfs send | btrfs receive. This is easy to reproduce
(currently on 3.19.0-rc6, x86_64, with btrfs-progs 3.18.1):

Have two btrfs file systems, /fs1 and /fs2.

# btrfs sub create /fs1/test
# touch /fs1/test/foo
# setcap cap_net_admin+ep /fs1/test/foo
# getcap /fs1/test/foo
/fs1/test/foo = cap_net_admin+ep
# btrfs prop set /fs1/test ro true
# btrfs send /fs1/test | btrfs receive /fs2
# getcap /fs2/test/foo
[reports nothing]


The cause of the problem seems to be that BTRFS_SEND_C_SET_XATTR comes
before BTRFS_SEND_C_CHMOD in the send stream, so that the receiving end
will first correctly restore all the xattrs of the file, and after that,
perform an lchown() which will cause the kernel to reset the
file's capabilities.

I don't know how to fix this correctly (especially in the case of
incremental sends), so I don't have a patch, but figured it might be
useful to share what I found.

Regards,
Jan

-- 
Jan Andres jand...@gmx.net
--
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: security.capability xattr missing after btrfs send/receive

2015-02-01 Thread Juan Orti
El dom, 01-02-2015 a las 13:13 +0100, Jan Andres escribió:
 I found that the security.capability xattr gets lost when cloning a
 subvolume via btrfs send | btrfs receive. This is easy to reproduce
 (currently on 3.19.0-rc6, x86_64, with btrfs-progs 3.18.1):
 
 Have two btrfs file systems, /fs1 and /fs2.
 
 # btrfs sub create /fs1/test
 # touch /fs1/test/foo
 # setcap cap_net_admin+ep /fs1/test/foo
 # getcap /fs1/test/foo
 /fs1/test/foo = cap_net_admin+ep
 # btrfs prop set /fs1/test ro true
 # btrfs send /fs1/test | btrfs receive /fs2
 # getcap /fs2/test/foo
 [reports nothing]
 
 
 The cause of the problem seems to be that BTRFS_SEND_C_SET_XATTR comes
 before BTRFS_SEND_C_CHMOD in the send stream, so that the receiving end
 will first correctly restore all the xattrs of the file, and after that,
 perform an lchown() which will cause the kernel to reset the
 file's capabilities.
 
 I don't know how to fix this correctly (especially in the case of
 incremental sends), so I don't have a patch, but figured it might be
 useful to share what I found.

https://bugzilla.kernel.org/show_bug.cgi?id=68891

-- 
Juan Orti
https://miceliux.com

--
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: security.capability xattr missing after btrfs send/receive

2015-02-01 Thread Chris Murphy
Looks like security.capabilities also has tripped up tar.
https://bugzilla.redhat.com/show_bug.cgi?id=771927

There's a suggestion that security.capabilities are non standard
attributes? Also, comment 28 is interesting. Anyway it seems a big
messy to support them in any case.
--
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 fix uncorrectable errors

2015-02-01 Thread Kalle Ahlin
 
About a week ago my machine started reporting the following after scrubbing the 
btrfs filesystem which I do regularly:

scrub status for f74d1ed9-e591-4cbd-8b56-cda5c2f40285  
scrub device /dev/sda (id 1) history
scrub started at Wed Jan 28 01:00:02 2015 and finished after 48737 seconds
total bytes scrubbed: 3.04TiB with 0 errors
scrub device /dev/sdh (id 2) history
scrub started at Wed Jan 28 01:00:02 2015 and finished after 15612 seconds
total bytes scrubbed: 1.22TiB with 0 errors
scrub device /dev/sdb (id 3) history
scrub started at Wed Jan 28 01:00:02 2015 and finished after 20059 seconds
total bytes scrubbed: 789.07GiB with 0 errors
scrub device /dev/sdc (id 5) history
scrub started at Wed Jan 28 01:00:02 2015 and finished after 29746 seconds
total bytes scrubbed: 2.13TiB with 0 errors
scrub device /dev/sde (id 6) history
scrub started at Wed Jan 28 01:00:02 2015 and finished after 26889 seconds
total bytes scrubbed: 2.10TiB with 4027 errors
error details: csum=4027
corrected errors: 0, uncorrectable errors: 4027, unverified errors: 0
scrub device /dev/sdg (id 7) history
scrub started at Wed Jan 28 01:00:02 2015 and finished after 27231 seconds
total bytes scrubbed: 2.10TiB with 4027 errors
error details: csum=4027
corrected errors: 0, uncorrectable errors: 4027, unverified errors: 0



That is, there are 4027 uncorrectable errors on both /dev/sde and /dev/sdg. 
Neither disk seems to have any hardware problems as far as I can tell. I have 
no idea why this happened - nothing unusual has been going on with the machine 
or filesystem.  

I have found the files which seems to be related to the uncorrectable errors, 
and if I do anything at all with those files the entire btrfs filesystem is 
mounted readonly and I cannot fix the problem.  

From a data perspective it’s not a big deal - the problem files are not 
important. For now I have made a copy of the files in the subvolume with 
problems to a new sub volume and I’m now using that copy instead without any 
problems.  

However, I would like to get rid of those uncorrectable errors since they make 
me somewhat worried that something serious is wrong with my filesystem so I 
would like to fix that. Preferrably I would like to remove the subvolume with 
the broked files but I cannot do that since I cannot rm the files and I cannot 
remove the subvolume unless it’s empty.  

Can anybody help me with suggestions about how to solve this?  

(Since the exact same problem appeared out of nowhere on two separate disks 
which don’t have any hardware issues I’m also curious how something like this 
could happen but I guess that is secondary to actually fixing the problem.)

Best Regards,  
Karl Ahlin


--
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 fix uncorrectable errors

2015-02-01 Thread Chris Murphy
I think more info is needed. What kernel and btrfs-progs versions have
been tried? What hardware? What is btrfs fi show and fi df mp? What
files, are there snapshots, etc? Is there any pattern to the two
cases, like the same types of files? And what are the kernel messages
for the above scrub (the entire scrub)?

When you say don't have any hardware issues, I'd like to think that
means an exhaustive (tedious) look at all kernel messages since the
last good scrub to see if there have been any libata or mount errors,
and smartctl -x shows no problems, and at some point in the life of
this machine's current configuration an exhaustive multiple day memory
test? Otherwise I don't know what no hardware issues means. The csum
errors not being fixed sounds like it's probably single copy data
corruption, is that correct? And are the files actually corrupt? Can
you extract them with btrfs restore and are they actually broken (if
this is even practically determinable)?

Chris Murphy
--
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: qgroup: account shared subtrees during snapshot delete

2015-02-01 Thread Dan Carpenter
Hello Mark Fasheh,

The patch 1152651a0817: btrfs: qgroup: account shared subtrees
during snapshot delete from Jul 17, 2014, leads to the following
static checker warning:

fs/btrfs/extent-tree.c:7642 account_shared_subtree()
error: off-by-one overflow 'path-nodes' size 8.  index range = '1-8'

fs/btrfs/extent-tree.c
  7611  BUG_ON(root_level  0 || root_level  BTRFS_MAX_LEVEL);

At first I thought that I could just change this  to = to fix this
warning.

  7612  BUG_ON(root_eb == NULL);
  7613  
  7614  if (!root-fs_info-quota_enabled)
  7615  return 0;
  7616  
  7617  if (!extent_buffer_uptodate(root_eb)) {
  7618  ret = btrfs_read_buffer(root_eb, root_gen);
  7619  if (ret)
  7620  goto out;
  7621  }
  7622  
  7623  if (root_level == 0) {
  7624  ret = account_leaf_items(trans, root, root_eb);
  7625  goto out;
  7626  }
  7627  
  7628  path = btrfs_alloc_path();
  7629  if (!path)
  7630  return -ENOMEM;
  7631  
  7632  /*
  7633   * Walk down the tree.  Missing extent blocks are filled in as
  7634   * we go. Metadata is accounted every time we read a new
  7635   * extent block.
  7636   *
  7637   * When we reach a leaf, we account for file extent items in it,
  7638   * walk back up the tree (adjusting slot pointers as we go)
  7639   * and restart the search process.
  7640   */
  7641  extent_buffer_get(root_eb); /* For path */
  7642  path-nodes[root_level] = root_eb;

-nodes[] has BTRFS_MAX_LEVEL elements.

  7643  path-slots[root_level] = 0;
  7644  path-locks[root_level] = 0; /* so release_path doesn't try to 
unlock */
  7645  walk_down:
  7646  level = root_level;
  7647  while (level = 0) {
  7648  if (path-nodes[level] == NULL) {
  7649  int parent_slot;
  7650  u64 child_gen;
  7651  u64 child_bytenr;
  7652  
  7653  /* We need to get child blockptr/gen from
  7654   * parent before we can read it. */
  7655  eb = path-nodes[level + 1];
 ^^
But when I changed that, then it introduced a warning here because we
add one.  I'm not sure what to do.

  7656  parent_slot = path-slots[level + 1];
  7657  child_bytenr = btrfs_node_blockptr(eb, 
parent_slot);
  7658  child_gen = btrfs_node_ptr_generation(eb, 
parent_slot);
  7659  
  7660  eb = read_tree_block(root, child_bytenr, 
child_gen);
  7661  if (!eb || !extent_buffer_uptodate(eb)) {
  7662  ret = -EIO;
  7663  goto out;
  7664  }
  7665  
  7666  path-nodes[level] = eb;
  7667  path-slots[level] = 0;
  7668  

regards,
dan carpenter
--
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: fix find_free_dev_extent() malfunction in case device tree has hole

2015-02-01 Thread Forrest Liu
If device tree has hole, find_free_dev_extent() cannot find available
address properly.

The example below, has one BIG hole in device tree, and can only
allocate just one chunk in a transaction.

item 9 key (1 DEV_EXTENT 273841913856) itemoff 15811 itemsize 48
dev extent chunk_tree 3
chunk objectid 256 chunk offset 272759783424 length 1073741824
item 10 key (1 DEV_EXTENT 1071632089088) itemoff 15763 itemsize 48
dev extent chunk_tree 3
chunk objectid 256 chunk offset 1070549958656 length 1073741824
item 11 key (1 DEV_EXTENT 1072705830912) itemoff 15715 itemsize 48
dev extent chunk_tree 3
chunk objectid 256 chunk offset 1071623700480 length

Signed-off-by: Forrest Liu forre...@synology.com
---
 fs/btrfs/volumes.c | 15 +++
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index da7e0e1..61be789 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -1060,6 +1060,7 @@ static int contains_pending_extent(struct 
btrfs_trans_handle *trans,
struct extent_map *em;
struct list_head *search_list = trans-transaction-pending_chunks;
int ret = 0;
+   u64 physical_start = *start;
 
 again:
list_for_each_entry(em, search_list, list) {
@@ -1070,9 +1071,9 @@ again:
for (i = 0; i  map-num_stripes; i++) {
if (map-stripes[i].dev != device)
continue;
-   if (map-stripes[i].physical = *start + len ||
+   if (map-stripes[i].physical = physical_start + len ||
map-stripes[i].physical + em-orig_block_len =
-   *start)
+   physical_start)
continue;
*start = map-stripes[i].physical +
em-orig_block_len;
@@ -1195,8 +1196,14 @@ again:
 */
if (contains_pending_extent(trans, device,
search_start,
-   hole_size))
-   hole_size = 0;
+   hole_size)) {
+   if (key.offset = search_start)
+   hole_size = key_offset - search_start;
+   else {
+   WARN_ON(1);
+   hole_size = 0;
+   }
+   }
 
if (hole_size  max_hole_size) {
max_hole_start = search_start;
-- 
1.9.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


Re: __might_sleep() warnings on v3.19-rc6

2015-02-01 Thread NeilBrown

(high-jacking the thread a bit... I don't have the patch that I want to reply
to still in my mail box:  the subject still matches...)

I just got a might-sleep warning in my own testing.
This was introduced by 

commit e22b886a8a43b147e1994a9f970f678fc0df2033
Author: Peter Zijlstra pet...@infradead.org
Date:   Wed Sep 24 10:18:48 2014 +0200

sched/wait: Add might_sleep() checks


In particular:

@@ -318,6 +320,7 @@ do {
  */
 #define wait_event_cmd(wq, condition, cmd1, cmd2)  \
 do {   \
+   might_sleep();  \
if (condition)  \
break;  \
__wait_event_cmd(wq, condition, cmd1, cmd2);\


Where I call this in raid5_quiesce(), 'cmd1' releases a lock and enables
interrupts and  cmd2 takes the lock and disables interrupts.

So it is perfectly OK to sleep at the point where schedule is called, but not
at the point where wait_event_cmd is called.

I can't use wait_event_lock_irq_cmd() as there are actually several spinlocks
I need to manipulate.

So I'm hoping that this part of the patch (at least) can be reverted.

Otherwise I guess I'll need to use __wait_event_cmd().

Thanks,
NeilBrown


pgpQc81MRD5Ju.pgp
Description: OpenPGP digital signature


Re: __might_sleep() warnings on v3.19-rc6

2015-02-01 Thread NeilBrown
On Sun, 1 Feb 2015 21:08:12 -0800 Linus Torvalds
torva...@linux-foundation.org wrote:

 On Sun, Feb 1, 2015 at 3:03 PM, NeilBrown ne...@suse.de wrote:
 
  I guess I could
__set_current_state(TASK_RUNNING);
  somewhere to defeat the warning, and add a comment explaining why.
 
  Would that be a good thing?
 
 Use sched_annotate_sleep() instead, but yes, add a comment about why it's 
 ok.
 
 Linus
 --
 To unsubscribe from this list: send the line unsubscribe linux-kernel in
 the body of a message to majord...@vger.kernel.org
 More majordomo info at  http://vger.kernel.org/majordomo-info.html
 Please read the FAQ at  http://www.tux.org/lkml/

OK - following patch is queued to appear in a pull request tomorrow  (I hope).

Thanks,
NeilBrown

From: NeilBrown ne...@suse.de
Date: Mon, 2 Feb 2015 17:08:03 +1100
Subject: [PATCH] md/bitmap: fix a might_sleep() warning.

commit 8eb23b9f35aae413140d3fda766a98092c21e9b0
sched: Debug nested sleeps

causes false-positive warnings in RAID5 code.

This annotation removes them and adds a comment
explaining why there is no real problem.

Reported-by: Fengguang Wu fengguang...@intel.com
Signed-off-by: NeilBrown ne...@suse.de

diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
index da3604e73e8a..1695ee5f3ffc 100644
--- a/drivers/md/bitmap.c
+++ b/drivers/md/bitmap.c
@@ -72,6 +72,19 @@ __acquires(bitmap-lock)
/* this page has not been allocated yet */
 
spin_unlock_irq(bitmap-lock);
+   /* It is possible that this is being called inside a
+* prepare_to_wait/finish_wait loop from raid5c:make_request().
+* In general it is not permitted to sleep in that context as it
+* can cause the loop to spin freely.
+* That doesn't apply here as we can only reach this point
+* once with any loop.
+* When this function completes, either bp[page].map or
+* bp[page].hijacked.  In either case, this function will
+* abort before getting to this point again.  So there is
+* no risk of a free-spin, and so it is safe to assert
+* that sleeping here is allowed.
+*/
+   sched_annotate_sleep();
mappage = kzalloc(PAGE_SIZE, GFP_NOIO);
spin_lock_irq(bitmap-lock);
 


pgpVKI1XPTGam.pgp
Description: OpenPGP digital signature


Unclean shutdown, BTRFS will not mount after - what things to try in what order?

2015-02-01 Thread Victor Hooi
We have a Ubuntu 14.10 server that has a BTRFS root filesystem.

There was a power outage, and the server will not boot afterwards.

We went into rescue mode, and / didn't mount there, in the
/var/log/syslog we see:

BTRFS: read error corrected: ino 1 of 398856193 (dev /dev/sda1 sector 795400)
repeated twice more with different innodes and sectors
parent transid verify failed on 397688832 wanted 901 found 408
repeated once more with different numbers
BTRFS: Failed to read block groups: -5
rescue: mount: mounting /dev/sda1 on /target failed: Invalid argument
rescue-mode: mount '/dev/sda1' /target failed
BTRFS: open_ctree failed

I've been reading through pages like
https://btrfs.wiki.kernel.org/index.php/Problem_FAQ, and apparently
there's a few things to try (e.g. mounting with -o recovery,
btrfs-zero-log etc), and also using btrfs-restore.

However, I'm wondering if the above specific error messages shed any
light on what happened?

Is there any metadata, or anything I can grab from the disks which
would help diagnose it?
--
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