2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
9 * Portions Copyright (c) 2006 Sine Nomine Associates
12 /* viced.c - File Server main loop */
16 /* Function - This routine has the initialization code for */
19 /* ********************************************************************** */
21 #include <afsconfig.h>
22 #include <afs/param.h>
29 #include <sys/types.h>
30 #include <afs/procmgmt.h> /* signal(), kill(), wait(), etc. */
39 #include <WINNT/afsevent.h>
42 #include <netinet/in.h>
44 #include <unistd.h> /* sysconf() */
48 #endif /* ITIMER_REAL */
49 #include <sys/resource.h>
50 #endif /* AFS_NT40_ENV */
55 #ifdef AFS_PTHREAD_ENV
57 #else /* AFS_PTHREAD_ENV */
58 #include <afs/assert.h>
59 #endif /* AFS_PTHREAD_ENV */
62 #include <afs/ptclient.h>
63 #include <afs/afsint.h>
64 #include <afs/vldbint.h>
65 #include <afs/errors.h>
66 #include <afs/ihandle.h>
67 #include <afs/vnode.h>
68 #include <afs/volume.h>
70 #include <afs/cellconfig.h>
72 #include <afs/prs_fs.h>
74 #include <rx/rxstat.h>
76 #include <afs/afs_args.h>
77 #include <afs/vlserver.h>
78 #include <afs/afsutil.h>
79 #include <afs/fileutil.h>
80 #include <afs/ptuser.h>
81 #include <afs/audit.h>
82 #include <afs/partition.h>
85 #include <afs/netutils.h>
87 #include "viced_prototypes.h"
90 #ifdef AFS_PTHREAD_ENV
91 #include <afs/softsig.h>
93 #if defined(AFS_SGI_ENV)
94 #include "sys/schedctl.h"
97 #include <rx/rx_globals.h>
100 #define afs_stat stat64
101 #define afs_fstat fstat64
102 #define afs_open open64
103 #define afs_fopen fopen64
104 #else /* !O_LARGEFILE */
105 #define afs_stat stat
106 #define afs_fstat fstat
107 #define afs_open open
108 #define afs_fopen fopen
109 #endif /* !O_LARGEFILE */
113 void *ShutDown(void *);
114 static void ClearXStatValues(void);
115 static void NewParms(int);
116 static void PrintCounters(void);
117 static void ResetCheckDescriptors(void);
118 static void ResetCheckSignal(void);
119 static void *CheckSignal(void *);
121 static afs_int32 Do_VLRegisterRPC(void);
123 int eventlog = 0, rxlog = 0;
126 #ifdef AFS_PTHREAD_ENV
127 pthread_mutex_t fsync_glock_mutex;
128 pthread_cond_t fsync_cond;
131 #endif /* AFS_PTHREAD_ENV */
134 #define NT_OPEN_MAX 1024 /* This is an arbitrary no. we came up with for
135 * now. We hope this will be replaced by a more
136 * intelligent estimate later. */
139 int SystemId; /* ViceID of "Administrators" */
140 int SystemAnyUser; /* Viceid of "System:AnyUser" */
141 prlist SystemAnyUserCPS; /* CPS for "system:AnyUser */
142 int AnonymousID = 0; /* ViceId of "Anonymous" */
143 prlist AnonCPS; /* CPS for "Anonymous" */
145 struct afsconf_dir *confDir; /* Configuration dir object */
147 int restartMode = RESTART_ORDINARY;
150 * Home for the performance statistics.
152 struct afs_PerfStats afs_perfstats;
155 extern int Statistics;
163 int rxJumbograms = 0; /* default is to not send and receive jumbograms. */
164 int rxBind = 0; /* don't bind */
165 int rxkadDisableDotCheck = 0; /* disable check for dot in principal name */
167 afs_int32 implicitAdminRights = PRSFS_LOOKUP; /* The ADMINISTER right is
169 afs_int32 readonlyServer = 0;
172 int stackSize = 24000;
173 int fiveminutes = 300; /* 5 minutes. Change this for debugging only */
174 int CurrentConnections = 0;
175 int hostaclRefresh = 7200; /* refresh host clients' acls every 2 hrs */
176 #if defined(AFS_SGI_ENV)
182 * seconds to wait until forcing a panic during ShutDownAndCore(PANIC)
183 * in case we get stuck.
185 #ifdef AFS_DEMAND_ATTACH_FS
186 static int panic_timeout = 2 * 60;
188 static int panic_timeout = 30 * 60;
191 int rxpackets = 150; /* 100 */
192 int nSmallVns = 400; /* 200 */
193 int large = 400; /* 200 */
194 int volcache = 400; /* 400 */
195 int numberofcbs = 60000; /* 60000 */
196 int lwps = 9; /* 6 */
197 int buffs = 90; /* 70 */
198 int novbc = 0; /* Enable Volume Break calls */
199 int busy_threshold = 600;
200 int abort_threshold = 10;
201 int udpBufSize = 0; /* UDP buffer size for receive */
202 int sendBufSize = 16384; /* send buffer size */
203 int saneacls = 0; /* Sane ACLs Flag */
204 static int unsafe_attach = 0; /* avoid inUse check on vol attach? */
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 assert(pthread_cond_init(&fs_state.worker_done_cv, NULL) == 0);
273 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 assert(pthread_cond_broadcast(&fs_state.worker_done_cv)==0);
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 assert(pthread_cond_broadcast(&fs_state.worker_done_cv)==0);
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;
601 pthread_cond_timedwait(&fsync_cond, &fsync_glock_mutex,
603 if (code != 0 && code != ETIMEDOUT)
604 ViceLog(0, ("pthread_cond_timedwait returned %d\n", code));
605 #else /* AFS_PTHREAD_ENV */
606 if ((code = LWP_WaitProcess(fsync_wait)) != LWP_SUCCESS)
607 ViceLog(0, ("LWP_WaitProcess returned %d\n", code));
608 #endif /* AFS_PTHREAD_ENV */
611 #ifdef AFS_DEMAND_ATTACH_FS
613 if (fs_state.mode != FS_MODE_NORMAL) {
616 fs_state.FsyncCheckLWP_tranquil = 0;
618 #endif /* AFS_DEMAND_ATTACH_FS */
620 ViceLog(2, ("Checking for fsync events\n"));
622 code = BreakLaterCallBacks();
624 #ifdef AFS_DEMAND_ATTACH_FS
628 #ifdef AFS_DEMAND_ATTACH_FS
629 fs_state.FsyncCheckLWP_tranquil = 1;
631 assert(pthread_cond_broadcast(&fs_state.worker_done_cv)==0);
634 #endif /* AFS_DEMAND_ATTACH_FS */
638 /*------------------------------------------------------------------------
639 * PRIVATE ClearXStatValues
642 * Initialize all of the values collected via the xstat
652 * Must be called during File Server initialization.
656 *------------------------------------------------------------------------*/
659 ClearXStatValues(void)
660 { /*ClearXStatValues */
662 struct fs_stats_opTimingData *opTimeP; /*Ptr to timing struct */
663 struct fs_stats_xferData *opXferP; /*Ptr to xfer struct */
664 int i; /*Loop counter */
667 * Zero all xstat-related structures.
669 memset((&afs_perfstats), 0, sizeof(struct afs_PerfStats));
670 #if FS_STATS_DETAILED
671 memset((&afs_FullPerfStats), 0,
672 sizeof(struct fs_stats_FullPerfStats));
675 * That's not enough. We have to set reasonable minima for
676 * time and xfer values in the detailed stats.
678 opTimeP = &(afs_FullPerfStats.det.rpcOpTimes[0]);
679 for (i = 0; i < FS_STATS_NUM_RPC_OPS; i++, opTimeP++)
680 opTimeP->minTime.tv_sec = 999999;
682 opXferP = &(afs_FullPerfStats.det.xferOpTimes[0]);
683 for (i = 0; i < FS_STATS_NUM_XFER_OPS; i++, opXferP++) {
684 opXferP->minTime.tv_sec = 999999;
685 opXferP->minBytes = 999999999;
689 * There's more. We have to set our unique system identifier, as
690 * declared in param.h. If such a thing is not defined, we bitch
691 * and declare ourselves to be an unknown system type.
694 afs_perfstats.sysname_ID = SYS_NAME_ID;
697 ViceLog(0, ("Sys name ID constant not defined in param.h!!\n"));
698 ViceLog(0, ("[Choosing ``undefined'' sys name ID.\n"));
700 afs_perfstats.sysname_ID = SYS_NAME_ID_UNDEFINED;
701 #endif /* SYS_NAME_ID */
704 } /*ClearXStatValues */
706 int CopyOnWrite_calls = 0, CopyOnWrite_off0 = 0, CopyOnWrite_size0 = 0;
707 afs_fsize_t CopyOnWrite_maxsize = 0;
712 int dirbuff, dircall, dirio;
714 int workstations, activeworkstations, delworkstations;
718 FT_GetTimeOfDay(&tpl, 0);
721 ("Vice was last started at %s\n",
722 afs_ctime(&StartTime, tbuffer, sizeof(tbuffer))));
724 #ifdef AFS_DEMAND_ATTACH_FS
725 /* XXX perhaps set extended stats verbosity flags
726 * based upon LogLevel ?? */
727 VPrintExtendedCacheStats(VOL_STATS_PER_CHAIN2);
731 DStat(&dirbuff, &dircall, &dirio);
733 ("With %d directory buffers; %d reads resulted in %d read I/Os\n",
734 dirbuff, dircall, dirio));
735 rx_PrintStats(stderr);
736 audit_PrintStats(stderr);
738 PrintCallBackStats();
740 processSize = -1; /* TODO: */
742 processSize = (int)((long)sbrk(0) >> 10);
745 ("There are %d connections, process size %d\n",
746 CurrentConnections, processSize));
747 h_GetWorkStats(&workstations, &activeworkstations, &delworkstations,
748 tpl.tv_sec - 15 * 60);
750 ("There are %d workstations, %d are active (req in < 15 mins), %d marked \"down\"\n",
751 workstations, activeworkstations, delworkstations));
752 ViceLog(0, ("CopyOnWrite: calls %d off0 %d size0 %d maxsize 0x%llx\n",
753 CopyOnWrite_calls, CopyOnWrite_off0, CopyOnWrite_size0, CopyOnWrite_maxsize));
762 CheckSignal(void *unused)
764 if (FS_registered > 0) {
766 * We have proper ip addresses; tell the vlserver what we got; the following
767 * routine will do the proper reporting for us
780 ShutdownWatchdogLWP(void *unused)
782 sleep(panic_timeout);
783 ViceLog(0, ("ShutdownWatchdogLWP: Failed to shutdown and panic "
784 "within %d seconds; forcing panic\n", panic_timeout));
790 ShutDownAndCore(int dopanic)
792 time_t now = time(0);
796 #ifdef AFS_PTHREAD_ENV
797 pthread_t watchdogPid;
798 pthread_attr_t tattr;
799 assert(pthread_attr_init(&tattr) == 0);
800 assert(pthread_create(&watchdogPid, &tattr, ShutdownWatchdogLWP, NULL) == 0);
803 assert(LWP_CreateProcess
804 (ShutdownWatchdogLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
805 NULL, "ShutdownWatchdog", &watchdogPid) == LWP_SUCCESS);
809 /* do not allows new reqests to be served from now on, all new requests
810 * are returned with an error code of RX_RESTARTING ( transient failure ) */
811 rx_SetRxTranquil(); /* dhruba */
815 #ifdef AFS_DEMAND_ATTACH_FS
817 if (fs_state.mode == FS_MODE_SHUTDOWN) {
818 /* it is possible for at least fs_stateSave() (called below) to call
819 * ShutDownAndCore if there's host list corruption; prevent
820 * deinitializing some stuff twice */
821 ViceLog(0, ("ShutDownAndCore called during shutdown? Skipping volume "
822 "and host package shutdown\n"));
826 fs_state.mode = FS_MODE_SHUTDOWN;
831 ("Shutting down file server at %s",
832 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
834 ViceLog(0, ("ABNORMAL SHUTDOWN, see core file.\n"));
839 /* shut down volume package */
842 #ifdef AFS_DEMAND_ATTACH_FS
843 if (fs_state.options.fs_state_save) {
846 * save fileserver state to disk */
849 ViceLog(0, ("Not saving fileserver state; abnormal shutdown\n"));
852 /* make sure background threads have finished all of their asynchronous
853 * work on host and callback structures */
855 while (!fs_state.FiveMinuteLWP_tranquil ||
856 !fs_state.HostCheckLWP_tranquil ||
857 !fs_state.FsyncCheckLWP_tranquil) {
860 ViceLog(0, ("waiting for background host/callback threads to quiesce before saving fileserver state...\n"));
861 assert(pthread_cond_wait(&fs_state.worker_done_cv, &fileproc_glock_mutex) == 0);
867 /* ok. it should now be fairly safe. let's do the state dump */
873 #endif /* AFS_DEMAND_ATTACH_FS */
876 rx_PrintStats(debugFile);
882 ("File server has terminated abnormally at %s\n",
883 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
886 ("File server has terminated normally at %s\n",
887 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
897 ShutDown(void *unused)
898 { /* backward compatibility */
899 ShutDownAndCore(DONTPANIC);
907 /* default supports help flag */
909 fputs("Usage: fileserver ", stdout);
910 fputs("[-auditlog <log path>] ", stdout);
911 fputs("[-audit-interface <file|sysvmq> (default is file)] ", stdout);
912 fputs("[-d <debug level>] ", stdout);
913 fputs("[-p <number of processes>] ", stdout);
914 fputs("[-spare <number of spare blocks>] ", stdout);
915 fputs("[-pctspare <percentage spare>] ", stdout);
916 fputs("[-b <buffers>] ", stdout);
917 fputs("[-l <large vnodes>] ", stdout);
918 fputs("[-s <small vnodes>] ", stdout);
919 fputs("[-vc <volume cachesize>] ", stdout);
920 fputs("[-w <call back wait interval>] ", stdout);
921 fputs("[-cb <number of call backs>] ", stdout);
922 fputs("[-banner (print banner every 10 minutes)] ", stdout);
923 fputs("[-novbc (whole volume cbs disabled)] ", stdout);
924 fputs("[-implicit <admin mode bits: rlidwka>] ", stdout);
925 fputs("[-readonly (read-only file server)] ", stdout);
926 fputs("[-hr <number of hours between refreshing the host cps>] ", stdout);
927 fputs("[-busyat <redirect clients when queue > n>] ", stdout);
928 fputs("[-nobusy <no VBUSY before a volume is attached>] ", stdout);
929 fputs("[-rxpck <number of rx extra packets>] ", stdout);
930 fputs("[-rxdbg (enable rx debugging)] ", stdout);
931 fputs("[-rxdbge (enable rxevent debugging)] ", stdout);
932 fputs("[-rxmaxmtu <bytes>] ", stdout);
933 fputs("[-rxbind (bind the Rx socket to one address)] ", stdout);
934 fputs("[-allow-dotted-principals (disable the rxkad principal name dot check)] ", stdout);
935 fputs("[-vhandle-setaside (fds reserved for non-cache io [default 128])] ", stdout);
936 fputs("[-vhandle-max-cachesize (max open files [default 128])] ", stdout);
937 fputs("[-vhandle-initial-cachesize (fds reserved for cache io [default 128])] ", stdout);
938 #ifdef AFS_DEMAND_ATTACH_FS
939 fputs("[-fs-state-dont-save (disable state save during shutdown)] ", stdout);
940 fputs("[-fs-state-dont-restore (disable state restore during startup)] ", stdout);
941 fputs("[-fs-state-verify <none|save|restore|both> (default is both)] ", stdout);
942 fputs("[-vattachpar <max number of volume attach/shutdown threads> (default is 1)] ", stdout);
943 fputs("[-vhashsize <log(2) of number of volume hash buckets> (default is 8)] ", stdout);
944 fputs("[-vlrudisable (disable VLRU functionality)] ", stdout);
945 fputs("[-vlruthresh <minutes before unused volumes become eligible for soft detach> (default is 2 hours)] ", stdout);
946 fputs("[-vlruinterval <seconds between VLRU scans> (default is 2 minutes)] ", stdout);
947 fputs("[-vlrumax <max volumes to soft detach in one VLRU scan> (default is 8)] ", stdout);
948 fputs("[-unsafe-nosalvage (bypass volume inUse safety check on attach, bypassing salvage)] ", stdout);
949 #elif AFS_PTHREAD_ENV
950 fputs("[-vattachpar <number of volume attach threads> (default is 1)] ", stdout);
953 fputs("[-m <min percentage spare in partition>] ", stdout);
955 #if defined(AFS_SGI_ENV)
956 fputs("[-lock (keep fileserver from swapping)] ", stdout);
958 fputs("[-L (large server conf)] ", stdout);
959 fputs("[-S (small server conf)] ", stdout);
960 fputs("[-k <stack size>] ", stdout);
961 fputs("[-realm <Kerberos realm name>] ", stdout);
962 fputs("[-udpsize <size of socket buffer in bytes>] ", stdout);
963 fputs("[-sendsize <size of send buffer in bytes>] ", stdout);
964 fputs("[-abortthreshold <abort threshold>] ", stdout);
965 fputs("[-nojumbo (disable jumbogram network packets - deprecated)] ", stdout);
966 fputs("[-jumbo (enable jumbogram network packets)] ", stdout);
967 /* fputs("[-enable_peer_stats] ", stdout); */
968 /* fputs("[-enable_process_stats] ", stdout); */
969 fputs("[-help]\n", stdout);
971 ViceLog(0, ("%s", buffer));
980 ParseRights(char *arights)
986 if (!arights || !strcmp(arights, "")) {
987 printf("Missing list of mode bits on -implicit option\n");
990 if (!strcmp(arights, "none"))
992 else if (!strcmp(arights, "read"))
993 mode = PRSFS_READ | PRSFS_LOOKUP;
994 else if (!strcmp(arights, "write"))
996 PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
997 PRSFS_WRITE | PRSFS_LOCK;
998 else if (!strcmp(arights, "all"))
1000 PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
1001 PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER;
1003 len = strlen(arights);
1004 for (i = 0; i < len; i++) {
1009 mode |= PRSFS_LOOKUP;
1011 mode |= PRSFS_INSERT;
1013 mode |= PRSFS_DELETE;
1015 mode |= PRSFS_WRITE;
1019 mode |= PRSFS_ADMINISTER;
1037 printf("Illegal -implicit rights character '%c'.\n", tc);
1046 * Limit MAX_FILESERVER_THREAD by the system limit on the number of
1047 * pthreads (sysconf(_SC_THREAD_THREADS_MAX)), if applicable and
1050 * AIX: sysconf() limit is real
1051 * HP-UX: sysconf() limit is real
1052 * IRIX: sysconf() limit is apparently NOT real -- too small
1053 * DUX: sysconf() limit is apparently NOT real -- too big
1054 * Linux: sysconf() limit is apparently NOT real -- too big
1055 * Solaris: no sysconf() limit
1058 max_fileserver_thread(void)
1060 #if defined(AFS_PTHREAD_ENV)
1061 #if defined(AFS_AIX_ENV) || defined(AFS_HPUX_ENV)
1064 ans = sysconf(_SC_THREAD_THREADS_MAX);
1065 if (0 < ans && ans < MAX_FILESERVER_THREAD)
1068 #endif /* defined(AFS_PTHREAD_ENV) */
1069 return MAX_FILESERVER_THREAD;
1072 /* from ihandle.c */
1073 extern ih_init_params vol_io_params;
1076 ParseArgs(int argc, char *argv[])
1078 int SawL = 0, SawS = 0, SawVC = 0;
1079 int Sawrxpck = 0, Sawsmall = 0, Sawlarge = 0, Sawcbs = 0, Sawlwps =
1083 int bufSize = 0; /* temp variable to read in udp socket buf size */
1084 char *auditFileName = NULL;
1086 for (i = 1; i < argc; i++) {
1087 if (!strcmp(argv[i], "-d")) {
1088 if ((i + 1) >= argc) {
1089 fprintf(stderr, "missing argument for -d\n");
1092 debuglevel = atoi(argv[++i]);
1093 LogLevel = debuglevel;
1094 } else if (!strcmp(argv[i], "-banner")) {
1096 } else if (!strcmp(argv[i], "-implicit")) {
1097 if ((i + 1) >= argc) {
1098 fprintf(stderr, "missing argument for -implicit\n");
1101 implicitAdminRights = ParseRights(argv[++i]);
1102 if (implicitAdminRights < 0)
1103 return implicitAdminRights;
1104 } else if (!strcmp(argv[i], "-readonly")) {
1106 } else if (!strcmp(argv[i], "-L")) {
1108 } else if (!strcmp(argv[i], "-S")) {
1110 } else if (!strcmp(argv[i], "-p")) {
1112 max_fileserver_thread() - FILESERVER_HELPER_THREADS;
1114 if ((i + 1) >= argc) {
1115 fprintf(stderr, "missing argument for -p\n");
1118 lwps = atoi(argv[++i]);
1119 if (lwps > lwps_max)
1123 } else if (!strcmp(argv[i], "-b")) {
1125 if ((i + 1) >= argc) {
1126 fprintf(stderr, "missing argument for -b\n");
1129 buffs = atoi(argv[++i]);
1130 } else if (!strcmp(argv[i], "-l")) {
1132 if ((i + 1) >= argc) {
1133 fprintf(stderr, "missing argument for -l\n");
1136 large = atoi(argv[++i]);
1137 } else if (!strcmp(argv[i], "-vc")) {
1139 if ((i + 1) >= argc) {
1140 fprintf(stderr, "missing argument for -vc\n");
1143 volcache = atoi(argv[++i]);
1144 } else if (!strcmp(argv[i], "-novbc")) {
1146 } else if (!strcmp(argv[i], "-rxpck")) {
1148 if ((i + 1) >= argc) {
1149 fprintf(stderr, "missing argument for -rxpck\n");
1152 rxpackets = atoi(argv[++i]);
1153 #ifdef AFS_PTHREAD_ENV
1154 } else if (!strcmp(argv[i], "-vattachpar")) {
1155 if ((i + 1) >= argc) {
1156 fprintf(stderr, "missing argument for %s\n", argv[i]);
1159 vol_attach_threads = atoi(argv[++i]);
1160 #endif /* AFS_PTHREAD_ENV */
1161 } else if (!strcmp(argv[i], "-vhandle-setaside")) {
1162 if ((i + 1) >= argc) {
1163 fprintf(stderr, "missing argument for %s\n", argv[i]);
1166 vol_io_params.fd_handle_setaside = atoi(argv[++i]);
1167 } else if (!strcmp(argv[i], "-vhandle-max-cachesize")) {
1168 if ((i + 1) >= argc) {
1169 fprintf(stderr, "missing argument for %s\n", argv[i]);
1172 vol_io_params.fd_max_cachesize = atoi(argv[++i]);
1173 } else if (!strcmp(argv[i], "-vhandle-initial-cachesize")) {
1174 if ((i + 1) >= argc) {
1175 fprintf(stderr, "missing argument for %s\n", argv[i]);
1178 vol_io_params.fd_initial_cachesize = atoi(argv[++i]);
1179 #ifdef AFS_DEMAND_ATTACH_FS
1180 } else if (!strcmp(argv[i], "-fs-state-dont-save")) {
1181 fs_state.options.fs_state_save = 0;
1182 } else if (!strcmp(argv[i], "-fs-state-dont-restore")) {
1183 fs_state.options.fs_state_restore = 0;
1184 } else if (!strcmp(argv[i], "-fs-state-verify")) {
1185 if ((i + 1) >= argc) {
1186 fprintf(stderr, "missing argument for %s\n", argv[i]);
1190 if (!strcmp(argv[i], "none")) {
1191 fs_state.options.fs_state_verify_before_save = 0;
1192 fs_state.options.fs_state_verify_after_restore = 0;
1193 } else if (!strcmp(argv[i], "save")) {
1194 fs_state.options.fs_state_verify_after_restore = 0;
1195 } else if (!strcmp(argv[i], "restore")) {
1196 fs_state.options.fs_state_verify_before_save = 0;
1197 } else if (!strcmp(argv[i], "both")) {
1200 fprintf(stderr, "invalid argument for %s\n", argv[i-1]);
1203 } else if (!strcmp(argv[i], "-vhashsize")) {
1205 if ((i + 1) >= argc) {
1206 fprintf(stderr, "missing argument for %s\n", argv[i]);
1209 hashsize = atoi(argv[++i]);
1210 if (VSetVolHashSize(hashsize)) {
1211 fprintf(stderr, "specified -vhashsize (%s) is invalid or out "
1212 "of range\n", argv[i]);
1215 } else if (!strcmp(argv[i], "-vlrudisable")) {
1216 VLRU_SetOptions(VLRU_SET_ENABLED, 0);
1217 } else if (!strcmp(argv[i], "-vlruthresh")) {
1218 if ((i + 1) >= argc) {
1219 fprintf(stderr, "missing argument for %s\n", argv[i]);
1222 VLRU_SetOptions(VLRU_SET_THRESH, 60*atoi(argv[++i]));
1223 } else if (!strcmp(argv[i], "-vlruinterval")) {
1224 if ((i + 1) >= argc) {
1225 fprintf(stderr, "missing argument for %s\n", argv[i]);
1228 VLRU_SetOptions(VLRU_SET_INTERVAL, atoi(argv[++i]));
1229 } else if (!strcmp(argv[i], "-vlrumax")) {
1230 if ((i + 1) >= argc) {
1231 fprintf(stderr, "missing argument for %s\n", argv[i]);
1234 VLRU_SetOptions(VLRU_SET_MAX, atoi(argv[++i]));
1235 } else if (!strcmp(argv[i], "-unsafe-nosalvage")) {
1237 #endif /* AFS_DEMAND_ATTACH_FS */
1238 } else if (!strcmp(argv[i], "-s")) {
1240 if ((i + 1) >= argc) {
1241 fprintf(stderr, "missing argument for -s\n");
1244 nSmallVns = atoi(argv[++i]);
1245 } else if (!strcmp(argv[i], "-abortthreshold")) {
1246 if ((i + 1) >= argc) {
1247 fprintf(stderr, "missing argument for -abortthreshold\n");
1250 abort_threshold = atoi(argv[++i]);
1251 } else if (!strcmp(argv[i], "-k")) {
1252 if ((i + 1) >= argc) {
1253 fprintf(stderr, "missing argument for -k\n");
1256 stack = atoi(argv[++i]);
1258 #if defined(AFS_SGI_ENV)
1259 else if (!strcmp(argv[i], "-lock")) {
1263 else if (!strcmp(argv[i], "-spare")) {
1264 if ((i + 1) >= argc) {
1265 fprintf(stderr, "missing argument for -spare\n");
1268 BlocksSpare = atoi(argv[++i]);
1270 } else if (!strcmp(argv[i], "-pctspare")) {
1271 if ((i + 1) >= argc) {
1272 fprintf(stderr, "missing argument for -pctspare\n");
1275 PctSpare = atoi(argv[++i]);
1276 BlocksSpare = 0; /* has non-zero default */
1278 } else if (!strcmp(argv[i], "-w")) {
1279 if ((i + 1) >= argc) {
1280 fprintf(stderr, "missing argument for -w\n");
1283 fiveminutes = atoi(argv[++i]);
1284 } else if (!strcmp(argv[i], "-hr")) {
1286 if ((i + 1) >= argc) {
1287 fprintf(stderr, "missing argument for -hr\n");
1290 hr = atoi(argv[++i]);
1291 if ((hr < 1) || (hr > 36)) {
1293 ("host acl refresh interval of %d hours is invalid; hours must be between 1 and 36\n\n",
1297 hostaclRefresh = hr * 60 * 60;
1298 } else if (!strcmp(argv[i], "-rxdbg"))
1300 else if (!strcmp(argv[i], "-rxdbge"))
1302 else if (!strcmp(argv[i], "-cb")) {
1304 if ((i + 1) >= argc) {
1305 fprintf(stderr, "missing argument for -cb\n");
1308 numberofcbs = atoi(argv[++i]);
1309 if ((numberofcbs < 10000) || (numberofcbs > 2147483647)) {
1311 ("number of cbs %d invalid; must be between 10000 and 2147483647\n",
1315 } else if (!strcmp(argv[i], "-busyat")) {
1317 if ((i + 1) >= argc) {
1318 fprintf(stderr, "missing argument for -busyat\n");
1321 busy_threshold = atoi(argv[++i]);
1322 if (busy_threshold < 10) {
1324 ("Busy threshold %d is too low, will compute default.\n",
1328 } else if (!strcmp(argv[i], "-nobusy"))
1330 #ifdef AFS_AIX32_ENV
1331 else if (!strcmp(argv[i], "-m")) {
1332 extern int aixlow_water;
1333 if ((i + 1) >= argc) {
1334 fprintf(stderr, "missing argument for -m\n");
1337 aixlow_water = atoi(argv[++i]);
1338 if ((aixlow_water < 0) || (aixlow_water > 30)) {
1339 printf("space reserved %d% invalid; must be between 0-30%\n",
1345 else if (!strcmp(argv[i], "-nojumbo")) {
1347 } else if (!strcmp(argv[i], "-jumbo")) {
1349 } else if (!strcmp(argv[i], "-rxbind")) {
1351 } else if (!strcmp(argv[i], "-allow-dotted-principals")) {
1352 rxkadDisableDotCheck = 1;
1353 } else if (!strcmp(argv[i], "-rxmaxmtu")) {
1354 if ((i + 1) >= argc) {
1355 fprintf(stderr, "missing argument for -rxmaxmtu\n");
1358 rxMaxMTU = atoi(argv[++i]);
1359 if ((rxMaxMTU < RX_MIN_PACKET_SIZE) ||
1360 (rxMaxMTU > RX_MAX_PACKET_DATA_SIZE)) {
1361 printf("rxMaxMTU %d%% invalid; must be between %d-%" AFS_SIZET_FMT "\n",
1362 rxMaxMTU, RX_MIN_PACKET_SIZE,
1363 RX_MAX_PACKET_DATA_SIZE);
1366 } else if (!strcmp(argv[i], "-realm")) {
1367 extern char local_realms[AFS_NUM_LREALMS][AFS_REALM_SZ];
1368 extern int num_lrealms;
1369 if ((i + 1) >= argc) {
1370 fprintf(stderr, "missing argument for -realm\n");
1373 if (strlen(argv[++i]) >= AFS_REALM_SZ) {
1375 ("-realm argument must contain fewer than %d characters.\n",
1379 if (num_lrealms == -1)
1381 if (num_lrealms >= AFS_NUM_LREALMS) {
1383 ("a maximum of %d -realm arguments can be specified.\n",
1387 strncpy(local_realms[num_lrealms++], argv[i], AFS_REALM_SZ);
1388 } else if (!strcmp(argv[i], "-udpsize")) {
1389 if ((i + 1) >= argc) {
1390 printf("You have to specify -udpsize <integer value>\n");
1393 bufSize = atoi(argv[++i]);
1394 if (bufSize < rx_GetMinUdpBufSize())
1396 ("Warning:udpsize %d is less than minimum %d; ignoring\n",
1397 bufSize, rx_GetMinUdpBufSize());
1399 udpBufSize = bufSize;
1400 } else if (!strcmp(argv[i], "-sendsize")) {
1401 if ((i + 1) >= argc) {
1402 printf("You have to specify -sendsize <integer value>\n");
1405 bufSize = atoi(argv[++i]);
1406 if (bufSize < 16384)
1408 ("Warning:sendsize %d is less than minimum %d; ignoring\n",
1411 sendBufSize = bufSize;
1412 } else if (!strcmp(argv[i], "-enable_peer_stats")) {
1413 rx_enablePeerRPCStats();
1414 } else if (!strcmp(argv[i], "-enable_process_stats")) {
1415 rx_enableProcessRPCStats();
1417 else if (strcmp(argv[i], "-auditlog") == 0) {
1418 auditFileName = argv[++i];
1420 else if (strcmp(argv[i], "-audit-interface") == 0) {
1421 char *interface = argv[++i];
1423 if (osi_audit_interface(interface)) {
1424 printf("Invalid audit interface '%s'\n", interface);
1428 #ifndef AFS_NT40_ENV
1429 else if (strcmp(argv[i], "-syslog") == 0) {
1430 /* set syslog logging flag */
1431 serverLogSyslog = 1;
1432 } else if (strncmp(argv[i], "-syslog=", 8) == 0) {
1433 serverLogSyslog = 1;
1434 serverLogSyslogFacility = atoi(argv[i] + 8);
1437 else if (strcmp(argv[i], "-mrafslogs") == 0) {
1438 /* set syslog logging flag */
1441 else if (strcmp(argv[i], "-saneacls") == 0) {
1449 printf("Only one of -L, or -S must be specified\n");
1460 numberofcbs = 20000;
1476 numberofcbs = 64000;
1485 busy_threshold = 3 * rxpackets / 2;
1487 osi_audit_file(auditFileName);
1497 NewParms(int initializing)
1499 static struct afs_stat sbuf;
1502 char *argv[MAXPARMS];
1505 if (!(afs_stat("/vice/file/parms", &sbuf))) {
1506 parms = (char *)malloc(sbuf.st_size);
1509 fd = afs_open("parms", O_RDONLY, 0666);
1511 ViceLog(0, ("Open for parms failed with errno = %d\n", errno));
1515 i = read(fd, parms, sbuf.st_size);
1517 if (i != sbuf.st_size) {
1519 ViceLog(0, ("Read on parms failed with errno = %d\n", errno));
1522 ("Read on parms failed; expected %ld bytes but read %d\n",
1523 (long) sbuf.st_size, i));
1529 for (i = 0; i < MAXPARMS; argv[i++] = 0);
1531 for (argc = i = 0; i < sbuf.st_size; i++) {
1532 if ((*(parms + i) != ' ') && (*(parms + i) != '\n')) {
1533 if (argv[argc] == 0)
1534 argv[argc] = (parms + i);
1536 *(parms + i) = '\0';
1537 if (argv[argc] != 0) {
1538 if (++argc == MAXPARMS)
1541 while ((*(parms + i + 1) == ' ')
1542 || (*(parms + i + 1) == '\n'))
1546 if (ParseArgs(argc, argv) == 0) {
1547 ViceLog(0, ("Change parameters to:"));
1549 ViceLog(0, ("Invalid parameter in:"));
1551 for (i = 0; i < argc; i++) {
1552 ViceLog(0, (" %s", argv[i]));
1556 } else if (!initializing)
1558 ("Received request to change parms but no parms file exists\n"));
1563 /* Miscellaneous routines */
1567 ViceLog(0, ("%s\n", msg));
1579 * If this fails, it's because something major is wrong, and is not
1580 * likely to be time dependent.
1582 code = pr_Initialize(2, AFSDIR_SERVER_ETC_DIRPATH, 0);
1585 ("Couldn't initialize protection library; code=%d.\n", code));
1589 #ifdef AFS_PTHREAD_ENV
1590 assert(pthread_key_create(&viced_uclient_key, NULL) == 0);
1593 SystemId = SYSADMINID;
1594 SystemAnyUser = ANYUSERID;
1595 SystemAnyUserCPS.prlist_len = 0;
1596 SystemAnyUserCPS.prlist_val = NULL;
1597 AnonCPS.prlist_len = 0;
1598 AnonCPS.prlist_val = NULL;
1600 code = pr_GetCPS(SystemAnyUser, &SystemAnyUserCPS);
1603 ("Couldn't get CPS for AnyUser, will try again in 30 seconds; code=%d.\n",
1607 code = pr_GetCPS(ANONYMOUSID, &AnonCPS);
1610 ("Couldn't get Anonymous CPS, exiting; code=%d.\n",
1614 AnonymousID = ANONYMOUSID;
1617 #ifdef AFS_PTHREAD_ENV
1619 #else /* AFS_PTHREAD_ENV */
1621 #endif /* AFS_PTHREAD_ENV */
1625 struct rx_connection *serverconns[MAXSERVERS];
1626 struct ubik_client *cstruct;
1629 vl_Initialize(const char *confDir)
1632 afs_int32 scIndex = RX_SECIDX_NULL;
1633 struct afsconf_dir *tdir;
1634 struct rx_securityClass *sc;
1635 struct afsconf_cell info;
1637 tdir = afsconf_Open(confDir);
1640 ("Could not open configuration directory (%s).\n", confDir));
1643 code = afsconf_ClientAuth(tdir, &sc, &scIndex);
1645 ViceLog(0, ("Could not get security object for localAuth\n"));
1648 code = afsconf_GetCellInfo(tdir, NULL, AFSCONF_VLDBSERVICE, &info);
1649 if (info.numServers > MAXSERVERS) {
1651 ("vl_Initialize: info.numServers=%d (> MAXSERVERS=%d)\n",
1652 info.numServers, MAXSERVERS));
1655 for (i = 0; i < info.numServers; i++)
1657 rx_NewConnection(info.hostAddr[i].sin_addr.s_addr,
1658 info.hostAddr[i].sin_port, USER_SERVICE_ID, sc,
1660 code = ubik_ClientInit(serverconns, &cstruct);
1661 afsconf_Close(tdir);
1663 ViceLog(0, ("vl_Initialize: ubik client init failed.\n"));
1669 #define SYSIDMAGIC 0x88aabbcc
1670 #define SYSIDVERSION 1
1675 afs_int32 fd, nentries, i;
1676 struct versionStamp vsn;
1677 struct afs_stat status;
1680 if ((afs_stat(AFSDIR_SERVER_SYSID_FILEPATH, &status))
1681 || (status.st_size <= 0)) {
1682 ViceLog(0, ("%s: doesn't exist\n", AFSDIR_SERVER_SYSID_FILEPATH));
1685 if (!(fd = afs_open(AFSDIR_SERVER_SYSID_FILEPATH, O_RDONLY, 0))) {
1687 ("%s: can't open (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1691 if ((i = read(fd, (char *)&vsn, sizeof(vsn))) != sizeof(vsn)) {
1693 ("%s: Read failed (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1697 if (vsn.magic != SYSIDMAGIC) {
1699 ("%s: wrong magic %x (we support %x)\n",
1700 AFSDIR_SERVER_SYSID_FILEPATH, vsn.magic, SYSIDMAGIC));
1703 if (vsn.version != SYSIDVERSION) {
1705 ("%s: wrong version %d (we support %d)\n",
1706 AFSDIR_SERVER_SYSID_FILEPATH, vsn.version, SYSIDVERSION));
1710 read(fd, (char *)&uuid,
1711 sizeof(struct afsUUID))) != sizeof(struct afsUUID)) {
1713 ("%s: read of uuid failed (%d)\n",
1714 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1717 afs_ntohuuid(&uuid);
1720 read(fd, (char *)&nentries,
1721 sizeof(afs_int32))) != sizeof(afs_int32)) {
1723 ("%s: Read of entries failed (%d)\n",
1724 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1727 if (nentries <= 0 || nentries > ADDRSPERSITE) {
1729 ("%s: invalid num of interfaces: %d\n",
1730 AFSDIR_SERVER_SYSID_FILEPATH, nentries));
1733 if (FS_HostAddr_cnt == 0) {
1734 FS_HostAddr_cnt = nentries;
1735 for (i = 0; i < nentries; i++) {
1736 if (read(fd, (char *)&FS_HostAddrs[i], sizeof(afs_int32)) !=
1737 sizeof(afs_int32)) {
1739 ("%s: Read of addresses failed (%d)\n",
1740 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1741 FS_HostAddr_cnt = 0; /* reset it */
1747 ("%s: address list ignored (NetInfo/NetRestrict override)\n",
1748 AFSDIR_SERVER_SYSID_FILEPATH));
1755 WriteSysIdFile(void)
1758 struct versionStamp vsn;
1759 struct afs_stat status;
1762 if (!afs_stat(AFSDIR_SERVER_SYSID_FILEPATH, &status)) {
1764 * File exists; keep the old one around
1766 renamefile(AFSDIR_SERVER_SYSID_FILEPATH,
1767 AFSDIR_SERVER_OLDSYSID_FILEPATH);
1769 fd = afs_open(AFSDIR_SERVER_SYSID_FILEPATH, O_WRONLY | O_TRUNC | O_CREAT,
1773 ("%s: can't create (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1777 vsn.magic = SYSIDMAGIC;
1779 if ((i = write(fd, (char *)&vsn, sizeof(vsn))) != sizeof(vsn)) {
1781 ("%s: write failed (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1786 afs_htonuuid(&uuid);
1788 write(fd, (char *)&uuid,
1789 sizeof(struct afsUUID))) != sizeof(struct afsUUID)) {
1791 ("%s: write of uuid failed (%d)\n",
1792 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1796 write(fd, (char *)&FS_HostAddr_cnt,
1797 sizeof(afs_int32))) != sizeof(afs_int32)) {
1799 ("%s: write of # of entries failed (%d)\n",
1800 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1803 for (i = 0; i < FS_HostAddr_cnt; i++) {
1804 if (write(fd, (char *)&FS_HostAddrs[i], sizeof(afs_int32)) !=
1805 sizeof(afs_int32)) {
1807 ("%s: write of addresses failed (%d)\n",
1808 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1818 * This routine sets up the buffers for the VL_RegisterAddrs RPC. All addresses
1819 * in FS_HostAddrs[] are in NBO, while the RPC treats them as a "blob" of data
1820 * and so we need to convert each of them into HBO which is what the extra
1821 * array called FS_HostAddrs_HBO is used here.
1824 Do_VLRegisterRPC(void)
1828 afs_uint32 FS_HostAddrs_HBO[ADDRSPERSITE];
1831 for (i = 0; i < FS_HostAddr_cnt; i++)
1832 FS_HostAddrs_HBO[i] = ntohl(FS_HostAddrs[i]);
1833 addrs.bulkaddrs_len = FS_HostAddr_cnt;
1834 addrs.bulkaddrs_val = (afs_uint32 *) FS_HostAddrs_HBO;
1835 code = ubik_VL_RegisterAddrs(cstruct, 0, &FS_HostUUID, 0, &addrs);
1837 if (code == VL_MULTIPADDR) {
1839 ("VL_RegisterAddrs rpc failed; The IP address exists on a different server; repair it\n"));
1841 ("VL_RegisterAddrs rpc failed; See VLLog for details\n"));
1843 } else if (code == RXGEN_OPCODE) {
1845 ("vlserver doesn't support VL_RegisterAddrs rpc; ignored\n"));
1846 FS_registered = 2; /* So we don't have to retry in the gc daemon */
1849 ("VL_RegisterAddrs rpc failed; will retry periodically (code=%d, err=%d)\n",
1851 FS_registered = 1; /* Retry in the gc daemon */
1854 FS_registered = 2; /* So we don't have to retry in the gc daemon */
1866 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH || AFSDIR_SERVER_NETINFO_FILEPATH) {
1868 * Find addresses we are supposed to register as per the netrestrict
1869 * and netinfo files (/usr/afs/local/NetInfo and
1870 * /usr/afs/local/NetRestict)
1873 afs_int32 code = parseNetFiles(FS_HostAddrs, NULL, NULL,
1874 ADDRSPERSITE, reason,
1875 AFSDIR_SERVER_NETINFO_FILEPATH,
1876 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
1878 ViceLog(0, ("Can't register any valid addresses: %s\n", reason));
1881 FS_HostAddr_cnt = (afs_uint32) code;
1884 FS_HostAddr_cnt = rx_getAllAddr(FS_HostAddrs, ADDRSPERSITE);
1887 if (FS_HostAddr_cnt == 1 && rxBind == 1)
1888 code = FS_HostAddrs[0];
1890 code = htonl(INADDR_ANY);
1900 * If this fails, it's because something major is wrong, and is not
1901 * likely to be time dependent.
1903 code = vl_Initialize(AFSDIR_SERVER_ETC_DIRPATH);
1906 ("Couldn't initialize protection library; code=%d.\n", code));
1910 /* Read or create the sysid file and register the fileserver's
1911 * IP addresses with the vlserver.
1913 code = ReadSysIdFile();
1915 /* Need to create the file */
1916 ViceLog(0, ("Creating new SysID file\n"));
1917 if ((code = afs_uuid_create(&FS_HostUUID))) {
1918 ViceLog(0, ("Failed to create new uuid: %d\n", code));
1922 /* A good sysid file exists; inform the vlserver. If any conflicts,
1923 * we always use the latest interface available as the real truth.
1926 code = Do_VLRegisterRPC();
1931 main(int argc, char *argv[])
1935 struct rx_securityClass **securityClasses;
1936 afs_int32 numClasses;
1937 struct rx_service *tservice;
1938 #ifdef AFS_PTHREAD_ENV
1939 pthread_t serverPid;
1940 pthread_attr_t tattr;
1941 #else /* AFS_PTHREAD_ENV */
1942 PROCESS parentPid, serverPid;
1943 #endif /* AFS_PTHREAD_ENV */
1945 int minVnodesRequired; /* min size of vnode cache */
1946 #ifndef AFS_NT40_ENV
1947 struct rlimit rlim; /* max number of open file descriptors */
1951 afs_uint32 rx_bindhost;
1952 VolumePackageOptions opts;
1954 #ifdef AFS_AIX32_ENV
1955 struct sigaction nsa;
1957 sigemptyset(&nsa.sa_mask);
1958 nsa.sa_handler = SIG_DFL;
1959 nsa.sa_flags = SA_FULLDUMP;
1960 sigaction(SIGABRT, &nsa, NULL);
1961 sigaction(SIGSEGV, &nsa, NULL);
1965 /* Initialize dirpaths */
1966 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
1968 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
1970 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
1974 /* set ihandle package defaults prior to parsing args */
1977 if (ParseArgs(argc, argv)) {
1981 #ifdef AFS_PTHREAD_ENV
1982 assert(pthread_mutex_init(&fileproc_glock_mutex, NULL) == 0);
1983 #endif /* AFS_PTHREAD_ENV */
1985 #ifdef AFS_SGI_VNODE_GLUE
1986 if (afs_init_kernel_config(-1) < 0) {
1988 ("Can't determine NUMA configuration, not starting fileserver.\n");
1992 confDir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
1994 fprintf(stderr, "Unable to open config directory %s\n",
1995 AFSDIR_SERVER_ETC_DIRPATH);
2001 /* Open FileLog on stdout, stderr, fd 1 and fd2 (for perror), sigh. */
2002 #ifndef AFS_NT40_ENV
2003 serverLogSyslogTag = "fileserver";
2005 OpenLog(AFSDIR_SERVER_FILELOG_FILEPATH);
2008 if (SawSpare && SawPctSpare) {
2009 ViceLog(0, ("Both -spare and -pctspare specified, exiting.\n"));
2012 LogCommandLine(argc, argv, "starting", "", "File server", FSLog);
2014 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
2015 /* initialize the pthread soft signal handler thread */
2019 /* install signal handlers for controlling the fileserver process */
2020 ResetCheckSignal(); /* set CheckSignal_Signal() sig handler */
2021 ResetCheckDescriptors(); /* set CheckDescriptors_Signal() sig handler */
2023 #if defined(AFS_SGI_ENV)
2024 /* give this guy a non-degrading priority so help busy servers */
2025 schedctl(NDPRI, 0, NDPNORMMAX);
2029 #ifndef AFS_NT40_ENV
2030 nice(-5); /* TODO: */
2033 assert(DInit(buffs) == 0);
2034 #ifdef AFS_DEMAND_ATTACH_FS
2039 if (afs_winsockInit() < 0) {
2040 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
2041 ViceLog(0, ("File server failed to intialize winsock.\n"));
2047 /* if we support more than 16 threads, then we better have the ability
2048 ** to keep open a large number of files simultaneously
2050 #if defined(AFS_AIX_ENV) && !defined(AFS_AIX42_ENV)
2051 curLimit = OPEN_MAX; /* for pre AIX 4.2 systems */
2052 #elif defined(AFS_NT40_ENV)
2053 curLimit = NT_OPEN_MAX; /* open file descriptor limit on NT */
2056 curLimit = 0; /* the number of open file descriptors */
2057 code = getrlimit(RLIMIT_NOFILE, &rlim);
2059 curLimit = rlim.rlim_cur;
2060 rlim.rlim_cur = rlim.rlim_max;
2061 code = setrlimit(RLIMIT_NOFILE, &rlim);
2063 curLimit = rlim.rlim_max;
2066 ViceLog(0, ("Failed to increase open file limit, using default\n"));
2068 #endif /* defined(AFS_AIX_ENV) && !defined(AFS_AIX42_ENV) */
2070 curLimit -= 32; /* leave a slack of 32 file descriptors */
2071 if (lwps > curLimit) {
2075 lwps = 16; /* default to a maximum of 16 threads */
2077 /* tune the ihandle fd cache accordingly */
2078 if (vol_io_params.fd_max_cachesize < curLimit)
2079 vol_io_params.fd_max_cachesize = curLimit + 1;
2082 ("The system supports a max of %d open files and we are starting %d threads (ihandle fd cache is %d)\n",
2083 curLimit, lwps, vol_io_params.fd_max_cachesize));
2085 #ifndef AFS_PTHREAD_ENV
2086 assert(LWP_InitializeProcessSupport(LWP_MAX_PRIORITY - 2, &parentPid) ==
2088 #endif /* !AFS_PTHREAD_ENV */
2090 /* Initialize volume support */
2092 V_BreakVolumeCallbacks = BreakVolumeCallBacksLater;
2095 #ifdef AFS_PTHREAD_ENV
2096 SetLogThreadNumProgram( threadNum );
2099 /* initialize libacl routines */
2100 acl_Initialize(ACL_VERSION);
2102 /* initialize RX support */
2103 #ifndef AFS_NT40_ENV
2104 rxi_syscallp = viced_syscall;
2106 rx_extraPackets = rxpackets;
2107 rx_extraQuota = 4; /* for outgoing prserver calls from R threads */
2108 rx_SetBusyThreshold(busy_threshold, VBUSY);
2109 rx_SetCallAbortThreshold(abort_threshold);
2110 rx_SetConnAbortThreshold(abort_threshold);
2112 stackSize = 128 * 1024;
2114 stackSize = lwps * 4000;
2115 if (stackSize < 32000)
2117 else if (stackSize > 44000)
2120 #if defined(AFS_HPUX_ENV) || defined(AFS_SUN_ENV) || defined(AFS_SGI51_ENV) || defined(AFS_XBSD_ENV)
2121 rx_SetStackSize(1, stackSize);
2124 rx_SetUdpBufSize(udpBufSize); /* set the UDP buffer size for receive */
2125 rx_bindhost = SetupVL();
2127 if (rx_InitHost(rx_bindhost, (int)htons(7000)) < 0) {
2128 ViceLog(0, ("Cannot initialize RX\n"));
2131 if (!rxJumbograms) {
2132 /* Don't send and don't allow 3.4 clients to send jumbograms. */
2135 if (rxMaxMTU != -1) {
2136 rx_SetMaxMTU(rxMaxMTU);
2139 rx_SetRxDeadTime(30);
2140 afsconf_BuildServerSecurityObjects(confDir, AFSCONF_SEC_OBJS_RXKAD_CRYPT,
2141 &securityClasses, &numClasses);
2143 tservice = rx_NewServiceHost(rx_bindhost, /* port */ 0, /* service id */
2144 1, /*service name */
2146 securityClasses, numClasses,
2147 RXAFS_ExecuteRequest);
2150 ("Failed to initialize RX, probably two servers running.\n"));
2153 if (rxkadDisableDotCheck) {
2154 rx_SetSecurityConfiguration(tservice, RXS_CONFIG_FLAGS,
2155 (void *)RXS_CONFIG_FLAGS_DISABLE_DOTCHECK);
2157 rx_SetMinProcs(tservice, 3);
2158 rx_SetMaxProcs(tservice, lwps);
2159 rx_SetCheckReach(tservice, 1);
2160 rx_SetServerIdleDeadErr(tservice, VNOSERVICE);
2163 rx_NewService(0, RX_STATS_SERVICE_ID, "rpcstats", securityClasses,
2164 numClasses, RXSTATS_ExecuteRequest);
2166 ViceLog(0, ("Failed to initialize rpc stat service.\n"));
2169 rx_SetMinProcs(tservice, 2);
2170 rx_SetMaxProcs(tservice, 4);
2173 * Enable RX hot threads, which allows the listener thread to trade
2174 * places with an idle thread and moves the context switch from listener
2175 * to worker out of the critical path.
2177 rx_EnableHotThread();
2179 /* Some rx debugging */
2180 if (rxlog || eventlog) {
2181 debugFile = afs_fopen("rx_dbg", "w");
2183 rx_debugFile = debugFile;
2185 rxevent_debugFile = debugFile;
2188 init_sys_error_to_et(); /* Set up error table translation */
2189 h_InitHostPackage(); /* set up local cellname and realmname */
2190 InitCallBack(numberofcbs);
2194 if (code && code != VL_MULTIPADDR) {
2195 ViceLog(0, ("Fatal error in library initialization, exiting!!\n"));
2200 if (code && code != -1) {
2201 ViceLog(0, ("Fatal error in protection initialization, exiting!!\n"));
2205 /* allow super users to manage RX statistics */
2206 rx_SetRxStatUserOk(fs_rxstat_userok);
2208 #ifdef AFS_PTHREAD_ENV
2209 assert(pthread_cond_init(&fsync_cond, NULL) == 0);
2210 assert(pthread_mutex_init(&fsync_glock_mutex, NULL) == 0);
2213 #if !defined(AFS_DEMAND_ATTACH_FS)
2215 * For DAFS, we do not start the Rx server threads until after
2216 * the volume package is initialized, and fileserver state is
2217 * restored. This is necessary in order to keep host and callback
2218 * package state pristine until we have a chance to restore state.
2220 * Furthermore, startup latency is much lower with dafs, so this
2221 * shouldn't pose a serious problem.
2223 rx_StartServer(0); /* now start handling requests */
2226 /* we ensure that there is enough space in the vnode buffer to satisfy
2227 ** requests from all concurrent threads.
2228 ** the maximum number of vnodes used by a single thread at any one time
2229 ** is three ( "link" uses three vnodes simultaneously, one vLarge and
2230 ** two vSmall for linking files and two vLarge and one vSmall for linking
2233 minVnodesRequired = 2 * lwps + 1;
2234 if (minVnodesRequired > nSmallVns) {
2235 nSmallVns = minVnodesRequired;
2237 ("Overriding -s command line parameter with %d\n",
2240 if (minVnodesRequired > large) {
2241 large = minVnodesRequired;
2242 ViceLog(0, ("Overriding -l command line parameter with %d\n", large));
2245 /* We now do this after getting the listener up and running, so that client
2246 * connections don't timeout (maybe) if a file server is restarted, since it
2247 * will be available "real soon now". Worry about whether we can satisfy the
2248 * calls in the volume package itself.
2250 VOptDefaults(fileServer, &opts);
2251 opts.nLargeVnodes = large;
2252 opts.nSmallVnodes = nSmallVns;
2253 opts.volcache = volcache;
2254 opts.unsafe_attach = unsafe_attach;
2256 if (VInitVolumePackage2(fileServer, &opts)) {
2258 ("Shutting down: errors encountered initializing volume package\n"));
2263 /* Install handler to catch the shutdown signal;
2264 * bosserver assumes SIGQUIT shutdown
2266 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
2267 softsig_signal(SIGQUIT, ShutDown_Signal);
2269 (void)signal(SIGQUIT, ShutDown_Signal);
2272 if (VInitAttachVolumes(fileServer)) {
2274 ("Shutting down: errors encountered initializing volume package\n"));
2279 #ifdef AFS_DEMAND_ATTACH_FS
2280 if (fs_state.options.fs_state_restore) {
2283 * restore fileserver state */
2286 rx_StartServer(0); /* now start handling requests */
2287 #endif /* AFS_DEMAND_ATTACH_FS */
2290 * We are done calling fopen/fdopen. It is safe to use a large
2291 * of the file descriptor cache.
2295 #ifdef AFS_PTHREAD_ENV
2296 ViceLog(5, ("Starting pthreads\n"));
2297 assert(pthread_attr_init(&tattr) == 0);
2298 assert(pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED) == 0);
2300 assert(pthread_create
2301 (&serverPid, &tattr, FiveMinuteCheckLWP,
2302 &fiveminutes) == 0);
2303 assert(pthread_create
2304 (&serverPid, &tattr, HostCheckLWP, &fiveminutes) == 0);
2305 assert(pthread_create
2306 (&serverPid, &tattr, FsyncCheckLWP, &fiveminutes) == 0);
2307 #else /* AFS_PTHREAD_ENV */
2308 ViceLog(5, ("Starting LWP\n"));
2309 assert(LWP_CreateProcess
2310 (FiveMinuteCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
2311 (void *)&fiveminutes, "FiveMinuteChecks",
2312 &serverPid) == LWP_SUCCESS);
2314 assert(LWP_CreateProcess
2315 (HostCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
2316 (void *)&fiveminutes, "HostCheck", &serverPid) == LWP_SUCCESS);
2317 assert(LWP_CreateProcess
2318 (FsyncCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
2319 (void *)&fiveminutes, "FsyncCheck", &serverPid) == LWP_SUCCESS);
2320 #endif /* AFS_PTHREAD_ENV */
2322 FT_GetTimeOfDay(&tp, 0);
2324 ViceLog(0, ("File server has started at %s",
2325 afs_ctime((time_t *)&(tp.tv_sec), tbuffer, sizeof(tbuffer))));
2328 * Figure out the FileServer's name and primary address.
2330 ViceLog(0, ("Getting FileServer name...\n"));
2331 code = gethostname(FS_HostName, 64);
2333 ViceLog(0, ("gethostname() failed\n"));
2335 ViceLog(0, ("FileServer host name is '%s'\n", FS_HostName));
2337 ViceLog(0, ("Getting FileServer address...\n"));
2338 he = gethostbyname(FS_HostName);
2340 ViceLog(0, ("Can't find address for FileServer '%s'\n", FS_HostName));
2343 memcpy(&FS_HostAddr_NBO, he->h_addr, 4);
2344 (void)afs_inet_ntoa_r(FS_HostAddr_NBO, hoststr);
2345 FS_HostAddr_HBO = ntohl(FS_HostAddr_NBO);
2347 ("FileServer %s has address %s (0x%x or 0x%x in host byte order)\n",
2348 FS_HostName, hoststr, FS_HostAddr_NBO, FS_HostAddr_HBO));
2353 ("File Server started %s",
2354 afs_ctime(&t, tbuffer, sizeof(tbuffer))));
2355 #if FS_STATS_DETAILED
2356 afs_FullPerfStats.det.epoch.tv_sec = StartTime = tp.tv_sec;
2358 #ifdef AFS_PTHREAD_ENV
2360 sleep(1000); /* long time */
2362 #else /* AFS_PTHREAD_ENV */
2363 assert(LWP_WaitProcess(&parentPid) == LWP_SUCCESS);
2364 #endif /* AFS_PTHREAD_ENV */