Import Upstream version 1.8.5
[hcoop/debian/openafs.git] / src / tests / OpenAFS / vos.pm
1 # CMUCS AFStools
2 # Copyright (c) 1996, Carnegie Mellon University
3 # All rights reserved.
4 #
5 # See CMU_copyright.ph for use and distribution information
6 #
7 #: * vos.pm - Wrappers around VOS commands (volume maintenance)
8 #: * This module provides wrappers around the various volserver and VLDB
9 #: * commands, giving them a nice perl-based interface. Someday, they might
10 #: * talk to the servers directly instead of using 'vos', but not anytime
11 #: * soon.
12 #:
13
14 package OpenAFS::vos;
15 use OpenAFS::CMU_copyright;
16 use OpenAFS::util qw(:DEFAULT :afs_internal);
17 use OpenAFS::wrapper;
18 use Exporter;
19
20 $VERSION = '';
21 $VERSION = '1.00';
22 @ISA = qw(Exporter);
23 @EXPORT = qw(&AFS_vos_create &AFS_vos_listvldb
24 &AFS_vos_remove &AFS_vos_delentry
25 &AFS_vos_rename &AFS_vos_syncserv
26 &AFS_vos_move &AFS_vos_syncvldb
27 &AFS_vos_examine &AFS_vos_lock
28 &AFS_vos_addsite &AFS_vos_unlock
29 &AFS_vos_remsite &AFS_vos_unlockvldb
30 &AFS_vos_release &AFS_vos_changeaddr
31 &AFS_vos_backup &AFS_vos_listpart
32 &AFS_vos_backupsys &AFS_vos_partinfo
33 &AFS_vos_dump &AFS_vos_listvol
34 &AFS_vos_restore &AFS_vos_zap
35 &AFS_vos_status);
36
37 $vos_err_parse = [ 'Error in vos (.*) command', '-(.*)' ];
38
39
40 #: AFS_vos_create($vol, $server, $part, [$quota], [$cell])
41 #: Create a volume with name $vol
42 #: The server name ($server) may be a hostname or IP address
43 #: The partition may be a partition name (/vicepx), letter (x), or number (24)
44 #: If specified, use $quota for the initial quota instead of 5000 blocks.
45 #: If specified, work in $cell instead of the default cell.
46 #: On success, return the volume ID.
47 #:
48 $AFS_Help{vos_create} = '$vol, $server, $part, [$quota], [$cell] => $volid';
49 sub AFS_vos_create {
50 my($vol, $server, $part, $quota, $cell) = @_;
51 my(@args, $id);
52
53 @args = ('create', '-name', $vol, '-server', $server, '-part', $part);
54 push(@args, '-maxquota', $quota) if ($quota ne '');
55 push(@args, '-noauth') if ($AFS_Parms{'authlvl'} == 0);
56 push(@args, '-localauth') if ($AFS_Parms{'authlvl'} == 2);
57 push(@args, '-verbose') if ($AFS_Parms{'vostrace'} > 1);
58 push(@args, '-cell', $cell ? $cell : $AFS_Parms{'cell'});
59 &wrapper('vos', \@args,
60 [$vos_err_parse,
61 ['^Volume (\d+) created on partition \/vicep\S+ of \S+', \$id ],
62 $AFS_Parms{'vostrace'} ? ([ '', '?']) : () ]);
63 $id;
64 }
65
66
67 #: AFS_vos_remove($vol, $server, $part, [$cell])
68 #: Remove the volume $vol from the server and partition specified by $server and
69 #: $part. If appropriate, also remove the corresponding VLDB entry.
70 #: If specified, work in $cell instead of the default cell.
71 #: On success, return 1.
72 #:
73 $AFS_Help{vos_remove} = '$vol, $server, $part, [$cell] => Success?';
74 sub AFS_vos_remove {
75 my($vol, $server, $part, $cell) = @_;
76 my(@args);
77
78 @args = ('remove', '-id', $vol, '-server', $server, '-part', $part);
79 push(@args, '-noauth') if ($AFS_Parms{'authlvl'} == 0);
80 push(@args, '-localauth') if ($AFS_Parms{'authlvl'} == 2);
81 push(@args, '-verbose') if ($AFS_Parms{'vostrace'} > 1);
82 push(@args, '-cell', $cell ? $cell : $AFS_Parms{'cell'});
83 &wrapper('vos', \@args,
84 [$vos_err_parse,
85 $AFS_Parms{'vostrace'} ? ([ '', '?']) : () ]);
86 1;
87 }
88
89
90 #: AFS_vos_rename($old, $new, [$cell])
91 #: Rename the volume $old to have the name $new.
92 #: If specified, work in $cell instead of the default cell.
93 #: On success, return 1.
94 #:
95 $AFS_Help{vos_rename} = '$old, $new, [$cell] => Success?';
96 sub AFS_vos_rename {
97 my($old, $new, $cell) = @_;
98 my(@args);
99
100 @args = ('rename', '-oldname', $old, '-newname', $new);
101 push(@args, '-noauth') if ($AFS_Parms{'authlvl'} == 0);
102 push(@args, '-localauth') if ($AFS_Parms{'authlvl'} == 2);
103 push(@args, '-verbose') if ($AFS_Parms{'vostrace'} > 1);
104 push(@args, '-cell', $cell ? $cell : $AFS_Parms{'cell'});
105 &wrapper('vos', \@args,
106 [$vos_err_parse,
107 $AFS_Parms{'vostrace'} ? ([ '', '?']) : () ]);
108 1;
109 }
110
111
112 #: AFS_vos_move($vol, $fromsrv, $frompart, $tosrv, $topart, [$cell])
113 #: Move the volume specified by $vol.
114 #: The source location is specified by $fromsrv and $frompart.
115 #: The destination location is specified by $tosrv and $topart.
116 #: If specified, work in $cell instead of the default cell.
117 #: On success, return 1.
118
119 #:
120 $AFS_Help{vos_move} = '$vol, $fromsrv, $frompart, $tosrv, $topart, [$cell] => Success?';
121 sub AFS_vos_move {
122 my($vol, $fromsrv, $frompart, $tosrv, $topart, $cell) = @_;
123 my(@args);
124
125 @args = ('move', '-id', $vol,
126 '-fromserver', $fromsrv, '-frompartition', $frompart,
127 '-toserver', $tosrv, '-topartition', $topart);
128 push(@args, '-noauth') if ($AFS_Parms{'authlvl'} == 0);
129 push(@args, '-localauth') if ($AFS_Parms{'authlvl'} == 2);
130 push(@args, '-verbose') if ($AFS_Parms{'vostrace'} > 1);
131 push(@args, '-cell', $cell ? $cell : $AFS_Parms{'cell'});
132 &wrapper('vos', \@args,
133 [$vos_err_parse,
134 $AFS_Parms{'vostrace'} ? ([ '', '?']) : () ]);
135 1;
136 }
137
138
139 #: AFS_vos_examine($vol, [$cell])
140 #: Examine the volume $vol, and return information about it.
141 #: If specified, operate in cell $cell instead of the default cell.
142 #: On success, return an associative array with some or all of the following:
143 #: - name Name of this volume
144 #: - id ID of this volume
145 #: - kind Kind of volume (RW, RO, or BK)
146 #: - inuse Disk space in use
147 #: - state On-line or Off-line
148 #: - maxquota Maximum disk usage quota
149 #: - minquota Minimum disk usage quota (optional)
150 #: - stamp_create Time when volume was originally created
151 #: - stamp_update Time volume was last modified
152 #: - stamp_backup Time backup volume was cloned, or 'Never'
153 #: - stamp_copy Time this copy of volume was made
154 #: - backup_flag State of automatic backups: empty or 'disabled'
155 #: - dayuse Number of accesses in the past day
156 #: - rwid ID of read-write volume (even if this is RO or BK)
157 #: - roid ID of read-only volume (even if this is RW or BK)
158 #: - bkid ID of backup volume (even if this is RW or RO)
159 #: - rwserv Name of server where read/write volume is
160 #: - rwpart Name of partition where read/write volume is
161 #: - rosites Reference to a list of read-only sites. Each site, in turn,
162 #: is a reference to a two-element list (server, part).
163 #:
164 $AFS_Help{vos_examine} = '$vol, [$cell] => %info';
165 sub AFS_vos_examine {
166 my($vol, $cell) = @_;
167 my(%result, @args, @rosites);
168
169 @args = ('examine', '-id', $vol);
170 push(@args, '-noauth') if ($AFS_Parms{'authlvl'} == 0);
171 push(@args, '-localauth') if ($AFS_Parms{'authlvl'} == 2);
172 push(@args, '-verbose') if ($AFS_Parms{'vostrace'} > 2);
173 push(@args, '-cell', $cell ? $cell : $AFS_Parms{'cell'});
174 %result = &wrapper('vos', \@args,
175 [$vos_err_parse,
176 ['^(\S+)\s*(\d+)\s*(RW|RO|BK)\s*(\d+)\s*K\s*([-\w]+)', 'name', 'id', 'kind', 'inuse', 'state'],
177 ['MaxQuota\s*(\d+)\s*K', 'maxquota' ],
178 ['MinQuota\s*(\d+)\s*K', 'minquota' ],
179 ['Creation\s*(.*\S+)', 'stamp_create' ],
180 ['Last Update\s*(.*\S+)', 'stamp_update' ],
181 ['Backup\s+([^\d\s].*\S+)', 'stamp_backup' ],
182 ['Copy\s*(.*\S+)', 'stamp_copy' ],
183 ['Automatic backups are (disabled) for this volume', 'backup_flag' ],
184 ['(\d+) accesses in the past day', 'dayuse' ],
185 ['RWrite\:\s*(\d+)', 'rwid' ],
186 ['ROnly\:\s*(\d+)', 'roid' ],
187 ['Backup\:\s*(\d+)', 'bkid' ],
188 ['server (\S+) partition /vicep(\S+) RW Site', 'rwserv', 'rwpart'],
189 ['server (\S+) partition /vicep(\S+) RO Site', sub {
190 push(@rosites, [$_[0], $_[1]]);
191 }],
192 ($AFS_Parms{'vostrace'} > 2) ? ([ '', '?']) : () ]);
193
194 $result{'rosites'} = \@rosites if (@rosites);
195 %result;
196 }
197
198
199
200 #: AFS_vos_addsite($vol, $server, $part, [$cell])
201 #: Add a replication site for volume $vol
202 #: The server name ($server) may be a hostname or IP address
203 #: The partition may be a partition name (/vicepx), letter (x), or number (24)
204 #: If specified, work in $cell instead of the default cell.
205 #: On success, return 1.
206 #:
207 $AFS_Help{vos_addsite} = '$vol, $server, $part, [$cell] => Success?';
208 sub AFS_vos_addsite {
209 my($vol, $server, $part, $cell) = @_;
210 my(@args);
211
212 @args = ('addsite', '-id', $vol, '-server', $server, '-part', $part);
213 push(@args, '-noauth') if ($AFS_Parms{'authlvl'} == 0);
214 push(@args, '-localauth') if ($AFS_Parms{'authlvl'} == 2);
215 push(@args, '-verbose') if ($AFS_Parms{'vostrace'} > 1);
216 push(@args, '-cell', $cell ? $cell : $AFS_Parms{'cell'});
217 &wrapper('vos', \@args,
218 [$vos_err_parse,
219 $AFS_Parms{'vostrace'} ? ([ '', '?']) : () ]);
220 1;
221 }
222
223
224 #: AFS_vos_remsite($vol, $server, $part, [$cell])
225 #: Remove a replication site for volume $vol
226 #: The server name ($server) may be a hostname or IP address
227 #: The partition may be a partition name (/vicepx), letter (x), or number (24)
228 #: If specified, work in $cell instead of the default cell.
229 #: On success, return 1.
230 #:
231 $AFS_Help{vos_remsite} = '$vol, $server, $part, [$cell] => Success?';
232 sub AFS_vos_remsite {
233 my($vol, $server, $part, $cell) = @_;
234 my(@args);
235
236 @args = ('remsite', '-id', $vol, '-server', $server, '-part', $part);
237 push(@args, '-noauth') if ($AFS_Parms{'authlvl'} == 0);
238 push(@args, '-localauth') if ($AFS_Parms{'authlvl'} == 2);
239 push(@args, '-verbose') if ($AFS_Parms{'vostrace'} > 1);
240 push(@args, '-cell', $cell ? $cell : $AFS_Parms{'cell'});
241 &wrapper('vos', \@args,
242 [$vos_err_parse,
243 $AFS_Parms{'vostrace'} ? ([ '', '?']) : () ]);
244 1;
245 }
246
247
248 #: AFS_vos_release($vol, [$cell], [$force])
249 #: Release the volume $vol.
250 #: If $force is specified and non-zero, use the "-f" switch.
251 #: If specified, work in $cell instead of the default cell.
252 #: On success, return 1.
253 #:
254 $AFS_Help{vos_release} = '$vol, [$cell], [$force] => Success?';
255 sub AFS_vos_release {
256 my($vol, $cell, $force) = @_;
257 my(@args);
258
259 @args = ('release', '-id', $vol);
260 push(@args, '-f') if ($force);
261 push(@args, '-noauth') if ($AFS_Parms{'authlvl'} == 0);
262 push(@args, '-localauth') if ($AFS_Parms{'authlvl'} == 2);
263 push(@args, '-verbose') if ($AFS_Parms{'vostrace'} > 1);
264 push(@args, '-cell', $cell ? $cell : $AFS_Parms{'cell'});
265 &wrapper('vos', \@args,
266 [$vos_err_parse,
267 $AFS_Parms{'vostrace'} ? ([ '', '?']) : () ]);
268 1;
269 }
270
271
272 #: AFS_vos_backup($vol, [$cell])
273 #: Make a backup of the volume $vol.
274 #: If specified, work in $cell instead of the default cell.
275 #: On success, return 1.
276 #:
277 $AFS_Help{vos_backup} = '$vol, [$cell] => Success?';
278 sub AFS_vos_backup {
279 my($vol, $cell) = @_;
280 my(@args);
281
282 @args = ('backup', '-id', $vol);
283 push(@args, '-noauth') if ($AFS_Parms{'authlvl'} == 0);
284 push(@args, '-localauth') if ($AFS_Parms{'authlvl'} == 2);
285 push(@args, '-verbose') if ($AFS_Parms{'vostrace'} > 1);
286 push(@args, '-cell', $cell ? $cell : $AFS_Parms{'cell'});
287 &wrapper('vos', \@args,
288 [$vos_err_parse,
289 $AFS_Parms{'vostrace'} ? ([ '', '?']) : () ]);
290 1;
291 }
292
293
294 #: AFS_vos_backupsys([$prefix], [$server, [$part]], [$exclude], [$cell])
295 #: Do en masse backups of AFS volumes.
296 #: If specified, match only volumes whose names begin with $prefix
297 #: If specified, limit work to the $server and, if given, $part.
298 #: If $exclude is specified and non-zero, backup only volumes NOT matched.
299 #: If specified, work in $cell instead of the default cell.
300 #: On success, return 1.
301 #:
302 $AFS_Help{vos_backupsys} = '[$prefix], [$server, [$part]], [$exclude], [$cell] => Success?';
303 sub AFS_vos_backupsys {
304 my($prefix, $server, $part, $exclude, $cell) = @_;
305 my(@args);
306
307 @args = ('backupsys');
308 push(@args, '-prefix', $prefix) if ($prefix);
309 push(@args, '-server', $server) if ($server);
310 push(@args, '-partition', $part) if ($server && $part);
311 push(@args, '-exclude') if ($exclude);
312 push(@args, '-noauth') if ($AFS_Parms{'authlvl'} == 0);
313 push(@args, '-localauth') if ($AFS_Parms{'authlvl'} == 2);
314 push(@args, '-verbose') if ($AFS_Parms{'vostrace'} > 1);
315 push(@args, '-cell', $cell ? $cell : $AFS_Parms{'cell'});
316 &wrapper('vos', \@args,
317 [$vos_err_parse,
318 $AFS_Parms{'vostrace'} ? ([ '', '?']) : () ]);
319 1;
320 }
321
322
323 #: AFS_vos_dump($vol, [$time], [$file], [$cell])
324 #: Dump the volume $vol
325 #: If specified, do an incremental dump since $time instead of a full dump.
326 #: If specified, dump to $file instead of STDOUT
327 #: If specified, work in $cell instead of the default cell.
328 #: On success, return 1.
329 #:
330 $AFS_Help{vos_dump} = '$vol, [$time], [$file], [$cell] => Success?';
331 sub AFS_vos_dump {
332 my($vol, $time, $file, $cell) = @_;
333 my(@args);
334
335 @args = ('dump', '-id', $vol);
336 push(@args, '-time', ($time ? $time : 0));
337 push(@args, '-file', $file) if ($file);
338 push(@args, '-noauth') if ($AFS_Parms{'authlvl'} == 0);
339 push(@args, '-localauth') if ($AFS_Parms{'authlvl'} == 2);
340 push(@args, '-verbose') if ($AFS_Parms{'vostrace'} > 1);
341 push(@args, '-cell', $cell ? $cell : $AFS_Parms{'cell'});
342 &wrapper('vos', \@args,
343 [$vos_err_parse,
344 $AFS_Parms{'vostrace'} ? ([ '', '?']) : () ],
345 { pass_stdout => !$file });
346 1;
347 }
348
349
350 #: AFS_vos_restore($vol, $server, $part, [$file], [$id], [$owmode], [$cell])
351 #: Restore the volume $vol to partition $part on server $server.
352 #: If specified, restore from $file instead of STDIN
353 #: If specified, use the volume ID $id
354 #: If specified, $owmode must be 'abort', 'full', or 'incremental', and
355 #: indicates what to do if the volume exists.
356 #: If specified, work in $cell instead of the default cell.
357 #: On success, return 1.
358 #:
359 $AFS_Help{vos_restore} = '$vol, $server, $part, [$file], [$id], [$owmode], [$cell] => Success?';
360 sub AFS_vos_restore {
361 my($vol, $server, $part, $file, $id, $owmode, $cell) = @_;
362 my(@args);
363
364 @args = ('restore', '-name', $vol, '-server', $server, '-partition', $part);
365 push(@args, '-file', $file) if ($file);
366 push(@args, '-id', $id) if ($id);
367 push(@args, '-overwrite', $owmode) if ($owmode);
368 push(@args, '-noauth') if ($AFS_Parms{'authlvl'} == 0);
369 push(@args, '-localauth') if ($AFS_Parms{'authlvl'} == 2);
370 push(@args, '-verbose') if ($AFS_Parms{'vostrace'} > 1);
371 push(@args, '-cell', $cell ? $cell : $AFS_Parms{'cell'});
372 &wrapper('vos', \@args,
373 [$vos_err_parse,
374 $AFS_Parms{'vostrace'} ? ([ '', '?']) : () ]);
375 1;
376 }
377
378
379 #: AFS_vos_listvldb([$vol], [$server, [$part]], [$locked], [$cell])
380 #: Get a list of volumes in the VLDB.
381 #: If specified, list only the volume $vol
382 #: If specified, list only volumes on the server $server.
383 #: If specified with $server, list only volumes on the partition $part.
384 #: If $locked is specified and nonzero, list only locked VLDB entries
385 #: If specified, work in $cell instead of the default cell.
386 #: On success, return an associative array whose keys are names of volumes
387 #: on the specified server, and each of whose values is an associative
388 #: array describing the corresponding volume, containing some or all of
389 #: these elements:
390 #: - name Name of this volume (same as key)
391 #: - rwid ID of read-write volume (even if this is RO or BK)
392 #: - roid ID of read-only volume (even if this is RW or BK)
393 #: - bkid ID of backup volume (even if this is RW or RO)
394 #: - locked Empty or LOCKED to indicate VLDB entry is locked
395 #: - rwserv Name of server where read/write volume is
396 #: - rwpart Name of partition where read/write volume is
397 #: - rosites Reference to a list of read-only sites. Each site, in turn,
398 #: is a reference to a two-element list (server, part).
399 #:
400 $AFS_Help{vos_listvldb} = '[$vol], [$server, [$part]], [$locked], [$cell] => %vols';
401 sub AFS_vos_listvldb {
402 my($vol, $server, $part, $locked, $cell) = @_;
403 my(%finres, %vlist, @rosites);
404
405 @args = ('listvldb');
406 push(@args, '-name', $vol) if ($vol);
407 push(@args, '-server', $server) if ($server);
408 push(@args, '-partition', $part) if ($part && $server);
409 push(@args, '-locked') if ($locked);
410 push(@args, '-noauth') if ($AFS_Parms{'authlvl'} == 0);
411 push(@args, '-localauth') if ($AFS_Parms{'authlvl'} == 2);
412 push(@args, '-verbose') if ($AFS_Parms{'vostrace'} > 2);
413 push(@args, '-cell', $cell ? $cell : $AFS_Parms{'cell'});
414 %finres = &wrapper('vos', \@args,
415 [$vos_err_parse,
416 ['^(VLDB|Total) entries', '.'],
417 ['^(\S+)', sub {
418 my(%vinfo) = %OpenAFS::wrapper::result;
419
420 if ($vinfo{name}) {
421 $vinfo{rosites} = [@rosites] if (@rosites);
422 $vlist{$vinfo{name}} = \%vinfo;
423
424 @rosites = ();
425 %OpenAFS::wrapper::result = ();
426 }
427 }],
428 ['^(\S+)', 'name' ],
429 ['RWrite\:\s*(\d+)', 'rwid' ],
430 ['ROnly\:\s*(\d+)', 'roid' ],
431 ['Backup\:\s*(\d+)', 'bkid' ],
432 ['Volume is currently (LOCKED)', 'locked' ],
433 ['server (\S+) partition /vicep(\S+) RW Site', 'rwserv', 'rwpart'],
434 ['server (\S+) partition /vicep(\S+) RO Site', sub {
435 push(@rosites, [$_[0], $_[1]]);
436 }],
437 ($AFS_Parms{'vostrace'} > 2) ? ([ '', '?']) : () ]);
438
439 if ($finres{name}) {
440 $finres{rosites} = [@rosites] if (@rosites);
441 $vlist{$finres{name}} = \%finres;
442 }
443 %vlist;
444 }
445
446
447
448 #: AFS_vos_delentry($vol, [$cell])
449 #: Delete the VLDB entry for the volume $vol
450 #: If specified, work in $cell instead of the default cell.
451 #: On success, return 1.
452 #:
453 $AFS_Help{vos_delentry} = '$vol, [$cell] => Success?';
454 sub AFS_vos_delentry {
455 my($vol, $cell) = @_;
456 my(@args);
457
458 @args = ('delentry', '-id', $vol);
459 push(@args, '-noauth') if ($AFS_Parms{'authlvl'} == 0);
460 push(@args, '-localauth') if ($AFS_Parms{'authlvl'} == 2);
461 push(@args, '-verbose') if ($AFS_Parms{'vostrace'} > 1);
462 push(@args, '-cell', $cell ? $cell : $AFS_Parms{'cell'});
463 &wrapper('vos', \@args,
464 [$vos_err_parse,
465 $AFS_Parms{'vostrace'} ? ([ '', '?']) : () ]);
466 1;
467 }
468
469
470 #: AFS_vos_syncserv($server, [$part], [$cell], [$force])
471 #: Synchronize the server $server with the VLDB
472 #: If specified, synchronize only partition $part
473 #: If specified, work in $cell instead of the default cell
474 #: If $force is specified, force updates to occur
475 #: On success, return 1.
476 #:
477 $AFS_Help{vos_syncserv} = '$server, [$part], [$cell], [$force] => Success?';
478 sub AFS_vos_syncserv {
479 my($server, $part, $cell, $force) = @_;
480 my(@args);
481
482 @args = ('syncserv', '-server', $server);
483 push(@args, '-partition', $part) if ($part);
484 push(@args, '-force') if ($force);
485 push(@args, '-noauth') if ($AFS_Parms{'authlvl'} == 0);
486 push(@args, '-localauth') if ($AFS_Parms{'authlvl'} == 2);
487 push(@args, '-verbose') if ($AFS_Parms{'vostrace'} > 1);
488 push(@args, '-cell', $cell ? $cell : $AFS_Parms{'cell'});
489 &wrapper('vos', \@args,
490 [$vos_err_parse,
491 $AFS_Parms{'vostrace'} ? ([ '', '?']) : () ]);
492 1;
493 }
494
495
496 #: AFS_vos_syncvldb($server, [$part], [$cell], [$force])
497 #: Synchronize the VLDB with server $server
498 #: If specified, synchronize only partition $part
499 #: If specified, work in $cell instead of the default cell
500 #: If $force is specified, force updates to occur
501 #: On success, return 1.
502 #:
503 $AFS_Help{vos_syncvldb} = '$server, [$part], [$cell], [$force] => Success?';
504 sub AFS_vos_syncvldb {
505 my($server, $part, $cell, $force) = @_;
506 my(@args);
507
508 @args = ('syncvldb', '-server', $server);
509 push(@args, '-partition', $part) if ($part);
510 push(@args, '-force') if ($force);
511 push(@args, '-noauth') if ($AFS_Parms{'authlvl'} == 0);
512 push(@args, '-localauth') if ($AFS_Parms{'authlvl'} == 2);
513 push(@args, '-verbose') if ($AFS_Parms{'vostrace'} > 1);
514 push(@args, '-cell', $cell ? $cell : $AFS_Parms{'cell'});
515 &wrapper('vos', \@args,
516 [$vos_err_parse,
517 $AFS_Parms{'vostrace'} ? ([ '', '?']) : () ]);
518 1;
519 }
520
521
522 #: AFS_vos_lock($vol, [$cell])
523 #: Lock the VLDB entry for volume $vol.
524 #: If specified, work in $cell instead of the default cell.
525 #: On success, return 1.
526 #:
527 $AFS_Help{vos_lock} = '$vol, [$cell] => Success?';
528 sub AFS_vos_lock {
529 my($vol, $cell) = @_;
530 my(@args);
531
532 @args = ('lock', '-id', $vol);
533 push(@args, '-noauth') if ($AFS_Parms{'authlvl'} == 0);
534 push(@args, '-localauth') if ($AFS_Parms{'authlvl'} == 2);
535 push(@args, '-verbose') if ($AFS_Parms{'vostrace'} > 1);
536 push(@args, '-cell', $cell ? $cell : $AFS_Parms{'cell'});
537 &wrapper('vos', \@args,
538 [$vos_err_parse,
539 $AFS_Parms{'vostrace'} ? ([ '', '?']) : () ]);
540 1;
541 }
542
543
544 #: AFS_vos_unlock($vol, [$cell])
545 #: Unlock the VLDB entry for volume $vol.
546 #: If specified, work in $cell instead of the default cell.
547 #: On success, return 1.
548 #:
549 $AFS_Help{vos_unlock} = '$vol, [$cell] => Success?';
550 sub AFS_vos_unlock {
551 my($vol, $cell) = @_;
552 my(@args);
553
554 @args = ('unlock', '-id', $vol);
555 push(@args, '-noauth') if ($AFS_Parms{'authlvl'} == 0);
556 push(@args, '-localauth') if ($AFS_Parms{'authlvl'} == 2);
557 push(@args, '-verbose') if ($AFS_Parms{'vostrace'} > 1);
558 push(@args, '-cell', $cell ? $cell : $AFS_Parms{'cell'});
559 &wrapper('vos', \@args,
560 [$vos_err_parse,
561 $AFS_Parms{'vostrace'} ? ([ '', '?']) : () ]);
562 1;
563 }
564
565
566 #: AFS_vos_unlockvldb([$server, [$part]], [$cell])
567 #: Unlock some or all VLDB entries
568 #: If specified, unlock only entries for volumes on server $server
569 #: If specified with $server, unlock only entries for volumes on
570 #: partition $part, instead of entries for volumes on all partitions
571 #: If specified, work in $cell instead of the default cell.
572 #: On success, return 1.
573 #:
574 $AFS_Help{vos_unlockvldb} = '[$server, [$part]], [$cell] => Success?';
575 sub AFS_vos_unlockvldb {
576 my($server, $part, $cell) = @_;
577 my(@args);
578
579 @args = ('unlockvldb');
580 push(@args, '-server', $server) if ($server);
581 push(@args, '-partition', $part) if ($server && $part);
582 push(@args, '-noauth') if ($AFS_Parms{'authlvl'} == 0);
583 push(@args, '-localauth') if ($AFS_Parms{'authlvl'} == 2);
584 push(@args, '-verbose') if ($AFS_Parms{'vostrace'} > 1);
585 push(@args, '-cell', $cell ? $cell : $AFS_Parms{'cell'});
586 &wrapper('vos', \@args,
587 [$vos_err_parse,
588 $AFS_Parms{'vostrace'} ? ([ '', '?']) : () ]);
589 1;
590 }
591
592
593 #: AFS_vos_changeaddr($old, $new, [$cell])
594 #: Change the IP address of server $old to $new.
595 #: If specified, work in $cell instead of the default cell.
596 #: On success, return 1.
597 #:
598 $AFS_Help{vos_changeaddr} = '$old, $new, [$cell] => Success?';
599 sub AFS_vos_changeaddr {
600 my($old, $new, $cell) = @_;
601 my(@args);
602
603 @args = ('changeaddr', '-oldaddr', $old, '-newaddr', $new);
604 push(@args, '-noauth') if ($AFS_Parms{'authlvl'} == 0);
605 push(@args, '-localauth') if ($AFS_Parms{'authlvl'} == 2);
606 push(@args, '-verbose') if ($AFS_Parms{'vostrace'} > 1);
607 push(@args, '-cell', $cell ? $cell : $AFS_Parms{'cell'});
608 &wrapper('vos', \@args,
609 [$vos_err_parse,
610 $AFS_Parms{'vostrace'} ? ([ '', '?']) : () ]);
611 1;
612 }
613
614
615 #: AFS_vos_listpart($server, [$cell])
616 #: Retrieve a list of partitions on server $server
617 #: If specified, work in $cell instead of the default cell.
618 #: On success, return a list of partition letters
619 #:
620 $AFS_Help{vos_listpart} = '$server, [$cell] => @parts';
621 sub AFS_vos_listpart {
622 my($server, $cell) = @_;
623 my(@args, @parts);
624
625 @args = ('listpart', '-server', $server);
626 push(@args, '-noauth') if ($AFS_Parms{'authlvl'} == 0);
627 push(@args, '-localauth') if ($AFS_Parms{'authlvl'} == 2);
628 push(@args, '-verbose') if ($AFS_Parms{'vostrace'} > 2);
629 push(@args, '-cell', $cell ? $cell : $AFS_Parms{'cell'});
630 &wrapper('vos', \@args,
631 [$vos_err_parse,
632 [ '^(.*\/vicep.*)$', #',
633 sub {
634 push(@parts, map {
635 my($x) = $_;
636 $x =~ s/^\/vicep//;
637 $x;
638 } split(' ', $_[0]));
639 }],
640 ($AFS_Parms{'vostrace'} > 2) ? ([ '', '?']) : () ]);
641 @parts;
642 }
643
644
645 #: AFS_vos_partinfo($server, [$part], [$cell])
646 #: Get information about partitions on server $server.
647 #: If specified, only get info about partition $part.
648 #: If specified, work in $cell instead of the default cell.
649 #: On success, return an associative array whose keys are partition letters,
650 #: and each of whose values is a reference to a 2-element list, consisting
651 #: of the total size of the partition and the amount of space used.
652 #:
653 $AFS_Help{vos_partinfo} = '$server, [$part], [$cell] => %info';
654 sub AFS_vos_partinfo {
655 my($server, $part, $cell) = @_;
656 my(@args, %parts);
657
658 @args = ('partinfo', '-server', $server);
659 push(@args, '-partition', $part) if ($part);
660 push(@args, '-noauth') if ($AFS_Parms{'authlvl'} == 0);
661 push(@args, '-localauth') if ($AFS_Parms{'authlvl'} == 2);
662 push(@args, '-verbose') if ($AFS_Parms{'vostrace'} > 2);
663 push(@args, '-cell', $cell ? $cell : $AFS_Parms{'cell'});
664 &wrapper('vos', \@args,
665 [$vos_err_parse,
666 [ '^Free space on partition /vicep(.+)\: (\d+) K blocks out of total (\d+)',
667 sub {
668 $parts{$_[0]} = [ $_[1], $_[2] ];
669 }],
670 ($AFS_Parms{'vostrace'} > 2) ? ([ '', '?']) : () ]);
671 %parts;
672 }
673
674
675 #: AFS_vos_listvol($server, [$part], [$cell])
676 #: Get a list of volumes on the server $server.
677 #: If specified, list only volumes on the partition $part.
678 #: If specified, work in $cell instead of the default cell.
679 #: On success, return an associative array whose keys are names of volumes
680 #: on the specified server, and each of whose values is an associative
681 #: array describing the corresponding volume, containing some or all of
682 #: these elements:
683 #: - name Name of this volume (same as key)
684 #: - id ID of this volume
685 #: - kind Kind of volume (RW, RO, or BK)
686 #: - inuse Disk space in use
687 #: - maxquota Maximum disk usage quota
688 #: - minquota Minimum disk usage quota (optional)
689 #: - stamp_create Time when volume was originally created
690 #: - stamp_update Time volume was last modified
691 #: - stamp_backup Time backup volume was cloned, or 'Never'
692 #: - stamp_copy Time this copy of volume was made
693 #: - backup_flag State of automatic backups: empty or 'disabled'
694 #: - dayuse Number of accesses in the past day
695 #: - serv Server where this volume is located
696 #: - part Partition where this volume is located
697 #:
698 $AFS_Help{vos_listvol} = '$server, [$part], [$cell] => %vols';
699 sub AFS_vos_listvol {
700 my($server, $part, $cell) = @_;
701 my(%finres, %vlist);
702
703 @args = ('listvol', '-server', $server, '-long');
704 push(@args, '-partition', $part) if ($part);
705 push(@args, '-noauth') if ($AFS_Parms{'authlvl'} == 0);
706 push(@args, '-localauth') if ($AFS_Parms{'authlvl'} == 2);
707 push(@args, '-verbose') if ($AFS_Parms{'vostrace'} > 2);
708 push(@args, '-cell', $cell ? $cell : $AFS_Parms{'cell'});
709 %finres = &wrapper('vos', \@args,
710 [$vos_err_parse,
711 ['^\S+\s*\d+\s*(RW|RO|BK)', sub {
712 my(%vinfo) = %OpenAFS::wrapper::result;
713
714 if ($vinfo{name}) {
715 $vlist{$vinfo{name}} = \%vinfo;
716 %OpenAFS::wrapper::result = ();
717 }
718 }],
719 ['^(\S+)\s*(\d+)\s*(RW|RO|BK)\s*(\d+)\s*K', 'name', 'id', 'kind', 'inuse'],
720 ['(\S+)\s*\/vicep(\S+)\:', 'serv', 'part' ],
721 ['MaxQuota\s*(\d+)\s*K', 'maxquota' ],
722 ['MinQuota\s*(\d+)\s*K', 'minquota' ],
723 ['Creation\s*(.*\S+)', 'stamp_create' ],
724 ['Last Update\s*(.*\S+)', 'stamp_update' ],
725 ['Backup\s+([^\d\s].*\S+)', 'stamp_backup' ],
726 ['Copy\s*(.*\S+)', 'stamp_copy' ],
727 ['Automatic backups are (disabled) for this volume', 'backup_flag' ],
728 ['(\d+) accesses in the past day', 'dayuse' ],
729 ($AFS_Parms{'vostrace'} > 2) ? ([ '', '?']) : () ]);
730
731 if ($finres{name}) {
732 $vlist{$finres{name}} = \%finres;
733 }
734 %vlist;
735 }
736
737 #: AFS_vos_zap($vol, $server, $part, [$cell], [$force])
738 #: Remove the volume $vol from the server and partition specified by $server and
739 #: $part. Don't bother messing with the VLDB.
740 #: If specified, work in $cell instead of the default cell.
741 #: If $force is specified, force the zap to happen
742 #: On success, return 1.
743 #:
744 $AFS_Help{vos_zap} = '$vol, $server, $part, [$cell], [$force] => Success?';
745 sub AFS_vos_zap {
746 my($vol, $server, $part, $cell, $force) = @_;
747 my(@args);
748
749 @args = ('zap', '-id', $vol, '-server', $server, '-part', $part);
750 push(@args, '-force') if ($force);
751 push(@args, '-noauth') if ($AFS_Parms{'authlvl'} == 0);
752 push(@args, '-localauth') if ($AFS_Parms{'authlvl'} == 2);
753 push(@args, '-verbose') if ($AFS_Parms{'vostrace'} > 1);
754 push(@args, '-cell', $cell ? $cell : $AFS_Parms{'cell'});
755 &wrapper('vos', \@args,
756 [$vos_err_parse,
757 $AFS_Parms{'vostrace'} ? ([ '', '?']) : () ]);
758 1;
759 }
760
761
762 #: AFS_vos_status($server, [$cell])
763 #: Get information about outstanding transactions on $server
764 #: If specified, work in $cell instead of the default cell
765 #: On success, return a list of transactions, each of which is a reference
766 #: to an associative array containing some or all of these elements:
767 #: - transid Transaction ID
768 #: - stamp_create Time the transaction was created
769 #: - volid Volume ID
770 #: - part Partition letter
771 #: - action Action or procedure
772 #: - flags Volume attach flags
773 #: If there are no transactions, the list will be empty.
774 #:
775 $AFS_Help{vos_status} = '$server, [$cell] => @trans';
776 sub AFS_vos_status {
777 my($server, $cell) = @_;
778 my(@trlist);
779
780 @args = ('status', '-server', $server);
781 push(@args, '-noauth') if ($AFS_Parms{'authlvl'} == 0);
782 push(@args, '-localauth') if ($AFS_Parms{'authlvl'} == 2);
783 push(@args, '-verbose') if ($AFS_Parms{'vostrace'} > 2);
784 push(@args, '-cell', $cell ? $cell : $AFS_Parms{'cell'});
785 &wrapper('vos', \@args,
786 [$vos_err_parse,
787 ['^(\-)', sub {
788 my(%trinfo) = %OpenAFS::wrapper::result;
789
790 if ($trinfo{transid}) {
791 push(@trlist, \%trinfo);
792 %OpenAFS::wrapper::result = ();
793 }
794 }],
795 ['^transaction\:\s*(\d+)\s*created: (.*\S+)', 'transid', 'stamp_create'],
796 ['^attachFlags:\s*(.*\S+)', 'flags'],
797 ['^volume:\s*(\d+)\s*partition\: \/vicep(\S+)\s*procedure\:\s*(\S+)',
798 'volid', 'part', 'action'],
799 ($AFS_Parms{'vostrace'} > 2) ? ([ '', '?']) : () ]);
800
801 @trlist;
802 }
803
804 1;