ufs: switch ufs_evict_inode() to trimmed-down variant of ufs_truncate()
authorAl Viro <viro@zeniv.linux.org.uk>
Tue, 16 Jun 2015 22:04:16 +0000 (18:04 -0400)
committerAl Viro <viro@zeniv.linux.org.uk>
Mon, 6 Jul 2015 21:39:20 +0000 (17:39 -0400)
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
fs/ufs/inode.c
fs/ufs/truncate.c
fs/ufs/ufs.h

index 0e4d88e..282b0ce 100644 (file)
@@ -884,14 +884,9 @@ void ufs_evict_inode(struct inode * inode)
 
        truncate_inode_pages_final(&inode->i_data);
        if (want_delete) {
-               loff_t old_i_size;
-               /*UFS_I(inode)->i_dtime = CURRENT_TIME;*/
-               mark_inode_dirty(inode);
-               ufs_update_inode(inode, IS_SYNC(inode));
-               old_i_size = inode->i_size;
                inode->i_size = 0;
-               if (inode->i_blocks && ufs_truncate(inode, old_i_size))
-                       ufs_warning(inode->i_sb, __func__, "ufs_truncate failed\n");
+               if (inode->i_blocks)
+                       ufs_truncate_blocks(inode);
        }
 
        invalidate_inode_buffers(inode);
index 90cf3a7..5a2e708 100644 (file)
@@ -440,12 +440,36 @@ out:
        return err;
 }
 
-int ufs_truncate(struct inode *inode, loff_t old_i_size)
+static void __ufs_truncate_blocks(struct inode *inode)
 {
        struct ufs_inode_info *ufsi = UFS_I(inode);
        struct super_block *sb = inode->i_sb;
        struct ufs_sb_private_info *uspi = UFS_SB(sb)->s_uspi;
-       int retry, err = 0;
+       int retry;
+
+       while (1) {
+               retry = ufs_trunc_direct(inode);
+               retry |= ufs_trunc_indirect(inode, UFS_IND_BLOCK,
+                                           ufs_get_direct_data_ptr(uspi, ufsi,
+                                                                   UFS_IND_BLOCK));
+               retry |= ufs_trunc_dindirect(inode, UFS_IND_BLOCK + uspi->s_apb,
+                                            ufs_get_direct_data_ptr(uspi, ufsi,
+                                                                    UFS_DIND_BLOCK));
+               retry |= ufs_trunc_tindirect (inode);
+               if (!retry)
+                       break;
+               if (IS_SYNC(inode) && (inode->i_state & I_DIRTY))
+                       ufs_sync_inode (inode);
+               yield();
+       }
+
+       ufsi->i_lastfrag = DIRECT_FRAGMENT;
+}
+
+int ufs_truncate(struct inode *inode, loff_t old_i_size)
+{
+       struct super_block *sb = inode->i_sb;
+       int err = 0;
        
        UFSD("ENTER: ino %lu, i_size: %llu, old_i_size: %llu\n",
             inode->i_ino, (unsigned long long)i_size_read(inode),
@@ -467,24 +491,8 @@ int ufs_truncate(struct inode *inode, loff_t old_i_size)
 
        block_truncate_page(inode->i_mapping, inode->i_size, ufs_getfrag_block);
 
-       while (1) {
-               retry = ufs_trunc_direct(inode);
-               retry |= ufs_trunc_indirect(inode, UFS_IND_BLOCK,
-                                           ufs_get_direct_data_ptr(uspi, ufsi,
-                                                                   UFS_IND_BLOCK));
-               retry |= ufs_trunc_dindirect(inode, UFS_IND_BLOCK + uspi->s_apb,
-                                            ufs_get_direct_data_ptr(uspi, ufsi,
-                                                                    UFS_DIND_BLOCK));
-               retry |= ufs_trunc_tindirect (inode);
-               if (!retry)
-                       break;
-               if (IS_SYNC(inode) && (inode->i_state & I_DIRTY))
-                       ufs_sync_inode (inode);
-               yield();
-       }
-
+       __ufs_truncate_blocks(inode);
        inode->i_mtime = inode->i_ctime = CURRENT_TIME_SEC;
-       ufsi->i_lastfrag = DIRECT_FRAGMENT;
        mark_inode_dirty(inode);
 out:
        unlock_ufs(sb);
@@ -492,6 +500,20 @@ out:
        return err;
 }
 
+void ufs_truncate_blocks(struct inode *inode)
+{
+       struct super_block *sb = inode->i_sb;
+       if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
+             S_ISLNK(inode->i_mode)))
+               return;
+       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
+               return;
+
+       lock_ufs(sb);
+       __ufs_truncate_blocks(inode);
+       unlock_ufs(sb);
+}
+
 int ufs_setattr(struct dentry *dentry, struct iattr *attr)
 {
        struct inode *inode = d_inode(dentry);
index 2e31ea2..43fcab3 100644 (file)
@@ -141,7 +141,7 @@ extern const struct inode_operations ufs_fast_symlink_inode_operations;
 extern const struct inode_operations ufs_symlink_inode_operations;
 
 /* truncate.c */
-extern int ufs_truncate (struct inode *, loff_t);
+extern void ufs_truncate_blocks(struct inode *);
 extern int ufs_setattr(struct dentry *dentry, struct iattr *attr);
 
 static inline struct ufs_sb_info *UFS_SB(struct super_block *sb)