summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgrange <grange@openbsd.org>2004-01-14 19:34:05 +0000
committergrange <grange@openbsd.org>2004-01-14 19:34:05 +0000
commit10131fbe9c29fb02f7d5a5d1cd9900b1ade5cada (patch)
treea28bae774246949dcb76a0756c2830fb8d8b3024
parentFix printf format string. ok deraadt@ (diff)
downloadwireguard-openbsd-10131fbe9c29fb02f7d5a5d1cd9900b1ade5cada.tar.xz
wireguard-openbsd-10131fbe9c29fb02f7d5a5d1cd9900b1ade5cada.zip
Get rid of M_LOCKF and use pool for allocating lockf structures.
From NetBSD. Tested by many people, ok art@.
-rw-r--r--share/man/man9/malloc.94
-rw-r--r--sys/kern/init_main.c6
-rw-r--r--sys/kern/vfs_lockf.c41
-rw-r--r--sys/sys/lockf.h3
-rw-r--r--sys/sys/malloc.h6
5 files changed, 36 insertions, 24 deletions
diff --git a/share/man/man9/malloc.9 b/share/man/man9/malloc.9
index b0e11695be4..3f66e63569b 100644
--- a/share/man/man9/malloc.9
+++ b/share/man/man9/malloc.9
@@ -1,4 +1,4 @@
-.\" $OpenBSD: malloc.9,v 1.29 2003/07/11 13:47:41 jmc Exp $
+.\" $OpenBSD: malloc.9,v 1.30 2004/01/14 19:34:05 grange Exp $
.\" $NetBSD: malloc.9,v 1.2 1996/10/30 05:29:54 lukem Exp $
.\"
.\" Copyright (c) 1996 The NetBSD Foundation, Inc.
@@ -172,8 +172,6 @@ VM pmap data.
Open file structures.
.It Dv M_FILEDESC
Open file descriptor tables.
-.It Dv M_LOCKF
-Byte-range locking structures.
.It Dv M_PROC
Proc structures.
.It Dv M_SUBPROC
diff --git a/sys/kern/init_main.c b/sys/kern/init_main.c
index 28bf9d99d47..efc735280b8 100644
--- a/sys/kern/init_main.c
+++ b/sys/kern/init_main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: init_main.c,v 1.109 2004/01/01 00:04:35 deraadt Exp $ */
+/* $OpenBSD: init_main.c,v 1.110 2004/01/14 19:34:05 grange Exp $ */
/* $NetBSD: init_main.c,v 1.84.4.1 1996/06/02 09:08:06 mrg Exp $ */
/*
@@ -57,6 +57,7 @@
#include <sys/buf.h>
#include <sys/device.h>
#include <sys/socketvar.h>
+#include <sys/lockf.h>
#include <sys/protosw.h>
#include <sys/reboot.h>
#include <sys/user.h>
@@ -229,6 +230,9 @@ main(framep)
*/
procinit();
+ /* Initialize file locking. */
+ lf_init();
+
/*
* Initialize filedescriptors.
*/
diff --git a/sys/kern/vfs_lockf.c b/sys/kern/vfs_lockf.c
index 69195ee9dec..301ed50dd21 100644
--- a/sys/kern/vfs_lockf.c
+++ b/sys/kern/vfs_lockf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vfs_lockf.c,v 1.7 2003/07/21 22:44:50 tedu Exp $ */
+/* $OpenBSD: vfs_lockf.c,v 1.8 2004/01/14 19:34:05 grange Exp $ */
/* $NetBSD: vfs_lockf.c,v 1.7 1996/02/04 02:18:21 christos Exp $ */
/*
@@ -41,10 +41,12 @@
#include <sys/file.h>
#include <sys/proc.h>
#include <sys/vnode.h>
-#include <sys/malloc.h>
+#include <sys/pool.h>
#include <sys/fcntl.h>
#include <sys/lockf.h>
+struct pool lockfpool;
+
/*
* This variable controls the maximum number of processes that will
* be checked in doing deadlock detection.
@@ -70,6 +72,13 @@ int lockf_debug = DEBUG_SETLOCK|DEBUG_CLEARLOCK|DEBUG_WAKELOCK;
#define DPRINTF(args, level)
#endif
+void
+lf_init(void)
+{
+ pool_init(&lockfpool, sizeof(struct lockf), 0, 0, 0,
+ "lockfpl", &pool_allocator_nointr);
+}
+
/*
* Do an advisory lock operation.
*/
@@ -130,7 +139,7 @@ lf_advlock(head, size, id, op, fl, flags)
/*
* Create the lockf structure.
*/
- MALLOC(lock, struct lockf *, sizeof *lock, M_LOCKF, M_WAITOK);
+ lock = pool_get(&lockfpool, PR_WAITOK);
lock->lf_start = start;
lock->lf_end = end;
lock->lf_id = id;
@@ -149,16 +158,16 @@ lf_advlock(head, size, id, op, fl, flags)
case F_UNLCK:
error = lf_clearlock(lock);
- FREE(lock, M_LOCKF);
+ pool_put(&lockfpool, lock);
return (error);
case F_GETLK:
error = lf_getlock(lock, fl);
- FREE(lock, M_LOCKF);
+ pool_put(&lockfpool, lock);
return (error);
default:
- FREE(lock, M_LOCKF);
+ pool_put(&lockfpool, lock);
return (EINVAL);
}
/* NOTREACHED */
@@ -197,7 +206,7 @@ lf_setlock(lock)
* Free the structure and return if nonblocking.
*/
if ((lock->lf_flags & F_WAIT) == 0) {
- FREE(lock, M_LOCKF);
+ pool_put(&lockfpool, lock);
return (EAGAIN);
}
/*
@@ -228,7 +237,7 @@ lf_setlock(lock)
break;
wproc = (struct proc *)waitblock->lf_id;
if (wproc == (struct proc *)lock->lf_id) {
- FREE(lock, M_LOCKF);
+ pool_put(&lockfpool, lock);
return (EDEADLK);
}
}
@@ -263,7 +272,7 @@ lf_setlock(lock)
* Delete ourselves from the waiting to lock list.
*/
TAILQ_REMOVE(&lock->lf_next->lf_blkhd, lock, lf_block);
- FREE(lock, M_LOCKF);
+ pool_put(&lockfpool, lock);
return (error);
}
#else
@@ -272,7 +281,7 @@ lf_setlock(lock)
lock->lf_next = NULL;
}
if (error) {
- FREE(lock, M_LOCKF);
+ pool_put(&lockfpool, lock);
return (error);
}
#endif
@@ -318,7 +327,7 @@ lf_setlock(lock)
overlap->lf_type == F_WRLCK)
lf_wakelock(overlap);
overlap->lf_type = lock->lf_type;
- FREE(lock, M_LOCKF);
+ pool_put(&lockfpool, lock);
lock = overlap; /* for debug output below */
break;
@@ -327,7 +336,7 @@ lf_setlock(lock)
* Check for common starting point and different types.
*/
if (overlap->lf_type == lock->lf_type) {
- FREE(lock, M_LOCKF);
+ pool_put(&lockfpool, lock);
lock = overlap; /* for debug output below */
break;
}
@@ -368,7 +377,7 @@ lf_setlock(lock)
needtolink = 0;
} else
*prev = overlap->lf_next;
- FREE(overlap, M_LOCKF);
+ pool_put(&lockfpool, overlap);
continue;
case 4: /* overlap starts before lock */
@@ -438,7 +447,7 @@ lf_clearlock(lock)
case 1: /* overlap == lock */
*prev = overlap->lf_next;
- FREE(overlap, M_LOCKF);
+ pool_put(&lockfpool, overlap);
break;
case 2: /* overlap contains lock: split it */
@@ -453,7 +462,7 @@ lf_clearlock(lock)
case 3: /* lock contains overlap */
*prev = overlap->lf_next;
lf = overlap->lf_next;
- FREE(overlap, M_LOCKF);
+ pool_put(&lockfpool, overlap);
continue;
case 4: /* overlap starts before lock */
@@ -663,7 +672,7 @@ lf_split(lock1, lock2)
* Make a new lock consisting of the last part of
* the encompassing lock
*/
- MALLOC(splitlock, struct lockf *, sizeof *splitlock, M_LOCKF, M_WAITOK);
+ splitlock = pool_get(&lockfpool, PR_WAITOK);
memcpy(splitlock, lock1, sizeof (*splitlock));
splitlock->lf_start = lock2->lf_end + 1;
splitlock->lf_block.tqe_next = NULL;
diff --git a/sys/sys/lockf.h b/sys/sys/lockf.h
index a19aeeabcf0..35e6da253fd 100644
--- a/sys/sys/lockf.h
+++ b/sys/sys/lockf.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: lockf.h,v 1.5 2003/06/02 23:28:21 millert Exp $ */
+/* $OpenBSD: lockf.h,v 1.6 2004/01/14 19:34:05 grange Exp $ */
/* $NetBSD: lockf.h,v 1.5 1994/06/29 06:44:33 cgd Exp $ */
/*
@@ -59,6 +59,7 @@ struct lockf {
#define MAXDEPTH 50
__BEGIN_DECLS
+void lf_init(void);
int lf_advlock(struct lockf **,
off_t, caddr_t, int, struct flock *, int);
int lf_clearlock(struct lockf *);
diff --git a/sys/sys/malloc.h b/sys/sys/malloc.h
index 0f02f30b20d..32fad7dd0e5 100644
--- a/sys/sys/malloc.h
+++ b/sys/sys/malloc.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: malloc.h,v 1.69 2003/12/28 17:16:55 tedu Exp $ */
+/* $OpenBSD: malloc.h,v 1.70 2004/01/14 19:34:05 grange Exp $ */
/* $NetBSD: malloc.h,v 1.39 1998/07/12 19:52:01 augustss Exp $ */
/*
@@ -93,7 +93,7 @@
/* 35-37 - free */
#define M_FILE 38 /* Open file structure */
#define M_FILEDESC 39 /* Open file descriptor table */
-#define M_LOCKF 40 /* Byte-range locking structures */
+/* 40 - free */
#define M_PROC 41 /* Proc structures */
#define M_SUBPROC 42 /* Proc sub-structures */
#define M_VCLUSTER 43 /* Cluster for VFS */
@@ -216,7 +216,7 @@
NULL, /* 37 */ \
"file", /* 38 M_FILE */ \
"file desc", /* 39 M_FILEDESC */ \
- "lockf", /* 40 M_LOCKF */ \
+ NULL, /* 40 */ \
"proc", /* 41 M_PROC */ \
"subproc", /* 42 M_SUBPROC */ \
"VFS cluster", /* 43 M_VCLUSTER */ \