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>
81 #include <afs/afs_args.h>
82 #include <afs/vlserver.h>
83 #include <afs/afsutil.h>
84 #include <afs/fileutil.h>
85 #include <afs/ptuser.h>
86 #include <afs/audit.h>
87 #include <afs/partition.h>
89 #include <afs/netutils.h>
93 #ifdef AFS_PTHREAD_ENV
96 #if defined(AFS_SGI_ENV)
97 #include "sys/schedctl.h"
100 #include <rx/rx_globals.h>
103 #define afs_stat stat64
104 #define afs_fstat fstat64
105 #define afs_open open64
106 #define afs_fopen fopen64
107 #else /* !O_LARGEFILE */
108 #define afs_stat stat
109 #define afs_fstat fstat
110 #define afs_open open
111 #define afs_fopen fopen
112 #endif /* !O_LARGEFILE */
114 extern int BreakVolumeCallBacks(), InitCallBack();
115 extern int BreakVolumeCallBacks(), InitCallBack(), BreakLaterCallBacks();
116 extern int BreakVolumeCallBacksLater();
117 extern int LogLevel, etext;
118 extern afs_int32 BlocksSpare, PctSpare;
121 static void ClearXStatValues(), NewParms(), PrintCounters();
122 static void ResetCheckDescriptors(void), ResetCheckSignal(void);
123 static int CheckSignal(void);
124 extern int GetKeysFromToken();
125 extern int RXAFS_ExecuteRequest();
126 extern int RXSTATS_ExecuteRequest();
127 afs_int32 Do_VLRegisterRPC();
129 int eventlog = 0, rxlog = 0;
131 FILE *console = NULL;
133 #ifdef AFS_PTHREAD_ENV
134 pthread_mutex_t fsync_glock_mutex;
135 pthread_cond_t fsync_cond;
138 #endif /* AFS_PTHREAD_ENV */
141 #define AFS_QUIETFS_ENV 1
142 #define NT_OPEN_MAX 1024 /* This is an arbitrary no. we came up with for
143 * now. We hope this will be replaced by a more
144 * intelligent estimate later. */
147 int SystemId; /* ViceID of "Administrators" */
148 int SystemAnyUser; /* Viceid of "System:AnyUser" */
149 prlist SystemAnyUserCPS; /* CPS for "system:AnyUser */
150 int AnonymousID = 0; /* ViceId of "Anonymous" */
151 prlist AnonCPS; /* CPS for "Anonymous" */
153 struct afsconf_dir *confDir; /* Configuration dir object */
155 int restartMode = RESTART_ORDINARY;
158 * Home for the performance statistics.
160 struct afs_PerfStats afs_perfstats;
163 extern int Statistics;
171 int rxJumbograms = 1; /* default is to send and receive jumbograms. */
172 int rxBind = 0; /* don't bind */
174 afs_int32 implicitAdminRights = PRSFS_LOOKUP; /* The ADMINISTER right is
176 afs_int32 readonlyServer = 0;
179 int stackSize = 24000;
180 int fiveminutes = 300; /* 5 minutes. Change this for debugging only */
181 int CurrentConnections = 0;
182 int hostaclRefresh = 7200; /* refresh host clients' acls every 2 hrs */
183 #if defined(AFS_SGI_ENV)
188 int rxpackets = 150; /* 100 */
189 int nSmallVns = 400; /* 200 */
190 int large = 400; /* 200 */
191 int volcache = 400; /* 400 */
192 int numberofcbs = 60000; /* 60000 */
193 int lwps = 9; /* 6 */
194 int buffs = 90; /* 70 */
195 int novbc = 0; /* Enable Volume Break calls */
196 int busy_threshold = 600;
197 int abort_threshold = 10;
198 int udpBufSize = 0; /* UDP buffer size for receive */
199 int sendBufSize = 16384; /* send buffer size */
200 int saneacls = 0; /* Sane ACLs Flag */
204 #ifdef AFS_PTHREAD_ENV
205 pthread_key_t viced_uclient_key;
208 #ifdef AFS_PTHREAD_ENV
209 pthread_key_t viced_uclient_key;
213 * FileServer's name and IP address, both network byte order and
216 #define ADDRSPERSITE 16 /* Same global is in rx/rx_user.c */
218 char FS_HostName[128] = "localhost";
219 afs_uint32 FS_HostAddr_NBO;
220 afs_uint32 FS_HostAddr_HBO;
221 afs_uint32 FS_HostAddrs[ADDRSPERSITE], FS_HostAddr_cnt = 0, FS_registered = 0;
222 /* All addresses in FS_HostAddrs are in NBO */
225 static void FlagMsg();
227 #ifdef AFS_DEMAND_ATTACH_FS
230 * fileserver mode support
232 * during fileserver shutdown, we have to track the graceful shutdown of
233 * certain background threads before we are allowed to dump state to
236 struct fs_state fs_state =
243 PTHREAD_COND_INITIALIZER,
244 PTHREAD_RWLOCK_INITIALIZER
246 #endif /* AFS_DEMAND_ATTACH_FS */
249 * Home for the performance statistics.
257 struct afs_stat status;
258 register int tsize = getdtablesize();
260 for (i = 0; i < tsize; i++) {
261 if (afs_fstat(i, &status) != -1) {
262 printf("%d: dev %x, inode %u, length %u, type/mode %x\n", i,
263 status.st_dev, status.st_ino, status.st_size,
268 ResetCheckDescriptors();
271 } /*CheckDescriptors */
274 #ifdef AFS_PTHREAD_ENV
276 CheckSignal_Signal(x)
288 CheckDescriptors_Signal(x)
292 #else /* AFS_PTHREAD_ENV */
294 CheckSignal_Signal(x)
296 IOMGR_SoftSig(CheckSignal, 0);
302 IOMGR_SoftSig(ShutDown, 0);
306 CheckDescriptors_Signal(x)
308 IOMGR_SoftSig(CheckDescriptors, 0);
310 #endif /* AFS_PTHREAD_ENV */
312 /* check whether caller is authorized to manage RX statistics */
314 fs_rxstat_userok(struct rx_call *call)
316 return afsconf_SuperUser(confDir, call, NULL);
320 ResetCheckSignal(void)
324 #if defined(AFS_HPUX_ENV)
327 #if defined(AFS_NT40_ENV)
334 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
335 softsig_signal(signo, CheckSignal_Signal);
337 signal(signo, CheckSignal_Signal);
342 ResetCheckDescriptors(void)
345 #if defined(AFS_PTHREAD_ENV)
346 softsig_signal(SIGTERM, CheckDescriptors_Signal);
348 (void)signal(SIGTERM, CheckDescriptors_Signal);
353 #if defined(AFS_PTHREAD_ENV)
357 return pthread_getspecific(rx_thread_id_key);
361 /* proc called by rxkad module to get a key */
363 get_key(char *arock, register afs_int32 akvno, char *akey)
366 static struct afsconf_key tkey;
367 register afs_int32 code;
370 ViceLog(0, ("conf dir not open\n"));
373 code = afsconf_GetKey(confDir, akvno, tkey.key);
375 ViceLog(0, ("afsconf_GetKey failure: kvno %d code %d\n", akvno, code));
378 memcpy(akey, tkey.key, sizeof(tkey.key));
385 viced_syscall(afs_uint32 a3, afs_uint32 a4, void *a5)
390 #ifndef AFS_LINUX20_ENV
391 old = (void (*)())signal(SIGSYS, SIG_IGN);
393 rcode = syscall(AFS_SYSCALL, 28 /* AFSCALL_CALL */ , a3, a4, a5);
394 #ifndef AFS_LINUX20_ENV
402 #if !defined(AFS_NT40_ENV)
403 #include "AFS_component_version_number.c"
404 #endif /* !AFS_NT40_ENV */
406 #define MAXADMINNAME 64
407 char adminName[MAXADMINNAME];
413 struct afs_stat status;
415 if ((afs_stat("/AdminName", &status)) || /* if file does not exist */
416 (status.st_size <= 0) || /* or it is too short */
417 (status.st_size >= (MAXADMINNAME)) || /* or it is too long */
418 !(fd = afs_open("/AdminName", O_RDONLY, 0))) { /* or the open fails */
419 strcpy(adminName, "System:Administrators"); /* use the default name */
421 (void)read(fd, adminName, status.st_size); /* use name from the file */
424 close(fd); /* close fd if it was opened */
426 } /*CheckAdminName */
432 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
433 /* set our 'thread-id' so that the host hold table works */
434 MUTEX_ENTER(&rx_stats_mutex); /* protects rxi_pthread_hinum */
436 pthread_setspecific(rx_thread_id_key, (void *)rxi_pthread_hinum);
437 MUTEX_EXIT(&rx_stats_mutex);
439 ("Set thread id %d for '%s'\n",
440 pthread_getspecific(rx_thread_id_key), s));
444 /* This LWP does things roughly every 5 minutes */
451 ViceLog(1, ("Starting five minute check process\n"));
452 setThreadId("FiveMinuteCheckLWP");
454 #ifdef AFS_DEMAND_ATTACH_FS
456 while (fs_state.mode == FS_MODE_NORMAL) {
457 fs_state.FiveMinuteLWP_tranquil = 1;
463 #ifdef AFS_PTHREAD_ENV
465 #else /* AFS_PTHREAD_ENV */
466 IOMGR_Sleep(fiveminutes);
467 #endif /* AFS_PTHREAD_ENV */
469 #ifdef AFS_DEMAND_ATTACH_FS
471 if (fs_state.mode != FS_MODE_NORMAL) {
474 fs_state.FiveMinuteLWP_tranquil = 0;
478 /* close the log so it can be removed */
479 ReOpenLog(AFSDIR_SERVER_FILELOG_FILEPATH); /* don't trunc, just append */
480 ViceLog(2, ("Cleaning up timed out callbacks\n"));
481 if (CleanupTimedOutCallBacks())
482 ViceLog(5, ("Timed out callbacks deleted\n"));
483 ViceLog(2, ("Set disk usage statistics\n"));
485 if (FS_registered == 1)
487 /* Force wakeup in case we missed something; pthreads does timedwait */
488 #ifndef AFS_PTHREAD_ENV
489 LWP_NoYieldSignal(fsync_wait);
491 if (printBanner && (++msg & 1)) { /* Every 10 minutes */
492 time_t now = FT_ApproxTime();
493 if (console != NULL) {
494 #ifndef AFS_QUIETFS_ENV
495 fprintf(console, "File server is running at %s\r",
496 afs_ctime(&now, tbuffer, sizeof(tbuffer)));
497 #endif /* AFS_QUIETFS_ENV */
499 ("File server is running at %s\n",
500 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
503 #ifdef AFS_DEMAND_ATTACH_FS
507 #ifdef AFS_DEMAND_ATTACH_FS
508 fs_state.FiveMinuteLWP_tranquil = 1;
510 assert(pthread_cond_broadcast(&fs_state.worker_done_cv)==0);
514 } /*FiveMinuteCheckLWP */
517 /* This LWP does host checks every 5 minutes: it should not be used for
518 * other 5 minute activities because it may be delayed by timeouts when
519 * it probes the workstations
525 ViceLog(1, ("Starting Host check process\n"));
526 setThreadId("HostCheckLWP");
527 #ifdef AFS_DEMAND_ATTACH_FS
529 while (fs_state.mode == FS_MODE_NORMAL) {
530 fs_state.HostCheckLWP_tranquil = 1;
536 #ifdef AFS_PTHREAD_ENV
538 #else /* AFS_PTHREAD_ENV */
539 IOMGR_Sleep(fiveminutes);
540 #endif /* AFS_PTHREAD_ENV */
542 #ifdef AFS_DEMAND_ATTACH_FS
544 if (fs_state.mode != FS_MODE_NORMAL) {
547 fs_state.HostCheckLWP_tranquil = 0;
551 ViceLog(2, ("Checking for dead venii & clients\n"));
554 #ifdef AFS_DEMAND_ATTACH_FS
558 #ifdef AFS_DEMAND_ATTACH_FS
559 fs_state.HostCheckLWP_tranquil = 1;
561 assert(pthread_cond_broadcast(&fs_state.worker_done_cv)==0);
567 /* This LWP does fsync checks every 5 minutes: it should not be used for
568 * other 5 minute activities because it may be delayed by timeouts when
569 * it probes the workstations
575 #ifdef AFS_PTHREAD_ENV
576 struct timespec fsync_next;
578 ViceLog(1, ("Starting fsync check process\n"));
580 setThreadId("FsyncCheckLWP");
582 #ifdef AFS_PTHREAD_ENV
583 assert(pthread_cond_init(&fsync_cond, NULL) == 0);
584 assert(pthread_mutex_init(&fsync_glock_mutex, NULL) == 0);
587 #ifdef AFS_DEMAND_ATTACH_FS
589 while (fs_state.mode == FS_MODE_NORMAL) {
590 fs_state.FsyncCheckLWP_tranquil = 1;
596 #ifdef AFS_PTHREAD_ENV
597 /* rounding is fine */
598 fsync_next.tv_nsec = 0;
599 fsync_next.tv_sec = time(0) + fiveminutes;
602 pthread_cond_timedwait(&fsync_cond, &fsync_glock_mutex,
604 if (code != 0 && code != ETIMEDOUT)
605 ViceLog(0, ("pthread_cond_timedwait returned %d\n", code));
606 #else /* AFS_PTHREAD_ENV */
607 if ((code = LWP_WaitProcess(fsync_wait)) != LWP_SUCCESS)
608 ViceLog(0, ("LWP_WaitProcess returned %d\n", code));
609 #endif /* AFS_PTHREAD_ENV */
612 #ifdef AFS_DEMAND_ATTACH_FS
614 if (fs_state.mode != FS_MODE_NORMAL) {
617 fs_state.FsyncCheckLWP_tranquil = 0;
619 #endif /* AFS_DEMAND_ATTACH_FS */
621 ViceLog(2, ("Checking for fsync events\n"));
623 code = BreakLaterCallBacks();
625 #ifdef AFS_DEMAND_ATTACH_FS
629 #ifdef AFS_DEMAND_ATTACH_FS
630 fs_state.FsyncCheckLWP_tranquil = 1;
632 assert(pthread_cond_broadcast(&fs_state.worker_done_cv)==0);
635 #endif /* AFS_DEMAND_ATTACH_FS */
638 /*------------------------------------------------------------------------
639 * PRIVATE ClearXStatValues
642 * Initialize all of the values collected via the xstat
652 * Must be called during File Server initialization.
656 *------------------------------------------------------------------------*/
660 { /*ClearXStatValues */
662 struct fs_stats_opTimingData *opTimeP; /*Ptr to timing struct */
663 struct fs_stats_xferData *opXferP; /*Ptr to xfer struct */
664 int i; /*Loop counter */
667 * Zero all xstat-related structures.
669 memset((char *)(&afs_perfstats), 0, sizeof(struct afs_PerfStats));
670 #if FS_STATS_DETAILED
671 memset((char *)(&afs_FullPerfStats), 0,
672 sizeof(struct fs_stats_FullPerfStats));
675 * That's not enough. We have to set reasonable minima for
676 * time and xfer values in the detailed stats.
678 opTimeP = &(afs_FullPerfStats.det.rpcOpTimes[0]);
679 for (i = 0; i < FS_STATS_NUM_RPC_OPS; i++, opTimeP++)
680 opTimeP->minTime.tv_sec = 999999;
682 opXferP = &(afs_FullPerfStats.det.xferOpTimes[0]);
683 for (i = 0; i < FS_STATS_NUM_XFER_OPS; i++, opXferP++) {
684 opXferP->minTime.tv_sec = 999999;
685 opXferP->minBytes = 999999999;
689 * There's more. We have to set our unique system identifier, as
690 * declared in param.h. If such a thing is not defined, we bitch
691 * and declare ourselves to be an unknown system type.
694 afs_perfstats.sysname_ID = SYS_NAME_ID;
697 ViceLog(0, ("Sys name ID constant not defined in param.h!!\n"));
698 ViceLog(0, ("[Choosing ``undefined'' sys name ID.\n"));
700 afs_perfstats.sysname_ID = SYS_NAME_ID_UNDEFINED;
701 #endif /* SYS_NAME_ID */
704 } /*ClearXStatValues */
710 int dirbuff, dircall, dirio;
712 int workstations, activeworkstations, delworkstations;
716 TM_GetTimeOfDay(&tpl, 0);
719 ("Vice was last started at %s\n",
720 afs_ctime(&StartTime, tbuffer, sizeof(tbuffer))));
722 #ifdef AFS_DEMAND_ATTACH_FS
723 /* XXX perhaps set extended stats verbosity flags
724 * based upon LogLevel ?? */
725 VPrintExtendedCacheStats(VOL_STATS_PER_CHAIN2);
729 DStat(&dirbuff, &dircall, &dirio);
731 ("With %d directory buffers; %d reads resulted in %d read I/Os\n",
732 dirbuff, dircall, dirio));
733 rx_PrintStats(stderr);
735 PrintCallBackStats();
737 processSize = -1; /* TODO: */
739 processSize = (int)((long)sbrk(0) >> 10);
742 ("There are %d connections, process size %d\n",
743 CurrentConnections, processSize));
744 h_GetWorkStats(&workstations, &activeworkstations, &delworkstations,
745 tpl.tv_sec - 15 * 60);
747 ("There are %d workstations, %d are active (req in < 15 mins), %d marked \"down\"\n",
748 workstations, activeworkstations, delworkstations));
758 if (FS_registered > 0) {
760 * We have proper ip addresses; tell the vlserver what we got; the following
761 * routine will do the proper reporting for us
774 ShutDownAndCore(int dopanic)
776 time_t now = time(0);
779 /* do not allows new reqests to be served from now on, all new requests
780 * are returned with an error code of RX_RESTARTING ( transient failure ) */
781 rx_SetRxTranquil(); /* dhruba */
783 #ifdef AFS_DEMAND_ATTACH_FS
785 fs_state.mode = FS_MODE_SHUTDOWN;
790 ("Shutting down file server at %s",
791 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
793 ViceLog(0, ("ABNORMAL SHUTDOWN, see core file.\n"));
794 #ifndef AFS_QUIETFS_ENV
795 if (console != NULL) {
796 fprintf(console, "File server restart/shutdown received at %s\r",
797 afs_ctime(&now, tbuffer, sizeof(tbuffer)));
804 /* shut down volume package */
807 #ifdef AFS_DEMAND_ATTACH_FS
808 if (fs_state.options.fs_state_save) {
811 * save fileserver state to disk */
813 /* make sure background threads have finished all of their asynchronous
814 * work on host and callback structures */
816 while (!fs_state.FiveMinuteLWP_tranquil ||
817 !fs_state.HostCheckLWP_tranquil ||
818 !fs_state.FsyncCheckLWP_tranquil) {
821 ViceLog(0, ("waiting for background host/callback threads to quiesce before saving fileserver state...\n"));
822 assert(pthread_cond_wait(&fs_state.worker_done_cv, &fileproc_glock_mutex) == 0);
827 /* ok. it should now be fairly safe. let's do the state dump */
830 #endif /* AFS_DEMAND_ATTACH_FS */
833 rx_PrintStats(debugFile);
836 if (console != NULL) {
839 #ifndef AFS_QUIETFS_ENV
840 fprintf(console, "File server has terminated abnormally at %s\r",
841 afs_ctime(&now, tbuffer, sizeof(tbuffer)));
844 ("File server has terminated abnormally at %s\n",
845 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
847 #ifndef AFS_QUIETFS_ENV
848 fprintf(console, "File server has terminated normally at %s\r",
849 afs_ctime(&now, tbuffer, sizeof(tbuffer)));
852 ("File server has terminated normally at %s\n",
853 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
862 { /* backward compatibility */
863 ShutDownAndCore(DONTPANIC);
871 /* default supports help flag */
873 fputs("Usage: fileserver ", stdout);
874 fputs("[-auditlog <log path>] ", stdout);
875 fputs("[-d <debug level>] ", stdout);
876 fputs("[-p <number of processes>] ", stdout);
877 fputs("[-spare <number of spare blocks>] ", stdout);
878 fputs("[-pctspare <percentage spare>] ", stdout);
879 fputs("[-b <buffers>] ", stdout);
880 fputs("[-l <large vnodes>] ", stdout);
881 fputs("[-s <small vnodes>] ", stdout);
882 fputs("[-vc <volume cachesize>] ", stdout);
883 fputs("[-w <call back wait interval>] ", stdout);
884 fputs("[-cb <number of call backs>] ", stdout);
885 fputs("[-banner (print banner every 10 minutes)] ", stdout);
886 fputs("[-novbc (whole volume cbs disabled)] ", stdout);
887 fputs("[-implicit <admin mode bits: rlidwka>] ", stdout);
888 fputs("[-readonly (read-only file server)] ", stdout);
889 fputs("[-hr <number of hours between refreshing the host cps>] ", stdout);
890 fputs("[-busyat <redirect clients when queue > n>] ", stdout);
891 fputs("[-nobusy <no VBUSY before a volume is attached>] ", stdout);
892 fputs("[-rxpck <number of rx extra packets>] ", stdout);
893 fputs("[-rxdbg (enable rx debugging)] ", stdout);
894 fputs("[-rxdbge (enable rxevent debugging)] ", stdout);
895 fputs("[-rxmaxmtu <bytes>] ", stdout);
896 fputs("[-rxbind (bind the Rx socket to one address)] ", stdout);
897 #ifdef AFS_DEMAND_ATTACH_FS
898 fputs("[-fs-state-dont-save (disable state save during shutdown)] ", stdout);
899 fputs("[-fs-state-dont-restore (disable state restore during startup)] ", stdout);
900 fputs("[-fs-state-verify <none|save|restore|both> (default is both)] ", stdout);
901 fputs("[-vattachpar <max number of volume attach/shutdown threads> (default is 1)] ", stdout);
902 fputs("[-vhashsize <log(2) of number of volume hash buckets> (default is 8)] ", stdout);
903 fputs("[-vlrudisable (disable VLRU functionality)] ", stdout);
904 fputs("[-vlruthresh <minutes before unused volumes become eligible for soft detach> (default is 2 hours)] ", stdout);
905 fputs("[-vlruinterval <seconds between VLRU scans> (default is 2 minutes)] ", stdout);
906 fputs("[-vlrumax <max volumes to soft detach in one VLRU scan> (default is 8)] ", stdout);
907 #elif AFS_PTHREAD_ENV
908 fputs("[-vattachpar <number of volume attach threads> (default is 1)] ", stdout);
911 fputs("[-m <min percentage spare in partition>] ", stdout);
913 #if defined(AFS_SGI_ENV)
914 fputs("[-lock (keep fileserver from swapping)] ", stdout);
916 fputs("[-L (large server conf)] ", stdout);
917 fputs("[-S (small server conf)] ", stdout);
918 fputs("[-k <stack size>] ", stdout);
919 fputs("[-realm <Kerberos realm name>] ", stdout);
920 fputs("[-udpsize <size of socket buffer in bytes>] ", stdout);
921 fputs("[-sendsize <size of send buffer in bytes>] ", stdout);
922 fputs("[-abortthreshold <abort threshold>] ", stdout);
923 /* fputs("[-enable_peer_stats] ", stdout); */
924 /* fputs("[-enable_process_stats] ", stdout); */
925 fputs("[-help]\n", stdout);
927 ViceLog(0, ("%s", buffer));
936 ParseRights(char *arights)
942 if (!arights || !strcmp(arights, "")) {
943 printf("Missing list of mode bits on -implicit option\n");
946 if (!strcmp(arights, "none"))
948 else if (!strcmp(arights, "read"))
949 mode = PRSFS_READ | PRSFS_LOOKUP;
950 else if (!strcmp(arights, "write"))
952 PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
953 PRSFS_WRITE | PRSFS_LOCK;
954 else if (!strcmp(arights, "all"))
956 PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
957 PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER;
959 len = strlen(arights);
960 for (i = 0; i < len; i++) {
965 mode |= PRSFS_LOOKUP;
967 mode |= PRSFS_INSERT;
969 mode |= PRSFS_DELETE;
975 mode |= PRSFS_ADMINISTER;
993 printf("Illegal -implicit rights character '%c'.\n", tc);
1002 * Limit MAX_FILESERVER_THREAD by the system limit on the number of
1003 * pthreads (sysconf(_SC_THREAD_THREADS_MAX)), if applicable and
1006 * AIX: sysconf() limit is real
1007 * HP-UX: sysconf() limit is real
1008 * IRIX: sysconf() limit is apparently NOT real -- too small
1009 * DUX: sysconf() limit is apparently NOT real -- too big
1010 * Linux: sysconf() limit is apparently NOT real -- too big
1011 * Solaris: no sysconf() limit
1014 max_fileserver_thread(void)
1016 #if defined(AFS_PTHREAD_ENV)
1017 #if defined(AFS_AIX_ENV) || defined(AFS_HPUX_ENV)
1020 ans = sysconf(_SC_THREAD_THREADS_MAX);
1021 if (0 < ans && ans < MAX_FILESERVER_THREAD)
1024 #endif /* defined(AFS_PTHREAD_ENV) */
1025 return MAX_FILESERVER_THREAD;
1029 ParseArgs(int argc, char *argv[])
1031 int SawL = 0, SawS = 0, SawVC = 0;
1032 int Sawrxpck = 0, Sawsmall = 0, Sawlarge = 0, Sawcbs = 0, Sawlwps =
1036 int bufSize = 0; /* temp variable to read in udp socket buf size */
1038 for (i = 1; i < argc; i++) {
1039 if (!strcmp(argv[i], "-d")) {
1040 if ((i + 1) >= argc) {
1041 fprintf(stderr, "missing argument for -d\n");
1044 debuglevel = atoi(argv[++i]);
1045 LogLevel = debuglevel;
1046 } else if (!strcmp(argv[i], "-banner")) {
1048 } else if (!strcmp(argv[i], "-implicit")) {
1049 if ((i + 1) >= argc) {
1050 fprintf(stderr, "missing argument for -implicit\n");
1053 implicitAdminRights = ParseRights(argv[++i]);
1054 if (implicitAdminRights < 0)
1055 return implicitAdminRights;
1056 } else if (!strcmp(argv[i], "-readonly")) {
1058 } else if (!strcmp(argv[i], "-L")) {
1060 } else if (!strcmp(argv[i], "-S")) {
1062 } else if (!strcmp(argv[i], "-p")) {
1064 max_fileserver_thread() - FILESERVER_HELPER_THREADS;
1066 if ((i + 1) >= argc) {
1067 fprintf(stderr, "missing argument for -p\n");
1070 lwps = atoi(argv[++i]);
1071 if (lwps > lwps_max)
1075 } else if (!strcmp(argv[i], "-b")) {
1077 if ((i + 1) >= argc) {
1078 fprintf(stderr, "missing argument for -b\n");
1081 buffs = atoi(argv[++i]);
1082 } else if (!strcmp(argv[i], "-l")) {
1084 if ((i + 1) >= argc) {
1085 fprintf(stderr, "missing argument for -l\n");
1088 large = atoi(argv[++i]);
1089 } else if (!strcmp(argv[i], "-vc")) {
1091 if ((i + 1) >= argc) {
1092 fprintf(stderr, "missing argument for -vc\n");
1095 volcache = atoi(argv[++i]);
1096 } else if (!strcmp(argv[i], "-novbc")) {
1098 } else if (!strcmp(argv[i], "-rxpck")) {
1100 if ((i + 1) >= argc) {
1101 fprintf(stderr, "missing argument for -rxpck\n");
1104 rxpackets = atoi(argv[++i]);
1105 #ifdef AFS_PTHREAD_ENV
1106 } else if (!strcmp(argv[i], "-vattachpar")) {
1107 if ((i + 1) >= argc) {
1108 fprintf(stderr, "missing argument for %s\n", argv[i]);
1111 vol_attach_threads = atoi(argv[++i]);
1112 #endif /* AFS_PTHREAD_ENV */
1113 #ifdef AFS_DEMAND_ATTACH_FS
1114 } else if (!strcmp(argv[i], "-fs-state-dont-save")) {
1115 fs_state.options.fs_state_save = 0;
1116 } else if (!strcmp(argv[i], "-fs-state-dont-restore")) {
1117 fs_state.options.fs_state_restore = 0;
1118 } else if (!strcmp(argv[i], "-fs-state-verify")) {
1119 if ((i + 1) >= argc) {
1120 fprintf(stderr, "missing argument for %s\n", argv[i]);
1124 if (!strcmp(argv[i], "none")) {
1125 fs_state.options.fs_state_verify_before_save = 0;
1126 fs_state.options.fs_state_verify_after_restore = 0;
1127 } else if (!strcmp(argv[i], "save")) {
1128 fs_state.options.fs_state_verify_after_restore = 0;
1129 } else if (!strcmp(argv[i], "restore")) {
1130 fs_state.options.fs_state_verify_before_save = 0;
1131 } else if (!strcmp(argv[i], "both")) {
1134 fprintf(stderr, "invalid argument for %s\n", argv[i-1]);
1137 } else if (!strcmp(argv[i], "-vhashsize")) {
1138 if ((i + 1) >= argc) {
1139 fprintf(stderr, "missing argument for %s\n", argv[i]);
1142 VSetVolHashSize(atoi(argv[++i]));
1143 } else if (!strcmp(argv[i], "-vlrudisable")) {
1144 VLRU_SetOptions(VLRU_SET_ENABLED, 0);
1145 } else if (!strcmp(argv[i], "-vlruthresh")) {
1146 if ((i + 1) >= argc) {
1147 fprintf(stderr, "missing argument for %s\n", argv[i]);
1150 VLRU_SetOptions(VLRU_SET_THRESH, 60*atoi(argv[++i]));
1151 } else if (!strcmp(argv[i], "-vlruinterval")) {
1152 if ((i + 1) >= argc) {
1153 fprintf(stderr, "missing argument for %s\n", argv[i]);
1156 VLRU_SetOptions(VLRU_SET_INTERVAL, atoi(argv[++i]));
1157 } else if (!strcmp(argv[i], "-vlrumax")) {
1158 if ((i + 1) >= argc) {
1159 fprintf(stderr, "missing argument for %s\n", argv[i]);
1162 VLRU_SetOptions(VLRU_SET_MAX, atoi(argv[++i]));
1163 #endif /* AFS_DEMAND_ATTACH_FS */
1164 } else if (!strcmp(argv[i], "-s")) {
1166 if ((i + 1) >= argc) {
1167 fprintf(stderr, "missing argument for -s\n");
1170 nSmallVns = atoi(argv[++i]);
1171 } else if (!strcmp(argv[i], "-abortthreshold")) {
1172 if ((i + 1) >= argc) {
1173 fprintf(stderr, "missing argument for -abortthreshold\n");
1176 abort_threshold = atoi(argv[++i]);
1177 } else if (!strcmp(argv[i], "-k")) {
1178 if ((i + 1) >= argc) {
1179 fprintf(stderr, "missing argument for -k\n");
1182 stack = atoi(argv[++i]);
1184 #if defined(AFS_SGI_ENV)
1185 else if (!strcmp(argv[i], "-lock")) {
1189 else if (!strcmp(argv[i], "-spare")) {
1190 if ((i + 1) >= argc) {
1191 fprintf(stderr, "missing argument for -spare\n");
1194 BlocksSpare = atoi(argv[++i]);
1196 } else if (!strcmp(argv[i], "-pctspare")) {
1197 if ((i + 1) >= argc) {
1198 fprintf(stderr, "missing argument for -pctspare\n");
1201 PctSpare = atoi(argv[++i]);
1202 BlocksSpare = 0; /* has non-zero default */
1204 } else if (!strcmp(argv[i], "-w")) {
1205 if ((i + 1) >= argc) {
1206 fprintf(stderr, "missing argument for -w\n");
1209 fiveminutes = atoi(argv[++i]);
1210 } else if (!strcmp(argv[i], "-hr")) {
1212 if ((i + 1) >= argc) {
1213 fprintf(stderr, "missing argument for -hr\n");
1216 hr = atoi(argv[++i]);
1217 if ((hr < 1) || (hr > 36)) {
1219 ("host acl refresh interval of %d hours is invalid; hours must be between 1 and 36\n\n",
1223 hostaclRefresh = hr * 60 * 60;
1224 } else if (!strcmp(argv[i], "-rxdbg"))
1226 else if (!strcmp(argv[i], "-rxdbge"))
1228 else if (!strcmp(argv[i], "-cb")) {
1230 if ((i + 1) >= argc) {
1231 fprintf(stderr, "missing argument for -cb\n");
1234 numberofcbs = atoi(argv[++i]);
1235 if ((numberofcbs < 10000) || (numberofcbs > 2147483647)) {
1237 ("number of cbs %d invalid; must be between 10000 and 2147483647\n",
1241 } else if (!strcmp(argv[i], "-busyat")) {
1243 if ((i + 1) >= argc) {
1244 fprintf(stderr, "missing argument for -busyat\n");
1247 busy_threshold = atoi(argv[++i]);
1248 if (busy_threshold < 10) {
1250 ("Busy threshold %d is too low, will compute default.\n",
1254 } else if (!strcmp(argv[i], "-nobusy"))
1256 #ifdef AFS_AIX32_ENV
1257 else if (!strcmp(argv[i], "-m")) {
1258 extern int aixlow_water;
1259 if ((i + 1) >= argc) {
1260 fprintf(stderr, "missing argument for -m\n");
1263 aixlow_water = atoi(argv[++i]);
1264 if ((aixlow_water < 0) || (aixlow_water > 30)) {
1265 printf("space reserved %d% invalid; must be between 0-30%\n",
1271 else if (!strcmp(argv[i], "-nojumbo")) {
1273 } else if (!strcmp(argv[i], "-rxbind")) {
1275 } else if (!strcmp(argv[i], "-rxmaxmtu")) {
1276 if ((i + 1) >= argc) {
1277 fprintf(stderr, "missing argument for -rxmaxmtu\n");
1280 rxMaxMTU = atoi(argv[++i]);
1281 if ((rxMaxMTU < RX_MIN_PACKET_SIZE) ||
1282 (rxMaxMTU > RX_MAX_PACKET_DATA_SIZE)) {
1283 printf("rxMaxMTU %d%% invalid; must be between %d-%d\n",
1284 rxMaxMTU, RX_MIN_PACKET_SIZE,
1285 RX_MAX_PACKET_DATA_SIZE);
1288 } else if (!strcmp(argv[i], "-realm")) {
1289 extern char local_realms[AFS_NUM_LREALMS][AFS_REALM_SZ];
1290 extern int num_lrealms;
1291 if ((i + 1) >= argc) {
1292 fprintf(stderr, "missing argument for -realm\n");
1295 if (strlen(argv[++i]) >= AFS_REALM_SZ) {
1297 ("-realm argument must contain fewer than %d characters.\n",
1301 if (num_lrealms == -1)
1303 if (num_lrealms >= AFS_NUM_LREALMS) {
1305 ("a maximum of %d -realm arguments can be specified.\n",
1309 strncpy(local_realms[num_lrealms++], argv[i], AFS_REALM_SZ);
1310 } else if (!strcmp(argv[i], "-udpsize")) {
1311 if ((i + 1) >= argc) {
1312 printf("You have to specify -udpsize <integer value>\n");
1315 bufSize = atoi(argv[++i]);
1316 if (bufSize < rx_GetMinUdpBufSize())
1318 ("Warning:udpsize %d is less than minimum %d; ignoring\n",
1319 bufSize, rx_GetMinUdpBufSize());
1321 udpBufSize = bufSize;
1322 } else if (!strcmp(argv[i], "-sendsize")) {
1323 if ((i + 1) >= argc) {
1324 printf("You have to specify -sendsize <integer value>\n");
1327 bufSize = atoi(argv[++i]);
1328 if (bufSize < 16384)
1330 ("Warning:sendsize %d is less than minimum %d; ignoring\n",
1333 sendBufSize = bufSize;
1334 } else if (!strcmp(argv[i], "-enable_peer_stats")) {
1335 rx_enablePeerRPCStats();
1336 } else if (!strcmp(argv[i], "-enable_process_stats")) {
1337 rx_enableProcessRPCStats();
1339 else if (strcmp(argv[i], "-auditlog") == 0) {
1342 char oldName[MAXPATHLEN];
1343 char *fileName = argv[++i];
1345 #ifndef AFS_NT40_ENV
1346 struct stat statbuf;
1348 if ((lstat(fileName, &statbuf) == 0)
1349 && (S_ISFIFO(statbuf.st_mode))) {
1350 flags = O_WRONLY | O_NONBLOCK;
1354 strcpy(oldName, fileName);
1355 strcat(oldName, ".old");
1356 renamefile(fileName, oldName);
1357 flags = O_WRONLY | O_TRUNC | O_CREAT;
1359 tempfd = open(fileName, flags, 0666);
1361 auditout = fdopen(tempfd, "a");
1363 osi_audit_file(auditout);
1365 printf("Warning: auditlog %s not writable, ignored.\n", fileName);
1367 printf("Warning: auditlog %s not writable, ignored.\n", fileName);
1369 #ifndef AFS_NT40_ENV
1370 else if (strcmp(argv[i], "-syslog") == 0) {
1371 /* set syslog logging flag */
1372 serverLogSyslog = 1;
1373 } else if (strncmp(argv[i], "-syslog=", 8) == 0) {
1374 serverLogSyslog = 1;
1375 serverLogSyslogFacility = atoi(argv[i] + 8);
1378 else if (strcmp(argv[i], "-mrafslogs") == 0) {
1379 /* set syslog logging flag */
1382 else if (strcmp(argv[i], "-saneacls") == 0) {
1390 printf("Only one of -L, or -S must be specified\n");
1401 numberofcbs = 20000;
1417 numberofcbs = 64000;
1426 busy_threshold = 3 * rxpackets / 2;
1436 NewParms(int initializing)
1438 static struct afs_stat sbuf;
1441 char *argv[MAXPARMS];
1444 if (!(afs_stat("/vice/file/parms", &sbuf))) {
1445 parms = (char *)malloc(sbuf.st_size);
1448 fd = afs_open("parms", O_RDONLY, 0666);
1450 ViceLog(0, ("Open for parms failed with errno = %d\n", errno));
1454 i = read(fd, parms, sbuf.st_size);
1456 if (i != sbuf.st_size) {
1458 ViceLog(0, ("Read on parms failed with errno = %d\n", errno));
1461 ("Read on parms failed; expected %d bytes but read %d\n",
1468 for (i = 0; i < MAXPARMS; argv[i++] = 0);
1470 for (argc = i = 0; i < sbuf.st_size; i++) {
1471 if ((*(parms + i) != ' ') && (*(parms + i) != '\n')) {
1472 if (argv[argc] == 0)
1473 argv[argc] = (parms + i);
1475 *(parms + i) = '\0';
1476 if (argv[argc] != 0) {
1477 if (++argc == MAXPARMS)
1480 while ((*(parms + i + 1) == ' ')
1481 || (*(parms + i + 1) == '\n'))
1485 if (ParseArgs(argc, argv) == 0) {
1486 ViceLog(0, ("Change parameters to:"));
1488 ViceLog(0, ("Invalid parameter in:"));
1490 for (i = 0; i < argc; i++) {
1491 ViceLog(0, (" %s", argv[i]));
1495 } else if (!initializing)
1497 ("Received request to change parms but no parms file exists\n"));
1502 /* Miscellaneous routines */
1506 ViceLog(0, ("%s\n", msg));
1518 * If this fails, it's because something major is wrong, and is not
1519 * likely to be time dependent.
1521 code = pr_Initialize(2, AFSDIR_SERVER_ETC_DIRPATH, 0);
1524 ("Couldn't initialize protection library; code=%d.\n", code));
1528 #ifdef AFS_PTHREAD_ENV
1529 assert(pthread_key_create(&viced_uclient_key, NULL) == 0);
1532 SystemId = SYSADMINID;
1533 SystemAnyUser = ANYUSERID;
1534 SystemAnyUserCPS.prlist_len = 0;
1535 SystemAnyUserCPS.prlist_val = NULL;
1536 AnonCPS.prlist_len = 0;
1537 AnonCPS.prlist_val = NULL;
1539 code = pr_GetCPS(SystemAnyUser, &SystemAnyUserCPS);
1542 ("Couldn't get CPS for AnyUser, will try again in 30 seconds; code=%d.\n",
1546 code = pr_GetCPS(ANONYMOUSID, &AnonCPS);
1549 ("Couldn't get Anonymous CPS, exiting; code=%d.\n",
1553 AnonymousID = ANONYMOUSID;
1556 #ifdef AFS_PTHREAD_ENV
1558 #else /* AFS_PTHREAD_ENV */
1560 #endif /* AFS_PTHREAD_ENV */
1564 struct rx_connection *serverconns[MAXSERVERS];
1565 struct ubik_client *cstruct;
1568 vl_Initialize(const char *confDir)
1570 afs_int32 code, scIndex = 0, i;
1571 struct afsconf_dir *tdir;
1572 struct rx_securityClass *sc;
1573 struct afsconf_cell info;
1575 tdir = afsconf_Open(confDir);
1578 ("Could not open configuration directory (%s).\n", confDir));
1581 code = afsconf_ClientAuth(tdir, &sc, &scIndex);
1583 ViceLog(0, ("Could not get security object for localAuth\n"));
1586 code = afsconf_GetCellInfo(tdir, NULL, AFSCONF_VLDBSERVICE, &info);
1587 if (info.numServers > MAXSERVERS) {
1589 ("vl_Initialize: info.numServers=%d (> MAXSERVERS=%d)\n",
1590 info.numServers, MAXSERVERS));
1593 for (i = 0; i < info.numServers; i++)
1595 rx_NewConnection(info.hostAddr[i].sin_addr.s_addr,
1596 info.hostAddr[i].sin_port, USER_SERVICE_ID, sc,
1598 code = ubik_ClientInit(serverconns, &cstruct);
1599 afsconf_Close(tdir);
1601 ViceLog(0, ("vl_Initialize: ubik client init failed.\n"));
1607 #define SYSIDMAGIC 0x88aabbcc
1608 #define SYSIDVERSION 1
1613 afs_int32 fd, nentries, i;
1614 struct versionStamp vsn;
1615 struct afs_stat status;
1618 if ((afs_stat(AFSDIR_SERVER_SYSID_FILEPATH, &status))
1619 || (status.st_size <= 0)) {
1620 ViceLog(0, ("%s: doesn't exist\n", AFSDIR_SERVER_SYSID_FILEPATH));
1623 if (!(fd = afs_open(AFSDIR_SERVER_SYSID_FILEPATH, O_RDONLY, 0))) {
1625 ("%s: can't open (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1629 if ((i = read(fd, (char *)&vsn, sizeof(vsn))) != sizeof(vsn)) {
1631 ("%s: Read failed (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1635 if (vsn.magic != SYSIDMAGIC) {
1637 ("%s: wrong magic %x (we support %x)\n",
1638 AFSDIR_SERVER_SYSID_FILEPATH, vsn.magic, SYSIDMAGIC));
1641 if (vsn.version != SYSIDVERSION) {
1643 ("%s: wrong version %d (we support %d)\n",
1644 AFSDIR_SERVER_SYSID_FILEPATH, vsn.version, SYSIDVERSION));
1648 read(fd, (char *)&uuid,
1649 sizeof(struct afsUUID))) != sizeof(struct afsUUID)) {
1651 ("%s: read of uuid failed (%d)\n",
1652 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1655 afs_ntohuuid(&uuid);
1658 read(fd, (char *)&nentries,
1659 sizeof(afs_int32))) != sizeof(afs_int32)) {
1661 ("%s: Read of entries failed (%d)\n",
1662 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1665 if (nentries <= 0 || nentries > ADDRSPERSITE) {
1667 ("%s: invalid num of interfaces: %d\n",
1668 AFSDIR_SERVER_SYSID_FILEPATH, nentries));
1671 if (FS_HostAddr_cnt == 0) {
1672 FS_HostAddr_cnt = nentries;
1673 for (i = 0; i < nentries; i++) {
1674 if (read(fd, (char *)&FS_HostAddrs[i], sizeof(afs_int32)) !=
1675 sizeof(afs_int32)) {
1677 ("%s: Read of addresses failed (%d)\n",
1678 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1679 FS_HostAddr_cnt = 0; /* reset it */
1685 ("%s: address list ignored (NetInfo/NetRestrict override)\n",
1686 AFSDIR_SERVER_SYSID_FILEPATH));
1696 struct versionStamp vsn;
1697 struct afs_stat status;
1700 if (!afs_stat(AFSDIR_SERVER_SYSID_FILEPATH, &status)) {
1702 * File exists; keep the old one around
1704 renamefile(AFSDIR_SERVER_SYSID_FILEPATH,
1705 AFSDIR_SERVER_OLDSYSID_FILEPATH);
1707 fd = afs_open(AFSDIR_SERVER_SYSID_FILEPATH, O_WRONLY | O_TRUNC | O_CREAT,
1711 ("%s: can't create (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1715 vsn.magic = SYSIDMAGIC;
1717 if ((i = write(fd, (char *)&vsn, sizeof(vsn))) != sizeof(vsn)) {
1719 ("%s: write failed (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1724 afs_htonuuid(&uuid);
1726 write(fd, (char *)&uuid,
1727 sizeof(struct afsUUID))) != sizeof(struct afsUUID)) {
1729 ("%s: write of uuid failed (%d)\n",
1730 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1734 write(fd, (char *)&FS_HostAddr_cnt,
1735 sizeof(afs_int32))) != sizeof(afs_int32)) {
1737 ("%s: write of # of entries failed (%d)\n",
1738 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1741 for (i = 0; i < FS_HostAddr_cnt; i++) {
1742 if (write(fd, (char *)&FS_HostAddrs[i], sizeof(afs_int32)) !=
1743 sizeof(afs_int32)) {
1745 ("%s: write of addresses failed (%d)\n",
1746 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1756 * This routine sets up the buffers for the VL_RegisterAddrs RPC. All addresses
1757 * in FS_HostAddrs[] are in NBO, while the RPC treats them as a "blob" of data
1758 * and so we need to convert each of them into HBO which is what the extra
1759 * array called FS_HostAddrs_HBO is used here.
1766 extern int VL_RegisterAddrs();
1767 afs_uint32 FS_HostAddrs_HBO[ADDRSPERSITE];
1770 for (i = 0; i < FS_HostAddr_cnt; i++)
1771 FS_HostAddrs_HBO[i] = ntohl(FS_HostAddrs[i]);
1772 addrs.bulkaddrs_len = FS_HostAddr_cnt;
1773 addrs.bulkaddrs_val = (afs_uint32 *) FS_HostAddrs_HBO;
1774 code = ubik_VL_RegisterAddrs(cstruct, 0, &FS_HostUUID, 0, &addrs);
1776 if (code == VL_MULTIPADDR) {
1778 ("VL_RegisterAddrs rpc failed; The IP address exists on a different server; repair it\n"));
1780 ("VL_RegisterAddrs rpc failed; See VLLog for details\n"));
1782 } else if (code == RXGEN_OPCODE) {
1784 ("vlserver doesn't support VL_RegisterAddrs rpc; ignored\n"));
1785 FS_registered = 2; /* So we don't have to retry in the gc daemon */
1788 ("VL_RegisterAddrs rpc failed; will retry periodically (code=%d, err=%d)\n",
1792 FS_registered = 2; /* So we don't have to retry in the gc daemon */
1803 extern int rxi_numNetAddrs;
1804 extern afs_uint32 rxi_NetAddrs[];
1806 #ifndef AFS_NT40_ENV
1807 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH || AFSDIR_SERVER_NETINFO_FILEPATH) {
1809 * Find addresses we are supposed to register as per the netrestrict
1810 * and netinfo files (/usr/afs/local/NetInfo and
1811 * /usr/afs/local/NetRestict)
1814 afs_int32 code = parseNetFiles(FS_HostAddrs, NULL, NULL,
1815 ADDRSPERSITE, reason,
1816 AFSDIR_SERVER_NETINFO_FILEPATH,
1817 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
1819 ViceLog(0, ("Can't register any valid addresses: %s\n", reason));
1822 FS_HostAddr_cnt = (afs_uint32) code;
1826 FS_HostAddr_cnt = rx_getAllAddr(FS_HostAddrs, ADDRSPERSITE);
1829 if (FS_HostAddr_cnt == 1 && rxBind == 1)
1830 code = FS_HostAddrs[0];
1832 code = htonl(INADDR_ANY);
1842 * If this fails, it's because something major is wrong, and is not
1843 * likely to be time dependent.
1845 code = vl_Initialize(AFSDIR_SERVER_ETC_DIRPATH);
1848 ("Couldn't initialize protection library; code=%d.\n", code));
1852 /* Read or create the sysid file and register the fileserver's
1853 * IP addresses with the vlserver.
1855 code = ReadSysIdFile();
1857 /* Need to create the file */
1858 ViceLog(0, ("Creating new SysID file\n"));
1859 if ((code = afs_uuid_create(&FS_HostUUID))) {
1860 ViceLog(0, ("Failed to create new uuid: %d\n", code));
1864 /* A good sysid file exists; inform the vlserver. If any conflicts,
1865 * we always use the latest interface available as the real truth.
1868 code = Do_VLRegisterRPC();
1873 main(int argc, char *argv[])
1877 struct rx_securityClass *sc[4];
1878 struct rx_service *tservice;
1879 #ifdef AFS_PTHREAD_ENV
1880 pthread_t serverPid;
1881 pthread_attr_t tattr;
1882 #else /* AFS_PTHREAD_ENV */
1883 PROCESS parentPid, serverPid;
1884 #endif /* AFS_PTHREAD_ENV */
1886 int minVnodesRequired; /* min size of vnode cache */
1887 #ifndef AFS_NT40_ENV
1888 struct rlimit rlim; /* max number of open file descriptors */
1892 afs_uint32 rx_bindhost;
1894 #ifdef AFS_AIX32_ENV
1895 struct sigaction nsa;
1897 sigemptyset(&nsa.sa_mask);
1898 nsa.sa_handler = SIG_DFL;
1899 nsa.sa_flags = SA_FULLDUMP;
1900 sigaction(SIGABRT, &nsa, NULL);
1901 sigaction(SIGSEGV, &nsa, NULL);
1905 /* Initialize dirpaths */
1906 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
1908 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
1910 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
1914 #ifndef AFS_QUIETFS_ENV
1915 console = afs_fopen("/dev/console", "w");
1918 if (ParseArgs(argc, argv)) {
1922 #ifdef AFS_PTHREAD_ENV
1923 assert(pthread_mutex_init(&fileproc_glock_mutex, NULL) == 0);
1924 #endif /* AFS_PTHREAD_ENV */
1926 #ifdef AFS_SGI_VNODE_GLUE
1927 if (afs_init_kernel_config(-1) < 0) {
1929 ("Can't determine NUMA configuration, not starting fileserver.\n");
1933 confDir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
1935 fprintf(stderr, "Unable to open config directory %s\n",
1936 AFSDIR_SERVER_ETC_DIRPATH);
1942 /* Open FileLog on stdout, stderr, fd 1 and fd2 (for perror), sigh. */
1943 #ifndef AFS_NT40_ENV
1944 serverLogSyslogTag = "fileserver";
1946 OpenLog(AFSDIR_SERVER_FILELOG_FILEPATH);
1949 if (SawSpare && SawPctSpare) {
1950 ViceLog(0, ("Both -spare and -pctspare specified, exiting.\n"));
1953 #ifdef AFS_SGI_XFS_IOPS_ENV
1954 ViceLog(0, ("XFS/EFS File server starting\n"));
1956 ViceLog(0, ("File server starting\n"));
1959 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
1960 /* initialize the pthread soft signal handler thread */
1964 /* install signal handlers for controlling the fileserver process */
1965 ResetCheckSignal(); /* set CheckSignal_Signal() sig handler */
1966 ResetCheckDescriptors(); /* set CheckDescriptors_Signal() sig handler */
1968 #if defined(AFS_SGI_ENV)
1969 /* give this guy a non-degrading priority so help busy servers */
1970 schedctl(NDPRI, 0, NDPNORMMAX);
1974 #ifndef AFS_NT40_ENV
1975 nice(-5); /* TODO: */
1978 assert(DInit(buffs) == 0);
1981 if (afs_winsockInit() < 0) {
1982 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
1983 ViceLog(0, ("File server failed to intialize winsock.\n"));
1989 /* if we support more than 16 threads, then we better have the ability
1990 ** to keep open a large number of files simultaneously
1992 #if defined(AFS_AIX_ENV) && !defined(AFS_AIX42_ENV)
1993 curLimit = OPEN_MAX; /* for pre AIX 4.2 systems */
1994 #elif defined(AFS_NT40_ENV)
1995 curLimit = NT_OPEN_MAX; /* open file descriptor limit on NT */
1998 curLimit = 0; /* the number of open file descriptors */
1999 code = getrlimit(RLIMIT_NOFILE, &rlim);
2001 curLimit = rlim.rlim_cur;
2002 rlim.rlim_cur = rlim.rlim_max;
2003 code = setrlimit(RLIMIT_NOFILE, &rlim);
2005 curLimit = rlim.rlim_max;
2008 ViceLog(0, ("Failed to increase open file limit, using default\n"));
2010 #endif /* defined(AFS_AIX_ENV) && !defined(AFS_AIX42_ENV) */
2012 curLimit -= 32; /* leave a slack of 32 file descriptors */
2013 if (lwps > curLimit) {
2017 lwps = 16; /* default to a maximum of 16 threads */
2019 ("The system supports a max of %d open files and we are starting %d threads\n",
2022 #ifndef AFS_PTHREAD_ENV
2023 assert(LWP_InitializeProcessSupport(LWP_MAX_PRIORITY - 2, &parentPid) ==
2025 #endif /* !AFS_PTHREAD_ENV */
2027 /* Initialize volume support */
2029 V_BreakVolumeCallbacks = BreakVolumeCallBacksLater;
2032 #ifdef AFS_PTHREAD_ENV
2033 SetLogThreadNumProgram( threadNum );
2036 /* initialize libacl routines */
2037 acl_Initialize(ACL_VERSION);
2039 /* initialize RX support */
2040 #ifndef AFS_NT40_ENV
2041 rxi_syscallp = viced_syscall;
2043 rx_extraPackets = rxpackets;
2044 rx_extraQuota = 4; /* for outgoing prserver calls from R threads */
2045 rx_SetBusyThreshold(busy_threshold, VBUSY);
2046 rx_SetCallAbortThreshold(abort_threshold);
2047 rx_SetConnAbortThreshold(abort_threshold);
2048 stackSize = lwps * 4000;
2049 if (stackSize < 32000)
2051 else if (stackSize > 44000)
2053 #if defined(AFS_HPUX_ENV) || defined(AFS_SUN_ENV) || defined(AFS_SGI51_ENV)
2054 rx_SetStackSize(1, stackSize);
2057 rx_SetUdpBufSize(udpBufSize); /* set the UDP buffer size for receive */
2058 rx_bindhost = SetupVL();
2060 if (rx_InitHost(rx_bindhost, (int)htons(7000)) < 0) {
2061 ViceLog(0, ("Cannot initialize RX\n"));
2064 if (!rxJumbograms) {
2065 /* Don't send and don't allow 3.4 clients to send jumbograms. */
2068 if (rxMaxMTU != -1) {
2069 rx_SetMaxMTU(rxMaxMTU);
2072 rx_SetRxDeadTime(30);
2073 sc[0] = rxnull_NewServerSecurityObject();
2074 sc[1] = 0; /* rxvab_NewServerSecurityObject(key1, 0) */
2075 sc[2] = rxkad_NewServerSecurityObject(rxkad_clear, NULL, get_key, NULL);
2076 sc[3] = rxkad_NewServerSecurityObject(rxkad_crypt, NULL, get_key, NULL);
2077 tservice = rx_NewServiceHost(rx_bindhost, /* port */ 0, /* service id */
2078 1, /*service name */
2080 /* security classes */ sc,
2081 /* numb sec classes */
2082 4, RXAFS_ExecuteRequest);
2085 ("Failed to initialize RX, probably two servers running.\n"));
2088 rx_SetMinProcs(tservice, 3);
2089 rx_SetMaxProcs(tservice, lwps);
2090 rx_SetCheckReach(tservice, 1);
2093 rx_NewService(0, RX_STATS_SERVICE_ID, "rpcstats", sc, 4,
2094 RXSTATS_ExecuteRequest);
2096 ViceLog(0, ("Failed to initialize rpc stat service.\n"));
2099 rx_SetMinProcs(tservice, 2);
2100 rx_SetMaxProcs(tservice, 4);
2103 * Enable RX hot threads, which allows the listener thread to trade
2104 * places with an idle thread and moves the context switch from listener
2105 * to worker out of the critical path.
2107 rx_EnableHotThread();
2109 /* Some rx debugging */
2110 if (rxlog || eventlog) {
2111 debugFile = afs_fopen("rx_dbg", "w");
2113 rx_debugFile = debugFile;
2115 rxevent_debugFile = debugFile;
2118 init_sys_error_to_et(); /* Set up error table translation */
2119 h_InitHostPackage(); /* set up local cellname and realmname */
2120 InitCallBack(numberofcbs);
2125 ViceLog(0, ("Fatal error in library initialization, exiting!!\n"));
2131 ViceLog(0, ("Fatal error in protection initialization, exiting!!\n"));
2135 /* allow super users to manage RX statistics */
2136 rx_SetRxStatUserOk(fs_rxstat_userok);
2138 rx_StartServer(0); /* now start handling requests */
2140 /* we ensure that there is enough space in the vnode buffer to satisfy
2141 ** requests from all concurrent threads.
2142 ** the maximum number of vnodes used by a single thread at any one time
2143 ** is three ( "link" uses three vnodes simultaneously, one vLarge and
2144 ** two vSmall for linking files and two vLarge and one vSmall for linking
2147 minVnodesRequired = 2 * lwps + 1;
2148 if (minVnodesRequired > nSmallVns) {
2149 nSmallVns = minVnodesRequired;
2151 ("Overriding -s command line parameter with %d\n",
2154 if (minVnodesRequired > large) {
2155 large = minVnodesRequired;
2156 ViceLog(0, ("Overriding -l command line parameter with %d\n", large));
2159 /* We now do this after getting the listener up and running, so that client
2160 * connections don't timeout (maybe) if a file server is restarted, since it
2161 * will be available "real soon now". Worry about whether we can satisfy the
2162 * calls in the volume package itself.
2164 if (VInitVolumePackage(fileServer, large, nSmallVns, 0, volcache)) {
2166 ("Shutting down: errors encountered initializing volume package\n"));
2171 #ifdef AFS_DEMAND_ATTACH_FS
2172 if (fs_state.options.fs_state_restore) {
2175 * restore fileserver state */
2178 #endif /* AFS_DEMAND_ATTACH_FS */
2181 * We are done calling fopen/fdopen. It is safe to use a large
2182 * of the file descriptor cache.
2186 #ifdef AFS_PTHREAD_ENV
2187 ViceLog(5, ("Starting pthreads\n"));
2188 assert(pthread_attr_init(&tattr) == 0);
2189 assert(pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED) == 0);
2191 assert(pthread_create
2192 (&serverPid, &tattr, (void *)FiveMinuteCheckLWP,
2193 &fiveminutes) == 0);
2194 assert(pthread_create
2195 (&serverPid, &tattr, (void *)HostCheckLWP, &fiveminutes) == 0);
2196 assert(pthread_create
2197 (&serverPid, &tattr, (void *)FsyncCheckLWP, &fiveminutes) == 0);
2198 #else /* AFS_PTHREAD_ENV */
2199 ViceLog(5, ("Starting LWP\n"));
2200 assert(LWP_CreateProcess
2201 (FiveMinuteCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
2202 (void *)&fiveminutes, "FiveMinuteChecks",
2203 &serverPid) == LWP_SUCCESS);
2205 assert(LWP_CreateProcess
2206 (HostCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
2207 (void *)&fiveminutes, "HostCheck", &serverPid) == LWP_SUCCESS);
2208 assert(LWP_CreateProcess
2209 (FsyncCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
2210 (void *)&fiveminutes, "FsyncCheck", &serverPid) == LWP_SUCCESS);
2211 #endif /* AFS_PTHREAD_ENV */
2213 TM_GetTimeOfDay(&tp, 0);
2215 #ifndef AFS_QUIETFS_ENV
2216 if (console != NULL) {
2217 time_t t = tp.tv_sec;
2218 fprintf(console, "File server has started at %s\r",
2219 afs_ctime(&t, tbuffer, sizeof(tbuffer)));
2224 * Figure out the FileServer's name and primary address.
2226 ViceLog(0, ("Getting FileServer name...\n"));
2227 code = gethostname(FS_HostName, 64);
2229 ViceLog(0, ("gethostname() failed\n"));
2231 ViceLog(0, ("FileServer host name is '%s'\n", FS_HostName));
2233 ViceLog(0, ("Getting FileServer address...\n"));
2234 he = gethostbyname(FS_HostName);
2236 ViceLog(0, ("Can't find address for FileServer '%s'\n", FS_HostName));
2239 memcpy(&FS_HostAddr_NBO, he->h_addr, 4);
2240 (void)afs_inet_ntoa_r(FS_HostAddr_NBO, hoststr);
2241 FS_HostAddr_HBO = ntohl(FS_HostAddr_NBO);
2243 ("FileServer %s has address %s (0x%x or 0x%x in host byte order)\n",
2244 FS_HostName, hoststr, FS_HostAddr_NBO, FS_HostAddr_HBO));
2247 /* Install handler to catch the shutdown signal;
2248 * bosserver assumes SIGQUIT shutdown
2250 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
2251 softsig_signal(SIGQUIT, ShutDown_Signal);
2253 (void)signal(SIGQUIT, ShutDown_Signal);
2258 ("File Server started %s",
2259 afs_ctime(&t, tbuffer, sizeof(tbuffer))));
2260 #if FS_STATS_DETAILED
2261 afs_FullPerfStats.det.epoch.tv_sec = StartTime = tp.tv_sec;
2263 #ifdef AFS_PTHREAD_ENV
2265 sleep(1000); /* long time */
2267 #else /* AFS_PTHREAD_ENV */
2268 assert(LWP_WaitProcess(&parentPid) == LWP_SUCCESS);
2269 #endif /* AFS_PTHREAD_ENV */