Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/ufs/lfs In lfs_update, hold lfs_writer around lfs_vflush.



details:   https://anonhg.NetBSD.org/src/rev/552389a3ca8f
branches:  trunk
changeset: 969559:552389a3ca8f
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Sun Feb 23 08:40:58 2020 +0000

description:
In lfs_update, hold lfs_writer around lfs_vflush.

Otherwise, we might do

lfs_vflush
-> lfs_seglock
-> lfs_segwait(SEGM_CKP)
   -> lfs_writer_enter

which is the reverse of the lfs_writer -> lfs_seglock ordering.

diffstat:

 sys/ufs/lfs/lfs_inode.c |  19 +++++++++++++++----
 1 files changed, 15 insertions(+), 4 deletions(-)

diffs (55 lines):

diff -r ded1277fcfbe -r 552389a3ca8f sys/ufs/lfs/lfs_inode.c
--- a/sys/ufs/lfs/lfs_inode.c   Sun Feb 23 08:40:49 2020 +0000
+++ b/sys/ufs/lfs/lfs_inode.c   Sun Feb 23 08:40:58 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lfs_inode.c,v 1.157 2017/06/10 05:29:36 maya Exp $     */
+/*     $NetBSD: lfs_inode.c,v 1.158 2020/02/23 08:40:58 riastradh Exp $        */
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lfs_inode.c,v 1.157 2017/06/10 05:29:36 maya Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_inode.c,v 1.158 2020/02/23 08:40:58 riastradh Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_quota.h"
@@ -133,6 +133,7 @@
        struct inode *ip;
        struct lfs *fs = VFSTOULFS(vp->v_mount)->um_lfs;
        int flags;
+       int error;
 
        ASSERT_NO_SEGLOCK(fs);
        if (vp->v_mount->mnt_flag & MNT_RDONLY)
@@ -175,7 +176,7 @@
                              vp->v_iflag | vp->v_vflag | vp->v_uflag,
                              ip->i_state));
                        if (fs->lfs_dirops == 0)
-                               lfs_flush_fs(fs, SEGM_SYNC);
+                               break;
                        else
                                mtsleep(&fs->lfs_writer, PRIBIO+1, "lfs_fsync",
                                        0, &lfs_lock);
@@ -183,8 +184,18 @@
                        twice? */
                }
                --fs->lfs_diropwait;
+               fs->lfs_writer++;
+               if (vp->v_uflag & VU_DIROP) {
+                       KASSERT(fs->lfs_dirops == 0);
+                       lfs_flush_fs(fs, SEGM_SYNC);
+               }
                mutex_exit(&lfs_lock);
-               return lfs_vflush(vp);
+               error = lfs_vflush(vp);
+               mutex_enter(&lfs_lock);
+               if (--fs->lfs_writer == 0)
+                       cv_broadcast(&fs->lfs_diropscv);
+               mutex_exit(&lfs_lock);
+               return error;
        }
        return 0;
 }



Home | Main Index | Thread Index | Old Index