Re: [PATCH] Btrfs: get rid of btrfs_symlink_aops

2018-09-24 Thread Nikolay Borisov



On 25.09.2018 01:16, Omar Sandoval wrote:
> From: Omar Sandoval 
> 
> The only aops we define for symlinks are identical to the aops for
> regular files. This has been the case since symlink support was added in
> commit 2b8d99a723a3 ("Btrfs: symlinks and hard links"). As far as I can
> tell, there wasn't a good reason to have separate aops then, and there
> isn't now, so let's just do what most other filesystems do and reuse the
> same structure.
> 
> Signed-off-by: Omar Sandoval 

The only difference would be if for symlink it's required to not have
certain operations defined.

Reviewed-by: Nikolay Borisov 

> ---
> Based on v4.19-rc5.
> 
>  fs/btrfs/inode.c | 12 ++--
>  1 file changed, 2 insertions(+), 10 deletions(-)
> 
> diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
> index 3ea5339603cf..590063b0b6dc 100644
> --- a/fs/btrfs/inode.c
> +++ b/fs/btrfs/inode.c
> @@ -64,7 +64,6 @@ static const struct inode_operations 
> btrfs_dir_ro_inode_operations;
>  static const struct inode_operations btrfs_special_inode_operations;
>  static const struct inode_operations btrfs_file_inode_operations;
>  static const struct address_space_operations btrfs_aops;
> -static const struct address_space_operations btrfs_symlink_aops;
>  static const struct file_operations btrfs_dir_file_operations;
>  static const struct extent_io_ops btrfs_extent_io_ops;
>  
> @@ -3738,7 +3737,7 @@ static int btrfs_read_locked_inode(struct inode *inode)
>   case S_IFLNK:
>   inode->i_op = _symlink_inode_operations;
>   inode_nohighmem(inode);
> - inode->i_mapping->a_ops = _symlink_aops;
> + inode->i_mapping->a_ops = _aops;
>   break;
>   default:
>   inode->i_op = _special_inode_operations;
> @@ -10191,7 +10190,7 @@ static int btrfs_symlink(struct inode *dir, struct 
> dentry *dentry,
>  
>   inode->i_op = _symlink_inode_operations;
>   inode_nohighmem(inode);
> - inode->i_mapping->a_ops = _symlink_aops;
> + inode->i_mapping->a_ops = _aops;
>   inode_set_bytes(inode, name_len);
>   btrfs_i_size_write(BTRFS_I(inode), name_len);
>   err = btrfs_update_inode(trans, root, inode);
> @@ -10567,13 +10566,6 @@ static const struct address_space_operations 
> btrfs_aops = {
>   .error_remove_page = generic_error_remove_page,
>  };
>  
> -static const struct address_space_operations btrfs_symlink_aops = {
> - .readpage   = btrfs_readpage,
> - .writepage  = btrfs_writepage,
> - .invalidatepage = btrfs_invalidatepage,
> - .releasepage= btrfs_releasepage,
> -};
> -
>  static const struct inode_operations btrfs_file_inode_operations = {
>   .getattr= btrfs_getattr,
>   .setattr= btrfs_setattr,
> 


[PATCH v2 9/9] generic/387 fix _scratch_mkfs_sized option for btrfs

2018-09-24 Thread Anand Jain
btrfs needs 256mb to create a fs with default block group which is non
mixed, so pass 256mb to _scratch_mkfs_sized().

Signed-off-by: Anand Jain 
---
 tests/generic/387 | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tests/generic/387 b/tests/generic/387
index 68a48012faa5..54a782bba3bc 100755
--- a/tests/generic/387
+++ b/tests/generic/387
@@ -35,7 +35,8 @@ _supported_fs generic
 _supported_os Linux
 _require_scratch_reflink
 
-_scratch_mkfs_sized $((32 * 1024 * 1024)) >> $seqres.full 2>&1
+#btrfs needs 256mb to create default blockgroup fs
+_scratch_mkfs_sized $((256 * 1024 * 1024)) >> $seqres.full 2>&1
 _scratch_mount
 
 testfile=$SCRATCH_MNT/testfile
-- 
1.8.3.1



[PATCH v2 5/9] generic/102 open code dev_size _scratch_mkfs_sized()

2018-09-24 Thread Anand Jain
Open code helps to grep and find out parameter sent to the
_scratch_mkfs_sized here.

Signed-off-by: Anand Jain 
---
 tests/generic/102 | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/tests/generic/102 b/tests/generic/102
index faf940ac5070..aad496a5bc69 100755
--- a/tests/generic/102
+++ b/tests/generic/102
@@ -31,8 +31,7 @@ _require_scratch
 
 rm -f $seqres.full
 
-dev_size=$((512 * 1024 * 1024)) # 512MB filesystem
-_scratch_mkfs_sized $dev_size >>$seqres.full 2>&1
+_scratch_mkfs_sized $((512 * 1024 * 1024)) >>$seqres.full 2>&1
 _scratch_mount
 
 for ((i = 0; i < 10; i++)); do
-- 
1.8.3.1



[PATCH v2 7/9] generic/312 open code fs_size _scratch_mkfs_sized()

2018-09-24 Thread Anand Jain
fs_size isn't used anywhere else further more now grep tells what size
is being used.

Signed-off-by: Anand Jain 
---
 tests/generic/312 | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/tests/generic/312 b/tests/generic/312
index 756f5c3e4c5a..465009c8d184 100755
--- a/tests/generic/312
+++ b/tests/generic/312
@@ -34,11 +34,10 @@ _supported_os Linux
 _require_xfs_io_command "falloc"
 _require_scratch
 
-# 5G in byte
-fssize=$((2**30 * 5))
-
 rm -f $seqres.full
-_scratch_mkfs_sized $fssize >>$seqres.full 2>&1
+
+# 5G FS
+_scratch_mkfs_sized $((2**30 * 5)) >>$seqres.full 2>&1
 _scratch_mount >>$seqres.full 2>&1
 
 echo "Silence is golden"
-- 
1.8.3.1



[PATCH v2 8/9] generic/449 fix fs size for _scratch_mkfs_sized for btrfs

2018-09-24 Thread Anand Jain
btrfs needs 256m to create btrfs with default options like non mixed
block groups.

Signed-off-by: Anand Jain 
---
 tests/generic/449 | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tests/generic/449 b/tests/generic/449
index 88f918654b54..21b920bf6a50 100755
--- a/tests/generic/449
+++ b/tests/generic/449
@@ -41,7 +41,7 @@ _require_test
 _require_acls
 _require_attrs
 
-_scratch_mkfs_sized $((50 * 1024 * 1024)) >> $seqres.full 2>&1
+_scratch_mkfs_sized $((256 * 1024 * 1024)) >> $seqres.full 2>&1
 _scratch_mount || _fail "mount failed"
 
 TFILE=$SCRATCH_MNT/testfile.$seq
@@ -52,7 +52,7 @@ chmod u+rwx $TFILE
 chmod go-rwx $TFILE
 
 # Try to run out of space so setfacl will fail
-$XFS_IO_PROG -c "pwrite 0 50m" $TFILE >>$seqres.full 2>&1
+$XFS_IO_PROG -c "pwrite 0 256m" $TFILE >>$seqres.full 2>&1
 i=1
 
 # Setting acls on an xfs filesystem will succeed even after running out of
-- 
1.8.3.1



[PATCH v2 1/9] fstests: btrfs: _scratch_mkfs_sized fix min size without mixed option

2018-09-24 Thread Anand Jain
As of now _scratch_mkfs_sized() checks if the requested size is below 1G
and forces the --mixed option for the mkfs.btrfs. Well the correct size
considering all possible group profiles at which we need to force the
mixed option is roughly 256Mbytes. So fix that.

Signed-off-by: Anand Jain 
---
 common/rc | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/common/rc b/common/rc
index d5bb1feee2c3..90dc3002bc3d 100644
--- a/common/rc
+++ b/common/rc
@@ -969,7 +969,10 @@ _scratch_mkfs_sized()
;;
 btrfs)
local mixed_opt=
-   (( fssize <= 1024 * 1024 * 1024 )) && mixed_opt='--mixed'
+   # minimum size that's needed without the mixed option.
+   # Ref: btrfs-prog: btrfs_min_dev_size()
+   # Non mixed mode is also the default option.
+   (( fssize < $((256 * 1024 *1024)) )) && mixed_opt='--mixed'
$MKFS_BTRFS_PROG $MKFS_OPTIONS $mixed_opt -b $fssize $SCRATCH_DEV
;;
 jfs)
-- 
1.8.3.1



[PATCH v2 6/9] generic/204 open code SIZE for _scratch_mkfs_sized()

2018-09-24 Thread Anand Jain
By open code we could grep to find out FS size being use by this test
case.

Signed-off-by: Anand Jain 
---
 tests/generic/204 | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/tests/generic/204 b/tests/generic/204
index 349f5eff351f..576c4eabd359 100755
--- a/tests/generic/204
+++ b/tests/generic/204
@@ -42,8 +42,7 @@ _scratch_mkfs 2> /dev/null | _filter_mkfs 2> $tmp.mkfs > 
/dev/null
 # time solves this problem.
 [ $FSTYP = "xfs" ] && MKFS_OPTIONS="$MKFS_OPTIONS -l size=16m -i maxpct=50"
 
-SIZE=`expr 115 \* 1024 \* 1024`
-_scratch_mkfs_sized $SIZE $dbsize 2> /dev/null > $tmp.mkfs.raw
+_scratch_mkfs_sized $((115 * 1024 * 1024)) $dbsize 2> /dev/null > $tmp.mkfs.raw
 cat $tmp.mkfs.raw | _filter_mkfs 2> $tmp.mkfs > /dev/null
 _scratch_mount
 
-- 
1.8.3.1



[PATCH v2 4/9] generic/083 fix btrfs fs size for default mode

2018-09-24 Thread Anand Jain
btrfs needs at least 256mb to create a FS with the defaults options.

Signed-off-by: Anand Jain 
---
 tests/generic/083 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/generic/083 b/tests/generic/083
index 63d96ba2ab88..eabff02a36eb 100755
--- a/tests/generic/083
+++ b/tests/generic/083
@@ -71,7 +71,7 @@ workout()
 
 echo "*** test out-of-space handling for random write operations"
 
-filesize=`expr 100 \* 1024 \* 1024`
+filesize=`expr 256 \* 1024 \* 1024`
 agcount=6
 numprocs=15
 numops=1500
-- 
1.8.3.1



[PATCH v2 3/9] geneirc/077 fix min size for btrfs

2018-09-24 Thread Anand Jain
If btrfs need to be tested at its default blockgroup which is non-mixed,
then it needs at least 256mb.

Signed-off-by: Anand Jain 
---
 tests/generic/077 | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/tests/generic/077 b/tests/generic/077
index ef6af18c83e3..ec236992513f 100755
--- a/tests/generic/077
+++ b/tests/generic/077
@@ -49,8 +49,7 @@ rm -f $seqres.full
 _scratch_unmount >/dev/null 2>&1
 echo "*** MKFS ***" >>$seqres.full
 echo "" >>$seqres.full
-SIZE=`expr 50 \* 1024 \* 1024`
-_scratch_mkfs_sized $SIZE   >>$seqres.full 2>&1 \
+_scratch_mkfs_sized $((256 * 1024 *1024))   >>$seqres.full 2>&1 \
|| _fail "mkfs failed"
 _scratch_mount
 mkdir $SCRATCH_MNT/subdir
-- 
1.8.3.1



[PATCH v2 0/9] Fix _scratch_mkfs_sized() for btrfs

2018-09-24 Thread Anand Jain
v1->v2: Fix the min size for _scratch_mkfs_sized() to 256MB for btrfs and
 add comment about its ref.
Fix _scratch_mkfs_sized() options to use at least 256MB in each
 test case.
Update change long.

Currently _scratch_mkfs_sized() checks if the requested size is below 1G
for btrfs and forces the --mixed mkfs option. The 1G size cut off is too
larger where the actual size is ~256mb. The patch 1/9 fixes the
_scratch_mkfs_sized() to check for 256mb instead.

Also fix the test cases requesting to create FS below 256mb. And open
code the fssize computation where possible (that is the variable used
is only used once).

Further, there are test cases generic/250,252,256,416 which uses
_scratch_mkfs_sized with < 200mb but its fix isn't straight forward
and they are not yet ready for the review.

The affected testcases (which calls _scratch_mkfs_sized) [1] have
been tested on btrfs. And the test cases [2] which are being patches
here are tested on xfs ext4 and btrfs for no regression.

[1]
generic/015 generic/027 generic/077 generic/081 generic/083 generic/085 
generic/096 generic/102 generic/171 generic/172 generic/173 generic/174 
generic/204 generic/224 generic/226 generic/250 generic/252 generic/256 
generic/269 generic/270 generic/273 generic/274 generic/275 generic/300 
generic/312 generic/320 generic/333 generic/334 generic/361 generic/371 
generic/387 generic/399 generic/416 generic/427 generic/449 generic/459 
generic/466 generic/488 generic/505 btrfs/004 btrfs/007 btrfs/132 btrfs/170

[2]
generic/015 generic/077 generic/083 generic/387 generic/449

Anand Jain (9):
  fstests: btrfs: _scratch_mkfs_sized fix min size without mixed option
  generic/015 fix to test the default non-mixed mode
  geneirc/077 fix min size for btrfs
  generic/083 fix btrfs fs size for default mode
  generic/102 open code dev_size _scratch_mkfs_sized()
  generic/204 open code SIZE for _scratch_mkfs_sized()
  generic/312 open code fs_size _scratch_mkfs_sized()
  generic/449 fix fs size for _scratch_mkfs_sized for btrfs
  generic/387 fix _scratch_mkfs_sized option for btrfs

 common/rc | 4 +++-
 tests/generic/015 | 8 +++-
 tests/generic/077 | 3 +--
 tests/generic/083 | 2 +-
 tests/generic/102 | 3 +--
 tests/generic/204 | 3 +--
 tests/generic/312 | 7 +++
 tests/generic/387 | 3 ++-
 tests/generic/449 | 4 ++--
 9 files changed, 17 insertions(+), 20 deletions(-)

-- 
1.8.3.1



[PATCH v2 2/9] generic/015 fix to test the default non-mixed mode

2018-09-24 Thread Anand Jain
commit 97575acd7495 (generic/015: Change the test filesystem size to
101mb), created 101mb FS instead of 100mb FS to make sure we create
a FS which is non mixed mode.

btrfs-progs commit 18e2663db3e1 (btrfs-progs: Add minimum device size
check) added a more accurate minimum required space to create the btrfs
FS in non mixed mode depending on the group profile, and considering
any group profiles we would need at least 256MB (with upward round off).

So this patch changes the FS size to be created by _scratch_sized_mkfs()
to 256MB so that we create the FS in non mixed mode for any group
profile.

Mixed blockgroup can be tested using the MKFS_OPTIONS explicitly.

Signed-off-by: Anand Jain 
---
 tests/generic/015 | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/tests/generic/015 b/tests/generic/015
index 0f4d29800f4f..e6c8d7c37c07 100755
--- a/tests/generic/015
+++ b/tests/generic/015
@@ -37,11 +37,9 @@ _supported_os Linux
 _require_scratch
 _require_no_large_scratch_dev
 
-# With filesystems less than 100mb btrfs is created in mixed mode
-# which can lead to slight accounting errors of 1mb. Having the
-# fs be at least 101 mb ensures those errors are within the error
-# tolerance of 1%
-_scratch_mkfs_sized `expr 101 \* 1024 \* 1024` >/dev/null 2>&1 \
+# btrfs needs at least 256MB (with upward round off) to create a non-mixed mode
+# fs. Ref: btrfs-progs: btrfs_min_dev_size()
+_scratch_mkfs_sized $((256 * 1024 * 1024)) >> $seqres.full 2>&1 \
 || _fail "mkfs failed"
 _scratch_mount
 out=$SCRATCH_MNT/fillup.$$
-- 
1.8.3.1



Re: [PATCH 1/2] btrfs: Use NAME_MAX to replace intermediate number of BTRFS_NAME_LEN

2018-09-24 Thread Su Yue




On 9/25/18 8:06 AM, Qu Wenruo wrote:

Since we're following the name size limit of linux, just use NAME_MAX.

Signed-off-by: Qu Wenruo 


Reviewed-by: Su Yue 

---
  fs/btrfs/ctree.h | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 53af9f5253f4..5ab6d1f6e055 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -65,7 +65,7 @@ struct btrfs_ordered_sum;
   * we can actually store much bigger names, but lets not confuse the rest
   * of linux
   */
-#define BTRFS_NAME_LEN 255
+#define BTRFS_NAME_LEN NAME_MAX
  
  /*

   * Theoretical limit is larger, but we keep this down to a sane






DUP dev_extent might overlap something next to it

2018-09-24 Thread Hans van Kranenburg
(I'm using v4.19-rc5 code here.)

Imagine allocating a DATA|DUP chunk.

In the chunk allocator, we first set...
  max_stripe_size = SZ_1G;
  max_chunk_size = BTRFS_MAX_DATA_CHUNK_SIZE
... which is 10GiB.

Then...
  /* we don't want a chunk larger than 10% of writeable space */
  max_chunk_size = min(div_factor(fs_devices->total_rw_bytes, 1),
   max_chunk_size);

Imagine we only have one 7880MiB block device in this filesystem. Now
max_chunk_size is down to 788MiB.

The next step in the code is to search for max_stripe_size * dev_stripes
amount of free space on the device, which is in our example 1GiB * 2 =
2GiB. Imagine the device has exactly 1578MiB free in one contiguous
piece. This amount of bytes will be put in devices_info[ndevs - 1].max_avail

Next we recalculate the stripe_size (which is actually the device extent
length), based on the actual maximum amount of available raw disk space:
  stripe_size = div_u64(devices_info[ndevs - 1].max_avail, dev_stripes);

stripe_size is now 789MiB

Next we do...
  data_stripes = num_stripes / ncopies
...where data_stripes ends up as 1, because num_stripes is 2 (the amount
of device extents we're going to have), and DUP has ncopies 2.

Next there's a check...
  if (stripe_size * data_stripes > max_chunk_size)
...which matches because 789MiB * 1 > 788MiB.

We go into the if code, and next is...
  stripe_size = div_u64(max_chunk_size, data_stripes);
...which resets stripe_size to max_chunk_size: 788MiB

Next is a fun one...
  /* bump the answer up to a 16MB boundary */
  stripe_size = round_up(stripe_size, SZ_16M);
...which changes stripe_size from 788MiB to 800MiB.

We're not done changing stripe_size yet...
  /* But don't go higher than the limits we found while searching
   * for free extents
   */
  stripe_size = min(devices_info[ndevs - 1].max_avail,
stripe_size);

This is bad. max_avail is twice the stripe_size (we need to fit 2 device
extents on the same device for DUP).

The result here is that 800MiB < 1578MiB, so it's unchanged. However,
the resulting DUP chunk will need 1600MiB disk space, which isn't there,
and the second dev_extent might extend into the next thing (next
dev_extent? end of device?) for 22MiB.

The last shown line of code relies on a situation where there's twice
the value of stripe_size present as value for the variable stripe_size
when it's DUP. This was actually the case before commit 92e222df7b
"btrfs: alloc_chunk: fix DUP stripe size handling", from which I quote:
  "[...] in the meantime there's a check to see if the stripe_size does
not exceed max_chunk_size. Since during this check stripe_size is twice
the amount as intended, the check will reduce the stripe_size to
max_chunk_size if the actual correct to be used stripe_size is more than
half the amount of max_chunk_size."

In the previous version of the code, the 16MiB alignment (why is this
done, by the way?) would result in a 50% chance that it would actually
do an 8MiB alignment for the individual dev_extents, since it was
operating on double the size. Does this matter?

Does it matter that stripe_size can be set to anything which is not
16MiB aligned because of the amount of remaining available disk space
which is just taken?

What is the main purpose of this round_up?

The most straightforward thing to do seems something like...
  stripe_size = min(
  div_u64(devices_info[ndevs - 1].max_avail, dev_stripes),
  stripe_size
  )
..just putting half of the max_avail into stripe_size.

I hope the above analysis is correct...

If this is fixed, then it will be the 5th commit in btrfs history which
tries to fix the same thing in this code again, where all the previous
ones were breaking things while fixing things.

The real problem is that in the very first version of this code, the
stripe_size variable was already reused for very different purposes
throughout the function. And it still is, all the time.

So, while it may seem very logical fix (again), I guess this needs more
eyes, since we missed this line the previous time. D:

-- 
Hans van Kranenburg


[PATCH 1/2] btrfs: Use NAME_MAX to replace intermediate number of BTRFS_NAME_LEN

2018-09-24 Thread Qu Wenruo
Since we're following the name size limit of linux, just use NAME_MAX.

Signed-off-by: Qu Wenruo 
---
 fs/btrfs/ctree.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 53af9f5253f4..5ab6d1f6e055 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -65,7 +65,7 @@ struct btrfs_ordered_sum;
  * we can actually store much bigger names, but lets not confuse the rest
  * of linux
  */
-#define BTRFS_NAME_LEN 255
+#define BTRFS_NAME_LEN NAME_MAX
 
 /*
  * Theoretical limit is larger, but we keep this down to a sane
-- 
2.19.0



[PATCH 2/2] btrfs: tree-checker: Avoid using max() for stack array allocation

2018-09-24 Thread Qu Wenruo
Although BTRFS_NAME_LEN and XATTR_NAME_MAX is the same value (255),
max(BTRFS_NAME_LEN, XATTR_NAME_MAX) should be optimized as const at
runtime.

However S390x' arch dependent option "-mwarn-dynamicstack" could still
report it as dyanamic stack allocation.

Just use BTRFS_NAME_LEN directly to avoid such false alert.

Signed-off-by: Qu Wenruo 
---
 fs/btrfs/tree-checker.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/btrfs/tree-checker.c b/fs/btrfs/tree-checker.c
index db835635372f..4c045609909b 100644
--- a/fs/btrfs/tree-checker.c
+++ b/fs/btrfs/tree-checker.c
@@ -336,7 +336,7 @@ static int check_dir_item(struct btrfs_fs_info *fs_info,
 */
if (key->type == BTRFS_DIR_ITEM_KEY ||
key->type == BTRFS_XATTR_ITEM_KEY) {
-   char namebuf[max(BTRFS_NAME_LEN, XATTR_NAME_MAX)];
+   char namebuf[BTRFS_NAME_LEN];
 
read_extent_buffer(leaf, namebuf,
(unsigned long)(di + 1), name_len);
-- 
2.19.0



[PATCH] Btrfs: get rid of btrfs_symlink_aops

2018-09-24 Thread Omar Sandoval
From: Omar Sandoval 

The only aops we define for symlinks are identical to the aops for
regular files. This has been the case since symlink support was added in
commit 2b8d99a723a3 ("Btrfs: symlinks and hard links"). As far as I can
tell, there wasn't a good reason to have separate aops then, and there
isn't now, so let's just do what most other filesystems do and reuse the
same structure.

Signed-off-by: Omar Sandoval 
---
Based on v4.19-rc5.

 fs/btrfs/inode.c | 12 ++--
 1 file changed, 2 insertions(+), 10 deletions(-)

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 3ea5339603cf..590063b0b6dc 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -64,7 +64,6 @@ static const struct inode_operations 
btrfs_dir_ro_inode_operations;
 static const struct inode_operations btrfs_special_inode_operations;
 static const struct inode_operations btrfs_file_inode_operations;
 static const struct address_space_operations btrfs_aops;
-static const struct address_space_operations btrfs_symlink_aops;
 static const struct file_operations btrfs_dir_file_operations;
 static const struct extent_io_ops btrfs_extent_io_ops;
 
@@ -3738,7 +3737,7 @@ static int btrfs_read_locked_inode(struct inode *inode)
case S_IFLNK:
inode->i_op = _symlink_inode_operations;
inode_nohighmem(inode);
-   inode->i_mapping->a_ops = _symlink_aops;
+   inode->i_mapping->a_ops = _aops;
break;
default:
inode->i_op = _special_inode_operations;
@@ -10191,7 +10190,7 @@ static int btrfs_symlink(struct inode *dir, struct 
dentry *dentry,
 
inode->i_op = _symlink_inode_operations;
inode_nohighmem(inode);
-   inode->i_mapping->a_ops = _symlink_aops;
+   inode->i_mapping->a_ops = _aops;
inode_set_bytes(inode, name_len);
btrfs_i_size_write(BTRFS_I(inode), name_len);
err = btrfs_update_inode(trans, root, inode);
@@ -10567,13 +10566,6 @@ static const struct address_space_operations 
btrfs_aops = {
.error_remove_page = generic_error_remove_page,
 };
 
-static const struct address_space_operations btrfs_symlink_aops = {
-   .readpage   = btrfs_readpage,
-   .writepage  = btrfs_writepage,
-   .invalidatepage = btrfs_invalidatepage,
-   .releasepage= btrfs_releasepage,
-};
-
 static const struct inode_operations btrfs_file_inode_operations = {
.getattr= btrfs_getattr,
.setattr= btrfs_setattr,
-- 
2.19.0



Re: [PATCH 1/2] Btrfs: don't clean dirty pages during buffered writes

2018-09-24 Thread David Sterba
On Wed, Jun 20, 2018 at 07:56:11AM -0700, Chris Mason wrote:
> During buffered writes, we follow this basic series of steps:
> 
> again:
>   lock all the pages
>   wait for writeback on all the pages
>   Take the extent range lock
>   wait for ordered extents on the whole range
>   clean all the pages
> 
>   if (copy_from_user_in_atomic() hits a fault) {
>   drop our locks
>   goto again;
>   }
> 
>   dirty all the pages
>   release all the locks
> 
> The extra waiting, cleaning and locking are there to make sure we don't
> modify pages in flight to the drive, after they've been crc'd.
> 
> If some of the pages in the range were already dirty when the write
> began, and we need to goto again, we create a window where a dirty page
> has been cleaned and unlocked.  It may be reclaimed before we're able to
> lock it again, which means we'll read the old contents off the drive and
> lose any modifications that had been pending writeback.
> 
> We don't actually need to clean the pages.  All of the other locking in
> place makes sure we don't start IO on the pages, so we can just leave
> them dirty for the duration of the write.
> 
> Fixes: 73d59314e6ed (the original btrfs merge)
> Signed-off-by: Chris Mason 

Reviewed-by: David Sterba 

Moved from for-next to 4.20 queue.


Re: [PATCH 1/9] fstests: btrfs: _scratch_mkfs_sized fix min size without mixed option

2018-09-24 Thread Anand Jain




On 09/24/2018 08:02 PM, Qu Wenruo wrote:



On 2018/9/24 下午7:53, Anand Jain wrote:



On 09/24/2018 06:58 PM, Qu Wenruo wrote:



On 2018/9/24 下午6:16, Anand Jain wrote:

As of now _scratch_mkfs_sized check if the requested size is below 1G
and forces the --mixed option for the mkfs.btrfs. Well the correct size
at which we need to force the mixed option is 114294784bytes. Fix that.


How this size is get from?
If it's from btrfs_min_dev_size(), I strongly recommend to add reference
here, and don't use the ugly intermediate number.


BTW, this number is related to mkfs profile.
If you really want to use some maximum number, please follow the max
possible value in btrfs_min_dev_size(), which should be 229M other than
106M.


  Thanks for the comments. I completely missed out the point of other
  group profile requiring more than ~115 bytes. Will fix.


I'd go a rounded number, like 256M.

Non of the number from btrfs_min_dev_size() is really easy to remember
nor makes sense out of btrfs realm.

And this also leaves a little more headroom for later modification
(although I hope such modification never happen)


 I agree. Actually I was thinking it should be like that when I was 
writing this patch, then my logical mind didn't provide any strong 
reason to back that up. As ideas match, Will fix it at 256M.


Thanks, Anand



Thanks,
Qu


  Yep the ref for the size is btrfs_min_dev_size().

-Anand



Thanks,
Qu



Signed-off-by: Anand Jain 
---
   common/rc | 4 +++-
   1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/common/rc b/common/rc
index d5bb1feee2c3..bcdbf03e1bf0 100644
--- a/common/rc
+++ b/common/rc
@@ -969,7 +969,9 @@ _scratch_mkfs_sized()
   ;;
   btrfs)
   local mixed_opt=
-    (( fssize <= 1024 * 1024 * 1024 )) && mixed_opt='--mixed'
+    # minimum size that's needed without the mixed option.
+    # Non mixed mode is also the default option.
+    (( fssize < 114294784 )) && mixed_opt='--mixed'
   $MKFS_BTRFS_PROG $MKFS_OPTIONS $mixed_opt -b $fssize $SCRATCH_DEV
   ;;
   jfs)







Re: [PATCH 1/9] fstests: btrfs: _scratch_mkfs_sized fix min size without mixed option

2018-09-24 Thread Qu Wenruo


On 2018/9/24 下午7:53, Anand Jain wrote:
> 
> 
> On 09/24/2018 06:58 PM, Qu Wenruo wrote:
>>
>>
>> On 2018/9/24 下午6:16, Anand Jain wrote:
>>> As of now _scratch_mkfs_sized check if the requested size is below 1G
>>> and forces the --mixed option for the mkfs.btrfs. Well the correct size
>>> at which we need to force the mixed option is 114294784bytes. Fix that.
>>
>> How this size is get from?
>> If it's from btrfs_min_dev_size(), I strongly recommend to add reference
>> here, and don't use the ugly intermediate number.
>>
>>
>> BTW, this number is related to mkfs profile.
>> If you really want to use some maximum number, please follow the max
>> possible value in btrfs_min_dev_size(), which should be 229M other than
>> 106M.
> 
>  Thanks for the comments. I completely missed out the point of other
>  group profile requiring more than ~115 bytes. Will fix.

I'd go a rounded number, like 256M.

Non of the number from btrfs_min_dev_size() is really easy to remember
nor makes sense out of btrfs realm.

And this also leaves a little more headroom for later modification
(although I hope such modification never happen)

Thanks,
Qu

>  Yep the ref for the size is btrfs_min_dev_size().
> 
> -Anand
> 
> 
>> Thanks,
>> Qu
>>
>>>
>>> Signed-off-by: Anand Jain 
>>> ---
>>>   common/rc | 4 +++-
>>>   1 file changed, 3 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/common/rc b/common/rc
>>> index d5bb1feee2c3..bcdbf03e1bf0 100644
>>> --- a/common/rc
>>> +++ b/common/rc
>>> @@ -969,7 +969,9 @@ _scratch_mkfs_sized()
>>>   ;;
>>>   btrfs)
>>>   local mixed_opt=
>>> -    (( fssize <= 1024 * 1024 * 1024 )) && mixed_opt='--mixed'
>>> +    # minimum size that's needed without the mixed option.
>>> +    # Non mixed mode is also the default option.
>>> +    (( fssize < 114294784 )) && mixed_opt='--mixed'
>>>   $MKFS_BTRFS_PROG $MKFS_OPTIONS $mixed_opt -b $fssize $SCRATCH_DEV
>>>   ;;
>>>   jfs)
>>>
>>



signature.asc
Description: OpenPGP digital signature


Re: [PATCH 2/9] generic/015 fix to test the default non-mixed mode

2018-09-24 Thread Anand Jain




On 09/24/2018 07:01 PM, Qu Wenruo wrote:



On 2018/9/24 下午6:16, Anand Jain wrote:

commit 97575acd7495 (generic/015: Change the test filesystem size to
101mb), created 101mb FS instead of 100mb FS to make sure we create
a FS which is non mixed mode, which is our default mode.

btrfs-progs commit 18e2663db3e1 (btrfs-progs: Add minimum device size
check) added a more accurate minimum required space to create the btrfs
FS in non mixed mode. Which is at 14294784 bytes.

So this patch changes the FS size to be created by _scratch_sized_mkfs
to 200mb so that we create the FS in non mixed mode.

To test mixed blockgroup its better we set it using the MKFS_OPTIONS
explicitly.

Signed-off-by: Anand Jain 
---
  tests/generic/015 | 9 -
  1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/tests/generic/015 b/tests/generic/015
index 0f4d29800f4f..14941ab6d552 100755
--- a/tests/generic/015
+++ b/tests/generic/015
@@ -37,11 +37,10 @@ _supported_os Linux
  _require_scratch
  _require_no_large_scratch_dev
  
-# With filesystems less than 100mb btrfs is created in mixed mode

-# which can lead to slight accounting errors of 1mb. Having the
-# fs be at least 101 mb ensures those errors are within the error
-# tolerance of 1%
-_scratch_mkfs_sized `expr 101 \* 1024 \* 1024` >/dev/null 2>&1 \
+# With filesystems less than ~200mb _scratch_mkfs_sized will create
+# data and metadata mixed mode btrfs, so use 200mb so that we test
+# the default btrfs.
+_scratch_mkfs_sized $((200 * 1024 * 1024)) >> $seqres.full 2>&1 \
  || _fail "mkfs failed"


Just as mentioned in the first patch, the minimal size for non-mixed
btrfs depends on mkfs profile.

Metadata DUP and data DUP would fail using 200M mkfs size:

  $ mkfs.btrfs  -m DUP -d DUP -b 200M /dev/data/btrfs -f
  btrfs-progs v4.17.1
  See http://btrfs.wiki.kernel.org for more information.

  ERROR: size 209715200 is too small to make a usable filesystem
  ERROR: minimum size for btrfs filesystem is 240123904

This problem applies to all patches, unfortunately.


 Yes. Handling the other (non default) group profiles is missing.
 Will fix.

Thanks, Anand



Thanks,
Qu


  _scratch_mount
  out=$SCRATCH_MNT/fillup.$$





Re: [PATCH 1/9] fstests: btrfs: _scratch_mkfs_sized fix min size without mixed option

2018-09-24 Thread Anand Jain




On 09/24/2018 06:58 PM, Qu Wenruo wrote:



On 2018/9/24 下午6:16, Anand Jain wrote:

As of now _scratch_mkfs_sized check if the requested size is below 1G
and forces the --mixed option for the mkfs.btrfs. Well the correct size
at which we need to force the mixed option is 114294784bytes. Fix that.


How this size is get from?
If it's from btrfs_min_dev_size(), I strongly recommend to add reference
here, and don't use the ugly intermediate number.


BTW, this number is related to mkfs profile.
If you really want to use some maximum number, please follow the max
possible value in btrfs_min_dev_size(), which should be 229M other than
106M.


 Thanks for the comments. I completely missed out the point of other
 group profile requiring more than ~115 bytes. Will fix.
 Yep the ref for the size is btrfs_min_dev_size().

-Anand



Thanks,
Qu



Signed-off-by: Anand Jain 
---
  common/rc | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/common/rc b/common/rc
index d5bb1feee2c3..bcdbf03e1bf0 100644
--- a/common/rc
+++ b/common/rc
@@ -969,7 +969,9 @@ _scratch_mkfs_sized()
;;
  btrfs)
local mixed_opt=
-   (( fssize <= 1024 * 1024 * 1024 )) && mixed_opt='--mixed'
+   # minimum size that's needed without the mixed option.
+   # Non mixed mode is also the default option.
+   (( fssize < 114294784 )) && mixed_opt='--mixed'
$MKFS_BTRFS_PROG $MKFS_OPTIONS $mixed_opt -b $fssize $SCRATCH_DEV
;;
  jfs)





[PATCH] test unaligned punch hole at ENOSPC

2018-09-24 Thread Anand Jain
Try to punch hole with unaligned size and offset when the FS
returns ENOSPC

Signed-off-by: Anand Jain 
---
This test case fails on btrfs as of now.

 tests/btrfs/172 | 66 +
 tests/btrfs/172.out |  2 ++
 tests/btrfs/group   |  1 +
 3 files changed, 69 insertions(+)
 create mode 100755 tests/btrfs/172
 create mode 100644 tests/btrfs/172.out

diff --git a/tests/btrfs/172 b/tests/btrfs/172
new file mode 100755
index ..9c32a173f912
--- /dev/null
+++ b/tests/btrfs/172
@@ -0,0 +1,66 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2018 Oracle. All Rights Reserved.
+#
+# FS QA Test 172
+#
+# Test if the unaligned (by size and offset) punch hole is successful when FS
+# is at ENOSPC.
+#
+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 generic
+_supported_os Linux
+_require_scratch
+
+_scratch_mkfs_sized $((200 * 1024 *1024)) >> $seqres.full
+
+# max_inline helps to create regular extent
+_scratch_mount "-o max_inline=0,nodatacow"
+
+echo "Fill fs upto ENOSPC" >> $seqres.full
+dd status=none if=/dev/zero of=$SCRATCH_MNT/filler bs=512 >> $seqres.full 2>&1
+
+extent_size=$(_scratch_btrfs_sectorsize)
+unalign_by=512
+echo extent_size=$extent_size unalign_by=$unalign_by >> $seqres.full
+
+hole_offset=0
+hole_len=$unalign_by
+run_check fallocate -p -o $hole_offset -l $hole_len $SCRATCH_MNT/filler
+
+hole_offset=$(($extent_size + $unalign_by))
+hole_len=$(($extent_size - $unalign_by))
+run_check fallocate -p -o $hole_offset -l $hole_len $SCRATCH_MNT/filler
+
+hole_offset=$(($extent_size * 2 + $unalign_by))
+hole_len=$(($extent_size * 5))
+run_check fallocate -p -o $hole_offset -l $hole_len $SCRATCH_MNT/filler
+
+# success, all done
+echo "Silence is golden"
+status=0
+exit
diff --git a/tests/btrfs/172.out b/tests/btrfs/172.out
new file mode 100644
index ..ce2de3f0d107
--- /dev/null
+++ b/tests/btrfs/172.out
@@ -0,0 +1,2 @@
+QA output created by 172
+Silence is golden
diff --git a/tests/btrfs/group b/tests/btrfs/group
index feffc45b6564..7e1a638ab7e1 100644
--- a/tests/btrfs/group
+++ b/tests/btrfs/group
@@ -174,3 +174,4 @@
 169 auto quick send
 170 auto quick snapshot
 171 auto quick qgroup
+172 auto quick
-- 
1.8.3.1



Re: [PATCH 2/9] generic/015 fix to test the default non-mixed mode

2018-09-24 Thread Qu Wenruo


On 2018/9/24 下午6:16, Anand Jain wrote:
> commit 97575acd7495 (generic/015: Change the test filesystem size to
> 101mb), created 101mb FS instead of 100mb FS to make sure we create
> a FS which is non mixed mode, which is our default mode.
> 
> btrfs-progs commit 18e2663db3e1 (btrfs-progs: Add minimum device size
> check) added a more accurate minimum required space to create the btrfs
> FS in non mixed mode. Which is at 14294784 bytes.
> 
> So this patch changes the FS size to be created by _scratch_sized_mkfs
> to 200mb so that we create the FS in non mixed mode.
> 
> To test mixed blockgroup its better we set it using the MKFS_OPTIONS
> explicitly.
> 
> Signed-off-by: Anand Jain 
> ---
>  tests/generic/015 | 9 -
>  1 file changed, 4 insertions(+), 5 deletions(-)
> 
> diff --git a/tests/generic/015 b/tests/generic/015
> index 0f4d29800f4f..14941ab6d552 100755
> --- a/tests/generic/015
> +++ b/tests/generic/015
> @@ -37,11 +37,10 @@ _supported_os Linux
>  _require_scratch
>  _require_no_large_scratch_dev
>  
> -# With filesystems less than 100mb btrfs is created in mixed mode
> -# which can lead to slight accounting errors of 1mb. Having the
> -# fs be at least 101 mb ensures those errors are within the error
> -# tolerance of 1%
> -_scratch_mkfs_sized `expr 101 \* 1024 \* 1024` >/dev/null 2>&1 \
> +# With filesystems less than ~200mb _scratch_mkfs_sized will create
> +# data and metadata mixed mode btrfs, so use 200mb so that we test
> +# the default btrfs.
> +_scratch_mkfs_sized $((200 * 1024 * 1024)) >> $seqres.full 2>&1 \
>  || _fail "mkfs failed"

Just as mentioned in the first patch, the minimal size for non-mixed
btrfs depends on mkfs profile.

Metadata DUP and data DUP would fail using 200M mkfs size:

 $ mkfs.btrfs  -m DUP -d DUP -b 200M /dev/data/btrfs -f
 btrfs-progs v4.17.1
 See http://btrfs.wiki.kernel.org for more information.

 ERROR: size 209715200 is too small to make a usable filesystem
 ERROR: minimum size for btrfs filesystem is 240123904

This problem applies to all patches, unfortunately.

Thanks,
Qu

>  _scratch_mount
>  out=$SCRATCH_MNT/fillup.$$
> 



signature.asc
Description: OpenPGP digital signature


Re: [PATCH 1/9] fstests: btrfs: _scratch_mkfs_sized fix min size without mixed option

2018-09-24 Thread Qu Wenruo


On 2018/9/24 下午6:16, Anand Jain wrote:
> As of now _scratch_mkfs_sized check if the requested size is below 1G
> and forces the --mixed option for the mkfs.btrfs. Well the correct size
> at which we need to force the mixed option is 114294784bytes. Fix that.

How this size is get from?
If it's from btrfs_min_dev_size(), I strongly recommend to add reference
here, and don't use the ugly intermediate number.


BTW, this number is related to mkfs profile.
If you really want to use some maximum number, please follow the max
possible value in btrfs_min_dev_size(), which should be 229M other than
106M.

Thanks,
Qu

> 
> Signed-off-by: Anand Jain 
> ---
>  common/rc | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/common/rc b/common/rc
> index d5bb1feee2c3..bcdbf03e1bf0 100644
> --- a/common/rc
> +++ b/common/rc
> @@ -969,7 +969,9 @@ _scratch_mkfs_sized()
>   ;;
>  btrfs)
>   local mixed_opt=
> - (( fssize <= 1024 * 1024 * 1024 )) && mixed_opt='--mixed'
> + # minimum size that's needed without the mixed option.
> + # Non mixed mode is also the default option.
> + (( fssize < 114294784 )) && mixed_opt='--mixed'
>   $MKFS_BTRFS_PROG $MKFS_OPTIONS $mixed_opt -b $fssize $SCRATCH_DEV
>   ;;
>  jfs)
> 



signature.asc
Description: OpenPGP digital signature


[PATCH 5/9] generic/102 open code dev_size _scratch_mkfs_sized()

2018-09-24 Thread Anand Jain
Open code helps to grep and find out parameter sent to the
_scratch_mkfs_sized here.

Signed-off-by: Anand Jain 
---
 tests/generic/102 | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/tests/generic/102 b/tests/generic/102
index faf940ac5070..aad496a5bc69 100755
--- a/tests/generic/102
+++ b/tests/generic/102
@@ -31,8 +31,7 @@ _require_scratch
 
 rm -f $seqres.full
 
-dev_size=$((512 * 1024 * 1024)) # 512MB filesystem
-_scratch_mkfs_sized $dev_size >>$seqres.full 2>&1
+_scratch_mkfs_sized $((512 * 1024 * 1024)) >>$seqres.full 2>&1
 _scratch_mount
 
 for ((i = 0; i < 10; i++)); do
-- 
1.8.3.1



[PATCH 7/9] generic/312 open code fs_size _scratch_mkfs_sized()

2018-09-24 Thread Anand Jain
fs_size isn't used anywhere else further more now grep tells what size
is being used.

Signed-off-by: Anand Jain 
---
 tests/generic/312 | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/tests/generic/312 b/tests/generic/312
index 756f5c3e4c5a..465009c8d184 100755
--- a/tests/generic/312
+++ b/tests/generic/312
@@ -34,11 +34,10 @@ _supported_os Linux
 _require_xfs_io_command "falloc"
 _require_scratch
 
-# 5G in byte
-fssize=$((2**30 * 5))
-
 rm -f $seqres.full
-_scratch_mkfs_sized $fssize >>$seqres.full 2>&1
+
+# 5G FS
+_scratch_mkfs_sized $((2**30 * 5)) >>$seqres.full 2>&1
 _scratch_mount >>$seqres.full 2>&1
 
 echo "Silence is golden"
-- 
1.8.3.1



[PATCH 8/9] generic/449 fix fs size for _scratch_mkfs_sized for btrfs

2018-09-24 Thread Anand Jain
btrfs needs ~200m to create btrfs with default options like non mixed
block groups.

Signed-off-by: Anand Jain 
---
 tests/generic/449 | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tests/generic/449 b/tests/generic/449
index 88f918654b54..47c219222dde 100755
--- a/tests/generic/449
+++ b/tests/generic/449
@@ -41,7 +41,7 @@ _require_test
 _require_acls
 _require_attrs
 
-_scratch_mkfs_sized $((50 * 1024 * 1024)) >> $seqres.full 2>&1
+_scratch_mkfs_sized $((200 * 1024 * 1024)) >> $seqres.full 2>&1
 _scratch_mount || _fail "mount failed"
 
 TFILE=$SCRATCH_MNT/testfile.$seq
@@ -52,7 +52,7 @@ chmod u+rwx $TFILE
 chmod go-rwx $TFILE
 
 # Try to run out of space so setfacl will fail
-$XFS_IO_PROG -c "pwrite 0 50m" $TFILE >>$seqres.full 2>&1
+$XFS_IO_PROG -c "pwrite 0 200m" $TFILE >>$seqres.full 2>&1
 i=1
 
 # Setting acls on an xfs filesystem will succeed even after running out of
-- 
1.8.3.1



[PATCH 9/9] generic/387 fix _scratch_mkfs_sized option for btrfs

2018-09-24 Thread Anand Jain
btrfs needs 200mb to create a fs with default block group which is non
mixed, so pass 200mb to _scratch_mkfs_sized().

Signed-off-by: Anand Jain 
---
 tests/generic/387 | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tests/generic/387 b/tests/generic/387
index 68a48012faa5..9d9d65d222c8 100755
--- a/tests/generic/387
+++ b/tests/generic/387
@@ -35,7 +35,8 @@ _supported_fs generic
 _supported_os Linux
 _require_scratch_reflink
 
-_scratch_mkfs_sized $((32 * 1024 * 1024)) >> $seqres.full 2>&1
+#btrfs needs ~200mb to create default blockgroup fs
+_scratch_mkfs_sized $((200 * 1024 * 1024)) >> $seqres.full 2>&1
 _scratch_mount
 
 testfile=$SCRATCH_MNT/testfile
-- 
1.8.3.1



[PATCH 0/9] Fix _scratch_mkfs_sized() for btrfs

2018-09-24 Thread Anand Jain
Currently _scratch_mkfs_sized() checks if requested size for the fs
is below 1G for btrfs and forces the --mixed mkfs option. The 1G size
cut off is too larger where the actual size is 114294784 bytes. The
patch 1/9 fixes the _scratch_mkfs_sized() to check for 114294784
bytes instead. By this now we test the default config (non mixed).
And the mixed option may still be tested using the MKFS_OPTIONS.
This change only affect btrfs FS and test cases using the
_scratch_mkfs_sized() in generic and btrfs.


Also, to make sure btrfs is created in non-mixed mode, so in each individual 
test cases we need to make sure that _scratch_mkfs_sized()
been requested to create a FS of at least 200mb in size (114294784
bytes rounded off to the nearest 100). And there are few test
cases which does not do that, Patches [2,3,4,8,9]/9 fixes them.
These changes affects all FS as such.

And there are some test cases where we use local
variable as an option for the _scratch_mkfs_sized() is being used
and this local variable is not used anywhere else with in the test
case. So patches [5,6,7]/9 drops the local variable and open codes
it. This is a straight forward change as the fs size is kept same
as in the original.

Further, there are test cases generic/250,252,256 which uses
_scratch_mkfs_sized with < 200mb but its fix isn't straight forward
and they are not yet ready for the review.

The affected testcases (which calls _scratch_mkfs_sized) [1] have
been tested with xfs/ext4 and btrfs. And there are no regressions.

[1]
generic/015 generic/027 generic/077 generic/081 generic/083 generic/085 
generic/096 generic/102 generic/171 generic/172 generic/173 generic/174 
generic/204 generic/224 generic/226 generic/250 generic/252 generic/256 
generic/269 generic/270 generic/273 generic/274 generic/275 generic/300 
generic/312 generic/320 generic/333 generic/334 generic/361 generic/371 
generic/387 generic/399 generic/416 generic/427 generic/449 generic/459 
generic/466 generic/488 generic/505 btrfs/004 btrfs/007 btrfs/132 btrfs/170

Anand Jain (9):
  fstests: btrfs: _scratch_mkfs_sized fix min size without mixed option
  generic/015 fix to test the default non-mixed mode
  geneirc/077 fix min size for btrfs
  generic/083 create at least 200mb fs
  generic/102 open code dev_size _scratch_mkfs_sized()
  generic/204 open code SIZE for _scratch_mkfs_sized()
  generic/312 open code fs_size _scratch_mkfs_sized()
  generic/449 fix fs size for _scratch_mkfs_sized for btrfs
  generic/387 fix _scratch_mkfs_sized option for btrfs

 common/rc | 4 +++-
 tests/generic/015 | 9 -
 tests/generic/077 | 3 +--
 tests/generic/083 | 2 +-
 tests/generic/102 | 3 +--
 tests/generic/204 | 3 +--
 tests/generic/312 | 7 +++
 tests/generic/387 | 3 ++-
 tests/generic/449 | 4 ++--
 9 files changed, 18 insertions(+), 20 deletions(-)

-- 
1.8.3.1



[PATCH 1/9] fstests: btrfs: _scratch_mkfs_sized fix min size without mixed option

2018-09-24 Thread Anand Jain
As of now _scratch_mkfs_sized check if the requested size is below 1G
and forces the --mixed option for the mkfs.btrfs. Well the correct size
at which we need to force the mixed option is 114294784bytes. Fix that.

Signed-off-by: Anand Jain 
---
 common/rc | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/common/rc b/common/rc
index d5bb1feee2c3..bcdbf03e1bf0 100644
--- a/common/rc
+++ b/common/rc
@@ -969,7 +969,9 @@ _scratch_mkfs_sized()
;;
 btrfs)
local mixed_opt=
-   (( fssize <= 1024 * 1024 * 1024 )) && mixed_opt='--mixed'
+   # minimum size that's needed without the mixed option.
+   # Non mixed mode is also the default option.
+   (( fssize < 114294784 )) && mixed_opt='--mixed'
$MKFS_BTRFS_PROG $MKFS_OPTIONS $mixed_opt -b $fssize $SCRATCH_DEV
;;
 jfs)
-- 
1.8.3.1



[PATCH 3/9] geneirc/077 fix min size for btrfs

2018-09-24 Thread Anand Jain
If btrfs need to be tested at its default blockgroup which is non-mixed,
then it needs at least ~200mb (upward round off to nearest 100'),
instead of 50mb use 200mb to test this test case.

Signed-off-by: Anand Jain 
---
 tests/generic/077 | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/tests/generic/077 b/tests/generic/077
index ef6af18c83e3..60c3493451c7 100755
--- a/tests/generic/077
+++ b/tests/generic/077
@@ -49,8 +49,7 @@ rm -f $seqres.full
 _scratch_unmount >/dev/null 2>&1
 echo "*** MKFS ***" >>$seqres.full
 echo "" >>$seqres.full
-SIZE=`expr 50 \* 1024 \* 1024`
-_scratch_mkfs_sized $SIZE   >>$seqres.full 2>&1 \
+_scratch_mkfs_sized $((200 * 1024 *1024))   >>$seqres.full 2>&1 \
|| _fail "mkfs failed"
 _scratch_mount
 mkdir $SCRATCH_MNT/subdir
-- 
1.8.3.1



[PATCH 4/9] generic/083 create at least 200mb fs

2018-09-24 Thread Anand Jain
btrfs needs at least ~200mb to create a FS with the defaults options,
so instead of 100mb create 200mb sized fs.

Signed-off-by: Anand Jain 
---
 tests/generic/083 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/generic/083 b/tests/generic/083
index 63d96ba2ab88..e5f0a88ef221 100755
--- a/tests/generic/083
+++ b/tests/generic/083
@@ -71,7 +71,7 @@ workout()
 
 echo "*** test out-of-space handling for random write operations"
 
-filesize=`expr 100 \* 1024 \* 1024`
+filesize=`expr 200 \* 1024 \* 1024`
 agcount=6
 numprocs=15
 numops=1500
-- 
1.8.3.1



[PATCH 6/9] generic/204 open code SIZE for _scratch_mkfs_sized()

2018-09-24 Thread Anand Jain
By open code we could grep to find out FS size being use by this test
case.

Signed-off-by: Anand Jain 
---
 tests/generic/204 | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/tests/generic/204 b/tests/generic/204
index 349f5eff351f..576c4eabd359 100755
--- a/tests/generic/204
+++ b/tests/generic/204
@@ -42,8 +42,7 @@ _scratch_mkfs 2> /dev/null | _filter_mkfs 2> $tmp.mkfs > 
/dev/null
 # time solves this problem.
 [ $FSTYP = "xfs" ] && MKFS_OPTIONS="$MKFS_OPTIONS -l size=16m -i maxpct=50"
 
-SIZE=`expr 115 \* 1024 \* 1024`
-_scratch_mkfs_sized $SIZE $dbsize 2> /dev/null > $tmp.mkfs.raw
+_scratch_mkfs_sized $((115 * 1024 * 1024)) $dbsize 2> /dev/null > $tmp.mkfs.raw
 cat $tmp.mkfs.raw | _filter_mkfs 2> $tmp.mkfs > /dev/null
 _scratch_mount
 
-- 
1.8.3.1



[PATCH 2/9] generic/015 fix to test the default non-mixed mode

2018-09-24 Thread Anand Jain
commit 97575acd7495 (generic/015: Change the test filesystem size to
101mb), created 101mb FS instead of 100mb FS to make sure we create
a FS which is non mixed mode, which is our default mode.

btrfs-progs commit 18e2663db3e1 (btrfs-progs: Add minimum device size
check) added a more accurate minimum required space to create the btrfs
FS in non mixed mode. Which is at 14294784 bytes.

So this patch changes the FS size to be created by _scratch_sized_mkfs
to 200mb so that we create the FS in non mixed mode.

To test mixed blockgroup its better we set it using the MKFS_OPTIONS
explicitly.

Signed-off-by: Anand Jain 
---
 tests/generic/015 | 9 -
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/tests/generic/015 b/tests/generic/015
index 0f4d29800f4f..14941ab6d552 100755
--- a/tests/generic/015
+++ b/tests/generic/015
@@ -37,11 +37,10 @@ _supported_os Linux
 _require_scratch
 _require_no_large_scratch_dev
 
-# With filesystems less than 100mb btrfs is created in mixed mode
-# which can lead to slight accounting errors of 1mb. Having the
-# fs be at least 101 mb ensures those errors are within the error
-# tolerance of 1%
-_scratch_mkfs_sized `expr 101 \* 1024 \* 1024` >/dev/null 2>&1 \
+# With filesystems less than ~200mb _scratch_mkfs_sized will create
+# data and metadata mixed mode btrfs, so use 200mb so that we test
+# the default btrfs.
+_scratch_mkfs_sized $((200 * 1024 * 1024)) >> $seqres.full 2>&1 \
 || _fail "mkfs failed"
 _scratch_mount
 out=$SCRATCH_MNT/fillup.$$
-- 
1.8.3.1



Re: python-btrfs v10 preview... detailed usage reporting and a tutorial

2018-09-24 Thread Nikolay Borisov



On 24.09.2018 00:54, Hans van Kranenburg wrote:


.
> 
> The bugs are all related to repeated kernel code all over the place
> containing a lot of if statements dealing with different kind of
> allocation profiles and their exceptions. What I ended up doing is
> making a few helper functions instead, see the commit "Add volumes.py,
> handling device / chunk logic". It would probably be nice to do the same
> in the kernel code, which would also solve the mentioned bugs and
> prevent new similar ones from happening.

Would you care to report each bug separately so they can be triaged and
fixed?

> 
> Have fun,
>