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
92 #if defined(AFS_SGI_ENV)
93 #include "sys/schedctl.h"
96 #include <rx/rx_globals.h>
99 #define afs_stat stat64
100 #define afs_fstat fstat64
101 #define afs_open open64
102 #define afs_fopen fopen64
103 #else /* !O_LARGEFILE */
104 #define afs_stat stat
105 #define afs_fstat fstat
106 #define afs_open open
107 #define afs_fopen fopen
108 #endif /* !O_LARGEFILE */
110 extern int BreakVolumeCallBacks(), InitCallBack();
111 extern int BreakVolumeCallBacks(), InitCallBack(), BreakLaterCallBacks();
112 extern int BreakVolumeCallBacksLater();
113 extern int LogLevel, etext;
114 extern afs_int32 BlocksSpare, PctSpare;
117 static void ClearXStatValues(), NewParms(), PrintCounters();
118 static void ResetCheckDescriptors(void), ResetCheckSignal(void);
119 static void CheckSignal(void);
120 extern int GetKeysFromToken();
121 extern int RXAFS_ExecuteRequest();
122 extern int RXSTATS_ExecuteRequest();
123 afs_int32 Do_VLRegisterRPC();
125 int eventlog = 0, rxlog = 0;
127 FILE *console = NULL;
129 #ifdef AFS_PTHREAD_ENV
130 pthread_mutex_t fsync_glock_mutex;
131 pthread_cond_t fsync_cond;
134 #endif /* AFS_PTHREAD_ENV */
137 #define AFS_QUIETFS_ENV 1
138 #define NT_OPEN_MAX 1024 /* This is an arbitrary no. we came up with for
139 * now. We hope this will be replaced by a more
140 * intelligent estimate later. */
143 int SystemId; /* ViceID of "Administrators" */
144 int SystemAnyUser; /* Viceid of "System:AnyUser" */
145 prlist SystemAnyUserCPS; /* CPS for "system:AnyUser */
146 int AnonymousID = 0; /* ViceId of "Anonymous" */
147 prlist AnonCPS; /* CPS for "Anonymous" */
149 struct afsconf_dir *confDir; /* Configuration dir object */
151 int restartMode = RESTART_ORDINARY;
153 int Testing = 0; /* for ListViceInodes */
156 * Home for the performance statistics.
158 struct afs_PerfStats afs_perfstats;
161 extern int Statistics;
169 int rxJumbograms = 1; /* default is to send and receive jumbograms. */
170 afs_int32 implicitAdminRights = PRSFS_LOOKUP; /* The ADMINISTER right is
172 afs_int32 readonlyServer = 0;
175 int stackSize = 24000;
176 int fiveminutes = 300; /* 5 minutes. Change this for debugging only */
177 int CurrentConnections = 0;
178 int hostaclRefresh = 7200; /* refresh host clients' acls every 2 hrs */
179 #if defined(AFS_SGI_ENV)
184 int rxpackets = 150; /* 100 */
185 int nSmallVns = 400; /* 200 */
186 int large = 400; /* 200 */
187 int volcache = 400; /* 400 */
188 int numberofcbs = 60000; /* 60000 */
189 int lwps = 9; /* 6 */
190 int buffs = 90; /* 70 */
191 int novbc = 0; /* Enable Volume Break calls */
192 int busy_threshold = 600;
193 int abort_threshold = 10;
194 int udpBufSize = 0; /* UDP buffer size for receive */
195 int sendBufSize = 16384; /* send buffer size */
200 * FileServer's name and IP address, both network byte order and
203 #define ADDRSPERSITE 16 /* Same global is in rx/rx_user.c */
205 char FS_HostName[128] = "localhost";
206 afs_uint32 FS_HostAddr_NBO;
207 afs_uint32 FS_HostAddr_HBO;
208 afs_uint32 FS_HostAddrs[ADDRSPERSITE], FS_HostAddr_cnt = 0, FS_registered = 0;
209 /* All addresses in FS_HostAddrs are in NBO */
212 static void FlagMsg();
215 * Home for the performance statistics.
223 struct afs_stat status;
224 register int tsize = getdtablesize();
226 for (i = 0; i < tsize; i++) {
227 if (afs_fstat(i, &status) != -1) {
228 printf("%d: dev %x, inode %u, length %u, type/mode %x\n", i,
229 status.st_dev, status.st_ino, status.st_size,
234 ResetCheckDescriptors();
236 } /*CheckDescriptors */
239 #ifdef AFS_PTHREAD_ENV
241 CheckSignal_Signal(x)
253 CheckDescriptors_Signal(x)
257 #else /* AFS_PTHREAD_ENV */
259 CheckSignal_Signal(x)
261 IOMGR_SoftSig(CheckSignal, 0);
267 IOMGR_SoftSig(ShutDown, 0);
271 CheckDescriptors_Signal(x)
273 IOMGR_SoftSig(CheckDescriptors, 0);
275 #endif /* AFS_PTHREAD_ENV */
277 /* check whether caller is authorized to manage RX statistics */
279 fs_rxstat_userok(struct rx_call *call)
281 return afsconf_SuperUser(confDir, call, NULL);
285 ResetCheckSignal(void)
289 #if defined(AFS_HPUX_ENV)
292 #if defined(AFS_NT40_ENV)
299 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
300 softsig_signal(signo, CheckSignal_Signal);
302 signal(signo, CheckSignal_Signal);
307 ResetCheckDescriptors(void)
310 #if defined(AFS_PTHREAD_ENV)
311 softsig_signal(SIGTERM, CheckDescriptors_Signal);
313 (void)signal(SIGTERM, CheckDescriptors_Signal);
318 #if defined(AFS_PTHREAD_ENV)
322 return pthread_getspecific(rx_thread_id_key);
326 /* proc called by rxkad module to get a key */
328 get_key(char *arock, register afs_int32 akvno, char *akey)
331 static struct afsconf_key tkey;
332 register afs_int32 code;
335 ViceLog(0, ("conf dir not open\n"));
338 code = afsconf_GetKey(confDir, akvno, tkey.key);
341 memcpy(akey, tkey.key, sizeof(tkey.key));
348 viced_syscall(afs_uint32 a3, afs_uint32 a4, void *a5)
353 #ifndef AFS_LINUX20_ENV
354 old = (void (*)())signal(SIGSYS, SIG_IGN);
356 rcode = syscall(AFS_SYSCALL, 28 /* AFSCALL_CALL */ , a3, a4, a5);
357 #ifndef AFS_LINUX20_ENV
365 #if !defined(AFS_NT40_ENV)
366 #include "AFS_component_version_number.c"
367 #endif /* !AFS_NT40_ENV */
369 #define MAXADMINNAME 64
370 char adminName[MAXADMINNAME];
376 struct afs_stat status;
378 if ((afs_stat("/AdminName", &status)) || /* if file does not exist */
379 (status.st_size <= 0) || /* or it is too short */
380 (status.st_size >= (MAXADMINNAME)) || /* or it is too long */
381 !(fd = afs_open("/AdminName", O_RDONLY, 0))) { /* or the open fails */
382 strcpy(adminName, "System:Administrators"); /* use the default name */
384 (void)read(fd, adminName, status.st_size); /* use name from the file */
387 close(fd); /* close fd if it was opened */
389 } /*CheckAdminName */
395 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
396 /* set our 'thread-id' so that the host hold table works */
397 MUTEX_ENTER(&rx_stats_mutex); /* protects rxi_pthread_hinum */
399 pthread_setspecific(rx_thread_id_key, (void *)rxi_pthread_hinum);
400 MUTEX_EXIT(&rx_stats_mutex);
402 ("Set thread id %d for '%s'\n",
403 pthread_getspecific(rx_thread_id_key), s));
407 /* This LWP does things roughly every 5 minutes */
414 ViceLog(1, ("Starting five minute check process\n"));
415 setThreadId("FiveMinuteCheckLWP");
417 #ifdef AFS_PTHREAD_ENV
419 #else /* AFS_PTHREAD_ENV */
420 IOMGR_Sleep(fiveminutes);
421 #endif /* AFS_PTHREAD_ENV */
423 /* close the log so it can be removed */
424 ReOpenLog(AFSDIR_SERVER_FILELOG_FILEPATH); /* don't trunc, just append */
425 ViceLog(2, ("Cleaning up timed out callbacks\n"));
426 if (CleanupTimedOutCallBacks())
427 ViceLog(5, ("Timed out callbacks deleted\n"));
428 ViceLog(2, ("Set disk usage statistics\n"));
430 if (FS_registered == 1)
432 /* Force wakeup in case we missed something; pthreads does timedwait */
433 #ifndef AFS_PTHREAD_ENV
434 LWP_NoYieldSignal(fsync_wait);
436 if (printBanner && (++msg & 1)) { /* Every 10 minutes */
437 time_t now = FT_ApproxTime();
438 if (console != NULL) {
439 #ifndef AFS_QUIETFS_ENV
440 fprintf(console, "File server is running at %s\r",
441 afs_ctime(&now, tbuffer, sizeof(tbuffer)));
442 #endif /* AFS_QUIETFS_ENV */
444 ("File server is running at %s\n",
445 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
449 } /*FiveMinuteCheckLWP */
452 /* This LWP does host checks every 5 minutes: it should not be used for
453 * other 5 minute activities because it may be delayed by timeouts when
454 * it probes the workstations
459 ViceLog(1, ("Starting Host check process\n"));
460 setThreadId("HostCheckLWP");
462 #ifdef AFS_PTHREAD_ENV
464 #else /* AFS_PTHREAD_ENV */
465 IOMGR_Sleep(fiveminutes);
466 #endif /* AFS_PTHREAD_ENV */
467 ViceLog(2, ("Checking for dead venii & clients\n"));
472 /* This LWP does fsync checks every 5 minutes: it should not be used for
473 * other 5 minute activities because it may be delayed by timeouts when
474 * it probes the workstations
480 #ifdef AFS_PTHREAD_ENV
481 struct timespec fsync_next;
483 ViceLog(1, ("Starting fsync check process\n"));
485 setThreadId("FsyncCheckLWP");
487 #ifdef AFS_PTHREAD_ENV
488 assert(pthread_cond_init(&fsync_cond, NULL) == 0);
489 assert(pthread_mutex_init(&fsync_glock_mutex, NULL) == 0);
494 #ifdef AFS_PTHREAD_ENV
495 /* rounding is fine */
496 fsync_next.tv_nsec = 0;
497 fsync_next.tv_sec = time(0) + fiveminutes;
500 pthread_cond_timedwait(&fsync_cond, &fsync_glock_mutex,
502 if (code != 0 && code != ETIMEDOUT)
503 ViceLog(0, ("pthread_cond_timedwait returned %d\n", code));
504 #else /* AFS_PTHREAD_ENV */
505 if ((code = LWP_WaitProcess(fsync_wait)) != LWP_SUCCESS)
506 ViceLog(0, ("LWP_WaitProcess returned %d\n", code));
507 #endif /* AFS_PTHREAD_ENV */
509 ViceLog(2, ("Checking for fsync events\n"));
511 code = BreakLaterCallBacks();
516 /*------------------------------------------------------------------------
517 * PRIVATE ClearXStatValues
520 * Initialize all of the values collected via the xstat
530 * Must be called during File Server initialization.
534 *------------------------------------------------------------------------*/
538 { /*ClearXStatValues */
540 struct fs_stats_opTimingData *opTimeP; /*Ptr to timing struct */
541 struct fs_stats_xferData *opXferP; /*Ptr to xfer struct */
542 int i; /*Loop counter */
545 * Zero all xstat-related structures.
547 memset((char *)(&afs_perfstats), 0, sizeof(struct afs_PerfStats));
548 #if FS_STATS_DETAILED
549 memset((char *)(&afs_FullPerfStats), 0,
550 sizeof(struct fs_stats_FullPerfStats));
553 * That's not enough. We have to set reasonable minima for
554 * time and xfer values in the detailed stats.
556 opTimeP = &(afs_FullPerfStats.det.rpcOpTimes[0]);
557 for (i = 0; i < FS_STATS_NUM_RPC_OPS; i++, opTimeP++)
558 opTimeP->minTime.tv_sec = 999999;
560 opXferP = &(afs_FullPerfStats.det.xferOpTimes[0]);
561 for (i = 0; i < FS_STATS_NUM_XFER_OPS; i++, opXferP++) {
562 opXferP->minTime.tv_sec = 999999;
563 opXferP->minBytes = 999999999;
567 * There's more. We have to set our unique system identifier, as
568 * declared in param.h. If such a thing is not defined, we bitch
569 * and declare ourselves to be an unknown system type.
572 afs_perfstats.sysname_ID = SYS_NAME_ID;
575 ViceLog(0, ("Sys name ID constant not defined in param.h!!\n"));
576 ViceLog(0, ("[Choosing ``undefined'' sys name ID.\n"));
578 afs_perfstats.sysname_ID = SYS_NAME_ID_UNDEFINED;
579 #endif /* SYS_NAME_ID */
582 } /*ClearXStatValues */
588 int dirbuff, dircall, dirio;
590 int workstations, activeworkstations, delworkstations;
594 TM_GetTimeOfDay(&tpl, 0);
597 ("Vice was last started at %s\n",
598 afs_ctime(&StartTime, tbuffer, sizeof(tbuffer))));
602 DStat(&dirbuff, &dircall, &dirio);
604 ("With %d directory buffers; %d reads resulted in %d read I/Os\n",
605 dirbuff, dircall, dirio));
606 rx_PrintStats(stderr);
608 PrintCallBackStats();
610 processSize = -1; /* TODO: */
612 processSize = (int)((long)sbrk(0) >> 10);
615 ("There are %d connections, process size %d\n",
616 CurrentConnections, processSize));
617 h_GetWorkStats(&workstations, &activeworkstations, &delworkstations,
618 tpl.tv_sec - 15 * 60);
620 ("There are %d workstations, %d are active (req in < 15 mins), %d marked \"down\"\n",
621 workstations, activeworkstations, delworkstations));
631 if (FS_registered > 0) {
633 * We have proper ip addresses; tell the vlserver what we got; the following
634 * routine will do the proper reporting for us
647 ShutDownAndCore(int dopanic)
649 time_t now = time(0);
653 ("Shutting down file server at %s",
654 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
656 ViceLog(0, ("ABNORMAL SHUTDOWN, see core file.\n"));
657 #ifndef AFS_QUIETFS_ENV
658 if (console != NULL) {
659 fprintf(console, "File server restart/shutdown received at %s\r",
660 afs_ctime(&now, tbuffer, sizeof(tbuffer)));
667 /* do not allows new reqests to be served from now on, all new requests
668 * are returned with an error code of RX_RESTARTING ( transient failure ) */
669 rx_SetRxTranquil(); /* dhruba */
673 rx_PrintStats(debugFile);
676 if (console != NULL) {
679 #ifndef AFS_QUIETFS_ENV
680 fprintf(console, "File server has terminated abnormally at %s\r",
681 afs_ctime(&now, tbuffer, sizeof(tbuffer)));
684 ("File server has terminated abnormally at %s\n",
685 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
687 #ifndef AFS_QUIETFS_ENV
688 fprintf(console, "File server has terminated normally at %s\r",
689 afs_ctime(&now, tbuffer, sizeof(tbuffer)));
692 ("File server has terminated normally at %s\n",
693 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
703 { /* backward compatibility */
704 ShutDownAndCore(DONTPANIC);
713 /* default supports help flag */
715 strcpy(buffer, "Usage: fileserver ");
716 strcpy(buffer, "[-auditlog <log path>] ");
717 strcat(buffer, "[-d <debug level>] ");
718 strcat(buffer, "[-p <number of processes>] ");
719 strcat(buffer, "[-spare <number of spare blocks>] ");
720 strcat(buffer, "[-pctspare <percentage spare>] ");
721 strcat(buffer, "[-b <buffers>] ");
722 strcat(buffer, "[-l <large vnodes>] ");
723 strcat(buffer, "[-s <small vnodes>] ");
724 strcat(buffer, "[-vc <volume cachesize>] ");
725 strcat(buffer, "[-w <call back wait interval>] ");
726 strcat(buffer, "[-cb <number of call backs>] ");
727 strcat(buffer, "[-banner (print banner every 10 minutes)] ");
728 strcat(buffer, "[-novbc (whole volume cbs disabled)] ");
729 strcat(buffer, "[-implicit <admin mode bits: rlidwka>] ");
730 strcat(buffer, "[-readonly (read-only file server)] ");
732 "[-hr <number of hours between refreshing the host cps>] ");
733 strcat(buffer, "[-busyat <redirect clients when queue > n>] ");
734 strcat(buffer, "[-nobusy <no VBUSY before a volume is attached>] ");
735 strcat(buffer, "[-rxpck <number of rx extra packets>] ");
736 strcat(buffer, "[-rxdbg (enable rx debugging)] ");
737 strcat(buffer, "[-rxdbge (enable rxevent debugging)] ");
739 strcat(buffer, "[-vattachpar <number of volume attach threads>] ");
742 strcat(buffer, "[-m <min percentage spare in partition>] ");
744 #if defined(AFS_SGI_ENV)
745 strcat(buffer, "[-lock (keep fileserver from swapping)] ");
747 strcat(buffer, "[-L (large server conf)] ");
748 strcat(buffer, "[-S (small server conf)] ");
749 strcat(buffer, "[-k <stack size>] ");
750 strcat(buffer, "[-realm <Kerberos realm name>] ");
751 strcat(buffer, "[-udpsize <size of socket buffer in bytes>] ");
752 strcat(buffer, "[-sendsize <size of send buffer in bytes>] ");
753 strcat(buffer, "[-abortthreshold <abort threshold>] ");
754 /* strcat(buffer, "[-enable_peer_stats] "); */
755 /* strcat(buffer, "[-enable_process_stats] "); */
756 strcat(buffer, "[-help]\n");
758 ViceLog(0, ("%s", buffer));
761 printf("%s", buffer);
768 ParseRights(char *arights)
774 if (!arights || !strcmp(arights, "")) {
775 printf("Missing list of mode bits on -implicit option\n");
778 if (!strcmp(arights, "none"))
780 else if (!strcmp(arights, "read"))
781 mode = PRSFS_READ | PRSFS_LOOKUP;
782 else if (!strcmp(arights, "write"))
784 PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
785 PRSFS_WRITE | PRSFS_LOCK;
786 else if (!strcmp(arights, "all"))
788 PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
789 PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER;
791 len = strlen(arights);
792 for (i = 0; i < len; i++) {
797 mode |= PRSFS_LOOKUP;
799 mode |= PRSFS_INSERT;
801 mode |= PRSFS_DELETE;
807 mode |= PRSFS_ADMINISTER;
825 printf("Illegal -implicit rights character '%c'.\n", tc);
834 * Limit MAX_FILESERVER_THREAD by the system limit on the number of
835 * pthreads (sysconf(_SC_THREAD_THREADS_MAX)), if applicable and
838 * AIX: sysconf() limit is real
839 * HP-UX: sysconf() limit is real
840 * IRIX: sysconf() limit is apparently NOT real -- too small
841 * DUX: sysconf() limit is apparently NOT real -- too big
842 * Linux: sysconf() limit is apparently NOT real -- too big
843 * Solaris: no sysconf() limit
846 max_fileserver_thread(void)
848 #if defined(AFS_PTHREAD_ENV)
849 #if defined(AFS_AIX_ENV) || defined(AFS_HPUX_ENV)
852 ans = sysconf(_SC_THREAD_THREADS_MAX);
853 if (0 < ans && ans < MAX_FILESERVER_THREAD)
856 #endif /* defined(AFS_PTHREAD_ENV) */
857 return MAX_FILESERVER_THREAD;
861 ParseArgs(int argc, char *argv[])
863 int SawL = 0, SawS = 0, SawVC = 0;
864 int Sawrxpck = 0, Sawsmall = 0, Sawlarge = 0, Sawcbs = 0, Sawlwps =
868 int bufSize = 0; /* temp variable to read in udp socket buf size */
870 for (i = 1; i < argc; i++) {
871 if (!strcmp(argv[i], "-d")) {
872 if ((i + 1) >= argc) {
873 fprintf(stderr, "missing argument for -d\n");
876 debuglevel = atoi(argv[++i]);
877 LogLevel = debuglevel;
878 } else if (!strcmp(argv[i], "-banner")) {
880 } else if (!strcmp(argv[i], "-implicit")) {
881 if ((i + 1) >= argc) {
882 fprintf(stderr, "missing argument for -implicit\n");
885 implicitAdminRights = ParseRights(argv[++i]);
886 if (implicitAdminRights < 0)
887 return implicitAdminRights;
888 } else if (!strcmp(argv[i], "-readonly")) {
890 } else if (!strcmp(argv[i], "-L")) {
892 } else if (!strcmp(argv[i], "-S")) {
894 } else if (!strcmp(argv[i], "-p")) {
896 max_fileserver_thread() - FILESERVER_HELPER_THREADS;
898 if ((i + 1) >= argc) {
899 fprintf(stderr, "missing argument for -p\n");
902 lwps = atoi(argv[++i]);
907 } else if (!strcmp(argv[i], "-b")) {
909 if ((i + 1) >= argc) {
910 fprintf(stderr, "missing argument for -b\n");
913 buffs = atoi(argv[++i]);
914 } else if (!strcmp(argv[i], "-l")) {
916 if ((i + 1) >= argc) {
917 fprintf(stderr, "missing argument for -l\n");
920 large = atoi(argv[++i]);
921 } else if (!strcmp(argv[i], "-vc")) {
923 if ((i + 1) >= argc) {
924 fprintf(stderr, "missing argument for -vc\n");
927 volcache = atoi(argv[++i]);
928 } else if (!strcmp(argv[i], "-novbc")) {
930 } else if (!strcmp(argv[i], "-rxpck")) {
932 if ((i + 1) >= argc) {
933 fprintf(stderr, "missing argument for -rxpck\n");
936 rxpackets = atoi(argv[++i]);
937 #ifdef AFS_PTHREAD_ENV
938 } else if (!strcmp(argv[i], "-vattachpar")) {
939 if ((i + 1) >= argc) {
940 fprintf(stderr, "missing argument for -vattachpar\n");
943 vol_attach_threads = atoi(argv[++i]);
944 #endif /* AFS_PTHREAD_ENV */
945 } else if (!strcmp(argv[i], "-s")) {
947 if ((i + 1) >= argc) {
948 fprintf(stderr, "missing argument for -s\n");
951 nSmallVns = atoi(argv[++i]);
952 } else if (!strcmp(argv[i], "-abortthreshold")) {
953 if ((i + 1) >= argc) {
954 fprintf(stderr, "missing argument for -abortthreshold\n");
957 abort_threshold = atoi(argv[++i]);
958 } else if (!strcmp(argv[i], "-k")) {
959 if ((i + 1) >= argc) {
960 fprintf(stderr, "missing argument for -k\n");
963 stack = atoi(argv[++i]);
965 #if defined(AFS_SGI_ENV)
966 else if (!strcmp(argv[i], "-lock")) {
970 else if (!strcmp(argv[i], "-spare")) {
971 if ((i + 1) >= argc) {
972 fprintf(stderr, "missing argument for -spare\n");
975 BlocksSpare = atoi(argv[++i]);
977 } else if (!strcmp(argv[i], "-pctspare")) {
978 if ((i + 1) >= argc) {
979 fprintf(stderr, "missing argument for -pctspare\n");
982 PctSpare = atoi(argv[++i]);
983 BlocksSpare = 0; /* has non-zero default */
985 } else if (!strcmp(argv[i], "-w")) {
986 if ((i + 1) >= argc) {
987 fprintf(stderr, "missing argument for -w\n");
990 fiveminutes = atoi(argv[++i]);
991 } else if (!strcmp(argv[i], "-hr")) {
993 if ((i + 1) >= argc) {
994 fprintf(stderr, "missing argument for -hr\n");
997 hr = atoi(argv[++i]);
998 if ((hr < 1) || (hr > 36)) {
1000 ("host acl refresh interval of %d hours is invalid; hours must be between 1 and 36\n\n",
1004 hostaclRefresh = hr * 60 * 60;
1005 } else if (!strcmp(argv[i], "-rxdbg"))
1007 else if (!strcmp(argv[i], "-rxdbge"))
1009 else if (!strcmp(argv[i], "-cb")) {
1011 if ((i + 1) >= argc) {
1012 fprintf(stderr, "missing argument for -cb\n");
1015 numberofcbs = atoi(argv[++i]);
1016 if ((numberofcbs < 10000) || (numberofcbs > 2147483647)) {
1018 ("number of cbs %d invalid; must be between 10000 and 2147483647\n",
1022 } else if (!strcmp(argv[i], "-busyat")) {
1024 if ((i + 1) >= argc) {
1025 fprintf(stderr, "missing argument for -busyat\n");
1028 busy_threshold = atoi(argv[++i]);
1029 if (busy_threshold < 10) {
1031 ("Busy threshold %d is too low, will compute default.\n",
1035 } else if (!strcmp(argv[i], "-nobusy"))
1037 #ifdef AFS_AIX32_ENV
1038 else if (!strcmp(argv[i], "-m")) {
1039 extern int aixlow_water;
1040 if ((i + 1) >= argc) {
1041 fprintf(stderr, "missing argument for -m\n");
1044 aixlow_water = atoi(argv[++i]);
1045 if ((aixlow_water < 0) || (aixlow_water > 30)) {
1046 printf("space reserved %d% invalid; must be between 0-30%\n",
1052 else if (!strcmp(argv[i], "-nojumbo")) {
1054 } else if (!strcmp(argv[i], "-realm")) {
1055 extern char local_realms[AFS_NUM_LREALMS][AFS_REALM_SZ];
1056 extern int num_lrealms;
1057 if ((i + 1) >= argc) {
1058 fprintf(stderr, "missing argument for -realm\n");
1061 if (strlen(argv[++i]) >= AFS_REALM_SZ) {
1063 ("-realm argument must contain fewer than %d characters.\n",
1067 if (num_lrealms == -1)
1069 if (num_lrealms >= AFS_NUM_LREALMS) {
1071 ("a maximum of %d -realm arguments can be specified.\n",
1075 strncpy(local_realms[num_lrealms++], argv[i], AFS_REALM_SZ);
1076 } else if (!strcmp(argv[i], "-udpsize")) {
1077 if ((i + 1) >= argc) {
1078 printf("You have to specify -udpsize <integer value>\n");
1081 bufSize = atoi(argv[++i]);
1082 if (bufSize < rx_GetMinUdpBufSize())
1084 ("Warning:udpsize %d is less than minimum %d; ignoring\n",
1085 bufSize, rx_GetMinUdpBufSize());
1087 udpBufSize = bufSize;
1088 } else if (!strcmp(argv[i], "-sendsize")) {
1089 if ((i + 1) >= argc) {
1090 printf("You have to specify -sendsize <integer value>\n");
1093 bufSize = atoi(argv[++i]);
1094 if (bufSize < 16384)
1096 ("Warning:sendsize %d is less than minimum %d; ignoring\n",
1099 sendBufSize = bufSize;
1100 } else if (!strcmp(argv[i], "-enable_peer_stats")) {
1101 rx_enablePeerRPCStats();
1102 } else if (!strcmp(argv[i], "-enable_process_stats")) {
1103 rx_enableProcessRPCStats();
1105 else if (strcmp(argv[i], "-auditlog") == 0) {
1108 char oldName[MAXPATHLEN];
1109 char *fileName = argv[++i];
1111 #ifndef AFS_NT40_ENV
1112 struct stat statbuf;
1114 if ((lstat(fileName, &statbuf) == 0)
1115 && (S_ISFIFO(statbuf.st_mode))) {
1116 flags = O_WRONLY | O_NONBLOCK;
1120 strcpy(oldName, fileName);
1121 strcat(oldName, ".old");
1122 renamefile(fileName, oldName);
1123 flags = O_WRONLY | O_TRUNC | O_CREAT;
1125 tempfd = open(fileName, flags, 0666);
1127 auditout = fdopen(tempfd, "a");
1129 osi_audit_file(auditout);
1131 printf("Warning: auditlog %s not writable, ignored.\n", fileName);
1133 printf("Warning: auditlog %s not writable, ignored.\n", fileName);
1135 #ifndef AFS_NT40_ENV
1136 else if (strcmp(argv[i], "-syslog") == 0) {
1137 /* set syslog logging flag */
1138 serverLogSyslog = 1;
1139 } else if (strncmp(argv[i], "-syslog=", 8) == 0) {
1140 serverLogSyslog = 1;
1141 serverLogSyslogFacility = atoi(argv[i] + 8);
1144 else if (strcmp(argv[i], "-mrafslogs") == 0) {
1145 /* set syslog logging flag */
1153 printf("Only one of -L, or -S must be specified\n");
1164 numberofcbs = 20000;
1180 numberofcbs = 64000;
1189 busy_threshold = 3 * rxpackets / 2;
1199 NewParms(int initializing)
1201 static struct afs_stat sbuf;
1204 char *argv[MAXPARMS];
1207 if (!(afs_stat("/vice/file/parms", &sbuf))) {
1208 parms = (char *)malloc(sbuf.st_size);
1211 fd = afs_open("parms", O_RDONLY, 0666);
1213 ViceLog(0, ("Open for parms failed with errno = %d\n", errno));
1217 i = read(fd, parms, sbuf.st_size);
1219 if (i != sbuf.st_size) {
1221 ViceLog(0, ("Read on parms failed with errno = %d\n", errno));
1224 ("Read on parms failed; expected %d bytes but read %d\n",
1231 for (i = 0; i < MAXPARMS; argv[i++] = 0);
1233 for (argc = i = 0; i < sbuf.st_size; i++) {
1234 if ((*(parms + i) != ' ') && (*(parms + i) != '\n')) {
1235 if (argv[argc] == 0)
1236 argv[argc] = (parms + i);
1238 *(parms + i) = '\0';
1239 if (argv[argc] != 0) {
1240 if (++argc == MAXPARMS)
1243 while ((*(parms + i + 1) == ' ')
1244 || (*(parms + i + 1) == '\n'))
1248 if (ParseArgs(argc, argv) == 0) {
1249 ViceLog(0, ("Change parameters to:"));
1251 ViceLog(0, ("Invalid parameter in:"));
1253 for (i = 0; i < argc; i++) {
1254 ViceLog(0, (" %s", argv[i]));
1258 } else if (!initializing)
1260 ("Received request to change parms but no parms file exists\n"));
1265 /* Miscellaneous routines */
1269 ViceLog(0, ("%s\n", msg));
1281 * If this fails, it's because something major is wrong, and is not
1282 * likely to be time dependent.
1284 code = pr_Initialize(2, AFSDIR_SERVER_ETC_DIRPATH, 0);
1287 ("Couldn't initialize protection library; code=%d.\n", code));
1290 SystemId = SYSADMINID;
1291 SystemAnyUser = ANYUSERID;
1292 SystemAnyUserCPS.prlist_len = 0;
1293 SystemAnyUserCPS.prlist_val = NULL;
1294 AnonCPS.prlist_len = 0;
1295 AnonCPS.prlist_val = NULL;
1297 code = pr_GetCPS(SystemAnyUser, &SystemAnyUserCPS);
1300 ("Couldn't get CPS for AnyUser, will try again in 30 seconds; code=%d.\n",
1304 code = pr_GetCPS(ANONYMOUSID, &AnonCPS);
1307 ("Couldn't get Anonymous CPS, exiting; code=%d.\n",
1311 AnonymousID = ANONYMOUSID;
1314 #ifdef AFS_PTHREAD_ENV
1316 #else /* AFS_PTHREAD_ENV */
1318 #endif /* AFS_PTHREAD_ENV */
1322 struct rx_connection *serverconns[MAXSERVERS];
1323 struct ubik_client *cstruct;
1326 vl_Initialize(char *confDir)
1328 afs_int32 code, scIndex = 0, i;
1329 struct afsconf_dir *tdir;
1330 struct rx_securityClass *sc;
1331 struct afsconf_cell info;
1333 tdir = afsconf_Open(confDir);
1336 ("Could not open configuration directory (%s).\n", confDir));
1339 code = afsconf_ClientAuth(tdir, &sc, &scIndex);
1341 ViceLog(0, ("Could not get security object for localAuth\n"));
1344 code = afsconf_GetCellInfo(tdir, NULL, AFSCONF_VLDBSERVICE, &info);
1345 if (info.numServers > MAXSERVERS) {
1347 ("vl_Initialize: info.numServers=%d (> MAXSERVERS=%d)\n",
1348 info.numServers, MAXSERVERS));
1351 for (i = 0; i < info.numServers; i++)
1353 rx_NewConnection(info.hostAddr[i].sin_addr.s_addr,
1354 info.hostAddr[i].sin_port, USER_SERVICE_ID, sc,
1356 code = ubik_ClientInit(serverconns, &cstruct);
1358 ViceLog(0, ("vl_Initialize: ubik client init failed.\n"));
1364 #define SYSIDMAGIC 0x88aabbcc
1365 #define SYSIDVERSION 1
1370 afs_int32 fd, nentries, i;
1371 struct versionStamp vsn;
1372 struct afs_stat status;
1375 if ((afs_stat(AFSDIR_SERVER_SYSID_FILEPATH, &status))
1376 || (status.st_size <= 0)) {
1377 ViceLog(0, ("%s: doesn't exist\n", AFSDIR_SERVER_SYSID_FILEPATH));
1380 if (!(fd = afs_open(AFSDIR_SERVER_SYSID_FILEPATH, O_RDONLY, 0))) {
1382 ("%s: can't open (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1386 if ((i = read(fd, (char *)&vsn, sizeof(vsn))) != sizeof(vsn)) {
1388 ("%s: Read failed (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1392 if (vsn.magic != SYSIDMAGIC) {
1394 ("%s: wrong magic %x (we support %x)\n",
1395 AFSDIR_SERVER_SYSID_FILEPATH, vsn.magic, SYSIDMAGIC));
1398 if (vsn.version != SYSIDVERSION) {
1400 ("%s: wrong version %d (we support %d)\n",
1401 AFSDIR_SERVER_SYSID_FILEPATH, vsn.version, SYSIDVERSION));
1405 read(fd, (char *)&uuid,
1406 sizeof(struct afsUUID))) != sizeof(struct afsUUID)) {
1408 ("%s: read of uuid failed (%d)\n",
1409 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1412 afs_ntohuuid(&uuid);
1415 read(fd, (char *)&nentries,
1416 sizeof(afs_int32))) != sizeof(afs_int32)) {
1418 ("%s: Read of entries failed (%d)\n",
1419 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1422 if (nentries <= 0 || nentries > ADDRSPERSITE) {
1424 ("%s: invalid num of interfaces: %d\n",
1425 AFSDIR_SERVER_SYSID_FILEPATH, nentries));
1428 FS_HostAddr_cnt = nentries;
1429 for (i = 0; i < nentries; i++) {
1430 if (read(fd, (char *)&FS_HostAddrs[i], sizeof(afs_int32)) !=
1431 sizeof(afs_int32)) {
1433 ("%s: Read of addresses failed (%d)\n",
1434 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1435 FS_HostAddr_cnt = 0; /* reset it */
1447 struct versionStamp vsn;
1448 struct afs_stat status;
1451 if (!afs_stat(AFSDIR_SERVER_SYSID_FILEPATH, &status)) {
1453 * File exists; keep the old one around
1455 renamefile(AFSDIR_SERVER_SYSID_FILEPATH,
1456 AFSDIR_SERVER_OLDSYSID_FILEPATH);
1458 fd = afs_open(AFSDIR_SERVER_SYSID_FILEPATH, O_WRONLY | O_TRUNC | O_CREAT,
1462 ("%s: can't create (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1466 vsn.magic = SYSIDMAGIC;
1468 if ((i = write(fd, (char *)&vsn, sizeof(vsn))) != sizeof(vsn)) {
1470 ("%s: write failed (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1475 afs_htonuuid(&uuid);
1477 write(fd, (char *)&uuid,
1478 sizeof(struct afsUUID))) != sizeof(struct afsUUID)) {
1480 ("%s: write of uuid failed (%d)\n",
1481 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1485 write(fd, (char *)&FS_HostAddr_cnt,
1486 sizeof(afs_int32))) != sizeof(afs_int32)) {
1488 ("%s: write of # of entries failed (%d)\n",
1489 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1492 for (i = 0; i < FS_HostAddr_cnt; i++) {
1493 if (write(fd, (char *)&FS_HostAddrs[i], sizeof(afs_int32)) !=
1494 sizeof(afs_int32)) {
1496 ("%s: write of addresses failed (%d)\n",
1497 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1507 * This routine sets up the buffers for the VL_RegisterAddrs RPC. All addresses
1508 * in FS_HostAddrs[] are in NBO, while the RPC treats them as a "blob" of data
1509 * and so we need to convert each of them into HBO which is what the extra
1510 * array called FS_HostAddrs_HBO is used here.
1517 extern int VL_RegisterAddrs();
1518 afs_uint32 FS_HostAddrs_HBO[ADDRSPERSITE];
1521 for (i = 0; i < FS_HostAddr_cnt; i++)
1522 FS_HostAddrs_HBO[i] = ntohl(FS_HostAddrs[i]);
1523 addrs.bulkaddrs_len = FS_HostAddr_cnt;
1524 addrs.bulkaddrs_val = (afs_uint32 *) FS_HostAddrs_HBO;
1525 code = ubik_Call(VL_RegisterAddrs, cstruct, 0, &FS_HostUUID, 0, &addrs);
1527 if (code == VL_MULTIPADDR) {
1529 ("VL_RegisterAddrs rpc failed; The IP address exists on a different server; repair it\n"));
1531 ("VL_RegisterAddrs rpc failed; See VLLog for details\n"));
1533 } else if (code == RXGEN_OPCODE) {
1535 ("vlserver doesn't support VL_RegisterAddrs rpc; ignored\n"));
1536 FS_registered = 2; /* So we don't have to retry in the gc daemon */
1539 ("VL_RegisterAddrs rpc failed; will retry periodically (code=%d, err=%d)\n",
1543 FS_registered = 2; /* So we don't have to retry in the gc daemon */
1554 extern int rxi_numNetAddrs;
1555 extern afs_uint32 rxi_NetAddrs[];
1558 * If this fails, it's because something major is wrong, and is not
1559 * likely to be time dependent.
1561 code = vl_Initialize(AFSDIR_SERVER_ETC_DIRPATH);
1564 ("Couldn't initialize protection library; code=%d.\n", code));
1568 /* Read or create the sysid file and register the fileserver's
1569 * IP addresses with the vlserver.
1571 code = ReadSysIdFile();
1573 /* Need to create the file */
1574 ViceLog(0, ("Creating new SysID file\n"));
1575 if ((code = afs_uuid_create(&FS_HostUUID))) {
1576 ViceLog(0, ("Failed to create new uuid: %d\n", code));
1580 /* A good sysid file exists; inform the vlserver. If any conflicts,
1581 * we always use the latest interface available as the real truth.
1583 #ifndef AFS_NT40_ENV
1584 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH || AFSDIR_SERVER_NETINFO_FILEPATH) {
1586 * Find addresses we are supposed to register as per the netrestrict
1587 * and netinfo files (/usr/afs/local/NetInfo and
1588 * /usr/afs/local/NetRestict)
1591 afs_int32 code = parseNetFiles(FS_HostAddrs, NULL, NULL,
1592 ADDRSPERSITE, reason,
1593 AFSDIR_SERVER_NETINFO_FILEPATH,
1594 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
1596 ViceLog(0, ("Can't register any valid addresses: %s\n", reason));
1599 FS_HostAddr_cnt = (afs_uint32) code;
1603 FS_HostAddr_cnt = rx_getAllAddr(FS_HostAddrs, ADDRSPERSITE);
1607 code = Do_VLRegisterRPC();
1612 main(int argc, char *argv[])
1616 struct rx_securityClass *sc[4];
1617 struct rx_service *tservice;
1618 #ifdef AFS_PTHREAD_ENV
1619 pthread_t serverPid;
1620 pthread_attr_t tattr;
1621 #else /* AFS_PTHREAD_ENV */
1622 PROCESS parentPid, serverPid;
1623 #endif /* AFS_PTHREAD_ENV */
1625 int minVnodesRequired; /* min size of vnode cache */
1626 #ifndef AFS_NT40_ENV
1627 struct rlimit rlim; /* max number of open file descriptors */
1632 #ifdef AFS_AIX32_ENV
1633 struct sigaction nsa;
1635 sigemptyset(&nsa.sa_mask);
1636 nsa.sa_handler = SIG_DFL;
1637 nsa.sa_flags = SA_FULLDUMP;
1638 sigaction(SIGABRT, &nsa, NULL);
1639 sigaction(SIGSEGV, &nsa, NULL);
1643 /* Initialize dirpaths */
1644 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
1646 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
1648 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
1652 #ifndef AFS_QUIETFS_ENV
1653 console = afs_fopen("/dev/console", "w");
1656 if (ParseArgs(argc, argv)) {
1660 #ifdef AFS_PTHREAD_ENV
1661 assert(pthread_mutex_init(&fileproc_glock_mutex, NULL) == 0);
1662 #endif /* AFS_PTHREAD_ENV */
1664 #ifdef AFS_SGI_VNODE_GLUE
1665 if (afs_init_kernel_config(-1) < 0) {
1667 ("Can't determine NUMA configuration, not starting fileserver.\n");
1671 confDir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
1673 fprintf(stderr, "Unable to open config directory %s\n",
1674 AFSDIR_SERVER_ETC_DIRPATH);
1680 /* Open FileLog on stdout, stderr, fd 1 and fd2 (for perror), sigh. */
1681 #ifndef AFS_NT40_ENV
1682 serverLogSyslogTag = "fileserver";
1684 OpenLog(AFSDIR_SERVER_FILELOG_FILEPATH);
1687 if (SawSpare && SawPctSpare) {
1688 ViceLog(0, ("Both -spare and -pctspare specified, exiting.\n"));
1691 #ifdef AFS_SGI_XFS_IOPS_ENV
1692 ViceLog(0, ("XFS/EFS File server starting\n"));
1694 ViceLog(0, ("File server starting\n"));
1697 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
1698 /* initialize the pthread soft signal handler thread */
1702 /* install signal handlers for controlling the fileserver process */
1703 ResetCheckSignal(); /* set CheckSignal_Signal() sig handler */
1704 ResetCheckDescriptors(); /* set CheckDescriptors_Signal() sig handler */
1706 #if defined(AFS_SGI_ENV)
1707 /* give this guy a non-degrading priority so help busy servers */
1708 schedctl(NDPRI, 0, NDPNORMMAX);
1712 #ifndef AFS_NT40_ENV
1713 nice(-5); /* TODO: */
1716 assert(DInit(buffs) == 0);
1719 if (afs_winsockInit() < 0) {
1720 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
1721 ViceLog(0, ("File server failed to intialize winsock.\n"));
1727 /* if we support more than 16 threads, then we better have the ability
1728 ** to keep open a large number of files simultaneously
1730 #if defined(AFS_AIX_ENV) && !defined(AFS_AIX42_ENV)
1731 curLimit = OPEN_MAX; /* for pre AIX 4.2 systems */
1732 #elif defined(AFS_NT40_ENV)
1733 curLimit = NT_OPEN_MAX; /* open file descriptor limit on NT */
1736 curLimit = 0; /* the number of open file descriptors */
1737 code = getrlimit(RLIMIT_NOFILE, &rlim);
1739 curLimit = rlim.rlim_cur;
1740 rlim.rlim_cur = rlim.rlim_max;
1741 code = setrlimit(RLIMIT_NOFILE, &rlim);
1743 curLimit = rlim.rlim_max;
1746 ViceLog(0, ("Failed to increase open file limit, using default\n"));
1748 #endif /* defined(AFS_AIX_ENV) && !defined(AFS_AIX42_ENV) */
1750 curLimit -= 32; /* leave a slack of 32 file descriptors */
1751 if (lwps > curLimit) {
1755 lwps = 16; /* default to a maximum of 16 threads */
1757 ("The system supports a max of %d open files and we are starting %d threads\n",
1760 #ifndef AFS_PTHREAD_ENV
1761 assert(LWP_InitializeProcessSupport(LWP_MAX_PRIORITY - 2, &parentPid) ==
1763 #endif /* !AFS_PTHREAD_ENV */
1765 /* Initialize volume support */
1767 V_BreakVolumeCallbacks = BreakVolumeCallBacksLater;
1770 #ifdef AFS_PTHREAD_ENV
1771 SetLogThreadNumProgram( threadNum );
1774 /* initialize libacl routines */
1775 acl_Initialize(ACL_VERSION);
1777 /* initialize RX support */
1778 #ifndef AFS_NT40_ENV
1779 rxi_syscallp = viced_syscall;
1781 rx_extraPackets = rxpackets;
1782 rx_extraQuota = 4; /* for outgoing prserver calls from R threads */
1783 rx_SetBusyThreshold(busy_threshold, VBUSY);
1784 rx_SetCallAbortThreshold(abort_threshold);
1785 rx_SetConnAbortThreshold(abort_threshold);
1786 stackSize = lwps * 4000;
1787 if (stackSize < 32000)
1789 else if (stackSize > 44000)
1791 #if defined(AFS_HPUX_ENV) || defined(AFS_SUN_ENV) || defined(AFS_SGI51_ENV)
1792 rx_SetStackSize(1, stackSize);
1795 rx_SetUdpBufSize(udpBufSize); /* set the UDP buffer size for receive */
1796 if (rx_Init((int)htons(7000)) < 0) {
1797 ViceLog(0, ("Cannot initialize RX\n"));
1800 if (!rxJumbograms) {
1801 /* Don't send and don't allow 3.4 clients to send jumbograms. */
1805 rx_SetRxDeadTime(30);
1806 sc[0] = rxnull_NewServerSecurityObject();
1807 sc[1] = 0; /* rxvab_NewServerSecurityObject(key1, 0) */
1808 sc[2] = rxkad_NewServerSecurityObject(rxkad_clear, NULL, get_key, NULL);
1809 sc[3] = rxkad_NewServerSecurityObject(rxkad_crypt, NULL, get_key, NULL);
1810 tservice = rx_NewService( /* port */ 0, /* service id */ 1, /*service name */
1812 /* security classes */ sc,
1813 /* numb sec classes */
1814 4, RXAFS_ExecuteRequest);
1817 ("Failed to initialize RX, probably two servers running.\n"));
1820 rx_SetDestroyConnProc(tservice, (void (*)())h_FreeConnection);
1821 rx_SetMinProcs(tservice, 3);
1822 rx_SetMaxProcs(tservice, lwps);
1823 rx_SetCheckReach(tservice, 1);
1826 rx_NewService(0, RX_STATS_SERVICE_ID, "rpcstats", sc, 4,
1827 RXSTATS_ExecuteRequest);
1829 ViceLog(0, ("Failed to initialize rpc stat service.\n"));
1832 rx_SetMinProcs(tservice, 2);
1833 rx_SetMaxProcs(tservice, 4);
1836 * Enable RX hot threads, which allows the listener thread to trade
1837 * places with an idle thread and moves the context switch from listener
1838 * to worker out of the critical path.
1840 rx_EnableHotThread();
1842 /* Some rx debugging */
1843 if (rxlog || eventlog) {
1844 debugFile = afs_fopen("rx_dbg", "w");
1846 rx_debugFile = debugFile;
1848 rxevent_debugFile = debugFile;
1851 init_sys_error_to_et(); /* Set up error table translation */
1852 h_InitHostPackage(); /* set up local cellname and realmname */
1853 InitCallBack(numberofcbs);
1858 ViceLog(0, ("Fatal error in library initialization, exiting!!\n"));
1864 ViceLog(0, ("Fatal error in protection initialization, exiting!!\n"));
1868 /* allow super users to manage RX statistics */
1869 rx_SetRxStatUserOk(fs_rxstat_userok);
1871 rx_StartServer(0); /* now start handling requests */
1873 /* we ensure that there is enough space in the vnode buffer to satisfy
1874 ** requests from all concurrent threads.
1875 ** the maximum number of vnodes used by a single thread at any one time
1876 ** is three ( "link" uses three vnodes simultaneously, one vLarge and
1877 ** two vSmall for linking files and two vLarge and one vSmall for linking
1880 minVnodesRequired = 2 * lwps + 1;
1881 if (minVnodesRequired > nSmallVns) {
1882 nSmallVns = minVnodesRequired;
1884 ("Overriding -s command line parameter with %d\n",
1887 if (minVnodesRequired > large) {
1888 large = minVnodesRequired;
1889 ViceLog(0, ("Overriding -l command line parameter with %d\n", large));
1892 /* We now do this after getting the listener up and running, so that client
1893 * connections don't timeout (maybe) if a file server is restarted, since it
1894 * will be available "real soon now". Worry about whether we can satisfy the
1895 * calls in the volume package itself.
1897 if (VInitVolumePackage(fileServer, large, nSmallVns, 0, volcache)) {
1899 ("Shutting down: errors encountered initializing volume package\n"));
1905 * We are done calling fopen/fdopen. It is safe to use a large
1906 * of the file descriptor cache.
1910 #ifdef AFS_PTHREAD_ENV
1911 ViceLog(5, ("Starting pthreads\n"));
1912 assert(pthread_attr_init(&tattr) == 0);
1913 assert(pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED) == 0);
1915 assert(pthread_create
1916 (&serverPid, &tattr, (void *)FiveMinuteCheckLWP,
1917 &fiveminutes) == 0);
1918 assert(pthread_create
1919 (&serverPid, &tattr, (void *)HostCheckLWP, &fiveminutes) == 0);
1920 assert(pthread_create
1921 (&serverPid, &tattr, (void *)FsyncCheckLWP, &fiveminutes) == 0);
1922 #else /* AFS_PTHREAD_ENV */
1923 ViceLog(5, ("Starting LWP\n"));
1924 assert(LWP_CreateProcess
1925 (FiveMinuteCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
1926 (void *)&fiveminutes, "FiveMinuteChecks",
1927 &serverPid) == LWP_SUCCESS);
1929 assert(LWP_CreateProcess
1930 (HostCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
1931 (void *)&fiveminutes, "HostCheck", &serverPid) == LWP_SUCCESS);
1932 assert(LWP_CreateProcess
1933 (FsyncCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
1934 (void *)&fiveminutes, "FsyncCheck", &serverPid) == LWP_SUCCESS);
1935 #endif /* AFS_PTHREAD_ENV */
1937 TM_GetTimeOfDay(&tp, 0);
1939 #ifndef AFS_QUIETFS_ENV
1940 if (console != NULL) {
1941 time_t t = tp.tv_sec;
1942 fprintf(console, "File server has started at %s\r",
1943 afs_ctime(&t, tbuffer, sizeof(tbuffer)));
1948 * Figure out the FileServer's name and primary address.
1950 ViceLog(0, ("Getting FileServer name...\n"));
1951 code = gethostname(FS_HostName, 64);
1953 ViceLog(0, ("gethostname() failed\n"));
1955 ViceLog(0, ("FileServer host name is '%s'\n", FS_HostName));
1957 ViceLog(0, ("Getting FileServer address...\n"));
1958 he = gethostbyname(FS_HostName);
1960 ViceLog(0, ("Can't find address for FileServer '%s'\n", FS_HostName));
1963 memcpy(&FS_HostAddr_NBO, he->h_addr, 4);
1964 (void)afs_inet_ntoa_r(FS_HostAddr_NBO, hoststr);
1965 FS_HostAddr_HBO = ntohl(FS_HostAddr_NBO);
1967 ("FileServer %s has address %s (0x%x or 0x%x in host byte order)\n",
1968 FS_HostName, hoststr, FS_HostAddr_NBO, FS_HostAddr_HBO));
1971 /* Install handler to catch the shutdown signal;
1972 * bosserver assumes SIGQUIT shutdown
1974 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
1975 softsig_signal(SIGQUIT, ShutDown_Signal);
1977 (void)signal(SIGQUIT, ShutDown_Signal);
1982 ("File Server started %s",
1983 afs_ctime(&t, tbuffer, sizeof(tbuffer))));
1984 #if FS_STATS_DETAILED
1985 afs_FullPerfStats.det.epoch.tv_sec = StartTime = tp.tv_sec;
1987 #ifdef AFS_PTHREAD_ENV
1989 sleep(1000); /* long time */
1991 #else /* AFS_PTHREAD_ENV */
1992 assert(LWP_WaitProcess(&parentPid) == LWP_SUCCESS);
1993 #endif /* AFS_PTHREAD_ENV */