deal-with-linux-large-uids-20020115
[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 #: - maxquota     Maximum disk usage quota
148 #: - minquota     Minimum disk usage quota (optional)
149 #: - stamp_create Time when volume was originally created
150 #: - stamp_update Time volume was last modified
151 #: - stamp_backup Time backup volume was cloned, or 'Never'
152 #: - stamp_copy   Time this copy of volume was made
153 #: - backup_flag  State of automatic backups: empty or 'disabled'
154 #: - dayuse       Number of accesses in the past day
155 #: - rwid         ID of read-write volume (even if this is RO or BK)
156 #: - roid         ID of read-only volume (even if this is RW or BK)
157 #: - bkid         ID of backup volume (even if this is RW or RO)
158 #: - rwserv       Name of server where read/write volume is
159 #: - rwpart       Name of partition where read/write volume is
160 #: - rosites      Reference to a list of read-only sites.  Each site, in turn,
161 #:                is a reference to a two-element list (server, part).
162 #:
163 $AFS_Help{vos_examine} = '$vol, [$cell] => %info';
164 sub AFS_vos_examine {
165   my($vol, $cell) = @_;
166   my(%result, @args, @rosites);
167
168   @args = ('examine', '-id', $vol);
169   push(@args, '-noauth')           if ($AFS_Parms{'authlvl'} == 0);
170   push(@args, '-localauth')        if ($AFS_Parms{'authlvl'} == 2);
171   push(@args, '-verbose')          if ($AFS_Parms{'vostrace'} > 2);
172   push(@args, '-cell', $cell ? $cell : $AFS_Parms{'cell'});
173   %result = &wrapper('vos', \@args,
174                      [$vos_err_parse,
175                       ['^(\S+)\s*(\d+)\s*(RW|RO|BK)\s*(\d+)\s*K',          'name', 'id', 'kind', 'inuse'],
176                       ['MaxQuota\s*(\d+)\s*K',                             'maxquota'     ],
177                       ['MinQuota\s*(\d+)\s*K',                             'minquota'     ],
178                       ['Creation\s*(.*\S+)',                               'stamp_create' ],
179                       ['Last Update\s*(.*\S+)',                            'stamp_update' ],
180                       ['Backup\s+([^\d\s].*\S+)',                          'stamp_backup' ],
181                       ['Copy\s*(.*\S+)',                                   'stamp_copy'   ],
182                       ['Automatic backups are (disabled) for this volume', 'backup_flag'  ],
183                       ['(\d+) accesses in the past day',                   'dayuse'       ],
184                       ['RWrite\:\s*(\d+)',                                 'rwid'         ],
185                       ['ROnly\:\s*(\d+)',                                  'roid'         ],
186                       ['Backup\:\s*(\d+)',                                 'bkid'         ],
187                       ['server (\S+) partition /vicep(\S+) RW Site',       'rwserv', 'rwpart'],
188                       ['server (\S+) partition /vicep(\S+) RO Site',       sub {
189                         push(@rosites, [$_[0], $_[1]]);
190                       }],
191                       ($AFS_Parms{'vostrace'} > 2) ? ([ '', '?']) : () ]);
192
193   $result{'rosites'} = \@rosites if (@rosites);
194   %result;
195 }
196
197
198
199 #: AFS_vos_addsite($vol, $server, $part, [$cell])
200 #: Add a replication site for volume $vol
201 #: The server name ($server) may be a hostname or IP address
202 #: The partition may be a partition name (/vicepx), letter (x), or number (24)
203 #: If specified, work in $cell instead of the default cell.
204 #: On success, return 1.
205 #:
206 $AFS_Help{vos_addsite} = '$vol, $server, $part, [$cell] => Success?';
207 sub AFS_vos_addsite {
208   my($vol, $server, $part, $cell) = @_;
209   my(@args);
210
211   @args = ('addsite', '-id', $vol, '-server', $server, '-part', $part);
212   push(@args, '-noauth')           if ($AFS_Parms{'authlvl'} == 0);
213   push(@args, '-localauth')        if ($AFS_Parms{'authlvl'} == 2);
214   push(@args, '-verbose')          if ($AFS_Parms{'vostrace'} > 1);
215   push(@args, '-cell', $cell ? $cell : $AFS_Parms{'cell'});
216   &wrapper('vos', \@args,
217            [$vos_err_parse,
218             $AFS_Parms{'vostrace'} ? ([ '', '?']) : () ]);
219   1;
220 }
221
222
223 #: AFS_vos_remsite($vol, $server, $part, [$cell])
224 #: Remove a replication site for volume $vol
225 #: The server name ($server) may be a hostname or IP address
226 #: The partition may be a partition name (/vicepx), letter (x), or number (24)
227 #: If specified, work in $cell instead of the default cell.
228 #: On success, return 1.
229 #:
230 $AFS_Help{vos_remsite} = '$vol, $server, $part, [$cell] => Success?';
231 sub AFS_vos_remsite {
232   my($vol, $server, $part, $cell) = @_;
233   my(@args);
234
235   @args = ('remsite', '-id', $vol, '-server', $server, '-part', $part);
236   push(@args, '-noauth')           if ($AFS_Parms{'authlvl'} == 0);
237   push(@args, '-localauth')        if ($AFS_Parms{'authlvl'} == 2);
238   push(@args, '-verbose')          if ($AFS_Parms{'vostrace'} > 1);
239   push(@args, '-cell', $cell ? $cell : $AFS_Parms{'cell'});
240   &wrapper('vos', \@args,
241            [$vos_err_parse,
242             $AFS_Parms{'vostrace'} ? ([ '', '?']) : () ]);
243   1;
244 }
245
246
247 #: AFS_vos_release($vol, [$cell], [$force])
248 #: Release the volume $vol.
249 #: If $force is specified and non-zero, use the "-f" switch.
250 #: If specified, work in $cell instead of the default cell.
251 #: On success, return 1.
252 #:
253 $AFS_Help{vos_release} = '$vol, [$cell], [$force] => Success?';
254 sub AFS_vos_release {
255   my($vol, $cell, $force) = @_;
256   my(@args);
257
258   @args = ('release', '-id', $vol);
259   push(@args, '-f')                if ($force);
260   push(@args, '-noauth')           if ($AFS_Parms{'authlvl'} == 0);
261   push(@args, '-localauth')        if ($AFS_Parms{'authlvl'} == 2);
262   push(@args, '-verbose')          if ($AFS_Parms{'vostrace'} > 1);
263   push(@args, '-cell', $cell ? $cell : $AFS_Parms{'cell'});
264   &wrapper('vos', \@args,
265            [$vos_err_parse,
266             $AFS_Parms{'vostrace'} ? ([ '', '?']) : () ]);
267   1;
268 }
269
270
271 #: AFS_vos_backup($vol, [$cell])
272 #: Make a backup of the volume $vol.
273 #: If specified, work in $cell instead of the default cell.
274 #: On success, return 1.
275 #:
276 $AFS_Help{vos_backup} = '$vol, [$cell] => Success?';
277 sub AFS_vos_backup {
278   my($vol, $cell) = @_;
279   my(@args);
280
281   @args = ('backup', '-id', $vol);
282   push(@args, '-noauth')           if ($AFS_Parms{'authlvl'} == 0);
283   push(@args, '-localauth')        if ($AFS_Parms{'authlvl'} == 2);
284   push(@args, '-verbose')          if ($AFS_Parms{'vostrace'} > 1);
285   push(@args, '-cell', $cell ? $cell : $AFS_Parms{'cell'});
286   &wrapper('vos', \@args,
287            [$vos_err_parse,
288             $AFS_Parms{'vostrace'} ? ([ '', '?']) : () ]);
289   1;
290 }
291
292
293 #: AFS_vos_backupsys([$prefix], [$server, [$part]], [$exclude], [$cell])
294 #: Do en masse backups of AFS volumes.
295 #: If specified, match only volumes whose names begin with $prefix
296 #: If specified, limit work to the $server and, if given, $part.
297 #: If $exclude is specified and non-zero, backup only volumes NOT matched.
298 #: If specified, work in $cell instead of the default cell.
299 #: On success, return 1.
300 #:
301 $AFS_Help{vos_backupsys} = '[$prefix], [$server, [$part]], [$exclude], [$cell] => Success?';
302 sub AFS_vos_backupsys {
303   my($prefix, $server, $part, $exclude, $cell) = @_;
304   my(@args);
305
306   @args = ('backupsys');
307   push(@args, '-prefix', $prefix)  if ($prefix);
308   push(@args, '-server', $server)  if ($server);
309   push(@args, '-partition', $part) if ($server && $part);
310   push(@args, '-exclude')          if ($exclude);
311   push(@args, '-noauth')           if ($AFS_Parms{'authlvl'} == 0);
312   push(@args, '-localauth')        if ($AFS_Parms{'authlvl'} == 2);
313   push(@args, '-verbose')          if ($AFS_Parms{'vostrace'} > 1);
314   push(@args, '-cell', $cell ? $cell : $AFS_Parms{'cell'});
315   &wrapper('vos', \@args,
316            [$vos_err_parse,
317             $AFS_Parms{'vostrace'} ? ([ '', '?']) : () ]);
318   1;
319 }
320
321
322 #: AFS_vos_dump($vol, [$time], [$file], [$cell])
323 #: Dump the volume $vol
324 #: If specified, do an incremental dump since $time instead of a full dump.
325 #: If specified, dump to $file instead of STDOUT
326 #: If specified, work in $cell instead of the default cell.
327 #: On success, return 1.
328 #:
329 $AFS_Help{vos_dump} = '$vol, [$time], [$file], [$cell] => Success?';
330 sub AFS_vos_dump {
331   my($vol, $time, $file, $cell) = @_;
332   my(@args);
333
334   @args = ('dump', '-id', $vol);
335   push(@args, '-time', ($time ? $time : 0));
336   push(@args, '-file', $file)      if ($file);
337   push(@args, '-noauth')           if ($AFS_Parms{'authlvl'} == 0);
338   push(@args, '-localauth')        if ($AFS_Parms{'authlvl'} == 2);
339   push(@args, '-verbose')          if ($AFS_Parms{'vostrace'} > 1);
340   push(@args, '-cell', $cell ? $cell : $AFS_Parms{'cell'});
341   &wrapper('vos', \@args,
342            [$vos_err_parse,
343             $AFS_Parms{'vostrace'} ? ([ '', '?']) : () ],
344            { pass_stdout => !$file });
345   1;
346 }
347
348
349 #: AFS_vos_restore($vol, $server, $part, [$file], [$id], [$owmode], [$cell])
350 #: Restore the volume $vol to partition $part on server $server.
351 #: If specified, restore from $file instead of STDIN
352 #: If specified, use the volume ID $id
353 #: If specified, $owmode must be 'abort', 'full', or 'incremental', and
354 #: indicates what to do if the volume exists.
355 #: If specified, work in $cell instead of the default cell.
356 #: On success, return 1.
357 #:
358 $AFS_Help{vos_restore} = '$vol, $server, $part, [$file], [$id], [$owmode], [$cell] => Success?';
359 sub AFS_vos_restore {
360   my($vol, $server, $part, $file, $id, $owmode, $cell) = @_;
361   my(@args);
362
363   @args = ('restore', '-name', $vol, '-server', $server, '-partition', $part);
364   push(@args, '-file', $file)      if ($file);
365   push(@args, '-id', $id)          if ($id);
366   push(@args, '-overwrite', $owmode) if ($owmode);
367   push(@args, '-noauth')           if ($AFS_Parms{'authlvl'} == 0);
368   push(@args, '-localauth')        if ($AFS_Parms{'authlvl'} == 2);
369   push(@args, '-verbose')          if ($AFS_Parms{'vostrace'} > 1);
370   push(@args, '-cell', $cell ? $cell : $AFS_Parms{'cell'});
371   &wrapper('vos', \@args,
372            [$vos_err_parse,
373             $AFS_Parms{'vostrace'} ? ([ '', '?']) : () ]);
374   1;
375 }
376
377
378 #: AFS_vos_listvldb([$vol], [$server, [$part]], [$locked], [$cell])
379 #: Get a list of volumes in the VLDB.
380 #: If specified, list only the volume $vol
381 #: If specified, list only volumes on the server $server.
382 #: If specified with $server, list only volumes on the partition $part.
383 #: If $locked is specified and nonzero, list only locked VLDB entries
384 #: If specified, work in $cell instead of the default cell.
385 #: On success, return an associative array whose keys are names of volumes
386 #: on the specified server, and each of whose values is an associative
387 #: array describing the corresponding volume, containing some or all of
388 #: these elements:
389 #: - name         Name of this volume (same as key)
390 #: - rwid         ID of read-write volume (even if this is RO or BK)
391 #: - roid         ID of read-only volume (even if this is RW or BK)
392 #: - bkid         ID of backup volume (even if this is RW or RO)
393 #: - locked       Empty or LOCKED to indicate VLDB entry is locked
394 #: - rwserv       Name of server where read/write volume is
395 #: - rwpart       Name of partition where read/write volume is
396 #: - rosites      Reference to a list of read-only sites.  Each site, in turn,
397 #:                is a reference to a two-element list (server, part).
398 #:
399 $AFS_Help{vos_listvldb} = '[$vol], [$server, [$part]], [$locked], [$cell] => %vols';
400 sub AFS_vos_listvldb {
401   my($vol, $server, $part, $locked, $cell) = @_;
402   my(%finres, %vlist, @rosites);
403
404   @args = ('listvldb');
405   push(@args, '-name', $vol)       if ($vol);
406   push(@args, '-server', $server)  if ($server);
407   push(@args, '-partition', $part) if ($part && $server);
408   push(@args, '-locked')           if ($locked);
409   push(@args, '-noauth')           if ($AFS_Parms{'authlvl'} == 0);
410   push(@args, '-localauth')        if ($AFS_Parms{'authlvl'} == 2);
411   push(@args, '-verbose')          if ($AFS_Parms{'vostrace'} > 2);
412   push(@args, '-cell', $cell ? $cell : $AFS_Parms{'cell'});
413   %finres = &wrapper('vos', \@args,
414                      [$vos_err_parse,
415                       ['^(VLDB|Total) entries', '.'],
416                       ['^(\S+)', sub {
417                         my(%vinfo) = %OpenAFS::wrapper::result;
418
419                         if ($vinfo{name}) {
420                           $vinfo{rosites} = [@rosites] if (@rosites);
421                           $vlist{$vinfo{name}} = \%vinfo;
422
423                           @rosites = ();
424                           %OpenAFS::wrapper::result = ();
425                         }
426                       }],
427                       ['^(\S+)',                                           'name'         ],
428                       ['RWrite\:\s*(\d+)',                                 'rwid'         ],
429                       ['ROnly\:\s*(\d+)',                                  'roid'         ],
430                       ['Backup\:\s*(\d+)',                                 'bkid'         ],
431                       ['Volume is currently (LOCKED)',                     'locked'       ],
432                       ['server (\S+) partition /vicep(\S+) RW Site',       'rwserv', 'rwpart'],
433                       ['server (\S+) partition /vicep(\S+) RO Site',       sub {
434                         push(@rosites, [$_[0], $_[1]]);
435                       }],
436                       ($AFS_Parms{'vostrace'} > 2) ? ([ '', '?']) : () ]);
437
438   if ($finres{name}) {
439     $finres{rosites} = [@rosites] if (@rosites);
440     $vlist{$finres{name}} = \%finres;
441   }
442   %vlist;
443 }
444
445
446
447 #: AFS_vos_delentry($vol, [$cell])
448 #: Delete the VLDB entry for the volume $vol
449 #: If specified, work in $cell instead of the default cell.
450 #: On success, return 1.
451 #:
452 $AFS_Help{vos_delentry} = '$vol, [$cell] => Success?';
453 sub AFS_vos_delentry {
454   my($vol, $cell) = @_;
455   my(@args);
456
457   @args = ('delentry', '-id', $vol);
458   push(@args, '-noauth')           if ($AFS_Parms{'authlvl'} == 0);
459   push(@args, '-localauth')        if ($AFS_Parms{'authlvl'} == 2);
460   push(@args, '-verbose')          if ($AFS_Parms{'vostrace'} > 1);
461   push(@args, '-cell', $cell ? $cell : $AFS_Parms{'cell'});
462   &wrapper('vos', \@args,
463            [$vos_err_parse,
464             $AFS_Parms{'vostrace'} ? ([ '', '?']) : () ]);
465   1;
466 }
467
468
469 #: AFS_vos_syncserv($server, [$part], [$cell], [$force])
470 #: Synchronize the server $server with the VLDB
471 #: If specified, synchronize only partition $part
472 #: If specified, work in $cell instead of the default cell
473 #: If $force is specified, force updates to occur
474 #: On success, return 1.
475 #:
476 $AFS_Help{vos_syncserv} = '$server, [$part], [$cell], [$force] => Success?';
477 sub AFS_vos_syncserv {
478   my($server, $part, $cell, $force) = @_;
479   my(@args);
480
481   @args = ('syncserv', '-server', $server);
482   push(@args, '-partition', $part) if ($part);
483   push(@args, '-force')            if ($force);
484   push(@args, '-noauth')           if ($AFS_Parms{'authlvl'} == 0);
485   push(@args, '-localauth')        if ($AFS_Parms{'authlvl'} == 2);
486   push(@args, '-verbose')          if ($AFS_Parms{'vostrace'} > 1);
487   push(@args, '-cell', $cell ? $cell : $AFS_Parms{'cell'});
488   &wrapper('vos', \@args,
489            [$vos_err_parse,
490             $AFS_Parms{'vostrace'} ? ([ '', '?']) : () ]);
491   1;
492 }
493
494
495 #: AFS_vos_syncvldb($server, [$part], [$cell], [$force])
496 #: Synchronize the VLDB with server $server
497 #: If specified, synchronize only partition $part
498 #: If specified, work in $cell instead of the default cell
499 #: If $force is specified, force updates to occur
500 #: On success, return 1.
501 #:
502 $AFS_Help{vos_syncvldb} = '$server, [$part], [$cell], [$force] => Success?';
503 sub AFS_vos_syncvldb {
504   my($server, $part, $cell, $force) = @_;
505   my(@args);
506
507   @args = ('syncvldb', '-server', $server);
508   push(@args, '-partition', $part) if ($part);
509   push(@args, '-force')            if ($force);
510   push(@args, '-noauth')           if ($AFS_Parms{'authlvl'} == 0);
511   push(@args, '-localauth')        if ($AFS_Parms{'authlvl'} == 2);
512   push(@args, '-verbose')          if ($AFS_Parms{'vostrace'} > 1);
513   push(@args, '-cell', $cell ? $cell : $AFS_Parms{'cell'});
514   &wrapper('vos', \@args,
515            [$vos_err_parse,
516             $AFS_Parms{'vostrace'} ? ([ '', '?']) : () ]);
517   1;
518 }
519
520
521 #: AFS_vos_lock($vol, [$cell])
522 #: Lock the VLDB entry for volume $vol.
523 #: If specified, work in $cell instead of the default cell.
524 #: On success, return 1.
525 #:
526 $AFS_Help{vos_lock} = '$vol, [$cell] => Success?';
527 sub AFS_vos_lock {
528   my($vol, $cell) = @_;
529   my(@args);
530
531   @args = ('lock', '-id', $vol);
532   push(@args, '-noauth')           if ($AFS_Parms{'authlvl'} == 0);
533   push(@args, '-localauth')        if ($AFS_Parms{'authlvl'} == 2);
534   push(@args, '-verbose')          if ($AFS_Parms{'vostrace'} > 1);
535   push(@args, '-cell', $cell ? $cell : $AFS_Parms{'cell'});
536   &wrapper('vos', \@args,
537            [$vos_err_parse,
538             $AFS_Parms{'vostrace'} ? ([ '', '?']) : () ]);
539   1;
540 }
541
542
543 #: AFS_vos_unlock($vol, [$cell])
544 #: Unlock the VLDB entry for volume $vol.
545 #: If specified, work in $cell instead of the default cell.
546 #: On success, return 1.
547 #:
548 $AFS_Help{vos_unlock} = '$vol, [$cell] => Success?';
549 sub AFS_vos_unlock {
550   my($vol, $cell) = @_;
551   my(@args);
552
553   @args = ('unlock', '-id', $vol);
554   push(@args, '-noauth')           if ($AFS_Parms{'authlvl'} == 0);
555   push(@args, '-localauth')        if ($AFS_Parms{'authlvl'} == 2);
556   push(@args, '-verbose')          if ($AFS_Parms{'vostrace'} > 1);
557   push(@args, '-cell', $cell ? $cell : $AFS_Parms{'cell'});
558   &wrapper('vos', \@args,
559            [$vos_err_parse,
560             $AFS_Parms{'vostrace'} ? ([ '', '?']) : () ]);
561   1;
562 }
563
564
565 #: AFS_vos_unlockvldb([$server, [$part]], [$cell])
566 #: Unlock some or all VLDB entries
567 #: If specified, unlock only entries for volumes on server $server
568 #: If specified with $server, unlock only entries for volumes on
569 #: partition $part, instead of entries for volumes on all partitions
570 #: If specified, work in $cell instead of the default cell.
571 #: On success, return 1.
572 #:
573 $AFS_Help{vos_unlockvldb} = '[$server, [$part]], [$cell] => Success?';
574 sub AFS_vos_unlockvldb {
575   my($server, $part, $cell) = @_;
576   my(@args);
577
578   @args = ('unlockvldb');
579   push(@args, '-server', $server)  if ($server);
580   push(@args, '-partition', $part) if ($server && $part);
581   push(@args, '-noauth')           if ($AFS_Parms{'authlvl'} == 0);
582   push(@args, '-localauth')        if ($AFS_Parms{'authlvl'} == 2);
583   push(@args, '-verbose')          if ($AFS_Parms{'vostrace'} > 1);
584   push(@args, '-cell', $cell ? $cell : $AFS_Parms{'cell'});
585   &wrapper('vos', \@args,
586            [$vos_err_parse,
587             $AFS_Parms{'vostrace'} ? ([ '', '?']) : () ]);
588   1;
589 }
590
591
592 #: AFS_vos_changeaddr($old, $new, [$cell])
593 #: Change the IP address of server $old to $new.
594 #: If specified, work in $cell instead of the default cell.
595 #: On success, return 1.
596 #:
597 $AFS_Help{vos_changeaddr} = '$old, $new, [$cell] => Success?';
598 sub AFS_vos_changeaddr {
599   my($old, $new, $cell) = @_;
600   my(@args);
601
602   @args = ('changeaddr', '-oldaddr', $old, '-newaddr', $new);
603   push(@args, '-noauth')           if ($AFS_Parms{'authlvl'} == 0);
604   push(@args, '-localauth')        if ($AFS_Parms{'authlvl'} == 2);
605   push(@args, '-verbose')          if ($AFS_Parms{'vostrace'} > 1);
606   push(@args, '-cell', $cell ? $cell : $AFS_Parms{'cell'});
607   &wrapper('vos', \@args,
608            [$vos_err_parse,
609             $AFS_Parms{'vostrace'} ? ([ '', '?']) : () ]);
610   1;
611 }
612
613
614 #: AFS_vos_listpart($server, [$cell])
615 #: Retrieve a list of partitions on server $server
616 #: If specified, work in $cell instead of the default cell.
617 #: On success, return a list of partition letters
618 #:
619 $AFS_Help{vos_listpart} = '$server, [$cell] => @parts';
620 sub AFS_vos_listpart {
621   my($server, $cell) = @_;
622   my(@args, @parts);
623
624   @args = ('listpart', '-server', $server);
625   push(@args, '-noauth')           if ($AFS_Parms{'authlvl'} == 0);
626   push(@args, '-localauth')        if ($AFS_Parms{'authlvl'} == 2);
627   push(@args, '-verbose')          if ($AFS_Parms{'vostrace'} > 2);
628   push(@args, '-cell', $cell ? $cell : $AFS_Parms{'cell'});
629   &wrapper('vos', \@args,
630            [$vos_err_parse,
631             [ '^(.*\/vicep.*)$', #',
632              sub {
633                push(@parts, map {
634                  my($x) = $_;
635                  $x =~ s/^\/vicep//;
636                  $x;
637                } split(' ', $_[0]));
638              }],
639             ($AFS_Parms{'vostrace'} > 2) ? ([ '', '?']) : () ]);
640   @parts;
641 }
642
643
644 #: AFS_vos_partinfo($server, [$part], [$cell])
645 #: Get information about partitions on server $server.
646 #: If specified, only get info about partition $part.
647 #: If specified, work in $cell instead of the default cell.
648 #: On success, return an associative array whose keys are partition letters,
649 #: and each of whose values is a reference to a 2-element list, consisting
650 #: of the total size of the partition and the amount of space used.
651 #:
652 $AFS_Help{vos_partinfo} = '$server, [$part], [$cell] => %info';
653 sub AFS_vos_partinfo {
654   my($server, $part, $cell) = @_;
655   my(@args, %parts);
656
657   @args = ('partinfo', '-server', $server);
658   push(@args, '-partition', $part) if ($part);
659   push(@args, '-noauth')           if ($AFS_Parms{'authlvl'} == 0);
660   push(@args, '-localauth')        if ($AFS_Parms{'authlvl'} == 2);
661   push(@args, '-verbose')          if ($AFS_Parms{'vostrace'} > 2);
662   push(@args, '-cell', $cell ? $cell : $AFS_Parms{'cell'});
663   &wrapper('vos', \@args,
664            [$vos_err_parse,
665             [ '^Free space on partition /vicep(.+)\: (\d+) K blocks out of total (\d+)',
666              sub {
667                $parts{$_[0]} = [ $_[1], $_[2] ];
668              }],
669             ($AFS_Parms{'vostrace'} > 2) ? ([ '', '?']) : () ]);
670   %parts;
671 }
672
673
674 #: AFS_vos_listvol($server, [$part], [$cell])
675 #: Get a list of volumes on the server $server.
676 #: If specified, list only volumes on the partition $part.
677 #: If specified, work in $cell instead of the default cell.
678 #: On success, return an associative array whose keys are names of volumes
679 #: on the specified server, and each of whose values is an associative
680 #: array describing the corresponding volume, containing some or all of
681 #: these elements:
682 #: - name         Name of this volume (same as key)
683 #: - id           ID of this volume
684 #: - kind         Kind of volume (RW, RO, or BK)
685 #: - inuse        Disk space in use
686 #: - maxquota     Maximum disk usage quota
687 #: - minquota     Minimum disk usage quota (optional)
688 #: - stamp_create Time when volume was originally created
689 #: - stamp_update Time volume was last modified
690 #: - stamp_backup Time backup volume was cloned, or 'Never'
691 #: - stamp_copy   Time this copy of volume was made
692 #: - backup_flag  State of automatic backups: empty or 'disabled'
693 #: - dayuse       Number of accesses in the past day
694 #: - serv         Server where this volume is located
695 #: - part         Partition where this volume is located
696 #:
697 $AFS_Help{vos_listvol} = '$server, [$part], [$cell] => %vols';
698 sub AFS_vos_listvol {
699   my($server, $part, $cell) = @_;
700   my(%finres, %vlist);
701
702   @args = ('listvol', '-server', $server, '-long');
703   push(@args, '-partition', $part) if ($part);
704   push(@args, '-noauth')           if ($AFS_Parms{'authlvl'} == 0);
705   push(@args, '-localauth')        if ($AFS_Parms{'authlvl'} == 2);
706   push(@args, '-verbose')          if ($AFS_Parms{'vostrace'} > 2);
707   push(@args, '-cell', $cell ? $cell : $AFS_Parms{'cell'});
708   %finres = &wrapper('vos', \@args,
709                      [$vos_err_parse,
710                       ['^\S+\s*\d+\s*(RW|RO|BK)', sub {
711                         my(%vinfo) = %OpenAFS::wrapper::result;
712
713                         if ($vinfo{name}) {
714                           $vlist{$vinfo{name}} = \%vinfo;
715                           %OpenAFS::wrapper::result = ();
716                         }
717                       }],
718                       ['^(\S+)\s*(\d+)\s*(RW|RO|BK)\s*(\d+)\s*K',          'name', 'id', 'kind', 'inuse'],
719                       ['(\S+)\s*\/vicep(\S+)\:',                           'serv', 'part' ],
720                       ['MaxQuota\s*(\d+)\s*K',                             'maxquota'     ],
721                       ['MinQuota\s*(\d+)\s*K',                             'minquota'     ],
722                       ['Creation\s*(.*\S+)',                               'stamp_create' ],
723                       ['Last Update\s*(.*\S+)',                            'stamp_update' ],
724                       ['Backup\s+([^\d\s].*\S+)',                          'stamp_backup' ],
725                       ['Copy\s*(.*\S+)',                                   'stamp_copy'   ],
726                       ['Automatic backups are (disabled) for this volume', 'backup_flag'  ],
727                       ['(\d+) accesses in the past day',                   'dayuse'       ],
728                       ($AFS_Parms{'vostrace'} > 2) ? ([ '', '?']) : () ]);
729
730   if ($finres{name}) {
731     $vlist{$finres{name}} = \%finres;
732   }
733   %vlist;
734 }
735
736 #: AFS_vos_zap($vol, $server, $part, [$cell], [$force])
737 #: Remove the volume $vol from the server and partition specified by $server and
738 #: $part.  Don't bother messing with the VLDB.
739 #: If specified, work in $cell instead of the default cell.
740 #: If $force is specified, force the zap to happen
741 #: On success, return 1.
742 #:
743 $AFS_Help{vos_zap} = '$vol, $server, $part, [$cell], [$force] => Success?';
744 sub AFS_vos_zap {
745   my($vol, $server, $part, $cell, $force) = @_;
746   my(@args);
747
748   @args = ('zap', '-id', $vol, '-server', $server, '-part', $part);
749   push(@args, '-force')            if ($force);
750   push(@args, '-noauth')           if ($AFS_Parms{'authlvl'} == 0);
751   push(@args, '-localauth')        if ($AFS_Parms{'authlvl'} == 2);
752   push(@args, '-verbose')          if ($AFS_Parms{'vostrace'} > 1);
753   push(@args, '-cell', $cell ? $cell : $AFS_Parms{'cell'});
754   &wrapper('vos', \@args,
755            [$vos_err_parse,
756             $AFS_Parms{'vostrace'} ? ([ '', '?']) : () ]);
757   1;
758 }
759
760
761 #: AFS_vos_status($server, [$cell])
762 #: Get information about outstanding transactions on $server
763 #: If specified, work in $cell instead of the default cell
764 #: On success, return a list of transactions, each of which is a reference
765 #: to an associative array containing some or all of these elements:
766 #: - transid      Transaction ID
767 #: - stamp_create Time the transaction was created
768 #: - volid        Volume ID
769 #: - part         Partition letter
770 #: - action       Action or procedure
771 #: - flags        Volume attach flags
772 #: If there are no transactions, the list will be empty.
773 #:
774 $AFS_Help{vos_status} = '$server, [$cell] => @trans';
775 sub AFS_vos_status {
776   my($server, $cell) = @_;
777   my(@trlist);
778
779   @args = ('status', '-server', $server);
780   push(@args, '-noauth')           if ($AFS_Parms{'authlvl'} == 0);
781   push(@args, '-localauth')        if ($AFS_Parms{'authlvl'} == 2);
782   push(@args, '-verbose')          if ($AFS_Parms{'vostrace'} > 2);
783   push(@args, '-cell', $cell ? $cell : $AFS_Parms{'cell'});
784   &wrapper('vos', \@args,
785            [$vos_err_parse,
786             ['^(\-)', sub {
787               my(%trinfo) = %OpenAFS::wrapper::result;
788               
789               if ($trinfo{transid}) {
790                 push(@trlist, \%trinfo);
791                 %OpenAFS::wrapper::result = ();
792               }
793             }],
794             ['^transaction\:\s*(\d+)\s*created: (.*\S+)',        'transid', 'stamp_create'],
795             ['^attachFlags:\s*(.*\S+)',                          'flags'],
796             ['^volume:\s*(\d+)\s*partition\: \/vicep(\S+)\s*procedure\:\s*(\S+)',
797              'volid', 'part', 'action'],
798             ($AFS_Parms{'vostrace'} > 2) ? ([ '', '?']) : () ]);
799
800   @trlist;
801 }
802
803 1;