2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
9 * Portions Copyright (c) 2006 Sine Nomine Associates
12 /* viced.c - File Server main loop */
16 /* Function - This routine has the initialization code for */
19 /* ********************************************************************** */
21 #include <afsconfig.h>
22 #include <afs/param.h>
24 #include <afs/procmgmt.h>
31 #include <sys/types.h>
32 #include <afs/procmgmt.h> /* signal(), kill(), wait(), etc. */
41 #include <WINNT/afsevent.h>
44 #include <netinet/in.h>
46 #include <unistd.h> /* sysconf() */
50 #endif /* ITIMER_REAL */
51 #include <sys/resource.h>
52 #endif /* AFS_NT40_ENV */
57 #include <afs/afs_assert.h>
60 #include <afs/ptclient.h>
61 #include <afs/afsint.h>
62 #include <afs/vldbint.h>
63 #include <afs/errors.h>
64 #include <afs/ihandle.h>
65 #include <afs/vnode.h>
66 #include <afs/volume.h>
68 #include <afs/cellconfig.h>
70 #include <afs/prs_fs.h>
72 #include <rx/rxstat.h>
74 #include <afs/afs_args.h>
75 #include <afs/vlserver.h>
76 #include <afs/afsutil.h>
77 #include <afs/fileutil.h>
78 #include <afs/ptuser.h>
79 #include <afs/audit.h>
80 #include <afs/partition.h>
83 #include <afs/netutils.h>
85 #include "viced_prototypes.h"
88 #ifdef AFS_PTHREAD_ENV
89 #include <afs/softsig.h>
91 #if defined(AFS_SGI_ENV)
92 #include "sys/schedctl.h"
95 #include <rx/rx_globals.h>
98 #define afs_stat stat64
99 #define afs_fstat fstat64
100 #define afs_open open64
101 #define afs_fopen fopen64
102 #else /* !O_LARGEFILE */
103 #define afs_stat stat
104 #define afs_fstat fstat
105 #define afs_open open
106 #define afs_fopen fopen
107 #endif /* !O_LARGEFILE */
111 void *ShutDown(void *);
112 static void ClearXStatValues(void);
113 static void NewParms(int);
114 static void PrintCounters(void);
115 static void ResetCheckDescriptors(void);
116 static void ResetCheckSignal(void);
117 static void *CheckSignal(void *);
119 static afs_int32 Do_VLRegisterRPC(void);
121 int eventlog = 0, rxlog = 0;
124 #ifdef AFS_PTHREAD_ENV
125 pthread_mutex_t fsync_glock_mutex;
126 pthread_cond_t fsync_cond;
129 #endif /* AFS_PTHREAD_ENV */
132 #define NT_OPEN_MAX 1024 /* This is an arbitrary no. we came up with for
133 * now. We hope this will be replaced by a more
134 * intelligent estimate later. */
137 int SystemId; /* ViceID of "Administrators" */
138 int SystemAnyUser; /* Viceid of "System:AnyUser" */
139 prlist SystemAnyUserCPS; /* CPS for "system:AnyUser */
140 int AnonymousID = 0; /* ViceId of "Anonymous" */
141 prlist AnonCPS; /* CPS for "Anonymous" */
143 struct afsconf_dir *confDir; /* Configuration dir object */
145 int restartMode = RESTART_ORDINARY;
148 * Home for the performance statistics.
150 struct afs_PerfStats afs_perfstats;
153 extern int Statistics;
161 int rxJumbograms = 0; /* default is to not send and receive jumbograms. */
162 int rxBind = 0; /* don't bind */
163 int rxkadDisableDotCheck = 0; /* disable check for dot in principal name */
165 afs_int32 implicitAdminRights = PRSFS_LOOKUP; /* The ADMINISTER right is
167 afs_int32 readonlyServer = 0;
170 int stackSize = 24000;
171 int fiveminutes = 300; /* 5 minutes. Change this for debugging only */
172 int CurrentConnections = 0;
173 int hostaclRefresh = 7200; /* refresh host clients' acls every 2 hrs */
174 #if defined(AFS_SGI_ENV)
180 * seconds to wait until forcing a panic during ShutDownAndCore(PANIC)
181 * in case we get stuck.
183 #ifdef AFS_DEMAND_ATTACH_FS
184 static int panic_timeout = 2 * 60;
186 static int panic_timeout = 30 * 60;
189 int rxpackets = 150; /* 100 */
190 int nSmallVns = 400; /* 200 */
191 int large = 400; /* 200 */
192 int volcache = 400; /* 400 */
193 int numberofcbs = 60000; /* 60000 */
194 int lwps = 9; /* 6 */
195 int buffs = 90; /* 70 */
196 int novbc = 0; /* Enable Volume Break calls */
197 int busy_threshold = 600;
198 int abort_threshold = 10;
199 int udpBufSize = 0; /* UDP buffer size for receive */
200 int sendBufSize = 16384; /* send buffer size */
201 int saneacls = 0; /* Sane ACLs Flag */
202 static int unsafe_attach = 0; /* avoid inUse check on vol attach? */
203 static int offline_timeout = -1; /* -offline-timeout option */
204 static int offline_shutdown_timeout = -1; /* -offline-shutdown-timeout option */
208 #ifdef AFS_PTHREAD_ENV
209 pthread_key_t viced_uclient_key;
212 #ifdef AFS_PTHREAD_ENV
213 pthread_key_t viced_uclient_key;
217 * FileServer's name and IP address, both network byte order and
220 #define ADDRSPERSITE 16 /* Same global is in rx/rx_user.c */
222 char FS_HostName[128] = "localhost";
223 afs_uint32 FS_HostAddr_NBO;
224 afs_uint32 FS_HostAddr_HBO;
225 afs_uint32 FS_HostAddrs[ADDRSPERSITE], FS_HostAddr_cnt = 0, FS_registered = 0;
226 /* All addresses in FS_HostAddrs are in NBO */
229 static void FlagMsg(void);
231 #ifdef AFS_DEMAND_ATTACH_FS
234 * fileserver mode support
236 * during fileserver shutdown, we have to track the graceful shutdown of
237 * certain background threads before we are allowed to dump state to
241 #if !defined(PTHREAD_RWLOCK_INITIALIZER) && defined(AFS_DARWIN80_ENV)
242 #define PTHREAD_RWLOCK_INITIALIZER {0x2DA8B3B4, {0}}
246 struct fs_state fs_state =
253 PTHREAD_COND_INITIALIZER,
254 PTHREAD_RWLOCK_INITIALIZER
256 #else /* AFS_NT40_ENV */
257 struct fs_state fs_state;
259 static int fs_stateInit(void)
261 fs_state.mode = FS_MODE_NORMAL;
262 fs_state.FiveMinuteLWP_tranquil = 0;
263 fs_state.HostCheckLWP_tranquil = 0;
264 fs_state.FsyncCheckLWP_tranquil = 0;
265 fs_state.salvsync_fatal_error = 0;
267 fs_state.options.fs_state_save = 1;
268 fs_state.options.fs_state_restore = 1;
269 fs_state.options.fs_state_verify_before_save = 1;
270 fs_state.options.fs_state_verify_after_restore = 1;
272 CV_INIT(&fs_state.worker_done_cv, "worker done", CV_DEFAULT, 0);
273 osi_Assert(pthread_rwlock_init(&fs_state.state_lock, NULL) == 0);
275 #endif /* AFS_NT40_ENV */
276 #endif /* AFS_DEMAND_ATTACH_FS */
279 * Home for the performance statistics.
284 CheckDescriptors(void *unused)
287 struct afs_stat status;
288 int tsize = getdtablesize();
290 for (i = 0; i < tsize; i++) {
291 if (afs_fstat(i, &status) != -1) {
292 printf("%d: dev %x, inode %u, length %u, type/mode %x\n", i,
293 (unsigned int) status.st_dev,
294 (unsigned int) status.st_ino,
295 (unsigned int) status.st_size,
300 ResetCheckDescriptors();
303 } /*CheckDescriptors */
306 #ifdef AFS_PTHREAD_ENV
308 CheckSignal_Signal(int x)
314 ShutDown_Signal(int x)
320 CheckDescriptors_Signal(int x)
322 CheckDescriptors(NULL);
324 #else /* AFS_PTHREAD_ENV */
326 CheckSignal_Signal(int x)
328 IOMGR_SoftSig(CheckSignal, 0);
332 ShutDown_Signal(int x)
334 IOMGR_SoftSig(ShutDown, 0);
338 CheckDescriptors_Signal(int x)
340 IOMGR_SoftSig(CheckDescriptors, 0);
342 #endif /* AFS_PTHREAD_ENV */
344 /* check whether caller is authorized to manage RX statistics */
346 fs_rxstat_userok(struct rx_call *call)
348 return afsconf_SuperUser(confDir, call, NULL);
352 ResetCheckSignal(void)
356 #if defined(AFS_HPUX_ENV)
359 #if defined(AFS_NT40_ENV)
366 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
367 softsig_signal(signo, CheckSignal_Signal);
369 signal(signo, CheckSignal_Signal);
374 ResetCheckDescriptors(void)
377 #if defined(AFS_PTHREAD_ENV)
378 softsig_signal(SIGTERM, CheckDescriptors_Signal);
380 (void)signal(SIGTERM, CheckDescriptors_Signal);
385 #if defined(AFS_PTHREAD_ENV)
389 return (intptr_t)pthread_getspecific(rx_thread_id_key);
395 viced_syscall(afs_uint32 a3, afs_uint32 a4, void *a5)
398 #ifndef AFS_LINUX20_ENV
401 old = (void (*)(int))signal(SIGSYS, SIG_IGN);
403 rcode = syscall(AFS_SYSCALL, 28 /* AFSCALL_CALL */ , a3, a4, a5);
404 #ifndef AFS_LINUX20_ENV
412 #if !defined(AFS_NT40_ENV)
413 #include "AFS_component_version_number.c"
414 #endif /* !AFS_NT40_ENV */
416 #define MAXADMINNAME 64
417 char adminName[MAXADMINNAME];
423 struct afs_stat status;
425 if ((afs_stat("/AdminName", &status)) || /* if file does not exist */
426 (status.st_size <= 0) || /* or it is too short */
427 (status.st_size >= (MAXADMINNAME)) || /* or it is too long */
428 !(fd = afs_open("/AdminName", O_RDONLY, 0))) { /* or the open fails */
429 strcpy(adminName, "System:Administrators"); /* use the default name */
431 (void)read(fd, adminName, status.st_size); /* use name from the file */
434 close(fd); /* close fd if it was opened */
436 } /*CheckAdminName */
442 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
443 /* set our 'thread-id' so that the host hold table works */
444 pthread_setspecific(rx_thread_id_key,
445 (void *)(intptr_t)rx_NewThreadId());
447 ("Set thread id %p for '%s'\n",
448 pthread_getspecific(rx_thread_id_key), s));
452 /* This LWP does things roughly every 5 minutes */
454 FiveMinuteCheckLWP(void *unused)
459 ViceLog(1, ("Starting five minute check process\n"));
460 setThreadId("FiveMinuteCheckLWP");
462 #ifdef AFS_DEMAND_ATTACH_FS
464 while (fs_state.mode == FS_MODE_NORMAL) {
465 fs_state.FiveMinuteLWP_tranquil = 1;
471 #ifdef AFS_PTHREAD_ENV
473 #else /* AFS_PTHREAD_ENV */
474 IOMGR_Sleep(fiveminutes);
475 #endif /* AFS_PTHREAD_ENV */
477 #ifdef AFS_DEMAND_ATTACH_FS
479 if (fs_state.mode != FS_MODE_NORMAL) {
482 fs_state.FiveMinuteLWP_tranquil = 0;
486 /* close the log so it can be removed */
487 ReOpenLog(AFSDIR_SERVER_FILELOG_FILEPATH); /* don't trunc, just append */
488 ViceLog(2, ("Cleaning up timed out callbacks\n"));
489 if (CleanupTimedOutCallBacks())
490 ViceLog(5, ("Timed out callbacks deleted\n"));
491 ViceLog(2, ("Set disk usage statistics\n"));
493 if (FS_registered == 1)
495 /* Force wakeup in case we missed something; pthreads does timedwait */
496 #ifndef AFS_PTHREAD_ENV
497 LWP_NoYieldSignal(fsync_wait);
499 if (printBanner && (++msg & 1)) { /* Every 10 minutes */
500 time_t now = FT_ApproxTime();
502 ("File server is running at %s\n",
503 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
505 #ifdef AFS_DEMAND_ATTACH_FS
509 #ifdef AFS_DEMAND_ATTACH_FS
510 fs_state.FiveMinuteLWP_tranquil = 1;
512 CV_BROADCAST(&fs_state.worker_done_cv);
517 } /*FiveMinuteCheckLWP */
520 /* This LWP does host checks every 5 minutes: it should not be used for
521 * other 5 minute activities because it may be delayed by timeouts when
522 * it probes the workstations
526 HostCheckLWP(void *unused)
528 ViceLog(1, ("Starting Host check process\n"));
529 setThreadId("HostCheckLWP");
530 #ifdef AFS_DEMAND_ATTACH_FS
532 while (fs_state.mode == FS_MODE_NORMAL) {
533 fs_state.HostCheckLWP_tranquil = 1;
539 #ifdef AFS_PTHREAD_ENV
541 #else /* AFS_PTHREAD_ENV */
542 IOMGR_Sleep(fiveminutes);
543 #endif /* AFS_PTHREAD_ENV */
545 #ifdef AFS_DEMAND_ATTACH_FS
547 if (fs_state.mode != FS_MODE_NORMAL) {
550 fs_state.HostCheckLWP_tranquil = 0;
554 ViceLog(2, ("Checking for dead venii & clients\n"));
557 #ifdef AFS_DEMAND_ATTACH_FS
561 #ifdef AFS_DEMAND_ATTACH_FS
562 fs_state.HostCheckLWP_tranquil = 1;
564 CV_BROADCAST(&fs_state.worker_done_cv);
571 /* This LWP does fsync checks every 5 minutes: it should not be used for
572 * other 5 minute activities because it may be delayed by timeouts when
573 * it probes the workstations
576 FsyncCheckLWP(void *unused)
579 #ifdef AFS_PTHREAD_ENV
580 struct timespec fsync_next;
582 ViceLog(1, ("Starting fsync check process\n"));
584 setThreadId("FsyncCheckLWP");
586 #ifdef AFS_DEMAND_ATTACH_FS
588 while (fs_state.mode == FS_MODE_NORMAL) {
589 fs_state.FsyncCheckLWP_tranquil = 1;
595 #ifdef AFS_PTHREAD_ENV
596 /* rounding is fine */
597 fsync_next.tv_nsec = 0;
598 fsync_next.tv_sec = time(0) + fiveminutes;
600 code = CV_TIMEDWAIT(&fsync_cond, &fsync_glock_mutex,
602 if (code != 0 && code != ETIMEDOUT)
603 ViceLog(0, ("pthread_cond_timedwait returned %d\n", code));
604 #else /* AFS_PTHREAD_ENV */
605 if ((code = LWP_WaitProcess(fsync_wait)) != LWP_SUCCESS)
606 ViceLog(0, ("LWP_WaitProcess returned %d\n", code));
607 #endif /* AFS_PTHREAD_ENV */
610 #ifdef AFS_DEMAND_ATTACH_FS
612 if (fs_state.mode != FS_MODE_NORMAL) {
615 fs_state.FsyncCheckLWP_tranquil = 0;
617 #endif /* AFS_DEMAND_ATTACH_FS */
619 ViceLog(2, ("Checking for fsync events\n"));
621 code = BreakLaterCallBacks();
623 #ifdef AFS_DEMAND_ATTACH_FS
627 #ifdef AFS_DEMAND_ATTACH_FS
628 fs_state.FsyncCheckLWP_tranquil = 1;
630 CV_BROADCAST(&fs_state.worker_done_cv);
633 #endif /* AFS_DEMAND_ATTACH_FS */
637 /*------------------------------------------------------------------------
638 * PRIVATE ClearXStatValues
641 * Initialize all of the values collected via the xstat
651 * Must be called during File Server initialization.
655 *------------------------------------------------------------------------*/
658 ClearXStatValues(void)
659 { /*ClearXStatValues */
661 struct fs_stats_opTimingData *opTimeP; /*Ptr to timing struct */
662 struct fs_stats_xferData *opXferP; /*Ptr to xfer struct */
663 int i; /*Loop counter */
666 * Zero all xstat-related structures.
668 memset((&afs_perfstats), 0, sizeof(struct afs_PerfStats));
669 #if FS_STATS_DETAILED
670 memset((&afs_FullPerfStats), 0,
671 sizeof(struct fs_stats_FullPerfStats));
674 * That's not enough. We have to set reasonable minima for
675 * time and xfer values in the detailed stats.
677 opTimeP = &(afs_FullPerfStats.det.rpcOpTimes[0]);
678 for (i = 0; i < FS_STATS_NUM_RPC_OPS; i++, opTimeP++)
679 opTimeP->minTime.tv_sec = 999999;
681 opXferP = &(afs_FullPerfStats.det.xferOpTimes[0]);
682 for (i = 0; i < FS_STATS_NUM_XFER_OPS; i++, opXferP++) {
683 opXferP->minTime.tv_sec = 999999;
684 opXferP->minBytes = 999999999;
688 * There's more. We have to set our unique system identifier, as
689 * declared in param.h. If such a thing is not defined, we bitch
690 * and declare ourselves to be an unknown system type.
693 afs_perfstats.sysname_ID = SYS_NAME_ID;
696 ViceLog(0, ("Sys name ID constant not defined in param.h!!\n"));
697 ViceLog(0, ("[Choosing ``undefined'' sys name ID.\n"));
699 afs_perfstats.sysname_ID = SYS_NAME_ID_UNDEFINED;
700 #endif /* SYS_NAME_ID */
703 } /*ClearXStatValues */
705 int CopyOnWrite_calls = 0, CopyOnWrite_off0 = 0, CopyOnWrite_size0 = 0;
706 afs_fsize_t CopyOnWrite_maxsize = 0;
711 int dirbuff, dircall, dirio;
713 int workstations, activeworkstations, delworkstations;
716 #ifdef AFS_DEMAND_ATTACH_FS
720 FT_GetTimeOfDay(&tpl, 0);
723 ("Vice was last started at %s\n",
724 afs_ctime(&StartTime, tbuffer, sizeof(tbuffer))));
726 #ifdef AFS_DEMAND_ATTACH_FS
727 if (LogLevel >= 125) {
728 stats_flags = VOL_STATS_PER_CHAIN2;
729 } else if (LogLevel >= 25) {
730 stats_flags = VOL_STATS_PER_CHAIN;
732 VPrintExtendedCacheStats(stats_flags);
736 DStat(&dirbuff, &dircall, &dirio);
738 ("With %d directory buffers; %d reads resulted in %d read I/Os\n",
739 dirbuff, dircall, dirio));
740 rx_PrintStats(stderr);
741 audit_PrintStats(stderr);
743 PrintCallBackStats();
745 processSize = -1; /* TODO: */
747 processSize = (int)((long)sbrk(0) >> 10);
750 ("There are %d connections, process size %d\n",
751 CurrentConnections, processSize));
752 h_GetWorkStats(&workstations, &activeworkstations, &delworkstations,
753 tpl.tv_sec - 15 * 60);
755 ("There are %d workstations, %d are active (req in < 15 mins), %d marked \"down\"\n",
756 workstations, activeworkstations, delworkstations));
757 ViceLog(0, ("CopyOnWrite: calls %d off0 %d size0 %d maxsize 0x%llx\n",
758 CopyOnWrite_calls, CopyOnWrite_off0, CopyOnWrite_size0, CopyOnWrite_maxsize));
767 CheckSignal(void *unused)
769 if (FS_registered > 0) {
771 * We have proper ip addresses; tell the vlserver what we got; the following
772 * routine will do the proper reporting for us
785 ShutdownWatchdogLWP(void *unused)
787 sleep(panic_timeout);
788 ViceLog(0, ("ShutdownWatchdogLWP: Failed to shutdown and panic "
789 "within %d seconds; forcing panic\n", panic_timeout));
790 osi_Panic("ShutdownWatchdogLWP: Failed to shutdown and panic "
791 "within %d seconds; forcing panic\n", panic_timeout);
796 ShutDownAndCore(int dopanic)
798 time_t now = time(0);
802 #ifdef AFS_PTHREAD_ENV
803 pthread_t watchdogPid;
804 pthread_attr_t tattr;
805 osi_Assert(pthread_attr_init(&tattr) == 0);
806 osi_Assert(pthread_create(&watchdogPid, &tattr, ShutdownWatchdogLWP, NULL) == 0);
809 osi_Assert(LWP_CreateProcess
810 (ShutdownWatchdogLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
811 NULL, "ShutdownWatchdog", &watchdogPid) == LWP_SUCCESS);
815 /* do not allows new reqests to be served from now on, all new requests
816 * are returned with an error code of RX_RESTARTING ( transient failure ) */
817 rx_SetRxTranquil(); /* dhruba */
821 #ifdef AFS_DEMAND_ATTACH_FS
823 if (fs_state.mode == FS_MODE_SHUTDOWN) {
824 /* it is possible for at least fs_stateSave() (called below) to call
825 * ShutDownAndCore if there's host list corruption; prevent
826 * deinitializing some stuff twice */
827 ViceLog(0, ("ShutDownAndCore called during shutdown? Skipping volume "
828 "and host package shutdown\n"));
832 fs_state.mode = FS_MODE_SHUTDOWN;
837 ("Shutting down file server at %s",
838 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
840 ViceLog(0, ("ABNORMAL SHUTDOWN, see core file.\n"));
845 /* shut down volume package */
848 #ifdef AFS_DEMAND_ATTACH_FS
849 if (fs_state.options.fs_state_save) {
852 * save fileserver state to disk */
855 ViceLog(0, ("Not saving fileserver state; abnormal shutdown\n"));
858 /* make sure background threads have finished all of their asynchronous
859 * work on host and callback structures */
861 while (!fs_state.FiveMinuteLWP_tranquil ||
862 !fs_state.HostCheckLWP_tranquil ||
863 !fs_state.FsyncCheckLWP_tranquil) {
866 ViceLog(0, ("waiting for background host/callback threads to quiesce before saving fileserver state...\n"));
867 CV_WAIT(&fs_state.worker_done_cv, &fileproc_glock_mutex);
873 /* ok. it should now be fairly safe. let's do the state dump */
879 #endif /* AFS_DEMAND_ATTACH_FS */
882 rx_PrintStats(debugFile);
888 ("File server has terminated abnormally at %s\n",
889 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
892 ("File server has terminated normally at %s\n",
893 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
896 if (dopanic) /* XXX pass in file and line? */
897 osi_Panic("Panic requested\n");
903 ShutDown(void *unused)
904 { /* backward compatibility */
905 ShutDownAndCore(DONTPANIC);
913 /* default supports help flag */
915 fputs("Usage: fileserver ", stdout);
916 fputs("[-auditlog <log path>] ", stdout);
917 fputs("[-audit-interface <file|sysvmq> (default is file)] ", stdout);
918 fputs("[-d <debug level>] ", stdout);
919 fputs("[-p <number of processes>] ", stdout);
920 fputs("[-spare <number of spare blocks>] ", stdout);
921 fputs("[-pctspare <percentage spare>] ", stdout);
922 fputs("[-b <buffers>] ", stdout);
923 fputs("[-l <large vnodes>] ", stdout);
924 fputs("[-s <small vnodes>] ", stdout);
925 fputs("[-vc <volume cachesize>] ", stdout);
926 fputs("[-w <call back wait interval>] ", stdout);
927 fputs("[-cb <number of call backs>] ", stdout);
928 fputs("[-banner (print banner every 10 minutes)] ", stdout);
929 fputs("[-novbc (whole volume cbs disabled)] ", stdout);
930 fputs("[-implicit <admin mode bits: rlidwka>] ", stdout);
931 fputs("[-readonly (read-only file server)] ", stdout);
932 fputs("[-hr <number of hours between refreshing the host cps>] ", stdout);
933 fputs("[-busyat <redirect clients when queue > n>] ", stdout);
934 fputs("[-nobusy <no VBUSY before a volume is attached>] ", stdout);
935 fputs("[-rxpck <number of rx extra packets>] ", stdout);
936 fputs("[-rxdbg (enable rx debugging)] ", stdout);
937 fputs("[-rxdbge (enable rxevent debugging)] ", stdout);
938 fputs("[-rxmaxmtu <bytes>] ", stdout);
939 fputs("[-rxbind (bind the Rx socket to one address)] ", stdout);
940 fputs("[-allow-dotted-principals (disable the rxkad principal name dot check)] ", stdout);
941 fputs("[-vhandle-setaside (fds reserved for non-cache io [default 128])] ", stdout);
942 fputs("[-vhandle-max-cachesize (max open files [default 128])] ", stdout);
943 fputs("[-vhandle-initial-cachesize (fds reserved for cache io [default 128])] ", stdout);
944 #ifdef AFS_DEMAND_ATTACH_FS
945 fputs("[-fs-state-dont-save (disable state save during shutdown)] ", stdout);
946 fputs("[-fs-state-dont-restore (disable state restore during startup)] ", stdout);
947 fputs("[-fs-state-verify <none|save|restore|both> (default is both)] ", stdout);
948 fputs("[-vattachpar <max number of volume attach/shutdown threads> (default is 1)] ", stdout);
949 fputs("[-vhashsize <log(2) of number of volume hash buckets> (default is 8)] ", stdout);
950 fputs("[-vlrudisable (disable VLRU functionality)] ", stdout);
951 fputs("[-vlruthresh <minutes before unused volumes become eligible for soft detach> (default is 2 hours)] ", stdout);
952 fputs("[-vlruinterval <seconds between VLRU scans> (default is 2 minutes)] ", stdout);
953 fputs("[-vlrumax <max volumes to soft detach in one VLRU scan> (default is 8)] ", stdout);
954 fputs("[-unsafe-nosalvage (bypass volume inUse safety check on attach, bypassing salvage)] ", stdout);
955 #elif AFS_PTHREAD_ENV
956 fputs("[-vattachpar <number of volume attach threads> (default is 1)] ", stdout);
959 fputs("[-m <min percentage spare in partition>] ", stdout);
961 #if defined(AFS_SGI_ENV)
962 fputs("[-lock (keep fileserver from swapping)] ", stdout);
964 fputs("[-L (large server conf)] ", stdout);
965 fputs("[-S (small server conf)] ", stdout);
966 fputs("[-k <stack size>] ", stdout);
967 fputs("[-realm <Kerberos realm name>] ", stdout);
968 fputs("[-udpsize <size of socket buffer in bytes>] ", stdout);
969 fputs("[-sendsize <size of send buffer in bytes>] ", stdout);
970 fputs("[-abortthreshold <abort threshold>] ", stdout);
971 fputs("[-nojumbo (disable jumbogram network packets - deprecated)] ", stdout);
972 fputs("[-jumbo (enable jumbogram network packets)] ", stdout);
973 fputs("[-offline-timeout <client RX timeout for offlining volumes>]", stdout);
974 fputs("[-offline-shutdown-timeout <RX timeout for offlining volumes during shutdown>]", stdout);
975 /* fputs("[-enable_peer_stats] ", stdout); */
976 /* fputs("[-enable_process_stats] ", stdout); */
977 fputs("[-help]\n", stdout);
979 ViceLog(0, ("%s", buffer));
988 ParseRights(char *arights)
994 if (!arights || !strcmp(arights, "")) {
995 printf("Missing list of mode bits on -implicit option\n");
998 if (!strcmp(arights, "none"))
1000 else if (!strcmp(arights, "read"))
1001 mode = PRSFS_READ | PRSFS_LOOKUP;
1002 else if (!strcmp(arights, "write"))
1004 PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
1005 PRSFS_WRITE | PRSFS_LOCK;
1006 else if (!strcmp(arights, "all"))
1008 PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
1009 PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER;
1011 len = strlen(arights);
1012 for (i = 0; i < len; i++) {
1017 mode |= PRSFS_LOOKUP;
1019 mode |= PRSFS_INSERT;
1021 mode |= PRSFS_DELETE;
1023 mode |= PRSFS_WRITE;
1027 mode |= PRSFS_ADMINISTER;
1045 printf("Illegal -implicit rights character '%c'.\n", tc);
1054 * Limit MAX_FILESERVER_THREAD by the system limit on the number of
1055 * pthreads (sysconf(_SC_THREAD_THREADS_MAX)), if applicable and
1058 * AIX: sysconf() limit is real
1059 * HP-UX: sysconf() limit is real
1060 * IRIX: sysconf() limit is apparently NOT real -- too small
1061 * DUX: sysconf() limit is apparently NOT real -- too big
1062 * Linux: sysconf() limit is apparently NOT real -- too big
1063 * Solaris: no sysconf() limit
1066 max_fileserver_thread(void)
1068 #if defined(AFS_PTHREAD_ENV)
1069 #if defined(AFS_AIX_ENV) || defined(AFS_HPUX_ENV)
1072 ans = sysconf(_SC_THREAD_THREADS_MAX);
1073 if (0 < ans && ans < MAX_FILESERVER_THREAD)
1076 #endif /* defined(AFS_PTHREAD_ENV) */
1077 return MAX_FILESERVER_THREAD;
1080 /* from ihandle.c */
1081 extern ih_init_params vol_io_params;
1084 ParseArgs(int argc, char *argv[])
1086 int SawL = 0, SawS = 0, SawVC = 0;
1087 int Sawrxpck = 0, Sawsmall = 0, Sawlarge = 0, Sawcbs = 0, Sawlwps =
1091 int bufSize = 0; /* temp variable to read in udp socket buf size */
1092 char *auditFileName = NULL;
1094 for (i = 1; i < argc; i++) {
1095 if (!strcmp(argv[i], "-d")) {
1096 if ((i + 1) >= argc) {
1097 fprintf(stderr, "missing argument for -d\n");
1100 debuglevel = atoi(argv[++i]);
1101 LogLevel = debuglevel;
1102 } else if (!strcmp(argv[i], "-banner")) {
1104 } else if (!strcmp(argv[i], "-implicit")) {
1105 if ((i + 1) >= argc) {
1106 fprintf(stderr, "missing argument for -implicit\n");
1109 implicitAdminRights = ParseRights(argv[++i]);
1110 if (implicitAdminRights < 0)
1111 return implicitAdminRights;
1112 } else if (!strcmp(argv[i], "-readonly")) {
1114 } else if (!strcmp(argv[i], "-L")) {
1116 } else if (!strcmp(argv[i], "-S")) {
1118 } else if (!strcmp(argv[i], "-p")) {
1120 max_fileserver_thread() - FILESERVER_HELPER_THREADS;
1122 if ((i + 1) >= argc) {
1123 fprintf(stderr, "missing argument for -p\n");
1126 lwps = atoi(argv[++i]);
1127 if (lwps > lwps_max)
1131 } else if (!strcmp(argv[i], "-b")) {
1133 if ((i + 1) >= argc) {
1134 fprintf(stderr, "missing argument for -b\n");
1137 buffs = atoi(argv[++i]);
1138 } else if (!strcmp(argv[i], "-l")) {
1140 if ((i + 1) >= argc) {
1141 fprintf(stderr, "missing argument for -l\n");
1144 large = atoi(argv[++i]);
1145 } else if (!strcmp(argv[i], "-vc")) {
1147 if ((i + 1) >= argc) {
1148 fprintf(stderr, "missing argument for -vc\n");
1151 volcache = atoi(argv[++i]);
1152 } else if (!strcmp(argv[i], "-novbc")) {
1154 } else if (!strcmp(argv[i], "-rxpck")) {
1156 if ((i + 1) >= argc) {
1157 fprintf(stderr, "missing argument for -rxpck\n");
1160 rxpackets = atoi(argv[++i]);
1161 #ifdef AFS_PTHREAD_ENV
1162 } else if (!strcmp(argv[i], "-vattachpar")) {
1163 if ((i + 1) >= argc) {
1164 fprintf(stderr, "missing argument for %s\n", argv[i]);
1167 vol_attach_threads = atoi(argv[++i]);
1168 #endif /* AFS_PTHREAD_ENV */
1169 } else if (!strcmp(argv[i], "-vhandle-setaside")) {
1170 if ((i + 1) >= argc) {
1171 fprintf(stderr, "missing argument for %s\n", argv[i]);
1174 vol_io_params.fd_handle_setaside = atoi(argv[++i]);
1175 } else if (!strcmp(argv[i], "-vhandle-max-cachesize")) {
1176 if ((i + 1) >= argc) {
1177 fprintf(stderr, "missing argument for %s\n", argv[i]);
1180 vol_io_params.fd_max_cachesize = atoi(argv[++i]);
1181 } else if (!strcmp(argv[i], "-vhandle-initial-cachesize")) {
1182 if ((i + 1) >= argc) {
1183 fprintf(stderr, "missing argument for %s\n", argv[i]);
1186 vol_io_params.fd_initial_cachesize = atoi(argv[++i]);
1187 #ifdef AFS_DEMAND_ATTACH_FS
1188 } else if (!strcmp(argv[i], "-fs-state-dont-save")) {
1189 fs_state.options.fs_state_save = 0;
1190 } else if (!strcmp(argv[i], "-fs-state-dont-restore")) {
1191 fs_state.options.fs_state_restore = 0;
1192 } else if (!strcmp(argv[i], "-fs-state-verify")) {
1193 if ((i + 1) >= argc) {
1194 fprintf(stderr, "missing argument for %s\n", argv[i]);
1198 if (!strcmp(argv[i], "none")) {
1199 fs_state.options.fs_state_verify_before_save = 0;
1200 fs_state.options.fs_state_verify_after_restore = 0;
1201 } else if (!strcmp(argv[i], "save")) {
1202 fs_state.options.fs_state_verify_after_restore = 0;
1203 } else if (!strcmp(argv[i], "restore")) {
1204 fs_state.options.fs_state_verify_before_save = 0;
1205 } else if (!strcmp(argv[i], "both")) {
1208 fprintf(stderr, "invalid argument for %s\n", argv[i-1]);
1211 } else if (!strcmp(argv[i], "-vhashsize")) {
1213 if ((i + 1) >= argc) {
1214 fprintf(stderr, "missing argument for %s\n", argv[i]);
1217 hashsize = atoi(argv[++i]);
1218 if (VSetVolHashSize(hashsize)) {
1219 fprintf(stderr, "specified -vhashsize (%s) is invalid or out "
1220 "of range\n", argv[i]);
1223 } else if (!strcmp(argv[i], "-vlrudisable")) {
1224 VLRU_SetOptions(VLRU_SET_ENABLED, 0);
1225 } else if (!strcmp(argv[i], "-vlruthresh")) {
1226 if ((i + 1) >= argc) {
1227 fprintf(stderr, "missing argument for %s\n", argv[i]);
1230 VLRU_SetOptions(VLRU_SET_THRESH, 60*atoi(argv[++i]));
1231 } else if (!strcmp(argv[i], "-vlruinterval")) {
1232 if ((i + 1) >= argc) {
1233 fprintf(stderr, "missing argument for %s\n", argv[i]);
1236 VLRU_SetOptions(VLRU_SET_INTERVAL, atoi(argv[++i]));
1237 } else if (!strcmp(argv[i], "-vlrumax")) {
1238 if ((i + 1) >= argc) {
1239 fprintf(stderr, "missing argument for %s\n", argv[i]);
1242 VLRU_SetOptions(VLRU_SET_MAX, atoi(argv[++i]));
1243 } else if (!strcmp(argv[i], "-unsafe-nosalvage")) {
1245 #endif /* AFS_DEMAND_ATTACH_FS */
1246 } else if (!strcmp(argv[i], "-s")) {
1248 if ((i + 1) >= argc) {
1249 fprintf(stderr, "missing argument for -s\n");
1252 nSmallVns = atoi(argv[++i]);
1253 } else if (!strcmp(argv[i], "-abortthreshold")) {
1254 if ((i + 1) >= argc) {
1255 fprintf(stderr, "missing argument for -abortthreshold\n");
1258 abort_threshold = atoi(argv[++i]);
1259 } else if (!strcmp(argv[i], "-k")) {
1260 if ((i + 1) >= argc) {
1261 fprintf(stderr, "missing argument for -k\n");
1264 stack = atoi(argv[++i]);
1266 #if defined(AFS_SGI_ENV)
1267 else if (!strcmp(argv[i], "-lock")) {
1271 else if (!strcmp(argv[i], "-spare")) {
1272 if ((i + 1) >= argc) {
1273 fprintf(stderr, "missing argument for -spare\n");
1276 BlocksSpare = atoi(argv[++i]);
1278 } else if (!strcmp(argv[i], "-pctspare")) {
1279 if ((i + 1) >= argc) {
1280 fprintf(stderr, "missing argument for -pctspare\n");
1283 PctSpare = atoi(argv[++i]);
1284 BlocksSpare = 0; /* has non-zero default */
1286 } else if (!strcmp(argv[i], "-w")) {
1287 if ((i + 1) >= argc) {
1288 fprintf(stderr, "missing argument for -w\n");
1291 fiveminutes = atoi(argv[++i]);
1292 } else if (!strcmp(argv[i], "-hr")) {
1294 if ((i + 1) >= argc) {
1295 fprintf(stderr, "missing argument for -hr\n");
1298 hr = atoi(argv[++i]);
1299 if ((hr < 1) || (hr > 36)) {
1301 ("host acl refresh interval of %d hours is invalid; hours must be between 1 and 36\n\n",
1305 hostaclRefresh = hr * 60 * 60;
1306 } else if (!strcmp(argv[i], "-rxdbg"))
1308 else if (!strcmp(argv[i], "-rxdbge"))
1310 else if (!strcmp(argv[i], "-cb")) {
1312 if ((i + 1) >= argc) {
1313 fprintf(stderr, "missing argument for -cb\n");
1316 numberofcbs = atoi(argv[++i]);
1317 if ((numberofcbs < 10000) || (numberofcbs > 2147483647)) {
1319 ("number of cbs %d invalid; must be between 10000 and 2147483647\n",
1323 } else if (!strcmp(argv[i], "-busyat")) {
1325 if ((i + 1) >= argc) {
1326 fprintf(stderr, "missing argument for -busyat\n");
1329 busy_threshold = atoi(argv[++i]);
1330 if (busy_threshold < 10) {
1332 ("Busy threshold %d is too low, will compute default.\n",
1336 } else if (!strcmp(argv[i], "-nobusy"))
1338 #ifdef AFS_AIX32_ENV
1339 else if (!strcmp(argv[i], "-m")) {
1340 extern int aixlow_water;
1341 if ((i + 1) >= argc) {
1342 fprintf(stderr, "missing argument for -m\n");
1345 aixlow_water = atoi(argv[++i]);
1346 if ((aixlow_water < 0) || (aixlow_water > 30)) {
1347 printf("space reserved %d% invalid; must be between 0-30%\n",
1353 else if (!strcmp(argv[i], "-nojumbo")) {
1355 } else if (!strcmp(argv[i], "-jumbo")) {
1357 } else if (!strcmp(argv[i], "-rxbind")) {
1359 } else if (!strcmp(argv[i], "-allow-dotted-principals")) {
1360 rxkadDisableDotCheck = 1;
1361 } else if (!strcmp(argv[i], "-rxmaxmtu")) {
1362 if ((i + 1) >= argc) {
1363 fprintf(stderr, "missing argument for -rxmaxmtu\n");
1366 rxMaxMTU = atoi(argv[++i]);
1367 if ((rxMaxMTU < RX_MIN_PACKET_SIZE) ||
1368 (rxMaxMTU > RX_MAX_PACKET_DATA_SIZE)) {
1369 printf("rxMaxMTU %d%% invalid; must be between %d-%" AFS_SIZET_FMT "\n",
1370 rxMaxMTU, RX_MIN_PACKET_SIZE,
1371 RX_MAX_PACKET_DATA_SIZE);
1374 } else if (!strcmp(argv[i], "-realm")) {
1375 extern char local_realms[AFS_NUM_LREALMS][AFS_REALM_SZ];
1376 extern int num_lrealms;
1377 if ((i + 1) >= argc) {
1378 fprintf(stderr, "missing argument for -realm\n");
1381 if (strlen(argv[++i]) >= AFS_REALM_SZ) {
1383 ("-realm argument must contain fewer than %d characters.\n",
1387 if (num_lrealms == -1)
1389 if (num_lrealms >= AFS_NUM_LREALMS) {
1391 ("a maximum of %d -realm arguments can be specified.\n",
1395 strncpy(local_realms[num_lrealms++], argv[i], AFS_REALM_SZ);
1396 } else if (!strcmp(argv[i], "-udpsize")) {
1397 if ((i + 1) >= argc) {
1398 printf("You have to specify -udpsize <integer value>\n");
1401 bufSize = atoi(argv[++i]);
1402 if (bufSize < rx_GetMinUdpBufSize())
1404 ("Warning:udpsize %d is less than minimum %d; ignoring\n",
1405 bufSize, rx_GetMinUdpBufSize());
1407 udpBufSize = bufSize;
1408 } else if (!strcmp(argv[i], "-sendsize")) {
1409 if ((i + 1) >= argc) {
1410 printf("You have to specify -sendsize <integer value>\n");
1413 bufSize = atoi(argv[++i]);
1414 if (bufSize < 16384)
1416 ("Warning:sendsize %d is less than minimum %d; ignoring\n",
1419 sendBufSize = bufSize;
1420 } else if (!strcmp(argv[i], "-enable_peer_stats")) {
1421 rx_enablePeerRPCStats();
1422 } else if (!strcmp(argv[i], "-enable_process_stats")) {
1423 rx_enableProcessRPCStats();
1425 else if (strcmp(argv[i], "-auditlog") == 0) {
1426 auditFileName = argv[++i];
1428 else if (strcmp(argv[i], "-audit-interface") == 0) {
1429 char *interface = argv[++i];
1431 if (osi_audit_interface(interface)) {
1432 printf("Invalid audit interface '%s'\n", interface);
1436 #ifndef AFS_NT40_ENV
1437 else if (strcmp(argv[i], "-syslog") == 0) {
1438 /* set syslog logging flag */
1439 serverLogSyslog = 1;
1440 } else if (strncmp(argv[i], "-syslog=", 8) == 0) {
1441 serverLogSyslog = 1;
1442 serverLogSyslogFacility = atoi(argv[i] + 8);
1445 else if (strcmp(argv[i], "-mrafslogs") == 0) {
1446 /* set syslog logging flag */
1449 else if (strcmp(argv[i], "-saneacls") == 0) {
1452 else if (strcmp(argv[i], "-offline-timeout") == 0) {
1453 if (i + 1 >= argc) {
1454 printf("You have to specify -offline-timeout <integer>\n");
1457 offline_timeout = atoi(argv[++i]);
1458 #ifndef AFS_PTHREAD_ENV
1459 if (offline_timeout != -1) {
1460 printf("The only valid -offline-timeout value for the LWP "
1461 "fileserver is -1\n");
1464 #endif /* AFS_PTHREAD_ENV */
1465 if (offline_timeout < -1) {
1466 printf("Invalid -offline-timeout value %s; the only valid "
1467 "negative value is -1\n", argv[i]);
1471 else if (strcmp(argv[i], "-offline-shutdown-timeout") == 0) {
1472 if (i + 1 >= argc) {
1473 printf("You have to specify -offline-shutdown-timeout "
1477 offline_shutdown_timeout = atoi(argv[++i]);
1478 #ifndef AFS_PTHREAD_ENV
1479 if (offline_shutdown_timeout != -1) {
1480 printf("The only valid -offline-shutdown-timeout value for the "
1481 "LWP fileserver is -1\n");
1484 #endif /* AFS_PTHREAD_ENV */
1485 if (offline_shutdown_timeout < -1) {
1486 printf("Invalid -offline-timeout value %s; the only valid "
1487 "negative value is -1\n", argv[i]);
1496 printf("Only one of -L, or -S must be specified\n");
1507 numberofcbs = 20000;
1523 numberofcbs = 64000;
1532 busy_threshold = 3 * rxpackets / 2;
1534 osi_audit_file(auditFileName);
1544 NewParms(int initializing)
1546 static struct afs_stat sbuf;
1549 char *argv[MAXPARMS];
1552 if (!(afs_stat("/vice/file/parms", &sbuf))) {
1553 parms = (char *)malloc(sbuf.st_size);
1556 fd = afs_open("parms", O_RDONLY, 0666);
1558 ViceLog(0, ("Open for parms failed with errno = %d\n", errno));
1562 i = read(fd, parms, sbuf.st_size);
1564 if (i != sbuf.st_size) {
1566 ViceLog(0, ("Read on parms failed with errno = %d\n", errno));
1569 ("Read on parms failed; expected %ld bytes but read %d\n",
1570 (long) sbuf.st_size, i));
1576 for (i = 0; i < MAXPARMS; argv[i++] = 0);
1578 for (argc = i = 0; i < sbuf.st_size; i++) {
1579 if ((*(parms + i) != ' ') && (*(parms + i) != '\n')) {
1580 if (argv[argc] == 0)
1581 argv[argc] = (parms + i);
1583 *(parms + i) = '\0';
1584 if (argv[argc] != 0) {
1585 if (++argc == MAXPARMS)
1588 while ((*(parms + i + 1) == ' ')
1589 || (*(parms + i + 1) == '\n'))
1593 if (ParseArgs(argc, argv) == 0) {
1594 ViceLog(0, ("Change parameters to:"));
1596 ViceLog(0, ("Invalid parameter in:"));
1598 for (i = 0; i < argc; i++) {
1599 ViceLog(0, (" %s", argv[i]));
1603 } else if (!initializing)
1605 ("Received request to change parms but no parms file exists\n"));
1610 /* Miscellaneous routines */
1614 ViceLog(0, ("%s\n", msg));
1615 osi_Panic("%s\n", msg);
1626 * If this fails, it's because something major is wrong, and is not
1627 * likely to be time dependent.
1629 code = pr_Initialize(2, AFSDIR_SERVER_ETC_DIRPATH, 0);
1632 ("Couldn't initialize protection library; code=%d.\n", code));
1636 #ifdef AFS_PTHREAD_ENV
1637 osi_Assert(pthread_key_create(&viced_uclient_key, NULL) == 0);
1640 SystemId = SYSADMINID;
1641 SystemAnyUser = ANYUSERID;
1642 SystemAnyUserCPS.prlist_len = 0;
1643 SystemAnyUserCPS.prlist_val = NULL;
1644 AnonCPS.prlist_len = 0;
1645 AnonCPS.prlist_val = NULL;
1647 code = pr_GetCPS(SystemAnyUser, &SystemAnyUserCPS);
1650 ("Couldn't get CPS for AnyUser, will try again in 30 seconds; code=%d.\n",
1654 code = pr_GetCPS(ANONYMOUSID, &AnonCPS);
1657 ("Couldn't get Anonymous CPS, exiting; code=%d.\n",
1661 AnonymousID = ANONYMOUSID;
1664 #ifdef AFS_PTHREAD_ENV
1666 #else /* AFS_PTHREAD_ENV */
1668 #endif /* AFS_PTHREAD_ENV */
1672 struct rx_connection *serverconns[MAXSERVERS];
1673 struct ubik_client *cstruct;
1676 vl_Initialize(const char *confDir)
1679 afs_int32 scIndex = RX_SECIDX_NULL;
1680 struct afsconf_dir *tdir;
1681 struct rx_securityClass *sc;
1682 struct afsconf_cell info;
1684 tdir = afsconf_Open(confDir);
1687 ("Could not open configuration directory (%s).\n", confDir));
1690 code = afsconf_ClientAuth(tdir, &sc, &scIndex);
1692 ViceLog(0, ("Could not get security object for localAuth\n"));
1695 code = afsconf_GetCellInfo(tdir, NULL, AFSCONF_VLDBSERVICE, &info);
1696 if (info.numServers > MAXSERVERS) {
1698 ("vl_Initialize: info.numServers=%d (> MAXSERVERS=%d)\n",
1699 info.numServers, MAXSERVERS));
1702 for (i = 0; i < info.numServers; i++)
1704 rx_NewConnection(info.hostAddr[i].sin_addr.s_addr,
1705 info.hostAddr[i].sin_port, USER_SERVICE_ID, sc,
1707 code = ubik_ClientInit(serverconns, &cstruct);
1708 afsconf_Close(tdir);
1710 ViceLog(0, ("vl_Initialize: ubik client init failed.\n"));
1716 #define SYSIDMAGIC 0x88aabbcc
1717 #define SYSIDVERSION 1
1722 afs_int32 fd, nentries, i;
1723 struct versionStamp vsn;
1724 struct afs_stat status;
1727 if ((afs_stat(AFSDIR_SERVER_SYSID_FILEPATH, &status))
1728 || (status.st_size <= 0)) {
1729 ViceLog(0, ("%s: doesn't exist\n", AFSDIR_SERVER_SYSID_FILEPATH));
1732 if (!(fd = afs_open(AFSDIR_SERVER_SYSID_FILEPATH, O_RDONLY, 0))) {
1734 ("%s: can't open (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1738 if ((i = read(fd, (char *)&vsn, sizeof(vsn))) != sizeof(vsn)) {
1740 ("%s: Read failed (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1744 if (vsn.magic != SYSIDMAGIC) {
1746 ("%s: wrong magic %x (we support %x)\n",
1747 AFSDIR_SERVER_SYSID_FILEPATH, vsn.magic, SYSIDMAGIC));
1750 if (vsn.version != SYSIDVERSION) {
1752 ("%s: wrong version %d (we support %d)\n",
1753 AFSDIR_SERVER_SYSID_FILEPATH, vsn.version, SYSIDVERSION));
1757 read(fd, (char *)&uuid,
1758 sizeof(struct afsUUID))) != sizeof(struct afsUUID)) {
1760 ("%s: read of uuid failed (%d)\n",
1761 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1764 afs_ntohuuid(&uuid);
1767 read(fd, (char *)&nentries,
1768 sizeof(afs_int32))) != sizeof(afs_int32)) {
1770 ("%s: Read of entries failed (%d)\n",
1771 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1774 if (nentries <= 0 || nentries > ADDRSPERSITE) {
1776 ("%s: invalid num of interfaces: %d\n",
1777 AFSDIR_SERVER_SYSID_FILEPATH, nentries));
1780 if (FS_HostAddr_cnt == 0) {
1781 FS_HostAddr_cnt = nentries;
1782 for (i = 0; i < nentries; i++) {
1783 if (read(fd, (char *)&FS_HostAddrs[i], sizeof(afs_int32)) !=
1784 sizeof(afs_int32)) {
1786 ("%s: Read of addresses failed (%d)\n",
1787 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1788 FS_HostAddr_cnt = 0; /* reset it */
1794 ("%s: address list ignored (NetInfo/NetRestrict override)\n",
1795 AFSDIR_SERVER_SYSID_FILEPATH));
1802 WriteSysIdFile(void)
1805 struct versionStamp vsn;
1806 struct afs_stat status;
1809 if (!afs_stat(AFSDIR_SERVER_SYSID_FILEPATH, &status)) {
1811 * File exists; keep the old one around
1813 renamefile(AFSDIR_SERVER_SYSID_FILEPATH,
1814 AFSDIR_SERVER_OLDSYSID_FILEPATH);
1816 fd = afs_open(AFSDIR_SERVER_SYSID_FILEPATH, O_WRONLY | O_TRUNC | O_CREAT,
1820 ("%s: can't create (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1824 vsn.magic = SYSIDMAGIC;
1826 if ((i = write(fd, (char *)&vsn, sizeof(vsn))) != sizeof(vsn)) {
1828 ("%s: write failed (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1833 afs_htonuuid(&uuid);
1835 write(fd, (char *)&uuid,
1836 sizeof(struct afsUUID))) != sizeof(struct afsUUID)) {
1838 ("%s: write of uuid failed (%d)\n",
1839 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1843 write(fd, (char *)&FS_HostAddr_cnt,
1844 sizeof(afs_int32))) != sizeof(afs_int32)) {
1846 ("%s: write of # of entries failed (%d)\n",
1847 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1850 for (i = 0; i < FS_HostAddr_cnt; i++) {
1851 if (write(fd, (char *)&FS_HostAddrs[i], sizeof(afs_int32)) !=
1852 sizeof(afs_int32)) {
1854 ("%s: write of addresses failed (%d)\n",
1855 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1865 * This routine sets up the buffers for the VL_RegisterAddrs RPC. All addresses
1866 * in FS_HostAddrs[] are in NBO, while the RPC treats them as a "blob" of data
1867 * and so we need to convert each of them into HBO which is what the extra
1868 * array called FS_HostAddrs_HBO is used here.
1871 Do_VLRegisterRPC(void)
1875 afs_uint32 FS_HostAddrs_HBO[ADDRSPERSITE];
1878 for (i = 0; i < FS_HostAddr_cnt; i++)
1879 FS_HostAddrs_HBO[i] = ntohl(FS_HostAddrs[i]);
1880 addrs.bulkaddrs_len = FS_HostAddr_cnt;
1881 addrs.bulkaddrs_val = (afs_uint32 *) FS_HostAddrs_HBO;
1882 code = ubik_VL_RegisterAddrs(cstruct, 0, &FS_HostUUID, 0, &addrs);
1884 if (code == VL_MULTIPADDR) {
1886 ("VL_RegisterAddrs rpc failed; The IP address exists on a different server; repair it\n"));
1888 ("VL_RegisterAddrs rpc failed; See VLLog for details\n"));
1890 } else if (code == RXGEN_OPCODE) {
1892 ("vlserver doesn't support VL_RegisterAddrs rpc; ignored\n"));
1893 FS_registered = 2; /* So we don't have to retry in the gc daemon */
1896 ("VL_RegisterAddrs rpc failed; will retry periodically (code=%d, err=%d)\n",
1898 FS_registered = 1; /* Retry in the gc daemon */
1901 FS_registered = 2; /* So we don't have to retry in the gc daemon */
1913 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH || AFSDIR_SERVER_NETINFO_FILEPATH) {
1915 * Find addresses we are supposed to register as per the netrestrict
1916 * and netinfo files (/usr/afs/local/NetInfo and
1917 * /usr/afs/local/NetRestict)
1920 afs_int32 code = parseNetFiles(FS_HostAddrs, NULL, NULL,
1921 ADDRSPERSITE, reason,
1922 AFSDIR_SERVER_NETINFO_FILEPATH,
1923 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
1925 ViceLog(0, ("Can't register any valid addresses: %s\n", reason));
1928 FS_HostAddr_cnt = (afs_uint32) code;
1931 FS_HostAddr_cnt = rx_getAllAddr(FS_HostAddrs, ADDRSPERSITE);
1934 if (FS_HostAddr_cnt == 1 && rxBind == 1)
1935 code = FS_HostAddrs[0];
1937 code = htonl(INADDR_ANY);
1947 * If this fails, it's because something major is wrong, and is not
1948 * likely to be time dependent.
1950 code = vl_Initialize(AFSDIR_SERVER_ETC_DIRPATH);
1953 ("Couldn't initialize protection library; code=%d.\n", code));
1957 /* Read or create the sysid file and register the fileserver's
1958 * IP addresses with the vlserver.
1960 code = ReadSysIdFile();
1962 /* Need to create the file */
1963 ViceLog(0, ("Creating new SysID file\n"));
1964 if ((code = afs_uuid_create(&FS_HostUUID))) {
1965 ViceLog(0, ("Failed to create new uuid: %d\n", code));
1969 /* A good sysid file exists; inform the vlserver. If any conflicts,
1970 * we always use the latest interface available as the real truth.
1973 code = Do_VLRegisterRPC();
1978 main(int argc, char *argv[])
1982 struct rx_securityClass **securityClasses;
1983 afs_int32 numClasses;
1984 struct rx_service *tservice;
1985 #ifdef AFS_PTHREAD_ENV
1986 pthread_t serverPid;
1987 pthread_attr_t tattr;
1988 #else /* AFS_PTHREAD_ENV */
1989 PROCESS parentPid, serverPid;
1990 #endif /* AFS_PTHREAD_ENV */
1992 int minVnodesRequired; /* min size of vnode cache */
1993 #ifndef AFS_NT40_ENV
1994 struct rlimit rlim; /* max number of open file descriptors */
1998 afs_uint32 rx_bindhost;
1999 VolumePackageOptions opts;
2001 #ifdef AFS_AIX32_ENV
2002 struct sigaction nsa;
2004 sigemptyset(&nsa.sa_mask);
2005 nsa.sa_handler = SIG_DFL;
2006 nsa.sa_flags = SA_FULLDUMP;
2007 sigaction(SIGABRT, &nsa, NULL);
2008 sigaction(SIGSEGV, &nsa, NULL);
2012 /* Initialize dirpaths */
2013 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
2015 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
2017 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
2021 /* set ihandle package defaults prior to parsing args */
2024 if (ParseArgs(argc, argv)) {
2028 #ifdef AFS_PTHREAD_ENV
2029 MUTEX_INIT(&fileproc_glock_mutex, "fileproc", MUTEX_DEFAULT, 0);
2030 #endif /* AFS_PTHREAD_ENV */
2032 #ifdef AFS_SGI_VNODE_GLUE
2033 if (afs_init_kernel_config(-1) < 0) {
2035 ("Can't determine NUMA configuration, not starting fileserver.\n");
2039 confDir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
2041 fprintf(stderr, "Unable to open config directory %s\n",
2042 AFSDIR_SERVER_ETC_DIRPATH);
2048 /* Open FileLog on stdout, stderr, fd 1 and fd2 (for perror), sigh. */
2049 #ifndef AFS_NT40_ENV
2050 serverLogSyslogTag = "fileserver";
2052 OpenLog(AFSDIR_SERVER_FILELOG_FILEPATH);
2055 if (SawSpare && SawPctSpare) {
2056 ViceLog(0, ("Both -spare and -pctspare specified, exiting.\n"));
2059 LogCommandLine(argc, argv, "starting", "", "File server", FSLog);
2061 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
2062 /* initialize the pthread soft signal handler thread */
2066 /* install signal handlers for controlling the fileserver process */
2067 ResetCheckSignal(); /* set CheckSignal_Signal() sig handler */
2068 ResetCheckDescriptors(); /* set CheckDescriptors_Signal() sig handler */
2070 #if defined(AFS_SGI_ENV)
2071 /* give this guy a non-degrading priority so help busy servers */
2072 schedctl(NDPRI, 0, NDPNORMMAX);
2076 #ifndef AFS_NT40_ENV
2077 nice(-5); /* TODO: */
2080 osi_Assert(DInit(buffs) == 0);
2081 #ifdef AFS_DEMAND_ATTACH_FS
2086 if (afs_winsockInit() < 0) {
2087 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
2088 ViceLog(0, ("File server failed to intialize winsock.\n"));
2094 /* if we support more than 16 threads, then we better have the ability
2095 ** to keep open a large number of files simultaneously
2097 #if defined(AFS_AIX_ENV) && !defined(AFS_AIX42_ENV)
2098 curLimit = OPEN_MAX; /* for pre AIX 4.2 systems */
2099 #elif defined(AFS_NT40_ENV)
2100 curLimit = NT_OPEN_MAX; /* open file descriptor limit on NT */
2103 curLimit = 0; /* the number of open file descriptors */
2104 code = getrlimit(RLIMIT_NOFILE, &rlim);
2106 curLimit = rlim.rlim_cur;
2107 rlim.rlim_cur = rlim.rlim_max;
2108 code = setrlimit(RLIMIT_NOFILE, &rlim);
2110 curLimit = rlim.rlim_max;
2113 ViceLog(0, ("Failed to increase open file limit, using default\n"));
2115 #endif /* defined(AFS_AIX_ENV) && !defined(AFS_AIX42_ENV) */
2117 curLimit -= 32; /* leave a slack of 32 file descriptors */
2118 if (lwps > curLimit) {
2122 lwps = 16; /* default to a maximum of 16 threads */
2124 /* tune the ihandle fd cache accordingly */
2125 if (vol_io_params.fd_max_cachesize < curLimit)
2126 vol_io_params.fd_max_cachesize = curLimit + 1;
2129 ("The system supports a max of %d open files and we are starting %d threads (ihandle fd cache is %d)\n",
2130 curLimit, lwps, vol_io_params.fd_max_cachesize));
2132 #ifndef AFS_PTHREAD_ENV
2133 osi_Assert(LWP_InitializeProcessSupport(LWP_MAX_PRIORITY - 2, &parentPid) ==
2135 #endif /* !AFS_PTHREAD_ENV */
2137 /* Initialize volume support */
2139 V_BreakVolumeCallbacks = BreakVolumeCallBacksLater;
2142 #ifdef AFS_PTHREAD_ENV
2143 SetLogThreadNumProgram( threadNum );
2146 /* initialize libacl routines */
2147 acl_Initialize(ACL_VERSION);
2149 /* initialize RX support */
2150 #ifndef AFS_NT40_ENV
2151 rxi_syscallp = viced_syscall;
2153 rx_extraPackets = rxpackets;
2154 rx_extraQuota = 4; /* for outgoing prserver calls from R threads */
2155 rx_SetBusyThreshold(busy_threshold, VBUSY);
2156 rx_SetCallAbortThreshold(abort_threshold);
2157 rx_SetConnAbortThreshold(abort_threshold);
2159 stackSize = 128 * 1024;
2161 stackSize = lwps * 4000;
2162 if (stackSize < 32000)
2164 else if (stackSize > 44000)
2167 #if defined(AFS_HPUX_ENV) || defined(AFS_SUN_ENV) || defined(AFS_SGI51_ENV) || defined(AFS_XBSD_ENV)
2168 rx_SetStackSize(1, stackSize);
2171 rx_SetUdpBufSize(udpBufSize); /* set the UDP buffer size for receive */
2172 rx_bindhost = SetupVL();
2174 if (rx_InitHost(rx_bindhost, (int)htons(7000)) < 0) {
2175 ViceLog(0, ("Cannot initialize RX\n"));
2178 if (!rxJumbograms) {
2179 /* Don't send and don't allow 3.4 clients to send jumbograms. */
2182 if (rxMaxMTU != -1) {
2183 rx_SetMaxMTU(rxMaxMTU);
2186 rx_SetRxDeadTime(30);
2187 afsconf_BuildServerSecurityObjects(confDir, AFSCONF_SEC_OBJS_RXKAD_CRYPT,
2188 &securityClasses, &numClasses);
2190 tservice = rx_NewServiceHost(rx_bindhost, /* port */ 0, /* service id */
2191 1, /*service name */
2193 securityClasses, numClasses,
2194 RXAFS_ExecuteRequest);
2197 ("Failed to initialize RX, probably two servers running.\n"));
2200 if (rxkadDisableDotCheck) {
2201 rx_SetSecurityConfiguration(tservice, RXS_CONFIG_FLAGS,
2202 (void *)RXS_CONFIG_FLAGS_DISABLE_DOTCHECK);
2204 rx_SetMinProcs(tservice, 3);
2205 rx_SetMaxProcs(tservice, lwps);
2206 rx_SetCheckReach(tservice, 1);
2207 rx_SetServerIdleDeadErr(tservice, VNOSERVICE);
2210 rx_NewService(0, RX_STATS_SERVICE_ID, "rpcstats", securityClasses,
2211 numClasses, RXSTATS_ExecuteRequest);
2213 ViceLog(0, ("Failed to initialize rpc stat service.\n"));
2216 rx_SetMinProcs(tservice, 2);
2217 rx_SetMaxProcs(tservice, 4);
2220 * Enable RX hot threads, which allows the listener thread to trade
2221 * places with an idle thread and moves the context switch from listener
2222 * to worker out of the critical path.
2224 rx_EnableHotThread();
2226 /* Some rx debugging */
2227 if (rxlog || eventlog) {
2228 debugFile = afs_fopen("rx_dbg", "w");
2230 rx_debugFile = debugFile;
2232 rxevent_debugFile = debugFile;
2235 init_sys_error_to_et(); /* Set up error table translation */
2236 h_InitHostPackage(); /* set up local cellname and realmname */
2237 InitCallBack(numberofcbs);
2241 if (code && code != VL_MULTIPADDR) {
2242 ViceLog(0, ("Fatal error in library initialization, exiting!!\n"));
2247 if (code && code != -1) {
2248 ViceLog(0, ("Fatal error in protection initialization, exiting!!\n"));
2252 /* allow super users to manage RX statistics */
2253 rx_SetRxStatUserOk(fs_rxstat_userok);
2255 CV_INIT(&fsync_cond, "fsync", CV_DEFAULT, 0);
2256 MUTEX_INIT(&fsync_glock_mutex, "fsync", MUTEX_DEFAULT, 0);
2258 #if !defined(AFS_DEMAND_ATTACH_FS)
2260 * For DAFS, we do not start the Rx server threads until after
2261 * the volume package is initialized, and fileserver state is
2262 * restored. This is necessary in order to keep host and callback
2263 * package state pristine until we have a chance to restore state.
2265 * Furthermore, startup latency is much lower with dafs, so this
2266 * shouldn't pose a serious problem.
2268 rx_StartServer(0); /* now start handling requests */
2271 /* we ensure that there is enough space in the vnode buffer to satisfy
2272 ** requests from all concurrent threads.
2273 ** the maximum number of vnodes used by a single thread at any one time
2274 ** is three ( "link" uses three vnodes simultaneously, one vLarge and
2275 ** two vSmall for linking files and two vLarge and one vSmall for linking
2278 minVnodesRequired = 2 * lwps + 1;
2279 if (minVnodesRequired > nSmallVns) {
2280 nSmallVns = minVnodesRequired;
2282 ("Overriding -s command line parameter with %d\n",
2285 if (minVnodesRequired > large) {
2286 large = minVnodesRequired;
2287 ViceLog(0, ("Overriding -l command line parameter with %d\n", large));
2290 /* We now do this after getting the listener up and running, so that client
2291 * connections don't timeout (maybe) if a file server is restarted, since it
2292 * will be available "real soon now". Worry about whether we can satisfy the
2293 * calls in the volume package itself.
2295 VOptDefaults(fileServer, &opts);
2296 opts.nLargeVnodes = large;
2297 opts.nSmallVnodes = nSmallVns;
2298 opts.volcache = volcache;
2299 opts.unsafe_attach = unsafe_attach;
2300 if (offline_timeout != -1) {
2301 opts.interrupt_rxcall = rx_InterruptCall;
2302 opts.offline_timeout = offline_timeout;
2304 if (offline_shutdown_timeout == -1) {
2305 /* default to -offline-timeout, if shutdown-specific timeout is not
2307 opts.offline_shutdown_timeout = offline_timeout;
2309 opts.interrupt_rxcall = rx_InterruptCall;
2310 opts.offline_shutdown_timeout = offline_shutdown_timeout;
2313 if (VInitVolumePackage2(fileServer, &opts)) {
2315 ("Shutting down: errors encountered initializing volume package\n"));
2320 /* Install handler to catch the shutdown signal;
2321 * bosserver assumes SIGQUIT shutdown
2323 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
2324 softsig_signal(SIGQUIT, ShutDown_Signal);
2326 (void)signal(SIGQUIT, ShutDown_Signal);
2329 if (VInitAttachVolumes(fileServer)) {
2331 ("Shutting down: errors encountered initializing volume package\n"));
2336 #ifdef AFS_DEMAND_ATTACH_FS
2337 if (fs_state.options.fs_state_restore) {
2340 * restore fileserver state */
2343 rx_StartServer(0); /* now start handling requests */
2344 #endif /* AFS_DEMAND_ATTACH_FS */
2347 * We are done calling fopen/fdopen. It is safe to use a large
2348 * of the file descriptor cache.
2352 #ifdef AFS_PTHREAD_ENV
2353 ViceLog(5, ("Starting pthreads\n"));
2354 osi_Assert(pthread_attr_init(&tattr) == 0);
2355 osi_Assert(pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED) == 0);
2357 osi_Assert(pthread_create
2358 (&serverPid, &tattr, FiveMinuteCheckLWP,
2359 &fiveminutes) == 0);
2360 osi_Assert(pthread_create
2361 (&serverPid, &tattr, HostCheckLWP, &fiveminutes) == 0);
2362 osi_Assert(pthread_create
2363 (&serverPid, &tattr, FsyncCheckLWP, &fiveminutes) == 0);
2364 #else /* AFS_PTHREAD_ENV */
2365 ViceLog(5, ("Starting LWP\n"));
2366 osi_Assert(LWP_CreateProcess
2367 (FiveMinuteCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
2368 (void *)&fiveminutes, "FiveMinuteChecks",
2369 &serverPid) == LWP_SUCCESS);
2371 osi_Assert(LWP_CreateProcess
2372 (HostCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
2373 (void *)&fiveminutes, "HostCheck", &serverPid) == LWP_SUCCESS);
2374 osi_Assert(LWP_CreateProcess
2375 (FsyncCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
2376 (void *)&fiveminutes, "FsyncCheck", &serverPid) == LWP_SUCCESS);
2377 #endif /* AFS_PTHREAD_ENV */
2379 FT_GetTimeOfDay(&tp, 0);
2382 * Figure out the FileServer's name and primary address.
2384 ViceLog(0, ("Getting FileServer name...\n"));
2385 code = gethostname(FS_HostName, 64);
2387 ViceLog(0, ("gethostname() failed\n"));
2389 ViceLog(0, ("FileServer host name is '%s'\n", FS_HostName));
2391 ViceLog(0, ("Getting FileServer address...\n"));
2392 he = gethostbyname(FS_HostName);
2394 ViceLog(0, ("Can't find address for FileServer '%s'\n", FS_HostName));
2397 memcpy(&FS_HostAddr_NBO, he->h_addr, 4);
2398 (void)afs_inet_ntoa_r(FS_HostAddr_NBO, hoststr);
2399 FS_HostAddr_HBO = ntohl(FS_HostAddr_NBO);
2401 ("FileServer %s has address %s (0x%x or 0x%x in host byte order)\n",
2402 FS_HostName, hoststr, FS_HostAddr_NBO, FS_HostAddr_HBO));
2407 ("File Server started %s",
2408 afs_ctime(&t, tbuffer, sizeof(tbuffer))));
2409 #if FS_STATS_DETAILED
2410 afs_FullPerfStats.det.epoch.tv_sec = StartTime = tp.tv_sec;
2412 #ifdef AFS_PTHREAD_ENV
2414 sleep(1000); /* long time */
2416 #else /* AFS_PTHREAD_ENV */
2417 osi_Assert(LWP_WaitProcess(&parentPid) == LWP_SUCCESS);
2418 #endif /* AFS_PTHREAD_ENV */