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, "[-m <min percentage spare in partition>] ");
746 #if defined(AFS_SGI_ENV)
747 strcat(buffer, "[-lock (keep fileserver from swapping)] ");
749 strcat(buffer, "[-L (large server conf)] ");
750 strcat(buffer, "[-S (small server conf)] ");
751 strcat(buffer, "[-k <stack size>] ");
752 strcat(buffer, "[-realm <Kerberos realm name>] ");
753 strcat(buffer, "[-udpsize <size of socket buffer in bytes>] ");
754 strcat(buffer, "[-sendsize <size of send buffer in bytes>] ");
755 /* strcat(buffer, "[-enable_peer_stats] "); */
756 /* strcat(buffer, "[-enable_process_stats] "); */
757 strcat(buffer, "[-help]\n");
759 ViceLog(0, ("%s", buffer));
762 printf("%s", buffer);
769 ParseRights(char *arights)
775 if (!arights || !strcmp(arights, "")) {
776 printf("Missing list of mode bits on -implicit option\n");
779 if (!strcmp(arights, "none"))
781 else if (!strcmp(arights, "read"))
782 mode = PRSFS_READ | PRSFS_LOOKUP;
783 else if (!strcmp(arights, "write"))
785 PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
786 PRSFS_WRITE | PRSFS_LOCK;
787 else if (!strcmp(arights, "all"))
789 PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
790 PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER;
792 len = strlen(arights);
793 for (i = 0; i < len; i++) {
798 mode |= PRSFS_LOOKUP;
800 mode |= PRSFS_INSERT;
802 mode |= PRSFS_DELETE;
808 mode |= PRSFS_ADMINISTER;
826 printf("Illegal -implicit rights character '%c'.\n", tc);
835 * Limit MAX_FILESERVER_THREAD by the system limit on the number of
836 * pthreads (sysconf(_SC_THREAD_THREADS_MAX)), if applicable and
839 * AIX: sysconf() limit is real
840 * HP-UX: sysconf() limit is real
841 * IRIX: sysconf() limit is apparently NOT real -- too small
842 * DUX: sysconf() limit is apparently NOT real -- too big
843 * Linux: sysconf() limit is apparently NOT real -- too big
844 * Solaris: no sysconf() limit
847 max_fileserver_thread(void)
849 #if defined(AFS_PTHREAD_ENV)
850 #if defined(AFS_AIX_ENV) || defined(AFS_HPUX_ENV)
853 ans = sysconf(_SC_THREAD_THREADS_MAX);
854 if (0 < ans && ans < MAX_FILESERVER_THREAD)
857 #endif /* defined(AFS_PTHREAD_ENV) */
858 return MAX_FILESERVER_THREAD;
862 ParseArgs(int argc, char *argv[])
864 int SawL = 0, SawS = 0, SawVC = 0;
865 int Sawrxpck = 0, Sawsmall = 0, Sawlarge = 0, Sawcbs = 0, Sawlwps =
869 int bufSize = 0; /* temp variable to read in udp socket buf size */
871 for (i = 1; i < argc; i++) {
872 if (!strcmp(argv[i], "-d")) {
873 if ((i + 1) >= argc) {
874 fprintf(stderr, "missing argument for -d\n");
877 debuglevel = atoi(argv[++i]);
878 LogLevel = debuglevel;
879 } else if (!strcmp(argv[i], "-banner")) {
881 } else if (!strcmp(argv[i], "-implicit")) {
882 if ((i + 1) >= argc) {
883 fprintf(stderr, "missing argument for -implicit\n");
886 implicitAdminRights = ParseRights(argv[++i]);
887 if (implicitAdminRights < 0)
888 return implicitAdminRights;
889 } else if (!strcmp(argv[i], "-readonly")) {
891 } else if (!strcmp(argv[i], "-L")) {
893 } else if (!strcmp(argv[i], "-S")) {
895 } else if (!strcmp(argv[i], "-p")) {
897 max_fileserver_thread() - FILESERVER_HELPER_THREADS;
899 if ((i + 1) >= argc) {
900 fprintf(stderr, "missing argument for -p\n");
903 lwps = atoi(argv[++i]);
908 } else if (!strcmp(argv[i], "-b")) {
910 if ((i + 1) >= argc) {
911 fprintf(stderr, "missing argument for -b\n");
914 buffs = atoi(argv[++i]);
915 } else if (!strcmp(argv[i], "-l")) {
917 if ((i + 1) >= argc) {
918 fprintf(stderr, "missing argument for -l\n");
921 large = atoi(argv[++i]);
922 } else if (!strcmp(argv[i], "-vc")) {
924 if ((i + 1) >= argc) {
925 fprintf(stderr, "missing argument for -vc\n");
928 volcache = atoi(argv[++i]);
929 } else if (!strcmp(argv[i], "-novbc")) {
931 } else if (!strcmp(argv[i], "-rxpck")) {
933 if ((i + 1) >= argc) {
934 fprintf(stderr, "missing argument for -rxpck\n");
937 rxpackets = atoi(argv[++i]);
938 } else if (!strcmp(argv[i], "-s")) {
940 if ((i + 1) >= argc) {
941 fprintf(stderr, "missing argument for -s\n");
944 nSmallVns = atoi(argv[++i]);
945 } else if (!strcmp(argv[i], "-abortthreshold")) {
946 if ((i + 1) >= argc) {
947 fprintf(stderr, "missing argument for -abortthreshold\n");
950 abort_threshold = atoi(argv[++i]);
951 } else if (!strcmp(argv[i], "-k")) {
952 if ((i + 1) >= argc) {
953 fprintf(stderr, "missing argument for -k\n");
956 stack = atoi(argv[++i]);
958 #if defined(AFS_SGI_ENV)
959 else if (!strcmp(argv[i], "-lock")) {
963 else if (!strcmp(argv[i], "-spare")) {
964 if ((i + 1) >= argc) {
965 fprintf(stderr, "missing argument for -spare\n");
968 BlocksSpare = atoi(argv[++i]);
970 } else if (!strcmp(argv[i], "-pctspare")) {
971 if ((i + 1) >= argc) {
972 fprintf(stderr, "missing argument for -pctspare\n");
975 PctSpare = atoi(argv[++i]);
976 BlocksSpare = 0; /* has non-zero default */
978 } else if (!strcmp(argv[i], "-w")) {
979 if ((i + 1) >= argc) {
980 fprintf(stderr, "missing argument for -w\n");
983 fiveminutes = atoi(argv[++i]);
984 } else if (!strcmp(argv[i], "-hr")) {
986 if ((i + 1) >= argc) {
987 fprintf(stderr, "missing argument for -hr\n");
990 hr = atoi(argv[++i]);
991 if ((hr < 1) || (hr > 36)) {
993 ("host acl refresh interval of %d hours is invalid; hours must be between 1 and 36\n\n",
997 hostaclRefresh = hr * 60 * 60;
998 } else if (!strcmp(argv[i], "-rxdbg"))
1000 else if (!strcmp(argv[i], "-rxdbge"))
1002 else if (!strcmp(argv[i], "-cb")) {
1004 if ((i + 1) >= argc) {
1005 fprintf(stderr, "missing argument for -cb\n");
1008 numberofcbs = atoi(argv[++i]);
1009 if ((numberofcbs < 10000) || (numberofcbs > 2147483647)) {
1011 ("number of cbs %d invalid; must be between 10000 and 2147483647\n",
1015 } else if (!strcmp(argv[i], "-busyat")) {
1017 if ((i + 1) >= argc) {
1018 fprintf(stderr, "missing argument for -busyat\n");
1021 busy_threshold = atoi(argv[++i]);
1022 if (busy_threshold < 10) {
1024 ("Busy threshold %d is too low, will compute default.\n",
1028 } else if (!strcmp(argv[i], "-nobusy"))
1030 #ifdef AFS_AIX32_ENV
1031 else if (!strcmp(argv[i], "-m")) {
1032 extern int aixlow_water;
1033 if ((i + 1) >= argc) {
1034 fprintf(stderr, "missing argument for -m\n");
1037 aixlow_water = atoi(argv[++i]);
1038 if ((aixlow_water < 0) || (aixlow_water > 30)) {
1039 printf("space reserved %d% invalid; must be between 0-30%\n",
1045 else if (!strcmp(argv[i], "-nojumbo")) {
1047 } else if (!strcmp(argv[i], "-realm")) {
1048 extern char local_realm[AFS_REALM_SZ];
1049 if ((i + 1) >= argc) {
1050 fprintf(stderr, "missing argument for -realm\n");
1053 if (strlen(argv[++i]) >= AFS_REALM_SZ) {
1055 ("-realm argument must contain fewer than %d characters.\n",
1059 strncpy(local_realm, argv[i], AFS_REALM_SZ);
1060 } else if (!strcmp(argv[i], "-udpsize")) {
1061 if ((i + 1) >= argc) {
1062 printf("You have to specify -udpsize <integer value>\n");
1065 bufSize = atoi(argv[++i]);
1066 if (bufSize < rx_GetMinUdpBufSize())
1068 ("Warning:udpsize %d is less than minimum %d; ignoring\n",
1069 bufSize, rx_GetMinUdpBufSize());
1071 udpBufSize = bufSize;
1072 } else if (!strcmp(argv[i], "-sendsize")) {
1073 if ((i + 1) >= argc) {
1074 printf("You have to specify -sendsize <integer value>\n");
1077 bufSize = atoi(argv[++i]);
1078 if (bufSize < 16384)
1080 ("Warning:sendsize %d is less than minimum %d; ignoring\n",
1083 sendBufSize = bufSize;
1084 } else if (!strcmp(argv[i], "-enable_peer_stats")) {
1085 rx_enablePeerRPCStats();
1086 } else if (!strcmp(argv[i], "-enable_process_stats")) {
1087 rx_enableProcessRPCStats();
1089 #ifndef AFS_NT40_ENV
1090 else if (strcmp(argv[i], "-syslog") == 0) {
1091 /* set syslog logging flag */
1092 serverLogSyslog = 1;
1093 } else if (strncmp(argv[i], "-syslog=", 8) == 0) {
1094 serverLogSyslog = 1;
1095 serverLogSyslogFacility = atoi(argv[i] + 8);
1103 printf("Only one of -L, or -S must be specified\n");
1114 numberofcbs = 20000;
1130 numberofcbs = 64000;
1139 busy_threshold = 3 * rxpackets / 2;
1149 NewParms(int initializing)
1151 static struct afs_stat sbuf;
1154 char *argv[MAXPARMS];
1157 if (!(afs_stat("/vice/file/parms", &sbuf))) {
1158 parms = (char *)malloc(sbuf.st_size);
1161 fd = afs_open("parms", O_RDONLY, 0666);
1163 ViceLog(0, ("Open for parms failed with errno = %d\n", errno));
1167 i = read(fd, parms, sbuf.st_size);
1169 if (i != sbuf.st_size) {
1171 ViceLog(0, ("Read on parms failed with errno = %d\n", errno));
1174 ("Read on parms failed; expected %d bytes but read %d\n",
1181 for (i = 0; i < MAXPARMS; argv[i++] = 0);
1183 for (argc = i = 0; i < sbuf.st_size; i++) {
1184 if ((*(parms + i) != ' ') && (*(parms + i) != '\n')) {
1185 if (argv[argc] == 0)
1186 argv[argc] = (parms + i);
1188 *(parms + i) = '\0';
1189 if (argv[argc] != 0) {
1190 if (++argc == MAXPARMS)
1193 while ((*(parms + i + 1) == ' ')
1194 || (*(parms + i + 1) == '\n'))
1198 if (ParseArgs(argc, argv) == 0) {
1199 ViceLog(0, ("Change parameters to:"));
1201 ViceLog(0, ("Invalid parameter in:"));
1203 for (i = 0; i < argc; i++) {
1204 ViceLog(0, (" %s", argv[i]));
1208 } else if (!initializing)
1210 ("Received request to change parms but no parms file exists\n"));
1215 /* Miscellaneous routines */
1219 ViceLog(0, ("%s\n", msg));
1231 * If this fails, it's because something major is wrong, and is not
1232 * likely to be time dependent.
1234 code = pr_Initialize(2, AFSDIR_SERVER_ETC_DIRPATH, 0);
1237 ("Couldn't initialize protection library; code=%d.\n", code));
1240 SystemId = SYSADMINID;
1241 SystemAnyUser = ANYUSERID;
1242 SystemAnyUserCPS.prlist_len = 0;
1243 SystemAnyUserCPS.prlist_val = NULL;
1244 AnonCPS.prlist_len = 0;
1245 AnonCPS.prlist_val = NULL;
1247 code = pr_GetCPS(SystemAnyUser, &SystemAnyUserCPS);
1250 ("Couldn't get CPS for AnyUser, will try again in 30 seconds; code=%d.\n",
1254 code = pr_GetCPS(ANONYMOUSID, &AnonCPS);
1257 ("Couldn't get Anonymous CPS, exiting; code=%d.\n",
1261 AnonymousID = ANONYMOUSID;
1264 #ifdef AFS_PTHREAD_ENV
1266 #else /* AFS_PTHREAD_ENV */
1268 #endif /* AFS_PTHREAD_ENV */
1272 struct rx_connection *serverconns[MAXSERVERS];
1273 struct ubik_client *cstruct;
1276 vl_Initialize(char *confDir)
1278 afs_int32 code, scIndex = 0, i;
1279 struct afsconf_dir *tdir;
1280 struct rx_securityClass *sc;
1281 struct afsconf_cell info;
1283 tdir = afsconf_Open(confDir);
1286 ("Could not open configuration directory (%s).\n", confDir));
1289 code = afsconf_ClientAuth(tdir, &sc, &scIndex);
1291 ViceLog(0, ("Could not get security object for localAuth\n"));
1294 code = afsconf_GetCellInfo(tdir, NULL, AFSCONF_VLDBSERVICE, &info);
1295 if (info.numServers > MAXSERVERS) {
1297 ("vl_Initialize: info.numServers=%d (> MAXSERVERS=%d)\n",
1298 info.numServers, MAXSERVERS));
1301 for (i = 0; i < info.numServers; i++)
1303 rx_NewConnection(info.hostAddr[i].sin_addr.s_addr,
1304 info.hostAddr[i].sin_port, USER_SERVICE_ID, sc,
1306 code = ubik_ClientInit(serverconns, &cstruct);
1308 ViceLog(0, ("vl_Initialize: ubik client init failed.\n"));
1314 #define SYSIDMAGIC 0x88aabbcc
1315 #define SYSIDVERSION 1
1320 afs_int32 fd, nentries, i;
1321 struct versionStamp vsn;
1322 struct afs_stat status;
1325 if ((afs_stat(AFSDIR_SERVER_SYSID_FILEPATH, &status))
1326 || (status.st_size <= 0)) {
1327 ViceLog(0, ("%s: doesn't exist\n", AFSDIR_SERVER_SYSID_FILEPATH));
1330 if (!(fd = afs_open(AFSDIR_SERVER_SYSID_FILEPATH, O_RDONLY, 0))) {
1332 ("%s: can't open (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1336 if ((i = read(fd, (char *)&vsn, sizeof(vsn))) != sizeof(vsn)) {
1338 ("%s: Read failed (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1342 if (vsn.magic != SYSIDMAGIC) {
1344 ("%s: wrong magic %x (we support %x)\n",
1345 AFSDIR_SERVER_SYSID_FILEPATH, vsn.magic, SYSIDMAGIC));
1348 if (vsn.version != SYSIDVERSION) {
1350 ("%s: wrong version %d (we support %d)\n",
1351 AFSDIR_SERVER_SYSID_FILEPATH, vsn.version, SYSIDVERSION));
1355 read(fd, (char *)&uuid,
1356 sizeof(struct afsUUID))) != sizeof(struct afsUUID)) {
1358 ("%s: read of uuid failed (%d)\n",
1359 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1362 afs_ntohuuid(&uuid);
1365 read(fd, (char *)&nentries,
1366 sizeof(afs_int32))) != sizeof(afs_int32)) {
1368 ("%s: Read of entries failed (%d)\n",
1369 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1372 if (nentries <= 0 || nentries > ADDRSPERSITE) {
1374 ("%s: invalid num of interfaces: %d\n",
1375 AFSDIR_SERVER_SYSID_FILEPATH, nentries));
1378 FS_HostAddr_cnt = nentries;
1379 for (i = 0; i < nentries; i++) {
1380 if (read(fd, (char *)&FS_HostAddrs[i], sizeof(afs_int32)) !=
1381 sizeof(afs_int32)) {
1383 ("%s: Read of addresses failed (%d)\n",
1384 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1385 FS_HostAddr_cnt = 0; /* reset it */
1397 struct versionStamp vsn;
1398 struct afs_stat status;
1401 if (!afs_stat(AFSDIR_SERVER_SYSID_FILEPATH, &status)) {
1403 * File exists; keep the old one around
1405 renamefile(AFSDIR_SERVER_SYSID_FILEPATH,
1406 AFSDIR_SERVER_OLDSYSID_FILEPATH);
1408 fd = afs_open(AFSDIR_SERVER_SYSID_FILEPATH, O_WRONLY | O_TRUNC | O_CREAT,
1412 ("%s: can't create (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1416 vsn.magic = SYSIDMAGIC;
1418 if ((i = write(fd, (char *)&vsn, sizeof(vsn))) != sizeof(vsn)) {
1420 ("%s: write failed (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1425 afs_htonuuid(&uuid);
1427 write(fd, (char *)&uuid,
1428 sizeof(struct afsUUID))) != sizeof(struct afsUUID)) {
1430 ("%s: write of uuid failed (%d)\n",
1431 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1435 write(fd, (char *)&FS_HostAddr_cnt,
1436 sizeof(afs_int32))) != sizeof(afs_int32)) {
1438 ("%s: write of # of entries failed (%d)\n",
1439 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1442 for (i = 0; i < FS_HostAddr_cnt; i++) {
1443 if (write(fd, (char *)&FS_HostAddrs[i], sizeof(afs_int32)) !=
1444 sizeof(afs_int32)) {
1446 ("%s: write of addresses failed (%d)\n",
1447 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1457 * This routine sets up the buffers for the VL_RegisterAddrs RPC. All addresses
1458 * in FS_HostAddrs[] are in NBO, while the RPC treats them as a "blob" of data
1459 * and so we need to convert each of them into HBO which is what the extra
1460 * array called FS_HostAddrs_HBO is used here.
1467 extern int VL_RegisterAddrs();
1468 afs_uint32 FS_HostAddrs_HBO[ADDRSPERSITE];
1471 for (i = 0; i < FS_HostAddr_cnt; i++)
1472 FS_HostAddrs_HBO[i] = ntohl(FS_HostAddrs[i]);
1473 addrs.bulkaddrs_len = FS_HostAddr_cnt;
1474 addrs.bulkaddrs_val = (afs_uint32 *) FS_HostAddrs_HBO;
1475 code = ubik_Call(VL_RegisterAddrs, cstruct, 0, &FS_HostUUID, 0, &addrs);
1477 if (code == VL_MULTIPADDR) {
1479 ("VL_RegisterAddrs rpc failed; The ethernet address exist on a different server; repair it\n"));
1481 ("VL_RegisterAddrs rpc failed; See VLLog for details\n"));
1483 } else if (code == RXGEN_OPCODE) {
1485 ("vlserver doesn't support VL_RegisterAddrs rpc; ignored\n"));
1486 FS_registered = 2; /* So we don't have to retry in the gc daemon */
1489 ("VL_RegisterAddrs rpc failed; will retry periodically (code=%d, err=%d)\n",
1493 FS_registered = 2; /* So we don't have to retry in the gc daemon */
1504 extern int rxi_numNetAddrs;
1505 extern afs_uint32 rxi_NetAddrs[];
1508 * If this fails, it's because something major is wrong, and is not
1509 * likely to be time dependent.
1511 code = vl_Initialize(AFSDIR_SERVER_ETC_DIRPATH);
1514 ("Couldn't initialize protection library; code=%d.\n", code));
1518 /* Read or create the sysid file and register the fileserver's
1519 * IP addresses with the vlserver.
1521 code = ReadSysIdFile();
1523 /* Need to create the file */
1524 ViceLog(0, ("Creating new SysID file\n"));
1525 if ((code = afs_uuid_create(&FS_HostUUID))) {
1526 ViceLog(0, ("Failed to create new uuid: %d\n", code));
1530 /* A good sysid file exists; inform the vlserver. If any conflicts,
1531 * we always use the latest interface available as the real truth.
1533 #ifndef AFS_NT40_ENV
1534 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH || AFSDIR_SERVER_NETINFO_FILEPATH) {
1536 * Find addresses we are supposed to register as per the netrestrict
1537 * and netinfo files (/usr/afs/local/NetInfo and
1538 * /usr/afs/local/NetRestict)
1541 afs_int32 code = parseNetFiles(FS_HostAddrs, NULL, NULL,
1542 ADDRSPERSITE, reason,
1543 AFSDIR_SERVER_NETINFO_FILEPATH,
1544 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
1546 ViceLog(0, ("Can't register any valid addresses: %s\n", reason));
1549 FS_HostAddr_cnt = (afs_uint32) code;
1553 FS_HostAddr_cnt = rx_getAllAddr(FS_HostAddrs, ADDRSPERSITE);
1557 code = Do_VLRegisterRPC();
1562 main(int argc, char *argv[])
1566 struct rx_securityClass *sc[4];
1567 struct rx_service *tservice;
1568 #ifdef AFS_PTHREAD_ENV
1569 pthread_t serverPid;
1570 pthread_attr_t tattr;
1571 #else /* AFS_PTHREAD_ENV */
1572 PROCESS parentPid, serverPid;
1573 #endif /* AFS_PTHREAD_ENV */
1575 int minVnodesRequired; /* min size of vnode cache */
1576 #ifndef AFS_NT40_ENV
1577 struct rlimit rlim; /* max number of open file descriptors */
1582 #ifdef AFS_AIX32_ENV
1583 struct sigaction nsa;
1585 sigemptyset(&nsa.sa_mask);
1586 nsa.sa_handler = SIG_DFL;
1587 nsa.sa_flags = SA_FULLDUMP;
1588 sigaction(SIGABRT, &nsa, NULL);
1589 sigaction(SIGSEGV, &nsa, NULL);
1592 /* Initialize dirpaths */
1593 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
1595 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
1597 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
1601 #ifndef AFS_QUIETFS_ENV
1602 console = afs_fopen("/dev/console", "w");
1605 if (ParseArgs(argc, argv)) {
1609 #ifdef AFS_PTHREAD_ENV
1610 assert(pthread_mutex_init(&fileproc_glock_mutex, NULL) == 0);
1611 #endif /* AFS_PTHREAD_ENV */
1613 #ifdef AFS_SGI_VNODE_GLUE
1614 if (afs_init_kernel_config(-1) < 0) {
1616 ("Can't determine NUMA configuration, not starting fileserver.\n");
1620 confDir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
1622 fprintf(stderr, "Unable to open config directory %s\n",
1623 AFSDIR_SERVER_ETC_DIRPATH);
1629 /* Open FileLog on stdout, stderr, fd 1 and fd2 (for perror), sigh. */
1630 #ifndef AFS_NT40_ENV
1631 serverLogSyslogTag = "fileserver";
1633 OpenLog(AFSDIR_SERVER_FILELOG_FILEPATH);
1636 if (SawSpare && SawPctSpare) {
1637 ViceLog(0, ("Both -spare and -pctspare specified, exiting.\n"));
1640 #ifdef AFS_SGI_XFS_IOPS_ENV
1641 ViceLog(0, ("XFS/EFS File server starting\n"));
1643 ViceLog(0, ("File server starting\n"));
1646 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
1647 /* initialize the pthread soft signal handler thread */
1651 /* install signal handlers for controlling the fileserver process */
1652 ResetCheckSignal(); /* set CheckSignal_Signal() sig handler */
1653 ResetCheckDescriptors(); /* set CheckDescriptors_Signal() sig handler */
1655 #if defined(AFS_SGI_ENV)
1656 /* give this guy a non-degrading priority so help busy servers */
1657 schedctl(NDPRI, 0, NDPNORMMAX);
1661 #ifndef AFS_NT40_ENV
1662 nice(-5); /* TODO: */
1665 assert(DInit(buffs) == 0);
1668 if (afs_winsockInit() < 0) {
1669 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
1670 ViceLog(0, ("File server failed to intialize winsock.\n"));
1676 /* if we support more than 16 threads, then we better have the ability
1677 ** to keep open a large number of files simultaneously
1679 #if defined(AFS_AIX_ENV) && !defined(AFS_AIX42_ENV)
1680 curLimit = OPEN_MAX; /* for pre AIX 4.2 systems */
1681 #elif defined(AFS_NT40_ENV)
1682 curLimit = NT_OPEN_MAX; /* open file descriptor limit on NT */
1685 curLimit = 0; /* the number of open file descriptors */
1686 code = getrlimit(RLIMIT_NOFILE, &rlim);
1688 curLimit = rlim.rlim_cur;
1689 rlim.rlim_cur = rlim.rlim_max;
1690 code = setrlimit(RLIMIT_NOFILE, &rlim);
1692 curLimit = rlim.rlim_max;
1695 ViceLog(0, ("Failed to increase open file limit, using default\n"));
1697 #endif /* defined(AFS_AIX_ENV) && !defined(AFS_AIX42_ENV) */
1699 curLimit -= 32; /* leave a slack of 32 file descriptors */
1700 if (lwps > curLimit) {
1704 lwps = 16; /* default to a maximum of 16 threads */
1706 ("The system supports a max of %d open files and we are starting %d threads\n",
1709 #ifndef AFS_PTHREAD_ENV
1710 assert(LWP_InitializeProcessSupport(LWP_MAX_PRIORITY - 2, &parentPid) ==
1712 #endif /* !AFS_PTHREAD_ENV */
1714 /* Initialize volume support */
1716 V_BreakVolumeCallbacks = BreakVolumeCallBacksLater;
1719 #if defined(AFS_PTHREAD_ENV)
1720 threadNameProgram = threadName;
1723 /* initialize libacl routines */
1724 acl_Initialize(ACL_VERSION);
1726 /* initialize RX support */
1727 #ifndef AFS_NT40_ENV
1728 rxi_syscallp = viced_syscall;
1730 rx_extraPackets = rxpackets;
1731 rx_extraQuota = 4; /* for outgoing prserver calls from R threads */
1732 rx_SetBusyThreshold(busy_threshold, VBUSY);
1733 rx_SetCallAbortThreshold(abort_threshold);
1734 rx_SetConnAbortThreshold(abort_threshold);
1735 stackSize = lwps * 4000;
1736 if (stackSize < 32000)
1738 else if (stackSize > 44000)
1740 #if defined(AFS_HPUX_ENV) || defined(AFS_SUN_ENV) || defined(AFS_SGI51_ENV)
1741 rx_SetStackSize(1, stackSize);
1744 rx_SetUdpBufSize(udpBufSize); /* set the UDP buffer size for receive */
1745 if (rx_Init((int)htons(7000)) < 0) {
1746 ViceLog(0, ("Cannot initialize RX\n"));
1749 if (!rxJumbograms) {
1750 /* Don't send and don't allow 3.4 clients to send jumbograms. */
1754 rx_SetRxDeadTime(30);
1755 sc[0] = rxnull_NewServerSecurityObject();
1756 sc[1] = 0; /* rxvab_NewServerSecurityObject(key1, 0) */
1757 sc[2] = rxkad_NewServerSecurityObject(rxkad_clear, NULL, get_key, NULL);
1758 sc[3] = rxkad_NewServerSecurityObject(rxkad_crypt, NULL, get_key, NULL);
1759 tservice = rx_NewService( /* port */ 0, /* service id */ 1, /*service name */
1761 /* security classes */ sc,
1762 /* numb sec classes */
1763 4, RXAFS_ExecuteRequest);
1766 ("Failed to initialize RX, probably two servers running.\n"));
1769 rx_SetDestroyConnProc(tservice, (void (*)())h_FreeConnection);
1770 rx_SetMinProcs(tservice, 3);
1771 rx_SetMaxProcs(tservice, lwps);
1772 rx_SetCheckReach(tservice, 1);
1775 rx_NewService(0, RX_STATS_SERVICE_ID, "rpcstats", sc, 4,
1776 RXSTATS_ExecuteRequest);
1778 ViceLog(0, ("Failed to initialize rpc stat service.\n"));
1781 rx_SetMinProcs(tservice, 2);
1782 rx_SetMaxProcs(tservice, 4);
1785 * Enable RX hot threads, which allows the listener thread to trade
1786 * places with an idle thread and moves the context switch from listener
1787 * to worker out of the critical path.
1789 rx_EnableHotThread();
1791 /* Some rx debugging */
1792 if (rxlog || eventlog) {
1793 debugFile = afs_fopen("rx_dbg", "w");
1795 rx_debugFile = debugFile;
1797 rxevent_debugFile = debugFile;
1800 init_sys_error_to_et(); /* Set up error table translation */
1801 h_InitHostPackage(); /* set up local cellname and realmname */
1802 InitCallBack(numberofcbs);
1807 ViceLog(0, ("Fatal error in library initialization, exiting!!\n"));
1813 ViceLog(0, ("Fatal error in protection initialization, exiting!!\n"));
1817 /* allow super users to manage RX statistics */
1818 rx_SetRxStatUserOk(fs_rxstat_userok);
1820 rx_StartServer(0); /* now start handling requests */
1822 /* we ensure that there is enough space in the vnode buffer to satisfy
1823 ** requests from all concurrent threads.
1824 ** the maximum number of vnodes used by a single thread at any one time
1825 ** is three ( "link" uses three vnodes simultaneously, one vLarge and
1826 ** two vSmall for linking files and two vLarge and one vSmall for linking
1829 minVnodesRequired = 2 * lwps + 1;
1830 if (minVnodesRequired > nSmallVns) {
1831 nSmallVns = minVnodesRequired;
1833 ("Overriding -s command line parameter with %d\n",
1836 if (minVnodesRequired > large) {
1837 large = minVnodesRequired;
1838 ViceLog(0, ("Overriding -l command line parameter with %d\n", large));
1841 /* We now do this after getting the listener up and running, so that client
1842 * connections don't timeout (maybe) if a file server is restarted, since it
1843 * will be available "real soon now". Worry about whether we can satisfy the
1844 * calls in the volume package itself.
1846 if (VInitVolumePackage(fileServer, large, nSmallVns, 0, volcache)) {
1848 ("Shutting down: errors encountered initializing volume package\n"));
1854 * We are done calling fopen/fdopen. It is safe to use a large
1855 * of the file descriptor cache.
1859 #ifdef AFS_PTHREAD_ENV
1860 ViceLog(5, ("Starting pthreads\n"));
1861 assert(pthread_attr_init(&tattr) == 0);
1862 assert(pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED) == 0);
1864 assert(pthread_create
1865 (&serverPid, &tattr, (void *)FiveMinuteCheckLWP,
1866 &fiveminutes) == 0);
1867 assert(pthread_create
1868 (&serverPid, &tattr, (void *)HostCheckLWP, &fiveminutes) == 0);
1869 assert(pthread_create
1870 (&serverPid, &tattr, (void *)FsyncCheckLWP, &fiveminutes) == 0);
1871 #else /* AFS_PTHREAD_ENV */
1872 ViceLog(5, ("Starting LWP\n"));
1873 assert(LWP_CreateProcess
1874 (FiveMinuteCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
1875 (void *)&fiveminutes, "FiveMinuteChecks",
1876 &serverPid) == LWP_SUCCESS);
1878 assert(LWP_CreateProcess
1879 (HostCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
1880 (void *)&fiveminutes, "HostCheck", &serverPid) == LWP_SUCCESS);
1881 assert(LWP_CreateProcess
1882 (FsyncCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
1883 (void *)&fiveminutes, "FsyncCheck", &serverPid) == LWP_SUCCESS);
1884 #endif /* AFS_PTHREAD_ENV */
1886 TM_GetTimeOfDay(&tp, 0);
1888 #ifndef AFS_QUIETFS_ENV
1889 if (console != NULL) {
1890 time_t t = tp.tv_sec;
1891 fprintf(console, "File server has started at %s\r",
1892 afs_ctime(&t, tbuffer, sizeof(tbuffer)));
1897 * Figure out the FileServer's name and primary address.
1899 ViceLog(0, ("Getting FileServer name...\n"));
1900 code = gethostname(FS_HostName, 64);
1902 ViceLog(0, ("gethostname() failed\n"));
1904 ViceLog(0, ("FileServer host name is '%s'\n", FS_HostName));
1906 ViceLog(0, ("Getting FileServer address...\n"));
1907 he = gethostbyname(FS_HostName);
1909 ViceLog(0, ("Can't find address for FileServer '%s'\n", FS_HostName));
1912 memcpy(&FS_HostAddr_NBO, he->h_addr, 4);
1913 (void)afs_inet_ntoa_r(FS_HostAddr_NBO, hoststr);
1914 FS_HostAddr_HBO = ntohl(FS_HostAddr_NBO);
1916 ("FileServer %s has address %s (0x%x or 0x%x in host byte order)\n",
1917 FS_HostName, hoststr, FS_HostAddr_NBO, FS_HostAddr_HBO));
1920 /* Install handler to catch the shutdown signal;
1921 * bosserver assumes SIGQUIT shutdown
1923 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
1924 softsig_signal(SIGQUIT, ShutDown_Signal);
1926 (void)signal(SIGQUIT, ShutDown_Signal);
1931 ("File Server started %s",
1932 afs_ctime(&t, tbuffer, sizeof(tbuffer))));
1933 #if FS_STATS_DETAILED
1934 afs_FullPerfStats.det.epoch.tv_sec = StartTime = tp.tv_sec;
1936 #ifdef AFS_PTHREAD_ENV
1938 sleep(1000); /* long time */
1940 #else /* AFS_PTHREAD_ENV */
1941 assert(LWP_WaitProcess(&parentPid) == LWP_SUCCESS);
1942 #endif /* AFS_PTHREAD_ENV */