]> andersk Git - moira.git/blame - incremental/afs/afs_rename.pl
Command line printer manipulation client, and build goo.
[moira.git] / incremental / afs / afs_rename.pl
CommitLineData
2b269eed 1#!/usr/athena/bin/perl
2# Usage: afs_change \
3# oldname oldcell oldtype oldltype oldpath \
4# newname newcell newtype newltype newpath
5
6require "/moira/bin/afs_utils.pl";
7
8die "$0: Incorrect number of arguments\n" if (@ARGV != 10);
9
10($oldname, $oldcell, $oldtype, $oldltype, $oldpath,
11 $newname, $newcell, $newtype, $newltype, $newpath) =
12 @ARGV;
13
14# Modify the paths, as only the read-write paths are used.
15$oldpath =~ s:^/afs/([^.]):/afs/.\1:; # use read-write path
16$newpath =~ s:^/afs/([^.]):/afs/.\1:; # use read-write path
17
18die "Cannot change cells\n" if ($oldcell ne $newcell);
19die "Can only handle AFS and ERR lockers\n"
20 if (($oldtype !~ /^(AFS|ERR)$/) ||
21 ($newtype !~ /^(AFS|ERR)$/));
22
23# Lookup volume type
24($c = $newcell) =~ s/\./_/g;
1f0b7bbc 25$vtype = eval "\$vtypes_${c}{$newltype}";
2b269eed 26die "Cannot handle $newltype volumes\n" unless $vtype;
27$newvname = $vtype . "." . $newname;
28
29if ($oldtype eq "ERR") {
0beb8644 30 # If volume was never unmounted, we don't need to do anything.
31 system("$fs lsm $oldpath > /dev/null");
32 exit(0) if ($? == 0);
33
2b269eed 34 # Lookup volume type for old locker
35 ($c = $oldcell) =~ s/\./_/g;
1f0b7bbc 36 $vtype = eval "\$vtypes_${c}{$oldltype}";
2b269eed 37 die "Cannot handle $oldltype volumes\n" unless $vtype;
38 $oldvname = $vtype . "." . $oldname;
39 $oldvname =~ s/[^-A-Za-z0-9_.]//g; # strip out illegal characters
40
41 if (&check("X" . $oldvname) && &check("Xn." . $oldvname)) {
42 print STDERR "Cannot locate deactivated locker $oldname\n";
43 exit(1) if ($newtype eq "AFS");
44 exit(0);
45 }
46 $newvname = "n." . $newvname if ($oldvname =~ /^Xn\./);
47} else {
48 $prefix = "";
49
50 open(FS, "$fs lsm $oldpath|");
51 chop($_ = <FS>);
52 close(FS);
53 die "Unable to locate locker $oldname\n" if ($?);
54 ($oldvname = $_) =~ s/^.* volume '.(.*)'$/\1/;
55 die "Unusual mountpoint encountered: $oldpath\n" if ($oldvname =~ /[ :]/);
56 $newvname = "n." . $newvname if ($oldvname =~ /^n\./);
57}
58
59$newvname = "X" . $newvname if ($newtype eq "ERR");
60$newvname =~ s/[^-A-Za-z0-9_.]//g; # strip out illegal characters
61
ca227840 62if ($oldbackup && $newvname =~ /^n\./) {
63 system("$vos remove $oldbackup $oldvname.backup -cell $oldcell");
64}
65if ($oldvname ne $newvname) {
66 &run("$vos rename $oldvname $newvname -cell $newcell");
67 push(@clean, "$vos rename $newvname $oldvname -cell $newcell");
68}
bccd18ac 69
70if ($oldtype eq "AFS") {
71 &run("$fs rmm $oldpath");
ca227840 72 push(@clean, "$fs mkm $oldpath $oldvname");
bccd18ac 73 &release_parent($oldpath)
74 if ($newtype ne "AFS" || $oldpath ne $newpath);
75}
76if ($newtype eq "AFS") {
77 &run("$fs mkm $newpath $newvname");
ca227840 78 push(@clean, "$fs rmm $newpath");
b7d3f652 79 $oldfilespath = $newpath . "/OldFiles";
80 open(FS, "$fs lsm $oldfilespath|");
81 chop($_ = <FS>);
82 close(FS);
83 if (! $?) {
84 ($oldofvname = $_) =~ s/^.* volume '.(.*)'$/\1/;
85 $newofvname = $newvname . ".backup";
035df4a5 86 if ($newofvname ne $oldofvname) {
87 &run("$fs sa $newpath sms all");
88 push(@clean, "$fs sa $newpath sms none");
89 &run("$fs rmm $oldfilespath");
90 push(@clean, "$fs mkm $oldfilespath $oldofvname");
91 &run("$fs mkm $oldfilespath $newofvname");
92 push(@clean, "$fs rmm $oldfilespath");
93 &run("$fs sa $newpath sms none");
94 }
b7d3f652 95 }
bccd18ac 96 &release_parent($newpath);
97}
2b269eed 98
ca227840 99&do_releases;
2b269eed 100exit;
101
102
103sub run
104{
105 local(@cmd) = @_;
ca227840 106
2b269eed 107 system("@cmd >/dev/null");
ca227840 108 &fatal("@cmd: FAILED") if ($?);
2b269eed 109 return 0;
110}
111
112
ca227840 113sub fatal
114{
115 local($cmd);
116 $_ = join(' ',@_);
117 s/\n$//;
118
119 while (@clean) {
035df4a5 120 $cmd = pop(@clean);
ca227840 121 warn "$newname: Cleanup failed: $cmd\n" if (system("$cmd"));
122 }
123 die "$newname: $_\n";
124}
125
126
2b269eed 127sub check
128{
129 local($vname) = @_;
130 local(@vos, @a);
5eaef520 131
2b269eed 132 open (VOS, "$vos listvldb -name $vname -cell $oldcell 2>/dev/null|");
133 chop(@vos = <VOS>);
134 close(VOS);
135 return 1 if ($?);
136
137 $oldvname = $vname;
138 @a = split(/\s+/, $vos[$[ + 4]);
139 if (($_ = pop @a) eq "valid") {
140 splice(@vos, 0, 6);
141 for (@vos) {
142 ($oldbackup=$_) =~ s/^.*server (.*) partition (.*) RW .*$/\1 \2/
143 if (/RW Site/);
144 }
145 }
146 return 0;
147}
148
149sub release_parent
150{
151 local($p) = @_;
152
153 $p =~ s:/[^/]+$::;
154 open(FS, "$fs lv $p|") || &fatal("Can't get information about $p");
155 chop($_ = <FS>);
156 close(FS);
157 return if ($?);
158
159 local(@tmp) = (split(/ /,$_));
ca227840 160 push(@vrelease, "$tmp[$#tmp] -cell $newcell");
161}
162
163
164sub do_releases
165{
166 local($lastv) = "";
167 local(@volumes) = sort @vrelease;
168 while (@volumes) {
169 $_ = shift(@volumes);
170 next if ($_ eq $lastv);
171 system("$vos release $_");
172 }
2b269eed 173}
This page took 0.104612 seconds and 5 git commands to generate.