#!/bin/rc # attaches to hubfs and runs on storage node rfork spawnmax=`{cat /usr/grid/spawnmax} if(~ $#spawnmax 0) spawnmax=5 if(! test -e /usr/grid/stononce) echo 1009 >usr/grid/stononce nonce = `{cat /usr/grid/stononce} if(! test -e /usr/grid/nextstoport) echo 20000 >/usr/grid/nextstoport ndb/ipquery sys $sysname ip |sed 's/ip=127.0.0.1//' >/usr/grid/myip . /usr/grid/myip scorefile=/n/9fat/scorenames if(! test -e $scorefile) mount /srv/fatsrv /n/9fat while(usercmd=`{read}){ reqcmd=() srvowner=() username=$usercmd(1) echo $username $usercmd >>/usr/grid/stolog.$pid if(test -e /srv/$username.req){ srvowner=`{ls -l /srv/$username.req |awk '{print $4}'} if(~ $srvowner $username){ echo reqcmd equals cat /srv/$username.req >>/usr/grid/stolog.$pid reqcmd=`{cat /srv/$username.req} echo $reqcmd >>/usr/grid/$username.reqlog } if not echo user id error >[1=2] rm /srv/$username.req } if(! ~ $username $reqcmd(1)) reqcmd=(fail fail) usercmd=$reqcmd(2-) switch($usercmd){ case spawn* if(~ $#usercmd 2){ targetfs=$usercmd(2) if(! test -e /usr/grid/spawncount) echo 0 >/usr/grid/spawncount spawncount=`{cat /usr/grid/spawncount} if(test -e /srv/$targetfs^fossil){ echo that root is already being served from this storage node >[1=2] echo use save to clone it to a new name if desired >[1=2] } if not if(! ~ $spawncount $spawnmax){ usercheck=`{ndb/query -f /n/9fat/scorenames -a scorename $targetfs user |grep $username} if(~ $usercheck $username){ echo init fossil...waiting for 10... stoport=`{cat /usr/grid/nextstoport} echo $username spawnroot -l $stoport $targetfs >>/usr/grid/stolog.$pid if(~ $usercmd spawndisk*){ spawnroot -d -l $stoport $targetfs & } if(! ~ $usercmd spawndisk*){ spawnroot -l $stoport $targetfs & } sleep 3 if(! test -e /srv/$targetfs^fossil) sleep 3 if(! test -e /srv/$targetfs^fossil) sleep 4 if(test -e /srv/$targetfs^fossil){ spawncount=`{echo $spawncount '+ 1' |hoc} echo $spawncount >/usr/grid/spawncount if(! test -d /usr/grid/$username) mkdir /usr/grid/$username echo 'fetch tcp!'^$ip^'!'^$stoport $targetfs $username echo 'fetch tcp!'^$ip^'!'^$stoport $targetfs $username >/usr/grid/$username/$targetfs echo 'fetch tcp!'^$ip^'!'^$stoport $targetfs $username >>/n/g/cpu.in stoport=`{echo $stoport '+ 2' |hoc} echo $stoport >/usr/grid/nextstoport } if not echo $targetfs spawn failed on storage server >[1=2] } if not echo $targetfs not found for $username >[1=2] } if not echo spawn limit reached >[1=2] } if not echo spawn SCORENAME >[1=2] case save* if(~ $#usercmd 3){ echo savesnap -u $username $usercmd(2) $usercmd(3) $nonce >>/usr/grid/stolog.$pid if(! ~ $usercmd savedisk*) savesnap -u $username -r /srv/^$usercmd(2) -s /srv/^$usercmd(2)^fscons $usercmd(3)^.^$nonce & if(~ $usercmd savedisk*) savesnap -u $username -f `{cat /usr/grid/^$usercmd(2)} -s /srv/^$usercmd(2)^fscons $usercmd(3)^.^$nonce & nonce=`{echo $nonce ' + 100 ' |hoc} echo $nonce >/usr/grid/stononce } if not echo save OLDNAME NEWNAME >[1=2] case invite* if(~ $#usercmd 3){ inviteduser=$usercmd(2) targetfs=$usercmd(3) if(test -e /usr/grid/$username/$targetfs){ echo uname $inviteduser $inviteduser >>/srv/$targetfs^fscons echo 'uname sys +'^$inviteduser >>/srv/$targetfs^fscons echo 'uname adm +'^$inviteduser >>/srv/$targetfs^fscons echo 'uname upas +'^$inviteduser >>/srv/$targetfs^fscons sleep 1 echo savesnap -u $inviteduser $targetfs $targetfs^$inviteduser $nonce >>/usr/grid/stolog.$pid savesnap -u $inviteduser -r /srv/$targetfs -s /srv/$targetfs^fscons $targetfs^$inviteduser^.^$nonce & nonce=`{echo $nonce ' + 100 ' |hoc} echo $nonce >/usr/grid/stononce } if not echo $targetfs not owned by $username >[1=2] } if not echo invite USER FSNAME >[1=2] case boom* if(~ $#usercmd 2){ targetfs=$usercmd(2) if(test -e /usr/grid/$username/$targetfs){ echo boom $targetfs >>/n/g/cpu.in sleep 1 . /usr/grid/kill.$targetfs rm /usr/grid/$targetfs rm /usr/grid/$username/$targetfs rm /usr/grid/kill.$targetfs echo $targetfs BOOMed } if not echo $targetfs not owned by $username >[1=2] } if not echo boom FSNAME >[1=2] case status echo active grid namespaces for $username for(i in `{ls /usr/grid/$username}){ basename $i echo serving on cpu port `{cat $i |sed 's/.*!.*!//g' |sed 's/ .*/ \+1/g' |hoc} } case scores* if(! test -e /n/9fat/scorenames) mount /srv/fatsrv /n/9fat if(~ $#usercmd 2) ndb/query -a -f /n/9fat/scorenames user $username scorename |grep $usercmd(2) if not ndb/query -a -f /n/9fat/scorenames user $username scorename case fail* echo command authorization failed case * echo unknown command >[1=2] } }