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
10 /* viced.c - File Server main loop */
14 /* Function - This routine has the initialization code for */
17 /* ********************************************************************** */
19 #include <afsconfig.h>
20 #include <afs/param.h>
28 #include <sys/types.h>
29 #include <afs/procmgmt.h> /* signal(), kill(), wait(), etc. */
35 #include <WINNT/afsevent.h>
38 #include <netinet/in.h>
40 #include <unistd.h> /* sysconf() */
52 #endif /* ITIMER_REAL */
53 #include <sys/resource.h>
54 #endif /* AFS_NT40_ENV */
59 #ifdef AFS_PTHREAD_ENV
61 #else /* AFS_PTHREAD_ENV */
62 #include <afs/assert.h>
63 #endif /* AFS_PTHREAD_ENV */
66 #include <afs/ptclient.h>
67 #include <afs/afsint.h>
68 #include <afs/vldbint.h>
69 #include <afs/errors.h>
70 #include <afs/ihandle.h>
71 #include <afs/vnode.h>
72 #include <afs/volume.h>
74 #include <afs/cellconfig.h>
76 #include <afs/prs_fs.h>
80 #include <afs/afs_args.h>
81 #include <afs/vlserver.h>
82 #include <afs/afsutil.h>
83 #include <afs/fileutil.h>
85 #include <afs/netutils.h>
89 #ifdef AFS_PTHREAD_ENV
91 char *(*threadNameProgram) ();
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 */
111 extern int BreakVolumeCallBacks(), InitCallBack();
112 extern int BreakVolumeCallBacks(), InitCallBack(), BreakLaterCallBacks();
113 extern int BreakVolumeCallBacksLater();
114 extern int LogLevel, etext;
115 extern afs_int32 BlocksSpare, PctSpare;
118 static void ClearXStatValues(), NewParms(), PrintCounters();
119 static void ResetCheckDescriptors(void), ResetCheckSignal(void);
120 static void CheckSignal(void);
121 extern int GetKeysFromToken();
122 extern int RXAFS_ExecuteRequest();
123 extern int RXSTATS_ExecuteRequest();
124 afs_int32 Do_VLRegisterRPC();
126 int eventlog = 0, rxlog = 0;
128 FILE *console = NULL;
130 #ifdef AFS_PTHREAD_ENV
131 pthread_mutex_t fsync_glock_mutex;
132 pthread_cond_t fsync_cond;
135 #endif /* AFS_PTHREAD_ENV */
138 #define AFS_QUIETFS_ENV 1
139 #define NT_OPEN_MAX 1024 /* This is an arbitrary no. we came up with for
140 * now. We hope this will be replaced by a more
141 * intelligent estimate later. */
144 int SystemId; /* ViceID of "Administrators" */
145 int SystemAnyUser; /* Viceid of "System:AnyUser" */
146 prlist SystemAnyUserCPS; /* CPS for "system:AnyUser */
147 int AnonymousID = 0; /* ViceId of "Anonymous" */
148 prlist AnonCPS; /* CPS for "Anonymous" */
150 struct afsconf_dir *confDir; /* Configuration dir object */
152 int restartMode = RESTART_ORDINARY;
154 int Testing = 0; /* for ListViceInodes */
157 * Home for the performance statistics.
159 struct afs_PerfStats afs_perfstats;
162 extern int Statistics;
170 int rxJumbograms = 1; /* default is to send and receive jumbograms. */
171 afs_int32 implicitAdminRights = PRSFS_LOOKUP; /* The ADMINISTER right is
173 afs_int32 readonlyServer = 0;
176 int stackSize = 24000;
177 int fiveminutes = 300; /* 5 minutes. Change this for debugging only */
178 int CurrentConnections = 0;
179 int hostaclRefresh = 7200; /* refresh host clients' acls every 2 hrs */
180 #if defined(AFS_SGI_ENV)
185 int rxpackets = 150; /* 100 */
186 int nSmallVns = 400; /* 200 */
187 int large = 400; /* 200 */
188 int volcache = 400; /* 400 */
189 int numberofcbs = 60000; /* 60000 */
190 int lwps = 9; /* 6 */
191 int buffs = 90; /* 70 */
192 int novbc = 0; /* Enable Volume Break calls */
193 int busy_threshold = 600;
194 int abort_threshold = 10;
195 int udpBufSize = 0; /* UDP buffer size for receive */
196 int sendBufSize = 16384; /* send buffer size */
201 * FileServer's name and IP address, both network byte order and
204 #define ADDRSPERSITE 16 /* Same global is in rx/rx_user.c */
206 char FS_HostName[128] = "localhost";
207 afs_uint32 FS_HostAddr_NBO;
208 afs_uint32 FS_HostAddr_HBO;
209 afs_uint32 FS_HostAddrs[ADDRSPERSITE], FS_HostAddr_cnt = 0, FS_registered = 0;
210 /* All addresses in FS_HostAddrs are in NBO */
213 static void FlagMsg();
216 * Home for the performance statistics.
224 struct afs_stat status;
225 register int tsize = getdtablesize();
227 for (i = 0; i < tsize; i++) {
228 if (afs_fstat(i, &status) != -1) {
229 printf("%d: dev %x, inode %u, length %u, type/mode %x\n", i,
230 status.st_dev, status.st_ino, status.st_size,
235 ResetCheckDescriptors();
237 } /*CheckDescriptors */
240 #ifdef AFS_PTHREAD_ENV
242 CheckSignal_Signal(x)
254 CheckDescriptors_Signal(x)
258 #else /* AFS_PTHREAD_ENV */
260 CheckSignal_Signal(x)
262 IOMGR_SoftSig(CheckSignal, 0);
268 IOMGR_SoftSig(ShutDown, 0);
272 CheckDescriptors_Signal(x)
274 IOMGR_SoftSig(CheckDescriptors, 0);
276 #endif /* AFS_PTHREAD_ENV */
278 /* check whether caller is authorized to manage RX statistics */
280 fs_rxstat_userok(struct rx_call *call)
282 return afsconf_SuperUser(confDir, call, NULL);
286 ResetCheckSignal(void)
290 #if defined(AFS_HPUX_ENV)
293 #if defined(AFS_NT40_ENV)
300 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
301 softsig_signal(signo, CheckSignal_Signal);
303 signal(signo, CheckSignal_Signal);
308 ResetCheckDescriptors(void)
311 #if defined(AFS_PTHREAD_ENV)
312 softsig_signal(SIGTERM, CheckDescriptors_Signal);
314 (void)signal(SIGTERM, CheckDescriptors_Signal);
319 #if defined(AFS_PTHREAD_ENV)
324 if (LogLevel > 999) {
325 afs_snprintf(threadid, 16, "%d", pthread_getspecific(rx_thread_id_key));
332 /* proc called by rxkad module to get a key */
334 get_key(char *arock, register afs_int32 akvno, char *akey)
337 static struct afsconf_key tkey;
338 register afs_int32 code;
341 ViceLog(0, ("conf dir not open\n"));
344 code = afsconf_GetKey(confDir, akvno, tkey.key);
347 memcpy(akey, tkey.key, sizeof(tkey.key));
354 viced_syscall(afs_uint32 a3, afs_uint32 a4, void *a5)
359 #ifndef AFS_LINUX20_ENV
360 old = (void (*)())signal(SIGSYS, SIG_IGN);
362 rcode = syscall(AFS_SYSCALL, 28 /* AFSCALL_CALL */ , a3, a4, a5);
363 #ifndef AFS_LINUX20_ENV
371 #if !defined(AFS_NT40_ENV)
372 #include "AFS_component_version_number.c"
373 #endif /* !AFS_NT40_ENV */
375 #define MAXADMINNAME 64
376 char adminName[MAXADMINNAME];
382 struct afs_stat status;
384 if ((afs_stat("/AdminName", &status)) || /* if file does not exist */
385 (status.st_size <= 0) || /* or it is too short */
386 (status.st_size >= (MAXADMINNAME)) || /* or it is too long */
387 !(fd = afs_open("/AdminName", O_RDONLY, 0))) { /* or the open fails */
388 strcpy(adminName, "System:Administrators"); /* use the default name */
390 (void)read(fd, adminName, status.st_size); /* use name from the file */
393 close(fd); /* close fd if it was opened */
395 } /*CheckAdminName */
401 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
402 /* set our 'thread-id' so that the host hold table works */
403 MUTEX_ENTER(&rx_stats_mutex); /* protects rxi_pthread_hinum */
405 pthread_setspecific(rx_thread_id_key, (void *)rxi_pthread_hinum);
406 MUTEX_EXIT(&rx_stats_mutex);
408 ("Set thread id %d for '%s'\n",
409 pthread_getspecific(rx_thread_id_key), s));
413 /* This LWP does things roughly every 5 minutes */
420 ViceLog(1, ("Starting five minute check process\n"));
421 setThreadId("FiveMinuteCheckLWP");
423 #ifdef AFS_PTHREAD_ENV
425 #else /* AFS_PTHREAD_ENV */
426 IOMGR_Sleep(fiveminutes);
427 #endif /* AFS_PTHREAD_ENV */
429 /* close the log so it can be removed */
430 ReOpenLog(AFSDIR_SERVER_FILELOG_FILEPATH); /* don't trunc, just append */
431 ViceLog(2, ("Cleaning up timed out callbacks\n"));
432 if (CleanupTimedOutCallBacks())
433 ViceLog(5, ("Timed out callbacks deleted\n"));
434 ViceLog(2, ("Set disk usage statistics\n"));
436 if (FS_registered == 1)
438 /* Force wakeup in case we missed something; pthreads does timedwait */
439 #ifndef AFS_PTHREAD_ENV
440 LWP_NoYieldSignal(fsync_wait);
442 if (printBanner && (++msg & 1)) { /* Every 10 minutes */
443 time_t now = FT_ApproxTime();
444 if (console != NULL) {
445 #ifndef AFS_QUIETFS_ENV
446 fprintf(console, "File server is running at %s\r",
447 afs_ctime(&now, tbuffer, sizeof(tbuffer)));
448 #endif /* AFS_QUIETFS_ENV */
450 ("File server is running at %s\n",
451 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
455 } /*FiveMinuteCheckLWP */
458 /* This LWP does host checks every 5 minutes: it should not be used for
459 * other 5 minute activities because it may be delayed by timeouts when
460 * it probes the workstations
465 ViceLog(1, ("Starting Host check process\n"));
466 setThreadId("HostCheckLWP");
468 #ifdef AFS_PTHREAD_ENV
470 #else /* AFS_PTHREAD_ENV */
471 IOMGR_Sleep(fiveminutes);
472 #endif /* AFS_PTHREAD_ENV */
473 ViceLog(2, ("Checking for dead venii & clients\n"));
478 /* This LWP does fsync checks every 5 minutes: it should not be used for
479 * other 5 minute activities because it may be delayed by timeouts when
480 * it probes the workstations
486 #ifdef AFS_PTHREAD_ENV
487 struct timespec fsync_next;
489 ViceLog(1, ("Starting fsync check process\n"));
491 setThreadId("FsyncCheckLWP");
493 #ifdef AFS_PTHREAD_ENV
494 assert(pthread_cond_init(&fsync_cond, NULL) == 0);
495 assert(pthread_mutex_init(&fsync_glock_mutex, NULL) == 0);
500 #ifdef AFS_PTHREAD_ENV
501 /* rounding is fine */
502 fsync_next.tv_nsec = 0;
503 fsync_next.tv_sec = time(0) + fiveminutes;
506 pthread_cond_timedwait(&fsync_cond, &fsync_glock_mutex,
508 if (code != 0 && code != ETIMEDOUT)
509 ViceLog(0, ("pthread_cond_timedwait returned %d\n", code));
510 #else /* AFS_PTHREAD_ENV */
511 if ((code = LWP_WaitProcess(fsync_wait)) != LWP_SUCCESS)
512 ViceLog(0, ("LWP_WaitProcess returned %d\n", code));
513 #endif /* AFS_PTHREAD_ENV */
515 ViceLog(2, ("Checking for fsync events\n"));
517 code = BreakLaterCallBacks();
522 /*------------------------------------------------------------------------
523 * PRIVATE ClearXStatValues
526 * Initialize all of the values collected via the xstat
536 * Must be called during File Server initialization.
540 *------------------------------------------------------------------------*/
544 { /*ClearXStatValues */
546 struct fs_stats_opTimingData *opTimeP; /*Ptr to timing struct */
547 struct fs_stats_xferData *opXferP; /*Ptr to xfer struct */
548 int i; /*Loop counter */
551 * Zero all xstat-related structures.
553 memset((char *)(&afs_perfstats), 0, sizeof(struct afs_PerfStats));
554 #if FS_STATS_DETAILED
555 memset((char *)(&afs_FullPerfStats), 0,
556 sizeof(struct fs_stats_FullPerfStats));
559 * That's not enough. We have to set reasonable minima for
560 * time and xfer values in the detailed stats.
562 opTimeP = &(afs_FullPerfStats.det.rpcOpTimes[0]);
563 for (i = 0; i < FS_STATS_NUM_RPC_OPS; i++, opTimeP++)
564 opTimeP->minTime.tv_sec = 999999;
566 opXferP = &(afs_FullPerfStats.det.xferOpTimes[0]);
567 for (i = 0; i < FS_STATS_NUM_XFER_OPS; i++, opXferP++) {
568 opXferP->minTime.tv_sec = 999999;
569 opXferP->minBytes = 999999999;
573 * There's more. We have to set our unique system identifier, as
574 * declared in param.h. If such a thing is not defined, we bitch
575 * and declare ourselves to be an unknown system type.
578 afs_perfstats.sysname_ID = SYS_NAME_ID;
581 ViceLog(0, ("Sys name ID constant not defined in param.h!!\n"));
582 ViceLog(0, ("[Choosing ``undefined'' sys name ID.\n"));
584 afs_perfstats.sysname_ID = SYS_NAME_ID_UNDEFINED;
585 #endif /* SYS_NAME_ID */
588 } /*ClearXStatValues */
594 int dirbuff, dircall, dirio;
596 int workstations, activeworkstations, delworkstations;
600 TM_GetTimeOfDay(&tpl, 0);
603 ("Vice was last started at %s\n",
604 afs_ctime(&StartTime, tbuffer, sizeof(tbuffer))));
608 DStat(&dirbuff, &dircall, &dirio);
610 ("With %d directory buffers; %d reads resulted in %d read I/Os\n",
611 dirbuff, dircall, dirio));
612 rx_PrintStats(stderr);
614 PrintCallBackStats();
616 processSize = -1; /* TODO: */
618 processSize = (int)((long)sbrk(0) >> 10);
621 ("There are %d connections, process size %d\n",
622 CurrentConnections, processSize));
623 h_GetWorkStats(&workstations, &activeworkstations, &delworkstations,
624 tpl.tv_sec - 15 * 60);
626 ("There are %d workstations, %d are active (req in < 15 mins), %d marked \"down\"\n",
627 workstations, activeworkstations, delworkstations));
637 if (FS_registered > 0) {
639 * We have proper ip addresses; tell the vlserver what we got; the following
640 * routine will do the proper reporting for us
653 ShutDownAndCore(int dopanic)
655 time_t now = time(0);
659 ("Shutting down file server at %s",
660 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
662 ViceLog(0, ("ABNORMAL SHUTDOWN, see core file.\n"));
663 #ifndef AFS_QUIETFS_ENV
664 if (console != NULL) {
665 fprintf(console, "File server restart/shutdown received at %s\r",
666 afs_ctime(&now, tbuffer, sizeof(tbuffer)));
673 /* do not allows new reqests to be served from now on, all new requests
674 * are returned with an error code of RX_RESTARTING ( transient failure ) */
675 rx_SetRxTranquil(); /* dhruba */
679 rx_PrintStats(debugFile);
682 if (console != NULL) {
685 #ifndef AFS_QUIETFS_ENV
686 fprintf(console, "File server has terminated abnormally at %s\r",
687 afs_ctime(&now, tbuffer, sizeof(tbuffer)));
690 ("File server has terminated abnormally at %s\n",
691 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
693 #ifndef AFS_QUIETFS_ENV
694 fprintf(console, "File server has terminated normally at %s\r",
695 afs_ctime(&now, tbuffer, sizeof(tbuffer)));
698 ("File server has terminated normally at %s\n",
699 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
709 { /* backward compatibility */
710 ShutDownAndCore(DONTPANIC);
719 /* default supports help flag */
721 strcpy(buffer, "Usage: fileserver ");
722 strcat(buffer, "[-d <debug level>] ");
723 strcat(buffer, "[-p <number of processes>] ");
724 strcat(buffer, "[-spare <number of spare blocks>] ");
725 strcat(buffer, "[-pctspare <percentage spare>] ");
726 strcat(buffer, "[-b <buffers>] ");
727 strcat(buffer, "[-l <large vnodes>] ");
728 strcat(buffer, "[-s <small vnodes>] ");
729 strcat(buffer, "[-vc <volume cachesize>] ");
730 strcat(buffer, "[-w <call back wait interval>] ");
731 strcat(buffer, "[-cb <number of call backs>] ");
732 strcat(buffer, "[-banner (print banner every 10 minutes)] ");
733 strcat(buffer, "[-novbc (whole volume cbs disabled)] ");
734 strcat(buffer, "[-implicit <admin mode bits: rlidwka>] ");
735 strcat(buffer, "[-readonly (read-only file server)] ");
737 "[-hr <number of hours between refreshing the host cps>] ");
738 strcat(buffer, "[-busyat <redirect clients when queue > n>] ");
739 strcat(buffer, "[-nobusy <no VBUSY before a volume is attached>] ");
740 strcat(buffer, "[-rxpck <number of rx extra packets>] ");
741 strcat(buffer, "[-rxdbg (enable rx debugging)] ");
742 strcat(buffer, "[-rxdbge (enable rxevent debugging)] ");
744 strcat(buffer, "[-vattachpar <number of volume attach threads>] ");
747 strcat(buffer, "[-m <min percentage spare in partition>] ");
749 #if defined(AFS_SGI_ENV)
750 strcat(buffer, "[-lock (keep fileserver from swapping)] ");
752 strcat(buffer, "[-L (large server conf)] ");
753 strcat(buffer, "[-S (small server conf)] ");
754 strcat(buffer, "[-k <stack size>] ");
755 strcat(buffer, "[-realm <Kerberos realm name>] ");
756 strcat(buffer, "[-udpsize <size of socket buffer in bytes>] ");
757 strcat(buffer, "[-sendsize <size of send buffer in bytes>] ");
758 /* strcat(buffer, "[-enable_peer_stats] "); */
759 /* strcat(buffer, "[-enable_process_stats] "); */
760 strcat(buffer, "[-help]\n");
762 ViceLog(0, ("%s", buffer));
765 printf("%s", buffer);
772 ParseRights(char *arights)
778 if (!arights || !strcmp(arights, "")) {
779 printf("Missing list of mode bits on -implicit option\n");
782 if (!strcmp(arights, "none"))
784 else if (!strcmp(arights, "read"))
785 mode = PRSFS_READ | PRSFS_LOOKUP;
786 else if (!strcmp(arights, "write"))
788 PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
789 PRSFS_WRITE | PRSFS_LOCK;
790 else if (!strcmp(arights, "all"))
792 PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
793 PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER;
795 len = strlen(arights);
796 for (i = 0; i < len; i++) {
801 mode |= PRSFS_LOOKUP;
803 mode |= PRSFS_INSERT;
805 mode |= PRSFS_DELETE;
811 mode |= PRSFS_ADMINISTER;
829 printf("Illegal -implicit rights character '%c'.\n", tc);
838 * Limit MAX_FILESERVER_THREAD by the system limit on the number of
839 * pthreads (sysconf(_SC_THREAD_THREADS_MAX)), if applicable and
842 * AIX: sysconf() limit is real
843 * HP-UX: sysconf() limit is real
844 * IRIX: sysconf() limit is apparently NOT real -- too small
845 * DUX: sysconf() limit is apparently NOT real -- too big
846 * Linux: sysconf() limit is apparently NOT real -- too big
847 * Solaris: no sysconf() limit
850 max_fileserver_thread(void)
852 #if defined(AFS_PTHREAD_ENV)
853 #if defined(AFS_AIX_ENV) || defined(AFS_HPUX_ENV)
856 ans = sysconf(_SC_THREAD_THREADS_MAX);
857 if (0 < ans && ans < MAX_FILESERVER_THREAD)
860 #endif /* defined(AFS_PTHREAD_ENV) */
861 return MAX_FILESERVER_THREAD;
865 ParseArgs(int argc, char *argv[])
867 int SawL = 0, SawS = 0, SawVC = 0;
868 int Sawrxpck = 0, Sawsmall = 0, Sawlarge = 0, Sawcbs = 0, Sawlwps =
872 int bufSize = 0; /* temp variable to read in udp socket buf size */
874 for (i = 1; i < argc; i++) {
875 if (!strcmp(argv[i], "-d")) {
876 if ((i + 1) >= argc) {
877 fprintf(stderr, "missing argument for -d\n");
880 debuglevel = atoi(argv[++i]);
881 LogLevel = debuglevel;
882 } else if (!strcmp(argv[i], "-banner")) {
884 } else if (!strcmp(argv[i], "-implicit")) {
885 if ((i + 1) >= argc) {
886 fprintf(stderr, "missing argument for -implicit\n");
889 implicitAdminRights = ParseRights(argv[++i]);
890 if (implicitAdminRights < 0)
891 return implicitAdminRights;
892 } else if (!strcmp(argv[i], "-readonly")) {
894 } else if (!strcmp(argv[i], "-L")) {
896 } else if (!strcmp(argv[i], "-S")) {
898 } else if (!strcmp(argv[i], "-p")) {
900 max_fileserver_thread() - FILESERVER_HELPER_THREADS;
902 if ((i + 1) >= argc) {
903 fprintf(stderr, "missing argument for -p\n");
906 lwps = atoi(argv[++i]);
911 } else if (!strcmp(argv[i], "-b")) {
913 if ((i + 1) >= argc) {
914 fprintf(stderr, "missing argument for -b\n");
917 buffs = atoi(argv[++i]);
918 } else if (!strcmp(argv[i], "-l")) {
920 if ((i + 1) >= argc) {
921 fprintf(stderr, "missing argument for -l\n");
924 large = atoi(argv[++i]);
925 } else if (!strcmp(argv[i], "-vc")) {
927 if ((i + 1) >= argc) {
928 fprintf(stderr, "missing argument for -vc\n");
931 volcache = atoi(argv[++i]);
932 } else if (!strcmp(argv[i], "-novbc")) {
934 } else if (!strcmp(argv[i], "-rxpck")) {
936 if ((i + 1) >= argc) {
937 fprintf(stderr, "missing argument for -rxpck\n");
940 rxpackets = atoi(argv[++i]);
941 #ifdef AFS_PTHREAD_ENV
942 } else if (!strcmp(argv[i], "-vattachpar")) {
943 if ((i + 1) >= argc) {
944 fprintf(stderr, "missing argument for -vattachpar\n");
947 vol_attach_threads = atoi(argv[++i]);
948 #endif /* AFS_PTHREAD_ENV */
949 } else if (!strcmp(argv[i], "-s")) {
951 if ((i + 1) >= argc) {
952 fprintf(stderr, "missing argument for -s\n");
955 nSmallVns = atoi(argv[++i]);
956 } else if (!strcmp(argv[i], "-abortthreshold")) {
957 if ((i + 1) >= argc) {
958 fprintf(stderr, "missing argument for -abortthreshold\n");
961 abort_threshold = atoi(argv[++i]);
962 } else if (!strcmp(argv[i], "-k")) {
963 if ((i + 1) >= argc) {
964 fprintf(stderr, "missing argument for -k\n");
967 stack = atoi(argv[++i]);
969 #if defined(AFS_SGI_ENV)
970 else if (!strcmp(argv[i], "-lock")) {
974 else if (!strcmp(argv[i], "-spare")) {
975 if ((i + 1) >= argc) {
976 fprintf(stderr, "missing argument for -spare\n");
979 BlocksSpare = atoi(argv[++i]);
981 } else if (!strcmp(argv[i], "-pctspare")) {
982 if ((i + 1) >= argc) {
983 fprintf(stderr, "missing argument for -pctspare\n");
986 PctSpare = atoi(argv[++i]);
987 BlocksSpare = 0; /* has non-zero default */
989 } else if (!strcmp(argv[i], "-w")) {
990 if ((i + 1) >= argc) {
991 fprintf(stderr, "missing argument for -w\n");
994 fiveminutes = atoi(argv[++i]);
995 } else if (!strcmp(argv[i], "-hr")) {
997 if ((i + 1) >= argc) {
998 fprintf(stderr, "missing argument for -hr\n");
1001 hr = atoi(argv[++i]);
1002 if ((hr < 1) || (hr > 36)) {
1004 ("host acl refresh interval of %d hours is invalid; hours must be between 1 and 36\n\n",
1008 hostaclRefresh = hr * 60 * 60;
1009 } else if (!strcmp(argv[i], "-rxdbg"))
1011 else if (!strcmp(argv[i], "-rxdbge"))
1013 else if (!strcmp(argv[i], "-cb")) {
1015 if ((i + 1) >= argc) {
1016 fprintf(stderr, "missing argument for -cb\n");
1019 numberofcbs = atoi(argv[++i]);
1020 if ((numberofcbs < 10000) || (numberofcbs > 2147483647)) {
1022 ("number of cbs %d invalid; must be between 10000 and 2147483647\n",
1026 } else if (!strcmp(argv[i], "-busyat")) {
1028 if ((i + 1) >= argc) {
1029 fprintf(stderr, "missing argument for -busyat\n");
1032 busy_threshold = atoi(argv[++i]);
1033 if (busy_threshold < 10) {
1035 ("Busy threshold %d is too low, will compute default.\n",
1039 } else if (!strcmp(argv[i], "-nobusy"))
1041 #ifdef AFS_AIX32_ENV
1042 else if (!strcmp(argv[i], "-m")) {
1043 extern int aixlow_water;
1044 if ((i + 1) >= argc) {
1045 fprintf(stderr, "missing argument for -m\n");
1048 aixlow_water = atoi(argv[++i]);
1049 if ((aixlow_water < 0) || (aixlow_water > 30)) {
1050 printf("space reserved %d% invalid; must be between 0-30%\n",
1056 else if (!strcmp(argv[i], "-nojumbo")) {
1058 } else if (!strcmp(argv[i], "-realm")) {
1059 extern char local_realm[AFS_REALM_SZ];
1060 if ((i + 1) >= argc) {
1061 fprintf(stderr, "missing argument for -realm\n");
1064 if (strlen(argv[++i]) >= AFS_REALM_SZ) {
1066 ("-realm argument must contain fewer than %d characters.\n",
1070 strncpy(local_realm, argv[i], AFS_REALM_SZ);
1071 } else if (!strcmp(argv[i], "-udpsize")) {
1072 if ((i + 1) >= argc) {
1073 printf("You have to specify -udpsize <integer value>\n");
1076 bufSize = atoi(argv[++i]);
1077 if (bufSize < rx_GetMinUdpBufSize())
1079 ("Warning:udpsize %d is less than minimum %d; ignoring\n",
1080 bufSize, rx_GetMinUdpBufSize());
1082 udpBufSize = bufSize;
1083 } else if (!strcmp(argv[i], "-sendsize")) {
1084 if ((i + 1) >= argc) {
1085 printf("You have to specify -sendsize <integer value>\n");
1088 bufSize = atoi(argv[++i]);
1089 if (bufSize < 16384)
1091 ("Warning:sendsize %d is less than minimum %d; ignoring\n",
1094 sendBufSize = bufSize;
1095 } else if (!strcmp(argv[i], "-enable_peer_stats")) {
1096 rx_enablePeerRPCStats();
1097 } else if (!strcmp(argv[i], "-enable_process_stats")) {
1098 rx_enableProcessRPCStats();
1100 #ifndef AFS_NT40_ENV
1101 else if (strcmp(argv[i], "-syslog") == 0) {
1102 /* set syslog logging flag */
1103 serverLogSyslog = 1;
1104 } else if (strncmp(argv[i], "-syslog=", 8) == 0) {
1105 serverLogSyslog = 1;
1106 serverLogSyslogFacility = atoi(argv[i] + 8);
1114 printf("Only one of -L, or -S must be specified\n");
1125 numberofcbs = 20000;
1141 numberofcbs = 64000;
1150 busy_threshold = 3 * rxpackets / 2;
1160 NewParms(int initializing)
1162 static struct afs_stat sbuf;
1165 char *argv[MAXPARMS];
1168 if (!(afs_stat("/vice/file/parms", &sbuf))) {
1169 parms = (char *)malloc(sbuf.st_size);
1172 fd = afs_open("parms", O_RDONLY, 0666);
1174 ViceLog(0, ("Open for parms failed with errno = %d\n", errno));
1178 i = read(fd, parms, sbuf.st_size);
1180 if (i != sbuf.st_size) {
1182 ViceLog(0, ("Read on parms failed with errno = %d\n", errno));
1185 ("Read on parms failed; expected %d bytes but read %d\n",
1192 for (i = 0; i < MAXPARMS; argv[i++] = 0);
1194 for (argc = i = 0; i < sbuf.st_size; i++) {
1195 if ((*(parms + i) != ' ') && (*(parms + i) != '\n')) {
1196 if (argv[argc] == 0)
1197 argv[argc] = (parms + i);
1199 *(parms + i) = '\0';
1200 if (argv[argc] != 0) {
1201 if (++argc == MAXPARMS)
1204 while ((*(parms + i + 1) == ' ')
1205 || (*(parms + i + 1) == '\n'))
1209 if (ParseArgs(argc, argv) == 0) {
1210 ViceLog(0, ("Change parameters to:"));
1212 ViceLog(0, ("Invalid parameter in:"));
1214 for (i = 0; i < argc; i++) {
1215 ViceLog(0, (" %s", argv[i]));
1219 } else if (!initializing)
1221 ("Received request to change parms but no parms file exists\n"));
1226 /* Miscellaneous routines */
1230 ViceLog(0, ("%s\n", msg));
1242 * If this fails, it's because something major is wrong, and is not
1243 * likely to be time dependent.
1245 code = pr_Initialize(2, AFSDIR_SERVER_ETC_DIRPATH, 0);
1248 ("Couldn't initialize protection library; code=%d.\n", code));
1251 SystemId = SYSADMINID;
1252 SystemAnyUser = ANYUSERID;
1253 SystemAnyUserCPS.prlist_len = 0;
1254 SystemAnyUserCPS.prlist_val = NULL;
1255 AnonCPS.prlist_len = 0;
1256 AnonCPS.prlist_val = NULL;
1258 code = pr_GetCPS(SystemAnyUser, &SystemAnyUserCPS);
1261 ("Couldn't get CPS for AnyUser, will try again in 30 seconds; code=%d.\n",
1265 code = pr_GetCPS(ANONYMOUSID, &AnonCPS);
1268 ("Couldn't get Anonymous CPS, exiting; code=%d.\n",
1272 AnonymousID = ANONYMOUSID;
1275 #ifdef AFS_PTHREAD_ENV
1277 #else /* AFS_PTHREAD_ENV */
1279 #endif /* AFS_PTHREAD_ENV */
1283 struct rx_connection *serverconns[MAXSERVERS];
1284 struct ubik_client *cstruct;
1287 vl_Initialize(char *confDir)
1289 afs_int32 code, scIndex = 0, i;
1290 struct afsconf_dir *tdir;
1291 struct rx_securityClass *sc;
1292 struct afsconf_cell info;
1294 tdir = afsconf_Open(confDir);
1297 ("Could not open configuration directory (%s).\n", confDir));
1300 code = afsconf_ClientAuth(tdir, &sc, &scIndex);
1302 ViceLog(0, ("Could not get security object for localAuth\n"));
1305 code = afsconf_GetCellInfo(tdir, NULL, AFSCONF_VLDBSERVICE, &info);
1306 if (info.numServers > MAXSERVERS) {
1308 ("vl_Initialize: info.numServers=%d (> MAXSERVERS=%d)\n",
1309 info.numServers, MAXSERVERS));
1312 for (i = 0; i < info.numServers; i++)
1314 rx_NewConnection(info.hostAddr[i].sin_addr.s_addr,
1315 info.hostAddr[i].sin_port, USER_SERVICE_ID, sc,
1317 code = ubik_ClientInit(serverconns, &cstruct);
1319 ViceLog(0, ("vl_Initialize: ubik client init failed.\n"));
1325 #define SYSIDMAGIC 0x88aabbcc
1326 #define SYSIDVERSION 1
1331 afs_int32 fd, nentries, i;
1332 struct versionStamp vsn;
1333 struct afs_stat status;
1336 if ((afs_stat(AFSDIR_SERVER_SYSID_FILEPATH, &status))
1337 || (status.st_size <= 0)) {
1338 ViceLog(0, ("%s: doesn't exist\n", AFSDIR_SERVER_SYSID_FILEPATH));
1341 if (!(fd = afs_open(AFSDIR_SERVER_SYSID_FILEPATH, O_RDONLY, 0))) {
1343 ("%s: can't open (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1347 if ((i = read(fd, (char *)&vsn, sizeof(vsn))) != sizeof(vsn)) {
1349 ("%s: Read failed (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1353 if (vsn.magic != SYSIDMAGIC) {
1355 ("%s: wrong magic %x (we support %x)\n",
1356 AFSDIR_SERVER_SYSID_FILEPATH, vsn.magic, SYSIDMAGIC));
1359 if (vsn.version != SYSIDVERSION) {
1361 ("%s: wrong version %d (we support %d)\n",
1362 AFSDIR_SERVER_SYSID_FILEPATH, vsn.version, SYSIDVERSION));
1366 read(fd, (char *)&uuid,
1367 sizeof(struct afsUUID))) != sizeof(struct afsUUID)) {
1369 ("%s: read of uuid failed (%d)\n",
1370 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1373 afs_ntohuuid(&uuid);
1376 read(fd, (char *)&nentries,
1377 sizeof(afs_int32))) != sizeof(afs_int32)) {
1379 ("%s: Read of entries failed (%d)\n",
1380 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1383 if (nentries <= 0 || nentries > ADDRSPERSITE) {
1385 ("%s: invalid num of interfaces: %d\n",
1386 AFSDIR_SERVER_SYSID_FILEPATH, nentries));
1389 FS_HostAddr_cnt = nentries;
1390 for (i = 0; i < nentries; i++) {
1391 if (read(fd, (char *)&FS_HostAddrs[i], sizeof(afs_int32)) !=
1392 sizeof(afs_int32)) {
1394 ("%s: Read of addresses failed (%d)\n",
1395 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1396 FS_HostAddr_cnt = 0; /* reset it */
1408 struct versionStamp vsn;
1409 struct afs_stat status;
1412 if (!afs_stat(AFSDIR_SERVER_SYSID_FILEPATH, &status)) {
1414 * File exists; keep the old one around
1416 renamefile(AFSDIR_SERVER_SYSID_FILEPATH,
1417 AFSDIR_SERVER_OLDSYSID_FILEPATH);
1419 fd = afs_open(AFSDIR_SERVER_SYSID_FILEPATH, O_WRONLY | O_TRUNC | O_CREAT,
1423 ("%s: can't create (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1427 vsn.magic = SYSIDMAGIC;
1429 if ((i = write(fd, (char *)&vsn, sizeof(vsn))) != sizeof(vsn)) {
1431 ("%s: write failed (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1436 afs_htonuuid(&uuid);
1438 write(fd, (char *)&uuid,
1439 sizeof(struct afsUUID))) != sizeof(struct afsUUID)) {
1441 ("%s: write of uuid failed (%d)\n",
1442 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1446 write(fd, (char *)&FS_HostAddr_cnt,
1447 sizeof(afs_int32))) != sizeof(afs_int32)) {
1449 ("%s: write of # of entries failed (%d)\n",
1450 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1453 for (i = 0; i < FS_HostAddr_cnt; i++) {
1454 if (write(fd, (char *)&FS_HostAddrs[i], sizeof(afs_int32)) !=
1455 sizeof(afs_int32)) {
1457 ("%s: write of addresses failed (%d)\n",
1458 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1468 * This routine sets up the buffers for the VL_RegisterAddrs RPC. All addresses
1469 * in FS_HostAddrs[] are in NBO, while the RPC treats them as a "blob" of data
1470 * and so we need to convert each of them into HBO which is what the extra
1471 * array called FS_HostAddrs_HBO is used here.
1478 extern int VL_RegisterAddrs();
1479 afs_uint32 FS_HostAddrs_HBO[ADDRSPERSITE];
1482 for (i = 0; i < FS_HostAddr_cnt; i++)
1483 FS_HostAddrs_HBO[i] = ntohl(FS_HostAddrs[i]);
1484 addrs.bulkaddrs_len = FS_HostAddr_cnt;
1485 addrs.bulkaddrs_val = (afs_uint32 *) FS_HostAddrs_HBO;
1486 code = ubik_Call(VL_RegisterAddrs, cstruct, 0, &FS_HostUUID, 0, &addrs);
1488 if (code == VL_MULTIPADDR) {
1490 ("VL_RegisterAddrs rpc failed; The IP address exists on a different server; repair it\n"));
1492 ("VL_RegisterAddrs rpc failed; See VLLog for details\n"));
1494 } else if (code == RXGEN_OPCODE) {
1496 ("vlserver doesn't support VL_RegisterAddrs rpc; ignored\n"));
1497 FS_registered = 2; /* So we don't have to retry in the gc daemon */
1500 ("VL_RegisterAddrs rpc failed; will retry periodically (code=%d, err=%d)\n",
1504 FS_registered = 2; /* So we don't have to retry in the gc daemon */
1515 extern int rxi_numNetAddrs;
1516 extern afs_uint32 rxi_NetAddrs[];
1519 * If this fails, it's because something major is wrong, and is not
1520 * likely to be time dependent.
1522 code = vl_Initialize(AFSDIR_SERVER_ETC_DIRPATH);
1525 ("Couldn't initialize protection library; code=%d.\n", code));
1529 /* Read or create the sysid file and register the fileserver's
1530 * IP addresses with the vlserver.
1532 code = ReadSysIdFile();
1534 /* Need to create the file */
1535 ViceLog(0, ("Creating new SysID file\n"));
1536 if ((code = afs_uuid_create(&FS_HostUUID))) {
1537 ViceLog(0, ("Failed to create new uuid: %d\n", code));
1541 /* A good sysid file exists; inform the vlserver. If any conflicts,
1542 * we always use the latest interface available as the real truth.
1544 #ifndef AFS_NT40_ENV
1545 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH || AFSDIR_SERVER_NETINFO_FILEPATH) {
1547 * Find addresses we are supposed to register as per the netrestrict
1548 * and netinfo files (/usr/afs/local/NetInfo and
1549 * /usr/afs/local/NetRestict)
1552 afs_int32 code = parseNetFiles(FS_HostAddrs, NULL, NULL,
1553 ADDRSPERSITE, reason,
1554 AFSDIR_SERVER_NETINFO_FILEPATH,
1555 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
1557 ViceLog(0, ("Can't register any valid addresses: %s\n", reason));
1560 FS_HostAddr_cnt = (afs_uint32) code;
1564 FS_HostAddr_cnt = rx_getAllAddr(FS_HostAddrs, ADDRSPERSITE);
1568 code = Do_VLRegisterRPC();
1573 main(int argc, char *argv[])
1577 struct rx_securityClass *sc[4];
1578 struct rx_service *tservice;
1579 #ifdef AFS_PTHREAD_ENV
1580 pthread_t serverPid;
1581 pthread_attr_t tattr;
1582 #else /* AFS_PTHREAD_ENV */
1583 PROCESS parentPid, serverPid;
1584 #endif /* AFS_PTHREAD_ENV */
1586 int minVnodesRequired; /* min size of vnode cache */
1587 #ifndef AFS_NT40_ENV
1588 struct rlimit rlim; /* max number of open file descriptors */
1593 #ifdef AFS_AIX32_ENV
1594 struct sigaction nsa;
1596 sigemptyset(&nsa.sa_mask);
1597 nsa.sa_handler = SIG_DFL;
1598 nsa.sa_flags = SA_FULLDUMP;
1599 sigaction(SIGABRT, &nsa, NULL);
1600 sigaction(SIGSEGV, &nsa, NULL);
1603 /* Initialize dirpaths */
1604 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
1606 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
1608 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
1612 #ifndef AFS_QUIETFS_ENV
1613 console = afs_fopen("/dev/console", "w");
1616 if (ParseArgs(argc, argv)) {
1620 #ifdef AFS_PTHREAD_ENV
1621 assert(pthread_mutex_init(&fileproc_glock_mutex, NULL) == 0);
1622 #endif /* AFS_PTHREAD_ENV */
1624 #ifdef AFS_SGI_VNODE_GLUE
1625 if (afs_init_kernel_config(-1) < 0) {
1627 ("Can't determine NUMA configuration, not starting fileserver.\n");
1631 confDir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
1633 fprintf(stderr, "Unable to open config directory %s\n",
1634 AFSDIR_SERVER_ETC_DIRPATH);
1640 /* Open FileLog on stdout, stderr, fd 1 and fd2 (for perror), sigh. */
1641 #ifndef AFS_NT40_ENV
1642 serverLogSyslogTag = "fileserver";
1644 OpenLog(AFSDIR_SERVER_FILELOG_FILEPATH);
1647 if (SawSpare && SawPctSpare) {
1648 ViceLog(0, ("Both -spare and -pctspare specified, exiting.\n"));
1651 #ifdef AFS_SGI_XFS_IOPS_ENV
1652 ViceLog(0, ("XFS/EFS File server starting\n"));
1654 ViceLog(0, ("File server starting\n"));
1657 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
1658 /* initialize the pthread soft signal handler thread */
1662 /* install signal handlers for controlling the fileserver process */
1663 ResetCheckSignal(); /* set CheckSignal_Signal() sig handler */
1664 ResetCheckDescriptors(); /* set CheckDescriptors_Signal() sig handler */
1666 #if defined(AFS_SGI_ENV)
1667 /* give this guy a non-degrading priority so help busy servers */
1668 schedctl(NDPRI, 0, NDPNORMMAX);
1672 #ifndef AFS_NT40_ENV
1673 nice(-5); /* TODO: */
1676 assert(DInit(buffs) == 0);
1679 if (afs_winsockInit() < 0) {
1680 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
1681 ViceLog(0, ("File server failed to intialize winsock.\n"));
1687 /* if we support more than 16 threads, then we better have the ability
1688 ** to keep open a large number of files simultaneously
1690 #if defined(AFS_AIX_ENV) && !defined(AFS_AIX42_ENV)
1691 curLimit = OPEN_MAX; /* for pre AIX 4.2 systems */
1692 #elif defined(AFS_NT40_ENV)
1693 curLimit = NT_OPEN_MAX; /* open file descriptor limit on NT */
1696 curLimit = 0; /* the number of open file descriptors */
1697 code = getrlimit(RLIMIT_NOFILE, &rlim);
1699 curLimit = rlim.rlim_cur;
1700 rlim.rlim_cur = rlim.rlim_max;
1701 code = setrlimit(RLIMIT_NOFILE, &rlim);
1703 curLimit = rlim.rlim_max;
1706 ViceLog(0, ("Failed to increase open file limit, using default\n"));
1708 #endif /* defined(AFS_AIX_ENV) && !defined(AFS_AIX42_ENV) */
1710 curLimit -= 32; /* leave a slack of 32 file descriptors */
1711 if (lwps > curLimit) {
1715 lwps = 16; /* default to a maximum of 16 threads */
1717 ("The system supports a max of %d open files and we are starting %d threads\n",
1720 #ifndef AFS_PTHREAD_ENV
1721 assert(LWP_InitializeProcessSupport(LWP_MAX_PRIORITY - 2, &parentPid) ==
1723 #endif /* !AFS_PTHREAD_ENV */
1725 /* Initialize volume support */
1727 V_BreakVolumeCallbacks = BreakVolumeCallBacksLater;
1730 #if defined(AFS_PTHREAD_ENV)
1731 threadNameProgram = threadName;
1734 /* initialize libacl routines */
1735 acl_Initialize(ACL_VERSION);
1737 /* initialize RX support */
1738 #ifndef AFS_NT40_ENV
1739 rxi_syscallp = viced_syscall;
1741 rx_extraPackets = rxpackets;
1742 rx_extraQuota = 4; /* for outgoing prserver calls from R threads */
1743 rx_SetBusyThreshold(busy_threshold, VBUSY);
1744 rx_SetCallAbortThreshold(abort_threshold);
1745 rx_SetConnAbortThreshold(abort_threshold);
1746 stackSize = lwps * 4000;
1747 if (stackSize < 32000)
1749 else if (stackSize > 44000)
1751 #if defined(AFS_HPUX_ENV) || defined(AFS_SUN_ENV) || defined(AFS_SGI51_ENV)
1752 rx_SetStackSize(1, stackSize);
1755 rx_SetUdpBufSize(udpBufSize); /* set the UDP buffer size for receive */
1756 if (rx_Init((int)htons(7000)) < 0) {
1757 ViceLog(0, ("Cannot initialize RX\n"));
1760 if (!rxJumbograms) {
1761 /* Don't send and don't allow 3.4 clients to send jumbograms. */
1765 rx_SetRxDeadTime(30);
1766 sc[0] = rxnull_NewServerSecurityObject();
1767 sc[1] = 0; /* rxvab_NewServerSecurityObject(key1, 0) */
1768 sc[2] = rxkad_NewServerSecurityObject(rxkad_clear, NULL, get_key, NULL);
1769 sc[3] = rxkad_NewServerSecurityObject(rxkad_crypt, NULL, get_key, NULL);
1770 tservice = rx_NewService( /* port */ 0, /* service id */ 1, /*service name */
1772 /* security classes */ sc,
1773 /* numb sec classes */
1774 4, RXAFS_ExecuteRequest);
1777 ("Failed to initialize RX, probably two servers running.\n"));
1780 rx_SetDestroyConnProc(tservice, (void (*)())h_FreeConnection);
1781 rx_SetMinProcs(tservice, 3);
1782 rx_SetMaxProcs(tservice, lwps);
1783 rx_SetCheckReach(tservice, 1);
1786 rx_NewService(0, RX_STATS_SERVICE_ID, "rpcstats", sc, 4,
1787 RXSTATS_ExecuteRequest);
1789 ViceLog(0, ("Failed to initialize rpc stat service.\n"));
1792 rx_SetMinProcs(tservice, 2);
1793 rx_SetMaxProcs(tservice, 4);
1796 * Enable RX hot threads, which allows the listener thread to trade
1797 * places with an idle thread and moves the context switch from listener
1798 * to worker out of the critical path.
1800 rx_EnableHotThread();
1802 /* Some rx debugging */
1803 if (rxlog || eventlog) {
1804 debugFile = afs_fopen("rx_dbg", "w");
1806 rx_debugFile = debugFile;
1808 rxevent_debugFile = debugFile;
1811 init_sys_error_to_et(); /* Set up error table translation */
1812 h_InitHostPackage(); /* set up local cellname and realmname */
1813 InitCallBack(numberofcbs);
1818 ViceLog(0, ("Fatal error in library initialization, exiting!!\n"));
1824 ViceLog(0, ("Fatal error in protection initialization, exiting!!\n"));
1828 /* allow super users to manage RX statistics */
1829 rx_SetRxStatUserOk(fs_rxstat_userok);
1831 rx_StartServer(0); /* now start handling requests */
1833 /* we ensure that there is enough space in the vnode buffer to satisfy
1834 ** requests from all concurrent threads.
1835 ** the maximum number of vnodes used by a single thread at any one time
1836 ** is three ( "link" uses three vnodes simultaneously, one vLarge and
1837 ** two vSmall for linking files and two vLarge and one vSmall for linking
1840 minVnodesRequired = 2 * lwps + 1;
1841 if (minVnodesRequired > nSmallVns) {
1842 nSmallVns = minVnodesRequired;
1844 ("Overriding -s command line parameter with %d\n",
1847 if (minVnodesRequired > large) {
1848 large = minVnodesRequired;
1849 ViceLog(0, ("Overriding -l command line parameter with %d\n", large));
1852 /* We now do this after getting the listener up and running, so that client
1853 * connections don't timeout (maybe) if a file server is restarted, since it
1854 * will be available "real soon now". Worry about whether we can satisfy the
1855 * calls in the volume package itself.
1857 if (VInitVolumePackage(fileServer, large, nSmallVns, 0, volcache)) {
1859 ("Shutting down: errors encountered initializing volume package\n"));
1865 * We are done calling fopen/fdopen. It is safe to use a large
1866 * of the file descriptor cache.
1870 #ifdef AFS_PTHREAD_ENV
1871 ViceLog(5, ("Starting pthreads\n"));
1872 assert(pthread_attr_init(&tattr) == 0);
1873 assert(pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED) == 0);
1875 assert(pthread_create
1876 (&serverPid, &tattr, (void *)FiveMinuteCheckLWP,
1877 &fiveminutes) == 0);
1878 assert(pthread_create
1879 (&serverPid, &tattr, (void *)HostCheckLWP, &fiveminutes) == 0);
1880 assert(pthread_create
1881 (&serverPid, &tattr, (void *)FsyncCheckLWP, &fiveminutes) == 0);
1882 #else /* AFS_PTHREAD_ENV */
1883 ViceLog(5, ("Starting LWP\n"));
1884 assert(LWP_CreateProcess
1885 (FiveMinuteCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
1886 (void *)&fiveminutes, "FiveMinuteChecks",
1887 &serverPid) == LWP_SUCCESS);
1889 assert(LWP_CreateProcess
1890 (HostCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
1891 (void *)&fiveminutes, "HostCheck", &serverPid) == LWP_SUCCESS);
1892 assert(LWP_CreateProcess
1893 (FsyncCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
1894 (void *)&fiveminutes, "FsyncCheck", &serverPid) == LWP_SUCCESS);
1895 #endif /* AFS_PTHREAD_ENV */
1897 TM_GetTimeOfDay(&tp, 0);
1899 #ifndef AFS_QUIETFS_ENV
1900 if (console != NULL) {
1901 time_t t = tp.tv_sec;
1902 fprintf(console, "File server has started at %s\r",
1903 afs_ctime(&t, tbuffer, sizeof(tbuffer)));
1908 * Figure out the FileServer's name and primary address.
1910 ViceLog(0, ("Getting FileServer name...\n"));
1911 code = gethostname(FS_HostName, 64);
1913 ViceLog(0, ("gethostname() failed\n"));
1915 ViceLog(0, ("FileServer host name is '%s'\n", FS_HostName));
1917 ViceLog(0, ("Getting FileServer address...\n"));
1918 he = gethostbyname(FS_HostName);
1920 ViceLog(0, ("Can't find address for FileServer '%s'\n", FS_HostName));
1923 memcpy(&FS_HostAddr_NBO, he->h_addr, 4);
1924 (void)afs_inet_ntoa_r(FS_HostAddr_NBO, hoststr);
1925 FS_HostAddr_HBO = ntohl(FS_HostAddr_NBO);
1927 ("FileServer %s has address %s (0x%x or 0x%x in host byte order)\n",
1928 FS_HostName, hoststr, FS_HostAddr_NBO, FS_HostAddr_HBO));
1931 /* Install handler to catch the shutdown signal;
1932 * bosserver assumes SIGQUIT shutdown
1934 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
1935 softsig_signal(SIGQUIT, ShutDown_Signal);
1937 (void)signal(SIGQUIT, ShutDown_Signal);
1942 ("File Server started %s",
1943 afs_ctime(&t, tbuffer, sizeof(tbuffer))));
1944 #if FS_STATS_DETAILED
1945 afs_FullPerfStats.det.epoch.tv_sec = StartTime = tp.tv_sec;
1947 #ifdef AFS_PTHREAD_ENV
1949 sleep(1000); /* long time */
1951 #else /* AFS_PTHREAD_ENV */
1952 assert(LWP_WaitProcess(&parentPid) == LWP_SUCCESS);
1953 #endif /* AFS_PTHREAD_ENV */