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
9 * Portions Copyright (c) 2006 Sine Nomine Associates
12 /* viced.c - File Server main loop */
16 /* Function - This routine has the initialization code for */
19 /* ********************************************************************** */
21 #include <afsconfig.h>
22 #include <afs/param.h>
30 #include <sys/types.h>
31 #include <afs/procmgmt.h> /* signal(), kill(), wait(), etc. */
37 #include <WINNT/afsevent.h>
40 #include <netinet/in.h>
42 #include <unistd.h> /* sysconf() */
54 #endif /* ITIMER_REAL */
55 #include <sys/resource.h>
56 #endif /* AFS_NT40_ENV */
61 #ifdef AFS_PTHREAD_ENV
63 #else /* AFS_PTHREAD_ENV */
64 #include <afs/assert.h>
65 #endif /* AFS_PTHREAD_ENV */
68 #include <afs/ptclient.h>
69 #include <afs/afsint.h>
70 #include <afs/vldbint.h>
71 #include <afs/errors.h>
72 #include <afs/ihandle.h>
73 #include <afs/vnode.h>
74 #include <afs/volume.h>
76 #include <afs/cellconfig.h>
78 #include <afs/prs_fs.h>
82 #include <afs/afs_args.h>
83 #include <afs/vlserver.h>
84 #include <afs/afsutil.h>
85 #include <afs/fileutil.h>
86 #include <afs/ptuser.h>
87 #include <afs/audit.h>
88 #include <afs/partition.h>
90 #include <afs/netutils.h>
94 #ifdef AFS_PTHREAD_ENV
97 #if defined(AFS_SGI_ENV)
98 #include "sys/schedctl.h"
101 #include <rx/rx_globals.h>
104 #define afs_stat stat64
105 #define afs_fstat fstat64
106 #define afs_open open64
107 #define afs_fopen fopen64
108 #else /* !O_LARGEFILE */
109 #define afs_stat stat
110 #define afs_fstat fstat
111 #define afs_open open
112 #define afs_fopen fopen
113 #endif /* !O_LARGEFILE */
115 extern int BreakVolumeCallBacks(), InitCallBack();
116 extern int BreakVolumeCallBacks(), InitCallBack(), BreakLaterCallBacks();
117 extern int BreakVolumeCallBacksLater();
118 extern int LogLevel, etext;
119 extern afs_int32 BlocksSpare, PctSpare;
122 static void ClearXStatValues(), NewParms(), PrintCounters();
123 static void ResetCheckDescriptors(void), ResetCheckSignal(void);
124 static int CheckSignal(void);
125 extern int GetKeysFromToken();
126 extern int RXAFS_ExecuteRequest();
127 extern int RXSTATS_ExecuteRequest();
128 afs_int32 Do_VLRegisterRPC();
130 int eventlog = 0, rxlog = 0;
132 FILE *console = NULL;
134 #ifdef AFS_PTHREAD_ENV
135 pthread_mutex_t fsync_glock_mutex;
136 pthread_cond_t fsync_cond;
139 #endif /* AFS_PTHREAD_ENV */
142 #define AFS_QUIETFS_ENV 1
143 #define NT_OPEN_MAX 1024 /* This is an arbitrary no. we came up with for
144 * now. We hope this will be replaced by a more
145 * intelligent estimate later. */
148 int SystemId; /* ViceID of "Administrators" */
149 int SystemAnyUser; /* Viceid of "System:AnyUser" */
150 prlist SystemAnyUserCPS; /* CPS for "system:AnyUser */
151 int AnonymousID = 0; /* ViceId of "Anonymous" */
152 prlist AnonCPS; /* CPS for "Anonymous" */
154 struct afsconf_dir *confDir; /* Configuration dir object */
156 int restartMode = RESTART_ORDINARY;
159 * Home for the performance statistics.
161 struct afs_PerfStats afs_perfstats;
164 extern int Statistics;
172 int rxJumbograms = 1; /* default is to send and receive jumbograms. */
173 int rxBind = 0; /* don't bind */
175 afs_int32 implicitAdminRights = PRSFS_LOOKUP; /* The ADMINISTER right is
177 afs_int32 readonlyServer = 0;
180 int stackSize = 24000;
181 int fiveminutes = 300; /* 5 minutes. Change this for debugging only */
182 int CurrentConnections = 0;
183 int hostaclRefresh = 7200; /* refresh host clients' acls every 2 hrs */
184 #if defined(AFS_SGI_ENV)
189 int rxpackets = 150; /* 100 */
190 int nSmallVns = 400; /* 200 */
191 int large = 400; /* 200 */
192 int volcache = 400; /* 400 */
193 int numberofcbs = 60000; /* 60000 */
194 int lwps = 9; /* 6 */
195 int buffs = 90; /* 70 */
196 int novbc = 0; /* Enable Volume Break calls */
197 int busy_threshold = 600;
198 int abort_threshold = 10;
199 int udpBufSize = 0; /* UDP buffer size for receive */
200 int sendBufSize = 16384; /* send buffer size */
201 int saneacls = 0; /* Sane ACLs Flag */
205 #ifdef AFS_PTHREAD_ENV
206 pthread_key_t viced_uclient_key;
209 #ifdef AFS_PTHREAD_ENV
210 pthread_key_t viced_uclient_key;
214 * FileServer's name and IP address, both network byte order and
217 #define ADDRSPERSITE 16 /* Same global is in rx/rx_user.c */
219 char FS_HostName[128] = "localhost";
220 afs_uint32 FS_HostAddr_NBO;
221 afs_uint32 FS_HostAddr_HBO;
222 afs_uint32 FS_HostAddrs[ADDRSPERSITE], FS_HostAddr_cnt = 0, FS_registered = 0;
223 /* All addresses in FS_HostAddrs are in NBO */
226 static void FlagMsg();
228 #ifdef AFS_DEMAND_ATTACH_FS
231 * fileserver mode support
233 * during fileserver shutdown, we have to track the graceful shutdown of
234 * certain background threads before we are allowed to dump state to
237 struct fs_state fs_state =
244 PTHREAD_COND_INITIALIZER,
245 PTHREAD_RWLOCK_INITIALIZER
247 #endif /* AFS_DEMAND_ATTACH_FS */
250 * Home for the performance statistics.
258 struct afs_stat status;
259 register int tsize = getdtablesize();
261 for (i = 0; i < tsize; i++) {
262 if (afs_fstat(i, &status) != -1) {
263 printf("%d: dev %x, inode %u, length %u, type/mode %x\n", i,
264 status.st_dev, status.st_ino, status.st_size,
269 ResetCheckDescriptors();
272 } /*CheckDescriptors */
275 #ifdef AFS_PTHREAD_ENV
277 CheckSignal_Signal(x)
289 CheckDescriptors_Signal(x)
293 #else /* AFS_PTHREAD_ENV */
295 CheckSignal_Signal(x)
297 IOMGR_SoftSig(CheckSignal, 0);
303 IOMGR_SoftSig(ShutDown, 0);
307 CheckDescriptors_Signal(x)
309 IOMGR_SoftSig(CheckDescriptors, 0);
311 #endif /* AFS_PTHREAD_ENV */
313 /* check whether caller is authorized to manage RX statistics */
315 fs_rxstat_userok(struct rx_call *call)
317 return afsconf_SuperUser(confDir, call, NULL);
321 ResetCheckSignal(void)
325 #if defined(AFS_HPUX_ENV)
328 #if defined(AFS_NT40_ENV)
335 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
336 softsig_signal(signo, CheckSignal_Signal);
338 signal(signo, CheckSignal_Signal);
343 ResetCheckDescriptors(void)
346 #if defined(AFS_PTHREAD_ENV)
347 softsig_signal(SIGTERM, CheckDescriptors_Signal);
349 (void)signal(SIGTERM, CheckDescriptors_Signal);
354 #if defined(AFS_PTHREAD_ENV)
358 return pthread_getspecific(rx_thread_id_key);
362 /* proc called by rxkad module to get a key */
364 get_key(char *arock, register afs_int32 akvno, char *akey)
367 static struct afsconf_key tkey;
368 register afs_int32 code;
371 ViceLog(0, ("conf dir not open\n"));
374 code = afsconf_GetKey(confDir, akvno, tkey.key);
376 ViceLog(0, ("afsconf_GetKey failure: kvno %d code %d\n", akvno, code));
379 memcpy(akey, tkey.key, sizeof(tkey.key));
386 viced_syscall(afs_uint32 a3, afs_uint32 a4, void *a5)
391 #ifndef AFS_LINUX20_ENV
392 old = (void (*)())signal(SIGSYS, SIG_IGN);
394 rcode = syscall(AFS_SYSCALL, 28 /* AFSCALL_CALL */ , a3, a4, a5);
395 #ifndef AFS_LINUX20_ENV
403 #if !defined(AFS_NT40_ENV)
404 #include "AFS_component_version_number.c"
405 #endif /* !AFS_NT40_ENV */
407 #define MAXADMINNAME 64
408 char adminName[MAXADMINNAME];
414 struct afs_stat status;
416 if ((afs_stat("/AdminName", &status)) || /* if file does not exist */
417 (status.st_size <= 0) || /* or it is too short */
418 (status.st_size >= (MAXADMINNAME)) || /* or it is too long */
419 !(fd = afs_open("/AdminName", O_RDONLY, 0))) { /* or the open fails */
420 strcpy(adminName, "System:Administrators"); /* use the default name */
422 (void)read(fd, adminName, status.st_size); /* use name from the file */
425 close(fd); /* close fd if it was opened */
427 } /*CheckAdminName */
433 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
434 /* set our 'thread-id' so that the host hold table works */
435 MUTEX_ENTER(&rx_stats_mutex); /* protects rxi_pthread_hinum */
437 pthread_setspecific(rx_thread_id_key, (void *)rxi_pthread_hinum);
438 MUTEX_EXIT(&rx_stats_mutex);
440 ("Set thread id %d for '%s'\n",
441 pthread_getspecific(rx_thread_id_key), s));
445 /* This LWP does things roughly every 5 minutes */
452 ViceLog(1, ("Starting five minute check process\n"));
453 setThreadId("FiveMinuteCheckLWP");
455 #ifdef AFS_DEMAND_ATTACH_FS
457 while (fs_state.mode == FS_MODE_NORMAL) {
458 fs_state.FiveMinuteLWP_tranquil = 1;
464 #ifdef AFS_PTHREAD_ENV
466 #else /* AFS_PTHREAD_ENV */
467 IOMGR_Sleep(fiveminutes);
468 #endif /* AFS_PTHREAD_ENV */
470 #ifdef AFS_DEMAND_ATTACH_FS
472 if (fs_state.mode != FS_MODE_NORMAL) {
475 fs_state.FiveMinuteLWP_tranquil = 0;
479 /* close the log so it can be removed */
480 ReOpenLog(AFSDIR_SERVER_FILELOG_FILEPATH); /* don't trunc, just append */
481 ViceLog(2, ("Cleaning up timed out callbacks\n"));
482 if (CleanupTimedOutCallBacks())
483 ViceLog(5, ("Timed out callbacks deleted\n"));
484 ViceLog(2, ("Set disk usage statistics\n"));
486 if (FS_registered == 1)
488 /* Force wakeup in case we missed something; pthreads does timedwait */
489 #ifndef AFS_PTHREAD_ENV
490 LWP_NoYieldSignal(fsync_wait);
492 if (printBanner && (++msg & 1)) { /* Every 10 minutes */
493 time_t now = FT_ApproxTime();
494 if (console != NULL) {
495 #ifndef AFS_QUIETFS_ENV
496 fprintf(console, "File server is running at %s\r",
497 afs_ctime(&now, tbuffer, sizeof(tbuffer)));
498 #endif /* AFS_QUIETFS_ENV */
500 ("File server is running at %s\n",
501 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
504 #ifdef AFS_DEMAND_ATTACH_FS
508 #ifdef AFS_DEMAND_ATTACH_FS
509 fs_state.FiveMinuteLWP_tranquil = 1;
511 assert(pthread_cond_broadcast(&fs_state.worker_done_cv)==0);
515 } /*FiveMinuteCheckLWP */
518 /* This LWP does host checks every 5 minutes: it should not be used for
519 * other 5 minute activities because it may be delayed by timeouts when
520 * it probes the workstations
526 ViceLog(1, ("Starting Host check process\n"));
527 setThreadId("HostCheckLWP");
528 #ifdef AFS_DEMAND_ATTACH_FS
530 while (fs_state.mode == FS_MODE_NORMAL) {
531 fs_state.HostCheckLWP_tranquil = 1;
537 #ifdef AFS_PTHREAD_ENV
539 #else /* AFS_PTHREAD_ENV */
540 IOMGR_Sleep(fiveminutes);
541 #endif /* AFS_PTHREAD_ENV */
543 #ifdef AFS_DEMAND_ATTACH_FS
545 if (fs_state.mode != FS_MODE_NORMAL) {
548 fs_state.HostCheckLWP_tranquil = 0;
552 ViceLog(2, ("Checking for dead venii & clients\n"));
555 #ifdef AFS_DEMAND_ATTACH_FS
559 #ifdef AFS_DEMAND_ATTACH_FS
560 fs_state.HostCheckLWP_tranquil = 1;
562 assert(pthread_cond_broadcast(&fs_state.worker_done_cv)==0);
568 /* This LWP does fsync checks every 5 minutes: it should not be used for
569 * other 5 minute activities because it may be delayed by timeouts when
570 * it probes the workstations
576 #ifdef AFS_PTHREAD_ENV
577 struct timespec fsync_next;
579 ViceLog(1, ("Starting fsync check process\n"));
581 setThreadId("FsyncCheckLWP");
583 #ifdef AFS_PTHREAD_ENV
584 assert(pthread_cond_init(&fsync_cond, NULL) == 0);
585 assert(pthread_mutex_init(&fsync_glock_mutex, NULL) == 0);
588 #ifdef AFS_DEMAND_ATTACH_FS
590 while (fs_state.mode == FS_MODE_NORMAL) {
591 fs_state.FsyncCheckLWP_tranquil = 1;
597 #ifdef AFS_PTHREAD_ENV
598 /* rounding is fine */
599 fsync_next.tv_nsec = 0;
600 fsync_next.tv_sec = time(0) + fiveminutes;
603 pthread_cond_timedwait(&fsync_cond, &fsync_glock_mutex,
605 if (code != 0 && code != ETIMEDOUT)
606 ViceLog(0, ("pthread_cond_timedwait returned %d\n", code));
607 #else /* AFS_PTHREAD_ENV */
608 if ((code = LWP_WaitProcess(fsync_wait)) != LWP_SUCCESS)
609 ViceLog(0, ("LWP_WaitProcess returned %d\n", code));
610 #endif /* AFS_PTHREAD_ENV */
613 #ifdef AFS_DEMAND_ATTACH_FS
615 if (fs_state.mode != FS_MODE_NORMAL) {
618 fs_state.FsyncCheckLWP_tranquil = 0;
620 #endif /* AFS_DEMAND_ATTACH_FS */
622 ViceLog(2, ("Checking for fsync events\n"));
624 code = BreakLaterCallBacks();
626 #ifdef AFS_DEMAND_ATTACH_FS
630 #ifdef AFS_DEMAND_ATTACH_FS
631 fs_state.FsyncCheckLWP_tranquil = 1;
633 assert(pthread_cond_broadcast(&fs_state.worker_done_cv)==0);
636 #endif /* AFS_DEMAND_ATTACH_FS */
639 /*------------------------------------------------------------------------
640 * PRIVATE ClearXStatValues
643 * Initialize all of the values collected via the xstat
653 * Must be called during File Server initialization.
657 *------------------------------------------------------------------------*/
661 { /*ClearXStatValues */
663 struct fs_stats_opTimingData *opTimeP; /*Ptr to timing struct */
664 struct fs_stats_xferData *opXferP; /*Ptr to xfer struct */
665 int i; /*Loop counter */
668 * Zero all xstat-related structures.
670 memset((char *)(&afs_perfstats), 0, sizeof(struct afs_PerfStats));
671 #if FS_STATS_DETAILED
672 memset((char *)(&afs_FullPerfStats), 0,
673 sizeof(struct fs_stats_FullPerfStats));
676 * That's not enough. We have to set reasonable minima for
677 * time and xfer values in the detailed stats.
679 opTimeP = &(afs_FullPerfStats.det.rpcOpTimes[0]);
680 for (i = 0; i < FS_STATS_NUM_RPC_OPS; i++, opTimeP++)
681 opTimeP->minTime.tv_sec = 999999;
683 opXferP = &(afs_FullPerfStats.det.xferOpTimes[0]);
684 for (i = 0; i < FS_STATS_NUM_XFER_OPS; i++, opXferP++) {
685 opXferP->minTime.tv_sec = 999999;
686 opXferP->minBytes = 999999999;
690 * There's more. We have to set our unique system identifier, as
691 * declared in param.h. If such a thing is not defined, we bitch
692 * and declare ourselves to be an unknown system type.
695 afs_perfstats.sysname_ID = SYS_NAME_ID;
698 ViceLog(0, ("Sys name ID constant not defined in param.h!!\n"));
699 ViceLog(0, ("[Choosing ``undefined'' sys name ID.\n"));
701 afs_perfstats.sysname_ID = SYS_NAME_ID_UNDEFINED;
702 #endif /* SYS_NAME_ID */
705 } /*ClearXStatValues */
711 int dirbuff, dircall, dirio;
713 int workstations, activeworkstations, delworkstations;
717 TM_GetTimeOfDay(&tpl, 0);
720 ("Vice was last started at %s\n",
721 afs_ctime(&StartTime, tbuffer, sizeof(tbuffer))));
723 #ifdef AFS_DEMAND_ATTACH_FS
724 /* XXX perhaps set extended stats verbosity flags
725 * based upon LogLevel ?? */
726 VPrintExtendedCacheStats(VOL_STATS_PER_CHAIN2);
730 DStat(&dirbuff, &dircall, &dirio);
732 ("With %d directory buffers; %d reads resulted in %d read I/Os\n",
733 dirbuff, dircall, dirio));
734 rx_PrintStats(stderr);
736 PrintCallBackStats();
738 processSize = -1; /* TODO: */
740 processSize = (int)((long)sbrk(0) >> 10);
743 ("There are %d connections, process size %d\n",
744 CurrentConnections, processSize));
745 h_GetWorkStats(&workstations, &activeworkstations, &delworkstations,
746 tpl.tv_sec - 15 * 60);
748 ("There are %d workstations, %d are active (req in < 15 mins), %d marked \"down\"\n",
749 workstations, activeworkstations, delworkstations));
759 if (FS_registered > 0) {
761 * We have proper ip addresses; tell the vlserver what we got; the following
762 * routine will do the proper reporting for us
775 ShutDownAndCore(int dopanic)
777 time_t now = time(0);
780 /* do not allows new reqests to be served from now on, all new requests
781 * are returned with an error code of RX_RESTARTING ( transient failure ) */
782 rx_SetRxTranquil(); /* dhruba */
784 #ifdef AFS_DEMAND_ATTACH_FS
786 fs_state.mode = FS_MODE_SHUTDOWN;
791 ("Shutting down file server at %s",
792 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
794 ViceLog(0, ("ABNORMAL SHUTDOWN, see core file.\n"));
795 #ifndef AFS_QUIETFS_ENV
796 if (console != NULL) {
797 fprintf(console, "File server restart/shutdown received at %s\r",
798 afs_ctime(&now, tbuffer, sizeof(tbuffer)));
805 /* shut down volume package */
808 #ifdef AFS_DEMAND_ATTACH_FS
809 if (fs_state.options.fs_state_save) {
812 * save fileserver state to disk */
814 /* make sure background threads have finished all of their asynchronous
815 * work on host and callback structures */
817 while (!fs_state.FiveMinuteLWP_tranquil ||
818 !fs_state.HostCheckLWP_tranquil ||
819 !fs_state.FsyncCheckLWP_tranquil) {
822 ViceLog(0, ("waiting for background host/callback threads to quiesce before saving fileserver state...\n"));
823 assert(pthread_cond_wait(&fs_state.worker_done_cv, &fileproc_glock_mutex) == 0);
828 /* ok. it should now be fairly safe. let's do the state dump */
831 #endif /* AFS_DEMAND_ATTACH_FS */
834 rx_PrintStats(debugFile);
837 if (console != NULL) {
840 #ifndef AFS_QUIETFS_ENV
841 fprintf(console, "File server has terminated abnormally at %s\r",
842 afs_ctime(&now, tbuffer, sizeof(tbuffer)));
845 ("File server has terminated abnormally at %s\n",
846 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
848 #ifndef AFS_QUIETFS_ENV
849 fprintf(console, "File server has terminated normally at %s\r",
850 afs_ctime(&now, tbuffer, sizeof(tbuffer)));
853 ("File server has terminated normally at %s\n",
854 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
863 { /* backward compatibility */
864 ShutDownAndCore(DONTPANIC);
872 /* default supports help flag */
874 fputs("Usage: fileserver ", stdout);
875 fputs("[-auditlog <log path>] ", stdout);
876 fputs("[-d <debug level>] ", stdout);
877 fputs("[-p <number of processes>] ", stdout);
878 fputs("[-spare <number of spare blocks>] ", stdout);
879 fputs("[-pctspare <percentage spare>] ", stdout);
880 fputs("[-b <buffers>] ", stdout);
881 fputs("[-l <large vnodes>] ", stdout);
882 fputs("[-s <small vnodes>] ", stdout);
883 fputs("[-vc <volume cachesize>] ", stdout);
884 fputs("[-w <call back wait interval>] ", stdout);
885 fputs("[-cb <number of call backs>] ", stdout);
886 fputs("[-banner (print banner every 10 minutes)] ", stdout);
887 fputs("[-novbc (whole volume cbs disabled)] ", stdout);
888 fputs("[-implicit <admin mode bits: rlidwka>] ", stdout);
889 fputs("[-readonly (read-only file server)] ", stdout);
890 fputs("[-hr <number of hours between refreshing the host cps>] ", stdout);
891 fputs("[-busyat <redirect clients when queue > n>] ", stdout);
892 fputs("[-nobusy <no VBUSY before a volume is attached>] ", stdout);
893 fputs("[-rxpck <number of rx extra packets>] ", stdout);
894 fputs("[-rxdbg (enable rx debugging)] ", stdout);
895 fputs("[-rxdbge (enable rxevent debugging)] ", stdout);
896 fputs("[-rxmaxmtu <bytes>] ", stdout);
897 fputs("[-rxbind (bind the Rx socket to one address)] ", stdout);
898 #ifdef AFS_DEMAND_ATTACH_FS
899 fputs("[-fs-state-dont-save (disable state save during shutdown)] ", stdout);
900 fputs("[-fs-state-dont-restore (disable state restore during startup)] ", stdout);
901 fputs("[-fs-state-verify <none|save|restore|both> (default is both)] ", stdout);
902 fputs("[-vattachpar <max number of volume attach/shutdown threads> (default is 1)] ", stdout);
903 fputs("[-vhashsize <log(2) of number of volume hash buckets> (default is 8)] ", stdout);
904 fputs("[-vlrudisable (disable VLRU functionality)] ", stdout);
905 fputs("[-vlruthresh <minutes before unused volumes become eligible for soft detach> (default is 2 hours)] ", stdout);
906 fputs("[-vlruinterval <seconds between VLRU scans> (default is 2 minutes)] ", stdout);
907 fputs("[-vlrumax <max volumes to soft detach in one VLRU scan> (default is 8)] ", stdout);
908 #elif AFS_PTHREAD_ENV
909 fputs("[-vattachpar <number of volume attach threads> (default is 1)] ", stdout);
912 fputs("[-m <min percentage spare in partition>] ", stdout);
914 #if defined(AFS_SGI_ENV)
915 fputs("[-lock (keep fileserver from swapping)] ", stdout);
917 fputs("[-L (large server conf)] ", stdout);
918 fputs("[-S (small server conf)] ", stdout);
919 fputs("[-k <stack size>] ", stdout);
920 fputs("[-realm <Kerberos realm name>] ", stdout);
921 fputs("[-udpsize <size of socket buffer in bytes>] ", stdout);
922 fputs("[-sendsize <size of send buffer in bytes>] ", stdout);
923 fputs("[-abortthreshold <abort threshold>] ", stdout);
924 /* fputs("[-enable_peer_stats] ", stdout); */
925 /* fputs("[-enable_process_stats] ", stdout); */
926 fputs("[-help]\n", stdout);
928 ViceLog(0, ("%s", buffer));
937 ParseRights(char *arights)
943 if (!arights || !strcmp(arights, "")) {
944 printf("Missing list of mode bits on -implicit option\n");
947 if (!strcmp(arights, "none"))
949 else if (!strcmp(arights, "read"))
950 mode = PRSFS_READ | PRSFS_LOOKUP;
951 else if (!strcmp(arights, "write"))
953 PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
954 PRSFS_WRITE | PRSFS_LOCK;
955 else if (!strcmp(arights, "all"))
957 PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
958 PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER;
960 len = strlen(arights);
961 for (i = 0; i < len; i++) {
966 mode |= PRSFS_LOOKUP;
968 mode |= PRSFS_INSERT;
970 mode |= PRSFS_DELETE;
976 mode |= PRSFS_ADMINISTER;
994 printf("Illegal -implicit rights character '%c'.\n", tc);
1003 * Limit MAX_FILESERVER_THREAD by the system limit on the number of
1004 * pthreads (sysconf(_SC_THREAD_THREADS_MAX)), if applicable and
1007 * AIX: sysconf() limit is real
1008 * HP-UX: sysconf() limit is real
1009 * IRIX: sysconf() limit is apparently NOT real -- too small
1010 * DUX: sysconf() limit is apparently NOT real -- too big
1011 * Linux: sysconf() limit is apparently NOT real -- too big
1012 * Solaris: no sysconf() limit
1015 max_fileserver_thread(void)
1017 #if defined(AFS_PTHREAD_ENV)
1018 #if defined(AFS_AIX_ENV) || defined(AFS_HPUX_ENV)
1021 ans = sysconf(_SC_THREAD_THREADS_MAX);
1022 if (0 < ans && ans < MAX_FILESERVER_THREAD)
1025 #endif /* defined(AFS_PTHREAD_ENV) */
1026 return MAX_FILESERVER_THREAD;
1030 ParseArgs(int argc, char *argv[])
1032 int SawL = 0, SawS = 0, SawVC = 0;
1033 int Sawrxpck = 0, Sawsmall = 0, Sawlarge = 0, Sawcbs = 0, Sawlwps =
1037 int bufSize = 0; /* temp variable to read in udp socket buf size */
1039 for (i = 1; i < argc; i++) {
1040 if (!strcmp(argv[i], "-d")) {
1041 if ((i + 1) >= argc) {
1042 fprintf(stderr, "missing argument for -d\n");
1045 debuglevel = atoi(argv[++i]);
1046 LogLevel = debuglevel;
1047 } else if (!strcmp(argv[i], "-banner")) {
1049 } else if (!strcmp(argv[i], "-implicit")) {
1050 if ((i + 1) >= argc) {
1051 fprintf(stderr, "missing argument for -implicit\n");
1054 implicitAdminRights = ParseRights(argv[++i]);
1055 if (implicitAdminRights < 0)
1056 return implicitAdminRights;
1057 } else if (!strcmp(argv[i], "-readonly")) {
1059 } else if (!strcmp(argv[i], "-L")) {
1061 } else if (!strcmp(argv[i], "-S")) {
1063 } else if (!strcmp(argv[i], "-p")) {
1065 max_fileserver_thread() - FILESERVER_HELPER_THREADS;
1067 if ((i + 1) >= argc) {
1068 fprintf(stderr, "missing argument for -p\n");
1071 lwps = atoi(argv[++i]);
1072 if (lwps > lwps_max)
1076 } else if (!strcmp(argv[i], "-b")) {
1078 if ((i + 1) >= argc) {
1079 fprintf(stderr, "missing argument for -b\n");
1082 buffs = atoi(argv[++i]);
1083 } else if (!strcmp(argv[i], "-l")) {
1085 if ((i + 1) >= argc) {
1086 fprintf(stderr, "missing argument for -l\n");
1089 large = atoi(argv[++i]);
1090 } else if (!strcmp(argv[i], "-vc")) {
1092 if ((i + 1) >= argc) {
1093 fprintf(stderr, "missing argument for -vc\n");
1096 volcache = atoi(argv[++i]);
1097 } else if (!strcmp(argv[i], "-novbc")) {
1099 } else if (!strcmp(argv[i], "-rxpck")) {
1101 if ((i + 1) >= argc) {
1102 fprintf(stderr, "missing argument for -rxpck\n");
1105 rxpackets = atoi(argv[++i]);
1106 #ifdef AFS_PTHREAD_ENV
1107 } else if (!strcmp(argv[i], "-vattachpar")) {
1108 if ((i + 1) >= argc) {
1109 fprintf(stderr, "missing argument for %s\n", argv[i]);
1112 vol_attach_threads = atoi(argv[++i]);
1113 #endif /* AFS_PTHREAD_ENV */
1114 #ifdef AFS_DEMAND_ATTACH_FS
1115 } else if (!strcmp(argv[i], "-fs-state-dont-save")) {
1116 fs_state.options.fs_state_save = 0;
1117 } else if (!strcmp(argv[i], "-fs-state-dont-restore")) {
1118 fs_state.options.fs_state_restore = 0;
1119 } else if (!strcmp(argv[i], "-fs-state-verify")) {
1120 if ((i + 1) >= argc) {
1121 fprintf(stderr, "missing argument for %s\n", argv[i]);
1125 if (!strcmp(argv[i], "none")) {
1126 fs_state.options.fs_state_verify_before_save = 0;
1127 fs_state.options.fs_state_verify_after_restore = 0;
1128 } else if (!strcmp(argv[i], "save")) {
1129 fs_state.options.fs_state_verify_after_restore = 0;
1130 } else if (!strcmp(argv[i], "restore")) {
1131 fs_state.options.fs_state_verify_before_save = 0;
1132 } else if (!strcmp(argv[i], "both")) {
1135 fprintf(stderr, "invalid argument for %s\n", argv[i-1]);
1138 } else if (!strcmp(argv[i], "-vhashsize")) {
1139 if ((i + 1) >= argc) {
1140 fprintf(stderr, "missing argument for %s\n", argv[i]);
1143 VSetVolHashSize(atoi(argv[++i]));
1144 } else if (!strcmp(argv[i], "-vlrudisable")) {
1145 VLRU_SetOptions(VLRU_SET_ENABLED, 0);
1146 } else if (!strcmp(argv[i], "-vlruthresh")) {
1147 if ((i + 1) >= argc) {
1148 fprintf(stderr, "missing argument for %s\n", argv[i]);
1151 VLRU_SetOptions(VLRU_SET_THRESH, 60*atoi(argv[++i]));
1152 } else if (!strcmp(argv[i], "-vlruinterval")) {
1153 if ((i + 1) >= argc) {
1154 fprintf(stderr, "missing argument for %s\n", argv[i]);
1157 VLRU_SetOptions(VLRU_SET_INTERVAL, atoi(argv[++i]));
1158 } else if (!strcmp(argv[i], "-vlrumax")) {
1159 if ((i + 1) >= argc) {
1160 fprintf(stderr, "missing argument for %s\n", argv[i]);
1163 VLRU_SetOptions(VLRU_SET_MAX, atoi(argv[++i]));
1164 #endif /* AFS_DEMAND_ATTACH_FS */
1165 } else if (!strcmp(argv[i], "-s")) {
1167 if ((i + 1) >= argc) {
1168 fprintf(stderr, "missing argument for -s\n");
1171 nSmallVns = atoi(argv[++i]);
1172 } else if (!strcmp(argv[i], "-abortthreshold")) {
1173 if ((i + 1) >= argc) {
1174 fprintf(stderr, "missing argument for -abortthreshold\n");
1177 abort_threshold = atoi(argv[++i]);
1178 } else if (!strcmp(argv[i], "-k")) {
1179 if ((i + 1) >= argc) {
1180 fprintf(stderr, "missing argument for -k\n");
1183 stack = atoi(argv[++i]);
1185 #if defined(AFS_SGI_ENV)
1186 else if (!strcmp(argv[i], "-lock")) {
1190 else if (!strcmp(argv[i], "-spare")) {
1191 if ((i + 1) >= argc) {
1192 fprintf(stderr, "missing argument for -spare\n");
1195 BlocksSpare = atoi(argv[++i]);
1197 } else if (!strcmp(argv[i], "-pctspare")) {
1198 if ((i + 1) >= argc) {
1199 fprintf(stderr, "missing argument for -pctspare\n");
1202 PctSpare = atoi(argv[++i]);
1203 BlocksSpare = 0; /* has non-zero default */
1205 } else if (!strcmp(argv[i], "-w")) {
1206 if ((i + 1) >= argc) {
1207 fprintf(stderr, "missing argument for -w\n");
1210 fiveminutes = atoi(argv[++i]);
1211 } else if (!strcmp(argv[i], "-hr")) {
1213 if ((i + 1) >= argc) {
1214 fprintf(stderr, "missing argument for -hr\n");
1217 hr = atoi(argv[++i]);
1218 if ((hr < 1) || (hr > 36)) {
1220 ("host acl refresh interval of %d hours is invalid; hours must be between 1 and 36\n\n",
1224 hostaclRefresh = hr * 60 * 60;
1225 } else if (!strcmp(argv[i], "-rxdbg"))
1227 else if (!strcmp(argv[i], "-rxdbge"))
1229 else if (!strcmp(argv[i], "-cb")) {
1231 if ((i + 1) >= argc) {
1232 fprintf(stderr, "missing argument for -cb\n");
1235 numberofcbs = atoi(argv[++i]);
1236 if ((numberofcbs < 10000) || (numberofcbs > 2147483647)) {
1238 ("number of cbs %d invalid; must be between 10000 and 2147483647\n",
1242 } else if (!strcmp(argv[i], "-busyat")) {
1244 if ((i + 1) >= argc) {
1245 fprintf(stderr, "missing argument for -busyat\n");
1248 busy_threshold = atoi(argv[++i]);
1249 if (busy_threshold < 10) {
1251 ("Busy threshold %d is too low, will compute default.\n",
1255 } else if (!strcmp(argv[i], "-nobusy"))
1257 #ifdef AFS_AIX32_ENV
1258 else if (!strcmp(argv[i], "-m")) {
1259 extern int aixlow_water;
1260 if ((i + 1) >= argc) {
1261 fprintf(stderr, "missing argument for -m\n");
1264 aixlow_water = atoi(argv[++i]);
1265 if ((aixlow_water < 0) || (aixlow_water > 30)) {
1266 printf("space reserved %d% invalid; must be between 0-30%\n",
1272 else if (!strcmp(argv[i], "-nojumbo")) {
1274 } else if (!strcmp(argv[i], "-rxbind")) {
1276 } else if (!strcmp(argv[i], "-rxmaxmtu")) {
1277 if ((i + 1) >= argc) {
1278 fprintf(stderr, "missing argument for -rxmaxmtu\n");
1281 rxMaxMTU = atoi(argv[++i]);
1282 if ((rxMaxMTU < RX_MIN_PACKET_SIZE) ||
1283 (rxMaxMTU > RX_MAX_PACKET_DATA_SIZE)) {
1284 printf("rxMaxMTU %d%% invalid; must be between %d-%d\n",
1285 rxMaxMTU, RX_MIN_PACKET_SIZE,
1286 RX_MAX_PACKET_DATA_SIZE);
1289 } else if (!strcmp(argv[i], "-realm")) {
1290 extern char local_realms[AFS_NUM_LREALMS][AFS_REALM_SZ];
1291 extern int num_lrealms;
1292 if ((i + 1) >= argc) {
1293 fprintf(stderr, "missing argument for -realm\n");
1296 if (strlen(argv[++i]) >= AFS_REALM_SZ) {
1298 ("-realm argument must contain fewer than %d characters.\n",
1302 if (num_lrealms == -1)
1304 if (num_lrealms >= AFS_NUM_LREALMS) {
1306 ("a maximum of %d -realm arguments can be specified.\n",
1310 strncpy(local_realms[num_lrealms++], argv[i], AFS_REALM_SZ);
1311 } else if (!strcmp(argv[i], "-udpsize")) {
1312 if ((i + 1) >= argc) {
1313 printf("You have to specify -udpsize <integer value>\n");
1316 bufSize = atoi(argv[++i]);
1317 if (bufSize < rx_GetMinUdpBufSize())
1319 ("Warning:udpsize %d is less than minimum %d; ignoring\n",
1320 bufSize, rx_GetMinUdpBufSize());
1322 udpBufSize = bufSize;
1323 } else if (!strcmp(argv[i], "-sendsize")) {
1324 if ((i + 1) >= argc) {
1325 printf("You have to specify -sendsize <integer value>\n");
1328 bufSize = atoi(argv[++i]);
1329 if (bufSize < 16384)
1331 ("Warning:sendsize %d is less than minimum %d; ignoring\n",
1334 sendBufSize = bufSize;
1335 } else if (!strcmp(argv[i], "-enable_peer_stats")) {
1336 rx_enablePeerRPCStats();
1337 } else if (!strcmp(argv[i], "-enable_process_stats")) {
1338 rx_enableProcessRPCStats();
1340 else if (strcmp(argv[i], "-auditlog") == 0) {
1343 char oldName[MAXPATHLEN];
1344 char *fileName = argv[++i];
1346 #ifndef AFS_NT40_ENV
1347 struct stat statbuf;
1349 if ((lstat(fileName, &statbuf) == 0)
1350 && (S_ISFIFO(statbuf.st_mode))) {
1351 flags = O_WRONLY | O_NONBLOCK;
1355 strcpy(oldName, fileName);
1356 strcat(oldName, ".old");
1357 renamefile(fileName, oldName);
1358 flags = O_WRONLY | O_TRUNC | O_CREAT;
1360 tempfd = open(fileName, flags, 0666);
1362 auditout = fdopen(tempfd, "a");
1364 osi_audit_file(auditout);
1366 printf("Warning: auditlog %s not writable, ignored.\n", fileName);
1368 printf("Warning: auditlog %s not writable, ignored.\n", fileName);
1370 #ifndef AFS_NT40_ENV
1371 else if (strcmp(argv[i], "-syslog") == 0) {
1372 /* set syslog logging flag */
1373 serverLogSyslog = 1;
1374 } else if (strncmp(argv[i], "-syslog=", 8) == 0) {
1375 serverLogSyslog = 1;
1376 serverLogSyslogFacility = atoi(argv[i] + 8);
1379 else if (strcmp(argv[i], "-mrafslogs") == 0) {
1380 /* set syslog logging flag */
1383 else if (strcmp(argv[i], "-saneacls") == 0) {
1391 printf("Only one of -L, or -S must be specified\n");
1402 numberofcbs = 20000;
1418 numberofcbs = 64000;
1427 busy_threshold = 3 * rxpackets / 2;
1437 NewParms(int initializing)
1439 static struct afs_stat sbuf;
1442 char *argv[MAXPARMS];
1445 if (!(afs_stat("/vice/file/parms", &sbuf))) {
1446 parms = (char *)malloc(sbuf.st_size);
1449 fd = afs_open("parms", O_RDONLY, 0666);
1451 ViceLog(0, ("Open for parms failed with errno = %d\n", errno));
1455 i = read(fd, parms, sbuf.st_size);
1457 if (i != sbuf.st_size) {
1459 ViceLog(0, ("Read on parms failed with errno = %d\n", errno));
1462 ("Read on parms failed; expected %d bytes but read %d\n",
1469 for (i = 0; i < MAXPARMS; argv[i++] = 0);
1471 for (argc = i = 0; i < sbuf.st_size; i++) {
1472 if ((*(parms + i) != ' ') && (*(parms + i) != '\n')) {
1473 if (argv[argc] == 0)
1474 argv[argc] = (parms + i);
1476 *(parms + i) = '\0';
1477 if (argv[argc] != 0) {
1478 if (++argc == MAXPARMS)
1481 while ((*(parms + i + 1) == ' ')
1482 || (*(parms + i + 1) == '\n'))
1486 if (ParseArgs(argc, argv) == 0) {
1487 ViceLog(0, ("Change parameters to:"));
1489 ViceLog(0, ("Invalid parameter in:"));
1491 for (i = 0; i < argc; i++) {
1492 ViceLog(0, (" %s", argv[i]));
1496 } else if (!initializing)
1498 ("Received request to change parms but no parms file exists\n"));
1503 /* Miscellaneous routines */
1507 ViceLog(0, ("%s\n", msg));
1519 * If this fails, it's because something major is wrong, and is not
1520 * likely to be time dependent.
1522 code = pr_Initialize(2, AFSDIR_SERVER_ETC_DIRPATH, 0);
1525 ("Couldn't initialize protection library; code=%d.\n", code));
1529 #ifdef AFS_PTHREAD_ENV
1530 assert(pthread_key_create(&viced_uclient_key, NULL) == 0);
1533 SystemId = SYSADMINID;
1534 SystemAnyUser = ANYUSERID;
1535 SystemAnyUserCPS.prlist_len = 0;
1536 SystemAnyUserCPS.prlist_val = NULL;
1537 AnonCPS.prlist_len = 0;
1538 AnonCPS.prlist_val = NULL;
1540 code = pr_GetCPS(SystemAnyUser, &SystemAnyUserCPS);
1543 ("Couldn't get CPS for AnyUser, will try again in 30 seconds; code=%d.\n",
1547 code = pr_GetCPS(ANONYMOUSID, &AnonCPS);
1550 ("Couldn't get Anonymous CPS, exiting; code=%d.\n",
1554 AnonymousID = ANONYMOUSID;
1557 #ifdef AFS_PTHREAD_ENV
1559 #else /* AFS_PTHREAD_ENV */
1561 #endif /* AFS_PTHREAD_ENV */
1565 struct rx_connection *serverconns[MAXSERVERS];
1566 struct ubik_client *cstruct;
1569 vl_Initialize(const char *confDir)
1571 afs_int32 code, scIndex = 0, i;
1572 struct afsconf_dir *tdir;
1573 struct rx_securityClass *sc;
1574 struct afsconf_cell info;
1576 tdir = afsconf_Open(confDir);
1579 ("Could not open configuration directory (%s).\n", confDir));
1582 code = afsconf_ClientAuth(tdir, &sc, &scIndex);
1584 ViceLog(0, ("Could not get security object for localAuth\n"));
1587 code = afsconf_GetCellInfo(tdir, NULL, AFSCONF_VLDBSERVICE, &info);
1588 if (info.numServers > MAXSERVERS) {
1590 ("vl_Initialize: info.numServers=%d (> MAXSERVERS=%d)\n",
1591 info.numServers, MAXSERVERS));
1594 for (i = 0; i < info.numServers; i++)
1596 rx_NewConnection(info.hostAddr[i].sin_addr.s_addr,
1597 info.hostAddr[i].sin_port, USER_SERVICE_ID, sc,
1599 code = ubik_ClientInit(serverconns, &cstruct);
1600 afsconf_Close(tdir);
1602 ViceLog(0, ("vl_Initialize: ubik client init failed.\n"));
1608 #define SYSIDMAGIC 0x88aabbcc
1609 #define SYSIDVERSION 1
1614 afs_int32 fd, nentries, i;
1615 struct versionStamp vsn;
1616 struct afs_stat status;
1619 if ((afs_stat(AFSDIR_SERVER_SYSID_FILEPATH, &status))
1620 || (status.st_size <= 0)) {
1621 ViceLog(0, ("%s: doesn't exist\n", AFSDIR_SERVER_SYSID_FILEPATH));
1624 if (!(fd = afs_open(AFSDIR_SERVER_SYSID_FILEPATH, O_RDONLY, 0))) {
1626 ("%s: can't open (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1630 if ((i = read(fd, (char *)&vsn, sizeof(vsn))) != sizeof(vsn)) {
1632 ("%s: Read failed (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1636 if (vsn.magic != SYSIDMAGIC) {
1638 ("%s: wrong magic %x (we support %x)\n",
1639 AFSDIR_SERVER_SYSID_FILEPATH, vsn.magic, SYSIDMAGIC));
1642 if (vsn.version != SYSIDVERSION) {
1644 ("%s: wrong version %d (we support %d)\n",
1645 AFSDIR_SERVER_SYSID_FILEPATH, vsn.version, SYSIDVERSION));
1649 read(fd, (char *)&uuid,
1650 sizeof(struct afsUUID))) != sizeof(struct afsUUID)) {
1652 ("%s: read of uuid failed (%d)\n",
1653 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1656 afs_ntohuuid(&uuid);
1659 read(fd, (char *)&nentries,
1660 sizeof(afs_int32))) != sizeof(afs_int32)) {
1662 ("%s: Read of entries failed (%d)\n",
1663 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1666 if (nentries <= 0 || nentries > ADDRSPERSITE) {
1668 ("%s: invalid num of interfaces: %d\n",
1669 AFSDIR_SERVER_SYSID_FILEPATH, nentries));
1672 if (FS_HostAddr_cnt == 0) {
1673 FS_HostAddr_cnt = nentries;
1674 for (i = 0; i < nentries; i++) {
1675 if (read(fd, (char *)&FS_HostAddrs[i], sizeof(afs_int32)) !=
1676 sizeof(afs_int32)) {
1678 ("%s: Read of addresses failed (%d)\n",
1679 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1680 FS_HostAddr_cnt = 0; /* reset it */
1686 ("%s: address list ignored (NetInfo/NetRestrict override)\n",
1687 AFSDIR_SERVER_SYSID_FILEPATH));
1697 struct versionStamp vsn;
1698 struct afs_stat status;
1701 if (!afs_stat(AFSDIR_SERVER_SYSID_FILEPATH, &status)) {
1703 * File exists; keep the old one around
1705 renamefile(AFSDIR_SERVER_SYSID_FILEPATH,
1706 AFSDIR_SERVER_OLDSYSID_FILEPATH);
1708 fd = afs_open(AFSDIR_SERVER_SYSID_FILEPATH, O_WRONLY | O_TRUNC | O_CREAT,
1712 ("%s: can't create (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1716 vsn.magic = SYSIDMAGIC;
1718 if ((i = write(fd, (char *)&vsn, sizeof(vsn))) != sizeof(vsn)) {
1720 ("%s: write failed (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1725 afs_htonuuid(&uuid);
1727 write(fd, (char *)&uuid,
1728 sizeof(struct afsUUID))) != sizeof(struct afsUUID)) {
1730 ("%s: write of uuid failed (%d)\n",
1731 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1735 write(fd, (char *)&FS_HostAddr_cnt,
1736 sizeof(afs_int32))) != sizeof(afs_int32)) {
1738 ("%s: write of # of entries failed (%d)\n",
1739 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1742 for (i = 0; i < FS_HostAddr_cnt; i++) {
1743 if (write(fd, (char *)&FS_HostAddrs[i], sizeof(afs_int32)) !=
1744 sizeof(afs_int32)) {
1746 ("%s: write of addresses failed (%d)\n",
1747 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1757 * This routine sets up the buffers for the VL_RegisterAddrs RPC. All addresses
1758 * in FS_HostAddrs[] are in NBO, while the RPC treats them as a "blob" of data
1759 * and so we need to convert each of them into HBO which is what the extra
1760 * array called FS_HostAddrs_HBO is used here.
1767 extern int VL_RegisterAddrs();
1768 afs_uint32 FS_HostAddrs_HBO[ADDRSPERSITE];
1771 for (i = 0; i < FS_HostAddr_cnt; i++)
1772 FS_HostAddrs_HBO[i] = ntohl(FS_HostAddrs[i]);
1773 addrs.bulkaddrs_len = FS_HostAddr_cnt;
1774 addrs.bulkaddrs_val = (afs_uint32 *) FS_HostAddrs_HBO;
1775 code = ubik_VL_RegisterAddrs(cstruct, 0, &FS_HostUUID, 0, &addrs);
1777 if (code == VL_MULTIPADDR) {
1779 ("VL_RegisterAddrs rpc failed; The IP address exists on a different server; repair it\n"));
1781 ("VL_RegisterAddrs rpc failed; See VLLog for details\n"));
1783 } else if (code == RXGEN_OPCODE) {
1785 ("vlserver doesn't support VL_RegisterAddrs rpc; ignored\n"));
1786 FS_registered = 2; /* So we don't have to retry in the gc daemon */
1789 ("VL_RegisterAddrs rpc failed; will retry periodically (code=%d, err=%d)\n",
1793 FS_registered = 2; /* So we don't have to retry in the gc daemon */
1804 extern int rxi_numNetAddrs;
1805 extern afs_uint32 rxi_NetAddrs[];
1807 #ifndef AFS_NT40_ENV
1808 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH || AFSDIR_SERVER_NETINFO_FILEPATH) {
1810 * Find addresses we are supposed to register as per the netrestrict
1811 * and netinfo files (/usr/afs/local/NetInfo and
1812 * /usr/afs/local/NetRestict)
1815 afs_int32 code = parseNetFiles(FS_HostAddrs, NULL, NULL,
1816 ADDRSPERSITE, reason,
1817 AFSDIR_SERVER_NETINFO_FILEPATH,
1818 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
1820 ViceLog(0, ("Can't register any valid addresses: %s\n", reason));
1823 FS_HostAddr_cnt = (afs_uint32) code;
1827 FS_HostAddr_cnt = rx_getAllAddr(FS_HostAddrs, ADDRSPERSITE);
1830 if (FS_HostAddr_cnt == 1 && rxBind == 1)
1831 code = FS_HostAddrs[0];
1833 code = htonl(INADDR_ANY);
1843 * If this fails, it's because something major is wrong, and is not
1844 * likely to be time dependent.
1846 code = vl_Initialize(AFSDIR_SERVER_ETC_DIRPATH);
1849 ("Couldn't initialize protection library; code=%d.\n", code));
1853 /* Read or create the sysid file and register the fileserver's
1854 * IP addresses with the vlserver.
1856 code = ReadSysIdFile();
1858 /* Need to create the file */
1859 ViceLog(0, ("Creating new SysID file\n"));
1860 if ((code = afs_uuid_create(&FS_HostUUID))) {
1861 ViceLog(0, ("Failed to create new uuid: %d\n", code));
1865 /* A good sysid file exists; inform the vlserver. If any conflicts,
1866 * we always use the latest interface available as the real truth.
1869 code = Do_VLRegisterRPC();
1874 main(int argc, char *argv[])
1878 struct rx_securityClass *sc[4];
1879 struct rx_service *tservice;
1880 #ifdef AFS_PTHREAD_ENV
1881 pthread_t serverPid;
1882 pthread_attr_t tattr;
1883 #else /* AFS_PTHREAD_ENV */
1884 PROCESS parentPid, serverPid;
1885 #endif /* AFS_PTHREAD_ENV */
1887 int minVnodesRequired; /* min size of vnode cache */
1888 #ifndef AFS_NT40_ENV
1889 struct rlimit rlim; /* max number of open file descriptors */
1893 afs_uint32 rx_bindhost;
1895 #ifdef AFS_AIX32_ENV
1896 struct sigaction nsa;
1898 sigemptyset(&nsa.sa_mask);
1899 nsa.sa_handler = SIG_DFL;
1900 nsa.sa_flags = SA_FULLDUMP;
1901 sigaction(SIGABRT, &nsa, NULL);
1902 sigaction(SIGSEGV, &nsa, NULL);
1906 /* Initialize dirpaths */
1907 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
1909 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
1911 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
1915 #ifndef AFS_QUIETFS_ENV
1916 console = afs_fopen("/dev/console", "w");
1919 if (ParseArgs(argc, argv)) {
1923 #ifdef AFS_PTHREAD_ENV
1924 assert(pthread_mutex_init(&fileproc_glock_mutex, NULL) == 0);
1925 #endif /* AFS_PTHREAD_ENV */
1927 #ifdef AFS_SGI_VNODE_GLUE
1928 if (afs_init_kernel_config(-1) < 0) {
1930 ("Can't determine NUMA configuration, not starting fileserver.\n");
1934 confDir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
1936 fprintf(stderr, "Unable to open config directory %s\n",
1937 AFSDIR_SERVER_ETC_DIRPATH);
1943 /* Open FileLog on stdout, stderr, fd 1 and fd2 (for perror), sigh. */
1944 #ifndef AFS_NT40_ENV
1945 serverLogSyslogTag = "fileserver";
1947 OpenLog(AFSDIR_SERVER_FILELOG_FILEPATH);
1950 if (SawSpare && SawPctSpare) {
1951 ViceLog(0, ("Both -spare and -pctspare specified, exiting.\n"));
1954 #ifdef AFS_SGI_XFS_IOPS_ENV
1955 ViceLog(0, ("XFS/EFS File server starting\n"));
1957 ViceLog(0, ("File server starting\n"));
1960 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
1961 /* initialize the pthread soft signal handler thread */
1965 /* install signal handlers for controlling the fileserver process */
1966 ResetCheckSignal(); /* set CheckSignal_Signal() sig handler */
1967 ResetCheckDescriptors(); /* set CheckDescriptors_Signal() sig handler */
1969 #if defined(AFS_SGI_ENV)
1970 /* give this guy a non-degrading priority so help busy servers */
1971 schedctl(NDPRI, 0, NDPNORMMAX);
1975 #ifndef AFS_NT40_ENV
1976 nice(-5); /* TODO: */
1979 assert(DInit(buffs) == 0);
1982 if (afs_winsockInit() < 0) {
1983 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
1984 ViceLog(0, ("File server failed to intialize winsock.\n"));
1990 /* if we support more than 16 threads, then we better have the ability
1991 ** to keep open a large number of files simultaneously
1993 #if defined(AFS_AIX_ENV) && !defined(AFS_AIX42_ENV)
1994 curLimit = OPEN_MAX; /* for pre AIX 4.2 systems */
1995 #elif defined(AFS_NT40_ENV)
1996 curLimit = NT_OPEN_MAX; /* open file descriptor limit on NT */
1999 curLimit = 0; /* the number of open file descriptors */
2000 code = getrlimit(RLIMIT_NOFILE, &rlim);
2002 curLimit = rlim.rlim_cur;
2003 rlim.rlim_cur = rlim.rlim_max;
2004 code = setrlimit(RLIMIT_NOFILE, &rlim);
2006 curLimit = rlim.rlim_max;
2009 ViceLog(0, ("Failed to increase open file limit, using default\n"));
2011 #endif /* defined(AFS_AIX_ENV) && !defined(AFS_AIX42_ENV) */
2013 curLimit -= 32; /* leave a slack of 32 file descriptors */
2014 if (lwps > curLimit) {
2018 lwps = 16; /* default to a maximum of 16 threads */
2020 ("The system supports a max of %d open files and we are starting %d threads\n",
2023 #ifndef AFS_PTHREAD_ENV
2024 assert(LWP_InitializeProcessSupport(LWP_MAX_PRIORITY - 2, &parentPid) ==
2026 #endif /* !AFS_PTHREAD_ENV */
2028 /* Initialize volume support */
2030 V_BreakVolumeCallbacks = BreakVolumeCallBacksLater;
2033 #ifdef AFS_PTHREAD_ENV
2034 SetLogThreadNumProgram( threadNum );
2037 /* initialize libacl routines */
2038 acl_Initialize(ACL_VERSION);
2040 /* initialize RX support */
2041 #ifndef AFS_NT40_ENV
2042 rxi_syscallp = viced_syscall;
2044 rx_extraPackets = rxpackets;
2045 rx_extraQuota = 4; /* for outgoing prserver calls from R threads */
2046 rx_SetBusyThreshold(busy_threshold, VBUSY);
2047 rx_SetCallAbortThreshold(abort_threshold);
2048 rx_SetConnAbortThreshold(abort_threshold);
2049 stackSize = lwps * 4000;
2050 if (stackSize < 32000)
2052 else if (stackSize > 44000)
2054 #if defined(AFS_HPUX_ENV) || defined(AFS_SUN_ENV) || defined(AFS_SGI51_ENV)
2055 rx_SetStackSize(1, stackSize);
2058 rx_SetUdpBufSize(udpBufSize); /* set the UDP buffer size for receive */
2059 rx_bindhost = SetupVL();
2061 if (rx_InitHost(rx_bindhost, (int)htons(7000)) < 0) {
2062 ViceLog(0, ("Cannot initialize RX\n"));
2065 if (!rxJumbograms) {
2066 /* Don't send and don't allow 3.4 clients to send jumbograms. */
2069 if (rxMaxMTU != -1) {
2070 rx_SetMaxMTU(rxMaxMTU);
2073 rx_SetRxDeadTime(30);
2074 sc[0] = rxnull_NewServerSecurityObject();
2075 sc[1] = 0; /* rxvab_NewServerSecurityObject(key1, 0) */
2076 sc[2] = rxkad_NewServerSecurityObject(rxkad_clear, NULL, get_key, NULL);
2077 sc[3] = rxkad_NewServerSecurityObject(rxkad_crypt, NULL, get_key, NULL);
2078 tservice = rx_NewServiceHost(rx_bindhost, /* port */ 0, /* service id */
2079 1, /*service name */
2081 /* security classes */ sc,
2082 /* numb sec classes */
2083 4, RXAFS_ExecuteRequest);
2086 ("Failed to initialize RX, probably two servers running.\n"));
2089 rx_SetMinProcs(tservice, 3);
2090 rx_SetMaxProcs(tservice, lwps);
2091 rx_SetCheckReach(tservice, 1);
2094 rx_NewService(0, RX_STATS_SERVICE_ID, "rpcstats", sc, 4,
2095 RXSTATS_ExecuteRequest);
2097 ViceLog(0, ("Failed to initialize rpc stat service.\n"));
2100 rx_SetMinProcs(tservice, 2);
2101 rx_SetMaxProcs(tservice, 4);
2104 * Enable RX hot threads, which allows the listener thread to trade
2105 * places with an idle thread and moves the context switch from listener
2106 * to worker out of the critical path.
2108 rx_EnableHotThread();
2110 /* Some rx debugging */
2111 if (rxlog || eventlog) {
2112 debugFile = afs_fopen("rx_dbg", "w");
2114 rx_debugFile = debugFile;
2116 rxevent_debugFile = debugFile;
2119 init_sys_error_to_et(); /* Set up error table translation */
2120 h_InitHostPackage(); /* set up local cellname and realmname */
2121 InitCallBack(numberofcbs);
2126 ViceLog(0, ("Fatal error in library initialization, exiting!!\n"));
2132 ViceLog(0, ("Fatal error in protection initialization, exiting!!\n"));
2136 /* allow super users to manage RX statistics */
2137 rx_SetRxStatUserOk(fs_rxstat_userok);
2139 rx_StartServer(0); /* now start handling requests */
2141 /* we ensure that there is enough space in the vnode buffer to satisfy
2142 ** requests from all concurrent threads.
2143 ** the maximum number of vnodes used by a single thread at any one time
2144 ** is three ( "link" uses three vnodes simultaneously, one vLarge and
2145 ** two vSmall for linking files and two vLarge and one vSmall for linking
2148 minVnodesRequired = 2 * lwps + 1;
2149 if (minVnodesRequired > nSmallVns) {
2150 nSmallVns = minVnodesRequired;
2152 ("Overriding -s command line parameter with %d\n",
2155 if (minVnodesRequired > large) {
2156 large = minVnodesRequired;
2157 ViceLog(0, ("Overriding -l command line parameter with %d\n", large));
2160 /* We now do this after getting the listener up and running, so that client
2161 * connections don't timeout (maybe) if a file server is restarted, since it
2162 * will be available "real soon now". Worry about whether we can satisfy the
2163 * calls in the volume package itself.
2165 if (VInitVolumePackage(fileServer, large, nSmallVns, 0, volcache)) {
2167 ("Shutting down: errors encountered initializing volume package\n"));
2172 #ifdef AFS_DEMAND_ATTACH_FS
2173 if (fs_state.options.fs_state_restore) {
2176 * restore fileserver state */
2179 #endif /* AFS_DEMAND_ATTACH_FS */
2182 * We are done calling fopen/fdopen. It is safe to use a large
2183 * of the file descriptor cache.
2187 #ifdef AFS_PTHREAD_ENV
2188 ViceLog(5, ("Starting pthreads\n"));
2189 assert(pthread_attr_init(&tattr) == 0);
2190 assert(pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED) == 0);
2192 assert(pthread_create
2193 (&serverPid, &tattr, (void *)FiveMinuteCheckLWP,
2194 &fiveminutes) == 0);
2195 assert(pthread_create
2196 (&serverPid, &tattr, (void *)HostCheckLWP, &fiveminutes) == 0);
2197 assert(pthread_create
2198 (&serverPid, &tattr, (void *)FsyncCheckLWP, &fiveminutes) == 0);
2199 #else /* AFS_PTHREAD_ENV */
2200 ViceLog(5, ("Starting LWP\n"));
2201 assert(LWP_CreateProcess
2202 (FiveMinuteCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
2203 (void *)&fiveminutes, "FiveMinuteChecks",
2204 &serverPid) == LWP_SUCCESS);
2206 assert(LWP_CreateProcess
2207 (HostCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
2208 (void *)&fiveminutes, "HostCheck", &serverPid) == LWP_SUCCESS);
2209 assert(LWP_CreateProcess
2210 (FsyncCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
2211 (void *)&fiveminutes, "FsyncCheck", &serverPid) == LWP_SUCCESS);
2212 #endif /* AFS_PTHREAD_ENV */
2214 TM_GetTimeOfDay(&tp, 0);
2216 #ifndef AFS_QUIETFS_ENV
2217 if (console != NULL) {
2218 time_t t = tp.tv_sec;
2219 fprintf(console, "File server has started at %s\r",
2220 afs_ctime(&t, tbuffer, sizeof(tbuffer)));
2225 * Figure out the FileServer's name and primary address.
2227 ViceLog(0, ("Getting FileServer name...\n"));
2228 code = gethostname(FS_HostName, 64);
2230 ViceLog(0, ("gethostname() failed\n"));
2232 ViceLog(0, ("FileServer host name is '%s'\n", FS_HostName));
2234 ViceLog(0, ("Getting FileServer address...\n"));
2235 he = gethostbyname(FS_HostName);
2237 ViceLog(0, ("Can't find address for FileServer '%s'\n", FS_HostName));
2240 memcpy(&FS_HostAddr_NBO, he->h_addr, 4);
2241 (void)afs_inet_ntoa_r(FS_HostAddr_NBO, hoststr);
2242 FS_HostAddr_HBO = ntohl(FS_HostAddr_NBO);
2244 ("FileServer %s has address %s (0x%x or 0x%x in host byte order)\n",
2245 FS_HostName, hoststr, FS_HostAddr_NBO, FS_HostAddr_HBO));
2248 /* Install handler to catch the shutdown signal;
2249 * bosserver assumes SIGQUIT shutdown
2251 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
2252 softsig_signal(SIGQUIT, ShutDown_Signal);
2254 (void)signal(SIGQUIT, ShutDown_Signal);
2259 ("File Server started %s",
2260 afs_ctime(&t, tbuffer, sizeof(tbuffer))));
2261 #if FS_STATS_DETAILED
2262 afs_FullPerfStats.det.epoch.tv_sec = StartTime = tp.tv_sec;
2264 #ifdef AFS_PTHREAD_ENV
2266 sleep(1000); /* long time */
2268 #else /* AFS_PTHREAD_ENV */
2269 assert(LWP_WaitProcess(&parentPid) == LWP_SUCCESS);
2270 #endif /* AFS_PTHREAD_ENV */