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);
372 viced_syscall(afs_uint32 a3, afs_uint32 a4, void *a5)
375 #ifndef AFS_LINUX20_ENV
378 old = (void (*)(int))signal(SIGSYS, SIG_IGN);
380 rcode = syscall(AFS_SYSCALL, 28 /* AFSCALL_CALL */ , a3, a4, a5);
381 #ifndef AFS_LINUX20_ENV
389 #if !defined(AFS_NT40_ENV)
390 #include "AFS_component_version_number.c"
391 #endif /* !AFS_NT40_ENV */
393 #define MAXADMINNAME 64
394 char adminName[MAXADMINNAME];
400 struct afs_stat status;
402 if ((afs_stat("/AdminName", &status)) || /* if file does not exist */
403 (status.st_size <= 0) || /* or it is too short */
404 (status.st_size >= (MAXADMINNAME)) || /* or it is too long */
405 !(fd = afs_open("/AdminName", O_RDONLY, 0))) { /* or the open fails */
406 strcpy(adminName, "System:Administrators"); /* use the default name */
408 (void)read(fd, adminName, status.st_size); /* use name from the file */
411 close(fd); /* close fd if it was opened */
413 } /*CheckAdminName */
419 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
420 /* set our 'thread-id' so that the host hold table works */
421 MUTEX_ENTER(&rx_stats_mutex); /* protects rxi_pthread_hinum */
423 pthread_setspecific(rx_thread_id_key, (void *)(intptr_t)rxi_pthread_hinum);
424 MUTEX_EXIT(&rx_stats_mutex);
426 ("Set thread id %p for '%s'\n",
427 pthread_getspecific(rx_thread_id_key), s));
431 /* This LWP does things roughly every 5 minutes */
433 FiveMinuteCheckLWP(void *unused)
438 ViceLog(1, ("Starting five minute check process\n"));
439 setThreadId("FiveMinuteCheckLWP");
441 #ifdef AFS_DEMAND_ATTACH_FS
443 while (fs_state.mode == FS_MODE_NORMAL) {
444 fs_state.FiveMinuteLWP_tranquil = 1;
450 #ifdef AFS_PTHREAD_ENV
452 #else /* AFS_PTHREAD_ENV */
453 IOMGR_Sleep(fiveminutes);
454 #endif /* AFS_PTHREAD_ENV */
456 #ifdef AFS_DEMAND_ATTACH_FS
458 if (fs_state.mode != FS_MODE_NORMAL) {
461 fs_state.FiveMinuteLWP_tranquil = 0;
465 /* close the log so it can be removed */
466 ReOpenLog(AFSDIR_SERVER_FILELOG_FILEPATH); /* don't trunc, just append */
467 ViceLog(2, ("Cleaning up timed out callbacks\n"));
468 if (CleanupTimedOutCallBacks())
469 ViceLog(5, ("Timed out callbacks deleted\n"));
470 ViceLog(2, ("Set disk usage statistics\n"));
472 if (FS_registered == 1)
474 /* Force wakeup in case we missed something; pthreads does timedwait */
475 #ifndef AFS_PTHREAD_ENV
476 LWP_NoYieldSignal(fsync_wait);
478 if (printBanner && (++msg & 1)) { /* Every 10 minutes */
479 time_t now = FT_ApproxTime();
480 if (console != NULL) {
481 #ifndef AFS_QUIETFS_ENV
482 fprintf(console, "File server is running at %s\r",
483 afs_ctime(&now, tbuffer, sizeof(tbuffer)));
484 #endif /* AFS_QUIETFS_ENV */
486 ("File server is running at %s\n",
487 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
490 #ifdef AFS_DEMAND_ATTACH_FS
494 #ifdef AFS_DEMAND_ATTACH_FS
495 fs_state.FiveMinuteLWP_tranquil = 1;
497 assert(pthread_cond_broadcast(&fs_state.worker_done_cv)==0);
502 } /*FiveMinuteCheckLWP */
505 /* This LWP does host checks every 5 minutes: it should not be used for
506 * other 5 minute activities because it may be delayed by timeouts when
507 * it probes the workstations
511 HostCheckLWP(void *unused)
513 ViceLog(1, ("Starting Host check process\n"));
514 setThreadId("HostCheckLWP");
515 #ifdef AFS_DEMAND_ATTACH_FS
517 while (fs_state.mode == FS_MODE_NORMAL) {
518 fs_state.HostCheckLWP_tranquil = 1;
524 #ifdef AFS_PTHREAD_ENV
526 #else /* AFS_PTHREAD_ENV */
527 IOMGR_Sleep(fiveminutes);
528 #endif /* AFS_PTHREAD_ENV */
530 #ifdef AFS_DEMAND_ATTACH_FS
532 if (fs_state.mode != FS_MODE_NORMAL) {
535 fs_state.HostCheckLWP_tranquil = 0;
539 ViceLog(2, ("Checking for dead venii & clients\n"));
542 #ifdef AFS_DEMAND_ATTACH_FS
546 #ifdef AFS_DEMAND_ATTACH_FS
547 fs_state.HostCheckLWP_tranquil = 1;
549 assert(pthread_cond_broadcast(&fs_state.worker_done_cv)==0);
556 /* This LWP does fsync checks every 5 minutes: it should not be used for
557 * other 5 minute activities because it may be delayed by timeouts when
558 * it probes the workstations
561 FsyncCheckLWP(void *unused)
564 #ifdef AFS_PTHREAD_ENV
565 struct timespec fsync_next;
567 ViceLog(1, ("Starting fsync check process\n"));
569 setThreadId("FsyncCheckLWP");
571 #ifdef AFS_DEMAND_ATTACH_FS
573 while (fs_state.mode == FS_MODE_NORMAL) {
574 fs_state.FsyncCheckLWP_tranquil = 1;
580 #ifdef AFS_PTHREAD_ENV
581 /* rounding is fine */
582 fsync_next.tv_nsec = 0;
583 fsync_next.tv_sec = time(0) + fiveminutes;
586 pthread_cond_timedwait(&fsync_cond, &fsync_glock_mutex,
588 if (code != 0 && code != ETIMEDOUT)
589 ViceLog(0, ("pthread_cond_timedwait returned %d\n", code));
590 #else /* AFS_PTHREAD_ENV */
591 if ((code = LWP_WaitProcess(fsync_wait)) != LWP_SUCCESS)
592 ViceLog(0, ("LWP_WaitProcess returned %d\n", code));
593 #endif /* AFS_PTHREAD_ENV */
596 #ifdef AFS_DEMAND_ATTACH_FS
598 if (fs_state.mode != FS_MODE_NORMAL) {
601 fs_state.FsyncCheckLWP_tranquil = 0;
603 #endif /* AFS_DEMAND_ATTACH_FS */
605 ViceLog(2, ("Checking for fsync events\n"));
607 code = BreakLaterCallBacks();
609 #ifdef AFS_DEMAND_ATTACH_FS
613 #ifdef AFS_DEMAND_ATTACH_FS
614 fs_state.FsyncCheckLWP_tranquil = 1;
616 assert(pthread_cond_broadcast(&fs_state.worker_done_cv)==0);
619 #endif /* AFS_DEMAND_ATTACH_FS */
623 /*------------------------------------------------------------------------
624 * PRIVATE ClearXStatValues
627 * Initialize all of the values collected via the xstat
637 * Must be called during File Server initialization.
641 *------------------------------------------------------------------------*/
644 ClearXStatValues(void)
645 { /*ClearXStatValues */
647 struct fs_stats_opTimingData *opTimeP; /*Ptr to timing struct */
648 struct fs_stats_xferData *opXferP; /*Ptr to xfer struct */
649 int i; /*Loop counter */
652 * Zero all xstat-related structures.
654 memset((&afs_perfstats), 0, sizeof(struct afs_PerfStats));
655 #if FS_STATS_DETAILED
656 memset((&afs_FullPerfStats), 0,
657 sizeof(struct fs_stats_FullPerfStats));
660 * That's not enough. We have to set reasonable minima for
661 * time and xfer values in the detailed stats.
663 opTimeP = &(afs_FullPerfStats.det.rpcOpTimes[0]);
664 for (i = 0; i < FS_STATS_NUM_RPC_OPS; i++, opTimeP++)
665 opTimeP->minTime.tv_sec = 999999;
667 opXferP = &(afs_FullPerfStats.det.xferOpTimes[0]);
668 for (i = 0; i < FS_STATS_NUM_XFER_OPS; i++, opXferP++) {
669 opXferP->minTime.tv_sec = 999999;
670 opXferP->minBytes = 999999999;
674 * There's more. We have to set our unique system identifier, as
675 * declared in param.h. If such a thing is not defined, we bitch
676 * and declare ourselves to be an unknown system type.
679 afs_perfstats.sysname_ID = SYS_NAME_ID;
682 ViceLog(0, ("Sys name ID constant not defined in param.h!!\n"));
683 ViceLog(0, ("[Choosing ``undefined'' sys name ID.\n"));
685 afs_perfstats.sysname_ID = SYS_NAME_ID_UNDEFINED;
686 #endif /* SYS_NAME_ID */
689 } /*ClearXStatValues */
691 int CopyOnWrite_calls = 0, CopyOnWrite_off0 = 0, CopyOnWrite_size0 = 0;
692 afs_fsize_t CopyOnWrite_maxsize = 0;
697 int dirbuff, dircall, dirio;
699 int workstations, activeworkstations, delworkstations;
703 FT_GetTimeOfDay(&tpl, 0);
706 ("Vice was last started at %s\n",
707 afs_ctime(&StartTime, tbuffer, sizeof(tbuffer))));
709 #ifdef AFS_DEMAND_ATTACH_FS
710 /* XXX perhaps set extended stats verbosity flags
711 * based upon LogLevel ?? */
712 VPrintExtendedCacheStats(VOL_STATS_PER_CHAIN2);
716 DStat(&dirbuff, &dircall, &dirio);
718 ("With %d directory buffers; %d reads resulted in %d read I/Os\n",
719 dirbuff, dircall, dirio));
720 rx_PrintStats(stderr);
721 audit_PrintStats(stderr);
723 PrintCallBackStats();
725 processSize = -1; /* TODO: */
727 processSize = (int)((long)sbrk(0) >> 10);
730 ("There are %d connections, process size %d\n",
731 CurrentConnections, processSize));
732 h_GetWorkStats(&workstations, &activeworkstations, &delworkstations,
733 tpl.tv_sec - 15 * 60);
735 ("There are %d workstations, %d are active (req in < 15 mins), %d marked \"down\"\n",
736 workstations, activeworkstations, delworkstations));
737 ViceLog(0, ("CopyOnWrite: calls %d off0 %d size0 %d maxsize 0x%llx\n",
738 CopyOnWrite_calls, CopyOnWrite_off0, CopyOnWrite_size0, CopyOnWrite_maxsize));
747 CheckSignal(void *unused)
749 if (FS_registered > 0) {
751 * We have proper ip addresses; tell the vlserver what we got; the following
752 * routine will do the proper reporting for us
765 ShutdownWatchdogLWP(void *unused)
767 sleep(panic_timeout);
768 ViceLog(0, ("ShutdownWatchdogLWP: Failed to shutdown and panic "
769 "within %d seconds; forcing panic\n", panic_timeout));
775 ShutDownAndCore(int dopanic)
777 time_t now = time(0);
781 #ifdef AFS_PTHREAD_ENV
782 pthread_t watchdogPid;
783 pthread_attr_t tattr;
784 assert(pthread_attr_init(&tattr) == 0);
785 assert(pthread_create(&watchdogPid, &tattr, ShutdownWatchdogLWP, NULL) == 0);
788 assert(LWP_CreateProcess
789 (ShutdownWatchdogLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
790 NULL, "ShutdownWatchdog", &watchdogPid) == LWP_SUCCESS);
794 /* do not allows new reqests to be served from now on, all new requests
795 * are returned with an error code of RX_RESTARTING ( transient failure ) */
796 rx_SetRxTranquil(); /* dhruba */
800 #ifdef AFS_DEMAND_ATTACH_FS
802 fs_state.mode = FS_MODE_SHUTDOWN;
807 ("Shutting down file server at %s",
808 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
810 ViceLog(0, ("ABNORMAL SHUTDOWN, see core file.\n"));
811 #ifndef AFS_QUIETFS_ENV
812 if (console != NULL) {
813 fprintf(console, "File server restart/shutdown received at %s\r",
814 afs_ctime(&now, tbuffer, sizeof(tbuffer)));
821 /* shut down volume package */
824 #ifdef AFS_DEMAND_ATTACH_FS
825 if (fs_state.options.fs_state_save) {
828 * save fileserver state to disk */
831 ViceLog(0, ("Not saving fileserver state; abnormal shutdown\n"));
834 /* make sure background threads have finished all of their asynchronous
835 * work on host and callback structures */
837 while (!fs_state.FiveMinuteLWP_tranquil ||
838 !fs_state.HostCheckLWP_tranquil ||
839 !fs_state.FsyncCheckLWP_tranquil) {
842 ViceLog(0, ("waiting for background host/callback threads to quiesce before saving fileserver state...\n"));
843 assert(pthread_cond_wait(&fs_state.worker_done_cv, &fileproc_glock_mutex) == 0);
848 /* ok. it should now be fairly safe. let's do the state dump */
852 #endif /* AFS_DEMAND_ATTACH_FS */
855 rx_PrintStats(debugFile);
858 if (console != NULL) {
861 #ifndef AFS_QUIETFS_ENV
862 fprintf(console, "File server has terminated abnormally at %s\r",
863 afs_ctime(&now, tbuffer, sizeof(tbuffer)));
866 ("File server has terminated abnormally at %s\n",
867 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
869 #ifndef AFS_QUIETFS_ENV
870 fprintf(console, "File server has terminated normally at %s\r",
871 afs_ctime(&now, tbuffer, sizeof(tbuffer)));
874 ("File server has terminated normally at %s\n",
875 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
886 ShutDown(void *unused)
887 { /* backward compatibility */
888 ShutDownAndCore(DONTPANIC);
896 /* default supports help flag */
898 fputs("Usage: fileserver ", stdout);
899 fputs("[-auditlog <log path>] ", stdout);
900 fputs("[-audit-interface <file|sysvmq> (default is file)] ", stdout);
901 fputs("[-d <debug level>] ", stdout);
902 fputs("[-p <number of processes>] ", stdout);
903 fputs("[-spare <number of spare blocks>] ", stdout);
904 fputs("[-pctspare <percentage spare>] ", stdout);
905 fputs("[-b <buffers>] ", stdout);
906 fputs("[-l <large vnodes>] ", stdout);
907 fputs("[-s <small vnodes>] ", stdout);
908 fputs("[-vc <volume cachesize>] ", stdout);
909 fputs("[-w <call back wait interval>] ", stdout);
910 fputs("[-cb <number of call backs>] ", stdout);
911 fputs("[-banner (print banner every 10 minutes)] ", stdout);
912 fputs("[-novbc (whole volume cbs disabled)] ", stdout);
913 fputs("[-implicit <admin mode bits: rlidwka>] ", stdout);
914 fputs("[-readonly (read-only file server)] ", stdout);
915 fputs("[-hr <number of hours between refreshing the host cps>] ", stdout);
916 fputs("[-busyat <redirect clients when queue > n>] ", stdout);
917 fputs("[-nobusy <no VBUSY before a volume is attached>] ", stdout);
918 fputs("[-rxpck <number of rx extra packets>] ", stdout);
919 fputs("[-rxdbg (enable rx debugging)] ", stdout);
920 fputs("[-rxdbge (enable rxevent debugging)] ", stdout);
921 fputs("[-rxmaxmtu <bytes>] ", stdout);
922 fputs("[-rxbind (bind the Rx socket to one address)] ", stdout);
923 fputs("[-allow-dotted-principals (disable the rxkad principal name dot check)] ", stdout);
924 fputs("[-vhandle-setaside (fds reserved for non-cache io [default 128])] ", stdout);
925 fputs("[-vhandle-max-cachesize (max open files [default 128])] ", stdout);
926 fputs("[-vhandle-initial-cachesize (fds reserved for cache io [default 128])] ", stdout);
927 #ifdef AFS_DEMAND_ATTACH_FS
928 fputs("[-fs-state-dont-save (disable state save during shutdown)] ", stdout);
929 fputs("[-fs-state-dont-restore (disable state restore during startup)] ", stdout);
930 fputs("[-fs-state-verify <none|save|restore|both> (default is both)] ", stdout);
931 fputs("[-vattachpar <max number of volume attach/shutdown threads> (default is 1)] ", stdout);
932 fputs("[-vhashsize <log(2) of number of volume hash buckets> (default is 8)] ", stdout);
933 fputs("[-vlrudisable (disable VLRU functionality)] ", stdout);
934 fputs("[-vlruthresh <minutes before unused volumes become eligible for soft detach> (default is 2 hours)] ", stdout);
935 fputs("[-vlruinterval <seconds between VLRU scans> (default is 2 minutes)] ", stdout);
936 fputs("[-vlrumax <max volumes to soft detach in one VLRU scan> (default is 8)] ", stdout);
937 #elif AFS_PTHREAD_ENV
938 fputs("[-vattachpar <number of volume attach threads> (default is 1)] ", stdout);
941 fputs("[-m <min percentage spare in partition>] ", stdout);
943 #if defined(AFS_SGI_ENV)
944 fputs("[-lock (keep fileserver from swapping)] ", stdout);
946 fputs("[-L (large server conf)] ", stdout);
947 fputs("[-S (small server conf)] ", stdout);
948 fputs("[-k <stack size>] ", stdout);
949 fputs("[-realm <Kerberos realm name>] ", stdout);
950 fputs("[-udpsize <size of socket buffer in bytes>] ", stdout);
951 fputs("[-sendsize <size of send buffer in bytes>] ", stdout);
952 fputs("[-abortthreshold <abort threshold>] ", stdout);
953 fputs("[-nojumbo (disable jumbogram network packets - deprecated)] ", stdout);
954 fputs("[-jumbo (enable jumbogram network packets)] ", stdout);
955 /* fputs("[-enable_peer_stats] ", stdout); */
956 /* fputs("[-enable_process_stats] ", stdout); */
957 fputs("[-help]\n", stdout);
959 ViceLog(0, ("%s", buffer));
968 ParseRights(char *arights)
974 if (!arights || !strcmp(arights, "")) {
975 printf("Missing list of mode bits on -implicit option\n");
978 if (!strcmp(arights, "none"))
980 else if (!strcmp(arights, "read"))
981 mode = PRSFS_READ | PRSFS_LOOKUP;
982 else if (!strcmp(arights, "write"))
984 PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
985 PRSFS_WRITE | PRSFS_LOCK;
986 else if (!strcmp(arights, "all"))
988 PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
989 PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER;
991 len = strlen(arights);
992 for (i = 0; i < len; i++) {
997 mode |= PRSFS_LOOKUP;
999 mode |= PRSFS_INSERT;
1001 mode |= PRSFS_DELETE;
1003 mode |= PRSFS_WRITE;
1007 mode |= PRSFS_ADMINISTER;
1025 printf("Illegal -implicit rights character '%c'.\n", tc);
1034 * Limit MAX_FILESERVER_THREAD by the system limit on the number of
1035 * pthreads (sysconf(_SC_THREAD_THREADS_MAX)), if applicable and
1038 * AIX: sysconf() limit is real
1039 * HP-UX: sysconf() limit is real
1040 * IRIX: sysconf() limit is apparently NOT real -- too small
1041 * DUX: sysconf() limit is apparently NOT real -- too big
1042 * Linux: sysconf() limit is apparently NOT real -- too big
1043 * Solaris: no sysconf() limit
1046 max_fileserver_thread(void)
1048 #if defined(AFS_PTHREAD_ENV)
1049 #if defined(AFS_AIX_ENV) || defined(AFS_HPUX_ENV)
1052 ans = sysconf(_SC_THREAD_THREADS_MAX);
1053 if (0 < ans && ans < MAX_FILESERVER_THREAD)
1056 #endif /* defined(AFS_PTHREAD_ENV) */
1057 return MAX_FILESERVER_THREAD;
1060 /* from ihandle.c */
1061 extern ih_init_params vol_io_params;
1064 ParseArgs(int argc, char *argv[])
1066 int SawL = 0, SawS = 0, SawVC = 0;
1067 int Sawrxpck = 0, Sawsmall = 0, Sawlarge = 0, Sawcbs = 0, Sawlwps =
1071 int bufSize = 0; /* temp variable to read in udp socket buf size */
1072 char *auditFileName = NULL;
1074 for (i = 1; i < argc; i++) {
1075 if (!strcmp(argv[i], "-d")) {
1076 if ((i + 1) >= argc) {
1077 fprintf(stderr, "missing argument for -d\n");
1080 debuglevel = atoi(argv[++i]);
1081 LogLevel = debuglevel;
1082 } else if (!strcmp(argv[i], "-banner")) {
1084 } else if (!strcmp(argv[i], "-implicit")) {
1085 if ((i + 1) >= argc) {
1086 fprintf(stderr, "missing argument for -implicit\n");
1089 implicitAdminRights = ParseRights(argv[++i]);
1090 if (implicitAdminRights < 0)
1091 return implicitAdminRights;
1092 } else if (!strcmp(argv[i], "-readonly")) {
1094 } else if (!strcmp(argv[i], "-L")) {
1096 } else if (!strcmp(argv[i], "-S")) {
1098 } else if (!strcmp(argv[i], "-p")) {
1100 max_fileserver_thread() - FILESERVER_HELPER_THREADS;
1102 if ((i + 1) >= argc) {
1103 fprintf(stderr, "missing argument for -p\n");
1106 lwps = atoi(argv[++i]);
1107 if (lwps > lwps_max)
1111 } else if (!strcmp(argv[i], "-b")) {
1113 if ((i + 1) >= argc) {
1114 fprintf(stderr, "missing argument for -b\n");
1117 buffs = atoi(argv[++i]);
1118 } else if (!strcmp(argv[i], "-l")) {
1120 if ((i + 1) >= argc) {
1121 fprintf(stderr, "missing argument for -l\n");
1124 large = atoi(argv[++i]);
1125 } else if (!strcmp(argv[i], "-vc")) {
1127 if ((i + 1) >= argc) {
1128 fprintf(stderr, "missing argument for -vc\n");
1131 volcache = atoi(argv[++i]);
1132 } else if (!strcmp(argv[i], "-novbc")) {
1134 } else if (!strcmp(argv[i], "-rxpck")) {
1136 if ((i + 1) >= argc) {
1137 fprintf(stderr, "missing argument for -rxpck\n");
1140 rxpackets = atoi(argv[++i]);
1141 #ifdef AFS_PTHREAD_ENV
1142 } else if (!strcmp(argv[i], "-vattachpar")) {
1143 if ((i + 1) >= argc) {
1144 fprintf(stderr, "missing argument for %s\n", argv[i]);
1147 vol_attach_threads = atoi(argv[++i]);
1148 #endif /* AFS_PTHREAD_ENV */
1149 } else if (!strcmp(argv[i], "-vhandle-setaside")) {
1150 if ((i + 1) >= argc) {
1151 fprintf(stderr, "missing argument for %s\n", argv[i]);
1154 vol_io_params.fd_handle_setaside = atoi(argv[++i]);
1155 } else if (!strcmp(argv[i], "-vhandle-max-cachesize")) {
1156 if ((i + 1) >= argc) {
1157 fprintf(stderr, "missing argument for %s\n", argv[i]);
1160 vol_io_params.fd_max_cachesize = atoi(argv[++i]);
1161 } else if (!strcmp(argv[i], "-vhandle-initial-cachesize")) {
1162 if ((i + 1) >= argc) {
1163 fprintf(stderr, "missing argument for %s\n", argv[i]);
1166 vol_io_params.fd_initial_cachesize = atoi(argv[++i]);
1167 #ifdef AFS_DEMAND_ATTACH_FS
1168 } else if (!strcmp(argv[i], "-fs-state-dont-save")) {
1169 fs_state.options.fs_state_save = 0;
1170 } else if (!strcmp(argv[i], "-fs-state-dont-restore")) {
1171 fs_state.options.fs_state_restore = 0;
1172 } else if (!strcmp(argv[i], "-fs-state-verify")) {
1173 if ((i + 1) >= argc) {
1174 fprintf(stderr, "missing argument for %s\n", argv[i]);
1178 if (!strcmp(argv[i], "none")) {
1179 fs_state.options.fs_state_verify_before_save = 0;
1180 fs_state.options.fs_state_verify_after_restore = 0;
1181 } else if (!strcmp(argv[i], "save")) {
1182 fs_state.options.fs_state_verify_after_restore = 0;
1183 } else if (!strcmp(argv[i], "restore")) {
1184 fs_state.options.fs_state_verify_before_save = 0;
1185 } else if (!strcmp(argv[i], "both")) {
1188 fprintf(stderr, "invalid argument for %s\n", argv[i-1]);
1191 } else if (!strcmp(argv[i], "-vhashsize")) {
1192 if ((i + 1) >= argc) {
1193 fprintf(stderr, "missing argument for %s\n", argv[i]);
1196 VSetVolHashSize(atoi(argv[++i]));
1197 } else if (!strcmp(argv[i], "-vlrudisable")) {
1198 VLRU_SetOptions(VLRU_SET_ENABLED, 0);
1199 } else if (!strcmp(argv[i], "-vlruthresh")) {
1200 if ((i + 1) >= argc) {
1201 fprintf(stderr, "missing argument for %s\n", argv[i]);
1204 VLRU_SetOptions(VLRU_SET_THRESH, 60*atoi(argv[++i]));
1205 } else if (!strcmp(argv[i], "-vlruinterval")) {
1206 if ((i + 1) >= argc) {
1207 fprintf(stderr, "missing argument for %s\n", argv[i]);
1210 VLRU_SetOptions(VLRU_SET_INTERVAL, atoi(argv[++i]));
1211 } else if (!strcmp(argv[i], "-vlrumax")) {
1212 if ((i + 1) >= argc) {
1213 fprintf(stderr, "missing argument for %s\n", argv[i]);
1216 VLRU_SetOptions(VLRU_SET_MAX, atoi(argv[++i]));
1217 #endif /* AFS_DEMAND_ATTACH_FS */
1218 } else if (!strcmp(argv[i], "-s")) {
1220 if ((i + 1) >= argc) {
1221 fprintf(stderr, "missing argument for -s\n");
1224 nSmallVns = atoi(argv[++i]);
1225 } else if (!strcmp(argv[i], "-abortthreshold")) {
1226 if ((i + 1) >= argc) {
1227 fprintf(stderr, "missing argument for -abortthreshold\n");
1230 abort_threshold = atoi(argv[++i]);
1231 } else if (!strcmp(argv[i], "-k")) {
1232 if ((i + 1) >= argc) {
1233 fprintf(stderr, "missing argument for -k\n");
1236 stack = atoi(argv[++i]);
1238 #if defined(AFS_SGI_ENV)
1239 else if (!strcmp(argv[i], "-lock")) {
1243 else if (!strcmp(argv[i], "-spare")) {
1244 if ((i + 1) >= argc) {
1245 fprintf(stderr, "missing argument for -spare\n");
1248 BlocksSpare = atoi(argv[++i]);
1250 } else if (!strcmp(argv[i], "-pctspare")) {
1251 if ((i + 1) >= argc) {
1252 fprintf(stderr, "missing argument for -pctspare\n");
1255 PctSpare = atoi(argv[++i]);
1256 BlocksSpare = 0; /* has non-zero default */
1258 } else if (!strcmp(argv[i], "-w")) {
1259 if ((i + 1) >= argc) {
1260 fprintf(stderr, "missing argument for -w\n");
1263 fiveminutes = atoi(argv[++i]);
1264 } else if (!strcmp(argv[i], "-hr")) {
1266 if ((i + 1) >= argc) {
1267 fprintf(stderr, "missing argument for -hr\n");
1270 hr = atoi(argv[++i]);
1271 if ((hr < 1) || (hr > 36)) {
1273 ("host acl refresh interval of %d hours is invalid; hours must be between 1 and 36\n\n",
1277 hostaclRefresh = hr * 60 * 60;
1278 } else if (!strcmp(argv[i], "-rxdbg"))
1280 else if (!strcmp(argv[i], "-rxdbge"))
1282 else if (!strcmp(argv[i], "-cb")) {
1284 if ((i + 1) >= argc) {
1285 fprintf(stderr, "missing argument for -cb\n");
1288 numberofcbs = atoi(argv[++i]);
1289 if ((numberofcbs < 10000) || (numberofcbs > 2147483647)) {
1291 ("number of cbs %d invalid; must be between 10000 and 2147483647\n",
1295 } else if (!strcmp(argv[i], "-busyat")) {
1297 if ((i + 1) >= argc) {
1298 fprintf(stderr, "missing argument for -busyat\n");
1301 busy_threshold = atoi(argv[++i]);
1302 if (busy_threshold < 10) {
1304 ("Busy threshold %d is too low, will compute default.\n",
1308 } else if (!strcmp(argv[i], "-nobusy"))
1310 #ifdef AFS_AIX32_ENV
1311 else if (!strcmp(argv[i], "-m")) {
1312 extern int aixlow_water;
1313 if ((i + 1) >= argc) {
1314 fprintf(stderr, "missing argument for -m\n");
1317 aixlow_water = atoi(argv[++i]);
1318 if ((aixlow_water < 0) || (aixlow_water > 30)) {
1319 printf("space reserved %d% invalid; must be between 0-30%\n",
1325 else if (!strcmp(argv[i], "-nojumbo")) {
1327 } else if (!strcmp(argv[i], "-jumbo")) {
1329 } else if (!strcmp(argv[i], "-rxbind")) {
1331 } else if (!strcmp(argv[i], "-allow-dotted-principals")) {
1332 rxkadDisableDotCheck = 1;
1333 } else if (!strcmp(argv[i], "-rxmaxmtu")) {
1334 if ((i + 1) >= argc) {
1335 fprintf(stderr, "missing argument for -rxmaxmtu\n");
1338 rxMaxMTU = atoi(argv[++i]);
1339 if ((rxMaxMTU < RX_MIN_PACKET_SIZE) ||
1340 (rxMaxMTU > RX_MAX_PACKET_DATA_SIZE)) {
1341 printf("rxMaxMTU %d%% invalid; must be between %d-%" AFS_SIZET_FMT "\n",
1342 rxMaxMTU, RX_MIN_PACKET_SIZE,
1343 RX_MAX_PACKET_DATA_SIZE);
1346 } else if (!strcmp(argv[i], "-realm")) {
1347 extern char local_realms[AFS_NUM_LREALMS][AFS_REALM_SZ];
1348 extern int num_lrealms;
1349 if ((i + 1) >= argc) {
1350 fprintf(stderr, "missing argument for -realm\n");
1353 if (strlen(argv[++i]) >= AFS_REALM_SZ) {
1355 ("-realm argument must contain fewer than %d characters.\n",
1359 if (num_lrealms == -1)
1361 if (num_lrealms >= AFS_NUM_LREALMS) {
1363 ("a maximum of %d -realm arguments can be specified.\n",
1367 strncpy(local_realms[num_lrealms++], argv[i], AFS_REALM_SZ);
1368 } else if (!strcmp(argv[i], "-udpsize")) {
1369 if ((i + 1) >= argc) {
1370 printf("You have to specify -udpsize <integer value>\n");
1373 bufSize = atoi(argv[++i]);
1374 if (bufSize < rx_GetMinUdpBufSize())
1376 ("Warning:udpsize %d is less than minimum %d; ignoring\n",
1377 bufSize, rx_GetMinUdpBufSize());
1379 udpBufSize = bufSize;
1380 } else if (!strcmp(argv[i], "-sendsize")) {
1381 if ((i + 1) >= argc) {
1382 printf("You have to specify -sendsize <integer value>\n");
1385 bufSize = atoi(argv[++i]);
1386 if (bufSize < 16384)
1388 ("Warning:sendsize %d is less than minimum %d; ignoring\n",
1391 sendBufSize = bufSize;
1392 } else if (!strcmp(argv[i], "-enable_peer_stats")) {
1393 rx_enablePeerRPCStats();
1394 } else if (!strcmp(argv[i], "-enable_process_stats")) {
1395 rx_enableProcessRPCStats();
1397 else if (strcmp(argv[i], "-auditlog") == 0) {
1398 auditFileName = argv[++i];
1400 else if (strcmp(argv[i], "-audit-interface") == 0) {
1401 char *interface = argv[++i];
1403 if (osi_audit_interface(interface)) {
1404 printf("Invalid audit interface '%s'\n", interface);
1408 #ifndef AFS_NT40_ENV
1409 else if (strcmp(argv[i], "-syslog") == 0) {
1410 /* set syslog logging flag */
1411 serverLogSyslog = 1;
1412 } else if (strncmp(argv[i], "-syslog=", 8) == 0) {
1413 serverLogSyslog = 1;
1414 serverLogSyslogFacility = atoi(argv[i] + 8);
1417 else if (strcmp(argv[i], "-mrafslogs") == 0) {
1418 /* set syslog logging flag */
1421 else if (strcmp(argv[i], "-saneacls") == 0) {
1429 printf("Only one of -L, or -S must be specified\n");
1440 numberofcbs = 20000;
1456 numberofcbs = 64000;
1465 busy_threshold = 3 * rxpackets / 2;
1467 osi_audit_file(auditFileName);
1477 NewParms(int initializing)
1479 static struct afs_stat sbuf;
1482 char *argv[MAXPARMS];
1485 if (!(afs_stat("/vice/file/parms", &sbuf))) {
1486 parms = (char *)malloc(sbuf.st_size);
1489 fd = afs_open("parms", O_RDONLY, 0666);
1491 ViceLog(0, ("Open for parms failed with errno = %d\n", errno));
1495 i = read(fd, parms, sbuf.st_size);
1497 if (i != sbuf.st_size) {
1499 ViceLog(0, ("Read on parms failed with errno = %d\n", errno));
1502 ("Read on parms failed; expected %ld bytes but read %d\n",
1503 (long) sbuf.st_size, i));
1509 for (i = 0; i < MAXPARMS; argv[i++] = 0);
1511 for (argc = i = 0; i < sbuf.st_size; i++) {
1512 if ((*(parms + i) != ' ') && (*(parms + i) != '\n')) {
1513 if (argv[argc] == 0)
1514 argv[argc] = (parms + i);
1516 *(parms + i) = '\0';
1517 if (argv[argc] != 0) {
1518 if (++argc == MAXPARMS)
1521 while ((*(parms + i + 1) == ' ')
1522 || (*(parms + i + 1) == '\n'))
1526 if (ParseArgs(argc, argv) == 0) {
1527 ViceLog(0, ("Change parameters to:"));
1529 ViceLog(0, ("Invalid parameter in:"));
1531 for (i = 0; i < argc; i++) {
1532 ViceLog(0, (" %s", argv[i]));
1536 } else if (!initializing)
1538 ("Received request to change parms but no parms file exists\n"));
1543 /* Miscellaneous routines */
1547 ViceLog(0, ("%s\n", msg));
1559 * If this fails, it's because something major is wrong, and is not
1560 * likely to be time dependent.
1562 code = pr_Initialize(2, AFSDIR_SERVER_ETC_DIRPATH, 0);
1565 ("Couldn't initialize protection library; code=%d.\n", code));
1569 #ifdef AFS_PTHREAD_ENV
1570 assert(pthread_key_create(&viced_uclient_key, NULL) == 0);
1573 SystemId = SYSADMINID;
1574 SystemAnyUser = ANYUSERID;
1575 SystemAnyUserCPS.prlist_len = 0;
1576 SystemAnyUserCPS.prlist_val = NULL;
1577 AnonCPS.prlist_len = 0;
1578 AnonCPS.prlist_val = NULL;
1580 code = pr_GetCPS(SystemAnyUser, &SystemAnyUserCPS);
1583 ("Couldn't get CPS for AnyUser, will try again in 30 seconds; code=%d.\n",
1587 code = pr_GetCPS(ANONYMOUSID, &AnonCPS);
1590 ("Couldn't get Anonymous CPS, exiting; code=%d.\n",
1594 AnonymousID = ANONYMOUSID;
1597 #ifdef AFS_PTHREAD_ENV
1599 #else /* AFS_PTHREAD_ENV */
1601 #endif /* AFS_PTHREAD_ENV */
1605 struct rx_connection *serverconns[MAXSERVERS];
1606 struct ubik_client *cstruct;
1609 vl_Initialize(const char *confDir)
1611 afs_int32 code, scIndex = 0, i;
1612 struct afsconf_dir *tdir;
1613 struct rx_securityClass *sc;
1614 struct afsconf_cell info;
1616 tdir = afsconf_Open(confDir);
1619 ("Could not open configuration directory (%s).\n", confDir));
1622 code = afsconf_ClientAuth(tdir, &sc, &scIndex);
1624 ViceLog(0, ("Could not get security object for localAuth\n"));
1627 code = afsconf_GetCellInfo(tdir, NULL, AFSCONF_VLDBSERVICE, &info);
1628 if (info.numServers > MAXSERVERS) {
1630 ("vl_Initialize: info.numServers=%d (> MAXSERVERS=%d)\n",
1631 info.numServers, MAXSERVERS));
1634 for (i = 0; i < info.numServers; i++)
1636 rx_NewConnection(info.hostAddr[i].sin_addr.s_addr,
1637 info.hostAddr[i].sin_port, USER_SERVICE_ID, sc,
1639 code = ubik_ClientInit(serverconns, &cstruct);
1640 afsconf_Close(tdir);
1642 ViceLog(0, ("vl_Initialize: ubik client init failed.\n"));
1648 #define SYSIDMAGIC 0x88aabbcc
1649 #define SYSIDVERSION 1
1654 afs_int32 fd, nentries, i;
1655 struct versionStamp vsn;
1656 struct afs_stat status;
1659 if ((afs_stat(AFSDIR_SERVER_SYSID_FILEPATH, &status))
1660 || (status.st_size <= 0)) {
1661 ViceLog(0, ("%s: doesn't exist\n", AFSDIR_SERVER_SYSID_FILEPATH));
1664 if (!(fd = afs_open(AFSDIR_SERVER_SYSID_FILEPATH, O_RDONLY, 0))) {
1666 ("%s: can't open (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1670 if ((i = read(fd, (char *)&vsn, sizeof(vsn))) != sizeof(vsn)) {
1672 ("%s: Read failed (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1676 if (vsn.magic != SYSIDMAGIC) {
1678 ("%s: wrong magic %x (we support %x)\n",
1679 AFSDIR_SERVER_SYSID_FILEPATH, vsn.magic, SYSIDMAGIC));
1682 if (vsn.version != SYSIDVERSION) {
1684 ("%s: wrong version %d (we support %d)\n",
1685 AFSDIR_SERVER_SYSID_FILEPATH, vsn.version, SYSIDVERSION));
1689 read(fd, (char *)&uuid,
1690 sizeof(struct afsUUID))) != sizeof(struct afsUUID)) {
1692 ("%s: read of uuid failed (%d)\n",
1693 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1696 afs_ntohuuid(&uuid);
1699 read(fd, (char *)&nentries,
1700 sizeof(afs_int32))) != sizeof(afs_int32)) {
1702 ("%s: Read of entries failed (%d)\n",
1703 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1706 if (nentries <= 0 || nentries > ADDRSPERSITE) {
1708 ("%s: invalid num of interfaces: %d\n",
1709 AFSDIR_SERVER_SYSID_FILEPATH, nentries));
1712 if (FS_HostAddr_cnt == 0) {
1713 FS_HostAddr_cnt = nentries;
1714 for (i = 0; i < nentries; i++) {
1715 if (read(fd, (char *)&FS_HostAddrs[i], sizeof(afs_int32)) !=
1716 sizeof(afs_int32)) {
1718 ("%s: Read of addresses failed (%d)\n",
1719 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1720 FS_HostAddr_cnt = 0; /* reset it */
1726 ("%s: address list ignored (NetInfo/NetRestrict override)\n",
1727 AFSDIR_SERVER_SYSID_FILEPATH));
1734 WriteSysIdFile(void)
1737 struct versionStamp vsn;
1738 struct afs_stat status;
1741 if (!afs_stat(AFSDIR_SERVER_SYSID_FILEPATH, &status)) {
1743 * File exists; keep the old one around
1745 renamefile(AFSDIR_SERVER_SYSID_FILEPATH,
1746 AFSDIR_SERVER_OLDSYSID_FILEPATH);
1748 fd = afs_open(AFSDIR_SERVER_SYSID_FILEPATH, O_WRONLY | O_TRUNC | O_CREAT,
1752 ("%s: can't create (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1756 vsn.magic = SYSIDMAGIC;
1758 if ((i = write(fd, (char *)&vsn, sizeof(vsn))) != sizeof(vsn)) {
1760 ("%s: write failed (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1765 afs_htonuuid(&uuid);
1767 write(fd, (char *)&uuid,
1768 sizeof(struct afsUUID))) != sizeof(struct afsUUID)) {
1770 ("%s: write of uuid failed (%d)\n",
1771 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1775 write(fd, (char *)&FS_HostAddr_cnt,
1776 sizeof(afs_int32))) != sizeof(afs_int32)) {
1778 ("%s: write of # of entries failed (%d)\n",
1779 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1782 for (i = 0; i < FS_HostAddr_cnt; i++) {
1783 if (write(fd, (char *)&FS_HostAddrs[i], sizeof(afs_int32)) !=
1784 sizeof(afs_int32)) {
1786 ("%s: write of addresses failed (%d)\n",
1787 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1797 * This routine sets up the buffers for the VL_RegisterAddrs RPC. All addresses
1798 * in FS_HostAddrs[] are in NBO, while the RPC treats them as a "blob" of data
1799 * and so we need to convert each of them into HBO which is what the extra
1800 * array called FS_HostAddrs_HBO is used here.
1803 Do_VLRegisterRPC(void)
1807 afs_uint32 FS_HostAddrs_HBO[ADDRSPERSITE];
1810 for (i = 0; i < FS_HostAddr_cnt; i++)
1811 FS_HostAddrs_HBO[i] = ntohl(FS_HostAddrs[i]);
1812 addrs.bulkaddrs_len = FS_HostAddr_cnt;
1813 addrs.bulkaddrs_val = (afs_uint32 *) FS_HostAddrs_HBO;
1814 code = ubik_VL_RegisterAddrs(cstruct, 0, &FS_HostUUID, 0, &addrs);
1816 if (code == VL_MULTIPADDR) {
1818 ("VL_RegisterAddrs rpc failed; The IP address exists on a different server; repair it\n"));
1820 ("VL_RegisterAddrs rpc failed; See VLLog for details\n"));
1822 } else if (code == RXGEN_OPCODE) {
1824 ("vlserver doesn't support VL_RegisterAddrs rpc; ignored\n"));
1825 FS_registered = 2; /* So we don't have to retry in the gc daemon */
1828 ("VL_RegisterAddrs rpc failed; will retry periodically (code=%d, err=%d)\n",
1830 FS_registered = 1; /* Retry in the gc daemon */
1833 FS_registered = 2; /* So we don't have to retry in the gc daemon */
1845 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH || AFSDIR_SERVER_NETINFO_FILEPATH) {
1847 * Find addresses we are supposed to register as per the netrestrict
1848 * and netinfo files (/usr/afs/local/NetInfo and
1849 * /usr/afs/local/NetRestict)
1852 afs_int32 code = parseNetFiles(FS_HostAddrs, NULL, NULL,
1853 ADDRSPERSITE, reason,
1854 AFSDIR_SERVER_NETINFO_FILEPATH,
1855 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
1857 ViceLog(0, ("Can't register any valid addresses: %s\n", reason));
1860 FS_HostAddr_cnt = (afs_uint32) code;
1863 FS_HostAddr_cnt = rx_getAllAddr(FS_HostAddrs, ADDRSPERSITE);
1866 if (FS_HostAddr_cnt == 1 && rxBind == 1)
1867 code = FS_HostAddrs[0];
1869 code = htonl(INADDR_ANY);
1879 * If this fails, it's because something major is wrong, and is not
1880 * likely to be time dependent.
1882 code = vl_Initialize(AFSDIR_SERVER_ETC_DIRPATH);
1885 ("Couldn't initialize protection library; code=%d.\n", code));
1889 /* Read or create the sysid file and register the fileserver's
1890 * IP addresses with the vlserver.
1892 code = ReadSysIdFile();
1894 /* Need to create the file */
1895 ViceLog(0, ("Creating new SysID file\n"));
1896 if ((code = afs_uuid_create(&FS_HostUUID))) {
1897 ViceLog(0, ("Failed to create new uuid: %d\n", code));
1901 /* A good sysid file exists; inform the vlserver. If any conflicts,
1902 * we always use the latest interface available as the real truth.
1905 code = Do_VLRegisterRPC();
1910 main(int argc, char *argv[])
1914 struct rx_securityClass **securityClasses;
1915 afs_int32 numClasses;
1916 struct rx_service *tservice;
1917 #ifdef AFS_PTHREAD_ENV
1918 pthread_t serverPid;
1919 pthread_attr_t tattr;
1920 #else /* AFS_PTHREAD_ENV */
1921 PROCESS parentPid, serverPid;
1922 #endif /* AFS_PTHREAD_ENV */
1924 int minVnodesRequired; /* min size of vnode cache */
1925 #ifndef AFS_NT40_ENV
1926 struct rlimit rlim; /* max number of open file descriptors */
1930 afs_uint32 rx_bindhost;
1931 VolumePackageOptions opts;
1933 #ifdef AFS_AIX32_ENV
1934 struct sigaction nsa;
1936 sigemptyset(&nsa.sa_mask);
1937 nsa.sa_handler = SIG_DFL;
1938 nsa.sa_flags = SA_FULLDUMP;
1939 sigaction(SIGABRT, &nsa, NULL);
1940 sigaction(SIGSEGV, &nsa, NULL);
1944 /* Initialize dirpaths */
1945 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
1947 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
1949 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
1953 #ifndef AFS_QUIETFS_ENV
1954 console = afs_fopen("/dev/console", "w");
1956 /* set ihandle package defaults prior to parsing args */
1959 if (ParseArgs(argc, argv)) {
1963 #ifdef AFS_PTHREAD_ENV
1964 assert(pthread_mutex_init(&fileproc_glock_mutex, NULL) == 0);
1965 #endif /* AFS_PTHREAD_ENV */
1967 #ifdef AFS_SGI_VNODE_GLUE
1968 if (afs_init_kernel_config(-1) < 0) {
1970 ("Can't determine NUMA configuration, not starting fileserver.\n");
1974 confDir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
1976 fprintf(stderr, "Unable to open config directory %s\n",
1977 AFSDIR_SERVER_ETC_DIRPATH);
1983 /* Open FileLog on stdout, stderr, fd 1 and fd2 (for perror), sigh. */
1984 #ifndef AFS_NT40_ENV
1985 serverLogSyslogTag = "fileserver";
1987 OpenLog(AFSDIR_SERVER_FILELOG_FILEPATH);
1990 if (SawSpare && SawPctSpare) {
1991 ViceLog(0, ("Both -spare and -pctspare specified, exiting.\n"));
1994 #ifdef AFS_SGI_XFS_IOPS_ENV
1995 ViceLog(0, ("XFS/EFS File server starting\n"));
1997 ViceLog(0, ("File server starting\n"));
2000 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
2001 /* initialize the pthread soft signal handler thread */
2005 /* install signal handlers for controlling the fileserver process */
2006 ResetCheckSignal(); /* set CheckSignal_Signal() sig handler */
2007 ResetCheckDescriptors(); /* set CheckDescriptors_Signal() sig handler */
2009 #if defined(AFS_SGI_ENV)
2010 /* give this guy a non-degrading priority so help busy servers */
2011 schedctl(NDPRI, 0, NDPNORMMAX);
2015 #ifndef AFS_NT40_ENV
2016 nice(-5); /* TODO: */
2019 assert(DInit(buffs) == 0);
2020 #ifdef AFS_DEMAND_ATTACH_FS
2025 if (afs_winsockInit() < 0) {
2026 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
2027 ViceLog(0, ("File server failed to intialize winsock.\n"));
2033 /* if we support more than 16 threads, then we better have the ability
2034 ** to keep open a large number of files simultaneously
2036 #if defined(AFS_AIX_ENV) && !defined(AFS_AIX42_ENV)
2037 curLimit = OPEN_MAX; /* for pre AIX 4.2 systems */
2038 #elif defined(AFS_NT40_ENV)
2039 curLimit = NT_OPEN_MAX; /* open file descriptor limit on NT */
2042 curLimit = 0; /* the number of open file descriptors */
2043 code = getrlimit(RLIMIT_NOFILE, &rlim);
2045 curLimit = rlim.rlim_cur;
2046 rlim.rlim_cur = rlim.rlim_max;
2047 code = setrlimit(RLIMIT_NOFILE, &rlim);
2049 curLimit = rlim.rlim_max;
2052 ViceLog(0, ("Failed to increase open file limit, using default\n"));
2054 #endif /* defined(AFS_AIX_ENV) && !defined(AFS_AIX42_ENV) */
2056 curLimit -= 32; /* leave a slack of 32 file descriptors */
2057 if (lwps > curLimit) {
2061 lwps = 16; /* default to a maximum of 16 threads */
2063 /* tune the ihandle fd cache accordingly */
2064 if (vol_io_params.fd_max_cachesize < curLimit)
2065 vol_io_params.fd_max_cachesize = curLimit + 1;
2068 ("The system supports a max of %d open files and we are starting %d threads (ihandle fd cache is %d)\n",
2069 curLimit, lwps, vol_io_params.fd_max_cachesize));
2071 #ifndef AFS_PTHREAD_ENV
2072 assert(LWP_InitializeProcessSupport(LWP_MAX_PRIORITY - 2, &parentPid) ==
2074 #endif /* !AFS_PTHREAD_ENV */
2076 /* Initialize volume support */
2078 V_BreakVolumeCallbacks = BreakVolumeCallBacksLater;
2081 #ifdef AFS_PTHREAD_ENV
2082 SetLogThreadNumProgram( threadNum );
2085 /* initialize libacl routines */
2086 acl_Initialize(ACL_VERSION);
2088 /* initialize RX support */
2089 #ifndef AFS_NT40_ENV
2090 rxi_syscallp = viced_syscall;
2092 rx_extraPackets = rxpackets;
2093 rx_extraQuota = 4; /* for outgoing prserver calls from R threads */
2094 rx_SetBusyThreshold(busy_threshold, VBUSY);
2095 rx_SetCallAbortThreshold(abort_threshold);
2096 rx_SetConnAbortThreshold(abort_threshold);
2098 stackSize = 128 * 1024;
2100 stackSize = lwps * 4000;
2101 if (stackSize < 32000)
2103 else if (stackSize > 44000)
2106 #if defined(AFS_HPUX_ENV) || defined(AFS_SUN_ENV) || defined(AFS_SGI51_ENV) || defined(AFS_XBSD_ENV)
2107 rx_SetStackSize(1, stackSize);
2110 rx_SetUdpBufSize(udpBufSize); /* set the UDP buffer size for receive */
2111 rx_bindhost = SetupVL();
2113 if (rx_InitHost(rx_bindhost, (int)htons(7000)) < 0) {
2114 ViceLog(0, ("Cannot initialize RX\n"));
2117 if (!rxJumbograms) {
2118 /* Don't send and don't allow 3.4 clients to send jumbograms. */
2121 if (rxMaxMTU != -1) {
2122 rx_SetMaxMTU(rxMaxMTU);
2125 rx_SetRxDeadTime(30);
2126 afsconf_BuildServerSecurityObjects(confDir, AFSCONF_SEC_OBJS_RXKAD_CRYPT,
2127 &securityClasses, &numClasses);
2129 tservice = rx_NewServiceHost(rx_bindhost, /* port */ 0, /* service id */
2130 1, /*service name */
2132 securityClasses, numClasses,
2133 RXAFS_ExecuteRequest);
2136 ("Failed to initialize RX, probably two servers running.\n"));
2139 if (rxkadDisableDotCheck) {
2140 rx_SetSecurityConfiguration(tservice, RXS_CONFIG_FLAGS,
2141 (void *)RXS_CONFIG_FLAGS_DISABLE_DOTCHECK);
2143 rx_SetMinProcs(tservice, 3);
2144 rx_SetMaxProcs(tservice, lwps);
2145 rx_SetCheckReach(tservice, 1);
2146 rx_SetServerIdleDeadErr(tservice, VNOSERVICE);
2149 rx_NewService(0, RX_STATS_SERVICE_ID, "rpcstats", securityClasses,
2150 numClasses, RXSTATS_ExecuteRequest);
2152 ViceLog(0, ("Failed to initialize rpc stat service.\n"));
2155 rx_SetMinProcs(tservice, 2);
2156 rx_SetMaxProcs(tservice, 4);
2159 * Enable RX hot threads, which allows the listener thread to trade
2160 * places with an idle thread and moves the context switch from listener
2161 * to worker out of the critical path.
2163 rx_EnableHotThread();
2165 /* Some rx debugging */
2166 if (rxlog || eventlog) {
2167 debugFile = afs_fopen("rx_dbg", "w");
2169 rx_debugFile = debugFile;
2171 rxevent_debugFile = debugFile;
2174 init_sys_error_to_et(); /* Set up error table translation */
2175 h_InitHostPackage(); /* set up local cellname and realmname */
2176 InitCallBack(numberofcbs);
2180 if (code && code != VL_MULTIPADDR) {
2181 ViceLog(0, ("Fatal error in library initialization, exiting!!\n"));
2186 if (code && code != -1) {
2187 ViceLog(0, ("Fatal error in protection initialization, exiting!!\n"));
2191 /* allow super users to manage RX statistics */
2192 rx_SetRxStatUserOk(fs_rxstat_userok);
2194 #ifdef AFS_PTHREAD_ENV
2195 assert(pthread_cond_init(&fsync_cond, NULL) == 0);
2196 assert(pthread_mutex_init(&fsync_glock_mutex, NULL) == 0);
2199 #if !defined(AFS_DEMAND_ATTACH_FS)
2201 * For DAFS, we do not start the Rx server threads until after
2202 * the volume package is initialized, and fileserver state is
2203 * restored. This is necessary in order to keep host and callback
2204 * package state pristine until we have a chance to restore state.
2206 * Furthermore, startup latency is much lower with dafs, so this
2207 * shouldn't pose a serious problem.
2209 rx_StartServer(0); /* now start handling requests */
2212 /* we ensure that there is enough space in the vnode buffer to satisfy
2213 ** requests from all concurrent threads.
2214 ** the maximum number of vnodes used by a single thread at any one time
2215 ** is three ( "link" uses three vnodes simultaneously, one vLarge and
2216 ** two vSmall for linking files and two vLarge and one vSmall for linking
2219 minVnodesRequired = 2 * lwps + 1;
2220 if (minVnodesRequired > nSmallVns) {
2221 nSmallVns = minVnodesRequired;
2223 ("Overriding -s command line parameter with %d\n",
2226 if (minVnodesRequired > large) {
2227 large = minVnodesRequired;
2228 ViceLog(0, ("Overriding -l command line parameter with %d\n", large));
2231 /* We now do this after getting the listener up and running, so that client
2232 * connections don't timeout (maybe) if a file server is restarted, since it
2233 * will be available "real soon now". Worry about whether we can satisfy the
2234 * calls in the volume package itself.
2236 VOptDefaults(fileServer, &opts);
2237 opts.nLargeVnodes = large;
2238 opts.nSmallVnodes = nSmallVns;
2239 opts.volcache = volcache;
2241 if (VInitVolumePackage2(fileServer, &opts)) {
2243 ("Shutting down: errors encountered initializing volume package\n"));
2248 /* Install handler to catch the shutdown signal;
2249 * bosserver assumes SIGQUIT shutdown
2251 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
2252 softsig_signal(SIGQUIT, ShutDown_Signal);
2254 (void)signal(SIGQUIT, ShutDown_Signal);
2257 if (VInitAttachVolumes(fileServer)) {
2259 ("Shutting down: errors encountered initializing volume package\n"));
2264 #ifdef AFS_DEMAND_ATTACH_FS
2265 if (fs_state.options.fs_state_restore) {
2268 * restore fileserver state */
2271 rx_StartServer(0); /* now start handling requests */
2272 #endif /* AFS_DEMAND_ATTACH_FS */
2275 * We are done calling fopen/fdopen. It is safe to use a large
2276 * of the file descriptor cache.
2280 #ifdef AFS_PTHREAD_ENV
2281 ViceLog(5, ("Starting pthreads\n"));
2282 assert(pthread_attr_init(&tattr) == 0);
2283 assert(pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED) == 0);
2285 assert(pthread_create
2286 (&serverPid, &tattr, FiveMinuteCheckLWP,
2287 &fiveminutes) == 0);
2288 assert(pthread_create
2289 (&serverPid, &tattr, HostCheckLWP, &fiveminutes) == 0);
2290 assert(pthread_create
2291 (&serverPid, &tattr, FsyncCheckLWP, &fiveminutes) == 0);
2292 #else /* AFS_PTHREAD_ENV */
2293 ViceLog(5, ("Starting LWP\n"));
2294 assert(LWP_CreateProcess
2295 (FiveMinuteCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
2296 (void *)&fiveminutes, "FiveMinuteChecks",
2297 &serverPid) == LWP_SUCCESS);
2299 assert(LWP_CreateProcess
2300 (HostCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
2301 (void *)&fiveminutes, "HostCheck", &serverPid) == LWP_SUCCESS);
2302 assert(LWP_CreateProcess
2303 (FsyncCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
2304 (void *)&fiveminutes, "FsyncCheck", &serverPid) == LWP_SUCCESS);
2305 #endif /* AFS_PTHREAD_ENV */
2307 FT_GetTimeOfDay(&tp, 0);
2309 #ifndef AFS_QUIETFS_ENV
2310 if (console != NULL) {
2311 time_t t = tp.tv_sec;
2312 fprintf(console, "File server has started at %s\r",
2313 afs_ctime(&t, tbuffer, sizeof(tbuffer)));
2318 * Figure out the FileServer's name and primary address.
2320 ViceLog(0, ("Getting FileServer name...\n"));
2321 code = gethostname(FS_HostName, 64);
2323 ViceLog(0, ("gethostname() failed\n"));
2325 ViceLog(0, ("FileServer host name is '%s'\n", FS_HostName));
2327 ViceLog(0, ("Getting FileServer address...\n"));
2328 he = gethostbyname(FS_HostName);
2330 ViceLog(0, ("Can't find address for FileServer '%s'\n", FS_HostName));
2333 memcpy(&FS_HostAddr_NBO, he->h_addr, 4);
2334 (void)afs_inet_ntoa_r(FS_HostAddr_NBO, hoststr);
2335 FS_HostAddr_HBO = ntohl(FS_HostAddr_NBO);
2337 ("FileServer %s has address %s (0x%x or 0x%x in host byte order)\n",
2338 FS_HostName, hoststr, FS_HostAddr_NBO, FS_HostAddr_HBO));
2343 ("File Server started %s",
2344 afs_ctime(&t, tbuffer, sizeof(tbuffer))));
2345 #if FS_STATS_DETAILED
2346 afs_FullPerfStats.det.epoch.tv_sec = StartTime = tp.tv_sec;
2348 #ifdef AFS_PTHREAD_ENV
2350 sleep(1000); /* long time */
2352 #else /* AFS_PTHREAD_ENV */
2353 assert(LWP_WaitProcess(&parentPid) == LWP_SUCCESS);
2354 #endif /* AFS_PTHREAD_ENV */