2 * Copyright 2000, International Business Machines Corporation and others.
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
10 #include <afsconfig.h>
11 #include <afs/param.h>
13 #include <afs/procmgmt.h>
19 #include <sys/types.h>
26 #include <netinet/in.h>
28 #include <sys/socket.h>
30 #endif /* AFS_NT40_ENV */
32 #include <afs/procmgmt.h> /* signal(), kill(), wait(), etc. */
36 #include <afs/afsutil.h>
37 #include <afs/cellconfig.h>
42 #include <afs/cellconfig.h>
45 #include <afs/com_err.h>
47 #include <afs/ktime.h>
49 #include <des_prototypes.h>
50 #include <afs/kautils.h>
51 #include <afs/volser.h>
53 static int IStatServer(struct cmd_syndesc *as, int int32p);
54 static int DoStat(char *aname, struct rx_connection *aconn,
55 int aint32p, int firstTime);
58 #include "bosprototypes.h"
60 /* command offsets for bos salvage command */
61 #define MRAFS_OFFSET 10
62 #define ADDPARMOFFSET 27
64 /* MR-AFS salvage parameters */
65 struct MRAFSSalvageParms {
70 afs_int32 Optrootfiles;
71 afs_int32 Optsalvagedirs;
72 afs_int32 Optblockreads;
73 afs_int32 OptListResidencies;
74 afs_int32 OptSalvageRemote;
75 afs_int32 OptSalvageArchival;
76 afs_int32 OptIgnoreCheck;
77 afs_int32 OptForceOnLine;
78 afs_int32 OptUseRootDirACL;
79 afs_int32 OptTraceBadLinkCounts;
80 afs_int32 OptDontAskFS;
81 afs_int32 OptLogLevel;
83 afs_uint32 OptResidencies;
86 /* dummy routine for the audit work. It should do nothing since audits */
87 /* occur at the server level and bos is not a server. */
93 /* keep those lines small */
98 return "communications failure (-1)";
100 return "communications timeout (-3)";
102 return (char *)afs_error_message(acode);
105 /* get partition id from a name */
106 /* XXX - unused code - could be removed? */
109 GetPartitionID(char *aname)
116 return -1; /* unknown */
117 /* numbers go straight through */
118 if (tc >= '0' && tc <= '9') {
121 /* otherwise check for vicepa or /vicepa, or just plain "a" */
123 if (strlen(aname) <= 2) {
124 strcpy(ascii, aname);
125 } else if (!strncmp(aname, "/vicep", 6)) {
126 strncpy(ascii, aname + 6, 2);
127 } else if (!strncmp(aname, "vicep", 5)) {
128 strncpy(ascii, aname + 5, 2);
130 return -1; /* bad partition name */
131 /* now partitions are named /vicepa ... /vicepz, /vicepaa, /vicepab,
132 * .../vicepzz, and are numbered from 0. Do the appropriate conversion */
134 /* one char name, 0..25 */
135 if (ascii[0] < 'a' || ascii[0] > 'z')
136 return -1; /* wrongo */
137 return ascii[0] - 'a';
139 /* two char name, 26 .. <whatever> */
140 if (ascii[0] < 'a' || ascii[0] > 'z')
141 return -1; /* wrongo */
142 if (ascii[1] < 'a' || ascii[1] > 'z')
143 return -1; /* just as bad */
144 return (ascii[0] - 'a') * 26 + (ascii[1] - 'a') + 26;
149 /* make ctime easier to use */
151 DateOf(afs_int32 atime)
153 static char tbuffer[30];
155 time_t t = (time_t) atime;
159 tbuffer[24] = 0; /* get rid of new line */
161 strcpy(tbuffer, "BAD TIME");
166 /* use the syntax descr to get a connection, authenticated appropriately.
167 * aencrypt is set if we want to encrypt the data on the wire.
169 static struct rx_connection *
170 GetConn(struct cmd_syndesc *as, int aencrypt)
174 char *cellname = NULL;
177 struct rx_connection *tconn;
179 struct afsconf_dir *tdir = NULL;
180 afsconf_secflags secFlags;
181 struct rx_securityClass *sc;
184 hostname = as->parms[0].items->data;
185 th = hostutil_GetHostByName(hostname);
187 printf("bos: can't find address for host '%s'\n", hostname);
190 memcpy(&addr, th->h_addr, sizeof(afs_int32));
192 secFlags = AFSCONF_SECOPTS_FALLBACK_NULL;
194 if (as->parms[ADDPARMOFFSET + 2].items) { /* -localauth */
195 secFlags |= AFSCONF_SECOPTS_LOCALAUTH;
196 confdir = AFSDIR_SERVER_ETC_DIRPATH;
198 confdir = AFSDIR_CLIENT_ETC_DIRPATH;
201 if (as->parms[ADDPARMOFFSET + 1].items) { /* -noauth */
202 secFlags |= AFSCONF_SECOPTS_NOAUTH;
204 /* If we're running with -noauth, we don't need a configuration
206 tdir = afsconf_Open(confdir);
208 printf("bos: can't open cell database (%s)\n", confdir);
213 if (as->parms[ADDPARMOFFSET].items) /* -cell */
214 cellname = as->parms[ADDPARMOFFSET].items->data;
216 code = afsconf_PickClientSecObj(tdir, secFlags, NULL, cellname,
217 &sc, &scIndex, NULL);
219 afs_com_err("bos", code, "(configuring connection security)");
223 if (scIndex == RX_SECIDX_NULL)
224 fprintf(stderr, "bos: running unauthenticated\n");
227 rx_NewConnection(addr, htons(AFSCONF_NANNYPORT), 1, sc, scIndex);
229 fprintf(stderr, "bos: could not create rx connection\n");
238 SetAuth(struct cmd_syndesc *as, void *arock)
241 struct rx_connection *tconn;
245 tconn = GetConn(as, 0);
246 tp = as->parms[1].items->data;
247 if (strcmp(tp, "on") == 0)
248 flag = 0; /* auth req.: noauthflag is false */
249 else if (strcmp(tp, "off") == 0)
253 ("bos: illegal authentication specifier '%s', must be 'off' or 'on'.\n",
257 code = BOZO_SetNoAuthFlag(tconn, flag);
259 afs_com_err("bos", code, "(failed to set authentication flag)");
263 /* take a name (e.g. foo/bar, and a dir e.g. /usr/afs/bin, and construct
264 * /usr/afs/bin/bar */
266 ComputeDestDir(char *aname, char *adir, char *aresult, afs_int32 alen)
270 strcpy(aresult, adir);
271 tp = strrchr(aname, '/');
274 strcat(aresult, "/");
275 strcat(aresult, aname);
277 /* tp points at the / character */
283 /* copy data from fd afd to rx call acall */
285 CopyBytes(int afd, struct rx_call *acall)
292 len = read(afd, tbuffer, sizeof(tbuffer));
296 return 0; /* all done */
297 code = rx_Write(acall, tbuffer, len);
304 Prune(struct cmd_syndesc *as, void *arock)
307 struct rx_connection *tconn;
310 tconn = GetConn(as, 0);
312 if (as->parms[1].items)
313 flags |= BOZO_PRUNEBAK;
314 if (as->parms[2].items)
315 flags |= BOZO_PRUNEOLD;
316 if (as->parms[3].items)
317 flags |= BOZO_PRUNECORE;
318 if (as->parms[4].items)
320 code = BOZO_Prune(tconn, flags);
322 afs_com_err("bos", code, "(failed to prune server files)");
327 Exec(struct cmd_syndesc *as, void *arock)
329 struct rx_connection *tconn;
332 tconn = GetConn(as, 0);
333 code = BOZO_Exec(tconn, as->parms[1].items->data);
335 printf("bos: failed to execute command (%s)\n", em(code));
340 GetDate(struct cmd_syndesc *as, void *arock)
345 afs_int32 time, bakTime, oldTime;
346 struct rx_connection *tconn;
349 tconn = GetConn(as, 0);
350 if (!as->parms[1].items) {
351 printf("bos: no files to check\n");
355 /* compute dest dir or file; default MUST be canonical form of dir path */
356 if (as->parms[2].items)
357 strcpy(destDir, as->parms[2].items->data);
359 strcpy(destDir, AFSDIR_CANONICAL_SERVER_BIN_DIRPATH);
361 for (ti = as->parms[1].items; ti; ti = ti->next) {
362 /* check date for each file */
363 ComputeDestDir(ti->data, destDir, tbuffer, sizeof(tbuffer));
364 code = BOZO_GetDates(tconn, tbuffer, &time, &bakTime, &oldTime);
366 printf("bos: failed to check date on %s (%s)\n", ti->data,
370 printf("File %s ", tbuffer);
372 printf("does not exist, ");
374 printf("dated %s, ", DateOf(time));
376 printf("no .BAK file, ");
378 printf(".BAK file dated %s, ", DateOf(bakTime));
380 printf("no .OLD file.");
382 printf(".OLD file dated %s.", DateOf(oldTime));
390 UnInstall(struct cmd_syndesc *as, void *arock)
396 struct rx_connection *tconn;
398 tconn = GetConn(as, 0);
399 if (!as->parms[1].items) {
400 printf("bos: no files to uninstall\n");
404 /* compute dest dir or file; default MUST be canonical form of dir path */
405 if (as->parms[2].items)
406 strcpy(destDir, as->parms[2].items->data);
408 strcpy(destDir, AFSDIR_CANONICAL_SERVER_BIN_DIRPATH);
410 for (ti = as->parms[1].items; ti; ti = ti->next) {
411 /* uninstall each file */
412 ComputeDestDir(ti->data, destDir, tbuffer, sizeof(tbuffer));
413 code = BOZO_UnInstall(tconn, tbuffer);
415 printf("bos: failed to uninstall %s (%s)\n", ti->data, em(code));
418 printf("bos: uninstalled file %s\n", ti->data);
424 GetServerGoal(struct rx_connection *aconn, char *aname)
429 struct bozo_status istatus;
432 code = BOZO_GetInstanceInfo(aconn, aname, &tp, &istatus);
434 printf("bos: failed to get instance info for '%s' (%s)\n", aname,
436 /* if we can't get the answer, assume its running */
439 if (istatus.goal == 0)
440 return BSTAT_SHUTDOWN;
446 Install(struct cmd_syndesc *as, void *arock)
448 struct rx_connection *tconn;
454 struct rx_call *tcall;
457 tconn = GetConn(as, 0);
458 if (!as->parms[1].items) {
459 printf("bos: no files to install\n");
463 /* compute dest dir or file; default MUST be canonical form of dir path */
464 if (as->parms[2].items)
465 strcpy(destDir, as->parms[2].items->data);
467 strcpy(destDir, AFSDIR_CANONICAL_SERVER_BIN_DIRPATH);
469 for (ti = as->parms[1].items; ti; ti = ti->next) {
470 /* install each file */
471 fd = open(ti->data, O_RDONLY);
473 /* better to quit on error than continue for install command */
474 printf("bos: can't find file '%s', quitting\n", ti->data);
477 code = fstat(fd, &tstat);
479 printf("bos: failed to stat file %s, errno is %d\n", ti->data,
483 /* compute destination dir */
484 ComputeDestDir(ti->data, destDir, tbuffer, sizeof(tbuffer));
485 tcall = rx_NewCall(tconn);
487 StartBOZO_Install(tcall, tbuffer, tstat.st_size,
488 (afs_int32) tstat.st_mode, tstat.st_mtime);
490 code = CopyBytes(fd, tcall);
492 code = rx_EndCall(tcall, code);
494 printf("bos: failed to install %s (%s)\n", ti->data, em(code));
497 printf("bos: installed file %s\n", ti->data);
503 Shutdown(struct cmd_syndesc *as, void *arock)
505 struct rx_connection *tconn;
509 tconn = GetConn(as, 0);
510 if (as->parms[1].items == 0) {
511 code = BOZO_ShutdownAll(tconn);
513 printf("bos: failed to shutdown servers (%s)\n", em(code));
515 for (ti = as->parms[1].items; ti; ti = ti->next) {
516 code = BOZO_SetTStatus(tconn, ti->data, BSTAT_SHUTDOWN);
518 printf("bos: failed to shutdown instance %s (%s)\n", ti->data,
522 if (as->parms[8].items) {
523 code = BOZO_WaitAll(tconn);
525 printf("bos: can't wait for processes to shutdown (%s)\n",
532 BlockScannerCmd(struct cmd_syndesc *as, void *arock)
535 struct rx_connection *tconn;
536 char BlockCommand[] = "/usr/afs/bin/scanner -block";
538 tconn = GetConn(as, 0);
539 code = BOZO_Exec(tconn, BlockCommand);
542 ("bos: failed to block scanner from making migration requests (%s)\n",
548 UnBlockScannerCmd(struct cmd_syndesc *as, void *arock)
551 struct rx_connection *tconn;
552 char UnBlockCommand[] = "/usr/afs/bin/scanner -unblock";
554 tconn = GetConn(as, 0);
555 code = BOZO_Exec(tconn, UnBlockCommand);
558 ("bos: failed to allow scanner daemon to make migration requests again (%s)\n",
564 GetRestartCmd(struct cmd_syndesc *as, void *arock)
567 struct ktime generalTime, newBinaryTime;
568 char messageBuffer[256];
569 struct rx_connection *tconn;
572 hostp = as->parms[0].items->data; /* host name for messages */
573 tconn = GetConn(as, 0);
575 code = BOZO_GetRestartTime(tconn, 1, (struct bozo_netKTime *) &generalTime);
577 printf("bos: failed to retrieve restart information (%s)\n",
581 code = BOZO_GetRestartTime(tconn, 2, (struct bozo_netKTime *) &newBinaryTime);
583 printf("bos: failed to retrieve restart information (%s)\n",
588 code = ktime_DisplayString(&generalTime, messageBuffer);
590 printf("bos: failed to decode restart time (%s)\n", em(code));
593 printf("Server %s restarts %s\n", hostp, messageBuffer);
595 code = ktime_DisplayString(&newBinaryTime, messageBuffer);
597 printf("bos: failed to decode restart time (%s)\n", em(code));
600 printf("Server %s restarts for new binaries %s\n", hostp, messageBuffer);
607 SetRestartCmd(struct cmd_syndesc *as, void *arock)
611 struct ktime restartTime;
613 struct rx_connection *tconn;
616 tconn = GetConn(as, 0);
617 if (as->parms[2].items) {
621 if (as->parms[3].items) {
626 printf("bos: can't specify more than one restart time at a time\n");
630 type = 1; /* by default set general restart time */
632 if ((code = ktime_ParsePeriodic(as->parms[1].items->data, &restartTime))) {
633 printf("bos: failed to parse '%s' as periodic restart time(%s)\n",
634 as->parms[1].items->data, em(code));
638 code = BOZO_SetRestartTime(tconn, type, (struct bozo_netKTime *) &restartTime);
640 printf("bos: failed to set restart time at server (%s)\n", em(code));
647 Startup(struct cmd_syndesc *as, void *arock)
649 struct rx_connection *tconn;
653 tconn = GetConn(as, 0);
654 if (as->parms[1].items == 0) {
655 code = BOZO_StartupAll(tconn);
657 printf("bos: failed to startup servers (%s)\n", em(code));
659 for (ti = as->parms[1].items; ti; ti = ti->next) {
660 code = BOZO_SetTStatus(tconn, ti->data, BSTAT_NORMAL);
662 printf("bos: failed to start instance %s (%s)\n", ti->data,
670 Restart(struct cmd_syndesc *as, void *arock)
672 struct rx_connection *tconn;
676 tconn = GetConn(as, 0);
677 if (as->parms[2].items) {
678 /* this is really a rebozo command */
679 if (as->parms[1].items) {
680 /* specified specific things to restart, can't do this at the same
683 ("bos: can't specify both '-bos' and specific servers to restart.\n");
686 /* otherwise do a rebozo */
687 code = BOZO_ReBozo(tconn);
689 printf("bos: failed to restart bosserver (%s)\n", em(code));
692 if (as->parms[1].items == 0) {
693 if (as->parms[3].items) { /* '-all' */
694 code = BOZO_RestartAll(tconn);
696 printf("bos: failed to restart servers (%s)\n", em(code));
698 printf("bos: To restart all processes please specify '-all'\n");
700 if (as->parms[3].items) {
701 printf("bos: Can't use '-all' along with individual instances\n");
703 for (ti = as->parms[1].items; ti; ti = ti->next) {
704 code = BOZO_Restart(tconn, ti->data);
706 printf("bos: failed to restart instance %s (%s)\n",
715 SetCellName(struct cmd_syndesc *as, void *arock)
717 struct rx_connection *tconn;
720 tconn = GetConn(as, 0);
721 code = BOZO_SetCellName(tconn, as->parms[1].items->data);
723 printf("bos: failed to set cell (%s)\n", em(code));
728 AddHost(struct cmd_syndesc *as, void *arock)
730 struct rx_connection *tconn;
733 char name[MAXHOSTCHARS];
735 tconn = GetConn(as, 0);
736 for (ti = as->parms[1].items; ti; ti = ti->next) {
737 if (as->parms[2].items) {
738 if (strlen(ti->data) > MAXHOSTCHARS - 3) {
739 fprintf(stderr, "bos: host name too long\n");
743 strcpy(&name[1], ti->data);
744 strcat((char *)&name, "]");
745 code = BOZO_AddCellHost(tconn, name);
747 code = BOZO_AddCellHost(tconn, ti->data);
749 printf("bos: failed to add host %s (%s)\n", ti->data, em(code));
755 RemoveHost(struct cmd_syndesc *as, void *arock)
757 struct rx_connection *tconn;
761 tconn = GetConn(as, 0);
762 for (ti = as->parms[1].items; ti; ti = ti->next) {
763 code = BOZO_DeleteCellHost(tconn, ti->data);
765 printf("bos: failed to delete host %s (%s)\n", ti->data,
772 ListHosts(struct cmd_syndesc *as, void *arock)
774 struct rx_connection *tconn;
781 tconn = GetConn(as, 0);
782 code = BOZO_GetCellName(tconn, &tp);
784 printf("bos: failed to get cell name (%s)\n", em(code));
787 printf("Cell name is %s\n", tbuffer);
789 code = BOZO_GetCellHost(tconn, i, &tp);
793 printf("bos: failed to get cell host %d (%s)\n", i, em(code));
796 printf(" Host %d is %s\n", i + 1, tbuffer);
802 AddKey(struct cmd_syndesc *as, void *arock)
804 struct rx_connection *tconn;
806 struct ktc_encryptionKey tkey;
809 char cellBuffer[256];
810 char buf[BUFSIZ], ver[BUFSIZ];
812 tconn = GetConn(as, 1);
813 memset(&tkey, 0, sizeof(struct ktc_encryptionKey));
815 if (as->parms[1].items)
816 strcpy(buf, as->parms[1].items->data);
819 code = des_read_pw_string(buf, sizeof(buf), "input key: ", 0);
820 if (code || strlen(buf) == 0) {
821 fprintf(stderr, "Bad key: \n");
824 code = des_read_pw_string(ver, sizeof(ver), "Retype input key: ", 0);
825 if (code || strlen(ver) == 0) {
826 fprintf(stderr, "Bad key: \n");
829 if (strcmp(ver, buf) != 0) {
830 fprintf(stderr, "\nInput key mismatch\n");
836 temp = atoi(as->parms[2].items->data);
840 strcpy((char *)&tkey, as->parms[1].items->data);
842 strcpy((char *)&tkey, buf);
843 } else { /* kerberos key */
844 if (as->parms[ADDPARMOFFSET].items) {
845 strcpy(cellBuffer, as->parms[ADDPARMOFFSET].items->data);
847 /* string to key needs upper-case cell names */
849 /* I don't believe this is true. The string to key function
850 * actually expands the cell name, then LOWER-CASES it. Perhaps it
851 * didn't use to??? */
852 ucstring(cellBuffer, cellBuffer, strlen(cellBuffer));
855 tcell = NULL; /* no cell specified, use current */
857 ka_StringToKey(as->parms[1].items->data, tcell, &tkey);
859 ka_StringToKey(buf, tcell, &tkey);
861 tconn = GetConn(as, 1);
862 code = BOZO_AddKey(tconn, temp, ktc_to_bozoptr(&tkey));
864 printf("bos: failed to set key %d (%s)\n", temp, em(code));
871 RemoveKey(struct cmd_syndesc *as, void *arock)
873 struct rx_connection *tconn;
878 tconn = GetConn(as, 0);
879 for (ti = as->parms[1].items; ti; ti = ti->next) {
880 temp = atoi(ti->data);
881 code = BOZO_DeleteKey(tconn, temp);
883 printf("bos: failed to delete key %d (%s)\n", temp, em(code));
891 ListKeys(struct cmd_syndesc *as, void *arock)
893 struct rx_connection *tconn;
895 struct ktc_encryptionKey tkey;
897 struct bozo_keyInfo keyInfo;
901 tconn = GetConn(as, 1);
904 code = BOZO_ListKeys(tconn, i, &kvno, ktc_to_bozoptr(&tkey), &keyInfo);
908 /* first check if key is returned */
909 if ((!ka_KeyIsZero(ktc_to_charptr(&tkey), sizeof(tkey))) && (as->parms[1].items)) {
910 printf("key %d is '", kvno);
911 ka_PrintBytes(ktc_to_charptr(&tkey), sizeof(tkey));
914 if (keyInfo.keyCheckSum == 0) /* shouldn't happen */
915 printf("key version is %d\n", kvno);
917 printf("key %d has cksum %u\n", kvno, keyInfo.keyCheckSum);
921 printf("Keys last changed on %s.\n", DateOf(keyInfo.mod_sec));
924 printf("bos: %s error encountered while listing keys\n", em(code));
926 printf("All done.\n");
931 AddSUser(struct cmd_syndesc *as, void *arock)
933 struct rx_connection *tconn;
939 tconn = GetConn(as, 0);
940 for (ti = as->parms[1].items; ti; ti = ti->next) {
941 code = BOZO_AddSUser(tconn, ti->data);
943 printf("bos: failed to add user '%s' (%s)\n", ti->data, em(code));
951 RemoveSUser(struct cmd_syndesc *as, void *arock)
953 struct rx_connection *tconn;
959 tconn = GetConn(as, 0);
960 for (ti = as->parms[1].items; ti; ti = ti->next) {
961 code = BOZO_DeleteSUser(tconn, ti->data);
963 printf("bos: failed to delete user '%s', ", ti->data);
965 printf("(no such user)\n");
967 printf("(%s)\n", em(code));
974 #define NPERLINE 10 /* dudes to print per line */
976 ListSUsers(struct cmd_syndesc *as, void *arock)
978 struct rx_connection *tconn;
983 int lastNL, printGreeting;
985 tconn = GetConn(as, 0);
990 code = BOZO_ListSUsers(tconn, i, &tp);
994 printGreeting = 0; /* delay until after first call succeeds */
995 printf("SUsers are: ");
997 printf("%s ", tbuffer);
998 if ((i % NPERLINE) == NPERLINE - 1) {
1005 /* a real error code, instead of scanned past end */
1006 printf("bos: failed to retrieve super-user list (%s)\n", em(code));
1015 StatServer(struct cmd_syndesc *as, void *arock)
1017 struct rx_connection *tconn;
1020 char ibuffer[BOZO_BSSIZE];
1024 /* int32p==1 is obsolete, smaller, printout */
1025 int32p = (as->parms[2].items != 0 ? 2 : 0);
1027 /* no parms does something pretty different */
1028 if (as->parms[1].items)
1029 return IStatServer(as, int32p);
1031 tconn = GetConn(as, 0);
1033 /* for each instance */
1035 code = BOZO_EnumerateInstance(tconn, i, &tp);
1039 printf("bos: failed to contact host's bosserver (%s).\n",
1043 DoStat(ibuffer, tconn, int32p, (i == 0)); /* print status line */
1049 CreateServer(struct cmd_syndesc *as, void *arock)
1051 struct rx_connection *tconn;
1054 struct cmd_item *ti;
1056 char *type, *name, *notifier = NONOTIFIER;
1058 tconn = GetConn(as, 0);
1059 for (i = 0; i < 6; i++)
1061 for (i = 0, ti = as->parms[3].items; (ti && i < 6); ti = ti->next, i++) {
1062 parms[i] = ti->data;
1064 name = as->parms[1].items->data;
1065 type = as->parms[2].items->data;
1066 if ((ti = as->parms[4].items)) {
1067 notifier = ti->data;
1070 BOZO_CreateBnode(tconn, type, name, parms[0], parms[1], parms[2],
1071 parms[3], parms[4], notifier);
1074 ("bos: failed to create new server instance %s of type '%s' (%s)\n",
1075 name, type, em(code));
1081 DeleteServer(struct cmd_syndesc *as, void *arock)
1083 struct rx_connection *tconn;
1085 struct cmd_item *ti;
1088 tconn = GetConn(as, 0);
1089 for (ti = as->parms[1].items; ti; ti = ti->next) {
1090 code = BOZO_DeleteBnode(tconn, ti->data);
1093 printf("bos: can't delete running instance '%s'\n", ti->data);
1095 printf("bos: failed to delete instance '%s' (%s)\n", ti->data,
1103 StartServer(struct cmd_syndesc *as, void *arock)
1105 struct rx_connection *tconn;
1107 struct cmd_item *ti;
1110 tconn = GetConn(as, 0);
1111 for (ti = as->parms[1].items; ti; ti = ti->next) {
1112 code = BOZO_SetStatus(tconn, ti->data, BSTAT_NORMAL);
1114 printf("bos: failed to start instance '%s' (%s)\n", ti->data,
1121 StopServer(struct cmd_syndesc *as, void *arock)
1123 struct rx_connection *tconn;
1125 struct cmd_item *ti;
1128 tconn = GetConn(as, 0);
1129 for (ti = as->parms[1].items; ti; ti = ti->next) {
1130 code = BOZO_SetStatus(tconn, ti->data, BSTAT_SHUTDOWN);
1132 printf("bos: failed to change stop instance '%s' (%s)\n",
1133 ti->data, em(code));
1135 if (as->parms[8].items) {
1136 code = BOZO_WaitAll(tconn);
1138 printf("bos: can't wait for processes to shutdown (%s)\n",
1144 #define PARMBUFFERSSIZE 32
1147 DoSalvage(struct rx_connection * aconn, char * aparm1, char * aparm2,
1148 char * aoutName, afs_int32 showlog, char * parallel,
1149 char * atmpDir, char * orphans, int dafs,
1150 struct MRAFSSalvageParms * mrafsParm)
1155 char tbuffer[BOZO_BSSIZE];
1156 struct bozo_status istatus;
1157 struct rx_call *tcall;
1161 char partName[20]; /* canonical name for partition */
1162 char pbuffer[PARMBUFFERSSIZE];
1163 afs_int32 partNumber;
1164 char *notifier = NONOTIFIER;
1166 /* if a partition was specified, canonicalize the name, since
1167 * the salvager has a stupid partition ID parser */
1169 partNumber = volutil_GetPartitionID(aparm1);
1170 if (partNumber < 0) {
1171 printf("bos: could not parse partition ID '%s'\n", aparm1);
1174 tp = volutil_PartitionName(partNumber);
1176 printf("bos: internal error parsing partition ID '%s'\n", aparm1);
1179 strcpy(partName, tp);
1183 /* open the file name */
1185 outFile = fopen(aoutName, "w");
1187 printf("bos: can't open specified SalvageLog file '%s'\n",
1191 closeIt = 1; /* close this file later */
1194 closeIt = 0; /* don't close this file later */
1197 for (code = 2; code < 6; code++)
1202 /* MUST pass canonical (wire-format) salvager path to bosserver */
1204 /* single volume salvage */
1206 /* for DAFS, we call the salvagserver binary with special options.
1207 * in this mode, it simply uses SALVSYNC to tell the currently
1208 * running salvageserver to offline and salvage the volume in question */
1209 strncpy(tbuffer, AFSDIR_CANONICAL_SERVER_SALSRV_FILEPATH, BOZO_BSSIZE);
1211 if ((strlen(tbuffer) + 9 + strlen(partName) + 1 + strlen(aparm2) +
1213 printf("bos: command line too big\n");
1217 strcat(tbuffer, " -client ");
1218 strcat(tbuffer, partName);
1219 strcat(tbuffer, " ");
1220 strcat(tbuffer, aparm2);
1222 strncpy(tbuffer, AFSDIR_CANONICAL_SERVER_SALVAGER_FILEPATH, BOZO_BSSIZE);
1224 if ((strlen(tbuffer) + 1 + strlen(partName) + 1 + strlen(aparm2) +
1226 printf("bos: command line too big\n");
1230 strcat(tbuffer, " ");
1231 strcat(tbuffer, partName);
1232 strcat(tbuffer, " ");
1233 strcat(tbuffer, aparm2);
1236 /* partition salvage */
1237 strncpy(tbuffer, AFSDIR_CANONICAL_SERVER_SALVAGER_FILEPATH, BOZO_BSSIZE);
1238 if ((strlen(tbuffer) + 4 + strlen(partName) + 1) > BOZO_BSSIZE) {
1239 printf("bos: command line too big\n");
1242 strcat(tbuffer, " -force ");
1243 strcat(tbuffer, partName);
1246 /* For DAFS, specifying a single volume does not result in a standard
1247 * salvager call. Instead, it simply results in a SALVSYNC call to the
1248 * online salvager daemon. This interface does not give us the same rich
1249 * set of call flags. Thus, we skip these steps for DAFS single-volume
1251 if (!dafs || (*aparm2 == 0)) {
1252 /* add the parallel option if given */
1253 if (parallel != NULL) {
1254 if ((strlen(tbuffer) + 11 + strlen(parallel) + 1) > BOZO_BSSIZE) {
1255 printf("bos: command line too big\n");
1258 strcat(tbuffer, " -parallel ");
1259 strcat(tbuffer, parallel);
1262 /* add the tmpdir option if given */
1263 if (atmpDir != NULL) {
1264 if ((strlen(tbuffer) + 9 + strlen(atmpDir) + 1) > BOZO_BSSIZE) {
1265 printf("bos: command line too big\n");
1268 strcat(tbuffer, " -tmpdir ");
1269 strcat(tbuffer, atmpDir);
1272 /* add the orphans option if given */
1273 if (orphans != NULL) {
1274 if ((strlen(tbuffer) + 10 + strlen(orphans) + 1) > BOZO_BSSIZE) {
1275 printf("bos: command line too big\n");
1278 strcat(tbuffer, " -orphans ");
1279 strcat(tbuffer, orphans);
1282 if (mrafsParm->Optdebug)
1283 strcat(tbuffer, " -debug");
1284 if (mrafsParm->Optnowrite)
1285 strcat(tbuffer, " -nowrite");
1286 if (mrafsParm->Optforce)
1287 strcat(tbuffer, " -force");
1288 if (mrafsParm->Optoktozap)
1289 strcat(tbuffer, " -oktozap");
1290 if (mrafsParm->Optrootfiles)
1291 strcat(tbuffer, " -rootfiles");
1292 if (mrafsParm->Optsalvagedirs)
1293 strcat(tbuffer, " -salvagedirs");
1294 if (mrafsParm->Optblockreads)
1295 strcat(tbuffer, " -blockreads");
1296 if (mrafsParm->OptListResidencies)
1297 strcat(tbuffer, " -ListResidencies");
1298 if (mrafsParm->OptSalvageRemote)
1299 strcat(tbuffer, " -SalvageRemote");
1300 if (mrafsParm->OptSalvageArchival)
1301 strcat(tbuffer, " -SalvageArchival");
1302 if (mrafsParm->OptIgnoreCheck)
1303 strcat(tbuffer, " -IgnoreCheck");
1304 if (mrafsParm->OptForceOnLine)
1305 strcat(tbuffer, " -ForceOnLine");
1306 if (mrafsParm->OptUseRootDirACL)
1307 strcat(tbuffer, " -UseRootDirACL");
1308 if (mrafsParm->OptTraceBadLinkCounts)
1309 strcat(tbuffer, " -TraceBadLinkCounts");
1310 if (mrafsParm->OptDontAskFS)
1311 strcat(tbuffer, " -DontAskFS");
1312 if (mrafsParm->OptLogLevel) {
1313 sprintf(pbuffer, " -LogLevel %ld", afs_printable_int32_ld(mrafsParm->OptLogLevel));
1314 strcat(tbuffer, pbuffer);
1316 if (mrafsParm->OptRxDebug)
1317 strcat(tbuffer, " -rxdebug");
1318 if (mrafsParm->OptResidencies) {
1319 sprintf(pbuffer, " -Residencies %lu",
1320 afs_printable_uint32_lu(mrafsParm->OptResidencies));
1321 strcat(tbuffer, pbuffer);
1326 parms[1] = "now"; /* when to do it */
1328 BOZO_CreateBnode(aconn, "cron", "salvage-tmp", parms[0], parms[1],
1329 parms[2], parms[3], parms[4], notifier);
1331 printf("bos: failed to start 'salvager' (%s)\n", em(code));
1334 /* now wait for bnode to disappear */
1338 code = BOZO_GetInstanceInfo(aconn, "salvage-tmp", &tp, &istatus);
1341 printf("bos: waiting for salvage to complete.\n");
1343 if (code != BZNOENT) {
1344 printf("bos: salvage failed (%s)\n", em(code));
1349 /* now print the log file to the output file */
1350 printf("bos: salvage completed\n");
1351 if (aoutName || showlog) {
1352 fprintf(outFile, "SalvageLog:\n");
1353 tcall = rx_NewCall(aconn);
1354 /* MUST pass canonical (wire-format) salvager log path to bosserver */
1356 StartBOZO_GetLog(tcall, AFSDIR_CANONICAL_SERVER_SLVGLOG_FILEPATH);
1358 rx_EndCall(tcall, code);
1363 code = rx_Read(tcall, &buffer, 1);
1366 putc(buffer, outFile);
1368 break; /* the end delimeter */
1370 code = rx_EndCall(tcall, 0);
1371 /* fall through into cleanup code */
1375 if (closeIt && outFile)
1381 GetLogCmd(struct cmd_syndesc *as, void *arock)
1383 struct rx_connection *tconn;
1384 struct rx_call *tcall;
1389 printf("Fetching log file '%s'...\n", as->parms[1].items->data);
1390 tconn = GetConn(as, 0);
1391 tcall = rx_NewCall(tconn);
1392 code = StartBOZO_GetLog(tcall, as->parms[1].items->data);
1394 rx_EndCall(tcall, code);
1400 code = rx_Read(tcall, &buffer, 1);
1406 break; /* the end delimeter */
1409 code = rx_EndCall(tcall, error);
1410 /* fall through into cleanup code */
1414 afs_com_err("bos", code, "(while reading log)");
1419 IsDAFS(struct rx_connection *aconn)
1421 char buffer[BOZO_BSSIZE];
1423 struct bozo_status istatus;
1428 code = BOZO_GetInstanceInfo(aconn, "dafs", &tp, &istatus);
1430 /* no dafs bnode; cannot be dafs */
1434 /* dafs bnode is running; we must be dafs */
1438 /* At this point, either we have neither a dafs nor fs bnode running, or
1439 * we have an fs bnode running but the dafs bnode is stopped.
1441 * If an fs bnode is running, we are obviously not DAFS. If an fs bnode
1442 * is not running and a dafs bnode is not running... it's not certain if
1443 * we are DAFS or not DAFS. Just return 0 in that case; it shouldn't much
1444 * matter what we return, anyway */
1449 SalvageCmd(struct cmd_syndesc *as, void *arock)
1451 struct rx_connection *tconn;
1452 afs_int32 code, rc, i;
1454 char tname[BOZO_BSSIZE];
1456 extern struct ubik_client *cstruct;
1457 afs_int32 curGoal, showlog = 0, dafs = 0, mrafs = 0;
1463 struct MRAFSSalvageParms mrafsParm;
1465 memset(&mrafsParm, 0, sizeof(mrafsParm));
1467 /* parm 0 is machine name, 1 is partition, 2 is volume, 3 is -all flag */
1468 tconn = GetConn(as, 0);
1472 /* find out whether fileserver is running demand attach fs */
1473 if (IsDAFS(tconn)) {
1475 serviceName = "dafs";
1476 /* Find out whether fileserver is running MR-AFS (has a scanner instance) */
1477 /* XXX this should really be done some other way, potentially by RPC */
1478 if ((code = BOZO_GetInstanceParm(tconn, serviceName, 4, &tp) == 0))
1482 /* Find out whether fileserver is running MR-AFS (has a scanner instance) */
1483 /* XXX this should really be done some other way, potentially by RPC */
1484 if ((code = BOZO_GetInstanceParm(tconn, serviceName, 3, &tp) == 0))
1488 /* we can do a volume, a partition or the whole thing, but not mixtures
1490 if (!as->parms[1].items && as->parms[2].items) {
1491 printf("bos: must specify partition to salvage individual volume.\n");
1494 if (as->parms[5].items && as->parms[3].items) {
1495 printf("bos: can not specify both -file and -showlog.\n");
1498 if (as->parms[4].items && (as->parms[1].items || as->parms[2].items)) {
1499 printf("bos: can not specify -all with other flags.\n");
1503 /* get the output file name, if any */
1504 if (as->parms[3].items)
1505 outName = as->parms[3].items->data;
1509 if (as->parms[5].items)
1512 /* parallel option */
1514 if (as->parms[6].items)
1515 parallel = as->parms[6].items->data;
1517 /* get the tmpdir filename if any */
1519 if (as->parms[7].items)
1520 tmpDir = as->parms[7].items->data;
1522 /* -orphans option */
1524 if (as->parms[8].items) {
1526 printf("Can't specify -orphans for MR-AFS fileserver\n");
1529 orphans = as->parms[8].items->data;
1533 if (!as->parms[9].items) { /* -forceDAFS flag */
1534 printf("This is a demand attach fileserver. Are you sure you want to proceed with a manual salvage?\n");
1535 printf("must specify -forceDAFS flag in order to proceed.\n");
1541 if (as->parms[MRAFS_OFFSET].items)
1542 mrafsParm.Optdebug = 1;
1543 if (as->parms[MRAFS_OFFSET + 1].items)
1544 mrafsParm.Optnowrite = 1;
1545 if (as->parms[MRAFS_OFFSET + 2].items)
1546 mrafsParm.Optforce = 1;
1547 if (as->parms[MRAFS_OFFSET + 3].items)
1548 mrafsParm.Optoktozap = 1;
1549 if (as->parms[MRAFS_OFFSET + 4].items)
1550 mrafsParm.Optrootfiles = 1;
1551 if (as->parms[MRAFS_OFFSET + 5].items)
1552 mrafsParm.Optsalvagedirs = 1;
1553 if (as->parms[MRAFS_OFFSET + 6].items)
1554 mrafsParm.Optblockreads = 1;
1555 if (as->parms[MRAFS_OFFSET + 7].items)
1556 mrafsParm.OptListResidencies = 1;
1557 if (as->parms[MRAFS_OFFSET + 8].items)
1558 mrafsParm.OptSalvageRemote = 1;
1559 if (as->parms[MRAFS_OFFSET + 9].items)
1560 mrafsParm.OptSalvageArchival = 1;
1561 if (as->parms[MRAFS_OFFSET + 10].items)
1562 mrafsParm.OptIgnoreCheck = 1;
1563 if (as->parms[MRAFS_OFFSET + 11].items)
1564 mrafsParm.OptForceOnLine = 1;
1565 if (as->parms[MRAFS_OFFSET + 12].items)
1566 mrafsParm.OptUseRootDirACL = 1;
1567 if (as->parms[MRAFS_OFFSET + 13].items)
1568 mrafsParm.OptTraceBadLinkCounts = 1;
1569 if (as->parms[MRAFS_OFFSET + 14].items)
1570 mrafsParm.OptDontAskFS = 1;
1571 if (as->parms[MRAFS_OFFSET + 15].items)
1572 mrafsParm.OptLogLevel =
1573 atoi(as->parms[MRAFS_OFFSET + 15].items->data);
1574 if (as->parms[MRAFS_OFFSET + 16].items)
1575 mrafsParm.OptRxDebug = 1;
1576 if (as->parms[MRAFS_OFFSET + 17].items) {
1577 if (as->parms[MRAFS_OFFSET + 8].items
1578 || as->parms[MRAFS_OFFSET + 9].items) {
1580 ("Can't specify -Residencies with -SalvageRemote or -SalvageArchival\n");
1584 util_GetUInt32(as->parms[MRAFS_OFFSET + 17].items->data,
1585 &mrafsParm.OptResidencies);
1587 printf("bos: '%s' is not a valid residency mask.\n",
1588 as->parms[MRAFS_OFFSET + 13].items->data);
1595 for (i = MRAFS_OFFSET; i < ADDPARMOFFSET; i++) {
1596 if (as->parms[i].items) {
1597 printf(" %s only possible for MR-AFS fileserver.\n",
1606 if (as->parms[4].items) {
1607 /* salvage whole enchilada */
1608 curGoal = GetServerGoal(tconn, serviceName);
1609 if (curGoal == BSTAT_NORMAL) {
1610 printf("bos: shutting down '%s'.\n", serviceName);
1611 code = BOZO_SetTStatus(tconn, serviceName, BSTAT_SHUTDOWN);
1613 printf("bos: failed to stop '%s' (%s)\n", serviceName, em(code));
1616 code = BOZO_WaitAll(tconn); /* wait for shutdown to complete */
1619 ("bos: failed to wait for file server shutdown, continuing.\n");
1621 /* now do the salvage operation */
1622 printf("Starting salvage.\n");
1623 rc = DoSalvage(tconn, NULL, NULL, outName, showlog, parallel, tmpDir,
1624 orphans, dafs, &mrafsParm);
1625 if (curGoal == BSTAT_NORMAL) {
1626 printf("bos: restarting %s.\n", serviceName);
1627 code = BOZO_SetTStatus(tconn, serviceName, BSTAT_NORMAL);
1629 printf("bos: failed to restart '%s' (%s)\n", serviceName, em(code));
1635 } else if (!as->parms[2].items) {
1636 if (!as->parms[1].items) {
1638 ("bos: must specify -all switch to salvage all partitions.\n");
1641 if (volutil_GetPartitionID(as->parms[1].items->data) < 0) {
1642 /* can't parse volume ID, so complain before shutting down
1645 printf("bos: can't interpret %s as partition ID.\n",
1646 as->parms[1].items->data);
1649 curGoal = GetServerGoal(tconn, serviceName);
1650 /* salvage a whole partition (specified by parms[1]) */
1651 if (curGoal == BSTAT_NORMAL) {
1652 printf("bos: shutting down '%s'.\n", serviceName);
1653 code = BOZO_SetTStatus(tconn, serviceName, BSTAT_SHUTDOWN);
1655 printf("bos: can't stop '%s' (%s)\n", serviceName, em(code));
1658 code = BOZO_WaitAll(tconn); /* wait for shutdown to complete */
1661 ("bos: failed to wait for file server shutdown, continuing.\n");
1663 /* now do the salvage operation */
1664 printf("Starting salvage.\n");
1665 rc = DoSalvage(tconn, as->parms[1].items->data, NULL, outName,
1666 showlog, parallel, tmpDir, orphans, dafs, &mrafsParm);
1667 if (curGoal == BSTAT_NORMAL) {
1668 printf("bos: restarting '%s'.\n", serviceName);
1669 code = BOZO_SetTStatus(tconn, serviceName, BSTAT_NORMAL);
1671 printf("bos: failed to restart '%s' (%s)\n", serviceName, em(code));
1678 /* salvage individual volume (don't shutdown fs first), just use
1679 * single-shot cron bnode. Must leave server running when using this
1680 * option, since salvager will ask file server for the volume */
1683 const char *confdir;
1686 if (as->parms[ADDPARMOFFSET].items)
1687 tmpname = as->parms[ADDPARMOFFSET].items->data;
1691 localauth = (as->parms[ADDPARMOFFSET + 2].items != 0);
1693 (localauth ? AFSDIR_SERVER_ETC_DIRPATH :
1694 AFSDIR_CLIENT_ETC_DIRPATH);
1695 code = vsu_ClientInit( /* noauth */ 1, confdir, tmpname,
1696 /* server auth */ 0, &cstruct, (int (*)())0);
1698 newID = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
1700 printf("bos: can't interpret %s as volume name or ID\n",
1701 as->parms[2].items->data);
1704 sprintf(tname, "%u", newID);
1707 ("bos: can't initialize volume system client (code %d), trying anyway.\n",
1709 strncpy(tname, as->parms[2].items->data, sizeof(tname));
1711 if (volutil_GetPartitionID(as->parms[1].items->data) < 0) {
1712 /* can't parse volume ID, so complain before shutting down
1715 printf("bos: can't interpret %s as partition ID.\n",
1716 as->parms[1].items->data);
1719 printf("Starting salvage.\n");
1720 rc = DoSalvage(tconn, as->parms[1].items->data, tname, outName,
1721 showlog, parallel, tmpDir, orphans, dafs, &mrafsParm);
1729 IStatServer(struct cmd_syndesc *as, int int32p)
1731 struct rx_connection *tconn;
1732 struct cmd_item *ti;
1735 tconn = GetConn(as, 0);
1736 for (ti = as->parms[1].items; ti; ti = ti->next) {
1737 DoStat(ti->data, tconn, int32p, firstTime);
1744 DoStat(IN char *aname,
1745 IN struct rx_connection *aconn,
1747 IN int firstTime) /* true iff first instance in cmd */
1753 struct bozo_status istatus;
1755 char *is1, *is2, *is3, *is4; /* instance strings */
1758 code = BOZO_GetInstanceInfo(aconn, aname, &tp, &istatus);
1760 printf("bos: failed to get instance info for '%s' (%s)\n", aname,
1764 if (firstTime && aint32p && (istatus.flags & BOZO_BADDIRACCESS))
1766 ("Bosserver reports inappropriate access on server directories\n");
1767 printf("Instance %s, ", aname);
1769 printf("(type is %s) ", buffer);
1770 if (istatus.fileGoal == istatus.goal) {
1772 printf("disabled, ");
1774 if (istatus.fileGoal)
1775 printf("temporarily disabled, ");
1777 printf("temporarily enabled, ");
1780 if (istatus.flags & BOZO_ERRORSTOP)
1781 printf("stopped for too many errors, ");
1782 if (istatus.flags & BOZO_HASCORE)
1783 printf("has core file, ");
1786 code = BOZO_GetStatus(aconn, aname, &temp, &tp);
1788 printf("bos: failed to get status for instance '%s' (%s)\n", aname,
1791 printf("currently ");
1792 if (temp == BSTAT_NORMAL)
1793 printf("running normally.\n");
1794 else if (temp == BSTAT_SHUTDOWN)
1795 printf("shutdown.\n");
1796 else if (temp == BSTAT_STARTINGUP)
1797 printf("starting up.\n");
1798 else if (temp == BSTAT_SHUTTINGDOWN)
1799 printf("shutting down.\n");
1800 if (buffer[0] != 0) {
1801 printf(" Auxiliary status is: %s.\n", buffer);
1805 /* are we done yet? */
1809 if (istatus.procStartTime)
1810 printf(" Process last started at %s (%d proc starts)\n",
1811 DateOf(istatus.procStartTime), istatus.procStarts);
1812 if (istatus.lastAnyExit) {
1813 printf(" Last exit at %s\n", DateOf(istatus.lastAnyExit));
1815 if (istatus.lastErrorExit) {
1816 is1 = is2 = is3 = is4 = NULL;
1817 printf(" Last error exit at %s, ", DateOf(istatus.lastErrorExit));
1818 code = BOZO_GetInstanceStrings(aconn, aname, &is1, &is2, &is3, &is4);
1819 /* don't complain about failing call, since could simply mean
1820 * interface mismatch.
1824 /* non-null instance string */
1825 printf("by %s, ", is1);
1832 if (istatus.errorSignal) {
1833 if (istatus.errorSignal == SIGTERM)
1834 printf("due to shutdown request\n");
1836 printf("due to signal %d\n", istatus.errorSignal);
1838 printf("by exiting with code %d\n", istatus.errorCode);
1842 /* try to display all the parms */
1845 code = BOZO_GetInstanceParm(aconn, aname, i, &tp);
1848 printf(" Command %d is '%s'\n", i + 1, buffer);
1851 code = BOZO_GetInstanceParm(aconn, aname, 999, &tp);
1853 /* Any type of failure is treated as not having a notifier program */
1854 printf(" Notifier is '%s'\n", buffer);
1862 GetRestrict(struct cmd_syndesc *as, void *arock)
1864 struct rx_connection *tconn;
1865 afs_int32 code, val;
1867 tconn = GetConn(as, 0);
1868 code = BOZO_GetRestrictedMode(tconn, &val);
1870 printf("bos: failed to get restricted mode (%s)\n", em(code));
1872 printf("Restricted mode is %s\n", val ? "on" : "off");
1878 SetRestrict(struct cmd_syndesc *as, void *arock)
1880 struct rx_connection *tconn;
1881 afs_int32 code, val;
1883 tconn = GetConn(as, 0);
1884 util_GetInt32(as->parms[1].items->data, &val);
1885 code = BOZO_SetRestrictedMode(tconn, val);
1887 printf("bos: failed to set restricted mode (%s)\n", em(code));
1892 add_std_args(struct cmd_syndesc *ts)
1894 cmd_Seek(ts, ADDPARMOFFSET);
1895 /* + 0 */ cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");
1896 /* + 1 */ cmd_AddParm(ts, "-noauth", CMD_FLAG, CMD_OPTIONAL,
1897 "don't authenticate");
1898 /* + 2 */ cmd_AddParm(ts, "-localauth", CMD_FLAG, CMD_OPTIONAL,
1899 "create tickets from KeyFile");
1902 #include "AFS_component_version_number.c"
1905 main(int argc, char **argv)
1908 struct cmd_syndesc *ts;
1909 extern int afsconf_SawCell;
1911 #ifdef AFS_AIX32_ENV
1913 * The following signal action for AIX is necessary so that in case of a
1914 * crash (i.e. core is generated) we can include the user's data section
1915 * in the core dump. Unfortunately, by default, only a partial core is
1916 * generated which, in many cases, isn't too useful.
1918 struct sigaction nsa;
1920 sigemptyset(&nsa.sa_mask);
1921 nsa.sa_handler = SIG_DFL;
1922 nsa.sa_flags = SA_FULLDUMP;
1923 sigaction(SIGSEGV, &nsa, NULL);
1924 sigaction(SIGABRT, &nsa, NULL);
1930 printf("bos: could not initialize rx (%s)\n", em(code));
1934 /* To resolve a AFSCELL environment "Note: ..." problem: Because bos calls ka_Init (why?) before any
1935 * checkup on the existance of a "-cell" option on the particular bos command we don't print the
1936 * message if a cell is passed in. Luckily the rest of the programs don't call these adhoc routines
1937 * and things work fine. Note that if the "-cell" isn't passed then we're still ok since later on
1938 * the proper routine (afsconf_GetCellInfo) is going to be called to do the right thing.
1940 afsconf_SawCell = 1; /* Means don't print warning if AFSCELL is set */
1942 afsconf_SawCell = 0; /* Reset it */
1943 /* don't check error code, since fails sometimes when we're setting up a
1945 initialize_CMD_error_table();
1946 initialize_BZ_error_table();
1948 ts = cmd_CreateSyntax("start", StartServer, NULL, "start running a server");
1949 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1950 cmd_AddParm(ts, "-instance", CMD_LIST, 0, "server process name");
1953 ts = cmd_CreateSyntax("stop", StopServer, NULL, "halt a server instance");
1954 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1955 cmd_AddParm(ts, "-instance", CMD_LIST, 0, "server process name");
1957 cmd_AddParm(ts, "-wait", CMD_FLAG, CMD_OPTIONAL,
1958 "wait for process to stop");
1961 ts = cmd_CreateSyntax("status", StatServer, NULL,
1962 "show server instance status");
1963 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1964 cmd_AddParm(ts, "-instance", CMD_LIST, CMD_OPTIONAL,
1965 "server process name");
1966 cmd_AddParm(ts, "-long", CMD_FLAG, CMD_OPTIONAL, "long status");
1969 ts = cmd_CreateSyntax("shutdown", Shutdown, NULL, "shutdown all processes");
1970 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1971 cmd_AddParm(ts, "-instance", CMD_LIST, CMD_OPTIONAL, "instances");
1973 cmd_AddParm(ts, "-wait", CMD_FLAG, CMD_OPTIONAL,
1974 "wait for process to stop");
1977 ts = cmd_CreateSyntax("startup", Startup, NULL, "start all processes");
1978 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1979 cmd_AddParm(ts, "-instance", CMD_LIST, CMD_OPTIONAL, "instances");
1982 ts = cmd_CreateSyntax("restart", Restart, NULL, "restart processes");
1983 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1984 cmd_AddParm(ts, "-instance", CMD_LIST, CMD_OPTIONAL, "instances");
1985 cmd_AddParm(ts, "-bosserver", CMD_FLAG, CMD_OPTIONAL,
1986 "restart bosserver");
1987 cmd_AddParm(ts, "-all", CMD_FLAG, CMD_OPTIONAL, "restart all processes");
1992 ts = cmd_CreateSyntax("create", CreateServer, NULL,
1993 "create a new server instance");
1994 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1995 cmd_AddParm(ts, "-instance", CMD_SINGLE, 0, "server process name");
1996 cmd_AddParm(ts, "-type", CMD_SINGLE, 0, "server type");
1997 cmd_AddParm(ts, "-cmd", CMD_LIST, 0, "command lines");
1998 cmd_AddParm(ts, "-notifier", CMD_SINGLE, CMD_OPTIONAL,
1999 "Notifier program");
2002 ts = cmd_CreateSyntax("delete", DeleteServer, NULL,
2003 "delete a server instance");
2004 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2005 cmd_AddParm(ts, "-instance", CMD_LIST, 0, "server process name");
2008 ts = cmd_CreateSyntax("adduser", AddSUser, NULL,
2009 "add users to super-user list");
2010 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2011 cmd_AddParm(ts, "-user", CMD_LIST, 0, "user names");
2014 ts = cmd_CreateSyntax("removeuser", RemoveSUser, NULL,
2015 "remove users from super-user list");
2016 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2017 cmd_AddParm(ts, "-user", CMD_LIST, 0, "user names");
2020 ts = cmd_CreateSyntax("listusers", ListSUsers, NULL, "list super-users");
2021 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2024 ts = cmd_CreateSyntax("addkey", AddKey, NULL,
2025 "add keys to key dbase (kvno 999 is bcrypt)");
2026 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2027 cmd_AddParm(ts, "-key", CMD_SINGLE, CMD_OPTIONAL, "key");
2028 cmd_AddParm(ts, "-kvno", CMD_SINGLE, 0, "key version number");
2031 ts = cmd_CreateSyntax("removekey", RemoveKey, NULL,
2032 "remove keys from key dbase");
2033 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2034 cmd_AddParm(ts, "-kvno", CMD_LIST, 0, "key version number");
2037 ts = cmd_CreateSyntax("listkeys", ListKeys, NULL, "list keys");
2038 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2039 cmd_AddParm(ts, "-showkey", CMD_FLAG, CMD_OPTIONAL,
2040 "show the actual key rather than the checksum");
2043 ts = cmd_CreateSyntax("listhosts", ListHosts, NULL, "get cell host list");
2044 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2046 cmd_CreateAlias(ts, "getcell");
2048 ts = cmd_CreateSyntax("setcellname", SetCellName, NULL, "set cell name");
2049 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2050 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "cell name");
2053 ts = cmd_CreateSyntax("addhost", AddHost, NULL, "add host to cell dbase");
2054 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2055 cmd_AddParm(ts, "-host", CMD_LIST, 0, "host name");
2056 cmd_AddParm(ts, "-clone", CMD_FLAG, CMD_OPTIONAL, "vote doesn't count");
2059 ts = cmd_CreateSyntax("removehost", RemoveHost, NULL,
2060 "remove host from cell dbase");
2061 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2062 cmd_AddParm(ts, "-host", CMD_LIST, 0, "host name");
2065 ts = cmd_CreateSyntax("setauth", SetAuth, NULL,
2066 "set authentication required flag");
2067 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2068 cmd_AddParm(ts, "-authrequired", CMD_SINGLE, 0,
2069 "on or off: authentication required for admin requests");
2072 ts = cmd_CreateSyntax("install", Install, NULL, "install program");
2073 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2074 cmd_AddParm(ts, "-file", CMD_LIST, 0, "files to install");
2075 cmd_AddParm(ts, "-dir", CMD_SINGLE, CMD_OPTIONAL, "destination dir");
2078 ts = cmd_CreateSyntax("uninstall", UnInstall, NULL, "uninstall program");
2079 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2080 cmd_AddParm(ts, "-file", CMD_LIST, 0, "files to uninstall");
2081 cmd_AddParm(ts, "-dir", CMD_SINGLE, CMD_OPTIONAL, "destination dir");
2084 ts = cmd_CreateSyntax("getlog", GetLogCmd, NULL, "examine log file");
2085 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2086 cmd_AddParm(ts, "-file", CMD_SINGLE, 0, "log file to examine");
2089 ts = cmd_CreateSyntax("getdate", GetDate, NULL, "get dates for programs");
2090 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2091 cmd_AddParm(ts, "-file", CMD_LIST, 0, "files to check");
2092 cmd_AddParm(ts, "-dir", CMD_SINGLE, CMD_OPTIONAL, "destination dir");
2095 ts = cmd_CreateSyntax("exec", Exec, NULL, "execute shell command on server");
2096 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2097 cmd_AddParm(ts, "-cmd", CMD_SINGLE, 0, "command to execute");
2100 ts = cmd_CreateSyntax("prune", Prune, NULL, "prune server files");
2101 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2102 cmd_AddParm(ts, "-bak", CMD_FLAG, CMD_OPTIONAL, "delete .BAK files");
2103 cmd_AddParm(ts, "-old", CMD_FLAG, CMD_OPTIONAL, "delete .OLD files");
2104 cmd_AddParm(ts, "-core", CMD_FLAG, CMD_OPTIONAL, "delete core files");
2105 cmd_AddParm(ts, "-all", CMD_FLAG, CMD_OPTIONAL, "delete all junk files");
2108 ts = cmd_CreateSyntax("setrestart", SetRestartCmd, NULL,
2109 "set restart times");
2110 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_REQUIRED, "machine name");
2111 cmd_AddParm(ts, "-time", CMD_SINGLE, CMD_REQUIRED,
2112 "time to restart server");
2113 cmd_AddParm(ts, "-general", CMD_FLAG, CMD_OPTIONAL,
2114 "set general restart time");
2115 cmd_AddParm(ts, "-newbinary", CMD_FLAG, CMD_OPTIONAL,
2116 "set new binary restart time");
2118 cmd_CreateAlias(ts, "setr");
2120 ts = cmd_CreateSyntax("getrestart", GetRestartCmd, NULL,
2121 "get restart times");
2122 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_REQUIRED, "machine name");
2124 cmd_CreateAlias(ts, "getr");
2126 ts = cmd_CreateSyntax("salvage", SalvageCmd, NULL,
2127 "salvage partition or volumes");
2128 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2129 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL,
2130 "salvage partition");
2131 cmd_AddParm(ts, "-volume", CMD_SINGLE, CMD_OPTIONAL,
2132 "salvage volume number or volume name");
2133 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL,
2134 "salvage log output file");
2135 cmd_AddParm(ts, "-all", CMD_FLAG, CMD_OPTIONAL, "salvage whole server");
2136 cmd_AddParm(ts, "-showlog", CMD_FLAG, CMD_OPTIONAL,
2137 "display salvage log");
2138 cmd_AddParm(ts, "-parallel", CMD_SINGLE, CMD_OPTIONAL,
2139 "# of max parallel partition salvaging");
2140 cmd_AddParm(ts, "-tmpdir", CMD_SINGLE, CMD_OPTIONAL,
2141 "directory to place tmp files");
2142 cmd_AddParm(ts, "-orphans", CMD_SINGLE, CMD_OPTIONAL,
2143 "ignore | remove | attach");
2144 cmd_AddParm(ts, "-forceDAFS", CMD_FLAG, CMD_OPTIONAL,
2145 "(DAFS) force salvage of demand attach fileserver");
2146 cmd_AddParm(ts, "-debug", CMD_FLAG, CMD_OPTIONAL,
2147 "(MR-AFS) Run in Debugging mode");
2148 cmd_AddParm(ts, "-nowrite", CMD_FLAG, CMD_OPTIONAL,
2149 "(MR-AFS) Run readonly/test mode");
2150 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL,
2151 "(MR-AFS) Force full salvaging");
2152 cmd_AddParm(ts, "-oktozap", CMD_FLAG, CMD_OPTIONAL,
2153 "(MR-AFS) Give permission to destroy bogus file residencies/volumes - debugging flag");
2154 cmd_AddParm(ts, "-rootfiles", CMD_FLAG, CMD_OPTIONAL,
2155 "(MR-AFS) Show files owned by root - debugging flag");
2156 cmd_AddParm(ts, "-salvagedirs", CMD_FLAG, CMD_OPTIONAL,
2157 "(MR-AFS) Force rebuild/salvage of all directories");
2158 cmd_AddParm(ts, "-blockreads", CMD_FLAG, CMD_OPTIONAL,
2159 "(MR-AFS) Read smaller blocks to handle IO/bad blocks");
2160 cmd_AddParm(ts, "-ListResidencies", CMD_FLAG, CMD_OPTIONAL,
2161 "(MR-AFS) Just list affected file residencies - debugging flag");
2162 cmd_AddParm(ts, "-SalvageRemote", CMD_FLAG, CMD_OPTIONAL,
2163 "(MR-AFS) Salvage storage systems that are not directly attached");
2164 cmd_AddParm(ts, "-SalvageArchival", CMD_FLAG, CMD_OPTIONAL,
2165 "(MR-AFS) Salvage HSM storage systems");
2166 cmd_AddParm(ts, "-IgnoreCheck", CMD_FLAG, CMD_OPTIONAL,
2167 "(MR-AFS) Don't perform VLDB safety check when deleting unreferenced files. Only a good idea in single server cell.");
2168 cmd_AddParm(ts, "-ForceOnLine", CMD_FLAG, CMD_OPTIONAL,
2169 "(MR-AFS) Force the volume to come online, even if it hasn't salvaged cleanly.");
2170 cmd_AddParm(ts, "-UseRootDirACL", CMD_FLAG, CMD_OPTIONAL,
2171 "(MR-AFS) Use the root directory ACL for lost+found directory if it is created.");
2172 cmd_AddParm(ts, "-TraceBadLinkCounts", CMD_FLAG, CMD_OPTIONAL,
2173 "(MR-AFS) Print out lines about volume reference count changes.");
2174 cmd_AddParm(ts, "-DontAskFS", CMD_FLAG, CMD_OPTIONAL,
2175 "(MR-AFS) Don't ask fileserver to take volume offline. THIS IS VERY DANGEROUS.");
2176 cmd_AddParm(ts, "-LogLevel", CMD_SINGLE, CMD_OPTIONAL,
2177 "(MR-AFS) log level");
2178 cmd_AddParm(ts, "-rxdebug", CMD_FLAG, CMD_OPTIONAL,
2179 "(MR-AFS) Write out rx debug information.");
2180 cmd_AddParm(ts, "-Residencies", CMD_SINGLE, CMD_OPTIONAL,
2181 "(MR-AFS) Numeric mask of residencies to be included in the salvage. Do not use with -SalvageRemote or -SalvageArchival");
2184 ts = cmd_CreateSyntax("blockscanner", BlockScannerCmd, NULL,
2185 "block scanner daemon from making migration requests");
2186 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_REQUIRED, "machine name");
2189 ts = cmd_CreateSyntax("unblockscanner", UnBlockScannerCmd, NULL,
2190 "allow scanner daemon to make migration requests again");
2191 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_REQUIRED, "machine name");
2194 ts = cmd_CreateSyntax("getrestricted", GetRestrict, NULL,
2195 "get restrict mode");
2196 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2199 ts = cmd_CreateSyntax("setrestricted", SetRestrict, NULL,
2200 "set restrict mode");
2201 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2202 cmd_AddParm(ts, "-mode", CMD_SINGLE, 0, "mode to set");
2206 code = cmd_Dispatch(argc, argv);