]>
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") { | |
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; | |
36 | $vtype = eval "\$vtypes_$c{$oldltype}"; | |
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 | 62 | if ($oldbackup && $newvname =~ /^n\./) { |
63 | system("$vos remove $oldbackup $oldvname.backup -cell $oldcell"); | |
64 | } | |
65 | if ($oldvname ne $newvname) { | |
66 | &run("$vos rename $oldvname $newvname -cell $newcell"); | |
67 | push(@clean, "$vos rename $newvname $oldvname -cell $newcell"); | |
68 | } | |
bccd18ac | 69 | |
70 | if ($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 | } | |
76 | if ($newtype eq "AFS") { | |
77 | &run("$fs mkm $newpath $newvname"); | |
ca227840 | 78 | push(@clean, "$fs rmm $newpath"); |
bccd18ac | 79 | &release_parent($newpath); |
80 | } | |
2b269eed | 81 | |
ca227840 | 82 | &do_releases; |
2b269eed | 83 | exit; |
84 | ||
85 | ||
86 | sub run | |
87 | { | |
88 | local(@cmd) = @_; | |
ca227840 | 89 | |
2b269eed | 90 | system("@cmd >/dev/null"); |
ca227840 | 91 | &fatal("@cmd: FAILED") if ($?); |
2b269eed | 92 | return 0; |
93 | } | |
94 | ||
95 | ||
ca227840 | 96 | sub fatal |
97 | { | |
98 | local($cmd); | |
99 | $_ = join(' ',@_); | |
100 | s/\n$//; | |
101 | ||
102 | while (@clean) { | |
103 | $cmd = shift(@clean); | |
104 | warn "$newname: Cleanup failed: $cmd\n" if (system("$cmd")); | |
105 | } | |
106 | die "$newname: $_\n"; | |
107 | } | |
108 | ||
109 | ||
2b269eed | 110 | sub check |
111 | { | |
112 | local($vname) = @_; | |
113 | local(@vos, @a); | |
5eaef520 | 114 | |
2b269eed | 115 | open (VOS, "$vos listvldb -name $vname -cell $oldcell 2>/dev/null|"); |
116 | chop(@vos = <VOS>); | |
117 | close(VOS); | |
118 | return 1 if ($?); | |
119 | ||
120 | $oldvname = $vname; | |
121 | @a = split(/\s+/, $vos[$[ + 4]); | |
122 | if (($_ = pop @a) eq "valid") { | |
123 | splice(@vos, 0, 6); | |
124 | for (@vos) { | |
125 | ($oldbackup=$_) =~ s/^.*server (.*) partition (.*) RW .*$/\1 \2/ | |
126 | if (/RW Site/); | |
127 | } | |
128 | } | |
129 | return 0; | |
130 | } | |
131 | ||
132 | sub release_parent | |
133 | { | |
134 | local($p) = @_; | |
135 | ||
136 | $p =~ s:/[^/]+$::; | |
137 | open(FS, "$fs lv $p|") || &fatal("Can't get information about $p"); | |
138 | chop($_ = <FS>); | |
139 | close(FS); | |
140 | return if ($?); | |
141 | ||
142 | local(@tmp) = (split(/ /,$_)); | |
ca227840 | 143 | push(@vrelease, "$tmp[$#tmp] -cell $newcell"); |
144 | } | |
145 | ||
146 | ||
147 | sub do_releases | |
148 | { | |
149 | local($lastv) = ""; | |
150 | local(@volumes) = sort @vrelease; | |
151 | while (@volumes) { | |
152 | $_ = shift(@volumes); | |
153 | next if ($_ eq $lastv); | |
154 | system("$vos release $_"); | |
155 | } | |
2b269eed | 156 | } |