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>
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(register struct cmd_syndesc *as, int int32p);
54 static int DoStat(char *aname, register struct rx_connection *aconn,
55 int aint32p, int firstTime);
59 /* command offsets for bos salvage command */
60 #define MRAFS_OFFSET 10
61 #define ADDPARMOFFSET 27
63 /* MR-AFS salvage parameters */
64 struct MRAFSSalvageParms {
69 afs_int32 Optrootfiles;
70 afs_int32 Optsalvagedirs;
71 afs_int32 Optblockreads;
72 afs_int32 OptListResidencies;
73 afs_int32 OptSalvageRemote;
74 afs_int32 OptSalvageArchival;
75 afs_int32 OptIgnoreCheck;
76 afs_int32 OptForceOnLine;
77 afs_int32 OptUseRootDirACL;
78 afs_int32 OptTraceBadLinkCounts;
79 afs_int32 OptDontAskFS;
80 afs_int32 OptLogLevel;
82 afs_uint32 OptResidencies;
85 /* dummy routine for the audit work. It should do nothing since audits */
86 /* occur at the server level and bos is not a server. */
92 /* keep those lines small */
97 return "communications failure (-1)";
99 return "communications timeout (-3)";
101 return (char *)afs_error_message(acode);
104 /* get partition id from a name */
105 /* XXX - unused code - could be removed? */
108 GetPartitionID(char *aname)
115 return -1; /* unknown */
116 /* numbers go straight through */
117 if (tc >= '0' && tc <= '9') {
120 /* otherwise check for vicepa or /vicepa, or just plain "a" */
122 if (strlen(aname) <= 2) {
123 strcpy(ascii, aname);
124 } else if (!strncmp(aname, "/vicep", 6)) {
125 strncpy(ascii, aname + 6, 2);
126 } else if (!strncmp(aname, "vicep", 5)) {
127 strncpy(ascii, aname + 5, 2);
129 return -1; /* bad partition name */
130 /* now partitions are named /vicepa ... /vicepz, /vicepaa, /vicepab,
131 * .../vicepzz, and are numbered from 0. Do the appropriate conversion */
133 /* one char name, 0..25 */
134 if (ascii[0] < 'a' || ascii[0] > 'z')
135 return -1; /* wrongo */
136 return ascii[0] - 'a';
138 /* two char name, 26 .. <whatever> */
139 if (ascii[0] < 'a' || ascii[0] > 'z')
140 return -1; /* wrongo */
141 if (ascii[1] < 'a' || ascii[1] > 'z')
142 return -1; /* just as bad */
143 return (ascii[0] - 'a') * 26 + (ascii[1] - 'a') + 26;
148 /* make ctime easier to use */
150 DateOf(afs_int32 atime)
152 static char tbuffer[30];
154 time_t t = (time_t) atime;
158 tbuffer[24] = 0; /* get rid of new line */
160 strcpy(tbuffer, "BAD TIME");
164 /* global stuff from main for communicating with GetConn */
165 static struct rx_securityClass *sc[3];
168 /* use the syntax descr to get a connection, authenticated appropriately.
169 * aencrypt is set if we want to encrypt the data on the wire.
171 static struct rx_connection *
172 GetConn(struct cmd_syndesc *as, int aencrypt)
176 register afs_int32 code;
177 register struct rx_connection *tconn;
179 register struct afsconf_dir *tdir;
181 struct ktc_principal sname;
182 struct ktc_token ttoken;
186 hostname = as->parms[0].items->data;
187 th = hostutil_GetHostByName(hostname);
189 printf("bos: can't find address for host '%s'\n", hostname);
192 memcpy(&addr, th->h_addr, sizeof(afs_int32));
194 /* get tokens for making authenticated connections */
195 localauth = (as->parms[ADDPARMOFFSET + 2].items != 0);
197 (localauth ? AFSDIR_SERVER_ETC_DIRPATH : AFSDIR_CLIENT_ETC_DIRPATH);
198 tdir = afsconf_Open(confdir);
200 struct afsconf_cell info;
203 if (as->parms[ADDPARMOFFSET].items)
204 tname = as->parms[ADDPARMOFFSET].items->data;
207 /* next call expands cell name abbrevs for us and handles looking up
209 code = afsconf_GetCellInfo(tdir, tname, NULL, &info);
211 afs_com_err("bos", code, "(can't find cell '%s' in cell database)",
212 (tname ? tname : "<default>"));
215 strcpy(sname.cell, info.name);
217 printf("bos: can't open cell database (%s)\n", confdir);
220 sname.instance[0] = 0;
221 strcpy(sname.name, "afs");
222 sc[0] = rxnull_NewClientSecurityObject();
227 if (!as->parms[ADDPARMOFFSET + 1].items) { /* not -noauth */
228 if (as->parms[ADDPARMOFFSET + 2].items) { /* -localauth */
229 code = afsconf_GetLatestKey(tdir, 0, 0);
231 afs_com_err("bos", code, "(getting key from local KeyFile)");
234 code = afsconf_ClientAuthSecure(tdir, &sc[2], &scIndex);
236 code = afsconf_ClientAuth(tdir, &sc[2], &scIndex);
238 afs_com_err("bos", code, "(calling ClientAuth)");
239 else if (scIndex != 2) /* this shouldn't happen */
242 } else { /* not -localauth, check for tickets */
243 code = ktc_GetToken(&sname, &ttoken, sizeof(ttoken), NULL);
245 /* have tickets, will travel */
246 if (ttoken.kvno >= 0 && ttoken.kvno <= 256);
249 "bos: funny kvno (%d) in ticket, proceeding\n",
254 encryptLevel = rxkad_crypt;
256 encryptLevel = rxkad_clear;
257 sc[2] = (struct rx_securityClass *)
258 rxkad_NewClientSecurityObject(encryptLevel,
265 afs_com_err("bos", code, "(getting tickets)");
267 if ((scIndex == 0) || (sc[scIndex] == 0)) {
268 fprintf(stderr, "bos: running unauthenticated\n");
273 rx_NewConnection(addr, htons(AFSCONF_NANNYPORT), 1, sc[scIndex],
276 fprintf(stderr, "bos: could not create rx connection\n");
279 rxs_Release(sc[scIndex]);
285 SetAuth(struct cmd_syndesc *as, void *arock)
287 register afs_int32 code;
288 register struct rx_connection *tconn;
292 tconn = GetConn(as, 0);
293 tp = as->parms[1].items->data;
294 if (strcmp(tp, "on") == 0)
295 flag = 0; /* auth req.: noauthflag is false */
296 else if (strcmp(tp, "off") == 0)
300 ("bos: illegal authentication specifier '%s', must be 'off' or 'on'.\n",
304 code = BOZO_SetNoAuthFlag(tconn, flag);
306 afs_com_err("bos", code, "(failed to set authentication flag)");
310 /* take a name (e.g. foo/bar, and a dir e.g. /usr/afs/bin, and construct
311 * /usr/afs/bin/bar */
313 ComputeDestDir(char *aname, char *adir, char *aresult, afs_int32 alen)
317 strcpy(aresult, adir);
318 tp = strrchr(aname, '/');
321 strcat(aresult, "/");
322 strcat(aresult, aname);
324 /* tp points at the / character */
330 /* copy data from fd afd to rx call acall */
332 CopyBytes(int afd, register struct rx_call *acall)
334 register afs_int32 code;
335 register afs_int32 len;
339 len = read(afd, tbuffer, sizeof(tbuffer));
343 return 0; /* all done */
344 code = rx_Write(acall, tbuffer, len);
351 Prune(register struct cmd_syndesc *as, void *arock)
353 register afs_int32 code;
354 register struct rx_connection *tconn;
355 register afs_int32 flags;
357 tconn = GetConn(as, 0);
359 if (as->parms[1].items)
360 flags |= BOZO_PRUNEBAK;
361 if (as->parms[2].items)
362 flags |= BOZO_PRUNEOLD;
363 if (as->parms[3].items)
364 flags |= BOZO_PRUNECORE;
365 if (as->parms[4].items)
367 code = BOZO_Prune(tconn, flags);
369 afs_com_err("bos", code, "(failed to prune server files)");
374 Exec(register struct cmd_syndesc *as, void *arock)
376 register struct rx_connection *tconn;
377 register afs_int32 code;
379 tconn = GetConn(as, 0);
380 code = BOZO_Exec(tconn, as->parms[1].items->data);
382 printf("bos: failed to execute command (%s)\n", em(code));
387 GetDate(register struct cmd_syndesc *as, void *arock)
389 register afs_int32 code;
392 afs_int32 time, bakTime, oldTime;
393 register struct rx_connection *tconn;
394 register struct cmd_item *ti;
396 tconn = GetConn(as, 0);
397 if (!as->parms[1].items) {
398 printf("bos: no files to check\n");
402 /* compute dest dir or file; default MUST be canonical form of dir path */
403 if (as->parms[2].items)
404 strcpy(destDir, as->parms[2].items->data);
406 strcpy(destDir, AFSDIR_CANONICAL_SERVER_BIN_DIRPATH);
408 for (ti = as->parms[1].items; ti; ti = ti->next) {
409 /* check date for each file */
410 ComputeDestDir(ti->data, destDir, tbuffer, sizeof(tbuffer));
411 code = BOZO_GetDates(tconn, tbuffer, &time, &bakTime, &oldTime);
413 printf("bos: failed to check date on %s (%s)\n", ti->data,
417 printf("File %s ", tbuffer);
419 printf("does not exist, ");
421 printf("dated %s, ", DateOf(time));
423 printf("no .BAK file, ");
425 printf(".BAK file dated %s, ", DateOf(bakTime));
427 printf("no .OLD file.");
429 printf(".OLD file dated %s.", DateOf(oldTime));
437 UnInstall(register struct cmd_syndesc *as, void *arock)
439 register afs_int32 code;
442 register struct cmd_item *ti;
443 register struct rx_connection *tconn;
445 tconn = GetConn(as, 0);
446 if (!as->parms[1].items) {
447 printf("bos: no files to uninstall\n");
451 /* compute dest dir or file; default MUST be canonical form of dir path */
452 if (as->parms[2].items)
453 strcpy(destDir, as->parms[2].items->data);
455 strcpy(destDir, AFSDIR_CANONICAL_SERVER_BIN_DIRPATH);
457 for (ti = as->parms[1].items; ti; ti = ti->next) {
458 /* uninstall each file */
459 ComputeDestDir(ti->data, destDir, tbuffer, sizeof(tbuffer));
460 code = BOZO_UnInstall(tconn, tbuffer);
462 printf("bos: failed to uninstall %s (%s)\n", ti->data, em(code));
465 printf("bos: uninstalled file %s\n", ti->data);
471 GetServerGoal(struct rx_connection *aconn, char *aname)
475 register afs_int32 code;
476 struct bozo_status istatus;
479 code = BOZO_GetInstanceInfo(aconn, aname, &tp, &istatus);
481 printf("bos: failed to get instance info for '%s' (%s)\n", aname,
483 /* if we can't get the answer, assume its running */
486 if (istatus.goal == 0)
487 return BSTAT_SHUTDOWN;
493 Install(struct cmd_syndesc *as, void *arock)
495 struct rx_connection *tconn;
496 register afs_int32 code;
497 register struct cmd_item *ti;
501 struct rx_call *tcall;
504 tconn = GetConn(as, 0);
505 if (!as->parms[1].items) {
506 printf("bos: no files to install\n");
510 /* compute dest dir or file; default MUST be canonical form of dir path */
511 if (as->parms[2].items)
512 strcpy(destDir, as->parms[2].items->data);
514 strcpy(destDir, AFSDIR_CANONICAL_SERVER_BIN_DIRPATH);
516 for (ti = as->parms[1].items; ti; ti = ti->next) {
517 /* install each file */
518 fd = open(ti->data, O_RDONLY);
520 /* better to quit on error than continue for install command */
521 printf("bos: can't find file '%s', quitting\n", ti->data);
524 code = fstat(fd, &tstat);
526 printf("bos: failed to stat file %s, errno is %d\n", ti->data,
530 /* compute destination dir */
531 ComputeDestDir(ti->data, destDir, tbuffer, sizeof(tbuffer));
532 tcall = rx_NewCall(tconn);
534 StartBOZO_Install(tcall, tbuffer, tstat.st_size,
535 (afs_int32) tstat.st_mode, tstat.st_mtime);
537 code = CopyBytes(fd, tcall);
539 code = rx_EndCall(tcall, code);
541 printf("bos: failed to install %s (%s)\n", ti->data, em(code));
544 printf("bos: installed file %s\n", ti->data);
550 Shutdown(struct cmd_syndesc *as, void *arock)
552 register struct rx_connection *tconn;
553 register afs_int32 code;
554 register struct cmd_item *ti;
556 tconn = GetConn(as, 0);
557 if (as->parms[1].items == 0) {
558 code = BOZO_ShutdownAll(tconn);
560 printf("bos: failed to shutdown servers (%s)\n", em(code));
562 for (ti = as->parms[1].items; ti; ti = ti->next) {
563 code = BOZO_SetTStatus(tconn, ti->data, BSTAT_SHUTDOWN);
565 printf("bos: failed to shutdown instance %s (%s)\n", ti->data,
569 if (as->parms[8].items) {
570 code = BOZO_WaitAll(tconn);
572 printf("bos: can't wait for processes to shutdown (%s)\n",
579 BlockScannerCmd(struct cmd_syndesc *as, void *arock)
581 register afs_int32 code;
582 struct rx_connection *tconn;
583 char BlockCommand[] = "/usr/afs/bin/scanner -block";
585 tconn = GetConn(as, 0);
586 code = BOZO_Exec(tconn, BlockCommand);
589 ("bos: failed to block scanner from making migration requests (%s)\n",
595 UnBlockScannerCmd(struct cmd_syndesc *as, void *arock)
597 register afs_int32 code;
598 struct rx_connection *tconn;
599 char UnBlockCommand[] = "/usr/afs/bin/scanner -unblock";
601 tconn = GetConn(as, 0);
602 code = BOZO_Exec(tconn, UnBlockCommand);
605 ("bos: failed to allow scanner daemon to make migration requests again (%s)\n",
611 GetRestartCmd(struct cmd_syndesc *as, void *arock)
613 register afs_int32 code;
614 struct ktime generalTime, newBinaryTime;
615 char messageBuffer[256];
616 struct rx_connection *tconn;
619 hostp = as->parms[0].items->data; /* host name for messages */
620 tconn = GetConn(as, 0);
622 code = BOZO_GetRestartTime(tconn, 1, (struct bozo_netKTime *) &generalTime);
624 printf("bos: failed to retrieve restart information (%s)\n",
628 code = BOZO_GetRestartTime(tconn, 2, (struct bozo_netKTime *) &newBinaryTime);
630 printf("bos: failed to retrieve restart information (%s)\n",
635 code = ktime_DisplayString(&generalTime, messageBuffer);
637 printf("bos: failed to decode restart time (%s)\n", em(code));
640 printf("Server %s restarts %s\n", hostp, messageBuffer);
642 code = ktime_DisplayString(&newBinaryTime, messageBuffer);
644 printf("bos: failed to decode restart time (%s)\n", em(code));
647 printf("Server %s restarts for new binaries %s\n", hostp, messageBuffer);
654 SetRestartCmd(struct cmd_syndesc *as, void *arock)
657 register afs_int32 code;
658 struct ktime restartTime;
660 struct rx_connection *tconn;
663 tconn = GetConn(as, 0);
664 if (as->parms[2].items) {
668 if (as->parms[3].items) {
673 printf("bos: can't specify more than one restart time at a time\n");
677 type = 1; /* by default set general restart time */
679 if ((code = ktime_ParsePeriodic(as->parms[1].items->data, &restartTime))) {
680 printf("bos: failed to parse '%s' as periodic restart time(%s)\n",
681 as->parms[1].items->data, em(code));
685 code = BOZO_SetRestartTime(tconn, type, (struct bozo_netKTime *) &restartTime);
687 printf("bos: failed to set restart time at server (%s)\n", em(code));
694 Startup(struct cmd_syndesc *as, void *arock)
696 register struct rx_connection *tconn;
697 register afs_int32 code;
698 register struct cmd_item *ti;
700 tconn = GetConn(as, 0);
701 if (as->parms[1].items == 0) {
702 code = BOZO_StartupAll(tconn);
704 printf("bos: failed to startup servers (%s)\n", em(code));
706 for (ti = as->parms[1].items; ti; ti = ti->next) {
707 code = BOZO_SetTStatus(tconn, ti->data, BSTAT_NORMAL);
709 printf("bos: failed to start instance %s (%s)\n", ti->data,
717 Restart(struct cmd_syndesc *as, void *arock)
719 register struct rx_connection *tconn;
720 register afs_int32 code;
721 register struct cmd_item *ti;
723 tconn = GetConn(as, 0);
724 if (as->parms[2].items) {
725 /* this is really a rebozo command */
726 if (as->parms[1].items) {
727 /* specified specific things to restart, can't do this at the same
730 ("bos: can't specify both '-bos' and specific servers to restart.\n");
733 /* otherwise do a rebozo */
734 code = BOZO_ReBozo(tconn);
736 printf("bos: failed to restart bosserver (%s)\n", em(code));
739 if (as->parms[1].items == 0) {
740 if (as->parms[3].items) { /* '-all' */
741 code = BOZO_RestartAll(tconn);
743 printf("bos: failed to restart servers (%s)\n", em(code));
745 printf("bos: To restart all processes please specify '-all'\n");
747 if (as->parms[3].items) {
748 printf("bos: Can't use '-all' along with individual instances\n");
750 for (ti = as->parms[1].items; ti; ti = ti->next) {
751 code = BOZO_Restart(tconn, ti->data);
753 printf("bos: failed to restart instance %s (%s)\n",
762 SetCellName(struct cmd_syndesc *as, void *arock)
764 register struct rx_connection *tconn;
765 register afs_int32 code;
767 tconn = GetConn(as, 0);
768 code = BOZO_SetCellName(tconn, as->parms[1].items->data);
770 printf("bos: failed to set cell (%s)\n", em(code));
775 AddHost(register struct cmd_syndesc *as, void *arock)
777 register struct rx_connection *tconn;
778 register afs_int32 code;
779 register struct cmd_item *ti;
780 char name[MAXHOSTCHARS];
782 tconn = GetConn(as, 0);
783 for (ti = as->parms[1].items; ti; ti = ti->next) {
784 if (as->parms[2].items) {
785 if (strlen(ti->data) > MAXHOSTCHARS - 3) {
786 fprintf(stderr, "bos: host name too long\n");
790 strcpy(&name[1], ti->data);
791 strcat((char *)&name, "]");
792 code = BOZO_AddCellHost(tconn, name);
794 code = BOZO_AddCellHost(tconn, ti->data);
796 printf("bos: failed to add host %s (%s)\n", ti->data, em(code));
802 RemoveHost(register struct cmd_syndesc *as, void *arock)
804 register struct rx_connection *tconn;
805 register afs_int32 code;
806 register struct cmd_item *ti;
808 tconn = GetConn(as, 0);
809 for (ti = as->parms[1].items; ti; ti = ti->next) {
810 code = BOZO_DeleteCellHost(tconn, ti->data);
812 printf("bos: failed to delete host %s (%s)\n", ti->data,
819 ListHosts(register struct cmd_syndesc *as, void *arock)
821 register struct rx_connection *tconn;
822 register afs_int32 code;
825 register afs_int32 i;
828 tconn = GetConn(as, 0);
829 code = BOZO_GetCellName(tconn, &tp);
831 printf("bos: failed to get cell name (%s)\n", em(code));
834 printf("Cell name is %s\n", tbuffer);
836 code = BOZO_GetCellHost(tconn, i, &tp);
840 printf("bos: failed to get cell host %d (%s)\n", i, em(code));
843 printf(" Host %d is %s\n", i + 1, tbuffer);
849 AddKey(register struct cmd_syndesc *as, void *arock)
851 register struct rx_connection *tconn;
852 register afs_int32 code;
853 struct ktc_encryptionKey tkey;
856 char cellBuffer[256];
857 char buf[BUFSIZ], ver[BUFSIZ];
859 tconn = GetConn(as, 1);
860 memset(&tkey, 0, sizeof(struct ktc_encryptionKey));
862 if (as->parms[1].items)
863 strcpy(buf, as->parms[1].items->data);
866 code = des_read_pw_string(buf, sizeof(buf), "input key: ", 0);
867 if (code || strlen(buf) == 0) {
868 fprintf(stderr, "Bad key: \n");
871 code = des_read_pw_string(ver, sizeof(ver), "Retype input key: ", 0);
872 if (code || strlen(ver) == 0) {
873 fprintf(stderr, "Bad key: \n");
876 if (strcmp(ver, buf) != 0) {
877 fprintf(stderr, "\nInput key mismatch\n");
883 temp = atoi(as->parms[2].items->data);
887 strcpy((char *)&tkey, as->parms[1].items->data);
889 strcpy((char *)&tkey, buf);
890 } else { /* kerberos key */
891 if (as->parms[ADDPARMOFFSET].items) {
892 strcpy(cellBuffer, as->parms[ADDPARMOFFSET].items->data);
894 /* string to key needs upper-case cell names */
896 /* I don't believe this is true. The string to key function
897 * actually expands the cell name, then LOWER-CASES it. Perhaps it
898 * didn't use to??? */
899 ucstring(cellBuffer, cellBuffer, strlen(cellBuffer));
902 tcell = NULL; /* no cell specified, use current */
904 ka_StringToKey(as->parms[1].items->data, tcell, &tkey);
906 ka_StringToKey(buf, tcell, &tkey);
908 tconn = GetConn(as, 1);
909 code = BOZO_AddKey(tconn, temp, &tkey);
911 printf("bos: failed to set key %d (%s)\n", temp, em(code));
918 RemoveKey(register struct cmd_syndesc *as, void *arock)
920 register struct rx_connection *tconn;
921 register afs_int32 code;
923 register struct cmd_item *ti;
925 tconn = GetConn(as, 0);
926 for (ti = as->parms[1].items; ti; ti = ti->next) {
927 temp = atoi(ti->data);
928 code = BOZO_DeleteKey(tconn, temp);
930 printf("bos: failed to delete key %d (%s)\n", temp, em(code));
938 ListKeys(register struct cmd_syndesc *as, void *arock)
940 register struct rx_connection *tconn;
941 register afs_int32 code;
942 struct ktc_encryptionKey tkey;
944 struct bozo_keyInfo keyInfo;
946 register afs_int32 i;
948 tconn = GetConn(as, 1);
951 code = BOZO_ListKeys(tconn, i, &kvno, &tkey, &keyInfo);
955 /* first check if key is returned */
956 if ((!ka_KeyIsZero(&tkey, sizeof(tkey))) && (as->parms[1].items)) {
957 printf("key %d is '", kvno);
958 ka_PrintBytes(&tkey, sizeof(tkey));
961 if (keyInfo.keyCheckSum == 0) /* shouldn't happen */
962 printf("key version is %d\n", kvno);
964 printf("key %d has cksum %u\n", kvno, keyInfo.keyCheckSum);
968 printf("Keys last changed on %s.\n", DateOf(keyInfo.mod_sec));
971 printf("bos: %s error encountered while listing keys\n", em(code));
973 printf("All done.\n");
978 AddSUser(register struct cmd_syndesc *as, void *arock)
980 register struct rx_connection *tconn;
981 register afs_int32 code;
983 register struct cmd_item *ti;
986 tconn = GetConn(as, 0);
987 for (ti = as->parms[1].items; ti; ti = ti->next) {
988 code = BOZO_AddSUser(tconn, ti->data);
990 printf("bos: failed to add user '%s' (%s)\n", ti->data, em(code));
998 RemoveSUser(register struct cmd_syndesc *as, void *arock)
1000 register struct rx_connection *tconn;
1001 register struct cmd_item *ti;
1002 register afs_int32 code;
1006 tconn = GetConn(as, 0);
1007 for (ti = as->parms[1].items; ti; ti = ti->next) {
1008 code = BOZO_DeleteSUser(tconn, ti->data);
1010 printf("bos: failed to delete user '%s', ", ti->data);
1012 printf("(no such user)\n");
1014 printf("(%s)\n", em(code));
1021 #define NPERLINE 10 /* dudes to print per line */
1023 ListSUsers(register struct cmd_syndesc *as, void *arock)
1025 register struct rx_connection *tconn;
1027 register afs_int32 code;
1030 int lastNL, printGreeting;
1032 tconn = GetConn(as, 0);
1037 code = BOZO_ListSUsers(tconn, i, &tp);
1040 if (printGreeting) {
1041 printGreeting = 0; /* delay until after first call succeeds */
1042 printf("SUsers are: ");
1044 printf("%s ", tbuffer);
1045 if ((i % NPERLINE) == NPERLINE - 1) {
1052 /* a real error code, instead of scanned past end */
1053 printf("bos: failed to retrieve super-user list (%s)\n", em(code));
1062 StatServer(register struct cmd_syndesc *as, void *arock)
1064 register struct rx_connection *tconn;
1065 register afs_int32 code;
1067 char ibuffer[BOZO_BSSIZE];
1071 /* int32p==1 is obsolete, smaller, printout */
1072 int32p = (as->parms[2].items != 0 ? 2 : 0);
1074 /* no parms does something pretty different */
1075 if (as->parms[1].items)
1076 return IStatServer(as, int32p);
1078 tconn = GetConn(as, 0);
1080 /* for each instance */
1082 code = BOZO_EnumerateInstance(tconn, i, &tp);
1086 printf("bos: failed to contact host's bosserver (%s).\n",
1090 DoStat(ibuffer, tconn, int32p, (i == 0)); /* print status line */
1096 CreateServer(register struct cmd_syndesc *as, void *arock)
1098 register struct rx_connection *tconn;
1099 register afs_int32 code;
1101 register struct cmd_item *ti;
1103 char *type, *name, *notifier = NONOTIFIER;
1105 tconn = GetConn(as, 0);
1106 for (i = 0; i < 6; i++)
1108 for (i = 0, ti = as->parms[3].items; (ti && i < 6); ti = ti->next, i++) {
1109 parms[i] = ti->data;
1111 name = as->parms[1].items->data;
1112 type = as->parms[2].items->data;
1113 if ((ti = as->parms[4].items)) {
1114 notifier = ti->data;
1117 BOZO_CreateBnode(tconn, type, name, parms[0], parms[1], parms[2],
1118 parms[3], parms[4], notifier);
1121 ("bos: failed to create new server instance %s of type '%s' (%s)\n",
1122 name, type, em(code));
1128 DeleteServer(register struct cmd_syndesc *as, void *arock)
1130 register struct rx_connection *tconn;
1131 register afs_int32 code;
1132 register struct cmd_item *ti;
1135 tconn = GetConn(as, 0);
1136 for (ti = as->parms[1].items; ti; ti = ti->next) {
1137 code = BOZO_DeleteBnode(tconn, ti->data);
1140 printf("bos: can't delete running instance '%s'\n", ti->data);
1142 printf("bos: failed to delete instance '%s' (%s)\n", ti->data,
1150 StartServer(register struct cmd_syndesc *as, void *arock)
1152 register struct rx_connection *tconn;
1153 register afs_int32 code;
1154 register struct cmd_item *ti;
1157 tconn = GetConn(as, 0);
1158 for (ti = as->parms[1].items; ti; ti = ti->next) {
1159 code = BOZO_SetStatus(tconn, ti->data, BSTAT_NORMAL);
1161 printf("bos: failed to start instance '%s' (%s)\n", ti->data,
1168 StopServer(register struct cmd_syndesc *as, void *arock)
1170 register struct rx_connection *tconn;
1171 register afs_int32 code;
1172 register struct cmd_item *ti;
1175 tconn = GetConn(as, 0);
1176 for (ti = as->parms[1].items; ti; ti = ti->next) {
1177 code = BOZO_SetStatus(tconn, ti->data, BSTAT_SHUTDOWN);
1179 printf("bos: failed to change stop instance '%s' (%s)\n",
1180 ti->data, em(code));
1182 if (as->parms[8].items) {
1183 code = BOZO_WaitAll(tconn);
1185 printf("bos: can't wait for processes to shutdown (%s)\n",
1191 #define PARMBUFFERSSIZE 32
1194 DoSalvage(struct rx_connection * aconn, char * aparm1, char * aparm2,
1195 char * aoutName, afs_int32 showlog, char * parallel,
1196 char * atmpDir, char * orphans, int dafs,
1197 struct MRAFSSalvageParms * mrafsParm)
1199 register afs_int32 code;
1202 char tbuffer[BOZO_BSSIZE];
1203 struct bozo_status istatus;
1204 struct rx_call *tcall;
1208 char partName[20]; /* canonical name for partition */
1209 char pbuffer[PARMBUFFERSSIZE];
1210 afs_int32 partNumber;
1211 char *notifier = NONOTIFIER;
1213 /* if a partition was specified, canonicalize the name, since
1214 * the salvager has a stupid partition ID parser */
1216 partNumber = volutil_GetPartitionID(aparm1);
1217 if (partNumber < 0) {
1218 printf("bos: could not parse partition ID '%s'\n", aparm1);
1221 tp = volutil_PartitionName(partNumber);
1223 printf("bos: internal error parsing partition ID '%s'\n", aparm1);
1226 strcpy(partName, tp);
1230 /* open the file name */
1232 outFile = fopen(aoutName, "w");
1234 printf("bos: can't open specified SalvageLog file '%s'\n",
1238 closeIt = 1; /* close this file later */
1241 closeIt = 0; /* don't close this file later */
1244 for (code = 2; code < 6; code++)
1249 /* MUST pass canonical (wire-format) salvager path to bosserver */
1251 /* single volume salvage */
1253 /* for DAFS, we call the salvagserver binary with special options.
1254 * in this mode, it simply uses SALVSYNC to tell the currently
1255 * running salvageserver to offline and salvage the volume in question */
1256 strncpy(tbuffer, AFSDIR_CANONICAL_SERVER_SALSRV_FILEPATH, BOZO_BSSIZE);
1258 if ((strlen(tbuffer) + 9 + strlen(partName) + 1 + strlen(aparm2) +
1260 printf("bos: command line too big\n");
1264 strcat(tbuffer, " -client ");
1265 strcat(tbuffer, partName);
1266 strcat(tbuffer, " ");
1267 strcat(tbuffer, aparm2);
1269 strncpy(tbuffer, AFSDIR_CANONICAL_SERVER_SALVAGER_FILEPATH, BOZO_BSSIZE);
1271 if ((strlen(tbuffer) + 1 + strlen(partName) + 1 + strlen(aparm2) +
1273 printf("bos: command line too big\n");
1277 strcat(tbuffer, " ");
1278 strcat(tbuffer, partName);
1279 strcat(tbuffer, " ");
1280 strcat(tbuffer, aparm2);
1283 /* partition salvage */
1284 strncpy(tbuffer, AFSDIR_CANONICAL_SERVER_SALVAGER_FILEPATH, BOZO_BSSIZE);
1285 if ((strlen(tbuffer) + 4 + strlen(partName) + 1) > BOZO_BSSIZE) {
1286 printf("bos: command line too big\n");
1289 strcat(tbuffer, " -force ");
1290 strcat(tbuffer, partName);
1293 /* For DAFS, specifying a single volume does not result in a standard
1294 * salvager call. Instead, it simply results in a SALVSYNC call to the
1295 * online salvager daemon. This interface does not give us the same rich
1296 * set of call flags. Thus, we skip these steps for DAFS single-volume
1298 if (!dafs || (*aparm2 == 0)) {
1299 /* add the parallel option if given */
1300 if (parallel != NULL) {
1301 if ((strlen(tbuffer) + 11 + strlen(parallel) + 1) > BOZO_BSSIZE) {
1302 printf("bos: command line too big\n");
1305 strcat(tbuffer, " -parallel ");
1306 strcat(tbuffer, parallel);
1309 /* add the tmpdir option if given */
1310 if (atmpDir != NULL) {
1311 if ((strlen(tbuffer) + 9 + strlen(atmpDir) + 1) > BOZO_BSSIZE) {
1312 printf("bos: command line too big\n");
1315 strcat(tbuffer, " -tmpdir ");
1316 strcat(tbuffer, atmpDir);
1319 /* add the orphans option if given */
1320 if (orphans != NULL) {
1321 if ((strlen(tbuffer) + 10 + strlen(orphans) + 1) > BOZO_BSSIZE) {
1322 printf("bos: command line too big\n");
1325 strcat(tbuffer, " -orphans ");
1326 strcat(tbuffer, orphans);
1329 if (mrafsParm->Optdebug)
1330 strcat(tbuffer, " -debug");
1331 if (mrafsParm->Optnowrite)
1332 strcat(tbuffer, " -nowrite");
1333 if (mrafsParm->Optforce)
1334 strcat(tbuffer, " -force");
1335 if (mrafsParm->Optoktozap)
1336 strcat(tbuffer, " -oktozap");
1337 if (mrafsParm->Optrootfiles)
1338 strcat(tbuffer, " -rootfiles");
1339 if (mrafsParm->Optsalvagedirs)
1340 strcat(tbuffer, " -salvagedirs");
1341 if (mrafsParm->Optblockreads)
1342 strcat(tbuffer, " -blockreads");
1343 if (mrafsParm->OptListResidencies)
1344 strcat(tbuffer, " -ListResidencies");
1345 if (mrafsParm->OptSalvageRemote)
1346 strcat(tbuffer, " -SalvageRemote");
1347 if (mrafsParm->OptSalvageArchival)
1348 strcat(tbuffer, " -SalvageArchival");
1349 if (mrafsParm->OptIgnoreCheck)
1350 strcat(tbuffer, " -IgnoreCheck");
1351 if (mrafsParm->OptForceOnLine)
1352 strcat(tbuffer, " -ForceOnLine");
1353 if (mrafsParm->OptUseRootDirACL)
1354 strcat(tbuffer, " -UseRootDirACL");
1355 if (mrafsParm->OptTraceBadLinkCounts)
1356 strcat(tbuffer, " -TraceBadLinkCounts");
1357 if (mrafsParm->OptDontAskFS)
1358 strcat(tbuffer, " -DontAskFS");
1359 if (mrafsParm->OptLogLevel) {
1360 sprintf(pbuffer, " -LogLevel %ld", afs_cast_int32(mrafsParm->OptLogLevel));
1361 strcat(tbuffer, pbuffer);
1363 if (mrafsParm->OptRxDebug)
1364 strcat(tbuffer, " -rxdebug");
1365 if (mrafsParm->OptResidencies) {
1366 sprintf(pbuffer, " -Residencies %lu",
1367 afs_cast_uint32(mrafsParm->OptResidencies));
1368 strcat(tbuffer, pbuffer);
1373 parms[1] = "now"; /* when to do it */
1375 BOZO_CreateBnode(aconn, "cron", "salvage-tmp", parms[0], parms[1],
1376 parms[2], parms[3], parms[4], notifier);
1378 printf("bos: failed to start 'salvager' (%s)\n", em(code));
1381 /* now wait for bnode to disappear */
1385 code = BOZO_GetInstanceInfo(aconn, "salvage-tmp", &tp, &istatus);
1388 printf("bos: waiting for salvage to complete.\n");
1390 if (code != BZNOENT) {
1391 printf("bos: salvage failed (%s)\n", em(code));
1396 /* now print the log file to the output file */
1397 printf("bos: salvage completed\n");
1398 if (aoutName || showlog) {
1399 fprintf(outFile, "SalvageLog:\n");
1400 tcall = rx_NewCall(aconn);
1401 /* MUST pass canonical (wire-format) salvager log path to bosserver */
1403 StartBOZO_GetLog(tcall, AFSDIR_CANONICAL_SERVER_SLVGLOG_FILEPATH);
1405 rx_EndCall(tcall, code);
1410 code = rx_Read(tcall, &buffer, 1);
1413 putc(buffer, outFile);
1415 break; /* the end delimeter */
1417 code = rx_EndCall(tcall, 0);
1418 /* fall through into cleanup code */
1422 if (closeIt && outFile)
1428 GetLogCmd(register struct cmd_syndesc *as, void *arock)
1430 struct rx_connection *tconn;
1431 register struct rx_call *tcall;
1432 register afs_int32 code;
1436 printf("Fetching log file '%s'...\n", as->parms[1].items->data);
1437 tconn = GetConn(as, 0);
1438 tcall = rx_NewCall(tconn);
1439 code = StartBOZO_GetLog(tcall, as->parms[1].items->data);
1441 rx_EndCall(tcall, code);
1447 code = rx_Read(tcall, &buffer, 1);
1453 break; /* the end delimeter */
1456 code = rx_EndCall(tcall, error);
1457 /* fall through into cleanup code */
1461 afs_com_err("bos", code, "(while reading log)");
1466 SalvageCmd(struct cmd_syndesc *as, void *arock)
1468 register struct rx_connection *tconn;
1469 register afs_int32 code, rc, i;
1471 char tname[BOZO_BSSIZE];
1473 extern struct ubik_client *cstruct;
1474 afs_int32 curGoal, showlog = 0, dafs = 0, mrafs = 0;
1480 struct MRAFSSalvageParms mrafsParm;
1482 memset(&mrafsParm, 0, sizeof(mrafsParm));
1484 /* parm 0 is machine name, 1 is partition, 2 is volume, 3 is -all flag */
1485 tconn = GetConn(as, 0);
1489 /* find out whether fileserver is running demand attach fs */
1490 if ((code = BOZO_GetInstanceParm(tconn, "dafs", 0, &tp) == 0)) {
1492 serviceName = "dafs";
1493 /* Find out whether fileserver is running MR-AFS (has a scanner instance) */
1494 /* XXX this should really be done some other way, potentially by RPC */
1495 if ((code = BOZO_GetInstanceParm(tconn, serviceName, 4, &tp) == 0))
1499 /* Find out whether fileserver is running MR-AFS (has a scanner instance) */
1500 /* XXX this should really be done some other way, potentially by RPC */
1501 if ((code = BOZO_GetInstanceParm(tconn, serviceName, 3, &tp) == 0))
1505 /* we can do a volume, a partition or the whole thing, but not mixtures
1507 if (!as->parms[1].items && as->parms[2].items) {
1508 printf("bos: must specify partition to salvage individual volume.\n");
1511 if (as->parms[5].items && as->parms[3].items) {
1512 printf("bos: can not specify both -file and -showlog.\n");
1515 if (as->parms[4].items && (as->parms[1].items || as->parms[2].items)) {
1516 printf("bos: can not specify -all with other flags.\n");
1520 /* get the output file name, if any */
1521 if (as->parms[3].items)
1522 outName = as->parms[3].items->data;
1526 if (as->parms[5].items)
1529 /* parallel option */
1531 if (as->parms[6].items)
1532 parallel = as->parms[6].items->data;
1534 /* get the tmpdir filename if any */
1536 if (as->parms[7].items)
1537 tmpDir = as->parms[7].items->data;
1539 /* -orphans option */
1541 if (as->parms[8].items) {
1543 printf("Can't specify -orphans for MR-AFS fileserver\n");
1546 orphans = as->parms[8].items->data;
1550 if (!as->parms[9].items) { /* -forceDAFS flag */
1551 printf("This is a demand attach fileserver. Are you sure you want to proceed with a manual salvage?\n");
1552 printf("must specify -forceDAFS flag in order to proceed.\n");
1558 if (as->parms[MRAFS_OFFSET].items)
1559 mrafsParm.Optdebug = 1;
1560 if (as->parms[MRAFS_OFFSET + 1].items)
1561 mrafsParm.Optnowrite = 1;
1562 if (as->parms[MRAFS_OFFSET + 2].items)
1563 mrafsParm.Optforce = 1;
1564 if (as->parms[MRAFS_OFFSET + 3].items)
1565 mrafsParm.Optoktozap = 1;
1566 if (as->parms[MRAFS_OFFSET + 4].items)
1567 mrafsParm.Optrootfiles = 1;
1568 if (as->parms[MRAFS_OFFSET + 5].items)
1569 mrafsParm.Optsalvagedirs = 1;
1570 if (as->parms[MRAFS_OFFSET + 6].items)
1571 mrafsParm.Optblockreads = 1;
1572 if (as->parms[MRAFS_OFFSET + 7].items)
1573 mrafsParm.OptListResidencies = 1;
1574 if (as->parms[MRAFS_OFFSET + 8].items)
1575 mrafsParm.OptSalvageRemote = 1;
1576 if (as->parms[MRAFS_OFFSET + 9].items)
1577 mrafsParm.OptSalvageArchival = 1;
1578 if (as->parms[MRAFS_OFFSET + 10].items)
1579 mrafsParm.OptIgnoreCheck = 1;
1580 if (as->parms[MRAFS_OFFSET + 11].items)
1581 mrafsParm.OptForceOnLine = 1;
1582 if (as->parms[MRAFS_OFFSET + 12].items)
1583 mrafsParm.OptUseRootDirACL = 1;
1584 if (as->parms[MRAFS_OFFSET + 13].items)
1585 mrafsParm.OptTraceBadLinkCounts = 1;
1586 if (as->parms[MRAFS_OFFSET + 14].items)
1587 mrafsParm.OptDontAskFS = 1;
1588 if (as->parms[MRAFS_OFFSET + 15].items)
1589 mrafsParm.OptLogLevel =
1590 atoi(as->parms[MRAFS_OFFSET + 15].items->data);
1591 if (as->parms[MRAFS_OFFSET + 16].items)
1592 mrafsParm.OptRxDebug = 1;
1593 if (as->parms[MRAFS_OFFSET + 17].items) {
1594 if (as->parms[MRAFS_OFFSET + 8].items
1595 || as->parms[MRAFS_OFFSET + 9].items) {
1597 ("Can't specify -Residencies with -SalvageRemote or -SalvageArchival\n");
1601 util_GetUInt32(as->parms[MRAFS_OFFSET + 17].items->data,
1602 &mrafsParm.OptResidencies);
1604 printf("bos: '%s' is not a valid residency mask.\n",
1605 as->parms[MRAFS_OFFSET + 13].items->data);
1612 for (i = MRAFS_OFFSET; i < ADDPARMOFFSET; i++) {
1613 if (as->parms[i].items) {
1614 printf(" %s only possible for MR-AFS fileserver.\n",
1623 if (as->parms[4].items) {
1624 /* salvage whole enchilada */
1625 curGoal = GetServerGoal(tconn, serviceName);
1626 if (curGoal == BSTAT_NORMAL) {
1627 printf("bos: shutting down '%s'.\n", serviceName);
1628 code = BOZO_SetTStatus(tconn, serviceName, BSTAT_SHUTDOWN);
1630 printf("bos: failed to stop '%s' (%s)\n", serviceName, em(code));
1633 code = BOZO_WaitAll(tconn); /* wait for shutdown to complete */
1636 ("bos: failed to wait for file server shutdown, continuing.\n");
1638 /* now do the salvage operation */
1639 printf("Starting salvage.\n");
1640 rc = DoSalvage(tconn, NULL, NULL, outName, showlog, parallel, tmpDir,
1641 orphans, dafs, &mrafsParm);
1642 if (curGoal == BSTAT_NORMAL) {
1643 printf("bos: restarting %s.\n", serviceName);
1644 code = BOZO_SetTStatus(tconn, serviceName, BSTAT_NORMAL);
1646 printf("bos: failed to restart '%s' (%s)\n", serviceName, em(code));
1652 } else if (!as->parms[2].items) {
1653 if (!as->parms[1].items) {
1655 ("bos: must specify -all switch to salvage all partitions.\n");
1658 if (volutil_GetPartitionID(as->parms[1].items->data) < 0) {
1659 /* can't parse volume ID, so complain before shutting down
1662 printf("bos: can't interpret %s as partition ID.\n",
1663 as->parms[1].items->data);
1666 curGoal = GetServerGoal(tconn, serviceName);
1667 /* salvage a whole partition (specified by parms[1]) */
1668 if (curGoal == BSTAT_NORMAL) {
1669 printf("bos: shutting down '%s'.\n", serviceName);
1670 code = BOZO_SetTStatus(tconn, serviceName, BSTAT_SHUTDOWN);
1672 printf("bos: can't stop '%s' (%s)\n", serviceName, em(code));
1675 code = BOZO_WaitAll(tconn); /* wait for shutdown to complete */
1678 ("bos: failed to wait for file server shutdown, continuing.\n");
1680 /* now do the salvage operation */
1681 printf("Starting salvage.\n");
1682 rc = DoSalvage(tconn, as->parms[1].items->data, NULL, outName,
1683 showlog, parallel, tmpDir, orphans, dafs, &mrafsParm);
1684 if (curGoal == BSTAT_NORMAL) {
1685 printf("bos: restarting '%s'.\n", serviceName);
1686 code = BOZO_SetTStatus(tconn, serviceName, BSTAT_NORMAL);
1688 printf("bos: failed to restart '%s' (%s)\n", serviceName, em(code));
1695 /* salvage individual volume (don't shutdown fs first), just use
1696 * single-shot cron bnode. Must leave server running when using this
1697 * option, since salvager will ask file server for the volume */
1700 const char *confdir;
1703 if (as->parms[ADDPARMOFFSET].items)
1704 tmpname = as->parms[ADDPARMOFFSET].items->data;
1708 localauth = (as->parms[ADDPARMOFFSET + 2].items != 0);
1710 (localauth ? AFSDIR_SERVER_ETC_DIRPATH :
1711 AFSDIR_CLIENT_ETC_DIRPATH);
1712 code = vsu_ClientInit( /* noauth */ 1, confdir, tmpname,
1713 /* server auth */ 0, &cstruct, (int (*)())0);
1715 newID = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
1717 printf("bos: can't interpret %s as volume name or ID\n",
1718 as->parms[2].items->data);
1721 sprintf(tname, "%u", newID);
1724 ("bos: can't initialize volume system client (code %d), trying anyway.\n",
1726 strncpy(tname, as->parms[2].items->data, sizeof(tname));
1728 if (volutil_GetPartitionID(as->parms[1].items->data) < 0) {
1729 /* can't parse volume ID, so complain before shutting down
1732 printf("bos: can't interpret %s as partition ID.\n",
1733 as->parms[1].items->data);
1736 printf("Starting salvage.\n");
1737 rc = DoSalvage(tconn, as->parms[1].items->data, tname, outName,
1738 showlog, parallel, tmpDir, orphans, dafs, &mrafsParm);
1746 IStatServer(register struct cmd_syndesc *as, int int32p)
1748 register struct rx_connection *tconn;
1749 register struct cmd_item *ti;
1752 tconn = GetConn(as, 0);
1753 for (ti = as->parms[1].items; ti; ti = ti->next) {
1754 DoStat(ti->data, tconn, int32p, firstTime);
1761 DoStat(IN char *aname,
1762 IN register struct rx_connection *aconn,
1764 IN int firstTime) /* true iff first instance in cmd */
1768 register afs_int32 code;
1769 register afs_int32 i;
1770 struct bozo_status istatus;
1772 char *is1, *is2, *is3, *is4; /* instance strings */
1775 code = BOZO_GetInstanceInfo(aconn, aname, &tp, &istatus);
1777 printf("bos: failed to get instance info for '%s' (%s)\n", aname,
1781 if (firstTime && aint32p && (istatus.flags & BOZO_BADDIRACCESS))
1783 ("Bosserver reports inappropriate access on server directories\n");
1784 printf("Instance %s, ", aname);
1786 printf("(type is %s) ", buffer);
1787 if (istatus.fileGoal == istatus.goal) {
1789 printf("disabled, ");
1791 if (istatus.fileGoal)
1792 printf("temporarily disabled, ");
1794 printf("temporarily enabled, ");
1797 if (istatus.flags & BOZO_ERRORSTOP)
1798 printf("stopped for too many errors, ");
1799 if (istatus.flags & BOZO_HASCORE)
1800 printf("has core file, ");
1803 code = BOZO_GetStatus(aconn, aname, &temp, &tp);
1805 printf("bos: failed to get status for instance '%s' (%s)\n", aname,
1808 printf("currently ");
1809 if (temp == BSTAT_NORMAL)
1810 printf("running normally.\n");
1811 else if (temp == BSTAT_SHUTDOWN)
1812 printf("shutdown.\n");
1813 else if (temp == BSTAT_STARTINGUP)
1814 printf("starting up.\n");
1815 else if (temp == BSTAT_SHUTTINGDOWN)
1816 printf("shutting down.\n");
1817 if (buffer[0] != 0) {
1818 printf(" Auxiliary status is: %s.\n", buffer);
1822 /* are we done yet? */
1826 if (istatus.procStartTime)
1827 printf(" Process last started at %s (%d proc starts)\n",
1828 DateOf(istatus.procStartTime), istatus.procStarts);
1829 if (istatus.lastAnyExit) {
1830 printf(" Last exit at %s\n", DateOf(istatus.lastAnyExit));
1832 if (istatus.lastErrorExit) {
1833 is1 = is2 = is3 = is4 = NULL;
1834 printf(" Last error exit at %s, ", DateOf(istatus.lastErrorExit));
1835 code = BOZO_GetInstanceStrings(aconn, aname, &is1, &is2, &is3, &is4);
1836 /* don't complain about failing call, since could simply mean
1837 * interface mismatch.
1841 /* non-null instance string */
1842 printf("by %s, ", is1);
1849 if (istatus.errorSignal) {
1850 if (istatus.errorSignal == SIGTERM)
1851 printf("due to shutdown request\n");
1853 printf("due to signal %d\n", istatus.errorSignal);
1855 printf("by exiting with code %d\n", istatus.errorCode);
1859 /* try to display all the parms */
1862 code = BOZO_GetInstanceParm(aconn, aname, i, &tp);
1865 printf(" Command %d is '%s'\n", i + 1, buffer);
1868 code = BOZO_GetInstanceParm(aconn, aname, 999, &tp);
1870 /* Any type of failure is treated as not having a notifier program */
1871 printf(" Notifier is '%s'\n", buffer);
1878 #ifdef BOS_RESTRICTED_MODE
1880 GetRestrict(struct cmd_syndesc *as, void *arock)
1882 register struct rx_connection *tconn;
1883 afs_int32 code, val;
1885 tconn = GetConn(as, 0);
1886 code = BOZO_GetRestrictedMode(tconn, &val);
1888 printf("bos: failed to get restricted mode (%s)\n", em(code));
1890 printf("Restricted mode is %s\n", val ? "on" : "off");
1896 SetRestrict(struct cmd_syndesc *as, void *arock)
1898 register struct rx_connection *tconn;
1899 afs_int32 code, val;
1901 tconn = GetConn(as, 0);
1902 util_GetInt32(as->parms[1].items->data, &val);
1903 code = BOZO_SetRestrictedMode(tconn, val);
1905 printf("bos: failed to set restricted mode (%s)\n", em(code));
1911 add_std_args(register struct cmd_syndesc *ts)
1913 cmd_Seek(ts, ADDPARMOFFSET);
1914 /* + 0 */ cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");
1915 /* + 1 */ cmd_AddParm(ts, "-noauth", CMD_FLAG, CMD_OPTIONAL,
1916 "don't authenticate");
1917 /* + 2 */ cmd_AddParm(ts, "-localauth", CMD_FLAG, CMD_OPTIONAL,
1918 "create tickets from KeyFile");
1921 #include "AFS_component_version_number.c"
1924 main(int argc, char **argv)
1926 register afs_int32 code;
1927 register struct cmd_syndesc *ts;
1928 extern int afsconf_SawCell;
1930 #ifdef AFS_AIX32_ENV
1932 * The following signal action for AIX is necessary so that in case of a
1933 * crash (i.e. core is generated) we can include the user's data section
1934 * in the core dump. Unfortunately, by default, only a partial core is
1935 * generated which, in many cases, isn't too useful.
1937 struct sigaction nsa;
1939 sigemptyset(&nsa.sa_mask);
1940 nsa.sa_handler = SIG_DFL;
1941 nsa.sa_flags = SA_FULLDUMP;
1942 sigaction(SIGSEGV, &nsa, NULL);
1943 sigaction(SIGABRT, &nsa, NULL);
1949 printf("bos: could not initialize rx (%s)\n", em(code));
1953 /* To resolve a AFSCELL environment "Note: ..." problem: Because bos calls ka_Init (why?) before any
1954 * checkup on the existance of a "-cell" option on the particular bos command we don't print the
1955 * message if a cell is passed in. Luckily the rest of the programs don't call these adhoc routines
1956 * and things work fine. Note that if the "-cell" isn't passed then we're still ok since later on
1957 * the proper routine (afsconf_GetCellInfo) is going to be called to do the right thing.
1959 afsconf_SawCell = 1; /* Means don't print warning if AFSCELL is set */
1961 afsconf_SawCell = 0; /* Reset it */
1962 /* don't check error code, since fails sometimes when we're setting up a
1964 initialize_CMD_error_table();
1965 initialize_BZ_error_table();
1967 ts = cmd_CreateSyntax("start", StartServer, NULL, "start running a server");
1968 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1969 cmd_AddParm(ts, "-instance", CMD_LIST, 0, "server process name");
1972 ts = cmd_CreateSyntax("stop", StopServer, NULL, "halt a server instance");
1973 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1974 cmd_AddParm(ts, "-instance", CMD_LIST, 0, "server process name");
1976 cmd_AddParm(ts, "-wait", CMD_FLAG, CMD_OPTIONAL,
1977 "wait for process to stop");
1980 ts = cmd_CreateSyntax("status", StatServer, NULL,
1981 "show server instance status");
1982 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1983 cmd_AddParm(ts, "-instance", CMD_LIST, CMD_OPTIONAL,
1984 "server process name");
1985 cmd_AddParm(ts, "-long", CMD_FLAG, CMD_OPTIONAL, "long status");
1988 ts = cmd_CreateSyntax("shutdown", Shutdown, NULL, "shutdown all processes");
1989 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1990 cmd_AddParm(ts, "-instance", CMD_LIST, CMD_OPTIONAL, "instances");
1992 cmd_AddParm(ts, "-wait", CMD_FLAG, CMD_OPTIONAL,
1993 "wait for process to stop");
1996 ts = cmd_CreateSyntax("startup", Startup, NULL, "start all processes");
1997 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1998 cmd_AddParm(ts, "-instance", CMD_LIST, CMD_OPTIONAL, "instances");
2001 ts = cmd_CreateSyntax("restart", Restart, NULL, "restart processes");
2002 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2003 cmd_AddParm(ts, "-instance", CMD_LIST, CMD_OPTIONAL, "instances");
2004 cmd_AddParm(ts, "-bosserver", CMD_FLAG, CMD_OPTIONAL,
2005 "restart bosserver");
2006 cmd_AddParm(ts, "-all", CMD_FLAG, CMD_OPTIONAL, "restart all processes");
2011 ts = cmd_CreateSyntax("create", CreateServer, NULL,
2012 "create a new server instance");
2013 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2014 cmd_AddParm(ts, "-instance", CMD_SINGLE, 0, "server process name");
2015 cmd_AddParm(ts, "-type", CMD_SINGLE, 0, "server type");
2016 cmd_AddParm(ts, "-cmd", CMD_LIST, 0, "command lines");
2017 cmd_AddParm(ts, "-notifier", CMD_SINGLE, CMD_OPTIONAL,
2018 "Notifier program");
2021 ts = cmd_CreateSyntax("delete", DeleteServer, NULL,
2022 "delete a server instance");
2023 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2024 cmd_AddParm(ts, "-instance", CMD_LIST, 0, "server process name");
2027 ts = cmd_CreateSyntax("adduser", AddSUser, NULL,
2028 "add users to super-user list");
2029 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2030 cmd_AddParm(ts, "-user", CMD_LIST, 0, "user names");
2033 ts = cmd_CreateSyntax("removeuser", RemoveSUser, NULL,
2034 "remove users from super-user list");
2035 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2036 cmd_AddParm(ts, "-user", CMD_LIST, 0, "user names");
2039 ts = cmd_CreateSyntax("listusers", ListSUsers, NULL, "list super-users");
2040 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2043 ts = cmd_CreateSyntax("addkey", AddKey, NULL,
2044 "add keys to key dbase (kvno 999 is bcrypt)");
2045 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2046 cmd_AddParm(ts, "-key", CMD_SINGLE, CMD_OPTIONAL, "key");
2047 cmd_AddParm(ts, "-kvno", CMD_SINGLE, 0, "key version number");
2050 ts = cmd_CreateSyntax("removekey", RemoveKey, NULL,
2051 "remove keys from key dbase");
2052 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2053 cmd_AddParm(ts, "-kvno", CMD_LIST, 0, "key version number");
2056 ts = cmd_CreateSyntax("listkeys", ListKeys, NULL, "list keys");
2057 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2058 cmd_AddParm(ts, "-showkey", CMD_FLAG, CMD_OPTIONAL,
2059 "show the actual key rather than the checksum");
2062 ts = cmd_CreateSyntax("listhosts", ListHosts, NULL, "get cell host list");
2063 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2065 cmd_CreateAlias(ts, "getcell");
2067 ts = cmd_CreateSyntax("setcellname", SetCellName, NULL, "set cell name");
2068 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2069 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "cell name");
2072 ts = cmd_CreateSyntax("addhost", AddHost, NULL, "add host to cell dbase");
2073 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2074 cmd_AddParm(ts, "-host", CMD_LIST, 0, "host name");
2075 cmd_AddParm(ts, "-clone", CMD_FLAG, CMD_OPTIONAL, "vote doesn't count");
2078 ts = cmd_CreateSyntax("removehost", RemoveHost, NULL,
2079 "remove host from cell dbase");
2080 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2081 cmd_AddParm(ts, "-host", CMD_LIST, 0, "host name");
2084 ts = cmd_CreateSyntax("setauth", SetAuth, NULL,
2085 "set authentication required flag");
2086 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2087 cmd_AddParm(ts, "-authrequired", CMD_SINGLE, 0,
2088 "on or off: authentication required for admin requests");
2091 ts = cmd_CreateSyntax("install", Install, NULL, "install program");
2092 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2093 cmd_AddParm(ts, "-file", CMD_LIST, 0, "files to install");
2094 cmd_AddParm(ts, "-dir", CMD_SINGLE, CMD_OPTIONAL, "destination dir");
2097 ts = cmd_CreateSyntax("uninstall", UnInstall, NULL, "uninstall program");
2098 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2099 cmd_AddParm(ts, "-file", CMD_LIST, 0, "files to uninstall");
2100 cmd_AddParm(ts, "-dir", CMD_SINGLE, CMD_OPTIONAL, "destination dir");
2103 ts = cmd_CreateSyntax("getlog", GetLogCmd, NULL, "examine log file");
2104 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2105 cmd_AddParm(ts, "-file", CMD_SINGLE, 0, "log file to examine");
2108 ts = cmd_CreateSyntax("getdate", GetDate, NULL, "get dates for programs");
2109 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2110 cmd_AddParm(ts, "-file", CMD_LIST, 0, "files to check");
2111 cmd_AddParm(ts, "-dir", CMD_SINGLE, CMD_OPTIONAL, "destination dir");
2114 ts = cmd_CreateSyntax("exec", Exec, NULL, "execute shell command on server");
2115 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2116 cmd_AddParm(ts, "-cmd", CMD_SINGLE, 0, "command to execute");
2119 ts = cmd_CreateSyntax("prune", Prune, NULL, "prune server files");
2120 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2121 cmd_AddParm(ts, "-bak", CMD_FLAG, CMD_OPTIONAL, "delete .BAK files");
2122 cmd_AddParm(ts, "-old", CMD_FLAG, CMD_OPTIONAL, "delete .OLD files");
2123 cmd_AddParm(ts, "-core", CMD_FLAG, CMD_OPTIONAL, "delete core files");
2124 cmd_AddParm(ts, "-all", CMD_FLAG, CMD_OPTIONAL, "delete all junk files");
2127 ts = cmd_CreateSyntax("setrestart", SetRestartCmd, NULL,
2128 "set restart times");
2129 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_REQUIRED, "machine name");
2130 cmd_AddParm(ts, "-time", CMD_SINGLE, CMD_REQUIRED,
2131 "time to restart server");
2132 cmd_AddParm(ts, "-general", CMD_FLAG, CMD_OPTIONAL,
2133 "set general restart time");
2134 cmd_AddParm(ts, "-newbinary", CMD_FLAG, CMD_OPTIONAL,
2135 "set new binary restart time");
2138 ts = cmd_CreateSyntax("getrestart", GetRestartCmd, NULL,
2139 "get restart times");
2140 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_REQUIRED, "machine name");
2143 ts = cmd_CreateSyntax("salvage", SalvageCmd, NULL,
2144 "salvage partition or volumes");
2145 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2146 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL,
2147 "salvage partition");
2148 cmd_AddParm(ts, "-volume", CMD_SINGLE, CMD_OPTIONAL,
2149 "salvage volume number or volume name");
2150 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL,
2151 "salvage log output file");
2152 cmd_AddParm(ts, "-all", CMD_FLAG, CMD_OPTIONAL, "salvage whole server");
2153 cmd_AddParm(ts, "-showlog", CMD_FLAG, CMD_OPTIONAL,
2154 "display salvage log");
2155 cmd_AddParm(ts, "-parallel", CMD_SINGLE, CMD_OPTIONAL,
2156 "# of max parallel partition salvaging");
2157 cmd_AddParm(ts, "-tmpdir", CMD_SINGLE, CMD_OPTIONAL,
2158 "directory to place tmp files");
2159 cmd_AddParm(ts, "-orphans", CMD_SINGLE, CMD_OPTIONAL,
2160 "ignore | remove | attach");
2161 cmd_AddParm(ts, "-forceDAFS", CMD_FLAG, CMD_OPTIONAL,
2162 "(DAFS) force salvage of demand attach fileserver");
2163 cmd_AddParm(ts, "-debug", CMD_FLAG, CMD_OPTIONAL,
2164 "(MR-AFS) Run in Debugging mode");
2165 cmd_AddParm(ts, "-nowrite", CMD_FLAG, CMD_OPTIONAL,
2166 "(MR-AFS) Run readonly/test mode");
2167 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL,
2168 "(MR-AFS) Force full salvaging");
2169 cmd_AddParm(ts, "-oktozap", CMD_FLAG, CMD_OPTIONAL,
2170 "(MR-AFS) Give permission to destroy bogus file residencies/volumes - debugging flag");
2171 cmd_AddParm(ts, "-rootfiles", CMD_FLAG, CMD_OPTIONAL,
2172 "(MR-AFS) Show files owned by root - debugging flag");
2173 cmd_AddParm(ts, "-salvagedirs", CMD_FLAG, CMD_OPTIONAL,
2174 "(MR-AFS) Force rebuild/salvage of all directories");
2175 cmd_AddParm(ts, "-blockreads", CMD_FLAG, CMD_OPTIONAL,
2176 "(MR-AFS) Read smaller blocks to handle IO/bad blocks");
2177 cmd_AddParm(ts, "-ListResidencies", CMD_FLAG, CMD_OPTIONAL,
2178 "(MR-AFS) Just list affected file residencies - debugging flag");
2179 cmd_AddParm(ts, "-SalvageRemote", CMD_FLAG, CMD_OPTIONAL,
2180 "(MR-AFS) Salvage storage systems that are not directly attached");
2181 cmd_AddParm(ts, "-SalvageArchival", CMD_FLAG, CMD_OPTIONAL,
2182 "(MR-AFS) Salvage HSM storage systems");
2183 cmd_AddParm(ts, "-IgnoreCheck", CMD_FLAG, CMD_OPTIONAL,
2184 "(MR-AFS) Don't perform VLDB safety check when deleting unreferenced files. Only a good idea in single server cell.");
2185 cmd_AddParm(ts, "-ForceOnLine", CMD_FLAG, CMD_OPTIONAL,
2186 "(MR-AFS) Force the volume to come online, even if it hasn't salvaged cleanly.");
2187 cmd_AddParm(ts, "-UseRootDirACL", CMD_FLAG, CMD_OPTIONAL,
2188 "(MR-AFS) Use the root directory ACL for lost+found directory if it is created.");
2189 cmd_AddParm(ts, "-TraceBadLinkCounts", CMD_FLAG, CMD_OPTIONAL,
2190 "(MR-AFS) Print out lines about volume reference count changes.");
2191 cmd_AddParm(ts, "-DontAskFS", CMD_FLAG, CMD_OPTIONAL,
2192 "(MR-AFS) Don't ask fileserver to take volume offline. THIS IS VERY DANGEROUS.");
2193 cmd_AddParm(ts, "-LogLevel", CMD_SINGLE, CMD_OPTIONAL,
2194 "(MR-AFS) log level");
2195 cmd_AddParm(ts, "-rxdebug", CMD_FLAG, CMD_OPTIONAL,
2196 "(MR-AFS) Write out rx debug information.");
2197 cmd_AddParm(ts, "-Residencies", CMD_SINGLE, CMD_OPTIONAL,
2198 "(MR-AFS) Numeric mask of residencies to be included in the salvage. Do not use with -SalvageRemote or -SalvageArchival");
2201 ts = cmd_CreateSyntax("blockscanner", BlockScannerCmd, NULL,
2202 "block scanner daemon from making migration requests");
2203 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_REQUIRED, "machine name");
2206 ts = cmd_CreateSyntax("unblockscanner", UnBlockScannerCmd, NULL,
2207 "allow scanner daemon to make migration requests again");
2208 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_REQUIRED, "machine name");
2211 #ifdef BOS_RESTRICTED_MODE
2212 ts = cmd_CreateSyntax("getrestricted", GetRestrict, NULL,
2213 "get restrict mode");
2214 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2217 ts = cmd_CreateSyntax("setrestricted", SetRestrict, NULL,
2218 "set restrict mode");
2219 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2220 cmd_AddParm(ts, "-mode", CMD_SINGLE, 0, "mode to set");
2225 code = cmd_Dispatch(argc, argv);