svn commit: r256076 - in stable/9/sys: kern sys

Konstantin Belousov kib at FreeBSD.org
Sun Oct 6 06:05:12 UTC 2013


Author: kib
Date: Sun Oct  6 06:05:11 2013
New Revision: 256076
URL: http://svnweb.freebsd.org/changeset/base/256076

Log:
  MFC r255940:
  Add LK_TRYUPGRADE operation for lockmgr(9).

Modified:
  stable/9/sys/kern/kern_lock.c
  stable/9/sys/sys/lockmgr.h
Directory Properties:
  stable/9/sys/   (props changed)
  stable/9/sys/sys/   (props changed)

Modified: stable/9/sys/kern/kern_lock.c
==============================================================================
--- stable/9/sys/kern/kern_lock.c	Sun Oct  6 05:53:29 2013	(r256075)
+++ stable/9/sys/kern/kern_lock.c	Sun Oct  6 06:05:11 2013	(r256076)
@@ -490,6 +490,7 @@ __lockmgr_args(struct lock *lk, u_int fl
 			op = LK_EXCLUSIVE;
 			break;
 		case LK_UPGRADE:
+		case LK_TRYUPGRADE:
 		case LK_DOWNGRADE:
 			_lockmgr_assert(lk, KA_XLOCKED | KA_NOTRECURSED,
 			    file, line);
@@ -687,6 +688,7 @@ __lockmgr_args(struct lock *lk, u_int fl
 		}
 		break;
 	case LK_UPGRADE:
+	case LK_TRYUPGRADE:
 		_lockmgr_assert(lk, KA_SLOCKED, file, line);
 		v = lk->lk_lock;
 		x = v & LK_ALL_WAITERS;
@@ -707,6 +709,17 @@ __lockmgr_args(struct lock *lk, u_int fl
 		}
 
 		/*
+		 * In LK_TRYUPGRADE mode, do not drop the lock,
+		 * returning EBUSY instead.
+		 */
+		if (op == LK_TRYUPGRADE) {
+			LOCK_LOG2(lk, "%s: %p failed the nowait upgrade",
+			    __func__, lk);
+			error = EBUSY;
+			break;
+		}
+
+		/*
 		 * We have been unable to succeed in upgrading, so just
 		 * give up the shared lock.
 		 */

Modified: stable/9/sys/sys/lockmgr.h
==============================================================================
--- stable/9/sys/sys/lockmgr.h	Sun Oct  6 05:53:29 2013	(r256075)
+++ stable/9/sys/sys/lockmgr.h	Sun Oct  6 06:05:11 2013	(r256076)
@@ -168,6 +168,7 @@ _lockmgr_args_rw(struct lock *lk, u_int 
 #define	LK_RELEASE	0x100000
 #define	LK_SHARED	0x200000
 #define	LK_UPGRADE	0x400000
+#define	LK_TRYUPGRADE	0x800000
 
 #define	LK_TOTAL_MASK	(LK_INIT_MASK | LK_EATTR_MASK | LK_TYPE_MASK)
 


More information about the svn-src-stable-9 mailing list