2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
9 * Portions Copyright (c) 2006 Sine Nomine Associates
12 /* viced.c - File Server main loop */
16 /* Function - This routine has the initialization code for */
19 /* ********************************************************************** */
21 #include <afsconfig.h>
22 #include <afs/param.h>
30 #include <sys/types.h>
31 #include <afs/procmgmt.h> /* signal(), kill(), wait(), etc. */
37 #include <WINNT/afsevent.h>
40 #include <netinet/in.h>
42 #include <unistd.h> /* sysconf() */
54 #endif /* ITIMER_REAL */
55 #include <sys/resource.h>
56 #endif /* AFS_NT40_ENV */
61 #ifdef AFS_PTHREAD_ENV
63 #else /* AFS_PTHREAD_ENV */
64 #include <afs/assert.h>
65 #endif /* AFS_PTHREAD_ENV */
68 #include <afs/ptclient.h>
69 #include <afs/afsint.h>
70 #include <afs/vldbint.h>
71 #include <afs/errors.h>
72 #include <afs/ihandle.h>
73 #include <afs/vnode.h>
74 #include <afs/volume.h>
76 #include <afs/cellconfig.h>
78 #include <afs/prs_fs.h>
82 #include <afs/afs_args.h>
83 #include <afs/vlserver.h>
84 #include <afs/afsutil.h>
85 #include <afs/fileutil.h>
86 #include <afs/ptuser.h>
87 #include <afs/audit.h>
88 #include <afs/partition.h>
90 #include <afs/netutils.h>
94 #ifdef AFS_PTHREAD_ENV
97 #if defined(AFS_SGI_ENV)
98 #include "sys/schedctl.h"
101 #include <rx/rx_globals.h>
104 #define afs_stat stat64
105 #define afs_fstat fstat64
106 #define afs_open open64
107 #define afs_fopen fopen64
108 #else /* !O_LARGEFILE */
109 #define afs_stat stat
110 #define afs_fstat fstat
111 #define afs_open open
112 #define afs_fopen fopen
113 #endif /* !O_LARGEFILE */
115 extern int BreakVolumeCallBacks(), InitCallBack();
116 extern int BreakVolumeCallBacks(), InitCallBack(), BreakLaterCallBacks();
117 extern int BreakVolumeCallBacksLater();
118 extern int LogLevel, etext;
119 extern afs_int32 BlocksSpare, PctSpare;
122 static void ClearXStatValues(), NewParms(), PrintCounters();
123 static void ResetCheckDescriptors(void), ResetCheckSignal(void);
124 static int CheckSignal(void);
125 extern int GetKeysFromToken();
126 extern int RXAFS_ExecuteRequest();
127 extern int RXSTATS_ExecuteRequest();
128 afs_int32 Do_VLRegisterRPC();
130 int eventlog = 0, rxlog = 0;
132 FILE *console = NULL;
134 #ifdef AFS_PTHREAD_ENV
135 pthread_mutex_t fsync_glock_mutex;
136 pthread_cond_t fsync_cond;
139 #endif /* AFS_PTHREAD_ENV */
142 #define AFS_QUIETFS_ENV 1
143 #define NT_OPEN_MAX 1024 /* This is an arbitrary no. we came up with for
144 * now. We hope this will be replaced by a more
145 * intelligent estimate later. */
148 int SystemId; /* ViceID of "Administrators" */
149 int SystemAnyUser; /* Viceid of "System:AnyUser" */
150 prlist SystemAnyUserCPS; /* CPS for "system:AnyUser */
151 int AnonymousID = 0; /* ViceId of "Anonymous" */
152 prlist AnonCPS; /* CPS for "Anonymous" */
154 struct afsconf_dir *confDir; /* Configuration dir object */
156 int restartMode = RESTART_ORDINARY;
158 int Testing = 0; /* for ListViceInodes */
161 * Home for the performance statistics.
163 struct afs_PerfStats afs_perfstats;
166 extern int Statistics;
174 int rxJumbograms = 1; /* default is to send and receive jumbograms. */
176 afs_int32 implicitAdminRights = PRSFS_LOOKUP; /* The ADMINISTER right is
178 afs_int32 readonlyServer = 0;
181 int stackSize = 24000;
182 int fiveminutes = 300; /* 5 minutes. Change this for debugging only */
183 int CurrentConnections = 0;
184 int hostaclRefresh = 7200; /* refresh host clients' acls every 2 hrs */
185 #if defined(AFS_SGI_ENV)
190 int rxpackets = 150; /* 100 */
191 int nSmallVns = 400; /* 200 */
192 int large = 400; /* 200 */
193 int volcache = 400; /* 400 */
194 int numberofcbs = 60000; /* 60000 */
195 int lwps = 9; /* 6 */
196 int buffs = 90; /* 70 */
197 int novbc = 0; /* Enable Volume Break calls */
198 int busy_threshold = 600;
199 int abort_threshold = 10;
200 int udpBufSize = 0; /* UDP buffer size for receive */
201 int sendBufSize = 16384; /* send buffer size */
206 * FileServer's name and IP address, both network byte order and
209 #define ADDRSPERSITE 16 /* Same global is in rx/rx_user.c */
211 char FS_HostName[128] = "localhost";
212 afs_uint32 FS_HostAddr_NBO;
213 afs_uint32 FS_HostAddr_HBO;
214 afs_uint32 FS_HostAddrs[ADDRSPERSITE], FS_HostAddr_cnt = 0, FS_registered = 0;
215 /* All addresses in FS_HostAddrs are in NBO */
218 static void FlagMsg();
220 #ifdef AFS_DEMAND_ATTACH_FS
223 * fileserver mode support
225 * during fileserver shutdown, we have to track the graceful shutdown of
226 * certain background threads before we are allowed to dump state to
229 struct fs_state fs_state =
236 PTHREAD_COND_INITIALIZER,
237 PTHREAD_RWLOCK_INITIALIZER
239 #endif /* AFS_DEMAND_ATTACH_FS */
242 * Home for the performance statistics.
250 struct afs_stat status;
251 register int tsize = getdtablesize();
253 for (i = 0; i < tsize; i++) {
254 if (afs_fstat(i, &status) != -1) {
255 printf("%d: dev %x, inode %u, length %u, type/mode %x\n", i,
256 status.st_dev, status.st_ino, status.st_size,
261 ResetCheckDescriptors();
264 } /*CheckDescriptors */
267 #ifdef AFS_PTHREAD_ENV
269 CheckSignal_Signal(x)
281 CheckDescriptors_Signal(x)
285 #else /* AFS_PTHREAD_ENV */
287 CheckSignal_Signal(x)
289 IOMGR_SoftSig(CheckSignal, 0);
295 IOMGR_SoftSig(ShutDown, 0);
299 CheckDescriptors_Signal(x)
301 IOMGR_SoftSig(CheckDescriptors, 0);
303 #endif /* AFS_PTHREAD_ENV */
305 /* check whether caller is authorized to manage RX statistics */
307 fs_rxstat_userok(struct rx_call *call)
309 return afsconf_SuperUser(confDir, call, NULL);
313 ResetCheckSignal(void)
317 #if defined(AFS_HPUX_ENV)
320 #if defined(AFS_NT40_ENV)
327 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
328 softsig_signal(signo, CheckSignal_Signal);
330 signal(signo, CheckSignal_Signal);
335 ResetCheckDescriptors(void)
338 #if defined(AFS_PTHREAD_ENV)
339 softsig_signal(SIGTERM, CheckDescriptors_Signal);
341 (void)signal(SIGTERM, CheckDescriptors_Signal);
346 #if defined(AFS_PTHREAD_ENV)
350 return pthread_getspecific(rx_thread_id_key);
354 /* proc called by rxkad module to get a key */
356 get_key(char *arock, register afs_int32 akvno, char *akey)
359 static struct afsconf_key tkey;
360 register afs_int32 code;
363 ViceLog(0, ("conf dir not open\n"));
366 code = afsconf_GetKey(confDir, akvno, tkey.key);
368 ViceLog(0, ("afsconf_GetKey failure: kvno %d code %d\n", akvno, code));
371 memcpy(akey, tkey.key, sizeof(tkey.key));
378 viced_syscall(afs_uint32 a3, afs_uint32 a4, void *a5)
383 #ifndef AFS_LINUX20_ENV
384 old = (void (*)())signal(SIGSYS, SIG_IGN);
386 rcode = syscall(AFS_SYSCALL, 28 /* AFSCALL_CALL */ , a3, a4, a5);
387 #ifndef AFS_LINUX20_ENV
395 #if !defined(AFS_NT40_ENV)
396 #include "AFS_component_version_number.c"
397 #endif /* !AFS_NT40_ENV */
399 #define MAXADMINNAME 64
400 char adminName[MAXADMINNAME];
406 struct afs_stat status;
408 if ((afs_stat("/AdminName", &status)) || /* if file does not exist */
409 (status.st_size <= 0) || /* or it is too short */
410 (status.st_size >= (MAXADMINNAME)) || /* or it is too long */
411 !(fd = afs_open("/AdminName", O_RDONLY, 0))) { /* or the open fails */
412 strcpy(adminName, "System:Administrators"); /* use the default name */
414 (void)read(fd, adminName, status.st_size); /* use name from the file */
417 close(fd); /* close fd if it was opened */
419 } /*CheckAdminName */
425 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
426 /* set our 'thread-id' so that the host hold table works */
427 MUTEX_ENTER(&rx_stats_mutex); /* protects rxi_pthread_hinum */
429 pthread_setspecific(rx_thread_id_key, (void *)rxi_pthread_hinum);
430 MUTEX_EXIT(&rx_stats_mutex);
432 ("Set thread id %d for '%s'\n",
433 pthread_getspecific(rx_thread_id_key), s));
437 /* This LWP does things roughly every 5 minutes */
444 ViceLog(1, ("Starting five minute check process\n"));
445 setThreadId("FiveMinuteCheckLWP");
447 #ifdef AFS_DEMAND_ATTACH_FS
449 while (fs_state.mode == FS_MODE_NORMAL) {
450 fs_state.FiveMinuteLWP_tranquil = 1;
456 #ifdef AFS_PTHREAD_ENV
458 #else /* AFS_PTHREAD_ENV */
459 IOMGR_Sleep(fiveminutes);
460 #endif /* AFS_PTHREAD_ENV */
462 #ifdef AFS_DEMAND_ATTACH_FS
464 if (fs_state.mode != FS_MODE_NORMAL) {
467 fs_state.FiveMinuteLWP_tranquil = 0;
471 /* close the log so it can be removed */
472 ReOpenLog(AFSDIR_SERVER_FILELOG_FILEPATH); /* don't trunc, just append */
473 ViceLog(2, ("Cleaning up timed out callbacks\n"));
474 if (CleanupTimedOutCallBacks())
475 ViceLog(5, ("Timed out callbacks deleted\n"));
476 ViceLog(2, ("Set disk usage statistics\n"));
478 if (FS_registered == 1)
480 /* Force wakeup in case we missed something; pthreads does timedwait */
481 #ifndef AFS_PTHREAD_ENV
482 LWP_NoYieldSignal(fsync_wait);
484 if (printBanner && (++msg & 1)) { /* Every 10 minutes */
485 time_t now = FT_ApproxTime();
486 if (console != NULL) {
487 #ifndef AFS_QUIETFS_ENV
488 fprintf(console, "File server is running at %s\r",
489 afs_ctime(&now, tbuffer, sizeof(tbuffer)));
490 #endif /* AFS_QUIETFS_ENV */
492 ("File server is running at %s\n",
493 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
496 #ifdef AFS_DEMAND_ATTACH_FS
500 #ifdef AFS_DEMAND_ATTACH_FS
501 fs_state.FiveMinuteLWP_tranquil = 1;
503 assert(pthread_cond_broadcast(&fs_state.worker_done_cv)==0);
507 } /*FiveMinuteCheckLWP */
510 /* This LWP does host checks every 5 minutes: it should not be used for
511 * other 5 minute activities because it may be delayed by timeouts when
512 * it probes the workstations
518 ViceLog(1, ("Starting Host check process\n"));
519 setThreadId("HostCheckLWP");
520 #ifdef AFS_DEMAND_ATTACH_FS
522 while (fs_state.mode == FS_MODE_NORMAL) {
523 fs_state.HostCheckLWP_tranquil = 1;
529 #ifdef AFS_PTHREAD_ENV
531 #else /* AFS_PTHREAD_ENV */
532 IOMGR_Sleep(fiveminutes);
533 #endif /* AFS_PTHREAD_ENV */
535 #ifdef AFS_DEMAND_ATTACH_FS
537 if (fs_state.mode != FS_MODE_NORMAL) {
540 fs_state.HostCheckLWP_tranquil = 0;
544 ViceLog(2, ("Checking for dead venii & clients\n"));
547 #ifdef AFS_DEMAND_ATTACH_FS
551 #ifdef AFS_DEMAND_ATTACH_FS
552 fs_state.HostCheckLWP_tranquil = 1;
554 assert(pthread_cond_broadcast(&fs_state.worker_done_cv)==0);
560 /* This LWP does fsync checks every 5 minutes: it should not be used for
561 * other 5 minute activities because it may be delayed by timeouts when
562 * it probes the workstations
568 #ifdef AFS_PTHREAD_ENV
569 struct timespec fsync_next;
571 ViceLog(1, ("Starting fsync check process\n"));
573 setThreadId("FsyncCheckLWP");
575 #ifdef AFS_PTHREAD_ENV
576 assert(pthread_cond_init(&fsync_cond, NULL) == 0);
577 assert(pthread_mutex_init(&fsync_glock_mutex, NULL) == 0);
580 #ifdef AFS_DEMAND_ATTACH_FS
582 while (fs_state.mode == FS_MODE_NORMAL) {
583 fs_state.FsyncCheckLWP_tranquil = 1;
589 #ifdef AFS_PTHREAD_ENV
590 /* rounding is fine */
591 fsync_next.tv_nsec = 0;
592 fsync_next.tv_sec = time(0) + fiveminutes;
595 pthread_cond_timedwait(&fsync_cond, &fsync_glock_mutex,
597 if (code != 0 && code != ETIMEDOUT)
598 ViceLog(0, ("pthread_cond_timedwait returned %d\n", code));
599 #else /* AFS_PTHREAD_ENV */
600 if ((code = LWP_WaitProcess(fsync_wait)) != LWP_SUCCESS)
601 ViceLog(0, ("LWP_WaitProcess returned %d\n", code));
602 #endif /* AFS_PTHREAD_ENV */
605 #ifdef AFS_DEMAND_ATTACH_FS
607 if (fs_state.mode != FS_MODE_NORMAL) {
610 fs_state.FsyncCheckLWP_tranquil = 0;
612 #endif /* AFS_DEMAND_ATTACH_FS */
614 ViceLog(2, ("Checking for fsync events\n"));
616 code = BreakLaterCallBacks();
618 #ifdef AFS_DEMAND_ATTACH_FS
622 #ifdef AFS_DEMAND_ATTACH_FS
623 fs_state.FsyncCheckLWP_tranquil = 1;
625 assert(pthread_cond_broadcast(&fs_state.worker_done_cv)==0);
628 #endif /* AFS_DEMAND_ATTACH_FS */
631 /*------------------------------------------------------------------------
632 * PRIVATE ClearXStatValues
635 * Initialize all of the values collected via the xstat
645 * Must be called during File Server initialization.
649 *------------------------------------------------------------------------*/
653 { /*ClearXStatValues */
655 struct fs_stats_opTimingData *opTimeP; /*Ptr to timing struct */
656 struct fs_stats_xferData *opXferP; /*Ptr to xfer struct */
657 int i; /*Loop counter */
660 * Zero all xstat-related structures.
662 memset((char *)(&afs_perfstats), 0, sizeof(struct afs_PerfStats));
663 #if FS_STATS_DETAILED
664 memset((char *)(&afs_FullPerfStats), 0,
665 sizeof(struct fs_stats_FullPerfStats));
668 * That's not enough. We have to set reasonable minima for
669 * time and xfer values in the detailed stats.
671 opTimeP = &(afs_FullPerfStats.det.rpcOpTimes[0]);
672 for (i = 0; i < FS_STATS_NUM_RPC_OPS; i++, opTimeP++)
673 opTimeP->minTime.tv_sec = 999999;
675 opXferP = &(afs_FullPerfStats.det.xferOpTimes[0]);
676 for (i = 0; i < FS_STATS_NUM_XFER_OPS; i++, opXferP++) {
677 opXferP->minTime.tv_sec = 999999;
678 opXferP->minBytes = 999999999;
682 * There's more. We have to set our unique system identifier, as
683 * declared in param.h. If such a thing is not defined, we bitch
684 * and declare ourselves to be an unknown system type.
687 afs_perfstats.sysname_ID = SYS_NAME_ID;
690 ViceLog(0, ("Sys name ID constant not defined in param.h!!\n"));
691 ViceLog(0, ("[Choosing ``undefined'' sys name ID.\n"));
693 afs_perfstats.sysname_ID = SYS_NAME_ID_UNDEFINED;
694 #endif /* SYS_NAME_ID */
697 } /*ClearXStatValues */
703 int dirbuff, dircall, dirio;
705 int workstations, activeworkstations, delworkstations;
709 TM_GetTimeOfDay(&tpl, 0);
712 ("Vice was last started at %s\n",
713 afs_ctime(&StartTime, tbuffer, sizeof(tbuffer))));
715 #ifdef AFS_DEMAND_ATTACH_FS
716 /* XXX perhaps set extended stats verbosity flags
717 * based upon LogLevel ?? */
718 VPrintExtendedCacheStats(VOL_STATS_PER_CHAIN2);
722 DStat(&dirbuff, &dircall, &dirio);
724 ("With %d directory buffers; %d reads resulted in %d read I/Os\n",
725 dirbuff, dircall, dirio));
726 rx_PrintStats(stderr);
728 PrintCallBackStats();
730 processSize = -1; /* TODO: */
732 processSize = (int)((long)sbrk(0) >> 10);
735 ("There are %d connections, process size %d\n",
736 CurrentConnections, processSize));
737 h_GetWorkStats(&workstations, &activeworkstations, &delworkstations,
738 tpl.tv_sec - 15 * 60);
740 ("There are %d workstations, %d are active (req in < 15 mins), %d marked \"down\"\n",
741 workstations, activeworkstations, delworkstations));
751 if (FS_registered > 0) {
753 * We have proper ip addresses; tell the vlserver what we got; the following
754 * routine will do the proper reporting for us
767 ShutDownAndCore(int dopanic)
769 time_t now = time(0);
772 /* do not allows new reqests to be served from now on, all new requests
773 * are returned with an error code of RX_RESTARTING ( transient failure ) */
774 rx_SetRxTranquil(); /* dhruba */
776 #ifdef AFS_DEMAND_ATTACH_FS
778 fs_state.mode = FS_MODE_SHUTDOWN;
783 ("Shutting down file server at %s",
784 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
786 ViceLog(0, ("ABNORMAL SHUTDOWN, see core file.\n"));
787 #ifndef AFS_QUIETFS_ENV
788 if (console != NULL) {
789 fprintf(console, "File server restart/shutdown received at %s\r",
790 afs_ctime(&now, tbuffer, sizeof(tbuffer)));
797 /* shut down volume package */
800 #ifdef AFS_DEMAND_ATTACH_FS
801 if (fs_state.options.fs_state_save) {
804 * save fileserver state to disk */
806 /* make sure background threads have finished all of their asynchronous
807 * work on host and callback structures */
809 while (!fs_state.FiveMinuteLWP_tranquil ||
810 !fs_state.HostCheckLWP_tranquil ||
811 !fs_state.FsyncCheckLWP_tranquil) {
814 ViceLog(0, ("waiting for background host/callback threads to quiesce before saving fileserver state...\n"));
815 assert(pthread_cond_wait(&fs_state.worker_done_cv, &fileproc_glock_mutex) == 0);
820 /* ok. it should now be fairly safe. let's do the state dump */
823 #endif /* AFS_DEMAND_ATTACH_FS */
826 rx_PrintStats(debugFile);
829 if (console != NULL) {
832 #ifndef AFS_QUIETFS_ENV
833 fprintf(console, "File server has terminated abnormally at %s\r",
834 afs_ctime(&now, tbuffer, sizeof(tbuffer)));
837 ("File server has terminated abnormally at %s\n",
838 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
840 #ifndef AFS_QUIETFS_ENV
841 fprintf(console, "File server has terminated normally at %s\r",
842 afs_ctime(&now, tbuffer, sizeof(tbuffer)));
845 ("File server has terminated normally at %s\n",
846 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
855 { /* backward compatibility */
856 ShutDownAndCore(DONTPANIC);
866 /* default supports help flag */
868 strcpy(buffer, "Usage: fileserver ");
869 strcpy(buffer, "[-auditlog <log path>] ");
870 strcat(buffer, "[-d <debug level>] ");
871 strcat(buffer, "[-p <number of processes>] ");
872 strcat(buffer, "[-spare <number of spare blocks>] ");
873 strcat(buffer, "[-pctspare <percentage spare>] ");
874 strcat(buffer, "[-b <buffers>] ");
875 strcat(buffer, "[-l <large vnodes>] ");
876 strcat(buffer, "[-s <small vnodes>] ");
877 strcat(buffer, "[-vc <volume cachesize>] ");
878 strcat(buffer, "[-w <call back wait interval>] ");
879 strcat(buffer, "[-cb <number of call backs>] ");
880 strcat(buffer, "[-banner (print banner every 10 minutes)] ");
881 strcat(buffer, "[-novbc (whole volume cbs disabled)] ");
882 strcat(buffer, "[-implicit <admin mode bits: rlidwka>] ");
883 strcat(buffer, "[-readonly (read-only file server)] ");
885 "[-hr <number of hours between refreshing the host cps>] ");
886 strcat(buffer, "[-busyat <redirect clients when queue > n>] ");
887 strcat(buffer, "[-nobusy <no VBUSY before a volume is attached>] ");
888 strcat(buffer, "[-rxpck <number of rx extra packets>] ");
889 strcat(buffer, "[-rxdbg (enable rx debugging)] ");
890 strcat(buffer, "[-rxdbge (enable rxevent debugging)] ");
891 strcat(buffer, "[-rxmaxmtu <bytes>] ");
892 #ifdef AFS_DEMAND_ATTACH_FS
893 strcat(buffer, "[-fs-state-dont-save (disable state save during shutdown)] ");
894 strcat(buffer, "[-fs-state-dont-restore (disable state restore during startup)] ");
895 strcat(buffer, "[-fs-state-verify <none|save|restore|both> (default is both)] ");
896 strcat(buffer, "[-vattachpar <max number of volume attach/shutdown threads> (default is 1)] ");
897 strcat(buffer, "[-vhashsize <log(2) of number of volume hash buckets> (default is 8)] ");
898 strcat(buffer, "[-vlrudisable (disable VLRU functionality)] ");
899 strcat(buffer, "[-vlruthresh <minutes before unused volumes become eligible for soft detach> (default is 2 hours)] ");
900 strcat(buffer, "[-vlruinterval <seconds between VLRU scans> (default is 2 minutes)] ");
901 strcat(buffer, "[-vlrumax <max volumes to soft detach in one VLRU scan> (default is 8)] ");
902 #elif AFS_PTHREAD_ENV
903 strcat(buffer, "[-vattachpar <number of volume attach threads> (default is 1)] ");
906 strcat(buffer, "[-m <min percentage spare in partition>] ");
908 #if defined(AFS_SGI_ENV)
909 strcat(buffer, "[-lock (keep fileserver from swapping)] ");
911 strcat(buffer, "[-L (large server conf)] ");
912 strcat(buffer, "[-S (small server conf)] ");
913 strcat(buffer, "[-k <stack size>] ");
914 strcat(buffer, "[-realm <Kerberos realm name>] ");
915 strcat(buffer, "[-udpsize <size of socket buffer in bytes>] ");
916 strcat(buffer, "[-sendsize <size of send buffer in bytes>] ");
917 strcat(buffer, "[-abortthreshold <abort threshold>] ");
918 /* strcat(buffer, "[-enable_peer_stats] "); */
919 /* strcat(buffer, "[-enable_process_stats] "); */
920 strcat(buffer, "[-help]\n");
922 ViceLog(0, ("%s", buffer));
925 printf("%s", buffer);
932 ParseRights(char *arights)
938 if (!arights || !strcmp(arights, "")) {
939 printf("Missing list of mode bits on -implicit option\n");
942 if (!strcmp(arights, "none"))
944 else if (!strcmp(arights, "read"))
945 mode = PRSFS_READ | PRSFS_LOOKUP;
946 else if (!strcmp(arights, "write"))
948 PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
949 PRSFS_WRITE | PRSFS_LOCK;
950 else if (!strcmp(arights, "all"))
952 PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
953 PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER;
955 len = strlen(arights);
956 for (i = 0; i < len; i++) {
961 mode |= PRSFS_LOOKUP;
963 mode |= PRSFS_INSERT;
965 mode |= PRSFS_DELETE;
971 mode |= PRSFS_ADMINISTER;
989 printf("Illegal -implicit rights character '%c'.\n", tc);
998 * Limit MAX_FILESERVER_THREAD by the system limit on the number of
999 * pthreads (sysconf(_SC_THREAD_THREADS_MAX)), if applicable and
1002 * AIX: sysconf() limit is real
1003 * HP-UX: sysconf() limit is real
1004 * IRIX: sysconf() limit is apparently NOT real -- too small
1005 * DUX: sysconf() limit is apparently NOT real -- too big
1006 * Linux: sysconf() limit is apparently NOT real -- too big
1007 * Solaris: no sysconf() limit
1010 max_fileserver_thread(void)
1012 #if defined(AFS_PTHREAD_ENV)
1013 #if defined(AFS_AIX_ENV) || defined(AFS_HPUX_ENV)
1016 ans = sysconf(_SC_THREAD_THREADS_MAX);
1017 if (0 < ans && ans < MAX_FILESERVER_THREAD)
1020 #endif /* defined(AFS_PTHREAD_ENV) */
1021 return MAX_FILESERVER_THREAD;
1025 ParseArgs(int argc, char *argv[])
1027 int SawL = 0, SawS = 0, SawVC = 0;
1028 int Sawrxpck = 0, Sawsmall = 0, Sawlarge = 0, Sawcbs = 0, Sawlwps =
1032 int bufSize = 0; /* temp variable to read in udp socket buf size */
1034 for (i = 1; i < argc; i++) {
1035 if (!strcmp(argv[i], "-d")) {
1036 if ((i + 1) >= argc) {
1037 fprintf(stderr, "missing argument for -d\n");
1040 debuglevel = atoi(argv[++i]);
1041 LogLevel = debuglevel;
1042 } else if (!strcmp(argv[i], "-banner")) {
1044 } else if (!strcmp(argv[i], "-implicit")) {
1045 if ((i + 1) >= argc) {
1046 fprintf(stderr, "missing argument for -implicit\n");
1049 implicitAdminRights = ParseRights(argv[++i]);
1050 if (implicitAdminRights < 0)
1051 return implicitAdminRights;
1052 } else if (!strcmp(argv[i], "-readonly")) {
1054 } else if (!strcmp(argv[i], "-L")) {
1056 } else if (!strcmp(argv[i], "-S")) {
1058 } else if (!strcmp(argv[i], "-p")) {
1060 max_fileserver_thread() - FILESERVER_HELPER_THREADS;
1062 if ((i + 1) >= argc) {
1063 fprintf(stderr, "missing argument for -p\n");
1066 lwps = atoi(argv[++i]);
1067 if (lwps > lwps_max)
1071 } else if (!strcmp(argv[i], "-b")) {
1073 if ((i + 1) >= argc) {
1074 fprintf(stderr, "missing argument for -b\n");
1077 buffs = atoi(argv[++i]);
1078 } else if (!strcmp(argv[i], "-l")) {
1080 if ((i + 1) >= argc) {
1081 fprintf(stderr, "missing argument for -l\n");
1084 large = atoi(argv[++i]);
1085 } else if (!strcmp(argv[i], "-vc")) {
1087 if ((i + 1) >= argc) {
1088 fprintf(stderr, "missing argument for -vc\n");
1091 volcache = atoi(argv[++i]);
1092 } else if (!strcmp(argv[i], "-novbc")) {
1094 } else if (!strcmp(argv[i], "-rxpck")) {
1096 if ((i + 1) >= argc) {
1097 fprintf(stderr, "missing argument for -rxpck\n");
1100 rxpackets = atoi(argv[++i]);
1101 #ifdef AFS_PTHREAD_ENV
1102 } else if (!strcmp(argv[i], "-vattachpar")) {
1103 if ((i + 1) >= argc) {
1104 fprintf(stderr, "missing argument for %s\n", argv[i]);
1107 vol_attach_threads = atoi(argv[++i]);
1108 #endif /* AFS_PTHREAD_ENV */
1109 #ifdef AFS_DEMAND_ATTACH_FS
1110 } else if (!strcmp(argv[i], "-fs-state-dont-save")) {
1111 fs_state.options.fs_state_save = 0;
1112 } else if (!strcmp(argv[i], "-fs-state-dont-restore")) {
1113 fs_state.options.fs_state_restore = 0;
1114 } else if (!strcmp(argv[i], "-fs-state-verify")) {
1115 if ((i + 1) >= argc) {
1116 fprintf(stderr, "missing argument for %s\n", argv[i]);
1120 if (!strcmp(argv[i], "none")) {
1121 fs_state.options.fs_state_verify_before_save = 0;
1122 fs_state.options.fs_state_verify_after_restore = 0;
1123 } else if (!strcmp(argv[i], "save")) {
1124 fs_state.options.fs_state_verify_after_restore = 0;
1125 } else if (!strcmp(argv[i], "restore")) {
1126 fs_state.options.fs_state_verify_before_save = 0;
1127 } else if (!strcmp(argv[i], "both")) {
1130 fprintf(stderr, "invalid argument for %s\n", argv[i-1]);
1133 } else if (!strcmp(argv[i], "-vhashsize")) {
1134 if ((i + 1) >= argc) {
1135 fprintf(stderr, "missing argument for %s\n", argv[i]);
1138 VSetVolHashSize(atoi(argv[++i]));
1139 } else if (!strcmp(argv[i], "-vlrudisable")) {
1140 VLRU_SetOptions(VLRU_SET_ENABLED, 0);
1141 } else if (!strcmp(argv[i], "-vlruthresh")) {
1142 if ((i + 1) >= argc) {
1143 fprintf(stderr, "missing argument for %s\n", argv[i]);
1146 VLRU_SetOptions(VLRU_SET_THRESH, 60*atoi(argv[++i]));
1147 } else if (!strcmp(argv[i], "-vlruinterval")) {
1148 if ((i + 1) >= argc) {
1149 fprintf(stderr, "missing argument for %s\n", argv[i]);
1152 VLRU_SetOptions(VLRU_SET_INTERVAL, atoi(argv[++i]));
1153 } else if (!strcmp(argv[i], "-vlrumax")) {
1154 if ((i + 1) >= argc) {
1155 fprintf(stderr, "missing argument for %s\n", argv[i]);
1158 VLRU_SetOptions(VLRU_SET_MAX, atoi(argv[++i]));
1159 #endif /* AFS_DEMAND_ATTACH_FS */
1160 } else if (!strcmp(argv[i], "-s")) {
1162 if ((i + 1) >= argc) {
1163 fprintf(stderr, "missing argument for -s\n");
1166 nSmallVns = atoi(argv[++i]);
1167 } else if (!strcmp(argv[i], "-abortthreshold")) {
1168 if ((i + 1) >= argc) {
1169 fprintf(stderr, "missing argument for -abortthreshold\n");
1172 abort_threshold = atoi(argv[++i]);
1173 } else if (!strcmp(argv[i], "-k")) {
1174 if ((i + 1) >= argc) {
1175 fprintf(stderr, "missing argument for -k\n");
1178 stack = atoi(argv[++i]);
1180 #if defined(AFS_SGI_ENV)
1181 else if (!strcmp(argv[i], "-lock")) {
1185 else if (!strcmp(argv[i], "-spare")) {
1186 if ((i + 1) >= argc) {
1187 fprintf(stderr, "missing argument for -spare\n");
1190 BlocksSpare = atoi(argv[++i]);
1192 } else if (!strcmp(argv[i], "-pctspare")) {
1193 if ((i + 1) >= argc) {
1194 fprintf(stderr, "missing argument for -pctspare\n");
1197 PctSpare = atoi(argv[++i]);
1198 BlocksSpare = 0; /* has non-zero default */
1200 } else if (!strcmp(argv[i], "-w")) {
1201 if ((i + 1) >= argc) {
1202 fprintf(stderr, "missing argument for -w\n");
1205 fiveminutes = atoi(argv[++i]);
1206 } else if (!strcmp(argv[i], "-hr")) {
1208 if ((i + 1) >= argc) {
1209 fprintf(stderr, "missing argument for -hr\n");
1212 hr = atoi(argv[++i]);
1213 if ((hr < 1) || (hr > 36)) {
1215 ("host acl refresh interval of %d hours is invalid; hours must be between 1 and 36\n\n",
1219 hostaclRefresh = hr * 60 * 60;
1220 } else if (!strcmp(argv[i], "-rxdbg"))
1222 else if (!strcmp(argv[i], "-rxdbge"))
1224 else if (!strcmp(argv[i], "-cb")) {
1226 if ((i + 1) >= argc) {
1227 fprintf(stderr, "missing argument for -cb\n");
1230 numberofcbs = atoi(argv[++i]);
1231 if ((numberofcbs < 10000) || (numberofcbs > 2147483647)) {
1233 ("number of cbs %d invalid; must be between 10000 and 2147483647\n",
1237 } else if (!strcmp(argv[i], "-busyat")) {
1239 if ((i + 1) >= argc) {
1240 fprintf(stderr, "missing argument for -busyat\n");
1243 busy_threshold = atoi(argv[++i]);
1244 if (busy_threshold < 10) {
1246 ("Busy threshold %d is too low, will compute default.\n",
1250 } else if (!strcmp(argv[i], "-nobusy"))
1252 #ifdef AFS_AIX32_ENV
1253 else if (!strcmp(argv[i], "-m")) {
1254 extern int aixlow_water;
1255 if ((i + 1) >= argc) {
1256 fprintf(stderr, "missing argument for -m\n");
1259 aixlow_water = atoi(argv[++i]);
1260 if ((aixlow_water < 0) || (aixlow_water > 30)) {
1261 printf("space reserved %d% invalid; must be between 0-30%\n",
1267 else if (!strcmp(argv[i], "-nojumbo")) {
1269 } else if (!strcmp(argv[i], "-rxmaxmtu")) {
1270 if ((i + 1) >= argc) {
1271 fprintf(stderr, "missing argument for -rxmaxmtu\n");
1274 rxMaxMTU = atoi(argv[++i]);
1275 if ((rxMaxMTU < RX_MIN_PACKET_SIZE) ||
1276 (rxMaxMTU > RX_MAX_PACKET_DATA_SIZE)) {
1277 printf("rxMaxMTU %d%% invalid; must be between %d-%d\n",
1278 rxMaxMTU, RX_MIN_PACKET_SIZE,
1279 RX_MAX_PACKET_DATA_SIZE);
1282 } else if (!strcmp(argv[i], "-realm")) {
1283 extern char local_realms[AFS_NUM_LREALMS][AFS_REALM_SZ];
1284 extern int num_lrealms;
1285 if ((i + 1) >= argc) {
1286 fprintf(stderr, "missing argument for -realm\n");
1289 if (strlen(argv[++i]) >= AFS_REALM_SZ) {
1291 ("-realm argument must contain fewer than %d characters.\n",
1295 if (num_lrealms == -1)
1297 if (num_lrealms >= AFS_NUM_LREALMS) {
1299 ("a maximum of %d -realm arguments can be specified.\n",
1303 strncpy(local_realms[num_lrealms++], argv[i], AFS_REALM_SZ);
1304 } else if (!strcmp(argv[i], "-udpsize")) {
1305 if ((i + 1) >= argc) {
1306 printf("You have to specify -udpsize <integer value>\n");
1309 bufSize = atoi(argv[++i]);
1310 if (bufSize < rx_GetMinUdpBufSize())
1312 ("Warning:udpsize %d is less than minimum %d; ignoring\n",
1313 bufSize, rx_GetMinUdpBufSize());
1315 udpBufSize = bufSize;
1316 } else if (!strcmp(argv[i], "-sendsize")) {
1317 if ((i + 1) >= argc) {
1318 printf("You have to specify -sendsize <integer value>\n");
1321 bufSize = atoi(argv[++i]);
1322 if (bufSize < 16384)
1324 ("Warning:sendsize %d is less than minimum %d; ignoring\n",
1327 sendBufSize = bufSize;
1328 } else if (!strcmp(argv[i], "-enable_peer_stats")) {
1329 rx_enablePeerRPCStats();
1330 } else if (!strcmp(argv[i], "-enable_process_stats")) {
1331 rx_enableProcessRPCStats();
1333 else if (strcmp(argv[i], "-auditlog") == 0) {
1336 char oldName[MAXPATHLEN];
1337 char *fileName = argv[++i];
1339 #ifndef AFS_NT40_ENV
1340 struct stat statbuf;
1342 if ((lstat(fileName, &statbuf) == 0)
1343 && (S_ISFIFO(statbuf.st_mode))) {
1344 flags = O_WRONLY | O_NONBLOCK;
1348 strcpy(oldName, fileName);
1349 strcat(oldName, ".old");
1350 renamefile(fileName, oldName);
1351 flags = O_WRONLY | O_TRUNC | O_CREAT;
1353 tempfd = open(fileName, flags, 0666);
1355 auditout = fdopen(tempfd, "a");
1357 osi_audit_file(auditout);
1359 printf("Warning: auditlog %s not writable, ignored.\n", fileName);
1361 printf("Warning: auditlog %s not writable, ignored.\n", fileName);
1363 #ifndef AFS_NT40_ENV
1364 else if (strcmp(argv[i], "-syslog") == 0) {
1365 /* set syslog logging flag */
1366 serverLogSyslog = 1;
1367 } else if (strncmp(argv[i], "-syslog=", 8) == 0) {
1368 serverLogSyslog = 1;
1369 serverLogSyslogFacility = atoi(argv[i] + 8);
1372 else if (strcmp(argv[i], "-mrafslogs") == 0) {
1373 /* set syslog logging flag */
1381 printf("Only one of -L, or -S must be specified\n");
1392 numberofcbs = 20000;
1408 numberofcbs = 64000;
1417 busy_threshold = 3 * rxpackets / 2;
1427 NewParms(int initializing)
1429 static struct afs_stat sbuf;
1432 char *argv[MAXPARMS];
1435 if (!(afs_stat("/vice/file/parms", &sbuf))) {
1436 parms = (char *)malloc(sbuf.st_size);
1439 fd = afs_open("parms", O_RDONLY, 0666);
1441 ViceLog(0, ("Open for parms failed with errno = %d\n", errno));
1445 i = read(fd, parms, sbuf.st_size);
1447 if (i != sbuf.st_size) {
1449 ViceLog(0, ("Read on parms failed with errno = %d\n", errno));
1452 ("Read on parms failed; expected %d bytes but read %d\n",
1459 for (i = 0; i < MAXPARMS; argv[i++] = 0);
1461 for (argc = i = 0; i < sbuf.st_size; i++) {
1462 if ((*(parms + i) != ' ') && (*(parms + i) != '\n')) {
1463 if (argv[argc] == 0)
1464 argv[argc] = (parms + i);
1466 *(parms + i) = '\0';
1467 if (argv[argc] != 0) {
1468 if (++argc == MAXPARMS)
1471 while ((*(parms + i + 1) == ' ')
1472 || (*(parms + i + 1) == '\n'))
1476 if (ParseArgs(argc, argv) == 0) {
1477 ViceLog(0, ("Change parameters to:"));
1479 ViceLog(0, ("Invalid parameter in:"));
1481 for (i = 0; i < argc; i++) {
1482 ViceLog(0, (" %s", argv[i]));
1486 } else if (!initializing)
1488 ("Received request to change parms but no parms file exists\n"));
1493 /* Miscellaneous routines */
1497 ViceLog(0, ("%s\n", msg));
1509 * If this fails, it's because something major is wrong, and is not
1510 * likely to be time dependent.
1512 code = pr_Initialize(2, AFSDIR_SERVER_ETC_DIRPATH, 0);
1515 ("Couldn't initialize protection library; code=%d.\n", code));
1518 SystemId = SYSADMINID;
1519 SystemAnyUser = ANYUSERID;
1520 SystemAnyUserCPS.prlist_len = 0;
1521 SystemAnyUserCPS.prlist_val = NULL;
1522 AnonCPS.prlist_len = 0;
1523 AnonCPS.prlist_val = NULL;
1525 code = pr_GetCPS(SystemAnyUser, &SystemAnyUserCPS);
1528 ("Couldn't get CPS for AnyUser, will try again in 30 seconds; code=%d.\n",
1532 code = pr_GetCPS(ANONYMOUSID, &AnonCPS);
1535 ("Couldn't get Anonymous CPS, exiting; code=%d.\n",
1539 AnonymousID = ANONYMOUSID;
1542 #ifdef AFS_PTHREAD_ENV
1544 #else /* AFS_PTHREAD_ENV */
1546 #endif /* AFS_PTHREAD_ENV */
1550 struct rx_connection *serverconns[MAXSERVERS];
1551 struct ubik_client *cstruct;
1554 vl_Initialize(const char *confDir)
1556 afs_int32 code, scIndex = 0, i;
1557 struct afsconf_dir *tdir;
1558 struct rx_securityClass *sc;
1559 struct afsconf_cell info;
1561 tdir = afsconf_Open(confDir);
1564 ("Could not open configuration directory (%s).\n", confDir));
1567 code = afsconf_ClientAuth(tdir, &sc, &scIndex);
1569 ViceLog(0, ("Could not get security object for localAuth\n"));
1572 code = afsconf_GetCellInfo(tdir, NULL, AFSCONF_VLDBSERVICE, &info);
1573 if (info.numServers > MAXSERVERS) {
1575 ("vl_Initialize: info.numServers=%d (> MAXSERVERS=%d)\n",
1576 info.numServers, MAXSERVERS));
1579 for (i = 0; i < info.numServers; i++)
1581 rx_NewConnection(info.hostAddr[i].sin_addr.s_addr,
1582 info.hostAddr[i].sin_port, USER_SERVICE_ID, sc,
1584 code = ubik_ClientInit(serverconns, &cstruct);
1586 ViceLog(0, ("vl_Initialize: ubik client init failed.\n"));
1592 #define SYSIDMAGIC 0x88aabbcc
1593 #define SYSIDVERSION 1
1598 afs_int32 fd, nentries, i;
1599 struct versionStamp vsn;
1600 struct afs_stat status;
1603 if ((afs_stat(AFSDIR_SERVER_SYSID_FILEPATH, &status))
1604 || (status.st_size <= 0)) {
1605 ViceLog(0, ("%s: doesn't exist\n", AFSDIR_SERVER_SYSID_FILEPATH));
1608 if (!(fd = afs_open(AFSDIR_SERVER_SYSID_FILEPATH, O_RDONLY, 0))) {
1610 ("%s: can't open (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1614 if ((i = read(fd, (char *)&vsn, sizeof(vsn))) != sizeof(vsn)) {
1616 ("%s: Read failed (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1620 if (vsn.magic != SYSIDMAGIC) {
1622 ("%s: wrong magic %x (we support %x)\n",
1623 AFSDIR_SERVER_SYSID_FILEPATH, vsn.magic, SYSIDMAGIC));
1626 if (vsn.version != SYSIDVERSION) {
1628 ("%s: wrong version %d (we support %d)\n",
1629 AFSDIR_SERVER_SYSID_FILEPATH, vsn.version, SYSIDVERSION));
1633 read(fd, (char *)&uuid,
1634 sizeof(struct afsUUID))) != sizeof(struct afsUUID)) {
1636 ("%s: read of uuid failed (%d)\n",
1637 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1640 afs_ntohuuid(&uuid);
1643 read(fd, (char *)&nentries,
1644 sizeof(afs_int32))) != sizeof(afs_int32)) {
1646 ("%s: Read of entries failed (%d)\n",
1647 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1650 if (nentries <= 0 || nentries > ADDRSPERSITE) {
1652 ("%s: invalid num of interfaces: %d\n",
1653 AFSDIR_SERVER_SYSID_FILEPATH, nentries));
1656 FS_HostAddr_cnt = nentries;
1657 for (i = 0; i < nentries; i++) {
1658 if (read(fd, (char *)&FS_HostAddrs[i], sizeof(afs_int32)) !=
1659 sizeof(afs_int32)) {
1661 ("%s: Read of addresses failed (%d)\n",
1662 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1663 FS_HostAddr_cnt = 0; /* reset it */
1675 struct versionStamp vsn;
1676 struct afs_stat status;
1679 if (!afs_stat(AFSDIR_SERVER_SYSID_FILEPATH, &status)) {
1681 * File exists; keep the old one around
1683 renamefile(AFSDIR_SERVER_SYSID_FILEPATH,
1684 AFSDIR_SERVER_OLDSYSID_FILEPATH);
1686 fd = afs_open(AFSDIR_SERVER_SYSID_FILEPATH, O_WRONLY | O_TRUNC | O_CREAT,
1690 ("%s: can't create (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1694 vsn.magic = SYSIDMAGIC;
1696 if ((i = write(fd, (char *)&vsn, sizeof(vsn))) != sizeof(vsn)) {
1698 ("%s: write failed (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1703 afs_htonuuid(&uuid);
1705 write(fd, (char *)&uuid,
1706 sizeof(struct afsUUID))) != sizeof(struct afsUUID)) {
1708 ("%s: write of uuid failed (%d)\n",
1709 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1713 write(fd, (char *)&FS_HostAddr_cnt,
1714 sizeof(afs_int32))) != sizeof(afs_int32)) {
1716 ("%s: write of # of entries failed (%d)\n",
1717 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1720 for (i = 0; i < FS_HostAddr_cnt; i++) {
1721 if (write(fd, (char *)&FS_HostAddrs[i], sizeof(afs_int32)) !=
1722 sizeof(afs_int32)) {
1724 ("%s: write of addresses failed (%d)\n",
1725 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1735 * This routine sets up the buffers for the VL_RegisterAddrs RPC. All addresses
1736 * in FS_HostAddrs[] are in NBO, while the RPC treats them as a "blob" of data
1737 * and so we need to convert each of them into HBO which is what the extra
1738 * array called FS_HostAddrs_HBO is used here.
1745 extern int VL_RegisterAddrs();
1746 afs_uint32 FS_HostAddrs_HBO[ADDRSPERSITE];
1749 for (i = 0; i < FS_HostAddr_cnt; i++)
1750 FS_HostAddrs_HBO[i] = ntohl(FS_HostAddrs[i]);
1751 addrs.bulkaddrs_len = FS_HostAddr_cnt;
1752 addrs.bulkaddrs_val = (afs_uint32 *) FS_HostAddrs_HBO;
1753 code = ubik_Call(VL_RegisterAddrs, cstruct, 0, &FS_HostUUID, 0, &addrs);
1755 if (code == VL_MULTIPADDR) {
1757 ("VL_RegisterAddrs rpc failed; The IP address exists on a different server; repair it\n"));
1759 ("VL_RegisterAddrs rpc failed; See VLLog for details\n"));
1761 } else if (code == RXGEN_OPCODE) {
1763 ("vlserver doesn't support VL_RegisterAddrs rpc; ignored\n"));
1764 FS_registered = 2; /* So we don't have to retry in the gc daemon */
1767 ("VL_RegisterAddrs rpc failed; will retry periodically (code=%d, err=%d)\n",
1771 FS_registered = 2; /* So we don't have to retry in the gc daemon */
1784 * If this fails, it's because something major is wrong, and is not
1785 * likely to be time dependent.
1787 code = vl_Initialize(AFSDIR_SERVER_ETC_DIRPATH);
1790 ("Couldn't initialize protection library; code=%d.\n", code));
1794 /* Read or create the sysid file and register the fileserver's
1795 * IP addresses with the vlserver.
1797 code = ReadSysIdFile();
1799 /* Need to create the file */
1800 ViceLog(0, ("Creating new SysID file\n"));
1801 if ((code = afs_uuid_create(&FS_HostUUID))) {
1802 ViceLog(0, ("Failed to create new uuid: %d\n", code));
1806 /* A good sysid file exists; inform the vlserver. If any conflicts,
1807 * we always use the latest interface available as the real truth.
1809 #ifndef AFS_NT40_ENV
1810 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH || AFSDIR_SERVER_NETINFO_FILEPATH) {
1812 * Find addresses we are supposed to register as per the netrestrict
1813 * and netinfo files (/usr/afs/local/NetInfo and
1814 * /usr/afs/local/NetRestict)
1817 afs_int32 code = parseNetFiles(FS_HostAddrs, NULL, NULL,
1818 ADDRSPERSITE, reason,
1819 AFSDIR_SERVER_NETINFO_FILEPATH,
1820 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
1822 ViceLog(0, ("Can't register any valid addresses: %s\n", reason));
1825 FS_HostAddr_cnt = (afs_uint32) code;
1829 FS_HostAddr_cnt = rx_getAllAddr(FS_HostAddrs, ADDRSPERSITE);
1833 code = Do_VLRegisterRPC();
1838 main(int argc, char *argv[])
1842 struct rx_securityClass *sc[4];
1843 struct rx_service *tservice;
1844 #ifdef AFS_PTHREAD_ENV
1845 pthread_t serverPid;
1846 pthread_attr_t tattr;
1847 #else /* AFS_PTHREAD_ENV */
1848 PROCESS parentPid, serverPid;
1849 #endif /* AFS_PTHREAD_ENV */
1851 int minVnodesRequired; /* min size of vnode cache */
1852 #ifndef AFS_NT40_ENV
1853 struct rlimit rlim; /* max number of open file descriptors */
1858 #ifdef AFS_AIX32_ENV
1859 struct sigaction nsa;
1861 sigemptyset(&nsa.sa_mask);
1862 nsa.sa_handler = SIG_DFL;
1863 nsa.sa_flags = SA_FULLDUMP;
1864 sigaction(SIGABRT, &nsa, NULL);
1865 sigaction(SIGSEGV, &nsa, NULL);
1869 /* Initialize dirpaths */
1870 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
1872 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
1874 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
1878 #ifndef AFS_QUIETFS_ENV
1879 console = afs_fopen("/dev/console", "w");
1882 if (ParseArgs(argc, argv)) {
1886 #ifdef AFS_PTHREAD_ENV
1887 assert(pthread_mutex_init(&fileproc_glock_mutex, NULL) == 0);
1888 #endif /* AFS_PTHREAD_ENV */
1890 #ifdef AFS_SGI_VNODE_GLUE
1891 if (afs_init_kernel_config(-1) < 0) {
1893 ("Can't determine NUMA configuration, not starting fileserver.\n");
1897 confDir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
1899 fprintf(stderr, "Unable to open config directory %s\n",
1900 AFSDIR_SERVER_ETC_DIRPATH);
1906 /* Open FileLog on stdout, stderr, fd 1 and fd2 (for perror), sigh. */
1907 #ifndef AFS_NT40_ENV
1908 serverLogSyslogTag = "fileserver";
1910 OpenLog(AFSDIR_SERVER_FILELOG_FILEPATH);
1913 if (SawSpare && SawPctSpare) {
1914 ViceLog(0, ("Both -spare and -pctspare specified, exiting.\n"));
1917 #ifdef AFS_SGI_XFS_IOPS_ENV
1918 ViceLog(0, ("XFS/EFS File server starting\n"));
1920 ViceLog(0, ("File server starting\n"));
1923 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
1924 /* initialize the pthread soft signal handler thread */
1928 /* install signal handlers for controlling the fileserver process */
1929 ResetCheckSignal(); /* set CheckSignal_Signal() sig handler */
1930 ResetCheckDescriptors(); /* set CheckDescriptors_Signal() sig handler */
1932 #if defined(AFS_SGI_ENV)
1933 /* give this guy a non-degrading priority so help busy servers */
1934 schedctl(NDPRI, 0, NDPNORMMAX);
1938 #ifndef AFS_NT40_ENV
1939 nice(-5); /* TODO: */
1942 assert(DInit(buffs) == 0);
1945 if (afs_winsockInit() < 0) {
1946 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
1947 ViceLog(0, ("File server failed to intialize winsock.\n"));
1953 /* if we support more than 16 threads, then we better have the ability
1954 ** to keep open a large number of files simultaneously
1956 #if defined(AFS_AIX_ENV) && !defined(AFS_AIX42_ENV)
1957 curLimit = OPEN_MAX; /* for pre AIX 4.2 systems */
1958 #elif defined(AFS_NT40_ENV)
1959 curLimit = NT_OPEN_MAX; /* open file descriptor limit on NT */
1962 curLimit = 0; /* the number of open file descriptors */
1963 code = getrlimit(RLIMIT_NOFILE, &rlim);
1965 curLimit = rlim.rlim_cur;
1966 rlim.rlim_cur = rlim.rlim_max;
1967 code = setrlimit(RLIMIT_NOFILE, &rlim);
1969 curLimit = rlim.rlim_max;
1972 ViceLog(0, ("Failed to increase open file limit, using default\n"));
1974 #endif /* defined(AFS_AIX_ENV) && !defined(AFS_AIX42_ENV) */
1976 curLimit -= 32; /* leave a slack of 32 file descriptors */
1977 if (lwps > curLimit) {
1981 lwps = 16; /* default to a maximum of 16 threads */
1983 ("The system supports a max of %d open files and we are starting %d threads\n",
1986 #ifndef AFS_PTHREAD_ENV
1987 assert(LWP_InitializeProcessSupport(LWP_MAX_PRIORITY - 2, &parentPid) ==
1989 #endif /* !AFS_PTHREAD_ENV */
1991 /* Initialize volume support */
1993 V_BreakVolumeCallbacks = BreakVolumeCallBacksLater;
1996 #ifdef AFS_PTHREAD_ENV
1997 SetLogThreadNumProgram( threadNum );
2000 /* initialize libacl routines */
2001 acl_Initialize(ACL_VERSION);
2003 /* initialize RX support */
2004 #ifndef AFS_NT40_ENV
2005 rxi_syscallp = viced_syscall;
2007 rx_extraPackets = rxpackets;
2008 rx_extraQuota = 4; /* for outgoing prserver calls from R threads */
2009 rx_SetBusyThreshold(busy_threshold, VBUSY);
2010 rx_SetCallAbortThreshold(abort_threshold);
2011 rx_SetConnAbortThreshold(abort_threshold);
2012 stackSize = lwps * 4000;
2013 if (stackSize < 32000)
2015 else if (stackSize > 44000)
2017 #if defined(AFS_HPUX_ENV) || defined(AFS_SUN_ENV) || defined(AFS_SGI51_ENV)
2018 rx_SetStackSize(1, stackSize);
2021 rx_SetUdpBufSize(udpBufSize); /* set the UDP buffer size for receive */
2022 if (rx_Init((int)htons(7000)) < 0) {
2023 ViceLog(0, ("Cannot initialize RX\n"));
2026 if (!rxJumbograms) {
2027 /* Don't send and don't allow 3.4 clients to send jumbograms. */
2030 if (rxMaxMTU != -1) {
2031 rx_SetMaxMTU(rxMaxMTU);
2034 rx_SetRxDeadTime(30);
2035 sc[0] = rxnull_NewServerSecurityObject();
2036 sc[1] = 0; /* rxvab_NewServerSecurityObject(key1, 0) */
2037 sc[2] = rxkad_NewServerSecurityObject(rxkad_clear, NULL, get_key, NULL);
2038 sc[3] = rxkad_NewServerSecurityObject(rxkad_crypt, NULL, get_key, NULL);
2039 tservice = rx_NewService( /* port */ 0, /* service id */ 1, /*service name */
2041 /* security classes */ sc,
2042 /* numb sec classes */
2043 4, RXAFS_ExecuteRequest);
2046 ("Failed to initialize RX, probably two servers running.\n"));
2049 rx_SetDestroyConnProc(tservice, (void (*)())h_FreeConnection);
2050 rx_SetMinProcs(tservice, 3);
2051 rx_SetMaxProcs(tservice, lwps);
2052 rx_SetCheckReach(tservice, 1);
2055 rx_NewService(0, RX_STATS_SERVICE_ID, "rpcstats", sc, 4,
2056 RXSTATS_ExecuteRequest);
2058 ViceLog(0, ("Failed to initialize rpc stat service.\n"));
2061 rx_SetMinProcs(tservice, 2);
2062 rx_SetMaxProcs(tservice, 4);
2065 * Enable RX hot threads, which allows the listener thread to trade
2066 * places with an idle thread and moves the context switch from listener
2067 * to worker out of the critical path.
2069 rx_EnableHotThread();
2071 /* Some rx debugging */
2072 if (rxlog || eventlog) {
2073 debugFile = afs_fopen("rx_dbg", "w");
2075 rx_debugFile = debugFile;
2077 rxevent_debugFile = debugFile;
2080 init_sys_error_to_et(); /* Set up error table translation */
2081 h_InitHostPackage(); /* set up local cellname and realmname */
2082 InitCallBack(numberofcbs);
2087 ViceLog(0, ("Fatal error in library initialization, exiting!!\n"));
2093 ViceLog(0, ("Fatal error in protection initialization, exiting!!\n"));
2097 /* allow super users to manage RX statistics */
2098 rx_SetRxStatUserOk(fs_rxstat_userok);
2100 rx_StartServer(0); /* now start handling requests */
2102 /* we ensure that there is enough space in the vnode buffer to satisfy
2103 ** requests from all concurrent threads.
2104 ** the maximum number of vnodes used by a single thread at any one time
2105 ** is three ( "link" uses three vnodes simultaneously, one vLarge and
2106 ** two vSmall for linking files and two vLarge and one vSmall for linking
2109 minVnodesRequired = 2 * lwps + 1;
2110 if (minVnodesRequired > nSmallVns) {
2111 nSmallVns = minVnodesRequired;
2113 ("Overriding -s command line parameter with %d\n",
2116 if (minVnodesRequired > large) {
2117 large = minVnodesRequired;
2118 ViceLog(0, ("Overriding -l command line parameter with %d\n", large));
2121 /* We now do this after getting the listener up and running, so that client
2122 * connections don't timeout (maybe) if a file server is restarted, since it
2123 * will be available "real soon now". Worry about whether we can satisfy the
2124 * calls in the volume package itself.
2126 if (VInitVolumePackage(fileServer, large, nSmallVns, 0, volcache)) {
2128 ("Shutting down: errors encountered initializing volume package\n"));
2133 #ifdef AFS_DEMAND_ATTACH_FS
2134 if (fs_state.options.fs_state_restore) {
2137 * restore fileserver state */
2140 #endif /* AFS_DEMAND_ATTACH_FS */
2143 * We are done calling fopen/fdopen. It is safe to use a large
2144 * of the file descriptor cache.
2148 #ifdef AFS_PTHREAD_ENV
2149 ViceLog(5, ("Starting pthreads\n"));
2150 assert(pthread_attr_init(&tattr) == 0);
2151 assert(pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED) == 0);
2153 assert(pthread_create
2154 (&serverPid, &tattr, (void *)FiveMinuteCheckLWP,
2155 &fiveminutes) == 0);
2156 assert(pthread_create
2157 (&serverPid, &tattr, (void *)HostCheckLWP, &fiveminutes) == 0);
2158 assert(pthread_create
2159 (&serverPid, &tattr, (void *)FsyncCheckLWP, &fiveminutes) == 0);
2160 #else /* AFS_PTHREAD_ENV */
2161 ViceLog(5, ("Starting LWP\n"));
2162 assert(LWP_CreateProcess
2163 (FiveMinuteCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
2164 (void *)&fiveminutes, "FiveMinuteChecks",
2165 &serverPid) == LWP_SUCCESS);
2167 assert(LWP_CreateProcess
2168 (HostCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
2169 (void *)&fiveminutes, "HostCheck", &serverPid) == LWP_SUCCESS);
2170 assert(LWP_CreateProcess
2171 (FsyncCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
2172 (void *)&fiveminutes, "FsyncCheck", &serverPid) == LWP_SUCCESS);
2173 #endif /* AFS_PTHREAD_ENV */
2175 TM_GetTimeOfDay(&tp, 0);
2177 #ifndef AFS_QUIETFS_ENV
2178 if (console != NULL) {
2179 time_t t = tp.tv_sec;
2180 fprintf(console, "File server has started at %s\r",
2181 afs_ctime(&t, tbuffer, sizeof(tbuffer)));
2186 * Figure out the FileServer's name and primary address.
2188 ViceLog(0, ("Getting FileServer name...\n"));
2189 code = gethostname(FS_HostName, 64);
2191 ViceLog(0, ("gethostname() failed\n"));
2193 ViceLog(0, ("FileServer host name is '%s'\n", FS_HostName));
2195 ViceLog(0, ("Getting FileServer address...\n"));
2196 he = gethostbyname(FS_HostName);
2198 ViceLog(0, ("Can't find address for FileServer '%s'\n", FS_HostName));
2201 memcpy(&FS_HostAddr_NBO, he->h_addr, 4);
2202 (void)afs_inet_ntoa_r(FS_HostAddr_NBO, hoststr);
2203 FS_HostAddr_HBO = ntohl(FS_HostAddr_NBO);
2205 ("FileServer %s has address %s (0x%x or 0x%x in host byte order)\n",
2206 FS_HostName, hoststr, FS_HostAddr_NBO, FS_HostAddr_HBO));
2209 /* Install handler to catch the shutdown signal;
2210 * bosserver assumes SIGQUIT shutdown
2212 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
2213 softsig_signal(SIGQUIT, ShutDown_Signal);
2215 (void)signal(SIGQUIT, ShutDown_Signal);
2220 ("File Server started %s",
2221 afs_ctime(&t, tbuffer, sizeof(tbuffer))));
2222 #if FS_STATS_DETAILED
2223 afs_FullPerfStats.det.epoch.tv_sec = StartTime = tp.tv_sec;
2225 #ifdef AFS_PTHREAD_ENV
2227 sleep(1000); /* long time */
2229 #else /* AFS_PTHREAD_ENV */
2230 assert(LWP_WaitProcess(&parentPid) == LWP_SUCCESS);
2231 #endif /* AFS_PTHREAD_ENV */