]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
NFS: Clean up pnfs_put_layout_hdr()/pnfs_destroy_layout_final()
authorTrond Myklebust <trond.myklebust@hammerspace.com>
Fri, 18 Jul 2025 23:44:03 +0000 (16:44 -0700)
committerTrond Myklebust <trond.myklebust@hammerspace.com>
Tue, 22 Jul 2025 12:10:41 +0000 (08:10 -0400)
Use the wake_up_var_locked() and wait_var_event_spinlock() helpers.

Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
fs/nfs/pnfs.c

index 3fd0971bf16fcfdaba390674666d3fca4a07f328..a3135b5af7eeca201e5a6e6e3c7f692ad9e0b250 100644 (file)
@@ -306,7 +306,6 @@ void
 pnfs_put_layout_hdr(struct pnfs_layout_hdr *lo)
 {
        struct inode *inode;
-       unsigned long i_state;
 
        if (!lo)
                return;
@@ -317,12 +316,11 @@ pnfs_put_layout_hdr(struct pnfs_layout_hdr *lo)
                if (!list_empty(&lo->plh_segs))
                        WARN_ONCE(1, "NFS: BUG unfreed layout segments.\n");
                pnfs_detach_layout_hdr(lo);
-               i_state = inode->i_state;
+               /* Notify pnfs_destroy_layout_final() that we're done */
+               if (inode->i_state & (I_FREEING | I_CLEAR))
+                       wake_up_var_locked(lo, &inode->i_lock);
                spin_unlock(&inode->i_lock);
                pnfs_free_layout_hdr(lo);
-               /* Notify pnfs_destroy_layout_final() that we're done */
-               if (i_state & (I_FREEING | I_CLEAR))
-                       wake_up_var(lo);
        }
 }
 
@@ -809,23 +807,17 @@ void pnfs_destroy_layout(struct nfs_inode *nfsi)
 }
 EXPORT_SYMBOL_GPL(pnfs_destroy_layout);
 
-static bool pnfs_layout_removed(struct nfs_inode *nfsi,
-                               struct pnfs_layout_hdr *lo)
-{
-       bool ret;
-
-       spin_lock(&nfsi->vfs_inode.i_lock);
-       ret = nfsi->layout != lo;
-       spin_unlock(&nfsi->vfs_inode.i_lock);
-       return ret;
-}
-
 void pnfs_destroy_layout_final(struct nfs_inode *nfsi)
 {
        struct pnfs_layout_hdr *lo = __pnfs_destroy_layout(nfsi);
+       struct inode *inode = &nfsi->vfs_inode;
 
-       if (lo)
-               wait_var_event(lo, pnfs_layout_removed(nfsi, lo));
+       if (lo) {
+               spin_lock(&inode->i_lock);
+               wait_var_event_spinlock(lo, nfsi->layout != lo,
+                                       &inode->i_lock);
+               spin_unlock(&inode->i_lock);
+       }
 }
 
 static bool