Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 21 Jan 1998 18:56:27 +1030
From:      Greg Lehey <grog@lemis.com>
To:        FreeBSD Hackers <hackers@FreeBSD.ORG>
Subject:   Locking on disk slice I/O--yes, no or how?
Message-ID:  <19980121185627.21744@lemis.com>

next in thread | raw e-mail | index | archive | help
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




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