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>
31 #include <sys/types.h>
32 #include <afs/procmgmt.h> /* signal(), kill(), wait(), etc. */
38 #include <WINNT/afsevent.h>
41 #include <netinet/in.h>
43 #include <unistd.h> /* sysconf() */
47 #endif /* ITIMER_REAL */
48 #include <sys/resource.h>
49 #endif /* AFS_NT40_ENV */
54 #ifdef AFS_PTHREAD_ENV
56 #else /* AFS_PTHREAD_ENV */
57 #include <afs/assert.h>
58 #endif /* AFS_PTHREAD_ENV */
61 #include <afs/ptclient.h>
62 #include <afs/afsint.h>
63 #include <afs/vldbint.h>
64 #include <afs/errors.h>
65 #include <afs/ihandle.h>
66 #include <afs/vnode.h>
67 #include <afs/volume.h>
69 #include <afs/cellconfig.h>
71 #include <afs/prs_fs.h>
74 #include <afs/afs_args.h>
75 #include <afs/vlserver.h>
76 #include <afs/afsutil.h>
77 #include <afs/fileutil.h>
78 #include <afs/ptuser.h>
79 #include <afs/audit.h>
80 #include <afs/partition.h>
82 #include <afs/netutils.h>
84 #include "viced_prototypes.h"
87 #ifdef AFS_PTHREAD_ENV
90 #if defined(AFS_SGI_ENV)
91 #include "sys/schedctl.h"
94 #include <rx/rx_globals.h>
97 #define afs_stat stat64
98 #define afs_fstat fstat64
99 #define afs_open open64
100 #define afs_fopen fopen64
101 #else /* !O_LARGEFILE */
102 #define afs_stat stat
103 #define afs_fstat fstat
104 #define afs_open open
105 #define afs_fopen fopen
106 #endif /* !O_LARGEFILE */
108 extern int BreakVolumeCallBacks(), InitCallBack();
109 extern int BreakVolumeCallBacks(), InitCallBack(), BreakLaterCallBacks();
110 extern int BreakVolumeCallBacksLater();
111 extern int LogLevel, etext;
112 extern afs_int32 BlocksSpare, PctSpare;
115 static void ClearXStatValues(), NewParms(), PrintCounters();
116 static void ResetCheckDescriptors(void), ResetCheckSignal(void);
117 static int CheckSignal(void);
118 extern int GetKeysFromToken();
119 extern int RXAFS_ExecuteRequest();
120 extern int RXSTATS_ExecuteRequest();
121 afs_int32 Do_VLRegisterRPC();
123 int eventlog = 0, rxlog = 0;
125 FILE *console = NULL;
127 #ifdef AFS_PTHREAD_ENV
128 pthread_mutex_t fsync_glock_mutex;
129 pthread_cond_t fsync_cond;
132 #endif /* AFS_PTHREAD_ENV */
135 #define AFS_QUIETFS_ENV 1
136 #define NT_OPEN_MAX 1024 /* This is an arbitrary no. we came up with for
137 * now. We hope this will be replaced by a more
138 * intelligent estimate later. */
141 int SystemId; /* ViceID of "Administrators" */
142 int SystemAnyUser; /* Viceid of "System:AnyUser" */
143 prlist SystemAnyUserCPS; /* CPS for "system:AnyUser */
144 int AnonymousID = 0; /* ViceId of "Anonymous" */
145 prlist AnonCPS; /* CPS for "Anonymous" */
147 struct afsconf_dir *confDir; /* Configuration dir object */
149 int restartMode = RESTART_ORDINARY;
152 * Home for the performance statistics.
154 struct afs_PerfStats afs_perfstats;
157 extern int Statistics;
165 int rxJumbograms = 1; /* default is to send and receive jumbograms. */
166 int rxBind = 0; /* don't bind */
168 afs_int32 implicitAdminRights = PRSFS_LOOKUP; /* The ADMINISTER right is
170 afs_int32 readonlyServer = 0;
173 int stackSize = 24000;
174 int fiveminutes = 300; /* 5 minutes. Change this for debugging only */
175 int CurrentConnections = 0;
176 int hostaclRefresh = 7200; /* refresh host clients' acls every 2 hrs */
177 #if defined(AFS_SGI_ENV)
182 int rxpackets = 150; /* 100 */
183 int nSmallVns = 400; /* 200 */
184 int large = 400; /* 200 */
185 int volcache = 400; /* 400 */
186 int numberofcbs = 60000; /* 60000 */
187 int lwps = 9; /* 6 */
188 int buffs = 90; /* 70 */
189 int novbc = 0; /* Enable Volume Break calls */
190 int busy_threshold = 600;
191 int abort_threshold = 10;
192 int udpBufSize = 0; /* UDP buffer size for receive */
193 int sendBufSize = 16384; /* send buffer size */
194 int saneacls = 0; /* Sane ACLs Flag */
198 #ifdef AFS_PTHREAD_ENV
199 pthread_key_t viced_uclient_key;
202 #ifdef AFS_PTHREAD_ENV
203 pthread_key_t viced_uclient_key;
207 * FileServer's name and IP address, both network byte order and
210 #define ADDRSPERSITE 16 /* Same global is in rx/rx_user.c */
212 char FS_HostName[128] = "localhost";
213 afs_uint32 FS_HostAddr_NBO;
214 afs_uint32 FS_HostAddr_HBO;
215 afs_uint32 FS_HostAddrs[ADDRSPERSITE], FS_HostAddr_cnt = 0, FS_registered = 0;
216 /* All addresses in FS_HostAddrs are in NBO */
219 static void FlagMsg();
221 #ifdef AFS_DEMAND_ATTACH_FS
224 * fileserver mode support
226 * during fileserver shutdown, we have to track the graceful shutdown of
227 * certain background threads before we are allowed to dump state to
231 #if !defined(PTHREAD_RWLOCK_INITIALIZER) && defined(AFS_DARWIN80_ENV)
232 #define PTHREAD_RWLOCK_INITIALIZER {0x2DA8B3B4, {0}}
235 struct fs_state fs_state =
242 PTHREAD_COND_INITIALIZER,
243 PTHREAD_RWLOCK_INITIALIZER
245 #endif /* AFS_DEMAND_ATTACH_FS */
248 * Home for the performance statistics.
256 struct afs_stat status;
257 register int tsize = getdtablesize();
259 for (i = 0; i < tsize; i++) {
260 if (afs_fstat(i, &status) != -1) {
261 printf("%d: dev %x, inode %u, length %u, type/mode %x\n", i,
262 status.st_dev, status.st_ino, status.st_size,
267 ResetCheckDescriptors();
270 } /*CheckDescriptors */
273 #ifdef AFS_PTHREAD_ENV
275 CheckSignal_Signal(x)
287 CheckDescriptors_Signal(x)
291 #else /* AFS_PTHREAD_ENV */
293 CheckSignal_Signal(x)
295 IOMGR_SoftSig(CheckSignal, 0);
301 IOMGR_SoftSig(ShutDown, 0);
305 CheckDescriptors_Signal(x)
307 IOMGR_SoftSig(CheckDescriptors, 0);
309 #endif /* AFS_PTHREAD_ENV */
311 /* check whether caller is authorized to manage RX statistics */
313 fs_rxstat_userok(struct rx_call *call)
315 return afsconf_SuperUser(confDir, call, NULL);
319 ResetCheckSignal(void)
323 #if defined(AFS_HPUX_ENV)
326 #if defined(AFS_NT40_ENV)
333 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
334 softsig_signal(signo, CheckSignal_Signal);
336 signal(signo, CheckSignal_Signal);
341 ResetCheckDescriptors(void)
344 #if defined(AFS_PTHREAD_ENV)
345 softsig_signal(SIGTERM, CheckDescriptors_Signal);
347 (void)signal(SIGTERM, CheckDescriptors_Signal);
352 #if defined(AFS_PTHREAD_ENV)
356 return pthread_getspecific(rx_thread_id_key);
360 /* proc called by rxkad module to get a key */
362 get_key(char *arock, register afs_int32 akvno, char *akey)
365 static struct afsconf_key tkey;
366 register afs_int32 code;
369 ViceLog(0, ("conf dir not open\n"));
372 code = afsconf_GetKey(confDir, akvno, tkey.key);
374 ViceLog(0, ("afsconf_GetKey failure: kvno %d code %d\n", akvno, code));
377 memcpy(akey, tkey.key, sizeof(tkey.key));
384 viced_syscall(afs_uint32 a3, afs_uint32 a4, void *a5)
389 #ifndef AFS_LINUX20_ENV
390 old = (void (*)())signal(SIGSYS, SIG_IGN);
392 rcode = syscall(AFS_SYSCALL, 28 /* AFSCALL_CALL */ , a3, a4, a5);
393 #ifndef AFS_LINUX20_ENV
401 #if !defined(AFS_NT40_ENV)
402 #include "AFS_component_version_number.c"
403 #endif /* !AFS_NT40_ENV */
405 #define MAXADMINNAME 64
406 char adminName[MAXADMINNAME];
412 struct afs_stat status;
414 if ((afs_stat("/AdminName", &status)) || /* if file does not exist */
415 (status.st_size <= 0) || /* or it is too short */
416 (status.st_size >= (MAXADMINNAME)) || /* or it is too long */
417 !(fd = afs_open("/AdminName", O_RDONLY, 0))) { /* or the open fails */
418 strcpy(adminName, "System:Administrators"); /* use the default name */
420 (void)read(fd, adminName, status.st_size); /* use name from the file */
423 close(fd); /* close fd if it was opened */
425 } /*CheckAdminName */
431 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
432 /* set our 'thread-id' so that the host hold table works */
433 MUTEX_ENTER(&rx_stats_mutex); /* protects rxi_pthread_hinum */
435 pthread_setspecific(rx_thread_id_key, (void *)rxi_pthread_hinum);
436 MUTEX_EXIT(&rx_stats_mutex);
438 ("Set thread id %d for '%s'\n",
439 pthread_getspecific(rx_thread_id_key), s));
443 /* This LWP does things roughly every 5 minutes */
450 ViceLog(1, ("Starting five minute check process\n"));
451 setThreadId("FiveMinuteCheckLWP");
453 #ifdef AFS_DEMAND_ATTACH_FS
455 while (fs_state.mode == FS_MODE_NORMAL) {
456 fs_state.FiveMinuteLWP_tranquil = 1;
462 #ifdef AFS_PTHREAD_ENV
464 #else /* AFS_PTHREAD_ENV */
465 IOMGR_Sleep(fiveminutes);
466 #endif /* AFS_PTHREAD_ENV */
468 #ifdef AFS_DEMAND_ATTACH_FS
470 if (fs_state.mode != FS_MODE_NORMAL) {
473 fs_state.FiveMinuteLWP_tranquil = 0;
477 /* close the log so it can be removed */
478 ReOpenLog(AFSDIR_SERVER_FILELOG_FILEPATH); /* don't trunc, just append */
479 ViceLog(2, ("Cleaning up timed out callbacks\n"));
480 if (CleanupTimedOutCallBacks())
481 ViceLog(5, ("Timed out callbacks deleted\n"));
482 ViceLog(2, ("Set disk usage statistics\n"));
484 if (FS_registered == 1)
486 /* Force wakeup in case we missed something; pthreads does timedwait */
487 #ifndef AFS_PTHREAD_ENV
488 LWP_NoYieldSignal(fsync_wait);
490 if (printBanner && (++msg & 1)) { /* Every 10 minutes */
491 time_t now = FT_ApproxTime();
492 if (console != NULL) {
493 #ifndef AFS_QUIETFS_ENV
494 fprintf(console, "File server is running at %s\r",
495 afs_ctime(&now, tbuffer, sizeof(tbuffer)));
496 #endif /* AFS_QUIETFS_ENV */
498 ("File server is running at %s\n",
499 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
502 #ifdef AFS_DEMAND_ATTACH_FS
506 #ifdef AFS_DEMAND_ATTACH_FS
507 fs_state.FiveMinuteLWP_tranquil = 1;
509 assert(pthread_cond_broadcast(&fs_state.worker_done_cv)==0);
513 } /*FiveMinuteCheckLWP */
516 /* This LWP does host checks every 5 minutes: it should not be used for
517 * other 5 minute activities because it may be delayed by timeouts when
518 * it probes the workstations
524 ViceLog(1, ("Starting Host check process\n"));
525 setThreadId("HostCheckLWP");
526 #ifdef AFS_DEMAND_ATTACH_FS
528 while (fs_state.mode == FS_MODE_NORMAL) {
529 fs_state.HostCheckLWP_tranquil = 1;
535 #ifdef AFS_PTHREAD_ENV
537 #else /* AFS_PTHREAD_ENV */
538 IOMGR_Sleep(fiveminutes);
539 #endif /* AFS_PTHREAD_ENV */
541 #ifdef AFS_DEMAND_ATTACH_FS
543 if (fs_state.mode != FS_MODE_NORMAL) {
546 fs_state.HostCheckLWP_tranquil = 0;
550 ViceLog(2, ("Checking for dead venii & clients\n"));
553 #ifdef AFS_DEMAND_ATTACH_FS
557 #ifdef AFS_DEMAND_ATTACH_FS
558 fs_state.HostCheckLWP_tranquil = 1;
560 assert(pthread_cond_broadcast(&fs_state.worker_done_cv)==0);
566 /* This LWP does fsync checks every 5 minutes: it should not be used for
567 * other 5 minute activities because it may be delayed by timeouts when
568 * it probes the workstations
574 #ifdef AFS_PTHREAD_ENV
575 struct timespec fsync_next;
577 ViceLog(1, ("Starting fsync check process\n"));
579 setThreadId("FsyncCheckLWP");
581 #ifdef AFS_PTHREAD_ENV
582 assert(pthread_cond_init(&fsync_cond, NULL) == 0);
583 assert(pthread_mutex_init(&fsync_glock_mutex, NULL) == 0);
586 #ifdef AFS_DEMAND_ATTACH_FS
588 while (fs_state.mode == FS_MODE_NORMAL) {
589 fs_state.FsyncCheckLWP_tranquil = 1;
595 #ifdef AFS_PTHREAD_ENV
596 /* rounding is fine */
597 fsync_next.tv_nsec = 0;
598 fsync_next.tv_sec = time(0) + fiveminutes;
601 pthread_cond_timedwait(&fsync_cond, &fsync_glock_mutex,
603 if (code != 0 && code != ETIMEDOUT)
604 ViceLog(0, ("pthread_cond_timedwait returned %d\n", code));
605 #else /* AFS_PTHREAD_ENV */
606 if ((code = LWP_WaitProcess(fsync_wait)) != LWP_SUCCESS)
607 ViceLog(0, ("LWP_WaitProcess returned %d\n", code));
608 #endif /* AFS_PTHREAD_ENV */
611 #ifdef AFS_DEMAND_ATTACH_FS
613 if (fs_state.mode != FS_MODE_NORMAL) {
616 fs_state.FsyncCheckLWP_tranquil = 0;
618 #endif /* AFS_DEMAND_ATTACH_FS */
620 ViceLog(2, ("Checking for fsync events\n"));
622 code = BreakLaterCallBacks();
624 #ifdef AFS_DEMAND_ATTACH_FS
628 #ifdef AFS_DEMAND_ATTACH_FS
629 fs_state.FsyncCheckLWP_tranquil = 1;
631 assert(pthread_cond_broadcast(&fs_state.worker_done_cv)==0);
634 #endif /* AFS_DEMAND_ATTACH_FS */
637 /*------------------------------------------------------------------------
638 * PRIVATE ClearXStatValues
641 * Initialize all of the values collected via the xstat
651 * Must be called during File Server initialization.
655 *------------------------------------------------------------------------*/
659 { /*ClearXStatValues */
661 struct fs_stats_opTimingData *opTimeP; /*Ptr to timing struct */
662 struct fs_stats_xferData *opXferP; /*Ptr to xfer struct */
663 int i; /*Loop counter */
666 * Zero all xstat-related structures.
668 memset((char *)(&afs_perfstats), 0, sizeof(struct afs_PerfStats));
669 #if FS_STATS_DETAILED
670 memset((char *)(&afs_FullPerfStats), 0,
671 sizeof(struct fs_stats_FullPerfStats));
674 * That's not enough. We have to set reasonable minima for
675 * time and xfer values in the detailed stats.
677 opTimeP = &(afs_FullPerfStats.det.rpcOpTimes[0]);
678 for (i = 0; i < FS_STATS_NUM_RPC_OPS; i++, opTimeP++)
679 opTimeP->minTime.tv_sec = 999999;
681 opXferP = &(afs_FullPerfStats.det.xferOpTimes[0]);
682 for (i = 0; i < FS_STATS_NUM_XFER_OPS; i++, opXferP++) {
683 opXferP->minTime.tv_sec = 999999;
684 opXferP->minBytes = 999999999;
688 * There's more. We have to set our unique system identifier, as
689 * declared in param.h. If such a thing is not defined, we bitch
690 * and declare ourselves to be an unknown system type.
693 afs_perfstats.sysname_ID = SYS_NAME_ID;
696 ViceLog(0, ("Sys name ID constant not defined in param.h!!\n"));
697 ViceLog(0, ("[Choosing ``undefined'' sys name ID.\n"));
699 afs_perfstats.sysname_ID = SYS_NAME_ID_UNDEFINED;
700 #endif /* SYS_NAME_ID */
703 } /*ClearXStatValues */
709 int dirbuff, dircall, dirio;
711 int workstations, activeworkstations, delworkstations;
715 TM_GetTimeOfDay(&tpl, 0);
718 ("Vice was last started at %s\n",
719 afs_ctime(&StartTime, tbuffer, sizeof(tbuffer))));
721 #ifdef AFS_DEMAND_ATTACH_FS
722 /* XXX perhaps set extended stats verbosity flags
723 * based upon LogLevel ?? */
724 VPrintExtendedCacheStats(VOL_STATS_PER_CHAIN2);
728 DStat(&dirbuff, &dircall, &dirio);
730 ("With %d directory buffers; %d reads resulted in %d read I/Os\n",
731 dirbuff, dircall, dirio));
732 rx_PrintStats(stderr);
734 PrintCallBackStats();
736 processSize = -1; /* TODO: */
738 processSize = (int)((long)sbrk(0) >> 10);
741 ("There are %d connections, process size %d\n",
742 CurrentConnections, processSize));
743 h_GetWorkStats(&workstations, &activeworkstations, &delworkstations,
744 tpl.tv_sec - 15 * 60);
746 ("There are %d workstations, %d are active (req in < 15 mins), %d marked \"down\"\n",
747 workstations, activeworkstations, delworkstations));
757 if (FS_registered > 0) {
759 * We have proper ip addresses; tell the vlserver what we got; the following
760 * routine will do the proper reporting for us
773 ShutDownAndCore(int dopanic)
775 time_t now = time(0);
778 /* do not allows new reqests to be served from now on, all new requests
779 * are returned with an error code of RX_RESTARTING ( transient failure ) */
780 rx_SetRxTranquil(); /* dhruba */
782 #ifdef AFS_DEMAND_ATTACH_FS
784 fs_state.mode = FS_MODE_SHUTDOWN;
789 ("Shutting down file server at %s",
790 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
792 ViceLog(0, ("ABNORMAL SHUTDOWN, see core file.\n"));
793 #ifndef AFS_QUIETFS_ENV
794 if (console != NULL) {
795 fprintf(console, "File server restart/shutdown received at %s\r",
796 afs_ctime(&now, tbuffer, sizeof(tbuffer)));
803 /* shut down volume package */
806 #ifdef AFS_DEMAND_ATTACH_FS
807 if (fs_state.options.fs_state_save) {
810 * save fileserver state to disk */
812 /* make sure background threads have finished all of their asynchronous
813 * work on host and callback structures */
815 while (!fs_state.FiveMinuteLWP_tranquil ||
816 !fs_state.HostCheckLWP_tranquil ||
817 !fs_state.FsyncCheckLWP_tranquil) {
820 ViceLog(0, ("waiting for background host/callback threads to quiesce before saving fileserver state...\n"));
821 assert(pthread_cond_wait(&fs_state.worker_done_cv, &fileproc_glock_mutex) == 0);
826 /* ok. it should now be fairly safe. let's do the state dump */
829 #endif /* AFS_DEMAND_ATTACH_FS */
832 rx_PrintStats(debugFile);
835 if (console != NULL) {
838 #ifndef AFS_QUIETFS_ENV
839 fprintf(console, "File server has terminated abnormally at %s\r",
840 afs_ctime(&now, tbuffer, sizeof(tbuffer)));
843 ("File server has terminated abnormally at %s\n",
844 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
846 #ifndef AFS_QUIETFS_ENV
847 fprintf(console, "File server has terminated normally at %s\r",
848 afs_ctime(&now, tbuffer, sizeof(tbuffer)));
851 ("File server has terminated normally at %s\n",
852 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
864 { /* backward compatibility */
865 ShutDownAndCore(DONTPANIC);
873 /* default supports help flag */
875 fputs("Usage: fileserver ", stdout);
876 fputs("[-auditlog <log path>] ", stdout);
877 fputs("[-d <debug level>] ", stdout);
878 fputs("[-p <number of processes>] ", stdout);
879 fputs("[-spare <number of spare blocks>] ", stdout);
880 fputs("[-pctspare <percentage spare>] ", stdout);
881 fputs("[-b <buffers>] ", stdout);
882 fputs("[-l <large vnodes>] ", stdout);
883 fputs("[-s <small vnodes>] ", stdout);
884 fputs("[-vc <volume cachesize>] ", stdout);
885 fputs("[-w <call back wait interval>] ", stdout);
886 fputs("[-cb <number of call backs>] ", stdout);
887 fputs("[-banner (print banner every 10 minutes)] ", stdout);
888 fputs("[-novbc (whole volume cbs disabled)] ", stdout);
889 fputs("[-implicit <admin mode bits: rlidwka>] ", stdout);
890 fputs("[-readonly (read-only file server)] ", stdout);
891 fputs("[-hr <number of hours between refreshing the host cps>] ", stdout);
892 fputs("[-busyat <redirect clients when queue > n>] ", stdout);
893 fputs("[-nobusy <no VBUSY before a volume is attached>] ", stdout);
894 fputs("[-rxpck <number of rx extra packets>] ", stdout);
895 fputs("[-rxdbg (enable rx debugging)] ", stdout);
896 fputs("[-rxdbge (enable rxevent debugging)] ", stdout);
897 fputs("[-rxmaxmtu <bytes>] ", stdout);
898 fputs("[-rxbind (bind the Rx socket to one address)] ", stdout);
899 #ifdef AFS_DEMAND_ATTACH_FS
900 fputs("[-fs-state-dont-save (disable state save during shutdown)] ", stdout);
901 fputs("[-fs-state-dont-restore (disable state restore during startup)] ", stdout);
902 fputs("[-fs-state-verify <none|save|restore|both> (default is both)] ", stdout);
903 fputs("[-vattachpar <max number of volume attach/shutdown threads> (default is 1)] ", stdout);
904 fputs("[-vhashsize <log(2) of number of volume hash buckets> (default is 8)] ", stdout);
905 fputs("[-vlrudisable (disable VLRU functionality)] ", stdout);
906 fputs("[-vlruthresh <minutes before unused volumes become eligible for soft detach> (default is 2 hours)] ", stdout);
907 fputs("[-vlruinterval <seconds between VLRU scans> (default is 2 minutes)] ", stdout);
908 fputs("[-vlrumax <max volumes to soft detach in one VLRU scan> (default is 8)] ", stdout);
909 #elif AFS_PTHREAD_ENV
910 fputs("[-vattachpar <number of volume attach threads> (default is 1)] ", stdout);
913 fputs("[-m <min percentage spare in partition>] ", stdout);
915 #if defined(AFS_SGI_ENV)
916 fputs("[-lock (keep fileserver from swapping)] ", stdout);
918 fputs("[-L (large server conf)] ", stdout);
919 fputs("[-S (small server conf)] ", stdout);
920 fputs("[-k <stack size>] ", stdout);
921 fputs("[-realm <Kerberos realm name>] ", stdout);
922 fputs("[-udpsize <size of socket buffer in bytes>] ", stdout);
923 fputs("[-sendsize <size of send buffer in bytes>] ", stdout);
924 fputs("[-abortthreshold <abort threshold>] ", stdout);
925 /* fputs("[-enable_peer_stats] ", stdout); */
926 /* fputs("[-enable_process_stats] ", stdout); */
927 fputs("[-help]\n", stdout);
929 ViceLog(0, ("%s", buffer));
938 ParseRights(char *arights)
944 if (!arights || !strcmp(arights, "")) {
945 printf("Missing list of mode bits on -implicit option\n");
948 if (!strcmp(arights, "none"))
950 else if (!strcmp(arights, "read"))
951 mode = PRSFS_READ | PRSFS_LOOKUP;
952 else if (!strcmp(arights, "write"))
954 PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
955 PRSFS_WRITE | PRSFS_LOCK;
956 else if (!strcmp(arights, "all"))
958 PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
959 PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER;
961 len = strlen(arights);
962 for (i = 0; i < len; i++) {
967 mode |= PRSFS_LOOKUP;
969 mode |= PRSFS_INSERT;
971 mode |= PRSFS_DELETE;
977 mode |= PRSFS_ADMINISTER;
995 printf("Illegal -implicit rights character '%c'.\n", tc);
1004 * Limit MAX_FILESERVER_THREAD by the system limit on the number of
1005 * pthreads (sysconf(_SC_THREAD_THREADS_MAX)), if applicable and
1008 * AIX: sysconf() limit is real
1009 * HP-UX: sysconf() limit is real
1010 * IRIX: sysconf() limit is apparently NOT real -- too small
1011 * DUX: sysconf() limit is apparently NOT real -- too big
1012 * Linux: sysconf() limit is apparently NOT real -- too big
1013 * Solaris: no sysconf() limit
1016 max_fileserver_thread(void)
1018 #if defined(AFS_PTHREAD_ENV)
1019 #if defined(AFS_AIX_ENV) || defined(AFS_HPUX_ENV)
1022 ans = sysconf(_SC_THREAD_THREADS_MAX);
1023 if (0 < ans && ans < MAX_FILESERVER_THREAD)
1026 #endif /* defined(AFS_PTHREAD_ENV) */
1027 return MAX_FILESERVER_THREAD;
1031 ParseArgs(int argc, char *argv[])
1033 int SawL = 0, SawS = 0, SawVC = 0;
1034 int Sawrxpck = 0, Sawsmall = 0, Sawlarge = 0, Sawcbs = 0, Sawlwps =
1038 int bufSize = 0; /* temp variable to read in udp socket buf size */
1040 for (i = 1; i < argc; i++) {
1041 if (!strcmp(argv[i], "-d")) {
1042 if ((i + 1) >= argc) {
1043 fprintf(stderr, "missing argument for -d\n");
1046 debuglevel = atoi(argv[++i]);
1047 LogLevel = debuglevel;
1048 } else if (!strcmp(argv[i], "-banner")) {
1050 } else if (!strcmp(argv[i], "-implicit")) {
1051 if ((i + 1) >= argc) {
1052 fprintf(stderr, "missing argument for -implicit\n");
1055 implicitAdminRights = ParseRights(argv[++i]);
1056 if (implicitAdminRights < 0)
1057 return implicitAdminRights;
1058 } else if (!strcmp(argv[i], "-readonly")) {
1060 } else if (!strcmp(argv[i], "-L")) {
1062 } else if (!strcmp(argv[i], "-S")) {
1064 } else if (!strcmp(argv[i], "-p")) {
1066 max_fileserver_thread() - FILESERVER_HELPER_THREADS;
1068 if ((i + 1) >= argc) {
1069 fprintf(stderr, "missing argument for -p\n");
1072 lwps = atoi(argv[++i]);
1073 if (lwps > lwps_max)
1077 } else if (!strcmp(argv[i], "-b")) {
1079 if ((i + 1) >= argc) {
1080 fprintf(stderr, "missing argument for -b\n");
1083 buffs = atoi(argv[++i]);
1084 } else if (!strcmp(argv[i], "-l")) {
1086 if ((i + 1) >= argc) {
1087 fprintf(stderr, "missing argument for -l\n");
1090 large = atoi(argv[++i]);
1091 } else if (!strcmp(argv[i], "-vc")) {
1093 if ((i + 1) >= argc) {
1094 fprintf(stderr, "missing argument for -vc\n");
1097 volcache = atoi(argv[++i]);
1098 } else if (!strcmp(argv[i], "-novbc")) {
1100 } else if (!strcmp(argv[i], "-rxpck")) {
1102 if ((i + 1) >= argc) {
1103 fprintf(stderr, "missing argument for -rxpck\n");
1106 rxpackets = atoi(argv[++i]);
1107 #ifdef AFS_PTHREAD_ENV
1108 } else if (!strcmp(argv[i], "-vattachpar")) {
1109 if ((i + 1) >= argc) {
1110 fprintf(stderr, "missing argument for %s\n", argv[i]);
1113 vol_attach_threads = atoi(argv[++i]);
1114 #endif /* AFS_PTHREAD_ENV */
1115 #ifdef AFS_DEMAND_ATTACH_FS
1116 } else if (!strcmp(argv[i], "-fs-state-dont-save")) {
1117 fs_state.options.fs_state_save = 0;
1118 } else if (!strcmp(argv[i], "-fs-state-dont-restore")) {
1119 fs_state.options.fs_state_restore = 0;
1120 } else if (!strcmp(argv[i], "-fs-state-verify")) {
1121 if ((i + 1) >= argc) {
1122 fprintf(stderr, "missing argument for %s\n", argv[i]);
1126 if (!strcmp(argv[i], "none")) {
1127 fs_state.options.fs_state_verify_before_save = 0;
1128 fs_state.options.fs_state_verify_after_restore = 0;
1129 } else if (!strcmp(argv[i], "save")) {
1130 fs_state.options.fs_state_verify_after_restore = 0;
1131 } else if (!strcmp(argv[i], "restore")) {
1132 fs_state.options.fs_state_verify_before_save = 0;
1133 } else if (!strcmp(argv[i], "both")) {
1136 fprintf(stderr, "invalid argument for %s\n", argv[i-1]);
1139 } else if (!strcmp(argv[i], "-vhashsize")) {
1140 if ((i + 1) >= argc) {
1141 fprintf(stderr, "missing argument for %s\n", argv[i]);
1144 VSetVolHashSize(atoi(argv[++i]));
1145 } else if (!strcmp(argv[i], "-vlrudisable")) {
1146 VLRU_SetOptions(VLRU_SET_ENABLED, 0);
1147 } else if (!strcmp(argv[i], "-vlruthresh")) {
1148 if ((i + 1) >= argc) {
1149 fprintf(stderr, "missing argument for %s\n", argv[i]);
1152 VLRU_SetOptions(VLRU_SET_THRESH, 60*atoi(argv[++i]));
1153 } else if (!strcmp(argv[i], "-vlruinterval")) {
1154 if ((i + 1) >= argc) {
1155 fprintf(stderr, "missing argument for %s\n", argv[i]);
1158 VLRU_SetOptions(VLRU_SET_INTERVAL, atoi(argv[++i]));
1159 } else if (!strcmp(argv[i], "-vlrumax")) {
1160 if ((i + 1) >= argc) {
1161 fprintf(stderr, "missing argument for %s\n", argv[i]);
1164 VLRU_SetOptions(VLRU_SET_MAX, atoi(argv[++i]));
1165 #endif /* AFS_DEMAND_ATTACH_FS */
1166 } else if (!strcmp(argv[i], "-s")) {
1168 if ((i + 1) >= argc) {
1169 fprintf(stderr, "missing argument for -s\n");
1172 nSmallVns = atoi(argv[++i]);
1173 } else if (!strcmp(argv[i], "-abortthreshold")) {
1174 if ((i + 1) >= argc) {
1175 fprintf(stderr, "missing argument for -abortthreshold\n");
1178 abort_threshold = atoi(argv[++i]);
1179 } else if (!strcmp(argv[i], "-k")) {
1180 if ((i + 1) >= argc) {
1181 fprintf(stderr, "missing argument for -k\n");
1184 stack = atoi(argv[++i]);
1186 #if defined(AFS_SGI_ENV)
1187 else if (!strcmp(argv[i], "-lock")) {
1191 else if (!strcmp(argv[i], "-spare")) {
1192 if ((i + 1) >= argc) {
1193 fprintf(stderr, "missing argument for -spare\n");
1196 BlocksSpare = atoi(argv[++i]);
1198 } else if (!strcmp(argv[i], "-pctspare")) {
1199 if ((i + 1) >= argc) {
1200 fprintf(stderr, "missing argument for -pctspare\n");
1203 PctSpare = atoi(argv[++i]);
1204 BlocksSpare = 0; /* has non-zero default */
1206 } else if (!strcmp(argv[i], "-w")) {
1207 if ((i + 1) >= argc) {
1208 fprintf(stderr, "missing argument for -w\n");
1211 fiveminutes = atoi(argv[++i]);
1212 } else if (!strcmp(argv[i], "-hr")) {
1214 if ((i + 1) >= argc) {
1215 fprintf(stderr, "missing argument for -hr\n");
1218 hr = atoi(argv[++i]);
1219 if ((hr < 1) || (hr > 36)) {
1221 ("host acl refresh interval of %d hours is invalid; hours must be between 1 and 36\n\n",
1225 hostaclRefresh = hr * 60 * 60;
1226 } else if (!strcmp(argv[i], "-rxdbg"))
1228 else if (!strcmp(argv[i], "-rxdbge"))
1230 else if (!strcmp(argv[i], "-cb")) {
1232 if ((i + 1) >= argc) {
1233 fprintf(stderr, "missing argument for -cb\n");
1236 numberofcbs = atoi(argv[++i]);
1237 if ((numberofcbs < 10000) || (numberofcbs > 2147483647)) {
1239 ("number of cbs %d invalid; must be between 10000 and 2147483647\n",
1243 } else if (!strcmp(argv[i], "-busyat")) {
1245 if ((i + 1) >= argc) {
1246 fprintf(stderr, "missing argument for -busyat\n");
1249 busy_threshold = atoi(argv[++i]);
1250 if (busy_threshold < 10) {
1252 ("Busy threshold %d is too low, will compute default.\n",
1256 } else if (!strcmp(argv[i], "-nobusy"))
1258 #ifdef AFS_AIX32_ENV
1259 else if (!strcmp(argv[i], "-m")) {
1260 extern int aixlow_water;
1261 if ((i + 1) >= argc) {
1262 fprintf(stderr, "missing argument for -m\n");
1265 aixlow_water = atoi(argv[++i]);
1266 if ((aixlow_water < 0) || (aixlow_water > 30)) {
1267 printf("space reserved %d% invalid; must be between 0-30%\n",
1273 else if (!strcmp(argv[i], "-nojumbo")) {
1275 } else if (!strcmp(argv[i], "-rxbind")) {
1277 } else if (!strcmp(argv[i], "-rxmaxmtu")) {
1278 if ((i + 1) >= argc) {
1279 fprintf(stderr, "missing argument for -rxmaxmtu\n");
1282 rxMaxMTU = atoi(argv[++i]);
1283 if ((rxMaxMTU < RX_MIN_PACKET_SIZE) ||
1284 (rxMaxMTU > RX_MAX_PACKET_DATA_SIZE)) {
1285 printf("rxMaxMTU %d%% invalid; must be between %d-%d\n",
1286 rxMaxMTU, RX_MIN_PACKET_SIZE,
1287 RX_MAX_PACKET_DATA_SIZE);
1290 } else if (!strcmp(argv[i], "-realm")) {
1291 extern char local_realms[AFS_NUM_LREALMS][AFS_REALM_SZ];
1292 extern int num_lrealms;
1293 if ((i + 1) >= argc) {
1294 fprintf(stderr, "missing argument for -realm\n");
1297 if (strlen(argv[++i]) >= AFS_REALM_SZ) {
1299 ("-realm argument must contain fewer than %d characters.\n",
1303 if (num_lrealms == -1)
1305 if (num_lrealms >= AFS_NUM_LREALMS) {
1307 ("a maximum of %d -realm arguments can be specified.\n",
1311 strncpy(local_realms[num_lrealms++], argv[i], AFS_REALM_SZ);
1312 } else if (!strcmp(argv[i], "-udpsize")) {
1313 if ((i + 1) >= argc) {
1314 printf("You have to specify -udpsize <integer value>\n");
1317 bufSize = atoi(argv[++i]);
1318 if (bufSize < rx_GetMinUdpBufSize())
1320 ("Warning:udpsize %d is less than minimum %d; ignoring\n",
1321 bufSize, rx_GetMinUdpBufSize());
1323 udpBufSize = bufSize;
1324 } else if (!strcmp(argv[i], "-sendsize")) {
1325 if ((i + 1) >= argc) {
1326 printf("You have to specify -sendsize <integer value>\n");
1329 bufSize = atoi(argv[++i]);
1330 if (bufSize < 16384)
1332 ("Warning:sendsize %d is less than minimum %d; ignoring\n",
1335 sendBufSize = bufSize;
1336 } else if (!strcmp(argv[i], "-enable_peer_stats")) {
1337 rx_enablePeerRPCStats();
1338 } else if (!strcmp(argv[i], "-enable_process_stats")) {
1339 rx_enableProcessRPCStats();
1341 else if (strcmp(argv[i], "-auditlog") == 0) {
1344 char oldName[MAXPATHLEN];
1345 char *fileName = argv[++i];
1347 #ifndef AFS_NT40_ENV
1348 struct stat statbuf;
1350 if ((lstat(fileName, &statbuf) == 0)
1351 && (S_ISFIFO(statbuf.st_mode))) {
1352 flags = O_WRONLY | O_NONBLOCK;
1356 strcpy(oldName, fileName);
1357 strcat(oldName, ".old");
1358 renamefile(fileName, oldName);
1359 flags = O_WRONLY | O_TRUNC | O_CREAT;
1361 tempfd = open(fileName, flags, 0666);
1363 auditout = fdopen(tempfd, "a");
1365 osi_audit_file(auditout);
1367 printf("Warning: auditlog %s not writable, ignored.\n", fileName);
1369 printf("Warning: auditlog %s not writable, ignored.\n", fileName);
1371 #ifndef AFS_NT40_ENV
1372 else if (strcmp(argv[i], "-syslog") == 0) {
1373 /* set syslog logging flag */
1374 serverLogSyslog = 1;
1375 } else if (strncmp(argv[i], "-syslog=", 8) == 0) {
1376 serverLogSyslog = 1;
1377 serverLogSyslogFacility = atoi(argv[i] + 8);
1380 else if (strcmp(argv[i], "-mrafslogs") == 0) {
1381 /* set syslog logging flag */
1384 else if (strcmp(argv[i], "-saneacls") == 0) {
1392 printf("Only one of -L, or -S must be specified\n");
1403 numberofcbs = 20000;
1419 numberofcbs = 64000;
1428 busy_threshold = 3 * rxpackets / 2;
1438 NewParms(int initializing)
1440 static struct afs_stat sbuf;
1443 char *argv[MAXPARMS];
1446 if (!(afs_stat("/vice/file/parms", &sbuf))) {
1447 parms = (char *)malloc(sbuf.st_size);
1450 fd = afs_open("parms", O_RDONLY, 0666);
1452 ViceLog(0, ("Open for parms failed with errno = %d\n", errno));
1456 i = read(fd, parms, sbuf.st_size);
1458 if (i != sbuf.st_size) {
1460 ViceLog(0, ("Read on parms failed with errno = %d\n", errno));
1463 ("Read on parms failed; expected %d bytes but read %d\n",
1470 for (i = 0; i < MAXPARMS; argv[i++] = 0);
1472 for (argc = i = 0; i < sbuf.st_size; i++) {
1473 if ((*(parms + i) != ' ') && (*(parms + i) != '\n')) {
1474 if (argv[argc] == 0)
1475 argv[argc] = (parms + i);
1477 *(parms + i) = '\0';
1478 if (argv[argc] != 0) {
1479 if (++argc == MAXPARMS)
1482 while ((*(parms + i + 1) == ' ')
1483 || (*(parms + i + 1) == '\n'))
1487 if (ParseArgs(argc, argv) == 0) {
1488 ViceLog(0, ("Change parameters to:"));
1490 ViceLog(0, ("Invalid parameter in:"));
1492 for (i = 0; i < argc; i++) {
1493 ViceLog(0, (" %s", argv[i]));
1497 } else if (!initializing)
1499 ("Received request to change parms but no parms file exists\n"));
1504 /* Miscellaneous routines */
1508 ViceLog(0, ("%s\n", msg));
1520 * If this fails, it's because something major is wrong, and is not
1521 * likely to be time dependent.
1523 code = pr_Initialize(2, AFSDIR_SERVER_ETC_DIRPATH, 0);
1526 ("Couldn't initialize protection library; code=%d.\n", code));
1530 #ifdef AFS_PTHREAD_ENV
1531 assert(pthread_key_create(&viced_uclient_key, NULL) == 0);
1534 SystemId = SYSADMINID;
1535 SystemAnyUser = ANYUSERID;
1536 SystemAnyUserCPS.prlist_len = 0;
1537 SystemAnyUserCPS.prlist_val = NULL;
1538 AnonCPS.prlist_len = 0;
1539 AnonCPS.prlist_val = NULL;
1541 code = pr_GetCPS(SystemAnyUser, &SystemAnyUserCPS);
1544 ("Couldn't get CPS for AnyUser, will try again in 30 seconds; code=%d.\n",
1548 code = pr_GetCPS(ANONYMOUSID, &AnonCPS);
1551 ("Couldn't get Anonymous CPS, exiting; code=%d.\n",
1555 AnonymousID = ANONYMOUSID;
1558 #ifdef AFS_PTHREAD_ENV
1560 #else /* AFS_PTHREAD_ENV */
1562 #endif /* AFS_PTHREAD_ENV */
1566 struct rx_connection *serverconns[MAXSERVERS];
1567 struct ubik_client *cstruct;
1570 vl_Initialize(const char *confDir)
1572 afs_int32 code, scIndex = 0, i;
1573 struct afsconf_dir *tdir;
1574 struct rx_securityClass *sc;
1575 struct afsconf_cell info;
1577 tdir = afsconf_Open(confDir);
1580 ("Could not open configuration directory (%s).\n", confDir));
1583 code = afsconf_ClientAuth(tdir, &sc, &scIndex);
1585 ViceLog(0, ("Could not get security object for localAuth\n"));
1588 code = afsconf_GetCellInfo(tdir, NULL, AFSCONF_VLDBSERVICE, &info);
1589 if (info.numServers > MAXSERVERS) {
1591 ("vl_Initialize: info.numServers=%d (> MAXSERVERS=%d)\n",
1592 info.numServers, MAXSERVERS));
1595 for (i = 0; i < info.numServers; i++)
1597 rx_NewConnection(info.hostAddr[i].sin_addr.s_addr,
1598 info.hostAddr[i].sin_port, USER_SERVICE_ID, sc,
1600 code = ubik_ClientInit(serverconns, &cstruct);
1601 afsconf_Close(tdir);
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 if (FS_HostAddr_cnt == 0) {
1674 FS_HostAddr_cnt = nentries;
1675 for (i = 0; i < nentries; i++) {
1676 if (read(fd, (char *)&FS_HostAddrs[i], sizeof(afs_int32)) !=
1677 sizeof(afs_int32)) {
1679 ("%s: Read of addresses failed (%d)\n",
1680 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1681 FS_HostAddr_cnt = 0; /* reset it */
1687 ("%s: address list ignored (NetInfo/NetRestrict override)\n",
1688 AFSDIR_SERVER_SYSID_FILEPATH));
1698 struct versionStamp vsn;
1699 struct afs_stat status;
1702 if (!afs_stat(AFSDIR_SERVER_SYSID_FILEPATH, &status)) {
1704 * File exists; keep the old one around
1706 renamefile(AFSDIR_SERVER_SYSID_FILEPATH,
1707 AFSDIR_SERVER_OLDSYSID_FILEPATH);
1709 fd = afs_open(AFSDIR_SERVER_SYSID_FILEPATH, O_WRONLY | O_TRUNC | O_CREAT,
1713 ("%s: can't create (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1717 vsn.magic = SYSIDMAGIC;
1719 if ((i = write(fd, (char *)&vsn, sizeof(vsn))) != sizeof(vsn)) {
1721 ("%s: write failed (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1726 afs_htonuuid(&uuid);
1728 write(fd, (char *)&uuid,
1729 sizeof(struct afsUUID))) != sizeof(struct afsUUID)) {
1731 ("%s: write of uuid failed (%d)\n",
1732 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1736 write(fd, (char *)&FS_HostAddr_cnt,
1737 sizeof(afs_int32))) != sizeof(afs_int32)) {
1739 ("%s: write of # of entries failed (%d)\n",
1740 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1743 for (i = 0; i < FS_HostAddr_cnt; i++) {
1744 if (write(fd, (char *)&FS_HostAddrs[i], sizeof(afs_int32)) !=
1745 sizeof(afs_int32)) {
1747 ("%s: write of addresses failed (%d)\n",
1748 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1758 * This routine sets up the buffers for the VL_RegisterAddrs RPC. All addresses
1759 * in FS_HostAddrs[] are in NBO, while the RPC treats them as a "blob" of data
1760 * and so we need to convert each of them into HBO which is what the extra
1761 * array called FS_HostAddrs_HBO is used here.
1768 extern int VL_RegisterAddrs();
1769 afs_uint32 FS_HostAddrs_HBO[ADDRSPERSITE];
1772 for (i = 0; i < FS_HostAddr_cnt; i++)
1773 FS_HostAddrs_HBO[i] = ntohl(FS_HostAddrs[i]);
1774 addrs.bulkaddrs_len = FS_HostAddr_cnt;
1775 addrs.bulkaddrs_val = (afs_uint32 *) FS_HostAddrs_HBO;
1776 code = ubik_VL_RegisterAddrs(cstruct, 0, &FS_HostUUID, 0, &addrs);
1778 if (code == VL_MULTIPADDR) {
1780 ("VL_RegisterAddrs rpc failed; The IP address exists on a different server; repair it\n"));
1782 ("VL_RegisterAddrs rpc failed; See VLLog for details\n"));
1784 } else if (code == RXGEN_OPCODE) {
1786 ("vlserver doesn't support VL_RegisterAddrs rpc; ignored\n"));
1787 FS_registered = 2; /* So we don't have to retry in the gc daemon */
1790 ("VL_RegisterAddrs rpc failed; will retry periodically (code=%d, err=%d)\n",
1794 FS_registered = 2; /* So we don't have to retry in the gc daemon */
1805 extern int rxi_numNetAddrs;
1806 extern afs_uint32 rxi_NetAddrs[];
1808 #ifndef AFS_NT40_ENV
1809 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH || AFSDIR_SERVER_NETINFO_FILEPATH) {
1811 * Find addresses we are supposed to register as per the netrestrict
1812 * and netinfo files (/usr/afs/local/NetInfo and
1813 * /usr/afs/local/NetRestict)
1816 afs_int32 code = parseNetFiles(FS_HostAddrs, NULL, NULL,
1817 ADDRSPERSITE, reason,
1818 AFSDIR_SERVER_NETINFO_FILEPATH,
1819 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
1821 ViceLog(0, ("Can't register any valid addresses: %s\n", reason));
1824 FS_HostAddr_cnt = (afs_uint32) code;
1828 FS_HostAddr_cnt = rx_getAllAddr(FS_HostAddrs, ADDRSPERSITE);
1831 if (FS_HostAddr_cnt == 1 && rxBind == 1)
1832 code = FS_HostAddrs[0];
1834 code = htonl(INADDR_ANY);
1844 * If this fails, it's because something major is wrong, and is not
1845 * likely to be time dependent.
1847 code = vl_Initialize(AFSDIR_SERVER_ETC_DIRPATH);
1850 ("Couldn't initialize protection library; code=%d.\n", code));
1854 /* Read or create the sysid file and register the fileserver's
1855 * IP addresses with the vlserver.
1857 code = ReadSysIdFile();
1859 /* Need to create the file */
1860 ViceLog(0, ("Creating new SysID file\n"));
1861 if ((code = afs_uuid_create(&FS_HostUUID))) {
1862 ViceLog(0, ("Failed to create new uuid: %d\n", code));
1866 /* A good sysid file exists; inform the vlserver. If any conflicts,
1867 * we always use the latest interface available as the real truth.
1870 code = Do_VLRegisterRPC();
1875 main(int argc, char *argv[])
1879 struct rx_securityClass *sc[4];
1880 struct rx_service *tservice;
1881 #ifdef AFS_PTHREAD_ENV
1882 pthread_t serverPid;
1883 pthread_attr_t tattr;
1884 #else /* AFS_PTHREAD_ENV */
1885 PROCESS parentPid, serverPid;
1886 #endif /* AFS_PTHREAD_ENV */
1888 int minVnodesRequired; /* min size of vnode cache */
1889 #ifndef AFS_NT40_ENV
1890 struct rlimit rlim; /* max number of open file descriptors */
1894 afs_uint32 rx_bindhost;
1896 #ifdef AFS_AIX32_ENV
1897 struct sigaction nsa;
1899 sigemptyset(&nsa.sa_mask);
1900 nsa.sa_handler = SIG_DFL;
1901 nsa.sa_flags = SA_FULLDUMP;
1902 sigaction(SIGABRT, &nsa, NULL);
1903 sigaction(SIGSEGV, &nsa, NULL);
1907 /* Initialize dirpaths */
1908 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
1910 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
1912 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
1916 #ifndef AFS_QUIETFS_ENV
1917 console = afs_fopen("/dev/console", "w");
1920 if (ParseArgs(argc, argv)) {
1924 #ifdef AFS_PTHREAD_ENV
1925 assert(pthread_mutex_init(&fileproc_glock_mutex, NULL) == 0);
1926 #endif /* AFS_PTHREAD_ENV */
1928 #ifdef AFS_SGI_VNODE_GLUE
1929 if (afs_init_kernel_config(-1) < 0) {
1931 ("Can't determine NUMA configuration, not starting fileserver.\n");
1935 confDir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
1937 fprintf(stderr, "Unable to open config directory %s\n",
1938 AFSDIR_SERVER_ETC_DIRPATH);
1944 /* Open FileLog on stdout, stderr, fd 1 and fd2 (for perror), sigh. */
1945 #ifndef AFS_NT40_ENV
1946 serverLogSyslogTag = "fileserver";
1948 OpenLog(AFSDIR_SERVER_FILELOG_FILEPATH);
1951 if (SawSpare && SawPctSpare) {
1952 ViceLog(0, ("Both -spare and -pctspare specified, exiting.\n"));
1955 #ifdef AFS_SGI_XFS_IOPS_ENV
1956 ViceLog(0, ("XFS/EFS File server starting\n"));
1958 ViceLog(0, ("File server starting\n"));
1961 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
1962 /* initialize the pthread soft signal handler thread */
1966 /* install signal handlers for controlling the fileserver process */
1967 ResetCheckSignal(); /* set CheckSignal_Signal() sig handler */
1968 ResetCheckDescriptors(); /* set CheckDescriptors_Signal() sig handler */
1970 #if defined(AFS_SGI_ENV)
1971 /* give this guy a non-degrading priority so help busy servers */
1972 schedctl(NDPRI, 0, NDPNORMMAX);
1976 #ifndef AFS_NT40_ENV
1977 nice(-5); /* TODO: */
1980 assert(DInit(buffs) == 0);
1983 if (afs_winsockInit() < 0) {
1984 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
1985 ViceLog(0, ("File server failed to intialize winsock.\n"));
1991 /* if we support more than 16 threads, then we better have the ability
1992 ** to keep open a large number of files simultaneously
1994 #if defined(AFS_AIX_ENV) && !defined(AFS_AIX42_ENV)
1995 curLimit = OPEN_MAX; /* for pre AIX 4.2 systems */
1996 #elif defined(AFS_NT40_ENV)
1997 curLimit = NT_OPEN_MAX; /* open file descriptor limit on NT */
2000 curLimit = 0; /* the number of open file descriptors */
2001 code = getrlimit(RLIMIT_NOFILE, &rlim);
2003 curLimit = rlim.rlim_cur;
2004 rlim.rlim_cur = rlim.rlim_max;
2005 code = setrlimit(RLIMIT_NOFILE, &rlim);
2007 curLimit = rlim.rlim_max;
2010 ViceLog(0, ("Failed to increase open file limit, using default\n"));
2012 #endif /* defined(AFS_AIX_ENV) && !defined(AFS_AIX42_ENV) */
2014 curLimit -= 32; /* leave a slack of 32 file descriptors */
2015 if (lwps > curLimit) {
2019 lwps = 16; /* default to a maximum of 16 threads */
2021 ("The system supports a max of %d open files and we are starting %d threads\n",
2024 #ifndef AFS_PTHREAD_ENV
2025 assert(LWP_InitializeProcessSupport(LWP_MAX_PRIORITY - 2, &parentPid) ==
2027 #endif /* !AFS_PTHREAD_ENV */
2029 /* Initialize volume support */
2031 V_BreakVolumeCallbacks = BreakVolumeCallBacksLater;
2034 #ifdef AFS_PTHREAD_ENV
2035 SetLogThreadNumProgram( threadNum );
2038 /* initialize libacl routines */
2039 acl_Initialize(ACL_VERSION);
2041 /* initialize RX support */
2042 #ifndef AFS_NT40_ENV
2043 rxi_syscallp = viced_syscall;
2045 rx_extraPackets = rxpackets;
2046 rx_extraQuota = 4; /* for outgoing prserver calls from R threads */
2047 rx_SetBusyThreshold(busy_threshold, VBUSY);
2048 rx_SetCallAbortThreshold(abort_threshold);
2049 rx_SetConnAbortThreshold(abort_threshold);
2050 stackSize = lwps * 4000;
2051 if (stackSize < 32000)
2053 else if (stackSize > 44000)
2055 #if defined(AFS_HPUX_ENV) || defined(AFS_SUN_ENV) || defined(AFS_SGI51_ENV)
2056 rx_SetStackSize(1, stackSize);
2059 rx_SetUdpBufSize(udpBufSize); /* set the UDP buffer size for receive */
2060 rx_bindhost = SetupVL();
2062 if (rx_InitHost(rx_bindhost, (int)htons(7000)) < 0) {
2063 ViceLog(0, ("Cannot initialize RX\n"));
2066 if (!rxJumbograms) {
2067 /* Don't send and don't allow 3.4 clients to send jumbograms. */
2070 if (rxMaxMTU != -1) {
2071 rx_SetMaxMTU(rxMaxMTU);
2074 rx_SetRxDeadTime(30);
2075 sc[0] = rxnull_NewServerSecurityObject();
2076 sc[1] = 0; /* rxvab_NewServerSecurityObject(key1, 0) */
2077 sc[2] = rxkad_NewServerSecurityObject(rxkad_clear, NULL, get_key, NULL);
2078 sc[3] = rxkad_NewServerSecurityObject(rxkad_crypt, NULL, get_key, NULL);
2079 tservice = rx_NewServiceHost(rx_bindhost, /* port */ 0, /* service id */
2080 1, /*service name */
2082 /* security classes */ sc,
2083 /* numb sec classes */
2084 4, RXAFS_ExecuteRequest);
2087 ("Failed to initialize RX, probably two servers running.\n"));
2090 rx_SetMinProcs(tservice, 3);
2091 rx_SetMaxProcs(tservice, lwps);
2092 rx_SetCheckReach(tservice, 1);
2095 rx_NewService(0, RX_STATS_SERVICE_ID, "rpcstats", sc, 4,
2096 RXSTATS_ExecuteRequest);
2098 ViceLog(0, ("Failed to initialize rpc stat service.\n"));
2101 rx_SetMinProcs(tservice, 2);
2102 rx_SetMaxProcs(tservice, 4);
2105 * Enable RX hot threads, which allows the listener thread to trade
2106 * places with an idle thread and moves the context switch from listener
2107 * to worker out of the critical path.
2109 rx_EnableHotThread();
2111 /* Some rx debugging */
2112 if (rxlog || eventlog) {
2113 debugFile = afs_fopen("rx_dbg", "w");
2115 rx_debugFile = debugFile;
2117 rxevent_debugFile = debugFile;
2120 init_sys_error_to_et(); /* Set up error table translation */
2121 h_InitHostPackage(); /* set up local cellname and realmname */
2122 InitCallBack(numberofcbs);
2127 ViceLog(0, ("Fatal error in library initialization, exiting!!\n"));
2133 ViceLog(0, ("Fatal error in protection initialization, exiting!!\n"));
2137 /* allow super users to manage RX statistics */
2138 rx_SetRxStatUserOk(fs_rxstat_userok);
2140 #if !defined(AFS_DEMAND_ATTACH_FS)
2142 * For DAFS, we do not start the Rx server threads until after
2143 * the volume package is initialized, and fileserver state is
2144 * restored. This is necessary in order to keep host and callback
2145 * package state pristine until we have a chance to restore state.
2147 * Furthermore, startup latency is much lower with dafs, so this
2148 * shouldn't pose a serious problem.
2150 rx_StartServer(0); /* now start handling requests */
2153 /* we ensure that there is enough space in the vnode buffer to satisfy
2154 ** requests from all concurrent threads.
2155 ** the maximum number of vnodes used by a single thread at any one time
2156 ** is three ( "link" uses three vnodes simultaneously, one vLarge and
2157 ** two vSmall for linking files and two vLarge and one vSmall for linking
2160 minVnodesRequired = 2 * lwps + 1;
2161 if (minVnodesRequired > nSmallVns) {
2162 nSmallVns = minVnodesRequired;
2164 ("Overriding -s command line parameter with %d\n",
2167 if (minVnodesRequired > large) {
2168 large = minVnodesRequired;
2169 ViceLog(0, ("Overriding -l command line parameter with %d\n", large));
2172 /* We now do this after getting the listener up and running, so that client
2173 * connections don't timeout (maybe) if a file server is restarted, since it
2174 * will be available "real soon now". Worry about whether we can satisfy the
2175 * calls in the volume package itself.
2177 if (VInitVolumePackage(fileServer, large, nSmallVns, 0, volcache)) {
2179 ("Shutting down: errors encountered initializing volume package\n"));
2184 #ifdef AFS_DEMAND_ATTACH_FS
2185 if (fs_state.options.fs_state_restore) {
2188 * restore fileserver state */
2191 rx_StartServer(0); /* now start handling requests */
2192 #endif /* AFS_DEMAND_ATTACH_FS */
2195 * We are done calling fopen/fdopen. It is safe to use a large
2196 * of the file descriptor cache.
2200 #ifdef AFS_PTHREAD_ENV
2201 ViceLog(5, ("Starting pthreads\n"));
2202 #ifdef AFS_DEMAND_ATTACH_FS
2205 assert(pthread_attr_init(&tattr) == 0);
2206 assert(pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED) == 0);
2208 assert(pthread_create
2209 (&serverPid, &tattr, (void *)FiveMinuteCheckLWP,
2210 &fiveminutes) == 0);
2211 assert(pthread_create
2212 (&serverPid, &tattr, (void *)HostCheckLWP, &fiveminutes) == 0);
2213 assert(pthread_create
2214 (&serverPid, &tattr, (void *)FsyncCheckLWP, &fiveminutes) == 0);
2215 #else /* AFS_PTHREAD_ENV */
2216 ViceLog(5, ("Starting LWP\n"));
2217 assert(LWP_CreateProcess
2218 (FiveMinuteCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
2219 (void *)&fiveminutes, "FiveMinuteChecks",
2220 &serverPid) == LWP_SUCCESS);
2222 assert(LWP_CreateProcess
2223 (HostCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
2224 (void *)&fiveminutes, "HostCheck", &serverPid) == LWP_SUCCESS);
2225 assert(LWP_CreateProcess
2226 (FsyncCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
2227 (void *)&fiveminutes, "FsyncCheck", &serverPid) == LWP_SUCCESS);
2228 #endif /* AFS_PTHREAD_ENV */
2230 TM_GetTimeOfDay(&tp, 0);
2232 #ifndef AFS_QUIETFS_ENV
2233 if (console != NULL) {
2234 time_t t = tp.tv_sec;
2235 fprintf(console, "File server has started at %s\r",
2236 afs_ctime(&t, tbuffer, sizeof(tbuffer)));
2241 * Figure out the FileServer's name and primary address.
2243 ViceLog(0, ("Getting FileServer name...\n"));
2244 code = gethostname(FS_HostName, 64);
2246 ViceLog(0, ("gethostname() failed\n"));
2248 ViceLog(0, ("FileServer host name is '%s'\n", FS_HostName));
2250 ViceLog(0, ("Getting FileServer address...\n"));
2251 he = gethostbyname(FS_HostName);
2253 ViceLog(0, ("Can't find address for FileServer '%s'\n", FS_HostName));
2256 memcpy(&FS_HostAddr_NBO, he->h_addr, 4);
2257 (void)afs_inet_ntoa_r(FS_HostAddr_NBO, hoststr);
2258 FS_HostAddr_HBO = ntohl(FS_HostAddr_NBO);
2260 ("FileServer %s has address %s (0x%x or 0x%x in host byte order)\n",
2261 FS_HostName, hoststr, FS_HostAddr_NBO, FS_HostAddr_HBO));
2264 /* Install handler to catch the shutdown signal;
2265 * bosserver assumes SIGQUIT shutdown
2267 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
2268 softsig_signal(SIGQUIT, ShutDown_Signal);
2270 (void)signal(SIGQUIT, ShutDown_Signal);
2275 ("File Server started %s",
2276 afs_ctime(&t, tbuffer, sizeof(tbuffer))));
2277 #if FS_STATS_DETAILED
2278 afs_FullPerfStats.det.epoch.tv_sec = StartTime = tp.tv_sec;
2280 #ifdef AFS_PTHREAD_ENV
2282 sleep(1000); /* long time */
2284 #else /* AFS_PTHREAD_ENV */
2285 assert(LWP_WaitProcess(&parentPid) == LWP_SUCCESS);
2286 #endif /* AFS_PTHREAD_ENV */