Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 13 Dec 2019 04:03:04 +0000 (UTC)
From:      Kyle Evans <kevans@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org
Subject:   svn commit: r355690 - in stable: 11/sys/kern 11/sys/sys 12/sys/kern 12/sys/sys
Message-ID:  <201912130403.xBD434Qn011982@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kevans
Date: Fri Dec 13 04:03:03 2019
New Revision: 355690
URL: https://svnweb.freebsd.org/changeset/base/355690

Log:
  MFC r352350: rangelock: add rangelock_cookie_assert
  
  A future change to posixshm to add file sealing will move locking out of
  shm_dotruncate as kern_shm_open() will require the lock to be held across
  the dotruncate until the seal is actually applied. For this, the cookie is
  passed into shm_dotruncate_locked which asserts RCA_WLOCKED.

Modified:
  stable/12/sys/kern/kern_rangelock.c
  stable/12/sys/sys/rangelock.h
Directory Properties:
  stable/12/   (props changed)

Changes in other areas also in this revision:
Modified:
  stable/11/sys/kern/kern_rangelock.c
  stable/11/sys/sys/rangelock.h
Directory Properties:
  stable/11/   (props changed)

Modified: stable/12/sys/kern/kern_rangelock.c
==============================================================================
--- stable/12/sys/kern/kern_rangelock.c	Fri Dec 13 03:29:54 2019	(r355689)
+++ stable/12/sys/kern/kern_rangelock.c	Fri Dec 13 04:03:03 2019	(r355690)
@@ -248,3 +248,35 @@ rangelock_wlock(struct rangelock *lock, off_t start, o
 
 	return (rangelock_enqueue(lock, start, end, RL_LOCK_WRITE, ilk));
 }
+
+#ifdef INVARIANT_SUPPORT
+void
+_rangelock_cookie_assert(void *cookie, int what, const char *file, int line)
+{
+	struct rl_q_entry *entry;
+	int flags;
+
+	MPASS(cookie != NULL);
+	entry = cookie;
+	flags = entry->rl_q_flags;
+	switch (what) {
+	case RCA_LOCKED:
+		if ((flags & RL_LOCK_GRANTED) == 0)
+			panic("rangelock not held @ %s:%d\n", file, line);
+		break;
+	case RCA_RLOCKED:
+		if ((flags & (RL_LOCK_GRANTED | RL_LOCK_READ)) !=
+		    (RL_LOCK_GRANTED | RL_LOCK_READ))
+			panic("rangelock not rlocked @ %s:%d\n", file, line);
+		break;
+	case RCA_WLOCKED:
+		if ((flags & (RL_LOCK_GRANTED | RL_LOCK_WRITE)) !=
+		    (RL_LOCK_GRANTED | RL_LOCK_WRITE))
+			panic("rangelock not wlocked @ %s:%d\n", file, line);
+		break;
+	default:
+		panic("Unknown rangelock assertion: %d @ %s:%d", what, file,
+		    line);
+	}
+}
+#endif	/* INVARIANT_SUPPORT */

Modified: stable/12/sys/sys/rangelock.h
==============================================================================
--- stable/12/sys/sys/rangelock.h	Fri Dec 13 03:29:54 2019	(r355689)
+++ stable/12/sys/sys/rangelock.h	Fri Dec 13 04:03:03 2019	(r355690)
@@ -78,6 +78,29 @@ void	*rangelock_rlock(struct rangelock *lock, off_t st
 void	*rangelock_wlock(struct rangelock *lock, off_t start, off_t end,
 	    struct mtx *ilk);
 void	 rlqentry_free(struct rl_q_entry *rlqe);
+#if defined(INVARIANTS) || defined(INVARIANT_SUPPORT)
+void	_rangelock_cookie_assert(void *cookie, int what, const char *file,
+    int line);
+#endif
+
+#ifdef INVARIANTS
+#define	rangelock_cookie_assert_(cookie, what, file, line)	\
+	_rangelock_cookie_assert((cookie), (what), (file), (line))
+#else
+#define	rangelock_cookie_assert_(cookie, what, file, line)		(void)0
+#endif
+
+#define	rangelock_cookie_assert(cookie, what)	\
+	rangelock_cookie_assert_((cookie), (what), __FILE__, __LINE__)
+
+/*
+ * Assertion flags.
+ */
+#if defined(INVARIANTS) || defined(INVARIANT_SUPPORT)
+#define	RCA_LOCKED	0x0001
+#define	RCA_RLOCKED	0x0002
+#define	RCA_WLOCKED	0x0004
+#endif
 
 #endif	/* _KERNEL */
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201912130403.xBD434Qn011982>