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. */
175 int rxBind = 0; /* don't bind */
177 afs_int32 implicitAdminRights = PRSFS_LOOKUP; /* The ADMINISTER right is
179 afs_int32 readonlyServer = 0;
182 int stackSize = 24000;
183 int fiveminutes = 300; /* 5 minutes. Change this for debugging only */
184 int CurrentConnections = 0;
185 int hostaclRefresh = 7200; /* refresh host clients' acls every 2 hrs */
186 #if defined(AFS_SGI_ENV)
191 int rxpackets = 150; /* 100 */
192 int nSmallVns = 400; /* 200 */
193 int large = 400; /* 200 */
194 int volcache = 400; /* 400 */
195 int numberofcbs = 60000; /* 60000 */
196 int lwps = 9; /* 6 */
197 int buffs = 90; /* 70 */
198 int novbc = 0; /* Enable Volume Break calls */
199 int busy_threshold = 600;
200 int abort_threshold = 10;
201 int udpBufSize = 0; /* UDP buffer size for receive */
202 int sendBufSize = 16384; /* send buffer size */
206 #ifdef AFS_PTHREAD_ENV
207 pthread_key_t viced_uclient_key;
210 #ifdef AFS_PTHREAD_ENV
211 pthread_key_t viced_uclient_key;
215 * FileServer's name and IP address, both network byte order and
218 #define ADDRSPERSITE 16 /* Same global is in rx/rx_user.c */
220 char FS_HostName[128] = "localhost";
221 afs_uint32 FS_HostAddr_NBO;
222 afs_uint32 FS_HostAddr_HBO;
223 afs_uint32 FS_HostAddrs[ADDRSPERSITE], FS_HostAddr_cnt = 0, FS_registered = 0;
224 /* All addresses in FS_HostAddrs are in NBO */
227 static void FlagMsg();
229 #ifdef AFS_DEMAND_ATTACH_FS
232 * fileserver mode support
234 * during fileserver shutdown, we have to track the graceful shutdown of
235 * certain background threads before we are allowed to dump state to
238 struct fs_state fs_state =
245 PTHREAD_COND_INITIALIZER,
246 PTHREAD_RWLOCK_INITIALIZER
248 #endif /* AFS_DEMAND_ATTACH_FS */
251 * Home for the performance statistics.
259 struct afs_stat status;
260 register int tsize = getdtablesize();
262 for (i = 0; i < tsize; i++) {
263 if (afs_fstat(i, &status) != -1) {
264 printf("%d: dev %x, inode %u, length %u, type/mode %x\n", i,
265 status.st_dev, status.st_ino, status.st_size,
270 ResetCheckDescriptors();
273 } /*CheckDescriptors */
276 #ifdef AFS_PTHREAD_ENV
278 CheckSignal_Signal(x)
290 CheckDescriptors_Signal(x)
294 #else /* AFS_PTHREAD_ENV */
296 CheckSignal_Signal(x)
298 IOMGR_SoftSig(CheckSignal, 0);
304 IOMGR_SoftSig(ShutDown, 0);
308 CheckDescriptors_Signal(x)
310 IOMGR_SoftSig(CheckDescriptors, 0);
312 #endif /* AFS_PTHREAD_ENV */
314 /* check whether caller is authorized to manage RX statistics */
316 fs_rxstat_userok(struct rx_call *call)
318 return afsconf_SuperUser(confDir, call, NULL);
322 ResetCheckSignal(void)
326 #if defined(AFS_HPUX_ENV)
329 #if defined(AFS_NT40_ENV)
336 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
337 softsig_signal(signo, CheckSignal_Signal);
339 signal(signo, CheckSignal_Signal);
344 ResetCheckDescriptors(void)
347 #if defined(AFS_PTHREAD_ENV)
348 softsig_signal(SIGTERM, CheckDescriptors_Signal);
350 (void)signal(SIGTERM, CheckDescriptors_Signal);
355 #if defined(AFS_PTHREAD_ENV)
359 return pthread_getspecific(rx_thread_id_key);
363 /* proc called by rxkad module to get a key */
365 get_key(char *arock, register afs_int32 akvno, char *akey)
368 static struct afsconf_key tkey;
369 register afs_int32 code;
372 ViceLog(0, ("conf dir not open\n"));
375 code = afsconf_GetKey(confDir, akvno, tkey.key);
377 ViceLog(0, ("afsconf_GetKey failure: kvno %d code %d\n", akvno, code));
380 memcpy(akey, tkey.key, sizeof(tkey.key));
387 viced_syscall(afs_uint32 a3, afs_uint32 a4, void *a5)
392 #ifndef AFS_LINUX20_ENV
393 old = (void (*)())signal(SIGSYS, SIG_IGN);
395 rcode = syscall(AFS_SYSCALL, 28 /* AFSCALL_CALL */ , a3, a4, a5);
396 #ifndef AFS_LINUX20_ENV
404 #if !defined(AFS_NT40_ENV)
405 #include "AFS_component_version_number.c"
406 #endif /* !AFS_NT40_ENV */
408 #define MAXADMINNAME 64
409 char adminName[MAXADMINNAME];
415 struct afs_stat status;
417 if ((afs_stat("/AdminName", &status)) || /* if file does not exist */
418 (status.st_size <= 0) || /* or it is too short */
419 (status.st_size >= (MAXADMINNAME)) || /* or it is too long */
420 !(fd = afs_open("/AdminName", O_RDONLY, 0))) { /* or the open fails */
421 strcpy(adminName, "System:Administrators"); /* use the default name */
423 (void)read(fd, adminName, status.st_size); /* use name from the file */
426 close(fd); /* close fd if it was opened */
428 } /*CheckAdminName */
434 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
435 /* set our 'thread-id' so that the host hold table works */
436 MUTEX_ENTER(&rx_stats_mutex); /* protects rxi_pthread_hinum */
438 pthread_setspecific(rx_thread_id_key, (void *)rxi_pthread_hinum);
439 MUTEX_EXIT(&rx_stats_mutex);
441 ("Set thread id %d for '%s'\n",
442 pthread_getspecific(rx_thread_id_key), s));
446 /* This LWP does things roughly every 5 minutes */
453 ViceLog(1, ("Starting five minute check process\n"));
454 setThreadId("FiveMinuteCheckLWP");
456 #ifdef AFS_DEMAND_ATTACH_FS
458 while (fs_state.mode == FS_MODE_NORMAL) {
459 fs_state.FiveMinuteLWP_tranquil = 1;
465 #ifdef AFS_PTHREAD_ENV
467 #else /* AFS_PTHREAD_ENV */
468 IOMGR_Sleep(fiveminutes);
469 #endif /* AFS_PTHREAD_ENV */
471 #ifdef AFS_DEMAND_ATTACH_FS
473 if (fs_state.mode != FS_MODE_NORMAL) {
476 fs_state.FiveMinuteLWP_tranquil = 0;
480 /* close the log so it can be removed */
481 ReOpenLog(AFSDIR_SERVER_FILELOG_FILEPATH); /* don't trunc, just append */
482 ViceLog(2, ("Cleaning up timed out callbacks\n"));
483 if (CleanupTimedOutCallBacks())
484 ViceLog(5, ("Timed out callbacks deleted\n"));
485 ViceLog(2, ("Set disk usage statistics\n"));
487 if (FS_registered == 1)
489 /* Force wakeup in case we missed something; pthreads does timedwait */
490 #ifndef AFS_PTHREAD_ENV
491 LWP_NoYieldSignal(fsync_wait);
493 if (printBanner && (++msg & 1)) { /* Every 10 minutes */
494 time_t now = FT_ApproxTime();
495 if (console != NULL) {
496 #ifndef AFS_QUIETFS_ENV
497 fprintf(console, "File server is running at %s\r",
498 afs_ctime(&now, tbuffer, sizeof(tbuffer)));
499 #endif /* AFS_QUIETFS_ENV */
501 ("File server is running at %s\n",
502 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
505 #ifdef AFS_DEMAND_ATTACH_FS
509 #ifdef AFS_DEMAND_ATTACH_FS
510 fs_state.FiveMinuteLWP_tranquil = 1;
512 assert(pthread_cond_broadcast(&fs_state.worker_done_cv)==0);
516 } /*FiveMinuteCheckLWP */
519 /* This LWP does host checks every 5 minutes: it should not be used for
520 * other 5 minute activities because it may be delayed by timeouts when
521 * it probes the workstations
527 ViceLog(1, ("Starting Host check process\n"));
528 setThreadId("HostCheckLWP");
529 #ifdef AFS_DEMAND_ATTACH_FS
531 while (fs_state.mode == FS_MODE_NORMAL) {
532 fs_state.HostCheckLWP_tranquil = 1;
538 #ifdef AFS_PTHREAD_ENV
540 #else /* AFS_PTHREAD_ENV */
541 IOMGR_Sleep(fiveminutes);
542 #endif /* AFS_PTHREAD_ENV */
544 #ifdef AFS_DEMAND_ATTACH_FS
546 if (fs_state.mode != FS_MODE_NORMAL) {
549 fs_state.HostCheckLWP_tranquil = 0;
553 ViceLog(2, ("Checking for dead venii & clients\n"));
556 #ifdef AFS_DEMAND_ATTACH_FS
560 #ifdef AFS_DEMAND_ATTACH_FS
561 fs_state.HostCheckLWP_tranquil = 1;
563 assert(pthread_cond_broadcast(&fs_state.worker_done_cv)==0);
569 /* This LWP does fsync checks every 5 minutes: it should not be used for
570 * other 5 minute activities because it may be delayed by timeouts when
571 * it probes the workstations
577 #ifdef AFS_PTHREAD_ENV
578 struct timespec fsync_next;
580 ViceLog(1, ("Starting fsync check process\n"));
582 setThreadId("FsyncCheckLWP");
584 #ifdef AFS_PTHREAD_ENV
585 assert(pthread_cond_init(&fsync_cond, NULL) == 0);
586 assert(pthread_mutex_init(&fsync_glock_mutex, NULL) == 0);
589 #ifdef AFS_DEMAND_ATTACH_FS
591 while (fs_state.mode == FS_MODE_NORMAL) {
592 fs_state.FsyncCheckLWP_tranquil = 1;
598 #ifdef AFS_PTHREAD_ENV
599 /* rounding is fine */
600 fsync_next.tv_nsec = 0;
601 fsync_next.tv_sec = time(0) + fiveminutes;
604 pthread_cond_timedwait(&fsync_cond, &fsync_glock_mutex,
606 if (code != 0 && code != ETIMEDOUT)
607 ViceLog(0, ("pthread_cond_timedwait returned %d\n", code));
608 #else /* AFS_PTHREAD_ENV */
609 if ((code = LWP_WaitProcess(fsync_wait)) != LWP_SUCCESS)
610 ViceLog(0, ("LWP_WaitProcess returned %d\n", code));
611 #endif /* AFS_PTHREAD_ENV */
614 #ifdef AFS_DEMAND_ATTACH_FS
616 if (fs_state.mode != FS_MODE_NORMAL) {
619 fs_state.FsyncCheckLWP_tranquil = 0;
621 #endif /* AFS_DEMAND_ATTACH_FS */
623 ViceLog(2, ("Checking for fsync events\n"));
625 code = BreakLaterCallBacks();
627 #ifdef AFS_DEMAND_ATTACH_FS
631 #ifdef AFS_DEMAND_ATTACH_FS
632 fs_state.FsyncCheckLWP_tranquil = 1;
634 assert(pthread_cond_broadcast(&fs_state.worker_done_cv)==0);
637 #endif /* AFS_DEMAND_ATTACH_FS */
640 /*------------------------------------------------------------------------
641 * PRIVATE ClearXStatValues
644 * Initialize all of the values collected via the xstat
654 * Must be called during File Server initialization.
658 *------------------------------------------------------------------------*/
662 { /*ClearXStatValues */
664 struct fs_stats_opTimingData *opTimeP; /*Ptr to timing struct */
665 struct fs_stats_xferData *opXferP; /*Ptr to xfer struct */
666 int i; /*Loop counter */
669 * Zero all xstat-related structures.
671 memset((char *)(&afs_perfstats), 0, sizeof(struct afs_PerfStats));
672 #if FS_STATS_DETAILED
673 memset((char *)(&afs_FullPerfStats), 0,
674 sizeof(struct fs_stats_FullPerfStats));
677 * That's not enough. We have to set reasonable minima for
678 * time and xfer values in the detailed stats.
680 opTimeP = &(afs_FullPerfStats.det.rpcOpTimes[0]);
681 for (i = 0; i < FS_STATS_NUM_RPC_OPS; i++, opTimeP++)
682 opTimeP->minTime.tv_sec = 999999;
684 opXferP = &(afs_FullPerfStats.det.xferOpTimes[0]);
685 for (i = 0; i < FS_STATS_NUM_XFER_OPS; i++, opXferP++) {
686 opXferP->minTime.tv_sec = 999999;
687 opXferP->minBytes = 999999999;
691 * There's more. We have to set our unique system identifier, as
692 * declared in param.h. If such a thing is not defined, we bitch
693 * and declare ourselves to be an unknown system type.
696 afs_perfstats.sysname_ID = SYS_NAME_ID;
699 ViceLog(0, ("Sys name ID constant not defined in param.h!!\n"));
700 ViceLog(0, ("[Choosing ``undefined'' sys name ID.\n"));
702 afs_perfstats.sysname_ID = SYS_NAME_ID_UNDEFINED;
703 #endif /* SYS_NAME_ID */
706 } /*ClearXStatValues */
712 int dirbuff, dircall, dirio;
714 int workstations, activeworkstations, delworkstations;
718 TM_GetTimeOfDay(&tpl, 0);
721 ("Vice was last started at %s\n",
722 afs_ctime(&StartTime, tbuffer, sizeof(tbuffer))));
724 #ifdef AFS_DEMAND_ATTACH_FS
725 /* XXX perhaps set extended stats verbosity flags
726 * based upon LogLevel ?? */
727 VPrintExtendedCacheStats(VOL_STATS_PER_CHAIN2);
731 DStat(&dirbuff, &dircall, &dirio);
733 ("With %d directory buffers; %d reads resulted in %d read I/Os\n",
734 dirbuff, dircall, dirio));
735 rx_PrintStats(stderr);
737 PrintCallBackStats();
739 processSize = -1; /* TODO: */
741 processSize = (int)((long)sbrk(0) >> 10);
744 ("There are %d connections, process size %d\n",
745 CurrentConnections, processSize));
746 h_GetWorkStats(&workstations, &activeworkstations, &delworkstations,
747 tpl.tv_sec - 15 * 60);
749 ("There are %d workstations, %d are active (req in < 15 mins), %d marked \"down\"\n",
750 workstations, activeworkstations, delworkstations));
760 if (FS_registered > 0) {
762 * We have proper ip addresses; tell the vlserver what we got; the following
763 * routine will do the proper reporting for us
776 ShutDownAndCore(int dopanic)
778 time_t now = time(0);
781 /* do not allows new reqests to be served from now on, all new requests
782 * are returned with an error code of RX_RESTARTING ( transient failure ) */
783 rx_SetRxTranquil(); /* dhruba */
785 #ifdef AFS_DEMAND_ATTACH_FS
787 fs_state.mode = FS_MODE_SHUTDOWN;
792 ("Shutting down file server at %s",
793 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
795 ViceLog(0, ("ABNORMAL SHUTDOWN, see core file.\n"));
796 #ifndef AFS_QUIETFS_ENV
797 if (console != NULL) {
798 fprintf(console, "File server restart/shutdown received at %s\r",
799 afs_ctime(&now, tbuffer, sizeof(tbuffer)));
806 /* shut down volume package */
809 #ifdef AFS_DEMAND_ATTACH_FS
810 if (fs_state.options.fs_state_save) {
813 * save fileserver state to disk */
815 /* make sure background threads have finished all of their asynchronous
816 * work on host and callback structures */
818 while (!fs_state.FiveMinuteLWP_tranquil ||
819 !fs_state.HostCheckLWP_tranquil ||
820 !fs_state.FsyncCheckLWP_tranquil) {
823 ViceLog(0, ("waiting for background host/callback threads to quiesce before saving fileserver state...\n"));
824 assert(pthread_cond_wait(&fs_state.worker_done_cv, &fileproc_glock_mutex) == 0);
829 /* ok. it should now be fairly safe. let's do the state dump */
832 #endif /* AFS_DEMAND_ATTACH_FS */
835 rx_PrintStats(debugFile);
838 if (console != NULL) {
841 #ifndef AFS_QUIETFS_ENV
842 fprintf(console, "File server has terminated abnormally at %s\r",
843 afs_ctime(&now, tbuffer, sizeof(tbuffer)));
846 ("File server has terminated abnormally at %s\n",
847 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
849 #ifndef AFS_QUIETFS_ENV
850 fprintf(console, "File server has terminated normally at %s\r",
851 afs_ctime(&now, tbuffer, sizeof(tbuffer)));
854 ("File server has terminated normally at %s\n",
855 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
864 { /* backward compatibility */
865 ShutDownAndCore(DONTPANIC);
875 /* default supports help flag */
877 strcpy(buffer, "Usage: fileserver ");
878 strcpy(buffer, "[-auditlog <log path>] ");
879 strcat(buffer, "[-d <debug level>] ");
880 strcat(buffer, "[-p <number of processes>] ");
881 strcat(buffer, "[-spare <number of spare blocks>] ");
882 strcat(buffer, "[-pctspare <percentage spare>] ");
883 strcat(buffer, "[-b <buffers>] ");
884 strcat(buffer, "[-l <large vnodes>] ");
885 strcat(buffer, "[-s <small vnodes>] ");
886 strcat(buffer, "[-vc <volume cachesize>] ");
887 strcat(buffer, "[-w <call back wait interval>] ");
888 strcat(buffer, "[-cb <number of call backs>] ");
889 strcat(buffer, "[-banner (print banner every 10 minutes)] ");
890 strcat(buffer, "[-novbc (whole volume cbs disabled)] ");
891 strcat(buffer, "[-implicit <admin mode bits: rlidwka>] ");
892 strcat(buffer, "[-readonly (read-only file server)] ");
894 "[-hr <number of hours between refreshing the host cps>] ");
895 strcat(buffer, "[-busyat <redirect clients when queue > n>] ");
896 strcat(buffer, "[-nobusy <no VBUSY before a volume is attached>] ");
897 strcat(buffer, "[-rxpck <number of rx extra packets>] ");
898 strcat(buffer, "[-rxdbg (enable rx debugging)] ");
899 strcat(buffer, "[-rxdbge (enable rxevent debugging)] ");
900 strcat(buffer, "[-rxmaxmtu <bytes>] ");
901 strcat(buffer, "[-rxbind (bind the Rx socket to one address)] ");
902 #ifdef AFS_DEMAND_ATTACH_FS
903 strcat(buffer, "[-fs-state-dont-save (disable state save during shutdown)] ");
904 strcat(buffer, "[-fs-state-dont-restore (disable state restore during startup)] ");
905 strcat(buffer, "[-fs-state-verify <none|save|restore|both> (default is both)] ");
906 strcat(buffer, "[-vattachpar <max number of volume attach/shutdown threads> (default is 1)] ");
907 strcat(buffer, "[-vhashsize <log(2) of number of volume hash buckets> (default is 8)] ");
908 strcat(buffer, "[-vlrudisable (disable VLRU functionality)] ");
909 strcat(buffer, "[-vlruthresh <minutes before unused volumes become eligible for soft detach> (default is 2 hours)] ");
910 strcat(buffer, "[-vlruinterval <seconds between VLRU scans> (default is 2 minutes)] ");
911 strcat(buffer, "[-vlrumax <max volumes to soft detach in one VLRU scan> (default is 8)] ");
912 #elif AFS_PTHREAD_ENV
913 strcat(buffer, "[-vattachpar <number of volume attach threads> (default is 1)] ");
916 strcat(buffer, "[-m <min percentage spare in partition>] ");
918 #if defined(AFS_SGI_ENV)
919 strcat(buffer, "[-lock (keep fileserver from swapping)] ");
921 strcat(buffer, "[-L (large server conf)] ");
922 strcat(buffer, "[-S (small server conf)] ");
923 strcat(buffer, "[-k <stack size>] ");
924 strcat(buffer, "[-realm <Kerberos realm name>] ");
925 strcat(buffer, "[-udpsize <size of socket buffer in bytes>] ");
926 strcat(buffer, "[-sendsize <size of send buffer in bytes>] ");
927 strcat(buffer, "[-abortthreshold <abort threshold>] ");
928 /* strcat(buffer, "[-enable_peer_stats] "); */
929 /* strcat(buffer, "[-enable_process_stats] "); */
930 strcat(buffer, "[-help]\n");
932 ViceLog(0, ("%s", buffer));
935 printf("%s", buffer);
942 ParseRights(char *arights)
948 if (!arights || !strcmp(arights, "")) {
949 printf("Missing list of mode bits on -implicit option\n");
952 if (!strcmp(arights, "none"))
954 else if (!strcmp(arights, "read"))
955 mode = PRSFS_READ | PRSFS_LOOKUP;
956 else if (!strcmp(arights, "write"))
958 PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
959 PRSFS_WRITE | PRSFS_LOCK;
960 else if (!strcmp(arights, "all"))
962 PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
963 PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER;
965 len = strlen(arights);
966 for (i = 0; i < len; i++) {
971 mode |= PRSFS_LOOKUP;
973 mode |= PRSFS_INSERT;
975 mode |= PRSFS_DELETE;
981 mode |= PRSFS_ADMINISTER;
999 printf("Illegal -implicit rights character '%c'.\n", tc);
1008 * Limit MAX_FILESERVER_THREAD by the system limit on the number of
1009 * pthreads (sysconf(_SC_THREAD_THREADS_MAX)), if applicable and
1012 * AIX: sysconf() limit is real
1013 * HP-UX: sysconf() limit is real
1014 * IRIX: sysconf() limit is apparently NOT real -- too small
1015 * DUX: sysconf() limit is apparently NOT real -- too big
1016 * Linux: sysconf() limit is apparently NOT real -- too big
1017 * Solaris: no sysconf() limit
1020 max_fileserver_thread(void)
1022 #if defined(AFS_PTHREAD_ENV)
1023 #if defined(AFS_AIX_ENV) || defined(AFS_HPUX_ENV)
1026 ans = sysconf(_SC_THREAD_THREADS_MAX);
1027 if (0 < ans && ans < MAX_FILESERVER_THREAD)
1030 #endif /* defined(AFS_PTHREAD_ENV) */
1031 return MAX_FILESERVER_THREAD;
1035 ParseArgs(int argc, char *argv[])
1037 int SawL = 0, SawS = 0, SawVC = 0;
1038 int Sawrxpck = 0, Sawsmall = 0, Sawlarge = 0, Sawcbs = 0, Sawlwps =
1042 int bufSize = 0; /* temp variable to read in udp socket buf size */
1044 for (i = 1; i < argc; i++) {
1045 if (!strcmp(argv[i], "-d")) {
1046 if ((i + 1) >= argc) {
1047 fprintf(stderr, "missing argument for -d\n");
1050 debuglevel = atoi(argv[++i]);
1051 LogLevel = debuglevel;
1052 } else if (!strcmp(argv[i], "-banner")) {
1054 } else if (!strcmp(argv[i], "-implicit")) {
1055 if ((i + 1) >= argc) {
1056 fprintf(stderr, "missing argument for -implicit\n");
1059 implicitAdminRights = ParseRights(argv[++i]);
1060 if (implicitAdminRights < 0)
1061 return implicitAdminRights;
1062 } else if (!strcmp(argv[i], "-readonly")) {
1064 } else if (!strcmp(argv[i], "-L")) {
1066 } else if (!strcmp(argv[i], "-S")) {
1068 } else if (!strcmp(argv[i], "-p")) {
1070 max_fileserver_thread() - FILESERVER_HELPER_THREADS;
1072 if ((i + 1) >= argc) {
1073 fprintf(stderr, "missing argument for -p\n");
1076 lwps = atoi(argv[++i]);
1077 if (lwps > lwps_max)
1081 } else if (!strcmp(argv[i], "-b")) {
1083 if ((i + 1) >= argc) {
1084 fprintf(stderr, "missing argument for -b\n");
1087 buffs = atoi(argv[++i]);
1088 } else if (!strcmp(argv[i], "-l")) {
1090 if ((i + 1) >= argc) {
1091 fprintf(stderr, "missing argument for -l\n");
1094 large = atoi(argv[++i]);
1095 } else if (!strcmp(argv[i], "-vc")) {
1097 if ((i + 1) >= argc) {
1098 fprintf(stderr, "missing argument for -vc\n");
1101 volcache = atoi(argv[++i]);
1102 } else if (!strcmp(argv[i], "-novbc")) {
1104 } else if (!strcmp(argv[i], "-rxpck")) {
1106 if ((i + 1) >= argc) {
1107 fprintf(stderr, "missing argument for -rxpck\n");
1110 rxpackets = atoi(argv[++i]);
1111 #ifdef AFS_PTHREAD_ENV
1112 } else if (!strcmp(argv[i], "-vattachpar")) {
1113 if ((i + 1) >= argc) {
1114 fprintf(stderr, "missing argument for %s\n", argv[i]);
1117 vol_attach_threads = atoi(argv[++i]);
1118 #endif /* AFS_PTHREAD_ENV */
1119 #ifdef AFS_DEMAND_ATTACH_FS
1120 } else if (!strcmp(argv[i], "-fs-state-dont-save")) {
1121 fs_state.options.fs_state_save = 0;
1122 } else if (!strcmp(argv[i], "-fs-state-dont-restore")) {
1123 fs_state.options.fs_state_restore = 0;
1124 } else if (!strcmp(argv[i], "-fs-state-verify")) {
1125 if ((i + 1) >= argc) {
1126 fprintf(stderr, "missing argument for %s\n", argv[i]);
1130 if (!strcmp(argv[i], "none")) {
1131 fs_state.options.fs_state_verify_before_save = 0;
1132 fs_state.options.fs_state_verify_after_restore = 0;
1133 } else if (!strcmp(argv[i], "save")) {
1134 fs_state.options.fs_state_verify_after_restore = 0;
1135 } else if (!strcmp(argv[i], "restore")) {
1136 fs_state.options.fs_state_verify_before_save = 0;
1137 } else if (!strcmp(argv[i], "both")) {
1140 fprintf(stderr, "invalid argument for %s\n", argv[i-1]);
1143 } else if (!strcmp(argv[i], "-vhashsize")) {
1144 if ((i + 1) >= argc) {
1145 fprintf(stderr, "missing argument for %s\n", argv[i]);
1148 VSetVolHashSize(atoi(argv[++i]));
1149 } else if (!strcmp(argv[i], "-vlrudisable")) {
1150 VLRU_SetOptions(VLRU_SET_ENABLED, 0);
1151 } else if (!strcmp(argv[i], "-vlruthresh")) {
1152 if ((i + 1) >= argc) {
1153 fprintf(stderr, "missing argument for %s\n", argv[i]);
1156 VLRU_SetOptions(VLRU_SET_THRESH, 60*atoi(argv[++i]));
1157 } else if (!strcmp(argv[i], "-vlruinterval")) {
1158 if ((i + 1) >= argc) {
1159 fprintf(stderr, "missing argument for %s\n", argv[i]);
1162 VLRU_SetOptions(VLRU_SET_INTERVAL, atoi(argv[++i]));
1163 } else if (!strcmp(argv[i], "-vlrumax")) {
1164 if ((i + 1) >= argc) {
1165 fprintf(stderr, "missing argument for %s\n", argv[i]);
1168 VLRU_SetOptions(VLRU_SET_MAX, atoi(argv[++i]));
1169 #endif /* AFS_DEMAND_ATTACH_FS */
1170 } else if (!strcmp(argv[i], "-s")) {
1172 if ((i + 1) >= argc) {
1173 fprintf(stderr, "missing argument for -s\n");
1176 nSmallVns = atoi(argv[++i]);
1177 } else if (!strcmp(argv[i], "-abortthreshold")) {
1178 if ((i + 1) >= argc) {
1179 fprintf(stderr, "missing argument for -abortthreshold\n");
1182 abort_threshold = atoi(argv[++i]);
1183 } else if (!strcmp(argv[i], "-k")) {
1184 if ((i + 1) >= argc) {
1185 fprintf(stderr, "missing argument for -k\n");
1188 stack = atoi(argv[++i]);
1190 #if defined(AFS_SGI_ENV)
1191 else if (!strcmp(argv[i], "-lock")) {
1195 else if (!strcmp(argv[i], "-spare")) {
1196 if ((i + 1) >= argc) {
1197 fprintf(stderr, "missing argument for -spare\n");
1200 BlocksSpare = atoi(argv[++i]);
1202 } else if (!strcmp(argv[i], "-pctspare")) {
1203 if ((i + 1) >= argc) {
1204 fprintf(stderr, "missing argument for -pctspare\n");
1207 PctSpare = atoi(argv[++i]);
1208 BlocksSpare = 0; /* has non-zero default */
1210 } else if (!strcmp(argv[i], "-w")) {
1211 if ((i + 1) >= argc) {
1212 fprintf(stderr, "missing argument for -w\n");
1215 fiveminutes = atoi(argv[++i]);
1216 } else if (!strcmp(argv[i], "-hr")) {
1218 if ((i + 1) >= argc) {
1219 fprintf(stderr, "missing argument for -hr\n");
1222 hr = atoi(argv[++i]);
1223 if ((hr < 1) || (hr > 36)) {
1225 ("host acl refresh interval of %d hours is invalid; hours must be between 1 and 36\n\n",
1229 hostaclRefresh = hr * 60 * 60;
1230 } else if (!strcmp(argv[i], "-rxdbg"))
1232 else if (!strcmp(argv[i], "-rxdbge"))
1234 else if (!strcmp(argv[i], "-cb")) {
1236 if ((i + 1) >= argc) {
1237 fprintf(stderr, "missing argument for -cb\n");
1240 numberofcbs = atoi(argv[++i]);
1241 if ((numberofcbs < 10000) || (numberofcbs > 2147483647)) {
1243 ("number of cbs %d invalid; must be between 10000 and 2147483647\n",
1247 } else if (!strcmp(argv[i], "-busyat")) {
1249 if ((i + 1) >= argc) {
1250 fprintf(stderr, "missing argument for -busyat\n");
1253 busy_threshold = atoi(argv[++i]);
1254 if (busy_threshold < 10) {
1256 ("Busy threshold %d is too low, will compute default.\n",
1260 } else if (!strcmp(argv[i], "-nobusy"))
1262 #ifdef AFS_AIX32_ENV
1263 else if (!strcmp(argv[i], "-m")) {
1264 extern int aixlow_water;
1265 if ((i + 1) >= argc) {
1266 fprintf(stderr, "missing argument for -m\n");
1269 aixlow_water = atoi(argv[++i]);
1270 if ((aixlow_water < 0) || (aixlow_water > 30)) {
1271 printf("space reserved %d% invalid; must be between 0-30%\n",
1277 else if (!strcmp(argv[i], "-nojumbo")) {
1279 } else if (!strcmp(argv[i], "-rxbind")) {
1281 } else if (!strcmp(argv[i], "-rxmaxmtu")) {
1282 if ((i + 1) >= argc) {
1283 fprintf(stderr, "missing argument for -rxmaxmtu\n");
1286 rxMaxMTU = atoi(argv[++i]);
1287 if ((rxMaxMTU < RX_MIN_PACKET_SIZE) ||
1288 (rxMaxMTU > RX_MAX_PACKET_DATA_SIZE)) {
1289 printf("rxMaxMTU %d%% invalid; must be between %d-%d\n",
1290 rxMaxMTU, RX_MIN_PACKET_SIZE,
1291 RX_MAX_PACKET_DATA_SIZE);
1294 } else if (!strcmp(argv[i], "-realm")) {
1295 extern char local_realms[AFS_NUM_LREALMS][AFS_REALM_SZ];
1296 extern int num_lrealms;
1297 if ((i + 1) >= argc) {
1298 fprintf(stderr, "missing argument for -realm\n");
1301 if (strlen(argv[++i]) >= AFS_REALM_SZ) {
1303 ("-realm argument must contain fewer than %d characters.\n",
1307 if (num_lrealms == -1)
1309 if (num_lrealms >= AFS_NUM_LREALMS) {
1311 ("a maximum of %d -realm arguments can be specified.\n",
1315 strncpy(local_realms[num_lrealms++], argv[i], AFS_REALM_SZ);
1316 } else if (!strcmp(argv[i], "-udpsize")) {
1317 if ((i + 1) >= argc) {
1318 printf("You have to specify -udpsize <integer value>\n");
1321 bufSize = atoi(argv[++i]);
1322 if (bufSize < rx_GetMinUdpBufSize())
1324 ("Warning:udpsize %d is less than minimum %d; ignoring\n",
1325 bufSize, rx_GetMinUdpBufSize());
1327 udpBufSize = bufSize;
1328 } else if (!strcmp(argv[i], "-sendsize")) {
1329 if ((i + 1) >= argc) {
1330 printf("You have to specify -sendsize <integer value>\n");
1333 bufSize = atoi(argv[++i]);
1334 if (bufSize < 16384)
1336 ("Warning:sendsize %d is less than minimum %d; ignoring\n",
1339 sendBufSize = bufSize;
1340 } else if (!strcmp(argv[i], "-enable_peer_stats")) {
1341 rx_enablePeerRPCStats();
1342 } else if (!strcmp(argv[i], "-enable_process_stats")) {
1343 rx_enableProcessRPCStats();
1345 else if (strcmp(argv[i], "-auditlog") == 0) {
1348 char oldName[MAXPATHLEN];
1349 char *fileName = argv[++i];
1351 #ifndef AFS_NT40_ENV
1352 struct stat statbuf;
1354 if ((lstat(fileName, &statbuf) == 0)
1355 && (S_ISFIFO(statbuf.st_mode))) {
1356 flags = O_WRONLY | O_NONBLOCK;
1360 strcpy(oldName, fileName);
1361 strcat(oldName, ".old");
1362 renamefile(fileName, oldName);
1363 flags = O_WRONLY | O_TRUNC | O_CREAT;
1365 tempfd = open(fileName, flags, 0666);
1367 auditout = fdopen(tempfd, "a");
1369 osi_audit_file(auditout);
1371 printf("Warning: auditlog %s not writable, ignored.\n", fileName);
1373 printf("Warning: auditlog %s not writable, ignored.\n", fileName);
1375 #ifndef AFS_NT40_ENV
1376 else if (strcmp(argv[i], "-syslog") == 0) {
1377 /* set syslog logging flag */
1378 serverLogSyslog = 1;
1379 } else if (strncmp(argv[i], "-syslog=", 8) == 0) {
1380 serverLogSyslog = 1;
1381 serverLogSyslogFacility = atoi(argv[i] + 8);
1384 else if (strcmp(argv[i], "-mrafslogs") == 0) {
1385 /* set syslog logging flag */
1393 printf("Only one of -L, or -S must be specified\n");
1404 numberofcbs = 20000;
1420 numberofcbs = 64000;
1429 busy_threshold = 3 * rxpackets / 2;
1439 NewParms(int initializing)
1441 static struct afs_stat sbuf;
1444 char *argv[MAXPARMS];
1447 if (!(afs_stat("/vice/file/parms", &sbuf))) {
1448 parms = (char *)malloc(sbuf.st_size);
1451 fd = afs_open("parms", O_RDONLY, 0666);
1453 ViceLog(0, ("Open for parms failed with errno = %d\n", errno));
1457 i = read(fd, parms, sbuf.st_size);
1459 if (i != sbuf.st_size) {
1461 ViceLog(0, ("Read on parms failed with errno = %d\n", errno));
1464 ("Read on parms failed; expected %d bytes but read %d\n",
1471 for (i = 0; i < MAXPARMS; argv[i++] = 0);
1473 for (argc = i = 0; i < sbuf.st_size; i++) {
1474 if ((*(parms + i) != ' ') && (*(parms + i) != '\n')) {
1475 if (argv[argc] == 0)
1476 argv[argc] = (parms + i);
1478 *(parms + i) = '\0';
1479 if (argv[argc] != 0) {
1480 if (++argc == MAXPARMS)
1483 while ((*(parms + i + 1) == ' ')
1484 || (*(parms + i + 1) == '\n'))
1488 if (ParseArgs(argc, argv) == 0) {
1489 ViceLog(0, ("Change parameters to:"));
1491 ViceLog(0, ("Invalid parameter in:"));
1493 for (i = 0; i < argc; i++) {
1494 ViceLog(0, (" %s", argv[i]));
1498 } else if (!initializing)
1500 ("Received request to change parms but no parms file exists\n"));
1505 /* Miscellaneous routines */
1509 ViceLog(0, ("%s\n", msg));
1521 * If this fails, it's because something major is wrong, and is not
1522 * likely to be time dependent.
1524 code = pr_Initialize(2, AFSDIR_SERVER_ETC_DIRPATH, 0);
1527 ("Couldn't initialize protection library; code=%d.\n", code));
1531 #ifdef AFS_PTHREAD_ENV
1532 assert(pthread_key_create(&viced_uclient_key, NULL) == 0);
1535 SystemId = SYSADMINID;
1536 SystemAnyUser = ANYUSERID;
1537 SystemAnyUserCPS.prlist_len = 0;
1538 SystemAnyUserCPS.prlist_val = NULL;
1539 AnonCPS.prlist_len = 0;
1540 AnonCPS.prlist_val = NULL;
1542 code = pr_GetCPS(SystemAnyUser, &SystemAnyUserCPS);
1545 ("Couldn't get CPS for AnyUser, will try again in 30 seconds; code=%d.\n",
1549 code = pr_GetCPS(ANONYMOUSID, &AnonCPS);
1552 ("Couldn't get Anonymous CPS, exiting; code=%d.\n",
1556 AnonymousID = ANONYMOUSID;
1559 #ifdef AFS_PTHREAD_ENV
1561 #else /* AFS_PTHREAD_ENV */
1563 #endif /* AFS_PTHREAD_ENV */
1567 struct rx_connection *serverconns[MAXSERVERS];
1568 struct ubik_client *cstruct;
1571 vl_Initialize(const char *confDir)
1573 afs_int32 code, scIndex = 0, i;
1574 struct afsconf_dir *tdir;
1575 struct rx_securityClass *sc;
1576 struct afsconf_cell info;
1578 tdir = afsconf_Open(confDir);
1581 ("Could not open configuration directory (%s).\n", confDir));
1584 code = afsconf_ClientAuth(tdir, &sc, &scIndex);
1586 ViceLog(0, ("Could not get security object for localAuth\n"));
1589 code = afsconf_GetCellInfo(tdir, NULL, AFSCONF_VLDBSERVICE, &info);
1590 if (info.numServers > MAXSERVERS) {
1592 ("vl_Initialize: info.numServers=%d (> MAXSERVERS=%d)\n",
1593 info.numServers, MAXSERVERS));
1596 for (i = 0; i < info.numServers; i++)
1598 rx_NewConnection(info.hostAddr[i].sin_addr.s_addr,
1599 info.hostAddr[i].sin_port, USER_SERVICE_ID, sc,
1601 code = ubik_ClientInit(serverconns, &cstruct);
1603 ViceLog(0, ("vl_Initialize: ubik client init failed.\n"));
1609 #define SYSIDMAGIC 0x88aabbcc
1610 #define SYSIDVERSION 1
1615 afs_int32 fd, nentries, i;
1616 struct versionStamp vsn;
1617 struct afs_stat status;
1620 if ((afs_stat(AFSDIR_SERVER_SYSID_FILEPATH, &status))
1621 || (status.st_size <= 0)) {
1622 ViceLog(0, ("%s: doesn't exist\n", AFSDIR_SERVER_SYSID_FILEPATH));
1625 if (!(fd = afs_open(AFSDIR_SERVER_SYSID_FILEPATH, O_RDONLY, 0))) {
1627 ("%s: can't open (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1631 if ((i = read(fd, (char *)&vsn, sizeof(vsn))) != sizeof(vsn)) {
1633 ("%s: Read failed (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1637 if (vsn.magic != SYSIDMAGIC) {
1639 ("%s: wrong magic %x (we support %x)\n",
1640 AFSDIR_SERVER_SYSID_FILEPATH, vsn.magic, SYSIDMAGIC));
1643 if (vsn.version != SYSIDVERSION) {
1645 ("%s: wrong version %d (we support %d)\n",
1646 AFSDIR_SERVER_SYSID_FILEPATH, vsn.version, SYSIDVERSION));
1650 read(fd, (char *)&uuid,
1651 sizeof(struct afsUUID))) != sizeof(struct afsUUID)) {
1653 ("%s: read of uuid failed (%d)\n",
1654 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1657 afs_ntohuuid(&uuid);
1660 read(fd, (char *)&nentries,
1661 sizeof(afs_int32))) != sizeof(afs_int32)) {
1663 ("%s: Read of entries failed (%d)\n",
1664 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1667 if (nentries <= 0 || nentries > ADDRSPERSITE) {
1669 ("%s: invalid num of interfaces: %d\n",
1670 AFSDIR_SERVER_SYSID_FILEPATH, nentries));
1673 FS_HostAddr_cnt = nentries;
1674 for (i = 0; i < nentries; i++) {
1675 if (read(fd, (char *)&FS_HostAddrs[i], sizeof(afs_int32)) !=
1676 sizeof(afs_int32)) {
1678 ("%s: Read of addresses failed (%d)\n",
1679 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1680 FS_HostAddr_cnt = 0; /* reset it */
1692 struct versionStamp vsn;
1693 struct afs_stat status;
1696 if (!afs_stat(AFSDIR_SERVER_SYSID_FILEPATH, &status)) {
1698 * File exists; keep the old one around
1700 renamefile(AFSDIR_SERVER_SYSID_FILEPATH,
1701 AFSDIR_SERVER_OLDSYSID_FILEPATH);
1703 fd = afs_open(AFSDIR_SERVER_SYSID_FILEPATH, O_WRONLY | O_TRUNC | O_CREAT,
1707 ("%s: can't create (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1711 vsn.magic = SYSIDMAGIC;
1713 if ((i = write(fd, (char *)&vsn, sizeof(vsn))) != sizeof(vsn)) {
1715 ("%s: write failed (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1720 afs_htonuuid(&uuid);
1722 write(fd, (char *)&uuid,
1723 sizeof(struct afsUUID))) != sizeof(struct afsUUID)) {
1725 ("%s: write of uuid failed (%d)\n",
1726 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1730 write(fd, (char *)&FS_HostAddr_cnt,
1731 sizeof(afs_int32))) != sizeof(afs_int32)) {
1733 ("%s: write of # of entries failed (%d)\n",
1734 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1737 for (i = 0; i < FS_HostAddr_cnt; i++) {
1738 if (write(fd, (char *)&FS_HostAddrs[i], sizeof(afs_int32)) !=
1739 sizeof(afs_int32)) {
1741 ("%s: write of addresses failed (%d)\n",
1742 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1752 * This routine sets up the buffers for the VL_RegisterAddrs RPC. All addresses
1753 * in FS_HostAddrs[] are in NBO, while the RPC treats them as a "blob" of data
1754 * and so we need to convert each of them into HBO which is what the extra
1755 * array called FS_HostAddrs_HBO is used here.
1762 extern int VL_RegisterAddrs();
1763 afs_uint32 FS_HostAddrs_HBO[ADDRSPERSITE];
1766 for (i = 0; i < FS_HostAddr_cnt; i++)
1767 FS_HostAddrs_HBO[i] = ntohl(FS_HostAddrs[i]);
1768 addrs.bulkaddrs_len = FS_HostAddr_cnt;
1769 addrs.bulkaddrs_val = (afs_uint32 *) FS_HostAddrs_HBO;
1770 code = ubik_VL_RegisterAddrs(cstruct, 0, &FS_HostUUID, 0, &addrs);
1772 if (code == VL_MULTIPADDR) {
1774 ("VL_RegisterAddrs rpc failed; The IP address exists on a different server; repair it\n"));
1776 ("VL_RegisterAddrs rpc failed; See VLLog for details\n"));
1778 } else if (code == RXGEN_OPCODE) {
1780 ("vlserver doesn't support VL_RegisterAddrs rpc; ignored\n"));
1781 FS_registered = 2; /* So we don't have to retry in the gc daemon */
1784 ("VL_RegisterAddrs rpc failed; will retry periodically (code=%d, err=%d)\n",
1788 FS_registered = 2; /* So we don't have to retry in the gc daemon */
1799 extern int rxi_numNetAddrs;
1800 extern afs_uint32 rxi_NetAddrs[];
1802 #ifndef AFS_NT40_ENV
1803 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH || AFSDIR_SERVER_NETINFO_FILEPATH) {
1805 * Find addresses we are supposed to register as per the netrestrict
1806 * and netinfo files (/usr/afs/local/NetInfo and
1807 * /usr/afs/local/NetRestict)
1810 afs_int32 code = parseNetFiles(FS_HostAddrs, NULL, NULL,
1811 ADDRSPERSITE, reason,
1812 AFSDIR_SERVER_NETINFO_FILEPATH,
1813 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
1815 ViceLog(0, ("Can't register any valid addresses: %s\n", reason));
1818 FS_HostAddr_cnt = (afs_uint32) code;
1822 FS_HostAddr_cnt = rx_getAllAddr(FS_HostAddrs, ADDRSPERSITE);
1825 if (FS_HostAddr_cnt == 1 && rxBind == 1)
1826 code = FS_HostAddrs[0];
1828 code = htonl(INADDR_ANY);
1838 * If this fails, it's because something major is wrong, and is not
1839 * likely to be time dependent.
1841 code = vl_Initialize(AFSDIR_SERVER_ETC_DIRPATH);
1844 ("Couldn't initialize protection library; code=%d.\n", code));
1848 /* Read or create the sysid file and register the fileserver's
1849 * IP addresses with the vlserver.
1851 code = ReadSysIdFile();
1853 /* Need to create the file */
1854 ViceLog(0, ("Creating new SysID file\n"));
1855 if ((code = afs_uuid_create(&FS_HostUUID))) {
1856 ViceLog(0, ("Failed to create new uuid: %d\n", code));
1860 /* A good sysid file exists; inform the vlserver. If any conflicts,
1861 * we always use the latest interface available as the real truth.
1864 code = Do_VLRegisterRPC();
1869 main(int argc, char *argv[])
1873 struct rx_securityClass *sc[4];
1874 struct rx_service *tservice;
1875 #ifdef AFS_PTHREAD_ENV
1876 pthread_t serverPid;
1877 pthread_attr_t tattr;
1878 #else /* AFS_PTHREAD_ENV */
1879 PROCESS parentPid, serverPid;
1880 #endif /* AFS_PTHREAD_ENV */
1882 int minVnodesRequired; /* min size of vnode cache */
1883 #ifndef AFS_NT40_ENV
1884 struct rlimit rlim; /* max number of open file descriptors */
1888 afs_uint32 rx_bindhost;
1890 #ifdef AFS_AIX32_ENV
1891 struct sigaction nsa;
1893 sigemptyset(&nsa.sa_mask);
1894 nsa.sa_handler = SIG_DFL;
1895 nsa.sa_flags = SA_FULLDUMP;
1896 sigaction(SIGABRT, &nsa, NULL);
1897 sigaction(SIGSEGV, &nsa, NULL);
1901 /* Initialize dirpaths */
1902 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
1904 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
1906 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
1910 #ifndef AFS_QUIETFS_ENV
1911 console = afs_fopen("/dev/console", "w");
1914 if (ParseArgs(argc, argv)) {
1918 #ifdef AFS_PTHREAD_ENV
1919 assert(pthread_mutex_init(&fileproc_glock_mutex, NULL) == 0);
1920 #endif /* AFS_PTHREAD_ENV */
1922 #ifdef AFS_SGI_VNODE_GLUE
1923 if (afs_init_kernel_config(-1) < 0) {
1925 ("Can't determine NUMA configuration, not starting fileserver.\n");
1929 confDir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
1931 fprintf(stderr, "Unable to open config directory %s\n",
1932 AFSDIR_SERVER_ETC_DIRPATH);
1938 /* Open FileLog on stdout, stderr, fd 1 and fd2 (for perror), sigh. */
1939 #ifndef AFS_NT40_ENV
1940 serverLogSyslogTag = "fileserver";
1942 OpenLog(AFSDIR_SERVER_FILELOG_FILEPATH);
1945 if (SawSpare && SawPctSpare) {
1946 ViceLog(0, ("Both -spare and -pctspare specified, exiting.\n"));
1949 #ifdef AFS_SGI_XFS_IOPS_ENV
1950 ViceLog(0, ("XFS/EFS File server starting\n"));
1952 ViceLog(0, ("File server starting\n"));
1955 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
1956 /* initialize the pthread soft signal handler thread */
1960 /* install signal handlers for controlling the fileserver process */
1961 ResetCheckSignal(); /* set CheckSignal_Signal() sig handler */
1962 ResetCheckDescriptors(); /* set CheckDescriptors_Signal() sig handler */
1964 #if defined(AFS_SGI_ENV)
1965 /* give this guy a non-degrading priority so help busy servers */
1966 schedctl(NDPRI, 0, NDPNORMMAX);
1970 #ifndef AFS_NT40_ENV
1971 nice(-5); /* TODO: */
1974 assert(DInit(buffs) == 0);
1977 if (afs_winsockInit() < 0) {
1978 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
1979 ViceLog(0, ("File server failed to intialize winsock.\n"));
1985 /* if we support more than 16 threads, then we better have the ability
1986 ** to keep open a large number of files simultaneously
1988 #if defined(AFS_AIX_ENV) && !defined(AFS_AIX42_ENV)
1989 curLimit = OPEN_MAX; /* for pre AIX 4.2 systems */
1990 #elif defined(AFS_NT40_ENV)
1991 curLimit = NT_OPEN_MAX; /* open file descriptor limit on NT */
1994 curLimit = 0; /* the number of open file descriptors */
1995 code = getrlimit(RLIMIT_NOFILE, &rlim);
1997 curLimit = rlim.rlim_cur;
1998 rlim.rlim_cur = rlim.rlim_max;
1999 code = setrlimit(RLIMIT_NOFILE, &rlim);
2001 curLimit = rlim.rlim_max;
2004 ViceLog(0, ("Failed to increase open file limit, using default\n"));
2006 #endif /* defined(AFS_AIX_ENV) && !defined(AFS_AIX42_ENV) */
2008 curLimit -= 32; /* leave a slack of 32 file descriptors */
2009 if (lwps > curLimit) {
2013 lwps = 16; /* default to a maximum of 16 threads */
2015 ("The system supports a max of %d open files and we are starting %d threads\n",
2018 #ifndef AFS_PTHREAD_ENV
2019 assert(LWP_InitializeProcessSupport(LWP_MAX_PRIORITY - 2, &parentPid) ==
2021 #endif /* !AFS_PTHREAD_ENV */
2023 /* Initialize volume support */
2025 V_BreakVolumeCallbacks = BreakVolumeCallBacksLater;
2028 #ifdef AFS_PTHREAD_ENV
2029 SetLogThreadNumProgram( threadNum );
2032 /* initialize libacl routines */
2033 acl_Initialize(ACL_VERSION);
2035 /* initialize RX support */
2036 #ifndef AFS_NT40_ENV
2037 rxi_syscallp = viced_syscall;
2039 rx_extraPackets = rxpackets;
2040 rx_extraQuota = 4; /* for outgoing prserver calls from R threads */
2041 rx_SetBusyThreshold(busy_threshold, VBUSY);
2042 rx_SetCallAbortThreshold(abort_threshold);
2043 rx_SetConnAbortThreshold(abort_threshold);
2044 stackSize = lwps * 4000;
2045 if (stackSize < 32000)
2047 else if (stackSize > 44000)
2049 #if defined(AFS_HPUX_ENV) || defined(AFS_SUN_ENV) || defined(AFS_SGI51_ENV)
2050 rx_SetStackSize(1, stackSize);
2053 rx_SetUdpBufSize(udpBufSize); /* set the UDP buffer size for receive */
2054 rx_bindhost = SetupVL();
2056 if (rx_InitHost(rx_bindhost, (int)htons(7000)) < 0) {
2057 ViceLog(0, ("Cannot initialize RX\n"));
2060 if (!rxJumbograms) {
2061 /* Don't send and don't allow 3.4 clients to send jumbograms. */
2064 if (rxMaxMTU != -1) {
2065 rx_SetMaxMTU(rxMaxMTU);
2068 rx_SetRxDeadTime(30);
2069 sc[0] = rxnull_NewServerSecurityObject();
2070 sc[1] = 0; /* rxvab_NewServerSecurityObject(key1, 0) */
2071 sc[2] = rxkad_NewServerSecurityObject(rxkad_clear, NULL, get_key, NULL);
2072 sc[3] = rxkad_NewServerSecurityObject(rxkad_crypt, NULL, get_key, NULL);
2073 tservice = rx_NewServiceHost(rx_bindhost, /* port */ 0, /* service id */
2074 1, /*service name */
2076 /* security classes */ sc,
2077 /* numb sec classes */
2078 4, RXAFS_ExecuteRequest);
2081 ("Failed to initialize RX, probably two servers running.\n"));
2084 rx_SetMinProcs(tservice, 3);
2085 rx_SetMaxProcs(tservice, lwps);
2086 rx_SetCheckReach(tservice, 1);
2089 rx_NewService(0, RX_STATS_SERVICE_ID, "rpcstats", sc, 4,
2090 RXSTATS_ExecuteRequest);
2092 ViceLog(0, ("Failed to initialize rpc stat service.\n"));
2095 rx_SetMinProcs(tservice, 2);
2096 rx_SetMaxProcs(tservice, 4);
2099 * Enable RX hot threads, which allows the listener thread to trade
2100 * places with an idle thread and moves the context switch from listener
2101 * to worker out of the critical path.
2103 rx_EnableHotThread();
2105 /* Some rx debugging */
2106 if (rxlog || eventlog) {
2107 debugFile = afs_fopen("rx_dbg", "w");
2109 rx_debugFile = debugFile;
2111 rxevent_debugFile = debugFile;
2114 init_sys_error_to_et(); /* Set up error table translation */
2115 h_InitHostPackage(); /* set up local cellname and realmname */
2116 InitCallBack(numberofcbs);
2121 ViceLog(0, ("Fatal error in library initialization, exiting!!\n"));
2127 ViceLog(0, ("Fatal error in protection initialization, exiting!!\n"));
2131 /* allow super users to manage RX statistics */
2132 rx_SetRxStatUserOk(fs_rxstat_userok);
2134 rx_StartServer(0); /* now start handling requests */
2136 /* we ensure that there is enough space in the vnode buffer to satisfy
2137 ** requests from all concurrent threads.
2138 ** the maximum number of vnodes used by a single thread at any one time
2139 ** is three ( "link" uses three vnodes simultaneously, one vLarge and
2140 ** two vSmall for linking files and two vLarge and one vSmall for linking
2143 minVnodesRequired = 2 * lwps + 1;
2144 if (minVnodesRequired > nSmallVns) {
2145 nSmallVns = minVnodesRequired;
2147 ("Overriding -s command line parameter with %d\n",
2150 if (minVnodesRequired > large) {
2151 large = minVnodesRequired;
2152 ViceLog(0, ("Overriding -l command line parameter with %d\n", large));
2155 /* We now do this after getting the listener up and running, so that client
2156 * connections don't timeout (maybe) if a file server is restarted, since it
2157 * will be available "real soon now". Worry about whether we can satisfy the
2158 * calls in the volume package itself.
2160 if (VInitVolumePackage(fileServer, large, nSmallVns, 0, volcache)) {
2162 ("Shutting down: errors encountered initializing volume package\n"));
2167 #ifdef AFS_DEMAND_ATTACH_FS
2168 if (fs_state.options.fs_state_restore) {
2171 * restore fileserver state */
2174 #endif /* AFS_DEMAND_ATTACH_FS */
2177 * We are done calling fopen/fdopen. It is safe to use a large
2178 * of the file descriptor cache.
2182 #ifdef AFS_PTHREAD_ENV
2183 ViceLog(5, ("Starting pthreads\n"));
2184 assert(pthread_attr_init(&tattr) == 0);
2185 assert(pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED) == 0);
2187 assert(pthread_create
2188 (&serverPid, &tattr, (void *)FiveMinuteCheckLWP,
2189 &fiveminutes) == 0);
2190 assert(pthread_create
2191 (&serverPid, &tattr, (void *)HostCheckLWP, &fiveminutes) == 0);
2192 assert(pthread_create
2193 (&serverPid, &tattr, (void *)FsyncCheckLWP, &fiveminutes) == 0);
2194 #else /* AFS_PTHREAD_ENV */
2195 ViceLog(5, ("Starting LWP\n"));
2196 assert(LWP_CreateProcess
2197 (FiveMinuteCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
2198 (void *)&fiveminutes, "FiveMinuteChecks",
2199 &serverPid) == LWP_SUCCESS);
2201 assert(LWP_CreateProcess
2202 (HostCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
2203 (void *)&fiveminutes, "HostCheck", &serverPid) == LWP_SUCCESS);
2204 assert(LWP_CreateProcess
2205 (FsyncCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
2206 (void *)&fiveminutes, "FsyncCheck", &serverPid) == LWP_SUCCESS);
2207 #endif /* AFS_PTHREAD_ENV */
2209 TM_GetTimeOfDay(&tp, 0);
2211 #ifndef AFS_QUIETFS_ENV
2212 if (console != NULL) {
2213 time_t t = tp.tv_sec;
2214 fprintf(console, "File server has started at %s\r",
2215 afs_ctime(&t, tbuffer, sizeof(tbuffer)));
2220 * Figure out the FileServer's name and primary address.
2222 ViceLog(0, ("Getting FileServer name...\n"));
2223 code = gethostname(FS_HostName, 64);
2225 ViceLog(0, ("gethostname() failed\n"));
2227 ViceLog(0, ("FileServer host name is '%s'\n", FS_HostName));
2229 ViceLog(0, ("Getting FileServer address...\n"));
2230 he = gethostbyname(FS_HostName);
2232 ViceLog(0, ("Can't find address for FileServer '%s'\n", FS_HostName));
2235 memcpy(&FS_HostAddr_NBO, he->h_addr, 4);
2236 (void)afs_inet_ntoa_r(FS_HostAddr_NBO, hoststr);
2237 FS_HostAddr_HBO = ntohl(FS_HostAddr_NBO);
2239 ("FileServer %s has address %s (0x%x or 0x%x in host byte order)\n",
2240 FS_HostName, hoststr, FS_HostAddr_NBO, FS_HostAddr_HBO));
2243 /* Install handler to catch the shutdown signal;
2244 * bosserver assumes SIGQUIT shutdown
2246 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
2247 softsig_signal(SIGQUIT, ShutDown_Signal);
2249 (void)signal(SIGQUIT, ShutDown_Signal);
2254 ("File Server started %s",
2255 afs_ctime(&t, tbuffer, sizeof(tbuffer))));
2256 #if FS_STATS_DETAILED
2257 afs_FullPerfStats.det.epoch.tv_sec = StartTime = tp.tv_sec;
2259 #ifdef AFS_PTHREAD_ENV
2261 sleep(1000); /* long time */
2263 #else /* AFS_PTHREAD_ENV */
2264 assert(LWP_WaitProcess(&parentPid) == LWP_SUCCESS);
2265 #endif /* AFS_PTHREAD_ENV */