xfs: move the di_crtime field to struct xfs_inode
[linux-2.6-microblaze.git] / fs / xfs / xfs_iops.c
index 66ebccb..607b3f2 100644 (file)
@@ -126,6 +126,37 @@ xfs_cleanup_inode(
        xfs_remove(XFS_I(dir), &teardown, XFS_I(inode));
 }
 
+/*
+ * Check to see if we are likely to need an extended attribute to be added to
+ * the inode we are about to allocate. This allows the attribute fork to be
+ * created during the inode allocation, reducing the number of transactions we
+ * need to do in this fast path.
+ *
+ * The security checks are optimistic, but not guaranteed. The two LSMs that
+ * require xattrs to be added here (selinux and smack) are also the only two
+ * LSMs that add a sb->s_security structure to the superblock. Hence if security
+ * is enabled and sb->s_security is set, we have a pretty good idea that we are
+ * going to be asked to add a security xattr immediately after allocating the
+ * xfs inode and instantiating the VFS inode.
+ */
+static inline bool
+xfs_create_need_xattr(
+       struct inode    *dir,
+       struct posix_acl *default_acl,
+       struct posix_acl *acl)
+{
+       if (acl)
+               return true;
+       if (default_acl)
+               return true;
+#if IS_ENABLED(CONFIG_SECURITY)
+       if (dir->i_sb->s_security)
+               return true;
+#endif
+       return false;
+}
+
+
 STATIC int
 xfs_generic_create(
        struct user_namespace   *mnt_userns,
@@ -163,7 +194,8 @@ xfs_generic_create(
 
        if (!tmpfile) {
                error = xfs_create(mnt_userns, XFS_I(dir), &name, mode, rdev,
-                                  &ip);
+                               xfs_create_need_xattr(dir, default_acl, acl),
+                               &ip);
        } else {
                error = xfs_create_tmpfile(mnt_userns, XFS_I(dir), mode, &ip);
        }
@@ -562,13 +594,12 @@ xfs_vn_getattr(
        stat->atime = inode->i_atime;
        stat->mtime = inode->i_mtime;
        stat->ctime = inode->i_ctime;
-       stat->blocks =
-               XFS_FSB_TO_BB(mp, ip->i_d.di_nblocks + ip->i_delayed_blks);
+       stat->blocks = XFS_FSB_TO_BB(mp, ip->i_nblocks + ip->i_delayed_blks);
 
        if (xfs_sb_version_has_v3inode(&mp->m_sb)) {
                if (request_mask & STATX_BTIME) {
                        stat->result_mask |= STATX_BTIME;
-                       stat->btime = ip->i_d.di_crtime;
+                       stat->btime = ip->i_crtime;
                }
        }
 
@@ -576,11 +607,11 @@ xfs_vn_getattr(
         * Note: If you add another clause to set an attribute flag, please
         * update attributes_mask below.
         */
-       if (ip->i_d.di_flags & XFS_DIFLAG_IMMUTABLE)
+       if (ip->i_diflags & XFS_DIFLAG_IMMUTABLE)
                stat->attributes |= STATX_ATTR_IMMUTABLE;
-       if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
+       if (ip->i_diflags & XFS_DIFLAG_APPEND)
                stat->attributes |= STATX_ATTR_APPEND;
-       if (ip->i_d.di_flags & XFS_DIFLAG_NODUMP)
+       if (ip->i_diflags & XFS_DIFLAG_NODUMP)
                stat->attributes |= STATX_ATTR_NODUMP;
 
        stat->attributes_mask |= (STATX_ATTR_IMMUTABLE |
@@ -705,7 +736,7 @@ xfs_setattr_nonsize(
                 */
                ASSERT(udqp == NULL);
                ASSERT(gdqp == NULL);
-               error = xfs_qm_vop_dqalloc(ip, uid, gid, ip->i_d.di_projid,
+               error = xfs_qm_vop_dqalloc(ip, uid, gid, ip->i_projid,
                                           qflags, &udqp, &gdqp, NULL);
                if (error)
                        return error;
@@ -917,8 +948,8 @@ xfs_setattr_size(
         * operation.
         *
         * And we update in-core i_size and truncate page cache beyond newsize
-        * before writeback the [di_size, newsize] range, so we're guaranteed
-        * not to write stale data past the new EOF on truncate down.
+        * before writeback the [i_disk_size, newsize] range, so we're
+        * guaranteed not to write stale data past the new EOF on truncate down.
         */
        truncate_setsize(inode, newsize);
 
@@ -931,9 +962,9 @@ xfs_setattr_size(
         * otherwise those blocks may not be zeroed after a crash.
         */
        if (did_zeroing ||
-           (newsize > ip->i_d.di_size && oldsize != ip->i_d.di_size)) {
+           (newsize > ip->i_disk_size && oldsize != ip->i_disk_size)) {
                error = filemap_write_and_wait_range(VFS_I(ip)->i_mapping,
-                                               ip->i_d.di_size, newsize - 1);
+                                               ip->i_disk_size, newsize - 1);
                if (error)
                        return error;
        }
@@ -975,7 +1006,7 @@ xfs_setattr_size(
         * permanent before actually freeing any blocks it doesn't matter if
         * they get written to.
         */
-       ip->i_d.di_size = newsize;
+       ip->i_disk_size = newsize;
        xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
 
        if (newsize <= oldsize) {
@@ -1255,7 +1286,7 @@ xfs_inode_should_enable_dax(
                return false;
        if (ip->i_mount->m_flags & XFS_MOUNT_DAX_ALWAYS)
                return true;
-       if (ip->i_d.di_flags2 & XFS_DIFLAG2_DAX)
+       if (ip->i_diflags2 & XFS_DIFLAG2_DAX)
                return true;
        return false;
 }
@@ -1312,7 +1343,7 @@ xfs_setup_inode(
        /* make the inode look hashed for the writeback code */
        inode_fake_hash(inode);
 
-       i_size_write(inode, ip->i_d.di_size);
+       i_size_write(inode, ip->i_disk_size);
        xfs_diflags_to_iflags(ip, true);
 
        if (S_ISDIR(inode->i_mode)) {