Merge tag 'xfs-4.18-merge-10' of git://git.kernel.org/pub/scm/fs/xfs/xfs-linux
[platform/kernel/linux-starfive.git] / fs / xfs / xfs_iops.c
index 3020c57..1fce707 100644 (file)
@@ -25,7 +25,6 @@
 #include "xfs_da_btree.h"
 #include "xfs_dir2.h"
 #include "xfs_trans_space.h"
-#include "xfs_pnfs.h"
 #include "xfs_iomap.h"
 
 #include <linux/capability.h>
@@ -248,6 +247,7 @@ xfs_vn_lookup(
        struct dentry   *dentry,
        unsigned int flags)
 {
+       struct inode *inode;
        struct xfs_inode *cip;
        struct xfs_name name;
        int             error;
@@ -257,14 +257,13 @@ xfs_vn_lookup(
 
        xfs_dentry_to_name(&name, dentry);
        error = xfs_lookup(XFS_I(dir), &name, &cip, NULL);
-       if (unlikely(error)) {
-               if (unlikely(error != -ENOENT))
-                       return ERR_PTR(error);
-               d_add(dentry, NULL);
-               return NULL;
-       }
-
-       return d_splice_alias(VFS_I(cip), dentry);
+       if (likely(!error))
+               inode = VFS_I(cip);
+       else if (likely(error == -ENOENT))
+               inode = NULL;
+       else
+               inode = ERR_PTR(error);
+       return d_splice_alias(inode, dentry);
 }
 
 STATIC struct dentry *
@@ -1018,14 +1017,19 @@ xfs_vn_setattr(
        int                     error;
 
        if (iattr->ia_valid & ATTR_SIZE) {
-               struct xfs_inode        *ip = XFS_I(d_inode(dentry));
-               uint                    iolock = XFS_IOLOCK_EXCL;
+               struct inode            *inode = d_inode(dentry);
+               struct xfs_inode        *ip = XFS_I(inode);
+               uint                    iolock;
 
-               error = xfs_break_layouts(d_inode(dentry), &iolock);
-               if (error)
+               xfs_ilock(ip, XFS_MMAPLOCK_EXCL);
+               iolock = XFS_IOLOCK_EXCL | XFS_MMAPLOCK_EXCL;
+
+               error = xfs_break_layouts(inode, &iolock, BREAK_UNMAP);
+               if (error) {
+                       xfs_iunlock(ip, XFS_MMAPLOCK_EXCL);
                        return error;
+               }
 
-               xfs_ilock(ip, XFS_MMAPLOCK_EXCL);
                error = xfs_vn_setattr_size(dentry, iattr);
                xfs_iunlock(ip, XFS_MMAPLOCK_EXCL);
        } else {