Ray Van Dolson's Blog

Pontifications from smoggy Southern California

File Locks on Solaris 10

with 6 comments

In the process of troubleshooting a file locking issue on a Samba/NFS server, I needed to be able to take a look at the locks on a Solaris 10 system. In Linux this is fairly straightforward to do with the lslk command or by taking a peek at /proc/locks. No such luck on Solaris.

Fortunately, I stumbled across this excellent reference and was introduced to the Solaris Modular Debugger (mdb).

The ::lminfo command gave me almost exactly what I needed, except, as Chris mentions in his wiki entry, the path information is truncated. You can easily cycle through and print only the path out, but then you’re missing the rest of the information which is awfully nice to see.

> ::lminfo
ADDR             TP FLAG    PID COMM             VNODE            PATH
600114a7040      WR 0021    315 ypbind           60012161080      /var/yp/binding/xpr
6001203ea00      WR 0021    315 ypbind           60012160080      /var/yp/binding/xpr
6001203e800      WR 0021    315 ypbind           600115b0140      /var/yp/binding/xpr
60011452700      WR 0001    558 mdmonitord       600131da100      /etc/lvm/.mdmonitor
6001203eb00      WR 0021    315 ypbind           60012160180      /var/yp/binding/xpr
60010a90e80      WR 0001    505 automountd       60013024180      /etc/svc/volatile/f

I couldn’t figure out a good way to convince ::print to display multiple lock_descriptor_t members — and format it as nicely as ::lminfo did. I was about to write an external parser in awk or python to hack this together, when Jonathan Adams of Sun suggested that an mdb module could be created to accomplish just what I was after.

After some trials and tribulations getting this going, I was able to create a ::lminfo2 module that not only displays the pathname of the locked file sans truncation, but also spits out the whence, start and length information for ranged locks! Sample output:

# echo "::load /home/rayvd/src/mdb/sparcv9/lminfo2.so; ::lminfo2" | mdb -k
ADDR             TP FLAG    PID COMM             VNODE            WHENCE    START     LEN       PATH
600114a7040      WR 0021    315 ypbind           60012161080      1         0         1         /var/yp/binding/xprt.udp.2
6001203ea00      WR 0021    315 ypbind           60012160080      1         0         1         /var/yp/binding/xprt.ticlts.2
6001203e800      WR 0021    315 ypbind           600115b0140      1         0         1         /var/yp/binding/xprt.ticotsord.3
60011452700      WR 0001    558 mdmonitord       600131da100      0         0         0         /etc/lvm/.mdmonitord.lock
6001203eb00      WR 0021    315 ypbind           60012160180      1         0         1         /var/yp/binding/xprt.ticlts.3
60010a90e80      WR 0001    505 automountd       60013024180      0         0         0         /etc/svc/volatile/filesystem-autofs.lock

The main challenge I encountered was dealing with the mdb_printf and mdb_snprintf commands. Both are “smart” in that they automatically truncate lines at the end of the terminal.

To build the module, you need a C compiler, the SUNWmdbdm package, and also, a header file (mdb_ks.h) from the mdb sources (available in OpenSolaris) to gain access to some internal mdb functions not exposed by mdb_modapi.h.

The module, and some basic instructions on building are available here. Feedback welcome.

Advertisements

Written by rayvd

October 25, 2009 at 8:16 pm

Posted in Systems Administration, Technology

Tagged with ,

6 Responses

Subscribe to comments with RSS.

  1. The link above ( http://www.bludgeon.org/~rayvd/devel/mdb/lminfo2/ ) is unreachable; host pings but attempts to access the web page hang; this has been the case for at least a day now.

    rlhamil2

    March 23, 2016 at 12:53 pm

    • It’s probably been the case for a few years, as the system all of that source resided on crashed. I may be able to dig it up again if you’re wanting to take a look?

      rayvd

      March 23, 2016 at 1:02 pm

      • If it’s not too much trouble, please! I’ve had situations where the extra information it provides would have been helpful.

        rlhamil2

        March 23, 2016 at 1:49 pm

      • Restored from a backup and should be available again via the original URL…

        rayvd

        March 24, 2016 at 6:26 am

  2. Got it, thanks! Works great. BTW, with opensolaris.org gone, mdb_ks.h can be obtained at https://raw.githubusercontent.com/joyent/illumos-joyent/master/usr/src/cmd/mdb/common/mdb/mdb_ks.h

    (probably a number of other places too)

    rlhamil2

    March 24, 2016 at 7:03 am

  3. Builds on Solaris 11 also, if package pkg://solaris/source/demo/mdb-examples is installed, AND if a suitable version of sys/dumphdr.h can be scrounged (it may be missing from the system header package). The one from illumos or joyent would probably work, except on compressed crash dumps. A certain rumored torrent might contain a better one. 🙂

    rlhamil2

    March 24, 2016 at 8:07 am


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: