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>
29 #include <sys/types.h>
30 #include <afs/procmgmt.h> /* signal(), kill(), wait(), etc. */
36 #include <WINNT/afsevent.h>
39 #include <netinet/in.h>
41 #include <unistd.h> /* sysconf() */
45 #endif /* ITIMER_REAL */
46 #include <sys/resource.h>
47 #endif /* AFS_NT40_ENV */
52 #ifdef AFS_PTHREAD_ENV
54 #else /* AFS_PTHREAD_ENV */
55 #include <afs/assert.h>
56 #endif /* AFS_PTHREAD_ENV */
59 #include <afs/ptclient.h>
60 #include <afs/afsint.h>
61 #include <afs/vldbint.h>
62 #include <afs/errors.h>
63 #include <afs/ihandle.h>
64 #include <afs/vnode.h>
65 #include <afs/volume.h>
67 #include <afs/cellconfig.h>
69 #include <afs/prs_fs.h>
72 #include <afs/afs_args.h>
73 #include <afs/vlserver.h>
74 #include <afs/afsutil.h>
75 #include <afs/fileutil.h>
76 #include <afs/ptuser.h>
77 #include <afs/audit.h>
78 #include <afs/partition.h>
81 #include <afs/netutils.h>
83 #include "viced_prototypes.h"
86 #ifdef AFS_PTHREAD_ENV
89 #if defined(AFS_SGI_ENV)
90 #include "sys/schedctl.h"
93 #include <rx/rx_globals.h>
94 #include <rx/rxstat_prototypes.h>
97 #define afs_stat stat64
98 #define afs_fstat fstat64
99 #define afs_open open64
100 #define afs_fopen fopen64
101 #else /* !O_LARGEFILE */
102 #define afs_stat stat
103 #define afs_fstat fstat
104 #define afs_open open
105 #define afs_fopen fopen
106 #endif /* !O_LARGEFILE */
110 void *ShutDown(void *);
111 static void ClearXStatValues(void);
112 static void NewParms(int);
113 static void PrintCounters(void);
114 static void ResetCheckDescriptors(void);
115 static void ResetCheckSignal(void);
116 static void *CheckSignal(void *);
118 extern int RXAFS_ExecuteRequest(struct rx_call *);
119 extern int RXSTATS_ExecuteRequest(struct rx_call *);
121 static afs_int32 Do_VLRegisterRPC(void);
123 int eventlog = 0, rxlog = 0;
125 FILE *console = NULL;
127 #ifdef AFS_PTHREAD_ENV
128 pthread_mutex_t fsync_glock_mutex;
129 pthread_cond_t fsync_cond;
132 #endif /* AFS_PTHREAD_ENV */
135 #define AFS_QUIETFS_ENV 1
136 #define NT_OPEN_MAX 1024 /* This is an arbitrary no. we came up with for
137 * now. We hope this will be replaced by a more
138 * intelligent estimate later. */
141 int SystemId; /* ViceID of "Administrators" */
142 int SystemAnyUser; /* Viceid of "System:AnyUser" */
143 prlist SystemAnyUserCPS; /* CPS for "system:AnyUser */
144 int AnonymousID = 0; /* ViceId of "Anonymous" */
145 prlist AnonCPS; /* CPS for "Anonymous" */
147 struct afsconf_dir *confDir; /* Configuration dir object */
149 int restartMode = RESTART_ORDINARY;
152 * Home for the performance statistics.
154 struct afs_PerfStats afs_perfstats;
157 extern int Statistics;
165 int rxJumbograms = 0; /* default is to not send and receive jumbograms. */
166 int rxBind = 0; /* don't bind */
167 int rxkadDisableDotCheck = 0; /* disable check for dot in principal name */
169 afs_int32 implicitAdminRights = PRSFS_LOOKUP; /* The ADMINISTER right is
171 afs_int32 readonlyServer = 0;
174 int stackSize = 24000;
175 int fiveminutes = 300; /* 5 minutes. Change this for debugging only */
176 int CurrentConnections = 0;
177 int hostaclRefresh = 7200; /* refresh host clients' acls every 2 hrs */
178 #if defined(AFS_SGI_ENV)
183 int rxpackets = 150; /* 100 */
184 int nSmallVns = 400; /* 200 */
185 int large = 400; /* 200 */
186 int volcache = 400; /* 400 */
187 int numberofcbs = 60000; /* 60000 */
188 int lwps = 9; /* 6 */
189 int buffs = 90; /* 70 */
190 int novbc = 0; /* Enable Volume Break calls */
191 int busy_threshold = 600;
192 int abort_threshold = 10;
193 int udpBufSize = 0; /* UDP buffer size for receive */
194 int sendBufSize = 16384; /* send buffer size */
195 int saneacls = 0; /* Sane ACLs Flag */
199 #ifdef AFS_PTHREAD_ENV
200 pthread_key_t viced_uclient_key;
203 #ifdef AFS_PTHREAD_ENV
204 pthread_key_t viced_uclient_key;
208 * FileServer's name and IP address, both network byte order and
211 #define ADDRSPERSITE 16 /* Same global is in rx/rx_user.c */
213 char FS_HostName[128] = "localhost";
214 afs_uint32 FS_HostAddr_NBO;
215 afs_uint32 FS_HostAddr_HBO;
216 afs_uint32 FS_HostAddrs[ADDRSPERSITE], FS_HostAddr_cnt = 0, FS_registered = 0;
217 /* All addresses in FS_HostAddrs are in NBO */
220 static void FlagMsg(void);
222 #ifdef AFS_DEMAND_ATTACH_FS
225 * fileserver mode support
227 * during fileserver shutdown, we have to track the graceful shutdown of
228 * certain background threads before we are allowed to dump state to
232 #if !defined(PTHREAD_RWLOCK_INITIALIZER) && defined(AFS_DARWIN80_ENV)
233 #define PTHREAD_RWLOCK_INITIALIZER {0x2DA8B3B4, {0}}
236 struct fs_state fs_state =
243 PTHREAD_COND_INITIALIZER,
244 PTHREAD_RWLOCK_INITIALIZER
246 #endif /* AFS_DEMAND_ATTACH_FS */
249 * Home for the performance statistics.
254 CheckDescriptors(void *unused)
257 struct afs_stat status;
258 register int tsize = getdtablesize();
260 for (i = 0; i < tsize; i++) {
261 if (afs_fstat(i, &status) != -1) {
262 printf("%d: dev %x, inode %u, length %u, type/mode %x\n", i,
263 status.st_dev, status.st_ino,
264 (unsigned int) status.st_size,
269 ResetCheckDescriptors();
272 } /*CheckDescriptors */
275 #ifdef AFS_PTHREAD_ENV
277 CheckSignal_Signal(int x)
283 ShutDown_Signal(int x)
289 CheckDescriptors_Signal(int x)
291 CheckDescriptors(NULL);
293 #else /* AFS_PTHREAD_ENV */
295 CheckSignal_Signal(int x)
297 IOMGR_SoftSig(CheckSignal, 0);
301 ShutDown_Signal(int x)
303 IOMGR_SoftSig(ShutDown, 0);
307 CheckDescriptors_Signal(int 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 (int)pthread_getspecific(rx_thread_id_key);
362 /* proc called by rxkad module to get a key */
364 get_key(void *arock, register afs_int32 akvno, struct ktc_encryptionKey *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, (struct ktc_encryptionKey *)tkey.key);
376 ViceLog(0, ("afsconf_GetKey failure: kvno %d code %d\n", akvno, code));
379 memcpy(akey, tkey.key, sizeof(tkey.key));
385 viced_syscall(afs_uint32 a3, afs_uint32 a4, void *a5)
390 #ifndef AFS_LINUX20_ENV
391 old = (void (*)(int))signal(SIGSYS, SIG_IGN);
393 rcode = syscall(AFS_SYSCALL, 28 /* AFSCALL_CALL */ , a3, a4, a5);
394 #ifndef AFS_LINUX20_ENV
402 #if !defined(AFS_NT40_ENV)
403 #include "AFS_component_version_number.c"
404 #endif /* !AFS_NT40_ENV */
406 #define MAXADMINNAME 64
407 char adminName[MAXADMINNAME];
413 struct afs_stat status;
415 if ((afs_stat("/AdminName", &status)) || /* if file does not exist */
416 (status.st_size <= 0) || /* or it is too short */
417 (status.st_size >= (MAXADMINNAME)) || /* or it is too long */
418 !(fd = afs_open("/AdminName", O_RDONLY, 0))) { /* or the open fails */
419 strcpy(adminName, "System:Administrators"); /* use the default name */
421 (void)read(fd, adminName, status.st_size); /* use name from the file */
424 close(fd); /* close fd if it was opened */
426 } /*CheckAdminName */
432 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
433 /* set our 'thread-id' so that the host hold table works */
434 MUTEX_ENTER(&rx_stats_mutex); /* protects rxi_pthread_hinum */
436 pthread_setspecific(rx_thread_id_key, (void *)rxi_pthread_hinum);
437 MUTEX_EXIT(&rx_stats_mutex);
439 ("Set thread id %d for '%s'\n",
440 pthread_getspecific(rx_thread_id_key), s));
444 /* This LWP does things roughly every 5 minutes */
446 FiveMinuteCheckLWP(void *unused)
451 ViceLog(1, ("Starting five minute check process\n"));
452 setThreadId("FiveMinuteCheckLWP");
454 #ifdef AFS_DEMAND_ATTACH_FS
456 while (fs_state.mode == FS_MODE_NORMAL) {
457 fs_state.FiveMinuteLWP_tranquil = 1;
463 #ifdef AFS_PTHREAD_ENV
465 #else /* AFS_PTHREAD_ENV */
466 IOMGR_Sleep(fiveminutes);
467 #endif /* AFS_PTHREAD_ENV */
469 #ifdef AFS_DEMAND_ATTACH_FS
471 if (fs_state.mode != FS_MODE_NORMAL) {
474 fs_state.FiveMinuteLWP_tranquil = 0;
478 /* close the log so it can be removed */
479 ReOpenLog(AFSDIR_SERVER_FILELOG_FILEPATH); /* don't trunc, just append */
480 ViceLog(2, ("Cleaning up timed out callbacks\n"));
481 if (CleanupTimedOutCallBacks())
482 ViceLog(5, ("Timed out callbacks deleted\n"));
483 ViceLog(2, ("Set disk usage statistics\n"));
485 if (FS_registered == 1)
487 /* Force wakeup in case we missed something; pthreads does timedwait */
488 #ifndef AFS_PTHREAD_ENV
489 LWP_NoYieldSignal(fsync_wait);
491 if (printBanner && (++msg & 1)) { /* Every 10 minutes */
492 time_t now = FT_ApproxTime();
493 if (console != NULL) {
494 #ifndef AFS_QUIETFS_ENV
495 fprintf(console, "File server is running at %s\r",
496 afs_ctime(&now, tbuffer, sizeof(tbuffer)));
497 #endif /* AFS_QUIETFS_ENV */
499 ("File server is running at %s\n",
500 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
503 #ifdef AFS_DEMAND_ATTACH_FS
507 #ifdef AFS_DEMAND_ATTACH_FS
508 fs_state.FiveMinuteLWP_tranquil = 1;
510 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
524 HostCheckLWP(void *unused)
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);
569 /* This LWP does fsync checks every 5 minutes: it should not be used for
570 * other 5 minute activities because it may be delayed by timeouts when
571 * it probes the workstations
574 FsyncCheckLWP(void *unused)
577 #ifdef AFS_PTHREAD_ENV
578 struct timespec fsync_next;
580 ViceLog(1, ("Starting fsync check process\n"));
582 setThreadId("FsyncCheckLWP");
584 #ifdef AFS_DEMAND_ATTACH_FS
586 while (fs_state.mode == FS_MODE_NORMAL) {
587 fs_state.FsyncCheckLWP_tranquil = 1;
593 #ifdef AFS_PTHREAD_ENV
594 /* rounding is fine */
595 fsync_next.tv_nsec = 0;
596 fsync_next.tv_sec = time(0) + fiveminutes;
599 pthread_cond_timedwait(&fsync_cond, &fsync_glock_mutex,
601 if (code != 0 && code != ETIMEDOUT)
602 ViceLog(0, ("pthread_cond_timedwait returned %d\n", code));
603 #else /* AFS_PTHREAD_ENV */
604 if ((code = LWP_WaitProcess(fsync_wait)) != LWP_SUCCESS)
605 ViceLog(0, ("LWP_WaitProcess returned %d\n", code));
606 #endif /* AFS_PTHREAD_ENV */
609 #ifdef AFS_DEMAND_ATTACH_FS
611 if (fs_state.mode != FS_MODE_NORMAL) {
614 fs_state.FsyncCheckLWP_tranquil = 0;
616 #endif /* AFS_DEMAND_ATTACH_FS */
618 ViceLog(2, ("Checking for fsync events\n"));
620 code = BreakLaterCallBacks();
622 #ifdef AFS_DEMAND_ATTACH_FS
626 #ifdef AFS_DEMAND_ATTACH_FS
627 fs_state.FsyncCheckLWP_tranquil = 1;
629 assert(pthread_cond_broadcast(&fs_state.worker_done_cv)==0);
632 #endif /* AFS_DEMAND_ATTACH_FS */
636 /*------------------------------------------------------------------------
637 * PRIVATE ClearXStatValues
640 * Initialize all of the values collected via the xstat
650 * Must be called during File Server initialization.
654 *------------------------------------------------------------------------*/
657 ClearXStatValues(void)
658 { /*ClearXStatValues */
660 struct fs_stats_opTimingData *opTimeP; /*Ptr to timing struct */
661 struct fs_stats_xferData *opXferP; /*Ptr to xfer struct */
662 int i; /*Loop counter */
665 * Zero all xstat-related structures.
667 memset((char *)(&afs_perfstats), 0, sizeof(struct afs_PerfStats));
668 #if FS_STATS_DETAILED
669 memset((char *)(&afs_FullPerfStats), 0,
670 sizeof(struct fs_stats_FullPerfStats));
673 * That's not enough. We have to set reasonable minima for
674 * time and xfer values in the detailed stats.
676 opTimeP = &(afs_FullPerfStats.det.rpcOpTimes[0]);
677 for (i = 0; i < FS_STATS_NUM_RPC_OPS; i++, opTimeP++)
678 opTimeP->minTime.tv_sec = 999999;
680 opXferP = &(afs_FullPerfStats.det.xferOpTimes[0]);
681 for (i = 0; i < FS_STATS_NUM_XFER_OPS; i++, opXferP++) {
682 opXferP->minTime.tv_sec = 999999;
683 opXferP->minBytes = 999999999;
687 * There's more. We have to set our unique system identifier, as
688 * declared in param.h. If such a thing is not defined, we bitch
689 * and declare ourselves to be an unknown system type.
692 afs_perfstats.sysname_ID = SYS_NAME_ID;
695 ViceLog(0, ("Sys name ID constant not defined in param.h!!\n"));
696 ViceLog(0, ("[Choosing ``undefined'' sys name ID.\n"));
698 afs_perfstats.sysname_ID = SYS_NAME_ID_UNDEFINED;
699 #endif /* SYS_NAME_ID */
702 } /*ClearXStatValues */
704 int CopyOnWrite_calls = 0, CopyOnWrite_off0 = 0, CopyOnWrite_size0 = 0;
705 afs_fsize_t CopyOnWrite_maxsize = 0;
710 int dirbuff, dircall, dirio;
712 int workstations, activeworkstations, delworkstations;
716 FT_GetTimeOfDay(&tpl, 0);
719 ("Vice was last started at %s\n",
720 afs_ctime(&StartTime, tbuffer, sizeof(tbuffer))));
722 #ifdef AFS_DEMAND_ATTACH_FS
723 /* XXX perhaps set extended stats verbosity flags
724 * based upon LogLevel ?? */
725 VPrintExtendedCacheStats(VOL_STATS_PER_CHAIN2);
729 DStat(&dirbuff, &dircall, &dirio);
731 ("With %d directory buffers; %d reads resulted in %d read I/Os\n",
732 dirbuff, dircall, dirio));
733 rx_PrintStats(stderr);
735 PrintCallBackStats();
737 processSize = -1; /* TODO: */
739 processSize = (int)((long)sbrk(0) >> 10);
742 ("There are %d connections, process size %d\n",
743 CurrentConnections, processSize));
744 h_GetWorkStats(&workstations, &activeworkstations, &delworkstations,
745 tpl.tv_sec - 15 * 60);
747 ("There are %d workstations, %d are active (req in < 15 mins), %d marked \"down\"\n",
748 workstations, activeworkstations, delworkstations));
749 ViceLog(0, ("CopyOnWrite: calls %d off0 %d size0 %d maxsize 0x%llx\n",
750 CopyOnWrite_calls, CopyOnWrite_off0, CopyOnWrite_size0, CopyOnWrite_maxsize));
759 CheckSignal(void *unused)
761 if (FS_registered > 0) {
763 * We have proper ip addresses; tell the vlserver what we got; the following
764 * routine will do the proper reporting for us
777 ShutDownAndCore(int dopanic)
779 time_t now = time(0);
782 /* do not allows new reqests to be served from now on, all new requests
783 * are returned with an error code of RX_RESTARTING ( transient failure ) */
784 rx_SetRxTranquil(); /* dhruba */
786 #ifdef AFS_DEMAND_ATTACH_FS
788 fs_state.mode = FS_MODE_SHUTDOWN;
793 ("Shutting down file server at %s",
794 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
796 ViceLog(0, ("ABNORMAL SHUTDOWN, see core file.\n"));
797 #ifndef AFS_QUIETFS_ENV
798 if (console != NULL) {
799 fprintf(console, "File server restart/shutdown received at %s\r",
800 afs_ctime(&now, tbuffer, sizeof(tbuffer)));
807 /* shut down volume package */
810 #ifdef AFS_DEMAND_ATTACH_FS
811 if (fs_state.options.fs_state_save) {
814 * save fileserver state to disk */
816 /* make sure background threads have finished all of their asynchronous
817 * work on host and callback structures */
819 while (!fs_state.FiveMinuteLWP_tranquil ||
820 !fs_state.HostCheckLWP_tranquil ||
821 !fs_state.FsyncCheckLWP_tranquil) {
824 ViceLog(0, ("waiting for background host/callback threads to quiesce before saving fileserver state...\n"));
825 assert(pthread_cond_wait(&fs_state.worker_done_cv, &fileproc_glock_mutex) == 0);
830 /* ok. it should now be fairly safe. let's do the state dump */
833 #endif /* AFS_DEMAND_ATTACH_FS */
836 rx_PrintStats(debugFile);
839 if (console != NULL) {
842 #ifndef AFS_QUIETFS_ENV
843 fprintf(console, "File server has terminated abnormally at %s\r",
844 afs_ctime(&now, tbuffer, sizeof(tbuffer)));
847 ("File server has terminated abnormally at %s\n",
848 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
850 #ifndef AFS_QUIETFS_ENV
851 fprintf(console, "File server has terminated normally at %s\r",
852 afs_ctime(&now, tbuffer, sizeof(tbuffer)));
855 ("File server has terminated normally at %s\n",
856 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
867 ShutDown(void *unused)
868 { /* backward compatibility */
869 ShutDownAndCore(DONTPANIC);
877 /* default supports help flag */
879 fputs("Usage: fileserver ", stdout);
880 fputs("[-auditlog <log path>] ", stdout);
881 fputs("[-d <debug level>] ", stdout);
882 fputs("[-p <number of processes>] ", stdout);
883 fputs("[-spare <number of spare blocks>] ", stdout);
884 fputs("[-pctspare <percentage spare>] ", stdout);
885 fputs("[-b <buffers>] ", stdout);
886 fputs("[-l <large vnodes>] ", stdout);
887 fputs("[-s <small vnodes>] ", stdout);
888 fputs("[-vc <volume cachesize>] ", stdout);
889 fputs("[-w <call back wait interval>] ", stdout);
890 fputs("[-cb <number of call backs>] ", stdout);
891 fputs("[-banner (print banner every 10 minutes)] ", stdout);
892 fputs("[-novbc (whole volume cbs disabled)] ", stdout);
893 fputs("[-implicit <admin mode bits: rlidwka>] ", stdout);
894 fputs("[-readonly (read-only file server)] ", stdout);
895 fputs("[-hr <number of hours between refreshing the host cps>] ", stdout);
896 fputs("[-busyat <redirect clients when queue > n>] ", stdout);
897 fputs("[-nobusy <no VBUSY before a volume is attached>] ", stdout);
898 fputs("[-rxpck <number of rx extra packets>] ", stdout);
899 fputs("[-rxdbg (enable rx debugging)] ", stdout);
900 fputs("[-rxdbge (enable rxevent debugging)] ", stdout);
901 fputs("[-rxmaxmtu <bytes>] ", stdout);
902 fputs("[-rxbind (bind the Rx socket to one address)] ", stdout);
903 fputs("[-allow-dotted-principals (disable the rxkad principal name dot check)] ", stdout);
904 #ifdef AFS_DEMAND_ATTACH_FS
905 fputs("[-fs-state-dont-save (disable state save during shutdown)] ", stdout);
906 fputs("[-fs-state-dont-restore (disable state restore during startup)] ", stdout);
907 fputs("[-fs-state-verify <none|save|restore|both> (default is both)] ", stdout);
908 fputs("[-vattachpar <max number of volume attach/shutdown threads> (default is 1)] ", stdout);
909 fputs("[-vhashsize <log(2) of number of volume hash buckets> (default is 8)] ", stdout);
910 fputs("[-vlrudisable (disable VLRU functionality)] ", stdout);
911 fputs("[-vlruthresh <minutes before unused volumes become eligible for soft detach> (default is 2 hours)] ", stdout);
912 fputs("[-vlruinterval <seconds between VLRU scans> (default is 2 minutes)] ", stdout);
913 fputs("[-vlrumax <max volumes to soft detach in one VLRU scan> (default is 8)] ", stdout);
914 #elif AFS_PTHREAD_ENV
915 fputs("[-vattachpar <number of volume attach threads> (default is 1)] ", stdout);
918 fputs("[-m <min percentage spare in partition>] ", stdout);
920 #if defined(AFS_SGI_ENV)
921 fputs("[-lock (keep fileserver from swapping)] ", stdout);
923 fputs("[-L (large server conf)] ", stdout);
924 fputs("[-S (small server conf)] ", stdout);
925 fputs("[-k <stack size>] ", stdout);
926 fputs("[-realm <Kerberos realm name>] ", stdout);
927 fputs("[-udpsize <size of socket buffer in bytes>] ", stdout);
928 fputs("[-sendsize <size of send buffer in bytes>] ", stdout);
929 fputs("[-abortthreshold <abort threshold>] ", stdout);
930 fputs("[-nojumbo (disable jumbogram network packets - deprecated)] ", stdout);
931 fputs("[-jumbo (enable jumbogram network packets)] ", stdout);
932 /* fputs("[-enable_peer_stats] ", stdout); */
933 /* fputs("[-enable_process_stats] ", stdout); */
934 fputs("[-help]\n", stdout);
936 ViceLog(0, ("%s", buffer));
945 ParseRights(char *arights)
951 if (!arights || !strcmp(arights, "")) {
952 printf("Missing list of mode bits on -implicit option\n");
955 if (!strcmp(arights, "none"))
957 else if (!strcmp(arights, "read"))
958 mode = PRSFS_READ | PRSFS_LOOKUP;
959 else if (!strcmp(arights, "write"))
961 PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
962 PRSFS_WRITE | PRSFS_LOCK;
963 else if (!strcmp(arights, "all"))
965 PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
966 PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER;
968 len = strlen(arights);
969 for (i = 0; i < len; i++) {
974 mode |= PRSFS_LOOKUP;
976 mode |= PRSFS_INSERT;
978 mode |= PRSFS_DELETE;
984 mode |= PRSFS_ADMINISTER;
1002 printf("Illegal -implicit rights character '%c'.\n", tc);
1011 * Limit MAX_FILESERVER_THREAD by the system limit on the number of
1012 * pthreads (sysconf(_SC_THREAD_THREADS_MAX)), if applicable and
1015 * AIX: sysconf() limit is real
1016 * HP-UX: sysconf() limit is real
1017 * IRIX: sysconf() limit is apparently NOT real -- too small
1018 * DUX: sysconf() limit is apparently NOT real -- too big
1019 * Linux: sysconf() limit is apparently NOT real -- too big
1020 * Solaris: no sysconf() limit
1023 max_fileserver_thread(void)
1025 #if defined(AFS_PTHREAD_ENV)
1026 #if defined(AFS_AIX_ENV) || defined(AFS_HPUX_ENV)
1029 ans = sysconf(_SC_THREAD_THREADS_MAX);
1030 if (0 < ans && ans < MAX_FILESERVER_THREAD)
1033 #endif /* defined(AFS_PTHREAD_ENV) */
1034 return MAX_FILESERVER_THREAD;
1038 ParseArgs(int argc, char *argv[])
1040 int SawL = 0, SawS = 0, SawVC = 0;
1041 int Sawrxpck = 0, Sawsmall = 0, Sawlarge = 0, Sawcbs = 0, Sawlwps =
1045 int bufSize = 0; /* temp variable to read in udp socket buf size */
1047 for (i = 1; i < argc; i++) {
1048 if (!strcmp(argv[i], "-d")) {
1049 if ((i + 1) >= argc) {
1050 fprintf(stderr, "missing argument for -d\n");
1053 debuglevel = atoi(argv[++i]);
1054 LogLevel = debuglevel;
1055 } else if (!strcmp(argv[i], "-banner")) {
1057 } else if (!strcmp(argv[i], "-implicit")) {
1058 if ((i + 1) >= argc) {
1059 fprintf(stderr, "missing argument for -implicit\n");
1062 implicitAdminRights = ParseRights(argv[++i]);
1063 if (implicitAdminRights < 0)
1064 return implicitAdminRights;
1065 } else if (!strcmp(argv[i], "-readonly")) {
1067 } else if (!strcmp(argv[i], "-L")) {
1069 } else if (!strcmp(argv[i], "-S")) {
1071 } else if (!strcmp(argv[i], "-p")) {
1073 max_fileserver_thread() - FILESERVER_HELPER_THREADS;
1075 if ((i + 1) >= argc) {
1076 fprintf(stderr, "missing argument for -p\n");
1079 lwps = atoi(argv[++i]);
1080 if (lwps > lwps_max)
1084 } else if (!strcmp(argv[i], "-b")) {
1086 if ((i + 1) >= argc) {
1087 fprintf(stderr, "missing argument for -b\n");
1090 buffs = atoi(argv[++i]);
1091 } else if (!strcmp(argv[i], "-l")) {
1093 if ((i + 1) >= argc) {
1094 fprintf(stderr, "missing argument for -l\n");
1097 large = atoi(argv[++i]);
1098 } else if (!strcmp(argv[i], "-vc")) {
1100 if ((i + 1) >= argc) {
1101 fprintf(stderr, "missing argument for -vc\n");
1104 volcache = atoi(argv[++i]);
1105 } else if (!strcmp(argv[i], "-novbc")) {
1107 } else if (!strcmp(argv[i], "-rxpck")) {
1109 if ((i + 1) >= argc) {
1110 fprintf(stderr, "missing argument for -rxpck\n");
1113 rxpackets = atoi(argv[++i]);
1114 #ifdef AFS_PTHREAD_ENV
1115 } else if (!strcmp(argv[i], "-vattachpar")) {
1116 if ((i + 1) >= argc) {
1117 fprintf(stderr, "missing argument for %s\n", argv[i]);
1120 vol_attach_threads = atoi(argv[++i]);
1121 #endif /* AFS_PTHREAD_ENV */
1122 #ifdef AFS_DEMAND_ATTACH_FS
1123 } else if (!strcmp(argv[i], "-fs-state-dont-save")) {
1124 fs_state.options.fs_state_save = 0;
1125 } else if (!strcmp(argv[i], "-fs-state-dont-restore")) {
1126 fs_state.options.fs_state_restore = 0;
1127 } else if (!strcmp(argv[i], "-fs-state-verify")) {
1128 if ((i + 1) >= argc) {
1129 fprintf(stderr, "missing argument for %s\n", argv[i]);
1133 if (!strcmp(argv[i], "none")) {
1134 fs_state.options.fs_state_verify_before_save = 0;
1135 fs_state.options.fs_state_verify_after_restore = 0;
1136 } else if (!strcmp(argv[i], "save")) {
1137 fs_state.options.fs_state_verify_after_restore = 0;
1138 } else if (!strcmp(argv[i], "restore")) {
1139 fs_state.options.fs_state_verify_before_save = 0;
1140 } else if (!strcmp(argv[i], "both")) {
1143 fprintf(stderr, "invalid argument for %s\n", argv[i-1]);
1146 } else if (!strcmp(argv[i], "-vhashsize")) {
1147 if ((i + 1) >= argc) {
1148 fprintf(stderr, "missing argument for %s\n", argv[i]);
1151 VSetVolHashSize(atoi(argv[++i]));
1152 } else if (!strcmp(argv[i], "-vlrudisable")) {
1153 VLRU_SetOptions(VLRU_SET_ENABLED, 0);
1154 } else if (!strcmp(argv[i], "-vlruthresh")) {
1155 if ((i + 1) >= argc) {
1156 fprintf(stderr, "missing argument for %s\n", argv[i]);
1159 VLRU_SetOptions(VLRU_SET_THRESH, 60*atoi(argv[++i]));
1160 } else if (!strcmp(argv[i], "-vlruinterval")) {
1161 if ((i + 1) >= argc) {
1162 fprintf(stderr, "missing argument for %s\n", argv[i]);
1165 VLRU_SetOptions(VLRU_SET_INTERVAL, atoi(argv[++i]));
1166 } else if (!strcmp(argv[i], "-vlrumax")) {
1167 if ((i + 1) >= argc) {
1168 fprintf(stderr, "missing argument for %s\n", argv[i]);
1171 VLRU_SetOptions(VLRU_SET_MAX, atoi(argv[++i]));
1172 #endif /* AFS_DEMAND_ATTACH_FS */
1173 } else if (!strcmp(argv[i], "-s")) {
1175 if ((i + 1) >= argc) {
1176 fprintf(stderr, "missing argument for -s\n");
1179 nSmallVns = atoi(argv[++i]);
1180 } else if (!strcmp(argv[i], "-abortthreshold")) {
1181 if ((i + 1) >= argc) {
1182 fprintf(stderr, "missing argument for -abortthreshold\n");
1185 abort_threshold = atoi(argv[++i]);
1186 } else if (!strcmp(argv[i], "-k")) {
1187 if ((i + 1) >= argc) {
1188 fprintf(stderr, "missing argument for -k\n");
1191 stack = atoi(argv[++i]);
1193 #if defined(AFS_SGI_ENV)
1194 else if (!strcmp(argv[i], "-lock")) {
1198 else if (!strcmp(argv[i], "-spare")) {
1199 if ((i + 1) >= argc) {
1200 fprintf(stderr, "missing argument for -spare\n");
1203 BlocksSpare = atoi(argv[++i]);
1205 } else if (!strcmp(argv[i], "-pctspare")) {
1206 if ((i + 1) >= argc) {
1207 fprintf(stderr, "missing argument for -pctspare\n");
1210 PctSpare = atoi(argv[++i]);
1211 BlocksSpare = 0; /* has non-zero default */
1213 } else if (!strcmp(argv[i], "-w")) {
1214 if ((i + 1) >= argc) {
1215 fprintf(stderr, "missing argument for -w\n");
1218 fiveminutes = atoi(argv[++i]);
1219 } else if (!strcmp(argv[i], "-hr")) {
1221 if ((i + 1) >= argc) {
1222 fprintf(stderr, "missing argument for -hr\n");
1225 hr = atoi(argv[++i]);
1226 if ((hr < 1) || (hr > 36)) {
1228 ("host acl refresh interval of %d hours is invalid; hours must be between 1 and 36\n\n",
1232 hostaclRefresh = hr * 60 * 60;
1233 } else if (!strcmp(argv[i], "-rxdbg"))
1235 else if (!strcmp(argv[i], "-rxdbge"))
1237 else if (!strcmp(argv[i], "-cb")) {
1239 if ((i + 1) >= argc) {
1240 fprintf(stderr, "missing argument for -cb\n");
1243 numberofcbs = atoi(argv[++i]);
1244 if ((numberofcbs < 10000) || (numberofcbs > 2147483647)) {
1246 ("number of cbs %d invalid; must be between 10000 and 2147483647\n",
1250 } else if (!strcmp(argv[i], "-busyat")) {
1252 if ((i + 1) >= argc) {
1253 fprintf(stderr, "missing argument for -busyat\n");
1256 busy_threshold = atoi(argv[++i]);
1257 if (busy_threshold < 10) {
1259 ("Busy threshold %d is too low, will compute default.\n",
1263 } else if (!strcmp(argv[i], "-nobusy"))
1265 #ifdef AFS_AIX32_ENV
1266 else if (!strcmp(argv[i], "-m")) {
1267 extern int aixlow_water;
1268 if ((i + 1) >= argc) {
1269 fprintf(stderr, "missing argument for -m\n");
1272 aixlow_water = atoi(argv[++i]);
1273 if ((aixlow_water < 0) || (aixlow_water > 30)) {
1274 printf("space reserved %d% invalid; must be between 0-30%\n",
1280 else if (!strcmp(argv[i], "-nojumbo")) {
1282 } else if (!strcmp(argv[i], "-jumbo")) {
1284 } else if (!strcmp(argv[i], "-rxbind")) {
1286 } else if (!strcmp(argv[i], "-allow-dotted-principals")) {
1287 rxkadDisableDotCheck = 1;
1288 } else if (!strcmp(argv[i], "-rxmaxmtu")) {
1289 if ((i + 1) >= argc) {
1290 fprintf(stderr, "missing argument for -rxmaxmtu\n");
1293 rxMaxMTU = atoi(argv[++i]);
1294 if ((rxMaxMTU < RX_MIN_PACKET_SIZE) ||
1295 (rxMaxMTU > RX_MAX_PACKET_DATA_SIZE)) {
1296 printf("rxMaxMTU %d%% invalid; must be between %d-%lu\n",
1297 rxMaxMTU, RX_MIN_PACKET_SIZE,
1298 RX_MAX_PACKET_DATA_SIZE);
1301 } else if (!strcmp(argv[i], "-realm")) {
1302 extern char local_realms[AFS_NUM_LREALMS][AFS_REALM_SZ];
1303 extern int num_lrealms;
1304 if ((i + 1) >= argc) {
1305 fprintf(stderr, "missing argument for -realm\n");
1308 if (strlen(argv[++i]) >= AFS_REALM_SZ) {
1310 ("-realm argument must contain fewer than %d characters.\n",
1314 if (num_lrealms == -1)
1316 if (num_lrealms >= AFS_NUM_LREALMS) {
1318 ("a maximum of %d -realm arguments can be specified.\n",
1322 strncpy(local_realms[num_lrealms++], argv[i], AFS_REALM_SZ);
1323 } else if (!strcmp(argv[i], "-udpsize")) {
1324 if ((i + 1) >= argc) {
1325 printf("You have to specify -udpsize <integer value>\n");
1328 bufSize = atoi(argv[++i]);
1329 if (bufSize < rx_GetMinUdpBufSize())
1331 ("Warning:udpsize %d is less than minimum %d; ignoring\n",
1332 bufSize, rx_GetMinUdpBufSize());
1334 udpBufSize = bufSize;
1335 } else if (!strcmp(argv[i], "-sendsize")) {
1336 if ((i + 1) >= argc) {
1337 printf("You have to specify -sendsize <integer value>\n");
1340 bufSize = atoi(argv[++i]);
1341 if (bufSize < 16384)
1343 ("Warning:sendsize %d is less than minimum %d; ignoring\n",
1346 sendBufSize = bufSize;
1347 } else if (!strcmp(argv[i], "-enable_peer_stats")) {
1348 rx_enablePeerRPCStats();
1349 } else if (!strcmp(argv[i], "-enable_process_stats")) {
1350 rx_enableProcessRPCStats();
1352 else if (strcmp(argv[i], "-auditlog") == 0) {
1353 char *fileName = argv[++i];
1355 osi_audit_file(fileName);
1357 #ifndef AFS_NT40_ENV
1358 else if (strcmp(argv[i], "-syslog") == 0) {
1359 /* set syslog logging flag */
1360 serverLogSyslog = 1;
1361 } else if (strncmp(argv[i], "-syslog=", 8) == 0) {
1362 serverLogSyslog = 1;
1363 serverLogSyslogFacility = atoi(argv[i] + 8);
1366 else if (strcmp(argv[i], "-mrafslogs") == 0) {
1367 /* set syslog logging flag */
1370 else if (strcmp(argv[i], "-saneacls") == 0) {
1378 printf("Only one of -L, or -S must be specified\n");
1389 numberofcbs = 20000;
1405 numberofcbs = 64000;
1414 busy_threshold = 3 * rxpackets / 2;
1424 NewParms(int initializing)
1426 static struct afs_stat sbuf;
1429 char *argv[MAXPARMS];
1432 if (!(afs_stat("/vice/file/parms", &sbuf))) {
1433 parms = (char *)malloc(sbuf.st_size);
1436 fd = afs_open("parms", O_RDONLY, 0666);
1438 ViceLog(0, ("Open for parms failed with errno = %d\n", errno));
1442 i = read(fd, parms, sbuf.st_size);
1444 if (i != sbuf.st_size) {
1446 ViceLog(0, ("Read on parms failed with errno = %d\n", errno));
1449 ("Read on parms failed; expected %d bytes but read %d\n",
1456 for (i = 0; i < MAXPARMS; argv[i++] = 0);
1458 for (argc = i = 0; i < sbuf.st_size; i++) {
1459 if ((*(parms + i) != ' ') && (*(parms + i) != '\n')) {
1460 if (argv[argc] == 0)
1461 argv[argc] = (parms + i);
1463 *(parms + i) = '\0';
1464 if (argv[argc] != 0) {
1465 if (++argc == MAXPARMS)
1468 while ((*(parms + i + 1) == ' ')
1469 || (*(parms + i + 1) == '\n'))
1473 if (ParseArgs(argc, argv) == 0) {
1474 ViceLog(0, ("Change parameters to:"));
1476 ViceLog(0, ("Invalid parameter in:"));
1478 for (i = 0; i < argc; i++) {
1479 ViceLog(0, (" %s", argv[i]));
1483 } else if (!initializing)
1485 ("Received request to change parms but no parms file exists\n"));
1490 /* Miscellaneous routines */
1494 ViceLog(0, ("%s\n", msg));
1506 * If this fails, it's because something major is wrong, and is not
1507 * likely to be time dependent.
1509 code = pr_Initialize(2, AFSDIR_SERVER_ETC_DIRPATH, 0);
1512 ("Couldn't initialize protection library; code=%d.\n", code));
1516 #ifdef AFS_PTHREAD_ENV
1517 assert(pthread_key_create(&viced_uclient_key, NULL) == 0);
1520 SystemId = SYSADMINID;
1521 SystemAnyUser = ANYUSERID;
1522 SystemAnyUserCPS.prlist_len = 0;
1523 SystemAnyUserCPS.prlist_val = NULL;
1524 AnonCPS.prlist_len = 0;
1525 AnonCPS.prlist_val = NULL;
1527 code = pr_GetCPS(SystemAnyUser, &SystemAnyUserCPS);
1530 ("Couldn't get CPS for AnyUser, will try again in 30 seconds; code=%d.\n",
1534 code = pr_GetCPS(ANONYMOUSID, &AnonCPS);
1537 ("Couldn't get Anonymous CPS, exiting; code=%d.\n",
1541 AnonymousID = ANONYMOUSID;
1544 #ifdef AFS_PTHREAD_ENV
1546 #else /* AFS_PTHREAD_ENV */
1548 #endif /* AFS_PTHREAD_ENV */
1552 struct rx_connection *serverconns[MAXSERVERS];
1553 struct ubik_client *cstruct;
1556 vl_Initialize(const char *confDir)
1558 afs_int32 code, scIndex = 0, i;
1559 struct afsconf_dir *tdir;
1560 struct rx_securityClass *sc;
1561 struct afsconf_cell info;
1563 tdir = afsconf_Open(confDir);
1566 ("Could not open configuration directory (%s).\n", confDir));
1569 code = afsconf_ClientAuth(tdir, &sc, &scIndex);
1571 ViceLog(0, ("Could not get security object for localAuth\n"));
1574 code = afsconf_GetCellInfo(tdir, NULL, AFSCONF_VLDBSERVICE, &info);
1575 if (info.numServers > MAXSERVERS) {
1577 ("vl_Initialize: info.numServers=%d (> MAXSERVERS=%d)\n",
1578 info.numServers, MAXSERVERS));
1581 for (i = 0; i < info.numServers; i++)
1583 rx_NewConnection(info.hostAddr[i].sin_addr.s_addr,
1584 info.hostAddr[i].sin_port, USER_SERVICE_ID, sc,
1586 code = ubik_ClientInit(serverconns, &cstruct);
1587 afsconf_Close(tdir);
1589 ViceLog(0, ("vl_Initialize: ubik client init failed.\n"));
1595 #define SYSIDMAGIC 0x88aabbcc
1596 #define SYSIDVERSION 1
1601 afs_int32 fd, nentries, i;
1602 struct versionStamp vsn;
1603 struct afs_stat status;
1606 if ((afs_stat(AFSDIR_SERVER_SYSID_FILEPATH, &status))
1607 || (status.st_size <= 0)) {
1608 ViceLog(0, ("%s: doesn't exist\n", AFSDIR_SERVER_SYSID_FILEPATH));
1611 if (!(fd = afs_open(AFSDIR_SERVER_SYSID_FILEPATH, O_RDONLY, 0))) {
1613 ("%s: can't open (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1617 if ((i = read(fd, (char *)&vsn, sizeof(vsn))) != sizeof(vsn)) {
1619 ("%s: Read failed (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1623 if (vsn.magic != SYSIDMAGIC) {
1625 ("%s: wrong magic %x (we support %x)\n",
1626 AFSDIR_SERVER_SYSID_FILEPATH, vsn.magic, SYSIDMAGIC));
1629 if (vsn.version != SYSIDVERSION) {
1631 ("%s: wrong version %d (we support %d)\n",
1632 AFSDIR_SERVER_SYSID_FILEPATH, vsn.version, SYSIDVERSION));
1636 read(fd, (char *)&uuid,
1637 sizeof(struct afsUUID))) != sizeof(struct afsUUID)) {
1639 ("%s: read of uuid failed (%d)\n",
1640 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1643 afs_ntohuuid(&uuid);
1646 read(fd, (char *)&nentries,
1647 sizeof(afs_int32))) != sizeof(afs_int32)) {
1649 ("%s: Read of entries failed (%d)\n",
1650 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1653 if (nentries <= 0 || nentries > ADDRSPERSITE) {
1655 ("%s: invalid num of interfaces: %d\n",
1656 AFSDIR_SERVER_SYSID_FILEPATH, nentries));
1659 if (FS_HostAddr_cnt == 0) {
1660 FS_HostAddr_cnt = nentries;
1661 for (i = 0; i < nentries; i++) {
1662 if (read(fd, (char *)&FS_HostAddrs[i], sizeof(afs_int32)) !=
1663 sizeof(afs_int32)) {
1665 ("%s: Read of addresses failed (%d)\n",
1666 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1667 FS_HostAddr_cnt = 0; /* reset it */
1673 ("%s: address list ignored (NetInfo/NetRestrict override)\n",
1674 AFSDIR_SERVER_SYSID_FILEPATH));
1681 WriteSysIdFile(void)
1684 struct versionStamp vsn;
1685 struct afs_stat status;
1688 if (!afs_stat(AFSDIR_SERVER_SYSID_FILEPATH, &status)) {
1690 * File exists; keep the old one around
1692 renamefile(AFSDIR_SERVER_SYSID_FILEPATH,
1693 AFSDIR_SERVER_OLDSYSID_FILEPATH);
1695 fd = afs_open(AFSDIR_SERVER_SYSID_FILEPATH, O_WRONLY | O_TRUNC | O_CREAT,
1699 ("%s: can't create (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1703 vsn.magic = SYSIDMAGIC;
1705 if ((i = write(fd, (char *)&vsn, sizeof(vsn))) != sizeof(vsn)) {
1707 ("%s: write failed (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1712 afs_htonuuid(&uuid);
1714 write(fd, (char *)&uuid,
1715 sizeof(struct afsUUID))) != sizeof(struct afsUUID)) {
1717 ("%s: write of uuid failed (%d)\n",
1718 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1722 write(fd, (char *)&FS_HostAddr_cnt,
1723 sizeof(afs_int32))) != sizeof(afs_int32)) {
1725 ("%s: write of # of entries failed (%d)\n",
1726 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1729 for (i = 0; i < FS_HostAddr_cnt; i++) {
1730 if (write(fd, (char *)&FS_HostAddrs[i], sizeof(afs_int32)) !=
1731 sizeof(afs_int32)) {
1733 ("%s: write of addresses failed (%d)\n",
1734 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1744 * This routine sets up the buffers for the VL_RegisterAddrs RPC. All addresses
1745 * in FS_HostAddrs[] are in NBO, while the RPC treats them as a "blob" of data
1746 * and so we need to convert each of them into HBO which is what the extra
1747 * array called FS_HostAddrs_HBO is used here.
1750 Do_VLRegisterRPC(void)
1754 afs_uint32 FS_HostAddrs_HBO[ADDRSPERSITE];
1757 for (i = 0; i < FS_HostAddr_cnt; i++)
1758 FS_HostAddrs_HBO[i] = ntohl(FS_HostAddrs[i]);
1759 addrs.bulkaddrs_len = FS_HostAddr_cnt;
1760 addrs.bulkaddrs_val = (afs_uint32 *) FS_HostAddrs_HBO;
1761 code = ubik_VL_RegisterAddrs(cstruct, 0, &FS_HostUUID, 0, &addrs);
1763 if (code == VL_MULTIPADDR) {
1765 ("VL_RegisterAddrs rpc failed; The IP address exists on a different server; repair it\n"));
1767 ("VL_RegisterAddrs rpc failed; See VLLog for details\n"));
1769 } else if (code == RXGEN_OPCODE) {
1771 ("vlserver doesn't support VL_RegisterAddrs rpc; ignored\n"));
1772 FS_registered = 2; /* So we don't have to retry in the gc daemon */
1775 ("VL_RegisterAddrs rpc failed; will retry periodically (code=%d, err=%d)\n",
1779 FS_registered = 2; /* So we don't have to retry in the gc daemon */
1791 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH || AFSDIR_SERVER_NETINFO_FILEPATH) {
1793 * Find addresses we are supposed to register as per the netrestrict
1794 * and netinfo files (/usr/afs/local/NetInfo and
1795 * /usr/afs/local/NetRestict)
1798 afs_int32 code = parseNetFiles(FS_HostAddrs, NULL, NULL,
1799 ADDRSPERSITE, reason,
1800 AFSDIR_SERVER_NETINFO_FILEPATH,
1801 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
1803 ViceLog(0, ("Can't register any valid addresses: %s\n", reason));
1806 FS_HostAddr_cnt = (afs_uint32) code;
1809 FS_HostAddr_cnt = rx_getAllAddr(FS_HostAddrs, ADDRSPERSITE);
1812 if (FS_HostAddr_cnt == 1 && rxBind == 1)
1813 code = FS_HostAddrs[0];
1815 code = htonl(INADDR_ANY);
1825 * If this fails, it's because something major is wrong, and is not
1826 * likely to be time dependent.
1828 code = vl_Initialize(AFSDIR_SERVER_ETC_DIRPATH);
1831 ("Couldn't initialize protection library; code=%d.\n", code));
1835 /* Read or create the sysid file and register the fileserver's
1836 * IP addresses with the vlserver.
1838 code = ReadSysIdFile();
1840 /* Need to create the file */
1841 ViceLog(0, ("Creating new SysID file\n"));
1842 if ((code = afs_uuid_create(&FS_HostUUID))) {
1843 ViceLog(0, ("Failed to create new uuid: %d\n", code));
1847 /* A good sysid file exists; inform the vlserver. If any conflicts,
1848 * we always use the latest interface available as the real truth.
1851 code = Do_VLRegisterRPC();
1856 main(int argc, char *argv[])
1860 struct rx_securityClass *sc[4];
1861 struct rx_service *tservice;
1862 #ifdef AFS_PTHREAD_ENV
1863 pthread_t serverPid;
1864 pthread_attr_t tattr;
1865 #else /* AFS_PTHREAD_ENV */
1866 PROCESS parentPid, serverPid;
1867 #endif /* AFS_PTHREAD_ENV */
1869 int minVnodesRequired; /* min size of vnode cache */
1870 #ifndef AFS_NT40_ENV
1871 struct rlimit rlim; /* max number of open file descriptors */
1875 afs_uint32 rx_bindhost;
1877 #ifdef AFS_AIX32_ENV
1878 struct sigaction nsa;
1880 sigemptyset(&nsa.sa_mask);
1881 nsa.sa_handler = SIG_DFL;
1882 nsa.sa_flags = SA_FULLDUMP;
1883 sigaction(SIGABRT, &nsa, NULL);
1884 sigaction(SIGSEGV, &nsa, NULL);
1888 /* Initialize dirpaths */
1889 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
1891 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
1893 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
1897 #ifndef AFS_QUIETFS_ENV
1898 console = afs_fopen("/dev/console", "w");
1901 if (ParseArgs(argc, argv)) {
1905 #ifdef AFS_PTHREAD_ENV
1906 assert(pthread_mutex_init(&fileproc_glock_mutex, NULL) == 0);
1907 #endif /* AFS_PTHREAD_ENV */
1909 #ifdef AFS_SGI_VNODE_GLUE
1910 if (afs_init_kernel_config(-1) < 0) {
1912 ("Can't determine NUMA configuration, not starting fileserver.\n");
1916 confDir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
1918 fprintf(stderr, "Unable to open config directory %s\n",
1919 AFSDIR_SERVER_ETC_DIRPATH);
1925 /* Open FileLog on stdout, stderr, fd 1 and fd2 (for perror), sigh. */
1926 #ifndef AFS_NT40_ENV
1927 serverLogSyslogTag = "fileserver";
1929 OpenLog(AFSDIR_SERVER_FILELOG_FILEPATH);
1932 if (SawSpare && SawPctSpare) {
1933 ViceLog(0, ("Both -spare and -pctspare specified, exiting.\n"));
1936 #ifdef AFS_SGI_XFS_IOPS_ENV
1937 ViceLog(0, ("XFS/EFS File server starting\n"));
1939 ViceLog(0, ("File server starting\n"));
1942 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
1943 /* initialize the pthread soft signal handler thread */
1947 /* install signal handlers for controlling the fileserver process */
1948 ResetCheckSignal(); /* set CheckSignal_Signal() sig handler */
1949 ResetCheckDescriptors(); /* set CheckDescriptors_Signal() sig handler */
1951 #if defined(AFS_SGI_ENV)
1952 /* give this guy a non-degrading priority so help busy servers */
1953 schedctl(NDPRI, 0, NDPNORMMAX);
1957 #ifndef AFS_NT40_ENV
1958 nice(-5); /* TODO: */
1961 assert(DInit(buffs) == 0);
1964 if (afs_winsockInit() < 0) {
1965 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
1966 ViceLog(0, ("File server failed to intialize winsock.\n"));
1972 /* if we support more than 16 threads, then we better have the ability
1973 ** to keep open a large number of files simultaneously
1975 #if defined(AFS_AIX_ENV) && !defined(AFS_AIX42_ENV)
1976 curLimit = OPEN_MAX; /* for pre AIX 4.2 systems */
1977 #elif defined(AFS_NT40_ENV)
1978 curLimit = NT_OPEN_MAX; /* open file descriptor limit on NT */
1981 curLimit = 0; /* the number of open file descriptors */
1982 code = getrlimit(RLIMIT_NOFILE, &rlim);
1984 curLimit = rlim.rlim_cur;
1985 rlim.rlim_cur = rlim.rlim_max;
1986 code = setrlimit(RLIMIT_NOFILE, &rlim);
1988 curLimit = rlim.rlim_max;
1991 ViceLog(0, ("Failed to increase open file limit, using default\n"));
1993 #endif /* defined(AFS_AIX_ENV) && !defined(AFS_AIX42_ENV) */
1995 curLimit -= 32; /* leave a slack of 32 file descriptors */
1996 if (lwps > curLimit) {
2000 lwps = 16; /* default to a maximum of 16 threads */
2002 ("The system supports a max of %d open files and we are starting %d threads\n",
2005 #ifndef AFS_PTHREAD_ENV
2006 assert(LWP_InitializeProcessSupport(LWP_MAX_PRIORITY - 2, &parentPid) ==
2008 #endif /* !AFS_PTHREAD_ENV */
2010 /* Initialize volume support */
2012 V_BreakVolumeCallbacks = BreakVolumeCallBacksLater;
2015 #ifdef AFS_PTHREAD_ENV
2016 SetLogThreadNumProgram( threadNum );
2019 /* initialize libacl routines */
2020 acl_Initialize(ACL_VERSION);
2022 /* initialize RX support */
2023 #ifndef AFS_NT40_ENV
2024 rxi_syscallp = viced_syscall;
2026 rx_extraPackets = rxpackets;
2027 rx_extraQuota = 4; /* for outgoing prserver calls from R threads */
2028 rx_SetBusyThreshold(busy_threshold, VBUSY);
2029 rx_SetCallAbortThreshold(abort_threshold);
2030 rx_SetConnAbortThreshold(abort_threshold);
2032 stackSize = 128 * 1024;
2034 stackSize = lwps * 4000;
2035 if (stackSize < 32000)
2037 else if (stackSize > 44000)
2040 #if defined(AFS_HPUX_ENV) || defined(AFS_SUN_ENV) || defined(AFS_SGI51_ENV) || defined(AFS_XBSD_ENV)
2041 rx_SetStackSize(1, stackSize);
2044 rx_SetUdpBufSize(udpBufSize); /* set the UDP buffer size for receive */
2045 rx_bindhost = SetupVL();
2047 if (rx_InitHost(rx_bindhost, (int)htons(7000)) < 0) {
2048 ViceLog(0, ("Cannot initialize RX\n"));
2051 if (!rxJumbograms) {
2052 /* Don't send and don't allow 3.4 clients to send jumbograms. */
2055 if (rxMaxMTU != -1) {
2056 rx_SetMaxMTU(rxMaxMTU);
2059 rx_SetRxDeadTime(30);
2060 sc[0] = rxnull_NewServerSecurityObject();
2061 sc[1] = 0; /* rxvab_NewServerSecurityObject(key1, 0) */
2062 sc[2] = rxkad_NewServerSecurityObject(rxkad_clear, NULL, get_key, NULL);
2063 sc[3] = rxkad_NewServerSecurityObject(rxkad_crypt, NULL, get_key, NULL);
2064 tservice = rx_NewServiceHost(rx_bindhost, /* port */ 0, /* service id */
2065 1, /*service name */
2067 /* security classes */ sc,
2068 /* numb sec classes */
2069 4, RXAFS_ExecuteRequest);
2072 ("Failed to initialize RX, probably two servers running.\n"));
2075 if (rxkadDisableDotCheck) {
2076 rx_SetSecurityConfiguration(tservice, RXS_CONFIG_FLAGS,
2077 (void *)RXS_CONFIG_FLAGS_DISABLE_DOTCHECK);
2079 rx_SetMinProcs(tservice, 3);
2080 rx_SetMaxProcs(tservice, lwps);
2081 rx_SetCheckReach(tservice, 1);
2082 rx_SetServerIdleDeadErr(tservice, VNOSERVICE);
2085 rx_NewService(0, RX_STATS_SERVICE_ID, "rpcstats", sc, 4,
2086 RXSTATS_ExecuteRequest);
2088 ViceLog(0, ("Failed to initialize rpc stat service.\n"));
2091 rx_SetMinProcs(tservice, 2);
2092 rx_SetMaxProcs(tservice, 4);
2095 * Enable RX hot threads, which allows the listener thread to trade
2096 * places with an idle thread and moves the context switch from listener
2097 * to worker out of the critical path.
2099 rx_EnableHotThread();
2101 /* Some rx debugging */
2102 if (rxlog || eventlog) {
2103 debugFile = afs_fopen("rx_dbg", "w");
2105 rx_debugFile = debugFile;
2107 rxevent_debugFile = debugFile;
2110 init_sys_error_to_et(); /* Set up error table translation */
2111 h_InitHostPackage(); /* set up local cellname and realmname */
2112 InitCallBack(numberofcbs);
2117 ViceLog(0, ("Fatal error in library initialization, exiting!!\n"));
2123 ViceLog(0, ("Fatal error in protection initialization, exiting!!\n"));
2127 /* allow super users to manage RX statistics */
2128 rx_SetRxStatUserOk(fs_rxstat_userok);
2130 #ifdef AFS_PTHREAD_ENV
2131 assert(pthread_cond_init(&fsync_cond, NULL) == 0);
2132 assert(pthread_mutex_init(&fsync_glock_mutex, NULL) == 0);
2135 #if !defined(AFS_DEMAND_ATTACH_FS)
2137 * For DAFS, we do not start the Rx server threads until after
2138 * the volume package is initialized, and fileserver state is
2139 * restored. This is necessary in order to keep host and callback
2140 * package state pristine until we have a chance to restore state.
2142 * Furthermore, startup latency is much lower with dafs, so this
2143 * shouldn't pose a serious problem.
2145 rx_StartServer(0); /* now start handling requests */
2148 /* we ensure that there is enough space in the vnode buffer to satisfy
2149 ** requests from all concurrent threads.
2150 ** the maximum number of vnodes used by a single thread at any one time
2151 ** is three ( "link" uses three vnodes simultaneously, one vLarge and
2152 ** two vSmall for linking files and two vLarge and one vSmall for linking
2155 minVnodesRequired = 2 * lwps + 1;
2156 if (minVnodesRequired > nSmallVns) {
2157 nSmallVns = minVnodesRequired;
2159 ("Overriding -s command line parameter with %d\n",
2162 if (minVnodesRequired > large) {
2163 large = minVnodesRequired;
2164 ViceLog(0, ("Overriding -l command line parameter with %d\n", large));
2167 /* We now do this after getting the listener up and running, so that client
2168 * connections don't timeout (maybe) if a file server is restarted, since it
2169 * will be available "real soon now". Worry about whether we can satisfy the
2170 * calls in the volume package itself.
2172 if (VInitVolumePackage(fileServer, large, nSmallVns, 0, volcache)) {
2174 ("Shutting down: errors encountered initializing volume package\n"));
2179 #ifdef AFS_DEMAND_ATTACH_FS
2180 if (fs_state.options.fs_state_restore) {
2183 * restore fileserver state */
2186 rx_StartServer(0); /* now start handling requests */
2187 #endif /* AFS_DEMAND_ATTACH_FS */
2190 * We are done calling fopen/fdopen. It is safe to use a large
2191 * of the file descriptor cache.
2195 #ifdef AFS_PTHREAD_ENV
2196 ViceLog(5, ("Starting pthreads\n"));
2197 #ifdef AFS_DEMAND_ATTACH_FS
2200 assert(pthread_attr_init(&tattr) == 0);
2201 assert(pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED) == 0);
2203 assert(pthread_create
2204 (&serverPid, &tattr, FiveMinuteCheckLWP,
2205 &fiveminutes) == 0);
2206 assert(pthread_create
2207 (&serverPid, &tattr, HostCheckLWP, &fiveminutes) == 0);
2208 assert(pthread_create
2209 (&serverPid, &tattr, FsyncCheckLWP, &fiveminutes) == 0);
2210 #else /* AFS_PTHREAD_ENV */
2211 ViceLog(5, ("Starting LWP\n"));
2212 assert(LWP_CreateProcess
2213 (FiveMinuteCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
2214 (void *)&fiveminutes, "FiveMinuteChecks",
2215 &serverPid) == LWP_SUCCESS);
2217 assert(LWP_CreateProcess
2218 (HostCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
2219 (void *)&fiveminutes, "HostCheck", &serverPid) == LWP_SUCCESS);
2220 assert(LWP_CreateProcess
2221 (FsyncCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
2222 (void *)&fiveminutes, "FsyncCheck", &serverPid) == LWP_SUCCESS);
2223 #endif /* AFS_PTHREAD_ENV */
2225 FT_GetTimeOfDay(&tp, 0);
2227 #ifndef AFS_QUIETFS_ENV
2228 if (console != NULL) {
2229 time_t t = tp.tv_sec;
2230 fprintf(console, "File server has started at %s\r",
2231 afs_ctime(&t, tbuffer, sizeof(tbuffer)));
2236 * Figure out the FileServer's name and primary address.
2238 ViceLog(0, ("Getting FileServer name...\n"));
2239 code = gethostname(FS_HostName, 64);
2241 ViceLog(0, ("gethostname() failed\n"));
2243 ViceLog(0, ("FileServer host name is '%s'\n", FS_HostName));
2245 ViceLog(0, ("Getting FileServer address...\n"));
2246 he = gethostbyname(FS_HostName);
2248 ViceLog(0, ("Can't find address for FileServer '%s'\n", FS_HostName));
2251 memcpy(&FS_HostAddr_NBO, he->h_addr, 4);
2252 (void)afs_inet_ntoa_r(FS_HostAddr_NBO, hoststr);
2253 FS_HostAddr_HBO = ntohl(FS_HostAddr_NBO);
2255 ("FileServer %s has address %s (0x%x or 0x%x in host byte order)\n",
2256 FS_HostName, hoststr, FS_HostAddr_NBO, FS_HostAddr_HBO));
2259 /* Install handler to catch the shutdown signal;
2260 * bosserver assumes SIGQUIT shutdown
2262 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
2263 softsig_signal(SIGQUIT, ShutDown_Signal);
2265 (void)signal(SIGQUIT, ShutDown_Signal);
2270 ("File Server started %s",
2271 afs_ctime(&t, tbuffer, sizeof(tbuffer))));
2272 #if FS_STATS_DETAILED
2273 afs_FullPerfStats.det.epoch.tv_sec = StartTime = tp.tv_sec;
2275 #ifdef AFS_PTHREAD_ENV
2277 sleep(1000); /* long time */
2279 #else /* AFS_PTHREAD_ENV */
2280 assert(LWP_WaitProcess(&parentPid) == LWP_SUCCESS);
2281 #endif /* AFS_PTHREAD_ENV */