[Midnightbsd-cvs] src [7924] trunk/sys: Add a rangelock implementation, intended to be used to range-locking
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Wed Sep 14 16:43:02 EDT 2016
Revision: 7924
http://svnweb.midnightbsd.org/src/?rev=7924
Author: laffer1
Date: 2016-09-14 16:43:02 -0400 (Wed, 14 Sep 2016)
Log Message:
-----------
Add a rangelock implementation, intended to be used to range-locking
the i/o regions of the vnode data space. The implementation is quite
simple-minded, it uses the list of the lock requests, ordered by
arrival time. Each request may be for read or for write. The
implementation is fair FIFO.
Obtained from: FreeBSD
Modified Paths:
--------------
trunk/sys/conf/files
trunk/sys/kern/kern_thread.c
trunk/sys/kern/vfs_subr.c
trunk/sys/sys/proc.h
trunk/sys/sys/vnode.h
Modified: trunk/sys/conf/files
===================================================================
--- trunk/sys/conf/files 2016-09-14 20:19:40 UTC (rev 7923)
+++ trunk/sys/conf/files 2016-09-14 20:43:02 UTC (rev 7924)
@@ -2420,6 +2420,7 @@
kern/kern_proc.c standard
kern/kern_prot.c standard
kern/kern_racct.c standard
+kern/kern_rangelock.c standard
kern/kern_rctl.c standard
kern/kern_resource.c standard
kern/kern_rmlock.c standard
Modified: trunk/sys/kern/kern_thread.c
===================================================================
--- trunk/sys/kern/kern_thread.c 2016-09-14 20:19:40 UTC (rev 7923)
+++ trunk/sys/kern/kern_thread.c 2016-09-14 20:43:02 UTC (rev 7924)
@@ -39,6 +39,7 @@
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/proc.h>
+#include <sys/rangelock.h>
#include <sys/resourcevar.h>
#include <sys/sdt.h>
#include <sys/smp.h>
@@ -205,6 +206,7 @@
td->td_sleepqueue = sleepq_alloc();
td->td_turnstile = turnstile_alloc();
+ td->td_rlqe = NULL;
EVENTHANDLER_INVOKE(thread_init, td);
td->td_sched = (struct td_sched *)&td[1];
umtx_thread_init(td);
@@ -222,6 +224,7 @@
td = (struct thread *)mem;
EVENTHANDLER_INVOKE(thread_fini, td);
+ rlqentry_free(td->td_rlqe);
turnstile_free(td->td_turnstile);
sleepq_free(td->td_sleepqueue);
umtx_thread_fini(td);
Modified: trunk/sys/kern/vfs_subr.c
===================================================================
--- trunk/sys/kern/vfs_subr.c 2016-09-14 20:19:40 UTC (rev 7923)
+++ trunk/sys/kern/vfs_subr.c 2016-09-14 20:43:02 UTC (rev 7924)
@@ -1026,6 +1026,7 @@
if ((mp->mnt_kern_flag & MNTK_NOKNOTE) != 0)
vp->v_vflag |= VV_NOKNOTE;
}
+ rangelock_init(&vp->v_rl);
*vpp = vp;
return (0);
@@ -2468,6 +2469,7 @@
/* XXX Elsewhere we detect an already freed vnode via NULL v_op. */
vp->v_op = NULL;
#endif
+ rangelock_destroy(&vp->v_rl);
lockdestroy(vp->v_vnlock);
mtx_destroy(&vp->v_interlock);
mtx_destroy(BO_MTX(bo));
Modified: trunk/sys/sys/proc.h
===================================================================
--- trunk/sys/sys/proc.h 2016-09-14 20:19:40 UTC (rev 7923)
+++ trunk/sys/sys/proc.h 2016-09-14 20:43:02 UTC (rev 7924)
@@ -313,6 +313,7 @@
const char *td_vnet_lpush; /* (k) Debugging vnet push / pop. */
struct trapframe *td_intr_frame;/* (k) Frame of the current irq */
struct proc *td_rfppwait_p; /* (k) The vforked child */
+ struct rl_q_entry *td_rlqe; /* (k) Associated range lock entry. */
void *td_machdata; /* (k) mach state. */
};
Modified: trunk/sys/sys/vnode.h
===================================================================
--- trunk/sys/sys/vnode.h 2016-09-14 20:19:40 UTC (rev 7923)
+++ trunk/sys/sys/vnode.h 2016-09-14 20:43:02 UTC (rev 7924)
@@ -38,6 +38,7 @@
#include <sys/lock.h>
#include <sys/lockmgr.h>
#include <sys/mutex.h>
+#include <sys/rangelock.h>
#include <sys/selinfo.h>
#include <sys/uio.h>
#include <sys/acl.h>
@@ -165,6 +166,7 @@
struct vpollinfo *v_pollinfo; /* i Poll events, p for *v_pi */
struct label *v_label; /* MAC label for vnode */
struct lockf *v_lockf; /* Byte-level advisory lock list */
+ struct rangelock v_rl; /* Byte-range lock */
};
#endif /* defined(_KERNEL) || defined(_KVM_VNODE) */
@@ -682,6 +684,15 @@
int vn_vget_ino(struct vnode *vp, ino_t ino, int lkflags,
struct vnode **rvp);
+#define vn_rangelock_unlock(vp, cookie) \
+ rangelock_unlock(&(vp)->v_rl, (cookie), VI_MTX(vp))
+#define vn_rangelock_unlock_range(vp, cookie, start, end) \
+ rangelock_unlock_range(&(vp)->v_rl, (cookie), (start), (end), \
+ VI_MTX(vp))
+#define vn_rangelock_rlock(vp, start, end) \
+ rangelock_rlock(&(vp)->v_rl, (start), (end), VI_MTX(vp))
+#define vn_rangelock_wlock(vp, start, end) \
+ rangelock_wlock(&(vp)->v_rl, (start), (end), VI_MTX(vp))
int vfs_cache_lookup(struct vop_lookup_args *ap);
void vfs_timestamp(struct timespec *);
More information about the Midnightbsd-cvs
mailing list