aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
Diffstat (limited to 'fs')
-rw-r--r--fs/9p/acl.c4
-rw-r--r--fs/9p/vfs_dentry.c4
-rw-r--r--fs/9p/vfs_dir.c2
-rw-r--r--fs/9p/vfs_inode.c34
-rw-r--r--fs/9p/vfs_inode_dotl.c16
-rw-r--r--fs/9p/vfs_super.c8
-rw-r--r--fs/adfs/inode.c2
-rw-r--r--fs/affs/amigaffs.c9
-rw-r--r--fs/affs/inode.c2
-rw-r--r--fs/affs/namei.c10
-rw-r--r--fs/afs/dir.c42
-rw-r--r--fs/afs/inode.c4
-rw-r--r--fs/afs/mntpt.c8
-rw-r--r--fs/afs/super.c2
-rw-r--r--fs/autofs4/autofs_i.h4
-rw-r--r--fs/autofs4/expire.c2
-rw-r--r--fs/autofs4/inode.c6
-rw-r--r--fs/autofs4/root.c18
-rw-r--r--fs/autofs4/symlink.c2
-rw-r--r--fs/autofs4/waitq.c4
-rw-r--r--fs/befs/linuxvfs.c4
-rw-r--r--fs/bfs/dir.c8
-rw-r--r--fs/binfmt_misc.c16
-rw-r--r--fs/block_dev.c5
-rw-r--r--fs/btrfs/async-thread.c4
-rw-r--r--fs/btrfs/async-thread.h2
-rw-r--r--fs/btrfs/backref.c4
-rw-r--r--fs/btrfs/btrfs_inode.h14
-rw-r--r--fs/btrfs/check-integrity.c9
-rw-r--r--fs/btrfs/compression.c4
-rw-r--r--fs/btrfs/compression.h4
-rw-r--r--fs/btrfs/ctree.c62
-rw-r--r--fs/btrfs/ctree.h46
-rw-r--r--fs/btrfs/delayed-inode.c9
-rw-r--r--fs/btrfs/delayed-ref.c22
-rw-r--r--fs/btrfs/delayed-ref.h10
-rw-r--r--fs/btrfs/dev-replace.c6
-rw-r--r--fs/btrfs/disk-io.c570
-rw-r--r--fs/btrfs/disk-io.h4
-rw-r--r--fs/btrfs/export.c6
-rw-r--r--fs/btrfs/extent-tree.c476
-rw-r--r--fs/btrfs/extent_io.c5
-rw-r--r--fs/btrfs/extent_io.h2
-rw-r--r--fs/btrfs/file-item.c6
-rw-r--r--fs/btrfs/file.c67
-rw-r--r--fs/btrfs/free-space-cache.c331
-rw-r--r--fs/btrfs/free-space-cache.h9
-rw-r--r--fs/btrfs/inode-map.c2
-rw-r--r--fs/btrfs/inode.c182
-rw-r--r--fs/btrfs/ioctl.c55
-rw-r--r--fs/btrfs/lzo.c2
-rw-r--r--fs/btrfs/math.h6
-rw-r--r--fs/btrfs/props.c2
-rw-r--r--fs/btrfs/qgroup.c348
-rw-r--r--fs/btrfs/qgroup.h3
-rw-r--r--fs/btrfs/raid56.c16
-rw-r--r--fs/btrfs/relocation.c11
-rw-r--r--fs/btrfs/scrub.c25
-rw-r--r--fs/btrfs/send.c83
-rw-r--r--fs/btrfs/super.c31
-rw-r--r--fs/btrfs/sysfs.c2
-rw-r--r--fs/btrfs/sysfs.h22
-rw-r--r--fs/btrfs/tests/qgroup-tests.c4
-rw-r--r--fs/btrfs/transaction.c54
-rw-r--r--fs/btrfs/transaction.h12
-rw-r--r--fs/btrfs/tree-log.c396
-rw-r--r--fs/btrfs/tree-log.h2
-rw-r--r--fs/btrfs/volumes.c140
-rw-r--r--fs/btrfs/volumes.h3
-rw-r--r--fs/btrfs/xattr.c69
-rw-r--r--fs/btrfs/zlib.c2
-rw-r--r--fs/cachefiles/bind.c10
-rw-r--r--fs/cachefiles/interface.c6
-rw-r--r--fs/cachefiles/namei.c122
-rw-r--r--fs/cachefiles/rdwr.c14
-rw-r--r--fs/cachefiles/security.c6
-rw-r--r--fs/cachefiles/xattr.c22
-rw-r--r--fs/ceph/caps.c2
-rw-r--r--fs/ceph/debugfs.c2
-rw-r--r--fs/ceph/dir.c60
-rw-r--r--fs/ceph/export.c28
-rw-r--r--fs/ceph/file.c4
-rw-r--r--fs/ceph/inode.c52
-rw-r--r--fs/ceph/mds_client.c24
-rw-r--r--fs/ceph/super.c4
-rw-r--r--fs/ceph/xattr.c16
-rw-r--r--fs/cifs/cifs_dfs_ref.c2
-rw-r--r--fs/cifs/cifsfs.c2
-rw-r--r--fs/cifs/cifssmb.c4
-rw-r--r--fs/cifs/dir.c8
-rw-r--r--fs/cifs/file.c48
-rw-r--r--fs/cifs/inode.c32
-rw-r--r--fs/cifs/link.c12
-rw-r--r--fs/cifs/misc.c2
-rw-r--r--fs/cifs/readdir.c4
-rw-r--r--fs/cifs/smb1ops.c2
-rw-r--r--fs/cifs/smb2file.c4
-rw-r--r--fs/cifs/smb2misc.c4
-rw-r--r--fs/cifs/smb2ops.c10
-rw-r--r--fs/cifs/xattr.c22
-rw-r--r--fs/coda/cache.c4
-rw-r--r--fs/coda/dir.c22
-rw-r--r--fs/coda/inode.c6
-rw-r--r--fs/coda/pioctl.c2
-rw-r--r--fs/coda/upcall.c4
-rw-r--r--fs/configfs/dir.c70
-rw-r--r--fs/configfs/file.c4
-rw-r--r--fs/configfs/inode.c16
-rw-r--r--fs/dax.c4
-rw-r--r--fs/debugfs/file.c2
-rw-r--r--fs/debugfs/inode.c56
-rw-r--r--fs/devpts/inode.c16
-rw-r--r--fs/direct-io.c7
-rw-r--r--fs/ecryptfs/crypto.c4
-rw-r--r--fs/ecryptfs/dentry.c6
-rw-r--r--fs/ecryptfs/file.c2
-rw-r--r--fs/ecryptfs/inode.c164
-rw-r--r--fs/ecryptfs/kthread.c2
-rw-r--r--fs/ecryptfs/main.c6
-rw-r--r--fs/ecryptfs/mmap.c2
-rw-r--r--fs/efivarfs/inode.c4
-rw-r--r--fs/efivarfs/super.c2
-rw-r--r--fs/efs/namei.c4
-rw-r--r--fs/exofs/dir.c4
-rw-r--r--fs/exofs/inode.c2
-rw-r--r--fs/exofs/namei.c10
-rw-r--r--fs/exofs/super.c2
-rw-r--r--fs/exofs/symlink.c2
-rw-r--r--fs/ext2/dir.c2
-rw-r--r--fs/ext2/ialloc.c2
-rw-r--r--fs/ext2/inode.c2
-rw-r--r--fs/ext2/namei.c14
-rw-r--r--fs/ext2/symlink.c2
-rw-r--r--fs/ext2/xattr.c4
-rw-r--r--fs/ext2/xattr_security.c4
-rw-r--r--fs/ext2/xattr_trusted.c4
-rw-r--r--fs/ext2/xattr_user.c4
-rw-r--r--fs/ext3/ialloc.c2
-rw-r--r--fs/ext3/inode.c2
-rw-r--r--fs/ext3/namei.c34
-rw-r--r--fs/ext3/super.c6
-rw-r--r--fs/ext3/symlink.c2
-rw-r--r--fs/ext3/xattr.c10
-rw-r--r--fs/ext3/xattr_security.c4
-rw-r--r--fs/ext3/xattr_trusted.c4
-rw-r--r--fs/ext3/xattr_user.c4
-rw-r--r--fs/ext4/fsync.c2
-rw-r--r--fs/ext4/ialloc.c2
-rw-r--r--fs/ext4/indirect.c6
-rw-r--r--fs/ext4/inline.c4
-rw-r--r--fs/ext4/inode.c8
-rw-r--r--fs/ext4/migrate.c2
-rw-r--r--fs/ext4/namei.c34
-rw-r--r--fs/ext4/super.c6
-rw-r--r--fs/ext4/symlink.c8
-rw-r--r--fs/ext4/xattr.c10
-rw-r--r--fs/ext4/xattr_security.c4
-rw-r--r--fs/ext4/xattr_trusted.c4
-rw-r--r--fs/ext4/xattr_user.c4
-rw-r--r--fs/f2fs/f2fs.h2
-rw-r--r--fs/f2fs/file.c4
-rw-r--r--fs/f2fs/namei.c18
-rw-r--r--fs/f2fs/xattr.c10
-rw-r--r--fs/fat/file.c4
-rw-r--r--fs/fat/namei_msdos.c8
-rw-r--r--fs/fat/namei_vfat.c14
-rw-r--r--fs/fat/nfs.c4
-rw-r--r--fs/freevxfs/vxfs_immed.c2
-rw-r--r--fs/fuse/control.c6
-rw-r--r--fs/fuse/dir.c60
-rw-r--r--fs/fuse/inode.c4
-rw-r--r--fs/gfs2/dentry.c12
-rw-r--r--fs/gfs2/export.c8
-rw-r--r--fs/gfs2/inode.c34
-rw-r--r--fs/gfs2/ops_fstype.c8
-rw-r--r--fs/gfs2/super.c2
-rw-r--r--fs/gfs2/xattr.c6
-rw-r--r--fs/hfs/attr.c6
-rw-r--r--fs/hfs/dir.c8
-rw-r--r--fs/hfs/inode.c2
-rw-r--r--fs/hfs/sysdep.c2
-rw-r--r--fs/hfsplus/dir.c12
-rw-r--r--fs/hfsplus/inode.c2
-rw-r--r--fs/hfsplus/ioctl.c2
-rw-r--r--fs/hfsplus/xattr.c12
-rw-r--r--fs/hostfs/hostfs_kern.c2
-rw-r--r--fs/hpfs/inode.c2
-rw-r--r--fs/hpfs/namei.c8
-rw-r--r--fs/hppfs/hppfs.c20
-rw-r--r--fs/hugetlbfs/inode.c4
-rw-r--r--fs/inode.c20
-rw-r--r--fs/isofs/export.c2
-rw-r--r--fs/jffs2/dir.c40
-rw-r--r--fs/jffs2/fs.c2
-rw-r--r--fs/jffs2/security.c4
-rw-r--r--fs/jffs2/super.c4
-rw-r--r--fs/jffs2/symlink.c2
-rw-r--r--fs/jffs2/xattr.c2
-rw-r--r--fs/jffs2/xattr_trusted.c4
-rw-r--r--fs/jffs2/xattr_user.c4
-rw-r--r--fs/jfs/file.c2
-rw-r--r--fs/jfs/namei.c18
-rw-r--r--fs/jfs/symlink.c2
-rw-r--r--fs/jfs/xattr.c12
-rw-r--r--fs/kernfs/dir.c2
-rw-r--r--fs/kernfs/inode.c8
-rw-r--r--fs/libfs.c26
-rw-r--r--fs/lockd/svcsubs.c2
-rw-r--r--fs/logfs/dir.c14
-rw-r--r--fs/logfs/file.c2
-rw-r--r--fs/minix/dir.c4
-rw-r--r--fs/minix/file.c2
-rw-r--r--fs/minix/inode.c4
-rw-r--r--fs/minix/namei.c10
-rw-r--r--fs/namei.c6
-rw-r--r--fs/ncpfs/dir.c48
-rw-r--r--fs/ncpfs/inode.c6
-rw-r--r--fs/ncpfs/ioctl.c8
-rw-r--r--fs/ncpfs/ncplib_kernel.c2
-rw-r--r--fs/ncpfs/symlink.c2
-rw-r--r--fs/nfs/Makefile2
-rw-r--r--fs/nfs/blocklayout/blocklayout.c1
-rw-r--r--fs/nfs/blocklayout/dev.c2
-rw-r--r--fs/nfs/callback.c6
-rw-r--r--fs/nfs/client.c1
-rw-r--r--fs/nfs/delegation.c4
-rw-r--r--fs/nfs/dir.c63
-rw-r--r--fs/nfs/direct.c53
-rw-r--r--fs/nfs/file.c3
-rw-r--r--fs/nfs/filelayout/filelayout.c10
-rw-r--r--fs/nfs/filelayout/filelayoutdev.c2
-rw-r--r--fs/nfs/flexfilelayout/flexfilelayout.c12
-rw-r--r--fs/nfs/flexfilelayout/flexfilelayoutdev.c2
-rw-r--r--fs/nfs/getroot.c4
-rw-r--r--fs/nfs/inode.c54
-rw-r--r--fs/nfs/namespace.c10
-rw-r--r--fs/nfs/nfs3acl.c2
-rw-r--r--fs/nfs/nfs3proc.c12
-rw-r--r--fs/nfs/nfs42proc.c31
-rw-r--r--fs/nfs/nfs42xdr.c20
-rw-r--r--fs/nfs/nfs4client.c4
-rw-r--r--fs/nfs/nfs4file.c24
-rw-r--r--fs/nfs/nfs4idmap.c (renamed from fs/nfs/idmap.c)2
-rw-r--r--fs/nfs/nfs4idmap.h68
-rw-r--r--fs/nfs/nfs4namespace.c4
-rw-r--r--fs/nfs/nfs4proc.c83
-rw-r--r--fs/nfs/nfs4state.c6
-rw-r--r--fs/nfs/nfs4super.c7
-rw-r--r--fs/nfs/nfs4sysctl.c2
-rw-r--r--fs/nfs/nfs4trace.h4
-rw-r--r--fs/nfs/nfs4xdr.c22
-rw-r--r--fs/nfs/nfstrace.c3
-rw-r--r--fs/nfs/objlayout/objio_osd.c4
-rw-r--r--fs/nfs/pagelist.c2
-rw-r--r--fs/nfs/pnfs.c68
-rw-r--r--fs/nfs/pnfs.h28
-rw-r--r--fs/nfs/pnfs_dev.c21
-rw-r--r--fs/nfs/pnfs_nfs.c12
-rw-r--r--fs/nfs/proc.c4
-rw-r--r--fs/nfs/read.c4
-rw-r--r--fs/nfs/super.c10
-rw-r--r--fs/nfs/symlink.c2
-rw-r--r--fs/nfs/unlink.c20
-rw-r--r--fs/nfs/write.c23
-rw-r--r--fs/nfsd/Kconfig2
-rw-r--r--fs/nfsd/export.c8
-rw-r--r--fs/nfsd/nfs2acl.c8
-rw-r--r--fs/nfsd/nfs3acl.c8
-rw-r--r--fs/nfsd/nfs3proc.c6
-rw-r--r--fs/nfsd/nfs3xdr.c16
-rw-r--r--fs/nfsd/nfs4acl.c54
-rw-r--r--fs/nfsd/nfs4proc.c24
-rw-r--r--fs/nfsd/nfs4recover.c22
-rw-r--r--fs/nfsd/nfs4state.c9
-rw-r--r--fs/nfsd/nfs4xdr.c26
-rw-r--r--fs/nfsd/nfsctl.c16
-rw-r--r--fs/nfsd/nfsd.h2
-rw-r--r--fs/nfsd/nfsfh.c20
-rw-r--r--fs/nfsd/nfsfh.h6
-rw-r--r--fs/nfsd/nfsproc.c4
-rw-r--r--fs/nfsd/nfsxdr.c2
-rw-r--r--fs/nfsd/vfs.c62
-rw-r--r--fs/nfsd/xdr4.h5
-rw-r--r--fs/nilfs2/dir.c2
-rw-r--r--fs/nilfs2/inode.c2
-rw-r--r--fs/nilfs2/namei.c18
-rw-r--r--fs/nilfs2/super.c6
-rw-r--r--fs/nsfs.c4
-rw-r--r--fs/ntfs/inode.c2
-rw-r--r--fs/ntfs/namei.c4
-rw-r--r--fs/ocfs2/dcache.c14
-rw-r--r--fs/ocfs2/dir.h2
-rw-r--r--fs/ocfs2/dlmfs/dlmfs.c4
-rw-r--r--fs/ocfs2/export.c2
-rw-r--r--fs/ocfs2/file.c8
-rw-r--r--fs/ocfs2/inode.c2
-rw-r--r--fs/ocfs2/namei.c14
-rw-r--r--fs/ocfs2/refcounttree.c10
-rw-r--r--fs/ocfs2/xattr.c22
-rw-r--r--fs/omfs/dir.c10
-rw-r--r--fs/omfs/file.c2
-rw-r--r--fs/open.c8
-rw-r--r--fs/pipe.c2
-rw-r--r--fs/posix_acl.c8
-rw-r--r--fs/proc/base.c32
-rw-r--r--fs/proc/fd.c6
-rw-r--r--fs/proc/generic.c4
-rw-r--r--fs/proc/inode.c2
-rw-r--r--fs/proc/namespaces.c4
-rw-r--r--fs/proc/proc_net.c2
-rw-r--r--fs/proc/proc_sysctl.c12
-rw-r--r--fs/proc/root.c2
-rw-r--r--fs/proc/self.c2
-rw-r--r--fs/proc/thread_self.c2
-rw-r--r--fs/pstore/inode.c10
-rw-r--r--fs/qnx6/inode.c2
-rw-r--r--fs/quota/dquot.c10
-rw-r--r--fs/ramfs/file-nommu.c2
-rw-r--r--fs/reiserfs/dir.c4
-rw-r--r--fs/reiserfs/inode.c2
-rw-r--r--fs/reiserfs/namei.c12
-rw-r--r--fs/reiserfs/super.c4
-rw-r--r--fs/reiserfs/xattr.c126
-rw-r--r--fs/reiserfs/xattr.h2
-rw-r--r--fs/reiserfs/xattr_security.c10
-rw-r--r--fs/reiserfs/xattr_trusted.c10
-rw-r--r--fs/reiserfs/xattr_user.c4
-rw-r--r--fs/squashfs/export.c2
-rw-r--r--fs/squashfs/xattr.c8
-rw-r--r--fs/stat.c4
-rw-r--r--fs/sysv/dir.c4
-rw-r--r--fs/sysv/file.c2
-rw-r--r--fs/sysv/itree.c2
-rw-r--r--fs/sysv/namei.c10
-rw-r--r--fs/sysv/symlink.c2
-rw-r--r--fs/ubifs/dir.c14
-rw-r--r--fs/ubifs/file.c4
-rw-r--r--fs/ubifs/journal.c4
-rw-r--r--fs/ubifs/xattr.c10
-rw-r--r--fs/udf/file.c2
-rw-r--r--fs/udf/namei.c16
-rw-r--r--fs/ufs/dir.c2
-rw-r--r--fs/ufs/namei.c10
-rw-r--r--fs/ufs/super.c4
-rw-r--r--fs/ufs/symlink.c2
-rw-r--r--fs/ufs/truncate.c2
-rw-r--r--fs/xfs/libxfs/xfs_alloc.c104
-rw-r--r--fs/xfs/libxfs/xfs_attr_leaf.c150
-rw-r--r--fs/xfs/libxfs/xfs_attr_leaf.h6
-rw-r--r--fs/xfs/libxfs/xfs_bmap.c554
-rw-r--r--fs/xfs/libxfs/xfs_bmap.h13
-rw-r--r--fs/xfs/libxfs/xfs_btree.c24
-rw-r--r--fs/xfs/libxfs/xfs_da_btree.c8
-rw-r--r--fs/xfs/libxfs/xfs_da_format.h14
-rw-r--r--fs/xfs/libxfs/xfs_dir2_data.c39
-rw-r--r--fs/xfs/libxfs/xfs_format.h62
-rw-r--r--fs/xfs/libxfs/xfs_ialloc.c48
-rw-r--r--fs/xfs/libxfs/xfs_sb.c20
-rw-r--r--fs/xfs/xfs_aops.c270
-rw-r--r--fs/xfs/xfs_attr_inactive.c3
-rw-r--r--fs/xfs/xfs_attr_list.c9
-rw-r--r--fs/xfs/xfs_bmap_util.c164
-rw-r--r--fs/xfs/xfs_bmap_util.h2
-rw-r--r--fs/xfs/xfs_buf_item.c4
-rw-r--r--fs/xfs/xfs_discard.c2
-rw-r--r--fs/xfs/xfs_error.c2
-rw-r--r--fs/xfs/xfs_error.h8
-rw-r--r--fs/xfs/xfs_export.c2
-rw-r--r--fs/xfs/xfs_file.c161
-rw-r--r--fs/xfs/xfs_filestream.c4
-rw-r--r--fs/xfs/xfs_fsops.c20
-rw-r--r--fs/xfs/xfs_icache.c4
-rw-r--r--fs/xfs/xfs_inode.c558
-rw-r--r--fs/xfs/xfs_inode.h49
-rw-r--r--fs/xfs/xfs_ioctl.c25
-rw-r--r--fs/xfs/xfs_ioctl32.c12
-rw-r--r--fs/xfs/xfs_iomap.c3
-rw-r--r--fs/xfs/xfs_iops.c109
-rw-r--r--fs/xfs/xfs_iops.h2
-rw-r--r--fs/xfs/xfs_itable.c2
-rw-r--r--fs/xfs/xfs_linux.h9
-rw-r--r--fs/xfs/xfs_log_recover.c4
-rw-r--r--fs/xfs/xfs_mount.c918
-rw-r--r--fs/xfs/xfs_mount.h95
-rw-r--r--fs/xfs/xfs_mru_cache.c2
-rw-r--r--fs/xfs/xfs_pnfs.c7
-rw-r--r--fs/xfs/xfs_pnfs.h5
-rw-r--r--fs/xfs/xfs_qm.c13
-rw-r--r--fs/xfs/xfs_super.c134
-rw-r--r--fs/xfs/xfs_super.h2
-rw-r--r--fs/xfs/xfs_symlink.c58
-rw-r--r--fs/xfs/xfs_trace.h29
-rw-r--r--fs/xfs/xfs_trans.c234
-rw-r--r--fs/xfs/xfs_xattr.c6
394 files changed, 5983 insertions, 4596 deletions
diff --git a/fs/9p/acl.c b/fs/9p/acl.c
index 8482f2d11606..31c010372660 100644
--- a/fs/9p/acl.c
+++ b/fs/9p/acl.c
@@ -247,7 +247,7 @@ static int v9fs_xattr_get_acl(struct dentry *dentry, const char *name,
247 if ((v9ses->flags & V9FS_ACCESS_MASK) != V9FS_ACCESS_CLIENT) 247 if ((v9ses->flags & V9FS_ACCESS_MASK) != V9FS_ACCESS_CLIENT)
248 return v9fs_remote_get_acl(dentry, name, buffer, size, type); 248 return v9fs_remote_get_acl(dentry, name, buffer, size, type);
249 249
250 acl = v9fs_get_cached_acl(dentry->d_inode, type); 250 acl = v9fs_get_cached_acl(d_inode(dentry), type);
251 if (IS_ERR(acl)) 251 if (IS_ERR(acl))
252 return PTR_ERR(acl); 252 return PTR_ERR(acl);
253 if (acl == NULL) 253 if (acl == NULL)
@@ -285,7 +285,7 @@ static int v9fs_xattr_set_acl(struct dentry *dentry, const char *name,
285 int retval; 285 int retval;
286 struct posix_acl *acl; 286 struct posix_acl *acl;
287 struct v9fs_session_info *v9ses; 287 struct v9fs_session_info *v9ses;
288 struct inode *inode = dentry->d_inode; 288 struct inode *inode = d_inode(dentry);
289 289
290 if (strcmp(name, "") != 0) 290 if (strcmp(name, "") != 0)
291 return -EINVAL; 291 return -EINVAL;
diff --git a/fs/9p/vfs_dentry.c b/fs/9p/vfs_dentry.c
index a345b2d659cc..bd456c668d39 100644
--- a/fs/9p/vfs_dentry.c
+++ b/fs/9p/vfs_dentry.c
@@ -53,7 +53,7 @@ static int v9fs_cached_dentry_delete(const struct dentry *dentry)
53 dentry, dentry); 53 dentry, dentry);
54 54
55 /* Don't cache negative dentries */ 55 /* Don't cache negative dentries */
56 if (!dentry->d_inode) 56 if (d_really_is_negative(dentry))
57 return 1; 57 return 1;
58 return 0; 58 return 0;
59} 59}
@@ -83,7 +83,7 @@ static int v9fs_lookup_revalidate(struct dentry *dentry, unsigned int flags)
83 if (flags & LOOKUP_RCU) 83 if (flags & LOOKUP_RCU)
84 return -ECHILD; 84 return -ECHILD;
85 85
86 inode = dentry->d_inode; 86 inode = d_inode(dentry);
87 if (!inode) 87 if (!inode)
88 goto out_valid; 88 goto out_valid;
89 89
diff --git a/fs/9p/vfs_dir.c b/fs/9p/vfs_dir.c
index 76c3b1ab6361..5cc00e56206e 100644
--- a/fs/9p/vfs_dir.c
+++ b/fs/9p/vfs_dir.c
@@ -138,6 +138,8 @@ static int v9fs_dir_readdir(struct file *file, struct dir_context *ctx)
138 &err); 138 &err);
139 if (err) 139 if (err)
140 return err; 140 return err;
141 if (n == 0)
142 return 0;
141 143
142 rdir->head = 0; 144 rdir->head = 0;
143 rdir->tail = n; 145 rdir->tail = n;
diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
index 3662f1d1d9cf..703342e309f5 100644
--- a/fs/9p/vfs_inode.c
+++ b/fs/9p/vfs_inode.c
@@ -595,7 +595,7 @@ static int v9fs_remove(struct inode *dir, struct dentry *dentry, int flags)
595 dir, dentry, flags); 595 dir, dentry, flags);
596 596
597 v9ses = v9fs_inode2v9ses(dir); 597 v9ses = v9fs_inode2v9ses(dir);
598 inode = dentry->d_inode; 598 inode = d_inode(dentry);
599 dfid = v9fs_fid_lookup(dentry->d_parent); 599 dfid = v9fs_fid_lookup(dentry->d_parent);
600 if (IS_ERR(dfid)) { 600 if (IS_ERR(dfid)) {
601 retval = PTR_ERR(dfid); 601 retval = PTR_ERR(dfid);
@@ -864,7 +864,7 @@ v9fs_vfs_atomic_open(struct inode *dir, struct dentry *dentry,
864 } 864 }
865 865
866 /* Only creates */ 866 /* Only creates */
867 if (!(flags & O_CREAT) || dentry->d_inode) 867 if (!(flags & O_CREAT) || d_really_is_positive(dentry))
868 return finish_no_open(file, res); 868 return finish_no_open(file, res);
869 869
870 err = 0; 870 err = 0;
@@ -881,7 +881,7 @@ v9fs_vfs_atomic_open(struct inode *dir, struct dentry *dentry,
881 } 881 }
882 882
883 v9fs_invalidate_inode_attr(dir); 883 v9fs_invalidate_inode_attr(dir);
884 v9inode = V9FS_I(dentry->d_inode); 884 v9inode = V9FS_I(d_inode(dentry));
885 mutex_lock(&v9inode->v_mutex); 885 mutex_lock(&v9inode->v_mutex);
886 if ((v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) && 886 if ((v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) &&
887 !v9inode->writeback_fid && 887 !v9inode->writeback_fid &&
@@ -908,7 +908,7 @@ v9fs_vfs_atomic_open(struct inode *dir, struct dentry *dentry,
908 908
909 file->private_data = fid; 909 file->private_data = fid;
910 if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) 910 if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE)
911 v9fs_cache_inode_set_cookie(dentry->d_inode, file); 911 v9fs_cache_inode_set_cookie(d_inode(dentry), file);
912 912
913 *opened |= FILE_CREATED; 913 *opened |= FILE_CREATED;
914out: 914out:
@@ -969,8 +969,8 @@ v9fs_vfs_rename(struct inode *old_dir, struct dentry *old_dentry,
969 969
970 p9_debug(P9_DEBUG_VFS, "\n"); 970 p9_debug(P9_DEBUG_VFS, "\n");
971 retval = 0; 971 retval = 0;
972 old_inode = old_dentry->d_inode; 972 old_inode = d_inode(old_dentry);
973 new_inode = new_dentry->d_inode; 973 new_inode = d_inode(new_dentry);
974 v9ses = v9fs_inode2v9ses(old_inode); 974 v9ses = v9fs_inode2v9ses(old_inode);
975 oldfid = v9fs_fid_lookup(old_dentry); 975 oldfid = v9fs_fid_lookup(old_dentry);
976 if (IS_ERR(oldfid)) 976 if (IS_ERR(oldfid))
@@ -1061,7 +1061,7 @@ v9fs_vfs_getattr(struct vfsmount *mnt, struct dentry *dentry,
1061 p9_debug(P9_DEBUG_VFS, "dentry: %p\n", dentry); 1061 p9_debug(P9_DEBUG_VFS, "dentry: %p\n", dentry);
1062 v9ses = v9fs_dentry2v9ses(dentry); 1062 v9ses = v9fs_dentry2v9ses(dentry);
1063 if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) { 1063 if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
1064 generic_fillattr(dentry->d_inode, stat); 1064 generic_fillattr(d_inode(dentry), stat);
1065 return 0; 1065 return 0;
1066 } 1066 }
1067 fid = v9fs_fid_lookup(dentry); 1067 fid = v9fs_fid_lookup(dentry);
@@ -1072,8 +1072,8 @@ v9fs_vfs_getattr(struct vfsmount *mnt, struct dentry *dentry,
1072 if (IS_ERR(st)) 1072 if (IS_ERR(st))
1073 return PTR_ERR(st); 1073 return PTR_ERR(st);
1074 1074
1075 v9fs_stat2inode(st, dentry->d_inode, dentry->d_inode->i_sb); 1075 v9fs_stat2inode(st, d_inode(dentry), d_inode(dentry)->i_sb);
1076 generic_fillattr(dentry->d_inode, stat); 1076 generic_fillattr(d_inode(dentry), stat);
1077 1077
1078 p9stat_free(st); 1078 p9stat_free(st);
1079 kfree(st); 1079 kfree(st);
@@ -1095,7 +1095,7 @@ static int v9fs_vfs_setattr(struct dentry *dentry, struct iattr *iattr)
1095 struct p9_wstat wstat; 1095 struct p9_wstat wstat;
1096 1096
1097 p9_debug(P9_DEBUG_VFS, "\n"); 1097 p9_debug(P9_DEBUG_VFS, "\n");
1098 retval = inode_change_ok(dentry->d_inode, iattr); 1098 retval = inode_change_ok(d_inode(dentry), iattr);
1099 if (retval) 1099 if (retval)
1100 return retval; 1100 return retval;
1101 1101
@@ -1128,20 +1128,20 @@ static int v9fs_vfs_setattr(struct dentry *dentry, struct iattr *iattr)
1128 1128
1129 /* Write all dirty data */ 1129 /* Write all dirty data */
1130 if (d_is_reg(dentry)) 1130 if (d_is_reg(dentry))
1131 filemap_write_and_wait(dentry->d_inode->i_mapping); 1131 filemap_write_and_wait(d_inode(dentry)->i_mapping);
1132 1132
1133 retval = p9_client_wstat(fid, &wstat); 1133 retval = p9_client_wstat(fid, &wstat);
1134 if (retval < 0) 1134 if (retval < 0)
1135 return retval; 1135 return retval;
1136 1136
1137 if ((iattr->ia_valid & ATTR_SIZE) && 1137 if ((iattr->ia_valid & ATTR_SIZE) &&
1138 iattr->ia_size != i_size_read(dentry->d_inode)) 1138 iattr->ia_size != i_size_read(d_inode(dentry)))
1139 truncate_setsize(dentry->d_inode, iattr->ia_size); 1139 truncate_setsize(d_inode(dentry), iattr->ia_size);
1140 1140
1141 v9fs_invalidate_inode_attr(dentry->d_inode); 1141 v9fs_invalidate_inode_attr(d_inode(dentry));
1142 1142
1143 setattr_copy(dentry->d_inode, iattr); 1143 setattr_copy(d_inode(dentry), iattr);
1144 mark_inode_dirty(dentry->d_inode); 1144 mark_inode_dirty(d_inode(dentry));
1145 return 0; 1145 return 0;
1146} 1146}
1147 1147
@@ -1403,7 +1403,7 @@ v9fs_vfs_link(struct dentry *old_dentry, struct inode *dir,
1403 retval = v9fs_vfs_mkspecial(dir, dentry, P9_DMLINK, name); 1403 retval = v9fs_vfs_mkspecial(dir, dentry, P9_DMLINK, name);
1404 __putname(name); 1404 __putname(name);
1405 if (!retval) { 1405 if (!retval) {
1406 v9fs_refresh_inode(oldfid, old_dentry->d_inode); 1406 v9fs_refresh_inode(oldfid, d_inode(old_dentry));
1407 v9fs_invalidate_inode_attr(dir); 1407 v9fs_invalidate_inode_attr(dir);
1408 } 1408 }
1409clunk_fid: 1409clunk_fid:
diff --git a/fs/9p/vfs_inode_dotl.c b/fs/9p/vfs_inode_dotl.c
index 6054c16b8fae..9861c7c951a6 100644
--- a/fs/9p/vfs_inode_dotl.c
+++ b/fs/9p/vfs_inode_dotl.c
@@ -265,7 +265,7 @@ v9fs_vfs_atomic_open_dotl(struct inode *dir, struct dentry *dentry,
265 } 265 }
266 266
267 /* Only creates */ 267 /* Only creates */
268 if (!(flags & O_CREAT) || dentry->d_inode) 268 if (!(flags & O_CREAT) || d_really_is_positive(dentry))
269 return finish_no_open(file, res); 269 return finish_no_open(file, res);
270 270
271 v9ses = v9fs_inode2v9ses(dir); 271 v9ses = v9fs_inode2v9ses(dir);
@@ -481,7 +481,7 @@ v9fs_vfs_getattr_dotl(struct vfsmount *mnt, struct dentry *dentry,
481 p9_debug(P9_DEBUG_VFS, "dentry: %p\n", dentry); 481 p9_debug(P9_DEBUG_VFS, "dentry: %p\n", dentry);
482 v9ses = v9fs_dentry2v9ses(dentry); 482 v9ses = v9fs_dentry2v9ses(dentry);
483 if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) { 483 if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
484 generic_fillattr(dentry->d_inode, stat); 484 generic_fillattr(d_inode(dentry), stat);
485 return 0; 485 return 0;
486 } 486 }
487 fid = v9fs_fid_lookup(dentry); 487 fid = v9fs_fid_lookup(dentry);
@@ -496,8 +496,8 @@ v9fs_vfs_getattr_dotl(struct vfsmount *mnt, struct dentry *dentry,
496 if (IS_ERR(st)) 496 if (IS_ERR(st))
497 return PTR_ERR(st); 497 return PTR_ERR(st);
498 498
499 v9fs_stat2inode_dotl(st, dentry->d_inode); 499 v9fs_stat2inode_dotl(st, d_inode(dentry));
500 generic_fillattr(dentry->d_inode, stat); 500 generic_fillattr(d_inode(dentry), stat);
501 /* Change block size to what the server returned */ 501 /* Change block size to what the server returned */
502 stat->blksize = st->st_blksize; 502 stat->blksize = st->st_blksize;
503 503
@@ -557,7 +557,7 @@ int v9fs_vfs_setattr_dotl(struct dentry *dentry, struct iattr *iattr)
557 int retval; 557 int retval;
558 struct p9_fid *fid; 558 struct p9_fid *fid;
559 struct p9_iattr_dotl p9attr; 559 struct p9_iattr_dotl p9attr;
560 struct inode *inode = dentry->d_inode; 560 struct inode *inode = d_inode(dentry);
561 561
562 p9_debug(P9_DEBUG_VFS, "\n"); 562 p9_debug(P9_DEBUG_VFS, "\n");
563 563
@@ -795,10 +795,10 @@ v9fs_vfs_link_dotl(struct dentry *old_dentry, struct inode *dir,
795 if (IS_ERR(fid)) 795 if (IS_ERR(fid))
796 return PTR_ERR(fid); 796 return PTR_ERR(fid);
797 797
798 v9fs_refresh_inode_dotl(fid, old_dentry->d_inode); 798 v9fs_refresh_inode_dotl(fid, d_inode(old_dentry));
799 } 799 }
800 ihold(old_dentry->d_inode); 800 ihold(d_inode(old_dentry));
801 d_instantiate(dentry, old_dentry->d_inode); 801 d_instantiate(dentry, d_inode(old_dentry));
802 802
803 return err; 803 return err;
804} 804}
diff --git a/fs/9p/vfs_super.c b/fs/9p/vfs_super.c
index 0afd0382822b..e99a338a4638 100644
--- a/fs/9p/vfs_super.c
+++ b/fs/9p/vfs_super.c
@@ -168,8 +168,8 @@ static struct dentry *v9fs_mount(struct file_system_type *fs_type, int flags,
168 retval = PTR_ERR(st); 168 retval = PTR_ERR(st);
169 goto release_sb; 169 goto release_sb;
170 } 170 }
171 root->d_inode->i_ino = v9fs_qid2ino(&st->qid); 171 d_inode(root)->i_ino = v9fs_qid2ino(&st->qid);
172 v9fs_stat2inode_dotl(st, root->d_inode); 172 v9fs_stat2inode_dotl(st, d_inode(root));
173 kfree(st); 173 kfree(st);
174 } else { 174 } else {
175 struct p9_wstat *st = NULL; 175 struct p9_wstat *st = NULL;
@@ -179,8 +179,8 @@ static struct dentry *v9fs_mount(struct file_system_type *fs_type, int flags,
179 goto release_sb; 179 goto release_sb;
180 } 180 }
181 181
182 root->d_inode->i_ino = v9fs_qid2ino(&st->qid); 182 d_inode(root)->i_ino = v9fs_qid2ino(&st->qid);
183 v9fs_stat2inode(st, root->d_inode, sb); 183 v9fs_stat2inode(st, d_inode(root), sb);
184 184
185 p9stat_free(st); 185 p9stat_free(st);
186 kfree(st); 186 kfree(st);
diff --git a/fs/adfs/inode.c b/fs/adfs/inode.c
index b9acadafa4a1..335055d828e4 100644
--- a/fs/adfs/inode.c
+++ b/fs/adfs/inode.c
@@ -298,7 +298,7 @@ out:
298int 298int
299adfs_notify_change(struct dentry *dentry, struct iattr *attr) 299adfs_notify_change(struct dentry *dentry, struct iattr *attr)
300{ 300{
301 struct inode *inode = dentry->d_inode; 301 struct inode *inode = d_inode(dentry);
302 struct super_block *sb = inode->i_sb; 302 struct super_block *sb = inode->i_sb;
303 unsigned int ia_valid = attr->ia_valid; 303 unsigned int ia_valid = attr->ia_valid;
304 int error; 304 int error;
diff --git a/fs/affs/amigaffs.c b/fs/affs/amigaffs.c
index 5022ac96aa40..a8f463c028ce 100644
--- a/fs/affs/amigaffs.c
+++ b/fs/affs/amigaffs.c
@@ -138,7 +138,7 @@ affs_fix_dcache(struct inode *inode, u32 entry_ino)
138static int 138static int
139affs_remove_link(struct dentry *dentry) 139affs_remove_link(struct dentry *dentry)
140{ 140{
141 struct inode *dir, *inode = dentry->d_inode; 141 struct inode *dir, *inode = d_inode(dentry);
142 struct super_block *sb = inode->i_sb; 142 struct super_block *sb = inode->i_sb;
143 struct buffer_head *bh = NULL, *link_bh = NULL; 143 struct buffer_head *bh = NULL, *link_bh = NULL;
144 u32 link_ino, ino; 144 u32 link_ino, ino;
@@ -268,11 +268,11 @@ affs_remove_header(struct dentry *dentry)
268 struct buffer_head *bh = NULL; 268 struct buffer_head *bh = NULL;
269 int retval; 269 int retval;
270 270
271 dir = dentry->d_parent->d_inode; 271 dir = d_inode(dentry->d_parent);
272 sb = dir->i_sb; 272 sb = dir->i_sb;
273 273
274 retval = -ENOENT; 274 retval = -ENOENT;
275 inode = dentry->d_inode; 275 inode = d_inode(dentry);
276 if (!inode) 276 if (!inode)
277 goto done; 277 goto done;
278 278
@@ -471,10 +471,9 @@ affs_warning(struct super_block *sb, const char *function, const char *fmt, ...)
471bool 471bool
472affs_nofilenametruncate(const struct dentry *dentry) 472affs_nofilenametruncate(const struct dentry *dentry)
473{ 473{
474 struct inode *inode = dentry->d_inode; 474 struct inode *inode = d_inode(dentry);
475 475
476 return affs_test_opt(AFFS_SB(inode->i_sb)->s_flags, SF_NO_TRUNCATE); 476 return affs_test_opt(AFFS_SB(inode->i_sb)->s_flags, SF_NO_TRUNCATE);
477
478} 477}
479 478
480/* Check if the name is valid for a affs object. */ 479/* Check if the name is valid for a affs object. */
diff --git a/fs/affs/inode.c b/fs/affs/inode.c
index 9628003ccd2f..a022f4accd76 100644
--- a/fs/affs/inode.c
+++ b/fs/affs/inode.c
@@ -213,7 +213,7 @@ affs_write_inode(struct inode *inode, struct writeback_control *wbc)
213int 213int
214affs_notify_change(struct dentry *dentry, struct iattr *attr) 214affs_notify_change(struct dentry *dentry, struct iattr *attr)
215{ 215{
216 struct inode *inode = dentry->d_inode; 216 struct inode *inode = d_inode(dentry);
217 int error; 217 int error;
218 218
219 pr_debug("notify_change(%lu,0x%x)\n", inode->i_ino, attr->ia_valid); 219 pr_debug("notify_change(%lu,0x%x)\n", inode->i_ino, attr->ia_valid);
diff --git a/fs/affs/namei.c b/fs/affs/namei.c
index ec8ca0efb960..181e05b46e72 100644
--- a/fs/affs/namei.c
+++ b/fs/affs/namei.c
@@ -251,7 +251,7 @@ int
251affs_unlink(struct inode *dir, struct dentry *dentry) 251affs_unlink(struct inode *dir, struct dentry *dentry)
252{ 252{
253 pr_debug("%s(dir=%lu, %lu \"%pd\")\n", __func__, dir->i_ino, 253 pr_debug("%s(dir=%lu, %lu \"%pd\")\n", __func__, dir->i_ino,
254 dentry->d_inode->i_ino, dentry); 254 d_inode(dentry)->i_ino, dentry);
255 255
256 return affs_remove_header(dentry); 256 return affs_remove_header(dentry);
257} 257}
@@ -320,7 +320,7 @@ int
320affs_rmdir(struct inode *dir, struct dentry *dentry) 320affs_rmdir(struct inode *dir, struct dentry *dentry)
321{ 321{
322 pr_debug("%s(dir=%lu, %lu \"%pd\")\n", __func__, dir->i_ino, 322 pr_debug("%s(dir=%lu, %lu \"%pd\")\n", __func__, dir->i_ino,
323 dentry->d_inode->i_ino, dentry); 323 d_inode(dentry)->i_ino, dentry);
324 324
325 return affs_remove_header(dentry); 325 return affs_remove_header(dentry);
326} 326}
@@ -403,7 +403,7 @@ err:
403int 403int
404affs_link(struct dentry *old_dentry, struct inode *dir, struct dentry *dentry) 404affs_link(struct dentry *old_dentry, struct inode *dir, struct dentry *dentry)
405{ 405{
406 struct inode *inode = old_dentry->d_inode; 406 struct inode *inode = d_inode(old_dentry);
407 407
408 pr_debug("%s(%lu, %lu, \"%pd\")\n", __func__, inode->i_ino, dir->i_ino, 408 pr_debug("%s(%lu, %lu, \"%pd\")\n", __func__, inode->i_ino, dir->i_ino,
409 dentry); 409 dentry);
@@ -430,13 +430,13 @@ affs_rename(struct inode *old_dir, struct dentry *old_dentry,
430 return retval; 430 return retval;
431 431
432 /* Unlink destination if it already exists */ 432 /* Unlink destination if it already exists */
433 if (new_dentry->d_inode) { 433 if (d_really_is_positive(new_dentry)) {
434 retval = affs_remove_header(new_dentry); 434 retval = affs_remove_header(new_dentry);
435 if (retval) 435 if (retval)
436 return retval; 436 return retval;
437 } 437 }
438 438
439 bh = affs_bread(sb, old_dentry->d_inode->i_ino); 439 bh = affs_bread(sb, d_inode(old_dentry)->i_ino);
440 if (!bh) 440 if (!bh)
441 return -EIO; 441 return -EIO;
442 442
diff --git a/fs/afs/dir.c b/fs/afs/dir.c
index 4ec35e9130e1..e10e17788f06 100644
--- a/fs/afs/dir.c
+++ b/fs/afs/dir.c
@@ -505,7 +505,7 @@ static struct dentry *afs_lookup(struct inode *dir, struct dentry *dentry,
505 _enter("{%x:%u},%p{%pd},", 505 _enter("{%x:%u},%p{%pd},",
506 vnode->fid.vid, vnode->fid.vnode, dentry, dentry); 506 vnode->fid.vid, vnode->fid.vnode, dentry, dentry);
507 507
508 ASSERTCMP(dentry->d_inode, ==, NULL); 508 ASSERTCMP(d_inode(dentry), ==, NULL);
509 509
510 if (dentry->d_name.len >= AFSNAMEMAX) { 510 if (dentry->d_name.len >= AFSNAMEMAX) {
511 _leave(" = -ENAMETOOLONG"); 511 _leave(" = -ENAMETOOLONG");
@@ -563,8 +563,8 @@ success:
563 _leave(" = 0 { vn=%u u=%u } -> { ino=%lu v=%u }", 563 _leave(" = 0 { vn=%u u=%u } -> { ino=%lu v=%u }",
564 fid.vnode, 564 fid.vnode,
565 fid.unique, 565 fid.unique,
566 dentry->d_inode->i_ino, 566 d_inode(dentry)->i_ino,
567 dentry->d_inode->i_generation); 567 d_inode(dentry)->i_generation);
568 568
569 return NULL; 569 return NULL;
570} 570}
@@ -586,9 +586,9 @@ static int afs_d_revalidate(struct dentry *dentry, unsigned int flags)
586 if (flags & LOOKUP_RCU) 586 if (flags & LOOKUP_RCU)
587 return -ECHILD; 587 return -ECHILD;
588 588
589 vnode = AFS_FS_I(dentry->d_inode); 589 vnode = AFS_FS_I(d_inode(dentry));
590 590
591 if (dentry->d_inode) 591 if (d_really_is_positive(dentry))
592 _enter("{v={%x:%u} n=%pd fl=%lx},", 592 _enter("{v={%x:%u} n=%pd fl=%lx},",
593 vnode->fid.vid, vnode->fid.vnode, dentry, 593 vnode->fid.vid, vnode->fid.vnode, dentry,
594 vnode->flags); 594 vnode->flags);
@@ -601,7 +601,7 @@ static int afs_d_revalidate(struct dentry *dentry, unsigned int flags)
601 601
602 /* lock down the parent dentry so we can peer at it */ 602 /* lock down the parent dentry so we can peer at it */
603 parent = dget_parent(dentry); 603 parent = dget_parent(dentry);
604 dir = AFS_FS_I(parent->d_inode); 604 dir = AFS_FS_I(d_inode(parent));
605 605
606 /* validate the parent directory */ 606 /* validate the parent directory */
607 if (test_bit(AFS_VNODE_MODIFIED, &dir->flags)) 607 if (test_bit(AFS_VNODE_MODIFIED, &dir->flags))
@@ -623,9 +623,9 @@ static int afs_d_revalidate(struct dentry *dentry, unsigned int flags)
623 switch (ret) { 623 switch (ret) {
624 case 0: 624 case 0:
625 /* the filename maps to something */ 625 /* the filename maps to something */
626 if (!dentry->d_inode) 626 if (d_really_is_negative(dentry))
627 goto out_bad; 627 goto out_bad;
628 if (is_bad_inode(dentry->d_inode)) { 628 if (is_bad_inode(d_inode(dentry))) {
629 printk("kAFS: afs_d_revalidate: %pd2 has bad inode\n", 629 printk("kAFS: afs_d_revalidate: %pd2 has bad inode\n",
630 dentry); 630 dentry);
631 goto out_bad; 631 goto out_bad;
@@ -647,7 +647,7 @@ static int afs_d_revalidate(struct dentry *dentry, unsigned int flags)
647 _debug("%pd: file deleted (uq %u -> %u I:%u)", 647 _debug("%pd: file deleted (uq %u -> %u I:%u)",
648 dentry, fid.unique, 648 dentry, fid.unique,
649 vnode->fid.unique, 649 vnode->fid.unique,
650 dentry->d_inode->i_generation); 650 d_inode(dentry)->i_generation);
651 spin_lock(&vnode->lock); 651 spin_lock(&vnode->lock);
652 set_bit(AFS_VNODE_DELETED, &vnode->flags); 652 set_bit(AFS_VNODE_DELETED, &vnode->flags);
653 spin_unlock(&vnode->lock); 653 spin_unlock(&vnode->lock);
@@ -658,7 +658,7 @@ static int afs_d_revalidate(struct dentry *dentry, unsigned int flags)
658 case -ENOENT: 658 case -ENOENT:
659 /* the filename is unknown */ 659 /* the filename is unknown */
660 _debug("%pd: dirent not found", dentry); 660 _debug("%pd: dirent not found", dentry);
661 if (dentry->d_inode) 661 if (d_really_is_positive(dentry))
662 goto not_found; 662 goto not_found;
663 goto out_valid; 663 goto out_valid;
664 664
@@ -703,9 +703,9 @@ static int afs_d_delete(const struct dentry *dentry)
703 if (dentry->d_flags & DCACHE_NFSFS_RENAMED) 703 if (dentry->d_flags & DCACHE_NFSFS_RENAMED)
704 goto zap; 704 goto zap;
705 705
706 if (dentry->d_inode && 706 if (d_really_is_positive(dentry) &&
707 (test_bit(AFS_VNODE_DELETED, &AFS_FS_I(dentry->d_inode)->flags) || 707 (test_bit(AFS_VNODE_DELETED, &AFS_FS_I(d_inode(dentry))->flags) ||
708 test_bit(AFS_VNODE_PSEUDODIR, &AFS_FS_I(dentry->d_inode)->flags))) 708 test_bit(AFS_VNODE_PSEUDODIR, &AFS_FS_I(d_inode(dentry))->flags)))
709 goto zap; 709 goto zap;
710 710
711 _leave(" = 0 [keep]"); 711 _leave(" = 0 [keep]");
@@ -814,8 +814,8 @@ static int afs_rmdir(struct inode *dir, struct dentry *dentry)
814 if (ret < 0) 814 if (ret < 0)
815 goto rmdir_error; 815 goto rmdir_error;
816 816
817 if (dentry->d_inode) { 817 if (d_really_is_positive(dentry)) {
818 vnode = AFS_FS_I(dentry->d_inode); 818 vnode = AFS_FS_I(d_inode(dentry));
819 clear_nlink(&vnode->vfs_inode); 819 clear_nlink(&vnode->vfs_inode);
820 set_bit(AFS_VNODE_DELETED, &vnode->flags); 820 set_bit(AFS_VNODE_DELETED, &vnode->flags);
821 afs_discard_callback_on_delete(vnode); 821 afs_discard_callback_on_delete(vnode);
@@ -856,8 +856,8 @@ static int afs_unlink(struct inode *dir, struct dentry *dentry)
856 goto error; 856 goto error;
857 } 857 }
858 858
859 if (dentry->d_inode) { 859 if (d_really_is_positive(dentry)) {
860 vnode = AFS_FS_I(dentry->d_inode); 860 vnode = AFS_FS_I(d_inode(dentry));
861 861
862 /* make sure we have a callback promise on the victim */ 862 /* make sure we have a callback promise on the victim */
863 ret = afs_validate(vnode, key); 863 ret = afs_validate(vnode, key);
@@ -869,7 +869,7 @@ static int afs_unlink(struct inode *dir, struct dentry *dentry)
869 if (ret < 0) 869 if (ret < 0)
870 goto remove_error; 870 goto remove_error;
871 871
872 if (dentry->d_inode) { 872 if (d_really_is_positive(dentry)) {
873 /* if the file wasn't deleted due to excess hard links, the 873 /* if the file wasn't deleted due to excess hard links, the
874 * fileserver will break the callback promise on the file - if 874 * fileserver will break the callback promise on the file - if
875 * it had one - before it returns to us, and if it was deleted, 875 * it had one - before it returns to us, and if it was deleted,
@@ -879,7 +879,7 @@ static int afs_unlink(struct inode *dir, struct dentry *dentry)
879 * or it was outstanding on a different server, then it won't 879 * or it was outstanding on a different server, then it won't
880 * break it either... 880 * break it either...
881 */ 881 */
882 vnode = AFS_FS_I(dentry->d_inode); 882 vnode = AFS_FS_I(d_inode(dentry));
883 if (test_bit(AFS_VNODE_DELETED, &vnode->flags)) 883 if (test_bit(AFS_VNODE_DELETED, &vnode->flags))
884 _debug("AFS_VNODE_DELETED"); 884 _debug("AFS_VNODE_DELETED");
885 if (test_bit(AFS_VNODE_CB_BROKEN, &vnode->flags)) 885 if (test_bit(AFS_VNODE_CB_BROKEN, &vnode->flags))
@@ -977,7 +977,7 @@ static int afs_link(struct dentry *from, struct inode *dir,
977 struct key *key; 977 struct key *key;
978 int ret; 978 int ret;
979 979
980 vnode = AFS_FS_I(from->d_inode); 980 vnode = AFS_FS_I(d_inode(from));
981 dvnode = AFS_FS_I(dir); 981 dvnode = AFS_FS_I(dir);
982 982
983 _enter("{%x:%u},{%x:%u},{%pd}", 983 _enter("{%x:%u},{%x:%u},{%pd}",
@@ -1089,7 +1089,7 @@ static int afs_rename(struct inode *old_dir, struct dentry *old_dentry,
1089 struct key *key; 1089 struct key *key;
1090 int ret; 1090 int ret;
1091 1091
1092 vnode = AFS_FS_I(old_dentry->d_inode); 1092 vnode = AFS_FS_I(d_inode(old_dentry));
1093 orig_dvnode = AFS_FS_I(old_dir); 1093 orig_dvnode = AFS_FS_I(old_dir);
1094 new_dvnode = AFS_FS_I(new_dir); 1094 new_dvnode = AFS_FS_I(new_dir);
1095 1095
diff --git a/fs/afs/inode.c b/fs/afs/inode.c
index 8a1d38ef0fc2..e06f5a23352a 100644
--- a/fs/afs/inode.c
+++ b/fs/afs/inode.c
@@ -379,7 +379,7 @@ int afs_getattr(struct vfsmount *mnt, struct dentry *dentry,
379{ 379{
380 struct inode *inode; 380 struct inode *inode;
381 381
382 inode = dentry->d_inode; 382 inode = d_inode(dentry);
383 383
384 _enter("{ ino=%lu v=%u }", inode->i_ino, inode->i_generation); 384 _enter("{ ino=%lu v=%u }", inode->i_ino, inode->i_generation);
385 385
@@ -458,7 +458,7 @@ void afs_evict_inode(struct inode *inode)
458 */ 458 */
459int afs_setattr(struct dentry *dentry, struct iattr *attr) 459int afs_setattr(struct dentry *dentry, struct iattr *attr)
460{ 460{
461 struct afs_vnode *vnode = AFS_FS_I(dentry->d_inode); 461 struct afs_vnode *vnode = AFS_FS_I(d_inode(dentry));
462 struct key *key; 462 struct key *key;
463 int ret; 463 int ret;
464 464
diff --git a/fs/afs/mntpt.c b/fs/afs/mntpt.c
index 938c5ab06d5a..ccd0b212e82a 100644
--- a/fs/afs/mntpt.c
+++ b/fs/afs/mntpt.c
@@ -134,7 +134,7 @@ static struct vfsmount *afs_mntpt_do_automount(struct dentry *mntpt)
134 134
135 _enter("{%pd}", mntpt); 135 _enter("{%pd}", mntpt);
136 136
137 BUG_ON(!mntpt->d_inode); 137 BUG_ON(!d_inode(mntpt));
138 138
139 ret = -ENOMEM; 139 ret = -ENOMEM;
140 devname = (char *) get_zeroed_page(GFP_KERNEL); 140 devname = (char *) get_zeroed_page(GFP_KERNEL);
@@ -145,7 +145,7 @@ static struct vfsmount *afs_mntpt_do_automount(struct dentry *mntpt)
145 if (!options) 145 if (!options)
146 goto error_no_options; 146 goto error_no_options;
147 147
148 vnode = AFS_FS_I(mntpt->d_inode); 148 vnode = AFS_FS_I(d_inode(mntpt));
149 if (test_bit(AFS_VNODE_PSEUDODIR, &vnode->flags)) { 149 if (test_bit(AFS_VNODE_PSEUDODIR, &vnode->flags)) {
150 /* if the directory is a pseudo directory, use the d_name */ 150 /* if the directory is a pseudo directory, use the d_name */
151 static const char afs_root_cell[] = ":root.cell."; 151 static const char afs_root_cell[] = ":root.cell.";
@@ -169,14 +169,14 @@ static struct vfsmount *afs_mntpt_do_automount(struct dentry *mntpt)
169 } 169 }
170 } else { 170 } else {
171 /* read the contents of the AFS special symlink */ 171 /* read the contents of the AFS special symlink */
172 loff_t size = i_size_read(mntpt->d_inode); 172 loff_t size = i_size_read(d_inode(mntpt));
173 char *buf; 173 char *buf;
174 174
175 ret = -EINVAL; 175 ret = -EINVAL;
176 if (size > PAGE_SIZE - 1) 176 if (size > PAGE_SIZE - 1)
177 goto error_no_page; 177 goto error_no_page;
178 178
179 page = read_mapping_page(mntpt->d_inode->i_mapping, 0, NULL); 179 page = read_mapping_page(d_inode(mntpt)->i_mapping, 0, NULL);
180 if (IS_ERR(page)) { 180 if (IS_ERR(page)) {
181 ret = PTR_ERR(page); 181 ret = PTR_ERR(page);
182 goto error_no_page; 182 goto error_no_page;
diff --git a/fs/afs/super.c b/fs/afs/super.c
index c4861557e385..1fb4a5129f7d 100644
--- a/fs/afs/super.c
+++ b/fs/afs/super.c
@@ -529,7 +529,7 @@ static void afs_destroy_inode(struct inode *inode)
529static int afs_statfs(struct dentry *dentry, struct kstatfs *buf) 529static int afs_statfs(struct dentry *dentry, struct kstatfs *buf)
530{ 530{
531 struct afs_volume_status vs; 531 struct afs_volume_status vs;
532 struct afs_vnode *vnode = AFS_FS_I(dentry->d_inode); 532 struct afs_vnode *vnode = AFS_FS_I(d_inode(dentry));
533 struct key *key; 533 struct key *key;
534 int ret; 534 int ret;
535 535
diff --git a/fs/autofs4/autofs_i.h b/fs/autofs4/autofs_i.h
index d10e619632ab..5b700ef1e59d 100644
--- a/fs/autofs4/autofs_i.h
+++ b/fs/autofs4/autofs_i.h
@@ -235,12 +235,12 @@ static inline u32 autofs4_get_dev(struct autofs_sb_info *sbi)
235 235
236static inline u64 autofs4_get_ino(struct autofs_sb_info *sbi) 236static inline u64 autofs4_get_ino(struct autofs_sb_info *sbi)
237{ 237{
238 return sbi->sb->s_root->d_inode->i_ino; 238 return d_inode(sbi->sb->s_root)->i_ino;
239} 239}
240 240
241static inline int simple_positive(struct dentry *dentry) 241static inline int simple_positive(struct dentry *dentry)
242{ 242{
243 return dentry->d_inode && !d_unhashed(dentry); 243 return d_really_is_positive(dentry) && !d_unhashed(dentry);
244} 244}
245 245
246static inline void __autofs4_add_expiring(struct dentry *dentry) 246static inline void __autofs4_add_expiring(struct dentry *dentry)
diff --git a/fs/autofs4/expire.c b/fs/autofs4/expire.c
index 11dd118f75e2..1cebc3c52fa5 100644
--- a/fs/autofs4/expire.c
+++ b/fs/autofs4/expire.c
@@ -374,7 +374,7 @@ static struct dentry *should_expire(struct dentry *dentry,
374 return NULL; 374 return NULL;
375 } 375 }
376 376
377 if (dentry->d_inode && d_is_symlink(dentry)) { 377 if (d_really_is_positive(dentry) && d_is_symlink(dentry)) {
378 DPRINTK("checking symlink %p %pd", dentry, dentry); 378 DPRINTK("checking symlink %p %pd", dentry, dentry);
379 /* 379 /*
380 * A symlink can't be "busy" in the usual sense so 380 * A symlink can't be "busy" in the usual sense so
diff --git a/fs/autofs4/inode.c b/fs/autofs4/inode.c
index 1c55388ae633..a3ae0b2aeb5a 100644
--- a/fs/autofs4/inode.c
+++ b/fs/autofs4/inode.c
@@ -71,7 +71,7 @@ void autofs4_kill_sb(struct super_block *sb)
71static int autofs4_show_options(struct seq_file *m, struct dentry *root) 71static int autofs4_show_options(struct seq_file *m, struct dentry *root)
72{ 72{
73 struct autofs_sb_info *sbi = autofs4_sbi(root->d_sb); 73 struct autofs_sb_info *sbi = autofs4_sbi(root->d_sb);
74 struct inode *root_inode = root->d_sb->s_root->d_inode; 74 struct inode *root_inode = d_inode(root->d_sb->s_root);
75 75
76 if (!sbi) 76 if (!sbi)
77 return 0; 77 return 0;
@@ -352,8 +352,8 @@ struct inode *autofs4_get_inode(struct super_block *sb, umode_t mode)
352 352
353 inode->i_mode = mode; 353 inode->i_mode = mode;
354 if (sb->s_root) { 354 if (sb->s_root) {
355 inode->i_uid = sb->s_root->d_inode->i_uid; 355 inode->i_uid = d_inode(sb->s_root)->i_uid;
356 inode->i_gid = sb->s_root->d_inode->i_gid; 356 inode->i_gid = d_inode(sb->s_root)->i_gid;
357 } 357 }
358 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME; 358 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
359 inode->i_ino = get_next_ino(); 359 inode->i_ino = get_next_ino();
diff --git a/fs/autofs4/root.c b/fs/autofs4/root.c
index 7e44fdd03e2d..c6d7d3dbd52a 100644
--- a/fs/autofs4/root.c
+++ b/fs/autofs4/root.c
@@ -240,7 +240,7 @@ static struct dentry *autofs4_lookup_expiring(struct dentry *dentry,
240 spin_lock(&expiring->d_lock); 240 spin_lock(&expiring->d_lock);
241 241
242 /* We've already been dentry_iput or unlinked */ 242 /* We've already been dentry_iput or unlinked */
243 if (!expiring->d_inode) 243 if (d_really_is_negative(expiring))
244 goto next; 244 goto next;
245 245
246 qstr = &expiring->d_name; 246 qstr = &expiring->d_name;
@@ -371,7 +371,7 @@ static struct vfsmount *autofs4_d_automount(struct path *path)
371 * having d_mountpoint() true, so there's no need to call back 371 * having d_mountpoint() true, so there's no need to call back
372 * to the daemon. 372 * to the daemon.
373 */ 373 */
374 if (dentry->d_inode && d_is_symlink(dentry)) { 374 if (d_really_is_positive(dentry) && d_is_symlink(dentry)) {
375 spin_unlock(&sbi->fs_lock); 375 spin_unlock(&sbi->fs_lock);
376 goto done; 376 goto done;
377 } 377 }
@@ -459,7 +459,7 @@ static int autofs4_d_manage(struct dentry *dentry, bool rcu_walk)
459 return 0; 459 return 0;
460 if (d_mountpoint(dentry)) 460 if (d_mountpoint(dentry))
461 return 0; 461 return 0;
462 inode = ACCESS_ONCE(dentry->d_inode); 462 inode = d_inode_rcu(dentry);
463 if (inode && S_ISLNK(inode->i_mode)) 463 if (inode && S_ISLNK(inode->i_mode))
464 return -EISDIR; 464 return -EISDIR;
465 if (list_empty(&dentry->d_subdirs)) 465 if (list_empty(&dentry->d_subdirs))
@@ -485,7 +485,7 @@ static int autofs4_d_manage(struct dentry *dentry, bool rcu_walk)
485 * an incorrect ELOOP error return. 485 * an incorrect ELOOP error return.
486 */ 486 */
487 if ((!d_mountpoint(dentry) && !simple_empty(dentry)) || 487 if ((!d_mountpoint(dentry) && !simple_empty(dentry)) ||
488 (dentry->d_inode && d_is_symlink(dentry))) 488 (d_really_is_positive(dentry) && d_is_symlink(dentry)))
489 status = -EISDIR; 489 status = -EISDIR;
490 } 490 }
491 spin_unlock(&sbi->fs_lock); 491 spin_unlock(&sbi->fs_lock);
@@ -625,8 +625,8 @@ static int autofs4_dir_unlink(struct inode *dir, struct dentry *dentry)
625 } 625 }
626 dput(ino->dentry); 626 dput(ino->dentry);
627 627
628 dentry->d_inode->i_size = 0; 628 d_inode(dentry)->i_size = 0;
629 clear_nlink(dentry->d_inode); 629 clear_nlink(d_inode(dentry));
630 630
631 dir->i_mtime = CURRENT_TIME; 631 dir->i_mtime = CURRENT_TIME;
632 632
@@ -719,8 +719,8 @@ static int autofs4_dir_rmdir(struct inode *dir, struct dentry *dentry)
719 atomic_dec(&p_ino->count); 719 atomic_dec(&p_ino->count);
720 } 720 }
721 dput(ino->dentry); 721 dput(ino->dentry);
722 dentry->d_inode->i_size = 0; 722 d_inode(dentry)->i_size = 0;
723 clear_nlink(dentry->d_inode); 723 clear_nlink(d_inode(dentry));
724 724
725 if (dir->i_nlink) 725 if (dir->i_nlink)
726 drop_nlink(dir); 726 drop_nlink(dir);
@@ -839,7 +839,7 @@ static inline int autofs4_ask_umount(struct vfsmount *mnt, int __user *p)
839*/ 839*/
840int is_autofs4_dentry(struct dentry *dentry) 840int is_autofs4_dentry(struct dentry *dentry)
841{ 841{
842 return dentry && dentry->d_inode && 842 return dentry && d_really_is_positive(dentry) &&
843 dentry->d_op == &autofs4_dentry_operations && 843 dentry->d_op == &autofs4_dentry_operations &&
844 dentry->d_fsdata != NULL; 844 dentry->d_fsdata != NULL;
845} 845}
diff --git a/fs/autofs4/symlink.c b/fs/autofs4/symlink.c
index 1e8ea192be2b..de58cc7b8076 100644
--- a/fs/autofs4/symlink.c
+++ b/fs/autofs4/symlink.c
@@ -18,7 +18,7 @@ static void *autofs4_follow_link(struct dentry *dentry, struct nameidata *nd)
18 struct autofs_info *ino = autofs4_dentry_ino(dentry); 18 struct autofs_info *ino = autofs4_dentry_ino(dentry);
19 if (ino && !autofs4_oz_mode(sbi)) 19 if (ino && !autofs4_oz_mode(sbi))
20 ino->last_used = jiffies; 20 ino->last_used = jiffies;
21 nd_set_link(nd, dentry->d_inode->i_private); 21 nd_set_link(nd, d_inode(dentry)->i_private);
22 return NULL; 22 return NULL;
23} 23}
24 24
diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
index 2ad05ab93db8..35b755e79c2d 100644
--- a/fs/autofs4/waitq.c
+++ b/fs/autofs4/waitq.c
@@ -322,7 +322,7 @@ static int validate_request(struct autofs_wait_queue **wait,
322 * continue on and create a new request. 322 * continue on and create a new request.
323 */ 323 */
324 if (!IS_ROOT(dentry)) { 324 if (!IS_ROOT(dentry)) {
325 if (dentry->d_inode && d_unhashed(dentry)) { 325 if (d_really_is_positive(dentry) && d_unhashed(dentry)) {
326 struct dentry *parent = dentry->d_parent; 326 struct dentry *parent = dentry->d_parent;
327 new = d_lookup(parent, &dentry->d_name); 327 new = d_lookup(parent, &dentry->d_name);
328 if (new) 328 if (new)
@@ -364,7 +364,7 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
364 if (pid == 0 || tgid == 0) 364 if (pid == 0 || tgid == 0)
365 return -ENOENT; 365 return -ENOENT;
366 366
367 if (!dentry->d_inode) { 367 if (d_really_is_negative(dentry)) {
368 /* 368 /*
369 * A wait for a negative dentry is invalid for certain 369 * A wait for a negative dentry is invalid for certain
370 * cases. A direct or offset mount "always" has its mount 370 * cases. A direct or offset mount "always" has its mount
diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
index 16e0a48bfccd..7943533c3868 100644
--- a/fs/befs/linuxvfs.c
+++ b/fs/befs/linuxvfs.c
@@ -471,7 +471,7 @@ static void *
471befs_follow_link(struct dentry *dentry, struct nameidata *nd) 471befs_follow_link(struct dentry *dentry, struct nameidata *nd)
472{ 472{
473 struct super_block *sb = dentry->d_sb; 473 struct super_block *sb = dentry->d_sb;
474 struct befs_inode_info *befs_ino = BEFS_I(dentry->d_inode); 474 struct befs_inode_info *befs_ino = BEFS_I(d_inode(dentry));
475 befs_data_stream *data = &befs_ino->i_data.ds; 475 befs_data_stream *data = &befs_ino->i_data.ds;
476 befs_off_t len = data->size; 476 befs_off_t len = data->size;
477 char *link; 477 char *link;
@@ -501,7 +501,7 @@ befs_follow_link(struct dentry *dentry, struct nameidata *nd)
501static void * 501static void *
502befs_fast_follow_link(struct dentry *dentry, struct nameidata *nd) 502befs_fast_follow_link(struct dentry *dentry, struct nameidata *nd)
503{ 503{
504 struct befs_inode_info *befs_ino = BEFS_I(dentry->d_inode); 504 struct befs_inode_info *befs_ino = BEFS_I(d_inode(dentry));
505 505
506 nd_set_link(nd, befs_ino->i_data.symlink); 506 nd_set_link(nd, befs_ino->i_data.symlink);
507 return NULL; 507 return NULL;
diff --git a/fs/bfs/dir.c b/fs/bfs/dir.c
index 7a8182770649..3ec6113146c0 100644
--- a/fs/bfs/dir.c
+++ b/fs/bfs/dir.c
@@ -153,7 +153,7 @@ static struct dentry *bfs_lookup(struct inode *dir, struct dentry *dentry,
153static int bfs_link(struct dentry *old, struct inode *dir, 153static int bfs_link(struct dentry *old, struct inode *dir,
154 struct dentry *new) 154 struct dentry *new)
155{ 155{
156 struct inode *inode = old->d_inode; 156 struct inode *inode = d_inode(old);
157 struct bfs_sb_info *info = BFS_SB(inode->i_sb); 157 struct bfs_sb_info *info = BFS_SB(inode->i_sb);
158 int err; 158 int err;
159 159
@@ -176,7 +176,7 @@ static int bfs_link(struct dentry *old, struct inode *dir,
176static int bfs_unlink(struct inode *dir, struct dentry *dentry) 176static int bfs_unlink(struct inode *dir, struct dentry *dentry)
177{ 177{
178 int error = -ENOENT; 178 int error = -ENOENT;
179 struct inode *inode = dentry->d_inode; 179 struct inode *inode = d_inode(dentry);
180 struct buffer_head *bh; 180 struct buffer_head *bh;
181 struct bfs_dirent *de; 181 struct bfs_dirent *de;
182 struct bfs_sb_info *info = BFS_SB(inode->i_sb); 182 struct bfs_sb_info *info = BFS_SB(inode->i_sb);
@@ -216,7 +216,7 @@ static int bfs_rename(struct inode *old_dir, struct dentry *old_dentry,
216 int error = -ENOENT; 216 int error = -ENOENT;
217 217
218 old_bh = new_bh = NULL; 218 old_bh = new_bh = NULL;
219 old_inode = old_dentry->d_inode; 219 old_inode = d_inode(old_dentry);
220 if (S_ISDIR(old_inode->i_mode)) 220 if (S_ISDIR(old_inode->i_mode))
221 return -EINVAL; 221 return -EINVAL;
222 222
@@ -231,7 +231,7 @@ static int bfs_rename(struct inode *old_dir, struct dentry *old_dentry,
231 goto end_rename; 231 goto end_rename;
232 232
233 error = -EPERM; 233 error = -EPERM;
234 new_inode = new_dentry->d_inode; 234 new_inode = d_inode(new_dentry);
235 new_bh = bfs_find_entry(new_dir, 235 new_bh = bfs_find_entry(new_dir,
236 new_dentry->d_name.name, 236 new_dentry->d_name.name,
237 new_dentry->d_name.len, &new_de); 237 new_dentry->d_name.len, &new_de);
diff --git a/fs/binfmt_misc.c b/fs/binfmt_misc.c
index 9dcb05409ba7..78f005f37847 100644
--- a/fs/binfmt_misc.c
+++ b/fs/binfmt_misc.c
@@ -591,7 +591,7 @@ static void kill_node(Node *e)
591 write_unlock(&entries_lock); 591 write_unlock(&entries_lock);
592 592
593 if (dentry) { 593 if (dentry) {
594 drop_nlink(dentry->d_inode); 594 drop_nlink(d_inode(dentry));
595 d_drop(dentry); 595 d_drop(dentry);
596 dput(dentry); 596 dput(dentry);
597 simple_release_fs(&bm_mnt, &entry_count); 597 simple_release_fs(&bm_mnt, &entry_count);
@@ -638,11 +638,11 @@ static ssize_t bm_entry_write(struct file *file, const char __user *buffer,
638 case 3: 638 case 3:
639 /* Delete this handler. */ 639 /* Delete this handler. */
640 root = dget(file->f_path.dentry->d_sb->s_root); 640 root = dget(file->f_path.dentry->d_sb->s_root);
641 mutex_lock(&root->d_inode->i_mutex); 641 mutex_lock(&d_inode(root)->i_mutex);
642 642
643 kill_node(e); 643 kill_node(e);
644 644
645 mutex_unlock(&root->d_inode->i_mutex); 645 mutex_unlock(&d_inode(root)->i_mutex);
646 dput(root); 646 dput(root);
647 break; 647 break;
648 default: 648 default:
@@ -675,14 +675,14 @@ static ssize_t bm_register_write(struct file *file, const char __user *buffer,
675 return PTR_ERR(e); 675 return PTR_ERR(e);
676 676
677 root = dget(sb->s_root); 677 root = dget(sb->s_root);
678 mutex_lock(&root->d_inode->i_mutex); 678 mutex_lock(&d_inode(root)->i_mutex);
679 dentry = lookup_one_len(e->name, root, strlen(e->name)); 679 dentry = lookup_one_len(e->name, root, strlen(e->name));
680 err = PTR_ERR(dentry); 680 err = PTR_ERR(dentry);
681 if (IS_ERR(dentry)) 681 if (IS_ERR(dentry))
682 goto out; 682 goto out;
683 683
684 err = -EEXIST; 684 err = -EEXIST;
685 if (dentry->d_inode) 685 if (d_really_is_positive(dentry))
686 goto out2; 686 goto out2;
687 687
688 inode = bm_get_inode(sb, S_IFREG | 0644); 688 inode = bm_get_inode(sb, S_IFREG | 0644);
@@ -711,7 +711,7 @@ static ssize_t bm_register_write(struct file *file, const char __user *buffer,
711out2: 711out2:
712 dput(dentry); 712 dput(dentry);
713out: 713out:
714 mutex_unlock(&root->d_inode->i_mutex); 714 mutex_unlock(&d_inode(root)->i_mutex);
715 dput(root); 715 dput(root);
716 716
717 if (err) { 717 if (err) {
@@ -754,12 +754,12 @@ static ssize_t bm_status_write(struct file *file, const char __user *buffer,
754 case 3: 754 case 3:
755 /* Delete all handlers. */ 755 /* Delete all handlers. */
756 root = dget(file->f_path.dentry->d_sb->s_root); 756 root = dget(file->f_path.dentry->d_sb->s_root);
757 mutex_lock(&root->d_inode->i_mutex); 757 mutex_lock(&d_inode(root)->i_mutex);
758 758
759 while (!list_empty(&entries)) 759 while (!list_empty(&entries))
760 kill_node(list_entry(entries.next, Node, list)); 760 kill_node(list_entry(entries.next, Node, list));
761 761
762 mutex_unlock(&root->d_inode->i_mutex); 762 mutex_unlock(&d_inode(root)->i_mutex);
763 dput(root); 763 dput(root);
764 break; 764 break;
765 default: 765 default:
diff --git a/fs/block_dev.c b/fs/block_dev.c
index 897ee0503932..c7e4163ede87 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -152,7 +152,8 @@ blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter, loff_t offset)
152 struct inode *inode = file->f_mapping->host; 152 struct inode *inode = file->f_mapping->host;
153 153
154 return __blockdev_direct_IO(iocb, inode, I_BDEV(inode), iter, offset, 154 return __blockdev_direct_IO(iocb, inode, I_BDEV(inode), iter, offset,
155 blkdev_get_block, NULL, NULL, 0); 155 blkdev_get_block, NULL, NULL,
156 DIO_SKIP_DIO_COUNT);
156} 157}
157 158
158int __sync_blockdev(struct block_device *bdev, int wait) 159int __sync_blockdev(struct block_device *bdev, int wait)
@@ -1716,7 +1717,7 @@ struct block_device *lookup_bdev(const char *pathname)
1716 if (error) 1717 if (error)
1717 return ERR_PTR(error); 1718 return ERR_PTR(error);
1718 1719
1719 inode = path.dentry->d_inode; 1720 inode = d_backing_inode(path.dentry);
1720 error = -ENOTBLK; 1721 error = -ENOTBLK;
1721 if (!S_ISBLK(inode->i_mode)) 1722 if (!S_ISBLK(inode->i_mode))
1722 goto fail; 1723 goto fail;
diff --git a/fs/btrfs/async-thread.c b/fs/btrfs/async-thread.c
index 4dabeb893b7c..df9932b00d08 100644
--- a/fs/btrfs/async-thread.c
+++ b/fs/btrfs/async-thread.c
@@ -87,7 +87,7 @@ BTRFS_WORK_HELPER(scrubwrc_helper);
87BTRFS_WORK_HELPER(scrubnc_helper); 87BTRFS_WORK_HELPER(scrubnc_helper);
88 88
89static struct __btrfs_workqueue * 89static struct __btrfs_workqueue *
90__btrfs_alloc_workqueue(const char *name, int flags, int max_active, 90__btrfs_alloc_workqueue(const char *name, unsigned int flags, int max_active,
91 int thresh) 91 int thresh)
92{ 92{
93 struct __btrfs_workqueue *ret = kzalloc(sizeof(*ret), GFP_NOFS); 93 struct __btrfs_workqueue *ret = kzalloc(sizeof(*ret), GFP_NOFS);
@@ -132,7 +132,7 @@ static inline void
132__btrfs_destroy_workqueue(struct __btrfs_workqueue *wq); 132__btrfs_destroy_workqueue(struct __btrfs_workqueue *wq);
133 133
134struct btrfs_workqueue *btrfs_alloc_workqueue(const char *name, 134struct btrfs_workqueue *btrfs_alloc_workqueue(const char *name,
135 int flags, 135 unsigned int flags,
136 int max_active, 136 int max_active,
137 int thresh) 137 int thresh)
138{ 138{
diff --git a/fs/btrfs/async-thread.h b/fs/btrfs/async-thread.h
index e386c29ef1f6..ec2ee477f8ba 100644
--- a/fs/btrfs/async-thread.h
+++ b/fs/btrfs/async-thread.h
@@ -66,7 +66,7 @@ BTRFS_WORK_HELPER_PROTO(scrubwrc_helper);
66BTRFS_WORK_HELPER_PROTO(scrubnc_helper); 66BTRFS_WORK_HELPER_PROTO(scrubnc_helper);
67 67
68struct btrfs_workqueue *btrfs_alloc_workqueue(const char *name, 68struct btrfs_workqueue *btrfs_alloc_workqueue(const char *name,
69 int flags, 69 unsigned int flags,
70 int max_active, 70 int max_active,
71 int thresh); 71 int thresh);
72void btrfs_init_work(struct btrfs_work *work, btrfs_work_func_t helper, 72void btrfs_init_work(struct btrfs_work *work, btrfs_work_func_t helper,
diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c
index f55721ff9385..9de772ee0031 100644
--- a/fs/btrfs/backref.c
+++ b/fs/btrfs/backref.c
@@ -1206,7 +1206,7 @@ int btrfs_check_shared(struct btrfs_trans_handle *trans,
1206 struct ulist *roots = NULL; 1206 struct ulist *roots = NULL;
1207 struct ulist_iterator uiter; 1207 struct ulist_iterator uiter;
1208 struct ulist_node *node; 1208 struct ulist_node *node;
1209 struct seq_list elem = {}; 1209 struct seq_list elem = SEQ_LIST_INIT(elem);
1210 int ret = 0; 1210 int ret = 0;
1211 1211
1212 tmp = ulist_alloc(GFP_NOFS); 1212 tmp = ulist_alloc(GFP_NOFS);
@@ -1610,7 +1610,7 @@ int iterate_extent_inodes(struct btrfs_fs_info *fs_info,
1610 struct ulist *roots = NULL; 1610 struct ulist *roots = NULL;
1611 struct ulist_node *ref_node = NULL; 1611 struct ulist_node *ref_node = NULL;
1612 struct ulist_node *root_node = NULL; 1612 struct ulist_node *root_node = NULL;
1613 struct seq_list tree_mod_seq_elem = {}; 1613 struct seq_list tree_mod_seq_elem = SEQ_LIST_INIT(tree_mod_seq_elem);
1614 struct ulist_iterator ref_uiter; 1614 struct ulist_iterator ref_uiter;
1615 struct ulist_iterator root_uiter; 1615 struct ulist_iterator root_uiter;
1616 1616
diff --git a/fs/btrfs/btrfs_inode.h b/fs/btrfs/btrfs_inode.h
index de5e4f2adfea..0ef5cc13fae2 100644
--- a/fs/btrfs/btrfs_inode.h
+++ b/fs/btrfs/btrfs_inode.h
@@ -66,7 +66,11 @@ struct btrfs_inode {
66 */ 66 */
67 struct btrfs_key location; 67 struct btrfs_key location;
68 68
69 /* Lock for counters */ 69 /*
70 * Lock for counters and all fields used to determine if the inode is in
71 * the log or not (last_trans, last_sub_trans, last_log_commit,
72 * logged_trans).
73 */
70 spinlock_t lock; 74 spinlock_t lock;
71 75
72 /* the extent_tree has caches of all the extent mappings to disk */ 76 /* the extent_tree has caches of all the extent mappings to disk */
@@ -250,6 +254,9 @@ static inline bool btrfs_is_free_space_inode(struct inode *inode)
250 254
251static inline int btrfs_inode_in_log(struct inode *inode, u64 generation) 255static inline int btrfs_inode_in_log(struct inode *inode, u64 generation)
252{ 256{
257 int ret = 0;
258
259 spin_lock(&BTRFS_I(inode)->lock);
253 if (BTRFS_I(inode)->logged_trans == generation && 260 if (BTRFS_I(inode)->logged_trans == generation &&
254 BTRFS_I(inode)->last_sub_trans <= 261 BTRFS_I(inode)->last_sub_trans <=
255 BTRFS_I(inode)->last_log_commit && 262 BTRFS_I(inode)->last_log_commit &&
@@ -263,9 +270,10 @@ static inline int btrfs_inode_in_log(struct inode *inode, u64 generation)
263 */ 270 */
264 smp_mb(); 271 smp_mb();
265 if (list_empty(&BTRFS_I(inode)->extent_tree.modified_extents)) 272 if (list_empty(&BTRFS_I(inode)->extent_tree.modified_extents))
266 return 1; 273 ret = 1;
267 } 274 }
268 return 0; 275 spin_unlock(&BTRFS_I(inode)->lock);
276 return ret;
269} 277}
270 278
271#define BTRFS_DIO_ORIG_BIO_SUBMITTED 0x1 279#define BTRFS_DIO_ORIG_BIO_SUBMITTED 0x1
diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
index d897ef803b3b..ce7dec88f4b8 100644
--- a/fs/btrfs/check-integrity.c
+++ b/fs/btrfs/check-integrity.c
@@ -2990,8 +2990,8 @@ static void __btrfsic_submit_bio(int rw, struct bio *bio)
2990 (unsigned long long)bio->bi_iter.bi_sector, 2990 (unsigned long long)bio->bi_iter.bi_sector,
2991 dev_bytenr, bio->bi_bdev); 2991 dev_bytenr, bio->bi_bdev);
2992 2992
2993 mapped_datav = kmalloc(sizeof(*mapped_datav) * bio->bi_vcnt, 2993 mapped_datav = kmalloc_array(bio->bi_vcnt,
2994 GFP_NOFS); 2994 sizeof(*mapped_datav), GFP_NOFS);
2995 if (!mapped_datav) 2995 if (!mapped_datav)
2996 goto leave; 2996 goto leave;
2997 cur_bytenr = dev_bytenr; 2997 cur_bytenr = dev_bytenr;
@@ -3241,8 +3241,5 @@ void btrfsic_unmount(struct btrfs_root *root,
3241 3241
3242 mutex_unlock(&btrfsic_mutex); 3242 mutex_unlock(&btrfsic_mutex);
3243 3243
3244 if (is_vmalloc_addr(state)) 3244 kvfree(state);
3245 vfree(state);
3246 else
3247 kfree(state);
3248} 3245}
diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c
index e9df8862012c..ce62324c78e7 100644
--- a/fs/btrfs/compression.c
+++ b/fs/btrfs/compression.c
@@ -622,7 +622,7 @@ int btrfs_submit_compressed_read(struct inode *inode, struct bio *bio,
622 cb->orig_bio = bio; 622 cb->orig_bio = bio;
623 623
624 nr_pages = DIV_ROUND_UP(compressed_len, PAGE_CACHE_SIZE); 624 nr_pages = DIV_ROUND_UP(compressed_len, PAGE_CACHE_SIZE);
625 cb->compressed_pages = kzalloc(sizeof(struct page *) * nr_pages, 625 cb->compressed_pages = kcalloc(nr_pages, sizeof(struct page *),
626 GFP_NOFS); 626 GFP_NOFS);
627 if (!cb->compressed_pages) 627 if (!cb->compressed_pages)
628 goto fail1; 628 goto fail1;
@@ -750,7 +750,7 @@ static int comp_num_workspace[BTRFS_COMPRESS_TYPES];
750static atomic_t comp_alloc_workspace[BTRFS_COMPRESS_TYPES]; 750static atomic_t comp_alloc_workspace[BTRFS_COMPRESS_TYPES];
751static wait_queue_head_t comp_workspace_wait[BTRFS_COMPRESS_TYPES]; 751static wait_queue_head_t comp_workspace_wait[BTRFS_COMPRESS_TYPES];
752 752
753static struct btrfs_compress_op *btrfs_compress_op[] = { 753static const struct btrfs_compress_op * const btrfs_compress_op[] = {
754 &btrfs_zlib_compress, 754 &btrfs_zlib_compress,
755 &btrfs_lzo_compress, 755 &btrfs_lzo_compress,
756}; 756};
diff --git a/fs/btrfs/compression.h b/fs/btrfs/compression.h
index d181f70caae0..13a4dc0436c9 100644
--- a/fs/btrfs/compression.h
+++ b/fs/btrfs/compression.h
@@ -77,7 +77,7 @@ struct btrfs_compress_op {
77 size_t srclen, size_t destlen); 77 size_t srclen, size_t destlen);
78}; 78};
79 79
80extern struct btrfs_compress_op btrfs_zlib_compress; 80extern const struct btrfs_compress_op btrfs_zlib_compress;
81extern struct btrfs_compress_op btrfs_lzo_compress; 81extern const struct btrfs_compress_op btrfs_lzo_compress;
82 82
83#endif 83#endif
diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
index 6d67f32e648d..0f11ebc92f02 100644
--- a/fs/btrfs/ctree.c
+++ b/fs/btrfs/ctree.c
@@ -578,7 +578,7 @@ tree_mod_log_insert_move(struct btrfs_fs_info *fs_info,
578 if (!tree_mod_need_log(fs_info, eb)) 578 if (!tree_mod_need_log(fs_info, eb))
579 return 0; 579 return 0;
580 580
581 tm_list = kzalloc(nr_items * sizeof(struct tree_mod_elem *), flags); 581 tm_list = kcalloc(nr_items, sizeof(struct tree_mod_elem *), flags);
582 if (!tm_list) 582 if (!tm_list)
583 return -ENOMEM; 583 return -ENOMEM;
584 584
@@ -677,7 +677,7 @@ tree_mod_log_insert_root(struct btrfs_fs_info *fs_info,
677 677
678 if (log_removal && btrfs_header_level(old_root) > 0) { 678 if (log_removal && btrfs_header_level(old_root) > 0) {
679 nritems = btrfs_header_nritems(old_root); 679 nritems = btrfs_header_nritems(old_root);
680 tm_list = kzalloc(nritems * sizeof(struct tree_mod_elem *), 680 tm_list = kcalloc(nritems, sizeof(struct tree_mod_elem *),
681 flags); 681 flags);
682 if (!tm_list) { 682 if (!tm_list) {
683 ret = -ENOMEM; 683 ret = -ENOMEM;
@@ -814,7 +814,7 @@ tree_mod_log_eb_copy(struct btrfs_fs_info *fs_info, struct extent_buffer *dst,
814 if (btrfs_header_level(dst) == 0 && btrfs_header_level(src) == 0) 814 if (btrfs_header_level(dst) == 0 && btrfs_header_level(src) == 0)
815 return 0; 815 return 0;
816 816
817 tm_list = kzalloc(nr_items * 2 * sizeof(struct tree_mod_elem *), 817 tm_list = kcalloc(nr_items * 2, sizeof(struct tree_mod_elem *),
818 GFP_NOFS); 818 GFP_NOFS);
819 if (!tm_list) 819 if (!tm_list)
820 return -ENOMEM; 820 return -ENOMEM;
@@ -905,8 +905,7 @@ tree_mod_log_free_eb(struct btrfs_fs_info *fs_info, struct extent_buffer *eb)
905 return 0; 905 return 0;
906 906
907 nritems = btrfs_header_nritems(eb); 907 nritems = btrfs_header_nritems(eb);
908 tm_list = kzalloc(nritems * sizeof(struct tree_mod_elem *), 908 tm_list = kcalloc(nritems, sizeof(struct tree_mod_elem *), GFP_NOFS);
909 GFP_NOFS);
910 if (!tm_list) 909 if (!tm_list)
911 return -ENOMEM; 910 return -ENOMEM;
912 911
@@ -1073,7 +1072,7 @@ static noinline int update_ref_for_cow(struct btrfs_trans_handle *trans,
1073 ret = btrfs_dec_ref(trans, root, buf, 1); 1072 ret = btrfs_dec_ref(trans, root, buf, 1);
1074 BUG_ON(ret); /* -ENOMEM */ 1073 BUG_ON(ret); /* -ENOMEM */
1075 } 1074 }
1076 clean_tree_block(trans, root, buf); 1075 clean_tree_block(trans, root->fs_info, buf);
1077 *last_ref = 1; 1076 *last_ref = 1;
1078 } 1077 }
1079 return 0; 1078 return 0;
@@ -1678,7 +1677,7 @@ int btrfs_realloc_node(struct btrfs_trans_handle *trans,
1678 continue; 1677 continue;
1679 } 1678 }
1680 1679
1681 cur = btrfs_find_tree_block(root, blocknr); 1680 cur = btrfs_find_tree_block(root->fs_info, blocknr);
1682 if (cur) 1681 if (cur)
1683 uptodate = btrfs_buffer_uptodate(cur, gen, 0); 1682 uptodate = btrfs_buffer_uptodate(cur, gen, 0);
1684 else 1683 else
@@ -1943,7 +1942,7 @@ static noinline int balance_level(struct btrfs_trans_handle *trans,
1943 1942
1944 path->locks[level] = 0; 1943 path->locks[level] = 0;
1945 path->nodes[level] = NULL; 1944 path->nodes[level] = NULL;
1946 clean_tree_block(trans, root, mid); 1945 clean_tree_block(trans, root->fs_info, mid);
1947 btrfs_tree_unlock(mid); 1946 btrfs_tree_unlock(mid);
1948 /* once for the path */ 1947 /* once for the path */
1949 free_extent_buffer(mid); 1948 free_extent_buffer(mid);
@@ -1997,7 +1996,7 @@ static noinline int balance_level(struct btrfs_trans_handle *trans,
1997 if (wret < 0 && wret != -ENOSPC) 1996 if (wret < 0 && wret != -ENOSPC)
1998 ret = wret; 1997 ret = wret;
1999 if (btrfs_header_nritems(right) == 0) { 1998 if (btrfs_header_nritems(right) == 0) {
2000 clean_tree_block(trans, root, right); 1999 clean_tree_block(trans, root->fs_info, right);
2001 btrfs_tree_unlock(right); 2000 btrfs_tree_unlock(right);
2002 del_ptr(root, path, level + 1, pslot + 1); 2001 del_ptr(root, path, level + 1, pslot + 1);
2003 root_sub_used(root, right->len); 2002 root_sub_used(root, right->len);
@@ -2041,7 +2040,7 @@ static noinline int balance_level(struct btrfs_trans_handle *trans,
2041 BUG_ON(wret == 1); 2040 BUG_ON(wret == 1);
2042 } 2041 }
2043 if (btrfs_header_nritems(mid) == 0) { 2042 if (btrfs_header_nritems(mid) == 0) {
2044 clean_tree_block(trans, root, mid); 2043 clean_tree_block(trans, root->fs_info, mid);
2045 btrfs_tree_unlock(mid); 2044 btrfs_tree_unlock(mid);
2046 del_ptr(root, path, level + 1, pslot); 2045 del_ptr(root, path, level + 1, pslot);
2047 root_sub_used(root, mid->len); 2046 root_sub_used(root, mid->len);
@@ -2259,7 +2258,7 @@ static void reada_for_search(struct btrfs_root *root,
2259 2258
2260 search = btrfs_node_blockptr(node, slot); 2259 search = btrfs_node_blockptr(node, slot);
2261 blocksize = root->nodesize; 2260 blocksize = root->nodesize;
2262 eb = btrfs_find_tree_block(root, search); 2261 eb = btrfs_find_tree_block(root->fs_info, search);
2263 if (eb) { 2262 if (eb) {
2264 free_extent_buffer(eb); 2263 free_extent_buffer(eb);
2265 return; 2264 return;
@@ -2319,7 +2318,7 @@ static noinline void reada_for_balance(struct btrfs_root *root,
2319 if (slot > 0) { 2318 if (slot > 0) {
2320 block1 = btrfs_node_blockptr(parent, slot - 1); 2319 block1 = btrfs_node_blockptr(parent, slot - 1);
2321 gen = btrfs_node_ptr_generation(parent, slot - 1); 2320 gen = btrfs_node_ptr_generation(parent, slot - 1);
2322 eb = btrfs_find_tree_block(root, block1); 2321 eb = btrfs_find_tree_block(root->fs_info, block1);
2323 /* 2322 /*
2324 * if we get -eagain from btrfs_buffer_uptodate, we 2323 * if we get -eagain from btrfs_buffer_uptodate, we
2325 * don't want to return eagain here. That will loop 2324 * don't want to return eagain here. That will loop
@@ -2332,7 +2331,7 @@ static noinline void reada_for_balance(struct btrfs_root *root,
2332 if (slot + 1 < nritems) { 2331 if (slot + 1 < nritems) {
2333 block2 = btrfs_node_blockptr(parent, slot + 1); 2332 block2 = btrfs_node_blockptr(parent, slot + 1);
2334 gen = btrfs_node_ptr_generation(parent, slot + 1); 2333 gen = btrfs_node_ptr_generation(parent, slot + 1);
2335 eb = btrfs_find_tree_block(root, block2); 2334 eb = btrfs_find_tree_block(root->fs_info, block2);
2336 if (eb && btrfs_buffer_uptodate(eb, gen, 1) != 0) 2335 if (eb && btrfs_buffer_uptodate(eb, gen, 1) != 0)
2337 block2 = 0; 2336 block2 = 0;
2338 free_extent_buffer(eb); 2337 free_extent_buffer(eb);
@@ -2450,7 +2449,7 @@ read_block_for_search(struct btrfs_trans_handle *trans,
2450 blocknr = btrfs_node_blockptr(b, slot); 2449 blocknr = btrfs_node_blockptr(b, slot);
2451 gen = btrfs_node_ptr_generation(b, slot); 2450 gen = btrfs_node_ptr_generation(b, slot);
2452 2451
2453 tmp = btrfs_find_tree_block(root, blocknr); 2452 tmp = btrfs_find_tree_block(root->fs_info, blocknr);
2454 if (tmp) { 2453 if (tmp) {
2455 /* first we do an atomic uptodate check */ 2454 /* first we do an atomic uptodate check */
2456 if (btrfs_buffer_uptodate(tmp, gen, 1) > 0) { 2455 if (btrfs_buffer_uptodate(tmp, gen, 1) > 0) {
@@ -3126,7 +3125,8 @@ again:
3126 * higher levels 3125 * higher levels
3127 * 3126 *
3128 */ 3127 */
3129static void fixup_low_keys(struct btrfs_root *root, struct btrfs_path *path, 3128static void fixup_low_keys(struct btrfs_fs_info *fs_info,
3129 struct btrfs_path *path,
3130 struct btrfs_disk_key *key, int level) 3130 struct btrfs_disk_key *key, int level)
3131{ 3131{
3132 int i; 3132 int i;
@@ -3137,7 +3137,7 @@ static void fixup_low_keys(struct btrfs_root *root, struct btrfs_path *path,
3137 if (!path->nodes[i]) 3137 if (!path->nodes[i])
3138 break; 3138 break;
3139 t = path->nodes[i]; 3139 t = path->nodes[i];
3140 tree_mod_log_set_node_key(root->fs_info, t, tslot, 1); 3140 tree_mod_log_set_node_key(fs_info, t, tslot, 1);
3141 btrfs_set_node_key(t, key, tslot); 3141 btrfs_set_node_key(t, key, tslot);
3142 btrfs_mark_buffer_dirty(path->nodes[i]); 3142 btrfs_mark_buffer_dirty(path->nodes[i]);
3143 if (tslot != 0) 3143 if (tslot != 0)
@@ -3151,7 +3151,8 @@ static void fixup_low_keys(struct btrfs_root *root, struct btrfs_path *path,
3151 * This function isn't completely safe. It's the caller's responsibility 3151 * This function isn't completely safe. It's the caller's responsibility
3152 * that the new key won't break the order 3152 * that the new key won't break the order
3153 */ 3153 */
3154void btrfs_set_item_key_safe(struct btrfs_root *root, struct btrfs_path *path, 3154void btrfs_set_item_key_safe(struct btrfs_fs_info *fs_info,
3155 struct btrfs_path *path,
3155 struct btrfs_key *new_key) 3156 struct btrfs_key *new_key)
3156{ 3157{
3157 struct btrfs_disk_key disk_key; 3158 struct btrfs_disk_key disk_key;
@@ -3173,7 +3174,7 @@ void btrfs_set_item_key_safe(struct btrfs_root *root, struct btrfs_path *path,
3173 btrfs_set_item_key(eb, &disk_key, slot); 3174 btrfs_set_item_key(eb, &disk_key, slot);
3174 btrfs_mark_buffer_dirty(eb); 3175 btrfs_mark_buffer_dirty(eb);
3175 if (slot == 0) 3176 if (slot == 0)
3176 fixup_low_keys(root, path, &disk_key, 1); 3177 fixup_low_keys(fs_info, path, &disk_key, 1);
3177} 3178}
3178 3179
3179/* 3180/*
@@ -3692,7 +3693,7 @@ static noinline int __push_leaf_right(struct btrfs_trans_handle *trans,
3692 if (left_nritems) 3693 if (left_nritems)
3693 btrfs_mark_buffer_dirty(left); 3694 btrfs_mark_buffer_dirty(left);
3694 else 3695 else
3695 clean_tree_block(trans, root, left); 3696 clean_tree_block(trans, root->fs_info, left);
3696 3697
3697 btrfs_mark_buffer_dirty(right); 3698 btrfs_mark_buffer_dirty(right);
3698 3699
@@ -3704,7 +3705,7 @@ static noinline int __push_leaf_right(struct btrfs_trans_handle *trans,
3704 if (path->slots[0] >= left_nritems) { 3705 if (path->slots[0] >= left_nritems) {
3705 path->slots[0] -= left_nritems; 3706 path->slots[0] -= left_nritems;
3706 if (btrfs_header_nritems(path->nodes[0]) == 0) 3707 if (btrfs_header_nritems(path->nodes[0]) == 0)
3707 clean_tree_block(trans, root, path->nodes[0]); 3708 clean_tree_block(trans, root->fs_info, path->nodes[0]);
3708 btrfs_tree_unlock(path->nodes[0]); 3709 btrfs_tree_unlock(path->nodes[0]);
3709 free_extent_buffer(path->nodes[0]); 3710 free_extent_buffer(path->nodes[0]);
3710 path->nodes[0] = right; 3711 path->nodes[0] = right;
@@ -3928,10 +3929,10 @@ static noinline int __push_leaf_left(struct btrfs_trans_handle *trans,
3928 if (right_nritems) 3929 if (right_nritems)
3929 btrfs_mark_buffer_dirty(right); 3930 btrfs_mark_buffer_dirty(right);
3930 else 3931 else
3931 clean_tree_block(trans, root, right); 3932 clean_tree_block(trans, root->fs_info, right);
3932 3933
3933 btrfs_item_key(right, &disk_key, 0); 3934 btrfs_item_key(right, &disk_key, 0);
3934 fixup_low_keys(root, path, &disk_key, 1); 3935 fixup_low_keys(root->fs_info, path, &disk_key, 1);
3935 3936
3936 /* then fixup the leaf pointer in the path */ 3937 /* then fixup the leaf pointer in the path */
3937 if (path->slots[0] < push_items) { 3938 if (path->slots[0] < push_items) {
@@ -4168,6 +4169,7 @@ static noinline int split_leaf(struct btrfs_trans_handle *trans,
4168 int mid; 4169 int mid;
4169 int slot; 4170 int slot;
4170 struct extent_buffer *right; 4171 struct extent_buffer *right;
4172 struct btrfs_fs_info *fs_info = root->fs_info;
4171 int ret = 0; 4173 int ret = 0;
4172 int wret; 4174 int wret;
4173 int split; 4175 int split;
@@ -4271,10 +4273,10 @@ again:
4271 btrfs_set_header_backref_rev(right, BTRFS_MIXED_BACKREF_REV); 4273 btrfs_set_header_backref_rev(right, BTRFS_MIXED_BACKREF_REV);
4272 btrfs_set_header_owner(right, root->root_key.objectid); 4274 btrfs_set_header_owner(right, root->root_key.objectid);
4273 btrfs_set_header_level(right, 0); 4275 btrfs_set_header_level(right, 0);
4274 write_extent_buffer(right, root->fs_info->fsid, 4276 write_extent_buffer(right, fs_info->fsid,
4275 btrfs_header_fsid(), BTRFS_FSID_SIZE); 4277 btrfs_header_fsid(), BTRFS_FSID_SIZE);
4276 4278
4277 write_extent_buffer(right, root->fs_info->chunk_tree_uuid, 4279 write_extent_buffer(right, fs_info->chunk_tree_uuid,
4278 btrfs_header_chunk_tree_uuid(right), 4280 btrfs_header_chunk_tree_uuid(right),
4279 BTRFS_UUID_SIZE); 4281 BTRFS_UUID_SIZE);
4280 4282
@@ -4297,7 +4299,7 @@ again:
4297 path->nodes[0] = right; 4299 path->nodes[0] = right;
4298 path->slots[0] = 0; 4300 path->slots[0] = 0;
4299 if (path->slots[1] == 0) 4301 if (path->slots[1] == 0)
4300 fixup_low_keys(root, path, &disk_key, 1); 4302 fixup_low_keys(fs_info, path, &disk_key, 1);
4301 } 4303 }
4302 btrfs_mark_buffer_dirty(right); 4304 btrfs_mark_buffer_dirty(right);
4303 return ret; 4305 return ret;
@@ -4615,7 +4617,7 @@ void btrfs_truncate_item(struct btrfs_root *root, struct btrfs_path *path,
4615 btrfs_set_disk_key_offset(&disk_key, offset + size_diff); 4617 btrfs_set_disk_key_offset(&disk_key, offset + size_diff);
4616 btrfs_set_item_key(leaf, &disk_key, slot); 4618 btrfs_set_item_key(leaf, &disk_key, slot);
4617 if (slot == 0) 4619 if (slot == 0)
4618 fixup_low_keys(root, path, &disk_key, 1); 4620 fixup_low_keys(root->fs_info, path, &disk_key, 1);
4619 } 4621 }
4620 4622
4621 item = btrfs_item_nr(slot); 4623 item = btrfs_item_nr(slot);
@@ -4716,7 +4718,7 @@ void setup_items_for_insert(struct btrfs_root *root, struct btrfs_path *path,
4716 4718
4717 if (path->slots[0] == 0) { 4719 if (path->slots[0] == 0) {
4718 btrfs_cpu_key_to_disk(&disk_key, cpu_key); 4720 btrfs_cpu_key_to_disk(&disk_key, cpu_key);
4719 fixup_low_keys(root, path, &disk_key, 1); 4721 fixup_low_keys(root->fs_info, path, &disk_key, 1);
4720 } 4722 }
4721 btrfs_unlock_up_safe(path, 1); 4723 btrfs_unlock_up_safe(path, 1);
4722 4724
@@ -4888,7 +4890,7 @@ static void del_ptr(struct btrfs_root *root, struct btrfs_path *path,
4888 struct btrfs_disk_key disk_key; 4890 struct btrfs_disk_key disk_key;
4889 4891
4890 btrfs_node_key(parent, &disk_key, 0); 4892 btrfs_node_key(parent, &disk_key, 0);
4891 fixup_low_keys(root, path, &disk_key, level + 1); 4893 fixup_low_keys(root->fs_info, path, &disk_key, level + 1);
4892 } 4894 }
4893 btrfs_mark_buffer_dirty(parent); 4895 btrfs_mark_buffer_dirty(parent);
4894} 4896}
@@ -4981,7 +4983,7 @@ int btrfs_del_items(struct btrfs_trans_handle *trans, struct btrfs_root *root,
4981 btrfs_set_header_level(leaf, 0); 4983 btrfs_set_header_level(leaf, 0);
4982 } else { 4984 } else {
4983 btrfs_set_path_blocking(path); 4985 btrfs_set_path_blocking(path);
4984 clean_tree_block(trans, root, leaf); 4986 clean_tree_block(trans, root->fs_info, leaf);
4985 btrfs_del_leaf(trans, root, path, leaf); 4987 btrfs_del_leaf(trans, root, path, leaf);
4986 } 4988 }
4987 } else { 4989 } else {
@@ -4990,7 +4992,7 @@ int btrfs_del_items(struct btrfs_trans_handle *trans, struct btrfs_root *root,
4990 struct btrfs_disk_key disk_key; 4992 struct btrfs_disk_key disk_key;
4991 4993
4992 btrfs_item_key(leaf, &disk_key, 0); 4994 btrfs_item_key(leaf, &disk_key, 0);
4993 fixup_low_keys(root, path, &disk_key, 1); 4995 fixup_low_keys(root->fs_info, path, &disk_key, 1);
4994 } 4996 }
4995 4997
4996 /* delete the leaf if it is mostly empty */ 4998 /* delete the leaf if it is mostly empty */
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index f9c89cae39ee..6f364e1d8d3d 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -1061,6 +1061,12 @@ struct btrfs_block_group_item {
1061 __le64 flags; 1061 __le64 flags;
1062} __attribute__ ((__packed__)); 1062} __attribute__ ((__packed__));
1063 1063
1064#define BTRFS_QGROUP_LEVEL_SHIFT 48
1065static inline u64 btrfs_qgroup_level(u64 qgroupid)
1066{
1067 return qgroupid >> BTRFS_QGROUP_LEVEL_SHIFT;
1068}
1069
1064/* 1070/*
1065 * is subvolume quota turned on? 1071 * is subvolume quota turned on?
1066 */ 1072 */
@@ -1256,6 +1262,20 @@ struct btrfs_caching_control {
1256 atomic_t count; 1262 atomic_t count;
1257}; 1263};
1258 1264
1265struct btrfs_io_ctl {
1266 void *cur, *orig;
1267 struct page *page;
1268 struct page **pages;
1269 struct btrfs_root *root;
1270 struct inode *inode;
1271 unsigned long size;
1272 int index;
1273 int num_pages;
1274 int entries;
1275 int bitmaps;
1276 unsigned check_crcs:1;
1277};
1278
1259struct btrfs_block_group_cache { 1279struct btrfs_block_group_cache {
1260 struct btrfs_key key; 1280 struct btrfs_key key;
1261 struct btrfs_block_group_item item; 1281 struct btrfs_block_group_item item;
@@ -1321,6 +1341,9 @@ struct btrfs_block_group_cache {
1321 1341
1322 /* For dirty block groups */ 1342 /* For dirty block groups */
1323 struct list_head dirty_list; 1343 struct list_head dirty_list;
1344 struct list_head io_list;
1345
1346 struct btrfs_io_ctl io_ctl;
1324}; 1347};
1325 1348
1326/* delayed seq elem */ 1349/* delayed seq elem */
@@ -1329,6 +1352,8 @@ struct seq_list {
1329 u64 seq; 1352 u64 seq;
1330}; 1353};
1331 1354
1355#define SEQ_LIST_INIT(name) { .list = LIST_HEAD_INIT((name).list), .seq = 0 }
1356
1332enum btrfs_orphan_cleanup_state { 1357enum btrfs_orphan_cleanup_state {
1333 ORPHAN_CLEANUP_STARTED = 1, 1358 ORPHAN_CLEANUP_STARTED = 1,
1334 ORPHAN_CLEANUP_DONE = 2, 1359 ORPHAN_CLEANUP_DONE = 2,
@@ -1472,6 +1497,12 @@ struct btrfs_fs_info {
1472 struct mutex chunk_mutex; 1497 struct mutex chunk_mutex;
1473 struct mutex volume_mutex; 1498 struct mutex volume_mutex;
1474 1499
1500 /*
1501 * this is taken to make sure we don't set block groups ro after
1502 * the free space cache has been allocated on them
1503 */
1504 struct mutex ro_block_group_mutex;
1505
1475 /* this is used during read/modify/write to make sure 1506 /* this is used during read/modify/write to make sure
1476 * no two ios are trying to mod the same stripe at the same 1507 * no two ios are trying to mod the same stripe at the same
1477 * time 1508 * time
@@ -1513,6 +1544,7 @@ struct btrfs_fs_info {
1513 1544
1514 spinlock_t delayed_iput_lock; 1545 spinlock_t delayed_iput_lock;
1515 struct list_head delayed_iputs; 1546 struct list_head delayed_iputs;
1547 struct rw_semaphore delayed_iput_sem;
1516 1548
1517 /* this protects tree_mod_seq_list */ 1549 /* this protects tree_mod_seq_list */
1518 spinlock_t tree_mod_seq_lock; 1550 spinlock_t tree_mod_seq_lock;
@@ -3295,6 +3327,9 @@ static inline gfp_t btrfs_alloc_write_mask(struct address_space *mapping)
3295} 3327}
3296 3328
3297/* extent-tree.c */ 3329/* extent-tree.c */
3330
3331u64 btrfs_csum_bytes_to_leaves(struct btrfs_root *root, u64 csum_bytes);
3332
3298static inline u64 btrfs_calc_trans_metadata_size(struct btrfs_root *root, 3333static inline u64 btrfs_calc_trans_metadata_size(struct btrfs_root *root,
3299 unsigned num_items) 3334 unsigned num_items)
3300{ 3335{
@@ -3385,6 +3420,8 @@ int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans,
3385 u64 bytenr, u64 num_bytes, u64 parent, 3420 u64 bytenr, u64 num_bytes, u64 parent,
3386 u64 root_objectid, u64 owner, u64 offset, int no_quota); 3421 u64 root_objectid, u64 owner, u64 offset, int no_quota);
3387 3422
3423int btrfs_start_dirty_block_groups(struct btrfs_trans_handle *trans,
3424 struct btrfs_root *root);
3388int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans, 3425int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans,
3389 struct btrfs_root *root); 3426 struct btrfs_root *root);
3390int btrfs_setup_space_cache(struct btrfs_trans_handle *trans, 3427int btrfs_setup_space_cache(struct btrfs_trans_handle *trans,
@@ -3417,7 +3454,7 @@ enum btrfs_reserve_flush_enum {
3417 BTRFS_RESERVE_FLUSH_ALL, 3454 BTRFS_RESERVE_FLUSH_ALL,
3418}; 3455};
3419 3456
3420int btrfs_check_data_free_space(struct inode *inode, u64 bytes); 3457int btrfs_check_data_free_space(struct inode *inode, u64 bytes, u64 write_bytes);
3421void btrfs_free_reserved_data_space(struct inode *inode, u64 bytes); 3458void btrfs_free_reserved_data_space(struct inode *inode, u64 bytes);
3422void btrfs_trans_release_metadata(struct btrfs_trans_handle *trans, 3459void btrfs_trans_release_metadata(struct btrfs_trans_handle *trans,
3423 struct btrfs_root *root); 3460 struct btrfs_root *root);
@@ -3440,6 +3477,7 @@ struct btrfs_block_rsv *btrfs_alloc_block_rsv(struct btrfs_root *root,
3440 unsigned short type); 3477 unsigned short type);
3441void btrfs_free_block_rsv(struct btrfs_root *root, 3478void btrfs_free_block_rsv(struct btrfs_root *root,
3442 struct btrfs_block_rsv *rsv); 3479 struct btrfs_block_rsv *rsv);
3480void __btrfs_free_block_rsv(struct btrfs_block_rsv *rsv);
3443int btrfs_block_rsv_add(struct btrfs_root *root, 3481int btrfs_block_rsv_add(struct btrfs_root *root,
3444 struct btrfs_block_rsv *block_rsv, u64 num_bytes, 3482 struct btrfs_block_rsv *block_rsv, u64 num_bytes,
3445 enum btrfs_reserve_flush_enum flush); 3483 enum btrfs_reserve_flush_enum flush);
@@ -3486,7 +3524,8 @@ int btrfs_previous_item(struct btrfs_root *root,
3486 int type); 3524 int type);
3487int btrfs_previous_extent_item(struct btrfs_root *root, 3525int btrfs_previous_extent_item(struct btrfs_root *root,
3488 struct btrfs_path *path, u64 min_objectid); 3526 struct btrfs_path *path, u64 min_objectid);
3489void btrfs_set_item_key_safe(struct btrfs_root *root, struct btrfs_path *path, 3527void btrfs_set_item_key_safe(struct btrfs_fs_info *fs_info,
3528 struct btrfs_path *path,
3490 struct btrfs_key *new_key); 3529 struct btrfs_key *new_key);
3491struct extent_buffer *btrfs_root_node(struct btrfs_root *root); 3530struct extent_buffer *btrfs_root_node(struct btrfs_root *root);
3492struct extent_buffer *btrfs_lock_root_node(struct btrfs_root *root); 3531struct extent_buffer *btrfs_lock_root_node(struct btrfs_root *root);
@@ -4180,7 +4219,8 @@ int btree_readahead_hook(struct btrfs_root *root, struct extent_buffer *eb,
4180static inline int is_fstree(u64 rootid) 4219static inline int is_fstree(u64 rootid)
4181{ 4220{
4182 if (rootid == BTRFS_FS_TREE_OBJECTID || 4221 if (rootid == BTRFS_FS_TREE_OBJECTID ||
4183 (s64)rootid >= (s64)BTRFS_FIRST_FREE_OBJECTID) 4222 ((s64)rootid >= (s64)BTRFS_FIRST_FREE_OBJECTID &&
4223 !btrfs_qgroup_level(rootid)))
4184 return 1; 4224 return 1;
4185 return 0; 4225 return 0;
4186} 4226}
diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
index 82f0c7c95474..cde698a07d21 100644
--- a/fs/btrfs/delayed-inode.c
+++ b/fs/btrfs/delayed-inode.c
@@ -1383,7 +1383,7 @@ out:
1383 1383
1384 1384
1385static int btrfs_wq_run_delayed_node(struct btrfs_delayed_root *delayed_root, 1385static int btrfs_wq_run_delayed_node(struct btrfs_delayed_root *delayed_root,
1386 struct btrfs_root *root, int nr) 1386 struct btrfs_fs_info *fs_info, int nr)
1387{ 1387{
1388 struct btrfs_async_delayed_work *async_work; 1388 struct btrfs_async_delayed_work *async_work;
1389 1389
@@ -1399,7 +1399,7 @@ static int btrfs_wq_run_delayed_node(struct btrfs_delayed_root *delayed_root,
1399 btrfs_async_run_delayed_root, NULL, NULL); 1399 btrfs_async_run_delayed_root, NULL, NULL);
1400 async_work->nr = nr; 1400 async_work->nr = nr;
1401 1401
1402 btrfs_queue_work(root->fs_info->delayed_workers, &async_work->work); 1402 btrfs_queue_work(fs_info->delayed_workers, &async_work->work);
1403 return 0; 1403 return 0;
1404} 1404}
1405 1405
@@ -1426,6 +1426,7 @@ static int could_end_wait(struct btrfs_delayed_root *delayed_root, int seq)
1426void btrfs_balance_delayed_items(struct btrfs_root *root) 1426void btrfs_balance_delayed_items(struct btrfs_root *root)
1427{ 1427{
1428 struct btrfs_delayed_root *delayed_root; 1428 struct btrfs_delayed_root *delayed_root;
1429 struct btrfs_fs_info *fs_info = root->fs_info;
1429 1430
1430 delayed_root = btrfs_get_delayed_root(root); 1431 delayed_root = btrfs_get_delayed_root(root);
1431 1432
@@ -1438,7 +1439,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
1438 1439
1439 seq = atomic_read(&delayed_root->items_seq); 1440 seq = atomic_read(&delayed_root->items_seq);
1440 1441
1441 ret = btrfs_wq_run_delayed_node(delayed_root, root, 0); 1442 ret = btrfs_wq_run_delayed_node(delayed_root, fs_info, 0);
1442 if (ret) 1443 if (ret)
1443 return; 1444 return;
1444 1445
@@ -1447,7 +1448,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
1447 return; 1448 return;
1448 } 1449 }
1449 1450
1450 btrfs_wq_run_delayed_node(delayed_root, root, BTRFS_DELAYED_BATCH); 1451 btrfs_wq_run_delayed_node(delayed_root, fs_info, BTRFS_DELAYED_BATCH);
1451} 1452}
1452 1453
1453/* Will return 0 or -ENOMEM */ 1454/* Will return 0 or -ENOMEM */
diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c
index 6d16bea94e1c..8f8ed7d20bac 100644
--- a/fs/btrfs/delayed-ref.c
+++ b/fs/btrfs/delayed-ref.c
@@ -489,11 +489,13 @@ update_existing_ref(struct btrfs_trans_handle *trans,
489 * existing and update must have the same bytenr 489 * existing and update must have the same bytenr
490 */ 490 */
491static noinline void 491static noinline void
492update_existing_head_ref(struct btrfs_delayed_ref_node *existing, 492update_existing_head_ref(struct btrfs_delayed_ref_root *delayed_refs,
493 struct btrfs_delayed_ref_node *existing,
493 struct btrfs_delayed_ref_node *update) 494 struct btrfs_delayed_ref_node *update)
494{ 495{
495 struct btrfs_delayed_ref_head *existing_ref; 496 struct btrfs_delayed_ref_head *existing_ref;
496 struct btrfs_delayed_ref_head *ref; 497 struct btrfs_delayed_ref_head *ref;
498 int old_ref_mod;
497 499
498 existing_ref = btrfs_delayed_node_to_head(existing); 500 existing_ref = btrfs_delayed_node_to_head(existing);
499 ref = btrfs_delayed_node_to_head(update); 501 ref = btrfs_delayed_node_to_head(update);
@@ -541,7 +543,20 @@ update_existing_head_ref(struct btrfs_delayed_ref_node *existing,
541 * only need the lock for this case cause we could be processing it 543 * only need the lock for this case cause we could be processing it
542 * currently, for refs we just added we know we're a-ok. 544 * currently, for refs we just added we know we're a-ok.
543 */ 545 */
546 old_ref_mod = existing_ref->total_ref_mod;
544 existing->ref_mod += update->ref_mod; 547 existing->ref_mod += update->ref_mod;
548 existing_ref->total_ref_mod += update->ref_mod;
549
550 /*
551 * If we are going to from a positive ref mod to a negative or vice
552 * versa we need to make sure to adjust pending_csums accordingly.
553 */
554 if (existing_ref->is_data) {
555 if (existing_ref->total_ref_mod >= 0 && old_ref_mod < 0)
556 delayed_refs->pending_csums -= existing->num_bytes;
557 if (existing_ref->total_ref_mod < 0 && old_ref_mod >= 0)
558 delayed_refs->pending_csums += existing->num_bytes;
559 }
545 spin_unlock(&existing_ref->lock); 560 spin_unlock(&existing_ref->lock);
546} 561}
547 562
@@ -605,6 +620,7 @@ add_delayed_ref_head(struct btrfs_fs_info *fs_info,
605 head_ref->is_data = is_data; 620 head_ref->is_data = is_data;
606 head_ref->ref_root = RB_ROOT; 621 head_ref->ref_root = RB_ROOT;
607 head_ref->processing = 0; 622 head_ref->processing = 0;
623 head_ref->total_ref_mod = count_mod;
608 624
609 spin_lock_init(&head_ref->lock); 625 spin_lock_init(&head_ref->lock);
610 mutex_init(&head_ref->mutex); 626 mutex_init(&head_ref->mutex);
@@ -614,7 +630,7 @@ add_delayed_ref_head(struct btrfs_fs_info *fs_info,
614 existing = htree_insert(&delayed_refs->href_root, 630 existing = htree_insert(&delayed_refs->href_root,
615 &head_ref->href_node); 631 &head_ref->href_node);
616 if (existing) { 632 if (existing) {
617 update_existing_head_ref(&existing->node, ref); 633 update_existing_head_ref(delayed_refs, &existing->node, ref);
618 /* 634 /*
619 * we've updated the existing ref, free the newly 635 * we've updated the existing ref, free the newly
620 * allocated ref 636 * allocated ref
@@ -622,6 +638,8 @@ add_delayed_ref_head(struct btrfs_fs_info *fs_info,
622 kmem_cache_free(btrfs_delayed_ref_head_cachep, head_ref); 638 kmem_cache_free(btrfs_delayed_ref_head_cachep, head_ref);
623 head_ref = existing; 639 head_ref = existing;
624 } else { 640 } else {
641 if (is_data && count_mod < 0)
642 delayed_refs->pending_csums += num_bytes;
625 delayed_refs->num_heads++; 643 delayed_refs->num_heads++;
626 delayed_refs->num_heads_ready++; 644 delayed_refs->num_heads_ready++;
627 atomic_inc(&delayed_refs->num_entries); 645 atomic_inc(&delayed_refs->num_entries);
diff --git a/fs/btrfs/delayed-ref.h b/fs/btrfs/delayed-ref.h
index a764e2340d48..5eb0892396d0 100644
--- a/fs/btrfs/delayed-ref.h
+++ b/fs/btrfs/delayed-ref.h
@@ -88,6 +88,14 @@ struct btrfs_delayed_ref_head {
88 struct rb_node href_node; 88 struct rb_node href_node;
89 89
90 struct btrfs_delayed_extent_op *extent_op; 90 struct btrfs_delayed_extent_op *extent_op;
91
92 /*
93 * This is used to track the final ref_mod from all the refs associated
94 * with this head ref, this is not adjusted as delayed refs are run,
95 * this is meant to track if we need to do the csum accounting or not.
96 */
97 int total_ref_mod;
98
91 /* 99 /*
92 * when a new extent is allocated, it is just reserved in memory 100 * when a new extent is allocated, it is just reserved in memory
93 * The actual extent isn't inserted into the extent allocation tree 101 * The actual extent isn't inserted into the extent allocation tree
@@ -138,6 +146,8 @@ struct btrfs_delayed_ref_root {
138 /* total number of head nodes ready for processing */ 146 /* total number of head nodes ready for processing */
139 unsigned long num_heads_ready; 147 unsigned long num_heads_ready;
140 148
149 u64 pending_csums;
150
141 /* 151 /*
142 * set when the tree is flushing before a transaction commit, 152 * set when the tree is flushing before a transaction commit,
143 * used by the throttling code to decide if new updates need 153 * used by the throttling code to decide if new updates need
diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c
index 5ec03d999c37..0573848c7333 100644
--- a/fs/btrfs/dev-replace.c
+++ b/fs/btrfs/dev-replace.c
@@ -670,8 +670,8 @@ void btrfs_dev_replace_status(struct btrfs_fs_info *fs_info,
670 case BTRFS_IOCTL_DEV_REPLACE_STATE_STARTED: 670 case BTRFS_IOCTL_DEV_REPLACE_STATE_STARTED:
671 case BTRFS_IOCTL_DEV_REPLACE_STATE_SUSPENDED: 671 case BTRFS_IOCTL_DEV_REPLACE_STATE_SUSPENDED:
672 srcdev = dev_replace->srcdev; 672 srcdev = dev_replace->srcdev;
673 args->status.progress_1000 = div64_u64(dev_replace->cursor_left, 673 args->status.progress_1000 = div_u64(dev_replace->cursor_left,
674 div64_u64(btrfs_device_get_total_bytes(srcdev), 1000)); 674 div_u64(btrfs_device_get_total_bytes(srcdev), 1000));
675 break; 675 break;
676 } 676 }
677 btrfs_dev_replace_unlock(dev_replace); 677 btrfs_dev_replace_unlock(dev_replace);
@@ -806,7 +806,7 @@ static int btrfs_dev_replace_kthread(void *data)
806 btrfs_dev_replace_status(fs_info, status_args); 806 btrfs_dev_replace_status(fs_info, status_args);
807 progress = status_args->status.progress_1000; 807 progress = status_args->status.progress_1000;
808 kfree(status_args); 808 kfree(status_args);
809 do_div(progress, 10); 809 progress = div_u64(progress, 10);
810 printk_in_rcu(KERN_INFO 810 printk_in_rcu(KERN_INFO
811 "BTRFS: continuing dev_replace from %s (devid %llu) to %s @%u%%\n", 811 "BTRFS: continuing dev_replace from %s (devid %llu) to %s @%u%%\n",
812 dev_replace->srcdev->missing ? "<missing disk>" : 812 dev_replace->srcdev->missing ? "<missing disk>" :
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 639f2663ed3f..2ef9a4b72d06 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -54,7 +54,7 @@
54#include <asm/cpufeature.h> 54#include <asm/cpufeature.h>
55#endif 55#endif
56 56
57static struct extent_io_ops btree_extent_io_ops; 57static const struct extent_io_ops btree_extent_io_ops;
58static void end_workqueue_fn(struct btrfs_work *work); 58static void end_workqueue_fn(struct btrfs_work *work);
59static void free_fs_root(struct btrfs_root *root); 59static void free_fs_root(struct btrfs_root *root);
60static int btrfs_check_super_valid(struct btrfs_fs_info *fs_info, 60static int btrfs_check_super_valid(struct btrfs_fs_info *fs_info,
@@ -274,10 +274,11 @@ void btrfs_csum_final(u32 crc, char *result)
274 * compute the csum for a btree block, and either verify it or write it 274 * compute the csum for a btree block, and either verify it or write it
275 * into the csum field of the block. 275 * into the csum field of the block.
276 */ 276 */
277static int csum_tree_block(struct btrfs_root *root, struct extent_buffer *buf, 277static int csum_tree_block(struct btrfs_fs_info *fs_info,
278 struct extent_buffer *buf,
278 int verify) 279 int verify)
279{ 280{
280 u16 csum_size = btrfs_super_csum_size(root->fs_info->super_copy); 281 u16 csum_size = btrfs_super_csum_size(fs_info->super_copy);
281 char *result = NULL; 282 char *result = NULL;
282 unsigned long len; 283 unsigned long len;
283 unsigned long cur_len; 284 unsigned long cur_len;
@@ -302,7 +303,7 @@ static int csum_tree_block(struct btrfs_root *root, struct extent_buffer *buf,
302 offset += cur_len; 303 offset += cur_len;
303 } 304 }
304 if (csum_size > sizeof(inline_result)) { 305 if (csum_size > sizeof(inline_result)) {
305 result = kzalloc(csum_size * sizeof(char), GFP_NOFS); 306 result = kzalloc(csum_size, GFP_NOFS);
306 if (!result) 307 if (!result)
307 return 1; 308 return 1;
308 } else { 309 } else {
@@ -321,7 +322,7 @@ static int csum_tree_block(struct btrfs_root *root, struct extent_buffer *buf,
321 printk_ratelimited(KERN_WARNING 322 printk_ratelimited(KERN_WARNING
322 "BTRFS: %s checksum verify failed on %llu wanted %X found %X " 323 "BTRFS: %s checksum verify failed on %llu wanted %X found %X "
323 "level %d\n", 324 "level %d\n",
324 root->fs_info->sb->s_id, buf->start, 325 fs_info->sb->s_id, buf->start,
325 val, found, btrfs_header_level(buf)); 326 val, found, btrfs_header_level(buf));
326 if (result != (char *)&inline_result) 327 if (result != (char *)&inline_result)
327 kfree(result); 328 kfree(result);
@@ -418,12 +419,6 @@ static int btrfs_check_super_csum(char *raw_disk_sb)
418 419
419 if (memcmp(raw_disk_sb, result, csum_size)) 420 if (memcmp(raw_disk_sb, result, csum_size))
420 ret = 1; 421 ret = 1;
421
422 if (ret && btrfs_super_generation(disk_sb) < 10) {
423 printk(KERN_WARNING
424 "BTRFS: super block crcs don't match, older mkfs detected\n");
425 ret = 0;
426 }
427 } 422 }
428 423
429 if (csum_type >= ARRAY_SIZE(btrfs_csum_sizes)) { 424 if (csum_type >= ARRAY_SIZE(btrfs_csum_sizes)) {
@@ -501,7 +496,7 @@ static int btree_read_extent_buffer_pages(struct btrfs_root *root,
501 * we only fill in the checksum field in the first page of a multi-page block 496 * we only fill in the checksum field in the first page of a multi-page block
502 */ 497 */
503 498
504static int csum_dirty_buffer(struct btrfs_root *root, struct page *page) 499static int csum_dirty_buffer(struct btrfs_fs_info *fs_info, struct page *page)
505{ 500{
506 u64 start = page_offset(page); 501 u64 start = page_offset(page);
507 u64 found_start; 502 u64 found_start;
@@ -513,14 +508,14 @@ static int csum_dirty_buffer(struct btrfs_root *root, struct page *page)
513 found_start = btrfs_header_bytenr(eb); 508 found_start = btrfs_header_bytenr(eb);
514 if (WARN_ON(found_start != start || !PageUptodate(page))) 509 if (WARN_ON(found_start != start || !PageUptodate(page)))
515 return 0; 510 return 0;
516 csum_tree_block(root, eb, 0); 511 csum_tree_block(fs_info, eb, 0);
517 return 0; 512 return 0;
518} 513}
519 514
520static int check_tree_block_fsid(struct btrfs_root *root, 515static int check_tree_block_fsid(struct btrfs_fs_info *fs_info,
521 struct extent_buffer *eb) 516 struct extent_buffer *eb)
522{ 517{
523 struct btrfs_fs_devices *fs_devices = root->fs_info->fs_devices; 518 struct btrfs_fs_devices *fs_devices = fs_info->fs_devices;
524 u8 fsid[BTRFS_UUID_SIZE]; 519 u8 fsid[BTRFS_UUID_SIZE];
525 int ret = 1; 520 int ret = 1;
526 521
@@ -640,7 +635,7 @@ static int btree_readpage_end_io_hook(struct btrfs_io_bio *io_bio,
640 ret = -EIO; 635 ret = -EIO;
641 goto err; 636 goto err;
642 } 637 }
643 if (check_tree_block_fsid(root, eb)) { 638 if (check_tree_block_fsid(root->fs_info, eb)) {
644 printk_ratelimited(KERN_ERR "BTRFS (device %s): bad fsid on block %llu\n", 639 printk_ratelimited(KERN_ERR "BTRFS (device %s): bad fsid on block %llu\n",
645 eb->fs_info->sb->s_id, eb->start); 640 eb->fs_info->sb->s_id, eb->start);
646 ret = -EIO; 641 ret = -EIO;
@@ -657,7 +652,7 @@ static int btree_readpage_end_io_hook(struct btrfs_io_bio *io_bio,
657 btrfs_set_buffer_lockdep_class(btrfs_header_owner(eb), 652 btrfs_set_buffer_lockdep_class(btrfs_header_owner(eb),
658 eb, found_level); 653 eb, found_level);
659 654
660 ret = csum_tree_block(root, eb, 1); 655 ret = csum_tree_block(root->fs_info, eb, 1);
661 if (ret) { 656 if (ret) {
662 ret = -EIO; 657 ret = -EIO;
663 goto err; 658 goto err;
@@ -882,7 +877,7 @@ static int btree_csum_one_bio(struct bio *bio)
882 877
883 bio_for_each_segment_all(bvec, bio, i) { 878 bio_for_each_segment_all(bvec, bio, i) {
884 root = BTRFS_I(bvec->bv_page->mapping->host)->root; 879 root = BTRFS_I(bvec->bv_page->mapping->host)->root;
885 ret = csum_dirty_buffer(root, bvec->bv_page); 880 ret = csum_dirty_buffer(root->fs_info, bvec->bv_page);
886 if (ret) 881 if (ret)
887 break; 882 break;
888 } 883 }
@@ -1119,10 +1114,10 @@ int reada_tree_block_flagged(struct btrfs_root *root, u64 bytenr,
1119 return 0; 1114 return 0;
1120} 1115}
1121 1116
1122struct extent_buffer *btrfs_find_tree_block(struct btrfs_root *root, 1117struct extent_buffer *btrfs_find_tree_block(struct btrfs_fs_info *fs_info,
1123 u64 bytenr) 1118 u64 bytenr)
1124{ 1119{
1125 return find_extent_buffer(root->fs_info, bytenr); 1120 return find_extent_buffer(fs_info, bytenr);
1126} 1121}
1127 1122
1128struct extent_buffer *btrfs_find_create_tree_block(struct btrfs_root *root, 1123struct extent_buffer *btrfs_find_create_tree_block(struct btrfs_root *root,
@@ -1165,11 +1160,10 @@ struct extent_buffer *read_tree_block(struct btrfs_root *root, u64 bytenr,
1165 1160
1166} 1161}
1167 1162
1168void clean_tree_block(struct btrfs_trans_handle *trans, struct btrfs_root *root, 1163void clean_tree_block(struct btrfs_trans_handle *trans,
1164 struct btrfs_fs_info *fs_info,
1169 struct extent_buffer *buf) 1165 struct extent_buffer *buf)
1170{ 1166{
1171 struct btrfs_fs_info *fs_info = root->fs_info;
1172
1173 if (btrfs_header_generation(buf) == 1167 if (btrfs_header_generation(buf) ==
1174 fs_info->running_transaction->transid) { 1168 fs_info->running_transaction->transid) {
1175 btrfs_assert_tree_locked(buf); 1169 btrfs_assert_tree_locked(buf);
@@ -2146,6 +2140,267 @@ void btrfs_free_fs_roots(struct btrfs_fs_info *fs_info)
2146 } 2140 }
2147} 2141}
2148 2142
2143static void btrfs_init_scrub(struct btrfs_fs_info *fs_info)
2144{
2145 mutex_init(&fs_info->scrub_lock);
2146 atomic_set(&fs_info->scrubs_running, 0);
2147 atomic_set(&fs_info->scrub_pause_req, 0);
2148 atomic_set(&fs_info->scrubs_paused, 0);
2149 atomic_set(&fs_info->scrub_cancel_req, 0);
2150 init_waitqueue_head(&fs_info->scrub_pause_wait);
2151 fs_info->scrub_workers_refcnt = 0;
2152}
2153
2154static void btrfs_init_balance(struct btrfs_fs_info *fs_info)
2155{
2156 spin_lock_init(&fs_info->balance_lock);
2157 mutex_init(&fs_info->balance_mutex);
2158 atomic_set(&fs_info->balance_running, 0);
2159 atomic_set(&fs_info->balance_pause_req, 0);
2160 atomic_set(&fs_info->balance_cancel_req, 0);
2161 fs_info->balance_ctl = NULL;
2162 init_waitqueue_head(&fs_info->balance_wait_q);
2163}
2164
2165static void btrfs_init_btree_inode(struct btrfs_fs_info *fs_info,
2166 struct btrfs_root *tree_root)
2167{
2168 fs_info->btree_inode->i_ino = BTRFS_BTREE_INODE_OBJECTID;
2169 set_nlink(fs_info->btree_inode, 1);
2170 /*
2171 * we set the i_size on the btree inode to the max possible int.
2172 * the real end of the address space is determined by all of
2173 * the devices in the system
2174 */
2175 fs_info->btree_inode->i_size = OFFSET_MAX;
2176 fs_info->btree_inode->i_mapping->a_ops = &btree_aops;
2177
2178 RB_CLEAR_NODE(&BTRFS_I(fs_info->btree_inode)->rb_node);
2179 extent_io_tree_init(&BTRFS_I(fs_info->btree_inode)->io_tree,
2180 fs_info->btree_inode->i_mapping);
2181 BTRFS_I(fs_info->btree_inode)->io_tree.track_uptodate = 0;
2182 extent_map_tree_init(&BTRFS_I(fs_info->btree_inode)->extent_tree);
2183
2184 BTRFS_I(fs_info->btree_inode)->io_tree.ops = &btree_extent_io_ops;
2185
2186 BTRFS_I(fs_info->btree_inode)->root = tree_root;
2187 memset(&BTRFS_I(fs_info->btree_inode)->location, 0,
2188 sizeof(struct btrfs_key));
2189 set_bit(BTRFS_INODE_DUMMY,
2190 &BTRFS_I(fs_info->btree_inode)->runtime_flags);
2191 btrfs_insert_inode_hash(fs_info->btree_inode);
2192}
2193
2194static void btrfs_init_dev_replace_locks(struct btrfs_fs_info *fs_info)
2195{
2196 fs_info->dev_replace.lock_owner = 0;
2197 atomic_set(&fs_info->dev_replace.nesting_level, 0);
2198 mutex_init(&fs_info->dev_replace.lock_finishing_cancel_unmount);
2199 mutex_init(&fs_info->dev_replace.lock_management_lock);
2200 mutex_init(&fs_info->dev_replace.lock);
2201 init_waitqueue_head(&fs_info->replace_wait);
2202}
2203
2204static void btrfs_init_qgroup(struct btrfs_fs_info *fs_info)
2205{
2206 spin_lock_init(&fs_info->qgroup_lock);
2207 mutex_init(&fs_info->qgroup_ioctl_lock);
2208 fs_info->qgroup_tree = RB_ROOT;
2209 fs_info->qgroup_op_tree = RB_ROOT;
2210 INIT_LIST_HEAD(&fs_info->dirty_qgroups);
2211 fs_info->qgroup_seq = 1;
2212 fs_info->quota_enabled = 0;
2213 fs_info->pending_quota_state = 0;
2214 fs_info->qgroup_ulist = NULL;
2215 mutex_init(&fs_info->qgroup_rescan_lock);
2216}
2217
2218static int btrfs_init_workqueues(struct btrfs_fs_info *fs_info,
2219 struct btrfs_fs_devices *fs_devices)
2220{
2221 int max_active = fs_info->thread_pool_size;
2222 unsigned int flags = WQ_MEM_RECLAIM | WQ_FREEZABLE | WQ_UNBOUND;
2223
2224 fs_info->workers =
2225 btrfs_alloc_workqueue("worker", flags | WQ_HIGHPRI,
2226 max_active, 16);
2227
2228 fs_info->delalloc_workers =
2229 btrfs_alloc_workqueue("delalloc", flags, max_active, 2);
2230
2231 fs_info->flush_workers =
2232 btrfs_alloc_workqueue("flush_delalloc", flags, max_active, 0);
2233
2234 fs_info->caching_workers =
2235 btrfs_alloc_workqueue("cache", flags, max_active, 0);
2236
2237 /*
2238 * a higher idle thresh on the submit workers makes it much more
2239 * likely that bios will be send down in a sane order to the
2240 * devices
2241 */
2242 fs_info->submit_workers =
2243 btrfs_alloc_workqueue("submit", flags,
2244 min_t(u64, fs_devices->num_devices,
2245 max_active), 64);
2246
2247 fs_info->fixup_workers =
2248 btrfs_alloc_workqueue("fixup", flags, 1, 0);
2249
2250 /*
2251 * endios are largely parallel and should have a very
2252 * low idle thresh
2253 */
2254 fs_info->endio_workers =
2255 btrfs_alloc_workqueue("endio", flags, max_active, 4);
2256 fs_info->endio_meta_workers =
2257 btrfs_alloc_workqueue("endio-meta", flags, max_active, 4);
2258 fs_info->endio_meta_write_workers =
2259 btrfs_alloc_workqueue("endio-meta-write", flags, max_active, 2);
2260 fs_info->endio_raid56_workers =
2261 btrfs_alloc_workqueue("endio-raid56", flags, max_active, 4);
2262 fs_info->endio_repair_workers =
2263 btrfs_alloc_workqueue("endio-repair", flags, 1, 0);
2264 fs_info->rmw_workers =
2265 btrfs_alloc_workqueue("rmw", flags, max_active, 2);
2266 fs_info->endio_write_workers =
2267 btrfs_alloc_workqueue("endio-write", flags, max_active, 2);
2268 fs_info->endio_freespace_worker =
2269 btrfs_alloc_workqueue("freespace-write", flags, max_active, 0);
2270 fs_info->delayed_workers =
2271 btrfs_alloc_workqueue("delayed-meta", flags, max_active, 0);
2272 fs_info->readahead_workers =
2273 btrfs_alloc_workqueue("readahead", flags, max_active, 2);
2274 fs_info->qgroup_rescan_workers =
2275 btrfs_alloc_workqueue("qgroup-rescan", flags, 1, 0);
2276 fs_info->extent_workers =
2277 btrfs_alloc_workqueue("extent-refs", flags,
2278 min_t(u64, fs_devices->num_devices,
2279 max_active), 8);
2280
2281 if (!(fs_info->workers && fs_info->delalloc_workers &&
2282 fs_info->submit_workers && fs_info->flush_workers &&
2283 fs_info->endio_workers && fs_info->endio_meta_workers &&
2284 fs_info->endio_meta_write_workers &&
2285 fs_info->endio_repair_workers &&
2286 fs_info->endio_write_workers && fs_info->endio_raid56_workers &&
2287 fs_info->endio_freespace_worker && fs_info->rmw_workers &&
2288 fs_info->caching_workers && fs_info->readahead_workers &&
2289 fs_info->fixup_workers && fs_info->delayed_workers &&
2290 fs_info->extent_workers &&
2291 fs_info->qgroup_rescan_workers)) {
2292 return -ENOMEM;
2293 }
2294
2295 return 0;
2296}
2297
2298static int btrfs_replay_log(struct btrfs_fs_info *fs_info,
2299 struct btrfs_fs_devices *fs_devices)
2300{
2301 int ret;
2302 struct btrfs_root *tree_root = fs_info->tree_root;
2303 struct btrfs_root *log_tree_root;
2304 struct btrfs_super_block *disk_super = fs_info->super_copy;
2305 u64 bytenr = btrfs_super_log_root(disk_super);
2306
2307 if (fs_devices->rw_devices == 0) {
2308 printk(KERN_WARNING "BTRFS: log replay required "
2309 "on RO media\n");
2310 return -EIO;
2311 }
2312
2313 log_tree_root = btrfs_alloc_root(fs_info);
2314 if (!log_tree_root)
2315 return -ENOMEM;
2316
2317 __setup_root(tree_root->nodesize, tree_root->sectorsize,
2318 tree_root->stripesize, log_tree_root, fs_info,
2319 BTRFS_TREE_LOG_OBJECTID);
2320
2321 log_tree_root->node = read_tree_block(tree_root, bytenr,
2322 fs_info->generation + 1);
2323 if (!log_tree_root->node ||
2324 !extent_buffer_uptodate(log_tree_root->node)) {
2325 printk(KERN_ERR "BTRFS: failed to read log tree\n");
2326 free_extent_buffer(log_tree_root->node);
2327 kfree(log_tree_root);
2328 return -EIO;
2329 }
2330 /* returns with log_tree_root freed on success */
2331 ret = btrfs_recover_log_trees(log_tree_root);
2332 if (ret) {
2333 btrfs_error(tree_root->fs_info, ret,
2334 "Failed to recover log tree");
2335 free_extent_buffer(log_tree_root->node);
2336 kfree(log_tree_root);
2337 return ret;
2338 }
2339
2340 if (fs_info->sb->s_flags & MS_RDONLY) {
2341 ret = btrfs_commit_super(tree_root);
2342 if (ret)
2343 return ret;
2344 }
2345
2346 return 0;
2347}
2348
2349static int btrfs_read_roots(struct btrfs_fs_info *fs_info,
2350 struct btrfs_root *tree_root)
2351{
2352 struct btrfs_root *root;
2353 struct btrfs_key location;
2354 int ret;
2355
2356 location.objectid = BTRFS_EXTENT_TREE_OBJECTID;
2357 location.type = BTRFS_ROOT_ITEM_KEY;
2358 location.offset = 0;
2359
2360 root = btrfs_read_tree_root(tree_root, &location);
2361 if (IS_ERR(root))
2362 return PTR_ERR(root);
2363 set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state);
2364 fs_info->extent_root = root;
2365
2366 location.objectid = BTRFS_DEV_TREE_OBJECTID;
2367 root = btrfs_read_tree_root(tree_root, &location);
2368 if (IS_ERR(root))
2369 return PTR_ERR(root);
2370 set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state);
2371 fs_info->dev_root = root;
2372 btrfs_init_devices_late(fs_info);
2373
2374 location.objectid = BTRFS_CSUM_TREE_OBJECTID;
2375 root = btrfs_read_tree_root(tree_root, &location);
2376 if (IS_ERR(root))
2377 return PTR_ERR(root);
2378 set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state);
2379 fs_info->csum_root = root;
2380
2381 location.objectid = BTRFS_QUOTA_TREE_OBJECTID;
2382 root = btrfs_read_tree_root(tree_root, &location);
2383 if (!IS_ERR(root)) {
2384 set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state);
2385 fs_info->quota_enabled = 1;
2386 fs_info->pending_quota_state = 1;
2387 fs_info->quota_root = root;
2388 }
2389
2390 location.objectid = BTRFS_UUID_TREE_OBJECTID;
2391 root = btrfs_read_tree_root(tree_root, &location);
2392 if (IS_ERR(root)) {
2393 ret = PTR_ERR(root);
2394 if (ret != -ENOENT)
2395 return ret;
2396 } else {
2397 set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state);
2398 fs_info->uuid_root = root;
2399 }
2400
2401 return 0;
2402}
2403
2149int open_ctree(struct super_block *sb, 2404int open_ctree(struct super_block *sb,
2150 struct btrfs_fs_devices *fs_devices, 2405 struct btrfs_fs_devices *fs_devices,
2151 char *options) 2406 char *options)
@@ -2160,21 +2415,12 @@ int open_ctree(struct super_block *sb,
2160 struct btrfs_super_block *disk_super; 2415 struct btrfs_super_block *disk_super;
2161 struct btrfs_fs_info *fs_info = btrfs_sb(sb); 2416 struct btrfs_fs_info *fs_info = btrfs_sb(sb);
2162 struct btrfs_root *tree_root; 2417 struct btrfs_root *tree_root;
2163 struct btrfs_root *extent_root;
2164 struct btrfs_root *csum_root;
2165 struct btrfs_root *chunk_root; 2418 struct btrfs_root *chunk_root;
2166 struct btrfs_root *dev_root;
2167 struct btrfs_root *quota_root;
2168 struct btrfs_root *uuid_root;
2169 struct btrfs_root *log_tree_root;
2170 int ret; 2419 int ret;
2171 int err = -EINVAL; 2420 int err = -EINVAL;
2172 int num_backups_tried = 0; 2421 int num_backups_tried = 0;
2173 int backup_index = 0; 2422 int backup_index = 0;
2174 int max_active; 2423 int max_active;
2175 int flags = WQ_MEM_RECLAIM | WQ_FREEZABLE | WQ_UNBOUND;
2176 bool create_uuid_tree;
2177 bool check_uuid_tree;
2178 2424
2179 tree_root = fs_info->tree_root = btrfs_alloc_root(fs_info); 2425 tree_root = fs_info->tree_root = btrfs_alloc_root(fs_info);
2180 chunk_root = fs_info->chunk_root = btrfs_alloc_root(fs_info); 2426 chunk_root = fs_info->chunk_root = btrfs_alloc_root(fs_info);
@@ -2241,11 +2487,12 @@ int open_ctree(struct super_block *sb,
2241 spin_lock_init(&fs_info->qgroup_op_lock); 2487 spin_lock_init(&fs_info->qgroup_op_lock);
2242 spin_lock_init(&fs_info->buffer_lock); 2488 spin_lock_init(&fs_info->buffer_lock);
2243 spin_lock_init(&fs_info->unused_bgs_lock); 2489 spin_lock_init(&fs_info->unused_bgs_lock);
2244 mutex_init(&fs_info->unused_bg_unpin_mutex);
2245 rwlock_init(&fs_info->tree_mod_log_lock); 2490 rwlock_init(&fs_info->tree_mod_log_lock);
2491 mutex_init(&fs_info->unused_bg_unpin_mutex);
2246 mutex_init(&fs_info->reloc_mutex); 2492 mutex_init(&fs_info->reloc_mutex);
2247 mutex_init(&fs_info->delalloc_root_mutex); 2493 mutex_init(&fs_info->delalloc_root_mutex);
2248 seqlock_init(&fs_info->profiles_lock); 2494 seqlock_init(&fs_info->profiles_lock);
2495 init_rwsem(&fs_info->delayed_iput_sem);
2249 2496
2250 init_completion(&fs_info->kobj_unregister); 2497 init_completion(&fs_info->kobj_unregister);
2251 INIT_LIST_HEAD(&fs_info->dirty_cowonly_roots); 2498 INIT_LIST_HEAD(&fs_info->dirty_cowonly_roots);
@@ -2276,7 +2523,7 @@ int open_ctree(struct super_block *sb,
2276 fs_info->free_chunk_space = 0; 2523 fs_info->free_chunk_space = 0;
2277 fs_info->tree_mod_log = RB_ROOT; 2524 fs_info->tree_mod_log = RB_ROOT;
2278 fs_info->commit_interval = BTRFS_DEFAULT_COMMIT_INTERVAL; 2525 fs_info->commit_interval = BTRFS_DEFAULT_COMMIT_INTERVAL;
2279 fs_info->avg_delayed_ref_runtime = div64_u64(NSEC_PER_SEC, 64); 2526 fs_info->avg_delayed_ref_runtime = NSEC_PER_SEC >> 6; /* div by 64 */
2280 /* readahead state */ 2527 /* readahead state */
2281 INIT_RADIX_TREE(&fs_info->reada_tree, GFP_NOFS & ~__GFP_WAIT); 2528 INIT_RADIX_TREE(&fs_info->reada_tree, GFP_NOFS & ~__GFP_WAIT);
2282 spin_lock_init(&fs_info->reada_lock); 2529 spin_lock_init(&fs_info->reada_lock);
@@ -2294,55 +2541,18 @@ int open_ctree(struct super_block *sb,
2294 } 2541 }
2295 btrfs_init_delayed_root(fs_info->delayed_root); 2542 btrfs_init_delayed_root(fs_info->delayed_root);
2296 2543
2297 mutex_init(&fs_info->scrub_lock); 2544 btrfs_init_scrub(fs_info);
2298 atomic_set(&fs_info->scrubs_running, 0);
2299 atomic_set(&fs_info->scrub_pause_req, 0);
2300 atomic_set(&fs_info->scrubs_paused, 0);
2301 atomic_set(&fs_info->scrub_cancel_req, 0);
2302 init_waitqueue_head(&fs_info->replace_wait);
2303 init_waitqueue_head(&fs_info->scrub_pause_wait);
2304 fs_info->scrub_workers_refcnt = 0;
2305#ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY 2545#ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY
2306 fs_info->check_integrity_print_mask = 0; 2546 fs_info->check_integrity_print_mask = 0;
2307#endif 2547#endif
2308 2548 btrfs_init_balance(fs_info);
2309 spin_lock_init(&fs_info->balance_lock);
2310 mutex_init(&fs_info->balance_mutex);
2311 atomic_set(&fs_info->balance_running, 0);
2312 atomic_set(&fs_info->balance_pause_req, 0);
2313 atomic_set(&fs_info->balance_cancel_req, 0);
2314 fs_info->balance_ctl = NULL;
2315 init_waitqueue_head(&fs_info->balance_wait_q);
2316 btrfs_init_async_reclaim_work(&fs_info->async_reclaim_work); 2549 btrfs_init_async_reclaim_work(&fs_info->async_reclaim_work);
2317 2550
2318 sb->s_blocksize = 4096; 2551 sb->s_blocksize = 4096;
2319 sb->s_blocksize_bits = blksize_bits(4096); 2552 sb->s_blocksize_bits = blksize_bits(4096);
2320 sb->s_bdi = &fs_info->bdi; 2553 sb->s_bdi = &fs_info->bdi;
2321 2554
2322 fs_info->btree_inode->i_ino = BTRFS_BTREE_INODE_OBJECTID; 2555 btrfs_init_btree_inode(fs_info, tree_root);
2323 set_nlink(fs_info->btree_inode, 1);
2324 /*
2325 * we set the i_size on the btree inode to the max possible int.
2326 * the real end of the address space is determined by all of
2327 * the devices in the system
2328 */
2329 fs_info->btree_inode->i_size = OFFSET_MAX;
2330 fs_info->btree_inode->i_mapping->a_ops = &btree_aops;
2331
2332 RB_CLEAR_NODE(&BTRFS_I(fs_info->btree_inode)->rb_node);
2333 extent_io_tree_init(&BTRFS_I(fs_info->btree_inode)->io_tree,
2334 fs_info->btree_inode->i_mapping);
2335 BTRFS_I(fs_info->btree_inode)->io_tree.track_uptodate = 0;
2336 extent_map_tree_init(&BTRFS_I(fs_info->btree_inode)->extent_tree);
2337
2338 BTRFS_I(fs_info->btree_inode)->io_tree.ops = &btree_extent_io_ops;
2339
2340 BTRFS_I(fs_info->btree_inode)->root = tree_root;
2341 memset(&BTRFS_I(fs_info->btree_inode)->location, 0,
2342 sizeof(struct btrfs_key));
2343 set_bit(BTRFS_INODE_DUMMY,
2344 &BTRFS_I(fs_info->btree_inode)->runtime_flags);
2345 btrfs_insert_inode_hash(fs_info->btree_inode);
2346 2556
2347 spin_lock_init(&fs_info->block_group_cache_lock); 2557 spin_lock_init(&fs_info->block_group_cache_lock);
2348 fs_info->block_group_cache_tree = RB_ROOT; 2558 fs_info->block_group_cache_tree = RB_ROOT;
@@ -2363,26 +2573,14 @@ int open_ctree(struct super_block *sb,
2363 mutex_init(&fs_info->transaction_kthread_mutex); 2573 mutex_init(&fs_info->transaction_kthread_mutex);
2364 mutex_init(&fs_info->cleaner_mutex); 2574 mutex_init(&fs_info->cleaner_mutex);
2365 mutex_init(&fs_info->volume_mutex); 2575 mutex_init(&fs_info->volume_mutex);
2576 mutex_init(&fs_info->ro_block_group_mutex);
2366 init_rwsem(&fs_info->commit_root_sem); 2577 init_rwsem(&fs_info->commit_root_sem);
2367 init_rwsem(&fs_info->cleanup_work_sem); 2578 init_rwsem(&fs_info->cleanup_work_sem);
2368 init_rwsem(&fs_info->subvol_sem); 2579 init_rwsem(&fs_info->subvol_sem);
2369 sema_init(&fs_info->uuid_tree_rescan_sem, 1); 2580 sema_init(&fs_info->uuid_tree_rescan_sem, 1);
2370 fs_info->dev_replace.lock_owner = 0;
2371 atomic_set(&fs_info->dev_replace.nesting_level, 0);
2372 mutex_init(&fs_info->dev_replace.lock_finishing_cancel_unmount);
2373 mutex_init(&fs_info->dev_replace.lock_management_lock);
2374 mutex_init(&fs_info->dev_replace.lock);
2375 2581
2376 spin_lock_init(&fs_info->qgroup_lock); 2582 btrfs_init_dev_replace_locks(fs_info);
2377 mutex_init(&fs_info->qgroup_ioctl_lock); 2583 btrfs_init_qgroup(fs_info);
2378 fs_info->qgroup_tree = RB_ROOT;
2379 fs_info->qgroup_op_tree = RB_ROOT;
2380 INIT_LIST_HEAD(&fs_info->dirty_qgroups);
2381 fs_info->qgroup_seq = 1;
2382 fs_info->quota_enabled = 0;
2383 fs_info->pending_quota_state = 0;
2384 fs_info->qgroup_ulist = NULL;
2385 mutex_init(&fs_info->qgroup_rescan_lock);
2386 2584
2387 btrfs_init_free_cluster(&fs_info->meta_alloc_cluster); 2585 btrfs_init_free_cluster(&fs_info->meta_alloc_cluster);
2388 btrfs_init_free_cluster(&fs_info->data_alloc_cluster); 2586 btrfs_init_free_cluster(&fs_info->data_alloc_cluster);
@@ -2554,75 +2752,9 @@ int open_ctree(struct super_block *sb,
2554 2752
2555 max_active = fs_info->thread_pool_size; 2753 max_active = fs_info->thread_pool_size;
2556 2754
2557 fs_info->workers = 2755 ret = btrfs_init_workqueues(fs_info, fs_devices);
2558 btrfs_alloc_workqueue("worker", flags | WQ_HIGHPRI, 2756 if (ret) {
2559 max_active, 16); 2757 err = ret;
2560
2561 fs_info->delalloc_workers =
2562 btrfs_alloc_workqueue("delalloc", flags, max_active, 2);
2563
2564 fs_info->flush_workers =
2565 btrfs_alloc_workqueue("flush_delalloc", flags, max_active, 0);
2566
2567 fs_info->caching_workers =
2568 btrfs_alloc_workqueue("cache", flags, max_active, 0);
2569
2570 /*
2571 * a higher idle thresh on the submit workers makes it much more
2572 * likely that bios will be send down in a sane order to the
2573 * devices
2574 */
2575 fs_info->submit_workers =
2576 btrfs_alloc_workqueue("submit", flags,
2577 min_t(u64, fs_devices->num_devices,
2578 max_active), 64);
2579
2580 fs_info->fixup_workers =
2581 btrfs_alloc_workqueue("fixup", flags, 1, 0);
2582
2583 /*
2584 * endios are largely parallel and should have a very
2585 * low idle thresh
2586 */
2587 fs_info->endio_workers =
2588 btrfs_alloc_workqueue("endio", flags, max_active, 4);
2589 fs_info->endio_meta_workers =
2590 btrfs_alloc_workqueue("endio-meta", flags, max_active, 4);
2591 fs_info->endio_meta_write_workers =
2592 btrfs_alloc_workqueue("endio-meta-write", flags, max_active, 2);
2593 fs_info->endio_raid56_workers =
2594 btrfs_alloc_workqueue("endio-raid56", flags, max_active, 4);
2595 fs_info->endio_repair_workers =
2596 btrfs_alloc_workqueue("endio-repair", flags, 1, 0);
2597 fs_info->rmw_workers =
2598 btrfs_alloc_workqueue("rmw", flags, max_active, 2);
2599 fs_info->endio_write_workers =
2600 btrfs_alloc_workqueue("endio-write", flags, max_active, 2);
2601 fs_info->endio_freespace_worker =
2602 btrfs_alloc_workqueue("freespace-write", flags, max_active, 0);
2603 fs_info->delayed_workers =
2604 btrfs_alloc_workqueue("delayed-meta", flags, max_active, 0);
2605 fs_info->readahead_workers =
2606 btrfs_alloc_workqueue("readahead", flags, max_active, 2);
2607 fs_info->qgroup_rescan_workers =
2608 btrfs_alloc_workqueue("qgroup-rescan", flags, 1, 0);
2609 fs_info->extent_workers =
2610 btrfs_alloc_workqueue("extent-refs", flags,
2611 min_t(u64, fs_devices->num_devices,
2612 max_active), 8);
2613
2614 if (!(fs_info->workers && fs_info->delalloc_workers &&
2615 fs_info->submit_workers && fs_info->flush_workers &&
2616 fs_info->endio_workers && fs_info->endio_meta_workers &&
2617 fs_info->endio_meta_write_workers &&
2618 fs_info->endio_repair_workers &&
2619 fs_info->endio_write_workers && fs_info->endio_raid56_workers &&
2620 fs_info->endio_freespace_worker && fs_info->rmw_workers &&
2621 fs_info->caching_workers && fs_info->readahead_workers &&
2622 fs_info->fixup_workers && fs_info->delayed_workers &&
2623 fs_info->extent_workers &&
2624 fs_info->qgroup_rescan_workers)) {
2625 err = -ENOMEM;
2626 goto fail_sb_buffer; 2758 goto fail_sb_buffer;
2627 } 2759 }
2628 2760
@@ -2688,7 +2820,7 @@ int open_ctree(struct super_block *sb,
2688 * keep the device that is marked to be the target device for the 2820 * keep the device that is marked to be the target device for the
2689 * dev_replace procedure 2821 * dev_replace procedure
2690 */ 2822 */
2691 btrfs_close_extra_devices(fs_info, fs_devices, 0); 2823 btrfs_close_extra_devices(fs_devices, 0);
2692 2824
2693 if (!fs_devices->latest_bdev) { 2825 if (!fs_devices->latest_bdev) {
2694 printk(KERN_ERR "BTRFS: failed to read devices on %s\n", 2826 printk(KERN_ERR "BTRFS: failed to read devices on %s\n",
@@ -2714,61 +2846,9 @@ retry_root_backup:
2714 tree_root->commit_root = btrfs_root_node(tree_root); 2846 tree_root->commit_root = btrfs_root_node(tree_root);
2715 btrfs_set_root_refs(&tree_root->root_item, 1); 2847 btrfs_set_root_refs(&tree_root->root_item, 1);
2716 2848
2717 location.objectid = BTRFS_EXTENT_TREE_OBJECTID; 2849 ret = btrfs_read_roots(fs_info, tree_root);
2718 location.type = BTRFS_ROOT_ITEM_KEY; 2850 if (ret)
2719 location.offset = 0;
2720
2721 extent_root = btrfs_read_tree_root(tree_root, &location);
2722 if (IS_ERR(extent_root)) {
2723 ret = PTR_ERR(extent_root);
2724 goto recovery_tree_root;
2725 }
2726 set_bit(BTRFS_ROOT_TRACK_DIRTY, &extent_root->state);
2727 fs_info->extent_root = extent_root;
2728
2729 location.objectid = BTRFS_DEV_TREE_OBJECTID;
2730 dev_root = btrfs_read_tree_root(tree_root, &location);
2731 if (IS_ERR(dev_root)) {
2732 ret = PTR_ERR(dev_root);
2733 goto recovery_tree_root;
2734 }
2735 set_bit(BTRFS_ROOT_TRACK_DIRTY, &dev_root->state);
2736 fs_info->dev_root = dev_root;
2737 btrfs_init_devices_late(fs_info);
2738
2739 location.objectid = BTRFS_CSUM_TREE_OBJECTID;
2740 csum_root = btrfs_read_tree_root(tree_root, &location);
2741 if (IS_ERR(csum_root)) {
2742 ret = PTR_ERR(csum_root);
2743 goto recovery_tree_root; 2851 goto recovery_tree_root;
2744 }
2745 set_bit(BTRFS_ROOT_TRACK_DIRTY, &csum_root->state);
2746 fs_info->csum_root = csum_root;
2747
2748 location.objectid = BTRFS_QUOTA_TREE_OBJECTID;
2749 quota_root = btrfs_read_tree_root(tree_root, &location);
2750 if (!IS_ERR(quota_root)) {
2751 set_bit(BTRFS_ROOT_TRACK_DIRTY, &quota_root->state);
2752 fs_info->quota_enabled = 1;
2753 fs_info->pending_quota_state = 1;
2754 fs_info->quota_root = quota_root;
2755 }
2756
2757 location.objectid = BTRFS_UUID_TREE_OBJECTID;
2758 uuid_root = btrfs_read_tree_root(tree_root, &location);
2759 if (IS_ERR(uuid_root)) {
2760 ret = PTR_ERR(uuid_root);
2761 if (ret != -ENOENT)
2762 goto recovery_tree_root;
2763 create_uuid_tree = true;
2764 check_uuid_tree = false;
2765 } else {
2766 set_bit(BTRFS_ROOT_TRACK_DIRTY, &uuid_root->state);
2767 fs_info->uuid_root = uuid_root;
2768 create_uuid_tree = false;
2769 check_uuid_tree =
2770 generation != btrfs_super_uuid_tree_generation(disk_super);
2771 }
2772 2852
2773 fs_info->generation = generation; 2853 fs_info->generation = generation;
2774 fs_info->last_trans_committed = generation; 2854 fs_info->last_trans_committed = generation;
@@ -2792,7 +2872,7 @@ retry_root_backup:
2792 goto fail_block_groups; 2872 goto fail_block_groups;
2793 } 2873 }
2794 2874
2795 btrfs_close_extra_devices(fs_info, fs_devices, 1); 2875 btrfs_close_extra_devices(fs_devices, 1);
2796 2876
2797 ret = btrfs_sysfs_add_one(fs_info); 2877 ret = btrfs_sysfs_add_one(fs_info);
2798 if (ret) { 2878 if (ret) {
@@ -2806,7 +2886,7 @@ retry_root_backup:
2806 goto fail_sysfs; 2886 goto fail_sysfs;
2807 } 2887 }
2808 2888
2809 ret = btrfs_read_block_groups(extent_root); 2889 ret = btrfs_read_block_groups(fs_info->extent_root);
2810 if (ret) { 2890 if (ret) {
2811 printk(KERN_ERR "BTRFS: Failed to read block groups: %d\n", ret); 2891 printk(KERN_ERR "BTRFS: Failed to read block groups: %d\n", ret);
2812 goto fail_sysfs; 2892 goto fail_sysfs;
@@ -2864,48 +2944,11 @@ retry_root_backup:
2864 2944
2865 /* do not make disk changes in broken FS */ 2945 /* do not make disk changes in broken FS */
2866 if (btrfs_super_log_root(disk_super) != 0) { 2946 if (btrfs_super_log_root(disk_super) != 0) {
2867 u64 bytenr = btrfs_super_log_root(disk_super); 2947 ret = btrfs_replay_log(fs_info, fs_devices);
2868
2869 if (fs_devices->rw_devices == 0) {
2870 printk(KERN_WARNING "BTRFS: log replay required "
2871 "on RO media\n");
2872 err = -EIO;
2873 goto fail_qgroup;
2874 }
2875
2876 log_tree_root = btrfs_alloc_root(fs_info);
2877 if (!log_tree_root) {
2878 err = -ENOMEM;
2879 goto fail_qgroup;
2880 }
2881
2882 __setup_root(nodesize, sectorsize, stripesize,
2883 log_tree_root, fs_info, BTRFS_TREE_LOG_OBJECTID);
2884
2885 log_tree_root->node = read_tree_block(tree_root, bytenr,
2886 generation + 1);
2887 if (!log_tree_root->node ||
2888 !extent_buffer_uptodate(log_tree_root->node)) {
2889 printk(KERN_ERR "BTRFS: failed to read log tree\n");
2890 free_extent_buffer(log_tree_root->node);
2891 kfree(log_tree_root);
2892 goto fail_qgroup;
2893 }
2894 /* returns with log_tree_root freed on success */
2895 ret = btrfs_recover_log_trees(log_tree_root);
2896 if (ret) { 2948 if (ret) {
2897 btrfs_error(tree_root->fs_info, ret, 2949 err = ret;
2898 "Failed to recover log tree");
2899 free_extent_buffer(log_tree_root->node);
2900 kfree(log_tree_root);
2901 goto fail_qgroup; 2950 goto fail_qgroup;
2902 } 2951 }
2903
2904 if (sb->s_flags & MS_RDONLY) {
2905 ret = btrfs_commit_super(tree_root);
2906 if (ret)
2907 goto fail_qgroup;
2908 }
2909 } 2952 }
2910 2953
2911 ret = btrfs_find_orphan_roots(tree_root); 2954 ret = btrfs_find_orphan_roots(tree_root);
@@ -2966,7 +3009,7 @@ retry_root_backup:
2966 3009
2967 btrfs_qgroup_rescan_resume(fs_info); 3010 btrfs_qgroup_rescan_resume(fs_info);
2968 3011
2969 if (create_uuid_tree) { 3012 if (!fs_info->uuid_root) {
2970 pr_info("BTRFS: creating UUID tree\n"); 3013 pr_info("BTRFS: creating UUID tree\n");
2971 ret = btrfs_create_uuid_tree(fs_info); 3014 ret = btrfs_create_uuid_tree(fs_info);
2972 if (ret) { 3015 if (ret) {
@@ -2975,8 +3018,9 @@ retry_root_backup:
2975 close_ctree(tree_root); 3018 close_ctree(tree_root);
2976 return ret; 3019 return ret;
2977 } 3020 }
2978 } else if (check_uuid_tree || 3021 } else if (btrfs_test_opt(tree_root, RESCAN_UUID_TREE) ||
2979 btrfs_test_opt(tree_root, RESCAN_UUID_TREE)) { 3022 fs_info->generation !=
3023 btrfs_super_uuid_tree_generation(disk_super)) {
2980 pr_info("BTRFS: checking UUID tree\n"); 3024 pr_info("BTRFS: checking UUID tree\n");
2981 ret = btrfs_check_uuid_tree(fs_info); 3025 ret = btrfs_check_uuid_tree(fs_info);
2982 if (ret) { 3026 if (ret) {
@@ -3668,7 +3712,7 @@ void close_ctree(struct btrfs_root *root)
3668 if (!(fs_info->sb->s_flags & MS_RDONLY)) { 3712 if (!(fs_info->sb->s_flags & MS_RDONLY)) {
3669 ret = btrfs_commit_super(root); 3713 ret = btrfs_commit_super(root);
3670 if (ret) 3714 if (ret)
3671 btrfs_err(root->fs_info, "commit super ret %d", ret); 3715 btrfs_err(fs_info, "commit super ret %d", ret);
3672 } 3716 }
3673 3717
3674 if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) 3718 if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state))
@@ -3680,10 +3724,10 @@ void close_ctree(struct btrfs_root *root)
3680 fs_info->closing = 2; 3724 fs_info->closing = 2;
3681 smp_mb(); 3725 smp_mb();
3682 3726
3683 btrfs_free_qgroup_config(root->fs_info); 3727 btrfs_free_qgroup_config(fs_info);
3684 3728
3685 if (percpu_counter_sum(&fs_info->delalloc_bytes)) { 3729 if (percpu_counter_sum(&fs_info->delalloc_bytes)) {
3686 btrfs_info(root->fs_info, "at unmount delalloc count %lld", 3730 btrfs_info(fs_info, "at unmount delalloc count %lld",
3687 percpu_counter_sum(&fs_info->delalloc_bytes)); 3731 percpu_counter_sum(&fs_info->delalloc_bytes));
3688 } 3732 }
3689 3733
@@ -3723,7 +3767,7 @@ void close_ctree(struct btrfs_root *root)
3723 3767
3724 btrfs_free_stripe_hash_table(fs_info); 3768 btrfs_free_stripe_hash_table(fs_info);
3725 3769
3726 btrfs_free_block_rsv(root, root->orphan_block_rsv); 3770 __btrfs_free_block_rsv(root->orphan_block_rsv);
3727 root->orphan_block_rsv = NULL; 3771 root->orphan_block_rsv = NULL;
3728 3772
3729 lock_chunks(root); 3773 lock_chunks(root);
@@ -4134,7 +4178,7 @@ static int btrfs_destroy_marked_extents(struct btrfs_root *root,
4134 4178
4135 clear_extent_bits(dirty_pages, start, end, mark, GFP_NOFS); 4179 clear_extent_bits(dirty_pages, start, end, mark, GFP_NOFS);
4136 while (start <= end) { 4180 while (start <= end) {
4137 eb = btrfs_find_tree_block(root, start); 4181 eb = btrfs_find_tree_block(root->fs_info, start);
4138 start += root->nodesize; 4182 start += root->nodesize;
4139 if (!eb) 4183 if (!eb)
4140 continue; 4184 continue;
@@ -4285,7 +4329,7 @@ static int btrfs_cleanup_transaction(struct btrfs_root *root)
4285 return 0; 4329 return 0;
4286} 4330}
4287 4331
4288static struct extent_io_ops btree_extent_io_ops = { 4332static const struct extent_io_ops btree_extent_io_ops = {
4289 .readpage_end_io_hook = btree_readpage_end_io_hook, 4333 .readpage_end_io_hook = btree_readpage_end_io_hook,
4290 .readpage_io_failed_hook = btree_io_failed_hook, 4334 .readpage_io_failed_hook = btree_io_failed_hook,
4291 .submit_bio_hook = btree_submit_bio_hook, 4335 .submit_bio_hook = btree_submit_bio_hook,
diff --git a/fs/btrfs/disk-io.h b/fs/btrfs/disk-io.h
index 27d44c0fd236..d4cbfeeeedd4 100644
--- a/fs/btrfs/disk-io.h
+++ b/fs/btrfs/disk-io.h
@@ -52,7 +52,7 @@ int reada_tree_block_flagged(struct btrfs_root *root, u64 bytenr,
52struct extent_buffer *btrfs_find_create_tree_block(struct btrfs_root *root, 52struct extent_buffer *btrfs_find_create_tree_block(struct btrfs_root *root,
53 u64 bytenr); 53 u64 bytenr);
54void clean_tree_block(struct btrfs_trans_handle *trans, 54void clean_tree_block(struct btrfs_trans_handle *trans,
55 struct btrfs_root *root, struct extent_buffer *buf); 55 struct btrfs_fs_info *fs_info, struct extent_buffer *buf);
56int open_ctree(struct super_block *sb, 56int open_ctree(struct super_block *sb,
57 struct btrfs_fs_devices *fs_devices, 57 struct btrfs_fs_devices *fs_devices,
58 char *options); 58 char *options);
@@ -61,7 +61,7 @@ int write_ctree_super(struct btrfs_trans_handle *trans,
61 struct btrfs_root *root, int max_mirrors); 61 struct btrfs_root *root, int max_mirrors);
62struct buffer_head *btrfs_read_dev_super(struct block_device *bdev); 62struct buffer_head *btrfs_read_dev_super(struct block_device *bdev);
63int btrfs_commit_super(struct btrfs_root *root); 63int btrfs_commit_super(struct btrfs_root *root);
64struct extent_buffer *btrfs_find_tree_block(struct btrfs_root *root, 64struct extent_buffer *btrfs_find_tree_block(struct btrfs_fs_info *fs_info,
65 u64 bytenr); 65 u64 bytenr);
66struct btrfs_root *btrfs_read_fs_root(struct btrfs_root *tree_root, 66struct btrfs_root *btrfs_read_fs_root(struct btrfs_root *tree_root,
67 struct btrfs_key *location); 67 struct btrfs_key *location);
diff --git a/fs/btrfs/export.c b/fs/btrfs/export.c
index 37d164540c3a..8d052209f473 100644
--- a/fs/btrfs/export.c
+++ b/fs/btrfs/export.c
@@ -152,7 +152,7 @@ static struct dentry *btrfs_fh_to_dentry(struct super_block *sb, struct fid *fh,
152 152
153static struct dentry *btrfs_get_parent(struct dentry *child) 153static struct dentry *btrfs_get_parent(struct dentry *child)
154{ 154{
155 struct inode *dir = child->d_inode; 155 struct inode *dir = d_inode(child);
156 struct btrfs_root *root = BTRFS_I(dir)->root; 156 struct btrfs_root *root = BTRFS_I(dir)->root;
157 struct btrfs_path *path; 157 struct btrfs_path *path;
158 struct extent_buffer *leaf; 158 struct extent_buffer *leaf;
@@ -220,8 +220,8 @@ fail:
220static int btrfs_get_name(struct dentry *parent, char *name, 220static int btrfs_get_name(struct dentry *parent, char *name,
221 struct dentry *child) 221 struct dentry *child)
222{ 222{
223 struct inode *inode = child->d_inode; 223 struct inode *inode = d_inode(child);
224 struct inode *dir = parent->d_inode; 224 struct inode *dir = d_inode(parent);
225 struct btrfs_path *path; 225 struct btrfs_path *path;
226 struct btrfs_root *root = BTRFS_I(dir)->root; 226 struct btrfs_root *root = BTRFS_I(dir)->root;
227 struct btrfs_inode_ref *iref; 227 struct btrfs_inode_ref *iref;
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 8b353ad02f03..1eef4ee01d1a 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -2538,6 +2538,12 @@ static noinline int __btrfs_run_delayed_refs(struct btrfs_trans_handle *trans,
2538 * list before we release it. 2538 * list before we release it.
2539 */ 2539 */
2540 if (btrfs_delayed_ref_is_head(ref)) { 2540 if (btrfs_delayed_ref_is_head(ref)) {
2541 if (locked_ref->is_data &&
2542 locked_ref->total_ref_mod < 0) {
2543 spin_lock(&delayed_refs->lock);
2544 delayed_refs->pending_csums -= ref->num_bytes;
2545 spin_unlock(&delayed_refs->lock);
2546 }
2541 btrfs_delayed_ref_unlock(locked_ref); 2547 btrfs_delayed_ref_unlock(locked_ref);
2542 locked_ref = NULL; 2548 locked_ref = NULL;
2543 } 2549 }
@@ -2561,8 +2567,7 @@ static noinline int __btrfs_run_delayed_refs(struct btrfs_trans_handle *trans,
2561 */ 2567 */
2562 spin_lock(&delayed_refs->lock); 2568 spin_lock(&delayed_refs->lock);
2563 avg = fs_info->avg_delayed_ref_runtime * 3 + runtime; 2569 avg = fs_info->avg_delayed_ref_runtime * 3 + runtime;
2564 avg = div64_u64(avg, 4); 2570 fs_info->avg_delayed_ref_runtime = avg >> 2; /* div by 4 */
2565 fs_info->avg_delayed_ref_runtime = avg;
2566 spin_unlock(&delayed_refs->lock); 2571 spin_unlock(&delayed_refs->lock);
2567 } 2572 }
2568 return 0; 2573 return 0;
@@ -2624,7 +2629,26 @@ static inline u64 heads_to_leaves(struct btrfs_root *root, u64 heads)
2624 * We don't ever fill up leaves all the way so multiply by 2 just to be 2629 * We don't ever fill up leaves all the way so multiply by 2 just to be
2625 * closer to what we're really going to want to ouse. 2630 * closer to what we're really going to want to ouse.
2626 */ 2631 */
2627 return div64_u64(num_bytes, BTRFS_LEAF_DATA_SIZE(root)); 2632 return div_u64(num_bytes, BTRFS_LEAF_DATA_SIZE(root));
2633}
2634
2635/*
2636 * Takes the number of bytes to be csumm'ed and figures out how many leaves it
2637 * would require to store the csums for that many bytes.
2638 */
2639u64 btrfs_csum_bytes_to_leaves(struct btrfs_root *root, u64 csum_bytes)
2640{
2641 u64 csum_size;
2642 u64 num_csums_per_leaf;
2643 u64 num_csums;
2644
2645 csum_size = BTRFS_LEAF_DATA_SIZE(root) - sizeof(struct btrfs_item);
2646 num_csums_per_leaf = div64_u64(csum_size,
2647 (u64)btrfs_super_csum_size(root->fs_info->super_copy));
2648 num_csums = div64_u64(csum_bytes, root->sectorsize);
2649 num_csums += num_csums_per_leaf - 1;
2650 num_csums = div64_u64(num_csums, num_csums_per_leaf);
2651 return num_csums;
2628} 2652}
2629 2653
2630int btrfs_check_space_for_delayed_refs(struct btrfs_trans_handle *trans, 2654int btrfs_check_space_for_delayed_refs(struct btrfs_trans_handle *trans,
@@ -2632,7 +2656,9 @@ int btrfs_check_space_for_delayed_refs(struct btrfs_trans_handle *trans,
2632{ 2656{
2633 struct btrfs_block_rsv *global_rsv; 2657 struct btrfs_block_rsv *global_rsv;
2634 u64 num_heads = trans->transaction->delayed_refs.num_heads_ready; 2658 u64 num_heads = trans->transaction->delayed_refs.num_heads_ready;
2635 u64 num_bytes; 2659 u64 csum_bytes = trans->transaction->delayed_refs.pending_csums;
2660 u64 num_dirty_bgs = trans->transaction->num_dirty_bgs;
2661 u64 num_bytes, num_dirty_bgs_bytes;
2636 int ret = 0; 2662 int ret = 0;
2637 2663
2638 num_bytes = btrfs_calc_trans_metadata_size(root, 1); 2664 num_bytes = btrfs_calc_trans_metadata_size(root, 1);
@@ -2640,17 +2666,22 @@ int btrfs_check_space_for_delayed_refs(struct btrfs_trans_handle *trans,
2640 if (num_heads > 1) 2666 if (num_heads > 1)
2641 num_bytes += (num_heads - 1) * root->nodesize; 2667 num_bytes += (num_heads - 1) * root->nodesize;
2642 num_bytes <<= 1; 2668 num_bytes <<= 1;
2669 num_bytes += btrfs_csum_bytes_to_leaves(root, csum_bytes) * root->nodesize;
2670 num_dirty_bgs_bytes = btrfs_calc_trans_metadata_size(root,
2671 num_dirty_bgs);
2643 global_rsv = &root->fs_info->global_block_rsv; 2672 global_rsv = &root->fs_info->global_block_rsv;
2644 2673
2645 /* 2674 /*
2646 * If we can't allocate any more chunks lets make sure we have _lots_ of 2675 * If we can't allocate any more chunks lets make sure we have _lots_ of
2647 * wiggle room since running delayed refs can create more delayed refs. 2676 * wiggle room since running delayed refs can create more delayed refs.
2648 */ 2677 */
2649 if (global_rsv->space_info->full) 2678 if (global_rsv->space_info->full) {
2679 num_dirty_bgs_bytes <<= 1;
2650 num_bytes <<= 1; 2680 num_bytes <<= 1;
2681 }
2651 2682
2652 spin_lock(&global_rsv->lock); 2683 spin_lock(&global_rsv->lock);
2653 if (global_rsv->reserved <= num_bytes) 2684 if (global_rsv->reserved <= num_bytes + num_dirty_bgs_bytes)
2654 ret = 1; 2685 ret = 1;
2655 spin_unlock(&global_rsv->lock); 2686 spin_unlock(&global_rsv->lock);
2656 return ret; 2687 return ret;
@@ -3193,7 +3224,7 @@ static int cache_save_setup(struct btrfs_block_group_cache *block_group,
3193 struct inode *inode = NULL; 3224 struct inode *inode = NULL;
3194 u64 alloc_hint = 0; 3225 u64 alloc_hint = 0;
3195 int dcs = BTRFS_DC_ERROR; 3226 int dcs = BTRFS_DC_ERROR;
3196 int num_pages = 0; 3227 u64 num_pages = 0;
3197 int retries = 0; 3228 int retries = 0;
3198 int ret = 0; 3229 int ret = 0;
3199 3230
@@ -3267,7 +3298,7 @@ again:
3267 if (ret) 3298 if (ret)
3268 goto out_put; 3299 goto out_put;
3269 3300
3270 ret = btrfs_truncate_free_space_cache(root, trans, inode); 3301 ret = btrfs_truncate_free_space_cache(root, trans, NULL, inode);
3271 if (ret) 3302 if (ret)
3272 goto out_put; 3303 goto out_put;
3273 } 3304 }
@@ -3293,14 +3324,14 @@ again:
3293 * taking up quite a bit since it's not folded into the other space 3324 * taking up quite a bit since it's not folded into the other space
3294 * cache. 3325 * cache.
3295 */ 3326 */
3296 num_pages = (int)div64_u64(block_group->key.offset, 256 * 1024 * 1024); 3327 num_pages = div_u64(block_group->key.offset, 256 * 1024 * 1024);
3297 if (!num_pages) 3328 if (!num_pages)
3298 num_pages = 1; 3329 num_pages = 1;
3299 3330
3300 num_pages *= 16; 3331 num_pages *= 16;
3301 num_pages *= PAGE_CACHE_SIZE; 3332 num_pages *= PAGE_CACHE_SIZE;
3302 3333
3303 ret = btrfs_check_data_free_space(inode, num_pages); 3334 ret = btrfs_check_data_free_space(inode, num_pages, num_pages);
3304 if (ret) 3335 if (ret)
3305 goto out_put; 3336 goto out_put;
3306 3337
@@ -3351,16 +3382,156 @@ int btrfs_setup_space_cache(struct btrfs_trans_handle *trans,
3351 return 0; 3382 return 0;
3352} 3383}
3353 3384
3354int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans, 3385/*
3386 * transaction commit does final block group cache writeback during a
3387 * critical section where nothing is allowed to change the FS. This is
3388 * required in order for the cache to actually match the block group,
3389 * but can introduce a lot of latency into the commit.
3390 *
3391 * So, btrfs_start_dirty_block_groups is here to kick off block group
3392 * cache IO. There's a chance we'll have to redo some of it if the
3393 * block group changes again during the commit, but it greatly reduces
3394 * the commit latency by getting rid of the easy block groups while
3395 * we're still allowing others to join the commit.
3396 */
3397int btrfs_start_dirty_block_groups(struct btrfs_trans_handle *trans,
3355 struct btrfs_root *root) 3398 struct btrfs_root *root)
3356{ 3399{
3357 struct btrfs_block_group_cache *cache; 3400 struct btrfs_block_group_cache *cache;
3358 struct btrfs_transaction *cur_trans = trans->transaction; 3401 struct btrfs_transaction *cur_trans = trans->transaction;
3359 int ret = 0; 3402 int ret = 0;
3360 struct btrfs_path *path; 3403 int should_put;
3404 struct btrfs_path *path = NULL;
3405 LIST_HEAD(dirty);
3406 struct list_head *io = &cur_trans->io_bgs;
3407 int num_started = 0;
3408 int loops = 0;
3409
3410 spin_lock(&cur_trans->dirty_bgs_lock);
3411 if (!list_empty(&cur_trans->dirty_bgs)) {
3412 list_splice_init(&cur_trans->dirty_bgs, &dirty);
3413 }
3414 spin_unlock(&cur_trans->dirty_bgs_lock);
3361 3415
3362 if (list_empty(&cur_trans->dirty_bgs)) 3416again:
3417 if (list_empty(&dirty)) {
3418 btrfs_free_path(path);
3363 return 0; 3419 return 0;
3420 }
3421
3422 /*
3423 * make sure all the block groups on our dirty list actually
3424 * exist
3425 */
3426 btrfs_create_pending_block_groups(trans, root);
3427
3428 if (!path) {
3429 path = btrfs_alloc_path();
3430 if (!path)
3431 return -ENOMEM;
3432 }
3433
3434 while (!list_empty(&dirty)) {
3435 cache = list_first_entry(&dirty,
3436 struct btrfs_block_group_cache,
3437 dirty_list);
3438
3439 /*
3440 * cache_write_mutex is here only to save us from balance
3441 * deleting this block group while we are writing out the
3442 * cache
3443 */
3444 mutex_lock(&trans->transaction->cache_write_mutex);
3445
3446 /*
3447 * this can happen if something re-dirties a block
3448 * group that is already under IO. Just wait for it to
3449 * finish and then do it all again
3450 */
3451 if (!list_empty(&cache->io_list)) {
3452 list_del_init(&cache->io_list);
3453 btrfs_wait_cache_io(root, trans, cache,
3454 &cache->io_ctl, path,
3455 cache->key.objectid);
3456 btrfs_put_block_group(cache);
3457 }
3458
3459
3460 /*
3461 * btrfs_wait_cache_io uses the cache->dirty_list to decide
3462 * if it should update the cache_state. Don't delete
3463 * until after we wait.
3464 *
3465 * Since we're not running in the commit critical section
3466 * we need the dirty_bgs_lock to protect from update_block_group
3467 */
3468 spin_lock(&cur_trans->dirty_bgs_lock);
3469 list_del_init(&cache->dirty_list);
3470 spin_unlock(&cur_trans->dirty_bgs_lock);
3471
3472 should_put = 1;
3473
3474 cache_save_setup(cache, trans, path);
3475
3476 if (cache->disk_cache_state == BTRFS_DC_SETUP) {
3477 cache->io_ctl.inode = NULL;
3478 ret = btrfs_write_out_cache(root, trans, cache, path);
3479 if (ret == 0 && cache->io_ctl.inode) {
3480 num_started++;
3481 should_put = 0;
3482
3483 /*
3484 * the cache_write_mutex is protecting
3485 * the io_list
3486 */
3487 list_add_tail(&cache->io_list, io);
3488 } else {
3489 /*
3490 * if we failed to write the cache, the
3491 * generation will be bad and life goes on
3492 */
3493 ret = 0;
3494 }
3495 }
3496 if (!ret)
3497 ret = write_one_cache_group(trans, root, path, cache);
3498 mutex_unlock(&trans->transaction->cache_write_mutex);
3499
3500 /* if its not on the io list, we need to put the block group */
3501 if (should_put)
3502 btrfs_put_block_group(cache);
3503
3504 if (ret)
3505 break;
3506 }
3507
3508 /*
3509 * go through delayed refs for all the stuff we've just kicked off
3510 * and then loop back (just once)
3511 */
3512 ret = btrfs_run_delayed_refs(trans, root, 0);
3513 if (!ret && loops == 0) {
3514 loops++;
3515 spin_lock(&cur_trans->dirty_bgs_lock);
3516 list_splice_init(&cur_trans->dirty_bgs, &dirty);
3517 spin_unlock(&cur_trans->dirty_bgs_lock);
3518 goto again;
3519 }
3520
3521 btrfs_free_path(path);
3522 return ret;
3523}
3524
3525int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans,
3526 struct btrfs_root *root)
3527{
3528 struct btrfs_block_group_cache *cache;
3529 struct btrfs_transaction *cur_trans = trans->transaction;
3530 int ret = 0;
3531 int should_put;
3532 struct btrfs_path *path;
3533 struct list_head *io = &cur_trans->io_bgs;
3534 int num_started = 0;
3364 3535
3365 path = btrfs_alloc_path(); 3536 path = btrfs_alloc_path();
3366 if (!path) 3537 if (!path)
@@ -3376,16 +3547,61 @@ int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans,
3376 cache = list_first_entry(&cur_trans->dirty_bgs, 3547 cache = list_first_entry(&cur_trans->dirty_bgs,
3377 struct btrfs_block_group_cache, 3548 struct btrfs_block_group_cache,
3378 dirty_list); 3549 dirty_list);
3550
3551 /*
3552 * this can happen if cache_save_setup re-dirties a block
3553 * group that is already under IO. Just wait for it to
3554 * finish and then do it all again
3555 */
3556 if (!list_empty(&cache->io_list)) {
3557 list_del_init(&cache->io_list);
3558 btrfs_wait_cache_io(root, trans, cache,
3559 &cache->io_ctl, path,
3560 cache->key.objectid);
3561 btrfs_put_block_group(cache);
3562 }
3563
3564 /*
3565 * don't remove from the dirty list until after we've waited
3566 * on any pending IO
3567 */
3379 list_del_init(&cache->dirty_list); 3568 list_del_init(&cache->dirty_list);
3380 if (cache->disk_cache_state == BTRFS_DC_CLEAR) 3569 should_put = 1;
3381 cache_save_setup(cache, trans, path); 3570
3571 cache_save_setup(cache, trans, path);
3572
3382 if (!ret) 3573 if (!ret)
3383 ret = btrfs_run_delayed_refs(trans, root, 3574 ret = btrfs_run_delayed_refs(trans, root, (unsigned long) -1);
3384 (unsigned long) -1); 3575
3385 if (!ret && cache->disk_cache_state == BTRFS_DC_SETUP) 3576 if (!ret && cache->disk_cache_state == BTRFS_DC_SETUP) {
3386 btrfs_write_out_cache(root, trans, cache, path); 3577 cache->io_ctl.inode = NULL;
3578 ret = btrfs_write_out_cache(root, trans, cache, path);
3579 if (ret == 0 && cache->io_ctl.inode) {
3580 num_started++;
3581 should_put = 0;
3582 list_add_tail(&cache->io_list, io);
3583 } else {
3584 /*
3585 * if we failed to write the cache, the
3586 * generation will be bad and life goes on
3587 */
3588 ret = 0;
3589 }
3590 }
3387 if (!ret) 3591 if (!ret)
3388 ret = write_one_cache_group(trans, root, path, cache); 3592 ret = write_one_cache_group(trans, root, path, cache);
3593
3594 /* if its not on the io list, we need to put the block group */
3595 if (should_put)
3596 btrfs_put_block_group(cache);
3597 }
3598
3599 while (!list_empty(io)) {
3600 cache = list_first_entry(io, struct btrfs_block_group_cache,
3601 io_list);
3602 list_del_init(&cache->io_list);
3603 btrfs_wait_cache_io(root, trans, cache,
3604 &cache->io_ctl, path, cache->key.objectid);
3389 btrfs_put_block_group(cache); 3605 btrfs_put_block_group(cache);
3390 } 3606 }
3391 3607
@@ -3635,19 +3851,21 @@ u64 btrfs_get_alloc_profile(struct btrfs_root *root, int data)
3635 * This will check the space that the inode allocates from to make sure we have 3851 * This will check the space that the inode allocates from to make sure we have
3636 * enough space for bytes. 3852 * enough space for bytes.
3637 */ 3853 */
3638int btrfs_check_data_free_space(struct inode *inode, u64 bytes) 3854int btrfs_check_data_free_space(struct inode *inode, u64 bytes, u64 write_bytes)
3639{ 3855{
3640 struct btrfs_space_info *data_sinfo; 3856 struct btrfs_space_info *data_sinfo;
3641 struct btrfs_root *root = BTRFS_I(inode)->root; 3857 struct btrfs_root *root = BTRFS_I(inode)->root;
3642 struct btrfs_fs_info *fs_info = root->fs_info; 3858 struct btrfs_fs_info *fs_info = root->fs_info;
3643 u64 used; 3859 u64 used;
3644 int ret = 0, committed = 0, alloc_chunk = 1; 3860 int ret = 0;
3861 int need_commit = 2;
3862 int have_pinned_space;
3645 3863
3646 /* make sure bytes are sectorsize aligned */ 3864 /* make sure bytes are sectorsize aligned */
3647 bytes = ALIGN(bytes, root->sectorsize); 3865 bytes = ALIGN(bytes, root->sectorsize);
3648 3866
3649 if (btrfs_is_free_space_inode(inode)) { 3867 if (btrfs_is_free_space_inode(inode)) {
3650 committed = 1; 3868 need_commit = 0;
3651 ASSERT(current->journal_info); 3869 ASSERT(current->journal_info);
3652 } 3870 }
3653 3871
@@ -3669,7 +3887,7 @@ again:
3669 * if we don't have enough free bytes in this space then we need 3887 * if we don't have enough free bytes in this space then we need
3670 * to alloc a new chunk. 3888 * to alloc a new chunk.
3671 */ 3889 */
3672 if (!data_sinfo->full && alloc_chunk) { 3890 if (!data_sinfo->full) {
3673 u64 alloc_target; 3891 u64 alloc_target;
3674 3892
3675 data_sinfo->force_alloc = CHUNK_ALLOC_FORCE; 3893 data_sinfo->force_alloc = CHUNK_ALLOC_FORCE;
@@ -3697,8 +3915,10 @@ alloc:
3697 if (ret < 0) { 3915 if (ret < 0) {
3698 if (ret != -ENOSPC) 3916 if (ret != -ENOSPC)
3699 return ret; 3917 return ret;
3700 else 3918 else {
3919 have_pinned_space = 1;
3701 goto commit_trans; 3920 goto commit_trans;
3921 }
3702 } 3922 }
3703 3923
3704 if (!data_sinfo) 3924 if (!data_sinfo)
@@ -3709,26 +3929,39 @@ alloc:
3709 3929
3710 /* 3930 /*
3711 * If we don't have enough pinned space to deal with this 3931 * If we don't have enough pinned space to deal with this
3712 * allocation don't bother committing the transaction. 3932 * allocation, and no removed chunk in current transaction,
3933 * don't bother committing the transaction.
3713 */ 3934 */
3714 if (percpu_counter_compare(&data_sinfo->total_bytes_pinned, 3935 have_pinned_space = percpu_counter_compare(
3715 bytes) < 0) 3936 &data_sinfo->total_bytes_pinned,
3716 committed = 1; 3937 used + bytes - data_sinfo->total_bytes);
3717 spin_unlock(&data_sinfo->lock); 3938 spin_unlock(&data_sinfo->lock);
3718 3939
3719 /* commit the current transaction and try again */ 3940 /* commit the current transaction and try again */
3720commit_trans: 3941commit_trans:
3721 if (!committed && 3942 if (need_commit &&
3722 !atomic_read(&root->fs_info->open_ioctl_trans)) { 3943 !atomic_read(&root->fs_info->open_ioctl_trans)) {
3723 committed = 1; 3944 need_commit--;
3724 3945
3725 trans = btrfs_join_transaction(root); 3946 trans = btrfs_join_transaction(root);
3726 if (IS_ERR(trans)) 3947 if (IS_ERR(trans))
3727 return PTR_ERR(trans); 3948 return PTR_ERR(trans);
3728 ret = btrfs_commit_transaction(trans, root); 3949 if (have_pinned_space >= 0 ||
3729 if (ret) 3950 trans->transaction->have_free_bgs ||
3730 return ret; 3951 need_commit > 0) {
3731 goto again; 3952 ret = btrfs_commit_transaction(trans, root);
3953 if (ret)
3954 return ret;
3955 /*
3956 * make sure that all running delayed iput are
3957 * done
3958 */
3959 down_write(&root->fs_info->delayed_iput_sem);
3960 up_write(&root->fs_info->delayed_iput_sem);
3961 goto again;
3962 } else {
3963 btrfs_end_transaction(trans, root);
3964 }
3732 } 3965 }
3733 3966
3734 trace_btrfs_space_reservation(root->fs_info, 3967 trace_btrfs_space_reservation(root->fs_info,
@@ -3736,12 +3969,16 @@ commit_trans:
3736 data_sinfo->flags, bytes, 1); 3969 data_sinfo->flags, bytes, 1);
3737 return -ENOSPC; 3970 return -ENOSPC;
3738 } 3971 }
3972 ret = btrfs_qgroup_reserve(root, write_bytes);
3973 if (ret)
3974 goto out;
3739 data_sinfo->bytes_may_use += bytes; 3975 data_sinfo->bytes_may_use += bytes;
3740 trace_btrfs_space_reservation(root->fs_info, "space_info", 3976 trace_btrfs_space_reservation(root->fs_info, "space_info",
3741 data_sinfo->flags, bytes, 1); 3977 data_sinfo->flags, bytes, 1);
3978out:
3742 spin_unlock(&data_sinfo->lock); 3979 spin_unlock(&data_sinfo->lock);
3743 3980
3744 return 0; 3981 return ret;
3745} 3982}
3746 3983
3747/* 3984/*
@@ -4298,8 +4535,13 @@ out:
4298static inline int need_do_async_reclaim(struct btrfs_space_info *space_info, 4535static inline int need_do_async_reclaim(struct btrfs_space_info *space_info,
4299 struct btrfs_fs_info *fs_info, u64 used) 4536 struct btrfs_fs_info *fs_info, u64 used)
4300{ 4537{
4301 return (used >= div_factor_fine(space_info->total_bytes, 98) && 4538 u64 thresh = div_factor_fine(space_info->total_bytes, 98);
4302 !btrfs_fs_closing(fs_info) && 4539
4540 /* If we're just plain full then async reclaim just slows us down. */
4541 if (space_info->bytes_used >= thresh)
4542 return 0;
4543
4544 return (used >= thresh && !btrfs_fs_closing(fs_info) &&
4303 !test_bit(BTRFS_FS_STATE_REMOUNTING, &fs_info->fs_state)); 4545 !test_bit(BTRFS_FS_STATE_REMOUNTING, &fs_info->fs_state));
4304} 4546}
4305 4547
@@ -4354,10 +4596,7 @@ static void btrfs_async_reclaim_metadata_space(struct work_struct *work)
4354 if (!btrfs_need_do_async_reclaim(space_info, fs_info, 4596 if (!btrfs_need_do_async_reclaim(space_info, fs_info,
4355 flush_state)) 4597 flush_state))
4356 return; 4598 return;
4357 } while (flush_state <= COMMIT_TRANS); 4599 } while (flush_state < COMMIT_TRANS);
4358
4359 if (btrfs_need_do_async_reclaim(space_info, fs_info, flush_state))
4360 queue_work(system_unbound_wq, work);
4361} 4600}
4362 4601
4363void btrfs_init_async_reclaim_work(struct work_struct *work) 4602void btrfs_init_async_reclaim_work(struct work_struct *work)
@@ -4700,6 +4939,11 @@ void btrfs_free_block_rsv(struct btrfs_root *root,
4700 kfree(rsv); 4939 kfree(rsv);
4701} 4940}
4702 4941
4942void __btrfs_free_block_rsv(struct btrfs_block_rsv *rsv)
4943{
4944 kfree(rsv);
4945}
4946
4703int btrfs_block_rsv_add(struct btrfs_root *root, 4947int btrfs_block_rsv_add(struct btrfs_root *root,
4704 struct btrfs_block_rsv *block_rsv, u64 num_bytes, 4948 struct btrfs_block_rsv *block_rsv, u64 num_bytes,
4705 enum btrfs_reserve_flush_enum flush) 4949 enum btrfs_reserve_flush_enum flush)
@@ -4812,10 +5056,10 @@ static u64 calc_global_metadata_size(struct btrfs_fs_info *fs_info)
4812 5056
4813 num_bytes = (data_used >> fs_info->sb->s_blocksize_bits) * 5057 num_bytes = (data_used >> fs_info->sb->s_blocksize_bits) *
4814 csum_size * 2; 5058 csum_size * 2;
4815 num_bytes += div64_u64(data_used + meta_used, 50); 5059 num_bytes += div_u64(data_used + meta_used, 50);
4816 5060
4817 if (num_bytes * 3 > meta_used) 5061 if (num_bytes * 3 > meta_used)
4818 num_bytes = div64_u64(meta_used, 3); 5062 num_bytes = div_u64(meta_used, 3);
4819 5063
4820 return ALIGN(num_bytes, fs_info->extent_root->nodesize << 10); 5064 return ALIGN(num_bytes, fs_info->extent_root->nodesize << 10);
4821} 5065}
@@ -4998,8 +5242,6 @@ void btrfs_subvolume_release_metadata(struct btrfs_root *root,
4998 u64 qgroup_reserved) 5242 u64 qgroup_reserved)
4999{ 5243{
5000 btrfs_block_rsv_release(root, rsv, (u64)-1); 5244 btrfs_block_rsv_release(root, rsv, (u64)-1);
5001 if (qgroup_reserved)
5002 btrfs_qgroup_free(root, qgroup_reserved);
5003} 5245}
5004 5246
5005/** 5247/**
@@ -5066,30 +5308,18 @@ static u64 calc_csum_metadata_size(struct inode *inode, u64 num_bytes,
5066 int reserve) 5308 int reserve)
5067{ 5309{
5068 struct btrfs_root *root = BTRFS_I(inode)->root; 5310 struct btrfs_root *root = BTRFS_I(inode)->root;
5069 u64 csum_size; 5311 u64 old_csums, num_csums;
5070 int num_csums_per_leaf;
5071 int num_csums;
5072 int old_csums;
5073 5312
5074 if (BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM && 5313 if (BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM &&
5075 BTRFS_I(inode)->csum_bytes == 0) 5314 BTRFS_I(inode)->csum_bytes == 0)
5076 return 0; 5315 return 0;
5077 5316
5078 old_csums = (int)div64_u64(BTRFS_I(inode)->csum_bytes, root->sectorsize); 5317 old_csums = btrfs_csum_bytes_to_leaves(root, BTRFS_I(inode)->csum_bytes);
5079 if (reserve) 5318 if (reserve)
5080 BTRFS_I(inode)->csum_bytes += num_bytes; 5319 BTRFS_I(inode)->csum_bytes += num_bytes;
5081 else 5320 else
5082 BTRFS_I(inode)->csum_bytes -= num_bytes; 5321 BTRFS_I(inode)->csum_bytes -= num_bytes;
5083 csum_size = BTRFS_LEAF_DATA_SIZE(root) - sizeof(struct btrfs_item); 5322 num_csums = btrfs_csum_bytes_to_leaves(root, BTRFS_I(inode)->csum_bytes);
5084 num_csums_per_leaf = (int)div64_u64(csum_size,
5085 sizeof(struct btrfs_csum_item) +
5086 sizeof(struct btrfs_disk_key));
5087 num_csums = (int)div64_u64(BTRFS_I(inode)->csum_bytes, root->sectorsize);
5088 num_csums = num_csums + num_csums_per_leaf - 1;
5089 num_csums = num_csums / num_csums_per_leaf;
5090
5091 old_csums = old_csums + num_csums_per_leaf - 1;
5092 old_csums = old_csums / num_csums_per_leaf;
5093 5323
5094 /* No change, no need to reserve more */ 5324 /* No change, no need to reserve more */
5095 if (old_csums == num_csums) 5325 if (old_csums == num_csums)
@@ -5163,8 +5393,7 @@ int btrfs_delalloc_reserve_metadata(struct inode *inode, u64 num_bytes)
5163 spin_unlock(&BTRFS_I(inode)->lock); 5393 spin_unlock(&BTRFS_I(inode)->lock);
5164 5394
5165 if (root->fs_info->quota_enabled) { 5395 if (root->fs_info->quota_enabled) {
5166 ret = btrfs_qgroup_reserve(root, num_bytes + 5396 ret = btrfs_qgroup_reserve(root, nr_extents * root->nodesize);
5167 nr_extents * root->nodesize);
5168 if (ret) 5397 if (ret)
5169 goto out_fail; 5398 goto out_fail;
5170 } 5399 }
@@ -5172,8 +5401,7 @@ int btrfs_delalloc_reserve_metadata(struct inode *inode, u64 num_bytes)
5172 ret = reserve_metadata_bytes(root, block_rsv, to_reserve, flush); 5401 ret = reserve_metadata_bytes(root, block_rsv, to_reserve, flush);
5173 if (unlikely(ret)) { 5402 if (unlikely(ret)) {
5174 if (root->fs_info->quota_enabled) 5403 if (root->fs_info->quota_enabled)
5175 btrfs_qgroup_free(root, num_bytes + 5404 btrfs_qgroup_free(root, nr_extents * root->nodesize);
5176 nr_extents * root->nodesize);
5177 goto out_fail; 5405 goto out_fail;
5178 } 5406 }
5179 5407
@@ -5290,10 +5518,6 @@ void btrfs_delalloc_release_metadata(struct inode *inode, u64 num_bytes)
5290 5518
5291 trace_btrfs_space_reservation(root->fs_info, "delalloc", 5519 trace_btrfs_space_reservation(root->fs_info, "delalloc",
5292 btrfs_ino(inode), to_free, 0); 5520 btrfs_ino(inode), to_free, 0);
5293 if (root->fs_info->quota_enabled) {
5294 btrfs_qgroup_free(root, num_bytes +
5295 dropped * root->nodesize);
5296 }
5297 5521
5298 btrfs_block_rsv_release(root, &root->fs_info->delalloc_block_rsv, 5522 btrfs_block_rsv_release(root, &root->fs_info->delalloc_block_rsv,
5299 to_free); 5523 to_free);
@@ -5318,7 +5542,7 @@ int btrfs_delalloc_reserve_space(struct inode *inode, u64 num_bytes)
5318{ 5542{
5319 int ret; 5543 int ret;
5320 5544
5321 ret = btrfs_check_data_free_space(inode, num_bytes); 5545 ret = btrfs_check_data_free_space(inode, num_bytes, num_bytes);
5322 if (ret) 5546 if (ret)
5323 return ret; 5547 return ret;
5324 5548
@@ -5390,14 +5614,6 @@ static int update_block_group(struct btrfs_trans_handle *trans,
5390 if (!alloc && cache->cached == BTRFS_CACHE_NO) 5614 if (!alloc && cache->cached == BTRFS_CACHE_NO)
5391 cache_block_group(cache, 1); 5615 cache_block_group(cache, 1);
5392 5616
5393 spin_lock(&trans->transaction->dirty_bgs_lock);
5394 if (list_empty(&cache->dirty_list)) {
5395 list_add_tail(&cache->dirty_list,
5396 &trans->transaction->dirty_bgs);
5397 btrfs_get_block_group(cache);
5398 }
5399 spin_unlock(&trans->transaction->dirty_bgs_lock);
5400
5401 byte_in_group = bytenr - cache->key.objectid; 5617 byte_in_group = bytenr - cache->key.objectid;
5402 WARN_ON(byte_in_group > cache->key.offset); 5618 WARN_ON(byte_in_group > cache->key.offset);
5403 5619
@@ -5446,6 +5662,16 @@ static int update_block_group(struct btrfs_trans_handle *trans,
5446 spin_unlock(&info->unused_bgs_lock); 5662 spin_unlock(&info->unused_bgs_lock);
5447 } 5663 }
5448 } 5664 }
5665
5666 spin_lock(&trans->transaction->dirty_bgs_lock);
5667 if (list_empty(&cache->dirty_list)) {
5668 list_add_tail(&cache->dirty_list,
5669 &trans->transaction->dirty_bgs);
5670 trans->transaction->num_dirty_bgs++;
5671 btrfs_get_block_group(cache);
5672 }
5673 spin_unlock(&trans->transaction->dirty_bgs_lock);
5674
5449 btrfs_put_block_group(cache); 5675 btrfs_put_block_group(cache);
5450 total -= num_bytes; 5676 total -= num_bytes;
5451 bytenr += num_bytes; 5677 bytenr += num_bytes;
@@ -6956,15 +7182,15 @@ static int __btrfs_free_reserved_extent(struct btrfs_root *root,
6956 return -ENOSPC; 7182 return -ENOSPC;
6957 } 7183 }
6958 7184
6959 if (btrfs_test_opt(root, DISCARD))
6960 ret = btrfs_discard_extent(root, start, len, NULL);
6961
6962 if (pin) 7185 if (pin)
6963 pin_down_extent(root, cache, start, len, 1); 7186 pin_down_extent(root, cache, start, len, 1);
6964 else { 7187 else {
7188 if (btrfs_test_opt(root, DISCARD))
7189 ret = btrfs_discard_extent(root, start, len, NULL);
6965 btrfs_add_free_space(cache, start, len); 7190 btrfs_add_free_space(cache, start, len);
6966 btrfs_update_reserved_bytes(cache, len, RESERVE_FREE, delalloc); 7191 btrfs_update_reserved_bytes(cache, len, RESERVE_FREE, delalloc);
6967 } 7192 }
7193
6968 btrfs_put_block_group(cache); 7194 btrfs_put_block_group(cache);
6969 7195
6970 trace_btrfs_reserved_extent_free(root, start, len); 7196 trace_btrfs_reserved_extent_free(root, start, len);
@@ -7095,9 +7321,9 @@ static int alloc_reserved_tree_block(struct btrfs_trans_handle *trans,
7095 ret = btrfs_insert_empty_item(trans, fs_info->extent_root, path, 7321 ret = btrfs_insert_empty_item(trans, fs_info->extent_root, path,
7096 ins, size); 7322 ins, size);
7097 if (ret) { 7323 if (ret) {
7324 btrfs_free_path(path);
7098 btrfs_free_and_pin_reserved_extent(root, ins->objectid, 7325 btrfs_free_and_pin_reserved_extent(root, ins->objectid,
7099 root->nodesize); 7326 root->nodesize);
7100 btrfs_free_path(path);
7101 return ret; 7327 return ret;
7102 } 7328 }
7103 7329
@@ -7217,7 +7443,7 @@ btrfs_init_new_buffer(struct btrfs_trans_handle *trans, struct btrfs_root *root,
7217 btrfs_set_header_generation(buf, trans->transid); 7443 btrfs_set_header_generation(buf, trans->transid);
7218 btrfs_set_buffer_lockdep_class(root->root_key.objectid, buf, level); 7444 btrfs_set_buffer_lockdep_class(root->root_key.objectid, buf, level);
7219 btrfs_tree_lock(buf); 7445 btrfs_tree_lock(buf);
7220 clean_tree_block(trans, root, buf); 7446 clean_tree_block(trans, root->fs_info, buf);
7221 clear_bit(EXTENT_BUFFER_STALE, &buf->bflags); 7447 clear_bit(EXTENT_BUFFER_STALE, &buf->bflags);
7222 7448
7223 btrfs_set_lock_blocking(buf); 7449 btrfs_set_lock_blocking(buf);
@@ -7815,7 +8041,7 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans,
7815 bytenr = btrfs_node_blockptr(path->nodes[level], path->slots[level]); 8041 bytenr = btrfs_node_blockptr(path->nodes[level], path->slots[level]);
7816 blocksize = root->nodesize; 8042 blocksize = root->nodesize;
7817 8043
7818 next = btrfs_find_tree_block(root, bytenr); 8044 next = btrfs_find_tree_block(root->fs_info, bytenr);
7819 if (!next) { 8045 if (!next) {
7820 next = btrfs_find_create_tree_block(root, bytenr); 8046 next = btrfs_find_create_tree_block(root, bytenr);
7821 if (!next) 8047 if (!next)
@@ -8016,7 +8242,7 @@ static noinline int walk_up_proc(struct btrfs_trans_handle *trans,
8016 btrfs_set_lock_blocking(eb); 8242 btrfs_set_lock_blocking(eb);
8017 path->locks[level] = BTRFS_WRITE_LOCK_BLOCKING; 8243 path->locks[level] = BTRFS_WRITE_LOCK_BLOCKING;
8018 } 8244 }
8019 clean_tree_block(trans, root, eb); 8245 clean_tree_block(trans, root->fs_info, eb);
8020 } 8246 }
8021 8247
8022 if (eb == root->node) { 8248 if (eb == root->node) {
@@ -8533,10 +8759,30 @@ int btrfs_set_block_group_ro(struct btrfs_root *root,
8533 8759
8534 BUG_ON(cache->ro); 8760 BUG_ON(cache->ro);
8535 8761
8762again:
8536 trans = btrfs_join_transaction(root); 8763 trans = btrfs_join_transaction(root);
8537 if (IS_ERR(trans)) 8764 if (IS_ERR(trans))
8538 return PTR_ERR(trans); 8765 return PTR_ERR(trans);
8539 8766
8767 /*
8768 * we're not allowed to set block groups readonly after the dirty
8769 * block groups cache has started writing. If it already started,
8770 * back off and let this transaction commit
8771 */
8772 mutex_lock(&root->fs_info->ro_block_group_mutex);
8773 if (trans->transaction->dirty_bg_run) {
8774 u64 transid = trans->transid;
8775
8776 mutex_unlock(&root->fs_info->ro_block_group_mutex);
8777 btrfs_end_transaction(trans, root);
8778
8779 ret = btrfs_wait_for_commit(root, transid);
8780 if (ret)
8781 return ret;
8782 goto again;
8783 }
8784
8785
8540 ret = set_block_group_ro(cache, 0); 8786 ret = set_block_group_ro(cache, 0);
8541 if (!ret) 8787 if (!ret)
8542 goto out; 8788 goto out;
@@ -8551,6 +8797,7 @@ out:
8551 alloc_flags = update_block_group_flags(root, cache->flags); 8797 alloc_flags = update_block_group_flags(root, cache->flags);
8552 check_system_chunk(trans, root, alloc_flags); 8798 check_system_chunk(trans, root, alloc_flags);
8553 } 8799 }
8800 mutex_unlock(&root->fs_info->ro_block_group_mutex);
8554 8801
8555 btrfs_end_transaction(trans, root); 8802 btrfs_end_transaction(trans, root);
8556 return ret; 8803 return ret;
@@ -8720,7 +8967,7 @@ int btrfs_can_relocate(struct btrfs_root *root, u64 bytenr)
8720 min_free <<= 1; 8967 min_free <<= 1;
8721 } else if (index == BTRFS_RAID_RAID0) { 8968 } else if (index == BTRFS_RAID_RAID0) {
8722 dev_min = fs_devices->rw_devices; 8969 dev_min = fs_devices->rw_devices;
8723 do_div(min_free, dev_min); 8970 min_free = div64_u64(min_free, dev_min);
8724 } 8971 }
8725 8972
8726 /* We need to do this so that we can look at pending chunks */ 8973 /* We need to do this so that we can look at pending chunks */
@@ -8992,6 +9239,7 @@ btrfs_create_block_group_cache(struct btrfs_root *root, u64 start, u64 size)
8992 INIT_LIST_HEAD(&cache->bg_list); 9239 INIT_LIST_HEAD(&cache->bg_list);
8993 INIT_LIST_HEAD(&cache->ro_list); 9240 INIT_LIST_HEAD(&cache->ro_list);
8994 INIT_LIST_HEAD(&cache->dirty_list); 9241 INIT_LIST_HEAD(&cache->dirty_list);
9242 INIT_LIST_HEAD(&cache->io_list);
8995 btrfs_init_free_space_ctl(cache); 9243 btrfs_init_free_space_ctl(cache);
8996 atomic_set(&cache->trimming, 0); 9244 atomic_set(&cache->trimming, 0);
8997 9245
@@ -9355,7 +9603,38 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans,
9355 goto out; 9603 goto out;
9356 } 9604 }
9357 9605
9606 /*
9607 * get the inode first so any iput calls done for the io_list
9608 * aren't the final iput (no unlinks allowed now)
9609 */
9358 inode = lookup_free_space_inode(tree_root, block_group, path); 9610 inode = lookup_free_space_inode(tree_root, block_group, path);
9611
9612 mutex_lock(&trans->transaction->cache_write_mutex);
9613 /*
9614 * make sure our free spache cache IO is done before remove the
9615 * free space inode
9616 */
9617 spin_lock(&trans->transaction->dirty_bgs_lock);
9618 if (!list_empty(&block_group->io_list)) {
9619 list_del_init(&block_group->io_list);
9620
9621 WARN_ON(!IS_ERR(inode) && inode != block_group->io_ctl.inode);
9622
9623 spin_unlock(&trans->transaction->dirty_bgs_lock);
9624 btrfs_wait_cache_io(root, trans, block_group,
9625 &block_group->io_ctl, path,
9626 block_group->key.objectid);
9627 btrfs_put_block_group(block_group);
9628 spin_lock(&trans->transaction->dirty_bgs_lock);
9629 }
9630
9631 if (!list_empty(&block_group->dirty_list)) {
9632 list_del_init(&block_group->dirty_list);
9633 btrfs_put_block_group(block_group);
9634 }
9635 spin_unlock(&trans->transaction->dirty_bgs_lock);
9636 mutex_unlock(&trans->transaction->cache_write_mutex);
9637
9359 if (!IS_ERR(inode)) { 9638 if (!IS_ERR(inode)) {
9360 ret = btrfs_orphan_add(trans, inode); 9639 ret = btrfs_orphan_add(trans, inode);
9361 if (ret) { 9640 if (ret) {
@@ -9448,18 +9727,29 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans,
9448 9727
9449 spin_lock(&trans->transaction->dirty_bgs_lock); 9728 spin_lock(&trans->transaction->dirty_bgs_lock);
9450 if (!list_empty(&block_group->dirty_list)) { 9729 if (!list_empty(&block_group->dirty_list)) {
9451 list_del_init(&block_group->dirty_list); 9730 WARN_ON(1);
9452 btrfs_put_block_group(block_group); 9731 }
9732 if (!list_empty(&block_group->io_list)) {
9733 WARN_ON(1);
9453 } 9734 }
9454 spin_unlock(&trans->transaction->dirty_bgs_lock); 9735 spin_unlock(&trans->transaction->dirty_bgs_lock);
9455
9456 btrfs_remove_free_space_cache(block_group); 9736 btrfs_remove_free_space_cache(block_group);
9457 9737
9458 spin_lock(&block_group->space_info->lock); 9738 spin_lock(&block_group->space_info->lock);
9459 list_del_init(&block_group->ro_list); 9739 list_del_init(&block_group->ro_list);
9740
9741 if (btrfs_test_opt(root, ENOSPC_DEBUG)) {
9742 WARN_ON(block_group->space_info->total_bytes
9743 < block_group->key.offset);
9744 WARN_ON(block_group->space_info->bytes_readonly
9745 < block_group->key.offset);
9746 WARN_ON(block_group->space_info->disk_total
9747 < block_group->key.offset * factor);
9748 }
9460 block_group->space_info->total_bytes -= block_group->key.offset; 9749 block_group->space_info->total_bytes -= block_group->key.offset;
9461 block_group->space_info->bytes_readonly -= block_group->key.offset; 9750 block_group->space_info->bytes_readonly -= block_group->key.offset;
9462 block_group->space_info->disk_total -= block_group->key.offset * factor; 9751 block_group->space_info->disk_total -= block_group->key.offset * factor;
9752
9463 spin_unlock(&block_group->space_info->lock); 9753 spin_unlock(&block_group->space_info->lock);
9464 9754
9465 memcpy(&key, &block_group->key, sizeof(key)); 9755 memcpy(&key, &block_group->key, sizeof(key));
@@ -9647,8 +9937,18 @@ void btrfs_delete_unused_bgs(struct btrfs_fs_info *fs_info)
9647 mutex_unlock(&fs_info->unused_bg_unpin_mutex); 9937 mutex_unlock(&fs_info->unused_bg_unpin_mutex);
9648 9938
9649 /* Reset pinned so btrfs_put_block_group doesn't complain */ 9939 /* Reset pinned so btrfs_put_block_group doesn't complain */
9940 spin_lock(&space_info->lock);
9941 spin_lock(&block_group->lock);
9942
9943 space_info->bytes_pinned -= block_group->pinned;
9944 space_info->bytes_readonly += block_group->pinned;
9945 percpu_counter_add(&space_info->total_bytes_pinned,
9946 -block_group->pinned);
9650 block_group->pinned = 0; 9947 block_group->pinned = 0;
9651 9948
9949 spin_unlock(&block_group->lock);
9950 spin_unlock(&space_info->lock);
9951
9652 /* 9952 /*
9653 * Btrfs_remove_chunk will abort the transaction if things go 9953 * Btrfs_remove_chunk will abort the transaction if things go
9654 * horribly wrong. 9954 * horribly wrong.
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index d688cfe5d496..782f3bc4651d 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -4514,8 +4514,11 @@ int extent_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
4514 } 4514 }
4515 ret = fiemap_fill_next_extent(fieinfo, em_start, disko, 4515 ret = fiemap_fill_next_extent(fieinfo, em_start, disko,
4516 em_len, flags); 4516 em_len, flags);
4517 if (ret) 4517 if (ret) {
4518 if (ret == 1)
4519 ret = 0;
4518 goto out_free; 4520 goto out_free;
4521 }
4519 } 4522 }
4520out_free: 4523out_free:
4521 free_extent_map(em); 4524 free_extent_map(em);
diff --git a/fs/btrfs/extent_io.h b/fs/btrfs/extent_io.h
index 695b0ccfb755..c668f36898d3 100644
--- a/fs/btrfs/extent_io.h
+++ b/fs/btrfs/extent_io.h
@@ -97,7 +97,7 @@ struct extent_io_tree {
97 u64 dirty_bytes; 97 u64 dirty_bytes;
98 int track_uptodate; 98 int track_uptodate;
99 spinlock_t lock; 99 spinlock_t lock;
100 struct extent_io_ops *ops; 100 const struct extent_io_ops *ops;
101}; 101};
102 102
103struct extent_state { 103struct extent_state {
diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c
index 84a2d1868271..58ece6558430 100644
--- a/fs/btrfs/file-item.c
+++ b/fs/btrfs/file-item.c
@@ -185,8 +185,8 @@ static int __btrfs_lookup_bio_sums(struct btrfs_root *root,
185 nblocks = bio->bi_iter.bi_size >> inode->i_sb->s_blocksize_bits; 185 nblocks = bio->bi_iter.bi_size >> inode->i_sb->s_blocksize_bits;
186 if (!dst) { 186 if (!dst) {
187 if (nblocks * csum_size > BTRFS_BIO_INLINE_CSUM_SIZE) { 187 if (nblocks * csum_size > BTRFS_BIO_INLINE_CSUM_SIZE) {
188 btrfs_bio->csum_allocated = kmalloc(nblocks * csum_size, 188 btrfs_bio->csum_allocated = kmalloc_array(nblocks,
189 GFP_NOFS); 189 csum_size, GFP_NOFS);
190 if (!btrfs_bio->csum_allocated) { 190 if (!btrfs_bio->csum_allocated) {
191 btrfs_free_path(path); 191 btrfs_free_path(path);
192 return -ENOMEM; 192 return -ENOMEM;
@@ -553,7 +553,7 @@ static noinline void truncate_one_csum(struct btrfs_root *root,
553 btrfs_truncate_item(root, path, new_size, 0); 553 btrfs_truncate_item(root, path, new_size, 0);
554 554
555 key->offset = end_byte; 555 key->offset = end_byte;
556 btrfs_set_item_key_safe(root, path, key); 556 btrfs_set_item_key_safe(root->fs_info, path, key);
557 } else { 557 } else {
558 BUG(); 558 BUG();
559 } 559 }
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index faa7d390841b..b072e17479aa 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -273,11 +273,7 @@ void btrfs_cleanup_defrag_inodes(struct btrfs_fs_info *fs_info)
273 defrag = rb_entry(node, struct inode_defrag, rb_node); 273 defrag = rb_entry(node, struct inode_defrag, rb_node);
274 kmem_cache_free(btrfs_inode_defrag_cachep, defrag); 274 kmem_cache_free(btrfs_inode_defrag_cachep, defrag);
275 275
276 if (need_resched()) { 276 cond_resched_lock(&fs_info->defrag_inodes_lock);
277 spin_unlock(&fs_info->defrag_inodes_lock);
278 cond_resched();
279 spin_lock(&fs_info->defrag_inodes_lock);
280 }
281 277
282 node = rb_first(&fs_info->defrag_inodes); 278 node = rb_first(&fs_info->defrag_inodes);
283 } 279 }
@@ -868,7 +864,7 @@ next_slot:
868 864
869 memcpy(&new_key, &key, sizeof(new_key)); 865 memcpy(&new_key, &key, sizeof(new_key));
870 new_key.offset = end; 866 new_key.offset = end;
871 btrfs_set_item_key_safe(root, path, &new_key); 867 btrfs_set_item_key_safe(root->fs_info, path, &new_key);
872 868
873 extent_offset += end - key.offset; 869 extent_offset += end - key.offset;
874 btrfs_set_file_extent_offset(leaf, fi, extent_offset); 870 btrfs_set_file_extent_offset(leaf, fi, extent_offset);
@@ -1126,7 +1122,7 @@ again:
1126 ino, bytenr, orig_offset, 1122 ino, bytenr, orig_offset,
1127 &other_start, &other_end)) { 1123 &other_start, &other_end)) {
1128 new_key.offset = end; 1124 new_key.offset = end;
1129 btrfs_set_item_key_safe(root, path, &new_key); 1125 btrfs_set_item_key_safe(root->fs_info, path, &new_key);
1130 fi = btrfs_item_ptr(leaf, path->slots[0], 1126 fi = btrfs_item_ptr(leaf, path->slots[0],
1131 struct btrfs_file_extent_item); 1127 struct btrfs_file_extent_item);
1132 btrfs_set_file_extent_generation(leaf, fi, 1128 btrfs_set_file_extent_generation(leaf, fi,
@@ -1160,7 +1156,7 @@ again:
1160 trans->transid); 1156 trans->transid);
1161 path->slots[0]++; 1157 path->slots[0]++;
1162 new_key.offset = start; 1158 new_key.offset = start;
1163 btrfs_set_item_key_safe(root, path, &new_key); 1159 btrfs_set_item_key_safe(root->fs_info, path, &new_key);
1164 1160
1165 fi = btrfs_item_ptr(leaf, path->slots[0], 1161 fi = btrfs_item_ptr(leaf, path->slots[0],
1166 struct btrfs_file_extent_item); 1162 struct btrfs_file_extent_item);
@@ -1485,7 +1481,7 @@ static noinline ssize_t __btrfs_buffered_write(struct file *file,
1485 PAGE_CACHE_SIZE / (sizeof(struct page *))); 1481 PAGE_CACHE_SIZE / (sizeof(struct page *)));
1486 nrptrs = min(nrptrs, current->nr_dirtied_pause - current->nr_dirtied); 1482 nrptrs = min(nrptrs, current->nr_dirtied_pause - current->nr_dirtied);
1487 nrptrs = max(nrptrs, 8); 1483 nrptrs = max(nrptrs, 8);
1488 pages = kmalloc(nrptrs * sizeof(struct page *), GFP_KERNEL); 1484 pages = kmalloc_array(nrptrs, sizeof(struct page *), GFP_KERNEL);
1489 if (!pages) 1485 if (!pages)
1490 return -ENOMEM; 1486 return -ENOMEM;
1491 1487
@@ -1514,7 +1510,7 @@ static noinline ssize_t __btrfs_buffered_write(struct file *file,
1514 } 1510 }
1515 1511
1516 reserve_bytes = num_pages << PAGE_CACHE_SHIFT; 1512 reserve_bytes = num_pages << PAGE_CACHE_SHIFT;
1517 ret = btrfs_check_data_free_space(inode, reserve_bytes); 1513 ret = btrfs_check_data_free_space(inode, reserve_bytes, write_bytes);
1518 if (ret == -ENOSPC && 1514 if (ret == -ENOSPC &&
1519 (BTRFS_I(inode)->flags & (BTRFS_INODE_NODATACOW | 1515 (BTRFS_I(inode)->flags & (BTRFS_INODE_NODATACOW |
1520 BTRFS_INODE_PREALLOC))) { 1516 BTRFS_INODE_PREALLOC))) {
@@ -1635,8 +1631,8 @@ again:
1635 btrfs_end_write_no_snapshoting(root); 1631 btrfs_end_write_no_snapshoting(root);
1636 1632
1637 if (only_release_metadata && copied > 0) { 1633 if (only_release_metadata && copied > 0) {
1638 u64 lockstart = round_down(pos, root->sectorsize); 1634 lockstart = round_down(pos, root->sectorsize);
1639 u64 lockend = lockstart + 1635 lockend = lockstart +
1640 (dirty_pages << PAGE_CACHE_SHIFT) - 1; 1636 (dirty_pages << PAGE_CACHE_SHIFT) - 1;
1641 1637
1642 set_extent_bit(&BTRFS_I(inode)->io_tree, lockstart, 1638 set_extent_bit(&BTRFS_I(inode)->io_tree, lockstart,
@@ -1809,7 +1805,9 @@ static ssize_t btrfs_file_write_iter(struct kiocb *iocb,
1809 * otherwise subsequent syncs to a file that's been synced in this 1805 * otherwise subsequent syncs to a file that's been synced in this
1810 * transaction will appear to have already occured. 1806 * transaction will appear to have already occured.
1811 */ 1807 */
1808 spin_lock(&BTRFS_I(inode)->lock);
1812 BTRFS_I(inode)->last_sub_trans = root->log_transid; 1809 BTRFS_I(inode)->last_sub_trans = root->log_transid;
1810 spin_unlock(&BTRFS_I(inode)->lock);
1813 if (num_written > 0) { 1811 if (num_written > 0) {
1814 err = generic_write_sync(file, pos, num_written); 1812 err = generic_write_sync(file, pos, num_written);
1815 if (err < 0) 1813 if (err < 0)
@@ -1864,7 +1862,7 @@ static int start_ordered_ops(struct inode *inode, loff_t start, loff_t end)
1864int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync) 1862int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
1865{ 1863{
1866 struct dentry *dentry = file->f_path.dentry; 1864 struct dentry *dentry = file->f_path.dentry;
1867 struct inode *inode = dentry->d_inode; 1865 struct inode *inode = d_inode(dentry);
1868 struct btrfs_root *root = BTRFS_I(inode)->root; 1866 struct btrfs_root *root = BTRFS_I(inode)->root;
1869 struct btrfs_trans_handle *trans; 1867 struct btrfs_trans_handle *trans;
1870 struct btrfs_log_ctx ctx; 1868 struct btrfs_log_ctx ctx;
@@ -2162,7 +2160,7 @@ static int fill_holes(struct btrfs_trans_handle *trans, struct inode *inode,
2162 u64 num_bytes; 2160 u64 num_bytes;
2163 2161
2164 key.offset = offset; 2162 key.offset = offset;
2165 btrfs_set_item_key_safe(root, path, &key); 2163 btrfs_set_item_key_safe(root->fs_info, path, &key);
2166 fi = btrfs_item_ptr(leaf, path->slots[0], 2164 fi = btrfs_item_ptr(leaf, path->slots[0],
2167 struct btrfs_file_extent_item); 2165 struct btrfs_file_extent_item);
2168 num_bytes = btrfs_file_extent_num_bytes(leaf, fi) + end - 2166 num_bytes = btrfs_file_extent_num_bytes(leaf, fi) + end -
@@ -2545,7 +2543,6 @@ static long btrfs_fallocate(struct file *file, int mode,
2545{ 2543{
2546 struct inode *inode = file_inode(file); 2544 struct inode *inode = file_inode(file);
2547 struct extent_state *cached_state = NULL; 2545 struct extent_state *cached_state = NULL;
2548 struct btrfs_root *root = BTRFS_I(inode)->root;
2549 u64 cur_offset; 2546 u64 cur_offset;
2550 u64 last_byte; 2547 u64 last_byte;
2551 u64 alloc_start; 2548 u64 alloc_start;
@@ -2570,14 +2567,9 @@ static long btrfs_fallocate(struct file *file, int mode,
2570 * Make sure we have enough space before we do the 2567 * Make sure we have enough space before we do the
2571 * allocation. 2568 * allocation.
2572 */ 2569 */
2573 ret = btrfs_check_data_free_space(inode, alloc_end - alloc_start); 2570 ret = btrfs_check_data_free_space(inode, alloc_end - alloc_start, alloc_end - alloc_start);
2574 if (ret) 2571 if (ret)
2575 return ret; 2572 return ret;
2576 if (root->fs_info->quota_enabled) {
2577 ret = btrfs_qgroup_reserve(root, alloc_end - alloc_start);
2578 if (ret)
2579 goto out_reserve_fail;
2580 }
2581 2573
2582 mutex_lock(&inode->i_mutex); 2574 mutex_lock(&inode->i_mutex);
2583 ret = inode_newsize_ok(inode, alloc_end); 2575 ret = inode_newsize_ok(inode, alloc_end);
@@ -2667,23 +2659,35 @@ static long btrfs_fallocate(struct file *file, int mode,
2667 1 << inode->i_blkbits, 2659 1 << inode->i_blkbits,
2668 offset + len, 2660 offset + len,
2669 &alloc_hint); 2661 &alloc_hint);
2670
2671 if (ret < 0) {
2672 free_extent_map(em);
2673 break;
2674 }
2675 } else if (actual_end > inode->i_size && 2662 } else if (actual_end > inode->i_size &&
2676 !(mode & FALLOC_FL_KEEP_SIZE)) { 2663 !(mode & FALLOC_FL_KEEP_SIZE)) {
2664 struct btrfs_trans_handle *trans;
2665 struct btrfs_root *root = BTRFS_I(inode)->root;
2666
2677 /* 2667 /*
2678 * We didn't need to allocate any more space, but we 2668 * We didn't need to allocate any more space, but we
2679 * still extended the size of the file so we need to 2669 * still extended the size of the file so we need to
2680 * update i_size. 2670 * update i_size and the inode item.
2681 */ 2671 */
2682 inode->i_ctime = CURRENT_TIME; 2672 trans = btrfs_start_transaction(root, 1);
2683 i_size_write(inode, actual_end); 2673 if (IS_ERR(trans)) {
2684 btrfs_ordered_update_i_size(inode, actual_end, NULL); 2674 ret = PTR_ERR(trans);
2675 } else {
2676 inode->i_ctime = CURRENT_TIME;
2677 i_size_write(inode, actual_end);
2678 btrfs_ordered_update_i_size(inode, actual_end,
2679 NULL);
2680 ret = btrfs_update_inode(trans, root, inode);
2681 if (ret)
2682 btrfs_end_transaction(trans, root);
2683 else
2684 ret = btrfs_end_transaction(trans,
2685 root);
2686 }
2685 } 2687 }
2686 free_extent_map(em); 2688 free_extent_map(em);
2689 if (ret < 0)
2690 break;
2687 2691
2688 cur_offset = last_byte; 2692 cur_offset = last_byte;
2689 if (cur_offset >= alloc_end) { 2693 if (cur_offset >= alloc_end) {
@@ -2695,9 +2699,6 @@ static long btrfs_fallocate(struct file *file, int mode,
2695 &cached_state, GFP_NOFS); 2699 &cached_state, GFP_NOFS);
2696out: 2700out:
2697 mutex_unlock(&inode->i_mutex); 2701 mutex_unlock(&inode->i_mutex);
2698 if (root->fs_info->quota_enabled)
2699 btrfs_qgroup_free(root, alloc_end - alloc_start);
2700out_reserve_fail:
2701 /* Let go of our reservation. */ 2702 /* Let go of our reservation. */
2702 btrfs_free_reserved_data_space(inode, alloc_end - alloc_start); 2703 btrfs_free_reserved_data_space(inode, alloc_end - alloc_start);
2703 return ret; 2704 return ret;
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
index a71978578fa7..81fa75a8e1f3 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
@@ -85,7 +85,8 @@ static struct inode *__lookup_free_space_inode(struct btrfs_root *root,
85 } 85 }
86 86
87 mapping_set_gfp_mask(inode->i_mapping, 87 mapping_set_gfp_mask(inode->i_mapping,
88 mapping_gfp_mask(inode->i_mapping) & ~__GFP_FS); 88 mapping_gfp_mask(inode->i_mapping) &
89 ~(GFP_NOFS & ~__GFP_HIGHMEM));
89 90
90 return inode; 91 return inode;
91} 92}
@@ -170,13 +171,13 @@ static int __create_free_space_inode(struct btrfs_root *root,
170 key.objectid = BTRFS_FREE_SPACE_OBJECTID; 171 key.objectid = BTRFS_FREE_SPACE_OBJECTID;
171 key.offset = offset; 172 key.offset = offset;
172 key.type = 0; 173 key.type = 0;
173
174 ret = btrfs_insert_empty_item(trans, root, path, &key, 174 ret = btrfs_insert_empty_item(trans, root, path, &key,
175 sizeof(struct btrfs_free_space_header)); 175 sizeof(struct btrfs_free_space_header));
176 if (ret < 0) { 176 if (ret < 0) {
177 btrfs_release_path(path); 177 btrfs_release_path(path);
178 return ret; 178 return ret;
179 } 179 }
180
180 leaf = path->nodes[0]; 181 leaf = path->nodes[0];
181 header = btrfs_item_ptr(leaf, path->slots[0], 182 header = btrfs_item_ptr(leaf, path->slots[0],
182 struct btrfs_free_space_header); 183 struct btrfs_free_space_header);
@@ -225,9 +226,37 @@ int btrfs_check_trunc_cache_free_space(struct btrfs_root *root,
225 226
226int btrfs_truncate_free_space_cache(struct btrfs_root *root, 227int btrfs_truncate_free_space_cache(struct btrfs_root *root,
227 struct btrfs_trans_handle *trans, 228 struct btrfs_trans_handle *trans,
229 struct btrfs_block_group_cache *block_group,
228 struct inode *inode) 230 struct inode *inode)
229{ 231{
230 int ret = 0; 232 int ret = 0;
233 struct btrfs_path *path = btrfs_alloc_path();
234
235 if (!path) {
236 ret = -ENOMEM;
237 goto fail;
238 }
239
240 if (block_group) {
241 mutex_lock(&trans->transaction->cache_write_mutex);
242 if (!list_empty(&block_group->io_list)) {
243 list_del_init(&block_group->io_list);
244
245 btrfs_wait_cache_io(root, trans, block_group,
246 &block_group->io_ctl, path,
247 block_group->key.objectid);
248 btrfs_put_block_group(block_group);
249 }
250
251 /*
252 * now that we've truncated the cache away, its no longer
253 * setup or written
254 */
255 spin_lock(&block_group->lock);
256 block_group->disk_cache_state = BTRFS_DC_CLEAR;
257 spin_unlock(&block_group->lock);
258 }
259 btrfs_free_path(path);
231 260
232 btrfs_i_size_write(inode, 0); 261 btrfs_i_size_write(inode, 0);
233 truncate_pagecache(inode, 0); 262 truncate_pagecache(inode, 0);
@@ -235,15 +264,23 @@ int btrfs_truncate_free_space_cache(struct btrfs_root *root,
235 /* 264 /*
236 * We don't need an orphan item because truncating the free space cache 265 * We don't need an orphan item because truncating the free space cache
237 * will never be split across transactions. 266 * will never be split across transactions.
267 * We don't need to check for -EAGAIN because we're a free space
268 * cache inode
238 */ 269 */
239 ret = btrfs_truncate_inode_items(trans, root, inode, 270 ret = btrfs_truncate_inode_items(trans, root, inode,
240 0, BTRFS_EXTENT_DATA_KEY); 271 0, BTRFS_EXTENT_DATA_KEY);
241 if (ret) { 272 if (ret) {
273 mutex_unlock(&trans->transaction->cache_write_mutex);
242 btrfs_abort_transaction(trans, root, ret); 274 btrfs_abort_transaction(trans, root, ret);
243 return ret; 275 return ret;
244 } 276 }
245 277
246 ret = btrfs_update_inode(trans, root, inode); 278 ret = btrfs_update_inode(trans, root, inode);
279
280 if (block_group)
281 mutex_unlock(&trans->transaction->cache_write_mutex);
282
283fail:
247 if (ret) 284 if (ret)
248 btrfs_abort_transaction(trans, root, ret); 285 btrfs_abort_transaction(trans, root, ret);
249 286
@@ -269,18 +306,7 @@ static int readahead_cache(struct inode *inode)
269 return 0; 306 return 0;
270} 307}
271 308
272struct io_ctl { 309static int io_ctl_init(struct btrfs_io_ctl *io_ctl, struct inode *inode,
273 void *cur, *orig;
274 struct page *page;
275 struct page **pages;
276 struct btrfs_root *root;
277 unsigned long size;
278 int index;
279 int num_pages;
280 unsigned check_crcs:1;
281};
282
283static int io_ctl_init(struct io_ctl *io_ctl, struct inode *inode,
284 struct btrfs_root *root, int write) 310 struct btrfs_root *root, int write)
285{ 311{
286 int num_pages; 312 int num_pages;
@@ -296,45 +322,46 @@ static int io_ctl_init(struct io_ctl *io_ctl, struct inode *inode,
296 (num_pages * sizeof(u32)) >= PAGE_CACHE_SIZE) 322 (num_pages * sizeof(u32)) >= PAGE_CACHE_SIZE)
297 return -ENOSPC; 323 return -ENOSPC;
298 324
299 memset(io_ctl, 0, sizeof(struct io_ctl)); 325 memset(io_ctl, 0, sizeof(struct btrfs_io_ctl));
300 326
301 io_ctl->pages = kzalloc(sizeof(struct page *) * num_pages, GFP_NOFS); 327 io_ctl->pages = kcalloc(num_pages, sizeof(struct page *), GFP_NOFS);
302 if (!io_ctl->pages) 328 if (!io_ctl->pages)
303 return -ENOMEM; 329 return -ENOMEM;
304 330
305 io_ctl->num_pages = num_pages; 331 io_ctl->num_pages = num_pages;
306 io_ctl->root = root; 332 io_ctl->root = root;
307 io_ctl->check_crcs = check_crcs; 333 io_ctl->check_crcs = check_crcs;
334 io_ctl->inode = inode;
308 335
309 return 0; 336 return 0;
310} 337}
311 338
312static void io_ctl_free(struct io_ctl *io_ctl) 339static void io_ctl_free(struct btrfs_io_ctl *io_ctl)
313{ 340{
314 kfree(io_ctl->pages); 341 kfree(io_ctl->pages);
342 io_ctl->pages = NULL;
315} 343}
316 344
317static void io_ctl_unmap_page(struct io_ctl *io_ctl) 345static void io_ctl_unmap_page(struct btrfs_io_ctl *io_ctl)
318{ 346{
319 if (io_ctl->cur) { 347 if (io_ctl->cur) {
320 kunmap(io_ctl->page);
321 io_ctl->cur = NULL; 348 io_ctl->cur = NULL;
322 io_ctl->orig = NULL; 349 io_ctl->orig = NULL;
323 } 350 }
324} 351}
325 352
326static void io_ctl_map_page(struct io_ctl *io_ctl, int clear) 353static void io_ctl_map_page(struct btrfs_io_ctl *io_ctl, int clear)
327{ 354{
328 ASSERT(io_ctl->index < io_ctl->num_pages); 355 ASSERT(io_ctl->index < io_ctl->num_pages);
329 io_ctl->page = io_ctl->pages[io_ctl->index++]; 356 io_ctl->page = io_ctl->pages[io_ctl->index++];
330 io_ctl->cur = kmap(io_ctl->page); 357 io_ctl->cur = page_address(io_ctl->page);
331 io_ctl->orig = io_ctl->cur; 358 io_ctl->orig = io_ctl->cur;
332 io_ctl->size = PAGE_CACHE_SIZE; 359 io_ctl->size = PAGE_CACHE_SIZE;
333 if (clear) 360 if (clear)
334 memset(io_ctl->cur, 0, PAGE_CACHE_SIZE); 361 memset(io_ctl->cur, 0, PAGE_CACHE_SIZE);
335} 362}
336 363
337static void io_ctl_drop_pages(struct io_ctl *io_ctl) 364static void io_ctl_drop_pages(struct btrfs_io_ctl *io_ctl)
338{ 365{
339 int i; 366 int i;
340 367
@@ -349,7 +376,7 @@ static void io_ctl_drop_pages(struct io_ctl *io_ctl)
349 } 376 }
350} 377}
351 378
352static int io_ctl_prepare_pages(struct io_ctl *io_ctl, struct inode *inode, 379static int io_ctl_prepare_pages(struct btrfs_io_ctl *io_ctl, struct inode *inode,
353 int uptodate) 380 int uptodate)
354{ 381{
355 struct page *page; 382 struct page *page;
@@ -383,7 +410,7 @@ static int io_ctl_prepare_pages(struct io_ctl *io_ctl, struct inode *inode,
383 return 0; 410 return 0;
384} 411}
385 412
386static void io_ctl_set_generation(struct io_ctl *io_ctl, u64 generation) 413static void io_ctl_set_generation(struct btrfs_io_ctl *io_ctl, u64 generation)
387{ 414{
388 __le64 *val; 415 __le64 *val;
389 416
@@ -406,7 +433,7 @@ static void io_ctl_set_generation(struct io_ctl *io_ctl, u64 generation)
406 io_ctl->cur += sizeof(u64); 433 io_ctl->cur += sizeof(u64);
407} 434}
408 435
409static int io_ctl_check_generation(struct io_ctl *io_ctl, u64 generation) 436static int io_ctl_check_generation(struct btrfs_io_ctl *io_ctl, u64 generation)
410{ 437{
411 __le64 *gen; 438 __le64 *gen;
412 439
@@ -435,7 +462,7 @@ static int io_ctl_check_generation(struct io_ctl *io_ctl, u64 generation)
435 return 0; 462 return 0;
436} 463}
437 464
438static void io_ctl_set_crc(struct io_ctl *io_ctl, int index) 465static void io_ctl_set_crc(struct btrfs_io_ctl *io_ctl, int index)
439{ 466{
440 u32 *tmp; 467 u32 *tmp;
441 u32 crc = ~(u32)0; 468 u32 crc = ~(u32)0;
@@ -453,13 +480,12 @@ static void io_ctl_set_crc(struct io_ctl *io_ctl, int index)
453 PAGE_CACHE_SIZE - offset); 480 PAGE_CACHE_SIZE - offset);
454 btrfs_csum_final(crc, (char *)&crc); 481 btrfs_csum_final(crc, (char *)&crc);
455 io_ctl_unmap_page(io_ctl); 482 io_ctl_unmap_page(io_ctl);
456 tmp = kmap(io_ctl->pages[0]); 483 tmp = page_address(io_ctl->pages[0]);
457 tmp += index; 484 tmp += index;
458 *tmp = crc; 485 *tmp = crc;
459 kunmap(io_ctl->pages[0]);
460} 486}
461 487
462static int io_ctl_check_crc(struct io_ctl *io_ctl, int index) 488static int io_ctl_check_crc(struct btrfs_io_ctl *io_ctl, int index)
463{ 489{
464 u32 *tmp, val; 490 u32 *tmp, val;
465 u32 crc = ~(u32)0; 491 u32 crc = ~(u32)0;
@@ -473,10 +499,9 @@ static int io_ctl_check_crc(struct io_ctl *io_ctl, int index)
473 if (index == 0) 499 if (index == 0)
474 offset = sizeof(u32) * io_ctl->num_pages; 500 offset = sizeof(u32) * io_ctl->num_pages;
475 501
476 tmp = kmap(io_ctl->pages[0]); 502 tmp = page_address(io_ctl->pages[0]);
477 tmp += index; 503 tmp += index;
478 val = *tmp; 504 val = *tmp;
479 kunmap(io_ctl->pages[0]);
480 505
481 io_ctl_map_page(io_ctl, 0); 506 io_ctl_map_page(io_ctl, 0);
482 crc = btrfs_csum_data(io_ctl->orig + offset, crc, 507 crc = btrfs_csum_data(io_ctl->orig + offset, crc,
@@ -492,7 +517,7 @@ static int io_ctl_check_crc(struct io_ctl *io_ctl, int index)
492 return 0; 517 return 0;
493} 518}
494 519
495static int io_ctl_add_entry(struct io_ctl *io_ctl, u64 offset, u64 bytes, 520static int io_ctl_add_entry(struct btrfs_io_ctl *io_ctl, u64 offset, u64 bytes,
496 void *bitmap) 521 void *bitmap)
497{ 522{
498 struct btrfs_free_space_entry *entry; 523 struct btrfs_free_space_entry *entry;
@@ -522,7 +547,7 @@ static int io_ctl_add_entry(struct io_ctl *io_ctl, u64 offset, u64 bytes,
522 return 0; 547 return 0;
523} 548}
524 549
525static int io_ctl_add_bitmap(struct io_ctl *io_ctl, void *bitmap) 550static int io_ctl_add_bitmap(struct btrfs_io_ctl *io_ctl, void *bitmap)
526{ 551{
527 if (!io_ctl->cur) 552 if (!io_ctl->cur)
528 return -ENOSPC; 553 return -ENOSPC;
@@ -545,7 +570,7 @@ static int io_ctl_add_bitmap(struct io_ctl *io_ctl, void *bitmap)
545 return 0; 570 return 0;
546} 571}
547 572
548static void io_ctl_zero_remaining_pages(struct io_ctl *io_ctl) 573static void io_ctl_zero_remaining_pages(struct btrfs_io_ctl *io_ctl)
549{ 574{
550 /* 575 /*
551 * If we're not on the boundary we know we've modified the page and we 576 * If we're not on the boundary we know we've modified the page and we
@@ -562,7 +587,7 @@ static void io_ctl_zero_remaining_pages(struct io_ctl *io_ctl)
562 } 587 }
563} 588}
564 589
565static int io_ctl_read_entry(struct io_ctl *io_ctl, 590static int io_ctl_read_entry(struct btrfs_io_ctl *io_ctl,
566 struct btrfs_free_space *entry, u8 *type) 591 struct btrfs_free_space *entry, u8 *type)
567{ 592{
568 struct btrfs_free_space_entry *e; 593 struct btrfs_free_space_entry *e;
@@ -589,7 +614,7 @@ static int io_ctl_read_entry(struct io_ctl *io_ctl,
589 return 0; 614 return 0;
590} 615}
591 616
592static int io_ctl_read_bitmap(struct io_ctl *io_ctl, 617static int io_ctl_read_bitmap(struct btrfs_io_ctl *io_ctl,
593 struct btrfs_free_space *entry) 618 struct btrfs_free_space *entry)
594{ 619{
595 int ret; 620 int ret;
@@ -648,7 +673,7 @@ static int __load_free_space_cache(struct btrfs_root *root, struct inode *inode,
648{ 673{
649 struct btrfs_free_space_header *header; 674 struct btrfs_free_space_header *header;
650 struct extent_buffer *leaf; 675 struct extent_buffer *leaf;
651 struct io_ctl io_ctl; 676 struct btrfs_io_ctl io_ctl;
652 struct btrfs_key key; 677 struct btrfs_key key;
653 struct btrfs_free_space *e, *n; 678 struct btrfs_free_space *e, *n;
654 LIST_HEAD(bitmaps); 679 LIST_HEAD(bitmaps);
@@ -877,7 +902,7 @@ out:
877} 902}
878 903
879static noinline_for_stack 904static noinline_for_stack
880int write_cache_extent_entries(struct io_ctl *io_ctl, 905int write_cache_extent_entries(struct btrfs_io_ctl *io_ctl,
881 struct btrfs_free_space_ctl *ctl, 906 struct btrfs_free_space_ctl *ctl,
882 struct btrfs_block_group_cache *block_group, 907 struct btrfs_block_group_cache *block_group,
883 int *entries, int *bitmaps, 908 int *entries, int *bitmaps,
@@ -885,6 +910,7 @@ int write_cache_extent_entries(struct io_ctl *io_ctl,
885{ 910{
886 int ret; 911 int ret;
887 struct btrfs_free_cluster *cluster = NULL; 912 struct btrfs_free_cluster *cluster = NULL;
913 struct btrfs_free_cluster *cluster_locked = NULL;
888 struct rb_node *node = rb_first(&ctl->free_space_offset); 914 struct rb_node *node = rb_first(&ctl->free_space_offset);
889 struct btrfs_trim_range *trim_entry; 915 struct btrfs_trim_range *trim_entry;
890 916
@@ -896,6 +922,8 @@ int write_cache_extent_entries(struct io_ctl *io_ctl,
896 } 922 }
897 923
898 if (!node && cluster) { 924 if (!node && cluster) {
925 cluster_locked = cluster;
926 spin_lock(&cluster_locked->lock);
899 node = rb_first(&cluster->root); 927 node = rb_first(&cluster->root);
900 cluster = NULL; 928 cluster = NULL;
901 } 929 }
@@ -919,9 +947,15 @@ int write_cache_extent_entries(struct io_ctl *io_ctl,
919 node = rb_next(node); 947 node = rb_next(node);
920 if (!node && cluster) { 948 if (!node && cluster) {
921 node = rb_first(&cluster->root); 949 node = rb_first(&cluster->root);
950 cluster_locked = cluster;
951 spin_lock(&cluster_locked->lock);
922 cluster = NULL; 952 cluster = NULL;
923 } 953 }
924 } 954 }
955 if (cluster_locked) {
956 spin_unlock(&cluster_locked->lock);
957 cluster_locked = NULL;
958 }
925 959
926 /* 960 /*
927 * Make sure we don't miss any range that was removed from our rbtree 961 * Make sure we don't miss any range that was removed from our rbtree
@@ -939,6 +973,8 @@ int write_cache_extent_entries(struct io_ctl *io_ctl,
939 973
940 return 0; 974 return 0;
941fail: 975fail:
976 if (cluster_locked)
977 spin_unlock(&cluster_locked->lock);
942 return -ENOSPC; 978 return -ENOSPC;
943} 979}
944 980
@@ -1000,7 +1036,7 @@ fail:
1000static noinline_for_stack int 1036static noinline_for_stack int
1001write_pinned_extent_entries(struct btrfs_root *root, 1037write_pinned_extent_entries(struct btrfs_root *root,
1002 struct btrfs_block_group_cache *block_group, 1038 struct btrfs_block_group_cache *block_group,
1003 struct io_ctl *io_ctl, 1039 struct btrfs_io_ctl *io_ctl,
1004 int *entries) 1040 int *entries)
1005{ 1041{
1006 u64 start, extent_start, extent_end, len; 1042 u64 start, extent_start, extent_end, len;
@@ -1050,7 +1086,7 @@ write_pinned_extent_entries(struct btrfs_root *root,
1050} 1086}
1051 1087
1052static noinline_for_stack int 1088static noinline_for_stack int
1053write_bitmap_entries(struct io_ctl *io_ctl, struct list_head *bitmap_list) 1089write_bitmap_entries(struct btrfs_io_ctl *io_ctl, struct list_head *bitmap_list)
1054{ 1090{
1055 struct list_head *pos, *n; 1091 struct list_head *pos, *n;
1056 int ret; 1092 int ret;
@@ -1083,10 +1119,7 @@ static int flush_dirty_cache(struct inode *inode)
1083} 1119}
1084 1120
1085static void noinline_for_stack 1121static void noinline_for_stack
1086cleanup_write_cache_enospc(struct inode *inode, 1122cleanup_bitmap_list(struct list_head *bitmap_list)
1087 struct io_ctl *io_ctl,
1088 struct extent_state **cached_state,
1089 struct list_head *bitmap_list)
1090{ 1123{
1091 struct list_head *pos, *n; 1124 struct list_head *pos, *n;
1092 1125
@@ -1095,12 +1128,85 @@ cleanup_write_cache_enospc(struct inode *inode,
1095 list_entry(pos, struct btrfs_free_space, list); 1128 list_entry(pos, struct btrfs_free_space, list);
1096 list_del_init(&entry->list); 1129 list_del_init(&entry->list);
1097 } 1130 }
1131}
1132
1133static void noinline_for_stack
1134cleanup_write_cache_enospc(struct inode *inode,
1135 struct btrfs_io_ctl *io_ctl,
1136 struct extent_state **cached_state,
1137 struct list_head *bitmap_list)
1138{
1098 io_ctl_drop_pages(io_ctl); 1139 io_ctl_drop_pages(io_ctl);
1099 unlock_extent_cached(&BTRFS_I(inode)->io_tree, 0, 1140 unlock_extent_cached(&BTRFS_I(inode)->io_tree, 0,
1100 i_size_read(inode) - 1, cached_state, 1141 i_size_read(inode) - 1, cached_state,
1101 GFP_NOFS); 1142 GFP_NOFS);
1102} 1143}
1103 1144
1145int btrfs_wait_cache_io(struct btrfs_root *root,
1146 struct btrfs_trans_handle *trans,
1147 struct btrfs_block_group_cache *block_group,
1148 struct btrfs_io_ctl *io_ctl,
1149 struct btrfs_path *path, u64 offset)
1150{
1151 int ret;
1152 struct inode *inode = io_ctl->inode;
1153
1154 if (!inode)
1155 return 0;
1156
1157 if (block_group)
1158 root = root->fs_info->tree_root;
1159
1160 /* Flush the dirty pages in the cache file. */
1161 ret = flush_dirty_cache(inode);
1162 if (ret)
1163 goto out;
1164
1165 /* Update the cache item to tell everyone this cache file is valid. */
1166 ret = update_cache_item(trans, root, inode, path, offset,
1167 io_ctl->entries, io_ctl->bitmaps);
1168out:
1169 io_ctl_free(io_ctl);
1170 if (ret) {
1171 invalidate_inode_pages2(inode->i_mapping);
1172 BTRFS_I(inode)->generation = 0;
1173 if (block_group) {
1174#ifdef DEBUG
1175 btrfs_err(root->fs_info,
1176 "failed to write free space cache for block group %llu",
1177 block_group->key.objectid);
1178#endif
1179 }
1180 }
1181 btrfs_update_inode(trans, root, inode);
1182
1183 if (block_group) {
1184 /* the dirty list is protected by the dirty_bgs_lock */
1185 spin_lock(&trans->transaction->dirty_bgs_lock);
1186
1187 /* the disk_cache_state is protected by the block group lock */
1188 spin_lock(&block_group->lock);
1189
1190 /*
1191 * only mark this as written if we didn't get put back on
1192 * the dirty list while waiting for IO. Otherwise our
1193 * cache state won't be right, and we won't get written again
1194 */
1195 if (!ret && list_empty(&block_group->dirty_list))
1196 block_group->disk_cache_state = BTRFS_DC_WRITTEN;
1197 else if (ret)
1198 block_group->disk_cache_state = BTRFS_DC_ERROR;
1199
1200 spin_unlock(&block_group->lock);
1201 spin_unlock(&trans->transaction->dirty_bgs_lock);
1202 io_ctl->inode = NULL;
1203 iput(inode);
1204 }
1205
1206 return ret;
1207
1208}
1209
1104/** 1210/**
1105 * __btrfs_write_out_cache - write out cached info to an inode 1211 * __btrfs_write_out_cache - write out cached info to an inode
1106 * @root - the root the inode belongs to 1212 * @root - the root the inode belongs to
@@ -1117,20 +1223,22 @@ cleanup_write_cache_enospc(struct inode *inode,
1117static int __btrfs_write_out_cache(struct btrfs_root *root, struct inode *inode, 1223static int __btrfs_write_out_cache(struct btrfs_root *root, struct inode *inode,
1118 struct btrfs_free_space_ctl *ctl, 1224 struct btrfs_free_space_ctl *ctl,
1119 struct btrfs_block_group_cache *block_group, 1225 struct btrfs_block_group_cache *block_group,
1226 struct btrfs_io_ctl *io_ctl,
1120 struct btrfs_trans_handle *trans, 1227 struct btrfs_trans_handle *trans,
1121 struct btrfs_path *path, u64 offset) 1228 struct btrfs_path *path, u64 offset)
1122{ 1229{
1123 struct extent_state *cached_state = NULL; 1230 struct extent_state *cached_state = NULL;
1124 struct io_ctl io_ctl;
1125 LIST_HEAD(bitmap_list); 1231 LIST_HEAD(bitmap_list);
1126 int entries = 0; 1232 int entries = 0;
1127 int bitmaps = 0; 1233 int bitmaps = 0;
1128 int ret; 1234 int ret;
1235 int must_iput = 0;
1129 1236
1130 if (!i_size_read(inode)) 1237 if (!i_size_read(inode))
1131 return -1; 1238 return -1;
1132 1239
1133 ret = io_ctl_init(&io_ctl, inode, root, 1); 1240 WARN_ON(io_ctl->pages);
1241 ret = io_ctl_init(io_ctl, inode, root, 1);
1134 if (ret) 1242 if (ret)
1135 return -1; 1243 return -1;
1136 1244
@@ -1143,55 +1251,57 @@ static int __btrfs_write_out_cache(struct btrfs_root *root, struct inode *inode,
1143 up_write(&block_group->data_rwsem); 1251 up_write(&block_group->data_rwsem);
1144 BTRFS_I(inode)->generation = 0; 1252 BTRFS_I(inode)->generation = 0;
1145 ret = 0; 1253 ret = 0;
1254 must_iput = 1;
1146 goto out; 1255 goto out;
1147 } 1256 }
1148 spin_unlock(&block_group->lock); 1257 spin_unlock(&block_group->lock);
1149 } 1258 }
1150 1259
1151 /* Lock all pages first so we can lock the extent safely. */ 1260 /* Lock all pages first so we can lock the extent safely. */
1152 io_ctl_prepare_pages(&io_ctl, inode, 0); 1261 io_ctl_prepare_pages(io_ctl, inode, 0);
1153 1262
1154 lock_extent_bits(&BTRFS_I(inode)->io_tree, 0, i_size_read(inode) - 1, 1263 lock_extent_bits(&BTRFS_I(inode)->io_tree, 0, i_size_read(inode) - 1,
1155 0, &cached_state); 1264 0, &cached_state);
1156 1265
1157 io_ctl_set_generation(&io_ctl, trans->transid); 1266 io_ctl_set_generation(io_ctl, trans->transid);
1158 1267
1159 mutex_lock(&ctl->cache_writeout_mutex); 1268 mutex_lock(&ctl->cache_writeout_mutex);
1160 /* Write out the extent entries in the free space cache */ 1269 /* Write out the extent entries in the free space cache */
1161 ret = write_cache_extent_entries(&io_ctl, ctl, 1270 spin_lock(&ctl->tree_lock);
1271 ret = write_cache_extent_entries(io_ctl, ctl,
1162 block_group, &entries, &bitmaps, 1272 block_group, &entries, &bitmaps,
1163 &bitmap_list); 1273 &bitmap_list);
1164 if (ret) { 1274 if (ret)
1165 mutex_unlock(&ctl->cache_writeout_mutex); 1275 goto out_nospc_locked;
1166 goto out_nospc;
1167 }
1168 1276
1169 /* 1277 /*
1170 * Some spaces that are freed in the current transaction are pinned, 1278 * Some spaces that are freed in the current transaction are pinned,
1171 * they will be added into free space cache after the transaction is 1279 * they will be added into free space cache after the transaction is
1172 * committed, we shouldn't lose them. 1280 * committed, we shouldn't lose them.
1281 *
1282 * If this changes while we are working we'll get added back to
1283 * the dirty list and redo it. No locking needed
1173 */ 1284 */
1174 ret = write_pinned_extent_entries(root, block_group, &io_ctl, &entries); 1285 ret = write_pinned_extent_entries(root, block_group, io_ctl, &entries);
1175 if (ret) { 1286 if (ret)
1176 mutex_unlock(&ctl->cache_writeout_mutex); 1287 goto out_nospc_locked;
1177 goto out_nospc;
1178 }
1179 1288
1180 /* 1289 /*
1181 * At last, we write out all the bitmaps and keep cache_writeout_mutex 1290 * At last, we write out all the bitmaps and keep cache_writeout_mutex
1182 * locked while doing it because a concurrent trim can be manipulating 1291 * locked while doing it because a concurrent trim can be manipulating
1183 * or freeing the bitmap. 1292 * or freeing the bitmap.
1184 */ 1293 */
1185 ret = write_bitmap_entries(&io_ctl, &bitmap_list); 1294 ret = write_bitmap_entries(io_ctl, &bitmap_list);
1295 spin_unlock(&ctl->tree_lock);
1186 mutex_unlock(&ctl->cache_writeout_mutex); 1296 mutex_unlock(&ctl->cache_writeout_mutex);
1187 if (ret) 1297 if (ret)
1188 goto out_nospc; 1298 goto out_nospc;
1189 1299
1190 /* Zero out the rest of the pages just to make sure */ 1300 /* Zero out the rest of the pages just to make sure */
1191 io_ctl_zero_remaining_pages(&io_ctl); 1301 io_ctl_zero_remaining_pages(io_ctl);
1192 1302
1193 /* Everything is written out, now we dirty the pages in the file. */ 1303 /* Everything is written out, now we dirty the pages in the file. */
1194 ret = btrfs_dirty_pages(root, inode, io_ctl.pages, io_ctl.num_pages, 1304 ret = btrfs_dirty_pages(root, inode, io_ctl->pages, io_ctl->num_pages,
1195 0, i_size_read(inode), &cached_state); 1305 0, i_size_read(inode), &cached_state);
1196 if (ret) 1306 if (ret)
1197 goto out_nospc; 1307 goto out_nospc;
@@ -1202,30 +1312,44 @@ static int __btrfs_write_out_cache(struct btrfs_root *root, struct inode *inode,
1202 * Release the pages and unlock the extent, we will flush 1312 * Release the pages and unlock the extent, we will flush
1203 * them out later 1313 * them out later
1204 */ 1314 */
1205 io_ctl_drop_pages(&io_ctl); 1315 io_ctl_drop_pages(io_ctl);
1206 1316
1207 unlock_extent_cached(&BTRFS_I(inode)->io_tree, 0, 1317 unlock_extent_cached(&BTRFS_I(inode)->io_tree, 0,
1208 i_size_read(inode) - 1, &cached_state, GFP_NOFS); 1318 i_size_read(inode) - 1, &cached_state, GFP_NOFS);
1209 1319
1210 /* Flush the dirty pages in the cache file. */ 1320 /*
1211 ret = flush_dirty_cache(inode); 1321 * at this point the pages are under IO and we're happy,
1322 * The caller is responsible for waiting on them and updating the
1323 * the cache and the inode
1324 */
1325 io_ctl->entries = entries;
1326 io_ctl->bitmaps = bitmaps;
1327
1328 ret = btrfs_fdatawrite_range(inode, 0, (u64)-1);
1212 if (ret) 1329 if (ret)
1213 goto out; 1330 goto out;
1214 1331
1215 /* Update the cache item to tell everyone this cache file is valid. */ 1332 return 0;
1216 ret = update_cache_item(trans, root, inode, path, offset, 1333
1217 entries, bitmaps);
1218out: 1334out:
1219 io_ctl_free(&io_ctl); 1335 io_ctl->inode = NULL;
1336 io_ctl_free(io_ctl);
1220 if (ret) { 1337 if (ret) {
1221 invalidate_inode_pages2(inode->i_mapping); 1338 invalidate_inode_pages2(inode->i_mapping);
1222 BTRFS_I(inode)->generation = 0; 1339 BTRFS_I(inode)->generation = 0;
1223 } 1340 }
1224 btrfs_update_inode(trans, root, inode); 1341 btrfs_update_inode(trans, root, inode);
1342 if (must_iput)
1343 iput(inode);
1225 return ret; 1344 return ret;
1226 1345
1346out_nospc_locked:
1347 cleanup_bitmap_list(&bitmap_list);
1348 spin_unlock(&ctl->tree_lock);
1349 mutex_unlock(&ctl->cache_writeout_mutex);
1350
1227out_nospc: 1351out_nospc:
1228 cleanup_write_cache_enospc(inode, &io_ctl, &cached_state, &bitmap_list); 1352 cleanup_write_cache_enospc(inode, io_ctl, &cached_state, &bitmap_list);
1229 1353
1230 if (block_group && (block_group->flags & BTRFS_BLOCK_GROUP_DATA)) 1354 if (block_group && (block_group->flags & BTRFS_BLOCK_GROUP_DATA))
1231 up_write(&block_group->data_rwsem); 1355 up_write(&block_group->data_rwsem);
@@ -1241,7 +1365,6 @@ int btrfs_write_out_cache(struct btrfs_root *root,
1241 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; 1365 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl;
1242 struct inode *inode; 1366 struct inode *inode;
1243 int ret = 0; 1367 int ret = 0;
1244 enum btrfs_disk_cache_state dcs = BTRFS_DC_WRITTEN;
1245 1368
1246 root = root->fs_info->tree_root; 1369 root = root->fs_info->tree_root;
1247 1370
@@ -1250,34 +1373,34 @@ int btrfs_write_out_cache(struct btrfs_root *root,
1250 spin_unlock(&block_group->lock); 1373 spin_unlock(&block_group->lock);
1251 return 0; 1374 return 0;
1252 } 1375 }
1253
1254 if (block_group->delalloc_bytes) {
1255 block_group->disk_cache_state = BTRFS_DC_WRITTEN;
1256 spin_unlock(&block_group->lock);
1257 return 0;
1258 }
1259 spin_unlock(&block_group->lock); 1376 spin_unlock(&block_group->lock);
1260 1377
1261 inode = lookup_free_space_inode(root, block_group, path); 1378 inode = lookup_free_space_inode(root, block_group, path);
1262 if (IS_ERR(inode)) 1379 if (IS_ERR(inode))
1263 return 0; 1380 return 0;
1264 1381
1265 ret = __btrfs_write_out_cache(root, inode, ctl, block_group, trans, 1382 ret = __btrfs_write_out_cache(root, inode, ctl, block_group,
1383 &block_group->io_ctl, trans,
1266 path, block_group->key.objectid); 1384 path, block_group->key.objectid);
1267 if (ret) { 1385 if (ret) {
1268 dcs = BTRFS_DC_ERROR;
1269 ret = 0;
1270#ifdef DEBUG 1386#ifdef DEBUG
1271 btrfs_err(root->fs_info, 1387 btrfs_err(root->fs_info,
1272 "failed to write free space cache for block group %llu", 1388 "failed to write free space cache for block group %llu",
1273 block_group->key.objectid); 1389 block_group->key.objectid);
1274#endif 1390#endif
1391 spin_lock(&block_group->lock);
1392 block_group->disk_cache_state = BTRFS_DC_ERROR;
1393 spin_unlock(&block_group->lock);
1394
1395 block_group->io_ctl.inode = NULL;
1396 iput(inode);
1275 } 1397 }
1276 1398
1277 spin_lock(&block_group->lock); 1399 /*
1278 block_group->disk_cache_state = dcs; 1400 * if ret == 0 the caller is expected to call btrfs_wait_cache_io
1279 spin_unlock(&block_group->lock); 1401 * to wait for IO and put the inode
1280 iput(inode); 1402 */
1403
1281 return ret; 1404 return ret;
1282} 1405}
1283 1406
@@ -1298,11 +1421,11 @@ static inline u64 offset_to_bitmap(struct btrfs_free_space_ctl *ctl,
1298 u64 offset) 1421 u64 offset)
1299{ 1422{
1300 u64 bitmap_start; 1423 u64 bitmap_start;
1301 u64 bytes_per_bitmap; 1424 u32 bytes_per_bitmap;
1302 1425
1303 bytes_per_bitmap = BITS_PER_BITMAP * ctl->unit; 1426 bytes_per_bitmap = BITS_PER_BITMAP * ctl->unit;
1304 bitmap_start = offset - ctl->start; 1427 bitmap_start = offset - ctl->start;
1305 bitmap_start = div64_u64(bitmap_start, bytes_per_bitmap); 1428 bitmap_start = div_u64(bitmap_start, bytes_per_bitmap);
1306 bitmap_start *= bytes_per_bitmap; 1429 bitmap_start *= bytes_per_bitmap;
1307 bitmap_start += ctl->start; 1430 bitmap_start += ctl->start;
1308 1431
@@ -1521,10 +1644,10 @@ static void recalculate_thresholds(struct btrfs_free_space_ctl *ctl)
1521 u64 bitmap_bytes; 1644 u64 bitmap_bytes;
1522 u64 extent_bytes; 1645 u64 extent_bytes;
1523 u64 size = block_group->key.offset; 1646 u64 size = block_group->key.offset;
1524 u64 bytes_per_bg = BITS_PER_BITMAP * ctl->unit; 1647 u32 bytes_per_bg = BITS_PER_BITMAP * ctl->unit;
1525 int max_bitmaps = div64_u64(size + bytes_per_bg - 1, bytes_per_bg); 1648 u32 max_bitmaps = div_u64(size + bytes_per_bg - 1, bytes_per_bg);
1526 1649
1527 max_bitmaps = max(max_bitmaps, 1); 1650 max_bitmaps = max_t(u32, max_bitmaps, 1);
1528 1651
1529 ASSERT(ctl->total_bitmaps <= max_bitmaps); 1652 ASSERT(ctl->total_bitmaps <= max_bitmaps);
1530 1653
@@ -1537,7 +1660,7 @@ static void recalculate_thresholds(struct btrfs_free_space_ctl *ctl)
1537 max_bytes = MAX_CACHE_BYTES_PER_GIG; 1660 max_bytes = MAX_CACHE_BYTES_PER_GIG;
1538 else 1661 else
1539 max_bytes = MAX_CACHE_BYTES_PER_GIG * 1662 max_bytes = MAX_CACHE_BYTES_PER_GIG *
1540 div64_u64(size, 1024 * 1024 * 1024); 1663 div_u64(size, 1024 * 1024 * 1024);
1541 1664
1542 /* 1665 /*
1543 * we want to account for 1 more bitmap than what we have so we can make 1666 * we want to account for 1 more bitmap than what we have so we can make
@@ -1552,14 +1675,14 @@ static void recalculate_thresholds(struct btrfs_free_space_ctl *ctl)
1552 } 1675 }
1553 1676
1554 /* 1677 /*
1555 * we want the extent entry threshold to always be at most 1/2 the maxw 1678 * we want the extent entry threshold to always be at most 1/2 the max
1556 * bytes we can have, or whatever is less than that. 1679 * bytes we can have, or whatever is less than that.
1557 */ 1680 */
1558 extent_bytes = max_bytes - bitmap_bytes; 1681 extent_bytes = max_bytes - bitmap_bytes;
1559 extent_bytes = min_t(u64, extent_bytes, div64_u64(max_bytes, 2)); 1682 extent_bytes = min_t(u64, extent_bytes, max_bytes >> 1);
1560 1683
1561 ctl->extents_thresh = 1684 ctl->extents_thresh =
1562 div64_u64(extent_bytes, (sizeof(struct btrfs_free_space))); 1685 div_u64(extent_bytes, sizeof(struct btrfs_free_space));
1563} 1686}
1564 1687
1565static inline void __bitmap_clear_bits(struct btrfs_free_space_ctl *ctl, 1688static inline void __bitmap_clear_bits(struct btrfs_free_space_ctl *ctl,
@@ -1673,7 +1796,7 @@ find_free_space(struct btrfs_free_space_ctl *ctl, u64 *offset, u64 *bytes,
1673 */ 1796 */
1674 if (*bytes >= align) { 1797 if (*bytes >= align) {
1675 tmp = entry->offset - ctl->start + align - 1; 1798 tmp = entry->offset - ctl->start + align - 1;
1676 do_div(tmp, align); 1799 tmp = div64_u64(tmp, align);
1677 tmp = tmp * align + ctl->start; 1800 tmp = tmp * align + ctl->start;
1678 align_off = tmp - entry->offset; 1801 align_off = tmp - entry->offset;
1679 } else { 1802 } else {
@@ -2402,11 +2525,8 @@ static void __btrfs_remove_free_space_cache_locked(
2402 } else { 2525 } else {
2403 free_bitmap(ctl, info); 2526 free_bitmap(ctl, info);
2404 } 2527 }
2405 if (need_resched()) { 2528
2406 spin_unlock(&ctl->tree_lock); 2529 cond_resched_lock(&ctl->tree_lock);
2407 cond_resched();
2408 spin_lock(&ctl->tree_lock);
2409 }
2410 } 2530 }
2411} 2531}
2412 2532
@@ -2431,11 +2551,8 @@ void btrfs_remove_free_space_cache(struct btrfs_block_group_cache *block_group)
2431 2551
2432 WARN_ON(cluster->block_group != block_group); 2552 WARN_ON(cluster->block_group != block_group);
2433 __btrfs_return_cluster_to_free_space(block_group, cluster); 2553 __btrfs_return_cluster_to_free_space(block_group, cluster);
2434 if (need_resched()) { 2554
2435 spin_unlock(&ctl->tree_lock); 2555 cond_resched_lock(&ctl->tree_lock);
2436 cond_resched();
2437 spin_lock(&ctl->tree_lock);
2438 }
2439 } 2556 }
2440 __btrfs_remove_free_space_cache_locked(ctl); 2557 __btrfs_remove_free_space_cache_locked(ctl);
2441 spin_unlock(&ctl->tree_lock); 2558 spin_unlock(&ctl->tree_lock);
@@ -3346,11 +3463,17 @@ int btrfs_write_out_ino_cache(struct btrfs_root *root,
3346{ 3463{
3347 struct btrfs_free_space_ctl *ctl = root->free_ino_ctl; 3464 struct btrfs_free_space_ctl *ctl = root->free_ino_ctl;
3348 int ret; 3465 int ret;
3466 struct btrfs_io_ctl io_ctl;
3349 3467
3350 if (!btrfs_test_opt(root, INODE_MAP_CACHE)) 3468 if (!btrfs_test_opt(root, INODE_MAP_CACHE))
3351 return 0; 3469 return 0;
3352 3470
3353 ret = __btrfs_write_out_cache(root, inode, ctl, NULL, trans, path, 0); 3471 memset(&io_ctl, 0, sizeof(io_ctl));
3472 ret = __btrfs_write_out_cache(root, inode, ctl, NULL, &io_ctl,
3473 trans, path, 0);
3474 if (!ret)
3475 ret = btrfs_wait_cache_io(root, trans, NULL, &io_ctl, path, 0);
3476
3354 if (ret) { 3477 if (ret) {
3355 btrfs_delalloc_release_metadata(inode, inode->i_size); 3478 btrfs_delalloc_release_metadata(inode, inode->i_size);
3356#ifdef DEBUG 3479#ifdef DEBUG
diff --git a/fs/btrfs/free-space-cache.h b/fs/btrfs/free-space-cache.h
index 88b2238a0aed..a16a029ad3b1 100644
--- a/fs/btrfs/free-space-cache.h
+++ b/fs/btrfs/free-space-cache.h
@@ -48,6 +48,8 @@ struct btrfs_free_space_op {
48 struct btrfs_free_space *info); 48 struct btrfs_free_space *info);
49}; 49};
50 50
51struct btrfs_io_ctl;
52
51struct inode *lookup_free_space_inode(struct btrfs_root *root, 53struct inode *lookup_free_space_inode(struct btrfs_root *root,
52 struct btrfs_block_group_cache 54 struct btrfs_block_group_cache
53 *block_group, struct btrfs_path *path); 55 *block_group, struct btrfs_path *path);
@@ -60,14 +62,19 @@ int btrfs_check_trunc_cache_free_space(struct btrfs_root *root,
60 struct btrfs_block_rsv *rsv); 62 struct btrfs_block_rsv *rsv);
61int btrfs_truncate_free_space_cache(struct btrfs_root *root, 63int btrfs_truncate_free_space_cache(struct btrfs_root *root,
62 struct btrfs_trans_handle *trans, 64 struct btrfs_trans_handle *trans,
65 struct btrfs_block_group_cache *block_group,
63 struct inode *inode); 66 struct inode *inode);
64int load_free_space_cache(struct btrfs_fs_info *fs_info, 67int load_free_space_cache(struct btrfs_fs_info *fs_info,
65 struct btrfs_block_group_cache *block_group); 68 struct btrfs_block_group_cache *block_group);
69int btrfs_wait_cache_io(struct btrfs_root *root,
70 struct btrfs_trans_handle *trans,
71 struct btrfs_block_group_cache *block_group,
72 struct btrfs_io_ctl *io_ctl,
73 struct btrfs_path *path, u64 offset);
66int btrfs_write_out_cache(struct btrfs_root *root, 74int btrfs_write_out_cache(struct btrfs_root *root,
67 struct btrfs_trans_handle *trans, 75 struct btrfs_trans_handle *trans,
68 struct btrfs_block_group_cache *block_group, 76 struct btrfs_block_group_cache *block_group,
69 struct btrfs_path *path); 77 struct btrfs_path *path);
70
71struct inode *lookup_free_ino_inode(struct btrfs_root *root, 78struct inode *lookup_free_ino_inode(struct btrfs_root *root,
72 struct btrfs_path *path); 79 struct btrfs_path *path);
73int create_free_ino_inode(struct btrfs_root *root, 80int create_free_ino_inode(struct btrfs_root *root,
diff --git a/fs/btrfs/inode-map.c b/fs/btrfs/inode-map.c
index 74faea3a516e..f6a596d5a637 100644
--- a/fs/btrfs/inode-map.c
+++ b/fs/btrfs/inode-map.c
@@ -456,7 +456,7 @@ again:
456 } 456 }
457 457
458 if (i_size_read(inode) > 0) { 458 if (i_size_read(inode) > 0) {
459 ret = btrfs_truncate_free_space_cache(root, trans, inode); 459 ret = btrfs_truncate_free_space_cache(root, trans, NULL, inode);
460 if (ret) { 460 if (ret) {
461 if (ret != -ENOSPC) 461 if (ret != -ENOSPC)
462 btrfs_abort_transaction(trans, root, ret); 462 btrfs_abort_transaction(trans, root, ret);
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 43192e10cc43..ada4d24ed11b 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -59,6 +59,7 @@
59#include "backref.h" 59#include "backref.h"
60#include "hash.h" 60#include "hash.h"
61#include "props.h" 61#include "props.h"
62#include "qgroup.h"
62 63
63struct btrfs_iget_args { 64struct btrfs_iget_args {
64 struct btrfs_key *location; 65 struct btrfs_key *location;
@@ -470,7 +471,7 @@ again:
470 */ 471 */
471 if (inode_need_compress(inode)) { 472 if (inode_need_compress(inode)) {
472 WARN_ON(pages); 473 WARN_ON(pages);
473 pages = kzalloc(sizeof(struct page *) * nr_pages, GFP_NOFS); 474 pages = kcalloc(nr_pages, sizeof(struct page *), GFP_NOFS);
474 if (!pages) { 475 if (!pages) {
475 /* just bail out to the uncompressed code */ 476 /* just bail out to the uncompressed code */
476 goto cont; 477 goto cont;
@@ -752,7 +753,6 @@ retry:
752 } 753 }
753 goto out_free; 754 goto out_free;
754 } 755 }
755
756 /* 756 /*
757 * here we're doing allocation and writeback of the 757 * here we're doing allocation and writeback of the
758 * compressed pages 758 * compressed pages
@@ -3110,6 +3110,8 @@ void btrfs_run_delayed_iputs(struct btrfs_root *root)
3110 if (empty) 3110 if (empty)
3111 return; 3111 return;
3112 3112
3113 down_read(&fs_info->delayed_iput_sem);
3114
3113 spin_lock(&fs_info->delayed_iput_lock); 3115 spin_lock(&fs_info->delayed_iput_lock);
3114 list_splice_init(&fs_info->delayed_iputs, &list); 3116 list_splice_init(&fs_info->delayed_iputs, &list);
3115 spin_unlock(&fs_info->delayed_iput_lock); 3117 spin_unlock(&fs_info->delayed_iput_lock);
@@ -3120,6 +3122,8 @@ void btrfs_run_delayed_iputs(struct btrfs_root *root)
3120 iput(delayed->inode); 3122 iput(delayed->inode);
3121 kfree(delayed); 3123 kfree(delayed);
3122 } 3124 }
3125
3126 up_read(&root->fs_info->delayed_iput_sem);
3123} 3127}
3124 3128
3125/* 3129/*
@@ -4016,16 +4020,16 @@ static int btrfs_unlink(struct inode *dir, struct dentry *dentry)
4016{ 4020{
4017 struct btrfs_root *root = BTRFS_I(dir)->root; 4021 struct btrfs_root *root = BTRFS_I(dir)->root;
4018 struct btrfs_trans_handle *trans; 4022 struct btrfs_trans_handle *trans;
4019 struct inode *inode = dentry->d_inode; 4023 struct inode *inode = d_inode(dentry);
4020 int ret; 4024 int ret;
4021 4025
4022 trans = __unlink_start_trans(dir); 4026 trans = __unlink_start_trans(dir);
4023 if (IS_ERR(trans)) 4027 if (IS_ERR(trans))
4024 return PTR_ERR(trans); 4028 return PTR_ERR(trans);
4025 4029
4026 btrfs_record_unlink_dir(trans, dir, dentry->d_inode, 0); 4030 btrfs_record_unlink_dir(trans, dir, d_inode(dentry), 0);
4027 4031
4028 ret = btrfs_unlink_inode(trans, root, dir, dentry->d_inode, 4032 ret = btrfs_unlink_inode(trans, root, dir, d_inode(dentry),
4029 dentry->d_name.name, dentry->d_name.len); 4033 dentry->d_name.name, dentry->d_name.len);
4030 if (ret) 4034 if (ret)
4031 goto out; 4035 goto out;
@@ -4124,7 +4128,7 @@ out:
4124 4128
4125static int btrfs_rmdir(struct inode *dir, struct dentry *dentry) 4129static int btrfs_rmdir(struct inode *dir, struct dentry *dentry)
4126{ 4130{
4127 struct inode *inode = dentry->d_inode; 4131 struct inode *inode = d_inode(dentry);
4128 int err = 0; 4132 int err = 0;
4129 struct btrfs_root *root = BTRFS_I(dir)->root; 4133 struct btrfs_root *root = BTRFS_I(dir)->root;
4130 struct btrfs_trans_handle *trans; 4134 struct btrfs_trans_handle *trans;
@@ -4151,7 +4155,7 @@ static int btrfs_rmdir(struct inode *dir, struct dentry *dentry)
4151 goto out; 4155 goto out;
4152 4156
4153 /* now the directory is empty */ 4157 /* now the directory is empty */
4154 err = btrfs_unlink_inode(trans, root, dir, dentry->d_inode, 4158 err = btrfs_unlink_inode(trans, root, dir, d_inode(dentry),
4155 dentry->d_name.name, dentry->d_name.len); 4159 dentry->d_name.name, dentry->d_name.len);
4156 if (!err) 4160 if (!err)
4157 btrfs_i_size_write(inode, 0); 4161 btrfs_i_size_write(inode, 0);
@@ -4162,6 +4166,21 @@ out:
4162 return err; 4166 return err;
4163} 4167}
4164 4168
4169static int truncate_space_check(struct btrfs_trans_handle *trans,
4170 struct btrfs_root *root,
4171 u64 bytes_deleted)
4172{
4173 int ret;
4174
4175 bytes_deleted = btrfs_csum_bytes_to_leaves(root, bytes_deleted);
4176 ret = btrfs_block_rsv_add(root, &root->fs_info->trans_block_rsv,
4177 bytes_deleted, BTRFS_RESERVE_NO_FLUSH);
4178 if (!ret)
4179 trans->bytes_reserved += bytes_deleted;
4180 return ret;
4181
4182}
4183
4165/* 4184/*
4166 * this can truncate away extent items, csum items and directory items. 4185 * this can truncate away extent items, csum items and directory items.
4167 * It starts at a high offset and removes keys until it can't find 4186 * It starts at a high offset and removes keys until it can't find
@@ -4197,9 +4216,21 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans,
4197 int ret; 4216 int ret;
4198 int err = 0; 4217 int err = 0;
4199 u64 ino = btrfs_ino(inode); 4218 u64 ino = btrfs_ino(inode);
4219 u64 bytes_deleted = 0;
4220 bool be_nice = 0;
4221 bool should_throttle = 0;
4222 bool should_end = 0;
4200 4223
4201 BUG_ON(new_size > 0 && min_type != BTRFS_EXTENT_DATA_KEY); 4224 BUG_ON(new_size > 0 && min_type != BTRFS_EXTENT_DATA_KEY);
4202 4225
4226 /*
4227 * for non-free space inodes and ref cows, we want to back off from
4228 * time to time
4229 */
4230 if (!btrfs_is_free_space_inode(inode) &&
4231 test_bit(BTRFS_ROOT_REF_COWS, &root->state))
4232 be_nice = 1;
4233
4203 path = btrfs_alloc_path(); 4234 path = btrfs_alloc_path();
4204 if (!path) 4235 if (!path)
4205 return -ENOMEM; 4236 return -ENOMEM;
@@ -4229,6 +4260,19 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans,
4229 key.type = (u8)-1; 4260 key.type = (u8)-1;
4230 4261
4231search_again: 4262search_again:
4263 /*
4264 * with a 16K leaf size and 128MB extents, you can actually queue
4265 * up a huge file in a single leaf. Most of the time that
4266 * bytes_deleted is > 0, it will be huge by the time we get here
4267 */
4268 if (be_nice && bytes_deleted > 32 * 1024 * 1024) {
4269 if (btrfs_should_end_transaction(trans, root)) {
4270 err = -EAGAIN;
4271 goto error;
4272 }
4273 }
4274
4275
4232 path->leave_spinning = 1; 4276 path->leave_spinning = 1;
4233 ret = btrfs_search_slot(trans, root, &key, path, -1, 1); 4277 ret = btrfs_search_slot(trans, root, &key, path, -1, 1);
4234 if (ret < 0) { 4278 if (ret < 0) {
@@ -4371,22 +4415,39 @@ delete:
4371 } else { 4415 } else {
4372 break; 4416 break;
4373 } 4417 }
4418 should_throttle = 0;
4419
4374 if (found_extent && 4420 if (found_extent &&
4375 (test_bit(BTRFS_ROOT_REF_COWS, &root->state) || 4421 (test_bit(BTRFS_ROOT_REF_COWS, &root->state) ||
4376 root == root->fs_info->tree_root)) { 4422 root == root->fs_info->tree_root)) {
4377 btrfs_set_path_blocking(path); 4423 btrfs_set_path_blocking(path);
4424 bytes_deleted += extent_num_bytes;
4378 ret = btrfs_free_extent(trans, root, extent_start, 4425 ret = btrfs_free_extent(trans, root, extent_start,
4379 extent_num_bytes, 0, 4426 extent_num_bytes, 0,
4380 btrfs_header_owner(leaf), 4427 btrfs_header_owner(leaf),
4381 ino, extent_offset, 0); 4428 ino, extent_offset, 0);
4382 BUG_ON(ret); 4429 BUG_ON(ret);
4430 if (btrfs_should_throttle_delayed_refs(trans, root))
4431 btrfs_async_run_delayed_refs(root,
4432 trans->delayed_ref_updates * 2, 0);
4433 if (be_nice) {
4434 if (truncate_space_check(trans, root,
4435 extent_num_bytes)) {
4436 should_end = 1;
4437 }
4438 if (btrfs_should_throttle_delayed_refs(trans,
4439 root)) {
4440 should_throttle = 1;
4441 }
4442 }
4383 } 4443 }
4384 4444
4385 if (found_type == BTRFS_INODE_ITEM_KEY) 4445 if (found_type == BTRFS_INODE_ITEM_KEY)
4386 break; 4446 break;
4387 4447
4388 if (path->slots[0] == 0 || 4448 if (path->slots[0] == 0 ||
4389 path->slots[0] != pending_del_slot) { 4449 path->slots[0] != pending_del_slot ||
4450 should_throttle || should_end) {
4390 if (pending_del_nr) { 4451 if (pending_del_nr) {
4391 ret = btrfs_del_items(trans, root, path, 4452 ret = btrfs_del_items(trans, root, path,
4392 pending_del_slot, 4453 pending_del_slot,
@@ -4399,6 +4460,23 @@ delete:
4399 pending_del_nr = 0; 4460 pending_del_nr = 0;
4400 } 4461 }
4401 btrfs_release_path(path); 4462 btrfs_release_path(path);
4463 if (should_throttle) {
4464 unsigned long updates = trans->delayed_ref_updates;
4465 if (updates) {
4466 trans->delayed_ref_updates = 0;
4467 ret = btrfs_run_delayed_refs(trans, root, updates * 2);
4468 if (ret && !err)
4469 err = ret;
4470 }
4471 }
4472 /*
4473 * if we failed to refill our space rsv, bail out
4474 * and let the transaction restart
4475 */
4476 if (should_end) {
4477 err = -EAGAIN;
4478 goto error;
4479 }
4402 goto search_again; 4480 goto search_again;
4403 } else { 4481 } else {
4404 path->slots[0]--; 4482 path->slots[0]--;
@@ -4415,7 +4493,18 @@ error:
4415 if (last_size != (u64)-1 && 4493 if (last_size != (u64)-1 &&
4416 root->root_key.objectid != BTRFS_TREE_LOG_OBJECTID) 4494 root->root_key.objectid != BTRFS_TREE_LOG_OBJECTID)
4417 btrfs_ordered_update_i_size(inode, last_size, NULL); 4495 btrfs_ordered_update_i_size(inode, last_size, NULL);
4496
4418 btrfs_free_path(path); 4497 btrfs_free_path(path);
4498
4499 if (be_nice && bytes_deleted > 32 * 1024 * 1024) {
4500 unsigned long updates = trans->delayed_ref_updates;
4501 if (updates) {
4502 trans->delayed_ref_updates = 0;
4503 ret = btrfs_run_delayed_refs(trans, root, updates * 2);
4504 if (ret && !err)
4505 err = ret;
4506 }
4507 }
4419 return err; 4508 return err;
4420} 4509}
4421 4510
@@ -4826,7 +4915,7 @@ static int btrfs_setsize(struct inode *inode, struct iattr *attr)
4826 4915
4827static int btrfs_setattr(struct dentry *dentry, struct iattr *attr) 4916static int btrfs_setattr(struct dentry *dentry, struct iattr *attr)
4828{ 4917{
4829 struct inode *inode = dentry->d_inode; 4918 struct inode *inode = d_inode(dentry);
4830 struct btrfs_root *root = BTRFS_I(inode)->root; 4919 struct btrfs_root *root = BTRFS_I(inode)->root;
4831 int err; 4920 int err;
4832 4921
@@ -4924,6 +5013,7 @@ void btrfs_evict_inode(struct inode *inode)
4924 struct btrfs_trans_handle *trans; 5013 struct btrfs_trans_handle *trans;
4925 struct btrfs_root *root = BTRFS_I(inode)->root; 5014 struct btrfs_root *root = BTRFS_I(inode)->root;
4926 struct btrfs_block_rsv *rsv, *global_rsv; 5015 struct btrfs_block_rsv *rsv, *global_rsv;
5016 int steal_from_global = 0;
4927 u64 min_size = btrfs_calc_trunc_metadata_size(root, 1); 5017 u64 min_size = btrfs_calc_trunc_metadata_size(root, 1);
4928 int ret; 5018 int ret;
4929 5019
@@ -4991,9 +5081,20 @@ void btrfs_evict_inode(struct inode *inode)
4991 * hard as possible to get this to work. 5081 * hard as possible to get this to work.
4992 */ 5082 */
4993 if (ret) 5083 if (ret)
4994 ret = btrfs_block_rsv_migrate(global_rsv, rsv, min_size); 5084 steal_from_global++;
5085 else
5086 steal_from_global = 0;
5087 ret = 0;
4995 5088
4996 if (ret) { 5089 /*
5090 * steal_from_global == 0: we reserved stuff, hooray!
5091 * steal_from_global == 1: we didn't reserve stuff, boo!
5092 * steal_from_global == 2: we've committed, still not a lot of
5093 * room but maybe we'll have room in the global reserve this
5094 * time.
5095 * steal_from_global == 3: abandon all hope!
5096 */
5097 if (steal_from_global > 2) {
4997 btrfs_warn(root->fs_info, 5098 btrfs_warn(root->fs_info,
4998 "Could not get space for a delete, will truncate on mount %d", 5099 "Could not get space for a delete, will truncate on mount %d",
4999 ret); 5100 ret);
@@ -5009,10 +5110,40 @@ void btrfs_evict_inode(struct inode *inode)
5009 goto no_delete; 5110 goto no_delete;
5010 } 5111 }
5011 5112
5113 /*
5114 * We can't just steal from the global reserve, we need tomake
5115 * sure there is room to do it, if not we need to commit and try
5116 * again.
5117 */
5118 if (steal_from_global) {
5119 if (!btrfs_check_space_for_delayed_refs(trans, root))
5120 ret = btrfs_block_rsv_migrate(global_rsv, rsv,
5121 min_size);
5122 else
5123 ret = -ENOSPC;
5124 }
5125
5126 /*
5127 * Couldn't steal from the global reserve, we have too much
5128 * pending stuff built up, commit the transaction and try it
5129 * again.
5130 */
5131 if (ret) {
5132 ret = btrfs_commit_transaction(trans, root);
5133 if (ret) {
5134 btrfs_orphan_del(NULL, inode);
5135 btrfs_free_block_rsv(root, rsv);
5136 goto no_delete;
5137 }
5138 continue;
5139 } else {
5140 steal_from_global = 0;
5141 }
5142
5012 trans->block_rsv = rsv; 5143 trans->block_rsv = rsv;
5013 5144
5014 ret = btrfs_truncate_inode_items(trans, root, inode, 0, 0); 5145 ret = btrfs_truncate_inode_items(trans, root, inode, 0, 0);
5015 if (ret != -ENOSPC) 5146 if (ret != -ENOSPC && ret != -EAGAIN)
5016 break; 5147 break;
5017 5148
5018 trans->block_rsv = &root->fs_info->trans_block_rsv; 5149 trans->block_rsv = &root->fs_info->trans_block_rsv;
@@ -5416,10 +5547,10 @@ struct inode *btrfs_lookup_dentry(struct inode *dir, struct dentry *dentry)
5416static int btrfs_dentry_delete(const struct dentry *dentry) 5547static int btrfs_dentry_delete(const struct dentry *dentry)
5417{ 5548{
5418 struct btrfs_root *root; 5549 struct btrfs_root *root;
5419 struct inode *inode = dentry->d_inode; 5550 struct inode *inode = d_inode(dentry);
5420 5551
5421 if (!inode && !IS_ROOT(dentry)) 5552 if (!inode && !IS_ROOT(dentry))
5422 inode = dentry->d_parent->d_inode; 5553 inode = d_inode(dentry->d_parent);
5423 5554
5424 if (inode) { 5555 if (inode) {
5425 root = BTRFS_I(inode)->root; 5556 root = BTRFS_I(inode)->root;
@@ -6226,7 +6357,7 @@ static int btrfs_link(struct dentry *old_dentry, struct inode *dir,
6226{ 6357{
6227 struct btrfs_trans_handle *trans; 6358 struct btrfs_trans_handle *trans;
6228 struct btrfs_root *root = BTRFS_I(dir)->root; 6359 struct btrfs_root *root = BTRFS_I(dir)->root;
6229 struct inode *inode = old_dentry->d_inode; 6360 struct inode *inode = d_inode(old_dentry);
6230 u64 index; 6361 u64 index;
6231 int err; 6362 int err;
6232 int drop_inode = 0; 6363 int drop_inode = 0;
@@ -8129,7 +8260,7 @@ static ssize_t btrfs_direct_IO(struct kiocb *iocb, struct iov_iter *iter,
8129 if (check_direct_IO(BTRFS_I(inode)->root, iocb, iter, offset)) 8260 if (check_direct_IO(BTRFS_I(inode)->root, iocb, iter, offset))
8130 return 0; 8261 return 0;
8131 8262
8132 atomic_inc(&inode->i_dio_count); 8263 inode_dio_begin(inode);
8133 smp_mb__after_atomic(); 8264 smp_mb__after_atomic();
8134 8265
8135 /* 8266 /*
@@ -8169,7 +8300,7 @@ static ssize_t btrfs_direct_IO(struct kiocb *iocb, struct iov_iter *iter,
8169 current->journal_info = &outstanding_extents; 8300 current->journal_info = &outstanding_extents;
8170 } else if (test_bit(BTRFS_INODE_READDIO_NEED_LOCK, 8301 } else if (test_bit(BTRFS_INODE_READDIO_NEED_LOCK,
8171 &BTRFS_I(inode)->runtime_flags)) { 8302 &BTRFS_I(inode)->runtime_flags)) {
8172 inode_dio_done(inode); 8303 inode_dio_end(inode);
8173 flags = DIO_LOCKING | DIO_SKIP_HOLES; 8304 flags = DIO_LOCKING | DIO_SKIP_HOLES;
8174 wakeup = false; 8305 wakeup = false;
8175 } 8306 }
@@ -8188,7 +8319,7 @@ static ssize_t btrfs_direct_IO(struct kiocb *iocb, struct iov_iter *iter,
8188 } 8319 }
8189out: 8320out:
8190 if (wakeup) 8321 if (wakeup)
8191 inode_dio_done(inode); 8322 inode_dio_end(inode);
8192 if (relock) 8323 if (relock)
8193 mutex_lock(&inode->i_mutex); 8324 mutex_lock(&inode->i_mutex);
8194 8325
@@ -8581,7 +8712,7 @@ static int btrfs_truncate(struct inode *inode)
8581 ret = btrfs_truncate_inode_items(trans, root, inode, 8712 ret = btrfs_truncate_inode_items(trans, root, inode,
8582 inode->i_size, 8713 inode->i_size,
8583 BTRFS_EXTENT_DATA_KEY); 8714 BTRFS_EXTENT_DATA_KEY);
8584 if (ret != -ENOSPC) { 8715 if (ret != -ENOSPC && ret != -EAGAIN) {
8585 err = ret; 8716 err = ret;
8586 break; 8717 break;
8587 } 8718 }
@@ -8875,7 +9006,7 @@ static int btrfs_getattr(struct vfsmount *mnt,
8875 struct dentry *dentry, struct kstat *stat) 9006 struct dentry *dentry, struct kstat *stat)
8876{ 9007{
8877 u64 delalloc_bytes; 9008 u64 delalloc_bytes;
8878 struct inode *inode = dentry->d_inode; 9009 struct inode *inode = d_inode(dentry);
8879 u32 blocksize = inode->i_sb->s_blocksize; 9010 u32 blocksize = inode->i_sb->s_blocksize;
8880 9011
8881 generic_fillattr(inode, stat); 9012 generic_fillattr(inode, stat);
@@ -8896,8 +9027,8 @@ static int btrfs_rename(struct inode *old_dir, struct dentry *old_dentry,
8896 struct btrfs_trans_handle *trans; 9027 struct btrfs_trans_handle *trans;
8897 struct btrfs_root *root = BTRFS_I(old_dir)->root; 9028 struct btrfs_root *root = BTRFS_I(old_dir)->root;
8898 struct btrfs_root *dest = BTRFS_I(new_dir)->root; 9029 struct btrfs_root *dest = BTRFS_I(new_dir)->root;
8899 struct inode *new_inode = new_dentry->d_inode; 9030 struct inode *new_inode = d_inode(new_dentry);
8900 struct inode *old_inode = old_dentry->d_inode; 9031 struct inode *old_inode = d_inode(old_dentry);
8901 struct timespec ctime = CURRENT_TIME; 9032 struct timespec ctime = CURRENT_TIME;
8902 u64 index = 0; 9033 u64 index = 0;
8903 u64 root_objectid; 9034 u64 root_objectid;
@@ -9009,7 +9140,7 @@ static int btrfs_rename(struct inode *old_dir, struct dentry *old_dentry,
9009 old_dentry->d_name.len); 9140 old_dentry->d_name.len);
9010 } else { 9141 } else {
9011 ret = __btrfs_unlink_inode(trans, root, old_dir, 9142 ret = __btrfs_unlink_inode(trans, root, old_dir,
9012 old_dentry->d_inode, 9143 d_inode(old_dentry),
9013 old_dentry->d_name.name, 9144 old_dentry->d_name.name,
9014 old_dentry->d_name.len); 9145 old_dentry->d_name.len);
9015 if (!ret) 9146 if (!ret)
@@ -9033,12 +9164,12 @@ static int btrfs_rename(struct inode *old_dir, struct dentry *old_dentry,
9033 BUG_ON(new_inode->i_nlink == 0); 9164 BUG_ON(new_inode->i_nlink == 0);
9034 } else { 9165 } else {
9035 ret = btrfs_unlink_inode(trans, dest, new_dir, 9166 ret = btrfs_unlink_inode(trans, dest, new_dir,
9036 new_dentry->d_inode, 9167 d_inode(new_dentry),
9037 new_dentry->d_name.name, 9168 new_dentry->d_name.name,
9038 new_dentry->d_name.len); 9169 new_dentry->d_name.len);
9039 } 9170 }
9040 if (!ret && new_inode->i_nlink == 0) 9171 if (!ret && new_inode->i_nlink == 0)
9041 ret = btrfs_orphan_add(trans, new_dentry->d_inode); 9172 ret = btrfs_orphan_add(trans, d_inode(new_dentry));
9042 if (ret) { 9173 if (ret) {
9043 btrfs_abort_transaction(trans, root, ret); 9174 btrfs_abort_transaction(trans, root, ret);
9044 goto out_fail; 9175 goto out_fail;
@@ -9451,6 +9582,7 @@ static int __btrfs_prealloc_file_range(struct inode *inode, int mode,
9451 btrfs_end_transaction(trans, root); 9582 btrfs_end_transaction(trans, root);
9452 break; 9583 break;
9453 } 9584 }
9585
9454 btrfs_drop_extent_cache(inode, cur_offset, 9586 btrfs_drop_extent_cache(inode, cur_offset,
9455 cur_offset + ins.offset -1, 0); 9587 cur_offset + ins.offset -1, 0);
9456 9588
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 74609b931ba5..b05653f182c2 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -456,6 +456,13 @@ static noinline int create_subvol(struct inode *dir,
456 if (ret) 456 if (ret)
457 return ret; 457 return ret;
458 458
459 /*
460 * Don't create subvolume whose level is not zero. Or qgroup will be
461 * screwed up since it assume subvolme qgroup's level to be 0.
462 */
463 if (btrfs_qgroup_level(objectid))
464 return -ENOSPC;
465
459 btrfs_init_block_rsv(&block_rsv, BTRFS_BLOCK_RSV_TEMP); 466 btrfs_init_block_rsv(&block_rsv, BTRFS_BLOCK_RSV_TEMP);
460 /* 467 /*
461 * The same as the snapshot creation, please see the comment 468 * The same as the snapshot creation, please see the comment
@@ -717,7 +724,7 @@ static int create_snapshot(struct btrfs_root *root, struct inode *dir,
717 if (ret) 724 if (ret)
718 goto fail; 725 goto fail;
719 726
720 inode = btrfs_lookup_dentry(dentry->d_parent->d_inode, dentry); 727 inode = btrfs_lookup_dentry(d_inode(dentry->d_parent), dentry);
721 if (IS_ERR(inode)) { 728 if (IS_ERR(inode)) {
722 ret = PTR_ERR(inode); 729 ret = PTR_ERR(inode);
723 goto fail; 730 goto fail;
@@ -761,10 +768,10 @@ static int btrfs_may_delete(struct inode *dir, struct dentry *victim, int isdir)
761{ 768{
762 int error; 769 int error;
763 770
764 if (!victim->d_inode) 771 if (d_really_is_negative(victim))
765 return -ENOENT; 772 return -ENOENT;
766 773
767 BUG_ON(victim->d_parent->d_inode != dir); 774 BUG_ON(d_inode(victim->d_parent) != dir);
768 audit_inode_child(dir, victim, AUDIT_TYPE_CHILD_DELETE); 775 audit_inode_child(dir, victim, AUDIT_TYPE_CHILD_DELETE);
769 776
770 error = inode_permission(dir, MAY_WRITE | MAY_EXEC); 777 error = inode_permission(dir, MAY_WRITE | MAY_EXEC);
@@ -772,8 +779,8 @@ static int btrfs_may_delete(struct inode *dir, struct dentry *victim, int isdir)
772 return error; 779 return error;
773 if (IS_APPEND(dir)) 780 if (IS_APPEND(dir))
774 return -EPERM; 781 return -EPERM;
775 if (check_sticky(dir, victim->d_inode) || IS_APPEND(victim->d_inode) || 782 if (check_sticky(dir, d_inode(victim)) || IS_APPEND(d_inode(victim)) ||
776 IS_IMMUTABLE(victim->d_inode) || IS_SWAPFILE(victim->d_inode)) 783 IS_IMMUTABLE(d_inode(victim)) || IS_SWAPFILE(d_inode(victim)))
777 return -EPERM; 784 return -EPERM;
778 if (isdir) { 785 if (isdir) {
779 if (!d_is_dir(victim)) 786 if (!d_is_dir(victim))
@@ -792,7 +799,7 @@ static int btrfs_may_delete(struct inode *dir, struct dentry *victim, int isdir)
792/* copy of may_create in fs/namei.c() */ 799/* copy of may_create in fs/namei.c() */
793static inline int btrfs_may_create(struct inode *dir, struct dentry *child) 800static inline int btrfs_may_create(struct inode *dir, struct dentry *child)
794{ 801{
795 if (child->d_inode) 802 if (d_really_is_positive(child))
796 return -EEXIST; 803 return -EEXIST;
797 if (IS_DEADDIR(dir)) 804 if (IS_DEADDIR(dir))
798 return -ENOENT; 805 return -ENOENT;
@@ -810,7 +817,7 @@ static noinline int btrfs_mksubvol(struct path *parent,
810 u64 *async_transid, bool readonly, 817 u64 *async_transid, bool readonly,
811 struct btrfs_qgroup_inherit *inherit) 818 struct btrfs_qgroup_inherit *inherit)
812{ 819{
813 struct inode *dir = parent->dentry->d_inode; 820 struct inode *dir = d_inode(parent->dentry);
814 struct dentry *dentry; 821 struct dentry *dentry;
815 int error; 822 int error;
816 823
@@ -824,7 +831,7 @@ static noinline int btrfs_mksubvol(struct path *parent,
824 goto out_unlock; 831 goto out_unlock;
825 832
826 error = -EEXIST; 833 error = -EEXIST;
827 if (dentry->d_inode) 834 if (d_really_is_positive(dentry))
828 goto out_dput; 835 goto out_dput;
829 836
830 error = btrfs_may_create(dir, dentry); 837 error = btrfs_may_create(dir, dentry);
@@ -1564,7 +1571,7 @@ static noinline int btrfs_ioctl_resize(struct file *file,
1564 goto out_free; 1571 goto out_free;
1565 } 1572 }
1566 1573
1567 do_div(new_size, root->sectorsize); 1574 new_size = div_u64(new_size, root->sectorsize);
1568 new_size *= root->sectorsize; 1575 new_size *= root->sectorsize;
1569 1576
1570 printk_in_rcu(KERN_INFO "BTRFS: new size for %s is %llu\n", 1577 printk_in_rcu(KERN_INFO "BTRFS: new size for %s is %llu\n",
@@ -2294,7 +2301,7 @@ static noinline int btrfs_ioctl_snap_destroy(struct file *file,
2294{ 2301{
2295 struct dentry *parent = file->f_path.dentry; 2302 struct dentry *parent = file->f_path.dentry;
2296 struct dentry *dentry; 2303 struct dentry *dentry;
2297 struct inode *dir = parent->d_inode; 2304 struct inode *dir = d_inode(parent);
2298 struct inode *inode; 2305 struct inode *inode;
2299 struct btrfs_root *root = BTRFS_I(dir)->root; 2306 struct btrfs_root *root = BTRFS_I(dir)->root;
2300 struct btrfs_root *dest = NULL; 2307 struct btrfs_root *dest = NULL;
@@ -2333,12 +2340,12 @@ static noinline int btrfs_ioctl_snap_destroy(struct file *file,
2333 goto out_unlock_dir; 2340 goto out_unlock_dir;
2334 } 2341 }
2335 2342
2336 if (!dentry->d_inode) { 2343 if (d_really_is_negative(dentry)) {
2337 err = -ENOENT; 2344 err = -ENOENT;
2338 goto out_dput; 2345 goto out_dput;
2339 } 2346 }
2340 2347
2341 inode = dentry->d_inode; 2348 inode = d_inode(dentry);
2342 dest = BTRFS_I(inode)->root; 2349 dest = BTRFS_I(inode)->root;
2343 if (!capable(CAP_SYS_ADMIN)) { 2350 if (!capable(CAP_SYS_ADMIN)) {
2344 /* 2351 /*
@@ -2897,6 +2904,9 @@ static int btrfs_extent_same(struct inode *src, u64 loff, u64 len,
2897 if (src == dst) 2904 if (src == dst)
2898 return -EINVAL; 2905 return -EINVAL;
2899 2906
2907 if (len == 0)
2908 return 0;
2909
2900 btrfs_double_lock(src, loff, dst, dst_loff, len); 2910 btrfs_double_lock(src, loff, dst, dst_loff, len);
2901 2911
2902 ret = extent_same_check_offsets(src, loff, len); 2912 ret = extent_same_check_offsets(src, loff, len);
@@ -3039,7 +3049,7 @@ out:
3039static int check_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root, 3049static int check_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
3040 u64 disko) 3050 u64 disko)
3041{ 3051{
3042 struct seq_list tree_mod_seq_elem = {}; 3052 struct seq_list tree_mod_seq_elem = SEQ_LIST_INIT(tree_mod_seq_elem);
3043 struct ulist *roots; 3053 struct ulist *roots;
3044 struct ulist_iterator uiter; 3054 struct ulist_iterator uiter;
3045 struct ulist_node *root_node = NULL; 3055 struct ulist_node *root_node = NULL;
@@ -3202,6 +3212,8 @@ static int btrfs_clone(struct inode *src, struct inode *inode,
3202 key.offset = off; 3212 key.offset = off;
3203 3213
3204 while (1) { 3214 while (1) {
3215 u64 next_key_min_offset = key.offset + 1;
3216
3205 /* 3217 /*
3206 * note the key will change type as we walk through the 3218 * note the key will change type as we walk through the
3207 * tree. 3219 * tree.
@@ -3282,7 +3294,7 @@ process_slot:
3282 } else if (key.offset >= off + len) { 3294 } else if (key.offset >= off + len) {
3283 break; 3295 break;
3284 } 3296 }
3285 3297 next_key_min_offset = key.offset + datal;
3286 size = btrfs_item_size_nr(leaf, slot); 3298 size = btrfs_item_size_nr(leaf, slot);
3287 read_extent_buffer(leaf, buf, 3299 read_extent_buffer(leaf, buf,
3288 btrfs_item_ptr_offset(leaf, slot), 3300 btrfs_item_ptr_offset(leaf, slot),
@@ -3497,7 +3509,7 @@ process_slot:
3497 break; 3509 break;
3498 } 3510 }
3499 btrfs_release_path(path); 3511 btrfs_release_path(path);
3500 key.offset++; 3512 key.offset = next_key_min_offset;
3501 } 3513 }
3502 ret = 0; 3514 ret = 0;
3503 3515
@@ -3626,6 +3638,11 @@ static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd,
3626 if (off + len == src->i_size) 3638 if (off + len == src->i_size)
3627 len = ALIGN(src->i_size, bs) - off; 3639 len = ALIGN(src->i_size, bs) - off;
3628 3640
3641 if (len == 0) {
3642 ret = 0;
3643 goto out_unlock;
3644 }
3645
3629 /* verify the end result is block aligned */ 3646 /* verify the end result is block aligned */
3630 if (!IS_ALIGNED(off, bs) || !IS_ALIGNED(off + len, bs) || 3647 if (!IS_ALIGNED(off, bs) || !IS_ALIGNED(off + len, bs) ||
3631 !IS_ALIGNED(destoff, bs)) 3648 !IS_ALIGNED(destoff, bs))
@@ -4624,6 +4641,11 @@ static long btrfs_ioctl_qgroup_assign(struct file *file, void __user *arg)
4624 sa->src, sa->dst); 4641 sa->src, sa->dst);
4625 } 4642 }
4626 4643
4644 /* update qgroup status and info */
4645 err = btrfs_run_qgroups(trans, root->fs_info);
4646 if (err < 0)
4647 btrfs_error(root->fs_info, ret,
4648 "failed to update qgroup status and info\n");
4627 err = btrfs_end_transaction(trans, root); 4649 err = btrfs_end_transaction(trans, root);
4628 if (err && !ret) 4650 if (err && !ret)
4629 ret = err; 4651 ret = err;
@@ -4669,8 +4691,7 @@ static long btrfs_ioctl_qgroup_create(struct file *file, void __user *arg)
4669 4691
4670 /* FIXME: check if the IDs really exist */ 4692 /* FIXME: check if the IDs really exist */
4671 if (sa->create) { 4693 if (sa->create) {
4672 ret = btrfs_create_qgroup(trans, root->fs_info, sa->qgroupid, 4694 ret = btrfs_create_qgroup(trans, root->fs_info, sa->qgroupid);
4673 NULL);
4674 } else { 4695 } else {
4675 ret = btrfs_remove_qgroup(trans, root->fs_info, sa->qgroupid); 4696 ret = btrfs_remove_qgroup(trans, root->fs_info, sa->qgroupid);
4676 } 4697 }
diff --git a/fs/btrfs/lzo.c b/fs/btrfs/lzo.c
index 617553cdb7d3..a2f051347731 100644
--- a/fs/btrfs/lzo.c
+++ b/fs/btrfs/lzo.c
@@ -434,7 +434,7 @@ out:
434 return ret; 434 return ret;
435} 435}
436 436
437struct btrfs_compress_op btrfs_lzo_compress = { 437const struct btrfs_compress_op btrfs_lzo_compress = {
438 .alloc_workspace = lzo_alloc_workspace, 438 .alloc_workspace = lzo_alloc_workspace,
439 .free_workspace = lzo_free_workspace, 439 .free_workspace = lzo_free_workspace,
440 .compress_pages = lzo_compress_pages, 440 .compress_pages = lzo_compress_pages,
diff --git a/fs/btrfs/math.h b/fs/btrfs/math.h
index b7816cefbd13..1b10a3cd1195 100644
--- a/fs/btrfs/math.h
+++ b/fs/btrfs/math.h
@@ -28,8 +28,7 @@ static inline u64 div_factor(u64 num, int factor)
28 if (factor == 10) 28 if (factor == 10)
29 return num; 29 return num;
30 num *= factor; 30 num *= factor;
31 do_div(num, 10); 31 return div_u64(num, 10);
32 return num;
33} 32}
34 33
35static inline u64 div_factor_fine(u64 num, int factor) 34static inline u64 div_factor_fine(u64 num, int factor)
@@ -37,8 +36,7 @@ static inline u64 div_factor_fine(u64 num, int factor)
37 if (factor == 100) 36 if (factor == 100)
38 return num; 37 return num;
39 num *= factor; 38 num *= factor;
40 do_div(num, 100); 39 return div_u64(num, 100);
41 return num;
42} 40}
43 41
44#endif 42#endif
diff --git a/fs/btrfs/props.c b/fs/btrfs/props.c
index 129b1dd28527..dca137b04095 100644
--- a/fs/btrfs/props.c
+++ b/fs/btrfs/props.c
@@ -425,3 +425,5 @@ static const char *prop_compression_extract(struct inode *inode)
425 425
426 return NULL; 426 return NULL;
427} 427}
428
429
diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c
index 058c79eecbfb..3d6546581bb9 100644
--- a/fs/btrfs/qgroup.c
+++ b/fs/btrfs/qgroup.c
@@ -644,9 +644,8 @@ out:
644} 644}
645 645
646static int update_qgroup_limit_item(struct btrfs_trans_handle *trans, 646static int update_qgroup_limit_item(struct btrfs_trans_handle *trans,
647 struct btrfs_root *root, u64 qgroupid, 647 struct btrfs_root *root,
648 u64 flags, u64 max_rfer, u64 max_excl, 648 struct btrfs_qgroup *qgroup)
649 u64 rsv_rfer, u64 rsv_excl)
650{ 649{
651 struct btrfs_path *path; 650 struct btrfs_path *path;
652 struct btrfs_key key; 651 struct btrfs_key key;
@@ -657,7 +656,7 @@ static int update_qgroup_limit_item(struct btrfs_trans_handle *trans,
657 656
658 key.objectid = 0; 657 key.objectid = 0;
659 key.type = BTRFS_QGROUP_LIMIT_KEY; 658 key.type = BTRFS_QGROUP_LIMIT_KEY;
660 key.offset = qgroupid; 659 key.offset = qgroup->qgroupid;
661 660
662 path = btrfs_alloc_path(); 661 path = btrfs_alloc_path();
663 if (!path) 662 if (!path)
@@ -673,11 +672,11 @@ static int update_qgroup_limit_item(struct btrfs_trans_handle *trans,
673 l = path->nodes[0]; 672 l = path->nodes[0];
674 slot = path->slots[0]; 673 slot = path->slots[0];
675 qgroup_limit = btrfs_item_ptr(l, slot, struct btrfs_qgroup_limit_item); 674 qgroup_limit = btrfs_item_ptr(l, slot, struct btrfs_qgroup_limit_item);
676 btrfs_set_qgroup_limit_flags(l, qgroup_limit, flags); 675 btrfs_set_qgroup_limit_flags(l, qgroup_limit, qgroup->lim_flags);
677 btrfs_set_qgroup_limit_max_rfer(l, qgroup_limit, max_rfer); 676 btrfs_set_qgroup_limit_max_rfer(l, qgroup_limit, qgroup->max_rfer);
678 btrfs_set_qgroup_limit_max_excl(l, qgroup_limit, max_excl); 677 btrfs_set_qgroup_limit_max_excl(l, qgroup_limit, qgroup->max_excl);
679 btrfs_set_qgroup_limit_rsv_rfer(l, qgroup_limit, rsv_rfer); 678 btrfs_set_qgroup_limit_rsv_rfer(l, qgroup_limit, qgroup->rsv_rfer);
680 btrfs_set_qgroup_limit_rsv_excl(l, qgroup_limit, rsv_excl); 679 btrfs_set_qgroup_limit_rsv_excl(l, qgroup_limit, qgroup->rsv_excl);
681 680
682 btrfs_mark_buffer_dirty(l); 681 btrfs_mark_buffer_dirty(l);
683 682
@@ -967,6 +966,7 @@ int btrfs_quota_disable(struct btrfs_trans_handle *trans,
967 fs_info->pending_quota_state = 0; 966 fs_info->pending_quota_state = 0;
968 quota_root = fs_info->quota_root; 967 quota_root = fs_info->quota_root;
969 fs_info->quota_root = NULL; 968 fs_info->quota_root = NULL;
969 fs_info->qgroup_flags &= ~BTRFS_QGROUP_STATUS_FLAG_ON;
970 spin_unlock(&fs_info->qgroup_lock); 970 spin_unlock(&fs_info->qgroup_lock);
971 971
972 btrfs_free_qgroup_config(fs_info); 972 btrfs_free_qgroup_config(fs_info);
@@ -982,7 +982,7 @@ int btrfs_quota_disable(struct btrfs_trans_handle *trans,
982 list_del(&quota_root->dirty_list); 982 list_del(&quota_root->dirty_list);
983 983
984 btrfs_tree_lock(quota_root->node); 984 btrfs_tree_lock(quota_root->node);
985 clean_tree_block(trans, tree_root, quota_root->node); 985 clean_tree_block(trans, tree_root->fs_info, quota_root->node);
986 btrfs_tree_unlock(quota_root->node); 986 btrfs_tree_unlock(quota_root->node);
987 btrfs_free_tree_block(trans, quota_root, quota_root->node, 0, 1); 987 btrfs_free_tree_block(trans, quota_root, quota_root->node, 0, 1);
988 988
@@ -1001,6 +1001,110 @@ static void qgroup_dirty(struct btrfs_fs_info *fs_info,
1001 list_add(&qgroup->dirty, &fs_info->dirty_qgroups); 1001 list_add(&qgroup->dirty, &fs_info->dirty_qgroups);
1002} 1002}
1003 1003
1004/*
1005 * The easy accounting, if we are adding/removing the only ref for an extent
1006 * then this qgroup and all of the parent qgroups get their refrence and
1007 * exclusive counts adjusted.
1008 *
1009 * Caller should hold fs_info->qgroup_lock.
1010 */
1011static int __qgroup_excl_accounting(struct btrfs_fs_info *fs_info,
1012 struct ulist *tmp, u64 ref_root,
1013 u64 num_bytes, int sign)
1014{
1015 struct btrfs_qgroup *qgroup;
1016 struct btrfs_qgroup_list *glist;
1017 struct ulist_node *unode;
1018 struct ulist_iterator uiter;
1019 int ret = 0;
1020
1021 qgroup = find_qgroup_rb(fs_info, ref_root);
1022 if (!qgroup)
1023 goto out;
1024
1025 qgroup->rfer += sign * num_bytes;
1026 qgroup->rfer_cmpr += sign * num_bytes;
1027
1028 WARN_ON(sign < 0 && qgroup->excl < num_bytes);
1029 qgroup->excl += sign * num_bytes;
1030 qgroup->excl_cmpr += sign * num_bytes;
1031 if (sign > 0)
1032 qgroup->reserved -= num_bytes;
1033
1034 qgroup_dirty(fs_info, qgroup);
1035
1036 /* Get all of the parent groups that contain this qgroup */
1037 list_for_each_entry(glist, &qgroup->groups, next_group) {
1038 ret = ulist_add(tmp, glist->group->qgroupid,
1039 ptr_to_u64(glist->group), GFP_ATOMIC);
1040 if (ret < 0)
1041 goto out;
1042 }
1043
1044 /* Iterate all of the parents and adjust their reference counts */
1045 ULIST_ITER_INIT(&uiter);
1046 while ((unode = ulist_next(tmp, &uiter))) {
1047 qgroup = u64_to_ptr(unode->aux);
1048 qgroup->rfer += sign * num_bytes;
1049 qgroup->rfer_cmpr += sign * num_bytes;
1050 WARN_ON(sign < 0 && qgroup->excl < num_bytes);
1051 qgroup->excl += sign * num_bytes;
1052 if (sign > 0)
1053 qgroup->reserved -= num_bytes;
1054 qgroup->excl_cmpr += sign * num_bytes;
1055 qgroup_dirty(fs_info, qgroup);
1056
1057 /* Add any parents of the parents */
1058 list_for_each_entry(glist, &qgroup->groups, next_group) {
1059 ret = ulist_add(tmp, glist->group->qgroupid,
1060 ptr_to_u64(glist->group), GFP_ATOMIC);
1061 if (ret < 0)
1062 goto out;
1063 }
1064 }
1065 ret = 0;
1066out:
1067 return ret;
1068}
1069
1070
1071/*
1072 * Quick path for updating qgroup with only excl refs.
1073 *
1074 * In that case, just update all parent will be enough.
1075 * Or we needs to do a full rescan.
1076 * Caller should also hold fs_info->qgroup_lock.
1077 *
1078 * Return 0 for quick update, return >0 for need to full rescan
1079 * and mark INCONSISTENT flag.
1080 * Return < 0 for other error.
1081 */
1082static int quick_update_accounting(struct btrfs_fs_info *fs_info,
1083 struct ulist *tmp, u64 src, u64 dst,
1084 int sign)
1085{
1086 struct btrfs_qgroup *qgroup;
1087 int ret = 1;
1088 int err = 0;
1089
1090 qgroup = find_qgroup_rb(fs_info, src);
1091 if (!qgroup)
1092 goto out;
1093 if (qgroup->excl == qgroup->rfer) {
1094 ret = 0;
1095 err = __qgroup_excl_accounting(fs_info, tmp, dst,
1096 qgroup->excl, sign);
1097 if (err < 0) {
1098 ret = err;
1099 goto out;
1100 }
1101 }
1102out:
1103 if (ret)
1104 fs_info->qgroup_flags |= BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT;
1105 return ret;
1106}
1107
1004int btrfs_add_qgroup_relation(struct btrfs_trans_handle *trans, 1108int btrfs_add_qgroup_relation(struct btrfs_trans_handle *trans,
1005 struct btrfs_fs_info *fs_info, u64 src, u64 dst) 1109 struct btrfs_fs_info *fs_info, u64 src, u64 dst)
1006{ 1110{
@@ -1008,8 +1112,17 @@ int btrfs_add_qgroup_relation(struct btrfs_trans_handle *trans,
1008 struct btrfs_qgroup *parent; 1112 struct btrfs_qgroup *parent;
1009 struct btrfs_qgroup *member; 1113 struct btrfs_qgroup *member;
1010 struct btrfs_qgroup_list *list; 1114 struct btrfs_qgroup_list *list;
1115 struct ulist *tmp;
1011 int ret = 0; 1116 int ret = 0;
1012 1117
1118 tmp = ulist_alloc(GFP_NOFS);
1119 if (!tmp)
1120 return -ENOMEM;
1121
1122 /* Check the level of src and dst first */
1123 if (btrfs_qgroup_level(src) >= btrfs_qgroup_level(dst))
1124 return -EINVAL;
1125
1013 mutex_lock(&fs_info->qgroup_ioctl_lock); 1126 mutex_lock(&fs_info->qgroup_ioctl_lock);
1014 quota_root = fs_info->quota_root; 1127 quota_root = fs_info->quota_root;
1015 if (!quota_root) { 1128 if (!quota_root) {
@@ -1043,23 +1156,33 @@ int btrfs_add_qgroup_relation(struct btrfs_trans_handle *trans,
1043 1156
1044 spin_lock(&fs_info->qgroup_lock); 1157 spin_lock(&fs_info->qgroup_lock);
1045 ret = add_relation_rb(quota_root->fs_info, src, dst); 1158 ret = add_relation_rb(quota_root->fs_info, src, dst);
1159 if (ret < 0) {
1160 spin_unlock(&fs_info->qgroup_lock);
1161 goto out;
1162 }
1163 ret = quick_update_accounting(fs_info, tmp, src, dst, 1);
1046 spin_unlock(&fs_info->qgroup_lock); 1164 spin_unlock(&fs_info->qgroup_lock);
1047out: 1165out:
1048 mutex_unlock(&fs_info->qgroup_ioctl_lock); 1166 mutex_unlock(&fs_info->qgroup_ioctl_lock);
1167 ulist_free(tmp);
1049 return ret; 1168 return ret;
1050} 1169}
1051 1170
1052int btrfs_del_qgroup_relation(struct btrfs_trans_handle *trans, 1171int __del_qgroup_relation(struct btrfs_trans_handle *trans,
1053 struct btrfs_fs_info *fs_info, u64 src, u64 dst) 1172 struct btrfs_fs_info *fs_info, u64 src, u64 dst)
1054{ 1173{
1055 struct btrfs_root *quota_root; 1174 struct btrfs_root *quota_root;
1056 struct btrfs_qgroup *parent; 1175 struct btrfs_qgroup *parent;
1057 struct btrfs_qgroup *member; 1176 struct btrfs_qgroup *member;
1058 struct btrfs_qgroup_list *list; 1177 struct btrfs_qgroup_list *list;
1178 struct ulist *tmp;
1059 int ret = 0; 1179 int ret = 0;
1060 int err; 1180 int err;
1061 1181
1062 mutex_lock(&fs_info->qgroup_ioctl_lock); 1182 tmp = ulist_alloc(GFP_NOFS);
1183 if (!tmp)
1184 return -ENOMEM;
1185
1063 quota_root = fs_info->quota_root; 1186 quota_root = fs_info->quota_root;
1064 if (!quota_root) { 1187 if (!quota_root) {
1065 ret = -EINVAL; 1188 ret = -EINVAL;
@@ -1088,14 +1211,27 @@ exist:
1088 1211
1089 spin_lock(&fs_info->qgroup_lock); 1212 spin_lock(&fs_info->qgroup_lock);
1090 del_relation_rb(fs_info, src, dst); 1213 del_relation_rb(fs_info, src, dst);
1214 ret = quick_update_accounting(fs_info, tmp, src, dst, -1);
1091 spin_unlock(&fs_info->qgroup_lock); 1215 spin_unlock(&fs_info->qgroup_lock);
1092out: 1216out:
1217 ulist_free(tmp);
1218 return ret;
1219}
1220
1221int btrfs_del_qgroup_relation(struct btrfs_trans_handle *trans,
1222 struct btrfs_fs_info *fs_info, u64 src, u64 dst)
1223{
1224 int ret = 0;
1225
1226 mutex_lock(&fs_info->qgroup_ioctl_lock);
1227 ret = __del_qgroup_relation(trans, fs_info, src, dst);
1093 mutex_unlock(&fs_info->qgroup_ioctl_lock); 1228 mutex_unlock(&fs_info->qgroup_ioctl_lock);
1229
1094 return ret; 1230 return ret;
1095} 1231}
1096 1232
1097int btrfs_create_qgroup(struct btrfs_trans_handle *trans, 1233int btrfs_create_qgroup(struct btrfs_trans_handle *trans,
1098 struct btrfs_fs_info *fs_info, u64 qgroupid, char *name) 1234 struct btrfs_fs_info *fs_info, u64 qgroupid)
1099{ 1235{
1100 struct btrfs_root *quota_root; 1236 struct btrfs_root *quota_root;
1101 struct btrfs_qgroup *qgroup; 1237 struct btrfs_qgroup *qgroup;
@@ -1133,6 +1269,7 @@ int btrfs_remove_qgroup(struct btrfs_trans_handle *trans,
1133{ 1269{
1134 struct btrfs_root *quota_root; 1270 struct btrfs_root *quota_root;
1135 struct btrfs_qgroup *qgroup; 1271 struct btrfs_qgroup *qgroup;
1272 struct btrfs_qgroup_list *list;
1136 int ret = 0; 1273 int ret = 0;
1137 1274
1138 mutex_lock(&fs_info->qgroup_ioctl_lock); 1275 mutex_lock(&fs_info->qgroup_ioctl_lock);
@@ -1147,15 +1284,24 @@ int btrfs_remove_qgroup(struct btrfs_trans_handle *trans,
1147 ret = -ENOENT; 1284 ret = -ENOENT;
1148 goto out; 1285 goto out;
1149 } else { 1286 } else {
1150 /* check if there are no relations to this qgroup */ 1287 /* check if there are no children of this qgroup */
1151 if (!list_empty(&qgroup->groups) || 1288 if (!list_empty(&qgroup->members)) {
1152 !list_empty(&qgroup->members)) {
1153 ret = -EBUSY; 1289 ret = -EBUSY;
1154 goto out; 1290 goto out;
1155 } 1291 }
1156 } 1292 }
1157 ret = del_qgroup_item(trans, quota_root, qgroupid); 1293 ret = del_qgroup_item(trans, quota_root, qgroupid);
1158 1294
1295 while (!list_empty(&qgroup->groups)) {
1296 list = list_first_entry(&qgroup->groups,
1297 struct btrfs_qgroup_list, next_group);
1298 ret = __del_qgroup_relation(trans, fs_info,
1299 qgroupid,
1300 list->group->qgroupid);
1301 if (ret)
1302 goto out;
1303 }
1304
1159 spin_lock(&fs_info->qgroup_lock); 1305 spin_lock(&fs_info->qgroup_lock);
1160 del_qgroup_rb(quota_root->fs_info, qgroupid); 1306 del_qgroup_rb(quota_root->fs_info, qgroupid);
1161 spin_unlock(&fs_info->qgroup_lock); 1307 spin_unlock(&fs_info->qgroup_lock);
@@ -1184,23 +1330,27 @@ int btrfs_limit_qgroup(struct btrfs_trans_handle *trans,
1184 ret = -ENOENT; 1330 ret = -ENOENT;
1185 goto out; 1331 goto out;
1186 } 1332 }
1187 ret = update_qgroup_limit_item(trans, quota_root, qgroupid, 1333
1188 limit->flags, limit->max_rfer, 1334 spin_lock(&fs_info->qgroup_lock);
1189 limit->max_excl, limit->rsv_rfer, 1335 if (limit->flags & BTRFS_QGROUP_LIMIT_MAX_RFER)
1190 limit->rsv_excl); 1336 qgroup->max_rfer = limit->max_rfer;
1337 if (limit->flags & BTRFS_QGROUP_LIMIT_MAX_EXCL)
1338 qgroup->max_excl = limit->max_excl;
1339 if (limit->flags & BTRFS_QGROUP_LIMIT_RSV_RFER)
1340 qgroup->rsv_rfer = limit->rsv_rfer;
1341 if (limit->flags & BTRFS_QGROUP_LIMIT_RSV_EXCL)
1342 qgroup->rsv_excl = limit->rsv_excl;
1343 qgroup->lim_flags |= limit->flags;
1344
1345 spin_unlock(&fs_info->qgroup_lock);
1346
1347 ret = update_qgroup_limit_item(trans, quota_root, qgroup);
1191 if (ret) { 1348 if (ret) {
1192 fs_info->qgroup_flags |= BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT; 1349 fs_info->qgroup_flags |= BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT;
1193 btrfs_info(fs_info, "unable to update quota limit for %llu", 1350 btrfs_info(fs_info, "unable to update quota limit for %llu",
1194 qgroupid); 1351 qgroupid);
1195 } 1352 }
1196 1353
1197 spin_lock(&fs_info->qgroup_lock);
1198 qgroup->lim_flags = limit->flags;
1199 qgroup->max_rfer = limit->max_rfer;
1200 qgroup->max_excl = limit->max_excl;
1201 qgroup->rsv_rfer = limit->rsv_rfer;
1202 qgroup->rsv_excl = limit->rsv_excl;
1203 spin_unlock(&fs_info->qgroup_lock);
1204out: 1354out:
1205 mutex_unlock(&fs_info->qgroup_ioctl_lock); 1355 mutex_unlock(&fs_info->qgroup_ioctl_lock);
1206 return ret; 1356 return ret;
@@ -1256,14 +1406,14 @@ static int comp_oper(struct btrfs_qgroup_operation *oper1,
1256 return -1; 1406 return -1;
1257 if (oper1->bytenr > oper2->bytenr) 1407 if (oper1->bytenr > oper2->bytenr)
1258 return 1; 1408 return 1;
1259 if (oper1->seq < oper2->seq)
1260 return -1;
1261 if (oper1->seq > oper2->seq)
1262 return 1;
1263 if (oper1->ref_root < oper2->ref_root) 1409 if (oper1->ref_root < oper2->ref_root)
1264 return -1; 1410 return -1;
1265 if (oper1->ref_root > oper2->ref_root) 1411 if (oper1->ref_root > oper2->ref_root)
1266 return 1; 1412 return 1;
1413 if (oper1->seq < oper2->seq)
1414 return -1;
1415 if (oper1->seq > oper2->seq)
1416 return 1;
1267 if (oper1->type < oper2->type) 1417 if (oper1->type < oper2->type)
1268 return -1; 1418 return -1;
1269 if (oper1->type > oper2->type) 1419 if (oper1->type > oper2->type)
@@ -1372,19 +1522,10 @@ int btrfs_qgroup_record_ref(struct btrfs_trans_handle *trans,
1372 return 0; 1522 return 0;
1373} 1523}
1374 1524
1375/*
1376 * The easy accounting, if we are adding/removing the only ref for an extent
1377 * then this qgroup and all of the parent qgroups get their refrence and
1378 * exclusive counts adjusted.
1379 */
1380static int qgroup_excl_accounting(struct btrfs_fs_info *fs_info, 1525static int qgroup_excl_accounting(struct btrfs_fs_info *fs_info,
1381 struct btrfs_qgroup_operation *oper) 1526 struct btrfs_qgroup_operation *oper)
1382{ 1527{
1383 struct btrfs_qgroup *qgroup;
1384 struct ulist *tmp; 1528 struct ulist *tmp;
1385 struct btrfs_qgroup_list *glist;
1386 struct ulist_node *unode;
1387 struct ulist_iterator uiter;
1388 int sign = 0; 1529 int sign = 0;
1389 int ret = 0; 1530 int ret = 0;
1390 1531
@@ -1395,9 +1536,7 @@ static int qgroup_excl_accounting(struct btrfs_fs_info *fs_info,
1395 spin_lock(&fs_info->qgroup_lock); 1536 spin_lock(&fs_info->qgroup_lock);
1396 if (!fs_info->quota_root) 1537 if (!fs_info->quota_root)
1397 goto out; 1538 goto out;
1398 qgroup = find_qgroup_rb(fs_info, oper->ref_root); 1539
1399 if (!qgroup)
1400 goto out;
1401 switch (oper->type) { 1540 switch (oper->type) {
1402 case BTRFS_QGROUP_OPER_ADD_EXCL: 1541 case BTRFS_QGROUP_OPER_ADD_EXCL:
1403 sign = 1; 1542 sign = 1;
@@ -1408,43 +1547,8 @@ static int qgroup_excl_accounting(struct btrfs_fs_info *fs_info,
1408 default: 1547 default:
1409 ASSERT(0); 1548 ASSERT(0);
1410 } 1549 }
1411 qgroup->rfer += sign * oper->num_bytes; 1550 ret = __qgroup_excl_accounting(fs_info, tmp, oper->ref_root,
1412 qgroup->rfer_cmpr += sign * oper->num_bytes; 1551 oper->num_bytes, sign);
1413
1414 WARN_ON(sign < 0 && qgroup->excl < oper->num_bytes);
1415 qgroup->excl += sign * oper->num_bytes;
1416 qgroup->excl_cmpr += sign * oper->num_bytes;
1417
1418 qgroup_dirty(fs_info, qgroup);
1419
1420 /* Get all of the parent groups that contain this qgroup */
1421 list_for_each_entry(glist, &qgroup->groups, next_group) {
1422 ret = ulist_add(tmp, glist->group->qgroupid,
1423 ptr_to_u64(glist->group), GFP_ATOMIC);
1424 if (ret < 0)
1425 goto out;
1426 }
1427
1428 /* Iterate all of the parents and adjust their reference counts */
1429 ULIST_ITER_INIT(&uiter);
1430 while ((unode = ulist_next(tmp, &uiter))) {
1431 qgroup = u64_to_ptr(unode->aux);
1432 qgroup->rfer += sign * oper->num_bytes;
1433 qgroup->rfer_cmpr += sign * oper->num_bytes;
1434 WARN_ON(sign < 0 && qgroup->excl < oper->num_bytes);
1435 qgroup->excl += sign * oper->num_bytes;
1436 qgroup->excl_cmpr += sign * oper->num_bytes;
1437 qgroup_dirty(fs_info, qgroup);
1438
1439 /* Add any parents of the parents */
1440 list_for_each_entry(glist, &qgroup->groups, next_group) {
1441 ret = ulist_add(tmp, glist->group->qgroupid,
1442 ptr_to_u64(glist->group), GFP_ATOMIC);
1443 if (ret < 0)
1444 goto out;
1445 }
1446 }
1447 ret = 0;
1448out: 1552out:
1449 spin_unlock(&fs_info->qgroup_lock); 1553 spin_unlock(&fs_info->qgroup_lock);
1450 ulist_free(tmp); 1554 ulist_free(tmp);
@@ -1845,7 +1949,7 @@ static int qgroup_shared_accounting(struct btrfs_trans_handle *trans,
1845 struct ulist *roots = NULL; 1949 struct ulist *roots = NULL;
1846 struct ulist *qgroups, *tmp; 1950 struct ulist *qgroups, *tmp;
1847 struct btrfs_qgroup *qgroup; 1951 struct btrfs_qgroup *qgroup;
1848 struct seq_list elem = {}; 1952 struct seq_list elem = SEQ_LIST_INIT(elem);
1849 u64 seq; 1953 u64 seq;
1850 int old_roots = 0; 1954 int old_roots = 0;
1851 int new_roots = 0; 1955 int new_roots = 0;
@@ -1967,7 +2071,7 @@ static int qgroup_subtree_accounting(struct btrfs_trans_handle *trans,
1967 int err; 2071 int err;
1968 struct btrfs_qgroup *qg; 2072 struct btrfs_qgroup *qg;
1969 u64 root_obj = 0; 2073 u64 root_obj = 0;
1970 struct seq_list elem = {}; 2074 struct seq_list elem = SEQ_LIST_INIT(elem);
1971 2075
1972 parents = ulist_alloc(GFP_NOFS); 2076 parents = ulist_alloc(GFP_NOFS);
1973 if (!parents) 2077 if (!parents)
@@ -2156,6 +2260,10 @@ int btrfs_run_qgroups(struct btrfs_trans_handle *trans,
2156 if (ret) 2260 if (ret)
2157 fs_info->qgroup_flags |= 2261 fs_info->qgroup_flags |=
2158 BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT; 2262 BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT;
2263 ret = update_qgroup_limit_item(trans, quota_root, qgroup);
2264 if (ret)
2265 fs_info->qgroup_flags |=
2266 BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT;
2159 spin_lock(&fs_info->qgroup_lock); 2267 spin_lock(&fs_info->qgroup_lock);
2160 } 2268 }
2161 if (fs_info->quota_enabled) 2269 if (fs_info->quota_enabled)
@@ -2219,6 +2327,11 @@ int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans,
2219 ret = -EINVAL; 2327 ret = -EINVAL;
2220 goto out; 2328 goto out;
2221 } 2329 }
2330
2331 if ((srcgroup->qgroupid >> 48) <= (objectid >> 48)) {
2332 ret = -EINVAL;
2333 goto out;
2334 }
2222 ++i_qgroups; 2335 ++i_qgroups;
2223 } 2336 }
2224 } 2337 }
@@ -2230,17 +2343,6 @@ int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans,
2230 if (ret) 2343 if (ret)
2231 goto out; 2344 goto out;
2232 2345
2233 if (inherit && inherit->flags & BTRFS_QGROUP_INHERIT_SET_LIMITS) {
2234 ret = update_qgroup_limit_item(trans, quota_root, objectid,
2235 inherit->lim.flags,
2236 inherit->lim.max_rfer,
2237 inherit->lim.max_excl,
2238 inherit->lim.rsv_rfer,
2239 inherit->lim.rsv_excl);
2240 if (ret)
2241 goto out;
2242 }
2243
2244 if (srcid) { 2346 if (srcid) {
2245 struct btrfs_root *srcroot; 2347 struct btrfs_root *srcroot;
2246 struct btrfs_key srckey; 2348 struct btrfs_key srckey;
@@ -2286,6 +2388,22 @@ int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans,
2286 goto unlock; 2388 goto unlock;
2287 } 2389 }
2288 2390
2391 if (inherit && inherit->flags & BTRFS_QGROUP_INHERIT_SET_LIMITS) {
2392 dstgroup->lim_flags = inherit->lim.flags;
2393 dstgroup->max_rfer = inherit->lim.max_rfer;
2394 dstgroup->max_excl = inherit->lim.max_excl;
2395 dstgroup->rsv_rfer = inherit->lim.rsv_rfer;
2396 dstgroup->rsv_excl = inherit->lim.rsv_excl;
2397
2398 ret = update_qgroup_limit_item(trans, quota_root, dstgroup);
2399 if (ret) {
2400 fs_info->qgroup_flags |= BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT;
2401 btrfs_info(fs_info, "unable to update quota limit for %llu",
2402 dstgroup->qgroupid);
2403 goto unlock;
2404 }
2405 }
2406
2289 if (srcid) { 2407 if (srcid) {
2290 srcgroup = find_qgroup_rb(fs_info, srcid); 2408 srcgroup = find_qgroup_rb(fs_info, srcid);
2291 if (!srcgroup) 2409 if (!srcgroup)
@@ -2302,6 +2420,14 @@ int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans,
2302 dstgroup->excl_cmpr = level_size; 2420 dstgroup->excl_cmpr = level_size;
2303 srcgroup->excl = level_size; 2421 srcgroup->excl = level_size;
2304 srcgroup->excl_cmpr = level_size; 2422 srcgroup->excl_cmpr = level_size;
2423
2424 /* inherit the limit info */
2425 dstgroup->lim_flags = srcgroup->lim_flags;
2426 dstgroup->max_rfer = srcgroup->max_rfer;
2427 dstgroup->max_excl = srcgroup->max_excl;
2428 dstgroup->rsv_rfer = srcgroup->rsv_rfer;
2429 dstgroup->rsv_excl = srcgroup->rsv_excl;
2430
2305 qgroup_dirty(fs_info, dstgroup); 2431 qgroup_dirty(fs_info, dstgroup);
2306 qgroup_dirty(fs_info, srcgroup); 2432 qgroup_dirty(fs_info, srcgroup);
2307 } 2433 }
@@ -2358,12 +2484,6 @@ out:
2358 return ret; 2484 return ret;
2359} 2485}
2360 2486
2361/*
2362 * reserve some space for a qgroup and all its parents. The reservation takes
2363 * place with start_transaction or dealloc_reserve, similar to ENOSPC
2364 * accounting. If not enough space is available, EDQUOT is returned.
2365 * We assume that the requested space is new for all qgroups.
2366 */
2367int btrfs_qgroup_reserve(struct btrfs_root *root, u64 num_bytes) 2487int btrfs_qgroup_reserve(struct btrfs_root *root, u64 num_bytes)
2368{ 2488{
2369 struct btrfs_root *quota_root; 2489 struct btrfs_root *quota_root;
@@ -2513,7 +2633,7 @@ void assert_qgroups_uptodate(struct btrfs_trans_handle *trans)
2513 2633
2514/* 2634/*
2515 * returns < 0 on error, 0 when more leafs are to be scanned. 2635 * returns < 0 on error, 0 when more leafs are to be scanned.
2516 * returns 1 when done, 2 when done and FLAG_INCONSISTENT was cleared. 2636 * returns 1 when done.
2517 */ 2637 */
2518static int 2638static int
2519qgroup_rescan_leaf(struct btrfs_fs_info *fs_info, struct btrfs_path *path, 2639qgroup_rescan_leaf(struct btrfs_fs_info *fs_info, struct btrfs_path *path,
@@ -2522,7 +2642,7 @@ qgroup_rescan_leaf(struct btrfs_fs_info *fs_info, struct btrfs_path *path,
2522{ 2642{
2523 struct btrfs_key found; 2643 struct btrfs_key found;
2524 struct ulist *roots = NULL; 2644 struct ulist *roots = NULL;
2525 struct seq_list tree_mod_seq_elem = {}; 2645 struct seq_list tree_mod_seq_elem = SEQ_LIST_INIT(tree_mod_seq_elem);
2526 u64 num_bytes; 2646 u64 num_bytes;
2527 u64 seq; 2647 u64 seq;
2528 int new_roots; 2648 int new_roots;
@@ -2618,6 +2738,7 @@ static void btrfs_qgroup_rescan_worker(struct btrfs_work *work)
2618 struct ulist *tmp = NULL, *qgroups = NULL; 2738 struct ulist *tmp = NULL, *qgroups = NULL;
2619 struct extent_buffer *scratch_leaf = NULL; 2739 struct extent_buffer *scratch_leaf = NULL;
2620 int err = -ENOMEM; 2740 int err = -ENOMEM;
2741 int ret = 0;
2621 2742
2622 path = btrfs_alloc_path(); 2743 path = btrfs_alloc_path();
2623 if (!path) 2744 if (!path)
@@ -2660,7 +2781,7 @@ out:
2660 mutex_lock(&fs_info->qgroup_rescan_lock); 2781 mutex_lock(&fs_info->qgroup_rescan_lock);
2661 fs_info->qgroup_flags &= ~BTRFS_QGROUP_STATUS_FLAG_RESCAN; 2782 fs_info->qgroup_flags &= ~BTRFS_QGROUP_STATUS_FLAG_RESCAN;
2662 2783
2663 if (err == 2 && 2784 if (err > 0 &&
2664 fs_info->qgroup_flags & BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT) { 2785 fs_info->qgroup_flags & BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT) {
2665 fs_info->qgroup_flags &= ~BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT; 2786 fs_info->qgroup_flags &= ~BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT;
2666 } else if (err < 0) { 2787 } else if (err < 0) {
@@ -2668,13 +2789,33 @@ out:
2668 } 2789 }
2669 mutex_unlock(&fs_info->qgroup_rescan_lock); 2790 mutex_unlock(&fs_info->qgroup_rescan_lock);
2670 2791
2792 /*
2793 * only update status, since the previous part has alreay updated the
2794 * qgroup info.
2795 */
2796 trans = btrfs_start_transaction(fs_info->quota_root, 1);
2797 if (IS_ERR(trans)) {
2798 err = PTR_ERR(trans);
2799 btrfs_err(fs_info,
2800 "fail to start transaction for status update: %d\n",
2801 err);
2802 goto done;
2803 }
2804 ret = update_qgroup_status_item(trans, fs_info, fs_info->quota_root);
2805 if (ret < 0) {
2806 err = ret;
2807 btrfs_err(fs_info, "fail to update qgroup status: %d\n", err);
2808 }
2809 btrfs_end_transaction(trans, fs_info->quota_root);
2810
2671 if (err >= 0) { 2811 if (err >= 0) {
2672 btrfs_info(fs_info, "qgroup scan completed%s", 2812 btrfs_info(fs_info, "qgroup scan completed%s",
2673 err == 2 ? " (inconsistency flag cleared)" : ""); 2813 err > 0 ? " (inconsistency flag cleared)" : "");
2674 } else { 2814 } else {
2675 btrfs_err(fs_info, "qgroup scan failed with %d", err); 2815 btrfs_err(fs_info, "qgroup scan failed with %d", err);
2676 } 2816 }
2677 2817
2818done:
2678 complete_all(&fs_info->qgroup_rescan_completion); 2819 complete_all(&fs_info->qgroup_rescan_completion);
2679} 2820}
2680 2821
@@ -2709,7 +2850,6 @@ qgroup_rescan_init(struct btrfs_fs_info *fs_info, u64 progress_objectid,
2709 mutex_unlock(&fs_info->qgroup_rescan_lock); 2850 mutex_unlock(&fs_info->qgroup_rescan_lock);
2710 goto err; 2851 goto err;
2711 } 2852 }
2712
2713 fs_info->qgroup_flags |= BTRFS_QGROUP_STATUS_FLAG_RESCAN; 2853 fs_info->qgroup_flags |= BTRFS_QGROUP_STATUS_FLAG_RESCAN;
2714 } 2854 }
2715 2855
diff --git a/fs/btrfs/qgroup.h b/fs/btrfs/qgroup.h
index 18cc68ca3090..c5242aa9a4b2 100644
--- a/fs/btrfs/qgroup.h
+++ b/fs/btrfs/qgroup.h
@@ -70,8 +70,7 @@ int btrfs_add_qgroup_relation(struct btrfs_trans_handle *trans,
70int btrfs_del_qgroup_relation(struct btrfs_trans_handle *trans, 70int btrfs_del_qgroup_relation(struct btrfs_trans_handle *trans,
71 struct btrfs_fs_info *fs_info, u64 src, u64 dst); 71 struct btrfs_fs_info *fs_info, u64 src, u64 dst);
72int btrfs_create_qgroup(struct btrfs_trans_handle *trans, 72int btrfs_create_qgroup(struct btrfs_trans_handle *trans,
73 struct btrfs_fs_info *fs_info, u64 qgroupid, 73 struct btrfs_fs_info *fs_info, u64 qgroupid);
74 char *name);
75int btrfs_remove_qgroup(struct btrfs_trans_handle *trans, 74int btrfs_remove_qgroup(struct btrfs_trans_handle *trans,
76 struct btrfs_fs_info *fs_info, u64 qgroupid); 75 struct btrfs_fs_info *fs_info, u64 qgroupid);
77int btrfs_limit_qgroup(struct btrfs_trans_handle *trans, 76int btrfs_limit_qgroup(struct btrfs_trans_handle *trans,
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
index 5264858ed768..fa72068bd256 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
@@ -237,12 +237,8 @@ int btrfs_alloc_stripe_hash_table(struct btrfs_fs_info *info)
237 } 237 }
238 238
239 x = cmpxchg(&info->stripe_hash_table, NULL, table); 239 x = cmpxchg(&info->stripe_hash_table, NULL, table);
240 if (x) { 240 if (x)
241 if (is_vmalloc_addr(x)) 241 kvfree(x);
242 vfree(x);
243 else
244 kfree(x);
245 }
246 return 0; 242 return 0;
247} 243}
248 244
@@ -453,10 +449,7 @@ void btrfs_free_stripe_hash_table(struct btrfs_fs_info *info)
453 if (!info->stripe_hash_table) 449 if (!info->stripe_hash_table)
454 return; 450 return;
455 btrfs_clear_rbio_cache(info); 451 btrfs_clear_rbio_cache(info);
456 if (is_vmalloc_addr(info->stripe_hash_table)) 452 kvfree(info->stripe_hash_table);
457 vfree(info->stripe_hash_table);
458 else
459 kfree(info->stripe_hash_table);
460 info->stripe_hash_table = NULL; 453 info->stripe_hash_table = NULL;
461} 454}
462 455
@@ -1807,8 +1800,7 @@ static void __raid_recover_end_io(struct btrfs_raid_bio *rbio)
1807 int err; 1800 int err;
1808 int i; 1801 int i;
1809 1802
1810 pointers = kzalloc(rbio->real_stripes * sizeof(void *), 1803 pointers = kcalloc(rbio->real_stripes, sizeof(void *), GFP_NOFS);
1811 GFP_NOFS);
1812 if (!pointers) { 1804 if (!pointers) {
1813 err = -ENOMEM; 1805 err = -ENOMEM;
1814 goto cleanup_io; 1806 goto cleanup_io;
diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index d83085381bcc..74b24b01d574 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -3027,7 +3027,7 @@ int prealloc_file_extent_cluster(struct inode *inode,
3027 mutex_lock(&inode->i_mutex); 3027 mutex_lock(&inode->i_mutex);
3028 3028
3029 ret = btrfs_check_data_free_space(inode, cluster->end + 3029 ret = btrfs_check_data_free_space(inode, cluster->end +
3030 1 - cluster->start); 3030 1 - cluster->start, 0);
3031 if (ret) 3031 if (ret)
3032 goto out; 3032 goto out;
3033 3033
@@ -3430,7 +3430,9 @@ static int block_use_full_backref(struct reloc_control *rc,
3430} 3430}
3431 3431
3432static int delete_block_group_cache(struct btrfs_fs_info *fs_info, 3432static int delete_block_group_cache(struct btrfs_fs_info *fs_info,
3433 struct inode *inode, u64 ino) 3433 struct btrfs_block_group_cache *block_group,
3434 struct inode *inode,
3435 u64 ino)
3434{ 3436{
3435 struct btrfs_key key; 3437 struct btrfs_key key;
3436 struct btrfs_root *root = fs_info->tree_root; 3438 struct btrfs_root *root = fs_info->tree_root;
@@ -3463,7 +3465,7 @@ truncate:
3463 goto out; 3465 goto out;
3464 } 3466 }
3465 3467
3466 ret = btrfs_truncate_free_space_cache(root, trans, inode); 3468 ret = btrfs_truncate_free_space_cache(root, trans, block_group, inode);
3467 3469
3468 btrfs_end_transaction(trans, root); 3470 btrfs_end_transaction(trans, root);
3469 btrfs_btree_balance_dirty(root); 3471 btrfs_btree_balance_dirty(root);
@@ -3509,6 +3511,7 @@ static int find_data_references(struct reloc_control *rc,
3509 */ 3511 */
3510 if (ref_root == BTRFS_ROOT_TREE_OBJECTID) { 3512 if (ref_root == BTRFS_ROOT_TREE_OBJECTID) {
3511 ret = delete_block_group_cache(rc->extent_root->fs_info, 3513 ret = delete_block_group_cache(rc->extent_root->fs_info,
3514 rc->block_group,
3512 NULL, ref_objectid); 3515 NULL, ref_objectid);
3513 if (ret != -ENOENT) 3516 if (ret != -ENOENT)
3514 return ret; 3517 return ret;
@@ -4223,7 +4226,7 @@ int btrfs_relocate_block_group(struct btrfs_root *extent_root, u64 group_start)
4223 btrfs_free_path(path); 4226 btrfs_free_path(path);
4224 4227
4225 if (!IS_ERR(inode)) 4228 if (!IS_ERR(inode))
4226 ret = delete_block_group_cache(fs_info, inode, 0); 4229 ret = delete_block_group_cache(fs_info, rc->block_group, inode, 0);
4227 else 4230 else
4228 ret = PTR_ERR(inode); 4231 ret = PTR_ERR(inode);
4229 4232
diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
index ec57687c9a4d..ab5811545a98 100644
--- a/fs/btrfs/scrub.c
+++ b/fs/btrfs/scrub.c
@@ -964,9 +964,8 @@ static int scrub_handle_errored_block(struct scrub_block *sblock_to_check)
964 * the statistics. 964 * the statistics.
965 */ 965 */
966 966
967 sblocks_for_recheck = kzalloc(BTRFS_MAX_MIRRORS * 967 sblocks_for_recheck = kcalloc(BTRFS_MAX_MIRRORS,
968 sizeof(*sblocks_for_recheck), 968 sizeof(*sblocks_for_recheck), GFP_NOFS);
969 GFP_NOFS);
970 if (!sblocks_for_recheck) { 969 if (!sblocks_for_recheck) {
971 spin_lock(&sctx->stat_lock); 970 spin_lock(&sctx->stat_lock);
972 sctx->stat.malloc_errors++; 971 sctx->stat.malloc_errors++;
@@ -2319,7 +2318,7 @@ static inline void __scrub_mark_bitmap(struct scrub_parity *sparity,
2319 unsigned long *bitmap, 2318 unsigned long *bitmap,
2320 u64 start, u64 len) 2319 u64 start, u64 len)
2321{ 2320{
2322 int offset; 2321 u32 offset;
2323 int nsectors; 2322 int nsectors;
2324 int sectorsize = sparity->sctx->dev_root->sectorsize; 2323 int sectorsize = sparity->sctx->dev_root->sectorsize;
2325 2324
@@ -2329,7 +2328,7 @@ static inline void __scrub_mark_bitmap(struct scrub_parity *sparity,
2329 } 2328 }
2330 2329
2331 start -= sparity->logic_start; 2330 start -= sparity->logic_start;
2332 offset = (int)do_div(start, sparity->stripe_len); 2331 start = div_u64_rem(start, sparity->stripe_len, &offset);
2333 offset /= sectorsize; 2332 offset /= sectorsize;
2334 nsectors = (int)len / sectorsize; 2333 nsectors = (int)len / sectorsize;
2335 2334
@@ -2612,8 +2611,8 @@ static int get_raid56_logic_offset(u64 physical, int num,
2612 int j = 0; 2611 int j = 0;
2613 u64 stripe_nr; 2612 u64 stripe_nr;
2614 u64 last_offset; 2613 u64 last_offset;
2615 int stripe_index; 2614 u32 stripe_index;
2616 int rot; 2615 u32 rot;
2617 2616
2618 last_offset = (physical - map->stripes[num].physical) * 2617 last_offset = (physical - map->stripes[num].physical) *
2619 nr_data_stripes(map); 2618 nr_data_stripes(map);
@@ -2624,12 +2623,11 @@ static int get_raid56_logic_offset(u64 physical, int num,
2624 for (i = 0; i < nr_data_stripes(map); i++) { 2623 for (i = 0; i < nr_data_stripes(map); i++) {
2625 *offset = last_offset + i * map->stripe_len; 2624 *offset = last_offset + i * map->stripe_len;
2626 2625
2627 stripe_nr = *offset; 2626 stripe_nr = div_u64(*offset, map->stripe_len);
2628 do_div(stripe_nr, map->stripe_len); 2627 stripe_nr = div_u64(stripe_nr, nr_data_stripes(map));
2629 do_div(stripe_nr, nr_data_stripes(map));
2630 2628
2631 /* Work out the disk rotation on this stripe-set */ 2629 /* Work out the disk rotation on this stripe-set */
2632 rot = do_div(stripe_nr, map->num_stripes); 2630 stripe_nr = div_u64_rem(stripe_nr, map->num_stripes, &rot);
2633 /* calculate which stripe this data locates */ 2631 /* calculate which stripe this data locates */
2634 rot += i; 2632 rot += i;
2635 stripe_index = rot % map->num_stripes; 2633 stripe_index = rot % map->num_stripes;
@@ -2995,10 +2993,9 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx,
2995 int extent_mirror_num; 2993 int extent_mirror_num;
2996 int stop_loop = 0; 2994 int stop_loop = 0;
2997 2995
2998 nstripes = length;
2999 physical = map->stripes[num].physical; 2996 physical = map->stripes[num].physical;
3000 offset = 0; 2997 offset = 0;
3001 do_div(nstripes, map->stripe_len); 2998 nstripes = div_u64(length, map->stripe_len);
3002 if (map->type & BTRFS_BLOCK_GROUP_RAID0) { 2999 if (map->type & BTRFS_BLOCK_GROUP_RAID0) {
3003 offset = map->stripe_len * num; 3000 offset = map->stripe_len * num;
3004 increment = map->stripe_len * map->num_stripes; 3001 increment = map->stripe_len * map->num_stripes;
@@ -3563,7 +3560,7 @@ static noinline_for_stack int scrub_workers_get(struct btrfs_fs_info *fs_info,
3563 int is_dev_replace) 3560 int is_dev_replace)
3564{ 3561{
3565 int ret = 0; 3562 int ret = 0;
3566 int flags = WQ_FREEZABLE | WQ_UNBOUND; 3563 unsigned int flags = WQ_FREEZABLE | WQ_UNBOUND;
3567 int max_active = fs_info->thread_pool_size; 3564 int max_active = fs_info->thread_pool_size;
3568 3565
3569 if (fs_info->scrub_workers_refcnt == 0) { 3566 if (fs_info->scrub_workers_refcnt == 0) {
diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c
index d6033f540cc7..a1216f9b4917 100644
--- a/fs/btrfs/send.c
+++ b/fs/btrfs/send.c
@@ -3067,48 +3067,6 @@ static struct pending_dir_move *get_pending_dir_moves(struct send_ctx *sctx,
3067 return NULL; 3067 return NULL;
3068} 3068}
3069 3069
3070static int path_loop(struct send_ctx *sctx, struct fs_path *name,
3071 u64 ino, u64 gen, u64 *ancestor_ino)
3072{
3073 int ret = 0;
3074 u64 parent_inode = 0;
3075 u64 parent_gen = 0;
3076 u64 start_ino = ino;
3077
3078 *ancestor_ino = 0;
3079 while (ino != BTRFS_FIRST_FREE_OBJECTID) {
3080 fs_path_reset(name);
3081
3082 if (is_waiting_for_rm(sctx, ino))
3083 break;
3084 if (is_waiting_for_move(sctx, ino)) {
3085 if (*ancestor_ino == 0)
3086 *ancestor_ino = ino;
3087 ret = get_first_ref(sctx->parent_root, ino,
3088 &parent_inode, &parent_gen, name);
3089 } else {
3090 ret = __get_cur_name_and_parent(sctx, ino, gen,
3091 &parent_inode,
3092 &parent_gen, name);
3093 if (ret > 0) {
3094 ret = 0;
3095 break;
3096 }
3097 }
3098 if (ret < 0)
3099 break;
3100 if (parent_inode == start_ino) {
3101 ret = 1;
3102 if (*ancestor_ino == 0)
3103 *ancestor_ino = ino;
3104 break;
3105 }
3106 ino = parent_inode;
3107 gen = parent_gen;
3108 }
3109 return ret;
3110}
3111
3112static int apply_dir_move(struct send_ctx *sctx, struct pending_dir_move *pm) 3070static int apply_dir_move(struct send_ctx *sctx, struct pending_dir_move *pm)
3113{ 3071{
3114 struct fs_path *from_path = NULL; 3072 struct fs_path *from_path = NULL;
@@ -3120,7 +3078,6 @@ static int apply_dir_move(struct send_ctx *sctx, struct pending_dir_move *pm)
3120 struct waiting_dir_move *dm = NULL; 3078 struct waiting_dir_move *dm = NULL;
3121 u64 rmdir_ino = 0; 3079 u64 rmdir_ino = 0;
3122 int ret; 3080 int ret;
3123 u64 ancestor = 0;
3124 3081
3125 name = fs_path_alloc(); 3082 name = fs_path_alloc();
3126 from_path = fs_path_alloc(); 3083 from_path = fs_path_alloc();
@@ -3152,22 +3109,6 @@ static int apply_dir_move(struct send_ctx *sctx, struct pending_dir_move *pm)
3152 goto out; 3109 goto out;
3153 3110
3154 sctx->send_progress = sctx->cur_ino + 1; 3111 sctx->send_progress = sctx->cur_ino + 1;
3155 ret = path_loop(sctx, name, pm->ino, pm->gen, &ancestor);
3156 if (ret) {
3157 LIST_HEAD(deleted_refs);
3158 ASSERT(ancestor > BTRFS_FIRST_FREE_OBJECTID);
3159 ret = add_pending_dir_move(sctx, pm->ino, pm->gen, ancestor,
3160 &pm->update_refs, &deleted_refs,
3161 pm->is_orphan);
3162 if (ret < 0)
3163 goto out;
3164 if (rmdir_ino) {
3165 dm = get_waiting_dir_move(sctx, pm->ino);
3166 ASSERT(dm);
3167 dm->rmdir_ino = rmdir_ino;
3168 }
3169 goto out;
3170 }
3171 fs_path_reset(name); 3112 fs_path_reset(name);
3172 to_path = name; 3113 to_path = name;
3173 name = NULL; 3114 name = NULL;
@@ -3610,10 +3551,27 @@ verbose_printk("btrfs: process_recorded_refs %llu\n", sctx->cur_ino);
3610 if (ret < 0) 3551 if (ret < 0)
3611 goto out; 3552 goto out;
3612 if (ret) { 3553 if (ret) {
3554 struct name_cache_entry *nce;
3555
3613 ret = orphanize_inode(sctx, ow_inode, ow_gen, 3556 ret = orphanize_inode(sctx, ow_inode, ow_gen,
3614 cur->full_path); 3557 cur->full_path);
3615 if (ret < 0) 3558 if (ret < 0)
3616 goto out; 3559 goto out;
3560 /*
3561 * Make sure we clear our orphanized inode's
3562 * name from the name cache. This is because the
3563 * inode ow_inode might be an ancestor of some
3564 * other inode that will be orphanized as well
3565 * later and has an inode number greater than
3566 * sctx->send_progress. We need to prevent
3567 * future name lookups from using the old name
3568 * and get instead the orphan name.
3569 */
3570 nce = name_cache_search(sctx, ow_inode, ow_gen);
3571 if (nce) {
3572 name_cache_delete(sctx, nce);
3573 kfree(nce);
3574 }
3617 } else { 3575 } else {
3618 ret = send_unlink(sctx, cur->full_path); 3576 ret = send_unlink(sctx, cur->full_path);
3619 if (ret < 0) 3577 if (ret < 0)
@@ -5852,19 +5810,20 @@ long btrfs_ioctl_send(struct file *mnt_file, void __user *arg_)
5852 ret = PTR_ERR(clone_root); 5810 ret = PTR_ERR(clone_root);
5853 goto out; 5811 goto out;
5854 } 5812 }
5855 clone_sources_to_rollback = i + 1;
5856 spin_lock(&clone_root->root_item_lock); 5813 spin_lock(&clone_root->root_item_lock);
5857 clone_root->send_in_progress++; 5814 if (!btrfs_root_readonly(clone_root) ||
5858 if (!btrfs_root_readonly(clone_root)) { 5815 btrfs_root_dead(clone_root)) {
5859 spin_unlock(&clone_root->root_item_lock); 5816 spin_unlock(&clone_root->root_item_lock);
5860 srcu_read_unlock(&fs_info->subvol_srcu, index); 5817 srcu_read_unlock(&fs_info->subvol_srcu, index);
5861 ret = -EPERM; 5818 ret = -EPERM;
5862 goto out; 5819 goto out;
5863 } 5820 }
5821 clone_root->send_in_progress++;
5864 spin_unlock(&clone_root->root_item_lock); 5822 spin_unlock(&clone_root->root_item_lock);
5865 srcu_read_unlock(&fs_info->subvol_srcu, index); 5823 srcu_read_unlock(&fs_info->subvol_srcu, index);
5866 5824
5867 sctx->clone_roots[i].root = clone_root; 5825 sctx->clone_roots[i].root = clone_root;
5826 clone_sources_to_rollback = i + 1;
5868 } 5827 }
5869 vfree(clone_sources_tmp); 5828 vfree(clone_sources_tmp);
5870 clone_sources_tmp = NULL; 5829 clone_sources_tmp = NULL;
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index 05fef198ff94..9e66f5e724db 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -901,6 +901,15 @@ find_root:
901 if (IS_ERR(new_root)) 901 if (IS_ERR(new_root))
902 return ERR_CAST(new_root); 902 return ERR_CAST(new_root);
903 903
904 if (!(sb->s_flags & MS_RDONLY)) {
905 int ret;
906 down_read(&fs_info->cleanup_work_sem);
907 ret = btrfs_orphan_cleanup(new_root);
908 up_read(&fs_info->cleanup_work_sem);
909 if (ret)
910 return ERR_PTR(ret);
911 }
912
904 dir_id = btrfs_root_dirid(&new_root->root_item); 913 dir_id = btrfs_root_dirid(&new_root->root_item);
905setup_root: 914setup_root:
906 location.objectid = dir_id; 915 location.objectid = dir_id;
@@ -916,7 +925,7 @@ setup_root:
916 * a reference to the dentry. We will have already gotten a reference 925 * a reference to the dentry. We will have already gotten a reference
917 * to the inode in btrfs_fill_super so we're good to go. 926 * to the inode in btrfs_fill_super so we're good to go.
918 */ 927 */
919 if (!new && sb->s_root->d_inode == inode) { 928 if (!new && d_inode(sb->s_root) == inode) {
920 iput(inode); 929 iput(inode);
921 return dget(sb->s_root); 930 return dget(sb->s_root);
922 } 931 }
@@ -1221,7 +1230,7 @@ static struct dentry *mount_subvol(const char *subvol_name, int flags,
1221 1230
1222 root = mount_subtree(mnt, subvol_name); 1231 root = mount_subtree(mnt, subvol_name);
1223 1232
1224 if (!IS_ERR(root) && !is_subvolume_inode(root->d_inode)) { 1233 if (!IS_ERR(root) && !is_subvolume_inode(d_inode(root))) {
1225 struct super_block *s = root->d_sb; 1234 struct super_block *s = root->d_sb;
1226 dput(root); 1235 dput(root);
1227 root = ERR_PTR(-EINVAL); 1236 root = ERR_PTR(-EINVAL);
@@ -1714,7 +1723,7 @@ static int btrfs_calc_avail_data_space(struct btrfs_root *root, u64 *free_bytes)
1714 avail_space = device->total_bytes - device->bytes_used; 1723 avail_space = device->total_bytes - device->bytes_used;
1715 1724
1716 /* align with stripe_len */ 1725 /* align with stripe_len */
1717 do_div(avail_space, BTRFS_STRIPE_LEN); 1726 avail_space = div_u64(avail_space, BTRFS_STRIPE_LEN);
1718 avail_space *= BTRFS_STRIPE_LEN; 1727 avail_space *= BTRFS_STRIPE_LEN;
1719 1728
1720 /* 1729 /*
@@ -1886,8 +1895,8 @@ static int btrfs_statfs(struct dentry *dentry, struct kstatfs *buf)
1886 buf->f_fsid.val[0] = be32_to_cpu(fsid[0]) ^ be32_to_cpu(fsid[2]); 1895 buf->f_fsid.val[0] = be32_to_cpu(fsid[0]) ^ be32_to_cpu(fsid[2]);
1887 buf->f_fsid.val[1] = be32_to_cpu(fsid[1]) ^ be32_to_cpu(fsid[3]); 1896 buf->f_fsid.val[1] = be32_to_cpu(fsid[1]) ^ be32_to_cpu(fsid[3]);
1888 /* Mask in the root object ID too, to disambiguate subvols */ 1897 /* Mask in the root object ID too, to disambiguate subvols */
1889 buf->f_fsid.val[0] ^= BTRFS_I(dentry->d_inode)->root->objectid >> 32; 1898 buf->f_fsid.val[0] ^= BTRFS_I(d_inode(dentry))->root->objectid >> 32;
1890 buf->f_fsid.val[1] ^= BTRFS_I(dentry->d_inode)->root->objectid; 1899 buf->f_fsid.val[1] ^= BTRFS_I(d_inode(dentry))->root->objectid;
1891 1900
1892 return 0; 1901 return 0;
1893} 1902}
@@ -1908,6 +1917,17 @@ static struct file_system_type btrfs_fs_type = {
1908}; 1917};
1909MODULE_ALIAS_FS("btrfs"); 1918MODULE_ALIAS_FS("btrfs");
1910 1919
1920static int btrfs_control_open(struct inode *inode, struct file *file)
1921{
1922 /*
1923 * The control file's private_data is used to hold the
1924 * transaction when it is started and is used to keep
1925 * track of whether a transaction is already in progress.
1926 */
1927 file->private_data = NULL;
1928 return 0;
1929}
1930
1911/* 1931/*
1912 * used by btrfsctl to scan devices when no FS is mounted 1932 * used by btrfsctl to scan devices when no FS is mounted
1913 */ 1933 */
@@ -2009,6 +2029,7 @@ static const struct super_operations btrfs_super_ops = {
2009}; 2029};
2010 2030
2011static const struct file_operations btrfs_ctl_fops = { 2031static const struct file_operations btrfs_ctl_fops = {
2032 .open = btrfs_control_open,
2012 .unlocked_ioctl = btrfs_control_ioctl, 2033 .unlocked_ioctl = btrfs_control_ioctl,
2013 .compat_ioctl = btrfs_control_ioctl, 2034 .compat_ioctl = btrfs_control_ioctl,
2014 .owner = THIS_MODULE, 2035 .owner = THIS_MODULE,
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index 94edb0a2a026..e8a4c86d274d 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -459,7 +459,7 @@ static inline struct btrfs_fs_info *to_fs_info(struct kobject *kobj)
459static char btrfs_unknown_feature_names[3][NUM_FEATURE_BITS][13]; 459static char btrfs_unknown_feature_names[3][NUM_FEATURE_BITS][13];
460static struct btrfs_feature_attr btrfs_feature_attrs[3][NUM_FEATURE_BITS]; 460static struct btrfs_feature_attr btrfs_feature_attrs[3][NUM_FEATURE_BITS];
461 461
462static u64 supported_feature_masks[3] = { 462static const u64 supported_feature_masks[3] = {
463 [FEAT_COMPAT] = BTRFS_FEATURE_COMPAT_SUPP, 463 [FEAT_COMPAT] = BTRFS_FEATURE_COMPAT_SUPP,
464 [FEAT_COMPAT_RO] = BTRFS_FEATURE_COMPAT_RO_SUPP, 464 [FEAT_COMPAT_RO] = BTRFS_FEATURE_COMPAT_RO_SUPP,
465 [FEAT_INCOMPAT] = BTRFS_FEATURE_INCOMPAT_SUPP, 465 [FEAT_INCOMPAT] = BTRFS_FEATURE_INCOMPAT_SUPP,
diff --git a/fs/btrfs/sysfs.h b/fs/btrfs/sysfs.h
index f7dd298b3cf6..3a4bbed723fd 100644
--- a/fs/btrfs/sysfs.h
+++ b/fs/btrfs/sysfs.h
@@ -61,11 +61,23 @@ static struct btrfs_feature_attr btrfs_attr_##_name = { \
61 BTRFS_FEAT_ATTR(name, FEAT_INCOMPAT, BTRFS_FEATURE_INCOMPAT, feature) 61 BTRFS_FEAT_ATTR(name, FEAT_INCOMPAT, BTRFS_FEATURE_INCOMPAT, feature)
62 62
63/* convert from attribute */ 63/* convert from attribute */
64#define to_btrfs_feature_attr(a) \ 64static inline struct btrfs_feature_attr *
65 container_of(a, struct btrfs_feature_attr, kobj_attr) 65to_btrfs_feature_attr(struct kobj_attribute *a)
66#define attr_to_btrfs_attr(a) container_of(a, struct kobj_attribute, attr) 66{
67#define attr_to_btrfs_feature_attr(a) \ 67 return container_of(a, struct btrfs_feature_attr, kobj_attr);
68 to_btrfs_feature_attr(attr_to_btrfs_attr(a)) 68}
69
70static inline struct kobj_attribute *attr_to_btrfs_attr(struct attribute *attr)
71{
72 return container_of(attr, struct kobj_attribute, attr);
73}
74
75static inline struct btrfs_feature_attr *
76attr_to_btrfs_feature_attr(struct attribute *attr)
77{
78 return to_btrfs_feature_attr(attr_to_btrfs_attr(attr));
79}
80
69char *btrfs_printable_features(enum btrfs_feature_set set, u64 flags); 81char *btrfs_printable_features(enum btrfs_feature_set set, u64 flags);
70extern const char * const btrfs_feature_set_names[3]; 82extern const char * const btrfs_feature_set_names[3];
71extern struct kobj_type space_info_ktype; 83extern struct kobj_type space_info_ktype;
diff --git a/fs/btrfs/tests/qgroup-tests.c b/fs/btrfs/tests/qgroup-tests.c
index 73f299ebdabb..c32a7ba76bca 100644
--- a/fs/btrfs/tests/qgroup-tests.c
+++ b/fs/btrfs/tests/qgroup-tests.c
@@ -232,7 +232,7 @@ static int test_no_shared_qgroup(struct btrfs_root *root)
232 init_dummy_trans(&trans); 232 init_dummy_trans(&trans);
233 233
234 test_msg("Qgroup basic add\n"); 234 test_msg("Qgroup basic add\n");
235 ret = btrfs_create_qgroup(NULL, fs_info, 5, NULL); 235 ret = btrfs_create_qgroup(NULL, fs_info, 5);
236 if (ret) { 236 if (ret) {
237 test_msg("Couldn't create a qgroup %d\n", ret); 237 test_msg("Couldn't create a qgroup %d\n", ret);
238 return ret; 238 return ret;
@@ -301,7 +301,7 @@ static int test_multiple_refs(struct btrfs_root *root)
301 test_msg("Qgroup multiple refs test\n"); 301 test_msg("Qgroup multiple refs test\n");
302 302
303 /* We have 5 created already from the previous test */ 303 /* We have 5 created already from the previous test */
304 ret = btrfs_create_qgroup(NULL, fs_info, 256, NULL); 304 ret = btrfs_create_qgroup(NULL, fs_info, 256);
305 if (ret) { 305 if (ret) {
306 test_msg("Couldn't create a qgroup %d\n", ret); 306 test_msg("Couldn't create a qgroup %d\n", ret);
307 return ret; 307 return ret;
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index 8be4278e25e8..5628e25250c0 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -35,7 +35,7 @@
35 35
36#define BTRFS_ROOT_TRANS_TAG 0 36#define BTRFS_ROOT_TRANS_TAG 0
37 37
38static unsigned int btrfs_blocked_trans_types[TRANS_STATE_MAX] = { 38static const unsigned int btrfs_blocked_trans_types[TRANS_STATE_MAX] = {
39 [TRANS_STATE_RUNNING] = 0U, 39 [TRANS_STATE_RUNNING] = 0U,
40 [TRANS_STATE_BLOCKED] = (__TRANS_USERSPACE | 40 [TRANS_STATE_BLOCKED] = (__TRANS_USERSPACE |
41 __TRANS_START), 41 __TRANS_START),
@@ -64,6 +64,9 @@ void btrfs_put_transaction(struct btrfs_transaction *transaction)
64 if (atomic_dec_and_test(&transaction->use_count)) { 64 if (atomic_dec_and_test(&transaction->use_count)) {
65 BUG_ON(!list_empty(&transaction->list)); 65 BUG_ON(!list_empty(&transaction->list));
66 WARN_ON(!RB_EMPTY_ROOT(&transaction->delayed_refs.href_root)); 66 WARN_ON(!RB_EMPTY_ROOT(&transaction->delayed_refs.href_root));
67 if (transaction->delayed_refs.pending_csums)
68 printk(KERN_ERR "pending csums is %llu\n",
69 transaction->delayed_refs.pending_csums);
67 while (!list_empty(&transaction->pending_chunks)) { 70 while (!list_empty(&transaction->pending_chunks)) {
68 struct extent_map *em; 71 struct extent_map *em;
69 72
@@ -93,11 +96,8 @@ static void clear_btree_io_tree(struct extent_io_tree *tree)
93 */ 96 */
94 ASSERT(!waitqueue_active(&state->wq)); 97 ASSERT(!waitqueue_active(&state->wq));
95 free_extent_state(state); 98 free_extent_state(state);
96 if (need_resched()) { 99
97 spin_unlock(&tree->lock); 100 cond_resched_lock(&tree->lock);
98 cond_resched();
99 spin_lock(&tree->lock);
100 }
101 } 101 }
102 spin_unlock(&tree->lock); 102 spin_unlock(&tree->lock);
103} 103}
@@ -222,10 +222,12 @@ loop:
222 atomic_set(&cur_trans->use_count, 2); 222 atomic_set(&cur_trans->use_count, 2);
223 cur_trans->have_free_bgs = 0; 223 cur_trans->have_free_bgs = 0;
224 cur_trans->start_time = get_seconds(); 224 cur_trans->start_time = get_seconds();
225 cur_trans->dirty_bg_run = 0;
225 226
226 cur_trans->delayed_refs.href_root = RB_ROOT; 227 cur_trans->delayed_refs.href_root = RB_ROOT;
227 atomic_set(&cur_trans->delayed_refs.num_entries, 0); 228 atomic_set(&cur_trans->delayed_refs.num_entries, 0);
228 cur_trans->delayed_refs.num_heads_ready = 0; 229 cur_trans->delayed_refs.num_heads_ready = 0;
230 cur_trans->delayed_refs.pending_csums = 0;
229 cur_trans->delayed_refs.num_heads = 0; 231 cur_trans->delayed_refs.num_heads = 0;
230 cur_trans->delayed_refs.flushing = 0; 232 cur_trans->delayed_refs.flushing = 0;
231 cur_trans->delayed_refs.run_delayed_start = 0; 233 cur_trans->delayed_refs.run_delayed_start = 0;
@@ -250,6 +252,9 @@ loop:
250 INIT_LIST_HEAD(&cur_trans->switch_commits); 252 INIT_LIST_HEAD(&cur_trans->switch_commits);
251 INIT_LIST_HEAD(&cur_trans->pending_ordered); 253 INIT_LIST_HEAD(&cur_trans->pending_ordered);
252 INIT_LIST_HEAD(&cur_trans->dirty_bgs); 254 INIT_LIST_HEAD(&cur_trans->dirty_bgs);
255 INIT_LIST_HEAD(&cur_trans->io_bgs);
256 mutex_init(&cur_trans->cache_write_mutex);
257 cur_trans->num_dirty_bgs = 0;
253 spin_lock_init(&cur_trans->dirty_bgs_lock); 258 spin_lock_init(&cur_trans->dirty_bgs_lock);
254 list_add_tail(&cur_trans->list, &fs_info->trans_list); 259 list_add_tail(&cur_trans->list, &fs_info->trans_list);
255 extent_io_tree_init(&cur_trans->dirty_pages, 260 extent_io_tree_init(&cur_trans->dirty_pages,
@@ -721,7 +726,7 @@ int btrfs_should_end_transaction(struct btrfs_trans_handle *trans,
721 updates = trans->delayed_ref_updates; 726 updates = trans->delayed_ref_updates;
722 trans->delayed_ref_updates = 0; 727 trans->delayed_ref_updates = 0;
723 if (updates) { 728 if (updates) {
724 err = btrfs_run_delayed_refs(trans, root, updates); 729 err = btrfs_run_delayed_refs(trans, root, updates * 2);
725 if (err) /* Error code will also eval true */ 730 if (err) /* Error code will also eval true */
726 return err; 731 return err;
727 } 732 }
@@ -1057,6 +1062,7 @@ static noinline int commit_cowonly_roots(struct btrfs_trans_handle *trans,
1057{ 1062{
1058 struct btrfs_fs_info *fs_info = root->fs_info; 1063 struct btrfs_fs_info *fs_info = root->fs_info;
1059 struct list_head *dirty_bgs = &trans->transaction->dirty_bgs; 1064 struct list_head *dirty_bgs = &trans->transaction->dirty_bgs;
1065 struct list_head *io_bgs = &trans->transaction->io_bgs;
1060 struct list_head *next; 1066 struct list_head *next;
1061 struct extent_buffer *eb; 1067 struct extent_buffer *eb;
1062 int ret; 1068 int ret;
@@ -1110,7 +1116,7 @@ again:
1110 return ret; 1116 return ret;
1111 } 1117 }
1112 1118
1113 while (!list_empty(dirty_bgs)) { 1119 while (!list_empty(dirty_bgs) || !list_empty(io_bgs)) {
1114 ret = btrfs_write_dirty_block_groups(trans, root); 1120 ret = btrfs_write_dirty_block_groups(trans, root);
1115 if (ret) 1121 if (ret)
1116 return ret; 1122 return ret;
@@ -1810,6 +1816,37 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans,
1810 return ret; 1816 return ret;
1811 } 1817 }
1812 1818
1819 if (!cur_trans->dirty_bg_run) {
1820 int run_it = 0;
1821
1822 /* this mutex is also taken before trying to set
1823 * block groups readonly. We need to make sure
1824 * that nobody has set a block group readonly
1825 * after a extents from that block group have been
1826 * allocated for cache files. btrfs_set_block_group_ro
1827 * will wait for the transaction to commit if it
1828 * finds dirty_bg_run = 1
1829 *
1830 * The dirty_bg_run flag is also used to make sure only
1831 * one process starts all the block group IO. It wouldn't
1832 * hurt to have more than one go through, but there's no
1833 * real advantage to it either.
1834 */
1835 mutex_lock(&root->fs_info->ro_block_group_mutex);
1836 if (!cur_trans->dirty_bg_run) {
1837 run_it = 1;
1838 cur_trans->dirty_bg_run = 1;
1839 }
1840 mutex_unlock(&root->fs_info->ro_block_group_mutex);
1841
1842 if (run_it)
1843 ret = btrfs_start_dirty_block_groups(trans, root);
1844 }
1845 if (ret) {
1846 btrfs_end_transaction(trans, root);
1847 return ret;
1848 }
1849
1813 spin_lock(&root->fs_info->trans_lock); 1850 spin_lock(&root->fs_info->trans_lock);
1814 list_splice(&trans->ordered, &cur_trans->pending_ordered); 1851 list_splice(&trans->ordered, &cur_trans->pending_ordered);
1815 if (cur_trans->state >= TRANS_STATE_COMMIT_START) { 1852 if (cur_trans->state >= TRANS_STATE_COMMIT_START) {
@@ -2003,6 +2040,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans,
2003 2040
2004 assert_qgroups_uptodate(trans); 2041 assert_qgroups_uptodate(trans);
2005 ASSERT(list_empty(&cur_trans->dirty_bgs)); 2042 ASSERT(list_empty(&cur_trans->dirty_bgs));
2043 ASSERT(list_empty(&cur_trans->io_bgs));
2006 update_super_roots(root); 2044 update_super_roots(root);
2007 2045
2008 btrfs_set_super_log_root(root->fs_info->super_copy, 0); 2046 btrfs_set_super_log_root(root->fs_info->super_copy, 0);
diff --git a/fs/btrfs/transaction.h b/fs/btrfs/transaction.h
index 937050a2b68e..0b24755596ba 100644
--- a/fs/btrfs/transaction.h
+++ b/fs/btrfs/transaction.h
@@ -64,9 +64,19 @@ struct btrfs_transaction {
64 struct list_head pending_ordered; 64 struct list_head pending_ordered;
65 struct list_head switch_commits; 65 struct list_head switch_commits;
66 struct list_head dirty_bgs; 66 struct list_head dirty_bgs;
67 struct list_head io_bgs;
68 u64 num_dirty_bgs;
69
70 /*
71 * we need to make sure block group deletion doesn't race with
72 * free space cache writeout. This mutex keeps them from stomping
73 * on each other
74 */
75 struct mutex cache_write_mutex;
67 spinlock_t dirty_bgs_lock; 76 spinlock_t dirty_bgs_lock;
68 struct btrfs_delayed_ref_root delayed_refs; 77 struct btrfs_delayed_ref_root delayed_refs;
69 int aborted; 78 int aborted;
79 int dirty_bg_run;
70}; 80};
71 81
72#define __TRANS_FREEZABLE (1U << 0) 82#define __TRANS_FREEZABLE (1U << 0)
@@ -136,9 +146,11 @@ struct btrfs_pending_snapshot {
136static inline void btrfs_set_inode_last_trans(struct btrfs_trans_handle *trans, 146static inline void btrfs_set_inode_last_trans(struct btrfs_trans_handle *trans,
137 struct inode *inode) 147 struct inode *inode)
138{ 148{
149 spin_lock(&BTRFS_I(inode)->lock);
139 BTRFS_I(inode)->last_trans = trans->transaction->transid; 150 BTRFS_I(inode)->last_trans = trans->transaction->transid;
140 BTRFS_I(inode)->last_sub_trans = BTRFS_I(inode)->root->log_transid; 151 BTRFS_I(inode)->last_sub_trans = BTRFS_I(inode)->root->log_transid;
141 BTRFS_I(inode)->last_log_commit = BTRFS_I(inode)->root->last_log_commit; 152 BTRFS_I(inode)->last_log_commit = BTRFS_I(inode)->root->last_log_commit;
153 spin_unlock(&BTRFS_I(inode)->lock);
142} 154}
143 155
144int btrfs_end_transaction(struct btrfs_trans_handle *trans, 156int btrfs_end_transaction(struct btrfs_trans_handle *trans,
diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
index c5b8ba37f88e..d04968374e9d 100644
--- a/fs/btrfs/tree-log.c
+++ b/fs/btrfs/tree-log.c
@@ -492,11 +492,19 @@ insert:
492 492
493 if (btrfs_inode_generation(eb, src_item) == 0) { 493 if (btrfs_inode_generation(eb, src_item) == 0) {
494 struct extent_buffer *dst_eb = path->nodes[0]; 494 struct extent_buffer *dst_eb = path->nodes[0];
495 const u64 ino_size = btrfs_inode_size(eb, src_item);
495 496
497 /*
498 * For regular files an ino_size == 0 is used only when
499 * logging that an inode exists, as part of a directory
500 * fsync, and the inode wasn't fsynced before. In this
501 * case don't set the size of the inode in the fs/subvol
502 * tree, otherwise we would be throwing valid data away.
503 */
496 if (S_ISREG(btrfs_inode_mode(eb, src_item)) && 504 if (S_ISREG(btrfs_inode_mode(eb, src_item)) &&
497 S_ISREG(btrfs_inode_mode(dst_eb, dst_item))) { 505 S_ISREG(btrfs_inode_mode(dst_eb, dst_item)) &&
506 ino_size != 0) {
498 struct btrfs_map_token token; 507 struct btrfs_map_token token;
499 u64 ino_size = btrfs_inode_size(eb, src_item);
500 508
501 btrfs_init_map_token(&token); 509 btrfs_init_map_token(&token);
502 btrfs_set_token_inode_size(dst_eb, dst_item, 510 btrfs_set_token_inode_size(dst_eb, dst_item,
@@ -1951,6 +1959,104 @@ out:
1951 return ret; 1959 return ret;
1952} 1960}
1953 1961
1962static int replay_xattr_deletes(struct btrfs_trans_handle *trans,
1963 struct btrfs_root *root,
1964 struct btrfs_root *log,
1965 struct btrfs_path *path,
1966 const u64 ino)
1967{
1968 struct btrfs_key search_key;
1969 struct btrfs_path *log_path;
1970 int i;
1971 int nritems;
1972 int ret;
1973
1974 log_path = btrfs_alloc_path();
1975 if (!log_path)
1976 return -ENOMEM;
1977
1978 search_key.objectid = ino;
1979 search_key.type = BTRFS_XATTR_ITEM_KEY;
1980 search_key.offset = 0;
1981again:
1982 ret = btrfs_search_slot(NULL, root, &search_key, path, 0, 0);
1983 if (ret < 0)
1984 goto out;
1985process_leaf:
1986 nritems = btrfs_header_nritems(path->nodes[0]);
1987 for (i = path->slots[0]; i < nritems; i++) {
1988 struct btrfs_key key;
1989 struct btrfs_dir_item *di;
1990 struct btrfs_dir_item *log_di;
1991 u32 total_size;
1992 u32 cur;
1993
1994 btrfs_item_key_to_cpu(path->nodes[0], &key, i);
1995 if (key.objectid != ino || key.type != BTRFS_XATTR_ITEM_KEY) {
1996 ret = 0;
1997 goto out;
1998 }
1999
2000 di = btrfs_item_ptr(path->nodes[0], i, struct btrfs_dir_item);
2001 total_size = btrfs_item_size_nr(path->nodes[0], i);
2002 cur = 0;
2003 while (cur < total_size) {
2004 u16 name_len = btrfs_dir_name_len(path->nodes[0], di);
2005 u16 data_len = btrfs_dir_data_len(path->nodes[0], di);
2006 u32 this_len = sizeof(*di) + name_len + data_len;
2007 char *name;
2008
2009 name = kmalloc(name_len, GFP_NOFS);
2010 if (!name) {
2011 ret = -ENOMEM;
2012 goto out;
2013 }
2014 read_extent_buffer(path->nodes[0], name,
2015 (unsigned long)(di + 1), name_len);
2016
2017 log_di = btrfs_lookup_xattr(NULL, log, log_path, ino,
2018 name, name_len, 0);
2019 btrfs_release_path(log_path);
2020 if (!log_di) {
2021 /* Doesn't exist in log tree, so delete it. */
2022 btrfs_release_path(path);
2023 di = btrfs_lookup_xattr(trans, root, path, ino,
2024 name, name_len, -1);
2025 kfree(name);
2026 if (IS_ERR(di)) {
2027 ret = PTR_ERR(di);
2028 goto out;
2029 }
2030 ASSERT(di);
2031 ret = btrfs_delete_one_dir_name(trans, root,
2032 path, di);
2033 if (ret)
2034 goto out;
2035 btrfs_release_path(path);
2036 search_key = key;
2037 goto again;
2038 }
2039 kfree(name);
2040 if (IS_ERR(log_di)) {
2041 ret = PTR_ERR(log_di);
2042 goto out;
2043 }
2044 cur += this_len;
2045 di = (struct btrfs_dir_item *)((char *)di + this_len);
2046 }
2047 }
2048 ret = btrfs_next_leaf(root, path);
2049 if (ret > 0)
2050 ret = 0;
2051 else if (ret == 0)
2052 goto process_leaf;
2053out:
2054 btrfs_free_path(log_path);
2055 btrfs_release_path(path);
2056 return ret;
2057}
2058
2059
1954/* 2060/*
1955 * deletion replay happens before we copy any new directory items 2061 * deletion replay happens before we copy any new directory items
1956 * out of the log or out of backreferences from inodes. It 2062 * out of the log or out of backreferences from inodes. It
@@ -2104,6 +2210,10 @@ static int replay_one_buffer(struct btrfs_root *log, struct extent_buffer *eb,
2104 2210
2105 inode_item = btrfs_item_ptr(eb, i, 2211 inode_item = btrfs_item_ptr(eb, i,
2106 struct btrfs_inode_item); 2212 struct btrfs_inode_item);
2213 ret = replay_xattr_deletes(wc->trans, root, log,
2214 path, key.objectid);
2215 if (ret)
2216 break;
2107 mode = btrfs_inode_mode(eb, inode_item); 2217 mode = btrfs_inode_mode(eb, inode_item);
2108 if (S_ISDIR(mode)) { 2218 if (S_ISDIR(mode)) {
2109 ret = replay_dir_deletes(wc->trans, 2219 ret = replay_dir_deletes(wc->trans,
@@ -2230,7 +2340,8 @@ static noinline int walk_down_log_tree(struct btrfs_trans_handle *trans,
2230 if (trans) { 2340 if (trans) {
2231 btrfs_tree_lock(next); 2341 btrfs_tree_lock(next);
2232 btrfs_set_lock_blocking(next); 2342 btrfs_set_lock_blocking(next);
2233 clean_tree_block(trans, root, next); 2343 clean_tree_block(trans, root->fs_info,
2344 next);
2234 btrfs_wait_tree_block_writeback(next); 2345 btrfs_wait_tree_block_writeback(next);
2235 btrfs_tree_unlock(next); 2346 btrfs_tree_unlock(next);
2236 } 2347 }
@@ -2308,7 +2419,8 @@ static noinline int walk_up_log_tree(struct btrfs_trans_handle *trans,
2308 if (trans) { 2419 if (trans) {
2309 btrfs_tree_lock(next); 2420 btrfs_tree_lock(next);
2310 btrfs_set_lock_blocking(next); 2421 btrfs_set_lock_blocking(next);
2311 clean_tree_block(trans, root, next); 2422 clean_tree_block(trans, root->fs_info,
2423 next);
2312 btrfs_wait_tree_block_writeback(next); 2424 btrfs_wait_tree_block_writeback(next);
2313 btrfs_tree_unlock(next); 2425 btrfs_tree_unlock(next);
2314 } 2426 }
@@ -2384,7 +2496,7 @@ static int walk_log_tree(struct btrfs_trans_handle *trans,
2384 if (trans) { 2496 if (trans) {
2385 btrfs_tree_lock(next); 2497 btrfs_tree_lock(next);
2386 btrfs_set_lock_blocking(next); 2498 btrfs_set_lock_blocking(next);
2387 clean_tree_block(trans, log, next); 2499 clean_tree_block(trans, log->fs_info, next);
2388 btrfs_wait_tree_block_writeback(next); 2500 btrfs_wait_tree_block_writeback(next);
2389 btrfs_tree_unlock(next); 2501 btrfs_tree_unlock(next);
2390 } 2502 }
@@ -3020,6 +3132,7 @@ static noinline int log_dir_items(struct btrfs_trans_handle *trans,
3020 struct btrfs_root *root, struct inode *inode, 3132 struct btrfs_root *root, struct inode *inode,
3021 struct btrfs_path *path, 3133 struct btrfs_path *path,
3022 struct btrfs_path *dst_path, int key_type, 3134 struct btrfs_path *dst_path, int key_type,
3135 struct btrfs_log_ctx *ctx,
3023 u64 min_offset, u64 *last_offset_ret) 3136 u64 min_offset, u64 *last_offset_ret)
3024{ 3137{
3025 struct btrfs_key min_key; 3138 struct btrfs_key min_key;
@@ -3104,6 +3217,8 @@ static noinline int log_dir_items(struct btrfs_trans_handle *trans,
3104 src = path->nodes[0]; 3217 src = path->nodes[0];
3105 nritems = btrfs_header_nritems(src); 3218 nritems = btrfs_header_nritems(src);
3106 for (i = path->slots[0]; i < nritems; i++) { 3219 for (i = path->slots[0]; i < nritems; i++) {
3220 struct btrfs_dir_item *di;
3221
3107 btrfs_item_key_to_cpu(src, &min_key, i); 3222 btrfs_item_key_to_cpu(src, &min_key, i);
3108 3223
3109 if (min_key.objectid != ino || min_key.type != key_type) 3224 if (min_key.objectid != ino || min_key.type != key_type)
@@ -3114,6 +3229,37 @@ static noinline int log_dir_items(struct btrfs_trans_handle *trans,
3114 err = ret; 3229 err = ret;
3115 goto done; 3230 goto done;
3116 } 3231 }
3232
3233 /*
3234 * We must make sure that when we log a directory entry,
3235 * the corresponding inode, after log replay, has a
3236 * matching link count. For example:
3237 *
3238 * touch foo
3239 * mkdir mydir
3240 * sync
3241 * ln foo mydir/bar
3242 * xfs_io -c "fsync" mydir
3243 * <crash>
3244 * <mount fs and log replay>
3245 *
3246 * Would result in a fsync log that when replayed, our
3247 * file inode would have a link count of 1, but we get
3248 * two directory entries pointing to the same inode.
3249 * After removing one of the names, it would not be
3250 * possible to remove the other name, which resulted
3251 * always in stale file handle errors, and would not
3252 * be possible to rmdir the parent directory, since
3253 * its i_size could never decrement to the value
3254 * BTRFS_EMPTY_DIR_SIZE, resulting in -ENOTEMPTY errors.
3255 */
3256 di = btrfs_item_ptr(src, i, struct btrfs_dir_item);
3257 btrfs_dir_item_key_to_cpu(src, di, &tmp);
3258 if (ctx &&
3259 (btrfs_dir_transid(src, di) == trans->transid ||
3260 btrfs_dir_type(src, di) == BTRFS_FT_DIR) &&
3261 tmp.type != BTRFS_ROOT_ITEM_KEY)
3262 ctx->log_new_dentries = true;
3117 } 3263 }
3118 path->slots[0] = nritems; 3264 path->slots[0] = nritems;
3119 3265
@@ -3175,7 +3321,8 @@ done:
3175static noinline int log_directory_changes(struct btrfs_trans_handle *trans, 3321static noinline int log_directory_changes(struct btrfs_trans_handle *trans,
3176 struct btrfs_root *root, struct inode *inode, 3322 struct btrfs_root *root, struct inode *inode,
3177 struct btrfs_path *path, 3323 struct btrfs_path *path,
3178 struct btrfs_path *dst_path) 3324 struct btrfs_path *dst_path,
3325 struct btrfs_log_ctx *ctx)
3179{ 3326{
3180 u64 min_key; 3327 u64 min_key;
3181 u64 max_key; 3328 u64 max_key;
@@ -3187,7 +3334,7 @@ again:
3187 max_key = 0; 3334 max_key = 0;
3188 while (1) { 3335 while (1) {
3189 ret = log_dir_items(trans, root, inode, path, 3336 ret = log_dir_items(trans, root, inode, path,
3190 dst_path, key_type, min_key, 3337 dst_path, key_type, ctx, min_key,
3191 &max_key); 3338 &max_key);
3192 if (ret) 3339 if (ret)
3193 return ret; 3340 return ret;
@@ -3963,7 +4110,7 @@ static int logged_inode_size(struct btrfs_root *log, struct inode *inode,
3963 if (ret < 0) { 4110 if (ret < 0) {
3964 return ret; 4111 return ret;
3965 } else if (ret > 0) { 4112 } else if (ret > 0) {
3966 *size_ret = i_size_read(inode); 4113 *size_ret = 0;
3967 } else { 4114 } else {
3968 struct btrfs_inode_item *item; 4115 struct btrfs_inode_item *item;
3969 4116
@@ -4070,10 +4217,8 @@ static int btrfs_log_inode(struct btrfs_trans_handle *trans,
4070 if (S_ISDIR(inode->i_mode)) { 4217 if (S_ISDIR(inode->i_mode)) {
4071 int max_key_type = BTRFS_DIR_LOG_INDEX_KEY; 4218 int max_key_type = BTRFS_DIR_LOG_INDEX_KEY;
4072 4219
4073 if (inode_only == LOG_INODE_EXISTS) { 4220 if (inode_only == LOG_INODE_EXISTS)
4074 max_key_type = BTRFS_INODE_EXTREF_KEY; 4221 max_key_type = BTRFS_XATTR_ITEM_KEY;
4075 max_key.type = max_key_type;
4076 }
4077 ret = drop_objectid_items(trans, log, path, ino, max_key_type); 4222 ret = drop_objectid_items(trans, log, path, ino, max_key_type);
4078 } else { 4223 } else {
4079 if (inode_only == LOG_INODE_EXISTS) { 4224 if (inode_only == LOG_INODE_EXISTS) {
@@ -4098,7 +4243,7 @@ static int btrfs_log_inode(struct btrfs_trans_handle *trans,
4098 if (test_bit(BTRFS_INODE_NEEDS_FULL_SYNC, 4243 if (test_bit(BTRFS_INODE_NEEDS_FULL_SYNC,
4099 &BTRFS_I(inode)->runtime_flags)) { 4244 &BTRFS_I(inode)->runtime_flags)) {
4100 if (inode_only == LOG_INODE_EXISTS) { 4245 if (inode_only == LOG_INODE_EXISTS) {
4101 max_key.type = BTRFS_INODE_EXTREF_KEY; 4246 max_key.type = BTRFS_XATTR_ITEM_KEY;
4102 ret = drop_objectid_items(trans, log, path, ino, 4247 ret = drop_objectid_items(trans, log, path, ino,
4103 max_key.type); 4248 max_key.type);
4104 } else { 4249 } else {
@@ -4106,20 +4251,19 @@ static int btrfs_log_inode(struct btrfs_trans_handle *trans,
4106 &BTRFS_I(inode)->runtime_flags); 4251 &BTRFS_I(inode)->runtime_flags);
4107 clear_bit(BTRFS_INODE_COPY_EVERYTHING, 4252 clear_bit(BTRFS_INODE_COPY_EVERYTHING,
4108 &BTRFS_I(inode)->runtime_flags); 4253 &BTRFS_I(inode)->runtime_flags);
4109 ret = btrfs_truncate_inode_items(trans, log, 4254 while(1) {
4110 inode, 0, 0); 4255 ret = btrfs_truncate_inode_items(trans,
4256 log, inode, 0, 0);
4257 if (ret != -EAGAIN)
4258 break;
4259 }
4111 } 4260 }
4112 } else if (test_bit(BTRFS_INODE_COPY_EVERYTHING, 4261 } else if (test_and_clear_bit(BTRFS_INODE_COPY_EVERYTHING,
4113 &BTRFS_I(inode)->runtime_flags) || 4262 &BTRFS_I(inode)->runtime_flags) ||
4114 inode_only == LOG_INODE_EXISTS) { 4263 inode_only == LOG_INODE_EXISTS) {
4115 if (inode_only == LOG_INODE_ALL) { 4264 if (inode_only == LOG_INODE_ALL)
4116 clear_bit(BTRFS_INODE_COPY_EVERYTHING,
4117 &BTRFS_I(inode)->runtime_flags);
4118 fast_search = true; 4265 fast_search = true;
4119 max_key.type = BTRFS_XATTR_ITEM_KEY; 4266 max_key.type = BTRFS_XATTR_ITEM_KEY;
4120 } else {
4121 max_key.type = BTRFS_INODE_EXTREF_KEY;
4122 }
4123 ret = drop_objectid_items(trans, log, path, ino, 4267 ret = drop_objectid_items(trans, log, path, ino,
4124 max_key.type); 4268 max_key.type);
4125 } else { 4269 } else {
@@ -4277,15 +4421,18 @@ log_extents:
4277 } 4421 }
4278 4422
4279 if (inode_only == LOG_INODE_ALL && S_ISDIR(inode->i_mode)) { 4423 if (inode_only == LOG_INODE_ALL && S_ISDIR(inode->i_mode)) {
4280 ret = log_directory_changes(trans, root, inode, path, dst_path); 4424 ret = log_directory_changes(trans, root, inode, path, dst_path,
4425 ctx);
4281 if (ret) { 4426 if (ret) {
4282 err = ret; 4427 err = ret;
4283 goto out_unlock; 4428 goto out_unlock;
4284 } 4429 }
4285 } 4430 }
4286 4431
4432 spin_lock(&BTRFS_I(inode)->lock);
4287 BTRFS_I(inode)->logged_trans = trans->transid; 4433 BTRFS_I(inode)->logged_trans = trans->transid;
4288 BTRFS_I(inode)->last_log_commit = BTRFS_I(inode)->last_sub_trans; 4434 BTRFS_I(inode)->last_log_commit = BTRFS_I(inode)->last_sub_trans;
4435 spin_unlock(&BTRFS_I(inode)->lock);
4289out_unlock: 4436out_unlock:
4290 if (unlikely(err)) 4437 if (unlikely(err))
4291 btrfs_put_logged_extents(&logged_list); 4438 btrfs_put_logged_extents(&logged_list);
@@ -4327,9 +4474,9 @@ static noinline int check_parent_dirs_for_sync(struct btrfs_trans_handle *trans,
4327 goto out; 4474 goto out;
4328 4475
4329 if (!S_ISDIR(inode->i_mode)) { 4476 if (!S_ISDIR(inode->i_mode)) {
4330 if (!parent || !parent->d_inode || sb != parent->d_inode->i_sb) 4477 if (!parent || d_really_is_negative(parent) || sb != d_inode(parent)->i_sb)
4331 goto out; 4478 goto out;
4332 inode = parent->d_inode; 4479 inode = d_inode(parent);
4333 } 4480 }
4334 4481
4335 while (1) { 4482 while (1) {
@@ -4355,7 +4502,7 @@ static noinline int check_parent_dirs_for_sync(struct btrfs_trans_handle *trans,
4355 break; 4502 break;
4356 } 4503 }
4357 4504
4358 if (!parent || !parent->d_inode || sb != parent->d_inode->i_sb) 4505 if (!parent || d_really_is_negative(parent) || sb != d_inode(parent)->i_sb)
4359 break; 4506 break;
4360 4507
4361 if (IS_ROOT(parent)) 4508 if (IS_ROOT(parent))
@@ -4364,7 +4511,7 @@ static noinline int check_parent_dirs_for_sync(struct btrfs_trans_handle *trans,
4364 parent = dget_parent(parent); 4511 parent = dget_parent(parent);
4365 dput(old_parent); 4512 dput(old_parent);
4366 old_parent = parent; 4513 old_parent = parent;
4367 inode = parent->d_inode; 4514 inode = d_inode(parent);
4368 4515
4369 } 4516 }
4370 dput(old_parent); 4517 dput(old_parent);
@@ -4372,6 +4519,181 @@ out:
4372 return ret; 4519 return ret;
4373} 4520}
4374 4521
4522struct btrfs_dir_list {
4523 u64 ino;
4524 struct list_head list;
4525};
4526
4527/*
4528 * Log the inodes of the new dentries of a directory. See log_dir_items() for
4529 * details about the why it is needed.
4530 * This is a recursive operation - if an existing dentry corresponds to a
4531 * directory, that directory's new entries are logged too (same behaviour as
4532 * ext3/4, xfs, f2fs, reiserfs, nilfs2). Note that when logging the inodes
4533 * the dentries point to we do not lock their i_mutex, otherwise lockdep
4534 * complains about the following circular lock dependency / possible deadlock:
4535 *
4536 * CPU0 CPU1
4537 * ---- ----
4538 * lock(&type->i_mutex_dir_key#3/2);
4539 * lock(sb_internal#2);
4540 * lock(&type->i_mutex_dir_key#3/2);
4541 * lock(&sb->s_type->i_mutex_key#14);
4542 *
4543 * Where sb_internal is the lock (a counter that works as a lock) acquired by
4544 * sb_start_intwrite() in btrfs_start_transaction().
4545 * Not locking i_mutex of the inodes is still safe because:
4546 *
4547 * 1) For regular files we log with a mode of LOG_INODE_EXISTS. It's possible
4548 * that while logging the inode new references (names) are added or removed
4549 * from the inode, leaving the logged inode item with a link count that does
4550 * not match the number of logged inode reference items. This is fine because
4551 * at log replay time we compute the real number of links and correct the
4552 * link count in the inode item (see replay_one_buffer() and
4553 * link_to_fixup_dir());
4554 *
4555 * 2) For directories we log with a mode of LOG_INODE_ALL. It's possible that
4556 * while logging the inode's items new items with keys BTRFS_DIR_ITEM_KEY and
4557 * BTRFS_DIR_INDEX_KEY are added to fs/subvol tree and the logged inode item
4558 * has a size that doesn't match the sum of the lengths of all the logged
4559 * names. This does not result in a problem because if a dir_item key is
4560 * logged but its matching dir_index key is not logged, at log replay time we
4561 * don't use it to replay the respective name (see replay_one_name()). On the
4562 * other hand if only the dir_index key ends up being logged, the respective
4563 * name is added to the fs/subvol tree with both the dir_item and dir_index
4564 * keys created (see replay_one_name()).
4565 * The directory's inode item with a wrong i_size is not a problem as well,
4566 * since we don't use it at log replay time to set the i_size in the inode
4567 * item of the fs/subvol tree (see overwrite_item()).
4568 */
4569static int log_new_dir_dentries(struct btrfs_trans_handle *trans,
4570 struct btrfs_root *root,
4571 struct inode *start_inode,
4572 struct btrfs_log_ctx *ctx)
4573{
4574 struct btrfs_root *log = root->log_root;
4575 struct btrfs_path *path;
4576 LIST_HEAD(dir_list);
4577 struct btrfs_dir_list *dir_elem;
4578 int ret = 0;
4579
4580 path = btrfs_alloc_path();
4581 if (!path)
4582 return -ENOMEM;
4583
4584 dir_elem = kmalloc(sizeof(*dir_elem), GFP_NOFS);
4585 if (!dir_elem) {
4586 btrfs_free_path(path);
4587 return -ENOMEM;
4588 }
4589 dir_elem->ino = btrfs_ino(start_inode);
4590 list_add_tail(&dir_elem->list, &dir_list);
4591
4592 while (!list_empty(&dir_list)) {
4593 struct extent_buffer *leaf;
4594 struct btrfs_key min_key;
4595 int nritems;
4596 int i;
4597
4598 dir_elem = list_first_entry(&dir_list, struct btrfs_dir_list,
4599 list);
4600 if (ret)
4601 goto next_dir_inode;
4602
4603 min_key.objectid = dir_elem->ino;
4604 min_key.type = BTRFS_DIR_ITEM_KEY;
4605 min_key.offset = 0;
4606again:
4607 btrfs_release_path(path);
4608 ret = btrfs_search_forward(log, &min_key, path, trans->transid);
4609 if (ret < 0) {
4610 goto next_dir_inode;
4611 } else if (ret > 0) {
4612 ret = 0;
4613 goto next_dir_inode;
4614 }
4615
4616process_leaf:
4617 leaf = path->nodes[0];
4618 nritems = btrfs_header_nritems(leaf);
4619 for (i = path->slots[0]; i < nritems; i++) {
4620 struct btrfs_dir_item *di;
4621 struct btrfs_key di_key;
4622 struct inode *di_inode;
4623 struct btrfs_dir_list *new_dir_elem;
4624 int log_mode = LOG_INODE_EXISTS;
4625 int type;
4626
4627 btrfs_item_key_to_cpu(leaf, &min_key, i);
4628 if (min_key.objectid != dir_elem->ino ||
4629 min_key.type != BTRFS_DIR_ITEM_KEY)
4630 goto next_dir_inode;
4631
4632 di = btrfs_item_ptr(leaf, i, struct btrfs_dir_item);
4633 type = btrfs_dir_type(leaf, di);
4634 if (btrfs_dir_transid(leaf, di) < trans->transid &&
4635 type != BTRFS_FT_DIR)
4636 continue;
4637 btrfs_dir_item_key_to_cpu(leaf, di, &di_key);
4638 if (di_key.type == BTRFS_ROOT_ITEM_KEY)
4639 continue;
4640
4641 di_inode = btrfs_iget(root->fs_info->sb, &di_key,
4642 root, NULL);
4643 if (IS_ERR(di_inode)) {
4644 ret = PTR_ERR(di_inode);
4645 goto next_dir_inode;
4646 }
4647
4648 if (btrfs_inode_in_log(di_inode, trans->transid)) {
4649 iput(di_inode);
4650 continue;
4651 }
4652
4653 ctx->log_new_dentries = false;
4654 if (type == BTRFS_FT_DIR)
4655 log_mode = LOG_INODE_ALL;
4656 btrfs_release_path(path);
4657 ret = btrfs_log_inode(trans, root, di_inode,
4658 log_mode, 0, LLONG_MAX, ctx);
4659 iput(di_inode);
4660 if (ret)
4661 goto next_dir_inode;
4662 if (ctx->log_new_dentries) {
4663 new_dir_elem = kmalloc(sizeof(*new_dir_elem),
4664 GFP_NOFS);
4665 if (!new_dir_elem) {
4666 ret = -ENOMEM;
4667 goto next_dir_inode;
4668 }
4669 new_dir_elem->ino = di_key.objectid;
4670 list_add_tail(&new_dir_elem->list, &dir_list);
4671 }
4672 break;
4673 }
4674 if (i == nritems) {
4675 ret = btrfs_next_leaf(log, path);
4676 if (ret < 0) {
4677 goto next_dir_inode;
4678 } else if (ret > 0) {
4679 ret = 0;
4680 goto next_dir_inode;
4681 }
4682 goto process_leaf;
4683 }
4684 if (min_key.offset < (u64)-1) {
4685 min_key.offset++;
4686 goto again;
4687 }
4688next_dir_inode:
4689 list_del(&dir_elem->list);
4690 kfree(dir_elem);
4691 }
4692
4693 btrfs_free_path(path);
4694 return ret;
4695}
4696
4375/* 4697/*
4376 * helper function around btrfs_log_inode to make sure newly created 4698 * helper function around btrfs_log_inode to make sure newly created
4377 * parent directories also end up in the log. A minimal inode and backref 4699 * parent directories also end up in the log. A minimal inode and backref
@@ -4394,6 +4716,8 @@ static int btrfs_log_inode_parent(struct btrfs_trans_handle *trans,
4394 const struct dentry * const first_parent = parent; 4716 const struct dentry * const first_parent = parent;
4395 const bool did_unlink = (BTRFS_I(inode)->last_unlink_trans > 4717 const bool did_unlink = (BTRFS_I(inode)->last_unlink_trans >
4396 last_committed); 4718 last_committed);
4719 bool log_dentries = false;
4720 struct inode *orig_inode = inode;
4397 4721
4398 sb = inode->i_sb; 4722 sb = inode->i_sb;
4399 4723
@@ -4449,11 +4773,14 @@ static int btrfs_log_inode_parent(struct btrfs_trans_handle *trans,
4449 goto end_trans; 4773 goto end_trans;
4450 } 4774 }
4451 4775
4776 if (S_ISDIR(inode->i_mode) && ctx && ctx->log_new_dentries)
4777 log_dentries = true;
4778
4452 while (1) { 4779 while (1) {
4453 if (!parent || !parent->d_inode || sb != parent->d_inode->i_sb) 4780 if (!parent || d_really_is_negative(parent) || sb != d_inode(parent)->i_sb)
4454 break; 4781 break;
4455 4782
4456 inode = parent->d_inode; 4783 inode = d_inode(parent);
4457 if (root != BTRFS_I(inode)->root) 4784 if (root != BTRFS_I(inode)->root)
4458 break; 4785 break;
4459 4786
@@ -4485,7 +4812,10 @@ static int btrfs_log_inode_parent(struct btrfs_trans_handle *trans,
4485 dput(old_parent); 4812 dput(old_parent);
4486 old_parent = parent; 4813 old_parent = parent;
4487 } 4814 }
4488 ret = 0; 4815 if (log_dentries)
4816 ret = log_new_dir_dentries(trans, root, orig_inode, ctx);
4817 else
4818 ret = 0;
4489end_trans: 4819end_trans:
4490 dput(old_parent); 4820 dput(old_parent);
4491 if (ret < 0) { 4821 if (ret < 0) {
@@ -4515,7 +4845,7 @@ int btrfs_log_dentry_safe(struct btrfs_trans_handle *trans,
4515 struct dentry *parent = dget_parent(dentry); 4845 struct dentry *parent = dget_parent(dentry);
4516 int ret; 4846 int ret;
4517 4847
4518 ret = btrfs_log_inode_parent(trans, root, dentry->d_inode, parent, 4848 ret = btrfs_log_inode_parent(trans, root, d_inode(dentry), parent,
4519 start, end, 0, ctx); 4849 start, end, 0, ctx);
4520 dput(parent); 4850 dput(parent);
4521 4851
diff --git a/fs/btrfs/tree-log.h b/fs/btrfs/tree-log.h
index 154990c26dcb..6916a781ea02 100644
--- a/fs/btrfs/tree-log.h
+++ b/fs/btrfs/tree-log.h
@@ -29,6 +29,7 @@ struct btrfs_log_ctx {
29 int log_ret; 29 int log_ret;
30 int log_transid; 30 int log_transid;
31 int io_err; 31 int io_err;
32 bool log_new_dentries;
32 struct list_head list; 33 struct list_head list;
33}; 34};
34 35
@@ -37,6 +38,7 @@ static inline void btrfs_init_log_ctx(struct btrfs_log_ctx *ctx)
37 ctx->log_ret = 0; 38 ctx->log_ret = 0;
38 ctx->log_transid = 0; 39 ctx->log_transid = 0;
39 ctx->io_err = 0; 40 ctx->io_err = 0;
41 ctx->log_new_dentries = false;
40 INIT_LIST_HEAD(&ctx->list); 42 INIT_LIST_HEAD(&ctx->list);
41} 43}
42 44
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 8222f6f74147..8bcd2a007517 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -366,8 +366,8 @@ loop_lock:
366 btrfsic_submit_bio(cur->bi_rw, cur); 366 btrfsic_submit_bio(cur->bi_rw, cur);
367 num_run++; 367 num_run++;
368 batch_run++; 368 batch_run++;
369 if (need_resched()) 369
370 cond_resched(); 370 cond_resched();
371 371
372 /* 372 /*
373 * we made progress, there is more work to do and the bdi 373 * we made progress, there is more work to do and the bdi
@@ -400,8 +400,7 @@ loop_lock:
400 * against it before looping 400 * against it before looping
401 */ 401 */
402 last_waited = ioc->last_waited; 402 last_waited = ioc->last_waited;
403 if (need_resched()) 403 cond_resched();
404 cond_resched();
405 continue; 404 continue;
406 } 405 }
407 spin_lock(&device->io_lock); 406 spin_lock(&device->io_lock);
@@ -609,8 +608,7 @@ error:
609 return ERR_PTR(-ENOMEM); 608 return ERR_PTR(-ENOMEM);
610} 609}
611 610
612void btrfs_close_extra_devices(struct btrfs_fs_info *fs_info, 611void btrfs_close_extra_devices(struct btrfs_fs_devices *fs_devices, int step)
613 struct btrfs_fs_devices *fs_devices, int step)
614{ 612{
615 struct btrfs_device *device, *next; 613 struct btrfs_device *device, *next;
616 struct btrfs_device *latest_dev = NULL; 614 struct btrfs_device *latest_dev = NULL;
@@ -1136,11 +1134,11 @@ int find_free_dev_extent(struct btrfs_trans_handle *trans,
1136 path = btrfs_alloc_path(); 1134 path = btrfs_alloc_path();
1137 if (!path) 1135 if (!path)
1138 return -ENOMEM; 1136 return -ENOMEM;
1139again: 1137
1140 max_hole_start = search_start; 1138 max_hole_start = search_start;
1141 max_hole_size = 0; 1139 max_hole_size = 0;
1142 hole_size = 0;
1143 1140
1141again:
1144 if (search_start >= search_end || device->is_tgtdev_for_dev_replace) { 1142 if (search_start >= search_end || device->is_tgtdev_for_dev_replace) {
1145 ret = -ENOSPC; 1143 ret = -ENOSPC;
1146 goto out; 1144 goto out;
@@ -1233,21 +1231,23 @@ next:
1233 * allocated dev extents, and when shrinking the device, 1231 * allocated dev extents, and when shrinking the device,
1234 * search_end may be smaller than search_start. 1232 * search_end may be smaller than search_start.
1235 */ 1233 */
1236 if (search_end > search_start) 1234 if (search_end > search_start) {
1237 hole_size = search_end - search_start; 1235 hole_size = search_end - search_start;
1238 1236
1239 if (hole_size > max_hole_size) { 1237 if (contains_pending_extent(trans, device, &search_start,
1240 max_hole_start = search_start; 1238 hole_size)) {
1241 max_hole_size = hole_size; 1239 btrfs_release_path(path);
1242 } 1240 goto again;
1241 }
1243 1242
1244 if (contains_pending_extent(trans, device, &search_start, hole_size)) { 1243 if (hole_size > max_hole_size) {
1245 btrfs_release_path(path); 1244 max_hole_start = search_start;
1246 goto again; 1245 max_hole_size = hole_size;
1246 }
1247 } 1247 }
1248 1248
1249 /* See above. */ 1249 /* See above. */
1250 if (hole_size < num_bytes) 1250 if (max_hole_size < num_bytes)
1251 ret = -ENOSPC; 1251 ret = -ENOSPC;
1252 else 1252 else
1253 ret = 0; 1253 ret = 0;
@@ -2487,8 +2487,7 @@ int btrfs_grow_device(struct btrfs_trans_handle *trans,
2487} 2487}
2488 2488
2489static int btrfs_free_chunk(struct btrfs_trans_handle *trans, 2489static int btrfs_free_chunk(struct btrfs_trans_handle *trans,
2490 struct btrfs_root *root, 2490 struct btrfs_root *root, u64 chunk_objectid,
2491 u64 chunk_tree, u64 chunk_objectid,
2492 u64 chunk_offset) 2491 u64 chunk_offset)
2493{ 2492{
2494 int ret; 2493 int ret;
@@ -2580,7 +2579,6 @@ int btrfs_remove_chunk(struct btrfs_trans_handle *trans,
2580 struct map_lookup *map; 2579 struct map_lookup *map;
2581 u64 dev_extent_len = 0; 2580 u64 dev_extent_len = 0;
2582 u64 chunk_objectid = BTRFS_FIRST_CHUNK_TREE_OBJECTID; 2581 u64 chunk_objectid = BTRFS_FIRST_CHUNK_TREE_OBJECTID;
2583 u64 chunk_tree = root->fs_info->chunk_root->objectid;
2584 int i, ret = 0; 2582 int i, ret = 0;
2585 2583
2586 /* Just in case */ 2584 /* Just in case */
@@ -2634,8 +2632,7 @@ int btrfs_remove_chunk(struct btrfs_trans_handle *trans,
2634 } 2632 }
2635 } 2633 }
2636 } 2634 }
2637 ret = btrfs_free_chunk(trans, root, chunk_tree, chunk_objectid, 2635 ret = btrfs_free_chunk(trans, root, chunk_objectid, chunk_offset);
2638 chunk_offset);
2639 if (ret) { 2636 if (ret) {
2640 btrfs_abort_transaction(trans, root, ret); 2637 btrfs_abort_transaction(trans, root, ret);
2641 goto out; 2638 goto out;
@@ -2664,8 +2661,8 @@ out:
2664} 2661}
2665 2662
2666static int btrfs_relocate_chunk(struct btrfs_root *root, 2663static int btrfs_relocate_chunk(struct btrfs_root *root,
2667 u64 chunk_tree, u64 chunk_objectid, 2664 u64 chunk_objectid,
2668 u64 chunk_offset) 2665 u64 chunk_offset)
2669{ 2666{
2670 struct btrfs_root *extent_root; 2667 struct btrfs_root *extent_root;
2671 struct btrfs_trans_handle *trans; 2668 struct btrfs_trans_handle *trans;
@@ -2707,7 +2704,6 @@ static int btrfs_relocate_sys_chunks(struct btrfs_root *root)
2707 struct btrfs_chunk *chunk; 2704 struct btrfs_chunk *chunk;
2708 struct btrfs_key key; 2705 struct btrfs_key key;
2709 struct btrfs_key found_key; 2706 struct btrfs_key found_key;
2710 u64 chunk_tree = chunk_root->root_key.objectid;
2711 u64 chunk_type; 2707 u64 chunk_type;
2712 bool retried = false; 2708 bool retried = false;
2713 int failed = 0; 2709 int failed = 0;
@@ -2744,7 +2740,7 @@ again:
2744 btrfs_release_path(path); 2740 btrfs_release_path(path);
2745 2741
2746 if (chunk_type & BTRFS_BLOCK_GROUP_SYSTEM) { 2742 if (chunk_type & BTRFS_BLOCK_GROUP_SYSTEM) {
2747 ret = btrfs_relocate_chunk(chunk_root, chunk_tree, 2743 ret = btrfs_relocate_chunk(chunk_root,
2748 found_key.objectid, 2744 found_key.objectid,
2749 found_key.offset); 2745 found_key.offset);
2750 if (ret == -ENOSPC) 2746 if (ret == -ENOSPC)
@@ -3022,7 +3018,7 @@ static int chunk_drange_filter(struct extent_buffer *leaf,
3022 3018
3023 stripe_offset = btrfs_stripe_offset(leaf, stripe); 3019 stripe_offset = btrfs_stripe_offset(leaf, stripe);
3024 stripe_length = btrfs_chunk_length(leaf, chunk); 3020 stripe_length = btrfs_chunk_length(leaf, chunk);
3025 do_div(stripe_length, factor); 3021 stripe_length = div_u64(stripe_length, factor);
3026 3022
3027 if (stripe_offset < bargs->pend && 3023 if (stripe_offset < bargs->pend &&
3028 stripe_offset + stripe_length > bargs->pstart) 3024 stripe_offset + stripe_length > bargs->pstart)
@@ -3255,7 +3251,6 @@ again:
3255 } 3251 }
3256 3252
3257 ret = btrfs_relocate_chunk(chunk_root, 3253 ret = btrfs_relocate_chunk(chunk_root,
3258 chunk_root->root_key.objectid,
3259 found_key.objectid, 3254 found_key.objectid,
3260 found_key.offset); 3255 found_key.offset);
3261 if (ret && ret != -ENOSPC) 3256 if (ret && ret != -ENOSPC)
@@ -3957,7 +3952,6 @@ int btrfs_shrink_device(struct btrfs_device *device, u64 new_size)
3957 struct btrfs_dev_extent *dev_extent = NULL; 3952 struct btrfs_dev_extent *dev_extent = NULL;
3958 struct btrfs_path *path; 3953 struct btrfs_path *path;
3959 u64 length; 3954 u64 length;
3960 u64 chunk_tree;
3961 u64 chunk_objectid; 3955 u64 chunk_objectid;
3962 u64 chunk_offset; 3956 u64 chunk_offset;
3963 int ret; 3957 int ret;
@@ -4027,13 +4021,11 @@ again:
4027 break; 4021 break;
4028 } 4022 }
4029 4023
4030 chunk_tree = btrfs_dev_extent_chunk_tree(l, dev_extent);
4031 chunk_objectid = btrfs_dev_extent_chunk_objectid(l, dev_extent); 4024 chunk_objectid = btrfs_dev_extent_chunk_objectid(l, dev_extent);
4032 chunk_offset = btrfs_dev_extent_chunk_offset(l, dev_extent); 4025 chunk_offset = btrfs_dev_extent_chunk_offset(l, dev_extent);
4033 btrfs_release_path(path); 4026 btrfs_release_path(path);
4034 4027
4035 ret = btrfs_relocate_chunk(root, chunk_tree, chunk_objectid, 4028 ret = btrfs_relocate_chunk(root, chunk_objectid, chunk_offset);
4036 chunk_offset);
4037 if (ret && ret != -ENOSPC) 4029 if (ret && ret != -ENOSPC)
4038 goto done; 4030 goto done;
4039 if (ret == -ENOSPC) 4031 if (ret == -ENOSPC)
@@ -4131,7 +4123,7 @@ static int btrfs_cmp_device_info(const void *a, const void *b)
4131 return 0; 4123 return 0;
4132} 4124}
4133 4125
4134static struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES] = { 4126static const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES] = {
4135 [BTRFS_RAID_RAID10] = { 4127 [BTRFS_RAID_RAID10] = {
4136 .sub_stripes = 2, 4128 .sub_stripes = 2,
4137 .dev_stripes = 1, 4129 .dev_stripes = 1,
@@ -4289,7 +4281,7 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
4289 max_chunk_size = min(div_factor(fs_devices->total_rw_bytes, 1), 4281 max_chunk_size = min(div_factor(fs_devices->total_rw_bytes, 1),
4290 max_chunk_size); 4282 max_chunk_size);
4291 4283
4292 devices_info = kzalloc(sizeof(*devices_info) * fs_devices->rw_devices, 4284 devices_info = kcalloc(fs_devices->rw_devices, sizeof(*devices_info),
4293 GFP_NOFS); 4285 GFP_NOFS);
4294 if (!devices_info) 4286 if (!devices_info)
4295 return -ENOMEM; 4287 return -ENOMEM;
@@ -4400,8 +4392,8 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
4400 */ 4392 */
4401 if (stripe_size * data_stripes > max_chunk_size) { 4393 if (stripe_size * data_stripes > max_chunk_size) {
4402 u64 mask = (1ULL << 24) - 1; 4394 u64 mask = (1ULL << 24) - 1;
4403 stripe_size = max_chunk_size; 4395
4404 do_div(stripe_size, data_stripes); 4396 stripe_size = div_u64(max_chunk_size, data_stripes);
4405 4397
4406 /* bump the answer up to a 16MB boundary */ 4398 /* bump the answer up to a 16MB boundary */
4407 stripe_size = (stripe_size + mask) & ~mask; 4399 stripe_size = (stripe_size + mask) & ~mask;
@@ -4413,10 +4405,10 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
4413 stripe_size = devices_info[ndevs-1].max_avail; 4405 stripe_size = devices_info[ndevs-1].max_avail;
4414 } 4406 }
4415 4407
4416 do_div(stripe_size, dev_stripes); 4408 stripe_size = div_u64(stripe_size, dev_stripes);
4417 4409
4418 /* align to BTRFS_STRIPE_LEN */ 4410 /* align to BTRFS_STRIPE_LEN */
4419 do_div(stripe_size, raid_stripe_len); 4411 stripe_size = div_u64(stripe_size, raid_stripe_len);
4420 stripe_size *= raid_stripe_len; 4412 stripe_size *= raid_stripe_len;
4421 4413
4422 map = kmalloc(map_lookup_size(num_stripes), GFP_NOFS); 4414 map = kmalloc(map_lookup_size(num_stripes), GFP_NOFS);
@@ -4954,7 +4946,7 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw,
4954 u64 stripe_nr_orig; 4946 u64 stripe_nr_orig;
4955 u64 stripe_nr_end; 4947 u64 stripe_nr_end;
4956 u64 stripe_len; 4948 u64 stripe_len;
4957 int stripe_index; 4949 u32 stripe_index;
4958 int i; 4950 int i;
4959 int ret = 0; 4951 int ret = 0;
4960 int num_stripes; 4952 int num_stripes;
@@ -4995,7 +4987,7 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw,
4995 * stripe_nr counts the total number of stripes we have to stride 4987 * stripe_nr counts the total number of stripes we have to stride
4996 * to get to this block 4988 * to get to this block
4997 */ 4989 */
4998 do_div(stripe_nr, stripe_len); 4990 stripe_nr = div64_u64(stripe_nr, stripe_len);
4999 4991
5000 stripe_offset = stripe_nr * stripe_len; 4992 stripe_offset = stripe_nr * stripe_len;
5001 BUG_ON(offset < stripe_offset); 4993 BUG_ON(offset < stripe_offset);
@@ -5011,7 +5003,8 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw,
5011 /* allow a write of a full stripe, but make sure we don't 5003 /* allow a write of a full stripe, but make sure we don't
5012 * allow straddling of stripes 5004 * allow straddling of stripes
5013 */ 5005 */
5014 do_div(raid56_full_stripe_start, full_stripe_len); 5006 raid56_full_stripe_start = div64_u64(raid56_full_stripe_start,
5007 full_stripe_len);
5015 raid56_full_stripe_start *= full_stripe_len; 5008 raid56_full_stripe_start *= full_stripe_len;
5016 } 5009 }
5017 5010
@@ -5136,7 +5129,7 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw,
5136 stripe_index = 0; 5129 stripe_index = 0;
5137 stripe_nr_orig = stripe_nr; 5130 stripe_nr_orig = stripe_nr;
5138 stripe_nr_end = ALIGN(offset + *length, map->stripe_len); 5131 stripe_nr_end = ALIGN(offset + *length, map->stripe_len);
5139 do_div(stripe_nr_end, map->stripe_len); 5132 stripe_nr_end = div_u64(stripe_nr_end, map->stripe_len);
5140 stripe_end_offset = stripe_nr_end * map->stripe_len - 5133 stripe_end_offset = stripe_nr_end * map->stripe_len -
5141 (offset + *length); 5134 (offset + *length);
5142 5135
@@ -5144,7 +5137,8 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw,
5144 if (rw & REQ_DISCARD) 5137 if (rw & REQ_DISCARD)
5145 num_stripes = min_t(u64, map->num_stripes, 5138 num_stripes = min_t(u64, map->num_stripes,
5146 stripe_nr_end - stripe_nr_orig); 5139 stripe_nr_end - stripe_nr_orig);
5147 stripe_index = do_div(stripe_nr, map->num_stripes); 5140 stripe_nr = div_u64_rem(stripe_nr, map->num_stripes,
5141 &stripe_index);
5148 if (!(rw & (REQ_WRITE | REQ_DISCARD | REQ_GET_READ_MIRRORS))) 5142 if (!(rw & (REQ_WRITE | REQ_DISCARD | REQ_GET_READ_MIRRORS)))
5149 mirror_num = 1; 5143 mirror_num = 1;
5150 } else if (map->type & BTRFS_BLOCK_GROUP_RAID1) { 5144 } else if (map->type & BTRFS_BLOCK_GROUP_RAID1) {
@@ -5170,9 +5164,9 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw,
5170 } 5164 }
5171 5165
5172 } else if (map->type & BTRFS_BLOCK_GROUP_RAID10) { 5166 } else if (map->type & BTRFS_BLOCK_GROUP_RAID10) {
5173 int factor = map->num_stripes / map->sub_stripes; 5167 u32 factor = map->num_stripes / map->sub_stripes;
5174 5168
5175 stripe_index = do_div(stripe_nr, factor); 5169 stripe_nr = div_u64_rem(stripe_nr, factor, &stripe_index);
5176 stripe_index *= map->sub_stripes; 5170 stripe_index *= map->sub_stripes;
5177 5171
5178 if (rw & (REQ_WRITE | REQ_GET_READ_MIRRORS)) 5172 if (rw & (REQ_WRITE | REQ_GET_READ_MIRRORS))
@@ -5198,8 +5192,8 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw,
5198 ((rw & (REQ_WRITE | REQ_GET_READ_MIRRORS)) || 5192 ((rw & (REQ_WRITE | REQ_GET_READ_MIRRORS)) ||
5199 mirror_num > 1)) { 5193 mirror_num > 1)) {
5200 /* push stripe_nr back to the start of the full stripe */ 5194 /* push stripe_nr back to the start of the full stripe */
5201 stripe_nr = raid56_full_stripe_start; 5195 stripe_nr = div_u64(raid56_full_stripe_start,
5202 do_div(stripe_nr, stripe_len * nr_data_stripes(map)); 5196 stripe_len * nr_data_stripes(map));
5203 5197
5204 /* RAID[56] write or recovery. Return all stripes */ 5198 /* RAID[56] write or recovery. Return all stripes */
5205 num_stripes = map->num_stripes; 5199 num_stripes = map->num_stripes;
@@ -5209,32 +5203,32 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw,
5209 stripe_index = 0; 5203 stripe_index = 0;
5210 stripe_offset = 0; 5204 stripe_offset = 0;
5211 } else { 5205 } else {
5212 u64 tmp;
5213
5214 /* 5206 /*
5215 * Mirror #0 or #1 means the original data block. 5207 * Mirror #0 or #1 means the original data block.
5216 * Mirror #2 is RAID5 parity block. 5208 * Mirror #2 is RAID5 parity block.
5217 * Mirror #3 is RAID6 Q block. 5209 * Mirror #3 is RAID6 Q block.
5218 */ 5210 */
5219 stripe_index = do_div(stripe_nr, nr_data_stripes(map)); 5211 stripe_nr = div_u64_rem(stripe_nr,
5212 nr_data_stripes(map), &stripe_index);
5220 if (mirror_num > 1) 5213 if (mirror_num > 1)
5221 stripe_index = nr_data_stripes(map) + 5214 stripe_index = nr_data_stripes(map) +
5222 mirror_num - 2; 5215 mirror_num - 2;
5223 5216
5224 /* We distribute the parity blocks across stripes */ 5217 /* We distribute the parity blocks across stripes */
5225 tmp = stripe_nr + stripe_index; 5218 div_u64_rem(stripe_nr + stripe_index, map->num_stripes,
5226 stripe_index = do_div(tmp, map->num_stripes); 5219 &stripe_index);
5227 if (!(rw & (REQ_WRITE | REQ_DISCARD | 5220 if (!(rw & (REQ_WRITE | REQ_DISCARD |
5228 REQ_GET_READ_MIRRORS)) && mirror_num <= 1) 5221 REQ_GET_READ_MIRRORS)) && mirror_num <= 1)
5229 mirror_num = 1; 5222 mirror_num = 1;
5230 } 5223 }
5231 } else { 5224 } else {
5232 /* 5225 /*
5233 * after this do_div call, stripe_nr is the number of stripes 5226 * after this, stripe_nr is the number of stripes on this
5234 * on this device we have to walk to find the data, and 5227 * device we have to walk to find the data, and stripe_index is
5235 * stripe_index is the number of our device in the stripe array 5228 * the number of our device in the stripe array
5236 */ 5229 */
5237 stripe_index = do_div(stripe_nr, map->num_stripes); 5230 stripe_nr = div_u64_rem(stripe_nr, map->num_stripes,
5231 &stripe_index);
5238 mirror_num = stripe_index + 1; 5232 mirror_num = stripe_index + 1;
5239 } 5233 }
5240 BUG_ON(stripe_index >= map->num_stripes); 5234 BUG_ON(stripe_index >= map->num_stripes);
@@ -5261,7 +5255,7 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw,
5261 need_raid_map && ((rw & (REQ_WRITE | REQ_GET_READ_MIRRORS)) || 5255 need_raid_map && ((rw & (REQ_WRITE | REQ_GET_READ_MIRRORS)) ||
5262 mirror_num > 1)) { 5256 mirror_num > 1)) {
5263 u64 tmp; 5257 u64 tmp;
5264 int i, rot; 5258 unsigned rot;
5265 5259
5266 bbio->raid_map = (u64 *)((void *)bbio->stripes + 5260 bbio->raid_map = (u64 *)((void *)bbio->stripes +
5267 sizeof(struct btrfs_bio_stripe) * 5261 sizeof(struct btrfs_bio_stripe) *
@@ -5269,8 +5263,7 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw,
5269 sizeof(int) * tgtdev_indexes); 5263 sizeof(int) * tgtdev_indexes);
5270 5264
5271 /* Work out the disk rotation on this stripe-set */ 5265 /* Work out the disk rotation on this stripe-set */
5272 tmp = stripe_nr; 5266 div_u64_rem(stripe_nr, num_stripes, &rot);
5273 rot = do_div(tmp, num_stripes);
5274 5267
5275 /* Fill in the logical address of each stripe */ 5268 /* Fill in the logical address of each stripe */
5276 tmp = stripe_nr * nr_data_stripes(map); 5269 tmp = stripe_nr * nr_data_stripes(map);
@@ -5285,8 +5278,8 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw,
5285 } 5278 }
5286 5279
5287 if (rw & REQ_DISCARD) { 5280 if (rw & REQ_DISCARD) {
5288 int factor = 0; 5281 u32 factor = 0;
5289 int sub_stripes = 0; 5282 u32 sub_stripes = 0;
5290 u64 stripes_per_dev = 0; 5283 u64 stripes_per_dev = 0;
5291 u32 remaining_stripes = 0; 5284 u32 remaining_stripes = 0;
5292 u32 last_stripe = 0; 5285 u32 last_stripe = 0;
@@ -5437,9 +5430,7 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw,
5437 } 5430 }
5438 } 5431 }
5439 if (found) { 5432 if (found) {
5440 u64 length = map->stripe_len; 5433 if (physical_of_found + map->stripe_len <=
5441
5442 if (physical_of_found + length <=
5443 dev_replace->cursor_left) { 5434 dev_replace->cursor_left) {
5444 struct btrfs_bio_stripe *tgtdev_stripe = 5435 struct btrfs_bio_stripe *tgtdev_stripe =
5445 bbio->stripes + num_stripes; 5436 bbio->stripes + num_stripes;
@@ -5535,15 +5526,15 @@ int btrfs_rmap_block(struct btrfs_mapping_tree *map_tree,
5535 rmap_len = map->stripe_len; 5526 rmap_len = map->stripe_len;
5536 5527
5537 if (map->type & BTRFS_BLOCK_GROUP_RAID10) 5528 if (map->type & BTRFS_BLOCK_GROUP_RAID10)
5538 do_div(length, map->num_stripes / map->sub_stripes); 5529 length = div_u64(length, map->num_stripes / map->sub_stripes);
5539 else if (map->type & BTRFS_BLOCK_GROUP_RAID0) 5530 else if (map->type & BTRFS_BLOCK_GROUP_RAID0)
5540 do_div(length, map->num_stripes); 5531 length = div_u64(length, map->num_stripes);
5541 else if (map->type & BTRFS_BLOCK_GROUP_RAID56_MASK) { 5532 else if (map->type & BTRFS_BLOCK_GROUP_RAID56_MASK) {
5542 do_div(length, nr_data_stripes(map)); 5533 length = div_u64(length, nr_data_stripes(map));
5543 rmap_len = map->stripe_len * nr_data_stripes(map); 5534 rmap_len = map->stripe_len * nr_data_stripes(map);
5544 } 5535 }
5545 5536
5546 buf = kzalloc(sizeof(u64) * map->num_stripes, GFP_NOFS); 5537 buf = kcalloc(map->num_stripes, sizeof(u64), GFP_NOFS);
5547 BUG_ON(!buf); /* -ENOMEM */ 5538 BUG_ON(!buf); /* -ENOMEM */
5548 5539
5549 for (i = 0; i < map->num_stripes; i++) { 5540 for (i = 0; i < map->num_stripes; i++) {
@@ -5554,11 +5545,11 @@ int btrfs_rmap_block(struct btrfs_mapping_tree *map_tree,
5554 continue; 5545 continue;
5555 5546
5556 stripe_nr = physical - map->stripes[i].physical; 5547 stripe_nr = physical - map->stripes[i].physical;
5557 do_div(stripe_nr, map->stripe_len); 5548 stripe_nr = div_u64(stripe_nr, map->stripe_len);
5558 5549
5559 if (map->type & BTRFS_BLOCK_GROUP_RAID10) { 5550 if (map->type & BTRFS_BLOCK_GROUP_RAID10) {
5560 stripe_nr = stripe_nr * map->num_stripes + i; 5551 stripe_nr = stripe_nr * map->num_stripes + i;
5561 do_div(stripe_nr, map->sub_stripes); 5552 stripe_nr = div_u64(stripe_nr, map->sub_stripes);
5562 } else if (map->type & BTRFS_BLOCK_GROUP_RAID0) { 5553 } else if (map->type & BTRFS_BLOCK_GROUP_RAID0) {
5563 stripe_nr = stripe_nr * map->num_stripes + i; 5554 stripe_nr = stripe_nr * map->num_stripes + i;
5564 } /* else if RAID[56], multiply by nr_data_stripes(). 5555 } /* else if RAID[56], multiply by nr_data_stripes().
@@ -5835,8 +5826,8 @@ int btrfs_map_bio(struct btrfs_root *root, int rw, struct bio *bio,
5835 u64 length = 0; 5826 u64 length = 0;
5836 u64 map_length; 5827 u64 map_length;
5837 int ret; 5828 int ret;
5838 int dev_nr = 0; 5829 int dev_nr;
5839 int total_devs = 1; 5830 int total_devs;
5840 struct btrfs_bio *bbio = NULL; 5831 struct btrfs_bio *bbio = NULL;
5841 5832
5842 length = bio->bi_iter.bi_size; 5833 length = bio->bi_iter.bi_size;
@@ -5877,11 +5868,10 @@ int btrfs_map_bio(struct btrfs_root *root, int rw, struct bio *bio,
5877 BUG(); 5868 BUG();
5878 } 5869 }
5879 5870
5880 while (dev_nr < total_devs) { 5871 for (dev_nr = 0; dev_nr < total_devs; dev_nr++) {
5881 dev = bbio->stripes[dev_nr].dev; 5872 dev = bbio->stripes[dev_nr].dev;
5882 if (!dev || !dev->bdev || (rw & WRITE && !dev->writeable)) { 5873 if (!dev || !dev->bdev || (rw & WRITE && !dev->writeable)) {
5883 bbio_error(bbio, first_bio, logical); 5874 bbio_error(bbio, first_bio, logical);
5884 dev_nr++;
5885 continue; 5875 continue;
5886 } 5876 }
5887 5877
@@ -5894,7 +5884,6 @@ int btrfs_map_bio(struct btrfs_root *root, int rw, struct bio *bio,
5894 ret = breakup_stripe_bio(root, bbio, first_bio, dev, 5884 ret = breakup_stripe_bio(root, bbio, first_bio, dev,
5895 dev_nr, rw, async_submit); 5885 dev_nr, rw, async_submit);
5896 BUG_ON(ret); 5886 BUG_ON(ret);
5897 dev_nr++;
5898 continue; 5887 continue;
5899 } 5888 }
5900 5889
@@ -5909,7 +5898,6 @@ int btrfs_map_bio(struct btrfs_root *root, int rw, struct bio *bio,
5909 submit_stripe_bio(root, bbio, bio, 5898 submit_stripe_bio(root, bbio, bio,
5910 bbio->stripes[dev_nr].physical, dev_nr, rw, 5899 bbio->stripes[dev_nr].physical, dev_nr, rw,
5911 async_submit); 5900 async_submit);
5912 dev_nr++;
5913 } 5901 }
5914 btrfs_bio_counter_dec(root->fs_info); 5902 btrfs_bio_counter_dec(root->fs_info);
5915 return 0; 5903 return 0;
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
index 83069dec6898..ebc31331a837 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -421,8 +421,7 @@ int btrfs_open_devices(struct btrfs_fs_devices *fs_devices,
421int btrfs_scan_one_device(const char *path, fmode_t flags, void *holder, 421int btrfs_scan_one_device(const char *path, fmode_t flags, void *holder,
422 struct btrfs_fs_devices **fs_devices_ret); 422 struct btrfs_fs_devices **fs_devices_ret);
423int btrfs_close_devices(struct btrfs_fs_devices *fs_devices); 423int btrfs_close_devices(struct btrfs_fs_devices *fs_devices);
424void btrfs_close_extra_devices(struct btrfs_fs_info *fs_info, 424void btrfs_close_extra_devices(struct btrfs_fs_devices *fs_devices, int step);
425 struct btrfs_fs_devices *fs_devices, int step);
426int btrfs_find_device_missing_or_by_path(struct btrfs_root *root, 425int btrfs_find_device_missing_or_by_path(struct btrfs_root *root,
427 char *device_path, 426 char *device_path,
428 struct btrfs_device **device); 427 struct btrfs_device **device);
diff --git a/fs/btrfs/xattr.c b/fs/btrfs/xattr.c
index 883b93623bc5..6f518c90e1c1 100644
--- a/fs/btrfs/xattr.c
+++ b/fs/btrfs/xattr.c
@@ -261,7 +261,7 @@ out:
261ssize_t btrfs_listxattr(struct dentry *dentry, char *buffer, size_t size) 261ssize_t btrfs_listxattr(struct dentry *dentry, char *buffer, size_t size)
262{ 262{
263 struct btrfs_key key, found_key; 263 struct btrfs_key key, found_key;
264 struct inode *inode = dentry->d_inode; 264 struct inode *inode = d_inode(dentry);
265 struct btrfs_root *root = BTRFS_I(inode)->root; 265 struct btrfs_root *root = BTRFS_I(inode)->root;
266 struct btrfs_path *path; 266 struct btrfs_path *path;
267 struct extent_buffer *leaf; 267 struct extent_buffer *leaf;
@@ -364,22 +364,42 @@ const struct xattr_handler *btrfs_xattr_handlers[] = {
364/* 364/*
365 * Check if the attribute is in a supported namespace. 365 * Check if the attribute is in a supported namespace.
366 * 366 *
367 * This applied after the check for the synthetic attributes in the system 367 * This is applied after the check for the synthetic attributes in the system
368 * namespace. 368 * namespace.
369 */ 369 */
370static bool btrfs_is_valid_xattr(const char *name) 370static int btrfs_is_valid_xattr(const char *name)
371{ 371{
372 return !strncmp(name, XATTR_SECURITY_PREFIX, 372 int len = strlen(name);
373 XATTR_SECURITY_PREFIX_LEN) || 373 int prefixlen = 0;
374 !strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN) || 374
375 !strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN) || 375 if (!strncmp(name, XATTR_SECURITY_PREFIX,
376 !strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN) || 376 XATTR_SECURITY_PREFIX_LEN))
377 !strncmp(name, XATTR_BTRFS_PREFIX, XATTR_BTRFS_PREFIX_LEN); 377 prefixlen = XATTR_SECURITY_PREFIX_LEN;
378 else if (!strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN))
379 prefixlen = XATTR_SYSTEM_PREFIX_LEN;
380 else if (!strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN))
381 prefixlen = XATTR_TRUSTED_PREFIX_LEN;
382 else if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN))
383 prefixlen = XATTR_USER_PREFIX_LEN;
384 else if (!strncmp(name, XATTR_BTRFS_PREFIX, XATTR_BTRFS_PREFIX_LEN))
385 prefixlen = XATTR_BTRFS_PREFIX_LEN;
386 else
387 return -EOPNOTSUPP;
388
389 /*
390 * The name cannot consist of just prefix
391 */
392 if (len <= prefixlen)
393 return -EINVAL;
394
395 return 0;
378} 396}
379 397
380ssize_t btrfs_getxattr(struct dentry *dentry, const char *name, 398ssize_t btrfs_getxattr(struct dentry *dentry, const char *name,
381 void *buffer, size_t size) 399 void *buffer, size_t size)
382{ 400{
401 int ret;
402
383 /* 403 /*
384 * If this is a request for a synthetic attribute in the system.* 404 * If this is a request for a synthetic attribute in the system.*
385 * namespace use the generic infrastructure to resolve a handler 405 * namespace use the generic infrastructure to resolve a handler
@@ -388,15 +408,17 @@ ssize_t btrfs_getxattr(struct dentry *dentry, const char *name,
388 if (!strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN)) 408 if (!strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN))
389 return generic_getxattr(dentry, name, buffer, size); 409 return generic_getxattr(dentry, name, buffer, size);
390 410
391 if (!btrfs_is_valid_xattr(name)) 411 ret = btrfs_is_valid_xattr(name);
392 return -EOPNOTSUPP; 412 if (ret)
393 return __btrfs_getxattr(dentry->d_inode, name, buffer, size); 413 return ret;
414 return __btrfs_getxattr(d_inode(dentry), name, buffer, size);
394} 415}
395 416
396int btrfs_setxattr(struct dentry *dentry, const char *name, const void *value, 417int btrfs_setxattr(struct dentry *dentry, const char *name, const void *value,
397 size_t size, int flags) 418 size_t size, int flags)
398{ 419{
399 struct btrfs_root *root = BTRFS_I(dentry->d_inode)->root; 420 struct btrfs_root *root = BTRFS_I(d_inode(dentry))->root;
421 int ret;
400 422
401 /* 423 /*
402 * The permission on security.* and system.* is not checked 424 * The permission on security.* and system.* is not checked
@@ -413,23 +435,25 @@ int btrfs_setxattr(struct dentry *dentry, const char *name, const void *value,
413 if (!strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN)) 435 if (!strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN))
414 return generic_setxattr(dentry, name, value, size, flags); 436 return generic_setxattr(dentry, name, value, size, flags);
415 437
416 if (!btrfs_is_valid_xattr(name)) 438 ret = btrfs_is_valid_xattr(name);
417 return -EOPNOTSUPP; 439 if (ret)
440 return ret;
418 441
419 if (!strncmp(name, XATTR_BTRFS_PREFIX, XATTR_BTRFS_PREFIX_LEN)) 442 if (!strncmp(name, XATTR_BTRFS_PREFIX, XATTR_BTRFS_PREFIX_LEN))
420 return btrfs_set_prop(dentry->d_inode, name, 443 return btrfs_set_prop(d_inode(dentry), name,
421 value, size, flags); 444 value, size, flags);
422 445
423 if (size == 0) 446 if (size == 0)
424 value = ""; /* empty EA, do not remove */ 447 value = ""; /* empty EA, do not remove */
425 448
426 return __btrfs_setxattr(NULL, dentry->d_inode, name, value, size, 449 return __btrfs_setxattr(NULL, d_inode(dentry), name, value, size,
427 flags); 450 flags);
428} 451}
429 452
430int btrfs_removexattr(struct dentry *dentry, const char *name) 453int btrfs_removexattr(struct dentry *dentry, const char *name)
431{ 454{
432 struct btrfs_root *root = BTRFS_I(dentry->d_inode)->root; 455 struct btrfs_root *root = BTRFS_I(d_inode(dentry))->root;
456 int ret;
433 457
434 /* 458 /*
435 * The permission on security.* and system.* is not checked 459 * The permission on security.* and system.* is not checked
@@ -446,14 +470,15 @@ int btrfs_removexattr(struct dentry *dentry, const char *name)
446 if (!strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN)) 470 if (!strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN))
447 return generic_removexattr(dentry, name); 471 return generic_removexattr(dentry, name);
448 472
449 if (!btrfs_is_valid_xattr(name)) 473 ret = btrfs_is_valid_xattr(name);
450 return -EOPNOTSUPP; 474 if (ret)
475 return ret;
451 476
452 if (!strncmp(name, XATTR_BTRFS_PREFIX, XATTR_BTRFS_PREFIX_LEN)) 477 if (!strncmp(name, XATTR_BTRFS_PREFIX, XATTR_BTRFS_PREFIX_LEN))
453 return btrfs_set_prop(dentry->d_inode, name, 478 return btrfs_set_prop(d_inode(dentry), name,
454 NULL, 0, XATTR_REPLACE); 479 NULL, 0, XATTR_REPLACE);
455 480
456 return __btrfs_setxattr(NULL, dentry->d_inode, name, NULL, 0, 481 return __btrfs_setxattr(NULL, d_inode(dentry), name, NULL, 0,
457 XATTR_REPLACE); 482 XATTR_REPLACE);
458} 483}
459 484
diff --git a/fs/btrfs/zlib.c b/fs/btrfs/zlib.c
index fb22fd8d8fb8..82990b8f872b 100644
--- a/fs/btrfs/zlib.c
+++ b/fs/btrfs/zlib.c
@@ -403,7 +403,7 @@ next:
403 return ret; 403 return ret;
404} 404}
405 405
406struct btrfs_compress_op btrfs_zlib_compress = { 406const struct btrfs_compress_op btrfs_zlib_compress = {
407 .alloc_workspace = zlib_alloc_workspace, 407 .alloc_workspace = zlib_alloc_workspace,
408 .free_workspace = zlib_free_workspace, 408 .free_workspace = zlib_free_workspace,
409 .compress_pages = zlib_compress_pages, 409 .compress_pages = zlib_compress_pages,
diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
index fbb08e97438d..6af790fc3df8 100644
--- a/fs/cachefiles/bind.c
+++ b/fs/cachefiles/bind.c
@@ -123,11 +123,11 @@ static int cachefiles_daemon_add_cache(struct cachefiles_cache *cache)
123 123
124 /* check parameters */ 124 /* check parameters */
125 ret = -EOPNOTSUPP; 125 ret = -EOPNOTSUPP;
126 if (!root->d_inode || 126 if (d_is_negative(root) ||
127 !root->d_inode->i_op->lookup || 127 !d_backing_inode(root)->i_op->lookup ||
128 !root->d_inode->i_op->mkdir || 128 !d_backing_inode(root)->i_op->mkdir ||
129 !root->d_inode->i_op->setxattr || 129 !d_backing_inode(root)->i_op->setxattr ||
130 !root->d_inode->i_op->getxattr || 130 !d_backing_inode(root)->i_op->getxattr ||
131 !root->d_sb->s_op->statfs || 131 !root->d_sb->s_op->statfs ||
132 !root->d_sb->s_op->sync_fs) 132 !root->d_sb->s_op->sync_fs)
133 goto error_unsupported; 133 goto error_unsupported;
diff --git a/fs/cachefiles/interface.c b/fs/cachefiles/interface.c
index 232426214fdd..afa023dded5b 100644
--- a/fs/cachefiles/interface.c
+++ b/fs/cachefiles/interface.c
@@ -441,12 +441,12 @@ static int cachefiles_attr_changed(struct fscache_object *_object)
441 441
442 fscache_set_store_limit(&object->fscache, ni_size); 442 fscache_set_store_limit(&object->fscache, ni_size);
443 443
444 oi_size = i_size_read(object->backer->d_inode); 444 oi_size = i_size_read(d_backing_inode(object->backer));
445 if (oi_size == ni_size) 445 if (oi_size == ni_size)
446 return 0; 446 return 0;
447 447
448 cachefiles_begin_secure(cache, &saved_cred); 448 cachefiles_begin_secure(cache, &saved_cred);
449 mutex_lock(&object->backer->d_inode->i_mutex); 449 mutex_lock(&d_inode(object->backer)->i_mutex);
450 450
451 /* if there's an extension to a partial page at the end of the backing 451 /* if there's an extension to a partial page at the end of the backing
452 * file, we need to discard the partial page so that we pick up new 452 * file, we need to discard the partial page so that we pick up new
@@ -465,7 +465,7 @@ static int cachefiles_attr_changed(struct fscache_object *_object)
465 ret = notify_change(object->backer, &newattrs, NULL); 465 ret = notify_change(object->backer, &newattrs, NULL);
466 466
467truncate_failed: 467truncate_failed:
468 mutex_unlock(&object->backer->d_inode->i_mutex); 468 mutex_unlock(&d_inode(object->backer)->i_mutex);
469 cachefiles_end_secure(cache, saved_cred); 469 cachefiles_end_secure(cache, saved_cred);
470 470
471 if (ret == -EIO) { 471 if (ret == -EIO) {
diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
index 1e51714eb33e..ab857ab9f40d 100644
--- a/fs/cachefiles/namei.c
+++ b/fs/cachefiles/namei.c
@@ -286,13 +286,13 @@ static int cachefiles_bury_object(struct cachefiles_cache *cache,
286 if (ret < 0) { 286 if (ret < 0) {
287 cachefiles_io_error(cache, "Unlink security error"); 287 cachefiles_io_error(cache, "Unlink security error");
288 } else { 288 } else {
289 ret = vfs_unlink(dir->d_inode, rep, NULL); 289 ret = vfs_unlink(d_inode(dir), rep, NULL);
290 290
291 if (preemptive) 291 if (preemptive)
292 cachefiles_mark_object_buried(cache, rep); 292 cachefiles_mark_object_buried(cache, rep);
293 } 293 }
294 294
295 mutex_unlock(&dir->d_inode->i_mutex); 295 mutex_unlock(&d_inode(dir)->i_mutex);
296 296
297 if (ret == -EIO) 297 if (ret == -EIO)
298 cachefiles_io_error(cache, "Unlink failed"); 298 cachefiles_io_error(cache, "Unlink failed");
@@ -303,7 +303,7 @@ static int cachefiles_bury_object(struct cachefiles_cache *cache,
303 303
304 /* directories have to be moved to the graveyard */ 304 /* directories have to be moved to the graveyard */
305 _debug("move stale object to graveyard"); 305 _debug("move stale object to graveyard");
306 mutex_unlock(&dir->d_inode->i_mutex); 306 mutex_unlock(&d_inode(dir)->i_mutex);
307 307
308try_again: 308try_again:
309 /* first step is to make up a grave dentry in the graveyard */ 309 /* first step is to make up a grave dentry in the graveyard */
@@ -355,7 +355,7 @@ try_again:
355 return -EIO; 355 return -EIO;
356 } 356 }
357 357
358 if (grave->d_inode) { 358 if (d_is_positive(grave)) {
359 unlock_rename(cache->graveyard, dir); 359 unlock_rename(cache->graveyard, dir);
360 dput(grave); 360 dput(grave);
361 grave = NULL; 361 grave = NULL;
@@ -387,8 +387,8 @@ try_again:
387 if (ret < 0) { 387 if (ret < 0) {
388 cachefiles_io_error(cache, "Rename security error %d", ret); 388 cachefiles_io_error(cache, "Rename security error %d", ret);
389 } else { 389 } else {
390 ret = vfs_rename(dir->d_inode, rep, 390 ret = vfs_rename(d_inode(dir), rep,
391 cache->graveyard->d_inode, grave, NULL, 0); 391 d_inode(cache->graveyard), grave, NULL, 0);
392 if (ret != 0 && ret != -ENOMEM) 392 if (ret != 0 && ret != -ENOMEM)
393 cachefiles_io_error(cache, 393 cachefiles_io_error(cache,
394 "Rename failed with error %d", ret); 394 "Rename failed with error %d", ret);
@@ -415,18 +415,18 @@ int cachefiles_delete_object(struct cachefiles_cache *cache,
415 _enter(",OBJ%x{%p}", object->fscache.debug_id, object->dentry); 415 _enter(",OBJ%x{%p}", object->fscache.debug_id, object->dentry);
416 416
417 ASSERT(object->dentry); 417 ASSERT(object->dentry);
418 ASSERT(object->dentry->d_inode); 418 ASSERT(d_backing_inode(object->dentry));
419 ASSERT(object->dentry->d_parent); 419 ASSERT(object->dentry->d_parent);
420 420
421 dir = dget_parent(object->dentry); 421 dir = dget_parent(object->dentry);
422 422
423 mutex_lock_nested(&dir->d_inode->i_mutex, I_MUTEX_PARENT); 423 mutex_lock_nested(&d_inode(dir)->i_mutex, I_MUTEX_PARENT);
424 424
425 if (test_bit(CACHEFILES_OBJECT_BURIED, &object->flags)) { 425 if (test_bit(CACHEFILES_OBJECT_BURIED, &object->flags)) {
426 /* object allocation for the same key preemptively deleted this 426 /* object allocation for the same key preemptively deleted this
427 * object's file so that it could create its own file */ 427 * object's file so that it could create its own file */
428 _debug("object preemptively buried"); 428 _debug("object preemptively buried");
429 mutex_unlock(&dir->d_inode->i_mutex); 429 mutex_unlock(&d_inode(dir)->i_mutex);
430 ret = 0; 430 ret = 0;
431 } else { 431 } else {
432 /* we need to check that our parent is _still_ our parent - it 432 /* we need to check that our parent is _still_ our parent - it
@@ -438,7 +438,7 @@ int cachefiles_delete_object(struct cachefiles_cache *cache,
438 /* it got moved, presumably by cachefilesd culling it, 438 /* it got moved, presumably by cachefilesd culling it,
439 * so it's no longer in the key path and we can ignore 439 * so it's no longer in the key path and we can ignore
440 * it */ 440 * it */
441 mutex_unlock(&dir->d_inode->i_mutex); 441 mutex_unlock(&d_inode(dir)->i_mutex);
442 ret = 0; 442 ret = 0;
443 } 443 }
444 } 444 }
@@ -473,7 +473,7 @@ int cachefiles_walk_to_object(struct cachefiles_object *parent,
473 path.mnt = cache->mnt; 473 path.mnt = cache->mnt;
474 474
475 ASSERT(parent->dentry); 475 ASSERT(parent->dentry);
476 ASSERT(parent->dentry->d_inode); 476 ASSERT(d_backing_inode(parent->dentry));
477 477
478 if (!(d_is_dir(parent->dentry))) { 478 if (!(d_is_dir(parent->dentry))) {
479 // TODO: convert file to dir 479 // TODO: convert file to dir
@@ -497,7 +497,7 @@ lookup_again:
497 /* search the current directory for the element name */ 497 /* search the current directory for the element name */
498 _debug("lookup '%s'", name); 498 _debug("lookup '%s'", name);
499 499
500 mutex_lock_nested(&dir->d_inode->i_mutex, I_MUTEX_PARENT); 500 mutex_lock_nested(&d_inode(dir)->i_mutex, I_MUTEX_PARENT);
501 501
502 start = jiffies; 502 start = jiffies;
503 next = lookup_one_len(name, dir, nlen); 503 next = lookup_one_len(name, dir, nlen);
@@ -505,21 +505,21 @@ lookup_again:
505 if (IS_ERR(next)) 505 if (IS_ERR(next))
506 goto lookup_error; 506 goto lookup_error;
507 507
508 _debug("next -> %p %s", next, next->d_inode ? "positive" : "negative"); 508 _debug("next -> %p %s", next, d_backing_inode(next) ? "positive" : "negative");
509 509
510 if (!key) 510 if (!key)
511 object->new = !next->d_inode; 511 object->new = !d_backing_inode(next);
512 512
513 /* if this element of the path doesn't exist, then the lookup phase 513 /* if this element of the path doesn't exist, then the lookup phase
514 * failed, and we can release any readers in the certain knowledge that 514 * failed, and we can release any readers in the certain knowledge that
515 * there's nothing for them to actually read */ 515 * there's nothing for them to actually read */
516 if (!next->d_inode) 516 if (d_is_negative(next))
517 fscache_object_lookup_negative(&object->fscache); 517 fscache_object_lookup_negative(&object->fscache);
518 518
519 /* we need to create the object if it's negative */ 519 /* we need to create the object if it's negative */
520 if (key || object->type == FSCACHE_COOKIE_TYPE_INDEX) { 520 if (key || object->type == FSCACHE_COOKIE_TYPE_INDEX) {
521 /* index objects and intervening tree levels must be subdirs */ 521 /* index objects and intervening tree levels must be subdirs */
522 if (!next->d_inode) { 522 if (d_is_negative(next)) {
523 ret = cachefiles_has_space(cache, 1, 0); 523 ret = cachefiles_has_space(cache, 1, 0);
524 if (ret < 0) 524 if (ret < 0)
525 goto create_error; 525 goto create_error;
@@ -529,26 +529,26 @@ lookup_again:
529 if (ret < 0) 529 if (ret < 0)
530 goto create_error; 530 goto create_error;
531 start = jiffies; 531 start = jiffies;
532 ret = vfs_mkdir(dir->d_inode, next, 0); 532 ret = vfs_mkdir(d_inode(dir), next, 0);
533 cachefiles_hist(cachefiles_mkdir_histogram, start); 533 cachefiles_hist(cachefiles_mkdir_histogram, start);
534 if (ret < 0) 534 if (ret < 0)
535 goto create_error; 535 goto create_error;
536 536
537 ASSERT(next->d_inode); 537 ASSERT(d_backing_inode(next));
538 538
539 _debug("mkdir -> %p{%p{ino=%lu}}", 539 _debug("mkdir -> %p{%p{ino=%lu}}",
540 next, next->d_inode, next->d_inode->i_ino); 540 next, d_backing_inode(next), d_backing_inode(next)->i_ino);
541 541
542 } else if (!d_can_lookup(next)) { 542 } else if (!d_can_lookup(next)) {
543 pr_err("inode %lu is not a directory\n", 543 pr_err("inode %lu is not a directory\n",
544 next->d_inode->i_ino); 544 d_backing_inode(next)->i_ino);
545 ret = -ENOBUFS; 545 ret = -ENOBUFS;
546 goto error; 546 goto error;
547 } 547 }
548 548
549 } else { 549 } else {
550 /* non-index objects start out life as files */ 550 /* non-index objects start out life as files */
551 if (!next->d_inode) { 551 if (d_is_negative(next)) {
552 ret = cachefiles_has_space(cache, 1, 0); 552 ret = cachefiles_has_space(cache, 1, 0);
553 if (ret < 0) 553 if (ret < 0)
554 goto create_error; 554 goto create_error;
@@ -558,21 +558,21 @@ lookup_again:
558 if (ret < 0) 558 if (ret < 0)
559 goto create_error; 559 goto create_error;
560 start = jiffies; 560 start = jiffies;
561 ret = vfs_create(dir->d_inode, next, S_IFREG, true); 561 ret = vfs_create(d_inode(dir), next, S_IFREG, true);
562 cachefiles_hist(cachefiles_create_histogram, start); 562 cachefiles_hist(cachefiles_create_histogram, start);
563 if (ret < 0) 563 if (ret < 0)
564 goto create_error; 564 goto create_error;
565 565
566 ASSERT(next->d_inode); 566 ASSERT(d_backing_inode(next));
567 567
568 _debug("create -> %p{%p{ino=%lu}}", 568 _debug("create -> %p{%p{ino=%lu}}",
569 next, next->d_inode, next->d_inode->i_ino); 569 next, d_backing_inode(next), d_backing_inode(next)->i_ino);
570 570
571 } else if (!d_can_lookup(next) && 571 } else if (!d_can_lookup(next) &&
572 !d_is_reg(next) 572 !d_is_reg(next)
573 ) { 573 ) {
574 pr_err("inode %lu is not a file or directory\n", 574 pr_err("inode %lu is not a file or directory\n",
575 next->d_inode->i_ino); 575 d_backing_inode(next)->i_ino);
576 ret = -ENOBUFS; 576 ret = -ENOBUFS;
577 goto error; 577 goto error;
578 } 578 }
@@ -581,7 +581,7 @@ lookup_again:
581 /* process the next component */ 581 /* process the next component */
582 if (key) { 582 if (key) {
583 _debug("advance"); 583 _debug("advance");
584 mutex_unlock(&dir->d_inode->i_mutex); 584 mutex_unlock(&d_inode(dir)->i_mutex);
585 dput(dir); 585 dput(dir);
586 dir = next; 586 dir = next;
587 next = NULL; 587 next = NULL;
@@ -617,7 +617,7 @@ lookup_again:
617 /* note that we're now using this object */ 617 /* note that we're now using this object */
618 ret = cachefiles_mark_object_active(cache, object); 618 ret = cachefiles_mark_object_active(cache, object);
619 619
620 mutex_unlock(&dir->d_inode->i_mutex); 620 mutex_unlock(&d_inode(dir)->i_mutex);
621 dput(dir); 621 dput(dir);
622 dir = NULL; 622 dir = NULL;
623 623
@@ -646,7 +646,7 @@ lookup_again:
646 const struct address_space_operations *aops; 646 const struct address_space_operations *aops;
647 647
648 ret = -EPERM; 648 ret = -EPERM;
649 aops = object->dentry->d_inode->i_mapping->a_ops; 649 aops = d_backing_inode(object->dentry)->i_mapping->a_ops;
650 if (!aops->bmap) 650 if (!aops->bmap)
651 goto check_error; 651 goto check_error;
652 652
@@ -659,7 +659,7 @@ lookup_again:
659 object->new = 0; 659 object->new = 0;
660 fscache_obtained_object(&object->fscache); 660 fscache_obtained_object(&object->fscache);
661 661
662 _leave(" = 0 [%lu]", object->dentry->d_inode->i_ino); 662 _leave(" = 0 [%lu]", d_backing_inode(object->dentry)->i_ino);
663 return 0; 663 return 0;
664 664
665create_error: 665create_error:
@@ -695,7 +695,7 @@ lookup_error:
695 cachefiles_io_error(cache, "Lookup failed"); 695 cachefiles_io_error(cache, "Lookup failed");
696 next = NULL; 696 next = NULL;
697error: 697error:
698 mutex_unlock(&dir->d_inode->i_mutex); 698 mutex_unlock(&d_inode(dir)->i_mutex);
699 dput(next); 699 dput(next);
700error_out2: 700error_out2:
701 dput(dir); 701 dput(dir);
@@ -719,7 +719,7 @@ struct dentry *cachefiles_get_directory(struct cachefiles_cache *cache,
719 _enter(",,%s", dirname); 719 _enter(",,%s", dirname);
720 720
721 /* search the current directory for the element name */ 721 /* search the current directory for the element name */
722 mutex_lock(&dir->d_inode->i_mutex); 722 mutex_lock(&d_inode(dir)->i_mutex);
723 723
724 start = jiffies; 724 start = jiffies;
725 subdir = lookup_one_len(dirname, dir, strlen(dirname)); 725 subdir = lookup_one_len(dirname, dir, strlen(dirname));
@@ -731,10 +731,10 @@ struct dentry *cachefiles_get_directory(struct cachefiles_cache *cache,
731 } 731 }
732 732
733 _debug("subdir -> %p %s", 733 _debug("subdir -> %p %s",
734 subdir, subdir->d_inode ? "positive" : "negative"); 734 subdir, d_backing_inode(subdir) ? "positive" : "negative");
735 735
736 /* we need to create the subdir if it doesn't exist yet */ 736 /* we need to create the subdir if it doesn't exist yet */
737 if (!subdir->d_inode) { 737 if (d_is_negative(subdir)) {
738 ret = cachefiles_has_space(cache, 1, 0); 738 ret = cachefiles_has_space(cache, 1, 0);
739 if (ret < 0) 739 if (ret < 0)
740 goto mkdir_error; 740 goto mkdir_error;
@@ -746,22 +746,22 @@ struct dentry *cachefiles_get_directory(struct cachefiles_cache *cache,
746 ret = security_path_mkdir(&path, subdir, 0700); 746 ret = security_path_mkdir(&path, subdir, 0700);
747 if (ret < 0) 747 if (ret < 0)
748 goto mkdir_error; 748 goto mkdir_error;
749 ret = vfs_mkdir(dir->d_inode, subdir, 0700); 749 ret = vfs_mkdir(d_inode(dir), subdir, 0700);
750 if (ret < 0) 750 if (ret < 0)
751 goto mkdir_error; 751 goto mkdir_error;
752 752
753 ASSERT(subdir->d_inode); 753 ASSERT(d_backing_inode(subdir));
754 754
755 _debug("mkdir -> %p{%p{ino=%lu}}", 755 _debug("mkdir -> %p{%p{ino=%lu}}",
756 subdir, 756 subdir,
757 subdir->d_inode, 757 d_backing_inode(subdir),
758 subdir->d_inode->i_ino); 758 d_backing_inode(subdir)->i_ino);
759 } 759 }
760 760
761 mutex_unlock(&dir->d_inode->i_mutex); 761 mutex_unlock(&d_inode(dir)->i_mutex);
762 762
763 /* we need to make sure the subdir is a directory */ 763 /* we need to make sure the subdir is a directory */
764 ASSERT(subdir->d_inode); 764 ASSERT(d_backing_inode(subdir));
765 765
766 if (!d_can_lookup(subdir)) { 766 if (!d_can_lookup(subdir)) {
767 pr_err("%s is not a directory\n", dirname); 767 pr_err("%s is not a directory\n", dirname);
@@ -770,18 +770,18 @@ struct dentry *cachefiles_get_directory(struct cachefiles_cache *cache,
770 } 770 }
771 771
772 ret = -EPERM; 772 ret = -EPERM;
773 if (!subdir->d_inode->i_op->setxattr || 773 if (!d_backing_inode(subdir)->i_op->setxattr ||
774 !subdir->d_inode->i_op->getxattr || 774 !d_backing_inode(subdir)->i_op->getxattr ||
775 !subdir->d_inode->i_op->lookup || 775 !d_backing_inode(subdir)->i_op->lookup ||
776 !subdir->d_inode->i_op->mkdir || 776 !d_backing_inode(subdir)->i_op->mkdir ||
777 !subdir->d_inode->i_op->create || 777 !d_backing_inode(subdir)->i_op->create ||
778 (!subdir->d_inode->i_op->rename && 778 (!d_backing_inode(subdir)->i_op->rename &&
779 !subdir->d_inode->i_op->rename2) || 779 !d_backing_inode(subdir)->i_op->rename2) ||
780 !subdir->d_inode->i_op->rmdir || 780 !d_backing_inode(subdir)->i_op->rmdir ||
781 !subdir->d_inode->i_op->unlink) 781 !d_backing_inode(subdir)->i_op->unlink)
782 goto check_error; 782 goto check_error;
783 783
784 _leave(" = [%lu]", subdir->d_inode->i_ino); 784 _leave(" = [%lu]", d_backing_inode(subdir)->i_ino);
785 return subdir; 785 return subdir;
786 786
787check_error: 787check_error:
@@ -790,19 +790,19 @@ check_error:
790 return ERR_PTR(ret); 790 return ERR_PTR(ret);
791 791
792mkdir_error: 792mkdir_error:
793 mutex_unlock(&dir->d_inode->i_mutex); 793 mutex_unlock(&d_inode(dir)->i_mutex);
794 dput(subdir); 794 dput(subdir);
795 pr_err("mkdir %s failed with error %d\n", dirname, ret); 795 pr_err("mkdir %s failed with error %d\n", dirname, ret);
796 return ERR_PTR(ret); 796 return ERR_PTR(ret);
797 797
798lookup_error: 798lookup_error:
799 mutex_unlock(&dir->d_inode->i_mutex); 799 mutex_unlock(&d_inode(dir)->i_mutex);
800 ret = PTR_ERR(subdir); 800 ret = PTR_ERR(subdir);
801 pr_err("Lookup %s failed with error %d\n", dirname, ret); 801 pr_err("Lookup %s failed with error %d\n", dirname, ret);
802 return ERR_PTR(ret); 802 return ERR_PTR(ret);
803 803
804nomem_d_alloc: 804nomem_d_alloc:
805 mutex_unlock(&dir->d_inode->i_mutex); 805 mutex_unlock(&d_inode(dir)->i_mutex);
806 _leave(" = -ENOMEM"); 806 _leave(" = -ENOMEM");
807 return ERR_PTR(-ENOMEM); 807 return ERR_PTR(-ENOMEM);
808} 808}
@@ -827,7 +827,7 @@ static struct dentry *cachefiles_check_active(struct cachefiles_cache *cache,
827 // dir, filename); 827 // dir, filename);
828 828
829 /* look up the victim */ 829 /* look up the victim */
830 mutex_lock_nested(&dir->d_inode->i_mutex, I_MUTEX_PARENT); 830 mutex_lock_nested(&d_inode(dir)->i_mutex, I_MUTEX_PARENT);
831 831
832 start = jiffies; 832 start = jiffies;
833 victim = lookup_one_len(filename, dir, strlen(filename)); 833 victim = lookup_one_len(filename, dir, strlen(filename));
@@ -836,13 +836,13 @@ static struct dentry *cachefiles_check_active(struct cachefiles_cache *cache,
836 goto lookup_error; 836 goto lookup_error;
837 837
838 //_debug("victim -> %p %s", 838 //_debug("victim -> %p %s",
839 // victim, victim->d_inode ? "positive" : "negative"); 839 // victim, d_backing_inode(victim) ? "positive" : "negative");
840 840
841 /* if the object is no longer there then we probably retired the object 841 /* if the object is no longer there then we probably retired the object
842 * at the netfs's request whilst the cull was in progress 842 * at the netfs's request whilst the cull was in progress
843 */ 843 */
844 if (!victim->d_inode) { 844 if (d_is_negative(victim)) {
845 mutex_unlock(&dir->d_inode->i_mutex); 845 mutex_unlock(&d_inode(dir)->i_mutex);
846 dput(victim); 846 dput(victim);
847 _leave(" = -ENOENT [absent]"); 847 _leave(" = -ENOENT [absent]");
848 return ERR_PTR(-ENOENT); 848 return ERR_PTR(-ENOENT);
@@ -871,13 +871,13 @@ static struct dentry *cachefiles_check_active(struct cachefiles_cache *cache,
871 871
872object_in_use: 872object_in_use:
873 read_unlock(&cache->active_lock); 873 read_unlock(&cache->active_lock);
874 mutex_unlock(&dir->d_inode->i_mutex); 874 mutex_unlock(&d_inode(dir)->i_mutex);
875 dput(victim); 875 dput(victim);
876 //_leave(" = -EBUSY [in use]"); 876 //_leave(" = -EBUSY [in use]");
877 return ERR_PTR(-EBUSY); 877 return ERR_PTR(-EBUSY);
878 878
879lookup_error: 879lookup_error:
880 mutex_unlock(&dir->d_inode->i_mutex); 880 mutex_unlock(&d_inode(dir)->i_mutex);
881 ret = PTR_ERR(victim); 881 ret = PTR_ERR(victim);
882 if (ret == -ENOENT) { 882 if (ret == -ENOENT) {
883 /* file or dir now absent - probably retired by netfs */ 883 /* file or dir now absent - probably retired by netfs */
@@ -913,7 +913,7 @@ int cachefiles_cull(struct cachefiles_cache *cache, struct dentry *dir,
913 return PTR_ERR(victim); 913 return PTR_ERR(victim);
914 914
915 _debug("victim -> %p %s", 915 _debug("victim -> %p %s",
916 victim, victim->d_inode ? "positive" : "negative"); 916 victim, d_backing_inode(victim) ? "positive" : "negative");
917 917
918 /* okay... the victim is not being used so we can cull it 918 /* okay... the victim is not being used so we can cull it
919 * - start by marking it as stale 919 * - start by marking it as stale
@@ -936,7 +936,7 @@ int cachefiles_cull(struct cachefiles_cache *cache, struct dentry *dir,
936 return 0; 936 return 0;
937 937
938error_unlock: 938error_unlock:
939 mutex_unlock(&dir->d_inode->i_mutex); 939 mutex_unlock(&d_inode(dir)->i_mutex);
940error: 940error:
941 dput(victim); 941 dput(victim);
942 if (ret == -ENOENT) { 942 if (ret == -ENOENT) {
@@ -971,7 +971,7 @@ int cachefiles_check_in_use(struct cachefiles_cache *cache, struct dentry *dir,
971 if (IS_ERR(victim)) 971 if (IS_ERR(victim))
972 return PTR_ERR(victim); 972 return PTR_ERR(victim);
973 973
974 mutex_unlock(&dir->d_inode->i_mutex); 974 mutex_unlock(&d_inode(dir)->i_mutex);
975 dput(victim); 975 dput(victim);
976 //_leave(" = 0"); 976 //_leave(" = 0");
977 return 0; 977 return 0;
diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
index c6cd8d7a4eef..3cbb0e834694 100644
--- a/fs/cachefiles/rdwr.c
+++ b/fs/cachefiles/rdwr.c
@@ -74,12 +74,12 @@ static int cachefiles_read_waiter(wait_queue_t *wait, unsigned mode,
74static int cachefiles_read_reissue(struct cachefiles_object *object, 74static int cachefiles_read_reissue(struct cachefiles_object *object,
75 struct cachefiles_one_read *monitor) 75 struct cachefiles_one_read *monitor)
76{ 76{
77 struct address_space *bmapping = object->backer->d_inode->i_mapping; 77 struct address_space *bmapping = d_backing_inode(object->backer)->i_mapping;
78 struct page *backpage = monitor->back_page, *backpage2; 78 struct page *backpage = monitor->back_page, *backpage2;
79 int ret; 79 int ret;
80 80
81 _enter("{ino=%lx},{%lx,%lx}", 81 _enter("{ino=%lx},{%lx,%lx}",
82 object->backer->d_inode->i_ino, 82 d_backing_inode(object->backer)->i_ino,
83 backpage->index, backpage->flags); 83 backpage->index, backpage->flags);
84 84
85 /* skip if the page was truncated away completely */ 85 /* skip if the page was truncated away completely */
@@ -157,7 +157,7 @@ static void cachefiles_read_copier(struct fscache_operation *_op)
157 object = container_of(op->op.object, 157 object = container_of(op->op.object,
158 struct cachefiles_object, fscache); 158 struct cachefiles_object, fscache);
159 159
160 _enter("{ino=%lu}", object->backer->d_inode->i_ino); 160 _enter("{ino=%lu}", d_backing_inode(object->backer)->i_ino);
161 161
162 max = 8; 162 max = 8;
163 spin_lock_irq(&object->work_lock); 163 spin_lock_irq(&object->work_lock);
@@ -247,7 +247,7 @@ static int cachefiles_read_backing_file_one(struct cachefiles_object *object,
247 init_waitqueue_func_entry(&monitor->monitor, cachefiles_read_waiter); 247 init_waitqueue_func_entry(&monitor->monitor, cachefiles_read_waiter);
248 248
249 /* attempt to get hold of the backing page */ 249 /* attempt to get hold of the backing page */
250 bmapping = object->backer->d_inode->i_mapping; 250 bmapping = d_backing_inode(object->backer)->i_mapping;
251 newpage = NULL; 251 newpage = NULL;
252 252
253 for (;;) { 253 for (;;) {
@@ -408,7 +408,7 @@ int cachefiles_read_or_alloc_page(struct fscache_retrieval *op,
408 if (!object->backer) 408 if (!object->backer)
409 goto enobufs; 409 goto enobufs;
410 410
411 inode = object->backer->d_inode; 411 inode = d_backing_inode(object->backer);
412 ASSERT(S_ISREG(inode->i_mode)); 412 ASSERT(S_ISREG(inode->i_mode));
413 ASSERT(inode->i_mapping->a_ops->bmap); 413 ASSERT(inode->i_mapping->a_ops->bmap);
414 ASSERT(inode->i_mapping->a_ops->readpages); 414 ASSERT(inode->i_mapping->a_ops->readpages);
@@ -468,7 +468,7 @@ static int cachefiles_read_backing_file(struct cachefiles_object *object,
468 struct list_head *list) 468 struct list_head *list)
469{ 469{
470 struct cachefiles_one_read *monitor = NULL; 470 struct cachefiles_one_read *monitor = NULL;
471 struct address_space *bmapping = object->backer->d_inode->i_mapping; 471 struct address_space *bmapping = d_backing_inode(object->backer)->i_mapping;
472 struct page *newpage = NULL, *netpage, *_n, *backpage = NULL; 472 struct page *newpage = NULL, *netpage, *_n, *backpage = NULL;
473 int ret = 0; 473 int ret = 0;
474 474
@@ -705,7 +705,7 @@ int cachefiles_read_or_alloc_pages(struct fscache_retrieval *op,
705 if (cachefiles_has_space(cache, 0, *nr_pages) < 0) 705 if (cachefiles_has_space(cache, 0, *nr_pages) < 0)
706 space = 0; 706 space = 0;
707 707
708 inode = object->backer->d_inode; 708 inode = d_backing_inode(object->backer);
709 ASSERT(S_ISREG(inode->i_mode)); 709 ASSERT(S_ISREG(inode->i_mode));
710 ASSERT(inode->i_mapping->a_ops->bmap); 710 ASSERT(inode->i_mapping->a_ops->bmap);
711 ASSERT(inode->i_mapping->a_ops->readpages); 711 ASSERT(inode->i_mapping->a_ops->readpages);
diff --git a/fs/cachefiles/security.c b/fs/cachefiles/security.c
index 396c18ea2764..31bbc0528b11 100644
--- a/fs/cachefiles/security.c
+++ b/fs/cachefiles/security.c
@@ -55,14 +55,14 @@ static int cachefiles_check_cache_dir(struct cachefiles_cache *cache,
55{ 55{
56 int ret; 56 int ret;
57 57
58 ret = security_inode_mkdir(root->d_inode, root, 0); 58 ret = security_inode_mkdir(d_backing_inode(root), root, 0);
59 if (ret < 0) { 59 if (ret < 0) {
60 pr_err("Security denies permission to make dirs: error %d", 60 pr_err("Security denies permission to make dirs: error %d",
61 ret); 61 ret);
62 return ret; 62 return ret;
63 } 63 }
64 64
65 ret = security_inode_create(root->d_inode, root, 0); 65 ret = security_inode_create(d_backing_inode(root), root, 0);
66 if (ret < 0) 66 if (ret < 0)
67 pr_err("Security denies permission to create files: error %d", 67 pr_err("Security denies permission to create files: error %d",
68 ret); 68 ret);
@@ -95,7 +95,7 @@ int cachefiles_determine_cache_security(struct cachefiles_cache *cache,
95 95
96 /* use the cache root dir's security context as the basis with 96 /* use the cache root dir's security context as the basis with
97 * which create files */ 97 * which create files */
98 ret = set_create_files_as(new, root->d_inode); 98 ret = set_create_files_as(new, d_backing_inode(root));
99 if (ret < 0) { 99 if (ret < 0) {
100 abort_creds(new); 100 abort_creds(new);
101 cachefiles_begin_secure(cache, _saved_cred); 101 cachefiles_begin_secure(cache, _saved_cred);
diff --git a/fs/cachefiles/xattr.c b/fs/cachefiles/xattr.c
index a8a68745e11d..d31c1a72d8a5 100644
--- a/fs/cachefiles/xattr.c
+++ b/fs/cachefiles/xattr.c
@@ -33,7 +33,7 @@ int cachefiles_check_object_type(struct cachefiles_object *object)
33 int ret; 33 int ret;
34 34
35 ASSERT(dentry); 35 ASSERT(dentry);
36 ASSERT(dentry->d_inode); 36 ASSERT(d_backing_inode(dentry));
37 37
38 if (!object->fscache.cookie) 38 if (!object->fscache.cookie)
39 strcpy(type, "C3"); 39 strcpy(type, "C3");
@@ -52,7 +52,7 @@ int cachefiles_check_object_type(struct cachefiles_object *object)
52 52
53 if (ret != -EEXIST) { 53 if (ret != -EEXIST) {
54 pr_err("Can't set xattr on %pd [%lu] (err %d)\n", 54 pr_err("Can't set xattr on %pd [%lu] (err %d)\n",
55 dentry, dentry->d_inode->i_ino, 55 dentry, d_backing_inode(dentry)->i_ino,
56 -ret); 56 -ret);
57 goto error; 57 goto error;
58 } 58 }
@@ -64,7 +64,7 @@ int cachefiles_check_object_type(struct cachefiles_object *object)
64 goto bad_type_length; 64 goto bad_type_length;
65 65
66 pr_err("Can't read xattr on %pd [%lu] (err %d)\n", 66 pr_err("Can't read xattr on %pd [%lu] (err %d)\n",
67 dentry, dentry->d_inode->i_ino, 67 dentry, d_backing_inode(dentry)->i_ino,
68 -ret); 68 -ret);
69 goto error; 69 goto error;
70 } 70 }
@@ -84,14 +84,14 @@ error:
84 84
85bad_type_length: 85bad_type_length:
86 pr_err("Cache object %lu type xattr length incorrect\n", 86 pr_err("Cache object %lu type xattr length incorrect\n",
87 dentry->d_inode->i_ino); 87 d_backing_inode(dentry)->i_ino);
88 ret = -EIO; 88 ret = -EIO;
89 goto error; 89 goto error;
90 90
91bad_type: 91bad_type:
92 xtype[2] = 0; 92 xtype[2] = 0;
93 pr_err("Cache object %pd [%lu] type %s not %s\n", 93 pr_err("Cache object %pd [%lu] type %s not %s\n",
94 dentry, dentry->d_inode->i_ino, 94 dentry, d_backing_inode(dentry)->i_ino,
95 xtype, type); 95 xtype, type);
96 ret = -EIO; 96 ret = -EIO;
97 goto error; 97 goto error;
@@ -165,7 +165,7 @@ int cachefiles_check_auxdata(struct cachefiles_object *object)
165 int ret; 165 int ret;
166 166
167 ASSERT(dentry); 167 ASSERT(dentry);
168 ASSERT(dentry->d_inode); 168 ASSERT(d_backing_inode(dentry));
169 ASSERT(object->fscache.cookie->def->check_aux); 169 ASSERT(object->fscache.cookie->def->check_aux);
170 170
171 auxbuf = kmalloc(sizeof(struct cachefiles_xattr) + 512, GFP_KERNEL); 171 auxbuf = kmalloc(sizeof(struct cachefiles_xattr) + 512, GFP_KERNEL);
@@ -204,7 +204,7 @@ int cachefiles_check_object_xattr(struct cachefiles_object *object,
204 _enter("%p,#%d", object, auxdata->len); 204 _enter("%p,#%d", object, auxdata->len);
205 205
206 ASSERT(dentry); 206 ASSERT(dentry);
207 ASSERT(dentry->d_inode); 207 ASSERT(d_backing_inode(dentry));
208 208
209 auxbuf = kmalloc(sizeof(struct cachefiles_xattr) + 512, cachefiles_gfp); 209 auxbuf = kmalloc(sizeof(struct cachefiles_xattr) + 512, cachefiles_gfp);
210 if (!auxbuf) { 210 if (!auxbuf) {
@@ -225,7 +225,7 @@ int cachefiles_check_object_xattr(struct cachefiles_object *object,
225 225
226 cachefiles_io_error_obj(object, 226 cachefiles_io_error_obj(object,
227 "Can't read xattr on %lu (err %d)", 227 "Can't read xattr on %lu (err %d)",
228 dentry->d_inode->i_ino, -ret); 228 d_backing_inode(dentry)->i_ino, -ret);
229 goto error; 229 goto error;
230 } 230 }
231 231
@@ -276,7 +276,7 @@ int cachefiles_check_object_xattr(struct cachefiles_object *object,
276 cachefiles_io_error_obj(object, 276 cachefiles_io_error_obj(object,
277 "Can't update xattr on %lu" 277 "Can't update xattr on %lu"
278 " (error %d)", 278 " (error %d)",
279 dentry->d_inode->i_ino, -ret); 279 d_backing_inode(dentry)->i_ino, -ret);
280 goto error; 280 goto error;
281 } 281 }
282 } 282 }
@@ -291,7 +291,7 @@ error:
291 291
292bad_type_length: 292bad_type_length:
293 pr_err("Cache object %lu xattr length incorrect\n", 293 pr_err("Cache object %lu xattr length incorrect\n",
294 dentry->d_inode->i_ino); 294 d_backing_inode(dentry)->i_ino);
295 ret = -EIO; 295 ret = -EIO;
296 goto error; 296 goto error;
297 297
@@ -316,7 +316,7 @@ int cachefiles_remove_object_xattr(struct cachefiles_cache *cache,
316 cachefiles_io_error(cache, 316 cachefiles_io_error(cache,
317 "Can't remove xattr from %lu" 317 "Can't remove xattr from %lu"
318 " (error %d)", 318 " (error %d)",
319 dentry->d_inode->i_ino, -ret); 319 d_backing_inode(dentry)->i_ino, -ret);
320 } 320 }
321 321
322 _leave(" = %d", ret); 322 _leave(" = %d", ret);
diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c
index 11631c4c7d14..be5ea6af8366 100644
--- a/fs/ceph/caps.c
+++ b/fs/ceph/caps.c
@@ -3422,7 +3422,7 @@ int ceph_encode_inode_release(void **p, struct inode *inode,
3422int ceph_encode_dentry_release(void **p, struct dentry *dentry, 3422int ceph_encode_dentry_release(void **p, struct dentry *dentry,
3423 int mds, int drop, int unless) 3423 int mds, int drop, int unless)
3424{ 3424{
3425 struct inode *dir = dentry->d_parent->d_inode; 3425 struct inode *dir = d_inode(dentry->d_parent);
3426 struct ceph_mds_request_release *rel = *p; 3426 struct ceph_mds_request_release *rel = *p;
3427 struct ceph_dentry_info *di = ceph_dentry(dentry); 3427 struct ceph_dentry_info *di = ceph_dentry(dentry);
3428 int force = 0; 3428 int force = 0;
diff --git a/fs/ceph/debugfs.c b/fs/ceph/debugfs.c
index 1b2355109b9f..31f831471ed2 100644
--- a/fs/ceph/debugfs.c
+++ b/fs/ceph/debugfs.c
@@ -84,7 +84,7 @@ static int mdsc_show(struct seq_file *s, void *p)
84 path = NULL; 84 path = NULL;
85 spin_lock(&req->r_dentry->d_lock); 85 spin_lock(&req->r_dentry->d_lock);
86 seq_printf(s, " #%llx/%pd (%s)", 86 seq_printf(s, " #%llx/%pd (%s)",
87 ceph_ino(req->r_dentry->d_parent->d_inode), 87 ceph_ino(d_inode(req->r_dentry->d_parent)),
88 req->r_dentry, 88 req->r_dentry,
89 path ? path : ""); 89 path ? path : "");
90 spin_unlock(&req->r_dentry->d_lock); 90 spin_unlock(&req->r_dentry->d_lock);
diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
index e729b79812b4..4248307fea90 100644
--- a/fs/ceph/dir.c
+++ b/fs/ceph/dir.c
@@ -49,9 +49,9 @@ int ceph_init_dentry(struct dentry *dentry)
49 goto out_unlock; 49 goto out_unlock;
50 } 50 }
51 51
52 if (ceph_snap(dentry->d_parent->d_inode) == CEPH_NOSNAP) 52 if (ceph_snap(d_inode(dentry->d_parent)) == CEPH_NOSNAP)
53 d_set_d_op(dentry, &ceph_dentry_ops); 53 d_set_d_op(dentry, &ceph_dentry_ops);
54 else if (ceph_snap(dentry->d_parent->d_inode) == CEPH_SNAPDIR) 54 else if (ceph_snap(d_inode(dentry->d_parent)) == CEPH_SNAPDIR)
55 d_set_d_op(dentry, &ceph_snapdir_dentry_ops); 55 d_set_d_op(dentry, &ceph_snapdir_dentry_ops);
56 else 56 else
57 d_set_d_op(dentry, &ceph_snap_dentry_ops); 57 d_set_d_op(dentry, &ceph_snap_dentry_ops);
@@ -77,7 +77,7 @@ struct inode *ceph_get_dentry_parent_inode(struct dentry *dentry)
77 77
78 spin_lock(&dentry->d_lock); 78 spin_lock(&dentry->d_lock);
79 if (!IS_ROOT(dentry)) { 79 if (!IS_ROOT(dentry)) {
80 inode = dentry->d_parent->d_inode; 80 inode = d_inode(dentry->d_parent);
81 ihold(inode); 81 ihold(inode);
82 } 82 }
83 spin_unlock(&dentry->d_lock); 83 spin_unlock(&dentry->d_lock);
@@ -122,7 +122,7 @@ static int __dcache_readdir(struct file *file, struct dir_context *ctx,
122{ 122{
123 struct ceph_file_info *fi = file->private_data; 123 struct ceph_file_info *fi = file->private_data;
124 struct dentry *parent = file->f_path.dentry; 124 struct dentry *parent = file->f_path.dentry;
125 struct inode *dir = parent->d_inode; 125 struct inode *dir = d_inode(parent);
126 struct list_head *p; 126 struct list_head *p;
127 struct dentry *dentry, *last; 127 struct dentry *dentry, *last;
128 struct ceph_dentry_info *di; 128 struct ceph_dentry_info *di;
@@ -161,15 +161,15 @@ more:
161 } 161 }
162 spin_lock_nested(&dentry->d_lock, DENTRY_D_LOCK_NESTED); 162 spin_lock_nested(&dentry->d_lock, DENTRY_D_LOCK_NESTED);
163 if (di->lease_shared_gen == shared_gen && 163 if (di->lease_shared_gen == shared_gen &&
164 !d_unhashed(dentry) && dentry->d_inode && 164 !d_unhashed(dentry) && d_really_is_positive(dentry) &&
165 ceph_snap(dentry->d_inode) != CEPH_SNAPDIR && 165 ceph_snap(d_inode(dentry)) != CEPH_SNAPDIR &&
166 ceph_ino(dentry->d_inode) != CEPH_INO_CEPH && 166 ceph_ino(d_inode(dentry)) != CEPH_INO_CEPH &&
167 fpos_cmp(ctx->pos, di->offset) <= 0) 167 fpos_cmp(ctx->pos, di->offset) <= 0)
168 break; 168 break;
169 dout(" skipping %p %pd at %llu (%llu)%s%s\n", dentry, 169 dout(" skipping %p %pd at %llu (%llu)%s%s\n", dentry,
170 dentry, di->offset, 170 dentry, di->offset,
171 ctx->pos, d_unhashed(dentry) ? " unhashed" : "", 171 ctx->pos, d_unhashed(dentry) ? " unhashed" : "",
172 !dentry->d_inode ? " null" : ""); 172 !d_inode(dentry) ? " null" : "");
173 spin_unlock(&dentry->d_lock); 173 spin_unlock(&dentry->d_lock);
174 p = p->prev; 174 p = p->prev;
175 dentry = list_entry(p, struct dentry, d_child); 175 dentry = list_entry(p, struct dentry, d_child);
@@ -189,11 +189,11 @@ more:
189 } 189 }
190 190
191 dout(" %llu (%llu) dentry %p %pd %p\n", di->offset, ctx->pos, 191 dout(" %llu (%llu) dentry %p %pd %p\n", di->offset, ctx->pos,
192 dentry, dentry, dentry->d_inode); 192 dentry, dentry, d_inode(dentry));
193 if (!dir_emit(ctx, dentry->d_name.name, 193 if (!dir_emit(ctx, dentry->d_name.name,
194 dentry->d_name.len, 194 dentry->d_name.len,
195 ceph_translate_ino(dentry->d_sb, dentry->d_inode->i_ino), 195 ceph_translate_ino(dentry->d_sb, d_inode(dentry)->i_ino),
196 dentry->d_inode->i_mode >> 12)) { 196 d_inode(dentry)->i_mode >> 12)) {
197 if (last) { 197 if (last) {
198 /* remember our position */ 198 /* remember our position */
199 fi->dentry = last; 199 fi->dentry = last;
@@ -543,7 +543,7 @@ int ceph_handle_snapdir(struct ceph_mds_request *req,
543 struct dentry *dentry, int err) 543 struct dentry *dentry, int err)
544{ 544{
545 struct ceph_fs_client *fsc = ceph_sb_to_client(dentry->d_sb); 545 struct ceph_fs_client *fsc = ceph_sb_to_client(dentry->d_sb);
546 struct inode *parent = dentry->d_parent->d_inode; /* we hold i_mutex */ 546 struct inode *parent = d_inode(dentry->d_parent); /* we hold i_mutex */
547 547
548 /* .snap dir? */ 548 /* .snap dir? */
549 if (err == -ENOENT && 549 if (err == -ENOENT &&
@@ -579,8 +579,8 @@ struct dentry *ceph_finish_lookup(struct ceph_mds_request *req,
579 err = 0; 579 err = 0;
580 if (!req->r_reply_info.head->is_dentry) { 580 if (!req->r_reply_info.head->is_dentry) {
581 dout("ENOENT and no trace, dentry %p inode %p\n", 581 dout("ENOENT and no trace, dentry %p inode %p\n",
582 dentry, dentry->d_inode); 582 dentry, d_inode(dentry));
583 if (dentry->d_inode) { 583 if (d_really_is_positive(dentry)) {
584 d_drop(dentry); 584 d_drop(dentry);
585 err = -ENOENT; 585 err = -ENOENT;
586 } else { 586 } else {
@@ -627,7 +627,7 @@ static struct dentry *ceph_lookup(struct inode *dir, struct dentry *dentry,
627 return ERR_PTR(err); 627 return ERR_PTR(err);
628 628
629 /* can we conclude ENOENT locally? */ 629 /* can we conclude ENOENT locally? */
630 if (dentry->d_inode == NULL) { 630 if (d_really_is_negative(dentry)) {
631 struct ceph_inode_info *ci = ceph_inode(dir); 631 struct ceph_inode_info *ci = ceph_inode(dir);
632 struct ceph_dentry_info *di = ceph_dentry(dentry); 632 struct ceph_dentry_info *di = ceph_dentry(dentry);
633 633
@@ -734,7 +734,7 @@ static int ceph_mknod(struct inode *dir, struct dentry *dentry,
734 ceph_mdsc_put_request(req); 734 ceph_mdsc_put_request(req);
735out: 735out:
736 if (!err) 736 if (!err)
737 ceph_init_inode_acls(dentry->d_inode, &acls); 737 ceph_init_inode_acls(d_inode(dentry), &acls);
738 else 738 else
739 d_drop(dentry); 739 d_drop(dentry);
740 ceph_release_acls_info(&acls); 740 ceph_release_acls_info(&acls);
@@ -835,7 +835,7 @@ static int ceph_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
835 ceph_mdsc_put_request(req); 835 ceph_mdsc_put_request(req);
836out: 836out:
837 if (!err) 837 if (!err)
838 ceph_init_inode_acls(dentry->d_inode, &acls); 838 ceph_init_inode_acls(d_inode(dentry), &acls);
839 else 839 else
840 d_drop(dentry); 840 d_drop(dentry);
841 ceph_release_acls_info(&acls); 841 ceph_release_acls_info(&acls);
@@ -872,8 +872,8 @@ static int ceph_link(struct dentry *old_dentry, struct inode *dir,
872 if (err) { 872 if (err) {
873 d_drop(dentry); 873 d_drop(dentry);
874 } else if (!req->r_reply_info.head->is_dentry) { 874 } else if (!req->r_reply_info.head->is_dentry) {
875 ihold(old_dentry->d_inode); 875 ihold(d_inode(old_dentry));
876 d_instantiate(dentry, old_dentry->d_inode); 876 d_instantiate(dentry, d_inode(old_dentry));
877 } 877 }
878 ceph_mdsc_put_request(req); 878 ceph_mdsc_put_request(req);
879 return err; 879 return err;
@@ -906,7 +906,7 @@ static int ceph_unlink(struct inode *dir, struct dentry *dentry)
906{ 906{
907 struct ceph_fs_client *fsc = ceph_sb_to_client(dir->i_sb); 907 struct ceph_fs_client *fsc = ceph_sb_to_client(dir->i_sb);
908 struct ceph_mds_client *mdsc = fsc->mdsc; 908 struct ceph_mds_client *mdsc = fsc->mdsc;
909 struct inode *inode = dentry->d_inode; 909 struct inode *inode = d_inode(dentry);
910 struct ceph_mds_request *req; 910 struct ceph_mds_request *req;
911 int err = -EROFS; 911 int err = -EROFS;
912 int op; 912 int op;
@@ -975,8 +975,8 @@ static int ceph_rename(struct inode *old_dir, struct dentry *old_dentry,
975 req->r_dentry_unless = CEPH_CAP_FILE_EXCL; 975 req->r_dentry_unless = CEPH_CAP_FILE_EXCL;
976 /* release LINK_RDCACHE on source inode (mds will lock it) */ 976 /* release LINK_RDCACHE on source inode (mds will lock it) */
977 req->r_old_inode_drop = CEPH_CAP_LINK_SHARED; 977 req->r_old_inode_drop = CEPH_CAP_LINK_SHARED;
978 if (new_dentry->d_inode) 978 if (d_really_is_positive(new_dentry))
979 req->r_inode_drop = drop_caps_for_unlink(new_dentry->d_inode); 979 req->r_inode_drop = drop_caps_for_unlink(d_inode(new_dentry));
980 err = ceph_mdsc_do_request(mdsc, old_dir, req); 980 err = ceph_mdsc_do_request(mdsc, old_dir, req);
981 if (!err && !req->r_reply_info.head->is_dentry) { 981 if (!err && !req->r_reply_info.head->is_dentry) {
982 /* 982 /*
@@ -1042,7 +1042,7 @@ static int dentry_lease_is_valid(struct dentry *dentry)
1042 if (di->lease_renew_after && 1042 if (di->lease_renew_after &&
1043 time_after(jiffies, di->lease_renew_after)) { 1043 time_after(jiffies, di->lease_renew_after)) {
1044 /* we should renew */ 1044 /* we should renew */
1045 dir = dentry->d_parent->d_inode; 1045 dir = d_inode(dentry->d_parent);
1046 session = ceph_get_mds_session(s); 1046 session = ceph_get_mds_session(s);
1047 seq = di->lease_seq; 1047 seq = di->lease_seq;
1048 di->lease_renew_after = 0; 1048 di->lease_renew_after = 0;
@@ -1092,22 +1092,22 @@ static int ceph_d_revalidate(struct dentry *dentry, unsigned int flags)
1092 return -ECHILD; 1092 return -ECHILD;
1093 1093
1094 dout("d_revalidate %p '%pd' inode %p offset %lld\n", dentry, 1094 dout("d_revalidate %p '%pd' inode %p offset %lld\n", dentry,
1095 dentry, dentry->d_inode, ceph_dentry(dentry)->offset); 1095 dentry, d_inode(dentry), ceph_dentry(dentry)->offset);
1096 1096
1097 dir = ceph_get_dentry_parent_inode(dentry); 1097 dir = ceph_get_dentry_parent_inode(dentry);
1098 1098
1099 /* always trust cached snapped dentries, snapdir dentry */ 1099 /* always trust cached snapped dentries, snapdir dentry */
1100 if (ceph_snap(dir) != CEPH_NOSNAP) { 1100 if (ceph_snap(dir) != CEPH_NOSNAP) {
1101 dout("d_revalidate %p '%pd' inode %p is SNAPPED\n", dentry, 1101 dout("d_revalidate %p '%pd' inode %p is SNAPPED\n", dentry,
1102 dentry, dentry->d_inode); 1102 dentry, d_inode(dentry));
1103 valid = 1; 1103 valid = 1;
1104 } else if (dentry->d_inode && 1104 } else if (d_really_is_positive(dentry) &&
1105 ceph_snap(dentry->d_inode) == CEPH_SNAPDIR) { 1105 ceph_snap(d_inode(dentry)) == CEPH_SNAPDIR) {
1106 valid = 1; 1106 valid = 1;
1107 } else if (dentry_lease_is_valid(dentry) || 1107 } else if (dentry_lease_is_valid(dentry) ||
1108 dir_lease_is_valid(dir, dentry)) { 1108 dir_lease_is_valid(dir, dentry)) {
1109 if (dentry->d_inode) 1109 if (d_really_is_positive(dentry))
1110 valid = ceph_is_any_caps(dentry->d_inode); 1110 valid = ceph_is_any_caps(d_inode(dentry));
1111 else 1111 else
1112 valid = 1; 1112 valid = 1;
1113 } 1113 }
@@ -1169,7 +1169,7 @@ static void ceph_d_prune(struct dentry *dentry)
1169 * we hold d_lock, so d_parent is stable, and d_fsdata is never 1169 * we hold d_lock, so d_parent is stable, and d_fsdata is never
1170 * cleared until d_release 1170 * cleared until d_release
1171 */ 1171 */
1172 ceph_dir_clear_complete(dentry->d_parent->d_inode); 1172 ceph_dir_clear_complete(d_inode(dentry->d_parent));
1173} 1173}
1174 1174
1175/* 1175/*
diff --git a/fs/ceph/export.c b/fs/ceph/export.c
index 8d7d782f4382..fe02ae7f056a 100644
--- a/fs/ceph/export.c
+++ b/fs/ceph/export.c
@@ -136,8 +136,8 @@ static struct dentry *__get_parent(struct super_block *sb,
136 return ERR_CAST(req); 136 return ERR_CAST(req);
137 137
138 if (child) { 138 if (child) {
139 req->r_inode = child->d_inode; 139 req->r_inode = d_inode(child);
140 ihold(child->d_inode); 140 ihold(d_inode(child));
141 } else { 141 } else {
142 req->r_ino1 = (struct ceph_vino) { 142 req->r_ino1 = (struct ceph_vino) {
143 .ino = ino, 143 .ino = ino,
@@ -164,7 +164,7 @@ static struct dentry *__get_parent(struct super_block *sb,
164 return ERR_PTR(err); 164 return ERR_PTR(err);
165 } 165 }
166 dout("__get_parent ino %llx parent %p ino %llx.%llx\n", 166 dout("__get_parent ino %llx parent %p ino %llx.%llx\n",
167 child ? ceph_ino(child->d_inode) : ino, 167 child ? ceph_ino(d_inode(child)) : ino,
168 dentry, ceph_vinop(inode)); 168 dentry, ceph_vinop(inode));
169 return dentry; 169 return dentry;
170} 170}
@@ -172,11 +172,11 @@ static struct dentry *__get_parent(struct super_block *sb,
172static struct dentry *ceph_get_parent(struct dentry *child) 172static struct dentry *ceph_get_parent(struct dentry *child)
173{ 173{
174 /* don't re-export snaps */ 174 /* don't re-export snaps */
175 if (ceph_snap(child->d_inode) != CEPH_NOSNAP) 175 if (ceph_snap(d_inode(child)) != CEPH_NOSNAP)
176 return ERR_PTR(-EINVAL); 176 return ERR_PTR(-EINVAL);
177 177
178 dout("get_parent %p ino %llx.%llx\n", 178 dout("get_parent %p ino %llx.%llx\n",
179 child, ceph_vinop(child->d_inode)); 179 child, ceph_vinop(d_inode(child)));
180 return __get_parent(child->d_sb, child, 0); 180 return __get_parent(child->d_sb, child, 0);
181} 181}
182 182
@@ -209,32 +209,32 @@ static int ceph_get_name(struct dentry *parent, char *name,
209 struct ceph_mds_request *req; 209 struct ceph_mds_request *req;
210 int err; 210 int err;
211 211
212 mdsc = ceph_inode_to_client(child->d_inode)->mdsc; 212 mdsc = ceph_inode_to_client(d_inode(child))->mdsc;
213 req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_LOOKUPNAME, 213 req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_LOOKUPNAME,
214 USE_ANY_MDS); 214 USE_ANY_MDS);
215 if (IS_ERR(req)) 215 if (IS_ERR(req))
216 return PTR_ERR(req); 216 return PTR_ERR(req);
217 217
218 mutex_lock(&parent->d_inode->i_mutex); 218 mutex_lock(&d_inode(parent)->i_mutex);
219 219
220 req->r_inode = child->d_inode; 220 req->r_inode = d_inode(child);
221 ihold(child->d_inode); 221 ihold(d_inode(child));
222 req->r_ino2 = ceph_vino(parent->d_inode); 222 req->r_ino2 = ceph_vino(d_inode(parent));
223 req->r_locked_dir = parent->d_inode; 223 req->r_locked_dir = d_inode(parent);
224 req->r_num_caps = 2; 224 req->r_num_caps = 2;
225 err = ceph_mdsc_do_request(mdsc, NULL, req); 225 err = ceph_mdsc_do_request(mdsc, NULL, req);
226 226
227 mutex_unlock(&parent->d_inode->i_mutex); 227 mutex_unlock(&d_inode(parent)->i_mutex);
228 228
229 if (!err) { 229 if (!err) {
230 struct ceph_mds_reply_info_parsed *rinfo = &req->r_reply_info; 230 struct ceph_mds_reply_info_parsed *rinfo = &req->r_reply_info;
231 memcpy(name, rinfo->dname, rinfo->dname_len); 231 memcpy(name, rinfo->dname, rinfo->dname_len);
232 name[rinfo->dname_len] = 0; 232 name[rinfo->dname_len] = 0;
233 dout("get_name %p ino %llx.%llx name %s\n", 233 dout("get_name %p ino %llx.%llx name %s\n",
234 child, ceph_vinop(child->d_inode), name); 234 child, ceph_vinop(d_inode(child)), name);
235 } else { 235 } else {
236 dout("get_name %p ino %llx.%llx err %d\n", 236 dout("get_name %p ino %llx.%llx err %d\n",
237 child, ceph_vinop(child->d_inode), err); 237 child, ceph_vinop(d_inode(child)), err);
238 } 238 }
239 239
240 ceph_mdsc_put_request(req); 240 ceph_mdsc_put_request(req);
diff --git a/fs/ceph/file.c b/fs/ceph/file.c
index b9b8eb225f66..3b6b522b4b31 100644
--- a/fs/ceph/file.c
+++ b/fs/ceph/file.c
@@ -291,14 +291,14 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry,
291 } 291 }
292 if (err) 292 if (err)
293 goto out_req; 293 goto out_req;
294 if (dn || dentry->d_inode == NULL || d_is_symlink(dentry)) { 294 if (dn || d_really_is_negative(dentry) || d_is_symlink(dentry)) {
295 /* make vfs retry on splice, ENOENT, or symlink */ 295 /* make vfs retry on splice, ENOENT, or symlink */
296 dout("atomic_open finish_no_open on dn %p\n", dn); 296 dout("atomic_open finish_no_open on dn %p\n", dn);
297 err = finish_no_open(file, dn); 297 err = finish_no_open(file, dn);
298 } else { 298 } else {
299 dout("atomic_open finish_open on dn %p\n", dn); 299 dout("atomic_open finish_open on dn %p\n", dn);
300 if (req->r_op == CEPH_MDS_OP_CREATE && req->r_reply_info.has_create_ino) { 300 if (req->r_op == CEPH_MDS_OP_CREATE && req->r_reply_info.has_create_ino) {
301 ceph_init_inode_acls(dentry->d_inode, &acls); 301 ceph_init_inode_acls(d_inode(dentry), &acls);
302 *opened |= FILE_CREATED; 302 *opened |= FILE_CREATED;
303 } 303 }
304 err = finish_open(file, dentry, ceph_open, opened); 304 err = finish_open(file, dentry, ceph_open, opened);
diff --git a/fs/ceph/inode.c b/fs/ceph/inode.c
index 119c43c80638..e876e1944519 100644
--- a/fs/ceph/inode.c
+++ b/fs/ceph/inode.c
@@ -940,7 +940,7 @@ static void update_dentry_lease(struct dentry *dentry,
940 dentry, duration, ttl); 940 dentry, duration, ttl);
941 941
942 /* make lease_rdcache_gen match directory */ 942 /* make lease_rdcache_gen match directory */
943 dir = dentry->d_parent->d_inode; 943 dir = d_inode(dentry->d_parent);
944 di->lease_shared_gen = ceph_inode(dir)->i_shared_gen; 944 di->lease_shared_gen = ceph_inode(dir)->i_shared_gen;
945 945
946 if (duration == 0) 946 if (duration == 0)
@@ -980,7 +980,7 @@ static struct dentry *splice_dentry(struct dentry *dn, struct inode *in,
980{ 980{
981 struct dentry *realdn; 981 struct dentry *realdn;
982 982
983 BUG_ON(dn->d_inode); 983 BUG_ON(d_inode(dn));
984 984
985 /* dn must be unhashed */ 985 /* dn must be unhashed */
986 if (!d_unhashed(dn)) 986 if (!d_unhashed(dn))
@@ -998,13 +998,13 @@ static struct dentry *splice_dentry(struct dentry *dn, struct inode *in,
998 "inode %p ino %llx.%llx\n", 998 "inode %p ino %llx.%llx\n",
999 dn, d_count(dn), 999 dn, d_count(dn),
1000 realdn, d_count(realdn), 1000 realdn, d_count(realdn),
1001 realdn->d_inode, ceph_vinop(realdn->d_inode)); 1001 d_inode(realdn), ceph_vinop(d_inode(realdn)));
1002 dput(dn); 1002 dput(dn);
1003 dn = realdn; 1003 dn = realdn;
1004 } else { 1004 } else {
1005 BUG_ON(!ceph_dentry(dn)); 1005 BUG_ON(!ceph_dentry(dn));
1006 dout("dn %p attached to %p ino %llx.%llx\n", 1006 dout("dn %p attached to %p ino %llx.%llx\n",
1007 dn, dn->d_inode, ceph_vinop(dn->d_inode)); 1007 dn, d_inode(dn), ceph_vinop(d_inode(dn)));
1008 } 1008 }
1009 if ((!prehash || *prehash) && d_unhashed(dn)) 1009 if ((!prehash || *prehash) && d_unhashed(dn))
1010 d_rehash(dn); 1010 d_rehash(dn);
@@ -1125,11 +1125,11 @@ retry_lookup:
1125 dput(parent); 1125 dput(parent);
1126 goto done; 1126 goto done;
1127 } 1127 }
1128 } else if (dn->d_inode && 1128 } else if (d_really_is_positive(dn) &&
1129 (ceph_ino(dn->d_inode) != vino.ino || 1129 (ceph_ino(d_inode(dn)) != vino.ino ||
1130 ceph_snap(dn->d_inode) != vino.snap)) { 1130 ceph_snap(d_inode(dn)) != vino.snap)) {
1131 dout(" dn %p points to wrong inode %p\n", 1131 dout(" dn %p points to wrong inode %p\n",
1132 dn, dn->d_inode); 1132 dn, d_inode(dn));
1133 d_delete(dn); 1133 d_delete(dn);
1134 dput(dn); 1134 dput(dn);
1135 goto retry_lookup; 1135 goto retry_lookup;
@@ -1183,7 +1183,7 @@ retry_lookup:
1183 1183
1184 BUG_ON(!dn); 1184 BUG_ON(!dn);
1185 BUG_ON(!dir); 1185 BUG_ON(!dir);
1186 BUG_ON(dn->d_parent->d_inode != dir); 1186 BUG_ON(d_inode(dn->d_parent) != dir);
1187 BUG_ON(ceph_ino(dir) != 1187 BUG_ON(ceph_ino(dir) !=
1188 le64_to_cpu(rinfo->diri.in->ino)); 1188 le64_to_cpu(rinfo->diri.in->ino));
1189 BUG_ON(ceph_snap(dir) != 1189 BUG_ON(ceph_snap(dir) !=
@@ -1235,7 +1235,7 @@ retry_lookup:
1235 /* null dentry? */ 1235 /* null dentry? */
1236 if (!rinfo->head->is_target) { 1236 if (!rinfo->head->is_target) {
1237 dout("fill_trace null dentry\n"); 1237 dout("fill_trace null dentry\n");
1238 if (dn->d_inode) { 1238 if (d_really_is_positive(dn)) {
1239 ceph_dir_clear_ordered(dir); 1239 ceph_dir_clear_ordered(dir);
1240 dout("d_delete %p\n", dn); 1240 dout("d_delete %p\n", dn);
1241 d_delete(dn); 1241 d_delete(dn);
@@ -1252,7 +1252,7 @@ retry_lookup:
1252 } 1252 }
1253 1253
1254 /* attach proper inode */ 1254 /* attach proper inode */
1255 if (!dn->d_inode) { 1255 if (d_really_is_negative(dn)) {
1256 ceph_dir_clear_ordered(dir); 1256 ceph_dir_clear_ordered(dir);
1257 ihold(in); 1257 ihold(in);
1258 dn = splice_dentry(dn, in, &have_lease); 1258 dn = splice_dentry(dn, in, &have_lease);
@@ -1261,9 +1261,9 @@ retry_lookup:
1261 goto done; 1261 goto done;
1262 } 1262 }
1263 req->r_dentry = dn; /* may have spliced */ 1263 req->r_dentry = dn; /* may have spliced */
1264 } else if (dn->d_inode && dn->d_inode != in) { 1264 } else if (d_really_is_positive(dn) && d_inode(dn) != in) {
1265 dout(" %p links to %p %llx.%llx, not %llx.%llx\n", 1265 dout(" %p links to %p %llx.%llx, not %llx.%llx\n",
1266 dn, dn->d_inode, ceph_vinop(dn->d_inode), 1266 dn, d_inode(dn), ceph_vinop(d_inode(dn)),
1267 ceph_vinop(in)); 1267 ceph_vinop(in));
1268 have_lease = false; 1268 have_lease = false;
1269 } 1269 }
@@ -1363,7 +1363,7 @@ int ceph_readdir_prepopulate(struct ceph_mds_request *req,
1363 return readdir_prepopulate_inodes_only(req, session); 1363 return readdir_prepopulate_inodes_only(req, session);
1364 1364
1365 if (le32_to_cpu(rinfo->head->op) == CEPH_MDS_OP_LSSNAP) { 1365 if (le32_to_cpu(rinfo->head->op) == CEPH_MDS_OP_LSSNAP) {
1366 snapdir = ceph_get_snapdir(parent->d_inode); 1366 snapdir = ceph_get_snapdir(d_inode(parent));
1367 parent = d_find_alias(snapdir); 1367 parent = d_find_alias(snapdir);
1368 dout("readdir_prepopulate %d items under SNAPDIR dn %p\n", 1368 dout("readdir_prepopulate %d items under SNAPDIR dn %p\n",
1369 rinfo->dir_nr, parent); 1369 rinfo->dir_nr, parent);
@@ -1371,7 +1371,7 @@ int ceph_readdir_prepopulate(struct ceph_mds_request *req,
1371 dout("readdir_prepopulate %d items under dn %p\n", 1371 dout("readdir_prepopulate %d items under dn %p\n",
1372 rinfo->dir_nr, parent); 1372 rinfo->dir_nr, parent);
1373 if (rinfo->dir_dir) 1373 if (rinfo->dir_dir)
1374 ceph_fill_dirfrag(parent->d_inode, rinfo->dir_dir); 1374 ceph_fill_dirfrag(d_inode(parent), rinfo->dir_dir);
1375 } 1375 }
1376 1376
1377 /* FIXME: release caps/leases if error occurs */ 1377 /* FIXME: release caps/leases if error occurs */
@@ -1405,11 +1405,11 @@ retry_lookup:
1405 err = ret; 1405 err = ret;
1406 goto out; 1406 goto out;
1407 } 1407 }
1408 } else if (dn->d_inode && 1408 } else if (d_really_is_positive(dn) &&
1409 (ceph_ino(dn->d_inode) != vino.ino || 1409 (ceph_ino(d_inode(dn)) != vino.ino ||
1410 ceph_snap(dn->d_inode) != vino.snap)) { 1410 ceph_snap(d_inode(dn)) != vino.snap)) {
1411 dout(" dn %p points to wrong inode %p\n", 1411 dout(" dn %p points to wrong inode %p\n",
1412 dn, dn->d_inode); 1412 dn, d_inode(dn));
1413 d_delete(dn); 1413 d_delete(dn);
1414 dput(dn); 1414 dput(dn);
1415 goto retry_lookup; 1415 goto retry_lookup;
@@ -1423,8 +1423,8 @@ retry_lookup:
1423 } 1423 }
1424 1424
1425 /* inode */ 1425 /* inode */
1426 if (dn->d_inode) { 1426 if (d_really_is_positive(dn)) {
1427 in = dn->d_inode; 1427 in = d_inode(dn);
1428 } else { 1428 } else {
1429 in = ceph_get_inode(parent->d_sb, vino); 1429 in = ceph_get_inode(parent->d_sb, vino);
1430 if (IS_ERR(in)) { 1430 if (IS_ERR(in)) {
@@ -1440,13 +1440,13 @@ retry_lookup:
1440 req->r_request_started, -1, 1440 req->r_request_started, -1,
1441 &req->r_caps_reservation) < 0) { 1441 &req->r_caps_reservation) < 0) {
1442 pr_err("fill_inode badness on %p\n", in); 1442 pr_err("fill_inode badness on %p\n", in);
1443 if (!dn->d_inode) 1443 if (d_really_is_negative(dn))
1444 iput(in); 1444 iput(in);
1445 d_drop(dn); 1445 d_drop(dn);
1446 goto next_item; 1446 goto next_item;
1447 } 1447 }
1448 1448
1449 if (!dn->d_inode) { 1449 if (d_really_is_negative(dn)) {
1450 struct dentry *realdn = splice_dentry(dn, in, NULL); 1450 struct dentry *realdn = splice_dentry(dn, in, NULL);
1451 if (IS_ERR(realdn)) { 1451 if (IS_ERR(realdn)) {
1452 err = PTR_ERR(realdn); 1452 err = PTR_ERR(realdn);
@@ -1693,7 +1693,7 @@ retry:
1693 */ 1693 */
1694static void *ceph_sym_follow_link(struct dentry *dentry, struct nameidata *nd) 1694static void *ceph_sym_follow_link(struct dentry *dentry, struct nameidata *nd)
1695{ 1695{
1696 struct ceph_inode_info *ci = ceph_inode(dentry->d_inode); 1696 struct ceph_inode_info *ci = ceph_inode(d_inode(dentry));
1697 nd_set_link(nd, ci->i_symlink); 1697 nd_set_link(nd, ci->i_symlink);
1698 return NULL; 1698 return NULL;
1699} 1699}
@@ -1714,7 +1714,7 @@ static const struct inode_operations ceph_symlink_iops = {
1714 */ 1714 */
1715int ceph_setattr(struct dentry *dentry, struct iattr *attr) 1715int ceph_setattr(struct dentry *dentry, struct iattr *attr)
1716{ 1716{
1717 struct inode *inode = dentry->d_inode; 1717 struct inode *inode = d_inode(dentry);
1718 struct ceph_inode_info *ci = ceph_inode(inode); 1718 struct ceph_inode_info *ci = ceph_inode(inode);
1719 const unsigned int ia_valid = attr->ia_valid; 1719 const unsigned int ia_valid = attr->ia_valid;
1720 struct ceph_mds_request *req; 1720 struct ceph_mds_request *req;
@@ -1990,7 +1990,7 @@ int ceph_permission(struct inode *inode, int mask)
1990int ceph_getattr(struct vfsmount *mnt, struct dentry *dentry, 1990int ceph_getattr(struct vfsmount *mnt, struct dentry *dentry,
1991 struct kstat *stat) 1991 struct kstat *stat)
1992{ 1992{
1993 struct inode *inode = dentry->d_inode; 1993 struct inode *inode = d_inode(dentry);
1994 struct ceph_inode_info *ci = ceph_inode(inode); 1994 struct ceph_inode_info *ci = ceph_inode(inode);
1995 int err; 1995 int err;
1996 1996
diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c
index 0a2eb32ffe43..84f37f34f9aa 100644
--- a/fs/ceph/mds_client.c
+++ b/fs/ceph/mds_client.c
@@ -679,7 +679,7 @@ static struct dentry *get_nonsnap_parent(struct dentry *dentry)
679 * except to resplice to another snapdir, and either the old or new 679 * except to resplice to another snapdir, and either the old or new
680 * result is a valid result. 680 * result is a valid result.
681 */ 681 */
682 while (!IS_ROOT(dentry) && ceph_snap(dentry->d_inode) != CEPH_NOSNAP) 682 while (!IS_ROOT(dentry) && ceph_snap(d_inode(dentry)) != CEPH_NOSNAP)
683 dentry = dentry->d_parent; 683 dentry = dentry->d_parent;
684 return dentry; 684 return dentry;
685} 685}
@@ -716,20 +716,20 @@ static int __choose_mds(struct ceph_mds_client *mdsc,
716 } else if (req->r_dentry) { 716 } else if (req->r_dentry) {
717 /* ignore race with rename; old or new d_parent is okay */ 717 /* ignore race with rename; old or new d_parent is okay */
718 struct dentry *parent = req->r_dentry->d_parent; 718 struct dentry *parent = req->r_dentry->d_parent;
719 struct inode *dir = parent->d_inode; 719 struct inode *dir = d_inode(parent);
720 720
721 if (dir->i_sb != mdsc->fsc->sb) { 721 if (dir->i_sb != mdsc->fsc->sb) {
722 /* not this fs! */ 722 /* not this fs! */
723 inode = req->r_dentry->d_inode; 723 inode = d_inode(req->r_dentry);
724 } else if (ceph_snap(dir) != CEPH_NOSNAP) { 724 } else if (ceph_snap(dir) != CEPH_NOSNAP) {
725 /* direct snapped/virtual snapdir requests 725 /* direct snapped/virtual snapdir requests
726 * based on parent dir inode */ 726 * based on parent dir inode */
727 struct dentry *dn = get_nonsnap_parent(parent); 727 struct dentry *dn = get_nonsnap_parent(parent);
728 inode = dn->d_inode; 728 inode = d_inode(dn);
729 dout("__choose_mds using nonsnap parent %p\n", inode); 729 dout("__choose_mds using nonsnap parent %p\n", inode);
730 } else { 730 } else {
731 /* dentry target */ 731 /* dentry target */
732 inode = req->r_dentry->d_inode; 732 inode = d_inode(req->r_dentry);
733 if (!inode || mode == USE_AUTH_MDS) { 733 if (!inode || mode == USE_AUTH_MDS) {
734 /* dir + name */ 734 /* dir + name */
735 inode = dir; 735 inode = dir;
@@ -1732,7 +1732,7 @@ retry:
1732 seq = read_seqbegin(&rename_lock); 1732 seq = read_seqbegin(&rename_lock);
1733 rcu_read_lock(); 1733 rcu_read_lock();
1734 for (temp = dentry; !IS_ROOT(temp);) { 1734 for (temp = dentry; !IS_ROOT(temp);) {
1735 struct inode *inode = temp->d_inode; 1735 struct inode *inode = d_inode(temp);
1736 if (inode && ceph_snap(inode) == CEPH_SNAPDIR) 1736 if (inode && ceph_snap(inode) == CEPH_SNAPDIR)
1737 len++; /* slash only */ 1737 len++; /* slash only */
1738 else if (stop_on_nosnap && inode && 1738 else if (stop_on_nosnap && inode &&
@@ -1756,7 +1756,7 @@ retry:
1756 struct inode *inode; 1756 struct inode *inode;
1757 1757
1758 spin_lock(&temp->d_lock); 1758 spin_lock(&temp->d_lock);
1759 inode = temp->d_inode; 1759 inode = d_inode(temp);
1760 if (inode && ceph_snap(inode) == CEPH_SNAPDIR) { 1760 if (inode && ceph_snap(inode) == CEPH_SNAPDIR) {
1761 dout("build_path path+%d: %p SNAPDIR\n", 1761 dout("build_path path+%d: %p SNAPDIR\n",
1762 pos, temp); 1762 pos, temp);
@@ -1790,7 +1790,7 @@ retry:
1790 goto retry; 1790 goto retry;
1791 } 1791 }
1792 1792
1793 *base = ceph_ino(temp->d_inode); 1793 *base = ceph_ino(d_inode(temp));
1794 *plen = len; 1794 *plen = len;
1795 dout("build_path on %p %d built %llx '%.*s'\n", 1795 dout("build_path on %p %d built %llx '%.*s'\n",
1796 dentry, d_count(dentry), *base, len, path); 1796 dentry, d_count(dentry), *base, len, path);
@@ -1803,8 +1803,8 @@ static int build_dentry_path(struct dentry *dentry,
1803{ 1803{
1804 char *path; 1804 char *path;
1805 1805
1806 if (ceph_snap(dentry->d_parent->d_inode) == CEPH_NOSNAP) { 1806 if (ceph_snap(d_inode(dentry->d_parent)) == CEPH_NOSNAP) {
1807 *pino = ceph_ino(dentry->d_parent->d_inode); 1807 *pino = ceph_ino(d_inode(dentry->d_parent));
1808 *ppath = dentry->d_name.name; 1808 *ppath = dentry->d_name.name;
1809 *ppathlen = dentry->d_name.len; 1809 *ppathlen = dentry->d_name.len;
1810 return 0; 1810 return 0;
@@ -1945,7 +1945,7 @@ static struct ceph_msg *create_request_message(struct ceph_mds_client *mdsc,
1945 releases = 0; 1945 releases = 0;
1946 if (req->r_inode_drop) 1946 if (req->r_inode_drop)
1947 releases += ceph_encode_inode_release(&p, 1947 releases += ceph_encode_inode_release(&p,
1948 req->r_inode ? req->r_inode : req->r_dentry->d_inode, 1948 req->r_inode ? req->r_inode : d_inode(req->r_dentry),
1949 mds, req->r_inode_drop, req->r_inode_unless, 0); 1949 mds, req->r_inode_drop, req->r_inode_unless, 0);
1950 if (req->r_dentry_drop) 1950 if (req->r_dentry_drop)
1951 releases += ceph_encode_dentry_release(&p, req->r_dentry, 1951 releases += ceph_encode_dentry_release(&p, req->r_dentry,
@@ -1955,7 +1955,7 @@ static struct ceph_msg *create_request_message(struct ceph_mds_client *mdsc,
1955 mds, req->r_old_dentry_drop, req->r_old_dentry_unless); 1955 mds, req->r_old_dentry_drop, req->r_old_dentry_unless);
1956 if (req->r_old_inode_drop) 1956 if (req->r_old_inode_drop)
1957 releases += ceph_encode_inode_release(&p, 1957 releases += ceph_encode_inode_release(&p,
1958 req->r_old_dentry->d_inode, 1958 d_inode(req->r_old_dentry),
1959 mds, req->r_old_inode_drop, req->r_old_inode_unless, 0); 1959 mds, req->r_old_inode_drop, req->r_old_inode_unless, 0);
1960 1960
1961 if (drop_cap_releases) { 1961 if (drop_cap_releases) {
diff --git a/fs/ceph/super.c b/fs/ceph/super.c
index e463ebd69a9c..4e9905374078 100644
--- a/fs/ceph/super.c
+++ b/fs/ceph/super.c
@@ -44,7 +44,7 @@ static void ceph_put_super(struct super_block *s)
44 44
45static int ceph_statfs(struct dentry *dentry, struct kstatfs *buf) 45static int ceph_statfs(struct dentry *dentry, struct kstatfs *buf)
46{ 46{
47 struct ceph_fs_client *fsc = ceph_inode_to_client(dentry->d_inode); 47 struct ceph_fs_client *fsc = ceph_inode_to_client(d_inode(dentry));
48 struct ceph_monmap *monmap = fsc->client->monc.monmap; 48 struct ceph_monmap *monmap = fsc->client->monc.monmap;
49 struct ceph_statfs st; 49 struct ceph_statfs st;
50 u64 fsid; 50 u64 fsid;
@@ -972,7 +972,7 @@ static struct dentry *ceph_mount(struct file_system_type *fs_type,
972 if (IS_ERR(res)) 972 if (IS_ERR(res))
973 goto out_splat; 973 goto out_splat;
974 dout("root %p inode %p ino %llx.%llx\n", res, 974 dout("root %p inode %p ino %llx.%llx\n", res,
975 res->d_inode, ceph_vinop(res->d_inode)); 975 d_inode(res), ceph_vinop(d_inode(res)));
976 return res; 976 return res;
977 977
978out_splat: 978out_splat:
diff --git a/fs/ceph/xattr.c b/fs/ceph/xattr.c
index 5c4c9c256931..cd7ffad4041d 100644
--- a/fs/ceph/xattr.c
+++ b/fs/ceph/xattr.c
@@ -776,12 +776,12 @@ ssize_t ceph_getxattr(struct dentry *dentry, const char *name, void *value,
776 if (!strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN)) 776 if (!strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN))
777 return generic_getxattr(dentry, name, value, size); 777 return generic_getxattr(dentry, name, value, size);
778 778
779 return __ceph_getxattr(dentry->d_inode, name, value, size); 779 return __ceph_getxattr(d_inode(dentry), name, value, size);
780} 780}
781 781
782ssize_t ceph_listxattr(struct dentry *dentry, char *names, size_t size) 782ssize_t ceph_listxattr(struct dentry *dentry, char *names, size_t size)
783{ 783{
784 struct inode *inode = dentry->d_inode; 784 struct inode *inode = d_inode(dentry);
785 struct ceph_inode_info *ci = ceph_inode(inode); 785 struct ceph_inode_info *ci = ceph_inode(inode);
786 struct ceph_vxattr *vxattrs = ceph_inode_vxattrs(inode); 786 struct ceph_vxattr *vxattrs = ceph_inode_vxattrs(inode);
787 u32 vir_namelen = 0; 787 u32 vir_namelen = 0;
@@ -847,7 +847,7 @@ static int ceph_sync_setxattr(struct dentry *dentry, const char *name,
847 const char *value, size_t size, int flags) 847 const char *value, size_t size, int flags)
848{ 848{
849 struct ceph_fs_client *fsc = ceph_sb_to_client(dentry->d_sb); 849 struct ceph_fs_client *fsc = ceph_sb_to_client(dentry->d_sb);
850 struct inode *inode = dentry->d_inode; 850 struct inode *inode = d_inode(dentry);
851 struct ceph_inode_info *ci = ceph_inode(inode); 851 struct ceph_inode_info *ci = ceph_inode(inode);
852 struct ceph_mds_request *req; 852 struct ceph_mds_request *req;
853 struct ceph_mds_client *mdsc = fsc->mdsc; 853 struct ceph_mds_client *mdsc = fsc->mdsc;
@@ -908,7 +908,7 @@ out:
908int __ceph_setxattr(struct dentry *dentry, const char *name, 908int __ceph_setxattr(struct dentry *dentry, const char *name,
909 const void *value, size_t size, int flags) 909 const void *value, size_t size, int flags)
910{ 910{
911 struct inode *inode = dentry->d_inode; 911 struct inode *inode = d_inode(dentry);
912 struct ceph_vxattr *vxattr; 912 struct ceph_vxattr *vxattr;
913 struct ceph_inode_info *ci = ceph_inode(inode); 913 struct ceph_inode_info *ci = ceph_inode(inode);
914 int issued; 914 int issued;
@@ -1002,7 +1002,7 @@ out:
1002int ceph_setxattr(struct dentry *dentry, const char *name, 1002int ceph_setxattr(struct dentry *dentry, const char *name,
1003 const void *value, size_t size, int flags) 1003 const void *value, size_t size, int flags)
1004{ 1004{
1005 if (ceph_snap(dentry->d_inode) != CEPH_NOSNAP) 1005 if (ceph_snap(d_inode(dentry)) != CEPH_NOSNAP)
1006 return -EROFS; 1006 return -EROFS;
1007 1007
1008 if (!strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN)) 1008 if (!strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN))
@@ -1018,7 +1018,7 @@ static int ceph_send_removexattr(struct dentry *dentry, const char *name)
1018{ 1018{
1019 struct ceph_fs_client *fsc = ceph_sb_to_client(dentry->d_sb); 1019 struct ceph_fs_client *fsc = ceph_sb_to_client(dentry->d_sb);
1020 struct ceph_mds_client *mdsc = fsc->mdsc; 1020 struct ceph_mds_client *mdsc = fsc->mdsc;
1021 struct inode *inode = dentry->d_inode; 1021 struct inode *inode = d_inode(dentry);
1022 struct ceph_mds_request *req; 1022 struct ceph_mds_request *req;
1023 int err; 1023 int err;
1024 1024
@@ -1041,7 +1041,7 @@ static int ceph_send_removexattr(struct dentry *dentry, const char *name)
1041 1041
1042int __ceph_removexattr(struct dentry *dentry, const char *name) 1042int __ceph_removexattr(struct dentry *dentry, const char *name)
1043{ 1043{
1044 struct inode *inode = dentry->d_inode; 1044 struct inode *inode = d_inode(dentry);
1045 struct ceph_vxattr *vxattr; 1045 struct ceph_vxattr *vxattr;
1046 struct ceph_inode_info *ci = ceph_inode(inode); 1046 struct ceph_inode_info *ci = ceph_inode(inode);
1047 int issued; 1047 int issued;
@@ -1107,7 +1107,7 @@ out:
1107 1107
1108int ceph_removexattr(struct dentry *dentry, const char *name) 1108int ceph_removexattr(struct dentry *dentry, const char *name)
1109{ 1109{
1110 if (ceph_snap(dentry->d_inode) != CEPH_NOSNAP) 1110 if (ceph_snap(d_inode(dentry)) != CEPH_NOSNAP)
1111 return -EROFS; 1111 return -EROFS;
1112 1112
1113 if (!strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN)) 1113 if (!strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN))
diff --git a/fs/cifs/cifs_dfs_ref.c b/fs/cifs/cifs_dfs_ref.c
index b8602f199815..430e0348c99e 100644
--- a/fs/cifs/cifs_dfs_ref.c
+++ b/fs/cifs/cifs_dfs_ref.c
@@ -301,7 +301,7 @@ static struct vfsmount *cifs_dfs_do_automount(struct dentry *mntpt)
301 if (full_path == NULL) 301 if (full_path == NULL)
302 goto cdda_exit; 302 goto cdda_exit;
303 303
304 cifs_sb = CIFS_SB(mntpt->d_inode->i_sb); 304 cifs_sb = CIFS_SB(d_inode(mntpt)->i_sb);
305 tlink = cifs_sb_tlink(cifs_sb); 305 tlink = cifs_sb_tlink(cifs_sb);
306 if (IS_ERR(tlink)) { 306 if (IS_ERR(tlink)) {
307 mnt = ERR_CAST(tlink); 307 mnt = ERR_CAST(tlink);
diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
index eaab4b2a0595..f5089bde3635 100644
--- a/fs/cifs/cifsfs.c
+++ b/fs/cifs/cifsfs.c
@@ -607,7 +607,7 @@ cifs_get_root(struct smb_vol *vol, struct super_block *sb)
607 p = s = full_path; 607 p = s = full_path;
608 608
609 do { 609 do {
610 struct inode *dir = dentry->d_inode; 610 struct inode *dir = d_inode(dentry);
611 struct dentry *child; 611 struct dentry *child;
612 612
613 if (!dir) { 613 if (!dir) {
diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c
index fa13d5e79f64..84650a51c7c4 100644
--- a/fs/cifs/cifssmb.c
+++ b/fs/cifs/cifssmb.c
@@ -1898,7 +1898,7 @@ static void
1898cifs_writev_requeue(struct cifs_writedata *wdata) 1898cifs_writev_requeue(struct cifs_writedata *wdata)
1899{ 1899{
1900 int i, rc = 0; 1900 int i, rc = 0;
1901 struct inode *inode = wdata->cfile->dentry->d_inode; 1901 struct inode *inode = d_inode(wdata->cfile->dentry);
1902 struct TCP_Server_Info *server; 1902 struct TCP_Server_Info *server;
1903 unsigned int rest_len; 1903 unsigned int rest_len;
1904 1904
@@ -1981,7 +1981,7 @@ cifs_writev_complete(struct work_struct *work)
1981{ 1981{
1982 struct cifs_writedata *wdata = container_of(work, 1982 struct cifs_writedata *wdata = container_of(work,
1983 struct cifs_writedata, work); 1983 struct cifs_writedata, work);
1984 struct inode *inode = wdata->cfile->dentry->d_inode; 1984 struct inode *inode = d_inode(wdata->cfile->dentry);
1985 int i = 0; 1985 int i = 0;
1986 1986
1987 if (wdata->result == 0) { 1987 if (wdata->result == 0) {
diff --git a/fs/cifs/dir.c b/fs/cifs/dir.c
index b72bc29cba23..338d56936f6a 100644
--- a/fs/cifs/dir.c
+++ b/fs/cifs/dir.c
@@ -745,13 +745,13 @@ cifs_lookup(struct inode *parent_dir_inode, struct dentry *direntry,
745 goto lookup_out; 745 goto lookup_out;
746 } 746 }
747 747
748 if (direntry->d_inode != NULL) { 748 if (d_really_is_positive(direntry)) {
749 cifs_dbg(FYI, "non-NULL inode in lookup\n"); 749 cifs_dbg(FYI, "non-NULL inode in lookup\n");
750 } else { 750 } else {
751 cifs_dbg(FYI, "NULL inode in lookup\n"); 751 cifs_dbg(FYI, "NULL inode in lookup\n");
752 } 752 }
753 cifs_dbg(FYI, "Full path: %s inode = 0x%p\n", 753 cifs_dbg(FYI, "Full path: %s inode = 0x%p\n",
754 full_path, direntry->d_inode); 754 full_path, d_inode(direntry));
755 755
756 if (pTcon->unix_ext) { 756 if (pTcon->unix_ext) {
757 rc = cifs_get_inode_info_unix(&newInode, full_path, 757 rc = cifs_get_inode_info_unix(&newInode, full_path,
@@ -792,7 +792,7 @@ cifs_d_revalidate(struct dentry *direntry, unsigned int flags)
792 if (flags & LOOKUP_RCU) 792 if (flags & LOOKUP_RCU)
793 return -ECHILD; 793 return -ECHILD;
794 794
795 if (direntry->d_inode) { 795 if (d_really_is_positive(direntry)) {
796 if (cifs_revalidate_dentry(direntry)) 796 if (cifs_revalidate_dentry(direntry))
797 return 0; 797 return 0;
798 else { 798 else {
@@ -803,7 +803,7 @@ cifs_d_revalidate(struct dentry *direntry, unsigned int flags)
803 * attributes will have been updated by 803 * attributes will have been updated by
804 * cifs_revalidate_dentry(). 804 * cifs_revalidate_dentry().
805 */ 805 */
806 if (IS_AUTOMOUNT(direntry->d_inode) && 806 if (IS_AUTOMOUNT(d_inode(direntry)) &&
807 !(direntry->d_flags & DCACHE_NEED_AUTOMOUNT)) { 807 !(direntry->d_flags & DCACHE_NEED_AUTOMOUNT)) {
808 spin_lock(&direntry->d_lock); 808 spin_lock(&direntry->d_lock);
809 direntry->d_flags |= DCACHE_NEED_AUTOMOUNT; 809 direntry->d_flags |= DCACHE_NEED_AUTOMOUNT;
diff --git a/fs/cifs/file.c b/fs/cifs/file.c
index ca2bc5406306..cafbf10521d5 100644
--- a/fs/cifs/file.c
+++ b/fs/cifs/file.c
@@ -273,7 +273,7 @@ cifs_new_fileinfo(struct cifs_fid *fid, struct file *file,
273 struct tcon_link *tlink, __u32 oplock) 273 struct tcon_link *tlink, __u32 oplock)
274{ 274{
275 struct dentry *dentry = file->f_path.dentry; 275 struct dentry *dentry = file->f_path.dentry;
276 struct inode *inode = dentry->d_inode; 276 struct inode *inode = d_inode(dentry);
277 struct cifsInodeInfo *cinode = CIFS_I(inode); 277 struct cifsInodeInfo *cinode = CIFS_I(inode);
278 struct cifsFileInfo *cfile; 278 struct cifsFileInfo *cfile;
279 struct cifs_fid_locks *fdlocks; 279 struct cifs_fid_locks *fdlocks;
@@ -357,7 +357,7 @@ cifsFileInfo_get(struct cifsFileInfo *cifs_file)
357 */ 357 */
358void cifsFileInfo_put(struct cifsFileInfo *cifs_file) 358void cifsFileInfo_put(struct cifsFileInfo *cifs_file)
359{ 359{
360 struct inode *inode = cifs_file->dentry->d_inode; 360 struct inode *inode = d_inode(cifs_file->dentry);
361 struct cifs_tcon *tcon = tlink_tcon(cifs_file->tlink); 361 struct cifs_tcon *tcon = tlink_tcon(cifs_file->tlink);
362 struct TCP_Server_Info *server = tcon->ses->server; 362 struct TCP_Server_Info *server = tcon->ses->server;
363 struct cifsInodeInfo *cifsi = CIFS_I(inode); 363 struct cifsInodeInfo *cifsi = CIFS_I(inode);
@@ -386,7 +386,7 @@ void cifsFileInfo_put(struct cifsFileInfo *cifs_file)
386 386
387 if (list_empty(&cifsi->openFileList)) { 387 if (list_empty(&cifsi->openFileList)) {
388 cifs_dbg(FYI, "closing last open instance for inode %p\n", 388 cifs_dbg(FYI, "closing last open instance for inode %p\n",
389 cifs_file->dentry->d_inode); 389 d_inode(cifs_file->dentry));
390 /* 390 /*
391 * In strict cache mode we need invalidate mapping on the last 391 * In strict cache mode we need invalidate mapping on the last
392 * close because it may cause a error when we open this file 392 * close because it may cause a error when we open this file
@@ -572,7 +572,7 @@ static int
572cifs_relock_file(struct cifsFileInfo *cfile) 572cifs_relock_file(struct cifsFileInfo *cfile)
573{ 573{
574 struct cifs_sb_info *cifs_sb = CIFS_SB(cfile->dentry->d_sb); 574 struct cifs_sb_info *cifs_sb = CIFS_SB(cfile->dentry->d_sb);
575 struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode); 575 struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry));
576 struct cifs_tcon *tcon = tlink_tcon(cfile->tlink); 576 struct cifs_tcon *tcon = tlink_tcon(cfile->tlink);
577 int rc = 0; 577 int rc = 0;
578 578
@@ -620,7 +620,7 @@ cifs_reopen_file(struct cifsFileInfo *cfile, bool can_flush)
620 return rc; 620 return rc;
621 } 621 }
622 622
623 inode = cfile->dentry->d_inode; 623 inode = d_inode(cfile->dentry);
624 cifs_sb = CIFS_SB(inode->i_sb); 624 cifs_sb = CIFS_SB(inode->i_sb);
625 tcon = tlink_tcon(cfile->tlink); 625 tcon = tlink_tcon(cfile->tlink);
626 server = tcon->ses->server; 626 server = tcon->ses->server;
@@ -874,7 +874,7 @@ cifs_find_lock_conflict(struct cifsFileInfo *cfile, __u64 offset, __u64 length,
874{ 874{
875 bool rc = false; 875 bool rc = false;
876 struct cifs_fid_locks *cur; 876 struct cifs_fid_locks *cur;
877 struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode); 877 struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry));
878 878
879 list_for_each_entry(cur, &cinode->llist, llist) { 879 list_for_each_entry(cur, &cinode->llist, llist) {
880 rc = cifs_find_fid_lock_conflict(cur, offset, length, type, 880 rc = cifs_find_fid_lock_conflict(cur, offset, length, type,
@@ -899,7 +899,7 @@ cifs_lock_test(struct cifsFileInfo *cfile, __u64 offset, __u64 length,
899{ 899{
900 int rc = 0; 900 int rc = 0;
901 struct cifsLockInfo *conf_lock; 901 struct cifsLockInfo *conf_lock;
902 struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode); 902 struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry));
903 struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server; 903 struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server;
904 bool exist; 904 bool exist;
905 905
@@ -927,7 +927,7 @@ cifs_lock_test(struct cifsFileInfo *cfile, __u64 offset, __u64 length,
927static void 927static void
928cifs_lock_add(struct cifsFileInfo *cfile, struct cifsLockInfo *lock) 928cifs_lock_add(struct cifsFileInfo *cfile, struct cifsLockInfo *lock)
929{ 929{
930 struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode); 930 struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry));
931 down_write(&cinode->lock_sem); 931 down_write(&cinode->lock_sem);
932 list_add_tail(&lock->llist, &cfile->llist->locks); 932 list_add_tail(&lock->llist, &cfile->llist->locks);
933 up_write(&cinode->lock_sem); 933 up_write(&cinode->lock_sem);
@@ -944,7 +944,7 @@ cifs_lock_add_if(struct cifsFileInfo *cfile, struct cifsLockInfo *lock,
944 bool wait) 944 bool wait)
945{ 945{
946 struct cifsLockInfo *conf_lock; 946 struct cifsLockInfo *conf_lock;
947 struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode); 947 struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry));
948 bool exist; 948 bool exist;
949 int rc = 0; 949 int rc = 0;
950 950
@@ -1125,7 +1125,7 @@ struct lock_to_push {
1125static int 1125static int
1126cifs_push_posix_locks(struct cifsFileInfo *cfile) 1126cifs_push_posix_locks(struct cifsFileInfo *cfile)
1127{ 1127{
1128 struct inode *inode = cfile->dentry->d_inode; 1128 struct inode *inode = d_inode(cfile->dentry);
1129 struct cifs_tcon *tcon = tlink_tcon(cfile->tlink); 1129 struct cifs_tcon *tcon = tlink_tcon(cfile->tlink);
1130 struct file_lock *flock; 1130 struct file_lock *flock;
1131 struct file_lock_context *flctx = inode->i_flctx; 1131 struct file_lock_context *flctx = inode->i_flctx;
@@ -1214,7 +1214,7 @@ static int
1214cifs_push_locks(struct cifsFileInfo *cfile) 1214cifs_push_locks(struct cifsFileInfo *cfile)
1215{ 1215{
1216 struct cifs_sb_info *cifs_sb = CIFS_SB(cfile->dentry->d_sb); 1216 struct cifs_sb_info *cifs_sb = CIFS_SB(cfile->dentry->d_sb);
1217 struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode); 1217 struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry));
1218 struct cifs_tcon *tcon = tlink_tcon(cfile->tlink); 1218 struct cifs_tcon *tcon = tlink_tcon(cfile->tlink);
1219 int rc = 0; 1219 int rc = 0;
1220 1220
@@ -1382,7 +1382,7 @@ cifs_unlock_range(struct cifsFileInfo *cfile, struct file_lock *flock,
1382 unsigned int max_num, num, max_buf; 1382 unsigned int max_num, num, max_buf;
1383 LOCKING_ANDX_RANGE *buf, *cur; 1383 LOCKING_ANDX_RANGE *buf, *cur;
1384 struct cifs_tcon *tcon = tlink_tcon(cfile->tlink); 1384 struct cifs_tcon *tcon = tlink_tcon(cfile->tlink);
1385 struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode); 1385 struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry));
1386 struct cifsLockInfo *li, *tmp; 1386 struct cifsLockInfo *li, *tmp;
1387 __u64 length = 1 + flock->fl_end - flock->fl_start; 1387 __u64 length = 1 + flock->fl_end - flock->fl_start;
1388 struct list_head tmp_llist; 1388 struct list_head tmp_llist;
@@ -1488,7 +1488,7 @@ cifs_setlk(struct file *file, struct file_lock *flock, __u32 type,
1488 struct cifsFileInfo *cfile = (struct cifsFileInfo *)file->private_data; 1488 struct cifsFileInfo *cfile = (struct cifsFileInfo *)file->private_data;
1489 struct cifs_tcon *tcon = tlink_tcon(cfile->tlink); 1489 struct cifs_tcon *tcon = tlink_tcon(cfile->tlink);
1490 struct TCP_Server_Info *server = tcon->ses->server; 1490 struct TCP_Server_Info *server = tcon->ses->server;
1491 struct inode *inode = cfile->dentry->d_inode; 1491 struct inode *inode = d_inode(cfile->dentry);
1492 1492
1493 if (posix_lck) { 1493 if (posix_lck) {
1494 int posix_lock_type; 1494 int posix_lock_type;
@@ -1643,7 +1643,7 @@ cifs_write(struct cifsFileInfo *open_file, __u32 pid, const char *write_data,
1643 struct TCP_Server_Info *server; 1643 struct TCP_Server_Info *server;
1644 unsigned int xid; 1644 unsigned int xid;
1645 struct dentry *dentry = open_file->dentry; 1645 struct dentry *dentry = open_file->dentry;
1646 struct cifsInodeInfo *cifsi = CIFS_I(dentry->d_inode); 1646 struct cifsInodeInfo *cifsi = CIFS_I(d_inode(dentry));
1647 struct cifs_io_parms io_parms; 1647 struct cifs_io_parms io_parms;
1648 1648
1649 cifs_sb = CIFS_SB(dentry->d_sb); 1649 cifs_sb = CIFS_SB(dentry->d_sb);
@@ -1676,7 +1676,7 @@ cifs_write(struct cifsFileInfo *open_file, __u32 pid, const char *write_data,
1676 break; 1676 break;
1677 } 1677 }
1678 1678
1679 len = min(server->ops->wp_retry_size(dentry->d_inode), 1679 len = min(server->ops->wp_retry_size(d_inode(dentry)),
1680 (unsigned int)write_size - total_written); 1680 (unsigned int)write_size - total_written);
1681 /* iov[0] is reserved for smb header */ 1681 /* iov[0] is reserved for smb header */
1682 iov[1].iov_base = (char *)write_data + total_written; 1682 iov[1].iov_base = (char *)write_data + total_written;
@@ -1696,9 +1696,9 @@ cifs_write(struct cifsFileInfo *open_file, __u32 pid, const char *write_data,
1696 return rc; 1696 return rc;
1697 } 1697 }
1698 } else { 1698 } else {
1699 spin_lock(&dentry->d_inode->i_lock); 1699 spin_lock(&d_inode(dentry)->i_lock);
1700 cifs_update_eof(cifsi, *offset, bytes_written); 1700 cifs_update_eof(cifsi, *offset, bytes_written);
1701 spin_unlock(&dentry->d_inode->i_lock); 1701 spin_unlock(&d_inode(dentry)->i_lock);
1702 *offset += bytes_written; 1702 *offset += bytes_written;
1703 } 1703 }
1704 } 1704 }
@@ -1706,12 +1706,12 @@ cifs_write(struct cifsFileInfo *open_file, __u32 pid, const char *write_data,
1706 cifs_stats_bytes_written(tcon, total_written); 1706 cifs_stats_bytes_written(tcon, total_written);
1707 1707
1708 if (total_written > 0) { 1708 if (total_written > 0) {
1709 spin_lock(&dentry->d_inode->i_lock); 1709 spin_lock(&d_inode(dentry)->i_lock);
1710 if (*offset > dentry->d_inode->i_size) 1710 if (*offset > d_inode(dentry)->i_size)
1711 i_size_write(dentry->d_inode, *offset); 1711 i_size_write(d_inode(dentry), *offset);
1712 spin_unlock(&dentry->d_inode->i_lock); 1712 spin_unlock(&d_inode(dentry)->i_lock);
1713 } 1713 }
1714 mark_inode_dirty_sync(dentry->d_inode); 1714 mark_inode_dirty_sync(d_inode(dentry));
1715 free_xid(xid); 1715 free_xid(xid);
1716 return total_written; 1716 return total_written;
1717} 1717}
@@ -2406,7 +2406,7 @@ cifs_uncached_writev_complete(struct work_struct *work)
2406{ 2406{
2407 struct cifs_writedata *wdata = container_of(work, 2407 struct cifs_writedata *wdata = container_of(work,
2408 struct cifs_writedata, work); 2408 struct cifs_writedata, work);
2409 struct inode *inode = wdata->cfile->dentry->d_inode; 2409 struct inode *inode = d_inode(wdata->cfile->dentry);
2410 struct cifsInodeInfo *cifsi = CIFS_I(inode); 2410 struct cifsInodeInfo *cifsi = CIFS_I(inode);
2411 2411
2412 spin_lock(&inode->i_lock); 2412 spin_lock(&inode->i_lock);
@@ -3794,7 +3794,7 @@ void cifs_oplock_break(struct work_struct *work)
3794{ 3794{
3795 struct cifsFileInfo *cfile = container_of(work, struct cifsFileInfo, 3795 struct cifsFileInfo *cfile = container_of(work, struct cifsFileInfo,
3796 oplock_break); 3796 oplock_break);
3797 struct inode *inode = cfile->dentry->d_inode; 3797 struct inode *inode = d_inode(cfile->dentry);
3798 struct cifsInodeInfo *cinode = CIFS_I(inode); 3798 struct cifsInodeInfo *cinode = CIFS_I(inode);
3799 struct cifs_tcon *tcon = tlink_tcon(cfile->tlink); 3799 struct cifs_tcon *tcon = tlink_tcon(cfile->tlink);
3800 struct TCP_Server_Info *server = tcon->ses->server; 3800 struct TCP_Server_Info *server = tcon->ses->server;
diff --git a/fs/cifs/inode.c b/fs/cifs/inode.c
index 3e126d7bb2ea..55b58112d122 100644
--- a/fs/cifs/inode.c
+++ b/fs/cifs/inode.c
@@ -1067,7 +1067,7 @@ cifs_rename_pending_delete(const char *full_path, struct dentry *dentry,
1067 int rc; 1067 int rc;
1068 struct cifs_fid fid; 1068 struct cifs_fid fid;
1069 struct cifs_open_parms oparms; 1069 struct cifs_open_parms oparms;
1070 struct inode *inode = dentry->d_inode; 1070 struct inode *inode = d_inode(dentry);
1071 struct cifsInodeInfo *cifsInode = CIFS_I(inode); 1071 struct cifsInodeInfo *cifsInode = CIFS_I(inode);
1072 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); 1072 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
1073 struct tcon_link *tlink; 1073 struct tcon_link *tlink;
@@ -1196,7 +1196,7 @@ cifs_drop_nlink(struct inode *inode)
1196} 1196}
1197 1197
1198/* 1198/*
1199 * If dentry->d_inode is null (usually meaning the cached dentry 1199 * If d_inode(dentry) is null (usually meaning the cached dentry
1200 * is a negative dentry) then we would attempt a standard SMB delete, but 1200 * is a negative dentry) then we would attempt a standard SMB delete, but
1201 * if that fails we can not attempt the fall back mechanisms on EACCESS 1201 * if that fails we can not attempt the fall back mechanisms on EACCESS
1202 * but will return the EACCESS to the caller. Note that the VFS does not call 1202 * but will return the EACCESS to the caller. Note that the VFS does not call
@@ -1207,7 +1207,7 @@ int cifs_unlink(struct inode *dir, struct dentry *dentry)
1207 int rc = 0; 1207 int rc = 0;
1208 unsigned int xid; 1208 unsigned int xid;
1209 char *full_path = NULL; 1209 char *full_path = NULL;
1210 struct inode *inode = dentry->d_inode; 1210 struct inode *inode = d_inode(dentry);
1211 struct cifsInodeInfo *cifs_inode; 1211 struct cifsInodeInfo *cifs_inode;
1212 struct super_block *sb = dir->i_sb; 1212 struct super_block *sb = dir->i_sb;
1213 struct cifs_sb_info *cifs_sb = CIFS_SB(sb); 1213 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
@@ -1551,13 +1551,13 @@ int cifs_rmdir(struct inode *inode, struct dentry *direntry)
1551 cifs_put_tlink(tlink); 1551 cifs_put_tlink(tlink);
1552 1552
1553 if (!rc) { 1553 if (!rc) {
1554 spin_lock(&direntry->d_inode->i_lock); 1554 spin_lock(&d_inode(direntry)->i_lock);
1555 i_size_write(direntry->d_inode, 0); 1555 i_size_write(d_inode(direntry), 0);
1556 clear_nlink(direntry->d_inode); 1556 clear_nlink(d_inode(direntry));
1557 spin_unlock(&direntry->d_inode->i_lock); 1557 spin_unlock(&d_inode(direntry)->i_lock);
1558 } 1558 }
1559 1559
1560 cifsInode = CIFS_I(direntry->d_inode); 1560 cifsInode = CIFS_I(d_inode(direntry));
1561 /* force revalidate to go get info when needed */ 1561 /* force revalidate to go get info when needed */
1562 cifsInode->time = 0; 1562 cifsInode->time = 0;
1563 1563
@@ -1568,7 +1568,7 @@ int cifs_rmdir(struct inode *inode, struct dentry *direntry)
1568 */ 1568 */
1569 cifsInode->time = 0; 1569 cifsInode->time = 0;
1570 1570
1571 direntry->d_inode->i_ctime = inode->i_ctime = inode->i_mtime = 1571 d_inode(direntry)->i_ctime = inode->i_ctime = inode->i_mtime =
1572 current_fs_time(inode->i_sb); 1572 current_fs_time(inode->i_sb);
1573 1573
1574rmdir_exit: 1574rmdir_exit:
@@ -1727,7 +1727,7 @@ cifs_rename2(struct inode *source_dir, struct dentry *source_dentry,
1727 1727
1728unlink_target: 1728unlink_target:
1729 /* Try unlinking the target dentry if it's not negative */ 1729 /* Try unlinking the target dentry if it's not negative */
1730 if (target_dentry->d_inode && (rc == -EACCES || rc == -EEXIST)) { 1730 if (d_really_is_positive(target_dentry) && (rc == -EACCES || rc == -EEXIST)) {
1731 if (d_is_dir(target_dentry)) 1731 if (d_is_dir(target_dentry))
1732 tmprc = cifs_rmdir(target_dir, target_dentry); 1732 tmprc = cifs_rmdir(target_dir, target_dentry);
1733 else 1733 else
@@ -1867,7 +1867,7 @@ int cifs_revalidate_dentry_attr(struct dentry *dentry)
1867{ 1867{
1868 unsigned int xid; 1868 unsigned int xid;
1869 int rc = 0; 1869 int rc = 0;
1870 struct inode *inode = dentry->d_inode; 1870 struct inode *inode = d_inode(dentry);
1871 struct super_block *sb = dentry->d_sb; 1871 struct super_block *sb = dentry->d_sb;
1872 char *full_path = NULL; 1872 char *full_path = NULL;
1873 1873
@@ -1919,7 +1919,7 @@ int cifs_revalidate_file(struct file *filp)
1919int cifs_revalidate_dentry(struct dentry *dentry) 1919int cifs_revalidate_dentry(struct dentry *dentry)
1920{ 1920{
1921 int rc; 1921 int rc;
1922 struct inode *inode = dentry->d_inode; 1922 struct inode *inode = d_inode(dentry);
1923 1923
1924 rc = cifs_revalidate_dentry_attr(dentry); 1924 rc = cifs_revalidate_dentry_attr(dentry);
1925 if (rc) 1925 if (rc)
@@ -1933,7 +1933,7 @@ int cifs_getattr(struct vfsmount *mnt, struct dentry *dentry,
1933{ 1933{
1934 struct cifs_sb_info *cifs_sb = CIFS_SB(dentry->d_sb); 1934 struct cifs_sb_info *cifs_sb = CIFS_SB(dentry->d_sb);
1935 struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb); 1935 struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
1936 struct inode *inode = dentry->d_inode; 1936 struct inode *inode = d_inode(dentry);
1937 int rc; 1937 int rc;
1938 1938
1939 /* 1939 /*
@@ -2110,7 +2110,7 @@ cifs_setattr_unix(struct dentry *direntry, struct iattr *attrs)
2110 int rc; 2110 int rc;
2111 unsigned int xid; 2111 unsigned int xid;
2112 char *full_path = NULL; 2112 char *full_path = NULL;
2113 struct inode *inode = direntry->d_inode; 2113 struct inode *inode = d_inode(direntry);
2114 struct cifsInodeInfo *cifsInode = CIFS_I(inode); 2114 struct cifsInodeInfo *cifsInode = CIFS_I(inode);
2115 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); 2115 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
2116 struct tcon_link *tlink; 2116 struct tcon_link *tlink;
@@ -2251,7 +2251,7 @@ cifs_setattr_nounix(struct dentry *direntry, struct iattr *attrs)
2251 unsigned int xid; 2251 unsigned int xid;
2252 kuid_t uid = INVALID_UID; 2252 kuid_t uid = INVALID_UID;
2253 kgid_t gid = INVALID_GID; 2253 kgid_t gid = INVALID_GID;
2254 struct inode *inode = direntry->d_inode; 2254 struct inode *inode = d_inode(direntry);
2255 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); 2255 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
2256 struct cifsInodeInfo *cifsInode = CIFS_I(inode); 2256 struct cifsInodeInfo *cifsInode = CIFS_I(inode);
2257 char *full_path = NULL; 2257 char *full_path = NULL;
@@ -2409,7 +2409,7 @@ cifs_setattr_exit:
2409int 2409int
2410cifs_setattr(struct dentry *direntry, struct iattr *attrs) 2410cifs_setattr(struct dentry *direntry, struct iattr *attrs)
2411{ 2411{
2412 struct inode *inode = direntry->d_inode; 2412 struct inode *inode = d_inode(direntry);
2413 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); 2413 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
2414 struct cifs_tcon *pTcon = cifs_sb_master_tcon(cifs_sb); 2414 struct cifs_tcon *pTcon = cifs_sb_master_tcon(cifs_sb);
2415 2415
diff --git a/fs/cifs/link.c b/fs/cifs/link.c
index 2ec6037f61c7..252e672d5604 100644
--- a/fs/cifs/link.c
+++ b/fs/cifs/link.c
@@ -586,12 +586,12 @@ cifs_hardlink(struct dentry *old_file, struct inode *inode,
586 * if source file is cached (oplocked) revalidate will not go to server 586 * if source file is cached (oplocked) revalidate will not go to server
587 * until the file is closed or oplock broken so update nlinks locally 587 * until the file is closed or oplock broken so update nlinks locally
588 */ 588 */
589 if (old_file->d_inode) { 589 if (d_really_is_positive(old_file)) {
590 cifsInode = CIFS_I(old_file->d_inode); 590 cifsInode = CIFS_I(d_inode(old_file));
591 if (rc == 0) { 591 if (rc == 0) {
592 spin_lock(&old_file->d_inode->i_lock); 592 spin_lock(&d_inode(old_file)->i_lock);
593 inc_nlink(old_file->d_inode); 593 inc_nlink(d_inode(old_file));
594 spin_unlock(&old_file->d_inode->i_lock); 594 spin_unlock(&d_inode(old_file)->i_lock);
595 595
596 /* 596 /*
597 * parent dir timestamps will update from srv within a 597 * parent dir timestamps will update from srv within a
@@ -629,7 +629,7 @@ cifs_hl_exit:
629void * 629void *
630cifs_follow_link(struct dentry *direntry, struct nameidata *nd) 630cifs_follow_link(struct dentry *direntry, struct nameidata *nd)
631{ 631{
632 struct inode *inode = direntry->d_inode; 632 struct inode *inode = d_inode(direntry);
633 int rc = -ENOMEM; 633 int rc = -ENOMEM;
634 unsigned int xid; 634 unsigned int xid;
635 char *full_path = NULL; 635 char *full_path = NULL;
diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
index 337946355b29..8442b8b8e0be 100644
--- a/fs/cifs/misc.c
+++ b/fs/cifs/misc.c
@@ -473,7 +473,7 @@ is_valid_oplock_break(char *buffer, struct TCP_Server_Info *srv)
473 continue; 473 continue;
474 474
475 cifs_dbg(FYI, "file id match, oplock break\n"); 475 cifs_dbg(FYI, "file id match, oplock break\n");
476 pCifsInode = CIFS_I(netfile->dentry->d_inode); 476 pCifsInode = CIFS_I(d_inode(netfile->dentry));
477 477
478 set_bit(CIFS_INODE_PENDING_OPLOCK_BREAK, 478 set_bit(CIFS_INODE_PENDING_OPLOCK_BREAK,
479 &pCifsInode->flags); 479 &pCifsInode->flags);
diff --git a/fs/cifs/readdir.c b/fs/cifs/readdir.c
index c295338e0a98..b4a47237486b 100644
--- a/fs/cifs/readdir.c
+++ b/fs/cifs/readdir.c
@@ -78,7 +78,7 @@ cifs_prime_dcache(struct dentry *parent, struct qstr *name,
78{ 78{
79 struct dentry *dentry, *alias; 79 struct dentry *dentry, *alias;
80 struct inode *inode; 80 struct inode *inode;
81 struct super_block *sb = parent->d_inode->i_sb; 81 struct super_block *sb = d_inode(parent)->i_sb;
82 struct cifs_sb_info *cifs_sb = CIFS_SB(sb); 82 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
83 83
84 cifs_dbg(FYI, "%s: for %s\n", __func__, name->name); 84 cifs_dbg(FYI, "%s: for %s\n", __func__, name->name);
@@ -88,7 +88,7 @@ cifs_prime_dcache(struct dentry *parent, struct qstr *name,
88 return; 88 return;
89 89
90 if (dentry) { 90 if (dentry) {
91 inode = dentry->d_inode; 91 inode = d_inode(dentry);
92 if (inode) { 92 if (inode) {
93 /* 93 /*
94 * If we're generating inode numbers, then we don't 94 * If we're generating inode numbers, then we don't
diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
index d2979036a4c7..7bfdd6066276 100644
--- a/fs/cifs/smb1ops.c
+++ b/fs/cifs/smb1ops.c
@@ -722,7 +722,7 @@ cifs_open_file(const unsigned int xid, struct cifs_open_parms *oparms,
722static void 722static void
723cifs_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock) 723cifs_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock)
724{ 724{
725 struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode); 725 struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry));
726 cfile->fid.netfid = fid->netfid; 726 cfile->fid.netfid = fid->netfid;
727 cifs_set_oplock_level(cinode, oplock); 727 cifs_set_oplock_level(cinode, oplock);
728 cinode->can_cache_brlcks = CIFS_CACHE_WRITE(cinode); 728 cinode->can_cache_brlcks = CIFS_CACHE_WRITE(cinode);
diff --git a/fs/cifs/smb2file.c b/fs/cifs/smb2file.c
index 7198eac5dddd..2ab297dae5a7 100644
--- a/fs/cifs/smb2file.c
+++ b/fs/cifs/smb2file.c
@@ -95,7 +95,7 @@ smb2_unlock_range(struct cifsFileInfo *cfile, struct file_lock *flock,
95 unsigned int max_num, num = 0, max_buf; 95 unsigned int max_num, num = 0, max_buf;
96 struct smb2_lock_element *buf, *cur; 96 struct smb2_lock_element *buf, *cur;
97 struct cifs_tcon *tcon = tlink_tcon(cfile->tlink); 97 struct cifs_tcon *tcon = tlink_tcon(cfile->tlink);
98 struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode); 98 struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry));
99 struct cifsLockInfo *li, *tmp; 99 struct cifsLockInfo *li, *tmp;
100 __u64 length = 1 + flock->fl_end - flock->fl_start; 100 __u64 length = 1 + flock->fl_end - flock->fl_start;
101 struct list_head tmp_llist; 101 struct list_head tmp_llist;
@@ -231,7 +231,7 @@ smb2_push_mandatory_locks(struct cifsFileInfo *cfile)
231 unsigned int xid; 231 unsigned int xid;
232 unsigned int max_num, max_buf; 232 unsigned int max_num, max_buf;
233 struct smb2_lock_element *buf; 233 struct smb2_lock_element *buf;
234 struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode); 234 struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry));
235 struct cifs_fid_locks *fdlocks; 235 struct cifs_fid_locks *fdlocks;
236 236
237 xid = get_xid(); 237 xid = get_xid();
diff --git a/fs/cifs/smb2misc.c b/fs/cifs/smb2misc.c
index 22dfdf17d065..1c5907019045 100644
--- a/fs/cifs/smb2misc.c
+++ b/fs/cifs/smb2misc.c
@@ -453,7 +453,7 @@ smb2_tcon_has_lease(struct cifs_tcon *tcon, struct smb2_lease_break *rsp,
453 453
454 list_for_each(tmp, &tcon->openFileList) { 454 list_for_each(tmp, &tcon->openFileList) {
455 cfile = list_entry(tmp, struct cifsFileInfo, tlist); 455 cfile = list_entry(tmp, struct cifsFileInfo, tlist);
456 cinode = CIFS_I(cfile->dentry->d_inode); 456 cinode = CIFS_I(d_inode(cfile->dentry));
457 457
458 if (memcmp(cinode->lease_key, rsp->LeaseKey, 458 if (memcmp(cinode->lease_key, rsp->LeaseKey,
459 SMB2_LEASE_KEY_SIZE)) 459 SMB2_LEASE_KEY_SIZE))
@@ -590,7 +590,7 @@ smb2_is_valid_oplock_break(char *buffer, struct TCP_Server_Info *server)
590 continue; 590 continue;
591 591
592 cifs_dbg(FYI, "file id match, oplock break\n"); 592 cifs_dbg(FYI, "file id match, oplock break\n");
593 cinode = CIFS_I(cfile->dentry->d_inode); 593 cinode = CIFS_I(d_inode(cfile->dentry));
594 594
595 if (!CIFS_CACHE_WRITE(cinode) && 595 if (!CIFS_CACHE_WRITE(cinode) &&
596 rsp->OplockLevel == SMB2_OPLOCK_LEVEL_NONE) 596 rsp->OplockLevel == SMB2_OPLOCK_LEVEL_NONE)
diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
index eab05e1aa587..54daee5ad4c1 100644
--- a/fs/cifs/smb2ops.c
+++ b/fs/cifs/smb2ops.c
@@ -524,7 +524,7 @@ smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
524static void 524static void
525smb2_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock) 525smb2_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock)
526{ 526{
527 struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode); 527 struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry));
528 struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server; 528 struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server;
529 529
530 cfile->fid.persistent_fid = fid->persistent_fid; 530 cfile->fid.persistent_fid = fid->persistent_fid;
@@ -793,7 +793,7 @@ smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon,
793 * If extending file more than one page make sparse. Many Linux fs 793 * If extending file more than one page make sparse. Many Linux fs
794 * make files sparse by default when extending via ftruncate 794 * make files sparse by default when extending via ftruncate
795 */ 795 */
796 inode = cfile->dentry->d_inode; 796 inode = d_inode(cfile->dentry);
797 797
798 if (!set_alloc && (size > inode->i_size + 8192)) { 798 if (!set_alloc && (size > inode->i_size + 8192)) {
799 __u8 set_sparse = 1; 799 __u8 set_sparse = 1;
@@ -1032,7 +1032,7 @@ static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,
1032 1032
1033 xid = get_xid(); 1033 xid = get_xid();
1034 1034
1035 inode = cfile->dentry->d_inode; 1035 inode = d_inode(cfile->dentry);
1036 cifsi = CIFS_I(inode); 1036 cifsi = CIFS_I(inode);
1037 1037
1038 /* if file not oplocked can't be sure whether asking to extend size */ 1038 /* if file not oplocked can't be sure whether asking to extend size */
@@ -1083,7 +1083,7 @@ static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon,
1083 1083
1084 xid = get_xid(); 1084 xid = get_xid();
1085 1085
1086 inode = cfile->dentry->d_inode; 1086 inode = d_inode(cfile->dentry);
1087 cifsi = CIFS_I(inode); 1087 cifsi = CIFS_I(inode);
1088 1088
1089 /* Need to make file sparse, if not already, before freeing range. */ 1089 /* Need to make file sparse, if not already, before freeing range. */
@@ -1115,7 +1115,7 @@ static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,
1115 1115
1116 xid = get_xid(); 1116 xid = get_xid();
1117 1117
1118 inode = cfile->dentry->d_inode; 1118 inode = d_inode(cfile->dentry);
1119 cifsi = CIFS_I(inode); 1119 cifsi = CIFS_I(inode);
1120 1120
1121 /* if file not oplocked can't be sure whether asking to extend size */ 1121 /* if file not oplocked can't be sure whether asking to extend size */
diff --git a/fs/cifs/xattr.c b/fs/cifs/xattr.c
index 72a4d10653d6..ff9e1f8b16a4 100644
--- a/fs/cifs/xattr.c
+++ b/fs/cifs/xattr.c
@@ -50,9 +50,9 @@ int cifs_removexattr(struct dentry *direntry, const char *ea_name)
50 50
51 if (direntry == NULL) 51 if (direntry == NULL)
52 return -EIO; 52 return -EIO;
53 if (direntry->d_inode == NULL) 53 if (d_really_is_negative(direntry))
54 return -EIO; 54 return -EIO;
55 sb = direntry->d_inode->i_sb; 55 sb = d_inode(direntry)->i_sb;
56 if (sb == NULL) 56 if (sb == NULL)
57 return -EIO; 57 return -EIO;
58 58
@@ -111,9 +111,9 @@ int cifs_setxattr(struct dentry *direntry, const char *ea_name,
111 111
112 if (direntry == NULL) 112 if (direntry == NULL)
113 return -EIO; 113 return -EIO;
114 if (direntry->d_inode == NULL) 114 if (d_really_is_negative(direntry))
115 return -EIO; 115 return -EIO;
116 sb = direntry->d_inode->i_sb; 116 sb = d_inode(direntry)->i_sb;
117 if (sb == NULL) 117 if (sb == NULL)
118 return -EIO; 118 return -EIO;
119 119
@@ -177,12 +177,12 @@ int cifs_setxattr(struct dentry *direntry, const char *ea_name,
177 memcpy(pacl, ea_value, value_size); 177 memcpy(pacl, ea_value, value_size);
178 if (pTcon->ses->server->ops->set_acl) 178 if (pTcon->ses->server->ops->set_acl)
179 rc = pTcon->ses->server->ops->set_acl(pacl, 179 rc = pTcon->ses->server->ops->set_acl(pacl,
180 value_size, direntry->d_inode, 180 value_size, d_inode(direntry),
181 full_path, CIFS_ACL_DACL); 181 full_path, CIFS_ACL_DACL);
182 else 182 else
183 rc = -EOPNOTSUPP; 183 rc = -EOPNOTSUPP;
184 if (rc == 0) /* force revalidate of the inode */ 184 if (rc == 0) /* force revalidate of the inode */
185 CIFS_I(direntry->d_inode)->time = 0; 185 CIFS_I(d_inode(direntry))->time = 0;
186 kfree(pacl); 186 kfree(pacl);
187 } 187 }
188#else 188#else
@@ -246,9 +246,9 @@ ssize_t cifs_getxattr(struct dentry *direntry, const char *ea_name,
246 246
247 if (direntry == NULL) 247 if (direntry == NULL)
248 return -EIO; 248 return -EIO;
249 if (direntry->d_inode == NULL) 249 if (d_really_is_negative(direntry))
250 return -EIO; 250 return -EIO;
251 sb = direntry->d_inode->i_sb; 251 sb = d_inode(direntry)->i_sb;
252 if (sb == NULL) 252 if (sb == NULL)
253 return -EIO; 253 return -EIO;
254 254
@@ -324,7 +324,7 @@ ssize_t cifs_getxattr(struct dentry *direntry, const char *ea_name,
324 goto get_ea_exit; /* rc already EOPNOTSUPP */ 324 goto get_ea_exit; /* rc already EOPNOTSUPP */
325 325
326 pacl = pTcon->ses->server->ops->get_acl(cifs_sb, 326 pacl = pTcon->ses->server->ops->get_acl(cifs_sb,
327 direntry->d_inode, full_path, &acllen); 327 d_inode(direntry), full_path, &acllen);
328 if (IS_ERR(pacl)) { 328 if (IS_ERR(pacl)) {
329 rc = PTR_ERR(pacl); 329 rc = PTR_ERR(pacl);
330 cifs_dbg(VFS, "%s: error %zd getting sec desc\n", 330 cifs_dbg(VFS, "%s: error %zd getting sec desc\n",
@@ -382,9 +382,9 @@ ssize_t cifs_listxattr(struct dentry *direntry, char *data, size_t buf_size)
382 382
383 if (direntry == NULL) 383 if (direntry == NULL)
384 return -EIO; 384 return -EIO;
385 if (direntry->d_inode == NULL) 385 if (d_really_is_negative(direntry))
386 return -EIO; 386 return -EIO;
387 sb = direntry->d_inode->i_sb; 387 sb = d_inode(direntry)->i_sb;
388 if (sb == NULL) 388 if (sb == NULL)
389 return -EIO; 389 return -EIO;
390 390
diff --git a/fs/coda/cache.c b/fs/coda/cache.c
index 46ee6f238985..5bb630a769e0 100644
--- a/fs/coda/cache.c
+++ b/fs/coda/cache.c
@@ -94,8 +94,8 @@ static void coda_flag_children(struct dentry *parent, int flag)
94 spin_lock(&parent->d_lock); 94 spin_lock(&parent->d_lock);
95 list_for_each_entry(de, &parent->d_subdirs, d_child) { 95 list_for_each_entry(de, &parent->d_subdirs, d_child) {
96 /* don't know what to do with negative dentries */ 96 /* don't know what to do with negative dentries */
97 if (de->d_inode ) 97 if (d_inode(de) )
98 coda_flag_inode(de->d_inode, flag); 98 coda_flag_inode(d_inode(de), flag);
99 } 99 }
100 spin_unlock(&parent->d_lock); 100 spin_unlock(&parent->d_lock);
101 return; 101 return;
diff --git a/fs/coda/dir.c b/fs/coda/dir.c
index 60cb88c1dd2b..fda9f4311212 100644
--- a/fs/coda/dir.c
+++ b/fs/coda/dir.c
@@ -201,7 +201,7 @@ err_out:
201static int coda_link(struct dentry *source_de, struct inode *dir_inode, 201static int coda_link(struct dentry *source_de, struct inode *dir_inode,
202 struct dentry *de) 202 struct dentry *de)
203{ 203{
204 struct inode *inode = source_de->d_inode; 204 struct inode *inode = d_inode(source_de);
205 const char * name = de->d_name.name; 205 const char * name = de->d_name.name;
206 int len = de->d_name.len; 206 int len = de->d_name.len;
207 int error; 207 int error;
@@ -266,7 +266,7 @@ static int coda_unlink(struct inode *dir, struct dentry *de)
266 return error; 266 return error;
267 267
268 coda_dir_update_mtime(dir); 268 coda_dir_update_mtime(dir);
269 drop_nlink(de->d_inode); 269 drop_nlink(d_inode(de));
270 return 0; 270 return 0;
271} 271}
272 272
@@ -279,8 +279,8 @@ static int coda_rmdir(struct inode *dir, struct dentry *de)
279 error = venus_rmdir(dir->i_sb, coda_i2f(dir), name, len); 279 error = venus_rmdir(dir->i_sb, coda_i2f(dir), name, len);
280 if (!error) { 280 if (!error) {
281 /* VFS may delete the child */ 281 /* VFS may delete the child */
282 if (de->d_inode) 282 if (d_really_is_positive(de))
283 clear_nlink(de->d_inode); 283 clear_nlink(d_inode(de));
284 284
285 /* fix the link count of the parent */ 285 /* fix the link count of the parent */
286 coda_dir_drop_nlink(dir); 286 coda_dir_drop_nlink(dir);
@@ -303,14 +303,14 @@ static int coda_rename(struct inode *old_dir, struct dentry *old_dentry,
303 coda_i2f(new_dir), old_length, new_length, 303 coda_i2f(new_dir), old_length, new_length,
304 (const char *) old_name, (const char *)new_name); 304 (const char *) old_name, (const char *)new_name);
305 if (!error) { 305 if (!error) {
306 if (new_dentry->d_inode) { 306 if (d_really_is_positive(new_dentry)) {
307 if (d_is_dir(new_dentry)) { 307 if (d_is_dir(new_dentry)) {
308 coda_dir_drop_nlink(old_dir); 308 coda_dir_drop_nlink(old_dir);
309 coda_dir_inc_nlink(new_dir); 309 coda_dir_inc_nlink(new_dir);
310 } 310 }
311 coda_dir_update_mtime(old_dir); 311 coda_dir_update_mtime(old_dir);
312 coda_dir_update_mtime(new_dir); 312 coda_dir_update_mtime(new_dir);
313 coda_flag_inode(new_dentry->d_inode, C_VATTR); 313 coda_flag_inode(d_inode(new_dentry), C_VATTR);
314 } else { 314 } else {
315 coda_flag_inode(old_dir, C_VATTR); 315 coda_flag_inode(old_dir, C_VATTR);
316 coda_flag_inode(new_dir, C_VATTR); 316 coda_flag_inode(new_dir, C_VATTR);
@@ -449,13 +449,13 @@ static int coda_dentry_revalidate(struct dentry *de, unsigned int flags)
449 if (flags & LOOKUP_RCU) 449 if (flags & LOOKUP_RCU)
450 return -ECHILD; 450 return -ECHILD;
451 451
452 inode = de->d_inode; 452 inode = d_inode(de);
453 if (!inode || is_root_inode(inode)) 453 if (!inode || is_root_inode(inode))
454 goto out; 454 goto out;
455 if (is_bad_inode(inode)) 455 if (is_bad_inode(inode))
456 goto bad; 456 goto bad;
457 457
458 cii = ITOC(de->d_inode); 458 cii = ITOC(d_inode(de));
459 if (!(cii->c_flags & (C_PURGE | C_FLUSH))) 459 if (!(cii->c_flags & (C_PURGE | C_FLUSH)))
460 goto out; 460 goto out;
461 461
@@ -487,11 +487,11 @@ static int coda_dentry_delete(const struct dentry * dentry)
487{ 487{
488 int flags; 488 int flags;
489 489
490 if (!dentry->d_inode) 490 if (d_really_is_negative(dentry))
491 return 0; 491 return 0;
492 492
493 flags = (ITOC(dentry->d_inode)->c_flags) & C_PURGE; 493 flags = (ITOC(d_inode(dentry))->c_flags) & C_PURGE;
494 if (is_bad_inode(dentry->d_inode) || flags) { 494 if (is_bad_inode(d_inode(dentry)) || flags) {
495 return 1; 495 return 1;
496 } 496 }
497 return 0; 497 return 0;
diff --git a/fs/coda/inode.c b/fs/coda/inode.c
index 82ec68b59208..cac1390b87a3 100644
--- a/fs/coda/inode.c
+++ b/fs/coda/inode.c
@@ -257,15 +257,15 @@ static void coda_evict_inode(struct inode *inode)
257 257
258int coda_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat) 258int coda_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
259{ 259{
260 int err = coda_revalidate_inode(dentry->d_inode); 260 int err = coda_revalidate_inode(d_inode(dentry));
261 if (!err) 261 if (!err)
262 generic_fillattr(dentry->d_inode, stat); 262 generic_fillattr(d_inode(dentry), stat);
263 return err; 263 return err;
264} 264}
265 265
266int coda_setattr(struct dentry *de, struct iattr *iattr) 266int coda_setattr(struct dentry *de, struct iattr *iattr)
267{ 267{
268 struct inode *inode = de->d_inode; 268 struct inode *inode = d_inode(de);
269 struct coda_vattr vattr; 269 struct coda_vattr vattr;
270 int error; 270 int error;
271 271
diff --git a/fs/coda/pioctl.c b/fs/coda/pioctl.c
index 4326d172fc27..f36a4040afb8 100644
--- a/fs/coda/pioctl.c
+++ b/fs/coda/pioctl.c
@@ -72,7 +72,7 @@ static long coda_pioctl(struct file *filp, unsigned int cmd,
72 if (error) 72 if (error)
73 return error; 73 return error;
74 74
75 target_inode = path.dentry->d_inode; 75 target_inode = d_inode(path.dentry);
76 76
77 /* return if it is not a Coda inode */ 77 /* return if it is not a Coda inode */
78 if (target_inode->i_sb != inode->i_sb) { 78 if (target_inode->i_sb != inode->i_sb) {
diff --git a/fs/coda/upcall.c b/fs/coda/upcall.c
index 5bb6e27298a4..9b1ffaa0572e 100644
--- a/fs/coda/upcall.c
+++ b/fs/coda/upcall.c
@@ -820,8 +820,8 @@ int coda_downcall(struct venus_comm *vcp, int opcode, union outputArgs *out)
820 case CODA_FLUSH: 820 case CODA_FLUSH:
821 coda_cache_clear_all(sb); 821 coda_cache_clear_all(sb);
822 shrink_dcache_sb(sb); 822 shrink_dcache_sb(sb);
823 if (sb->s_root->d_inode) 823 if (d_really_is_positive(sb->s_root))
824 coda_flag_inode(sb->s_root->d_inode, C_FLUSH); 824 coda_flag_inode(d_inode(sb->s_root), C_FLUSH);
825 break; 825 break;
826 826
827 case CODA_PURGEUSER: 827 case CODA_PURGEUSER:
diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
index acb3d63bc9dc..c81ce7f200a6 100644
--- a/fs/configfs/dir.c
+++ b/fs/configfs/dir.c
@@ -289,7 +289,7 @@ static int configfs_create_dir(struct config_item *item, struct dentry *dentry)
289 configfs_set_dir_dirent_depth(p->d_fsdata, dentry->d_fsdata); 289 configfs_set_dir_dirent_depth(p->d_fsdata, dentry->d_fsdata);
290 error = configfs_create(dentry, mode, init_dir); 290 error = configfs_create(dentry, mode, init_dir);
291 if (!error) { 291 if (!error) {
292 inc_nlink(p->d_inode); 292 inc_nlink(d_inode(p));
293 item->ci_dentry = dentry; 293 item->ci_dentry = dentry;
294 } else { 294 } else {
295 struct configfs_dirent *sd = dentry->d_fsdata; 295 struct configfs_dirent *sd = dentry->d_fsdata;
@@ -375,8 +375,8 @@ static void remove_dir(struct dentry * d)
375 list_del_init(&sd->s_sibling); 375 list_del_init(&sd->s_sibling);
376 spin_unlock(&configfs_dirent_lock); 376 spin_unlock(&configfs_dirent_lock);
377 configfs_put(sd); 377 configfs_put(sd);
378 if (d->d_inode) 378 if (d_really_is_positive(d))
379 simple_rmdir(parent->d_inode,d); 379 simple_rmdir(d_inode(parent),d);
380 380
381 pr_debug(" o %pd removing done (%d)\n", d, d_count(d)); 381 pr_debug(" o %pd removing done (%d)\n", d, d_count(d));
382 382
@@ -513,7 +513,7 @@ static int configfs_detach_prep(struct dentry *dentry, struct mutex **wait_mutex
513 /* Abort if racing with mkdir() */ 513 /* Abort if racing with mkdir() */
514 if (sd->s_type & CONFIGFS_USET_IN_MKDIR) { 514 if (sd->s_type & CONFIGFS_USET_IN_MKDIR) {
515 if (wait_mutex) 515 if (wait_mutex)
516 *wait_mutex = &sd->s_dentry->d_inode->i_mutex; 516 *wait_mutex = &d_inode(sd->s_dentry)->i_mutex;
517 return -EAGAIN; 517 return -EAGAIN;
518 } 518 }
519 519
@@ -624,13 +624,13 @@ static void detach_groups(struct config_group *group)
624 624
625 child = sd->s_dentry; 625 child = sd->s_dentry;
626 626
627 mutex_lock(&child->d_inode->i_mutex); 627 mutex_lock(&d_inode(child)->i_mutex);
628 628
629 configfs_detach_group(sd->s_element); 629 configfs_detach_group(sd->s_element);
630 child->d_inode->i_flags |= S_DEAD; 630 d_inode(child)->i_flags |= S_DEAD;
631 dont_mount(child); 631 dont_mount(child);
632 632
633 mutex_unlock(&child->d_inode->i_mutex); 633 mutex_unlock(&d_inode(child)->i_mutex);
634 634
635 d_delete(child); 635 d_delete(child);
636 dput(child); 636 dput(child);
@@ -672,7 +672,7 @@ static int create_default_group(struct config_group *parent_group,
672 sd = child->d_fsdata; 672 sd = child->d_fsdata;
673 sd->s_type |= CONFIGFS_USET_DEFAULT; 673 sd->s_type |= CONFIGFS_USET_DEFAULT;
674 } else { 674 } else {
675 BUG_ON(child->d_inode); 675 BUG_ON(d_inode(child));
676 d_drop(child); 676 d_drop(child);
677 dput(child); 677 dput(child);
678 } 678 }
@@ -818,11 +818,11 @@ static int configfs_attach_item(struct config_item *parent_item,
818 * the VFS may already have hit and used them. Thus, 818 * the VFS may already have hit and used them. Thus,
819 * we must lock them as rmdir() would. 819 * we must lock them as rmdir() would.
820 */ 820 */
821 mutex_lock(&dentry->d_inode->i_mutex); 821 mutex_lock(&d_inode(dentry)->i_mutex);
822 configfs_remove_dir(item); 822 configfs_remove_dir(item);
823 dentry->d_inode->i_flags |= S_DEAD; 823 d_inode(dentry)->i_flags |= S_DEAD;
824 dont_mount(dentry); 824 dont_mount(dentry);
825 mutex_unlock(&dentry->d_inode->i_mutex); 825 mutex_unlock(&d_inode(dentry)->i_mutex);
826 d_delete(dentry); 826 d_delete(dentry);
827 } 827 }
828 } 828 }
@@ -858,16 +858,16 @@ static int configfs_attach_group(struct config_item *parent_item,
858 * We must also lock the inode to remove it safely in case of 858 * We must also lock the inode to remove it safely in case of
859 * error, as rmdir() would. 859 * error, as rmdir() would.
860 */ 860 */
861 mutex_lock_nested(&dentry->d_inode->i_mutex, I_MUTEX_CHILD); 861 mutex_lock_nested(&d_inode(dentry)->i_mutex, I_MUTEX_CHILD);
862 configfs_adjust_dir_dirent_depth_before_populate(sd); 862 configfs_adjust_dir_dirent_depth_before_populate(sd);
863 ret = populate_groups(to_config_group(item)); 863 ret = populate_groups(to_config_group(item));
864 if (ret) { 864 if (ret) {
865 configfs_detach_item(item); 865 configfs_detach_item(item);
866 dentry->d_inode->i_flags |= S_DEAD; 866 d_inode(dentry)->i_flags |= S_DEAD;
867 dont_mount(dentry); 867 dont_mount(dentry);
868 } 868 }
869 configfs_adjust_dir_dirent_depth_after_populate(sd); 869 configfs_adjust_dir_dirent_depth_after_populate(sd);
870 mutex_unlock(&dentry->d_inode->i_mutex); 870 mutex_unlock(&d_inode(dentry)->i_mutex);
871 if (ret) 871 if (ret)
872 d_delete(dentry); 872 d_delete(dentry);
873 } 873 }
@@ -1075,7 +1075,7 @@ int configfs_depend_item(struct configfs_subsystem *subsys,
1075 * subsystem is really registered, and so we need to lock out 1075 * subsystem is really registered, and so we need to lock out
1076 * configfs_[un]register_subsystem(). 1076 * configfs_[un]register_subsystem().
1077 */ 1077 */
1078 mutex_lock(&root->d_inode->i_mutex); 1078 mutex_lock(&d_inode(root)->i_mutex);
1079 1079
1080 root_sd = root->d_fsdata; 1080 root_sd = root->d_fsdata;
1081 1081
@@ -1111,7 +1111,7 @@ int configfs_depend_item(struct configfs_subsystem *subsys,
1111out_unlock_dirent_lock: 1111out_unlock_dirent_lock:
1112 spin_unlock(&configfs_dirent_lock); 1112 spin_unlock(&configfs_dirent_lock);
1113out_unlock_fs: 1113out_unlock_fs:
1114 mutex_unlock(&root->d_inode->i_mutex); 1114 mutex_unlock(&d_inode(root)->i_mutex);
1115 1115
1116 /* 1116 /*
1117 * If we succeeded, the fs is pinned via other methods. If not, 1117 * If we succeeded, the fs is pinned via other methods. If not,
@@ -1453,11 +1453,11 @@ int configfs_rename_dir(struct config_item * item, const char *new_name)
1453 down_write(&configfs_rename_sem); 1453 down_write(&configfs_rename_sem);
1454 parent = item->parent->dentry; 1454 parent = item->parent->dentry;
1455 1455
1456 mutex_lock(&parent->d_inode->i_mutex); 1456 mutex_lock(&d_inode(parent)->i_mutex);
1457 1457
1458 new_dentry = lookup_one_len(new_name, parent, strlen(new_name)); 1458 new_dentry = lookup_one_len(new_name, parent, strlen(new_name));
1459 if (!IS_ERR(new_dentry)) { 1459 if (!IS_ERR(new_dentry)) {
1460 if (!new_dentry->d_inode) { 1460 if (d_really_is_negative(new_dentry)) {
1461 error = config_item_set_name(item, "%s", new_name); 1461 error = config_item_set_name(item, "%s", new_name);
1462 if (!error) { 1462 if (!error) {
1463 d_add(new_dentry, NULL); 1463 d_add(new_dentry, NULL);
@@ -1469,7 +1469,7 @@ int configfs_rename_dir(struct config_item * item, const char *new_name)
1469 error = -EEXIST; 1469 error = -EEXIST;
1470 dput(new_dentry); 1470 dput(new_dentry);
1471 } 1471 }
1472 mutex_unlock(&parent->d_inode->i_mutex); 1472 mutex_unlock(&d_inode(parent)->i_mutex);
1473 up_write(&configfs_rename_sem); 1473 up_write(&configfs_rename_sem);
1474 1474
1475 return error; 1475 return error;
@@ -1482,7 +1482,7 @@ static int configfs_dir_open(struct inode *inode, struct file *file)
1482 struct configfs_dirent * parent_sd = dentry->d_fsdata; 1482 struct configfs_dirent * parent_sd = dentry->d_fsdata;
1483 int err; 1483 int err;
1484 1484
1485 mutex_lock(&dentry->d_inode->i_mutex); 1485 mutex_lock(&d_inode(dentry)->i_mutex);
1486 /* 1486 /*
1487 * Fake invisibility if dir belongs to a group/default groups hierarchy 1487 * Fake invisibility if dir belongs to a group/default groups hierarchy
1488 * being attached 1488 * being attached
@@ -1495,7 +1495,7 @@ static int configfs_dir_open(struct inode *inode, struct file *file)
1495 else 1495 else
1496 err = 0; 1496 err = 0;
1497 } 1497 }
1498 mutex_unlock(&dentry->d_inode->i_mutex); 1498 mutex_unlock(&d_inode(dentry)->i_mutex);
1499 1499
1500 return err; 1500 return err;
1501} 1501}
@@ -1505,11 +1505,11 @@ static int configfs_dir_close(struct inode *inode, struct file *file)
1505 struct dentry * dentry = file->f_path.dentry; 1505 struct dentry * dentry = file->f_path.dentry;
1506 struct configfs_dirent * cursor = file->private_data; 1506 struct configfs_dirent * cursor = file->private_data;
1507 1507
1508 mutex_lock(&dentry->d_inode->i_mutex); 1508 mutex_lock(&d_inode(dentry)->i_mutex);
1509 spin_lock(&configfs_dirent_lock); 1509 spin_lock(&configfs_dirent_lock);
1510 list_del_init(&cursor->s_sibling); 1510 list_del_init(&cursor->s_sibling);
1511 spin_unlock(&configfs_dirent_lock); 1511 spin_unlock(&configfs_dirent_lock);
1512 mutex_unlock(&dentry->d_inode->i_mutex); 1512 mutex_unlock(&d_inode(dentry)->i_mutex);
1513 1513
1514 release_configfs_dirent(cursor); 1514 release_configfs_dirent(cursor);
1515 1515
@@ -1567,7 +1567,7 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
1567 spin_lock(&configfs_dirent_lock); 1567 spin_lock(&configfs_dirent_lock);
1568 dentry = next->s_dentry; 1568 dentry = next->s_dentry;
1569 if (dentry) 1569 if (dentry)
1570 inode = dentry->d_inode; 1570 inode = d_inode(dentry);
1571 if (inode) 1571 if (inode)
1572 ino = inode->i_ino; 1572 ino = inode->i_ino;
1573 spin_unlock(&configfs_dirent_lock); 1573 spin_unlock(&configfs_dirent_lock);
@@ -1590,7 +1590,7 @@ static loff_t configfs_dir_lseek(struct file *file, loff_t offset, int whence)
1590{ 1590{
1591 struct dentry * dentry = file->f_path.dentry; 1591 struct dentry * dentry = file->f_path.dentry;
1592 1592
1593 mutex_lock(&dentry->d_inode->i_mutex); 1593 mutex_lock(&d_inode(dentry)->i_mutex);
1594 switch (whence) { 1594 switch (whence) {
1595 case 1: 1595 case 1:
1596 offset += file->f_pos; 1596 offset += file->f_pos;
@@ -1598,7 +1598,7 @@ static loff_t configfs_dir_lseek(struct file *file, loff_t offset, int whence)
1598 if (offset >= 0) 1598 if (offset >= 0)
1599 break; 1599 break;
1600 default: 1600 default:
1601 mutex_unlock(&dentry->d_inode->i_mutex); 1601 mutex_unlock(&d_inode(dentry)->i_mutex);
1602 return -EINVAL; 1602 return -EINVAL;
1603 } 1603 }
1604 if (offset != file->f_pos) { 1604 if (offset != file->f_pos) {
@@ -1624,7 +1624,7 @@ static loff_t configfs_dir_lseek(struct file *file, loff_t offset, int whence)
1624 spin_unlock(&configfs_dirent_lock); 1624 spin_unlock(&configfs_dirent_lock);
1625 } 1625 }
1626 } 1626 }
1627 mutex_unlock(&dentry->d_inode->i_mutex); 1627 mutex_unlock(&d_inode(dentry)->i_mutex);
1628 return offset; 1628 return offset;
1629} 1629}
1630 1630
@@ -1654,7 +1654,7 @@ int configfs_register_subsystem(struct configfs_subsystem *subsys)
1654 sd = root->d_fsdata; 1654 sd = root->d_fsdata;
1655 link_group(to_config_group(sd->s_element), group); 1655 link_group(to_config_group(sd->s_element), group);
1656 1656
1657 mutex_lock_nested(&root->d_inode->i_mutex, I_MUTEX_PARENT); 1657 mutex_lock_nested(&d_inode(root)->i_mutex, I_MUTEX_PARENT);
1658 1658
1659 err = -ENOMEM; 1659 err = -ENOMEM;
1660 dentry = d_alloc_name(root, group->cg_item.ci_name); 1660 dentry = d_alloc_name(root, group->cg_item.ci_name);
@@ -1664,7 +1664,7 @@ int configfs_register_subsystem(struct configfs_subsystem *subsys)
1664 err = configfs_attach_group(sd->s_element, &group->cg_item, 1664 err = configfs_attach_group(sd->s_element, &group->cg_item,
1665 dentry); 1665 dentry);
1666 if (err) { 1666 if (err) {
1667 BUG_ON(dentry->d_inode); 1667 BUG_ON(d_inode(dentry));
1668 d_drop(dentry); 1668 d_drop(dentry);
1669 dput(dentry); 1669 dput(dentry);
1670 } else { 1670 } else {
@@ -1674,7 +1674,7 @@ int configfs_register_subsystem(struct configfs_subsystem *subsys)
1674 } 1674 }
1675 } 1675 }
1676 1676
1677 mutex_unlock(&root->d_inode->i_mutex); 1677 mutex_unlock(&d_inode(root)->i_mutex);
1678 1678
1679 if (err) { 1679 if (err) {
1680 unlink_group(group); 1680 unlink_group(group);
@@ -1695,9 +1695,9 @@ void configfs_unregister_subsystem(struct configfs_subsystem *subsys)
1695 return; 1695 return;
1696 } 1696 }
1697 1697
1698 mutex_lock_nested(&root->d_inode->i_mutex, 1698 mutex_lock_nested(&d_inode(root)->i_mutex,
1699 I_MUTEX_PARENT); 1699 I_MUTEX_PARENT);
1700 mutex_lock_nested(&dentry->d_inode->i_mutex, I_MUTEX_CHILD); 1700 mutex_lock_nested(&d_inode(dentry)->i_mutex, I_MUTEX_CHILD);
1701 mutex_lock(&configfs_symlink_mutex); 1701 mutex_lock(&configfs_symlink_mutex);
1702 spin_lock(&configfs_dirent_lock); 1702 spin_lock(&configfs_dirent_lock);
1703 if (configfs_detach_prep(dentry, NULL)) { 1703 if (configfs_detach_prep(dentry, NULL)) {
@@ -1706,13 +1706,13 @@ void configfs_unregister_subsystem(struct configfs_subsystem *subsys)
1706 spin_unlock(&configfs_dirent_lock); 1706 spin_unlock(&configfs_dirent_lock);
1707 mutex_unlock(&configfs_symlink_mutex); 1707 mutex_unlock(&configfs_symlink_mutex);
1708 configfs_detach_group(&group->cg_item); 1708 configfs_detach_group(&group->cg_item);
1709 dentry->d_inode->i_flags |= S_DEAD; 1709 d_inode(dentry)->i_flags |= S_DEAD;
1710 dont_mount(dentry); 1710 dont_mount(dentry);
1711 mutex_unlock(&dentry->d_inode->i_mutex); 1711 mutex_unlock(&d_inode(dentry)->i_mutex);
1712 1712
1713 d_delete(dentry); 1713 d_delete(dentry);
1714 1714
1715 mutex_unlock(&root->d_inode->i_mutex); 1715 mutex_unlock(&d_inode(root)->i_mutex);
1716 1716
1717 dput(dentry); 1717 dput(dentry);
1718 1718
diff --git a/fs/configfs/file.c b/fs/configfs/file.c
index 56d2cdc9ae0a..403269ffcdf3 100644
--- a/fs/configfs/file.c
+++ b/fs/configfs/file.c
@@ -326,10 +326,10 @@ int configfs_create_file(struct config_item * item, const struct configfs_attrib
326 umode_t mode = (attr->ca_mode & S_IALLUGO) | S_IFREG; 326 umode_t mode = (attr->ca_mode & S_IALLUGO) | S_IFREG;
327 int error = 0; 327 int error = 0;
328 328
329 mutex_lock_nested(&dir->d_inode->i_mutex, I_MUTEX_NORMAL); 329 mutex_lock_nested(&d_inode(dir)->i_mutex, I_MUTEX_NORMAL);
330 error = configfs_make_dirent(parent_sd, NULL, (void *) attr, mode, 330 error = configfs_make_dirent(parent_sd, NULL, (void *) attr, mode,
331 CONFIGFS_ITEM_ATTR); 331 CONFIGFS_ITEM_ATTR);
332 mutex_unlock(&dir->d_inode->i_mutex); 332 mutex_unlock(&d_inode(dir)->i_mutex);
333 333
334 return error; 334 return error;
335} 335}
diff --git a/fs/configfs/inode.c b/fs/configfs/inode.c
index 5423a6a6ecc8..8d89f5fd0331 100644
--- a/fs/configfs/inode.c
+++ b/fs/configfs/inode.c
@@ -56,7 +56,7 @@ static const struct inode_operations configfs_inode_operations ={
56 56
57int configfs_setattr(struct dentry * dentry, struct iattr * iattr) 57int configfs_setattr(struct dentry * dentry, struct iattr * iattr)
58{ 58{
59 struct inode * inode = dentry->d_inode; 59 struct inode * inode = d_inode(dentry);
60 struct configfs_dirent * sd = dentry->d_fsdata; 60 struct configfs_dirent * sd = dentry->d_fsdata;
61 struct iattr * sd_iattr; 61 struct iattr * sd_iattr;
62 unsigned int ia_valid = iattr->ia_valid; 62 unsigned int ia_valid = iattr->ia_valid;
@@ -186,7 +186,7 @@ int configfs_create(struct dentry * dentry, umode_t mode, void (*init)(struct in
186 if (!dentry) 186 if (!dentry)
187 return -ENOENT; 187 return -ENOENT;
188 188
189 if (dentry->d_inode) 189 if (d_really_is_positive(dentry))
190 return -EEXIST; 190 return -EEXIST;
191 191
192 sd = dentry->d_fsdata; 192 sd = dentry->d_fsdata;
@@ -194,7 +194,7 @@ int configfs_create(struct dentry * dentry, umode_t mode, void (*init)(struct in
194 if (!inode) 194 if (!inode)
195 return -ENOMEM; 195 return -ENOMEM;
196 196
197 p_inode = dentry->d_parent->d_inode; 197 p_inode = d_inode(dentry->d_parent);
198 p_inode->i_mtime = p_inode->i_ctime = CURRENT_TIME; 198 p_inode->i_mtime = p_inode->i_ctime = CURRENT_TIME;
199 configfs_set_inode_lock_class(sd, inode); 199 configfs_set_inode_lock_class(sd, inode);
200 200
@@ -236,11 +236,11 @@ void configfs_drop_dentry(struct configfs_dirent * sd, struct dentry * parent)
236 236
237 if (dentry) { 237 if (dentry) {
238 spin_lock(&dentry->d_lock); 238 spin_lock(&dentry->d_lock);
239 if (!d_unhashed(dentry) && dentry->d_inode) { 239 if (!d_unhashed(dentry) && d_really_is_positive(dentry)) {
240 dget_dlock(dentry); 240 dget_dlock(dentry);
241 __d_drop(dentry); 241 __d_drop(dentry);
242 spin_unlock(&dentry->d_lock); 242 spin_unlock(&dentry->d_lock);
243 simple_unlink(parent->d_inode, dentry); 243 simple_unlink(d_inode(parent), dentry);
244 } else 244 } else
245 spin_unlock(&dentry->d_lock); 245 spin_unlock(&dentry->d_lock);
246 } 246 }
@@ -251,11 +251,11 @@ void configfs_hash_and_remove(struct dentry * dir, const char * name)
251 struct configfs_dirent * sd; 251 struct configfs_dirent * sd;
252 struct configfs_dirent * parent_sd = dir->d_fsdata; 252 struct configfs_dirent * parent_sd = dir->d_fsdata;
253 253
254 if (dir->d_inode == NULL) 254 if (d_really_is_negative(dir))
255 /* no inode means this hasn't been made visible yet */ 255 /* no inode means this hasn't been made visible yet */
256 return; 256 return;
257 257
258 mutex_lock(&dir->d_inode->i_mutex); 258 mutex_lock(&d_inode(dir)->i_mutex);
259 list_for_each_entry(sd, &parent_sd->s_children, s_sibling) { 259 list_for_each_entry(sd, &parent_sd->s_children, s_sibling) {
260 if (!sd->s_element) 260 if (!sd->s_element)
261 continue; 261 continue;
@@ -268,5 +268,5 @@ void configfs_hash_and_remove(struct dentry * dir, const char * name)
268 break; 268 break;
269 } 269 }
270 } 270 }
271 mutex_unlock(&dir->d_inode->i_mutex); 271 mutex_unlock(&d_inode(dir)->i_mutex);
272} 272}
diff --git a/fs/dax.c b/fs/dax.c
index 0bb0aecb556c..6f65f00e58ec 100644
--- a/fs/dax.c
+++ b/fs/dax.c
@@ -209,7 +209,7 @@ ssize_t dax_do_io(struct kiocb *iocb, struct inode *inode,
209 } 209 }
210 210
211 /* Protects against truncate */ 211 /* Protects against truncate */
212 atomic_inc(&inode->i_dio_count); 212 inode_dio_begin(inode);
213 213
214 retval = dax_io(inode, iter, pos, end, get_block, &bh); 214 retval = dax_io(inode, iter, pos, end, get_block, &bh);
215 215
@@ -219,7 +219,7 @@ ssize_t dax_do_io(struct kiocb *iocb, struct inode *inode,
219 if ((retval > 0) && end_io) 219 if ((retval > 0) && end_io)
220 end_io(iocb, pos, retval, bh.b_private); 220 end_io(iocb, pos, retval, bh.b_private);
221 221
222 inode_dio_done(inode); 222 inode_dio_end(inode);
223 out: 223 out:
224 return retval; 224 return retval;
225} 225}
diff --git a/fs/debugfs/file.c b/fs/debugfs/file.c
index 517e64938438..830a7e76f5c6 100644
--- a/fs/debugfs/file.c
+++ b/fs/debugfs/file.c
@@ -45,7 +45,7 @@ const struct file_operations debugfs_file_operations = {
45 45
46static void *debugfs_follow_link(struct dentry *dentry, struct nameidata *nd) 46static void *debugfs_follow_link(struct dentry *dentry, struct nameidata *nd)
47{ 47{
48 nd_set_link(nd, dentry->d_inode->i_private); 48 nd_set_link(nd, d_inode(dentry)->i_private);
49 return NULL; 49 return NULL;
50} 50}
51 51
diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
index c9ee0dfe90b5..c1e7ffb0dab6 100644
--- a/fs/debugfs/inode.c
+++ b/fs/debugfs/inode.c
@@ -46,7 +46,7 @@ static struct inode *debugfs_get_inode(struct super_block *sb)
46 46
47static inline int debugfs_positive(struct dentry *dentry) 47static inline int debugfs_positive(struct dentry *dentry)
48{ 48{
49 return dentry->d_inode && !d_unhashed(dentry); 49 return d_really_is_positive(dentry) && !d_unhashed(dentry);
50} 50}
51 51
52struct debugfs_mount_opts { 52struct debugfs_mount_opts {
@@ -124,7 +124,7 @@ static int debugfs_parse_options(char *data, struct debugfs_mount_opts *opts)
124static int debugfs_apply_options(struct super_block *sb) 124static int debugfs_apply_options(struct super_block *sb)
125{ 125{
126 struct debugfs_fs_info *fsi = sb->s_fs_info; 126 struct debugfs_fs_info *fsi = sb->s_fs_info;
127 struct inode *inode = sb->s_root->d_inode; 127 struct inode *inode = d_inode(sb->s_root);
128 struct debugfs_mount_opts *opts = &fsi->mount_opts; 128 struct debugfs_mount_opts *opts = &fsi->mount_opts;
129 129
130 inode->i_mode &= ~S_IALLUGO; 130 inode->i_mode &= ~S_IALLUGO;
@@ -188,7 +188,7 @@ static struct vfsmount *debugfs_automount(struct path *path)
188{ 188{
189 struct vfsmount *(*f)(void *); 189 struct vfsmount *(*f)(void *);
190 f = (struct vfsmount *(*)(void *))path->dentry->d_fsdata; 190 f = (struct vfsmount *(*)(void *))path->dentry->d_fsdata;
191 return f(path->dentry->d_inode->i_private); 191 return f(d_inode(path->dentry)->i_private);
192} 192}
193 193
194static const struct dentry_operations debugfs_dops = { 194static const struct dentry_operations debugfs_dops = {
@@ -270,20 +270,20 @@ static struct dentry *start_creating(const char *name, struct dentry *parent)
270 if (!parent) 270 if (!parent)
271 parent = debugfs_mount->mnt_root; 271 parent = debugfs_mount->mnt_root;
272 272
273 mutex_lock(&parent->d_inode->i_mutex); 273 mutex_lock(&d_inode(parent)->i_mutex);
274 dentry = lookup_one_len(name, parent, strlen(name)); 274 dentry = lookup_one_len(name, parent, strlen(name));
275 if (!IS_ERR(dentry) && dentry->d_inode) { 275 if (!IS_ERR(dentry) && d_really_is_positive(dentry)) {
276 dput(dentry); 276 dput(dentry);
277 dentry = ERR_PTR(-EEXIST); 277 dentry = ERR_PTR(-EEXIST);
278 } 278 }
279 if (IS_ERR(dentry)) 279 if (IS_ERR(dentry))
280 mutex_unlock(&parent->d_inode->i_mutex); 280 mutex_unlock(&d_inode(parent)->i_mutex);
281 return dentry; 281 return dentry;
282} 282}
283 283
284static struct dentry *failed_creating(struct dentry *dentry) 284static struct dentry *failed_creating(struct dentry *dentry)
285{ 285{
286 mutex_unlock(&dentry->d_parent->d_inode->i_mutex); 286 mutex_unlock(&d_inode(dentry->d_parent)->i_mutex);
287 dput(dentry); 287 dput(dentry);
288 simple_release_fs(&debugfs_mount, &debugfs_mount_count); 288 simple_release_fs(&debugfs_mount, &debugfs_mount_count);
289 return NULL; 289 return NULL;
@@ -291,7 +291,7 @@ static struct dentry *failed_creating(struct dentry *dentry)
291 291
292static struct dentry *end_creating(struct dentry *dentry) 292static struct dentry *end_creating(struct dentry *dentry)
293{ 293{
294 mutex_unlock(&dentry->d_parent->d_inode->i_mutex); 294 mutex_unlock(&d_inode(dentry->d_parent)->i_mutex);
295 return dentry; 295 return dentry;
296} 296}
297 297
@@ -344,7 +344,7 @@ struct dentry *debugfs_create_file(const char *name, umode_t mode,
344 inode->i_fop = fops ? fops : &debugfs_file_operations; 344 inode->i_fop = fops ? fops : &debugfs_file_operations;
345 inode->i_private = data; 345 inode->i_private = data;
346 d_instantiate(dentry, inode); 346 d_instantiate(dentry, inode);
347 fsnotify_create(dentry->d_parent->d_inode, dentry); 347 fsnotify_create(d_inode(dentry->d_parent), dentry);
348 return end_creating(dentry); 348 return end_creating(dentry);
349} 349}
350EXPORT_SYMBOL_GPL(debugfs_create_file); 350EXPORT_SYMBOL_GPL(debugfs_create_file);
@@ -384,7 +384,7 @@ struct dentry *debugfs_create_file_size(const char *name, umode_t mode,
384 struct dentry *de = debugfs_create_file(name, mode, parent, data, fops); 384 struct dentry *de = debugfs_create_file(name, mode, parent, data, fops);
385 385
386 if (de) 386 if (de)
387 de->d_inode->i_size = file_size; 387 d_inode(de)->i_size = file_size;
388 return de; 388 return de;
389} 389}
390EXPORT_SYMBOL_GPL(debugfs_create_file_size); 390EXPORT_SYMBOL_GPL(debugfs_create_file_size);
@@ -426,8 +426,8 @@ struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
426 /* directory inodes start off with i_nlink == 2 (for "." entry) */ 426 /* directory inodes start off with i_nlink == 2 (for "." entry) */
427 inc_nlink(inode); 427 inc_nlink(inode);
428 d_instantiate(dentry, inode); 428 d_instantiate(dentry, inode);
429 inc_nlink(dentry->d_parent->d_inode); 429 inc_nlink(d_inode(dentry->d_parent));
430 fsnotify_mkdir(dentry->d_parent->d_inode, dentry); 430 fsnotify_mkdir(d_inode(dentry->d_parent), dentry);
431 return end_creating(dentry); 431 return end_creating(dentry);
432} 432}
433EXPORT_SYMBOL_GPL(debugfs_create_dir); 433EXPORT_SYMBOL_GPL(debugfs_create_dir);
@@ -525,9 +525,9 @@ static int __debugfs_remove(struct dentry *dentry, struct dentry *parent)
525 if (debugfs_positive(dentry)) { 525 if (debugfs_positive(dentry)) {
526 dget(dentry); 526 dget(dentry);
527 if (d_is_dir(dentry)) 527 if (d_is_dir(dentry))
528 ret = simple_rmdir(parent->d_inode, dentry); 528 ret = simple_rmdir(d_inode(parent), dentry);
529 else 529 else
530 simple_unlink(parent->d_inode, dentry); 530 simple_unlink(d_inode(parent), dentry);
531 if (!ret) 531 if (!ret)
532 d_delete(dentry); 532 d_delete(dentry);
533 dput(dentry); 533 dput(dentry);
@@ -557,12 +557,12 @@ void debugfs_remove(struct dentry *dentry)
557 return; 557 return;
558 558
559 parent = dentry->d_parent; 559 parent = dentry->d_parent;
560 if (!parent || !parent->d_inode) 560 if (!parent || d_really_is_negative(parent))
561 return; 561 return;
562 562
563 mutex_lock(&parent->d_inode->i_mutex); 563 mutex_lock(&d_inode(parent)->i_mutex);
564 ret = __debugfs_remove(dentry, parent); 564 ret = __debugfs_remove(dentry, parent);
565 mutex_unlock(&parent->d_inode->i_mutex); 565 mutex_unlock(&d_inode(parent)->i_mutex);
566 if (!ret) 566 if (!ret)
567 simple_release_fs(&debugfs_mount, &debugfs_mount_count); 567 simple_release_fs(&debugfs_mount, &debugfs_mount_count);
568} 568}
@@ -588,12 +588,12 @@ void debugfs_remove_recursive(struct dentry *dentry)
588 return; 588 return;
589 589
590 parent = dentry->d_parent; 590 parent = dentry->d_parent;
591 if (!parent || !parent->d_inode) 591 if (!parent || d_really_is_negative(parent))
592 return; 592 return;
593 593
594 parent = dentry; 594 parent = dentry;
595 down: 595 down:
596 mutex_lock(&parent->d_inode->i_mutex); 596 mutex_lock(&d_inode(parent)->i_mutex);
597 loop: 597 loop:
598 /* 598 /*
599 * The parent->d_subdirs is protected by the d_lock. Outside that 599 * The parent->d_subdirs is protected by the d_lock. Outside that
@@ -608,7 +608,7 @@ void debugfs_remove_recursive(struct dentry *dentry)
608 /* perhaps simple_empty(child) makes more sense */ 608 /* perhaps simple_empty(child) makes more sense */
609 if (!list_empty(&child->d_subdirs)) { 609 if (!list_empty(&child->d_subdirs)) {
610 spin_unlock(&parent->d_lock); 610 spin_unlock(&parent->d_lock);
611 mutex_unlock(&parent->d_inode->i_mutex); 611 mutex_unlock(&d_inode(parent)->i_mutex);
612 parent = child; 612 parent = child;
613 goto down; 613 goto down;
614 } 614 }
@@ -629,10 +629,10 @@ void debugfs_remove_recursive(struct dentry *dentry)
629 } 629 }
630 spin_unlock(&parent->d_lock); 630 spin_unlock(&parent->d_lock);
631 631
632 mutex_unlock(&parent->d_inode->i_mutex); 632 mutex_unlock(&d_inode(parent)->i_mutex);
633 child = parent; 633 child = parent;
634 parent = parent->d_parent; 634 parent = parent->d_parent;
635 mutex_lock(&parent->d_inode->i_mutex); 635 mutex_lock(&d_inode(parent)->i_mutex);
636 636
637 if (child != dentry) 637 if (child != dentry)
638 /* go up */ 638 /* go up */
@@ -640,7 +640,7 @@ void debugfs_remove_recursive(struct dentry *dentry)
640 640
641 if (!__debugfs_remove(child, parent)) 641 if (!__debugfs_remove(child, parent))
642 simple_release_fs(&debugfs_mount, &debugfs_mount_count); 642 simple_release_fs(&debugfs_mount, &debugfs_mount_count);
643 mutex_unlock(&parent->d_inode->i_mutex); 643 mutex_unlock(&d_inode(parent)->i_mutex);
644} 644}
645EXPORT_SYMBOL_GPL(debugfs_remove_recursive); 645EXPORT_SYMBOL_GPL(debugfs_remove_recursive);
646 646
@@ -672,27 +672,27 @@ struct dentry *debugfs_rename(struct dentry *old_dir, struct dentry *old_dentry,
672 672
673 trap = lock_rename(new_dir, old_dir); 673 trap = lock_rename(new_dir, old_dir);
674 /* Source or destination directories don't exist? */ 674 /* Source or destination directories don't exist? */
675 if (!old_dir->d_inode || !new_dir->d_inode) 675 if (d_really_is_negative(old_dir) || d_really_is_negative(new_dir))
676 goto exit; 676 goto exit;
677 /* Source does not exist, cyclic rename, or mountpoint? */ 677 /* Source does not exist, cyclic rename, or mountpoint? */
678 if (!old_dentry->d_inode || old_dentry == trap || 678 if (d_really_is_negative(old_dentry) || old_dentry == trap ||
679 d_mountpoint(old_dentry)) 679 d_mountpoint(old_dentry))
680 goto exit; 680 goto exit;
681 dentry = lookup_one_len(new_name, new_dir, strlen(new_name)); 681 dentry = lookup_one_len(new_name, new_dir, strlen(new_name));
682 /* Lookup failed, cyclic rename or target exists? */ 682 /* Lookup failed, cyclic rename or target exists? */
683 if (IS_ERR(dentry) || dentry == trap || dentry->d_inode) 683 if (IS_ERR(dentry) || dentry == trap || d_really_is_positive(dentry))
684 goto exit; 684 goto exit;
685 685
686 old_name = fsnotify_oldname_init(old_dentry->d_name.name); 686 old_name = fsnotify_oldname_init(old_dentry->d_name.name);
687 687
688 error = simple_rename(old_dir->d_inode, old_dentry, new_dir->d_inode, 688 error = simple_rename(d_inode(old_dir), old_dentry, d_inode(new_dir),
689 dentry); 689 dentry);
690 if (error) { 690 if (error) {
691 fsnotify_oldname_free(old_name); 691 fsnotify_oldname_free(old_name);
692 goto exit; 692 goto exit;
693 } 693 }
694 d_move(old_dentry, dentry); 694 d_move(old_dentry, dentry);
695 fsnotify_move(old_dir->d_inode, new_dir->d_inode, old_name, 695 fsnotify_move(d_inode(old_dir), d_inode(new_dir), old_name,
696 d_is_dir(old_dentry), 696 d_is_dir(old_dentry),
697 NULL, old_dentry); 697 NULL, old_dentry);
698 fsnotify_oldname_free(old_name); 698 fsnotify_oldname_free(old_name);
diff --git a/fs/devpts/inode.c b/fs/devpts/inode.c
index cfe8466f7fef..add566303c68 100644
--- a/fs/devpts/inode.c
+++ b/fs/devpts/inode.c
@@ -253,7 +253,7 @@ static int mknod_ptmx(struct super_block *sb)
253 if (!uid_valid(root_uid) || !gid_valid(root_gid)) 253 if (!uid_valid(root_uid) || !gid_valid(root_gid))
254 return -EINVAL; 254 return -EINVAL;
255 255
256 mutex_lock(&root->d_inode->i_mutex); 256 mutex_lock(&d_inode(root)->i_mutex);
257 257
258 /* If we have already created ptmx node, return */ 258 /* If we have already created ptmx node, return */
259 if (fsi->ptmx_dentry) { 259 if (fsi->ptmx_dentry) {
@@ -290,7 +290,7 @@ static int mknod_ptmx(struct super_block *sb)
290 fsi->ptmx_dentry = dentry; 290 fsi->ptmx_dentry = dentry;
291 rc = 0; 291 rc = 0;
292out: 292out:
293 mutex_unlock(&root->d_inode->i_mutex); 293 mutex_unlock(&d_inode(root)->i_mutex);
294 return rc; 294 return rc;
295} 295}
296 296
@@ -298,7 +298,7 @@ static void update_ptmx_mode(struct pts_fs_info *fsi)
298{ 298{
299 struct inode *inode; 299 struct inode *inode;
300 if (fsi->ptmx_dentry) { 300 if (fsi->ptmx_dentry) {
301 inode = fsi->ptmx_dentry->d_inode; 301 inode = d_inode(fsi->ptmx_dentry);
302 inode->i_mode = S_IFCHR|fsi->mount_opts.ptmxmode; 302 inode->i_mode = S_IFCHR|fsi->mount_opts.ptmxmode;
303 } 303 }
304} 304}
@@ -602,18 +602,18 @@ struct inode *devpts_pty_new(struct inode *ptmx_inode, dev_t device, int index,
602 602
603 sprintf(s, "%d", index); 603 sprintf(s, "%d", index);
604 604
605 mutex_lock(&root->d_inode->i_mutex); 605 mutex_lock(&d_inode(root)->i_mutex);
606 606
607 dentry = d_alloc_name(root, s); 607 dentry = d_alloc_name(root, s);
608 if (dentry) { 608 if (dentry) {
609 d_add(dentry, inode); 609 d_add(dentry, inode);
610 fsnotify_create(root->d_inode, dentry); 610 fsnotify_create(d_inode(root), dentry);
611 } else { 611 } else {
612 iput(inode); 612 iput(inode);
613 inode = ERR_PTR(-ENOMEM); 613 inode = ERR_PTR(-ENOMEM);
614 } 614 }
615 615
616 mutex_unlock(&root->d_inode->i_mutex); 616 mutex_unlock(&d_inode(root)->i_mutex);
617 617
618 return inode; 618 return inode;
619} 619}
@@ -658,7 +658,7 @@ void devpts_pty_kill(struct inode *inode)
658 658
659 BUG_ON(inode->i_rdev == MKDEV(TTYAUX_MAJOR, PTMX_MINOR)); 659 BUG_ON(inode->i_rdev == MKDEV(TTYAUX_MAJOR, PTMX_MINOR));
660 660
661 mutex_lock(&root->d_inode->i_mutex); 661 mutex_lock(&d_inode(root)->i_mutex);
662 662
663 dentry = d_find_alias(inode); 663 dentry = d_find_alias(inode);
664 664
@@ -667,7 +667,7 @@ void devpts_pty_kill(struct inode *inode)
667 dput(dentry); /* d_alloc_name() in devpts_pty_new() */ 667 dput(dentry); /* d_alloc_name() in devpts_pty_new() */
668 dput(dentry); /* d_find_alias above */ 668 dput(dentry); /* d_find_alias above */
669 669
670 mutex_unlock(&root->d_inode->i_mutex); 670 mutex_unlock(&d_inode(root)->i_mutex);
671} 671}
672 672
673static int __init init_devpts_fs(void) 673static int __init init_devpts_fs(void)
diff --git a/fs/direct-io.c b/fs/direct-io.c
index c3b560b24a46..745d2342651a 100644
--- a/fs/direct-io.c
+++ b/fs/direct-io.c
@@ -253,7 +253,9 @@ static ssize_t dio_complete(struct dio *dio, loff_t offset, ssize_t ret,
253 if (dio->end_io && dio->result) 253 if (dio->end_io && dio->result)
254 dio->end_io(dio->iocb, offset, transferred, dio->private); 254 dio->end_io(dio->iocb, offset, transferred, dio->private);
255 255
256 inode_dio_done(dio->inode); 256 if (!(dio->flags & DIO_SKIP_DIO_COUNT))
257 inode_dio_end(dio->inode);
258
257 if (is_async) { 259 if (is_async) {
258 if (dio->rw & WRITE) { 260 if (dio->rw & WRITE) {
259 int err; 261 int err;
@@ -1195,7 +1197,8 @@ do_blockdev_direct_IO(struct kiocb *iocb, struct inode *inode,
1195 /* 1197 /*
1196 * Will be decremented at I/O completion time. 1198 * Will be decremented at I/O completion time.
1197 */ 1199 */
1198 atomic_inc(&inode->i_dio_count); 1200 if (!(dio->flags & DIO_SKIP_DIO_COUNT))
1201 inode_dio_begin(inode);
1199 1202
1200 retval = 0; 1203 retval = 0;
1201 sdio.blkbits = blkbits; 1204 sdio.blkbits = blkbits;
diff --git a/fs/ecryptfs/crypto.c b/fs/ecryptfs/crypto.c
index 719e1ce1c609..97315f2f6816 100644
--- a/fs/ecryptfs/crypto.c
+++ b/fs/ecryptfs/crypto.c
@@ -1326,7 +1326,7 @@ static int ecryptfs_read_headers_virt(char *page_virt,
1326 if (rc) 1326 if (rc)
1327 goto out; 1327 goto out;
1328 if (!(crypt_stat->flags & ECRYPTFS_I_SIZE_INITIALIZED)) 1328 if (!(crypt_stat->flags & ECRYPTFS_I_SIZE_INITIALIZED))
1329 ecryptfs_i_size_init(page_virt, ecryptfs_dentry->d_inode); 1329 ecryptfs_i_size_init(page_virt, d_inode(ecryptfs_dentry));
1330 offset += MAGIC_ECRYPTFS_MARKER_SIZE_BYTES; 1330 offset += MAGIC_ECRYPTFS_MARKER_SIZE_BYTES;
1331 rc = ecryptfs_process_flags(crypt_stat, (page_virt + offset), 1331 rc = ecryptfs_process_flags(crypt_stat, (page_virt + offset),
1332 &bytes_read); 1332 &bytes_read);
@@ -1425,7 +1425,7 @@ int ecryptfs_read_metadata(struct dentry *ecryptfs_dentry)
1425{ 1425{
1426 int rc; 1426 int rc;
1427 char *page_virt; 1427 char *page_virt;
1428 struct inode *ecryptfs_inode = ecryptfs_dentry->d_inode; 1428 struct inode *ecryptfs_inode = d_inode(ecryptfs_dentry);
1429 struct ecryptfs_crypt_stat *crypt_stat = 1429 struct ecryptfs_crypt_stat *crypt_stat =
1430 &ecryptfs_inode_to_private(ecryptfs_inode)->crypt_stat; 1430 &ecryptfs_inode_to_private(ecryptfs_inode)->crypt_stat;
1431 struct ecryptfs_mount_crypt_stat *mount_crypt_stat = 1431 struct ecryptfs_mount_crypt_stat *mount_crypt_stat =
diff --git a/fs/ecryptfs/dentry.c b/fs/ecryptfs/dentry.c
index 4000f6b3a750..8db0b464483f 100644
--- a/fs/ecryptfs/dentry.c
+++ b/fs/ecryptfs/dentry.c
@@ -54,11 +54,11 @@ static int ecryptfs_d_revalidate(struct dentry *dentry, unsigned int flags)
54 return -ECHILD; 54 return -ECHILD;
55 55
56 rc = lower_dentry->d_op->d_revalidate(lower_dentry, flags); 56 rc = lower_dentry->d_op->d_revalidate(lower_dentry, flags);
57 if (dentry->d_inode) { 57 if (d_really_is_positive(dentry)) {
58 struct inode *lower_inode = 58 struct inode *lower_inode =
59 ecryptfs_inode_to_lower(dentry->d_inode); 59 ecryptfs_inode_to_lower(d_inode(dentry));
60 60
61 fsstack_copy_attr_all(dentry->d_inode, lower_inode); 61 fsstack_copy_attr_all(d_inode(dentry), lower_inode);
62 } 62 }
63 return rc; 63 return rc;
64} 64}
diff --git a/fs/ecryptfs/file.c b/fs/ecryptfs/file.c
index a65786e26b05..72afcc629d7b 100644
--- a/fs/ecryptfs/file.c
+++ b/fs/ecryptfs/file.c
@@ -130,7 +130,7 @@ struct kmem_cache *ecryptfs_file_info_cache;
130 130
131static int read_or_initialize_metadata(struct dentry *dentry) 131static int read_or_initialize_metadata(struct dentry *dentry)
132{ 132{
133 struct inode *inode = dentry->d_inode; 133 struct inode *inode = d_inode(dentry);
134 struct ecryptfs_mount_crypt_stat *mount_crypt_stat; 134 struct ecryptfs_mount_crypt_stat *mount_crypt_stat;
135 struct ecryptfs_crypt_stat *crypt_stat; 135 struct ecryptfs_crypt_stat *crypt_stat;
136 int rc; 136 int rc;
diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
index b08b5187f662..fc850b55db67 100644
--- a/fs/ecryptfs/inode.c
+++ b/fs/ecryptfs/inode.c
@@ -41,13 +41,13 @@ static struct dentry *lock_parent(struct dentry *dentry)
41 struct dentry *dir; 41 struct dentry *dir;
42 42
43 dir = dget_parent(dentry); 43 dir = dget_parent(dentry);
44 mutex_lock_nested(&(dir->d_inode->i_mutex), I_MUTEX_PARENT); 44 mutex_lock_nested(&(d_inode(dir)->i_mutex), I_MUTEX_PARENT);
45 return dir; 45 return dir;
46} 46}
47 47
48static void unlock_dir(struct dentry *dir) 48static void unlock_dir(struct dentry *dir)
49{ 49{
50 mutex_unlock(&dir->d_inode->i_mutex); 50 mutex_unlock(&d_inode(dir)->i_mutex);
51 dput(dir); 51 dput(dir);
52} 52}
53 53
@@ -131,7 +131,7 @@ struct inode *ecryptfs_get_inode(struct inode *lower_inode,
131static int ecryptfs_interpose(struct dentry *lower_dentry, 131static int ecryptfs_interpose(struct dentry *lower_dentry,
132 struct dentry *dentry, struct super_block *sb) 132 struct dentry *dentry, struct super_block *sb)
133{ 133{
134 struct inode *inode = ecryptfs_get_inode(lower_dentry->d_inode, sb); 134 struct inode *inode = ecryptfs_get_inode(d_inode(lower_dentry), sb);
135 135
136 if (IS_ERR(inode)) 136 if (IS_ERR(inode))
137 return PTR_ERR(inode); 137 return PTR_ERR(inode);
@@ -189,21 +189,21 @@ ecryptfs_do_create(struct inode *directory_inode,
189 189
190 lower_dentry = ecryptfs_dentry_to_lower(ecryptfs_dentry); 190 lower_dentry = ecryptfs_dentry_to_lower(ecryptfs_dentry);
191 lower_dir_dentry = lock_parent(lower_dentry); 191 lower_dir_dentry = lock_parent(lower_dentry);
192 rc = vfs_create(lower_dir_dentry->d_inode, lower_dentry, mode, true); 192 rc = vfs_create(d_inode(lower_dir_dentry), lower_dentry, mode, true);
193 if (rc) { 193 if (rc) {
194 printk(KERN_ERR "%s: Failure to create dentry in lower fs; " 194 printk(KERN_ERR "%s: Failure to create dentry in lower fs; "
195 "rc = [%d]\n", __func__, rc); 195 "rc = [%d]\n", __func__, rc);
196 inode = ERR_PTR(rc); 196 inode = ERR_PTR(rc);
197 goto out_lock; 197 goto out_lock;
198 } 198 }
199 inode = __ecryptfs_get_inode(lower_dentry->d_inode, 199 inode = __ecryptfs_get_inode(d_inode(lower_dentry),
200 directory_inode->i_sb); 200 directory_inode->i_sb);
201 if (IS_ERR(inode)) { 201 if (IS_ERR(inode)) {
202 vfs_unlink(lower_dir_dentry->d_inode, lower_dentry, NULL); 202 vfs_unlink(d_inode(lower_dir_dentry), lower_dentry, NULL);
203 goto out_lock; 203 goto out_lock;
204 } 204 }
205 fsstack_copy_attr_times(directory_inode, lower_dir_dentry->d_inode); 205 fsstack_copy_attr_times(directory_inode, d_inode(lower_dir_dentry));
206 fsstack_copy_inode_size(directory_inode, lower_dir_dentry->d_inode); 206 fsstack_copy_inode_size(directory_inode, d_inode(lower_dir_dentry));
207out_lock: 207out_lock:
208 unlock_dir(lower_dir_dentry); 208 unlock_dir(lower_dir_dentry);
209 return inode; 209 return inode;
@@ -332,7 +332,7 @@ static int ecryptfs_lookup_interpose(struct dentry *dentry,
332 struct dentry *lower_dentry, 332 struct dentry *lower_dentry,
333 struct inode *dir_inode) 333 struct inode *dir_inode)
334{ 334{
335 struct inode *inode, *lower_inode = lower_dentry->d_inode; 335 struct inode *inode, *lower_inode = d_inode(lower_dentry);
336 struct ecryptfs_dentry_info *dentry_info; 336 struct ecryptfs_dentry_info *dentry_info;
337 struct vfsmount *lower_mnt; 337 struct vfsmount *lower_mnt;
338 int rc = 0; 338 int rc = 0;
@@ -347,14 +347,14 @@ static int ecryptfs_lookup_interpose(struct dentry *dentry,
347 } 347 }
348 348
349 lower_mnt = mntget(ecryptfs_dentry_to_lower_mnt(dentry->d_parent)); 349 lower_mnt = mntget(ecryptfs_dentry_to_lower_mnt(dentry->d_parent));
350 fsstack_copy_attr_atime(dir_inode, lower_dentry->d_parent->d_inode); 350 fsstack_copy_attr_atime(dir_inode, d_inode(lower_dentry->d_parent));
351 BUG_ON(!d_count(lower_dentry)); 351 BUG_ON(!d_count(lower_dentry));
352 352
353 ecryptfs_set_dentry_private(dentry, dentry_info); 353 ecryptfs_set_dentry_private(dentry, dentry_info);
354 dentry_info->lower_path.mnt = lower_mnt; 354 dentry_info->lower_path.mnt = lower_mnt;
355 dentry_info->lower_path.dentry = lower_dentry; 355 dentry_info->lower_path.dentry = lower_dentry;
356 356
357 if (!lower_dentry->d_inode) { 357 if (d_really_is_negative(lower_dentry)) {
358 /* We want to add because we couldn't find in lower */ 358 /* We want to add because we couldn't find in lower */
359 d_add(dentry, NULL); 359 d_add(dentry, NULL);
360 return 0; 360 return 0;
@@ -400,11 +400,11 @@ static struct dentry *ecryptfs_lookup(struct inode *ecryptfs_dir_inode,
400 int rc = 0; 400 int rc = 0;
401 401
402 lower_dir_dentry = ecryptfs_dentry_to_lower(ecryptfs_dentry->d_parent); 402 lower_dir_dentry = ecryptfs_dentry_to_lower(ecryptfs_dentry->d_parent);
403 mutex_lock(&lower_dir_dentry->d_inode->i_mutex); 403 mutex_lock(&d_inode(lower_dir_dentry)->i_mutex);
404 lower_dentry = lookup_one_len(ecryptfs_dentry->d_name.name, 404 lower_dentry = lookup_one_len(ecryptfs_dentry->d_name.name,
405 lower_dir_dentry, 405 lower_dir_dentry,
406 ecryptfs_dentry->d_name.len); 406 ecryptfs_dentry->d_name.len);
407 mutex_unlock(&lower_dir_dentry->d_inode->i_mutex); 407 mutex_unlock(&d_inode(lower_dir_dentry)->i_mutex);
408 if (IS_ERR(lower_dentry)) { 408 if (IS_ERR(lower_dentry)) {
409 rc = PTR_ERR(lower_dentry); 409 rc = PTR_ERR(lower_dentry);
410 ecryptfs_printk(KERN_DEBUG, "%s: lookup_one_len() returned " 410 ecryptfs_printk(KERN_DEBUG, "%s: lookup_one_len() returned "
@@ -412,7 +412,7 @@ static struct dentry *ecryptfs_lookup(struct inode *ecryptfs_dir_inode,
412 ecryptfs_dentry); 412 ecryptfs_dentry);
413 goto out; 413 goto out;
414 } 414 }
415 if (lower_dentry->d_inode) 415 if (d_really_is_positive(lower_dentry))
416 goto interpose; 416 goto interpose;
417 mount_crypt_stat = &ecryptfs_superblock_to_private( 417 mount_crypt_stat = &ecryptfs_superblock_to_private(
418 ecryptfs_dentry->d_sb)->mount_crypt_stat; 418 ecryptfs_dentry->d_sb)->mount_crypt_stat;
@@ -429,11 +429,11 @@ static struct dentry *ecryptfs_lookup(struct inode *ecryptfs_dir_inode,
429 "filename; rc = [%d]\n", __func__, rc); 429 "filename; rc = [%d]\n", __func__, rc);
430 goto out; 430 goto out;
431 } 431 }
432 mutex_lock(&lower_dir_dentry->d_inode->i_mutex); 432 mutex_lock(&d_inode(lower_dir_dentry)->i_mutex);
433 lower_dentry = lookup_one_len(encrypted_and_encoded_name, 433 lower_dentry = lookup_one_len(encrypted_and_encoded_name,
434 lower_dir_dentry, 434 lower_dir_dentry,
435 encrypted_and_encoded_name_size); 435 encrypted_and_encoded_name_size);
436 mutex_unlock(&lower_dir_dentry->d_inode->i_mutex); 436 mutex_unlock(&d_inode(lower_dir_dentry)->i_mutex);
437 if (IS_ERR(lower_dentry)) { 437 if (IS_ERR(lower_dentry)) {
438 rc = PTR_ERR(lower_dentry); 438 rc = PTR_ERR(lower_dentry);
439 ecryptfs_printk(KERN_DEBUG, "%s: lookup_one_len() returned " 439 ecryptfs_printk(KERN_DEBUG, "%s: lookup_one_len() returned "
@@ -458,24 +458,24 @@ static int ecryptfs_link(struct dentry *old_dentry, struct inode *dir,
458 u64 file_size_save; 458 u64 file_size_save;
459 int rc; 459 int rc;
460 460
461 file_size_save = i_size_read(old_dentry->d_inode); 461 file_size_save = i_size_read(d_inode(old_dentry));
462 lower_old_dentry = ecryptfs_dentry_to_lower(old_dentry); 462 lower_old_dentry = ecryptfs_dentry_to_lower(old_dentry);
463 lower_new_dentry = ecryptfs_dentry_to_lower(new_dentry); 463 lower_new_dentry = ecryptfs_dentry_to_lower(new_dentry);
464 dget(lower_old_dentry); 464 dget(lower_old_dentry);
465 dget(lower_new_dentry); 465 dget(lower_new_dentry);
466 lower_dir_dentry = lock_parent(lower_new_dentry); 466 lower_dir_dentry = lock_parent(lower_new_dentry);
467 rc = vfs_link(lower_old_dentry, lower_dir_dentry->d_inode, 467 rc = vfs_link(lower_old_dentry, d_inode(lower_dir_dentry),
468 lower_new_dentry, NULL); 468 lower_new_dentry, NULL);
469 if (rc || !lower_new_dentry->d_inode) 469 if (rc || d_really_is_negative(lower_new_dentry))
470 goto out_lock; 470 goto out_lock;
471 rc = ecryptfs_interpose(lower_new_dentry, new_dentry, dir->i_sb); 471 rc = ecryptfs_interpose(lower_new_dentry, new_dentry, dir->i_sb);
472 if (rc) 472 if (rc)
473 goto out_lock; 473 goto out_lock;
474 fsstack_copy_attr_times(dir, lower_dir_dentry->d_inode); 474 fsstack_copy_attr_times(dir, d_inode(lower_dir_dentry));
475 fsstack_copy_inode_size(dir, lower_dir_dentry->d_inode); 475 fsstack_copy_inode_size(dir, d_inode(lower_dir_dentry));
476 set_nlink(old_dentry->d_inode, 476 set_nlink(d_inode(old_dentry),
477 ecryptfs_inode_to_lower(old_dentry->d_inode)->i_nlink); 477 ecryptfs_inode_to_lower(d_inode(old_dentry))->i_nlink);
478 i_size_write(new_dentry->d_inode, file_size_save); 478 i_size_write(d_inode(new_dentry), file_size_save);
479out_lock: 479out_lock:
480 unlock_dir(lower_dir_dentry); 480 unlock_dir(lower_dir_dentry);
481 dput(lower_new_dentry); 481 dput(lower_new_dentry);
@@ -485,7 +485,7 @@ out_lock:
485 485
486static int ecryptfs_unlink(struct inode *dir, struct dentry *dentry) 486static int ecryptfs_unlink(struct inode *dir, struct dentry *dentry)
487{ 487{
488 return ecryptfs_do_unlink(dir, dentry, dentry->d_inode); 488 return ecryptfs_do_unlink(dir, dentry, d_inode(dentry));
489} 489}
490 490
491static int ecryptfs_symlink(struct inode *dir, struct dentry *dentry, 491static int ecryptfs_symlink(struct inode *dir, struct dentry *dentry,
@@ -510,20 +510,20 @@ static int ecryptfs_symlink(struct inode *dir, struct dentry *dentry,
510 strlen(symname)); 510 strlen(symname));
511 if (rc) 511 if (rc)
512 goto out_lock; 512 goto out_lock;
513 rc = vfs_symlink(lower_dir_dentry->d_inode, lower_dentry, 513 rc = vfs_symlink(d_inode(lower_dir_dentry), lower_dentry,
514 encoded_symname); 514 encoded_symname);
515 kfree(encoded_symname); 515 kfree(encoded_symname);
516 if (rc || !lower_dentry->d_inode) 516 if (rc || d_really_is_negative(lower_dentry))
517 goto out_lock; 517 goto out_lock;
518 rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb); 518 rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb);
519 if (rc) 519 if (rc)
520 goto out_lock; 520 goto out_lock;
521 fsstack_copy_attr_times(dir, lower_dir_dentry->d_inode); 521 fsstack_copy_attr_times(dir, d_inode(lower_dir_dentry));
522 fsstack_copy_inode_size(dir, lower_dir_dentry->d_inode); 522 fsstack_copy_inode_size(dir, d_inode(lower_dir_dentry));
523out_lock: 523out_lock:
524 unlock_dir(lower_dir_dentry); 524 unlock_dir(lower_dir_dentry);
525 dput(lower_dentry); 525 dput(lower_dentry);
526 if (!dentry->d_inode) 526 if (d_really_is_negative(dentry))
527 d_drop(dentry); 527 d_drop(dentry);
528 return rc; 528 return rc;
529} 529}
@@ -536,18 +536,18 @@ static int ecryptfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode
536 536
537 lower_dentry = ecryptfs_dentry_to_lower(dentry); 537 lower_dentry = ecryptfs_dentry_to_lower(dentry);
538 lower_dir_dentry = lock_parent(lower_dentry); 538 lower_dir_dentry = lock_parent(lower_dentry);
539 rc = vfs_mkdir(lower_dir_dentry->d_inode, lower_dentry, mode); 539 rc = vfs_mkdir(d_inode(lower_dir_dentry), lower_dentry, mode);
540 if (rc || !lower_dentry->d_inode) 540 if (rc || d_really_is_negative(lower_dentry))
541 goto out; 541 goto out;
542 rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb); 542 rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb);
543 if (rc) 543 if (rc)
544 goto out; 544 goto out;
545 fsstack_copy_attr_times(dir, lower_dir_dentry->d_inode); 545 fsstack_copy_attr_times(dir, d_inode(lower_dir_dentry));
546 fsstack_copy_inode_size(dir, lower_dir_dentry->d_inode); 546 fsstack_copy_inode_size(dir, d_inode(lower_dir_dentry));
547 set_nlink(dir, lower_dir_dentry->d_inode->i_nlink); 547 set_nlink(dir, d_inode(lower_dir_dentry)->i_nlink);
548out: 548out:
549 unlock_dir(lower_dir_dentry); 549 unlock_dir(lower_dir_dentry);
550 if (!dentry->d_inode) 550 if (d_really_is_negative(dentry))
551 d_drop(dentry); 551 d_drop(dentry);
552 return rc; 552 return rc;
553} 553}
@@ -562,12 +562,12 @@ static int ecryptfs_rmdir(struct inode *dir, struct dentry *dentry)
562 dget(dentry); 562 dget(dentry);
563 lower_dir_dentry = lock_parent(lower_dentry); 563 lower_dir_dentry = lock_parent(lower_dentry);
564 dget(lower_dentry); 564 dget(lower_dentry);
565 rc = vfs_rmdir(lower_dir_dentry->d_inode, lower_dentry); 565 rc = vfs_rmdir(d_inode(lower_dir_dentry), lower_dentry);
566 dput(lower_dentry); 566 dput(lower_dentry);
567 if (!rc && dentry->d_inode) 567 if (!rc && d_really_is_positive(dentry))
568 clear_nlink(dentry->d_inode); 568 clear_nlink(d_inode(dentry));
569 fsstack_copy_attr_times(dir, lower_dir_dentry->d_inode); 569 fsstack_copy_attr_times(dir, d_inode(lower_dir_dentry));
570 set_nlink(dir, lower_dir_dentry->d_inode->i_nlink); 570 set_nlink(dir, d_inode(lower_dir_dentry)->i_nlink);
571 unlock_dir(lower_dir_dentry); 571 unlock_dir(lower_dir_dentry);
572 if (!rc) 572 if (!rc)
573 d_drop(dentry); 573 d_drop(dentry);
@@ -584,17 +584,17 @@ ecryptfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev
584 584
585 lower_dentry = ecryptfs_dentry_to_lower(dentry); 585 lower_dentry = ecryptfs_dentry_to_lower(dentry);
586 lower_dir_dentry = lock_parent(lower_dentry); 586 lower_dir_dentry = lock_parent(lower_dentry);
587 rc = vfs_mknod(lower_dir_dentry->d_inode, lower_dentry, mode, dev); 587 rc = vfs_mknod(d_inode(lower_dir_dentry), lower_dentry, mode, dev);
588 if (rc || !lower_dentry->d_inode) 588 if (rc || d_really_is_negative(lower_dentry))
589 goto out; 589 goto out;
590 rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb); 590 rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb);
591 if (rc) 591 if (rc)
592 goto out; 592 goto out;
593 fsstack_copy_attr_times(dir, lower_dir_dentry->d_inode); 593 fsstack_copy_attr_times(dir, d_inode(lower_dir_dentry));
594 fsstack_copy_inode_size(dir, lower_dir_dentry->d_inode); 594 fsstack_copy_inode_size(dir, d_inode(lower_dir_dentry));
595out: 595out:
596 unlock_dir(lower_dir_dentry); 596 unlock_dir(lower_dir_dentry);
597 if (!dentry->d_inode) 597 if (d_really_is_negative(dentry))
598 d_drop(dentry); 598 d_drop(dentry);
599 return rc; 599 return rc;
600} 600}
@@ -617,7 +617,7 @@ ecryptfs_rename(struct inode *old_dir, struct dentry *old_dentry,
617 dget(lower_new_dentry); 617 dget(lower_new_dentry);
618 lower_old_dir_dentry = dget_parent(lower_old_dentry); 618 lower_old_dir_dentry = dget_parent(lower_old_dentry);
619 lower_new_dir_dentry = dget_parent(lower_new_dentry); 619 lower_new_dir_dentry = dget_parent(lower_new_dentry);
620 target_inode = new_dentry->d_inode; 620 target_inode = d_inode(new_dentry);
621 trap = lock_rename(lower_old_dir_dentry, lower_new_dir_dentry); 621 trap = lock_rename(lower_old_dir_dentry, lower_new_dir_dentry);
622 /* source should not be ancestor of target */ 622 /* source should not be ancestor of target */
623 if (trap == lower_old_dentry) { 623 if (trap == lower_old_dentry) {
@@ -629,17 +629,17 @@ ecryptfs_rename(struct inode *old_dir, struct dentry *old_dentry,
629 rc = -ENOTEMPTY; 629 rc = -ENOTEMPTY;
630 goto out_lock; 630 goto out_lock;
631 } 631 }
632 rc = vfs_rename(lower_old_dir_dentry->d_inode, lower_old_dentry, 632 rc = vfs_rename(d_inode(lower_old_dir_dentry), lower_old_dentry,
633 lower_new_dir_dentry->d_inode, lower_new_dentry, 633 d_inode(lower_new_dir_dentry), lower_new_dentry,
634 NULL, 0); 634 NULL, 0);
635 if (rc) 635 if (rc)
636 goto out_lock; 636 goto out_lock;
637 if (target_inode) 637 if (target_inode)
638 fsstack_copy_attr_all(target_inode, 638 fsstack_copy_attr_all(target_inode,
639 ecryptfs_inode_to_lower(target_inode)); 639 ecryptfs_inode_to_lower(target_inode));
640 fsstack_copy_attr_all(new_dir, lower_new_dir_dentry->d_inode); 640 fsstack_copy_attr_all(new_dir, d_inode(lower_new_dir_dentry));
641 if (new_dir != old_dir) 641 if (new_dir != old_dir)
642 fsstack_copy_attr_all(old_dir, lower_old_dir_dentry->d_inode); 642 fsstack_copy_attr_all(old_dir, d_inode(lower_old_dir_dentry));
643out_lock: 643out_lock:
644 unlock_rename(lower_old_dir_dentry, lower_new_dir_dentry); 644 unlock_rename(lower_old_dir_dentry, lower_new_dir_dentry);
645 dput(lower_new_dir_dentry); 645 dput(lower_new_dir_dentry);
@@ -662,7 +662,7 @@ static char *ecryptfs_readlink_lower(struct dentry *dentry, size_t *bufsiz)
662 return ERR_PTR(-ENOMEM); 662 return ERR_PTR(-ENOMEM);
663 old_fs = get_fs(); 663 old_fs = get_fs();
664 set_fs(get_ds()); 664 set_fs(get_ds());
665 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry, 665 rc = d_inode(lower_dentry)->i_op->readlink(lower_dentry,
666 (char __user *)lower_buf, 666 (char __user *)lower_buf,
667 PATH_MAX); 667 PATH_MAX);
668 set_fs(old_fs); 668 set_fs(old_fs);
@@ -681,8 +681,8 @@ static void *ecryptfs_follow_link(struct dentry *dentry, struct nameidata *nd)
681 char *buf = ecryptfs_readlink_lower(dentry, &len); 681 char *buf = ecryptfs_readlink_lower(dentry, &len);
682 if (IS_ERR(buf)) 682 if (IS_ERR(buf))
683 goto out; 683 goto out;
684 fsstack_copy_attr_atime(dentry->d_inode, 684 fsstack_copy_attr_atime(d_inode(dentry),
685 ecryptfs_dentry_to_lower(dentry)->d_inode); 685 d_inode(ecryptfs_dentry_to_lower(dentry)));
686 buf[len] = '\0'; 686 buf[len] = '\0';
687out: 687out:
688 nd_set_link(nd, buf); 688 nd_set_link(nd, buf);
@@ -738,7 +738,7 @@ static int truncate_upper(struct dentry *dentry, struct iattr *ia,
738 struct iattr *lower_ia) 738 struct iattr *lower_ia)
739{ 739{
740 int rc = 0; 740 int rc = 0;
741 struct inode *inode = dentry->d_inode; 741 struct inode *inode = d_inode(dentry);
742 struct ecryptfs_crypt_stat *crypt_stat; 742 struct ecryptfs_crypt_stat *crypt_stat;
743 loff_t i_size = i_size_read(inode); 743 loff_t i_size = i_size_read(inode);
744 loff_t lower_size_before_truncate; 744 loff_t lower_size_before_truncate;
@@ -751,7 +751,7 @@ static int truncate_upper(struct dentry *dentry, struct iattr *ia,
751 rc = ecryptfs_get_lower_file(dentry, inode); 751 rc = ecryptfs_get_lower_file(dentry, inode);
752 if (rc) 752 if (rc)
753 return rc; 753 return rc;
754 crypt_stat = &ecryptfs_inode_to_private(dentry->d_inode)->crypt_stat; 754 crypt_stat = &ecryptfs_inode_to_private(d_inode(dentry))->crypt_stat;
755 /* Switch on growing or shrinking file */ 755 /* Switch on growing or shrinking file */
756 if (ia->ia_size > i_size) { 756 if (ia->ia_size > i_size) {
757 char zero[] = { 0x00 }; 757 char zero[] = { 0x00 };
@@ -858,7 +858,7 @@ int ecryptfs_truncate(struct dentry *dentry, loff_t new_length)
858 struct iattr lower_ia = { .ia_valid = 0 }; 858 struct iattr lower_ia = { .ia_valid = 0 };
859 int rc; 859 int rc;
860 860
861 rc = ecryptfs_inode_newsize_ok(dentry->d_inode, new_length); 861 rc = ecryptfs_inode_newsize_ok(d_inode(dentry), new_length);
862 if (rc) 862 if (rc)
863 return rc; 863 return rc;
864 864
@@ -866,9 +866,9 @@ int ecryptfs_truncate(struct dentry *dentry, loff_t new_length)
866 if (!rc && lower_ia.ia_valid & ATTR_SIZE) { 866 if (!rc && lower_ia.ia_valid & ATTR_SIZE) {
867 struct dentry *lower_dentry = ecryptfs_dentry_to_lower(dentry); 867 struct dentry *lower_dentry = ecryptfs_dentry_to_lower(dentry);
868 868
869 mutex_lock(&lower_dentry->d_inode->i_mutex); 869 mutex_lock(&d_inode(lower_dentry)->i_mutex);
870 rc = notify_change(lower_dentry, &lower_ia, NULL); 870 rc = notify_change(lower_dentry, &lower_ia, NULL);
871 mutex_unlock(&lower_dentry->d_inode->i_mutex); 871 mutex_unlock(&d_inode(lower_dentry)->i_mutex);
872 } 872 }
873 return rc; 873 return rc;
874} 874}
@@ -900,10 +900,10 @@ static int ecryptfs_setattr(struct dentry *dentry, struct iattr *ia)
900 struct inode *lower_inode; 900 struct inode *lower_inode;
901 struct ecryptfs_crypt_stat *crypt_stat; 901 struct ecryptfs_crypt_stat *crypt_stat;
902 902
903 crypt_stat = &ecryptfs_inode_to_private(dentry->d_inode)->crypt_stat; 903 crypt_stat = &ecryptfs_inode_to_private(d_inode(dentry))->crypt_stat;
904 if (!(crypt_stat->flags & ECRYPTFS_STRUCT_INITIALIZED)) 904 if (!(crypt_stat->flags & ECRYPTFS_STRUCT_INITIALIZED))
905 ecryptfs_init_crypt_stat(crypt_stat); 905 ecryptfs_init_crypt_stat(crypt_stat);
906 inode = dentry->d_inode; 906 inode = d_inode(dentry);
907 lower_inode = ecryptfs_inode_to_lower(inode); 907 lower_inode = ecryptfs_inode_to_lower(inode);
908 lower_dentry = ecryptfs_dentry_to_lower(dentry); 908 lower_dentry = ecryptfs_dentry_to_lower(dentry);
909 mutex_lock(&crypt_stat->cs_mutex); 909 mutex_lock(&crypt_stat->cs_mutex);
@@ -967,9 +967,9 @@ static int ecryptfs_setattr(struct dentry *dentry, struct iattr *ia)
967 if (lower_ia.ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID)) 967 if (lower_ia.ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
968 lower_ia.ia_valid &= ~ATTR_MODE; 968 lower_ia.ia_valid &= ~ATTR_MODE;
969 969
970 mutex_lock(&lower_dentry->d_inode->i_mutex); 970 mutex_lock(&d_inode(lower_dentry)->i_mutex);
971 rc = notify_change(lower_dentry, &lower_ia, NULL); 971 rc = notify_change(lower_dentry, &lower_ia, NULL);
972 mutex_unlock(&lower_dentry->d_inode->i_mutex); 972 mutex_unlock(&d_inode(lower_dentry)->i_mutex);
973out: 973out:
974 fsstack_copy_attr_all(inode, lower_inode); 974 fsstack_copy_attr_all(inode, lower_inode);
975 return rc; 975 return rc;
@@ -983,7 +983,7 @@ static int ecryptfs_getattr_link(struct vfsmount *mnt, struct dentry *dentry,
983 983
984 mount_crypt_stat = &ecryptfs_superblock_to_private( 984 mount_crypt_stat = &ecryptfs_superblock_to_private(
985 dentry->d_sb)->mount_crypt_stat; 985 dentry->d_sb)->mount_crypt_stat;
986 generic_fillattr(dentry->d_inode, stat); 986 generic_fillattr(d_inode(dentry), stat);
987 if (mount_crypt_stat->flags & ECRYPTFS_GLOBAL_ENCRYPT_FILENAMES) { 987 if (mount_crypt_stat->flags & ECRYPTFS_GLOBAL_ENCRYPT_FILENAMES) {
988 char *target; 988 char *target;
989 size_t targetsiz; 989 size_t targetsiz;
@@ -1007,9 +1007,9 @@ static int ecryptfs_getattr(struct vfsmount *mnt, struct dentry *dentry,
1007 1007
1008 rc = vfs_getattr(ecryptfs_dentry_to_lower_path(dentry), &lower_stat); 1008 rc = vfs_getattr(ecryptfs_dentry_to_lower_path(dentry), &lower_stat);
1009 if (!rc) { 1009 if (!rc) {
1010 fsstack_copy_attr_all(dentry->d_inode, 1010 fsstack_copy_attr_all(d_inode(dentry),
1011 ecryptfs_inode_to_lower(dentry->d_inode)); 1011 ecryptfs_inode_to_lower(d_inode(dentry)));
1012 generic_fillattr(dentry->d_inode, stat); 1012 generic_fillattr(d_inode(dentry), stat);
1013 stat->blocks = lower_stat.blocks; 1013 stat->blocks = lower_stat.blocks;
1014 } 1014 }
1015 return rc; 1015 return rc;
@@ -1023,14 +1023,14 @@ ecryptfs_setxattr(struct dentry *dentry, const char *name, const void *value,
1023 struct dentry *lower_dentry; 1023 struct dentry *lower_dentry;
1024 1024
1025 lower_dentry = ecryptfs_dentry_to_lower(dentry); 1025 lower_dentry = ecryptfs_dentry_to_lower(dentry);
1026 if (!lower_dentry->d_inode->i_op->setxattr) { 1026 if (!d_inode(lower_dentry)->i_op->setxattr) {
1027 rc = -EOPNOTSUPP; 1027 rc = -EOPNOTSUPP;
1028 goto out; 1028 goto out;
1029 } 1029 }
1030 1030
1031 rc = vfs_setxattr(lower_dentry, name, value, size, flags); 1031 rc = vfs_setxattr(lower_dentry, name, value, size, flags);
1032 if (!rc && dentry->d_inode) 1032 if (!rc && d_really_is_positive(dentry))
1033 fsstack_copy_attr_all(dentry->d_inode, lower_dentry->d_inode); 1033 fsstack_copy_attr_all(d_inode(dentry), d_inode(lower_dentry));
1034out: 1034out:
1035 return rc; 1035 return rc;
1036} 1036}
@@ -1041,14 +1041,14 @@ ecryptfs_getxattr_lower(struct dentry *lower_dentry, const char *name,
1041{ 1041{
1042 int rc = 0; 1042 int rc = 0;
1043 1043
1044 if (!lower_dentry->d_inode->i_op->getxattr) { 1044 if (!d_inode(lower_dentry)->i_op->getxattr) {
1045 rc = -EOPNOTSUPP; 1045 rc = -EOPNOTSUPP;
1046 goto out; 1046 goto out;
1047 } 1047 }
1048 mutex_lock(&lower_dentry->d_inode->i_mutex); 1048 mutex_lock(&d_inode(lower_dentry)->i_mutex);
1049 rc = lower_dentry->d_inode->i_op->getxattr(lower_dentry, name, value, 1049 rc = d_inode(lower_dentry)->i_op->getxattr(lower_dentry, name, value,
1050 size); 1050 size);
1051 mutex_unlock(&lower_dentry->d_inode->i_mutex); 1051 mutex_unlock(&d_inode(lower_dentry)->i_mutex);
1052out: 1052out:
1053 return rc; 1053 return rc;
1054} 1054}
@@ -1068,13 +1068,13 @@ ecryptfs_listxattr(struct dentry *dentry, char *list, size_t size)
1068 struct dentry *lower_dentry; 1068 struct dentry *lower_dentry;
1069 1069
1070 lower_dentry = ecryptfs_dentry_to_lower(dentry); 1070 lower_dentry = ecryptfs_dentry_to_lower(dentry);
1071 if (!lower_dentry->d_inode->i_op->listxattr) { 1071 if (!d_inode(lower_dentry)->i_op->listxattr) {
1072 rc = -EOPNOTSUPP; 1072 rc = -EOPNOTSUPP;
1073 goto out; 1073 goto out;
1074 } 1074 }
1075 mutex_lock(&lower_dentry->d_inode->i_mutex); 1075 mutex_lock(&d_inode(lower_dentry)->i_mutex);
1076 rc = lower_dentry->d_inode->i_op->listxattr(lower_dentry, list, size); 1076 rc = d_inode(lower_dentry)->i_op->listxattr(lower_dentry, list, size);
1077 mutex_unlock(&lower_dentry->d_inode->i_mutex); 1077 mutex_unlock(&d_inode(lower_dentry)->i_mutex);
1078out: 1078out:
1079 return rc; 1079 return rc;
1080} 1080}
@@ -1085,13 +1085,13 @@ static int ecryptfs_removexattr(struct dentry *dentry, const char *name)
1085 struct dentry *lower_dentry; 1085 struct dentry *lower_dentry;
1086 1086
1087 lower_dentry = ecryptfs_dentry_to_lower(dentry); 1087 lower_dentry = ecryptfs_dentry_to_lower(dentry);
1088 if (!lower_dentry->d_inode->i_op->removexattr) { 1088 if (!d_inode(lower_dentry)->i_op->removexattr) {
1089 rc = -EOPNOTSUPP; 1089 rc = -EOPNOTSUPP;
1090 goto out; 1090 goto out;
1091 } 1091 }
1092 mutex_lock(&lower_dentry->d_inode->i_mutex); 1092 mutex_lock(&d_inode(lower_dentry)->i_mutex);
1093 rc = lower_dentry->d_inode->i_op->removexattr(lower_dentry, name); 1093 rc = d_inode(lower_dentry)->i_op->removexattr(lower_dentry, name);
1094 mutex_unlock(&lower_dentry->d_inode->i_mutex); 1094 mutex_unlock(&d_inode(lower_dentry)->i_mutex);
1095out: 1095out:
1096 return rc; 1096 return rc;
1097} 1097}
diff --git a/fs/ecryptfs/kthread.c b/fs/ecryptfs/kthread.c
index f1ea610362c6..866bb18efefe 100644
--- a/fs/ecryptfs/kthread.c
+++ b/fs/ecryptfs/kthread.c
@@ -144,7 +144,7 @@ int ecryptfs_privileged_open(struct file **lower_file,
144 /* Corresponding dput() and mntput() are done when the 144 /* Corresponding dput() and mntput() are done when the
145 * lower file is fput() when all eCryptfs files for the inode are 145 * lower file is fput() when all eCryptfs files for the inode are
146 * released. */ 146 * released. */
147 flags |= IS_RDONLY(lower_dentry->d_inode) ? O_RDONLY : O_RDWR; 147 flags |= IS_RDONLY(d_inode(lower_dentry)) ? O_RDONLY : O_RDWR;
148 (*lower_file) = dentry_open(&req.path, flags, cred); 148 (*lower_file) = dentry_open(&req.path, flags, cred);
149 if (!IS_ERR(*lower_file)) 149 if (!IS_ERR(*lower_file))
150 goto out; 150 goto out;
diff --git a/fs/ecryptfs/main.c b/fs/ecryptfs/main.c
index c095d3264259..4f4d0474bee9 100644
--- a/fs/ecryptfs/main.c
+++ b/fs/ecryptfs/main.c
@@ -546,11 +546,11 @@ static struct dentry *ecryptfs_mount(struct file_system_type *fs_type, int flags
546 goto out_free; 546 goto out_free;
547 } 547 }
548 548
549 if (check_ruid && !uid_eq(path.dentry->d_inode->i_uid, current_uid())) { 549 if (check_ruid && !uid_eq(d_inode(path.dentry)->i_uid, current_uid())) {
550 rc = -EPERM; 550 rc = -EPERM;
551 printk(KERN_ERR "Mount of device (uid: %d) not owned by " 551 printk(KERN_ERR "Mount of device (uid: %d) not owned by "
552 "requested user (uid: %d)\n", 552 "requested user (uid: %d)\n",
553 i_uid_read(path.dentry->d_inode), 553 i_uid_read(d_inode(path.dentry)),
554 from_kuid(&init_user_ns, current_uid())); 554 from_kuid(&init_user_ns, current_uid()));
555 goto out_free; 555 goto out_free;
556 } 556 }
@@ -584,7 +584,7 @@ static struct dentry *ecryptfs_mount(struct file_system_type *fs_type, int flags
584 goto out_free; 584 goto out_free;
585 } 585 }
586 586
587 inode = ecryptfs_get_inode(path.dentry->d_inode, s); 587 inode = ecryptfs_get_inode(d_inode(path.dentry), s);
588 rc = PTR_ERR(inode); 588 rc = PTR_ERR(inode);
589 if (IS_ERR(inode)) 589 if (IS_ERR(inode))
590 goto out_free; 590 goto out_free;
diff --git a/fs/ecryptfs/mmap.c b/fs/ecryptfs/mmap.c
index 4626976794e7..cf208522998e 100644
--- a/fs/ecryptfs/mmap.c
+++ b/fs/ecryptfs/mmap.c
@@ -420,7 +420,7 @@ static int ecryptfs_write_inode_size_to_xattr(struct inode *ecryptfs_inode)
420 void *xattr_virt; 420 void *xattr_virt;
421 struct dentry *lower_dentry = 421 struct dentry *lower_dentry =
422 ecryptfs_inode_to_private(ecryptfs_inode)->lower_file->f_path.dentry; 422 ecryptfs_inode_to_private(ecryptfs_inode)->lower_file->f_path.dentry;
423 struct inode *lower_inode = lower_dentry->d_inode; 423 struct inode *lower_inode = d_inode(lower_dentry);
424 int rc; 424 int rc;
425 425
426 if (!lower_inode->i_op->getxattr || !lower_inode->i_op->setxattr) { 426 if (!lower_inode->i_op->getxattr || !lower_inode->i_op->setxattr) {
diff --git a/fs/efivarfs/inode.c b/fs/efivarfs/inode.c
index 07ab49745e31..3381b9da9ee6 100644
--- a/fs/efivarfs/inode.c
+++ b/fs/efivarfs/inode.c
@@ -145,12 +145,12 @@ out:
145 145
146static int efivarfs_unlink(struct inode *dir, struct dentry *dentry) 146static int efivarfs_unlink(struct inode *dir, struct dentry *dentry)
147{ 147{
148 struct efivar_entry *var = dentry->d_inode->i_private; 148 struct efivar_entry *var = d_inode(dentry)->i_private;
149 149
150 if (efivar_entry_delete(var)) 150 if (efivar_entry_delete(var))
151 return -EINVAL; 151 return -EINVAL;
152 152
153 drop_nlink(dentry->d_inode); 153 drop_nlink(d_inode(dentry));
154 dput(dentry); 154 dput(dentry);
155 return 0; 155 return 0;
156}; 156};
diff --git a/fs/efivarfs/super.c b/fs/efivarfs/super.c
index ddbce42548c9..59fedbcf8798 100644
--- a/fs/efivarfs/super.c
+++ b/fs/efivarfs/super.c
@@ -144,7 +144,7 @@ static int efivarfs_callback(efi_char16_t *name16, efi_guid_t vendor,
144 144
145 name[len + EFI_VARIABLE_GUID_LEN+1] = '\0'; 145 name[len + EFI_VARIABLE_GUID_LEN+1] = '\0';
146 146
147 inode = efivarfs_get_inode(sb, root->d_inode, S_IFREG | 0644, 0); 147 inode = efivarfs_get_inode(sb, d_inode(root), S_IFREG | 0644, 0);
148 if (!inode) 148 if (!inode)
149 goto fail_name; 149 goto fail_name;
150 150
diff --git a/fs/efs/namei.c b/fs/efs/namei.c
index bbee8f063dfa..40ba9cc41bf7 100644
--- a/fs/efs/namei.c
+++ b/fs/efs/namei.c
@@ -111,9 +111,9 @@ struct dentry *efs_get_parent(struct dentry *child)
111 struct dentry *parent = ERR_PTR(-ENOENT); 111 struct dentry *parent = ERR_PTR(-ENOENT);
112 efs_ino_t ino; 112 efs_ino_t ino;
113 113
114 ino = efs_find_entry(child->d_inode, "..", 2); 114 ino = efs_find_entry(d_inode(child), "..", 2);
115 if (ino) 115 if (ino)
116 parent = d_obtain_alias(efs_iget(child->d_inode->i_sb, ino)); 116 parent = d_obtain_alias(efs_iget(d_inode(child)->i_sb, ino));
117 117
118 return parent; 118 return parent;
119} 119}
diff --git a/fs/exofs/dir.c b/fs/exofs/dir.c
index d7defd557601..4deb0b05b011 100644
--- a/fs/exofs/dir.c
+++ b/fs/exofs/dir.c
@@ -379,7 +379,7 @@ ino_t exofs_parent_ino(struct dentry *child)
379 struct exofs_dir_entry *de; 379 struct exofs_dir_entry *de;
380 ino_t ino; 380 ino_t ino;
381 381
382 de = exofs_dotdot(child->d_inode, &page); 382 de = exofs_dotdot(d_inode(child), &page);
383 if (!de) 383 if (!de)
384 return 0; 384 return 0;
385 385
@@ -429,7 +429,7 @@ int exofs_set_link(struct inode *dir, struct exofs_dir_entry *de,
429 429
430int exofs_add_link(struct dentry *dentry, struct inode *inode) 430int exofs_add_link(struct dentry *dentry, struct inode *inode)
431{ 431{
432 struct inode *dir = dentry->d_parent->d_inode; 432 struct inode *dir = d_inode(dentry->d_parent);
433 const unsigned char *name = dentry->d_name.name; 433 const unsigned char *name = dentry->d_name.name;
434 int namelen = dentry->d_name.len; 434 int namelen = dentry->d_name.len;
435 unsigned chunk_size = exofs_chunk_size(dir); 435 unsigned chunk_size = exofs_chunk_size(dir);
diff --git a/fs/exofs/inode.c b/fs/exofs/inode.c
index 35073aaec6e0..786e4cc8c889 100644
--- a/fs/exofs/inode.c
+++ b/fs/exofs/inode.c
@@ -1028,7 +1028,7 @@ static int _do_truncate(struct inode *inode, loff_t newsize)
1028 */ 1028 */
1029int exofs_setattr(struct dentry *dentry, struct iattr *iattr) 1029int exofs_setattr(struct dentry *dentry, struct iattr *iattr)
1030{ 1030{
1031 struct inode *inode = dentry->d_inode; 1031 struct inode *inode = d_inode(dentry);
1032 int error; 1032 int error;
1033 1033
1034 /* if we are about to modify an object, and it hasn't been 1034 /* if we are about to modify an object, and it hasn't been
diff --git a/fs/exofs/namei.c b/fs/exofs/namei.c
index 28907460e8fa..5ae25e431191 100644
--- a/fs/exofs/namei.c
+++ b/fs/exofs/namei.c
@@ -141,7 +141,7 @@ out_fail:
141static int exofs_link(struct dentry *old_dentry, struct inode *dir, 141static int exofs_link(struct dentry *old_dentry, struct inode *dir,
142 struct dentry *dentry) 142 struct dentry *dentry)
143{ 143{
144 struct inode *inode = old_dentry->d_inode; 144 struct inode *inode = d_inode(old_dentry);
145 145
146 inode->i_ctime = CURRENT_TIME; 146 inode->i_ctime = CURRENT_TIME;
147 inode_inc_link_count(inode); 147 inode_inc_link_count(inode);
@@ -191,7 +191,7 @@ out_dir:
191 191
192static int exofs_unlink(struct inode *dir, struct dentry *dentry) 192static int exofs_unlink(struct inode *dir, struct dentry *dentry)
193{ 193{
194 struct inode *inode = dentry->d_inode; 194 struct inode *inode = d_inode(dentry);
195 struct exofs_dir_entry *de; 195 struct exofs_dir_entry *de;
196 struct page *page; 196 struct page *page;
197 int err = -ENOENT; 197 int err = -ENOENT;
@@ -213,7 +213,7 @@ out:
213 213
214static int exofs_rmdir(struct inode *dir, struct dentry *dentry) 214static int exofs_rmdir(struct inode *dir, struct dentry *dentry)
215{ 215{
216 struct inode *inode = dentry->d_inode; 216 struct inode *inode = d_inode(dentry);
217 int err = -ENOTEMPTY; 217 int err = -ENOTEMPTY;
218 218
219 if (exofs_empty_dir(inode)) { 219 if (exofs_empty_dir(inode)) {
@@ -230,8 +230,8 @@ static int exofs_rmdir(struct inode *dir, struct dentry *dentry)
230static int exofs_rename(struct inode *old_dir, struct dentry *old_dentry, 230static int exofs_rename(struct inode *old_dir, struct dentry *old_dentry,
231 struct inode *new_dir, struct dentry *new_dentry) 231 struct inode *new_dir, struct dentry *new_dentry)
232{ 232{
233 struct inode *old_inode = old_dentry->d_inode; 233 struct inode *old_inode = d_inode(old_dentry);
234 struct inode *new_inode = new_dentry->d_inode; 234 struct inode *new_inode = d_inode(new_dentry);
235 struct page *dir_page = NULL; 235 struct page *dir_page = NULL;
236 struct exofs_dir_entry *dir_de = NULL; 236 struct exofs_dir_entry *dir_de = NULL;
237 struct page *old_page; 237 struct page *old_page;
diff --git a/fs/exofs/super.c b/fs/exofs/super.c
index fcc2e565f540..b795c567b5e1 100644
--- a/fs/exofs/super.c
+++ b/fs/exofs/super.c
@@ -958,7 +958,7 @@ static struct dentry *exofs_get_parent(struct dentry *child)
958 if (!ino) 958 if (!ino)
959 return ERR_PTR(-ESTALE); 959 return ERR_PTR(-ESTALE);
960 960
961 return d_obtain_alias(exofs_iget(child->d_inode->i_sb, ino)); 961 return d_obtain_alias(exofs_iget(d_inode(child)->i_sb, ino));
962} 962}
963 963
964static struct inode *exofs_nfs_get_inode(struct super_block *sb, 964static struct inode *exofs_nfs_get_inode(struct super_block *sb,
diff --git a/fs/exofs/symlink.c b/fs/exofs/symlink.c
index 832e2624b80b..6f6f3a4c1365 100644
--- a/fs/exofs/symlink.c
+++ b/fs/exofs/symlink.c
@@ -37,7 +37,7 @@
37 37
38static void *exofs_follow_link(struct dentry *dentry, struct nameidata *nd) 38static void *exofs_follow_link(struct dentry *dentry, struct nameidata *nd)
39{ 39{
40 struct exofs_i_info *oi = exofs_i(dentry->d_inode); 40 struct exofs_i_info *oi = exofs_i(d_inode(dentry));
41 41
42 nd_set_link(nd, (char *)oi->i_data); 42 nd_set_link(nd, (char *)oi->i_data);
43 return NULL; 43 return NULL;
diff --git a/fs/ext2/dir.c b/fs/ext2/dir.c
index 6e1d4ab09d72..796b491e6978 100644
--- a/fs/ext2/dir.c
+++ b/fs/ext2/dir.c
@@ -486,7 +486,7 @@ void ext2_set_link(struct inode *dir, struct ext2_dir_entry_2 *de,
486 */ 486 */
487int ext2_add_link (struct dentry *dentry, struct inode *inode) 487int ext2_add_link (struct dentry *dentry, struct inode *inode)
488{ 488{
489 struct inode *dir = dentry->d_parent->d_inode; 489 struct inode *dir = d_inode(dentry->d_parent);
490 const char *name = dentry->d_name.name; 490 const char *name = dentry->d_name.name;
491 int namelen = dentry->d_name.len; 491 int namelen = dentry->d_name.len;
492 unsigned chunk_size = ext2_chunk_size(dir); 492 unsigned chunk_size = ext2_chunk_size(dir);
diff --git a/fs/ext2/ialloc.c b/fs/ext2/ialloc.c
index 6c14bb8322fa..5c04a0ddea80 100644
--- a/fs/ext2/ialloc.c
+++ b/fs/ext2/ialloc.c
@@ -278,7 +278,7 @@ static int find_group_orlov(struct super_block *sb, struct inode *parent)
278 avefreeb = free_blocks / ngroups; 278 avefreeb = free_blocks / ngroups;
279 ndirs = percpu_counter_read_positive(&sbi->s_dirs_counter); 279 ndirs = percpu_counter_read_positive(&sbi->s_dirs_counter);
280 280
281 if ((parent == sb->s_root->d_inode) || 281 if ((parent == d_inode(sb->s_root)) ||
282 (EXT2_I(parent)->i_flags & EXT2_TOPDIR_FL)) { 282 (EXT2_I(parent)->i_flags & EXT2_TOPDIR_FL)) {
283 struct ext2_group_desc *best_desc = NULL; 283 struct ext2_group_desc *best_desc = NULL;
284 int best_ndir = inodes_per_group; 284 int best_ndir = inodes_per_group;
diff --git a/fs/ext2/inode.c b/fs/ext2/inode.c
index 5d9213963fae..f460ae36d5b7 100644
--- a/fs/ext2/inode.c
+++ b/fs/ext2/inode.c
@@ -1544,7 +1544,7 @@ int ext2_write_inode(struct inode *inode, struct writeback_control *wbc)
1544 1544
1545int ext2_setattr(struct dentry *dentry, struct iattr *iattr) 1545int ext2_setattr(struct dentry *dentry, struct iattr *iattr)
1546{ 1546{
1547 struct inode *inode = dentry->d_inode; 1547 struct inode *inode = d_inode(dentry);
1548 int error; 1548 int error;
1549 1549
1550 error = inode_change_ok(inode, iattr); 1550 error = inode_change_ok(inode, iattr);
diff --git a/fs/ext2/namei.c b/fs/ext2/namei.c
index ce422931f411..3e074a9ccbe6 100644
--- a/fs/ext2/namei.c
+++ b/fs/ext2/namei.c
@@ -79,10 +79,10 @@ static struct dentry *ext2_lookup(struct inode * dir, struct dentry *dentry, uns
79struct dentry *ext2_get_parent(struct dentry *child) 79struct dentry *ext2_get_parent(struct dentry *child)
80{ 80{
81 struct qstr dotdot = QSTR_INIT("..", 2); 81 struct qstr dotdot = QSTR_INIT("..", 2);
82 unsigned long ino = ext2_inode_by_name(child->d_inode, &dotdot); 82 unsigned long ino = ext2_inode_by_name(d_inode(child), &dotdot);
83 if (!ino) 83 if (!ino)
84 return ERR_PTR(-ENOENT); 84 return ERR_PTR(-ENOENT);
85 return d_obtain_alias(ext2_iget(child->d_inode->i_sb, ino)); 85 return d_obtain_alias(ext2_iget(d_inode(child)->i_sb, ino));
86} 86}
87 87
88/* 88/*
@@ -208,7 +208,7 @@ out_fail:
208static int ext2_link (struct dentry * old_dentry, struct inode * dir, 208static int ext2_link (struct dentry * old_dentry, struct inode * dir,
209 struct dentry *dentry) 209 struct dentry *dentry)
210{ 210{
211 struct inode *inode = old_dentry->d_inode; 211 struct inode *inode = d_inode(old_dentry);
212 int err; 212 int err;
213 213
214 dquot_initialize(dir); 214 dquot_initialize(dir);
@@ -275,7 +275,7 @@ out_dir:
275 275
276static int ext2_unlink(struct inode * dir, struct dentry *dentry) 276static int ext2_unlink(struct inode * dir, struct dentry *dentry)
277{ 277{
278 struct inode * inode = dentry->d_inode; 278 struct inode * inode = d_inode(dentry);
279 struct ext2_dir_entry_2 * de; 279 struct ext2_dir_entry_2 * de;
280 struct page * page; 280 struct page * page;
281 int err = -ENOENT; 281 int err = -ENOENT;
@@ -299,7 +299,7 @@ out:
299 299
300static int ext2_rmdir (struct inode * dir, struct dentry *dentry) 300static int ext2_rmdir (struct inode * dir, struct dentry *dentry)
301{ 301{
302 struct inode * inode = dentry->d_inode; 302 struct inode * inode = d_inode(dentry);
303 int err = -ENOTEMPTY; 303 int err = -ENOTEMPTY;
304 304
305 if (ext2_empty_dir(inode)) { 305 if (ext2_empty_dir(inode)) {
@@ -316,8 +316,8 @@ static int ext2_rmdir (struct inode * dir, struct dentry *dentry)
316static int ext2_rename (struct inode * old_dir, struct dentry * old_dentry, 316static int ext2_rename (struct inode * old_dir, struct dentry * old_dentry,
317 struct inode * new_dir, struct dentry * new_dentry ) 317 struct inode * new_dir, struct dentry * new_dentry )
318{ 318{
319 struct inode * old_inode = old_dentry->d_inode; 319 struct inode * old_inode = d_inode(old_dentry);
320 struct inode * new_inode = new_dentry->d_inode; 320 struct inode * new_inode = d_inode(new_dentry);
321 struct page * dir_page = NULL; 321 struct page * dir_page = NULL;
322 struct ext2_dir_entry_2 * dir_de = NULL; 322 struct ext2_dir_entry_2 * dir_de = NULL;
323 struct page * old_page; 323 struct page * old_page;
diff --git a/fs/ext2/symlink.c b/fs/ext2/symlink.c
index 565cf817bbf1..20608f17c2e5 100644
--- a/fs/ext2/symlink.c
+++ b/fs/ext2/symlink.c
@@ -23,7 +23,7 @@
23 23
24static void *ext2_follow_link(struct dentry *dentry, struct nameidata *nd) 24static void *ext2_follow_link(struct dentry *dentry, struct nameidata *nd)
25{ 25{
26 struct ext2_inode_info *ei = EXT2_I(dentry->d_inode); 26 struct ext2_inode_info *ei = EXT2_I(d_inode(dentry));
27 nd_set_link(nd, (char *)ei->i_data); 27 nd_set_link(nd, (char *)ei->i_data);
28 return NULL; 28 return NULL;
29} 29}
diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
index 91426141c33a..0b6bfd3a398b 100644
--- a/fs/ext2/xattr.c
+++ b/fs/ext2/xattr.c
@@ -243,7 +243,7 @@ cleanup:
243static int 243static int
244ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size) 244ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
245{ 245{
246 struct inode *inode = dentry->d_inode; 246 struct inode *inode = d_inode(dentry);
247 struct buffer_head *bh = NULL; 247 struct buffer_head *bh = NULL;
248 struct ext2_xattr_entry *entry; 248 struct ext2_xattr_entry *entry;
249 char *end; 249 char *end;
@@ -319,7 +319,7 @@ cleanup:
319/* 319/*
320 * Inode operation listxattr() 320 * Inode operation listxattr()
321 * 321 *
322 * dentry->d_inode->i_mutex: don't care 322 * d_inode(dentry)->i_mutex: don't care
323 */ 323 */
324ssize_t 324ssize_t
325ext2_listxattr(struct dentry *dentry, char *buffer, size_t size) 325ext2_listxattr(struct dentry *dentry, char *buffer, size_t size)
diff --git a/fs/ext2/xattr_security.c b/fs/ext2/xattr_security.c
index c0ebc4db8849..702fc6840246 100644
--- a/fs/ext2/xattr_security.c
+++ b/fs/ext2/xattr_security.c
@@ -28,7 +28,7 @@ ext2_xattr_security_get(struct dentry *dentry, const char *name,
28{ 28{
29 if (strcmp(name, "") == 0) 29 if (strcmp(name, "") == 0)
30 return -EINVAL; 30 return -EINVAL;
31 return ext2_xattr_get(dentry->d_inode, EXT2_XATTR_INDEX_SECURITY, name, 31 return ext2_xattr_get(d_inode(dentry), EXT2_XATTR_INDEX_SECURITY, name,
32 buffer, size); 32 buffer, size);
33} 33}
34 34
@@ -38,7 +38,7 @@ ext2_xattr_security_set(struct dentry *dentry, const char *name,
38{ 38{
39 if (strcmp(name, "") == 0) 39 if (strcmp(name, "") == 0)
40 return -EINVAL; 40 return -EINVAL;
41 return ext2_xattr_set(dentry->d_inode, EXT2_XATTR_INDEX_SECURITY, name, 41 return ext2_xattr_set(d_inode(dentry), EXT2_XATTR_INDEX_SECURITY, name,
42 value, size, flags); 42 value, size, flags);
43} 43}
44 44
diff --git a/fs/ext2/xattr_trusted.c b/fs/ext2/xattr_trusted.c
index 7e192574c001..42b6e9874bcc 100644
--- a/fs/ext2/xattr_trusted.c
+++ b/fs/ext2/xattr_trusted.c
@@ -32,7 +32,7 @@ ext2_xattr_trusted_get(struct dentry *dentry, const char *name,
32{ 32{
33 if (strcmp(name, "") == 0) 33 if (strcmp(name, "") == 0)
34 return -EINVAL; 34 return -EINVAL;
35 return ext2_xattr_get(dentry->d_inode, EXT2_XATTR_INDEX_TRUSTED, name, 35 return ext2_xattr_get(d_inode(dentry), EXT2_XATTR_INDEX_TRUSTED, name,
36 buffer, size); 36 buffer, size);
37} 37}
38 38
@@ -42,7 +42,7 @@ ext2_xattr_trusted_set(struct dentry *dentry, const char *name,
42{ 42{
43 if (strcmp(name, "") == 0) 43 if (strcmp(name, "") == 0)
44 return -EINVAL; 44 return -EINVAL;
45 return ext2_xattr_set(dentry->d_inode, EXT2_XATTR_INDEX_TRUSTED, name, 45 return ext2_xattr_set(d_inode(dentry), EXT2_XATTR_INDEX_TRUSTED, name,
46 value, size, flags); 46 value, size, flags);
47} 47}
48 48
diff --git a/fs/ext2/xattr_user.c b/fs/ext2/xattr_user.c
index f470e44c4b8d..ecdc4605192c 100644
--- a/fs/ext2/xattr_user.c
+++ b/fs/ext2/xattr_user.c
@@ -36,7 +36,7 @@ ext2_xattr_user_get(struct dentry *dentry, const char *name,
36 return -EINVAL; 36 return -EINVAL;
37 if (!test_opt(dentry->d_sb, XATTR_USER)) 37 if (!test_opt(dentry->d_sb, XATTR_USER))
38 return -EOPNOTSUPP; 38 return -EOPNOTSUPP;
39 return ext2_xattr_get(dentry->d_inode, EXT2_XATTR_INDEX_USER, 39 return ext2_xattr_get(d_inode(dentry), EXT2_XATTR_INDEX_USER,
40 name, buffer, size); 40 name, buffer, size);
41} 41}
42 42
@@ -49,7 +49,7 @@ ext2_xattr_user_set(struct dentry *dentry, const char *name,
49 if (!test_opt(dentry->d_sb, XATTR_USER)) 49 if (!test_opt(dentry->d_sb, XATTR_USER))
50 return -EOPNOTSUPP; 50 return -EOPNOTSUPP;
51 51
52 return ext2_xattr_set(dentry->d_inode, EXT2_XATTR_INDEX_USER, 52 return ext2_xattr_set(d_inode(dentry), EXT2_XATTR_INDEX_USER,
53 name, value, size, flags); 53 name, value, size, flags);
54} 54}
55 55
diff --git a/fs/ext3/ialloc.c b/fs/ext3/ialloc.c
index a1b810230cc5..3ad242e5840e 100644
--- a/fs/ext3/ialloc.c
+++ b/fs/ext3/ialloc.c
@@ -210,7 +210,7 @@ static int find_group_orlov(struct super_block *sb, struct inode *parent)
210 avefreeb = freeb / ngroups; 210 avefreeb = freeb / ngroups;
211 ndirs = percpu_counter_read_positive(&sbi->s_dirs_counter); 211 ndirs = percpu_counter_read_positive(&sbi->s_dirs_counter);
212 212
213 if ((parent == sb->s_root->d_inode) || 213 if ((parent == d_inode(sb->s_root)) ||
214 (EXT3_I(parent)->i_flags & EXT3_TOPDIR_FL)) { 214 (EXT3_I(parent)->i_flags & EXT3_TOPDIR_FL)) {
215 int best_ndir = inodes_per_group; 215 int best_ndir = inodes_per_group;
216 int best_group = -1; 216 int best_group = -1;
diff --git a/fs/ext3/inode.c b/fs/ext3/inode.c
index 13c0868c7160..2ee2dc4351d1 100644
--- a/fs/ext3/inode.c
+++ b/fs/ext3/inode.c
@@ -3240,7 +3240,7 @@ int ext3_write_inode(struct inode *inode, struct writeback_control *wbc)
3240 */ 3240 */
3241int ext3_setattr(struct dentry *dentry, struct iattr *attr) 3241int ext3_setattr(struct dentry *dentry, struct iattr *attr)
3242{ 3242{
3243 struct inode *inode = dentry->d_inode; 3243 struct inode *inode = d_inode(dentry);
3244 int error, rc = 0; 3244 int error, rc = 0;
3245 const unsigned int ia_valid = attr->ia_valid; 3245 const unsigned int ia_valid = attr->ia_valid;
3246 3246
diff --git a/fs/ext3/namei.c b/fs/ext3/namei.c
index f197736dccfa..4264b9bd0002 100644
--- a/fs/ext3/namei.c
+++ b/fs/ext3/namei.c
@@ -1049,19 +1049,19 @@ struct dentry *ext3_get_parent(struct dentry *child)
1049 struct ext3_dir_entry_2 * de; 1049 struct ext3_dir_entry_2 * de;
1050 struct buffer_head *bh; 1050 struct buffer_head *bh;
1051 1051
1052 bh = ext3_find_entry(child->d_inode, &dotdot, &de); 1052 bh = ext3_find_entry(d_inode(child), &dotdot, &de);
1053 if (!bh) 1053 if (!bh)
1054 return ERR_PTR(-ENOENT); 1054 return ERR_PTR(-ENOENT);
1055 ino = le32_to_cpu(de->inode); 1055 ino = le32_to_cpu(de->inode);
1056 brelse(bh); 1056 brelse(bh);
1057 1057
1058 if (!ext3_valid_inum(child->d_inode->i_sb, ino)) { 1058 if (!ext3_valid_inum(d_inode(child)->i_sb, ino)) {
1059 ext3_error(child->d_inode->i_sb, "ext3_get_parent", 1059 ext3_error(d_inode(child)->i_sb, "ext3_get_parent",
1060 "bad inode number: %lu", ino); 1060 "bad inode number: %lu", ino);
1061 return ERR_PTR(-EIO); 1061 return ERR_PTR(-EIO);
1062 } 1062 }
1063 1063
1064 return d_obtain_alias(ext3_iget(child->d_inode->i_sb, ino)); 1064 return d_obtain_alias(ext3_iget(d_inode(child)->i_sb, ino));
1065} 1065}
1066 1066
1067#define S_SHIFT 12 1067#define S_SHIFT 12
@@ -1243,7 +1243,7 @@ static int add_dirent_to_buf(handle_t *handle, struct dentry *dentry,
1243 struct inode *inode, struct ext3_dir_entry_2 *de, 1243 struct inode *inode, struct ext3_dir_entry_2 *de,
1244 struct buffer_head * bh) 1244 struct buffer_head * bh)
1245{ 1245{
1246 struct inode *dir = dentry->d_parent->d_inode; 1246 struct inode *dir = d_inode(dentry->d_parent);
1247 const char *name = dentry->d_name.name; 1247 const char *name = dentry->d_name.name;
1248 int namelen = dentry->d_name.len; 1248 int namelen = dentry->d_name.len;
1249 unsigned long offset = 0; 1249 unsigned long offset = 0;
@@ -1330,7 +1330,7 @@ static int add_dirent_to_buf(handle_t *handle, struct dentry *dentry,
1330static int make_indexed_dir(handle_t *handle, struct dentry *dentry, 1330static int make_indexed_dir(handle_t *handle, struct dentry *dentry,
1331 struct inode *inode, struct buffer_head *bh) 1331 struct inode *inode, struct buffer_head *bh)
1332{ 1332{
1333 struct inode *dir = dentry->d_parent->d_inode; 1333 struct inode *dir = d_inode(dentry->d_parent);
1334 const char *name = dentry->d_name.name; 1334 const char *name = dentry->d_name.name;
1335 int namelen = dentry->d_name.len; 1335 int namelen = dentry->d_name.len;
1336 struct buffer_head *bh2; 1336 struct buffer_head *bh2;
@@ -1435,7 +1435,7 @@ static int make_indexed_dir(handle_t *handle, struct dentry *dentry,
1435static int ext3_add_entry (handle_t *handle, struct dentry *dentry, 1435static int ext3_add_entry (handle_t *handle, struct dentry *dentry,
1436 struct inode *inode) 1436 struct inode *inode)
1437{ 1437{
1438 struct inode *dir = dentry->d_parent->d_inode; 1438 struct inode *dir = d_inode(dentry->d_parent);
1439 struct buffer_head * bh; 1439 struct buffer_head * bh;
1440 struct ext3_dir_entry_2 *de; 1440 struct ext3_dir_entry_2 *de;
1441 struct super_block * sb; 1441 struct super_block * sb;
@@ -1489,7 +1489,7 @@ static int ext3_dx_add_entry(handle_t *handle, struct dentry *dentry,
1489 struct dx_entry *entries, *at; 1489 struct dx_entry *entries, *at;
1490 struct dx_hash_info hinfo; 1490 struct dx_hash_info hinfo;
1491 struct buffer_head * bh; 1491 struct buffer_head * bh;
1492 struct inode *dir = dentry->d_parent->d_inode; 1492 struct inode *dir = d_inode(dentry->d_parent);
1493 struct super_block * sb = dir->i_sb; 1493 struct super_block * sb = dir->i_sb;
1494 struct ext3_dir_entry_2 *de; 1494 struct ext3_dir_entry_2 *de;
1495 int err; 1495 int err;
@@ -2111,7 +2111,7 @@ static int ext3_rmdir (struct inode * dir, struct dentry *dentry)
2111 /* Initialize quotas before so that eventual writes go in 2111 /* Initialize quotas before so that eventual writes go in
2112 * separate transaction */ 2112 * separate transaction */
2113 dquot_initialize(dir); 2113 dquot_initialize(dir);
2114 dquot_initialize(dentry->d_inode); 2114 dquot_initialize(d_inode(dentry));
2115 2115
2116 handle = ext3_journal_start(dir, EXT3_DELETE_TRANS_BLOCKS(dir->i_sb)); 2116 handle = ext3_journal_start(dir, EXT3_DELETE_TRANS_BLOCKS(dir->i_sb));
2117 if (IS_ERR(handle)) 2117 if (IS_ERR(handle))
@@ -2125,7 +2125,7 @@ static int ext3_rmdir (struct inode * dir, struct dentry *dentry)
2125 if (IS_DIRSYNC(dir)) 2125 if (IS_DIRSYNC(dir))
2126 handle->h_sync = 1; 2126 handle->h_sync = 1;
2127 2127
2128 inode = dentry->d_inode; 2128 inode = d_inode(dentry);
2129 2129
2130 retval = -EIO; 2130 retval = -EIO;
2131 if (le32_to_cpu(de->inode) != inode->i_ino) 2131 if (le32_to_cpu(de->inode) != inode->i_ino)
@@ -2173,7 +2173,7 @@ static int ext3_unlink(struct inode * dir, struct dentry *dentry)
2173 /* Initialize quotas before so that eventual writes go 2173 /* Initialize quotas before so that eventual writes go
2174 * in separate transaction */ 2174 * in separate transaction */
2175 dquot_initialize(dir); 2175 dquot_initialize(dir);
2176 dquot_initialize(dentry->d_inode); 2176 dquot_initialize(d_inode(dentry));
2177 2177
2178 handle = ext3_journal_start(dir, EXT3_DELETE_TRANS_BLOCKS(dir->i_sb)); 2178 handle = ext3_journal_start(dir, EXT3_DELETE_TRANS_BLOCKS(dir->i_sb));
2179 if (IS_ERR(handle)) 2179 if (IS_ERR(handle))
@@ -2187,7 +2187,7 @@ static int ext3_unlink(struct inode * dir, struct dentry *dentry)
2187 if (!bh) 2187 if (!bh)
2188 goto end_unlink; 2188 goto end_unlink;
2189 2189
2190 inode = dentry->d_inode; 2190 inode = d_inode(dentry);
2191 2191
2192 retval = -EIO; 2192 retval = -EIO;
2193 if (le32_to_cpu(de->inode) != inode->i_ino) 2193 if (le32_to_cpu(de->inode) != inode->i_ino)
@@ -2328,7 +2328,7 @@ static int ext3_link (struct dentry * old_dentry,
2328 struct inode * dir, struct dentry *dentry) 2328 struct inode * dir, struct dentry *dentry)
2329{ 2329{
2330 handle_t *handle; 2330 handle_t *handle;
2331 struct inode *inode = old_dentry->d_inode; 2331 struct inode *inode = d_inode(old_dentry);
2332 int err, retries = 0; 2332 int err, retries = 0;
2333 2333
2334 if (inode->i_nlink >= EXT3_LINK_MAX) 2334 if (inode->i_nlink >= EXT3_LINK_MAX)
@@ -2391,8 +2391,8 @@ static int ext3_rename (struct inode * old_dir, struct dentry *old_dentry,
2391 2391
2392 /* Initialize quotas before so that eventual writes go 2392 /* Initialize quotas before so that eventual writes go
2393 * in separate transaction */ 2393 * in separate transaction */
2394 if (new_dentry->d_inode) 2394 if (d_really_is_positive(new_dentry))
2395 dquot_initialize(new_dentry->d_inode); 2395 dquot_initialize(d_inode(new_dentry));
2396 handle = ext3_journal_start(old_dir, 2 * 2396 handle = ext3_journal_start(old_dir, 2 *
2397 EXT3_DATA_TRANS_BLOCKS(old_dir->i_sb) + 2397 EXT3_DATA_TRANS_BLOCKS(old_dir->i_sb) +
2398 EXT3_INDEX_EXTRA_TRANS_BLOCKS + 2); 2398 EXT3_INDEX_EXTRA_TRANS_BLOCKS + 2);
@@ -2409,12 +2409,12 @@ static int ext3_rename (struct inode * old_dir, struct dentry *old_dentry,
2409 * and merrily kill the link to whatever was created under the 2409 * and merrily kill the link to whatever was created under the
2410 * same name. Goodbye sticky bit ;-< 2410 * same name. Goodbye sticky bit ;-<
2411 */ 2411 */
2412 old_inode = old_dentry->d_inode; 2412 old_inode = d_inode(old_dentry);
2413 retval = -ENOENT; 2413 retval = -ENOENT;
2414 if (!old_bh || le32_to_cpu(old_de->inode) != old_inode->i_ino) 2414 if (!old_bh || le32_to_cpu(old_de->inode) != old_inode->i_ino)
2415 goto end_rename; 2415 goto end_rename;
2416 2416
2417 new_inode = new_dentry->d_inode; 2417 new_inode = d_inode(new_dentry);
2418 new_bh = ext3_find_entry(new_dir, &new_dentry->d_name, &new_de); 2418 new_bh = ext3_find_entry(new_dir, &new_dentry->d_name, &new_de);
2419 if (new_bh) { 2419 if (new_bh) {
2420 if (!new_inode) { 2420 if (!new_inode) {
diff --git a/fs/ext3/super.c b/fs/ext3/super.c
index f037b4b27300..a9312f0a54e5 100644
--- a/fs/ext3/super.c
+++ b/fs/ext3/super.c
@@ -1170,7 +1170,7 @@ static int parse_options (char *options, struct super_block *sb,
1170 return 0; 1170 return 0;
1171 } 1171 }
1172 1172
1173 journal_inode = path.dentry->d_inode; 1173 journal_inode = d_inode(path.dentry);
1174 if (!S_ISBLK(journal_inode->i_mode)) { 1174 if (!S_ISBLK(journal_inode->i_mode)) {
1175 ext3_msg(sb, KERN_ERR, "error: journal path %s " 1175 ext3_msg(sb, KERN_ERR, "error: journal path %s "
1176 "is not a block device", journal_path); 1176 "is not a block device", journal_path);
@@ -2947,7 +2947,7 @@ static int ext3_write_info(struct super_block *sb, int type)
2947 handle_t *handle; 2947 handle_t *handle;
2948 2948
2949 /* Data block + inode block */ 2949 /* Data block + inode block */
2950 handle = ext3_journal_start(sb->s_root->d_inode, 2); 2950 handle = ext3_journal_start(d_inode(sb->s_root), 2);
2951 if (IS_ERR(handle)) 2951 if (IS_ERR(handle))
2952 return PTR_ERR(handle); 2952 return PTR_ERR(handle);
2953 ret = dquot_commit_info(sb, type); 2953 ret = dquot_commit_info(sb, type);
@@ -2994,7 +2994,7 @@ static int ext3_quota_on(struct super_block *sb, int type, int format_id,
2994 * When we journal data on quota file, we have to flush journal to see 2994 * When we journal data on quota file, we have to flush journal to see
2995 * all updates to the file when we bypass pagecache... 2995 * all updates to the file when we bypass pagecache...
2996 */ 2996 */
2997 if (ext3_should_journal_data(path->dentry->d_inode)) { 2997 if (ext3_should_journal_data(d_inode(path->dentry))) {
2998 /* 2998 /*
2999 * We don't need to lock updates but journal_flush() could 2999 * We don't need to lock updates but journal_flush() could
3000 * otherwise be livelocked... 3000 * otherwise be livelocked...
diff --git a/fs/ext3/symlink.c b/fs/ext3/symlink.c
index 6b01c3eab1f3..ea96df3c58db 100644
--- a/fs/ext3/symlink.c
+++ b/fs/ext3/symlink.c
@@ -23,7 +23,7 @@
23 23
24static void * ext3_follow_link(struct dentry *dentry, struct nameidata *nd) 24static void * ext3_follow_link(struct dentry *dentry, struct nameidata *nd)
25{ 25{
26 struct ext3_inode_info *ei = EXT3_I(dentry->d_inode); 26 struct ext3_inode_info *ei = EXT3_I(d_inode(dentry));
27 nd_set_link(nd, (char*)ei->i_data); 27 nd_set_link(nd, (char*)ei->i_data);
28 return NULL; 28 return NULL;
29} 29}
diff --git a/fs/ext3/xattr.c b/fs/ext3/xattr.c
index 24215dc09a18..7cf36501ccf4 100644
--- a/fs/ext3/xattr.c
+++ b/fs/ext3/xattr.c
@@ -137,7 +137,7 @@ ext3_xattr_handler(int name_index)
137/* 137/*
138 * Inode operation listxattr() 138 * Inode operation listxattr()
139 * 139 *
140 * dentry->d_inode->i_mutex: don't care 140 * d_inode(dentry)->i_mutex: don't care
141 */ 141 */
142ssize_t 142ssize_t
143ext3_listxattr(struct dentry *dentry, char *buffer, size_t size) 143ext3_listxattr(struct dentry *dentry, char *buffer, size_t size)
@@ -355,7 +355,7 @@ ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
355static int 355static int
356ext3_xattr_block_list(struct dentry *dentry, char *buffer, size_t buffer_size) 356ext3_xattr_block_list(struct dentry *dentry, char *buffer, size_t buffer_size)
357{ 357{
358 struct inode *inode = dentry->d_inode; 358 struct inode *inode = d_inode(dentry);
359 struct buffer_head *bh = NULL; 359 struct buffer_head *bh = NULL;
360 int error; 360 int error;
361 361
@@ -391,7 +391,7 @@ cleanup:
391static int 391static int
392ext3_xattr_ibody_list(struct dentry *dentry, char *buffer, size_t buffer_size) 392ext3_xattr_ibody_list(struct dentry *dentry, char *buffer, size_t buffer_size)
393{ 393{
394 struct inode *inode = dentry->d_inode; 394 struct inode *inode = d_inode(dentry);
395 struct ext3_xattr_ibody_header *header; 395 struct ext3_xattr_ibody_header *header;
396 struct ext3_inode *raw_inode; 396 struct ext3_inode *raw_inode;
397 struct ext3_iloc iloc; 397 struct ext3_iloc iloc;
@@ -432,7 +432,7 @@ ext3_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
432{ 432{
433 int i_error, b_error; 433 int i_error, b_error;
434 434
435 down_read(&EXT3_I(dentry->d_inode)->xattr_sem); 435 down_read(&EXT3_I(d_inode(dentry))->xattr_sem);
436 i_error = ext3_xattr_ibody_list(dentry, buffer, buffer_size); 436 i_error = ext3_xattr_ibody_list(dentry, buffer, buffer_size);
437 if (i_error < 0) { 437 if (i_error < 0) {
438 b_error = 0; 438 b_error = 0;
@@ -445,7 +445,7 @@ ext3_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
445 if (b_error < 0) 445 if (b_error < 0)
446 i_error = 0; 446 i_error = 0;
447 } 447 }
448 up_read(&EXT3_I(dentry->d_inode)->xattr_sem); 448 up_read(&EXT3_I(d_inode(dentry))->xattr_sem);
449 return i_error + b_error; 449 return i_error + b_error;
450} 450}
451 451
diff --git a/fs/ext3/xattr_security.c b/fs/ext3/xattr_security.c
index 722c2bf9645d..c9506d5e3b13 100644
--- a/fs/ext3/xattr_security.c
+++ b/fs/ext3/xattr_security.c
@@ -29,7 +29,7 @@ ext3_xattr_security_get(struct dentry *dentry, const char *name,
29{ 29{
30 if (strcmp(name, "") == 0) 30 if (strcmp(name, "") == 0)
31 return -EINVAL; 31 return -EINVAL;
32 return ext3_xattr_get(dentry->d_inode, EXT3_XATTR_INDEX_SECURITY, 32 return ext3_xattr_get(d_inode(dentry), EXT3_XATTR_INDEX_SECURITY,
33 name, buffer, size); 33 name, buffer, size);
34} 34}
35 35
@@ -39,7 +39,7 @@ ext3_xattr_security_set(struct dentry *dentry, const char *name,
39{ 39{
40 if (strcmp(name, "") == 0) 40 if (strcmp(name, "") == 0)
41 return -EINVAL; 41 return -EINVAL;
42 return ext3_xattr_set(dentry->d_inode, EXT3_XATTR_INDEX_SECURITY, 42 return ext3_xattr_set(d_inode(dentry), EXT3_XATTR_INDEX_SECURITY,
43 name, value, size, flags); 43 name, value, size, flags);
44} 44}
45 45
diff --git a/fs/ext3/xattr_trusted.c b/fs/ext3/xattr_trusted.c
index d75727cc67fa..206cc66dc285 100644
--- a/fs/ext3/xattr_trusted.c
+++ b/fs/ext3/xattr_trusted.c
@@ -32,7 +32,7 @@ ext3_xattr_trusted_get(struct dentry *dentry, const char *name,
32{ 32{
33 if (strcmp(name, "") == 0) 33 if (strcmp(name, "") == 0)
34 return -EINVAL; 34 return -EINVAL;
35 return ext3_xattr_get(dentry->d_inode, EXT3_XATTR_INDEX_TRUSTED, 35 return ext3_xattr_get(d_inode(dentry), EXT3_XATTR_INDEX_TRUSTED,
36 name, buffer, size); 36 name, buffer, size);
37} 37}
38 38
@@ -42,7 +42,7 @@ ext3_xattr_trusted_set(struct dentry *dentry, const char *name,
42{ 42{
43 if (strcmp(name, "") == 0) 43 if (strcmp(name, "") == 0)
44 return -EINVAL; 44 return -EINVAL;
45 return ext3_xattr_set(dentry->d_inode, EXT3_XATTR_INDEX_TRUSTED, name, 45 return ext3_xattr_set(d_inode(dentry), EXT3_XATTR_INDEX_TRUSTED, name,
46 value, size, flags); 46 value, size, flags);
47} 47}
48 48
diff --git a/fs/ext3/xattr_user.c b/fs/ext3/xattr_user.c
index 5612af3567e0..021508ad1616 100644
--- a/fs/ext3/xattr_user.c
+++ b/fs/ext3/xattr_user.c
@@ -34,7 +34,7 @@ ext3_xattr_user_get(struct dentry *dentry, const char *name, void *buffer,
34 return -EINVAL; 34 return -EINVAL;
35 if (!test_opt(dentry->d_sb, XATTR_USER)) 35 if (!test_opt(dentry->d_sb, XATTR_USER))
36 return -EOPNOTSUPP; 36 return -EOPNOTSUPP;
37 return ext3_xattr_get(dentry->d_inode, EXT3_XATTR_INDEX_USER, 37 return ext3_xattr_get(d_inode(dentry), EXT3_XATTR_INDEX_USER,
38 name, buffer, size); 38 name, buffer, size);
39} 39}
40 40
@@ -46,7 +46,7 @@ ext3_xattr_user_set(struct dentry *dentry, const char *name,
46 return -EINVAL; 46 return -EINVAL;
47 if (!test_opt(dentry->d_sb, XATTR_USER)) 47 if (!test_opt(dentry->d_sb, XATTR_USER))
48 return -EOPNOTSUPP; 48 return -EOPNOTSUPP;
49 return ext3_xattr_set(dentry->d_inode, EXT3_XATTR_INDEX_USER, 49 return ext3_xattr_set(d_inode(dentry), EXT3_XATTR_INDEX_USER,
50 name, value, size, flags); 50 name, value, size, flags);
51} 51}
52 52
diff --git a/fs/ext4/fsync.c b/fs/ext4/fsync.c
index e9d632e9aa4b..8850254136ae 100644
--- a/fs/ext4/fsync.c
+++ b/fs/ext4/fsync.c
@@ -55,7 +55,7 @@ static int ext4_sync_parent(struct inode *inode)
55 dentry = d_find_any_alias(inode); 55 dentry = d_find_any_alias(inode);
56 if (!dentry) 56 if (!dentry)
57 break; 57 break;
58 next = igrab(dentry->d_parent->d_inode); 58 next = igrab(d_inode(dentry->d_parent));
59 dput(dentry); 59 dput(dentry);
60 if (!next) 60 if (!next)
61 break; 61 break;
diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c
index 2cf18a2d5c72..1eaa6cb96cd0 100644
--- a/fs/ext4/ialloc.c
+++ b/fs/ext4/ialloc.c
@@ -443,7 +443,7 @@ static int find_group_orlov(struct super_block *sb, struct inode *parent,
443 ndirs = percpu_counter_read_positive(&sbi->s_dirs_counter); 443 ndirs = percpu_counter_read_positive(&sbi->s_dirs_counter);
444 444
445 if (S_ISDIR(mode) && 445 if (S_ISDIR(mode) &&
446 ((parent == sb->s_root->d_inode) || 446 ((parent == d_inode(sb->s_root)) ||
447 (ext4_test_inode_flag(parent, EXT4_INODE_TOPDIR)))) { 447 (ext4_test_inode_flag(parent, EXT4_INODE_TOPDIR)))) {
448 int best_ndir = inodes_per_group; 448 int best_ndir = inodes_per_group;
449 int ret = -1; 449 int ret = -1;
diff --git a/fs/ext4/indirect.c b/fs/ext4/indirect.c
index 3580629e42d3..958824019509 100644
--- a/fs/ext4/indirect.c
+++ b/fs/ext4/indirect.c
@@ -682,11 +682,11 @@ retry:
682 * via ext4_inode_block_unlocked_dio(). Check inode's state 682 * via ext4_inode_block_unlocked_dio(). Check inode's state
683 * while holding extra i_dio_count ref. 683 * while holding extra i_dio_count ref.
684 */ 684 */
685 atomic_inc(&inode->i_dio_count); 685 inode_dio_begin(inode);
686 smp_mb(); 686 smp_mb();
687 if (unlikely(ext4_test_inode_state(inode, 687 if (unlikely(ext4_test_inode_state(inode,
688 EXT4_STATE_DIOREAD_LOCK))) { 688 EXT4_STATE_DIOREAD_LOCK))) {
689 inode_dio_done(inode); 689 inode_dio_end(inode);
690 goto locked; 690 goto locked;
691 } 691 }
692 if (IS_DAX(inode)) 692 if (IS_DAX(inode))
@@ -697,7 +697,7 @@ retry:
697 inode->i_sb->s_bdev, iter, 697 inode->i_sb->s_bdev, iter,
698 offset, ext4_get_block, NULL, 698 offset, ext4_get_block, NULL,
699 NULL, 0); 699 NULL, 0);
700 inode_dio_done(inode); 700 inode_dio_end(inode);
701 } else { 701 } else {
702locked: 702locked:
703 if (IS_DAX(inode)) 703 if (IS_DAX(inode))
diff --git a/fs/ext4/inline.c b/fs/ext4/inline.c
index feb2cafbeace..095c7a258d97 100644
--- a/fs/ext4/inline.c
+++ b/fs/ext4/inline.c
@@ -1000,7 +1000,7 @@ static int ext4_add_dirent_to_inline(handle_t *handle,
1000 struct ext4_iloc *iloc, 1000 struct ext4_iloc *iloc,
1001 void *inline_start, int inline_size) 1001 void *inline_start, int inline_size)
1002{ 1002{
1003 struct inode *dir = dentry->d_parent->d_inode; 1003 struct inode *dir = d_inode(dentry->d_parent);
1004 const char *name = dentry->d_name.name; 1004 const char *name = dentry->d_name.name;
1005 int namelen = dentry->d_name.len; 1005 int namelen = dentry->d_name.len;
1006 int err; 1006 int err;
@@ -1254,7 +1254,7 @@ int ext4_try_add_inline_entry(handle_t *handle, struct dentry *dentry,
1254 int ret, inline_size; 1254 int ret, inline_size;
1255 void *inline_start; 1255 void *inline_start;
1256 struct ext4_iloc iloc; 1256 struct ext4_iloc iloc;
1257 struct inode *dir = dentry->d_parent->d_inode; 1257 struct inode *dir = d_inode(dentry->d_parent);
1258 1258
1259 ret = ext4_get_inode_loc(dir, &iloc); 1259 ret = ext4_get_inode_loc(dir, &iloc);
1260 if (ret) 1260 if (ret)
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 366476e71e10..cbd0654a2675 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -3077,7 +3077,7 @@ static ssize_t ext4_ext_direct_IO(struct kiocb *iocb, struct iov_iter *iter,
3077 * overwrite DIO as i_dio_count needs to be incremented under i_mutex. 3077 * overwrite DIO as i_dio_count needs to be incremented under i_mutex.
3078 */ 3078 */
3079 if (iov_iter_rw(iter) == WRITE) 3079 if (iov_iter_rw(iter) == WRITE)
3080 atomic_inc(&inode->i_dio_count); 3080 inode_dio_begin(inode);
3081 3081
3082 /* If we do a overwrite dio, i_mutex locking can be released */ 3082 /* If we do a overwrite dio, i_mutex locking can be released */
3083 overwrite = *((int *)iocb->private); 3083 overwrite = *((int *)iocb->private);
@@ -3182,7 +3182,7 @@ static ssize_t ext4_ext_direct_IO(struct kiocb *iocb, struct iov_iter *iter,
3182 3182
3183retake_lock: 3183retake_lock:
3184 if (iov_iter_rw(iter) == WRITE) 3184 if (iov_iter_rw(iter) == WRITE)
3185 inode_dio_done(inode); 3185 inode_dio_end(inode);
3186 /* take i_mutex locking again if we do a ovewrite dio */ 3186 /* take i_mutex locking again if we do a ovewrite dio */
3187 if (overwrite) { 3187 if (overwrite) {
3188 up_read(&EXT4_I(inode)->i_data_sem); 3188 up_read(&EXT4_I(inode)->i_data_sem);
@@ -4637,7 +4637,7 @@ static void ext4_wait_for_tail_page_commit(struct inode *inode)
4637 */ 4637 */
4638int ext4_setattr(struct dentry *dentry, struct iattr *attr) 4638int ext4_setattr(struct dentry *dentry, struct iattr *attr)
4639{ 4639{
4640 struct inode *inode = dentry->d_inode; 4640 struct inode *inode = d_inode(dentry);
4641 int error, rc = 0; 4641 int error, rc = 0;
4642 int orphan = 0; 4642 int orphan = 0;
4643 const unsigned int ia_valid = attr->ia_valid; 4643 const unsigned int ia_valid = attr->ia_valid;
@@ -4785,7 +4785,7 @@ int ext4_getattr(struct vfsmount *mnt, struct dentry *dentry,
4785 struct inode *inode; 4785 struct inode *inode;
4786 unsigned long long delalloc_blocks; 4786 unsigned long long delalloc_blocks;
4787 4787
4788 inode = dentry->d_inode; 4788 inode = d_inode(dentry);
4789 generic_fillattr(inode, stat); 4789 generic_fillattr(inode, stat);
4790 4790
4791 /* 4791 /*
diff --git a/fs/ext4/migrate.c b/fs/ext4/migrate.c
index 3cb267aee802..b52374e42102 100644
--- a/fs/ext4/migrate.c
+++ b/fs/ext4/migrate.c
@@ -475,7 +475,7 @@ int ext4_ext_migrate(struct inode *inode)
475 EXT4_INODES_PER_GROUP(inode->i_sb)) + 1; 475 EXT4_INODES_PER_GROUP(inode->i_sb)) + 1;
476 owner[0] = i_uid_read(inode); 476 owner[0] = i_uid_read(inode);
477 owner[1] = i_gid_read(inode); 477 owner[1] = i_gid_read(inode);
478 tmp_inode = ext4_new_inode(handle, inode->i_sb->s_root->d_inode, 478 tmp_inode = ext4_new_inode(handle, d_inode(inode->i_sb->s_root),
479 S_IFREG, NULL, goal, owner); 479 S_IFREG, NULL, goal, owner);
480 if (IS_ERR(tmp_inode)) { 480 if (IS_ERR(tmp_inode)) {
481 retval = PTR_ERR(tmp_inode); 481 retval = PTR_ERR(tmp_inode);
diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
index ef22cd951c0c..7223b0b4bc38 100644
--- a/fs/ext4/namei.c
+++ b/fs/ext4/namei.c
@@ -1664,7 +1664,7 @@ struct dentry *ext4_get_parent(struct dentry *child)
1664 struct ext4_dir_entry_2 * de; 1664 struct ext4_dir_entry_2 * de;
1665 struct buffer_head *bh; 1665 struct buffer_head *bh;
1666 1666
1667 bh = ext4_find_entry(child->d_inode, &dotdot, &de, NULL); 1667 bh = ext4_find_entry(d_inode(child), &dotdot, &de, NULL);
1668 if (IS_ERR(bh)) 1668 if (IS_ERR(bh))
1669 return (struct dentry *) bh; 1669 return (struct dentry *) bh;
1670 if (!bh) 1670 if (!bh)
@@ -1672,13 +1672,13 @@ struct dentry *ext4_get_parent(struct dentry *child)
1672 ino = le32_to_cpu(de->inode); 1672 ino = le32_to_cpu(de->inode);
1673 brelse(bh); 1673 brelse(bh);
1674 1674
1675 if (!ext4_valid_inum(child->d_inode->i_sb, ino)) { 1675 if (!ext4_valid_inum(d_inode(child)->i_sb, ino)) {
1676 EXT4_ERROR_INODE(child->d_inode, 1676 EXT4_ERROR_INODE(d_inode(child),
1677 "bad parent inode number: %u", ino); 1677 "bad parent inode number: %u", ino);
1678 return ERR_PTR(-EIO); 1678 return ERR_PTR(-EIO);
1679 } 1679 }
1680 1680
1681 return d_obtain_alias(ext4_iget_normal(child->d_inode->i_sb, ino)); 1681 return d_obtain_alias(ext4_iget_normal(d_inode(child)->i_sb, ino));
1682} 1682}
1683 1683
1684/* 1684/*
@@ -1988,7 +1988,7 @@ static int add_dirent_to_buf(handle_t *handle, struct dentry *dentry,
1988 struct inode *inode, struct ext4_dir_entry_2 *de, 1988 struct inode *inode, struct ext4_dir_entry_2 *de,
1989 struct buffer_head *bh) 1989 struct buffer_head *bh)
1990{ 1990{
1991 struct inode *dir = dentry->d_parent->d_inode; 1991 struct inode *dir = d_inode(dentry->d_parent);
1992 const char *name = dentry->d_name.name; 1992 const char *name = dentry->d_name.name;
1993 int namelen = dentry->d_name.len; 1993 int namelen = dentry->d_name.len;
1994 unsigned int blocksize = dir->i_sb->s_blocksize; 1994 unsigned int blocksize = dir->i_sb->s_blocksize;
@@ -2048,7 +2048,7 @@ static int add_dirent_to_buf(handle_t *handle, struct dentry *dentry,
2048static int make_indexed_dir(handle_t *handle, struct dentry *dentry, 2048static int make_indexed_dir(handle_t *handle, struct dentry *dentry,
2049 struct inode *inode, struct buffer_head *bh) 2049 struct inode *inode, struct buffer_head *bh)
2050{ 2050{
2051 struct inode *dir = dentry->d_parent->d_inode; 2051 struct inode *dir = d_inode(dentry->d_parent);
2052#ifdef CONFIG_EXT4_FS_ENCRYPTION 2052#ifdef CONFIG_EXT4_FS_ENCRYPTION
2053 struct ext4_fname_crypto_ctx *ctx = NULL; 2053 struct ext4_fname_crypto_ctx *ctx = NULL;
2054 int res; 2054 int res;
@@ -2202,7 +2202,7 @@ out_frames:
2202static int ext4_add_entry(handle_t *handle, struct dentry *dentry, 2202static int ext4_add_entry(handle_t *handle, struct dentry *dentry,
2203 struct inode *inode) 2203 struct inode *inode)
2204{ 2204{
2205 struct inode *dir = dentry->d_parent->d_inode; 2205 struct inode *dir = d_inode(dentry->d_parent);
2206 struct buffer_head *bh = NULL; 2206 struct buffer_head *bh = NULL;
2207 struct ext4_dir_entry_2 *de; 2207 struct ext4_dir_entry_2 *de;
2208 struct ext4_dir_entry_tail *t; 2208 struct ext4_dir_entry_tail *t;
@@ -2287,7 +2287,7 @@ static int ext4_dx_add_entry(handle_t *handle, struct dentry *dentry,
2287 struct dx_entry *entries, *at; 2287 struct dx_entry *entries, *at;
2288 struct dx_hash_info hinfo; 2288 struct dx_hash_info hinfo;
2289 struct buffer_head *bh; 2289 struct buffer_head *bh;
2290 struct inode *dir = dentry->d_parent->d_inode; 2290 struct inode *dir = d_inode(dentry->d_parent);
2291 struct super_block *sb = dir->i_sb; 2291 struct super_block *sb = dir->i_sb;
2292 struct ext4_dir_entry_2 *de; 2292 struct ext4_dir_entry_2 *de;
2293 int err; 2293 int err;
@@ -3063,7 +3063,7 @@ static int ext4_rmdir(struct inode *dir, struct dentry *dentry)
3063 /* Initialize quotas before so that eventual writes go in 3063 /* Initialize quotas before so that eventual writes go in
3064 * separate transaction */ 3064 * separate transaction */
3065 dquot_initialize(dir); 3065 dquot_initialize(dir);
3066 dquot_initialize(dentry->d_inode); 3066 dquot_initialize(d_inode(dentry));
3067 3067
3068 retval = -ENOENT; 3068 retval = -ENOENT;
3069 bh = ext4_find_entry(dir, &dentry->d_name, &de, NULL); 3069 bh = ext4_find_entry(dir, &dentry->d_name, &de, NULL);
@@ -3072,7 +3072,7 @@ static int ext4_rmdir(struct inode *dir, struct dentry *dentry)
3072 if (!bh) 3072 if (!bh)
3073 goto end_rmdir; 3073 goto end_rmdir;
3074 3074
3075 inode = dentry->d_inode; 3075 inode = d_inode(dentry);
3076 3076
3077 retval = -EIO; 3077 retval = -EIO;
3078 if (le32_to_cpu(de->inode) != inode->i_ino) 3078 if (le32_to_cpu(de->inode) != inode->i_ino)
@@ -3132,7 +3132,7 @@ static int ext4_unlink(struct inode *dir, struct dentry *dentry)
3132 /* Initialize quotas before so that eventual writes go 3132 /* Initialize quotas before so that eventual writes go
3133 * in separate transaction */ 3133 * in separate transaction */
3134 dquot_initialize(dir); 3134 dquot_initialize(dir);
3135 dquot_initialize(dentry->d_inode); 3135 dquot_initialize(d_inode(dentry));
3136 3136
3137 retval = -ENOENT; 3137 retval = -ENOENT;
3138 bh = ext4_find_entry(dir, &dentry->d_name, &de, NULL); 3138 bh = ext4_find_entry(dir, &dentry->d_name, &de, NULL);
@@ -3141,7 +3141,7 @@ static int ext4_unlink(struct inode *dir, struct dentry *dentry)
3141 if (!bh) 3141 if (!bh)
3142 goto end_unlink; 3142 goto end_unlink;
3143 3143
3144 inode = dentry->d_inode; 3144 inode = d_inode(dentry);
3145 3145
3146 retval = -EIO; 3146 retval = -EIO;
3147 if (le32_to_cpu(de->inode) != inode->i_ino) 3147 if (le32_to_cpu(de->inode) != inode->i_ino)
@@ -3339,7 +3339,7 @@ static int ext4_link(struct dentry *old_dentry,
3339 struct inode *dir, struct dentry *dentry) 3339 struct inode *dir, struct dentry *dentry)
3340{ 3340{
3341 handle_t *handle; 3341 handle_t *handle;
3342 struct inode *inode = old_dentry->d_inode; 3342 struct inode *inode = d_inode(old_dentry);
3343 int err, retries = 0; 3343 int err, retries = 0;
3344 3344
3345 if (inode->i_nlink >= EXT4_LINK_MAX) 3345 if (inode->i_nlink >= EXT4_LINK_MAX)
@@ -3613,12 +3613,12 @@ static int ext4_rename(struct inode *old_dir, struct dentry *old_dentry,
3613 struct ext4_renament old = { 3613 struct ext4_renament old = {
3614 .dir = old_dir, 3614 .dir = old_dir,
3615 .dentry = old_dentry, 3615 .dentry = old_dentry,
3616 .inode = old_dentry->d_inode, 3616 .inode = d_inode(old_dentry),
3617 }; 3617 };
3618 struct ext4_renament new = { 3618 struct ext4_renament new = {
3619 .dir = new_dir, 3619 .dir = new_dir,
3620 .dentry = new_dentry, 3620 .dentry = new_dentry,
3621 .inode = new_dentry->d_inode, 3621 .inode = d_inode(new_dentry),
3622 }; 3622 };
3623 int force_reread; 3623 int force_reread;
3624 int retval; 3624 int retval;
@@ -3809,12 +3809,12 @@ static int ext4_cross_rename(struct inode *old_dir, struct dentry *old_dentry,
3809 struct ext4_renament old = { 3809 struct ext4_renament old = {
3810 .dir = old_dir, 3810 .dir = old_dir,
3811 .dentry = old_dentry, 3811 .dentry = old_dentry,
3812 .inode = old_dentry->d_inode, 3812 .inode = d_inode(old_dentry),
3813 }; 3813 };
3814 struct ext4_renament new = { 3814 struct ext4_renament new = {
3815 .dir = new_dir, 3815 .dir = new_dir,
3816 .dentry = new_dentry, 3816 .dentry = new_dentry,
3817 .inode = new_dentry->d_inode, 3817 .inode = d_inode(new_dentry),
3818 }; 3818 };
3819 u8 new_file_type; 3819 u8 new_file_type;
3820 int retval; 3820 int retval;
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 821f22dbe825..f06d0589ddba 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -1556,7 +1556,7 @@ static int handle_mount_opt(struct super_block *sb, char *opt, int token,
1556 return -1; 1556 return -1;
1557 } 1557 }
1558 1558
1559 journal_inode = path.dentry->d_inode; 1559 journal_inode = d_inode(path.dentry);
1560 if (!S_ISBLK(journal_inode->i_mode)) { 1560 if (!S_ISBLK(journal_inode->i_mode)) {
1561 ext4_msg(sb, KERN_ERR, "error: journal path %s " 1561 ext4_msg(sb, KERN_ERR, "error: journal path %s "
1562 "is not a block device", journal_path); 1562 "is not a block device", journal_path);
@@ -5217,7 +5217,7 @@ static int ext4_write_info(struct super_block *sb, int type)
5217 handle_t *handle; 5217 handle_t *handle;
5218 5218
5219 /* Data block + inode block */ 5219 /* Data block + inode block */
5220 handle = ext4_journal_start(sb->s_root->d_inode, EXT4_HT_QUOTA, 2); 5220 handle = ext4_journal_start(d_inode(sb->s_root), EXT4_HT_QUOTA, 2);
5221 if (IS_ERR(handle)) 5221 if (IS_ERR(handle))
5222 return PTR_ERR(handle); 5222 return PTR_ERR(handle);
5223 ret = dquot_commit_info(sb, type); 5223 ret = dquot_commit_info(sb, type);
@@ -5265,7 +5265,7 @@ static int ext4_quota_on(struct super_block *sb, int type, int format_id,
5265 * all updates to the file when we bypass pagecache... 5265 * all updates to the file when we bypass pagecache...
5266 */ 5266 */
5267 if (EXT4_SB(sb)->s_journal && 5267 if (EXT4_SB(sb)->s_journal &&
5268 ext4_should_journal_data(path->dentry->d_inode)) { 5268 ext4_should_journal_data(d_inode(path->dentry))) {
5269 /* 5269 /*
5270 * We don't need to lock updates but journal_flush() could 5270 * We don't need to lock updates but journal_flush() could
5271 * otherwise be livelocked... 5271 * otherwise be livelocked...
diff --git a/fs/ext4/symlink.c b/fs/ext4/symlink.c
index 136ca0e911fd..19f78f20975e 100644
--- a/fs/ext4/symlink.c
+++ b/fs/ext4/symlink.c
@@ -28,7 +28,7 @@ static void *ext4_follow_link(struct dentry *dentry, struct nameidata *nd)
28 struct page *cpage = NULL; 28 struct page *cpage = NULL;
29 char *caddr, *paddr = NULL; 29 char *caddr, *paddr = NULL;
30 struct ext4_str cstr, pstr; 30 struct ext4_str cstr, pstr;
31 struct inode *inode = dentry->d_inode; 31 struct inode *inode = d_inode(dentry);
32 struct ext4_fname_crypto_ctx *ctx = NULL; 32 struct ext4_fname_crypto_ctx *ctx = NULL;
33 struct ext4_encrypted_symlink_data *sd; 33 struct ext4_encrypted_symlink_data *sd;
34 loff_t size = min_t(loff_t, i_size_read(inode), PAGE_SIZE - 1); 34 loff_t size = min_t(loff_t, i_size_read(inode), PAGE_SIZE - 1);
@@ -43,8 +43,8 @@ static void *ext4_follow_link(struct dentry *dentry, struct nameidata *nd)
43 return ctx; 43 return ctx;
44 44
45 if (ext4_inode_is_fast_symlink(inode)) { 45 if (ext4_inode_is_fast_symlink(inode)) {
46 caddr = (char *) EXT4_I(dentry->d_inode)->i_data; 46 caddr = (char *) EXT4_I(inode)->i_data;
47 max_size = sizeof(EXT4_I(dentry->d_inode)->i_data); 47 max_size = sizeof(EXT4_I(inode)->i_data);
48 } else { 48 } else {
49 cpage = read_mapping_page(inode->i_mapping, 0, NULL); 49 cpage = read_mapping_page(inode->i_mapping, 0, NULL);
50 if (IS_ERR(cpage)) { 50 if (IS_ERR(cpage)) {
@@ -113,7 +113,7 @@ static void ext4_put_link(struct dentry *dentry, struct nameidata *nd,
113 113
114static void *ext4_follow_fast_link(struct dentry *dentry, struct nameidata *nd) 114static void *ext4_follow_fast_link(struct dentry *dentry, struct nameidata *nd)
115{ 115{
116 struct ext4_inode_info *ei = EXT4_I(dentry->d_inode); 116 struct ext4_inode_info *ei = EXT4_I(d_inode(dentry));
117 nd_set_link(nd, (char *) ei->i_data); 117 nd_set_link(nd, (char *) ei->i_data);
118 return NULL; 118 return NULL;
119} 119}
diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
index 759842ff8af0..16e28c08d1e8 100644
--- a/fs/ext4/xattr.c
+++ b/fs/ext4/xattr.c
@@ -178,7 +178,7 @@ ext4_xattr_handler(int name_index)
178/* 178/*
179 * Inode operation listxattr() 179 * Inode operation listxattr()
180 * 180 *
181 * dentry->d_inode->i_mutex: don't care 181 * d_inode(dentry)->i_mutex: don't care
182 */ 182 */
183ssize_t 183ssize_t
184ext4_listxattr(struct dentry *dentry, char *buffer, size_t size) 184ext4_listxattr(struct dentry *dentry, char *buffer, size_t size)
@@ -423,7 +423,7 @@ ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
423static int 423static int
424ext4_xattr_block_list(struct dentry *dentry, char *buffer, size_t buffer_size) 424ext4_xattr_block_list(struct dentry *dentry, char *buffer, size_t buffer_size)
425{ 425{
426 struct inode *inode = dentry->d_inode; 426 struct inode *inode = d_inode(dentry);
427 struct buffer_head *bh = NULL; 427 struct buffer_head *bh = NULL;
428 int error; 428 int error;
429 struct mb_cache *ext4_mb_cache = EXT4_GET_MB_CACHE(inode); 429 struct mb_cache *ext4_mb_cache = EXT4_GET_MB_CACHE(inode);
@@ -460,7 +460,7 @@ cleanup:
460static int 460static int
461ext4_xattr_ibody_list(struct dentry *dentry, char *buffer, size_t buffer_size) 461ext4_xattr_ibody_list(struct dentry *dentry, char *buffer, size_t buffer_size)
462{ 462{
463 struct inode *inode = dentry->d_inode; 463 struct inode *inode = d_inode(dentry);
464 struct ext4_xattr_ibody_header *header; 464 struct ext4_xattr_ibody_header *header;
465 struct ext4_inode *raw_inode; 465 struct ext4_inode *raw_inode;
466 struct ext4_iloc iloc; 466 struct ext4_iloc iloc;
@@ -501,7 +501,7 @@ ext4_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
501{ 501{
502 int ret, ret2; 502 int ret, ret2;
503 503
504 down_read(&EXT4_I(dentry->d_inode)->xattr_sem); 504 down_read(&EXT4_I(d_inode(dentry))->xattr_sem);
505 ret = ret2 = ext4_xattr_ibody_list(dentry, buffer, buffer_size); 505 ret = ret2 = ext4_xattr_ibody_list(dentry, buffer, buffer_size);
506 if (ret < 0) 506 if (ret < 0)
507 goto errout; 507 goto errout;
@@ -514,7 +514,7 @@ ext4_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
514 goto errout; 514 goto errout;
515 ret += ret2; 515 ret += ret2;
516errout: 516errout:
517 up_read(&EXT4_I(dentry->d_inode)->xattr_sem); 517 up_read(&EXT4_I(d_inode(dentry))->xattr_sem);
518 return ret; 518 return ret;
519} 519}
520 520
diff --git a/fs/ext4/xattr_security.c b/fs/ext4/xattr_security.c
index d2a200624af5..95d90e0560f0 100644
--- a/fs/ext4/xattr_security.c
+++ b/fs/ext4/xattr_security.c
@@ -33,7 +33,7 @@ ext4_xattr_security_get(struct dentry *dentry, const char *name,
33{ 33{
34 if (strcmp(name, "") == 0) 34 if (strcmp(name, "") == 0)
35 return -EINVAL; 35 return -EINVAL;
36 return ext4_xattr_get(dentry->d_inode, EXT4_XATTR_INDEX_SECURITY, 36 return ext4_xattr_get(d_inode(dentry), EXT4_XATTR_INDEX_SECURITY,
37 name, buffer, size); 37 name, buffer, size);
38} 38}
39 39
@@ -43,7 +43,7 @@ ext4_xattr_security_set(struct dentry *dentry, const char *name,
43{ 43{
44 if (strcmp(name, "") == 0) 44 if (strcmp(name, "") == 0)
45 return -EINVAL; 45 return -EINVAL;
46 return ext4_xattr_set(dentry->d_inode, EXT4_XATTR_INDEX_SECURITY, 46 return ext4_xattr_set(d_inode(dentry), EXT4_XATTR_INDEX_SECURITY,
47 name, value, size, flags); 47 name, value, size, flags);
48} 48}
49 49
diff --git a/fs/ext4/xattr_trusted.c b/fs/ext4/xattr_trusted.c
index 95f1f4ab59a4..891ee2ddfbd6 100644
--- a/fs/ext4/xattr_trusted.c
+++ b/fs/ext4/xattr_trusted.c
@@ -36,7 +36,7 @@ ext4_xattr_trusted_get(struct dentry *dentry, const char *name, void *buffer,
36{ 36{
37 if (strcmp(name, "") == 0) 37 if (strcmp(name, "") == 0)
38 return -EINVAL; 38 return -EINVAL;
39 return ext4_xattr_get(dentry->d_inode, EXT4_XATTR_INDEX_TRUSTED, 39 return ext4_xattr_get(d_inode(dentry), EXT4_XATTR_INDEX_TRUSTED,
40 name, buffer, size); 40 name, buffer, size);
41} 41}
42 42
@@ -46,7 +46,7 @@ ext4_xattr_trusted_set(struct dentry *dentry, const char *name,
46{ 46{
47 if (strcmp(name, "") == 0) 47 if (strcmp(name, "") == 0)
48 return -EINVAL; 48 return -EINVAL;
49 return ext4_xattr_set(dentry->d_inode, EXT4_XATTR_INDEX_TRUSTED, 49 return ext4_xattr_set(d_inode(dentry), EXT4_XATTR_INDEX_TRUSTED,
50 name, value, size, flags); 50 name, value, size, flags);
51} 51}
52 52
diff --git a/fs/ext4/xattr_user.c b/fs/ext4/xattr_user.c
index 0edb7611ffbe..6ed932b3c043 100644
--- a/fs/ext4/xattr_user.c
+++ b/fs/ext4/xattr_user.c
@@ -37,7 +37,7 @@ ext4_xattr_user_get(struct dentry *dentry, const char *name,
37 return -EINVAL; 37 return -EINVAL;
38 if (!test_opt(dentry->d_sb, XATTR_USER)) 38 if (!test_opt(dentry->d_sb, XATTR_USER))
39 return -EOPNOTSUPP; 39 return -EOPNOTSUPP;
40 return ext4_xattr_get(dentry->d_inode, EXT4_XATTR_INDEX_USER, 40 return ext4_xattr_get(d_inode(dentry), EXT4_XATTR_INDEX_USER,
41 name, buffer, size); 41 name, buffer, size);
42} 42}
43 43
@@ -49,7 +49,7 @@ ext4_xattr_user_set(struct dentry *dentry, const char *name,
49 return -EINVAL; 49 return -EINVAL;
50 if (!test_opt(dentry->d_sb, XATTR_USER)) 50 if (!test_opt(dentry->d_sb, XATTR_USER))
51 return -EOPNOTSUPP; 51 return -EOPNOTSUPP;
52 return ext4_xattr_set(dentry->d_inode, EXT4_XATTR_INDEX_USER, 52 return ext4_xattr_set(d_inode(dentry), EXT4_XATTR_INDEX_USER,
53 name, value, size, flags); 53 name, value, size, flags);
54} 54}
55 55
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index c06a25e5cec3..d8921cf2ba9a 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -1482,7 +1482,7 @@ bool f2fs_empty_dir(struct inode *);
1482 1482
1483static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode) 1483static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode)
1484{ 1484{
1485 return __f2fs_add_link(dentry->d_parent->d_inode, &dentry->d_name, 1485 return __f2fs_add_link(d_inode(dentry->d_parent), &dentry->d_name,
1486 inode, inode->i_ino, inode->i_mode); 1486 inode, inode->i_ino, inode->i_mode);
1487} 1487}
1488 1488
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index a6f3f6186588..2b52e48d7482 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -574,7 +574,7 @@ void f2fs_truncate(struct inode *inode)
574int f2fs_getattr(struct vfsmount *mnt, 574int f2fs_getattr(struct vfsmount *mnt,
575 struct dentry *dentry, struct kstat *stat) 575 struct dentry *dentry, struct kstat *stat)
576{ 576{
577 struct inode *inode = dentry->d_inode; 577 struct inode *inode = d_inode(dentry);
578 generic_fillattr(inode, stat); 578 generic_fillattr(inode, stat);
579 stat->blocks <<= 3; 579 stat->blocks <<= 3;
580 return 0; 580 return 0;
@@ -613,7 +613,7 @@ static void __setattr_copy(struct inode *inode, const struct iattr *attr)
613 613
614int f2fs_setattr(struct dentry *dentry, struct iattr *attr) 614int f2fs_setattr(struct dentry *dentry, struct iattr *attr)
615{ 615{
616 struct inode *inode = dentry->d_inode; 616 struct inode *inode = d_inode(dentry);
617 struct f2fs_inode_info *fi = F2FS_I(inode); 617 struct f2fs_inode_info *fi = F2FS_I(inode);
618 int err; 618 int err;
619 619
diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c
index 407dde3d7a92..7e3794edae42 100644
--- a/fs/f2fs/namei.c
+++ b/fs/f2fs/namei.c
@@ -151,7 +151,7 @@ out:
151static int f2fs_link(struct dentry *old_dentry, struct inode *dir, 151static int f2fs_link(struct dentry *old_dentry, struct inode *dir,
152 struct dentry *dentry) 152 struct dentry *dentry)
153{ 153{
154 struct inode *inode = old_dentry->d_inode; 154 struct inode *inode = d_inode(old_dentry);
155 struct f2fs_sb_info *sbi = F2FS_I_SB(dir); 155 struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
156 int err; 156 int err;
157 157
@@ -182,10 +182,10 @@ out:
182struct dentry *f2fs_get_parent(struct dentry *child) 182struct dentry *f2fs_get_parent(struct dentry *child)
183{ 183{
184 struct qstr dotdot = QSTR_INIT("..", 2); 184 struct qstr dotdot = QSTR_INIT("..", 2);
185 unsigned long ino = f2fs_inode_by_name(child->d_inode, &dotdot); 185 unsigned long ino = f2fs_inode_by_name(d_inode(child), &dotdot);
186 if (!ino) 186 if (!ino)
187 return ERR_PTR(-ENOENT); 187 return ERR_PTR(-ENOENT);
188 return d_obtain_alias(f2fs_iget(child->d_inode->i_sb, ino)); 188 return d_obtain_alias(f2fs_iget(d_inode(child)->i_sb, ino));
189} 189}
190 190
191static int __recover_dot_dentries(struct inode *dir, nid_t pino) 191static int __recover_dot_dentries(struct inode *dir, nid_t pino)
@@ -263,7 +263,7 @@ static struct dentry *f2fs_lookup(struct inode *dir, struct dentry *dentry,
263static int f2fs_unlink(struct inode *dir, struct dentry *dentry) 263static int f2fs_unlink(struct inode *dir, struct dentry *dentry)
264{ 264{
265 struct f2fs_sb_info *sbi = F2FS_I_SB(dir); 265 struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
266 struct inode *inode = dentry->d_inode; 266 struct inode *inode = d_inode(dentry);
267 struct f2fs_dir_entry *de; 267 struct f2fs_dir_entry *de;
268 struct page *page; 268 struct page *page;
269 int err = -ENOENT; 269 int err = -ENOENT;
@@ -403,7 +403,7 @@ out_fail:
403 403
404static int f2fs_rmdir(struct inode *dir, struct dentry *dentry) 404static int f2fs_rmdir(struct inode *dir, struct dentry *dentry)
405{ 405{
406 struct inode *inode = dentry->d_inode; 406 struct inode *inode = d_inode(dentry);
407 if (f2fs_empty_dir(inode)) 407 if (f2fs_empty_dir(inode))
408 return f2fs_unlink(dir, dentry); 408 return f2fs_unlink(dir, dentry);
409 return -ENOTEMPTY; 409 return -ENOTEMPTY;
@@ -451,8 +451,8 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry,
451 struct inode *new_dir, struct dentry *new_dentry) 451 struct inode *new_dir, struct dentry *new_dentry)
452{ 452{
453 struct f2fs_sb_info *sbi = F2FS_I_SB(old_dir); 453 struct f2fs_sb_info *sbi = F2FS_I_SB(old_dir);
454 struct inode *old_inode = old_dentry->d_inode; 454 struct inode *old_inode = d_inode(old_dentry);
455 struct inode *new_inode = new_dentry->d_inode; 455 struct inode *new_inode = d_inode(new_dentry);
456 struct page *old_dir_page; 456 struct page *old_dir_page;
457 struct page *old_page, *new_page; 457 struct page *old_page, *new_page;
458 struct f2fs_dir_entry *old_dir_entry = NULL; 458 struct f2fs_dir_entry *old_dir_entry = NULL;
@@ -578,8 +578,8 @@ static int f2fs_cross_rename(struct inode *old_dir, struct dentry *old_dentry,
578 struct inode *new_dir, struct dentry *new_dentry) 578 struct inode *new_dir, struct dentry *new_dentry)
579{ 579{
580 struct f2fs_sb_info *sbi = F2FS_I_SB(old_dir); 580 struct f2fs_sb_info *sbi = F2FS_I_SB(old_dir);
581 struct inode *old_inode = old_dentry->d_inode; 581 struct inode *old_inode = d_inode(old_dentry);
582 struct inode *new_inode = new_dentry->d_inode; 582 struct inode *new_inode = d_inode(new_dentry);
583 struct page *old_dir_page, *new_dir_page; 583 struct page *old_dir_page, *new_dir_page;
584 struct page *old_page, *new_page; 584 struct page *old_page, *new_page;
585 struct f2fs_dir_entry *old_dir_entry = NULL, *new_dir_entry = NULL; 585 struct f2fs_dir_entry *old_dir_entry = NULL, *new_dir_entry = NULL;
diff --git a/fs/f2fs/xattr.c b/fs/f2fs/xattr.c
index b0fd2f2d0716..9757f65a05bc 100644
--- a/fs/f2fs/xattr.c
+++ b/fs/f2fs/xattr.c
@@ -83,7 +83,7 @@ static int f2fs_xattr_generic_get(struct dentry *dentry, const char *name,
83 } 83 }
84 if (strcmp(name, "") == 0) 84 if (strcmp(name, "") == 0)
85 return -EINVAL; 85 return -EINVAL;
86 return f2fs_getxattr(dentry->d_inode, type, name, buffer, size, NULL); 86 return f2fs_getxattr(d_inode(dentry), type, name, buffer, size, NULL);
87} 87}
88 88
89static int f2fs_xattr_generic_set(struct dentry *dentry, const char *name, 89static int f2fs_xattr_generic_set(struct dentry *dentry, const char *name,
@@ -108,7 +108,7 @@ static int f2fs_xattr_generic_set(struct dentry *dentry, const char *name,
108 if (strcmp(name, "") == 0) 108 if (strcmp(name, "") == 0)
109 return -EINVAL; 109 return -EINVAL;
110 110
111 return f2fs_setxattr(dentry->d_inode, type, name, 111 return f2fs_setxattr(d_inode(dentry), type, name,
112 value, size, NULL, flags); 112 value, size, NULL, flags);
113} 113}
114 114
@@ -130,7 +130,7 @@ static size_t f2fs_xattr_advise_list(struct dentry *dentry, char *list,
130static int f2fs_xattr_advise_get(struct dentry *dentry, const char *name, 130static int f2fs_xattr_advise_get(struct dentry *dentry, const char *name,
131 void *buffer, size_t size, int type) 131 void *buffer, size_t size, int type)
132{ 132{
133 struct inode *inode = dentry->d_inode; 133 struct inode *inode = d_inode(dentry);
134 134
135 if (strcmp(name, "") != 0) 135 if (strcmp(name, "") != 0)
136 return -EINVAL; 136 return -EINVAL;
@@ -143,7 +143,7 @@ static int f2fs_xattr_advise_get(struct dentry *dentry, const char *name,
143static int f2fs_xattr_advise_set(struct dentry *dentry, const char *name, 143static int f2fs_xattr_advise_set(struct dentry *dentry, const char *name,
144 const void *value, size_t size, int flags, int type) 144 const void *value, size_t size, int flags, int type)
145{ 145{
146 struct inode *inode = dentry->d_inode; 146 struct inode *inode = d_inode(dentry);
147 147
148 if (strcmp(name, "") != 0) 148 if (strcmp(name, "") != 0)
149 return -EINVAL; 149 return -EINVAL;
@@ -444,7 +444,7 @@ cleanup:
444 444
445ssize_t f2fs_listxattr(struct dentry *dentry, char *buffer, size_t buffer_size) 445ssize_t f2fs_listxattr(struct dentry *dentry, char *buffer, size_t buffer_size)
446{ 446{
447 struct inode *inode = dentry->d_inode; 447 struct inode *inode = d_inode(dentry);
448 struct f2fs_xattr_entry *entry; 448 struct f2fs_xattr_entry *entry;
449 void *base_addr; 449 void *base_addr;
450 int error = 0; 450 int error = 0;
diff --git a/fs/fat/file.c b/fs/fat/file.c
index cf50d93565a2..442d50a0e33e 100644
--- a/fs/fat/file.c
+++ b/fs/fat/file.c
@@ -305,7 +305,7 @@ void fat_truncate_blocks(struct inode *inode, loff_t offset)
305 305
306int fat_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat) 306int fat_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
307{ 307{
308 struct inode *inode = dentry->d_inode; 308 struct inode *inode = d_inode(dentry);
309 generic_fillattr(inode, stat); 309 generic_fillattr(inode, stat);
310 stat->blksize = MSDOS_SB(inode->i_sb)->cluster_size; 310 stat->blksize = MSDOS_SB(inode->i_sb)->cluster_size;
311 311
@@ -377,7 +377,7 @@ static int fat_allow_set_time(struct msdos_sb_info *sbi, struct inode *inode)
377int fat_setattr(struct dentry *dentry, struct iattr *attr) 377int fat_setattr(struct dentry *dentry, struct iattr *attr)
378{ 378{
379 struct msdos_sb_info *sbi = MSDOS_SB(dentry->d_sb); 379 struct msdos_sb_info *sbi = MSDOS_SB(dentry->d_sb);
380 struct inode *inode = dentry->d_inode; 380 struct inode *inode = d_inode(dentry);
381 unsigned int ia_valid; 381 unsigned int ia_valid;
382 int error; 382 int error;
383 383
diff --git a/fs/fat/namei_msdos.c b/fs/fat/namei_msdos.c
index cc6a8541b668..b7e2b33aa793 100644
--- a/fs/fat/namei_msdos.c
+++ b/fs/fat/namei_msdos.c
@@ -308,7 +308,7 @@ out:
308static int msdos_rmdir(struct inode *dir, struct dentry *dentry) 308static int msdos_rmdir(struct inode *dir, struct dentry *dentry)
309{ 309{
310 struct super_block *sb = dir->i_sb; 310 struct super_block *sb = dir->i_sb;
311 struct inode *inode = dentry->d_inode; 311 struct inode *inode = d_inode(dentry);
312 struct fat_slot_info sinfo; 312 struct fat_slot_info sinfo;
313 int err; 313 int err;
314 314
@@ -402,7 +402,7 @@ out:
402/***** Unlink a file */ 402/***** Unlink a file */
403static int msdos_unlink(struct inode *dir, struct dentry *dentry) 403static int msdos_unlink(struct inode *dir, struct dentry *dentry)
404{ 404{
405 struct inode *inode = dentry->d_inode; 405 struct inode *inode = d_inode(dentry);
406 struct super_block *sb = inode->i_sb; 406 struct super_block *sb = inode->i_sb;
407 struct fat_slot_info sinfo; 407 struct fat_slot_info sinfo;
408 int err; 408 int err;
@@ -440,8 +440,8 @@ static int do_msdos_rename(struct inode *old_dir, unsigned char *old_name,
440 int err, old_attrs, is_dir, update_dotdot, corrupt = 0; 440 int err, old_attrs, is_dir, update_dotdot, corrupt = 0;
441 441
442 old_sinfo.bh = sinfo.bh = dotdot_bh = NULL; 442 old_sinfo.bh = sinfo.bh = dotdot_bh = NULL;
443 old_inode = old_dentry->d_inode; 443 old_inode = d_inode(old_dentry);
444 new_inode = new_dentry->d_inode; 444 new_inode = d_inode(new_dentry);
445 445
446 err = fat_scan(old_dir, old_name, &old_sinfo); 446 err = fat_scan(old_dir, old_name, &old_sinfo);
447 if (err) { 447 if (err) {
diff --git a/fs/fat/namei_vfat.c b/fs/fat/namei_vfat.c
index 7e0974eebd8e..7092584f424a 100644
--- a/fs/fat/namei_vfat.c
+++ b/fs/fat/namei_vfat.c
@@ -33,7 +33,7 @@ static int vfat_revalidate_shortname(struct dentry *dentry)
33{ 33{
34 int ret = 1; 34 int ret = 1;
35 spin_lock(&dentry->d_lock); 35 spin_lock(&dentry->d_lock);
36 if (dentry->d_time != dentry->d_parent->d_inode->i_version) 36 if (dentry->d_time != d_inode(dentry->d_parent)->i_version)
37 ret = 0; 37 ret = 0;
38 spin_unlock(&dentry->d_lock); 38 spin_unlock(&dentry->d_lock);
39 return ret; 39 return ret;
@@ -45,7 +45,7 @@ static int vfat_revalidate(struct dentry *dentry, unsigned int flags)
45 return -ECHILD; 45 return -ECHILD;
46 46
47 /* This is not negative dentry. Always valid. */ 47 /* This is not negative dentry. Always valid. */
48 if (dentry->d_inode) 48 if (d_really_is_positive(dentry))
49 return 1; 49 return 1;
50 return vfat_revalidate_shortname(dentry); 50 return vfat_revalidate_shortname(dentry);
51} 51}
@@ -65,7 +65,7 @@ static int vfat_revalidate_ci(struct dentry *dentry, unsigned int flags)
65 * positive dentry isn't good idea. So it's unsupported like 65 * positive dentry isn't good idea. So it's unsupported like
66 * rename("filename", "FILENAME") for now. 66 * rename("filename", "FILENAME") for now.
67 */ 67 */
68 if (dentry->d_inode) 68 if (d_really_is_positive(dentry))
69 return 1; 69 return 1;
70 70
71 /* 71 /*
@@ -801,7 +801,7 @@ out:
801 801
802static int vfat_rmdir(struct inode *dir, struct dentry *dentry) 802static int vfat_rmdir(struct inode *dir, struct dentry *dentry)
803{ 803{
804 struct inode *inode = dentry->d_inode; 804 struct inode *inode = d_inode(dentry);
805 struct super_block *sb = dir->i_sb; 805 struct super_block *sb = dir->i_sb;
806 struct fat_slot_info sinfo; 806 struct fat_slot_info sinfo;
807 int err; 807 int err;
@@ -832,7 +832,7 @@ out:
832 832
833static int vfat_unlink(struct inode *dir, struct dentry *dentry) 833static int vfat_unlink(struct inode *dir, struct dentry *dentry)
834{ 834{
835 struct inode *inode = dentry->d_inode; 835 struct inode *inode = d_inode(dentry);
836 struct super_block *sb = dir->i_sb; 836 struct super_block *sb = dir->i_sb;
837 struct fat_slot_info sinfo; 837 struct fat_slot_info sinfo;
838 int err; 838 int err;
@@ -915,8 +915,8 @@ static int vfat_rename(struct inode *old_dir, struct dentry *old_dentry,
915 struct super_block *sb = old_dir->i_sb; 915 struct super_block *sb = old_dir->i_sb;
916 916
917 old_sinfo.bh = sinfo.bh = dotdot_bh = NULL; 917 old_sinfo.bh = sinfo.bh = dotdot_bh = NULL;
918 old_inode = old_dentry->d_inode; 918 old_inode = d_inode(old_dentry);
919 new_inode = new_dentry->d_inode; 919 new_inode = d_inode(new_dentry);
920 mutex_lock(&MSDOS_SB(sb)->s_lock); 920 mutex_lock(&MSDOS_SB(sb)->s_lock);
921 err = vfat_find(old_dir, &old_dentry->d_name, &old_sinfo); 921 err = vfat_find(old_dir, &old_dentry->d_name, &old_sinfo);
922 if (err) 922 if (err)
diff --git a/fs/fat/nfs.c b/fs/fat/nfs.c
index 93e14933dcb6..eb192656fba2 100644
--- a/fs/fat/nfs.c
+++ b/fs/fat/nfs.c
@@ -266,7 +266,7 @@ struct inode *fat_rebuild_parent(struct super_block *sb, int parent_logstart)
266 * Find the parent for a directory that is not currently connected to 266 * Find the parent for a directory that is not currently connected to
267 * the filesystem root. 267 * the filesystem root.
268 * 268 *
269 * On entry, the caller holds child_dir->d_inode->i_mutex. 269 * On entry, the caller holds d_inode(child_dir)->i_mutex.
270 */ 270 */
271static struct dentry *fat_get_parent(struct dentry *child_dir) 271static struct dentry *fat_get_parent(struct dentry *child_dir)
272{ 272{
@@ -276,7 +276,7 @@ static struct dentry *fat_get_parent(struct dentry *child_dir)
276 struct inode *parent_inode = NULL; 276 struct inode *parent_inode = NULL;
277 struct msdos_sb_info *sbi = MSDOS_SB(sb); 277 struct msdos_sb_info *sbi = MSDOS_SB(sb);
278 278
279 if (!fat_get_dotdot_entry(child_dir->d_inode, &bh, &de)) { 279 if (!fat_get_dotdot_entry(d_inode(child_dir), &bh, &de)) {
280 int parent_logstart = fat_get_start(sbi, de); 280 int parent_logstart = fat_get_start(sbi, de);
281 parent_inode = fat_dget(sb, parent_logstart); 281 parent_inode = fat_dget(sb, parent_logstart);
282 if (!parent_inode && sbi->options.nfs == FAT_NFS_NOSTALE_RO) 282 if (!parent_inode && sbi->options.nfs == FAT_NFS_NOSTALE_RO)
diff --git a/fs/freevxfs/vxfs_immed.c b/fs/freevxfs/vxfs_immed.c
index c36aeaf92e41..8b9229e2ca5c 100644
--- a/fs/freevxfs/vxfs_immed.c
+++ b/fs/freevxfs/vxfs_immed.c
@@ -76,7 +76,7 @@ const struct address_space_operations vxfs_immed_aops = {
76static void * 76static void *
77vxfs_immed_follow_link(struct dentry *dp, struct nameidata *np) 77vxfs_immed_follow_link(struct dentry *dp, struct nameidata *np)
78{ 78{
79 struct vxfs_inode_info *vip = VXFS_INO(dp->d_inode); 79 struct vxfs_inode_info *vip = VXFS_INO(d_inode(dp));
80 nd_set_link(np, vip->vii_immed.vi_immed); 80 nd_set_link(np, vip->vii_immed.vi_immed);
81 return NULL; 81 return NULL;
82} 82}
diff --git a/fs/fuse/control.c b/fs/fuse/control.c
index 205e0d5d5307..f863ac6647ac 100644
--- a/fs/fuse/control.c
+++ b/fs/fuse/control.c
@@ -244,7 +244,7 @@ int fuse_ctl_add_conn(struct fuse_conn *fc)
244 return 0; 244 return 0;
245 245
246 parent = fuse_control_sb->s_root; 246 parent = fuse_control_sb->s_root;
247 inc_nlink(parent->d_inode); 247 inc_nlink(d_inode(parent));
248 sprintf(name, "%u", fc->dev); 248 sprintf(name, "%u", fc->dev);
249 parent = fuse_ctl_add_dentry(parent, fc, name, S_IFDIR | 0500, 2, 249 parent = fuse_ctl_add_dentry(parent, fc, name, S_IFDIR | 0500, 2,
250 &simple_dir_inode_operations, 250 &simple_dir_inode_operations,
@@ -283,11 +283,11 @@ void fuse_ctl_remove_conn(struct fuse_conn *fc)
283 283
284 for (i = fc->ctl_ndents - 1; i >= 0; i--) { 284 for (i = fc->ctl_ndents - 1; i >= 0; i--) {
285 struct dentry *dentry = fc->ctl_dentry[i]; 285 struct dentry *dentry = fc->ctl_dentry[i];
286 dentry->d_inode->i_private = NULL; 286 d_inode(dentry)->i_private = NULL;
287 d_drop(dentry); 287 d_drop(dentry);
288 dput(dentry); 288 dput(dentry);
289 } 289 }
290 drop_nlink(fuse_control_sb->s_root->d_inode); 290 drop_nlink(d_inode(fuse_control_sb->s_root));
291} 291}
292 292
293static int fuse_ctl_fill_super(struct super_block *sb, void *data, int silent) 293static int fuse_ctl_fill_super(struct super_block *sb, void *data, int silent)
diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
index 1545b711ddcf..0572bca49f15 100644
--- a/fs/fuse/dir.c
+++ b/fs/fuse/dir.c
@@ -192,7 +192,7 @@ static int fuse_dentry_revalidate(struct dentry *entry, unsigned int flags)
192 struct fuse_inode *fi; 192 struct fuse_inode *fi;
193 int ret; 193 int ret;
194 194
195 inode = ACCESS_ONCE(entry->d_inode); 195 inode = d_inode_rcu(entry);
196 if (inode && is_bad_inode(inode)) 196 if (inode && is_bad_inode(inode))
197 goto invalid; 197 goto invalid;
198 else if (time_before64(fuse_dentry_time(entry), get_jiffies_64()) || 198 else if (time_before64(fuse_dentry_time(entry), get_jiffies_64()) ||
@@ -220,7 +220,7 @@ static int fuse_dentry_revalidate(struct dentry *entry, unsigned int flags)
220 attr_version = fuse_get_attr_version(fc); 220 attr_version = fuse_get_attr_version(fc);
221 221
222 parent = dget_parent(entry); 222 parent = dget_parent(entry);
223 fuse_lookup_init(fc, &args, get_node_id(parent->d_inode), 223 fuse_lookup_init(fc, &args, get_node_id(d_inode(parent)),
224 &entry->d_name, &outarg); 224 &entry->d_name, &outarg);
225 ret = fuse_simple_request(fc, &args); 225 ret = fuse_simple_request(fc, &args);
226 dput(parent); 226 dput(parent);
@@ -254,7 +254,7 @@ static int fuse_dentry_revalidate(struct dentry *entry, unsigned int flags)
254 return -ECHILD; 254 return -ECHILD;
255 } else if (test_and_clear_bit(FUSE_I_INIT_RDPLUS, &fi->state)) { 255 } else if (test_and_clear_bit(FUSE_I_INIT_RDPLUS, &fi->state)) {
256 parent = dget_parent(entry); 256 parent = dget_parent(entry);
257 fuse_advise_use_readdirplus(parent->d_inode); 257 fuse_advise_use_readdirplus(d_inode(parent));
258 dput(parent); 258 dput(parent);
259 } 259 }
260 } 260 }
@@ -487,7 +487,7 @@ static int fuse_atomic_open(struct inode *dir, struct dentry *entry,
487 entry = res; 487 entry = res;
488 } 488 }
489 489
490 if (!(flags & O_CREAT) || entry->d_inode) 490 if (!(flags & O_CREAT) || d_really_is_positive(entry))
491 goto no_open; 491 goto no_open;
492 492
493 /* Only creates */ 493 /* Only creates */
@@ -653,7 +653,7 @@ static int fuse_unlink(struct inode *dir, struct dentry *entry)
653 args.in.args[0].value = entry->d_name.name; 653 args.in.args[0].value = entry->d_name.name;
654 err = fuse_simple_request(fc, &args); 654 err = fuse_simple_request(fc, &args);
655 if (!err) { 655 if (!err) {
656 struct inode *inode = entry->d_inode; 656 struct inode *inode = d_inode(entry);
657 struct fuse_inode *fi = get_fuse_inode(inode); 657 struct fuse_inode *fi = get_fuse_inode(inode);
658 658
659 spin_lock(&fc->lock); 659 spin_lock(&fc->lock);
@@ -689,7 +689,7 @@ static int fuse_rmdir(struct inode *dir, struct dentry *entry)
689 args.in.args[0].value = entry->d_name.name; 689 args.in.args[0].value = entry->d_name.name;
690 err = fuse_simple_request(fc, &args); 690 err = fuse_simple_request(fc, &args);
691 if (!err) { 691 if (!err) {
692 clear_nlink(entry->d_inode); 692 clear_nlink(d_inode(entry));
693 fuse_invalidate_attr(dir); 693 fuse_invalidate_attr(dir);
694 fuse_invalidate_entry_cache(entry); 694 fuse_invalidate_entry_cache(entry);
695 } else if (err == -EINTR) 695 } else if (err == -EINTR)
@@ -721,12 +721,12 @@ static int fuse_rename_common(struct inode *olddir, struct dentry *oldent,
721 err = fuse_simple_request(fc, &args); 721 err = fuse_simple_request(fc, &args);
722 if (!err) { 722 if (!err) {
723 /* ctime changes */ 723 /* ctime changes */
724 fuse_invalidate_attr(oldent->d_inode); 724 fuse_invalidate_attr(d_inode(oldent));
725 fuse_update_ctime(oldent->d_inode); 725 fuse_update_ctime(d_inode(oldent));
726 726
727 if (flags & RENAME_EXCHANGE) { 727 if (flags & RENAME_EXCHANGE) {
728 fuse_invalidate_attr(newent->d_inode); 728 fuse_invalidate_attr(d_inode(newent));
729 fuse_update_ctime(newent->d_inode); 729 fuse_update_ctime(d_inode(newent));
730 } 730 }
731 731
732 fuse_invalidate_attr(olddir); 732 fuse_invalidate_attr(olddir);
@@ -734,10 +734,10 @@ static int fuse_rename_common(struct inode *olddir, struct dentry *oldent,
734 fuse_invalidate_attr(newdir); 734 fuse_invalidate_attr(newdir);
735 735
736 /* newent will end up negative */ 736 /* newent will end up negative */
737 if (!(flags & RENAME_EXCHANGE) && newent->d_inode) { 737 if (!(flags & RENAME_EXCHANGE) && d_really_is_positive(newent)) {
738 fuse_invalidate_attr(newent->d_inode); 738 fuse_invalidate_attr(d_inode(newent));
739 fuse_invalidate_entry_cache(newent); 739 fuse_invalidate_entry_cache(newent);
740 fuse_update_ctime(newent->d_inode); 740 fuse_update_ctime(d_inode(newent));
741 } 741 }
742 } else if (err == -EINTR) { 742 } else if (err == -EINTR) {
743 /* If request was interrupted, DEITY only knows if the 743 /* If request was interrupted, DEITY only knows if the
@@ -746,7 +746,7 @@ static int fuse_rename_common(struct inode *olddir, struct dentry *oldent,
746 directory), then there can be inconsistency between 746 directory), then there can be inconsistency between
747 the dcache and the real filesystem. Tough luck. */ 747 the dcache and the real filesystem. Tough luck. */
748 fuse_invalidate_entry(oldent); 748 fuse_invalidate_entry(oldent);
749 if (newent->d_inode) 749 if (d_really_is_positive(newent))
750 fuse_invalidate_entry(newent); 750 fuse_invalidate_entry(newent);
751 } 751 }
752 752
@@ -788,7 +788,7 @@ static int fuse_link(struct dentry *entry, struct inode *newdir,
788{ 788{
789 int err; 789 int err;
790 struct fuse_link_in inarg; 790 struct fuse_link_in inarg;
791 struct inode *inode = entry->d_inode; 791 struct inode *inode = d_inode(entry);
792 struct fuse_conn *fc = get_fuse_conn(inode); 792 struct fuse_conn *fc = get_fuse_conn(inode);
793 FUSE_ARGS(args); 793 FUSE_ARGS(args);
794 794
@@ -961,9 +961,9 @@ int fuse_reverse_inval_entry(struct super_block *sb, u64 parent_nodeid,
961 fuse_invalidate_attr(parent); 961 fuse_invalidate_attr(parent);
962 fuse_invalidate_entry(entry); 962 fuse_invalidate_entry(entry);
963 963
964 if (child_nodeid != 0 && entry->d_inode) { 964 if (child_nodeid != 0 && d_really_is_positive(entry)) {
965 mutex_lock(&entry->d_inode->i_mutex); 965 mutex_lock(&d_inode(entry)->i_mutex);
966 if (get_node_id(entry->d_inode) != child_nodeid) { 966 if (get_node_id(d_inode(entry)) != child_nodeid) {
967 err = -ENOENT; 967 err = -ENOENT;
968 goto badentry; 968 goto badentry;
969 } 969 }
@@ -977,13 +977,13 @@ int fuse_reverse_inval_entry(struct super_block *sb, u64 parent_nodeid,
977 err = -ENOTEMPTY; 977 err = -ENOTEMPTY;
978 goto badentry; 978 goto badentry;
979 } 979 }
980 entry->d_inode->i_flags |= S_DEAD; 980 d_inode(entry)->i_flags |= S_DEAD;
981 } 981 }
982 dont_mount(entry); 982 dont_mount(entry);
983 clear_nlink(entry->d_inode); 983 clear_nlink(d_inode(entry));
984 err = 0; 984 err = 0;
985 badentry: 985 badentry:
986 mutex_unlock(&entry->d_inode->i_mutex); 986 mutex_unlock(&d_inode(entry)->i_mutex);
987 if (!err) 987 if (!err)
988 d_delete(entry); 988 d_delete(entry);
989 } else { 989 } else {
@@ -1169,7 +1169,7 @@ static int fuse_direntplus_link(struct file *file,
1169 struct qstr name = QSTR_INIT(dirent->name, dirent->namelen); 1169 struct qstr name = QSTR_INIT(dirent->name, dirent->namelen);
1170 struct dentry *dentry; 1170 struct dentry *dentry;
1171 struct dentry *alias; 1171 struct dentry *alias;
1172 struct inode *dir = parent->d_inode; 1172 struct inode *dir = d_inode(parent);
1173 struct fuse_conn *fc; 1173 struct fuse_conn *fc;
1174 struct inode *inode; 1174 struct inode *inode;
1175 1175
@@ -1205,7 +1205,7 @@ static int fuse_direntplus_link(struct file *file,
1205 name.hash = full_name_hash(name.name, name.len); 1205 name.hash = full_name_hash(name.name, name.len);
1206 dentry = d_lookup(parent, &name); 1206 dentry = d_lookup(parent, &name);
1207 if (dentry) { 1207 if (dentry) {
1208 inode = dentry->d_inode; 1208 inode = d_inode(dentry);
1209 if (!inode) { 1209 if (!inode) {
1210 d_drop(dentry); 1210 d_drop(dentry);
1211 } else if (get_node_id(inode) != o->nodeid || 1211 } else if (get_node_id(inode) != o->nodeid ||
@@ -1367,7 +1367,7 @@ static int fuse_readdir(struct file *file, struct dir_context *ctx)
1367 1367
1368static char *read_link(struct dentry *dentry) 1368static char *read_link(struct dentry *dentry)
1369{ 1369{
1370 struct inode *inode = dentry->d_inode; 1370 struct inode *inode = d_inode(dentry);
1371 struct fuse_conn *fc = get_fuse_conn(inode); 1371 struct fuse_conn *fc = get_fuse_conn(inode);
1372 FUSE_ARGS(args); 1372 FUSE_ARGS(args);
1373 char *link; 1373 char *link;
@@ -1712,7 +1712,7 @@ error:
1712 1712
1713static int fuse_setattr(struct dentry *entry, struct iattr *attr) 1713static int fuse_setattr(struct dentry *entry, struct iattr *attr)
1714{ 1714{
1715 struct inode *inode = entry->d_inode; 1715 struct inode *inode = d_inode(entry);
1716 1716
1717 if (!fuse_allow_current_process(get_fuse_conn(inode))) 1717 if (!fuse_allow_current_process(get_fuse_conn(inode)))
1718 return -EACCES; 1718 return -EACCES;
@@ -1726,7 +1726,7 @@ static int fuse_setattr(struct dentry *entry, struct iattr *attr)
1726static int fuse_getattr(struct vfsmount *mnt, struct dentry *entry, 1726static int fuse_getattr(struct vfsmount *mnt, struct dentry *entry,
1727 struct kstat *stat) 1727 struct kstat *stat)
1728{ 1728{
1729 struct inode *inode = entry->d_inode; 1729 struct inode *inode = d_inode(entry);
1730 struct fuse_conn *fc = get_fuse_conn(inode); 1730 struct fuse_conn *fc = get_fuse_conn(inode);
1731 1731
1732 if (!fuse_allow_current_process(fc)) 1732 if (!fuse_allow_current_process(fc))
@@ -1738,7 +1738,7 @@ static int fuse_getattr(struct vfsmount *mnt, struct dentry *entry,
1738static int fuse_setxattr(struct dentry *entry, const char *name, 1738static int fuse_setxattr(struct dentry *entry, const char *name,
1739 const void *value, size_t size, int flags) 1739 const void *value, size_t size, int flags)
1740{ 1740{
1741 struct inode *inode = entry->d_inode; 1741 struct inode *inode = d_inode(entry);
1742 struct fuse_conn *fc = get_fuse_conn(inode); 1742 struct fuse_conn *fc = get_fuse_conn(inode);
1743 FUSE_ARGS(args); 1743 FUSE_ARGS(args);
1744 struct fuse_setxattr_in inarg; 1744 struct fuse_setxattr_in inarg;
@@ -1774,7 +1774,7 @@ static int fuse_setxattr(struct dentry *entry, const char *name,
1774static ssize_t fuse_getxattr(struct dentry *entry, const char *name, 1774static ssize_t fuse_getxattr(struct dentry *entry, const char *name,
1775 void *value, size_t size) 1775 void *value, size_t size)
1776{ 1776{
1777 struct inode *inode = entry->d_inode; 1777 struct inode *inode = d_inode(entry);
1778 struct fuse_conn *fc = get_fuse_conn(inode); 1778 struct fuse_conn *fc = get_fuse_conn(inode);
1779 FUSE_ARGS(args); 1779 FUSE_ARGS(args);
1780 struct fuse_getxattr_in inarg; 1780 struct fuse_getxattr_in inarg;
@@ -1815,7 +1815,7 @@ static ssize_t fuse_getxattr(struct dentry *entry, const char *name,
1815 1815
1816static ssize_t fuse_listxattr(struct dentry *entry, char *list, size_t size) 1816static ssize_t fuse_listxattr(struct dentry *entry, char *list, size_t size)
1817{ 1817{
1818 struct inode *inode = entry->d_inode; 1818 struct inode *inode = d_inode(entry);
1819 struct fuse_conn *fc = get_fuse_conn(inode); 1819 struct fuse_conn *fc = get_fuse_conn(inode);
1820 FUSE_ARGS(args); 1820 FUSE_ARGS(args);
1821 struct fuse_getxattr_in inarg; 1821 struct fuse_getxattr_in inarg;
@@ -1857,7 +1857,7 @@ static ssize_t fuse_listxattr(struct dentry *entry, char *list, size_t size)
1857 1857
1858static int fuse_removexattr(struct dentry *entry, const char *name) 1858static int fuse_removexattr(struct dentry *entry, const char *name)
1859{ 1859{
1860 struct inode *inode = entry->d_inode; 1860 struct inode *inode = d_inode(entry);
1861 struct fuse_conn *fc = get_fuse_conn(inode); 1861 struct fuse_conn *fc = get_fuse_conn(inode);
1862 FUSE_ARGS(args); 1862 FUSE_ARGS(args);
1863 int err; 1863 int err;
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index e8799c11424b..082ac1c97f39 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -421,7 +421,7 @@ static int fuse_statfs(struct dentry *dentry, struct kstatfs *buf)
421 memset(&outarg, 0, sizeof(outarg)); 421 memset(&outarg, 0, sizeof(outarg));
422 args.in.numargs = 0; 422 args.in.numargs = 0;
423 args.in.h.opcode = FUSE_STATFS; 423 args.in.h.opcode = FUSE_STATFS;
424 args.in.h.nodeid = get_node_id(dentry->d_inode); 424 args.in.h.nodeid = get_node_id(d_inode(dentry));
425 args.out.numargs = 1; 425 args.out.numargs = 1;
426 args.out.args[0].size = sizeof(outarg); 426 args.out.args[0].size = sizeof(outarg);
427 args.out.args[0].value = &outarg; 427 args.out.args[0].value = &outarg;
@@ -740,7 +740,7 @@ static struct dentry *fuse_fh_to_parent(struct super_block *sb,
740 740
741static struct dentry *fuse_get_parent(struct dentry *child) 741static struct dentry *fuse_get_parent(struct dentry *child)
742{ 742{
743 struct inode *child_inode = child->d_inode; 743 struct inode *child_inode = d_inode(child);
744 struct fuse_conn *fc = get_fuse_conn(child_inode); 744 struct fuse_conn *fc = get_fuse_conn(child_inode);
745 struct inode *inode; 745 struct inode *inode;
746 struct dentry *parent; 746 struct dentry *parent;
diff --git a/fs/gfs2/dentry.c b/fs/gfs2/dentry.c
index 589f4ea9381c..30822b148f3e 100644
--- a/fs/gfs2/dentry.c
+++ b/fs/gfs2/dentry.c
@@ -48,9 +48,9 @@ static int gfs2_drevalidate(struct dentry *dentry, unsigned int flags)
48 return -ECHILD; 48 return -ECHILD;
49 49
50 parent = dget_parent(dentry); 50 parent = dget_parent(dentry);
51 sdp = GFS2_SB(parent->d_inode); 51 sdp = GFS2_SB(d_inode(parent));
52 dip = GFS2_I(parent->d_inode); 52 dip = GFS2_I(d_inode(parent));
53 inode = dentry->d_inode; 53 inode = d_inode(dentry);
54 54
55 if (inode) { 55 if (inode) {
56 if (is_bad_inode(inode)) 56 if (is_bad_inode(inode))
@@ -68,7 +68,7 @@ static int gfs2_drevalidate(struct dentry *dentry, unsigned int flags)
68 goto fail; 68 goto fail;
69 } 69 }
70 70
71 error = gfs2_dir_check(parent->d_inode, &dentry->d_name, ip); 71 error = gfs2_dir_check(d_inode(parent), &dentry->d_name, ip);
72 switch (error) { 72 switch (error) {
73 case 0: 73 case 0:
74 if (!inode) 74 if (!inode)
@@ -113,10 +113,10 @@ static int gfs2_dentry_delete(const struct dentry *dentry)
113{ 113{
114 struct gfs2_inode *ginode; 114 struct gfs2_inode *ginode;
115 115
116 if (!dentry->d_inode) 116 if (d_really_is_negative(dentry))
117 return 0; 117 return 0;
118 118
119 ginode = GFS2_I(dentry->d_inode); 119 ginode = GFS2_I(d_inode(dentry));
120 if (!ginode->i_iopen_gh.gh_gl) 120 if (!ginode->i_iopen_gh.gh_gl)
121 return 0; 121 return 0;
122 122
diff --git a/fs/gfs2/export.c b/fs/gfs2/export.c
index c41d255b6a7b..5d15e9498b48 100644
--- a/fs/gfs2/export.c
+++ b/fs/gfs2/export.c
@@ -49,7 +49,7 @@ static int gfs2_encode_fh(struct inode *inode, __u32 *p, int *len,
49 fh[3] = cpu_to_be32(ip->i_no_addr & 0xFFFFFFFF); 49 fh[3] = cpu_to_be32(ip->i_no_addr & 0xFFFFFFFF);
50 *len = GFS2_SMALL_FH_SIZE; 50 *len = GFS2_SMALL_FH_SIZE;
51 51
52 if (!parent || inode == sb->s_root->d_inode) 52 if (!parent || inode == d_inode(sb->s_root))
53 return *len; 53 return *len;
54 54
55 ip = GFS2_I(parent); 55 ip = GFS2_I(parent);
@@ -88,8 +88,8 @@ static int get_name_filldir(struct dir_context *ctx, const char *name,
88static int gfs2_get_name(struct dentry *parent, char *name, 88static int gfs2_get_name(struct dentry *parent, char *name,
89 struct dentry *child) 89 struct dentry *child)
90{ 90{
91 struct inode *dir = parent->d_inode; 91 struct inode *dir = d_inode(parent);
92 struct inode *inode = child->d_inode; 92 struct inode *inode = d_inode(child);
93 struct gfs2_inode *dip, *ip; 93 struct gfs2_inode *dip, *ip;
94 struct get_name_filldir gnfd = { 94 struct get_name_filldir gnfd = {
95 .ctx.actor = get_name_filldir, 95 .ctx.actor = get_name_filldir,
@@ -128,7 +128,7 @@ static int gfs2_get_name(struct dentry *parent, char *name,
128 128
129static struct dentry *gfs2_get_parent(struct dentry *child) 129static struct dentry *gfs2_get_parent(struct dentry *child)
130{ 130{
131 return d_obtain_alias(gfs2_lookupi(child->d_inode, &gfs2_qdotdot, 1)); 131 return d_obtain_alias(gfs2_lookupi(d_inode(child), &gfs2_qdotdot, 1));
132} 132}
133 133
134static struct dentry *gfs2_get_dentry(struct super_block *sb, 134static struct dentry *gfs2_get_dentry(struct super_block *sb,
diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
index 08bc84d7e768..1b3ca7a2e3fc 100644
--- a/fs/gfs2/inode.c
+++ b/fs/gfs2/inode.c
@@ -295,7 +295,7 @@ struct inode *gfs2_lookupi(struct inode *dir, const struct qstr *name,
295 295
296 if ((name->len == 1 && memcmp(name->name, ".", 1) == 0) || 296 if ((name->len == 1 && memcmp(name->name, ".", 1) == 0) ||
297 (name->len == 2 && memcmp(name->name, "..", 2) == 0 && 297 (name->len == 2 && memcmp(name->name, "..", 2) == 0 &&
298 dir == sb->s_root->d_inode)) { 298 dir == d_inode(sb->s_root))) {
299 igrab(dir); 299 igrab(dir);
300 return dir; 300 return dir;
301 } 301 }
@@ -687,7 +687,7 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
687 } 687 }
688 gfs2_set_inode_flags(inode); 688 gfs2_set_inode_flags(inode);
689 689
690 if ((GFS2_I(sdp->sd_root_dir->d_inode) == dip) || 690 if ((GFS2_I(d_inode(sdp->sd_root_dir)) == dip) ||
691 (dip->i_diskflags & GFS2_DIF_TOPDIR)) 691 (dip->i_diskflags & GFS2_DIF_TOPDIR))
692 aflags |= GFS2_AF_ORLOV; 692 aflags |= GFS2_AF_ORLOV;
693 693
@@ -888,7 +888,7 @@ static int gfs2_link(struct dentry *old_dentry, struct inode *dir,
888{ 888{
889 struct gfs2_inode *dip = GFS2_I(dir); 889 struct gfs2_inode *dip = GFS2_I(dir);
890 struct gfs2_sbd *sdp = GFS2_SB(dir); 890 struct gfs2_sbd *sdp = GFS2_SB(dir);
891 struct inode *inode = old_dentry->d_inode; 891 struct inode *inode = d_inode(old_dentry);
892 struct gfs2_inode *ip = GFS2_I(inode); 892 struct gfs2_inode *ip = GFS2_I(inode);
893 struct gfs2_holder ghs[2]; 893 struct gfs2_holder ghs[2];
894 struct buffer_head *dibh; 894 struct buffer_head *dibh;
@@ -1055,7 +1055,7 @@ static int gfs2_unlink_ok(struct gfs2_inode *dip, const struct qstr *name,
1055static int gfs2_unlink_inode(struct gfs2_inode *dip, 1055static int gfs2_unlink_inode(struct gfs2_inode *dip,
1056 const struct dentry *dentry) 1056 const struct dentry *dentry)
1057{ 1057{
1058 struct inode *inode = dentry->d_inode; 1058 struct inode *inode = d_inode(dentry);
1059 struct gfs2_inode *ip = GFS2_I(inode); 1059 struct gfs2_inode *ip = GFS2_I(inode);
1060 int error; 1060 int error;
1061 1061
@@ -1091,7 +1091,7 @@ static int gfs2_unlink(struct inode *dir, struct dentry *dentry)
1091{ 1091{
1092 struct gfs2_inode *dip = GFS2_I(dir); 1092 struct gfs2_inode *dip = GFS2_I(dir);
1093 struct gfs2_sbd *sdp = GFS2_SB(dir); 1093 struct gfs2_sbd *sdp = GFS2_SB(dir);
1094 struct inode *inode = dentry->d_inode; 1094 struct inode *inode = d_inode(dentry);
1095 struct gfs2_inode *ip = GFS2_I(inode); 1095 struct gfs2_inode *ip = GFS2_I(inode);
1096 struct gfs2_holder ghs[3]; 1096 struct gfs2_holder ghs[3];
1097 struct gfs2_rgrpd *rgd; 1097 struct gfs2_rgrpd *rgd;
@@ -1241,7 +1241,7 @@ static int gfs2_atomic_open(struct inode *dir, struct dentry *dentry,
1241 return PTR_ERR(d); 1241 return PTR_ERR(d);
1242 if (d != NULL) 1242 if (d != NULL)
1243 dentry = d; 1243 dentry = d;
1244 if (dentry->d_inode) { 1244 if (d_really_is_positive(dentry)) {
1245 if (!(*opened & FILE_OPENED)) 1245 if (!(*opened & FILE_OPENED))
1246 return finish_no_open(file, d); 1246 return finish_no_open(file, d);
1247 dput(d); 1247 dput(d);
@@ -1282,7 +1282,7 @@ static int gfs2_ok_to_move(struct gfs2_inode *this, struct gfs2_inode *to)
1282 error = -EINVAL; 1282 error = -EINVAL;
1283 break; 1283 break;
1284 } 1284 }
1285 if (dir == sb->s_root->d_inode) { 1285 if (dir == d_inode(sb->s_root)) {
1286 error = 0; 1286 error = 0;
1287 break; 1287 break;
1288 } 1288 }
@@ -1321,7 +1321,7 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry,
1321{ 1321{
1322 struct gfs2_inode *odip = GFS2_I(odir); 1322 struct gfs2_inode *odip = GFS2_I(odir);
1323 struct gfs2_inode *ndip = GFS2_I(ndir); 1323 struct gfs2_inode *ndip = GFS2_I(ndir);
1324 struct gfs2_inode *ip = GFS2_I(odentry->d_inode); 1324 struct gfs2_inode *ip = GFS2_I(d_inode(odentry));
1325 struct gfs2_inode *nip = NULL; 1325 struct gfs2_inode *nip = NULL;
1326 struct gfs2_sbd *sdp = GFS2_SB(odir); 1326 struct gfs2_sbd *sdp = GFS2_SB(odir);
1327 struct gfs2_holder ghs[5], r_gh = { .gh_gl = NULL, }; 1327 struct gfs2_holder ghs[5], r_gh = { .gh_gl = NULL, };
@@ -1332,8 +1332,8 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry,
1332 unsigned int x; 1332 unsigned int x;
1333 int error; 1333 int error;
1334 1334
1335 if (ndentry->d_inode) { 1335 if (d_really_is_positive(ndentry)) {
1336 nip = GFS2_I(ndentry->d_inode); 1336 nip = GFS2_I(d_inode(ndentry));
1337 if (ip == nip) 1337 if (ip == nip)
1338 return 0; 1338 return 0;
1339 } 1339 }
@@ -1457,7 +1457,7 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry,
1457 /* Check out the dir to be renamed */ 1457 /* Check out the dir to be renamed */
1458 1458
1459 if (dir_rename) { 1459 if (dir_rename) {
1460 error = gfs2_permission(odentry->d_inode, MAY_WRITE); 1460 error = gfs2_permission(d_inode(odentry), MAY_WRITE);
1461 if (error) 1461 if (error)
1462 goto out_gunlock; 1462 goto out_gunlock;
1463 } 1463 }
@@ -1550,7 +1550,7 @@ out:
1550 1550
1551static void *gfs2_follow_link(struct dentry *dentry, struct nameidata *nd) 1551static void *gfs2_follow_link(struct dentry *dentry, struct nameidata *nd)
1552{ 1552{
1553 struct gfs2_inode *ip = GFS2_I(dentry->d_inode); 1553 struct gfs2_inode *ip = GFS2_I(d_inode(dentry));
1554 struct gfs2_holder i_gh; 1554 struct gfs2_holder i_gh;
1555 struct buffer_head *dibh; 1555 struct buffer_head *dibh;
1556 unsigned int size; 1556 unsigned int size;
@@ -1742,7 +1742,7 @@ out:
1742 1742
1743static int gfs2_setattr(struct dentry *dentry, struct iattr *attr) 1743static int gfs2_setattr(struct dentry *dentry, struct iattr *attr)
1744{ 1744{
1745 struct inode *inode = dentry->d_inode; 1745 struct inode *inode = d_inode(dentry);
1746 struct gfs2_inode *ip = GFS2_I(inode); 1746 struct gfs2_inode *ip = GFS2_I(inode);
1747 struct gfs2_holder i_gh; 1747 struct gfs2_holder i_gh;
1748 int error; 1748 int error;
@@ -1798,7 +1798,7 @@ out:
1798static int gfs2_getattr(struct vfsmount *mnt, struct dentry *dentry, 1798static int gfs2_getattr(struct vfsmount *mnt, struct dentry *dentry,
1799 struct kstat *stat) 1799 struct kstat *stat)
1800{ 1800{
1801 struct inode *inode = dentry->d_inode; 1801 struct inode *inode = d_inode(dentry);
1802 struct gfs2_inode *ip = GFS2_I(inode); 1802 struct gfs2_inode *ip = GFS2_I(inode);
1803 struct gfs2_holder gh; 1803 struct gfs2_holder gh;
1804 int error; 1804 int error;
@@ -1821,7 +1821,7 @@ static int gfs2_getattr(struct vfsmount *mnt, struct dentry *dentry,
1821static int gfs2_setxattr(struct dentry *dentry, const char *name, 1821static int gfs2_setxattr(struct dentry *dentry, const char *name,
1822 const void *data, size_t size, int flags) 1822 const void *data, size_t size, int flags)
1823{ 1823{
1824 struct inode *inode = dentry->d_inode; 1824 struct inode *inode = d_inode(dentry);
1825 struct gfs2_inode *ip = GFS2_I(inode); 1825 struct gfs2_inode *ip = GFS2_I(inode);
1826 struct gfs2_holder gh; 1826 struct gfs2_holder gh;
1827 int ret; 1827 int ret;
@@ -1841,7 +1841,7 @@ static int gfs2_setxattr(struct dentry *dentry, const char *name,
1841static ssize_t gfs2_getxattr(struct dentry *dentry, const char *name, 1841static ssize_t gfs2_getxattr(struct dentry *dentry, const char *name,
1842 void *data, size_t size) 1842 void *data, size_t size)
1843{ 1843{
1844 struct inode *inode = dentry->d_inode; 1844 struct inode *inode = d_inode(dentry);
1845 struct gfs2_inode *ip = GFS2_I(inode); 1845 struct gfs2_inode *ip = GFS2_I(inode);
1846 struct gfs2_holder gh; 1846 struct gfs2_holder gh;
1847 int ret; 1847 int ret;
@@ -1862,7 +1862,7 @@ static ssize_t gfs2_getxattr(struct dentry *dentry, const char *name,
1862 1862
1863static int gfs2_removexattr(struct dentry *dentry, const char *name) 1863static int gfs2_removexattr(struct dentry *dentry, const char *name)
1864{ 1864{
1865 struct inode *inode = dentry->d_inode; 1865 struct inode *inode = d_inode(dentry);
1866 struct gfs2_inode *ip = GFS2_I(inode); 1866 struct gfs2_inode *ip = GFS2_I(inode);
1867 struct gfs2_holder gh; 1867 struct gfs2_holder gh;
1868 int ret; 1868 int ret;
diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c
index efc8e254787c..35b49f44c72f 100644
--- a/fs/gfs2/ops_fstype.c
+++ b/fs/gfs2/ops_fstype.c
@@ -647,7 +647,7 @@ out_unlock:
647 647
648static int init_journal(struct gfs2_sbd *sdp, int undo) 648static int init_journal(struct gfs2_sbd *sdp, int undo)
649{ 649{
650 struct inode *master = sdp->sd_master_dir->d_inode; 650 struct inode *master = d_inode(sdp->sd_master_dir);
651 struct gfs2_holder ji_gh; 651 struct gfs2_holder ji_gh;
652 struct gfs2_inode *ip; 652 struct gfs2_inode *ip;
653 int jindex = 1; 653 int jindex = 1;
@@ -782,7 +782,7 @@ static struct lock_class_key gfs2_quota_imutex_key;
782static int init_inodes(struct gfs2_sbd *sdp, int undo) 782static int init_inodes(struct gfs2_sbd *sdp, int undo)
783{ 783{
784 int error = 0; 784 int error = 0;
785 struct inode *master = sdp->sd_master_dir->d_inode; 785 struct inode *master = d_inode(sdp->sd_master_dir);
786 786
787 if (undo) 787 if (undo)
788 goto fail_qinode; 788 goto fail_qinode;
@@ -848,7 +848,7 @@ static int init_per_node(struct gfs2_sbd *sdp, int undo)
848 char buf[30]; 848 char buf[30];
849 int error = 0; 849 int error = 0;
850 struct gfs2_inode *ip; 850 struct gfs2_inode *ip;
851 struct inode *master = sdp->sd_master_dir->d_inode; 851 struct inode *master = d_inode(sdp->sd_master_dir);
852 852
853 if (sdp->sd_args.ar_spectator) 853 if (sdp->sd_args.ar_spectator)
854 return 0; 854 return 0;
@@ -1357,7 +1357,7 @@ static struct dentry *gfs2_mount_meta(struct file_system_type *fs_type,
1357 return ERR_PTR(error); 1357 return ERR_PTR(error);
1358 } 1358 }
1359 s = sget(&gfs2_fs_type, test_gfs2_super, set_meta_super, flags, 1359 s = sget(&gfs2_fs_type, test_gfs2_super, set_meta_super, flags,
1360 path.dentry->d_inode->i_sb->s_bdev); 1360 d_inode(path.dentry)->i_sb->s_bdev);
1361 path_put(&path); 1361 path_put(&path);
1362 if (IS_ERR(s)) { 1362 if (IS_ERR(s)) {
1363 pr_warn("gfs2 mount does not exist\n"); 1363 pr_warn("gfs2 mount does not exist\n");
diff --git a/fs/gfs2/super.c b/fs/gfs2/super.c
index 1666382b198d..859c6edbf81a 100644
--- a/fs/gfs2/super.c
+++ b/fs/gfs2/super.c
@@ -1171,7 +1171,7 @@ static int gfs2_statfs_i(struct gfs2_sbd *sdp, struct gfs2_statfs_change_host *s
1171 1171
1172static int gfs2_statfs(struct dentry *dentry, struct kstatfs *buf) 1172static int gfs2_statfs(struct dentry *dentry, struct kstatfs *buf)
1173{ 1173{
1174 struct super_block *sb = dentry->d_inode->i_sb; 1174 struct super_block *sb = d_inode(dentry)->i_sb;
1175 struct gfs2_sbd *sdp = sb->s_fs_info; 1175 struct gfs2_sbd *sdp = sb->s_fs_info;
1176 struct gfs2_statfs_change_host sc; 1176 struct gfs2_statfs_change_host sc;
1177 int error; 1177 int error;
diff --git a/fs/gfs2/xattr.c b/fs/gfs2/xattr.c
index fd260ce8869a..4c096fa9e2a1 100644
--- a/fs/gfs2/xattr.c
+++ b/fs/gfs2/xattr.c
@@ -420,7 +420,7 @@ static int ea_list_i(struct gfs2_inode *ip, struct buffer_head *bh,
420 420
421ssize_t gfs2_listxattr(struct dentry *dentry, char *buffer, size_t size) 421ssize_t gfs2_listxattr(struct dentry *dentry, char *buffer, size_t size)
422{ 422{
423 struct gfs2_inode *ip = GFS2_I(dentry->d_inode); 423 struct gfs2_inode *ip = GFS2_I(d_inode(dentry));
424 struct gfs2_ea_request er; 424 struct gfs2_ea_request er;
425 struct gfs2_holder i_gh; 425 struct gfs2_holder i_gh;
426 int error; 426 int error;
@@ -586,7 +586,7 @@ out:
586static int gfs2_xattr_get(struct dentry *dentry, const char *name, 586static int gfs2_xattr_get(struct dentry *dentry, const char *name,
587 void *buffer, size_t size, int type) 587 void *buffer, size_t size, int type)
588{ 588{
589 struct gfs2_inode *ip = GFS2_I(dentry->d_inode); 589 struct gfs2_inode *ip = GFS2_I(d_inode(dentry));
590 struct gfs2_ea_location el; 590 struct gfs2_ea_location el;
591 int error; 591 int error;
592 592
@@ -1230,7 +1230,7 @@ int __gfs2_xattr_set(struct inode *inode, const char *name,
1230static int gfs2_xattr_set(struct dentry *dentry, const char *name, 1230static int gfs2_xattr_set(struct dentry *dentry, const char *name,
1231 const void *value, size_t size, int flags, int type) 1231 const void *value, size_t size, int flags, int type)
1232{ 1232{
1233 return __gfs2_xattr_set(dentry->d_inode, name, value, 1233 return __gfs2_xattr_set(d_inode(dentry), name, value,
1234 size, flags, type); 1234 size, flags, type);
1235} 1235}
1236 1236
diff --git a/fs/hfs/attr.c b/fs/hfs/attr.c
index e057ec542a6a..8d931b157bbe 100644
--- a/fs/hfs/attr.c
+++ b/fs/hfs/attr.c
@@ -16,7 +16,7 @@
16int hfs_setxattr(struct dentry *dentry, const char *name, 16int hfs_setxattr(struct dentry *dentry, const char *name,
17 const void *value, size_t size, int flags) 17 const void *value, size_t size, int flags)
18{ 18{
19 struct inode *inode = dentry->d_inode; 19 struct inode *inode = d_inode(dentry);
20 struct hfs_find_data fd; 20 struct hfs_find_data fd;
21 hfs_cat_rec rec; 21 hfs_cat_rec rec;
22 struct hfs_cat_file *file; 22 struct hfs_cat_file *file;
@@ -59,7 +59,7 @@ out:
59ssize_t hfs_getxattr(struct dentry *dentry, const char *name, 59ssize_t hfs_getxattr(struct dentry *dentry, const char *name,
60 void *value, size_t size) 60 void *value, size_t size)
61{ 61{
62 struct inode *inode = dentry->d_inode; 62 struct inode *inode = d_inode(dentry);
63 struct hfs_find_data fd; 63 struct hfs_find_data fd;
64 hfs_cat_rec rec; 64 hfs_cat_rec rec;
65 struct hfs_cat_file *file; 65 struct hfs_cat_file *file;
@@ -105,7 +105,7 @@ out:
105 105
106ssize_t hfs_listxattr(struct dentry *dentry, char *buffer, size_t size) 106ssize_t hfs_listxattr(struct dentry *dentry, char *buffer, size_t size)
107{ 107{
108 struct inode *inode = dentry->d_inode; 108 struct inode *inode = d_inode(dentry);
109 109
110 if (!S_ISREG(inode->i_mode) || HFS_IS_RSRC(inode)) 110 if (!S_ISREG(inode->i_mode) || HFS_IS_RSRC(inode))
111 return -EOPNOTSUPP; 111 return -EOPNOTSUPP;
diff --git a/fs/hfs/dir.c b/fs/hfs/dir.c
index 36d1a6ae7655..70788e03820a 100644
--- a/fs/hfs/dir.c
+++ b/fs/hfs/dir.c
@@ -253,7 +253,7 @@ static int hfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
253 */ 253 */
254static int hfs_remove(struct inode *dir, struct dentry *dentry) 254static int hfs_remove(struct inode *dir, struct dentry *dentry)
255{ 255{
256 struct inode *inode = dentry->d_inode; 256 struct inode *inode = d_inode(dentry);
257 int res; 257 int res;
258 258
259 if (S_ISDIR(inode->i_mode) && inode->i_size != 2) 259 if (S_ISDIR(inode->i_mode) && inode->i_size != 2)
@@ -285,18 +285,18 @@ static int hfs_rename(struct inode *old_dir, struct dentry *old_dentry,
285 int res; 285 int res;
286 286
287 /* Unlink destination if it already exists */ 287 /* Unlink destination if it already exists */
288 if (new_dentry->d_inode) { 288 if (d_really_is_positive(new_dentry)) {
289 res = hfs_remove(new_dir, new_dentry); 289 res = hfs_remove(new_dir, new_dentry);
290 if (res) 290 if (res)
291 return res; 291 return res;
292 } 292 }
293 293
294 res = hfs_cat_move(old_dentry->d_inode->i_ino, 294 res = hfs_cat_move(d_inode(old_dentry)->i_ino,
295 old_dir, &old_dentry->d_name, 295 old_dir, &old_dentry->d_name,
296 new_dir, &new_dentry->d_name); 296 new_dir, &new_dentry->d_name);
297 if (!res) 297 if (!res)
298 hfs_cat_build_key(old_dir->i_sb, 298 hfs_cat_build_key(old_dir->i_sb,
299 (btree_key *)&HFS_I(old_dentry->d_inode)->cat_key, 299 (btree_key *)&HFS_I(d_inode(old_dentry))->cat_key,
300 new_dir->i_ino, &new_dentry->d_name); 300 new_dir->i_ino, &new_dentry->d_name);
301 return res; 301 return res;
302} 302}
diff --git a/fs/hfs/inode.c b/fs/hfs/inode.c
index 75fd5d873c19..b99ebddb10cb 100644
--- a/fs/hfs/inode.c
+++ b/fs/hfs/inode.c
@@ -600,7 +600,7 @@ static int hfs_file_release(struct inode *inode, struct file *file)
600 600
601int hfs_inode_setattr(struct dentry *dentry, struct iattr * attr) 601int hfs_inode_setattr(struct dentry *dentry, struct iattr * attr)
602{ 602{
603 struct inode *inode = dentry->d_inode; 603 struct inode *inode = d_inode(dentry);
604 struct hfs_sb_info *hsb = HFS_SB(inode->i_sb); 604 struct hfs_sb_info *hsb = HFS_SB(inode->i_sb);
605 int error; 605 int error;
606 606
diff --git a/fs/hfs/sysdep.c b/fs/hfs/sysdep.c
index 91b91fd3a901..2875961fdc10 100644
--- a/fs/hfs/sysdep.c
+++ b/fs/hfs/sysdep.c
@@ -21,7 +21,7 @@ static int hfs_revalidate_dentry(struct dentry *dentry, unsigned int flags)
21 if (flags & LOOKUP_RCU) 21 if (flags & LOOKUP_RCU)
22 return -ECHILD; 22 return -ECHILD;
23 23
24 inode = dentry->d_inode; 24 inode = d_inode(dentry);
25 if(!inode) 25 if(!inode)
26 return 1; 26 return 1;
27 27
diff --git a/fs/hfsplus/dir.c b/fs/hfsplus/dir.c
index 3074609befc3..d0f39dcbb58e 100644
--- a/fs/hfsplus/dir.c
+++ b/fs/hfsplus/dir.c
@@ -81,7 +81,7 @@ again:
81 HFSPLUS_I(HFSPLUS_SB(sb)->hidden_dir)-> 81 HFSPLUS_I(HFSPLUS_SB(sb)->hidden_dir)->
82 create_date || 82 create_date ||
83 entry.file.create_date == 83 entry.file.create_date ==
84 HFSPLUS_I(sb->s_root->d_inode)-> 84 HFSPLUS_I(d_inode(sb->s_root))->
85 create_date) && 85 create_date) &&
86 HFSPLUS_SB(sb)->hidden_dir) { 86 HFSPLUS_SB(sb)->hidden_dir) {
87 struct qstr str; 87 struct qstr str;
@@ -296,8 +296,8 @@ static int hfsplus_link(struct dentry *src_dentry, struct inode *dst_dir,
296 struct dentry *dst_dentry) 296 struct dentry *dst_dentry)
297{ 297{
298 struct hfsplus_sb_info *sbi = HFSPLUS_SB(dst_dir->i_sb); 298 struct hfsplus_sb_info *sbi = HFSPLUS_SB(dst_dir->i_sb);
299 struct inode *inode = src_dentry->d_inode; 299 struct inode *inode = d_inode(src_dentry);
300 struct inode *src_dir = src_dentry->d_parent->d_inode; 300 struct inode *src_dir = d_inode(src_dentry->d_parent);
301 struct qstr str; 301 struct qstr str;
302 char name[32]; 302 char name[32];
303 u32 cnid, id; 303 u32 cnid, id;
@@ -353,7 +353,7 @@ out:
353static int hfsplus_unlink(struct inode *dir, struct dentry *dentry) 353static int hfsplus_unlink(struct inode *dir, struct dentry *dentry)
354{ 354{
355 struct hfsplus_sb_info *sbi = HFSPLUS_SB(dir->i_sb); 355 struct hfsplus_sb_info *sbi = HFSPLUS_SB(dir->i_sb);
356 struct inode *inode = dentry->d_inode; 356 struct inode *inode = d_inode(dentry);
357 struct qstr str; 357 struct qstr str;
358 char name[32]; 358 char name[32];
359 u32 cnid; 359 u32 cnid;
@@ -410,7 +410,7 @@ out:
410static int hfsplus_rmdir(struct inode *dir, struct dentry *dentry) 410static int hfsplus_rmdir(struct inode *dir, struct dentry *dentry)
411{ 411{
412 struct hfsplus_sb_info *sbi = HFSPLUS_SB(dir->i_sb); 412 struct hfsplus_sb_info *sbi = HFSPLUS_SB(dir->i_sb);
413 struct inode *inode = dentry->d_inode; 413 struct inode *inode = d_inode(dentry);
414 int res; 414 int res;
415 415
416 if (inode->i_size != 2) 416 if (inode->i_size != 2)
@@ -529,7 +529,7 @@ static int hfsplus_rename(struct inode *old_dir, struct dentry *old_dentry,
529 int res; 529 int res;
530 530
531 /* Unlink destination if it already exists */ 531 /* Unlink destination if it already exists */
532 if (new_dentry->d_inode) { 532 if (d_really_is_positive(new_dentry)) {
533 if (d_is_dir(new_dentry)) 533 if (d_is_dir(new_dentry))
534 res = hfsplus_rmdir(new_dir, new_dentry); 534 res = hfsplus_rmdir(new_dir, new_dentry);
535 else 535 else
diff --git a/fs/hfsplus/inode.c b/fs/hfsplus/inode.c
index b0afedbef12b..6dd107d7421e 100644
--- a/fs/hfsplus/inode.c
+++ b/fs/hfsplus/inode.c
@@ -243,7 +243,7 @@ static int hfsplus_file_release(struct inode *inode, struct file *file)
243 243
244static int hfsplus_setattr(struct dentry *dentry, struct iattr *attr) 244static int hfsplus_setattr(struct dentry *dentry, struct iattr *attr)
245{ 245{
246 struct inode *inode = dentry->d_inode; 246 struct inode *inode = d_inode(dentry);
247 int error; 247 int error;
248 248
249 error = inode_change_ok(inode, attr); 249 error = inode_change_ok(inode, attr);
diff --git a/fs/hfsplus/ioctl.c b/fs/hfsplus/ioctl.c
index 8e98f5db6ad6..0624ce4e0702 100644
--- a/fs/hfsplus/ioctl.c
+++ b/fs/hfsplus/ioctl.c
@@ -26,7 +26,7 @@
26static int hfsplus_ioctl_bless(struct file *file, int __user *user_flags) 26static int hfsplus_ioctl_bless(struct file *file, int __user *user_flags)
27{ 27{
28 struct dentry *dentry = file->f_path.dentry; 28 struct dentry *dentry = file->f_path.dentry;
29 struct inode *inode = dentry->d_inode; 29 struct inode *inode = d_inode(dentry);
30 struct hfsplus_sb_info *sbi = HFSPLUS_SB(inode->i_sb); 30 struct hfsplus_sb_info *sbi = HFSPLUS_SB(inode->i_sb);
31 struct hfsplus_vh *vh = sbi->s_vhdr; 31 struct hfsplus_vh *vh = sbi->s_vhdr;
32 struct hfsplus_vh *bvh = sbi->s_backup_vhdr; 32 struct hfsplus_vh *bvh = sbi->s_backup_vhdr;
diff --git a/fs/hfsplus/xattr.c b/fs/hfsplus/xattr.c
index 89f262d8fcd8..416b1dbafe51 100644
--- a/fs/hfsplus/xattr.c
+++ b/fs/hfsplus/xattr.c
@@ -440,7 +440,7 @@ int hfsplus_setxattr(struct dentry *dentry, const char *name,
440 return -ENOMEM; 440 return -ENOMEM;
441 strcpy(xattr_name, prefix); 441 strcpy(xattr_name, prefix);
442 strcpy(xattr_name + prefixlen, name); 442 strcpy(xattr_name + prefixlen, name);
443 res = __hfsplus_setxattr(dentry->d_inode, xattr_name, value, size, 443 res = __hfsplus_setxattr(d_inode(dentry), xattr_name, value, size,
444 flags); 444 flags);
445 kfree(xattr_name); 445 kfree(xattr_name);
446 return res; 446 return res;
@@ -600,7 +600,7 @@ ssize_t hfsplus_getxattr(struct dentry *dentry, const char *name,
600 strcpy(xattr_name, prefix); 600 strcpy(xattr_name, prefix);
601 strcpy(xattr_name + prefixlen, name); 601 strcpy(xattr_name + prefixlen, name);
602 602
603 res = __hfsplus_getxattr(dentry->d_inode, xattr_name, value, size); 603 res = __hfsplus_getxattr(d_inode(dentry), xattr_name, value, size);
604 kfree(xattr_name); 604 kfree(xattr_name);
605 return res; 605 return res;
606 606
@@ -620,7 +620,7 @@ static ssize_t hfsplus_listxattr_finder_info(struct dentry *dentry,
620 char *buffer, size_t size) 620 char *buffer, size_t size)
621{ 621{
622 ssize_t res = 0; 622 ssize_t res = 0;
623 struct inode *inode = dentry->d_inode; 623 struct inode *inode = d_inode(dentry);
624 struct hfs_find_data fd; 624 struct hfs_find_data fd;
625 u16 entry_type; 625 u16 entry_type;
626 u8 folder_finder_info[sizeof(struct DInfo) + sizeof(struct DXInfo)]; 626 u8 folder_finder_info[sizeof(struct DInfo) + sizeof(struct DXInfo)];
@@ -688,7 +688,7 @@ ssize_t hfsplus_listxattr(struct dentry *dentry, char *buffer, size_t size)
688{ 688{
689 ssize_t err; 689 ssize_t err;
690 ssize_t res = 0; 690 ssize_t res = 0;
691 struct inode *inode = dentry->d_inode; 691 struct inode *inode = d_inode(dentry);
692 struct hfs_find_data fd; 692 struct hfs_find_data fd;
693 u16 key_len = 0; 693 u16 key_len = 0;
694 struct hfsplus_attr_key attr_key; 694 struct hfsplus_attr_key attr_key;
@@ -868,7 +868,7 @@ static int hfsplus_osx_getxattr(struct dentry *dentry, const char *name,
868 * creates), so we pass the name through unmodified (after 868 * creates), so we pass the name through unmodified (after
869 * ensuring it doesn't conflict with another namespace). 869 * ensuring it doesn't conflict with another namespace).
870 */ 870 */
871 return __hfsplus_getxattr(dentry->d_inode, name, buffer, size); 871 return __hfsplus_getxattr(d_inode(dentry), name, buffer, size);
872} 872}
873 873
874static int hfsplus_osx_setxattr(struct dentry *dentry, const char *name, 874static int hfsplus_osx_setxattr(struct dentry *dentry, const char *name,
@@ -890,7 +890,7 @@ static int hfsplus_osx_setxattr(struct dentry *dentry, const char *name,
890 * creates), so we pass the name through unmodified (after 890 * creates), so we pass the name through unmodified (after
891 * ensuring it doesn't conflict with another namespace). 891 * ensuring it doesn't conflict with another namespace).
892 */ 892 */
893 return __hfsplus_setxattr(dentry->d_inode, name, buffer, size, flags); 893 return __hfsplus_setxattr(d_inode(dentry), name, buffer, size, flags);
894} 894}
895 895
896static size_t hfsplus_osx_listxattr(struct dentry *dentry, char *list, 896static size_t hfsplus_osx_listxattr(struct dentry *dentry, char *list,
diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
index b83a0343378b..ef263174acd2 100644
--- a/fs/hostfs/hostfs_kern.c
+++ b/fs/hostfs/hostfs_kern.c
@@ -807,7 +807,7 @@ static int hostfs_permission(struct inode *ino, int desired)
807 807
808static int hostfs_setattr(struct dentry *dentry, struct iattr *attr) 808static int hostfs_setattr(struct dentry *dentry, struct iattr *attr)
809{ 809{
810 struct inode *inode = dentry->d_inode; 810 struct inode *inode = d_inode(dentry);
811 struct hostfs_iattr attrs; 811 struct hostfs_iattr attrs;
812 char *name; 812 char *name;
813 int err; 813 int err;
diff --git a/fs/hpfs/inode.c b/fs/hpfs/inode.c
index 7ce4b74234a1..933c73780813 100644
--- a/fs/hpfs/inode.c
+++ b/fs/hpfs/inode.c
@@ -257,7 +257,7 @@ void hpfs_write_inode_nolock(struct inode *i)
257 257
258int hpfs_setattr(struct dentry *dentry, struct iattr *attr) 258int hpfs_setattr(struct dentry *dentry, struct iattr *attr)
259{ 259{
260 struct inode *inode = dentry->d_inode; 260 struct inode *inode = d_inode(dentry);
261 int error = -EINVAL; 261 int error = -EINVAL;
262 262
263 hpfs_lock(inode->i_sb); 263 hpfs_lock(inode->i_sb);
diff --git a/fs/hpfs/namei.c b/fs/hpfs/namei.c
index bdbc2c3080a4..a0872f239f04 100644
--- a/fs/hpfs/namei.c
+++ b/fs/hpfs/namei.c
@@ -359,7 +359,7 @@ static int hpfs_unlink(struct inode *dir, struct dentry *dentry)
359 unsigned len = dentry->d_name.len; 359 unsigned len = dentry->d_name.len;
360 struct quad_buffer_head qbh; 360 struct quad_buffer_head qbh;
361 struct hpfs_dirent *de; 361 struct hpfs_dirent *de;
362 struct inode *inode = dentry->d_inode; 362 struct inode *inode = d_inode(dentry);
363 dnode_secno dno; 363 dnode_secno dno;
364 int r; 364 int r;
365 int rep = 0; 365 int rep = 0;
@@ -433,7 +433,7 @@ static int hpfs_rmdir(struct inode *dir, struct dentry *dentry)
433 unsigned len = dentry->d_name.len; 433 unsigned len = dentry->d_name.len;
434 struct quad_buffer_head qbh; 434 struct quad_buffer_head qbh;
435 struct hpfs_dirent *de; 435 struct hpfs_dirent *de;
436 struct inode *inode = dentry->d_inode; 436 struct inode *inode = d_inode(dentry);
437 dnode_secno dno; 437 dnode_secno dno;
438 int n_items = 0; 438 int n_items = 0;
439 int err; 439 int err;
@@ -522,8 +522,8 @@ static int hpfs_rename(struct inode *old_dir, struct dentry *old_dentry,
522 unsigned old_len = old_dentry->d_name.len; 522 unsigned old_len = old_dentry->d_name.len;
523 const unsigned char *new_name = new_dentry->d_name.name; 523 const unsigned char *new_name = new_dentry->d_name.name;
524 unsigned new_len = new_dentry->d_name.len; 524 unsigned new_len = new_dentry->d_name.len;
525 struct inode *i = old_dentry->d_inode; 525 struct inode *i = d_inode(old_dentry);
526 struct inode *new_inode = new_dentry->d_inode; 526 struct inode *new_inode = d_inode(new_dentry);
527 struct quad_buffer_head qbh, qbh1; 527 struct quad_buffer_head qbh, qbh1;
528 struct hpfs_dirent *dep, *nde; 528 struct hpfs_dirent *dep, *nde;
529 struct hpfs_dirent de; 529 struct hpfs_dirent de;
diff --git a/fs/hppfs/hppfs.c b/fs/hppfs/hppfs.c
index 043ac9d77262..fa2bd5366ecf 100644
--- a/fs/hppfs/hppfs.c
+++ b/fs/hppfs/hppfs.c
@@ -153,9 +153,9 @@ static struct dentry *hppfs_lookup(struct inode *ino, struct dentry *dentry,
153 return ERR_PTR(-ENOENT); 153 return ERR_PTR(-ENOENT);
154 154
155 parent = HPPFS_I(ino)->proc_dentry; 155 parent = HPPFS_I(ino)->proc_dentry;
156 mutex_lock(&parent->d_inode->i_mutex); 156 mutex_lock(&d_inode(parent)->i_mutex);
157 proc_dentry = lookup_one_len(name->name, parent, name->len); 157 proc_dentry = lookup_one_len(name->name, parent, name->len);
158 mutex_unlock(&parent->d_inode->i_mutex); 158 mutex_unlock(&d_inode(parent)->i_mutex);
159 159
160 if (IS_ERR(proc_dentry)) 160 if (IS_ERR(proc_dentry))
161 return proc_dentry; 161 return proc_dentry;
@@ -637,25 +637,25 @@ static const struct super_operations hppfs_sbops = {
637static int hppfs_readlink(struct dentry *dentry, char __user *buffer, 637static int hppfs_readlink(struct dentry *dentry, char __user *buffer,
638 int buflen) 638 int buflen)
639{ 639{
640 struct dentry *proc_dentry = HPPFS_I(dentry->d_inode)->proc_dentry; 640 struct dentry *proc_dentry = HPPFS_I(d_inode(dentry))->proc_dentry;
641 return proc_dentry->d_inode->i_op->readlink(proc_dentry, buffer, 641 return d_inode(proc_dentry)->i_op->readlink(proc_dentry, buffer,
642 buflen); 642 buflen);
643} 643}
644 644
645static void *hppfs_follow_link(struct dentry *dentry, struct nameidata *nd) 645static void *hppfs_follow_link(struct dentry *dentry, struct nameidata *nd)
646{ 646{
647 struct dentry *proc_dentry = HPPFS_I(dentry->d_inode)->proc_dentry; 647 struct dentry *proc_dentry = HPPFS_I(d_inode(dentry))->proc_dentry;
648 648
649 return proc_dentry->d_inode->i_op->follow_link(proc_dentry, nd); 649 return d_inode(proc_dentry)->i_op->follow_link(proc_dentry, nd);
650} 650}
651 651
652static void hppfs_put_link(struct dentry *dentry, struct nameidata *nd, 652static void hppfs_put_link(struct dentry *dentry, struct nameidata *nd,
653 void *cookie) 653 void *cookie)
654{ 654{
655 struct dentry *proc_dentry = HPPFS_I(dentry->d_inode)->proc_dentry; 655 struct dentry *proc_dentry = HPPFS_I(d_inode(dentry))->proc_dentry;
656 656
657 if (proc_dentry->d_inode->i_op->put_link) 657 if (d_inode(proc_dentry)->i_op->put_link)
658 proc_dentry->d_inode->i_op->put_link(proc_dentry, nd, cookie); 658 d_inode(proc_dentry)->i_op->put_link(proc_dentry, nd, cookie);
659} 659}
660 660
661static const struct inode_operations hppfs_dir_iops = { 661static const struct inode_operations hppfs_dir_iops = {
@@ -670,7 +670,7 @@ static const struct inode_operations hppfs_link_iops = {
670 670
671static struct inode *get_inode(struct super_block *sb, struct dentry *dentry) 671static struct inode *get_inode(struct super_block *sb, struct dentry *dentry)
672{ 672{
673 struct inode *proc_ino = dentry->d_inode; 673 struct inode *proc_ino = d_inode(dentry);
674 struct inode *inode = new_inode(sb); 674 struct inode *inode = new_inode(sb);
675 675
676 if (!inode) { 676 if (!inode) {
diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
index 2640d88b0e63..87724c1d7be6 100644
--- a/fs/hugetlbfs/inode.c
+++ b/fs/hugetlbfs/inode.c
@@ -393,7 +393,7 @@ static int hugetlb_vmtruncate(struct inode *inode, loff_t offset)
393 393
394static int hugetlbfs_setattr(struct dentry *dentry, struct iattr *attr) 394static int hugetlbfs_setattr(struct dentry *dentry, struct iattr *attr)
395{ 395{
396 struct inode *inode = dentry->d_inode; 396 struct inode *inode = d_inode(dentry);
397 struct hstate *h = hstate_inode(inode); 397 struct hstate *h = hstate_inode(inode);
398 int error; 398 int error;
399 unsigned int ia_valid = attr->ia_valid; 399 unsigned int ia_valid = attr->ia_valid;
@@ -587,7 +587,7 @@ static int hugetlbfs_migrate_page(struct address_space *mapping,
587static int hugetlbfs_statfs(struct dentry *dentry, struct kstatfs *buf) 587static int hugetlbfs_statfs(struct dentry *dentry, struct kstatfs *buf)
588{ 588{
589 struct hugetlbfs_sb_info *sbinfo = HUGETLBFS_SB(dentry->d_sb); 589 struct hugetlbfs_sb_info *sbinfo = HUGETLBFS_SB(dentry->d_sb);
590 struct hstate *h = hstate_inode(dentry->d_inode); 590 struct hstate *h = hstate_inode(d_inode(dentry));
591 591
592 buf->f_type = HUGETLBFS_MAGIC; 592 buf->f_type = HUGETLBFS_MAGIC;
593 buf->f_bsize = huge_page_size(h); 593 buf->f_bsize = huge_page_size(h);
diff --git a/fs/inode.c b/fs/inode.c
index f00b16f45507..ea37cd17b53f 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -1587,7 +1587,7 @@ static int update_time(struct inode *inode, struct timespec *time, int flags)
1587void touch_atime(const struct path *path) 1587void touch_atime(const struct path *path)
1588{ 1588{
1589 struct vfsmount *mnt = path->mnt; 1589 struct vfsmount *mnt = path->mnt;
1590 struct inode *inode = path->dentry->d_inode; 1590 struct inode *inode = d_inode(path->dentry);
1591 struct timespec now; 1591 struct timespec now;
1592 1592
1593 if (inode->i_flags & S_NOATIME) 1593 if (inode->i_flags & S_NOATIME)
@@ -1639,7 +1639,7 @@ EXPORT_SYMBOL(touch_atime);
1639 */ 1639 */
1640int should_remove_suid(struct dentry *dentry) 1640int should_remove_suid(struct dentry *dentry)
1641{ 1641{
1642 umode_t mode = dentry->d_inode->i_mode; 1642 umode_t mode = d_inode(dentry)->i_mode;
1643 int kill = 0; 1643 int kill = 0;
1644 1644
1645 /* suid always must be killed */ 1645 /* suid always must be killed */
@@ -1675,7 +1675,7 @@ static int __remove_suid(struct dentry *dentry, int kill)
1675int file_remove_suid(struct file *file) 1675int file_remove_suid(struct file *file)
1676{ 1676{
1677 struct dentry *dentry = file->f_path.dentry; 1677 struct dentry *dentry = file->f_path.dentry;
1678 struct inode *inode = dentry->d_inode; 1678 struct inode *inode = d_inode(dentry);
1679 int killsuid; 1679 int killsuid;
1680 int killpriv; 1680 int killpriv;
1681 int error = 0; 1681 int error = 0;
@@ -1946,20 +1946,6 @@ void inode_dio_wait(struct inode *inode)
1946EXPORT_SYMBOL(inode_dio_wait); 1946EXPORT_SYMBOL(inode_dio_wait);
1947 1947
1948/* 1948/*
1949 * inode_dio_done - signal finish of a direct I/O requests
1950 * @inode: inode the direct I/O happens on
1951 *
1952 * This is called once we've finished processing a direct I/O request,
1953 * and is used to wake up callers waiting for direct I/O to be quiesced.
1954 */
1955void inode_dio_done(struct inode *inode)
1956{
1957 if (atomic_dec_and_test(&inode->i_dio_count))
1958 wake_up_bit(&inode->i_state, __I_DIO_WAKEUP);
1959}
1960EXPORT_SYMBOL(inode_dio_done);
1961
1962/*
1963 * inode_set_flags - atomically set some inode flags 1949 * inode_set_flags - atomically set some inode flags
1964 * 1950 *
1965 * Note: the caller should be holding i_mutex, or else be sure that 1951 * Note: the caller should be holding i_mutex, or else be sure that
diff --git a/fs/isofs/export.c b/fs/isofs/export.c
index 12088d8de3fa..0c5f721b4e91 100644
--- a/fs/isofs/export.c
+++ b/fs/isofs/export.c
@@ -44,7 +44,7 @@ static struct dentry *isofs_export_get_parent(struct dentry *child)
44{ 44{
45 unsigned long parent_block = 0; 45 unsigned long parent_block = 0;
46 unsigned long parent_offset = 0; 46 unsigned long parent_offset = 0;
47 struct inode *child_inode = child->d_inode; 47 struct inode *child_inode = d_inode(child);
48 struct iso_inode_info *e_child_inode = ISOFS_I(child_inode); 48 struct iso_inode_info *e_child_inode = ISOFS_I(child_inode);
49 struct iso_directory_record *de = NULL; 49 struct iso_directory_record *de = NULL;
50 struct buffer_head * bh = NULL; 50 struct buffer_head * bh = NULL;
diff --git a/fs/jffs2/dir.c b/fs/jffs2/dir.c
index f21b6fb5e4c4..1ba5c97943b8 100644
--- a/fs/jffs2/dir.c
+++ b/fs/jffs2/dir.c
@@ -224,14 +224,14 @@ static int jffs2_unlink(struct inode *dir_i, struct dentry *dentry)
224{ 224{
225 struct jffs2_sb_info *c = JFFS2_SB_INFO(dir_i->i_sb); 225 struct jffs2_sb_info *c = JFFS2_SB_INFO(dir_i->i_sb);
226 struct jffs2_inode_info *dir_f = JFFS2_INODE_INFO(dir_i); 226 struct jffs2_inode_info *dir_f = JFFS2_INODE_INFO(dir_i);
227 struct jffs2_inode_info *dead_f = JFFS2_INODE_INFO(dentry->d_inode); 227 struct jffs2_inode_info *dead_f = JFFS2_INODE_INFO(d_inode(dentry));
228 int ret; 228 int ret;
229 uint32_t now = get_seconds(); 229 uint32_t now = get_seconds();
230 230
231 ret = jffs2_do_unlink(c, dir_f, dentry->d_name.name, 231 ret = jffs2_do_unlink(c, dir_f, dentry->d_name.name,
232 dentry->d_name.len, dead_f, now); 232 dentry->d_name.len, dead_f, now);
233 if (dead_f->inocache) 233 if (dead_f->inocache)
234 set_nlink(dentry->d_inode, dead_f->inocache->pino_nlink); 234 set_nlink(d_inode(dentry), dead_f->inocache->pino_nlink);
235 if (!ret) 235 if (!ret)
236 dir_i->i_mtime = dir_i->i_ctime = ITIME(now); 236 dir_i->i_mtime = dir_i->i_ctime = ITIME(now);
237 return ret; 237 return ret;
@@ -241,8 +241,8 @@ static int jffs2_unlink(struct inode *dir_i, struct dentry *dentry)
241 241
242static int jffs2_link (struct dentry *old_dentry, struct inode *dir_i, struct dentry *dentry) 242static int jffs2_link (struct dentry *old_dentry, struct inode *dir_i, struct dentry *dentry)
243{ 243{
244 struct jffs2_sb_info *c = JFFS2_SB_INFO(old_dentry->d_inode->i_sb); 244 struct jffs2_sb_info *c = JFFS2_SB_INFO(d_inode(old_dentry)->i_sb);
245 struct jffs2_inode_info *f = JFFS2_INODE_INFO(old_dentry->d_inode); 245 struct jffs2_inode_info *f = JFFS2_INODE_INFO(d_inode(old_dentry));
246 struct jffs2_inode_info *dir_f = JFFS2_INODE_INFO(dir_i); 246 struct jffs2_inode_info *dir_f = JFFS2_INODE_INFO(dir_i);
247 int ret; 247 int ret;
248 uint8_t type; 248 uint8_t type;
@@ -256,7 +256,7 @@ static int jffs2_link (struct dentry *old_dentry, struct inode *dir_i, struct de
256 return -EPERM; 256 return -EPERM;
257 257
258 /* XXX: This is ugly */ 258 /* XXX: This is ugly */
259 type = (old_dentry->d_inode->i_mode & S_IFMT) >> 12; 259 type = (d_inode(old_dentry)->i_mode & S_IFMT) >> 12;
260 if (!type) type = DT_REG; 260 if (!type) type = DT_REG;
261 261
262 now = get_seconds(); 262 now = get_seconds();
@@ -264,11 +264,11 @@ static int jffs2_link (struct dentry *old_dentry, struct inode *dir_i, struct de
264 264
265 if (!ret) { 265 if (!ret) {
266 mutex_lock(&f->sem); 266 mutex_lock(&f->sem);
267 set_nlink(old_dentry->d_inode, ++f->inocache->pino_nlink); 267 set_nlink(d_inode(old_dentry), ++f->inocache->pino_nlink);
268 mutex_unlock(&f->sem); 268 mutex_unlock(&f->sem);
269 d_instantiate(dentry, old_dentry->d_inode); 269 d_instantiate(dentry, d_inode(old_dentry));
270 dir_i->i_mtime = dir_i->i_ctime = ITIME(now); 270 dir_i->i_mtime = dir_i->i_ctime = ITIME(now);
271 ihold(old_dentry->d_inode); 271 ihold(d_inode(old_dentry));
272 } 272 }
273 return ret; 273 return ret;
274} 274}
@@ -585,7 +585,7 @@ static int jffs2_rmdir (struct inode *dir_i, struct dentry *dentry)
585{ 585{
586 struct jffs2_sb_info *c = JFFS2_SB_INFO(dir_i->i_sb); 586 struct jffs2_sb_info *c = JFFS2_SB_INFO(dir_i->i_sb);
587 struct jffs2_inode_info *dir_f = JFFS2_INODE_INFO(dir_i); 587 struct jffs2_inode_info *dir_f = JFFS2_INODE_INFO(dir_i);
588 struct jffs2_inode_info *f = JFFS2_INODE_INFO(dentry->d_inode); 588 struct jffs2_inode_info *f = JFFS2_INODE_INFO(d_inode(dentry));
589 struct jffs2_full_dirent *fd; 589 struct jffs2_full_dirent *fd;
590 int ret; 590 int ret;
591 uint32_t now = get_seconds(); 591 uint32_t now = get_seconds();
@@ -599,7 +599,7 @@ static int jffs2_rmdir (struct inode *dir_i, struct dentry *dentry)
599 dentry->d_name.len, f, now); 599 dentry->d_name.len, f, now);
600 if (!ret) { 600 if (!ret) {
601 dir_i->i_mtime = dir_i->i_ctime = ITIME(now); 601 dir_i->i_mtime = dir_i->i_ctime = ITIME(now);
602 clear_nlink(dentry->d_inode); 602 clear_nlink(d_inode(dentry));
603 drop_nlink(dir_i); 603 drop_nlink(dir_i);
604 } 604 }
605 return ret; 605 return ret;
@@ -770,8 +770,8 @@ static int jffs2_rename (struct inode *old_dir_i, struct dentry *old_dentry,
770 * the VFS can't check whether the victim is empty. The filesystem 770 * the VFS can't check whether the victim is empty. The filesystem
771 * needs to do that for itself. 771 * needs to do that for itself.
772 */ 772 */
773 if (new_dentry->d_inode) { 773 if (d_really_is_positive(new_dentry)) {
774 victim_f = JFFS2_INODE_INFO(new_dentry->d_inode); 774 victim_f = JFFS2_INODE_INFO(d_inode(new_dentry));
775 if (d_is_dir(new_dentry)) { 775 if (d_is_dir(new_dentry)) {
776 struct jffs2_full_dirent *fd; 776 struct jffs2_full_dirent *fd;
777 777
@@ -794,12 +794,12 @@ static int jffs2_rename (struct inode *old_dir_i, struct dentry *old_dentry,
794 /* Make a hard link */ 794 /* Make a hard link */
795 795
796 /* XXX: This is ugly */ 796 /* XXX: This is ugly */
797 type = (old_dentry->d_inode->i_mode & S_IFMT) >> 12; 797 type = (d_inode(old_dentry)->i_mode & S_IFMT) >> 12;
798 if (!type) type = DT_REG; 798 if (!type) type = DT_REG;
799 799
800 now = get_seconds(); 800 now = get_seconds();
801 ret = jffs2_do_link(c, JFFS2_INODE_INFO(new_dir_i), 801 ret = jffs2_do_link(c, JFFS2_INODE_INFO(new_dir_i),
802 old_dentry->d_inode->i_ino, type, 802 d_inode(old_dentry)->i_ino, type,
803 new_dentry->d_name.name, new_dentry->d_name.len, now); 803 new_dentry->d_name.name, new_dentry->d_name.len, now);
804 804
805 if (ret) 805 if (ret)
@@ -808,9 +808,9 @@ static int jffs2_rename (struct inode *old_dir_i, struct dentry *old_dentry,
808 if (victim_f) { 808 if (victim_f) {
809 /* There was a victim. Kill it off nicely */ 809 /* There was a victim. Kill it off nicely */
810 if (d_is_dir(new_dentry)) 810 if (d_is_dir(new_dentry))
811 clear_nlink(new_dentry->d_inode); 811 clear_nlink(d_inode(new_dentry));
812 else 812 else
813 drop_nlink(new_dentry->d_inode); 813 drop_nlink(d_inode(new_dentry));
814 /* Don't oops if the victim was a dirent pointing to an 814 /* Don't oops if the victim was a dirent pointing to an
815 inode which didn't exist. */ 815 inode which didn't exist. */
816 if (victim_f->inocache) { 816 if (victim_f->inocache) {
@@ -836,9 +836,9 @@ static int jffs2_rename (struct inode *old_dir_i, struct dentry *old_dentry,
836 836
837 if (ret) { 837 if (ret) {
838 /* Oh shit. We really ought to make a single node which can do both atomically */ 838 /* Oh shit. We really ought to make a single node which can do both atomically */
839 struct jffs2_inode_info *f = JFFS2_INODE_INFO(old_dentry->d_inode); 839 struct jffs2_inode_info *f = JFFS2_INODE_INFO(d_inode(old_dentry));
840 mutex_lock(&f->sem); 840 mutex_lock(&f->sem);
841 inc_nlink(old_dentry->d_inode); 841 inc_nlink(d_inode(old_dentry));
842 if (f->inocache && !d_is_dir(old_dentry)) 842 if (f->inocache && !d_is_dir(old_dentry))
843 f->inocache->pino_nlink++; 843 f->inocache->pino_nlink++;
844 mutex_unlock(&f->sem); 844 mutex_unlock(&f->sem);
@@ -846,8 +846,8 @@ static int jffs2_rename (struct inode *old_dir_i, struct dentry *old_dentry,
846 pr_notice("%s(): Link succeeded, unlink failed (err %d). You now have a hard link\n", 846 pr_notice("%s(): Link succeeded, unlink failed (err %d). You now have a hard link\n",
847 __func__, ret); 847 __func__, ret);
848 /* Might as well let the VFS know */ 848 /* Might as well let the VFS know */
849 d_instantiate(new_dentry, old_dentry->d_inode); 849 d_instantiate(new_dentry, d_inode(old_dentry));
850 ihold(old_dentry->d_inode); 850 ihold(d_inode(old_dentry));
851 new_dir_i->i_mtime = new_dir_i->i_ctime = ITIME(now); 851 new_dir_i->i_mtime = new_dir_i->i_ctime = ITIME(now);
852 return ret; 852 return ret;
853 } 853 }
diff --git a/fs/jffs2/fs.c b/fs/jffs2/fs.c
index 601afd1afddf..fe5ea080b4ec 100644
--- a/fs/jffs2/fs.c
+++ b/fs/jffs2/fs.c
@@ -190,7 +190,7 @@ int jffs2_do_setattr (struct inode *inode, struct iattr *iattr)
190 190
191int jffs2_setattr(struct dentry *dentry, struct iattr *iattr) 191int jffs2_setattr(struct dentry *dentry, struct iattr *iattr)
192{ 192{
193 struct inode *inode = dentry->d_inode; 193 struct inode *inode = d_inode(dentry);
194 int rc; 194 int rc;
195 195
196 rc = inode_change_ok(inode, iattr); 196 rc = inode_change_ok(inode, iattr);
diff --git a/fs/jffs2/security.c b/fs/jffs2/security.c
index aca97f35b292..d4b43fb7adb1 100644
--- a/fs/jffs2/security.c
+++ b/fs/jffs2/security.c
@@ -54,7 +54,7 @@ static int jffs2_security_getxattr(struct dentry *dentry, const char *name,
54 if (!strcmp(name, "")) 54 if (!strcmp(name, ""))
55 return -EINVAL; 55 return -EINVAL;
56 56
57 return do_jffs2_getxattr(dentry->d_inode, JFFS2_XPREFIX_SECURITY, 57 return do_jffs2_getxattr(d_inode(dentry), JFFS2_XPREFIX_SECURITY,
58 name, buffer, size); 58 name, buffer, size);
59} 59}
60 60
@@ -64,7 +64,7 @@ static int jffs2_security_setxattr(struct dentry *dentry, const char *name,
64 if (!strcmp(name, "")) 64 if (!strcmp(name, ""))
65 return -EINVAL; 65 return -EINVAL;
66 66
67 return do_jffs2_setxattr(dentry->d_inode, JFFS2_XPREFIX_SECURITY, 67 return do_jffs2_setxattr(d_inode(dentry), JFFS2_XPREFIX_SECURITY,
68 name, buffer, size, flags); 68 name, buffer, size, flags);
69} 69}
70 70
diff --git a/fs/jffs2/super.c b/fs/jffs2/super.c
index 3d76f28a2ba9..d86c5e3176a1 100644
--- a/fs/jffs2/super.c
+++ b/fs/jffs2/super.c
@@ -140,14 +140,14 @@ static struct dentry *jffs2_get_parent(struct dentry *child)
140 140
141 BUG_ON(!d_is_dir(child)); 141 BUG_ON(!d_is_dir(child));
142 142
143 f = JFFS2_INODE_INFO(child->d_inode); 143 f = JFFS2_INODE_INFO(d_inode(child));
144 144
145 pino = f->inocache->pino_nlink; 145 pino = f->inocache->pino_nlink;
146 146
147 JFFS2_DEBUG("Parent of directory ino #%u is #%u\n", 147 JFFS2_DEBUG("Parent of directory ino #%u is #%u\n",
148 f->inocache->ino, pino); 148 f->inocache->ino, pino);
149 149
150 return d_obtain_alias(jffs2_iget(child->d_inode->i_sb, pino)); 150 return d_obtain_alias(jffs2_iget(d_inode(child)->i_sb, pino));
151} 151}
152 152
153static const struct export_operations jffs2_export_ops = { 153static const struct export_operations jffs2_export_ops = {
diff --git a/fs/jffs2/symlink.c b/fs/jffs2/symlink.c
index c7c77b0dfccd..1fefa25d0fa5 100644
--- a/fs/jffs2/symlink.c
+++ b/fs/jffs2/symlink.c
@@ -31,7 +31,7 @@ const struct inode_operations jffs2_symlink_inode_operations =
31 31
32static void *jffs2_follow_link(struct dentry *dentry, struct nameidata *nd) 32static void *jffs2_follow_link(struct dentry *dentry, struct nameidata *nd)
33{ 33{
34 struct jffs2_inode_info *f = JFFS2_INODE_INFO(dentry->d_inode); 34 struct jffs2_inode_info *f = JFFS2_INODE_INFO(d_inode(dentry));
35 char *p = (char *)f->target; 35 char *p = (char *)f->target;
36 36
37 /* 37 /*
diff --git a/fs/jffs2/xattr.c b/fs/jffs2/xattr.c
index 2eac55379239..f092fee5be50 100644
--- a/fs/jffs2/xattr.c
+++ b/fs/jffs2/xattr.c
@@ -960,7 +960,7 @@ static const struct xattr_handler *xprefix_to_handler(int xprefix) {
960 960
961ssize_t jffs2_listxattr(struct dentry *dentry, char *buffer, size_t size) 961ssize_t jffs2_listxattr(struct dentry *dentry, char *buffer, size_t size)
962{ 962{
963 struct inode *inode = dentry->d_inode; 963 struct inode *inode = d_inode(dentry);
964 struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode); 964 struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode);
965 struct jffs2_sb_info *c = JFFS2_SB_INFO(inode->i_sb); 965 struct jffs2_sb_info *c = JFFS2_SB_INFO(inode->i_sb);
966 struct jffs2_inode_cache *ic = f->inocache; 966 struct jffs2_inode_cache *ic = f->inocache;
diff --git a/fs/jffs2/xattr_trusted.c b/fs/jffs2/xattr_trusted.c
index 1c868194c504..ceaf9c693225 100644
--- a/fs/jffs2/xattr_trusted.c
+++ b/fs/jffs2/xattr_trusted.c
@@ -21,7 +21,7 @@ static int jffs2_trusted_getxattr(struct dentry *dentry, const char *name,
21{ 21{
22 if (!strcmp(name, "")) 22 if (!strcmp(name, ""))
23 return -EINVAL; 23 return -EINVAL;
24 return do_jffs2_getxattr(dentry->d_inode, JFFS2_XPREFIX_TRUSTED, 24 return do_jffs2_getxattr(d_inode(dentry), JFFS2_XPREFIX_TRUSTED,
25 name, buffer, size); 25 name, buffer, size);
26} 26}
27 27
@@ -30,7 +30,7 @@ static int jffs2_trusted_setxattr(struct dentry *dentry, const char *name,
30{ 30{
31 if (!strcmp(name, "")) 31 if (!strcmp(name, ""))
32 return -EINVAL; 32 return -EINVAL;
33 return do_jffs2_setxattr(dentry->d_inode, JFFS2_XPREFIX_TRUSTED, 33 return do_jffs2_setxattr(d_inode(dentry), JFFS2_XPREFIX_TRUSTED,
34 name, buffer, size, flags); 34 name, buffer, size, flags);
35} 35}
36 36
diff --git a/fs/jffs2/xattr_user.c b/fs/jffs2/xattr_user.c
index 916b5c966039..a71391eba514 100644
--- a/fs/jffs2/xattr_user.c
+++ b/fs/jffs2/xattr_user.c
@@ -21,7 +21,7 @@ static int jffs2_user_getxattr(struct dentry *dentry, const char *name,
21{ 21{
22 if (!strcmp(name, "")) 22 if (!strcmp(name, ""))
23 return -EINVAL; 23 return -EINVAL;
24 return do_jffs2_getxattr(dentry->d_inode, JFFS2_XPREFIX_USER, 24 return do_jffs2_getxattr(d_inode(dentry), JFFS2_XPREFIX_USER,
25 name, buffer, size); 25 name, buffer, size);
26} 26}
27 27
@@ -30,7 +30,7 @@ static int jffs2_user_setxattr(struct dentry *dentry, const char *name,
30{ 30{
31 if (!strcmp(name, "")) 31 if (!strcmp(name, ""))
32 return -EINVAL; 32 return -EINVAL;
33 return do_jffs2_setxattr(dentry->d_inode, JFFS2_XPREFIX_USER, 33 return do_jffs2_setxattr(d_inode(dentry), JFFS2_XPREFIX_USER,
34 name, buffer, size, flags); 34 name, buffer, size, flags);
35} 35}
36 36
diff --git a/fs/jfs/file.c b/fs/jfs/file.c
index ae46788b9723..e98d39d75cf4 100644
--- a/fs/jfs/file.c
+++ b/fs/jfs/file.c
@@ -100,7 +100,7 @@ static int jfs_release(struct inode *inode, struct file *file)
100 100
101int jfs_setattr(struct dentry *dentry, struct iattr *iattr) 101int jfs_setattr(struct dentry *dentry, struct iattr *iattr)
102{ 102{
103 struct inode *inode = dentry->d_inode; 103 struct inode *inode = d_inode(dentry);
104 int rc; 104 int rc;
105 105
106 rc = inode_change_ok(inode, iattr); 106 rc = inode_change_ok(inode, iattr);
diff --git a/fs/jfs/namei.c b/fs/jfs/namei.c
index 38fdc533f4ec..66db7bc0ed10 100644
--- a/fs/jfs/namei.c
+++ b/fs/jfs/namei.c
@@ -346,7 +346,7 @@ static int jfs_rmdir(struct inode *dip, struct dentry *dentry)
346{ 346{
347 int rc; 347 int rc;
348 tid_t tid; /* transaction id */ 348 tid_t tid; /* transaction id */
349 struct inode *ip = dentry->d_inode; 349 struct inode *ip = d_inode(dentry);
350 ino_t ino; 350 ino_t ino;
351 struct component_name dname; 351 struct component_name dname;
352 struct inode *iplist[2]; 352 struct inode *iplist[2];
@@ -472,7 +472,7 @@ static int jfs_unlink(struct inode *dip, struct dentry *dentry)
472{ 472{
473 int rc; 473 int rc;
474 tid_t tid; /* transaction id */ 474 tid_t tid; /* transaction id */
475 struct inode *ip = dentry->d_inode; 475 struct inode *ip = d_inode(dentry);
476 ino_t ino; 476 ino_t ino;
477 struct component_name dname; /* object name */ 477 struct component_name dname; /* object name */
478 struct inode *iplist[2]; 478 struct inode *iplist[2];
@@ -791,7 +791,7 @@ static int jfs_link(struct dentry *old_dentry,
791{ 791{
792 int rc; 792 int rc;
793 tid_t tid; 793 tid_t tid;
794 struct inode *ip = old_dentry->d_inode; 794 struct inode *ip = d_inode(old_dentry);
795 ino_t ino; 795 ino_t ino;
796 struct component_name dname; 796 struct component_name dname;
797 struct btstack btstack; 797 struct btstack btstack;
@@ -879,7 +879,7 @@ static int jfs_symlink(struct inode *dip, struct dentry *dentry,
879 struct component_name dname; 879 struct component_name dname;
880 int ssize; /* source pathname size */ 880 int ssize; /* source pathname size */
881 struct btstack btstack; 881 struct btstack btstack;
882 struct inode *ip = dentry->d_inode; 882 struct inode *ip = d_inode(dentry);
883 unchar *i_fastsymlink; 883 unchar *i_fastsymlink;
884 s64 xlen = 0; 884 s64 xlen = 0;
885 int bmask = 0, xsize; 885 int bmask = 0, xsize;
@@ -1086,8 +1086,8 @@ static int jfs_rename(struct inode *old_dir, struct dentry *old_dentry,
1086 dquot_initialize(old_dir); 1086 dquot_initialize(old_dir);
1087 dquot_initialize(new_dir); 1087 dquot_initialize(new_dir);
1088 1088
1089 old_ip = old_dentry->d_inode; 1089 old_ip = d_inode(old_dentry);
1090 new_ip = new_dentry->d_inode; 1090 new_ip = d_inode(new_dentry);
1091 1091
1092 if ((rc = get_UCSname(&old_dname, old_dentry))) 1092 if ((rc = get_UCSname(&old_dname, old_dentry)))
1093 goto out1; 1093 goto out1;
@@ -1500,9 +1500,9 @@ struct dentry *jfs_get_parent(struct dentry *dentry)
1500 unsigned long parent_ino; 1500 unsigned long parent_ino;
1501 1501
1502 parent_ino = 1502 parent_ino =
1503 le32_to_cpu(JFS_IP(dentry->d_inode)->i_dtroot.header.idotdot); 1503 le32_to_cpu(JFS_IP(d_inode(dentry))->i_dtroot.header.idotdot);
1504 1504
1505 return d_obtain_alias(jfs_iget(dentry->d_inode->i_sb, parent_ino)); 1505 return d_obtain_alias(jfs_iget(d_inode(dentry)->i_sb, parent_ino));
1506} 1506}
1507 1507
1508const struct inode_operations jfs_dir_inode_operations = { 1508const struct inode_operations jfs_dir_inode_operations = {
@@ -1578,7 +1578,7 @@ static int jfs_ci_revalidate(struct dentry *dentry, unsigned int flags)
1578 * positive dentry isn't good idea. So it's unsupported like 1578 * positive dentry isn't good idea. So it's unsupported like
1579 * rename("filename", "FILENAME") for now. 1579 * rename("filename", "FILENAME") for now.
1580 */ 1580 */
1581 if (dentry->d_inode) 1581 if (d_really_is_positive(dentry))
1582 return 1; 1582 return 1;
1583 1583
1584 /* 1584 /*
diff --git a/fs/jfs/symlink.c b/fs/jfs/symlink.c
index 205b946d8e0d..80f42bcc4ef1 100644
--- a/fs/jfs/symlink.c
+++ b/fs/jfs/symlink.c
@@ -24,7 +24,7 @@
24 24
25static void *jfs_follow_link(struct dentry *dentry, struct nameidata *nd) 25static void *jfs_follow_link(struct dentry *dentry, struct nameidata *nd)
26{ 26{
27 char *s = JFS_IP(dentry->d_inode)->i_inline; 27 char *s = JFS_IP(d_inode(dentry))->i_inline;
28 nd_set_link(nd, s); 28 nd_set_link(nd, s);
29 return NULL; 29 return NULL;
30} 30}
diff --git a/fs/jfs/xattr.c b/fs/jfs/xattr.c
index 46325d5c34fc..48b15a6e5558 100644
--- a/fs/jfs/xattr.c
+++ b/fs/jfs/xattr.c
@@ -849,7 +849,7 @@ int __jfs_setxattr(tid_t tid, struct inode *inode, const char *name,
849int jfs_setxattr(struct dentry *dentry, const char *name, const void *value, 849int jfs_setxattr(struct dentry *dentry, const char *name, const void *value,
850 size_t value_len, int flags) 850 size_t value_len, int flags)
851{ 851{
852 struct inode *inode = dentry->d_inode; 852 struct inode *inode = d_inode(dentry);
853 struct jfs_inode_info *ji = JFS_IP(inode); 853 struct jfs_inode_info *ji = JFS_IP(inode);
854 int rc; 854 int rc;
855 tid_t tid; 855 tid_t tid;
@@ -872,7 +872,7 @@ int jfs_setxattr(struct dentry *dentry, const char *name, const void *value,
872 872
873 tid = txBegin(inode->i_sb, 0); 873 tid = txBegin(inode->i_sb, 0);
874 mutex_lock(&ji->commit_mutex); 874 mutex_lock(&ji->commit_mutex);
875 rc = __jfs_setxattr(tid, dentry->d_inode, name, value, value_len, 875 rc = __jfs_setxattr(tid, d_inode(dentry), name, value, value_len,
876 flags); 876 flags);
877 if (!rc) 877 if (!rc)
878 rc = txCommit(tid, 1, &inode, 0); 878 rc = txCommit(tid, 1, &inode, 0);
@@ -959,7 +959,7 @@ ssize_t jfs_getxattr(struct dentry *dentry, const char *name, void *data,
959 return -EOPNOTSUPP; 959 return -EOPNOTSUPP;
960 } 960 }
961 961
962 err = __jfs_getxattr(dentry->d_inode, name, data, buf_size); 962 err = __jfs_getxattr(d_inode(dentry), name, data, buf_size);
963 963
964 return err; 964 return err;
965} 965}
@@ -976,7 +976,7 @@ static inline int can_list(struct jfs_ea *ea)
976 976
977ssize_t jfs_listxattr(struct dentry * dentry, char *data, size_t buf_size) 977ssize_t jfs_listxattr(struct dentry * dentry, char *data, size_t buf_size)
978{ 978{
979 struct inode *inode = dentry->d_inode; 979 struct inode *inode = d_inode(dentry);
980 char *buffer; 980 char *buffer;
981 ssize_t size = 0; 981 ssize_t size = 0;
982 int xattr_size; 982 int xattr_size;
@@ -1029,7 +1029,7 @@ ssize_t jfs_listxattr(struct dentry * dentry, char *data, size_t buf_size)
1029 1029
1030int jfs_removexattr(struct dentry *dentry, const char *name) 1030int jfs_removexattr(struct dentry *dentry, const char *name)
1031{ 1031{
1032 struct inode *inode = dentry->d_inode; 1032 struct inode *inode = d_inode(dentry);
1033 struct jfs_inode_info *ji = JFS_IP(inode); 1033 struct jfs_inode_info *ji = JFS_IP(inode);
1034 int rc; 1034 int rc;
1035 tid_t tid; 1035 tid_t tid;
@@ -1047,7 +1047,7 @@ int jfs_removexattr(struct dentry *dentry, const char *name)
1047 1047
1048 tid = txBegin(inode->i_sb, 0); 1048 tid = txBegin(inode->i_sb, 0);
1049 mutex_lock(&ji->commit_mutex); 1049 mutex_lock(&ji->commit_mutex);
1050 rc = __jfs_setxattr(tid, dentry->d_inode, name, NULL, 0, XATTR_REPLACE); 1050 rc = __jfs_setxattr(tid, d_inode(dentry), name, NULL, 0, XATTR_REPLACE);
1051 if (!rc) 1051 if (!rc)
1052 rc = txCommit(tid, 1, &inode, 0); 1052 rc = txCommit(tid, 1, &inode, 0);
1053 txEnd(tid); 1053 txEnd(tid);
diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
index 6acc9648f986..f131fc23ffc4 100644
--- a/fs/kernfs/dir.c
+++ b/fs/kernfs/dir.c
@@ -444,7 +444,7 @@ static int kernfs_dop_revalidate(struct dentry *dentry, unsigned int flags)
444 return -ECHILD; 444 return -ECHILD;
445 445
446 /* Always perform fresh lookup for negatives */ 446 /* Always perform fresh lookup for negatives */
447 if (!dentry->d_inode) 447 if (d_really_is_negative(dentry))
448 goto out_bad_unlocked; 448 goto out_bad_unlocked;
449 449
450 kn = dentry->d_fsdata; 450 kn = dentry->d_fsdata;
diff --git a/fs/kernfs/inode.c b/fs/kernfs/inode.c
index 9000874a945b..2da8493a380b 100644
--- a/fs/kernfs/inode.c
+++ b/fs/kernfs/inode.c
@@ -111,7 +111,7 @@ int kernfs_setattr(struct kernfs_node *kn, const struct iattr *iattr)
111 111
112int kernfs_iop_setattr(struct dentry *dentry, struct iattr *iattr) 112int kernfs_iop_setattr(struct dentry *dentry, struct iattr *iattr)
113{ 113{
114 struct inode *inode = dentry->d_inode; 114 struct inode *inode = d_inode(dentry);
115 struct kernfs_node *kn = dentry->d_fsdata; 115 struct kernfs_node *kn = dentry->d_fsdata;
116 int error; 116 int error;
117 117
@@ -172,11 +172,11 @@ int kernfs_iop_setxattr(struct dentry *dentry, const char *name,
172 172
173 if (!strncmp(name, XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN)) { 173 if (!strncmp(name, XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN)) {
174 const char *suffix = name + XATTR_SECURITY_PREFIX_LEN; 174 const char *suffix = name + XATTR_SECURITY_PREFIX_LEN;
175 error = security_inode_setsecurity(dentry->d_inode, suffix, 175 error = security_inode_setsecurity(d_inode(dentry), suffix,
176 value, size, flags); 176 value, size, flags);
177 if (error) 177 if (error)
178 return error; 178 return error;
179 error = security_inode_getsecctx(dentry->d_inode, 179 error = security_inode_getsecctx(d_inode(dentry),
180 &secdata, &secdata_len); 180 &secdata, &secdata_len);
181 if (error) 181 if (error)
182 return error; 182 return error;
@@ -271,7 +271,7 @@ int kernfs_iop_getattr(struct vfsmount *mnt, struct dentry *dentry,
271 struct kstat *stat) 271 struct kstat *stat)
272{ 272{
273 struct kernfs_node *kn = dentry->d_fsdata; 273 struct kernfs_node *kn = dentry->d_fsdata;
274 struct inode *inode = dentry->d_inode; 274 struct inode *inode = d_inode(dentry);
275 275
276 mutex_lock(&kernfs_mutex); 276 mutex_lock(&kernfs_mutex);
277 kernfs_refresh_inode(kn, inode); 277 kernfs_refresh_inode(kn, inode);
diff --git a/fs/libfs.c b/fs/libfs.c
index 0ab65122ee45..cb1fb4b9b637 100644
--- a/fs/libfs.c
+++ b/fs/libfs.c
@@ -22,13 +22,13 @@
22 22
23static inline int simple_positive(struct dentry *dentry) 23static inline int simple_positive(struct dentry *dentry)
24{ 24{
25 return dentry->d_inode && !d_unhashed(dentry); 25 return d_really_is_positive(dentry) && !d_unhashed(dentry);
26} 26}
27 27
28int simple_getattr(struct vfsmount *mnt, struct dentry *dentry, 28int simple_getattr(struct vfsmount *mnt, struct dentry *dentry,
29 struct kstat *stat) 29 struct kstat *stat)
30{ 30{
31 struct inode *inode = dentry->d_inode; 31 struct inode *inode = d_inode(dentry);
32 generic_fillattr(inode, stat); 32 generic_fillattr(inode, stat);
33 stat->blocks = inode->i_mapping->nrpages << (PAGE_CACHE_SHIFT - 9); 33 stat->blocks = inode->i_mapping->nrpages << (PAGE_CACHE_SHIFT - 9);
34 return 0; 34 return 0;
@@ -94,7 +94,7 @@ EXPORT_SYMBOL(dcache_dir_close);
94loff_t dcache_dir_lseek(struct file *file, loff_t offset, int whence) 94loff_t dcache_dir_lseek(struct file *file, loff_t offset, int whence)
95{ 95{
96 struct dentry *dentry = file->f_path.dentry; 96 struct dentry *dentry = file->f_path.dentry;
97 mutex_lock(&dentry->d_inode->i_mutex); 97 mutex_lock(&d_inode(dentry)->i_mutex);
98 switch (whence) { 98 switch (whence) {
99 case 1: 99 case 1:
100 offset += file->f_pos; 100 offset += file->f_pos;
@@ -102,7 +102,7 @@ loff_t dcache_dir_lseek(struct file *file, loff_t offset, int whence)
102 if (offset >= 0) 102 if (offset >= 0)
103 break; 103 break;
104 default: 104 default:
105 mutex_unlock(&dentry->d_inode->i_mutex); 105 mutex_unlock(&d_inode(dentry)->i_mutex);
106 return -EINVAL; 106 return -EINVAL;
107 } 107 }
108 if (offset != file->f_pos) { 108 if (offset != file->f_pos) {
@@ -129,7 +129,7 @@ loff_t dcache_dir_lseek(struct file *file, loff_t offset, int whence)
129 spin_unlock(&dentry->d_lock); 129 spin_unlock(&dentry->d_lock);
130 } 130 }
131 } 131 }
132 mutex_unlock(&dentry->d_inode->i_mutex); 132 mutex_unlock(&d_inode(dentry)->i_mutex);
133 return offset; 133 return offset;
134} 134}
135EXPORT_SYMBOL(dcache_dir_lseek); 135EXPORT_SYMBOL(dcache_dir_lseek);
@@ -169,7 +169,7 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
169 spin_unlock(&next->d_lock); 169 spin_unlock(&next->d_lock);
170 spin_unlock(&dentry->d_lock); 170 spin_unlock(&dentry->d_lock);
171 if (!dir_emit(ctx, next->d_name.name, next->d_name.len, 171 if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
172 next->d_inode->i_ino, dt_type(next->d_inode))) 172 d_inode(next)->i_ino, dt_type(d_inode(next))))
173 return 0; 173 return 0;
174 spin_lock(&dentry->d_lock); 174 spin_lock(&dentry->d_lock);
175 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED); 175 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
@@ -270,7 +270,7 @@ EXPORT_SYMBOL(simple_open);
270 270
271int simple_link(struct dentry *old_dentry, struct inode *dir, struct dentry *dentry) 271int simple_link(struct dentry *old_dentry, struct inode *dir, struct dentry *dentry)
272{ 272{
273 struct inode *inode = old_dentry->d_inode; 273 struct inode *inode = d_inode(old_dentry);
274 274
275 inode->i_ctime = dir->i_ctime = dir->i_mtime = CURRENT_TIME; 275 inode->i_ctime = dir->i_ctime = dir->i_mtime = CURRENT_TIME;
276 inc_nlink(inode); 276 inc_nlink(inode);
@@ -304,7 +304,7 @@ EXPORT_SYMBOL(simple_empty);
304 304
305int simple_unlink(struct inode *dir, struct dentry *dentry) 305int simple_unlink(struct inode *dir, struct dentry *dentry)
306{ 306{
307 struct inode *inode = dentry->d_inode; 307 struct inode *inode = d_inode(dentry);
308 308
309 inode->i_ctime = dir->i_ctime = dir->i_mtime = CURRENT_TIME; 309 inode->i_ctime = dir->i_ctime = dir->i_mtime = CURRENT_TIME;
310 drop_nlink(inode); 310 drop_nlink(inode);
@@ -318,7 +318,7 @@ int simple_rmdir(struct inode *dir, struct dentry *dentry)
318 if (!simple_empty(dentry)) 318 if (!simple_empty(dentry))
319 return -ENOTEMPTY; 319 return -ENOTEMPTY;
320 320
321 drop_nlink(dentry->d_inode); 321 drop_nlink(d_inode(dentry));
322 simple_unlink(dir, dentry); 322 simple_unlink(dir, dentry);
323 drop_nlink(dir); 323 drop_nlink(dir);
324 return 0; 324 return 0;
@@ -328,16 +328,16 @@ EXPORT_SYMBOL(simple_rmdir);
328int simple_rename(struct inode *old_dir, struct dentry *old_dentry, 328int simple_rename(struct inode *old_dir, struct dentry *old_dentry,
329 struct inode *new_dir, struct dentry *new_dentry) 329 struct inode *new_dir, struct dentry *new_dentry)
330{ 330{
331 struct inode *inode = old_dentry->d_inode; 331 struct inode *inode = d_inode(old_dentry);
332 int they_are_dirs = d_is_dir(old_dentry); 332 int they_are_dirs = d_is_dir(old_dentry);
333 333
334 if (!simple_empty(new_dentry)) 334 if (!simple_empty(new_dentry))
335 return -ENOTEMPTY; 335 return -ENOTEMPTY;
336 336
337 if (new_dentry->d_inode) { 337 if (d_really_is_positive(new_dentry)) {
338 simple_unlink(new_dir, new_dentry); 338 simple_unlink(new_dir, new_dentry);
339 if (they_are_dirs) { 339 if (they_are_dirs) {
340 drop_nlink(new_dentry->d_inode); 340 drop_nlink(d_inode(new_dentry));
341 drop_nlink(old_dir); 341 drop_nlink(old_dir);
342 } 342 }
343 } else if (they_are_dirs) { 343 } else if (they_are_dirs) {
@@ -368,7 +368,7 @@ EXPORT_SYMBOL(simple_rename);
368 */ 368 */
369int simple_setattr(struct dentry *dentry, struct iattr *iattr) 369int simple_setattr(struct dentry *dentry, struct iattr *iattr)
370{ 370{
371 struct inode *inode = dentry->d_inode; 371 struct inode *inode = d_inode(dentry);
372 int error; 372 int error;
373 373
374 error = inode_change_ok(inode, iattr); 374 error = inode_change_ok(inode, iattr);
diff --git a/fs/lockd/svcsubs.c b/fs/lockd/svcsubs.c
index 665ef5a05183..a563ddbc19e6 100644
--- a/fs/lockd/svcsubs.c
+++ b/fs/lockd/svcsubs.c
@@ -31,7 +31,7 @@
31static struct hlist_head nlm_files[FILE_NRHASH]; 31static struct hlist_head nlm_files[FILE_NRHASH];
32static DEFINE_MUTEX(nlm_file_mutex); 32static DEFINE_MUTEX(nlm_file_mutex);
33 33
34#ifdef NFSD_DEBUG 34#ifdef CONFIG_SUNRPC_DEBUG
35static inline void nlm_debug_print_fh(char *msg, struct nfs_fh *f) 35static inline void nlm_debug_print_fh(char *msg, struct nfs_fh *f)
36{ 36{
37 u32 *fhp = (u32*)f->data; 37 u32 *fhp = (u32*)f->data;
diff --git a/fs/logfs/dir.c b/fs/logfs/dir.c
index 6bdc347008f5..4cf38f118549 100644
--- a/fs/logfs/dir.c
+++ b/fs/logfs/dir.c
@@ -213,7 +213,7 @@ static void abort_transaction(struct inode *inode, struct logfs_transaction *ta)
213static int logfs_unlink(struct inode *dir, struct dentry *dentry) 213static int logfs_unlink(struct inode *dir, struct dentry *dentry)
214{ 214{
215 struct logfs_super *super = logfs_super(dir->i_sb); 215 struct logfs_super *super = logfs_super(dir->i_sb);
216 struct inode *inode = dentry->d_inode; 216 struct inode *inode = d_inode(dentry);
217 struct logfs_transaction *ta; 217 struct logfs_transaction *ta;
218 struct page *page; 218 struct page *page;
219 pgoff_t index; 219 pgoff_t index;
@@ -271,7 +271,7 @@ static inline int logfs_empty_dir(struct inode *dir)
271 271
272static int logfs_rmdir(struct inode *dir, struct dentry *dentry) 272static int logfs_rmdir(struct inode *dir, struct dentry *dentry)
273{ 273{
274 struct inode *inode = dentry->d_inode; 274 struct inode *inode = d_inode(dentry);
275 275
276 if (!logfs_empty_dir(inode)) 276 if (!logfs_empty_dir(inode))
277 return -ENOTEMPTY; 277 return -ENOTEMPTY;
@@ -537,7 +537,7 @@ static int logfs_symlink(struct inode *dir, struct dentry *dentry,
537static int logfs_link(struct dentry *old_dentry, struct inode *dir, 537static int logfs_link(struct dentry *old_dentry, struct inode *dir,
538 struct dentry *dentry) 538 struct dentry *dentry)
539{ 539{
540 struct inode *inode = old_dentry->d_inode; 540 struct inode *inode = d_inode(old_dentry);
541 541
542 inode->i_ctime = dir->i_ctime = dir->i_mtime = CURRENT_TIME; 542 inode->i_ctime = dir->i_ctime = dir->i_mtime = CURRENT_TIME;
543 ihold(inode); 543 ihold(inode);
@@ -607,7 +607,7 @@ static int logfs_rename_cross(struct inode *old_dir, struct dentry *old_dentry,
607 /* 2. write target dd */ 607 /* 2. write target dd */
608 mutex_lock(&super->s_dirop_mutex); 608 mutex_lock(&super->s_dirop_mutex);
609 logfs_add_transaction(new_dir, ta); 609 logfs_add_transaction(new_dir, ta);
610 err = logfs_write_dir(new_dir, new_dentry, old_dentry->d_inode); 610 err = logfs_write_dir(new_dir, new_dentry, d_inode(old_dentry));
611 if (!err) 611 if (!err)
612 err = write_inode(new_dir); 612 err = write_inode(new_dir);
613 613
@@ -658,8 +658,8 @@ static int logfs_rename_target(struct inode *old_dir, struct dentry *old_dentry,
658 struct inode *new_dir, struct dentry *new_dentry) 658 struct inode *new_dir, struct dentry *new_dentry)
659{ 659{
660 struct logfs_super *super = logfs_super(old_dir->i_sb); 660 struct logfs_super *super = logfs_super(old_dir->i_sb);
661 struct inode *old_inode = old_dentry->d_inode; 661 struct inode *old_inode = d_inode(old_dentry);
662 struct inode *new_inode = new_dentry->d_inode; 662 struct inode *new_inode = d_inode(new_dentry);
663 int isdir = S_ISDIR(old_inode->i_mode); 663 int isdir = S_ISDIR(old_inode->i_mode);
664 struct logfs_disk_dentry dd; 664 struct logfs_disk_dentry dd;
665 struct logfs_transaction *ta; 665 struct logfs_transaction *ta;
@@ -719,7 +719,7 @@ out:
719static int logfs_rename(struct inode *old_dir, struct dentry *old_dentry, 719static int logfs_rename(struct inode *old_dir, struct dentry *old_dentry,
720 struct inode *new_dir, struct dentry *new_dentry) 720 struct inode *new_dir, struct dentry *new_dentry)
721{ 721{
722 if (new_dentry->d_inode) 722 if (d_really_is_positive(new_dentry))
723 return logfs_rename_target(old_dir, old_dentry, 723 return logfs_rename_target(old_dir, old_dentry,
724 new_dir, new_dentry); 724 new_dir, new_dentry);
725 return logfs_rename_cross(old_dir, old_dentry, new_dir, new_dentry); 725 return logfs_rename_cross(old_dir, old_dentry, new_dir, new_dentry);
diff --git a/fs/logfs/file.c b/fs/logfs/file.c
index b2c13f739ffa..1a6f0167b16a 100644
--- a/fs/logfs/file.c
+++ b/fs/logfs/file.c
@@ -241,7 +241,7 @@ int logfs_fsync(struct file *file, loff_t start, loff_t end, int datasync)
241 241
242static int logfs_setattr(struct dentry *dentry, struct iattr *attr) 242static int logfs_setattr(struct dentry *dentry, struct iattr *attr)
243{ 243{
244 struct inode *inode = dentry->d_inode; 244 struct inode *inode = d_inode(dentry);
245 int err = 0; 245 int err = 0;
246 246
247 err = inode_change_ok(inode, attr); 247 err = inode_change_ok(inode, attr);
diff --git a/fs/minix/dir.c b/fs/minix/dir.c
index dfaf6fa9b7b5..118e4e7bc935 100644
--- a/fs/minix/dir.c
+++ b/fs/minix/dir.c
@@ -156,7 +156,7 @@ minix_dirent *minix_find_entry(struct dentry *dentry, struct page **res_page)
156{ 156{
157 const char * name = dentry->d_name.name; 157 const char * name = dentry->d_name.name;
158 int namelen = dentry->d_name.len; 158 int namelen = dentry->d_name.len;
159 struct inode * dir = dentry->d_parent->d_inode; 159 struct inode * dir = d_inode(dentry->d_parent);
160 struct super_block * sb = dir->i_sb; 160 struct super_block * sb = dir->i_sb;
161 struct minix_sb_info * sbi = minix_sb(sb); 161 struct minix_sb_info * sbi = minix_sb(sb);
162 unsigned long n; 162 unsigned long n;
@@ -203,7 +203,7 @@ found:
203 203
204int minix_add_link(struct dentry *dentry, struct inode *inode) 204int minix_add_link(struct dentry *dentry, struct inode *inode)
205{ 205{
206 struct inode *dir = dentry->d_parent->d_inode; 206 struct inode *dir = d_inode(dentry->d_parent);
207 const char * name = dentry->d_name.name; 207 const char * name = dentry->d_name.name;
208 int namelen = dentry->d_name.len; 208 int namelen = dentry->d_name.len;
209 struct super_block * sb = dir->i_sb; 209 struct super_block * sb = dir->i_sb;
diff --git a/fs/minix/file.c b/fs/minix/file.c
index 6d63e27ec961..94f0eb9a6e2c 100644
--- a/fs/minix/file.c
+++ b/fs/minix/file.c
@@ -23,7 +23,7 @@ const struct file_operations minix_file_operations = {
23 23
24static int minix_setattr(struct dentry *dentry, struct iattr *attr) 24static int minix_setattr(struct dentry *dentry, struct iattr *attr)
25{ 25{
26 struct inode *inode = dentry->d_inode; 26 struct inode *inode = d_inode(dentry);
27 int error; 27 int error;
28 28
29 error = inode_change_ok(inode, attr); 29 error = inode_change_ok(inode, attr);
diff --git a/fs/minix/inode.c b/fs/minix/inode.c
index 3f57af196a7d..1182d1e26a9c 100644
--- a/fs/minix/inode.c
+++ b/fs/minix/inode.c
@@ -626,8 +626,8 @@ static int minix_write_inode(struct inode *inode, struct writeback_control *wbc)
626int minix_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat) 626int minix_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
627{ 627{
628 struct super_block *sb = dentry->d_sb; 628 struct super_block *sb = dentry->d_sb;
629 generic_fillattr(dentry->d_inode, stat); 629 generic_fillattr(d_inode(dentry), stat);
630 if (INODE_VERSION(dentry->d_inode) == MINIX_V1) 630 if (INODE_VERSION(d_inode(dentry)) == MINIX_V1)
631 stat->blocks = (BLOCK_SIZE / 512) * V1_minix_blocks(stat->size, sb); 631 stat->blocks = (BLOCK_SIZE / 512) * V1_minix_blocks(stat->size, sb);
632 else 632 else
633 stat->blocks = (sb->s_blocksize / 512) * V2_minix_blocks(stat->size, sb); 633 stat->blocks = (sb->s_blocksize / 512) * V2_minix_blocks(stat->size, sb);
diff --git a/fs/minix/namei.c b/fs/minix/namei.c
index cd950e2331b6..a795a11e50c7 100644
--- a/fs/minix/namei.c
+++ b/fs/minix/namei.c
@@ -104,7 +104,7 @@ out_fail:
104static int minix_link(struct dentry * old_dentry, struct inode * dir, 104static int minix_link(struct dentry * old_dentry, struct inode * dir,
105 struct dentry *dentry) 105 struct dentry *dentry)
106{ 106{
107 struct inode *inode = old_dentry->d_inode; 107 struct inode *inode = d_inode(old_dentry);
108 108
109 inode->i_ctime = CURRENT_TIME_SEC; 109 inode->i_ctime = CURRENT_TIME_SEC;
110 inode_inc_link_count(inode); 110 inode_inc_link_count(inode);
@@ -151,7 +151,7 @@ out_dir:
151static int minix_unlink(struct inode * dir, struct dentry *dentry) 151static int minix_unlink(struct inode * dir, struct dentry *dentry)
152{ 152{
153 int err = -ENOENT; 153 int err = -ENOENT;
154 struct inode * inode = dentry->d_inode; 154 struct inode * inode = d_inode(dentry);
155 struct page * page; 155 struct page * page;
156 struct minix_dir_entry * de; 156 struct minix_dir_entry * de;
157 157
@@ -171,7 +171,7 @@ end_unlink:
171 171
172static int minix_rmdir(struct inode * dir, struct dentry *dentry) 172static int minix_rmdir(struct inode * dir, struct dentry *dentry)
173{ 173{
174 struct inode * inode = dentry->d_inode; 174 struct inode * inode = d_inode(dentry);
175 int err = -ENOTEMPTY; 175 int err = -ENOTEMPTY;
176 176
177 if (minix_empty_dir(inode)) { 177 if (minix_empty_dir(inode)) {
@@ -187,8 +187,8 @@ static int minix_rmdir(struct inode * dir, struct dentry *dentry)
187static int minix_rename(struct inode * old_dir, struct dentry *old_dentry, 187static int minix_rename(struct inode * old_dir, struct dentry *old_dentry,
188 struct inode * new_dir, struct dentry *new_dentry) 188 struct inode * new_dir, struct dentry *new_dentry)
189{ 189{
190 struct inode * old_inode = old_dentry->d_inode; 190 struct inode * old_inode = d_inode(old_dentry);
191 struct inode * new_inode = new_dentry->d_inode; 191 struct inode * new_inode = d_inode(new_dentry);
192 struct page * dir_page = NULL; 192 struct page * dir_page = NULL;
193 struct minix_dir_entry * dir_de = NULL; 193 struct minix_dir_entry * dir_de = NULL;
194 struct page * old_page; 194 struct page * old_page;
diff --git a/fs/namei.c b/fs/namei.c
index ffab2e06e147..4a8d998b7274 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -1590,7 +1590,8 @@ static inline int walk_component(struct nameidata *nd, struct path *path,
1590 1590
1591 if (should_follow_link(path->dentry, follow)) { 1591 if (should_follow_link(path->dentry, follow)) {
1592 if (nd->flags & LOOKUP_RCU) { 1592 if (nd->flags & LOOKUP_RCU) {
1593 if (unlikely(unlazy_walk(nd, path->dentry))) { 1593 if (unlikely(nd->path.mnt != path->mnt ||
1594 unlazy_walk(nd, path->dentry))) {
1594 err = -ECHILD; 1595 err = -ECHILD;
1595 goto out_err; 1596 goto out_err;
1596 } 1597 }
@@ -3045,7 +3046,8 @@ finish_lookup:
3045 3046
3046 if (should_follow_link(path->dentry, !symlink_ok)) { 3047 if (should_follow_link(path->dentry, !symlink_ok)) {
3047 if (nd->flags & LOOKUP_RCU) { 3048 if (nd->flags & LOOKUP_RCU) {
3048 if (unlikely(unlazy_walk(nd, path->dentry))) { 3049 if (unlikely(nd->path.mnt != path->mnt ||
3050 unlazy_walk(nd, path->dentry))) {
3049 error = -ECHILD; 3051 error = -ECHILD;
3050 goto out; 3052 goto out;
3051 } 3053 }
diff --git a/fs/ncpfs/dir.c b/fs/ncpfs/dir.c
index e7ca827d7694..80021c709af9 100644
--- a/fs/ncpfs/dir.c
+++ b/fs/ncpfs/dir.c
@@ -127,7 +127,7 @@ static inline int ncp_case_sensitive(const struct inode *i)
127static int 127static int
128ncp_hash_dentry(const struct dentry *dentry, struct qstr *this) 128ncp_hash_dentry(const struct dentry *dentry, struct qstr *this)
129{ 129{
130 struct inode *inode = ACCESS_ONCE(dentry->d_inode); 130 struct inode *inode = d_inode_rcu(dentry);
131 131
132 if (!inode) 132 if (!inode)
133 return 0; 133 return 0;
@@ -162,7 +162,7 @@ ncp_compare_dentry(const struct dentry *parent, const struct dentry *dentry,
162 if (len != name->len) 162 if (len != name->len)
163 return 1; 163 return 1;
164 164
165 pinode = ACCESS_ONCE(parent->d_inode); 165 pinode = d_inode_rcu(parent);
166 if (!pinode) 166 if (!pinode)
167 return 1; 167 return 1;
168 168
@@ -180,7 +180,7 @@ ncp_compare_dentry(const struct dentry *parent, const struct dentry *dentry,
180static int 180static int
181ncp_delete_dentry(const struct dentry * dentry) 181ncp_delete_dentry(const struct dentry * dentry)
182{ 182{
183 struct inode *inode = dentry->d_inode; 183 struct inode *inode = d_inode(dentry);
184 184
185 if (inode) { 185 if (inode) {
186 if (is_bad_inode(inode)) 186 if (is_bad_inode(inode))
@@ -224,7 +224,7 @@ ncp_force_unlink(struct inode *dir, struct dentry* dentry)
224 memset(&info, 0, sizeof(info)); 224 memset(&info, 0, sizeof(info));
225 225
226 /* remove the Read-Only flag on the NW server */ 226 /* remove the Read-Only flag on the NW server */
227 inode = dentry->d_inode; 227 inode = d_inode(dentry);
228 228
229 old_nwattr = NCP_FINFO(inode)->nwattr; 229 old_nwattr = NCP_FINFO(inode)->nwattr;
230 info.attributes = old_nwattr & ~(aRONLY|aDELETEINHIBIT|aRENAMEINHIBIT); 230 info.attributes = old_nwattr & ~(aRONLY|aDELETEINHIBIT|aRENAMEINHIBIT);
@@ -254,7 +254,7 @@ ncp_force_rename(struct inode *old_dir, struct dentry* old_dentry, char *_old_na
254{ 254{
255 struct nw_modify_dos_info info; 255 struct nw_modify_dos_info info;
256 int res=0x90,res2; 256 int res=0x90,res2;
257 struct inode *old_inode = old_dentry->d_inode; 257 struct inode *old_inode = d_inode(old_dentry);
258 __le32 old_nwattr = NCP_FINFO(old_inode)->nwattr; 258 __le32 old_nwattr = NCP_FINFO(old_inode)->nwattr;
259 __le32 new_nwattr = 0; /* shut compiler warning */ 259 __le32 new_nwattr = 0; /* shut compiler warning */
260 int old_nwattr_changed = 0; 260 int old_nwattr_changed = 0;
@@ -268,8 +268,8 @@ ncp_force_rename(struct inode *old_dir, struct dentry* old_dentry, char *_old_na
268 res2 = ncp_modify_file_or_subdir_dos_info_path(NCP_SERVER(old_inode), old_inode, NULL, DM_ATTRIBUTES, &info); 268 res2 = ncp_modify_file_or_subdir_dos_info_path(NCP_SERVER(old_inode), old_inode, NULL, DM_ATTRIBUTES, &info);
269 if (!res2) 269 if (!res2)
270 old_nwattr_changed = 1; 270 old_nwattr_changed = 1;
271 if (new_dentry && new_dentry->d_inode) { 271 if (new_dentry && d_really_is_positive(new_dentry)) {
272 new_nwattr = NCP_FINFO(new_dentry->d_inode)->nwattr; 272 new_nwattr = NCP_FINFO(d_inode(new_dentry))->nwattr;
273 info.attributes = new_nwattr & ~(aRONLY|aRENAMEINHIBIT|aDELETEINHIBIT); 273 info.attributes = new_nwattr & ~(aRONLY|aRENAMEINHIBIT|aDELETEINHIBIT);
274 res2 = ncp_modify_file_or_subdir_dos_info_path(NCP_SERVER(new_dir), new_dir, _new_name, DM_ATTRIBUTES, &info); 274 res2 = ncp_modify_file_or_subdir_dos_info_path(NCP_SERVER(new_dir), new_dir, _new_name, DM_ATTRIBUTES, &info);
275 if (!res2) 275 if (!res2)
@@ -324,9 +324,9 @@ ncp_lookup_validate(struct dentry *dentry, unsigned int flags)
324 return -ECHILD; 324 return -ECHILD;
325 325
326 parent = dget_parent(dentry); 326 parent = dget_parent(dentry);
327 dir = parent->d_inode; 327 dir = d_inode(parent);
328 328
329 if (!dentry->d_inode) 329 if (d_really_is_negative(dentry))
330 goto finished; 330 goto finished;
331 331
332 server = NCP_SERVER(dir); 332 server = NCP_SERVER(dir);
@@ -367,7 +367,7 @@ ncp_lookup_validate(struct dentry *dentry, unsigned int flags)
367 * what we remember, it's not valid any more. 367 * what we remember, it's not valid any more.
368 */ 368 */
369 if (!res) { 369 if (!res) {
370 struct inode *inode = dentry->d_inode; 370 struct inode *inode = d_inode(dentry);
371 371
372 mutex_lock(&inode->i_mutex); 372 mutex_lock(&inode->i_mutex);
373 if (finfo.i.dirEntNum == NCP_FINFO(inode)->dirEntNum) { 373 if (finfo.i.dirEntNum == NCP_FINFO(inode)->dirEntNum) {
@@ -388,7 +388,7 @@ finished:
388 388
389static time_t ncp_obtain_mtime(struct dentry *dentry) 389static time_t ncp_obtain_mtime(struct dentry *dentry)
390{ 390{
391 struct inode *inode = dentry->d_inode; 391 struct inode *inode = d_inode(dentry);
392 struct ncp_server *server = NCP_SERVER(inode); 392 struct ncp_server *server = NCP_SERVER(inode);
393 struct nw_info_struct i; 393 struct nw_info_struct i;
394 394
@@ -404,7 +404,7 @@ static time_t ncp_obtain_mtime(struct dentry *dentry)
404static inline void 404static inline void
405ncp_invalidate_dircache_entries(struct dentry *parent) 405ncp_invalidate_dircache_entries(struct dentry *parent)
406{ 406{
407 struct ncp_server *server = NCP_SERVER(parent->d_inode); 407 struct ncp_server *server = NCP_SERVER(d_inode(parent));
408 struct dentry *dentry; 408 struct dentry *dentry;
409 409
410 spin_lock(&parent->d_lock); 410 spin_lock(&parent->d_lock);
@@ -418,7 +418,7 @@ ncp_invalidate_dircache_entries(struct dentry *parent)
418static int ncp_readdir(struct file *file, struct dir_context *ctx) 418static int ncp_readdir(struct file *file, struct dir_context *ctx)
419{ 419{
420 struct dentry *dentry = file->f_path.dentry; 420 struct dentry *dentry = file->f_path.dentry;
421 struct inode *inode = dentry->d_inode; 421 struct inode *inode = d_inode(dentry);
422 struct page *page = NULL; 422 struct page *page = NULL;
423 struct ncp_server *server = NCP_SERVER(inode); 423 struct ncp_server *server = NCP_SERVER(inode);
424 union ncp_dir_cache *cache = NULL; 424 union ncp_dir_cache *cache = NULL;
@@ -491,13 +491,13 @@ static int ncp_readdir(struct file *file, struct dir_context *ctx)
491 goto invalid_cache; 491 goto invalid_cache;
492 } 492 }
493 spin_unlock(&dentry->d_lock); 493 spin_unlock(&dentry->d_lock);
494 if (!dent->d_inode) { 494 if (d_really_is_negative(dent)) {
495 dput(dent); 495 dput(dent);
496 goto invalid_cache; 496 goto invalid_cache;
497 } 497 }
498 over = !dir_emit(ctx, dent->d_name.name, 498 over = !dir_emit(ctx, dent->d_name.name,
499 dent->d_name.len, 499 dent->d_name.len,
500 dent->d_inode->i_ino, DT_UNKNOWN); 500 d_inode(dent)->i_ino, DT_UNKNOWN);
501 dput(dent); 501 dput(dent);
502 if (over) 502 if (over)
503 goto finished; 503 goto finished;
@@ -571,7 +571,7 @@ static void ncp_d_prune(struct dentry *dentry)
571{ 571{
572 if (!dentry->d_fsdata) /* not referenced from page cache */ 572 if (!dentry->d_fsdata) /* not referenced from page cache */
573 return; 573 return;
574 NCP_FINFO(dentry->d_parent->d_inode)->flags &= ~NCPI_DIR_CACHE; 574 NCP_FINFO(d_inode(dentry->d_parent))->flags &= ~NCPI_DIR_CACHE;
575} 575}
576 576
577static int 577static int
@@ -580,7 +580,7 @@ ncp_fill_cache(struct file *file, struct dir_context *ctx,
580 int inval_childs) 580 int inval_childs)
581{ 581{
582 struct dentry *newdent, *dentry = file->f_path.dentry; 582 struct dentry *newdent, *dentry = file->f_path.dentry;
583 struct inode *dir = dentry->d_inode; 583 struct inode *dir = d_inode(dentry);
584 struct ncp_cache_control ctl = *ctrl; 584 struct ncp_cache_control ctl = *ctrl;
585 struct qstr qname; 585 struct qstr qname;
586 int valid = 0; 586 int valid = 0;
@@ -621,7 +621,7 @@ ncp_fill_cache(struct file *file, struct dir_context *ctx,
621 dentry_update_name_case(newdent, &qname); 621 dentry_update_name_case(newdent, &qname);
622 } 622 }
623 623
624 if (!newdent->d_inode) { 624 if (d_really_is_negative(newdent)) {
625 struct inode *inode; 625 struct inode *inode;
626 626
627 entry->opened = 0; 627 entry->opened = 0;
@@ -637,7 +637,7 @@ ncp_fill_cache(struct file *file, struct dir_context *ctx,
637 spin_unlock(&dentry->d_lock); 637 spin_unlock(&dentry->d_lock);
638 } 638 }
639 } else { 639 } else {
640 struct inode *inode = newdent->d_inode; 640 struct inode *inode = d_inode(newdent);
641 641
642 mutex_lock_nested(&inode->i_mutex, I_MUTEX_CHILD); 642 mutex_lock_nested(&inode->i_mutex, I_MUTEX_CHILD);
643 ncp_update_inode2(inode, entry); 643 ncp_update_inode2(inode, entry);
@@ -659,10 +659,10 @@ ncp_fill_cache(struct file *file, struct dir_context *ctx,
659 ctl.cache = kmap(ctl.page); 659 ctl.cache = kmap(ctl.page);
660 } 660 }
661 if (ctl.cache) { 661 if (ctl.cache) {
662 if (newdent->d_inode) { 662 if (d_really_is_positive(newdent)) {
663 newdent->d_fsdata = newdent; 663 newdent->d_fsdata = newdent;
664 ctl.cache->dentry[ctl.idx] = newdent; 664 ctl.cache->dentry[ctl.idx] = newdent;
665 ino = newdent->d_inode->i_ino; 665 ino = d_inode(newdent)->i_ino;
666 ncp_new_dentry(newdent); 666 ncp_new_dentry(newdent);
667 } 667 }
668 valid = 1; 668 valid = 1;
@@ -807,7 +807,7 @@ int ncp_conn_logged_in(struct super_block *sb)
807 } 807 }
808 dent = sb->s_root; 808 dent = sb->s_root;
809 if (dent) { 809 if (dent) {
810 struct inode* ino = dent->d_inode; 810 struct inode* ino = d_inode(dent);
811 if (ino) { 811 if (ino) {
812 ncp_update_known_namespace(server, volNumber, NULL); 812 ncp_update_known_namespace(server, volNumber, NULL);
813 NCP_FINFO(ino)->volNumber = volNumber; 813 NCP_FINFO(ino)->volNumber = volNumber;
@@ -815,7 +815,7 @@ int ncp_conn_logged_in(struct super_block *sb)
815 NCP_FINFO(ino)->DosDirNum = DosDirNum; 815 NCP_FINFO(ino)->DosDirNum = DosDirNum;
816 result = 0; 816 result = 0;
817 } else { 817 } else {
818 ncp_dbg(1, "sb->s_root->d_inode == NULL!\n"); 818 ncp_dbg(1, "d_inode(sb->s_root) == NULL!\n");
819 } 819 }
820 } else { 820 } else {
821 ncp_dbg(1, "sb->s_root == NULL!\n"); 821 ncp_dbg(1, "sb->s_root == NULL!\n");
@@ -1055,7 +1055,7 @@ out:
1055 1055
1056static int ncp_unlink(struct inode *dir, struct dentry *dentry) 1056static int ncp_unlink(struct inode *dir, struct dentry *dentry)
1057{ 1057{
1058 struct inode *inode = dentry->d_inode; 1058 struct inode *inode = d_inode(dentry);
1059 struct ncp_server *server; 1059 struct ncp_server *server;
1060 int error; 1060 int error;
1061 1061
diff --git a/fs/ncpfs/inode.c b/fs/ncpfs/inode.c
index 01a9e16e9782..9605a2f63549 100644
--- a/fs/ncpfs/inode.c
+++ b/fs/ncpfs/inode.c
@@ -812,7 +812,7 @@ static int ncp_statfs(struct dentry *dentry, struct kstatfs *buf)
812 if (!d) { 812 if (!d) {
813 goto dflt; 813 goto dflt;
814 } 814 }
815 i = d->d_inode; 815 i = d_inode(d);
816 if (!i) { 816 if (!i) {
817 goto dflt; 817 goto dflt;
818 } 818 }
@@ -865,7 +865,7 @@ dflt:;
865 865
866int ncp_notify_change(struct dentry *dentry, struct iattr *attr) 866int ncp_notify_change(struct dentry *dentry, struct iattr *attr)
867{ 867{
868 struct inode *inode = dentry->d_inode; 868 struct inode *inode = d_inode(dentry);
869 int result = 0; 869 int result = 0;
870 __le32 info_mask; 870 __le32 info_mask;
871 struct nw_modify_dos_info info; 871 struct nw_modify_dos_info info;
@@ -878,7 +878,7 @@ int ncp_notify_change(struct dentry *dentry, struct iattr *attr)
878 goto out; 878 goto out;
879 879
880 result = -EPERM; 880 result = -EPERM;
881 if (IS_DEADDIR(dentry->d_inode)) 881 if (IS_DEADDIR(d_inode(dentry)))
882 goto out; 882 goto out;
883 883
884 /* ageing the dentry to force validation */ 884 /* ageing the dentry to force validation */
diff --git a/fs/ncpfs/ioctl.c b/fs/ncpfs/ioctl.c
index cf7e043a9447..79b113048eac 100644
--- a/fs/ncpfs/ioctl.c
+++ b/fs/ncpfs/ioctl.c
@@ -376,7 +376,7 @@ static long __ncp_ioctl(struct inode *inode, unsigned int cmd, unsigned long arg
376 struct dentry* dentry = inode->i_sb->s_root; 376 struct dentry* dentry = inode->i_sb->s_root;
377 377
378 if (dentry) { 378 if (dentry) {
379 struct inode* s_inode = dentry->d_inode; 379 struct inode* s_inode = d_inode(dentry);
380 380
381 if (s_inode) { 381 if (s_inode) {
382 sr.volNumber = NCP_FINFO(s_inode)->volNumber; 382 sr.volNumber = NCP_FINFO(s_inode)->volNumber;
@@ -384,7 +384,7 @@ static long __ncp_ioctl(struct inode *inode, unsigned int cmd, unsigned long arg
384 sr.namespace = server->name_space[sr.volNumber]; 384 sr.namespace = server->name_space[sr.volNumber];
385 result = 0; 385 result = 0;
386 } else 386 } else
387 ncp_dbg(1, "s_root->d_inode==NULL\n"); 387 ncp_dbg(1, "d_inode(s_root)==NULL\n");
388 } else 388 } else
389 ncp_dbg(1, "s_root==NULL\n"); 389 ncp_dbg(1, "s_root==NULL\n");
390 } else { 390 } else {
@@ -431,7 +431,7 @@ static long __ncp_ioctl(struct inode *inode, unsigned int cmd, unsigned long arg
431 if (result == 0) { 431 if (result == 0) {
432 dentry = inode->i_sb->s_root; 432 dentry = inode->i_sb->s_root;
433 if (dentry) { 433 if (dentry) {
434 struct inode* s_inode = dentry->d_inode; 434 struct inode* s_inode = d_inode(dentry);
435 435
436 if (s_inode) { 436 if (s_inode) {
437 NCP_FINFO(s_inode)->volNumber = vnum; 437 NCP_FINFO(s_inode)->volNumber = vnum;
@@ -439,7 +439,7 @@ static long __ncp_ioctl(struct inode *inode, unsigned int cmd, unsigned long arg
439 NCP_FINFO(s_inode)->DosDirNum = dosde; 439 NCP_FINFO(s_inode)->DosDirNum = dosde;
440 server->root_setuped = 1; 440 server->root_setuped = 1;
441 } else { 441 } else {
442 ncp_dbg(1, "s_root->d_inode==NULL\n"); 442 ncp_dbg(1, "d_inode(s_root)==NULL\n");
443 result = -EIO; 443 result = -EIO;
444 } 444 }
445 } else { 445 } else {
diff --git a/fs/ncpfs/ncplib_kernel.c b/fs/ncpfs/ncplib_kernel.c
index 2b502a0d7941..88dbbc9fcf4d 100644
--- a/fs/ncpfs/ncplib_kernel.c
+++ b/fs/ncpfs/ncplib_kernel.c
@@ -727,7 +727,7 @@ int
727ncp_del_file_or_subdir2(struct ncp_server *server, 727ncp_del_file_or_subdir2(struct ncp_server *server,
728 struct dentry *dentry) 728 struct dentry *dentry)
729{ 729{
730 struct inode *inode = dentry->d_inode; 730 struct inode *inode = d_inode(dentry);
731 __u8 volnum; 731 __u8 volnum;
732 __le32 dirent; 732 __le32 dirent;
733 733
diff --git a/fs/ncpfs/symlink.c b/fs/ncpfs/symlink.c
index 1a63bfdb4a65..421b6f91e8ec 100644
--- a/fs/ncpfs/symlink.c
+++ b/fs/ncpfs/symlink.c
@@ -156,7 +156,7 @@ int ncp_symlink(struct inode *dir, struct dentry *dentry, const char *symname) {
156 goto failfree; 156 goto failfree;
157 } 157 }
158 158
159 inode=dentry->d_inode; 159 inode=d_inode(dentry);
160 160
161 if (ncp_make_open(inode, O_WRONLY)) 161 if (ncp_make_open(inode, O_WRONLY))
162 goto failfree; 162 goto failfree;
diff --git a/fs/nfs/Makefile b/fs/nfs/Makefile
index 1e987acf20c9..8664417955a2 100644
--- a/fs/nfs/Makefile
+++ b/fs/nfs/Makefile
@@ -22,7 +22,7 @@ nfsv3-$(CONFIG_NFS_V3_ACL) += nfs3acl.o
22obj-$(CONFIG_NFS_V4) += nfsv4.o 22obj-$(CONFIG_NFS_V4) += nfsv4.o
23CFLAGS_nfs4trace.o += -I$(src) 23CFLAGS_nfs4trace.o += -I$(src)
24nfsv4-y := nfs4proc.o nfs4xdr.o nfs4state.o nfs4renewd.o nfs4super.o nfs4file.o \ 24nfsv4-y := nfs4proc.o nfs4xdr.o nfs4state.o nfs4renewd.o nfs4super.o nfs4file.o \
25 delegation.o idmap.o callback.o callback_xdr.o callback_proc.o \ 25 delegation.o nfs4idmap.o callback.o callback_xdr.o callback_proc.o \
26 nfs4namespace.o nfs4getroot.o nfs4client.o nfs4session.o \ 26 nfs4namespace.o nfs4getroot.o nfs4client.o nfs4session.o \
27 dns_resolve.o nfs4trace.o 27 dns_resolve.o nfs4trace.o
28nfsv4-$(CONFIG_NFS_USE_LEGACY_DNS) += cache_lib.o 28nfsv4-$(CONFIG_NFS_USE_LEGACY_DNS) += cache_lib.o
diff --git a/fs/nfs/blocklayout/blocklayout.c b/fs/nfs/blocklayout/blocklayout.c
index 1cac3c175d18..d2554fe140a3 100644
--- a/fs/nfs/blocklayout/blocklayout.c
+++ b/fs/nfs/blocklayout/blocklayout.c
@@ -890,6 +890,7 @@ static struct pnfs_layoutdriver_type blocklayout_type = {
890 .free_deviceid_node = bl_free_deviceid_node, 890 .free_deviceid_node = bl_free_deviceid_node,
891 .pg_read_ops = &bl_pg_read_ops, 891 .pg_read_ops = &bl_pg_read_ops,
892 .pg_write_ops = &bl_pg_write_ops, 892 .pg_write_ops = &bl_pg_write_ops,
893 .sync = pnfs_generic_sync,
893}; 894};
894 895
895static int __init nfs4blocklayout_init(void) 896static int __init nfs4blocklayout_init(void)
diff --git a/fs/nfs/blocklayout/dev.c b/fs/nfs/blocklayout/dev.c
index 5aed4f98df41..e535599a0719 100644
--- a/fs/nfs/blocklayout/dev.c
+++ b/fs/nfs/blocklayout/dev.c
@@ -33,7 +33,7 @@ bl_free_deviceid_node(struct nfs4_deviceid_node *d)
33 container_of(d, struct pnfs_block_dev, node); 33 container_of(d, struct pnfs_block_dev, node);
34 34
35 bl_free_device(dev); 35 bl_free_device(dev);
36 kfree(dev); 36 kfree_rcu(dev, node.rcu);
37} 37}
38 38
39static int 39static int
diff --git a/fs/nfs/callback.c b/fs/nfs/callback.c
index 351be9205bf8..8d129bb7355a 100644
--- a/fs/nfs/callback.c
+++ b/fs/nfs/callback.c
@@ -128,7 +128,7 @@ nfs41_callback_svc(void *vrqstp)
128 if (try_to_freeze()) 128 if (try_to_freeze())
129 continue; 129 continue;
130 130
131 prepare_to_wait(&serv->sv_cb_waitq, &wq, TASK_UNINTERRUPTIBLE); 131 prepare_to_wait(&serv->sv_cb_waitq, &wq, TASK_INTERRUPTIBLE);
132 spin_lock_bh(&serv->sv_cb_lock); 132 spin_lock_bh(&serv->sv_cb_lock);
133 if (!list_empty(&serv->sv_cb_list)) { 133 if (!list_empty(&serv->sv_cb_list)) {
134 req = list_first_entry(&serv->sv_cb_list, 134 req = list_first_entry(&serv->sv_cb_list,
@@ -142,10 +142,10 @@ nfs41_callback_svc(void *vrqstp)
142 error); 142 error);
143 } else { 143 } else {
144 spin_unlock_bh(&serv->sv_cb_lock); 144 spin_unlock_bh(&serv->sv_cb_lock);
145 /* schedule_timeout to game the hung task watchdog */ 145 schedule();
146 schedule_timeout(60 * HZ);
147 finish_wait(&serv->sv_cb_waitq, &wq); 146 finish_wait(&serv->sv_cb_waitq, &wq);
148 } 147 }
148 flush_signals(current);
149 } 149 }
150 return 0; 150 return 0;
151} 151}
diff --git a/fs/nfs/client.c b/fs/nfs/client.c
index 19874151e95c..892aefff3630 100644
--- a/fs/nfs/client.c
+++ b/fs/nfs/client.c
@@ -31,7 +31,6 @@
31#include <linux/lockd/bind.h> 31#include <linux/lockd/bind.h>
32#include <linux/seq_file.h> 32#include <linux/seq_file.h>
33#include <linux/mount.h> 33#include <linux/mount.h>
34#include <linux/nfs_idmap.h>
35#include <linux/vfs.h> 34#include <linux/vfs.h>
36#include <linux/inet.h> 35#include <linux/inet.h>
37#include <linux/in6.h> 36#include <linux/in6.h>
diff --git a/fs/nfs/delegation.c b/fs/nfs/delegation.c
index a6ad68865880..029d688a969f 100644
--- a/fs/nfs/delegation.c
+++ b/fs/nfs/delegation.c
@@ -378,7 +378,7 @@ int nfs_inode_set_delegation(struct inode *inode, struct rpc_cred *cred, struct
378 if (freeme == NULL) 378 if (freeme == NULL)
379 goto out; 379 goto out;
380 } 380 }
381 list_add_rcu(&delegation->super_list, &server->delegations); 381 list_add_tail_rcu(&delegation->super_list, &server->delegations);
382 rcu_assign_pointer(nfsi->delegation, delegation); 382 rcu_assign_pointer(nfsi->delegation, delegation);
383 delegation = NULL; 383 delegation = NULL;
384 384
@@ -514,7 +514,7 @@ void nfs_inode_return_delegation_noreclaim(struct inode *inode)
514 514
515 delegation = nfs_inode_detach_delegation(inode); 515 delegation = nfs_inode_detach_delegation(inode);
516 if (delegation != NULL) 516 if (delegation != NULL)
517 nfs_do_return_delegation(inode, delegation, 0); 517 nfs_do_return_delegation(inode, delegation, 1);
518} 518}
519 519
520/** 520/**
diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c
index c19e16f0b2d0..b2c8b31b2be7 100644
--- a/fs/nfs/dir.c
+++ b/fs/nfs/dir.c
@@ -416,15 +416,14 @@ int nfs_same_file(struct dentry *dentry, struct nfs_entry *entry)
416{ 416{
417 struct nfs_inode *nfsi; 417 struct nfs_inode *nfsi;
418 418
419 if (dentry->d_inode == NULL) 419 if (d_really_is_negative(dentry))
420 goto different; 420 return 0;
421 421
422 nfsi = NFS_I(dentry->d_inode); 422 nfsi = NFS_I(d_inode(dentry));
423 if (entry->fattr->fileid == nfsi->fileid) 423 if (entry->fattr->fileid == nfsi->fileid)
424 return 1; 424 return 1;
425 if (nfs_compare_fh(entry->fh, &nfsi->fh) == 0) 425 if (nfs_compare_fh(entry->fh, &nfsi->fh) == 0)
426 return 1; 426 return 1;
427different:
428 return 0; 427 return 0;
429} 428}
430 429
@@ -473,7 +472,7 @@ void nfs_prime_dcache(struct dentry *parent, struct nfs_entry *entry)
473 struct qstr filename = QSTR_INIT(entry->name, entry->len); 472 struct qstr filename = QSTR_INIT(entry->name, entry->len);
474 struct dentry *dentry; 473 struct dentry *dentry;
475 struct dentry *alias; 474 struct dentry *alias;
476 struct inode *dir = parent->d_inode; 475 struct inode *dir = d_inode(parent);
477 struct inode *inode; 476 struct inode *inode;
478 int status; 477 int status;
479 478
@@ -497,9 +496,9 @@ void nfs_prime_dcache(struct dentry *parent, struct nfs_entry *entry)
497 goto out; 496 goto out;
498 if (nfs_same_file(dentry, entry)) { 497 if (nfs_same_file(dentry, entry)) {
499 nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); 498 nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
500 status = nfs_refresh_inode(dentry->d_inode, entry->fattr); 499 status = nfs_refresh_inode(d_inode(dentry), entry->fattr);
501 if (!status) 500 if (!status)
502 nfs_setsecurity(dentry->d_inode, entry->fattr, entry->label); 501 nfs_setsecurity(d_inode(dentry), entry->fattr, entry->label);
503 goto out; 502 goto out;
504 } else { 503 } else {
505 d_invalidate(dentry); 504 d_invalidate(dentry);
@@ -544,6 +543,9 @@ int nfs_readdir_page_filler(nfs_readdir_descriptor_t *desc, struct nfs_entry *en
544 if (scratch == NULL) 543 if (scratch == NULL)
545 return -ENOMEM; 544 return -ENOMEM;
546 545
546 if (buflen == 0)
547 goto out_nopages;
548
547 xdr_init_decode_pages(&stream, &buf, xdr_pages, buflen); 549 xdr_init_decode_pages(&stream, &buf, xdr_pages, buflen);
548 xdr_set_scratch_buffer(&stream, page_address(scratch), PAGE_SIZE); 550 xdr_set_scratch_buffer(&stream, page_address(scratch), PAGE_SIZE);
549 551
@@ -565,6 +567,7 @@ int nfs_readdir_page_filler(nfs_readdir_descriptor_t *desc, struct nfs_entry *en
565 break; 567 break;
566 } while (!entry->eof); 568 } while (!entry->eof);
567 569
570out_nopages:
568 if (count == 0 || (status == -EBADCOOKIE && entry->eof != 0)) { 571 if (count == 0 || (status == -EBADCOOKIE && entry->eof != 0)) {
569 array = nfs_readdir_get_array(page); 572 array = nfs_readdir_get_array(page);
570 if (!IS_ERR(array)) { 573 if (!IS_ERR(array)) {
@@ -870,7 +873,7 @@ static bool nfs_dir_mapping_need_revalidate(struct inode *dir)
870static int nfs_readdir(struct file *file, struct dir_context *ctx) 873static int nfs_readdir(struct file *file, struct dir_context *ctx)
871{ 874{
872 struct dentry *dentry = file->f_path.dentry; 875 struct dentry *dentry = file->f_path.dentry;
873 struct inode *inode = dentry->d_inode; 876 struct inode *inode = d_inode(dentry);
874 nfs_readdir_descriptor_t my_desc, 877 nfs_readdir_descriptor_t my_desc,
875 *desc = &my_desc; 878 *desc = &my_desc;
876 struct nfs_open_dir_context *dir_ctx = file->private_data; 879 struct nfs_open_dir_context *dir_ctx = file->private_data;
@@ -1118,15 +1121,15 @@ static int nfs_lookup_revalidate(struct dentry *dentry, unsigned int flags)
1118 1121
1119 if (flags & LOOKUP_RCU) { 1122 if (flags & LOOKUP_RCU) {
1120 parent = ACCESS_ONCE(dentry->d_parent); 1123 parent = ACCESS_ONCE(dentry->d_parent);
1121 dir = ACCESS_ONCE(parent->d_inode); 1124 dir = d_inode_rcu(parent);
1122 if (!dir) 1125 if (!dir)
1123 return -ECHILD; 1126 return -ECHILD;
1124 } else { 1127 } else {
1125 parent = dget_parent(dentry); 1128 parent = dget_parent(dentry);
1126 dir = parent->d_inode; 1129 dir = d_inode(parent);
1127 } 1130 }
1128 nfs_inc_stats(dir, NFSIOS_DENTRYREVALIDATE); 1131 nfs_inc_stats(dir, NFSIOS_DENTRYREVALIDATE);
1129 inode = dentry->d_inode; 1132 inode = d_inode(dentry);
1130 1133
1131 if (!inode) { 1134 if (!inode) {
1132 if (nfs_neg_need_reval(dir, dentry, flags)) { 1135 if (nfs_neg_need_reval(dir, dentry, flags)) {
@@ -1242,7 +1245,7 @@ out_error:
1242} 1245}
1243 1246
1244/* 1247/*
1245 * A weaker form of d_revalidate for revalidating just the dentry->d_inode 1248 * A weaker form of d_revalidate for revalidating just the d_inode(dentry)
1246 * when we don't really care about the dentry name. This is called when a 1249 * when we don't really care about the dentry name. This is called when a
1247 * pathwalk ends on a dentry that was not found via a normal lookup in the 1250 * pathwalk ends on a dentry that was not found via a normal lookup in the
1248 * parent dir (e.g.: ".", "..", procfs symlinks or mountpoint traversals). 1251 * parent dir (e.g.: ".", "..", procfs symlinks or mountpoint traversals).
@@ -1253,7 +1256,7 @@ out_error:
1253static int nfs_weak_revalidate(struct dentry *dentry, unsigned int flags) 1256static int nfs_weak_revalidate(struct dentry *dentry, unsigned int flags)
1254{ 1257{
1255 int error; 1258 int error;
1256 struct inode *inode = dentry->d_inode; 1259 struct inode *inode = d_inode(dentry);
1257 1260
1258 /* 1261 /*
1259 * I believe we can only get a negative dentry here in the case of a 1262 * I believe we can only get a negative dentry here in the case of a
@@ -1287,7 +1290,7 @@ static int nfs_dentry_delete(const struct dentry *dentry)
1287 dentry, dentry->d_flags); 1290 dentry, dentry->d_flags);
1288 1291
1289 /* Unhash any dentry with a stale inode */ 1292 /* Unhash any dentry with a stale inode */
1290 if (dentry->d_inode != NULL && NFS_STALE(dentry->d_inode)) 1293 if (d_really_is_positive(dentry) && NFS_STALE(d_inode(dentry)))
1291 return 1; 1294 return 1;
1292 1295
1293 if (dentry->d_flags & DCACHE_NFSFS_RENAMED) { 1296 if (dentry->d_flags & DCACHE_NFSFS_RENAMED) {
@@ -1491,7 +1494,7 @@ int nfs_atomic_open(struct inode *dir, struct dentry *dentry,
1491 int err; 1494 int err;
1492 1495
1493 /* Expect a negative dentry */ 1496 /* Expect a negative dentry */
1494 BUG_ON(dentry->d_inode); 1497 BUG_ON(d_inode(dentry));
1495 1498
1496 dfprintk(VFS, "NFS: atomic_open(%s/%lu), %pd\n", 1499 dfprintk(VFS, "NFS: atomic_open(%s/%lu), %pd\n",
1497 dir->i_sb->s_id, dir->i_ino, dentry); 1500 dir->i_sb->s_id, dir->i_ino, dentry);
@@ -1587,7 +1590,7 @@ static int nfs4_lookup_revalidate(struct dentry *dentry, unsigned int flags)
1587 if (NFS_SB(dentry->d_sb)->caps & NFS_CAP_ATOMIC_OPEN_V1) 1590 if (NFS_SB(dentry->d_sb)->caps & NFS_CAP_ATOMIC_OPEN_V1)
1588 goto no_open; 1591 goto no_open;
1589 1592
1590 inode = dentry->d_inode; 1593 inode = d_inode(dentry);
1591 1594
1592 /* We can't create new files in nfs_open_revalidate(), so we 1595 /* We can't create new files in nfs_open_revalidate(), so we
1593 * optimize away revalidation of negative dentries. 1596 * optimize away revalidation of negative dentries.
@@ -1598,12 +1601,12 @@ static int nfs4_lookup_revalidate(struct dentry *dentry, unsigned int flags)
1598 1601
1599 if (flags & LOOKUP_RCU) { 1602 if (flags & LOOKUP_RCU) {
1600 parent = ACCESS_ONCE(dentry->d_parent); 1603 parent = ACCESS_ONCE(dentry->d_parent);
1601 dir = ACCESS_ONCE(parent->d_inode); 1604 dir = d_inode_rcu(parent);
1602 if (!dir) 1605 if (!dir)
1603 return -ECHILD; 1606 return -ECHILD;
1604 } else { 1607 } else {
1605 parent = dget_parent(dentry); 1608 parent = dget_parent(dentry);
1606 dir = parent->d_inode; 1609 dir = d_inode(parent);
1607 } 1610 }
1608 if (!nfs_neg_need_reval(dir, dentry, flags)) 1611 if (!nfs_neg_need_reval(dir, dentry, flags))
1609 ret = 1; 1612 ret = 1;
@@ -1643,14 +1646,14 @@ int nfs_instantiate(struct dentry *dentry, struct nfs_fh *fhandle,
1643 struct nfs4_label *label) 1646 struct nfs4_label *label)
1644{ 1647{
1645 struct dentry *parent = dget_parent(dentry); 1648 struct dentry *parent = dget_parent(dentry);
1646 struct inode *dir = parent->d_inode; 1649 struct inode *dir = d_inode(parent);
1647 struct inode *inode; 1650 struct inode *inode;
1648 int error = -EACCES; 1651 int error = -EACCES;
1649 1652
1650 d_drop(dentry); 1653 d_drop(dentry);
1651 1654
1652 /* We may have been initialized further down */ 1655 /* We may have been initialized further down */
1653 if (dentry->d_inode) 1656 if (d_really_is_positive(dentry))
1654 goto out; 1657 goto out;
1655 if (fhandle->size == 0) { 1658 if (fhandle->size == 0) {
1656 error = NFS_PROTO(dir)->lookup(dir, &dentry->d_name, fhandle, fattr, NULL); 1659 error = NFS_PROTO(dir)->lookup(dir, &dentry->d_name, fhandle, fattr, NULL);
@@ -1768,7 +1771,7 @@ EXPORT_SYMBOL_GPL(nfs_mkdir);
1768 1771
1769static void nfs_dentry_handle_enoent(struct dentry *dentry) 1772static void nfs_dentry_handle_enoent(struct dentry *dentry)
1770{ 1773{
1771 if (dentry->d_inode != NULL && !d_unhashed(dentry)) 1774 if (d_really_is_positive(dentry) && !d_unhashed(dentry))
1772 d_delete(dentry); 1775 d_delete(dentry);
1773} 1776}
1774 1777
@@ -1780,13 +1783,13 @@ int nfs_rmdir(struct inode *dir, struct dentry *dentry)
1780 dir->i_sb->s_id, dir->i_ino, dentry); 1783 dir->i_sb->s_id, dir->i_ino, dentry);
1781 1784
1782 trace_nfs_rmdir_enter(dir, dentry); 1785 trace_nfs_rmdir_enter(dir, dentry);
1783 if (dentry->d_inode) { 1786 if (d_really_is_positive(dentry)) {
1784 nfs_wait_on_sillyrename(dentry); 1787 nfs_wait_on_sillyrename(dentry);
1785 error = NFS_PROTO(dir)->rmdir(dir, &dentry->d_name); 1788 error = NFS_PROTO(dir)->rmdir(dir, &dentry->d_name);
1786 /* Ensure the VFS deletes this inode */ 1789 /* Ensure the VFS deletes this inode */
1787 switch (error) { 1790 switch (error) {
1788 case 0: 1791 case 0:
1789 clear_nlink(dentry->d_inode); 1792 clear_nlink(d_inode(dentry));
1790 break; 1793 break;
1791 case -ENOENT: 1794 case -ENOENT:
1792 nfs_dentry_handle_enoent(dentry); 1795 nfs_dentry_handle_enoent(dentry);
@@ -1808,8 +1811,8 @@ EXPORT_SYMBOL_GPL(nfs_rmdir);
1808 */ 1811 */
1809static int nfs_safe_remove(struct dentry *dentry) 1812static int nfs_safe_remove(struct dentry *dentry)
1810{ 1813{
1811 struct inode *dir = dentry->d_parent->d_inode; 1814 struct inode *dir = d_inode(dentry->d_parent);
1812 struct inode *inode = dentry->d_inode; 1815 struct inode *inode = d_inode(dentry);
1813 int error = -EBUSY; 1816 int error = -EBUSY;
1814 1817
1815 dfprintk(VFS, "NFS: safe_remove(%pd2)\n", dentry); 1818 dfprintk(VFS, "NFS: safe_remove(%pd2)\n", dentry);
@@ -1853,7 +1856,7 @@ int nfs_unlink(struct inode *dir, struct dentry *dentry)
1853 if (d_count(dentry) > 1) { 1856 if (d_count(dentry) > 1) {
1854 spin_unlock(&dentry->d_lock); 1857 spin_unlock(&dentry->d_lock);
1855 /* Start asynchronous writeout of the inode */ 1858 /* Start asynchronous writeout of the inode */
1856 write_inode_now(dentry->d_inode, 0); 1859 write_inode_now(d_inode(dentry), 0);
1857 error = nfs_sillyrename(dir, dentry); 1860 error = nfs_sillyrename(dir, dentry);
1858 goto out; 1861 goto out;
1859 } 1862 }
@@ -1931,7 +1934,7 @@ int nfs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
1931 * No big deal if we can't add this page to the page cache here. 1934 * No big deal if we can't add this page to the page cache here.
1932 * READLINK will get the missing page from the server if needed. 1935 * READLINK will get the missing page from the server if needed.
1933 */ 1936 */
1934 if (!add_to_page_cache_lru(page, dentry->d_inode->i_mapping, 0, 1937 if (!add_to_page_cache_lru(page, d_inode(dentry)->i_mapping, 0,
1935 GFP_KERNEL)) { 1938 GFP_KERNEL)) {
1936 SetPageUptodate(page); 1939 SetPageUptodate(page);
1937 unlock_page(page); 1940 unlock_page(page);
@@ -1950,7 +1953,7 @@ EXPORT_SYMBOL_GPL(nfs_symlink);
1950int 1953int
1951nfs_link(struct dentry *old_dentry, struct inode *dir, struct dentry *dentry) 1954nfs_link(struct dentry *old_dentry, struct inode *dir, struct dentry *dentry)
1952{ 1955{
1953 struct inode *inode = old_dentry->d_inode; 1956 struct inode *inode = d_inode(old_dentry);
1954 int error; 1957 int error;
1955 1958
1956 dfprintk(VFS, "NFS: link(%pd2 -> %pd2)\n", 1959 dfprintk(VFS, "NFS: link(%pd2 -> %pd2)\n",
@@ -1997,8 +2000,8 @@ EXPORT_SYMBOL_GPL(nfs_link);
1997int nfs_rename(struct inode *old_dir, struct dentry *old_dentry, 2000int nfs_rename(struct inode *old_dir, struct dentry *old_dentry,
1998 struct inode *new_dir, struct dentry *new_dentry) 2001 struct inode *new_dir, struct dentry *new_dentry)
1999{ 2002{
2000 struct inode *old_inode = old_dentry->d_inode; 2003 struct inode *old_inode = d_inode(old_dentry);
2001 struct inode *new_inode = new_dentry->d_inode; 2004 struct inode *new_inode = d_inode(new_dentry);
2002 struct dentry *dentry = NULL, *rehash = NULL; 2005 struct dentry *dentry = NULL, *rehash = NULL;
2003 struct rpc_task *task; 2006 struct rpc_task *task;
2004 int error = -EBUSY; 2007 int error = -EBUSY;
diff --git a/fs/nfs/direct.c b/fs/nfs/direct.c
index 682f65fe09b5..38678d9a5cc4 100644
--- a/fs/nfs/direct.c
+++ b/fs/nfs/direct.c
@@ -129,22 +129,25 @@ nfs_direct_good_bytes(struct nfs_direct_req *dreq, struct nfs_pgio_header *hdr)
129 int i; 129 int i;
130 ssize_t count; 130 ssize_t count;
131 131
132 WARN_ON_ONCE(hdr->pgio_mirror_idx >= dreq->mirror_count); 132 if (dreq->mirror_count == 1) {
133 133 dreq->mirrors[hdr->pgio_mirror_idx].count += hdr->good_bytes;
134 count = dreq->mirrors[hdr->pgio_mirror_idx].count; 134 dreq->count += hdr->good_bytes;
135 if (count + dreq->io_start < hdr->io_start + hdr->good_bytes) { 135 } else {
136 count = hdr->io_start + hdr->good_bytes - dreq->io_start; 136 /* mirrored writes */
137 dreq->mirrors[hdr->pgio_mirror_idx].count = count; 137 count = dreq->mirrors[hdr->pgio_mirror_idx].count;
138 } 138 if (count + dreq->io_start < hdr->io_start + hdr->good_bytes) {
139 139 count = hdr->io_start + hdr->good_bytes - dreq->io_start;
140 /* update the dreq->count by finding the minimum agreed count from all 140 dreq->mirrors[hdr->pgio_mirror_idx].count = count;
141 * mirrors */ 141 }
142 count = dreq->mirrors[0].count; 142 /* update the dreq->count by finding the minimum agreed count from all
143 * mirrors */
144 count = dreq->mirrors[0].count;
143 145
144 for (i = 1; i < dreq->mirror_count; i++) 146 for (i = 1; i < dreq->mirror_count; i++)
145 count = min(count, dreq->mirrors[i].count); 147 count = min(count, dreq->mirrors[i].count);
146 148
147 dreq->count = count; 149 dreq->count = count;
150 }
148} 151}
149 152
150/* 153/*
@@ -258,18 +261,11 @@ ssize_t nfs_direct_IO(struct kiocb *iocb, struct iov_iter *iter, loff_t pos)
258 if (!IS_SWAPFILE(inode)) 261 if (!IS_SWAPFILE(inode))
259 return 0; 262 return 0;
260 263
261#ifndef CONFIG_NFS_SWAP
262 dprintk("NFS: nfs_direct_IO (%pD) off/no(%Ld/%lu) EINVAL\n",
263 iocb->ki_filp, (long long) pos, iter->nr_segs);
264
265 return -EINVAL;
266#else
267 VM_BUG_ON(iov_iter_count(iter) != PAGE_SIZE); 264 VM_BUG_ON(iov_iter_count(iter) != PAGE_SIZE);
268 265
269 if (iov_iter_rw(iter) == READ) 266 if (iov_iter_rw(iter) == READ)
270 return nfs_file_direct_read(iocb, iter, pos); 267 return nfs_file_direct_read(iocb, iter, pos);
271 return nfs_file_direct_write(iocb, iter); 268 return nfs_file_direct_write(iocb, iter);
272#endif /* CONFIG_NFS_SWAP */
273} 269}
274 270
275static void nfs_direct_release_pages(struct page **pages, unsigned int npages) 271static void nfs_direct_release_pages(struct page **pages, unsigned int npages)
@@ -386,7 +382,7 @@ static void nfs_direct_complete(struct nfs_direct_req *dreq, bool write)
386 if (write) 382 if (write)
387 nfs_zap_mapping(inode, inode->i_mapping); 383 nfs_zap_mapping(inode, inode->i_mapping);
388 384
389 inode_dio_done(inode); 385 inode_dio_end(inode);
390 386
391 if (dreq->iocb) { 387 if (dreq->iocb) {
392 long res = (long) dreq->error; 388 long res = (long) dreq->error;
@@ -403,8 +399,8 @@ static void nfs_direct_complete(struct nfs_direct_req *dreq, bool write)
403static void nfs_direct_readpage_release(struct nfs_page *req) 399static void nfs_direct_readpage_release(struct nfs_page *req)
404{ 400{
405 dprintk("NFS: direct read done (%s/%llu %d@%lld)\n", 401 dprintk("NFS: direct read done (%s/%llu %d@%lld)\n",
406 req->wb_context->dentry->d_inode->i_sb->s_id, 402 d_inode(req->wb_context->dentry)->i_sb->s_id,
407 (unsigned long long)NFS_FILEID(req->wb_context->dentry->d_inode), 403 (unsigned long long)NFS_FILEID(d_inode(req->wb_context->dentry)),
408 req->wb_bytes, 404 req->wb_bytes,
409 (long long)req_offset(req)); 405 (long long)req_offset(req));
410 nfs_release_request(req); 406 nfs_release_request(req);
@@ -486,7 +482,7 @@ static ssize_t nfs_direct_read_schedule_iovec(struct nfs_direct_req *dreq,
486 &nfs_direct_read_completion_ops); 482 &nfs_direct_read_completion_ops);
487 get_dreq(dreq); 483 get_dreq(dreq);
488 desc.pg_dreq = dreq; 484 desc.pg_dreq = dreq;
489 atomic_inc(&inode->i_dio_count); 485 inode_dio_begin(inode);
490 486
491 while (iov_iter_count(iter)) { 487 while (iov_iter_count(iter)) {
492 struct page **pagevec; 488 struct page **pagevec;
@@ -538,7 +534,7 @@ static ssize_t nfs_direct_read_schedule_iovec(struct nfs_direct_req *dreq,
538 * generic layer handle the completion. 534 * generic layer handle the completion.
539 */ 535 */
540 if (requested_bytes == 0) { 536 if (requested_bytes == 0) {
541 inode_dio_done(inode); 537 inode_dio_end(inode);
542 nfs_direct_req_release(dreq); 538 nfs_direct_req_release(dreq);
543 return result < 0 ? result : -EIO; 539 return result < 0 ? result : -EIO;
544 } 540 }
@@ -872,7 +868,7 @@ static ssize_t nfs_direct_write_schedule_iovec(struct nfs_direct_req *dreq,
872 &nfs_direct_write_completion_ops); 868 &nfs_direct_write_completion_ops);
873 desc.pg_dreq = dreq; 869 desc.pg_dreq = dreq;
874 get_dreq(dreq); 870 get_dreq(dreq);
875 atomic_inc(&inode->i_dio_count); 871 inode_dio_begin(inode);
876 872
877 NFS_I(inode)->write_io += iov_iter_count(iter); 873 NFS_I(inode)->write_io += iov_iter_count(iter);
878 while (iov_iter_count(iter)) { 874 while (iov_iter_count(iter)) {
@@ -928,7 +924,7 @@ static ssize_t nfs_direct_write_schedule_iovec(struct nfs_direct_req *dreq,
928 * generic layer handle the completion. 924 * generic layer handle the completion.
929 */ 925 */
930 if (requested_bytes == 0) { 926 if (requested_bytes == 0) {
931 inode_dio_done(inode); 927 inode_dio_end(inode);
932 nfs_direct_req_release(dreq); 928 nfs_direct_req_release(dreq);
933 return result < 0 ? result : -EIO; 929 return result < 0 ? result : -EIO;
934 } 930 }
@@ -1030,6 +1026,7 @@ ssize_t nfs_file_direct_write(struct kiocb *iocb, struct iov_iter *iter)
1030 if (i_size_read(inode) < iocb->ki_pos) 1026 if (i_size_read(inode) < iocb->ki_pos)
1031 i_size_write(inode, iocb->ki_pos); 1027 i_size_write(inode, iocb->ki_pos);
1032 spin_unlock(&inode->i_lock); 1028 spin_unlock(&inode->i_lock);
1029 generic_write_sync(file, pos, result);
1033 } 1030 }
1034 } 1031 }
1035 nfs_direct_req_release(dreq); 1032 nfs_direct_req_release(dreq);
diff --git a/fs/nfs/file.c b/fs/nfs/file.c
index c40e4363e746..8b8d83a526ce 100644
--- a/fs/nfs/file.c
+++ b/fs/nfs/file.c
@@ -280,6 +280,7 @@ nfs_file_fsync(struct file *file, loff_t start, loff_t end, int datasync)
280 280
281 trace_nfs_fsync_enter(inode); 281 trace_nfs_fsync_enter(inode);
282 282
283 nfs_inode_dio_wait(inode);
283 do { 284 do {
284 ret = filemap_write_and_wait_range(inode->i_mapping, start, end); 285 ret = filemap_write_and_wait_range(inode->i_mapping, start, end);
285 if (ret != 0) 286 if (ret != 0)
@@ -782,7 +783,7 @@ do_unlk(struct file *filp, int cmd, struct file_lock *fl, int is_local)
782 * Flush all pending writes before doing anything 783 * Flush all pending writes before doing anything
783 * with locks.. 784 * with locks..
784 */ 785 */
785 nfs_sync_mapping(filp->f_mapping); 786 vfs_fsync(filp, 0);
786 787
787 l_ctx = nfs_get_lock_context(nfs_file_open_context(filp)); 788 l_ctx = nfs_get_lock_context(nfs_file_open_context(filp));
788 if (!IS_ERR(l_ctx)) { 789 if (!IS_ERR(l_ctx)) {
diff --git a/fs/nfs/filelayout/filelayout.c b/fs/nfs/filelayout/filelayout.c
index 91e88a7ecef0..a46bf6de9ce4 100644
--- a/fs/nfs/filelayout/filelayout.c
+++ b/fs/nfs/filelayout/filelayout.c
@@ -258,7 +258,8 @@ filelayout_set_layoutcommit(struct nfs_pgio_header *hdr)
258 hdr->res.verf->committed != NFS_DATA_SYNC) 258 hdr->res.verf->committed != NFS_DATA_SYNC)
259 return; 259 return;
260 260
261 pnfs_set_layoutcommit(hdr); 261 pnfs_set_layoutcommit(hdr->inode, hdr->lseg,
262 hdr->mds_offset + hdr->res.count);
262 dprintk("%s inode %lu pls_end_pos %lu\n", __func__, hdr->inode->i_ino, 263 dprintk("%s inode %lu pls_end_pos %lu\n", __func__, hdr->inode->i_ino,
263 (unsigned long) NFS_I(hdr->inode)->layout->plh_lwb); 264 (unsigned long) NFS_I(hdr->inode)->layout->plh_lwb);
264} 265}
@@ -373,7 +374,7 @@ static int filelayout_commit_done_cb(struct rpc_task *task,
373 } 374 }
374 375
375 if (data->verf.committed == NFS_UNSTABLE) 376 if (data->verf.committed == NFS_UNSTABLE)
376 pnfs_commit_set_layoutcommit(data); 377 pnfs_set_layoutcommit(data->inode, data->lseg, data->lwb);
377 378
378 return 0; 379 return 0;
379} 380}
@@ -1086,7 +1087,7 @@ filelayout_alloc_deviceid_node(struct nfs_server *server,
1086} 1087}
1087 1088
1088static void 1089static void
1089filelayout_free_deveiceid_node(struct nfs4_deviceid_node *d) 1090filelayout_free_deviceid_node(struct nfs4_deviceid_node *d)
1090{ 1091{
1091 nfs4_fl_free_deviceid(container_of(d, struct nfs4_file_layout_dsaddr, id_node)); 1092 nfs4_fl_free_deviceid(container_of(d, struct nfs4_file_layout_dsaddr, id_node));
1092} 1093}
@@ -1137,7 +1138,8 @@ static struct pnfs_layoutdriver_type filelayout_type = {
1137 .read_pagelist = filelayout_read_pagelist, 1138 .read_pagelist = filelayout_read_pagelist,
1138 .write_pagelist = filelayout_write_pagelist, 1139 .write_pagelist = filelayout_write_pagelist,
1139 .alloc_deviceid_node = filelayout_alloc_deviceid_node, 1140 .alloc_deviceid_node = filelayout_alloc_deviceid_node,
1140 .free_deviceid_node = filelayout_free_deveiceid_node, 1141 .free_deviceid_node = filelayout_free_deviceid_node,
1142 .sync = pnfs_nfs_generic_sync,
1141}; 1143};
1142 1144
1143static int __init nfs4filelayout_init(void) 1145static int __init nfs4filelayout_init(void)
diff --git a/fs/nfs/filelayout/filelayoutdev.c b/fs/nfs/filelayout/filelayoutdev.c
index 4f372e224603..4946ef40ba87 100644
--- a/fs/nfs/filelayout/filelayoutdev.c
+++ b/fs/nfs/filelayout/filelayoutdev.c
@@ -55,7 +55,7 @@ nfs4_fl_free_deviceid(struct nfs4_file_layout_dsaddr *dsaddr)
55 nfs4_pnfs_ds_put(ds); 55 nfs4_pnfs_ds_put(ds);
56 } 56 }
57 kfree(dsaddr->stripe_indices); 57 kfree(dsaddr->stripe_indices);
58 kfree(dsaddr); 58 kfree_rcu(dsaddr, id_node.rcu);
59} 59}
60 60
61/* Decode opaque device data and return the result */ 61/* Decode opaque device data and return the result */
diff --git a/fs/nfs/flexfilelayout/flexfilelayout.c b/fs/nfs/flexfilelayout/flexfilelayout.c
index 315cc68945b9..7d05089e52d6 100644
--- a/fs/nfs/flexfilelayout/flexfilelayout.c
+++ b/fs/nfs/flexfilelayout/flexfilelayout.c
@@ -11,10 +11,10 @@
11#include <linux/module.h> 11#include <linux/module.h>
12 12
13#include <linux/sunrpc/metrics.h> 13#include <linux/sunrpc/metrics.h>
14#include <linux/nfs_idmap.h>
15 14
16#include "flexfilelayout.h" 15#include "flexfilelayout.h"
17#include "../nfs4session.h" 16#include "../nfs4session.h"
17#include "../nfs4idmap.h"
18#include "../internal.h" 18#include "../internal.h"
19#include "../delegation.h" 19#include "../delegation.h"
20#include "../nfs4trace.h" 20#include "../nfs4trace.h"
@@ -891,7 +891,8 @@ static int ff_layout_read_done_cb(struct rpc_task *task,
891static void 891static void
892ff_layout_set_layoutcommit(struct nfs_pgio_header *hdr) 892ff_layout_set_layoutcommit(struct nfs_pgio_header *hdr)
893{ 893{
894 pnfs_set_layoutcommit(hdr); 894 pnfs_set_layoutcommit(hdr->inode, hdr->lseg,
895 hdr->mds_offset + hdr->res.count);
895 dprintk("%s inode %lu pls_end_pos %lu\n", __func__, hdr->inode->i_ino, 896 dprintk("%s inode %lu pls_end_pos %lu\n", __func__, hdr->inode->i_ino,
896 (unsigned long) NFS_I(hdr->inode)->layout->plh_lwb); 897 (unsigned long) NFS_I(hdr->inode)->layout->plh_lwb);
897} 898}
@@ -1074,7 +1075,7 @@ static int ff_layout_commit_done_cb(struct rpc_task *task,
1074 } 1075 }
1075 1076
1076 if (data->verf.committed == NFS_UNSTABLE) 1077 if (data->verf.committed == NFS_UNSTABLE)
1077 pnfs_commit_set_layoutcommit(data); 1078 pnfs_set_layoutcommit(data->inode, data->lseg, data->lwb);
1078 1079
1079 return 0; 1080 return 0;
1080} 1081}
@@ -1414,7 +1415,7 @@ ff_layout_get_ds_info(struct inode *inode)
1414} 1415}
1415 1416
1416static void 1417static void
1417ff_layout_free_deveiceid_node(struct nfs4_deviceid_node *d) 1418ff_layout_free_deviceid_node(struct nfs4_deviceid_node *d)
1418{ 1419{
1419 nfs4_ff_layout_free_deviceid(container_of(d, struct nfs4_ff_layout_ds, 1420 nfs4_ff_layout_free_deviceid(container_of(d, struct nfs4_ff_layout_ds,
1420 id_node)); 1421 id_node));
@@ -1498,7 +1499,7 @@ static struct pnfs_layoutdriver_type flexfilelayout_type = {
1498 .pg_read_ops = &ff_layout_pg_read_ops, 1499 .pg_read_ops = &ff_layout_pg_read_ops,
1499 .pg_write_ops = &ff_layout_pg_write_ops, 1500 .pg_write_ops = &ff_layout_pg_write_ops,
1500 .get_ds_info = ff_layout_get_ds_info, 1501 .get_ds_info = ff_layout_get_ds_info,
1501 .free_deviceid_node = ff_layout_free_deveiceid_node, 1502 .free_deviceid_node = ff_layout_free_deviceid_node,
1502 .mark_request_commit = pnfs_layout_mark_request_commit, 1503 .mark_request_commit = pnfs_layout_mark_request_commit,
1503 .clear_request_commit = pnfs_generic_clear_request_commit, 1504 .clear_request_commit = pnfs_generic_clear_request_commit,
1504 .scan_commit_lists = pnfs_generic_scan_commit_lists, 1505 .scan_commit_lists = pnfs_generic_scan_commit_lists,
@@ -1508,6 +1509,7 @@ static struct pnfs_layoutdriver_type flexfilelayout_type = {
1508 .write_pagelist = ff_layout_write_pagelist, 1509 .write_pagelist = ff_layout_write_pagelist,
1509 .alloc_deviceid_node = ff_layout_alloc_deviceid_node, 1510 .alloc_deviceid_node = ff_layout_alloc_deviceid_node,
1510 .encode_layoutreturn = ff_layout_encode_layoutreturn, 1511 .encode_layoutreturn = ff_layout_encode_layoutreturn,
1512 .sync = pnfs_nfs_generic_sync,
1511}; 1513};
1512 1514
1513static int __init nfs4flexfilelayout_init(void) 1515static int __init nfs4flexfilelayout_init(void)
diff --git a/fs/nfs/flexfilelayout/flexfilelayoutdev.c b/fs/nfs/flexfilelayout/flexfilelayoutdev.c
index e2c01f204a95..77a2d026aa12 100644
--- a/fs/nfs/flexfilelayout/flexfilelayoutdev.c
+++ b/fs/nfs/flexfilelayout/flexfilelayoutdev.c
@@ -30,7 +30,7 @@ void nfs4_ff_layout_free_deviceid(struct nfs4_ff_layout_ds *mirror_ds)
30{ 30{
31 nfs4_print_deviceid(&mirror_ds->id_node.deviceid); 31 nfs4_print_deviceid(&mirror_ds->id_node.deviceid);
32 nfs4_pnfs_ds_put(mirror_ds->ds); 32 nfs4_pnfs_ds_put(mirror_ds->ds);
33 kfree(mirror_ds); 33 kfree_rcu(mirror_ds, id_node.rcu);
34} 34}
35 35
36/* Decode opaque device data and construct new_ds using it */ 36/* Decode opaque device data and construct new_ds using it */
diff --git a/fs/nfs/getroot.c b/fs/nfs/getroot.c
index 9ac3846cb59e..a608ffd28acc 100644
--- a/fs/nfs/getroot.c
+++ b/fs/nfs/getroot.c
@@ -56,11 +56,11 @@ static int nfs_superblock_set_dummy_root(struct super_block *sb, struct inode *i
56 * This again causes shrink_dcache_for_umount_subtree() to 56 * This again causes shrink_dcache_for_umount_subtree() to
57 * Oops, since the test for IS_ROOT() will fail. 57 * Oops, since the test for IS_ROOT() will fail.
58 */ 58 */
59 spin_lock(&sb->s_root->d_inode->i_lock); 59 spin_lock(&d_inode(sb->s_root)->i_lock);
60 spin_lock(&sb->s_root->d_lock); 60 spin_lock(&sb->s_root->d_lock);
61 hlist_del_init(&sb->s_root->d_u.d_alias); 61 hlist_del_init(&sb->s_root->d_u.d_alias);
62 spin_unlock(&sb->s_root->d_lock); 62 spin_unlock(&sb->s_root->d_lock);
63 spin_unlock(&sb->s_root->d_inode->i_lock); 63 spin_unlock(&d_inode(sb->s_root)->i_lock);
64 } 64 }
65 return 0; 65 return 0;
66} 66}
diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
index d42dff6d5e98..f734562c6d24 100644
--- a/fs/nfs/inode.c
+++ b/fs/nfs/inode.c
@@ -133,6 +133,13 @@ void nfs_evict_inode(struct inode *inode)
133 nfs_clear_inode(inode); 133 nfs_clear_inode(inode);
134} 134}
135 135
136int nfs_sync_inode(struct inode *inode)
137{
138 nfs_inode_dio_wait(inode);
139 return nfs_wb_all(inode);
140}
141EXPORT_SYMBOL_GPL(nfs_sync_inode);
142
136/** 143/**
137 * nfs_sync_mapping - helper to flush all mmapped dirty data to disk 144 * nfs_sync_mapping - helper to flush all mmapped dirty data to disk
138 */ 145 */
@@ -192,7 +199,6 @@ void nfs_zap_caches(struct inode *inode)
192 nfs_zap_caches_locked(inode); 199 nfs_zap_caches_locked(inode);
193 spin_unlock(&inode->i_lock); 200 spin_unlock(&inode->i_lock);
194} 201}
195EXPORT_SYMBOL_GPL(nfs_zap_caches);
196 202
197void nfs_zap_mapping(struct inode *inode, struct address_space *mapping) 203void nfs_zap_mapping(struct inode *inode, struct address_space *mapping)
198{ 204{
@@ -495,7 +501,7 @@ EXPORT_SYMBOL_GPL(nfs_fhget);
495int 501int
496nfs_setattr(struct dentry *dentry, struct iattr *attr) 502nfs_setattr(struct dentry *dentry, struct iattr *attr)
497{ 503{
498 struct inode *inode = dentry->d_inode; 504 struct inode *inode = d_inode(dentry);
499 struct nfs_fattr *fattr; 505 struct nfs_fattr *fattr;
500 int error = -ENOMEM; 506 int error = -ENOMEM;
501 507
@@ -525,10 +531,8 @@ nfs_setattr(struct dentry *dentry, struct iattr *attr)
525 trace_nfs_setattr_enter(inode); 531 trace_nfs_setattr_enter(inode);
526 532
527 /* Write all dirty data */ 533 /* Write all dirty data */
528 if (S_ISREG(inode->i_mode)) { 534 if (S_ISREG(inode->i_mode))
529 nfs_inode_dio_wait(inode); 535 nfs_sync_inode(inode);
530 nfs_wb_all(inode);
531 }
532 536
533 fattr = nfs_alloc_fattr(); 537 fattr = nfs_alloc_fattr();
534 if (fattr == NULL) 538 if (fattr == NULL)
@@ -621,7 +625,7 @@ static void nfs_request_parent_use_readdirplus(struct dentry *dentry)
621 struct dentry *parent; 625 struct dentry *parent;
622 626
623 parent = dget_parent(dentry); 627 parent = dget_parent(dentry);
624 nfs_force_use_readdirplus(parent->d_inode); 628 nfs_force_use_readdirplus(d_inode(parent));
625 dput(parent); 629 dput(parent);
626} 630}
627 631
@@ -637,15 +641,16 @@ static bool nfs_need_revalidate_inode(struct inode *inode)
637 641
638int nfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat) 642int nfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
639{ 643{
640 struct inode *inode = dentry->d_inode; 644 struct inode *inode = d_inode(dentry);
641 int need_atime = NFS_I(inode)->cache_validity & NFS_INO_INVALID_ATIME; 645 int need_atime = NFS_I(inode)->cache_validity & NFS_INO_INVALID_ATIME;
642 int err = 0; 646 int err = 0;
643 647
644 trace_nfs_getattr_enter(inode); 648 trace_nfs_getattr_enter(inode);
645 /* Flush out writes to the server in order to update c/mtime. */ 649 /* Flush out writes to the server in order to update c/mtime. */
646 if (S_ISREG(inode->i_mode)) { 650 if (S_ISREG(inode->i_mode)) {
647 nfs_inode_dio_wait(inode); 651 mutex_lock(&inode->i_mutex);
648 err = filemap_write_and_wait(inode->i_mapping); 652 err = nfs_sync_inode(inode);
653 mutex_unlock(&inode->i_mutex);
649 if (err) 654 if (err)
650 goto out; 655 goto out;
651 } 656 }
@@ -708,7 +713,7 @@ static struct nfs_lock_context *__nfs_find_lock_context(struct nfs_open_context
708struct nfs_lock_context *nfs_get_lock_context(struct nfs_open_context *ctx) 713struct nfs_lock_context *nfs_get_lock_context(struct nfs_open_context *ctx)
709{ 714{
710 struct nfs_lock_context *res, *new = NULL; 715 struct nfs_lock_context *res, *new = NULL;
711 struct inode *inode = ctx->dentry->d_inode; 716 struct inode *inode = d_inode(ctx->dentry);
712 717
713 spin_lock(&inode->i_lock); 718 spin_lock(&inode->i_lock);
714 res = __nfs_find_lock_context(ctx); 719 res = __nfs_find_lock_context(ctx);
@@ -736,7 +741,7 @@ EXPORT_SYMBOL_GPL(nfs_get_lock_context);
736void nfs_put_lock_context(struct nfs_lock_context *l_ctx) 741void nfs_put_lock_context(struct nfs_lock_context *l_ctx)
737{ 742{
738 struct nfs_open_context *ctx = l_ctx->open_context; 743 struct nfs_open_context *ctx = l_ctx->open_context;
739 struct inode *inode = ctx->dentry->d_inode; 744 struct inode *inode = d_inode(ctx->dentry);
740 745
741 if (!atomic_dec_and_lock(&l_ctx->count, &inode->i_lock)) 746 if (!atomic_dec_and_lock(&l_ctx->count, &inode->i_lock))
742 return; 747 return;
@@ -763,7 +768,7 @@ void nfs_close_context(struct nfs_open_context *ctx, int is_sync)
763 return; 768 return;
764 if (!is_sync) 769 if (!is_sync)
765 return; 770 return;
766 inode = ctx->dentry->d_inode; 771 inode = d_inode(ctx->dentry);
767 if (!list_empty(&NFS_I(inode)->open_files)) 772 if (!list_empty(&NFS_I(inode)->open_files))
768 return; 773 return;
769 server = NFS_SERVER(inode); 774 server = NFS_SERVER(inode);
@@ -810,7 +815,7 @@ EXPORT_SYMBOL_GPL(get_nfs_open_context);
810 815
811static void __put_nfs_open_context(struct nfs_open_context *ctx, int is_sync) 816static void __put_nfs_open_context(struct nfs_open_context *ctx, int is_sync)
812{ 817{
813 struct inode *inode = ctx->dentry->d_inode; 818 struct inode *inode = d_inode(ctx->dentry);
814 struct super_block *sb = ctx->dentry->d_sb; 819 struct super_block *sb = ctx->dentry->d_sb;
815 820
816 if (!list_empty(&ctx->list)) { 821 if (!list_empty(&ctx->list)) {
@@ -842,7 +847,7 @@ EXPORT_SYMBOL_GPL(put_nfs_open_context);
842 */ 847 */
843void nfs_inode_attach_open_context(struct nfs_open_context *ctx) 848void nfs_inode_attach_open_context(struct nfs_open_context *ctx)
844{ 849{
845 struct inode *inode = ctx->dentry->d_inode; 850 struct inode *inode = d_inode(ctx->dentry);
846 struct nfs_inode *nfsi = NFS_I(inode); 851 struct nfs_inode *nfsi = NFS_I(inode);
847 852
848 spin_lock(&inode->i_lock); 853 spin_lock(&inode->i_lock);
@@ -885,7 +890,7 @@ static void nfs_file_clear_open_context(struct file *filp)
885 struct nfs_open_context *ctx = nfs_file_open_context(filp); 890 struct nfs_open_context *ctx = nfs_file_open_context(filp);
886 891
887 if (ctx) { 892 if (ctx) {
888 struct inode *inode = ctx->dentry->d_inode; 893 struct inode *inode = d_inode(ctx->dentry);
889 894
890 filp->private_data = NULL; 895 filp->private_data = NULL;
891 spin_lock(&inode->i_lock); 896 spin_lock(&inode->i_lock);
@@ -1588,6 +1593,19 @@ int nfs_post_op_update_inode_force_wcc(struct inode *inode, struct nfs_fattr *fa
1588} 1593}
1589EXPORT_SYMBOL_GPL(nfs_post_op_update_inode_force_wcc); 1594EXPORT_SYMBOL_GPL(nfs_post_op_update_inode_force_wcc);
1590 1595
1596
1597static inline bool nfs_fileid_valid(struct nfs_inode *nfsi,
1598 struct nfs_fattr *fattr)
1599{
1600 bool ret1 = true, ret2 = true;
1601
1602 if (fattr->valid & NFS_ATTR_FATTR_FILEID)
1603 ret1 = (nfsi->fileid == fattr->fileid);
1604 if (fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
1605 ret2 = (nfsi->fileid == fattr->mounted_on_fileid);
1606 return ret1 || ret2;
1607}
1608
1591/* 1609/*
1592 * Many nfs protocol calls return the new file attributes after 1610 * Many nfs protocol calls return the new file attributes after
1593 * an operation. Here we update the inode to reflect the state 1611 * an operation. Here we update the inode to reflect the state
@@ -1614,7 +1632,7 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
1614 nfs_display_fhandle_hash(NFS_FH(inode)), 1632 nfs_display_fhandle_hash(NFS_FH(inode)),
1615 atomic_read(&inode->i_count), fattr->valid); 1633 atomic_read(&inode->i_count), fattr->valid);
1616 1634
1617 if ((fattr->valid & NFS_ATTR_FATTR_FILEID) && nfsi->fileid != fattr->fileid) { 1635 if (!nfs_fileid_valid(nfsi, fattr)) {
1618 printk(KERN_ERR "NFS: server %s error: fileid changed\n" 1636 printk(KERN_ERR "NFS: server %s error: fileid changed\n"
1619 "fsid %s: expected fileid 0x%Lx, got 0x%Lx\n", 1637 "fsid %s: expected fileid 0x%Lx, got 0x%Lx\n",
1620 NFS_SERVER(inode)->nfs_client->cl_hostname, 1638 NFS_SERVER(inode)->nfs_client->cl_hostname,
@@ -1819,7 +1837,7 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
1819struct inode *nfs_alloc_inode(struct super_block *sb) 1837struct inode *nfs_alloc_inode(struct super_block *sb)
1820{ 1838{
1821 struct nfs_inode *nfsi; 1839 struct nfs_inode *nfsi;
1822 nfsi = (struct nfs_inode *)kmem_cache_alloc(nfs_inode_cachep, GFP_KERNEL); 1840 nfsi = kmem_cache_alloc(nfs_inode_cachep, GFP_KERNEL);
1823 if (!nfsi) 1841 if (!nfsi)
1824 return NULL; 1842 return NULL;
1825 nfsi->flags = 0UL; 1843 nfsi->flags = 0UL;
diff --git a/fs/nfs/namespace.c b/fs/nfs/namespace.c
index b5a0afc3ee10..c8162c660c44 100644
--- a/fs/nfs/namespace.c
+++ b/fs/nfs/namespace.c
@@ -139,7 +139,7 @@ EXPORT_SYMBOL_GPL(nfs_path);
139struct vfsmount *nfs_d_automount(struct path *path) 139struct vfsmount *nfs_d_automount(struct path *path)
140{ 140{
141 struct vfsmount *mnt; 141 struct vfsmount *mnt;
142 struct nfs_server *server = NFS_SERVER(path->dentry->d_inode); 142 struct nfs_server *server = NFS_SERVER(d_inode(path->dentry));
143 struct nfs_fh *fh = NULL; 143 struct nfs_fh *fh = NULL;
144 struct nfs_fattr *fattr = NULL; 144 struct nfs_fattr *fattr = NULL;
145 145
@@ -180,16 +180,16 @@ out_nofree:
180static int 180static int
181nfs_namespace_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat) 181nfs_namespace_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
182{ 182{
183 if (NFS_FH(dentry->d_inode)->size != 0) 183 if (NFS_FH(d_inode(dentry))->size != 0)
184 return nfs_getattr(mnt, dentry, stat); 184 return nfs_getattr(mnt, dentry, stat);
185 generic_fillattr(dentry->d_inode, stat); 185 generic_fillattr(d_inode(dentry), stat);
186 return 0; 186 return 0;
187} 187}
188 188
189static int 189static int
190nfs_namespace_setattr(struct dentry *dentry, struct iattr *attr) 190nfs_namespace_setattr(struct dentry *dentry, struct iattr *attr)
191{ 191{
192 if (NFS_FH(dentry->d_inode)->size != 0) 192 if (NFS_FH(d_inode(dentry))->size != 0)
193 return nfs_setattr(dentry, attr); 193 return nfs_setattr(dentry, attr);
194 return -EACCES; 194 return -EACCES;
195} 195}
@@ -279,7 +279,7 @@ struct vfsmount *nfs_submount(struct nfs_server *server, struct dentry *dentry,
279 struct dentry *parent = dget_parent(dentry); 279 struct dentry *parent = dget_parent(dentry);
280 280
281 /* Look it up again to get its attributes */ 281 /* Look it up again to get its attributes */
282 err = server->nfs_client->rpc_ops->lookup(parent->d_inode, &dentry->d_name, fh, fattr, NULL); 282 err = server->nfs_client->rpc_ops->lookup(d_inode(parent), &dentry->d_name, fh, fattr, NULL);
283 dput(parent); 283 dput(parent);
284 if (err != 0) 284 if (err != 0)
285 return ERR_PTR(err); 285 return ERR_PTR(err);
diff --git a/fs/nfs/nfs3acl.c b/fs/nfs/nfs3acl.c
index 658e586ca438..1ebe2fc7cda2 100644
--- a/fs/nfs/nfs3acl.c
+++ b/fs/nfs/nfs3acl.c
@@ -279,7 +279,7 @@ nfs3_list_one_acl(struct inode *inode, int type, const char *name, void *data,
279ssize_t 279ssize_t
280nfs3_listxattr(struct dentry *dentry, char *data, size_t size) 280nfs3_listxattr(struct dentry *dentry, char *data, size_t size)
281{ 281{
282 struct inode *inode = dentry->d_inode; 282 struct inode *inode = d_inode(dentry);
283 ssize_t result = 0; 283 ssize_t result = 0;
284 int error; 284 int error;
285 285
diff --git a/fs/nfs/nfs3proc.c b/fs/nfs/nfs3proc.c
index 1f11d2533ee4..cb28cceefebe 100644
--- a/fs/nfs/nfs3proc.c
+++ b/fs/nfs/nfs3proc.c
@@ -120,7 +120,7 @@ static int
120nfs3_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, 120nfs3_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr,
121 struct iattr *sattr) 121 struct iattr *sattr)
122{ 122{
123 struct inode *inode = dentry->d_inode; 123 struct inode *inode = d_inode(dentry);
124 struct nfs3_sattrargs arg = { 124 struct nfs3_sattrargs arg = {
125 .fh = NFS_FH(inode), 125 .fh = NFS_FH(inode),
126 .sattr = sattr, 126 .sattr = sattr,
@@ -386,13 +386,13 @@ nfs3_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
386 * not sure this buys us anything (and I'd have 386 * not sure this buys us anything (and I'd have
387 * to revamp the NFSv3 XDR code) */ 387 * to revamp the NFSv3 XDR code) */
388 status = nfs3_proc_setattr(dentry, data->res.fattr, sattr); 388 status = nfs3_proc_setattr(dentry, data->res.fattr, sattr);
389 nfs_post_op_update_inode(dentry->d_inode, data->res.fattr); 389 nfs_post_op_update_inode(d_inode(dentry), data->res.fattr);
390 dprintk("NFS reply setattr (post-create): %d\n", status); 390 dprintk("NFS reply setattr (post-create): %d\n", status);
391 if (status != 0) 391 if (status != 0)
392 goto out_release_acls; 392 goto out_release_acls;
393 } 393 }
394 394
395 status = nfs3_proc_setacls(dentry->d_inode, acl, default_acl); 395 status = nfs3_proc_setacls(d_inode(dentry), acl, default_acl);
396 396
397out_release_acls: 397out_release_acls:
398 posix_acl_release(acl); 398 posix_acl_release(acl);
@@ -570,7 +570,7 @@ nfs3_proc_mkdir(struct inode *dir, struct dentry *dentry, struct iattr *sattr)
570 if (status != 0) 570 if (status != 0)
571 goto out_release_acls; 571 goto out_release_acls;
572 572
573 status = nfs3_proc_setacls(dentry->d_inode, acl, default_acl); 573 status = nfs3_proc_setacls(d_inode(dentry), acl, default_acl);
574 574
575out_release_acls: 575out_release_acls:
576 posix_acl_release(acl); 576 posix_acl_release(acl);
@@ -623,7 +623,7 @@ static int
623nfs3_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, 623nfs3_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
624 u64 cookie, struct page **pages, unsigned int count, int plus) 624 u64 cookie, struct page **pages, unsigned int count, int plus)
625{ 625{
626 struct inode *dir = dentry->d_inode; 626 struct inode *dir = d_inode(dentry);
627 __be32 *verf = NFS_I(dir)->cookieverf; 627 __be32 *verf = NFS_I(dir)->cookieverf;
628 struct nfs3_readdirargs arg = { 628 struct nfs3_readdirargs arg = {
629 .fh = NFS_FH(dir), 629 .fh = NFS_FH(dir),
@@ -715,7 +715,7 @@ nfs3_proc_mknod(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
715 if (status != 0) 715 if (status != 0)
716 goto out_release_acls; 716 goto out_release_acls;
717 717
718 status = nfs3_proc_setacls(dentry->d_inode, acl, default_acl); 718 status = nfs3_proc_setacls(d_inode(dentry), acl, default_acl);
719 719
720out_release_acls: 720out_release_acls:
721 posix_acl_release(acl); 721 posix_acl_release(acl);
diff --git a/fs/nfs/nfs42proc.c b/fs/nfs/nfs42proc.c
index cb170722769c..3a9e75235f30 100644
--- a/fs/nfs/nfs42proc.c
+++ b/fs/nfs/nfs42proc.c
@@ -36,13 +36,16 @@ static int _nfs42_proc_fallocate(struct rpc_message *msg, struct file *filep,
36 loff_t offset, loff_t len) 36 loff_t offset, loff_t len)
37{ 37{
38 struct inode *inode = file_inode(filep); 38 struct inode *inode = file_inode(filep);
39 struct nfs_server *server = NFS_SERVER(inode);
39 struct nfs42_falloc_args args = { 40 struct nfs42_falloc_args args = {
40 .falloc_fh = NFS_FH(inode), 41 .falloc_fh = NFS_FH(inode),
41 .falloc_offset = offset, 42 .falloc_offset = offset,
42 .falloc_length = len, 43 .falloc_length = len,
44 .falloc_bitmask = server->cache_consistency_bitmask,
45 };
46 struct nfs42_falloc_res res = {
47 .falloc_server = server,
43 }; 48 };
44 struct nfs42_falloc_res res;
45 struct nfs_server *server = NFS_SERVER(inode);
46 int status; 49 int status;
47 50
48 msg->rpc_argp = &args; 51 msg->rpc_argp = &args;
@@ -52,8 +55,17 @@ static int _nfs42_proc_fallocate(struct rpc_message *msg, struct file *filep,
52 if (status) 55 if (status)
53 return status; 56 return status;
54 57
55 return nfs4_call_sync(server->client, server, msg, 58 res.falloc_fattr = nfs_alloc_fattr();
56 &args.seq_args, &res.seq_res, 0); 59 if (!res.falloc_fattr)
60 return -ENOMEM;
61
62 status = nfs4_call_sync(server->client, server, msg,
63 &args.seq_args, &res.seq_res, 0);
64 if (status == 0)
65 status = nfs_post_op_update_inode(inode, res.falloc_fattr);
66
67 kfree(res.falloc_fattr);
68 return status;
57} 69}
58 70
59static int nfs42_proc_fallocate(struct rpc_message *msg, struct file *filep, 71static int nfs42_proc_fallocate(struct rpc_message *msg, struct file *filep,
@@ -84,9 +96,13 @@ int nfs42_proc_allocate(struct file *filep, loff_t offset, loff_t len)
84 if (!nfs_server_capable(inode, NFS_CAP_ALLOCATE)) 96 if (!nfs_server_capable(inode, NFS_CAP_ALLOCATE))
85 return -EOPNOTSUPP; 97 return -EOPNOTSUPP;
86 98
99 mutex_lock(&inode->i_mutex);
100
87 err = nfs42_proc_fallocate(&msg, filep, offset, len); 101 err = nfs42_proc_fallocate(&msg, filep, offset, len);
88 if (err == -EOPNOTSUPP) 102 if (err == -EOPNOTSUPP)
89 NFS_SERVER(inode)->caps &= ~NFS_CAP_ALLOCATE; 103 NFS_SERVER(inode)->caps &= ~NFS_CAP_ALLOCATE;
104
105 mutex_unlock(&inode->i_mutex);
90 return err; 106 return err;
91} 107}
92 108
@@ -101,9 +117,16 @@ int nfs42_proc_deallocate(struct file *filep, loff_t offset, loff_t len)
101 if (!nfs_server_capable(inode, NFS_CAP_DEALLOCATE)) 117 if (!nfs_server_capable(inode, NFS_CAP_DEALLOCATE))
102 return -EOPNOTSUPP; 118 return -EOPNOTSUPP;
103 119
120 nfs_wb_all(inode);
121 mutex_lock(&inode->i_mutex);
122
104 err = nfs42_proc_fallocate(&msg, filep, offset, len); 123 err = nfs42_proc_fallocate(&msg, filep, offset, len);
124 if (err == 0)
125 truncate_pagecache_range(inode, offset, (offset + len) -1);
105 if (err == -EOPNOTSUPP) 126 if (err == -EOPNOTSUPP)
106 NFS_SERVER(inode)->caps &= ~NFS_CAP_DEALLOCATE; 127 NFS_SERVER(inode)->caps &= ~NFS_CAP_DEALLOCATE;
128
129 mutex_unlock(&inode->i_mutex);
107 return err; 130 return err;
108} 131}
109 132
diff --git a/fs/nfs/nfs42xdr.c b/fs/nfs/nfs42xdr.c
index 038a7e1521fa..1a25b27248f2 100644
--- a/fs/nfs/nfs42xdr.c
+++ b/fs/nfs/nfs42xdr.c
@@ -25,16 +25,20 @@
25 25
26#define NFS4_enc_allocate_sz (compound_encode_hdr_maxsz + \ 26#define NFS4_enc_allocate_sz (compound_encode_hdr_maxsz + \
27 encode_putfh_maxsz + \ 27 encode_putfh_maxsz + \
28 encode_allocate_maxsz) 28 encode_allocate_maxsz + \
29 encode_getattr_maxsz)
29#define NFS4_dec_allocate_sz (compound_decode_hdr_maxsz + \ 30#define NFS4_dec_allocate_sz (compound_decode_hdr_maxsz + \
30 decode_putfh_maxsz + \ 31 decode_putfh_maxsz + \
31 decode_allocate_maxsz) 32 decode_allocate_maxsz + \
33 decode_getattr_maxsz)
32#define NFS4_enc_deallocate_sz (compound_encode_hdr_maxsz + \ 34#define NFS4_enc_deallocate_sz (compound_encode_hdr_maxsz + \
33 encode_putfh_maxsz + \ 35 encode_putfh_maxsz + \
34 encode_deallocate_maxsz) 36 encode_deallocate_maxsz + \
37 encode_getattr_maxsz)
35#define NFS4_dec_deallocate_sz (compound_decode_hdr_maxsz + \ 38#define NFS4_dec_deallocate_sz (compound_decode_hdr_maxsz + \
36 decode_putfh_maxsz + \ 39 decode_putfh_maxsz + \
37 decode_deallocate_maxsz) 40 decode_deallocate_maxsz + \
41 decode_getattr_maxsz)
38#define NFS4_enc_seek_sz (compound_encode_hdr_maxsz + \ 42#define NFS4_enc_seek_sz (compound_encode_hdr_maxsz + \
39 encode_putfh_maxsz + \ 43 encode_putfh_maxsz + \
40 encode_seek_maxsz) 44 encode_seek_maxsz)
@@ -92,6 +96,7 @@ static void nfs4_xdr_enc_allocate(struct rpc_rqst *req,
92 encode_sequence(xdr, &args->seq_args, &hdr); 96 encode_sequence(xdr, &args->seq_args, &hdr);
93 encode_putfh(xdr, args->falloc_fh, &hdr); 97 encode_putfh(xdr, args->falloc_fh, &hdr);
94 encode_allocate(xdr, args, &hdr); 98 encode_allocate(xdr, args, &hdr);
99 encode_getfattr(xdr, args->falloc_bitmask, &hdr);
95 encode_nops(&hdr); 100 encode_nops(&hdr);
96} 101}
97 102
@@ -110,6 +115,7 @@ static void nfs4_xdr_enc_deallocate(struct rpc_rqst *req,
110 encode_sequence(xdr, &args->seq_args, &hdr); 115 encode_sequence(xdr, &args->seq_args, &hdr);
111 encode_putfh(xdr, args->falloc_fh, &hdr); 116 encode_putfh(xdr, args->falloc_fh, &hdr);
112 encode_deallocate(xdr, args, &hdr); 117 encode_deallocate(xdr, args, &hdr);
118 encode_getfattr(xdr, args->falloc_bitmask, &hdr);
113 encode_nops(&hdr); 119 encode_nops(&hdr);
114} 120}
115 121
@@ -183,6 +189,9 @@ static int nfs4_xdr_dec_allocate(struct rpc_rqst *rqstp,
183 if (status) 189 if (status)
184 goto out; 190 goto out;
185 status = decode_allocate(xdr, res); 191 status = decode_allocate(xdr, res);
192 if (status)
193 goto out;
194 decode_getfattr(xdr, res->falloc_fattr, res->falloc_server);
186out: 195out:
187 return status; 196 return status;
188} 197}
@@ -207,6 +216,9 @@ static int nfs4_xdr_dec_deallocate(struct rpc_rqst *rqstp,
207 if (status) 216 if (status)
208 goto out; 217 goto out;
209 status = decode_deallocate(xdr, res); 218 status = decode_deallocate(xdr, res);
219 if (status)
220 goto out;
221 decode_getfattr(xdr, res->falloc_fattr, res->falloc_server);
210out: 222out:
211 return status; 223 return status;
212} 224}
diff --git a/fs/nfs/nfs4client.c b/fs/nfs/nfs4client.c
index 86d6214ea022..e42be52a8c18 100644
--- a/fs/nfs/nfs4client.c
+++ b/fs/nfs/nfs4client.c
@@ -4,7 +4,6 @@
4 */ 4 */
5#include <linux/module.h> 5#include <linux/module.h>
6#include <linux/nfs_fs.h> 6#include <linux/nfs_fs.h>
7#include <linux/nfs_idmap.h>
8#include <linux/nfs_mount.h> 7#include <linux/nfs_mount.h>
9#include <linux/sunrpc/addr.h> 8#include <linux/sunrpc/addr.h>
10#include <linux/sunrpc/auth.h> 9#include <linux/sunrpc/auth.h>
@@ -15,6 +14,7 @@
15#include "callback.h" 14#include "callback.h"
16#include "delegation.h" 15#include "delegation.h"
17#include "nfs4session.h" 16#include "nfs4session.h"
17#include "nfs4idmap.h"
18#include "pnfs.h" 18#include "pnfs.h"
19#include "netns.h" 19#include "netns.h"
20 20
@@ -1130,7 +1130,7 @@ error:
1130 */ 1130 */
1131static int nfs_probe_destination(struct nfs_server *server) 1131static int nfs_probe_destination(struct nfs_server *server)
1132{ 1132{
1133 struct inode *inode = server->super->s_root->d_inode; 1133 struct inode *inode = d_inode(server->super->s_root);
1134 struct nfs_fattr *fattr; 1134 struct nfs_fattr *fattr;
1135 int error; 1135 int error;
1136 1136
diff --git a/fs/nfs/nfs4file.c b/fs/nfs/nfs4file.c
index 0181cde1d102..f58c17b3b480 100644
--- a/fs/nfs/nfs4file.c
+++ b/fs/nfs/nfs4file.c
@@ -10,6 +10,8 @@
10#include "fscache.h" 10#include "fscache.h"
11#include "pnfs.h" 11#include "pnfs.h"
12 12
13#include "nfstrace.h"
14
13#ifdef CONFIG_NFS_V4_2 15#ifdef CONFIG_NFS_V4_2
14#include "nfs42.h" 16#include "nfs42.h"
15#endif 17#endif
@@ -46,7 +48,7 @@ nfs4_file_open(struct inode *inode, struct file *filp)
46 openflags &= ~(O_CREAT|O_EXCL); 48 openflags &= ~(O_CREAT|O_EXCL);
47 49
48 parent = dget_parent(dentry); 50 parent = dget_parent(dentry);
49 dir = parent->d_inode; 51 dir = d_inode(parent);
50 52
51 ctx = alloc_nfs_open_context(filp->f_path.dentry, filp->f_mode); 53 ctx = alloc_nfs_open_context(filp->f_path.dentry, filp->f_mode);
52 err = PTR_ERR(ctx); 54 err = PTR_ERR(ctx);
@@ -57,7 +59,7 @@ nfs4_file_open(struct inode *inode, struct file *filp)
57 if (openflags & O_TRUNC) { 59 if (openflags & O_TRUNC) {
58 attr.ia_valid |= ATTR_SIZE; 60 attr.ia_valid |= ATTR_SIZE;
59 attr.ia_size = 0; 61 attr.ia_size = 0;
60 nfs_wb_all(inode); 62 nfs_sync_inode(inode);
61 } 63 }
62 64
63 inode = NFS_PROTO(dir)->open_context(dir, ctx, openflags, &attr, &opened); 65 inode = NFS_PROTO(dir)->open_context(dir, ctx, openflags, &attr, &opened);
@@ -74,7 +76,7 @@ nfs4_file_open(struct inode *inode, struct file *filp)
74 goto out_drop; 76 goto out_drop;
75 } 77 }
76 } 78 }
77 if (inode != dentry->d_inode) 79 if (inode != d_inode(dentry))
78 goto out_drop; 80 goto out_drop;
79 81
80 nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); 82 nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
@@ -100,6 +102,9 @@ nfs4_file_fsync(struct file *file, loff_t start, loff_t end, int datasync)
100 int ret; 102 int ret;
101 struct inode *inode = file_inode(file); 103 struct inode *inode = file_inode(file);
102 104
105 trace_nfs_fsync_enter(inode);
106
107 nfs_inode_dio_wait(inode);
103 do { 108 do {
104 ret = filemap_write_and_wait_range(inode->i_mapping, start, end); 109 ret = filemap_write_and_wait_range(inode->i_mapping, start, end);
105 if (ret != 0) 110 if (ret != 0)
@@ -107,7 +112,7 @@ nfs4_file_fsync(struct file *file, loff_t start, loff_t end, int datasync)
107 mutex_lock(&inode->i_mutex); 112 mutex_lock(&inode->i_mutex);
108 ret = nfs_file_fsync_commit(file, start, end, datasync); 113 ret = nfs_file_fsync_commit(file, start, end, datasync);
109 if (!ret) 114 if (!ret)
110 ret = pnfs_layoutcommit_inode(inode, true); 115 ret = pnfs_sync_inode(inode, !!datasync);
111 mutex_unlock(&inode->i_mutex); 116 mutex_unlock(&inode->i_mutex);
112 /* 117 /*
113 * If nfs_file_fsync_commit detected a server reboot, then 118 * If nfs_file_fsync_commit detected a server reboot, then
@@ -118,6 +123,7 @@ nfs4_file_fsync(struct file *file, loff_t start, loff_t end, int datasync)
118 end = LLONG_MAX; 123 end = LLONG_MAX;
119 } while (ret == -EAGAIN); 124 } while (ret == -EAGAIN);
120 125
126 trace_nfs_fsync_exit(inode, ret);
121 return ret; 127 return ret;
122} 128}
123 129
@@ -152,15 +158,9 @@ static long nfs42_fallocate(struct file *filep, int mode, loff_t offset, loff_t
152 if (ret < 0) 158 if (ret < 0)
153 return ret; 159 return ret;
154 160
155 mutex_lock(&inode->i_mutex);
156 if (mode & FALLOC_FL_PUNCH_HOLE) 161 if (mode & FALLOC_FL_PUNCH_HOLE)
157 ret = nfs42_proc_deallocate(filep, offset, len); 162 return nfs42_proc_deallocate(filep, offset, len);
158 else 163 return nfs42_proc_allocate(filep, offset, len);
159 ret = nfs42_proc_allocate(filep, offset, len);
160 mutex_unlock(&inode->i_mutex);
161
162 nfs_zap_caches(inode);
163 return ret;
164} 164}
165#endif /* CONFIG_NFS_V4_2 */ 165#endif /* CONFIG_NFS_V4_2 */
166 166
diff --git a/fs/nfs/idmap.c b/fs/nfs/nfs4idmap.c
index 857e2a99acc8..2e1737c40a29 100644
--- a/fs/nfs/idmap.c
+++ b/fs/nfs/nfs4idmap.c
@@ -36,7 +36,6 @@
36#include <linux/types.h> 36#include <linux/types.h>
37#include <linux/parser.h> 37#include <linux/parser.h>
38#include <linux/fs.h> 38#include <linux/fs.h>
39#include <linux/nfs_idmap.h>
40#include <net/net_namespace.h> 39#include <net/net_namespace.h>
41#include <linux/sunrpc/rpc_pipe_fs.h> 40#include <linux/sunrpc/rpc_pipe_fs.h>
42#include <linux/nfs_fs.h> 41#include <linux/nfs_fs.h>
@@ -49,6 +48,7 @@
49 48
50#include "internal.h" 49#include "internal.h"
51#include "netns.h" 50#include "netns.h"
51#include "nfs4idmap.h"
52#include "nfs4trace.h" 52#include "nfs4trace.h"
53 53
54#define NFS_UINT_MAXLEN 11 54#define NFS_UINT_MAXLEN 11
diff --git a/fs/nfs/nfs4idmap.h b/fs/nfs/nfs4idmap.h
new file mode 100644
index 000000000000..de44d7330ab3
--- /dev/null
+++ b/fs/nfs/nfs4idmap.h
@@ -0,0 +1,68 @@
1/*
2 * fs/nfs/nfs4idmap.h
3 *
4 * UID and GID to name mapping for clients.
5 *
6 * Copyright (c) 2002 The Regents of the University of Michigan.
7 * All rights reserved.
8 *
9 * Marius Aamodt Eriksen <marius@umich.edu>
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 *
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. Neither the name of the University nor the names of its
21 * contributors may be used to endorse or promote products derived
22 * from this software without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
25 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
26 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
31 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 */
36#ifndef NFS_IDMAP_H
37#define NFS_IDMAP_H
38
39#include <linux/uidgid.h>
40#include <uapi/linux/nfs_idmap.h>
41
42
43/* Forward declaration to make this header independent of others */
44struct nfs_client;
45struct nfs_server;
46struct nfs_fattr;
47struct nfs4_string;
48
49int nfs_idmap_init(void);
50void nfs_idmap_quit(void);
51int nfs_idmap_new(struct nfs_client *);
52void nfs_idmap_delete(struct nfs_client *);
53
54void nfs_fattr_init_names(struct nfs_fattr *fattr,
55 struct nfs4_string *owner_name,
56 struct nfs4_string *group_name);
57void nfs_fattr_free_names(struct nfs_fattr *);
58void nfs_fattr_map_and_free_names(struct nfs_server *, struct nfs_fattr *);
59
60int nfs_map_name_to_uid(const struct nfs_server *, const char *, size_t, kuid_t *);
61int nfs_map_group_to_gid(const struct nfs_server *, const char *, size_t, kgid_t *);
62int nfs_map_uid_to_name(const struct nfs_server *, kuid_t, char *, size_t);
63int nfs_map_gid_to_group(const struct nfs_server *, kgid_t, char *, size_t);
64
65int nfs_map_string_to_numeric(const char *name, size_t namelen, __u32 *res);
66
67extern unsigned int nfs_idmap_cache_timeout;
68#endif /* NFS_IDMAP_H */
diff --git a/fs/nfs/nfs4namespace.c b/fs/nfs/nfs4namespace.c
index 3d83cb1fdc70..f592672373cb 100644
--- a/fs/nfs/nfs4namespace.c
+++ b/fs/nfs/nfs4namespace.c
@@ -375,7 +375,7 @@ static struct vfsmount *nfs_do_refmount(struct rpc_clnt *client, struct dentry *
375 dprintk("%s: getting locations for %pd2\n", 375 dprintk("%s: getting locations for %pd2\n",
376 __func__, dentry); 376 __func__, dentry);
377 377
378 err = nfs4_proc_fs_locations(client, parent->d_inode, &dentry->d_name, fs_locations, page); 378 err = nfs4_proc_fs_locations(client, d_inode(parent), &dentry->d_name, fs_locations, page);
379 dput(parent); 379 dput(parent);
380 if (err != 0 || 380 if (err != 0 ||
381 fs_locations->nlocations <= 0 || 381 fs_locations->nlocations <= 0 ||
@@ -396,7 +396,7 @@ struct vfsmount *nfs4_submount(struct nfs_server *server, struct dentry *dentry,
396{ 396{
397 rpc_authflavor_t flavor = server->client->cl_auth->au_flavor; 397 rpc_authflavor_t flavor = server->client->cl_auth->au_flavor;
398 struct dentry *parent = dget_parent(dentry); 398 struct dentry *parent = dget_parent(dentry);
399 struct inode *dir = parent->d_inode; 399 struct inode *dir = d_inode(parent);
400 struct qstr *name = &dentry->d_name; 400 struct qstr *name = &dentry->d_name;
401 struct rpc_clnt *client; 401 struct rpc_clnt *client;
402 struct vfsmount *mnt; 402 struct vfsmount *mnt;
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index 627f37c44456..45b35b9b1e36 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -51,7 +51,6 @@
51#include <linux/namei.h> 51#include <linux/namei.h>
52#include <linux/mount.h> 52#include <linux/mount.h>
53#include <linux/module.h> 53#include <linux/module.h>
54#include <linux/nfs_idmap.h>
55#include <linux/xattr.h> 54#include <linux/xattr.h>
56#include <linux/utsname.h> 55#include <linux/utsname.h>
57#include <linux/freezer.h> 56#include <linux/freezer.h>
@@ -63,6 +62,7 @@
63#include "callback.h" 62#include "callback.h"
64#include "pnfs.h" 63#include "pnfs.h"
65#include "netns.h" 64#include "netns.h"
65#include "nfs4idmap.h"
66#include "nfs4session.h" 66#include "nfs4session.h"
67#include "fscache.h" 67#include "fscache.h"
68 68
@@ -185,7 +185,8 @@ const u32 nfs4_fattr_bitmap[3] = {
185 | FATTR4_WORD1_SPACE_USED 185 | FATTR4_WORD1_SPACE_USED
186 | FATTR4_WORD1_TIME_ACCESS 186 | FATTR4_WORD1_TIME_ACCESS
187 | FATTR4_WORD1_TIME_METADATA 187 | FATTR4_WORD1_TIME_METADATA
188 | FATTR4_WORD1_TIME_MODIFY, 188 | FATTR4_WORD1_TIME_MODIFY
189 | FATTR4_WORD1_MOUNTED_ON_FILEID,
189#ifdef CONFIG_NFS_V4_SECURITY_LABEL 190#ifdef CONFIG_NFS_V4_SECURITY_LABEL
190 FATTR4_WORD2_SECURITY_LABEL 191 FATTR4_WORD2_SECURITY_LABEL
191#endif 192#endif
@@ -293,7 +294,7 @@ static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dent
293 *p++ = xdr_one; /* bitmap length */ 294 *p++ = xdr_one; /* bitmap length */
294 *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ 295 *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */
295 *p++ = htonl(8); /* attribute buffer length */ 296 *p++ = htonl(8); /* attribute buffer length */
296 p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_inode)); 297 p = xdr_encode_hyper(p, NFS_FILEID(d_inode(dentry)));
297 } 298 }
298 299
299 *p++ = xdr_one; /* next */ 300 *p++ = xdr_one; /* next */
@@ -305,7 +306,7 @@ static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dent
305 *p++ = xdr_one; /* bitmap length */ 306 *p++ = xdr_one; /* bitmap length */
306 *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ 307 *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */
307 *p++ = htonl(8); /* attribute buffer length */ 308 *p++ = htonl(8); /* attribute buffer length */
308 p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_parent->d_inode)); 309 p = xdr_encode_hyper(p, NFS_FILEID(d_inode(dentry->d_parent)));
309 310
310 readdir->pgbase = (char *)p - (char *)start; 311 readdir->pgbase = (char *)p - (char *)start;
311 readdir->count -= readdir->pgbase; 312 readdir->count -= readdir->pgbase;
@@ -1004,7 +1005,7 @@ static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry,
1004 gfp_t gfp_mask) 1005 gfp_t gfp_mask)
1005{ 1006{
1006 struct dentry *parent = dget_parent(dentry); 1007 struct dentry *parent = dget_parent(dentry);
1007 struct inode *dir = parent->d_inode; 1008 struct inode *dir = d_inode(parent);
1008 struct nfs_server *server = NFS_SERVER(dir); 1009 struct nfs_server *server = NFS_SERVER(dir);
1009 struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); 1010 struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t);
1010 struct nfs4_opendata *p; 1011 struct nfs4_opendata *p;
@@ -1057,7 +1058,7 @@ static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry,
1057 case NFS4_OPEN_CLAIM_FH: 1058 case NFS4_OPEN_CLAIM_FH:
1058 case NFS4_OPEN_CLAIM_DELEG_CUR_FH: 1059 case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
1059 case NFS4_OPEN_CLAIM_DELEG_PREV_FH: 1060 case NFS4_OPEN_CLAIM_DELEG_PREV_FH:
1060 p->o_arg.fh = NFS_FH(dentry->d_inode); 1061 p->o_arg.fh = NFS_FH(d_inode(dentry));
1061 } 1062 }
1062 if (attrs != NULL && attrs->ia_valid != 0) { 1063 if (attrs != NULL && attrs->ia_valid != 0) {
1063 __u32 verf[2]; 1064 __u32 verf[2];
@@ -1794,7 +1795,7 @@ static const struct rpc_call_ops nfs4_open_confirm_ops = {
1794 */ 1795 */
1795static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) 1796static int _nfs4_proc_open_confirm(struct nfs4_opendata *data)
1796{ 1797{
1797 struct nfs_server *server = NFS_SERVER(data->dir->d_inode); 1798 struct nfs_server *server = NFS_SERVER(d_inode(data->dir));
1798 struct rpc_task *task; 1799 struct rpc_task *task;
1799 struct rpc_message msg = { 1800 struct rpc_message msg = {
1800 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], 1801 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM],
@@ -1951,7 +1952,7 @@ static const struct rpc_call_ops nfs4_open_ops = {
1951 1952
1952static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) 1953static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover)
1953{ 1954{
1954 struct inode *dir = data->dir->d_inode; 1955 struct inode *dir = d_inode(data->dir);
1955 struct nfs_server *server = NFS_SERVER(dir); 1956 struct nfs_server *server = NFS_SERVER(dir);
1956 struct nfs_openargs *o_arg = &data->o_arg; 1957 struct nfs_openargs *o_arg = &data->o_arg;
1957 struct nfs_openres *o_res = &data->o_res; 1958 struct nfs_openres *o_res = &data->o_res;
@@ -1998,7 +1999,7 @@ static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover)
1998 1999
1999static int _nfs4_recover_proc_open(struct nfs4_opendata *data) 2000static int _nfs4_recover_proc_open(struct nfs4_opendata *data)
2000{ 2001{
2001 struct inode *dir = data->dir->d_inode; 2002 struct inode *dir = d_inode(data->dir);
2002 struct nfs_openres *o_res = &data->o_res; 2003 struct nfs_openres *o_res = &data->o_res;
2003 int status; 2004 int status;
2004 2005
@@ -2067,7 +2068,7 @@ static int nfs4_opendata_access(struct rpc_cred *cred,
2067 */ 2068 */
2068static int _nfs4_proc_open(struct nfs4_opendata *data) 2069static int _nfs4_proc_open(struct nfs4_opendata *data)
2069{ 2070{
2070 struct inode *dir = data->dir->d_inode; 2071 struct inode *dir = d_inode(data->dir);
2071 struct nfs_server *server = NFS_SERVER(dir); 2072 struct nfs_server *server = NFS_SERVER(dir);
2072 struct nfs_openargs *o_arg = &data->o_arg; 2073 struct nfs_openargs *o_arg = &data->o_arg;
2073 struct nfs_openres *o_res = &data->o_res; 2074 struct nfs_openres *o_res = &data->o_res;
@@ -2314,7 +2315,7 @@ static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata,
2314 set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); 2315 set_bit(NFS_STATE_POSIX_LOCKS, &state->flags);
2315 2316
2316 dentry = opendata->dentry; 2317 dentry = opendata->dentry;
2317 if (dentry->d_inode == NULL) { 2318 if (d_really_is_negative(dentry)) {
2318 /* FIXME: Is this d_drop() ever needed? */ 2319 /* FIXME: Is this d_drop() ever needed? */
2319 d_drop(dentry); 2320 d_drop(dentry);
2320 dentry = d_add_unique(dentry, igrab(state->inode)); 2321 dentry = d_add_unique(dentry, igrab(state->inode));
@@ -2325,7 +2326,7 @@ static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata,
2325 ctx->dentry = dget(dentry); 2326 ctx->dentry = dget(dentry);
2326 } 2327 }
2327 nfs_set_verifier(dentry, 2328 nfs_set_verifier(dentry,
2328 nfs_save_change_attribute(opendata->dir->d_inode)); 2329 nfs_save_change_attribute(d_inode(opendata->dir)));
2329 } 2330 }
2330 2331
2331 ret = nfs4_opendata_access(sp->so_cred, opendata, state, fmode, flags); 2332 ret = nfs4_opendata_access(sp->so_cred, opendata, state, fmode, flags);
@@ -2333,7 +2334,7 @@ static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata,
2333 goto out; 2334 goto out;
2334 2335
2335 ctx->state = state; 2336 ctx->state = state;
2336 if (dentry->d_inode == state->inode) { 2337 if (d_inode(dentry) == state->inode) {
2337 nfs_inode_attach_open_context(ctx); 2338 nfs_inode_attach_open_context(ctx);
2338 if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) 2339 if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq))
2339 nfs4_schedule_stateid_recovery(server, state); 2340 nfs4_schedule_stateid_recovery(server, state);
@@ -2374,10 +2375,10 @@ static int _nfs4_do_open(struct inode *dir,
2374 status = nfs4_recover_expired_lease(server); 2375 status = nfs4_recover_expired_lease(server);
2375 if (status != 0) 2376 if (status != 0)
2376 goto err_put_state_owner; 2377 goto err_put_state_owner;
2377 if (dentry->d_inode != NULL) 2378 if (d_really_is_positive(dentry))
2378 nfs4_return_incompatible_delegation(dentry->d_inode, fmode); 2379 nfs4_return_incompatible_delegation(d_inode(dentry), fmode);
2379 status = -ENOMEM; 2380 status = -ENOMEM;
2380 if (dentry->d_inode) 2381 if (d_really_is_positive(dentry))
2381 claim = NFS4_OPEN_CLAIM_FH; 2382 claim = NFS4_OPEN_CLAIM_FH;
2382 opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr, 2383 opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr,
2383 label, claim, GFP_KERNEL); 2384 label, claim, GFP_KERNEL);
@@ -2400,8 +2401,8 @@ static int _nfs4_do_open(struct inode *dir,
2400 } 2401 }
2401 opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; 2402 opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0];
2402 } 2403 }
2403 if (dentry->d_inode != NULL) 2404 if (d_really_is_positive(dentry))
2404 opendata->state = nfs4_get_open_state(dentry->d_inode, sp); 2405 opendata->state = nfs4_get_open_state(d_inode(dentry), sp);
2405 2406
2406 status = _nfs4_open_and_get_state(opendata, fmode, flags, ctx); 2407 status = _nfs4_open_and_get_state(opendata, fmode, flags, ctx);
2407 if (status != 0) 2408 if (status != 0)
@@ -3095,16 +3096,13 @@ int nfs4_proc_get_rootfh(struct nfs_server *server, struct nfs_fh *fhandle,
3095 struct nfs_fsinfo *info, 3096 struct nfs_fsinfo *info,
3096 bool auth_probe) 3097 bool auth_probe)
3097{ 3098{
3098 int status; 3099 int status = 0;
3099 3100
3100 switch (auth_probe) { 3101 if (!auth_probe)
3101 case false:
3102 status = nfs4_lookup_root(server, fhandle, info); 3102 status = nfs4_lookup_root(server, fhandle, info);
3103 if (status != -NFS4ERR_WRONGSEC) 3103
3104 break; 3104 if (auth_probe || status == NFS4ERR_WRONGSEC)
3105 default:
3106 status = nfs4_do_find_root_sec(server, fhandle, info); 3105 status = nfs4_do_find_root_sec(server, fhandle, info);
3107 }
3108 3106
3109 if (status == 0) 3107 if (status == 0)
3110 status = nfs4_server_capabilities(server, fhandle); 3108 status = nfs4_server_capabilities(server, fhandle);
@@ -3254,7 +3252,7 @@ static int
3254nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, 3252nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr,
3255 struct iattr *sattr) 3253 struct iattr *sattr)
3256{ 3254{
3257 struct inode *inode = dentry->d_inode; 3255 struct inode *inode = d_inode(dentry);
3258 struct rpc_cred *cred = NULL; 3256 struct rpc_cred *cred = NULL;
3259 struct nfs4_state *state = NULL; 3257 struct nfs4_state *state = NULL;
3260 struct nfs4_label *label = NULL; 3258 struct nfs4_label *label = NULL;
@@ -3871,13 +3869,13 @@ static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry,
3871static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, 3869static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
3872 u64 cookie, struct page **pages, unsigned int count, int plus) 3870 u64 cookie, struct page **pages, unsigned int count, int plus)
3873{ 3871{
3874 struct inode *dir = dentry->d_inode; 3872 struct inode *dir = d_inode(dentry);
3875 struct nfs4_readdir_arg args = { 3873 struct nfs4_readdir_arg args = {
3876 .fh = NFS_FH(dir), 3874 .fh = NFS_FH(dir),
3877 .pages = pages, 3875 .pages = pages,
3878 .pgbase = 0, 3876 .pgbase = 0,
3879 .count = count, 3877 .count = count,
3880 .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask, 3878 .bitmask = NFS_SERVER(d_inode(dentry))->attr_bitmask,
3881 .plus = plus, 3879 .plus = plus,
3882 }; 3880 };
3883 struct nfs4_readdir_res res; 3881 struct nfs4_readdir_res res;
@@ -3914,8 +3912,8 @@ static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
3914 do { 3912 do {
3915 err = _nfs4_proc_readdir(dentry, cred, cookie, 3913 err = _nfs4_proc_readdir(dentry, cred, cookie,
3916 pages, count, plus); 3914 pages, count, plus);
3917 trace_nfs4_readdir(dentry->d_inode, err); 3915 trace_nfs4_readdir(d_inode(dentry), err);
3918 err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode), err, 3916 err = nfs4_handle_exception(NFS_SERVER(d_inode(dentry)), err,
3919 &exception); 3917 &exception);
3920 } while (exception.retry); 3918 } while (exception.retry);
3921 return err; 3919 return err;
@@ -4830,7 +4828,7 @@ nfs4_set_security_label(struct dentry *dentry, const void *buf, size_t buflen)
4830 struct nfs4_label ilabel, *olabel = NULL; 4828 struct nfs4_label ilabel, *olabel = NULL;
4831 struct nfs_fattr fattr; 4829 struct nfs_fattr fattr;
4832 struct rpc_cred *cred; 4830 struct rpc_cred *cred;
4833 struct inode *inode = dentry->d_inode; 4831 struct inode *inode = d_inode(dentry);
4834 int status; 4832 int status;
4835 4833
4836 if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) 4834 if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL))
@@ -5670,7 +5668,7 @@ static void nfs4_lock_done(struct rpc_task *task, void *calldata)
5670 data->rpc_status = task->tk_status; 5668 data->rpc_status = task->tk_status;
5671 switch (task->tk_status) { 5669 switch (task->tk_status) {
5672 case 0: 5670 case 0:
5673 renew_lease(NFS_SERVER(data->ctx->dentry->d_inode), 5671 renew_lease(NFS_SERVER(d_inode(data->ctx->dentry)),
5674 data->timestamp); 5672 data->timestamp);
5675 if (data->arg.new_lock) { 5673 if (data->arg.new_lock) {
5676 data->fl.fl_flags &= ~(FL_SLEEP | FL_ACCESS); 5674 data->fl.fl_flags &= ~(FL_SLEEP | FL_ACCESS);
@@ -6112,7 +6110,7 @@ static int nfs4_xattr_set_nfs4_acl(struct dentry *dentry, const char *key,
6112 if (strcmp(key, "") != 0) 6110 if (strcmp(key, "") != 0)
6113 return -EINVAL; 6111 return -EINVAL;
6114 6112
6115 return nfs4_proc_set_acl(dentry->d_inode, buf, buflen); 6113 return nfs4_proc_set_acl(d_inode(dentry), buf, buflen);
6116} 6114}
6117 6115
6118static int nfs4_xattr_get_nfs4_acl(struct dentry *dentry, const char *key, 6116static int nfs4_xattr_get_nfs4_acl(struct dentry *dentry, const char *key,
@@ -6121,7 +6119,7 @@ static int nfs4_xattr_get_nfs4_acl(struct dentry *dentry, const char *key,
6121 if (strcmp(key, "") != 0) 6119 if (strcmp(key, "") != 0)
6122 return -EINVAL; 6120 return -EINVAL;
6123 6121
6124 return nfs4_proc_get_acl(dentry->d_inode, buf, buflen); 6122 return nfs4_proc_get_acl(d_inode(dentry), buf, buflen);
6125} 6123}
6126 6124
6127static size_t nfs4_xattr_list_nfs4_acl(struct dentry *dentry, char *list, 6125static size_t nfs4_xattr_list_nfs4_acl(struct dentry *dentry, char *list,
@@ -6130,7 +6128,7 @@ static size_t nfs4_xattr_list_nfs4_acl(struct dentry *dentry, char *list,
6130{ 6128{
6131 size_t len = sizeof(XATTR_NAME_NFSV4_ACL); 6129 size_t len = sizeof(XATTR_NAME_NFSV4_ACL);
6132 6130
6133 if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode))) 6131 if (!nfs4_server_supports_acls(NFS_SERVER(d_inode(dentry))))
6134 return 0; 6132 return 0;
6135 6133
6136 if (list && len <= list_len) 6134 if (list && len <= list_len)
@@ -6158,7 +6156,7 @@ static int nfs4_xattr_get_nfs4_label(struct dentry *dentry, const char *key,
6158 void *buf, size_t buflen, int type) 6156 void *buf, size_t buflen, int type)
6159{ 6157{
6160 if (security_ismaclabel(key)) 6158 if (security_ismaclabel(key))
6161 return nfs4_get_security_label(dentry->d_inode, buf, buflen); 6159 return nfs4_get_security_label(d_inode(dentry), buf, buflen);
6162 return -EOPNOTSUPP; 6160 return -EOPNOTSUPP;
6163} 6161}
6164 6162
@@ -6168,10 +6166,10 @@ static size_t nfs4_xattr_list_nfs4_label(struct dentry *dentry, char *list,
6168{ 6166{
6169 size_t len = 0; 6167 size_t len = 0;
6170 6168
6171 if (nfs_server_capable(dentry->d_inode, NFS_CAP_SECURITY_LABEL)) { 6169 if (nfs_server_capable(d_inode(dentry), NFS_CAP_SECURITY_LABEL)) {
6172 len = security_inode_listsecurity(dentry->d_inode, NULL, 0); 6170 len = security_inode_listsecurity(d_inode(dentry), NULL, 0);
6173 if (list && len <= list_len) 6171 if (list && len <= list_len)
6174 security_inode_listsecurity(dentry->d_inode, list, len); 6172 security_inode_listsecurity(d_inode(dentry), list, len);
6175 } 6173 }
6176 return len; 6174 return len;
6177} 6175}
@@ -7944,6 +7942,8 @@ _nfs4_proc_getdeviceinfo(struct nfs_server *server,
7944{ 7942{
7945 struct nfs4_getdeviceinfo_args args = { 7943 struct nfs4_getdeviceinfo_args args = {
7946 .pdev = pdev, 7944 .pdev = pdev,
7945 .notify_types = NOTIFY_DEVICEID4_CHANGE |
7946 NOTIFY_DEVICEID4_DELETE,
7947 }; 7947 };
7948 struct nfs4_getdeviceinfo_res res = { 7948 struct nfs4_getdeviceinfo_res res = {
7949 .pdev = pdev, 7949 .pdev = pdev,
@@ -7958,6 +7958,11 @@ _nfs4_proc_getdeviceinfo(struct nfs_server *server,
7958 7958
7959 dprintk("--> %s\n", __func__); 7959 dprintk("--> %s\n", __func__);
7960 status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); 7960 status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0);
7961 if (res.notification & ~args.notify_types)
7962 dprintk("%s: unsupported notification\n", __func__);
7963 if (res.notification != args.notify_types)
7964 pdev->nocache = 1;
7965
7961 dprintk("<-- %s status=%d\n", __func__, status); 7966 dprintk("<-- %s status=%d\n", __func__, status);
7962 7967
7963 return status; 7968 return status;
diff --git a/fs/nfs/nfs4state.c b/fs/nfs/nfs4state.c
index f95e3b58bbc3..2782cfca2265 100644
--- a/fs/nfs/nfs4state.c
+++ b/fs/nfs/nfs4state.c
@@ -42,7 +42,6 @@
42#include <linux/slab.h> 42#include <linux/slab.h>
43#include <linux/fs.h> 43#include <linux/fs.h>
44#include <linux/nfs_fs.h> 44#include <linux/nfs_fs.h>
45#include <linux/nfs_idmap.h>
46#include <linux/kthread.h> 45#include <linux/kthread.h>
47#include <linux/module.h> 46#include <linux/module.h>
48#include <linux/random.h> 47#include <linux/random.h>
@@ -57,6 +56,7 @@
57#include "callback.h" 56#include "callback.h"
58#include "delegation.h" 57#include "delegation.h"
59#include "internal.h" 58#include "internal.h"
59#include "nfs4idmap.h"
60#include "nfs4session.h" 60#include "nfs4session.h"
61#include "pnfs.h" 61#include "pnfs.h"
62#include "netns.h" 62#include "netns.h"
@@ -1902,7 +1902,7 @@ static int nfs4_try_migration(struct nfs_server *server, struct rpc_cred *cred)
1902 goto out; 1902 goto out;
1903 } 1903 }
1904 1904
1905 inode = server->super->s_root->d_inode; 1905 inode = d_inode(server->super->s_root);
1906 result = nfs4_proc_get_locations(inode, locations, page, cred); 1906 result = nfs4_proc_get_locations(inode, locations, page, cred);
1907 if (result) { 1907 if (result) {
1908 dprintk("<-- %s: failed to retrieve fs_locations: %d\n", 1908 dprintk("<-- %s: failed to retrieve fs_locations: %d\n",
@@ -2021,7 +2021,7 @@ restart:
2021 2021
2022 rcu_read_unlock(); 2022 rcu_read_unlock();
2023 2023
2024 inode = server->super->s_root->d_inode; 2024 inode = d_inode(server->super->s_root);
2025 status = nfs4_proc_fsid_present(inode, cred); 2025 status = nfs4_proc_fsid_present(inode, cred);
2026 if (status != -NFS4ERR_MOVED) 2026 if (status != -NFS4ERR_MOVED)
2027 goto restart; /* wasn't this one */ 2027 goto restart; /* wasn't this one */
diff --git a/fs/nfs/nfs4super.c b/fs/nfs/nfs4super.c
index 75090feeafad..6fb7cb6b3f4b 100644
--- a/fs/nfs/nfs4super.c
+++ b/fs/nfs/nfs4super.c
@@ -3,12 +3,12 @@
3 */ 3 */
4#include <linux/init.h> 4#include <linux/init.h>
5#include <linux/module.h> 5#include <linux/module.h>
6#include <linux/nfs_idmap.h>
7#include <linux/nfs4_mount.h> 6#include <linux/nfs4_mount.h>
8#include <linux/nfs_fs.h> 7#include <linux/nfs_fs.h>
9#include "delegation.h" 8#include "delegation.h"
10#include "internal.h" 9#include "internal.h"
11#include "nfs4_fs.h" 10#include "nfs4_fs.h"
11#include "nfs4idmap.h"
12#include "dns_resolve.h" 12#include "dns_resolve.h"
13#include "pnfs.h" 13#include "pnfs.h"
14#include "nfs.h" 14#include "nfs.h"
@@ -91,10 +91,11 @@ static void nfs4_evict_inode(struct inode *inode)
91{ 91{
92 truncate_inode_pages_final(&inode->i_data); 92 truncate_inode_pages_final(&inode->i_data);
93 clear_inode(inode); 93 clear_inode(inode);
94 pnfs_return_layout(inode);
95 pnfs_destroy_layout(NFS_I(inode));
96 /* If we are holding a delegation, return it! */ 94 /* If we are holding a delegation, return it! */
97 nfs_inode_return_delegation_noreclaim(inode); 95 nfs_inode_return_delegation_noreclaim(inode);
96 /* Note that above delegreturn would trigger pnfs return-on-close */
97 pnfs_return_layout(inode);
98 pnfs_destroy_layout(NFS_I(inode));
98 /* First call standard NFS clear_inode() code */ 99 /* First call standard NFS clear_inode() code */
99 nfs_clear_inode(inode); 100 nfs_clear_inode(inode);
100} 101}
diff --git a/fs/nfs/nfs4sysctl.c b/fs/nfs/nfs4sysctl.c
index b6ebe7e445f6..0fbd3ab1be22 100644
--- a/fs/nfs/nfs4sysctl.c
+++ b/fs/nfs/nfs4sysctl.c
@@ -6,10 +6,10 @@
6 * Copyright (c) 2006 Trond Myklebust <Trond.Myklebust@netapp.com> 6 * Copyright (c) 2006 Trond Myklebust <Trond.Myklebust@netapp.com>
7 */ 7 */
8#include <linux/sysctl.h> 8#include <linux/sysctl.h>
9#include <linux/nfs_idmap.h>
10#include <linux/nfs_fs.h> 9#include <linux/nfs_fs.h>
11 10
12#include "nfs4_fs.h" 11#include "nfs4_fs.h"
12#include "nfs4idmap.h"
13#include "callback.h" 13#include "callback.h"
14 14
15static const int nfs_set_port_min = 0; 15static const int nfs_set_port_min = 0;
diff --git a/fs/nfs/nfs4trace.h b/fs/nfs/nfs4trace.h
index 1c32adbe728d..470af1a78bec 100644
--- a/fs/nfs/nfs4trace.h
+++ b/fs/nfs/nfs4trace.h
@@ -418,7 +418,7 @@ DECLARE_EVENT_CLASS(nfs4_open_event,
418 __entry->fileid = 0; 418 __entry->fileid = 0;
419 __entry->fhandle = 0; 419 __entry->fhandle = 0;
420 } 420 }
421 __entry->dir = NFS_FILEID(ctx->dentry->d_parent->d_inode); 421 __entry->dir = NFS_FILEID(d_inode(ctx->dentry->d_parent));
422 __assign_str(name, ctx->dentry->d_name.name); 422 __assign_str(name, ctx->dentry->d_name.name);
423 ), 423 ),
424 424
@@ -1110,7 +1110,7 @@ TRACE_EVENT(nfs4_layoutget,
1110 ), 1110 ),
1111 1111
1112 TP_fast_assign( 1112 TP_fast_assign(
1113 const struct inode *inode = ctx->dentry->d_inode; 1113 const struct inode *inode = d_inode(ctx->dentry);
1114 __entry->dev = inode->i_sb->s_dev; 1114 __entry->dev = inode->i_sb->s_dev;
1115 __entry->fileid = NFS_FILEID(inode); 1115 __entry->fileid = NFS_FILEID(inode);
1116 __entry->fhandle = nfs_fhandle_hash(NFS_FH(inode)); 1116 __entry->fhandle = nfs_fhandle_hash(NFS_FH(inode));
diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c
index 5c399ec41079..0aea97841d30 100644
--- a/fs/nfs/nfs4xdr.c
+++ b/fs/nfs/nfs4xdr.c
@@ -52,10 +52,10 @@
52#include <linux/nfs.h> 52#include <linux/nfs.h>
53#include <linux/nfs4.h> 53#include <linux/nfs4.h>
54#include <linux/nfs_fs.h> 54#include <linux/nfs_fs.h>
55#include <linux/nfs_idmap.h>
56 55
57#include "nfs4_fs.h" 56#include "nfs4_fs.h"
58#include "internal.h" 57#include "internal.h"
58#include "nfs4idmap.h"
59#include "nfs4session.h" 59#include "nfs4session.h"
60#include "pnfs.h" 60#include "pnfs.h"
61#include "netns.h" 61#include "netns.h"
@@ -1920,7 +1920,7 @@ encode_getdeviceinfo(struct xdr_stream *xdr,
1920 1920
1921 p = reserve_space(xdr, 4 + 4); 1921 p = reserve_space(xdr, 4 + 4);
1922 *p++ = cpu_to_be32(1); /* bitmap length */ 1922 *p++ = cpu_to_be32(1); /* bitmap length */
1923 *p++ = cpu_to_be32(NOTIFY_DEVICEID4_CHANGE | NOTIFY_DEVICEID4_DELETE); 1923 *p++ = cpu_to_be32(args->notify_types);
1924} 1924}
1925 1925
1926static void 1926static void
@@ -5753,8 +5753,9 @@ out_overflow:
5753 5753
5754#if defined(CONFIG_NFS_V4_1) 5754#if defined(CONFIG_NFS_V4_1)
5755static int decode_getdeviceinfo(struct xdr_stream *xdr, 5755static int decode_getdeviceinfo(struct xdr_stream *xdr,
5756 struct pnfs_device *pdev) 5756 struct nfs4_getdeviceinfo_res *res)
5757{ 5757{
5758 struct pnfs_device *pdev = res->pdev;
5758 __be32 *p; 5759 __be32 *p;
5759 uint32_t len, type; 5760 uint32_t len, type;
5760 int status; 5761 int status;
@@ -5802,12 +5803,7 @@ static int decode_getdeviceinfo(struct xdr_stream *xdr,
5802 if (unlikely(!p)) 5803 if (unlikely(!p))
5803 goto out_overflow; 5804 goto out_overflow;
5804 5805
5805 if (be32_to_cpup(p++) & 5806 res->notification = be32_to_cpup(p++);
5806 ~(NOTIFY_DEVICEID4_CHANGE | NOTIFY_DEVICEID4_DELETE)) {
5807 dprintk("%s: unsupported notification\n",
5808 __func__);
5809 }
5810
5811 for (i = 1; i < len; i++) { 5807 for (i = 1; i < len; i++) {
5812 if (be32_to_cpup(p++)) { 5808 if (be32_to_cpup(p++)) {
5813 dprintk("%s: unsupported notification\n", 5809 dprintk("%s: unsupported notification\n",
@@ -7061,7 +7057,7 @@ static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
7061 status = decode_sequence(xdr, &res->seq_res, rqstp); 7057 status = decode_sequence(xdr, &res->seq_res, rqstp);
7062 if (status != 0) 7058 if (status != 0)
7063 goto out; 7059 goto out;
7064 status = decode_getdeviceinfo(xdr, res->pdev); 7060 status = decode_getdeviceinfo(xdr, res);
7065out: 7061out:
7066 return status; 7062 return status;
7067} 7063}
@@ -7365,6 +7361,11 @@ nfs4_stat_to_errno(int stat)
7365 .p_name = #proc, \ 7361 .p_name = #proc, \
7366} 7362}
7367 7363
7364#define STUB(proc) \
7365[NFSPROC4_CLNT_##proc] = { \
7366 .p_name = #proc, \
7367}
7368
7368struct rpc_procinfo nfs4_procedures[] = { 7369struct rpc_procinfo nfs4_procedures[] = {
7369 PROC(READ, enc_read, dec_read), 7370 PROC(READ, enc_read, dec_read),
7370 PROC(WRITE, enc_write, dec_write), 7371 PROC(WRITE, enc_write, dec_write),
@@ -7417,6 +7418,7 @@ struct rpc_procinfo nfs4_procedures[] = {
7417 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name), 7418 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
7418 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid), 7419 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
7419 PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid), 7420 PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
7421 STUB(GETDEVICELIST),
7420 PROC(BIND_CONN_TO_SESSION, 7422 PROC(BIND_CONN_TO_SESSION,
7421 enc_bind_conn_to_session, dec_bind_conn_to_session), 7423 enc_bind_conn_to_session, dec_bind_conn_to_session),
7422 PROC(DESTROY_CLIENTID, enc_destroy_clientid, dec_destroy_clientid), 7424 PROC(DESTROY_CLIENTID, enc_destroy_clientid, dec_destroy_clientid),
diff --git a/fs/nfs/nfstrace.c b/fs/nfs/nfstrace.c
index 4eb0aead69b6..c74f7af23d77 100644
--- a/fs/nfs/nfstrace.c
+++ b/fs/nfs/nfstrace.c
@@ -7,3 +7,6 @@
7 7
8#define CREATE_TRACE_POINTS 8#define CREATE_TRACE_POINTS
9#include "nfstrace.h" 9#include "nfstrace.h"
10
11EXPORT_TRACEPOINT_SYMBOL_GPL(nfs_fsync_enter);
12EXPORT_TRACEPOINT_SYMBOL_GPL(nfs_fsync_exit);
diff --git a/fs/nfs/objlayout/objio_osd.c b/fs/nfs/objlayout/objio_osd.c
index 24e1d7403c0b..5aaed363556a 100644
--- a/fs/nfs/objlayout/objio_osd.c
+++ b/fs/nfs/objlayout/objio_osd.c
@@ -57,7 +57,7 @@ objio_free_deviceid_node(struct nfs4_deviceid_node *d)
57 57
58 dprintk("%s: free od=%p\n", __func__, de->od.od); 58 dprintk("%s: free od=%p\n", __func__, de->od.od);
59 osduld_put_device(de->od.od); 59 osduld_put_device(de->od.od);
60 kfree(de); 60 kfree_rcu(d, rcu);
61} 61}
62 62
63struct objio_segment { 63struct objio_segment {
@@ -637,6 +637,8 @@ static struct pnfs_layoutdriver_type objlayout_type = {
637 .pg_read_ops = &objio_pg_read_ops, 637 .pg_read_ops = &objio_pg_read_ops,
638 .pg_write_ops = &objio_pg_write_ops, 638 .pg_write_ops = &objio_pg_write_ops,
639 639
640 .sync = pnfs_generic_sync,
641
640 .free_deviceid_node = objio_free_deviceid_node, 642 .free_deviceid_node = objio_free_deviceid_node,
641 643
642 .encode_layoutcommit = objlayout_encode_layoutcommit, 644 .encode_layoutcommit = objlayout_encode_layoutcommit,
diff --git a/fs/nfs/pagelist.c b/fs/nfs/pagelist.c
index d57190a0d533..282b39369510 100644
--- a/fs/nfs/pagelist.c
+++ b/fs/nfs/pagelist.c
@@ -938,7 +938,7 @@ static bool nfs_can_coalesce_requests(struct nfs_page *prev,
938 if (prev) { 938 if (prev) {
939 if (!nfs_match_open_context(req->wb_context, prev->wb_context)) 939 if (!nfs_match_open_context(req->wb_context, prev->wb_context))
940 return false; 940 return false;
941 flctx = req->wb_context->dentry->d_inode->i_flctx; 941 flctx = d_inode(req->wb_context->dentry)->i_flctx;
942 if (flctx != NULL && 942 if (flctx != NULL &&
943 !(list_empty_careful(&flctx->flc_posix) && 943 !(list_empty_careful(&flctx->flc_posix) &&
944 list_empty_careful(&flctx->flc_flock)) && 944 list_empty_careful(&flctx->flc_flock)) &&
diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c
index 4f802b02fbb9..230606243be6 100644
--- a/fs/nfs/pnfs.c
+++ b/fs/nfs/pnfs.c
@@ -1090,6 +1090,7 @@ bool pnfs_roc(struct inode *ino)
1090 pnfs_get_layout_hdr(lo); /* matched in pnfs_roc_release */ 1090 pnfs_get_layout_hdr(lo); /* matched in pnfs_roc_release */
1091 spin_unlock(&ino->i_lock); 1091 spin_unlock(&ino->i_lock);
1092 pnfs_free_lseg_list(&tmp_list); 1092 pnfs_free_lseg_list(&tmp_list);
1093 pnfs_layoutcommit_inode(ino, true);
1093 return true; 1094 return true;
1094 1095
1095out_noroc: 1096out_noroc:
@@ -1104,8 +1105,10 @@ out_noroc:
1104 } 1105 }
1105 } 1106 }
1106 spin_unlock(&ino->i_lock); 1107 spin_unlock(&ino->i_lock);
1107 if (layoutreturn) 1108 if (layoutreturn) {
1109 pnfs_layoutcommit_inode(ino, true);
1108 pnfs_send_layoutreturn(lo, stateid, IOMODE_ANY, true); 1110 pnfs_send_layoutreturn(lo, stateid, IOMODE_ANY, true);
1111 }
1109 return false; 1112 return false;
1110} 1113}
1111 1114
@@ -1841,7 +1844,8 @@ void pnfs_ld_write_done(struct nfs_pgio_header *hdr)
1841{ 1844{
1842 trace_nfs4_pnfs_write(hdr, hdr->pnfs_error); 1845 trace_nfs4_pnfs_write(hdr, hdr->pnfs_error);
1843 if (!hdr->pnfs_error) { 1846 if (!hdr->pnfs_error) {
1844 pnfs_set_layoutcommit(hdr); 1847 pnfs_set_layoutcommit(hdr->inode, hdr->lseg,
1848 hdr->mds_offset + hdr->res.count);
1845 hdr->mds_ops->rpc_call_done(&hdr->task, hdr); 1849 hdr->mds_ops->rpc_call_done(&hdr->task, hdr);
1846 } else 1850 } else
1847 pnfs_ld_handle_write_error(hdr); 1851 pnfs_ld_handle_write_error(hdr);
@@ -1902,7 +1906,6 @@ static void pnfs_writehdr_free(struct nfs_pgio_header *hdr)
1902 pnfs_put_lseg(hdr->lseg); 1906 pnfs_put_lseg(hdr->lseg);
1903 nfs_pgio_header_free(hdr); 1907 nfs_pgio_header_free(hdr);
1904} 1908}
1905EXPORT_SYMBOL_GPL(pnfs_writehdr_free);
1906 1909
1907int 1910int
1908pnfs_generic_pg_writepages(struct nfs_pageio_descriptor *desc) 1911pnfs_generic_pg_writepages(struct nfs_pageio_descriptor *desc)
@@ -2032,7 +2035,6 @@ static void pnfs_readhdr_free(struct nfs_pgio_header *hdr)
2032 pnfs_put_lseg(hdr->lseg); 2035 pnfs_put_lseg(hdr->lseg);
2033 nfs_pgio_header_free(hdr); 2036 nfs_pgio_header_free(hdr);
2034} 2037}
2035EXPORT_SYMBOL_GPL(pnfs_readhdr_free);
2036 2038
2037int 2039int
2038pnfs_generic_pg_readpages(struct nfs_pageio_descriptor *desc) 2040pnfs_generic_pg_readpages(struct nfs_pageio_descriptor *desc)
@@ -2099,64 +2101,34 @@ void pnfs_set_lo_fail(struct pnfs_layout_segment *lseg)
2099EXPORT_SYMBOL_GPL(pnfs_set_lo_fail); 2101EXPORT_SYMBOL_GPL(pnfs_set_lo_fail);
2100 2102
2101void 2103void
2102pnfs_set_layoutcommit(struct nfs_pgio_header *hdr) 2104pnfs_set_layoutcommit(struct inode *inode, struct pnfs_layout_segment *lseg,
2105 loff_t end_pos)
2103{ 2106{
2104 struct inode *inode = hdr->inode;
2105 struct nfs_inode *nfsi = NFS_I(inode); 2107 struct nfs_inode *nfsi = NFS_I(inode);
2106 loff_t end_pos = hdr->mds_offset + hdr->res.count;
2107 bool mark_as_dirty = false; 2108 bool mark_as_dirty = false;
2108 2109
2109 spin_lock(&inode->i_lock); 2110 spin_lock(&inode->i_lock);
2110 if (!test_and_set_bit(NFS_INO_LAYOUTCOMMIT, &nfsi->flags)) { 2111 if (!test_and_set_bit(NFS_INO_LAYOUTCOMMIT, &nfsi->flags)) {
2111 mark_as_dirty = true;
2112 dprintk("%s: Set layoutcommit for inode %lu ",
2113 __func__, inode->i_ino);
2114 }
2115 if (!test_and_set_bit(NFS_LSEG_LAYOUTCOMMIT, &hdr->lseg->pls_flags)) {
2116 /* references matched in nfs4_layoutcommit_release */
2117 pnfs_get_lseg(hdr->lseg);
2118 }
2119 if (end_pos > nfsi->layout->plh_lwb)
2120 nfsi->layout->plh_lwb = end_pos; 2112 nfsi->layout->plh_lwb = end_pos;
2121 spin_unlock(&inode->i_lock);
2122 dprintk("%s: lseg %p end_pos %llu\n",
2123 __func__, hdr->lseg, nfsi->layout->plh_lwb);
2124
2125 /* if pnfs_layoutcommit_inode() runs between inode locks, the next one
2126 * will be a noop because NFS_INO_LAYOUTCOMMIT will not be set */
2127 if (mark_as_dirty)
2128 mark_inode_dirty_sync(inode);
2129}
2130EXPORT_SYMBOL_GPL(pnfs_set_layoutcommit);
2131
2132void pnfs_commit_set_layoutcommit(struct nfs_commit_data *data)
2133{
2134 struct inode *inode = data->inode;
2135 struct nfs_inode *nfsi = NFS_I(inode);
2136 bool mark_as_dirty = false;
2137
2138 spin_lock(&inode->i_lock);
2139 if (!test_and_set_bit(NFS_INO_LAYOUTCOMMIT, &nfsi->flags)) {
2140 mark_as_dirty = true; 2113 mark_as_dirty = true;
2141 dprintk("%s: Set layoutcommit for inode %lu ", 2114 dprintk("%s: Set layoutcommit for inode %lu ",
2142 __func__, inode->i_ino); 2115 __func__, inode->i_ino);
2143 } 2116 } else if (end_pos > nfsi->layout->plh_lwb)
2144 if (!test_and_set_bit(NFS_LSEG_LAYOUTCOMMIT, &data->lseg->pls_flags)) { 2117 nfsi->layout->plh_lwb = end_pos;
2118 if (!test_and_set_bit(NFS_LSEG_LAYOUTCOMMIT, &lseg->pls_flags)) {
2145 /* references matched in nfs4_layoutcommit_release */ 2119 /* references matched in nfs4_layoutcommit_release */
2146 pnfs_get_lseg(data->lseg); 2120 pnfs_get_lseg(lseg);
2147 } 2121 }
2148 if (data->lwb > nfsi->layout->plh_lwb)
2149 nfsi->layout->plh_lwb = data->lwb;
2150 spin_unlock(&inode->i_lock); 2122 spin_unlock(&inode->i_lock);
2151 dprintk("%s: lseg %p end_pos %llu\n", 2123 dprintk("%s: lseg %p end_pos %llu\n",
2152 __func__, data->lseg, nfsi->layout->plh_lwb); 2124 __func__, lseg, nfsi->layout->plh_lwb);
2153 2125
2154 /* if pnfs_layoutcommit_inode() runs between inode locks, the next one 2126 /* if pnfs_layoutcommit_inode() runs between inode locks, the next one
2155 * will be a noop because NFS_INO_LAYOUTCOMMIT will not be set */ 2127 * will be a noop because NFS_INO_LAYOUTCOMMIT will not be set */
2156 if (mark_as_dirty) 2128 if (mark_as_dirty)
2157 mark_inode_dirty_sync(inode); 2129 mark_inode_dirty_sync(inode);
2158} 2130}
2159EXPORT_SYMBOL_GPL(pnfs_commit_set_layoutcommit); 2131EXPORT_SYMBOL_GPL(pnfs_set_layoutcommit);
2160 2132
2161void pnfs_cleanup_layoutcommit(struct nfs4_layoutcommit_data *data) 2133void pnfs_cleanup_layoutcommit(struct nfs4_layoutcommit_data *data)
2162{ 2134{
@@ -2216,7 +2188,6 @@ pnfs_layoutcommit_inode(struct inode *inode, bool sync)
2216 pnfs_list_write_lseg(inode, &data->lseg_list); 2188 pnfs_list_write_lseg(inode, &data->lseg_list);
2217 2189
2218 end_pos = nfsi->layout->plh_lwb; 2190 end_pos = nfsi->layout->plh_lwb;
2219 nfsi->layout->plh_lwb = 0;
2220 2191
2221 nfs4_stateid_copy(&data->args.stateid, &nfsi->layout->plh_stateid); 2192 nfs4_stateid_copy(&data->args.stateid, &nfsi->layout->plh_stateid);
2222 spin_unlock(&inode->i_lock); 2193 spin_unlock(&inode->i_lock);
@@ -2233,11 +2204,11 @@ pnfs_layoutcommit_inode(struct inode *inode, bool sync)
2233 status = ld->prepare_layoutcommit(&data->args); 2204 status = ld->prepare_layoutcommit(&data->args);
2234 if (status) { 2205 if (status) {
2235 spin_lock(&inode->i_lock); 2206 spin_lock(&inode->i_lock);
2236 if (end_pos < nfsi->layout->plh_lwb) 2207 set_bit(NFS_INO_LAYOUTCOMMIT, &nfsi->flags);
2208 if (end_pos > nfsi->layout->plh_lwb)
2237 nfsi->layout->plh_lwb = end_pos; 2209 nfsi->layout->plh_lwb = end_pos;
2238 spin_unlock(&inode->i_lock); 2210 spin_unlock(&inode->i_lock);
2239 put_rpccred(data->cred); 2211 put_rpccred(data->cred);
2240 set_bit(NFS_INO_LAYOUTCOMMIT, &nfsi->flags);
2241 goto clear_layoutcommitting; 2212 goto clear_layoutcommitting;
2242 } 2213 }
2243 } 2214 }
@@ -2258,6 +2229,13 @@ clear_layoutcommitting:
2258} 2229}
2259EXPORT_SYMBOL_GPL(pnfs_layoutcommit_inode); 2230EXPORT_SYMBOL_GPL(pnfs_layoutcommit_inode);
2260 2231
2232int
2233pnfs_generic_sync(struct inode *inode, bool datasync)
2234{
2235 return pnfs_layoutcommit_inode(inode, true);
2236}
2237EXPORT_SYMBOL_GPL(pnfs_generic_sync);
2238
2261struct nfs4_threshold *pnfs_mdsthreshold_alloc(void) 2239struct nfs4_threshold *pnfs_mdsthreshold_alloc(void)
2262{ 2240{
2263 struct nfs4_threshold *thp; 2241 struct nfs4_threshold *thp;
diff --git a/fs/nfs/pnfs.h b/fs/nfs/pnfs.h
index 635f0865671c..1e6308f82fc3 100644
--- a/fs/nfs/pnfs.h
+++ b/fs/nfs/pnfs.h
@@ -155,6 +155,8 @@ struct pnfs_layoutdriver_type {
155 int how, 155 int how,
156 struct nfs_commit_info *cinfo); 156 struct nfs_commit_info *cinfo);
157 157
158 int (*sync)(struct inode *inode, bool datasync);
159
158 /* 160 /*
159 * Return PNFS_ATTEMPTED to indicate the layout code has attempted 161 * Return PNFS_ATTEMPTED to indicate the layout code has attempted
160 * I/O, else return PNFS_NOT_ATTEMPTED to fall back to normal NFS 162 * I/O, else return PNFS_NOT_ATTEMPTED to fall back to normal NFS
@@ -203,6 +205,7 @@ struct pnfs_device {
203 struct page **pages; 205 struct page **pages;
204 unsigned int pgbase; 206 unsigned int pgbase;
205 unsigned int pglen; /* reply buffer length */ 207 unsigned int pglen; /* reply buffer length */
208 unsigned char nocache : 1;/* May not be cached */
206}; 209};
207 210
208#define NFS4_PNFS_GETDEVLIST_MAXNUM 16 211#define NFS4_PNFS_GETDEVLIST_MAXNUM 16
@@ -263,10 +266,11 @@ bool pnfs_roc(struct inode *ino);
263void pnfs_roc_release(struct inode *ino); 266void pnfs_roc_release(struct inode *ino);
264void pnfs_roc_set_barrier(struct inode *ino, u32 barrier); 267void pnfs_roc_set_barrier(struct inode *ino, u32 barrier);
265bool pnfs_roc_drain(struct inode *ino, u32 *barrier, struct rpc_task *task); 268bool pnfs_roc_drain(struct inode *ino, u32 *barrier, struct rpc_task *task);
266void pnfs_set_layoutcommit(struct nfs_pgio_header *); 269void pnfs_set_layoutcommit(struct inode *, struct pnfs_layout_segment *, loff_t);
267void pnfs_commit_set_layoutcommit(struct nfs_commit_data *data);
268void pnfs_cleanup_layoutcommit(struct nfs4_layoutcommit_data *data); 270void pnfs_cleanup_layoutcommit(struct nfs4_layoutcommit_data *data);
269int pnfs_layoutcommit_inode(struct inode *inode, bool sync); 271int pnfs_layoutcommit_inode(struct inode *inode, bool sync);
272int pnfs_generic_sync(struct inode *inode, bool datasync);
273int pnfs_nfs_generic_sync(struct inode *inode, bool datasync);
270int _pnfs_return_layout(struct inode *); 274int _pnfs_return_layout(struct inode *);
271int pnfs_commit_and_return_layout(struct inode *); 275int pnfs_commit_and_return_layout(struct inode *);
272void pnfs_ld_write_done(struct nfs_pgio_header *); 276void pnfs_ld_write_done(struct nfs_pgio_header *);
@@ -291,6 +295,7 @@ void pnfs_error_mark_layout_for_return(struct inode *inode,
291enum { 295enum {
292 NFS_DEVICEID_INVALID = 0, /* set when MDS clientid recalled */ 296 NFS_DEVICEID_INVALID = 0, /* set when MDS clientid recalled */
293 NFS_DEVICEID_UNAVAILABLE, /* device temporarily unavailable */ 297 NFS_DEVICEID_UNAVAILABLE, /* device temporarily unavailable */
298 NFS_DEVICEID_NOCACHE, /* device may not be cached */
294}; 299};
295 300
296/* pnfs_dev.c */ 301/* pnfs_dev.c */
@@ -302,6 +307,7 @@ struct nfs4_deviceid_node {
302 unsigned long flags; 307 unsigned long flags;
303 unsigned long timestamp_unavailable; 308 unsigned long timestamp_unavailable;
304 struct nfs4_deviceid deviceid; 309 struct nfs4_deviceid deviceid;
310 struct rcu_head rcu;
305 atomic_t ref; 311 atomic_t ref;
306}; 312};
307 313
@@ -426,7 +432,7 @@ static inline bool
426pnfs_mark_request_commit(struct nfs_page *req, struct pnfs_layout_segment *lseg, 432pnfs_mark_request_commit(struct nfs_page *req, struct pnfs_layout_segment *lseg,
427 struct nfs_commit_info *cinfo, u32 ds_commit_idx) 433 struct nfs_commit_info *cinfo, u32 ds_commit_idx)
428{ 434{
429 struct inode *inode = req->wb_context->dentry->d_inode; 435 struct inode *inode = d_inode(req->wb_context->dentry);
430 struct pnfs_layoutdriver_type *ld = NFS_SERVER(inode)->pnfs_curr_ld; 436 struct pnfs_layoutdriver_type *ld = NFS_SERVER(inode)->pnfs_curr_ld;
431 437
432 if (lseg == NULL || ld->mark_request_commit == NULL) 438 if (lseg == NULL || ld->mark_request_commit == NULL)
@@ -438,7 +444,7 @@ pnfs_mark_request_commit(struct nfs_page *req, struct pnfs_layout_segment *lseg,
438static inline bool 444static inline bool
439pnfs_clear_request_commit(struct nfs_page *req, struct nfs_commit_info *cinfo) 445pnfs_clear_request_commit(struct nfs_page *req, struct nfs_commit_info *cinfo)
440{ 446{
441 struct inode *inode = req->wb_context->dentry->d_inode; 447 struct inode *inode = d_inode(req->wb_context->dentry);
442 struct pnfs_layoutdriver_type *ld = NFS_SERVER(inode)->pnfs_curr_ld; 448 struct pnfs_layoutdriver_type *ld = NFS_SERVER(inode)->pnfs_curr_ld;
443 449
444 if (ld == NULL || ld->clear_request_commit == NULL) 450 if (ld == NULL || ld->clear_request_commit == NULL)
@@ -486,6 +492,14 @@ pnfs_ld_read_whole_page(struct inode *inode)
486 return NFS_SERVER(inode)->pnfs_curr_ld->flags & PNFS_READ_WHOLE_PAGE; 492 return NFS_SERVER(inode)->pnfs_curr_ld->flags & PNFS_READ_WHOLE_PAGE;
487} 493}
488 494
495static inline int
496pnfs_sync_inode(struct inode *inode, bool datasync)
497{
498 if (!pnfs_enabled_sb(NFS_SERVER(inode)))
499 return 0;
500 return NFS_SERVER(inode)->pnfs_curr_ld->sync(inode, datasync);
501}
502
489static inline bool 503static inline bool
490pnfs_layoutcommit_outstanding(struct inode *inode) 504pnfs_layoutcommit_outstanding(struct inode *inode)
491{ 505{
@@ -568,6 +582,12 @@ pnfs_ld_read_whole_page(struct inode *inode)
568 return false; 582 return false;
569} 583}
570 584
585static inline int
586pnfs_sync_inode(struct inode *inode, bool datasync)
587{
588 return 0;
589}
590
571static inline bool 591static inline bool
572pnfs_roc(struct inode *ino) 592pnfs_roc(struct inode *ino)
573{ 593{
diff --git a/fs/nfs/pnfs_dev.c b/fs/nfs/pnfs_dev.c
index aa2ec0015183..2961fcd7a2df 100644
--- a/fs/nfs/pnfs_dev.c
+++ b/fs/nfs/pnfs_dev.c
@@ -149,6 +149,8 @@ nfs4_get_device_info(struct nfs_server *server,
149 */ 149 */
150 d = server->pnfs_curr_ld->alloc_deviceid_node(server, pdev, 150 d = server->pnfs_curr_ld->alloc_deviceid_node(server, pdev,
151 gfp_flags); 151 gfp_flags);
152 if (d && pdev->nocache)
153 set_bit(NFS_DEVICEID_NOCACHE, &d->flags);
152 154
153out_free_pages: 155out_free_pages:
154 for (i = 0; i < max_pages; i++) 156 for (i = 0; i < max_pages; i++)
@@ -175,8 +177,8 @@ __nfs4_find_get_deviceid(struct nfs_server *server,
175 rcu_read_lock(); 177 rcu_read_lock();
176 d = _lookup_deviceid(server->pnfs_curr_ld, server->nfs_client, id, 178 d = _lookup_deviceid(server->pnfs_curr_ld, server->nfs_client, id,
177 hash); 179 hash);
178 if (d != NULL) 180 if (d != NULL && !atomic_inc_not_zero(&d->ref))
179 atomic_inc(&d->ref); 181 d = NULL;
180 rcu_read_unlock(); 182 rcu_read_unlock();
181 return d; 183 return d;
182} 184}
@@ -235,12 +237,11 @@ nfs4_delete_deviceid(const struct pnfs_layoutdriver_type *ld,
235 return; 237 return;
236 } 238 }
237 hlist_del_init_rcu(&d->node); 239 hlist_del_init_rcu(&d->node);
240 clear_bit(NFS_DEVICEID_NOCACHE, &d->flags);
238 spin_unlock(&nfs4_deviceid_lock); 241 spin_unlock(&nfs4_deviceid_lock);
239 synchronize_rcu();
240 242
241 /* balance the initial ref set in pnfs_insert_deviceid */ 243 /* balance the initial ref set in pnfs_insert_deviceid */
242 if (atomic_dec_and_test(&d->ref)) 244 nfs4_put_deviceid_node(d);
243 d->ld->free_deviceid_node(d);
244} 245}
245EXPORT_SYMBOL_GPL(nfs4_delete_deviceid); 246EXPORT_SYMBOL_GPL(nfs4_delete_deviceid);
246 247
@@ -271,6 +272,11 @@ EXPORT_SYMBOL_GPL(nfs4_init_deviceid_node);
271bool 272bool
272nfs4_put_deviceid_node(struct nfs4_deviceid_node *d) 273nfs4_put_deviceid_node(struct nfs4_deviceid_node *d)
273{ 274{
275 if (test_bit(NFS_DEVICEID_NOCACHE, &d->flags)) {
276 if (atomic_add_unless(&d->ref, -1, 2))
277 return false;
278 nfs4_delete_deviceid(d->ld, d->nfs_client, &d->deviceid);
279 }
274 if (!atomic_dec_and_test(&d->ref)) 280 if (!atomic_dec_and_test(&d->ref))
275 return false; 281 return false;
276 d->ld->free_deviceid_node(d); 282 d->ld->free_deviceid_node(d);
@@ -314,6 +320,7 @@ _deviceid_purge_client(const struct nfs_client *clp, long hash)
314 if (d->nfs_client == clp && atomic_read(&d->ref)) { 320 if (d->nfs_client == clp && atomic_read(&d->ref)) {
315 hlist_del_init_rcu(&d->node); 321 hlist_del_init_rcu(&d->node);
316 hlist_add_head(&d->tmpnode, &tmp); 322 hlist_add_head(&d->tmpnode, &tmp);
323 clear_bit(NFS_DEVICEID_NOCACHE, &d->flags);
317 } 324 }
318 rcu_read_unlock(); 325 rcu_read_unlock();
319 spin_unlock(&nfs4_deviceid_lock); 326 spin_unlock(&nfs4_deviceid_lock);
@@ -321,12 +328,10 @@ _deviceid_purge_client(const struct nfs_client *clp, long hash)
321 if (hlist_empty(&tmp)) 328 if (hlist_empty(&tmp))
322 return; 329 return;
323 330
324 synchronize_rcu();
325 while (!hlist_empty(&tmp)) { 331 while (!hlist_empty(&tmp)) {
326 d = hlist_entry(tmp.first, struct nfs4_deviceid_node, tmpnode); 332 d = hlist_entry(tmp.first, struct nfs4_deviceid_node, tmpnode);
327 hlist_del(&d->tmpnode); 333 hlist_del(&d->tmpnode);
328 if (atomic_dec_and_test(&d->ref)) 334 nfs4_put_deviceid_node(d);
329 d->ld->free_deviceid_node(d);
330 } 335 }
331} 336}
332 337
diff --git a/fs/nfs/pnfs_nfs.c b/fs/nfs/pnfs_nfs.c
index 54e36b38fb5f..f37e25b6311c 100644
--- a/fs/nfs/pnfs_nfs.c
+++ b/fs/nfs/pnfs_nfs.c
@@ -561,7 +561,7 @@ static bool load_v3_ds_connect(void)
561 return(get_v3_ds_connect != NULL); 561 return(get_v3_ds_connect != NULL);
562} 562}
563 563
564void __exit nfs4_pnfs_v3_ds_connect_unload(void) 564void nfs4_pnfs_v3_ds_connect_unload(void)
565{ 565{
566 if (get_v3_ds_connect) { 566 if (get_v3_ds_connect) {
567 symbol_put(nfs3_set_ds_client); 567 symbol_put(nfs3_set_ds_client);
@@ -868,3 +868,13 @@ pnfs_layout_mark_request_commit(struct nfs_page *req,
868 nfs_request_add_commit_list(req, list, cinfo); 868 nfs_request_add_commit_list(req, list, cinfo);
869} 869}
870EXPORT_SYMBOL_GPL(pnfs_layout_mark_request_commit); 870EXPORT_SYMBOL_GPL(pnfs_layout_mark_request_commit);
871
872int
873pnfs_nfs_generic_sync(struct inode *inode, bool datasync)
874{
875 if (datasync)
876 return 0;
877 return pnfs_layoutcommit_inode(inode, true);
878}
879EXPORT_SYMBOL_GPL(pnfs_nfs_generic_sync);
880
diff --git a/fs/nfs/proc.c b/fs/nfs/proc.c
index c63189acd052..b417bbcd9704 100644
--- a/fs/nfs/proc.c
+++ b/fs/nfs/proc.c
@@ -118,7 +118,7 @@ static int
118nfs_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, 118nfs_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr,
119 struct iattr *sattr) 119 struct iattr *sattr)
120{ 120{
121 struct inode *inode = dentry->d_inode; 121 struct inode *inode = d_inode(dentry);
122 struct nfs_sattrargs arg = { 122 struct nfs_sattrargs arg = {
123 .fh = NFS_FH(inode), 123 .fh = NFS_FH(inode),
124 .sattr = sattr 124 .sattr = sattr
@@ -487,7 +487,7 @@ static int
487nfs_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, 487nfs_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
488 u64 cookie, struct page **pages, unsigned int count, int plus) 488 u64 cookie, struct page **pages, unsigned int count, int plus)
489{ 489{
490 struct inode *dir = dentry->d_inode; 490 struct inode *dir = d_inode(dentry);
491 struct nfs_readdirargs arg = { 491 struct nfs_readdirargs arg = {
492 .fh = NFS_FH(dir), 492 .fh = NFS_FH(dir),
493 .cookie = cookie, 493 .cookie = cookie,
diff --git a/fs/nfs/read.c b/fs/nfs/read.c
index b8f5c63f77b2..ae0ff7a11b40 100644
--- a/fs/nfs/read.c
+++ b/fs/nfs/read.c
@@ -117,7 +117,7 @@ int nfs_readpage_async(struct nfs_open_context *ctx, struct inode *inode,
117 117
118static void nfs_readpage_release(struct nfs_page *req) 118static void nfs_readpage_release(struct nfs_page *req)
119{ 119{
120 struct inode *inode = req->wb_context->dentry->d_inode; 120 struct inode *inode = d_inode(req->wb_context->dentry);
121 121
122 dprintk("NFS: read done (%s/%llu %d@%lld)\n", inode->i_sb->s_id, 122 dprintk("NFS: read done (%s/%llu %d@%lld)\n", inode->i_sb->s_id,
123 (unsigned long long)NFS_FILEID(inode), req->wb_bytes, 123 (unsigned long long)NFS_FILEID(inode), req->wb_bytes,
@@ -284,7 +284,7 @@ int nfs_readpage(struct file *file, struct page *page)
284 dprintk("NFS: nfs_readpage (%p %ld@%lu)\n", 284 dprintk("NFS: nfs_readpage (%p %ld@%lu)\n",
285 page, PAGE_CACHE_SIZE, page_file_index(page)); 285 page, PAGE_CACHE_SIZE, page_file_index(page));
286 nfs_inc_stats(inode, NFSIOS_VFSREADPAGE); 286 nfs_inc_stats(inode, NFSIOS_VFSREADPAGE);
287 nfs_inc_stats(inode, NFSIOS_READPAGES); 287 nfs_add_stats(inode, NFSIOS_READPAGES, 1);
288 288
289 /* 289 /*
290 * Try to flush any pending writes to the file.. 290 * Try to flush any pending writes to the file..
diff --git a/fs/nfs/super.c b/fs/nfs/super.c
index 322b2de02988..f175b833b6ba 100644
--- a/fs/nfs/super.c
+++ b/fs/nfs/super.c
@@ -43,7 +43,6 @@
43#include <linux/seq_file.h> 43#include <linux/seq_file.h>
44#include <linux/mount.h> 44#include <linux/mount.h>
45#include <linux/namei.h> 45#include <linux/namei.h>
46#include <linux/nfs_idmap.h>
47#include <linux/vfs.h> 46#include <linux/vfs.h>
48#include <linux/inet.h> 47#include <linux/inet.h>
49#include <linux/in6.h> 48#include <linux/in6.h>
@@ -433,7 +432,7 @@ int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
433 struct nfs_server *server = NFS_SB(dentry->d_sb); 432 struct nfs_server *server = NFS_SB(dentry->d_sb);
434 unsigned char blockbits; 433 unsigned char blockbits;
435 unsigned long blockres; 434 unsigned long blockres;
436 struct nfs_fh *fh = NFS_FH(dentry->d_inode); 435 struct nfs_fh *fh = NFS_FH(d_inode(dentry));
437 struct nfs_fsstat res; 436 struct nfs_fsstat res;
438 int error = -ENOMEM; 437 int error = -ENOMEM;
439 438
@@ -447,7 +446,7 @@ int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
447 446
448 pd_dentry = dget_parent(dentry); 447 pd_dentry = dget_parent(dentry);
449 if (pd_dentry != NULL) { 448 if (pd_dentry != NULL) {
450 nfs_zap_caches(pd_dentry->d_inode); 449 nfs_zap_caches(d_inode(pd_dentry));
451 dput(pd_dentry); 450 dput(pd_dentry);
452 } 451 }
453 } 452 }
@@ -2193,7 +2192,7 @@ nfs_compare_remount_data(struct nfs_server *nfss,
2193 data->version != nfss->nfs_client->rpc_ops->version || 2192 data->version != nfss->nfs_client->rpc_ops->version ||
2194 data->minorversion != nfss->nfs_client->cl_minorversion || 2193 data->minorversion != nfss->nfs_client->cl_minorversion ||
2195 data->retrans != nfss->client->cl_timeout->to_retries || 2194 data->retrans != nfss->client->cl_timeout->to_retries ||
2196 data->selected_flavor != nfss->client->cl_auth->au_flavor || 2195 !nfs_auth_info_match(&data->auth_info, nfss->client->cl_auth->au_flavor) ||
2197 data->acregmin != nfss->acregmin / HZ || 2196 data->acregmin != nfss->acregmin / HZ ||
2198 data->acregmax != nfss->acregmax / HZ || 2197 data->acregmax != nfss->acregmax / HZ ||
2199 data->acdirmin != nfss->acdirmin / HZ || 2198 data->acdirmin != nfss->acdirmin / HZ ||
@@ -2241,7 +2240,6 @@ nfs_remount(struct super_block *sb, int *flags, char *raw_data)
2241 data->wsize = nfss->wsize; 2240 data->wsize = nfss->wsize;
2242 data->retrans = nfss->client->cl_timeout->to_retries; 2241 data->retrans = nfss->client->cl_timeout->to_retries;
2243 data->selected_flavor = nfss->client->cl_auth->au_flavor; 2242 data->selected_flavor = nfss->client->cl_auth->au_flavor;
2244 data->auth_info = nfss->auth_info;
2245 data->acregmin = nfss->acregmin / HZ; 2243 data->acregmin = nfss->acregmin / HZ;
2246 data->acregmax = nfss->acregmax / HZ; 2244 data->acregmax = nfss->acregmax / HZ;
2247 data->acdirmin = nfss->acdirmin / HZ; 2245 data->acdirmin = nfss->acdirmin / HZ;
@@ -2526,7 +2524,7 @@ int nfs_clone_sb_security(struct super_block *s, struct dentry *mntroot,
2526 struct nfs_mount_info *mount_info) 2524 struct nfs_mount_info *mount_info)
2527{ 2525{
2528 /* clone any lsm security options from the parent to the new sb */ 2526 /* clone any lsm security options from the parent to the new sb */
2529 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) 2527 if (d_inode(mntroot)->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops)
2530 return -ESTALE; 2528 return -ESTALE;
2531 return security_sb_clone_mnt_opts(mount_info->cloned->sb, s); 2529 return security_sb_clone_mnt_opts(mount_info->cloned->sb, s);
2532} 2530}
diff --git a/fs/nfs/symlink.c b/fs/nfs/symlink.c
index 05c9e02f4153..2d56200655fe 100644
--- a/fs/nfs/symlink.c
+++ b/fs/nfs/symlink.c
@@ -45,7 +45,7 @@ error:
45 45
46static void *nfs_follow_link(struct dentry *dentry, struct nameidata *nd) 46static void *nfs_follow_link(struct dentry *dentry, struct nameidata *nd)
47{ 47{
48 struct inode *inode = dentry->d_inode; 48 struct inode *inode = d_inode(dentry);
49 struct page *page; 49 struct page *page;
50 void *err; 50 void *err;
51 51
diff --git a/fs/nfs/unlink.c b/fs/nfs/unlink.c
index de54129336c6..fa538b2ba251 100644
--- a/fs/nfs/unlink.c
+++ b/fs/nfs/unlink.c
@@ -143,7 +143,7 @@ static int nfs_do_call_unlink(struct dentry *parent, struct inode *dir, struct n
143 nfs_free_dname(data); 143 nfs_free_dname(data);
144 ret = nfs_copy_dname(alias, data); 144 ret = nfs_copy_dname(alias, data);
145 spin_lock(&alias->d_lock); 145 spin_lock(&alias->d_lock);
146 if (ret == 0 && alias->d_inode != NULL && 146 if (ret == 0 && d_really_is_positive(alias) &&
147 !(alias->d_flags & DCACHE_NFSFS_RENAMED)) { 147 !(alias->d_flags & DCACHE_NFSFS_RENAMED)) {
148 devname_garbage = alias->d_fsdata; 148 devname_garbage = alias->d_fsdata;
149 alias->d_fsdata = data; 149 alias->d_fsdata = data;
@@ -190,7 +190,7 @@ static int nfs_call_unlink(struct dentry *dentry, struct nfs_unlinkdata *data)
190 parent = dget_parent(dentry); 190 parent = dget_parent(dentry);
191 if (parent == NULL) 191 if (parent == NULL)
192 goto out_free; 192 goto out_free;
193 dir = parent->d_inode; 193 dir = d_inode(parent);
194 /* Non-exclusive lock protects against concurrent lookup() calls */ 194 /* Non-exclusive lock protects against concurrent lookup() calls */
195 spin_lock(&dir->i_lock); 195 spin_lock(&dir->i_lock);
196 if (atomic_inc_not_zero(&NFS_I(dir)->silly_count) == 0) { 196 if (atomic_inc_not_zero(&NFS_I(dir)->silly_count) == 0) {
@@ -210,21 +210,21 @@ out_free:
210 210
211void nfs_wait_on_sillyrename(struct dentry *dentry) 211void nfs_wait_on_sillyrename(struct dentry *dentry)
212{ 212{
213 struct nfs_inode *nfsi = NFS_I(dentry->d_inode); 213 struct nfs_inode *nfsi = NFS_I(d_inode(dentry));
214 214
215 wait_event(nfsi->waitqueue, atomic_read(&nfsi->silly_count) <= 1); 215 wait_event(nfsi->waitqueue, atomic_read(&nfsi->silly_count) <= 1);
216} 216}
217 217
218void nfs_block_sillyrename(struct dentry *dentry) 218void nfs_block_sillyrename(struct dentry *dentry)
219{ 219{
220 struct nfs_inode *nfsi = NFS_I(dentry->d_inode); 220 struct nfs_inode *nfsi = NFS_I(d_inode(dentry));
221 221
222 wait_event(nfsi->waitqueue, atomic_cmpxchg(&nfsi->silly_count, 1, 0) == 1); 222 wait_event(nfsi->waitqueue, atomic_cmpxchg(&nfsi->silly_count, 1, 0) == 1);
223} 223}
224 224
225void nfs_unblock_sillyrename(struct dentry *dentry) 225void nfs_unblock_sillyrename(struct dentry *dentry)
226{ 226{
227 struct inode *dir = dentry->d_inode; 227 struct inode *dir = d_inode(dentry);
228 struct nfs_inode *nfsi = NFS_I(dir); 228 struct nfs_inode *nfsi = NFS_I(dir);
229 struct nfs_unlinkdata *data; 229 struct nfs_unlinkdata *data;
230 230
@@ -367,8 +367,8 @@ static void nfs_async_rename_release(void *calldata)
367 struct nfs_renamedata *data = calldata; 367 struct nfs_renamedata *data = calldata;
368 struct super_block *sb = data->old_dir->i_sb; 368 struct super_block *sb = data->old_dir->i_sb;
369 369
370 if (data->old_dentry->d_inode) 370 if (d_really_is_positive(data->old_dentry))
371 nfs_mark_for_revalidate(data->old_dentry->d_inode); 371 nfs_mark_for_revalidate(d_inode(data->old_dentry));
372 372
373 dput(data->old_dentry); 373 dput(data->old_dentry);
374 dput(data->new_dentry); 374 dput(data->new_dentry);
@@ -529,10 +529,10 @@ nfs_sillyrename(struct inode *dir, struct dentry *dentry)
529 if (dentry->d_flags & DCACHE_NFSFS_RENAMED) 529 if (dentry->d_flags & DCACHE_NFSFS_RENAMED)
530 goto out; 530 goto out;
531 531
532 fileid = NFS_FILEID(dentry->d_inode); 532 fileid = NFS_FILEID(d_inode(dentry));
533 533
534 /* Return delegation in anticipation of the rename */ 534 /* Return delegation in anticipation of the rename */
535 NFS_PROTO(dentry->d_inode)->return_delegation(dentry->d_inode); 535 NFS_PROTO(d_inode(dentry))->return_delegation(d_inode(dentry));
536 536
537 sdentry = NULL; 537 sdentry = NULL;
538 do { 538 do {
@@ -554,7 +554,7 @@ nfs_sillyrename(struct inode *dir, struct dentry *dentry)
554 */ 554 */
555 if (IS_ERR(sdentry)) 555 if (IS_ERR(sdentry))
556 goto out; 556 goto out;
557 } while (sdentry->d_inode != NULL); /* need negative lookup */ 557 } while (d_inode(sdentry) != NULL); /* need negative lookup */
558 558
559 /* queue unlink first. Can't do this from rpc_release as it 559 /* queue unlink first. Can't do this from rpc_release as it
560 * has to allocate memory 560 * has to allocate memory
diff --git a/fs/nfs/write.c b/fs/nfs/write.c
index 759931088094..d12a4be613a5 100644
--- a/fs/nfs/write.c
+++ b/fs/nfs/write.c
@@ -580,7 +580,7 @@ static int nfs_do_writepage(struct page *page, struct writeback_control *wbc, st
580 int ret; 580 int ret;
581 581
582 nfs_inc_stats(inode, NFSIOS_VFSWRITEPAGE); 582 nfs_inc_stats(inode, NFSIOS_VFSWRITEPAGE);
583 nfs_inc_stats(inode, NFSIOS_WRITEPAGES); 583 nfs_add_stats(inode, NFSIOS_WRITEPAGES, 1);
584 584
585 nfs_pageio_cond_complete(pgio, page_file_index(page)); 585 nfs_pageio_cond_complete(pgio, page_file_index(page));
586 ret = nfs_page_async_flush(pgio, page, wbc->sync_mode == WB_SYNC_NONE); 586 ret = nfs_page_async_flush(pgio, page, wbc->sync_mode == WB_SYNC_NONE);
@@ -702,7 +702,7 @@ static void nfs_inode_add_request(struct inode *inode, struct nfs_page *req)
702 */ 702 */
703static void nfs_inode_remove_request(struct nfs_page *req) 703static void nfs_inode_remove_request(struct nfs_page *req)
704{ 704{
705 struct inode *inode = req->wb_context->dentry->d_inode; 705 struct inode *inode = d_inode(req->wb_context->dentry);
706 struct nfs_inode *nfsi = NFS_I(inode); 706 struct nfs_inode *nfsi = NFS_I(inode);
707 struct nfs_page *head; 707 struct nfs_page *head;
708 708
@@ -861,7 +861,7 @@ static void
861nfs_clear_request_commit(struct nfs_page *req) 861nfs_clear_request_commit(struct nfs_page *req)
862{ 862{
863 if (test_bit(PG_CLEAN, &req->wb_flags)) { 863 if (test_bit(PG_CLEAN, &req->wb_flags)) {
864 struct inode *inode = req->wb_context->dentry->d_inode; 864 struct inode *inode = d_inode(req->wb_context->dentry);
865 struct nfs_commit_info cinfo; 865 struct nfs_commit_info cinfo;
866 866
867 nfs_init_cinfo_from_inode(&cinfo, inode); 867 nfs_init_cinfo_from_inode(&cinfo, inode);
@@ -1591,7 +1591,7 @@ void nfs_init_commit(struct nfs_commit_data *data,
1591 struct nfs_commit_info *cinfo) 1591 struct nfs_commit_info *cinfo)
1592{ 1592{
1593 struct nfs_page *first = nfs_list_entry(head->next); 1593 struct nfs_page *first = nfs_list_entry(head->next);
1594 struct inode *inode = first->wb_context->dentry->d_inode; 1594 struct inode *inode = d_inode(first->wb_context->dentry);
1595 1595
1596 /* Set up the RPC argument and reply structs 1596 /* Set up the RPC argument and reply structs
1597 * NB: take care not to mess about with data->commit et al. */ 1597 * NB: take care not to mess about with data->commit et al. */
@@ -1690,7 +1690,7 @@ static void nfs_commit_release_pages(struct nfs_commit_data *data)
1690 1690
1691 dprintk("NFS: commit (%s/%llu %d@%lld)", 1691 dprintk("NFS: commit (%s/%llu %d@%lld)",
1692 req->wb_context->dentry->d_sb->s_id, 1692 req->wb_context->dentry->d_sb->s_id,
1693 (unsigned long long)NFS_FILEID(req->wb_context->dentry->d_inode), 1693 (unsigned long long)NFS_FILEID(d_inode(req->wb_context->dentry)),
1694 req->wb_bytes, 1694 req->wb_bytes,
1695 (long long)req_offset(req)); 1695 (long long)req_offset(req));
1696 if (status < 0) { 1696 if (status < 0) {
@@ -1840,17 +1840,16 @@ EXPORT_SYMBOL_GPL(nfs_write_inode);
1840 */ 1840 */
1841int nfs_wb_all(struct inode *inode) 1841int nfs_wb_all(struct inode *inode)
1842{ 1842{
1843 struct writeback_control wbc = {
1844 .sync_mode = WB_SYNC_ALL,
1845 .nr_to_write = LONG_MAX,
1846 .range_start = 0,
1847 .range_end = LLONG_MAX,
1848 };
1849 int ret; 1843 int ret;
1850 1844
1851 trace_nfs_writeback_inode_enter(inode); 1845 trace_nfs_writeback_inode_enter(inode);
1852 1846
1853 ret = sync_inode(inode, &wbc); 1847 ret = filemap_write_and_wait(inode->i_mapping);
1848 if (!ret) {
1849 ret = nfs_commit_inode(inode, FLUSH_SYNC);
1850 if (!ret)
1851 pnfs_sync_inode(inode, true);
1852 }
1854 1853
1855 trace_nfs_writeback_inode_exit(inode, ret); 1854 trace_nfs_writeback_inode_exit(inode, ret);
1856 return ret; 1855 return ret;
diff --git a/fs/nfsd/Kconfig b/fs/nfsd/Kconfig
index fc2d108f5272..a0b77fc1bd39 100644
--- a/fs/nfsd/Kconfig
+++ b/fs/nfsd/Kconfig
@@ -108,7 +108,7 @@ config NFSD_V4_SECURITY_LABEL
108 108
109config NFSD_FAULT_INJECTION 109config NFSD_FAULT_INJECTION
110 bool "NFS server manual fault injection" 110 bool "NFS server manual fault injection"
111 depends on NFSD_V4 && DEBUG_KERNEL 111 depends on NFSD_V4 && DEBUG_KERNEL && DEBUG_FS
112 help 112 help
113 This option enables support for manually injecting faults 113 This option enables support for manually injecting faults
114 into the NFS server. This is intended to be used for 114 into the NFS server. This is intended to be used for
diff --git a/fs/nfsd/export.c b/fs/nfsd/export.c
index c3e3b6e55ae2..f79521a59747 100644
--- a/fs/nfsd/export.c
+++ b/fs/nfsd/export.c
@@ -599,7 +599,7 @@ static int svc_export_parse(struct cache_detail *cd, char *mesg, int mlen)
599 goto out4; 599 goto out4;
600 } 600 }
601 601
602 err = check_export(exp.ex_path.dentry->d_inode, &exp.ex_flags, 602 err = check_export(d_inode(exp.ex_path.dentry), &exp.ex_flags,
603 exp.ex_uuid); 603 exp.ex_uuid);
604 if (err) 604 if (err)
605 goto out4; 605 goto out4;
@@ -691,8 +691,7 @@ static int svc_export_match(struct cache_head *a, struct cache_head *b)
691 struct svc_export *orig = container_of(a, struct svc_export, h); 691 struct svc_export *orig = container_of(a, struct svc_export, h);
692 struct svc_export *new = container_of(b, struct svc_export, h); 692 struct svc_export *new = container_of(b, struct svc_export, h);
693 return orig->ex_client == new->ex_client && 693 return orig->ex_client == new->ex_client &&
694 orig->ex_path.dentry == new->ex_path.dentry && 694 path_equal(&orig->ex_path, &new->ex_path);
695 orig->ex_path.mnt == new->ex_path.mnt;
696} 695}
697 696
698static void svc_export_init(struct cache_head *cnew, struct cache_head *citem) 697static void svc_export_init(struct cache_head *cnew, struct cache_head *citem)
@@ -891,7 +890,7 @@ exp_rootfh(struct net *net, struct auth_domain *clp, char *name,
891 printk("nfsd: exp_rootfh path not found %s", name); 890 printk("nfsd: exp_rootfh path not found %s", name);
892 return err; 891 return err;
893 } 892 }
894 inode = path.dentry->d_inode; 893 inode = d_inode(path.dentry);
895 894
896 dprintk("nfsd: exp_rootfh(%s [%p] %s:%s/%ld)\n", 895 dprintk("nfsd: exp_rootfh(%s [%p] %s:%s/%ld)\n",
897 name, path.dentry, clp->name, 896 name, path.dentry, clp->name,
@@ -1159,6 +1158,7 @@ static struct flags {
1159 { NFSEXP_NOSUBTREECHECK, {"no_subtree_check", ""}}, 1158 { NFSEXP_NOSUBTREECHECK, {"no_subtree_check", ""}},
1160 { NFSEXP_NOAUTHNLM, {"insecure_locks", ""}}, 1159 { NFSEXP_NOAUTHNLM, {"insecure_locks", ""}},
1161 { NFSEXP_V4ROOT, {"v4root", ""}}, 1160 { NFSEXP_V4ROOT, {"v4root", ""}},
1161 { NFSEXP_PNFS, {"pnfs", ""}},
1162 { 0, {"", ""}} 1162 { 0, {"", ""}}
1163}; 1163};
1164 1164
diff --git a/fs/nfsd/nfs2acl.c b/fs/nfsd/nfs2acl.c
index ac54ea60b3f6..d54701f6dc78 100644
--- a/fs/nfsd/nfs2acl.c
+++ b/fs/nfsd/nfs2acl.c
@@ -42,7 +42,7 @@ static __be32 nfsacld_proc_getacl(struct svc_rqst * rqstp,
42 if (nfserr) 42 if (nfserr)
43 RETURN_STATUS(nfserr); 43 RETURN_STATUS(nfserr);
44 44
45 inode = fh->fh_dentry->d_inode; 45 inode = d_inode(fh->fh_dentry);
46 46
47 if (argp->mask & ~(NFS_ACL|NFS_ACLCNT|NFS_DFACL|NFS_DFACLCNT)) 47 if (argp->mask & ~(NFS_ACL|NFS_ACLCNT|NFS_DFACL|NFS_DFACLCNT))
48 RETURN_STATUS(nfserr_inval); 48 RETURN_STATUS(nfserr_inval);
@@ -103,7 +103,7 @@ static __be32 nfsacld_proc_setacl(struct svc_rqst * rqstp,
103 if (nfserr) 103 if (nfserr)
104 goto out; 104 goto out;
105 105
106 inode = fh->fh_dentry->d_inode; 106 inode = d_inode(fh->fh_dentry);
107 if (!IS_POSIXACL(inode) || !inode->i_op->set_acl) { 107 if (!IS_POSIXACL(inode) || !inode->i_op->set_acl) {
108 error = -EOPNOTSUPP; 108 error = -EOPNOTSUPP;
109 goto out_errno; 109 goto out_errno;
@@ -266,9 +266,9 @@ static int nfsaclsvc_encode_getaclres(struct svc_rqst *rqstp, __be32 *p,
266 * nfsd_dispatch actually ensures the following cannot happen. 266 * nfsd_dispatch actually ensures the following cannot happen.
267 * However, it seems fragile to depend on that. 267 * However, it seems fragile to depend on that.
268 */ 268 */
269 if (dentry == NULL || dentry->d_inode == NULL) 269 if (dentry == NULL || d_really_is_negative(dentry))
270 return 0; 270 return 0;
271 inode = dentry->d_inode; 271 inode = d_inode(dentry);
272 272
273 p = nfs2svc_encode_fattr(rqstp, p, &resp->fh, &resp->stat); 273 p = nfs2svc_encode_fattr(rqstp, p, &resp->fh, &resp->stat);
274 *p++ = htonl(resp->mask); 274 *p++ = htonl(resp->mask);
diff --git a/fs/nfsd/nfs3acl.c b/fs/nfsd/nfs3acl.c
index 34cbbab6abd7..882b1a14bc3e 100644
--- a/fs/nfsd/nfs3acl.c
+++ b/fs/nfsd/nfs3acl.c
@@ -39,7 +39,7 @@ static __be32 nfsd3_proc_getacl(struct svc_rqst * rqstp,
39 if (nfserr) 39 if (nfserr)
40 RETURN_STATUS(nfserr); 40 RETURN_STATUS(nfserr);
41 41
42 inode = fh->fh_dentry->d_inode; 42 inode = d_inode(fh->fh_dentry);
43 43
44 if (argp->mask & ~(NFS_ACL|NFS_ACLCNT|NFS_DFACL|NFS_DFACLCNT)) 44 if (argp->mask & ~(NFS_ACL|NFS_ACLCNT|NFS_DFACL|NFS_DFACLCNT))
45 RETURN_STATUS(nfserr_inval); 45 RETURN_STATUS(nfserr_inval);
@@ -94,7 +94,7 @@ static __be32 nfsd3_proc_setacl(struct svc_rqst * rqstp,
94 if (nfserr) 94 if (nfserr)
95 goto out; 95 goto out;
96 96
97 inode = fh->fh_dentry->d_inode; 97 inode = d_inode(fh->fh_dentry);
98 if (!IS_POSIXACL(inode) || !inode->i_op->set_acl) { 98 if (!IS_POSIXACL(inode) || !inode->i_op->set_acl) {
99 error = -EOPNOTSUPP; 99 error = -EOPNOTSUPP;
100 goto out_errno; 100 goto out_errno;
@@ -174,8 +174,8 @@ static int nfs3svc_encode_getaclres(struct svc_rqst *rqstp, __be32 *p,
174 struct dentry *dentry = resp->fh.fh_dentry; 174 struct dentry *dentry = resp->fh.fh_dentry;
175 175
176 p = nfs3svc_encode_post_op_attr(rqstp, p, &resp->fh); 176 p = nfs3svc_encode_post_op_attr(rqstp, p, &resp->fh);
177 if (resp->status == 0 && dentry && dentry->d_inode) { 177 if (resp->status == 0 && dentry && d_really_is_positive(dentry)) {
178 struct inode *inode = dentry->d_inode; 178 struct inode *inode = d_inode(dentry);
179 struct kvec *head = rqstp->rq_res.head; 179 struct kvec *head = rqstp->rq_res.head;
180 unsigned int base; 180 unsigned int base;
181 int n; 181 int n;
diff --git a/fs/nfsd/nfs3proc.c b/fs/nfsd/nfs3proc.c
index 12f2aab4f614..7b755b7f785c 100644
--- a/fs/nfsd/nfs3proc.c
+++ b/fs/nfsd/nfs3proc.c
@@ -166,7 +166,7 @@ nfsd3_proc_read(struct svc_rqst *rqstp, struct nfsd3_readargs *argp,
166 rqstp->rq_vec, argp->vlen, 166 rqstp->rq_vec, argp->vlen,
167 &resp->count); 167 &resp->count);
168 if (nfserr == 0) { 168 if (nfserr == 0) {
169 struct inode *inode = resp->fh.fh_dentry->d_inode; 169 struct inode *inode = d_inode(resp->fh.fh_dentry);
170 170
171 resp->eof = (argp->offset + resp->count) >= inode->i_size; 171 resp->eof = (argp->offset + resp->count) >= inode->i_size;
172 } 172 }
@@ -551,7 +551,7 @@ nfsd3_proc_fsinfo(struct svc_rqst * rqstp, struct nfsd_fhandle *argp,
551 * different read/write sizes for file systems known to have 551 * different read/write sizes for file systems known to have
552 * problems with large blocks */ 552 * problems with large blocks */
553 if (nfserr == 0) { 553 if (nfserr == 0) {
554 struct super_block *sb = argp->fh.fh_dentry->d_inode->i_sb; 554 struct super_block *sb = d_inode(argp->fh.fh_dentry)->i_sb;
555 555
556 /* Note that we don't care for remote fs's here */ 556 /* Note that we don't care for remote fs's here */
557 if (sb->s_magic == MSDOS_SUPER_MAGIC) { 557 if (sb->s_magic == MSDOS_SUPER_MAGIC) {
@@ -587,7 +587,7 @@ nfsd3_proc_pathconf(struct svc_rqst * rqstp, struct nfsd_fhandle *argp,
587 nfserr = fh_verify(rqstp, &argp->fh, 0, NFSD_MAY_NOP); 587 nfserr = fh_verify(rqstp, &argp->fh, 0, NFSD_MAY_NOP);
588 588
589 if (nfserr == 0) { 589 if (nfserr == 0) {
590 struct super_block *sb = argp->fh.fh_dentry->d_inode->i_sb; 590 struct super_block *sb = d_inode(argp->fh.fh_dentry)->i_sb;
591 591
592 /* Note that we don't care for remote fs's here */ 592 /* Note that we don't care for remote fs's here */
593 switch (sb->s_magic) { 593 switch (sb->s_magic) {
diff --git a/fs/nfsd/nfs3xdr.c b/fs/nfsd/nfs3xdr.c
index 39c5eb3ad33a..e4b2b4322553 100644
--- a/fs/nfsd/nfs3xdr.c
+++ b/fs/nfsd/nfs3xdr.c
@@ -146,7 +146,7 @@ static __be32 *encode_fsid(__be32 *p, struct svc_fh *fhp)
146 default: 146 default:
147 case FSIDSOURCE_DEV: 147 case FSIDSOURCE_DEV:
148 p = xdr_encode_hyper(p, (u64)huge_encode_dev 148 p = xdr_encode_hyper(p, (u64)huge_encode_dev
149 (fhp->fh_dentry->d_inode->i_sb->s_dev)); 149 (d_inode(fhp->fh_dentry)->i_sb->s_dev));
150 break; 150 break;
151 case FSIDSOURCE_FSID: 151 case FSIDSOURCE_FSID:
152 p = xdr_encode_hyper(p, (u64) fhp->fh_export->ex_fsid); 152 p = xdr_encode_hyper(p, (u64) fhp->fh_export->ex_fsid);
@@ -203,14 +203,14 @@ static __be32 *
203encode_post_op_attr(struct svc_rqst *rqstp, __be32 *p, struct svc_fh *fhp) 203encode_post_op_attr(struct svc_rqst *rqstp, __be32 *p, struct svc_fh *fhp)
204{ 204{
205 struct dentry *dentry = fhp->fh_dentry; 205 struct dentry *dentry = fhp->fh_dentry;
206 if (dentry && dentry->d_inode) { 206 if (dentry && d_really_is_positive(dentry)) {
207 __be32 err; 207 __be32 err;
208 struct kstat stat; 208 struct kstat stat;
209 209
210 err = fh_getattr(fhp, &stat); 210 err = fh_getattr(fhp, &stat);
211 if (!err) { 211 if (!err) {
212 *p++ = xdr_one; /* attributes follow */ 212 *p++ = xdr_one; /* attributes follow */
213 lease_get_mtime(dentry->d_inode, &stat.mtime); 213 lease_get_mtime(d_inode(dentry), &stat.mtime);
214 return encode_fattr3(rqstp, p, fhp, &stat); 214 return encode_fattr3(rqstp, p, fhp, &stat);
215 } 215 }
216 } 216 }
@@ -233,7 +233,7 @@ encode_wcc_data(struct svc_rqst *rqstp, __be32 *p, struct svc_fh *fhp)
233{ 233{
234 struct dentry *dentry = fhp->fh_dentry; 234 struct dentry *dentry = fhp->fh_dentry;
235 235
236 if (dentry && dentry->d_inode && fhp->fh_post_saved) { 236 if (dentry && d_really_is_positive(dentry) && fhp->fh_post_saved) {
237 if (fhp->fh_pre_saved) { 237 if (fhp->fh_pre_saved) {
238 *p++ = xdr_one; 238 *p++ = xdr_one;
239 p = xdr_encode_hyper(p, (u64) fhp->fh_pre_size); 239 p = xdr_encode_hyper(p, (u64) fhp->fh_pre_size);
@@ -260,11 +260,11 @@ void fill_post_wcc(struct svc_fh *fhp)
260 printk("nfsd: inode locked twice during operation.\n"); 260 printk("nfsd: inode locked twice during operation.\n");
261 261
262 err = fh_getattr(fhp, &fhp->fh_post_attr); 262 err = fh_getattr(fhp, &fhp->fh_post_attr);
263 fhp->fh_post_change = fhp->fh_dentry->d_inode->i_version; 263 fhp->fh_post_change = d_inode(fhp->fh_dentry)->i_version;
264 if (err) { 264 if (err) {
265 fhp->fh_post_saved = 0; 265 fhp->fh_post_saved = 0;
266 /* Grab the ctime anyway - set_change_info might use it */ 266 /* Grab the ctime anyway - set_change_info might use it */
267 fhp->fh_post_attr.ctime = fhp->fh_dentry->d_inode->i_ctime; 267 fhp->fh_post_attr.ctime = d_inode(fhp->fh_dentry)->i_ctime;
268 } else 268 } else
269 fhp->fh_post_saved = 1; 269 fhp->fh_post_saved = 1;
270} 270}
@@ -628,7 +628,7 @@ nfs3svc_encode_attrstat(struct svc_rqst *rqstp, __be32 *p,
628 struct nfsd3_attrstat *resp) 628 struct nfsd3_attrstat *resp)
629{ 629{
630 if (resp->status == 0) { 630 if (resp->status == 0) {
631 lease_get_mtime(resp->fh.fh_dentry->d_inode, 631 lease_get_mtime(d_inode(resp->fh.fh_dentry),
632 &resp->stat.mtime); 632 &resp->stat.mtime);
633 p = encode_fattr3(rqstp, p, &resp->fh, &resp->stat); 633 p = encode_fattr3(rqstp, p, &resp->fh, &resp->stat);
634 } 634 }
@@ -828,7 +828,7 @@ compose_entry_fh(struct nfsd3_readdirres *cd, struct svc_fh *fhp,
828 return rv; 828 return rv;
829 if (d_mountpoint(dchild)) 829 if (d_mountpoint(dchild))
830 goto out; 830 goto out;
831 if (!dchild->d_inode) 831 if (d_really_is_negative(dchild))
832 goto out; 832 goto out;
833 rv = fh_compose(fhp, exp, dchild, &cd->fh); 833 rv = fh_compose(fhp, exp, dchild, &cd->fh);
834out: 834out:
diff --git a/fs/nfsd/nfs4acl.c b/fs/nfsd/nfs4acl.c
index 59fd76651781..67242bf7c6cc 100644
--- a/fs/nfsd/nfs4acl.c
+++ b/fs/nfsd/nfs4acl.c
@@ -139,7 +139,7 @@ int
139nfsd4_get_nfs4_acl(struct svc_rqst *rqstp, struct dentry *dentry, 139nfsd4_get_nfs4_acl(struct svc_rqst *rqstp, struct dentry *dentry,
140 struct nfs4_acl **acl) 140 struct nfs4_acl **acl)
141{ 141{
142 struct inode *inode = dentry->d_inode; 142 struct inode *inode = d_inode(dentry);
143 int error = 0; 143 int error = 0;
144 struct posix_acl *pacl = NULL, *dpacl = NULL; 144 struct posix_acl *pacl = NULL, *dpacl = NULL;
145 unsigned int flags = 0; 145 unsigned int flags = 0;
@@ -499,43 +499,13 @@ static inline void add_to_mask(struct posix_acl_state *state, struct posix_ace_s
499 state->mask.allow |= astate->allow; 499 state->mask.allow |= astate->allow;
500} 500}
501 501
502/*
503 * Certain bits (SYNCHRONIZE, DELETE, WRITE_OWNER, READ/WRITE_NAMED_ATTRS,
504 * READ_ATTRIBUTES, READ_ACL) are currently unenforceable and don't translate
505 * to traditional read/write/execute permissions.
506 *
507 * It's problematic to reject acls that use certain mode bits, because it
508 * places the burden on users to learn the rules about which bits one
509 * particular server sets, without giving the user a lot of help--we return an
510 * error that could mean any number of different things. To make matters
511 * worse, the problematic bits might be introduced by some application that's
512 * automatically mapping from some other acl model.
513 *
514 * So wherever possible we accept anything, possibly erring on the side of
515 * denying more permissions than necessary.
516 *
517 * However we do reject *explicit* DENY's of a few bits representing
518 * permissions we could never deny:
519 */
520
521static inline int check_deny(u32 mask, int isowner)
522{
523 if (mask & (NFS4_ACE_READ_ATTRIBUTES | NFS4_ACE_READ_ACL))
524 return -EINVAL;
525 if (!isowner)
526 return 0;
527 if (mask & (NFS4_ACE_WRITE_ATTRIBUTES | NFS4_ACE_WRITE_ACL))
528 return -EINVAL;
529 return 0;
530}
531
532static struct posix_acl * 502static struct posix_acl *
533posix_state_to_acl(struct posix_acl_state *state, unsigned int flags) 503posix_state_to_acl(struct posix_acl_state *state, unsigned int flags)
534{ 504{
535 struct posix_acl_entry *pace; 505 struct posix_acl_entry *pace;
536 struct posix_acl *pacl; 506 struct posix_acl *pacl;
537 int nace; 507 int nace;
538 int i, error = 0; 508 int i;
539 509
540 /* 510 /*
541 * ACLs with no ACEs are treated differently in the inheritable 511 * ACLs with no ACEs are treated differently in the inheritable
@@ -560,17 +530,11 @@ posix_state_to_acl(struct posix_acl_state *state, unsigned int flags)
560 530
561 pace = pacl->a_entries; 531 pace = pacl->a_entries;
562 pace->e_tag = ACL_USER_OBJ; 532 pace->e_tag = ACL_USER_OBJ;
563 error = check_deny(state->owner.deny, 1);
564 if (error)
565 goto out_err;
566 low_mode_from_nfs4(state->owner.allow, &pace->e_perm, flags); 533 low_mode_from_nfs4(state->owner.allow, &pace->e_perm, flags);
567 534
568 for (i=0; i < state->users->n; i++) { 535 for (i=0; i < state->users->n; i++) {
569 pace++; 536 pace++;
570 pace->e_tag = ACL_USER; 537 pace->e_tag = ACL_USER;
571 error = check_deny(state->users->aces[i].perms.deny, 0);
572 if (error)
573 goto out_err;
574 low_mode_from_nfs4(state->users->aces[i].perms.allow, 538 low_mode_from_nfs4(state->users->aces[i].perms.allow,
575 &pace->e_perm, flags); 539 &pace->e_perm, flags);
576 pace->e_uid = state->users->aces[i].uid; 540 pace->e_uid = state->users->aces[i].uid;
@@ -579,18 +543,12 @@ posix_state_to_acl(struct posix_acl_state *state, unsigned int flags)
579 543
580 pace++; 544 pace++;
581 pace->e_tag = ACL_GROUP_OBJ; 545 pace->e_tag = ACL_GROUP_OBJ;
582 error = check_deny(state->group.deny, 0);
583 if (error)
584 goto out_err;
585 low_mode_from_nfs4(state->group.allow, &pace->e_perm, flags); 546 low_mode_from_nfs4(state->group.allow, &pace->e_perm, flags);
586 add_to_mask(state, &state->group); 547 add_to_mask(state, &state->group);
587 548
588 for (i=0; i < state->groups->n; i++) { 549 for (i=0; i < state->groups->n; i++) {
589 pace++; 550 pace++;
590 pace->e_tag = ACL_GROUP; 551 pace->e_tag = ACL_GROUP;
591 error = check_deny(state->groups->aces[i].perms.deny, 0);
592 if (error)
593 goto out_err;
594 low_mode_from_nfs4(state->groups->aces[i].perms.allow, 552 low_mode_from_nfs4(state->groups->aces[i].perms.allow,
595 &pace->e_perm, flags); 553 &pace->e_perm, flags);
596 pace->e_gid = state->groups->aces[i].gid; 554 pace->e_gid = state->groups->aces[i].gid;
@@ -605,15 +563,9 @@ posix_state_to_acl(struct posix_acl_state *state, unsigned int flags)
605 563
606 pace++; 564 pace++;
607 pace->e_tag = ACL_OTHER; 565 pace->e_tag = ACL_OTHER;
608 error = check_deny(state->other.deny, 0);
609 if (error)
610 goto out_err;
611 low_mode_from_nfs4(state->other.allow, &pace->e_perm, flags); 566 low_mode_from_nfs4(state->other.allow, &pace->e_perm, flags);
612 567
613 return pacl; 568 return pacl;
614out_err:
615 posix_acl_release(pacl);
616 return ERR_PTR(error);
617} 569}
618 570
619static inline void allow_bits(struct posix_ace_state *astate, u32 mask) 571static inline void allow_bits(struct posix_ace_state *astate, u32 mask)
@@ -828,7 +780,7 @@ nfsd4_set_nfs4_acl(struct svc_rqst *rqstp, struct svc_fh *fhp,
828 return error; 780 return error;
829 781
830 dentry = fhp->fh_dentry; 782 dentry = fhp->fh_dentry;
831 inode = dentry->d_inode; 783 inode = d_inode(dentry);
832 784
833 if (!inode->i_op->set_acl || !IS_POSIXACL(inode)) 785 if (!inode->i_op->set_acl || !IS_POSIXACL(inode))
834 return nfserr_attrnotsupp; 786 return nfserr_attrnotsupp;
diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
index 92b9d97aff4f..864e2003e8de 100644
--- a/fs/nfsd/nfs4proc.c
+++ b/fs/nfsd/nfs4proc.c
@@ -52,7 +52,7 @@
52static inline void 52static inline void
53nfsd4_security_inode_setsecctx(struct svc_fh *resfh, struct xdr_netobj *label, u32 *bmval) 53nfsd4_security_inode_setsecctx(struct svc_fh *resfh, struct xdr_netobj *label, u32 *bmval)
54{ 54{
55 struct inode *inode = resfh->fh_dentry->d_inode; 55 struct inode *inode = d_inode(resfh->fh_dentry);
56 int status; 56 int status;
57 57
58 mutex_lock(&inode->i_mutex); 58 mutex_lock(&inode->i_mutex);
@@ -110,7 +110,7 @@ check_attr_support(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
110 * in current environment or not. 110 * in current environment or not.
111 */ 111 */
112 if (bmval[0] & FATTR4_WORD0_ACL) { 112 if (bmval[0] & FATTR4_WORD0_ACL) {
113 if (!IS_POSIXACL(dentry->d_inode)) 113 if (!IS_POSIXACL(d_inode(dentry)))
114 return nfserr_attrnotsupp; 114 return nfserr_attrnotsupp;
115 } 115 }
116 116
@@ -209,7 +209,7 @@ do_open_permission(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfs
209 209
210static __be32 nfsd_check_obj_isreg(struct svc_fh *fh) 210static __be32 nfsd_check_obj_isreg(struct svc_fh *fh)
211{ 211{
212 umode_t mode = fh->fh_dentry->d_inode->i_mode; 212 umode_t mode = d_inode(fh->fh_dentry)->i_mode;
213 213
214 if (S_ISREG(mode)) 214 if (S_ISREG(mode))
215 return nfs_ok; 215 return nfs_ok;
@@ -470,7 +470,7 @@ out:
470 fh_put(resfh); 470 fh_put(resfh);
471 kfree(resfh); 471 kfree(resfh);
472 } 472 }
473 nfsd4_cleanup_open_state(cstate, open, status); 473 nfsd4_cleanup_open_state(cstate, open);
474 nfsd4_bump_seqid(cstate, status); 474 nfsd4_bump_seqid(cstate, status);
475 return status; 475 return status;
476} 476}
@@ -881,7 +881,7 @@ nfsd4_secinfo(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
881 &exp, &dentry); 881 &exp, &dentry);
882 if (err) 882 if (err)
883 return err; 883 return err;
884 if (dentry->d_inode == NULL) { 884 if (d_really_is_negative(dentry)) {
885 exp_put(exp); 885 exp_put(exp);
886 err = nfserr_noent; 886 err = nfserr_noent;
887 } else 887 } else
@@ -1030,6 +1030,8 @@ nfsd4_fallocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1030 dprintk("NFSD: nfsd4_fallocate: couldn't process stateid!\n"); 1030 dprintk("NFSD: nfsd4_fallocate: couldn't process stateid!\n");
1031 return status; 1031 return status;
1032 } 1032 }
1033 if (!file)
1034 return nfserr_bad_stateid;
1033 1035
1034 status = nfsd4_vfs_fallocate(rqstp, &cstate->current_fh, file, 1036 status = nfsd4_vfs_fallocate(rqstp, &cstate->current_fh, file,
1035 fallocate->falloc_offset, 1037 fallocate->falloc_offset,
@@ -1069,6 +1071,8 @@ nfsd4_seek(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1069 dprintk("NFSD: nfsd4_seek: couldn't process stateid!\n"); 1071 dprintk("NFSD: nfsd4_seek: couldn't process stateid!\n");
1070 return status; 1072 return status;
1071 } 1073 }
1074 if (!file)
1075 return nfserr_bad_stateid;
1072 1076
1073 switch (seek->seek_whence) { 1077 switch (seek->seek_whence) {
1074 case NFS4_CONTENT_DATA: 1078 case NFS4_CONTENT_DATA:
@@ -1308,7 +1312,7 @@ nfsd4_layoutget(struct svc_rqst *rqstp,
1308 if (atomic_read(&ls->ls_stid.sc_file->fi_lo_recalls)) 1312 if (atomic_read(&ls->ls_stid.sc_file->fi_lo_recalls))
1309 goto out_put_stid; 1313 goto out_put_stid;
1310 1314
1311 nfserr = ops->proc_layoutget(current_fh->fh_dentry->d_inode, 1315 nfserr = ops->proc_layoutget(d_inode(current_fh->fh_dentry),
1312 current_fh, lgp); 1316 current_fh, lgp);
1313 if (nfserr) 1317 if (nfserr)
1314 goto out_put_stid; 1318 goto out_put_stid;
@@ -1342,7 +1346,7 @@ nfsd4_layoutcommit(struct svc_rqst *rqstp,
1342 ops = nfsd4_layout_verify(current_fh->fh_export, lcp->lc_layout_type); 1346 ops = nfsd4_layout_verify(current_fh->fh_export, lcp->lc_layout_type);
1343 if (!ops) 1347 if (!ops)
1344 goto out; 1348 goto out;
1345 inode = current_fh->fh_dentry->d_inode; 1349 inode = d_inode(current_fh->fh_dentry);
1346 1350
1347 nfserr = nfserr_inval; 1351 nfserr = nfserr_inval;
1348 if (new_size <= seg->offset) { 1352 if (new_size <= seg->offset) {
@@ -1815,7 +1819,7 @@ static inline u32 nfsd4_getattr_rsize(struct svc_rqst *rqstp,
1815 bmap0 &= ~FATTR4_WORD0_FILEHANDLE; 1819 bmap0 &= ~FATTR4_WORD0_FILEHANDLE;
1816 } 1820 }
1817 if (bmap2 & FATTR4_WORD2_SECURITY_LABEL) { 1821 if (bmap2 & FATTR4_WORD2_SECURITY_LABEL) {
1818 ret += NFSD4_MAX_SEC_LABEL_LEN + 12; 1822 ret += NFS4_MAXLABELLEN + 12;
1819 bmap2 &= ~FATTR4_WORD2_SECURITY_LABEL; 1823 bmap2 &= ~FATTR4_WORD2_SECURITY_LABEL;
1820 } 1824 }
1821 /* 1825 /*
@@ -2282,13 +2286,13 @@ static struct nfsd4_operation nfsd4_ops[] = {
2282 .op_func = (nfsd4op_func)nfsd4_allocate, 2286 .op_func = (nfsd4op_func)nfsd4_allocate,
2283 .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, 2287 .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
2284 .op_name = "OP_ALLOCATE", 2288 .op_name = "OP_ALLOCATE",
2285 .op_rsize_bop = (nfsd4op_rsize)nfsd4_write_rsize, 2289 .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
2286 }, 2290 },
2287 [OP_DEALLOCATE] = { 2291 [OP_DEALLOCATE] = {
2288 .op_func = (nfsd4op_func)nfsd4_deallocate, 2292 .op_func = (nfsd4op_func)nfsd4_deallocate,
2289 .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, 2293 .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
2290 .op_name = "OP_DEALLOCATE", 2294 .op_name = "OP_DEALLOCATE",
2291 .op_rsize_bop = (nfsd4op_rsize)nfsd4_write_rsize, 2295 .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
2292 }, 2296 },
2293 [OP_SEEK] = { 2297 [OP_SEEK] = {
2294 .op_func = (nfsd4op_func)nfsd4_seek, 2298 .op_func = (nfsd4op_func)nfsd4_seek,
diff --git a/fs/nfsd/nfs4recover.c b/fs/nfsd/nfs4recover.c
index 1c307f02baa8..d88ea7b9a85c 100644
--- a/fs/nfsd/nfs4recover.c
+++ b/fs/nfsd/nfs4recover.c
@@ -192,14 +192,14 @@ nfsd4_create_clid_dir(struct nfs4_client *clp)
192 192
193 dir = nn->rec_file->f_path.dentry; 193 dir = nn->rec_file->f_path.dentry;
194 /* lock the parent */ 194 /* lock the parent */
195 mutex_lock(&dir->d_inode->i_mutex); 195 mutex_lock(&d_inode(dir)->i_mutex);
196 196
197 dentry = lookup_one_len(dname, dir, HEXDIR_LEN-1); 197 dentry = lookup_one_len(dname, dir, HEXDIR_LEN-1);
198 if (IS_ERR(dentry)) { 198 if (IS_ERR(dentry)) {
199 status = PTR_ERR(dentry); 199 status = PTR_ERR(dentry);
200 goto out_unlock; 200 goto out_unlock;
201 } 201 }
202 if (dentry->d_inode) 202 if (d_really_is_positive(dentry))
203 /* 203 /*
204 * In the 4.1 case, where we're called from 204 * In the 4.1 case, where we're called from
205 * reclaim_complete(), records from the previous reboot 205 * reclaim_complete(), records from the previous reboot
@@ -209,11 +209,11 @@ nfsd4_create_clid_dir(struct nfs4_client *clp)
209 * as well be forgiving and just succeed silently. 209 * as well be forgiving and just succeed silently.
210 */ 210 */
211 goto out_put; 211 goto out_put;
212 status = vfs_mkdir(dir->d_inode, dentry, S_IRWXU); 212 status = vfs_mkdir(d_inode(dir), dentry, S_IRWXU);
213out_put: 213out_put:
214 dput(dentry); 214 dput(dentry);
215out_unlock: 215out_unlock:
216 mutex_unlock(&dir->d_inode->i_mutex); 216 mutex_unlock(&d_inode(dir)->i_mutex);
217 if (status == 0) { 217 if (status == 0) {
218 if (nn->in_grace) { 218 if (nn->in_grace) {
219 crp = nfs4_client_to_reclaim(dname, nn); 219 crp = nfs4_client_to_reclaim(dname, nn);
@@ -285,7 +285,7 @@ nfsd4_list_rec_dir(recdir_func *f, struct nfsd_net *nn)
285 } 285 }
286 286
287 status = iterate_dir(nn->rec_file, &ctx.ctx); 287 status = iterate_dir(nn->rec_file, &ctx.ctx);
288 mutex_lock_nested(&dir->d_inode->i_mutex, I_MUTEX_PARENT); 288 mutex_lock_nested(&d_inode(dir)->i_mutex, I_MUTEX_PARENT);
289 while (!list_empty(&ctx.names)) { 289 while (!list_empty(&ctx.names)) {
290 struct name_list *entry; 290 struct name_list *entry;
291 entry = list_entry(ctx.names.next, struct name_list, list); 291 entry = list_entry(ctx.names.next, struct name_list, list);
@@ -302,7 +302,7 @@ nfsd4_list_rec_dir(recdir_func *f, struct nfsd_net *nn)
302 list_del(&entry->list); 302 list_del(&entry->list);
303 kfree(entry); 303 kfree(entry);
304 } 304 }
305 mutex_unlock(&dir->d_inode->i_mutex); 305 mutex_unlock(&d_inode(dir)->i_mutex);
306 nfs4_reset_creds(original_cred); 306 nfs4_reset_creds(original_cred);
307 return status; 307 return status;
308} 308}
@@ -316,20 +316,20 @@ nfsd4_unlink_clid_dir(char *name, int namlen, struct nfsd_net *nn)
316 dprintk("NFSD: nfsd4_unlink_clid_dir. name %.*s\n", namlen, name); 316 dprintk("NFSD: nfsd4_unlink_clid_dir. name %.*s\n", namlen, name);
317 317
318 dir = nn->rec_file->f_path.dentry; 318 dir = nn->rec_file->f_path.dentry;
319 mutex_lock_nested(&dir->d_inode->i_mutex, I_MUTEX_PARENT); 319 mutex_lock_nested(&d_inode(dir)->i_mutex, I_MUTEX_PARENT);
320 dentry = lookup_one_len(name, dir, namlen); 320 dentry = lookup_one_len(name, dir, namlen);
321 if (IS_ERR(dentry)) { 321 if (IS_ERR(dentry)) {
322 status = PTR_ERR(dentry); 322 status = PTR_ERR(dentry);
323 goto out_unlock; 323 goto out_unlock;
324 } 324 }
325 status = -ENOENT; 325 status = -ENOENT;
326 if (!dentry->d_inode) 326 if (d_really_is_negative(dentry))
327 goto out; 327 goto out;
328 status = vfs_rmdir(dir->d_inode, dentry); 328 status = vfs_rmdir(d_inode(dir), dentry);
329out: 329out:
330 dput(dentry); 330 dput(dentry);
331out_unlock: 331out_unlock:
332 mutex_unlock(&dir->d_inode->i_mutex); 332 mutex_unlock(&d_inode(dir)->i_mutex);
333 return status; 333 return status;
334} 334}
335 335
@@ -385,7 +385,7 @@ purge_old(struct dentry *parent, struct dentry *child, struct nfsd_net *nn)
385 if (nfs4_has_reclaimed_state(child->d_name.name, nn)) 385 if (nfs4_has_reclaimed_state(child->d_name.name, nn))
386 return 0; 386 return 0;
387 387
388 status = vfs_rmdir(parent->d_inode, child); 388 status = vfs_rmdir(d_inode(parent), child);
389 if (status) 389 if (status)
390 printk("failed to remove client recovery directory %pd\n", 390 printk("failed to remove client recovery directory %pd\n",
391 child); 391 child);
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index 326a545ea7b2..38f2d7abe3a7 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -1139,7 +1139,7 @@ hash_sessionid(struct nfs4_sessionid *sessionid)
1139 return sid->sequence % SESSION_HASH_SIZE; 1139 return sid->sequence % SESSION_HASH_SIZE;
1140} 1140}
1141 1141
1142#ifdef NFSD_DEBUG 1142#ifdef CONFIG_SUNRPC_DEBUG
1143static inline void 1143static inline void
1144dump_sessionid(const char *fn, struct nfs4_sessionid *sessionid) 1144dump_sessionid(const char *fn, struct nfs4_sessionid *sessionid)
1145{ 1145{
@@ -4049,7 +4049,6 @@ nfsd4_process_open2(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nf
4049 status = nfserr_bad_stateid; 4049 status = nfserr_bad_stateid;
4050 if (nfsd4_is_deleg_cur(open)) 4050 if (nfsd4_is_deleg_cur(open))
4051 goto out; 4051 goto out;
4052 status = nfserr_jukebox;
4053 } 4052 }
4054 4053
4055 /* 4054 /*
@@ -4118,7 +4117,7 @@ out:
4118} 4117}
4119 4118
4120void nfsd4_cleanup_open_state(struct nfsd4_compound_state *cstate, 4119void nfsd4_cleanup_open_state(struct nfsd4_compound_state *cstate,
4121 struct nfsd4_open *open, __be32 status) 4120 struct nfsd4_open *open)
4122{ 4121{
4123 if (open->op_openowner) { 4122 if (open->op_openowner) {
4124 struct nfs4_stateowner *so = &open->op_openowner->oo_owner; 4123 struct nfs4_stateowner *so = &open->op_openowner->oo_owner;
@@ -4473,7 +4472,7 @@ nfs4_preprocess_stateid_op(struct net *net, struct nfsd4_compound_state *cstate,
4473 struct nfs4_ol_stateid *stp = NULL; 4472 struct nfs4_ol_stateid *stp = NULL;
4474 struct nfs4_delegation *dp = NULL; 4473 struct nfs4_delegation *dp = NULL;
4475 struct svc_fh *current_fh = &cstate->current_fh; 4474 struct svc_fh *current_fh = &cstate->current_fh;
4476 struct inode *ino = current_fh->fh_dentry->d_inode; 4475 struct inode *ino = d_inode(current_fh->fh_dentry);
4477 struct nfsd_net *nn = net_generic(net, nfsd_net_id); 4476 struct nfsd_net *nn = net_generic(net, nfsd_net_id);
4478 struct file *file = NULL; 4477 struct file *file = NULL;
4479 __be32 status; 4478 __be32 status;
@@ -5171,7 +5170,7 @@ lookup_or_create_lock_state(struct nfsd4_compound_state *cstate,
5171 struct nfs4_file *fi = ost->st_stid.sc_file; 5170 struct nfs4_file *fi = ost->st_stid.sc_file;
5172 struct nfs4_openowner *oo = openowner(ost->st_stateowner); 5171 struct nfs4_openowner *oo = openowner(ost->st_stateowner);
5173 struct nfs4_client *cl = oo->oo_owner.so_client; 5172 struct nfs4_client *cl = oo->oo_owner.so_client;
5174 struct inode *inode = cstate->current_fh.fh_dentry->d_inode; 5173 struct inode *inode = d_inode(cstate->current_fh.fh_dentry);
5175 struct nfs4_lockowner *lo; 5174 struct nfs4_lockowner *lo;
5176 unsigned int strhashval; 5175 unsigned int strhashval;
5177 5176
diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index 5fb7e78169a6..158badf945df 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -424,7 +424,7 @@ nfsd4_decode_fattr(struct nfsd4_compoundargs *argp, u32 *bmval,
424 len += 4; 424 len += 4;
425 dummy32 = be32_to_cpup(p++); 425 dummy32 = be32_to_cpup(p++);
426 READ_BUF(dummy32); 426 READ_BUF(dummy32);
427 if (dummy32 > NFSD4_MAX_SEC_LABEL_LEN) 427 if (dummy32 > NFS4_MAXLABELLEN)
428 return nfserr_badlabel; 428 return nfserr_badlabel;
429 len += (XDR_QUADLEN(dummy32) << 2); 429 len += (XDR_QUADLEN(dummy32) << 2);
430 READMEM(buf, dummy32); 430 READMEM(buf, dummy32);
@@ -2020,7 +2020,7 @@ static __be32 nfsd4_encode_path(struct xdr_stream *xdr,
2020 * dentries/path components in an array. 2020 * dentries/path components in an array.
2021 */ 2021 */
2022 for (;;) { 2022 for (;;) {
2023 if (cur.dentry == root->dentry && cur.mnt == root->mnt) 2023 if (path_equal(&cur, root))
2024 break; 2024 break;
2025 if (cur.dentry == cur.mnt->mnt_root) { 2025 if (cur.dentry == cur.mnt->mnt_root) {
2026 if (follow_up(&cur)) 2026 if (follow_up(&cur))
@@ -2292,7 +2292,7 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
2292#ifdef CONFIG_NFSD_V4_SECURITY_LABEL 2292#ifdef CONFIG_NFSD_V4_SECURITY_LABEL
2293 if ((bmval[2] & FATTR4_WORD2_SECURITY_LABEL) || 2293 if ((bmval[2] & FATTR4_WORD2_SECURITY_LABEL) ||
2294 bmval[0] & FATTR4_WORD0_SUPPORTED_ATTRS) { 2294 bmval[0] & FATTR4_WORD0_SUPPORTED_ATTRS) {
2295 err = security_inode_getsecctx(dentry->d_inode, 2295 err = security_inode_getsecctx(d_inode(dentry),
2296 &context, &contextlen); 2296 &context, &contextlen);
2297 contextsupport = (err == 0); 2297 contextsupport = (err == 0);
2298 if (bmval2 & FATTR4_WORD2_SECURITY_LABEL) { 2298 if (bmval2 & FATTR4_WORD2_SECURITY_LABEL) {
@@ -2384,7 +2384,7 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
2384 p = xdr_reserve_space(xdr, 8); 2384 p = xdr_reserve_space(xdr, 8);
2385 if (!p) 2385 if (!p)
2386 goto out_resource; 2386 goto out_resource;
2387 p = encode_change(p, &stat, dentry->d_inode); 2387 p = encode_change(p, &stat, d_inode(dentry));
2388 } 2388 }
2389 if (bmval0 & FATTR4_WORD0_SIZE) { 2389 if (bmval0 & FATTR4_WORD0_SIZE) {
2390 p = xdr_reserve_space(xdr, 8); 2390 p = xdr_reserve_space(xdr, 8);
@@ -2807,7 +2807,7 @@ nfsd4_encode_dirent_fattr(struct xdr_stream *xdr, struct nfsd4_readdir *cd,
2807 dentry = lookup_one_len(name, cd->rd_fhp->fh_dentry, namlen); 2807 dentry = lookup_one_len(name, cd->rd_fhp->fh_dentry, namlen);
2808 if (IS_ERR(dentry)) 2808 if (IS_ERR(dentry))
2809 return nfserrno(PTR_ERR(dentry)); 2809 return nfserrno(PTR_ERR(dentry));
2810 if (!dentry->d_inode) { 2810 if (d_really_is_negative(dentry)) {
2811 /* 2811 /*
2812 * nfsd_buffered_readdir drops the i_mutex between 2812 * nfsd_buffered_readdir drops the i_mutex between
2813 * readdir and calling this callback, leaving a window 2813 * readdir and calling this callback, leaving a window
@@ -3324,7 +3324,7 @@ static __be32 nfsd4_encode_splice_read(
3324 } 3324 }
3325 3325
3326 eof = (read->rd_offset + maxcount >= 3326 eof = (read->rd_offset + maxcount >=
3327 read->rd_fhp->fh_dentry->d_inode->i_size); 3327 d_inode(read->rd_fhp->fh_dentry)->i_size);
3328 3328
3329 *(p++) = htonl(eof); 3329 *(p++) = htonl(eof);
3330 *(p++) = htonl(maxcount); 3330 *(p++) = htonl(maxcount);
@@ -3401,7 +3401,7 @@ static __be32 nfsd4_encode_readv(struct nfsd4_compoundres *resp,
3401 xdr_truncate_encode(xdr, starting_len + 8 + ((maxcount+3)&~3)); 3401 xdr_truncate_encode(xdr, starting_len + 8 + ((maxcount+3)&~3));
3402 3402
3403 eof = (read->rd_offset + maxcount >= 3403 eof = (read->rd_offset + maxcount >=
3404 read->rd_fhp->fh_dentry->d_inode->i_size); 3404 d_inode(read->rd_fhp->fh_dentry)->i_size);
3405 3405
3406 tmp = htonl(eof); 3406 tmp = htonl(eof);
3407 write_bytes_to_xdr_buf(xdr->buf, starting_len , &tmp, 4); 3407 write_bytes_to_xdr_buf(xdr->buf, starting_len , &tmp, 4);
@@ -3422,6 +3422,7 @@ nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr,
3422 unsigned long maxcount; 3422 unsigned long maxcount;
3423 struct xdr_stream *xdr = &resp->xdr; 3423 struct xdr_stream *xdr = &resp->xdr;
3424 struct file *file = read->rd_filp; 3424 struct file *file = read->rd_filp;
3425 struct svc_fh *fhp = read->rd_fhp;
3425 int starting_len = xdr->buf->len; 3426 int starting_len = xdr->buf->len;
3426 struct raparms *ra; 3427 struct raparms *ra;
3427 __be32 *p; 3428 __be32 *p;
@@ -3445,12 +3446,15 @@ nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr,
3445 maxcount = min_t(unsigned long, maxcount, (xdr->buf->buflen - xdr->buf->len)); 3446 maxcount = min_t(unsigned long, maxcount, (xdr->buf->buflen - xdr->buf->len));
3446 maxcount = min_t(unsigned long, maxcount, read->rd_length); 3447 maxcount = min_t(unsigned long, maxcount, read->rd_length);
3447 3448
3448 if (!read->rd_filp) { 3449 if (read->rd_filp)
3450 err = nfsd_permission(resp->rqstp, fhp->fh_export,
3451 fhp->fh_dentry,
3452 NFSD_MAY_READ|NFSD_MAY_OWNER_OVERRIDE);
3453 else
3449 err = nfsd_get_tmp_read_open(resp->rqstp, read->rd_fhp, 3454 err = nfsd_get_tmp_read_open(resp->rqstp, read->rd_fhp,
3450 &file, &ra); 3455 &file, &ra);
3451 if (err) 3456 if (err)
3452 goto err_truncate; 3457 goto err_truncate;
3453 }
3454 3458
3455 if (file->f_op->splice_read && test_bit(RQ_SPLICE_OK, &resp->rqstp->rq_flags)) 3459 if (file->f_op->splice_read && test_bit(RQ_SPLICE_OK, &resp->rqstp->rq_flags))
3456 err = nfsd4_encode_splice_read(resp, read, file, maxcount); 3460 err = nfsd4_encode_splice_read(resp, read, file, maxcount);
diff --git a/fs/nfsd/nfsctl.c b/fs/nfsd/nfsctl.c
index aa47d75ddb26..9690cb4dd588 100644
--- a/fs/nfsd/nfsctl.c
+++ b/fs/nfsd/nfsctl.c
@@ -1250,15 +1250,15 @@ static int __init init_nfsd(void)
1250 int retval; 1250 int retval;
1251 printk(KERN_INFO "Installing knfsd (copyright (C) 1996 okir@monad.swb.de).\n"); 1251 printk(KERN_INFO "Installing knfsd (copyright (C) 1996 okir@monad.swb.de).\n");
1252 1252
1253 retval = register_cld_notifier();
1254 if (retval)
1255 return retval;
1256 retval = register_pernet_subsys(&nfsd_net_ops); 1253 retval = register_pernet_subsys(&nfsd_net_ops);
1257 if (retval < 0) 1254 if (retval < 0)
1258 goto out_unregister_notifier; 1255 return retval;
1259 retval = nfsd4_init_slabs(); 1256 retval = register_cld_notifier();
1260 if (retval) 1257 if (retval)
1261 goto out_unregister_pernet; 1258 goto out_unregister_pernet;
1259 retval = nfsd4_init_slabs();
1260 if (retval)
1261 goto out_unregister_notifier;
1262 retval = nfsd4_init_pnfs(); 1262 retval = nfsd4_init_pnfs();
1263 if (retval) 1263 if (retval)
1264 goto out_free_slabs; 1264 goto out_free_slabs;
@@ -1290,10 +1290,10 @@ out_exit_pnfs:
1290 nfsd4_exit_pnfs(); 1290 nfsd4_exit_pnfs();
1291out_free_slabs: 1291out_free_slabs:
1292 nfsd4_free_slabs(); 1292 nfsd4_free_slabs();
1293out_unregister_pernet:
1294 unregister_pernet_subsys(&nfsd_net_ops);
1295out_unregister_notifier: 1293out_unregister_notifier:
1296 unregister_cld_notifier(); 1294 unregister_cld_notifier();
1295out_unregister_pernet:
1296 unregister_pernet_subsys(&nfsd_net_ops);
1297 return retval; 1297 return retval;
1298} 1298}
1299 1299
@@ -1308,8 +1308,8 @@ static void __exit exit_nfsd(void)
1308 nfsd4_exit_pnfs(); 1308 nfsd4_exit_pnfs();
1309 nfsd_fault_inject_cleanup(); 1309 nfsd_fault_inject_cleanup();
1310 unregister_filesystem(&nfsd_fs_type); 1310 unregister_filesystem(&nfsd_fs_type);
1311 unregister_pernet_subsys(&nfsd_net_ops);
1312 unregister_cld_notifier(); 1311 unregister_cld_notifier();
1312 unregister_pernet_subsys(&nfsd_net_ops);
1313} 1313}
1314 1314
1315MODULE_AUTHOR("Olaf Kirch <okir@monad.swb.de>"); 1315MODULE_AUTHOR("Olaf Kirch <okir@monad.swb.de>");
diff --git a/fs/nfsd/nfsd.h b/fs/nfsd/nfsd.h
index 565c4da1a9eb..cf980523898b 100644
--- a/fs/nfsd/nfsd.h
+++ b/fs/nfsd/nfsd.h
@@ -24,7 +24,7 @@
24#include "export.h" 24#include "export.h"
25 25
26#undef ifdebug 26#undef ifdebug
27#ifdef NFSD_DEBUG 27#ifdef CONFIG_SUNRPC_DEBUG
28# define ifdebug(flag) if (nfsd_debug & NFSDDBG_##flag) 28# define ifdebug(flag) if (nfsd_debug & NFSDDBG_##flag)
29#else 29#else
30# define ifdebug(flag) if (0) 30# define ifdebug(flag) if (0)
diff --git a/fs/nfsd/nfsfh.c b/fs/nfsd/nfsfh.c
index e9fa966fc37f..350041a40fe5 100644
--- a/fs/nfsd/nfsfh.c
+++ b/fs/nfsd/nfsfh.c
@@ -38,7 +38,7 @@ static int nfsd_acceptable(void *expv, struct dentry *dentry)
38 /* make sure parents give x permission to user */ 38 /* make sure parents give x permission to user */
39 int err; 39 int err;
40 parent = dget_parent(tdentry); 40 parent = dget_parent(tdentry);
41 err = inode_permission(parent->d_inode, MAY_EXEC); 41 err = inode_permission(d_inode(parent), MAY_EXEC);
42 if (err < 0) { 42 if (err < 0) {
43 dput(parent); 43 dput(parent);
44 break; 44 break;
@@ -340,7 +340,7 @@ fh_verify(struct svc_rqst *rqstp, struct svc_fh *fhp, umode_t type, int access)
340 if (error) 340 if (error)
341 goto out; 341 goto out;
342 342
343 error = nfsd_mode_check(rqstp, dentry->d_inode->i_mode, type); 343 error = nfsd_mode_check(rqstp, d_inode(dentry)->i_mode, type);
344 if (error) 344 if (error)
345 goto out; 345 goto out;
346 346
@@ -412,8 +412,8 @@ static inline void _fh_update_old(struct dentry *dentry,
412 struct svc_export *exp, 412 struct svc_export *exp,
413 struct knfsd_fh *fh) 413 struct knfsd_fh *fh)
414{ 414{
415 fh->ofh_ino = ino_t_to_u32(dentry->d_inode->i_ino); 415 fh->ofh_ino = ino_t_to_u32(d_inode(dentry)->i_ino);
416 fh->ofh_generation = dentry->d_inode->i_generation; 416 fh->ofh_generation = d_inode(dentry)->i_generation;
417 if (d_is_dir(dentry) || 417 if (d_is_dir(dentry) ||
418 (exp->ex_flags & NFSEXP_NOSUBTREECHECK)) 418 (exp->ex_flags & NFSEXP_NOSUBTREECHECK))
419 fh->ofh_dirino = 0; 419 fh->ofh_dirino = 0;
@@ -426,7 +426,7 @@ static bool is_root_export(struct svc_export *exp)
426 426
427static struct super_block *exp_sb(struct svc_export *exp) 427static struct super_block *exp_sb(struct svc_export *exp)
428{ 428{
429 return exp->ex_path.dentry->d_inode->i_sb; 429 return d_inode(exp->ex_path.dentry)->i_sb;
430} 430}
431 431
432static bool fsid_type_ok_for_exp(u8 fsid_type, struct svc_export *exp) 432static bool fsid_type_ok_for_exp(u8 fsid_type, struct svc_export *exp)
@@ -520,12 +520,12 @@ fh_compose(struct svc_fh *fhp, struct svc_export *exp, struct dentry *dentry,
520 * 520 *
521 */ 521 */
522 522
523 struct inode * inode = dentry->d_inode; 523 struct inode * inode = d_inode(dentry);
524 dev_t ex_dev = exp_sb(exp)->s_dev; 524 dev_t ex_dev = exp_sb(exp)->s_dev;
525 525
526 dprintk("nfsd: fh_compose(exp %02x:%02x/%ld %pd2, ino=%ld)\n", 526 dprintk("nfsd: fh_compose(exp %02x:%02x/%ld %pd2, ino=%ld)\n",
527 MAJOR(ex_dev), MINOR(ex_dev), 527 MAJOR(ex_dev), MINOR(ex_dev),
528 (long) exp->ex_path.dentry->d_inode->i_ino, 528 (long) d_inode(exp->ex_path.dentry)->i_ino,
529 dentry, 529 dentry,
530 (inode ? inode->i_ino : 0)); 530 (inode ? inode->i_ino : 0));
531 531
@@ -558,7 +558,7 @@ fh_compose(struct svc_fh *fhp, struct svc_export *exp, struct dentry *dentry,
558 fhp->fh_handle.ofh_dev = old_encode_dev(ex_dev); 558 fhp->fh_handle.ofh_dev = old_encode_dev(ex_dev);
559 fhp->fh_handle.ofh_xdev = fhp->fh_handle.ofh_dev; 559 fhp->fh_handle.ofh_xdev = fhp->fh_handle.ofh_dev;
560 fhp->fh_handle.ofh_xino = 560 fhp->fh_handle.ofh_xino =
561 ino_t_to_u32(exp->ex_path.dentry->d_inode->i_ino); 561 ino_t_to_u32(d_inode(exp->ex_path.dentry)->i_ino);
562 fhp->fh_handle.ofh_dirino = ino_t_to_u32(parent_ino(dentry)); 562 fhp->fh_handle.ofh_dirino = ino_t_to_u32(parent_ino(dentry));
563 if (inode) 563 if (inode)
564 _fh_update_old(dentry, exp, &fhp->fh_handle); 564 _fh_update_old(dentry, exp, &fhp->fh_handle);
@@ -570,7 +570,7 @@ fh_compose(struct svc_fh *fhp, struct svc_export *exp, struct dentry *dentry,
570 mk_fsid(fhp->fh_handle.fh_fsid_type, 570 mk_fsid(fhp->fh_handle.fh_fsid_type,
571 fhp->fh_handle.fh_fsid, 571 fhp->fh_handle.fh_fsid,
572 ex_dev, 572 ex_dev,
573 exp->ex_path.dentry->d_inode->i_ino, 573 d_inode(exp->ex_path.dentry)->i_ino,
574 exp->ex_fsid, exp->ex_uuid); 574 exp->ex_fsid, exp->ex_uuid);
575 575
576 if (inode) 576 if (inode)
@@ -597,7 +597,7 @@ fh_update(struct svc_fh *fhp)
597 goto out_bad; 597 goto out_bad;
598 598
599 dentry = fhp->fh_dentry; 599 dentry = fhp->fh_dentry;
600 if (!dentry->d_inode) 600 if (d_really_is_negative(dentry))
601 goto out_negative; 601 goto out_negative;
602 if (fhp->fh_handle.fh_version != 1) { 602 if (fhp->fh_handle.fh_version != 1) {
603 _fh_update_old(dentry, fhp->fh_export, &fhp->fh_handle); 603 _fh_update_old(dentry, fhp->fh_export, &fhp->fh_handle);
diff --git a/fs/nfsd/nfsfh.h b/fs/nfsd/nfsfh.h
index f22920442172..1e90dad4926b 100644
--- a/fs/nfsd/nfsfh.h
+++ b/fs/nfsd/nfsfh.h
@@ -225,7 +225,7 @@ fill_pre_wcc(struct svc_fh *fhp)
225{ 225{
226 struct inode *inode; 226 struct inode *inode;
227 227
228 inode = fhp->fh_dentry->d_inode; 228 inode = d_inode(fhp->fh_dentry);
229 if (!fhp->fh_pre_saved) { 229 if (!fhp->fh_pre_saved) {
230 fhp->fh_pre_mtime = inode->i_mtime; 230 fhp->fh_pre_mtime = inode->i_mtime;
231 fhp->fh_pre_ctime = inode->i_ctime; 231 fhp->fh_pre_ctime = inode->i_ctime;
@@ -264,7 +264,7 @@ fh_lock_nested(struct svc_fh *fhp, unsigned int subclass)
264 return; 264 return;
265 } 265 }
266 266
267 inode = dentry->d_inode; 267 inode = d_inode(dentry);
268 mutex_lock_nested(&inode->i_mutex, subclass); 268 mutex_lock_nested(&inode->i_mutex, subclass);
269 fill_pre_wcc(fhp); 269 fill_pre_wcc(fhp);
270 fhp->fh_locked = 1; 270 fhp->fh_locked = 1;
@@ -284,7 +284,7 @@ fh_unlock(struct svc_fh *fhp)
284{ 284{
285 if (fhp->fh_locked) { 285 if (fhp->fh_locked) {
286 fill_post_wcc(fhp); 286 fill_post_wcc(fhp);
287 mutex_unlock(&fhp->fh_dentry->d_inode->i_mutex); 287 mutex_unlock(&d_inode(fhp->fh_dentry)->i_mutex);
288 fhp->fh_locked = 0; 288 fhp->fh_locked = 0;
289 } 289 }
290} 290}
diff --git a/fs/nfsd/nfsproc.c b/fs/nfsd/nfsproc.c
index b8680738f588..aecbcd34d336 100644
--- a/fs/nfsd/nfsproc.c
+++ b/fs/nfsd/nfsproc.c
@@ -223,7 +223,7 @@ nfsd_proc_create(struct svc_rqst *rqstp, struct nfsd_createargs *argp,
223 } 223 }
224 fh_init(newfhp, NFS_FHSIZE); 224 fh_init(newfhp, NFS_FHSIZE);
225 nfserr = fh_compose(newfhp, dirfhp->fh_export, dchild, dirfhp); 225 nfserr = fh_compose(newfhp, dirfhp->fh_export, dchild, dirfhp);
226 if (!nfserr && !dchild->d_inode) 226 if (!nfserr && d_really_is_negative(dchild))
227 nfserr = nfserr_noent; 227 nfserr = nfserr_noent;
228 dput(dchild); 228 dput(dchild);
229 if (nfserr) { 229 if (nfserr) {
@@ -241,7 +241,7 @@ nfsd_proc_create(struct svc_rqst *rqstp, struct nfsd_createargs *argp,
241 } 241 }
242 } 242 }
243 243
244 inode = newfhp->fh_dentry->d_inode; 244 inode = d_inode(newfhp->fh_dentry);
245 245
246 /* Unfudge the mode bits */ 246 /* Unfudge the mode bits */
247 if (attr->ia_valid & ATTR_MODE) { 247 if (attr->ia_valid & ATTR_MODE) {
diff --git a/fs/nfsd/nfsxdr.c b/fs/nfsd/nfsxdr.c
index 412d7061f9e5..79d964aa8079 100644
--- a/fs/nfsd/nfsxdr.c
+++ b/fs/nfsd/nfsxdr.c
@@ -187,7 +187,7 @@ encode_fattr(struct svc_rqst *rqstp, __be32 *p, struct svc_fh *fhp,
187 *p++ = htonl((u32) stat->ino); 187 *p++ = htonl((u32) stat->ino);
188 *p++ = htonl((u32) stat->atime.tv_sec); 188 *p++ = htonl((u32) stat->atime.tv_sec);
189 *p++ = htonl(stat->atime.tv_nsec ? stat->atime.tv_nsec / 1000 : 0); 189 *p++ = htonl(stat->atime.tv_nsec ? stat->atime.tv_nsec / 1000 : 0);
190 lease_get_mtime(dentry->d_inode, &time); 190 lease_get_mtime(d_inode(dentry), &time);
191 *p++ = htonl((u32) time.tv_sec); 191 *p++ = htonl((u32) time.tv_sec);
192 *p++ = htonl(time.tv_nsec ? time.tv_nsec / 1000 : 0); 192 *p++ = htonl(time.tv_nsec ? time.tv_nsec / 1000 : 0);
193 *p++ = htonl((u32) stat->ctime.tv_sec); 193 *p++ = htonl((u32) stat->ctime.tv_sec);
diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
index 368526582429..84d770be056e 100644
--- a/fs/nfsd/vfs.c
+++ b/fs/nfsd/vfs.c
@@ -174,7 +174,7 @@ int nfsd_mountpoint(struct dentry *dentry, struct svc_export *exp)
174 return 1; 174 return 1;
175 if (!(exp->ex_flags & NFSEXP_V4ROOT)) 175 if (!(exp->ex_flags & NFSEXP_V4ROOT))
176 return 0; 176 return 0;
177 return dentry->d_inode != NULL; 177 return d_inode(dentry) != NULL;
178} 178}
179 179
180__be32 180__be32
@@ -270,7 +270,7 @@ nfsd_lookup(struct svc_rqst *rqstp, struct svc_fh *fhp, const char *name,
270 * dentry may be negative, it may need to be updated. 270 * dentry may be negative, it may need to be updated.
271 */ 271 */
272 err = fh_compose(resfh, exp, dentry, fhp); 272 err = fh_compose(resfh, exp, dentry, fhp);
273 if (!err && !dentry->d_inode) 273 if (!err && d_really_is_negative(dentry))
274 err = nfserr_noent; 274 err = nfserr_noent;
275out: 275out:
276 dput(dentry); 276 dput(dentry);
@@ -284,7 +284,7 @@ out:
284static int 284static int
285commit_metadata(struct svc_fh *fhp) 285commit_metadata(struct svc_fh *fhp)
286{ 286{
287 struct inode *inode = fhp->fh_dentry->d_inode; 287 struct inode *inode = d_inode(fhp->fh_dentry);
288 const struct export_operations *export_ops = inode->i_sb->s_export_op; 288 const struct export_operations *export_ops = inode->i_sb->s_export_op;
289 289
290 if (!EX_ISSYNC(fhp->fh_export)) 290 if (!EX_ISSYNC(fhp->fh_export))
@@ -364,7 +364,7 @@ static __be32
364nfsd_get_write_access(struct svc_rqst *rqstp, struct svc_fh *fhp, 364nfsd_get_write_access(struct svc_rqst *rqstp, struct svc_fh *fhp,
365 struct iattr *iap) 365 struct iattr *iap)
366{ 366{
367 struct inode *inode = fhp->fh_dentry->d_inode; 367 struct inode *inode = d_inode(fhp->fh_dentry);
368 int host_err; 368 int host_err;
369 369
370 if (iap->ia_size < inode->i_size) { 370 if (iap->ia_size < inode->i_size) {
@@ -426,7 +426,7 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp, struct iattr *iap,
426 } 426 }
427 427
428 dentry = fhp->fh_dentry; 428 dentry = fhp->fh_dentry;
429 inode = dentry->d_inode; 429 inode = d_inode(dentry);
430 430
431 /* Ignore any mode updates on symlinks */ 431 /* Ignore any mode updates on symlinks */
432 if (S_ISLNK(inode->i_mode)) 432 if (S_ISLNK(inode->i_mode))
@@ -495,7 +495,7 @@ out:
495 */ 495 */
496int nfsd4_is_junction(struct dentry *dentry) 496int nfsd4_is_junction(struct dentry *dentry)
497{ 497{
498 struct inode *inode = dentry->d_inode; 498 struct inode *inode = d_inode(dentry);
499 499
500 if (inode == NULL) 500 if (inode == NULL)
501 return 0; 501 return 0;
@@ -521,9 +521,9 @@ __be32 nfsd4_set_nfs4_label(struct svc_rqst *rqstp, struct svc_fh *fhp,
521 521
522 dentry = fhp->fh_dentry; 522 dentry = fhp->fh_dentry;
523 523
524 mutex_lock(&dentry->d_inode->i_mutex); 524 mutex_lock(&d_inode(dentry)->i_mutex);
525 host_error = security_inode_setsecctx(dentry, label->data, label->len); 525 host_error = security_inode_setsecctx(dentry, label->data, label->len);
526 mutex_unlock(&dentry->d_inode->i_mutex); 526 mutex_unlock(&d_inode(dentry)->i_mutex);
527 return nfserrno(host_error); 527 return nfserrno(host_error);
528} 528}
529#else 529#else
@@ -706,7 +706,7 @@ nfsd_open(struct svc_rqst *rqstp, struct svc_fh *fhp, umode_t type,
706 706
707 path.mnt = fhp->fh_export->ex_path.mnt; 707 path.mnt = fhp->fh_export->ex_path.mnt;
708 path.dentry = fhp->fh_dentry; 708 path.dentry = fhp->fh_dentry;
709 inode = path.dentry->d_inode; 709 inode = d_inode(path.dentry);
710 710
711 /* Disallow write access to files with the append-only bit set 711 /* Disallow write access to files with the append-only bit set
712 * or any access when mandatory locking enabled 712 * or any access when mandatory locking enabled
@@ -1211,7 +1211,7 @@ nfsd_create(struct svc_rqst *rqstp, struct svc_fh *fhp,
1211 goto out; 1211 goto out;
1212 1212
1213 dentry = fhp->fh_dentry; 1213 dentry = fhp->fh_dentry;
1214 dirp = dentry->d_inode; 1214 dirp = d_inode(dentry);
1215 1215
1216 err = nfserr_notdir; 1216 err = nfserr_notdir;
1217 if (!dirp->i_op->lookup) 1217 if (!dirp->i_op->lookup)
@@ -1250,7 +1250,7 @@ nfsd_create(struct svc_rqst *rqstp, struct svc_fh *fhp,
1250 * Make sure the child dentry is still negative ... 1250 * Make sure the child dentry is still negative ...
1251 */ 1251 */
1252 err = nfserr_exist; 1252 err = nfserr_exist;
1253 if (dchild->d_inode) { 1253 if (d_really_is_positive(dchild)) {
1254 dprintk("nfsd_create: dentry %pd/%pd not negative!\n", 1254 dprintk("nfsd_create: dentry %pd/%pd not negative!\n",
1255 dentry, dchild); 1255 dentry, dchild);
1256 goto out; 1256 goto out;
@@ -1353,7 +1353,7 @@ do_nfsd_create(struct svc_rqst *rqstp, struct svc_fh *fhp,
1353 goto out; 1353 goto out;
1354 1354
1355 dentry = fhp->fh_dentry; 1355 dentry = fhp->fh_dentry;
1356 dirp = dentry->d_inode; 1356 dirp = d_inode(dentry);
1357 1357
1358 /* Get all the sanity checks out of the way before 1358 /* Get all the sanity checks out of the way before
1359 * we lock the parent. */ 1359 * we lock the parent. */
@@ -1376,7 +1376,7 @@ do_nfsd_create(struct svc_rqst *rqstp, struct svc_fh *fhp,
1376 goto out_nfserr; 1376 goto out_nfserr;
1377 1377
1378 /* If file doesn't exist, check for permissions to create one */ 1378 /* If file doesn't exist, check for permissions to create one */
1379 if (!dchild->d_inode) { 1379 if (d_really_is_negative(dchild)) {
1380 err = fh_verify(rqstp, fhp, S_IFDIR, NFSD_MAY_CREATE); 1380 err = fh_verify(rqstp, fhp, S_IFDIR, NFSD_MAY_CREATE);
1381 if (err) 1381 if (err)
1382 goto out; 1382 goto out;
@@ -1397,7 +1397,7 @@ do_nfsd_create(struct svc_rqst *rqstp, struct svc_fh *fhp,
1397 v_atime = verifier[1]&0x7fffffff; 1397 v_atime = verifier[1]&0x7fffffff;
1398 } 1398 }
1399 1399
1400 if (dchild->d_inode) { 1400 if (d_really_is_positive(dchild)) {
1401 err = 0; 1401 err = 0;
1402 1402
1403 switch (createmode) { 1403 switch (createmode) {
@@ -1420,17 +1420,17 @@ do_nfsd_create(struct svc_rqst *rqstp, struct svc_fh *fhp,
1420 } 1420 }
1421 break; 1421 break;
1422 case NFS3_CREATE_EXCLUSIVE: 1422 case NFS3_CREATE_EXCLUSIVE:
1423 if ( dchild->d_inode->i_mtime.tv_sec == v_mtime 1423 if ( d_inode(dchild)->i_mtime.tv_sec == v_mtime
1424 && dchild->d_inode->i_atime.tv_sec == v_atime 1424 && d_inode(dchild)->i_atime.tv_sec == v_atime
1425 && dchild->d_inode->i_size == 0 ) { 1425 && d_inode(dchild)->i_size == 0 ) {
1426 if (created) 1426 if (created)
1427 *created = 1; 1427 *created = 1;
1428 break; 1428 break;
1429 } 1429 }
1430 case NFS4_CREATE_EXCLUSIVE4_1: 1430 case NFS4_CREATE_EXCLUSIVE4_1:
1431 if ( dchild->d_inode->i_mtime.tv_sec == v_mtime 1431 if ( d_inode(dchild)->i_mtime.tv_sec == v_mtime
1432 && dchild->d_inode->i_atime.tv_sec == v_atime 1432 && d_inode(dchild)->i_atime.tv_sec == v_atime
1433 && dchild->d_inode->i_size == 0 ) { 1433 && d_inode(dchild)->i_size == 0 ) {
1434 if (created) 1434 if (created)
1435 *created = 1; 1435 *created = 1;
1436 goto set_attr; 1436 goto set_attr;
@@ -1513,7 +1513,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
1513 1513
1514 path.mnt = fhp->fh_export->ex_path.mnt; 1514 path.mnt = fhp->fh_export->ex_path.mnt;
1515 path.dentry = fhp->fh_dentry; 1515 path.dentry = fhp->fh_dentry;
1516 inode = path.dentry->d_inode; 1516 inode = d_inode(path.dentry);
1517 1517
1518 err = nfserr_inval; 1518 err = nfserr_inval;
1519 if (!inode->i_op->readlink) 1519 if (!inode->i_op->readlink)
@@ -1576,7 +1576,7 @@ nfsd_symlink(struct svc_rqst *rqstp, struct svc_fh *fhp,
1576 if (IS_ERR(dnew)) 1576 if (IS_ERR(dnew))
1577 goto out_nfserr; 1577 goto out_nfserr;
1578 1578
1579 host_err = vfs_symlink(dentry->d_inode, dnew, path); 1579 host_err = vfs_symlink(d_inode(dentry), dnew, path);
1580 err = nfserrno(host_err); 1580 err = nfserrno(host_err);
1581 if (!err) 1581 if (!err)
1582 err = nfserrno(commit_metadata(fhp)); 1582 err = nfserrno(commit_metadata(fhp));
@@ -1632,7 +1632,7 @@ nfsd_link(struct svc_rqst *rqstp, struct svc_fh *ffhp,
1632 1632
1633 fh_lock_nested(ffhp, I_MUTEX_PARENT); 1633 fh_lock_nested(ffhp, I_MUTEX_PARENT);
1634 ddir = ffhp->fh_dentry; 1634 ddir = ffhp->fh_dentry;
1635 dirp = ddir->d_inode; 1635 dirp = d_inode(ddir);
1636 1636
1637 dnew = lookup_one_len(name, ddir, len); 1637 dnew = lookup_one_len(name, ddir, len);
1638 host_err = PTR_ERR(dnew); 1638 host_err = PTR_ERR(dnew);
@@ -1642,7 +1642,7 @@ nfsd_link(struct svc_rqst *rqstp, struct svc_fh *ffhp,
1642 dold = tfhp->fh_dentry; 1642 dold = tfhp->fh_dentry;
1643 1643
1644 err = nfserr_noent; 1644 err = nfserr_noent;
1645 if (!dold->d_inode) 1645 if (d_really_is_negative(dold))
1646 goto out_dput; 1646 goto out_dput;
1647 host_err = vfs_link(dold, dirp, dnew, NULL); 1647 host_err = vfs_link(dold, dirp, dnew, NULL);
1648 if (!host_err) { 1648 if (!host_err) {
@@ -1689,10 +1689,10 @@ nfsd_rename(struct svc_rqst *rqstp, struct svc_fh *ffhp, char *fname, int flen,
1689 goto out; 1689 goto out;
1690 1690
1691 fdentry = ffhp->fh_dentry; 1691 fdentry = ffhp->fh_dentry;
1692 fdir = fdentry->d_inode; 1692 fdir = d_inode(fdentry);
1693 1693
1694 tdentry = tfhp->fh_dentry; 1694 tdentry = tfhp->fh_dentry;
1695 tdir = tdentry->d_inode; 1695 tdir = d_inode(tdentry);
1696 1696
1697 err = nfserr_perm; 1697 err = nfserr_perm;
1698 if (!flen || isdotent(fname, flen) || !tlen || isdotent(tname, tlen)) 1698 if (!flen || isdotent(fname, flen) || !tlen || isdotent(tname, tlen))
@@ -1717,7 +1717,7 @@ nfsd_rename(struct svc_rqst *rqstp, struct svc_fh *ffhp, char *fname, int flen,
1717 goto out_nfserr; 1717 goto out_nfserr;
1718 1718
1719 host_err = -ENOENT; 1719 host_err = -ENOENT;
1720 if (!odentry->d_inode) 1720 if (d_really_is_negative(odentry))
1721 goto out_dput_old; 1721 goto out_dput_old;
1722 host_err = -EINVAL; 1722 host_err = -EINVAL;
1723 if (odentry == trap) 1723 if (odentry == trap)
@@ -1790,21 +1790,21 @@ nfsd_unlink(struct svc_rqst *rqstp, struct svc_fh *fhp, int type,
1790 1790
1791 fh_lock_nested(fhp, I_MUTEX_PARENT); 1791 fh_lock_nested(fhp, I_MUTEX_PARENT);
1792 dentry = fhp->fh_dentry; 1792 dentry = fhp->fh_dentry;
1793 dirp = dentry->d_inode; 1793 dirp = d_inode(dentry);
1794 1794
1795 rdentry = lookup_one_len(fname, dentry, flen); 1795 rdentry = lookup_one_len(fname, dentry, flen);
1796 host_err = PTR_ERR(rdentry); 1796 host_err = PTR_ERR(rdentry);
1797 if (IS_ERR(rdentry)) 1797 if (IS_ERR(rdentry))
1798 goto out_nfserr; 1798 goto out_nfserr;
1799 1799
1800 if (!rdentry->d_inode) { 1800 if (d_really_is_negative(rdentry)) {
1801 dput(rdentry); 1801 dput(rdentry);
1802 err = nfserr_noent; 1802 err = nfserr_noent;
1803 goto out; 1803 goto out;
1804 } 1804 }
1805 1805
1806 if (!type) 1806 if (!type)
1807 type = rdentry->d_inode->i_mode & S_IFMT; 1807 type = d_inode(rdentry)->i_mode & S_IFMT;
1808 1808
1809 if (type != S_IFDIR) 1809 if (type != S_IFDIR)
1810 host_err = vfs_unlink(dirp, rdentry, NULL); 1810 host_err = vfs_unlink(dirp, rdentry, NULL);
@@ -2015,7 +2015,7 @@ __be32
2015nfsd_permission(struct svc_rqst *rqstp, struct svc_export *exp, 2015nfsd_permission(struct svc_rqst *rqstp, struct svc_export *exp,
2016 struct dentry *dentry, int acc) 2016 struct dentry *dentry, int acc)
2017{ 2017{
2018 struct inode *inode = dentry->d_inode; 2018 struct inode *inode = d_inode(dentry);
2019 int err; 2019 int err;
2020 2020
2021 if ((acc & NFSD_MAY_MASK) == NFSD_MAY_NOP) 2021 if ((acc & NFSD_MAY_MASK) == NFSD_MAY_NOP)
diff --git a/fs/nfsd/xdr4.h b/fs/nfsd/xdr4.h
index 0bda93e58e1b..f982ae84f0cd 100644
--- a/fs/nfsd/xdr4.h
+++ b/fs/nfsd/xdr4.h
@@ -40,7 +40,6 @@
40#include "state.h" 40#include "state.h"
41#include "nfsd.h" 41#include "nfsd.h"
42 42
43#define NFSD4_MAX_SEC_LABEL_LEN 2048
44#define NFSD4_MAX_TAGLEN 128 43#define NFSD4_MAX_TAGLEN 128
45#define XDR_LEN(n) (((n) + 3) & ~3) 44#define XDR_LEN(n) (((n) + 3) & ~3)
46 45
@@ -632,7 +631,7 @@ set_change_info(struct nfsd4_change_info *cinfo, struct svc_fh *fhp)
632{ 631{
633 BUG_ON(!fhp->fh_pre_saved); 632 BUG_ON(!fhp->fh_pre_saved);
634 cinfo->atomic = fhp->fh_post_saved; 633 cinfo->atomic = fhp->fh_post_saved;
635 cinfo->change_supported = IS_I_VERSION(fhp->fh_dentry->d_inode); 634 cinfo->change_supported = IS_I_VERSION(d_inode(fhp->fh_dentry));
636 635
637 cinfo->before_change = fhp->fh_pre_change; 636 cinfo->before_change = fhp->fh_pre_change;
638 cinfo->after_change = fhp->fh_post_change; 637 cinfo->after_change = fhp->fh_post_change;
@@ -683,7 +682,7 @@ extern __be32 nfsd4_process_open2(struct svc_rqst *rqstp,
683 struct svc_fh *current_fh, struct nfsd4_open *open); 682 struct svc_fh *current_fh, struct nfsd4_open *open);
684extern void nfsd4_cstate_clear_replay(struct nfsd4_compound_state *cstate); 683extern void nfsd4_cstate_clear_replay(struct nfsd4_compound_state *cstate);
685extern void nfsd4_cleanup_open_state(struct nfsd4_compound_state *cstate, 684extern void nfsd4_cleanup_open_state(struct nfsd4_compound_state *cstate,
686 struct nfsd4_open *open, __be32 status); 685 struct nfsd4_open *open);
687extern __be32 nfsd4_open_confirm(struct svc_rqst *rqstp, 686extern __be32 nfsd4_open_confirm(struct svc_rqst *rqstp,
688 struct nfsd4_compound_state *, struct nfsd4_open_confirm *oc); 687 struct nfsd4_compound_state *, struct nfsd4_open_confirm *oc);
689extern __be32 nfsd4_close(struct svc_rqst *rqstp, 688extern __be32 nfsd4_close(struct svc_rqst *rqstp,
diff --git a/fs/nilfs2/dir.c b/fs/nilfs2/dir.c
index 197a63e9d102..0ee0bed3649b 100644
--- a/fs/nilfs2/dir.c
+++ b/fs/nilfs2/dir.c
@@ -435,7 +435,7 @@ void nilfs_set_link(struct inode *dir, struct nilfs_dir_entry *de,
435 */ 435 */
436int nilfs_add_link(struct dentry *dentry, struct inode *inode) 436int nilfs_add_link(struct dentry *dentry, struct inode *inode)
437{ 437{
438 struct inode *dir = dentry->d_parent->d_inode; 438 struct inode *dir = d_inode(dentry->d_parent);
439 const unsigned char *name = dentry->d_name.name; 439 const unsigned char *name = dentry->d_name.name;
440 int namelen = dentry->d_name.len; 440 int namelen = dentry->d_name.len;
441 unsigned chunk_size = nilfs_chunk_size(dir); 441 unsigned chunk_size = nilfs_chunk_size(dir);
diff --git a/fs/nilfs2/inode.c b/fs/nilfs2/inode.c
index be936df4ba73..258d9fe2521a 100644
--- a/fs/nilfs2/inode.c
+++ b/fs/nilfs2/inode.c
@@ -835,7 +835,7 @@ void nilfs_evict_inode(struct inode *inode)
835int nilfs_setattr(struct dentry *dentry, struct iattr *iattr) 835int nilfs_setattr(struct dentry *dentry, struct iattr *iattr)
836{ 836{
837 struct nilfs_transaction_info ti; 837 struct nilfs_transaction_info ti;
838 struct inode *inode = dentry->d_inode; 838 struct inode *inode = d_inode(dentry);
839 struct super_block *sb = inode->i_sb; 839 struct super_block *sb = inode->i_sb;
840 int err; 840 int err;
841 841
diff --git a/fs/nilfs2/namei.c b/fs/nilfs2/namei.c
index 0f84b257932c..22180836ec22 100644
--- a/fs/nilfs2/namei.c
+++ b/fs/nilfs2/namei.c
@@ -192,7 +192,7 @@ out_fail:
192static int nilfs_link(struct dentry *old_dentry, struct inode *dir, 192static int nilfs_link(struct dentry *old_dentry, struct inode *dir,
193 struct dentry *dentry) 193 struct dentry *dentry)
194{ 194{
195 struct inode *inode = old_dentry->d_inode; 195 struct inode *inode = d_inode(old_dentry);
196 struct nilfs_transaction_info ti; 196 struct nilfs_transaction_info ti;
197 int err; 197 int err;
198 198
@@ -283,7 +283,7 @@ static int nilfs_do_unlink(struct inode *dir, struct dentry *dentry)
283 if (!de) 283 if (!de)
284 goto out; 284 goto out;
285 285
286 inode = dentry->d_inode; 286 inode = d_inode(dentry);
287 err = -EIO; 287 err = -EIO;
288 if (le64_to_cpu(de->inode) != inode->i_ino) 288 if (le64_to_cpu(de->inode) != inode->i_ino)
289 goto out; 289 goto out;
@@ -318,7 +318,7 @@ static int nilfs_unlink(struct inode *dir, struct dentry *dentry)
318 318
319 if (!err) { 319 if (!err) {
320 nilfs_mark_inode_dirty(dir); 320 nilfs_mark_inode_dirty(dir);
321 nilfs_mark_inode_dirty(dentry->d_inode); 321 nilfs_mark_inode_dirty(d_inode(dentry));
322 err = nilfs_transaction_commit(dir->i_sb); 322 err = nilfs_transaction_commit(dir->i_sb);
323 } else 323 } else
324 nilfs_transaction_abort(dir->i_sb); 324 nilfs_transaction_abort(dir->i_sb);
@@ -328,7 +328,7 @@ static int nilfs_unlink(struct inode *dir, struct dentry *dentry)
328 328
329static int nilfs_rmdir(struct inode *dir, struct dentry *dentry) 329static int nilfs_rmdir(struct inode *dir, struct dentry *dentry)
330{ 330{
331 struct inode *inode = dentry->d_inode; 331 struct inode *inode = d_inode(dentry);
332 struct nilfs_transaction_info ti; 332 struct nilfs_transaction_info ti;
333 int err; 333 int err;
334 334
@@ -358,8 +358,8 @@ static int nilfs_rmdir(struct inode *dir, struct dentry *dentry)
358static int nilfs_rename(struct inode *old_dir, struct dentry *old_dentry, 358static int nilfs_rename(struct inode *old_dir, struct dentry *old_dentry,
359 struct inode *new_dir, struct dentry *new_dentry) 359 struct inode *new_dir, struct dentry *new_dentry)
360{ 360{
361 struct inode *old_inode = old_dentry->d_inode; 361 struct inode *old_inode = d_inode(old_dentry);
362 struct inode *new_inode = new_dentry->d_inode; 362 struct inode *new_inode = d_inode(new_dentry);
363 struct page *dir_page = NULL; 363 struct page *dir_page = NULL;
364 struct nilfs_dir_entry *dir_de = NULL; 364 struct nilfs_dir_entry *dir_de = NULL;
365 struct page *old_page; 365 struct page *old_page;
@@ -453,13 +453,13 @@ static struct dentry *nilfs_get_parent(struct dentry *child)
453 struct qstr dotdot = QSTR_INIT("..", 2); 453 struct qstr dotdot = QSTR_INIT("..", 2);
454 struct nilfs_root *root; 454 struct nilfs_root *root;
455 455
456 ino = nilfs_inode_by_name(child->d_inode, &dotdot); 456 ino = nilfs_inode_by_name(d_inode(child), &dotdot);
457 if (!ino) 457 if (!ino)
458 return ERR_PTR(-ENOENT); 458 return ERR_PTR(-ENOENT);
459 459
460 root = NILFS_I(child->d_inode)->i_root; 460 root = NILFS_I(d_inode(child))->i_root;
461 461
462 inode = nilfs_iget(child->d_inode->i_sb, root, ino); 462 inode = nilfs_iget(d_inode(child)->i_sb, root, ino);
463 if (IS_ERR(inode)) 463 if (IS_ERR(inode))
464 return ERR_CAST(inode); 464 return ERR_CAST(inode);
465 465
diff --git a/fs/nilfs2/super.c b/fs/nilfs2/super.c
index c1725f20a9d1..f47585bfeb01 100644
--- a/fs/nilfs2/super.c
+++ b/fs/nilfs2/super.c
@@ -610,7 +610,7 @@ static int nilfs_unfreeze(struct super_block *sb)
610static int nilfs_statfs(struct dentry *dentry, struct kstatfs *buf) 610static int nilfs_statfs(struct dentry *dentry, struct kstatfs *buf)
611{ 611{
612 struct super_block *sb = dentry->d_sb; 612 struct super_block *sb = dentry->d_sb;
613 struct nilfs_root *root = NILFS_I(dentry->d_inode)->i_root; 613 struct nilfs_root *root = NILFS_I(d_inode(dentry))->i_root;
614 struct the_nilfs *nilfs = root->nilfs; 614 struct the_nilfs *nilfs = root->nilfs;
615 u64 id = huge_encode_dev(sb->s_bdev->bd_dev); 615 u64 id = huge_encode_dev(sb->s_bdev->bd_dev);
616 unsigned long long blocks; 616 unsigned long long blocks;
@@ -681,7 +681,7 @@ static int nilfs_show_options(struct seq_file *seq, struct dentry *dentry)
681{ 681{
682 struct super_block *sb = dentry->d_sb; 682 struct super_block *sb = dentry->d_sb;
683 struct the_nilfs *nilfs = sb->s_fs_info; 683 struct the_nilfs *nilfs = sb->s_fs_info;
684 struct nilfs_root *root = NILFS_I(dentry->d_inode)->i_root; 684 struct nilfs_root *root = NILFS_I(d_inode(dentry))->i_root;
685 685
686 if (!nilfs_test_opt(nilfs, BARRIER)) 686 if (!nilfs_test_opt(nilfs, BARRIER))
687 seq_puts(seq, ",nobarrier"); 687 seq_puts(seq, ",nobarrier");
@@ -1190,7 +1190,7 @@ static int nilfs_remount(struct super_block *sb, int *flags, char *data)
1190 1190
1191 sb->s_flags &= ~MS_RDONLY; 1191 sb->s_flags &= ~MS_RDONLY;
1192 1192
1193 root = NILFS_I(sb->s_root->d_inode)->i_root; 1193 root = NILFS_I(d_inode(sb->s_root))->i_root;
1194 err = nilfs_attach_log_writer(sb, root); 1194 err = nilfs_attach_log_writer(sb, root);
1195 if (err) 1195 if (err)
1196 goto restore_opts; 1196 goto restore_opts;
diff --git a/fs/nsfs.c b/fs/nsfs.c
index af1b24fa899d..99521e7c492b 100644
--- a/fs/nsfs.c
+++ b/fs/nsfs.c
@@ -13,7 +13,7 @@ static const struct file_operations ns_file_operations = {
13 13
14static char *ns_dname(struct dentry *dentry, char *buffer, int buflen) 14static char *ns_dname(struct dentry *dentry, char *buffer, int buflen)
15{ 15{
16 struct inode *inode = dentry->d_inode; 16 struct inode *inode = d_inode(dentry);
17 const struct proc_ns_operations *ns_ops = dentry->d_fsdata; 17 const struct proc_ns_operations *ns_ops = dentry->d_fsdata;
18 18
19 return dynamic_dname(dentry, buffer, buflen, "%s:[%lu]", 19 return dynamic_dname(dentry, buffer, buflen, "%s:[%lu]",
@@ -22,7 +22,7 @@ static char *ns_dname(struct dentry *dentry, char *buffer, int buflen)
22 22
23static void ns_prune_dentry(struct dentry *dentry) 23static void ns_prune_dentry(struct dentry *dentry)
24{ 24{
25 struct inode *inode = dentry->d_inode; 25 struct inode *inode = d_inode(dentry);
26 if (inode) { 26 if (inode) {
27 struct ns_common *ns = inode->i_private; 27 struct ns_common *ns = inode->i_private;
28 atomic_long_set(&ns->stashed, 0); 28 atomic_long_set(&ns->stashed, 0);
diff --git a/fs/ntfs/inode.c b/fs/ntfs/inode.c
index 1d0c21df0d80..d284f07eda77 100644
--- a/fs/ntfs/inode.c
+++ b/fs/ntfs/inode.c
@@ -2889,7 +2889,7 @@ void ntfs_truncate_vfs(struct inode *vi) {
2889 */ 2889 */
2890int ntfs_setattr(struct dentry *dentry, struct iattr *attr) 2890int ntfs_setattr(struct dentry *dentry, struct iattr *attr)
2891{ 2891{
2892 struct inode *vi = dentry->d_inode; 2892 struct inode *vi = d_inode(dentry);
2893 int err; 2893 int err;
2894 unsigned int ia_valid = attr->ia_valid; 2894 unsigned int ia_valid = attr->ia_valid;
2895 2895
diff --git a/fs/ntfs/namei.c b/fs/ntfs/namei.c
index b3973c2fd190..0f35b80d17fe 100644
--- a/fs/ntfs/namei.c
+++ b/fs/ntfs/namei.c
@@ -292,14 +292,14 @@ const struct inode_operations ntfs_dir_inode_ops = {
292 * The code is based on the ext3 ->get_parent() implementation found in 292 * The code is based on the ext3 ->get_parent() implementation found in
293 * fs/ext3/namei.c::ext3_get_parent(). 293 * fs/ext3/namei.c::ext3_get_parent().
294 * 294 *
295 * Note: ntfs_get_parent() is called with @child_dent->d_inode->i_mutex down. 295 * Note: ntfs_get_parent() is called with @d_inode(child_dent)->i_mutex down.
296 * 296 *
297 * Return the dentry of the parent directory on success or the error code on 297 * Return the dentry of the parent directory on success or the error code on
298 * error (IS_ERR() is true). 298 * error (IS_ERR() is true).
299 */ 299 */
300static struct dentry *ntfs_get_parent(struct dentry *child_dent) 300static struct dentry *ntfs_get_parent(struct dentry *child_dent)
301{ 301{
302 struct inode *vi = child_dent->d_inode; 302 struct inode *vi = d_inode(child_dent);
303 ntfs_inode *ni = NTFS_I(vi); 303 ntfs_inode *ni = NTFS_I(vi);
304 MFT_RECORD *mrec; 304 MFT_RECORD *mrec;
305 ntfs_attr_search_ctx *ctx; 305 ntfs_attr_search_ctx *ctx;
diff --git a/fs/ocfs2/dcache.c b/fs/ocfs2/dcache.c
index 4fda7a5f3088..290373024d9d 100644
--- a/fs/ocfs2/dcache.c
+++ b/fs/ocfs2/dcache.c
@@ -42,8 +42,8 @@
42void ocfs2_dentry_attach_gen(struct dentry *dentry) 42void ocfs2_dentry_attach_gen(struct dentry *dentry)
43{ 43{
44 unsigned long gen = 44 unsigned long gen =
45 OCFS2_I(dentry->d_parent->d_inode)->ip_dir_lock_gen; 45 OCFS2_I(d_inode(dentry->d_parent))->ip_dir_lock_gen;
46 BUG_ON(dentry->d_inode); 46 BUG_ON(d_inode(dentry));
47 dentry->d_fsdata = (void *)gen; 47 dentry->d_fsdata = (void *)gen;
48} 48}
49 49
@@ -57,7 +57,7 @@ static int ocfs2_dentry_revalidate(struct dentry *dentry, unsigned int flags)
57 if (flags & LOOKUP_RCU) 57 if (flags & LOOKUP_RCU)
58 return -ECHILD; 58 return -ECHILD;
59 59
60 inode = dentry->d_inode; 60 inode = d_inode(dentry);
61 osb = OCFS2_SB(dentry->d_sb); 61 osb = OCFS2_SB(dentry->d_sb);
62 62
63 trace_ocfs2_dentry_revalidate(dentry, dentry->d_name.len, 63 trace_ocfs2_dentry_revalidate(dentry, dentry->d_name.len,
@@ -71,7 +71,7 @@ static int ocfs2_dentry_revalidate(struct dentry *dentry, unsigned int flags)
71 unsigned long gen = (unsigned long) dentry->d_fsdata; 71 unsigned long gen = (unsigned long) dentry->d_fsdata;
72 unsigned long pgen; 72 unsigned long pgen;
73 spin_lock(&dentry->d_lock); 73 spin_lock(&dentry->d_lock);
74 pgen = OCFS2_I(dentry->d_parent->d_inode)->ip_dir_lock_gen; 74 pgen = OCFS2_I(d_inode(dentry->d_parent))->ip_dir_lock_gen;
75 spin_unlock(&dentry->d_lock); 75 spin_unlock(&dentry->d_lock);
76 trace_ocfs2_dentry_revalidate_negative(dentry->d_name.len, 76 trace_ocfs2_dentry_revalidate_negative(dentry->d_name.len,
77 dentry->d_name.name, 77 dentry->d_name.name,
@@ -146,7 +146,7 @@ static int ocfs2_match_dentry(struct dentry *dentry,
146 if (skip_unhashed && d_unhashed(dentry)) 146 if (skip_unhashed && d_unhashed(dentry))
147 return 0; 147 return 0;
148 148
149 parent = dentry->d_parent->d_inode; 149 parent = d_inode(dentry->d_parent);
150 /* Negative parent dentry? */ 150 /* Negative parent dentry? */
151 if (!parent) 151 if (!parent)
152 return 0; 152 return 0;
@@ -243,7 +243,7 @@ int ocfs2_dentry_attach_lock(struct dentry *dentry,
243 if (!inode) 243 if (!inode)
244 return 0; 244 return 0;
245 245
246 if (!dentry->d_inode && dentry->d_fsdata) { 246 if (d_really_is_negative(dentry) && dentry->d_fsdata) {
247 /* Converting a negative dentry to positive 247 /* Converting a negative dentry to positive
248 Clear dentry->d_fsdata */ 248 Clear dentry->d_fsdata */
249 dentry->d_fsdata = dl = NULL; 249 dentry->d_fsdata = dl = NULL;
@@ -446,7 +446,7 @@ void ocfs2_dentry_move(struct dentry *dentry, struct dentry *target,
446{ 446{
447 int ret; 447 int ret;
448 struct ocfs2_super *osb = OCFS2_SB(old_dir->i_sb); 448 struct ocfs2_super *osb = OCFS2_SB(old_dir->i_sb);
449 struct inode *inode = dentry->d_inode; 449 struct inode *inode = d_inode(dentry);
450 450
451 /* 451 /*
452 * Move within the same directory, so the actual lock info won't 452 * Move within the same directory, so the actual lock info won't
diff --git a/fs/ocfs2/dir.h b/fs/ocfs2/dir.h
index f0344b75b14d..3d8639f38973 100644
--- a/fs/ocfs2/dir.h
+++ b/fs/ocfs2/dir.h
@@ -72,7 +72,7 @@ static inline int ocfs2_add_entry(handle_t *handle,
72 struct buffer_head *parent_fe_bh, 72 struct buffer_head *parent_fe_bh,
73 struct ocfs2_dir_lookup_result *lookup) 73 struct ocfs2_dir_lookup_result *lookup)
74{ 74{
75 return __ocfs2_add_entry(handle, dentry->d_parent->d_inode, 75 return __ocfs2_add_entry(handle, d_inode(dentry->d_parent),
76 dentry->d_name.name, dentry->d_name.len, 76 dentry->d_name.name, dentry->d_name.len,
77 inode, blkno, parent_fe_bh, lookup); 77 inode, blkno, parent_fe_bh, lookup);
78} 78}
diff --git a/fs/ocfs2/dlmfs/dlmfs.c b/fs/ocfs2/dlmfs/dlmfs.c
index 061ba6a91bf2..b5cf27dcb18a 100644
--- a/fs/ocfs2/dlmfs/dlmfs.c
+++ b/fs/ocfs2/dlmfs/dlmfs.c
@@ -208,7 +208,7 @@ static int dlmfs_file_release(struct inode *inode,
208static int dlmfs_file_setattr(struct dentry *dentry, struct iattr *attr) 208static int dlmfs_file_setattr(struct dentry *dentry, struct iattr *attr)
209{ 209{
210 int error; 210 int error;
211 struct inode *inode = dentry->d_inode; 211 struct inode *inode = d_inode(dentry);
212 212
213 attr->ia_valid &= ~ATTR_SIZE; 213 attr->ia_valid &= ~ATTR_SIZE;
214 error = inode_change_ok(inode, attr); 214 error = inode_change_ok(inode, attr);
@@ -549,7 +549,7 @@ static int dlmfs_unlink(struct inode *dir,
549 struct dentry *dentry) 549 struct dentry *dentry)
550{ 550{
551 int status; 551 int status;
552 struct inode *inode = dentry->d_inode; 552 struct inode *inode = d_inode(dentry);
553 553
554 mlog(0, "unlink inode %lu\n", inode->i_ino); 554 mlog(0, "unlink inode %lu\n", inode->i_ino);
555 555
diff --git a/fs/ocfs2/export.c b/fs/ocfs2/export.c
index 540dc4bdd042..827fc9809bc2 100644
--- a/fs/ocfs2/export.c
+++ b/fs/ocfs2/export.c
@@ -147,7 +147,7 @@ static struct dentry *ocfs2_get_parent(struct dentry *child)
147 int status; 147 int status;
148 u64 blkno; 148 u64 blkno;
149 struct dentry *parent; 149 struct dentry *parent;
150 struct inode *dir = child->d_inode; 150 struct inode *dir = d_inode(child);
151 151
152 trace_ocfs2_get_parent(child, child->d_name.len, child->d_name.name, 152 trace_ocfs2_get_parent(child, child->d_name.len, child->d_name.name,
153 (unsigned long long)OCFS2_I(dir)->ip_blkno); 153 (unsigned long long)OCFS2_I(dir)->ip_blkno);
diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c
index 913fc250d85a..d8b670cbd909 100644
--- a/fs/ocfs2/file.c
+++ b/fs/ocfs2/file.c
@@ -1126,7 +1126,7 @@ out:
1126int ocfs2_setattr(struct dentry *dentry, struct iattr *attr) 1126int ocfs2_setattr(struct dentry *dentry, struct iattr *attr)
1127{ 1127{
1128 int status = 0, size_change; 1128 int status = 0, size_change;
1129 struct inode *inode = dentry->d_inode; 1129 struct inode *inode = d_inode(dentry);
1130 struct super_block *sb = inode->i_sb; 1130 struct super_block *sb = inode->i_sb;
1131 struct ocfs2_super *osb = OCFS2_SB(sb); 1131 struct ocfs2_super *osb = OCFS2_SB(sb);
1132 struct buffer_head *bh = NULL; 1132 struct buffer_head *bh = NULL;
@@ -1275,8 +1275,8 @@ int ocfs2_getattr(struct vfsmount *mnt,
1275 struct dentry *dentry, 1275 struct dentry *dentry,
1276 struct kstat *stat) 1276 struct kstat *stat)
1277{ 1277{
1278 struct inode *inode = dentry->d_inode; 1278 struct inode *inode = d_inode(dentry);
1279 struct super_block *sb = dentry->d_inode->i_sb; 1279 struct super_block *sb = d_inode(dentry)->i_sb;
1280 struct ocfs2_super *osb = sb->s_fs_info; 1280 struct ocfs2_super *osb = sb->s_fs_info;
1281 int err; 1281 int err;
1282 1282
@@ -2114,7 +2114,7 @@ static int ocfs2_prepare_inode_for_write(struct file *file,
2114{ 2114{
2115 int ret = 0, meta_level = 0; 2115 int ret = 0, meta_level = 0;
2116 struct dentry *dentry = file->f_path.dentry; 2116 struct dentry *dentry = file->f_path.dentry;
2117 struct inode *inode = dentry->d_inode; 2117 struct inode *inode = d_inode(dentry);
2118 loff_t end; 2118 loff_t end;
2119 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); 2119 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
2120 int full_coherency = !(osb->s_mount_opt & 2120 int full_coherency = !(osb->s_mount_opt &
diff --git a/fs/ocfs2/inode.c b/fs/ocfs2/inode.c
index be71ca0937f7..b254416dc8d9 100644
--- a/fs/ocfs2/inode.c
+++ b/fs/ocfs2/inode.c
@@ -1209,7 +1209,7 @@ int ocfs2_drop_inode(struct inode *inode)
1209 */ 1209 */
1210int ocfs2_inode_revalidate(struct dentry *dentry) 1210int ocfs2_inode_revalidate(struct dentry *dentry)
1211{ 1211{
1212 struct inode *inode = dentry->d_inode; 1212 struct inode *inode = d_inode(dentry);
1213 int status = 0; 1213 int status = 0;
1214 1214
1215 trace_ocfs2_inode_revalidate(inode, 1215 trace_ocfs2_inode_revalidate(inode,
diff --git a/fs/ocfs2/namei.c b/fs/ocfs2/namei.c
index 09f90cbf0e24..176fe6afd94e 100644
--- a/fs/ocfs2/namei.c
+++ b/fs/ocfs2/namei.c
@@ -689,8 +689,8 @@ static int ocfs2_link(struct dentry *old_dentry,
689 struct dentry *dentry) 689 struct dentry *dentry)
690{ 690{
691 handle_t *handle; 691 handle_t *handle;
692 struct inode *inode = old_dentry->d_inode; 692 struct inode *inode = d_inode(old_dentry);
693 struct inode *old_dir = old_dentry->d_parent->d_inode; 693 struct inode *old_dir = d_inode(old_dentry->d_parent);
694 int err; 694 int err;
695 struct buffer_head *fe_bh = NULL; 695 struct buffer_head *fe_bh = NULL;
696 struct buffer_head *old_dir_bh = NULL; 696 struct buffer_head *old_dir_bh = NULL;
@@ -879,7 +879,7 @@ static int ocfs2_unlink(struct inode *dir,
879 int status; 879 int status;
880 int child_locked = 0; 880 int child_locked = 0;
881 bool is_unlinkable = false; 881 bool is_unlinkable = false;
882 struct inode *inode = dentry->d_inode; 882 struct inode *inode = d_inode(dentry);
883 struct inode *orphan_dir = NULL; 883 struct inode *orphan_dir = NULL;
884 struct ocfs2_super *osb = OCFS2_SB(dir->i_sb); 884 struct ocfs2_super *osb = OCFS2_SB(dir->i_sb);
885 u64 blkno; 885 u64 blkno;
@@ -898,7 +898,7 @@ static int ocfs2_unlink(struct inode *dir,
898 898
899 dquot_initialize(dir); 899 dquot_initialize(dir);
900 900
901 BUG_ON(dentry->d_parent->d_inode != dir); 901 BUG_ON(d_inode(dentry->d_parent) != dir);
902 902
903 if (inode == osb->root_inode) 903 if (inode == osb->root_inode)
904 return -EPERM; 904 return -EPERM;
@@ -1209,8 +1209,8 @@ static int ocfs2_rename(struct inode *old_dir,
1209{ 1209{
1210 int status = 0, rename_lock = 0, parents_locked = 0, target_exists = 0; 1210 int status = 0, rename_lock = 0, parents_locked = 0, target_exists = 0;
1211 int old_child_locked = 0, new_child_locked = 0, update_dot_dot = 0; 1211 int old_child_locked = 0, new_child_locked = 0, update_dot_dot = 0;
1212 struct inode *old_inode = old_dentry->d_inode; 1212 struct inode *old_inode = d_inode(old_dentry);
1213 struct inode *new_inode = new_dentry->d_inode; 1213 struct inode *new_inode = d_inode(new_dentry);
1214 struct inode *orphan_dir = NULL; 1214 struct inode *orphan_dir = NULL;
1215 struct ocfs2_dinode *newfe = NULL; 1215 struct ocfs2_dinode *newfe = NULL;
1216 char orphan_name[OCFS2_ORPHAN_NAMELEN + 1]; 1216 char orphan_name[OCFS2_ORPHAN_NAMELEN + 1];
@@ -1454,7 +1454,7 @@ static int ocfs2_rename(struct inode *old_dir,
1454 should_add_orphan = true; 1454 should_add_orphan = true;
1455 } 1455 }
1456 } else { 1456 } else {
1457 BUG_ON(new_dentry->d_parent->d_inode != new_dir); 1457 BUG_ON(d_inode(new_dentry->d_parent) != new_dir);
1458 1458
1459 status = ocfs2_check_dir_for_entry(new_dir, 1459 status = ocfs2_check_dir_for_entry(new_dir,
1460 new_dentry->d_name.name, 1460 new_dentry->d_name.name,
diff --git a/fs/ocfs2/refcounttree.c b/fs/ocfs2/refcounttree.c
index df3a500789c7..d8c6af101f3f 100644
--- a/fs/ocfs2/refcounttree.c
+++ b/fs/ocfs2/refcounttree.c
@@ -4194,7 +4194,7 @@ static int __ocfs2_reflink(struct dentry *old_dentry,
4194 bool preserve) 4194 bool preserve)
4195{ 4195{
4196 int ret; 4196 int ret;
4197 struct inode *inode = old_dentry->d_inode; 4197 struct inode *inode = d_inode(old_dentry);
4198 struct buffer_head *new_bh = NULL; 4198 struct buffer_head *new_bh = NULL;
4199 4199
4200 if (OCFS2_I(inode)->ip_flags & OCFS2_INODE_SYSTEM_FILE) { 4200 if (OCFS2_I(inode)->ip_flags & OCFS2_INODE_SYSTEM_FILE) {
@@ -4263,7 +4263,7 @@ static int ocfs2_reflink(struct dentry *old_dentry, struct inode *dir,
4263 struct dentry *new_dentry, bool preserve) 4263 struct dentry *new_dentry, bool preserve)
4264{ 4264{
4265 int error; 4265 int error;
4266 struct inode *inode = old_dentry->d_inode; 4266 struct inode *inode = d_inode(old_dentry);
4267 struct buffer_head *old_bh = NULL; 4267 struct buffer_head *old_bh = NULL;
4268 struct inode *new_orphan_inode = NULL; 4268 struct inode *new_orphan_inode = NULL;
4269 struct posix_acl *default_acl, *acl; 4269 struct posix_acl *default_acl, *acl;
@@ -4357,7 +4357,7 @@ out:
4357/* copied from may_create in VFS. */ 4357/* copied from may_create in VFS. */
4358static inline int ocfs2_may_create(struct inode *dir, struct dentry *child) 4358static inline int ocfs2_may_create(struct inode *dir, struct dentry *child)
4359{ 4359{
4360 if (child->d_inode) 4360 if (d_really_is_positive(child))
4361 return -EEXIST; 4361 return -EEXIST;
4362 if (IS_DEADDIR(dir)) 4362 if (IS_DEADDIR(dir))
4363 return -ENOENT; 4363 return -ENOENT;
@@ -4375,7 +4375,7 @@ static inline int ocfs2_may_create(struct inode *dir, struct dentry *child)
4375static int ocfs2_vfs_reflink(struct dentry *old_dentry, struct inode *dir, 4375static int ocfs2_vfs_reflink(struct dentry *old_dentry, struct inode *dir,
4376 struct dentry *new_dentry, bool preserve) 4376 struct dentry *new_dentry, bool preserve)
4377{ 4377{
4378 struct inode *inode = old_dentry->d_inode; 4378 struct inode *inode = d_inode(old_dentry);
4379 int error; 4379 int error;
4380 4380
4381 if (!inode) 4381 if (!inode)
@@ -4463,7 +4463,7 @@ int ocfs2_reflink_ioctl(struct inode *inode,
4463 } 4463 }
4464 4464
4465 error = ocfs2_vfs_reflink(old_path.dentry, 4465 error = ocfs2_vfs_reflink(old_path.dentry,
4466 new_path.dentry->d_inode, 4466 d_inode(new_path.dentry),
4467 new_dentry, preserve); 4467 new_dentry, preserve);
4468out_dput: 4468out_dput:
4469 done_path_create(&new_path, new_dentry); 4469 done_path_create(&new_path, new_dentry);
diff --git a/fs/ocfs2/xattr.c b/fs/ocfs2/xattr.c
index 4ca7533be479..d03bfbf3d27d 100644
--- a/fs/ocfs2/xattr.c
+++ b/fs/ocfs2/xattr.c
@@ -1020,7 +1020,7 @@ ssize_t ocfs2_listxattr(struct dentry *dentry,
1020 int ret = 0, i_ret = 0, b_ret = 0; 1020 int ret = 0, i_ret = 0, b_ret = 0;
1021 struct buffer_head *di_bh = NULL; 1021 struct buffer_head *di_bh = NULL;
1022 struct ocfs2_dinode *di = NULL; 1022 struct ocfs2_dinode *di = NULL;
1023 struct ocfs2_inode_info *oi = OCFS2_I(dentry->d_inode); 1023 struct ocfs2_inode_info *oi = OCFS2_I(d_inode(dentry));
1024 1024
1025 if (!ocfs2_supports_xattr(OCFS2_SB(dentry->d_sb))) 1025 if (!ocfs2_supports_xattr(OCFS2_SB(dentry->d_sb)))
1026 return -EOPNOTSUPP; 1026 return -EOPNOTSUPP;
@@ -1028,7 +1028,7 @@ ssize_t ocfs2_listxattr(struct dentry *dentry,
1028 if (!(oi->ip_dyn_features & OCFS2_HAS_XATTR_FL)) 1028 if (!(oi->ip_dyn_features & OCFS2_HAS_XATTR_FL))
1029 return ret; 1029 return ret;
1030 1030
1031 ret = ocfs2_inode_lock(dentry->d_inode, &di_bh, 0); 1031 ret = ocfs2_inode_lock(d_inode(dentry), &di_bh, 0);
1032 if (ret < 0) { 1032 if (ret < 0) {
1033 mlog_errno(ret); 1033 mlog_errno(ret);
1034 return ret; 1034 return ret;
@@ -1037,7 +1037,7 @@ ssize_t ocfs2_listxattr(struct dentry *dentry,
1037 di = (struct ocfs2_dinode *)di_bh->b_data; 1037 di = (struct ocfs2_dinode *)di_bh->b_data;
1038 1038
1039 down_read(&oi->ip_xattr_sem); 1039 down_read(&oi->ip_xattr_sem);
1040 i_ret = ocfs2_xattr_ibody_list(dentry->d_inode, di, buffer, size); 1040 i_ret = ocfs2_xattr_ibody_list(d_inode(dentry), di, buffer, size);
1041 if (i_ret < 0) 1041 if (i_ret < 0)
1042 b_ret = 0; 1042 b_ret = 0;
1043 else { 1043 else {
@@ -1045,13 +1045,13 @@ ssize_t ocfs2_listxattr(struct dentry *dentry,
1045 buffer += i_ret; 1045 buffer += i_ret;
1046 size -= i_ret; 1046 size -= i_ret;
1047 } 1047 }
1048 b_ret = ocfs2_xattr_block_list(dentry->d_inode, di, 1048 b_ret = ocfs2_xattr_block_list(d_inode(dentry), di,
1049 buffer, size); 1049 buffer, size);
1050 if (b_ret < 0) 1050 if (b_ret < 0)
1051 i_ret = 0; 1051 i_ret = 0;
1052 } 1052 }
1053 up_read(&oi->ip_xattr_sem); 1053 up_read(&oi->ip_xattr_sem);
1054 ocfs2_inode_unlock(dentry->d_inode, 0); 1054 ocfs2_inode_unlock(d_inode(dentry), 0);
1055 1055
1056 brelse(di_bh); 1056 brelse(di_bh);
1057 1057
@@ -7257,7 +7257,7 @@ static int ocfs2_xattr_security_get(struct dentry *dentry, const char *name,
7257{ 7257{
7258 if (strcmp(name, "") == 0) 7258 if (strcmp(name, "") == 0)
7259 return -EINVAL; 7259 return -EINVAL;
7260 return ocfs2_xattr_get(dentry->d_inode, OCFS2_XATTR_INDEX_SECURITY, 7260 return ocfs2_xattr_get(d_inode(dentry), OCFS2_XATTR_INDEX_SECURITY,
7261 name, buffer, size); 7261 name, buffer, size);
7262} 7262}
7263 7263
@@ -7267,7 +7267,7 @@ static int ocfs2_xattr_security_set(struct dentry *dentry, const char *name,
7267 if (strcmp(name, "") == 0) 7267 if (strcmp(name, "") == 0)
7268 return -EINVAL; 7268 return -EINVAL;
7269 7269
7270 return ocfs2_xattr_set(dentry->d_inode, OCFS2_XATTR_INDEX_SECURITY, 7270 return ocfs2_xattr_set(d_inode(dentry), OCFS2_XATTR_INDEX_SECURITY,
7271 name, value, size, flags); 7271 name, value, size, flags);
7272} 7272}
7273 7273
@@ -7347,7 +7347,7 @@ static int ocfs2_xattr_trusted_get(struct dentry *dentry, const char *name,
7347{ 7347{
7348 if (strcmp(name, "") == 0) 7348 if (strcmp(name, "") == 0)
7349 return -EINVAL; 7349 return -EINVAL;
7350 return ocfs2_xattr_get(dentry->d_inode, OCFS2_XATTR_INDEX_TRUSTED, 7350 return ocfs2_xattr_get(d_inode(dentry), OCFS2_XATTR_INDEX_TRUSTED,
7351 name, buffer, size); 7351 name, buffer, size);
7352} 7352}
7353 7353
@@ -7357,7 +7357,7 @@ static int ocfs2_xattr_trusted_set(struct dentry *dentry, const char *name,
7357 if (strcmp(name, "") == 0) 7357 if (strcmp(name, "") == 0)
7358 return -EINVAL; 7358 return -EINVAL;
7359 7359
7360 return ocfs2_xattr_set(dentry->d_inode, OCFS2_XATTR_INDEX_TRUSTED, 7360 return ocfs2_xattr_set(d_inode(dentry), OCFS2_XATTR_INDEX_TRUSTED,
7361 name, value, size, flags); 7361 name, value, size, flags);
7362} 7362}
7363 7363
@@ -7399,7 +7399,7 @@ static int ocfs2_xattr_user_get(struct dentry *dentry, const char *name,
7399 return -EINVAL; 7399 return -EINVAL;
7400 if (osb->s_mount_opt & OCFS2_MOUNT_NOUSERXATTR) 7400 if (osb->s_mount_opt & OCFS2_MOUNT_NOUSERXATTR)
7401 return -EOPNOTSUPP; 7401 return -EOPNOTSUPP;
7402 return ocfs2_xattr_get(dentry->d_inode, OCFS2_XATTR_INDEX_USER, name, 7402 return ocfs2_xattr_get(d_inode(dentry), OCFS2_XATTR_INDEX_USER, name,
7403 buffer, size); 7403 buffer, size);
7404} 7404}
7405 7405
@@ -7413,7 +7413,7 @@ static int ocfs2_xattr_user_set(struct dentry *dentry, const char *name,
7413 if (osb->s_mount_opt & OCFS2_MOUNT_NOUSERXATTR) 7413 if (osb->s_mount_opt & OCFS2_MOUNT_NOUSERXATTR)
7414 return -EOPNOTSUPP; 7414 return -EOPNOTSUPP;
7415 7415
7416 return ocfs2_xattr_set(dentry->d_inode, OCFS2_XATTR_INDEX_USER, 7416 return ocfs2_xattr_set(d_inode(dentry), OCFS2_XATTR_INDEX_USER,
7417 name, value, size, flags); 7417 name, value, size, flags);
7418} 7418}
7419 7419
diff --git a/fs/omfs/dir.c b/fs/omfs/dir.c
index 1b8e9e8405b2..f833bf8d5792 100644
--- a/fs/omfs/dir.c
+++ b/fs/omfs/dir.c
@@ -110,7 +110,7 @@ int omfs_make_empty(struct inode *inode, struct super_block *sb)
110 110
111static int omfs_add_link(struct dentry *dentry, struct inode *inode) 111static int omfs_add_link(struct dentry *dentry, struct inode *inode)
112{ 112{
113 struct inode *dir = dentry->d_parent->d_inode; 113 struct inode *dir = d_inode(dentry->d_parent);
114 const char *name = dentry->d_name.name; 114 const char *name = dentry->d_name.name;
115 int namelen = dentry->d_name.len; 115 int namelen = dentry->d_name.len;
116 struct omfs_inode *oi; 116 struct omfs_inode *oi;
@@ -155,7 +155,7 @@ out:
155 155
156static int omfs_delete_entry(struct dentry *dentry) 156static int omfs_delete_entry(struct dentry *dentry)
157{ 157{
158 struct inode *dir = dentry->d_parent->d_inode; 158 struct inode *dir = d_inode(dentry->d_parent);
159 struct inode *dirty; 159 struct inode *dirty;
160 const char *name = dentry->d_name.name; 160 const char *name = dentry->d_name.name;
161 int namelen = dentry->d_name.len; 161 int namelen = dentry->d_name.len;
@@ -237,7 +237,7 @@ static int omfs_dir_is_empty(struct inode *inode)
237 237
238static int omfs_remove(struct inode *dir, struct dentry *dentry) 238static int omfs_remove(struct inode *dir, struct dentry *dentry)
239{ 239{
240 struct inode *inode = dentry->d_inode; 240 struct inode *inode = d_inode(dentry);
241 int ret; 241 int ret;
242 242
243 243
@@ -373,8 +373,8 @@ static bool omfs_fill_chain(struct inode *dir, struct dir_context *ctx,
373static int omfs_rename(struct inode *old_dir, struct dentry *old_dentry, 373static int omfs_rename(struct inode *old_dir, struct dentry *old_dentry,
374 struct inode *new_dir, struct dentry *new_dentry) 374 struct inode *new_dir, struct dentry *new_dentry)
375{ 375{
376 struct inode *new_inode = new_dentry->d_inode; 376 struct inode *new_inode = d_inode(new_dentry);
377 struct inode *old_inode = old_dentry->d_inode; 377 struct inode *old_inode = d_inode(old_dentry);
378 int err; 378 int err;
379 379
380 if (new_inode) { 380 if (new_inode) {
diff --git a/fs/omfs/file.c b/fs/omfs/file.c
index f993be7f2156..d9e26cfbb793 100644
--- a/fs/omfs/file.c
+++ b/fs/omfs/file.c
@@ -346,7 +346,7 @@ const struct file_operations omfs_file_operations = {
346 346
347static int omfs_setattr(struct dentry *dentry, struct iattr *attr) 347static int omfs_setattr(struct dentry *dentry, struct iattr *attr)
348{ 348{
349 struct inode *inode = dentry->d_inode; 349 struct inode *inode = d_inode(dentry);
350 int error; 350 int error;
351 351
352 error = inode_change_ok(inode, attr); 352 error = inode_change_ok(inode, attr);
diff --git a/fs/open.c b/fs/open.c
index 6796f04d6032..98e5a52dc68c 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -231,8 +231,7 @@ int vfs_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
231 return -EINVAL; 231 return -EINVAL;
232 232
233 /* Return error if mode is not supported */ 233 /* Return error if mode is not supported */
234 if (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE | 234 if (mode & ~FALLOC_FL_SUPPORTED_MASK)
235 FALLOC_FL_COLLAPSE_RANGE | FALLOC_FL_ZERO_RANGE))
236 return -EOPNOTSUPP; 235 return -EOPNOTSUPP;
237 236
238 /* Punch hole and zero range are mutually exclusive */ 237 /* Punch hole and zero range are mutually exclusive */
@@ -250,6 +249,11 @@ int vfs_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
250 (mode & ~FALLOC_FL_COLLAPSE_RANGE)) 249 (mode & ~FALLOC_FL_COLLAPSE_RANGE))
251 return -EINVAL; 250 return -EINVAL;
252 251
252 /* Insert range should only be used exclusively. */
253 if ((mode & FALLOC_FL_INSERT_RANGE) &&
254 (mode & ~FALLOC_FL_INSERT_RANGE))
255 return -EINVAL;
256
253 if (!(file->f_mode & FMODE_WRITE)) 257 if (!(file->f_mode & FMODE_WRITE))
254 return -EBADF; 258 return -EBADF;
255 259
diff --git a/fs/pipe.c b/fs/pipe.c
index 822da5b7cff0..8865f7963700 100644
--- a/fs/pipe.c
+++ b/fs/pipe.c
@@ -627,7 +627,7 @@ static struct vfsmount *pipe_mnt __read_mostly;
627static char *pipefs_dname(struct dentry *dentry, char *buffer, int buflen) 627static char *pipefs_dname(struct dentry *dentry, char *buffer, int buflen)
628{ 628{
629 return dynamic_dname(dentry, buffer, buflen, "pipe:[%lu]", 629 return dynamic_dname(dentry, buffer, buflen, "pipe:[%lu]",
630 dentry->d_inode->i_ino); 630 d_inode(dentry)->i_ino);
631} 631}
632 632
633static const struct dentry_operations pipefs_dentry_operations = { 633static const struct dentry_operations pipefs_dentry_operations = {
diff --git a/fs/posix_acl.c b/fs/posix_acl.c
index 3a48bb789c9f..84bb65b83570 100644
--- a/fs/posix_acl.c
+++ b/fs/posix_acl.c
@@ -774,12 +774,12 @@ posix_acl_xattr_get(struct dentry *dentry, const char *name,
774 struct posix_acl *acl; 774 struct posix_acl *acl;
775 int error; 775 int error;
776 776
777 if (!IS_POSIXACL(dentry->d_inode)) 777 if (!IS_POSIXACL(d_backing_inode(dentry)))
778 return -EOPNOTSUPP; 778 return -EOPNOTSUPP;
779 if (d_is_symlink(dentry)) 779 if (d_is_symlink(dentry))
780 return -EOPNOTSUPP; 780 return -EOPNOTSUPP;
781 781
782 acl = get_acl(dentry->d_inode, type); 782 acl = get_acl(d_backing_inode(dentry), type);
783 if (IS_ERR(acl)) 783 if (IS_ERR(acl))
784 return PTR_ERR(acl); 784 return PTR_ERR(acl);
785 if (acl == NULL) 785 if (acl == NULL)
@@ -795,7 +795,7 @@ static int
795posix_acl_xattr_set(struct dentry *dentry, const char *name, 795posix_acl_xattr_set(struct dentry *dentry, const char *name,
796 const void *value, size_t size, int flags, int type) 796 const void *value, size_t size, int flags, int type)
797{ 797{
798 struct inode *inode = dentry->d_inode; 798 struct inode *inode = d_backing_inode(dentry);
799 struct posix_acl *acl = NULL; 799 struct posix_acl *acl = NULL;
800 int ret; 800 int ret;
801 801
@@ -834,7 +834,7 @@ posix_acl_xattr_list(struct dentry *dentry, char *list, size_t list_size,
834 const char *xname; 834 const char *xname;
835 size_t size; 835 size_t size;
836 836
837 if (!IS_POSIXACL(dentry->d_inode)) 837 if (!IS_POSIXACL(d_backing_inode(dentry)))
838 return -EOPNOTSUPP; 838 return -EOPNOTSUPP;
839 if (d_is_symlink(dentry)) 839 if (d_is_symlink(dentry))
840 return -EOPNOTSUPP; 840 return -EOPNOTSUPP;
diff --git a/fs/proc/base.c b/fs/proc/base.c
index 7a3b82f986dd..093ca14f5701 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -169,7 +169,7 @@ static int get_task_root(struct task_struct *task, struct path *root)
169 169
170static int proc_cwd_link(struct dentry *dentry, struct path *path) 170static int proc_cwd_link(struct dentry *dentry, struct path *path)
171{ 171{
172 struct task_struct *task = get_proc_task(dentry->d_inode); 172 struct task_struct *task = get_proc_task(d_inode(dentry));
173 int result = -ENOENT; 173 int result = -ENOENT;
174 174
175 if (task) { 175 if (task) {
@@ -186,7 +186,7 @@ static int proc_cwd_link(struct dentry *dentry, struct path *path)
186 186
187static int proc_root_link(struct dentry *dentry, struct path *path) 187static int proc_root_link(struct dentry *dentry, struct path *path)
188{ 188{
189 struct task_struct *task = get_proc_task(dentry->d_inode); 189 struct task_struct *task = get_proc_task(d_inode(dentry));
190 int result = -ENOENT; 190 int result = -ENOENT;
191 191
192 if (task) { 192 if (task) {
@@ -514,7 +514,7 @@ static int proc_fd_access_allowed(struct inode *inode)
514int proc_setattr(struct dentry *dentry, struct iattr *attr) 514int proc_setattr(struct dentry *dentry, struct iattr *attr)
515{ 515{
516 int error; 516 int error;
517 struct inode *inode = dentry->d_inode; 517 struct inode *inode = d_inode(dentry);
518 518
519 if (attr->ia_valid & ATTR_MODE) 519 if (attr->ia_valid & ATTR_MODE)
520 return -EPERM; 520 return -EPERM;
@@ -1362,7 +1362,7 @@ static int proc_exe_link(struct dentry *dentry, struct path *exe_path)
1362 struct mm_struct *mm; 1362 struct mm_struct *mm;
1363 struct file *exe_file; 1363 struct file *exe_file;
1364 1364
1365 task = get_proc_task(dentry->d_inode); 1365 task = get_proc_task(d_inode(dentry));
1366 if (!task) 1366 if (!task)
1367 return -ENOENT; 1367 return -ENOENT;
1368 mm = get_task_mm(task); 1368 mm = get_task_mm(task);
@@ -1382,7 +1382,7 @@ static int proc_exe_link(struct dentry *dentry, struct path *exe_path)
1382 1382
1383static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd) 1383static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
1384{ 1384{
1385 struct inode *inode = dentry->d_inode; 1385 struct inode *inode = d_inode(dentry);
1386 struct path path; 1386 struct path path;
1387 int error = -EACCES; 1387 int error = -EACCES;
1388 1388
@@ -1427,7 +1427,7 @@ static int do_proc_readlink(struct path *path, char __user *buffer, int buflen)
1427static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int buflen) 1427static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int buflen)
1428{ 1428{
1429 int error = -EACCES; 1429 int error = -EACCES;
1430 struct inode *inode = dentry->d_inode; 1430 struct inode *inode = d_inode(dentry);
1431 struct path path; 1431 struct path path;
1432 1432
1433 /* Are we allowed to snoop on the tasks file descriptors? */ 1433 /* Are we allowed to snoop on the tasks file descriptors? */
@@ -1497,7 +1497,7 @@ out_unlock:
1497 1497
1498int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat) 1498int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
1499{ 1499{
1500 struct inode *inode = dentry->d_inode; 1500 struct inode *inode = d_inode(dentry);
1501 struct task_struct *task; 1501 struct task_struct *task;
1502 const struct cred *cred; 1502 const struct cred *cred;
1503 struct pid_namespace *pid = dentry->d_sb->s_fs_info; 1503 struct pid_namespace *pid = dentry->d_sb->s_fs_info;
@@ -1554,7 +1554,7 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
1554 if (flags & LOOKUP_RCU) 1554 if (flags & LOOKUP_RCU)
1555 return -ECHILD; 1555 return -ECHILD;
1556 1556
1557 inode = dentry->d_inode; 1557 inode = d_inode(dentry);
1558 task = get_proc_task(inode); 1558 task = get_proc_task(inode);
1559 1559
1560 if (task) { 1560 if (task) {
@@ -1588,7 +1588,7 @@ int pid_delete_dentry(const struct dentry *dentry)
1588 * If so, then don't put the dentry on the lru list, 1588 * If so, then don't put the dentry on the lru list,
1589 * kill it immediately. 1589 * kill it immediately.
1590 */ 1590 */
1591 return proc_inode_is_dead(dentry->d_inode); 1591 return proc_inode_is_dead(d_inode(dentry));
1592} 1592}
1593 1593
1594const struct dentry_operations pid_dentry_operations = 1594const struct dentry_operations pid_dentry_operations =
@@ -1626,12 +1626,12 @@ bool proc_fill_cache(struct file *file, struct dir_context *ctx,
1626 child = d_alloc(dir, &qname); 1626 child = d_alloc(dir, &qname);
1627 if (!child) 1627 if (!child)
1628 goto end_instantiate; 1628 goto end_instantiate;
1629 if (instantiate(dir->d_inode, child, task, ptr) < 0) { 1629 if (instantiate(d_inode(dir), child, task, ptr) < 0) {
1630 dput(child); 1630 dput(child);
1631 goto end_instantiate; 1631 goto end_instantiate;
1632 } 1632 }
1633 } 1633 }
1634 inode = child->d_inode; 1634 inode = d_inode(child);
1635 ino = inode->i_ino; 1635 ino = inode->i_ino;
1636 type = inode->i_mode >> 12; 1636 type = inode->i_mode >> 12;
1637 dput(child); 1637 dput(child);
@@ -1674,7 +1674,7 @@ static int map_files_d_revalidate(struct dentry *dentry, unsigned int flags)
1674 goto out_notask; 1674 goto out_notask;
1675 } 1675 }
1676 1676
1677 inode = dentry->d_inode; 1677 inode = d_inode(dentry);
1678 task = get_proc_task(inode); 1678 task = get_proc_task(inode);
1679 if (!task) 1679 if (!task)
1680 goto out_notask; 1680 goto out_notask;
@@ -1727,7 +1727,7 @@ static int proc_map_files_get_link(struct dentry *dentry, struct path *path)
1727 int rc; 1727 int rc;
1728 1728
1729 rc = -ENOENT; 1729 rc = -ENOENT;
1730 task = get_proc_task(dentry->d_inode); 1730 task = get_proc_task(d_inode(dentry));
1731 if (!task) 1731 if (!task)
1732 goto out; 1732 goto out;
1733 1733
@@ -2863,13 +2863,13 @@ int proc_pid_readdir(struct file *file, struct dir_context *ctx)
2863 return 0; 2863 return 0;
2864 2864
2865 if (pos == TGID_OFFSET - 2) { 2865 if (pos == TGID_OFFSET - 2) {
2866 struct inode *inode = ns->proc_self->d_inode; 2866 struct inode *inode = d_inode(ns->proc_self);
2867 if (!dir_emit(ctx, "self", 4, inode->i_ino, DT_LNK)) 2867 if (!dir_emit(ctx, "self", 4, inode->i_ino, DT_LNK))
2868 return 0; 2868 return 0;
2869 ctx->pos = pos = pos + 1; 2869 ctx->pos = pos = pos + 1;
2870 } 2870 }
2871 if (pos == TGID_OFFSET - 1) { 2871 if (pos == TGID_OFFSET - 1) {
2872 struct inode *inode = ns->proc_thread_self->d_inode; 2872 struct inode *inode = d_inode(ns->proc_thread_self);
2873 if (!dir_emit(ctx, "thread-self", 11, inode->i_ino, DT_LNK)) 2873 if (!dir_emit(ctx, "thread-self", 11, inode->i_ino, DT_LNK))
2874 return 0; 2874 return 0;
2875 ctx->pos = pos = pos + 1; 2875 ctx->pos = pos = pos + 1;
@@ -3188,7 +3188,7 @@ static int proc_task_readdir(struct file *file, struct dir_context *ctx)
3188 3188
3189static int proc_task_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat) 3189static int proc_task_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
3190{ 3190{
3191 struct inode *inode = dentry->d_inode; 3191 struct inode *inode = d_inode(dentry);
3192 struct task_struct *p = get_proc_task(inode); 3192 struct task_struct *p = get_proc_task(inode);
3193 generic_fillattr(inode, stat); 3193 generic_fillattr(inode, stat);
3194 3194
diff --git a/fs/proc/fd.c b/fs/proc/fd.c
index af84ad04df77..6e5fcd00733e 100644
--- a/fs/proc/fd.c
+++ b/fs/proc/fd.c
@@ -91,7 +91,7 @@ static int tid_fd_revalidate(struct dentry *dentry, unsigned int flags)
91 if (flags & LOOKUP_RCU) 91 if (flags & LOOKUP_RCU)
92 return -ECHILD; 92 return -ECHILD;
93 93
94 inode = dentry->d_inode; 94 inode = d_inode(dentry);
95 task = get_proc_task(inode); 95 task = get_proc_task(inode);
96 fd = proc_fd(inode); 96 fd = proc_fd(inode);
97 97
@@ -151,14 +151,14 @@ static int proc_fd_link(struct dentry *dentry, struct path *path)
151 struct task_struct *task; 151 struct task_struct *task;
152 int ret = -ENOENT; 152 int ret = -ENOENT;
153 153
154 task = get_proc_task(dentry->d_inode); 154 task = get_proc_task(d_inode(dentry));
155 if (task) { 155 if (task) {
156 files = get_files_struct(task); 156 files = get_files_struct(task);
157 put_task_struct(task); 157 put_task_struct(task);
158 } 158 }
159 159
160 if (files) { 160 if (files) {
161 int fd = proc_fd(dentry->d_inode); 161 int fd = proc_fd(d_inode(dentry));
162 struct file *fd_file; 162 struct file *fd_file;
163 163
164 spin_lock(&files->file_lock); 164 spin_lock(&files->file_lock);
diff --git a/fs/proc/generic.c b/fs/proc/generic.c
index be65b2082135..df6327a2b865 100644
--- a/fs/proc/generic.c
+++ b/fs/proc/generic.c
@@ -101,7 +101,7 @@ static bool pde_subdir_insert(struct proc_dir_entry *dir,
101 101
102static int proc_notify_change(struct dentry *dentry, struct iattr *iattr) 102static int proc_notify_change(struct dentry *dentry, struct iattr *iattr)
103{ 103{
104 struct inode *inode = dentry->d_inode; 104 struct inode *inode = d_inode(dentry);
105 struct proc_dir_entry *de = PDE(inode); 105 struct proc_dir_entry *de = PDE(inode);
106 int error; 106 int error;
107 107
@@ -120,7 +120,7 @@ static int proc_notify_change(struct dentry *dentry, struct iattr *iattr)
120static int proc_getattr(struct vfsmount *mnt, struct dentry *dentry, 120static int proc_getattr(struct vfsmount *mnt, struct dentry *dentry,
121 struct kstat *stat) 121 struct kstat *stat)
122{ 122{
123 struct inode *inode = dentry->d_inode; 123 struct inode *inode = d_inode(dentry);
124 struct proc_dir_entry *de = PDE(inode); 124 struct proc_dir_entry *de = PDE(inode);
125 if (de && de->nlink) 125 if (de && de->nlink)
126 set_nlink(inode, de->nlink); 126 set_nlink(inode, de->nlink);
diff --git a/fs/proc/inode.c b/fs/proc/inode.c
index 7697b6621cfd..8272aaba1bb0 100644
--- a/fs/proc/inode.c
+++ b/fs/proc/inode.c
@@ -396,7 +396,7 @@ static const struct file_operations proc_reg_file_ops_no_compat = {
396 396
397static void *proc_follow_link(struct dentry *dentry, struct nameidata *nd) 397static void *proc_follow_link(struct dentry *dentry, struct nameidata *nd)
398{ 398{
399 struct proc_dir_entry *pde = PDE(dentry->d_inode); 399 struct proc_dir_entry *pde = PDE(d_inode(dentry));
400 if (unlikely(!use_pde(pde))) 400 if (unlikely(!use_pde(pde)))
401 return ERR_PTR(-EINVAL); 401 return ERR_PTR(-EINVAL);
402 nd_set_link(nd, pde->data); 402 nd_set_link(nd, pde->data);
diff --git a/fs/proc/namespaces.c b/fs/proc/namespaces.c
index c9eac4563fa8..e512642dbbdc 100644
--- a/fs/proc/namespaces.c
+++ b/fs/proc/namespaces.c
@@ -32,7 +32,7 @@ static const struct proc_ns_operations *ns_entries[] = {
32 32
33static void *proc_ns_follow_link(struct dentry *dentry, struct nameidata *nd) 33static void *proc_ns_follow_link(struct dentry *dentry, struct nameidata *nd)
34{ 34{
35 struct inode *inode = dentry->d_inode; 35 struct inode *inode = d_inode(dentry);
36 const struct proc_ns_operations *ns_ops = PROC_I(inode)->ns_ops; 36 const struct proc_ns_operations *ns_ops = PROC_I(inode)->ns_ops;
37 struct task_struct *task; 37 struct task_struct *task;
38 struct path ns_path; 38 struct path ns_path;
@@ -53,7 +53,7 @@ static void *proc_ns_follow_link(struct dentry *dentry, struct nameidata *nd)
53 53
54static int proc_ns_readlink(struct dentry *dentry, char __user *buffer, int buflen) 54static int proc_ns_readlink(struct dentry *dentry, char __user *buffer, int buflen)
55{ 55{
56 struct inode *inode = dentry->d_inode; 56 struct inode *inode = d_inode(dentry);
57 const struct proc_ns_operations *ns_ops = PROC_I(inode)->ns_ops; 57 const struct proc_ns_operations *ns_ops = PROC_I(inode)->ns_ops;
58 struct task_struct *task; 58 struct task_struct *task;
59 char name[50]; 59 char name[50];
diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
index 1bde894bc624..350984a19c83 100644
--- a/fs/proc/proc_net.c
+++ b/fs/proc/proc_net.c
@@ -142,7 +142,7 @@ static struct dentry *proc_tgid_net_lookup(struct inode *dir,
142static int proc_tgid_net_getattr(struct vfsmount *mnt, struct dentry *dentry, 142static int proc_tgid_net_getattr(struct vfsmount *mnt, struct dentry *dentry,
143 struct kstat *stat) 143 struct kstat *stat)
144{ 144{
145 struct inode *inode = dentry->d_inode; 145 struct inode *inode = d_inode(dentry);
146 struct net *net; 146 struct net *net;
147 147
148 net = get_proc_task_net(inode); 148 net = get_proc_task_net(inode);
diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
index f92d5dd578a4..fea2561d773b 100644
--- a/fs/proc/proc_sysctl.c
+++ b/fs/proc/proc_sysctl.c
@@ -604,7 +604,7 @@ static bool proc_sys_fill_cache(struct file *file,
604 return false; 604 return false;
605 } 605 }
606 } 606 }
607 inode = child->d_inode; 607 inode = d_inode(child);
608 ino = inode->i_ino; 608 ino = inode->i_ino;
609 type = inode->i_mode >> 12; 609 type = inode->i_mode >> 12;
610 dput(child); 610 dput(child);
@@ -710,7 +710,7 @@ static int proc_sys_permission(struct inode *inode, int mask)
710 710
711static int proc_sys_setattr(struct dentry *dentry, struct iattr *attr) 711static int proc_sys_setattr(struct dentry *dentry, struct iattr *attr)
712{ 712{
713 struct inode *inode = dentry->d_inode; 713 struct inode *inode = d_inode(dentry);
714 int error; 714 int error;
715 715
716 if (attr->ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID)) 716 if (attr->ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID))
@@ -727,7 +727,7 @@ static int proc_sys_setattr(struct dentry *dentry, struct iattr *attr)
727 727
728static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat) 728static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
729{ 729{
730 struct inode *inode = dentry->d_inode; 730 struct inode *inode = d_inode(dentry);
731 struct ctl_table_header *head = grab_header(inode); 731 struct ctl_table_header *head = grab_header(inode);
732 struct ctl_table *table = PROC_I(inode)->sysctl_entry; 732 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
733 733
@@ -773,12 +773,12 @@ static int proc_sys_revalidate(struct dentry *dentry, unsigned int flags)
773{ 773{
774 if (flags & LOOKUP_RCU) 774 if (flags & LOOKUP_RCU)
775 return -ECHILD; 775 return -ECHILD;
776 return !PROC_I(dentry->d_inode)->sysctl->unregistering; 776 return !PROC_I(d_inode(dentry))->sysctl->unregistering;
777} 777}
778 778
779static int proc_sys_delete(const struct dentry *dentry) 779static int proc_sys_delete(const struct dentry *dentry)
780{ 780{
781 return !!PROC_I(dentry->d_inode)->sysctl->unregistering; 781 return !!PROC_I(d_inode(dentry))->sysctl->unregistering;
782} 782}
783 783
784static int sysctl_is_seen(struct ctl_table_header *p) 784static int sysctl_is_seen(struct ctl_table_header *p)
@@ -805,7 +805,7 @@ static int proc_sys_compare(const struct dentry *parent, const struct dentry *de
805 /* Although proc doesn't have negative dentries, rcu-walk means 805 /* Although proc doesn't have negative dentries, rcu-walk means
806 * that inode here can be NULL */ 806 * that inode here can be NULL */
807 /* AV: can it, indeed? */ 807 /* AV: can it, indeed? */
808 inode = ACCESS_ONCE(dentry->d_inode); 808 inode = d_inode_rcu(dentry);
809 if (!inode) 809 if (!inode)
810 return 1; 810 return 1;
811 if (name->len != len) 811 if (name->len != len)
diff --git a/fs/proc/root.c b/fs/proc/root.c
index e74ac9f1a2c0..b7fa4bfe896a 100644
--- a/fs/proc/root.c
+++ b/fs/proc/root.c
@@ -195,7 +195,7 @@ void __init proc_root_init(void)
195static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat 195static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
196) 196)
197{ 197{
198 generic_fillattr(dentry->d_inode, stat); 198 generic_fillattr(d_inode(dentry), stat);
199 stat->nlink = proc_root.nlink + nr_processes(); 199 stat->nlink = proc_root.nlink + nr_processes();
200 return 0; 200 return 0;
201} 201}
diff --git a/fs/proc/self.c b/fs/proc/self.c
index 4348bb8907c2..6195b4a7c3b1 100644
--- a/fs/proc/self.c
+++ b/fs/proc/self.c
@@ -46,7 +46,7 @@ static unsigned self_inum;
46 46
47int proc_setup_self(struct super_block *s) 47int proc_setup_self(struct super_block *s)
48{ 48{
49 struct inode *root_inode = s->s_root->d_inode; 49 struct inode *root_inode = d_inode(s->s_root);
50 struct pid_namespace *ns = s->s_fs_info; 50 struct pid_namespace *ns = s->s_fs_info;
51 struct dentry *self; 51 struct dentry *self;
52 52
diff --git a/fs/proc/thread_self.c b/fs/proc/thread_self.c
index 59075b509df3..a8371993b4fb 100644
--- a/fs/proc/thread_self.c
+++ b/fs/proc/thread_self.c
@@ -47,7 +47,7 @@ static unsigned thread_self_inum;
47 47
48int proc_setup_thread_self(struct super_block *s) 48int proc_setup_thread_self(struct super_block *s)
49{ 49{
50 struct inode *root_inode = s->s_root->d_inode; 50 struct inode *root_inode = d_inode(s->s_root);
51 struct pid_namespace *ns = s->s_fs_info; 51 struct pid_namespace *ns = s->s_fs_info;
52 struct dentry *thread_self; 52 struct dentry *thread_self;
53 53
diff --git a/fs/pstore/inode.c b/fs/pstore/inode.c
index 56e1ffda4d89..dc43b5f29305 100644
--- a/fs/pstore/inode.c
+++ b/fs/pstore/inode.c
@@ -190,7 +190,7 @@ static const struct file_operations pstore_file_operations = {
190 */ 190 */
191static int pstore_unlink(struct inode *dir, struct dentry *dentry) 191static int pstore_unlink(struct inode *dir, struct dentry *dentry)
192{ 192{
193 struct pstore_private *p = dentry->d_inode->i_private; 193 struct pstore_private *p = d_inode(dentry)->i_private;
194 int err; 194 int err;
195 195
196 err = pstore_check_syslog_permissions(p); 196 err = pstore_check_syslog_permissions(p);
@@ -199,7 +199,7 @@ static int pstore_unlink(struct inode *dir, struct dentry *dentry)
199 199
200 if (p->psi->erase) 200 if (p->psi->erase)
201 p->psi->erase(p->type, p->id, p->count, 201 p->psi->erase(p->type, p->id, p->count,
202 dentry->d_inode->i_ctime, p->psi); 202 d_inode(dentry)->i_ctime, p->psi);
203 else 203 else
204 return -EPERM; 204 return -EPERM;
205 205
@@ -376,7 +376,7 @@ int pstore_mkfile(enum pstore_type_id type, char *psname, u64 id, int count,
376 break; 376 break;
377 } 377 }
378 378
379 mutex_lock(&root->d_inode->i_mutex); 379 mutex_lock(&d_inode(root)->i_mutex);
380 380
381 dentry = d_alloc_name(root, name); 381 dentry = d_alloc_name(root, name);
382 if (!dentry) 382 if (!dentry)
@@ -396,12 +396,12 @@ int pstore_mkfile(enum pstore_type_id type, char *psname, u64 id, int count,
396 list_add(&private->list, &allpstore); 396 list_add(&private->list, &allpstore);
397 spin_unlock_irqrestore(&allpstore_lock, flags); 397 spin_unlock_irqrestore(&allpstore_lock, flags);
398 398
399 mutex_unlock(&root->d_inode->i_mutex); 399 mutex_unlock(&d_inode(root)->i_mutex);
400 400
401 return 0; 401 return 0;
402 402
403fail_lockedalloc: 403fail_lockedalloc:
404 mutex_unlock(&root->d_inode->i_mutex); 404 mutex_unlock(&d_inode(root)->i_mutex);
405 kfree(private); 405 kfree(private);
406fail_alloc: 406fail_alloc:
407 iput(inode); 407 iput(inode);
diff --git a/fs/qnx6/inode.c b/fs/qnx6/inode.c
index 44e73923670d..32d2e1a9774c 100644
--- a/fs/qnx6/inode.c
+++ b/fs/qnx6/inode.c
@@ -182,7 +182,7 @@ static const char *qnx6_checkroot(struct super_block *s)
182 static char match_root[2][3] = {".\0\0", "..\0"}; 182 static char match_root[2][3] = {".\0\0", "..\0"};
183 int i, error = 0; 183 int i, error = 0;
184 struct qnx6_dir_entry *dir_entry; 184 struct qnx6_dir_entry *dir_entry;
185 struct inode *root = s->s_root->d_inode; 185 struct inode *root = d_inode(s->s_root);
186 struct address_space *mapping = root->i_mapping; 186 struct address_space *mapping = root->i_mapping;
187 struct page *page = read_mapping_page(mapping, 0, NULL); 187 struct page *page = read_mapping_page(mapping, 0, NULL);
188 if (IS_ERR(page)) 188 if (IS_ERR(page))
diff --git a/fs/quota/dquot.c b/fs/quota/dquot.c
index ecc25cf0ee6e..20d1f74561cf 100644
--- a/fs/quota/dquot.c
+++ b/fs/quota/dquot.c
@@ -2328,7 +2328,7 @@ int dquot_quota_on(struct super_block *sb, int type, int format_id,
2328 if (path->dentry->d_sb != sb) 2328 if (path->dentry->d_sb != sb)
2329 error = -EXDEV; 2329 error = -EXDEV;
2330 else 2330 else
2331 error = vfs_load_quota_inode(path->dentry->d_inode, type, 2331 error = vfs_load_quota_inode(d_inode(path->dentry), type,
2332 format_id, DQUOT_USAGE_ENABLED | 2332 format_id, DQUOT_USAGE_ENABLED |
2333 DQUOT_LIMITS_ENABLED); 2333 DQUOT_LIMITS_ENABLED);
2334 return error; 2334 return error;
@@ -2392,20 +2392,20 @@ int dquot_quota_on_mount(struct super_block *sb, char *qf_name,
2392 struct dentry *dentry; 2392 struct dentry *dentry;
2393 int error; 2393 int error;
2394 2394
2395 mutex_lock(&sb->s_root->d_inode->i_mutex); 2395 mutex_lock(&d_inode(sb->s_root)->i_mutex);
2396 dentry = lookup_one_len(qf_name, sb->s_root, strlen(qf_name)); 2396 dentry = lookup_one_len(qf_name, sb->s_root, strlen(qf_name));
2397 mutex_unlock(&sb->s_root->d_inode->i_mutex); 2397 mutex_unlock(&d_inode(sb->s_root)->i_mutex);
2398 if (IS_ERR(dentry)) 2398 if (IS_ERR(dentry))
2399 return PTR_ERR(dentry); 2399 return PTR_ERR(dentry);
2400 2400
2401 if (!dentry->d_inode) { 2401 if (d_really_is_negative(dentry)) {
2402 error = -ENOENT; 2402 error = -ENOENT;
2403 goto out; 2403 goto out;
2404 } 2404 }
2405 2405
2406 error = security_quota_on(dentry); 2406 error = security_quota_on(dentry);
2407 if (!error) 2407 if (!error)
2408 error = vfs_load_quota_inode(dentry->d_inode, type, format_id, 2408 error = vfs_load_quota_inode(d_inode(dentry), type, format_id,
2409 DQUOT_USAGE_ENABLED | DQUOT_LIMITS_ENABLED); 2409 DQUOT_USAGE_ENABLED | DQUOT_LIMITS_ENABLED);
2410 2410
2411out: 2411out:
diff --git a/fs/ramfs/file-nommu.c b/fs/ramfs/file-nommu.c
index 0b38befa69f3..ba1323a94924 100644
--- a/fs/ramfs/file-nommu.c
+++ b/fs/ramfs/file-nommu.c
@@ -163,7 +163,7 @@ static int ramfs_nommu_resize(struct inode *inode, loff_t newsize, loff_t size)
163 */ 163 */
164static int ramfs_nommu_setattr(struct dentry *dentry, struct iattr *ia) 164static int ramfs_nommu_setattr(struct dentry *dentry, struct iattr *ia)
165{ 165{
166 struct inode *inode = dentry->d_inode; 166 struct inode *inode = d_inode(dentry);
167 unsigned int old_ia_valid = ia->ia_valid; 167 unsigned int old_ia_valid = ia->ia_valid;
168 int ret = 0; 168 int ret = 0;
169 169
diff --git a/fs/reiserfs/dir.c b/fs/reiserfs/dir.c
index 0a7dc941aaf4..4a024e2ceb9f 100644
--- a/fs/reiserfs/dir.c
+++ b/fs/reiserfs/dir.c
@@ -53,8 +53,8 @@ static int reiserfs_dir_fsync(struct file *filp, loff_t start, loff_t end,
53static inline bool is_privroot_deh(struct inode *dir, struct reiserfs_de_head *deh) 53static inline bool is_privroot_deh(struct inode *dir, struct reiserfs_de_head *deh)
54{ 54{
55 struct dentry *privroot = REISERFS_SB(dir->i_sb)->priv_root; 55 struct dentry *privroot = REISERFS_SB(dir->i_sb)->priv_root;
56 return (privroot->d_inode && 56 return (d_really_is_positive(privroot) &&
57 deh->deh_objectid == INODE_PKEY(privroot->d_inode)->k_objectid); 57 deh->deh_objectid == INODE_PKEY(d_inode(privroot))->k_objectid);
58} 58}
59 59
60int reiserfs_readdir_inode(struct inode *inode, struct dir_context *ctx) 60int reiserfs_readdir_inode(struct inode *inode, struct dir_context *ctx)
diff --git a/fs/reiserfs/inode.c b/fs/reiserfs/inode.c
index 742242b60972..f6f2fbad9777 100644
--- a/fs/reiserfs/inode.c
+++ b/fs/reiserfs/inode.c
@@ -3308,7 +3308,7 @@ static ssize_t reiserfs_direct_IO(struct kiocb *iocb, struct iov_iter *iter,
3308 3308
3309int reiserfs_setattr(struct dentry *dentry, struct iattr *attr) 3309int reiserfs_setattr(struct dentry *dentry, struct iattr *attr)
3310{ 3310{
3311 struct inode *inode = dentry->d_inode; 3311 struct inode *inode = d_inode(dentry);
3312 unsigned int ia_valid; 3312 unsigned int ia_valid;
3313 int error; 3313 int error;
3314 3314
diff --git a/fs/reiserfs/namei.c b/fs/reiserfs/namei.c
index cd11358b10c7..b55a074653d7 100644
--- a/fs/reiserfs/namei.c
+++ b/fs/reiserfs/namei.c
@@ -400,7 +400,7 @@ struct dentry *reiserfs_get_parent(struct dentry *child)
400 struct inode *inode = NULL; 400 struct inode *inode = NULL;
401 struct reiserfs_dir_entry de; 401 struct reiserfs_dir_entry de;
402 INITIALIZE_PATH(path_to_entry); 402 INITIALIZE_PATH(path_to_entry);
403 struct inode *dir = child->d_inode; 403 struct inode *dir = d_inode(child);
404 404
405 if (dir->i_nlink == 0) { 405 if (dir->i_nlink == 0) {
406 return ERR_PTR(-ENOENT); 406 return ERR_PTR(-ENOENT);
@@ -917,7 +917,7 @@ static int reiserfs_rmdir(struct inode *dir, struct dentry *dentry)
917 goto end_rmdir; 917 goto end_rmdir;
918 } 918 }
919 919
920 inode = dentry->d_inode; 920 inode = d_inode(dentry);
921 921
922 reiserfs_update_inode_transaction(inode); 922 reiserfs_update_inode_transaction(inode);
923 reiserfs_update_inode_transaction(dir); 923 reiserfs_update_inode_transaction(dir);
@@ -987,7 +987,7 @@ static int reiserfs_unlink(struct inode *dir, struct dentry *dentry)
987 987
988 dquot_initialize(dir); 988 dquot_initialize(dir);
989 989
990 inode = dentry->d_inode; 990 inode = d_inode(dentry);
991 991
992 /* 992 /*
993 * in this transaction we can be doing at max two balancings and 993 * in this transaction we can be doing at max two balancings and
@@ -1174,7 +1174,7 @@ static int reiserfs_link(struct dentry *old_dentry, struct inode *dir,
1174 struct dentry *dentry) 1174 struct dentry *dentry)
1175{ 1175{
1176 int retval; 1176 int retval;
1177 struct inode *inode = old_dentry->d_inode; 1177 struct inode *inode = d_inode(old_dentry);
1178 struct reiserfs_transaction_handle th; 1178 struct reiserfs_transaction_handle th;
1179 /* 1179 /*
1180 * We need blocks for transaction + update of quotas for 1180 * We need blocks for transaction + update of quotas for
@@ -1311,8 +1311,8 @@ static int reiserfs_rename(struct inode *old_dir, struct dentry *old_dentry,
1311 dquot_initialize(old_dir); 1311 dquot_initialize(old_dir);
1312 dquot_initialize(new_dir); 1312 dquot_initialize(new_dir);
1313 1313
1314 old_inode = old_dentry->d_inode; 1314 old_inode = d_inode(old_dentry);
1315 new_dentry_inode = new_dentry->d_inode; 1315 new_dentry_inode = d_inode(new_dentry);
1316 1316
1317 /* 1317 /*
1318 * make sure that oldname still exists and points to an object we 1318 * make sure that oldname still exists and points to an object we
diff --git a/fs/reiserfs/super.c b/fs/reiserfs/super.c
index 68b5f182984e..0111ad0466ed 100644
--- a/fs/reiserfs/super.c
+++ b/fs/reiserfs/super.c
@@ -1687,7 +1687,7 @@ static __u32 find_hash_out(struct super_block *s)
1687 __u32 hash = DEFAULT_HASH; 1687 __u32 hash = DEFAULT_HASH;
1688 __u32 deh_hashval, teahash, r5hash, yurahash; 1688 __u32 deh_hashval, teahash, r5hash, yurahash;
1689 1689
1690 inode = s->s_root->d_inode; 1690 inode = d_inode(s->s_root);
1691 1691
1692 make_cpu_key(&key, inode, ~0, TYPE_DIRENTRY, 3); 1692 make_cpu_key(&key, inode, ~0, TYPE_DIRENTRY, 3);
1693 retval = search_by_entry_key(s, &key, &path, &de); 1693 retval = search_by_entry_key(s, &key, &path, &de);
@@ -2347,7 +2347,7 @@ static int reiserfs_quota_on(struct super_block *sb, int type, int format_id,
2347 err = -EXDEV; 2347 err = -EXDEV;
2348 goto out; 2348 goto out;
2349 } 2349 }
2350 inode = path->dentry->d_inode; 2350 inode = d_inode(path->dentry);
2351 /* 2351 /*
2352 * We must not pack tails for quota files on reiserfs for quota 2352 * We must not pack tails for quota files on reiserfs for quota
2353 * IO to work 2353 * IO to work
diff --git a/fs/reiserfs/xattr.c b/fs/reiserfs/xattr.c
index 4e781e697c90..e87f9b52bf06 100644
--- a/fs/reiserfs/xattr.c
+++ b/fs/reiserfs/xattr.c
@@ -87,9 +87,9 @@ static int xattr_unlink(struct inode *dir, struct dentry *dentry)
87 87
88 BUG_ON(!mutex_is_locked(&dir->i_mutex)); 88 BUG_ON(!mutex_is_locked(&dir->i_mutex));
89 89
90 mutex_lock_nested(&dentry->d_inode->i_mutex, I_MUTEX_CHILD); 90 mutex_lock_nested(&d_inode(dentry)->i_mutex, I_MUTEX_CHILD);
91 error = dir->i_op->unlink(dir, dentry); 91 error = dir->i_op->unlink(dir, dentry);
92 mutex_unlock(&dentry->d_inode->i_mutex); 92 mutex_unlock(&d_inode(dentry)->i_mutex);
93 93
94 if (!error) 94 if (!error)
95 d_delete(dentry); 95 d_delete(dentry);
@@ -102,11 +102,11 @@ static int xattr_rmdir(struct inode *dir, struct dentry *dentry)
102 102
103 BUG_ON(!mutex_is_locked(&dir->i_mutex)); 103 BUG_ON(!mutex_is_locked(&dir->i_mutex));
104 104
105 mutex_lock_nested(&dentry->d_inode->i_mutex, I_MUTEX_CHILD); 105 mutex_lock_nested(&d_inode(dentry)->i_mutex, I_MUTEX_CHILD);
106 error = dir->i_op->rmdir(dir, dentry); 106 error = dir->i_op->rmdir(dir, dentry);
107 if (!error) 107 if (!error)
108 dentry->d_inode->i_flags |= S_DEAD; 108 d_inode(dentry)->i_flags |= S_DEAD;
109 mutex_unlock(&dentry->d_inode->i_mutex); 109 mutex_unlock(&d_inode(dentry)->i_mutex);
110 if (!error) 110 if (!error)
111 d_delete(dentry); 111 d_delete(dentry);
112 112
@@ -120,26 +120,26 @@ static struct dentry *open_xa_root(struct super_block *sb, int flags)
120 struct dentry *privroot = REISERFS_SB(sb)->priv_root; 120 struct dentry *privroot = REISERFS_SB(sb)->priv_root;
121 struct dentry *xaroot; 121 struct dentry *xaroot;
122 122
123 if (!privroot->d_inode) 123 if (d_really_is_negative(privroot))
124 return ERR_PTR(-ENODATA); 124 return ERR_PTR(-ENODATA);
125 125
126 mutex_lock_nested(&privroot->d_inode->i_mutex, I_MUTEX_XATTR); 126 mutex_lock_nested(&d_inode(privroot)->i_mutex, I_MUTEX_XATTR);
127 127
128 xaroot = dget(REISERFS_SB(sb)->xattr_root); 128 xaroot = dget(REISERFS_SB(sb)->xattr_root);
129 if (!xaroot) 129 if (!xaroot)
130 xaroot = ERR_PTR(-ENODATA); 130 xaroot = ERR_PTR(-ENODATA);
131 else if (!xaroot->d_inode) { 131 else if (d_really_is_negative(xaroot)) {
132 int err = -ENODATA; 132 int err = -ENODATA;
133 133
134 if (xattr_may_create(flags)) 134 if (xattr_may_create(flags))
135 err = xattr_mkdir(privroot->d_inode, xaroot, 0700); 135 err = xattr_mkdir(d_inode(privroot), xaroot, 0700);
136 if (err) { 136 if (err) {
137 dput(xaroot); 137 dput(xaroot);
138 xaroot = ERR_PTR(err); 138 xaroot = ERR_PTR(err);
139 } 139 }
140 } 140 }
141 141
142 mutex_unlock(&privroot->d_inode->i_mutex); 142 mutex_unlock(&d_inode(privroot)->i_mutex);
143 return xaroot; 143 return xaroot;
144} 144}
145 145
@@ -156,21 +156,21 @@ static struct dentry *open_xa_dir(const struct inode *inode, int flags)
156 le32_to_cpu(INODE_PKEY(inode)->k_objectid), 156 le32_to_cpu(INODE_PKEY(inode)->k_objectid),
157 inode->i_generation); 157 inode->i_generation);
158 158
159 mutex_lock_nested(&xaroot->d_inode->i_mutex, I_MUTEX_XATTR); 159 mutex_lock_nested(&d_inode(xaroot)->i_mutex, I_MUTEX_XATTR);
160 160
161 xadir = lookup_one_len(namebuf, xaroot, strlen(namebuf)); 161 xadir = lookup_one_len(namebuf, xaroot, strlen(namebuf));
162 if (!IS_ERR(xadir) && !xadir->d_inode) { 162 if (!IS_ERR(xadir) && d_really_is_negative(xadir)) {
163 int err = -ENODATA; 163 int err = -ENODATA;
164 164
165 if (xattr_may_create(flags)) 165 if (xattr_may_create(flags))
166 err = xattr_mkdir(xaroot->d_inode, xadir, 0700); 166 err = xattr_mkdir(d_inode(xaroot), xadir, 0700);
167 if (err) { 167 if (err) {
168 dput(xadir); 168 dput(xadir);
169 xadir = ERR_PTR(err); 169 xadir = ERR_PTR(err);
170 } 170 }
171 } 171 }
172 172
173 mutex_unlock(&xaroot->d_inode->i_mutex); 173 mutex_unlock(&d_inode(xaroot)->i_mutex);
174 dput(xaroot); 174 dput(xaroot);
175 return xadir; 175 return xadir;
176} 176}
@@ -195,7 +195,7 @@ fill_with_dentries(struct dir_context *ctx, const char *name, int namelen,
195 container_of(ctx, struct reiserfs_dentry_buf, ctx); 195 container_of(ctx, struct reiserfs_dentry_buf, ctx);
196 struct dentry *dentry; 196 struct dentry *dentry;
197 197
198 WARN_ON_ONCE(!mutex_is_locked(&dbuf->xadir->d_inode->i_mutex)); 198 WARN_ON_ONCE(!mutex_is_locked(&d_inode(dbuf->xadir)->i_mutex));
199 199
200 if (dbuf->count == ARRAY_SIZE(dbuf->dentries)) 200 if (dbuf->count == ARRAY_SIZE(dbuf->dentries))
201 return -ENOSPC; 201 return -ENOSPC;
@@ -207,7 +207,7 @@ fill_with_dentries(struct dir_context *ctx, const char *name, int namelen,
207 dentry = lookup_one_len(name, dbuf->xadir, namelen); 207 dentry = lookup_one_len(name, dbuf->xadir, namelen);
208 if (IS_ERR(dentry)) { 208 if (IS_ERR(dentry)) {
209 return PTR_ERR(dentry); 209 return PTR_ERR(dentry);
210 } else if (!dentry->d_inode) { 210 } else if (d_really_is_negative(dentry)) {
211 /* A directory entry exists, but no file? */ 211 /* A directory entry exists, but no file? */
212 reiserfs_error(dentry->d_sb, "xattr-20003", 212 reiserfs_error(dentry->d_sb, "xattr-20003",
213 "Corrupted directory: xattr %pd listed but " 213 "Corrupted directory: xattr %pd listed but "
@@ -249,16 +249,16 @@ static int reiserfs_for_each_xattr(struct inode *inode,
249 if (IS_ERR(dir)) { 249 if (IS_ERR(dir)) {
250 err = PTR_ERR(dir); 250 err = PTR_ERR(dir);
251 goto out; 251 goto out;
252 } else if (!dir->d_inode) { 252 } else if (d_really_is_negative(dir)) {
253 err = 0; 253 err = 0;
254 goto out_dir; 254 goto out_dir;
255 } 255 }
256 256
257 mutex_lock_nested(&dir->d_inode->i_mutex, I_MUTEX_XATTR); 257 mutex_lock_nested(&d_inode(dir)->i_mutex, I_MUTEX_XATTR);
258 258
259 buf.xadir = dir; 259 buf.xadir = dir;
260 while (1) { 260 while (1) {
261 err = reiserfs_readdir_inode(dir->d_inode, &buf.ctx); 261 err = reiserfs_readdir_inode(d_inode(dir), &buf.ctx);
262 if (err) 262 if (err)
263 break; 263 break;
264 if (!buf.count) 264 if (!buf.count)
@@ -276,7 +276,7 @@ static int reiserfs_for_each_xattr(struct inode *inode,
276 break; 276 break;
277 buf.count = 0; 277 buf.count = 0;
278 } 278 }
279 mutex_unlock(&dir->d_inode->i_mutex); 279 mutex_unlock(&d_inode(dir)->i_mutex);
280 280
281 cleanup_dentry_buf(&buf); 281 cleanup_dentry_buf(&buf);
282 282
@@ -298,13 +298,13 @@ static int reiserfs_for_each_xattr(struct inode *inode,
298 if (!err) { 298 if (!err) {
299 int jerror; 299 int jerror;
300 300
301 mutex_lock_nested(&dir->d_parent->d_inode->i_mutex, 301 mutex_lock_nested(&d_inode(dir->d_parent)->i_mutex,
302 I_MUTEX_XATTR); 302 I_MUTEX_XATTR);
303 err = action(dir, data); 303 err = action(dir, data);
304 reiserfs_write_lock(inode->i_sb); 304 reiserfs_write_lock(inode->i_sb);
305 jerror = journal_end(&th); 305 jerror = journal_end(&th);
306 reiserfs_write_unlock(inode->i_sb); 306 reiserfs_write_unlock(inode->i_sb);
307 mutex_unlock(&dir->d_parent->d_inode->i_mutex); 307 mutex_unlock(&d_inode(dir->d_parent)->i_mutex);
308 err = jerror ?: err; 308 err = jerror ?: err;
309 } 309 }
310 } 310 }
@@ -319,7 +319,7 @@ out:
319 319
320static int delete_one_xattr(struct dentry *dentry, void *data) 320static int delete_one_xattr(struct dentry *dentry, void *data)
321{ 321{
322 struct inode *dir = dentry->d_parent->d_inode; 322 struct inode *dir = d_inode(dentry->d_parent);
323 323
324 /* This is the xattr dir, handle specially. */ 324 /* This is the xattr dir, handle specially. */
325 if (d_is_dir(dentry)) 325 if (d_is_dir(dentry))
@@ -384,27 +384,27 @@ static struct dentry *xattr_lookup(struct inode *inode, const char *name,
384 if (IS_ERR(xadir)) 384 if (IS_ERR(xadir))
385 return ERR_CAST(xadir); 385 return ERR_CAST(xadir);
386 386
387 mutex_lock_nested(&xadir->d_inode->i_mutex, I_MUTEX_XATTR); 387 mutex_lock_nested(&d_inode(xadir)->i_mutex, I_MUTEX_XATTR);
388 xafile = lookup_one_len(name, xadir, strlen(name)); 388 xafile = lookup_one_len(name, xadir, strlen(name));
389 if (IS_ERR(xafile)) { 389 if (IS_ERR(xafile)) {
390 err = PTR_ERR(xafile); 390 err = PTR_ERR(xafile);
391 goto out; 391 goto out;
392 } 392 }
393 393
394 if (xafile->d_inode && (flags & XATTR_CREATE)) 394 if (d_really_is_positive(xafile) && (flags & XATTR_CREATE))
395 err = -EEXIST; 395 err = -EEXIST;
396 396
397 if (!xafile->d_inode) { 397 if (d_really_is_negative(xafile)) {
398 err = -ENODATA; 398 err = -ENODATA;
399 if (xattr_may_create(flags)) 399 if (xattr_may_create(flags))
400 err = xattr_create(xadir->d_inode, xafile, 400 err = xattr_create(d_inode(xadir), xafile,
401 0700|S_IFREG); 401 0700|S_IFREG);
402 } 402 }
403 403
404 if (err) 404 if (err)
405 dput(xafile); 405 dput(xafile);
406out: 406out:
407 mutex_unlock(&xadir->d_inode->i_mutex); 407 mutex_unlock(&d_inode(xadir)->i_mutex);
408 dput(xadir); 408 dput(xadir);
409 if (err) 409 if (err)
410 return ERR_PTR(err); 410 return ERR_PTR(err);
@@ -469,21 +469,21 @@ static int lookup_and_delete_xattr(struct inode *inode, const char *name)
469 if (IS_ERR(xadir)) 469 if (IS_ERR(xadir))
470 return PTR_ERR(xadir); 470 return PTR_ERR(xadir);
471 471
472 mutex_lock_nested(&xadir->d_inode->i_mutex, I_MUTEX_XATTR); 472 mutex_lock_nested(&d_inode(xadir)->i_mutex, I_MUTEX_XATTR);
473 dentry = lookup_one_len(name, xadir, strlen(name)); 473 dentry = lookup_one_len(name, xadir, strlen(name));
474 if (IS_ERR(dentry)) { 474 if (IS_ERR(dentry)) {
475 err = PTR_ERR(dentry); 475 err = PTR_ERR(dentry);
476 goto out_dput; 476 goto out_dput;
477 } 477 }
478 478
479 if (dentry->d_inode) { 479 if (d_really_is_positive(dentry)) {
480 err = xattr_unlink(xadir->d_inode, dentry); 480 err = xattr_unlink(d_inode(xadir), dentry);
481 update_ctime(inode); 481 update_ctime(inode);
482 } 482 }
483 483
484 dput(dentry); 484 dput(dentry);
485out_dput: 485out_dput:
486 mutex_unlock(&xadir->d_inode->i_mutex); 486 mutex_unlock(&d_inode(xadir)->i_mutex);
487 dput(xadir); 487 dput(xadir);
488 return err; 488 return err;
489} 489}
@@ -533,7 +533,7 @@ reiserfs_xattr_set_handle(struct reiserfs_transaction_handle *th,
533 else 533 else
534 chunk = buffer_size - buffer_pos; 534 chunk = buffer_size - buffer_pos;
535 535
536 page = reiserfs_get_page(dentry->d_inode, file_pos); 536 page = reiserfs_get_page(d_inode(dentry), file_pos);
537 if (IS_ERR(page)) { 537 if (IS_ERR(page)) {
538 err = PTR_ERR(page); 538 err = PTR_ERR(page);
539 goto out_unlock; 539 goto out_unlock;
@@ -573,18 +573,18 @@ reiserfs_xattr_set_handle(struct reiserfs_transaction_handle *th,
573 } 573 }
574 574
575 new_size = buffer_size + sizeof(struct reiserfs_xattr_header); 575 new_size = buffer_size + sizeof(struct reiserfs_xattr_header);
576 if (!err && new_size < i_size_read(dentry->d_inode)) { 576 if (!err && new_size < i_size_read(d_inode(dentry))) {
577 struct iattr newattrs = { 577 struct iattr newattrs = {
578 .ia_ctime = current_fs_time(inode->i_sb), 578 .ia_ctime = current_fs_time(inode->i_sb),
579 .ia_size = new_size, 579 .ia_size = new_size,
580 .ia_valid = ATTR_SIZE | ATTR_CTIME, 580 .ia_valid = ATTR_SIZE | ATTR_CTIME,
581 }; 581 };
582 582
583 mutex_lock_nested(&dentry->d_inode->i_mutex, I_MUTEX_XATTR); 583 mutex_lock_nested(&d_inode(dentry)->i_mutex, I_MUTEX_XATTR);
584 inode_dio_wait(dentry->d_inode); 584 inode_dio_wait(d_inode(dentry));
585 585
586 err = reiserfs_setattr(dentry, &newattrs); 586 err = reiserfs_setattr(dentry, &newattrs);
587 mutex_unlock(&dentry->d_inode->i_mutex); 587 mutex_unlock(&d_inode(dentry)->i_mutex);
588 } else 588 } else
589 update_ctime(inode); 589 update_ctime(inode);
590out_unlock: 590out_unlock:
@@ -657,7 +657,7 @@ reiserfs_xattr_get(struct inode *inode, const char *name, void *buffer,
657 657
658 down_read(&REISERFS_I(inode)->i_xattr_sem); 658 down_read(&REISERFS_I(inode)->i_xattr_sem);
659 659
660 isize = i_size_read(dentry->d_inode); 660 isize = i_size_read(d_inode(dentry));
661 661
662 /* Just return the size needed */ 662 /* Just return the size needed */
663 if (buffer == NULL) { 663 if (buffer == NULL) {
@@ -680,7 +680,7 @@ reiserfs_xattr_get(struct inode *inode, const char *name, void *buffer,
680 else 680 else
681 chunk = isize - file_pos; 681 chunk = isize - file_pos;
682 682
683 page = reiserfs_get_page(dentry->d_inode, file_pos); 683 page = reiserfs_get_page(d_inode(dentry), file_pos);
684 if (IS_ERR(page)) { 684 if (IS_ERR(page)) {
685 err = PTR_ERR(page); 685 err = PTR_ERR(page);
686 goto out_unlock; 686 goto out_unlock;
@@ -775,7 +775,7 @@ reiserfs_getxattr(struct dentry * dentry, const char *name, void *buffer,
775 775
776 handler = find_xattr_handler_prefix(dentry->d_sb->s_xattr, name); 776 handler = find_xattr_handler_prefix(dentry->d_sb->s_xattr, name);
777 777
778 if (!handler || get_inode_sd_version(dentry->d_inode) == STAT_DATA_V1) 778 if (!handler || get_inode_sd_version(d_inode(dentry)) == STAT_DATA_V1)
779 return -EOPNOTSUPP; 779 return -EOPNOTSUPP;
780 780
781 return handler->get(dentry, name, buffer, size, handler->flags); 781 return handler->get(dentry, name, buffer, size, handler->flags);
@@ -784,7 +784,7 @@ reiserfs_getxattr(struct dentry * dentry, const char *name, void *buffer,
784/* 784/*
785 * Inode operation setxattr() 785 * Inode operation setxattr()
786 * 786 *
787 * dentry->d_inode->i_mutex down 787 * d_inode(dentry)->i_mutex down
788 */ 788 */
789int 789int
790reiserfs_setxattr(struct dentry *dentry, const char *name, const void *value, 790reiserfs_setxattr(struct dentry *dentry, const char *name, const void *value,
@@ -794,7 +794,7 @@ reiserfs_setxattr(struct dentry *dentry, const char *name, const void *value,
794 794
795 handler = find_xattr_handler_prefix(dentry->d_sb->s_xattr, name); 795 handler = find_xattr_handler_prefix(dentry->d_sb->s_xattr, name);
796 796
797 if (!handler || get_inode_sd_version(dentry->d_inode) == STAT_DATA_V1) 797 if (!handler || get_inode_sd_version(d_inode(dentry)) == STAT_DATA_V1)
798 return -EOPNOTSUPP; 798 return -EOPNOTSUPP;
799 799
800 return handler->set(dentry, name, value, size, flags, handler->flags); 800 return handler->set(dentry, name, value, size, flags, handler->flags);
@@ -803,7 +803,7 @@ reiserfs_setxattr(struct dentry *dentry, const char *name, const void *value,
803/* 803/*
804 * Inode operation removexattr() 804 * Inode operation removexattr()
805 * 805 *
806 * dentry->d_inode->i_mutex down 806 * d_inode(dentry)->i_mutex down
807 */ 807 */
808int reiserfs_removexattr(struct dentry *dentry, const char *name) 808int reiserfs_removexattr(struct dentry *dentry, const char *name)
809{ 809{
@@ -811,7 +811,7 @@ int reiserfs_removexattr(struct dentry *dentry, const char *name)
811 811
812 handler = find_xattr_handler_prefix(dentry->d_sb->s_xattr, name); 812 handler = find_xattr_handler_prefix(dentry->d_sb->s_xattr, name);
813 813
814 if (!handler || get_inode_sd_version(dentry->d_inode) == STAT_DATA_V1) 814 if (!handler || get_inode_sd_version(d_inode(dentry)) == STAT_DATA_V1)
815 return -EOPNOTSUPP; 815 return -EOPNOTSUPP;
816 816
817 return handler->set(dentry, name, NULL, 0, XATTR_REPLACE, handler->flags); 817 return handler->set(dentry, name, NULL, 0, XATTR_REPLACE, handler->flags);
@@ -875,14 +875,14 @@ ssize_t reiserfs_listxattr(struct dentry * dentry, char *buffer, size_t size)
875 .size = buffer ? size : 0, 875 .size = buffer ? size : 0,
876 }; 876 };
877 877
878 if (!dentry->d_inode) 878 if (d_really_is_negative(dentry))
879 return -EINVAL; 879 return -EINVAL;
880 880
881 if (!dentry->d_sb->s_xattr || 881 if (!dentry->d_sb->s_xattr ||
882 get_inode_sd_version(dentry->d_inode) == STAT_DATA_V1) 882 get_inode_sd_version(d_inode(dentry)) == STAT_DATA_V1)
883 return -EOPNOTSUPP; 883 return -EOPNOTSUPP;
884 884
885 dir = open_xa_dir(dentry->d_inode, XATTR_REPLACE); 885 dir = open_xa_dir(d_inode(dentry), XATTR_REPLACE);
886 if (IS_ERR(dir)) { 886 if (IS_ERR(dir)) {
887 err = PTR_ERR(dir); 887 err = PTR_ERR(dir);
888 if (err == -ENODATA) 888 if (err == -ENODATA)
@@ -890,9 +890,9 @@ ssize_t reiserfs_listxattr(struct dentry * dentry, char *buffer, size_t size)
890 goto out; 890 goto out;
891 } 891 }
892 892
893 mutex_lock_nested(&dir->d_inode->i_mutex, I_MUTEX_XATTR); 893 mutex_lock_nested(&d_inode(dir)->i_mutex, I_MUTEX_XATTR);
894 err = reiserfs_readdir_inode(dir->d_inode, &buf.ctx); 894 err = reiserfs_readdir_inode(d_inode(dir), &buf.ctx);
895 mutex_unlock(&dir->d_inode->i_mutex); 895 mutex_unlock(&d_inode(dir)->i_mutex);
896 896
897 if (!err) 897 if (!err)
898 err = buf.pos; 898 err = buf.pos;
@@ -905,12 +905,12 @@ out:
905static int create_privroot(struct dentry *dentry) 905static int create_privroot(struct dentry *dentry)
906{ 906{
907 int err; 907 int err;
908 struct inode *inode = dentry->d_parent->d_inode; 908 struct inode *inode = d_inode(dentry->d_parent);
909 909
910 WARN_ON_ONCE(!mutex_is_locked(&inode->i_mutex)); 910 WARN_ON_ONCE(!mutex_is_locked(&inode->i_mutex));
911 911
912 err = xattr_mkdir(inode, dentry, 0700); 912 err = xattr_mkdir(inode, dentry, 0700);
913 if (err || !dentry->d_inode) { 913 if (err || d_really_is_negative(dentry)) {
914 reiserfs_warning(dentry->d_sb, "jdm-20006", 914 reiserfs_warning(dentry->d_sb, "jdm-20006",
915 "xattrs/ACLs enabled and couldn't " 915 "xattrs/ACLs enabled and couldn't "
916 "find/create .reiserfs_priv. " 916 "find/create .reiserfs_priv. "
@@ -918,7 +918,7 @@ static int create_privroot(struct dentry *dentry)
918 return -EOPNOTSUPP; 918 return -EOPNOTSUPP;
919 } 919 }
920 920
921 dentry->d_inode->i_flags |= S_PRIVATE; 921 d_inode(dentry)->i_flags |= S_PRIVATE;
922 reiserfs_info(dentry->d_sb, "Created %s - reserved for xattr " 922 reiserfs_info(dentry->d_sb, "Created %s - reserved for xattr "
923 "storage.\n", PRIVROOT_NAME); 923 "storage.\n", PRIVROOT_NAME);
924 924
@@ -997,17 +997,17 @@ int reiserfs_lookup_privroot(struct super_block *s)
997 int err = 0; 997 int err = 0;
998 998
999 /* If we don't have the privroot located yet - go find it */ 999 /* If we don't have the privroot located yet - go find it */
1000 mutex_lock(&s->s_root->d_inode->i_mutex); 1000 mutex_lock(&d_inode(s->s_root)->i_mutex);
1001 dentry = lookup_one_len(PRIVROOT_NAME, s->s_root, 1001 dentry = lookup_one_len(PRIVROOT_NAME, s->s_root,
1002 strlen(PRIVROOT_NAME)); 1002 strlen(PRIVROOT_NAME));
1003 if (!IS_ERR(dentry)) { 1003 if (!IS_ERR(dentry)) {
1004 REISERFS_SB(s)->priv_root = dentry; 1004 REISERFS_SB(s)->priv_root = dentry;
1005 d_set_d_op(dentry, &xattr_lookup_poison_ops); 1005 d_set_d_op(dentry, &xattr_lookup_poison_ops);
1006 if (dentry->d_inode) 1006 if (d_really_is_positive(dentry))
1007 dentry->d_inode->i_flags |= S_PRIVATE; 1007 d_inode(dentry)->i_flags |= S_PRIVATE;
1008 } else 1008 } else
1009 err = PTR_ERR(dentry); 1009 err = PTR_ERR(dentry);
1010 mutex_unlock(&s->s_root->d_inode->i_mutex); 1010 mutex_unlock(&d_inode(s->s_root)->i_mutex);
1011 1011
1012 return err; 1012 return err;
1013} 1013}
@@ -1026,15 +1026,15 @@ int reiserfs_xattr_init(struct super_block *s, int mount_flags)
1026 if (err) 1026 if (err)
1027 goto error; 1027 goto error;
1028 1028
1029 if (!privroot->d_inode && !(mount_flags & MS_RDONLY)) { 1029 if (d_really_is_negative(privroot) && !(mount_flags & MS_RDONLY)) {
1030 mutex_lock(&s->s_root->d_inode->i_mutex); 1030 mutex_lock(&d_inode(s->s_root)->i_mutex);
1031 err = create_privroot(REISERFS_SB(s)->priv_root); 1031 err = create_privroot(REISERFS_SB(s)->priv_root);
1032 mutex_unlock(&s->s_root->d_inode->i_mutex); 1032 mutex_unlock(&d_inode(s->s_root)->i_mutex);
1033 } 1033 }
1034 1034
1035 if (privroot->d_inode) { 1035 if (d_really_is_positive(privroot)) {
1036 s->s_xattr = reiserfs_xattr_handlers; 1036 s->s_xattr = reiserfs_xattr_handlers;
1037 mutex_lock(&privroot->d_inode->i_mutex); 1037 mutex_lock(&d_inode(privroot)->i_mutex);
1038 if (!REISERFS_SB(s)->xattr_root) { 1038 if (!REISERFS_SB(s)->xattr_root) {
1039 struct dentry *dentry; 1039 struct dentry *dentry;
1040 1040
@@ -1045,7 +1045,7 @@ int reiserfs_xattr_init(struct super_block *s, int mount_flags)
1045 else 1045 else
1046 err = PTR_ERR(dentry); 1046 err = PTR_ERR(dentry);
1047 } 1047 }
1048 mutex_unlock(&privroot->d_inode->i_mutex); 1048 mutex_unlock(&d_inode(privroot)->i_mutex);
1049 } 1049 }
1050 1050
1051error: 1051error:
diff --git a/fs/reiserfs/xattr.h b/fs/reiserfs/xattr.h
index f620e9678dd5..15dde6262c00 100644
--- a/fs/reiserfs/xattr.h
+++ b/fs/reiserfs/xattr.h
@@ -78,7 +78,7 @@ static inline size_t reiserfs_xattr_jcreate_nblocks(struct inode *inode)
78 78
79 if ((REISERFS_I(inode)->i_flags & i_has_xattr_dir) == 0) { 79 if ((REISERFS_I(inode)->i_flags & i_has_xattr_dir) == 0) {
80 nblocks += JOURNAL_BLOCKS_PER_OBJECT(inode->i_sb); 80 nblocks += JOURNAL_BLOCKS_PER_OBJECT(inode->i_sb);
81 if (!REISERFS_SB(inode->i_sb)->xattr_root->d_inode) 81 if (d_really_is_negative(REISERFS_SB(inode->i_sb)->xattr_root))
82 nblocks += JOURNAL_BLOCKS_PER_OBJECT(inode->i_sb); 82 nblocks += JOURNAL_BLOCKS_PER_OBJECT(inode->i_sb);
83 } 83 }
84 84
diff --git a/fs/reiserfs/xattr_security.c b/fs/reiserfs/xattr_security.c
index e7f8939a4cb5..9a3b0616f283 100644
--- a/fs/reiserfs/xattr_security.c
+++ b/fs/reiserfs/xattr_security.c
@@ -15,10 +15,10 @@ security_get(struct dentry *dentry, const char *name, void *buffer, size_t size,
15 if (strlen(name) < sizeof(XATTR_SECURITY_PREFIX)) 15 if (strlen(name) < sizeof(XATTR_SECURITY_PREFIX))
16 return -EINVAL; 16 return -EINVAL;
17 17
18 if (IS_PRIVATE(dentry->d_inode)) 18 if (IS_PRIVATE(d_inode(dentry)))
19 return -EPERM; 19 return -EPERM;
20 20
21 return reiserfs_xattr_get(dentry->d_inode, name, buffer, size); 21 return reiserfs_xattr_get(d_inode(dentry), name, buffer, size);
22} 22}
23 23
24static int 24static int
@@ -28,10 +28,10 @@ security_set(struct dentry *dentry, const char *name, const void *buffer,
28 if (strlen(name) < sizeof(XATTR_SECURITY_PREFIX)) 28 if (strlen(name) < sizeof(XATTR_SECURITY_PREFIX))
29 return -EINVAL; 29 return -EINVAL;
30 30
31 if (IS_PRIVATE(dentry->d_inode)) 31 if (IS_PRIVATE(d_inode(dentry)))
32 return -EPERM; 32 return -EPERM;
33 33
34 return reiserfs_xattr_set(dentry->d_inode, name, buffer, size, flags); 34 return reiserfs_xattr_set(d_inode(dentry), name, buffer, size, flags);
35} 35}
36 36
37static size_t security_list(struct dentry *dentry, char *list, size_t list_len, 37static size_t security_list(struct dentry *dentry, char *list, size_t list_len,
@@ -39,7 +39,7 @@ static size_t security_list(struct dentry *dentry, char *list, size_t list_len,
39{ 39{
40 const size_t len = namelen + 1; 40 const size_t len = namelen + 1;
41 41
42 if (IS_PRIVATE(dentry->d_inode)) 42 if (IS_PRIVATE(d_inode(dentry)))
43 return 0; 43 return 0;
44 44
45 if (list && len <= list_len) { 45 if (list && len <= list_len) {
diff --git a/fs/reiserfs/xattr_trusted.c b/fs/reiserfs/xattr_trusted.c
index 5eeb0c48ba46..e4f1343714e0 100644
--- a/fs/reiserfs/xattr_trusted.c
+++ b/fs/reiserfs/xattr_trusted.c
@@ -14,10 +14,10 @@ trusted_get(struct dentry *dentry, const char *name, void *buffer, size_t size,
14 if (strlen(name) < sizeof(XATTR_TRUSTED_PREFIX)) 14 if (strlen(name) < sizeof(XATTR_TRUSTED_PREFIX))
15 return -EINVAL; 15 return -EINVAL;
16 16
17 if (!capable(CAP_SYS_ADMIN) || IS_PRIVATE(dentry->d_inode)) 17 if (!capable(CAP_SYS_ADMIN) || IS_PRIVATE(d_inode(dentry)))
18 return -EPERM; 18 return -EPERM;
19 19
20 return reiserfs_xattr_get(dentry->d_inode, name, buffer, size); 20 return reiserfs_xattr_get(d_inode(dentry), name, buffer, size);
21} 21}
22 22
23static int 23static int
@@ -27,10 +27,10 @@ trusted_set(struct dentry *dentry, const char *name, const void *buffer,
27 if (strlen(name) < sizeof(XATTR_TRUSTED_PREFIX)) 27 if (strlen(name) < sizeof(XATTR_TRUSTED_PREFIX))
28 return -EINVAL; 28 return -EINVAL;
29 29
30 if (!capable(CAP_SYS_ADMIN) || IS_PRIVATE(dentry->d_inode)) 30 if (!capable(CAP_SYS_ADMIN) || IS_PRIVATE(d_inode(dentry)))
31 return -EPERM; 31 return -EPERM;
32 32
33 return reiserfs_xattr_set(dentry->d_inode, name, buffer, size, flags); 33 return reiserfs_xattr_set(d_inode(dentry), name, buffer, size, flags);
34} 34}
35 35
36static size_t trusted_list(struct dentry *dentry, char *list, size_t list_size, 36static size_t trusted_list(struct dentry *dentry, char *list, size_t list_size,
@@ -38,7 +38,7 @@ static size_t trusted_list(struct dentry *dentry, char *list, size_t list_size,
38{ 38{
39 const size_t len = name_len + 1; 39 const size_t len = name_len + 1;
40 40
41 if (!capable(CAP_SYS_ADMIN) || IS_PRIVATE(dentry->d_inode)) 41 if (!capable(CAP_SYS_ADMIN) || IS_PRIVATE(d_inode(dentry)))
42 return 0; 42 return 0;
43 43
44 if (list && len <= list_size) { 44 if (list && len <= list_size) {
diff --git a/fs/reiserfs/xattr_user.c b/fs/reiserfs/xattr_user.c
index e50eab046471..d0b08d3e5689 100644
--- a/fs/reiserfs/xattr_user.c
+++ b/fs/reiserfs/xattr_user.c
@@ -15,7 +15,7 @@ user_get(struct dentry *dentry, const char *name, void *buffer, size_t size,
15 return -EINVAL; 15 return -EINVAL;
16 if (!reiserfs_xattrs_user(dentry->d_sb)) 16 if (!reiserfs_xattrs_user(dentry->d_sb))
17 return -EOPNOTSUPP; 17 return -EOPNOTSUPP;
18 return reiserfs_xattr_get(dentry->d_inode, name, buffer, size); 18 return reiserfs_xattr_get(d_inode(dentry), name, buffer, size);
19} 19}
20 20
21static int 21static int
@@ -27,7 +27,7 @@ user_set(struct dentry *dentry, const char *name, const void *buffer,
27 27
28 if (!reiserfs_xattrs_user(dentry->d_sb)) 28 if (!reiserfs_xattrs_user(dentry->d_sb))
29 return -EOPNOTSUPP; 29 return -EOPNOTSUPP;
30 return reiserfs_xattr_set(dentry->d_inode, name, buffer, size, flags); 30 return reiserfs_xattr_set(d_inode(dentry), name, buffer, size, flags);
31} 31}
32 32
33static size_t user_list(struct dentry *dentry, char *list, size_t list_size, 33static size_t user_list(struct dentry *dentry, char *list, size_t list_size,
diff --git a/fs/squashfs/export.c b/fs/squashfs/export.c
index 5e1101ff276f..8073b6532cf0 100644
--- a/fs/squashfs/export.c
+++ b/fs/squashfs/export.c
@@ -110,7 +110,7 @@ static struct dentry *squashfs_fh_to_parent(struct super_block *sb,
110 110
111static struct dentry *squashfs_get_parent(struct dentry *child) 111static struct dentry *squashfs_get_parent(struct dentry *child)
112{ 112{
113 struct inode *inode = child->d_inode; 113 struct inode *inode = d_inode(child);
114 unsigned int parent_ino = squashfs_i(inode)->parent; 114 unsigned int parent_ino = squashfs_i(inode)->parent;
115 115
116 return squashfs_export_iget(inode->i_sb, parent_ino); 116 return squashfs_export_iget(inode->i_sb, parent_ino);
diff --git a/fs/squashfs/xattr.c b/fs/squashfs/xattr.c
index 92fcde7b4d61..e5e0ddf5b143 100644
--- a/fs/squashfs/xattr.c
+++ b/fs/squashfs/xattr.c
@@ -39,7 +39,7 @@ static const struct xattr_handler *squashfs_xattr_handler(int);
39ssize_t squashfs_listxattr(struct dentry *d, char *buffer, 39ssize_t squashfs_listxattr(struct dentry *d, char *buffer,
40 size_t buffer_size) 40 size_t buffer_size)
41{ 41{
42 struct inode *inode = d->d_inode; 42 struct inode *inode = d_inode(d);
43 struct super_block *sb = inode->i_sb; 43 struct super_block *sb = inode->i_sb;
44 struct squashfs_sb_info *msblk = sb->s_fs_info; 44 struct squashfs_sb_info *msblk = sb->s_fs_info;
45 u64 start = SQUASHFS_XATTR_BLK(squashfs_i(inode)->xattr) 45 u64 start = SQUASHFS_XATTR_BLK(squashfs_i(inode)->xattr)
@@ -229,7 +229,7 @@ static int squashfs_user_get(struct dentry *d, const char *name, void *buffer,
229 if (name[0] == '\0') 229 if (name[0] == '\0')
230 return -EINVAL; 230 return -EINVAL;
231 231
232 return squashfs_xattr_get(d->d_inode, SQUASHFS_XATTR_USER, name, 232 return squashfs_xattr_get(d_inode(d), SQUASHFS_XATTR_USER, name,
233 buffer, size); 233 buffer, size);
234} 234}
235 235
@@ -259,7 +259,7 @@ static int squashfs_trusted_get(struct dentry *d, const char *name,
259 if (name[0] == '\0') 259 if (name[0] == '\0')
260 return -EINVAL; 260 return -EINVAL;
261 261
262 return squashfs_xattr_get(d->d_inode, SQUASHFS_XATTR_TRUSTED, name, 262 return squashfs_xattr_get(d_inode(d), SQUASHFS_XATTR_TRUSTED, name,
263 buffer, size); 263 buffer, size);
264} 264}
265 265
@@ -286,7 +286,7 @@ static int squashfs_security_get(struct dentry *d, const char *name,
286 if (name[0] == '\0') 286 if (name[0] == '\0')
287 return -EINVAL; 287 return -EINVAL;
288 288
289 return squashfs_xattr_get(d->d_inode, SQUASHFS_XATTR_SECURITY, name, 289 return squashfs_xattr_get(d_inode(d), SQUASHFS_XATTR_SECURITY, name,
290 buffer, size); 290 buffer, size);
291} 291}
292 292
diff --git a/fs/stat.c b/fs/stat.c
index 19636af5e75c..cccc1aab9a8b 100644
--- a/fs/stat.c
+++ b/fs/stat.c
@@ -51,7 +51,7 @@ EXPORT_SYMBOL(generic_fillattr);
51 */ 51 */
52int vfs_getattr_nosec(struct path *path, struct kstat *stat) 52int vfs_getattr_nosec(struct path *path, struct kstat *stat)
53{ 53{
54 struct inode *inode = path->dentry->d_inode; 54 struct inode *inode = d_backing_inode(path->dentry);
55 55
56 if (inode->i_op->getattr) 56 if (inode->i_op->getattr)
57 return inode->i_op->getattr(path->mnt, path->dentry, stat); 57 return inode->i_op->getattr(path->mnt, path->dentry, stat);
@@ -326,7 +326,7 @@ SYSCALL_DEFINE4(readlinkat, int, dfd, const char __user *, pathname,
326retry: 326retry:
327 error = user_path_at_empty(dfd, pathname, lookup_flags, &path, &empty); 327 error = user_path_at_empty(dfd, pathname, lookup_flags, &path, &empty);
328 if (!error) { 328 if (!error) {
329 struct inode *inode = path.dentry->d_inode; 329 struct inode *inode = d_backing_inode(path.dentry);
330 330
331 error = empty ? -ENOENT : -EINVAL; 331 error = empty ? -ENOENT : -EINVAL;
332 if (inode->i_op->readlink) { 332 if (inode->i_op->readlink) {
diff --git a/fs/sysv/dir.c b/fs/sysv/dir.c
index d42291d08215..8f3555f00c54 100644
--- a/fs/sysv/dir.c
+++ b/fs/sysv/dir.c
@@ -132,7 +132,7 @@ struct sysv_dir_entry *sysv_find_entry(struct dentry *dentry, struct page **res_
132{ 132{
133 const char * name = dentry->d_name.name; 133 const char * name = dentry->d_name.name;
134 int namelen = dentry->d_name.len; 134 int namelen = dentry->d_name.len;
135 struct inode * dir = dentry->d_parent->d_inode; 135 struct inode * dir = d_inode(dentry->d_parent);
136 unsigned long start, n; 136 unsigned long start, n;
137 unsigned long npages = dir_pages(dir); 137 unsigned long npages = dir_pages(dir);
138 struct page *page = NULL; 138 struct page *page = NULL;
@@ -176,7 +176,7 @@ found:
176 176
177int sysv_add_link(struct dentry *dentry, struct inode *inode) 177int sysv_add_link(struct dentry *dentry, struct inode *inode)
178{ 178{
179 struct inode *dir = dentry->d_parent->d_inode; 179 struct inode *dir = d_inode(dentry->d_parent);
180 const char * name = dentry->d_name.name; 180 const char * name = dentry->d_name.name;
181 int namelen = dentry->d_name.len; 181 int namelen = dentry->d_name.len;
182 struct page *page = NULL; 182 struct page *page = NULL;
diff --git a/fs/sysv/file.c b/fs/sysv/file.c
index a48e30410ad1..82ddc09061e2 100644
--- a/fs/sysv/file.c
+++ b/fs/sysv/file.c
@@ -30,7 +30,7 @@ const struct file_operations sysv_file_operations = {
30 30
31static int sysv_setattr(struct dentry *dentry, struct iattr *attr) 31static int sysv_setattr(struct dentry *dentry, struct iattr *attr)
32{ 32{
33 struct inode *inode = dentry->d_inode; 33 struct inode *inode = d_inode(dentry);
34 int error; 34 int error;
35 35
36 error = inode_change_ok(inode, attr); 36 error = inode_change_ok(inode, attr);
diff --git a/fs/sysv/itree.c b/fs/sysv/itree.c
index 66bc316927e8..2fde40acf024 100644
--- a/fs/sysv/itree.c
+++ b/fs/sysv/itree.c
@@ -443,7 +443,7 @@ static unsigned sysv_nblocks(struct super_block *s, loff_t size)
443int sysv_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat) 443int sysv_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
444{ 444{
445 struct super_block *s = dentry->d_sb; 445 struct super_block *s = dentry->d_sb;
446 generic_fillattr(dentry->d_inode, stat); 446 generic_fillattr(d_inode(dentry), stat);
447 stat->blocks = (s->s_blocksize / 512) * sysv_nblocks(s, stat->size); 447 stat->blocks = (s->s_blocksize / 512) * sysv_nblocks(s, stat->size);
448 stat->blksize = s->s_blocksize; 448 stat->blksize = s->s_blocksize;
449 return 0; 449 return 0;
diff --git a/fs/sysv/namei.c b/fs/sysv/namei.c
index 731b2bbcaab3..11e83ed0b4bf 100644
--- a/fs/sysv/namei.c
+++ b/fs/sysv/namei.c
@@ -118,7 +118,7 @@ out_fail:
118static int sysv_link(struct dentry * old_dentry, struct inode * dir, 118static int sysv_link(struct dentry * old_dentry, struct inode * dir,
119 struct dentry * dentry) 119 struct dentry * dentry)
120{ 120{
121 struct inode *inode = old_dentry->d_inode; 121 struct inode *inode = d_inode(old_dentry);
122 122
123 inode->i_ctime = CURRENT_TIME_SEC; 123 inode->i_ctime = CURRENT_TIME_SEC;
124 inode_inc_link_count(inode); 124 inode_inc_link_count(inode);
@@ -166,7 +166,7 @@ out_dir:
166 166
167static int sysv_unlink(struct inode * dir, struct dentry * dentry) 167static int sysv_unlink(struct inode * dir, struct dentry * dentry)
168{ 168{
169 struct inode * inode = dentry->d_inode; 169 struct inode * inode = d_inode(dentry);
170 struct page * page; 170 struct page * page;
171 struct sysv_dir_entry * de; 171 struct sysv_dir_entry * de;
172 int err = -ENOENT; 172 int err = -ENOENT;
@@ -187,7 +187,7 @@ out:
187 187
188static int sysv_rmdir(struct inode * dir, struct dentry * dentry) 188static int sysv_rmdir(struct inode * dir, struct dentry * dentry)
189{ 189{
190 struct inode *inode = dentry->d_inode; 190 struct inode *inode = d_inode(dentry);
191 int err = -ENOTEMPTY; 191 int err = -ENOTEMPTY;
192 192
193 if (sysv_empty_dir(inode)) { 193 if (sysv_empty_dir(inode)) {
@@ -208,8 +208,8 @@ static int sysv_rmdir(struct inode * dir, struct dentry * dentry)
208static int sysv_rename(struct inode * old_dir, struct dentry * old_dentry, 208static int sysv_rename(struct inode * old_dir, struct dentry * old_dentry,
209 struct inode * new_dir, struct dentry * new_dentry) 209 struct inode * new_dir, struct dentry * new_dentry)
210{ 210{
211 struct inode * old_inode = old_dentry->d_inode; 211 struct inode * old_inode = d_inode(old_dentry);
212 struct inode * new_inode = new_dentry->d_inode; 212 struct inode * new_inode = d_inode(new_dentry);
213 struct page * dir_page = NULL; 213 struct page * dir_page = NULL;
214 struct sysv_dir_entry * dir_de = NULL; 214 struct sysv_dir_entry * dir_de = NULL;
215 struct page * old_page; 215 struct page * old_page;
diff --git a/fs/sysv/symlink.c b/fs/sysv/symlink.c
index 00d2f8a43e4e..d3fa0d703314 100644
--- a/fs/sysv/symlink.c
+++ b/fs/sysv/symlink.c
@@ -10,7 +10,7 @@
10 10
11static void *sysv_follow_link(struct dentry *dentry, struct nameidata *nd) 11static void *sysv_follow_link(struct dentry *dentry, struct nameidata *nd)
12{ 12{
13 nd_set_link(nd, (char *)SYSV_I(dentry->d_inode)->i_data); 13 nd_set_link(nd, (char *)SYSV_I(d_inode(dentry))->i_data);
14 return NULL; 14 return NULL;
15} 15}
16 16
diff --git a/fs/ubifs/dir.c b/fs/ubifs/dir.c
index 02d1ee778df0..27060fc855d4 100644
--- a/fs/ubifs/dir.c
+++ b/fs/ubifs/dir.c
@@ -499,7 +499,7 @@ static int ubifs_link(struct dentry *old_dentry, struct inode *dir,
499 struct dentry *dentry) 499 struct dentry *dentry)
500{ 500{
501 struct ubifs_info *c = dir->i_sb->s_fs_info; 501 struct ubifs_info *c = dir->i_sb->s_fs_info;
502 struct inode *inode = old_dentry->d_inode; 502 struct inode *inode = d_inode(old_dentry);
503 struct ubifs_inode *ui = ubifs_inode(inode); 503 struct ubifs_inode *ui = ubifs_inode(inode);
504 struct ubifs_inode *dir_ui = ubifs_inode(dir); 504 struct ubifs_inode *dir_ui = ubifs_inode(dir);
505 int err, sz_change = CALC_DENT_SIZE(dentry->d_name.len); 505 int err, sz_change = CALC_DENT_SIZE(dentry->d_name.len);
@@ -554,7 +554,7 @@ out_cancel:
554static int ubifs_unlink(struct inode *dir, struct dentry *dentry) 554static int ubifs_unlink(struct inode *dir, struct dentry *dentry)
555{ 555{
556 struct ubifs_info *c = dir->i_sb->s_fs_info; 556 struct ubifs_info *c = dir->i_sb->s_fs_info;
557 struct inode *inode = dentry->d_inode; 557 struct inode *inode = d_inode(dentry);
558 struct ubifs_inode *dir_ui = ubifs_inode(dir); 558 struct ubifs_inode *dir_ui = ubifs_inode(dir);
559 int sz_change = CALC_DENT_SIZE(dentry->d_name.len); 559 int sz_change = CALC_DENT_SIZE(dentry->d_name.len);
560 int err, budgeted = 1; 560 int err, budgeted = 1;
@@ -646,7 +646,7 @@ static int check_dir_empty(struct ubifs_info *c, struct inode *dir)
646static int ubifs_rmdir(struct inode *dir, struct dentry *dentry) 646static int ubifs_rmdir(struct inode *dir, struct dentry *dentry)
647{ 647{
648 struct ubifs_info *c = dir->i_sb->s_fs_info; 648 struct ubifs_info *c = dir->i_sb->s_fs_info;
649 struct inode *inode = dentry->d_inode; 649 struct inode *inode = d_inode(dentry);
650 int sz_change = CALC_DENT_SIZE(dentry->d_name.len); 650 int sz_change = CALC_DENT_SIZE(dentry->d_name.len);
651 int err, budgeted = 1; 651 int err, budgeted = 1;
652 struct ubifs_inode *dir_ui = ubifs_inode(dir); 652 struct ubifs_inode *dir_ui = ubifs_inode(dir);
@@ -662,7 +662,7 @@ static int ubifs_rmdir(struct inode *dir, struct dentry *dentry)
662 inode->i_ino, dir->i_ino); 662 inode->i_ino, dir->i_ino);
663 ubifs_assert(mutex_is_locked(&dir->i_mutex)); 663 ubifs_assert(mutex_is_locked(&dir->i_mutex));
664 ubifs_assert(mutex_is_locked(&inode->i_mutex)); 664 ubifs_assert(mutex_is_locked(&inode->i_mutex));
665 err = check_dir_empty(c, dentry->d_inode); 665 err = check_dir_empty(c, d_inode(dentry));
666 if (err) 666 if (err)
667 return err; 667 return err;
668 668
@@ -970,8 +970,8 @@ static int ubifs_rename(struct inode *old_dir, struct dentry *old_dentry,
970 struct inode *new_dir, struct dentry *new_dentry) 970 struct inode *new_dir, struct dentry *new_dentry)
971{ 971{
972 struct ubifs_info *c = old_dir->i_sb->s_fs_info; 972 struct ubifs_info *c = old_dir->i_sb->s_fs_info;
973 struct inode *old_inode = old_dentry->d_inode; 973 struct inode *old_inode = d_inode(old_dentry);
974 struct inode *new_inode = new_dentry->d_inode; 974 struct inode *new_inode = d_inode(new_dentry);
975 struct ubifs_inode *old_inode_ui = ubifs_inode(old_inode); 975 struct ubifs_inode *old_inode_ui = ubifs_inode(old_inode);
976 int err, release, sync = 0, move = (new_dir != old_dir); 976 int err, release, sync = 0, move = (new_dir != old_dir);
977 int is_dir = S_ISDIR(old_inode->i_mode); 977 int is_dir = S_ISDIR(old_inode->i_mode);
@@ -1136,7 +1136,7 @@ int ubifs_getattr(struct vfsmount *mnt, struct dentry *dentry,
1136 struct kstat *stat) 1136 struct kstat *stat)
1137{ 1137{
1138 loff_t size; 1138 loff_t size;
1139 struct inode *inode = dentry->d_inode; 1139 struct inode *inode = d_inode(dentry);
1140 struct ubifs_inode *ui = ubifs_inode(inode); 1140 struct ubifs_inode *ui = ubifs_inode(inode);
1141 1141
1142 mutex_lock(&ui->ui_mutex); 1142 mutex_lock(&ui->ui_mutex);
diff --git a/fs/ubifs/file.c b/fs/ubifs/file.c
index 3ba3fef64e9e..35efc103c39c 100644
--- a/fs/ubifs/file.c
+++ b/fs/ubifs/file.c
@@ -1257,7 +1257,7 @@ static int do_setattr(struct ubifs_info *c, struct inode *inode,
1257int ubifs_setattr(struct dentry *dentry, struct iattr *attr) 1257int ubifs_setattr(struct dentry *dentry, struct iattr *attr)
1258{ 1258{
1259 int err; 1259 int err;
1260 struct inode *inode = dentry->d_inode; 1260 struct inode *inode = d_inode(dentry);
1261 struct ubifs_info *c = inode->i_sb->s_fs_info; 1261 struct ubifs_info *c = inode->i_sb->s_fs_info;
1262 1262
1263 dbg_gen("ino %lu, mode %#x, ia_valid %#x", 1263 dbg_gen("ino %lu, mode %#x, ia_valid %#x",
@@ -1302,7 +1302,7 @@ static void ubifs_invalidatepage(struct page *page, unsigned int offset,
1302 1302
1303static void *ubifs_follow_link(struct dentry *dentry, struct nameidata *nd) 1303static void *ubifs_follow_link(struct dentry *dentry, struct nameidata *nd)
1304{ 1304{
1305 struct ubifs_inode *ui = ubifs_inode(dentry->d_inode); 1305 struct ubifs_inode *ui = ubifs_inode(d_inode(dentry));
1306 1306
1307 nd_set_link(nd, ui->data); 1307 nd_set_link(nd, ui->data);
1308 return NULL; 1308 return NULL;
diff --git a/fs/ubifs/journal.c b/fs/ubifs/journal.c
index 90ae1a8439d9..0b9da5b6e0f9 100644
--- a/fs/ubifs/journal.c
+++ b/fs/ubifs/journal.c
@@ -930,8 +930,8 @@ int ubifs_jnl_rename(struct ubifs_info *c, const struct inode *old_dir,
930 union ubifs_key key; 930 union ubifs_key key;
931 struct ubifs_dent_node *dent, *dent2; 931 struct ubifs_dent_node *dent, *dent2;
932 int err, dlen1, dlen2, ilen, lnum, offs, len; 932 int err, dlen1, dlen2, ilen, lnum, offs, len;
933 const struct inode *old_inode = old_dentry->d_inode; 933 const struct inode *old_inode = d_inode(old_dentry);
934 const struct inode *new_inode = new_dentry->d_inode; 934 const struct inode *new_inode = d_inode(new_dentry);
935 int aligned_dlen1, aligned_dlen2, plen = UBIFS_INO_NODE_SZ; 935 int aligned_dlen1, aligned_dlen2, plen = UBIFS_INO_NODE_SZ;
936 int last_reference = !!(new_inode && new_inode->i_nlink == 0); 936 int last_reference = !!(new_inode && new_inode->i_nlink == 0);
937 int move = (old_dir != new_dir); 937 int move = (old_dir != new_dir);
diff --git a/fs/ubifs/xattr.c b/fs/ubifs/xattr.c
index 3659b1934500..96f3448b6eb4 100644
--- a/fs/ubifs/xattr.c
+++ b/fs/ubifs/xattr.c
@@ -364,15 +364,15 @@ int ubifs_setxattr(struct dentry *dentry, const char *name,
364 const void *value, size_t size, int flags) 364 const void *value, size_t size, int flags)
365{ 365{
366 dbg_gen("xattr '%s', host ino %lu ('%pd'), size %zd", 366 dbg_gen("xattr '%s', host ino %lu ('%pd'), size %zd",
367 name, dentry->d_inode->i_ino, dentry, size); 367 name, d_inode(dentry)->i_ino, dentry, size);
368 368
369 return setxattr(dentry->d_inode, name, value, size, flags); 369 return setxattr(d_inode(dentry), name, value, size, flags);
370} 370}
371 371
372ssize_t ubifs_getxattr(struct dentry *dentry, const char *name, void *buf, 372ssize_t ubifs_getxattr(struct dentry *dentry, const char *name, void *buf,
373 size_t size) 373 size_t size)
374{ 374{
375 struct inode *inode, *host = dentry->d_inode; 375 struct inode *inode, *host = d_inode(dentry);
376 struct ubifs_info *c = host->i_sb->s_fs_info; 376 struct ubifs_info *c = host->i_sb->s_fs_info;
377 struct qstr nm = QSTR_INIT(name, strlen(name)); 377 struct qstr nm = QSTR_INIT(name, strlen(name));
378 struct ubifs_inode *ui; 378 struct ubifs_inode *ui;
@@ -432,7 +432,7 @@ out_unlock:
432ssize_t ubifs_listxattr(struct dentry *dentry, char *buffer, size_t size) 432ssize_t ubifs_listxattr(struct dentry *dentry, char *buffer, size_t size)
433{ 433{
434 union ubifs_key key; 434 union ubifs_key key;
435 struct inode *host = dentry->d_inode; 435 struct inode *host = d_inode(dentry);
436 struct ubifs_info *c = host->i_sb->s_fs_info; 436 struct ubifs_info *c = host->i_sb->s_fs_info;
437 struct ubifs_inode *host_ui = ubifs_inode(host); 437 struct ubifs_inode *host_ui = ubifs_inode(host);
438 struct ubifs_dent_node *xent, *pxent = NULL; 438 struct ubifs_dent_node *xent, *pxent = NULL;
@@ -535,7 +535,7 @@ out_cancel:
535 535
536int ubifs_removexattr(struct dentry *dentry, const char *name) 536int ubifs_removexattr(struct dentry *dentry, const char *name)
537{ 537{
538 struct inode *inode, *host = dentry->d_inode; 538 struct inode *inode, *host = d_inode(dentry);
539 struct ubifs_info *c = host->i_sb->s_fs_info; 539 struct ubifs_info *c = host->i_sb->s_fs_info;
540 struct qstr nm = QSTR_INIT(name, strlen(name)); 540 struct qstr nm = QSTR_INIT(name, strlen(name));
541 struct ubifs_dent_node *xent; 541 struct ubifs_dent_node *xent;
diff --git a/fs/udf/file.c b/fs/udf/file.c
index 5dadad9960b9..7a95b8fed302 100644
--- a/fs/udf/file.c
+++ b/fs/udf/file.c
@@ -249,7 +249,7 @@ const struct file_operations udf_file_operations = {
249 249
250static int udf_setattr(struct dentry *dentry, struct iattr *attr) 250static int udf_setattr(struct dentry *dentry, struct iattr *attr)
251{ 251{
252 struct inode *inode = dentry->d_inode; 252 struct inode *inode = d_inode(dentry);
253 int error; 253 int error;
254 254
255 error = inode_change_ok(inode, attr); 255 error = inode_change_ok(inode, attr);
diff --git a/fs/udf/namei.c b/fs/udf/namei.c
index 39661977c89c..5c03f0dfb98b 100644
--- a/fs/udf/namei.c
+++ b/fs/udf/namei.c
@@ -551,7 +551,7 @@ static int udf_delete_entry(struct inode *inode, struct fileIdentDesc *fi,
551static int udf_add_nondir(struct dentry *dentry, struct inode *inode) 551static int udf_add_nondir(struct dentry *dentry, struct inode *inode)
552{ 552{
553 struct udf_inode_info *iinfo = UDF_I(inode); 553 struct udf_inode_info *iinfo = UDF_I(inode);
554 struct inode *dir = dentry->d_parent->d_inode; 554 struct inode *dir = d_inode(dentry->d_parent);
555 struct udf_fileident_bh fibh; 555 struct udf_fileident_bh fibh;
556 struct fileIdentDesc cfi, *fi; 556 struct fileIdentDesc cfi, *fi;
557 int err; 557 int err;
@@ -767,7 +767,7 @@ static int empty_dir(struct inode *dir)
767static int udf_rmdir(struct inode *dir, struct dentry *dentry) 767static int udf_rmdir(struct inode *dir, struct dentry *dentry)
768{ 768{
769 int retval; 769 int retval;
770 struct inode *inode = dentry->d_inode; 770 struct inode *inode = d_inode(dentry);
771 struct udf_fileident_bh fibh; 771 struct udf_fileident_bh fibh;
772 struct fileIdentDesc *fi, cfi; 772 struct fileIdentDesc *fi, cfi;
773 struct kernel_lb_addr tloc; 773 struct kernel_lb_addr tloc;
@@ -809,7 +809,7 @@ out:
809static int udf_unlink(struct inode *dir, struct dentry *dentry) 809static int udf_unlink(struct inode *dir, struct dentry *dentry)
810{ 810{
811 int retval; 811 int retval;
812 struct inode *inode = dentry->d_inode; 812 struct inode *inode = d_inode(dentry);
813 struct udf_fileident_bh fibh; 813 struct udf_fileident_bh fibh;
814 struct fileIdentDesc *fi; 814 struct fileIdentDesc *fi;
815 struct fileIdentDesc cfi; 815 struct fileIdentDesc cfi;
@@ -999,7 +999,7 @@ out_no_entry:
999static int udf_link(struct dentry *old_dentry, struct inode *dir, 999static int udf_link(struct dentry *old_dentry, struct inode *dir,
1000 struct dentry *dentry) 1000 struct dentry *dentry)
1001{ 1001{
1002 struct inode *inode = old_dentry->d_inode; 1002 struct inode *inode = d_inode(old_dentry);
1003 struct udf_fileident_bh fibh; 1003 struct udf_fileident_bh fibh;
1004 struct fileIdentDesc cfi, *fi; 1004 struct fileIdentDesc cfi, *fi;
1005 int err; 1005 int err;
@@ -1038,8 +1038,8 @@ static int udf_link(struct dentry *old_dentry, struct inode *dir,
1038static int udf_rename(struct inode *old_dir, struct dentry *old_dentry, 1038static int udf_rename(struct inode *old_dir, struct dentry *old_dentry,
1039 struct inode *new_dir, struct dentry *new_dentry) 1039 struct inode *new_dir, struct dentry *new_dentry)
1040{ 1040{
1041 struct inode *old_inode = old_dentry->d_inode; 1041 struct inode *old_inode = d_inode(old_dentry);
1042 struct inode *new_inode = new_dentry->d_inode; 1042 struct inode *new_inode = d_inode(new_dentry);
1043 struct udf_fileident_bh ofibh, nfibh; 1043 struct udf_fileident_bh ofibh, nfibh;
1044 struct fileIdentDesc *ofi = NULL, *nfi = NULL, *dir_fi = NULL; 1044 struct fileIdentDesc *ofi = NULL, *nfi = NULL, *dir_fi = NULL;
1045 struct fileIdentDesc ocfi, ncfi; 1045 struct fileIdentDesc ocfi, ncfi;
@@ -1179,7 +1179,7 @@ static struct dentry *udf_get_parent(struct dentry *child)
1179 struct fileIdentDesc cfi; 1179 struct fileIdentDesc cfi;
1180 struct udf_fileident_bh fibh; 1180 struct udf_fileident_bh fibh;
1181 1181
1182 if (!udf_find_entry(child->d_inode, &dotdot, &fibh, &cfi)) 1182 if (!udf_find_entry(d_inode(child), &dotdot, &fibh, &cfi))
1183 return ERR_PTR(-EACCES); 1183 return ERR_PTR(-EACCES);
1184 1184
1185 if (fibh.sbh != fibh.ebh) 1185 if (fibh.sbh != fibh.ebh)
@@ -1187,7 +1187,7 @@ static struct dentry *udf_get_parent(struct dentry *child)
1187 brelse(fibh.sbh); 1187 brelse(fibh.sbh);
1188 1188
1189 tloc = lelb_to_cpu(cfi.icb.extLocation); 1189 tloc = lelb_to_cpu(cfi.icb.extLocation);
1190 inode = udf_iget(child->d_inode->i_sb, &tloc); 1190 inode = udf_iget(d_inode(child)->i_sb, &tloc);
1191 if (IS_ERR(inode)) 1191 if (IS_ERR(inode))
1192 return ERR_CAST(inode); 1192 return ERR_CAST(inode);
1193 1193
diff --git a/fs/ufs/dir.c b/fs/ufs/dir.c
index 0ecc2cebed8f..1bfe8cabff0f 100644
--- a/fs/ufs/dir.c
+++ b/fs/ufs/dir.c
@@ -311,7 +311,7 @@ found:
311 */ 311 */
312int ufs_add_link(struct dentry *dentry, struct inode *inode) 312int ufs_add_link(struct dentry *dentry, struct inode *inode)
313{ 313{
314 struct inode *dir = dentry->d_parent->d_inode; 314 struct inode *dir = d_inode(dentry->d_parent);
315 const unsigned char *name = dentry->d_name.name; 315 const unsigned char *name = dentry->d_name.name;
316 int namelen = dentry->d_name.len; 316 int namelen = dentry->d_name.len;
317 struct super_block *sb = dir->i_sb; 317 struct super_block *sb = dir->i_sb;
diff --git a/fs/ufs/namei.c b/fs/ufs/namei.c
index fd65deb4b5f0..e491a93a7e9a 100644
--- a/fs/ufs/namei.c
+++ b/fs/ufs/namei.c
@@ -165,7 +165,7 @@ out_fail:
165static int ufs_link (struct dentry * old_dentry, struct inode * dir, 165static int ufs_link (struct dentry * old_dentry, struct inode * dir,
166 struct dentry *dentry) 166 struct dentry *dentry)
167{ 167{
168 struct inode *inode = old_dentry->d_inode; 168 struct inode *inode = d_inode(old_dentry);
169 int error; 169 int error;
170 170
171 lock_ufs(dir->i_sb); 171 lock_ufs(dir->i_sb);
@@ -222,7 +222,7 @@ out_fail:
222 222
223static int ufs_unlink(struct inode *dir, struct dentry *dentry) 223static int ufs_unlink(struct inode *dir, struct dentry *dentry)
224{ 224{
225 struct inode * inode = dentry->d_inode; 225 struct inode * inode = d_inode(dentry);
226 struct ufs_dir_entry *de; 226 struct ufs_dir_entry *de;
227 struct page *page; 227 struct page *page;
228 int err = -ENOENT; 228 int err = -ENOENT;
@@ -244,7 +244,7 @@ out:
244 244
245static int ufs_rmdir (struct inode * dir, struct dentry *dentry) 245static int ufs_rmdir (struct inode * dir, struct dentry *dentry)
246{ 246{
247 struct inode * inode = dentry->d_inode; 247 struct inode * inode = d_inode(dentry);
248 int err= -ENOTEMPTY; 248 int err= -ENOTEMPTY;
249 249
250 lock_ufs(dir->i_sb); 250 lock_ufs(dir->i_sb);
@@ -263,8 +263,8 @@ static int ufs_rmdir (struct inode * dir, struct dentry *dentry)
263static int ufs_rename(struct inode *old_dir, struct dentry *old_dentry, 263static int ufs_rename(struct inode *old_dir, struct dentry *old_dentry,
264 struct inode *new_dir, struct dentry *new_dentry) 264 struct inode *new_dir, struct dentry *new_dentry)
265{ 265{
266 struct inode *old_inode = old_dentry->d_inode; 266 struct inode *old_inode = d_inode(old_dentry);
267 struct inode *new_inode = new_dentry->d_inode; 267 struct inode *new_inode = d_inode(new_dentry);
268 struct page *dir_page = NULL; 268 struct page *dir_page = NULL;
269 struct ufs_dir_entry * dir_de = NULL; 269 struct ufs_dir_entry * dir_de = NULL;
270 struct page *old_page; 270 struct page *old_page;
diff --git a/fs/ufs/super.c b/fs/ufs/super.c
index 8092d3759a5e..b3bc3e7ae79d 100644
--- a/fs/ufs/super.c
+++ b/fs/ufs/super.c
@@ -144,10 +144,10 @@ static struct dentry *ufs_get_parent(struct dentry *child)
144 struct qstr dot_dot = QSTR_INIT("..", 2); 144 struct qstr dot_dot = QSTR_INIT("..", 2);
145 ino_t ino; 145 ino_t ino;
146 146
147 ino = ufs_inode_by_name(child->d_inode, &dot_dot); 147 ino = ufs_inode_by_name(d_inode(child), &dot_dot);
148 if (!ino) 148 if (!ino)
149 return ERR_PTR(-ENOENT); 149 return ERR_PTR(-ENOENT);
150 return d_obtain_alias(ufs_iget(child->d_inode->i_sb, ino)); 150 return d_obtain_alias(ufs_iget(d_inode(child)->i_sb, ino));
151} 151}
152 152
153static const struct export_operations ufs_export_ops = { 153static const struct export_operations ufs_export_ops = {
diff --git a/fs/ufs/symlink.c b/fs/ufs/symlink.c
index d283628b4778..5b537e2fdda3 100644
--- a/fs/ufs/symlink.c
+++ b/fs/ufs/symlink.c
@@ -34,7 +34,7 @@
34 34
35static void *ufs_follow_link(struct dentry *dentry, struct nameidata *nd) 35static void *ufs_follow_link(struct dentry *dentry, struct nameidata *nd)
36{ 36{
37 struct ufs_inode_info *p = UFS_I(dentry->d_inode); 37 struct ufs_inode_info *p = UFS_I(d_inode(dentry));
38 nd_set_link(nd, (char*)p->i_u1.i_symlink); 38 nd_set_link(nd, (char*)p->i_u1.i_symlink);
39 return NULL; 39 return NULL;
40} 40}
diff --git a/fs/ufs/truncate.c b/fs/ufs/truncate.c
index f04f89fbd4d9..21154704c168 100644
--- a/fs/ufs/truncate.c
+++ b/fs/ufs/truncate.c
@@ -492,7 +492,7 @@ out:
492 492
493int ufs_setattr(struct dentry *dentry, struct iattr *attr) 493int ufs_setattr(struct dentry *dentry, struct iattr *attr)
494{ 494{
495 struct inode *inode = dentry->d_inode; 495 struct inode *inode = d_inode(dentry);
496 unsigned int ia_valid = attr->ia_valid; 496 unsigned int ia_valid = attr->ia_valid;
497 int error; 497 int error;
498 498
diff --git a/fs/xfs/libxfs/xfs_alloc.c b/fs/xfs/libxfs/xfs_alloc.c
index a6fbf4472017..516162be1398 100644
--- a/fs/xfs/libxfs/xfs_alloc.c
+++ b/fs/xfs/libxfs/xfs_alloc.c
@@ -260,6 +260,7 @@ xfs_alloc_fix_len(
260 rlen = rlen - (k - args->mod); 260 rlen = rlen - (k - args->mod);
261 else 261 else
262 rlen = rlen - args->prod + (args->mod - k); 262 rlen = rlen - args->prod + (args->mod - k);
263 /* casts to (int) catch length underflows */
263 if ((int)rlen < (int)args->minlen) 264 if ((int)rlen < (int)args->minlen)
264 return; 265 return;
265 ASSERT(rlen >= args->minlen && rlen <= args->maxlen); 266 ASSERT(rlen >= args->minlen && rlen <= args->maxlen);
@@ -286,7 +287,8 @@ xfs_alloc_fix_minleft(
286 if (diff >= 0) 287 if (diff >= 0)
287 return 1; 288 return 1;
288 args->len += diff; /* shrink the allocated space */ 289 args->len += diff; /* shrink the allocated space */
289 if (args->len >= args->minlen) 290 /* casts to (int) catch length underflows */
291 if ((int)args->len >= (int)args->minlen)
290 return 1; 292 return 1;
291 args->agbno = NULLAGBLOCK; 293 args->agbno = NULLAGBLOCK;
292 return 0; 294 return 0;
@@ -315,6 +317,9 @@ xfs_alloc_fixup_trees(
315 xfs_agblock_t nfbno2; /* second new free startblock */ 317 xfs_agblock_t nfbno2; /* second new free startblock */
316 xfs_extlen_t nflen1=0; /* first new free length */ 318 xfs_extlen_t nflen1=0; /* first new free length */
317 xfs_extlen_t nflen2=0; /* second new free length */ 319 xfs_extlen_t nflen2=0; /* second new free length */
320 struct xfs_mount *mp;
321
322 mp = cnt_cur->bc_mp;
318 323
319 /* 324 /*
320 * Look up the record in the by-size tree if necessary. 325 * Look up the record in the by-size tree if necessary.
@@ -323,13 +328,13 @@ xfs_alloc_fixup_trees(
323#ifdef DEBUG 328#ifdef DEBUG
324 if ((error = xfs_alloc_get_rec(cnt_cur, &nfbno1, &nflen1, &i))) 329 if ((error = xfs_alloc_get_rec(cnt_cur, &nfbno1, &nflen1, &i)))
325 return error; 330 return error;
326 XFS_WANT_CORRUPTED_RETURN( 331 XFS_WANT_CORRUPTED_RETURN(mp,
327 i == 1 && nfbno1 == fbno && nflen1 == flen); 332 i == 1 && nfbno1 == fbno && nflen1 == flen);
328#endif 333#endif
329 } else { 334 } else {
330 if ((error = xfs_alloc_lookup_eq(cnt_cur, fbno, flen, &i))) 335 if ((error = xfs_alloc_lookup_eq(cnt_cur, fbno, flen, &i)))
331 return error; 336 return error;
332 XFS_WANT_CORRUPTED_RETURN(i == 1); 337 XFS_WANT_CORRUPTED_RETURN(mp, i == 1);
333 } 338 }
334 /* 339 /*
335 * Look up the record in the by-block tree if necessary. 340 * Look up the record in the by-block tree if necessary.
@@ -338,13 +343,13 @@ xfs_alloc_fixup_trees(
338#ifdef DEBUG 343#ifdef DEBUG
339 if ((error = xfs_alloc_get_rec(bno_cur, &nfbno1, &nflen1, &i))) 344 if ((error = xfs_alloc_get_rec(bno_cur, &nfbno1, &nflen1, &i)))
340 return error; 345 return error;
341 XFS_WANT_CORRUPTED_RETURN( 346 XFS_WANT_CORRUPTED_RETURN(mp,
342 i == 1 && nfbno1 == fbno && nflen1 == flen); 347 i == 1 && nfbno1 == fbno && nflen1 == flen);
343#endif 348#endif
344 } else { 349 } else {
345 if ((error = xfs_alloc_lookup_eq(bno_cur, fbno, flen, &i))) 350 if ((error = xfs_alloc_lookup_eq(bno_cur, fbno, flen, &i)))
346 return error; 351 return error;
347 XFS_WANT_CORRUPTED_RETURN(i == 1); 352 XFS_WANT_CORRUPTED_RETURN(mp, i == 1);
348 } 353 }
349 354
350#ifdef DEBUG 355#ifdef DEBUG
@@ -355,7 +360,7 @@ xfs_alloc_fixup_trees(
355 bnoblock = XFS_BUF_TO_BLOCK(bno_cur->bc_bufs[0]); 360 bnoblock = XFS_BUF_TO_BLOCK(bno_cur->bc_bufs[0]);
356 cntblock = XFS_BUF_TO_BLOCK(cnt_cur->bc_bufs[0]); 361 cntblock = XFS_BUF_TO_BLOCK(cnt_cur->bc_bufs[0]);
357 362
358 XFS_WANT_CORRUPTED_RETURN( 363 XFS_WANT_CORRUPTED_RETURN(mp,
359 bnoblock->bb_numrecs == cntblock->bb_numrecs); 364 bnoblock->bb_numrecs == cntblock->bb_numrecs);
360 } 365 }
361#endif 366#endif
@@ -386,25 +391,25 @@ xfs_alloc_fixup_trees(
386 */ 391 */
387 if ((error = xfs_btree_delete(cnt_cur, &i))) 392 if ((error = xfs_btree_delete(cnt_cur, &i)))
388 return error; 393 return error;
389 XFS_WANT_CORRUPTED_RETURN(i == 1); 394 XFS_WANT_CORRUPTED_RETURN(mp, i == 1);
390 /* 395 /*
391 * Add new by-size btree entry(s). 396 * Add new by-size btree entry(s).
392 */ 397 */
393 if (nfbno1 != NULLAGBLOCK) { 398 if (nfbno1 != NULLAGBLOCK) {
394 if ((error = xfs_alloc_lookup_eq(cnt_cur, nfbno1, nflen1, &i))) 399 if ((error = xfs_alloc_lookup_eq(cnt_cur, nfbno1, nflen1, &i)))
395 return error; 400 return error;
396 XFS_WANT_CORRUPTED_RETURN(i == 0); 401 XFS_WANT_CORRUPTED_RETURN(mp, i == 0);
397 if ((error = xfs_btree_insert(cnt_cur, &i))) 402 if ((error = xfs_btree_insert(cnt_cur, &i)))
398 return error; 403 return error;
399 XFS_WANT_CORRUPTED_RETURN(i == 1); 404 XFS_WANT_CORRUPTED_RETURN(mp, i == 1);
400 } 405 }
401 if (nfbno2 != NULLAGBLOCK) { 406 if (nfbno2 != NULLAGBLOCK) {
402 if ((error = xfs_alloc_lookup_eq(cnt_cur, nfbno2, nflen2, &i))) 407 if ((error = xfs_alloc_lookup_eq(cnt_cur, nfbno2, nflen2, &i)))
403 return error; 408 return error;
404 XFS_WANT_CORRUPTED_RETURN(i == 0); 409 XFS_WANT_CORRUPTED_RETURN(mp, i == 0);
405 if ((error = xfs_btree_insert(cnt_cur, &i))) 410 if ((error = xfs_btree_insert(cnt_cur, &i)))
406 return error; 411 return error;
407 XFS_WANT_CORRUPTED_RETURN(i == 1); 412 XFS_WANT_CORRUPTED_RETURN(mp, i == 1);
408 } 413 }
409 /* 414 /*
410 * Fix up the by-block btree entry(s). 415 * Fix up the by-block btree entry(s).
@@ -415,7 +420,7 @@ xfs_alloc_fixup_trees(
415 */ 420 */
416 if ((error = xfs_btree_delete(bno_cur, &i))) 421 if ((error = xfs_btree_delete(bno_cur, &i)))
417 return error; 422 return error;
418 XFS_WANT_CORRUPTED_RETURN(i == 1); 423 XFS_WANT_CORRUPTED_RETURN(mp, i == 1);
419 } else { 424 } else {
420 /* 425 /*
421 * Update the by-block entry to start later|be shorter. 426 * Update the by-block entry to start later|be shorter.
@@ -429,10 +434,10 @@ xfs_alloc_fixup_trees(
429 */ 434 */
430 if ((error = xfs_alloc_lookup_eq(bno_cur, nfbno2, nflen2, &i))) 435 if ((error = xfs_alloc_lookup_eq(bno_cur, nfbno2, nflen2, &i)))
431 return error; 436 return error;
432 XFS_WANT_CORRUPTED_RETURN(i == 0); 437 XFS_WANT_CORRUPTED_RETURN(mp, i == 0);
433 if ((error = xfs_btree_insert(bno_cur, &i))) 438 if ((error = xfs_btree_insert(bno_cur, &i)))
434 return error; 439 return error;
435 XFS_WANT_CORRUPTED_RETURN(i == 1); 440 XFS_WANT_CORRUPTED_RETURN(mp, i == 1);
436 } 441 }
437 return 0; 442 return 0;
438} 443}
@@ -682,7 +687,7 @@ xfs_alloc_ag_vextent_exact(
682 error = xfs_alloc_get_rec(bno_cur, &fbno, &flen, &i); 687 error = xfs_alloc_get_rec(bno_cur, &fbno, &flen, &i);
683 if (error) 688 if (error)
684 goto error0; 689 goto error0;
685 XFS_WANT_CORRUPTED_GOTO(i == 1, error0); 690 XFS_WANT_CORRUPTED_GOTO(args->mp, i == 1, error0);
686 ASSERT(fbno <= args->agbno); 691 ASSERT(fbno <= args->agbno);
687 692
688 /* 693 /*
@@ -783,7 +788,7 @@ xfs_alloc_find_best_extent(
783 error = xfs_alloc_get_rec(*scur, sbno, slen, &i); 788 error = xfs_alloc_get_rec(*scur, sbno, slen, &i);
784 if (error) 789 if (error)
785 goto error0; 790 goto error0;
786 XFS_WANT_CORRUPTED_GOTO(i == 1, error0); 791 XFS_WANT_CORRUPTED_GOTO(args->mp, i == 1, error0);
787 xfs_alloc_compute_aligned(args, *sbno, *slen, sbnoa, slena); 792 xfs_alloc_compute_aligned(args, *sbno, *slen, sbnoa, slena);
788 793
789 /* 794 /*
@@ -946,7 +951,7 @@ restart:
946 if ((error = xfs_alloc_get_rec(cnt_cur, &ltbno, 951 if ((error = xfs_alloc_get_rec(cnt_cur, &ltbno,
947 &ltlen, &i))) 952 &ltlen, &i)))
948 goto error0; 953 goto error0;
949 XFS_WANT_CORRUPTED_GOTO(i == 1, error0); 954 XFS_WANT_CORRUPTED_GOTO(args->mp, i == 1, error0);
950 if (ltlen >= args->minlen) 955 if (ltlen >= args->minlen)
951 break; 956 break;
952 if ((error = xfs_btree_increment(cnt_cur, 0, &i))) 957 if ((error = xfs_btree_increment(cnt_cur, 0, &i)))
@@ -966,7 +971,7 @@ restart:
966 */ 971 */
967 if ((error = xfs_alloc_get_rec(cnt_cur, &ltbno, &ltlen, &i))) 972 if ((error = xfs_alloc_get_rec(cnt_cur, &ltbno, &ltlen, &i)))
968 goto error0; 973 goto error0;
969 XFS_WANT_CORRUPTED_GOTO(i == 1, error0); 974 XFS_WANT_CORRUPTED_GOTO(args->mp, i == 1, error0);
970 xfs_alloc_compute_aligned(args, ltbno, ltlen, 975 xfs_alloc_compute_aligned(args, ltbno, ltlen,
971 &ltbnoa, &ltlena); 976 &ltbnoa, &ltlena);
972 if (ltlena < args->minlen) 977 if (ltlena < args->minlen)
@@ -999,7 +1004,7 @@ restart:
999 cnt_cur->bc_ptrs[0] = besti; 1004 cnt_cur->bc_ptrs[0] = besti;
1000 if ((error = xfs_alloc_get_rec(cnt_cur, &ltbno, &ltlen, &i))) 1005 if ((error = xfs_alloc_get_rec(cnt_cur, &ltbno, &ltlen, &i)))
1001 goto error0; 1006 goto error0;
1002 XFS_WANT_CORRUPTED_GOTO(i == 1, error0); 1007 XFS_WANT_CORRUPTED_GOTO(args->mp, i == 1, error0);
1003 ASSERT(ltbno + ltlen <= be32_to_cpu(XFS_BUF_TO_AGF(args->agbp)->agf_length)); 1008 ASSERT(ltbno + ltlen <= be32_to_cpu(XFS_BUF_TO_AGF(args->agbp)->agf_length));
1004 args->len = blen; 1009 args->len = blen;
1005 if (!xfs_alloc_fix_minleft(args)) { 1010 if (!xfs_alloc_fix_minleft(args)) {
@@ -1088,7 +1093,7 @@ restart:
1088 if (bno_cur_lt) { 1093 if (bno_cur_lt) {
1089 if ((error = xfs_alloc_get_rec(bno_cur_lt, &ltbno, &ltlen, &i))) 1094 if ((error = xfs_alloc_get_rec(bno_cur_lt, &ltbno, &ltlen, &i)))
1090 goto error0; 1095 goto error0;
1091 XFS_WANT_CORRUPTED_GOTO(i == 1, error0); 1096 XFS_WANT_CORRUPTED_GOTO(args->mp, i == 1, error0);
1092 xfs_alloc_compute_aligned(args, ltbno, ltlen, 1097 xfs_alloc_compute_aligned(args, ltbno, ltlen,
1093 &ltbnoa, &ltlena); 1098 &ltbnoa, &ltlena);
1094 if (ltlena >= args->minlen) 1099 if (ltlena >= args->minlen)
@@ -1104,7 +1109,7 @@ restart:
1104 if (bno_cur_gt) { 1109 if (bno_cur_gt) {
1105 if ((error = xfs_alloc_get_rec(bno_cur_gt, &gtbno, &gtlen, &i))) 1110 if ((error = xfs_alloc_get_rec(bno_cur_gt, &gtbno, &gtlen, &i)))
1106 goto error0; 1111 goto error0;
1107 XFS_WANT_CORRUPTED_GOTO(i == 1, error0); 1112 XFS_WANT_CORRUPTED_GOTO(args->mp, i == 1, error0);
1108 xfs_alloc_compute_aligned(args, gtbno, gtlen, 1113 xfs_alloc_compute_aligned(args, gtbno, gtlen,
1109 &gtbnoa, &gtlena); 1114 &gtbnoa, &gtlena);
1110 if (gtlena >= args->minlen) 1115 if (gtlena >= args->minlen)
@@ -1303,7 +1308,7 @@ restart:
1303 error = xfs_alloc_get_rec(cnt_cur, &fbno, &flen, &i); 1308 error = xfs_alloc_get_rec(cnt_cur, &fbno, &flen, &i);
1304 if (error) 1309 if (error)
1305 goto error0; 1310 goto error0;
1306 XFS_WANT_CORRUPTED_GOTO(i == 1, error0); 1311 XFS_WANT_CORRUPTED_GOTO(args->mp, i == 1, error0);
1307 1312
1308 xfs_alloc_compute_aligned(args, fbno, flen, 1313 xfs_alloc_compute_aligned(args, fbno, flen,
1309 &rbno, &rlen); 1314 &rbno, &rlen);
@@ -1342,7 +1347,7 @@ restart:
1342 * This can't happen in the second case above. 1347 * This can't happen in the second case above.
1343 */ 1348 */
1344 rlen = XFS_EXTLEN_MIN(args->maxlen, rlen); 1349 rlen = XFS_EXTLEN_MIN(args->maxlen, rlen);
1345 XFS_WANT_CORRUPTED_GOTO(rlen == 0 || 1350 XFS_WANT_CORRUPTED_GOTO(args->mp, rlen == 0 ||
1346 (rlen <= flen && rbno + rlen <= fbno + flen), error0); 1351 (rlen <= flen && rbno + rlen <= fbno + flen), error0);
1347 if (rlen < args->maxlen) { 1352 if (rlen < args->maxlen) {
1348 xfs_agblock_t bestfbno; 1353 xfs_agblock_t bestfbno;
@@ -1362,13 +1367,13 @@ restart:
1362 if ((error = xfs_alloc_get_rec(cnt_cur, &fbno, &flen, 1367 if ((error = xfs_alloc_get_rec(cnt_cur, &fbno, &flen,
1363 &i))) 1368 &i)))
1364 goto error0; 1369 goto error0;
1365 XFS_WANT_CORRUPTED_GOTO(i == 1, error0); 1370 XFS_WANT_CORRUPTED_GOTO(args->mp, i == 1, error0);
1366 if (flen < bestrlen) 1371 if (flen < bestrlen)
1367 break; 1372 break;
1368 xfs_alloc_compute_aligned(args, fbno, flen, 1373 xfs_alloc_compute_aligned(args, fbno, flen,
1369 &rbno, &rlen); 1374 &rbno, &rlen);
1370 rlen = XFS_EXTLEN_MIN(args->maxlen, rlen); 1375 rlen = XFS_EXTLEN_MIN(args->maxlen, rlen);
1371 XFS_WANT_CORRUPTED_GOTO(rlen == 0 || 1376 XFS_WANT_CORRUPTED_GOTO(args->mp, rlen == 0 ||
1372 (rlen <= flen && rbno + rlen <= fbno + flen), 1377 (rlen <= flen && rbno + rlen <= fbno + flen),
1373 error0); 1378 error0);
1374 if (rlen > bestrlen) { 1379 if (rlen > bestrlen) {
@@ -1383,7 +1388,7 @@ restart:
1383 if ((error = xfs_alloc_lookup_eq(cnt_cur, bestfbno, bestflen, 1388 if ((error = xfs_alloc_lookup_eq(cnt_cur, bestfbno, bestflen,
1384 &i))) 1389 &i)))
1385 goto error0; 1390 goto error0;
1386 XFS_WANT_CORRUPTED_GOTO(i == 1, error0); 1391 XFS_WANT_CORRUPTED_GOTO(args->mp, i == 1, error0);
1387 rlen = bestrlen; 1392 rlen = bestrlen;
1388 rbno = bestrbno; 1393 rbno = bestrbno;
1389 flen = bestflen; 1394 flen = bestflen;
@@ -1408,7 +1413,7 @@ restart:
1408 if (!xfs_alloc_fix_minleft(args)) 1413 if (!xfs_alloc_fix_minleft(args))
1409 goto out_nominleft; 1414 goto out_nominleft;
1410 rlen = args->len; 1415 rlen = args->len;
1411 XFS_WANT_CORRUPTED_GOTO(rlen <= flen, error0); 1416 XFS_WANT_CORRUPTED_GOTO(args->mp, rlen <= flen, error0);
1412 /* 1417 /*
1413 * Allocate and initialize a cursor for the by-block tree. 1418 * Allocate and initialize a cursor for the by-block tree.
1414 */ 1419 */
@@ -1422,7 +1427,7 @@ restart:
1422 cnt_cur = bno_cur = NULL; 1427 cnt_cur = bno_cur = NULL;
1423 args->len = rlen; 1428 args->len = rlen;
1424 args->agbno = rbno; 1429 args->agbno = rbno;
1425 XFS_WANT_CORRUPTED_GOTO( 1430 XFS_WANT_CORRUPTED_GOTO(args->mp,
1426 args->agbno + args->len <= 1431 args->agbno + args->len <=
1427 be32_to_cpu(XFS_BUF_TO_AGF(args->agbp)->agf_length), 1432 be32_to_cpu(XFS_BUF_TO_AGF(args->agbp)->agf_length),
1428 error0); 1433 error0);
@@ -1467,7 +1472,7 @@ xfs_alloc_ag_vextent_small(
1467 if (i) { 1472 if (i) {
1468 if ((error = xfs_alloc_get_rec(ccur, &fbno, &flen, &i))) 1473 if ((error = xfs_alloc_get_rec(ccur, &fbno, &flen, &i)))
1469 goto error0; 1474 goto error0;
1470 XFS_WANT_CORRUPTED_GOTO(i == 1, error0); 1475 XFS_WANT_CORRUPTED_GOTO(args->mp, i == 1, error0);
1471 } 1476 }
1472 /* 1477 /*
1473 * Nothing in the btree, try the freelist. Make sure 1478 * Nothing in the btree, try the freelist. Make sure
@@ -1493,7 +1498,7 @@ xfs_alloc_ag_vextent_small(
1493 } 1498 }
1494 args->len = 1; 1499 args->len = 1;
1495 args->agbno = fbno; 1500 args->agbno = fbno;
1496 XFS_WANT_CORRUPTED_GOTO( 1501 XFS_WANT_CORRUPTED_GOTO(args->mp,
1497 args->agbno + args->len <= 1502 args->agbno + args->len <=
1498 be32_to_cpu(XFS_BUF_TO_AGF(args->agbp)->agf_length), 1503 be32_to_cpu(XFS_BUF_TO_AGF(args->agbp)->agf_length),
1499 error0); 1504 error0);
@@ -1579,7 +1584,7 @@ xfs_free_ag_extent(
1579 */ 1584 */
1580 if ((error = xfs_alloc_get_rec(bno_cur, &ltbno, &ltlen, &i))) 1585 if ((error = xfs_alloc_get_rec(bno_cur, &ltbno, &ltlen, &i)))
1581 goto error0; 1586 goto error0;
1582 XFS_WANT_CORRUPTED_GOTO(i == 1, error0); 1587 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, error0);
1583 /* 1588 /*
1584 * It's not contiguous, though. 1589 * It's not contiguous, though.
1585 */ 1590 */
@@ -1591,7 +1596,8 @@ xfs_free_ag_extent(
1591 * space was invalid, it's (partly) already free. 1596 * space was invalid, it's (partly) already free.
1592 * Very bad. 1597 * Very bad.
1593 */ 1598 */
1594 XFS_WANT_CORRUPTED_GOTO(ltbno + ltlen <= bno, error0); 1599 XFS_WANT_CORRUPTED_GOTO(mp,
1600 ltbno + ltlen <= bno, error0);
1595 } 1601 }
1596 } 1602 }
1597 /* 1603 /*
@@ -1606,7 +1612,7 @@ xfs_free_ag_extent(
1606 */ 1612 */
1607 if ((error = xfs_alloc_get_rec(bno_cur, &gtbno, &gtlen, &i))) 1613 if ((error = xfs_alloc_get_rec(bno_cur, &gtbno, &gtlen, &i)))
1608 goto error0; 1614 goto error0;
1609 XFS_WANT_CORRUPTED_GOTO(i == 1, error0); 1615 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, error0);
1610 /* 1616 /*
1611 * It's not contiguous, though. 1617 * It's not contiguous, though.
1612 */ 1618 */
@@ -1618,7 +1624,7 @@ xfs_free_ag_extent(
1618 * space was invalid, it's (partly) already free. 1624 * space was invalid, it's (partly) already free.
1619 * Very bad. 1625 * Very bad.
1620 */ 1626 */
1621 XFS_WANT_CORRUPTED_GOTO(gtbno >= bno + len, error0); 1627 XFS_WANT_CORRUPTED_GOTO(mp, gtbno >= bno + len, error0);
1622 } 1628 }
1623 } 1629 }
1624 /* 1630 /*
@@ -1635,31 +1641,31 @@ xfs_free_ag_extent(
1635 */ 1641 */
1636 if ((error = xfs_alloc_lookup_eq(cnt_cur, ltbno, ltlen, &i))) 1642 if ((error = xfs_alloc_lookup_eq(cnt_cur, ltbno, ltlen, &i)))
1637 goto error0; 1643 goto error0;
1638 XFS_WANT_CORRUPTED_GOTO(i == 1, error0); 1644 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, error0);
1639 if ((error = xfs_btree_delete(cnt_cur, &i))) 1645 if ((error = xfs_btree_delete(cnt_cur, &i)))
1640 goto error0; 1646 goto error0;
1641 XFS_WANT_CORRUPTED_GOTO(i == 1, error0); 1647 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, error0);
1642 /* 1648 /*
1643 * Delete the old by-size entry on the right. 1649 * Delete the old by-size entry on the right.
1644 */ 1650 */
1645 if ((error = xfs_alloc_lookup_eq(cnt_cur, gtbno, gtlen, &i))) 1651 if ((error = xfs_alloc_lookup_eq(cnt_cur, gtbno, gtlen, &i)))
1646 goto error0; 1652 goto error0;
1647 XFS_WANT_CORRUPTED_GOTO(i == 1, error0); 1653 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, error0);
1648 if ((error = xfs_btree_delete(cnt_cur, &i))) 1654 if ((error = xfs_btree_delete(cnt_cur, &i)))
1649 goto error0; 1655 goto error0;
1650 XFS_WANT_CORRUPTED_GOTO(i == 1, error0); 1656 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, error0);
1651 /* 1657 /*
1652 * Delete the old by-block entry for the right block. 1658 * Delete the old by-block entry for the right block.
1653 */ 1659 */
1654 if ((error = xfs_btree_delete(bno_cur, &i))) 1660 if ((error = xfs_btree_delete(bno_cur, &i)))
1655 goto error0; 1661 goto error0;
1656 XFS_WANT_CORRUPTED_GOTO(i == 1, error0); 1662 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, error0);
1657 /* 1663 /*
1658 * Move the by-block cursor back to the left neighbor. 1664 * Move the by-block cursor back to the left neighbor.
1659 */ 1665 */
1660 if ((error = xfs_btree_decrement(bno_cur, 0, &i))) 1666 if ((error = xfs_btree_decrement(bno_cur, 0, &i)))
1661 goto error0; 1667 goto error0;
1662 XFS_WANT_CORRUPTED_GOTO(i == 1, error0); 1668 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, error0);
1663#ifdef DEBUG 1669#ifdef DEBUG
1664 /* 1670 /*
1665 * Check that this is the right record: delete didn't 1671 * Check that this is the right record: delete didn't
@@ -1672,7 +1678,7 @@ xfs_free_ag_extent(
1672 if ((error = xfs_alloc_get_rec(bno_cur, &xxbno, &xxlen, 1678 if ((error = xfs_alloc_get_rec(bno_cur, &xxbno, &xxlen,
1673 &i))) 1679 &i)))
1674 goto error0; 1680 goto error0;
1675 XFS_WANT_CORRUPTED_GOTO( 1681 XFS_WANT_CORRUPTED_GOTO(mp,
1676 i == 1 && xxbno == ltbno && xxlen == ltlen, 1682 i == 1 && xxbno == ltbno && xxlen == ltlen,
1677 error0); 1683 error0);
1678 } 1684 }
@@ -1695,17 +1701,17 @@ xfs_free_ag_extent(
1695 */ 1701 */
1696 if ((error = xfs_alloc_lookup_eq(cnt_cur, ltbno, ltlen, &i))) 1702 if ((error = xfs_alloc_lookup_eq(cnt_cur, ltbno, ltlen, &i)))
1697 goto error0; 1703 goto error0;
1698 XFS_WANT_CORRUPTED_GOTO(i == 1, error0); 1704 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, error0);
1699 if ((error = xfs_btree_delete(cnt_cur, &i))) 1705 if ((error = xfs_btree_delete(cnt_cur, &i)))
1700 goto error0; 1706 goto error0;
1701 XFS_WANT_CORRUPTED_GOTO(i == 1, error0); 1707 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, error0);
1702 /* 1708 /*
1703 * Back up the by-block cursor to the left neighbor, and 1709 * Back up the by-block cursor to the left neighbor, and
1704 * update its length. 1710 * update its length.
1705 */ 1711 */
1706 if ((error = xfs_btree_decrement(bno_cur, 0, &i))) 1712 if ((error = xfs_btree_decrement(bno_cur, 0, &i)))
1707 goto error0; 1713 goto error0;
1708 XFS_WANT_CORRUPTED_GOTO(i == 1, error0); 1714 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, error0);
1709 nbno = ltbno; 1715 nbno = ltbno;
1710 nlen = len + ltlen; 1716 nlen = len + ltlen;
1711 if ((error = xfs_alloc_update(bno_cur, nbno, nlen))) 1717 if ((error = xfs_alloc_update(bno_cur, nbno, nlen)))
@@ -1721,10 +1727,10 @@ xfs_free_ag_extent(
1721 */ 1727 */
1722 if ((error = xfs_alloc_lookup_eq(cnt_cur, gtbno, gtlen, &i))) 1728 if ((error = xfs_alloc_lookup_eq(cnt_cur, gtbno, gtlen, &i)))
1723 goto error0; 1729 goto error0;
1724 XFS_WANT_CORRUPTED_GOTO(i == 1, error0); 1730 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, error0);
1725 if ((error = xfs_btree_delete(cnt_cur, &i))) 1731 if ((error = xfs_btree_delete(cnt_cur, &i)))
1726 goto error0; 1732 goto error0;
1727 XFS_WANT_CORRUPTED_GOTO(i == 1, error0); 1733 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, error0);
1728 /* 1734 /*
1729 * Update the starting block and length of the right 1735 * Update the starting block and length of the right
1730 * neighbor in the by-block tree. 1736 * neighbor in the by-block tree.
@@ -1743,7 +1749,7 @@ xfs_free_ag_extent(
1743 nlen = len; 1749 nlen = len;
1744 if ((error = xfs_btree_insert(bno_cur, &i))) 1750 if ((error = xfs_btree_insert(bno_cur, &i)))
1745 goto error0; 1751 goto error0;
1746 XFS_WANT_CORRUPTED_GOTO(i == 1, error0); 1752 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, error0);
1747 } 1753 }
1748 xfs_btree_del_cursor(bno_cur, XFS_BTREE_NOERROR); 1754 xfs_btree_del_cursor(bno_cur, XFS_BTREE_NOERROR);
1749 bno_cur = NULL; 1755 bno_cur = NULL;
@@ -1752,10 +1758,10 @@ xfs_free_ag_extent(
1752 */ 1758 */
1753 if ((error = xfs_alloc_lookup_eq(cnt_cur, nbno, nlen, &i))) 1759 if ((error = xfs_alloc_lookup_eq(cnt_cur, nbno, nlen, &i)))
1754 goto error0; 1760 goto error0;
1755 XFS_WANT_CORRUPTED_GOTO(i == 0, error0); 1761 XFS_WANT_CORRUPTED_GOTO(mp, i == 0, error0);
1756 if ((error = xfs_btree_insert(cnt_cur, &i))) 1762 if ((error = xfs_btree_insert(cnt_cur, &i)))
1757 goto error0; 1763 goto error0;
1758 XFS_WANT_CORRUPTED_GOTO(i == 1, error0); 1764 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, error0);
1759 xfs_btree_del_cursor(cnt_cur, XFS_BTREE_NOERROR); 1765 xfs_btree_del_cursor(cnt_cur, XFS_BTREE_NOERROR);
1760 cnt_cur = NULL; 1766 cnt_cur = NULL;
1761 1767
diff --git a/fs/xfs/libxfs/xfs_attr_leaf.c b/fs/xfs/libxfs/xfs_attr_leaf.c
index 15105dbc9e28..04e79d57bca6 100644
--- a/fs/xfs/libxfs/xfs_attr_leaf.c
+++ b/fs/xfs/libxfs/xfs_attr_leaf.c
@@ -86,8 +86,83 @@ STATIC void xfs_attr3_leaf_moveents(struct xfs_da_args *args,
86 int move_count); 86 int move_count);
87STATIC int xfs_attr_leaf_entsize(xfs_attr_leafblock_t *leaf, int index); 87STATIC int xfs_attr_leaf_entsize(xfs_attr_leafblock_t *leaf, int index);
88 88
89/*
90 * attr3 block 'firstused' conversion helpers.
91 *
92 * firstused refers to the offset of the first used byte of the nameval region
93 * of an attr leaf block. The region starts at the tail of the block and expands
94 * backwards towards the middle. As such, firstused is initialized to the block
95 * size for an empty leaf block and is reduced from there.
96 *
97 * The attr3 block size is pegged to the fsb size and the maximum fsb is 64k.
98 * The in-core firstused field is 32-bit and thus supports the maximum fsb size.
99 * The on-disk field is only 16-bit, however, and overflows at 64k. Since this
100 * only occurs at exactly 64k, we use zero as a magic on-disk value to represent
101 * the attr block size. The following helpers manage the conversion between the
102 * in-core and on-disk formats.
103 */
104
105static void
106xfs_attr3_leaf_firstused_from_disk(
107 struct xfs_da_geometry *geo,
108 struct xfs_attr3_icleaf_hdr *to,
109 struct xfs_attr_leafblock *from)
110{
111 struct xfs_attr3_leaf_hdr *hdr3;
112
113 if (from->hdr.info.magic == cpu_to_be16(XFS_ATTR3_LEAF_MAGIC)) {
114 hdr3 = (struct xfs_attr3_leaf_hdr *) from;
115 to->firstused = be16_to_cpu(hdr3->firstused);
116 } else {
117 to->firstused = be16_to_cpu(from->hdr.firstused);
118 }
119
120 /*
121 * Convert from the magic fsb size value to actual blocksize. This
122 * should only occur for empty blocks when the block size overflows
123 * 16-bits.
124 */
125 if (to->firstused == XFS_ATTR3_LEAF_NULLOFF) {
126 ASSERT(!to->count && !to->usedbytes);
127 ASSERT(geo->blksize > USHRT_MAX);
128 to->firstused = geo->blksize;
129 }
130}
131
132static void
133xfs_attr3_leaf_firstused_to_disk(
134 struct xfs_da_geometry *geo,
135 struct xfs_attr_leafblock *to,
136 struct xfs_attr3_icleaf_hdr *from)
137{
138 struct xfs_attr3_leaf_hdr *hdr3;
139 uint32_t firstused;
140
141 /* magic value should only be seen on disk */
142 ASSERT(from->firstused != XFS_ATTR3_LEAF_NULLOFF);
143
144 /*
145 * Scale down the 32-bit in-core firstused value to the 16-bit on-disk
146 * value. This only overflows at the max supported value of 64k. Use the
147 * magic on-disk value to represent block size in this case.
148 */
149 firstused = from->firstused;
150 if (firstused > USHRT_MAX) {
151 ASSERT(from->firstused == geo->blksize);
152 firstused = XFS_ATTR3_LEAF_NULLOFF;
153 }
154
155 if (from->magic == XFS_ATTR3_LEAF_MAGIC) {
156 hdr3 = (struct xfs_attr3_leaf_hdr *) to;
157 hdr3->firstused = cpu_to_be16(firstused);
158 } else {
159 to->hdr.firstused = cpu_to_be16(firstused);
160 }
161}
162
89void 163void
90xfs_attr3_leaf_hdr_from_disk( 164xfs_attr3_leaf_hdr_from_disk(
165 struct xfs_da_geometry *geo,
91 struct xfs_attr3_icleaf_hdr *to, 166 struct xfs_attr3_icleaf_hdr *to,
92 struct xfs_attr_leafblock *from) 167 struct xfs_attr_leafblock *from)
93{ 168{
@@ -104,7 +179,7 @@ xfs_attr3_leaf_hdr_from_disk(
104 to->magic = be16_to_cpu(hdr3->info.hdr.magic); 179 to->magic = be16_to_cpu(hdr3->info.hdr.magic);
105 to->count = be16_to_cpu(hdr3->count); 180 to->count = be16_to_cpu(hdr3->count);
106 to->usedbytes = be16_to_cpu(hdr3->usedbytes); 181 to->usedbytes = be16_to_cpu(hdr3->usedbytes);
107 to->firstused = be16_to_cpu(hdr3->firstused); 182 xfs_attr3_leaf_firstused_from_disk(geo, to, from);
108 to->holes = hdr3->holes; 183 to->holes = hdr3->holes;
109 184
110 for (i = 0; i < XFS_ATTR_LEAF_MAPSIZE; i++) { 185 for (i = 0; i < XFS_ATTR_LEAF_MAPSIZE; i++) {
@@ -118,7 +193,7 @@ xfs_attr3_leaf_hdr_from_disk(
118 to->magic = be16_to_cpu(from->hdr.info.magic); 193 to->magic = be16_to_cpu(from->hdr.info.magic);
119 to->count = be16_to_cpu(from->hdr.count); 194 to->count = be16_to_cpu(from->hdr.count);
120 to->usedbytes = be16_to_cpu(from->hdr.usedbytes); 195 to->usedbytes = be16_to_cpu(from->hdr.usedbytes);
121 to->firstused = be16_to_cpu(from->hdr.firstused); 196 xfs_attr3_leaf_firstused_from_disk(geo, to, from);
122 to->holes = from->hdr.holes; 197 to->holes = from->hdr.holes;
123 198
124 for (i = 0; i < XFS_ATTR_LEAF_MAPSIZE; i++) { 199 for (i = 0; i < XFS_ATTR_LEAF_MAPSIZE; i++) {
@@ -129,10 +204,11 @@ xfs_attr3_leaf_hdr_from_disk(
129 204
130void 205void
131xfs_attr3_leaf_hdr_to_disk( 206xfs_attr3_leaf_hdr_to_disk(
207 struct xfs_da_geometry *geo,
132 struct xfs_attr_leafblock *to, 208 struct xfs_attr_leafblock *to,
133 struct xfs_attr3_icleaf_hdr *from) 209 struct xfs_attr3_icleaf_hdr *from)
134{ 210{
135 int i; 211 int i;
136 212
137 ASSERT(from->magic == XFS_ATTR_LEAF_MAGIC || 213 ASSERT(from->magic == XFS_ATTR_LEAF_MAGIC ||
138 from->magic == XFS_ATTR3_LEAF_MAGIC); 214 from->magic == XFS_ATTR3_LEAF_MAGIC);
@@ -145,7 +221,7 @@ xfs_attr3_leaf_hdr_to_disk(
145 hdr3->info.hdr.magic = cpu_to_be16(from->magic); 221 hdr3->info.hdr.magic = cpu_to_be16(from->magic);
146 hdr3->count = cpu_to_be16(from->count); 222 hdr3->count = cpu_to_be16(from->count);
147 hdr3->usedbytes = cpu_to_be16(from->usedbytes); 223 hdr3->usedbytes = cpu_to_be16(from->usedbytes);
148 hdr3->firstused = cpu_to_be16(from->firstused); 224 xfs_attr3_leaf_firstused_to_disk(geo, to, from);
149 hdr3->holes = from->holes; 225 hdr3->holes = from->holes;
150 hdr3->pad1 = 0; 226 hdr3->pad1 = 0;
151 227
@@ -160,7 +236,7 @@ xfs_attr3_leaf_hdr_to_disk(
160 to->hdr.info.magic = cpu_to_be16(from->magic); 236 to->hdr.info.magic = cpu_to_be16(from->magic);
161 to->hdr.count = cpu_to_be16(from->count); 237 to->hdr.count = cpu_to_be16(from->count);
162 to->hdr.usedbytes = cpu_to_be16(from->usedbytes); 238 to->hdr.usedbytes = cpu_to_be16(from->usedbytes);
163 to->hdr.firstused = cpu_to_be16(from->firstused); 239 xfs_attr3_leaf_firstused_to_disk(geo, to, from);
164 to->hdr.holes = from->holes; 240 to->hdr.holes = from->holes;
165 to->hdr.pad1 = 0; 241 to->hdr.pad1 = 0;
166 242
@@ -178,7 +254,7 @@ xfs_attr3_leaf_verify(
178 struct xfs_attr_leafblock *leaf = bp->b_addr; 254 struct xfs_attr_leafblock *leaf = bp->b_addr;
179 struct xfs_attr3_icleaf_hdr ichdr; 255 struct xfs_attr3_icleaf_hdr ichdr;
180 256
181 xfs_attr3_leaf_hdr_from_disk(&ichdr, leaf); 257 xfs_attr3_leaf_hdr_from_disk(mp->m_attr_geo, &ichdr, leaf);
182 258
183 if (xfs_sb_version_hascrc(&mp->m_sb)) { 259 if (xfs_sb_version_hascrc(&mp->m_sb)) {
184 struct xfs_da3_node_hdr *hdr3 = bp->b_addr; 260 struct xfs_da3_node_hdr *hdr3 = bp->b_addr;
@@ -757,9 +833,10 @@ xfs_attr_shortform_allfit(
757 struct xfs_attr3_icleaf_hdr leafhdr; 833 struct xfs_attr3_icleaf_hdr leafhdr;
758 int bytes; 834 int bytes;
759 int i; 835 int i;
836 struct xfs_mount *mp = bp->b_target->bt_mount;
760 837
761 leaf = bp->b_addr; 838 leaf = bp->b_addr;
762 xfs_attr3_leaf_hdr_from_disk(&leafhdr, leaf); 839 xfs_attr3_leaf_hdr_from_disk(mp->m_attr_geo, &leafhdr, leaf);
763 entry = xfs_attr3_leaf_entryp(leaf); 840 entry = xfs_attr3_leaf_entryp(leaf);
764 841
765 bytes = sizeof(struct xfs_attr_sf_hdr); 842 bytes = sizeof(struct xfs_attr_sf_hdr);
@@ -812,7 +889,7 @@ xfs_attr3_leaf_to_shortform(
812 memcpy(tmpbuffer, bp->b_addr, args->geo->blksize); 889 memcpy(tmpbuffer, bp->b_addr, args->geo->blksize);
813 890
814 leaf = (xfs_attr_leafblock_t *)tmpbuffer; 891 leaf = (xfs_attr_leafblock_t *)tmpbuffer;
815 xfs_attr3_leaf_hdr_from_disk(&ichdr, leaf); 892 xfs_attr3_leaf_hdr_from_disk(args->geo, &ichdr, leaf);
816 entry = xfs_attr3_leaf_entryp(leaf); 893 entry = xfs_attr3_leaf_entryp(leaf);
817 894
818 /* XXX (dgc): buffer is about to be marked stale - why zero it? */ 895 /* XXX (dgc): buffer is about to be marked stale - why zero it? */
@@ -923,7 +1000,7 @@ xfs_attr3_leaf_to_node(
923 btree = dp->d_ops->node_tree_p(node); 1000 btree = dp->d_ops->node_tree_p(node);
924 1001
925 leaf = bp2->b_addr; 1002 leaf = bp2->b_addr;
926 xfs_attr3_leaf_hdr_from_disk(&icleafhdr, leaf); 1003 xfs_attr3_leaf_hdr_from_disk(args->geo, &icleafhdr, leaf);
927 entries = xfs_attr3_leaf_entryp(leaf); 1004 entries = xfs_attr3_leaf_entryp(leaf);
928 1005
929 /* both on-disk, don't endian-flip twice */ 1006 /* both on-disk, don't endian-flip twice */
@@ -988,7 +1065,7 @@ xfs_attr3_leaf_create(
988 } 1065 }
989 ichdr.freemap[0].size = ichdr.firstused - ichdr.freemap[0].base; 1066 ichdr.freemap[0].size = ichdr.firstused - ichdr.freemap[0].base;
990 1067
991 xfs_attr3_leaf_hdr_to_disk(leaf, &ichdr); 1068 xfs_attr3_leaf_hdr_to_disk(args->geo, leaf, &ichdr);
992 xfs_trans_log_buf(args->trans, bp, 0, args->geo->blksize - 1); 1069 xfs_trans_log_buf(args->trans, bp, 0, args->geo->blksize - 1);
993 1070
994 *bpp = bp; 1071 *bpp = bp;
@@ -1073,7 +1150,7 @@ xfs_attr3_leaf_add(
1073 trace_xfs_attr_leaf_add(args); 1150 trace_xfs_attr_leaf_add(args);
1074 1151
1075 leaf = bp->b_addr; 1152 leaf = bp->b_addr;
1076 xfs_attr3_leaf_hdr_from_disk(&ichdr, leaf); 1153 xfs_attr3_leaf_hdr_from_disk(args->geo, &ichdr, leaf);
1077 ASSERT(args->index >= 0 && args->index <= ichdr.count); 1154 ASSERT(args->index >= 0 && args->index <= ichdr.count);
1078 entsize = xfs_attr_leaf_newentsize(args, NULL); 1155 entsize = xfs_attr_leaf_newentsize(args, NULL);
1079 1156
@@ -1126,7 +1203,7 @@ xfs_attr3_leaf_add(
1126 tmp = xfs_attr3_leaf_add_work(bp, &ichdr, args, 0); 1203 tmp = xfs_attr3_leaf_add_work(bp, &ichdr, args, 0);
1127 1204
1128out_log_hdr: 1205out_log_hdr:
1129 xfs_attr3_leaf_hdr_to_disk(leaf, &ichdr); 1206 xfs_attr3_leaf_hdr_to_disk(args->geo, leaf, &ichdr);
1130 xfs_trans_log_buf(args->trans, bp, 1207 xfs_trans_log_buf(args->trans, bp,
1131 XFS_DA_LOGRANGE(leaf, &leaf->hdr, 1208 XFS_DA_LOGRANGE(leaf, &leaf->hdr,
1132 xfs_attr3_leaf_hdr_size(leaf))); 1209 xfs_attr3_leaf_hdr_size(leaf)));
@@ -1294,7 +1371,7 @@ xfs_attr3_leaf_compact(
1294 ichdr_dst->freemap[0].base; 1371 ichdr_dst->freemap[0].base;
1295 1372
1296 /* write the header back to initialise the underlying buffer */ 1373 /* write the header back to initialise the underlying buffer */
1297 xfs_attr3_leaf_hdr_to_disk(leaf_dst, ichdr_dst); 1374 xfs_attr3_leaf_hdr_to_disk(args->geo, leaf_dst, ichdr_dst);
1298 1375
1299 /* 1376 /*
1300 * Copy all entry's in the same (sorted) order, 1377 * Copy all entry's in the same (sorted) order,
@@ -1344,9 +1421,10 @@ xfs_attr_leaf_order(
1344{ 1421{
1345 struct xfs_attr3_icleaf_hdr ichdr1; 1422 struct xfs_attr3_icleaf_hdr ichdr1;
1346 struct xfs_attr3_icleaf_hdr ichdr2; 1423 struct xfs_attr3_icleaf_hdr ichdr2;
1424 struct xfs_mount *mp = leaf1_bp->b_target->bt_mount;
1347 1425
1348 xfs_attr3_leaf_hdr_from_disk(&ichdr1, leaf1_bp->b_addr); 1426 xfs_attr3_leaf_hdr_from_disk(mp->m_attr_geo, &ichdr1, leaf1_bp->b_addr);
1349 xfs_attr3_leaf_hdr_from_disk(&ichdr2, leaf2_bp->b_addr); 1427 xfs_attr3_leaf_hdr_from_disk(mp->m_attr_geo, &ichdr2, leaf2_bp->b_addr);
1350 return xfs_attr3_leaf_order(leaf1_bp, &ichdr1, leaf2_bp, &ichdr2); 1428 return xfs_attr3_leaf_order(leaf1_bp, &ichdr1, leaf2_bp, &ichdr2);
1351} 1429}
1352 1430
@@ -1388,8 +1466,8 @@ xfs_attr3_leaf_rebalance(
1388 ASSERT(blk2->magic == XFS_ATTR_LEAF_MAGIC); 1466 ASSERT(blk2->magic == XFS_ATTR_LEAF_MAGIC);
1389 leaf1 = blk1->bp->b_addr; 1467 leaf1 = blk1->bp->b_addr;
1390 leaf2 = blk2->bp->b_addr; 1468 leaf2 = blk2->bp->b_addr;
1391 xfs_attr3_leaf_hdr_from_disk(&ichdr1, leaf1); 1469 xfs_attr3_leaf_hdr_from_disk(state->args->geo, &ichdr1, leaf1);
1392 xfs_attr3_leaf_hdr_from_disk(&ichdr2, leaf2); 1470 xfs_attr3_leaf_hdr_from_disk(state->args->geo, &ichdr2, leaf2);
1393 ASSERT(ichdr2.count == 0); 1471 ASSERT(ichdr2.count == 0);
1394 args = state->args; 1472 args = state->args;
1395 1473
@@ -1490,8 +1568,8 @@ xfs_attr3_leaf_rebalance(
1490 ichdr1.count, count); 1568 ichdr1.count, count);
1491 } 1569 }
1492 1570
1493 xfs_attr3_leaf_hdr_to_disk(leaf1, &ichdr1); 1571 xfs_attr3_leaf_hdr_to_disk(state->args->geo, leaf1, &ichdr1);
1494 xfs_attr3_leaf_hdr_to_disk(leaf2, &ichdr2); 1572 xfs_attr3_leaf_hdr_to_disk(state->args->geo, leaf2, &ichdr2);
1495 xfs_trans_log_buf(args->trans, blk1->bp, 0, args->geo->blksize - 1); 1573 xfs_trans_log_buf(args->trans, blk1->bp, 0, args->geo->blksize - 1);
1496 xfs_trans_log_buf(args->trans, blk2->bp, 0, args->geo->blksize - 1); 1574 xfs_trans_log_buf(args->trans, blk2->bp, 0, args->geo->blksize - 1);
1497 1575
@@ -1684,7 +1762,7 @@ xfs_attr3_leaf_toosmall(
1684 */ 1762 */
1685 blk = &state->path.blk[ state->path.active-1 ]; 1763 blk = &state->path.blk[ state->path.active-1 ];
1686 leaf = blk->bp->b_addr; 1764 leaf = blk->bp->b_addr;
1687 xfs_attr3_leaf_hdr_from_disk(&ichdr, leaf); 1765 xfs_attr3_leaf_hdr_from_disk(state->args->geo, &ichdr, leaf);
1688 bytes = xfs_attr3_leaf_hdr_size(leaf) + 1766 bytes = xfs_attr3_leaf_hdr_size(leaf) +
1689 ichdr.count * sizeof(xfs_attr_leaf_entry_t) + 1767 ichdr.count * sizeof(xfs_attr_leaf_entry_t) +
1690 ichdr.usedbytes; 1768 ichdr.usedbytes;
@@ -1740,7 +1818,7 @@ xfs_attr3_leaf_toosmall(
1740 if (error) 1818 if (error)
1741 return error; 1819 return error;
1742 1820
1743 xfs_attr3_leaf_hdr_from_disk(&ichdr2, bp->b_addr); 1821 xfs_attr3_leaf_hdr_from_disk(state->args->geo, &ichdr2, bp->b_addr);
1744 1822
1745 bytes = state->args->geo->blksize - 1823 bytes = state->args->geo->blksize -
1746 (state->args->geo->blksize >> 2) - 1824 (state->args->geo->blksize >> 2) -
@@ -1805,7 +1883,7 @@ xfs_attr3_leaf_remove(
1805 trace_xfs_attr_leaf_remove(args); 1883 trace_xfs_attr_leaf_remove(args);
1806 1884
1807 leaf = bp->b_addr; 1885 leaf = bp->b_addr;
1808 xfs_attr3_leaf_hdr_from_disk(&ichdr, leaf); 1886 xfs_attr3_leaf_hdr_from_disk(args->geo, &ichdr, leaf);
1809 1887
1810 ASSERT(ichdr.count > 0 && ichdr.count < args->geo->blksize / 8); 1888 ASSERT(ichdr.count > 0 && ichdr.count < args->geo->blksize / 8);
1811 ASSERT(args->index >= 0 && args->index < ichdr.count); 1889 ASSERT(args->index >= 0 && args->index < ichdr.count);
@@ -1918,12 +1996,11 @@ xfs_attr3_leaf_remove(
1918 tmp = be16_to_cpu(entry->nameidx); 1996 tmp = be16_to_cpu(entry->nameidx);
1919 } 1997 }
1920 ichdr.firstused = tmp; 1998 ichdr.firstused = tmp;
1921 if (!ichdr.firstused) 1999 ASSERT(ichdr.firstused != 0);
1922 ichdr.firstused = tmp - XFS_ATTR_LEAF_NAME_ALIGN;
1923 } else { 2000 } else {
1924 ichdr.holes = 1; /* mark as needing compaction */ 2001 ichdr.holes = 1; /* mark as needing compaction */
1925 } 2002 }
1926 xfs_attr3_leaf_hdr_to_disk(leaf, &ichdr); 2003 xfs_attr3_leaf_hdr_to_disk(args->geo, leaf, &ichdr);
1927 xfs_trans_log_buf(args->trans, bp, 2004 xfs_trans_log_buf(args->trans, bp,
1928 XFS_DA_LOGRANGE(leaf, &leaf->hdr, 2005 XFS_DA_LOGRANGE(leaf, &leaf->hdr,
1929 xfs_attr3_leaf_hdr_size(leaf))); 2006 xfs_attr3_leaf_hdr_size(leaf)));
@@ -1957,8 +2034,8 @@ xfs_attr3_leaf_unbalance(
1957 2034
1958 drop_leaf = drop_blk->bp->b_addr; 2035 drop_leaf = drop_blk->bp->b_addr;
1959 save_leaf = save_blk->bp->b_addr; 2036 save_leaf = save_blk->bp->b_addr;
1960 xfs_attr3_leaf_hdr_from_disk(&drophdr, drop_leaf); 2037 xfs_attr3_leaf_hdr_from_disk(state->args->geo, &drophdr, drop_leaf);
1961 xfs_attr3_leaf_hdr_from_disk(&savehdr, save_leaf); 2038 xfs_attr3_leaf_hdr_from_disk(state->args->geo, &savehdr, save_leaf);
1962 entry = xfs_attr3_leaf_entryp(drop_leaf); 2039 entry = xfs_attr3_leaf_entryp(drop_leaf);
1963 2040
1964 /* 2041 /*
@@ -2012,7 +2089,7 @@ xfs_attr3_leaf_unbalance(
2012 tmphdr.firstused = state->args->geo->blksize; 2089 tmphdr.firstused = state->args->geo->blksize;
2013 2090
2014 /* write the header to the temp buffer to initialise it */ 2091 /* write the header to the temp buffer to initialise it */
2015 xfs_attr3_leaf_hdr_to_disk(tmp_leaf, &tmphdr); 2092 xfs_attr3_leaf_hdr_to_disk(state->args->geo, tmp_leaf, &tmphdr);
2016 2093
2017 if (xfs_attr3_leaf_order(save_blk->bp, &savehdr, 2094 if (xfs_attr3_leaf_order(save_blk->bp, &savehdr,
2018 drop_blk->bp, &drophdr)) { 2095 drop_blk->bp, &drophdr)) {
@@ -2039,7 +2116,7 @@ xfs_attr3_leaf_unbalance(
2039 kmem_free(tmp_leaf); 2116 kmem_free(tmp_leaf);
2040 } 2117 }
2041 2118
2042 xfs_attr3_leaf_hdr_to_disk(save_leaf, &savehdr); 2119 xfs_attr3_leaf_hdr_to_disk(state->args->geo, save_leaf, &savehdr);
2043 xfs_trans_log_buf(state->args->trans, save_blk->bp, 0, 2120 xfs_trans_log_buf(state->args->trans, save_blk->bp, 0,
2044 state->args->geo->blksize - 1); 2121 state->args->geo->blksize - 1);
2045 2122
@@ -2085,7 +2162,7 @@ xfs_attr3_leaf_lookup_int(
2085 trace_xfs_attr_leaf_lookup(args); 2162 trace_xfs_attr_leaf_lookup(args);
2086 2163
2087 leaf = bp->b_addr; 2164 leaf = bp->b_addr;
2088 xfs_attr3_leaf_hdr_from_disk(&ichdr, leaf); 2165 xfs_attr3_leaf_hdr_from_disk(args->geo, &ichdr, leaf);
2089 entries = xfs_attr3_leaf_entryp(leaf); 2166 entries = xfs_attr3_leaf_entryp(leaf);
2090 ASSERT(ichdr.count < args->geo->blksize / 8); 2167 ASSERT(ichdr.count < args->geo->blksize / 8);
2091 2168
@@ -2190,7 +2267,7 @@ xfs_attr3_leaf_getvalue(
2190 int valuelen; 2267 int valuelen;
2191 2268
2192 leaf = bp->b_addr; 2269 leaf = bp->b_addr;
2193 xfs_attr3_leaf_hdr_from_disk(&ichdr, leaf); 2270 xfs_attr3_leaf_hdr_from_disk(args->geo, &ichdr, leaf);
2194 ASSERT(ichdr.count < args->geo->blksize / 8); 2271 ASSERT(ichdr.count < args->geo->blksize / 8);
2195 ASSERT(args->index < ichdr.count); 2272 ASSERT(args->index < ichdr.count);
2196 2273
@@ -2391,8 +2468,9 @@ xfs_attr_leaf_lasthash(
2391{ 2468{
2392 struct xfs_attr3_icleaf_hdr ichdr; 2469 struct xfs_attr3_icleaf_hdr ichdr;
2393 struct xfs_attr_leaf_entry *entries; 2470 struct xfs_attr_leaf_entry *entries;
2471 struct xfs_mount *mp = bp->b_target->bt_mount;
2394 2472
2395 xfs_attr3_leaf_hdr_from_disk(&ichdr, bp->b_addr); 2473 xfs_attr3_leaf_hdr_from_disk(mp->m_attr_geo, &ichdr, bp->b_addr);
2396 entries = xfs_attr3_leaf_entryp(bp->b_addr); 2474 entries = xfs_attr3_leaf_entryp(bp->b_addr);
2397 if (count) 2475 if (count)
2398 *count = ichdr.count; 2476 *count = ichdr.count;
@@ -2486,7 +2564,7 @@ xfs_attr3_leaf_clearflag(
2486 ASSERT(entry->flags & XFS_ATTR_INCOMPLETE); 2564 ASSERT(entry->flags & XFS_ATTR_INCOMPLETE);
2487 2565
2488#ifdef DEBUG 2566#ifdef DEBUG
2489 xfs_attr3_leaf_hdr_from_disk(&ichdr, leaf); 2567 xfs_attr3_leaf_hdr_from_disk(args->geo, &ichdr, leaf);
2490 ASSERT(args->index < ichdr.count); 2568 ASSERT(args->index < ichdr.count);
2491 ASSERT(args->index >= 0); 2569 ASSERT(args->index >= 0);
2492 2570
@@ -2550,7 +2628,7 @@ xfs_attr3_leaf_setflag(
2550 2628
2551 leaf = bp->b_addr; 2629 leaf = bp->b_addr;
2552#ifdef DEBUG 2630#ifdef DEBUG
2553 xfs_attr3_leaf_hdr_from_disk(&ichdr, leaf); 2631 xfs_attr3_leaf_hdr_from_disk(args->geo, &ichdr, leaf);
2554 ASSERT(args->index < ichdr.count); 2632 ASSERT(args->index < ichdr.count);
2555 ASSERT(args->index >= 0); 2633 ASSERT(args->index >= 0);
2556#endif 2634#endif
@@ -2629,11 +2707,11 @@ xfs_attr3_leaf_flipflags(
2629 entry2 = &xfs_attr3_leaf_entryp(leaf2)[args->index2]; 2707 entry2 = &xfs_attr3_leaf_entryp(leaf2)[args->index2];
2630 2708
2631#ifdef DEBUG 2709#ifdef DEBUG
2632 xfs_attr3_leaf_hdr_from_disk(&ichdr1, leaf1); 2710 xfs_attr3_leaf_hdr_from_disk(args->geo, &ichdr1, leaf1);
2633 ASSERT(args->index < ichdr1.count); 2711 ASSERT(args->index < ichdr1.count);
2634 ASSERT(args->index >= 0); 2712 ASSERT(args->index >= 0);
2635 2713
2636 xfs_attr3_leaf_hdr_from_disk(&ichdr2, leaf2); 2714 xfs_attr3_leaf_hdr_from_disk(args->geo, &ichdr2, leaf2);
2637 ASSERT(args->index2 < ichdr2.count); 2715 ASSERT(args->index2 < ichdr2.count);
2638 ASSERT(args->index2 >= 0); 2716 ASSERT(args->index2 >= 0);
2639 2717
diff --git a/fs/xfs/libxfs/xfs_attr_leaf.h b/fs/xfs/libxfs/xfs_attr_leaf.h
index e2929da7c3ba..025c4b820c03 100644
--- a/fs/xfs/libxfs/xfs_attr_leaf.h
+++ b/fs/xfs/libxfs/xfs_attr_leaf.h
@@ -100,9 +100,11 @@ int xfs_attr_leaf_newentsize(struct xfs_da_args *args, int *local);
100int xfs_attr3_leaf_read(struct xfs_trans *tp, struct xfs_inode *dp, 100int xfs_attr3_leaf_read(struct xfs_trans *tp, struct xfs_inode *dp,
101 xfs_dablk_t bno, xfs_daddr_t mappedbno, 101 xfs_dablk_t bno, xfs_daddr_t mappedbno,
102 struct xfs_buf **bpp); 102 struct xfs_buf **bpp);
103void xfs_attr3_leaf_hdr_from_disk(struct xfs_attr3_icleaf_hdr *to, 103void xfs_attr3_leaf_hdr_from_disk(struct xfs_da_geometry *geo,
104 struct xfs_attr3_icleaf_hdr *to,
104 struct xfs_attr_leafblock *from); 105 struct xfs_attr_leafblock *from);
105void xfs_attr3_leaf_hdr_to_disk(struct xfs_attr_leafblock *to, 106void xfs_attr3_leaf_hdr_to_disk(struct xfs_da_geometry *geo,
107 struct xfs_attr_leafblock *to,
106 struct xfs_attr3_icleaf_hdr *from); 108 struct xfs_attr3_icleaf_hdr *from);
107 109
108#endif /* __XFS_ATTR_LEAF_H__ */ 110#endif /* __XFS_ATTR_LEAF_H__ */
diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
index 61ec015dca16..aeffeaaac0ec 100644
--- a/fs/xfs/libxfs/xfs_bmap.c
+++ b/fs/xfs/libxfs/xfs_bmap.c
@@ -244,30 +244,6 @@ xfs_bmap_forkoff_reset(
244 } 244 }
245} 245}
246 246
247/*
248 * Debug/sanity checking code
249 */
250
251STATIC int
252xfs_bmap_sanity_check(
253 struct xfs_mount *mp,
254 struct xfs_buf *bp,
255 int level)
256{
257 struct xfs_btree_block *block = XFS_BUF_TO_BLOCK(bp);
258
259 if (block->bb_magic != cpu_to_be32(XFS_BMAP_CRC_MAGIC) &&
260 block->bb_magic != cpu_to_be32(XFS_BMAP_MAGIC))
261 return 0;
262
263 if (be16_to_cpu(block->bb_level) != level ||
264 be16_to_cpu(block->bb_numrecs) == 0 ||
265 be16_to_cpu(block->bb_numrecs) > mp->m_bmap_dmxr[level != 0])
266 return 0;
267
268 return 1;
269}
270
271#ifdef DEBUG 247#ifdef DEBUG
272STATIC struct xfs_buf * 248STATIC struct xfs_buf *
273xfs_bmap_get_bp( 249xfs_bmap_get_bp(
@@ -410,9 +386,6 @@ xfs_bmap_check_leaf_extents(
410 goto error_norelse; 386 goto error_norelse;
411 } 387 }
412 block = XFS_BUF_TO_BLOCK(bp); 388 block = XFS_BUF_TO_BLOCK(bp);
413 XFS_WANT_CORRUPTED_GOTO(
414 xfs_bmap_sanity_check(mp, bp, level),
415 error0);
416 if (level == 0) 389 if (level == 0)
417 break; 390 break;
418 391
@@ -424,7 +397,8 @@ xfs_bmap_check_leaf_extents(
424 xfs_check_block(block, mp, 0, 0); 397 xfs_check_block(block, mp, 0, 0);
425 pp = XFS_BMBT_PTR_ADDR(mp, block, 1, mp->m_bmap_dmxr[1]); 398 pp = XFS_BMBT_PTR_ADDR(mp, block, 1, mp->m_bmap_dmxr[1]);
426 bno = be64_to_cpu(*pp); 399 bno = be64_to_cpu(*pp);
427 XFS_WANT_CORRUPTED_GOTO(XFS_FSB_SANITY_CHECK(mp, bno), error0); 400 XFS_WANT_CORRUPTED_GOTO(mp,
401 XFS_FSB_SANITY_CHECK(mp, bno), error0);
428 if (bp_release) { 402 if (bp_release) {
429 bp_release = 0; 403 bp_release = 0;
430 xfs_trans_brelse(NULL, bp); 404 xfs_trans_brelse(NULL, bp);
@@ -1029,7 +1003,7 @@ xfs_bmap_add_attrfork_btree(
1029 if ((error = xfs_bmbt_lookup_ge(cur, 0, 0, 0, &stat))) 1003 if ((error = xfs_bmbt_lookup_ge(cur, 0, 0, 0, &stat)))
1030 goto error0; 1004 goto error0;
1031 /* must be at least one entry */ 1005 /* must be at least one entry */
1032 XFS_WANT_CORRUPTED_GOTO(stat == 1, error0); 1006 XFS_WANT_CORRUPTED_GOTO(mp, stat == 1, error0);
1033 if ((error = xfs_btree_new_iroot(cur, flags, &stat))) 1007 if ((error = xfs_btree_new_iroot(cur, flags, &stat)))
1034 goto error0; 1008 goto error0;
1035 if (stat == 0) { 1009 if (stat == 0) {
@@ -1311,14 +1285,12 @@ xfs_bmap_read_extents(
1311 if (error) 1285 if (error)
1312 return error; 1286 return error;
1313 block = XFS_BUF_TO_BLOCK(bp); 1287 block = XFS_BUF_TO_BLOCK(bp);
1314 XFS_WANT_CORRUPTED_GOTO(
1315 xfs_bmap_sanity_check(mp, bp, level),
1316 error0);
1317 if (level == 0) 1288 if (level == 0)
1318 break; 1289 break;
1319 pp = XFS_BMBT_PTR_ADDR(mp, block, 1, mp->m_bmap_dmxr[1]); 1290 pp = XFS_BMBT_PTR_ADDR(mp, block, 1, mp->m_bmap_dmxr[1]);
1320 bno = be64_to_cpu(*pp); 1291 bno = be64_to_cpu(*pp);
1321 XFS_WANT_CORRUPTED_GOTO(XFS_FSB_SANITY_CHECK(mp, bno), error0); 1292 XFS_WANT_CORRUPTED_GOTO(mp,
1293 XFS_FSB_SANITY_CHECK(mp, bno), error0);
1322 xfs_trans_brelse(tp, bp); 1294 xfs_trans_brelse(tp, bp);
1323 } 1295 }
1324 /* 1296 /*
@@ -1345,9 +1317,6 @@ xfs_bmap_read_extents(
1345 XFS_ERRLEVEL_LOW, ip->i_mount, block); 1317 XFS_ERRLEVEL_LOW, ip->i_mount, block);
1346 goto error0; 1318 goto error0;
1347 } 1319 }
1348 XFS_WANT_CORRUPTED_GOTO(
1349 xfs_bmap_sanity_check(mp, bp, 0),
1350 error0);
1351 /* 1320 /*
1352 * Read-ahead the next leaf block, if any. 1321 * Read-ahead the next leaf block, if any.
1353 */ 1322 */
@@ -1755,7 +1724,9 @@ xfs_bmap_add_extent_delay_real(
1755 xfs_filblks_t temp=0; /* value for da_new calculations */ 1724 xfs_filblks_t temp=0; /* value for da_new calculations */
1756 xfs_filblks_t temp2=0;/* value for da_new calculations */ 1725 xfs_filblks_t temp2=0;/* value for da_new calculations */
1757 int tmp_rval; /* partial logging flags */ 1726 int tmp_rval; /* partial logging flags */
1727 struct xfs_mount *mp;
1758 1728
1729 mp = bma->tp ? bma->tp->t_mountp : NULL;
1759 ifp = XFS_IFORK_PTR(bma->ip, XFS_DATA_FORK); 1730 ifp = XFS_IFORK_PTR(bma->ip, XFS_DATA_FORK);
1760 1731
1761 ASSERT(bma->idx >= 0); 1732 ASSERT(bma->idx >= 0);
@@ -1866,15 +1837,15 @@ xfs_bmap_add_extent_delay_real(
1866 RIGHT.br_blockcount, &i); 1837 RIGHT.br_blockcount, &i);
1867 if (error) 1838 if (error)
1868 goto done; 1839 goto done;
1869 XFS_WANT_CORRUPTED_GOTO(i == 1, done); 1840 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
1870 error = xfs_btree_delete(bma->cur, &i); 1841 error = xfs_btree_delete(bma->cur, &i);
1871 if (error) 1842 if (error)
1872 goto done; 1843 goto done;
1873 XFS_WANT_CORRUPTED_GOTO(i == 1, done); 1844 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
1874 error = xfs_btree_decrement(bma->cur, 0, &i); 1845 error = xfs_btree_decrement(bma->cur, 0, &i);
1875 if (error) 1846 if (error)
1876 goto done; 1847 goto done;
1877 XFS_WANT_CORRUPTED_GOTO(i == 1, done); 1848 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
1878 error = xfs_bmbt_update(bma->cur, LEFT.br_startoff, 1849 error = xfs_bmbt_update(bma->cur, LEFT.br_startoff,
1879 LEFT.br_startblock, 1850 LEFT.br_startblock,
1880 LEFT.br_blockcount + 1851 LEFT.br_blockcount +
@@ -1907,7 +1878,7 @@ xfs_bmap_add_extent_delay_real(
1907 &i); 1878 &i);
1908 if (error) 1879 if (error)
1909 goto done; 1880 goto done;
1910 XFS_WANT_CORRUPTED_GOTO(i == 1, done); 1881 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
1911 error = xfs_bmbt_update(bma->cur, LEFT.br_startoff, 1882 error = xfs_bmbt_update(bma->cur, LEFT.br_startoff,
1912 LEFT.br_startblock, 1883 LEFT.br_startblock,
1913 LEFT.br_blockcount + 1884 LEFT.br_blockcount +
@@ -1938,7 +1909,7 @@ xfs_bmap_add_extent_delay_real(
1938 RIGHT.br_blockcount, &i); 1909 RIGHT.br_blockcount, &i);
1939 if (error) 1910 if (error)
1940 goto done; 1911 goto done;
1941 XFS_WANT_CORRUPTED_GOTO(i == 1, done); 1912 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
1942 error = xfs_bmbt_update(bma->cur, PREV.br_startoff, 1913 error = xfs_bmbt_update(bma->cur, PREV.br_startoff,
1943 new->br_startblock, 1914 new->br_startblock,
1944 PREV.br_blockcount + 1915 PREV.br_blockcount +
@@ -1968,12 +1939,12 @@ xfs_bmap_add_extent_delay_real(
1968 &i); 1939 &i);
1969 if (error) 1940 if (error)
1970 goto done; 1941 goto done;
1971 XFS_WANT_CORRUPTED_GOTO(i == 0, done); 1942 XFS_WANT_CORRUPTED_GOTO(mp, i == 0, done);
1972 bma->cur->bc_rec.b.br_state = XFS_EXT_NORM; 1943 bma->cur->bc_rec.b.br_state = XFS_EXT_NORM;
1973 error = xfs_btree_insert(bma->cur, &i); 1944 error = xfs_btree_insert(bma->cur, &i);
1974 if (error) 1945 if (error)
1975 goto done; 1946 goto done;
1976 XFS_WANT_CORRUPTED_GOTO(i == 1, done); 1947 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
1977 } 1948 }
1978 break; 1949 break;
1979 1950
@@ -2001,7 +1972,7 @@ xfs_bmap_add_extent_delay_real(
2001 &i); 1972 &i);
2002 if (error) 1973 if (error)
2003 goto done; 1974 goto done;
2004 XFS_WANT_CORRUPTED_GOTO(i == 1, done); 1975 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
2005 error = xfs_bmbt_update(bma->cur, LEFT.br_startoff, 1976 error = xfs_bmbt_update(bma->cur, LEFT.br_startoff,
2006 LEFT.br_startblock, 1977 LEFT.br_startblock,
2007 LEFT.br_blockcount + 1978 LEFT.br_blockcount +
@@ -2038,12 +2009,12 @@ xfs_bmap_add_extent_delay_real(
2038 &i); 2009 &i);
2039 if (error) 2010 if (error)
2040 goto done; 2011 goto done;
2041 XFS_WANT_CORRUPTED_GOTO(i == 0, done); 2012 XFS_WANT_CORRUPTED_GOTO(mp, i == 0, done);
2042 bma->cur->bc_rec.b.br_state = XFS_EXT_NORM; 2013 bma->cur->bc_rec.b.br_state = XFS_EXT_NORM;
2043 error = xfs_btree_insert(bma->cur, &i); 2014 error = xfs_btree_insert(bma->cur, &i);
2044 if (error) 2015 if (error)
2045 goto done; 2016 goto done;
2046 XFS_WANT_CORRUPTED_GOTO(i == 1, done); 2017 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
2047 } 2018 }
2048 2019
2049 if (xfs_bmap_needs_btree(bma->ip, XFS_DATA_FORK)) { 2020 if (xfs_bmap_needs_btree(bma->ip, XFS_DATA_FORK)) {
@@ -2084,7 +2055,7 @@ xfs_bmap_add_extent_delay_real(
2084 RIGHT.br_blockcount, &i); 2055 RIGHT.br_blockcount, &i);
2085 if (error) 2056 if (error)
2086 goto done; 2057 goto done;
2087 XFS_WANT_CORRUPTED_GOTO(i == 1, done); 2058 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
2088 error = xfs_bmbt_update(bma->cur, new->br_startoff, 2059 error = xfs_bmbt_update(bma->cur, new->br_startoff,
2089 new->br_startblock, 2060 new->br_startblock,
2090 new->br_blockcount + 2061 new->br_blockcount +
@@ -2122,12 +2093,12 @@ xfs_bmap_add_extent_delay_real(
2122 &i); 2093 &i);
2123 if (error) 2094 if (error)
2124 goto done; 2095 goto done;
2125 XFS_WANT_CORRUPTED_GOTO(i == 0, done); 2096 XFS_WANT_CORRUPTED_GOTO(mp, i == 0, done);
2126 bma->cur->bc_rec.b.br_state = XFS_EXT_NORM; 2097 bma->cur->bc_rec.b.br_state = XFS_EXT_NORM;
2127 error = xfs_btree_insert(bma->cur, &i); 2098 error = xfs_btree_insert(bma->cur, &i);
2128 if (error) 2099 if (error)
2129 goto done; 2100 goto done;
2130 XFS_WANT_CORRUPTED_GOTO(i == 1, done); 2101 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
2131 } 2102 }
2132 2103
2133 if (xfs_bmap_needs_btree(bma->ip, XFS_DATA_FORK)) { 2104 if (xfs_bmap_needs_btree(bma->ip, XFS_DATA_FORK)) {
@@ -2191,12 +2162,12 @@ xfs_bmap_add_extent_delay_real(
2191 &i); 2162 &i);
2192 if (error) 2163 if (error)
2193 goto done; 2164 goto done;
2194 XFS_WANT_CORRUPTED_GOTO(i == 0, done); 2165 XFS_WANT_CORRUPTED_GOTO(mp, i == 0, done);
2195 bma->cur->bc_rec.b.br_state = XFS_EXT_NORM; 2166 bma->cur->bc_rec.b.br_state = XFS_EXT_NORM;
2196 error = xfs_btree_insert(bma->cur, &i); 2167 error = xfs_btree_insert(bma->cur, &i);
2197 if (error) 2168 if (error)
2198 goto done; 2169 goto done;
2199 XFS_WANT_CORRUPTED_GOTO(i == 1, done); 2170 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
2200 } 2171 }
2201 2172
2202 if (xfs_bmap_needs_btree(bma->ip, XFS_DATA_FORK)) { 2173 if (xfs_bmap_needs_btree(bma->ip, XFS_DATA_FORK)) {
@@ -2212,9 +2183,8 @@ xfs_bmap_add_extent_delay_real(
2212 diff = (int)(temp + temp2 - startblockval(PREV.br_startblock) - 2183 diff = (int)(temp + temp2 - startblockval(PREV.br_startblock) -
2213 (bma->cur ? bma->cur->bc_private.b.allocated : 0)); 2184 (bma->cur ? bma->cur->bc_private.b.allocated : 0));
2214 if (diff > 0) { 2185 if (diff > 0) {
2215 error = xfs_icsb_modify_counters(bma->ip->i_mount, 2186 error = xfs_mod_fdblocks(bma->ip->i_mount,
2216 XFS_SBS_FDBLOCKS, 2187 -((int64_t)diff), false);
2217 -((int64_t)diff), 0);
2218 ASSERT(!error); 2188 ASSERT(!error);
2219 if (error) 2189 if (error)
2220 goto done; 2190 goto done;
@@ -2265,9 +2235,8 @@ xfs_bmap_add_extent_delay_real(
2265 temp += bma->cur->bc_private.b.allocated; 2235 temp += bma->cur->bc_private.b.allocated;
2266 ASSERT(temp <= da_old); 2236 ASSERT(temp <= da_old);
2267 if (temp < da_old) 2237 if (temp < da_old)
2268 xfs_icsb_modify_counters(bma->ip->i_mount, 2238 xfs_mod_fdblocks(bma->ip->i_mount,
2269 XFS_SBS_FDBLOCKS, 2239 (int64_t)(da_old - temp), false);
2270 (int64_t)(da_old - temp), 0);
2271 } 2240 }
2272 2241
2273 /* clear out the allocated field, done with it now in any case. */ 2242 /* clear out the allocated field, done with it now in any case. */
@@ -2309,6 +2278,7 @@ xfs_bmap_add_extent_unwritten_real(
2309 /* left is 0, right is 1, prev is 2 */ 2278 /* left is 0, right is 1, prev is 2 */
2310 int rval=0; /* return value (logging flags) */ 2279 int rval=0; /* return value (logging flags) */
2311 int state = 0;/* state bits, accessed thru macros */ 2280 int state = 0;/* state bits, accessed thru macros */
2281 struct xfs_mount *mp = tp->t_mountp;
2312 2282
2313 *logflagsp = 0; 2283 *logflagsp = 0;
2314 2284
@@ -2421,19 +2391,19 @@ xfs_bmap_add_extent_unwritten_real(
2421 RIGHT.br_startblock, 2391 RIGHT.br_startblock,
2422 RIGHT.br_blockcount, &i))) 2392 RIGHT.br_blockcount, &i)))
2423 goto done; 2393 goto done;
2424 XFS_WANT_CORRUPTED_GOTO(i == 1, done); 2394 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
2425 if ((error = xfs_btree_delete(cur, &i))) 2395 if ((error = xfs_btree_delete(cur, &i)))
2426 goto done; 2396 goto done;
2427 XFS_WANT_CORRUPTED_GOTO(i == 1, done); 2397 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
2428 if ((error = xfs_btree_decrement(cur, 0, &i))) 2398 if ((error = xfs_btree_decrement(cur, 0, &i)))
2429 goto done; 2399 goto done;
2430 XFS_WANT_CORRUPTED_GOTO(i == 1, done); 2400 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
2431 if ((error = xfs_btree_delete(cur, &i))) 2401 if ((error = xfs_btree_delete(cur, &i)))
2432 goto done; 2402 goto done;
2433 XFS_WANT_CORRUPTED_GOTO(i == 1, done); 2403 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
2434 if ((error = xfs_btree_decrement(cur, 0, &i))) 2404 if ((error = xfs_btree_decrement(cur, 0, &i)))
2435 goto done; 2405 goto done;
2436 XFS_WANT_CORRUPTED_GOTO(i == 1, done); 2406 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
2437 if ((error = xfs_bmbt_update(cur, LEFT.br_startoff, 2407 if ((error = xfs_bmbt_update(cur, LEFT.br_startoff,
2438 LEFT.br_startblock, 2408 LEFT.br_startblock,
2439 LEFT.br_blockcount + PREV.br_blockcount + 2409 LEFT.br_blockcount + PREV.br_blockcount +
@@ -2464,13 +2434,13 @@ xfs_bmap_add_extent_unwritten_real(
2464 PREV.br_startblock, PREV.br_blockcount, 2434 PREV.br_startblock, PREV.br_blockcount,
2465 &i))) 2435 &i)))
2466 goto done; 2436 goto done;
2467 XFS_WANT_CORRUPTED_GOTO(i == 1, done); 2437 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
2468 if ((error = xfs_btree_delete(cur, &i))) 2438 if ((error = xfs_btree_delete(cur, &i)))
2469 goto done; 2439 goto done;
2470 XFS_WANT_CORRUPTED_GOTO(i == 1, done); 2440 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
2471 if ((error = xfs_btree_decrement(cur, 0, &i))) 2441 if ((error = xfs_btree_decrement(cur, 0, &i)))
2472 goto done; 2442 goto done;
2473 XFS_WANT_CORRUPTED_GOTO(i == 1, done); 2443 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
2474 if ((error = xfs_bmbt_update(cur, LEFT.br_startoff, 2444 if ((error = xfs_bmbt_update(cur, LEFT.br_startoff,
2475 LEFT.br_startblock, 2445 LEFT.br_startblock,
2476 LEFT.br_blockcount + PREV.br_blockcount, 2446 LEFT.br_blockcount + PREV.br_blockcount,
@@ -2499,13 +2469,13 @@ xfs_bmap_add_extent_unwritten_real(
2499 RIGHT.br_startblock, 2469 RIGHT.br_startblock,
2500 RIGHT.br_blockcount, &i))) 2470 RIGHT.br_blockcount, &i)))
2501 goto done; 2471 goto done;
2502 XFS_WANT_CORRUPTED_GOTO(i == 1, done); 2472 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
2503 if ((error = xfs_btree_delete(cur, &i))) 2473 if ((error = xfs_btree_delete(cur, &i)))
2504 goto done; 2474 goto done;
2505 XFS_WANT_CORRUPTED_GOTO(i == 1, done); 2475 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
2506 if ((error = xfs_btree_decrement(cur, 0, &i))) 2476 if ((error = xfs_btree_decrement(cur, 0, &i)))
2507 goto done; 2477 goto done;
2508 XFS_WANT_CORRUPTED_GOTO(i == 1, done); 2478 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
2509 if ((error = xfs_bmbt_update(cur, new->br_startoff, 2479 if ((error = xfs_bmbt_update(cur, new->br_startoff,
2510 new->br_startblock, 2480 new->br_startblock,
2511 new->br_blockcount + RIGHT.br_blockcount, 2481 new->br_blockcount + RIGHT.br_blockcount,
@@ -2532,7 +2502,7 @@ xfs_bmap_add_extent_unwritten_real(
2532 new->br_startblock, new->br_blockcount, 2502 new->br_startblock, new->br_blockcount,
2533 &i))) 2503 &i)))
2534 goto done; 2504 goto done;
2535 XFS_WANT_CORRUPTED_GOTO(i == 1, done); 2505 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
2536 if ((error = xfs_bmbt_update(cur, new->br_startoff, 2506 if ((error = xfs_bmbt_update(cur, new->br_startoff,
2537 new->br_startblock, new->br_blockcount, 2507 new->br_startblock, new->br_blockcount,
2538 newext))) 2508 newext)))
@@ -2569,7 +2539,7 @@ xfs_bmap_add_extent_unwritten_real(
2569 PREV.br_startblock, PREV.br_blockcount, 2539 PREV.br_startblock, PREV.br_blockcount,
2570 &i))) 2540 &i)))
2571 goto done; 2541 goto done;
2572 XFS_WANT_CORRUPTED_GOTO(i == 1, done); 2542 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
2573 if ((error = xfs_bmbt_update(cur, 2543 if ((error = xfs_bmbt_update(cur,
2574 PREV.br_startoff + new->br_blockcount, 2544 PREV.br_startoff + new->br_blockcount,
2575 PREV.br_startblock + new->br_blockcount, 2545 PREV.br_startblock + new->br_blockcount,
@@ -2611,7 +2581,7 @@ xfs_bmap_add_extent_unwritten_real(
2611 PREV.br_startblock, PREV.br_blockcount, 2581 PREV.br_startblock, PREV.br_blockcount,
2612 &i))) 2582 &i)))
2613 goto done; 2583 goto done;
2614 XFS_WANT_CORRUPTED_GOTO(i == 1, done); 2584 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
2615 if ((error = xfs_bmbt_update(cur, 2585 if ((error = xfs_bmbt_update(cur,
2616 PREV.br_startoff + new->br_blockcount, 2586 PREV.br_startoff + new->br_blockcount,
2617 PREV.br_startblock + new->br_blockcount, 2587 PREV.br_startblock + new->br_blockcount,
@@ -2621,7 +2591,7 @@ xfs_bmap_add_extent_unwritten_real(
2621 cur->bc_rec.b = *new; 2591 cur->bc_rec.b = *new;
2622 if ((error = xfs_btree_insert(cur, &i))) 2592 if ((error = xfs_btree_insert(cur, &i)))
2623 goto done; 2593 goto done;
2624 XFS_WANT_CORRUPTED_GOTO(i == 1, done); 2594 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
2625 } 2595 }
2626 break; 2596 break;
2627 2597
@@ -2651,7 +2621,7 @@ xfs_bmap_add_extent_unwritten_real(
2651 PREV.br_startblock, 2621 PREV.br_startblock,
2652 PREV.br_blockcount, &i))) 2622 PREV.br_blockcount, &i)))
2653 goto done; 2623 goto done;
2654 XFS_WANT_CORRUPTED_GOTO(i == 1, done); 2624 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
2655 if ((error = xfs_bmbt_update(cur, PREV.br_startoff, 2625 if ((error = xfs_bmbt_update(cur, PREV.br_startoff,
2656 PREV.br_startblock, 2626 PREV.br_startblock,
2657 PREV.br_blockcount - new->br_blockcount, 2627 PREV.br_blockcount - new->br_blockcount,
@@ -2689,7 +2659,7 @@ xfs_bmap_add_extent_unwritten_real(
2689 PREV.br_startblock, PREV.br_blockcount, 2659 PREV.br_startblock, PREV.br_blockcount,
2690 &i))) 2660 &i)))
2691 goto done; 2661 goto done;
2692 XFS_WANT_CORRUPTED_GOTO(i == 1, done); 2662 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
2693 if ((error = xfs_bmbt_update(cur, PREV.br_startoff, 2663 if ((error = xfs_bmbt_update(cur, PREV.br_startoff,
2694 PREV.br_startblock, 2664 PREV.br_startblock,
2695 PREV.br_blockcount - new->br_blockcount, 2665 PREV.br_blockcount - new->br_blockcount,
@@ -2699,11 +2669,11 @@ xfs_bmap_add_extent_unwritten_real(
2699 new->br_startblock, new->br_blockcount, 2669 new->br_startblock, new->br_blockcount,
2700 &i))) 2670 &i)))
2701 goto done; 2671 goto done;
2702 XFS_WANT_CORRUPTED_GOTO(i == 0, done); 2672 XFS_WANT_CORRUPTED_GOTO(mp, i == 0, done);
2703 cur->bc_rec.b.br_state = XFS_EXT_NORM; 2673 cur->bc_rec.b.br_state = XFS_EXT_NORM;
2704 if ((error = xfs_btree_insert(cur, &i))) 2674 if ((error = xfs_btree_insert(cur, &i)))
2705 goto done; 2675 goto done;
2706 XFS_WANT_CORRUPTED_GOTO(i == 1, done); 2676 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
2707 } 2677 }
2708 break; 2678 break;
2709 2679
@@ -2737,7 +2707,7 @@ xfs_bmap_add_extent_unwritten_real(
2737 PREV.br_startblock, PREV.br_blockcount, 2707 PREV.br_startblock, PREV.br_blockcount,
2738 &i))) 2708 &i)))
2739 goto done; 2709 goto done;
2740 XFS_WANT_CORRUPTED_GOTO(i == 1, done); 2710 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
2741 /* new right extent - oldext */ 2711 /* new right extent - oldext */
2742 if ((error = xfs_bmbt_update(cur, r[1].br_startoff, 2712 if ((error = xfs_bmbt_update(cur, r[1].br_startoff,
2743 r[1].br_startblock, r[1].br_blockcount, 2713 r[1].br_startblock, r[1].br_blockcount,
@@ -2749,7 +2719,7 @@ xfs_bmap_add_extent_unwritten_real(
2749 new->br_startoff - PREV.br_startoff; 2719 new->br_startoff - PREV.br_startoff;
2750 if ((error = xfs_btree_insert(cur, &i))) 2720 if ((error = xfs_btree_insert(cur, &i)))
2751 goto done; 2721 goto done;
2752 XFS_WANT_CORRUPTED_GOTO(i == 1, done); 2722 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
2753 /* 2723 /*
2754 * Reset the cursor to the position of the new extent 2724 * Reset the cursor to the position of the new extent
2755 * we are about to insert as we can't trust it after 2725 * we are about to insert as we can't trust it after
@@ -2759,12 +2729,12 @@ xfs_bmap_add_extent_unwritten_real(
2759 new->br_startblock, new->br_blockcount, 2729 new->br_startblock, new->br_blockcount,
2760 &i))) 2730 &i)))
2761 goto done; 2731 goto done;
2762 XFS_WANT_CORRUPTED_GOTO(i == 0, done); 2732 XFS_WANT_CORRUPTED_GOTO(mp, i == 0, done);
2763 /* new middle extent - newext */ 2733 /* new middle extent - newext */
2764 cur->bc_rec.b.br_state = new->br_state; 2734 cur->bc_rec.b.br_state = new->br_state;
2765 if ((error = xfs_btree_insert(cur, &i))) 2735 if ((error = xfs_btree_insert(cur, &i)))
2766 goto done; 2736 goto done;
2767 XFS_WANT_CORRUPTED_GOTO(i == 1, done); 2737 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
2768 } 2738 }
2769 break; 2739 break;
2770 2740
@@ -2944,8 +2914,8 @@ xfs_bmap_add_extent_hole_delay(
2944 } 2914 }
2945 if (oldlen != newlen) { 2915 if (oldlen != newlen) {
2946 ASSERT(oldlen > newlen); 2916 ASSERT(oldlen > newlen);
2947 xfs_icsb_modify_counters(ip->i_mount, XFS_SBS_FDBLOCKS, 2917 xfs_mod_fdblocks(ip->i_mount, (int64_t)(oldlen - newlen),
2948 (int64_t)(oldlen - newlen), 0); 2918 false);
2949 /* 2919 /*
2950 * Nothing to do for disk quota accounting here. 2920 * Nothing to do for disk quota accounting here.
2951 */ 2921 */
@@ -2968,7 +2938,9 @@ xfs_bmap_add_extent_hole_real(
2968 xfs_bmbt_irec_t right; /* right neighbor extent entry */ 2938 xfs_bmbt_irec_t right; /* right neighbor extent entry */
2969 int rval=0; /* return value (logging flags) */ 2939 int rval=0; /* return value (logging flags) */
2970 int state; /* state bits, accessed thru macros */ 2940 int state; /* state bits, accessed thru macros */
2941 struct xfs_mount *mp;
2971 2942
2943 mp = bma->tp ? bma->tp->t_mountp : NULL;
2972 ifp = XFS_IFORK_PTR(bma->ip, whichfork); 2944 ifp = XFS_IFORK_PTR(bma->ip, whichfork);
2973 2945
2974 ASSERT(bma->idx >= 0); 2946 ASSERT(bma->idx >= 0);
@@ -3056,15 +3028,15 @@ xfs_bmap_add_extent_hole_real(
3056 &i); 3028 &i);
3057 if (error) 3029 if (error)
3058 goto done; 3030 goto done;
3059 XFS_WANT_CORRUPTED_GOTO(i == 1, done); 3031 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
3060 error = xfs_btree_delete(bma->cur, &i); 3032 error = xfs_btree_delete(bma->cur, &i);
3061 if (error) 3033 if (error)
3062 goto done; 3034 goto done;
3063 XFS_WANT_CORRUPTED_GOTO(i == 1, done); 3035 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
3064 error = xfs_btree_decrement(bma->cur, 0, &i); 3036 error = xfs_btree_decrement(bma->cur, 0, &i);
3065 if (error) 3037 if (error)
3066 goto done; 3038 goto done;
3067 XFS_WANT_CORRUPTED_GOTO(i == 1, done); 3039 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
3068 error = xfs_bmbt_update(bma->cur, left.br_startoff, 3040 error = xfs_bmbt_update(bma->cur, left.br_startoff,
3069 left.br_startblock, 3041 left.br_startblock,
3070 left.br_blockcount + 3042 left.br_blockcount +
@@ -3097,7 +3069,7 @@ xfs_bmap_add_extent_hole_real(
3097 &i); 3069 &i);
3098 if (error) 3070 if (error)
3099 goto done; 3071 goto done;
3100 XFS_WANT_CORRUPTED_GOTO(i == 1, done); 3072 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
3101 error = xfs_bmbt_update(bma->cur, left.br_startoff, 3073 error = xfs_bmbt_update(bma->cur, left.br_startoff,
3102 left.br_startblock, 3074 left.br_startblock,
3103 left.br_blockcount + 3075 left.br_blockcount +
@@ -3131,7 +3103,7 @@ xfs_bmap_add_extent_hole_real(
3131 right.br_blockcount, &i); 3103 right.br_blockcount, &i);
3132 if (error) 3104 if (error)
3133 goto done; 3105 goto done;
3134 XFS_WANT_CORRUPTED_GOTO(i == 1, done); 3106 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
3135 error = xfs_bmbt_update(bma->cur, new->br_startoff, 3107 error = xfs_bmbt_update(bma->cur, new->br_startoff,
3136 new->br_startblock, 3108 new->br_startblock,
3137 new->br_blockcount + 3109 new->br_blockcount +
@@ -3161,12 +3133,12 @@ xfs_bmap_add_extent_hole_real(
3161 new->br_blockcount, &i); 3133 new->br_blockcount, &i);
3162 if (error) 3134 if (error)
3163 goto done; 3135 goto done;
3164 XFS_WANT_CORRUPTED_GOTO(i == 0, done); 3136 XFS_WANT_CORRUPTED_GOTO(mp, i == 0, done);
3165 bma->cur->bc_rec.b.br_state = new->br_state; 3137 bma->cur->bc_rec.b.br_state = new->br_state;
3166 error = xfs_btree_insert(bma->cur, &i); 3138 error = xfs_btree_insert(bma->cur, &i);
3167 if (error) 3139 if (error)
3168 goto done; 3140 goto done;
3169 XFS_WANT_CORRUPTED_GOTO(i == 1, done); 3141 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
3170 } 3142 }
3171 break; 3143 break;
3172 } 3144 }
@@ -4160,18 +4132,15 @@ xfs_bmapi_reserve_delalloc(
4160 ASSERT(indlen > 0); 4132 ASSERT(indlen > 0);
4161 4133
4162 if (rt) { 4134 if (rt) {
4163 error = xfs_mod_incore_sb(mp, XFS_SBS_FREXTENTS, 4135 error = xfs_mod_frextents(mp, -((int64_t)extsz));
4164 -((int64_t)extsz), 0);
4165 } else { 4136 } else {
4166 error = xfs_icsb_modify_counters(mp, XFS_SBS_FDBLOCKS, 4137 error = xfs_mod_fdblocks(mp, -((int64_t)alen), false);
4167 -((int64_t)alen), 0);
4168 } 4138 }
4169 4139
4170 if (error) 4140 if (error)
4171 goto out_unreserve_quota; 4141 goto out_unreserve_quota;
4172 4142
4173 error = xfs_icsb_modify_counters(mp, XFS_SBS_FDBLOCKS, 4143 error = xfs_mod_fdblocks(mp, -((int64_t)indlen), false);
4174 -((int64_t)indlen), 0);
4175 if (error) 4144 if (error)
4176 goto out_unreserve_blocks; 4145 goto out_unreserve_blocks;
4177 4146
@@ -4198,9 +4167,9 @@ xfs_bmapi_reserve_delalloc(
4198 4167
4199out_unreserve_blocks: 4168out_unreserve_blocks:
4200 if (rt) 4169 if (rt)
4201 xfs_mod_incore_sb(mp, XFS_SBS_FREXTENTS, extsz, 0); 4170 xfs_mod_frextents(mp, extsz);
4202 else 4171 else
4203 xfs_icsb_modify_counters(mp, XFS_SBS_FDBLOCKS, alen, 0); 4172 xfs_mod_fdblocks(mp, alen, false);
4204out_unreserve_quota: 4173out_unreserve_quota:
4205 if (XFS_IS_QUOTA_ON(mp)) 4174 if (XFS_IS_QUOTA_ON(mp))
4206 xfs_trans_unreserve_quota_nblks(NULL, ip, (long)alen, 0, rt ? 4175 xfs_trans_unreserve_quota_nblks(NULL, ip, (long)alen, 0, rt ?
@@ -4801,7 +4770,7 @@ xfs_bmap_del_extent(
4801 got.br_startblock, got.br_blockcount, 4770 got.br_startblock, got.br_blockcount,
4802 &i))) 4771 &i)))
4803 goto done; 4772 goto done;
4804 XFS_WANT_CORRUPTED_GOTO(i == 1, done); 4773 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
4805 } 4774 }
4806 da_old = da_new = 0; 4775 da_old = da_new = 0;
4807 } else { 4776 } else {
@@ -4835,7 +4804,7 @@ xfs_bmap_del_extent(
4835 } 4804 }
4836 if ((error = xfs_btree_delete(cur, &i))) 4805 if ((error = xfs_btree_delete(cur, &i)))
4837 goto done; 4806 goto done;
4838 XFS_WANT_CORRUPTED_GOTO(i == 1, done); 4807 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
4839 break; 4808 break;
4840 4809
4841 case 2: 4810 case 2:
@@ -4935,7 +4904,8 @@ xfs_bmap_del_extent(
4935 got.br_startblock, 4904 got.br_startblock,
4936 temp, &i))) 4905 temp, &i)))
4937 goto done; 4906 goto done;
4938 XFS_WANT_CORRUPTED_GOTO(i == 1, done); 4907 XFS_WANT_CORRUPTED_GOTO(mp,
4908 i == 1, done);
4939 /* 4909 /*
4940 * Update the btree record back 4910 * Update the btree record back
4941 * to the original value. 4911 * to the original value.
@@ -4956,7 +4926,7 @@ xfs_bmap_del_extent(
4956 error = -ENOSPC; 4926 error = -ENOSPC;
4957 goto done; 4927 goto done;
4958 } 4928 }
4959 XFS_WANT_CORRUPTED_GOTO(i == 1, done); 4929 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
4960 } else 4930 } else
4961 flags |= xfs_ilog_fext(whichfork); 4931 flags |= xfs_ilog_fext(whichfork);
4962 XFS_IFORK_NEXT_SET(ip, whichfork, 4932 XFS_IFORK_NEXT_SET(ip, whichfork,
@@ -5012,10 +4982,8 @@ xfs_bmap_del_extent(
5012 * Nothing to do for disk quota accounting here. 4982 * Nothing to do for disk quota accounting here.
5013 */ 4983 */
5014 ASSERT(da_old >= da_new); 4984 ASSERT(da_old >= da_new);
5015 if (da_old > da_new) { 4985 if (da_old > da_new)
5016 xfs_icsb_modify_counters(mp, XFS_SBS_FDBLOCKS, 4986 xfs_mod_fdblocks(mp, (int64_t)(da_old - da_new), false);
5017 (int64_t)(da_old - da_new), 0);
5018 }
5019done: 4987done:
5020 *logflagsp = flags; 4988 *logflagsp = flags;
5021 return error; 4989 return error;
@@ -5284,14 +5252,13 @@ xfs_bunmapi(
5284 5252
5285 rtexts = XFS_FSB_TO_B(mp, del.br_blockcount); 5253 rtexts = XFS_FSB_TO_B(mp, del.br_blockcount);
5286 do_div(rtexts, mp->m_sb.sb_rextsize); 5254 do_div(rtexts, mp->m_sb.sb_rextsize);
5287 xfs_mod_incore_sb(mp, XFS_SBS_FREXTENTS, 5255 xfs_mod_frextents(mp, (int64_t)rtexts);
5288 (int64_t)rtexts, 0);
5289 (void)xfs_trans_reserve_quota_nblks(NULL, 5256 (void)xfs_trans_reserve_quota_nblks(NULL,
5290 ip, -((long)del.br_blockcount), 0, 5257 ip, -((long)del.br_blockcount), 0,
5291 XFS_QMOPT_RES_RTBLKS); 5258 XFS_QMOPT_RES_RTBLKS);
5292 } else { 5259 } else {
5293 xfs_icsb_modify_counters(mp, XFS_SBS_FDBLOCKS, 5260 xfs_mod_fdblocks(mp, (int64_t)del.br_blockcount,
5294 (int64_t)del.br_blockcount, 0); 5261 false);
5295 (void)xfs_trans_reserve_quota_nblks(NULL, 5262 (void)xfs_trans_reserve_quota_nblks(NULL,
5296 ip, -((long)del.br_blockcount), 0, 5263 ip, -((long)del.br_blockcount), 0,
5297 XFS_QMOPT_RES_REGBLKS); 5264 XFS_QMOPT_RES_REGBLKS);
@@ -5453,6 +5420,7 @@ xfs_bmse_merge(
5453 struct xfs_bmbt_irec left; 5420 struct xfs_bmbt_irec left;
5454 xfs_filblks_t blockcount; 5421 xfs_filblks_t blockcount;
5455 int error, i; 5422 int error, i;
5423 struct xfs_mount *mp = ip->i_mount;
5456 5424
5457 xfs_bmbt_get_all(gotp, &got); 5425 xfs_bmbt_get_all(gotp, &got);
5458 xfs_bmbt_get_all(leftp, &left); 5426 xfs_bmbt_get_all(leftp, &left);
@@ -5487,19 +5455,19 @@ xfs_bmse_merge(
5487 got.br_blockcount, &i); 5455 got.br_blockcount, &i);
5488 if (error) 5456 if (error)
5489 return error; 5457 return error;
5490 XFS_WANT_CORRUPTED_RETURN(i == 1); 5458 XFS_WANT_CORRUPTED_RETURN(mp, i == 1);
5491 5459
5492 error = xfs_btree_delete(cur, &i); 5460 error = xfs_btree_delete(cur, &i);
5493 if (error) 5461 if (error)
5494 return error; 5462 return error;
5495 XFS_WANT_CORRUPTED_RETURN(i == 1); 5463 XFS_WANT_CORRUPTED_RETURN(mp, i == 1);
5496 5464
5497 /* lookup and update size of the previous extent */ 5465 /* lookup and update size of the previous extent */
5498 error = xfs_bmbt_lookup_eq(cur, left.br_startoff, left.br_startblock, 5466 error = xfs_bmbt_lookup_eq(cur, left.br_startoff, left.br_startblock,
5499 left.br_blockcount, &i); 5467 left.br_blockcount, &i);
5500 if (error) 5468 if (error)
5501 return error; 5469 return error;
5502 XFS_WANT_CORRUPTED_RETURN(i == 1); 5470 XFS_WANT_CORRUPTED_RETURN(mp, i == 1);
5503 5471
5504 left.br_blockcount = blockcount; 5472 left.br_blockcount = blockcount;
5505 5473
@@ -5518,50 +5486,92 @@ xfs_bmse_shift_one(
5518 int *current_ext, 5486 int *current_ext,
5519 struct xfs_bmbt_rec_host *gotp, 5487 struct xfs_bmbt_rec_host *gotp,
5520 struct xfs_btree_cur *cur, 5488 struct xfs_btree_cur *cur,
5521 int *logflags) 5489 int *logflags,
5490 enum shift_direction direction)
5522{ 5491{
5523 struct xfs_ifork *ifp; 5492 struct xfs_ifork *ifp;
5493 struct xfs_mount *mp;
5524 xfs_fileoff_t startoff; 5494 xfs_fileoff_t startoff;
5525 struct xfs_bmbt_rec_host *leftp; 5495 struct xfs_bmbt_rec_host *adj_irecp;
5526 struct xfs_bmbt_irec got; 5496 struct xfs_bmbt_irec got;
5527 struct xfs_bmbt_irec left; 5497 struct xfs_bmbt_irec adj_irec;
5528 int error; 5498 int error;
5529 int i; 5499 int i;
5500 int total_extents;
5530 5501
5502 mp = ip->i_mount;
5531 ifp = XFS_IFORK_PTR(ip, whichfork); 5503 ifp = XFS_IFORK_PTR(ip, whichfork);
5504 total_extents = ifp->if_bytes / sizeof(xfs_bmbt_rec_t);
5532 5505
5533 xfs_bmbt_get_all(gotp, &got); 5506 xfs_bmbt_get_all(gotp, &got);
5534 startoff = got.br_startoff - offset_shift_fsb;
5535 5507
5536 /* delalloc extents should be prevented by caller */ 5508 /* delalloc extents should be prevented by caller */
5537 XFS_WANT_CORRUPTED_RETURN(!isnullstartblock(got.br_startblock)); 5509 XFS_WANT_CORRUPTED_RETURN(mp, !isnullstartblock(got.br_startblock));
5538 5510
5539 /* 5511 if (direction == SHIFT_LEFT) {
5540 * Check for merge if we've got an extent to the left, otherwise make 5512 startoff = got.br_startoff - offset_shift_fsb;
5541 * sure there's enough room at the start of the file for the shift. 5513
5542 */ 5514 /*
5543 if (*current_ext) { 5515 * Check for merge if we've got an extent to the left,
5544 /* grab the left extent and check for a large enough hole */ 5516 * otherwise make sure there's enough room at the start
5545 leftp = xfs_iext_get_ext(ifp, *current_ext - 1); 5517 * of the file for the shift.
5546 xfs_bmbt_get_all(leftp, &left); 5518 */
5519 if (!*current_ext) {
5520 if (got.br_startoff < offset_shift_fsb)
5521 return -EINVAL;
5522 goto update_current_ext;
5523 }
5524 /*
5525 * grab the left extent and check for a large
5526 * enough hole.
5527 */
5528 adj_irecp = xfs_iext_get_ext(ifp, *current_ext - 1);
5529 xfs_bmbt_get_all(adj_irecp, &adj_irec);
5547 5530
5548 if (startoff < left.br_startoff + left.br_blockcount) 5531 if (startoff <
5532 adj_irec.br_startoff + adj_irec.br_blockcount)
5549 return -EINVAL; 5533 return -EINVAL;
5550 5534
5551 /* check whether to merge the extent or shift it down */ 5535 /* check whether to merge the extent or shift it down */
5552 if (xfs_bmse_can_merge(&left, &got, offset_shift_fsb)) { 5536 if (xfs_bmse_can_merge(&adj_irec, &got,
5537 offset_shift_fsb)) {
5553 return xfs_bmse_merge(ip, whichfork, offset_shift_fsb, 5538 return xfs_bmse_merge(ip, whichfork, offset_shift_fsb,
5554 *current_ext, gotp, leftp, cur, 5539 *current_ext, gotp, adj_irecp,
5555 logflags); 5540 cur, logflags);
5556 } 5541 }
5557 } else if (got.br_startoff < offset_shift_fsb) 5542 } else {
5558 return -EINVAL; 5543 startoff = got.br_startoff + offset_shift_fsb;
5559 5544 /* nothing to move if this is the last extent */
5545 if (*current_ext >= (total_extents - 1))
5546 goto update_current_ext;
5547 /*
5548 * If this is not the last extent in the file, make sure there
5549 * is enough room between current extent and next extent for
5550 * accommodating the shift.
5551 */
5552 adj_irecp = xfs_iext_get_ext(ifp, *current_ext + 1);
5553 xfs_bmbt_get_all(adj_irecp, &adj_irec);
5554 if (startoff + got.br_blockcount > adj_irec.br_startoff)
5555 return -EINVAL;
5556 /*
5557 * Unlike a left shift (which involves a hole punch),
5558 * a right shift does not modify extent neighbors
5559 * in any way. We should never find mergeable extents
5560 * in this scenario. Check anyways and warn if we
5561 * encounter two extents that could be one.
5562 */
5563 if (xfs_bmse_can_merge(&got, &adj_irec, offset_shift_fsb))
5564 WARN_ON_ONCE(1);
5565 }
5560 /* 5566 /*
5561 * Increment the extent index for the next iteration, update the start 5567 * Increment the extent index for the next iteration, update the start
5562 * offset of the in-core extent and update the btree if applicable. 5568 * offset of the in-core extent and update the btree if applicable.
5563 */ 5569 */
5564 (*current_ext)++; 5570update_current_ext:
5571 if (direction == SHIFT_LEFT)
5572 (*current_ext)++;
5573 else
5574 (*current_ext)--;
5565 xfs_bmbt_set_startoff(gotp, startoff); 5575 xfs_bmbt_set_startoff(gotp, startoff);
5566 *logflags |= XFS_ILOG_CORE; 5576 *logflags |= XFS_ILOG_CORE;
5567 if (!cur) { 5577 if (!cur) {
@@ -5573,18 +5583,18 @@ xfs_bmse_shift_one(
5573 got.br_blockcount, &i); 5583 got.br_blockcount, &i);
5574 if (error) 5584 if (error)
5575 return error; 5585 return error;
5576 XFS_WANT_CORRUPTED_RETURN(i == 1); 5586 XFS_WANT_CORRUPTED_RETURN(mp, i == 1);
5577 5587
5578 got.br_startoff = startoff; 5588 got.br_startoff = startoff;
5579 return xfs_bmbt_update(cur, got.br_startoff, got.br_startblock, 5589 return xfs_bmbt_update(cur, got.br_startoff, got.br_startblock,
5580 got.br_blockcount, got.br_state); 5590 got.br_blockcount, got.br_state);
5581} 5591}
5582 5592
5583/* 5593/*
5584 * Shift extent records to the left to cover a hole. 5594 * Shift extent records to the left/right to cover/create a hole.
5585 * 5595 *
5586 * The maximum number of extents to be shifted in a single operation is 5596 * The maximum number of extents to be shifted in a single operation is
5587 * @num_exts. @start_fsb specifies the file offset to start the shift and the 5597 * @num_exts. @stop_fsb specifies the file offset at which to stop shift and the
5588 * file offset where we've left off is returned in @next_fsb. @offset_shift_fsb 5598 * file offset where we've left off is returned in @next_fsb. @offset_shift_fsb
5589 * is the length by which each extent is shifted. If there is no hole to shift 5599 * is the length by which each extent is shifted. If there is no hole to shift
5590 * the extents into, this will be considered invalid operation and we abort 5600 * the extents into, this will be considered invalid operation and we abort
@@ -5594,12 +5604,13 @@ int
5594xfs_bmap_shift_extents( 5604xfs_bmap_shift_extents(
5595 struct xfs_trans *tp, 5605 struct xfs_trans *tp,
5596 struct xfs_inode *ip, 5606 struct xfs_inode *ip,
5597 xfs_fileoff_t start_fsb, 5607 xfs_fileoff_t *next_fsb,
5598 xfs_fileoff_t offset_shift_fsb, 5608 xfs_fileoff_t offset_shift_fsb,
5599 int *done, 5609 int *done,
5600 xfs_fileoff_t *next_fsb, 5610 xfs_fileoff_t stop_fsb,
5601 xfs_fsblock_t *firstblock, 5611 xfs_fsblock_t *firstblock,
5602 struct xfs_bmap_free *flist, 5612 struct xfs_bmap_free *flist,
5613 enum shift_direction direction,
5603 int num_exts) 5614 int num_exts)
5604{ 5615{
5605 struct xfs_btree_cur *cur = NULL; 5616 struct xfs_btree_cur *cur = NULL;
@@ -5609,10 +5620,11 @@ xfs_bmap_shift_extents(
5609 struct xfs_ifork *ifp; 5620 struct xfs_ifork *ifp;
5610 xfs_extnum_t nexts = 0; 5621 xfs_extnum_t nexts = 0;
5611 xfs_extnum_t current_ext; 5622 xfs_extnum_t current_ext;
5623 xfs_extnum_t total_extents;
5624 xfs_extnum_t stop_extent;
5612 int error = 0; 5625 int error = 0;
5613 int whichfork = XFS_DATA_FORK; 5626 int whichfork = XFS_DATA_FORK;
5614 int logflags = 0; 5627 int logflags = 0;
5615 int total_extents;
5616 5628
5617 if (unlikely(XFS_TEST_ERROR( 5629 if (unlikely(XFS_TEST_ERROR(
5618 (XFS_IFORK_FORMAT(ip, whichfork) != XFS_DINODE_FMT_EXTENTS && 5630 (XFS_IFORK_FORMAT(ip, whichfork) != XFS_DINODE_FMT_EXTENTS &&
@@ -5628,6 +5640,8 @@ xfs_bmap_shift_extents(
5628 5640
5629 ASSERT(xfs_isilocked(ip, XFS_IOLOCK_EXCL)); 5641 ASSERT(xfs_isilocked(ip, XFS_IOLOCK_EXCL));
5630 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL)); 5642 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
5643 ASSERT(direction == SHIFT_LEFT || direction == SHIFT_RIGHT);
5644 ASSERT(*next_fsb != NULLFSBLOCK || direction == SHIFT_RIGHT);
5631 5645
5632 ifp = XFS_IFORK_PTR(ip, whichfork); 5646 ifp = XFS_IFORK_PTR(ip, whichfork);
5633 if (!(ifp->if_flags & XFS_IFEXTENTS)) { 5647 if (!(ifp->if_flags & XFS_IFEXTENTS)) {
@@ -5645,43 +5659,83 @@ xfs_bmap_shift_extents(
5645 } 5659 }
5646 5660
5647 /* 5661 /*
5662 * There may be delalloc extents in the data fork before the range we
5663 * are collapsing out, so we cannot use the count of real extents here.
5664 * Instead we have to calculate it from the incore fork.
5665 */
5666 total_extents = ifp->if_bytes / sizeof(xfs_bmbt_rec_t);
5667 if (total_extents == 0) {
5668 *done = 1;
5669 goto del_cursor;
5670 }
5671
5672 /*
5673 * In case of first right shift, we need to initialize next_fsb
5674 */
5675 if (*next_fsb == NULLFSBLOCK) {
5676 gotp = xfs_iext_get_ext(ifp, total_extents - 1);
5677 xfs_bmbt_get_all(gotp, &got);
5678 *next_fsb = got.br_startoff;
5679 if (stop_fsb > *next_fsb) {
5680 *done = 1;
5681 goto del_cursor;
5682 }
5683 }
5684
5685 /* Lookup the extent index at which we have to stop */
5686 if (direction == SHIFT_RIGHT) {
5687 gotp = xfs_iext_bno_to_ext(ifp, stop_fsb, &stop_extent);
5688 /* Make stop_extent exclusive of shift range */
5689 stop_extent--;
5690 } else
5691 stop_extent = total_extents;
5692
5693 /*
5648 * Look up the extent index for the fsb where we start shifting. We can 5694 * Look up the extent index for the fsb where we start shifting. We can
5649 * henceforth iterate with current_ext as extent list changes are locked 5695 * henceforth iterate with current_ext as extent list changes are locked
5650 * out via ilock. 5696 * out via ilock.
5651 * 5697 *
5652 * gotp can be null in 2 cases: 1) if there are no extents or 2) 5698 * gotp can be null in 2 cases: 1) if there are no extents or 2)
5653 * start_fsb lies in a hole beyond which there are no extents. Either 5699 * *next_fsb lies in a hole beyond which there are no extents. Either
5654 * way, we are done. 5700 * way, we are done.
5655 */ 5701 */
5656 gotp = xfs_iext_bno_to_ext(ifp, start_fsb, &current_ext); 5702 gotp = xfs_iext_bno_to_ext(ifp, *next_fsb, &current_ext);
5657 if (!gotp) { 5703 if (!gotp) {
5658 *done = 1; 5704 *done = 1;
5659 goto del_cursor; 5705 goto del_cursor;
5660 } 5706 }
5661 5707
5662 /* 5708 /* some sanity checking before we finally start shifting extents */
5663 * There may be delalloc extents in the data fork before the range we 5709 if ((direction == SHIFT_LEFT && current_ext >= stop_extent) ||
5664 * are collapsing out, so we cannot use the count of real extents here. 5710 (direction == SHIFT_RIGHT && current_ext <= stop_extent)) {
5665 * Instead we have to calculate it from the incore fork. 5711 error = -EIO;
5666 */ 5712 goto del_cursor;
5667 total_extents = ifp->if_bytes / sizeof(xfs_bmbt_rec_t); 5713 }
5668 while (nexts++ < num_exts && current_ext < total_extents) { 5714
5715 while (nexts++ < num_exts) {
5669 error = xfs_bmse_shift_one(ip, whichfork, offset_shift_fsb, 5716 error = xfs_bmse_shift_one(ip, whichfork, offset_shift_fsb,
5670 &current_ext, gotp, cur, &logflags); 5717 &current_ext, gotp, cur, &logflags,
5718 direction);
5671 if (error) 5719 if (error)
5672 goto del_cursor; 5720 goto del_cursor;
5721 /*
5722 * If there was an extent merge during the shift, the extent
5723 * count can change. Update the total and grade the next record.
5724 */
5725 if (direction == SHIFT_LEFT) {
5726 total_extents = ifp->if_bytes / sizeof(xfs_bmbt_rec_t);
5727 stop_extent = total_extents;
5728 }
5673 5729
5674 /* update total extent count and grab the next record */ 5730 if (current_ext == stop_extent) {
5675 total_extents = ifp->if_bytes / sizeof(xfs_bmbt_rec_t); 5731 *done = 1;
5676 if (current_ext >= total_extents) 5732 *next_fsb = NULLFSBLOCK;
5677 break; 5733 break;
5734 }
5678 gotp = xfs_iext_get_ext(ifp, current_ext); 5735 gotp = xfs_iext_get_ext(ifp, current_ext);
5679 } 5736 }
5680 5737
5681 /* Check if we are done */ 5738 if (!*done) {
5682 if (current_ext == total_extents) {
5683 *done = 1;
5684 } else if (next_fsb) {
5685 xfs_bmbt_get_all(gotp, &got); 5739 xfs_bmbt_get_all(gotp, &got);
5686 *next_fsb = got.br_startoff; 5740 *next_fsb = got.br_startoff;
5687 } 5741 }
@@ -5696,3 +5750,189 @@ del_cursor:
5696 5750
5697 return error; 5751 return error;
5698} 5752}
5753
5754/*
5755 * Splits an extent into two extents at split_fsb block such that it is
5756 * the first block of the current_ext. @current_ext is a target extent
5757 * to be split. @split_fsb is a block where the extents is split.
5758 * If split_fsb lies in a hole or the first block of extents, just return 0.
5759 */
5760STATIC int
5761xfs_bmap_split_extent_at(
5762 struct xfs_trans *tp,
5763 struct xfs_inode *ip,
5764 xfs_fileoff_t split_fsb,
5765 xfs_fsblock_t *firstfsb,
5766 struct xfs_bmap_free *free_list)
5767{
5768 int whichfork = XFS_DATA_FORK;
5769 struct xfs_btree_cur *cur = NULL;
5770 struct xfs_bmbt_rec_host *gotp;
5771 struct xfs_bmbt_irec got;
5772 struct xfs_bmbt_irec new; /* split extent */
5773 struct xfs_mount *mp = ip->i_mount;
5774 struct xfs_ifork *ifp;
5775 xfs_fsblock_t gotblkcnt; /* new block count for got */
5776 xfs_extnum_t current_ext;
5777 int error = 0;
5778 int logflags = 0;
5779 int i = 0;
5780
5781 if (unlikely(XFS_TEST_ERROR(
5782 (XFS_IFORK_FORMAT(ip, whichfork) != XFS_DINODE_FMT_EXTENTS &&
5783 XFS_IFORK_FORMAT(ip, whichfork) != XFS_DINODE_FMT_BTREE),
5784 mp, XFS_ERRTAG_BMAPIFORMAT, XFS_RANDOM_BMAPIFORMAT))) {
5785 XFS_ERROR_REPORT("xfs_bmap_split_extent_at",
5786 XFS_ERRLEVEL_LOW, mp);
5787 return -EFSCORRUPTED;
5788 }
5789
5790 if (XFS_FORCED_SHUTDOWN(mp))
5791 return -EIO;
5792
5793 ifp = XFS_IFORK_PTR(ip, whichfork);
5794 if (!(ifp->if_flags & XFS_IFEXTENTS)) {
5795 /* Read in all the extents */
5796 error = xfs_iread_extents(tp, ip, whichfork);
5797 if (error)
5798 return error;
5799 }
5800
5801 /*
5802 * gotp can be null in 2 cases: 1) if there are no extents
5803 * or 2) split_fsb lies in a hole beyond which there are
5804 * no extents. Either way, we are done.
5805 */
5806 gotp = xfs_iext_bno_to_ext(ifp, split_fsb, &current_ext);
5807 if (!gotp)
5808 return 0;
5809
5810 xfs_bmbt_get_all(gotp, &got);
5811
5812 /*
5813 * Check split_fsb lies in a hole or the start boundary offset
5814 * of the extent.
5815 */
5816 if (got.br_startoff >= split_fsb)
5817 return 0;
5818
5819 gotblkcnt = split_fsb - got.br_startoff;
5820 new.br_startoff = split_fsb;
5821 new.br_startblock = got.br_startblock + gotblkcnt;
5822 new.br_blockcount = got.br_blockcount - gotblkcnt;
5823 new.br_state = got.br_state;
5824
5825 if (ifp->if_flags & XFS_IFBROOT) {
5826 cur = xfs_bmbt_init_cursor(mp, tp, ip, whichfork);
5827 cur->bc_private.b.firstblock = *firstfsb;
5828 cur->bc_private.b.flist = free_list;
5829 cur->bc_private.b.flags = 0;
5830 error = xfs_bmbt_lookup_eq(cur, got.br_startoff,
5831 got.br_startblock,
5832 got.br_blockcount,
5833 &i);
5834 if (error)
5835 goto del_cursor;
5836 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, del_cursor);
5837 }
5838
5839 xfs_bmbt_set_blockcount(gotp, gotblkcnt);
5840 got.br_blockcount = gotblkcnt;
5841
5842 logflags = XFS_ILOG_CORE;
5843 if (cur) {
5844 error = xfs_bmbt_update(cur, got.br_startoff,
5845 got.br_startblock,
5846 got.br_blockcount,
5847 got.br_state);
5848 if (error)
5849 goto del_cursor;
5850 } else
5851 logflags |= XFS_ILOG_DEXT;
5852
5853 /* Add new extent */
5854 current_ext++;
5855 xfs_iext_insert(ip, current_ext, 1, &new, 0);
5856 XFS_IFORK_NEXT_SET(ip, whichfork,
5857 XFS_IFORK_NEXTENTS(ip, whichfork) + 1);
5858
5859 if (cur) {
5860 error = xfs_bmbt_lookup_eq(cur, new.br_startoff,
5861 new.br_startblock, new.br_blockcount,
5862 &i);
5863 if (error)
5864 goto del_cursor;
5865 XFS_WANT_CORRUPTED_GOTO(mp, i == 0, del_cursor);
5866 cur->bc_rec.b.br_state = new.br_state;
5867
5868 error = xfs_btree_insert(cur, &i);
5869 if (error)
5870 goto del_cursor;
5871 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, del_cursor);
5872 }
5873
5874 /*
5875 * Convert to a btree if necessary.
5876 */
5877 if (xfs_bmap_needs_btree(ip, whichfork)) {
5878 int tmp_logflags; /* partial log flag return val */
5879
5880 ASSERT(cur == NULL);
5881 error = xfs_bmap_extents_to_btree(tp, ip, firstfsb, free_list,
5882 &cur, 0, &tmp_logflags, whichfork);
5883 logflags |= tmp_logflags;
5884 }
5885
5886del_cursor:
5887 if (cur) {
5888 cur->bc_private.b.allocated = 0;
5889 xfs_btree_del_cursor(cur,
5890 error ? XFS_BTREE_ERROR : XFS_BTREE_NOERROR);
5891 }
5892
5893 if (logflags)
5894 xfs_trans_log_inode(tp, ip, logflags);
5895 return error;
5896}
5897
5898int
5899xfs_bmap_split_extent(
5900 struct xfs_inode *ip,
5901 xfs_fileoff_t split_fsb)
5902{
5903 struct xfs_mount *mp = ip->i_mount;
5904 struct xfs_trans *tp;
5905 struct xfs_bmap_free free_list;
5906 xfs_fsblock_t firstfsb;
5907 int committed;
5908 int error;
5909
5910 tp = xfs_trans_alloc(mp, XFS_TRANS_DIOSTRAT);
5911 error = xfs_trans_reserve(tp, &M_RES(mp)->tr_write,
5912 XFS_DIOSTRAT_SPACE_RES(mp, 0), 0);
5913 if (error) {
5914 xfs_trans_cancel(tp, 0);
5915 return error;
5916 }
5917
5918 xfs_ilock(ip, XFS_ILOCK_EXCL);
5919 xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
5920
5921 xfs_bmap_init(&free_list, &firstfsb);
5922
5923 error = xfs_bmap_split_extent_at(tp, ip, split_fsb,
5924 &firstfsb, &free_list);
5925 if (error)
5926 goto out;
5927
5928 error = xfs_bmap_finish(&tp, &free_list, &committed);
5929 if (error)
5930 goto out;
5931
5932 return xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES);
5933
5934
5935out:
5936 xfs_trans_cancel(tp, XFS_TRANS_RELEASE_LOG_RES | XFS_TRANS_ABORT);
5937 return error;
5938}
diff --git a/fs/xfs/libxfs/xfs_bmap.h b/fs/xfs/libxfs/xfs_bmap.h
index b9d8a499d2c4..6aaa0c1c7200 100644
--- a/fs/xfs/libxfs/xfs_bmap.h
+++ b/fs/xfs/libxfs/xfs_bmap.h
@@ -166,6 +166,11 @@ static inline void xfs_bmap_init(xfs_bmap_free_t *flp, xfs_fsblock_t *fbp)
166 */ 166 */
167#define XFS_BMAP_MAX_SHIFT_EXTENTS 1 167#define XFS_BMAP_MAX_SHIFT_EXTENTS 1
168 168
169enum shift_direction {
170 SHIFT_LEFT = 0,
171 SHIFT_RIGHT,
172};
173
169#ifdef DEBUG 174#ifdef DEBUG
170void xfs_bmap_trace_exlist(struct xfs_inode *ip, xfs_extnum_t cnt, 175void xfs_bmap_trace_exlist(struct xfs_inode *ip, xfs_extnum_t cnt,
171 int whichfork, unsigned long caller_ip); 176 int whichfork, unsigned long caller_ip);
@@ -211,8 +216,10 @@ int xfs_check_nostate_extents(struct xfs_ifork *ifp, xfs_extnum_t idx,
211 xfs_extnum_t num); 216 xfs_extnum_t num);
212uint xfs_default_attroffset(struct xfs_inode *ip); 217uint xfs_default_attroffset(struct xfs_inode *ip);
213int xfs_bmap_shift_extents(struct xfs_trans *tp, struct xfs_inode *ip, 218int xfs_bmap_shift_extents(struct xfs_trans *tp, struct xfs_inode *ip,
214 xfs_fileoff_t start_fsb, xfs_fileoff_t offset_shift_fsb, 219 xfs_fileoff_t *next_fsb, xfs_fileoff_t offset_shift_fsb,
215 int *done, xfs_fileoff_t *next_fsb, xfs_fsblock_t *firstblock, 220 int *done, xfs_fileoff_t stop_fsb, xfs_fsblock_t *firstblock,
216 struct xfs_bmap_free *flist, int num_exts); 221 struct xfs_bmap_free *flist, enum shift_direction direction,
222 int num_exts);
223int xfs_bmap_split_extent(struct xfs_inode *ip, xfs_fileoff_t split_offset);
217 224
218#endif /* __XFS_BMAP_H__ */ 225#endif /* __XFS_BMAP_H__ */
diff --git a/fs/xfs/libxfs/xfs_btree.c b/fs/xfs/libxfs/xfs_btree.c
index 81cad433df85..c72283dd8d44 100644
--- a/fs/xfs/libxfs/xfs_btree.c
+++ b/fs/xfs/libxfs/xfs_btree.c
@@ -168,7 +168,7 @@ xfs_btree_check_lptr(
168 xfs_fsblock_t bno, /* btree block disk address */ 168 xfs_fsblock_t bno, /* btree block disk address */
169 int level) /* btree block level */ 169 int level) /* btree block level */
170{ 170{
171 XFS_WANT_CORRUPTED_RETURN( 171 XFS_WANT_CORRUPTED_RETURN(cur->bc_mp,
172 level > 0 && 172 level > 0 &&
173 bno != NULLFSBLOCK && 173 bno != NULLFSBLOCK &&
174 XFS_FSB_SANITY_CHECK(cur->bc_mp, bno)); 174 XFS_FSB_SANITY_CHECK(cur->bc_mp, bno));
@@ -187,7 +187,7 @@ xfs_btree_check_sptr(
187{ 187{
188 xfs_agblock_t agblocks = cur->bc_mp->m_sb.sb_agblocks; 188 xfs_agblock_t agblocks = cur->bc_mp->m_sb.sb_agblocks;
189 189
190 XFS_WANT_CORRUPTED_RETURN( 190 XFS_WANT_CORRUPTED_RETURN(cur->bc_mp,
191 level > 0 && 191 level > 0 &&
192 bno != NULLAGBLOCK && 192 bno != NULLAGBLOCK &&
193 bno != 0 && 193 bno != 0 &&
@@ -1825,7 +1825,7 @@ xfs_btree_lookup(
1825 error = xfs_btree_increment(cur, 0, &i); 1825 error = xfs_btree_increment(cur, 0, &i);
1826 if (error) 1826 if (error)
1827 goto error0; 1827 goto error0;
1828 XFS_WANT_CORRUPTED_RETURN(i == 1); 1828 XFS_WANT_CORRUPTED_RETURN(cur->bc_mp, i == 1);
1829 XFS_BTREE_TRACE_CURSOR(cur, XBT_EXIT); 1829 XFS_BTREE_TRACE_CURSOR(cur, XBT_EXIT);
1830 *stat = 1; 1830 *stat = 1;
1831 return 0; 1831 return 0;
@@ -2285,7 +2285,7 @@ xfs_btree_rshift(
2285 if (error) 2285 if (error)
2286 goto error0; 2286 goto error0;
2287 i = xfs_btree_lastrec(tcur, level); 2287 i = xfs_btree_lastrec(tcur, level);
2288 XFS_WANT_CORRUPTED_GOTO(i == 1, error0); 2288 XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, i == 1, error0);
2289 2289
2290 error = xfs_btree_increment(tcur, level, &i); 2290 error = xfs_btree_increment(tcur, level, &i);
2291 if (error) 2291 if (error)
@@ -3138,7 +3138,7 @@ xfs_btree_insert(
3138 goto error0; 3138 goto error0;
3139 } 3139 }
3140 3140
3141 XFS_WANT_CORRUPTED_GOTO(i == 1, error0); 3141 XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, i == 1, error0);
3142 level++; 3142 level++;
3143 3143
3144 /* 3144 /*
@@ -3582,15 +3582,15 @@ xfs_btree_delrec(
3582 * Actually any entry but the first would suffice. 3582 * Actually any entry but the first would suffice.
3583 */ 3583 */
3584 i = xfs_btree_lastrec(tcur, level); 3584 i = xfs_btree_lastrec(tcur, level);
3585 XFS_WANT_CORRUPTED_GOTO(i == 1, error0); 3585 XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, i == 1, error0);
3586 3586
3587 error = xfs_btree_increment(tcur, level, &i); 3587 error = xfs_btree_increment(tcur, level, &i);
3588 if (error) 3588 if (error)
3589 goto error0; 3589 goto error0;
3590 XFS_WANT_CORRUPTED_GOTO(i == 1, error0); 3590 XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, i == 1, error0);
3591 3591
3592 i = xfs_btree_lastrec(tcur, level); 3592 i = xfs_btree_lastrec(tcur, level);
3593 XFS_WANT_CORRUPTED_GOTO(i == 1, error0); 3593 XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, i == 1, error0);
3594 3594
3595 /* Grab a pointer to the block. */ 3595 /* Grab a pointer to the block. */
3596 right = xfs_btree_get_block(tcur, level, &rbp); 3596 right = xfs_btree_get_block(tcur, level, &rbp);
@@ -3634,12 +3634,12 @@ xfs_btree_delrec(
3634 rrecs = xfs_btree_get_numrecs(right); 3634 rrecs = xfs_btree_get_numrecs(right);
3635 if (!xfs_btree_ptr_is_null(cur, &lptr)) { 3635 if (!xfs_btree_ptr_is_null(cur, &lptr)) {
3636 i = xfs_btree_firstrec(tcur, level); 3636 i = xfs_btree_firstrec(tcur, level);
3637 XFS_WANT_CORRUPTED_GOTO(i == 1, error0); 3637 XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, i == 1, error0);
3638 3638
3639 error = xfs_btree_decrement(tcur, level, &i); 3639 error = xfs_btree_decrement(tcur, level, &i);
3640 if (error) 3640 if (error)
3641 goto error0; 3641 goto error0;
3642 XFS_WANT_CORRUPTED_GOTO(i == 1, error0); 3642 XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, i == 1, error0);
3643 } 3643 }
3644 } 3644 }
3645 3645
@@ -3653,13 +3653,13 @@ xfs_btree_delrec(
3653 * previous block. 3653 * previous block.
3654 */ 3654 */
3655 i = xfs_btree_firstrec(tcur, level); 3655 i = xfs_btree_firstrec(tcur, level);
3656 XFS_WANT_CORRUPTED_GOTO(i == 1, error0); 3656 XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, i == 1, error0);
3657 3657
3658 error = xfs_btree_decrement(tcur, level, &i); 3658 error = xfs_btree_decrement(tcur, level, &i);
3659 if (error) 3659 if (error)
3660 goto error0; 3660 goto error0;
3661 i = xfs_btree_firstrec(tcur, level); 3661 i = xfs_btree_firstrec(tcur, level);
3662 XFS_WANT_CORRUPTED_GOTO(i == 1, error0); 3662 XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, i == 1, error0);
3663 3663
3664 /* Grab a pointer to the block. */ 3664 /* Grab a pointer to the block. */
3665 left = xfs_btree_get_block(tcur, level, &lbp); 3665 left = xfs_btree_get_block(tcur, level, &lbp);
diff --git a/fs/xfs/libxfs/xfs_da_btree.c b/fs/xfs/libxfs/xfs_da_btree.c
index 9cb0115c6bd1..2385f8cd08ab 100644
--- a/fs/xfs/libxfs/xfs_da_btree.c
+++ b/fs/xfs/libxfs/xfs_da_btree.c
@@ -538,12 +538,12 @@ xfs_da3_root_split(
538 oldroot = blk1->bp->b_addr; 538 oldroot = blk1->bp->b_addr;
539 if (oldroot->hdr.info.magic == cpu_to_be16(XFS_DA_NODE_MAGIC) || 539 if (oldroot->hdr.info.magic == cpu_to_be16(XFS_DA_NODE_MAGIC) ||
540 oldroot->hdr.info.magic == cpu_to_be16(XFS_DA3_NODE_MAGIC)) { 540 oldroot->hdr.info.magic == cpu_to_be16(XFS_DA3_NODE_MAGIC)) {
541 struct xfs_da3_icnode_hdr nodehdr; 541 struct xfs_da3_icnode_hdr icnodehdr;
542 542
543 dp->d_ops->node_hdr_from_disk(&nodehdr, oldroot); 543 dp->d_ops->node_hdr_from_disk(&icnodehdr, oldroot);
544 btree = dp->d_ops->node_tree_p(oldroot); 544 btree = dp->d_ops->node_tree_p(oldroot);
545 size = (int)((char *)&btree[nodehdr.count] - (char *)oldroot); 545 size = (int)((char *)&btree[icnodehdr.count] - (char *)oldroot);
546 level = nodehdr.level; 546 level = icnodehdr.level;
547 547
548 /* 548 /*
549 * we are about to copy oldroot to bp, so set up the type 549 * we are about to copy oldroot to bp, so set up the type
diff --git a/fs/xfs/libxfs/xfs_da_format.h b/fs/xfs/libxfs/xfs_da_format.h
index 0a49b0286372..74bcbabfa523 100644
--- a/fs/xfs/libxfs/xfs_da_format.h
+++ b/fs/xfs/libxfs/xfs_da_format.h
@@ -725,7 +725,13 @@ struct xfs_attr3_icleaf_hdr {
725 __uint16_t magic; 725 __uint16_t magic;
726 __uint16_t count; 726 __uint16_t count;
727 __uint16_t usedbytes; 727 __uint16_t usedbytes;
728 __uint16_t firstused; 728 /*
729 * firstused is 32-bit here instead of 16-bit like the on-disk variant
730 * to support maximum fsb size of 64k without overflow issues throughout
731 * the attr code. Instead, the overflow condition is handled on
732 * conversion to/from disk.
733 */
734 __uint32_t firstused;
729 __u8 holes; 735 __u8 holes;
730 struct { 736 struct {
731 __uint16_t base; 737 __uint16_t base;
@@ -734,6 +740,12 @@ struct xfs_attr3_icleaf_hdr {
734}; 740};
735 741
736/* 742/*
743 * Special value to represent fs block size in the leaf header firstused field.
744 * Only used when block size overflows the 2-bytes available on disk.
745 */
746#define XFS_ATTR3_LEAF_NULLOFF 0
747
748/*
737 * Flags used in the leaf_entry[i].flags field. 749 * Flags used in the leaf_entry[i].flags field.
738 * NOTE: the INCOMPLETE bit must not collide with the flags bits specified 750 * NOTE: the INCOMPLETE bit must not collide with the flags bits specified
739 * on the system call, they are "or"ed together for various operations. 751 * on the system call, they are "or"ed together for various operations.
diff --git a/fs/xfs/libxfs/xfs_dir2_data.c b/fs/xfs/libxfs/xfs_dir2_data.c
index 5ff31be9b1cd..de1ea16f5748 100644
--- a/fs/xfs/libxfs/xfs_dir2_data.c
+++ b/fs/xfs/libxfs/xfs_dir2_data.c
@@ -89,7 +89,7 @@ __xfs_dir3_data_check(
89 * so just ensure that the count falls somewhere inside the 89 * so just ensure that the count falls somewhere inside the
90 * block right now. 90 * block right now.
91 */ 91 */
92 XFS_WANT_CORRUPTED_RETURN(be32_to_cpu(btp->count) < 92 XFS_WANT_CORRUPTED_RETURN(mp, be32_to_cpu(btp->count) <
93 ((char *)btp - p) / sizeof(struct xfs_dir2_leaf_entry)); 93 ((char *)btp - p) / sizeof(struct xfs_dir2_leaf_entry));
94 break; 94 break;
95 case cpu_to_be32(XFS_DIR3_DATA_MAGIC): 95 case cpu_to_be32(XFS_DIR3_DATA_MAGIC):
@@ -107,21 +107,21 @@ __xfs_dir3_data_check(
107 bf = ops->data_bestfree_p(hdr); 107 bf = ops->data_bestfree_p(hdr);
108 count = lastfree = freeseen = 0; 108 count = lastfree = freeseen = 0;
109 if (!bf[0].length) { 109 if (!bf[0].length) {
110 XFS_WANT_CORRUPTED_RETURN(!bf[0].offset); 110 XFS_WANT_CORRUPTED_RETURN(mp, !bf[0].offset);
111 freeseen |= 1 << 0; 111 freeseen |= 1 << 0;
112 } 112 }
113 if (!bf[1].length) { 113 if (!bf[1].length) {
114 XFS_WANT_CORRUPTED_RETURN(!bf[1].offset); 114 XFS_WANT_CORRUPTED_RETURN(mp, !bf[1].offset);
115 freeseen |= 1 << 1; 115 freeseen |= 1 << 1;
116 } 116 }
117 if (!bf[2].length) { 117 if (!bf[2].length) {
118 XFS_WANT_CORRUPTED_RETURN(!bf[2].offset); 118 XFS_WANT_CORRUPTED_RETURN(mp, !bf[2].offset);
119 freeseen |= 1 << 2; 119 freeseen |= 1 << 2;
120 } 120 }
121 121
122 XFS_WANT_CORRUPTED_RETURN(be16_to_cpu(bf[0].length) >= 122 XFS_WANT_CORRUPTED_RETURN(mp, be16_to_cpu(bf[0].length) >=
123 be16_to_cpu(bf[1].length)); 123 be16_to_cpu(bf[1].length));
124 XFS_WANT_CORRUPTED_RETURN(be16_to_cpu(bf[1].length) >= 124 XFS_WANT_CORRUPTED_RETURN(mp, be16_to_cpu(bf[1].length) >=
125 be16_to_cpu(bf[2].length)); 125 be16_to_cpu(bf[2].length));
126 /* 126 /*
127 * Loop over the data/unused entries. 127 * Loop over the data/unused entries.
@@ -134,18 +134,18 @@ __xfs_dir3_data_check(
134 * doesn't need to be there. 134 * doesn't need to be there.
135 */ 135 */
136 if (be16_to_cpu(dup->freetag) == XFS_DIR2_DATA_FREE_TAG) { 136 if (be16_to_cpu(dup->freetag) == XFS_DIR2_DATA_FREE_TAG) {
137 XFS_WANT_CORRUPTED_RETURN(lastfree == 0); 137 XFS_WANT_CORRUPTED_RETURN(mp, lastfree == 0);
138 XFS_WANT_CORRUPTED_RETURN( 138 XFS_WANT_CORRUPTED_RETURN(mp,
139 be16_to_cpu(*xfs_dir2_data_unused_tag_p(dup)) == 139 be16_to_cpu(*xfs_dir2_data_unused_tag_p(dup)) ==
140 (char *)dup - (char *)hdr); 140 (char *)dup - (char *)hdr);
141 dfp = xfs_dir2_data_freefind(hdr, bf, dup); 141 dfp = xfs_dir2_data_freefind(hdr, bf, dup);
142 if (dfp) { 142 if (dfp) {
143 i = (int)(dfp - bf); 143 i = (int)(dfp - bf);
144 XFS_WANT_CORRUPTED_RETURN( 144 XFS_WANT_CORRUPTED_RETURN(mp,
145 (freeseen & (1 << i)) == 0); 145 (freeseen & (1 << i)) == 0);
146 freeseen |= 1 << i; 146 freeseen |= 1 << i;
147 } else { 147 } else {
148 XFS_WANT_CORRUPTED_RETURN( 148 XFS_WANT_CORRUPTED_RETURN(mp,
149 be16_to_cpu(dup->length) <= 149 be16_to_cpu(dup->length) <=
150 be16_to_cpu(bf[2].length)); 150 be16_to_cpu(bf[2].length));
151 } 151 }
@@ -160,13 +160,13 @@ __xfs_dir3_data_check(
160 * The linear search is crude but this is DEBUG code. 160 * The linear search is crude but this is DEBUG code.
161 */ 161 */
162 dep = (xfs_dir2_data_entry_t *)p; 162 dep = (xfs_dir2_data_entry_t *)p;
163 XFS_WANT_CORRUPTED_RETURN(dep->namelen != 0); 163 XFS_WANT_CORRUPTED_RETURN(mp, dep->namelen != 0);
164 XFS_WANT_CORRUPTED_RETURN( 164 XFS_WANT_CORRUPTED_RETURN(mp,
165 !xfs_dir_ino_validate(mp, be64_to_cpu(dep->inumber))); 165 !xfs_dir_ino_validate(mp, be64_to_cpu(dep->inumber)));
166 XFS_WANT_CORRUPTED_RETURN( 166 XFS_WANT_CORRUPTED_RETURN(mp,
167 be16_to_cpu(*ops->data_entry_tag_p(dep)) == 167 be16_to_cpu(*ops->data_entry_tag_p(dep)) ==
168 (char *)dep - (char *)hdr); 168 (char *)dep - (char *)hdr);
169 XFS_WANT_CORRUPTED_RETURN( 169 XFS_WANT_CORRUPTED_RETURN(mp,
170 ops->data_get_ftype(dep) < XFS_DIR3_FT_MAX); 170 ops->data_get_ftype(dep) < XFS_DIR3_FT_MAX);
171 count++; 171 count++;
172 lastfree = 0; 172 lastfree = 0;
@@ -183,14 +183,15 @@ __xfs_dir3_data_check(
183 be32_to_cpu(lep[i].hashval) == hash) 183 be32_to_cpu(lep[i].hashval) == hash)
184 break; 184 break;
185 } 185 }
186 XFS_WANT_CORRUPTED_RETURN(i < be32_to_cpu(btp->count)); 186 XFS_WANT_CORRUPTED_RETURN(mp,
187 i < be32_to_cpu(btp->count));
187 } 188 }
188 p += ops->data_entsize(dep->namelen); 189 p += ops->data_entsize(dep->namelen);
189 } 190 }
190 /* 191 /*
191 * Need to have seen all the entries and all the bestfree slots. 192 * Need to have seen all the entries and all the bestfree slots.
192 */ 193 */
193 XFS_WANT_CORRUPTED_RETURN(freeseen == 7); 194 XFS_WANT_CORRUPTED_RETURN(mp, freeseen == 7);
194 if (hdr->magic == cpu_to_be32(XFS_DIR2_BLOCK_MAGIC) || 195 if (hdr->magic == cpu_to_be32(XFS_DIR2_BLOCK_MAGIC) ||
195 hdr->magic == cpu_to_be32(XFS_DIR3_BLOCK_MAGIC)) { 196 hdr->magic == cpu_to_be32(XFS_DIR3_BLOCK_MAGIC)) {
196 for (i = stale = 0; i < be32_to_cpu(btp->count); i++) { 197 for (i = stale = 0; i < be32_to_cpu(btp->count); i++) {
@@ -198,13 +199,13 @@ __xfs_dir3_data_check(
198 cpu_to_be32(XFS_DIR2_NULL_DATAPTR)) 199 cpu_to_be32(XFS_DIR2_NULL_DATAPTR))
199 stale++; 200 stale++;
200 if (i > 0) 201 if (i > 0)
201 XFS_WANT_CORRUPTED_RETURN( 202 XFS_WANT_CORRUPTED_RETURN(mp,
202 be32_to_cpu(lep[i].hashval) >= 203 be32_to_cpu(lep[i].hashval) >=
203 be32_to_cpu(lep[i - 1].hashval)); 204 be32_to_cpu(lep[i - 1].hashval));
204 } 205 }
205 XFS_WANT_CORRUPTED_RETURN(count == 206 XFS_WANT_CORRUPTED_RETURN(mp, count ==
206 be32_to_cpu(btp->count) - be32_to_cpu(btp->stale)); 207 be32_to_cpu(btp->count) - be32_to_cpu(btp->stale));
207 XFS_WANT_CORRUPTED_RETURN(stale == be32_to_cpu(btp->stale)); 208 XFS_WANT_CORRUPTED_RETURN(mp, stale == be32_to_cpu(btp->stale));
208 } 209 }
209 return 0; 210 return 0;
210} 211}
diff --git a/fs/xfs/libxfs/xfs_format.h b/fs/xfs/libxfs/xfs_format.h
index 8eb718979383..4daaa662337b 100644
--- a/fs/xfs/libxfs/xfs_format.h
+++ b/fs/xfs/libxfs/xfs_format.h
@@ -264,68 +264,6 @@ typedef struct xfs_dsb {
264 /* must be padded to 64 bit alignment */ 264 /* must be padded to 64 bit alignment */
265} xfs_dsb_t; 265} xfs_dsb_t;
266 266
267/*
268 * Sequence number values for the fields.
269 */
270typedef enum {
271 XFS_SBS_MAGICNUM, XFS_SBS_BLOCKSIZE, XFS_SBS_DBLOCKS, XFS_SBS_RBLOCKS,
272 XFS_SBS_REXTENTS, XFS_SBS_UUID, XFS_SBS_LOGSTART, XFS_SBS_ROOTINO,
273 XFS_SBS_RBMINO, XFS_SBS_RSUMINO, XFS_SBS_REXTSIZE, XFS_SBS_AGBLOCKS,
274 XFS_SBS_AGCOUNT, XFS_SBS_RBMBLOCKS, XFS_SBS_LOGBLOCKS,
275 XFS_SBS_VERSIONNUM, XFS_SBS_SECTSIZE, XFS_SBS_INODESIZE,
276 XFS_SBS_INOPBLOCK, XFS_SBS_FNAME, XFS_SBS_BLOCKLOG,
277 XFS_SBS_SECTLOG, XFS_SBS_INODELOG, XFS_SBS_INOPBLOG, XFS_SBS_AGBLKLOG,
278 XFS_SBS_REXTSLOG, XFS_SBS_INPROGRESS, XFS_SBS_IMAX_PCT, XFS_SBS_ICOUNT,
279 XFS_SBS_IFREE, XFS_SBS_FDBLOCKS, XFS_SBS_FREXTENTS, XFS_SBS_UQUOTINO,
280 XFS_SBS_GQUOTINO, XFS_SBS_QFLAGS, XFS_SBS_FLAGS, XFS_SBS_SHARED_VN,
281 XFS_SBS_INOALIGNMT, XFS_SBS_UNIT, XFS_SBS_WIDTH, XFS_SBS_DIRBLKLOG,
282 XFS_SBS_LOGSECTLOG, XFS_SBS_LOGSECTSIZE, XFS_SBS_LOGSUNIT,
283 XFS_SBS_FEATURES2, XFS_SBS_BAD_FEATURES2, XFS_SBS_FEATURES_COMPAT,
284 XFS_SBS_FEATURES_RO_COMPAT, XFS_SBS_FEATURES_INCOMPAT,
285 XFS_SBS_FEATURES_LOG_INCOMPAT, XFS_SBS_CRC, XFS_SBS_PAD,
286 XFS_SBS_PQUOTINO, XFS_SBS_LSN,
287 XFS_SBS_FIELDCOUNT
288} xfs_sb_field_t;
289
290/*
291 * Mask values, defined based on the xfs_sb_field_t values.
292 * Only define the ones we're using.
293 */
294#define XFS_SB_MVAL(x) (1LL << XFS_SBS_ ## x)
295#define XFS_SB_UUID XFS_SB_MVAL(UUID)
296#define XFS_SB_FNAME XFS_SB_MVAL(FNAME)
297#define XFS_SB_ROOTINO XFS_SB_MVAL(ROOTINO)
298#define XFS_SB_RBMINO XFS_SB_MVAL(RBMINO)
299#define XFS_SB_RSUMINO XFS_SB_MVAL(RSUMINO)
300#define XFS_SB_VERSIONNUM XFS_SB_MVAL(VERSIONNUM)
301#define XFS_SB_UQUOTINO XFS_SB_MVAL(UQUOTINO)
302#define XFS_SB_GQUOTINO XFS_SB_MVAL(GQUOTINO)
303#define XFS_SB_QFLAGS XFS_SB_MVAL(QFLAGS)
304#define XFS_SB_SHARED_VN XFS_SB_MVAL(SHARED_VN)
305#define XFS_SB_UNIT XFS_SB_MVAL(UNIT)
306#define XFS_SB_WIDTH XFS_SB_MVAL(WIDTH)
307#define XFS_SB_ICOUNT XFS_SB_MVAL(ICOUNT)
308#define XFS_SB_IFREE XFS_SB_MVAL(IFREE)
309#define XFS_SB_FDBLOCKS XFS_SB_MVAL(FDBLOCKS)
310#define XFS_SB_FEATURES2 (XFS_SB_MVAL(FEATURES2) | \
311 XFS_SB_MVAL(BAD_FEATURES2))
312#define XFS_SB_FEATURES_COMPAT XFS_SB_MVAL(FEATURES_COMPAT)
313#define XFS_SB_FEATURES_RO_COMPAT XFS_SB_MVAL(FEATURES_RO_COMPAT)
314#define XFS_SB_FEATURES_INCOMPAT XFS_SB_MVAL(FEATURES_INCOMPAT)
315#define XFS_SB_FEATURES_LOG_INCOMPAT XFS_SB_MVAL(FEATURES_LOG_INCOMPAT)
316#define XFS_SB_CRC XFS_SB_MVAL(CRC)
317#define XFS_SB_PQUOTINO XFS_SB_MVAL(PQUOTINO)
318#define XFS_SB_NUM_BITS ((int)XFS_SBS_FIELDCOUNT)
319#define XFS_SB_ALL_BITS ((1LL << XFS_SB_NUM_BITS) - 1)
320#define XFS_SB_MOD_BITS \
321 (XFS_SB_UUID | XFS_SB_ROOTINO | XFS_SB_RBMINO | XFS_SB_RSUMINO | \
322 XFS_SB_VERSIONNUM | XFS_SB_UQUOTINO | XFS_SB_GQUOTINO | \
323 XFS_SB_QFLAGS | XFS_SB_SHARED_VN | XFS_SB_UNIT | XFS_SB_WIDTH | \
324 XFS_SB_ICOUNT | XFS_SB_IFREE | XFS_SB_FDBLOCKS | XFS_SB_FEATURES2 | \
325 XFS_SB_FEATURES_COMPAT | XFS_SB_FEATURES_RO_COMPAT | \
326 XFS_SB_FEATURES_INCOMPAT | XFS_SB_FEATURES_LOG_INCOMPAT | \
327 XFS_SB_PQUOTINO)
328
329 267
330/* 268/*
331 * Misc. Flags - warning - these will be cleared by xfs_repair unless 269 * Misc. Flags - warning - these will be cleared by xfs_repair unless
diff --git a/fs/xfs/libxfs/xfs_ialloc.c b/fs/xfs/libxfs/xfs_ialloc.c
index 116ef1ddb3e3..07349a183a11 100644
--- a/fs/xfs/libxfs/xfs_ialloc.c
+++ b/fs/xfs/libxfs/xfs_ialloc.c
@@ -376,7 +376,8 @@ xfs_ialloc_ag_alloc(
376 */ 376 */
377 newlen = args.mp->m_ialloc_inos; 377 newlen = args.mp->m_ialloc_inos;
378 if (args.mp->m_maxicount && 378 if (args.mp->m_maxicount &&
379 args.mp->m_sb.sb_icount + newlen > args.mp->m_maxicount) 379 percpu_counter_read(&args.mp->m_icount) + newlen >
380 args.mp->m_maxicount)
380 return -ENOSPC; 381 return -ENOSPC;
381 args.minlen = args.maxlen = args.mp->m_ialloc_blks; 382 args.minlen = args.maxlen = args.mp->m_ialloc_blks;
382 /* 383 /*
@@ -700,7 +701,7 @@ xfs_ialloc_next_rec(
700 error = xfs_inobt_get_rec(cur, rec, &i); 701 error = xfs_inobt_get_rec(cur, rec, &i);
701 if (error) 702 if (error)
702 return error; 703 return error;
703 XFS_WANT_CORRUPTED_RETURN(i == 1); 704 XFS_WANT_CORRUPTED_RETURN(cur->bc_mp, i == 1);
704 } 705 }
705 706
706 return 0; 707 return 0;
@@ -724,7 +725,7 @@ xfs_ialloc_get_rec(
724 error = xfs_inobt_get_rec(cur, rec, &i); 725 error = xfs_inobt_get_rec(cur, rec, &i);
725 if (error) 726 if (error)
726 return error; 727 return error;
727 XFS_WANT_CORRUPTED_RETURN(i == 1); 728 XFS_WANT_CORRUPTED_RETURN(cur->bc_mp, i == 1);
728 } 729 }
729 730
730 return 0; 731 return 0;
@@ -783,12 +784,12 @@ xfs_dialloc_ag_inobt(
783 error = xfs_inobt_lookup(cur, pagino, XFS_LOOKUP_LE, &i); 784 error = xfs_inobt_lookup(cur, pagino, XFS_LOOKUP_LE, &i);
784 if (error) 785 if (error)
785 goto error0; 786 goto error0;
786 XFS_WANT_CORRUPTED_GOTO(i == 1, error0); 787 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, error0);
787 788
788 error = xfs_inobt_get_rec(cur, &rec, &j); 789 error = xfs_inobt_get_rec(cur, &rec, &j);
789 if (error) 790 if (error)
790 goto error0; 791 goto error0;
791 XFS_WANT_CORRUPTED_GOTO(j == 1, error0); 792 XFS_WANT_CORRUPTED_GOTO(mp, j == 1, error0);
792 793
793 if (rec.ir_freecount > 0) { 794 if (rec.ir_freecount > 0) {
794 /* 795 /*
@@ -944,19 +945,19 @@ newino:
944 error = xfs_inobt_lookup(cur, 0, XFS_LOOKUP_GE, &i); 945 error = xfs_inobt_lookup(cur, 0, XFS_LOOKUP_GE, &i);
945 if (error) 946 if (error)
946 goto error0; 947 goto error0;
947 XFS_WANT_CORRUPTED_GOTO(i == 1, error0); 948 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, error0);
948 949
949 for (;;) { 950 for (;;) {
950 error = xfs_inobt_get_rec(cur, &rec, &i); 951 error = xfs_inobt_get_rec(cur, &rec, &i);
951 if (error) 952 if (error)
952 goto error0; 953 goto error0;
953 XFS_WANT_CORRUPTED_GOTO(i == 1, error0); 954 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, error0);
954 if (rec.ir_freecount > 0) 955 if (rec.ir_freecount > 0)
955 break; 956 break;
956 error = xfs_btree_increment(cur, 0, &i); 957 error = xfs_btree_increment(cur, 0, &i);
957 if (error) 958 if (error)
958 goto error0; 959 goto error0;
959 XFS_WANT_CORRUPTED_GOTO(i == 1, error0); 960 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, error0);
960 } 961 }
961 962
962alloc_inode: 963alloc_inode:
@@ -1016,7 +1017,7 @@ xfs_dialloc_ag_finobt_near(
1016 error = xfs_inobt_get_rec(lcur, rec, &i); 1017 error = xfs_inobt_get_rec(lcur, rec, &i);
1017 if (error) 1018 if (error)
1018 return error; 1019 return error;
1019 XFS_WANT_CORRUPTED_RETURN(i == 1); 1020 XFS_WANT_CORRUPTED_RETURN(lcur->bc_mp, i == 1);
1020 1021
1021 /* 1022 /*
1022 * See if we've landed in the parent inode record. The finobt 1023 * See if we've landed in the parent inode record. The finobt
@@ -1039,10 +1040,10 @@ xfs_dialloc_ag_finobt_near(
1039 error = xfs_inobt_get_rec(rcur, &rrec, &j); 1040 error = xfs_inobt_get_rec(rcur, &rrec, &j);
1040 if (error) 1041 if (error)
1041 goto error_rcur; 1042 goto error_rcur;
1042 XFS_WANT_CORRUPTED_GOTO(j == 1, error_rcur); 1043 XFS_WANT_CORRUPTED_GOTO(lcur->bc_mp, j == 1, error_rcur);
1043 } 1044 }
1044 1045
1045 XFS_WANT_CORRUPTED_GOTO(i == 1 || j == 1, error_rcur); 1046 XFS_WANT_CORRUPTED_GOTO(lcur->bc_mp, i == 1 || j == 1, error_rcur);
1046 if (i == 1 && j == 1) { 1047 if (i == 1 && j == 1) {
1047 /* 1048 /*
1048 * Both the left and right records are valid. Choose the closer 1049 * Both the left and right records are valid. Choose the closer
@@ -1095,7 +1096,7 @@ xfs_dialloc_ag_finobt_newino(
1095 error = xfs_inobt_get_rec(cur, rec, &i); 1096 error = xfs_inobt_get_rec(cur, rec, &i);
1096 if (error) 1097 if (error)
1097 return error; 1098 return error;
1098 XFS_WANT_CORRUPTED_RETURN(i == 1); 1099 XFS_WANT_CORRUPTED_RETURN(cur->bc_mp, i == 1);
1099 return 0; 1100 return 0;
1100 } 1101 }
1101 } 1102 }
@@ -1106,12 +1107,12 @@ xfs_dialloc_ag_finobt_newino(
1106 error = xfs_inobt_lookup(cur, 0, XFS_LOOKUP_GE, &i); 1107 error = xfs_inobt_lookup(cur, 0, XFS_LOOKUP_GE, &i);
1107 if (error) 1108 if (error)
1108 return error; 1109 return error;
1109 XFS_WANT_CORRUPTED_RETURN(i == 1); 1110 XFS_WANT_CORRUPTED_RETURN(cur->bc_mp, i == 1);
1110 1111
1111 error = xfs_inobt_get_rec(cur, rec, &i); 1112 error = xfs_inobt_get_rec(cur, rec, &i);
1112 if (error) 1113 if (error)
1113 return error; 1114 return error;
1114 XFS_WANT_CORRUPTED_RETURN(i == 1); 1115 XFS_WANT_CORRUPTED_RETURN(cur->bc_mp, i == 1);
1115 1116
1116 return 0; 1117 return 0;
1117} 1118}
@@ -1133,19 +1134,19 @@ xfs_dialloc_ag_update_inobt(
1133 error = xfs_inobt_lookup(cur, frec->ir_startino, XFS_LOOKUP_EQ, &i); 1134 error = xfs_inobt_lookup(cur, frec->ir_startino, XFS_LOOKUP_EQ, &i);
1134 if (error) 1135 if (error)
1135 return error; 1136 return error;
1136 XFS_WANT_CORRUPTED_RETURN(i == 1); 1137 XFS_WANT_CORRUPTED_RETURN(cur->bc_mp, i == 1);
1137 1138
1138 error = xfs_inobt_get_rec(cur, &rec, &i); 1139 error = xfs_inobt_get_rec(cur, &rec, &i);
1139 if (error) 1140 if (error)
1140 return error; 1141 return error;
1141 XFS_WANT_CORRUPTED_RETURN(i == 1); 1142 XFS_WANT_CORRUPTED_RETURN(cur->bc_mp, i == 1);
1142 ASSERT((XFS_AGINO_TO_OFFSET(cur->bc_mp, rec.ir_startino) % 1143 ASSERT((XFS_AGINO_TO_OFFSET(cur->bc_mp, rec.ir_startino) %
1143 XFS_INODES_PER_CHUNK) == 0); 1144 XFS_INODES_PER_CHUNK) == 0);
1144 1145
1145 rec.ir_free &= ~XFS_INOBT_MASK(offset); 1146 rec.ir_free &= ~XFS_INOBT_MASK(offset);
1146 rec.ir_freecount--; 1147 rec.ir_freecount--;
1147 1148
1148 XFS_WANT_CORRUPTED_RETURN((rec.ir_free == frec->ir_free) && 1149 XFS_WANT_CORRUPTED_RETURN(cur->bc_mp, (rec.ir_free == frec->ir_free) &&
1149 (rec.ir_freecount == frec->ir_freecount)); 1150 (rec.ir_freecount == frec->ir_freecount));
1150 1151
1151 return xfs_inobt_update(cur, &rec); 1152 return xfs_inobt_update(cur, &rec);
@@ -1340,7 +1341,8 @@ xfs_dialloc(
1340 * inode. 1341 * inode.
1341 */ 1342 */
1342 if (mp->m_maxicount && 1343 if (mp->m_maxicount &&
1343 mp->m_sb.sb_icount + mp->m_ialloc_inos > mp->m_maxicount) { 1344 percpu_counter_read(&mp->m_icount) + mp->m_ialloc_inos >
1345 mp->m_maxicount) {
1344 noroom = 1; 1346 noroom = 1;
1345 okalloc = 0; 1347 okalloc = 0;
1346 } 1348 }
@@ -1475,14 +1477,14 @@ xfs_difree_inobt(
1475 __func__, error); 1477 __func__, error);
1476 goto error0; 1478 goto error0;
1477 } 1479 }
1478 XFS_WANT_CORRUPTED_GOTO(i == 1, error0); 1480 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, error0);
1479 error = xfs_inobt_get_rec(cur, &rec, &i); 1481 error = xfs_inobt_get_rec(cur, &rec, &i);
1480 if (error) { 1482 if (error) {
1481 xfs_warn(mp, "%s: xfs_inobt_get_rec() returned error %d.", 1483 xfs_warn(mp, "%s: xfs_inobt_get_rec() returned error %d.",
1482 __func__, error); 1484 __func__, error);
1483 goto error0; 1485 goto error0;
1484 } 1486 }
1485 XFS_WANT_CORRUPTED_GOTO(i == 1, error0); 1487 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, error0);
1486 /* 1488 /*
1487 * Get the offset in the inode chunk. 1489 * Get the offset in the inode chunk.
1488 */ 1490 */
@@ -1592,7 +1594,7 @@ xfs_difree_finobt(
1592 * freed an inode in a previously fully allocated chunk. If not, 1594 * freed an inode in a previously fully allocated chunk. If not,
1593 * something is out of sync. 1595 * something is out of sync.
1594 */ 1596 */
1595 XFS_WANT_CORRUPTED_GOTO(ibtrec->ir_freecount == 1, error); 1597 XFS_WANT_CORRUPTED_GOTO(mp, ibtrec->ir_freecount == 1, error);
1596 1598
1597 error = xfs_inobt_insert_rec(cur, ibtrec->ir_freecount, 1599 error = xfs_inobt_insert_rec(cur, ibtrec->ir_freecount,
1598 ibtrec->ir_free, &i); 1600 ibtrec->ir_free, &i);
@@ -1613,12 +1615,12 @@ xfs_difree_finobt(
1613 error = xfs_inobt_get_rec(cur, &rec, &i); 1615 error = xfs_inobt_get_rec(cur, &rec, &i);
1614 if (error) 1616 if (error)
1615 goto error; 1617 goto error;
1616 XFS_WANT_CORRUPTED_GOTO(i == 1, error); 1618 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, error);
1617 1619
1618 rec.ir_free |= XFS_INOBT_MASK(offset); 1620 rec.ir_free |= XFS_INOBT_MASK(offset);
1619 rec.ir_freecount++; 1621 rec.ir_freecount++;
1620 1622
1621 XFS_WANT_CORRUPTED_GOTO((rec.ir_free == ibtrec->ir_free) && 1623 XFS_WANT_CORRUPTED_GOTO(mp, (rec.ir_free == ibtrec->ir_free) &&
1622 (rec.ir_freecount == ibtrec->ir_freecount), 1624 (rec.ir_freecount == ibtrec->ir_freecount),
1623 error); 1625 error);
1624 1626
diff --git a/fs/xfs/libxfs/xfs_sb.c b/fs/xfs/libxfs/xfs_sb.c
index b0a5fe95a3e2..dc4bfc5d88fc 100644
--- a/fs/xfs/libxfs/xfs_sb.c
+++ b/fs/xfs/libxfs/xfs_sb.c
@@ -111,14 +111,6 @@ xfs_mount_validate_sb(
111 bool check_inprogress, 111 bool check_inprogress,
112 bool check_version) 112 bool check_version)
113{ 113{
114
115 /*
116 * If the log device and data device have the
117 * same device number, the log is internal.
118 * Consequently, the sb_logstart should be non-zero. If
119 * we have a zero sb_logstart in this case, we may be trying to mount
120 * a volume filesystem in a non-volume manner.
121 */
122 if (sbp->sb_magicnum != XFS_SB_MAGIC) { 114 if (sbp->sb_magicnum != XFS_SB_MAGIC) {
123 xfs_warn(mp, "bad magic number"); 115 xfs_warn(mp, "bad magic number");
124 return -EWRONGFS; 116 return -EWRONGFS;
@@ -743,17 +735,15 @@ xfs_initialize_perag_data(
743 btree += pag->pagf_btreeblks; 735 btree += pag->pagf_btreeblks;
744 xfs_perag_put(pag); 736 xfs_perag_put(pag);
745 } 737 }
746 /* 738
747 * Overwrite incore superblock counters with just-read data 739 /* Overwrite incore superblock counters with just-read data */
748 */
749 spin_lock(&mp->m_sb_lock); 740 spin_lock(&mp->m_sb_lock);
750 sbp->sb_ifree = ifree; 741 sbp->sb_ifree = ifree;
751 sbp->sb_icount = ialloc; 742 sbp->sb_icount = ialloc;
752 sbp->sb_fdblocks = bfree + bfreelst + btree; 743 sbp->sb_fdblocks = bfree + bfreelst + btree;
753 spin_unlock(&mp->m_sb_lock); 744 spin_unlock(&mp->m_sb_lock);
754 745
755 /* Fixup the per-cpu counters as well. */ 746 xfs_reinit_percpu_counters(mp);
756 xfs_icsb_reinit_counters(mp);
757 747
758 return 0; 748 return 0;
759} 749}
@@ -771,6 +761,10 @@ xfs_log_sb(
771 struct xfs_mount *mp = tp->t_mountp; 761 struct xfs_mount *mp = tp->t_mountp;
772 struct xfs_buf *bp = xfs_trans_getsb(tp, mp, 0); 762 struct xfs_buf *bp = xfs_trans_getsb(tp, mp, 0);
773 763
764 mp->m_sb.sb_icount = percpu_counter_sum(&mp->m_icount);
765 mp->m_sb.sb_ifree = percpu_counter_sum(&mp->m_ifree);
766 mp->m_sb.sb_fdblocks = percpu_counter_sum(&mp->m_fdblocks);
767
774 xfs_sb_to_disk(XFS_BUF_TO_SBP(bp), &mp->m_sb); 768 xfs_sb_to_disk(XFS_BUF_TO_SBP(bp), &mp->m_sb);
775 xfs_trans_buf_set_type(tp, bp, XFS_BLFT_SB_BUF); 769 xfs_trans_buf_set_type(tp, bp, XFS_BLFT_SB_BUF);
776 xfs_trans_log_buf(tp, bp, 0, sizeof(struct xfs_dsb)); 770 xfs_trans_log_buf(tp, bp, 0, sizeof(struct xfs_dsb));
diff --git a/fs/xfs/xfs_aops.c b/fs/xfs/xfs_aops.c
index 1d8eef9cf0f5..a56960dd1684 100644
--- a/fs/xfs/xfs_aops.c
+++ b/fs/xfs/xfs_aops.c
@@ -1232,6 +1232,117 @@ xfs_vm_releasepage(
1232 return try_to_free_buffers(page); 1232 return try_to_free_buffers(page);
1233} 1233}
1234 1234
1235/*
1236 * When we map a DIO buffer, we may need to attach an ioend that describes the
1237 * type of write IO we are doing. This passes to the completion function the
1238 * operations it needs to perform. If the mapping is for an overwrite wholly
1239 * within the EOF then we don't need an ioend and so we don't allocate one.
1240 * This avoids the unnecessary overhead of allocating and freeing ioends for
1241 * workloads that don't require transactions on IO completion.
1242 *
1243 * If we get multiple mappings in a single IO, we might be mapping different
1244 * types. But because the direct IO can only have a single private pointer, we
1245 * need to ensure that:
1246 *
1247 * a) i) the ioend spans the entire region of unwritten mappings; or
1248 * ii) the ioend spans all the mappings that cross or are beyond EOF; and
1249 * b) if it contains unwritten extents, it is *permanently* marked as such
1250 *
1251 * We could do this by chaining ioends like buffered IO does, but we only
1252 * actually get one IO completion callback from the direct IO, and that spans
1253 * the entire IO regardless of how many mappings and IOs are needed to complete
1254 * the DIO. There is only going to be one reference to the ioend and its life
1255 * cycle is constrained by the DIO completion code. hence we don't need
1256 * reference counting here.
1257 */
1258static void
1259xfs_map_direct(
1260 struct inode *inode,
1261 struct buffer_head *bh_result,
1262 struct xfs_bmbt_irec *imap,
1263 xfs_off_t offset)
1264{
1265 struct xfs_ioend *ioend;
1266 xfs_off_t size = bh_result->b_size;
1267 int type;
1268
1269 if (ISUNWRITTEN(imap))
1270 type = XFS_IO_UNWRITTEN;
1271 else
1272 type = XFS_IO_OVERWRITE;
1273
1274 trace_xfs_gbmap_direct(XFS_I(inode), offset, size, type, imap);
1275
1276 if (bh_result->b_private) {
1277 ioend = bh_result->b_private;
1278 ASSERT(ioend->io_size > 0);
1279 ASSERT(offset >= ioend->io_offset);
1280 if (offset + size > ioend->io_offset + ioend->io_size)
1281 ioend->io_size = offset - ioend->io_offset + size;
1282
1283 if (type == XFS_IO_UNWRITTEN && type != ioend->io_type)
1284 ioend->io_type = XFS_IO_UNWRITTEN;
1285
1286 trace_xfs_gbmap_direct_update(XFS_I(inode), ioend->io_offset,
1287 ioend->io_size, ioend->io_type,
1288 imap);
1289 } else if (type == XFS_IO_UNWRITTEN ||
1290 offset + size > i_size_read(inode)) {
1291 ioend = xfs_alloc_ioend(inode, type);
1292 ioend->io_offset = offset;
1293 ioend->io_size = size;
1294
1295 bh_result->b_private = ioend;
1296 set_buffer_defer_completion(bh_result);
1297
1298 trace_xfs_gbmap_direct_new(XFS_I(inode), offset, size, type,
1299 imap);
1300 } else {
1301 trace_xfs_gbmap_direct_none(XFS_I(inode), offset, size, type,
1302 imap);
1303 }
1304}
1305
1306/*
1307 * If this is O_DIRECT or the mpage code calling tell them how large the mapping
1308 * is, so that we can avoid repeated get_blocks calls.
1309 *
1310 * If the mapping spans EOF, then we have to break the mapping up as the mapping
1311 * for blocks beyond EOF must be marked new so that sub block regions can be
1312 * correctly zeroed. We can't do this for mappings within EOF unless the mapping
1313 * was just allocated or is unwritten, otherwise the callers would overwrite
1314 * existing data with zeros. Hence we have to split the mapping into a range up
1315 * to and including EOF, and a second mapping for beyond EOF.
1316 */
1317static void
1318xfs_map_trim_size(
1319 struct inode *inode,
1320 sector_t iblock,
1321 struct buffer_head *bh_result,
1322 struct xfs_bmbt_irec *imap,
1323 xfs_off_t offset,
1324 ssize_t size)
1325{
1326 xfs_off_t mapping_size;
1327
1328 mapping_size = imap->br_startoff + imap->br_blockcount - iblock;
1329 mapping_size <<= inode->i_blkbits;
1330
1331 ASSERT(mapping_size > 0);
1332 if (mapping_size > size)
1333 mapping_size = size;
1334 if (offset < i_size_read(inode) &&
1335 offset + mapping_size >= i_size_read(inode)) {
1336 /* limit mapping to block that spans EOF */
1337 mapping_size = roundup_64(i_size_read(inode) - offset,
1338 1 << inode->i_blkbits);
1339 }
1340 if (mapping_size > LONG_MAX)
1341 mapping_size = LONG_MAX;
1342
1343 bh_result->b_size = mapping_size;
1344}
1345
1235STATIC int 1346STATIC int
1236__xfs_get_blocks( 1347__xfs_get_blocks(
1237 struct inode *inode, 1348 struct inode *inode,
@@ -1320,31 +1431,37 @@ __xfs_get_blocks(
1320 1431
1321 xfs_iunlock(ip, lockmode); 1432 xfs_iunlock(ip, lockmode);
1322 } 1433 }
1323 1434 trace_xfs_get_blocks_alloc(ip, offset, size,
1324 trace_xfs_get_blocks_alloc(ip, offset, size, 0, &imap); 1435 ISUNWRITTEN(&imap) ? XFS_IO_UNWRITTEN
1436 : XFS_IO_DELALLOC, &imap);
1325 } else if (nimaps) { 1437 } else if (nimaps) {
1326 trace_xfs_get_blocks_found(ip, offset, size, 0, &imap); 1438 trace_xfs_get_blocks_found(ip, offset, size,
1439 ISUNWRITTEN(&imap) ? XFS_IO_UNWRITTEN
1440 : XFS_IO_OVERWRITE, &imap);
1327 xfs_iunlock(ip, lockmode); 1441 xfs_iunlock(ip, lockmode);
1328 } else { 1442 } else {
1329 trace_xfs_get_blocks_notfound(ip, offset, size); 1443 trace_xfs_get_blocks_notfound(ip, offset, size);
1330 goto out_unlock; 1444 goto out_unlock;
1331 } 1445 }
1332 1446
1447 /* trim mapping down to size requested */
1448 if (direct || size > (1 << inode->i_blkbits))
1449 xfs_map_trim_size(inode, iblock, bh_result,
1450 &imap, offset, size);
1451
1452 /*
1453 * For unwritten extents do not report a disk address in the buffered
1454 * read case (treat as if we're reading into a hole).
1455 */
1333 if (imap.br_startblock != HOLESTARTBLOCK && 1456 if (imap.br_startblock != HOLESTARTBLOCK &&
1334 imap.br_startblock != DELAYSTARTBLOCK) { 1457 imap.br_startblock != DELAYSTARTBLOCK &&
1335 /* 1458 (create || !ISUNWRITTEN(&imap))) {
1336 * For unwritten extents do not report a disk address on 1459 xfs_map_buffer(inode, bh_result, &imap, offset);
1337 * the read case (treat as if we're reading into a hole). 1460 if (ISUNWRITTEN(&imap))
1338 */
1339 if (create || !ISUNWRITTEN(&imap))
1340 xfs_map_buffer(inode, bh_result, &imap, offset);
1341 if (create && ISUNWRITTEN(&imap)) {
1342 if (direct) {
1343 bh_result->b_private = inode;
1344 set_buffer_defer_completion(bh_result);
1345 }
1346 set_buffer_unwritten(bh_result); 1461 set_buffer_unwritten(bh_result);
1347 } 1462 /* direct IO needs special help */
1463 if (create && direct)
1464 xfs_map_direct(inode, bh_result, &imap, offset);
1348 } 1465 }
1349 1466
1350 /* 1467 /*
@@ -1377,39 +1494,6 @@ __xfs_get_blocks(
1377 } 1494 }
1378 } 1495 }
1379 1496
1380 /*
1381 * If this is O_DIRECT or the mpage code calling tell them how large
1382 * the mapping is, so that we can avoid repeated get_blocks calls.
1383 *
1384 * If the mapping spans EOF, then we have to break the mapping up as the
1385 * mapping for blocks beyond EOF must be marked new so that sub block
1386 * regions can be correctly zeroed. We can't do this for mappings within
1387 * EOF unless the mapping was just allocated or is unwritten, otherwise
1388 * the callers would overwrite existing data with zeros. Hence we have
1389 * to split the mapping into a range up to and including EOF, and a
1390 * second mapping for beyond EOF.
1391 */
1392 if (direct || size > (1 << inode->i_blkbits)) {
1393 xfs_off_t mapping_size;
1394
1395 mapping_size = imap.br_startoff + imap.br_blockcount - iblock;
1396 mapping_size <<= inode->i_blkbits;
1397
1398 ASSERT(mapping_size > 0);
1399 if (mapping_size > size)
1400 mapping_size = size;
1401 if (offset < i_size_read(inode) &&
1402 offset + mapping_size >= i_size_read(inode)) {
1403 /* limit mapping to block that spans EOF */
1404 mapping_size = roundup_64(i_size_read(inode) - offset,
1405 1 << inode->i_blkbits);
1406 }
1407 if (mapping_size > LONG_MAX)
1408 mapping_size = LONG_MAX;
1409
1410 bh_result->b_size = mapping_size;
1411 }
1412
1413 return 0; 1497 return 0;
1414 1498
1415out_unlock: 1499out_unlock:
@@ -1440,9 +1524,11 @@ xfs_get_blocks_direct(
1440/* 1524/*
1441 * Complete a direct I/O write request. 1525 * Complete a direct I/O write request.
1442 * 1526 *
1443 * If the private argument is non-NULL __xfs_get_blocks signals us that we 1527 * The ioend structure is passed from __xfs_get_blocks() to tell us what to do.
1444 * need to issue a transaction to convert the range from unwritten to written 1528 * If no ioend exists (i.e. @private == NULL) then the write IO is an overwrite
1445 * extents. 1529 * wholly within the EOF and so there is nothing for us to do. Note that in this
1530 * case the completion can be called in interrupt context, whereas if we have an
1531 * ioend we will always be called in task context (i.e. from a workqueue).
1446 */ 1532 */
1447STATIC void 1533STATIC void
1448xfs_end_io_direct_write( 1534xfs_end_io_direct_write(
@@ -1454,43 +1540,71 @@ xfs_end_io_direct_write(
1454 struct inode *inode = file_inode(iocb->ki_filp); 1540 struct inode *inode = file_inode(iocb->ki_filp);
1455 struct xfs_inode *ip = XFS_I(inode); 1541 struct xfs_inode *ip = XFS_I(inode);
1456 struct xfs_mount *mp = ip->i_mount; 1542 struct xfs_mount *mp = ip->i_mount;
1543 struct xfs_ioend *ioend = private;
1457 1544
1458 if (XFS_FORCED_SHUTDOWN(mp)) 1545 trace_xfs_gbmap_direct_endio(ip, offset, size,
1546 ioend ? ioend->io_type : 0, NULL);
1547
1548 if (!ioend) {
1549 ASSERT(offset + size <= i_size_read(inode));
1459 return; 1550 return;
1551 }
1552
1553 if (XFS_FORCED_SHUTDOWN(mp))
1554 goto out_end_io;
1460 1555
1461 /* 1556 /*
1462 * While the generic direct I/O code updates the inode size, it does 1557 * dio completion end_io functions are only called on writes if more
1463 * so only after the end_io handler is called, which means our 1558 * than 0 bytes was written.
1464 * end_io handler thinks the on-disk size is outside the in-core
1465 * size. To prevent this just update it a little bit earlier here.
1466 */ 1559 */
1560 ASSERT(size > 0);
1561
1562 /*
1563 * The ioend only maps whole blocks, while the IO may be sector aligned.
1564 * Hence the ioend offset/size may not match the IO offset/size exactly.
1565 * Because we don't map overwrites within EOF into the ioend, the offset
1566 * may not match, but only if the endio spans EOF. Either way, write
1567 * the IO sizes into the ioend so that completion processing does the
1568 * right thing.
1569 */
1570 ASSERT(offset + size <= ioend->io_offset + ioend->io_size);
1571 ioend->io_size = size;
1572 ioend->io_offset = offset;
1573
1574 /*
1575 * The ioend tells us whether we are doing unwritten extent conversion
1576 * or an append transaction that updates the on-disk file size. These
1577 * cases are the only cases where we should *potentially* be needing
1578 * to update the VFS inode size.
1579 *
1580 * We need to update the in-core inode size here so that we don't end up
1581 * with the on-disk inode size being outside the in-core inode size. We
1582 * have no other method of updating EOF for AIO, so always do it here
1583 * if necessary.
1584 *
1585 * We need to lock the test/set EOF update as we can be racing with
1586 * other IO completions here to update the EOF. Failing to serialise
1587 * here can result in EOF moving backwards and Bad Things Happen when
1588 * that occurs.
1589 */
1590 spin_lock(&ip->i_flags_lock);
1467 if (offset + size > i_size_read(inode)) 1591 if (offset + size > i_size_read(inode))
1468 i_size_write(inode, offset + size); 1592 i_size_write(inode, offset + size);
1593 spin_unlock(&ip->i_flags_lock);
1469 1594
1470 /* 1595 /*
1471 * For direct I/O we do not know if we need to allocate blocks or not, 1596 * If we are doing an append IO that needs to update the EOF on disk,
1472 * so we can't preallocate an append transaction, as that results in 1597 * do the transaction reserve now so we can use common end io
1473 * nested reservations and log space deadlocks. Hence allocate the 1598 * processing. Stashing the error (if there is one) in the ioend will
1474 * transaction here. While this is sub-optimal and can block IO 1599 * result in the ioend processing passing on the error if it is
1475 * completion for some time, we're stuck with doing it this way until 1600 * possible as we can't return it from here.
1476 * we can pass the ioend to the direct IO allocation callbacks and
1477 * avoid nesting that way.
1478 */ 1601 */
1479 if (private && size > 0) { 1602 if (ioend->io_type == XFS_IO_OVERWRITE)
1480 xfs_iomap_write_unwritten(ip, offset, size); 1603 ioend->io_error = xfs_setfilesize_trans_alloc(ioend);
1481 } else if (offset + size > ip->i_d.di_size) {
1482 struct xfs_trans *tp;
1483 int error;
1484
1485 tp = xfs_trans_alloc(mp, XFS_TRANS_FSYNC_TS);
1486 error = xfs_trans_reserve(tp, &M_RES(mp)->tr_fsyncts, 0, 0);
1487 if (error) {
1488 xfs_trans_cancel(tp, 0);
1489 return;
1490 }
1491 1604
1492 xfs_setfilesize(ip, tp, offset, size); 1605out_end_io:
1493 } 1606 xfs_end_io(&ioend->io_work);
1607 return;
1494} 1608}
1495 1609
1496STATIC ssize_t 1610STATIC ssize_t
diff --git a/fs/xfs/xfs_attr_inactive.c b/fs/xfs/xfs_attr_inactive.c
index 83af4c149635..f9c1c64782d3 100644
--- a/fs/xfs/xfs_attr_inactive.c
+++ b/fs/xfs/xfs_attr_inactive.c
@@ -132,9 +132,10 @@ xfs_attr3_leaf_inactive(
132 int size; 132 int size;
133 int tmp; 133 int tmp;
134 int i; 134 int i;
135 struct xfs_mount *mp = bp->b_target->bt_mount;
135 136
136 leaf = bp->b_addr; 137 leaf = bp->b_addr;
137 xfs_attr3_leaf_hdr_from_disk(&ichdr, leaf); 138 xfs_attr3_leaf_hdr_from_disk(mp->m_attr_geo, &ichdr, leaf);
138 139
139 /* 140 /*
140 * Count the number of "remote" value extents. 141 * Count the number of "remote" value extents.
diff --git a/fs/xfs/xfs_attr_list.c b/fs/xfs/xfs_attr_list.c
index a43d370d2c58..65fb37a18e92 100644
--- a/fs/xfs/xfs_attr_list.c
+++ b/fs/xfs/xfs_attr_list.c
@@ -225,6 +225,7 @@ xfs_attr_node_list(xfs_attr_list_context_t *context)
225 int error, i; 225 int error, i;
226 struct xfs_buf *bp; 226 struct xfs_buf *bp;
227 struct xfs_inode *dp = context->dp; 227 struct xfs_inode *dp = context->dp;
228 struct xfs_mount *mp = dp->i_mount;
228 229
229 trace_xfs_attr_node_list(context); 230 trace_xfs_attr_node_list(context);
230 231
@@ -256,7 +257,8 @@ xfs_attr_node_list(xfs_attr_list_context_t *context)
256 case XFS_ATTR_LEAF_MAGIC: 257 case XFS_ATTR_LEAF_MAGIC:
257 case XFS_ATTR3_LEAF_MAGIC: 258 case XFS_ATTR3_LEAF_MAGIC:
258 leaf = bp->b_addr; 259 leaf = bp->b_addr;
259 xfs_attr3_leaf_hdr_from_disk(&leafhdr, leaf); 260 xfs_attr3_leaf_hdr_from_disk(mp->m_attr_geo,
261 &leafhdr, leaf);
260 entries = xfs_attr3_leaf_entryp(leaf); 262 entries = xfs_attr3_leaf_entryp(leaf);
261 if (cursor->hashval > be32_to_cpu( 263 if (cursor->hashval > be32_to_cpu(
262 entries[leafhdr.count - 1].hashval)) { 264 entries[leafhdr.count - 1].hashval)) {
@@ -340,7 +342,7 @@ xfs_attr_node_list(xfs_attr_list_context_t *context)
340 xfs_trans_brelse(NULL, bp); 342 xfs_trans_brelse(NULL, bp);
341 return error; 343 return error;
342 } 344 }
343 xfs_attr3_leaf_hdr_from_disk(&leafhdr, leaf); 345 xfs_attr3_leaf_hdr_from_disk(mp->m_attr_geo, &leafhdr, leaf);
344 if (context->seen_enough || leafhdr.forw == 0) 346 if (context->seen_enough || leafhdr.forw == 0)
345 break; 347 break;
346 cursor->blkno = leafhdr.forw; 348 cursor->blkno = leafhdr.forw;
@@ -368,11 +370,12 @@ xfs_attr3_leaf_list_int(
368 struct xfs_attr_leaf_entry *entry; 370 struct xfs_attr_leaf_entry *entry;
369 int retval; 371 int retval;
370 int i; 372 int i;
373 struct xfs_mount *mp = context->dp->i_mount;
371 374
372 trace_xfs_attr_list_leaf(context); 375 trace_xfs_attr_list_leaf(context);
373 376
374 leaf = bp->b_addr; 377 leaf = bp->b_addr;
375 xfs_attr3_leaf_hdr_from_disk(&ichdr, leaf); 378 xfs_attr3_leaf_hdr_from_disk(mp->m_attr_geo, &ichdr, leaf);
376 entries = xfs_attr3_leaf_entryp(leaf); 379 entries = xfs_attr3_leaf_entryp(leaf);
377 380
378 cursor = context->cursor; 381 cursor = context->cursor;
diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c
index 22a5dcb70b32..a52bbd3abc7d 100644
--- a/fs/xfs/xfs_bmap_util.c
+++ b/fs/xfs/xfs_bmap_util.c
@@ -1376,22 +1376,19 @@ out:
1376} 1376}
1377 1377
1378/* 1378/*
1379 * xfs_collapse_file_space() 1379 * @next_fsb will keep track of the extent currently undergoing shift.
1380 * This routine frees disk space and shift extent for the given file. 1380 * @stop_fsb will keep track of the extent at which we have to stop.
1381 * The first thing we do is to free data blocks in the specified range 1381 * If we are shifting left, we will start with block (offset + len) and
1382 * by calling xfs_free_file_space(). It would also sync dirty data 1382 * shift each extent till last extent.
1383 * and invalidate page cache over the region on which collapse range 1383 * If we are shifting right, we will start with last extent inside file space
1384 * is working. And Shift extent records to the left to cover a hole. 1384 * and continue until we reach the block corresponding to offset.
1385 * RETURNS:
1386 * 0 on success
1387 * errno on error
1388 *
1389 */ 1385 */
1390int 1386static int
1391xfs_collapse_file_space( 1387xfs_shift_file_space(
1392 struct xfs_inode *ip, 1388 struct xfs_inode *ip,
1393 xfs_off_t offset, 1389 xfs_off_t offset,
1394 xfs_off_t len) 1390 xfs_off_t len,
1391 enum shift_direction direction)
1395{ 1392{
1396 int done = 0; 1393 int done = 0;
1397 struct xfs_mount *mp = ip->i_mount; 1394 struct xfs_mount *mp = ip->i_mount;
@@ -1400,21 +1397,26 @@ xfs_collapse_file_space(
1400 struct xfs_bmap_free free_list; 1397 struct xfs_bmap_free free_list;
1401 xfs_fsblock_t first_block; 1398 xfs_fsblock_t first_block;
1402 int committed; 1399 int committed;
1403 xfs_fileoff_t start_fsb; 1400 xfs_fileoff_t stop_fsb;
1404 xfs_fileoff_t next_fsb; 1401 xfs_fileoff_t next_fsb;
1405 xfs_fileoff_t shift_fsb; 1402 xfs_fileoff_t shift_fsb;
1406 1403
1407 ASSERT(xfs_isilocked(ip, XFS_IOLOCK_EXCL)); 1404 ASSERT(direction == SHIFT_LEFT || direction == SHIFT_RIGHT);
1408 1405
1409 trace_xfs_collapse_file_space(ip); 1406 if (direction == SHIFT_LEFT) {
1407 next_fsb = XFS_B_TO_FSB(mp, offset + len);
1408 stop_fsb = XFS_B_TO_FSB(mp, VFS_I(ip)->i_size);
1409 } else {
1410 /*
1411 * If right shift, delegate the work of initialization of
1412 * next_fsb to xfs_bmap_shift_extent as it has ilock held.
1413 */
1414 next_fsb = NULLFSBLOCK;
1415 stop_fsb = XFS_B_TO_FSB(mp, offset);
1416 }
1410 1417
1411 next_fsb = XFS_B_TO_FSB(mp, offset + len);
1412 shift_fsb = XFS_B_TO_FSB(mp, len); 1418 shift_fsb = XFS_B_TO_FSB(mp, len);
1413 1419
1414 error = xfs_free_file_space(ip, offset, len);
1415 if (error)
1416 return error;
1417
1418 /* 1420 /*
1419 * Trim eofblocks to avoid shifting uninitialized post-eof preallocation 1421 * Trim eofblocks to avoid shifting uninitialized post-eof preallocation
1420 * into the accessible region of the file. 1422 * into the accessible region of the file.
@@ -1427,20 +1429,28 @@ xfs_collapse_file_space(
1427 1429
1428 /* 1430 /*
1429 * Writeback and invalidate cache for the remainder of the file as we're 1431 * Writeback and invalidate cache for the remainder of the file as we're
1430 * about to shift down every extent from the collapse range to EOF. The 1432 * about to shift down every extent from offset to EOF.
1431 * free of the collapse range above might have already done some of
1432 * this, but we shouldn't rely on it to do anything outside of the range
1433 * that was freed.
1434 */ 1433 */
1435 error = filemap_write_and_wait_range(VFS_I(ip)->i_mapping, 1434 error = filemap_write_and_wait_range(VFS_I(ip)->i_mapping,
1436 offset + len, -1); 1435 offset, -1);
1437 if (error) 1436 if (error)
1438 return error; 1437 return error;
1439 error = invalidate_inode_pages2_range(VFS_I(ip)->i_mapping, 1438 error = invalidate_inode_pages2_range(VFS_I(ip)->i_mapping,
1440 (offset + len) >> PAGE_CACHE_SHIFT, -1); 1439 offset >> PAGE_CACHE_SHIFT, -1);
1441 if (error) 1440 if (error)
1442 return error; 1441 return error;
1443 1442
1443 /*
1444 * The extent shiting code works on extent granularity. So, if
1445 * stop_fsb is not the starting block of extent, we need to split
1446 * the extent at stop_fsb.
1447 */
1448 if (direction == SHIFT_RIGHT) {
1449 error = xfs_bmap_split_extent(ip, stop_fsb);
1450 if (error)
1451 return error;
1452 }
1453
1444 while (!error && !done) { 1454 while (!error && !done) {
1445 tp = xfs_trans_alloc(mp, XFS_TRANS_DIOSTRAT); 1455 tp = xfs_trans_alloc(mp, XFS_TRANS_DIOSTRAT);
1446 /* 1456 /*
@@ -1464,7 +1474,7 @@ xfs_collapse_file_space(
1464 if (error) 1474 if (error)
1465 goto out; 1475 goto out;
1466 1476
1467 xfs_trans_ijoin(tp, ip, 0); 1477 xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
1468 1478
1469 xfs_bmap_init(&free_list, &first_block); 1479 xfs_bmap_init(&free_list, &first_block);
1470 1480
@@ -1472,10 +1482,9 @@ xfs_collapse_file_space(
1472 * We are using the write transaction in which max 2 bmbt 1482 * We are using the write transaction in which max 2 bmbt
1473 * updates are allowed 1483 * updates are allowed
1474 */ 1484 */
1475 start_fsb = next_fsb; 1485 error = xfs_bmap_shift_extents(tp, ip, &next_fsb, shift_fsb,
1476 error = xfs_bmap_shift_extents(tp, ip, start_fsb, shift_fsb, 1486 &done, stop_fsb, &first_block, &free_list,
1477 &done, &next_fsb, &first_block, &free_list, 1487 direction, XFS_BMAP_MAX_SHIFT_EXTENTS);
1478 XFS_BMAP_MAX_SHIFT_EXTENTS);
1479 if (error) 1488 if (error)
1480 goto out; 1489 goto out;
1481 1490
@@ -1484,18 +1493,70 @@ xfs_collapse_file_space(
1484 goto out; 1493 goto out;
1485 1494
1486 error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES); 1495 error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES);
1487 xfs_iunlock(ip, XFS_ILOCK_EXCL);
1488 } 1496 }
1489 1497
1490 return error; 1498 return error;
1491 1499
1492out: 1500out:
1493 xfs_trans_cancel(tp, XFS_TRANS_RELEASE_LOG_RES | XFS_TRANS_ABORT); 1501 xfs_trans_cancel(tp, XFS_TRANS_RELEASE_LOG_RES | XFS_TRANS_ABORT);
1494 xfs_iunlock(ip, XFS_ILOCK_EXCL);
1495 return error; 1502 return error;
1496} 1503}
1497 1504
1498/* 1505/*
1506 * xfs_collapse_file_space()
1507 * This routine frees disk space and shift extent for the given file.
1508 * The first thing we do is to free data blocks in the specified range
1509 * by calling xfs_free_file_space(). It would also sync dirty data
1510 * and invalidate page cache over the region on which collapse range
1511 * is working. And Shift extent records to the left to cover a hole.
1512 * RETURNS:
1513 * 0 on success
1514 * errno on error
1515 *
1516 */
1517int
1518xfs_collapse_file_space(
1519 struct xfs_inode *ip,
1520 xfs_off_t offset,
1521 xfs_off_t len)
1522{
1523 int error;
1524
1525 ASSERT(xfs_isilocked(ip, XFS_IOLOCK_EXCL));
1526 trace_xfs_collapse_file_space(ip);
1527
1528 error = xfs_free_file_space(ip, offset, len);
1529 if (error)
1530 return error;
1531
1532 return xfs_shift_file_space(ip, offset, len, SHIFT_LEFT);
1533}
1534
1535/*
1536 * xfs_insert_file_space()
1537 * This routine create hole space by shifting extents for the given file.
1538 * The first thing we do is to sync dirty data and invalidate page cache
1539 * over the region on which insert range is working. And split an extent
1540 * to two extents at given offset by calling xfs_bmap_split_extent.
1541 * And shift all extent records which are laying between [offset,
1542 * last allocated extent] to the right to reserve hole range.
1543 * RETURNS:
1544 * 0 on success
1545 * errno on error
1546 */
1547int
1548xfs_insert_file_space(
1549 struct xfs_inode *ip,
1550 loff_t offset,
1551 loff_t len)
1552{
1553 ASSERT(xfs_isilocked(ip, XFS_IOLOCK_EXCL));
1554 trace_xfs_insert_file_space(ip);
1555
1556 return xfs_shift_file_space(ip, offset, len, SHIFT_RIGHT);
1557}
1558
1559/*
1499 * We need to check that the format of the data fork in the temporary inode is 1560 * We need to check that the format of the data fork in the temporary inode is
1500 * valid for the target inode before doing the swap. This is not a problem with 1561 * valid for the target inode before doing the swap. This is not a problem with
1501 * attr1 because of the fixed fork offset, but attr2 has a dynamically sized 1562 * attr1 because of the fixed fork offset, but attr2 has a dynamically sized
@@ -1599,13 +1660,6 @@ xfs_swap_extent_flush(
1599 /* Verify O_DIRECT for ftmp */ 1660 /* Verify O_DIRECT for ftmp */
1600 if (VFS_I(ip)->i_mapping->nrpages) 1661 if (VFS_I(ip)->i_mapping->nrpages)
1601 return -EINVAL; 1662 return -EINVAL;
1602
1603 /*
1604 * Don't try to swap extents on mmap()d files because we can't lock
1605 * out races against page faults safely.
1606 */
1607 if (mapping_mapped(VFS_I(ip)->i_mapping))
1608 return -EBUSY;
1609 return 0; 1663 return 0;
1610} 1664}
1611 1665
@@ -1633,13 +1687,14 @@ xfs_swap_extents(
1633 } 1687 }
1634 1688
1635 /* 1689 /*
1636 * Lock up the inodes against other IO and truncate to begin with. 1690 * Lock the inodes against other IO, page faults and truncate to
1637 * Then we can ensure the inodes are flushed and have no page cache 1691 * begin with. Then we can ensure the inodes are flushed and have no
1638 * safely. Once we have done this we can take the ilocks and do the rest 1692 * page cache safely. Once we have done this we can take the ilocks and
1639 * of the checks. 1693 * do the rest of the checks.
1640 */ 1694 */
1641 lock_flags = XFS_IOLOCK_EXCL; 1695 lock_flags = XFS_IOLOCK_EXCL | XFS_MMAPLOCK_EXCL;
1642 xfs_lock_two_inodes(ip, tip, XFS_IOLOCK_EXCL); 1696 xfs_lock_two_inodes(ip, tip, XFS_IOLOCK_EXCL);
1697 xfs_lock_two_inodes(ip, tip, XFS_MMAPLOCK_EXCL);
1643 1698
1644 /* Verify that both files have the same format */ 1699 /* Verify that both files have the same format */
1645 if ((ip->i_d.di_mode & S_IFMT) != (tip->i_d.di_mode & S_IFMT)) { 1700 if ((ip->i_d.di_mode & S_IFMT) != (tip->i_d.di_mode & S_IFMT)) {
@@ -1666,8 +1721,16 @@ xfs_swap_extents(
1666 xfs_trans_cancel(tp, 0); 1721 xfs_trans_cancel(tp, 0);
1667 goto out_unlock; 1722 goto out_unlock;
1668 } 1723 }
1724
1725 /*
1726 * Lock and join the inodes to the tansaction so that transaction commit
1727 * or cancel will unlock the inodes from this point onwards.
1728 */
1669 xfs_lock_two_inodes(ip, tip, XFS_ILOCK_EXCL); 1729 xfs_lock_two_inodes(ip, tip, XFS_ILOCK_EXCL);
1670 lock_flags |= XFS_ILOCK_EXCL; 1730 lock_flags |= XFS_ILOCK_EXCL;
1731 xfs_trans_ijoin(tp, ip, lock_flags);
1732 xfs_trans_ijoin(tp, tip, lock_flags);
1733
1671 1734
1672 /* Verify all data are being swapped */ 1735 /* Verify all data are being swapped */
1673 if (sxp->sx_offset != 0 || 1736 if (sxp->sx_offset != 0 ||
@@ -1720,9 +1783,6 @@ xfs_swap_extents(
1720 goto out_trans_cancel; 1783 goto out_trans_cancel;
1721 } 1784 }
1722 1785
1723 xfs_trans_ijoin(tp, ip, lock_flags);
1724 xfs_trans_ijoin(tp, tip, lock_flags);
1725
1726 /* 1786 /*
1727 * Before we've swapped the forks, lets set the owners of the forks 1787 * Before we've swapped the forks, lets set the owners of the forks
1728 * appropriately. We have to do this as we are demand paging the btree 1788 * appropriately. We have to do this as we are demand paging the btree
@@ -1856,5 +1916,5 @@ out_unlock:
1856 1916
1857out_trans_cancel: 1917out_trans_cancel:
1858 xfs_trans_cancel(tp, 0); 1918 xfs_trans_cancel(tp, 0);
1859 goto out_unlock; 1919 goto out;
1860} 1920}
diff --git a/fs/xfs/xfs_bmap_util.h b/fs/xfs/xfs_bmap_util.h
index 736429a72a12..af97d9a1dfb4 100644
--- a/fs/xfs/xfs_bmap_util.h
+++ b/fs/xfs/xfs_bmap_util.h
@@ -63,6 +63,8 @@ int xfs_zero_file_space(struct xfs_inode *ip, xfs_off_t offset,
63 xfs_off_t len); 63 xfs_off_t len);
64int xfs_collapse_file_space(struct xfs_inode *, xfs_off_t offset, 64int xfs_collapse_file_space(struct xfs_inode *, xfs_off_t offset,
65 xfs_off_t len); 65 xfs_off_t len);
66int xfs_insert_file_space(struct xfs_inode *, xfs_off_t offset,
67 xfs_off_t len);
66 68
67/* EOF block manipulation functions */ 69/* EOF block manipulation functions */
68bool xfs_can_free_eofblocks(struct xfs_inode *ip, bool force); 70bool xfs_can_free_eofblocks(struct xfs_inode *ip, bool force);
diff --git a/fs/xfs/xfs_buf_item.c b/fs/xfs/xfs_buf_item.c
index 507d96a57ac7..092d652bc03d 100644
--- a/fs/xfs/xfs_buf_item.c
+++ b/fs/xfs/xfs_buf_item.c
@@ -537,9 +537,9 @@ xfs_buf_item_push(
537 537
538 /* has a previous flush failed due to IO errors? */ 538 /* has a previous flush failed due to IO errors? */
539 if ((bp->b_flags & XBF_WRITE_FAIL) && 539 if ((bp->b_flags & XBF_WRITE_FAIL) &&
540 ___ratelimit(&xfs_buf_write_fail_rl_state, "XFS:")) { 540 ___ratelimit(&xfs_buf_write_fail_rl_state, "XFS: Failing async write")) {
541 xfs_warn(bp->b_target->bt_mount, 541 xfs_warn(bp->b_target->bt_mount,
542"Detected failing async write on buffer block 0x%llx. Retrying async write.", 542"Failing async write on buffer block 0x%llx. Retrying async write.",
543 (long long)bp->b_bn); 543 (long long)bp->b_bn);
544 } 544 }
545 545
diff --git a/fs/xfs/xfs_discard.c b/fs/xfs/xfs_discard.c
index 799e5a2d334d..e85a9519a5ae 100644
--- a/fs/xfs/xfs_discard.c
+++ b/fs/xfs/xfs_discard.c
@@ -84,7 +84,7 @@ xfs_trim_extents(
84 error = xfs_alloc_get_rec(cur, &fbno, &flen, &i); 84 error = xfs_alloc_get_rec(cur, &fbno, &flen, &i);
85 if (error) 85 if (error)
86 goto out_del_cursor; 86 goto out_del_cursor;
87 XFS_WANT_CORRUPTED_GOTO(i == 1, out_del_cursor); 87 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, out_del_cursor);
88 ASSERT(flen <= be32_to_cpu(XFS_BUF_TO_AGF(agbp)->agf_longest)); 88 ASSERT(flen <= be32_to_cpu(XFS_BUF_TO_AGF(agbp)->agf_longest));
89 89
90 /* 90 /*
diff --git a/fs/xfs/xfs_error.c b/fs/xfs/xfs_error.c
index 3ee186ac1093..338e50bbfd1e 100644
--- a/fs/xfs/xfs_error.c
+++ b/fs/xfs/xfs_error.c
@@ -131,7 +131,7 @@ xfs_error_report(
131{ 131{
132 if (level <= xfs_error_level) { 132 if (level <= xfs_error_level) {
133 xfs_alert_tag(mp, XFS_PTAG_ERROR_REPORT, 133 xfs_alert_tag(mp, XFS_PTAG_ERROR_REPORT,
134 "Internal error %s at line %d of file %s. Caller %pF", 134 "Internal error %s at line %d of file %s. Caller %pS",
135 tag, linenum, filename, ra); 135 tag, linenum, filename, ra);
136 136
137 xfs_stack_trace(); 137 xfs_stack_trace();
diff --git a/fs/xfs/xfs_error.h b/fs/xfs/xfs_error.h
index 279a76e52791..c0394ed126fc 100644
--- a/fs/xfs/xfs_error.h
+++ b/fs/xfs/xfs_error.h
@@ -40,25 +40,25 @@ extern void xfs_verifier_error(struct xfs_buf *bp);
40/* 40/*
41 * Macros to set EFSCORRUPTED & return/branch. 41 * Macros to set EFSCORRUPTED & return/branch.
42 */ 42 */
43#define XFS_WANT_CORRUPTED_GOTO(x,l) \ 43#define XFS_WANT_CORRUPTED_GOTO(mp, x, l) \
44 { \ 44 { \
45 int fs_is_ok = (x); \ 45 int fs_is_ok = (x); \
46 ASSERT(fs_is_ok); \ 46 ASSERT(fs_is_ok); \
47 if (unlikely(!fs_is_ok)) { \ 47 if (unlikely(!fs_is_ok)) { \
48 XFS_ERROR_REPORT("XFS_WANT_CORRUPTED_GOTO", \ 48 XFS_ERROR_REPORT("XFS_WANT_CORRUPTED_GOTO", \
49 XFS_ERRLEVEL_LOW, NULL); \ 49 XFS_ERRLEVEL_LOW, mp); \
50 error = -EFSCORRUPTED; \ 50 error = -EFSCORRUPTED; \
51 goto l; \ 51 goto l; \
52 } \ 52 } \
53 } 53 }
54 54
55#define XFS_WANT_CORRUPTED_RETURN(x) \ 55#define XFS_WANT_CORRUPTED_RETURN(mp, x) \
56 { \ 56 { \
57 int fs_is_ok = (x); \ 57 int fs_is_ok = (x); \
58 ASSERT(fs_is_ok); \ 58 ASSERT(fs_is_ok); \
59 if (unlikely(!fs_is_ok)) { \ 59 if (unlikely(!fs_is_ok)) { \
60 XFS_ERROR_REPORT("XFS_WANT_CORRUPTED_RETURN", \ 60 XFS_ERROR_REPORT("XFS_WANT_CORRUPTED_RETURN", \
61 XFS_ERRLEVEL_LOW, NULL); \ 61 XFS_ERRLEVEL_LOW, mp); \
62 return -EFSCORRUPTED; \ 62 return -EFSCORRUPTED; \
63 } \ 63 } \
64 } 64 }
diff --git a/fs/xfs/xfs_export.c b/fs/xfs/xfs_export.c
index b97359ba2648..652cd3c5b58c 100644
--- a/fs/xfs/xfs_export.c
+++ b/fs/xfs/xfs_export.c
@@ -215,7 +215,7 @@ xfs_fs_get_parent(
215 int error; 215 int error;
216 struct xfs_inode *cip; 216 struct xfs_inode *cip;
217 217
218 error = xfs_lookup(XFS_I(child->d_inode), &xfs_name_dotdot, &cip, NULL); 218 error = xfs_lookup(XFS_I(d_inode(child)), &xfs_name_dotdot, &cip, NULL);
219 if (unlikely(error)) 219 if (unlikely(error))
220 return ERR_PTR(error); 220 return ERR_PTR(error);
221 221
diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c
index 1f12ad0a8585..8121e75352ee 100644
--- a/fs/xfs/xfs_file.c
+++ b/fs/xfs/xfs_file.c
@@ -559,7 +559,7 @@ restart:
559 if (error <= 0) 559 if (error <= 0)
560 return error; 560 return error;
561 561
562 error = xfs_break_layouts(inode, iolock); 562 error = xfs_break_layouts(inode, iolock, true);
563 if (error) 563 if (error)
564 return error; 564 return error;
565 565
@@ -569,21 +569,42 @@ restart:
569 * write. If zeroing is needed and we are currently holding the 569 * write. If zeroing is needed and we are currently holding the
570 * iolock shared, we need to update it to exclusive which implies 570 * iolock shared, we need to update it to exclusive which implies
571 * having to redo all checks before. 571 * having to redo all checks before.
572 *
573 * We need to serialise against EOF updates that occur in IO
574 * completions here. We want to make sure that nobody is changing the
575 * size while we do this check until we have placed an IO barrier (i.e.
576 * hold the XFS_IOLOCK_EXCL) that prevents new IO from being dispatched.
577 * The spinlock effectively forms a memory barrier once we have the
578 * XFS_IOLOCK_EXCL so we are guaranteed to see the latest EOF value
579 * and hence be able to correctly determine if we need to run zeroing.
572 */ 580 */
581 spin_lock(&ip->i_flags_lock);
573 if (iocb->ki_pos > i_size_read(inode)) { 582 if (iocb->ki_pos > i_size_read(inode)) {
574 bool zero = false; 583 bool zero = false;
575 584
585 spin_unlock(&ip->i_flags_lock);
576 if (*iolock == XFS_IOLOCK_SHARED) { 586 if (*iolock == XFS_IOLOCK_SHARED) {
577 xfs_rw_iunlock(ip, *iolock); 587 xfs_rw_iunlock(ip, *iolock);
578 *iolock = XFS_IOLOCK_EXCL; 588 *iolock = XFS_IOLOCK_EXCL;
579 xfs_rw_ilock(ip, *iolock); 589 xfs_rw_ilock(ip, *iolock);
580 iov_iter_reexpand(from, count); 590 iov_iter_reexpand(from, count);
591
592 /*
593 * We now have an IO submission barrier in place, but
594 * AIO can do EOF updates during IO completion and hence
595 * we now need to wait for all of them to drain. Non-AIO
596 * DIO will have drained before we are given the
597 * XFS_IOLOCK_EXCL, and so for most cases this wait is a
598 * no-op.
599 */
600 inode_dio_wait(inode);
581 goto restart; 601 goto restart;
582 } 602 }
583 error = xfs_zero_eof(ip, iocb->ki_pos, i_size_read(inode), &zero); 603 error = xfs_zero_eof(ip, iocb->ki_pos, i_size_read(inode), &zero);
584 if (error) 604 if (error)
585 return error; 605 return error;
586 } 606 } else
607 spin_unlock(&ip->i_flags_lock);
587 608
588 /* 609 /*
589 * Updating the timestamps will grab the ilock again from 610 * Updating the timestamps will grab the ilock again from
@@ -645,6 +666,8 @@ xfs_file_dio_aio_write(
645 int iolock; 666 int iolock;
646 size_t count = iov_iter_count(from); 667 size_t count = iov_iter_count(from);
647 loff_t pos = iocb->ki_pos; 668 loff_t pos = iocb->ki_pos;
669 loff_t end;
670 struct iov_iter data;
648 struct xfs_buftarg *target = XFS_IS_REALTIME_INODE(ip) ? 671 struct xfs_buftarg *target = XFS_IS_REALTIME_INODE(ip) ?
649 mp->m_rtdev_targp : mp->m_ddev_targp; 672 mp->m_rtdev_targp : mp->m_ddev_targp;
650 673
@@ -685,10 +708,11 @@ xfs_file_dio_aio_write(
685 goto out; 708 goto out;
686 count = iov_iter_count(from); 709 count = iov_iter_count(from);
687 pos = iocb->ki_pos; 710 pos = iocb->ki_pos;
711 end = pos + count - 1;
688 712
689 if (mapping->nrpages) { 713 if (mapping->nrpages) {
690 ret = filemap_write_and_wait_range(VFS_I(ip)->i_mapping, 714 ret = filemap_write_and_wait_range(VFS_I(ip)->i_mapping,
691 pos, pos + count - 1); 715 pos, end);
692 if (ret) 716 if (ret)
693 goto out; 717 goto out;
694 /* 718 /*
@@ -698,7 +722,7 @@ xfs_file_dio_aio_write(
698 */ 722 */
699 ret = invalidate_inode_pages2_range(VFS_I(ip)->i_mapping, 723 ret = invalidate_inode_pages2_range(VFS_I(ip)->i_mapping,
700 pos >> PAGE_CACHE_SHIFT, 724 pos >> PAGE_CACHE_SHIFT,
701 (pos + count - 1) >> PAGE_CACHE_SHIFT); 725 end >> PAGE_CACHE_SHIFT);
702 WARN_ON_ONCE(ret); 726 WARN_ON_ONCE(ret);
703 ret = 0; 727 ret = 0;
704 } 728 }
@@ -715,8 +739,22 @@ xfs_file_dio_aio_write(
715 } 739 }
716 740
717 trace_xfs_file_direct_write(ip, count, iocb->ki_pos, 0); 741 trace_xfs_file_direct_write(ip, count, iocb->ki_pos, 0);
718 ret = generic_file_direct_write(iocb, from, pos);
719 742
743 data = *from;
744 ret = mapping->a_ops->direct_IO(iocb, &data, pos);
745
746 /* see generic_file_direct_write() for why this is necessary */
747 if (mapping->nrpages) {
748 invalidate_inode_pages2_range(mapping,
749 pos >> PAGE_CACHE_SHIFT,
750 end >> PAGE_CACHE_SHIFT);
751 }
752
753 if (ret > 0) {
754 pos += ret;
755 iov_iter_advance(from, ret);
756 iocb->ki_pos = pos;
757 }
720out: 758out:
721 xfs_rw_iunlock(ip, iolock); 759 xfs_rw_iunlock(ip, iolock);
722 760
@@ -822,6 +860,11 @@ xfs_file_write_iter(
822 return ret; 860 return ret;
823} 861}
824 862
863#define XFS_FALLOC_FL_SUPPORTED \
864 (FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE | \
865 FALLOC_FL_COLLAPSE_RANGE | FALLOC_FL_ZERO_RANGE | \
866 FALLOC_FL_INSERT_RANGE)
867
825STATIC long 868STATIC long
826xfs_file_fallocate( 869xfs_file_fallocate(
827 struct file *file, 870 struct file *file,
@@ -835,18 +878,21 @@ xfs_file_fallocate(
835 enum xfs_prealloc_flags flags = 0; 878 enum xfs_prealloc_flags flags = 0;
836 uint iolock = XFS_IOLOCK_EXCL; 879 uint iolock = XFS_IOLOCK_EXCL;
837 loff_t new_size = 0; 880 loff_t new_size = 0;
881 bool do_file_insert = 0;
838 882
839 if (!S_ISREG(inode->i_mode)) 883 if (!S_ISREG(inode->i_mode))
840 return -EINVAL; 884 return -EINVAL;
841 if (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE | 885 if (mode & ~XFS_FALLOC_FL_SUPPORTED)
842 FALLOC_FL_COLLAPSE_RANGE | FALLOC_FL_ZERO_RANGE))
843 return -EOPNOTSUPP; 886 return -EOPNOTSUPP;
844 887
845 xfs_ilock(ip, iolock); 888 xfs_ilock(ip, iolock);
846 error = xfs_break_layouts(inode, &iolock); 889 error = xfs_break_layouts(inode, &iolock, false);
847 if (error) 890 if (error)
848 goto out_unlock; 891 goto out_unlock;
849 892
893 xfs_ilock(ip, XFS_MMAPLOCK_EXCL);
894 iolock |= XFS_MMAPLOCK_EXCL;
895
850 if (mode & FALLOC_FL_PUNCH_HOLE) { 896 if (mode & FALLOC_FL_PUNCH_HOLE) {
851 error = xfs_free_file_space(ip, offset, len); 897 error = xfs_free_file_space(ip, offset, len);
852 if (error) 898 if (error)
@@ -873,6 +919,27 @@ xfs_file_fallocate(
873 error = xfs_collapse_file_space(ip, offset, len); 919 error = xfs_collapse_file_space(ip, offset, len);
874 if (error) 920 if (error)
875 goto out_unlock; 921 goto out_unlock;
922 } else if (mode & FALLOC_FL_INSERT_RANGE) {
923 unsigned blksize_mask = (1 << inode->i_blkbits) - 1;
924
925 new_size = i_size_read(inode) + len;
926 if (offset & blksize_mask || len & blksize_mask) {
927 error = -EINVAL;
928 goto out_unlock;
929 }
930
931 /* check the new inode size does not wrap through zero */
932 if (new_size > inode->i_sb->s_maxbytes) {
933 error = -EFBIG;
934 goto out_unlock;
935 }
936
937 /* Offset should be less than i_size */
938 if (offset >= i_size_read(inode)) {
939 error = -EINVAL;
940 goto out_unlock;
941 }
942 do_file_insert = 1;
876 } else { 943 } else {
877 flags |= XFS_PREALLOC_SET; 944 flags |= XFS_PREALLOC_SET;
878 945
@@ -907,8 +974,19 @@ xfs_file_fallocate(
907 iattr.ia_valid = ATTR_SIZE; 974 iattr.ia_valid = ATTR_SIZE;
908 iattr.ia_size = new_size; 975 iattr.ia_size = new_size;
909 error = xfs_setattr_size(ip, &iattr); 976 error = xfs_setattr_size(ip, &iattr);
977 if (error)
978 goto out_unlock;
910 } 979 }
911 980
981 /*
982 * Perform hole insertion now that the file size has been
983 * updated so that if we crash during the operation we don't
984 * leave shifted extents past EOF and hence losing access to
985 * the data that is contained within them.
986 */
987 if (do_file_insert)
988 error = xfs_insert_file_space(ip, offset, len);
989
912out_unlock: 990out_unlock:
913 xfs_iunlock(ip, iolock); 991 xfs_iunlock(ip, iolock);
914 return error; 992 return error;
@@ -997,20 +1075,6 @@ xfs_file_mmap(
997} 1075}
998 1076
999/* 1077/*
1000 * mmap()d file has taken write protection fault and is being made
1001 * writable. We can set the page state up correctly for a writable
1002 * page, which means we can do correct delalloc accounting (ENOSPC
1003 * checking!) and unwritten extent mapping.
1004 */
1005STATIC int
1006xfs_vm_page_mkwrite(
1007 struct vm_area_struct *vma,
1008 struct vm_fault *vmf)
1009{
1010 return block_page_mkwrite(vma, vmf, xfs_get_blocks);
1011}
1012
1013/*
1014 * This type is designed to indicate the type of offset we would like 1078 * This type is designed to indicate the type of offset we would like
1015 * to search from page cache for xfs_seek_hole_data(). 1079 * to search from page cache for xfs_seek_hole_data().
1016 */ 1080 */
@@ -1385,6 +1449,55 @@ xfs_file_llseek(
1385 } 1449 }
1386} 1450}
1387 1451
1452/*
1453 * Locking for serialisation of IO during page faults. This results in a lock
1454 * ordering of:
1455 *
1456 * mmap_sem (MM)
1457 * i_mmap_lock (XFS - truncate serialisation)
1458 * page_lock (MM)
1459 * i_lock (XFS - extent map serialisation)
1460 */
1461STATIC int
1462xfs_filemap_fault(
1463 struct vm_area_struct *vma,
1464 struct vm_fault *vmf)
1465{
1466 struct xfs_inode *ip = XFS_I(vma->vm_file->f_mapping->host);
1467 int error;
1468
1469 trace_xfs_filemap_fault(ip);
1470
1471 xfs_ilock(ip, XFS_MMAPLOCK_SHARED);
1472 error = filemap_fault(vma, vmf);
1473 xfs_iunlock(ip, XFS_MMAPLOCK_SHARED);
1474
1475 return error;
1476}
1477
1478/*
1479 * mmap()d file has taken write protection fault and is being made writable. We
1480 * can set the page state up correctly for a writable page, which means we can
1481 * do correct delalloc accounting (ENOSPC checking!) and unwritten extent
1482 * mapping.
1483 */
1484STATIC int
1485xfs_filemap_page_mkwrite(
1486 struct vm_area_struct *vma,
1487 struct vm_fault *vmf)
1488{
1489 struct xfs_inode *ip = XFS_I(vma->vm_file->f_mapping->host);
1490 int error;
1491
1492 trace_xfs_filemap_page_mkwrite(ip);
1493
1494 xfs_ilock(ip, XFS_MMAPLOCK_SHARED);
1495 error = block_page_mkwrite(vma, vmf, xfs_get_blocks);
1496 xfs_iunlock(ip, XFS_MMAPLOCK_SHARED);
1497
1498 return error;
1499}
1500
1388const struct file_operations xfs_file_operations = { 1501const struct file_operations xfs_file_operations = {
1389 .llseek = xfs_file_llseek, 1502 .llseek = xfs_file_llseek,
1390 .read_iter = xfs_file_read_iter, 1503 .read_iter = xfs_file_read_iter,
@@ -1415,7 +1528,7 @@ const struct file_operations xfs_dir_file_operations = {
1415}; 1528};
1416 1529
1417static const struct vm_operations_struct xfs_file_vm_ops = { 1530static const struct vm_operations_struct xfs_file_vm_ops = {
1418 .fault = filemap_fault, 1531 .fault = xfs_filemap_fault,
1419 .map_pages = filemap_map_pages, 1532 .map_pages = filemap_map_pages,
1420 .page_mkwrite = xfs_vm_page_mkwrite, 1533 .page_mkwrite = xfs_filemap_page_mkwrite,
1421}; 1534};
diff --git a/fs/xfs/xfs_filestream.c b/fs/xfs/xfs_filestream.c
index a2e86e8a0fea..da82f1cb4b9b 100644
--- a/fs/xfs/xfs_filestream.c
+++ b/fs/xfs/xfs_filestream.c
@@ -294,7 +294,7 @@ xfs_filestream_get_parent(
294 if (!parent) 294 if (!parent)
295 goto out_dput; 295 goto out_dput;
296 296
297 dir = igrab(parent->d_inode); 297 dir = igrab(d_inode(parent));
298 dput(parent); 298 dput(parent);
299 299
300out_dput: 300out_dput:
@@ -322,7 +322,7 @@ xfs_filestream_lookup_ag(
322 322
323 pip = xfs_filestream_get_parent(ip); 323 pip = xfs_filestream_get_parent(ip);
324 if (!pip) 324 if (!pip)
325 goto out; 325 return NULLAGNUMBER;
326 326
327 mru = xfs_mru_cache_lookup(mp->m_filestream, pip->i_ino); 327 mru = xfs_mru_cache_lookup(mp->m_filestream, pip->i_ino);
328 if (mru) { 328 if (mru) {
diff --git a/fs/xfs/xfs_fsops.c b/fs/xfs/xfs_fsops.c
index 74efe5b760dc..cb7e8a29dfb6 100644
--- a/fs/xfs/xfs_fsops.c
+++ b/fs/xfs/xfs_fsops.c
@@ -637,12 +637,13 @@ xfs_fs_counts(
637 xfs_mount_t *mp, 637 xfs_mount_t *mp,
638 xfs_fsop_counts_t *cnt) 638 xfs_fsop_counts_t *cnt)
639{ 639{
640 xfs_icsb_sync_counters(mp, XFS_ICSB_LAZY_COUNT); 640 cnt->allocino = percpu_counter_read_positive(&mp->m_icount);
641 cnt->freeino = percpu_counter_read_positive(&mp->m_ifree);
642 cnt->freedata = percpu_counter_read_positive(&mp->m_fdblocks) -
643 XFS_ALLOC_SET_ASIDE(mp);
644
641 spin_lock(&mp->m_sb_lock); 645 spin_lock(&mp->m_sb_lock);
642 cnt->freedata = mp->m_sb.sb_fdblocks - XFS_ALLOC_SET_ASIDE(mp);
643 cnt->freertx = mp->m_sb.sb_frextents; 646 cnt->freertx = mp->m_sb.sb_frextents;
644 cnt->freeino = mp->m_sb.sb_ifree;
645 cnt->allocino = mp->m_sb.sb_icount;
646 spin_unlock(&mp->m_sb_lock); 647 spin_unlock(&mp->m_sb_lock);
647 return 0; 648 return 0;
648} 649}
@@ -692,14 +693,9 @@ xfs_reserve_blocks(
692 * what to do. This means that the amount of free space can 693 * what to do. This means that the amount of free space can
693 * change while we do this, so we need to retry if we end up 694 * change while we do this, so we need to retry if we end up
694 * trying to reserve more space than is available. 695 * trying to reserve more space than is available.
695 *
696 * We also use the xfs_mod_incore_sb() interface so that we
697 * don't have to care about whether per cpu counter are
698 * enabled, disabled or even compiled in....
699 */ 696 */
700retry: 697retry:
701 spin_lock(&mp->m_sb_lock); 698 spin_lock(&mp->m_sb_lock);
702 xfs_icsb_sync_counters_locked(mp, 0);
703 699
704 /* 700 /*
705 * If our previous reservation was larger than the current value, 701 * If our previous reservation was larger than the current value,
@@ -716,7 +712,8 @@ retry:
716 } else { 712 } else {
717 __int64_t free; 713 __int64_t free;
718 714
719 free = mp->m_sb.sb_fdblocks - XFS_ALLOC_SET_ASIDE(mp); 715 free = percpu_counter_sum(&mp->m_fdblocks) -
716 XFS_ALLOC_SET_ASIDE(mp);
720 if (!free) 717 if (!free)
721 goto out; /* ENOSPC and fdblks_delta = 0 */ 718 goto out; /* ENOSPC and fdblks_delta = 0 */
722 719
@@ -755,8 +752,7 @@ out:
755 * the extra reserve blocks from the reserve..... 752 * the extra reserve blocks from the reserve.....
756 */ 753 */
757 int error; 754 int error;
758 error = xfs_icsb_modify_counters(mp, XFS_SBS_FDBLOCKS, 755 error = xfs_mod_fdblocks(mp, fdblks_delta, 0);
759 fdblks_delta, 0);
760 if (error == -ENOSPC) 756 if (error == -ENOSPC)
761 goto retry; 757 goto retry;
762 } 758 }
diff --git a/fs/xfs/xfs_icache.c b/fs/xfs/xfs_icache.c
index 9771b7ef62ed..76a9f2783282 100644
--- a/fs/xfs/xfs_icache.c
+++ b/fs/xfs/xfs_icache.c
@@ -439,11 +439,11 @@ again:
439 *ipp = ip; 439 *ipp = ip;
440 440
441 /* 441 /*
442 * If we have a real type for an on-disk inode, we can set ops(&unlock) 442 * If we have a real type for an on-disk inode, we can setup the inode
443 * now. If it's a new inode being created, xfs_ialloc will handle it. 443 * now. If it's a new inode being created, xfs_ialloc will handle it.
444 */ 444 */
445 if (xfs_iflags_test(ip, XFS_INEW) && ip->i_d.di_mode != 0) 445 if (xfs_iflags_test(ip, XFS_INEW) && ip->i_d.di_mode != 0)
446 xfs_setup_inode(ip); 446 xfs_setup_existing_inode(ip);
447 return 0; 447 return 0;
448 448
449out_error_or_again: 449out_error_or_again:
diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c
index 6163767aa856..d6ebc85192b7 100644
--- a/fs/xfs/xfs_inode.c
+++ b/fs/xfs/xfs_inode.c
@@ -117,24 +117,34 @@ xfs_ilock_attr_map_shared(
117} 117}
118 118
119/* 119/*
120 * The xfs inode contains 2 locks: a multi-reader lock called the 120 * The xfs inode contains 3 multi-reader locks: the i_iolock the i_mmap_lock and
121 * i_iolock and a multi-reader lock called the i_lock. This routine 121 * the i_lock. This routine allows various combinations of the locks to be
122 * allows either or both of the locks to be obtained. 122 * obtained.
123 * 123 *
124 * The 2 locks should always be ordered so that the IO lock is 124 * The 3 locks should always be ordered so that the IO lock is obtained first,
125 * obtained first in order to prevent deadlock. 125 * the mmap lock second and the ilock last in order to prevent deadlock.
126 * 126 *
127 * ip -- the inode being locked 127 * Basic locking order:
128 * lock_flags -- this parameter indicates the inode's locks 128 *
129 * to be locked. It can be: 129 * i_iolock -> i_mmap_lock -> page_lock -> i_ilock
130 * XFS_IOLOCK_SHARED, 130 *
131 * XFS_IOLOCK_EXCL, 131 * mmap_sem locking order:
132 * XFS_ILOCK_SHARED, 132 *
133 * XFS_ILOCK_EXCL, 133 * i_iolock -> page lock -> mmap_sem
134 * XFS_IOLOCK_SHARED | XFS_ILOCK_SHARED, 134 * mmap_sem -> i_mmap_lock -> page_lock
135 * XFS_IOLOCK_SHARED | XFS_ILOCK_EXCL, 135 *
136 * XFS_IOLOCK_EXCL | XFS_ILOCK_SHARED, 136 * The difference in mmap_sem locking order mean that we cannot hold the
137 * XFS_IOLOCK_EXCL | XFS_ILOCK_EXCL 137 * i_mmap_lock over syscall based read(2)/write(2) based IO. These IO paths can
138 * fault in pages during copy in/out (for buffered IO) or require the mmap_sem
139 * in get_user_pages() to map the user pages into the kernel address space for
140 * direct IO. Similarly the i_iolock cannot be taken inside a page fault because
141 * page faults already hold the mmap_sem.
142 *
143 * Hence to serialise fully against both syscall and mmap based IO, we need to
144 * take both the i_iolock and the i_mmap_lock. These locks should *only* be both
145 * taken in places where we need to invalidate the page cache in a race
146 * free manner (e.g. truncate, hole punch and other extent manipulation
147 * functions).
138 */ 148 */
139void 149void
140xfs_ilock( 150xfs_ilock(
@@ -150,6 +160,8 @@ xfs_ilock(
150 */ 160 */
151 ASSERT((lock_flags & (XFS_IOLOCK_SHARED | XFS_IOLOCK_EXCL)) != 161 ASSERT((lock_flags & (XFS_IOLOCK_SHARED | XFS_IOLOCK_EXCL)) !=
152 (XFS_IOLOCK_SHARED | XFS_IOLOCK_EXCL)); 162 (XFS_IOLOCK_SHARED | XFS_IOLOCK_EXCL));
163 ASSERT((lock_flags & (XFS_MMAPLOCK_SHARED | XFS_MMAPLOCK_EXCL)) !=
164 (XFS_MMAPLOCK_SHARED | XFS_MMAPLOCK_EXCL));
153 ASSERT((lock_flags & (XFS_ILOCK_SHARED | XFS_ILOCK_EXCL)) != 165 ASSERT((lock_flags & (XFS_ILOCK_SHARED | XFS_ILOCK_EXCL)) !=
154 (XFS_ILOCK_SHARED | XFS_ILOCK_EXCL)); 166 (XFS_ILOCK_SHARED | XFS_ILOCK_EXCL));
155 ASSERT((lock_flags & ~(XFS_LOCK_MASK | XFS_LOCK_DEP_MASK)) == 0); 167 ASSERT((lock_flags & ~(XFS_LOCK_MASK | XFS_LOCK_DEP_MASK)) == 0);
@@ -159,6 +171,11 @@ xfs_ilock(
159 else if (lock_flags & XFS_IOLOCK_SHARED) 171 else if (lock_flags & XFS_IOLOCK_SHARED)
160 mraccess_nested(&ip->i_iolock, XFS_IOLOCK_DEP(lock_flags)); 172 mraccess_nested(&ip->i_iolock, XFS_IOLOCK_DEP(lock_flags));
161 173
174 if (lock_flags & XFS_MMAPLOCK_EXCL)
175 mrupdate_nested(&ip->i_mmaplock, XFS_MMAPLOCK_DEP(lock_flags));
176 else if (lock_flags & XFS_MMAPLOCK_SHARED)
177 mraccess_nested(&ip->i_mmaplock, XFS_MMAPLOCK_DEP(lock_flags));
178
162 if (lock_flags & XFS_ILOCK_EXCL) 179 if (lock_flags & XFS_ILOCK_EXCL)
163 mrupdate_nested(&ip->i_lock, XFS_ILOCK_DEP(lock_flags)); 180 mrupdate_nested(&ip->i_lock, XFS_ILOCK_DEP(lock_flags));
164 else if (lock_flags & XFS_ILOCK_SHARED) 181 else if (lock_flags & XFS_ILOCK_SHARED)
@@ -191,6 +208,8 @@ xfs_ilock_nowait(
191 */ 208 */
192 ASSERT((lock_flags & (XFS_IOLOCK_SHARED | XFS_IOLOCK_EXCL)) != 209 ASSERT((lock_flags & (XFS_IOLOCK_SHARED | XFS_IOLOCK_EXCL)) !=
193 (XFS_IOLOCK_SHARED | XFS_IOLOCK_EXCL)); 210 (XFS_IOLOCK_SHARED | XFS_IOLOCK_EXCL));
211 ASSERT((lock_flags & (XFS_MMAPLOCK_SHARED | XFS_MMAPLOCK_EXCL)) !=
212 (XFS_MMAPLOCK_SHARED | XFS_MMAPLOCK_EXCL));
194 ASSERT((lock_flags & (XFS_ILOCK_SHARED | XFS_ILOCK_EXCL)) != 213 ASSERT((lock_flags & (XFS_ILOCK_SHARED | XFS_ILOCK_EXCL)) !=
195 (XFS_ILOCK_SHARED | XFS_ILOCK_EXCL)); 214 (XFS_ILOCK_SHARED | XFS_ILOCK_EXCL));
196 ASSERT((lock_flags & ~(XFS_LOCK_MASK | XFS_LOCK_DEP_MASK)) == 0); 215 ASSERT((lock_flags & ~(XFS_LOCK_MASK | XFS_LOCK_DEP_MASK)) == 0);
@@ -202,21 +221,35 @@ xfs_ilock_nowait(
202 if (!mrtryaccess(&ip->i_iolock)) 221 if (!mrtryaccess(&ip->i_iolock))
203 goto out; 222 goto out;
204 } 223 }
224
225 if (lock_flags & XFS_MMAPLOCK_EXCL) {
226 if (!mrtryupdate(&ip->i_mmaplock))
227 goto out_undo_iolock;
228 } else if (lock_flags & XFS_MMAPLOCK_SHARED) {
229 if (!mrtryaccess(&ip->i_mmaplock))
230 goto out_undo_iolock;
231 }
232
205 if (lock_flags & XFS_ILOCK_EXCL) { 233 if (lock_flags & XFS_ILOCK_EXCL) {
206 if (!mrtryupdate(&ip->i_lock)) 234 if (!mrtryupdate(&ip->i_lock))
207 goto out_undo_iolock; 235 goto out_undo_mmaplock;
208 } else if (lock_flags & XFS_ILOCK_SHARED) { 236 } else if (lock_flags & XFS_ILOCK_SHARED) {
209 if (!mrtryaccess(&ip->i_lock)) 237 if (!mrtryaccess(&ip->i_lock))
210 goto out_undo_iolock; 238 goto out_undo_mmaplock;
211 } 239 }
212 return 1; 240 return 1;
213 241
214 out_undo_iolock: 242out_undo_mmaplock:
243 if (lock_flags & XFS_MMAPLOCK_EXCL)
244 mrunlock_excl(&ip->i_mmaplock);
245 else if (lock_flags & XFS_MMAPLOCK_SHARED)
246 mrunlock_shared(&ip->i_mmaplock);
247out_undo_iolock:
215 if (lock_flags & XFS_IOLOCK_EXCL) 248 if (lock_flags & XFS_IOLOCK_EXCL)
216 mrunlock_excl(&ip->i_iolock); 249 mrunlock_excl(&ip->i_iolock);
217 else if (lock_flags & XFS_IOLOCK_SHARED) 250 else if (lock_flags & XFS_IOLOCK_SHARED)
218 mrunlock_shared(&ip->i_iolock); 251 mrunlock_shared(&ip->i_iolock);
219 out: 252out:
220 return 0; 253 return 0;
221} 254}
222 255
@@ -244,6 +277,8 @@ xfs_iunlock(
244 */ 277 */
245 ASSERT((lock_flags & (XFS_IOLOCK_SHARED | XFS_IOLOCK_EXCL)) != 278 ASSERT((lock_flags & (XFS_IOLOCK_SHARED | XFS_IOLOCK_EXCL)) !=
246 (XFS_IOLOCK_SHARED | XFS_IOLOCK_EXCL)); 279 (XFS_IOLOCK_SHARED | XFS_IOLOCK_EXCL));
280 ASSERT((lock_flags & (XFS_MMAPLOCK_SHARED | XFS_MMAPLOCK_EXCL)) !=
281 (XFS_MMAPLOCK_SHARED | XFS_MMAPLOCK_EXCL));
247 ASSERT((lock_flags & (XFS_ILOCK_SHARED | XFS_ILOCK_EXCL)) != 282 ASSERT((lock_flags & (XFS_ILOCK_SHARED | XFS_ILOCK_EXCL)) !=
248 (XFS_ILOCK_SHARED | XFS_ILOCK_EXCL)); 283 (XFS_ILOCK_SHARED | XFS_ILOCK_EXCL));
249 ASSERT((lock_flags & ~(XFS_LOCK_MASK | XFS_LOCK_DEP_MASK)) == 0); 284 ASSERT((lock_flags & ~(XFS_LOCK_MASK | XFS_LOCK_DEP_MASK)) == 0);
@@ -254,6 +289,11 @@ xfs_iunlock(
254 else if (lock_flags & XFS_IOLOCK_SHARED) 289 else if (lock_flags & XFS_IOLOCK_SHARED)
255 mrunlock_shared(&ip->i_iolock); 290 mrunlock_shared(&ip->i_iolock);
256 291
292 if (lock_flags & XFS_MMAPLOCK_EXCL)
293 mrunlock_excl(&ip->i_mmaplock);
294 else if (lock_flags & XFS_MMAPLOCK_SHARED)
295 mrunlock_shared(&ip->i_mmaplock);
296
257 if (lock_flags & XFS_ILOCK_EXCL) 297 if (lock_flags & XFS_ILOCK_EXCL)
258 mrunlock_excl(&ip->i_lock); 298 mrunlock_excl(&ip->i_lock);
259 else if (lock_flags & XFS_ILOCK_SHARED) 299 else if (lock_flags & XFS_ILOCK_SHARED)
@@ -271,11 +311,14 @@ xfs_ilock_demote(
271 xfs_inode_t *ip, 311 xfs_inode_t *ip,
272 uint lock_flags) 312 uint lock_flags)
273{ 313{
274 ASSERT(lock_flags & (XFS_IOLOCK_EXCL|XFS_ILOCK_EXCL)); 314 ASSERT(lock_flags & (XFS_IOLOCK_EXCL|XFS_MMAPLOCK_EXCL|XFS_ILOCK_EXCL));
275 ASSERT((lock_flags & ~(XFS_IOLOCK_EXCL|XFS_ILOCK_EXCL)) == 0); 315 ASSERT((lock_flags &
316 ~(XFS_IOLOCK_EXCL|XFS_MMAPLOCK_EXCL|XFS_ILOCK_EXCL)) == 0);
276 317
277 if (lock_flags & XFS_ILOCK_EXCL) 318 if (lock_flags & XFS_ILOCK_EXCL)
278 mrdemote(&ip->i_lock); 319 mrdemote(&ip->i_lock);
320 if (lock_flags & XFS_MMAPLOCK_EXCL)
321 mrdemote(&ip->i_mmaplock);
279 if (lock_flags & XFS_IOLOCK_EXCL) 322 if (lock_flags & XFS_IOLOCK_EXCL)
280 mrdemote(&ip->i_iolock); 323 mrdemote(&ip->i_iolock);
281 324
@@ -294,6 +337,12 @@ xfs_isilocked(
294 return rwsem_is_locked(&ip->i_lock.mr_lock); 337 return rwsem_is_locked(&ip->i_lock.mr_lock);
295 } 338 }
296 339
340 if (lock_flags & (XFS_MMAPLOCK_EXCL|XFS_MMAPLOCK_SHARED)) {
341 if (!(lock_flags & XFS_MMAPLOCK_SHARED))
342 return !!ip->i_mmaplock.mr_writer;
343 return rwsem_is_locked(&ip->i_mmaplock.mr_lock);
344 }
345
297 if (lock_flags & (XFS_IOLOCK_EXCL|XFS_IOLOCK_SHARED)) { 346 if (lock_flags & (XFS_IOLOCK_EXCL|XFS_IOLOCK_SHARED)) {
298 if (!(lock_flags & XFS_IOLOCK_SHARED)) 347 if (!(lock_flags & XFS_IOLOCK_SHARED))
299 return !!ip->i_iolock.mr_writer; 348 return !!ip->i_iolock.mr_writer;
@@ -314,14 +363,27 @@ int xfs_lock_delays;
314#endif 363#endif
315 364
316/* 365/*
317 * Bump the subclass so xfs_lock_inodes() acquires each lock with 366 * Bump the subclass so xfs_lock_inodes() acquires each lock with a different
318 * a different value 367 * value. This shouldn't be called for page fault locking, but we also need to
368 * ensure we don't overrun the number of lockdep subclasses for the iolock or
369 * mmaplock as that is limited to 12 by the mmap lock lockdep annotations.
319 */ 370 */
320static inline int 371static inline int
321xfs_lock_inumorder(int lock_mode, int subclass) 372xfs_lock_inumorder(int lock_mode, int subclass)
322{ 373{
323 if (lock_mode & (XFS_IOLOCK_SHARED|XFS_IOLOCK_EXCL)) 374 if (lock_mode & (XFS_IOLOCK_SHARED|XFS_IOLOCK_EXCL)) {
375 ASSERT(subclass + XFS_LOCK_INUMORDER <
376 (1 << (XFS_MMAPLOCK_SHIFT - XFS_IOLOCK_SHIFT)));
324 lock_mode |= (subclass + XFS_LOCK_INUMORDER) << XFS_IOLOCK_SHIFT; 377 lock_mode |= (subclass + XFS_LOCK_INUMORDER) << XFS_IOLOCK_SHIFT;
378 }
379
380 if (lock_mode & (XFS_MMAPLOCK_SHARED|XFS_MMAPLOCK_EXCL)) {
381 ASSERT(subclass + XFS_LOCK_INUMORDER <
382 (1 << (XFS_ILOCK_SHIFT - XFS_MMAPLOCK_SHIFT)));
383 lock_mode |= (subclass + XFS_LOCK_INUMORDER) <<
384 XFS_MMAPLOCK_SHIFT;
385 }
386
325 if (lock_mode & (XFS_ILOCK_SHARED|XFS_ILOCK_EXCL)) 387 if (lock_mode & (XFS_ILOCK_SHARED|XFS_ILOCK_EXCL))
326 lock_mode |= (subclass + XFS_LOCK_INUMORDER) << XFS_ILOCK_SHIFT; 388 lock_mode |= (subclass + XFS_LOCK_INUMORDER) << XFS_ILOCK_SHIFT;
327 389
@@ -329,15 +391,14 @@ xfs_lock_inumorder(int lock_mode, int subclass)
329} 391}
330 392
331/* 393/*
332 * The following routine will lock n inodes in exclusive mode. 394 * The following routine will lock n inodes in exclusive mode. We assume the
333 * We assume the caller calls us with the inodes in i_ino order. 395 * caller calls us with the inodes in i_ino order.
334 * 396 *
335 * We need to detect deadlock where an inode that we lock 397 * We need to detect deadlock where an inode that we lock is in the AIL and we
336 * is in the AIL and we start waiting for another inode that is locked 398 * start waiting for another inode that is locked by a thread in a long running
337 * by a thread in a long running transaction (such as truncate). This can 399 * transaction (such as truncate). This can result in deadlock since the long
338 * result in deadlock since the long running trans might need to wait 400 * running trans might need to wait for the inode we just locked in order to
339 * for the inode we just locked in order to push the tail and free space 401 * push the tail and free space in the log.
340 * in the log.
341 */ 402 */
342void 403void
343xfs_lock_inodes( 404xfs_lock_inodes(
@@ -348,30 +409,27 @@ xfs_lock_inodes(
348 int attempts = 0, i, j, try_lock; 409 int attempts = 0, i, j, try_lock;
349 xfs_log_item_t *lp; 410 xfs_log_item_t *lp;
350 411
351 ASSERT(ips && (inodes >= 2)); /* we need at least two */ 412 /* currently supports between 2 and 5 inodes */
413 ASSERT(ips && inodes >= 2 && inodes <= 5);
352 414
353 try_lock = 0; 415 try_lock = 0;
354 i = 0; 416 i = 0;
355
356again: 417again:
357 for (; i < inodes; i++) { 418 for (; i < inodes; i++) {
358 ASSERT(ips[i]); 419 ASSERT(ips[i]);
359 420
360 if (i && (ips[i] == ips[i-1])) /* Already locked */ 421 if (i && (ips[i] == ips[i - 1])) /* Already locked */
361 continue; 422 continue;
362 423
363 /* 424 /*
364 * If try_lock is not set yet, make sure all locked inodes 425 * If try_lock is not set yet, make sure all locked inodes are
365 * are not in the AIL. 426 * not in the AIL. If any are, set try_lock to be used later.
366 * If any are, set try_lock to be used later.
367 */ 427 */
368
369 if (!try_lock) { 428 if (!try_lock) {
370 for (j = (i - 1); j >= 0 && !try_lock; j--) { 429 for (j = (i - 1); j >= 0 && !try_lock; j--) {
371 lp = (xfs_log_item_t *)ips[j]->i_itemp; 430 lp = (xfs_log_item_t *)ips[j]->i_itemp;
372 if (lp && (lp->li_flags & XFS_LI_IN_AIL)) { 431 if (lp && (lp->li_flags & XFS_LI_IN_AIL))
373 try_lock++; 432 try_lock++;
374 }
375 } 433 }
376 } 434 }
377 435
@@ -381,51 +439,42 @@ again:
381 * we can't get any, we must release all we have 439 * we can't get any, we must release all we have
382 * and try again. 440 * and try again.
383 */ 441 */
442 if (!try_lock) {
443 xfs_ilock(ips[i], xfs_lock_inumorder(lock_mode, i));
444 continue;
445 }
446
447 /* try_lock means we have an inode locked that is in the AIL. */
448 ASSERT(i != 0);
449 if (xfs_ilock_nowait(ips[i], xfs_lock_inumorder(lock_mode, i)))
450 continue;
384 451
385 if (try_lock) { 452 /*
386 /* try_lock must be 0 if i is 0. */ 453 * Unlock all previous guys and try again. xfs_iunlock will try
454 * to push the tail if the inode is in the AIL.
455 */
456 attempts++;
457 for (j = i - 1; j >= 0; j--) {
387 /* 458 /*
388 * try_lock means we have an inode locked 459 * Check to see if we've already unlocked this one. Not
389 * that is in the AIL. 460 * the first one going back, and the inode ptr is the
461 * same.
390 */ 462 */
391 ASSERT(i != 0); 463 if (j != (i - 1) && ips[j] == ips[j + 1])
392 if (!xfs_ilock_nowait(ips[i], xfs_lock_inumorder(lock_mode, i))) { 464 continue;
393 attempts++; 465
394 466 xfs_iunlock(ips[j], lock_mode);
395 /* 467 }
396 * Unlock all previous guys and try again.
397 * xfs_iunlock will try to push the tail
398 * if the inode is in the AIL.
399 */
400
401 for(j = i - 1; j >= 0; j--) {
402
403 /*
404 * Check to see if we've already
405 * unlocked this one.
406 * Not the first one going back,
407 * and the inode ptr is the same.
408 */
409 if ((j != (i - 1)) && ips[j] ==
410 ips[j+1])
411 continue;
412
413 xfs_iunlock(ips[j], lock_mode);
414 }
415 468
416 if ((attempts % 5) == 0) { 469 if ((attempts % 5) == 0) {
417 delay(1); /* Don't just spin the CPU */ 470 delay(1); /* Don't just spin the CPU */
418#ifdef DEBUG 471#ifdef DEBUG
419 xfs_lock_delays++; 472 xfs_lock_delays++;
420#endif 473#endif
421 }
422 i = 0;
423 try_lock = 0;
424 goto again;
425 }
426 } else {
427 xfs_ilock(ips[i], xfs_lock_inumorder(lock_mode, i));
428 } 474 }
475 i = 0;
476 try_lock = 0;
477 goto again;
429 } 478 }
430 479
431#ifdef DEBUG 480#ifdef DEBUG
@@ -440,10 +489,10 @@ again:
440} 489}
441 490
442/* 491/*
443 * xfs_lock_two_inodes() can only be used to lock one type of lock 492 * xfs_lock_two_inodes() can only be used to lock one type of lock at a time -
444 * at a time - the iolock or the ilock, but not both at once. If 493 * the iolock, the mmaplock or the ilock, but not more than one at a time. If we
445 * we lock both at once, lockdep will report false positives saying 494 * lock more than one at a time, lockdep will report false positives saying we
446 * we have violated locking orders. 495 * have violated locking orders.
447 */ 496 */
448void 497void
449xfs_lock_two_inodes( 498xfs_lock_two_inodes(
@@ -455,8 +504,12 @@ xfs_lock_two_inodes(
455 int attempts = 0; 504 int attempts = 0;
456 xfs_log_item_t *lp; 505 xfs_log_item_t *lp;
457 506
458 if (lock_mode & (XFS_IOLOCK_SHARED|XFS_IOLOCK_EXCL)) 507 if (lock_mode & (XFS_IOLOCK_SHARED|XFS_IOLOCK_EXCL)) {
459 ASSERT((lock_mode & (XFS_ILOCK_SHARED|XFS_ILOCK_EXCL)) == 0); 508 ASSERT(!(lock_mode & (XFS_MMAPLOCK_SHARED|XFS_MMAPLOCK_EXCL)));
509 ASSERT(!(lock_mode & (XFS_ILOCK_SHARED|XFS_ILOCK_EXCL)));
510 } else if (lock_mode & (XFS_MMAPLOCK_SHARED|XFS_MMAPLOCK_EXCL))
511 ASSERT(!(lock_mode & (XFS_ILOCK_SHARED|XFS_ILOCK_EXCL)));
512
460 ASSERT(ip0->i_ino != ip1->i_ino); 513 ASSERT(ip0->i_ino != ip1->i_ino);
461 514
462 if (ip0->i_ino > ip1->i_ino) { 515 if (ip0->i_ino > ip1->i_ino) {
@@ -818,7 +871,7 @@ xfs_ialloc(
818 xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL); 871 xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
819 xfs_trans_log_inode(tp, ip, flags); 872 xfs_trans_log_inode(tp, ip, flags);
820 873
821 /* now that we have an i_mode we can setup inode ops and unlock */ 874 /* now that we have an i_mode we can setup the inode structure */
822 xfs_setup_inode(ip); 875 xfs_setup_inode(ip);
823 876
824 *ipp = ip; 877 *ipp = ip;
@@ -1235,12 +1288,14 @@ xfs_create(
1235 xfs_trans_cancel(tp, cancel_flags); 1288 xfs_trans_cancel(tp, cancel_flags);
1236 out_release_inode: 1289 out_release_inode:
1237 /* 1290 /*
1238 * Wait until after the current transaction is aborted to 1291 * Wait until after the current transaction is aborted to finish the
1239 * release the inode. This prevents recursive transactions 1292 * setup of the inode and release the inode. This prevents recursive
1240 * and deadlocks from xfs_inactive. 1293 * transactions and deadlocks from xfs_inactive.
1241 */ 1294 */
1242 if (ip) 1295 if (ip) {
1296 xfs_finish_inode_setup(ip);
1243 IRELE(ip); 1297 IRELE(ip);
1298 }
1244 1299
1245 xfs_qm_dqrele(udqp); 1300 xfs_qm_dqrele(udqp);
1246 xfs_qm_dqrele(gdqp); 1301 xfs_qm_dqrele(gdqp);
@@ -1345,12 +1400,14 @@ xfs_create_tmpfile(
1345 xfs_trans_cancel(tp, cancel_flags); 1400 xfs_trans_cancel(tp, cancel_flags);
1346 out_release_inode: 1401 out_release_inode:
1347 /* 1402 /*
1348 * Wait until after the current transaction is aborted to 1403 * Wait until after the current transaction is aborted to finish the
1349 * release the inode. This prevents recursive transactions 1404 * setup of the inode and release the inode. This prevents recursive
1350 * and deadlocks from xfs_inactive. 1405 * transactions and deadlocks from xfs_inactive.
1351 */ 1406 */
1352 if (ip) 1407 if (ip) {
1408 xfs_finish_inode_setup(ip);
1353 IRELE(ip); 1409 IRELE(ip);
1410 }
1354 1411
1355 xfs_qm_dqrele(udqp); 1412 xfs_qm_dqrele(udqp);
1356 xfs_qm_dqrele(gdqp); 1413 xfs_qm_dqrele(gdqp);
@@ -2611,19 +2668,22 @@ xfs_remove(
2611/* 2668/*
2612 * Enter all inodes for a rename transaction into a sorted array. 2669 * Enter all inodes for a rename transaction into a sorted array.
2613 */ 2670 */
2671#define __XFS_SORT_INODES 5
2614STATIC void 2672STATIC void
2615xfs_sort_for_rename( 2673xfs_sort_for_rename(
2616 xfs_inode_t *dp1, /* in: old (source) directory inode */ 2674 struct xfs_inode *dp1, /* in: old (source) directory inode */
2617 xfs_inode_t *dp2, /* in: new (target) directory inode */ 2675 struct xfs_inode *dp2, /* in: new (target) directory inode */
2618 xfs_inode_t *ip1, /* in: inode of old entry */ 2676 struct xfs_inode *ip1, /* in: inode of old entry */
2619 xfs_inode_t *ip2, /* in: inode of new entry, if it 2677 struct xfs_inode *ip2, /* in: inode of new entry */
2620 already exists, NULL otherwise. */ 2678 struct xfs_inode *wip, /* in: whiteout inode */
2621 xfs_inode_t **i_tab,/* out: array of inode returned, sorted */ 2679 struct xfs_inode **i_tab,/* out: sorted array of inodes */
2622 int *num_inodes) /* out: number of inodes in array */ 2680 int *num_inodes) /* in/out: inodes in array */
2623{ 2681{
2624 xfs_inode_t *temp;
2625 int i, j; 2682 int i, j;
2626 2683
2684 ASSERT(*num_inodes == __XFS_SORT_INODES);
2685 memset(i_tab, 0, *num_inodes * sizeof(struct xfs_inode *));
2686
2627 /* 2687 /*
2628 * i_tab contains a list of pointers to inodes. We initialize 2688 * i_tab contains a list of pointers to inodes. We initialize
2629 * the table here & we'll sort it. We will then use it to 2689 * the table here & we'll sort it. We will then use it to
@@ -2631,25 +2691,24 @@ xfs_sort_for_rename(
2631 * 2691 *
2632 * Note that the table may contain duplicates. e.g., dp1 == dp2. 2692 * Note that the table may contain duplicates. e.g., dp1 == dp2.
2633 */ 2693 */
2634 i_tab[0] = dp1; 2694 i = 0;
2635 i_tab[1] = dp2; 2695 i_tab[i++] = dp1;
2636 i_tab[2] = ip1; 2696 i_tab[i++] = dp2;
2637 if (ip2) { 2697 i_tab[i++] = ip1;
2638 *num_inodes = 4; 2698 if (ip2)
2639 i_tab[3] = ip2; 2699 i_tab[i++] = ip2;
2640 } else { 2700 if (wip)
2641 *num_inodes = 3; 2701 i_tab[i++] = wip;
2642 i_tab[3] = NULL; 2702 *num_inodes = i;
2643 }
2644 2703
2645 /* 2704 /*
2646 * Sort the elements via bubble sort. (Remember, there are at 2705 * Sort the elements via bubble sort. (Remember, there are at
2647 * most 4 elements to sort, so this is adequate.) 2706 * most 5 elements to sort, so this is adequate.)
2648 */ 2707 */
2649 for (i = 0; i < *num_inodes; i++) { 2708 for (i = 0; i < *num_inodes; i++) {
2650 for (j = 1; j < *num_inodes; j++) { 2709 for (j = 1; j < *num_inodes; j++) {
2651 if (i_tab[j]->i_ino < i_tab[j-1]->i_ino) { 2710 if (i_tab[j]->i_ino < i_tab[j-1]->i_ino) {
2652 temp = i_tab[j]; 2711 struct xfs_inode *temp = i_tab[j];
2653 i_tab[j] = i_tab[j-1]; 2712 i_tab[j] = i_tab[j-1];
2654 i_tab[j-1] = temp; 2713 i_tab[j-1] = temp;
2655 } 2714 }
@@ -2657,6 +2716,31 @@ xfs_sort_for_rename(
2657 } 2716 }
2658} 2717}
2659 2718
2719static int
2720xfs_finish_rename(
2721 struct xfs_trans *tp,
2722 struct xfs_bmap_free *free_list)
2723{
2724 int committed = 0;
2725 int error;
2726
2727 /*
2728 * If this is a synchronous mount, make sure that the rename transaction
2729 * goes to disk before returning to the user.
2730 */
2731 if (tp->t_mountp->m_flags & (XFS_MOUNT_WSYNC|XFS_MOUNT_DIRSYNC))
2732 xfs_trans_set_sync(tp);
2733
2734 error = xfs_bmap_finish(&tp, free_list, &committed);
2735 if (error) {
2736 xfs_bmap_cancel(free_list);
2737 xfs_trans_cancel(tp, XFS_TRANS_RELEASE_LOG_RES|XFS_TRANS_ABORT);
2738 return error;
2739 }
2740
2741 return xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES);
2742}
2743
2660/* 2744/*
2661 * xfs_cross_rename() 2745 * xfs_cross_rename()
2662 * 2746 *
@@ -2685,14 +2769,14 @@ xfs_cross_rename(
2685 ip2->i_ino, 2769 ip2->i_ino,
2686 first_block, free_list, spaceres); 2770 first_block, free_list, spaceres);
2687 if (error) 2771 if (error)
2688 goto out; 2772 goto out_trans_abort;
2689 2773
2690 /* Swap inode number for dirent in second parent */ 2774 /* Swap inode number for dirent in second parent */
2691 error = xfs_dir_replace(tp, dp2, name2, 2775 error = xfs_dir_replace(tp, dp2, name2,
2692 ip1->i_ino, 2776 ip1->i_ino,
2693 first_block, free_list, spaceres); 2777 first_block, free_list, spaceres);
2694 if (error) 2778 if (error)
2695 goto out; 2779 goto out_trans_abort;
2696 2780
2697 /* 2781 /*
2698 * If we're renaming one or more directories across different parents, 2782 * If we're renaming one or more directories across different parents,
@@ -2707,16 +2791,16 @@ xfs_cross_rename(
2707 dp1->i_ino, first_block, 2791 dp1->i_ino, first_block,
2708 free_list, spaceres); 2792 free_list, spaceres);
2709 if (error) 2793 if (error)
2710 goto out; 2794 goto out_trans_abort;
2711 2795
2712 /* transfer ip2 ".." reference to dp1 */ 2796 /* transfer ip2 ".." reference to dp1 */
2713 if (!S_ISDIR(ip1->i_d.di_mode)) { 2797 if (!S_ISDIR(ip1->i_d.di_mode)) {
2714 error = xfs_droplink(tp, dp2); 2798 error = xfs_droplink(tp, dp2);
2715 if (error) 2799 if (error)
2716 goto out; 2800 goto out_trans_abort;
2717 error = xfs_bumplink(tp, dp1); 2801 error = xfs_bumplink(tp, dp1);
2718 if (error) 2802 if (error)
2719 goto out; 2803 goto out_trans_abort;
2720 } 2804 }
2721 2805
2722 /* 2806 /*
@@ -2734,16 +2818,16 @@ xfs_cross_rename(
2734 dp2->i_ino, first_block, 2818 dp2->i_ino, first_block,
2735 free_list, spaceres); 2819 free_list, spaceres);
2736 if (error) 2820 if (error)
2737 goto out; 2821 goto out_trans_abort;
2738 2822
2739 /* transfer ip1 ".." reference to dp2 */ 2823 /* transfer ip1 ".." reference to dp2 */
2740 if (!S_ISDIR(ip2->i_d.di_mode)) { 2824 if (!S_ISDIR(ip2->i_d.di_mode)) {
2741 error = xfs_droplink(tp, dp1); 2825 error = xfs_droplink(tp, dp1);
2742 if (error) 2826 if (error)
2743 goto out; 2827 goto out_trans_abort;
2744 error = xfs_bumplink(tp, dp2); 2828 error = xfs_bumplink(tp, dp2);
2745 if (error) 2829 if (error)
2746 goto out; 2830 goto out_trans_abort;
2747 } 2831 }
2748 2832
2749 /* 2833 /*
@@ -2771,66 +2855,108 @@ xfs_cross_rename(
2771 } 2855 }
2772 xfs_trans_ichgtime(tp, dp1, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG); 2856 xfs_trans_ichgtime(tp, dp1, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG);
2773 xfs_trans_log_inode(tp, dp1, XFS_ILOG_CORE); 2857 xfs_trans_log_inode(tp, dp1, XFS_ILOG_CORE);
2774out: 2858 return xfs_finish_rename(tp, free_list);
2859
2860out_trans_abort:
2861 xfs_bmap_cancel(free_list);
2862 xfs_trans_cancel(tp, XFS_TRANS_RELEASE_LOG_RES|XFS_TRANS_ABORT);
2775 return error; 2863 return error;
2776} 2864}
2777 2865
2778/* 2866/*
2867 * xfs_rename_alloc_whiteout()
2868 *
2869 * Return a referenced, unlinked, unlocked inode that that can be used as a
2870 * whiteout in a rename transaction. We use a tmpfile inode here so that if we
2871 * crash between allocating the inode and linking it into the rename transaction
2872 * recovery will free the inode and we won't leak it.
2873 */
2874static int
2875xfs_rename_alloc_whiteout(
2876 struct xfs_inode *dp,
2877 struct xfs_inode **wip)
2878{
2879 struct xfs_inode *tmpfile;
2880 int error;
2881
2882 error = xfs_create_tmpfile(dp, NULL, S_IFCHR | WHITEOUT_MODE, &tmpfile);
2883 if (error)
2884 return error;
2885
2886 /* Satisfy xfs_bumplink that this is a real tmpfile */
2887 xfs_finish_inode_setup(tmpfile);
2888 VFS_I(tmpfile)->i_state |= I_LINKABLE;
2889
2890 *wip = tmpfile;
2891 return 0;
2892}
2893
2894/*
2779 * xfs_rename 2895 * xfs_rename
2780 */ 2896 */
2781int 2897int
2782xfs_rename( 2898xfs_rename(
2783 xfs_inode_t *src_dp, 2899 struct xfs_inode *src_dp,
2784 struct xfs_name *src_name, 2900 struct xfs_name *src_name,
2785 xfs_inode_t *src_ip, 2901 struct xfs_inode *src_ip,
2786 xfs_inode_t *target_dp, 2902 struct xfs_inode *target_dp,
2787 struct xfs_name *target_name, 2903 struct xfs_name *target_name,
2788 xfs_inode_t *target_ip, 2904 struct xfs_inode *target_ip,
2789 unsigned int flags) 2905 unsigned int flags)
2790{ 2906{
2791 xfs_trans_t *tp = NULL; 2907 struct xfs_mount *mp = src_dp->i_mount;
2792 xfs_mount_t *mp = src_dp->i_mount; 2908 struct xfs_trans *tp;
2793 int new_parent; /* moving to a new dir */ 2909 struct xfs_bmap_free free_list;
2794 int src_is_directory; /* src_name is a directory */ 2910 xfs_fsblock_t first_block;
2795 int error; 2911 struct xfs_inode *wip = NULL; /* whiteout inode */
2796 xfs_bmap_free_t free_list; 2912 struct xfs_inode *inodes[__XFS_SORT_INODES];
2797 xfs_fsblock_t first_block; 2913 int num_inodes = __XFS_SORT_INODES;
2798 int cancel_flags; 2914 bool new_parent = (src_dp != target_dp);
2799 int committed; 2915 bool src_is_directory = S_ISDIR(src_ip->i_d.di_mode);
2800 xfs_inode_t *inodes[4]; 2916 int cancel_flags = 0;
2801 int spaceres; 2917 int spaceres;
2802 int num_inodes; 2918 int error;
2803 2919
2804 trace_xfs_rename(src_dp, target_dp, src_name, target_name); 2920 trace_xfs_rename(src_dp, target_dp, src_name, target_name);
2805 2921
2806 new_parent = (src_dp != target_dp); 2922 if ((flags & RENAME_EXCHANGE) && !target_ip)
2807 src_is_directory = S_ISDIR(src_ip->i_d.di_mode); 2923 return -EINVAL;
2808 2924
2809 xfs_sort_for_rename(src_dp, target_dp, src_ip, target_ip, 2925 /*
2926 * If we are doing a whiteout operation, allocate the whiteout inode
2927 * we will be placing at the target and ensure the type is set
2928 * appropriately.
2929 */
2930 if (flags & RENAME_WHITEOUT) {
2931 ASSERT(!(flags & (RENAME_NOREPLACE | RENAME_EXCHANGE)));
2932 error = xfs_rename_alloc_whiteout(target_dp, &wip);
2933 if (error)
2934 return error;
2935
2936 /* setup target dirent info as whiteout */
2937 src_name->type = XFS_DIR3_FT_CHRDEV;
2938 }
2939
2940 xfs_sort_for_rename(src_dp, target_dp, src_ip, target_ip, wip,
2810 inodes, &num_inodes); 2941 inodes, &num_inodes);
2811 2942
2812 xfs_bmap_init(&free_list, &first_block);
2813 tp = xfs_trans_alloc(mp, XFS_TRANS_RENAME); 2943 tp = xfs_trans_alloc(mp, XFS_TRANS_RENAME);
2814 cancel_flags = XFS_TRANS_RELEASE_LOG_RES;
2815 spaceres = XFS_RENAME_SPACE_RES(mp, target_name->len); 2944 spaceres = XFS_RENAME_SPACE_RES(mp, target_name->len);
2816 error = xfs_trans_reserve(tp, &M_RES(mp)->tr_rename, spaceres, 0); 2945 error = xfs_trans_reserve(tp, &M_RES(mp)->tr_rename, spaceres, 0);
2817 if (error == -ENOSPC) { 2946 if (error == -ENOSPC) {
2818 spaceres = 0; 2947 spaceres = 0;
2819 error = xfs_trans_reserve(tp, &M_RES(mp)->tr_rename, 0, 0); 2948 error = xfs_trans_reserve(tp, &M_RES(mp)->tr_rename, 0, 0);
2820 } 2949 }
2821 if (error) { 2950 if (error)
2822 xfs_trans_cancel(tp, 0); 2951 goto out_trans_cancel;
2823 goto std_return; 2952 cancel_flags = XFS_TRANS_RELEASE_LOG_RES;
2824 }
2825 2953
2826 /* 2954 /*
2827 * Attach the dquots to the inodes 2955 * Attach the dquots to the inodes
2828 */ 2956 */
2829 error = xfs_qm_vop_rename_dqattach(inodes); 2957 error = xfs_qm_vop_rename_dqattach(inodes);
2830 if (error) { 2958 if (error)
2831 xfs_trans_cancel(tp, cancel_flags); 2959 goto out_trans_cancel;
2832 goto std_return;
2833 }
2834 2960
2835 /* 2961 /*
2836 * Lock all the participating inodes. Depending upon whether 2962 * Lock all the participating inodes. Depending upon whether
@@ -2851,6 +2977,8 @@ xfs_rename(
2851 xfs_trans_ijoin(tp, src_ip, XFS_ILOCK_EXCL); 2977 xfs_trans_ijoin(tp, src_ip, XFS_ILOCK_EXCL);
2852 if (target_ip) 2978 if (target_ip)
2853 xfs_trans_ijoin(tp, target_ip, XFS_ILOCK_EXCL); 2979 xfs_trans_ijoin(tp, target_ip, XFS_ILOCK_EXCL);
2980 if (wip)
2981 xfs_trans_ijoin(tp, wip, XFS_ILOCK_EXCL);
2854 2982
2855 /* 2983 /*
2856 * If we are using project inheritance, we only allow renames 2984 * If we are using project inheritance, we only allow renames
@@ -2860,24 +2988,16 @@ xfs_rename(
2860 if (unlikely((target_dp->i_d.di_flags & XFS_DIFLAG_PROJINHERIT) && 2988 if (unlikely((target_dp->i_d.di_flags & XFS_DIFLAG_PROJINHERIT) &&
2861 (xfs_get_projid(target_dp) != xfs_get_projid(src_ip)))) { 2989 (xfs_get_projid(target_dp) != xfs_get_projid(src_ip)))) {
2862 error = -EXDEV; 2990 error = -EXDEV;
2863 goto error_return; 2991 goto out_trans_cancel;
2864 } 2992 }
2865 2993
2866 /* 2994 xfs_bmap_init(&free_list, &first_block);
2867 * Handle RENAME_EXCHANGE flags 2995
2868 */ 2996 /* RENAME_EXCHANGE is unique from here on. */
2869 if (flags & RENAME_EXCHANGE) { 2997 if (flags & RENAME_EXCHANGE)
2870 if (target_ip == NULL) { 2998 return xfs_cross_rename(tp, src_dp, src_name, src_ip,
2871 error = -EINVAL; 2999 target_dp, target_name, target_ip,
2872 goto error_return; 3000 &free_list, &first_block, spaceres);
2873 }
2874 error = xfs_cross_rename(tp, src_dp, src_name, src_ip,
2875 target_dp, target_name, target_ip,
2876 &free_list, &first_block, spaceres);
2877 if (error)
2878 goto abort_return;
2879 goto finish_rename;
2880 }
2881 3001
2882 /* 3002 /*
2883 * Set up the target. 3003 * Set up the target.
@@ -2890,7 +3010,7 @@ xfs_rename(
2890 if (!spaceres) { 3010 if (!spaceres) {
2891 error = xfs_dir_canenter(tp, target_dp, target_name); 3011 error = xfs_dir_canenter(tp, target_dp, target_name);
2892 if (error) 3012 if (error)
2893 goto error_return; 3013 goto out_trans_cancel;
2894 } 3014 }
2895 /* 3015 /*
2896 * If target does not exist and the rename crosses 3016 * If target does not exist and the rename crosses
@@ -2901,9 +3021,9 @@ xfs_rename(
2901 src_ip->i_ino, &first_block, 3021 src_ip->i_ino, &first_block,
2902 &free_list, spaceres); 3022 &free_list, spaceres);
2903 if (error == -ENOSPC) 3023 if (error == -ENOSPC)
2904 goto error_return; 3024 goto out_bmap_cancel;
2905 if (error) 3025 if (error)
2906 goto abort_return; 3026 goto out_trans_abort;
2907 3027
2908 xfs_trans_ichgtime(tp, target_dp, 3028 xfs_trans_ichgtime(tp, target_dp,
2909 XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG); 3029 XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG);
@@ -2911,7 +3031,7 @@ xfs_rename(
2911 if (new_parent && src_is_directory) { 3031 if (new_parent && src_is_directory) {
2912 error = xfs_bumplink(tp, target_dp); 3032 error = xfs_bumplink(tp, target_dp);
2913 if (error) 3033 if (error)
2914 goto abort_return; 3034 goto out_trans_abort;
2915 } 3035 }
2916 } else { /* target_ip != NULL */ 3036 } else { /* target_ip != NULL */
2917 /* 3037 /*
@@ -2926,7 +3046,7 @@ xfs_rename(
2926 if (!(xfs_dir_isempty(target_ip)) || 3046 if (!(xfs_dir_isempty(target_ip)) ||
2927 (target_ip->i_d.di_nlink > 2)) { 3047 (target_ip->i_d.di_nlink > 2)) {
2928 error = -EEXIST; 3048 error = -EEXIST;
2929 goto error_return; 3049 goto out_trans_cancel;
2930 } 3050 }
2931 } 3051 }
2932 3052
@@ -2943,7 +3063,7 @@ xfs_rename(
2943 src_ip->i_ino, 3063 src_ip->i_ino,
2944 &first_block, &free_list, spaceres); 3064 &first_block, &free_list, spaceres);
2945 if (error) 3065 if (error)
2946 goto abort_return; 3066 goto out_trans_abort;
2947 3067
2948 xfs_trans_ichgtime(tp, target_dp, 3068 xfs_trans_ichgtime(tp, target_dp,
2949 XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG); 3069 XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG);
@@ -2954,7 +3074,7 @@ xfs_rename(
2954 */ 3074 */
2955 error = xfs_droplink(tp, target_ip); 3075 error = xfs_droplink(tp, target_ip);
2956 if (error) 3076 if (error)
2957 goto abort_return; 3077 goto out_trans_abort;
2958 3078
2959 if (src_is_directory) { 3079 if (src_is_directory) {
2960 /* 3080 /*
@@ -2962,7 +3082,7 @@ xfs_rename(
2962 */ 3082 */
2963 error = xfs_droplink(tp, target_ip); 3083 error = xfs_droplink(tp, target_ip);
2964 if (error) 3084 if (error)
2965 goto abort_return; 3085 goto out_trans_abort;
2966 } 3086 }
2967 } /* target_ip != NULL */ 3087 } /* target_ip != NULL */
2968 3088
@@ -2979,7 +3099,7 @@ xfs_rename(
2979 &first_block, &free_list, spaceres); 3099 &first_block, &free_list, spaceres);
2980 ASSERT(error != -EEXIST); 3100 ASSERT(error != -EEXIST);
2981 if (error) 3101 if (error)
2982 goto abort_return; 3102 goto out_trans_abort;
2983 } 3103 }
2984 3104
2985 /* 3105 /*
@@ -3005,49 +3125,67 @@ xfs_rename(
3005 */ 3125 */
3006 error = xfs_droplink(tp, src_dp); 3126 error = xfs_droplink(tp, src_dp);
3007 if (error) 3127 if (error)
3008 goto abort_return; 3128 goto out_trans_abort;
3009 } 3129 }
3010 3130
3011 error = xfs_dir_removename(tp, src_dp, src_name, src_ip->i_ino, 3131 /*
3132 * For whiteouts, we only need to update the source dirent with the
3133 * inode number of the whiteout inode rather than removing it
3134 * altogether.
3135 */
3136 if (wip) {
3137 error = xfs_dir_replace(tp, src_dp, src_name, wip->i_ino,
3012 &first_block, &free_list, spaceres); 3138 &first_block, &free_list, spaceres);
3139 } else
3140 error = xfs_dir_removename(tp, src_dp, src_name, src_ip->i_ino,
3141 &first_block, &free_list, spaceres);
3013 if (error) 3142 if (error)
3014 goto abort_return; 3143 goto out_trans_abort;
3015
3016 xfs_trans_ichgtime(tp, src_dp, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG);
3017 xfs_trans_log_inode(tp, src_dp, XFS_ILOG_CORE);
3018 if (new_parent)
3019 xfs_trans_log_inode(tp, target_dp, XFS_ILOG_CORE);
3020 3144
3021finish_rename:
3022 /* 3145 /*
3023 * If this is a synchronous mount, make sure that the 3146 * For whiteouts, we need to bump the link count on the whiteout inode.
3024 * rename transaction goes to disk before returning to 3147 * This means that failures all the way up to this point leave the inode
3025 * the user. 3148 * on the unlinked list and so cleanup is a simple matter of dropping
3149 * the remaining reference to it. If we fail here after bumping the link
3150 * count, we're shutting down the filesystem so we'll never see the
3151 * intermediate state on disk.
3026 */ 3152 */
3027 if (mp->m_flags & (XFS_MOUNT_WSYNC|XFS_MOUNT_DIRSYNC)) { 3153 if (wip) {
3028 xfs_trans_set_sync(tp); 3154 ASSERT(wip->i_d.di_nlink == 0);
3029 } 3155 error = xfs_bumplink(tp, wip);
3156 if (error)
3157 goto out_trans_abort;
3158 error = xfs_iunlink_remove(tp, wip);
3159 if (error)
3160 goto out_trans_abort;
3161 xfs_trans_log_inode(tp, wip, XFS_ILOG_CORE);
3030 3162
3031 error = xfs_bmap_finish(&tp, &free_list, &committed); 3163 /*
3032 if (error) { 3164 * Now we have a real link, clear the "I'm a tmpfile" state
3033 xfs_bmap_cancel(&free_list); 3165 * flag from the inode so it doesn't accidentally get misused in
3034 xfs_trans_cancel(tp, (XFS_TRANS_RELEASE_LOG_RES | 3166 * future.
3035 XFS_TRANS_ABORT)); 3167 */
3036 goto std_return; 3168 VFS_I(wip)->i_state &= ~I_LINKABLE;
3037 } 3169 }
3038 3170
3039 /* 3171 xfs_trans_ichgtime(tp, src_dp, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG);
3040 * trans_commit will unlock src_ip, target_ip & decrement 3172 xfs_trans_log_inode(tp, src_dp, XFS_ILOG_CORE);
3041 * the vnode references. 3173 if (new_parent)
3042 */ 3174 xfs_trans_log_inode(tp, target_dp, XFS_ILOG_CORE);
3043 return xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES);
3044 3175
3045 abort_return: 3176 error = xfs_finish_rename(tp, &free_list);
3177 if (wip)
3178 IRELE(wip);
3179 return error;
3180
3181out_trans_abort:
3046 cancel_flags |= XFS_TRANS_ABORT; 3182 cancel_flags |= XFS_TRANS_ABORT;
3047 error_return: 3183out_bmap_cancel:
3048 xfs_bmap_cancel(&free_list); 3184 xfs_bmap_cancel(&free_list);
3185out_trans_cancel:
3049 xfs_trans_cancel(tp, cancel_flags); 3186 xfs_trans_cancel(tp, cancel_flags);
3050 std_return: 3187 if (wip)
3188 IRELE(wip);
3051 return error; 3189 return error;
3052} 3190}
3053 3191
diff --git a/fs/xfs/xfs_inode.h b/fs/xfs/xfs_inode.h
index a1cd55f3f351..8f22d20368d8 100644
--- a/fs/xfs/xfs_inode.h
+++ b/fs/xfs/xfs_inode.h
@@ -56,6 +56,7 @@ typedef struct xfs_inode {
56 struct xfs_inode_log_item *i_itemp; /* logging information */ 56 struct xfs_inode_log_item *i_itemp; /* logging information */
57 mrlock_t i_lock; /* inode lock */ 57 mrlock_t i_lock; /* inode lock */
58 mrlock_t i_iolock; /* inode IO lock */ 58 mrlock_t i_iolock; /* inode IO lock */
59 mrlock_t i_mmaplock; /* inode mmap IO lock */
59 atomic_t i_pincount; /* inode pin count */ 60 atomic_t i_pincount; /* inode pin count */
60 spinlock_t i_flags_lock; /* inode i_flags lock */ 61 spinlock_t i_flags_lock; /* inode i_flags lock */
61 /* Miscellaneous state. */ 62 /* Miscellaneous state. */
@@ -263,15 +264,20 @@ static inline int xfs_isiflocked(struct xfs_inode *ip)
263#define XFS_IOLOCK_SHARED (1<<1) 264#define XFS_IOLOCK_SHARED (1<<1)
264#define XFS_ILOCK_EXCL (1<<2) 265#define XFS_ILOCK_EXCL (1<<2)
265#define XFS_ILOCK_SHARED (1<<3) 266#define XFS_ILOCK_SHARED (1<<3)
267#define XFS_MMAPLOCK_EXCL (1<<4)
268#define XFS_MMAPLOCK_SHARED (1<<5)
266 269
267#define XFS_LOCK_MASK (XFS_IOLOCK_EXCL | XFS_IOLOCK_SHARED \ 270#define XFS_LOCK_MASK (XFS_IOLOCK_EXCL | XFS_IOLOCK_SHARED \
268 | XFS_ILOCK_EXCL | XFS_ILOCK_SHARED) 271 | XFS_ILOCK_EXCL | XFS_ILOCK_SHARED \
272 | XFS_MMAPLOCK_EXCL | XFS_MMAPLOCK_SHARED)
269 273
270#define XFS_LOCK_FLAGS \ 274#define XFS_LOCK_FLAGS \
271 { XFS_IOLOCK_EXCL, "IOLOCK_EXCL" }, \ 275 { XFS_IOLOCK_EXCL, "IOLOCK_EXCL" }, \
272 { XFS_IOLOCK_SHARED, "IOLOCK_SHARED" }, \ 276 { XFS_IOLOCK_SHARED, "IOLOCK_SHARED" }, \
273 { XFS_ILOCK_EXCL, "ILOCK_EXCL" }, \ 277 { XFS_ILOCK_EXCL, "ILOCK_EXCL" }, \
274 { XFS_ILOCK_SHARED, "ILOCK_SHARED" } 278 { XFS_ILOCK_SHARED, "ILOCK_SHARED" }, \
279 { XFS_MMAPLOCK_EXCL, "MMAPLOCK_EXCL" }, \
280 { XFS_MMAPLOCK_SHARED, "MMAPLOCK_SHARED" }
275 281
276 282
277/* 283/*
@@ -302,17 +308,26 @@ static inline int xfs_isiflocked(struct xfs_inode *ip)
302#define XFS_IOLOCK_SHIFT 16 308#define XFS_IOLOCK_SHIFT 16
303#define XFS_IOLOCK_PARENT (XFS_LOCK_PARENT << XFS_IOLOCK_SHIFT) 309#define XFS_IOLOCK_PARENT (XFS_LOCK_PARENT << XFS_IOLOCK_SHIFT)
304 310
311#define XFS_MMAPLOCK_SHIFT 20
312
305#define XFS_ILOCK_SHIFT 24 313#define XFS_ILOCK_SHIFT 24
306#define XFS_ILOCK_PARENT (XFS_LOCK_PARENT << XFS_ILOCK_SHIFT) 314#define XFS_ILOCK_PARENT (XFS_LOCK_PARENT << XFS_ILOCK_SHIFT)
307#define XFS_ILOCK_RTBITMAP (XFS_LOCK_RTBITMAP << XFS_ILOCK_SHIFT) 315#define XFS_ILOCK_RTBITMAP (XFS_LOCK_RTBITMAP << XFS_ILOCK_SHIFT)
308#define XFS_ILOCK_RTSUM (XFS_LOCK_RTSUM << XFS_ILOCK_SHIFT) 316#define XFS_ILOCK_RTSUM (XFS_LOCK_RTSUM << XFS_ILOCK_SHIFT)
309 317
310#define XFS_IOLOCK_DEP_MASK 0x00ff0000 318#define XFS_IOLOCK_DEP_MASK 0x000f0000
319#define XFS_MMAPLOCK_DEP_MASK 0x00f00000
311#define XFS_ILOCK_DEP_MASK 0xff000000 320#define XFS_ILOCK_DEP_MASK 0xff000000
312#define XFS_LOCK_DEP_MASK (XFS_IOLOCK_DEP_MASK | XFS_ILOCK_DEP_MASK) 321#define XFS_LOCK_DEP_MASK (XFS_IOLOCK_DEP_MASK | \
322 XFS_MMAPLOCK_DEP_MASK | \
323 XFS_ILOCK_DEP_MASK)
313 324
314#define XFS_IOLOCK_DEP(flags) (((flags) & XFS_IOLOCK_DEP_MASK) >> XFS_IOLOCK_SHIFT) 325#define XFS_IOLOCK_DEP(flags) (((flags) & XFS_IOLOCK_DEP_MASK) \
315#define XFS_ILOCK_DEP(flags) (((flags) & XFS_ILOCK_DEP_MASK) >> XFS_ILOCK_SHIFT) 326 >> XFS_IOLOCK_SHIFT)
327#define XFS_MMAPLOCK_DEP(flags) (((flags) & XFS_MMAPLOCK_DEP_MASK) \
328 >> XFS_MMAPLOCK_SHIFT)
329#define XFS_ILOCK_DEP(flags) (((flags) & XFS_ILOCK_DEP_MASK) \
330 >> XFS_ILOCK_SHIFT)
316 331
317/* 332/*
318 * For multiple groups support: if S_ISGID bit is set in the parent 333 * For multiple groups support: if S_ISGID bit is set in the parent
@@ -391,6 +406,28 @@ int xfs_zero_eof(struct xfs_inode *ip, xfs_off_t offset,
391int xfs_iozero(struct xfs_inode *ip, loff_t pos, size_t count); 406int xfs_iozero(struct xfs_inode *ip, loff_t pos, size_t count);
392 407
393 408
409/* from xfs_iops.c */
410/*
411 * When setting up a newly allocated inode, we need to call
412 * xfs_finish_inode_setup() once the inode is fully instantiated at
413 * the VFS level to prevent the rest of the world seeing the inode
414 * before we've completed instantiation. Otherwise we can do it
415 * the moment the inode lookup is complete.
416 */
417extern void xfs_setup_inode(struct xfs_inode *ip);
418static inline void xfs_finish_inode_setup(struct xfs_inode *ip)
419{
420 xfs_iflags_clear(ip, XFS_INEW);
421 barrier();
422 unlock_new_inode(VFS_I(ip));
423}
424
425static inline void xfs_setup_existing_inode(struct xfs_inode *ip)
426{
427 xfs_setup_inode(ip);
428 xfs_finish_inode_setup(ip);
429}
430
394#define IHOLD(ip) \ 431#define IHOLD(ip) \
395do { \ 432do { \
396 ASSERT(atomic_read(&VFS_I(ip)->i_count) > 0) ; \ 433 ASSERT(atomic_read(&VFS_I(ip)->i_count) > 0) ; \
diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
index ac4feae45eb3..87f67c6b654c 100644
--- a/fs/xfs/xfs_ioctl.c
+++ b/fs/xfs/xfs_ioctl.c
@@ -82,7 +82,7 @@ xfs_find_handle(
82 error = user_lpath((const char __user *)hreq->path, &path); 82 error = user_lpath((const char __user *)hreq->path, &path);
83 if (error) 83 if (error)
84 return error; 84 return error;
85 inode = path.dentry->d_inode; 85 inode = d_inode(path.dentry);
86 } 86 }
87 ip = XFS_I(inode); 87 ip = XFS_I(inode);
88 88
@@ -210,7 +210,7 @@ xfs_open_by_handle(
210 dentry = xfs_handlereq_to_dentry(parfilp, hreq); 210 dentry = xfs_handlereq_to_dentry(parfilp, hreq);
211 if (IS_ERR(dentry)) 211 if (IS_ERR(dentry))
212 return PTR_ERR(dentry); 212 return PTR_ERR(dentry);
213 inode = dentry->d_inode; 213 inode = d_inode(dentry);
214 214
215 /* Restrict xfs_open_by_handle to directories & regular files. */ 215 /* Restrict xfs_open_by_handle to directories & regular files. */
216 if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode))) { 216 if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode))) {
@@ -303,7 +303,7 @@ xfs_readlink_by_handle(
303 goto out_dput; 303 goto out_dput;
304 } 304 }
305 305
306 error = xfs_readlink(XFS_I(dentry->d_inode), link); 306 error = xfs_readlink(XFS_I(d_inode(dentry)), link);
307 if (error) 307 if (error)
308 goto out_kfree; 308 goto out_kfree;
309 error = readlink_copy(hreq->ohandle, olen, link); 309 error = readlink_copy(hreq->ohandle, olen, link);
@@ -376,7 +376,7 @@ xfs_fssetdm_by_handle(
376 return PTR_ERR(dentry); 376 return PTR_ERR(dentry);
377 } 377 }
378 378
379 if (IS_IMMUTABLE(dentry->d_inode) || IS_APPEND(dentry->d_inode)) { 379 if (IS_IMMUTABLE(d_inode(dentry)) || IS_APPEND(d_inode(dentry))) {
380 error = -EPERM; 380 error = -EPERM;
381 goto out; 381 goto out;
382 } 382 }
@@ -386,7 +386,7 @@ xfs_fssetdm_by_handle(
386 goto out; 386 goto out;
387 } 387 }
388 388
389 error = xfs_set_dmattrs(XFS_I(dentry->d_inode), fsd.fsd_dmevmask, 389 error = xfs_set_dmattrs(XFS_I(d_inode(dentry)), fsd.fsd_dmevmask,
390 fsd.fsd_dmstate); 390 fsd.fsd_dmstate);
391 391
392 out: 392 out:
@@ -429,7 +429,7 @@ xfs_attrlist_by_handle(
429 goto out_dput; 429 goto out_dput;
430 430
431 cursor = (attrlist_cursor_kern_t *)&al_hreq.pos; 431 cursor = (attrlist_cursor_kern_t *)&al_hreq.pos;
432 error = xfs_attr_list(XFS_I(dentry->d_inode), kbuf, al_hreq.buflen, 432 error = xfs_attr_list(XFS_I(d_inode(dentry)), kbuf, al_hreq.buflen,
433 al_hreq.flags, cursor); 433 al_hreq.flags, cursor);
434 if (error) 434 if (error)
435 goto out_kfree; 435 goto out_kfree;
@@ -559,7 +559,7 @@ xfs_attrmulti_by_handle(
559 switch (ops[i].am_opcode) { 559 switch (ops[i].am_opcode) {
560 case ATTR_OP_GET: 560 case ATTR_OP_GET:
561 ops[i].am_error = xfs_attrmulti_attr_get( 561 ops[i].am_error = xfs_attrmulti_attr_get(
562 dentry->d_inode, attr_name, 562 d_inode(dentry), attr_name,
563 ops[i].am_attrvalue, &ops[i].am_length, 563 ops[i].am_attrvalue, &ops[i].am_length,
564 ops[i].am_flags); 564 ops[i].am_flags);
565 break; 565 break;
@@ -568,7 +568,7 @@ xfs_attrmulti_by_handle(
568 if (ops[i].am_error) 568 if (ops[i].am_error)
569 break; 569 break;
570 ops[i].am_error = xfs_attrmulti_attr_set( 570 ops[i].am_error = xfs_attrmulti_attr_set(
571 dentry->d_inode, attr_name, 571 d_inode(dentry), attr_name,
572 ops[i].am_attrvalue, ops[i].am_length, 572 ops[i].am_attrvalue, ops[i].am_length,
573 ops[i].am_flags); 573 ops[i].am_flags);
574 mnt_drop_write_file(parfilp); 574 mnt_drop_write_file(parfilp);
@@ -578,7 +578,7 @@ xfs_attrmulti_by_handle(
578 if (ops[i].am_error) 578 if (ops[i].am_error)
579 break; 579 break;
580 ops[i].am_error = xfs_attrmulti_attr_remove( 580 ops[i].am_error = xfs_attrmulti_attr_remove(
581 dentry->d_inode, attr_name, 581 d_inode(dentry), attr_name,
582 ops[i].am_flags); 582 ops[i].am_flags);
583 mnt_drop_write_file(parfilp); 583 mnt_drop_write_file(parfilp);
584 break; 584 break;
@@ -631,7 +631,7 @@ xfs_ioc_space(
631 631
632 if (filp->f_flags & O_DSYNC) 632 if (filp->f_flags & O_DSYNC)
633 flags |= XFS_PREALLOC_SYNC; 633 flags |= XFS_PREALLOC_SYNC;
634 if (ioflags & XFS_IO_INVIS) 634 if (ioflags & XFS_IO_INVIS)
635 flags |= XFS_PREALLOC_INVISIBLE; 635 flags |= XFS_PREALLOC_INVISIBLE;
636 636
637 error = mnt_want_write_file(filp); 637 error = mnt_want_write_file(filp);
@@ -639,10 +639,13 @@ xfs_ioc_space(
639 return error; 639 return error;
640 640
641 xfs_ilock(ip, iolock); 641 xfs_ilock(ip, iolock);
642 error = xfs_break_layouts(inode, &iolock); 642 error = xfs_break_layouts(inode, &iolock, false);
643 if (error) 643 if (error)
644 goto out_unlock; 644 goto out_unlock;
645 645
646 xfs_ilock(ip, XFS_MMAPLOCK_EXCL);
647 iolock |= XFS_MMAPLOCK_EXCL;
648
646 switch (bf->l_whence) { 649 switch (bf->l_whence) {
647 case 0: /*SEEK_SET*/ 650 case 0: /*SEEK_SET*/
648 break; 651 break;
diff --git a/fs/xfs/xfs_ioctl32.c b/fs/xfs/xfs_ioctl32.c
index bfc7c7c8a0c8..b88bdc85dd3d 100644
--- a/fs/xfs/xfs_ioctl32.c
+++ b/fs/xfs/xfs_ioctl32.c
@@ -375,7 +375,7 @@ xfs_compat_attrlist_by_handle(
375 goto out_dput; 375 goto out_dput;
376 376
377 cursor = (attrlist_cursor_kern_t *)&al_hreq.pos; 377 cursor = (attrlist_cursor_kern_t *)&al_hreq.pos;
378 error = xfs_attr_list(XFS_I(dentry->d_inode), kbuf, al_hreq.buflen, 378 error = xfs_attr_list(XFS_I(d_inode(dentry)), kbuf, al_hreq.buflen,
379 al_hreq.flags, cursor); 379 al_hreq.flags, cursor);
380 if (error) 380 if (error)
381 goto out_kfree; 381 goto out_kfree;
@@ -445,7 +445,7 @@ xfs_compat_attrmulti_by_handle(
445 switch (ops[i].am_opcode) { 445 switch (ops[i].am_opcode) {
446 case ATTR_OP_GET: 446 case ATTR_OP_GET:
447 ops[i].am_error = xfs_attrmulti_attr_get( 447 ops[i].am_error = xfs_attrmulti_attr_get(
448 dentry->d_inode, attr_name, 448 d_inode(dentry), attr_name,
449 compat_ptr(ops[i].am_attrvalue), 449 compat_ptr(ops[i].am_attrvalue),
450 &ops[i].am_length, ops[i].am_flags); 450 &ops[i].am_length, ops[i].am_flags);
451 break; 451 break;
@@ -454,7 +454,7 @@ xfs_compat_attrmulti_by_handle(
454 if (ops[i].am_error) 454 if (ops[i].am_error)
455 break; 455 break;
456 ops[i].am_error = xfs_attrmulti_attr_set( 456 ops[i].am_error = xfs_attrmulti_attr_set(
457 dentry->d_inode, attr_name, 457 d_inode(dentry), attr_name,
458 compat_ptr(ops[i].am_attrvalue), 458 compat_ptr(ops[i].am_attrvalue),
459 ops[i].am_length, ops[i].am_flags); 459 ops[i].am_length, ops[i].am_flags);
460 mnt_drop_write_file(parfilp); 460 mnt_drop_write_file(parfilp);
@@ -464,7 +464,7 @@ xfs_compat_attrmulti_by_handle(
464 if (ops[i].am_error) 464 if (ops[i].am_error)
465 break; 465 break;
466 ops[i].am_error = xfs_attrmulti_attr_remove( 466 ops[i].am_error = xfs_attrmulti_attr_remove(
467 dentry->d_inode, attr_name, 467 d_inode(dentry), attr_name,
468 ops[i].am_flags); 468 ops[i].am_flags);
469 mnt_drop_write_file(parfilp); 469 mnt_drop_write_file(parfilp);
470 break; 470 break;
@@ -504,7 +504,7 @@ xfs_compat_fssetdm_by_handle(
504 if (IS_ERR(dentry)) 504 if (IS_ERR(dentry))
505 return PTR_ERR(dentry); 505 return PTR_ERR(dentry);
506 506
507 if (IS_IMMUTABLE(dentry->d_inode) || IS_APPEND(dentry->d_inode)) { 507 if (IS_IMMUTABLE(d_inode(dentry)) || IS_APPEND(d_inode(dentry))) {
508 error = -EPERM; 508 error = -EPERM;
509 goto out; 509 goto out;
510 } 510 }
@@ -514,7 +514,7 @@ xfs_compat_fssetdm_by_handle(
514 goto out; 514 goto out;
515 } 515 }
516 516
517 error = xfs_set_dmattrs(XFS_I(dentry->d_inode), fsd.fsd_dmevmask, 517 error = xfs_set_dmattrs(XFS_I(d_inode(dentry)), fsd.fsd_dmevmask,
518 fsd.fsd_dmstate); 518 fsd.fsd_dmstate);
519 519
520out: 520out:
diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c
index ccb1dd0d509e..38e633bad8c2 100644
--- a/fs/xfs/xfs_iomap.c
+++ b/fs/xfs/xfs_iomap.c
@@ -460,8 +460,7 @@ xfs_iomap_prealloc_size(
460 alloc_blocks = XFS_FILEOFF_MIN(roundup_pow_of_two(MAXEXTLEN), 460 alloc_blocks = XFS_FILEOFF_MIN(roundup_pow_of_two(MAXEXTLEN),
461 alloc_blocks); 461 alloc_blocks);
462 462
463 xfs_icsb_sync_counters(mp, XFS_ICSB_LAZY_COUNT); 463 freesp = percpu_counter_read_positive(&mp->m_fdblocks);
464 freesp = mp->m_sb.sb_fdblocks;
465 if (freesp < mp->m_low_space[XFS_LOWSP_5_PCNT]) { 464 if (freesp < mp->m_low_space[XFS_LOWSP_5_PCNT]) {
466 shift = 2; 465 shift = 2;
467 if (freesp < mp->m_low_space[XFS_LOWSP_4_PCNT]) 466 if (freesp < mp->m_low_space[XFS_LOWSP_4_PCNT])
diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
index e53a90331422..f4cd7204e236 100644
--- a/fs/xfs/xfs_iops.c
+++ b/fs/xfs/xfs_iops.c
@@ -187,6 +187,8 @@ xfs_generic_create(
187 else 187 else
188 d_instantiate(dentry, inode); 188 d_instantiate(dentry, inode);
189 189
190 xfs_finish_inode_setup(ip);
191
190 out_free_acl: 192 out_free_acl:
191 if (default_acl) 193 if (default_acl)
192 posix_acl_release(default_acl); 194 posix_acl_release(default_acl);
@@ -195,6 +197,7 @@ xfs_generic_create(
195 return error; 197 return error;
196 198
197 out_cleanup_inode: 199 out_cleanup_inode:
200 xfs_finish_inode_setup(ip);
198 if (!tmpfile) 201 if (!tmpfile)
199 xfs_cleanup_inode(dir, inode, dentry); 202 xfs_cleanup_inode(dir, inode, dentry);
200 iput(inode); 203 iput(inode);
@@ -301,7 +304,7 @@ xfs_vn_link(
301 struct inode *dir, 304 struct inode *dir,
302 struct dentry *dentry) 305 struct dentry *dentry)
303{ 306{
304 struct inode *inode = old_dentry->d_inode; 307 struct inode *inode = d_inode(old_dentry);
305 struct xfs_name name; 308 struct xfs_name name;
306 int error; 309 int error;
307 310
@@ -326,7 +329,7 @@ xfs_vn_unlink(
326 329
327 xfs_dentry_to_name(&name, dentry, 0); 330 xfs_dentry_to_name(&name, dentry, 0);
328 331
329 error = xfs_remove(XFS_I(dir), &name, XFS_I(dentry->d_inode)); 332 error = xfs_remove(XFS_I(dir), &name, XFS_I(d_inode(dentry)));
330 if (error) 333 if (error)
331 return error; 334 return error;
332 335
@@ -367,9 +370,11 @@ xfs_vn_symlink(
367 goto out_cleanup_inode; 370 goto out_cleanup_inode;
368 371
369 d_instantiate(dentry, inode); 372 d_instantiate(dentry, inode);
373 xfs_finish_inode_setup(cip);
370 return 0; 374 return 0;
371 375
372 out_cleanup_inode: 376 out_cleanup_inode:
377 xfs_finish_inode_setup(cip);
373 xfs_cleanup_inode(dir, inode, dentry); 378 xfs_cleanup_inode(dir, inode, dentry);
374 iput(inode); 379 iput(inode);
375 out: 380 out:
@@ -384,22 +389,22 @@ xfs_vn_rename(
384 struct dentry *ndentry, 389 struct dentry *ndentry,
385 unsigned int flags) 390 unsigned int flags)
386{ 391{
387 struct inode *new_inode = ndentry->d_inode; 392 struct inode *new_inode = d_inode(ndentry);
388 int omode = 0; 393 int omode = 0;
389 struct xfs_name oname; 394 struct xfs_name oname;
390 struct xfs_name nname; 395 struct xfs_name nname;
391 396
392 if (flags & ~(RENAME_NOREPLACE | RENAME_EXCHANGE)) 397 if (flags & ~(RENAME_NOREPLACE | RENAME_EXCHANGE | RENAME_WHITEOUT))
393 return -EINVAL; 398 return -EINVAL;
394 399
395 /* if we are exchanging files, we need to set i_mode of both files */ 400 /* if we are exchanging files, we need to set i_mode of both files */
396 if (flags & RENAME_EXCHANGE) 401 if (flags & RENAME_EXCHANGE)
397 omode = ndentry->d_inode->i_mode; 402 omode = d_inode(ndentry)->i_mode;
398 403
399 xfs_dentry_to_name(&oname, odentry, omode); 404 xfs_dentry_to_name(&oname, odentry, omode);
400 xfs_dentry_to_name(&nname, ndentry, odentry->d_inode->i_mode); 405 xfs_dentry_to_name(&nname, ndentry, d_inode(odentry)->i_mode);
401 406
402 return xfs_rename(XFS_I(odir), &oname, XFS_I(odentry->d_inode), 407 return xfs_rename(XFS_I(odir), &oname, XFS_I(d_inode(odentry)),
403 XFS_I(ndir), &nname, 408 XFS_I(ndir), &nname,
404 new_inode ? XFS_I(new_inode) : NULL, flags); 409 new_inode ? XFS_I(new_inode) : NULL, flags);
405} 410}
@@ -421,7 +426,7 @@ xfs_vn_follow_link(
421 if (!link) 426 if (!link)
422 goto out_err; 427 goto out_err;
423 428
424 error = xfs_readlink(XFS_I(dentry->d_inode), link); 429 error = xfs_readlink(XFS_I(d_inode(dentry)), link);
425 if (unlikely(error)) 430 if (unlikely(error))
426 goto out_kfree; 431 goto out_kfree;
427 432
@@ -441,7 +446,7 @@ xfs_vn_getattr(
441 struct dentry *dentry, 446 struct dentry *dentry,
442 struct kstat *stat) 447 struct kstat *stat)
443{ 448{
444 struct inode *inode = dentry->d_inode; 449 struct inode *inode = d_inode(dentry);
445 struct xfs_inode *ip = XFS_I(inode); 450 struct xfs_inode *ip = XFS_I(inode);
446 struct xfs_mount *mp = ip->i_mount; 451 struct xfs_mount *mp = ip->i_mount;
447 452
@@ -766,6 +771,7 @@ xfs_setattr_size(
766 return error; 771 return error;
767 772
768 ASSERT(xfs_isilocked(ip, XFS_IOLOCK_EXCL)); 773 ASSERT(xfs_isilocked(ip, XFS_IOLOCK_EXCL));
774 ASSERT(xfs_isilocked(ip, XFS_MMAPLOCK_EXCL));
769 ASSERT(S_ISREG(ip->i_d.di_mode)); 775 ASSERT(S_ISREG(ip->i_d.di_mode));
770 ASSERT((iattr->ia_valid & (ATTR_UID|ATTR_GID|ATTR_ATIME|ATTR_ATIME_SET| 776 ASSERT((iattr->ia_valid & (ATTR_UID|ATTR_GID|ATTR_ATIME|ATTR_ATIME_SET|
771 ATTR_MTIME_SET|ATTR_KILL_PRIV|ATTR_TIMES_SET)) == 0); 777 ATTR_MTIME_SET|ATTR_KILL_PRIV|ATTR_TIMES_SET)) == 0);
@@ -829,55 +835,27 @@ xfs_setattr_size(
829 inode_dio_wait(inode); 835 inode_dio_wait(inode);
830 836
831 /* 837 /*
832 * Do all the page cache truncate work outside the transaction context 838 * We've already locked out new page faults, so now we can safely remove
833 * as the "lock" order is page lock->log space reservation. i.e. 839 * pages from the page cache knowing they won't get refaulted until we
834 * locking pages inside the transaction can ABBA deadlock with 840 * drop the XFS_MMAP_EXCL lock after the extent manipulations are
835 * writeback. We have to do the VFS inode size update before we truncate 841 * complete. The truncate_setsize() call also cleans partial EOF page
836 * the pagecache, however, to avoid racing with page faults beyond the 842 * PTEs on extending truncates and hence ensures sub-page block size
837 * new EOF they are not serialised against truncate operations except by 843 * filesystems are correctly handled, too.
838 * page locks and size updates.
839 * 844 *
840 * Hence we are in a situation where a truncate can fail with ENOMEM 845 * We have to do all the page cache truncate work outside the
841 * from xfs_trans_reserve(), but having already truncated the in-memory 846 * transaction context as the "lock" order is page lock->log space
842 * version of the file (i.e. made user visible changes). There's not 847 * reservation as defined by extent allocation in the writeback path.
843 * much we can do about this, except to hope that the caller sees ENOMEM 848 * Hence a truncate can fail with ENOMEM from xfs_trans_reserve(), but
844 * and retries the truncate operation. 849 * having already truncated the in-memory version of the file (i.e. made
850 * user visible changes). There's not much we can do about this, except
851 * to hope that the caller sees ENOMEM and retries the truncate
852 * operation.
845 */ 853 */
846 error = block_truncate_page(inode->i_mapping, newsize, xfs_get_blocks); 854 error = block_truncate_page(inode->i_mapping, newsize, xfs_get_blocks);
847 if (error) 855 if (error)
848 return error; 856 return error;
849 truncate_setsize(inode, newsize); 857 truncate_setsize(inode, newsize);
850 858
851 /*
852 * The "we can't serialise against page faults" pain gets worse.
853 *
854 * If the file is mapped then we have to clean the page at the old EOF
855 * when extending the file. Extending the file can expose changes the
856 * underlying page mapping (e.g. from beyond EOF to a hole or
857 * unwritten), and so on the next attempt to write to that page we need
858 * to remap it for write. i.e. we need .page_mkwrite() to be called.
859 * Hence we need to clean the page to clean the pte and so a new write
860 * fault will be triggered appropriately.
861 *
862 * If we do it before we change the inode size, then we can race with a
863 * page fault that maps the page with exactly the same problem. If we do
864 * it after we change the file size, then a new page fault can come in
865 * and allocate space before we've run the rest of the truncate
866 * transaction. That's kinda grotesque, but it's better than have data
867 * over a hole, and so that's the lesser evil that has been chosen here.
868 *
869 * The real solution, however, is to have some mechanism for locking out
870 * page faults while a truncate is in progress.
871 */
872 if (newsize > oldsize && mapping_mapped(VFS_I(ip)->i_mapping)) {
873 error = filemap_write_and_wait_range(
874 VFS_I(ip)->i_mapping,
875 round_down(oldsize, PAGE_CACHE_SIZE),
876 round_up(oldsize, PAGE_CACHE_SIZE) - 1);
877 if (error)
878 return error;
879 }
880
881 tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_SIZE); 859 tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_SIZE);
882 error = xfs_trans_reserve(tp, &M_RES(mp)->tr_itruncate, 0, 0); 860 error = xfs_trans_reserve(tp, &M_RES(mp)->tr_itruncate, 0, 0);
883 if (error) 861 if (error)
@@ -968,16 +946,20 @@ xfs_vn_setattr(
968 struct dentry *dentry, 946 struct dentry *dentry,
969 struct iattr *iattr) 947 struct iattr *iattr)
970{ 948{
971 struct xfs_inode *ip = XFS_I(dentry->d_inode); 949 struct xfs_inode *ip = XFS_I(d_inode(dentry));
972 int error; 950 int error;
973 951
974 if (iattr->ia_valid & ATTR_SIZE) { 952 if (iattr->ia_valid & ATTR_SIZE) {
975 uint iolock = XFS_IOLOCK_EXCL; 953 uint iolock = XFS_IOLOCK_EXCL;
976 954
977 xfs_ilock(ip, iolock); 955 xfs_ilock(ip, iolock);
978 error = xfs_break_layouts(dentry->d_inode, &iolock); 956 error = xfs_break_layouts(d_inode(dentry), &iolock, true);
979 if (!error) 957 if (!error) {
958 xfs_ilock(ip, XFS_MMAPLOCK_EXCL);
959 iolock |= XFS_MMAPLOCK_EXCL;
960
980 error = xfs_setattr_size(ip, iattr); 961 error = xfs_setattr_size(ip, iattr);
962 }
981 xfs_iunlock(ip, iolock); 963 xfs_iunlock(ip, iolock);
982 } else { 964 } else {
983 error = xfs_setattr_nonsize(ip, iattr, 0); 965 error = xfs_setattr_nonsize(ip, iattr, 0);
@@ -1228,16 +1210,12 @@ xfs_diflags_to_iflags(
1228} 1210}
1229 1211
1230/* 1212/*
1231 * Initialize the Linux inode, set up the operation vectors and 1213 * Initialize the Linux inode and set up the operation vectors.
1232 * unlock the inode.
1233 * 1214 *
1234 * When reading existing inodes from disk this is called directly 1215 * When reading existing inodes from disk this is called directly from xfs_iget,
1235 * from xfs_iget, when creating a new inode it is called from 1216 * when creating a new inode it is called from xfs_ialloc after setting up the
1236 * xfs_ialloc after setting up the inode. 1217 * inode. These callers have different criteria for clearing XFS_INEW, so leave
1237 * 1218 * it up to the caller to deal with unlocking the inode appropriately.
1238 * We are always called with an uninitialised linux inode here.
1239 * We need to initialise the necessary fields and take a reference
1240 * on it.
1241 */ 1219 */
1242void 1220void
1243xfs_setup_inode( 1221xfs_setup_inode(
@@ -1324,9 +1302,4 @@ xfs_setup_inode(
1324 inode_has_no_xattr(inode); 1302 inode_has_no_xattr(inode);
1325 cache_no_acl(inode); 1303 cache_no_acl(inode);
1326 } 1304 }
1327
1328 xfs_iflags_clear(ip, XFS_INEW);
1329 barrier();
1330
1331 unlock_new_inode(inode);
1332} 1305}
diff --git a/fs/xfs/xfs_iops.h b/fs/xfs/xfs_iops.h
index ea7a98e9cb70..a0f84abb0d09 100644
--- a/fs/xfs/xfs_iops.h
+++ b/fs/xfs/xfs_iops.h
@@ -25,8 +25,6 @@ extern const struct file_operations xfs_dir_file_operations;
25 25
26extern ssize_t xfs_vn_listxattr(struct dentry *, char *data, size_t size); 26extern ssize_t xfs_vn_listxattr(struct dentry *, char *data, size_t size);
27 27
28extern void xfs_setup_inode(struct xfs_inode *);
29
30/* 28/*
31 * Internal setattr interfaces. 29 * Internal setattr interfaces.
32 */ 30 */
diff --git a/fs/xfs/xfs_itable.c b/fs/xfs/xfs_itable.c
index 82e314258f73..80429891dc9b 100644
--- a/fs/xfs/xfs_itable.c
+++ b/fs/xfs/xfs_itable.c
@@ -229,7 +229,7 @@ xfs_bulkstat_grab_ichunk(
229 error = xfs_inobt_get_rec(cur, irec, &stat); 229 error = xfs_inobt_get_rec(cur, irec, &stat);
230 if (error) 230 if (error)
231 return error; 231 return error;
232 XFS_WANT_CORRUPTED_RETURN(stat == 1); 232 XFS_WANT_CORRUPTED_RETURN(cur->bc_mp, stat == 1);
233 233
234 /* Check if the record contains the inode in request */ 234 /* Check if the record contains the inode in request */
235 if (irec->ir_startino + XFS_INODES_PER_CHUNK <= agino) { 235 if (irec->ir_startino + XFS_INODES_PER_CHUNK <= agino) {
diff --git a/fs/xfs/xfs_linux.h b/fs/xfs/xfs_linux.h
index c31d2c2eadc4..7c7842c85a08 100644
--- a/fs/xfs/xfs_linux.h
+++ b/fs/xfs/xfs_linux.h
@@ -116,15 +116,6 @@ typedef __uint64_t __psunsigned_t;
116#undef XFS_NATIVE_HOST 116#undef XFS_NATIVE_HOST
117#endif 117#endif
118 118
119/*
120 * Feature macros (disable/enable)
121 */
122#ifdef CONFIG_SMP
123#define HAVE_PERCPU_SB /* per cpu superblock counters are a 2.6 feature */
124#else
125#undef HAVE_PERCPU_SB /* per cpu superblock counters are a 2.6 feature */
126#endif
127
128#define irix_sgid_inherit xfs_params.sgid_inherit.val 119#define irix_sgid_inherit xfs_params.sgid_inherit.val
129#define irix_symlink_mode xfs_params.symlink_mode.val 120#define irix_symlink_mode xfs_params.symlink_mode.val
130#define xfs_panic_mask xfs_params.panic_mask.val 121#define xfs_panic_mask xfs_params.panic_mask.val
diff --git a/fs/xfs/xfs_log_recover.c b/fs/xfs/xfs_log_recover.c
index a5a945fc3bdc..4f5784f85a5b 100644
--- a/fs/xfs/xfs_log_recover.c
+++ b/fs/xfs/xfs_log_recover.c
@@ -4463,10 +4463,10 @@ xlog_do_recover(
4463 xfs_sb_from_disk(sbp, XFS_BUF_TO_SBP(bp)); 4463 xfs_sb_from_disk(sbp, XFS_BUF_TO_SBP(bp));
4464 ASSERT(sbp->sb_magicnum == XFS_SB_MAGIC); 4464 ASSERT(sbp->sb_magicnum == XFS_SB_MAGIC);
4465 ASSERT(xfs_sb_good_version(sbp)); 4465 ASSERT(xfs_sb_good_version(sbp));
4466 xfs_reinit_percpu_counters(log->l_mp);
4467
4466 xfs_buf_relse(bp); 4468 xfs_buf_relse(bp);
4467 4469
4468 /* We've re-read the superblock so re-initialize per-cpu counters */
4469 xfs_icsb_reinit_counters(log->l_mp);
4470 4470
4471 xlog_recover_check_summary(log); 4471 xlog_recover_check_summary(log);
4472 4472
diff --git a/fs/xfs/xfs_mount.c b/fs/xfs/xfs_mount.c
index 4fa80e63eea2..2ce7ee3b4ec1 100644
--- a/fs/xfs/xfs_mount.c
+++ b/fs/xfs/xfs_mount.c
@@ -43,18 +43,6 @@
43#include "xfs_sysfs.h" 43#include "xfs_sysfs.h"
44 44
45 45
46#ifdef HAVE_PERCPU_SB
47STATIC void xfs_icsb_balance_counter(xfs_mount_t *, xfs_sb_field_t,
48 int);
49STATIC void xfs_icsb_balance_counter_locked(xfs_mount_t *, xfs_sb_field_t,
50 int);
51STATIC void xfs_icsb_disable_counter(xfs_mount_t *, xfs_sb_field_t);
52#else
53
54#define xfs_icsb_balance_counter(mp, a, b) do { } while (0)
55#define xfs_icsb_balance_counter_locked(mp, a, b) do { } while (0)
56#endif
57
58static DEFINE_MUTEX(xfs_uuid_table_mutex); 46static DEFINE_MUTEX(xfs_uuid_table_mutex);
59static int xfs_uuid_table_size; 47static int xfs_uuid_table_size;
60static uuid_t *xfs_uuid_table; 48static uuid_t *xfs_uuid_table;
@@ -347,8 +335,7 @@ reread:
347 goto reread; 335 goto reread;
348 } 336 }
349 337
350 /* Initialize per-cpu counters */ 338 xfs_reinit_percpu_counters(mp);
351 xfs_icsb_reinit_counters(mp);
352 339
353 /* no need to be quiet anymore, so reset the buf ops */ 340 /* no need to be quiet anymore, so reset the buf ops */
354 bp->b_ops = &xfs_sb_buf_ops; 341 bp->b_ops = &xfs_sb_buf_ops;
@@ -1087,8 +1074,6 @@ xfs_log_sbcount(xfs_mount_t *mp)
1087 if (!xfs_fs_writable(mp, SB_FREEZE_COMPLETE)) 1074 if (!xfs_fs_writable(mp, SB_FREEZE_COMPLETE))
1088 return 0; 1075 return 0;
1089 1076
1090 xfs_icsb_sync_counters(mp, 0);
1091
1092 /* 1077 /*
1093 * we don't need to do this if we are updating the superblock 1078 * we don't need to do this if we are updating the superblock
1094 * counters on every modification. 1079 * counters on every modification.
@@ -1099,253 +1084,136 @@ xfs_log_sbcount(xfs_mount_t *mp)
1099 return xfs_sync_sb(mp, true); 1084 return xfs_sync_sb(mp, true);
1100} 1085}
1101 1086
1102/* 1087int
1103 * xfs_mod_incore_sb_unlocked() is a utility routine commonly used to apply 1088xfs_mod_icount(
1104 * a delta to a specified field in the in-core superblock. Simply 1089 struct xfs_mount *mp,
1105 * switch on the field indicated and apply the delta to that field. 1090 int64_t delta)
1106 * Fields are not allowed to dip below zero, so if the delta would
1107 * do this do not apply it and return EINVAL.
1108 *
1109 * The m_sb_lock must be held when this routine is called.
1110 */
1111STATIC int
1112xfs_mod_incore_sb_unlocked(
1113 xfs_mount_t *mp,
1114 xfs_sb_field_t field,
1115 int64_t delta,
1116 int rsvd)
1117{ 1091{
1118 int scounter; /* short counter for 32 bit fields */ 1092 /* deltas are +/-64, hence the large batch size of 128. */
1119 long long lcounter; /* long counter for 64 bit fields */ 1093 __percpu_counter_add(&mp->m_icount, delta, 128);
1120 long long res_used, rem; 1094 if (percpu_counter_compare(&mp->m_icount, 0) < 0) {
1121
1122 /*
1123 * With the in-core superblock spin lock held, switch
1124 * on the indicated field. Apply the delta to the
1125 * proper field. If the fields value would dip below
1126 * 0, then do not apply the delta and return EINVAL.
1127 */
1128 switch (field) {
1129 case XFS_SBS_ICOUNT:
1130 lcounter = (long long)mp->m_sb.sb_icount;
1131 lcounter += delta;
1132 if (lcounter < 0) {
1133 ASSERT(0);
1134 return -EINVAL;
1135 }
1136 mp->m_sb.sb_icount = lcounter;
1137 return 0;
1138 case XFS_SBS_IFREE:
1139 lcounter = (long long)mp->m_sb.sb_ifree;
1140 lcounter += delta;
1141 if (lcounter < 0) {
1142 ASSERT(0);
1143 return -EINVAL;
1144 }
1145 mp->m_sb.sb_ifree = lcounter;
1146 return 0;
1147 case XFS_SBS_FDBLOCKS:
1148 lcounter = (long long)
1149 mp->m_sb.sb_fdblocks - XFS_ALLOC_SET_ASIDE(mp);
1150 res_used = (long long)(mp->m_resblks - mp->m_resblks_avail);
1151
1152 if (delta > 0) { /* Putting blocks back */
1153 if (res_used > delta) {
1154 mp->m_resblks_avail += delta;
1155 } else {
1156 rem = delta - res_used;
1157 mp->m_resblks_avail = mp->m_resblks;
1158 lcounter += rem;
1159 }
1160 } else { /* Taking blocks away */
1161 lcounter += delta;
1162 if (lcounter >= 0) {
1163 mp->m_sb.sb_fdblocks = lcounter +
1164 XFS_ALLOC_SET_ASIDE(mp);
1165 return 0;
1166 }
1167
1168 /*
1169 * We are out of blocks, use any available reserved
1170 * blocks if were allowed to.
1171 */
1172 if (!rsvd)
1173 return -ENOSPC;
1174
1175 lcounter = (long long)mp->m_resblks_avail + delta;
1176 if (lcounter >= 0) {
1177 mp->m_resblks_avail = lcounter;
1178 return 0;
1179 }
1180 printk_once(KERN_WARNING
1181 "Filesystem \"%s\": reserve blocks depleted! "
1182 "Consider increasing reserve pool size.",
1183 mp->m_fsname);
1184 return -ENOSPC;
1185 }
1186
1187 mp->m_sb.sb_fdblocks = lcounter + XFS_ALLOC_SET_ASIDE(mp);
1188 return 0;
1189 case XFS_SBS_FREXTENTS:
1190 lcounter = (long long)mp->m_sb.sb_frextents;
1191 lcounter += delta;
1192 if (lcounter < 0) {
1193 return -ENOSPC;
1194 }
1195 mp->m_sb.sb_frextents = lcounter;
1196 return 0;
1197 case XFS_SBS_DBLOCKS:
1198 lcounter = (long long)mp->m_sb.sb_dblocks;
1199 lcounter += delta;
1200 if (lcounter < 0) {
1201 ASSERT(0);
1202 return -EINVAL;
1203 }
1204 mp->m_sb.sb_dblocks = lcounter;
1205 return 0;
1206 case XFS_SBS_AGCOUNT:
1207 scounter = mp->m_sb.sb_agcount;
1208 scounter += delta;
1209 if (scounter < 0) {
1210 ASSERT(0);
1211 return -EINVAL;
1212 }
1213 mp->m_sb.sb_agcount = scounter;
1214 return 0;
1215 case XFS_SBS_IMAX_PCT:
1216 scounter = mp->m_sb.sb_imax_pct;
1217 scounter += delta;
1218 if (scounter < 0) {
1219 ASSERT(0);
1220 return -EINVAL;
1221 }
1222 mp->m_sb.sb_imax_pct = scounter;
1223 return 0;
1224 case XFS_SBS_REXTSIZE:
1225 scounter = mp->m_sb.sb_rextsize;
1226 scounter += delta;
1227 if (scounter < 0) {
1228 ASSERT(0);
1229 return -EINVAL;
1230 }
1231 mp->m_sb.sb_rextsize = scounter;
1232 return 0;
1233 case XFS_SBS_RBMBLOCKS:
1234 scounter = mp->m_sb.sb_rbmblocks;
1235 scounter += delta;
1236 if (scounter < 0) {
1237 ASSERT(0);
1238 return -EINVAL;
1239 }
1240 mp->m_sb.sb_rbmblocks = scounter;
1241 return 0;
1242 case XFS_SBS_RBLOCKS:
1243 lcounter = (long long)mp->m_sb.sb_rblocks;
1244 lcounter += delta;
1245 if (lcounter < 0) {
1246 ASSERT(0);
1247 return -EINVAL;
1248 }
1249 mp->m_sb.sb_rblocks = lcounter;
1250 return 0;
1251 case XFS_SBS_REXTENTS:
1252 lcounter = (long long)mp->m_sb.sb_rextents;
1253 lcounter += delta;
1254 if (lcounter < 0) {
1255 ASSERT(0);
1256 return -EINVAL;
1257 }
1258 mp->m_sb.sb_rextents = lcounter;
1259 return 0;
1260 case XFS_SBS_REXTSLOG:
1261 scounter = mp->m_sb.sb_rextslog;
1262 scounter += delta;
1263 if (scounter < 0) {
1264 ASSERT(0);
1265 return -EINVAL;
1266 }
1267 mp->m_sb.sb_rextslog = scounter;
1268 return 0;
1269 default:
1270 ASSERT(0); 1095 ASSERT(0);
1096 percpu_counter_add(&mp->m_icount, -delta);
1271 return -EINVAL; 1097 return -EINVAL;
1272 } 1098 }
1099 return 0;
1273} 1100}
1274 1101
1275/*
1276 * xfs_mod_incore_sb() is used to change a field in the in-core
1277 * superblock structure by the specified delta. This modification
1278 * is protected by the m_sb_lock. Just use the xfs_mod_incore_sb_unlocked()
1279 * routine to do the work.
1280 */
1281int 1102int
1282xfs_mod_incore_sb( 1103xfs_mod_ifree(
1283 struct xfs_mount *mp, 1104 struct xfs_mount *mp,
1284 xfs_sb_field_t field, 1105 int64_t delta)
1285 int64_t delta,
1286 int rsvd)
1287{ 1106{
1288 int status; 1107 percpu_counter_add(&mp->m_ifree, delta);
1289 1108 if (percpu_counter_compare(&mp->m_ifree, 0) < 0) {
1290#ifdef HAVE_PERCPU_SB 1109 ASSERT(0);
1291 ASSERT(field < XFS_SBS_ICOUNT || field > XFS_SBS_FDBLOCKS); 1110 percpu_counter_add(&mp->m_ifree, -delta);
1292#endif 1111 return -EINVAL;
1293 spin_lock(&mp->m_sb_lock); 1112 }
1294 status = xfs_mod_incore_sb_unlocked(mp, field, delta, rsvd); 1113 return 0;
1295 spin_unlock(&mp->m_sb_lock);
1296
1297 return status;
1298} 1114}
1299 1115
1300/*
1301 * Change more than one field in the in-core superblock structure at a time.
1302 *
1303 * The fields and changes to those fields are specified in the array of
1304 * xfs_mod_sb structures passed in. Either all of the specified deltas
1305 * will be applied or none of them will. If any modified field dips below 0,
1306 * then all modifications will be backed out and EINVAL will be returned.
1307 *
1308 * Note that this function may not be used for the superblock values that
1309 * are tracked with the in-memory per-cpu counters - a direct call to
1310 * xfs_icsb_modify_counters is required for these.
1311 */
1312int 1116int
1313xfs_mod_incore_sb_batch( 1117xfs_mod_fdblocks(
1314 struct xfs_mount *mp, 1118 struct xfs_mount *mp,
1315 xfs_mod_sb_t *msb, 1119 int64_t delta,
1316 uint nmsb, 1120 bool rsvd)
1317 int rsvd)
1318{ 1121{
1319 xfs_mod_sb_t *msbp; 1122 int64_t lcounter;
1320 int error = 0; 1123 long long res_used;
1124 s32 batch;
1125
1126 if (delta > 0) {
1127 /*
1128 * If the reserve pool is depleted, put blocks back into it
1129 * first. Most of the time the pool is full.
1130 */
1131 if (likely(mp->m_resblks == mp->m_resblks_avail)) {
1132 percpu_counter_add(&mp->m_fdblocks, delta);
1133 return 0;
1134 }
1135
1136 spin_lock(&mp->m_sb_lock);
1137 res_used = (long long)(mp->m_resblks - mp->m_resblks_avail);
1138
1139 if (res_used > delta) {
1140 mp->m_resblks_avail += delta;
1141 } else {
1142 delta -= res_used;
1143 mp->m_resblks_avail = mp->m_resblks;
1144 percpu_counter_add(&mp->m_fdblocks, delta);
1145 }
1146 spin_unlock(&mp->m_sb_lock);
1147 return 0;
1148 }
1321 1149
1322 /* 1150 /*
1323 * Loop through the array of mod structures and apply each individually. 1151 * Taking blocks away, need to be more accurate the closer we
1324 * If any fail, then back out all those which have already been applied. 1152 * are to zero.
1325 * Do all of this within the scope of the m_sb_lock so that all of the 1153 *
1326 * changes will be atomic. 1154 * batch size is set to a maximum of 1024 blocks - if we are
1155 * allocating of freeing extents larger than this then we aren't
1156 * going to be hammering the counter lock so a lock per update
1157 * is not a problem.
1158 *
1159 * If the counter has a value of less than 2 * max batch size,
1160 * then make everything serialise as we are real close to
1161 * ENOSPC.
1162 */
1163#define __BATCH 1024
1164 if (percpu_counter_compare(&mp->m_fdblocks, 2 * __BATCH) < 0)
1165 batch = 1;
1166 else
1167 batch = __BATCH;
1168#undef __BATCH
1169
1170 __percpu_counter_add(&mp->m_fdblocks, delta, batch);
1171 if (percpu_counter_compare(&mp->m_fdblocks,
1172 XFS_ALLOC_SET_ASIDE(mp)) >= 0) {
1173 /* we had space! */
1174 return 0;
1175 }
1176
1177 /*
1178 * lock up the sb for dipping into reserves before releasing the space
1179 * that took us to ENOSPC.
1327 */ 1180 */
1328 spin_lock(&mp->m_sb_lock); 1181 spin_lock(&mp->m_sb_lock);
1329 for (msbp = msb; msbp < (msb + nmsb); msbp++) { 1182 percpu_counter_add(&mp->m_fdblocks, -delta);
1330 ASSERT(msbp->msb_field < XFS_SBS_ICOUNT || 1183 if (!rsvd)
1331 msbp->msb_field > XFS_SBS_FDBLOCKS); 1184 goto fdblocks_enospc;
1332 1185
1333 error = xfs_mod_incore_sb_unlocked(mp, msbp->msb_field, 1186 lcounter = (long long)mp->m_resblks_avail + delta;
1334 msbp->msb_delta, rsvd); 1187 if (lcounter >= 0) {
1335 if (error) 1188 mp->m_resblks_avail = lcounter;
1336 goto unwind; 1189 spin_unlock(&mp->m_sb_lock);
1190 return 0;
1337 } 1191 }
1192 printk_once(KERN_WARNING
1193 "Filesystem \"%s\": reserve blocks depleted! "
1194 "Consider increasing reserve pool size.",
1195 mp->m_fsname);
1196fdblocks_enospc:
1338 spin_unlock(&mp->m_sb_lock); 1197 spin_unlock(&mp->m_sb_lock);
1339 return 0; 1198 return -ENOSPC;
1199}
1340 1200
1341unwind: 1201int
1342 while (--msbp >= msb) { 1202xfs_mod_frextents(
1343 error = xfs_mod_incore_sb_unlocked(mp, msbp->msb_field, 1203 struct xfs_mount *mp,
1344 -msbp->msb_delta, rsvd); 1204 int64_t delta)
1345 ASSERT(error == 0); 1205{
1346 } 1206 int64_t lcounter;
1207 int ret = 0;
1208
1209 spin_lock(&mp->m_sb_lock);
1210 lcounter = mp->m_sb.sb_frextents + delta;
1211 if (lcounter < 0)
1212 ret = -ENOSPC;
1213 else
1214 mp->m_sb.sb_frextents = lcounter;
1347 spin_unlock(&mp->m_sb_lock); 1215 spin_unlock(&mp->m_sb_lock);
1348 return error; 1216 return ret;
1349} 1217}
1350 1218
1351/* 1219/*
@@ -1407,573 +1275,3 @@ xfs_dev_is_read_only(
1407 } 1275 }
1408 return 0; 1276 return 0;
1409} 1277}
1410
1411#ifdef HAVE_PERCPU_SB
1412/*
1413 * Per-cpu incore superblock counters
1414 *
1415 * Simple concept, difficult implementation
1416 *
1417 * Basically, replace the incore superblock counters with a distributed per cpu
1418 * counter for contended fields (e.g. free block count).
1419 *
1420 * Difficulties arise in that the incore sb is used for ENOSPC checking, and
1421 * hence needs to be accurately read when we are running low on space. Hence
1422 * there is a method to enable and disable the per-cpu counters based on how
1423 * much "stuff" is available in them.
1424 *
1425 * Basically, a counter is enabled if there is enough free resource to justify
1426 * running a per-cpu fast-path. If the per-cpu counter runs out (i.e. a local
1427 * ENOSPC), then we disable the counters to synchronise all callers and
1428 * re-distribute the available resources.
1429 *
1430 * If, once we redistributed the available resources, we still get a failure,
1431 * we disable the per-cpu counter and go through the slow path.
1432 *
1433 * The slow path is the current xfs_mod_incore_sb() function. This means that
1434 * when we disable a per-cpu counter, we need to drain its resources back to
1435 * the global superblock. We do this after disabling the counter to prevent
1436 * more threads from queueing up on the counter.
1437 *
1438 * Essentially, this means that we still need a lock in the fast path to enable
1439 * synchronisation between the global counters and the per-cpu counters. This
1440 * is not a problem because the lock will be local to a CPU almost all the time
1441 * and have little contention except when we get to ENOSPC conditions.
1442 *
1443 * Basically, this lock becomes a barrier that enables us to lock out the fast
1444 * path while we do things like enabling and disabling counters and
1445 * synchronising the counters.
1446 *
1447 * Locking rules:
1448 *
1449 * 1. m_sb_lock before picking up per-cpu locks
1450 * 2. per-cpu locks always picked up via for_each_online_cpu() order
1451 * 3. accurate counter sync requires m_sb_lock + per cpu locks
1452 * 4. modifying per-cpu counters requires holding per-cpu lock
1453 * 5. modifying global counters requires holding m_sb_lock
1454 * 6. enabling or disabling a counter requires holding the m_sb_lock
1455 * and _none_ of the per-cpu locks.
1456 *
1457 * Disabled counters are only ever re-enabled by a balance operation
1458 * that results in more free resources per CPU than a given threshold.
1459 * To ensure counters don't remain disabled, they are rebalanced when
1460 * the global resource goes above a higher threshold (i.e. some hysteresis
1461 * is present to prevent thrashing).
1462 */
1463
1464#ifdef CONFIG_HOTPLUG_CPU
1465/*
1466 * hot-plug CPU notifier support.
1467 *
1468 * We need a notifier per filesystem as we need to be able to identify
1469 * the filesystem to balance the counters out. This is achieved by
1470 * having a notifier block embedded in the xfs_mount_t and doing pointer
1471 * magic to get the mount pointer from the notifier block address.
1472 */
1473STATIC int
1474xfs_icsb_cpu_notify(
1475 struct notifier_block *nfb,
1476 unsigned long action,
1477 void *hcpu)
1478{
1479 xfs_icsb_cnts_t *cntp;
1480 xfs_mount_t *mp;
1481
1482 mp = (xfs_mount_t *)container_of(nfb, xfs_mount_t, m_icsb_notifier);
1483 cntp = (xfs_icsb_cnts_t *)
1484 per_cpu_ptr(mp->m_sb_cnts, (unsigned long)hcpu);
1485 switch (action) {
1486 case CPU_UP_PREPARE:
1487 case CPU_UP_PREPARE_FROZEN:
1488 /* Easy Case - initialize the area and locks, and
1489 * then rebalance when online does everything else for us. */
1490 memset(cntp, 0, sizeof(xfs_icsb_cnts_t));
1491 break;
1492 case CPU_ONLINE:
1493 case CPU_ONLINE_FROZEN:
1494 xfs_icsb_lock(mp);
1495 xfs_icsb_balance_counter(mp, XFS_SBS_ICOUNT, 0);
1496 xfs_icsb_balance_counter(mp, XFS_SBS_IFREE, 0);
1497 xfs_icsb_balance_counter(mp, XFS_SBS_FDBLOCKS, 0);
1498 xfs_icsb_unlock(mp);
1499 break;
1500 case CPU_DEAD:
1501 case CPU_DEAD_FROZEN:
1502 /* Disable all the counters, then fold the dead cpu's
1503 * count into the total on the global superblock and
1504 * re-enable the counters. */
1505 xfs_icsb_lock(mp);
1506 spin_lock(&mp->m_sb_lock);
1507 xfs_icsb_disable_counter(mp, XFS_SBS_ICOUNT);
1508 xfs_icsb_disable_counter(mp, XFS_SBS_IFREE);
1509 xfs_icsb_disable_counter(mp, XFS_SBS_FDBLOCKS);
1510
1511 mp->m_sb.sb_icount += cntp->icsb_icount;
1512 mp->m_sb.sb_ifree += cntp->icsb_ifree;
1513 mp->m_sb.sb_fdblocks += cntp->icsb_fdblocks;
1514
1515 memset(cntp, 0, sizeof(xfs_icsb_cnts_t));
1516
1517 xfs_icsb_balance_counter_locked(mp, XFS_SBS_ICOUNT, 0);
1518 xfs_icsb_balance_counter_locked(mp, XFS_SBS_IFREE, 0);
1519 xfs_icsb_balance_counter_locked(mp, XFS_SBS_FDBLOCKS, 0);
1520 spin_unlock(&mp->m_sb_lock);
1521 xfs_icsb_unlock(mp);
1522 break;
1523 }
1524
1525 return NOTIFY_OK;
1526}
1527#endif /* CONFIG_HOTPLUG_CPU */
1528
1529int
1530xfs_icsb_init_counters(
1531 xfs_mount_t *mp)
1532{
1533 xfs_icsb_cnts_t *cntp;
1534 int i;
1535
1536 mp->m_sb_cnts = alloc_percpu(xfs_icsb_cnts_t);
1537 if (mp->m_sb_cnts == NULL)
1538 return -ENOMEM;
1539
1540 for_each_online_cpu(i) {
1541 cntp = (xfs_icsb_cnts_t *)per_cpu_ptr(mp->m_sb_cnts, i);
1542 memset(cntp, 0, sizeof(xfs_icsb_cnts_t));
1543 }
1544
1545 mutex_init(&mp->m_icsb_mutex);
1546
1547 /*
1548 * start with all counters disabled so that the
1549 * initial balance kicks us off correctly
1550 */
1551 mp->m_icsb_counters = -1;
1552
1553#ifdef CONFIG_HOTPLUG_CPU
1554 mp->m_icsb_notifier.notifier_call = xfs_icsb_cpu_notify;
1555 mp->m_icsb_notifier.priority = 0;
1556 register_hotcpu_notifier(&mp->m_icsb_notifier);
1557#endif /* CONFIG_HOTPLUG_CPU */
1558
1559 return 0;
1560}
1561
1562void
1563xfs_icsb_reinit_counters(
1564 xfs_mount_t *mp)
1565{
1566 xfs_icsb_lock(mp);
1567 /*
1568 * start with all counters disabled so that the
1569 * initial balance kicks us off correctly
1570 */
1571 mp->m_icsb_counters = -1;
1572 xfs_icsb_balance_counter(mp, XFS_SBS_ICOUNT, 0);
1573 xfs_icsb_balance_counter(mp, XFS_SBS_IFREE, 0);
1574 xfs_icsb_balance_counter(mp, XFS_SBS_FDBLOCKS, 0);
1575 xfs_icsb_unlock(mp);
1576}
1577
1578void
1579xfs_icsb_destroy_counters(
1580 xfs_mount_t *mp)
1581{
1582 if (mp->m_sb_cnts) {
1583 unregister_hotcpu_notifier(&mp->m_icsb_notifier);
1584 free_percpu(mp->m_sb_cnts);
1585 }
1586 mutex_destroy(&mp->m_icsb_mutex);
1587}
1588
1589STATIC void
1590xfs_icsb_lock_cntr(
1591 xfs_icsb_cnts_t *icsbp)
1592{
1593 while (test_and_set_bit(XFS_ICSB_FLAG_LOCK, &icsbp->icsb_flags)) {
1594 ndelay(1000);
1595 }
1596}
1597
1598STATIC void
1599xfs_icsb_unlock_cntr(
1600 xfs_icsb_cnts_t *icsbp)
1601{
1602 clear_bit(XFS_ICSB_FLAG_LOCK, &icsbp->icsb_flags);
1603}
1604
1605
1606STATIC void
1607xfs_icsb_lock_all_counters(
1608 xfs_mount_t *mp)
1609{
1610 xfs_icsb_cnts_t *cntp;
1611 int i;
1612
1613 for_each_online_cpu(i) {
1614 cntp = (xfs_icsb_cnts_t *)per_cpu_ptr(mp->m_sb_cnts, i);
1615 xfs_icsb_lock_cntr(cntp);
1616 }
1617}
1618
1619STATIC void
1620xfs_icsb_unlock_all_counters(
1621 xfs_mount_t *mp)
1622{
1623 xfs_icsb_cnts_t *cntp;
1624 int i;
1625
1626 for_each_online_cpu(i) {
1627 cntp = (xfs_icsb_cnts_t *)per_cpu_ptr(mp->m_sb_cnts, i);
1628 xfs_icsb_unlock_cntr(cntp);
1629 }
1630}
1631
1632STATIC void
1633xfs_icsb_count(
1634 xfs_mount_t *mp,
1635 xfs_icsb_cnts_t *cnt,
1636 int flags)
1637{
1638 xfs_icsb_cnts_t *cntp;
1639 int i;
1640
1641 memset(cnt, 0, sizeof(xfs_icsb_cnts_t));
1642
1643 if (!(flags & XFS_ICSB_LAZY_COUNT))
1644 xfs_icsb_lock_all_counters(mp);
1645
1646 for_each_online_cpu(i) {
1647 cntp = (xfs_icsb_cnts_t *)per_cpu_ptr(mp->m_sb_cnts, i);
1648 cnt->icsb_icount += cntp->icsb_icount;
1649 cnt->icsb_ifree += cntp->icsb_ifree;
1650 cnt->icsb_fdblocks += cntp->icsb_fdblocks;
1651 }
1652
1653 if (!(flags & XFS_ICSB_LAZY_COUNT))
1654 xfs_icsb_unlock_all_counters(mp);
1655}
1656
1657STATIC int
1658xfs_icsb_counter_disabled(
1659 xfs_mount_t *mp,
1660 xfs_sb_field_t field)
1661{
1662 ASSERT((field >= XFS_SBS_ICOUNT) && (field <= XFS_SBS_FDBLOCKS));
1663 return test_bit(field, &mp->m_icsb_counters);
1664}
1665
1666STATIC void
1667xfs_icsb_disable_counter(
1668 xfs_mount_t *mp,
1669 xfs_sb_field_t field)
1670{
1671 xfs_icsb_cnts_t cnt;
1672
1673 ASSERT((field >= XFS_SBS_ICOUNT) && (field <= XFS_SBS_FDBLOCKS));
1674
1675 /*
1676 * If we are already disabled, then there is nothing to do
1677 * here. We check before locking all the counters to avoid
1678 * the expensive lock operation when being called in the
1679 * slow path and the counter is already disabled. This is
1680 * safe because the only time we set or clear this state is under
1681 * the m_icsb_mutex.
1682 */
1683 if (xfs_icsb_counter_disabled(mp, field))
1684 return;
1685
1686 xfs_icsb_lock_all_counters(mp);
1687 if (!test_and_set_bit(field, &mp->m_icsb_counters)) {
1688 /* drain back to superblock */
1689
1690 xfs_icsb_count(mp, &cnt, XFS_ICSB_LAZY_COUNT);
1691 switch(field) {
1692 case XFS_SBS_ICOUNT:
1693 mp->m_sb.sb_icount = cnt.icsb_icount;
1694 break;
1695 case XFS_SBS_IFREE:
1696 mp->m_sb.sb_ifree = cnt.icsb_ifree;
1697 break;
1698 case XFS_SBS_FDBLOCKS:
1699 mp->m_sb.sb_fdblocks = cnt.icsb_fdblocks;
1700 break;
1701 default:
1702 BUG();
1703 }
1704 }
1705
1706 xfs_icsb_unlock_all_counters(mp);
1707}
1708
1709STATIC void
1710xfs_icsb_enable_counter(
1711 xfs_mount_t *mp,
1712 xfs_sb_field_t field,
1713 uint64_t count,
1714 uint64_t resid)
1715{
1716 xfs_icsb_cnts_t *cntp;
1717 int i;
1718
1719 ASSERT((field >= XFS_SBS_ICOUNT) && (field <= XFS_SBS_FDBLOCKS));
1720
1721 xfs_icsb_lock_all_counters(mp);
1722 for_each_online_cpu(i) {
1723 cntp = per_cpu_ptr(mp->m_sb_cnts, i);
1724 switch (field) {
1725 case XFS_SBS_ICOUNT:
1726 cntp->icsb_icount = count + resid;
1727 break;
1728 case XFS_SBS_IFREE:
1729 cntp->icsb_ifree = count + resid;
1730 break;
1731 case XFS_SBS_FDBLOCKS:
1732 cntp->icsb_fdblocks = count + resid;
1733 break;
1734 default:
1735 BUG();
1736 break;
1737 }
1738 resid = 0;
1739 }
1740 clear_bit(field, &mp->m_icsb_counters);
1741 xfs_icsb_unlock_all_counters(mp);
1742}
1743
1744void
1745xfs_icsb_sync_counters_locked(
1746 xfs_mount_t *mp,
1747 int flags)
1748{
1749 xfs_icsb_cnts_t cnt;
1750
1751 xfs_icsb_count(mp, &cnt, flags);
1752
1753 if (!xfs_icsb_counter_disabled(mp, XFS_SBS_ICOUNT))
1754 mp->m_sb.sb_icount = cnt.icsb_icount;
1755 if (!xfs_icsb_counter_disabled(mp, XFS_SBS_IFREE))
1756 mp->m_sb.sb_ifree = cnt.icsb_ifree;
1757 if (!xfs_icsb_counter_disabled(mp, XFS_SBS_FDBLOCKS))
1758 mp->m_sb.sb_fdblocks = cnt.icsb_fdblocks;
1759}
1760
1761/*
1762 * Accurate update of per-cpu counters to incore superblock
1763 */
1764void
1765xfs_icsb_sync_counters(
1766 xfs_mount_t *mp,
1767 int flags)
1768{
1769 spin_lock(&mp->m_sb_lock);
1770 xfs_icsb_sync_counters_locked(mp, flags);
1771 spin_unlock(&mp->m_sb_lock);
1772}
1773
1774/*
1775 * Balance and enable/disable counters as necessary.
1776 *
1777 * Thresholds for re-enabling counters are somewhat magic. inode counts are
1778 * chosen to be the same number as single on disk allocation chunk per CPU, and
1779 * free blocks is something far enough zero that we aren't going thrash when we
1780 * get near ENOSPC. We also need to supply a minimum we require per cpu to
1781 * prevent looping endlessly when xfs_alloc_space asks for more than will
1782 * be distributed to a single CPU but each CPU has enough blocks to be
1783 * reenabled.
1784 *
1785 * Note that we can be called when counters are already disabled.
1786 * xfs_icsb_disable_counter() optimises the counter locking in this case to
1787 * prevent locking every per-cpu counter needlessly.
1788 */
1789
1790#define XFS_ICSB_INO_CNTR_REENABLE (uint64_t)64
1791#define XFS_ICSB_FDBLK_CNTR_REENABLE(mp) \
1792 (uint64_t)(512 + XFS_ALLOC_SET_ASIDE(mp))
1793STATIC void
1794xfs_icsb_balance_counter_locked(
1795 xfs_mount_t *mp,
1796 xfs_sb_field_t field,
1797 int min_per_cpu)
1798{
1799 uint64_t count, resid;
1800 int weight = num_online_cpus();
1801 uint64_t min = (uint64_t)min_per_cpu;
1802
1803 /* disable counter and sync counter */
1804 xfs_icsb_disable_counter(mp, field);
1805
1806 /* update counters - first CPU gets residual*/
1807 switch (field) {
1808 case XFS_SBS_ICOUNT:
1809 count = mp->m_sb.sb_icount;
1810 resid = do_div(count, weight);
1811 if (count < max(min, XFS_ICSB_INO_CNTR_REENABLE))
1812 return;
1813 break;
1814 case XFS_SBS_IFREE:
1815 count = mp->m_sb.sb_ifree;
1816 resid = do_div(count, weight);
1817 if (count < max(min, XFS_ICSB_INO_CNTR_REENABLE))
1818 return;
1819 break;
1820 case XFS_SBS_FDBLOCKS:
1821 count = mp->m_sb.sb_fdblocks;
1822 resid = do_div(count, weight);
1823 if (count < max(min, XFS_ICSB_FDBLK_CNTR_REENABLE(mp)))
1824 return;
1825 break;
1826 default:
1827 BUG();
1828 count = resid = 0; /* quiet, gcc */
1829 break;
1830 }
1831
1832 xfs_icsb_enable_counter(mp, field, count, resid);
1833}
1834
1835STATIC void
1836xfs_icsb_balance_counter(
1837 xfs_mount_t *mp,
1838 xfs_sb_field_t fields,
1839 int min_per_cpu)
1840{
1841 spin_lock(&mp->m_sb_lock);
1842 xfs_icsb_balance_counter_locked(mp, fields, min_per_cpu);
1843 spin_unlock(&mp->m_sb_lock);
1844}
1845
1846int
1847xfs_icsb_modify_counters(
1848 xfs_mount_t *mp,
1849 xfs_sb_field_t field,
1850 int64_t delta,
1851 int rsvd)
1852{
1853 xfs_icsb_cnts_t *icsbp;
1854 long long lcounter; /* long counter for 64 bit fields */
1855 int ret = 0;
1856
1857 might_sleep();
1858again:
1859 preempt_disable();
1860 icsbp = this_cpu_ptr(mp->m_sb_cnts);
1861
1862 /*
1863 * if the counter is disabled, go to slow path
1864 */
1865 if (unlikely(xfs_icsb_counter_disabled(mp, field)))
1866 goto slow_path;
1867 xfs_icsb_lock_cntr(icsbp);
1868 if (unlikely(xfs_icsb_counter_disabled(mp, field))) {
1869 xfs_icsb_unlock_cntr(icsbp);
1870 goto slow_path;
1871 }
1872
1873 switch (field) {
1874 case XFS_SBS_ICOUNT:
1875 lcounter = icsbp->icsb_icount;
1876 lcounter += delta;
1877 if (unlikely(lcounter < 0))
1878 goto balance_counter;
1879 icsbp->icsb_icount = lcounter;
1880 break;
1881
1882 case XFS_SBS_IFREE:
1883 lcounter = icsbp->icsb_ifree;
1884 lcounter += delta;
1885 if (unlikely(lcounter < 0))
1886 goto balance_counter;
1887 icsbp->icsb_ifree = lcounter;
1888 break;
1889
1890 case XFS_SBS_FDBLOCKS:
1891 BUG_ON((mp->m_resblks - mp->m_resblks_avail) != 0);
1892
1893 lcounter = icsbp->icsb_fdblocks - XFS_ALLOC_SET_ASIDE(mp);
1894 lcounter += delta;
1895 if (unlikely(lcounter < 0))
1896 goto balance_counter;
1897 icsbp->icsb_fdblocks = lcounter + XFS_ALLOC_SET_ASIDE(mp);
1898 break;
1899 default:
1900 BUG();
1901 break;
1902 }
1903 xfs_icsb_unlock_cntr(icsbp);
1904 preempt_enable();
1905 return 0;
1906
1907slow_path:
1908 preempt_enable();
1909
1910 /*
1911 * serialise with a mutex so we don't burn lots of cpu on
1912 * the superblock lock. We still need to hold the superblock
1913 * lock, however, when we modify the global structures.
1914 */
1915 xfs_icsb_lock(mp);
1916
1917 /*
1918 * Now running atomically.
1919 *
1920 * If the counter is enabled, someone has beaten us to rebalancing.
1921 * Drop the lock and try again in the fast path....
1922 */
1923 if (!(xfs_icsb_counter_disabled(mp, field))) {
1924 xfs_icsb_unlock(mp);
1925 goto again;
1926 }
1927
1928 /*
1929 * The counter is currently disabled. Because we are
1930 * running atomically here, we know a rebalance cannot
1931 * be in progress. Hence we can go straight to operating
1932 * on the global superblock. We do not call xfs_mod_incore_sb()
1933 * here even though we need to get the m_sb_lock. Doing so
1934 * will cause us to re-enter this function and deadlock.
1935 * Hence we get the m_sb_lock ourselves and then call
1936 * xfs_mod_incore_sb_unlocked() as the unlocked path operates
1937 * directly on the global counters.
1938 */
1939 spin_lock(&mp->m_sb_lock);
1940 ret = xfs_mod_incore_sb_unlocked(mp, field, delta, rsvd);
1941 spin_unlock(&mp->m_sb_lock);
1942
1943 /*
1944 * Now that we've modified the global superblock, we
1945 * may be able to re-enable the distributed counters
1946 * (e.g. lots of space just got freed). After that
1947 * we are done.
1948 */
1949 if (ret != -ENOSPC)
1950 xfs_icsb_balance_counter(mp, field, 0);
1951 xfs_icsb_unlock(mp);
1952 return ret;
1953
1954balance_counter:
1955 xfs_icsb_unlock_cntr(icsbp);
1956 preempt_enable();
1957
1958 /*
1959 * We may have multiple threads here if multiple per-cpu
1960 * counters run dry at the same time. This will mean we can
1961 * do more balances than strictly necessary but it is not
1962 * the common slowpath case.
1963 */
1964 xfs_icsb_lock(mp);
1965
1966 /*
1967 * running atomically.
1968 *
1969 * This will leave the counter in the correct state for future
1970 * accesses. After the rebalance, we simply try again and our retry
1971 * will either succeed through the fast path or slow path without
1972 * another balance operation being required.
1973 */
1974 xfs_icsb_balance_counter(mp, field, delta);
1975 xfs_icsb_unlock(mp);
1976 goto again;
1977}
1978
1979#endif
diff --git a/fs/xfs/xfs_mount.h b/fs/xfs/xfs_mount.h
index 0d8abd6364d9..8c995a2ccb6f 100644
--- a/fs/xfs/xfs_mount.h
+++ b/fs/xfs/xfs_mount.h
@@ -18,8 +18,6 @@
18#ifndef __XFS_MOUNT_H__ 18#ifndef __XFS_MOUNT_H__
19#define __XFS_MOUNT_H__ 19#define __XFS_MOUNT_H__
20 20
21#ifdef __KERNEL__
22
23struct xlog; 21struct xlog;
24struct xfs_inode; 22struct xfs_inode;
25struct xfs_mru_cache; 23struct xfs_mru_cache;
@@ -29,44 +27,6 @@ struct xfs_quotainfo;
29struct xfs_dir_ops; 27struct xfs_dir_ops;
30struct xfs_da_geometry; 28struct xfs_da_geometry;
31 29
32#ifdef HAVE_PERCPU_SB
33
34/*
35 * Valid per-cpu incore superblock counters. Note that if you add new counters,
36 * you may need to define new counter disabled bit field descriptors as there
37 * are more possible fields in the superblock that can fit in a bitfield on a
38 * 32 bit platform. The XFS_SBS_* values for the current current counters just
39 * fit.
40 */
41typedef struct xfs_icsb_cnts {
42 uint64_t icsb_fdblocks;
43 uint64_t icsb_ifree;
44 uint64_t icsb_icount;
45 unsigned long icsb_flags;
46} xfs_icsb_cnts_t;
47
48#define XFS_ICSB_FLAG_LOCK (1 << 0) /* counter lock bit */
49
50#define XFS_ICSB_LAZY_COUNT (1 << 1) /* accuracy not needed */
51
52extern int xfs_icsb_init_counters(struct xfs_mount *);
53extern void xfs_icsb_reinit_counters(struct xfs_mount *);
54extern void xfs_icsb_destroy_counters(struct xfs_mount *);
55extern void xfs_icsb_sync_counters(struct xfs_mount *, int);
56extern void xfs_icsb_sync_counters_locked(struct xfs_mount *, int);
57extern int xfs_icsb_modify_counters(struct xfs_mount *, xfs_sb_field_t,
58 int64_t, int);
59
60#else
61#define xfs_icsb_init_counters(mp) (0)
62#define xfs_icsb_destroy_counters(mp) do { } while (0)
63#define xfs_icsb_reinit_counters(mp) do { } while (0)
64#define xfs_icsb_sync_counters(mp, flags) do { } while (0)
65#define xfs_icsb_sync_counters_locked(mp, flags) do { } while (0)
66#define xfs_icsb_modify_counters(mp, field, delta, rsvd) \
67 xfs_mod_incore_sb(mp, field, delta, rsvd)
68#endif
69
70/* dynamic preallocation free space thresholds, 5% down to 1% */ 30/* dynamic preallocation free space thresholds, 5% down to 1% */
71enum { 31enum {
72 XFS_LOWSP_1_PCNT = 0, 32 XFS_LOWSP_1_PCNT = 0,
@@ -81,8 +41,13 @@ typedef struct xfs_mount {
81 struct super_block *m_super; 41 struct super_block *m_super;
82 xfs_tid_t m_tid; /* next unused tid for fs */ 42 xfs_tid_t m_tid; /* next unused tid for fs */
83 struct xfs_ail *m_ail; /* fs active log item list */ 43 struct xfs_ail *m_ail; /* fs active log item list */
84 xfs_sb_t m_sb; /* copy of fs superblock */ 44
45 struct xfs_sb m_sb; /* copy of fs superblock */
85 spinlock_t m_sb_lock; /* sb counter lock */ 46 spinlock_t m_sb_lock; /* sb counter lock */
47 struct percpu_counter m_icount; /* allocated inodes counter */
48 struct percpu_counter m_ifree; /* free inodes counter */
49 struct percpu_counter m_fdblocks; /* free block counter */
50
86 struct xfs_buf *m_sb_bp; /* buffer for superblock */ 51 struct xfs_buf *m_sb_bp; /* buffer for superblock */
87 char *m_fsname; /* filesystem name */ 52 char *m_fsname; /* filesystem name */
88 int m_fsname_len; /* strlen of fs name */ 53 int m_fsname_len; /* strlen of fs name */
@@ -152,12 +117,6 @@ typedef struct xfs_mount {
152 const struct xfs_dir_ops *m_nondir_inode_ops; /* !dir inode ops */ 117 const struct xfs_dir_ops *m_nondir_inode_ops; /* !dir inode ops */
153 uint m_chsize; /* size of next field */ 118 uint m_chsize; /* size of next field */
154 atomic_t m_active_trans; /* number trans frozen */ 119 atomic_t m_active_trans; /* number trans frozen */
155#ifdef HAVE_PERCPU_SB
156 xfs_icsb_cnts_t __percpu *m_sb_cnts; /* per-cpu superblock counters */
157 unsigned long m_icsb_counters; /* disabled per-cpu counters */
158 struct notifier_block m_icsb_notifier; /* hotplug cpu notifier */
159 struct mutex m_icsb_mutex; /* balancer sync lock */
160#endif
161 struct xfs_mru_cache *m_filestream; /* per-mount filestream data */ 120 struct xfs_mru_cache *m_filestream; /* per-mount filestream data */
162 struct delayed_work m_reclaim_work; /* background inode reclaim */ 121 struct delayed_work m_reclaim_work; /* background inode reclaim */
163 struct delayed_work m_eofblocks_work; /* background eof blocks 122 struct delayed_work m_eofblocks_work; /* background eof blocks
@@ -301,35 +260,6 @@ xfs_daddr_to_agbno(struct xfs_mount *mp, xfs_daddr_t d)
301} 260}
302 261
303/* 262/*
304 * Per-cpu superblock locking functions
305 */
306#ifdef HAVE_PERCPU_SB
307static inline void
308xfs_icsb_lock(xfs_mount_t *mp)
309{
310 mutex_lock(&mp->m_icsb_mutex);
311}
312
313static inline void
314xfs_icsb_unlock(xfs_mount_t *mp)
315{
316 mutex_unlock(&mp->m_icsb_mutex);
317}
318#else
319#define xfs_icsb_lock(mp)
320#define xfs_icsb_unlock(mp)
321#endif
322
323/*
324 * This structure is for use by the xfs_mod_incore_sb_batch() routine.
325 * xfs_growfs can specify a few fields which are more than int limit
326 */
327typedef struct xfs_mod_sb {
328 xfs_sb_field_t msb_field; /* Field to modify, see below */
329 int64_t msb_delta; /* Change to make to specified field */
330} xfs_mod_sb_t;
331
332/*
333 * Per-ag incore structure, copies of information in agf and agi, to improve the 263 * Per-ag incore structure, copies of information in agf and agi, to improve the
334 * performance of allocation group selection. 264 * performance of allocation group selection.
335 */ 265 */
@@ -383,11 +313,14 @@ extern __uint64_t xfs_default_resblks(xfs_mount_t *mp);
383extern int xfs_mountfs(xfs_mount_t *mp); 313extern int xfs_mountfs(xfs_mount_t *mp);
384extern int xfs_initialize_perag(xfs_mount_t *mp, xfs_agnumber_t agcount, 314extern int xfs_initialize_perag(xfs_mount_t *mp, xfs_agnumber_t agcount,
385 xfs_agnumber_t *maxagi); 315 xfs_agnumber_t *maxagi);
386
387extern void xfs_unmountfs(xfs_mount_t *); 316extern void xfs_unmountfs(xfs_mount_t *);
388extern int xfs_mod_incore_sb(xfs_mount_t *, xfs_sb_field_t, int64_t, int); 317
389extern int xfs_mod_incore_sb_batch(xfs_mount_t *, xfs_mod_sb_t *, 318extern int xfs_mod_icount(struct xfs_mount *mp, int64_t delta);
390 uint, int); 319extern int xfs_mod_ifree(struct xfs_mount *mp, int64_t delta);
320extern int xfs_mod_fdblocks(struct xfs_mount *mp, int64_t delta,
321 bool reserved);
322extern int xfs_mod_frextents(struct xfs_mount *mp, int64_t delta);
323
391extern int xfs_mount_log_sb(xfs_mount_t *); 324extern int xfs_mount_log_sb(xfs_mount_t *);
392extern struct xfs_buf *xfs_getsb(xfs_mount_t *, int); 325extern struct xfs_buf *xfs_getsb(xfs_mount_t *, int);
393extern int xfs_readsb(xfs_mount_t *, int); 326extern int xfs_readsb(xfs_mount_t *, int);
@@ -399,6 +332,4 @@ extern int xfs_dev_is_read_only(struct xfs_mount *, char *);
399 332
400extern void xfs_set_low_space_thresholds(struct xfs_mount *); 333extern void xfs_set_low_space_thresholds(struct xfs_mount *);
401 334
402#endif /* __KERNEL__ */
403
404#endif /* __XFS_MOUNT_H__ */ 335#endif /* __XFS_MOUNT_H__ */
diff --git a/fs/xfs/xfs_mru_cache.c b/fs/xfs/xfs_mru_cache.c
index 30ecca3037e3..f8a674d7f092 100644
--- a/fs/xfs/xfs_mru_cache.c
+++ b/fs/xfs/xfs_mru_cache.c
@@ -437,7 +437,7 @@ xfs_mru_cache_insert(
437 if (!mru || !mru->lists) 437 if (!mru || !mru->lists)
438 return -EINVAL; 438 return -EINVAL;
439 439
440 if (radix_tree_preload(GFP_KERNEL)) 440 if (radix_tree_preload(GFP_NOFS))
441 return -ENOMEM; 441 return -ENOMEM;
442 442
443 INIT_LIST_HEAD(&elem->list_node); 443 INIT_LIST_HEAD(&elem->list_node);
diff --git a/fs/xfs/xfs_pnfs.c b/fs/xfs/xfs_pnfs.c
index 365dd57ea760..981a657eca39 100644
--- a/fs/xfs/xfs_pnfs.c
+++ b/fs/xfs/xfs_pnfs.c
@@ -31,7 +31,8 @@
31int 31int
32xfs_break_layouts( 32xfs_break_layouts(
33 struct inode *inode, 33 struct inode *inode,
34 uint *iolock) 34 uint *iolock,
35 bool with_imutex)
35{ 36{
36 struct xfs_inode *ip = XFS_I(inode); 37 struct xfs_inode *ip = XFS_I(inode);
37 int error; 38 int error;
@@ -40,8 +41,12 @@ xfs_break_layouts(
40 41
41 while ((error = break_layout(inode, false) == -EWOULDBLOCK)) { 42 while ((error = break_layout(inode, false) == -EWOULDBLOCK)) {
42 xfs_iunlock(ip, *iolock); 43 xfs_iunlock(ip, *iolock);
44 if (with_imutex && (*iolock & XFS_IOLOCK_EXCL))
45 mutex_unlock(&inode->i_mutex);
43 error = break_layout(inode, true); 46 error = break_layout(inode, true);
44 *iolock = XFS_IOLOCK_EXCL; 47 *iolock = XFS_IOLOCK_EXCL;
48 if (with_imutex)
49 mutex_lock(&inode->i_mutex);
45 xfs_ilock(ip, *iolock); 50 xfs_ilock(ip, *iolock);
46 } 51 }
47 52
diff --git a/fs/xfs/xfs_pnfs.h b/fs/xfs/xfs_pnfs.h
index b7fbfce660f6..8147ac108820 100644
--- a/fs/xfs/xfs_pnfs.h
+++ b/fs/xfs/xfs_pnfs.h
@@ -8,9 +8,10 @@ int xfs_fs_map_blocks(struct inode *inode, loff_t offset, u64 length,
8int xfs_fs_commit_blocks(struct inode *inode, struct iomap *maps, int nr_maps, 8int xfs_fs_commit_blocks(struct inode *inode, struct iomap *maps, int nr_maps,
9 struct iattr *iattr); 9 struct iattr *iattr);
10 10
11int xfs_break_layouts(struct inode *inode, uint *iolock); 11int xfs_break_layouts(struct inode *inode, uint *iolock, bool with_imutex);
12#else 12#else
13static inline int xfs_break_layouts(struct inode *inode, uint *iolock) 13static inline int
14xfs_break_layouts(struct inode *inode, uint *iolock, bool with_imutex)
14{ 15{
15 return 0; 16 return 0;
16} 17}
diff --git a/fs/xfs/xfs_qm.c b/fs/xfs/xfs_qm.c
index fbbb9e62e274..5538468c7f63 100644
--- a/fs/xfs/xfs_qm.c
+++ b/fs/xfs/xfs_qm.c
@@ -719,6 +719,7 @@ xfs_qm_qino_alloc(
719 xfs_trans_t *tp; 719 xfs_trans_t *tp;
720 int error; 720 int error;
721 int committed; 721 int committed;
722 bool need_alloc = true;
722 723
723 *ip = NULL; 724 *ip = NULL;
724 /* 725 /*
@@ -747,6 +748,7 @@ xfs_qm_qino_alloc(
747 return error; 748 return error;
748 mp->m_sb.sb_gquotino = NULLFSINO; 749 mp->m_sb.sb_gquotino = NULLFSINO;
749 mp->m_sb.sb_pquotino = NULLFSINO; 750 mp->m_sb.sb_pquotino = NULLFSINO;
751 need_alloc = false;
750 } 752 }
751 } 753 }
752 754
@@ -758,7 +760,7 @@ xfs_qm_qino_alloc(
758 return error; 760 return error;
759 } 761 }
760 762
761 if (!*ip) { 763 if (need_alloc) {
762 error = xfs_dir_ialloc(&tp, NULL, S_IFREG, 1, 0, 0, 1, ip, 764 error = xfs_dir_ialloc(&tp, NULL, S_IFREG, 1, 0, 0, 1, ip,
763 &committed); 765 &committed);
764 if (error) { 766 if (error) {
@@ -794,11 +796,14 @@ xfs_qm_qino_alloc(
794 spin_unlock(&mp->m_sb_lock); 796 spin_unlock(&mp->m_sb_lock);
795 xfs_log_sb(tp); 797 xfs_log_sb(tp);
796 798
797 if ((error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES))) { 799 error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES);
800 if (error) {
801 ASSERT(XFS_FORCED_SHUTDOWN(mp));
798 xfs_alert(mp, "%s failed (error %d)!", __func__, error); 802 xfs_alert(mp, "%s failed (error %d)!", __func__, error);
799 return error;
800 } 803 }
801 return 0; 804 if (need_alloc)
805 xfs_finish_inode_setup(*ip);
806 return error;
802} 807}
803 808
804 809
diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c
index 8fcc4ccc5c79..858e1e62bbaa 100644
--- a/fs/xfs/xfs_super.c
+++ b/fs/xfs/xfs_super.c
@@ -109,8 +109,6 @@ static struct xfs_kobj xfs_dbg_kobj; /* global debug sysfs attrs */
109#define MNTOPT_GQUOTANOENF "gqnoenforce"/* group quota limit enforcement */ 109#define MNTOPT_GQUOTANOENF "gqnoenforce"/* group quota limit enforcement */
110#define MNTOPT_PQUOTANOENF "pqnoenforce"/* project quota limit enforcement */ 110#define MNTOPT_PQUOTANOENF "pqnoenforce"/* project quota limit enforcement */
111#define MNTOPT_QUOTANOENF "qnoenforce" /* same as uqnoenforce */ 111#define MNTOPT_QUOTANOENF "qnoenforce" /* same as uqnoenforce */
112#define MNTOPT_DELAYLOG "delaylog" /* Delayed logging enabled */
113#define MNTOPT_NODELAYLOG "nodelaylog" /* Delayed logging disabled */
114#define MNTOPT_DISCARD "discard" /* Discard unused blocks */ 112#define MNTOPT_DISCARD "discard" /* Discard unused blocks */
115#define MNTOPT_NODISCARD "nodiscard" /* Do not discard unused blocks */ 113#define MNTOPT_NODISCARD "nodiscard" /* Do not discard unused blocks */
116 114
@@ -361,28 +359,10 @@ xfs_parseargs(
361 } else if (!strcmp(this_char, MNTOPT_GQUOTANOENF)) { 359 } else if (!strcmp(this_char, MNTOPT_GQUOTANOENF)) {
362 mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE); 360 mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE);
363 mp->m_qflags &= ~XFS_GQUOTA_ENFD; 361 mp->m_qflags &= ~XFS_GQUOTA_ENFD;
364 } else if (!strcmp(this_char, MNTOPT_DELAYLOG)) {
365 xfs_warn(mp,
366 "delaylog is the default now, option is deprecated.");
367 } else if (!strcmp(this_char, MNTOPT_NODELAYLOG)) {
368 xfs_warn(mp,
369 "nodelaylog support has been removed, option is deprecated.");
370 } else if (!strcmp(this_char, MNTOPT_DISCARD)) { 362 } else if (!strcmp(this_char, MNTOPT_DISCARD)) {
371 mp->m_flags |= XFS_MOUNT_DISCARD; 363 mp->m_flags |= XFS_MOUNT_DISCARD;
372 } else if (!strcmp(this_char, MNTOPT_NODISCARD)) { 364 } else if (!strcmp(this_char, MNTOPT_NODISCARD)) {
373 mp->m_flags &= ~XFS_MOUNT_DISCARD; 365 mp->m_flags &= ~XFS_MOUNT_DISCARD;
374 } else if (!strcmp(this_char, "ihashsize")) {
375 xfs_warn(mp,
376 "ihashsize no longer used, option is deprecated.");
377 } else if (!strcmp(this_char, "osyncisdsync")) {
378 xfs_warn(mp,
379 "osyncisdsync has no effect, option is deprecated.");
380 } else if (!strcmp(this_char, "osyncisosync")) {
381 xfs_warn(mp,
382 "osyncisosync has no effect, option is deprecated.");
383 } else if (!strcmp(this_char, "irixsgid")) {
384 xfs_warn(mp,
385 "irixsgid is now a sysctl(2) variable, option is deprecated.");
386 } else { 366 } else {
387 xfs_warn(mp, "unknown mount option [%s].", this_char); 367 xfs_warn(mp, "unknown mount option [%s].", this_char);
388 return -EINVAL; 368 return -EINVAL;
@@ -986,6 +966,8 @@ xfs_fs_inode_init_once(
986 atomic_set(&ip->i_pincount, 0); 966 atomic_set(&ip->i_pincount, 0);
987 spin_lock_init(&ip->i_flags_lock); 967 spin_lock_init(&ip->i_flags_lock);
988 968
969 mrlock_init(&ip->i_mmaplock, MRLOCK_ALLOW_EQUAL_PRI|MRLOCK_BARRIER,
970 "xfsino", ip->i_ino);
989 mrlock_init(&ip->i_lock, MRLOCK_ALLOW_EQUAL_PRI|MRLOCK_BARRIER, 971 mrlock_init(&ip->i_lock, MRLOCK_ALLOW_EQUAL_PRI|MRLOCK_BARRIER,
990 "xfsino", ip->i_ino); 972 "xfsino", ip->i_ino);
991} 973}
@@ -1033,23 +1015,6 @@ xfs_free_fsname(
1033 kfree(mp->m_logname); 1015 kfree(mp->m_logname);
1034} 1016}
1035 1017
1036STATIC void
1037xfs_fs_put_super(
1038 struct super_block *sb)
1039{
1040 struct xfs_mount *mp = XFS_M(sb);
1041
1042 xfs_filestream_unmount(mp);
1043 xfs_unmountfs(mp);
1044
1045 xfs_freesb(mp);
1046 xfs_icsb_destroy_counters(mp);
1047 xfs_destroy_mount_workqueues(mp);
1048 xfs_close_devices(mp);
1049 xfs_free_fsname(mp);
1050 kfree(mp);
1051}
1052
1053STATIC int 1018STATIC int
1054xfs_fs_sync_fs( 1019xfs_fs_sync_fs(
1055 struct super_block *sb, 1020 struct super_block *sb,
@@ -1083,8 +1048,11 @@ xfs_fs_statfs(
1083{ 1048{
1084 struct xfs_mount *mp = XFS_M(dentry->d_sb); 1049 struct xfs_mount *mp = XFS_M(dentry->d_sb);
1085 xfs_sb_t *sbp = &mp->m_sb; 1050 xfs_sb_t *sbp = &mp->m_sb;
1086 struct xfs_inode *ip = XFS_I(dentry->d_inode); 1051 struct xfs_inode *ip = XFS_I(d_inode(dentry));
1087 __uint64_t fakeinos, id; 1052 __uint64_t fakeinos, id;
1053 __uint64_t icount;
1054 __uint64_t ifree;
1055 __uint64_t fdblocks;
1088 xfs_extlen_t lsize; 1056 xfs_extlen_t lsize;
1089 __int64_t ffree; 1057 __int64_t ffree;
1090 1058
@@ -1095,17 +1063,21 @@ xfs_fs_statfs(
1095 statp->f_fsid.val[0] = (u32)id; 1063 statp->f_fsid.val[0] = (u32)id;
1096 statp->f_fsid.val[1] = (u32)(id >> 32); 1064 statp->f_fsid.val[1] = (u32)(id >> 32);
1097 1065
1098 xfs_icsb_sync_counters(mp, XFS_ICSB_LAZY_COUNT); 1066 icount = percpu_counter_sum(&mp->m_icount);
1067 ifree = percpu_counter_sum(&mp->m_ifree);
1068 fdblocks = percpu_counter_sum(&mp->m_fdblocks);
1099 1069
1100 spin_lock(&mp->m_sb_lock); 1070 spin_lock(&mp->m_sb_lock);
1101 statp->f_bsize = sbp->sb_blocksize; 1071 statp->f_bsize = sbp->sb_blocksize;
1102 lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0; 1072 lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0;
1103 statp->f_blocks = sbp->sb_dblocks - lsize; 1073 statp->f_blocks = sbp->sb_dblocks - lsize;
1104 statp->f_bfree = statp->f_bavail = 1074 spin_unlock(&mp->m_sb_lock);
1105 sbp->sb_fdblocks - XFS_ALLOC_SET_ASIDE(mp); 1075
1076 statp->f_bfree = fdblocks - XFS_ALLOC_SET_ASIDE(mp);
1077 statp->f_bavail = statp->f_bfree;
1078
1106 fakeinos = statp->f_bfree << sbp->sb_inopblog; 1079 fakeinos = statp->f_bfree << sbp->sb_inopblog;
1107 statp->f_files = 1080 statp->f_files = MIN(icount + fakeinos, (__uint64_t)XFS_MAXINUMBER);
1108 MIN(sbp->sb_icount + fakeinos, (__uint64_t)XFS_MAXINUMBER);
1109 if (mp->m_maxicount) 1081 if (mp->m_maxicount)
1110 statp->f_files = min_t(typeof(statp->f_files), 1082 statp->f_files = min_t(typeof(statp->f_files),
1111 statp->f_files, 1083 statp->f_files,
@@ -1117,10 +1089,9 @@ xfs_fs_statfs(
1117 sbp->sb_icount); 1089 sbp->sb_icount);
1118 1090
1119 /* make sure statp->f_ffree does not underflow */ 1091 /* make sure statp->f_ffree does not underflow */
1120 ffree = statp->f_files - (sbp->sb_icount - sbp->sb_ifree); 1092 ffree = statp->f_files - (icount - ifree);
1121 statp->f_ffree = max_t(__int64_t, ffree, 0); 1093 statp->f_ffree = max_t(__int64_t, ffree, 0);
1122 1094
1123 spin_unlock(&mp->m_sb_lock);
1124 1095
1125 if ((ip->i_d.di_flags & XFS_DIFLAG_PROJINHERIT) && 1096 if ((ip->i_d.di_flags & XFS_DIFLAG_PROJINHERIT) &&
1126 ((mp->m_qflags & (XFS_PQUOTA_ACCT|XFS_PQUOTA_ENFD))) == 1097 ((mp->m_qflags & (XFS_PQUOTA_ACCT|XFS_PQUOTA_ENFD))) ==
@@ -1256,6 +1227,12 @@ xfs_fs_remount(
1256 1227
1257 /* ro -> rw */ 1228 /* ro -> rw */
1258 if ((mp->m_flags & XFS_MOUNT_RDONLY) && !(*flags & MS_RDONLY)) { 1229 if ((mp->m_flags & XFS_MOUNT_RDONLY) && !(*flags & MS_RDONLY)) {
1230 if (mp->m_flags & XFS_MOUNT_NORECOVERY) {
1231 xfs_warn(mp,
1232 "ro->rw transition prohibited on norecovery mount");
1233 return -EINVAL;
1234 }
1235
1259 mp->m_flags &= ~XFS_MOUNT_RDONLY; 1236 mp->m_flags &= ~XFS_MOUNT_RDONLY;
1260 1237
1261 /* 1238 /*
@@ -1401,6 +1378,51 @@ xfs_finish_flags(
1401 return 0; 1378 return 0;
1402} 1379}
1403 1380
1381static int
1382xfs_init_percpu_counters(
1383 struct xfs_mount *mp)
1384{
1385 int error;
1386
1387 error = percpu_counter_init(&mp->m_icount, 0, GFP_KERNEL);
1388 if (error)
1389 return -ENOMEM;
1390
1391 error = percpu_counter_init(&mp->m_ifree, 0, GFP_KERNEL);
1392 if (error)
1393 goto free_icount;
1394
1395 error = percpu_counter_init(&mp->m_fdblocks, 0, GFP_KERNEL);
1396 if (error)
1397 goto free_ifree;
1398
1399 return 0;
1400
1401free_ifree:
1402 percpu_counter_destroy(&mp->m_ifree);
1403free_icount:
1404 percpu_counter_destroy(&mp->m_icount);
1405 return -ENOMEM;
1406}
1407
1408void
1409xfs_reinit_percpu_counters(
1410 struct xfs_mount *mp)
1411{
1412 percpu_counter_set(&mp->m_icount, mp->m_sb.sb_icount);
1413 percpu_counter_set(&mp->m_ifree, mp->m_sb.sb_ifree);
1414 percpu_counter_set(&mp->m_fdblocks, mp->m_sb.sb_fdblocks);
1415}
1416
1417static void
1418xfs_destroy_percpu_counters(
1419 struct xfs_mount *mp)
1420{
1421 percpu_counter_destroy(&mp->m_icount);
1422 percpu_counter_destroy(&mp->m_ifree);
1423 percpu_counter_destroy(&mp->m_fdblocks);
1424}
1425
1404STATIC int 1426STATIC int
1405xfs_fs_fill_super( 1427xfs_fs_fill_super(
1406 struct super_block *sb, 1428 struct super_block *sb,
@@ -1449,7 +1471,7 @@ xfs_fs_fill_super(
1449 if (error) 1471 if (error)
1450 goto out_close_devices; 1472 goto out_close_devices;
1451 1473
1452 error = xfs_icsb_init_counters(mp); 1474 error = xfs_init_percpu_counters(mp);
1453 if (error) 1475 if (error)
1454 goto out_destroy_workqueues; 1476 goto out_destroy_workqueues;
1455 1477
@@ -1507,7 +1529,7 @@ xfs_fs_fill_super(
1507 out_free_sb: 1529 out_free_sb:
1508 xfs_freesb(mp); 1530 xfs_freesb(mp);
1509 out_destroy_counters: 1531 out_destroy_counters:
1510 xfs_icsb_destroy_counters(mp); 1532 xfs_destroy_percpu_counters(mp);
1511out_destroy_workqueues: 1533out_destroy_workqueues:
1512 xfs_destroy_mount_workqueues(mp); 1534 xfs_destroy_mount_workqueues(mp);
1513 out_close_devices: 1535 out_close_devices:
@@ -1524,6 +1546,24 @@ out_destroy_workqueues:
1524 goto out_free_sb; 1546 goto out_free_sb;
1525} 1547}
1526 1548
1549STATIC void
1550xfs_fs_put_super(
1551 struct super_block *sb)
1552{
1553 struct xfs_mount *mp = XFS_M(sb);
1554
1555 xfs_notice(mp, "Unmounting Filesystem");
1556 xfs_filestream_unmount(mp);
1557 xfs_unmountfs(mp);
1558
1559 xfs_freesb(mp);
1560 xfs_destroy_percpu_counters(mp);
1561 xfs_destroy_mount_workqueues(mp);
1562 xfs_close_devices(mp);
1563 xfs_free_fsname(mp);
1564 kfree(mp);
1565}
1566
1527STATIC struct dentry * 1567STATIC struct dentry *
1528xfs_fs_mount( 1568xfs_fs_mount(
1529 struct file_system_type *fs_type, 1569 struct file_system_type *fs_type,
diff --git a/fs/xfs/xfs_super.h b/fs/xfs/xfs_super.h
index 2b830c2f322e..499058fea303 100644
--- a/fs/xfs/xfs_super.h
+++ b/fs/xfs/xfs_super.h
@@ -72,6 +72,8 @@ extern const struct export_operations xfs_export_operations;
72extern const struct xattr_handler *xfs_xattr_handlers[]; 72extern const struct xattr_handler *xfs_xattr_handlers[];
73extern const struct quotactl_ops xfs_quotactl_operations; 73extern const struct quotactl_ops xfs_quotactl_operations;
74 74
75extern void xfs_reinit_percpu_counters(struct xfs_mount *mp);
76
75#define XFS_M(sb) ((struct xfs_mount *)((sb)->s_fs_info)) 77#define XFS_M(sb) ((struct xfs_mount *)((sb)->s_fs_info))
76 78
77#endif /* __XFS_SUPER_H__ */ 79#endif /* __XFS_SUPER_H__ */
diff --git a/fs/xfs/xfs_symlink.c b/fs/xfs/xfs_symlink.c
index 25791df6f638..3df411eadb86 100644
--- a/fs/xfs/xfs_symlink.c
+++ b/fs/xfs/xfs_symlink.c
@@ -177,7 +177,7 @@ xfs_symlink(
177 int pathlen; 177 int pathlen;
178 struct xfs_bmap_free free_list; 178 struct xfs_bmap_free free_list;
179 xfs_fsblock_t first_block; 179 xfs_fsblock_t first_block;
180 bool unlock_dp_on_error = false; 180 bool unlock_dp_on_error = false;
181 uint cancel_flags; 181 uint cancel_flags;
182 int committed; 182 int committed;
183 xfs_fileoff_t first_fsb; 183 xfs_fileoff_t first_fsb;
@@ -221,7 +221,7 @@ xfs_symlink(
221 XFS_QMOPT_QUOTALL | XFS_QMOPT_INHERIT, 221 XFS_QMOPT_QUOTALL | XFS_QMOPT_INHERIT,
222 &udqp, &gdqp, &pdqp); 222 &udqp, &gdqp, &pdqp);
223 if (error) 223 if (error)
224 goto std_return; 224 return error;
225 225
226 tp = xfs_trans_alloc(mp, XFS_TRANS_SYMLINK); 226 tp = xfs_trans_alloc(mp, XFS_TRANS_SYMLINK);
227 cancel_flags = XFS_TRANS_RELEASE_LOG_RES; 227 cancel_flags = XFS_TRANS_RELEASE_LOG_RES;
@@ -241,7 +241,7 @@ xfs_symlink(
241 } 241 }
242 if (error) { 242 if (error) {
243 cancel_flags = 0; 243 cancel_flags = 0;
244 goto error_return; 244 goto out_trans_cancel;
245 } 245 }
246 246
247 xfs_ilock(dp, XFS_ILOCK_EXCL | XFS_ILOCK_PARENT); 247 xfs_ilock(dp, XFS_ILOCK_EXCL | XFS_ILOCK_PARENT);
@@ -252,7 +252,7 @@ xfs_symlink(
252 */ 252 */
253 if (dp->i_d.di_flags & XFS_DIFLAG_NOSYMLINKS) { 253 if (dp->i_d.di_flags & XFS_DIFLAG_NOSYMLINKS) {
254 error = -EPERM; 254 error = -EPERM;
255 goto error_return; 255 goto out_trans_cancel;
256 } 256 }
257 257
258 /* 258 /*
@@ -261,7 +261,7 @@ xfs_symlink(
261 error = xfs_trans_reserve_quota(tp, mp, udqp, gdqp, 261 error = xfs_trans_reserve_quota(tp, mp, udqp, gdqp,
262 pdqp, resblks, 1, 0); 262 pdqp, resblks, 1, 0);
263 if (error) 263 if (error)
264 goto error_return; 264 goto out_trans_cancel;
265 265
266 /* 266 /*
267 * Check for ability to enter directory entry, if no space reserved. 267 * Check for ability to enter directory entry, if no space reserved.
@@ -269,7 +269,7 @@ xfs_symlink(
269 if (!resblks) { 269 if (!resblks) {
270 error = xfs_dir_canenter(tp, dp, link_name); 270 error = xfs_dir_canenter(tp, dp, link_name);
271 if (error) 271 if (error)
272 goto error_return; 272 goto out_trans_cancel;
273 } 273 }
274 /* 274 /*
275 * Initialize the bmap freelist prior to calling either 275 * Initialize the bmap freelist prior to calling either
@@ -282,15 +282,14 @@ xfs_symlink(
282 */ 282 */
283 error = xfs_dir_ialloc(&tp, dp, S_IFLNK | (mode & ~S_IFMT), 1, 0, 283 error = xfs_dir_ialloc(&tp, dp, S_IFLNK | (mode & ~S_IFMT), 1, 0,
284 prid, resblks > 0, &ip, NULL); 284 prid, resblks > 0, &ip, NULL);
285 if (error) { 285 if (error)
286 if (error == -ENOSPC) 286 goto out_trans_cancel;
287 goto error_return;
288 goto error1;
289 }
290 287
291 /* 288 /*
292 * An error after we've joined dp to the transaction will result in the 289 * Now we join the directory inode to the transaction. We do not do it
293 * transaction cancel unlocking dp so don't do it explicitly in the 290 * earlier because xfs_dir_ialloc might commit the previous transaction
291 * (and release all the locks). An error from here on will result in
292 * the transaction cancel unlocking dp so don't do it explicitly in the
294 * error path. 293 * error path.
295 */ 294 */
296 xfs_trans_ijoin(tp, dp, XFS_ILOCK_EXCL); 295 xfs_trans_ijoin(tp, dp, XFS_ILOCK_EXCL);
@@ -330,7 +329,7 @@ xfs_symlink(
330 XFS_BMAPI_METADATA, &first_block, resblks, 329 XFS_BMAPI_METADATA, &first_block, resblks,
331 mval, &nmaps, &free_list); 330 mval, &nmaps, &free_list);
332 if (error) 331 if (error)
333 goto error2; 332 goto out_bmap_cancel;
334 333
335 if (resblks) 334 if (resblks)
336 resblks -= fs_blocks; 335 resblks -= fs_blocks;
@@ -348,7 +347,7 @@ xfs_symlink(
348 BTOBB(byte_cnt), 0); 347 BTOBB(byte_cnt), 0);
349 if (!bp) { 348 if (!bp) {
350 error = -ENOMEM; 349 error = -ENOMEM;
351 goto error2; 350 goto out_bmap_cancel;
352 } 351 }
353 bp->b_ops = &xfs_symlink_buf_ops; 352 bp->b_ops = &xfs_symlink_buf_ops;
354 353
@@ -378,7 +377,7 @@ xfs_symlink(
378 error = xfs_dir_createname(tp, dp, link_name, ip->i_ino, 377 error = xfs_dir_createname(tp, dp, link_name, ip->i_ino,
379 &first_block, &free_list, resblks); 378 &first_block, &free_list, resblks);
380 if (error) 379 if (error)
381 goto error2; 380 goto out_bmap_cancel;
382 xfs_trans_ichgtime(tp, dp, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG); 381 xfs_trans_ichgtime(tp, dp, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG);
383 xfs_trans_log_inode(tp, dp, XFS_ILOG_CORE); 382 xfs_trans_log_inode(tp, dp, XFS_ILOG_CORE);
384 383
@@ -392,10 +391,13 @@ xfs_symlink(
392 } 391 }
393 392
394 error = xfs_bmap_finish(&tp, &free_list, &committed); 393 error = xfs_bmap_finish(&tp, &free_list, &committed);
395 if (error) { 394 if (error)
396 goto error2; 395 goto out_bmap_cancel;
397 } 396
398 error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES); 397 error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES);
398 if (error)
399 goto out_release_inode;
400
399 xfs_qm_dqrele(udqp); 401 xfs_qm_dqrele(udqp);
400 xfs_qm_dqrele(gdqp); 402 xfs_qm_dqrele(gdqp);
401 xfs_qm_dqrele(pdqp); 403 xfs_qm_dqrele(pdqp);
@@ -403,20 +405,28 @@ xfs_symlink(
403 *ipp = ip; 405 *ipp = ip;
404 return 0; 406 return 0;
405 407
406 error2: 408out_bmap_cancel:
407 IRELE(ip);
408 error1:
409 xfs_bmap_cancel(&free_list); 409 xfs_bmap_cancel(&free_list);
410 cancel_flags |= XFS_TRANS_ABORT; 410 cancel_flags |= XFS_TRANS_ABORT;
411 error_return: 411out_trans_cancel:
412 xfs_trans_cancel(tp, cancel_flags); 412 xfs_trans_cancel(tp, cancel_flags);
413out_release_inode:
414 /*
415 * Wait until after the current transaction is aborted to finish the
416 * setup of the inode and release the inode. This prevents recursive
417 * transactions and deadlocks from xfs_inactive.
418 */
419 if (ip) {
420 xfs_finish_inode_setup(ip);
421 IRELE(ip);
422 }
423
413 xfs_qm_dqrele(udqp); 424 xfs_qm_dqrele(udqp);
414 xfs_qm_dqrele(gdqp); 425 xfs_qm_dqrele(gdqp);
415 xfs_qm_dqrele(pdqp); 426 xfs_qm_dqrele(pdqp);
416 427
417 if (unlock_dp_on_error) 428 if (unlock_dp_on_error)
418 xfs_iunlock(dp, XFS_ILOCK_EXCL); 429 xfs_iunlock(dp, XFS_ILOCK_EXCL);
419 std_return:
420 return error; 430 return error;
421} 431}
422 432
diff --git a/fs/xfs/xfs_trace.h b/fs/xfs/xfs_trace.h
index 51372e34d988..615781bf4ee5 100644
--- a/fs/xfs/xfs_trace.h
+++ b/fs/xfs/xfs_trace.h
@@ -115,7 +115,7 @@ DECLARE_EVENT_CLASS(xfs_perag_class,
115 __entry->refcount = refcount; 115 __entry->refcount = refcount;
116 __entry->caller_ip = caller_ip; 116 __entry->caller_ip = caller_ip;
117 ), 117 ),
118 TP_printk("dev %d:%d agno %u refcount %d caller %pf", 118 TP_printk("dev %d:%d agno %u refcount %d caller %ps",
119 MAJOR(__entry->dev), MINOR(__entry->dev), 119 MAJOR(__entry->dev), MINOR(__entry->dev),
120 __entry->agno, 120 __entry->agno,
121 __entry->refcount, 121 __entry->refcount,
@@ -239,7 +239,7 @@ TRACE_EVENT(xfs_iext_insert,
239 __entry->caller_ip = caller_ip; 239 __entry->caller_ip = caller_ip;
240 ), 240 ),
241 TP_printk("dev %d:%d ino 0x%llx state %s idx %ld " 241 TP_printk("dev %d:%d ino 0x%llx state %s idx %ld "
242 "offset %lld block %lld count %lld flag %d caller %pf", 242 "offset %lld block %lld count %lld flag %d caller %ps",
243 MAJOR(__entry->dev), MINOR(__entry->dev), 243 MAJOR(__entry->dev), MINOR(__entry->dev),
244 __entry->ino, 244 __entry->ino,
245 __print_flags(__entry->bmap_state, "|", XFS_BMAP_EXT_FLAGS), 245 __print_flags(__entry->bmap_state, "|", XFS_BMAP_EXT_FLAGS),
@@ -283,7 +283,7 @@ DECLARE_EVENT_CLASS(xfs_bmap_class,
283 __entry->caller_ip = caller_ip; 283 __entry->caller_ip = caller_ip;
284 ), 284 ),
285 TP_printk("dev %d:%d ino 0x%llx state %s idx %ld " 285 TP_printk("dev %d:%d ino 0x%llx state %s idx %ld "
286 "offset %lld block %lld count %lld flag %d caller %pf", 286 "offset %lld block %lld count %lld flag %d caller %ps",
287 MAJOR(__entry->dev), MINOR(__entry->dev), 287 MAJOR(__entry->dev), MINOR(__entry->dev),
288 __entry->ino, 288 __entry->ino,
289 __print_flags(__entry->bmap_state, "|", XFS_BMAP_EXT_FLAGS), 289 __print_flags(__entry->bmap_state, "|", XFS_BMAP_EXT_FLAGS),
@@ -329,7 +329,7 @@ DECLARE_EVENT_CLASS(xfs_buf_class,
329 __entry->caller_ip = caller_ip; 329 __entry->caller_ip = caller_ip;
330 ), 330 ),
331 TP_printk("dev %d:%d bno 0x%llx nblks 0x%x hold %d pincount %d " 331 TP_printk("dev %d:%d bno 0x%llx nblks 0x%x hold %d pincount %d "
332 "lock %d flags %s caller %pf", 332 "lock %d flags %s caller %ps",
333 MAJOR(__entry->dev), MINOR(__entry->dev), 333 MAJOR(__entry->dev), MINOR(__entry->dev),
334 (unsigned long long)__entry->bno, 334 (unsigned long long)__entry->bno,
335 __entry->nblks, 335 __entry->nblks,
@@ -402,7 +402,7 @@ DECLARE_EVENT_CLASS(xfs_buf_flags_class,
402 __entry->caller_ip = caller_ip; 402 __entry->caller_ip = caller_ip;
403 ), 403 ),
404 TP_printk("dev %d:%d bno 0x%llx len 0x%zx hold %d pincount %d " 404 TP_printk("dev %d:%d bno 0x%llx len 0x%zx hold %d pincount %d "
405 "lock %d flags %s caller %pf", 405 "lock %d flags %s caller %ps",
406 MAJOR(__entry->dev), MINOR(__entry->dev), 406 MAJOR(__entry->dev), MINOR(__entry->dev),
407 (unsigned long long)__entry->bno, 407 (unsigned long long)__entry->bno,
408 __entry->buffer_length, 408 __entry->buffer_length,
@@ -447,7 +447,7 @@ TRACE_EVENT(xfs_buf_ioerror,
447 __entry->caller_ip = caller_ip; 447 __entry->caller_ip = caller_ip;
448 ), 448 ),
449 TP_printk("dev %d:%d bno 0x%llx len 0x%zx hold %d pincount %d " 449 TP_printk("dev %d:%d bno 0x%llx len 0x%zx hold %d pincount %d "
450 "lock %d error %d flags %s caller %pf", 450 "lock %d error %d flags %s caller %ps",
451 MAJOR(__entry->dev), MINOR(__entry->dev), 451 MAJOR(__entry->dev), MINOR(__entry->dev),
452 (unsigned long long)__entry->bno, 452 (unsigned long long)__entry->bno,
453 __entry->buffer_length, 453 __entry->buffer_length,
@@ -613,7 +613,7 @@ DECLARE_EVENT_CLASS(xfs_lock_class,
613 __entry->lock_flags = lock_flags; 613 __entry->lock_flags = lock_flags;
614 __entry->caller_ip = caller_ip; 614 __entry->caller_ip = caller_ip;
615 ), 615 ),
616 TP_printk("dev %d:%d ino 0x%llx flags %s caller %pf", 616 TP_printk("dev %d:%d ino 0x%llx flags %s caller %ps",
617 MAJOR(__entry->dev), MINOR(__entry->dev), 617 MAJOR(__entry->dev), MINOR(__entry->dev),
618 __entry->ino, 618 __entry->ino,
619 __print_flags(__entry->lock_flags, "|", XFS_LOCK_FLAGS), 619 __print_flags(__entry->lock_flags, "|", XFS_LOCK_FLAGS),
@@ -664,6 +664,7 @@ DEFINE_INODE_EVENT(xfs_alloc_file_space);
664DEFINE_INODE_EVENT(xfs_free_file_space); 664DEFINE_INODE_EVENT(xfs_free_file_space);
665DEFINE_INODE_EVENT(xfs_zero_file_space); 665DEFINE_INODE_EVENT(xfs_zero_file_space);
666DEFINE_INODE_EVENT(xfs_collapse_file_space); 666DEFINE_INODE_EVENT(xfs_collapse_file_space);
667DEFINE_INODE_EVENT(xfs_insert_file_space);
667DEFINE_INODE_EVENT(xfs_readdir); 668DEFINE_INODE_EVENT(xfs_readdir);
668#ifdef CONFIG_XFS_POSIX_ACL 669#ifdef CONFIG_XFS_POSIX_ACL
669DEFINE_INODE_EVENT(xfs_get_acl); 670DEFINE_INODE_EVENT(xfs_get_acl);
@@ -685,6 +686,9 @@ DEFINE_INODE_EVENT(xfs_inode_set_eofblocks_tag);
685DEFINE_INODE_EVENT(xfs_inode_clear_eofblocks_tag); 686DEFINE_INODE_EVENT(xfs_inode_clear_eofblocks_tag);
686DEFINE_INODE_EVENT(xfs_inode_free_eofblocks_invalid); 687DEFINE_INODE_EVENT(xfs_inode_free_eofblocks_invalid);
687 688
689DEFINE_INODE_EVENT(xfs_filemap_fault);
690DEFINE_INODE_EVENT(xfs_filemap_page_mkwrite);
691
688DECLARE_EVENT_CLASS(xfs_iref_class, 692DECLARE_EVENT_CLASS(xfs_iref_class,
689 TP_PROTO(struct xfs_inode *ip, unsigned long caller_ip), 693 TP_PROTO(struct xfs_inode *ip, unsigned long caller_ip),
690 TP_ARGS(ip, caller_ip), 694 TP_ARGS(ip, caller_ip),
@@ -702,7 +706,7 @@ DECLARE_EVENT_CLASS(xfs_iref_class,
702 __entry->pincount = atomic_read(&ip->i_pincount); 706 __entry->pincount = atomic_read(&ip->i_pincount);
703 __entry->caller_ip = caller_ip; 707 __entry->caller_ip = caller_ip;
704 ), 708 ),
705 TP_printk("dev %d:%d ino 0x%llx count %d pincount %d caller %pf", 709 TP_printk("dev %d:%d ino 0x%llx count %d pincount %d caller %ps",
706 MAJOR(__entry->dev), MINOR(__entry->dev), 710 MAJOR(__entry->dev), MINOR(__entry->dev),
707 __entry->ino, 711 __entry->ino,
708 __entry->count, 712 __entry->count,
@@ -1217,6 +1221,11 @@ DEFINE_IOMAP_EVENT(xfs_map_blocks_found);
1217DEFINE_IOMAP_EVENT(xfs_map_blocks_alloc); 1221DEFINE_IOMAP_EVENT(xfs_map_blocks_alloc);
1218DEFINE_IOMAP_EVENT(xfs_get_blocks_found); 1222DEFINE_IOMAP_EVENT(xfs_get_blocks_found);
1219DEFINE_IOMAP_EVENT(xfs_get_blocks_alloc); 1223DEFINE_IOMAP_EVENT(xfs_get_blocks_alloc);
1224DEFINE_IOMAP_EVENT(xfs_gbmap_direct);
1225DEFINE_IOMAP_EVENT(xfs_gbmap_direct_new);
1226DEFINE_IOMAP_EVENT(xfs_gbmap_direct_update);
1227DEFINE_IOMAP_EVENT(xfs_gbmap_direct_none);
1228DEFINE_IOMAP_EVENT(xfs_gbmap_direct_endio);
1220 1229
1221DECLARE_EVENT_CLASS(xfs_simple_io_class, 1230DECLARE_EVENT_CLASS(xfs_simple_io_class,
1222 TP_PROTO(struct xfs_inode *ip, xfs_off_t offset, ssize_t count), 1231 TP_PROTO(struct xfs_inode *ip, xfs_off_t offset, ssize_t count),
@@ -1333,7 +1342,7 @@ TRACE_EVENT(xfs_bunmap,
1333 __entry->flags = flags; 1342 __entry->flags = flags;
1334 ), 1343 ),
1335 TP_printk("dev %d:%d ino 0x%llx size 0x%llx bno 0x%llx len 0x%llx" 1344 TP_printk("dev %d:%d ino 0x%llx size 0x%llx bno 0x%llx len 0x%llx"
1336 "flags %s caller %pf", 1345 "flags %s caller %ps",
1337 MAJOR(__entry->dev), MINOR(__entry->dev), 1346 MAJOR(__entry->dev), MINOR(__entry->dev),
1338 __entry->ino, 1347 __entry->ino,
1339 __entry->size, 1348 __entry->size,
@@ -1466,7 +1475,7 @@ TRACE_EVENT(xfs_agf,
1466 ), 1475 ),
1467 TP_printk("dev %d:%d agno %u flags %s length %u roots b %u c %u " 1476 TP_printk("dev %d:%d agno %u flags %s length %u roots b %u c %u "
1468 "levels b %u c %u flfirst %u fllast %u flcount %u " 1477 "levels b %u c %u flfirst %u fllast %u flcount %u "
1469 "freeblks %u longest %u caller %pf", 1478 "freeblks %u longest %u caller %ps",
1470 MAJOR(__entry->dev), MINOR(__entry->dev), 1479 MAJOR(__entry->dev), MINOR(__entry->dev),
1471 __entry->agno, 1480 __entry->agno,
1472 __print_flags(__entry->flags, "|", XFS_AGF_FLAGS), 1481 __print_flags(__entry->flags, "|", XFS_AGF_FLAGS),
diff --git a/fs/xfs/xfs_trans.c b/fs/xfs/xfs_trans.c
index eb90cd59a0ec..220ef2c906b2 100644
--- a/fs/xfs/xfs_trans.c
+++ b/fs/xfs/xfs_trans.c
@@ -173,7 +173,7 @@ xfs_trans_reserve(
173 uint rtextents) 173 uint rtextents)
174{ 174{
175 int error = 0; 175 int error = 0;
176 int rsvd = (tp->t_flags & XFS_TRANS_RESERVE) != 0; 176 bool rsvd = (tp->t_flags & XFS_TRANS_RESERVE) != 0;
177 177
178 /* Mark this thread as being in a transaction */ 178 /* Mark this thread as being in a transaction */
179 current_set_flags_nested(&tp->t_pflags, PF_FSTRANS); 179 current_set_flags_nested(&tp->t_pflags, PF_FSTRANS);
@@ -184,8 +184,7 @@ xfs_trans_reserve(
184 * fail if the count would go below zero. 184 * fail if the count would go below zero.
185 */ 185 */
186 if (blocks > 0) { 186 if (blocks > 0) {
187 error = xfs_icsb_modify_counters(tp->t_mountp, XFS_SBS_FDBLOCKS, 187 error = xfs_mod_fdblocks(tp->t_mountp, -((int64_t)blocks), rsvd);
188 -((int64_t)blocks), rsvd);
189 if (error != 0) { 188 if (error != 0) {
190 current_restore_flags_nested(&tp->t_pflags, PF_FSTRANS); 189 current_restore_flags_nested(&tp->t_pflags, PF_FSTRANS);
191 return -ENOSPC; 190 return -ENOSPC;
@@ -236,8 +235,7 @@ xfs_trans_reserve(
236 * fail if the count would go below zero. 235 * fail if the count would go below zero.
237 */ 236 */
238 if (rtextents > 0) { 237 if (rtextents > 0) {
239 error = xfs_mod_incore_sb(tp->t_mountp, XFS_SBS_FREXTENTS, 238 error = xfs_mod_frextents(tp->t_mountp, -((int64_t)rtextents));
240 -((int64_t)rtextents), rsvd);
241 if (error) { 239 if (error) {
242 error = -ENOSPC; 240 error = -ENOSPC;
243 goto undo_log; 241 goto undo_log;
@@ -268,8 +266,7 @@ undo_log:
268 266
269undo_blocks: 267undo_blocks:
270 if (blocks > 0) { 268 if (blocks > 0) {
271 xfs_icsb_modify_counters(tp->t_mountp, XFS_SBS_FDBLOCKS, 269 xfs_mod_fdblocks(tp->t_mountp, -((int64_t)blocks), rsvd);
272 (int64_t)blocks, rsvd);
273 tp->t_blk_res = 0; 270 tp->t_blk_res = 0;
274 } 271 }
275 272
@@ -488,6 +485,54 @@ xfs_trans_apply_sb_deltas(
488 sizeof(sbp->sb_frextents) - 1); 485 sizeof(sbp->sb_frextents) - 1);
489} 486}
490 487
488STATIC int
489xfs_sb_mod8(
490 uint8_t *field,
491 int8_t delta)
492{
493 int8_t counter = *field;
494
495 counter += delta;
496 if (counter < 0) {
497 ASSERT(0);
498 return -EINVAL;
499 }
500 *field = counter;
501 return 0;
502}
503
504STATIC int
505xfs_sb_mod32(
506 uint32_t *field,
507 int32_t delta)
508{
509 int32_t counter = *field;
510
511 counter += delta;
512 if (counter < 0) {
513 ASSERT(0);
514 return -EINVAL;
515 }
516 *field = counter;
517 return 0;
518}
519
520STATIC int
521xfs_sb_mod64(
522 uint64_t *field,
523 int64_t delta)
524{
525 int64_t counter = *field;
526
527 counter += delta;
528 if (counter < 0) {
529 ASSERT(0);
530 return -EINVAL;
531 }
532 *field = counter;
533 return 0;
534}
535
491/* 536/*
492 * xfs_trans_unreserve_and_mod_sb() is called to release unused reservations 537 * xfs_trans_unreserve_and_mod_sb() is called to release unused reservations
493 * and apply superblock counter changes to the in-core superblock. The 538 * and apply superblock counter changes to the in-core superblock. The
@@ -495,13 +540,6 @@ xfs_trans_apply_sb_deltas(
495 * applied to the in-core superblock. The idea is that that has already been 540 * applied to the in-core superblock. The idea is that that has already been
496 * done. 541 * done.
497 * 542 *
498 * This is done efficiently with a single call to xfs_mod_incore_sb_batch().
499 * However, we have to ensure that we only modify each superblock field only
500 * once because the application of the delta values may not be atomic. That can
501 * lead to ENOSPC races occurring if we have two separate modifcations of the
502 * free space counter to put back the entire reservation and then take away
503 * what we used.
504 *
505 * If we are not logging superblock counters, then the inode allocated/free and 543 * If we are not logging superblock counters, then the inode allocated/free and
506 * used block counts are not updated in the on disk superblock. In this case, 544 * used block counts are not updated in the on disk superblock. In this case,
507 * XFS_TRANS_SB_DIRTY will not be set when the transaction is updated but we 545 * XFS_TRANS_SB_DIRTY will not be set when the transaction is updated but we
@@ -509,21 +547,15 @@ xfs_trans_apply_sb_deltas(
509 */ 547 */
510void 548void
511xfs_trans_unreserve_and_mod_sb( 549xfs_trans_unreserve_and_mod_sb(
512 xfs_trans_t *tp) 550 struct xfs_trans *tp)
513{ 551{
514 xfs_mod_sb_t msb[9]; /* If you add cases, add entries */ 552 struct xfs_mount *mp = tp->t_mountp;
515 xfs_mod_sb_t *msbp; 553 bool rsvd = (tp->t_flags & XFS_TRANS_RESERVE) != 0;
516 xfs_mount_t *mp = tp->t_mountp; 554 int64_t blkdelta = 0;
517 /* REFERENCED */ 555 int64_t rtxdelta = 0;
518 int error; 556 int64_t idelta = 0;
519 int rsvd; 557 int64_t ifreedelta = 0;
520 int64_t blkdelta = 0; 558 int error;
521 int64_t rtxdelta = 0;
522 int64_t idelta = 0;
523 int64_t ifreedelta = 0;
524
525 msbp = msb;
526 rsvd = (tp->t_flags & XFS_TRANS_RESERVE) != 0;
527 559
528 /* calculate deltas */ 560 /* calculate deltas */
529 if (tp->t_blk_res > 0) 561 if (tp->t_blk_res > 0)
@@ -547,97 +579,115 @@ xfs_trans_unreserve_and_mod_sb(
547 579
548 /* apply the per-cpu counters */ 580 /* apply the per-cpu counters */
549 if (blkdelta) { 581 if (blkdelta) {
550 error = xfs_icsb_modify_counters(mp, XFS_SBS_FDBLOCKS, 582 error = xfs_mod_fdblocks(mp, blkdelta, rsvd);
551 blkdelta, rsvd);
552 if (error) 583 if (error)
553 goto out; 584 goto out;
554 } 585 }
555 586
556 if (idelta) { 587 if (idelta) {
557 error = xfs_icsb_modify_counters(mp, XFS_SBS_ICOUNT, 588 error = xfs_mod_icount(mp, idelta);
558 idelta, rsvd);
559 if (error) 589 if (error)
560 goto out_undo_fdblocks; 590 goto out_undo_fdblocks;
561 } 591 }
562 592
563 if (ifreedelta) { 593 if (ifreedelta) {
564 error = xfs_icsb_modify_counters(mp, XFS_SBS_IFREE, 594 error = xfs_mod_ifree(mp, ifreedelta);
565 ifreedelta, rsvd);
566 if (error) 595 if (error)
567 goto out_undo_icount; 596 goto out_undo_icount;
568 } 597 }
569 598
599 if (rtxdelta == 0 && !(tp->t_flags & XFS_TRANS_SB_DIRTY))
600 return;
601
570 /* apply remaining deltas */ 602 /* apply remaining deltas */
571 if (rtxdelta != 0) { 603 spin_lock(&mp->m_sb_lock);
572 msbp->msb_field = XFS_SBS_FREXTENTS; 604 if (rtxdelta) {
573 msbp->msb_delta = rtxdelta; 605 error = xfs_sb_mod64(&mp->m_sb.sb_frextents, rtxdelta);
574 msbp++; 606 if (error)
607 goto out_undo_ifree;
575 } 608 }
576 609
577 if (tp->t_flags & XFS_TRANS_SB_DIRTY) { 610 if (tp->t_dblocks_delta != 0) {
578 if (tp->t_dblocks_delta != 0) { 611 error = xfs_sb_mod64(&mp->m_sb.sb_dblocks, tp->t_dblocks_delta);
579 msbp->msb_field = XFS_SBS_DBLOCKS; 612 if (error)
580 msbp->msb_delta = tp->t_dblocks_delta; 613 goto out_undo_frextents;
581 msbp++;
582 }
583 if (tp->t_agcount_delta != 0) {
584 msbp->msb_field = XFS_SBS_AGCOUNT;
585 msbp->msb_delta = tp->t_agcount_delta;
586 msbp++;
587 }
588 if (tp->t_imaxpct_delta != 0) {
589 msbp->msb_field = XFS_SBS_IMAX_PCT;
590 msbp->msb_delta = tp->t_imaxpct_delta;
591 msbp++;
592 }
593 if (tp->t_rextsize_delta != 0) {
594 msbp->msb_field = XFS_SBS_REXTSIZE;
595 msbp->msb_delta = tp->t_rextsize_delta;
596 msbp++;
597 }
598 if (tp->t_rbmblocks_delta != 0) {
599 msbp->msb_field = XFS_SBS_RBMBLOCKS;
600 msbp->msb_delta = tp->t_rbmblocks_delta;
601 msbp++;
602 }
603 if (tp->t_rblocks_delta != 0) {
604 msbp->msb_field = XFS_SBS_RBLOCKS;
605 msbp->msb_delta = tp->t_rblocks_delta;
606 msbp++;
607 }
608 if (tp->t_rextents_delta != 0) {
609 msbp->msb_field = XFS_SBS_REXTENTS;
610 msbp->msb_delta = tp->t_rextents_delta;
611 msbp++;
612 }
613 if (tp->t_rextslog_delta != 0) {
614 msbp->msb_field = XFS_SBS_REXTSLOG;
615 msbp->msb_delta = tp->t_rextslog_delta;
616 msbp++;
617 }
618 } 614 }
619 615 if (tp->t_agcount_delta != 0) {
620 /* 616 error = xfs_sb_mod32(&mp->m_sb.sb_agcount, tp->t_agcount_delta);
621 * If we need to change anything, do it.
622 */
623 if (msbp > msb) {
624 error = xfs_mod_incore_sb_batch(tp->t_mountp, msb,
625 (uint)(msbp - msb), rsvd);
626 if (error) 617 if (error)
627 goto out_undo_ifreecount; 618 goto out_undo_dblocks;
628 } 619 }
629 620 if (tp->t_imaxpct_delta != 0) {
621 error = xfs_sb_mod8(&mp->m_sb.sb_imax_pct, tp->t_imaxpct_delta);
622 if (error)
623 goto out_undo_agcount;
624 }
625 if (tp->t_rextsize_delta != 0) {
626 error = xfs_sb_mod32(&mp->m_sb.sb_rextsize,
627 tp->t_rextsize_delta);
628 if (error)
629 goto out_undo_imaxpct;
630 }
631 if (tp->t_rbmblocks_delta != 0) {
632 error = xfs_sb_mod32(&mp->m_sb.sb_rbmblocks,
633 tp->t_rbmblocks_delta);
634 if (error)
635 goto out_undo_rextsize;
636 }
637 if (tp->t_rblocks_delta != 0) {
638 error = xfs_sb_mod64(&mp->m_sb.sb_rblocks, tp->t_rblocks_delta);
639 if (error)
640 goto out_undo_rbmblocks;
641 }
642 if (tp->t_rextents_delta != 0) {
643 error = xfs_sb_mod64(&mp->m_sb.sb_rextents,
644 tp->t_rextents_delta);
645 if (error)
646 goto out_undo_rblocks;
647 }
648 if (tp->t_rextslog_delta != 0) {
649 error = xfs_sb_mod8(&mp->m_sb.sb_rextslog,
650 tp->t_rextslog_delta);
651 if (error)
652 goto out_undo_rextents;
653 }
654 spin_unlock(&mp->m_sb_lock);
630 return; 655 return;
631 656
632out_undo_ifreecount: 657out_undo_rextents:
658 if (tp->t_rextents_delta)
659 xfs_sb_mod64(&mp->m_sb.sb_rextents, -tp->t_rextents_delta);
660out_undo_rblocks:
661 if (tp->t_rblocks_delta)
662 xfs_sb_mod64(&mp->m_sb.sb_rblocks, -tp->t_rblocks_delta);
663out_undo_rbmblocks:
664 if (tp->t_rbmblocks_delta)
665 xfs_sb_mod32(&mp->m_sb.sb_rbmblocks, -tp->t_rbmblocks_delta);
666out_undo_rextsize:
667 if (tp->t_rextsize_delta)
668 xfs_sb_mod32(&mp->m_sb.sb_rextsize, -tp->t_rextsize_delta);
669out_undo_imaxpct:
670 if (tp->t_rextsize_delta)
671 xfs_sb_mod8(&mp->m_sb.sb_imax_pct, -tp->t_imaxpct_delta);
672out_undo_agcount:
673 if (tp->t_agcount_delta)
674 xfs_sb_mod32(&mp->m_sb.sb_agcount, -tp->t_agcount_delta);
675out_undo_dblocks:
676 if (tp->t_dblocks_delta)
677 xfs_sb_mod64(&mp->m_sb.sb_dblocks, -tp->t_dblocks_delta);
678out_undo_frextents:
679 if (rtxdelta)
680 xfs_sb_mod64(&mp->m_sb.sb_frextents, -rtxdelta);
681out_undo_ifree:
682 spin_unlock(&mp->m_sb_lock);
633 if (ifreedelta) 683 if (ifreedelta)
634 xfs_icsb_modify_counters(mp, XFS_SBS_IFREE, -ifreedelta, rsvd); 684 xfs_mod_ifree(mp, -ifreedelta);
635out_undo_icount: 685out_undo_icount:
636 if (idelta) 686 if (idelta)
637 xfs_icsb_modify_counters(mp, XFS_SBS_ICOUNT, -idelta, rsvd); 687 xfs_mod_icount(mp, -idelta);
638out_undo_fdblocks: 688out_undo_fdblocks:
639 if (blkdelta) 689 if (blkdelta)
640 xfs_icsb_modify_counters(mp, XFS_SBS_FDBLOCKS, -blkdelta, rsvd); 690 xfs_mod_fdblocks(mp, -blkdelta, rsvd);
641out: 691out:
642 ASSERT(error == 0); 692 ASSERT(error == 0);
643 return; 693 return;
diff --git a/fs/xfs/xfs_xattr.c b/fs/xfs/xfs_xattr.c
index 69f6e475de97..c036815183cb 100644
--- a/fs/xfs/xfs_xattr.c
+++ b/fs/xfs/xfs_xattr.c
@@ -35,7 +35,7 @@ static int
35xfs_xattr_get(struct dentry *dentry, const char *name, 35xfs_xattr_get(struct dentry *dentry, const char *name,
36 void *value, size_t size, int xflags) 36 void *value, size_t size, int xflags)
37{ 37{
38 struct xfs_inode *ip = XFS_I(dentry->d_inode); 38 struct xfs_inode *ip = XFS_I(d_inode(dentry));
39 int error, asize = size; 39 int error, asize = size;
40 40
41 if (strcmp(name, "") == 0) 41 if (strcmp(name, "") == 0)
@@ -57,7 +57,7 @@ static int
57xfs_xattr_set(struct dentry *dentry, const char *name, const void *value, 57xfs_xattr_set(struct dentry *dentry, const char *name, const void *value,
58 size_t size, int flags, int xflags) 58 size_t size, int flags, int xflags)
59{ 59{
60 struct xfs_inode *ip = XFS_I(dentry->d_inode); 60 struct xfs_inode *ip = XFS_I(d_inode(dentry));
61 61
62 if (strcmp(name, "") == 0) 62 if (strcmp(name, "") == 0)
63 return -EINVAL; 63 return -EINVAL;
@@ -197,7 +197,7 @@ xfs_vn_listxattr(struct dentry *dentry, char *data, size_t size)
197{ 197{
198 struct xfs_attr_list_context context; 198 struct xfs_attr_list_context context;
199 struct attrlist_cursor_kern cursor = { 0 }; 199 struct attrlist_cursor_kern cursor = { 0 };
200 struct inode *inode = dentry->d_inode; 200 struct inode *inode = d_inode(dentry);
201 int error; 201 int error;
202 202
203 /* 203 /*