This is the mail archive of the systemtap@sourceware.org mailing list for the systemtap project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Proposing tapset MAJOR(), MINOR(), and MKDEV() function


Hi All,

I have been working on cleaning up the war stories and including them
in the regular testing. A number of the warstories(WSDeviceMonitor,
WSFileMonitor, and WSFileMonitor2) make use of the device number
information. The examples extract the device number out of a
dev_t. Right now the examples are a bit awkward. The examples use stat
to get determine the major and minor number, but the actual feeding to
the script requires some manual munging. From WSDeviceMonitor:

$ ls -laF /dev/sdc1
brw-r----- 1 root disk 8, 33 2007-06-12 20:25 /dev/sdc1
$ stap traceio2.stp 8 33

It seems like it would be nicer to allow the use the output of stat
directly.  Something like:

stap traceio2.stp `stat -c "0x%t 0x%T" /dev/sdc1`

It might be useful to have wrappers functions in systemtap to make
handling major and minor device numbers a bit more portable:

MAJOR(kdev_t dev)     	   extract major device number
MINOR(kdev_t dev)	   extract minor device number
MKDEV(int major, int minor)generate device number


rather than having hardcoded shifts and bit-wise or, could do something like the following in the script:

probe kernel.function ("vfs_write"),
      kernel.function ("vfs_read")
{
        dev_nr = $file->f_path->dentry->d_inode->i_sb->s_dev
        inode_nr = $file->f_path->dentry->d_inode->i_ino

        if (dev_nr == MKDEV($1,$2))
                printf ("%s(%d) %s 0x%x\n", execname(), pid(), probefunc(), dev_nr)
}

I have attached the dev.stp tapset to the mail. Any comments about
adding these tapset functions.

-Will
// Device numbering tapset
// Copyright (C) 2008 Red Hat Corp.
//
// This file is part of systemtap, and is free software.  You can
// redistribute it and/or modify it under the terms of the GNU General
// Public License (GPL); either version 2, or (at your option) any
// later version.

%{
#include <linux/kdev_t.h>
%}

function MAJOR:long(dev:long)
%{ /* pure */
    THIS->__retvalue = MAJOR(THIS->dev);
%}


function MINOR:long(dev:long)
%{ /* pure */
    THIS->__retvalue = MINOR(THIS->dev);
%}


function MKDEV:long(major:long, minor:long)
%{ /* pure */
    THIS->__retvalue = MKDEV(THIS->major,THIS->minor);
%}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]