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>
24 #include <afs/procmgmt.h>
31 #include <sys/types.h>
32 #include <afs/procmgmt.h> /* signal(), kill(), wait(), etc. */
41 #include <WINNT/afsevent.h>
44 #include <netinet/in.h>
46 #include <unistd.h> /* sysconf() */
50 #endif /* ITIMER_REAL */
51 #include <sys/resource.h>
52 #endif /* AFS_NT40_ENV */
57 #include <afs/afs_assert.h>
60 #include <afs/ptclient.h>
61 #include <afs/afsint.h>
62 #include <afs/vldbint.h>
63 #include <afs/errors.h>
64 #include <afs/ihandle.h>
65 #include <afs/vnode.h>
66 #include <afs/volume.h>
68 #include <afs/cellconfig.h>
70 #include <afs/prs_fs.h>
72 #include <rx/rxstat.h>
74 #include <afs/afs_args.h>
75 #include <afs/vlserver.h>
76 #include <afs/afsutil.h>
77 #include <afs/fileutil.h>
78 #include <afs/ptuser.h>
79 #include <afs/audit.h>
80 #include <afs/partition.h>
83 #include <afs/netutils.h>
85 #include "viced_prototypes.h"
88 #ifdef AFS_PTHREAD_ENV
89 #include <afs/softsig.h>
91 #if defined(AFS_SGI_ENV)
92 #include "sys/schedctl.h"
95 #include <rx/rx_globals.h>
99 void *ShutDown(void *);
100 static void ClearXStatValues(void);
101 static void NewParms(int);
102 static void PrintCounters(void);
103 static void ResetCheckDescriptors(void);
104 static void ResetCheckSignal(void);
105 static void *CheckSignal(void *);
107 static afs_int32 Do_VLRegisterRPC(void);
109 int eventlog = 0, rxlog = 0;
112 #ifdef AFS_PTHREAD_ENV
113 pthread_mutex_t fsync_glock_mutex;
114 pthread_cond_t fsync_cond;
117 #endif /* AFS_PTHREAD_ENV */
120 #define NT_OPEN_MAX 1024 /* This is an arbitrary no. we came up with for
121 * now. We hope this will be replaced by a more
122 * intelligent estimate later. */
125 int SystemId; /* ViceID of "Administrators" */
126 int SystemAnyUser; /* Viceid of "System:AnyUser" */
127 prlist SystemAnyUserCPS; /* CPS for "system:AnyUser */
128 int AnonymousID = 0; /* ViceId of "Anonymous" */
129 prlist AnonCPS; /* CPS for "Anonymous" */
131 struct afsconf_dir *confDir; /* Configuration dir object */
133 int restartMode = RESTART_ORDINARY;
136 * Home for the performance statistics.
138 struct afs_PerfStats afs_perfstats;
141 extern int Statistics;
149 int rxJumbograms = 0; /* default is to not send and receive jumbograms. */
150 int rxBind = 0; /* don't bind */
151 int rxkadDisableDotCheck = 0; /* disable check for dot in principal name */
153 afs_int32 implicitAdminRights = PRSFS_LOOKUP; /* The ADMINISTER right is
155 afs_int32 readonlyServer = 0;
158 int stackSize = 24000;
159 int fiveminutes = 300; /* 5 minutes. Change this for debugging only */
160 int CurrentConnections = 0;
161 int hostaclRefresh = 7200; /* refresh host clients' acls every 2 hrs */
162 #if defined(AFS_SGI_ENV)
168 * seconds to wait until forcing a panic during ShutDownAndCore(PANIC)
169 * in case we get stuck.
171 #ifdef AFS_DEMAND_ATTACH_FS
172 static int panic_timeout = 2 * 60;
174 static int panic_timeout = 30 * 60;
177 int rxpackets = 150; /* 100 */
178 int nSmallVns = 400; /* 200 */
179 int large = 400; /* 200 */
180 int volcache = 400; /* 400 */
181 int numberofcbs = 60000; /* 60000 */
182 int lwps = 9; /* 6 */
183 int buffs = 90; /* 70 */
184 int novbc = 0; /* Enable Volume Break calls */
185 int busy_threshold = 600;
186 int abort_threshold = 10;
187 int udpBufSize = 0; /* UDP buffer size for receive */
188 int sendBufSize = 16384; /* send buffer size */
189 int saneacls = 0; /* Sane ACLs Flag */
190 static int unsafe_attach = 0; /* avoid inUse check on vol attach? */
191 static int offline_timeout = -1; /* -offline-timeout option */
192 static int offline_shutdown_timeout = -1; /* -offline-shutdown-timeout option */
196 #ifdef AFS_PTHREAD_ENV
197 pthread_key_t viced_uclient_key;
200 #ifdef AFS_PTHREAD_ENV
201 pthread_key_t viced_uclient_key;
205 * FileServer's name and IP address, both network byte order and
208 #define ADDRSPERSITE 16 /* Same global is in rx/rx_user.c */
210 char FS_HostName[128] = "localhost";
211 afs_uint32 FS_HostAddr_NBO;
212 afs_uint32 FS_HostAddr_HBO;
213 afs_uint32 FS_HostAddrs[ADDRSPERSITE], FS_HostAddr_cnt = 0, FS_registered = 0;
214 /* All addresses in FS_HostAddrs are in NBO */
217 static void FlagMsg(void);
219 #ifdef AFS_DEMAND_ATTACH_FS
222 * fileserver mode support
224 * during fileserver shutdown, we have to track the graceful shutdown of
225 * certain background threads before we are allowed to dump state to
229 #if !defined(PTHREAD_RWLOCK_INITIALIZER) && defined(AFS_DARWIN80_ENV)
230 #define PTHREAD_RWLOCK_INITIALIZER {0x2DA8B3B4, {0}}
234 struct fs_state fs_state =
241 PTHREAD_COND_INITIALIZER,
242 PTHREAD_RWLOCK_INITIALIZER
244 #else /* AFS_NT40_ENV */
245 struct fs_state fs_state;
247 static int fs_stateInit(void)
249 fs_state.mode = FS_MODE_NORMAL;
250 fs_state.FiveMinuteLWP_tranquil = 0;
251 fs_state.HostCheckLWP_tranquil = 0;
252 fs_state.FsyncCheckLWP_tranquil = 0;
253 fs_state.salvsync_fatal_error = 0;
255 fs_state.options.fs_state_save = 1;
256 fs_state.options.fs_state_restore = 1;
257 fs_state.options.fs_state_verify_before_save = 1;
258 fs_state.options.fs_state_verify_after_restore = 1;
260 CV_INIT(&fs_state.worker_done_cv, "worker done", CV_DEFAULT, 0);
261 osi_Assert(pthread_rwlock_init(&fs_state.state_lock, NULL) == 0);
263 #endif /* AFS_NT40_ENV */
264 #endif /* AFS_DEMAND_ATTACH_FS */
267 * Home for the performance statistics.
272 CheckDescriptors(void *unused)
275 struct afs_stat status;
276 int tsize = getdtablesize();
278 for (i = 0; i < tsize; i++) {
279 if (afs_fstat(i, &status) != -1) {
280 printf("%d: dev %x, inode %u, length %u, type/mode %x\n", i,
281 (unsigned int) status.st_dev,
282 (unsigned int) status.st_ino,
283 (unsigned int) status.st_size,
288 ResetCheckDescriptors();
291 } /*CheckDescriptors */
294 #ifdef AFS_PTHREAD_ENV
296 CheckSignal_Signal(int x)
302 ShutDown_Signal(int x)
308 CheckDescriptors_Signal(int x)
310 CheckDescriptors(NULL);
312 #else /* AFS_PTHREAD_ENV */
314 CheckSignal_Signal(int x)
316 IOMGR_SoftSig(CheckSignal, 0);
320 ShutDown_Signal(int x)
322 IOMGR_SoftSig(ShutDown, 0);
326 CheckDescriptors_Signal(int x)
328 IOMGR_SoftSig(CheckDescriptors, 0);
330 #endif /* AFS_PTHREAD_ENV */
332 /* check whether caller is authorized to manage RX statistics */
334 fs_rxstat_userok(struct rx_call *call)
336 return afsconf_SuperUser(confDir, call, NULL);
340 ResetCheckSignal(void)
344 #if defined(AFS_HPUX_ENV)
347 #if defined(AFS_NT40_ENV)
354 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
355 softsig_signal(signo, CheckSignal_Signal);
357 signal(signo, CheckSignal_Signal);
362 ResetCheckDescriptors(void)
365 #if defined(AFS_PTHREAD_ENV)
366 softsig_signal(SIGTERM, CheckDescriptors_Signal);
368 (void)signal(SIGTERM, CheckDescriptors_Signal);
373 #if defined(AFS_PTHREAD_ENV)
377 return (intptr_t)pthread_getspecific(rx_thread_id_key);
383 viced_syscall(afs_uint32 a3, afs_uint32 a4, void *a5)
386 #ifndef AFS_LINUX20_ENV
389 old = (void (*)(int))signal(SIGSYS, SIG_IGN);
391 rcode = syscall(AFS_SYSCALL, 28 /* AFSCALL_CALL */ , a3, a4, a5);
392 #ifndef AFS_LINUX20_ENV
400 #if !defined(AFS_NT40_ENV)
401 #include "AFS_component_version_number.c"
402 #endif /* !AFS_NT40_ENV */
404 #define MAXADMINNAME 64
405 char adminName[MAXADMINNAME];
411 struct afs_stat status;
413 if ((afs_stat("/AdminName", &status)) || /* if file does not exist */
414 (status.st_size <= 0) || /* or it is too short */
415 (status.st_size >= (MAXADMINNAME)) || /* or it is too long */
416 !(fd = afs_open("/AdminName", O_RDONLY, 0))) { /* or the open fails */
417 strcpy(adminName, "System:Administrators"); /* use the default name */
419 (void)read(fd, adminName, status.st_size); /* use name from the file */
422 close(fd); /* close fd if it was opened */
424 } /*CheckAdminName */
430 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
431 /* set our 'thread-id' so that the host hold table works */
432 pthread_setspecific(rx_thread_id_key,
433 (void *)(intptr_t)rx_NewThreadId());
435 ("Set thread id %p for '%s'\n",
436 pthread_getspecific(rx_thread_id_key), s));
440 /* This LWP does things roughly every 5 minutes */
442 FiveMinuteCheckLWP(void *unused)
447 ViceLog(1, ("Starting five minute check process\n"));
448 setThreadId("FiveMinuteCheckLWP");
450 #ifdef AFS_DEMAND_ATTACH_FS
452 while (fs_state.mode == FS_MODE_NORMAL) {
453 fs_state.FiveMinuteLWP_tranquil = 1;
459 #ifdef AFS_PTHREAD_ENV
461 #else /* AFS_PTHREAD_ENV */
462 IOMGR_Sleep(fiveminutes);
463 #endif /* AFS_PTHREAD_ENV */
465 #ifdef AFS_DEMAND_ATTACH_FS
467 if (fs_state.mode != FS_MODE_NORMAL) {
470 fs_state.FiveMinuteLWP_tranquil = 0;
474 /* close the log so it can be removed */
475 ReOpenLog(AFSDIR_SERVER_FILELOG_FILEPATH); /* don't trunc, just append */
476 ViceLog(2, ("Cleaning up timed out callbacks\n"));
477 if (CleanupTimedOutCallBacks())
478 ViceLog(5, ("Timed out callbacks deleted\n"));
479 ViceLog(2, ("Set disk usage statistics\n"));
481 if (FS_registered == 1)
483 /* Force wakeup in case we missed something; pthreads does timedwait */
484 #ifndef AFS_PTHREAD_ENV
485 LWP_NoYieldSignal(fsync_wait);
487 if (printBanner && (++msg & 1)) { /* Every 10 minutes */
488 time_t now = FT_ApproxTime();
490 ("File server is running at %s\n",
491 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
493 #ifdef AFS_DEMAND_ATTACH_FS
497 #ifdef AFS_DEMAND_ATTACH_FS
498 fs_state.FiveMinuteLWP_tranquil = 1;
500 CV_BROADCAST(&fs_state.worker_done_cv);
505 } /*FiveMinuteCheckLWP */
508 /* This LWP does host checks every 5 minutes: it should not be used for
509 * other 5 minute activities because it may be delayed by timeouts when
510 * it probes the workstations
514 HostCheckLWP(void *unused)
516 ViceLog(1, ("Starting Host check process\n"));
517 setThreadId("HostCheckLWP");
518 #ifdef AFS_DEMAND_ATTACH_FS
520 while (fs_state.mode == FS_MODE_NORMAL) {
521 fs_state.HostCheckLWP_tranquil = 1;
527 #ifdef AFS_PTHREAD_ENV
529 #else /* AFS_PTHREAD_ENV */
530 IOMGR_Sleep(fiveminutes);
531 #endif /* AFS_PTHREAD_ENV */
533 #ifdef AFS_DEMAND_ATTACH_FS
535 if (fs_state.mode != FS_MODE_NORMAL) {
538 fs_state.HostCheckLWP_tranquil = 0;
542 ViceLog(2, ("Checking for dead venii & clients\n"));
545 #ifdef AFS_DEMAND_ATTACH_FS
549 #ifdef AFS_DEMAND_ATTACH_FS
550 fs_state.HostCheckLWP_tranquil = 1;
552 CV_BROADCAST(&fs_state.worker_done_cv);
559 /* This LWP does fsync checks every 5 minutes: it should not be used for
560 * other 5 minute activities because it may be delayed by timeouts when
561 * it probes the workstations
564 FsyncCheckLWP(void *unused)
567 #ifdef AFS_PTHREAD_ENV
568 struct timespec fsync_next;
570 ViceLog(1, ("Starting fsync check process\n"));
572 setThreadId("FsyncCheckLWP");
574 #ifdef AFS_DEMAND_ATTACH_FS
576 while (fs_state.mode == FS_MODE_NORMAL) {
577 fs_state.FsyncCheckLWP_tranquil = 1;
583 #ifdef AFS_PTHREAD_ENV
584 /* rounding is fine */
585 fsync_next.tv_nsec = 0;
586 fsync_next.tv_sec = time(0) + fiveminutes;
588 code = CV_TIMEDWAIT(&fsync_cond, &fsync_glock_mutex,
590 if (code != 0 && code != ETIMEDOUT)
591 ViceLog(0, ("pthread_cond_timedwait returned %d\n", code));
592 #else /* AFS_PTHREAD_ENV */
593 if ((code = LWP_WaitProcess(fsync_wait)) != LWP_SUCCESS)
594 ViceLog(0, ("LWP_WaitProcess returned %d\n", code));
595 #endif /* AFS_PTHREAD_ENV */
598 #ifdef AFS_DEMAND_ATTACH_FS
600 if (fs_state.mode != FS_MODE_NORMAL) {
603 fs_state.FsyncCheckLWP_tranquil = 0;
605 #endif /* AFS_DEMAND_ATTACH_FS */
607 ViceLog(2, ("Checking for fsync events\n"));
609 code = BreakLaterCallBacks();
611 #ifdef AFS_DEMAND_ATTACH_FS
615 #ifdef AFS_DEMAND_ATTACH_FS
616 fs_state.FsyncCheckLWP_tranquil = 1;
618 CV_BROADCAST(&fs_state.worker_done_cv);
621 #endif /* AFS_DEMAND_ATTACH_FS */
625 /*------------------------------------------------------------------------
626 * PRIVATE ClearXStatValues
629 * Initialize all of the values collected via the xstat
639 * Must be called during File Server initialization.
643 *------------------------------------------------------------------------*/
646 ClearXStatValues(void)
647 { /*ClearXStatValues */
649 struct fs_stats_opTimingData *opTimeP; /*Ptr to timing struct */
650 struct fs_stats_xferData *opXferP; /*Ptr to xfer struct */
651 int i; /*Loop counter */
654 * Zero all xstat-related structures.
656 memset((&afs_perfstats), 0, sizeof(struct afs_PerfStats));
657 #if FS_STATS_DETAILED
658 memset((&afs_FullPerfStats), 0,
659 sizeof(struct fs_stats_FullPerfStats));
662 * That's not enough. We have to set reasonable minima for
663 * time and xfer values in the detailed stats.
665 opTimeP = &(afs_FullPerfStats.det.rpcOpTimes[0]);
666 for (i = 0; i < FS_STATS_NUM_RPC_OPS; i++, opTimeP++)
667 opTimeP->minTime.tv_sec = 999999;
669 opXferP = &(afs_FullPerfStats.det.xferOpTimes[0]);
670 for (i = 0; i < FS_STATS_NUM_XFER_OPS; i++, opXferP++) {
671 opXferP->minTime.tv_sec = 999999;
672 opXferP->minBytes = 999999999;
676 * There's more. We have to set our unique system identifier, as
677 * declared in param.h. If such a thing is not defined, we bitch
678 * and declare ourselves to be an unknown system type.
681 afs_perfstats.sysname_ID = SYS_NAME_ID;
684 ViceLog(0, ("Sys name ID constant not defined in param.h!!\n"));
685 ViceLog(0, ("[Choosing ``undefined'' sys name ID.\n"));
687 afs_perfstats.sysname_ID = SYS_NAME_ID_UNDEFINED;
688 #endif /* SYS_NAME_ID */
691 } /*ClearXStatValues */
693 int CopyOnWrite_calls = 0, CopyOnWrite_off0 = 0, CopyOnWrite_size0 = 0;
694 afs_fsize_t CopyOnWrite_maxsize = 0;
699 int dirbuff, dircall, dirio;
701 int workstations, activeworkstations, delworkstations;
704 #ifdef AFS_DEMAND_ATTACH_FS
708 FT_GetTimeOfDay(&tpl, 0);
711 ("Vice was last started at %s\n",
712 afs_ctime(&StartTime, tbuffer, sizeof(tbuffer))));
714 #ifdef AFS_DEMAND_ATTACH_FS
715 if (LogLevel >= 125) {
716 stats_flags = VOL_STATS_PER_CHAIN2;
717 } else if (LogLevel >= 25) {
718 stats_flags = VOL_STATS_PER_CHAIN;
720 VPrintExtendedCacheStats(stats_flags);
724 DStat(&dirbuff, &dircall, &dirio);
726 ("With %d directory buffers; %d reads resulted in %d read I/Os\n",
727 dirbuff, dircall, dirio));
728 rx_PrintStats(stderr);
729 audit_PrintStats(stderr);
731 PrintCallBackStats();
733 processSize = -1; /* TODO: */
735 processSize = (int)((long)sbrk(0) >> 10);
738 ("There are %d connections, process size %d\n",
739 CurrentConnections, processSize));
740 h_GetWorkStats(&workstations, &activeworkstations, &delworkstations,
741 tpl.tv_sec - 15 * 60);
743 ("There are %d workstations, %d are active (req in < 15 mins), %d marked \"down\"\n",
744 workstations, activeworkstations, delworkstations));
745 ViceLog(0, ("CopyOnWrite: calls %d off0 %d size0 %d maxsize 0x%llx\n",
746 CopyOnWrite_calls, CopyOnWrite_off0, CopyOnWrite_size0, CopyOnWrite_maxsize));
755 CheckSignal(void *unused)
757 if (FS_registered > 0) {
759 * We have proper ip addresses; tell the vlserver what we got; the following
760 * routine will do the proper reporting for us
773 ShutdownWatchdogLWP(void *unused)
775 sleep(panic_timeout);
776 ViceLog(0, ("ShutdownWatchdogLWP: Failed to shutdown and panic "
777 "within %d seconds; forcing panic\n", panic_timeout));
778 osi_Panic("ShutdownWatchdogLWP: Failed to shutdown and panic "
779 "within %d seconds; forcing panic\n", panic_timeout);
784 ShutDownAndCore(int dopanic)
786 time_t now = time(0);
790 #ifdef AFS_PTHREAD_ENV
791 pthread_t watchdogPid;
792 pthread_attr_t tattr;
793 osi_Assert(pthread_attr_init(&tattr) == 0);
794 osi_Assert(pthread_create(&watchdogPid, &tattr, ShutdownWatchdogLWP, NULL) == 0);
797 osi_Assert(LWP_CreateProcess
798 (ShutdownWatchdogLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
799 NULL, "ShutdownWatchdog", &watchdogPid) == LWP_SUCCESS);
803 /* do not allows new reqests to be served from now on, all new requests
804 * are returned with an error code of RX_RESTARTING ( transient failure ) */
805 rx_SetRxTranquil(); /* dhruba */
809 #ifdef AFS_DEMAND_ATTACH_FS
811 if (fs_state.mode == FS_MODE_SHUTDOWN) {
812 /* it is possible for at least fs_stateSave() (called below) to call
813 * ShutDownAndCore if there's host list corruption; prevent
814 * deinitializing some stuff twice */
815 ViceLog(0, ("ShutDownAndCore called during shutdown? Skipping volume "
816 "and host package shutdown\n"));
820 fs_state.mode = FS_MODE_SHUTDOWN;
825 ("Shutting down file server at %s",
826 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
828 ViceLog(0, ("ABNORMAL SHUTDOWN, see core file.\n"));
833 /* shut down volume package */
836 #ifdef AFS_DEMAND_ATTACH_FS
837 if (fs_state.options.fs_state_save) {
840 * save fileserver state to disk */
843 ViceLog(0, ("Not saving fileserver state; abnormal shutdown\n"));
846 /* make sure background threads have finished all of their asynchronous
847 * work on host and callback structures */
849 while (!fs_state.FiveMinuteLWP_tranquil ||
850 !fs_state.HostCheckLWP_tranquil ||
851 !fs_state.FsyncCheckLWP_tranquil) {
854 ViceLog(0, ("waiting for background host/callback threads to quiesce before saving fileserver state...\n"));
855 CV_WAIT(&fs_state.worker_done_cv, &fileproc_glock_mutex);
861 /* ok. it should now be fairly safe. let's do the state dump */
867 #endif /* AFS_DEMAND_ATTACH_FS */
870 rx_PrintStats(debugFile);
876 ("File server has terminated abnormally at %s\n",
877 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
880 ("File server has terminated normally at %s\n",
881 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
884 if (dopanic) /* XXX pass in file and line? */
885 osi_Panic("Panic requested\n");
891 ShutDown(void *unused)
892 { /* backward compatibility */
893 ShutDownAndCore(DONTPANIC);
901 /* default supports help flag */
903 fputs("Usage: fileserver ", stdout);
904 fputs("[-auditlog <log path>] ", stdout);
905 fputs("[-audit-interface <file|sysvmq> (default is file)] ", stdout);
906 fputs("[-d <debug level>] ", stdout);
907 fputs("[-p <number of processes>] ", stdout);
908 fputs("[-spare <number of spare blocks>] ", stdout);
909 fputs("[-pctspare <percentage spare>] ", stdout);
910 fputs("[-b <buffers>] ", stdout);
911 fputs("[-l <large vnodes>] ", stdout);
912 fputs("[-s <small vnodes>] ", stdout);
913 fputs("[-vc <volume cachesize>] ", stdout);
914 fputs("[-w <call back wait interval>] ", stdout);
915 fputs("[-cb <number of call backs>] ", stdout);
916 fputs("[-banner (print banner every 10 minutes)] ", stdout);
917 fputs("[-novbc (whole volume cbs disabled)] ", stdout);
918 fputs("[-implicit <admin mode bits: rlidwka>] ", stdout);
919 fputs("[-readonly (read-only file server)] ", stdout);
920 fputs("[-hr <number of hours between refreshing the host cps>] ", stdout);
921 fputs("[-busyat <redirect clients when queue > n>] ", stdout);
922 fputs("[-nobusy <no VBUSY before a volume is attached>] ", stdout);
923 fputs("[-rxpck <number of rx extra packets>] ", stdout);
924 fputs("[-rxdbg (enable rx debugging)] ", stdout);
925 fputs("[-rxdbge (enable rxevent debugging)] ", stdout);
926 fputs("[-rxmaxmtu <bytes>] ", stdout);
927 fputs("[-rxbind (bind the Rx socket to one address)] ", stdout);
928 fputs("[-allow-dotted-principals (disable the rxkad principal name dot check)] ", stdout);
929 fputs("[-vhandle-setaside (fds reserved for non-cache io [default 128])] ", stdout);
930 fputs("[-vhandle-max-cachesize (max open files [default 128])] ", stdout);
931 fputs("[-vhandle-initial-cachesize (fds reserved for cache io [default 128])] ", stdout);
932 #ifdef AFS_DEMAND_ATTACH_FS
933 fputs("[-fs-state-dont-save (disable state save during shutdown)] ", stdout);
934 fputs("[-fs-state-dont-restore (disable state restore during startup)] ", stdout);
935 fputs("[-fs-state-verify <none|save|restore|both> (default is both)] ", stdout);
936 fputs("[-vattachpar <max number of volume attach/shutdown threads> (default is 1)] ", stdout);
937 fputs("[-vhashsize <log(2) of number of volume hash buckets> (default is 8)] ", stdout);
938 fputs("[-vlrudisable (disable VLRU functionality)] ", stdout);
939 fputs("[-vlruthresh <minutes before unused volumes become eligible for soft detach> (default is 2 hours)] ", stdout);
940 fputs("[-vlruinterval <seconds between VLRU scans> (default is 2 minutes)] ", stdout);
941 fputs("[-vlrumax <max volumes to soft detach in one VLRU scan> (default is 8)] ", stdout);
942 fputs("[-unsafe-nosalvage (bypass volume inUse safety check on attach, bypassing salvage)] ", stdout);
943 #elif AFS_PTHREAD_ENV
944 fputs("[-vattachpar <number of volume attach threads> (default is 1)] ", stdout);
947 fputs("[-m <min percentage spare in partition>] ", stdout);
949 #if defined(AFS_SGI_ENV)
950 fputs("[-lock (keep fileserver from swapping)] ", stdout);
952 fputs("[-L (large server conf)] ", stdout);
953 fputs("[-S (small server conf)] ", stdout);
954 fputs("[-k <stack size>] ", stdout);
955 fputs("[-realm <Kerberos realm name>] ", stdout);
956 fputs("[-udpsize <size of socket buffer in bytes>] ", stdout);
957 fputs("[-sendsize <size of send buffer in bytes>] ", stdout);
958 fputs("[-abortthreshold <abort threshold>] ", stdout);
959 fputs("[-nojumbo (disable jumbogram network packets - deprecated)] ", stdout);
960 fputs("[-jumbo (enable jumbogram network packets)] ", stdout);
961 fputs("[-offline-timeout <client RX timeout for offlining volumes>]", stdout);
962 fputs("[-offline-shutdown-timeout <RX timeout for offlining volumes during shutdown>]", stdout);
963 /* fputs("[-enable_peer_stats] ", stdout); */
964 /* fputs("[-enable_process_stats] ", stdout); */
965 fputs("[-help]\n", stdout);
967 ViceLog(0, ("%s", buffer));
976 ParseRights(char *arights)
982 if (!arights || !strcmp(arights, "")) {
983 printf("Missing list of mode bits on -implicit option\n");
986 if (!strcmp(arights, "none"))
988 else if (!strcmp(arights, "read"))
989 mode = PRSFS_READ | PRSFS_LOOKUP;
990 else if (!strcmp(arights, "write"))
992 PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
993 PRSFS_WRITE | PRSFS_LOCK;
994 else if (!strcmp(arights, "all"))
996 PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
997 PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER;
999 len = strlen(arights);
1000 for (i = 0; i < len; i++) {
1005 mode |= PRSFS_LOOKUP;
1007 mode |= PRSFS_INSERT;
1009 mode |= PRSFS_DELETE;
1011 mode |= PRSFS_WRITE;
1015 mode |= PRSFS_ADMINISTER;
1033 printf("Illegal -implicit rights character '%c'.\n", tc);
1042 * Limit MAX_FILESERVER_THREAD by the system limit on the number of
1043 * pthreads (sysconf(_SC_THREAD_THREADS_MAX)), if applicable and
1046 * AIX: sysconf() limit is real
1047 * HP-UX: sysconf() limit is real
1048 * IRIX: sysconf() limit is apparently NOT real -- too small
1049 * DUX: sysconf() limit is apparently NOT real -- too big
1050 * Linux: sysconf() limit is apparently NOT real -- too big
1051 * Solaris: no sysconf() limit
1054 max_fileserver_thread(void)
1056 #if defined(AFS_PTHREAD_ENV)
1057 #if defined(AFS_AIX_ENV) || defined(AFS_HPUX_ENV)
1060 ans = sysconf(_SC_THREAD_THREADS_MAX);
1061 if (0 < ans && ans < MAX_FILESERVER_THREAD)
1064 #endif /* defined(AFS_PTHREAD_ENV) */
1065 return MAX_FILESERVER_THREAD;
1068 /* from ihandle.c */
1069 extern ih_init_params vol_io_params;
1072 ParseArgs(int argc, char *argv[])
1074 int SawL = 0, SawS = 0, SawVC = 0;
1075 int Sawrxpck = 0, Sawsmall = 0, Sawlarge = 0, Sawcbs = 0, Sawlwps =
1079 int bufSize = 0; /* temp variable to read in udp socket buf size */
1081 char *auditFileName = NULL;
1083 for (i = 1; i < argc; i++) {
1084 if (!strcmp(argv[i], "-d")) {
1085 if ((i + 1) >= argc) {
1086 fprintf(stderr, "missing argument for -d\n");
1089 debuglevel = atoi(argv[++i]);
1090 LogLevel = debuglevel;
1091 } else if (!strcmp(argv[i], "-banner")) {
1093 } else if (!strcmp(argv[i], "-implicit")) {
1094 if ((i + 1) >= argc) {
1095 fprintf(stderr, "missing argument for -implicit\n");
1098 implicitAdminRights = ParseRights(argv[++i]);
1099 if (implicitAdminRights < 0)
1100 return implicitAdminRights;
1101 } else if (!strcmp(argv[i], "-readonly")) {
1103 } else if (!strcmp(argv[i], "-L")) {
1105 } else if (!strcmp(argv[i], "-S")) {
1107 } else if (!strcmp(argv[i], "-p")) {
1109 if ((i + 1) >= argc) {
1110 fprintf(stderr, "missing argument for -p\n");
1113 lwps = atoi(argv[++i]);
1114 } else if (!strcmp(argv[i], "-b")) {
1116 if ((i + 1) >= argc) {
1117 fprintf(stderr, "missing argument for -b\n");
1120 buffs = atoi(argv[++i]);
1121 } else if (!strcmp(argv[i], "-l")) {
1123 if ((i + 1) >= argc) {
1124 fprintf(stderr, "missing argument for -l\n");
1127 large = atoi(argv[++i]);
1128 } else if (!strcmp(argv[i], "-vc")) {
1130 if ((i + 1) >= argc) {
1131 fprintf(stderr, "missing argument for -vc\n");
1134 volcache = atoi(argv[++i]);
1135 } else if (!strcmp(argv[i], "-novbc")) {
1137 } else if (!strcmp(argv[i], "-rxpck")) {
1139 if ((i + 1) >= argc) {
1140 fprintf(stderr, "missing argument for -rxpck\n");
1143 rxpackets = atoi(argv[++i]);
1144 #ifdef AFS_PTHREAD_ENV
1145 } else if (!strcmp(argv[i], "-vattachpar")) {
1146 if ((i + 1) >= argc) {
1147 fprintf(stderr, "missing argument for %s\n", argv[i]);
1150 vol_attach_threads = atoi(argv[++i]);
1151 #endif /* AFS_PTHREAD_ENV */
1152 } else if (!strcmp(argv[i], "-vhandle-setaside")) {
1153 if ((i + 1) >= argc) {
1154 fprintf(stderr, "missing argument for %s\n", argv[i]);
1157 vol_io_params.fd_handle_setaside = atoi(argv[++i]);
1158 } else if (!strcmp(argv[i], "-vhandle-max-cachesize")) {
1159 if ((i + 1) >= argc) {
1160 fprintf(stderr, "missing argument for %s\n", argv[i]);
1163 vol_io_params.fd_max_cachesize = atoi(argv[++i]);
1164 } else if (!strcmp(argv[i], "-vhandle-initial-cachesize")) {
1165 if ((i + 1) >= argc) {
1166 fprintf(stderr, "missing argument for %s\n", argv[i]);
1169 vol_io_params.fd_initial_cachesize = atoi(argv[++i]);
1170 #ifdef AFS_DEMAND_ATTACH_FS
1171 } else if (!strcmp(argv[i], "-fs-state-dont-save")) {
1172 fs_state.options.fs_state_save = 0;
1173 } else if (!strcmp(argv[i], "-fs-state-dont-restore")) {
1174 fs_state.options.fs_state_restore = 0;
1175 } else if (!strcmp(argv[i], "-fs-state-verify")) {
1176 if ((i + 1) >= argc) {
1177 fprintf(stderr, "missing argument for %s\n", argv[i]);
1181 if (!strcmp(argv[i], "none")) {
1182 fs_state.options.fs_state_verify_before_save = 0;
1183 fs_state.options.fs_state_verify_after_restore = 0;
1184 } else if (!strcmp(argv[i], "save")) {
1185 fs_state.options.fs_state_verify_after_restore = 0;
1186 } else if (!strcmp(argv[i], "restore")) {
1187 fs_state.options.fs_state_verify_before_save = 0;
1188 } else if (!strcmp(argv[i], "both")) {
1191 fprintf(stderr, "invalid argument for %s\n", argv[i-1]);
1194 } else if (!strcmp(argv[i], "-vhashsize")) {
1196 if ((i + 1) >= argc) {
1197 fprintf(stderr, "missing argument for %s\n", argv[i]);
1200 hashsize = atoi(argv[++i]);
1201 if (VSetVolHashSize(hashsize)) {
1202 fprintf(stderr, "specified -vhashsize (%s) is invalid or out "
1203 "of range\n", argv[i]);
1206 } else if (!strcmp(argv[i], "-vlrudisable")) {
1207 VLRU_SetOptions(VLRU_SET_ENABLED, 0);
1208 } else if (!strcmp(argv[i], "-vlruthresh")) {
1209 if ((i + 1) >= argc) {
1210 fprintf(stderr, "missing argument for %s\n", argv[i]);
1213 VLRU_SetOptions(VLRU_SET_THRESH, 60*atoi(argv[++i]));
1214 } else if (!strcmp(argv[i], "-vlruinterval")) {
1215 if ((i + 1) >= argc) {
1216 fprintf(stderr, "missing argument for %s\n", argv[i]);
1219 VLRU_SetOptions(VLRU_SET_INTERVAL, atoi(argv[++i]));
1220 } else if (!strcmp(argv[i], "-vlrumax")) {
1221 if ((i + 1) >= argc) {
1222 fprintf(stderr, "missing argument for %s\n", argv[i]);
1225 VLRU_SetOptions(VLRU_SET_MAX, atoi(argv[++i]));
1226 } else if (!strcmp(argv[i], "-unsafe-nosalvage")) {
1228 #endif /* AFS_DEMAND_ATTACH_FS */
1229 } else if (!strcmp(argv[i], "-s")) {
1231 if ((i + 1) >= argc) {
1232 fprintf(stderr, "missing argument for -s\n");
1235 nSmallVns = atoi(argv[++i]);
1236 } else if (!strcmp(argv[i], "-abortthreshold")) {
1237 if ((i + 1) >= argc) {
1238 fprintf(stderr, "missing argument for -abortthreshold\n");
1241 abort_threshold = atoi(argv[++i]);
1242 } else if (!strcmp(argv[i], "-k")) {
1243 if ((i + 1) >= argc) {
1244 fprintf(stderr, "missing argument for -k\n");
1247 stack = atoi(argv[++i]);
1249 #if defined(AFS_SGI_ENV)
1250 else if (!strcmp(argv[i], "-lock")) {
1254 else if (!strcmp(argv[i], "-spare")) {
1255 if ((i + 1) >= argc) {
1256 fprintf(stderr, "missing argument for -spare\n");
1259 BlocksSpare = atoi(argv[++i]);
1261 } else if (!strcmp(argv[i], "-pctspare")) {
1262 if ((i + 1) >= argc) {
1263 fprintf(stderr, "missing argument for -pctspare\n");
1266 PctSpare = atoi(argv[++i]);
1267 BlocksSpare = 0; /* has non-zero default */
1269 } else if (!strcmp(argv[i], "-w")) {
1270 if ((i + 1) >= argc) {
1271 fprintf(stderr, "missing argument for -w\n");
1274 fiveminutes = atoi(argv[++i]);
1275 } else if (!strcmp(argv[i], "-hr")) {
1277 if ((i + 1) >= argc) {
1278 fprintf(stderr, "missing argument for -hr\n");
1281 hr = atoi(argv[++i]);
1282 if ((hr < 1) || (hr > 36)) {
1284 ("host acl refresh interval of %d hours is invalid; hours must be between 1 and 36\n\n",
1288 hostaclRefresh = hr * 60 * 60;
1289 } else if (!strcmp(argv[i], "-rxdbg"))
1291 else if (!strcmp(argv[i], "-rxdbge"))
1293 else if (!strcmp(argv[i], "-cb")) {
1295 if ((i + 1) >= argc) {
1296 fprintf(stderr, "missing argument for -cb\n");
1299 numberofcbs = atoi(argv[++i]);
1300 if ((numberofcbs < 10000) || (numberofcbs > 2147483647)) {
1302 ("number of cbs %d invalid; must be between 10000 and 2147483647\n",
1306 } else if (!strcmp(argv[i], "-busyat")) {
1308 if ((i + 1) >= argc) {
1309 fprintf(stderr, "missing argument for -busyat\n");
1312 busy_threshold = atoi(argv[++i]);
1313 if (busy_threshold < 10) {
1315 ("Busy threshold %d is too low, will compute default.\n",
1319 } else if (!strcmp(argv[i], "-nobusy"))
1321 #ifdef AFS_AIX32_ENV
1322 else if (!strcmp(argv[i], "-m")) {
1323 extern int aixlow_water;
1324 if ((i + 1) >= argc) {
1325 fprintf(stderr, "missing argument for -m\n");
1328 aixlow_water = atoi(argv[++i]);
1329 if ((aixlow_water < 0) || (aixlow_water > 30)) {
1330 printf("space reserved %d% invalid; must be between 0-30%\n",
1336 else if (!strcmp(argv[i], "-nojumbo")) {
1338 } else if (!strcmp(argv[i], "-jumbo")) {
1340 } else if (!strcmp(argv[i], "-rxbind")) {
1342 } else if (!strcmp(argv[i], "-allow-dotted-principals")) {
1343 rxkadDisableDotCheck = 1;
1344 } else if (!strcmp(argv[i], "-rxmaxmtu")) {
1345 if ((i + 1) >= argc) {
1346 fprintf(stderr, "missing argument for -rxmaxmtu\n");
1349 rxMaxMTU = atoi(argv[++i]);
1350 if ((rxMaxMTU < RX_MIN_PACKET_SIZE) ||
1351 (rxMaxMTU > RX_MAX_PACKET_DATA_SIZE)) {
1352 printf("rxMaxMTU %d%% invalid; must be between %d-%" AFS_SIZET_FMT "\n",
1353 rxMaxMTU, RX_MIN_PACKET_SIZE,
1354 RX_MAX_PACKET_DATA_SIZE);
1357 } else if (!strcmp(argv[i], "-realm")) {
1358 extern char local_realms[AFS_NUM_LREALMS][AFS_REALM_SZ];
1359 extern int num_lrealms;
1360 if ((i + 1) >= argc) {
1361 fprintf(stderr, "missing argument for -realm\n");
1364 if (strlen(argv[++i]) >= AFS_REALM_SZ) {
1366 ("-realm argument must contain fewer than %d characters.\n",
1370 if (num_lrealms == -1)
1372 if (num_lrealms >= AFS_NUM_LREALMS) {
1374 ("a maximum of %d -realm arguments can be specified.\n",
1378 strncpy(local_realms[num_lrealms++], argv[i], AFS_REALM_SZ);
1379 } else if (!strcmp(argv[i], "-udpsize")) {
1380 if ((i + 1) >= argc) {
1381 printf("You have to specify -udpsize <integer value>\n");
1384 bufSize = atoi(argv[++i]);
1385 if (bufSize < rx_GetMinUdpBufSize())
1387 ("Warning:udpsize %d is less than minimum %d; ignoring\n",
1388 bufSize, rx_GetMinUdpBufSize());
1390 udpBufSize = bufSize;
1391 } else if (!strcmp(argv[i], "-sendsize")) {
1392 if ((i + 1) >= argc) {
1393 printf("You have to specify -sendsize <integer value>\n");
1396 bufSize = atoi(argv[++i]);
1397 if (bufSize < 16384)
1399 ("Warning:sendsize %d is less than minimum %d; ignoring\n",
1402 sendBufSize = bufSize;
1403 } else if (!strcmp(argv[i], "-enable_peer_stats")) {
1404 rx_enablePeerRPCStats();
1405 } else if (!strcmp(argv[i], "-enable_process_stats")) {
1406 rx_enableProcessRPCStats();
1408 else if (strcmp(argv[i], "-auditlog") == 0) {
1409 auditFileName = argv[++i];
1411 else if (strcmp(argv[i], "-audit-interface") == 0) {
1412 char *interface = argv[++i];
1414 if (osi_audit_interface(interface)) {
1415 printf("Invalid audit interface '%s'\n", interface);
1419 #ifndef AFS_NT40_ENV
1420 else if (strcmp(argv[i], "-syslog") == 0) {
1421 /* set syslog logging flag */
1422 serverLogSyslog = 1;
1423 } else if (strncmp(argv[i], "-syslog=", 8) == 0) {
1424 serverLogSyslog = 1;
1425 serverLogSyslogFacility = atoi(argv[i] + 8);
1428 else if (strcmp(argv[i], "-mrafslogs") == 0) {
1429 /* set syslog logging flag */
1432 else if (strcmp(argv[i], "-saneacls") == 0) {
1435 else if (strcmp(argv[i], "-offline-timeout") == 0) {
1436 if (i + 1 >= argc) {
1437 printf("You have to specify -offline-timeout <integer>\n");
1440 offline_timeout = atoi(argv[++i]);
1441 #ifndef AFS_PTHREAD_ENV
1442 if (offline_timeout != -1) {
1443 printf("The only valid -offline-timeout value for the LWP "
1444 "fileserver is -1\n");
1447 #endif /* AFS_PTHREAD_ENV */
1448 if (offline_timeout < -1) {
1449 printf("Invalid -offline-timeout value %s; the only valid "
1450 "negative value is -1\n", argv[i]);
1454 else if (strcmp(argv[i], "-offline-shutdown-timeout") == 0) {
1455 if (i + 1 >= argc) {
1456 printf("You have to specify -offline-shutdown-timeout "
1460 offline_shutdown_timeout = atoi(argv[++i]);
1461 #ifndef AFS_PTHREAD_ENV
1462 if (offline_shutdown_timeout != -1) {
1463 printf("The only valid -offline-shutdown-timeout value for the "
1464 "LWP fileserver is -1\n");
1467 #endif /* AFS_PTHREAD_ENV */
1468 if (offline_shutdown_timeout < -1) {
1469 printf("Invalid -offline-timeout value %s; the only valid "
1470 "negative value is -1\n", argv[i]);
1479 printf("Only one of -L, or -S must be specified\n");
1490 numberofcbs = 20000;
1506 numberofcbs = 64000;
1515 busy_threshold = 3 * rxpackets / 2;
1517 osi_audit_file(auditFileName);
1519 lwps_max = max_fileserver_thread() - FILESERVER_HELPER_THREADS;
1520 if (lwps > lwps_max)
1533 NewParms(int initializing)
1535 static struct afs_stat sbuf;
1538 char *argv[MAXPARMS];
1541 if (!(afs_stat("/vice/file/parms", &sbuf))) {
1542 parms = (char *)malloc(sbuf.st_size);
1545 fd = afs_open("parms", O_RDONLY, 0666);
1547 ViceLog(0, ("Open for parms failed with errno = %d\n", errno));
1551 i = read(fd, parms, sbuf.st_size);
1553 if (i != sbuf.st_size) {
1555 ViceLog(0, ("Read on parms failed with errno = %d\n", errno));
1558 ("Read on parms failed; expected %ld bytes but read %d\n",
1559 (long) sbuf.st_size, i));
1565 for (i = 0; i < MAXPARMS; argv[i++] = 0);
1567 for (argc = i = 0; i < sbuf.st_size; i++) {
1568 if ((*(parms + i) != ' ') && (*(parms + i) != '\n')) {
1569 if (argv[argc] == 0)
1570 argv[argc] = (parms + i);
1572 *(parms + i) = '\0';
1573 if (argv[argc] != 0) {
1574 if (++argc == MAXPARMS)
1577 while ((*(parms + i + 1) == ' ')
1578 || (*(parms + i + 1) == '\n'))
1582 if (ParseArgs(argc, argv) == 0) {
1583 ViceLog(0, ("Change parameters to:"));
1585 ViceLog(0, ("Invalid parameter in:"));
1587 for (i = 0; i < argc; i++) {
1588 ViceLog(0, (" %s", argv[i]));
1592 } else if (!initializing)
1594 ("Received request to change parms but no parms file exists\n"));
1599 /* Miscellaneous routines */
1603 ViceLog(0, ("%s\n", msg));
1604 osi_Panic("%s\n", msg);
1615 * If this fails, it's because something major is wrong, and is not
1616 * likely to be time dependent.
1618 code = pr_Initialize(2, AFSDIR_SERVER_ETC_DIRPATH, 0);
1621 ("Couldn't initialize protection library; code=%d.\n", code));
1625 #ifdef AFS_PTHREAD_ENV
1626 osi_Assert(pthread_key_create(&viced_uclient_key, NULL) == 0);
1629 SystemId = SYSADMINID;
1630 SystemAnyUser = ANYUSERID;
1631 SystemAnyUserCPS.prlist_len = 0;
1632 SystemAnyUserCPS.prlist_val = NULL;
1633 AnonCPS.prlist_len = 0;
1634 AnonCPS.prlist_val = NULL;
1636 code = pr_GetCPS(SystemAnyUser, &SystemAnyUserCPS);
1639 ("Couldn't get CPS for AnyUser, will try again in 30 seconds; code=%d.\n",
1643 code = pr_GetCPS(ANONYMOUSID, &AnonCPS);
1646 ("Couldn't get Anonymous CPS, exiting; code=%d.\n",
1650 AnonymousID = ANONYMOUSID;
1653 #ifdef AFS_PTHREAD_ENV
1655 #else /* AFS_PTHREAD_ENV */
1657 #endif /* AFS_PTHREAD_ENV */
1661 struct rx_connection *serverconns[MAXSERVERS];
1662 struct ubik_client *cstruct;
1665 vl_Initialize(const char *confDir)
1668 afs_int32 scIndex = RX_SECIDX_NULL;
1669 struct afsconf_dir *tdir;
1670 struct rx_securityClass *sc;
1671 struct afsconf_cell info;
1673 tdir = afsconf_Open(confDir);
1676 ("Could not open configuration directory (%s).\n", confDir));
1679 code = afsconf_ClientAuth(tdir, &sc, &scIndex);
1681 ViceLog(0, ("Could not get security object for localAuth\n"));
1684 code = afsconf_GetCellInfo(tdir, NULL, AFSCONF_VLDBSERVICE, &info);
1685 if (info.numServers > MAXSERVERS) {
1687 ("vl_Initialize: info.numServers=%d (> MAXSERVERS=%d)\n",
1688 info.numServers, MAXSERVERS));
1691 for (i = 0; i < info.numServers; i++)
1693 rx_NewConnection(info.hostAddr[i].sin_addr.s_addr,
1694 info.hostAddr[i].sin_port, USER_SERVICE_ID, sc,
1696 code = ubik_ClientInit(serverconns, &cstruct);
1697 afsconf_Close(tdir);
1699 ViceLog(0, ("vl_Initialize: ubik client init failed.\n"));
1705 #define SYSIDMAGIC 0x88aabbcc
1706 #define SYSIDVERSION 1
1711 afs_int32 fd, nentries, i;
1712 struct versionStamp vsn;
1713 struct afs_stat status;
1716 if ((afs_stat(AFSDIR_SERVER_SYSID_FILEPATH, &status))
1717 || (status.st_size <= 0)) {
1718 ViceLog(0, ("%s: doesn't exist\n", AFSDIR_SERVER_SYSID_FILEPATH));
1721 if (!(fd = afs_open(AFSDIR_SERVER_SYSID_FILEPATH, O_RDONLY, 0))) {
1723 ("%s: can't open (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1727 if ((i = read(fd, (char *)&vsn, sizeof(vsn))) != sizeof(vsn)) {
1729 ("%s: Read failed (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1733 if (vsn.magic != SYSIDMAGIC) {
1735 ("%s: wrong magic %x (we support %x)\n",
1736 AFSDIR_SERVER_SYSID_FILEPATH, vsn.magic, SYSIDMAGIC));
1739 if (vsn.version != SYSIDVERSION) {
1741 ("%s: wrong version %d (we support %d)\n",
1742 AFSDIR_SERVER_SYSID_FILEPATH, vsn.version, SYSIDVERSION));
1746 read(fd, (char *)&uuid,
1747 sizeof(struct afsUUID))) != sizeof(struct afsUUID)) {
1749 ("%s: read of uuid failed (%d)\n",
1750 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1753 afs_ntohuuid(&uuid);
1756 read(fd, (char *)&nentries,
1757 sizeof(afs_int32))) != sizeof(afs_int32)) {
1759 ("%s: Read of entries failed (%d)\n",
1760 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1763 if (nentries <= 0 || nentries > ADDRSPERSITE) {
1765 ("%s: invalid num of interfaces: %d\n",
1766 AFSDIR_SERVER_SYSID_FILEPATH, nentries));
1769 if (FS_HostAddr_cnt == 0) {
1770 FS_HostAddr_cnt = nentries;
1771 for (i = 0; i < nentries; i++) {
1772 if (read(fd, (char *)&FS_HostAddrs[i], sizeof(afs_int32)) !=
1773 sizeof(afs_int32)) {
1775 ("%s: Read of addresses failed (%d)\n",
1776 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1777 FS_HostAddr_cnt = 0; /* reset it */
1783 ("%s: address list ignored (NetInfo/NetRestrict override)\n",
1784 AFSDIR_SERVER_SYSID_FILEPATH));
1791 WriteSysIdFile(void)
1794 struct versionStamp vsn;
1795 struct afs_stat status;
1798 if (!afs_stat(AFSDIR_SERVER_SYSID_FILEPATH, &status)) {
1800 * File exists; keep the old one around
1802 renamefile(AFSDIR_SERVER_SYSID_FILEPATH,
1803 AFSDIR_SERVER_OLDSYSID_FILEPATH);
1805 fd = afs_open(AFSDIR_SERVER_SYSID_FILEPATH, O_WRONLY | O_TRUNC | O_CREAT,
1809 ("%s: can't create (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1813 vsn.magic = SYSIDMAGIC;
1815 if ((i = write(fd, (char *)&vsn, sizeof(vsn))) != sizeof(vsn)) {
1817 ("%s: write failed (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1822 afs_htonuuid(&uuid);
1824 write(fd, (char *)&uuid,
1825 sizeof(struct afsUUID))) != sizeof(struct afsUUID)) {
1827 ("%s: write of uuid failed (%d)\n",
1828 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1832 write(fd, (char *)&FS_HostAddr_cnt,
1833 sizeof(afs_int32))) != sizeof(afs_int32)) {
1835 ("%s: write of # of entries failed (%d)\n",
1836 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1839 for (i = 0; i < FS_HostAddr_cnt; i++) {
1840 if (write(fd, (char *)&FS_HostAddrs[i], sizeof(afs_int32)) !=
1841 sizeof(afs_int32)) {
1843 ("%s: write of addresses failed (%d)\n",
1844 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1854 * This routine sets up the buffers for the VL_RegisterAddrs RPC. All addresses
1855 * in FS_HostAddrs[] are in NBO, while the RPC treats them as a "blob" of data
1856 * and so we need to convert each of them into HBO which is what the extra
1857 * array called FS_HostAddrs_HBO is used here.
1860 Do_VLRegisterRPC(void)
1864 afs_uint32 FS_HostAddrs_HBO[ADDRSPERSITE];
1867 for (i = 0; i < FS_HostAddr_cnt; i++)
1868 FS_HostAddrs_HBO[i] = ntohl(FS_HostAddrs[i]);
1869 addrs.bulkaddrs_len = FS_HostAddr_cnt;
1870 addrs.bulkaddrs_val = (afs_uint32 *) FS_HostAddrs_HBO;
1871 code = ubik_VL_RegisterAddrs(cstruct, 0, &FS_HostUUID, 0, &addrs);
1873 if (code == VL_MULTIPADDR) {
1875 ("VL_RegisterAddrs rpc failed; The IP address exists on a different server; repair it\n"));
1877 ("VL_RegisterAddrs rpc failed; See VLLog for details\n"));
1879 } else if (code == RXGEN_OPCODE) {
1881 ("vlserver doesn't support VL_RegisterAddrs rpc; ignored\n"));
1882 FS_registered = 2; /* So we don't have to retry in the gc daemon */
1885 ("VL_RegisterAddrs rpc failed; will retry periodically (code=%d, err=%d)\n",
1887 FS_registered = 1; /* Retry in the gc daemon */
1890 FS_registered = 2; /* So we don't have to retry in the gc daemon */
1902 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH || AFSDIR_SERVER_NETINFO_FILEPATH) {
1904 * Find addresses we are supposed to register as per the netrestrict
1905 * and netinfo files (/usr/afs/local/NetInfo and
1906 * /usr/afs/local/NetRestict)
1909 afs_int32 code = parseNetFiles(FS_HostAddrs, NULL, NULL,
1910 ADDRSPERSITE, reason,
1911 AFSDIR_SERVER_NETINFO_FILEPATH,
1912 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
1914 ViceLog(0, ("Can't register any valid addresses: %s\n", reason));
1917 FS_HostAddr_cnt = (afs_uint32) code;
1920 FS_HostAddr_cnt = rx_getAllAddr(FS_HostAddrs, ADDRSPERSITE);
1923 if (FS_HostAddr_cnt == 1 && rxBind == 1)
1924 code = FS_HostAddrs[0];
1926 code = htonl(INADDR_ANY);
1936 * If this fails, it's because something major is wrong, and is not
1937 * likely to be time dependent.
1939 code = vl_Initialize(AFSDIR_SERVER_ETC_DIRPATH);
1942 ("Couldn't initialize protection library; code=%d.\n", code));
1946 /* Read or create the sysid file and register the fileserver's
1947 * IP addresses with the vlserver.
1949 code = ReadSysIdFile();
1951 /* Need to create the file */
1952 ViceLog(0, ("Creating new SysID file\n"));
1953 if ((code = afs_uuid_create(&FS_HostUUID))) {
1954 ViceLog(0, ("Failed to create new uuid: %d\n", code));
1958 /* A good sysid file exists; inform the vlserver. If any conflicts,
1959 * we always use the latest interface available as the real truth.
1962 code = Do_VLRegisterRPC();
1967 main(int argc, char *argv[])
1971 struct rx_securityClass **securityClasses;
1972 afs_int32 numClasses;
1973 struct rx_service *tservice;
1974 #ifdef AFS_PTHREAD_ENV
1975 pthread_t serverPid;
1976 pthread_attr_t tattr;
1977 #else /* AFS_PTHREAD_ENV */
1978 PROCESS parentPid, serverPid;
1979 #endif /* AFS_PTHREAD_ENV */
1981 int minVnodesRequired; /* min size of vnode cache */
1982 #ifndef AFS_NT40_ENV
1983 struct rlimit rlim; /* max number of open file descriptors */
1987 afs_uint32 rx_bindhost;
1988 VolumePackageOptions opts;
1990 #ifdef AFS_AIX32_ENV
1991 struct sigaction nsa;
1993 sigemptyset(&nsa.sa_mask);
1994 nsa.sa_handler = SIG_DFL;
1995 nsa.sa_flags = SA_FULLDUMP;
1996 sigaction(SIGABRT, &nsa, NULL);
1997 sigaction(SIGSEGV, &nsa, NULL);
2001 /* Initialize dirpaths */
2002 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
2004 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
2006 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
2010 /* set ihandle package defaults prior to parsing args */
2013 if (ParseArgs(argc, argv)) {
2017 #ifdef AFS_PTHREAD_ENV
2018 MUTEX_INIT(&fileproc_glock_mutex, "fileproc", MUTEX_DEFAULT, 0);
2019 #endif /* AFS_PTHREAD_ENV */
2021 #ifdef AFS_SGI_VNODE_GLUE
2022 if (afs_init_kernel_config(-1) < 0) {
2024 ("Can't determine NUMA configuration, not starting fileserver.\n");
2028 confDir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
2030 fprintf(stderr, "Unable to open config directory %s\n",
2031 AFSDIR_SERVER_ETC_DIRPATH);
2037 /* Open FileLog on stdout, stderr, fd 1 and fd2 (for perror), sigh. */
2038 #ifndef AFS_NT40_ENV
2039 serverLogSyslogTag = "fileserver";
2041 OpenLog(AFSDIR_SERVER_FILELOG_FILEPATH);
2044 if (SawSpare && SawPctSpare) {
2045 ViceLog(0, ("Both -spare and -pctspare specified, exiting.\n"));
2048 LogCommandLine(argc, argv, "starting", "", "File server", FSLog);
2050 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
2051 /* initialize the pthread soft signal handler thread */
2055 /* install signal handlers for controlling the fileserver process */
2056 ResetCheckSignal(); /* set CheckSignal_Signal() sig handler */
2057 ResetCheckDescriptors(); /* set CheckDescriptors_Signal() sig handler */
2059 #if defined(AFS_SGI_ENV)
2060 /* give this guy a non-degrading priority so help busy servers */
2061 schedctl(NDPRI, 0, NDPNORMMAX);
2065 #ifndef AFS_NT40_ENV
2066 nice(-5); /* TODO: */
2069 osi_Assert(DInit(buffs) == 0);
2070 #ifdef AFS_DEMAND_ATTACH_FS
2075 if (afs_winsockInit() < 0) {
2076 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
2077 ViceLog(0, ("File server failed to intialize winsock.\n"));
2083 /* if we support more than 16 threads, then we better have the ability
2084 ** to keep open a large number of files simultaneously
2086 #if defined(AFS_AIX_ENV) && !defined(AFS_AIX42_ENV)
2087 curLimit = OPEN_MAX; /* for pre AIX 4.2 systems */
2088 #elif defined(AFS_NT40_ENV)
2089 curLimit = NT_OPEN_MAX; /* open file descriptor limit on NT */
2092 curLimit = 0; /* the number of open file descriptors */
2093 code = getrlimit(RLIMIT_NOFILE, &rlim);
2095 curLimit = rlim.rlim_cur;
2096 rlim.rlim_cur = rlim.rlim_max;
2097 code = setrlimit(RLIMIT_NOFILE, &rlim);
2099 curLimit = rlim.rlim_max;
2102 ViceLog(0, ("Failed to increase open file limit, using default\n"));
2104 #endif /* defined(AFS_AIX_ENV) && !defined(AFS_AIX42_ENV) */
2106 curLimit -= 32; /* leave a slack of 32 file descriptors */
2107 if (lwps > curLimit) {
2111 lwps = 16; /* default to a maximum of 16 threads */
2113 /* tune the ihandle fd cache accordingly */
2114 if (vol_io_params.fd_max_cachesize < curLimit)
2115 vol_io_params.fd_max_cachesize = curLimit + 1;
2118 ("The system supports a max of %d open files and we are starting %d threads (ihandle fd cache is %d)\n",
2119 curLimit, lwps, vol_io_params.fd_max_cachesize));
2121 #ifndef AFS_PTHREAD_ENV
2122 osi_Assert(LWP_InitializeProcessSupport(LWP_MAX_PRIORITY - 2, &parentPid) ==
2124 #endif /* !AFS_PTHREAD_ENV */
2126 /* Initialize volume support */
2128 V_BreakVolumeCallbacks = BreakVolumeCallBacksLater;
2131 #ifdef AFS_PTHREAD_ENV
2132 SetLogThreadNumProgram( threadNum );
2135 /* initialize libacl routines */
2136 acl_Initialize(ACL_VERSION);
2138 /* initialize RX support */
2139 #ifndef AFS_NT40_ENV
2140 rxi_syscallp = viced_syscall;
2142 rx_extraPackets = rxpackets;
2143 rx_extraQuota = 4; /* for outgoing prserver calls from R threads */
2144 rx_SetBusyThreshold(busy_threshold, VBUSY);
2145 rx_SetCallAbortThreshold(abort_threshold);
2146 rx_SetConnAbortThreshold(abort_threshold);
2148 stackSize = 128 * 1024;
2150 stackSize = lwps * 4000;
2151 if (stackSize < 32000)
2153 else if (stackSize > 44000)
2156 #if defined(AFS_HPUX_ENV) || defined(AFS_SUN_ENV) || defined(AFS_SGI51_ENV) || defined(AFS_XBSD_ENV)
2157 rx_SetStackSize(1, stackSize);
2160 rx_SetUdpBufSize(udpBufSize); /* set the UDP buffer size for receive */
2161 rx_bindhost = SetupVL();
2163 if (rx_InitHost(rx_bindhost, (int)htons(7000)) < 0) {
2164 ViceLog(0, ("Cannot initialize RX\n"));
2167 if (!rxJumbograms) {
2168 /* Don't send and don't allow 3.4 clients to send jumbograms. */
2171 if (rxMaxMTU != -1) {
2172 rx_SetMaxMTU(rxMaxMTU);
2175 rx_SetRxDeadTime(30);
2176 afsconf_SetSecurityFlags(confDir, AFSCONF_SECOPTS_ALWAYSENCRYPT);
2177 afsconf_BuildServerSecurityObjects(confDir, &securityClasses, &numClasses);
2179 tservice = rx_NewServiceHost(rx_bindhost, /* port */ 0, /* service id */
2180 1, /*service name */
2182 securityClasses, numClasses,
2183 RXAFS_ExecuteRequest);
2186 ("Failed to initialize RX, probably two servers running.\n"));
2189 if (rxkadDisableDotCheck) {
2190 rx_SetSecurityConfiguration(tservice, RXS_CONFIG_FLAGS,
2191 (void *)RXS_CONFIG_FLAGS_DISABLE_DOTCHECK);
2193 rx_SetMinProcs(tservice, 3);
2194 rx_SetMaxProcs(tservice, lwps);
2195 rx_SetCheckReach(tservice, 1);
2196 rx_SetServerIdleDeadErr(tservice, VNOSERVICE);
2199 rx_NewService(0, RX_STATS_SERVICE_ID, "rpcstats", securityClasses,
2200 numClasses, RXSTATS_ExecuteRequest);
2202 ViceLog(0, ("Failed to initialize rpc stat service.\n"));
2205 rx_SetMinProcs(tservice, 2);
2206 rx_SetMaxProcs(tservice, 4);
2209 * Enable RX hot threads, which allows the listener thread to trade
2210 * places with an idle thread and moves the context switch from listener
2211 * to worker out of the critical path.
2213 rx_EnableHotThread();
2215 /* Some rx debugging */
2216 if (rxlog || eventlog) {
2217 debugFile = afs_fopen("rx_dbg", "w");
2219 rx_debugFile = debugFile;
2221 rxevent_debugFile = debugFile;
2224 init_sys_error_to_et(); /* Set up error table translation */
2225 h_InitHostPackage(); /* set up local cellname and realmname */
2226 InitCallBack(numberofcbs);
2230 if (code && code != VL_MULTIPADDR) {
2231 ViceLog(0, ("Fatal error in library initialization, exiting!!\n"));
2236 if (code && code != -1) {
2237 ViceLog(0, ("Fatal error in protection initialization, exiting!!\n"));
2241 /* allow super users to manage RX statistics */
2242 rx_SetRxStatUserOk(fs_rxstat_userok);
2244 CV_INIT(&fsync_cond, "fsync", CV_DEFAULT, 0);
2245 MUTEX_INIT(&fsync_glock_mutex, "fsync", MUTEX_DEFAULT, 0);
2247 #if !defined(AFS_DEMAND_ATTACH_FS)
2249 * For DAFS, we do not start the Rx server threads until after
2250 * the volume package is initialized, and fileserver state is
2251 * restored. This is necessary in order to keep host and callback
2252 * package state pristine until we have a chance to restore state.
2254 * Furthermore, startup latency is much lower with dafs, so this
2255 * shouldn't pose a serious problem.
2257 rx_StartServer(0); /* now start handling requests */
2260 /* we ensure that there is enough space in the vnode buffer to satisfy
2261 ** requests from all concurrent threads.
2262 ** the maximum number of vnodes used by a single thread at any one time
2263 ** is three ( "link" uses three vnodes simultaneously, one vLarge and
2264 ** two vSmall for linking files and two vLarge and one vSmall for linking
2267 minVnodesRequired = 2 * lwps + 1;
2268 if (minVnodesRequired > nSmallVns) {
2269 nSmallVns = minVnodesRequired;
2271 ("Overriding -s command line parameter with %d\n",
2274 if (minVnodesRequired > large) {
2275 large = minVnodesRequired;
2276 ViceLog(0, ("Overriding -l command line parameter with %d\n", large));
2279 /* We now do this after getting the listener up and running, so that client
2280 * connections don't timeout (maybe) if a file server is restarted, since it
2281 * will be available "real soon now". Worry about whether we can satisfy the
2282 * calls in the volume package itself.
2284 VOptDefaults(fileServer, &opts);
2285 opts.nLargeVnodes = large;
2286 opts.nSmallVnodes = nSmallVns;
2287 opts.volcache = volcache;
2288 opts.unsafe_attach = unsafe_attach;
2289 if (offline_timeout != -1) {
2290 opts.interrupt_rxcall = rx_InterruptCall;
2291 opts.offline_timeout = offline_timeout;
2293 if (offline_shutdown_timeout == -1) {
2294 /* default to -offline-timeout, if shutdown-specific timeout is not
2296 opts.offline_shutdown_timeout = offline_timeout;
2298 opts.interrupt_rxcall = rx_InterruptCall;
2299 opts.offline_shutdown_timeout = offline_shutdown_timeout;
2302 if (VInitVolumePackage2(fileServer, &opts)) {
2304 ("Shutting down: errors encountered initializing volume package\n"));
2309 /* Install handler to catch the shutdown signal;
2310 * bosserver assumes SIGQUIT shutdown
2312 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
2313 softsig_signal(SIGQUIT, ShutDown_Signal);
2315 (void)signal(SIGQUIT, ShutDown_Signal);
2318 if (VInitAttachVolumes(fileServer)) {
2320 ("Shutting down: errors encountered initializing volume package\n"));
2325 #ifdef AFS_DEMAND_ATTACH_FS
2326 if (fs_state.options.fs_state_restore) {
2329 * restore fileserver state */
2332 rx_StartServer(0); /* now start handling requests */
2333 #endif /* AFS_DEMAND_ATTACH_FS */
2336 * We are done calling fopen/fdopen. It is safe to use a large
2337 * of the file descriptor cache.
2341 #ifdef AFS_PTHREAD_ENV
2342 ViceLog(5, ("Starting pthreads\n"));
2343 osi_Assert(pthread_attr_init(&tattr) == 0);
2344 osi_Assert(pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED) == 0);
2346 osi_Assert(pthread_create
2347 (&serverPid, &tattr, FiveMinuteCheckLWP,
2348 &fiveminutes) == 0);
2349 osi_Assert(pthread_create
2350 (&serverPid, &tattr, HostCheckLWP, &fiveminutes) == 0);
2351 osi_Assert(pthread_create
2352 (&serverPid, &tattr, FsyncCheckLWP, &fiveminutes) == 0);
2353 #else /* AFS_PTHREAD_ENV */
2354 ViceLog(5, ("Starting LWP\n"));
2355 osi_Assert(LWP_CreateProcess
2356 (FiveMinuteCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
2357 (void *)&fiveminutes, "FiveMinuteChecks",
2358 &serverPid) == LWP_SUCCESS);
2360 osi_Assert(LWP_CreateProcess
2361 (HostCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
2362 (void *)&fiveminutes, "HostCheck", &serverPid) == LWP_SUCCESS);
2363 osi_Assert(LWP_CreateProcess
2364 (FsyncCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
2365 (void *)&fiveminutes, "FsyncCheck", &serverPid) == LWP_SUCCESS);
2366 #endif /* AFS_PTHREAD_ENV */
2368 FT_GetTimeOfDay(&tp, 0);
2371 * Figure out the FileServer's name and primary address.
2373 ViceLog(0, ("Getting FileServer name...\n"));
2374 code = gethostname(FS_HostName, 64);
2376 ViceLog(0, ("gethostname() failed\n"));
2378 ViceLog(0, ("FileServer host name is '%s'\n", FS_HostName));
2380 ViceLog(0, ("Getting FileServer address...\n"));
2381 he = gethostbyname(FS_HostName);
2383 ViceLog(0, ("Can't find address for FileServer '%s'\n", FS_HostName));
2386 memcpy(&FS_HostAddr_NBO, he->h_addr, 4);
2387 (void)afs_inet_ntoa_r(FS_HostAddr_NBO, hoststr);
2388 FS_HostAddr_HBO = ntohl(FS_HostAddr_NBO);
2390 ("FileServer %s has address %s (0x%x or 0x%x in host byte order)\n",
2391 FS_HostName, hoststr, FS_HostAddr_NBO, FS_HostAddr_HBO));
2396 ("File Server started %s",
2397 afs_ctime(&t, tbuffer, sizeof(tbuffer))));
2398 #if FS_STATS_DETAILED
2399 afs_FullPerfStats.det.epoch.tv_sec = StartTime = tp.tv_sec;
2401 #ifdef AFS_PTHREAD_ENV
2403 sleep(1000); /* long time */
2405 #else /* AFS_PTHREAD_ENV */
2406 osi_Assert(LWP_WaitProcess(&parentPid) == LWP_SUCCESS);
2407 #endif /* AFS_PTHREAD_ENV */