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. */
39 #include <WINNT/afsevent.h>
42 #include <netinet/in.h>
44 #include <unistd.h> /* sysconf() */
48 #endif /* ITIMER_REAL */
49 #include <sys/resource.h>
50 #endif /* AFS_NT40_ENV */
55 #include <afs/afs_assert.h>
58 #include <afs/ptclient.h>
59 #include <afs/afsint.h>
60 #include <afs/vldbint.h>
61 #include <afs/errors.h>
62 #include <afs/ihandle.h>
63 #include <afs/vnode.h>
64 #include <afs/volume.h>
66 #include <afs/cellconfig.h>
68 #include <afs/prs_fs.h>
70 #include <rx/rxstat.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
87 #include <afs/softsig.h>
89 #if defined(AFS_SGI_ENV)
90 #include "sys/schedctl.h"
93 #include <rx/rx_globals.h>
96 #define afs_stat stat64
97 #define afs_fstat fstat64
98 #define afs_open open64
99 #define afs_fopen fopen64
100 #else /* !O_LARGEFILE */
101 #define afs_stat stat
102 #define afs_fstat fstat
103 #define afs_open open
104 #define afs_fopen fopen
105 #endif /* !O_LARGEFILE */
109 void *ShutDown(void *);
110 static void ClearXStatValues(void);
111 static void NewParms(int);
112 static void PrintCounters(void);
113 static void ResetCheckDescriptors(void);
114 static void ResetCheckSignal(void);
115 static void *CheckSignal(void *);
117 static afs_int32 Do_VLRegisterRPC(void);
119 int eventlog = 0, rxlog = 0;
122 #ifdef AFS_PTHREAD_ENV
123 pthread_mutex_t fsync_glock_mutex;
124 pthread_cond_t fsync_cond;
127 #endif /* AFS_PTHREAD_ENV */
130 #define NT_OPEN_MAX 1024 /* This is an arbitrary no. we came up with for
131 * now. We hope this will be replaced by a more
132 * intelligent estimate later. */
135 int SystemId; /* ViceID of "Administrators" */
136 int SystemAnyUser; /* Viceid of "System:AnyUser" */
137 prlist SystemAnyUserCPS; /* CPS for "system:AnyUser */
138 int AnonymousID = 0; /* ViceId of "Anonymous" */
139 prlist AnonCPS; /* CPS for "Anonymous" */
141 struct afsconf_dir *confDir; /* Configuration dir object */
143 int restartMode = RESTART_ORDINARY;
146 * Home for the performance statistics.
148 struct afs_PerfStats afs_perfstats;
151 extern int Statistics;
159 int rxJumbograms = 0; /* default is to not send and receive jumbograms. */
160 int rxBind = 0; /* don't bind */
161 int rxkadDisableDotCheck = 0; /* disable check for dot in principal name */
163 afs_int32 implicitAdminRights = PRSFS_LOOKUP; /* The ADMINISTER right is
165 afs_int32 readonlyServer = 0;
168 int stackSize = 24000;
169 int fiveminutes = 300; /* 5 minutes. Change this for debugging only */
170 int CurrentConnections = 0;
171 int hostaclRefresh = 7200; /* refresh host clients' acls every 2 hrs */
172 #if defined(AFS_SGI_ENV)
178 * seconds to wait until forcing a panic during ShutDownAndCore(PANIC)
179 * in case we get stuck.
181 #ifdef AFS_DEMAND_ATTACH_FS
182 static int panic_timeout = 2 * 60;
184 static int panic_timeout = 30 * 60;
187 int rxpackets = 150; /* 100 */
188 int nSmallVns = 400; /* 200 */
189 int large = 400; /* 200 */
190 int volcache = 400; /* 400 */
191 int numberofcbs = 60000; /* 60000 */
192 int lwps = 9; /* 6 */
193 int buffs = 90; /* 70 */
194 int novbc = 0; /* Enable Volume Break calls */
195 int busy_threshold = 600;
196 int abort_threshold = 10;
197 int udpBufSize = 0; /* UDP buffer size for receive */
198 int sendBufSize = 16384; /* send buffer size */
199 int saneacls = 0; /* Sane ACLs Flag */
200 static int unsafe_attach = 0; /* avoid inUse check on vol attach? */
201 static int offline_timeout = -1; /* -offline-timeout option */
202 static int offline_shutdown_timeout = -1; /* -offline-shutdown-timeout option */
206 #ifdef AFS_PTHREAD_ENV
207 pthread_key_t viced_uclient_key;
210 #ifdef AFS_PTHREAD_ENV
211 pthread_key_t viced_uclient_key;
215 * FileServer's name and IP address, both network byte order and
218 #define ADDRSPERSITE 16 /* Same global is in rx/rx_user.c */
220 char FS_HostName[128] = "localhost";
221 afs_uint32 FS_HostAddr_NBO;
222 afs_uint32 FS_HostAddr_HBO;
223 afs_uint32 FS_HostAddrs[ADDRSPERSITE], FS_HostAddr_cnt = 0, FS_registered = 0;
224 /* All addresses in FS_HostAddrs are in NBO */
227 static void FlagMsg(void);
229 #ifdef AFS_DEMAND_ATTACH_FS
232 * fileserver mode support
234 * during fileserver shutdown, we have to track the graceful shutdown of
235 * certain background threads before we are allowed to dump state to
239 #if !defined(PTHREAD_RWLOCK_INITIALIZER) && defined(AFS_DARWIN80_ENV)
240 #define PTHREAD_RWLOCK_INITIALIZER {0x2DA8B3B4, {0}}
244 struct fs_state fs_state =
251 PTHREAD_COND_INITIALIZER,
252 PTHREAD_RWLOCK_INITIALIZER
254 #else /* AFS_NT40_ENV */
255 struct fs_state fs_state;
257 static int fs_stateInit(void)
259 fs_state.mode = FS_MODE_NORMAL;
260 fs_state.FiveMinuteLWP_tranquil = 0;
261 fs_state.HostCheckLWP_tranquil = 0;
262 fs_state.FsyncCheckLWP_tranquil = 0;
263 fs_state.salvsync_fatal_error = 0;
265 fs_state.options.fs_state_save = 1;
266 fs_state.options.fs_state_restore = 1;
267 fs_state.options.fs_state_verify_before_save = 1;
268 fs_state.options.fs_state_verify_after_restore = 1;
270 CV_INIT(&fs_state.worker_done_cv, "worker done", CV_DEFAULT, 0);
271 osi_Assert(pthread_rwlock_init(&fs_state.state_lock, NULL) == 0);
273 #endif /* AFS_NT40_ENV */
274 #endif /* AFS_DEMAND_ATTACH_FS */
277 * Home for the performance statistics.
282 CheckDescriptors(void *unused)
285 struct afs_stat status;
286 int tsize = getdtablesize();
288 for (i = 0; i < tsize; i++) {
289 if (afs_fstat(i, &status) != -1) {
290 printf("%d: dev %x, inode %u, length %u, type/mode %x\n", i,
291 (unsigned int) status.st_dev,
292 (unsigned int) status.st_ino,
293 (unsigned int) status.st_size,
298 ResetCheckDescriptors();
301 } /*CheckDescriptors */
304 #ifdef AFS_PTHREAD_ENV
306 CheckSignal_Signal(int x)
312 ShutDown_Signal(int x)
318 CheckDescriptors_Signal(int x)
320 CheckDescriptors(NULL);
322 #else /* AFS_PTHREAD_ENV */
324 CheckSignal_Signal(int x)
326 IOMGR_SoftSig(CheckSignal, 0);
330 ShutDown_Signal(int x)
332 IOMGR_SoftSig(ShutDown, 0);
336 CheckDescriptors_Signal(int x)
338 IOMGR_SoftSig(CheckDescriptors, 0);
340 #endif /* AFS_PTHREAD_ENV */
342 /* check whether caller is authorized to manage RX statistics */
344 fs_rxstat_userok(struct rx_call *call)
346 return afsconf_SuperUser(confDir, call, NULL);
350 ResetCheckSignal(void)
354 #if defined(AFS_HPUX_ENV)
357 #if defined(AFS_NT40_ENV)
364 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
365 softsig_signal(signo, CheckSignal_Signal);
367 signal(signo, CheckSignal_Signal);
372 ResetCheckDescriptors(void)
375 #if defined(AFS_PTHREAD_ENV)
376 softsig_signal(SIGTERM, CheckDescriptors_Signal);
378 (void)signal(SIGTERM, CheckDescriptors_Signal);
383 #if defined(AFS_PTHREAD_ENV)
387 return (intptr_t)pthread_getspecific(rx_thread_id_key);
393 viced_syscall(afs_uint32 a3, afs_uint32 a4, void *a5)
396 #ifndef AFS_LINUX20_ENV
399 old = (void (*)(int))signal(SIGSYS, SIG_IGN);
401 rcode = syscall(AFS_SYSCALL, 28 /* AFSCALL_CALL */ , a3, a4, a5);
402 #ifndef AFS_LINUX20_ENV
410 #if !defined(AFS_NT40_ENV)
411 #include "AFS_component_version_number.c"
412 #endif /* !AFS_NT40_ENV */
414 #define MAXADMINNAME 64
415 char adminName[MAXADMINNAME];
421 struct afs_stat status;
423 if ((afs_stat("/AdminName", &status)) || /* if file does not exist */
424 (status.st_size <= 0) || /* or it is too short */
425 (status.st_size >= (MAXADMINNAME)) || /* or it is too long */
426 !(fd = afs_open("/AdminName", O_RDONLY, 0))) { /* or the open fails */
427 strcpy(adminName, "System:Administrators"); /* use the default name */
429 (void)read(fd, adminName, status.st_size); /* use name from the file */
432 close(fd); /* close fd if it was opened */
434 } /*CheckAdminName */
440 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
441 /* set our 'thread-id' so that the host hold table works */
442 pthread_setspecific(rx_thread_id_key,
443 (void *)(intptr_t)rx_NewThreadId());
445 ("Set thread id %p for '%s'\n",
446 pthread_getspecific(rx_thread_id_key), s));
450 /* This LWP does things roughly every 5 minutes */
452 FiveMinuteCheckLWP(void *unused)
457 ViceLog(1, ("Starting five minute check process\n"));
458 setThreadId("FiveMinuteCheckLWP");
460 #ifdef AFS_DEMAND_ATTACH_FS
462 while (fs_state.mode == FS_MODE_NORMAL) {
463 fs_state.FiveMinuteLWP_tranquil = 1;
469 #ifdef AFS_PTHREAD_ENV
471 #else /* AFS_PTHREAD_ENV */
472 IOMGR_Sleep(fiveminutes);
473 #endif /* AFS_PTHREAD_ENV */
475 #ifdef AFS_DEMAND_ATTACH_FS
477 if (fs_state.mode != FS_MODE_NORMAL) {
480 fs_state.FiveMinuteLWP_tranquil = 0;
484 /* close the log so it can be removed */
485 ReOpenLog(AFSDIR_SERVER_FILELOG_FILEPATH); /* don't trunc, just append */
486 ViceLog(2, ("Cleaning up timed out callbacks\n"));
487 if (CleanupTimedOutCallBacks())
488 ViceLog(5, ("Timed out callbacks deleted\n"));
489 ViceLog(2, ("Set disk usage statistics\n"));
491 if (FS_registered == 1)
493 /* Force wakeup in case we missed something; pthreads does timedwait */
494 #ifndef AFS_PTHREAD_ENV
495 LWP_NoYieldSignal(fsync_wait);
497 if (printBanner && (++msg & 1)) { /* Every 10 minutes */
498 time_t now = FT_ApproxTime();
500 ("File server is running at %s\n",
501 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 CV_BROADCAST(&fs_state.worker_done_cv);
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 CV_BROADCAST(&fs_state.worker_done_cv);
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;
598 code = CV_TIMEDWAIT(&fsync_cond, &fsync_glock_mutex,
600 if (code != 0 && code != ETIMEDOUT)
601 ViceLog(0, ("pthread_cond_timedwait returned %d\n", code));
602 #else /* AFS_PTHREAD_ENV */
603 if ((code = LWP_WaitProcess(fsync_wait)) != LWP_SUCCESS)
604 ViceLog(0, ("LWP_WaitProcess returned %d\n", code));
605 #endif /* AFS_PTHREAD_ENV */
608 #ifdef AFS_DEMAND_ATTACH_FS
610 if (fs_state.mode != FS_MODE_NORMAL) {
613 fs_state.FsyncCheckLWP_tranquil = 0;
615 #endif /* AFS_DEMAND_ATTACH_FS */
617 ViceLog(2, ("Checking for fsync events\n"));
619 code = BreakLaterCallBacks();
621 #ifdef AFS_DEMAND_ATTACH_FS
625 #ifdef AFS_DEMAND_ATTACH_FS
626 fs_state.FsyncCheckLWP_tranquil = 1;
628 CV_BROADCAST(&fs_state.worker_done_cv);
631 #endif /* AFS_DEMAND_ATTACH_FS */
635 /*------------------------------------------------------------------------
636 * PRIVATE ClearXStatValues
639 * Initialize all of the values collected via the xstat
649 * Must be called during File Server initialization.
653 *------------------------------------------------------------------------*/
656 ClearXStatValues(void)
657 { /*ClearXStatValues */
659 struct fs_stats_opTimingData *opTimeP; /*Ptr to timing struct */
660 struct fs_stats_xferData *opXferP; /*Ptr to xfer struct */
661 int i; /*Loop counter */
664 * Zero all xstat-related structures.
666 memset((&afs_perfstats), 0, sizeof(struct afs_PerfStats));
667 #if FS_STATS_DETAILED
668 memset((&afs_FullPerfStats), 0,
669 sizeof(struct fs_stats_FullPerfStats));
672 * That's not enough. We have to set reasonable minima for
673 * time and xfer values in the detailed stats.
675 opTimeP = &(afs_FullPerfStats.det.rpcOpTimes[0]);
676 for (i = 0; i < FS_STATS_NUM_RPC_OPS; i++, opTimeP++)
677 opTimeP->minTime.tv_sec = 999999;
679 opXferP = &(afs_FullPerfStats.det.xferOpTimes[0]);
680 for (i = 0; i < FS_STATS_NUM_XFER_OPS; i++, opXferP++) {
681 opXferP->minTime.tv_sec = 999999;
682 opXferP->minBytes = 999999999;
686 * There's more. We have to set our unique system identifier, as
687 * declared in param.h. If such a thing is not defined, we bitch
688 * and declare ourselves to be an unknown system type.
691 afs_perfstats.sysname_ID = SYS_NAME_ID;
694 ViceLog(0, ("Sys name ID constant not defined in param.h!!\n"));
695 ViceLog(0, ("[Choosing ``undefined'' sys name ID.\n"));
697 afs_perfstats.sysname_ID = SYS_NAME_ID_UNDEFINED;
698 #endif /* SYS_NAME_ID */
701 } /*ClearXStatValues */
703 int CopyOnWrite_calls = 0, CopyOnWrite_off0 = 0, CopyOnWrite_size0 = 0;
704 afs_fsize_t CopyOnWrite_maxsize = 0;
709 int dirbuff, dircall, dirio;
711 int workstations, activeworkstations, delworkstations;
714 #ifdef AFS_DEMAND_ATTACH_FS
718 FT_GetTimeOfDay(&tpl, 0);
721 ("Vice was last started at %s\n",
722 afs_ctime(&StartTime, tbuffer, sizeof(tbuffer))));
724 #ifdef AFS_DEMAND_ATTACH_FS
725 if (LogLevel >= 125) {
726 stats_flags = VOL_STATS_PER_CHAIN2;
727 } else if (LogLevel >= 25) {
728 stats_flags = VOL_STATS_PER_CHAIN;
730 VPrintExtendedCacheStats(stats_flags);
734 DStat(&dirbuff, &dircall, &dirio);
736 ("With %d directory buffers; %d reads resulted in %d read I/Os\n",
737 dirbuff, dircall, dirio));
738 rx_PrintStats(stderr);
739 audit_PrintStats(stderr);
741 PrintCallBackStats();
743 processSize = -1; /* TODO: */
745 processSize = (int)((long)sbrk(0) >> 10);
748 ("There are %d connections, process size %d\n",
749 CurrentConnections, processSize));
750 h_GetWorkStats(&workstations, &activeworkstations, &delworkstations,
751 tpl.tv_sec - 15 * 60);
753 ("There are %d workstations, %d are active (req in < 15 mins), %d marked \"down\"\n",
754 workstations, activeworkstations, delworkstations));
755 ViceLog(0, ("CopyOnWrite: calls %d off0 %d size0 %d maxsize 0x%llx\n",
756 CopyOnWrite_calls, CopyOnWrite_off0, CopyOnWrite_size0, CopyOnWrite_maxsize));
765 CheckSignal(void *unused)
767 if (FS_registered > 0) {
769 * We have proper ip addresses; tell the vlserver what we got; the following
770 * routine will do the proper reporting for us
783 ShutdownWatchdogLWP(void *unused)
785 sleep(panic_timeout);
786 ViceLog(0, ("ShutdownWatchdogLWP: Failed to shutdown and panic "
787 "within %d seconds; forcing panic\n", panic_timeout));
788 osi_Panic("ShutdownWatchdogLWP: Failed to shutdown and panic "
789 "within %d seconds; forcing panic\n", panic_timeout);
794 ShutDownAndCore(int dopanic)
796 time_t now = time(0);
800 #ifdef AFS_PTHREAD_ENV
801 pthread_t watchdogPid;
802 pthread_attr_t tattr;
803 osi_Assert(pthread_attr_init(&tattr) == 0);
804 osi_Assert(pthread_create(&watchdogPid, &tattr, ShutdownWatchdogLWP, NULL) == 0);
807 osi_Assert(LWP_CreateProcess
808 (ShutdownWatchdogLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
809 NULL, "ShutdownWatchdog", &watchdogPid) == LWP_SUCCESS);
813 /* do not allows new reqests to be served from now on, all new requests
814 * are returned with an error code of RX_RESTARTING ( transient failure ) */
815 rx_SetRxTranquil(); /* dhruba */
819 #ifdef AFS_DEMAND_ATTACH_FS
821 if (fs_state.mode == FS_MODE_SHUTDOWN) {
822 /* it is possible for at least fs_stateSave() (called below) to call
823 * ShutDownAndCore if there's host list corruption; prevent
824 * deinitializing some stuff twice */
825 ViceLog(0, ("ShutDownAndCore called during shutdown? Skipping volume "
826 "and host package shutdown\n"));
830 fs_state.mode = FS_MODE_SHUTDOWN;
835 ("Shutting down file server at %s",
836 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
838 ViceLog(0, ("ABNORMAL SHUTDOWN, see core file.\n"));
843 /* shut down volume package */
846 #ifdef AFS_DEMAND_ATTACH_FS
847 if (fs_state.options.fs_state_save) {
850 * save fileserver state to disk */
853 ViceLog(0, ("Not saving fileserver state; abnormal shutdown\n"));
856 /* make sure background threads have finished all of their asynchronous
857 * work on host and callback structures */
859 while (!fs_state.FiveMinuteLWP_tranquil ||
860 !fs_state.HostCheckLWP_tranquil ||
861 !fs_state.FsyncCheckLWP_tranquil) {
864 ViceLog(0, ("waiting for background host/callback threads to quiesce before saving fileserver state...\n"));
865 CV_WAIT(&fs_state.worker_done_cv, &fileproc_glock_mutex);
871 /* ok. it should now be fairly safe. let's do the state dump */
877 #endif /* AFS_DEMAND_ATTACH_FS */
880 rx_PrintStats(debugFile);
886 ("File server has terminated abnormally at %s\n",
887 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
890 ("File server has terminated normally at %s\n",
891 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
894 if (dopanic) /* XXX pass in file and line? */
895 osi_Panic("Panic requested\n");
901 ShutDown(void *unused)
902 { /* backward compatibility */
903 ShutDownAndCore(DONTPANIC);
911 /* default supports help flag */
913 fputs("Usage: fileserver ", stdout);
914 fputs("[-auditlog <log path>] ", stdout);
915 fputs("[-audit-interface <file|sysvmq> (default is file)] ", stdout);
916 fputs("[-d <debug level>] ", stdout);
917 fputs("[-p <number of processes>] ", stdout);
918 fputs("[-spare <number of spare blocks>] ", stdout);
919 fputs("[-pctspare <percentage spare>] ", stdout);
920 fputs("[-b <buffers>] ", stdout);
921 fputs("[-l <large vnodes>] ", stdout);
922 fputs("[-s <small vnodes>] ", stdout);
923 fputs("[-vc <volume cachesize>] ", stdout);
924 fputs("[-w <call back wait interval>] ", stdout);
925 fputs("[-cb <number of call backs>] ", stdout);
926 fputs("[-banner (print banner every 10 minutes)] ", stdout);
927 fputs("[-novbc (whole volume cbs disabled)] ", stdout);
928 fputs("[-implicit <admin mode bits: rlidwka>] ", stdout);
929 fputs("[-readonly (read-only file server)] ", stdout);
930 fputs("[-hr <number of hours between refreshing the host cps>] ", stdout);
931 fputs("[-busyat <redirect clients when queue > n>] ", stdout);
932 fputs("[-nobusy <no VBUSY before a volume is attached>] ", stdout);
933 fputs("[-rxpck <number of rx extra packets>] ", stdout);
934 fputs("[-rxdbg (enable rx debugging)] ", stdout);
935 fputs("[-rxdbge (enable rxevent debugging)] ", stdout);
936 fputs("[-rxmaxmtu <bytes>] ", stdout);
937 fputs("[-rxbind (bind the Rx socket to one address)] ", stdout);
938 fputs("[-allow-dotted-principals (disable the rxkad principal name dot check)] ", stdout);
939 fputs("[-vhandle-setaside (fds reserved for non-cache io [default 128])] ", stdout);
940 fputs("[-vhandle-max-cachesize (max open files [default 128])] ", stdout);
941 fputs("[-vhandle-initial-cachesize (fds reserved for cache io [default 128])] ", stdout);
942 #ifdef AFS_DEMAND_ATTACH_FS
943 fputs("[-fs-state-dont-save (disable state save during shutdown)] ", stdout);
944 fputs("[-fs-state-dont-restore (disable state restore during startup)] ", stdout);
945 fputs("[-fs-state-verify <none|save|restore|both> (default is both)] ", stdout);
946 fputs("[-vattachpar <max number of volume attach/shutdown threads> (default is 1)] ", stdout);
947 fputs("[-vhashsize <log(2) of number of volume hash buckets> (default is 8)] ", stdout);
948 fputs("[-vlrudisable (disable VLRU functionality)] ", stdout);
949 fputs("[-vlruthresh <minutes before unused volumes become eligible for soft detach> (default is 2 hours)] ", stdout);
950 fputs("[-vlruinterval <seconds between VLRU scans> (default is 2 minutes)] ", stdout);
951 fputs("[-vlrumax <max volumes to soft detach in one VLRU scan> (default is 8)] ", stdout);
952 fputs("[-unsafe-nosalvage (bypass volume inUse safety check on attach, bypassing salvage)] ", stdout);
953 #elif AFS_PTHREAD_ENV
954 fputs("[-vattachpar <number of volume attach threads> (default is 1)] ", stdout);
957 fputs("[-m <min percentage spare in partition>] ", stdout);
959 #if defined(AFS_SGI_ENV)
960 fputs("[-lock (keep fileserver from swapping)] ", stdout);
962 fputs("[-L (large server conf)] ", stdout);
963 fputs("[-S (small server conf)] ", stdout);
964 fputs("[-k <stack size>] ", stdout);
965 fputs("[-realm <Kerberos realm name>] ", stdout);
966 fputs("[-udpsize <size of socket buffer in bytes>] ", stdout);
967 fputs("[-sendsize <size of send buffer in bytes>] ", stdout);
968 fputs("[-abortthreshold <abort threshold>] ", stdout);
969 fputs("[-nojumbo (disable jumbogram network packets - deprecated)] ", stdout);
970 fputs("[-jumbo (enable jumbogram network packets)] ", stdout);
971 fputs("[-offline-timeout <client RX timeout for offlining volumes>]", stdout);
972 fputs("[-offline-shutdown-timeout <RX timeout for offlining volumes during shutdown>]", stdout);
973 /* fputs("[-enable_peer_stats] ", stdout); */
974 /* fputs("[-enable_process_stats] ", stdout); */
975 fputs("[-help]\n", stdout);
977 ViceLog(0, ("%s", buffer));
986 ParseRights(char *arights)
992 if (!arights || !strcmp(arights, "")) {
993 printf("Missing list of mode bits on -implicit option\n");
996 if (!strcmp(arights, "none"))
998 else if (!strcmp(arights, "read"))
999 mode = PRSFS_READ | PRSFS_LOOKUP;
1000 else if (!strcmp(arights, "write"))
1002 PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
1003 PRSFS_WRITE | PRSFS_LOCK;
1004 else if (!strcmp(arights, "all"))
1006 PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
1007 PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER;
1009 len = strlen(arights);
1010 for (i = 0; i < len; i++) {
1015 mode |= PRSFS_LOOKUP;
1017 mode |= PRSFS_INSERT;
1019 mode |= PRSFS_DELETE;
1021 mode |= PRSFS_WRITE;
1025 mode |= PRSFS_ADMINISTER;
1043 printf("Illegal -implicit rights character '%c'.\n", tc);
1052 * Limit MAX_FILESERVER_THREAD by the system limit on the number of
1053 * pthreads (sysconf(_SC_THREAD_THREADS_MAX)), if applicable and
1056 * AIX: sysconf() limit is real
1057 * HP-UX: sysconf() limit is real
1058 * IRIX: sysconf() limit is apparently NOT real -- too small
1059 * DUX: sysconf() limit is apparently NOT real -- too big
1060 * Linux: sysconf() limit is apparently NOT real -- too big
1061 * Solaris: no sysconf() limit
1064 max_fileserver_thread(void)
1066 #if defined(AFS_PTHREAD_ENV)
1067 #if defined(AFS_AIX_ENV) || defined(AFS_HPUX_ENV)
1070 ans = sysconf(_SC_THREAD_THREADS_MAX);
1071 if (0 < ans && ans < MAX_FILESERVER_THREAD)
1074 #endif /* defined(AFS_PTHREAD_ENV) */
1075 return MAX_FILESERVER_THREAD;
1078 /* from ihandle.c */
1079 extern ih_init_params vol_io_params;
1082 ParseArgs(int argc, char *argv[])
1084 int SawL = 0, SawS = 0, SawVC = 0;
1085 int Sawrxpck = 0, Sawsmall = 0, Sawlarge = 0, Sawcbs = 0, Sawlwps =
1089 int bufSize = 0; /* temp variable to read in udp socket buf size */
1090 char *auditFileName = NULL;
1092 for (i = 1; i < argc; i++) {
1093 if (!strcmp(argv[i], "-d")) {
1094 if ((i + 1) >= argc) {
1095 fprintf(stderr, "missing argument for -d\n");
1098 debuglevel = atoi(argv[++i]);
1099 LogLevel = debuglevel;
1100 } else if (!strcmp(argv[i], "-banner")) {
1102 } else if (!strcmp(argv[i], "-implicit")) {
1103 if ((i + 1) >= argc) {
1104 fprintf(stderr, "missing argument for -implicit\n");
1107 implicitAdminRights = ParseRights(argv[++i]);
1108 if (implicitAdminRights < 0)
1109 return implicitAdminRights;
1110 } else if (!strcmp(argv[i], "-readonly")) {
1112 } else if (!strcmp(argv[i], "-L")) {
1114 } else if (!strcmp(argv[i], "-S")) {
1116 } else if (!strcmp(argv[i], "-p")) {
1118 max_fileserver_thread() - FILESERVER_HELPER_THREADS;
1120 if ((i + 1) >= argc) {
1121 fprintf(stderr, "missing argument for -p\n");
1124 lwps = atoi(argv[++i]);
1125 if (lwps > lwps_max)
1129 } else if (!strcmp(argv[i], "-b")) {
1131 if ((i + 1) >= argc) {
1132 fprintf(stderr, "missing argument for -b\n");
1135 buffs = atoi(argv[++i]);
1136 } else if (!strcmp(argv[i], "-l")) {
1138 if ((i + 1) >= argc) {
1139 fprintf(stderr, "missing argument for -l\n");
1142 large = atoi(argv[++i]);
1143 } else if (!strcmp(argv[i], "-vc")) {
1145 if ((i + 1) >= argc) {
1146 fprintf(stderr, "missing argument for -vc\n");
1149 volcache = atoi(argv[++i]);
1150 } else if (!strcmp(argv[i], "-novbc")) {
1152 } else if (!strcmp(argv[i], "-rxpck")) {
1154 if ((i + 1) >= argc) {
1155 fprintf(stderr, "missing argument for -rxpck\n");
1158 rxpackets = atoi(argv[++i]);
1159 #ifdef AFS_PTHREAD_ENV
1160 } else if (!strcmp(argv[i], "-vattachpar")) {
1161 if ((i + 1) >= argc) {
1162 fprintf(stderr, "missing argument for %s\n", argv[i]);
1165 vol_attach_threads = atoi(argv[++i]);
1166 #endif /* AFS_PTHREAD_ENV */
1167 } else if (!strcmp(argv[i], "-vhandle-setaside")) {
1168 if ((i + 1) >= argc) {
1169 fprintf(stderr, "missing argument for %s\n", argv[i]);
1172 vol_io_params.fd_handle_setaside = atoi(argv[++i]);
1173 } else if (!strcmp(argv[i], "-vhandle-max-cachesize")) {
1174 if ((i + 1) >= argc) {
1175 fprintf(stderr, "missing argument for %s\n", argv[i]);
1178 vol_io_params.fd_max_cachesize = atoi(argv[++i]);
1179 } else if (!strcmp(argv[i], "-vhandle-initial-cachesize")) {
1180 if ((i + 1) >= argc) {
1181 fprintf(stderr, "missing argument for %s\n", argv[i]);
1184 vol_io_params.fd_initial_cachesize = atoi(argv[++i]);
1185 #ifdef AFS_DEMAND_ATTACH_FS
1186 } else if (!strcmp(argv[i], "-fs-state-dont-save")) {
1187 fs_state.options.fs_state_save = 0;
1188 } else if (!strcmp(argv[i], "-fs-state-dont-restore")) {
1189 fs_state.options.fs_state_restore = 0;
1190 } else if (!strcmp(argv[i], "-fs-state-verify")) {
1191 if ((i + 1) >= argc) {
1192 fprintf(stderr, "missing argument for %s\n", argv[i]);
1196 if (!strcmp(argv[i], "none")) {
1197 fs_state.options.fs_state_verify_before_save = 0;
1198 fs_state.options.fs_state_verify_after_restore = 0;
1199 } else if (!strcmp(argv[i], "save")) {
1200 fs_state.options.fs_state_verify_after_restore = 0;
1201 } else if (!strcmp(argv[i], "restore")) {
1202 fs_state.options.fs_state_verify_before_save = 0;
1203 } else if (!strcmp(argv[i], "both")) {
1206 fprintf(stderr, "invalid argument for %s\n", argv[i-1]);
1209 } else if (!strcmp(argv[i], "-vhashsize")) {
1211 if ((i + 1) >= argc) {
1212 fprintf(stderr, "missing argument for %s\n", argv[i]);
1215 hashsize = atoi(argv[++i]);
1216 if (VSetVolHashSize(hashsize)) {
1217 fprintf(stderr, "specified -vhashsize (%s) is invalid or out "
1218 "of range\n", argv[i]);
1221 } else if (!strcmp(argv[i], "-vlrudisable")) {
1222 VLRU_SetOptions(VLRU_SET_ENABLED, 0);
1223 } else if (!strcmp(argv[i], "-vlruthresh")) {
1224 if ((i + 1) >= argc) {
1225 fprintf(stderr, "missing argument for %s\n", argv[i]);
1228 VLRU_SetOptions(VLRU_SET_THRESH, 60*atoi(argv[++i]));
1229 } else if (!strcmp(argv[i], "-vlruinterval")) {
1230 if ((i + 1) >= argc) {
1231 fprintf(stderr, "missing argument for %s\n", argv[i]);
1234 VLRU_SetOptions(VLRU_SET_INTERVAL, atoi(argv[++i]));
1235 } else if (!strcmp(argv[i], "-vlrumax")) {
1236 if ((i + 1) >= argc) {
1237 fprintf(stderr, "missing argument for %s\n", argv[i]);
1240 VLRU_SetOptions(VLRU_SET_MAX, atoi(argv[++i]));
1241 } else if (!strcmp(argv[i], "-unsafe-nosalvage")) {
1243 #endif /* AFS_DEMAND_ATTACH_FS */
1244 } else if (!strcmp(argv[i], "-s")) {
1246 if ((i + 1) >= argc) {
1247 fprintf(stderr, "missing argument for -s\n");
1250 nSmallVns = atoi(argv[++i]);
1251 } else if (!strcmp(argv[i], "-abortthreshold")) {
1252 if ((i + 1) >= argc) {
1253 fprintf(stderr, "missing argument for -abortthreshold\n");
1256 abort_threshold = atoi(argv[++i]);
1257 } else if (!strcmp(argv[i], "-k")) {
1258 if ((i + 1) >= argc) {
1259 fprintf(stderr, "missing argument for -k\n");
1262 stack = atoi(argv[++i]);
1264 #if defined(AFS_SGI_ENV)
1265 else if (!strcmp(argv[i], "-lock")) {
1269 else if (!strcmp(argv[i], "-spare")) {
1270 if ((i + 1) >= argc) {
1271 fprintf(stderr, "missing argument for -spare\n");
1274 BlocksSpare = atoi(argv[++i]);
1276 } else if (!strcmp(argv[i], "-pctspare")) {
1277 if ((i + 1) >= argc) {
1278 fprintf(stderr, "missing argument for -pctspare\n");
1281 PctSpare = atoi(argv[++i]);
1282 BlocksSpare = 0; /* has non-zero default */
1284 } else if (!strcmp(argv[i], "-w")) {
1285 if ((i + 1) >= argc) {
1286 fprintf(stderr, "missing argument for -w\n");
1289 fiveminutes = atoi(argv[++i]);
1290 } else if (!strcmp(argv[i], "-hr")) {
1292 if ((i + 1) >= argc) {
1293 fprintf(stderr, "missing argument for -hr\n");
1296 hr = atoi(argv[++i]);
1297 if ((hr < 1) || (hr > 36)) {
1299 ("host acl refresh interval of %d hours is invalid; hours must be between 1 and 36\n\n",
1303 hostaclRefresh = hr * 60 * 60;
1304 } else if (!strcmp(argv[i], "-rxdbg"))
1306 else if (!strcmp(argv[i], "-rxdbge"))
1308 else if (!strcmp(argv[i], "-cb")) {
1310 if ((i + 1) >= argc) {
1311 fprintf(stderr, "missing argument for -cb\n");
1314 numberofcbs = atoi(argv[++i]);
1315 if ((numberofcbs < 10000) || (numberofcbs > 2147483647)) {
1317 ("number of cbs %d invalid; must be between 10000 and 2147483647\n",
1321 } else if (!strcmp(argv[i], "-busyat")) {
1323 if ((i + 1) >= argc) {
1324 fprintf(stderr, "missing argument for -busyat\n");
1327 busy_threshold = atoi(argv[++i]);
1328 if (busy_threshold < 10) {
1330 ("Busy threshold %d is too low, will compute default.\n",
1334 } else if (!strcmp(argv[i], "-nobusy"))
1336 #ifdef AFS_AIX32_ENV
1337 else if (!strcmp(argv[i], "-m")) {
1338 extern int aixlow_water;
1339 if ((i + 1) >= argc) {
1340 fprintf(stderr, "missing argument for -m\n");
1343 aixlow_water = atoi(argv[++i]);
1344 if ((aixlow_water < 0) || (aixlow_water > 30)) {
1345 printf("space reserved %d% invalid; must be between 0-30%\n",
1351 else if (!strcmp(argv[i], "-nojumbo")) {
1353 } else if (!strcmp(argv[i], "-jumbo")) {
1355 } else if (!strcmp(argv[i], "-rxbind")) {
1357 } else if (!strcmp(argv[i], "-allow-dotted-principals")) {
1358 rxkadDisableDotCheck = 1;
1359 } else if (!strcmp(argv[i], "-rxmaxmtu")) {
1360 if ((i + 1) >= argc) {
1361 fprintf(stderr, "missing argument for -rxmaxmtu\n");
1364 rxMaxMTU = atoi(argv[++i]);
1365 if ((rxMaxMTU < RX_MIN_PACKET_SIZE) ||
1366 (rxMaxMTU > RX_MAX_PACKET_DATA_SIZE)) {
1367 printf("rxMaxMTU %d%% invalid; must be between %d-%" AFS_SIZET_FMT "\n",
1368 rxMaxMTU, RX_MIN_PACKET_SIZE,
1369 RX_MAX_PACKET_DATA_SIZE);
1372 } else if (!strcmp(argv[i], "-realm")) {
1373 extern char local_realms[AFS_NUM_LREALMS][AFS_REALM_SZ];
1374 extern int num_lrealms;
1375 if ((i + 1) >= argc) {
1376 fprintf(stderr, "missing argument for -realm\n");
1379 if (strlen(argv[++i]) >= AFS_REALM_SZ) {
1381 ("-realm argument must contain fewer than %d characters.\n",
1385 if (num_lrealms == -1)
1387 if (num_lrealms >= AFS_NUM_LREALMS) {
1389 ("a maximum of %d -realm arguments can be specified.\n",
1393 strncpy(local_realms[num_lrealms++], argv[i], AFS_REALM_SZ);
1394 } else if (!strcmp(argv[i], "-udpsize")) {
1395 if ((i + 1) >= argc) {
1396 printf("You have to specify -udpsize <integer value>\n");
1399 bufSize = atoi(argv[++i]);
1400 if (bufSize < rx_GetMinUdpBufSize())
1402 ("Warning:udpsize %d is less than minimum %d; ignoring\n",
1403 bufSize, rx_GetMinUdpBufSize());
1405 udpBufSize = bufSize;
1406 } else if (!strcmp(argv[i], "-sendsize")) {
1407 if ((i + 1) >= argc) {
1408 printf("You have to specify -sendsize <integer value>\n");
1411 bufSize = atoi(argv[++i]);
1412 if (bufSize < 16384)
1414 ("Warning:sendsize %d is less than minimum %d; ignoring\n",
1417 sendBufSize = bufSize;
1418 } else if (!strcmp(argv[i], "-enable_peer_stats")) {
1419 rx_enablePeerRPCStats();
1420 } else if (!strcmp(argv[i], "-enable_process_stats")) {
1421 rx_enableProcessRPCStats();
1423 else if (strcmp(argv[i], "-auditlog") == 0) {
1424 auditFileName = argv[++i];
1426 else if (strcmp(argv[i], "-audit-interface") == 0) {
1427 char *interface = argv[++i];
1429 if (osi_audit_interface(interface)) {
1430 printf("Invalid audit interface '%s'\n", interface);
1434 #ifndef AFS_NT40_ENV
1435 else if (strcmp(argv[i], "-syslog") == 0) {
1436 /* set syslog logging flag */
1437 serverLogSyslog = 1;
1438 } else if (strncmp(argv[i], "-syslog=", 8) == 0) {
1439 serverLogSyslog = 1;
1440 serverLogSyslogFacility = atoi(argv[i] + 8);
1443 else if (strcmp(argv[i], "-mrafslogs") == 0) {
1444 /* set syslog logging flag */
1447 else if (strcmp(argv[i], "-saneacls") == 0) {
1450 else if (strcmp(argv[i], "-offline-timeout") == 0) {
1451 if (i + 1 >= argc) {
1452 printf("You have to specify -offline-timeout <integer>\n");
1455 offline_timeout = atoi(argv[++i]);
1456 #ifndef AFS_PTHREAD_ENV
1457 if (offline_timeout != -1) {
1458 printf("The only valid -offline-timeout value for the LWP "
1459 "fileserver is -1\n");
1462 #endif /* AFS_PTHREAD_ENV */
1463 if (offline_timeout < -1) {
1464 printf("Invalid -offline-timeout value %s; the only valid "
1465 "negative value is -1\n", argv[i]);
1469 else if (strcmp(argv[i], "-offline-shutdown-timeout") == 0) {
1470 if (i + 1 >= argc) {
1471 printf("You have to specify -offline-shutdown-timeout "
1475 offline_shutdown_timeout = atoi(argv[++i]);
1476 #ifndef AFS_PTHREAD_ENV
1477 if (offline_shutdown_timeout != -1) {
1478 printf("The only valid -offline-shutdown-timeout value for the "
1479 "LWP fileserver is -1\n");
1482 #endif /* AFS_PTHREAD_ENV */
1483 if (offline_shutdown_timeout < -1) {
1484 printf("Invalid -offline-timeout value %s; the only valid "
1485 "negative value is -1\n", argv[i]);
1494 printf("Only one of -L, or -S must be specified\n");
1505 numberofcbs = 20000;
1521 numberofcbs = 64000;
1530 busy_threshold = 3 * rxpackets / 2;
1532 osi_audit_file(auditFileName);
1542 NewParms(int initializing)
1544 static struct afs_stat sbuf;
1547 char *argv[MAXPARMS];
1550 if (!(afs_stat("/vice/file/parms", &sbuf))) {
1551 parms = (char *)malloc(sbuf.st_size);
1554 fd = afs_open("parms", O_RDONLY, 0666);
1556 ViceLog(0, ("Open for parms failed with errno = %d\n", errno));
1560 i = read(fd, parms, sbuf.st_size);
1562 if (i != sbuf.st_size) {
1564 ViceLog(0, ("Read on parms failed with errno = %d\n", errno));
1567 ("Read on parms failed; expected %ld bytes but read %d\n",
1568 (long) sbuf.st_size, i));
1574 for (i = 0; i < MAXPARMS; argv[i++] = 0);
1576 for (argc = i = 0; i < sbuf.st_size; i++) {
1577 if ((*(parms + i) != ' ') && (*(parms + i) != '\n')) {
1578 if (argv[argc] == 0)
1579 argv[argc] = (parms + i);
1581 *(parms + i) = '\0';
1582 if (argv[argc] != 0) {
1583 if (++argc == MAXPARMS)
1586 while ((*(parms + i + 1) == ' ')
1587 || (*(parms + i + 1) == '\n'))
1591 if (ParseArgs(argc, argv) == 0) {
1592 ViceLog(0, ("Change parameters to:"));
1594 ViceLog(0, ("Invalid parameter in:"));
1596 for (i = 0; i < argc; i++) {
1597 ViceLog(0, (" %s", argv[i]));
1601 } else if (!initializing)
1603 ("Received request to change parms but no parms file exists\n"));
1608 /* Miscellaneous routines */
1612 ViceLog(0, ("%s\n", msg));
1613 osi_Panic("%s\n", msg);
1624 * If this fails, it's because something major is wrong, and is not
1625 * likely to be time dependent.
1627 code = pr_Initialize(2, AFSDIR_SERVER_ETC_DIRPATH, 0);
1630 ("Couldn't initialize protection library; code=%d.\n", code));
1634 #ifdef AFS_PTHREAD_ENV
1635 osi_Assert(pthread_key_create(&viced_uclient_key, NULL) == 0);
1638 SystemId = SYSADMINID;
1639 SystemAnyUser = ANYUSERID;
1640 SystemAnyUserCPS.prlist_len = 0;
1641 SystemAnyUserCPS.prlist_val = NULL;
1642 AnonCPS.prlist_len = 0;
1643 AnonCPS.prlist_val = NULL;
1645 code = pr_GetCPS(SystemAnyUser, &SystemAnyUserCPS);
1648 ("Couldn't get CPS for AnyUser, will try again in 30 seconds; code=%d.\n",
1652 code = pr_GetCPS(ANONYMOUSID, &AnonCPS);
1655 ("Couldn't get Anonymous CPS, exiting; code=%d.\n",
1659 AnonymousID = ANONYMOUSID;
1662 #ifdef AFS_PTHREAD_ENV
1664 #else /* AFS_PTHREAD_ENV */
1666 #endif /* AFS_PTHREAD_ENV */
1670 struct rx_connection *serverconns[MAXSERVERS];
1671 struct ubik_client *cstruct;
1674 vl_Initialize(const char *confDir)
1677 afs_int32 scIndex = RX_SECIDX_NULL;
1678 struct afsconf_dir *tdir;
1679 struct rx_securityClass *sc;
1680 struct afsconf_cell info;
1682 tdir = afsconf_Open(confDir);
1685 ("Could not open configuration directory (%s).\n", confDir));
1688 code = afsconf_ClientAuth(tdir, &sc, &scIndex);
1690 ViceLog(0, ("Could not get security object for localAuth\n"));
1693 code = afsconf_GetCellInfo(tdir, NULL, AFSCONF_VLDBSERVICE, &info);
1694 if (info.numServers > MAXSERVERS) {
1696 ("vl_Initialize: info.numServers=%d (> MAXSERVERS=%d)\n",
1697 info.numServers, MAXSERVERS));
1700 for (i = 0; i < info.numServers; i++)
1702 rx_NewConnection(info.hostAddr[i].sin_addr.s_addr,
1703 info.hostAddr[i].sin_port, USER_SERVICE_ID, sc,
1705 code = ubik_ClientInit(serverconns, &cstruct);
1706 afsconf_Close(tdir);
1708 ViceLog(0, ("vl_Initialize: ubik client init failed.\n"));
1714 #define SYSIDMAGIC 0x88aabbcc
1715 #define SYSIDVERSION 1
1720 afs_int32 fd, nentries, i;
1721 struct versionStamp vsn;
1722 struct afs_stat status;
1725 if ((afs_stat(AFSDIR_SERVER_SYSID_FILEPATH, &status))
1726 || (status.st_size <= 0)) {
1727 ViceLog(0, ("%s: doesn't exist\n", AFSDIR_SERVER_SYSID_FILEPATH));
1730 if (!(fd = afs_open(AFSDIR_SERVER_SYSID_FILEPATH, O_RDONLY, 0))) {
1732 ("%s: can't open (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1736 if ((i = read(fd, (char *)&vsn, sizeof(vsn))) != sizeof(vsn)) {
1738 ("%s: Read failed (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1742 if (vsn.magic != SYSIDMAGIC) {
1744 ("%s: wrong magic %x (we support %x)\n",
1745 AFSDIR_SERVER_SYSID_FILEPATH, vsn.magic, SYSIDMAGIC));
1748 if (vsn.version != SYSIDVERSION) {
1750 ("%s: wrong version %d (we support %d)\n",
1751 AFSDIR_SERVER_SYSID_FILEPATH, vsn.version, SYSIDVERSION));
1755 read(fd, (char *)&uuid,
1756 sizeof(struct afsUUID))) != sizeof(struct afsUUID)) {
1758 ("%s: read of uuid failed (%d)\n",
1759 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1762 afs_ntohuuid(&uuid);
1765 read(fd, (char *)&nentries,
1766 sizeof(afs_int32))) != sizeof(afs_int32)) {
1768 ("%s: Read of entries failed (%d)\n",
1769 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1772 if (nentries <= 0 || nentries > ADDRSPERSITE) {
1774 ("%s: invalid num of interfaces: %d\n",
1775 AFSDIR_SERVER_SYSID_FILEPATH, nentries));
1778 if (FS_HostAddr_cnt == 0) {
1779 FS_HostAddr_cnt = nentries;
1780 for (i = 0; i < nentries; i++) {
1781 if (read(fd, (char *)&FS_HostAddrs[i], sizeof(afs_int32)) !=
1782 sizeof(afs_int32)) {
1784 ("%s: Read of addresses failed (%d)\n",
1785 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1786 FS_HostAddr_cnt = 0; /* reset it */
1792 ("%s: address list ignored (NetInfo/NetRestrict override)\n",
1793 AFSDIR_SERVER_SYSID_FILEPATH));
1800 WriteSysIdFile(void)
1803 struct versionStamp vsn;
1804 struct afs_stat status;
1807 if (!afs_stat(AFSDIR_SERVER_SYSID_FILEPATH, &status)) {
1809 * File exists; keep the old one around
1811 renamefile(AFSDIR_SERVER_SYSID_FILEPATH,
1812 AFSDIR_SERVER_OLDSYSID_FILEPATH);
1814 fd = afs_open(AFSDIR_SERVER_SYSID_FILEPATH, O_WRONLY | O_TRUNC | O_CREAT,
1818 ("%s: can't create (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1822 vsn.magic = SYSIDMAGIC;
1824 if ((i = write(fd, (char *)&vsn, sizeof(vsn))) != sizeof(vsn)) {
1826 ("%s: write failed (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1831 afs_htonuuid(&uuid);
1833 write(fd, (char *)&uuid,
1834 sizeof(struct afsUUID))) != sizeof(struct afsUUID)) {
1836 ("%s: write of uuid failed (%d)\n",
1837 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1841 write(fd, (char *)&FS_HostAddr_cnt,
1842 sizeof(afs_int32))) != sizeof(afs_int32)) {
1844 ("%s: write of # of entries failed (%d)\n",
1845 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1848 for (i = 0; i < FS_HostAddr_cnt; i++) {
1849 if (write(fd, (char *)&FS_HostAddrs[i], sizeof(afs_int32)) !=
1850 sizeof(afs_int32)) {
1852 ("%s: write of addresses failed (%d)\n",
1853 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1863 * This routine sets up the buffers for the VL_RegisterAddrs RPC. All addresses
1864 * in FS_HostAddrs[] are in NBO, while the RPC treats them as a "blob" of data
1865 * and so we need to convert each of them into HBO which is what the extra
1866 * array called FS_HostAddrs_HBO is used here.
1869 Do_VLRegisterRPC(void)
1873 afs_uint32 FS_HostAddrs_HBO[ADDRSPERSITE];
1876 for (i = 0; i < FS_HostAddr_cnt; i++)
1877 FS_HostAddrs_HBO[i] = ntohl(FS_HostAddrs[i]);
1878 addrs.bulkaddrs_len = FS_HostAddr_cnt;
1879 addrs.bulkaddrs_val = (afs_uint32 *) FS_HostAddrs_HBO;
1880 code = ubik_VL_RegisterAddrs(cstruct, 0, &FS_HostUUID, 0, &addrs);
1882 if (code == VL_MULTIPADDR) {
1884 ("VL_RegisterAddrs rpc failed; The IP address exists on a different server; repair it\n"));
1886 ("VL_RegisterAddrs rpc failed; See VLLog for details\n"));
1888 } else if (code == RXGEN_OPCODE) {
1890 ("vlserver doesn't support VL_RegisterAddrs rpc; ignored\n"));
1891 FS_registered = 2; /* So we don't have to retry in the gc daemon */
1894 ("VL_RegisterAddrs rpc failed; will retry periodically (code=%d, err=%d)\n",
1896 FS_registered = 1; /* Retry in the gc daemon */
1899 FS_registered = 2; /* So we don't have to retry in the gc daemon */
1911 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH || AFSDIR_SERVER_NETINFO_FILEPATH) {
1913 * Find addresses we are supposed to register as per the netrestrict
1914 * and netinfo files (/usr/afs/local/NetInfo and
1915 * /usr/afs/local/NetRestict)
1918 afs_int32 code = parseNetFiles(FS_HostAddrs, NULL, NULL,
1919 ADDRSPERSITE, reason,
1920 AFSDIR_SERVER_NETINFO_FILEPATH,
1921 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
1923 ViceLog(0, ("Can't register any valid addresses: %s\n", reason));
1926 FS_HostAddr_cnt = (afs_uint32) code;
1929 FS_HostAddr_cnt = rx_getAllAddr(FS_HostAddrs, ADDRSPERSITE);
1932 if (FS_HostAddr_cnt == 1 && rxBind == 1)
1933 code = FS_HostAddrs[0];
1935 code = htonl(INADDR_ANY);
1945 * If this fails, it's because something major is wrong, and is not
1946 * likely to be time dependent.
1948 code = vl_Initialize(AFSDIR_SERVER_ETC_DIRPATH);
1951 ("Couldn't initialize protection library; code=%d.\n", code));
1955 /* Read or create the sysid file and register the fileserver's
1956 * IP addresses with the vlserver.
1958 code = ReadSysIdFile();
1960 /* Need to create the file */
1961 ViceLog(0, ("Creating new SysID file\n"));
1962 if ((code = afs_uuid_create(&FS_HostUUID))) {
1963 ViceLog(0, ("Failed to create new uuid: %d\n", code));
1967 /* A good sysid file exists; inform the vlserver. If any conflicts,
1968 * we always use the latest interface available as the real truth.
1971 code = Do_VLRegisterRPC();
1976 main(int argc, char *argv[])
1980 struct rx_securityClass **securityClasses;
1981 afs_int32 numClasses;
1982 struct rx_service *tservice;
1983 #ifdef AFS_PTHREAD_ENV
1984 pthread_t serverPid;
1985 pthread_attr_t tattr;
1986 #else /* AFS_PTHREAD_ENV */
1987 PROCESS parentPid, serverPid;
1988 #endif /* AFS_PTHREAD_ENV */
1990 int minVnodesRequired; /* min size of vnode cache */
1991 #ifndef AFS_NT40_ENV
1992 struct rlimit rlim; /* max number of open file descriptors */
1996 afs_uint32 rx_bindhost;
1997 VolumePackageOptions opts;
1999 #ifdef AFS_AIX32_ENV
2000 struct sigaction nsa;
2002 sigemptyset(&nsa.sa_mask);
2003 nsa.sa_handler = SIG_DFL;
2004 nsa.sa_flags = SA_FULLDUMP;
2005 sigaction(SIGABRT, &nsa, NULL);
2006 sigaction(SIGSEGV, &nsa, NULL);
2010 /* Initialize dirpaths */
2011 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
2013 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
2015 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
2019 /* set ihandle package defaults prior to parsing args */
2022 if (ParseArgs(argc, argv)) {
2026 #ifdef AFS_PTHREAD_ENV
2027 MUTEX_INIT(&fileproc_glock_mutex, "fileproc", MUTEX_DEFAULT, 0);
2028 #endif /* AFS_PTHREAD_ENV */
2030 #ifdef AFS_SGI_VNODE_GLUE
2031 if (afs_init_kernel_config(-1) < 0) {
2033 ("Can't determine NUMA configuration, not starting fileserver.\n");
2037 confDir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
2039 fprintf(stderr, "Unable to open config directory %s\n",
2040 AFSDIR_SERVER_ETC_DIRPATH);
2046 /* Open FileLog on stdout, stderr, fd 1 and fd2 (for perror), sigh. */
2047 #ifndef AFS_NT40_ENV
2048 serverLogSyslogTag = "fileserver";
2050 OpenLog(AFSDIR_SERVER_FILELOG_FILEPATH);
2053 if (SawSpare && SawPctSpare) {
2054 ViceLog(0, ("Both -spare and -pctspare specified, exiting.\n"));
2057 LogCommandLine(argc, argv, "starting", "", "File server", FSLog);
2059 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
2060 /* initialize the pthread soft signal handler thread */
2064 /* install signal handlers for controlling the fileserver process */
2065 ResetCheckSignal(); /* set CheckSignal_Signal() sig handler */
2066 ResetCheckDescriptors(); /* set CheckDescriptors_Signal() sig handler */
2068 #if defined(AFS_SGI_ENV)
2069 /* give this guy a non-degrading priority so help busy servers */
2070 schedctl(NDPRI, 0, NDPNORMMAX);
2074 #ifndef AFS_NT40_ENV
2075 nice(-5); /* TODO: */
2078 osi_Assert(DInit(buffs) == 0);
2079 #ifdef AFS_DEMAND_ATTACH_FS
2084 if (afs_winsockInit() < 0) {
2085 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
2086 ViceLog(0, ("File server failed to intialize winsock.\n"));
2092 /* if we support more than 16 threads, then we better have the ability
2093 ** to keep open a large number of files simultaneously
2095 #if defined(AFS_AIX_ENV) && !defined(AFS_AIX42_ENV)
2096 curLimit = OPEN_MAX; /* for pre AIX 4.2 systems */
2097 #elif defined(AFS_NT40_ENV)
2098 curLimit = NT_OPEN_MAX; /* open file descriptor limit on NT */
2101 curLimit = 0; /* the number of open file descriptors */
2102 code = getrlimit(RLIMIT_NOFILE, &rlim);
2104 curLimit = rlim.rlim_cur;
2105 rlim.rlim_cur = rlim.rlim_max;
2106 code = setrlimit(RLIMIT_NOFILE, &rlim);
2108 curLimit = rlim.rlim_max;
2111 ViceLog(0, ("Failed to increase open file limit, using default\n"));
2113 #endif /* defined(AFS_AIX_ENV) && !defined(AFS_AIX42_ENV) */
2115 curLimit -= 32; /* leave a slack of 32 file descriptors */
2116 if (lwps > curLimit) {
2120 lwps = 16; /* default to a maximum of 16 threads */
2122 /* tune the ihandle fd cache accordingly */
2123 if (vol_io_params.fd_max_cachesize < curLimit)
2124 vol_io_params.fd_max_cachesize = curLimit + 1;
2127 ("The system supports a max of %d open files and we are starting %d threads (ihandle fd cache is %d)\n",
2128 curLimit, lwps, vol_io_params.fd_max_cachesize));
2130 #ifndef AFS_PTHREAD_ENV
2131 osi_Assert(LWP_InitializeProcessSupport(LWP_MAX_PRIORITY - 2, &parentPid) ==
2133 #endif /* !AFS_PTHREAD_ENV */
2135 /* Initialize volume support */
2137 V_BreakVolumeCallbacks = BreakVolumeCallBacksLater;
2140 #ifdef AFS_PTHREAD_ENV
2141 SetLogThreadNumProgram( threadNum );
2144 /* initialize libacl routines */
2145 acl_Initialize(ACL_VERSION);
2147 /* initialize RX support */
2148 #ifndef AFS_NT40_ENV
2149 rxi_syscallp = viced_syscall;
2151 rx_extraPackets = rxpackets;
2152 rx_extraQuota = 4; /* for outgoing prserver calls from R threads */
2153 rx_SetBusyThreshold(busy_threshold, VBUSY);
2154 rx_SetCallAbortThreshold(abort_threshold);
2155 rx_SetConnAbortThreshold(abort_threshold);
2157 stackSize = 128 * 1024;
2159 stackSize = lwps * 4000;
2160 if (stackSize < 32000)
2162 else if (stackSize > 44000)
2165 #if defined(AFS_HPUX_ENV) || defined(AFS_SUN_ENV) || defined(AFS_SGI51_ENV) || defined(AFS_XBSD_ENV)
2166 rx_SetStackSize(1, stackSize);
2169 rx_SetUdpBufSize(udpBufSize); /* set the UDP buffer size for receive */
2170 rx_bindhost = SetupVL();
2172 if (rx_InitHost(rx_bindhost, (int)htons(7000)) < 0) {
2173 ViceLog(0, ("Cannot initialize RX\n"));
2176 if (!rxJumbograms) {
2177 /* Don't send and don't allow 3.4 clients to send jumbograms. */
2180 if (rxMaxMTU != -1) {
2181 rx_SetMaxMTU(rxMaxMTU);
2184 rx_SetRxDeadTime(30);
2185 afsconf_BuildServerSecurityObjects(confDir, AFSCONF_SEC_OBJS_RXKAD_CRYPT,
2186 &securityClasses, &numClasses);
2188 tservice = rx_NewServiceHost(rx_bindhost, /* port */ 0, /* service id */
2189 1, /*service name */
2191 securityClasses, numClasses,
2192 RXAFS_ExecuteRequest);
2195 ("Failed to initialize RX, probably two servers running.\n"));
2198 if (rxkadDisableDotCheck) {
2199 rx_SetSecurityConfiguration(tservice, RXS_CONFIG_FLAGS,
2200 (void *)RXS_CONFIG_FLAGS_DISABLE_DOTCHECK);
2202 rx_SetMinProcs(tservice, 3);
2203 rx_SetMaxProcs(tservice, lwps);
2204 rx_SetCheckReach(tservice, 1);
2205 rx_SetServerIdleDeadErr(tservice, VNOSERVICE);
2208 rx_NewService(0, RX_STATS_SERVICE_ID, "rpcstats", securityClasses,
2209 numClasses, RXSTATS_ExecuteRequest);
2211 ViceLog(0, ("Failed to initialize rpc stat service.\n"));
2214 rx_SetMinProcs(tservice, 2);
2215 rx_SetMaxProcs(tservice, 4);
2218 * Enable RX hot threads, which allows the listener thread to trade
2219 * places with an idle thread and moves the context switch from listener
2220 * to worker out of the critical path.
2222 rx_EnableHotThread();
2224 /* Some rx debugging */
2225 if (rxlog || eventlog) {
2226 debugFile = afs_fopen("rx_dbg", "w");
2228 rx_debugFile = debugFile;
2230 rxevent_debugFile = debugFile;
2233 init_sys_error_to_et(); /* Set up error table translation */
2234 h_InitHostPackage(); /* set up local cellname and realmname */
2235 InitCallBack(numberofcbs);
2239 if (code && code != VL_MULTIPADDR) {
2240 ViceLog(0, ("Fatal error in library initialization, exiting!!\n"));
2245 if (code && code != -1) {
2246 ViceLog(0, ("Fatal error in protection initialization, exiting!!\n"));
2250 /* allow super users to manage RX statistics */
2251 rx_SetRxStatUserOk(fs_rxstat_userok);
2253 CV_INIT(&fsync_cond, "fsync", CV_DEFAULT, 0);
2254 MUTEX_INIT(&fsync_glock_mutex, "fsync", MUTEX_DEFAULT, 0);
2256 #if !defined(AFS_DEMAND_ATTACH_FS)
2258 * For DAFS, we do not start the Rx server threads until after
2259 * the volume package is initialized, and fileserver state is
2260 * restored. This is necessary in order to keep host and callback
2261 * package state pristine until we have a chance to restore state.
2263 * Furthermore, startup latency is much lower with dafs, so this
2264 * shouldn't pose a serious problem.
2266 rx_StartServer(0); /* now start handling requests */
2269 /* we ensure that there is enough space in the vnode buffer to satisfy
2270 ** requests from all concurrent threads.
2271 ** the maximum number of vnodes used by a single thread at any one time
2272 ** is three ( "link" uses three vnodes simultaneously, one vLarge and
2273 ** two vSmall for linking files and two vLarge and one vSmall for linking
2276 minVnodesRequired = 2 * lwps + 1;
2277 if (minVnodesRequired > nSmallVns) {
2278 nSmallVns = minVnodesRequired;
2280 ("Overriding -s command line parameter with %d\n",
2283 if (minVnodesRequired > large) {
2284 large = minVnodesRequired;
2285 ViceLog(0, ("Overriding -l command line parameter with %d\n", large));
2288 /* We now do this after getting the listener up and running, so that client
2289 * connections don't timeout (maybe) if a file server is restarted, since it
2290 * will be available "real soon now". Worry about whether we can satisfy the
2291 * calls in the volume package itself.
2293 VOptDefaults(fileServer, &opts);
2294 opts.nLargeVnodes = large;
2295 opts.nSmallVnodes = nSmallVns;
2296 opts.volcache = volcache;
2297 opts.unsafe_attach = unsafe_attach;
2298 if (offline_timeout != -1) {
2299 opts.interrupt_rxcall = rx_InterruptCall;
2300 opts.offline_timeout = offline_timeout;
2302 if (offline_shutdown_timeout == -1) {
2303 /* default to -offline-timeout, if shutdown-specific timeout is not
2305 opts.offline_shutdown_timeout = offline_timeout;
2307 opts.interrupt_rxcall = rx_InterruptCall;
2308 opts.offline_shutdown_timeout = offline_shutdown_timeout;
2311 if (VInitVolumePackage2(fileServer, &opts)) {
2313 ("Shutting down: errors encountered initializing volume package\n"));
2318 /* Install handler to catch the shutdown signal;
2319 * bosserver assumes SIGQUIT shutdown
2321 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
2322 softsig_signal(SIGQUIT, ShutDown_Signal);
2324 (void)signal(SIGQUIT, ShutDown_Signal);
2327 if (VInitAttachVolumes(fileServer)) {
2329 ("Shutting down: errors encountered initializing volume package\n"));
2334 #ifdef AFS_DEMAND_ATTACH_FS
2335 if (fs_state.options.fs_state_restore) {
2338 * restore fileserver state */
2341 rx_StartServer(0); /* now start handling requests */
2342 #endif /* AFS_DEMAND_ATTACH_FS */
2345 * We are done calling fopen/fdopen. It is safe to use a large
2346 * of the file descriptor cache.
2350 #ifdef AFS_PTHREAD_ENV
2351 ViceLog(5, ("Starting pthreads\n"));
2352 osi_Assert(pthread_attr_init(&tattr) == 0);
2353 osi_Assert(pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED) == 0);
2355 osi_Assert(pthread_create
2356 (&serverPid, &tattr, FiveMinuteCheckLWP,
2357 &fiveminutes) == 0);
2358 osi_Assert(pthread_create
2359 (&serverPid, &tattr, HostCheckLWP, &fiveminutes) == 0);
2360 osi_Assert(pthread_create
2361 (&serverPid, &tattr, FsyncCheckLWP, &fiveminutes) == 0);
2362 #else /* AFS_PTHREAD_ENV */
2363 ViceLog(5, ("Starting LWP\n"));
2364 osi_Assert(LWP_CreateProcess
2365 (FiveMinuteCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
2366 (void *)&fiveminutes, "FiveMinuteChecks",
2367 &serverPid) == LWP_SUCCESS);
2369 osi_Assert(LWP_CreateProcess
2370 (HostCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
2371 (void *)&fiveminutes, "HostCheck", &serverPid) == LWP_SUCCESS);
2372 osi_Assert(LWP_CreateProcess
2373 (FsyncCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
2374 (void *)&fiveminutes, "FsyncCheck", &serverPid) == LWP_SUCCESS);
2375 #endif /* AFS_PTHREAD_ENV */
2377 FT_GetTimeOfDay(&tp, 0);
2380 * Figure out the FileServer's name and primary address.
2382 ViceLog(0, ("Getting FileServer name...\n"));
2383 code = gethostname(FS_HostName, 64);
2385 ViceLog(0, ("gethostname() failed\n"));
2387 ViceLog(0, ("FileServer host name is '%s'\n", FS_HostName));
2389 ViceLog(0, ("Getting FileServer address...\n"));
2390 he = gethostbyname(FS_HostName);
2392 ViceLog(0, ("Can't find address for FileServer '%s'\n", FS_HostName));
2395 memcpy(&FS_HostAddr_NBO, he->h_addr, 4);
2396 (void)afs_inet_ntoa_r(FS_HostAddr_NBO, hoststr);
2397 FS_HostAddr_HBO = ntohl(FS_HostAddr_NBO);
2399 ("FileServer %s has address %s (0x%x or 0x%x in host byte order)\n",
2400 FS_HostName, hoststr, FS_HostAddr_NBO, FS_HostAddr_HBO));
2405 ("File Server started %s",
2406 afs_ctime(&t, tbuffer, sizeof(tbuffer))));
2407 #if FS_STATS_DETAILED
2408 afs_FullPerfStats.det.epoch.tv_sec = StartTime = tp.tv_sec;
2410 #ifdef AFS_PTHREAD_ENV
2412 sleep(1000); /* long time */
2414 #else /* AFS_PTHREAD_ENV */
2415 osi_Assert(LWP_WaitProcess(&parentPid) == LWP_SUCCESS);
2416 #endif /* AFS_PTHREAD_ENV */