Posts Tagged ‘mdb’
File Locks on Solaris 10
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.