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 really
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 setserverprefs.
# 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 = shift();
$length = 0;
while($bits) {
$bits >>= 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 = shift();
$ip2 = shift();
$xordiff = $ip1 ^ $ip2; # Mask out the shared network bits
return usedbitlength($xordiff);
}
sub ip2int($)
{
return unpack('N',inet_aton(shift()));
};
# Get IP
$myip = "";
open('IFCONFIG',"ifconfig eth0|") or die "Can't use ifconfig";
while(<IFCONFIG>) {
if(m/inet addr:([0-9\.]+) /) {
$myipstr = $1;
last;
}
}
die "Can't find this machines ip address" if $myipstr eq "";
$myip = ip2int($myipstr);
# Sort servers
open(FSGP, "fs gp -nu|") or die "Can't get servers";
while(<FSGP>) {
if(m/^([0-9\.]+) /) {
$server = $1;
$serverip = ip2int($server);
$diff = (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 = $1;
$serverip = ip2int($server);
$diff = (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
confidential 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 matter
concerned. If you do not consent to us storing your name and address for above
stated purpose, please notify the sender promptly. Also, if you are not the
intended recipient please inform the sender by replying to this transmission,
and delete the e-mail, its attachment(s), and any copies of it without,
disclosing it."
_______________________________________________
OpenAFS-info mailing list
[email protected]
https://lists.openafs.org/mailman/listinfo/openafs-info