Update NEWS for 1.6.22
[pkg-k5-afs_openafs.git] / src / volser / vos.c
bloba7b4851fc2ea89082798ad9f347c567a1f548626
1 /*
2 * Copyright 2000, International Business Machines Corporation and others.
3 * All Rights Reserved.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
8 */
10 #include <afsconfig.h>
11 #include <afs/param.h>
13 #ifdef IGNORE_SOME_GCC_WARNINGS
14 # pragma GCC diagnostic warning "-Wimplicit-function-declaration"
15 #endif
17 #include <sys/types.h>
18 #include <string.h>
19 #ifdef HAVE_STDINT_H
20 # include <stdint.h>
21 #endif
22 #ifdef AFS_NT40_ENV
23 #include <fcntl.h>
24 #include <io.h>
25 #include <winsock2.h>
26 #include <WINNT/afsreg.h>
27 #else
28 #include <sys/time.h>
29 #include <sys/file.h>
30 #include <netdb.h>
31 #include <netinet/in.h>
32 #include <arpa/inet.h>
33 #endif
34 #include <sys/stat.h>
35 #ifdef AFS_AIX_ENV
36 #include <sys/statfs.h>
37 #endif
38 #include <errno.h>
40 #include <lock.h>
41 #include <afs/stds.h>
42 #include <rx/xdr.h>
43 #include <rx/rx.h>
44 #include <rx/rx_globals.h>
45 #include <afs/nfs.h>
46 #include <afs/vlserver.h>
47 #include <afs/cellconfig.h>
48 #include <afs/keys.h>
49 #include <afs/afsutil.h>
50 #include <ubik.h>
51 #include <afs/afsint.h>
52 #include <afs/cmd.h>
53 #include <afs/usd.h>
54 #include "volser.h"
55 #include "volint.h"
56 #include <afs/ihandle.h>
57 #include <afs/vnode.h>
58 #include <afs/volume.h>
59 #include <afs/com_err.h>
60 #include "dump.h"
61 #include "lockdata.h"
63 #ifdef AFS_AIX32_ENV
64 #include <signal.h>
65 #endif
66 #include "volser_internal.h"
67 #include "volser_prototypes.h"
68 #include "vsutils_prototypes.h"
69 #include "lockprocs_prototypes.h"
71 #ifdef HAVE_POSIX_REGEX
72 #include <regex.h>
73 #endif
75 /* Local Prototypes */
76 int PrintDiagnostics(char *astring, afs_int32 acode);
77 int GetVolumeInfo(afs_uint32 volid, afs_uint32 *server, afs_int32 *part,
78 afs_int32 *voltype, struct nvldbentry *rentry);
80 struct tqElem {
81 afs_uint32 volid;
82 struct tqElem *next;
85 struct tqHead {
86 afs_int32 count;
87 struct tqElem *next;
90 #define COMMONPARMS cmd_Seek(ts, 12);\
91 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");\
92 cmd_AddParm(ts, "-noauth", CMD_FLAG, CMD_OPTIONAL, "don't authenticate");\
93 cmd_AddParm(ts, "-localauth",CMD_FLAG,CMD_OPTIONAL,"use server tickets");\
94 cmd_AddParm(ts, "-verbose", CMD_FLAG, CMD_OPTIONAL, "verbose");\
95 cmd_AddParm(ts, "-encrypt", CMD_FLAG, CMD_OPTIONAL, "encrypt commands");\
96 cmd_AddParm(ts, "-noresolve", CMD_FLAG, CMD_OPTIONAL, "don't resolve addresses"); \
98 #define ERROR_EXIT(code) do { \
99 error = (code); \
100 goto error_exit; \
101 } while (0)
103 int rxInitDone = 0;
104 struct rx_connection *tconn;
105 afs_uint32 tserver;
106 extern struct ubik_client *cstruct;
107 const char *confdir;
109 static struct tqHead busyHead, notokHead;
111 static void
112 qInit(struct tqHead *ahead)
114 memset(ahead, 0, sizeof(struct tqHead));
115 return;
119 static void
120 qPut(struct tqHead *ahead, afs_uint32 volid)
122 struct tqElem *elem;
124 elem = (struct tqElem *)malloc(sizeof(struct tqElem));
125 elem->next = ahead->next;
126 elem->volid = volid;
127 ahead->next = elem;
128 ahead->count++;
129 return;
132 static void
133 qGet(struct tqHead *ahead, afs_uint32 *volid)
135 struct tqElem *tmp;
137 if (ahead->count <= 0)
138 return;
139 *volid = ahead->next->volid;
140 tmp = ahead->next;
141 ahead->next = tmp->next;
142 ahead->count--;
143 free(tmp);
144 return;
147 /* returns 1 if <filename> exists else 0 */
148 static int
149 FileExists(char *filename)
151 usd_handle_t ufd;
152 int code;
153 afs_hyper_t size;
155 code = usd_Open(filename, USD_OPEN_RDONLY, 0, &ufd);
156 if (code) {
157 return 0;
159 code = USD_IOCTL(ufd, USD_IOCTL_GETSIZE, &size);
160 USD_CLOSE(ufd);
161 if (code) {
162 return 0;
164 return 1;
167 /* returns 1 if <name> doesnot end in .readonly or .backup, else 0 */
168 static int
169 VolNameOK(char *name)
171 int total;
174 total = strlen(name);
175 if (!strcmp(&name[total - 9], ".readonly")) {
176 return 0;
177 } else if (!strcmp(&name[total - 7], ".backup")) {
178 return 0;
179 } else {
180 return 1;
184 /* return 1 if name is a number else 0 */
185 static int
186 IsNumeric(char *name)
188 int result, len, i;
189 char *ptr;
191 result = 1;
192 ptr = name;
193 len = strlen(name);
194 for (i = 0; i < len; i++) {
195 if (*ptr < '0' || *ptr > '9') {
196 result = 0;
197 break;
199 ptr++;
202 return result;
207 * Parse a server dotted address and return the address in network byte order
209 afs_uint32
210 GetServerNoresolve(char *aname)
212 int b1, b2, b3, b4;
213 afs_uint32 addr;
214 afs_int32 code;
216 code = sscanf(aname, "%d.%d.%d.%d", &b1, &b2, &b3, &b4);
217 if (code == 4) {
218 addr = (b1 << 24) | (b2 << 16) | (b3 << 8) | b4;
219 addr = htonl(addr); /* convert to network byte order */
220 return addr;
221 } else
222 return 0;
225 * Parse a server name/address and return the address in network byte order
227 afs_uint32
228 GetServer(char *aname)
230 struct hostent *th;
231 afs_uint32 addr; /* in network byte order */
232 afs_int32 code;
233 char hostname[MAXHOSTCHARS];
235 if ((addr = GetServerNoresolve(aname)) == 0) {
236 th = gethostbyname(aname);
237 if (!th)
238 return 0;
239 memcpy(&addr, th->h_addr, sizeof(addr));
242 if (rx_IsLoopbackAddr(ntohl(addr))) { /* local host */
243 code = gethostname(hostname, MAXHOSTCHARS);
244 if (code)
245 return 0;
246 th = gethostbyname(hostname);
247 if (!th)
248 return 0;
249 memcpy(&addr, th->h_addr, sizeof(addr));
252 return (addr);
255 afs_int32
256 GetVolumeType(char *aname)
259 if (!strcmp(aname, "ro"))
260 return (ROVOL);
261 else if (!strcmp(aname, "rw"))
262 return (RWVOL);
263 else if (!strcmp(aname, "bk"))
264 return (BACKVOL);
265 else
266 return (-1);
270 IsPartValid(afs_int32 partId, afs_uint32 server, afs_int32 *code)
272 struct partList dummyPartList;
273 int i, success, cnt;
275 success = 0;
276 *code = 0;
278 *code = UV_ListPartitions(server, &dummyPartList, &cnt);
279 if (*code)
280 return success;
281 for (i = 0; i < cnt; i++) {
282 if (dummyPartList.partFlags[i] & PARTVALID)
283 if (dummyPartList.partId[i] == partId)
284 success = 1;
286 return success;
291 /*sends the contents of file associated with <fd> and <blksize> to Rx Stream
292 * associated with <call> */
294 SendFile(usd_handle_t ufd, struct rx_call *call, long blksize)
296 char *buffer = (char *)0;
297 afs_int32 error = 0;
298 int done = 0;
299 afs_uint32 nbytes;
301 buffer = (char *)malloc(blksize);
302 if (!buffer) {
303 fprintf(STDERR, "malloc failed\n");
304 return -1;
307 while (!error && !done) {
308 #ifndef AFS_NT40_ENV /* NT csn't select on non-socket fd's */
309 fd_set in;
310 FD_ZERO(&in);
311 FD_SET((intptr_t)(ufd->handle), &in);
312 /* don't timeout if read blocks */
313 #if defined(AFS_PTHREAD_ENV)
314 select(((intptr_t)(ufd->handle)) + 1, &in, 0, 0, 0);
315 #else
316 IOMGR_Select(((intptr_t)(ufd->handle)) + 1, &in, 0, 0, 0);
317 #endif
318 #endif
319 error = USD_READ(ufd, buffer, blksize, &nbytes);
320 if (error) {
321 fprintf(STDERR, "File system read failed: %s\n",
322 afs_error_message(error));
323 break;
325 if (nbytes == 0) {
326 done = 1;
327 break;
329 if (rx_Write(call, buffer, nbytes) != nbytes) {
330 error = -1;
331 break;
334 if (buffer)
335 free(buffer);
336 return error;
339 /* function invoked by UV_RestoreVolume, reads the data from rx_trx_stream and
340 * writes it out to the volume. */
341 afs_int32
342 WriteData(struct rx_call *call, void *rock)
344 char *filename = (char *) rock;
345 usd_handle_t ufd;
346 long blksize;
347 afs_int32 error, code;
348 int ufdIsOpen = 0;
349 afs_hyper_t filesize, currOffset;
350 afs_uint32 buffer;
351 afs_uint32 got;
353 error = 0;
355 if (!filename || !*filename) {
356 usd_StandardInput(&ufd);
357 blksize = 4096;
358 ufdIsOpen = 1;
359 } else {
360 code = usd_Open(filename, USD_OPEN_RDONLY, 0, &ufd);
361 if (code == 0) {
362 ufdIsOpen = 1;
363 code = USD_IOCTL(ufd, USD_IOCTL_GETBLKSIZE, &blksize);
365 if (code) {
366 fprintf(STDERR, "Could not access file '%s': %s\n", filename,
367 afs_error_message(code));
368 error = VOLSERBADOP;
369 goto wfail;
371 /* test if we have a valid dump */
372 hset64(filesize, 0, 0);
373 USD_SEEK(ufd, filesize, SEEK_END, &currOffset);
374 hset64(filesize, hgethi(currOffset), hgetlo(currOffset)-sizeof(afs_uint32));
375 USD_SEEK(ufd, filesize, SEEK_SET, &currOffset);
376 USD_READ(ufd, (char *)&buffer, sizeof(afs_uint32), &got);
377 if ((got != sizeof(afs_uint32)) || (ntohl(buffer) != DUMPENDMAGIC)) {
378 fprintf(STDERR, "Signature missing from end of file '%s'\n", filename);
379 error = VOLSERBADOP;
380 goto wfail;
382 /* rewind, we are done */
383 hset64(filesize, 0, 0);
384 USD_SEEK(ufd, filesize, SEEK_SET, &currOffset);
386 code = SendFile(ufd, call, blksize);
387 if (code) {
388 error = code;
389 goto wfail;
391 wfail:
392 if (ufdIsOpen) {
393 code = USD_CLOSE(ufd);
394 if (code) {
395 fprintf(STDERR, "Could not close dump file %s\n",
396 (filename && *filename) ? filename : "STDOUT");
397 if (!error)
398 error = code;
401 return error;
404 /* Receive data from <call> stream into file associated
405 * with <fd> <blksize>
408 ReceiveFile(usd_handle_t ufd, struct rx_call *call, long blksize)
410 char *buffer = NULL;
411 afs_int32 bytesread;
412 afs_uint32 bytesleft, w;
413 afs_int32 error = 0;
415 buffer = (char *)malloc(blksize);
416 if (!buffer) {
417 fprintf(STDERR, "memory allocation failed\n");
418 ERROR_EXIT(-1);
421 while ((bytesread = rx_Read(call, buffer, blksize)) > 0) {
422 for (bytesleft = bytesread; bytesleft; bytesleft -= w) {
423 #ifndef AFS_NT40_ENV /* NT csn't select on non-socket fd's */
424 fd_set out;
425 FD_ZERO(&out);
426 FD_SET((intptr_t)(ufd->handle), &out);
427 /* don't timeout if write blocks */
428 #if defined(AFS_PTHREAD_ENV)
429 select(((intptr_t)(ufd->handle)) + 1, &out, 0, 0, 0);
430 #else
431 IOMGR_Select(((intptr_t)(ufd->handle)) + 1, 0, &out, 0, 0);
432 #endif
433 #endif
434 error =
435 USD_WRITE(ufd, &buffer[bytesread - bytesleft], bytesleft, &w);
436 if (error) {
437 fprintf(STDERR, "File system write failed: %s\n",
438 afs_error_message(error));
439 ERROR_EXIT(-1);
444 error_exit:
445 if (buffer)
446 free(buffer);
447 return (error);
450 afs_int32
451 DumpFunction(struct rx_call *call, void *rock)
453 char *filename = (char *)rock;
454 usd_handle_t ufd; /* default is to stdout */
455 afs_int32 error = 0, code;
456 afs_hyper_t size;
457 long blksize;
458 int ufdIsOpen = 0;
460 /* Open the output file */
461 if (!filename || !*filename) {
462 usd_StandardOutput(&ufd);
463 blksize = 4096;
464 ufdIsOpen = 1;
465 } else {
466 code =
467 usd_Open(filename, USD_OPEN_CREATE | USD_OPEN_RDWR, 0666, &ufd);
468 if (code == 0) {
469 ufdIsOpen = 1;
470 hzero(size);
471 code = USD_IOCTL(ufd, USD_IOCTL_SETSIZE, &size);
473 if (code == 0) {
474 code = USD_IOCTL(ufd, USD_IOCTL_GETBLKSIZE, &blksize);
476 if (code) {
477 fprintf(STDERR, "Could not create file '%s': %s\n", filename,
478 afs_error_message(code));
479 ERROR_EXIT(VOLSERBADOP);
483 code = ReceiveFile(ufd, call, blksize);
484 if (code)
485 ERROR_EXIT(code);
487 error_exit:
488 /* Close the output file */
489 if (ufdIsOpen) {
490 code = USD_CLOSE(ufd);
491 if (code) {
492 fprintf(STDERR, "Could not close dump file %s\n",
493 (filename && *filename) ? filename : "STDIN");
494 if (!error)
495 error = code;
499 return (error);
502 static void
503 DisplayFormat(volintInfo *pntr, afs_uint32 server, afs_int32 part,
504 int *totalOK, int *totalNotOK, int *totalBusy, int fast,
505 int longlist, int disp)
507 char pname[10];
508 time_t t;
510 if (fast) {
511 fprintf(STDOUT, "%-10lu\n", (unsigned long)pntr->volid);
512 } else if (longlist) {
513 if (pntr->status == VOK) {
514 fprintf(STDOUT, "%-32s ", pntr->name);
515 fprintf(STDOUT, "%10lu ", (unsigned long)pntr->volid);
516 if (pntr->type == 0)
517 fprintf(STDOUT, "RW ");
518 if (pntr->type == 1)
519 fprintf(STDOUT, "RO ");
520 if (pntr->type == 2)
521 fprintf(STDOUT, "BK ");
522 fprintf(STDOUT, "%10d K ", pntr->size);
523 if (pntr->inUse == 1) {
524 fprintf(STDOUT, "On-line");
525 *totalOK += 1;
526 } else {
527 fprintf(STDOUT, "Off-line");
528 *totalNotOK += 1;
530 if (pntr->needsSalvaged == 1)
531 fprintf(STDOUT, "**needs salvage**");
532 fprintf(STDOUT, "\n");
533 MapPartIdIntoName(part, pname);
534 fprintf(STDOUT, " %s %s \n", hostutil_GetNameByINet(server),
535 pname);
536 fprintf(STDOUT, " RWrite %10lu ROnly %10lu Backup %10lu \n",
537 (unsigned long)pntr->parentID,
538 (unsigned long)pntr->cloneID,
539 (unsigned long)pntr->backupID);
540 fprintf(STDOUT, " MaxQuota %10d K \n", pntr->maxquota);
541 t = pntr->creationDate;
542 fprintf(STDOUT, " Creation %s",
543 ctime(&t));
544 t = pntr->copyDate;
545 fprintf(STDOUT, " Copy %s",
546 ctime(&t));
548 t = pntr->backupDate;
549 if (!t)
550 fprintf(STDOUT, " Backup Never\n");
551 else
552 fprintf(STDOUT, " Backup %s",
553 ctime(&t));
555 t = pntr->accessDate;
556 if (t)
557 fprintf(STDOUT, " Last Access %s",
558 ctime(&t));
560 t = pntr->updateDate;
561 if (!t)
562 fprintf(STDOUT, " Last Update Never\n");
563 else
564 fprintf(STDOUT, " Last Update %s",
565 ctime(&t));
566 fprintf(STDOUT,
567 " %d accesses in the past day (i.e., vnode references)\n",
568 pntr->dayUse);
569 } else if (pntr->status == VBUSY) {
570 *totalBusy += 1;
571 qPut(&busyHead, pntr->volid);
572 if (disp)
573 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
574 (unsigned long)pntr->volid);
575 } else {
576 *totalNotOK += 1;
577 qPut(&notokHead, pntr->volid);
578 if (disp)
579 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
580 (unsigned long)pntr->volid);
582 fprintf(STDOUT, "\n");
583 } else { /* default listing */
584 if (pntr->status == VOK) {
585 fprintf(STDOUT, "%-32s ", pntr->name);
586 fprintf(STDOUT, "%10lu ", (unsigned long)pntr->volid);
587 if (pntr->type == 0)
588 fprintf(STDOUT, "RW ");
589 if (pntr->type == 1)
590 fprintf(STDOUT, "RO ");
591 if (pntr->type == 2)
592 fprintf(STDOUT, "BK ");
593 fprintf(STDOUT, "%10d K ", pntr->size);
594 if (pntr->inUse == 1) {
595 fprintf(STDOUT, "On-line");
596 *totalOK += 1;
597 } else {
598 fprintf(STDOUT, "Off-line");
599 *totalNotOK += 1;
601 if (pntr->needsSalvaged == 1)
602 fprintf(STDOUT, "**needs salvage**");
603 fprintf(STDOUT, "\n");
604 } else if (pntr->status == VBUSY) {
605 *totalBusy += 1;
606 qPut(&busyHead, pntr->volid);
607 if (disp)
608 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
609 (unsigned long)pntr->volid);
610 } else {
611 *totalNotOK += 1;
612 qPut(&notokHead, pntr->volid);
613 if (disp)
614 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
615 (unsigned long)pntr->volid);
620 /*------------------------------------------------------------------------
621 * PRIVATE XDisplayFormat
623 * Description:
624 * Display the contents of one extended volume info structure.
626 * Arguments:
627 * a_xInfoP : Ptr to extended volume info struct to print.
628 * a_servID : Server ID to print.
629 * a_partID : Partition ID to print.
630 * a_totalOKP : Ptr to total-OK counter.
631 * a_totalNotOKP : Ptr to total-screwed counter.
632 * a_totalBusyP : Ptr to total-busy counter.
633 * a_fast : Fast listing?
634 * a_int32 : Int32 listing?
635 * a_showProblems : Show volume problems?
637 * Returns:
638 * Nothing.
640 * Environment:
641 * Nothing interesting.
643 * Side Effects:
644 * As advertised.
645 *------------------------------------------------------------------------*/
647 static void
648 XDisplayFormat(volintXInfo *a_xInfoP, afs_uint32 a_servID, afs_int32 a_partID,
649 int *a_totalOKP, int *a_totalNotOKP, int *a_totalBusyP,
650 int a_fast, int a_int32, int a_showProblems)
651 { /*XDisplayFormat */
652 time_t t;
653 char pname[10];
655 if (a_fast) {
657 * Short & sweet.
659 fprintf(STDOUT, "%-10lu\n", (unsigned long)a_xInfoP->volid);
660 } else if (a_int32) {
662 * Fully-detailed listing.
664 if (a_xInfoP->status == VOK) {
666 * Volume's status is OK - all the fields are valid.
668 fprintf(STDOUT, "%-32s ", a_xInfoP->name);
669 fprintf(STDOUT, "%10lu ", (unsigned long)a_xInfoP->volid);
670 if (a_xInfoP->type == 0)
671 fprintf(STDOUT, "RW ");
672 if (a_xInfoP->type == 1)
673 fprintf(STDOUT, "RO ");
674 if (a_xInfoP->type == 2)
675 fprintf(STDOUT, "BK ");
676 fprintf(STDOUT, "%10d K used ", a_xInfoP->size);
677 fprintf(STDOUT, "%d files ", a_xInfoP->filecount);
678 if (a_xInfoP->inUse == 1) {
679 fprintf(STDOUT, "On-line");
680 (*a_totalOKP)++;
681 } else {
682 fprintf(STDOUT, "Off-line");
683 (*a_totalNotOKP)++;
685 fprintf(STDOUT, "\n");
686 MapPartIdIntoName(a_partID, pname);
687 fprintf(STDOUT, " %s %s \n", hostutil_GetNameByINet(a_servID),
688 pname);
689 fprintf(STDOUT, " RWrite %10lu ROnly %10lu Backup %10lu \n",
690 (unsigned long)a_xInfoP->parentID,
691 (unsigned long)a_xInfoP->cloneID,
692 (unsigned long)a_xInfoP->backupID);
693 fprintf(STDOUT, " MaxQuota %10d K \n", a_xInfoP->maxquota);
695 t = a_xInfoP->creationDate;
696 fprintf(STDOUT, " Creation %s",
697 ctime(&t));
699 t = a_xInfoP->copyDate;
700 fprintf(STDOUT, " Copy %s",
701 ctime(&t));
703 t = a_xInfoP->backupDate;
704 if (!t)
705 fprintf(STDOUT, " Backup Never\n");
706 else
707 fprintf(STDOUT, " Backup %s",
708 ctime(&t));
710 t = a_xInfoP->accessDate;
711 if (t)
712 fprintf(STDOUT, " Last Access %s",
713 ctime(&t));
715 t = a_xInfoP->updateDate;
716 if (!t)
717 fprintf(STDOUT, " Last Update Never\n");
718 else
719 fprintf(STDOUT, " Last Update %s",
720 ctime(&t));
721 fprintf(STDOUT,
722 " %d accesses in the past day (i.e., vnode references)\n",
723 a_xInfoP->dayUse);
726 * Print all the read/write and authorship stats.
728 fprintf(STDOUT, "\n Raw Read/Write Stats\n");
729 fprintf(STDOUT,
730 " |-------------------------------------------|\n");
731 fprintf(STDOUT,
732 " | Same Network | Diff Network |\n");
733 fprintf(STDOUT,
734 " |----------|----------|----------|----------|\n");
735 fprintf(STDOUT,
736 " | Total | Auth | Total | Auth |\n");
737 fprintf(STDOUT,
738 " |----------|----------|----------|----------|\n");
739 fprintf(STDOUT, "Reads | %8d | %8d | %8d | %8d |\n",
740 a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET],
741 a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET_AUTH],
742 a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET],
743 a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET_AUTH]);
744 fprintf(STDOUT, "Writes | %8d | %8d | %8d | %8d |\n",
745 a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET],
746 a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET_AUTH],
747 a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET],
748 a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET_AUTH]);
749 fprintf(STDOUT,
750 " |-------------------------------------------|\n\n");
752 fprintf(STDOUT,
753 " Writes Affecting Authorship\n");
754 fprintf(STDOUT,
755 " |-------------------------------------------|\n");
756 fprintf(STDOUT,
757 " | File Authorship | Directory Authorship|\n");
758 fprintf(STDOUT,
759 " |----------|----------|----------|----------|\n");
760 fprintf(STDOUT,
761 " | Same | Diff | Same | Diff |\n");
762 fprintf(STDOUT,
763 " |----------|----------|----------|----------|\n");
764 fprintf(STDOUT, "0-60 sec | %8d | %8d | %8d | %8d |\n",
765 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_0],
766 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_0],
767 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_0],
768 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_0]);
769 fprintf(STDOUT, "1-10 min | %8d | %8d | %8d | %8d |\n",
770 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_1],
771 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_1],
772 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_1],
773 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_1]);
774 fprintf(STDOUT, "10min-1hr | %8d | %8d | %8d | %8d |\n",
775 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_2],
776 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_2],
777 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_2],
778 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_2]);
779 fprintf(STDOUT, "1hr-1day | %8d | %8d | %8d | %8d |\n",
780 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_3],
781 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_3],
782 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_3],
783 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_3]);
784 fprintf(STDOUT, "1day-1wk | %8d | %8d | %8d | %8d |\n",
785 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_4],
786 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_4],
787 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_4],
788 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_4]);
789 fprintf(STDOUT, "> 1wk | %8d | %8d | %8d | %8d |\n",
790 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_5],
791 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_5],
792 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_5],
793 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_5]);
794 fprintf(STDOUT,
795 " |-------------------------------------------|\n");
796 } /*Volume status OK */
797 else if (a_xInfoP->status == VBUSY) {
798 (*a_totalBusyP)++;
799 qPut(&busyHead, a_xInfoP->volid);
800 if (a_showProblems)
801 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
802 (unsigned long)a_xInfoP->volid);
803 } /*Busy volume */
804 else {
805 (*a_totalNotOKP)++;
806 qPut(&notokHead, a_xInfoP->volid);
807 if (a_showProblems)
808 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
809 (unsigned long)a_xInfoP->volid);
810 } /*Screwed volume */
811 fprintf(STDOUT, "\n");
812 } /*Long listing */
813 else {
815 * Default listing.
817 if (a_xInfoP->status == VOK) {
818 fprintf(STDOUT, "%-32s ", a_xInfoP->name);
819 fprintf(STDOUT, "%10lu ", (unsigned long)a_xInfoP->volid);
820 if (a_xInfoP->type == 0)
821 fprintf(STDOUT, "RW ");
822 if (a_xInfoP->type == 1)
823 fprintf(STDOUT, "RO ");
824 if (a_xInfoP->type == 2)
825 fprintf(STDOUT, "BK ");
826 fprintf(STDOUT, "%10d K ", a_xInfoP->size);
827 if (a_xInfoP->inUse == 1) {
828 fprintf(STDOUT, "On-line");
829 (*a_totalOKP)++;
830 } else {
831 fprintf(STDOUT, "Off-line");
832 (*a_totalNotOKP)++;
834 fprintf(STDOUT, "\n");
835 } /*Volume OK */
836 else if (a_xInfoP->status == VBUSY) {
837 (*a_totalBusyP)++;
838 qPut(&busyHead, a_xInfoP->volid);
839 if (a_showProblems)
840 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
841 (unsigned long)a_xInfoP->volid);
842 } /*Busy volume */
843 else {
844 (*a_totalNotOKP)++;
845 qPut(&notokHead, a_xInfoP->volid);
846 if (a_showProblems)
847 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
848 (unsigned long)a_xInfoP->volid);
849 } /*Screwed volume */
850 } /*Default listing */
851 } /*XDisplayFormat */
853 /*------------------------------------------------------------------------
854 * PRIVATE XDisplayFormat2
856 * Description:
857 * Display the formated contents of one extended volume info structure.
859 * Arguments:
860 * a_xInfoP : Ptr to extended volume info struct to print.
861 * a_servID : Server ID to print.
862 * a_partID : Partition ID to print.
863 * a_totalOKP : Ptr to total-OK counter.
864 * a_totalNotOKP : Ptr to total-screwed counter.
865 * a_totalBusyP : Ptr to total-busy counter.
866 * a_fast : Fast listing?
867 * a_int32 : Int32 listing?
868 * a_showProblems : Show volume problems?
870 * Returns:
871 * Nothing.
873 * Environment:
874 * Nothing interesting.
876 * Side Effects:
877 * As advertised.
878 *------------------------------------------------------------------------*/
880 static void
881 XDisplayFormat2(volintXInfo *a_xInfoP, afs_uint32 a_servID, afs_int32 a_partID,
882 int *a_totalOKP, int *a_totalNotOKP, int *a_totalBusyP,
883 int a_fast, int a_int32, int a_showProblems)
884 { /*XDisplayFormat */
885 time_t t;
886 if (a_fast) {
888 * Short & sweet.
890 fprintf(STDOUT, "vold_id\t%-10lu\n", (unsigned long)a_xInfoP->volid);
891 } else if (a_int32) {
893 * Fully-detailed listing.
895 if (a_xInfoP->status == VOK) {
897 * Volume's status is OK - all the fields are valid.
900 static long server_cache = -1, partition_cache = -1;
901 static char hostname[256], address[32], pname[16];
902 int i,ai[] = {VOLINT_STATS_TIME_IDX_0,VOLINT_STATS_TIME_IDX_1,VOLINT_STATS_TIME_IDX_2,
903 VOLINT_STATS_TIME_IDX_3,VOLINT_STATS_TIME_IDX_4,VOLINT_STATS_TIME_IDX_5};
905 if (a_servID != server_cache) {
906 struct in_addr s;
908 s.s_addr = a_servID;
909 strcpy(hostname, hostutil_GetNameByINet(a_servID));
910 strcpy(address, inet_ntoa(s));
911 server_cache = a_servID;
913 if (a_partID != partition_cache) {
914 MapPartIdIntoName(a_partID, pname);
915 partition_cache = a_partID;
918 fprintf(STDOUT, "name\t\t%s\n", a_xInfoP->name);
919 fprintf(STDOUT, "id\t\t%lu\n", afs_printable_uint32_lu(a_xInfoP->volid));
920 fprintf(STDOUT, "serv\t\t%s\t%s\n", address, hostname);
921 fprintf(STDOUT, "part\t\t%s\n", pname);
922 fprintf(STDOUT, "status\t\tOK\n");
923 fprintf(STDOUT, "backupID\t%lu\n",
924 afs_printable_uint32_lu(a_xInfoP->backupID));
925 fprintf(STDOUT, "parentID\t%lu\n",
926 afs_printable_uint32_lu(a_xInfoP->parentID));
927 fprintf(STDOUT, "cloneID\t\t%lu\n",
928 afs_printable_uint32_lu(a_xInfoP->cloneID));
929 fprintf(STDOUT, "inUse\t\t%s\n", a_xInfoP->inUse ? "Y" : "N");
930 switch (a_xInfoP->type) {
931 case 0:
932 fprintf(STDOUT, "type\t\tRW\n");
933 break;
934 case 1:
935 fprintf(STDOUT, "type\t\tRO\n");
936 break;
937 case 2:
938 fprintf(STDOUT, "type\t\tBK\n");
939 break;
940 default:
941 fprintf(STDOUT, "type\t\t?\n");
942 break;
944 t = a_xInfoP->creationDate;
945 fprintf(STDOUT, "creationDate\t%-9lu\t%s",
946 afs_printable_uint32_lu(a_xInfoP->creationDate),
947 ctime(&t));
949 t = a_xInfoP->accessDate;
950 fprintf(STDOUT, "accessDate\t%-9lu\t%s",
951 afs_printable_uint32_lu(a_xInfoP->accessDate),
952 ctime(&t));
954 t = a_xInfoP->updateDate;
955 fprintf(STDOUT, "updateDate\t%-9lu\t%s",
956 afs_printable_uint32_lu(a_xInfoP->updateDate),
957 ctime(&t));
959 t = a_xInfoP->backupDate;
960 fprintf(STDOUT, "backupDate\t%-9lu\t%s",
961 afs_printable_uint32_lu(a_xInfoP->backupDate),
962 ctime(&t));
964 t = a_xInfoP->copyDate;
965 fprintf(STDOUT, "copyDate\t%-9lu\t%s",
966 afs_printable_uint32_lu(a_xInfoP->copyDate),
967 ctime(&t));
969 fprintf(STDOUT, "diskused\t%u\n", a_xInfoP->size);
970 fprintf(STDOUT, "maxquota\t%u\n", a_xInfoP->maxquota);
972 fprintf(STDOUT, "filecount\t%u\n", a_xInfoP->filecount);
973 fprintf(STDOUT, "dayUse\t\t%u\n", a_xInfoP->dayUse);
977 fprintf(STDOUT,"reads_same_net\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET]);
978 fprintf(STDOUT,"reads_same_net_auth\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET_AUTH]);
979 fprintf(STDOUT,"reads_diff_net\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET]);
980 fprintf(STDOUT,"reads_diff_net_auth\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET_AUTH]);
982 fprintf(STDOUT,"writes_same_net\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET]);
983 fprintf(STDOUT,"writes_same_net_auth\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET_AUTH]);
984 fprintf(STDOUT,"writes_diff_net\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET]);
985 fprintf(STDOUT,"writes_diff_net_auth\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET_AUTH]);
987 for(i=0;i<5;i++)
989 fprintf(STDOUT,"file_same_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_fileSameAuthor[ai[i]]);
990 fprintf(STDOUT,"file_diff_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_fileDiffAuthor[ai[i]]);
991 fprintf(STDOUT,"dir_same_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_dirSameAuthor[ai[i]]);
992 fprintf(STDOUT,"dir_dif_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_dirDiffAuthor[ai[i]]);
995 } /*Volume status OK */
996 else if (a_xInfoP->status == VBUSY) {
997 (*a_totalBusyP)++;
998 qPut(&busyHead, a_xInfoP->volid);
999 if (a_showProblems)
1000 fprintf(STDOUT, "BUSY_VOL\t%lu\n",
1001 (unsigned long)a_xInfoP->volid);
1002 } /*Busy volume */
1003 else {
1004 (*a_totalNotOKP)++;
1005 qPut(&notokHead, a_xInfoP->volid);
1006 if (a_showProblems)
1007 fprintf(STDOUT, "COULD_NOT_ATTACH\t%lu\n",
1008 (unsigned long)a_xInfoP->volid);
1009 } /*Screwed volume */
1010 } /*Long listing */
1011 else {
1013 * Default listing.
1015 if (a_xInfoP->status == VOK) {
1016 fprintf(STDOUT, "name\t%-32s\n", a_xInfoP->name);
1017 fprintf(STDOUT, "volID\t%10lu\n", (unsigned long)a_xInfoP->volid);
1018 if (a_xInfoP->type == 0)
1019 fprintf(STDOUT, "type\tRW\n");
1020 if (a_xInfoP->type == 1)
1021 fprintf(STDOUT, "type\tRO\n");
1022 if (a_xInfoP->type == 2)
1023 fprintf(STDOUT, "type\tBK\n");
1024 fprintf(STDOUT, "size\t%10dK\n", a_xInfoP->size);
1026 fprintf(STDOUT, "inUse\t%d\n",a_xInfoP->inUse);
1027 if (a_xInfoP->inUse == 1)
1028 (*a_totalOKP)++;
1029 else
1030 (*a_totalNotOKP)++;
1032 } /*Volume OK */
1033 else if (a_xInfoP->status == VBUSY) {
1034 (*a_totalBusyP)++;
1035 qPut(&busyHead, a_xInfoP->volid);
1036 if (a_showProblems)
1037 fprintf(STDOUT, "VOLUME_BUSY\t%lu\n",
1038 (unsigned long)a_xInfoP->volid);
1039 } /*Busy volume */
1040 else {
1041 (*a_totalNotOKP)++;
1042 qPut(&notokHead, a_xInfoP->volid);
1043 if (a_showProblems)
1044 fprintf(STDOUT, "COULD_NOT_ATTACH_VOLUME\t%lu\n",
1045 (unsigned long)a_xInfoP->volid);
1046 } /*Screwed volume */
1047 } /*Default listing */
1048 } /*XDisplayFormat */
1050 static void
1051 DisplayFormat2(long server, long partition, volintInfo *pntr)
1053 static long server_cache = -1, partition_cache = -1;
1054 static char hostname[256], address[32], pname[16];
1055 time_t t;
1057 if (server != server_cache) {
1058 struct in_addr s;
1060 s.s_addr = server;
1061 strcpy(hostname, hostutil_GetNameByINet(server));
1062 strcpy(address, inet_ntoa(s));
1063 server_cache = server;
1065 if (partition != partition_cache) {
1066 MapPartIdIntoName(partition, pname);
1067 partition_cache = partition;
1070 if (pntr->status == VOK)
1071 fprintf(STDOUT, "name\t\t%s\n", pntr->name);
1073 fprintf(STDOUT, "id\t\t%lu\n",
1074 afs_printable_uint32_lu(pntr->volid));
1075 fprintf(STDOUT, "serv\t\t%s\t%s\n", address, hostname);
1076 fprintf(STDOUT, "part\t\t%s\n", pname);
1077 switch (pntr->status) {
1078 case VOK:
1079 fprintf(STDOUT, "status\t\tOK\n");
1080 break;
1081 case VBUSY:
1082 fprintf(STDOUT, "status\t\tBUSY\n");
1083 return;
1084 default:
1085 fprintf(STDOUT, "status\t\tUNATTACHABLE\n");
1086 return;
1088 fprintf(STDOUT, "backupID\t%lu\n",
1089 afs_printable_uint32_lu(pntr->backupID));
1090 fprintf(STDOUT, "parentID\t%lu\n",
1091 afs_printable_uint32_lu(pntr->parentID));
1092 fprintf(STDOUT, "cloneID\t\t%lu\n",
1093 afs_printable_uint32_lu(pntr->cloneID));
1094 fprintf(STDOUT, "inUse\t\t%s\n", pntr->inUse ? "Y" : "N");
1095 fprintf(STDOUT, "needsSalvaged\t%s\n", pntr->needsSalvaged ? "Y" : "N");
1096 /* 0xD3 is from afs/volume.h since I had trouble including the file */
1097 fprintf(STDOUT, "destroyMe\t%s\n", pntr->destroyMe == 0xD3 ? "Y" : "N");
1098 switch (pntr->type) {
1099 case 0:
1100 fprintf(STDOUT, "type\t\tRW\n");
1101 break;
1102 case 1:
1103 fprintf(STDOUT, "type\t\tRO\n");
1104 break;
1105 case 2:
1106 fprintf(STDOUT, "type\t\tBK\n");
1107 break;
1108 default:
1109 fprintf(STDOUT, "type\t\t?\n");
1110 break;
1112 t = pntr->creationDate;
1113 fprintf(STDOUT, "creationDate\t%-9lu\t%s",
1114 afs_printable_uint32_lu(pntr->creationDate),
1115 ctime(&t));
1117 t = pntr->accessDate;
1118 fprintf(STDOUT, "accessDate\t%-9lu\t%s",
1119 afs_printable_uint32_lu(pntr->accessDate),
1120 ctime(&t));
1122 t = pntr->updateDate;
1123 fprintf(STDOUT, "updateDate\t%-9lu\t%s",
1124 afs_printable_uint32_lu(pntr->updateDate),
1125 ctime(&t));
1127 t = pntr->backupDate;
1128 fprintf(STDOUT, "backupDate\t%-9lu\t%s",
1129 afs_printable_uint32_lu(pntr->backupDate),
1130 ctime(&t));
1132 t = pntr->copyDate;
1133 fprintf(STDOUT, "copyDate\t%-9lu\t%s",
1134 afs_printable_uint32_lu(pntr->copyDate),
1135 ctime(&t));
1137 fprintf(STDOUT, "flags\t\t%#lx\t(Optional)\n",
1138 afs_printable_uint32_lu(pntr->flags));
1139 fprintf(STDOUT, "diskused\t%u\n", pntr->size);
1140 fprintf(STDOUT, "maxquota\t%u\n", pntr->maxquota);
1141 fprintf(STDOUT, "minquota\t%lu\t(Optional)\n",
1142 afs_printable_uint32_lu(pntr->spare0));
1143 fprintf(STDOUT, "filecount\t%u\n", pntr->filecount);
1144 fprintf(STDOUT, "dayUse\t\t%u\n", pntr->dayUse);
1145 fprintf(STDOUT, "weekUse\t\t%lu\t(Optional)\n",
1146 afs_printable_uint32_lu(pntr->spare1));
1147 fprintf(STDOUT, "spare2\t\t%lu\t(Optional)\n",
1148 afs_printable_uint32_lu(pntr->spare2));
1149 fprintf(STDOUT, "spare3\t\t%lu\t(Optional)\n",
1150 afs_printable_uint32_lu(pntr->spare3));
1151 return;
1154 static void
1155 DisplayVolumes2(long server, long partition, volintInfo *pntr, long count)
1157 long i;
1159 for (i = 0; i < count; i++) {
1160 fprintf(STDOUT, "BEGIN_OF_ENTRY\n");
1161 DisplayFormat2(server, partition, pntr);
1162 fprintf(STDOUT, "END_OF_ENTRY\n\n");
1163 pntr++;
1165 return;
1168 static void
1169 DisplayVolumes(afs_uint32 server, afs_int32 part, volintInfo *pntr,
1170 afs_int32 count, afs_int32 longlist, afs_int32 fast,
1171 int quiet)
1173 int totalOK, totalNotOK, totalBusy, i;
1174 afs_uint32 volid = 0;
1176 totalOK = 0;
1177 totalNotOK = 0;
1178 totalBusy = 0;
1179 qInit(&busyHead);
1180 qInit(&notokHead);
1181 for (i = 0; i < count; i++) {
1182 DisplayFormat(pntr, server, part, &totalOK, &totalNotOK, &totalBusy,
1183 fast, longlist, 0);
1184 pntr++;
1186 if (totalBusy) {
1187 while (busyHead.count) {
1188 qGet(&busyHead, &volid);
1189 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
1190 (unsigned long)volid);
1193 if (totalNotOK) {
1194 while (notokHead.count) {
1195 qGet(&notokHead, &volid);
1196 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
1197 (unsigned long)volid);
1200 if (!quiet) {
1201 fprintf(STDOUT, "\n");
1202 if (!fast) {
1203 fprintf(STDOUT,
1204 "Total volumes onLine %d ; Total volumes offLine %d ; Total busy %d\n\n",
1205 totalOK, totalNotOK, totalBusy);
1209 /*------------------------------------------------------------------------
1210 * PRIVATE XDisplayVolumes
1212 * Description:
1213 * Display extended volume information.
1215 * Arguments:
1216 * a_servID : Pointer to the Rx call we're performing.
1217 * a_partID : Partition for which we want the extended list.
1218 * a_xInfoP : Ptr to extended volume info.
1219 * a_count : Number of volume records contained above.
1220 * a_int32 : Int32 listing generated?
1221 * a_fast : Fast listing generated?
1222 * a_quiet : Quiet listing generated?
1224 * Returns:
1225 * Nothing.
1227 * Environment:
1228 * Nothing interesting.
1230 * Side Effects:
1231 * As advertised.
1232 *------------------------------------------------------------------------*/
1234 static void
1235 XDisplayVolumes(afs_uint32 a_servID, afs_int32 a_partID, volintXInfo *a_xInfoP,
1236 afs_int32 a_count, afs_int32 a_int32, afs_int32 a_fast,
1237 int a_quiet)
1238 { /*XDisplayVolumes */
1240 int totalOK; /*Total OK volumes */
1241 int totalNotOK; /*Total screwed volumes */
1242 int totalBusy; /*Total busy volumes */
1243 int i; /*Loop variable */
1244 afs_uint32 volid = 0; /*Current volume ID */
1247 * Initialize counters and (global!!) queues.
1249 totalOK = 0;
1250 totalNotOK = 0;
1251 totalBusy = 0;
1252 qInit(&busyHead);
1253 qInit(&notokHead);
1256 * Display each volume in the list.
1258 for (i = 0; i < a_count; i++) {
1259 XDisplayFormat(a_xInfoP, a_servID, a_partID, &totalOK, &totalNotOK,
1260 &totalBusy, a_fast, a_int32, 0);
1261 a_xInfoP++;
1265 * If any volumes were found to be busy or screwed, display them.
1267 if (totalBusy) {
1268 while (busyHead.count) {
1269 qGet(&busyHead, &volid);
1270 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
1271 (unsigned long)volid);
1274 if (totalNotOK) {
1275 while (notokHead.count) {
1276 qGet(&notokHead, &volid);
1277 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
1278 (unsigned long)volid);
1282 if (!a_quiet) {
1283 fprintf(STDOUT, "\n");
1284 if (!a_fast) {
1285 fprintf(STDOUT,
1286 "Total volumes: %d on-line, %d off-line, %d busyd\n\n",
1287 totalOK, totalNotOK, totalBusy);
1291 } /*XDisplayVolumes */
1293 /*------------------------------------------------------------------------
1294 * PRIVATE XDisplayVolumes2
1296 * Description:
1297 * Display extended formated volume information.
1299 * Arguments:
1300 * a_servID : Pointer to the Rx call we're performing.
1301 * a_partID : Partition for which we want the extended list.
1302 * a_xInfoP : Ptr to extended volume info.
1303 * a_count : Number of volume records contained above.
1304 * a_int32 : Int32 listing generated?
1305 * a_fast : Fast listing generated?
1306 * a_quiet : Quiet listing generated?
1308 * Returns:
1309 * Nothing.
1311 * Environment:
1312 * Nothing interesting.
1314 * Side Effects:
1315 * As advertised.
1316 *------------------------------------------------------------------------*/
1318 static void
1319 XDisplayVolumes2(afs_uint32 a_servID, afs_int32 a_partID, volintXInfo *a_xInfoP,
1320 afs_int32 a_count, afs_int32 a_int32, afs_int32 a_fast,
1321 int a_quiet)
1322 { /*XDisplayVolumes */
1324 int totalOK; /*Total OK volumes */
1325 int totalNotOK; /*Total screwed volumes */
1326 int totalBusy; /*Total busy volumes */
1327 int i; /*Loop variable */
1328 afs_uint32 volid = 0; /*Current volume ID */
1331 * Initialize counters and (global!!) queues.
1333 totalOK = 0;
1334 totalNotOK = 0;
1335 totalBusy = 0;
1336 qInit(&busyHead);
1337 qInit(&notokHead);
1340 * Display each volume in the list.
1342 for (i = 0; i < a_count; i++) {
1343 fprintf(STDOUT, "BEGIN_OF_ENTRY\n");
1344 XDisplayFormat2(a_xInfoP, a_servID, a_partID, &totalOK, &totalNotOK,
1345 &totalBusy, a_fast, a_int32, 0);
1346 fprintf(STDOUT, "END_OF_ENTRY\n");
1347 a_xInfoP++;
1351 * If any volumes were found to be busy or screwed, display them.
1353 if (totalBusy) {
1354 while (busyHead.count) {
1355 qGet(&busyHead, &volid);
1356 fprintf(STDOUT, "BUSY_VOL\t%lu\n",
1357 (unsigned long)volid);
1360 if (totalNotOK) {
1361 while (notokHead.count) {
1362 qGet(&notokHead, &volid);
1363 fprintf(STDOUT, "COULD_NOT_ATTACH\t%lu\n",
1364 (unsigned long)volid);
1368 if (!a_quiet) {
1369 fprintf(STDOUT, "\n");
1370 if (!a_fast) {
1371 fprintf(STDOUT,
1372 "VOLUMES_ONLINE\t%d\nVOLUMES_OFFLINE\t%d\nVOLUMES_BUSY\t%d\n",
1373 totalOK, totalNotOK, totalBusy);
1377 } /*XDisplayVolumes2 */
1380 /* set <server> and <part> to the correct values depending on
1381 * <voltype> and <entry> */
1382 static void
1383 GetServerAndPart(struct nvldbentry *entry, int voltype, afs_uint32 *server,
1384 afs_int32 *part, int *previdx)
1386 int i, istart, vtype;
1388 *server = -1;
1389 *part = -1;
1391 /* Doesn't check for non-existance of backup volume */
1392 if ((voltype == RWVOL) || (voltype == BACKVOL)) {
1393 vtype = ITSRWVOL;
1394 istart = 0; /* seach the entire entry */
1395 } else {
1396 vtype = ITSROVOL;
1397 /* Seach from beginning of entry or pick up where we left off */
1398 istart = ((*previdx < 0) ? 0 : *previdx + 1);
1401 for (i = istart; i < entry->nServers; i++) {
1402 if (entry->serverFlags[i] & vtype) {
1403 *server = entry->serverNumber[i];
1404 *part = entry->serverPartition[i];
1405 *previdx = i;
1406 return;
1410 /* Didn't find any, return -1 */
1411 *previdx = -1;
1412 return;
1415 static void
1416 PrintLocked(afs_int32 aflags)
1418 afs_int32 flags = aflags & VLOP_ALLOPERS;
1420 if (flags) {
1421 fprintf(STDOUT, " Volume is currently LOCKED \n");
1423 if (flags & VLOP_MOVE) {
1424 fprintf(STDOUT, " Volume is locked for a move operation\n");
1426 if (flags & VLOP_RELEASE) {
1427 fprintf(STDOUT, " Volume is locked for a release operation\n");
1429 if (flags & VLOP_BACKUP) {
1430 fprintf(STDOUT, " Volume is locked for a backup operation\n");
1432 if (flags & VLOP_DELETE) {
1433 fprintf(STDOUT, " Volume is locked for a delete/misc operation\n");
1435 if (flags & VLOP_DUMP) {
1436 fprintf(STDOUT, " Volume is locked for a dump/restore operation\n");
1441 static void
1442 PostVolumeStats(struct nvldbentry *entry)
1444 SubEnumerateEntry(entry);
1445 /* Check for VLOP_ALLOPERS */
1446 PrintLocked(entry->flags);
1447 return;
1450 /*------------------------------------------------------------------------
1451 * PRIVATE XVolumeStats
1453 * Description:
1454 * Display extended volume information.
1456 * Arguments:
1457 * a_xInfoP : Ptr to extended volume info.
1458 * a_entryP : Ptr to the volume's VLDB entry.
1459 * a_srvID : Server ID.
1460 * a_partID : Partition ID.
1461 * a_volType : Type of volume to print.
1463 * Returns:
1464 * Nothing.
1466 * Environment:
1467 * Nothing interesting.
1469 * Side Effects:
1470 * As advertised.
1471 *------------------------------------------------------------------------*/
1473 static void
1474 XVolumeStats(volintXInfo *a_xInfoP, struct nvldbentry *a_entryP,
1475 afs_int32 a_srvID, afs_int32 a_partID, int a_volType)
1476 { /*XVolumeStats */
1478 int totalOK, totalNotOK, totalBusy; /*Dummies - we don't really count here */
1480 XDisplayFormat(a_xInfoP, /*Ptr to extended volume info */
1481 a_srvID, /*Server ID to print */
1482 a_partID, /*Partition ID to print */
1483 &totalOK, /*Ptr to total-OK counter */
1484 &totalNotOK, /*Ptr to total-screwed counter */
1485 &totalBusy, /*Ptr to total-busy counter */
1486 0, /*Don't do a fast listing */
1487 1, /*Do a long listing */
1488 1); /*Show volume problems */
1489 return;
1491 } /*XVolumeStats */
1493 static void
1494 VolumeStats_int(volintInfo *pntr, struct nvldbentry *entry, afs_uint32 server,
1495 afs_int32 part, int voltype)
1497 int totalOK, totalNotOK, totalBusy;
1499 DisplayFormat(pntr, server, part, &totalOK, &totalNotOK, &totalBusy, 0, 1,
1501 return;
1504 /* command to forcibly remove a volume */
1505 static int
1506 NukeVolume(struct cmd_syndesc *as)
1508 afs_int32 code;
1509 afs_uint32 volID;
1510 afs_int32 err;
1511 afs_int32 partID;
1512 afs_uint32 server;
1513 char *tp;
1515 server = GetServer(tp = as->parms[0].items->data);
1516 if (!server) {
1517 fprintf(STDERR, "vos: server '%s' not found in host table\n", tp);
1518 return 1;
1521 partID = volutil_GetPartitionID(tp = as->parms[1].items->data);
1522 if (partID == -1) {
1523 fprintf(STDERR, "vos: could not parse '%s' as a partition name", tp);
1524 return 1;
1527 volID = vsu_GetVolumeID(tp = as->parms[2].items->data, cstruct, &err);
1528 if (volID == 0) {
1529 if (err)
1530 PrintError("", err);
1531 else
1532 fprintf(STDERR,
1533 "vos: could not parse '%s' as a numeric volume ID", tp);
1534 return 1;
1537 fprintf(STDOUT,
1538 "vos: forcibly removing all traces of volume %d, please wait...",
1539 volID);
1540 fflush(STDOUT);
1541 code = UV_NukeVolume(server, partID, volID);
1542 if (code == 0)
1543 fprintf(STDOUT, "done.\n");
1544 else
1545 fprintf(STDOUT, "failed with code %d.\n", code);
1546 return code;
1550 /*------------------------------------------------------------------------
1551 * PRIVATE ExamineVolume
1553 * Description:
1554 * Routine used to examine a single volume, contacting the VLDB as
1555 * well as the Volume Server.
1557 * Arguments:
1558 * as : Ptr to parsed command line arguments.
1560 * Returns:
1561 * 0 for a successful operation,
1562 * Otherwise, one of the ubik or VolServer error values.
1564 * Environment:
1565 * Nothing interesting.
1567 * Side Effects:
1568 * As advertised.
1569 *------------------------------------------------------------------------
1571 static int
1572 ExamineVolume(struct cmd_syndesc *as, void *arock)
1574 struct nvldbentry entry;
1575 afs_int32 vcode = 0;
1576 volintInfo *pntr = (volintInfo *) 0;
1577 volintXInfo *xInfoP = (volintXInfo *) 0;
1578 afs_uint32 volid;
1579 afs_int32 code, err, error = 0;
1580 int voltype, foundserv = 0, foundentry = 0;
1581 afs_uint32 aserver;
1582 afs_int32 apart;
1583 int previdx = -1;
1584 int wantExtendedInfo; /*Do we want extended vol info? */
1585 int isSubEnum=0; /* Keep track whether sub enumerate called. */
1586 wantExtendedInfo = (as->parms[1].items ? 1 : 0); /* -extended */
1588 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); /* -id */
1589 if (volid == 0) {
1590 if (err)
1591 PrintError("", err);
1592 else
1593 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1594 as->parms[0].items->data);
1595 return -1;
1598 if (verbose) {
1599 fprintf(STDOUT, "Fetching VLDB entry for %lu .. ",
1600 (unsigned long)volid);
1601 fflush(STDOUT);
1603 vcode = VLDB_GetEntryByID(volid, -1, &entry);
1604 if (vcode) {
1605 fprintf(STDERR,
1606 "Could not fetch the entry for volume number %lu from VLDB \n",
1607 (unsigned long)volid);
1608 return (vcode);
1610 if (verbose)
1611 fprintf(STDOUT, "done\n");
1612 MapHostToNetwork(&entry);
1614 if (entry.volumeId[RWVOL] == volid)
1615 voltype = RWVOL;
1616 else if (entry.volumeId[BACKVOL] == volid)
1617 voltype = BACKVOL;
1618 else /* (entry.volumeId[ROVOL] == volid) */
1619 voltype = ROVOL;
1621 do { /* do {...} while (voltype == ROVOL) */
1622 /* Get the entry for the volume. If its a RW vol, get the RW entry.
1623 * It its a BK vol, get the RW entry (even if VLDB may say the BK doen't exist).
1624 * If its a RO vol, get the next RO entry.
1626 GetServerAndPart(&entry, ((voltype == ROVOL) ? ROVOL : RWVOL),
1627 &aserver, &apart, &previdx);
1628 if (previdx == -1) { /* searched all entries */
1629 if (!foundentry) {
1630 fprintf(STDERR, "Volume %s does not exist in VLDB\n\n",
1631 as->parms[0].items->data);
1632 error = ENOENT;
1634 break;
1636 foundentry = 1;
1638 /* Get information about the volume from the server */
1639 if (verbose) {
1640 fprintf(STDOUT, "Getting volume listing from the server %s .. ",
1641 hostutil_GetNameByINet(aserver));
1642 fflush(STDOUT);
1644 if (wantExtendedInfo)
1645 code = UV_XListOneVolume(aserver, apart, volid, &xInfoP);
1646 else
1647 code = UV_ListOneVolume(aserver, apart, volid, &pntr);
1648 if (verbose)
1649 fprintf(STDOUT, "done\n");
1651 if (code) {
1652 error = code;
1653 if (code == ENODEV) {
1654 if ((voltype == BACKVOL) && !(entry.flags & BACK_EXISTS)) {
1655 /* The VLDB says there is no backup volume and its not on disk */
1656 fprintf(STDERR, "Volume %s does not exist\n",
1657 as->parms[0].items->data);
1658 error = ENOENT;
1659 } else {
1660 fprintf(STDERR,
1661 "Volume does not exist on server %s as indicated by the VLDB\n",
1662 hostutil_GetNameByINet(aserver));
1664 } else {
1665 PrintDiagnostics("examine", code);
1667 fprintf(STDOUT, "\n");
1668 } else {
1669 foundserv = 1;
1670 if (wantExtendedInfo)
1671 XVolumeStats(xInfoP, &entry, aserver, apart, voltype);
1672 else if (as->parms[2].items) {
1673 DisplayFormat2(aserver, apart, pntr);
1674 EnumerateEntry(&entry);
1675 isSubEnum = 1;
1676 } else
1677 VolumeStats_int(pntr, &entry, aserver, apart, voltype);
1679 if ((voltype == BACKVOL) && !(entry.flags & BACK_EXISTS)) {
1680 /* The VLDB says there is no backup volume yet we found one on disk */
1681 fprintf(STDERR, "Volume %s does not exist in VLDB\n",
1682 as->parms[0].items->data);
1683 error = ENOENT;
1687 if (pntr)
1688 free(pntr);
1689 if (xInfoP)
1690 free(xInfoP);
1691 } while (voltype == ROVOL);
1693 if (!foundserv) {
1694 fprintf(STDERR, "Dump only information from VLDB\n\n");
1695 fprintf(STDOUT, "%s \n", entry.name); /* PostVolumeStats doesn't print name */
1698 if (!isSubEnum)
1699 PostVolumeStats(&entry);
1701 return (error);
1704 /*------------------------------------------------------------------------
1705 * PRIVATE SetFields
1707 * Description:
1708 * Routine used to change the status of a single volume.
1710 * Arguments:
1711 * as : Ptr to parsed command line arguments.
1713 * Returns:
1714 * 0 for a successful operation,
1715 * Otherwise, one of the ubik or VolServer error values.
1717 * Environment:
1718 * Nothing interesting.
1720 * Side Effects:
1721 * As advertised.
1722 *------------------------------------------------------------------------
1724 static int
1725 SetFields(struct cmd_syndesc *as, void *arock)
1727 struct nvldbentry entry;
1728 volintInfo info;
1729 afs_uint32 volid;
1730 afs_int32 code, err;
1731 afs_uint32 aserver;
1732 afs_int32 apart;
1733 int previdx = -1;
1735 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); /* -id */
1736 if (volid == 0) {
1737 if (err)
1738 PrintError("", err);
1739 else
1740 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1741 as->parms[0].items->data);
1742 return -1;
1745 code = VLDB_GetEntryByID(volid, RWVOL, &entry);
1746 if (code) {
1747 fprintf(STDERR,
1748 "Could not fetch the entry for volume number %lu from VLDB \n",
1749 (unsigned long)volid);
1750 return (code);
1752 MapHostToNetwork(&entry);
1754 GetServerAndPart(&entry, RWVOL, &aserver, &apart, &previdx);
1755 if (previdx == -1) {
1756 fprintf(STDERR, "Volume %s does not exist in VLDB\n\n",
1757 as->parms[0].items->data);
1758 return (ENOENT);
1761 init_volintInfo(&info);
1762 info.volid = volid;
1763 info.type = RWVOL;
1765 if (as->parms[1].items) {
1766 /* -max <quota> */
1767 code = util_GetHumanInt32(as->parms[1].items->data, &info.maxquota);
1768 if (code) {
1769 fprintf(STDERR, "invalid quota value\n");
1770 return code;
1773 if (as->parms[2].items) {
1774 /* -clearuse */
1775 info.dayUse = 0;
1777 if (as->parms[3].items) {
1778 /* -clearVolUpCounter */
1779 info.spare2 = 0;
1781 code = UV_SetVolumeInfo(aserver, apart, volid, &info);
1782 if (code)
1783 fprintf(STDERR,
1784 "Could not update volume info fields for volume number %lu\n",
1785 (unsigned long)volid);
1786 return (code);
1789 /*------------------------------------------------------------------------
1790 * PRIVATE volOnline
1792 * Description:
1793 * Brings a volume online.
1795 * Arguments:
1796 * as : Ptr to parsed command line arguments.
1798 * Returns:
1799 * 0 for a successful operation,
1801 * Environment:
1802 * Nothing interesting.
1804 * Side Effects:
1805 * As advertised.
1806 *------------------------------------------------------------------------
1808 static int
1809 volOnline(struct cmd_syndesc *as, void *arock)
1811 afs_uint32 server;
1812 afs_int32 partition;
1813 afs_uint32 volid;
1814 afs_int32 code, err = 0;
1816 server = GetServer(as->parms[0].items->data);
1817 if (server == 0) {
1818 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1819 as->parms[0].items->data);
1820 return -1;
1823 partition = volutil_GetPartitionID(as->parms[1].items->data);
1824 if (partition < 0) {
1825 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1826 as->parms[1].items->data);
1827 return ENOENT;
1830 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */
1831 if (!volid) {
1832 if (err)
1833 PrintError("", err);
1834 else
1835 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1836 as->parms[0].items->data);
1837 return -1;
1840 code = UV_SetVolume(server, partition, volid, ITOffline, 0 /*online */ ,
1841 0 /*sleep */ );
1842 if (code) {
1843 fprintf(STDERR, "Failed to set volume. Code = %d\n", code);
1844 return -1;
1847 return 0;
1850 /*------------------------------------------------------------------------
1851 * PRIVATE volOffline
1853 * Description:
1854 * Brings a volume offline.
1856 * Arguments:
1857 * as : Ptr to parsed command line arguments.
1859 * Returns:
1860 * 0 for a successful operation,
1862 * Environment:
1863 * Nothing interesting.
1865 * Side Effects:
1866 * As advertised.
1867 *------------------------------------------------------------------------
1869 static int
1870 volOffline(struct cmd_syndesc *as, void *arock)
1872 afs_uint32 server;
1873 afs_int32 partition;
1874 afs_uint32 volid;
1875 afs_int32 code, err = 0;
1876 afs_int32 transflag, sleeptime, transdone;
1878 server = GetServer(as->parms[0].items->data);
1879 if (server == 0) {
1880 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1881 as->parms[0].items->data);
1882 return -1;
1885 partition = volutil_GetPartitionID(as->parms[1].items->data);
1886 if (partition < 0) {
1887 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1888 as->parms[1].items->data);
1889 return ENOENT;
1892 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */
1893 if (!volid) {
1894 if (err)
1895 PrintError("", err);
1896 else
1897 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1898 as->parms[0].items->data);
1899 return -1;
1902 transflag = (as->parms[4].items ? ITBusy : ITOffline);
1903 sleeptime = (as->parms[3].items ? atol(as->parms[3].items->data) : 0);
1904 transdone = ((sleeptime || as->parms[4].items) ? 0 /*online */ : VTOutOfService);
1905 if (as->parms[4].items && !as->parms[3].items) {
1906 fprintf(STDERR, "-sleep option must be used with -busy flag\n");
1907 return -1;
1910 code =
1911 UV_SetVolume(server, partition, volid, transflag, transdone,
1912 sleeptime);
1913 if (code) {
1914 fprintf(STDERR, "Failed to set volume. Code = %d\n", code);
1915 return -1;
1918 return 0;
1921 static int
1922 CreateVolume(struct cmd_syndesc *as, void *arock)
1924 afs_int32 pnum;
1925 char part[10];
1926 afs_uint32 volid = 0, rovolid = 0, bkvolid = 0;
1927 afs_uint32 *arovolid;
1928 afs_int32 code;
1929 struct nvldbentry entry;
1930 afs_int32 vcode;
1931 afs_int32 quota;
1933 arovolid = &rovolid;
1935 quota = 5000;
1936 tserver = GetServer(as->parms[0].items->data);
1937 if (!tserver) {
1938 fprintf(STDERR, "vos: host '%s' not found in host table\n",
1939 as->parms[0].items->data);
1940 return ENOENT;
1942 pnum = volutil_GetPartitionID(as->parms[1].items->data);
1943 if (pnum < 0) {
1944 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1945 as->parms[1].items->data);
1946 return ENOENT;
1948 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
1949 if (code)
1950 PrintError("", code);
1951 else
1952 fprintf(STDERR,
1953 "vos : partition %s does not exist on the server\n",
1954 as->parms[1].items->data);
1955 return ENOENT;
1957 if (!ISNAMEVALID(as->parms[2].items->data)) {
1958 fprintf(STDERR,
1959 "vos: the name of the root volume %s exceeds the size limit of %d\n",
1960 as->parms[2].items->data, VOLSER_OLDMAXVOLNAME - 10);
1961 return E2BIG;
1963 if (!VolNameOK(as->parms[2].items->data)) {
1964 fprintf(STDERR,
1965 "Illegal volume name %s, should not end in .readonly or .backup\n",
1966 as->parms[2].items->data);
1967 return EINVAL;
1969 if (IsNumeric(as->parms[2].items->data)) {
1970 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
1971 as->parms[2].items->data);
1972 return EINVAL;
1974 vcode = VLDB_GetEntryByName(as->parms[2].items->data, &entry);
1975 if (!vcode) {
1976 fprintf(STDERR, "Volume %s already exists\n",
1977 as->parms[2].items->data);
1978 PrintDiagnostics("create", code);
1979 return EEXIST;
1982 if (as->parms[3].items) {
1983 code = util_GetHumanInt32(as->parms[3].items->data, &quota);
1984 if (code) {
1985 fprintf(STDERR, "vos: bad integer specified for quota.\n");
1986 return code;
1990 if (as->parms[4].items) {
1991 if (!IsNumeric(as->parms[4].items->data)) {
1992 fprintf(STDERR, "vos: Given volume ID %s should be numeric.\n",
1993 as->parms[4].items->data);
1994 return EINVAL;
1997 code = util_GetUInt32(as->parms[4].items->data, &volid);
1998 if (code) {
1999 fprintf(STDERR, "vos: bad integer specified for volume ID.\n");
2000 return code;
2004 if (as->parms[5].items) {
2005 if (!IsNumeric(as->parms[5].items->data)) {
2006 fprintf(STDERR, "vos: Given RO volume ID %s should be numeric.\n",
2007 as->parms[5].items->data);
2008 return EINVAL;
2011 code = util_GetUInt32(as->parms[5].items->data, &rovolid);
2012 if (code) {
2013 fprintf(STDERR, "vos: bad integer specified for volume ID.\n");
2014 return code;
2017 if (rovolid == 0) {
2018 arovolid = NULL;
2022 code =
2023 UV_CreateVolume3(tserver, pnum, as->parms[2].items->data, quota, 0,
2024 0, 0, 0, &volid, arovolid, &bkvolid);
2025 if (code) {
2026 PrintDiagnostics("create", code);
2027 return code;
2029 MapPartIdIntoName(pnum, part);
2030 fprintf(STDOUT, "Volume %lu created on partition %s of %s\n",
2031 (unsigned long)volid, part, as->parms[0].items->data);
2033 return 0;
2036 #if 0
2037 static afs_int32
2038 DeleteAll(struct nvldbentry *entry)
2040 int i;
2041 afs_int32 error, code, curserver, curpart;
2042 afs_uint32 volid;
2044 MapHostToNetwork(entry);
2045 error = 0;
2046 for (i = 0; i < entry->nServers; i++) {
2047 curserver = entry->serverNumber[i];
2048 curpart = entry->serverPartition[i];
2049 if (entry->serverFlags[i] & ITSROVOL) {
2050 volid = entry->volumeId[ROVOL];
2051 } else {
2052 volid = entry->volumeId[RWVOL];
2054 code = UV_DeleteVolume(curserver, curpart, volid);
2055 if (code && !error)
2056 error = code;
2058 return error;
2060 #endif
2062 static int
2063 DeleteVolume(struct cmd_syndesc *as, void *arock)
2065 afs_int32 err, code = 0;
2066 afs_uint32 server = 0;
2067 afs_int32 partition = -1;
2068 afs_uint32 volid;
2069 char pname[10];
2070 afs_int32 idx, j;
2072 if (as->parms[0].items) {
2073 server = GetServer(as->parms[0].items->data);
2074 if (!server) {
2075 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2076 as->parms[0].items->data);
2077 return ENOENT;
2081 if (as->parms[1].items) {
2082 partition = volutil_GetPartitionID(as->parms[1].items->data);
2083 if (partition < 0) {
2084 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2085 as->parms[1].items->data);
2086 return EINVAL;
2089 /* Check for validity of the partition */
2090 if (!IsPartValid(partition, server, &code)) {
2091 if (code) {
2092 PrintError("", code);
2093 } else {
2094 fprintf(STDERR,
2095 "vos : partition %s does not exist on the server\n",
2096 as->parms[1].items->data);
2098 return ENOENT;
2102 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
2103 if (volid == 0) {
2104 fprintf(STDERR, "Can't find volume name '%s' in VLDB\n",
2105 as->parms[2].items->data);
2106 if (err)
2107 PrintError("", err);
2108 return ENOENT;
2111 /* If the server or partition option are not complete, try to fill
2112 * them in from the VLDB entry.
2114 if ((partition == -1) || !server) {
2115 struct nvldbentry entry;
2117 code = VLDB_GetEntryByID(volid, -1, &entry);
2118 if (code) {
2119 fprintf(STDERR,
2120 "Could not fetch the entry for volume %lu from VLDB\n",
2121 (unsigned long)volid);
2122 PrintError("", code);
2123 return (code);
2126 if (((volid == entry.volumeId[RWVOL]) && (entry.flags & RW_EXISTS))
2127 || ((volid == entry.volumeId[BACKVOL])
2128 && (entry.flags & BACK_EXISTS))) {
2129 idx = Lp_GetRwIndex(&entry);
2130 if ((idx == -1) || (server && (server != entry.serverNumber[idx]))
2131 || ((partition != -1)
2132 && (partition != entry.serverPartition[idx]))) {
2133 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2134 as->parms[2].items->data);
2135 return ENOENT;
2137 } else if ((volid == entry.volumeId[ROVOL])
2138 && (entry.flags & RO_EXISTS)) {
2139 for (idx = -1, j = 0; j < entry.nServers; j++) {
2140 if (entry.serverFlags[j] != ITSROVOL)
2141 continue;
2143 if (((server == 0) || (server == entry.serverNumber[j]))
2144 && ((partition == -1)
2145 || (partition == entry.serverPartition[j]))) {
2146 if (idx != -1) {
2147 fprintf(STDERR,
2148 "VLDB: Volume '%s' matches more than one RO\n",
2149 as->parms[2].items->data);
2150 return ENOENT;
2152 idx = j;
2155 if (idx == -1) {
2156 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2157 as->parms[2].items->data);
2158 return ENOENT;
2160 } else {
2161 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2162 as->parms[2].items->data);
2163 return ENOENT;
2166 server = htonl(entry.serverNumber[idx]);
2167 partition = entry.serverPartition[idx];
2171 code = UV_DeleteVolume(server, partition, volid);
2172 if (code) {
2173 PrintDiagnostics("remove", code);
2174 return code;
2177 MapPartIdIntoName(partition, pname);
2178 fprintf(STDOUT, "Volume %lu on partition %s server %s deleted\n",
2179 (unsigned long)volid, pname, hostutil_GetNameByINet(server));
2180 return 0;
2183 #define TESTM 0 /* set for move space tests, clear for production */
2184 static int
2185 MoveVolume(struct cmd_syndesc *as, void *arock)
2188 afs_uint32 volid;
2189 afs_uint32 fromserver, toserver;
2190 afs_int32 frompart, topart;
2191 afs_int32 flags, code, err;
2192 char fromPartName[10], toPartName[10];
2194 struct diskPartition64 partition; /* for space check */
2195 volintInfo *p;
2197 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2198 if (volid == 0) {
2199 if (err)
2200 PrintError("", err);
2201 else
2202 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2203 as->parms[0].items->data);
2204 return ENOENT;
2206 fromserver = GetServer(as->parms[1].items->data);
2207 if (fromserver == 0) {
2208 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2209 as->parms[1].items->data);
2210 return ENOENT;
2212 toserver = GetServer(as->parms[3].items->data);
2213 if (toserver == 0) {
2214 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2215 as->parms[3].items->data);
2216 return ENOENT;
2218 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2219 if (frompart < 0) {
2220 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2221 as->parms[2].items->data);
2222 return EINVAL;
2224 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2225 if (code)
2226 PrintError("", code);
2227 else
2228 fprintf(STDERR,
2229 "vos : partition %s does not exist on the server\n",
2230 as->parms[2].items->data);
2231 return ENOENT;
2233 topart = volutil_GetPartitionID(as->parms[4].items->data);
2234 if (topart < 0) {
2235 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2236 as->parms[4].items->data);
2237 return EINVAL;
2239 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2240 if (code)
2241 PrintError("", code);
2242 else
2243 fprintf(STDERR,
2244 "vos : partition %s does not exist on the server\n",
2245 as->parms[4].items->data);
2246 return ENOENT;
2249 flags = 0;
2250 if (as->parms[5].items) flags |= RV_NOCLONE;
2253 * check source partition for space to clone volume
2256 MapPartIdIntoName(topart, toPartName);
2257 MapPartIdIntoName(frompart, fromPartName);
2260 * check target partition for space to move volume
2263 code = UV_PartitionInfo64(toserver, toPartName, &partition);
2264 if (code) {
2265 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2266 exit(1);
2268 if (TESTM)
2269 fprintf(STDOUT, "target partition %s free space %" AFS_INT64_FMT "\n", toPartName,
2270 partition.free);
2272 p = (volintInfo *) 0;
2273 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2274 if (code) {
2275 fprintf(STDERR, "vos:cannot access volume %lu\n",
2276 (unsigned long)volid);
2277 exit(1);
2279 if (TESTM)
2280 fprintf(STDOUT, "volume %lu size %d\n", (unsigned long)volid,
2281 p->size);
2282 if (partition.free <= p->size) {
2283 fprintf(STDERR,
2284 "vos: no space on target partition %s to move volume %lu\n",
2285 toPartName, (unsigned long)volid);
2286 free(p);
2287 exit(1);
2289 free(p);
2291 if (TESTM) {
2292 fprintf(STDOUT, "size test - don't do move\n");
2293 exit(0);
2296 /* successful move still not guaranteed but shoot for it */
2298 code =
2299 UV_MoveVolume2(volid, fromserver, frompart, toserver, topart, flags);
2300 if (code) {
2301 PrintDiagnostics("move", code);
2302 return code;
2304 MapPartIdIntoName(topart, toPartName);
2305 MapPartIdIntoName(frompart, fromPartName);
2306 fprintf(STDOUT, "Volume %lu moved from %s %s to %s %s \n",
2307 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2308 as->parms[3].items->data, toPartName);
2310 return 0;
2313 static int
2314 CopyVolume(struct cmd_syndesc *as, void *arock)
2316 afs_uint32 volid;
2317 afs_uint32 fromserver, toserver;
2318 afs_int32 frompart, topart, code, err, flags;
2319 char fromPartName[10], toPartName[10], *tovolume;
2320 struct nvldbentry entry;
2321 struct diskPartition64 partition; /* for space check */
2322 volintInfo *p;
2324 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2325 if (volid == 0) {
2326 if (err)
2327 PrintError("", err);
2328 else
2329 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2330 as->parms[0].items->data);
2331 return ENOENT;
2333 fromserver = GetServer(as->parms[1].items->data);
2334 if (fromserver == 0) {
2335 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2336 as->parms[1].items->data);
2337 return ENOENT;
2340 toserver = GetServer(as->parms[4].items->data);
2341 if (toserver == 0) {
2342 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2343 as->parms[4].items->data);
2344 return ENOENT;
2347 tovolume = as->parms[3].items->data;
2348 if (!ISNAMEVALID(tovolume)) {
2349 fprintf(STDERR,
2350 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2351 tovolume, VOLSER_OLDMAXVOLNAME - 10);
2352 return E2BIG;
2354 if (!VolNameOK(tovolume)) {
2355 fprintf(STDERR,
2356 "Illegal volume name %s, should not end in .readonly or .backup\n",
2357 tovolume);
2358 return EINVAL;
2360 if (IsNumeric(tovolume)) {
2361 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
2362 tovolume);
2363 return EINVAL;
2365 code = VLDB_GetEntryByName(tovolume, &entry);
2366 if (!code) {
2367 fprintf(STDERR, "Volume %s already exists\n", tovolume);
2368 PrintDiagnostics("copy", code);
2369 return EEXIST;
2372 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2373 if (frompart < 0) {
2374 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2375 as->parms[2].items->data);
2376 return EINVAL;
2378 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2379 if (code)
2380 PrintError("", code);
2381 else
2382 fprintf(STDERR,
2383 "vos : partition %s does not exist on the server\n",
2384 as->parms[2].items->data);
2385 return ENOENT;
2388 topart = volutil_GetPartitionID(as->parms[5].items->data);
2389 if (topart < 0) {
2390 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2391 as->parms[5].items->data);
2392 return EINVAL;
2394 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2395 if (code)
2396 PrintError("", code);
2397 else
2398 fprintf(STDERR,
2399 "vos : partition %s does not exist on the server\n",
2400 as->parms[5].items->data);
2401 return ENOENT;
2404 flags = 0;
2405 if (as->parms[6].items) flags |= RV_OFFLINE;
2406 if (as->parms[7].items) flags |= RV_RDONLY;
2407 if (as->parms[8].items) flags |= RV_NOCLONE;
2409 MapPartIdIntoName(topart, toPartName);
2410 MapPartIdIntoName(frompart, fromPartName);
2413 * check target partition for space to move volume
2416 code = UV_PartitionInfo64(toserver, toPartName, &partition);
2417 if (code) {
2418 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2419 exit(1);
2421 if (TESTM)
2422 fprintf(STDOUT, "target partition %s free space %" AFS_INT64_FMT "\n", toPartName,
2423 partition.free);
2425 p = (volintInfo *) 0;
2426 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2427 if (code) {
2428 fprintf(STDERR, "vos:cannot access volume %lu\n",
2429 (unsigned long)volid);
2430 exit(1);
2433 if (partition.free <= p->size) {
2434 fprintf(STDERR,
2435 "vos: no space on target partition %s to copy volume %lu\n",
2436 toPartName, (unsigned long)volid);
2437 free(p);
2438 exit(1);
2440 free(p);
2442 /* successful copy still not guaranteed but shoot for it */
2444 code =
2445 UV_CopyVolume2(volid, fromserver, frompart, tovolume, toserver,
2446 topart, 0, flags);
2447 if (code) {
2448 PrintDiagnostics("copy", code);
2449 return code;
2451 MapPartIdIntoName(topart, toPartName);
2452 MapPartIdIntoName(frompart, fromPartName);
2453 fprintf(STDOUT, "Volume %lu copied from %s %s to %s on %s %s \n",
2454 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2455 tovolume, as->parms[4].items->data, toPartName);
2457 return 0;
2461 static int
2462 ShadowVolume(struct cmd_syndesc *as, void *arock)
2464 afs_uint32 volid, tovolid;
2465 afs_uint32 fromserver, toserver;
2466 afs_int32 frompart, topart;
2467 afs_int32 code, err, flags;
2468 char fromPartName[10], toPartName[10], toVolName[32], *tovolume;
2469 struct diskPartition64 partition; /* for space check */
2470 volintInfo *p, *q;
2472 p = (volintInfo *) 0;
2473 q = (volintInfo *) 0;
2475 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2476 if (volid == 0) {
2477 if (err)
2478 PrintError("", err);
2479 else
2480 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2481 as->parms[0].items->data);
2482 return ENOENT;
2484 fromserver = GetServer(as->parms[1].items->data);
2485 if (fromserver == 0) {
2486 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2487 as->parms[1].items->data);
2488 return ENOENT;
2491 toserver = GetServer(as->parms[3].items->data);
2492 if (toserver == 0) {
2493 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2494 as->parms[3].items->data);
2495 return ENOENT;
2498 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2499 if (frompart < 0) {
2500 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2501 as->parms[2].items->data);
2502 return EINVAL;
2504 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2505 if (code)
2506 PrintError("", code);
2507 else
2508 fprintf(STDERR,
2509 "vos : partition %s does not exist on the server\n",
2510 as->parms[2].items->data);
2511 return ENOENT;
2514 topart = volutil_GetPartitionID(as->parms[4].items->data);
2515 if (topart < 0) {
2516 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2517 as->parms[4].items->data);
2518 return EINVAL;
2520 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2521 if (code)
2522 PrintError("", code);
2523 else
2524 fprintf(STDERR,
2525 "vos : partition %s does not exist on the server\n",
2526 as->parms[4].items->data);
2527 return ENOENT;
2530 if (as->parms[5].items) {
2531 tovolume = as->parms[5].items->data;
2532 if (!ISNAMEVALID(tovolume)) {
2533 fprintf(STDERR,
2534 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2535 tovolume, VOLSER_OLDMAXVOLNAME - 10);
2536 return E2BIG;
2538 if (!VolNameOK(tovolume)) {
2539 fprintf(STDERR,
2540 "Illegal volume name %s, should not end in .readonly or .backup\n",
2541 tovolume);
2542 return EINVAL;
2544 if (IsNumeric(tovolume)) {
2545 fprintf(STDERR,
2546 "Illegal volume name %s, should not be a number\n",
2547 tovolume);
2548 return EINVAL;
2550 } else {
2551 /* use actual name of source volume */
2552 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2553 if (code) {
2554 fprintf(STDERR, "vos:cannot access volume %lu\n",
2555 (unsigned long)volid);
2556 exit(1);
2558 strcpy(toVolName, p->name);
2559 tovolume = toVolName;
2560 /* save p for size checks later */
2563 if (as->parms[6].items) {
2564 tovolid = vsu_GetVolumeID(as->parms[6].items->data, cstruct, &err);
2565 if (tovolid == 0) {
2566 if (err)
2567 PrintError("", err);
2568 else
2569 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2570 as->parms[6].items->data);
2571 if (p)
2572 free(p);
2573 return ENOENT;
2575 } else {
2576 tovolid = vsu_GetVolumeID(tovolume, cstruct, &err);
2577 if (tovolid == 0) {
2578 if (err)
2579 PrintError("", err);
2580 else
2581 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2582 tovolume);
2583 if (p)
2584 free(p);
2585 return ENOENT;
2589 flags = RV_NOVLDB;
2590 if (as->parms[7].items) flags |= RV_OFFLINE;
2591 if (as->parms[8].items) flags |= RV_RDONLY;
2592 if (as->parms[9].items) flags |= RV_NOCLONE;
2593 if (as->parms[10].items) flags |= RV_CPINCR;
2595 MapPartIdIntoName(topart, toPartName);
2596 MapPartIdIntoName(frompart, fromPartName);
2599 * check target partition for space to move volume
2602 code = UV_PartitionInfo64(toserver, toPartName, &partition);
2603 if (code) {
2604 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2605 exit(1);
2607 if (TESTM)
2608 fprintf(STDOUT, "target partition %s free space %" AFS_INT64_FMT "\n", toPartName,
2609 partition.free);
2611 /* Don't do this again if we did it above */
2612 if (!p) {
2613 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2614 if (code) {
2615 fprintf(STDERR, "vos:cannot access volume %lu\n",
2616 (unsigned long)volid);
2617 exit(1);
2621 /* OK if this fails */
2622 code = UV_ListOneVolume(toserver, topart, tovolid, &q);
2624 /* Treat existing volume size as "free" */
2625 if (q)
2626 p->size = (q->size < p->size) ? p->size - q->size : 0;
2628 if (partition.free <= p->size) {
2629 fprintf(STDERR,
2630 "vos: no space on target partition %s to copy volume %lu\n",
2631 toPartName, (unsigned long)volid);
2632 free(p);
2633 if (q) free(q);
2634 exit(1);
2636 free(p);
2637 if (q) free(q);
2639 /* successful copy still not guaranteed but shoot for it */
2641 code =
2642 UV_CopyVolume2(volid, fromserver, frompart, tovolume, toserver,
2643 topart, tovolid, flags);
2644 if (code) {
2645 PrintDiagnostics("shadow", code);
2646 return code;
2648 MapPartIdIntoName(topart, toPartName);
2649 MapPartIdIntoName(frompart, fromPartName);
2650 fprintf(STDOUT, "Volume %lu shadowed from %s %s to %s %s \n",
2651 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2652 as->parms[3].items->data, toPartName);
2654 return 0;
2658 static int
2659 CloneVolume(struct cmd_syndesc *as, void *arock)
2661 afs_uint32 volid, cloneid;
2662 afs_uint32 server;
2663 afs_int32 part, voltype;
2664 char partName[10], *volname;
2665 afs_int32 code, err, flags;
2666 struct nvldbentry entry;
2668 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2669 if (volid == 0) {
2670 if (err)
2671 PrintError("", err);
2672 else
2673 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2674 as->parms[0].items->data);
2675 return ENOENT;
2678 if (as->parms[1].items || as->parms[2].items) {
2679 if (!as->parms[1].items || !as->parms[2].items) {
2680 fprintf(STDERR,
2681 "Must specify both -server and -partition options\n");
2682 return -1;
2684 server = GetServer(as->parms[1].items->data);
2685 if (server == 0) {
2686 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2687 as->parms[1].items->data);
2688 return ENOENT;
2690 part = volutil_GetPartitionID(as->parms[2].items->data);
2691 if (part < 0) {
2692 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2693 as->parms[2].items->data);
2694 return EINVAL;
2696 if (!IsPartValid(part, server, &code)) { /*check for validity of the partition */
2697 if (code)
2698 PrintError("", code);
2699 else
2700 fprintf(STDERR,
2701 "vos : partition %s does not exist on the server\n",
2702 as->parms[2].items->data);
2703 return ENOENT;
2705 } else {
2706 code = GetVolumeInfo(volid, &server, &part, &voltype, &entry);
2707 if (code)
2708 return code;
2711 volname = 0;
2712 if (as->parms[3].items) {
2713 volname = as->parms[3].items->data;
2714 if (strlen(volname) > VOLSER_OLDMAXVOLNAME - 1) {
2715 fprintf(STDERR,
2716 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2717 volname, VOLSER_OLDMAXVOLNAME - 1);
2718 return E2BIG;
2720 #if 0
2722 * In order that you be able to make clones of RO or BK, this
2723 * check must be omitted.
2725 if (!VolNameOK(volname)) {
2726 fprintf(STDERR,
2727 "Illegal volume name %s, should not end in .readonly or .backup\n",
2728 volname);
2729 return EINVAL;
2731 #endif
2732 if (IsNumeric(volname)) {
2733 fprintf(STDERR,
2734 "Illegal volume name %s, should not be a number\n",
2735 volname);
2736 return EINVAL;
2740 cloneid = 0;
2741 if (as->parms[4].items) {
2742 cloneid = vsu_GetVolumeID(as->parms[4].items->data, cstruct, &err);
2743 if (cloneid == 0) {
2744 if (err)
2745 PrintError("", err);
2746 else
2747 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2748 as->parms[4].items->data);
2749 return ENOENT;
2753 flags = 0;
2754 if (as->parms[5].items) flags |= RV_OFFLINE;
2755 if (as->parms[6].items && as->parms[7].items) {
2756 fprintf(STDERR, "vos: cannot specify that a volume be -readwrite and -readonly\n");
2757 return EINVAL;
2759 if (as->parms[6].items) flags |= RV_RDONLY;
2760 if (as->parms[7].items) flags |= RV_RWONLY;
2763 code =
2764 UV_CloneVolume(server, part, volid, cloneid, volname, flags);
2766 if (code) {
2767 PrintDiagnostics("clone", code);
2768 return code;
2770 MapPartIdIntoName(part, partName);
2771 fprintf(STDOUT, "Created clone for volume %s\n",
2772 as->parms[0].items->data);
2774 return 0;
2778 static int
2779 BackupVolume(struct cmd_syndesc *as, void *arock)
2781 afs_uint32 avolid;
2782 afs_uint32 aserver;
2783 afs_int32 apart, vtype, code, err;
2784 struct nvldbentry entry;
2786 afs_uint32 buvolid;
2787 afs_uint32 buserver;
2788 afs_int32 bupart, butype;
2789 struct nvldbentry buentry;
2791 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2792 if (avolid == 0) {
2793 if (err)
2794 PrintError("", err);
2795 else
2796 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2797 as->parms[0].items->data);
2798 return ENOENT;
2800 code = GetVolumeInfo(avolid, &aserver, &apart, &vtype, &entry);
2801 if (code)
2802 exit(1);
2804 /* verify this is a readwrite volume */
2806 if (vtype != RWVOL) {
2807 fprintf(STDERR, "%s not RW volume\n", as->parms[0].items->data);
2808 exit(1);
2811 /* is there a backup volume already? */
2813 if (entry.flags & BACK_EXISTS) {
2814 /* yep, where is it? */
2816 buvolid = entry.volumeId[BACKVOL];
2817 code = GetVolumeInfo(buvolid, &buserver, &bupart, &butype, &buentry);
2818 if (code)
2819 exit(1);
2821 /* is it local? */
2822 code = VLDB_IsSameAddrs(buserver, aserver, &err);
2823 if (err) {
2824 fprintf(STDERR,
2825 "Failed to get info about server's %d address(es) from vlserver; aborting call!\n",
2826 buserver);
2827 exit(1);
2829 if (!code) {
2830 fprintf(STDERR,
2831 "FATAL ERROR: backup volume %lu exists on server %lu\n",
2832 (unsigned long)buvolid, (unsigned long)buserver);
2833 exit(1);
2837 /* nope, carry on */
2839 code = UV_BackupVolume(aserver, apart, avolid);
2841 if (code) {
2842 PrintDiagnostics("backup", code);
2843 return code;
2845 fprintf(STDOUT, "Created backup volume for %s \n",
2846 as->parms[0].items->data);
2847 return 0;
2850 static int
2851 ReleaseVolume(struct cmd_syndesc *as, void *arock)
2854 struct nvldbentry entry;
2855 afs_uint32 avolid;
2856 afs_uint32 aserver;
2857 afs_int32 apart, vtype, code, err;
2858 int force = 0;
2859 int stayUp = 0;
2861 if (as->parms[1].items)
2862 force = 1;
2863 if (as->parms[2].items)
2864 stayUp = 1;
2865 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2866 if (avolid == 0) {
2867 if (err)
2868 PrintError("", err);
2869 else
2870 fprintf(STDERR, "vos: can't find volume '%s'\n",
2871 as->parms[0].items->data);
2872 return ENOENT;
2874 code = GetVolumeInfo(avolid, &aserver, &apart, &vtype, &entry);
2875 if (code)
2876 return code;
2878 if (vtype != RWVOL) {
2879 fprintf(STDERR, "%s not a RW volume\n", as->parms[0].items->data);
2880 return (ENOENT);
2883 if (!ISNAMEVALID(entry.name)) {
2884 fprintf(STDERR,
2885 "Volume name %s is too long, rename before releasing\n",
2886 entry.name);
2887 return E2BIG;
2890 code = UV_ReleaseVolume(avolid, aserver, apart, force, stayUp);
2892 if (code) {
2893 PrintDiagnostics("release", code);
2894 return code;
2896 fprintf(STDOUT, "Released volume %s successfully\n",
2897 as->parms[0].items->data);
2898 return 0;
2901 static int
2902 DumpVolumeCmd(struct cmd_syndesc *as, void *arock)
2904 afs_uint32 avolid;
2905 afs_uint32 aserver;
2906 afs_int32 apart, voltype, fromdate = 0, code, err, i, flags;
2907 char filename[MAXPATHLEN];
2908 struct nvldbentry entry;
2910 rx_SetRxDeadTime(60 * 10);
2911 for (i = 0; i < MAXSERVERS; i++) {
2912 struct rx_connection *rxConn = ubik_GetRPCConn(cstruct, i);
2913 if (rxConn == 0)
2914 break;
2915 rx_SetConnDeadTime(rxConn, rx_connDeadTime);
2916 if (rxConn->service)
2917 rxConn->service->connDeadTime = rx_connDeadTime;
2920 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2921 if (avolid == 0) {
2922 if (err)
2923 PrintError("", err);
2924 else
2925 fprintf(STDERR, "vos: can't find volume '%s'\n",
2926 as->parms[0].items->data);
2927 return ENOENT;
2930 if (as->parms[3].items || as->parms[4].items) {
2931 if (!as->parms[3].items || !as->parms[4].items) {
2932 fprintf(STDERR,
2933 "Must specify both -server and -partition options\n");
2934 return -1;
2936 aserver = GetServer(as->parms[3].items->data);
2937 if (aserver == 0) {
2938 fprintf(STDERR, "Invalid server name\n");
2939 return -1;
2941 apart = volutil_GetPartitionID(as->parms[4].items->data);
2942 if (apart < 0) {
2943 fprintf(STDERR, "Invalid partition name\n");
2944 return -1;
2946 } else {
2947 code = GetVolumeInfo(avolid, &aserver, &apart, &voltype, &entry);
2948 if (code)
2949 return code;
2952 if (as->parms[1].items && strcmp(as->parms[1].items->data, "0")) {
2953 code = ktime_DateToInt32(as->parms[1].items->data, &fromdate);
2954 if (code) {
2955 fprintf(STDERR, "vos: failed to parse date '%s' (error=%d))\n",
2956 as->parms[1].items->data, code);
2957 return code;
2960 if (as->parms[2].items) {
2961 strcpy(filename, as->parms[2].items->data);
2962 } else {
2963 strcpy(filename, "");
2966 flags = as->parms[6].items ? VOLDUMPV2_OMITDIRS : 0;
2967 retry_dump:
2968 if (as->parms[5].items) {
2969 code =
2970 UV_DumpClonedVolume(avolid, aserver, apart, fromdate,
2971 DumpFunction, filename, flags);
2972 } else {
2973 code =
2974 UV_DumpVolume(avolid, aserver, apart, fromdate, DumpFunction,
2975 filename, flags);
2977 if ((code == RXGEN_OPCODE) && (as->parms[6].items)) {
2978 flags &= ~VOLDUMPV2_OMITDIRS;
2979 goto retry_dump;
2981 if (code) {
2982 PrintDiagnostics("dump", code);
2983 return code;
2985 if (strcmp(filename, ""))
2986 fprintf(STDERR, "Dumped volume %s in file %s\n",
2987 as->parms[0].items->data, filename);
2988 else
2989 fprintf(STDERR, "Dumped volume %s in stdout \n",
2990 as->parms[0].items->data);
2991 return 0;
2994 #define ASK 0
2995 #define ABORT 1
2996 #define FULL 2
2997 #define INC 3
2999 #define TS_DUMP 1
3000 #define TS_KEEP 2
3001 #define TS_NEW 3
3003 static int
3004 RestoreVolumeCmd(struct cmd_syndesc *as, void *arock)
3006 afs_uint32 avolid, aparentid;
3007 afs_uint32 aserver;
3008 afs_int32 apart, code, vcode, err;
3009 afs_int32 aoverwrite = ASK;
3010 afs_int32 acreation = 0, alastupdate = 0;
3011 int restoreflags = 0;
3012 int readonly = 0, offline = 0, voltype = RWVOL;
3013 char afilename[MAXPATHLEN], avolname[VOLSER_MAXVOLNAME + 1], apartName[10];
3014 char volname[VOLSER_MAXVOLNAME + 1];
3015 struct nvldbentry entry;
3017 aparentid = 0;
3018 if (as->parms[4].items) {
3019 avolid = vsu_GetVolumeID(as->parms[4].items->data, cstruct, &err);
3020 if (avolid == 0) {
3021 if (err)
3022 PrintError("", err);
3023 else
3024 fprintf(STDERR, "vos: can't find volume '%s'\n",
3025 as->parms[4].items->data);
3026 exit(1);
3028 } else
3029 avolid = 0;
3031 if (as->parms[5].items) {
3032 if ((strcmp(as->parms[5].items->data, "a") == 0)
3033 || (strcmp(as->parms[5].items->data, "abort") == 0)) {
3034 aoverwrite = ABORT;
3035 } else if ((strcmp(as->parms[5].items->data, "f") == 0)
3036 || (strcmp(as->parms[5].items->data, "full") == 0)) {
3037 aoverwrite = FULL;
3038 } else if ((strcmp(as->parms[5].items->data, "i") == 0)
3039 || (strcmp(as->parms[5].items->data, "inc") == 0)
3040 || (strcmp(as->parms[5].items->data, "increment") == 0)
3041 || (strcmp(as->parms[5].items->data, "incremental") == 0)) {
3042 aoverwrite = INC;
3043 } else {
3044 fprintf(STDERR, "vos: %s is not a valid argument to -overwrite\n",
3045 as->parms[5].items->data);
3046 exit(1);
3049 if (as->parms[6].items)
3050 offline = 1;
3051 if (as->parms[7].items) {
3052 readonly = 1;
3053 voltype = ROVOL;
3056 if (as->parms[8].items) {
3057 if ((strcmp(as->parms[8].items->data, "d") == 0)
3058 || (strcmp(as->parms[8].items->data, "dump") == 0)) {
3059 acreation = TS_DUMP;
3060 } else if ((strcmp(as->parms[8].items->data, "k") == 0)
3061 || (strcmp(as->parms[8].items->data, "keep") == 0)) {
3062 acreation = TS_KEEP;
3063 } else if ((strcmp(as->parms[8].items->data, "n") == 0)
3064 || (strcmp(as->parms[8].items->data, "new") == 0)) {
3065 acreation = TS_NEW;
3066 } else {
3067 fprintf(STDERR, "vos: %s is not a valid argument to -creation\n",
3068 as->parms[8].items->data);
3069 exit(1);
3073 if (as->parms[9].items) {
3074 if ((strcmp(as->parms[9].items->data, "d") == 0)
3075 || (strcmp(as->parms[9].items->data, "dump") == 0)) {
3076 alastupdate = TS_DUMP;
3077 } else if ((strcmp(as->parms[9].items->data, "k") == 0)
3078 || (strcmp(as->parms[9].items->data, "keep") == 0)) {
3079 alastupdate = TS_KEEP;
3080 } else if ((strcmp(as->parms[9].items->data, "n") == 0)
3081 || (strcmp(as->parms[9].items->data, "new") == 0)) {
3082 alastupdate = TS_NEW;
3083 } else {
3084 fprintf(STDERR, "vos: %s is not a valid argument to -lastupdate\n",
3085 as->parms[9].items->data);
3086 exit(1);
3090 aserver = GetServer(as->parms[0].items->data);
3091 if (aserver == 0) {
3092 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3093 as->parms[0].items->data);
3094 exit(1);
3096 apart = volutil_GetPartitionID(as->parms[1].items->data);
3097 if (apart < 0) {
3098 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3099 as->parms[1].items->data);
3100 exit(1);
3102 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3103 if (code)
3104 PrintError("", code);
3105 else
3106 fprintf(STDERR,
3107 "vos : partition %s does not exist on the server\n",
3108 as->parms[1].items->data);
3109 exit(1);
3111 strcpy(avolname, as->parms[2].items->data);
3112 if (!ISNAMEVALID(avolname)) {
3113 fprintf(STDERR,
3114 "vos: the name of the volume %s exceeds the size limit\n",
3115 avolname);
3116 exit(1);
3118 if (!VolNameOK(avolname)) {
3119 fprintf(STDERR,
3120 "Illegal volume name %s, should not end in .readonly or .backup\n",
3121 avolname);
3122 exit(1);
3124 if (as->parms[3].items) {
3125 strcpy(afilename, as->parms[3].items->data);
3126 if (!FileExists(afilename)) {
3127 fprintf(STDERR, "Can't access file %s\n", afilename);
3128 exit(1);
3130 } else {
3131 strcpy(afilename, "");
3134 /* Check if volume exists or not */
3136 vsu_ExtractName(volname, avolname);
3137 vcode = VLDB_GetEntryByName(volname, &entry);
3138 if (vcode) { /* no volume - do a full restore */
3139 restoreflags = RV_FULLRST;
3140 if ((aoverwrite == INC) || (aoverwrite == ABORT))
3141 fprintf(STDERR,
3142 "Volume does not exist; Will perform a full restore\n");
3145 else if ((!readonly && Lp_GetRwIndex(&entry) == -1) /* RW volume does not exist - do a full */
3146 ||(readonly && !Lp_ROMatch(0, 0, &entry))) { /* RO volume does not exist - do a full */
3147 restoreflags = RV_FULLRST;
3148 if ((aoverwrite == INC) || (aoverwrite == ABORT))
3149 fprintf(STDERR,
3150 "%s Volume does not exist; Will perform a full restore\n",
3151 readonly ? "RO" : "RW");
3153 if (avolid == 0) {
3154 avolid = entry.volumeId[voltype];
3155 } else if (entry.volumeId[voltype] != 0
3156 && entry.volumeId[voltype] != avolid) {
3157 avolid = entry.volumeId[voltype];
3159 aparentid = entry.volumeId[RWVOL];
3162 else { /* volume exists - do we do a full incremental or abort */
3163 afs_uint32 Oserver;
3164 afs_int32 Opart, Otype, vol_elsewhere = 0;
3165 struct nvldbentry Oentry;
3166 int c, dc;
3168 if (avolid == 0) {
3169 avolid = entry.volumeId[voltype];
3170 } else if (entry.volumeId[voltype] != 0
3171 && entry.volumeId[voltype] != avolid) {
3172 avolid = entry.volumeId[voltype];
3174 aparentid = entry.volumeId[RWVOL];
3176 /* A file name was specified - check if volume is on another partition */
3177 vcode = GetVolumeInfo(avolid, &Oserver, &Opart, &Otype, &Oentry);
3178 if (vcode)
3179 exit(1);
3181 vcode = VLDB_IsSameAddrs(Oserver, aserver, &err);
3182 if (err) {
3183 fprintf(STDERR,
3184 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
3185 Oserver, err);
3186 exit(1);
3188 if (!vcode || (Opart != apart))
3189 vol_elsewhere = 1;
3191 if (aoverwrite == ASK) {
3192 if (strcmp(afilename, "") == 0) { /* The file is from standard in */
3193 fprintf(STDERR,
3194 "Volume exists and no -overwrite option specified; Aborting restore command\n");
3195 exit(1);
3198 /* Ask what to do */
3199 if (vol_elsewhere) {
3200 fprintf(STDERR,
3201 "The volume %s %u already exists on a different server/part\n",
3202 volname, entry.volumeId[voltype]);
3203 fprintf(STDERR,
3204 "Do you want to do a full restore or abort? [fa](a): ");
3205 } else {
3206 fprintf(STDERR,
3207 "The volume %s %u already exists in the VLDB\n",
3208 volname, entry.volumeId[voltype]);
3209 fprintf(STDERR,
3210 "Do you want to do a full/incremental restore or abort? [fia](a): ");
3212 dc = c = getchar();
3213 while (!(dc == EOF || dc == '\n'))
3214 dc = getchar(); /* goto end of line */
3215 if ((c == 'f') || (c == 'F'))
3216 aoverwrite = FULL;
3217 else if ((c == 'i') || (c == 'I'))
3218 aoverwrite = INC;
3219 else
3220 aoverwrite = ABORT;
3223 if (aoverwrite == ABORT) {
3224 fprintf(STDERR, "Volume exists; Aborting restore command\n");
3225 exit(1);
3226 } else if (aoverwrite == FULL) {
3227 restoreflags = RV_FULLRST;
3228 fprintf(STDERR,
3229 "Volume exists; Will delete and perform full restore\n");
3230 } else if (aoverwrite == INC) {
3231 restoreflags = 0;
3232 if (vol_elsewhere) {
3233 fprintf(STDERR,
3234 "%s volume %lu already exists on a different server/part; not allowed\n",
3235 readonly ? "RO" : "RW", (unsigned long)avolid);
3236 exit(1);
3240 if (offline)
3241 restoreflags |= RV_OFFLINE;
3242 if (readonly)
3243 restoreflags |= RV_RDONLY;
3245 switch (acreation) {
3246 case TS_DUMP:
3247 restoreflags |= RV_CRDUMP;
3248 break;
3249 case TS_KEEP:
3250 restoreflags |= RV_CRKEEP;
3251 break;
3252 case TS_NEW:
3253 restoreflags |= RV_CRNEW;
3254 break;
3255 default:
3256 if (aoverwrite == FULL)
3257 restoreflags |= RV_CRNEW;
3258 else
3259 restoreflags |= RV_CRKEEP;
3262 switch (alastupdate) {
3263 case TS_DUMP:
3264 restoreflags |= RV_LUDUMP;
3265 break;
3266 case TS_KEEP:
3267 restoreflags |= RV_LUKEEP;
3268 break;
3269 case TS_NEW:
3270 restoreflags |= RV_LUNEW;
3271 break;
3272 default:
3273 restoreflags |= RV_LUDUMP;
3275 if (as->parms[10].items) {
3276 restoreflags |= RV_NODEL;
3280 code =
3281 UV_RestoreVolume2(aserver, apart, avolid, aparentid,
3282 avolname, restoreflags, WriteData, afilename);
3283 if (code) {
3284 PrintDiagnostics("restore", code);
3285 exit(1);
3287 MapPartIdIntoName(apart, apartName);
3290 * patch typo here - originally "parms[1]", should be "parms[0]"
3293 fprintf(STDOUT, "Restored volume %s on %s %s\n", avolname,
3294 as->parms[0].items->data, apartName);
3295 return 0;
3298 static int
3299 LockReleaseCmd(struct cmd_syndesc *as, void *arock)
3301 afs_uint32 avolid;
3302 afs_int32 code, err;
3304 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
3305 if (avolid == 0) {
3306 if (err)
3307 PrintError("", err);
3308 else
3309 fprintf(STDERR, "vos: can't find volume '%s'\n",
3310 as->parms[0].items->data);
3311 exit(1);
3314 code = UV_LockRelease(avolid);
3315 if (code) {
3316 PrintDiagnostics("unlock", code);
3317 exit(1);
3319 fprintf(STDOUT, "Released lock on vldb entry for volume %s\n",
3320 as->parms[0].items->data);
3321 return 0;
3324 static int
3325 AddSite(struct cmd_syndesc *as, void *arock)
3327 afs_uint32 avolid;
3328 afs_uint32 aserver;
3329 afs_int32 apart, code, err, arovolid, valid = 0;
3330 char apartName[10], avolname[VOLSER_MAXVOLNAME + 1];
3332 vsu_ExtractName(avolname, as->parms[2].items->data);;
3333 avolid = vsu_GetVolumeID(avolname, cstruct, &err);
3334 if (avolid == 0) {
3335 if (err)
3336 PrintError("", err);
3337 else
3338 fprintf(STDERR, "vos: can't find volume '%s'\n",
3339 as->parms[2].items->data);
3340 exit(1);
3342 arovolid = 0;
3343 if (as->parms[3].items) {
3344 vsu_ExtractName(avolname, as->parms[3].items->data);
3345 arovolid = vsu_GetVolumeID(avolname, cstruct, &err);
3346 if (!arovolid) {
3347 fprintf(STDERR, "vos: invalid ro volume id '%s'\n",
3348 as->parms[3].items->data);
3349 exit(1);
3352 aserver = GetServer(as->parms[0].items->data);
3353 if (aserver == 0) {
3354 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3355 as->parms[0].items->data);
3356 exit(1);
3358 apart = volutil_GetPartitionID(as->parms[1].items->data);
3359 if (apart < 0) {
3360 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3361 as->parms[1].items->data);
3362 exit(1);
3364 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3365 if (code)
3366 PrintError("", code);
3367 else
3368 fprintf(STDERR,
3369 "vos : partition %s does not exist on the server\n",
3370 as->parms[1].items->data);
3371 exit(1);
3373 if (as->parms[4].items) {
3374 valid = 1;
3376 code = UV_AddSite2(aserver, apart, avolid, arovolid, valid);
3377 if (code) {
3378 PrintDiagnostics("addsite", code);
3379 exit(1);
3381 MapPartIdIntoName(apart, apartName);
3382 fprintf(STDOUT, "Added replication site %s %s for volume %s\n",
3383 as->parms[0].items->data, apartName, as->parms[2].items->data);
3384 return 0;
3387 static int
3388 RemoveSite(struct cmd_syndesc *as, void *arock)
3391 afs_uint32 avolid;
3392 afs_uint32 aserver;
3393 afs_int32 apart, code, err;
3394 char apartName[10], avolname[VOLSER_MAXVOLNAME + 1];
3396 vsu_ExtractName(avolname, as->parms[2].items->data);
3397 avolid = vsu_GetVolumeID(avolname, cstruct, &err);
3398 if (avolid == 0) {
3399 if (err)
3400 PrintError("", err);
3401 else
3402 fprintf(STDERR, "vos: can't find volume '%s'\n",
3403 as->parms[2].items->data);
3404 exit(1);
3406 aserver = GetServer(as->parms[0].items->data);
3407 if (aserver == 0) {
3408 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3409 as->parms[0].items->data);
3410 exit(1);
3412 apart = volutil_GetPartitionID(as->parms[1].items->data);
3413 if (apart < 0) {
3414 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3415 as->parms[1].items->data);
3416 exit(1);
3419 *skip the partition validity check, since it is possible that the partition
3420 *has since been decomissioned.
3423 if (!IsPartValid(apart,aserver,&code)){
3424 if(code) PrintError("",code);
3425 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data);
3426 exit(1);
3429 code = UV_RemoveSite(aserver, apart, avolid);
3430 if (code) {
3431 PrintDiagnostics("remsite", code);
3432 exit(1);
3434 MapPartIdIntoName(apart, apartName);
3435 fprintf(STDOUT, "Removed replication site %s %s for volume %s\n",
3436 as->parms[0].items->data, apartName, as->parms[2].items->data);
3437 return 0;
3440 static int
3441 ChangeLocation(struct cmd_syndesc *as, void *arock)
3443 afs_uint32 avolid;
3444 afs_uint32 aserver;
3445 afs_int32 apart, code, err;
3446 char apartName[10];
3448 avolid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
3449 if (avolid == 0) {
3450 if (err)
3451 PrintError("", err);
3452 else
3453 fprintf(STDERR, "vos: can't find volume '%s'\n",
3454 as->parms[2].items->data);
3455 exit(1);
3457 aserver = GetServer(as->parms[0].items->data);
3458 if (aserver == 0) {
3459 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3460 as->parms[0].items->data);
3461 exit(1);
3463 apart = volutil_GetPartitionID(as->parms[1].items->data);
3464 if (apart < 0) {
3465 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3466 as->parms[1].items->data);
3467 exit(1);
3469 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3470 if (code)
3471 PrintError("", code);
3472 else
3473 fprintf(STDERR,
3474 "vos : partition %s does not exist on the server\n",
3475 as->parms[1].items->data);
3476 exit(1);
3478 code = UV_ChangeLocation(aserver, apart, avolid);
3479 if (code) {
3480 PrintDiagnostics("changeloc", code);
3481 exit(1);
3483 MapPartIdIntoName(apart, apartName);
3484 fprintf(STDOUT, "Changed location to %s %s for volume %s\n",
3485 as->parms[0].items->data, apartName, as->parms[2].items->data);
3486 return 0;
3489 static int
3490 ListPartitions(struct cmd_syndesc *as, void *arock)
3492 afs_uint32 aserver;
3493 afs_int32 code;
3494 struct partList dummyPartList;
3495 int i;
3496 char pname[10];
3497 int total, cnt;
3499 aserver = GetServer(as->parms[0].items->data);
3500 if (aserver == 0) {
3501 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3502 as->parms[0].items->data);
3503 exit(1);
3507 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
3508 if (code) {
3509 PrintDiagnostics("listpart", code);
3510 exit(1);
3512 total = 0;
3513 fprintf(STDOUT, "The partitions on the server are:\n");
3514 for (i = 0; i < cnt; i++) {
3515 if (dummyPartList.partFlags[i] & PARTVALID) {
3516 memset(pname, 0, sizeof(pname));
3517 MapPartIdIntoName(dummyPartList.partId[i], pname);
3518 fprintf(STDOUT, " %10s ", pname);
3519 total++;
3520 if ((i % 5) == 0 && (i != 0))
3521 fprintf(STDOUT, "\n");
3524 fprintf(STDOUT, "\n");
3525 fprintf(STDOUT, "Total: %d\n", total);
3526 return 0;
3530 static int
3531 CompareVolName(const void *p1, const void *p2)
3533 volintInfo *arg1, *arg2;
3535 arg1 = (volintInfo *) p1;
3536 arg2 = (volintInfo *) p2;
3537 return (strcmp(arg1->name, arg2->name));
3541 /*------------------------------------------------------------------------
3542 * PRIVATE XCompareVolName
3544 * Description:
3545 * Comparison routine for volume names coming from an extended
3546 * volume listing.
3548 * Arguments:
3549 * a_obj1P : Char ptr to first extended vol info object
3550 * a_obj1P : Char ptr to second extended vol info object
3552 * Returns:
3553 * The value of strcmp() on the volume names within the passed
3554 * objects (i,e., -1, 0, or 1).
3556 * Environment:
3557 * Passed to qsort() as the designated comparison routine.
3559 * Side Effects:
3560 * As advertised.
3561 *------------------------------------------------------------------------*/
3563 static int
3564 XCompareVolName(const void *a_obj1P, const void *a_obj2P)
3565 { /*XCompareVolName */
3567 return (strcmp
3568 (((struct volintXInfo *)(a_obj1P))->name,
3569 ((struct volintXInfo *)(a_obj2P))->name));
3571 } /*XCompareVolName */
3573 static int
3574 CompareVolID(const void *p1, const void *p2)
3576 volintInfo *arg1, *arg2;
3578 arg1 = (volintInfo *) p1;
3579 arg2 = (volintInfo *) p2;
3580 if (arg1->volid == arg2->volid)
3581 return 0;
3582 if (arg1->volid > arg2->volid)
3583 return 1;
3584 else
3585 return -1;
3589 /*------------------------------------------------------------------------
3590 * PRIVATE XCompareVolID
3592 * Description:
3593 * Comparison routine for volume IDs coming from an extended
3594 * volume listing.
3596 * Arguments:
3597 * a_obj1P : Char ptr to first extended vol info object
3598 * a_obj1P : Char ptr to second extended vol info object
3600 * Returns:
3601 * The value of strcmp() on the volume names within the passed
3602 * objects (i,e., -1, 0, or 1).
3604 * Environment:
3605 * Passed to qsort() as the designated comparison routine.
3607 * Side Effects:
3608 * As advertised.
3609 *------------------------------------------------------------------------*/
3611 static int
3612 XCompareVolID(const void *a_obj1P, const void *a_obj2P)
3613 { /*XCompareVolID */
3615 afs_int32 id1, id2; /*Volume IDs we're comparing */
3617 id1 = ((struct volintXInfo *)(a_obj1P))->volid;
3618 id2 = ((struct volintXInfo *)(a_obj2P))->volid;
3619 if (id1 == id2)
3620 return (0);
3621 else if (id1 > id2)
3622 return (1);
3623 else
3624 return (-1);
3626 } /*XCompareVolID */
3628 /*------------------------------------------------------------------------
3629 * PRIVATE ListVolumes
3631 * Description:
3632 * Routine used to list volumes, contacting the Volume Server
3633 * directly, bypassing the VLDB.
3635 * Arguments:
3636 * as : Ptr to parsed command line arguments.
3638 * Returns:
3639 * 0 Successful operation
3641 * Environment:
3642 * Nothing interesting.
3644 * Side Effects:
3645 * As advertised.
3646 *------------------------------------------------------------------------*/
3648 static int
3649 ListVolumes(struct cmd_syndesc *as, void *arock)
3651 afs_int32 apart, int32list, fast;
3652 afs_uint32 aserver;
3653 afs_int32 code;
3654 volintInfo *pntr;
3655 volintInfo *oldpntr = NULL;
3656 afs_int32 count;
3657 int i;
3658 char *base;
3659 volintXInfo *xInfoP;
3660 volintXInfo *origxInfoP = NULL; /*Ptr to current/orig extended vol info */
3661 int wantExtendedInfo; /*Do we want extended vol info? */
3663 char pname[10];
3664 struct partList dummyPartList;
3665 int all;
3666 int quiet, cnt;
3668 apart = -1;
3669 fast = 0;
3670 int32list = 0;
3672 if (as->parms[3].items)
3673 int32list = 1;
3674 if (as->parms[4].items)
3675 quiet = 1;
3676 else
3677 quiet = 0;
3678 if (as->parms[2].items)
3679 fast = 1;
3680 if (fast)
3681 all = 0;
3682 else
3683 all = 1;
3684 if (as->parms[5].items) {
3686 * We can't coexist with the fast flag.
3688 if (fast) {
3689 fprintf(STDERR,
3690 "vos: Can't use the -fast and -extended flags together\n");
3691 exit(1);
3695 * We need to turn on ``long'' listings to get the full effect.
3697 wantExtendedInfo = 1;
3698 int32list = 1;
3699 } else
3700 wantExtendedInfo = 0;
3701 if (as->parms[1].items) {
3702 apart = volutil_GetPartitionID(as->parms[1].items->data);
3703 if (apart < 0) {
3704 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3705 as->parms[1].items->data);
3706 exit(1);
3708 dummyPartList.partId[0] = apart;
3709 dummyPartList.partFlags[0] = PARTVALID;
3710 cnt = 1;
3712 aserver = GetServer(as->parms[0].items->data);
3713 if (aserver == 0) {
3714 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3715 as->parms[0].items->data);
3716 exit(1);
3719 if (apart != -1) {
3720 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3721 if (code)
3722 PrintError("", code);
3723 else
3724 fprintf(STDERR,
3725 "vos : partition %s does not exist on the server\n",
3726 as->parms[1].items->data);
3727 exit(1);
3729 } else {
3730 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
3731 if (code) {
3732 PrintDiagnostics("listvol", code);
3733 exit(1);
3736 for (i = 0; i < cnt; i++) {
3737 if (dummyPartList.partFlags[i] & PARTVALID) {
3738 if (wantExtendedInfo)
3739 code =
3740 UV_XListVolumes(aserver, dummyPartList.partId[i], all,
3741 &xInfoP, &count);
3742 else
3743 code =
3744 UV_ListVolumes(aserver, dummyPartList.partId[i], all,
3745 &pntr, &count);
3746 if (code) {
3747 PrintDiagnostics("listvol", code);
3748 exit(1);
3750 if (wantExtendedInfo) {
3751 origxInfoP = xInfoP;
3752 base = (char *)xInfoP;
3753 } else {
3754 oldpntr = pntr;
3755 base = (char *)pntr;
3758 if (!fast) {
3759 if (wantExtendedInfo)
3760 qsort(base, count, sizeof(volintXInfo), XCompareVolName);
3761 else
3762 qsort(base, count, sizeof(volintInfo), CompareVolName);
3763 } else {
3764 if (wantExtendedInfo)
3765 qsort(base, count, sizeof(volintXInfo), XCompareVolID);
3766 else
3767 qsort(base, count, sizeof(volintInfo), CompareVolID);
3769 MapPartIdIntoName(dummyPartList.partId[i], pname);
3770 if (!quiet)
3771 fprintf(STDOUT,
3772 "Total number of volumes on server %s partition %s: %lu \n",
3773 as->parms[0].items->data, pname,
3774 (unsigned long)count);
3775 if (wantExtendedInfo) {
3776 if (as->parms[6].items)
3777 XDisplayVolumes2(aserver, dummyPartList.partId[i], origxInfoP,
3778 count, int32list, fast, quiet);
3779 else
3780 XDisplayVolumes(aserver, dummyPartList.partId[i], origxInfoP,
3781 count, int32list, fast, quiet);
3782 if (xInfoP)
3783 free(xInfoP);
3784 xInfoP = (volintXInfo *) 0;
3785 } else {
3786 if (as->parms[6].items)
3787 DisplayVolumes2(aserver, dummyPartList.partId[i], oldpntr,
3788 count);
3789 else
3790 DisplayVolumes(aserver, dummyPartList.partId[i], oldpntr,
3791 count, int32list, fast, quiet);
3792 if (pntr)
3793 free(pntr);
3794 pntr = (volintInfo *) 0;
3798 return 0;
3801 static int
3802 SyncVldb(struct cmd_syndesc *as, void *arock)
3804 afs_int32 pnum = 0, code; /* part name */
3805 char part[10];
3806 int flags = 0;
3807 char *volname = 0;
3809 tserver = 0;
3810 if (as->parms[0].items) {
3811 tserver = GetServer(as->parms[0].items->data);
3812 if (!tserver) {
3813 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3814 as->parms[0].items->data);
3815 exit(1);
3819 if (as->parms[1].items) {
3820 pnum = volutil_GetPartitionID(as->parms[1].items->data);
3821 if (pnum < 0) {
3822 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3823 as->parms[1].items->data);
3824 exit(1);
3826 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
3827 if (code)
3828 PrintError("", code);
3829 else
3830 fprintf(STDERR,
3831 "vos: partition %s does not exist on the server\n",
3832 as->parms[1].items->data);
3833 exit(1);
3835 flags = 1;
3837 if (!tserver) {
3838 fprintf(STDERR,
3839 "The -partition option requires a -server option\n");
3840 exit(1);
3844 if (as->parms[3].items) {
3845 flags |= 2; /* don't update */
3848 if (as->parms[2].items) {
3849 /* Synchronize an individual volume */
3850 volname = as->parms[2].items->data;
3851 code = UV_SyncVolume(tserver, pnum, volname, flags);
3852 } else {
3853 if (!tserver) {
3854 fprintf(STDERR,
3855 "Without a -volume option, the -server option is required\n");
3856 exit(1);
3858 code = UV_SyncVldb(tserver, pnum, flags, 0 /*unused */ );
3861 if (code) {
3862 PrintDiagnostics("syncvldb", code);
3863 exit(1);
3866 /* Print a summary of what we did */
3867 if (volname)
3868 fprintf(STDOUT, "VLDB volume %s synchronized", volname);
3869 else
3870 fprintf(STDOUT, "VLDB synchronized");
3871 if (tserver) {
3872 fprintf(STDOUT, " with state of server %s", as->parms[0].items->data);
3874 if (flags & 1) {
3875 MapPartIdIntoName(pnum, part);
3876 fprintf(STDOUT, " partition %s\n", part);
3878 fprintf(STDOUT, "\n");
3880 return 0;
3883 static int
3884 SyncServer(struct cmd_syndesc *as, void *arock)
3886 afs_int32 pnum, code; /* part name */
3887 char part[10];
3889 int flags = 0;
3891 tserver = GetServer(as->parms[0].items->data);
3892 if (!tserver) {
3893 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3894 as->parms[0].items->data);
3895 exit(1);
3897 if (as->parms[1].items) {
3898 pnum = volutil_GetPartitionID(as->parms[1].items->data);
3899 if (pnum < 0) {
3900 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3901 as->parms[1].items->data);
3902 exit(1);
3904 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
3905 if (code)
3906 PrintError("", code);
3907 else
3908 fprintf(STDERR,
3909 "vos : partition %s does not exist on the server\n",
3910 as->parms[1].items->data);
3911 exit(1);
3913 flags = 1;
3914 } else {
3915 pnum = -1;
3918 if (as->parms[2].items) {
3919 flags |= 2; /* don't update */
3921 code = UV_SyncServer(tserver, pnum, flags, 0 /*unused */ );
3922 if (code) {
3923 PrintDiagnostics("syncserv", code);
3924 exit(1);
3926 if (flags & 1) {
3927 MapPartIdIntoName(pnum, part);
3928 fprintf(STDOUT, "Server %s partition %s synchronized with VLDB\n",
3929 as->parms[0].items->data, part);
3930 } else
3931 fprintf(STDOUT, "Server %s synchronized with VLDB\n",
3932 as->parms[0].items->data);
3933 return 0;
3937 static int
3938 VolumeInfoCmd(char *name)
3940 struct nvldbentry entry;
3941 afs_int32 vcode;
3943 /* The vlserver will handle names with the .readonly
3944 * and .backup extension as well as volume ids.
3946 vcode = VLDB_GetEntryByName(name, &entry);
3947 if (vcode) {
3948 PrintError("", vcode);
3949 exit(1);
3951 MapHostToNetwork(&entry);
3952 EnumerateEntry(&entry);
3954 /* Defect #3027: grubby check to handle locked volume.
3955 * If VLOP_ALLOPERS is set, the entry is locked.
3956 * Leave this routine as is, but put in correct check.
3958 PrintLocked(entry.flags);
3960 return 0;
3963 static int
3964 VolumeZap(struct cmd_syndesc *as, void *arock)
3966 struct nvldbentry entry;
3967 afs_uint32 volid, zapbackupid = 0, backupid = 0;
3968 afs_int32 code, server, part, err;
3970 if (as->parms[3].items) {
3971 /* force flag is on, use the other version */
3972 return NukeVolume(as);
3975 if (as->parms[4].items) {
3976 zapbackupid = 1;
3979 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
3980 if (volid == 0) {
3981 if (err)
3982 PrintError("", err);
3983 else
3984 fprintf(STDERR, "vos: can't find volume '%s'\n",
3985 as->parms[2].items->data);
3986 exit(1);
3988 part = volutil_GetPartitionID(as->parms[1].items->data);
3989 if (part < 0) {
3990 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3991 as->parms[1].items->data);
3992 exit(1);
3994 server = GetServer(as->parms[0].items->data);
3995 if (!server) {
3996 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3997 as->parms[0].items->data);
3998 exit(1);
4000 if (!IsPartValid(part, server, &code)) { /*check for validity of the partition */
4001 if (code)
4002 PrintError("", code);
4003 else
4004 fprintf(STDERR,
4005 "vos : partition %s does not exist on the server\n",
4006 as->parms[1].items->data);
4007 exit(1);
4009 code = VLDB_GetEntryByID(volid, -1, &entry);
4010 if (!code) {
4011 if (volid == entry.volumeId[RWVOL])
4012 backupid = entry.volumeId[BACKVOL];
4013 fprintf(STDERR,
4014 "Warning: Entry for volume number %lu exists in VLDB (but we're zapping it anyway!)\n",
4015 (unsigned long)volid);
4017 if (zapbackupid) {
4018 volintInfo *pntr = (volintInfo *) 0;
4020 if (!backupid) {
4021 code = UV_ListOneVolume(server, part, volid, &pntr);
4022 if (!code) {
4023 if (volid == pntr->parentID)
4024 backupid = pntr->backupID;
4025 if (pntr)
4026 free(pntr);
4029 if (backupid) {
4030 code = UV_VolumeZap(server, part, backupid);
4031 if (code) {
4032 PrintDiagnostics("zap", code);
4033 exit(1);
4035 fprintf(STDOUT, "Backup Volume %lu deleted\n",
4036 (unsigned long)backupid);
4039 code = UV_VolumeZap(server, part, volid);
4040 if (code) {
4041 PrintDiagnostics("zap", code);
4042 exit(1);
4044 fprintf(STDOUT, "Volume %lu deleted\n", (unsigned long)volid);
4046 return 0;
4049 static int
4050 VolserStatus(struct cmd_syndesc *as, void *arock)
4052 afs_uint32 server;
4053 afs_int32 code;
4054 transDebugInfo *pntr, *oldpntr;
4055 afs_int32 count;
4056 int i;
4057 char pname[10];
4058 time_t t;
4060 server = GetServer(as->parms[0].items->data);
4061 if (!server) {
4062 fprintf(STDERR, "vos: host '%s' not found in host table\n",
4063 as->parms[0].items->data);
4064 exit(1);
4066 code = UV_VolserStatus(server, &pntr, &count);
4067 if (code) {
4068 PrintDiagnostics("status", code);
4069 exit(1);
4071 oldpntr = pntr;
4072 if (count == 0)
4073 fprintf(STDOUT, "No active transactions on %s\n",
4074 as->parms[0].items->data);
4075 else {
4076 fprintf(STDOUT, "Total transactions: %d\n", count);
4078 for (i = 0; i < count; i++) {
4079 /*print out the relevant info */
4080 fprintf(STDOUT, "--------------------------------------\n");
4081 t = pntr->creationTime;
4082 fprintf(STDOUT, "transaction: %lu created: %s",
4083 (unsigned long)pntr->tid, ctime(&t));
4084 t = pntr->time;
4085 fprintf(STDOUT, "lastActiveTime: %s", ctime(&t));
4086 if (pntr->returnCode) {
4087 fprintf(STDOUT, "returnCode: %lu\n",
4088 (unsigned long)pntr->returnCode);
4090 if (pntr->iflags) {
4091 fprintf(STDOUT, "attachFlags: ");
4092 switch (pntr->iflags) {
4093 case ITOffline:
4094 fprintf(STDOUT, "offline ");
4095 break;
4096 case ITBusy:
4097 fprintf(STDOUT, "busy ");
4098 break;
4099 case ITReadOnly:
4100 fprintf(STDOUT, "readonly ");
4101 break;
4102 case ITCreate:
4103 fprintf(STDOUT, "create ");
4104 break;
4105 case ITCreateVolID:
4106 fprintf(STDOUT, "create volid ");
4107 break;
4109 fprintf(STDOUT, "\n");
4111 if (pntr->vflags) {
4112 fprintf(STDOUT, "volumeStatus: ");
4113 switch (pntr->vflags) {
4114 case VTDeleteOnSalvage:
4115 fprintf(STDOUT, "deleteOnSalvage ");
4116 case VTOutOfService:
4117 fprintf(STDOUT, "outOfService ");
4118 case VTDeleted:
4119 fprintf(STDOUT, "deleted ");
4121 fprintf(STDOUT, "\n");
4123 if (pntr->tflags) {
4124 fprintf(STDOUT, "transactionFlags: ");
4125 fprintf(STDOUT, "delete\n");
4127 MapPartIdIntoName(pntr->partition, pname);
4128 fprintf(STDOUT, "volume: %lu partition: %s procedure: %s\n",
4129 (unsigned long)pntr->volid, pname, pntr->lastProcName);
4130 if (pntr->callValid) {
4131 t = pntr->lastReceiveTime;
4132 fprintf(STDOUT, "packetRead: %lu lastReceiveTime: %s",
4133 (unsigned long)pntr->readNext, ctime(&t));
4134 t = pntr->lastSendTime;
4135 fprintf(STDOUT, "packetSend: %lu lastSendTime: %s",
4136 (unsigned long)pntr->transmitNext, ctime(&t));
4138 pntr++;
4139 fprintf(STDOUT, "--------------------------------------\n");
4140 fprintf(STDOUT, "\n");
4142 if (oldpntr)
4143 free(oldpntr);
4144 return 0;
4147 static int
4148 RenameVolume(struct cmd_syndesc *as, void *arock)
4150 afs_int32 code1, code2, code;
4151 struct nvldbentry entry;
4153 code1 = VLDB_GetEntryByName(as->parms[0].items->data, &entry);
4154 if (code1) {
4155 fprintf(STDERR, "vos: Could not find entry for volume %s\n",
4156 as->parms[0].items->data);
4157 exit(1);
4159 code2 = VLDB_GetEntryByName(as->parms[1].items->data, &entry);
4160 if ((!code1) && (!code2)) { /*the newname already exists */
4161 fprintf(STDERR, "vos: volume %s already exists\n",
4162 as->parms[1].items->data);
4163 exit(1);
4166 if (code1 && code2) {
4167 fprintf(STDERR, "vos: Could not find entry for volume %s or %s\n",
4168 as->parms[0].items->data, as->parms[1].items->data);
4169 exit(1);
4171 if (!VolNameOK(as->parms[0].items->data)) {
4172 fprintf(STDERR,
4173 "Illegal volume name %s, should not end in .readonly or .backup\n",
4174 as->parms[0].items->data);
4175 exit(1);
4177 if (!ISNAMEVALID(as->parms[1].items->data)) {
4178 fprintf(STDERR,
4179 "vos: the new volume name %s exceeds the size limit of %d\n",
4180 as->parms[1].items->data, VOLSER_OLDMAXVOLNAME - 10);
4181 exit(1);
4183 if (!VolNameOK(as->parms[1].items->data)) {
4184 fprintf(STDERR,
4185 "Illegal volume name %s, should not end in .readonly or .backup\n",
4186 as->parms[1].items->data);
4187 exit(1);
4189 if (IsNumeric(as->parms[1].items->data)) {
4190 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
4191 as->parms[1].items->data);
4192 exit(1);
4194 MapHostToNetwork(&entry);
4195 code =
4196 UV_RenameVolume(&entry, as->parms[0].items->data,
4197 as->parms[1].items->data);
4198 if (code) {
4199 PrintDiagnostics("rename", code);
4200 exit(1);
4202 fprintf(STDOUT, "Renamed volume %s to %s\n", as->parms[0].items->data,
4203 as->parms[1].items->data);
4204 return 0;
4208 GetVolumeInfo(afs_uint32 volid, afs_uint32 *server, afs_int32 *part, afs_int32 *voltype,
4209 struct nvldbentry *rentry)
4211 afs_int32 vcode;
4212 int i, index = -1;
4214 vcode = VLDB_GetEntryByID(volid, -1, rentry);
4215 if (vcode) {
4216 fprintf(STDERR,
4217 "Could not fetch the entry for volume %lu from VLDB \n",
4218 (unsigned long)volid);
4219 PrintError("", vcode);
4220 return (vcode);
4222 MapHostToNetwork(rentry);
4223 if (volid == rentry->volumeId[ROVOL]) {
4224 *voltype = ROVOL;
4225 for (i = 0; i < rentry->nServers; i++) {
4226 if ((index == -1) && (rentry->serverFlags[i] & ITSROVOL)
4227 && !(rentry->serverFlags[i] & RO_DONTUSE))
4228 index = i;
4230 if (index == -1) {
4231 fprintf(STDERR,
4232 "RO volume is not found in VLDB entry for volume %lu\n",
4233 (unsigned long)volid);
4234 return -1;
4237 *server = rentry->serverNumber[index];
4238 *part = rentry->serverPartition[index];
4239 return 0;
4242 index = Lp_GetRwIndex(rentry);
4243 if (index == -1) {
4244 fprintf(STDERR,
4245 "RW Volume is not found in VLDB entry for volume %lu\n",
4246 (unsigned long)volid);
4247 return -1;
4249 if (volid == rentry->volumeId[RWVOL]) {
4250 *voltype = RWVOL;
4251 *server = rentry->serverNumber[index];
4252 *part = rentry->serverPartition[index];
4253 return 0;
4255 if (volid == rentry->volumeId[BACKVOL]) {
4256 *voltype = BACKVOL;
4257 *server = rentry->serverNumber[index];
4258 *part = rentry->serverPartition[index];
4259 return 0;
4261 fprintf(STDERR,
4262 "unexpected volume type for volume %lu\n",
4263 (unsigned long)volid);
4264 return -1;
4267 static int
4268 DeleteEntry(struct cmd_syndesc *as, void *arock)
4270 afs_int32 apart = 0;
4271 afs_uint32 avolid;
4272 afs_int32 vcode;
4273 struct VldbListByAttributes attributes;
4274 nbulkentries arrayEntries;
4275 struct nvldbentry *vllist;
4276 struct cmd_item *itp;
4277 afs_int32 nentries;
4278 int j;
4279 char prefix[VOLSER_MAXVOLNAME + 1];
4280 int seenprefix = 0;
4281 afs_int32 totalBack = 0, totalFail = 0, err;
4283 if (as->parms[0].items) { /* -id */
4284 if (as->parms[1].items || as->parms[2].items || as->parms[3].items) {
4285 fprintf(STDERR,
4286 "You cannot use -server, -partition, or -prefix with the -id argument\n");
4287 exit(-2);
4289 for (itp = as->parms[0].items; itp; itp = itp->next) {
4290 avolid = vsu_GetVolumeID(itp->data, cstruct, &err);
4291 if (avolid == 0) {
4292 if (err)
4293 PrintError("", err);
4294 else
4295 fprintf(STDERR, "vos: can't find volume '%s'\n",
4296 itp->data);
4297 continue;
4299 if (as->parms[4].items || as->parms[5].items) {
4300 /* -noexecute (hidden) or -dryrun */
4301 fprintf(STDOUT, "Would have deleted VLDB entry for %s \n",
4302 itp->data);
4303 fflush(STDOUT);
4304 continue;
4306 vcode = ubik_VL_DeleteEntry(cstruct, 0, avolid, RWVOL);
4307 if (vcode) {
4308 fprintf(STDERR, "Could not delete entry for volume %s\n",
4309 itp->data);
4310 fprintf(STDERR,
4311 "You must specify a RW volume name or ID "
4312 "(the entire VLDB entry will be deleted)\n");
4313 PrintError("", vcode);
4314 totalFail++;
4315 continue;
4317 totalBack++;
4319 fprintf(STDOUT, "Deleted %d VLDB entries\n", totalBack);
4320 return (totalFail);
4323 if (!as->parms[1].items && !as->parms[2].items && !as->parms[3].items) {
4324 fprintf(STDERR, "You must specify an option\n");
4325 exit(-2);
4328 /* Zero out search attributes */
4329 memset(&attributes, 0, sizeof(struct VldbListByAttributes));
4331 if (as->parms[1].items) { /* -prefix */
4332 strncpy(prefix, as->parms[1].items->data, VOLSER_MAXVOLNAME);
4333 seenprefix = 1;
4334 if (!as->parms[2].items && !as->parms[3].items) { /* a single entry only */
4335 fprintf(STDERR,
4336 "You must provide -server with the -prefix argument\n");
4337 exit(-2);
4341 if (as->parms[2].items) { /* -server */
4342 afs_uint32 aserver;
4343 aserver = GetServer(as->parms[2].items->data);
4344 if (aserver == 0) {
4345 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4346 as->parms[2].items->data);
4347 exit(-1);
4349 attributes.server = ntohl(aserver);
4350 attributes.Mask |= VLLIST_SERVER;
4353 if (as->parms[3].items) { /* -partition */
4354 if (!as->parms[2].items) {
4355 fprintf(STDERR,
4356 "You must provide -server with the -partition argument\n");
4357 exit(-2);
4359 apart = volutil_GetPartitionID(as->parms[3].items->data);
4360 if (apart < 0) {
4361 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4362 as->parms[3].items->data);
4363 exit(-1);
4365 attributes.partition = apart;
4366 attributes.Mask |= VLLIST_PARTITION;
4369 /* Print status line of what we are doing */
4370 fprintf(STDOUT, "Deleting VLDB entries for ");
4371 if (as->parms[2].items) {
4372 fprintf(STDOUT, "server %s ", as->parms[2].items->data);
4374 if (as->parms[3].items) {
4375 char pname[10];
4376 MapPartIdIntoName(apart, pname);
4377 fprintf(STDOUT, "partition %s ", pname);
4379 if (seenprefix) {
4380 fprintf(STDOUT, "which are prefixed with %s ", prefix);
4382 fprintf(STDOUT, "\n");
4383 fflush(STDOUT);
4385 /* Get all the VLDB entries on a server and/or partition */
4386 memset(&arrayEntries, 0, sizeof(arrayEntries));
4387 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
4388 if (vcode) {
4389 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4390 PrintError("", vcode);
4391 exit(-1);
4394 /* Process each entry */
4395 for (j = 0; j < nentries; j++) {
4396 vllist = &arrayEntries.nbulkentries_val[j];
4397 if (seenprefix) {
4398 /* It only deletes the RW volumes */
4399 if (strncmp(vllist->name, prefix, strlen(prefix))) {
4400 if (verbose) {
4401 fprintf(STDOUT,
4402 "Omitting to delete %s due to prefix %s mismatch\n",
4403 vllist->name, prefix);
4405 fflush(STDOUT);
4406 continue;
4410 if (as->parms[4].items || as->parms[5].items) {
4411 /* -noexecute (hidden) or -dryrun */
4412 fprintf(STDOUT, "Would have deleted VLDB entry for %s \n",
4413 vllist->name);
4414 fflush(STDOUT);
4415 continue;
4418 /* Only matches the RW volume name */
4419 avolid = vllist->volumeId[RWVOL];
4420 vcode = ubik_VL_DeleteEntry(cstruct, 0, avolid, RWVOL);
4421 if (vcode) {
4422 fprintf(STDOUT, "Could not delete VLDB entry for %s\n",
4423 vllist->name);
4424 totalFail++;
4425 PrintError("", vcode);
4426 continue;
4427 } else {
4428 totalBack++;
4429 if (verbose)
4430 fprintf(STDOUT, "Deleted VLDB entry for %s \n", vllist->name);
4432 fflush(STDOUT);
4433 } /*for */
4435 fprintf(STDOUT, "----------------------\n");
4436 fprintf(STDOUT,
4437 "Total VLDB entries deleted: %lu; failed to delete: %lu\n",
4438 (unsigned long)totalBack, (unsigned long)totalFail);
4440 xdr_free((xdrproc_t) xdr_nbulkentries, &arrayEntries);
4441 return 0;
4445 static int
4446 CompareVldbEntryByName(const void *p1, const void *p2)
4448 struct nvldbentry *arg1, *arg2;
4450 arg1 = (struct nvldbentry *)p1;
4451 arg2 = (struct nvldbentry *)p2;
4452 return (strcmp(arg1->name, arg2->name));
4456 static int CompareVldbEntry(char *p1, char *p2)
4458 struct nvldbentry *arg1,*arg2;
4459 int i;
4460 int pos1, pos2;
4461 char comp1[100],comp2[100];
4462 char temp1[20],temp2[20];
4464 arg1 = (struct nvldbentry *)p1;
4465 arg2 = (struct nvldbentry *)p2;
4466 pos1 = -1;
4467 pos2 = -1;
4469 for(i = 0; i < arg1->nServers; i++)
4470 if(arg1->serverFlags[i] & ITSRWVOL) pos1 = i;
4471 for(i = 0; i < arg2->nServers; i++)
4472 if(arg2->serverFlags[i] & ITSRWVOL) pos2 = i;
4473 if(pos1 == -1 || pos2 == -1){
4474 pos1 = 0;
4475 pos2 = 0;
4477 sprintf(comp1,"%10u",arg1->serverNumber[pos1]);
4478 sprintf(comp2,"%10u",arg2->serverNumber[pos2]);
4479 sprintf(temp1,"%10u",arg1->serverPartition[pos1]);
4480 sprintf(temp2,"%10u",arg2->serverPartition[pos2]);
4481 strcat(comp1,temp1);
4482 strcat(comp2,temp2);
4483 strcat(comp1,arg1->name);
4484 strcat(comp1,arg2->name);
4485 return(strcmp(comp1,comp2));
4490 static int
4491 ListVLDB(struct cmd_syndesc *as, void *arock)
4493 afs_int32 apart;
4494 afs_uint32 aserver;
4495 afs_int32 code;
4496 afs_int32 vcode;
4497 struct VldbListByAttributes attributes;
4498 nbulkentries arrayEntries;
4499 struct nvldbentry *vllist, *tarray = 0, *ttarray;
4500 afs_int32 centries, nentries = 0;
4501 afs_int32 tarraysize = 0;
4502 afs_int32 parraysize;
4503 int j;
4504 char pname[10];
4505 int quiet, sort, lock;
4506 afs_int32 thisindex, nextindex;
4508 aserver = 0;
4509 apart = 0;
4511 memset(&attributes, 0, sizeof(attributes));
4512 lock = (as->parms[3].items ? 1 : 0); /* -lock flag */
4513 quiet = (as->parms[4].items ? 1 : 0); /* -quit flag */
4514 sort = (as->parms[5].items ? 0 : 1); /* -nosort flag */
4516 /* If the volume name is given, Use VolumeInfoCmd to look it up
4517 * and not ListAttributes.
4519 if (as->parms[0].items) {
4520 if (lock) {
4521 fprintf(STDERR,
4522 "vos: illegal use of '-locked' switch, need to specify server and/or partition\n");
4523 exit(1);
4525 code = VolumeInfoCmd(as->parms[0].items->data);
4526 if (code) {
4527 PrintError("", code);
4528 exit(1);
4530 return 0;
4533 /* Server specified */
4534 if (as->parms[1].items) {
4535 aserver = GetServer(as->parms[1].items->data);
4536 if (aserver == 0) {
4537 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4538 as->parms[1].items->data);
4539 exit(1);
4541 attributes.server = ntohl(aserver);
4542 attributes.Mask |= VLLIST_SERVER;
4545 /* Partition specified */
4546 if (as->parms[2].items) {
4547 apart = volutil_GetPartitionID(as->parms[2].items->data);
4548 if (apart < 0) {
4549 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4550 as->parms[2].items->data);
4551 exit(1);
4553 attributes.partition = apart;
4554 attributes.Mask |= VLLIST_PARTITION;
4557 if (lock) {
4558 attributes.Mask |= VLLIST_FLAG;
4559 attributes.flag = VLOP_ALLOPERS;
4562 /* Print header information */
4563 if (!quiet) {
4564 MapPartIdIntoName(apart, pname);
4565 fprintf(STDOUT, "VLDB entries for %s %s%s%s %s\n",
4566 (as->parms[1].items ? "server" : "all"),
4567 (as->parms[1].items ? as->parms[1].items->data : "servers"),
4568 (as->parms[2].items ? " partition " : ""),
4569 (as->parms[2].items ? pname : ""),
4570 (lock ? "which are locked:" : ""));
4573 for (thisindex = 0; (thisindex != -1); thisindex = nextindex) {
4574 memset(&arrayEntries, 0, sizeof(arrayEntries));
4575 centries = 0;
4576 nextindex = -1;
4578 vcode =
4579 VLDB_ListAttributesN2(&attributes, 0, thisindex, &centries,
4580 &arrayEntries, &nextindex);
4581 if (vcode == RXGEN_OPCODE) {
4582 /* Vlserver not running with ListAttributesN2. Fall back */
4583 vcode =
4584 VLDB_ListAttributes(&attributes, &centries, &arrayEntries);
4585 nextindex = -1;
4587 if (vcode) {
4588 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4589 PrintError("", vcode);
4590 exit(1);
4592 nentries += centries;
4594 /* We don't sort, so just print the entries now */
4595 if (!sort) {
4596 for (j = 0; j < centries; j++) { /* process each entry */
4597 vllist = &arrayEntries.nbulkentries_val[j];
4598 MapHostToNetwork(vllist);
4599 EnumerateEntry(vllist);
4601 PrintLocked(vllist->flags);
4605 /* So we sort. First we must collect all the entries and keep
4606 * them in memory.
4608 else if (centries > 0) {
4609 if (!tarray) {
4610 /* malloc the first bulk entries array */
4611 tarraysize = centries * sizeof(struct nvldbentry);
4612 tarray = malloc(tarraysize);
4613 if (!tarray) {
4614 fprintf(STDERR,
4615 "Could not allocate enough space for the VLDB entries\n");
4616 goto bypass;
4618 memcpy((char*)tarray, arrayEntries.nbulkentries_val, tarraysize);
4619 } else {
4620 /* Grow the tarray to keep the extra entries */
4621 parraysize = (centries * sizeof(struct nvldbentry));
4622 ttarray =
4623 (struct nvldbentry *)realloc(tarray,
4624 tarraysize + parraysize);
4625 if (!ttarray) {
4626 fprintf(STDERR,
4627 "Could not allocate enough space for the VLDB entries\n");
4628 goto bypass;
4630 tarray = ttarray;
4632 /* Copy them in */
4633 memcpy(((char *)tarray) + tarraysize,
4634 (char *)arrayEntries.nbulkentries_val, parraysize);
4635 tarraysize += parraysize;
4639 /* Free the bulk array */
4640 xdr_free((xdrproc_t) xdr_nbulkentries, &arrayEntries);
4643 /* Here is where we now sort all the entries and print them */
4644 if (sort && (nentries > 0)) {
4645 qsort((char *)tarray, nentries, sizeof(struct nvldbentry),
4646 CompareVldbEntryByName);
4647 for (vllist = tarray, j = 0; j < nentries; j++, vllist++) {
4648 MapHostToNetwork(vllist);
4649 EnumerateEntry(vllist);
4651 PrintLocked(vllist->flags);
4655 bypass:
4656 if (!quiet)
4657 fprintf(STDOUT, "\nTotal entries: %lu\n", (unsigned long)nentries);
4658 if (tarray)
4659 free(tarray);
4660 return 0;
4663 static int
4664 BackSys(struct cmd_syndesc *as, void *arock)
4666 afs_uint32 avolid;
4667 afs_int32 apart = 0;
4668 afs_uint32 aserver = 0, aserver1;
4669 afs_int32 code, apart1;
4670 afs_int32 vcode;
4671 struct VldbListByAttributes attributes;
4672 nbulkentries arrayEntries;
4673 struct nvldbentry *vllist;
4674 afs_int32 nentries;
4675 int j;
4676 char pname[10];
4677 int seenprefix, seenxprefix, exclude, ex, exp, noaction;
4678 afs_int32 totalBack = 0;
4679 afs_int32 totalFail = 0;
4680 int previdx = -1;
4681 int error;
4682 int same = 0;
4683 struct cmd_item *ti;
4684 int match = 0;
4685 #ifndef HAVE_POSIX_REGEX
4686 char *ccode;
4687 #endif
4689 memset(&attributes, 0, sizeof(struct VldbListByAttributes));
4690 attributes.Mask = 0;
4692 seenprefix = (as->parms[0].items ? 1 : 0);
4693 exclude = (as->parms[3].items ? 1 : 0);
4694 seenxprefix = (as->parms[4].items ? 1 : 0);
4695 noaction = (as->parms[5].items ? 1 : 0);
4697 if (as->parms[1].items) { /* -server */
4698 aserver = GetServer(as->parms[1].items->data);
4699 if (aserver == 0) {
4700 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4701 as->parms[1].items->data);
4702 exit(1);
4704 attributes.server = ntohl(aserver);
4705 attributes.Mask |= VLLIST_SERVER;
4708 if (as->parms[2].items) { /* -partition */
4709 apart = volutil_GetPartitionID(as->parms[2].items->data);
4710 if (apart < 0) {
4711 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4712 as->parms[2].items->data);
4713 exit(1);
4715 attributes.partition = apart;
4716 attributes.Mask |= VLLIST_PARTITION;
4719 /* Check to make sure the prefix and xprefix expressions compile ok */
4720 if (seenprefix) {
4721 for (ti = as->parms[0].items; ti; ti = ti->next) {
4722 if (strncmp(ti->data, "^", 1) == 0) {
4723 #ifdef HAVE_POSIX_REGEX
4724 regex_t re;
4725 char errbuf[256];
4727 code = regcomp(&re, ti->data, REG_NOSUB);
4728 if (code != 0) {
4729 regerror(code, &re, errbuf, sizeof errbuf);
4730 fprintf(STDERR,
4731 "Unrecognizable -prefix regular expression: '%s': %s\n",
4732 ti->data, errbuf);
4733 exit(1);
4735 regfree(&re);
4736 #else
4737 ccode = (char *)re_comp(ti->data);
4738 if (ccode) {
4739 fprintf(STDERR,
4740 "Unrecognizable -prefix regular expression: '%s': %s\n",
4741 ti->data, ccode);
4742 exit(1);
4744 #endif
4748 if (seenxprefix) {
4749 for (ti = as->parms[4].items; ti; ti = ti->next) {
4750 if (strncmp(ti->data, "^", 1) == 0) {
4751 #ifdef HAVE_POSIX_REGEX
4752 regex_t re;
4753 char errbuf[256];
4755 code = regcomp(&re, ti->data, REG_NOSUB);
4756 if (code != 0) {
4757 regerror(code, &re, errbuf, sizeof errbuf);
4758 fprintf(STDERR,
4759 "Unrecognizable -xprefix regular expression: '%s': %s\n",
4760 ti->data, errbuf);
4761 exit(1);
4763 regfree(&re);
4764 #else
4765 ccode = (char *)re_comp(ti->data);
4766 if (ccode) {
4767 fprintf(STDERR,
4768 "Unrecognizable -xprefix regular expression: '%s': %s\n",
4769 ti->data, ccode);
4770 exit(1);
4772 #endif
4777 memset(&arrayEntries, 0, sizeof(arrayEntries)); /* initialize to hint the stub to alloc space */
4778 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
4779 if (vcode) {
4780 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4781 PrintError("", vcode);
4782 exit(1);
4785 if (as->parms[1].items || as->parms[2].items || verbose) {
4786 fprintf(STDOUT, "%s up volumes",
4787 (noaction ? "Would have backed" : "Backing"));
4789 if (as->parms[1].items) {
4790 fprintf(STDOUT, " on server %s", as->parms[1].items->data);
4791 } else if (as->parms[2].items) {
4792 fprintf(STDOUT, " for all servers");
4795 if (as->parms[2].items) {
4796 MapPartIdIntoName(apart, pname);
4797 fprintf(STDOUT, " partition %s", pname);
4800 if (seenprefix || (!seenprefix && seenxprefix)) {
4801 ti = (seenprefix ? as->parms[0].items : as->parms[4].items);
4802 ex = (seenprefix ? exclude : !exclude);
4803 exp = (strncmp(ti->data, "^", 1) == 0);
4804 fprintf(STDOUT, " which %smatch %s '%s'", (ex ? "do not " : ""),
4805 (exp ? "expression" : "prefix"), ti->data);
4806 for (ti = ti->next; ti; ti = ti->next) {
4807 exp = (strncmp(ti->data, "^", 1) == 0);
4808 printf(" %sor %s '%s'", (ex ? "n" : ""),
4809 (exp ? "expression" : "prefix"), ti->data);
4813 if (seenprefix && seenxprefix) {
4814 ti = as->parms[4].items;
4815 exp = (strncmp(ti->data, "^", 1) == 0);
4816 fprintf(STDOUT, " %swhich match %s '%s'",
4817 (exclude ? "adding those " : "removing those "),
4818 (exp ? "expression" : "prefix"), ti->data);
4819 for (ti = ti->next; ti; ti = ti->next) {
4820 exp = (strncmp(ti->data, "^", 1) == 0);
4821 printf(" or %s '%s'", (exp ? "expression" : "prefix"),
4822 ti->data);
4825 fprintf(STDOUT, " .. ");
4826 if (verbose)
4827 fprintf(STDOUT, "\n");
4828 fflush(STDOUT);
4831 for (j = 0; j < nentries; j++) { /* process each vldb entry */
4832 vllist = &arrayEntries.nbulkentries_val[j];
4834 if (seenprefix) {
4835 for (ti = as->parms[0].items; ti; ti = ti->next) {
4836 if (strncmp(ti->data, "^", 1) == 0) {
4837 #ifdef HAVE_POSIX_REGEX
4838 regex_t re;
4839 char errbuf[256];
4841 /* XXX -- should just do the compile once! */
4842 code = regcomp(&re, ti->data, REG_NOSUB);
4843 if (code != 0) {
4844 regerror(code, &re, errbuf, sizeof errbuf);
4845 fprintf(STDERR,
4846 "Error in -prefix regular expression: '%s': %s\n",
4847 ti->data, errbuf);
4848 exit(1);
4850 match = (regexec(&re, vllist->name, 0, NULL, 0) == 0);
4851 regfree(&re);
4852 #else
4853 ccode = (char *)re_comp(ti->data);
4854 if (ccode) {
4855 fprintf(STDERR,
4856 "Error in -prefix regular expression: '%s': %s\n",
4857 ti->data, ccode);
4858 exit(1);
4860 match = (re_exec(vllist->name) == 1);
4861 #endif
4862 } else {
4863 match =
4864 (strncmp(vllist->name, ti->data, strlen(ti->data)) ==
4867 if (match)
4868 break;
4870 } else {
4871 match = 1;
4874 /* Without the -exclude flag: If it matches the prefix, then
4875 * check if we want to exclude any from xprefix.
4876 * With the -exclude flag: If it matches the prefix, then
4877 * check if we want to add any from xprefix.
4879 if (match && seenxprefix) {
4880 for (ti = as->parms[4].items; ti; ti = ti->next) {
4881 if (strncmp(ti->data, "^", 1) == 0) {
4882 #ifdef HAVE_POSIX_REGEX
4883 regex_t re;
4884 char errbuf[256];
4886 /* XXX -- should just do the compile once! */
4887 code = regcomp(&re, ti->data, REG_NOSUB);
4888 if (code != 0) {
4889 regerror(code, &re, errbuf, sizeof errbuf);
4890 fprintf(STDERR,
4891 "Error in -xprefix regular expression: '%s': %s\n",
4892 ti->data, errbuf);
4893 exit(1);
4895 if (regexec(&re, vllist->name, 0, NULL, 0) == 0)
4896 match = 0;
4897 regfree(&re);
4898 #else
4899 ccode = (char *)re_comp(ti->data);
4900 if (ccode) {
4901 fprintf(STDERR,
4902 "Error in -xprefix regular expression: '%s': %s\n",
4903 ti->data, ccode);
4904 exit(1);
4906 if (re_exec(vllist->name) == 1) {
4907 match = 0;
4908 break;
4910 #endif
4911 } else {
4912 if (strncmp(vllist->name, ti->data, strlen(ti->data)) ==
4913 0) {
4914 match = 0;
4915 break;
4921 if (exclude)
4922 match = !match; /* -exclude will reverse the match */
4923 if (!match)
4924 continue; /* Skip if no match */
4926 /* Print list of volumes to backup */
4927 if (noaction) {
4928 fprintf(STDOUT, " %s\n", vllist->name);
4929 continue;
4932 if (!(vllist->flags & RW_EXISTS)) {
4933 if (verbose) {
4934 fprintf(STDOUT,
4935 "Omitting to backup %s since RW volume does not exist \n",
4936 vllist->name);
4937 fprintf(STDOUT, "\n");
4939 fflush(STDOUT);
4940 continue;
4943 avolid = vllist->volumeId[RWVOL];
4944 MapHostToNetwork(vllist);
4945 GetServerAndPart(vllist, RWVOL, &aserver1, &apart1, &previdx);
4946 if (aserver1 == -1 || apart1 == -1) {
4947 fprintf(STDOUT, "could not backup %s, invalid VLDB entry\n",
4948 vllist->name);
4949 totalFail++;
4950 continue;
4952 if (aserver) {
4953 same = VLDB_IsSameAddrs(aserver, aserver1, &error);
4954 if (error) {
4955 fprintf(STDERR,
4956 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
4957 aserver, error);
4958 totalFail++;
4959 continue;
4962 if ((aserver && !same) || (apart && (apart != apart1))) {
4963 if (verbose) {
4964 fprintf(STDOUT,
4965 "Omitting to backup %s since the RW is in a different location\n",
4966 vllist->name);
4968 continue;
4970 if (verbose) {
4971 time_t now = time(0);
4972 fprintf(STDOUT, "Creating backup volume for %s on %s",
4973 vllist->name, ctime(&now));
4974 fflush(STDOUT);
4977 code = UV_BackupVolume(aserver1, apart1, avolid);
4978 if (code) {
4979 fprintf(STDOUT, "Could not backup %s\n", vllist->name);
4980 totalFail++;
4981 } else {
4982 totalBack++;
4984 if (verbose)
4985 fprintf(STDOUT, "\n");
4986 fflush(STDOUT);
4987 } /* process each vldb entry */
4988 fprintf(STDOUT, "done\n");
4989 fprintf(STDOUT, "Total volumes backed up: %lu; failed to backup: %lu\n",
4990 (unsigned long)totalBack, (unsigned long)totalFail);
4991 fflush(STDOUT);
4992 xdr_free((xdrproc_t) xdr_nbulkentries, &arrayEntries);
4993 return 0;
4996 static int
4997 UnlockVLDB(struct cmd_syndesc *as, void *arock)
4999 afs_int32 apart;
5000 afs_uint32 aserver = 0;
5001 afs_int32 code;
5002 afs_int32 vcode;
5003 struct VldbListByAttributes attributes;
5004 nbulkentries arrayEntries;
5005 struct nvldbentry *vllist;
5006 afs_int32 nentries;
5007 int j;
5008 afs_uint32 volid;
5009 afs_int32 totalE;
5010 char pname[10];
5012 apart = -1;
5013 totalE = 0;
5014 memset(&attributes, 0, sizeof(attributes));
5016 if (as->parms[0].items) { /* server specified */
5017 aserver = GetServer(as->parms[0].items->data);
5018 if (aserver == 0) {
5019 fprintf(STDERR, "vos: server '%s' not found in host table\n",
5020 as->parms[0].items->data);
5021 exit(1);
5023 attributes.server = ntohl(aserver);
5024 attributes.Mask |= VLLIST_SERVER;
5026 if (as->parms[1].items) { /* partition specified */
5027 apart = volutil_GetPartitionID(as->parms[1].items->data);
5028 if (apart < 0) {
5029 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
5030 as->parms[1].items->data);
5031 exit(1);
5033 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
5034 if (code)
5035 PrintError("", code);
5036 else
5037 fprintf(STDERR,
5038 "vos : partition %s does not exist on the server\n",
5039 as->parms[1].items->data);
5040 exit(1);
5042 attributes.partition = apart;
5043 attributes.Mask |= VLLIST_PARTITION;
5045 attributes.flag = VLOP_ALLOPERS;
5046 attributes.Mask |= VLLIST_FLAG;
5047 memset(&arrayEntries, 0, sizeof(arrayEntries)); /*initialize to hint the stub to alloc space */
5048 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
5049 if (vcode) {
5050 fprintf(STDERR, "Could not access the VLDB for attributes\n");
5051 PrintError("", vcode);
5052 exit(1);
5054 for (j = 0; j < nentries; j++) { /* process each entry */
5055 vllist = &arrayEntries.nbulkentries_val[j];
5056 volid = vllist->volumeId[RWVOL];
5057 vcode =
5058 ubik_VL_ReleaseLock(cstruct, 0, volid, -1,
5059 LOCKREL_OPCODE | LOCKREL_AFSID |
5060 LOCKREL_TIMESTAMP);
5061 if (vcode) {
5062 fprintf(STDERR, "Could not unlock entry for volume %s\n",
5063 vllist->name);
5064 PrintError("", vcode);
5065 totalE++;
5069 MapPartIdIntoName(apart, pname);
5070 if (totalE)
5071 fprintf(STDOUT,
5072 "Could not lock %lu VLDB entries of %lu locked entries\n",
5073 (unsigned long)totalE, (unsigned long)nentries);
5074 else {
5075 if (as->parms[0].items) {
5076 fprintf(STDOUT,
5077 "Unlocked all the VLDB entries for volumes on server %s ",
5078 as->parms[0].items->data);
5079 if (as->parms[1].items) {
5080 MapPartIdIntoName(apart, pname);
5081 fprintf(STDOUT, "partition %s\n", pname);
5082 } else
5083 fprintf(STDOUT, "\n");
5085 } else if (as->parms[1].items) {
5086 MapPartIdIntoName(apart, pname);
5087 fprintf(STDOUT,
5088 "Unlocked all the VLDB entries for volumes on partition %s on all servers\n",
5089 pname);
5093 xdr_free((xdrproc_t) xdr_nbulkentries, &arrayEntries);
5094 return 0;
5097 static char *
5098 PrintInt64Size(afs_uint64 in)
5100 afs_uint32 hi, lo;
5101 char * units;
5102 static char output[16];
5104 SplitInt64(in,hi,lo);
5106 if (hi == 0) {
5107 units = "KB";
5108 } else if (!(hi & 0xFFFFFC00)) {
5109 units = "MB";
5110 lo = (hi << 22) | (lo >> 10);
5111 } else if (!(hi & 0xFFF00000)) {
5112 units = "GB";
5113 lo = (hi << 12) | (lo >> 20);
5114 } else if (!(hi & 0xC0000000)) {
5115 units = "TB";
5116 lo = (hi << 2) | (lo >> 30);
5117 } else {
5118 units = "PB";
5119 lo = (hi >> 8);
5121 sprintf(output,"%u %s", lo, units);
5122 return output;
5125 static int
5126 PartitionInfo(struct cmd_syndesc *as, void *arock)
5128 afs_int32 apart;
5129 afs_uint32 aserver;
5130 afs_int32 code;
5131 char pname[10];
5132 struct diskPartition64 partition;
5133 struct partList dummyPartList;
5134 int i, cnt;
5135 int printSummary=0, sumPartitions=0;
5136 afs_uint64 sumFree, sumStorage;
5138 ZeroInt64(sumFree);
5139 ZeroInt64(sumStorage);
5140 apart = -1;
5141 aserver = GetServer(as->parms[0].items->data);
5142 if (aserver == 0) {
5143 fprintf(STDERR, "vos: server '%s' not found in host table\n",
5144 as->parms[0].items->data);
5145 exit(1);
5147 if (as->parms[1].items) {
5148 apart = volutil_GetPartitionID(as->parms[1].items->data);
5149 if (apart < 0) {
5150 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
5151 as->parms[1].items->data);
5152 exit(1);
5154 dummyPartList.partId[0] = apart;
5155 dummyPartList.partFlags[0] = PARTVALID;
5156 cnt = 1;
5158 if (as->parms[2].items) {
5159 printSummary = 1;
5161 if (apart != -1) {
5162 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
5163 if (code)
5164 PrintError("", code);
5165 else
5166 fprintf(STDERR,
5167 "vos : partition %s does not exist on the server\n",
5168 as->parms[1].items->data);
5169 exit(1);
5171 } else {
5172 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
5173 if (code) {
5174 PrintDiagnostics("listpart", code);
5175 exit(1);
5178 for (i = 0; i < cnt; i++) {
5179 if (dummyPartList.partFlags[i] & PARTVALID) {
5180 MapPartIdIntoName(dummyPartList.partId[i], pname);
5181 code = UV_PartitionInfo64(aserver, pname, &partition);
5182 if (code) {
5183 fprintf(STDERR, "Could not get information on partition %s\n",
5184 pname);
5185 PrintError("", code);
5186 exit(1);
5188 fprintf(STDOUT,
5189 "Free space on partition %s: %" AFS_INT64_FMT " K blocks out of total %" AFS_INT64_FMT "\n",
5190 pname, partition.free, partition.minFree);
5191 sumPartitions++;
5192 AddUInt64(sumFree,partition.free,&sumFree);
5193 AddUInt64(sumStorage,partition.minFree,&sumStorage);
5196 if (printSummary) {
5197 fprintf(STDOUT,
5198 "Summary: %s free out of ",
5199 PrintInt64Size(sumFree));
5200 fprintf(STDOUT,
5201 "%s on %d partitions\n",
5202 PrintInt64Size(sumStorage),
5203 sumPartitions);
5205 return 0;
5208 static int
5209 ChangeAddr(struct cmd_syndesc *as, void *arock)
5211 afs_int32 ip1, ip2, vcode;
5212 int remove = 0;
5213 int force = 0;
5215 if (noresolve)
5216 ip1 = GetServerNoresolve(as->parms[0].items->data);
5217 else
5218 ip1 = GetServer(as->parms[0].items->data);
5219 if (!ip1) {
5220 fprintf(STDERR, "vos: invalid host address\n");
5221 return (EINVAL);
5224 if ((as->parms[1].items && as->parms[2].items)
5225 || (!as->parms[1].items && !as->parms[2].items)) {
5226 fprintf(STDERR,
5227 "vos: Must specify either '-newaddr <addr>' or '-remove' flag\n");
5228 return (EINVAL);
5231 if (as->parms[3].items) {
5232 force = 1;
5235 if (as->parms[1].items) {
5236 if (noresolve)
5237 ip2 = GetServerNoresolve(as->parms[1].items->data);
5238 else
5239 ip2 = GetServer(as->parms[1].items->data);
5240 if (!ip2) {
5241 fprintf(STDERR, "vos: invalid host address\n");
5242 return (EINVAL);
5244 } else {
5245 /* Play a trick here. If we are removing an address, ip1 will be -1
5246 * and ip2 will be the original address. This switch prevents an
5247 * older revision vlserver from removing the IP address.
5249 remove = 1;
5250 ip2 = ip1;
5251 ip1 = 0xffffffff;
5254 if (!remove && !force) {
5255 afs_int32 m_nentries;
5256 bulkaddrs m_addrs;
5257 afs_int32 m_uniq = 0;
5258 afsUUID m_uuid;
5259 ListAddrByAttributes m_attrs;
5260 char buffer[128];
5262 memset(&m_attrs, 0, sizeof(m_attrs));
5263 memset(&m_uuid, 0, sizeof(m_uuid));
5264 memset(&m_addrs, 0, sizeof(m_addrs));
5265 memset(buffer, 0, sizeof(buffer));
5267 m_attrs.Mask = VLADDR_IPADDR;
5268 m_attrs.ipaddr = ntohl(ip1); /* -oldaddr */
5270 vcode =
5271 ubik_VL_GetAddrsU(cstruct, UBIK_CALL_NEW, &m_attrs, &m_uuid,
5272 &m_uniq, &m_nentries, &m_addrs);
5273 xdr_free((xdrproc_t) xdr_bulkaddrs, &m_addrs);
5274 switch (vcode) {
5275 case 0: /* mh entry detected */
5276 afsUUID_to_string(&m_uuid, buffer, sizeof(buffer) - 1);
5277 fprintf(STDERR, "vos: Refusing to change address in multi-homed server entry.\n");
5278 fprintf(STDERR, " -oldaddr address is registered to file server UUID %s\n", buffer);
5279 fprintf(STDERR, " Please restart the file server or use vos setaddrs.\n");
5280 return EINVAL;
5281 case VL_NOENT:
5282 break;
5283 default:
5284 fprintf(STDERR, "vos: could not list the server addresses\n");
5285 PrintError("", vcode);
5286 return vcode;
5290 vcode = ubik_VL_ChangeAddr(cstruct, UBIK_CALL_NEW, ntohl(ip1), ntohl(ip2));
5291 if (vcode) {
5292 char hoststr1[16], hoststr2[16];
5293 if (remove) {
5294 afs_inet_ntoa_r(ip2, hoststr2);
5295 fprintf(STDERR, "Could not remove server %s from the VLDB\n",
5296 hoststr2);
5297 if (vcode == VL_NOENT) {
5298 fprintf(STDERR,
5299 "vlserver does not support the remove flag or ");
5301 } else {
5302 afs_inet_ntoa_r(ip1, hoststr1);
5303 afs_inet_ntoa_r(ip2, hoststr2);
5304 fprintf(STDERR, "Could not change server %s to server %s\n",
5305 hoststr1, hoststr2);
5307 PrintError("", vcode);
5308 return (vcode);
5311 if (remove) {
5312 fprintf(STDOUT, "Removed server %s from the VLDB\n",
5313 as->parms[0].items->data);
5314 } else {
5315 fprintf(STDOUT, "Changed server %s to server %s\n",
5316 as->parms[0].items->data, as->parms[1].items->data);
5318 return 0;
5321 static void
5322 print_addrs(const bulkaddrs * addrs, afsUUID * m_uuid, int nentries,
5323 int print)
5325 int i;
5326 afs_uint32 addr;
5327 char buf[1024];
5329 if (print) {
5330 afsUUID_to_string(m_uuid, buf, sizeof(buf));
5331 printf("UUID: %s\n", buf);
5334 /* print out the list of all the server */
5335 for (i = 0; i < addrs->bulkaddrs_len; i++) {
5336 addr = htonl(addrs->bulkaddrs_val[i]);
5337 if (noresolve) {
5338 char hoststr[16];
5339 printf("%s\n", afs_inet_ntoa_r(addr, hoststr));
5340 } else {
5341 printf("%s\n", hostutil_GetNameByINet(addr));
5345 if (print) {
5346 printf("\n");
5348 return;
5351 static int
5352 ListAddrs(struct cmd_syndesc *as, void *arock)
5354 afs_int32 vcode, m_uniq=0;
5355 afs_int32 i, printuuid = 0;
5356 struct VLCallBack vlcb;
5357 afs_int32 nentries;
5358 bulkaddrs m_addrs;
5359 ListAddrByAttributes m_attrs;
5360 afsUUID m_uuid, askuuid;
5361 afs_int32 m_nentries;
5363 memset(&m_attrs, 0, sizeof(struct ListAddrByAttributes));
5364 m_attrs.Mask = VLADDR_INDEX;
5366 memset(&askuuid, 0, sizeof(afsUUID));
5367 if (as->parms[0].items) {
5368 /* -uuid */
5369 if (afsUUID_from_string(as->parms[0].items->data, &askuuid) < 0) {
5370 fprintf(STDERR, "vos: invalid UUID '%s'\n",
5371 as->parms[0].items->data);
5372 exit(-1);
5374 m_attrs.Mask = VLADDR_UUID;
5375 m_attrs.uuid = askuuid;
5377 if (as->parms[1].items) {
5378 /* -host */
5379 struct hostent *he;
5380 afs_uint32 saddr;
5381 he = hostutil_GetHostByName((char *)as->parms[1].items->data);
5382 if (he == NULL) {
5383 fprintf(STDERR, "vos: Can't get host info for '%s'\n",
5384 as->parms[1].items->data);
5385 exit(-1);
5387 memcpy(&saddr, he->h_addr, 4);
5388 m_attrs.Mask = VLADDR_IPADDR;
5389 m_attrs.ipaddr = ntohl(saddr);
5391 if (as->parms[2].items) {
5392 printuuid = 1;
5395 memset(&m_addrs, 0, sizeof(bulkaddrs));
5396 memset(&vlcb, 0, sizeof(struct VLCallBack));
5398 vcode =
5399 ubik_VL_GetAddrs(cstruct, UBIK_CALL_NEW, 0, 0, &vlcb, &nentries,
5400 &m_addrs);
5401 if (vcode) {
5402 fprintf(STDERR, "vos: could not list the server addresses\n");
5403 PrintError("", vcode);
5404 goto out;
5407 m_nentries = 0;
5408 i = 1;
5409 while (1) {
5410 m_attrs.index = i;
5412 xdr_free((xdrproc_t)xdr_bulkaddrs, &m_addrs); /* reset addr list */
5413 vcode =
5414 ubik_VL_GetAddrsU(cstruct, UBIK_CALL_NEW, &m_attrs, &m_uuid,
5415 &m_uniq, &m_nentries, &m_addrs);
5417 if (vcode == VL_NOENT) {
5418 if (m_attrs.Mask == VLADDR_UUID) {
5419 fprintf(STDERR, "vos: no entry for UUID '%s' found in VLDB\n",
5420 as->parms[0].items->data);
5421 exit(-1);
5422 } else if (m_attrs.Mask == VLADDR_IPADDR) {
5423 fprintf(STDERR, "vos: no entry for host '%s' [0x%08x] found in VLDB\n",
5424 as->parms[1].items->data, m_attrs.ipaddr);
5425 exit(-1);
5426 } else {
5427 i++;
5428 nentries++;
5429 continue;
5433 if (vcode == VL_INDEXERANGE) {
5434 vcode = 0; /* not an error, just means we're done */
5435 goto out;
5438 if (vcode) {
5439 fprintf(STDERR, "vos: could not list the server addresses\n");
5440 PrintError("", vcode);
5441 goto out;
5444 print_addrs(&m_addrs, &m_uuid, m_nentries, printuuid);
5445 i++;
5447 if ((as->parms[1].items) || (as->parms[0].items) || (i > nentries))
5448 goto out;
5451 out:
5452 xdr_free((xdrproc_t)xdr_bulkaddrs, &m_addrs);
5453 return vcode;
5457 static int
5458 SetAddrs(struct cmd_syndesc *as, void *arock)
5460 afs_int32 vcode;
5461 bulkaddrs m_addrs;
5462 afsUUID askuuid;
5463 afs_uint32 FS_HostAddrs_HBO[ADDRSPERSITE];
5465 memset(&m_addrs, 0, sizeof(bulkaddrs));
5466 memset(&askuuid, 0, sizeof(afsUUID));
5467 if (as->parms[0].items) {
5468 /* -uuid */
5469 if (afsUUID_from_string(as->parms[0].items->data, &askuuid) < 0) {
5470 fprintf(STDERR, "vos: invalid UUID '%s'\n",
5471 as->parms[0].items->data);
5472 exit(-1);
5475 if (as->parms[1].items) {
5476 /* -host */
5477 struct cmd_item *ti;
5478 afs_uint32 saddr;
5479 int i = 0;
5481 for (ti = as->parms[1].items; ti && i < ADDRSPERSITE; ti = ti->next) {
5483 if (noresolve)
5484 saddr = GetServerNoresolve(ti->data);
5485 else
5486 saddr = GetServer(ti->data);
5488 if (!saddr) {
5489 fprintf(STDERR, "vos: Can't get host info for '%s'\n",
5490 ti->data);
5491 exit(-1);
5493 /* Convert it to host byte order */
5494 FS_HostAddrs_HBO[i] = ntohl(saddr);
5495 i++;
5497 m_addrs.bulkaddrs_len = i;
5498 m_addrs.bulkaddrs_val = FS_HostAddrs_HBO;
5501 vcode = ubik_VL_RegisterAddrs(cstruct, 0, &askuuid, 0, &m_addrs);
5503 if (vcode) {
5504 if (vcode == VL_MULTIPADDR) {
5505 fprintf(STDERR, "vos: VL_RegisterAddrs rpc failed; The IP address exists on a different server; repair it\n");
5506 } else if (vcode == RXGEN_OPCODE) {
5507 fprintf(STDERR, "vlserver doesn't support VL_RegisterAddrs rpc; ignored\n");
5508 } else {
5509 fprintf(STDERR, "vos: VL_RegisterAddrs rpc failed\n");
5511 PrintError("", vcode);
5512 return vcode;
5514 if (verbose) {
5515 fprintf(STDOUT, "vos: Changed UUID with addresses:\n");
5516 print_addrs(&m_addrs, &askuuid, m_addrs.bulkaddrs_len, 1);
5518 return 0;
5521 static int
5522 RemoveAddrs(struct cmd_syndesc *as, void *arock)
5524 afs_int32 code;
5525 ListAddrByAttributes attrs;
5526 afsUUID uuid;
5527 afs_int32 uniq = 0;
5528 afs_int32 nentries = 0;
5529 bulkaddrs addrs;
5530 afs_uint32 ip1;
5531 afs_uint32 ip2;
5533 memset(&attrs, 0, sizeof(ListAddrByAttributes));
5534 memset(&addrs, 0, sizeof(bulkaddrs));
5535 memset(&uuid, 0, sizeof(afsUUID));
5536 attrs.Mask = VLADDR_UUID;
5538 if (as->parms[0].items) { /* -uuid */
5539 if (afsUUID_from_string(as->parms[0].items->data, &attrs.uuid) < 0) {
5540 fprintf(STDERR, "vos: invalid UUID '%s'\n",
5541 as->parms[0].items->data);
5542 return EINVAL;
5546 code =
5547 ubik_VL_GetAddrsU(cstruct, UBIK_CALL_NEW, &attrs, &uuid, &uniq,
5548 &nentries, &addrs);
5549 if (code == VL_NOENT) {
5550 fprintf(STDERR, "vos: UUID not found\n");
5551 goto out;
5553 if (code != 0) {
5554 fprintf(STDERR, "vos: could not list the server addresses\n");
5555 PrintError("", code);
5556 goto out;
5558 if (addrs.bulkaddrs_len == 0) {
5559 fprintf(STDERR, "vos: no addresses found for UUID\n");
5560 goto out;
5563 ip2 = addrs.bulkaddrs_val[0]; /* network byte order */
5564 ip1 = 0xffffffff; /* indicates removal mode */
5566 if (verbose) {
5567 printf("vos: Removing UUID with hosts:\n");
5568 print_addrs(&addrs, &uuid, nentries, 1);
5571 code = ubik_VL_ChangeAddr(cstruct, UBIK_CALL_NEW, ip1, ip2);
5572 if (code) {
5573 fprintf(STDERR, "Could not remove server entry from the VLDB.\n");
5574 PrintError("", code);
5577 out:
5578 xdr_free((xdrproc_t) xdr_bulkaddrs, &addrs);
5579 return code;
5583 static int
5584 LockEntry(struct cmd_syndesc *as, void *arock)
5586 afs_uint32 avolid;
5587 afs_int32 vcode, err;
5589 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
5590 if (avolid == 0) {
5591 if (err)
5592 PrintError("", err);
5593 else
5594 fprintf(STDERR, "vos: can't find volume '%s'\n",
5595 as->parms[0].items->data);
5596 exit(1);
5598 vcode = ubik_VL_SetLock(cstruct, 0, avolid, -1, VLOP_DELETE);
5599 if (vcode) {
5600 fprintf(STDERR, "Could not lock VLDB entry for volume %s\n",
5601 as->parms[0].items->data);
5602 PrintError("", vcode);
5603 exit(1);
5605 fprintf(STDOUT, "Locked VLDB entry for volume %s\n",
5606 as->parms[0].items->data);
5607 return 0;
5610 static int
5611 ConvertRO(struct cmd_syndesc *as, void *arock)
5613 afs_int32 partition = -1;
5614 afs_uint32 volid;
5615 afs_uint32 server;
5616 afs_int32 code, i, same;
5617 struct nvldbentry entry, checkEntry, storeEntry;
5618 afs_int32 vcode;
5619 afs_int32 rwindex = 0;
5620 afs_uint32 rwserver = 0;
5621 afs_int32 rwpartition = 0;
5622 afs_int32 roindex = 0;
5623 afs_uint32 roserver = 0;
5624 afs_int32 ropartition = 0;
5625 int force = 0;
5626 struct rx_connection *aconn;
5627 int c, dc;
5629 memset(&storeEntry, 0, sizeof(struct nvldbentry));
5631 server = GetServer(as->parms[0].items->data);
5632 if (!server) {
5633 fprintf(STDERR, "vos: host '%s' not found in host table\n",
5634 as->parms[0].items->data);
5635 return ENOENT;
5637 partition = volutil_GetPartitionID(as->parms[1].items->data);
5638 if (partition < 0) {
5639 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
5640 as->parms[1].items->data);
5641 return ENOENT;
5643 if (!IsPartValid(partition, server, &code)) {
5644 if (code)
5645 PrintError("", code);
5646 else
5647 fprintf(STDERR,
5648 "vos : partition %s does not exist on the server\n",
5649 as->parms[1].items->data);
5650 return ENOENT;
5652 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &code);
5653 if (volid == 0) {
5654 if (code)
5655 PrintError("", code);
5656 else
5657 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
5658 as->parms[2].items->data);
5659 return -1;
5661 if (as->parms[3].items)
5662 force = 1;
5664 memset(&entry, 0, sizeof(entry));
5665 vcode = VLDB_GetEntryByID(volid, -1, &entry);
5666 if (vcode) {
5667 fprintf(STDERR,
5668 "Could not fetch the entry for volume %lu from VLDB\n",
5669 (unsigned long)volid);
5670 PrintError("convertROtoRW ", vcode);
5671 return vcode;
5674 /* use RO volid even if user specified RW or BK volid */
5675 if (volid != entry.volumeId[ROVOL])
5676 volid = entry.volumeId[ROVOL];
5678 MapHostToNetwork(&entry);
5679 for (i = 0; i < entry.nServers; i++) {
5680 if (entry.serverFlags[i] & ITSRWVOL) {
5681 rwindex = i;
5682 rwserver = entry.serverNumber[i];
5683 rwpartition = entry.serverPartition[i];
5684 if (roserver)
5685 break;
5686 } else if ((entry.serverFlags[i] & ITSROVOL) && !roserver) {
5687 same = VLDB_IsSameAddrs(server, entry.serverNumber[i], &code);
5688 if (code) {
5689 fprintf(STDERR,
5690 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
5691 server, code);
5692 return ENOENT;
5694 if (same) {
5695 roindex = i;
5696 roserver = entry.serverNumber[i];
5697 ropartition = entry.serverPartition[i];
5698 if (rwserver)
5699 break;
5703 if (!roserver) {
5704 fprintf(STDERR, "Warning: RO volume didn't exist in vldb!\n");
5706 if (roserver && (ropartition != partition)) {
5707 fprintf(STDERR,
5708 "Warning: RO volume should be in partition %d instead of %d (vldb)\n",
5709 ropartition, partition);
5712 if (rwserver) {
5713 fprintf(STDERR,
5714 "VLDB indicates that a RW volume exists already on %s in partition %s.\n",
5715 hostutil_GetNameByINet(rwserver),
5716 volutil_PartitionName(rwpartition));
5717 if (!force) {
5718 fprintf(STDERR, "Overwrite this VLDB entry? [y|n] (n)\n");
5719 dc = c = getchar();
5720 while (!(dc == EOF || dc == '\n'))
5721 dc = getchar(); /* goto end of line */
5722 if ((c != 'y') && (c != 'Y')) {
5723 fprintf(STDERR, "aborted.\n");
5724 return -1;
5729 vcode =
5730 ubik_VL_SetLock(cstruct, 0, entry.volumeId[RWVOL], RWVOL,
5731 VLOP_MOVE);
5732 if (vcode) {
5733 fprintf(STDERR,
5734 "Unable to lock volume %lu, code %d\n",
5735 (unsigned long)entry.volumeId[RWVOL],vcode);
5736 PrintError("", vcode);
5737 return -1;
5740 /* make sure the VLDB entry hasn't changed since we started */
5741 memset(&checkEntry, 0, sizeof(checkEntry));
5742 vcode = VLDB_GetEntryByID(volid, -1, &checkEntry);
5743 if (vcode) {
5744 fprintf(STDERR,
5745 "Could not fetch the entry for volume %lu from VLDB\n",
5746 (unsigned long)volid);
5747 PrintError("convertROtoRW ", vcode);
5748 code = vcode;
5749 goto error_exit;
5752 MapHostToNetwork(&checkEntry);
5753 entry.flags &= ~VLOP_ALLOPERS; /* clear any stale lock operation flags */
5754 entry.flags |= VLOP_MOVE; /* set to match SetLock operation above */
5755 if (memcmp(&entry, &checkEntry, sizeof(entry)) != 0) {
5756 fprintf(STDERR,
5757 "VLDB entry for volume %lu has changed; please reissue the command.\n",
5758 (unsigned long)volid);
5759 code = -1;
5760 goto error_exit;
5763 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
5764 code = AFSVolConvertROtoRWvolume(aconn, partition, volid);
5765 if (code) {
5766 fprintf(STDERR,
5767 "Converting RO volume %lu to RW volume failed with code %d\n",
5768 (unsigned long)volid, code);
5769 PrintError("convertROtoRW ", code);
5770 goto error_exit;
5772 /* Update the VLDB to match what we did on disk as much as possible. */
5773 /* If the converted RO was in the VLDB, make it look like the new RW. */
5774 if (roserver) {
5775 entry.serverFlags[roindex] = ITSRWVOL;
5776 } else {
5777 /* Add a new site entry for the newly created RW. It's possible
5778 * (but unlikely) that we are already at MAXNSERVERS and that this
5779 * new site will invalidate the whole VLDB entry; however,
5780 * VLDB_ReplaceEntry will detect this and return VL_BADSERVER,
5781 * so we need no extra guard logic here.
5783 afs_int32 newrwindex = entry.nServers;
5784 (entry.nServers)++;
5785 entry.serverNumber[newrwindex] = server;
5786 entry.serverPartition[newrwindex] = partition;
5787 entry.serverFlags[newrwindex] = ITSRWVOL;
5789 entry.flags |= RW_EXISTS;
5790 entry.flags &= ~BACK_EXISTS;
5792 /* if the old RW was in the VLDB, remove it by decrementing the number */
5793 /* of servers, replacing the RW entry with the last entry, and zeroing */
5794 /* out the last entry. */
5795 if (rwserver) {
5796 (entry.nServers)--;
5797 if (rwindex != entry.nServers) {
5798 entry.serverNumber[rwindex] = entry.serverNumber[entry.nServers];
5799 entry.serverPartition[rwindex] =
5800 entry.serverPartition[entry.nServers];
5801 entry.serverFlags[rwindex] = entry.serverFlags[entry.nServers];
5802 entry.serverNumber[entry.nServers] = 0;
5803 entry.serverPartition[entry.nServers] = 0;
5804 entry.serverFlags[entry.nServers] = 0;
5807 entry.flags &= ~RO_EXISTS;
5808 for (i = 0; i < entry.nServers; i++) {
5809 if (entry.serverFlags[i] & ITSROVOL) {
5810 if (!(entry.serverFlags[i] & (RO_DONTUSE | NEW_REPSITE)))
5811 entry.flags |= RO_EXISTS;
5814 MapNetworkToHost(&entry, &storeEntry);
5815 code =
5816 VLDB_ReplaceEntry(entry.volumeId[RWVOL], RWVOL, &storeEntry,
5817 (LOCKREL_OPCODE | LOCKREL_AFSID |
5818 LOCKREL_TIMESTAMP));
5819 if (code) {
5820 fprintf(STDERR,
5821 "Warning: volume converted, but vldb update failed with code %d!\n",
5822 code);
5825 error_exit:
5826 vcode = UV_LockRelease(entry.volumeId[RWVOL]);
5827 if (vcode) {
5828 fprintf(STDERR,
5829 "Unable to unlock volume %lu, code %d\n",
5830 (unsigned long)entry.volumeId[RWVOL],vcode);
5831 PrintError("", vcode);
5833 return code;
5836 static int
5837 Sizes(struct cmd_syndesc *as, void *arock)
5839 afs_uint32 avolid;
5840 afs_uint32 aserver;
5841 afs_int32 apart, voltype, fromdate = 0, code, err, i;
5842 struct nvldbentry entry;
5843 volintSize vol_size;
5845 rx_SetRxDeadTime(60 * 10);
5846 for (i = 0; i < MAXSERVERS; i++) {
5847 struct rx_connection *rxConn = ubik_GetRPCConn(cstruct, i);
5848 if (rxConn == 0)
5849 break;
5850 rx_SetConnDeadTime(rxConn, rx_connDeadTime);
5851 if (rxConn->service)
5852 rxConn->service->connDeadTime = rx_connDeadTime;
5855 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
5856 if (avolid == 0) {
5857 if (err)
5858 PrintError("", err);
5859 else
5860 fprintf(STDERR, "vos: can't find volume '%s'\n",
5861 as->parms[0].items->data);
5862 return ENOENT;
5865 if (as->parms[1].items || as->parms[2].items) {
5866 if (!as->parms[1].items || !as->parms[2].items) {
5867 fprintf(STDERR,
5868 "Must specify both -server and -partition options\n");
5869 return -1;
5871 aserver = GetServer(as->parms[2].items->data);
5872 if (aserver == 0) {
5873 fprintf(STDERR, "Invalid server name\n");
5874 return -1;
5876 apart = volutil_GetPartitionID(as->parms[1].items->data);
5877 if (apart < 0) {
5878 fprintf(STDERR, "Invalid partition name\n");
5879 return -1;
5881 } else {
5882 code = GetVolumeInfo(avolid, &aserver, &apart, &voltype, &entry);
5883 if (code)
5884 return code;
5887 fromdate = 0;
5889 if (as->parms[4].items && strcmp(as->parms[4].items->data, "0")) {
5890 code = ktime_DateToInt32(as->parms[4].items->data, &fromdate);
5891 if (code) {
5892 fprintf(STDERR, "vos: failed to parse date '%s' (error=%d))\n",
5893 as->parms[4].items->data, code);
5894 return code;
5898 fprintf(STDOUT, "Volume: %s\n", as->parms[0].items->data);
5900 if (as->parms[3].items) { /* do the dump estimate */
5901 #ifdef AFS_64BIT_ENV
5902 vol_size.dump_size = 0;
5903 #else
5904 FillInt64(vol_size.dump_size,0, 1);
5905 #endif
5906 code = UV_GetSize(avolid, aserver, apart, fromdate, &vol_size);
5907 if (code) {
5908 PrintDiagnostics("size", code);
5909 return code;
5911 /* presumably the size info is now gathered in pntr */
5912 /* now we display it */
5914 fprintf(STDOUT, "dump_size: %llu\n", vol_size.dump_size);
5917 /* Display info */
5919 return 0;
5922 static int
5923 EndTrans(struct cmd_syndesc *as, void *arock)
5925 afs_uint32 server;
5926 afs_int32 code, tid, rcode;
5927 struct rx_connection *aconn;
5929 server = GetServer(as->parms[0].items->data);
5930 if (!server) {
5931 fprintf(STDERR, "vos: host '%s' not found in host table\n",
5932 as->parms[0].items->data);
5933 return EINVAL;
5936 code = util_GetInt32(as->parms[1].items->data, &tid);
5937 if (code) {
5938 fprintf(STDERR, "vos: bad integer specified for transaction ID.\n");
5939 return code;
5942 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
5943 code = AFSVolEndTrans(aconn, tid, &rcode);
5944 if (!code) {
5945 code = rcode;
5948 if (code) {
5949 PrintDiagnostics("endtrans", code);
5950 return 1;
5953 return 0;
5957 PrintDiagnostics(char *astring, afs_int32 acode)
5959 switch (acode) {
5960 case EACCES:
5961 fprintf(STDERR,
5962 "You are not authorized to perform the 'vos %s' command (%d)\n",
5963 astring, acode);
5964 break;
5965 case EXDEV:
5966 fprintf(STDERR, "Error in vos %s command.\n", astring);
5967 fprintf(STDERR, "Clone volume is not in the same partition as the read-write volume.\n");
5968 break;
5969 default:
5970 fprintf(STDERR, "Error in vos %s command.\n", astring);
5971 PrintError("", acode);
5972 break;
5974 return 0;
5978 #ifdef AFS_NT40_ENV
5979 static DWORD
5980 win32_enableCrypt(void)
5982 HKEY parmKey;
5983 DWORD dummyLen;
5984 DWORD cryptall = 0;
5985 DWORD code;
5987 /* Look up configuration parameters in Registry */
5988 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
5989 0, (IsWow64()?KEY_WOW64_64KEY:0)|KEY_QUERY_VALUE, &parmKey);
5990 if (code != ERROR_SUCCESS) {
5991 dummyLen = sizeof(cryptall);
5992 RegQueryValueEx(parmKey, "SecurityLevel", NULL, NULL,
5993 (BYTE *) &cryptall, &dummyLen);
5995 RegCloseKey (parmKey);
5997 return cryptall;
5999 #endif /* AFS_NT40_ENV */
6001 static int
6002 MyBeforeProc(struct cmd_syndesc *as, void *arock)
6004 char *tcell;
6005 afs_int32 code;
6006 afs_int32 sauth;
6008 /* Initialize the ubik_client connection */
6009 rx_SetRxDeadTime(90);
6010 cstruct = (struct ubik_client *)0;
6012 sauth = 0;
6013 tcell = NULL;
6014 if (as->parms[12].items) /* if -cell specified */
6015 tcell = as->parms[12].items->data;
6016 if (as->parms[14].items) /* -serverauth specified */
6017 sauth = 1;
6018 if (as->parms[16].items /* -encrypt specified */
6019 #ifdef AFS_NT40_ENV
6020 || win32_enableCrypt()
6021 #endif /* AFS_NT40_ENV */
6023 vsu_SetCrypt(1);
6024 if ((code =
6025 vsu_ClientInit((as->parms[13].items != 0), confdir, tcell, sauth,
6026 &cstruct, UV_SetSecurity))) {
6027 fprintf(STDERR, "could not initialize VLDB library (code=%lu) \n",
6028 (unsigned long)code);
6029 exit(1);
6031 rxInitDone = 1;
6032 if (as->parms[15].items) /* -verbose flag set */
6033 verbose = 1;
6034 else
6035 verbose = 0;
6036 if (as->parms[17].items) /* -noresolve flag set */
6037 noresolve = 1;
6038 else
6039 noresolve = 0;
6040 return 0;
6044 osi_audit(void)
6046 /* this sucks but it works for now.
6048 return 0;
6051 #include "AFS_component_version_number.c"
6054 main(int argc, char **argv)
6056 afs_int32 code;
6058 struct cmd_syndesc *ts;
6060 #ifdef AFS_AIX32_ENV
6062 * The following signal action for AIX is necessary so that in case of a
6063 * crash (i.e. core is generated) we can include the user's data section
6064 * in the core dump. Unfortunately, by default, only a partial core is
6065 * generated which, in many cases, isn't too useful.
6067 struct sigaction nsa;
6069 sigemptyset(&nsa.sa_mask);
6070 nsa.sa_handler = SIG_DFL;
6071 nsa.sa_flags = SA_FULLDUMP;
6072 sigaction(SIGSEGV, &nsa, NULL);
6073 #endif
6075 confdir = AFSDIR_CLIENT_ETC_DIRPATH;
6077 cmd_SetBeforeProc(MyBeforeProc, NULL);
6079 ts = cmd_CreateSyntax("create", CreateVolume, NULL, "create a new volume");
6080 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6081 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6082 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "volume name");
6083 cmd_AddParm(ts, "-maxquota", CMD_SINGLE, CMD_OPTIONAL,
6084 "initial quota (KB)");
6085 cmd_AddParm(ts, "-id", CMD_SINGLE, CMD_OPTIONAL, "volume ID");
6086 cmd_AddParm(ts, "-roid", CMD_SINGLE, CMD_OPTIONAL, "readonly volume ID");
6087 #ifdef notdef
6088 cmd_AddParm(ts, "-minquota", CMD_SINGLE, CMD_OPTIONAL, "");
6089 #endif
6090 COMMONPARMS;
6092 ts = cmd_CreateSyntax("remove", DeleteVolume, NULL, "delete a volume");
6093 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6094 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6095 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6097 COMMONPARMS;
6099 ts = cmd_CreateSyntax("move", MoveVolume, NULL, "move a volume");
6100 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6101 cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source");
6102 cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0,
6103 "partition name on source");
6104 cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0,
6105 "machine name on destination");
6106 cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0,
6107 "partition name on destination");
6108 cmd_AddParm(ts, "-live", CMD_FLAG, CMD_OPTIONAL,
6109 "copy live volume without cloning");
6110 COMMONPARMS;
6112 ts = cmd_CreateSyntax("copy", CopyVolume, NULL, "copy a volume");
6113 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID on source");
6114 cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source");
6115 cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0,
6116 "partition name on source");
6117 cmd_AddParm(ts, "-toname", CMD_SINGLE, 0, "volume name on destination");
6118 cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0,
6119 "machine name on destination");
6120 cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0,
6121 "partition name on destination");
6122 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
6123 "leave new volume offline");
6124 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
6125 "make new volume read-only");
6126 cmd_AddParm(ts, "-live", CMD_FLAG, CMD_OPTIONAL,
6127 "copy live volume without cloning");
6128 COMMONPARMS;
6130 ts = cmd_CreateSyntax("shadow", ShadowVolume, NULL,
6131 "make or update a shadow volume");
6132 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID on source");
6133 cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source");
6134 cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0,
6135 "partition name on source");
6136 cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0,
6137 "machine name on destination");
6138 cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0,
6139 "partition name on destination");
6140 cmd_AddParm(ts, "-toname", CMD_SINGLE, CMD_OPTIONAL,
6141 "volume name on destination");
6142 cmd_AddParm(ts, "-toid", CMD_SINGLE, CMD_OPTIONAL,
6143 "volume ID on destination");
6144 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
6145 "leave shadow volume offline");
6146 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
6147 "make shadow volume read-only");
6148 cmd_AddParm(ts, "-live", CMD_FLAG, CMD_OPTIONAL,
6149 "copy live volume without cloning");
6150 cmd_AddParm(ts, "-incremental", CMD_FLAG, CMD_OPTIONAL,
6151 "do incremental update if target exists");
6152 COMMONPARMS;
6154 ts = cmd_CreateSyntax("backup", BackupVolume, NULL,
6155 "make backup of a volume");
6156 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6157 COMMONPARMS;
6159 ts = cmd_CreateSyntax("clone", CloneVolume, NULL,
6160 "make clone of a volume");
6161 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6162 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "server");
6163 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition");
6164 cmd_AddParm(ts, "-toname", CMD_SINGLE, CMD_OPTIONAL,
6165 "volume name on destination");
6166 cmd_AddParm(ts, "-toid", CMD_SINGLE, CMD_OPTIONAL,
6167 "volume ID on destination");
6168 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
6169 "leave clone volume offline");
6170 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
6171 "make clone volume read-only, not readwrite");
6172 cmd_AddParm(ts, "-readwrite", CMD_FLAG, CMD_OPTIONAL,
6173 "make clone volume readwrite, not read-only");
6174 COMMONPARMS;
6176 ts = cmd_CreateSyntax("release", ReleaseVolume, NULL, "release a volume");
6177 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6178 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL,
6179 "force a complete release");
6180 cmd_AddParm(ts, "-stayonline", CMD_FLAG, CMD_OPTIONAL,
6181 "release to cloned temp vol, then clone back to repsite RO");
6182 COMMONPARMS;
6184 ts = cmd_CreateSyntax("dump", DumpVolumeCmd, NULL, "dump a volume");
6185 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6186 cmd_AddParm(ts, "-time", CMD_SINGLE, CMD_OPTIONAL, "dump from time");
6187 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "dump file");
6188 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "server");
6189 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition");
6190 cmd_AddParm(ts, "-clone", CMD_FLAG, CMD_OPTIONAL,
6191 "dump a clone of the volume");
6192 cmd_AddParm(ts, "-omitdirs", CMD_FLAG, CMD_OPTIONAL,
6193 "omit unchanged directories from an incremental dump");
6194 COMMONPARMS;
6196 ts = cmd_CreateSyntax("restore", RestoreVolumeCmd, NULL,
6197 "restore a volume");
6198 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6199 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6200 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "name of volume to be restored");
6201 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "dump file");
6202 cmd_AddParm(ts, "-id", CMD_SINGLE, CMD_OPTIONAL, "volume ID");
6203 cmd_AddParm(ts, "-overwrite", CMD_SINGLE, CMD_OPTIONAL,
6204 "abort | full | incremental");
6205 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
6206 "leave restored volume offline");
6207 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
6208 "make restored volume read-only");
6209 cmd_AddParm(ts, "-creation", CMD_SINGLE, CMD_OPTIONAL,
6210 "dump | keep | new");
6211 cmd_AddParm(ts, "-lastupdate", CMD_SINGLE, CMD_OPTIONAL,
6212 "dump | keep | new");
6213 cmd_AddParm(ts, "-nodelete", CMD_FLAG, CMD_OPTIONAL,
6214 "do not delete old site when restoring to a new site");
6215 COMMONPARMS;
6217 ts = cmd_CreateSyntax("unlock", LockReleaseCmd, NULL,
6218 "release lock on VLDB entry for a volume");
6219 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6220 COMMONPARMS;
6222 ts = cmd_CreateSyntax("changeloc", ChangeLocation, NULL,
6223 "change an RW volume's location in the VLDB");
6224 cmd_AddParm(ts, "-server", CMD_SINGLE, 0,
6225 "machine name for new location");
6226 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0,
6227 "partition name for new location");
6228 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6229 COMMONPARMS;
6231 ts = cmd_CreateSyntax("addsite", AddSite, NULL, "add a replication site");
6232 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name for new site");
6233 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0,
6234 "partition name for new site");
6235 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6236 cmd_AddParm(ts, "-roid", CMD_SINGLE, CMD_OPTIONAL, "volume name or ID for RO");
6237 cmd_AddParm(ts, "-valid", CMD_FLAG, CMD_OPTIONAL, "publish as an up-to-date site in VLDB");
6238 COMMONPARMS;
6240 ts = cmd_CreateSyntax("remsite", RemoveSite, NULL,
6241 "remove a replication site");
6242 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6243 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6244 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6245 COMMONPARMS;
6247 ts = cmd_CreateSyntax("listpart", ListPartitions, NULL, "list partitions");
6248 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6249 COMMONPARMS;
6251 ts = cmd_CreateSyntax("listvol", ListVolumes, NULL,
6252 "list volumes on server (bypass VLDB)");
6253 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6254 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6255 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "minimal listing");
6256 cmd_AddParm(ts, "-long", CMD_FLAG, CMD_OPTIONAL,
6257 "list all normal volume fields");
6258 cmd_AddParm(ts, "-quiet", CMD_FLAG, CMD_OPTIONAL,
6259 "generate minimal information");
6260 cmd_AddParm(ts, "-extended", CMD_FLAG, CMD_OPTIONAL,
6261 "list extended volume fields");
6262 cmd_AddParm(ts, "-format", CMD_FLAG, CMD_OPTIONAL,
6263 "machine readable format");
6264 COMMONPARMS;
6266 ts = cmd_CreateSyntax("syncvldb", SyncVldb, NULL,
6267 "synchronize VLDB with server");
6268 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6269 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6270 cmd_AddParm(ts, "-volume", CMD_SINGLE, CMD_OPTIONAL, "volume name or ID");
6271 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL, "list what would be done, don't do it");
6272 COMMONPARMS;
6274 ts = cmd_CreateSyntax("syncserv", SyncServer, NULL,
6275 "synchronize server with VLDB");
6276 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6277 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6278 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL, "list what would be done, don't do it");
6279 COMMONPARMS;
6281 ts = cmd_CreateSyntax("examine", ExamineVolume, NULL,
6282 "everything about the volume");
6283 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6284 cmd_AddParm(ts, "-extended", CMD_FLAG, CMD_OPTIONAL,
6285 "list extended volume fields");
6286 cmd_AddParm(ts, "-format", CMD_FLAG, CMD_OPTIONAL,
6287 "machine readable format");
6288 COMMONPARMS;
6289 cmd_CreateAlias(ts, "volinfo");
6290 cmd_CreateAlias(ts, "e");
6292 ts = cmd_CreateSyntax("setfields", SetFields, NULL,
6293 "change volume info fields");
6294 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6295 cmd_AddParm(ts, "-maxquota", CMD_SINGLE, CMD_OPTIONAL, "quota (KB)");
6296 cmd_AddParm(ts, "-clearuse", CMD_FLAG, CMD_OPTIONAL, "clear dayUse");
6297 cmd_AddParm(ts, "-clearVolUpCounter", CMD_FLAG, CMD_OPTIONAL, "clear volUpdateCounter");
6298 COMMONPARMS;
6300 ts = cmd_CreateSyntax("offline", volOffline, NULL, "force the volume status to offline");
6301 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "server name");
6302 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6303 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6304 cmd_AddParm(ts, "-sleep", CMD_SINGLE, CMD_OPTIONAL, "seconds to sleep");
6305 cmd_AddParm(ts, "-busy", CMD_FLAG, CMD_OPTIONAL, "busy volume");
6306 COMMONPARMS;
6308 ts = cmd_CreateSyntax("online", volOnline, NULL, "force the volume status to online");
6309 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "server name");
6310 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6311 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6312 COMMONPARMS;
6314 ts = cmd_CreateSyntax("zap", VolumeZap, NULL,
6315 "delete the volume, don't bother with VLDB");
6316 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6317 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6318 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume ID");
6319 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL,
6320 "force deletion of bad volumes");
6321 cmd_AddParm(ts, "-backup", CMD_FLAG, CMD_OPTIONAL,
6322 "also delete backup volume if one is found");
6323 COMMONPARMS;
6325 ts = cmd_CreateSyntax("status", VolserStatus, NULL,
6326 "report on volser status");
6327 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6328 COMMONPARMS;
6330 ts = cmd_CreateSyntax("rename", RenameVolume, NULL, "rename a volume");
6331 cmd_AddParm(ts, "-oldname", CMD_SINGLE, 0, "old volume name ");
6332 cmd_AddParm(ts, "-newname", CMD_SINGLE, 0, "new volume name ");
6333 COMMONPARMS;
6335 ts = cmd_CreateSyntax("listvldb", ListVLDB, NULL,
6336 "list volumes in the VLDB");
6337 cmd_AddParm(ts, "-name", CMD_SINGLE, CMD_OPTIONAL, "volume name or ID");
6338 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6339 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6340 cmd_AddParm(ts, "-locked", CMD_FLAG, CMD_OPTIONAL, "locked volumes only");
6341 cmd_AddParm(ts, "-quiet", CMD_FLAG, CMD_OPTIONAL,
6342 "generate minimal information");
6343 cmd_AddParm(ts, "-nosort", CMD_FLAG, CMD_OPTIONAL,
6344 "do not alphabetically sort the volume names");
6345 COMMONPARMS;
6347 ts = cmd_CreateSyntax("backupsys", BackSys, NULL, "en masse backups");
6348 cmd_AddParm(ts, "-prefix", CMD_LIST, CMD_OPTIONAL,
6349 "common prefix on volume(s)");
6350 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6351 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6352 cmd_AddParm(ts, "-exclude", CMD_FLAG, CMD_OPTIONAL,
6353 "exclude common prefix volumes");
6354 cmd_AddParm(ts, "-xprefix", CMD_LIST, CMD_OPTIONAL,
6355 "negative prefix on volume(s)");
6356 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL, "list what would be done, don't do it");
6357 COMMONPARMS;
6359 ts = cmd_CreateSyntax("delentry", DeleteEntry, NULL,
6360 "delete VLDB entry for a volume");
6361 cmd_AddParm(ts, "-id", CMD_LIST, CMD_OPTIONAL, "volume name or ID");
6362 cmd_AddParm(ts, "-prefix", CMD_SINGLE, CMD_OPTIONAL,
6363 "prefix of the volume whose VLDB entry is to be deleted");
6364 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6365 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6366 cmd_AddParm(ts, "-noexecute", CMD_FLAG, CMD_OPTIONAL|CMD_HIDDEN, "");
6367 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL,
6368 "list what would be done, don't do it");
6369 COMMONPARMS;
6371 ts = cmd_CreateSyntax("partinfo", PartitionInfo, NULL,
6372 "list partition information");
6373 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6374 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6375 cmd_AddParm(ts, "-summary", CMD_FLAG, CMD_OPTIONAL,
6376 "print storage summary");
6377 COMMONPARMS;
6379 ts = cmd_CreateSyntax("unlockvldb", UnlockVLDB, NULL,
6380 "unlock all the locked entries in the VLDB");
6381 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6382 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6383 COMMONPARMS;
6385 ts = cmd_CreateSyntax("lock", LockEntry, NULL,
6386 "lock VLDB entry for a volume");
6387 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6388 COMMONPARMS;
6390 ts = cmd_CreateSyntax("changeaddr", ChangeAddr, NULL,
6391 "change the IP address of a file server");
6392 cmd_AddParm(ts, "-oldaddr", CMD_SINGLE, 0, "original IP address");
6393 cmd_AddParm(ts, "-newaddr", CMD_SINGLE, CMD_OPTIONAL, "new IP address");
6394 cmd_AddParm(ts, "-remove", CMD_FLAG, CMD_OPTIONAL,
6395 "remove the IP address from the VLDB");
6396 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL,
6397 "allow multi-homed server entry change (not recommended)");
6398 COMMONPARMS;
6400 ts = cmd_CreateSyntax("listaddrs", ListAddrs, NULL,
6401 "list the IP address of all file servers registered in the VLDB");
6402 cmd_AddParm(ts, "-uuid", CMD_SINGLE, CMD_OPTIONAL, "uuid of server");
6403 cmd_AddParm(ts, "-host", CMD_SINGLE, CMD_OPTIONAL, "address of host");
6404 cmd_AddParm(ts, "-printuuid", CMD_FLAG, CMD_OPTIONAL,
6405 "print uuid of hosts");
6406 COMMONPARMS;
6408 ts = cmd_CreateSyntax("convertROtoRW", ConvertRO, NULL,
6409 "convert a RO volume into a RW volume (after loss of old RW volume)");
6410 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6411 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6412 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6413 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL, "don't ask");
6414 COMMONPARMS;
6416 ts = cmd_CreateSyntax("size", Sizes, NULL,
6417 "obtain various sizes of the volume.");
6418 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6419 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6420 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6421 cmd_AddParm(ts, "-dump", CMD_FLAG, CMD_OPTIONAL,
6422 "Obtain the size of the dump");
6423 cmd_AddParm(ts, "-time", CMD_SINGLE, CMD_OPTIONAL, "dump from time");
6424 COMMONPARMS;
6426 ts = cmd_CreateSyntax("endtrans", EndTrans, NULL,
6427 "end a volserver transaction");
6428 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6429 cmd_AddParm(ts, "-transaction", CMD_SINGLE, 0,
6430 "transaction ID");
6431 COMMONPARMS;
6433 ts = cmd_CreateSyntax("setaddrs", SetAddrs, NULL,
6434 "set the list of IP addresses for a given UUID in the VLDB");
6435 cmd_AddParm(ts, "-uuid", CMD_SINGLE, 0, "uuid of server");
6436 cmd_AddParm(ts, "-host", CMD_LIST, 0, "address of host");
6437 COMMONPARMS;
6439 ts = cmd_CreateSyntax("remaddrs", RemoveAddrs, NULL,
6440 "remove the list of IP addresses for a given UUID in the VLDB");
6441 cmd_AddParm(ts, "-uuid", CMD_SINGLE, 0, "uuid of server");
6442 COMMONPARMS;
6444 code = cmd_Dispatch(argc, argv);
6445 if (rxInitDone) {
6446 /* Shut down the ubik_client and rx connections */
6447 if (cstruct) {
6448 (void)ubik_ClientDestroy(cstruct);
6449 cstruct = 0;
6451 rx_Finalize();
6454 exit((code ? -1 : 0));