[OpenAFS] fs setserverprefs and supernetting

Assarsson, Emil Emil.Assarsson@sonyericsson.com
Mon, 1 Nov 2010 10:31:15 +0100


Hi all,

I would just like to have your input on this method of setting serverprefs =
based on the supernet distance.

The background is that we have a large WAN with high latencies. The default=
 method of calculating the weight for serverprefs is not good.
We could have done this with static weighting but we need to keep things re=
ally flexible and self-configuring.

This script is intended to be executed by cron each minute or so.

----
#!/usr/bin/perl -w
# Author: Emil Assarsson
# Description:
#   OpenAFS currently doesn't set good default values with fs setserverpref=
s.
#   This script sets server weights depending on ip address difference

use Socket;

# This function returns the *used* length of the bit string
# 00001000 returns 4
# 00000101 returns 3
sub usedbitlength($)
{
    $bits =3D shift();
    $length =3D 0;
    while($bits) {
        $bits >>=3D 1;
        $length ++;
    }
    return($length);
}

# calculate the distance between two ip addresses in a supernetted
# network. This calculation is based on the equality of the network bits.
sub supernetdistance
{
    $ip1 =3D shift();
    $ip2 =3D shift();
    $xordiff =3D $ip1 ^ $ip2; # Mask out the shared network bits
    return usedbitlength($xordiff);
}

sub ip2int($)
{
    return unpack('N',inet_aton(shift()));
};

# Get IP
$myip =3D "";
open('IFCONFIG',"ifconfig eth0|") or die "Can't use ifconfig";
while(<IFCONFIG>) {
    if(m/inet addr:([0-9\.]+) /) {
        $myipstr =3D $1;
        last;
    }
}
die "Can't find this machines ip address" if $myipstr eq "";
$myip =3D ip2int($myipstr);

# Sort servers
open(FSGP, "fs gp -nu|") or die "Can't get servers";
while(<FSGP>) {
    if(m/^([0-9\.]+) /) {
        $server =3D $1;=20
        $serverip =3D ip2int($server);
        $diff =3D (supernetdistance($myip, $serverip) << 4) + 30000;
        system "fs sp -se $server $diff";
    }
}
close(FSGP);

open(FSGP, "fs gp -vl -nu|") or die "Can't get servers";
while(<FSGP>) {
    if(m/^([0-9\.]+) /) {
        $server =3D $1;=20
        $serverip =3D ip2int($server);
        $diff =3D (supernetdistance($myip, $serverip) << 4) + 20000;
        system "fs sp -vl $server $diff";
    }
}
close(FSGP);
----




Best regards

Emil Assarsson
Sony Ericsson Mobile Communications AB

"The information in this email, and attachment(s) thereto, is strictly conf=
idential and may be legally privileged. It is intended solely for the named=
 recipient(s), and access to this e-mail, or any attachment(s) thereto, by =
anyone else is unauthorized. Violations hereof may result in legal actions.=
 Any attachment(s) to this e-mail has been checked for viruses, but please =
rely on your own virus-checker and procedures. If you contact us by e-mail,=
 we will store your name and address to facilitate communications in the ma=
tter concerned. If you do not consent to us storing your name and address f=
or above stated purpose, please notify the sender promptly. Also, if you ar=
e not the intended recipient please inform the sender by replying to this t=
ransmission, and delete the e-mail, its attachment(s), and any copies of it=
 without, disclosing it."