Re: [PATCH] Btrfs: Improve FL_KEEP_SIZE handling in fallocate.

2015-10-21 Thread Davide Italiano
On Wed, Jul 22, 2015 at 10:45 AM, Davide Italiano <dccitali...@gmail.com> wrote:
> On Fri, Jun 26, 2015 at 7:08 AM, David Sterba <dste...@suse.cz> wrote:
>> On Mon, Apr 06, 2015 at 10:09:15PM -0700, Davide Italiano wrote:
>>> - We call inode_size_ok() only if FL_KEEP_SIZE isn't specified.
>>> - As an optimisation we can skip the call if (off + len)
>>>   isn't greater than the current size of the file. This operation
>>>   is called under the lock so the less work we do, the better.
>>> - If we call inode_size_ok() pass to it the correct value rather
>>>   than a more conservative estimation.
>>>
>>> Signed-off-by: Davide Italiano <dccitali...@gmail.com>
>>
>> Reviewed-by: David Sterba <dste...@suse.cz>
>
> Hi Chris, this has been around for a while and it's been reviewed by
> multiple people. Any chances you can pull in your branch?
>
> Thanks,
>
> --
> Davide

Any chance to get this in?
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] Btrfs: Improve FL_KEEP_SIZE handling in fallocate.

2015-07-22 Thread Davide Italiano
On Fri, Jun 26, 2015 at 7:08 AM, David Sterba dste...@suse.cz wrote:
 On Mon, Apr 06, 2015 at 10:09:15PM -0700, Davide Italiano wrote:
 - We call inode_size_ok() only if FL_KEEP_SIZE isn't specified.
 - As an optimisation we can skip the call if (off + len)
   isn't greater than the current size of the file. This operation
   is called under the lock so the less work we do, the better.
 - If we call inode_size_ok() pass to it the correct value rather
   than a more conservative estimation.

 Signed-off-by: Davide Italiano dccitali...@gmail.com

 Reviewed-by: David Sterba dste...@suse.cz

Hi Chris, this has been around for a while and it's been reviewed by
multiple people. Any chances you can pull in your branch?

Thanks,

--
Davide
--
To unsubscribe from this list: send the line unsubscribe linux-btrfs in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/2] [btrfs] btrfs_rename: abort transaction in case of error.

2015-06-29 Thread Davide Italiano
On Mon, Jun 29, 2015 at 4:59 AM, Filipe David Manana fdman...@gmail.com wrote:
 On Sun, Jun 28, 2015 at 10:47 PM, Davide C. C. Italiano
 dccitali...@gmail.com wrote:
 From: Davide Italiano dccitali...@gmail.com

 btrfs_insert_inode_ref() may fail and we want to make sure
 the transaction is aborted before calling btrfs_end_transaction(),
 as it already happens everywhere else in this function in case
 of error.

 Signed-off-by: Davide Italiano dccitali...@gmail.com
 ---
  fs/btrfs/inode.c | 5 -
  1 file changed, 4 insertions(+), 1 deletion(-)

 diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
 index 8bb0136..59c475c 100644
 --- a/fs/btrfs/inode.c
 +++ b/fs/btrfs/inode.c
 @@ -9114,8 +9114,11 @@ static int btrfs_rename(struct inode *old_dir, struct 
 dentry *old_dentry,
  new_dentry-d_name.len,
  old_ino,
  btrfs_ino(new_dir), index);
 -   if (ret)
 +   if (ret) {
 +   btrfs_abort_transaction(trans, root, ret);
 goto out_fail;
 +   }
 +

 Hi,

 I don't think we need a transaction abortion here. The reason it's not
 being done is likely because at that point the trees are in a
 consistent state (i.e. we haven't touched any of them yet) and not
 because it was forgotten. So an abortion there is
 unnecessary/excessive.

 thanks


Thank you for the comment -- I updated the other patch and I have
mixed feeling about this one.
I can either withdrawn the review or provide a new patch where I add a
comment to clarify why this is not needed, for the future.
Which one do you like better?

--
Davide
--
To unsubscribe from this list: send the line unsubscribe linux-btrfs in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] Btrfs: Improve FL_KEEP_SIZE handling in fallocate.

2015-06-25 Thread Davide Italiano
On Mon, Apr 20, 2015 at 1:49 PM, Davide Italiano dccitali...@gmail.com wrote:
 On Mon, Apr 6, 2015 at 10:09 PM, Davide Italiano dccitali...@gmail.com 
 wrote:
 - We call inode_size_ok() only if FL_KEEP_SIZE isn't specified.
 - As an optimisation we can skip the call if (off + len)
   isn't greater than the current size of the file. This operation
   is called under the lock so the less work we do, the better.
 - If we call inode_size_ok() pass to it the correct value rather
   than a more conservative estimation.

 Signed-off-by: Davide Italiano dccitali...@gmail.com
 ---
  fs/btrfs/file.c | 10 +++---
  1 file changed, 7 insertions(+), 3 deletions(-)

 diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
 index 30982bb..f649bfc 100644
 --- a/fs/btrfs/file.c
 +++ b/fs/btrfs/file.c
 @@ -2586,9 +2586,13 @@ static long btrfs_fallocate(struct file *file, int 
 mode,
 }

 mutex_lock(inode-i_mutex);
 -   ret = inode_newsize_ok(inode, alloc_end);
 -   if (ret)
 -   goto out;
 +
 +   if (!(mode  FALLOC_FL_KEEP_SIZE) 
 +   offset + len  inode-i_size) {
 +   ret = inode_newsize_ok(inode, offset + len);
 +   if (ret)
 +   goto out;
 +   }

 if (alloc_start  inode-i_size) {
 ret = btrfs_cont_expand(inode, i_size_read(inode),
 --
 2.3.4


 Any comment on this?

Very gentle ping after couple of months.
--
To unsubscribe from this list: send the line unsubscribe linux-btrfs in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] Btrfs: Improve FL_KEEP_SIZE handling in fallocate.

2015-04-20 Thread Davide Italiano
On Mon, Apr 6, 2015 at 10:09 PM, Davide Italiano dccitali...@gmail.com wrote:
 - We call inode_size_ok() only if FL_KEEP_SIZE isn't specified.
 - As an optimisation we can skip the call if (off + len)
   isn't greater than the current size of the file. This operation
   is called under the lock so the less work we do, the better.
 - If we call inode_size_ok() pass to it the correct value rather
   than a more conservative estimation.

 Signed-off-by: Davide Italiano dccitali...@gmail.com
 ---
  fs/btrfs/file.c | 10 +++---
  1 file changed, 7 insertions(+), 3 deletions(-)

 diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
 index 30982bb..f649bfc 100644
 --- a/fs/btrfs/file.c
 +++ b/fs/btrfs/file.c
 @@ -2586,9 +2586,13 @@ static long btrfs_fallocate(struct file *file, int 
 mode,
 }

 mutex_lock(inode-i_mutex);
 -   ret = inode_newsize_ok(inode, alloc_end);
 -   if (ret)
 -   goto out;
 +
 +   if (!(mode  FALLOC_FL_KEEP_SIZE) 
 +   offset + len  inode-i_size) {
 +   ret = inode_newsize_ok(inode, offset + len);
 +   if (ret)
 +   goto out;
 +   }

 if (alloc_start  inode-i_size) {
 ret = btrfs_cont_expand(inode, i_size_read(inode),
 --
 2.3.4


Any comment on this?
--
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] Improve FL_KEEP_SIZE handling

2015-04-06 Thread Davide Italiano
This matches the logic of ext4. I think it's more
correct passing (offset + len) to inode_newsize_ok() 
rather than rounding up to block size.
The call can be skipped in some cases too. It works for
me but I'm new to this code so I might miss something.
Let me know what you think.

Davide Italiano (1):
  Btrfs: Improve FL_KEEP_SIZE handling in fallocate.

 fs/btrfs/file.c | 10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

-- 
2.3.4

--
To unsubscribe from this list: send the line unsubscribe linux-btrfs in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] Btrfs: Improve FL_KEEP_SIZE handling in fallocate.

2015-04-06 Thread Davide Italiano
- We call inode_size_ok() only if FL_KEEP_SIZE isn't specified.
- As an optimisation we can skip the call if (off + len)
  isn't greater than the current size of the file. This operation
  is called under the lock so the less work we do, the better.
- If we call inode_size_ok() pass to it the correct value rather
  than a more conservative estimation.

Signed-off-by: Davide Italiano dccitali...@gmail.com
---
 fs/btrfs/file.c | 10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index 30982bb..f649bfc 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -2586,9 +2586,13 @@ static long btrfs_fallocate(struct file *file, int mode,
}
 
mutex_lock(inode-i_mutex);
-   ret = inode_newsize_ok(inode, alloc_end);
-   if (ret)
-   goto out;
+
+   if (!(mode  FALLOC_FL_KEEP_SIZE) 
+   offset + len  inode-i_size) {
+   ret = inode_newsize_ok(inode, offset + len);
+   if (ret)
+   goto out;
+   }
 
if (alloc_start  inode-i_size) {
ret = btrfs_cont_expand(inode, i_size_read(inode),
-- 
2.3.4

--
To unsubscribe from this list: send the line unsubscribe linux-btrfs in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] Btrfs: RENAME_EXCHANGE semantic for renameat2()

2015-04-01 Thread Davide Italiano
Signed-off-by: Davide Italiano dccitali...@gmail.com
---
 fs/btrfs/inode.c | 190 ++-
 1 file changed, 189 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index d2e732d..49b0867 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -8890,6 +8890,190 @@ static int btrfs_getattr(struct vfsmount *mnt,
return 0;
 }
 
+static int btrfs_cross_rename(struct inode *old_dir, struct dentry *old_dentry,
+ struct inode *new_dir, struct dentry *new_dentry)
+{
+   struct btrfs_trans_handle *trans;
+   struct btrfs_root *root = BTRFS_I(old_dir)-root;
+   struct btrfs_root *dest = BTRFS_I(new_dir)-root;
+   struct inode *new_inode = new_dentry-d_inode;
+   struct inode *old_inode = old_dentry-d_inode;
+   struct timespec ctime = CURRENT_TIME;
+   u64 old_ino = btrfs_ino(old_inode);
+   u64 new_ino = btrfs_ino(new_inode);
+   u64 old_idx = 0;
+   u64 new_idx = 0;
+   u64 root_objectid;
+   int ret;
+
+   /* we only allow rename subvolume link between subvolumes */
+   if (old_ino != BTRFS_FIRST_FREE_OBJECTID  root != dest)
+   return -EXDEV;
+
+   /* close the racy window with snapshot create/destroy ioctl */
+   if (old_ino == BTRFS_FIRST_FREE_OBJECTID)
+   down_read(root-fs_info-subvol_sem);
+   if (new_ino == BTRFS_FIRST_FREE_OBJECTID)
+   down_read(dest-fs_info-subvol_sem);
+
+   /*
+* We want to reserve the absolute worst case amount of items.  So if
+* both inodes are subvols and we need to unlink them then that would
+* require 4 item modifications, but if they are both normal inodes it
+* would require 5 item modifications, so we'll assume their normal
+* inodes.  So 5 * 2 is 10, plus 2 for the new links, so 12 total items
+* should cover the worst case number of items we'll modify.
+*/
+   trans = btrfs_start_transaction(root, 12);
+   if (IS_ERR(trans)) {
+ret = PTR_ERR(trans);
+goto out_notrans;
+}
+
+   /*
+* We need to find a free sequence number both in the source and
+* in the destination directory for the exchange.
+*/
+   ret = btrfs_set_inode_index(new_dir, old_idx);
+   if (ret)
+   goto out_fail;
+   ret = btrfs_set_inode_index(old_dir, new_idx);
+   if (ret)
+   goto out_fail;
+
+   BTRFS_I(old_inode)-dir_index = 0ULL;
+   BTRFS_I(new_inode)-dir_index = 0ULL;
+
+   /* Reference for the source. */
+   if (unlikely(old_ino == BTRFS_FIRST_FREE_OBJECTID)) {
+   /* force full log commit if subvolume involved. */
+   btrfs_set_log_full_commit(root-fs_info, trans);
+   } else {
+   ret = btrfs_insert_inode_ref(trans, dest,
+new_dentry-d_name.name,
+new_dentry-d_name.len,
+old_ino,
+btrfs_ino(new_dir), old_idx);
+   if (ret)
+   goto out_fail;
+   btrfs_pin_log_trans(root);
+   }
+
+   /* And now for the dest. */
+   if (unlikely(new_ino == BTRFS_FIRST_FREE_OBJECTID)) {
+   /* force full log commit if subvolume involved. */
+   btrfs_set_log_full_commit(dest-fs_info, trans);
+   } else {
+   ret = btrfs_insert_inode_ref(trans, root,
+old_dentry-d_name.name,
+old_dentry-d_name.len,
+new_ino,
+btrfs_ino(old_dir), new_idx);
+   if (ret)
+   goto out_fail;
+   btrfs_pin_log_trans(dest);
+   }
+
+   /*
+* Update i-node version and ctime/mtime.
+*/
+   inode_inc_iversion(old_dir);
+   inode_inc_iversion(new_dir);
+   inode_inc_iversion(old_inode);
+   inode_inc_iversion(new_inode);
+   old_dir-i_ctime = old_dir-i_mtime = ctime;
+   new_dir-i_ctime = new_dir-i_mtime = ctime;
+   old_inode-i_ctime = ctime;
+   new_inode-i_ctime = ctime;
+
+   if (old_dentry-d_parent != new_dentry-d_parent) {
+   btrfs_record_unlink_dir(trans, old_dir, old_inode, 1);
+   btrfs_record_unlink_dir(trans, new_dir, new_inode, 1);
+   }
+
+   /* src is a subvolume */
+   if (unlikely(old_ino == BTRFS_FIRST_FREE_OBJECTID)) {
+   root_objectid = BTRFS_I(old_inode)-root-root_key.objectid;
+   ret = btrfs_unlink_subvol(trans, root, old_dir,
+ root_objectid,
+ old_dentry-d_name.name

[PATCH] Btrfs: implement RENAME_EXCHANGE semantic

2015-04-01 Thread Davide Italiano
This is an attempt to implement RENAME_EXCHANGE in btrfs.
It survived basic testing and I think it's ready for others' feedback.
I'll stress test {and, or} rewrite it depending on people's comments.

Davide Italiano (1):
  Btrfs: RENAME_EXCHANGE semantic for renameat2()

 fs/btrfs/inode.c | 190 ++-
 1 file changed, 189 insertions(+), 1 deletion(-)

-- 
2.3.4

--
To unsubscribe from this list: send the line unsubscribe linux-btrfs in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html