Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/ufs/lfs - protect global resource counts with lfs_subsys...
details: https://anonhg.NetBSD.org/src/rev/a59f107bddbf
branches: trunk
changeset: 549352:a59f107bddbf
user: yamt <yamt%NetBSD.org@localhost>
date: Sat Jul 12 16:17:06 2003 +0000
description:
- protect global resource counts with lfs_subsys_lock.
- clean up scattered externs a little.
diffstat:
sys/ufs/lfs/lfs.h | 8 ++++--
sys/ufs/lfs/lfs_alloc.c | 9 +++----
sys/ufs/lfs/lfs_bio.c | 51 +++++++++++++++++++++++++++-------------------
sys/ufs/lfs/lfs_extern.h | 8 ++++++-
sys/ufs/lfs/lfs_inode.c | 7 +----
sys/ufs/lfs/lfs_segment.c | 9 +------
sys/ufs/lfs/lfs_subr.c | 7 +----
sys/ufs/lfs/lfs_vfsops.c | 15 +++++--------
sys/ufs/lfs/lfs_vnops.c | 8 +-----
9 files changed, 60 insertions(+), 62 deletions(-)
diffs (truncated from 465 to 300 lines):
diff -r 53ce2a2ea37c -r a59f107bddbf sys/ufs/lfs/lfs.h
--- a/sys/ufs/lfs/lfs.h Sat Jul 12 16:13:38 2003 +0000
+++ b/sys/ufs/lfs/lfs.h Sat Jul 12 16:17:06 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lfs.h,v 1.66 2003/07/02 13:43:02 yamt Exp $ */
+/* $NetBSD: lfs.h,v 1.67 2003/07/12 16:17:06 yamt Exp $ */
/*-
* Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -179,19 +179,23 @@
# define LFS_LOCK_BUF(bp) do { \
if (((bp)->b_flags & (B_LOCKED | B_CALL)) == 0) { \
+ simple_lock(&lfs_subsys_lock); \
++locked_queue_count; \
locked_queue_bytes += bp->b_bufsize; \
+ simple_unlock(&lfs_subsys_lock); \
} \
(bp)->b_flags |= B_LOCKED; \
} while (0)
# define LFS_UNLOCK_BUF(bp) do { \
if (((bp)->b_flags & (B_LOCKED | B_CALL)) == B_LOCKED) { \
+ simple_lock(&lfs_subsys_lock); \
--locked_queue_count; \
locked_queue_bytes -= bp->b_bufsize; \
if (locked_queue_count < LFS_WAIT_BUFS && \
locked_queue_bytes < LFS_WAIT_BYTES) \
wakeup(&locked_queue_count); \
+ simple_unlock(&lfs_subsys_lock); \
} \
(bp)->b_flags &= ~B_LOCKED; \
} while (0)
@@ -203,8 +207,6 @@
# ifdef DEBUG_LOCKED_LIST
# define LFS_DEBUG_COUNTLOCKED(m) do { \
int _s; \
- extern int locked_queue_count; \
- extern long locked_queue_bytes; \
_s = splbio(); \
lfs_countlocked(&locked_queue_count, &locked_queue_bytes, (m)); \
splx(_s); \
diff -r 53ce2a2ea37c -r a59f107bddbf sys/ufs/lfs/lfs_alloc.c
--- a/sys/ufs/lfs/lfs_alloc.c Sat Jul 12 16:13:38 2003 +0000
+++ b/sys/ufs/lfs/lfs_alloc.c Sat Jul 12 16:17:06 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lfs_alloc.c,v 1.69 2003/06/29 22:32:38 fvdl Exp $ */
+/* $NetBSD: lfs_alloc.c,v 1.70 2003/07/12 16:17:06 yamt Exp $ */
/*-
* Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -71,7 +71,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lfs_alloc.c,v 1.69 2003/06/29 22:32:38 fvdl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_alloc.c,v 1.70 2003/07/12 16:17:06 yamt Exp $");
#if defined(_KERNEL_OPT)
#include "opt_quota.h"
@@ -96,11 +96,11 @@
#include <ufs/lfs/lfs.h>
#include <ufs/lfs/lfs_extern.h>
-extern int lfs_dirvcount;
extern struct lock ufs_hashlock;
static int extend_ifile(struct lfs *, struct ucred *);
-static int lfs_ialloc(struct lfs *, struct vnode *, ino_t, int, struct vnode **);
+static int lfs_ialloc(struct lfs *, struct vnode *, ino_t, int,
+ struct vnode **);
/*
* Allocate a particular inode with a particular version number, freeing
@@ -488,7 +488,6 @@
struct lfs *fs;
daddr_t old_iaddr;
ino_t ino, otail;
- extern int lfs_dirvcount;
int s;
/* Get the inode number and file system. */
diff -r 53ce2a2ea37c -r a59f107bddbf sys/ufs/lfs/lfs_bio.c
--- a/sys/ufs/lfs/lfs_bio.c Sat Jul 12 16:13:38 2003 +0000
+++ b/sys/ufs/lfs/lfs_bio.c Sat Jul 12 16:17:06 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lfs_bio.c,v 1.70 2003/07/02 14:07:16 yamt Exp $ */
+/* $NetBSD: lfs_bio.c,v 1.71 2003/07/12 16:17:07 yamt Exp $ */
/*-
* Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -71,7 +71,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lfs_bio.c,v 1.70 2003/07/02 14:07:16 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_bio.c,v 1.71 2003/07/12 16:17:07 yamt Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -102,13 +102,15 @@
* XXX
* No write cost accounting is done.
* This is almost certainly wrong for synchronous operations and NFS.
+ *
+ * protected by lfs_subsys_lock.
*/
int locked_queue_count = 0; /* Count of locked-down buffers. */
long locked_queue_bytes = 0L; /* Total size of locked buffers. */
int lfs_subsys_pages = 0L; /* Total number LFS-written pages */
int lfs_writing = 0; /* Set if already kicked off a writer
because of buffer space */
-/* Lock for lfs_subsys_pages */
+/* Lock for aboves */
struct simplelock lfs_subsys_lock = SIMPLELOCK_INITIALIZER;
extern int lfs_dostats;
@@ -128,9 +130,13 @@
int
lfs_fits_buf(struct lfs *fs, int n, int bytes)
{
- int count_fit =
+ int count_fit, bytes_fit;
+
+ LOCK_ASSERT(simple_lock_held(&lfs_subsys_lock));
+
+ count_fit =
(locked_queue_count + locked_queue_rcount + n < LFS_WAIT_BUFS);
- int bytes_fit =
+ bytes_fit =
(locked_queue_bytes + locked_queue_rbytes + bytes < LFS_WAIT_BYTES);
#ifdef DEBUG_LFS
@@ -157,20 +163,25 @@
KASSERT(locked_queue_rcount >= 0);
KASSERT(locked_queue_rbytes >= 0);
+ simple_lock(&lfs_subsys_lock);
while (n > 0 && !lfs_fits_buf(fs, n, bytes)) {
int error;
lfs_flush(fs, 0);
- error = tsleep(&locked_queue_count, PCATCH | PUSER,
- "lfsresbuf", hz * LFS_BUFWAIT);
- if (error && error != EWOULDBLOCK)
+ error = ltsleep(&locked_queue_count, PCATCH | PUSER,
+ "lfsresbuf", hz * LFS_BUFWAIT, &lfs_subsys_lock);
+ if (error && error != EWOULDBLOCK) {
+ simple_unlock(&lfs_subsys_lock);
return error;
+ }
}
locked_queue_rcount += n;
locked_queue_rbytes += bytes;
+ simple_unlock(&lfs_subsys_lock);
+
KASSERT(locked_queue_rcount >= 0);
KASSERT(locked_queue_rbytes >= 0);
@@ -495,12 +506,15 @@
* when pages need to be reclaimed. Note, we have one static count of locked
* buffers, so we can't have more than a single file system. To make this
* work for multiple file systems, put the count into the mount structure.
+ *
+ * called and return with lfs_subsys_lock held.
*/
void
lfs_flush(struct lfs *fs, int flags)
{
struct mount *mp, *nmp;
+ LOCK_ASSERT(simple_lock_held(&lfs_subsys_lock));
KDASSERT(fs == NULL || !LFS_SEGLOCK_HELD(fs));
if (lfs_dostats)
@@ -511,12 +525,11 @@
#endif
return;
}
- /* XXX MP */
while (lfs_writing && (flags & SEGM_WRITERD))
- ltsleep(&lfs_writing, PRIBIO + 1, "lfsflush", 0, 0);
+ ltsleep(&lfs_writing, PRIBIO + 1, "lfsflush", 0,
+ &lfs_subsys_lock);
lfs_writing = 1;
- simple_lock(&lfs_subsys_lock);
lfs_subsys_pages = 0; /* XXXUBC need a better way to count this */
simple_unlock(&lfs_subsys_lock);
wakeup(&lfs_subsys_pages);
@@ -538,6 +551,8 @@
simple_unlock(&mountlist_slock);
LFS_DEBUG_COUNTLOCKED("flush");
+ simple_lock(&lfs_subsys_lock);
+ KASSERT(lfs_writing);
lfs_writing = 0;
wakeup(&lfs_writing);
}
@@ -555,7 +570,6 @@
int error;
struct lfs *fs;
struct inode *ip;
- extern int lfs_dirvcount;
error = 0;
ip = VTOI(vp);
@@ -605,18 +619,14 @@
if (locked_queue_count + INOCOUNT(fs) > LFS_MAX_BUFS ||
locked_queue_bytes + INOBYTES(fs) > LFS_MAX_BYTES ||
lfs_subsys_pages > LFS_MAX_PAGES ||
- lfs_dirvcount > LFS_MAX_DIROP || fs->lfs_diropwait > 0)
- {
- simple_unlock(&lfs_subsys_lock);
+ lfs_dirvcount > LFS_MAX_DIROP || fs->lfs_diropwait > 0) {
lfs_flush(fs, flags);
- simple_lock(&lfs_subsys_lock);
}
while (locked_queue_count + INOCOUNT(fs) > LFS_WAIT_BUFS ||
locked_queue_bytes + INOBYTES(fs) > LFS_WAIT_BYTES ||
lfs_subsys_pages > LFS_WAIT_PAGES ||
- lfs_dirvcount > LFS_MAX_DIROP)
- {
+ lfs_dirvcount > LFS_MAX_DIROP) {
simple_unlock(&lfs_subsys_lock);
if (lfs_dostats)
++lfs_stats.wait_exceeded;
@@ -636,12 +646,11 @@
* and we weren't asked to checkpoint. Try flushing again
* to keep us from blocking indefinitely.
*/
+ simple_lock(&lfs_subsys_lock);
if (locked_queue_count + INOCOUNT(fs) > LFS_MAX_BUFS ||
- locked_queue_bytes + INOBYTES(fs) > LFS_MAX_BYTES)
- {
+ locked_queue_bytes + INOBYTES(fs) > LFS_MAX_BYTES) {
lfs_flush(fs, flags | SEGM_CKP);
}
- simple_lock(&lfs_subsys_lock);
}
simple_unlock(&lfs_subsys_lock);
return (error);
diff -r 53ce2a2ea37c -r a59f107bddbf sys/ufs/lfs/lfs_extern.h
--- a/sys/ufs/lfs/lfs_extern.h Sat Jul 12 16:13:38 2003 +0000
+++ b/sys/ufs/lfs/lfs_extern.h Sat Jul 12 16:17:06 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lfs_extern.h,v 1.51 2003/07/02 13:40:52 yamt Exp $ */
+/* $NetBSD: lfs_extern.h,v 1.52 2003/07/12 16:17:07 yamt Exp $ */
/*-
* Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -122,6 +122,12 @@
extern struct pool lfs_dinode_pool; /* memory pool for dinodes */
extern struct pool lfs_inoext_pool; /* memory pool for inode extension */
+extern int locked_queue_count;
+extern long locked_queue_bytes;
+extern int lfs_subsys_pages;
+extern int lfs_dirvcount;
+extern struct simplelock lfs_subsys_lock;
+
__BEGIN_DECLS
/* lfs_alloc.c */
int lfs_rf_valloc(struct lfs *, ino_t, int, struct proc *, struct vnode **);
diff -r 53ce2a2ea37c -r a59f107bddbf sys/ufs/lfs/lfs_inode.c
--- a/sys/ufs/lfs/lfs_inode.c Sat Jul 12 16:13:38 2003 +0000
+++ b/sys/ufs/lfs/lfs_inode.c Sat Jul 12 16:17:06 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lfs_inode.c,v 1.77 2003/06/29 22:32:39 fvdl Exp $ */
+/* $NetBSD: lfs_inode.c,v 1.78 2003/07/12 16:17:07 yamt Exp $ */
/*-
* Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -71,7 +71,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lfs_inode.c,v 1.77 2003/06/29 22:32:39 fvdl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_inode.c,v 1.78 2003/07/12 16:17:07 yamt Exp $");
#if defined(_KERNEL_OPT)
#include "opt_quota.h"
@@ -97,9 +97,6 @@
#include <ufs/lfs/lfs.h>
#include <ufs/lfs/lfs_extern.h>
-extern int locked_queue_count;
-extern long locked_queue_bytes;
-
static int lfs_update_seguse(struct lfs *, long, size_t);
static int lfs_indirtrunc (struct inode *, daddr_t, daddr_t,
daddr_t, int, long *, long *, long *, size_t *,
diff -r 53ce2a2ea37c -r a59f107bddbf sys/ufs/lfs/lfs_segment.c
--- a/sys/ufs/lfs/lfs_segment.c Sat Jul 12 16:13:38 2003 +0000
+++ b/sys/ufs/lfs/lfs_segment.c Sat Jul 12 16:17:06 2003 +0000
@@ -1,4 +1,4 @@
Home |
Main Index |
Thread Index |
Old Index