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>
25 #include <afs/procmgmt.h>
30 #include <WINNT/afsevent.h>
33 #ifdef HAVE_SYS_FILE_H
37 #ifdef HAVE_SYS_RESOURCE_H
38 #include <sys/resource.h>
45 #include <afs/afs_assert.h>
48 #include <afs/ptclient.h>
49 #include <afs/afsint.h>
50 #include <afs/vldbint.h>
51 #include <afs/errors.h>
52 #include <afs/ihandle.h>
53 #include <afs/vnode.h>
54 #include <afs/volume.h>
56 #include <afs/cellconfig.h>
58 #include <afs/prs_fs.h>
60 #include <rx/rxstat.h>
62 #include <afs/afs_args.h>
63 #include <afs/vlserver.h>
64 #include <afs/afsutil.h>
65 #include <afs/fileutil.h>
66 #include <afs/ptuser.h>
67 #include <afs/audit.h>
68 #include <afs/partition.h>
71 #include <afs/netutils.h>
73 #include "viced_prototypes.h"
76 #ifdef AFS_PTHREAD_ENV
77 #include <afs/softsig.h>
79 #if defined(AFS_SGI_ENV)
80 #include "sys/schedctl.h"
83 #include <rx/rx_globals.h>
87 void *ShutDown(void *);
88 static void ClearXStatValues(void);
89 static void NewParms(int);
90 static void PrintCounters(void);
91 static void ResetCheckDescriptors(void);
92 static void ResetCheckSignal(void);
93 static void *CheckSignal(void *);
95 static afs_int32 Do_VLRegisterRPC(void);
97 int eventlog = 0, rxlog = 0;
100 #ifdef AFS_PTHREAD_ENV
101 pthread_mutex_t fsync_glock_mutex;
102 pthread_cond_t fsync_cond;
105 #endif /* AFS_PTHREAD_ENV */
108 #define NT_OPEN_MAX 1024 /* This is an arbitrary no. we came up with for
109 * now. We hope this will be replaced by a more
110 * intelligent estimate later. */
113 int SystemId; /* ViceID of "Administrators" */
114 int SystemAnyUser; /* Viceid of "System:AnyUser" */
115 prlist SystemAnyUserCPS; /* CPS for "system:AnyUser */
116 int AnonymousID = 0; /* ViceId of "Anonymous" */
117 prlist AnonCPS; /* CPS for "Anonymous" */
119 struct afsconf_dir *confDir; /* Configuration dir object */
121 int restartMode = RESTART_ORDINARY;
124 * Home for the performance statistics.
126 struct afs_PerfStats afs_perfstats;
129 extern int Statistics;
137 int rxJumbograms = 0; /* default is to not send and receive jumbograms. */
138 int rxBind = 0; /* don't bind */
139 int rxkadDisableDotCheck = 0; /* disable check for dot in principal name */
141 afs_int32 implicitAdminRights = PRSFS_LOOKUP; /* The ADMINISTER right is
143 afs_int32 readonlyServer = 0;
146 int stackSize = 24000;
147 int fiveminutes = 300; /* 5 minutes. Change this for debugging only */
148 int CurrentConnections = 0;
149 int hostaclRefresh = 7200; /* refresh host clients' acls every 2 hrs */
150 #if defined(AFS_SGI_ENV)
156 * seconds to wait until forcing a panic during ShutDownAndCore(PANIC)
157 * in case we get stuck.
159 #ifdef AFS_DEMAND_ATTACH_FS
160 static int panic_timeout = 2 * 60;
162 static int panic_timeout = 30 * 60;
165 int rxpackets = 150; /* 100 */
166 int nSmallVns = 400; /* 200 */
167 int large = 400; /* 200 */
168 int volcache = 400; /* 400 */
169 int numberofcbs = 60000; /* 60000 */
170 int lwps = 9; /* 6 */
171 int buffs = 90; /* 70 */
172 int novbc = 0; /* Enable Volume Break calls */
173 int busy_threshold = 600;
174 int abort_threshold = 10;
175 int udpBufSize = 0; /* UDP buffer size for receive */
176 int sendBufSize = 16384; /* send buffer size */
177 int saneacls = 0; /* Sane ACLs Flag */
178 static int unsafe_attach = 0; /* avoid inUse check on vol attach? */
179 static int offline_timeout = -1; /* -offline-timeout option */
180 static int offline_shutdown_timeout = -1; /* -offline-shutdown-timeout option */
184 #ifdef AFS_PTHREAD_ENV
185 pthread_key_t viced_uclient_key;
188 #ifdef AFS_PTHREAD_ENV
189 pthread_key_t viced_uclient_key;
193 * FileServer's name and IP address, both network byte order and
196 #define ADDRSPERSITE 16 /* Same global is in rx/rx_user.c */
198 char FS_HostName[128] = "localhost";
199 afs_uint32 FS_HostAddr_NBO;
200 afs_uint32 FS_HostAddr_HBO;
201 afs_uint32 FS_HostAddrs[ADDRSPERSITE], FS_HostAddr_cnt = 0, FS_registered = 0;
202 /* All addresses in FS_HostAddrs are in NBO */
205 static void FlagMsg(void);
207 #ifdef AFS_DEMAND_ATTACH_FS
210 * fileserver mode support
212 * during fileserver shutdown, we have to track the graceful shutdown of
213 * certain background threads before we are allowed to dump state to
217 #if !defined(PTHREAD_RWLOCK_INITIALIZER) && defined(AFS_DARWIN80_ENV)
218 #define PTHREAD_RWLOCK_INITIALIZER {0x2DA8B3B4, {0}}
222 struct fs_state fs_state =
229 PTHREAD_COND_INITIALIZER,
230 PTHREAD_RWLOCK_INITIALIZER
232 #else /* AFS_NT40_ENV */
233 struct fs_state fs_state;
235 static int fs_stateInit(void)
237 fs_state.mode = FS_MODE_NORMAL;
238 fs_state.FiveMinuteLWP_tranquil = 0;
239 fs_state.HostCheckLWP_tranquil = 0;
240 fs_state.FsyncCheckLWP_tranquil = 0;
241 fs_state.salvsync_fatal_error = 0;
243 fs_state.options.fs_state_save = 1;
244 fs_state.options.fs_state_restore = 1;
245 fs_state.options.fs_state_verify_before_save = 1;
246 fs_state.options.fs_state_verify_after_restore = 1;
248 CV_INIT(&fs_state.worker_done_cv, "worker done", CV_DEFAULT, 0);
249 osi_Assert(pthread_rwlock_init(&fs_state.state_lock, NULL) == 0);
251 #endif /* AFS_NT40_ENV */
252 #endif /* AFS_DEMAND_ATTACH_FS */
255 * Home for the performance statistics.
260 CheckDescriptors(void *unused)
263 struct afs_stat status;
264 int tsize = getdtablesize();
266 for (i = 0; i < tsize; i++) {
267 if (afs_fstat(i, &status) != -1) {
268 printf("%d: dev %x, inode %u, length %u, type/mode %x\n", i,
269 (unsigned int) status.st_dev,
270 (unsigned int) status.st_ino,
271 (unsigned int) status.st_size,
276 ResetCheckDescriptors();
279 } /*CheckDescriptors */
282 #ifdef AFS_PTHREAD_ENV
284 CheckSignal_Signal(int x)
290 ShutDown_Signal(int x)
296 CheckDescriptors_Signal(int x)
298 CheckDescriptors(NULL);
300 #else /* AFS_PTHREAD_ENV */
302 CheckSignal_Signal(int x)
304 IOMGR_SoftSig(CheckSignal, 0);
308 ShutDown_Signal(int x)
310 IOMGR_SoftSig(ShutDown, 0);
314 CheckDescriptors_Signal(int x)
316 IOMGR_SoftSig(CheckDescriptors, 0);
318 #endif /* AFS_PTHREAD_ENV */
320 /* check whether caller is authorized to manage RX statistics */
322 fs_rxstat_userok(struct rx_call *call)
324 return afsconf_SuperUser(confDir, call, NULL);
328 ResetCheckSignal(void)
332 #if defined(AFS_HPUX_ENV)
335 #if defined(AFS_NT40_ENV)
342 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
343 softsig_signal(signo, CheckSignal_Signal);
345 signal(signo, CheckSignal_Signal);
350 ResetCheckDescriptors(void)
353 #if defined(AFS_PTHREAD_ENV)
354 softsig_signal(SIGTERM, CheckDescriptors_Signal);
356 (void)signal(SIGTERM, CheckDescriptors_Signal);
361 #if defined(AFS_PTHREAD_ENV)
365 return (intptr_t)pthread_getspecific(rx_thread_id_key);
371 viced_syscall(afs_uint32 a3, afs_uint32 a4, void *a5)
374 #ifndef AFS_LINUX20_ENV
377 old = (void (*)(int))signal(SIGSYS, SIG_IGN);
379 rcode = syscall(AFS_SYSCALL, 28 /* AFSCALL_CALL */ , a3, a4, a5);
380 #ifndef AFS_LINUX20_ENV
388 #if !defined(AFS_NT40_ENV)
389 #include "AFS_component_version_number.c"
390 #endif /* !AFS_NT40_ENV */
392 #define MAXADMINNAME 64
393 char adminName[MAXADMINNAME];
399 struct afs_stat status;
401 if ((afs_stat("/AdminName", &status)) || /* if file does not exist */
402 (status.st_size <= 0) || /* or it is too short */
403 (status.st_size >= (MAXADMINNAME)) || /* or it is too long */
404 !(fd = afs_open("/AdminName", O_RDONLY, 0))) { /* or the open fails */
405 strcpy(adminName, "System:Administrators"); /* use the default name */
407 (void)read(fd, adminName, status.st_size); /* use name from the file */
410 close(fd); /* close fd if it was opened */
412 } /*CheckAdminName */
418 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
419 /* set our 'thread-id' so that the host hold table works */
420 pthread_setspecific(rx_thread_id_key,
421 (void *)(intptr_t)rx_NewThreadId());
423 ("Set thread id %p for '%s'\n",
424 pthread_getspecific(rx_thread_id_key), s));
428 /* This LWP does things roughly every 5 minutes */
430 FiveMinuteCheckLWP(void *unused)
435 ViceLog(1, ("Starting five minute check process\n"));
436 setThreadId("FiveMinuteCheckLWP");
438 #ifdef AFS_DEMAND_ATTACH_FS
440 while (fs_state.mode == FS_MODE_NORMAL) {
441 fs_state.FiveMinuteLWP_tranquil = 1;
447 #ifdef AFS_PTHREAD_ENV
449 #else /* AFS_PTHREAD_ENV */
450 IOMGR_Sleep(fiveminutes);
451 #endif /* AFS_PTHREAD_ENV */
453 #ifdef AFS_DEMAND_ATTACH_FS
455 if (fs_state.mode != FS_MODE_NORMAL) {
458 fs_state.FiveMinuteLWP_tranquil = 0;
462 /* close the log so it can be removed */
463 ReOpenLog(AFSDIR_SERVER_FILELOG_FILEPATH); /* don't trunc, just append */
464 ViceLog(2, ("Cleaning up timed out callbacks\n"));
465 if (CleanupTimedOutCallBacks())
466 ViceLog(5, ("Timed out callbacks deleted\n"));
467 ViceLog(2, ("Set disk usage statistics\n"));
469 if (FS_registered == 1)
471 /* Force wakeup in case we missed something; pthreads does timedwait */
472 #ifndef AFS_PTHREAD_ENV
473 LWP_NoYieldSignal(fsync_wait);
475 if (printBanner && (++msg & 1)) { /* Every 10 minutes */
476 time_t now = FT_ApproxTime();
478 strftime(tbuffer, sizeof(tbuffer), "%a %b %d %T %Y",
479 localtime_r(&now, &tm));
481 ("File server is running at %s\n", tbuffer));
483 #ifdef AFS_DEMAND_ATTACH_FS
487 #ifdef AFS_DEMAND_ATTACH_FS
488 fs_state.FiveMinuteLWP_tranquil = 1;
490 CV_BROADCAST(&fs_state.worker_done_cv);
495 } /*FiveMinuteCheckLWP */
498 /* This LWP does host checks every 5 minutes: it should not be used for
499 * other 5 minute activities because it may be delayed by timeouts when
500 * it probes the workstations
504 HostCheckLWP(void *unused)
506 ViceLog(1, ("Starting Host check process\n"));
507 setThreadId("HostCheckLWP");
508 #ifdef AFS_DEMAND_ATTACH_FS
510 while (fs_state.mode == FS_MODE_NORMAL) {
511 fs_state.HostCheckLWP_tranquil = 1;
517 #ifdef AFS_PTHREAD_ENV
519 #else /* AFS_PTHREAD_ENV */
520 IOMGR_Sleep(fiveminutes);
521 #endif /* AFS_PTHREAD_ENV */
523 #ifdef AFS_DEMAND_ATTACH_FS
525 if (fs_state.mode != FS_MODE_NORMAL) {
528 fs_state.HostCheckLWP_tranquil = 0;
532 ViceLog(2, ("Checking for dead venii & clients\n"));
535 #ifdef AFS_DEMAND_ATTACH_FS
539 #ifdef AFS_DEMAND_ATTACH_FS
540 fs_state.HostCheckLWP_tranquil = 1;
542 CV_BROADCAST(&fs_state.worker_done_cv);
549 /* This LWP does fsync checks every 5 minutes: it should not be used for
550 * other 5 minute activities because it may be delayed by timeouts when
551 * it probes the workstations
554 FsyncCheckLWP(void *unused)
557 #ifdef AFS_PTHREAD_ENV
558 struct timespec fsync_next;
560 ViceLog(1, ("Starting fsync check process\n"));
562 setThreadId("FsyncCheckLWP");
564 #ifdef AFS_DEMAND_ATTACH_FS
566 while (fs_state.mode == FS_MODE_NORMAL) {
567 fs_state.FsyncCheckLWP_tranquil = 1;
573 #ifdef AFS_PTHREAD_ENV
574 /* rounding is fine */
575 fsync_next.tv_nsec = 0;
576 fsync_next.tv_sec = time(0) + fiveminutes;
578 code = CV_TIMEDWAIT(&fsync_cond, &fsync_glock_mutex,
580 if (code != 0 && code != ETIMEDOUT)
581 ViceLog(0, ("pthread_cond_timedwait returned %d\n", code));
582 #else /* AFS_PTHREAD_ENV */
583 if ((code = LWP_WaitProcess(fsync_wait)) != LWP_SUCCESS)
584 ViceLog(0, ("LWP_WaitProcess returned %d\n", code));
585 #endif /* AFS_PTHREAD_ENV */
588 #ifdef AFS_DEMAND_ATTACH_FS
590 if (fs_state.mode != FS_MODE_NORMAL) {
593 fs_state.FsyncCheckLWP_tranquil = 0;
595 #endif /* AFS_DEMAND_ATTACH_FS */
597 ViceLog(2, ("Checking for fsync events\n"));
599 code = BreakLaterCallBacks();
601 #ifdef AFS_DEMAND_ATTACH_FS
605 #ifdef AFS_DEMAND_ATTACH_FS
606 fs_state.FsyncCheckLWP_tranquil = 1;
608 CV_BROADCAST(&fs_state.worker_done_cv);
611 #endif /* AFS_DEMAND_ATTACH_FS */
615 /*------------------------------------------------------------------------
616 * PRIVATE ClearXStatValues
619 * Initialize all of the values collected via the xstat
629 * Must be called during File Server initialization.
633 *------------------------------------------------------------------------*/
636 ClearXStatValues(void)
637 { /*ClearXStatValues */
639 struct fs_stats_opTimingData *opTimeP; /*Ptr to timing struct */
640 struct fs_stats_xferData *opXferP; /*Ptr to xfer struct */
641 int i; /*Loop counter */
644 * Zero all xstat-related structures.
646 memset((&afs_perfstats), 0, sizeof(struct afs_PerfStats));
647 #if FS_STATS_DETAILED
648 memset((&afs_FullPerfStats), 0,
649 sizeof(struct fs_stats_FullPerfStats));
652 * That's not enough. We have to set reasonable minima for
653 * time and xfer values in the detailed stats.
655 opTimeP = &(afs_FullPerfStats.det.rpcOpTimes[0]);
656 for (i = 0; i < FS_STATS_NUM_RPC_OPS; i++, opTimeP++)
657 opTimeP->minTime.tv_sec = 999999;
659 opXferP = &(afs_FullPerfStats.det.xferOpTimes[0]);
660 for (i = 0; i < FS_STATS_NUM_XFER_OPS; i++, opXferP++) {
661 opXferP->minTime.tv_sec = 999999;
662 opXferP->minBytes = 999999999;
666 * There's more. We have to set our unique system identifier, as
667 * declared in param.h. If such a thing is not defined, we bitch
668 * and declare ourselves to be an unknown system type.
671 afs_perfstats.sysname_ID = SYS_NAME_ID;
674 ViceLog(0, ("Sys name ID constant not defined in param.h!!\n"));
675 ViceLog(0, ("[Choosing ``undefined'' sys name ID.\n"));
677 afs_perfstats.sysname_ID = SYS_NAME_ID_UNDEFINED;
678 #endif /* SYS_NAME_ID */
681 } /*ClearXStatValues */
683 int CopyOnWrite_calls = 0, CopyOnWrite_off0 = 0, CopyOnWrite_size0 = 0;
684 afs_fsize_t CopyOnWrite_maxsize = 0;
689 int dirbuff, dircall, dirio;
691 int workstations, activeworkstations, delworkstations;
695 #ifdef AFS_DEMAND_ATTACH_FS
699 FT_GetTimeOfDay(&tpl, 0);
701 strftime(tbuffer, sizeof(tbuffer), "%a %b %d %T %Y",
702 localtime_r(&StartTime, &tm));
703 ViceLog(0, ("Vice was last started at %s\n", tbuffer));
705 #ifdef AFS_DEMAND_ATTACH_FS
706 if (LogLevel >= 125) {
707 stats_flags = VOL_STATS_PER_CHAIN2;
708 } else if (LogLevel >= 25) {
709 stats_flags = VOL_STATS_PER_CHAIN;
711 VPrintExtendedCacheStats(stats_flags);
715 DStat(&dirbuff, &dircall, &dirio);
717 ("With %d directory buffers; %d reads resulted in %d read I/Os\n",
718 dirbuff, dircall, dirio));
719 rx_PrintStats(stderr);
720 audit_PrintStats(stderr);
722 PrintCallBackStats();
724 processSize = -1; /* TODO: */
726 processSize = (int)((long)sbrk(0) >> 10);
729 ("There are %d connections, process size %d\n",
730 CurrentConnections, processSize));
731 h_GetWorkStats(&workstations, &activeworkstations, &delworkstations,
732 tpl.tv_sec - 15 * 60);
734 ("There are %d workstations, %d are active (req in < 15 mins), %d marked \"down\"\n",
735 workstations, activeworkstations, delworkstations));
736 ViceLog(0, ("CopyOnWrite: calls %d off0 %d size0 %d maxsize 0x%llx\n",
737 CopyOnWrite_calls, CopyOnWrite_off0, CopyOnWrite_size0, CopyOnWrite_maxsize));
746 CheckSignal(void *unused)
748 if (FS_registered > 0) {
750 * We have proper ip addresses; tell the vlserver what we got; the following
751 * routine will do the proper reporting for us
764 ShutdownWatchdogLWP(void *unused)
766 sleep(panic_timeout);
767 ViceLog(0, ("ShutdownWatchdogLWP: Failed to shutdown and panic "
768 "within %d seconds; forcing panic\n", panic_timeout));
769 osi_Panic("ShutdownWatchdogLWP: Failed to shutdown and panic "
770 "within %d seconds; forcing panic\n", panic_timeout);
775 ShutDownAndCore(int dopanic)
777 time_t now = time(NULL);
782 #ifdef AFS_PTHREAD_ENV
783 pthread_t watchdogPid;
784 pthread_attr_t tattr;
785 osi_Assert(pthread_attr_init(&tattr) == 0);
786 osi_Assert(pthread_create(&watchdogPid, &tattr, ShutdownWatchdogLWP, NULL) == 0);
789 osi_Assert(LWP_CreateProcess
790 (ShutdownWatchdogLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
791 NULL, "ShutdownWatchdog", &watchdogPid) == LWP_SUCCESS);
795 /* do not allows new reqests to be served from now on, all new requests
796 * are returned with an error code of RX_RESTARTING ( transient failure ) */
797 rx_SetRxTranquil(); /* dhruba */
801 #ifdef AFS_DEMAND_ATTACH_FS
803 if (fs_state.mode == FS_MODE_SHUTDOWN) {
804 /* it is possible for at least fs_stateSave() (called below) to call
805 * ShutDownAndCore if there's host list corruption; prevent
806 * deinitializing some stuff twice */
807 ViceLog(0, ("ShutDownAndCore called during shutdown? Skipping volume "
808 "and host package shutdown\n"));
812 fs_state.mode = FS_MODE_SHUTDOWN;
816 strftime(tbuffer, sizeof(tbuffer), "%a %b %d %T %Y",
817 localtime_r(&now, &tm));
818 ViceLog(0, ("Shutting down file server at %s", tbuffer));
820 ViceLog(0, ("ABNORMAL SHUTDOWN, see core file.\n"));
825 /* shut down volume package */
828 #ifdef AFS_DEMAND_ATTACH_FS
829 if (fs_state.options.fs_state_save) {
832 * save fileserver state to disk */
835 ViceLog(0, ("Not saving fileserver state; abnormal shutdown\n"));
838 /* make sure background threads have finished all of their asynchronous
839 * work on host and callback structures */
841 while (!fs_state.FiveMinuteLWP_tranquil ||
842 !fs_state.HostCheckLWP_tranquil ||
843 !fs_state.FsyncCheckLWP_tranquil) {
846 ViceLog(0, ("waiting for background host/callback threads to quiesce before saving fileserver state...\n"));
847 CV_WAIT(&fs_state.worker_done_cv, &fileproc_glock_mutex);
853 /* ok. it should now be fairly safe. let's do the state dump */
859 #endif /* AFS_DEMAND_ATTACH_FS */
862 rx_PrintStats(debugFile);
866 strftime(tbuffer, sizeof(tbuffer), "%a %b %d %T %Y",
867 localtime_r(&now, &tm));
869 ViceLog(0, ("File server has terminated abnormally at %s\n", tbuffer));
871 ViceLog(0, ("File server has terminated normally at %s\n", tbuffer));
874 if (dopanic) /* XXX pass in file and line? */
875 osi_Panic("Panic requested\n");
881 ShutDown(void *unused)
882 { /* backward compatibility */
883 ShutDownAndCore(DONTPANIC);
891 /* default supports help flag */
893 fputs("Usage: fileserver ", stdout);
894 fputs("[-auditlog <log path>] ", stdout);
895 fputs("[-audit-interface <file|sysvmq> (default is file)] ", stdout);
896 fputs("[-d <debug level>] ", stdout);
897 fputs("[-p <number of processes>] ", stdout);
898 fputs("[-spare <number of spare blocks>] ", stdout);
899 fputs("[-pctspare <percentage spare>] ", stdout);
900 fputs("[-b <buffers>] ", stdout);
901 fputs("[-l <large vnodes>] ", stdout);
902 fputs("[-s <small vnodes>] ", stdout);
903 fputs("[-vc <volume cachesize>] ", stdout);
904 fputs("[-w <call back wait interval>] ", stdout);
905 fputs("[-cb <number of call backs>] ", stdout);
906 fputs("[-banner (print banner every 10 minutes)] ", stdout);
907 fputs("[-novbc (whole volume cbs disabled)] ", stdout);
908 fputs("[-implicit <admin mode bits: rlidwka>] ", stdout);
909 fputs("[-readonly (read-only file server)] ", stdout);
910 fputs("[-hr <number of hours between refreshing the host cps>] ", stdout);
911 fputs("[-busyat <redirect clients when queue > n>] ", stdout);
912 fputs("[-nobusy <no VBUSY before a volume is attached>] ", stdout);
913 fputs("[-rxpck <number of rx extra packets>] ", stdout);
914 fputs("[-rxdbg (enable rx debugging)] ", stdout);
915 fputs("[-rxdbge (enable rxevent debugging)] ", stdout);
916 fputs("[-rxmaxmtu <bytes>] ", stdout);
917 fputs("[-rxbind (bind the Rx socket to one address)] ", stdout);
918 fputs("[-allow-dotted-principals (disable the rxkad principal name dot check)] ", stdout);
919 fputs("[-vhandle-setaside (fds reserved for non-cache io [default 128])] ", stdout);
920 fputs("[-vhandle-max-cachesize (max open files [default 128])] ", stdout);
921 fputs("[-vhandle-initial-cachesize (fds reserved for cache io [default 128])] ", stdout);
922 #ifdef AFS_DEMAND_ATTACH_FS
923 fputs("[-fs-state-dont-save (disable state save during shutdown)] ", stdout);
924 fputs("[-fs-state-dont-restore (disable state restore during startup)] ", stdout);
925 fputs("[-fs-state-verify <none|save|restore|both> (default is both)] ", stdout);
926 fputs("[-vattachpar <max number of volume attach/shutdown threads> (default is 1)] ", stdout);
927 fputs("[-vhashsize <log(2) of number of volume hash buckets> (default is 8)] ", stdout);
928 fputs("[-vlrudisable (disable VLRU functionality)] ", stdout);
929 fputs("[-vlruthresh <minutes before unused volumes become eligible for soft detach> (default is 2 hours)] ", stdout);
930 fputs("[-vlruinterval <seconds between VLRU scans> (default is 2 minutes)] ", stdout);
931 fputs("[-vlrumax <max volumes to soft detach in one VLRU scan> (default is 8)] ", stdout);
932 fputs("[-unsafe-nosalvage (bypass volume inUse safety check on attach, bypassing salvage)] ", stdout);
933 #elif AFS_PTHREAD_ENV
934 fputs("[-vattachpar <number of volume attach threads> (default is 1)] ", stdout);
937 fputs("[-m <min percentage spare in partition>] ", stdout);
939 #if defined(AFS_SGI_ENV)
940 fputs("[-lock (keep fileserver from swapping)] ", stdout);
942 fputs("[-L (large server conf)] ", stdout);
943 fputs("[-S (small server conf)] ", stdout);
944 fputs("[-k <stack size>] ", stdout);
945 fputs("[-realm <Kerberos realm name>] ", stdout);
946 fputs("[-udpsize <size of socket buffer in bytes>] ", stdout);
947 fputs("[-sendsize <size of send buffer in bytes>] ", stdout);
948 fputs("[-abortthreshold <abort threshold>] ", stdout);
949 fputs("[-nojumbo (disable jumbogram network packets - deprecated)] ", stdout);
950 fputs("[-jumbo (enable jumbogram network packets)] ", stdout);
951 fputs("[-offline-timeout <client RX timeout for offlining volumes>]", stdout);
952 fputs("[-offline-shutdown-timeout <RX timeout for offlining volumes during shutdown>]", stdout);
953 /* fputs("[-enable_peer_stats] ", stdout); */
954 /* fputs("[-enable_process_stats] ", stdout); */
955 fputs("[-help]\n", stdout);
957 ViceLog(0, ("%s", buffer));
966 ParseRights(char *arights)
972 if (!arights || !strcmp(arights, "")) {
973 printf("Missing list of mode bits on -implicit option\n");
976 if (!strcmp(arights, "none"))
978 else if (!strcmp(arights, "read"))
979 mode = PRSFS_READ | PRSFS_LOOKUP;
980 else if (!strcmp(arights, "write"))
982 PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
983 PRSFS_WRITE | PRSFS_LOCK;
984 else if (!strcmp(arights, "all"))
986 PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
987 PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER;
989 len = strlen(arights);
990 for (i = 0; i < len; i++) {
995 mode |= PRSFS_LOOKUP;
997 mode |= PRSFS_INSERT;
999 mode |= PRSFS_DELETE;
1001 mode |= PRSFS_WRITE;
1005 mode |= PRSFS_ADMINISTER;
1023 printf("Illegal -implicit rights character '%c'.\n", tc);
1032 * Limit MAX_FILESERVER_THREAD by the system limit on the number of
1033 * pthreads (sysconf(_SC_THREAD_THREADS_MAX)), if applicable and
1036 * AIX: sysconf() limit is real
1037 * HP-UX: sysconf() limit is real
1038 * IRIX: sysconf() limit is apparently NOT real -- too small
1039 * DUX: sysconf() limit is apparently NOT real -- too big
1040 * Linux: sysconf() limit is apparently NOT real -- too big
1041 * Solaris: no sysconf() limit
1044 max_fileserver_thread(void)
1046 #if defined(AFS_PTHREAD_ENV)
1047 #if defined(AFS_AIX_ENV) || defined(AFS_HPUX_ENV)
1050 ans = sysconf(_SC_THREAD_THREADS_MAX);
1051 if (0 < ans && ans < MAX_FILESERVER_THREAD)
1054 #endif /* defined(AFS_PTHREAD_ENV) */
1055 return MAX_FILESERVER_THREAD;
1058 /* from ihandle.c */
1059 extern ih_init_params vol_io_params;
1062 ParseArgs(int argc, char *argv[])
1064 int SawL = 0, SawS = 0, SawVC = 0;
1065 int Sawrxpck = 0, Sawsmall = 0, Sawlarge = 0, Sawcbs = 0, Sawlwps =
1069 int bufSize = 0; /* temp variable to read in udp socket buf size */
1071 char *auditFileName = NULL;
1073 for (i = 1; i < argc; i++) {
1074 if (!strcmp(argv[i], "-d")) {
1075 if ((i + 1) >= argc) {
1076 fprintf(stderr, "missing argument for -d\n");
1079 debuglevel = atoi(argv[++i]);
1080 LogLevel = debuglevel;
1081 } else if (!strcmp(argv[i], "-banner")) {
1083 } else if (!strcmp(argv[i], "-implicit")) {
1084 if ((i + 1) >= argc) {
1085 fprintf(stderr, "missing argument for -implicit\n");
1088 implicitAdminRights = ParseRights(argv[++i]);
1089 if (implicitAdminRights < 0)
1090 return implicitAdminRights;
1091 } else if (!strcmp(argv[i], "-readonly")) {
1093 } else if (!strcmp(argv[i], "-L")) {
1095 } else if (!strcmp(argv[i], "-S")) {
1097 } else if (!strcmp(argv[i], "-p")) {
1099 if ((i + 1) >= argc) {
1100 fprintf(stderr, "missing argument for -p\n");
1103 lwps = atoi(argv[++i]);
1104 } else if (!strcmp(argv[i], "-b")) {
1106 if ((i + 1) >= argc) {
1107 fprintf(stderr, "missing argument for -b\n");
1110 buffs = atoi(argv[++i]);
1111 } else if (!strcmp(argv[i], "-l")) {
1113 if ((i + 1) >= argc) {
1114 fprintf(stderr, "missing argument for -l\n");
1117 large = atoi(argv[++i]);
1118 } else if (!strcmp(argv[i], "-vc")) {
1120 if ((i + 1) >= argc) {
1121 fprintf(stderr, "missing argument for -vc\n");
1124 volcache = atoi(argv[++i]);
1125 } else if (!strcmp(argv[i], "-novbc")) {
1127 } else if (!strcmp(argv[i], "-rxpck")) {
1129 if ((i + 1) >= argc) {
1130 fprintf(stderr, "missing argument for -rxpck\n");
1133 rxpackets = atoi(argv[++i]);
1134 #ifdef AFS_PTHREAD_ENV
1135 } else if (!strcmp(argv[i], "-vattachpar")) {
1136 if ((i + 1) >= argc) {
1137 fprintf(stderr, "missing argument for %s\n", argv[i]);
1140 vol_attach_threads = atoi(argv[++i]);
1141 #endif /* AFS_PTHREAD_ENV */
1142 } else if (!strcmp(argv[i], "-vhandle-setaside")) {
1143 if ((i + 1) >= argc) {
1144 fprintf(stderr, "missing argument for %s\n", argv[i]);
1147 vol_io_params.fd_handle_setaside = atoi(argv[++i]);
1148 } else if (!strcmp(argv[i], "-vhandle-max-cachesize")) {
1149 if ((i + 1) >= argc) {
1150 fprintf(stderr, "missing argument for %s\n", argv[i]);
1153 vol_io_params.fd_max_cachesize = atoi(argv[++i]);
1154 } else if (!strcmp(argv[i], "-vhandle-initial-cachesize")) {
1155 if ((i + 1) >= argc) {
1156 fprintf(stderr, "missing argument for %s\n", argv[i]);
1159 vol_io_params.fd_initial_cachesize = atoi(argv[++i]);
1160 #ifdef AFS_DEMAND_ATTACH_FS
1161 } else if (!strcmp(argv[i], "-fs-state-dont-save")) {
1162 fs_state.options.fs_state_save = 0;
1163 } else if (!strcmp(argv[i], "-fs-state-dont-restore")) {
1164 fs_state.options.fs_state_restore = 0;
1165 } else if (!strcmp(argv[i], "-fs-state-verify")) {
1166 if ((i + 1) >= argc) {
1167 fprintf(stderr, "missing argument for %s\n", argv[i]);
1171 if (!strcmp(argv[i], "none")) {
1172 fs_state.options.fs_state_verify_before_save = 0;
1173 fs_state.options.fs_state_verify_after_restore = 0;
1174 } else if (!strcmp(argv[i], "save")) {
1175 fs_state.options.fs_state_verify_after_restore = 0;
1176 } else if (!strcmp(argv[i], "restore")) {
1177 fs_state.options.fs_state_verify_before_save = 0;
1178 } else if (!strcmp(argv[i], "both")) {
1181 fprintf(stderr, "invalid argument for %s\n", argv[i-1]);
1184 } else if (!strcmp(argv[i], "-vhashsize")) {
1186 if ((i + 1) >= argc) {
1187 fprintf(stderr, "missing argument for %s\n", argv[i]);
1190 hashsize = atoi(argv[++i]);
1191 if (VSetVolHashSize(hashsize)) {
1192 fprintf(stderr, "specified -vhashsize (%s) is invalid or out "
1193 "of range\n", argv[i]);
1196 } else if (!strcmp(argv[i], "-vlrudisable")) {
1197 VLRU_SetOptions(VLRU_SET_ENABLED, 0);
1198 } else if (!strcmp(argv[i], "-vlruthresh")) {
1199 if ((i + 1) >= argc) {
1200 fprintf(stderr, "missing argument for %s\n", argv[i]);
1203 VLRU_SetOptions(VLRU_SET_THRESH, 60*atoi(argv[++i]));
1204 } else if (!strcmp(argv[i], "-vlruinterval")) {
1205 if ((i + 1) >= argc) {
1206 fprintf(stderr, "missing argument for %s\n", argv[i]);
1209 VLRU_SetOptions(VLRU_SET_INTERVAL, atoi(argv[++i]));
1210 } else if (!strcmp(argv[i], "-vlrumax")) {
1211 if ((i + 1) >= argc) {
1212 fprintf(stderr, "missing argument for %s\n", argv[i]);
1215 VLRU_SetOptions(VLRU_SET_MAX, atoi(argv[++i]));
1216 } else if (!strcmp(argv[i], "-unsafe-nosalvage")) {
1218 #endif /* AFS_DEMAND_ATTACH_FS */
1219 } else if (!strcmp(argv[i], "-s")) {
1221 if ((i + 1) >= argc) {
1222 fprintf(stderr, "missing argument for -s\n");
1225 nSmallVns = atoi(argv[++i]);
1226 } else if (!strcmp(argv[i], "-abortthreshold")) {
1227 if ((i + 1) >= argc) {
1228 fprintf(stderr, "missing argument for -abortthreshold\n");
1231 abort_threshold = atoi(argv[++i]);
1232 } else if (!strcmp(argv[i], "-k")) {
1233 if ((i + 1) >= argc) {
1234 fprintf(stderr, "missing argument for -k\n");
1237 stack = atoi(argv[++i]);
1239 #if defined(AFS_SGI_ENV)
1240 else if (!strcmp(argv[i], "-lock")) {
1244 else if (!strcmp(argv[i], "-spare")) {
1245 if ((i + 1) >= argc) {
1246 fprintf(stderr, "missing argument for -spare\n");
1249 BlocksSpare = atoi(argv[++i]);
1251 } else if (!strcmp(argv[i], "-pctspare")) {
1252 if ((i + 1) >= argc) {
1253 fprintf(stderr, "missing argument for -pctspare\n");
1256 PctSpare = atoi(argv[++i]);
1257 BlocksSpare = 0; /* has non-zero default */
1259 } else if (!strcmp(argv[i], "-w")) {
1260 if ((i + 1) >= argc) {
1261 fprintf(stderr, "missing argument for -w\n");
1264 fiveminutes = atoi(argv[++i]);
1265 } else if (!strcmp(argv[i], "-hr")) {
1267 if ((i + 1) >= argc) {
1268 fprintf(stderr, "missing argument for -hr\n");
1271 hr = atoi(argv[++i]);
1272 if ((hr < 1) || (hr > 36)) {
1274 ("host acl refresh interval of %d hours is invalid; hours must be between 1 and 36\n\n",
1278 hostaclRefresh = hr * 60 * 60;
1279 } else if (!strcmp(argv[i], "-rxdbg"))
1281 else if (!strcmp(argv[i], "-rxdbge"))
1283 else if (!strcmp(argv[i], "-cb")) {
1285 if ((i + 1) >= argc) {
1286 fprintf(stderr, "missing argument for -cb\n");
1289 numberofcbs = atoi(argv[++i]);
1290 if ((numberofcbs < 10000) || (numberofcbs > 2147483647)) {
1292 ("number of cbs %d invalid; must be between 10000 and 2147483647\n",
1296 } else if (!strcmp(argv[i], "-busyat")) {
1298 if ((i + 1) >= argc) {
1299 fprintf(stderr, "missing argument for -busyat\n");
1302 busy_threshold = atoi(argv[++i]);
1303 if (busy_threshold < 10) {
1305 ("Busy threshold %d is too low, will compute default.\n",
1309 } else if (!strcmp(argv[i], "-nobusy"))
1311 #ifdef AFS_AIX32_ENV
1312 else if (!strcmp(argv[i], "-m")) {
1313 extern int aixlow_water;
1314 if ((i + 1) >= argc) {
1315 fprintf(stderr, "missing argument for -m\n");
1318 aixlow_water = atoi(argv[++i]);
1319 if ((aixlow_water < 0) || (aixlow_water > 30)) {
1320 printf("space reserved %d% invalid; must be between 0-30%\n",
1326 else if (!strcmp(argv[i], "-nojumbo")) {
1328 } else if (!strcmp(argv[i], "-jumbo")) {
1330 } else if (!strcmp(argv[i], "-rxbind")) {
1332 } else if (!strcmp(argv[i], "-allow-dotted-principals")) {
1333 rxkadDisableDotCheck = 1;
1334 } else if (!strcmp(argv[i], "-rxmaxmtu")) {
1335 if ((i + 1) >= argc) {
1336 fprintf(stderr, "missing argument for -rxmaxmtu\n");
1339 rxMaxMTU = atoi(argv[++i]);
1340 if ((rxMaxMTU < RX_MIN_PACKET_SIZE) ||
1341 (rxMaxMTU > RX_MAX_PACKET_DATA_SIZE)) {
1342 printf("rxMaxMTU %d%% invalid; must be between %d-%" AFS_SIZET_FMT "\n",
1343 rxMaxMTU, RX_MIN_PACKET_SIZE,
1344 RX_MAX_PACKET_DATA_SIZE);
1347 } else if (!strcmp(argv[i], "-realm")) {
1348 extern char local_realms[AFS_NUM_LREALMS][AFS_REALM_SZ];
1349 extern int num_lrealms;
1350 if ((i + 1) >= argc) {
1351 fprintf(stderr, "missing argument for -realm\n");
1354 if (strlen(argv[++i]) >= AFS_REALM_SZ) {
1356 ("-realm argument must contain fewer than %d characters.\n",
1360 if (num_lrealms == -1)
1362 if (num_lrealms >= AFS_NUM_LREALMS) {
1364 ("a maximum of %d -realm arguments can be specified.\n",
1368 strncpy(local_realms[num_lrealms++], argv[i], AFS_REALM_SZ);
1369 } else if (!strcmp(argv[i], "-udpsize")) {
1370 if ((i + 1) >= argc) {
1371 printf("You have to specify -udpsize <integer value>\n");
1374 bufSize = atoi(argv[++i]);
1375 if (bufSize < rx_GetMinUdpBufSize())
1377 ("Warning:udpsize %d is less than minimum %d; ignoring\n",
1378 bufSize, rx_GetMinUdpBufSize());
1380 udpBufSize = bufSize;
1381 } else if (!strcmp(argv[i], "-sendsize")) {
1382 if ((i + 1) >= argc) {
1383 printf("You have to specify -sendsize <integer value>\n");
1386 bufSize = atoi(argv[++i]);
1387 if (bufSize < 16384)
1389 ("Warning:sendsize %d is less than minimum %d; ignoring\n",
1392 sendBufSize = bufSize;
1393 } else if (!strcmp(argv[i], "-enable_peer_stats")) {
1394 rx_enablePeerRPCStats();
1395 } else if (!strcmp(argv[i], "-enable_process_stats")) {
1396 rx_enableProcessRPCStats();
1398 else if (strcmp(argv[i], "-auditlog") == 0) {
1399 auditFileName = argv[++i];
1401 else if (strcmp(argv[i], "-audit-interface") == 0) {
1402 char *interface = argv[++i];
1404 if (osi_audit_interface(interface)) {
1405 printf("Invalid audit interface '%s'\n", interface);
1409 #ifndef AFS_NT40_ENV
1410 else if (strcmp(argv[i], "-syslog") == 0) {
1411 /* set syslog logging flag */
1412 serverLogSyslog = 1;
1413 } else if (strncmp(argv[i], "-syslog=", 8) == 0) {
1414 serverLogSyslog = 1;
1415 serverLogSyslogFacility = atoi(argv[i] + 8);
1418 else if (strcmp(argv[i], "-mrafslogs") == 0) {
1419 /* set syslog logging flag */
1422 else if (strcmp(argv[i], "-saneacls") == 0) {
1425 else if (strcmp(argv[i], "-offline-timeout") == 0) {
1426 if (i + 1 >= argc) {
1427 printf("You have to specify -offline-timeout <integer>\n");
1430 offline_timeout = atoi(argv[++i]);
1431 #ifndef AFS_PTHREAD_ENV
1432 if (offline_timeout != -1) {
1433 printf("The only valid -offline-timeout value for the LWP "
1434 "fileserver is -1\n");
1437 #endif /* AFS_PTHREAD_ENV */
1438 if (offline_timeout < -1) {
1439 printf("Invalid -offline-timeout value %s; the only valid "
1440 "negative value is -1\n", argv[i]);
1444 else if (strcmp(argv[i], "-offline-shutdown-timeout") == 0) {
1445 if (i + 1 >= argc) {
1446 printf("You have to specify -offline-shutdown-timeout "
1450 offline_shutdown_timeout = atoi(argv[++i]);
1451 #ifndef AFS_PTHREAD_ENV
1452 if (offline_shutdown_timeout != -1) {
1453 printf("The only valid -offline-shutdown-timeout value for the "
1454 "LWP fileserver is -1\n");
1457 #endif /* AFS_PTHREAD_ENV */
1458 if (offline_shutdown_timeout < -1) {
1459 printf("Invalid -offline-timeout value %s; the only valid "
1460 "negative value is -1\n", argv[i]);
1469 printf("Only one of -L, or -S must be specified\n");
1480 numberofcbs = 20000;
1496 numberofcbs = 64000;
1505 busy_threshold = 3 * rxpackets / 2;
1507 osi_audit_file(auditFileName);
1509 lwps_max = max_fileserver_thread() - FILESERVER_HELPER_THREADS;
1510 if (lwps > lwps_max)
1523 NewParms(int initializing)
1525 static struct afs_stat sbuf;
1528 char *argv[MAXPARMS];
1531 if (!(afs_stat("/vice/file/parms", &sbuf))) {
1532 parms = (char *)malloc(sbuf.st_size);
1535 fd = afs_open("parms", O_RDONLY, 0666);
1537 ViceLog(0, ("Open for parms failed with errno = %d\n", errno));
1541 i = read(fd, parms, sbuf.st_size);
1543 if (i != sbuf.st_size) {
1545 ViceLog(0, ("Read on parms failed with errno = %d\n", errno));
1548 ("Read on parms failed; expected %ld bytes but read %d\n",
1549 (long) sbuf.st_size, i));
1555 for (i = 0; i < MAXPARMS; argv[i++] = 0);
1557 for (argc = i = 0; i < sbuf.st_size; i++) {
1558 if ((*(parms + i) != ' ') && (*(parms + i) != '\n')) {
1559 if (argv[argc] == 0)
1560 argv[argc] = (parms + i);
1562 *(parms + i) = '\0';
1563 if (argv[argc] != 0) {
1564 if (++argc == MAXPARMS)
1567 while ((*(parms + i + 1) == ' ')
1568 || (*(parms + i + 1) == '\n'))
1572 if (ParseArgs(argc, argv) == 0) {
1573 ViceLog(0, ("Change parameters to:"));
1575 ViceLog(0, ("Invalid parameter in:"));
1577 for (i = 0; i < argc; i++) {
1578 ViceLog(0, (" %s", argv[i]));
1582 } else if (!initializing)
1584 ("Received request to change parms but no parms file exists\n"));
1589 /* Miscellaneous routines */
1593 ViceLog(0, ("%s\n", msg));
1594 osi_Panic("%s\n", msg);
1605 * If this fails, it's because something major is wrong, and is not
1606 * likely to be time dependent.
1608 code = pr_Initialize(2, AFSDIR_SERVER_ETC_DIRPATH, 0);
1611 ("Couldn't initialize protection library; code=%d.\n", code));
1615 #ifdef AFS_PTHREAD_ENV
1616 osi_Assert(pthread_key_create(&viced_uclient_key, NULL) == 0);
1619 SystemId = SYSADMINID;
1620 SystemAnyUser = ANYUSERID;
1621 SystemAnyUserCPS.prlist_len = 0;
1622 SystemAnyUserCPS.prlist_val = NULL;
1623 AnonCPS.prlist_len = 0;
1624 AnonCPS.prlist_val = NULL;
1626 code = pr_GetCPS(SystemAnyUser, &SystemAnyUserCPS);
1629 ("Couldn't get CPS for AnyUser, will try again in 30 seconds; code=%d.\n",
1633 code = pr_GetCPS(ANONYMOUSID, &AnonCPS);
1636 ("Couldn't get Anonymous CPS, exiting; code=%d.\n",
1640 AnonymousID = ANONYMOUSID;
1643 #ifdef AFS_PTHREAD_ENV
1645 #else /* AFS_PTHREAD_ENV */
1647 #endif /* AFS_PTHREAD_ENV */
1651 struct rx_connection *serverconns[MAXSERVERS];
1652 struct ubik_client *cstruct;
1655 vl_Initialize(const char *confDir)
1658 afs_int32 scIndex = RX_SECIDX_NULL;
1659 struct afsconf_dir *tdir;
1660 struct rx_securityClass *sc;
1661 struct afsconf_cell info;
1663 tdir = afsconf_Open(confDir);
1666 ("Could not open configuration directory (%s).\n", confDir));
1669 code = afsconf_ClientAuth(tdir, &sc, &scIndex);
1671 ViceLog(0, ("Could not get security object for localAuth\n"));
1674 code = afsconf_GetCellInfo(tdir, NULL, AFSCONF_VLDBSERVICE, &info);
1675 if (info.numServers > MAXSERVERS) {
1677 ("vl_Initialize: info.numServers=%d (> MAXSERVERS=%d)\n",
1678 info.numServers, MAXSERVERS));
1681 for (i = 0; i < info.numServers; i++)
1683 rx_NewConnection(info.hostAddr[i].sin_addr.s_addr,
1684 info.hostAddr[i].sin_port, USER_SERVICE_ID, sc,
1686 code = ubik_ClientInit(serverconns, &cstruct);
1687 afsconf_Close(tdir);
1689 ViceLog(0, ("vl_Initialize: ubik client init failed.\n"));
1695 #define SYSIDMAGIC 0x88aabbcc
1696 #define SYSIDVERSION 1
1701 afs_int32 fd, nentries, i;
1702 struct versionStamp vsn;
1703 struct afs_stat status;
1706 if ((afs_stat(AFSDIR_SERVER_SYSID_FILEPATH, &status))
1707 || (status.st_size <= 0)) {
1708 ViceLog(0, ("%s: doesn't exist\n", AFSDIR_SERVER_SYSID_FILEPATH));
1711 if (!(fd = afs_open(AFSDIR_SERVER_SYSID_FILEPATH, O_RDONLY, 0))) {
1713 ("%s: can't open (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1717 if ((i = read(fd, (char *)&vsn, sizeof(vsn))) != sizeof(vsn)) {
1719 ("%s: Read failed (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1723 if (vsn.magic != SYSIDMAGIC) {
1725 ("%s: wrong magic %x (we support %x)\n",
1726 AFSDIR_SERVER_SYSID_FILEPATH, vsn.magic, SYSIDMAGIC));
1729 if (vsn.version != SYSIDVERSION) {
1731 ("%s: wrong version %d (we support %d)\n",
1732 AFSDIR_SERVER_SYSID_FILEPATH, vsn.version, SYSIDVERSION));
1736 read(fd, (char *)&uuid,
1737 sizeof(struct afsUUID))) != sizeof(struct afsUUID)) {
1739 ("%s: read of uuid failed (%d)\n",
1740 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1743 afs_ntohuuid(&uuid);
1746 read(fd, (char *)&nentries,
1747 sizeof(afs_int32))) != sizeof(afs_int32)) {
1749 ("%s: Read of entries failed (%d)\n",
1750 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1753 if (nentries <= 0 || nentries > ADDRSPERSITE) {
1755 ("%s: invalid num of interfaces: %d\n",
1756 AFSDIR_SERVER_SYSID_FILEPATH, nentries));
1759 if (FS_HostAddr_cnt == 0) {
1760 FS_HostAddr_cnt = nentries;
1761 for (i = 0; i < nentries; i++) {
1762 if (read(fd, (char *)&FS_HostAddrs[i], sizeof(afs_int32)) !=
1763 sizeof(afs_int32)) {
1765 ("%s: Read of addresses failed (%d)\n",
1766 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1767 FS_HostAddr_cnt = 0; /* reset it */
1773 ("%s: address list ignored (NetInfo/NetRestrict override)\n",
1774 AFSDIR_SERVER_SYSID_FILEPATH));
1781 WriteSysIdFile(void)
1784 struct versionStamp vsn;
1785 struct afs_stat status;
1788 if (!afs_stat(AFSDIR_SERVER_SYSID_FILEPATH, &status)) {
1790 * File exists; keep the old one around
1792 renamefile(AFSDIR_SERVER_SYSID_FILEPATH,
1793 AFSDIR_SERVER_OLDSYSID_FILEPATH);
1795 fd = afs_open(AFSDIR_SERVER_SYSID_FILEPATH, O_WRONLY | O_TRUNC | O_CREAT,
1799 ("%s: can't create (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1803 vsn.magic = SYSIDMAGIC;
1805 if ((i = write(fd, (char *)&vsn, sizeof(vsn))) != sizeof(vsn)) {
1807 ("%s: write failed (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1812 afs_htonuuid(&uuid);
1814 write(fd, (char *)&uuid,
1815 sizeof(struct afsUUID))) != sizeof(struct afsUUID)) {
1817 ("%s: write of uuid failed (%d)\n",
1818 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1822 write(fd, (char *)&FS_HostAddr_cnt,
1823 sizeof(afs_int32))) != sizeof(afs_int32)) {
1825 ("%s: write of # of entries failed (%d)\n",
1826 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1829 for (i = 0; i < FS_HostAddr_cnt; i++) {
1830 if (write(fd, (char *)&FS_HostAddrs[i], sizeof(afs_int32)) !=
1831 sizeof(afs_int32)) {
1833 ("%s: write of addresses failed (%d)\n",
1834 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1844 * This routine sets up the buffers for the VL_RegisterAddrs RPC. All addresses
1845 * in FS_HostAddrs[] are in NBO, while the RPC treats them as a "blob" of data
1846 * and so we need to convert each of them into HBO which is what the extra
1847 * array called FS_HostAddrs_HBO is used here.
1850 Do_VLRegisterRPC(void)
1854 afs_uint32 FS_HostAddrs_HBO[ADDRSPERSITE];
1857 for (i = 0; i < FS_HostAddr_cnt; i++)
1858 FS_HostAddrs_HBO[i] = ntohl(FS_HostAddrs[i]);
1859 addrs.bulkaddrs_len = FS_HostAddr_cnt;
1860 addrs.bulkaddrs_val = (afs_uint32 *) FS_HostAddrs_HBO;
1861 code = ubik_VL_RegisterAddrs(cstruct, 0, &FS_HostUUID, 0, &addrs);
1863 if (code == VL_MULTIPADDR) {
1865 ("VL_RegisterAddrs rpc failed; The IP address exists on a different server; repair it\n"));
1867 ("VL_RegisterAddrs rpc failed; See VLLog for details\n"));
1869 } else if (code == RXGEN_OPCODE) {
1871 ("vlserver doesn't support VL_RegisterAddrs rpc; ignored\n"));
1872 FS_registered = 2; /* So we don't have to retry in the gc daemon */
1875 ("VL_RegisterAddrs rpc failed; will retry periodically (code=%d, err=%d)\n",
1877 FS_registered = 1; /* Retry in the gc daemon */
1880 FS_registered = 2; /* So we don't have to retry in the gc daemon */
1892 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH || AFSDIR_SERVER_NETINFO_FILEPATH) {
1894 * Find addresses we are supposed to register as per the netrestrict
1895 * and netinfo files (/usr/afs/local/NetInfo and
1896 * /usr/afs/local/NetRestict)
1899 afs_int32 code = parseNetFiles(FS_HostAddrs, NULL, NULL,
1900 ADDRSPERSITE, reason,
1901 AFSDIR_SERVER_NETINFO_FILEPATH,
1902 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
1904 ViceLog(0, ("Can't register any valid addresses: %s\n", reason));
1907 FS_HostAddr_cnt = (afs_uint32) code;
1910 FS_HostAddr_cnt = rx_getAllAddr(FS_HostAddrs, ADDRSPERSITE);
1913 if (FS_HostAddr_cnt == 1 && rxBind == 1)
1914 code = FS_HostAddrs[0];
1916 code = htonl(INADDR_ANY);
1926 * If this fails, it's because something major is wrong, and is not
1927 * likely to be time dependent.
1929 code = vl_Initialize(AFSDIR_SERVER_ETC_DIRPATH);
1932 ("Couldn't initialize protection library; code=%d.\n", code));
1936 /* Read or create the sysid file and register the fileserver's
1937 * IP addresses with the vlserver.
1939 code = ReadSysIdFile();
1941 /* Need to create the file */
1942 ViceLog(0, ("Creating new SysID file\n"));
1943 if ((code = afs_uuid_create(&FS_HostUUID))) {
1944 ViceLog(0, ("Failed to create new uuid: %d\n", code));
1948 /* A good sysid file exists; inform the vlserver. If any conflicts,
1949 * we always use the latest interface available as the real truth.
1952 code = Do_VLRegisterRPC();
1957 main(int argc, char *argv[])
1961 struct rx_securityClass **securityClasses;
1962 afs_int32 numClasses;
1963 struct rx_service *tservice;
1964 #ifdef AFS_PTHREAD_ENV
1965 pthread_t serverPid;
1966 pthread_attr_t tattr;
1967 #else /* AFS_PTHREAD_ENV */
1968 PROCESS parentPid, serverPid;
1969 #endif /* AFS_PTHREAD_ENV */
1971 int minVnodesRequired; /* min size of vnode cache */
1972 #ifndef AFS_NT40_ENV
1973 struct rlimit rlim; /* max number of open file descriptors */
1978 afs_uint32 rx_bindhost;
1979 VolumePackageOptions opts;
1981 #ifdef AFS_AIX32_ENV
1982 struct sigaction nsa;
1984 sigemptyset(&nsa.sa_mask);
1985 nsa.sa_handler = SIG_DFL;
1986 nsa.sa_flags = SA_FULLDUMP;
1987 sigaction(SIGABRT, &nsa, NULL);
1988 sigaction(SIGSEGV, &nsa, NULL);
1992 /* Initialize dirpaths */
1993 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
1995 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
1997 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
2001 /* set ihandle package defaults prior to parsing args */
2004 if (ParseArgs(argc, argv)) {
2008 #ifdef AFS_PTHREAD_ENV
2009 MUTEX_INIT(&fileproc_glock_mutex, "fileproc", MUTEX_DEFAULT, 0);
2010 #endif /* AFS_PTHREAD_ENV */
2012 #ifdef AFS_SGI_VNODE_GLUE
2013 if (afs_init_kernel_config(-1) < 0) {
2015 ("Can't determine NUMA configuration, not starting fileserver.\n");
2019 confDir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
2021 fprintf(stderr, "Unable to open config directory %s\n",
2022 AFSDIR_SERVER_ETC_DIRPATH);
2028 /* Open FileLog on stdout, stderr, fd 1 and fd2 (for perror), sigh. */
2029 #ifndef AFS_NT40_ENV
2030 serverLogSyslogTag = "fileserver";
2032 OpenLog(AFSDIR_SERVER_FILELOG_FILEPATH);
2035 if (SawSpare && SawPctSpare) {
2036 ViceLog(0, ("Both -spare and -pctspare specified, exiting.\n"));
2039 LogCommandLine(argc, argv, "starting", "", "File server", FSLog);
2041 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
2042 /* initialize the pthread soft signal handler thread */
2046 /* install signal handlers for controlling the fileserver process */
2047 ResetCheckSignal(); /* set CheckSignal_Signal() sig handler */
2048 ResetCheckDescriptors(); /* set CheckDescriptors_Signal() sig handler */
2050 #if defined(AFS_SGI_ENV)
2051 /* give this guy a non-degrading priority so help busy servers */
2052 schedctl(NDPRI, 0, NDPNORMMAX);
2056 #ifndef AFS_NT40_ENV
2057 nice(-5); /* TODO: */
2060 osi_Assert(DInit(buffs) == 0);
2061 #ifdef AFS_DEMAND_ATTACH_FS
2066 if (afs_winsockInit() < 0) {
2067 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
2068 ViceLog(0, ("File server failed to intialize winsock.\n"));
2074 /* if we support more than 16 threads, then we better have the ability
2075 ** to keep open a large number of files simultaneously
2077 #if defined(AFS_AIX_ENV) && !defined(AFS_AIX42_ENV)
2078 curLimit = OPEN_MAX; /* for pre AIX 4.2 systems */
2079 #elif defined(AFS_NT40_ENV)
2080 curLimit = NT_OPEN_MAX; /* open file descriptor limit on NT */
2083 curLimit = 0; /* the number of open file descriptors */
2084 code = getrlimit(RLIMIT_NOFILE, &rlim);
2086 curLimit = rlim.rlim_cur;
2087 rlim.rlim_cur = rlim.rlim_max;
2088 code = setrlimit(RLIMIT_NOFILE, &rlim);
2090 curLimit = rlim.rlim_max;
2093 ViceLog(0, ("Failed to increase open file limit, using default\n"));
2095 #endif /* defined(AFS_AIX_ENV) && !defined(AFS_AIX42_ENV) */
2097 curLimit -= 32; /* leave a slack of 32 file descriptors */
2098 if (lwps > curLimit) {
2102 lwps = 16; /* default to a maximum of 16 threads */
2104 /* tune the ihandle fd cache accordingly */
2105 if (vol_io_params.fd_max_cachesize < curLimit)
2106 vol_io_params.fd_max_cachesize = curLimit + 1;
2109 ("The system supports a max of %d open files and we are starting %d threads (ihandle fd cache is %d)\n",
2110 curLimit, lwps, vol_io_params.fd_max_cachesize));
2112 #ifndef AFS_PTHREAD_ENV
2113 osi_Assert(LWP_InitializeProcessSupport(LWP_MAX_PRIORITY - 2, &parentPid) ==
2115 #endif /* !AFS_PTHREAD_ENV */
2117 /* Initialize volume support */
2119 V_BreakVolumeCallbacks = BreakVolumeCallBacksLater;
2122 #ifdef AFS_PTHREAD_ENV
2123 SetLogThreadNumProgram( threadNum );
2126 /* initialize libacl routines */
2127 acl_Initialize(ACL_VERSION);
2129 /* initialize RX support */
2130 #ifndef AFS_NT40_ENV
2131 rxi_syscallp = viced_syscall;
2133 rx_extraPackets = rxpackets;
2134 rx_extraQuota = 4; /* for outgoing prserver calls from R threads */
2135 rx_SetBusyThreshold(busy_threshold, VBUSY);
2136 rx_SetCallAbortThreshold(abort_threshold);
2137 rx_SetConnAbortThreshold(abort_threshold);
2139 stackSize = 128 * 1024;
2141 stackSize = lwps * 4000;
2142 if (stackSize < 32000)
2144 else if (stackSize > 44000)
2147 #if defined(AFS_HPUX_ENV) || defined(AFS_SUN_ENV) || defined(AFS_SGI51_ENV) || defined(AFS_XBSD_ENV)
2148 rx_SetStackSize(1, stackSize);
2151 rx_SetUdpBufSize(udpBufSize); /* set the UDP buffer size for receive */
2152 rx_bindhost = SetupVL();
2154 if (rx_InitHost(rx_bindhost, (int)htons(7000)) < 0) {
2155 ViceLog(0, ("Cannot initialize RX\n"));
2158 if (!rxJumbograms) {
2159 /* Don't send and don't allow 3.4 clients to send jumbograms. */
2162 if (rxMaxMTU != -1) {
2163 rx_SetMaxMTU(rxMaxMTU);
2166 rx_SetRxDeadTime(30);
2167 afsconf_SetSecurityFlags(confDir, AFSCONF_SECOPTS_ALWAYSENCRYPT);
2168 afsconf_BuildServerSecurityObjects(confDir, &securityClasses, &numClasses);
2170 tservice = rx_NewServiceHost(rx_bindhost, /* port */ 0, /* service id */
2171 1, /*service name */
2173 securityClasses, numClasses,
2174 RXAFS_ExecuteRequest);
2177 ("Failed to initialize RX, probably two servers running.\n"));
2180 if (rxkadDisableDotCheck) {
2181 rx_SetSecurityConfiguration(tservice, RXS_CONFIG_FLAGS,
2182 (void *)RXS_CONFIG_FLAGS_DISABLE_DOTCHECK);
2184 rx_SetMinProcs(tservice, 3);
2185 rx_SetMaxProcs(tservice, lwps);
2186 rx_SetCheckReach(tservice, 1);
2187 rx_SetServerIdleDeadErr(tservice, VNOSERVICE);
2190 rx_NewService(0, RX_STATS_SERVICE_ID, "rpcstats", securityClasses,
2191 numClasses, RXSTATS_ExecuteRequest);
2193 ViceLog(0, ("Failed to initialize rpc stat service.\n"));
2196 rx_SetMinProcs(tservice, 2);
2197 rx_SetMaxProcs(tservice, 4);
2200 * Enable RX hot threads, which allows the listener thread to trade
2201 * places with an idle thread and moves the context switch from listener
2202 * to worker out of the critical path.
2204 rx_EnableHotThread();
2206 /* Some rx debugging */
2207 if (rxlog || eventlog) {
2208 debugFile = afs_fopen("rx_dbg", "w");
2210 rx_debugFile = debugFile;
2212 rxevent_debugFile = debugFile;
2215 init_sys_error_to_et(); /* Set up error table translation */
2216 h_InitHostPackage(); /* set up local cellname and realmname */
2217 InitCallBack(numberofcbs);
2221 if (code && code != VL_MULTIPADDR) {
2222 ViceLog(0, ("Fatal error in library initialization, exiting!!\n"));
2227 if (code && code != -1) {
2228 ViceLog(0, ("Fatal error in protection initialization, exiting!!\n"));
2232 /* allow super users to manage RX statistics */
2233 rx_SetRxStatUserOk(fs_rxstat_userok);
2235 CV_INIT(&fsync_cond, "fsync", CV_DEFAULT, 0);
2236 MUTEX_INIT(&fsync_glock_mutex, "fsync", MUTEX_DEFAULT, 0);
2238 #if !defined(AFS_DEMAND_ATTACH_FS)
2240 * For DAFS, we do not start the Rx server threads until after
2241 * the volume package is initialized, and fileserver state is
2242 * restored. This is necessary in order to keep host and callback
2243 * package state pristine until we have a chance to restore state.
2245 * Furthermore, startup latency is much lower with dafs, so this
2246 * shouldn't pose a serious problem.
2248 rx_StartServer(0); /* now start handling requests */
2251 /* we ensure that there is enough space in the vnode buffer to satisfy
2252 ** requests from all concurrent threads.
2253 ** the maximum number of vnodes used by a single thread at any one time
2254 ** is three ( "link" uses three vnodes simultaneously, one vLarge and
2255 ** two vSmall for linking files and two vLarge and one vSmall for linking
2258 minVnodesRequired = 2 * lwps + 1;
2259 if (minVnodesRequired > nSmallVns) {
2260 nSmallVns = minVnodesRequired;
2262 ("Overriding -s command line parameter with %d\n",
2265 if (minVnodesRequired > large) {
2266 large = minVnodesRequired;
2267 ViceLog(0, ("Overriding -l command line parameter with %d\n", large));
2270 /* We now do this after getting the listener up and running, so that client
2271 * connections don't timeout (maybe) if a file server is restarted, since it
2272 * will be available "real soon now". Worry about whether we can satisfy the
2273 * calls in the volume package itself.
2275 VOptDefaults(fileServer, &opts);
2276 opts.nLargeVnodes = large;
2277 opts.nSmallVnodes = nSmallVns;
2278 opts.volcache = volcache;
2279 opts.unsafe_attach = unsafe_attach;
2280 if (offline_timeout != -1) {
2281 opts.interrupt_rxcall = rx_InterruptCall;
2282 opts.offline_timeout = offline_timeout;
2284 if (offline_shutdown_timeout == -1) {
2285 /* default to -offline-timeout, if shutdown-specific timeout is not
2287 opts.offline_shutdown_timeout = offline_timeout;
2289 opts.interrupt_rxcall = rx_InterruptCall;
2290 opts.offline_shutdown_timeout = offline_shutdown_timeout;
2293 if (VInitVolumePackage2(fileServer, &opts)) {
2295 ("Shutting down: errors encountered initializing volume package\n"));
2300 /* Install handler to catch the shutdown signal;
2301 * bosserver assumes SIGQUIT shutdown
2303 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
2304 softsig_signal(SIGQUIT, ShutDown_Signal);
2306 (void)signal(SIGQUIT, ShutDown_Signal);
2309 if (VInitAttachVolumes(fileServer)) {
2311 ("Shutting down: errors encountered initializing volume package\n"));
2316 #ifdef AFS_DEMAND_ATTACH_FS
2317 if (fs_state.options.fs_state_restore) {
2320 * restore fileserver state */
2323 rx_StartServer(0); /* now start handling requests */
2324 #endif /* AFS_DEMAND_ATTACH_FS */
2327 * We are done calling fopen/fdopen. It is safe to use a large
2328 * of the file descriptor cache.
2332 #ifdef AFS_PTHREAD_ENV
2333 ViceLog(5, ("Starting pthreads\n"));
2334 osi_Assert(pthread_attr_init(&tattr) == 0);
2335 osi_Assert(pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED) == 0);
2337 osi_Assert(pthread_create
2338 (&serverPid, &tattr, FiveMinuteCheckLWP,
2339 &fiveminutes) == 0);
2340 osi_Assert(pthread_create
2341 (&serverPid, &tattr, HostCheckLWP, &fiveminutes) == 0);
2342 osi_Assert(pthread_create
2343 (&serverPid, &tattr, FsyncCheckLWP, &fiveminutes) == 0);
2344 #else /* AFS_PTHREAD_ENV */
2345 ViceLog(5, ("Starting LWP\n"));
2346 osi_Assert(LWP_CreateProcess
2347 (FiveMinuteCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
2348 (void *)&fiveminutes, "FiveMinuteChecks",
2349 &serverPid) == LWP_SUCCESS);
2351 osi_Assert(LWP_CreateProcess
2352 (HostCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
2353 (void *)&fiveminutes, "HostCheck", &serverPid) == LWP_SUCCESS);
2354 osi_Assert(LWP_CreateProcess
2355 (FsyncCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
2356 (void *)&fiveminutes, "FsyncCheck", &serverPid) == LWP_SUCCESS);
2357 #endif /* AFS_PTHREAD_ENV */
2359 FT_GetTimeOfDay(&tp, 0);
2362 * Figure out the FileServer's name and primary address.
2364 ViceLog(0, ("Getting FileServer name...\n"));
2365 code = gethostname(FS_HostName, 64);
2367 ViceLog(0, ("gethostname() failed\n"));
2369 ViceLog(0, ("FileServer host name is '%s'\n", FS_HostName));
2371 ViceLog(0, ("Getting FileServer address...\n"));
2372 he = gethostbyname(FS_HostName);
2374 ViceLog(0, ("Can't find address for FileServer '%s'\n", FS_HostName));
2377 memcpy(&FS_HostAddr_NBO, he->h_addr, 4);
2378 (void)afs_inet_ntoa_r(FS_HostAddr_NBO, hoststr);
2379 FS_HostAddr_HBO = ntohl(FS_HostAddr_NBO);
2381 ("FileServer %s has address %s (0x%x or 0x%x in host byte order)\n",
2382 FS_HostName, hoststr, FS_HostAddr_NBO, FS_HostAddr_HBO));
2386 strftime(tbuffer, sizeof(tbuffer), "%a %b %d %T %Y",
2387 localtime_r(&t, &tm));
2388 ViceLog(0, ("File Server started %s", tbuffer));
2389 #if FS_STATS_DETAILED
2390 afs_FullPerfStats.det.epoch.tv_sec = StartTime = tp.tv_sec;
2392 #ifdef AFS_PTHREAD_ENV
2394 sleep(1000); /* long time */
2396 #else /* AFS_PTHREAD_ENV */
2397 osi_Assert(LWP_WaitProcess(&parentPid) == LWP_SUCCESS);
2398 #endif /* AFS_PTHREAD_ENV */