[PATCH v2] Btrfs: reserve enough space for file clone

2011-07-29 Thread Li Zefan
  # mount -t btrfs /dev/sda7 /mnt
  # dd if=/dev/zero of=/mnt/src bs=10K count=1
  # sync
  # clone 4K from /mnt/src to /mnt/dst

kernel BUG at fs/btrfs/delayed-inode.c:1693!

We should reserve space for both file extent item insertion and
inode update.

Signed-off-by: Li Zefan l...@cn.fujitsu.com
---

v2:

- fix typo: s/reverse/reserve

---
 fs/btrfs/ioctl.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 0b980af..05af14c 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -2314,7 +2314,7 @@ static noinline long btrfs_ioctl_clone(struct file *file, 
unsigned long srcfd,
else
new_key.offset = destoff;
 
-   trans = btrfs_start_transaction(root, 1);
+   trans = btrfs_start_transaction(root, 2);
if (IS_ERR(trans)) {
ret = PTR_ERR(trans);
goto out;
-- 1.7.3.1 --
--
To unsubscribe from this list: send the line unsubscribe linux-btrfs in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2] Btrfs: reserve enough space for file clone

2011-07-29 Thread Christoph Hellwig
On Fri, Jul 29, 2011 at 04:07:36PM +0800, Li Zefan wrote:
   # mount -t btrfs /dev/sda7 /mnt
   # dd if=/dev/zero of=/mnt/src bs=10K count=1
   # sync
   # clone 4K from /mnt/src to /mnt/dst
 
 kernel BUG at fs/btrfs/delayed-inode.c:1693!

Sounds like a regression test you should add to xfstests.
--
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/4] fs: add SEEK_HOLE and SEEK_DATA flags

2011-07-29 Thread Marco Stornelli

Sorry maybe I'm a bit late? :)

Il 28/06/2011 17:33, Josef Bacik ha scritto:


  loff_t default_llseek(struct file *file, loff_t offset, int origin)
  {
+   struct inode *inode = file-f_path.dentry-d_inode;
loff_t retval;

-   mutex_lock(file-f_dentry-d_inode-i_mutex);
+   mutex_lock(inode-i_mutex);
switch (origin) {
case SEEK_END:
-   offset += i_size_read(file-f_path.dentry-d_inode);
+   offset += i_size_read(inode);


Here we are under mutex, so I think we can use directly i_size without 
i_size_read.


Marco
--
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: do not allow mounting non-subvolumes via subvol option

2011-07-29 Thread Goffredo Baroncelli

Hi David,

On 07/29/2011 12:14 PM, David Sterba wrote:

There's a missing test whether the path passed to subvol=path option
during mount is a real subvolume, allowing any directory located in
default subovlume to be passed and accepted for mount.

(current btrfs progs prevent this early)
$ btrfs subvol snapshot . p1-snap
ERROR: '.' is not a subvolume

(with is subvolume? test bypassed)
$ btrfs subvol snapshot . p1-snap
Create a snapshot of '.' in './p1-snap'

$ btrfs subvol list -p .
ID 258 parent 5 top level 5 path subvol
ID 259 parent 5 top level 5 path subvol1
ID 260 parent 5 top level 5 path default-subvol1
ID 262 parent 5 top level 5 path p1/p1-snapshot
ID 263 parent 259 top level 5 path subvol1/subvol1-snap

The problem I see is that this makes a false impression of snapshotting the
given subvolume but in fact snapshots the default one: a user expects outcome


Not that matter too much, but the old behavior was to snapshot not the 
default one but the one which contains the directory.
This behavior leaded to a lot of misunderstanding about the btrfs 
capability of snapshot subvolume __only__.


Only one question, what happens now if an user pass subvol=dir ?


like ID 263 but in fact gets ID 262 .

This patch makes mount fail with EINVAL with a message in syslog.

Signed-off-by: David Sterbadste...@suse.cz
---

I did not find a better errno than EINVAL, probably adding someting like
ENSUBVOL would be better so that other filesystems with such functionality may
use it in future.

  fs/btrfs/super.c |   19 +++
  1 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index 15634d4..0c2a1d1 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -753,6 +753,15 @@ static int btrfs_set_super(struct super_block *s, void 
*data)
return set_anon_super(s, data);
  }

+/*
+ * subvolumes are identified by ino 256
+ */
+static inline int is_subvolume_inode(struct inode *inode)
+{
+   if (inode  inode-i_ino == BTRFS_FIRST_FREE_OBJECTID)
+   return 1;
+   return 0;
+}

  /*
   * Find a superblock for the given device / mount point.
@@ -873,6 +882,16 @@ static struct dentry *btrfs_mount(struct file_system_type 
*fs_type, int flags,
error = -ENXIO;
goto error_free_subvol_name;
}
+
+   if (!is_subvolume_inode(new_root-d_inode)) {
+   dput(root);
+   dput(new_root);
+   deactivate_locked_super(s);
+   error = -EINVAL;
+   printk(KERN_ERR btrfs: '%s' is not a valid 
subvolume\n,
+   subvol_name);
+   goto error_free_subvol_name;
+   }
dput(root);
root = new_root;
} else {


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