Merge tag 'stable/for-linus-3.16-rc1-tag' of git://git.kernel.org/pub/scm/linux/kerne...
[firefly-linux-kernel-4.4.55.git] / fs / xfs / xfs_inode.c
index 768087bedbac58f9dea71b8f534c303e65972b42..a6115fe1ac948a4b57efb6bf00830bb9a4845ed6 100644 (file)
@@ -655,7 +655,6 @@ xfs_ialloc(
        uint            flags;
        int             error;
        timespec_t      tv;
-       int             filestreams = 0;
 
        /*
         * Call the space management code to pick
@@ -682,6 +681,14 @@ xfs_ialloc(
                return error;
        ASSERT(ip != NULL);
 
+       /*
+        * We always convert v1 inodes to v2 now - we only support filesystems
+        * with >= v2 inode capability, so there is no reason for ever leaving
+        * an inode in v1 format.
+        */
+       if (ip->i_d.di_version == 1)
+               ip->i_d.di_version = 2;
+
        ip->i_d.di_mode = mode;
        ip->i_d.di_onlink = 0;
        ip->i_d.di_nlink = nlink;
@@ -691,27 +698,6 @@ xfs_ialloc(
        xfs_set_projid(ip, prid);
        memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad));
 
-       /*
-        * If the superblock version is up to where we support new format
-        * inodes and this is currently an old format inode, then change
-        * the inode version number now.  This way we only do the conversion
-        * here rather than here and in the flush/logging code.
-        */
-       if (xfs_sb_version_hasnlink(&mp->m_sb) &&
-           ip->i_d.di_version == 1) {
-               ip->i_d.di_version = 2;
-               /*
-                * We've already zeroed the old link count, the projid field,
-                * and the pad field.
-                */
-       }
-
-       /*
-        * Project ids won't be stored on disk if we are using a version 1 inode.
-        */
-       if ((prid != 0) && (ip->i_d.di_version == 1))
-               xfs_bump_ino_vers2(tp, ip);
-
        if (pip && XFS_INHERIT_GID(pip)) {
                ip->i_d.di_gid = pip->i_d.di_gid;
                if ((pip->i_d.di_mode & S_ISGID) && S_ISDIR(mode)) {
@@ -772,13 +758,6 @@ xfs_ialloc(
                flags |= XFS_ILOG_DEV;
                break;
        case S_IFREG:
-               /*
-                * we can't set up filestreams until after the VFS inode
-                * is set up properly.
-                */
-               if (pip && xfs_inode_is_filestream(pip))
-                       filestreams = 1;
-               /* fall through */
        case S_IFDIR:
                if (pip && (pip->i_d.di_flags & XFS_DIFLAG_ANY)) {
                        uint    di_flags = 0;
@@ -844,15 +823,6 @@ xfs_ialloc(
        /* now that we have an i_mode we can setup inode ops and unlock */
        xfs_setup_inode(ip);
 
-       /* now we have set up the vfs inode we can associate the filestream */
-       if (filestreams) {
-               error = xfs_filestream_associate(pip, ip);
-               if (error < 0)
-                       return -error;
-               if (!error)
-                       xfs_iflags_set(ip, XFS_IFILESTREAM);
-       }
-
        *ipp = ip;
        return 0;
 }
@@ -1072,40 +1042,6 @@ xfs_droplink(
        return error;
 }
 
-/*
- * This gets called when the inode's version needs to be changed from 1 to 2.
- * Currently this happens when the nlink field overflows the old 16-bit value
- * or when chproj is called to change the project for the first time.
- * As a side effect the superblock version will also get rev'd
- * to contain the NLINK bit.
- */
-void
-xfs_bump_ino_vers2(
-       xfs_trans_t     *tp,
-       xfs_inode_t     *ip)
-{
-       xfs_mount_t     *mp;
-
-       ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
-       ASSERT(ip->i_d.di_version == 1);
-
-       ip->i_d.di_version = 2;
-       ip->i_d.di_onlink = 0;
-       memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad));
-       mp = tp->t_mountp;
-       if (!xfs_sb_version_hasnlink(&mp->m_sb)) {
-               spin_lock(&mp->m_sb_lock);
-               if (!xfs_sb_version_hasnlink(&mp->m_sb)) {
-                       xfs_sb_version_addnlink(&mp->m_sb);
-                       spin_unlock(&mp->m_sb_lock);
-                       xfs_mod_sb(tp, XFS_SB_VERSIONNUM);
-               } else {
-                       spin_unlock(&mp->m_sb_lock);
-               }
-       }
-       /* Caller must log the inode */
-}
-
 /*
  * Increment the link count on an inode & log the change.
  */
@@ -1116,22 +1052,10 @@ xfs_bumplink(
 {
        xfs_trans_ichgtime(tp, ip, XFS_ICHGTIME_CHG);
 
+       ASSERT(ip->i_d.di_version > 1);
        ASSERT(ip->i_d.di_nlink > 0 || (VFS_I(ip)->i_state & I_LINKABLE));
        ip->i_d.di_nlink++;
        inc_nlink(VFS_I(ip));
-       if ((ip->i_d.di_version == 1) &&
-           (ip->i_d.di_nlink > XFS_MAXLINK_1)) {
-               /*
-                * The inode has increased its number of links beyond
-                * what can fit in an old format inode.  It now needs
-                * to be converted to a version 2 inode with a 32 bit
-                * link count.  If this is the first inode in the file
-                * system to do this, then we need to bump the superblock
-                * version number as well.
-                */
-               xfs_bump_ino_vers2(tp, ip);
-       }
-
        xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
        return 0;
 }
@@ -1698,16 +1622,6 @@ xfs_release(
        if (!XFS_FORCED_SHUTDOWN(mp)) {
                int truncated;
 
-               /*
-                * If we are using filestreams, and we have an unlinked
-                * file that we are processing the last close on, then nothing
-                * will be able to reopen and write to this file. Purge this
-                * inode from the filestreams cache so that it doesn't delay
-                * teardown of the inode.
-                */
-               if ((ip->i_d.di_nlink == 0) && xfs_inode_is_filestream(ip))
-                       xfs_filestream_deassociate(ip);
-
                /*
                 * If we previously truncated this file and removed old data
                 * in the process, we want to initiate "early" writeout on
@@ -1838,9 +1752,33 @@ xfs_inactive_ifree(
        int                     error;
 
        tp = xfs_trans_alloc(mp, XFS_TRANS_INACTIVE);
-       error = xfs_trans_reserve(tp, &M_RES(mp)->tr_ifree, 0, 0);
+
+       /*
+        * The ifree transaction might need to allocate blocks for record
+        * insertion to the finobt. We don't want to fail here at ENOSPC, so
+        * allow ifree to dip into the reserved block pool if necessary.
+        *
+        * Freeing large sets of inodes generally means freeing inode chunks,
+        * directory and file data blocks, so this should be relatively safe.
+        * Only under severe circumstances should it be possible to free enough
+        * inodes to exhaust the reserve block pool via finobt expansion while
+        * at the same time not creating free space in the filesystem.
+        *
+        * Send a warning if the reservation does happen to fail, as the inode
+        * now remains allocated and sits on the unlinked list until the fs is
+        * repaired.
+        */
+       tp->t_flags |= XFS_TRANS_RESERVE;
+       error = xfs_trans_reserve(tp, &M_RES(mp)->tr_ifree,
+                                 XFS_IFREE_SPACE_RES(mp), 0);
        if (error) {
-               ASSERT(XFS_FORCED_SHUTDOWN(mp));
+               if (error == ENOSPC) {
+                       xfs_warn_ratelimited(mp,
+                       "Failed to remove inode(s) from unlinked list. "
+                       "Please free space, unmount and run xfs_repair.");
+               } else {
+                       ASSERT(XFS_FORCED_SHUTDOWN(mp));
+               }
                xfs_trans_cancel(tp, XFS_TRANS_RELEASE_LOG_RES);
                return error;
        }
@@ -2664,13 +2602,7 @@ xfs_remove(
        if (error)
                goto std_return;
 
-       /*
-        * If we are using filestreams, kill the stream association.
-        * If the file is still open it may get a new one but that
-        * will get killed on last close in xfs_close() so we don't
-        * have to worry about that.
-        */
-       if (!is_dir && link_zero && xfs_inode_is_filestream(ip))
+       if (is_dir && xfs_inode_is_filestream(ip))
                xfs_filestream_deassociate(ip);
 
        return 0;
@@ -3258,6 +3190,7 @@ xfs_iflush_int(
        ASSERT(ip->i_d.di_format != XFS_DINODE_FMT_BTREE ||
               ip->i_d.di_nextents > XFS_IFORK_MAXEXT(ip, XFS_DATA_FORK));
        ASSERT(iip != NULL && iip->ili_fields != 0);
+       ASSERT(ip->i_d.di_version > 1);
 
        /* set *dip = inode's place in the buffer */
        dip = (xfs_dinode_t *)xfs_buf_offset(bp, ip->i_imap.im_boffset);
@@ -3318,7 +3251,7 @@ xfs_iflush_int(
        }
 
        /*
-        * Inode item log recovery for v1/v2 inodes are dependent on the
+        * Inode item log recovery for v2 inodes are dependent on the
         * di_flushiter count for correct sequencing. We bump the flush
         * iteration count so we can detect flushes which postdate a log record
         * during recovery. This is redundant as we now log every change and
@@ -3341,40 +3274,9 @@ xfs_iflush_int(
        if (ip->i_d.di_flushiter == DI_MAX_FLUSH)
                ip->i_d.di_flushiter = 0;
 
-       /*
-        * If this is really an old format inode and the superblock version
-        * has not been updated to support only new format inodes, then
-        * convert back to the old inode format.  If the superblock version
-        * has been updated, then make the conversion permanent.
-        */
-       ASSERT(ip->i_d.di_version == 1 || xfs_sb_version_hasnlink(&mp->m_sb));
-       if (ip->i_d.di_version == 1) {
-               if (!xfs_sb_version_hasnlink(&mp->m_sb)) {
-                       /*
-                        * Convert it back.
-                        */
-                       ASSERT(ip->i_d.di_nlink <= XFS_MAXLINK_1);
-                       dip->di_onlink = cpu_to_be16(ip->i_d.di_nlink);
-               } else {
-                       /*
-                        * The superblock version has already been bumped,
-                        * so just make the conversion to the new inode
-                        * format permanent.
-                        */
-                       ip->i_d.di_version = 2;
-                       dip->di_version = 2;
-                       ip->i_d.di_onlink = 0;
-                       dip->di_onlink = 0;
-                       memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad));
-                       memset(&(dip->di_pad[0]), 0,
-                             sizeof(dip->di_pad));
-                       ASSERT(xfs_get_projid(ip) == 0);
-               }
-       }
-
-       xfs_iflush_fork(ip, dip, iip, XFS_DATA_FORK, bp);
+       xfs_iflush_fork(ip, dip, iip, XFS_DATA_FORK);
        if (XFS_IFORK_Q(ip))
-               xfs_iflush_fork(ip, dip, iip, XFS_ATTR_FORK, bp);
+               xfs_iflush_fork(ip, dip, iip, XFS_ATTR_FORK);
        xfs_inobp_check(mp, bp);
 
        /*