From owner-freebsd-bugs@FreeBSD.ORG Thu Jul 1 01:40:39 2004 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id A4DD616A4CE for ; Thu, 1 Jul 2004 01:40:39 +0000 (GMT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 888F043D46 for ; Thu, 1 Jul 2004 01:40:39 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.11/8.12.11) with ESMTP id i611eS8Y027987 for ; Thu, 1 Jul 2004 01:40:28 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.11/8.12.11/Submit) id i611eRPI027986; Thu, 1 Jul 2004 01:40:27 GMT (envelope-from gnats) Date: Thu, 1 Jul 2004 01:40:27 GMT Message-Id: <200407010140.i611eRPI027986@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org From: Stephen Hurd Subject: Re: kern/50827: [PATCH] no sane record locking on *nix. (Moretypes needed) X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: Stephen Hurd List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 01 Jul 2004 01:40:39 -0000 The following reply was made to PR kern/50827; it has been noted by GNATS. From: Stephen Hurd To: freebsd-gnats-submit@FreeBSD.org, shurd@sasktel.net Cc: Subject: Re: kern/50827: [PATCH] no sane record locking on *nix. (More types needed) Date: Wed, 30 Jun 2004 19:37:17 -0600 Actually, I meant that the following patch works on 5.2.1 :-) --- sanelock.patch begins here --- diff -c /sys/kern.old/kern_descrip.c /sys/kern/kern_descrip.c *** /sys/kern.old/kern_descrip.c Thu Jun 24 17:25:47 2004 --- /sys/kern/kern_descrip.c Thu Jun 24 18:22:09 2004 *************** *** 380,385 **** --- 380,411 ---- error = VOP_ADVLOCK(vp, (caddr_t)p->p_leader, F_UNLCK, flp, F_POSIX); break; + case F_SANEWRLCKNO: + flg |= F_NOOVRLP; + case F_SANEWRLCK: + flp->l_type=F_WRLCK; + flg &= ~F_POSIX; + flg |= F_FLOCK; + fp->f_flag |= FHASLOCK; + error = VOP_ADVLOCK(vp, (caddr_t)fp, F_SETLK, + flp, flg); + break; + case F_SANERDLCKNO: + flg |= F_NOOVRLP; + case F_SANERDLCK: + flp->l_type=F_RDLCK; + flg &= ~F_POSIX; + flg |= F_FLOCK; + fp->f_flag |= FHASLOCK; + error = VOP_ADVLOCK(vp, (caddr_t)fp, F_SETLK, + flp, flg); + break; + case F_SANEUNLCK: + flg &= ~F_POSIX; + flg |= F_FLOCK; + error = VOP_ADVLOCK(vp, (caddr_t)fp, F_UNLCK, + flp, F_FLOCK); + break; default: error = EINVAL; break; Only in /sys/kern: kern_descrip.c.orig diff -c /sys/kern.old/kern_lockf.c /sys/kern/kern_lockf.c *** /sys/kern.old/kern_lockf.c Thu Jun 24 17:25:48 2004 --- /sys/kern/kern_lockf.c Thu Jun 24 17:28:52 2004 *************** *** 605,612 **** start = lock->lf_start; end = lock->lf_end; while (lf != NOLOCKF) { ! if (((type & SELF) && lf->lf_id != lock->lf_id) || ! ((type & OTHERS) && lf->lf_id == lock->lf_id)) { *prev = &lf->lf_next; *overlap = lf = lf->lf_next; continue; --- 605,613 ---- start = lock->lf_start; end = lock->lf_end; while (lf != NOLOCKF) { ! if ((!(lock->lf_flags & F_NOOVRLP)) && ! (((type & SELF) && lf->lf_id != lock->lf_id) || ! ((type & OTHERS) && lf->lf_id == lock->lf_id))) { *prev = &lf->lf_next; *overlap = lf = lf->lf_next; continue; diff -c /sys/sys.old/fcntl.h /sys/sys/fcntl.h *** /sys/sys.old/fcntl.h Fri Apr 11 01:48:32 2003 --- /sys/sys/fcntl.h Fri Apr 11 01:48:11 2003 *************** *** 167,176 **** --- 167,196 ---- #define F_RDLCK 1 /* shared or read lock */ #define F_UNLCK 2 /* unlock */ #define F_WRLCK 3 /* exclusive or write lock */ + #ifndef _POSIX_SOURCE + /* + * The following lock types do NOT follow the completely stupid POSIX + * fcntl() semantics. Locks are per file descriptor not per file, and + * you can request an exclusive lock on a file opened for read as well as+ * a read lock on a file opened for write. + */ + #define F_SANERDLCK 4 /* sane shared or read lock */ + #define F_SANEUNLCK 5 /* unlock sane locks */ + #define F_SANEWRLCK 6 /* sane exclusive or write lock */ + + /* + * These lock types are sane locks that fail if there is ANY lock in the region + * they are locking that would conflict (ie: process conflicts with itself as+ * well as other processes. + */ + #define F_SANERDLCKNO 7 /* don't up/downgrade or merge locks */ + #define F_SANEWRLCKNO 8 + #endif #ifdef _KERNEL #define F_WAIT 0x010 /* Wait until lock is granted */ #define F_FLOCK 0x020 /* Use flock(2) semantics for lock */ #define F_POSIX 0x040 /* Use POSIX semantics for lock */ + #define F_NOOVRLP 0x080 /* Don't allow overlapping locks */ #endif /* --- sanelock.patch ends here ---