From owner-freebsd-hackers Wed Jan 21 00:26:42 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id AAA03729 for hackers-outgoing; Wed, 21 Jan 1998 00:26:42 -0800 (PST) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from allegro.lemis.com (allegro.lemis.com [192.109.197.134]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id AAA03724 for ; Wed, 21 Jan 1998 00:26:35 -0800 (PST) (envelope-from grog@lemis.com) Received: from freebie.lemis.com (freebie.lemis.com [192.109.197.137]) by allegro.lemis.com (8.8.7/8.8.5) with ESMTP id SAA09859 for ; Wed, 21 Jan 1998 18:56:29 +1030 (CST) Received: (from grog@localhost) by freebie.lemis.com (8.8.8/8.8.7) id SAA08881; Wed, 21 Jan 1998 18:56:28 +1030 (CST) (envelope-from grog) Message-ID: <19980121185627.21744@lemis.com> Date: Wed, 21 Jan 1998 18:56:27 +1030 From: Greg Lehey To: FreeBSD Hackers Subject: Locking on disk slice I/O--yes, no or how? Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 0.84e Organization: LEMIS, PO Box 460, Echunga SA 5153, Australia Phone: +61-8-8388-8286 Fax: +61-8-8388-8725 Mobile: +61-41-739-7062 WWW-Home-Page: http://www.lemis.com/~grog Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk I'm currently trying to perform low-level I/O to disk slices in a driver. I've read section 9 of the manual, which tells me that all reads and writes should be protected with a VOP_LOCK/VOP_UNLOCK pair. I've tried this, and get a panic: "lockmgr: locking against myself" Looking at the dump, I find that my vnode does not appear to be locked. Here it is without most of the fields. (kgdb) p *devvp $12 = { v_flag = 0, v_usecount = 1, v_writecount = 0, v_type = VCHR, v_un = { vu_mountedhere = 0xf0337820, vu_socket = 0xf0337820, vu_specinfo = 0xf0337820, vu_fifoinfo = 0xf0337820 }, v_interlock = { lock_data = 0 }, v_vnlock = 0x0, v_tag = VT_UFS, v_data = 0xf0548700, /* this seems to be used by the locks */ } } The following code leads to a panic: VOP_LOCK (devvp, LK_EXCLUSIVE, curproc); /* lock the vnode */ error = VOP_WRITE (devvp, &uio, IO_NODELOCKED, FSCRED); /* write the header */ VOP_UNLOCK (devvp, 0, curproc); /* and unlock it again */ #1 0xf011bdaf in panic (fmt=0xf01172cf "lockmgr: locking against myself") at ../../kern/kern_shutdown.c:425 #2 0xf0117540 in lockmgr (lkp=0xf0548700, flags=2, interlkp=0xf052365c, p=0xf04fda00) at ../../kern/kern_lock.c:288 #3 0xf0138071 in vop_stdlock (ap=0xf3a45cac) at ../../kern/vfs_default.c:194 #4 0xf01c1a41 in ufs_vnoperatespec (ap=0xf3a45cac) at ../../ufs/ufs/ufs_vnops.c:2186 #5 0xf3cec47e in save_config () at vnode_if.h:811 Looking at the stack frame for vop_stdlock, it looks as if I'm trying to use my devvp->v_data as lock data to lock against my own vnode. I can't make sense of this (except that, under these circumstances, I can understand the panic). I have a number of questions: 1. What is the lock manager trying to do here? What's the content of devvp->v_data? 2. Why do I need to lock at all? According to the 4.4BSD book, it's "advisory", and then only for directory searches and such. 3. Are the parameters correct? It looks as if I shouldn't specify curproc in the calls, but I can't find any documentation that tells me what to put there, nor indeed what use the whole thing is. 4. This device is /dev/rsd1e. Should I even be calling ufs_vnoperatespec? 5. Am I doing anything else obviously wrong? Greg