* [PATCH] Btrfs: avoid setting ->d_op twice
@ 2012-02-21 9:04 Li Zefan
2012-02-21 14:52 ` David Sterba
0 siblings, 1 reply; 3+ messages in thread
From: Li Zefan @ 2012-02-21 9:04 UTC (permalink / raw)
To: linux-btrfs@vger.kernel.org
Follow those instructions, and you'll trigger a warning in the
beginning of d_set_d_op():
# mkfs.btrfs /dev/loop3
# mount /dev/loop3 /mnt
# btrfs sub create /mnt/sub
# btrfs sub snap /mnt /mnt/snap
# touch /mnt/snap/sub
touch: cannot touch `tmp': Permission denied
__d_alloc() set d_op to sb->s_d_op (btrfs_dentry_operations), and
then simple_lookup() reset it to simple_dentry_operations, which
triggered the warning.
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
---
fs/btrfs/inode.c | 14 +++++++++-----
1 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 32214fe..2a623cc 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -3908,7 +3908,7 @@ static struct inode *new_simple_dir(struct super_block *s,
BTRFS_I(inode)->dummy_inode = 1;
inode->i_ino = BTRFS_EMPTY_SUBVOL_DIR_OBJECTID;
- inode->i_op = &simple_dir_inode_operations;
+ inode->i_op = &btrfs_dir_ro_inode_operations;
inode->i_fop = &simple_dir_operations;
inode->i_mode = S_IFDIR | S_IRUGO | S_IWUSR | S_IXUGO;
inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
@@ -3979,14 +3979,18 @@ struct inode *btrfs_lookup_dentry(struct inode *dir, struct dentry *dentry)
static int btrfs_dentry_delete(const struct dentry *dentry)
{
struct btrfs_root *root;
+ struct inode *inode = dentry->d_inode;
- if (!dentry->d_inode && !IS_ROOT(dentry))
- dentry = dentry->d_parent;
+ if (!inode && !IS_ROOT(dentry))
+ inode = dentry->d_parent->d_inode;
- if (dentry->d_inode) {
- root = BTRFS_I(dentry->d_inode)->root;
+ if (inode) {
+ root = BTRFS_I(inode)->root;
if (btrfs_root_refs(&root->root_item) == 0)
return 1;
+
+ if (btrfs_ino(inode) == BTRFS_EMPTY_SUBVOL_DIR_OBJECTID)
+ return 1;
}
return 0;
}
--
1.7.3.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] Btrfs: avoid setting ->d_op twice
2012-02-21 9:04 [PATCH] Btrfs: avoid setting ->d_op twice Li Zefan
@ 2012-02-21 14:52 ` David Sterba
2012-02-22 1:29 ` Li Zefan
0 siblings, 1 reply; 3+ messages in thread
From: David Sterba @ 2012-02-21 14:52 UTC (permalink / raw)
To: Li Zefan; +Cc: linux-btrfs@vger.kernel.org
Hi,
thanks for the patch!
On Tue, Feb 21, 2012 at 05:04:28PM +0800, Li Zefan wrote:
> Follow those instructions, and you'll trigger a warning in the
> beginning of d_set_d_op():
>
> # mkfs.btrfs /dev/loop3
> # mount /dev/loop3 /mnt
> # btrfs sub create /mnt/sub
> # btrfs sub snap /mnt /mnt/snap
> # touch /mnt/snap/sub
> touch: cannot touch `tmp': Permission denied
is this the right error code? permission denied == EACCESS and this is
returned in case of file
(strace touch file)
open("file", O_WRONLY|O_CREAT|O_NOCTTY|O_NONBLOCK, 0666) = -1 EACCES (Permission denied)
while mkdir returns (strace mkdir a-dir)
mkdir("a-dir", 0777) = -1 EPERM (Operation not permitted)
The commands were run as root and EPERM looks more adequate than
EACCESS.
david
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Btrfs: avoid setting ->d_op twice
2012-02-21 14:52 ` David Sterba
@ 2012-02-22 1:29 ` Li Zefan
0 siblings, 0 replies; 3+ messages in thread
From: Li Zefan @ 2012-02-22 1:29 UTC (permalink / raw)
To: David Sterba; +Cc: linux-btrfs@vger.kernel.org
David Sterba wrote:
> Hi,
>
> thanks for the patch!
>
> On Tue, Feb 21, 2012 at 05:04:28PM +0800, Li Zefan wrote:
>> Follow those instructions, and you'll trigger a warning in the
>> beginning of d_set_d_op():
>>
>> # mkfs.btrfs /dev/loop3
>> # mount /dev/loop3 /mnt
>> # btrfs sub create /mnt/sub
>> # btrfs sub snap /mnt /mnt/snap
>> # touch /mnt/snap/sub
>> touch: cannot touch `tmp': Permission denied
>
> is this the right error code? permission denied == EACCESS and this is
> returned in case of file
>
> (strace touch file)
>
> open("file", O_WRONLY|O_CREAT|O_NOCTTY|O_NONBLOCK, 0666) = -1 EACCES (Permission denied)
>
> while mkdir returns (strace mkdir a-dir)
>
> mkdir("a-dir", 0777) = -1 EPERM (Operation not permitted)
>
>
> The commands were run as root and EPERM looks more adequate than
> EACCESS.
>
This is a different issue, and EPERM is returned by VFS not btrfs.
Feel free to submit a patch to fsdevel for discussion.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-02-22 1:29 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-21 9:04 [PATCH] Btrfs: avoid setting ->d_op twice Li Zefan
2012-02-21 14:52 ` David Sterba
2012-02-22 1:29 ` Li Zefan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).