October 2010

Thinking control versus command

I’m trying real hard to make that final switch to OS X and the biggest problem I am having is thinking “Control” instead of “Command” when I want to do a meta-operation. In Windows, I’d do a Ctl-C instead of a Cmd-C. So I’ve been letting myself get away with it.

Now that I’m trying to be legit, I find the thought process is impacting the finger process.

A recursive gdb script for Binary Trees

If we have a binary tree, how do we determine if a key is in the tree? Or another way, how do we know it was inserted correctly? We need to visit every node.

This is a recursive problem and hard to do in gdb. The convenience variables are very simple and we can not implement a stack with them. Since they are effectively global, we can not even hide them in stack frames. What we can do is use concatenation and a node-id to generate uniqe names.

Note that you have to do all variable name declarations before you do any recursion. That statement will make sense when you violate it and wonder why your output looks strange.

define indentby
        printf "%*c", $arg0+1, 0

define walk_btree
        set $node_$arg0 = ($arg1)
        set $fnum_$arg0 = ($arg2)
        set $branch_$arg0 = ($arg3)
        set $space_$arg0 = ($arg4)
        set $leftid_$arg0 = $arg0 + 1
        set $rightid_$arg0 = $arg0 + 2

        indentby $space_$arg0
        printf "%d %u (btree *)%p\n", $branch_$arg0, $node_$arg0->e_type[$fnum_$arg0].key, $node_$arg0

        set $space_$arg0 = $space_$arg0 + 1
        if $node_$arg0->e_type[$fnum_$arg0].left
                walk_btree $leftid_$arg0 $node_$arg0->e_type[$fnum_$arg0].left $fnum_$arg0 0 $space_$arg0
        if $node_$arg0->e_type[$fnum_$arg0].right
                walk_btree $rightid_$arg0 $node_$arg0->e_type[$fnum_$arg0].right $fnum_$arg0 1 $space_$arg0
document walk_btree
        Recursively walk the binary tree printing out the key for the fnum'ed entry

define start_walk_btree
        walk_btree 0 $arg0 $arg1 3 1
document start_walk_btree
        NODE FNUM
        Recursively walk the binary tree printing out the key for the fnum'ed entry

Contrast that against a very simple algorithm to find if the key is in the tree (with the assumption the tree is valid).

Recursion is not needed as we lop of a branch with each iteration.

define find_btree
        set $node = $arg0
        set $fnum = $arg1
        set $key = $arg2
        set $process = 1

        while $node && $process
                if $key == $node->e_type[$fnum].key
                        set $process = 0

                        if $key < $node->e_type[$fnum].key
                                $node = $node->e_type[$fnum].left
                                $node = $node->e_type[$fnum].right

        if $node
                printf "Found match on (btree *)%p\n", $node
                printf "No matching node in the binary tree\n"

Using xargs to apply tshark to many capture files

pktt on a filer can capture for all network interfaces on a head. In order to quickly determine which have relevant data, we can use xargs:

KinMage:csiqa-6080-15 thomas$ ls -1 *021* | xargs -I {} -t tshark -R nfs -r {}
tshark -R nfs -r e0a_20101021_090354.trc
tshark -R nfs -r e0b_20101021_090354.trc
tshark -R nfs -r e0c_20101021_090354.trc
tshark -R nfs -r e0d_20101021_090354.trc
tshark -R nfs -r e0e_20101021_090354.trc
123   0.267673 -> NFS V4 COMPOUND Reply (Call In 122) <EMPTY> PUTFH;CLOSE
tshark -R nfs -r e0f_20101021_090354.trc
tshark -R nfs -r e4a_20101021_090354.trc
tshark -R nfs -r lo_20101021_090354.trc
tshark -R nfs -r losk_20101021_090354.trc
KinMage:csiqa-6080-15 thomas$ cd ../csiqa-6080-16/
KinMage:csiqa-6080-16 thomas$ ls -1 *021* | xargs -I {} -t tshark -R nfs -r {}
tshark -R nfs -r e0a_20101021_090347.trc
tshark -R nfs -r e0b_20101021_090347.trc
tshark -R nfs -r e0c_20101021_090347.trc
tshark -R nfs -r e0d_20101021_090347.trc
tshark -R nfs -r e4a_20101021_090347.trc
tshark -R nfs -r lo_20101021_090347.trc
tshark -R nfs -r losk_20101021_090347.trc

So we see the first head saw NFS traffic on e0e, but the second saw none.

tshark, my new favorite command line tool

[thomas@godwit ~]> tshark -R nfs -r e4a_20101020_223437.trc
9   1.020806 -> NFS V4 NULL Call
10   1.020972 -> NFS V4 NULL Reply (Call In 9)

Going KVM

I’ve been cleaning up the clutter in my office and as much as I like having a keyboard for each computer, it isn’t like I can type on both at the same time. So I dug out my iogear GC634U 4-port USB KVM switch. Now I like the form factor and such, but it only does VGA, despite being shown on the box working with Mac Minis.

So I’ve just hooked up the KM and left the V on the roadside. I do use multiple displays at the same time, so this is a plus.

Anyway, the hotkeys are [scroll-lock][scroll-lock] and the Macs do not have that key. You can reprogram that with [clear][-] and once the [caps-lock] starts blinking, [t]. At that point [control][control] will be your hotkey initiator. And to cycle through the attached machines, [control][control][return]. I.e., I don’t care to remember which ports I have hooked up.

I haven’t made the jump to attaching my Win7 box yet.

Oh yeah, on the two interior cable sets, the ones not always attached, the white capped connector goes to the KVM and the blue capped one (which has the USB and audio cables) goes to your computer.

How to mount nfsv4 from Snow Leopard

KinMage:~ tdh$ sudo mount -o vers=4 /mnt
mount_nfs: sorry, you must specify vers=4.0alpha to use the alpha-quality NFSv4 support
KinMage:~ tdh$ sudo mount -o vers=4.0alpha /mnt
KinMage:~ tdh$ ls -la /mnt
total 23952
drwxr-xr-x   2 root  220776704     4096 Oct  7 17:31 .
drwxrwxr-t  32 root  admin         1156 Oct  4 14:01 ..
-rwxr-xr-x   1 root  daemon     1455680 Oct  7 17:31 img_0132.jpg
-rwxr-xr-x   1 root  daemon     1698991 Oct  7 17:31 img_0135.jpg
-rwxr-xr-x   1 root  daemon     1539525 Oct  7 17:31 img_0136.jpg
-rwxr-xr-x   1 root  daemon     1522669 Oct  7 17:31 img_0137.jpg
-rwxr-xr-x   1 root  daemon     1524863 Oct  7 17:31 img_0138.jpg
-rwxr-xr-x   1 root  daemon     1459397 Oct  7 17:31 img_0140.jpg
-rwxr-xr-x   1 root  220776704  1505265 Oct  7 17:31 img_0141.jpg
-rwxr-xr-x   1 root  daemon     1470002 Oct  7 17:31 img_0143.jpg