]>
Commit | Line | Data |
---|---|---|
2b269eed | 1 | #!/usr/athena/bin/perl |
2 | # Usage: afs_change \ | |
3 | # oldname oldcell oldtype oldltype oldpath \ | |
4 | # newname newcell newtype newltype newpath | |
5 | ||
6 | require "/moira/bin/afs_utils.pl"; | |
7 | ||
8 | die "$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 | ||
18 | die "Cannot change cells\n" if ($oldcell ne $newcell); | |
19 | die "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; | |
25 | $vtype = eval "\$vtypes_$c{$newltype}"; | |
26 | die "Cannot handle $newltype volumes\n" unless $vtype; | |
27 | $newvname = $vtype . "." . $newname; | |
28 | ||
29 | if ($oldtype eq "ERR") { | |
30 | # Lookup volume type for old locker | |
31 | ($c = $oldcell) =~ s/\./_/g; | |
32 | $vtype = eval "\$vtypes_$c{$oldltype}"; | |
33 | die "Cannot handle $oldltype volumes\n" unless $vtype; | |
34 | $oldvname = $vtype . "." . $oldname; | |
35 | $oldvname =~ s/[^-A-Za-z0-9_.]//g; # strip out illegal characters | |
36 | ||
37 | if (&check("X" . $oldvname) && &check("Xn." . $oldvname)) { | |
38 | print STDERR "Cannot locate deactivated locker $oldname\n"; | |
39 | exit(1) if ($newtype eq "AFS"); | |
40 | exit(0); | |
41 | } | |
42 | $newvname = "n." . $newvname if ($oldvname =~ /^Xn\./); | |
43 | } else { | |
44 | $prefix = ""; | |
45 | ||
46 | open(FS, "$fs lsm $oldpath|"); | |
47 | chop($_ = <FS>); | |
48 | close(FS); | |
49 | die "Unable to locate locker $oldname\n" if ($?); | |
50 | ($oldvname = $_) =~ s/^.* volume '.(.*)'$/\1/; | |
51 | die "Unusual mountpoint encountered: $oldpath\n" if ($oldvname =~ /[ :]/); | |
52 | $newvname = "n." . $newvname if ($oldvname =~ /^n\./); | |
53 | } | |
54 | ||
55 | $newvname = "X" . $newvname if ($newtype eq "ERR"); | |
56 | $newvname =~ s/[^-A-Za-z0-9_.]//g; # strip out illegal characters | |
57 | ||
ca227840 | 58 | if ($oldbackup && $newvname =~ /^n\./) { |
59 | system("$vos remove $oldbackup $oldvname.backup -cell $oldcell"); | |
60 | } | |
61 | if ($oldvname ne $newvname) { | |
62 | &run("$vos rename $oldvname $newvname -cell $newcell"); | |
63 | push(@clean, "$vos rename $newvname $oldvname -cell $newcell"); | |
64 | } | |
bccd18ac | 65 | |
66 | if ($oldtype eq "AFS") { | |
67 | &run("$fs rmm $oldpath"); | |
ca227840 | 68 | push(@clean, "$fs mkm $oldpath $oldvname"); |
bccd18ac | 69 | &release_parent($oldpath) |
70 | if ($newtype ne "AFS" || $oldpath ne $newpath); | |
71 | } | |
72 | if ($newtype eq "AFS") { | |
73 | &run("$fs mkm $newpath $newvname"); | |
ca227840 | 74 | push(@clean, "$fs rmm $newpath"); |
bccd18ac | 75 | &release_parent($newpath); |
76 | } | |
2b269eed | 77 | |
ca227840 | 78 | &do_releases; |
2b269eed | 79 | exit; |
80 | ||
81 | ||
82 | sub run | |
83 | { | |
84 | local(@cmd) = @_; | |
ca227840 | 85 | |
2b269eed | 86 | system("@cmd >/dev/null"); |
ca227840 | 87 | &fatal("@cmd: FAILED") if ($?); |
2b269eed | 88 | return 0; |
89 | } | |
90 | ||
91 | ||
ca227840 | 92 | sub fatal |
93 | { | |
94 | local($cmd); | |
95 | $_ = join(' ',@_); | |
96 | s/\n$//; | |
97 | ||
98 | while (@clean) { | |
99 | $cmd = shift(@clean); | |
100 | warn "$newname: Cleanup failed: $cmd\n" if (system("$cmd")); | |
101 | } | |
102 | die "$newname: $_\n"; | |
103 | } | |
104 | ||
105 | ||
2b269eed | 106 | sub check |
107 | { | |
108 | local($vname) = @_; | |
109 | local(@vos, @a); | |
110 | ||
111 | open (VOS, "$vos listvldb -name $vname -cell $oldcell 2>/dev/null|"); | |
112 | chop(@vos = <VOS>); | |
113 | close(VOS); | |
114 | return 1 if ($?); | |
115 | ||
116 | $oldvname = $vname; | |
117 | @a = split(/\s+/, $vos[$[ + 4]); | |
118 | if (($_ = pop @a) eq "valid") { | |
119 | splice(@vos, 0, 6); | |
120 | for (@vos) { | |
121 | ($oldbackup=$_) =~ s/^.*server (.*) partition (.*) RW .*$/\1 \2/ | |
122 | if (/RW Site/); | |
123 | } | |
124 | } | |
125 | return 0; | |
126 | } | |
127 | ||
128 | sub release_parent | |
129 | { | |
130 | local($p) = @_; | |
131 | ||
132 | $p =~ s:/[^/]+$::; | |
133 | open(FS, "$fs lv $p|") || &fatal("Can't get information about $p"); | |
134 | chop($_ = <FS>); | |
135 | close(FS); | |
136 | return if ($?); | |
137 | ||
138 | local(@tmp) = (split(/ /,$_)); | |
ca227840 | 139 | push(@vrelease, "$tmp[$#tmp] -cell $newcell"); |
140 | } | |
141 | ||
142 | ||
143 | sub do_releases | |
144 | { | |
145 | local($lastv) = ""; | |
146 | local(@volumes) = sort @vrelease; | |
147 | while (@volumes) { | |
148 | $_ = shift(@volumes); | |
149 | next if ($_ eq $lastv); | |
150 | system("$vos release $_"); | |
151 | } | |
2b269eed | 152 | } |