2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
9 * Portions Copyright (c) 2006 Sine Nomine Associates
12 /* viced.c - File Server main loop */
16 /* Function - This routine has the initialization code for */
19 /* ********************************************************************** */
21 #include <afsconfig.h>
22 #include <afs/param.h>
29 #include <sys/types.h>
30 #include <afs/procmgmt.h> /* signal(), kill(), wait(), etc. */
36 #include <WINNT/afsevent.h>
39 #include <netinet/in.h>
41 #include <unistd.h> /* sysconf() */
45 #endif /* ITIMER_REAL */
46 #include <sys/resource.h>
47 #endif /* AFS_NT40_ENV */
52 #ifdef AFS_PTHREAD_ENV
54 #else /* AFS_PTHREAD_ENV */
55 #include <afs/assert.h>
56 #endif /* AFS_PTHREAD_ENV */
59 #include <afs/ptclient.h>
60 #include <afs/afsint.h>
61 #include <afs/vldbint.h>
62 #include <afs/errors.h>
63 #include <afs/ihandle.h>
64 #include <afs/vnode.h>
65 #include <afs/volume.h>
67 #include <afs/cellconfig.h>
69 #include <afs/prs_fs.h>
71 #include <rx/rxstat.h>
73 #include <afs/afs_args.h>
74 #include <afs/vlserver.h>
75 #include <afs/afsutil.h>
76 #include <afs/fileutil.h>
77 #include <afs/ptuser.h>
78 #include <afs/audit.h>
79 #include <afs/partition.h>
82 #include <afs/netutils.h>
84 #include "viced_prototypes.h"
87 #ifdef AFS_PTHREAD_ENV
88 #include <afs/softsig.h>
90 #if defined(AFS_SGI_ENV)
91 #include "sys/schedctl.h"
94 #include <rx/rx_globals.h>
97 #define afs_stat stat64
98 #define afs_fstat fstat64
99 #define afs_open open64
100 #define afs_fopen fopen64
101 #else /* !O_LARGEFILE */
102 #define afs_stat stat
103 #define afs_fstat fstat
104 #define afs_open open
105 #define afs_fopen fopen
106 #endif /* !O_LARGEFILE */
110 void *ShutDown(void *);
111 static void ClearXStatValues(void);
112 static void NewParms(int);
113 static void PrintCounters(void);
114 static void ResetCheckDescriptors(void);
115 static void ResetCheckSignal(void);
116 static void *CheckSignal(void *);
118 static afs_int32 Do_VLRegisterRPC(void);
120 int eventlog = 0, rxlog = 0;
122 FILE *console = NULL;
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 AFS_QUIETFS_ENV 1
133 #define NT_OPEN_MAX 1024 /* This is an arbitrary no. we came up with for
134 * now. We hope this will be replaced by a more
135 * intelligent estimate later. */
138 int SystemId; /* ViceID of "Administrators" */
139 int SystemAnyUser; /* Viceid of "System:AnyUser" */
140 prlist SystemAnyUserCPS; /* CPS for "system:AnyUser */
141 int AnonymousID = 0; /* ViceId of "Anonymous" */
142 prlist AnonCPS; /* CPS for "Anonymous" */
144 struct afsconf_dir *confDir; /* Configuration dir object */
146 int restartMode = RESTART_ORDINARY;
149 * Home for the performance statistics.
151 struct afs_PerfStats afs_perfstats;
154 extern int Statistics;
162 int rxJumbograms = 0; /* default is to not send and receive jumbograms. */
163 int rxBind = 0; /* don't bind */
164 int rxkadDisableDotCheck = 0; /* disable check for dot in principal name */
166 afs_int32 implicitAdminRights = PRSFS_LOOKUP; /* The ADMINISTER right is
168 afs_int32 readonlyServer = 0;
171 int stackSize = 24000;
172 int fiveminutes = 300; /* 5 minutes. Change this for debugging only */
173 int CurrentConnections = 0;
174 int hostaclRefresh = 7200; /* refresh host clients' acls every 2 hrs */
175 #if defined(AFS_SGI_ENV)
181 * seconds to wait until forcing a panic during ShutDownAndCore(PANIC)
182 * in case we get stuck.
184 #ifdef AFS_DEMAND_ATTACH_FS
185 static int panic_timeout = 2 * 60;
187 static int panic_timeout = 30 * 60;
190 int rxpackets = 150; /* 100 */
191 int nSmallVns = 400; /* 200 */
192 int large = 400; /* 200 */
193 int volcache = 400; /* 400 */
194 int numberofcbs = 60000; /* 60000 */
195 int lwps = 9; /* 6 */
196 int buffs = 90; /* 70 */
197 int novbc = 0; /* Enable Volume Break calls */
198 int busy_threshold = 600;
199 int abort_threshold = 10;
200 int udpBufSize = 0; /* UDP buffer size for receive */
201 int sendBufSize = 16384; /* send buffer size */
202 int saneacls = 0; /* Sane ACLs Flag */
206 #ifdef AFS_PTHREAD_ENV
207 pthread_key_t viced_uclient_key;
210 #ifdef AFS_PTHREAD_ENV
211 pthread_key_t viced_uclient_key;
215 * FileServer's name and IP address, both network byte order and
218 #define ADDRSPERSITE 16 /* Same global is in rx/rx_user.c */
220 char FS_HostName[128] = "localhost";
221 afs_uint32 FS_HostAddr_NBO;
222 afs_uint32 FS_HostAddr_HBO;
223 afs_uint32 FS_HostAddrs[ADDRSPERSITE], FS_HostAddr_cnt = 0, FS_registered = 0;
224 /* All addresses in FS_HostAddrs are in NBO */
227 static void FlagMsg(void);
229 #ifdef AFS_DEMAND_ATTACH_FS
232 * fileserver mode support
234 * during fileserver shutdown, we have to track the graceful shutdown of
235 * certain background threads before we are allowed to dump state to
239 #if !defined(PTHREAD_RWLOCK_INITIALIZER) && defined(AFS_DARWIN80_ENV)
240 #define PTHREAD_RWLOCK_INITIALIZER {0x2DA8B3B4, {0}}
243 struct fs_state fs_state =
250 PTHREAD_COND_INITIALIZER,
251 PTHREAD_RWLOCK_INITIALIZER
253 #endif /* AFS_DEMAND_ATTACH_FS */
256 * Home for the performance statistics.
261 CheckDescriptors(void *unused)
264 struct afs_stat status;
265 register int tsize = getdtablesize();
267 for (i = 0; i < tsize; i++) {
268 if (afs_fstat(i, &status) != -1) {
269 printf("%d: dev %x, inode %u, length %u, type/mode %x\n", i,
270 (unsigned int) status.st_dev,
271 (unsigned int) status.st_ino,
272 (unsigned int) status.st_size,
277 ResetCheckDescriptors();
280 } /*CheckDescriptors */
283 #ifdef AFS_PTHREAD_ENV
285 CheckSignal_Signal(int x)
291 ShutDown_Signal(int x)
297 CheckDescriptors_Signal(int x)
299 CheckDescriptors(NULL);
301 #else /* AFS_PTHREAD_ENV */
303 CheckSignal_Signal(int x)
305 IOMGR_SoftSig(CheckSignal, 0);
309 ShutDown_Signal(int x)
311 IOMGR_SoftSig(ShutDown, 0);
315 CheckDescriptors_Signal(int x)
317 IOMGR_SoftSig(CheckDescriptors, 0);
319 #endif /* AFS_PTHREAD_ENV */
321 /* check whether caller is authorized to manage RX statistics */
323 fs_rxstat_userok(struct rx_call *call)
325 return afsconf_SuperUser(confDir, call, NULL);
329 ResetCheckSignal(void)
333 #if defined(AFS_HPUX_ENV)
336 #if defined(AFS_NT40_ENV)
343 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
344 softsig_signal(signo, CheckSignal_Signal);
346 signal(signo, CheckSignal_Signal);
351 ResetCheckDescriptors(void)
354 #if defined(AFS_PTHREAD_ENV)
355 softsig_signal(SIGTERM, CheckDescriptors_Signal);
357 (void)signal(SIGTERM, CheckDescriptors_Signal);
362 #if defined(AFS_PTHREAD_ENV)
366 return (intptr_t)pthread_getspecific(rx_thread_id_key);
370 /* proc called by rxkad module to get a key */
372 get_key(void *arock, register afs_int32 akvno, struct ktc_encryptionKey *akey)
375 static struct afsconf_key tkey;
376 register afs_int32 code;
379 ViceLog(0, ("conf dir not open\n"));
382 code = afsconf_GetKey(confDir, akvno, (struct ktc_encryptionKey *)tkey.key);
384 ViceLog(0, ("afsconf_GetKey failure: kvno %d code %d\n", akvno, code));
387 memcpy(akey, tkey.key, sizeof(tkey.key));
393 viced_syscall(afs_uint32 a3, afs_uint32 a4, void *a5)
396 #ifndef AFS_LINUX20_ENV
399 old = (void (*)(int))signal(SIGSYS, SIG_IGN);
401 rcode = syscall(AFS_SYSCALL, 28 /* AFSCALL_CALL */ , a3, a4, a5);
402 #ifndef AFS_LINUX20_ENV
410 #if !defined(AFS_NT40_ENV)
411 #include "AFS_component_version_number.c"
412 #endif /* !AFS_NT40_ENV */
414 #define MAXADMINNAME 64
415 char adminName[MAXADMINNAME];
421 struct afs_stat status;
423 if ((afs_stat("/AdminName", &status)) || /* if file does not exist */
424 (status.st_size <= 0) || /* or it is too short */
425 (status.st_size >= (MAXADMINNAME)) || /* or it is too long */
426 !(fd = afs_open("/AdminName", O_RDONLY, 0))) { /* or the open fails */
427 strcpy(adminName, "System:Administrators"); /* use the default name */
429 (void)read(fd, adminName, status.st_size); /* use name from the file */
432 close(fd); /* close fd if it was opened */
434 } /*CheckAdminName */
440 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
441 /* set our 'thread-id' so that the host hold table works */
442 MUTEX_ENTER(&rx_stats_mutex); /* protects rxi_pthread_hinum */
444 pthread_setspecific(rx_thread_id_key, (void *)(intptr_t)rxi_pthread_hinum);
445 MUTEX_EXIT(&rx_stats_mutex);
447 ("Set thread id %d 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();
501 if (console != NULL) {
502 #ifndef AFS_QUIETFS_ENV
503 fprintf(console, "File server is running at %s\r",
504 afs_ctime(&now, tbuffer, sizeof(tbuffer)));
505 #endif /* AFS_QUIETFS_ENV */
507 ("File server is running at %s\n",
508 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
511 #ifdef AFS_DEMAND_ATTACH_FS
515 #ifdef AFS_DEMAND_ATTACH_FS
516 fs_state.FiveMinuteLWP_tranquil = 1;
518 assert(pthread_cond_broadcast(&fs_state.worker_done_cv)==0);
523 } /*FiveMinuteCheckLWP */
526 /* This LWP does host checks every 5 minutes: it should not be used for
527 * other 5 minute activities because it may be delayed by timeouts when
528 * it probes the workstations
532 HostCheckLWP(void *unused)
534 ViceLog(1, ("Starting Host check process\n"));
535 setThreadId("HostCheckLWP");
536 #ifdef AFS_DEMAND_ATTACH_FS
538 while (fs_state.mode == FS_MODE_NORMAL) {
539 fs_state.HostCheckLWP_tranquil = 1;
545 #ifdef AFS_PTHREAD_ENV
547 #else /* AFS_PTHREAD_ENV */
548 IOMGR_Sleep(fiveminutes);
549 #endif /* AFS_PTHREAD_ENV */
551 #ifdef AFS_DEMAND_ATTACH_FS
553 if (fs_state.mode != FS_MODE_NORMAL) {
556 fs_state.HostCheckLWP_tranquil = 0;
560 ViceLog(2, ("Checking for dead venii & clients\n"));
563 #ifdef AFS_DEMAND_ATTACH_FS
567 #ifdef AFS_DEMAND_ATTACH_FS
568 fs_state.HostCheckLWP_tranquil = 1;
570 assert(pthread_cond_broadcast(&fs_state.worker_done_cv)==0);
577 /* This LWP does fsync checks every 5 minutes: it should not be used for
578 * other 5 minute activities because it may be delayed by timeouts when
579 * it probes the workstations
582 FsyncCheckLWP(void *unused)
585 #ifdef AFS_PTHREAD_ENV
586 struct timespec fsync_next;
588 ViceLog(1, ("Starting fsync check process\n"));
590 setThreadId("FsyncCheckLWP");
592 #ifdef AFS_DEMAND_ATTACH_FS
594 while (fs_state.mode == FS_MODE_NORMAL) {
595 fs_state.FsyncCheckLWP_tranquil = 1;
601 #ifdef AFS_PTHREAD_ENV
602 /* rounding is fine */
603 fsync_next.tv_nsec = 0;
604 fsync_next.tv_sec = time(0) + fiveminutes;
607 pthread_cond_timedwait(&fsync_cond, &fsync_glock_mutex,
609 if (code != 0 && code != ETIMEDOUT)
610 ViceLog(0, ("pthread_cond_timedwait returned %d\n", code));
611 #else /* AFS_PTHREAD_ENV */
612 if ((code = LWP_WaitProcess(fsync_wait)) != LWP_SUCCESS)
613 ViceLog(0, ("LWP_WaitProcess returned %d\n", code));
614 #endif /* AFS_PTHREAD_ENV */
617 #ifdef AFS_DEMAND_ATTACH_FS
619 if (fs_state.mode != FS_MODE_NORMAL) {
622 fs_state.FsyncCheckLWP_tranquil = 0;
624 #endif /* AFS_DEMAND_ATTACH_FS */
626 ViceLog(2, ("Checking for fsync events\n"));
628 code = BreakLaterCallBacks();
630 #ifdef AFS_DEMAND_ATTACH_FS
634 #ifdef AFS_DEMAND_ATTACH_FS
635 fs_state.FsyncCheckLWP_tranquil = 1;
637 assert(pthread_cond_broadcast(&fs_state.worker_done_cv)==0);
640 #endif /* AFS_DEMAND_ATTACH_FS */
644 /*------------------------------------------------------------------------
645 * PRIVATE ClearXStatValues
648 * Initialize all of the values collected via the xstat
658 * Must be called during File Server initialization.
662 *------------------------------------------------------------------------*/
665 ClearXStatValues(void)
666 { /*ClearXStatValues */
668 struct fs_stats_opTimingData *opTimeP; /*Ptr to timing struct */
669 struct fs_stats_xferData *opXferP; /*Ptr to xfer struct */
670 int i; /*Loop counter */
673 * Zero all xstat-related structures.
675 memset((&afs_perfstats), 0, sizeof(struct afs_PerfStats));
676 #if FS_STATS_DETAILED
677 memset((&afs_FullPerfStats), 0,
678 sizeof(struct fs_stats_FullPerfStats));
681 * That's not enough. We have to set reasonable minima for
682 * time and xfer values in the detailed stats.
684 opTimeP = &(afs_FullPerfStats.det.rpcOpTimes[0]);
685 for (i = 0; i < FS_STATS_NUM_RPC_OPS; i++, opTimeP++)
686 opTimeP->minTime.tv_sec = 999999;
688 opXferP = &(afs_FullPerfStats.det.xferOpTimes[0]);
689 for (i = 0; i < FS_STATS_NUM_XFER_OPS; i++, opXferP++) {
690 opXferP->minTime.tv_sec = 999999;
691 opXferP->minBytes = 999999999;
695 * There's more. We have to set our unique system identifier, as
696 * declared in param.h. If such a thing is not defined, we bitch
697 * and declare ourselves to be an unknown system type.
700 afs_perfstats.sysname_ID = SYS_NAME_ID;
703 ViceLog(0, ("Sys name ID constant not defined in param.h!!\n"));
704 ViceLog(0, ("[Choosing ``undefined'' sys name ID.\n"));
706 afs_perfstats.sysname_ID = SYS_NAME_ID_UNDEFINED;
707 #endif /* SYS_NAME_ID */
710 } /*ClearXStatValues */
712 int CopyOnWrite_calls = 0, CopyOnWrite_off0 = 0, CopyOnWrite_size0 = 0;
713 afs_fsize_t CopyOnWrite_maxsize = 0;
718 int dirbuff, dircall, dirio;
720 int workstations, activeworkstations, delworkstations;
724 FT_GetTimeOfDay(&tpl, 0);
727 ("Vice was last started at %s\n",
728 afs_ctime(&StartTime, tbuffer, sizeof(tbuffer))));
730 #ifdef AFS_DEMAND_ATTACH_FS
731 /* XXX perhaps set extended stats verbosity flags
732 * based upon LogLevel ?? */
733 VPrintExtendedCacheStats(VOL_STATS_PER_CHAIN2);
737 DStat(&dirbuff, &dircall, &dirio);
739 ("With %d directory buffers; %d reads resulted in %d read I/Os\n",
740 dirbuff, dircall, dirio));
741 rx_PrintStats(stderr);
742 audit_PrintStats(stderr);
744 PrintCallBackStats();
746 processSize = -1; /* TODO: */
748 processSize = (int)((long)sbrk(0) >> 10);
751 ("There are %d connections, process size %d\n",
752 CurrentConnections, processSize));
753 h_GetWorkStats(&workstations, &activeworkstations, &delworkstations,
754 tpl.tv_sec - 15 * 60);
756 ("There are %d workstations, %d are active (req in < 15 mins), %d marked \"down\"\n",
757 workstations, activeworkstations, delworkstations));
758 ViceLog(0, ("CopyOnWrite: calls %d off0 %d size0 %d maxsize 0x%llx\n",
759 CopyOnWrite_calls, CopyOnWrite_off0, CopyOnWrite_size0, CopyOnWrite_maxsize));
768 CheckSignal(void *unused)
770 if (FS_registered > 0) {
772 * We have proper ip addresses; tell the vlserver what we got; the following
773 * routine will do the proper reporting for us
786 ShutdownWatchdogLWP(void *unused)
788 sleep(panic_timeout);
789 ViceLog(0, ("ShutdownWatchdogLWP: Failed to shutdown and panic "
790 "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 assert(pthread_attr_init(&tattr) == 0);
806 assert(pthread_create(&watchdogPid, &tattr, ShutdownWatchdogLWP, NULL) == 0);
809 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 fs_state.mode = FS_MODE_SHUTDOWN;
828 ("Shutting down file server at %s",
829 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
831 ViceLog(0, ("ABNORMAL SHUTDOWN, see core file.\n"));
832 #ifndef AFS_QUIETFS_ENV
833 if (console != NULL) {
834 fprintf(console, "File server restart/shutdown received at %s\r",
835 afs_ctime(&now, tbuffer, sizeof(tbuffer)));
842 /* shut down volume package */
845 #ifdef AFS_DEMAND_ATTACH_FS
846 if (fs_state.options.fs_state_save) {
849 * save fileserver state to disk */
851 /* make sure background threads have finished all of their asynchronous
852 * work on host and callback structures */
854 while (!fs_state.FiveMinuteLWP_tranquil ||
855 !fs_state.HostCheckLWP_tranquil ||
856 !fs_state.FsyncCheckLWP_tranquil) {
859 ViceLog(0, ("waiting for background host/callback threads to quiesce before saving fileserver state...\n"));
860 assert(pthread_cond_wait(&fs_state.worker_done_cv, &fileproc_glock_mutex) == 0);
865 /* ok. it should now be fairly safe. let's do the state dump */
868 #endif /* AFS_DEMAND_ATTACH_FS */
871 rx_PrintStats(debugFile);
874 if (console != NULL) {
877 #ifndef AFS_QUIETFS_ENV
878 fprintf(console, "File server has terminated abnormally at %s\r",
879 afs_ctime(&now, tbuffer, sizeof(tbuffer)));
882 ("File server has terminated abnormally at %s\n",
883 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
885 #ifndef AFS_QUIETFS_ENV
886 fprintf(console, "File server has terminated normally at %s\r",
887 afs_ctime(&now, tbuffer, sizeof(tbuffer)));
890 ("File server has terminated normally at %s\n",
891 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
902 ShutDown(void *unused)
903 { /* backward compatibility */
904 ShutDownAndCore(DONTPANIC);
912 /* default supports help flag */
914 fputs("Usage: fileserver ", stdout);
915 fputs("[-auditlog <log path>] ", stdout);
916 fputs("[-audit-interface <file|sysvmq> (default is file)] ", stdout);
917 fputs("[-d <debug level>] ", stdout);
918 fputs("[-p <number of processes>] ", stdout);
919 fputs("[-spare <number of spare blocks>] ", stdout);
920 fputs("[-pctspare <percentage spare>] ", stdout);
921 fputs("[-b <buffers>] ", stdout);
922 fputs("[-l <large vnodes>] ", stdout);
923 fputs("[-s <small vnodes>] ", stdout);
924 fputs("[-vc <volume cachesize>] ", stdout);
925 fputs("[-w <call back wait interval>] ", stdout);
926 fputs("[-cb <number of call backs>] ", stdout);
927 fputs("[-banner (print banner every 10 minutes)] ", stdout);
928 fputs("[-novbc (whole volume cbs disabled)] ", stdout);
929 fputs("[-implicit <admin mode bits: rlidwka>] ", stdout);
930 fputs("[-readonly (read-only file server)] ", stdout);
931 fputs("[-hr <number of hours between refreshing the host cps>] ", stdout);
932 fputs("[-busyat <redirect clients when queue > n>] ", stdout);
933 fputs("[-nobusy <no VBUSY before a volume is attached>] ", stdout);
934 fputs("[-rxpck <number of rx extra packets>] ", stdout);
935 fputs("[-rxdbg (enable rx debugging)] ", stdout);
936 fputs("[-rxdbge (enable rxevent debugging)] ", stdout);
937 fputs("[-rxmaxmtu <bytes>] ", stdout);
938 fputs("[-rxbind (bind the Rx socket to one address)] ", stdout);
939 fputs("[-allow-dotted-principals (disable the rxkad principal name dot check)] ", stdout);
940 fputs("[-vhandle-setaside (fds reserved for non-cache io [default 128])] ", stdout);
941 fputs("[-vhandle-max-cachesize (max open files [default 128])] ", stdout);
942 fputs("[-vhandle-initial-cachesize (fds reserved for cache io [default 128])] ", stdout);
943 #ifdef AFS_DEMAND_ATTACH_FS
944 fputs("[-fs-state-dont-save (disable state save during shutdown)] ", stdout);
945 fputs("[-fs-state-dont-restore (disable state restore during startup)] ", stdout);
946 fputs("[-fs-state-verify <none|save|restore|both> (default is both)] ", stdout);
947 fputs("[-vattachpar <max number of volume attach/shutdown threads> (default is 1)] ", stdout);
948 fputs("[-vhashsize <log(2) of number of volume hash buckets> (default is 8)] ", stdout);
949 fputs("[-vlrudisable (disable VLRU functionality)] ", stdout);
950 fputs("[-vlruthresh <minutes before unused volumes become eligible for soft detach> (default is 2 hours)] ", stdout);
951 fputs("[-vlruinterval <seconds between VLRU scans> (default is 2 minutes)] ", stdout);
952 fputs("[-vlrumax <max volumes to soft detach in one VLRU scan> (default is 8)] ", stdout);
953 #elif AFS_PTHREAD_ENV
954 fputs("[-vattachpar <number of volume attach threads> (default is 1)] ", stdout);
957 fputs("[-m <min percentage spare in partition>] ", stdout);
959 #if defined(AFS_SGI_ENV)
960 fputs("[-lock (keep fileserver from swapping)] ", stdout);
962 fputs("[-L (large server conf)] ", stdout);
963 fputs("[-S (small server conf)] ", stdout);
964 fputs("[-k <stack size>] ", stdout);
965 fputs("[-realm <Kerberos realm name>] ", stdout);
966 fputs("[-udpsize <size of socket buffer in bytes>] ", stdout);
967 fputs("[-sendsize <size of send buffer in bytes>] ", stdout);
968 fputs("[-abortthreshold <abort threshold>] ", stdout);
969 fputs("[-nojumbo (disable jumbogram network packets - deprecated)] ", stdout);
970 fputs("[-jumbo (enable jumbogram network packets)] ", stdout);
971 /* fputs("[-enable_peer_stats] ", stdout); */
972 /* fputs("[-enable_process_stats] ", stdout); */
973 fputs("[-help]\n", stdout);
975 ViceLog(0, ("%s", buffer));
984 ParseRights(char *arights)
990 if (!arights || !strcmp(arights, "")) {
991 printf("Missing list of mode bits on -implicit option\n");
994 if (!strcmp(arights, "none"))
996 else if (!strcmp(arights, "read"))
997 mode = PRSFS_READ | PRSFS_LOOKUP;
998 else if (!strcmp(arights, "write"))
1000 PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
1001 PRSFS_WRITE | PRSFS_LOCK;
1002 else if (!strcmp(arights, "all"))
1004 PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
1005 PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER;
1007 len = strlen(arights);
1008 for (i = 0; i < len; i++) {
1013 mode |= PRSFS_LOOKUP;
1015 mode |= PRSFS_INSERT;
1017 mode |= PRSFS_DELETE;
1019 mode |= PRSFS_WRITE;
1023 mode |= PRSFS_ADMINISTER;
1041 printf("Illegal -implicit rights character '%c'.\n", tc);
1050 * Limit MAX_FILESERVER_THREAD by the system limit on the number of
1051 * pthreads (sysconf(_SC_THREAD_THREADS_MAX)), if applicable and
1054 * AIX: sysconf() limit is real
1055 * HP-UX: sysconf() limit is real
1056 * IRIX: sysconf() limit is apparently NOT real -- too small
1057 * DUX: sysconf() limit is apparently NOT real -- too big
1058 * Linux: sysconf() limit is apparently NOT real -- too big
1059 * Solaris: no sysconf() limit
1062 max_fileserver_thread(void)
1064 #if defined(AFS_PTHREAD_ENV)
1065 #if defined(AFS_AIX_ENV) || defined(AFS_HPUX_ENV)
1068 ans = sysconf(_SC_THREAD_THREADS_MAX);
1069 if (0 < ans && ans < MAX_FILESERVER_THREAD)
1072 #endif /* defined(AFS_PTHREAD_ENV) */
1073 return MAX_FILESERVER_THREAD;
1076 /* from ihandle.c */
1077 extern ih_init_params vol_io_params;
1080 ParseArgs(int argc, char *argv[])
1082 int SawL = 0, SawS = 0, SawVC = 0;
1083 int Sawrxpck = 0, Sawsmall = 0, Sawlarge = 0, Sawcbs = 0, Sawlwps =
1087 int bufSize = 0; /* temp variable to read in udp socket buf size */
1088 char *auditFileName = NULL;
1090 for (i = 1; i < argc; i++) {
1091 if (!strcmp(argv[i], "-d")) {
1092 if ((i + 1) >= argc) {
1093 fprintf(stderr, "missing argument for -d\n");
1096 debuglevel = atoi(argv[++i]);
1097 LogLevel = debuglevel;
1098 } else if (!strcmp(argv[i], "-banner")) {
1100 } else if (!strcmp(argv[i], "-implicit")) {
1101 if ((i + 1) >= argc) {
1102 fprintf(stderr, "missing argument for -implicit\n");
1105 implicitAdminRights = ParseRights(argv[++i]);
1106 if (implicitAdminRights < 0)
1107 return implicitAdminRights;
1108 } else if (!strcmp(argv[i], "-readonly")) {
1110 } else if (!strcmp(argv[i], "-L")) {
1112 } else if (!strcmp(argv[i], "-S")) {
1114 } else if (!strcmp(argv[i], "-p")) {
1116 max_fileserver_thread() - FILESERVER_HELPER_THREADS;
1118 if ((i + 1) >= argc) {
1119 fprintf(stderr, "missing argument for -p\n");
1122 lwps = atoi(argv[++i]);
1123 if (lwps > lwps_max)
1127 } else if (!strcmp(argv[i], "-b")) {
1129 if ((i + 1) >= argc) {
1130 fprintf(stderr, "missing argument for -b\n");
1133 buffs = atoi(argv[++i]);
1134 } else if (!strcmp(argv[i], "-l")) {
1136 if ((i + 1) >= argc) {
1137 fprintf(stderr, "missing argument for -l\n");
1140 large = atoi(argv[++i]);
1141 } else if (!strcmp(argv[i], "-vc")) {
1143 if ((i + 1) >= argc) {
1144 fprintf(stderr, "missing argument for -vc\n");
1147 volcache = atoi(argv[++i]);
1148 } else if (!strcmp(argv[i], "-novbc")) {
1150 } else if (!strcmp(argv[i], "-rxpck")) {
1152 if ((i + 1) >= argc) {
1153 fprintf(stderr, "missing argument for -rxpck\n");
1156 rxpackets = atoi(argv[++i]);
1157 #ifdef AFS_PTHREAD_ENV
1158 } else if (!strcmp(argv[i], "-vattachpar")) {
1159 if ((i + 1) >= argc) {
1160 fprintf(stderr, "missing argument for %s\n", argv[i]);
1163 vol_attach_threads = atoi(argv[++i]);
1164 #endif /* AFS_PTHREAD_ENV */
1165 } else if (!strcmp(argv[i], "-vhandle-setaside")) {
1166 if ((i + 1) >= argc) {
1167 fprintf(stderr, "missing argument for %s\n", argv[i]);
1170 vol_io_params.fd_handle_setaside = atoi(argv[++i]);
1171 } else if (!strcmp(argv[i], "-vhandle-max-cachesize")) {
1172 if ((i + 1) >= argc) {
1173 fprintf(stderr, "missing argument for %s\n", argv[i]);
1176 vol_io_params.fd_max_cachesize = atoi(argv[++i]);
1177 } else if (!strcmp(argv[i], "-vhandle-initial-cachesize")) {
1178 if ((i + 1) >= argc) {
1179 fprintf(stderr, "missing argument for %s\n", argv[i]);
1182 vol_io_params.fd_initial_cachesize = atoi(argv[++i]);
1183 #ifdef AFS_DEMAND_ATTACH_FS
1184 } else if (!strcmp(argv[i], "-fs-state-dont-save")) {
1185 fs_state.options.fs_state_save = 0;
1186 } else if (!strcmp(argv[i], "-fs-state-dont-restore")) {
1187 fs_state.options.fs_state_restore = 0;
1188 } else if (!strcmp(argv[i], "-fs-state-verify")) {
1189 if ((i + 1) >= argc) {
1190 fprintf(stderr, "missing argument for %s\n", argv[i]);
1194 if (!strcmp(argv[i], "none")) {
1195 fs_state.options.fs_state_verify_before_save = 0;
1196 fs_state.options.fs_state_verify_after_restore = 0;
1197 } else if (!strcmp(argv[i], "save")) {
1198 fs_state.options.fs_state_verify_after_restore = 0;
1199 } else if (!strcmp(argv[i], "restore")) {
1200 fs_state.options.fs_state_verify_before_save = 0;
1201 } else if (!strcmp(argv[i], "both")) {
1204 fprintf(stderr, "invalid argument for %s\n", argv[i-1]);
1207 } else if (!strcmp(argv[i], "-vhashsize")) {
1208 if ((i + 1) >= argc) {
1209 fprintf(stderr, "missing argument for %s\n", argv[i]);
1212 VSetVolHashSize(atoi(argv[++i]));
1213 } else if (!strcmp(argv[i], "-vlrudisable")) {
1214 VLRU_SetOptions(VLRU_SET_ENABLED, 0);
1215 } else if (!strcmp(argv[i], "-vlruthresh")) {
1216 if ((i + 1) >= argc) {
1217 fprintf(stderr, "missing argument for %s\n", argv[i]);
1220 VLRU_SetOptions(VLRU_SET_THRESH, 60*atoi(argv[++i]));
1221 } else if (!strcmp(argv[i], "-vlruinterval")) {
1222 if ((i + 1) >= argc) {
1223 fprintf(stderr, "missing argument for %s\n", argv[i]);
1226 VLRU_SetOptions(VLRU_SET_INTERVAL, atoi(argv[++i]));
1227 } else if (!strcmp(argv[i], "-vlrumax")) {
1228 if ((i + 1) >= argc) {
1229 fprintf(stderr, "missing argument for %s\n", argv[i]);
1232 VLRU_SetOptions(VLRU_SET_MAX, atoi(argv[++i]));
1233 #endif /* AFS_DEMAND_ATTACH_FS */
1234 } else if (!strcmp(argv[i], "-s")) {
1236 if ((i + 1) >= argc) {
1237 fprintf(stderr, "missing argument for -s\n");
1240 nSmallVns = atoi(argv[++i]);
1241 } else if (!strcmp(argv[i], "-abortthreshold")) {
1242 if ((i + 1) >= argc) {
1243 fprintf(stderr, "missing argument for -abortthreshold\n");
1246 abort_threshold = atoi(argv[++i]);
1247 } else if (!strcmp(argv[i], "-k")) {
1248 if ((i + 1) >= argc) {
1249 fprintf(stderr, "missing argument for -k\n");
1252 stack = atoi(argv[++i]);
1254 #if defined(AFS_SGI_ENV)
1255 else if (!strcmp(argv[i], "-lock")) {
1259 else if (!strcmp(argv[i], "-spare")) {
1260 if ((i + 1) >= argc) {
1261 fprintf(stderr, "missing argument for -spare\n");
1264 BlocksSpare = atoi(argv[++i]);
1266 } else if (!strcmp(argv[i], "-pctspare")) {
1267 if ((i + 1) >= argc) {
1268 fprintf(stderr, "missing argument for -pctspare\n");
1271 PctSpare = atoi(argv[++i]);
1272 BlocksSpare = 0; /* has non-zero default */
1274 } else if (!strcmp(argv[i], "-w")) {
1275 if ((i + 1) >= argc) {
1276 fprintf(stderr, "missing argument for -w\n");
1279 fiveminutes = atoi(argv[++i]);
1280 } else if (!strcmp(argv[i], "-hr")) {
1282 if ((i + 1) >= argc) {
1283 fprintf(stderr, "missing argument for -hr\n");
1286 hr = atoi(argv[++i]);
1287 if ((hr < 1) || (hr > 36)) {
1289 ("host acl refresh interval of %d hours is invalid; hours must be between 1 and 36\n\n",
1293 hostaclRefresh = hr * 60 * 60;
1294 } else if (!strcmp(argv[i], "-rxdbg"))
1296 else if (!strcmp(argv[i], "-rxdbge"))
1298 else if (!strcmp(argv[i], "-cb")) {
1300 if ((i + 1) >= argc) {
1301 fprintf(stderr, "missing argument for -cb\n");
1304 numberofcbs = atoi(argv[++i]);
1305 if ((numberofcbs < 10000) || (numberofcbs > 2147483647)) {
1307 ("number of cbs %d invalid; must be between 10000 and 2147483647\n",
1311 } else if (!strcmp(argv[i], "-busyat")) {
1313 if ((i + 1) >= argc) {
1314 fprintf(stderr, "missing argument for -busyat\n");
1317 busy_threshold = atoi(argv[++i]);
1318 if (busy_threshold < 10) {
1320 ("Busy threshold %d is too low, will compute default.\n",
1324 } else if (!strcmp(argv[i], "-nobusy"))
1326 #ifdef AFS_AIX32_ENV
1327 else if (!strcmp(argv[i], "-m")) {
1328 extern int aixlow_water;
1329 if ((i + 1) >= argc) {
1330 fprintf(stderr, "missing argument for -m\n");
1333 aixlow_water = atoi(argv[++i]);
1334 if ((aixlow_water < 0) || (aixlow_water > 30)) {
1335 printf("space reserved %d% invalid; must be between 0-30%\n",
1341 else if (!strcmp(argv[i], "-nojumbo")) {
1343 } else if (!strcmp(argv[i], "-jumbo")) {
1345 } else if (!strcmp(argv[i], "-rxbind")) {
1347 } else if (!strcmp(argv[i], "-allow-dotted-principals")) {
1348 rxkadDisableDotCheck = 1;
1349 } else if (!strcmp(argv[i], "-rxmaxmtu")) {
1350 if ((i + 1) >= argc) {
1351 fprintf(stderr, "missing argument for -rxmaxmtu\n");
1354 rxMaxMTU = atoi(argv[++i]);
1355 if ((rxMaxMTU < RX_MIN_PACKET_SIZE) ||
1356 (rxMaxMTU > RX_MAX_PACKET_DATA_SIZE)) {
1357 printf("rxMaxMTU %d%% invalid; must be between %d-%" AFS_SIZET_FMT "\n",
1358 rxMaxMTU, RX_MIN_PACKET_SIZE,
1359 RX_MAX_PACKET_DATA_SIZE);
1362 } else if (!strcmp(argv[i], "-realm")) {
1363 extern char local_realms[AFS_NUM_LREALMS][AFS_REALM_SZ];
1364 extern int num_lrealms;
1365 if ((i + 1) >= argc) {
1366 fprintf(stderr, "missing argument for -realm\n");
1369 if (strlen(argv[++i]) >= AFS_REALM_SZ) {
1371 ("-realm argument must contain fewer than %d characters.\n",
1375 if (num_lrealms == -1)
1377 if (num_lrealms >= AFS_NUM_LREALMS) {
1379 ("a maximum of %d -realm arguments can be specified.\n",
1383 strncpy(local_realms[num_lrealms++], argv[i], AFS_REALM_SZ);
1384 } else if (!strcmp(argv[i], "-udpsize")) {
1385 if ((i + 1) >= argc) {
1386 printf("You have to specify -udpsize <integer value>\n");
1389 bufSize = atoi(argv[++i]);
1390 if (bufSize < rx_GetMinUdpBufSize())
1392 ("Warning:udpsize %d is less than minimum %d; ignoring\n",
1393 bufSize, rx_GetMinUdpBufSize());
1395 udpBufSize = bufSize;
1396 } else if (!strcmp(argv[i], "-sendsize")) {
1397 if ((i + 1) >= argc) {
1398 printf("You have to specify -sendsize <integer value>\n");
1401 bufSize = atoi(argv[++i]);
1402 if (bufSize < 16384)
1404 ("Warning:sendsize %d is less than minimum %d; ignoring\n",
1407 sendBufSize = bufSize;
1408 } else if (!strcmp(argv[i], "-enable_peer_stats")) {
1409 rx_enablePeerRPCStats();
1410 } else if (!strcmp(argv[i], "-enable_process_stats")) {
1411 rx_enableProcessRPCStats();
1413 else if (strcmp(argv[i], "-auditlog") == 0) {
1414 auditFileName = argv[++i];
1416 else if (strcmp(argv[i], "-audit-interface") == 0) {
1417 char *interface = argv[++i];
1419 if (osi_audit_interface(interface)) {
1420 printf("Invalid audit interface '%s'\n", interface);
1424 #ifndef AFS_NT40_ENV
1425 else if (strcmp(argv[i], "-syslog") == 0) {
1426 /* set syslog logging flag */
1427 serverLogSyslog = 1;
1428 } else if (strncmp(argv[i], "-syslog=", 8) == 0) {
1429 serverLogSyslog = 1;
1430 serverLogSyslogFacility = atoi(argv[i] + 8);
1433 else if (strcmp(argv[i], "-mrafslogs") == 0) {
1434 /* set syslog logging flag */
1437 else if (strcmp(argv[i], "-saneacls") == 0) {
1445 printf("Only one of -L, or -S must be specified\n");
1456 numberofcbs = 20000;
1472 numberofcbs = 64000;
1481 busy_threshold = 3 * rxpackets / 2;
1483 osi_audit_file(auditFileName);
1493 NewParms(int initializing)
1495 static struct afs_stat sbuf;
1498 char *argv[MAXPARMS];
1501 if (!(afs_stat("/vice/file/parms", &sbuf))) {
1502 parms = (char *)malloc(sbuf.st_size);
1505 fd = afs_open("parms", O_RDONLY, 0666);
1507 ViceLog(0, ("Open for parms failed with errno = %d\n", errno));
1511 i = read(fd, parms, sbuf.st_size);
1513 if (i != sbuf.st_size) {
1515 ViceLog(0, ("Read on parms failed with errno = %d\n", errno));
1518 ("Read on parms failed; expected %d bytes but read %d\n",
1525 for (i = 0; i < MAXPARMS; argv[i++] = 0);
1527 for (argc = i = 0; i < sbuf.st_size; i++) {
1528 if ((*(parms + i) != ' ') && (*(parms + i) != '\n')) {
1529 if (argv[argc] == 0)
1530 argv[argc] = (parms + i);
1532 *(parms + i) = '\0';
1533 if (argv[argc] != 0) {
1534 if (++argc == MAXPARMS)
1537 while ((*(parms + i + 1) == ' ')
1538 || (*(parms + i + 1) == '\n'))
1542 if (ParseArgs(argc, argv) == 0) {
1543 ViceLog(0, ("Change parameters to:"));
1545 ViceLog(0, ("Invalid parameter in:"));
1547 for (i = 0; i < argc; i++) {
1548 ViceLog(0, (" %s", argv[i]));
1552 } else if (!initializing)
1554 ("Received request to change parms but no parms file exists\n"));
1559 /* Miscellaneous routines */
1563 ViceLog(0, ("%s\n", msg));
1575 * If this fails, it's because something major is wrong, and is not
1576 * likely to be time dependent.
1578 code = pr_Initialize(2, AFSDIR_SERVER_ETC_DIRPATH, 0);
1581 ("Couldn't initialize protection library; code=%d.\n", code));
1585 #ifdef AFS_PTHREAD_ENV
1586 assert(pthread_key_create(&viced_uclient_key, NULL) == 0);
1589 SystemId = SYSADMINID;
1590 SystemAnyUser = ANYUSERID;
1591 SystemAnyUserCPS.prlist_len = 0;
1592 SystemAnyUserCPS.prlist_val = NULL;
1593 AnonCPS.prlist_len = 0;
1594 AnonCPS.prlist_val = NULL;
1596 code = pr_GetCPS(SystemAnyUser, &SystemAnyUserCPS);
1599 ("Couldn't get CPS for AnyUser, will try again in 30 seconds; code=%d.\n",
1603 code = pr_GetCPS(ANONYMOUSID, &AnonCPS);
1606 ("Couldn't get Anonymous CPS, exiting; code=%d.\n",
1610 AnonymousID = ANONYMOUSID;
1613 #ifdef AFS_PTHREAD_ENV
1615 #else /* AFS_PTHREAD_ENV */
1617 #endif /* AFS_PTHREAD_ENV */
1621 struct rx_connection *serverconns[MAXSERVERS];
1622 struct ubik_client *cstruct;
1625 vl_Initialize(const char *confDir)
1627 afs_int32 code, scIndex = 0, i;
1628 struct afsconf_dir *tdir;
1629 struct rx_securityClass *sc;
1630 struct afsconf_cell info;
1632 tdir = afsconf_Open(confDir);
1635 ("Could not open configuration directory (%s).\n", confDir));
1638 code = afsconf_ClientAuth(tdir, &sc, &scIndex);
1640 ViceLog(0, ("Could not get security object for localAuth\n"));
1643 code = afsconf_GetCellInfo(tdir, NULL, AFSCONF_VLDBSERVICE, &info);
1644 if (info.numServers > MAXSERVERS) {
1646 ("vl_Initialize: info.numServers=%d (> MAXSERVERS=%d)\n",
1647 info.numServers, MAXSERVERS));
1650 for (i = 0; i < info.numServers; i++)
1652 rx_NewConnection(info.hostAddr[i].sin_addr.s_addr,
1653 info.hostAddr[i].sin_port, USER_SERVICE_ID, sc,
1655 code = ubik_ClientInit(serverconns, &cstruct);
1656 afsconf_Close(tdir);
1658 ViceLog(0, ("vl_Initialize: ubik client init failed.\n"));
1664 #define SYSIDMAGIC 0x88aabbcc
1665 #define SYSIDVERSION 1
1670 afs_int32 fd, nentries, i;
1671 struct versionStamp vsn;
1672 struct afs_stat status;
1675 if ((afs_stat(AFSDIR_SERVER_SYSID_FILEPATH, &status))
1676 || (status.st_size <= 0)) {
1677 ViceLog(0, ("%s: doesn't exist\n", AFSDIR_SERVER_SYSID_FILEPATH));
1680 if (!(fd = afs_open(AFSDIR_SERVER_SYSID_FILEPATH, O_RDONLY, 0))) {
1682 ("%s: can't open (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1686 if ((i = read(fd, (char *)&vsn, sizeof(vsn))) != sizeof(vsn)) {
1688 ("%s: Read failed (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1692 if (vsn.magic != SYSIDMAGIC) {
1694 ("%s: wrong magic %x (we support %x)\n",
1695 AFSDIR_SERVER_SYSID_FILEPATH, vsn.magic, SYSIDMAGIC));
1698 if (vsn.version != SYSIDVERSION) {
1700 ("%s: wrong version %d (we support %d)\n",
1701 AFSDIR_SERVER_SYSID_FILEPATH, vsn.version, SYSIDVERSION));
1705 read(fd, (char *)&uuid,
1706 sizeof(struct afsUUID))) != sizeof(struct afsUUID)) {
1708 ("%s: read of uuid failed (%d)\n",
1709 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1712 afs_ntohuuid(&uuid);
1715 read(fd, (char *)&nentries,
1716 sizeof(afs_int32))) != sizeof(afs_int32)) {
1718 ("%s: Read of entries failed (%d)\n",
1719 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1722 if (nentries <= 0 || nentries > ADDRSPERSITE) {
1724 ("%s: invalid num of interfaces: %d\n",
1725 AFSDIR_SERVER_SYSID_FILEPATH, nentries));
1728 if (FS_HostAddr_cnt == 0) {
1729 FS_HostAddr_cnt = nentries;
1730 for (i = 0; i < nentries; i++) {
1731 if (read(fd, (char *)&FS_HostAddrs[i], sizeof(afs_int32)) !=
1732 sizeof(afs_int32)) {
1734 ("%s: Read of addresses failed (%d)\n",
1735 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1736 FS_HostAddr_cnt = 0; /* reset it */
1742 ("%s: address list ignored (NetInfo/NetRestrict override)\n",
1743 AFSDIR_SERVER_SYSID_FILEPATH));
1750 WriteSysIdFile(void)
1753 struct versionStamp vsn;
1754 struct afs_stat status;
1757 if (!afs_stat(AFSDIR_SERVER_SYSID_FILEPATH, &status)) {
1759 * File exists; keep the old one around
1761 renamefile(AFSDIR_SERVER_SYSID_FILEPATH,
1762 AFSDIR_SERVER_OLDSYSID_FILEPATH);
1764 fd = afs_open(AFSDIR_SERVER_SYSID_FILEPATH, O_WRONLY | O_TRUNC | O_CREAT,
1768 ("%s: can't create (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1772 vsn.magic = SYSIDMAGIC;
1774 if ((i = write(fd, (char *)&vsn, sizeof(vsn))) != sizeof(vsn)) {
1776 ("%s: write failed (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1781 afs_htonuuid(&uuid);
1783 write(fd, (char *)&uuid,
1784 sizeof(struct afsUUID))) != sizeof(struct afsUUID)) {
1786 ("%s: write of uuid failed (%d)\n",
1787 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1791 write(fd, (char *)&FS_HostAddr_cnt,
1792 sizeof(afs_int32))) != sizeof(afs_int32)) {
1794 ("%s: write of # of entries failed (%d)\n",
1795 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1798 for (i = 0; i < FS_HostAddr_cnt; i++) {
1799 if (write(fd, (char *)&FS_HostAddrs[i], sizeof(afs_int32)) !=
1800 sizeof(afs_int32)) {
1802 ("%s: write of addresses failed (%d)\n",
1803 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1813 * This routine sets up the buffers for the VL_RegisterAddrs RPC. All addresses
1814 * in FS_HostAddrs[] are in NBO, while the RPC treats them as a "blob" of data
1815 * and so we need to convert each of them into HBO which is what the extra
1816 * array called FS_HostAddrs_HBO is used here.
1819 Do_VLRegisterRPC(void)
1823 afs_uint32 FS_HostAddrs_HBO[ADDRSPERSITE];
1826 for (i = 0; i < FS_HostAddr_cnt; i++)
1827 FS_HostAddrs_HBO[i] = ntohl(FS_HostAddrs[i]);
1828 addrs.bulkaddrs_len = FS_HostAddr_cnt;
1829 addrs.bulkaddrs_val = (afs_uint32 *) FS_HostAddrs_HBO;
1830 code = ubik_VL_RegisterAddrs(cstruct, 0, &FS_HostUUID, 0, &addrs);
1832 if (code == VL_MULTIPADDR) {
1834 ("VL_RegisterAddrs rpc failed; The IP address exists on a different server; repair it\n"));
1836 ("VL_RegisterAddrs rpc failed; See VLLog for details\n"));
1838 } else if (code == RXGEN_OPCODE) {
1840 ("vlserver doesn't support VL_RegisterAddrs rpc; ignored\n"));
1841 FS_registered = 2; /* So we don't have to retry in the gc daemon */
1844 ("VL_RegisterAddrs rpc failed; will retry periodically (code=%d, err=%d)\n",
1846 FS_registered = 1; /* Retry in the gc daemon */
1849 FS_registered = 2; /* So we don't have to retry in the gc daemon */
1861 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH || AFSDIR_SERVER_NETINFO_FILEPATH) {
1863 * Find addresses we are supposed to register as per the netrestrict
1864 * and netinfo files (/usr/afs/local/NetInfo and
1865 * /usr/afs/local/NetRestict)
1868 afs_int32 code = parseNetFiles(FS_HostAddrs, NULL, NULL,
1869 ADDRSPERSITE, reason,
1870 AFSDIR_SERVER_NETINFO_FILEPATH,
1871 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
1873 ViceLog(0, ("Can't register any valid addresses: %s\n", reason));
1876 FS_HostAddr_cnt = (afs_uint32) code;
1879 FS_HostAddr_cnt = rx_getAllAddr(FS_HostAddrs, ADDRSPERSITE);
1882 if (FS_HostAddr_cnt == 1 && rxBind == 1)
1883 code = FS_HostAddrs[0];
1885 code = htonl(INADDR_ANY);
1895 * If this fails, it's because something major is wrong, and is not
1896 * likely to be time dependent.
1898 code = vl_Initialize(AFSDIR_SERVER_ETC_DIRPATH);
1901 ("Couldn't initialize protection library; code=%d.\n", code));
1905 /* Read or create the sysid file and register the fileserver's
1906 * IP addresses with the vlserver.
1908 code = ReadSysIdFile();
1910 /* Need to create the file */
1911 ViceLog(0, ("Creating new SysID file\n"));
1912 if ((code = afs_uuid_create(&FS_HostUUID))) {
1913 ViceLog(0, ("Failed to create new uuid: %d\n", code));
1917 /* A good sysid file exists; inform the vlserver. If any conflicts,
1918 * we always use the latest interface available as the real truth.
1921 code = Do_VLRegisterRPC();
1926 main(int argc, char *argv[])
1930 struct rx_securityClass *sc[4];
1931 struct rx_service *tservice;
1932 #ifdef AFS_PTHREAD_ENV
1933 pthread_t serverPid;
1934 pthread_attr_t tattr;
1935 #else /* AFS_PTHREAD_ENV */
1936 PROCESS parentPid, serverPid;
1937 #endif /* AFS_PTHREAD_ENV */
1939 int minVnodesRequired; /* min size of vnode cache */
1940 #ifndef AFS_NT40_ENV
1941 struct rlimit rlim; /* max number of open file descriptors */
1945 afs_uint32 rx_bindhost;
1946 VolumePackageOptions opts;
1948 #ifdef AFS_AIX32_ENV
1949 struct sigaction nsa;
1951 sigemptyset(&nsa.sa_mask);
1952 nsa.sa_handler = SIG_DFL;
1953 nsa.sa_flags = SA_FULLDUMP;
1954 sigaction(SIGABRT, &nsa, NULL);
1955 sigaction(SIGSEGV, &nsa, NULL);
1959 /* Initialize dirpaths */
1960 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
1962 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
1964 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
1968 #ifndef AFS_QUIETFS_ENV
1969 console = afs_fopen("/dev/console", "w");
1971 /* set ihandle package defaults prior to parsing args */
1974 if (ParseArgs(argc, argv)) {
1978 #ifdef AFS_PTHREAD_ENV
1979 assert(pthread_mutex_init(&fileproc_glock_mutex, NULL) == 0);
1980 #endif /* AFS_PTHREAD_ENV */
1982 #ifdef AFS_SGI_VNODE_GLUE
1983 if (afs_init_kernel_config(-1) < 0) {
1985 ("Can't determine NUMA configuration, not starting fileserver.\n");
1989 confDir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
1991 fprintf(stderr, "Unable to open config directory %s\n",
1992 AFSDIR_SERVER_ETC_DIRPATH);
1998 /* Open FileLog on stdout, stderr, fd 1 and fd2 (for perror), sigh. */
1999 #ifndef AFS_NT40_ENV
2000 serverLogSyslogTag = "fileserver";
2002 OpenLog(AFSDIR_SERVER_FILELOG_FILEPATH);
2005 if (SawSpare && SawPctSpare) {
2006 ViceLog(0, ("Both -spare and -pctspare specified, exiting.\n"));
2009 #ifdef AFS_SGI_XFS_IOPS_ENV
2010 ViceLog(0, ("XFS/EFS File server starting\n"));
2012 ViceLog(0, ("File server starting\n"));
2015 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
2016 /* initialize the pthread soft signal handler thread */
2020 /* install signal handlers for controlling the fileserver process */
2021 ResetCheckSignal(); /* set CheckSignal_Signal() sig handler */
2022 ResetCheckDescriptors(); /* set CheckDescriptors_Signal() sig handler */
2024 #if defined(AFS_SGI_ENV)
2025 /* give this guy a non-degrading priority so help busy servers */
2026 schedctl(NDPRI, 0, NDPNORMMAX);
2030 #ifndef AFS_NT40_ENV
2031 nice(-5); /* TODO: */
2034 assert(DInit(buffs) == 0);
2035 #ifdef AFS_DEMAND_ATTACH_FS
2040 if (afs_winsockInit() < 0) {
2041 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
2042 ViceLog(0, ("File server failed to intialize winsock.\n"));
2048 /* if we support more than 16 threads, then we better have the ability
2049 ** to keep open a large number of files simultaneously
2051 #if defined(AFS_AIX_ENV) && !defined(AFS_AIX42_ENV)
2052 curLimit = OPEN_MAX; /* for pre AIX 4.2 systems */
2053 #elif defined(AFS_NT40_ENV)
2054 curLimit = NT_OPEN_MAX; /* open file descriptor limit on NT */
2057 curLimit = 0; /* the number of open file descriptors */
2058 code = getrlimit(RLIMIT_NOFILE, &rlim);
2060 curLimit = rlim.rlim_cur;
2061 rlim.rlim_cur = rlim.rlim_max;
2062 code = setrlimit(RLIMIT_NOFILE, &rlim);
2064 curLimit = rlim.rlim_max;
2067 ViceLog(0, ("Failed to increase open file limit, using default\n"));
2069 #endif /* defined(AFS_AIX_ENV) && !defined(AFS_AIX42_ENV) */
2071 curLimit -= 32; /* leave a slack of 32 file descriptors */
2072 if (lwps > curLimit) {
2076 lwps = 16; /* default to a maximum of 16 threads */
2078 /* tune the ihandle fd cache accordingly */
2079 if (vol_io_params.fd_max_cachesize < curLimit)
2080 vol_io_params.fd_max_cachesize = curLimit + 1;
2083 ("The system supports a max of %d open files and we are starting %d threads (ihandle fd cache is %d)\n",
2084 curLimit, lwps, vol_io_params.fd_max_cachesize));
2086 #ifndef AFS_PTHREAD_ENV
2087 assert(LWP_InitializeProcessSupport(LWP_MAX_PRIORITY - 2, &parentPid) ==
2089 #endif /* !AFS_PTHREAD_ENV */
2091 /* Initialize volume support */
2093 V_BreakVolumeCallbacks = BreakVolumeCallBacksLater;
2096 #ifdef AFS_PTHREAD_ENV
2097 SetLogThreadNumProgram( threadNum );
2100 /* initialize libacl routines */
2101 acl_Initialize(ACL_VERSION);
2103 /* initialize RX support */
2104 #ifndef AFS_NT40_ENV
2105 rxi_syscallp = viced_syscall;
2107 rx_extraPackets = rxpackets;
2108 rx_extraQuota = 4; /* for outgoing prserver calls from R threads */
2109 rx_SetBusyThreshold(busy_threshold, VBUSY);
2110 rx_SetCallAbortThreshold(abort_threshold);
2111 rx_SetConnAbortThreshold(abort_threshold);
2113 stackSize = 128 * 1024;
2115 stackSize = lwps * 4000;
2116 if (stackSize < 32000)
2118 else if (stackSize > 44000)
2121 #if defined(AFS_HPUX_ENV) || defined(AFS_SUN_ENV) || defined(AFS_SGI51_ENV) || defined(AFS_XBSD_ENV)
2122 rx_SetStackSize(1, stackSize);
2125 rx_SetUdpBufSize(udpBufSize); /* set the UDP buffer size for receive */
2126 rx_bindhost = SetupVL();
2128 if (rx_InitHost(rx_bindhost, (int)htons(7000)) < 0) {
2129 ViceLog(0, ("Cannot initialize RX\n"));
2132 if (!rxJumbograms) {
2133 /* Don't send and don't allow 3.4 clients to send jumbograms. */
2136 if (rxMaxMTU != -1) {
2137 rx_SetMaxMTU(rxMaxMTU);
2140 rx_SetRxDeadTime(30);
2141 sc[0] = rxnull_NewServerSecurityObject();
2142 sc[1] = 0; /* rxvab_NewServerSecurityObject(key1, 0) */
2143 sc[2] = rxkad_NewServerSecurityObject(rxkad_clear, NULL, get_key, NULL);
2144 sc[3] = rxkad_NewServerSecurityObject(rxkad_crypt, NULL, get_key, NULL);
2145 tservice = rx_NewServiceHost(rx_bindhost, /* port */ 0, /* service id */
2146 1, /*service name */
2148 /* security classes */ sc,
2149 /* numb sec classes */
2150 4, RXAFS_ExecuteRequest);
2153 ("Failed to initialize RX, probably two servers running.\n"));
2156 if (rxkadDisableDotCheck) {
2157 rx_SetSecurityConfiguration(tservice, RXS_CONFIG_FLAGS,
2158 (void *)RXS_CONFIG_FLAGS_DISABLE_DOTCHECK);
2160 rx_SetMinProcs(tservice, 3);
2161 rx_SetMaxProcs(tservice, lwps);
2162 rx_SetCheckReach(tservice, 1);
2163 rx_SetServerIdleDeadErr(tservice, VNOSERVICE);
2166 rx_NewService(0, RX_STATS_SERVICE_ID, "rpcstats", sc, 4,
2167 RXSTATS_ExecuteRequest);
2169 ViceLog(0, ("Failed to initialize rpc stat service.\n"));
2172 rx_SetMinProcs(tservice, 2);
2173 rx_SetMaxProcs(tservice, 4);
2176 * Enable RX hot threads, which allows the listener thread to trade
2177 * places with an idle thread and moves the context switch from listener
2178 * to worker out of the critical path.
2180 rx_EnableHotThread();
2182 /* Some rx debugging */
2183 if (rxlog || eventlog) {
2184 debugFile = afs_fopen("rx_dbg", "w");
2186 rx_debugFile = debugFile;
2188 rxevent_debugFile = debugFile;
2191 init_sys_error_to_et(); /* Set up error table translation */
2192 h_InitHostPackage(); /* set up local cellname and realmname */
2193 InitCallBack(numberofcbs);
2197 if (code && code != VL_MULTIPADDR) {
2198 ViceLog(0, ("Fatal error in library initialization, exiting!!\n"));
2203 if (code && code != -1) {
2204 ViceLog(0, ("Fatal error in protection initialization, exiting!!\n"));
2208 /* allow super users to manage RX statistics */
2209 rx_SetRxStatUserOk(fs_rxstat_userok);
2211 #ifdef AFS_PTHREAD_ENV
2212 assert(pthread_cond_init(&fsync_cond, NULL) == 0);
2213 assert(pthread_mutex_init(&fsync_glock_mutex, NULL) == 0);
2216 #if !defined(AFS_DEMAND_ATTACH_FS)
2218 * For DAFS, we do not start the Rx server threads until after
2219 * the volume package is initialized, and fileserver state is
2220 * restored. This is necessary in order to keep host and callback
2221 * package state pristine until we have a chance to restore state.
2223 * Furthermore, startup latency is much lower with dafs, so this
2224 * shouldn't pose a serious problem.
2226 rx_StartServer(0); /* now start handling requests */
2229 /* we ensure that there is enough space in the vnode buffer to satisfy
2230 ** requests from all concurrent threads.
2231 ** the maximum number of vnodes used by a single thread at any one time
2232 ** is three ( "link" uses three vnodes simultaneously, one vLarge and
2233 ** two vSmall for linking files and two vLarge and one vSmall for linking
2236 minVnodesRequired = 2 * lwps + 1;
2237 if (minVnodesRequired > nSmallVns) {
2238 nSmallVns = minVnodesRequired;
2240 ("Overriding -s command line parameter with %d\n",
2243 if (minVnodesRequired > large) {
2244 large = minVnodesRequired;
2245 ViceLog(0, ("Overriding -l command line parameter with %d\n", large));
2248 /* We now do this after getting the listener up and running, so that client
2249 * connections don't timeout (maybe) if a file server is restarted, since it
2250 * will be available "real soon now". Worry about whether we can satisfy the
2251 * calls in the volume package itself.
2253 VOptDefaults(fileServer, &opts);
2254 opts.nLargeVnodes = large;
2255 opts.nSmallVnodes = nSmallVns;
2256 opts.volcache = volcache;
2258 if (VInitVolumePackage2(fileServer, &opts)) {
2260 ("Shutting down: errors encountered initializing volume package\n"));
2265 /* Install handler to catch the shutdown signal;
2266 * bosserver assumes SIGQUIT shutdown
2268 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
2269 softsig_signal(SIGQUIT, ShutDown_Signal);
2271 (void)signal(SIGQUIT, ShutDown_Signal);
2274 if (VInitAttachVolumes(fileServer)) {
2276 ("Shutting down: errors encountered initializing volume package\n"));
2281 #ifdef AFS_DEMAND_ATTACH_FS
2282 if (fs_state.options.fs_state_restore) {
2285 * restore fileserver state */
2288 rx_StartServer(0); /* now start handling requests */
2289 #endif /* AFS_DEMAND_ATTACH_FS */
2292 * We are done calling fopen/fdopen. It is safe to use a large
2293 * of the file descriptor cache.
2297 #ifdef AFS_PTHREAD_ENV
2298 ViceLog(5, ("Starting pthreads\n"));
2299 assert(pthread_attr_init(&tattr) == 0);
2300 assert(pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED) == 0);
2302 assert(pthread_create
2303 (&serverPid, &tattr, FiveMinuteCheckLWP,
2304 &fiveminutes) == 0);
2305 assert(pthread_create
2306 (&serverPid, &tattr, HostCheckLWP, &fiveminutes) == 0);
2307 assert(pthread_create
2308 (&serverPid, &tattr, FsyncCheckLWP, &fiveminutes) == 0);
2309 #else /* AFS_PTHREAD_ENV */
2310 ViceLog(5, ("Starting LWP\n"));
2311 assert(LWP_CreateProcess
2312 (FiveMinuteCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
2313 (void *)&fiveminutes, "FiveMinuteChecks",
2314 &serverPid) == LWP_SUCCESS);
2316 assert(LWP_CreateProcess
2317 (HostCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
2318 (void *)&fiveminutes, "HostCheck", &serverPid) == LWP_SUCCESS);
2319 assert(LWP_CreateProcess
2320 (FsyncCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
2321 (void *)&fiveminutes, "FsyncCheck", &serverPid) == LWP_SUCCESS);
2322 #endif /* AFS_PTHREAD_ENV */
2324 FT_GetTimeOfDay(&tp, 0);
2326 #ifndef AFS_QUIETFS_ENV
2327 if (console != NULL) {
2328 time_t t = tp.tv_sec;
2329 fprintf(console, "File server has started at %s\r",
2330 afs_ctime(&t, tbuffer, sizeof(tbuffer)));
2335 * Figure out the FileServer's name and primary address.
2337 ViceLog(0, ("Getting FileServer name...\n"));
2338 code = gethostname(FS_HostName, 64);
2340 ViceLog(0, ("gethostname() failed\n"));
2342 ViceLog(0, ("FileServer host name is '%s'\n", FS_HostName));
2344 ViceLog(0, ("Getting FileServer address...\n"));
2345 he = gethostbyname(FS_HostName);
2347 ViceLog(0, ("Can't find address for FileServer '%s'\n", FS_HostName));
2350 memcpy(&FS_HostAddr_NBO, he->h_addr, 4);
2351 (void)afs_inet_ntoa_r(FS_HostAddr_NBO, hoststr);
2352 FS_HostAddr_HBO = ntohl(FS_HostAddr_NBO);
2354 ("FileServer %s has address %s (0x%x or 0x%x in host byte order)\n",
2355 FS_HostName, hoststr, FS_HostAddr_NBO, FS_HostAddr_HBO));
2360 ("File Server started %s",
2361 afs_ctime(&t, tbuffer, sizeof(tbuffer))));
2362 #if FS_STATS_DETAILED
2363 afs_FullPerfStats.det.epoch.tv_sec = StartTime = tp.tv_sec;
2365 #ifdef AFS_PTHREAD_ENV
2367 sleep(1000); /* long time */
2369 #else /* AFS_PTHREAD_ENV */
2370 assert(LWP_WaitProcess(&parentPid) == LWP_SUCCESS);
2371 #endif /* AFS_PTHREAD_ENV */