2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
9 * Portions Copyright (c) 2006 Sine Nomine Associates
12 /* viced.c - File Server main loop */
16 /* Function - This routine has the initialization code for */
19 /* ********************************************************************** */
21 #include <afsconfig.h>
22 #include <afs/param.h>
30 #include <sys/types.h>
31 #include <afs/procmgmt.h> /* signal(), kill(), wait(), etc. */
37 #include <WINNT/afsevent.h>
40 #include <netinet/in.h>
42 #include <unistd.h> /* sysconf() */
54 #endif /* ITIMER_REAL */
55 #include <sys/resource.h>
56 #endif /* AFS_NT40_ENV */
61 #ifdef AFS_PTHREAD_ENV
63 #else /* AFS_PTHREAD_ENV */
64 #include <afs/assert.h>
65 #endif /* AFS_PTHREAD_ENV */
68 #include <afs/ptclient.h>
69 #include <afs/afsint.h>
70 #include <afs/vldbint.h>
71 #include <afs/errors.h>
72 #include <afs/ihandle.h>
73 #include <afs/vnode.h>
74 #include <afs/volume.h>
76 #include <afs/cellconfig.h>
78 #include <afs/prs_fs.h>
82 #include <afs/afs_args.h>
83 #include <afs/vlserver.h>
84 #include <afs/afsutil.h>
85 #include <afs/fileutil.h>
86 #include <afs/ptuser.h>
87 #include <afs/audit.h>
88 #include <afs/partition.h>
90 #include <afs/netutils.h>
94 #ifdef AFS_PTHREAD_ENV
97 #if defined(AFS_SGI_ENV)
98 #include "sys/schedctl.h"
101 #include <rx/rx_globals.h>
104 #define afs_stat stat64
105 #define afs_fstat fstat64
106 #define afs_open open64
107 #define afs_fopen fopen64
108 #else /* !O_LARGEFILE */
109 #define afs_stat stat
110 #define afs_fstat fstat
111 #define afs_open open
112 #define afs_fopen fopen
113 #endif /* !O_LARGEFILE */
115 extern int BreakVolumeCallBacks(), InitCallBack();
116 extern int BreakVolumeCallBacks(), InitCallBack(), BreakLaterCallBacks();
117 extern int BreakVolumeCallBacksLater();
118 extern int LogLevel, etext;
119 extern afs_int32 BlocksSpare, PctSpare;
122 static void ClearXStatValues(), NewParms(), PrintCounters();
123 static void ResetCheckDescriptors(void), ResetCheckSignal(void);
124 static int CheckSignal(void);
125 extern int GetKeysFromToken();
126 extern int RXAFS_ExecuteRequest();
127 extern int RXSTATS_ExecuteRequest();
128 afs_int32 Do_VLRegisterRPC();
130 int eventlog = 0, rxlog = 0;
132 FILE *console = NULL;
134 #ifdef AFS_PTHREAD_ENV
135 pthread_mutex_t fsync_glock_mutex;
136 pthread_cond_t fsync_cond;
139 #endif /* AFS_PTHREAD_ENV */
142 #define AFS_QUIETFS_ENV 1
143 #define NT_OPEN_MAX 1024 /* This is an arbitrary no. we came up with for
144 * now. We hope this will be replaced by a more
145 * intelligent estimate later. */
148 int SystemId; /* ViceID of "Administrators" */
149 int SystemAnyUser; /* Viceid of "System:AnyUser" */
150 prlist SystemAnyUserCPS; /* CPS for "system:AnyUser */
151 int AnonymousID = 0; /* ViceId of "Anonymous" */
152 prlist AnonCPS; /* CPS for "Anonymous" */
154 struct afsconf_dir *confDir; /* Configuration dir object */
156 int restartMode = RESTART_ORDINARY;
158 int Testing = 0; /* for ListViceInodes */
161 * Home for the performance statistics.
163 struct afs_PerfStats afs_perfstats;
166 extern int Statistics;
174 int rxJumbograms = 1; /* default is to send and receive jumbograms. */
175 int rxBind = 0; /* don't bind */
177 afs_int32 implicitAdminRights = PRSFS_LOOKUP; /* The ADMINISTER right is
179 afs_int32 readonlyServer = 0;
182 int stackSize = 24000;
183 int fiveminutes = 300; /* 5 minutes. Change this for debugging only */
184 int CurrentConnections = 0;
185 int hostaclRefresh = 7200; /* refresh host clients' acls every 2 hrs */
186 #if defined(AFS_SGI_ENV)
191 int rxpackets = 150; /* 100 */
192 int nSmallVns = 400; /* 200 */
193 int large = 400; /* 200 */
194 int volcache = 400; /* 400 */
195 int numberofcbs = 60000; /* 60000 */
196 int lwps = 9; /* 6 */
197 int buffs = 90; /* 70 */
198 int novbc = 0; /* Enable Volume Break calls */
199 int busy_threshold = 600;
200 int abort_threshold = 10;
201 int udpBufSize = 0; /* UDP buffer size for receive */
202 int sendBufSize = 16384; /* send buffer size */
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
230 struct fs_state fs_state =
237 PTHREAD_COND_INITIALIZER,
238 PTHREAD_RWLOCK_INITIALIZER
240 #endif /* AFS_DEMAND_ATTACH_FS */
243 * Home for the performance statistics.
251 struct afs_stat status;
252 register int tsize = getdtablesize();
254 for (i = 0; i < tsize; i++) {
255 if (afs_fstat(i, &status) != -1) {
256 printf("%d: dev %x, inode %u, length %u, type/mode %x\n", i,
257 status.st_dev, status.st_ino, status.st_size,
262 ResetCheckDescriptors();
265 } /*CheckDescriptors */
268 #ifdef AFS_PTHREAD_ENV
270 CheckSignal_Signal(x)
282 CheckDescriptors_Signal(x)
286 #else /* AFS_PTHREAD_ENV */
288 CheckSignal_Signal(x)
290 IOMGR_SoftSig(CheckSignal, 0);
296 IOMGR_SoftSig(ShutDown, 0);
300 CheckDescriptors_Signal(x)
302 IOMGR_SoftSig(CheckDescriptors, 0);
304 #endif /* AFS_PTHREAD_ENV */
306 /* check whether caller is authorized to manage RX statistics */
308 fs_rxstat_userok(struct rx_call *call)
310 return afsconf_SuperUser(confDir, call, NULL);
314 ResetCheckSignal(void)
318 #if defined(AFS_HPUX_ENV)
321 #if defined(AFS_NT40_ENV)
328 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
329 softsig_signal(signo, CheckSignal_Signal);
331 signal(signo, CheckSignal_Signal);
336 ResetCheckDescriptors(void)
339 #if defined(AFS_PTHREAD_ENV)
340 softsig_signal(SIGTERM, CheckDescriptors_Signal);
342 (void)signal(SIGTERM, CheckDescriptors_Signal);
347 #if defined(AFS_PTHREAD_ENV)
351 return pthread_getspecific(rx_thread_id_key);
355 /* proc called by rxkad module to get a key */
357 get_key(char *arock, register afs_int32 akvno, char *akey)
360 static struct afsconf_key tkey;
361 register afs_int32 code;
364 ViceLog(0, ("conf dir not open\n"));
367 code = afsconf_GetKey(confDir, akvno, tkey.key);
369 ViceLog(0, ("afsconf_GetKey failure: kvno %d code %d\n", akvno, code));
372 memcpy(akey, tkey.key, sizeof(tkey.key));
379 viced_syscall(afs_uint32 a3, afs_uint32 a4, void *a5)
384 #ifndef AFS_LINUX20_ENV
385 old = (void (*)())signal(SIGSYS, SIG_IGN);
387 rcode = syscall(AFS_SYSCALL, 28 /* AFSCALL_CALL */ , a3, a4, a5);
388 #ifndef AFS_LINUX20_ENV
396 #if !defined(AFS_NT40_ENV)
397 #include "AFS_component_version_number.c"
398 #endif /* !AFS_NT40_ENV */
400 #define MAXADMINNAME 64
401 char adminName[MAXADMINNAME];
407 struct afs_stat status;
409 if ((afs_stat("/AdminName", &status)) || /* if file does not exist */
410 (status.st_size <= 0) || /* or it is too short */
411 (status.st_size >= (MAXADMINNAME)) || /* or it is too long */
412 !(fd = afs_open("/AdminName", O_RDONLY, 0))) { /* or the open fails */
413 strcpy(adminName, "System:Administrators"); /* use the default name */
415 (void)read(fd, adminName, status.st_size); /* use name from the file */
418 close(fd); /* close fd if it was opened */
420 } /*CheckAdminName */
426 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
427 /* set our 'thread-id' so that the host hold table works */
428 MUTEX_ENTER(&rx_stats_mutex); /* protects rxi_pthread_hinum */
430 pthread_setspecific(rx_thread_id_key, (void *)rxi_pthread_hinum);
431 MUTEX_EXIT(&rx_stats_mutex);
433 ("Set thread id %d for '%s'\n",
434 pthread_getspecific(rx_thread_id_key), s));
438 /* This LWP does things roughly every 5 minutes */
445 ViceLog(1, ("Starting five minute check process\n"));
446 setThreadId("FiveMinuteCheckLWP");
448 #ifdef AFS_DEMAND_ATTACH_FS
450 while (fs_state.mode == FS_MODE_NORMAL) {
451 fs_state.FiveMinuteLWP_tranquil = 1;
457 #ifdef AFS_PTHREAD_ENV
459 #else /* AFS_PTHREAD_ENV */
460 IOMGR_Sleep(fiveminutes);
461 #endif /* AFS_PTHREAD_ENV */
463 #ifdef AFS_DEMAND_ATTACH_FS
465 if (fs_state.mode != FS_MODE_NORMAL) {
468 fs_state.FiveMinuteLWP_tranquil = 0;
472 /* close the log so it can be removed */
473 ReOpenLog(AFSDIR_SERVER_FILELOG_FILEPATH); /* don't trunc, just append */
474 ViceLog(2, ("Cleaning up timed out callbacks\n"));
475 if (CleanupTimedOutCallBacks())
476 ViceLog(5, ("Timed out callbacks deleted\n"));
477 ViceLog(2, ("Set disk usage statistics\n"));
479 if (FS_registered == 1)
481 /* Force wakeup in case we missed something; pthreads does timedwait */
482 #ifndef AFS_PTHREAD_ENV
483 LWP_NoYieldSignal(fsync_wait);
485 if (printBanner && (++msg & 1)) { /* Every 10 minutes */
486 time_t now = FT_ApproxTime();
487 if (console != NULL) {
488 #ifndef AFS_QUIETFS_ENV
489 fprintf(console, "File server is running at %s\r",
490 afs_ctime(&now, tbuffer, sizeof(tbuffer)));
491 #endif /* AFS_QUIETFS_ENV */
493 ("File server is running at %s\n",
494 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
497 #ifdef AFS_DEMAND_ATTACH_FS
501 #ifdef AFS_DEMAND_ATTACH_FS
502 fs_state.FiveMinuteLWP_tranquil = 1;
504 assert(pthread_cond_broadcast(&fs_state.worker_done_cv)==0);
508 } /*FiveMinuteCheckLWP */
511 /* This LWP does host checks every 5 minutes: it should not be used for
512 * other 5 minute activities because it may be delayed by timeouts when
513 * it probes the workstations
519 ViceLog(1, ("Starting Host check process\n"));
520 setThreadId("HostCheckLWP");
521 #ifdef AFS_DEMAND_ATTACH_FS
523 while (fs_state.mode == FS_MODE_NORMAL) {
524 fs_state.HostCheckLWP_tranquil = 1;
530 #ifdef AFS_PTHREAD_ENV
532 #else /* AFS_PTHREAD_ENV */
533 IOMGR_Sleep(fiveminutes);
534 #endif /* AFS_PTHREAD_ENV */
536 #ifdef AFS_DEMAND_ATTACH_FS
538 if (fs_state.mode != FS_MODE_NORMAL) {
541 fs_state.HostCheckLWP_tranquil = 0;
545 ViceLog(2, ("Checking for dead venii & clients\n"));
548 #ifdef AFS_DEMAND_ATTACH_FS
552 #ifdef AFS_DEMAND_ATTACH_FS
553 fs_state.HostCheckLWP_tranquil = 1;
555 assert(pthread_cond_broadcast(&fs_state.worker_done_cv)==0);
561 /* This LWP does fsync checks every 5 minutes: it should not be used for
562 * other 5 minute activities because it may be delayed by timeouts when
563 * it probes the workstations
569 #ifdef AFS_PTHREAD_ENV
570 struct timespec fsync_next;
572 ViceLog(1, ("Starting fsync check process\n"));
574 setThreadId("FsyncCheckLWP");
576 #ifdef AFS_PTHREAD_ENV
577 assert(pthread_cond_init(&fsync_cond, NULL) == 0);
578 assert(pthread_mutex_init(&fsync_glock_mutex, NULL) == 0);
581 #ifdef AFS_DEMAND_ATTACH_FS
583 while (fs_state.mode == FS_MODE_NORMAL) {
584 fs_state.FsyncCheckLWP_tranquil = 1;
590 #ifdef AFS_PTHREAD_ENV
591 /* rounding is fine */
592 fsync_next.tv_nsec = 0;
593 fsync_next.tv_sec = time(0) + fiveminutes;
596 pthread_cond_timedwait(&fsync_cond, &fsync_glock_mutex,
598 if (code != 0 && code != ETIMEDOUT)
599 ViceLog(0, ("pthread_cond_timedwait returned %d\n", code));
600 #else /* AFS_PTHREAD_ENV */
601 if ((code = LWP_WaitProcess(fsync_wait)) != LWP_SUCCESS)
602 ViceLog(0, ("LWP_WaitProcess returned %d\n", code));
603 #endif /* AFS_PTHREAD_ENV */
606 #ifdef AFS_DEMAND_ATTACH_FS
608 if (fs_state.mode != FS_MODE_NORMAL) {
611 fs_state.FsyncCheckLWP_tranquil = 0;
613 #endif /* AFS_DEMAND_ATTACH_FS */
615 ViceLog(2, ("Checking for fsync events\n"));
617 code = BreakLaterCallBacks();
619 #ifdef AFS_DEMAND_ATTACH_FS
623 #ifdef AFS_DEMAND_ATTACH_FS
624 fs_state.FsyncCheckLWP_tranquil = 1;
626 assert(pthread_cond_broadcast(&fs_state.worker_done_cv)==0);
629 #endif /* AFS_DEMAND_ATTACH_FS */
632 /*------------------------------------------------------------------------
633 * PRIVATE ClearXStatValues
636 * Initialize all of the values collected via the xstat
646 * Must be called during File Server initialization.
650 *------------------------------------------------------------------------*/
654 { /*ClearXStatValues */
656 struct fs_stats_opTimingData *opTimeP; /*Ptr to timing struct */
657 struct fs_stats_xferData *opXferP; /*Ptr to xfer struct */
658 int i; /*Loop counter */
661 * Zero all xstat-related structures.
663 memset((char *)(&afs_perfstats), 0, sizeof(struct afs_PerfStats));
664 #if FS_STATS_DETAILED
665 memset((char *)(&afs_FullPerfStats), 0,
666 sizeof(struct fs_stats_FullPerfStats));
669 * That's not enough. We have to set reasonable minima for
670 * time and xfer values in the detailed stats.
672 opTimeP = &(afs_FullPerfStats.det.rpcOpTimes[0]);
673 for (i = 0; i < FS_STATS_NUM_RPC_OPS; i++, opTimeP++)
674 opTimeP->minTime.tv_sec = 999999;
676 opXferP = &(afs_FullPerfStats.det.xferOpTimes[0]);
677 for (i = 0; i < FS_STATS_NUM_XFER_OPS; i++, opXferP++) {
678 opXferP->minTime.tv_sec = 999999;
679 opXferP->minBytes = 999999999;
683 * There's more. We have to set our unique system identifier, as
684 * declared in param.h. If such a thing is not defined, we bitch
685 * and declare ourselves to be an unknown system type.
688 afs_perfstats.sysname_ID = SYS_NAME_ID;
691 ViceLog(0, ("Sys name ID constant not defined in param.h!!\n"));
692 ViceLog(0, ("[Choosing ``undefined'' sys name ID.\n"));
694 afs_perfstats.sysname_ID = SYS_NAME_ID_UNDEFINED;
695 #endif /* SYS_NAME_ID */
698 } /*ClearXStatValues */
704 int dirbuff, dircall, dirio;
706 int workstations, activeworkstations, delworkstations;
710 TM_GetTimeOfDay(&tpl, 0);
713 ("Vice was last started at %s\n",
714 afs_ctime(&StartTime, tbuffer, sizeof(tbuffer))));
716 #ifdef AFS_DEMAND_ATTACH_FS
717 /* XXX perhaps set extended stats verbosity flags
718 * based upon LogLevel ?? */
719 VPrintExtendedCacheStats(VOL_STATS_PER_CHAIN2);
723 DStat(&dirbuff, &dircall, &dirio);
725 ("With %d directory buffers; %d reads resulted in %d read I/Os\n",
726 dirbuff, dircall, dirio));
727 rx_PrintStats(stderr);
729 PrintCallBackStats();
731 processSize = -1; /* TODO: */
733 processSize = (int)((long)sbrk(0) >> 10);
736 ("There are %d connections, process size %d\n",
737 CurrentConnections, processSize));
738 h_GetWorkStats(&workstations, &activeworkstations, &delworkstations,
739 tpl.tv_sec - 15 * 60);
741 ("There are %d workstations, %d are active (req in < 15 mins), %d marked \"down\"\n",
742 workstations, activeworkstations, delworkstations));
752 if (FS_registered > 0) {
754 * We have proper ip addresses; tell the vlserver what we got; the following
755 * routine will do the proper reporting for us
768 ShutDownAndCore(int dopanic)
770 time_t now = time(0);
773 /* do not allows new reqests to be served from now on, all new requests
774 * are returned with an error code of RX_RESTARTING ( transient failure ) */
775 rx_SetRxTranquil(); /* dhruba */
777 #ifdef AFS_DEMAND_ATTACH_FS
779 fs_state.mode = FS_MODE_SHUTDOWN;
784 ("Shutting down file server at %s",
785 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
787 ViceLog(0, ("ABNORMAL SHUTDOWN, see core file.\n"));
788 #ifndef AFS_QUIETFS_ENV
789 if (console != NULL) {
790 fprintf(console, "File server restart/shutdown received at %s\r",
791 afs_ctime(&now, tbuffer, sizeof(tbuffer)));
798 /* shut down volume package */
801 #ifdef AFS_DEMAND_ATTACH_FS
802 if (fs_state.options.fs_state_save) {
805 * save fileserver state to disk */
807 /* make sure background threads have finished all of their asynchronous
808 * work on host and callback structures */
810 while (!fs_state.FiveMinuteLWP_tranquil ||
811 !fs_state.HostCheckLWP_tranquil ||
812 !fs_state.FsyncCheckLWP_tranquil) {
815 ViceLog(0, ("waiting for background host/callback threads to quiesce before saving fileserver state...\n"));
816 assert(pthread_cond_wait(&fs_state.worker_done_cv, &fileproc_glock_mutex) == 0);
821 /* ok. it should now be fairly safe. let's do the state dump */
824 #endif /* AFS_DEMAND_ATTACH_FS */
827 rx_PrintStats(debugFile);
830 if (console != NULL) {
833 #ifndef AFS_QUIETFS_ENV
834 fprintf(console, "File server has terminated abnormally at %s\r",
835 afs_ctime(&now, tbuffer, sizeof(tbuffer)));
838 ("File server has terminated abnormally at %s\n",
839 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
841 #ifndef AFS_QUIETFS_ENV
842 fprintf(console, "File server has terminated normally at %s\r",
843 afs_ctime(&now, tbuffer, sizeof(tbuffer)));
846 ("File server has terminated normally at %s\n",
847 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
856 { /* backward compatibility */
857 ShutDownAndCore(DONTPANIC);
867 /* default supports help flag */
869 strcpy(buffer, "Usage: fileserver ");
870 strcpy(buffer, "[-auditlog <log path>] ");
871 strcat(buffer, "[-d <debug level>] ");
872 strcat(buffer, "[-p <number of processes>] ");
873 strcat(buffer, "[-spare <number of spare blocks>] ");
874 strcat(buffer, "[-pctspare <percentage spare>] ");
875 strcat(buffer, "[-b <buffers>] ");
876 strcat(buffer, "[-l <large vnodes>] ");
877 strcat(buffer, "[-s <small vnodes>] ");
878 strcat(buffer, "[-vc <volume cachesize>] ");
879 strcat(buffer, "[-w <call back wait interval>] ");
880 strcat(buffer, "[-cb <number of call backs>] ");
881 strcat(buffer, "[-banner (print banner every 10 minutes)] ");
882 strcat(buffer, "[-novbc (whole volume cbs disabled)] ");
883 strcat(buffer, "[-implicit <admin mode bits: rlidwka>] ");
884 strcat(buffer, "[-readonly (read-only file server)] ");
886 "[-hr <number of hours between refreshing the host cps>] ");
887 strcat(buffer, "[-busyat <redirect clients when queue > n>] ");
888 strcat(buffer, "[-nobusy <no VBUSY before a volume is attached>] ");
889 strcat(buffer, "[-rxpck <number of rx extra packets>] ");
890 strcat(buffer, "[-rxdbg (enable rx debugging)] ");
891 strcat(buffer, "[-rxdbge (enable rxevent debugging)] ");
892 strcat(buffer, "[-rxmaxmtu <bytes>] ");
893 strcat(buffer, "[-rxbind (bind the Rx socket to one address)] ");
894 #ifdef AFS_DEMAND_ATTACH_FS
895 strcat(buffer, "[-fs-state-dont-save (disable state save during shutdown)] ");
896 strcat(buffer, "[-fs-state-dont-restore (disable state restore during startup)] ");
897 strcat(buffer, "[-fs-state-verify <none|save|restore|both> (default is both)] ");
898 strcat(buffer, "[-vattachpar <max number of volume attach/shutdown threads> (default is 1)] ");
899 strcat(buffer, "[-vhashsize <log(2) of number of volume hash buckets> (default is 8)] ");
900 strcat(buffer, "[-vlrudisable (disable VLRU functionality)] ");
901 strcat(buffer, "[-vlruthresh <minutes before unused volumes become eligible for soft detach> (default is 2 hours)] ");
902 strcat(buffer, "[-vlruinterval <seconds between VLRU scans> (default is 2 minutes)] ");
903 strcat(buffer, "[-vlrumax <max volumes to soft detach in one VLRU scan> (default is 8)] ");
904 #elif AFS_PTHREAD_ENV
905 strcat(buffer, "[-vattachpar <number of volume attach threads> (default is 1)] ");
908 strcat(buffer, "[-m <min percentage spare in partition>] ");
910 #if defined(AFS_SGI_ENV)
911 strcat(buffer, "[-lock (keep fileserver from swapping)] ");
913 strcat(buffer, "[-L (large server conf)] ");
914 strcat(buffer, "[-S (small server conf)] ");
915 strcat(buffer, "[-k <stack size>] ");
916 strcat(buffer, "[-realm <Kerberos realm name>] ");
917 strcat(buffer, "[-udpsize <size of socket buffer in bytes>] ");
918 strcat(buffer, "[-sendsize <size of send buffer in bytes>] ");
919 strcat(buffer, "[-abortthreshold <abort threshold>] ");
920 /* strcat(buffer, "[-enable_peer_stats] "); */
921 /* strcat(buffer, "[-enable_process_stats] "); */
922 strcat(buffer, "[-help]\n");
924 ViceLog(0, ("%s", buffer));
927 printf("%s", buffer);
934 ParseRights(char *arights)
940 if (!arights || !strcmp(arights, "")) {
941 printf("Missing list of mode bits on -implicit option\n");
944 if (!strcmp(arights, "none"))
946 else if (!strcmp(arights, "read"))
947 mode = PRSFS_READ | PRSFS_LOOKUP;
948 else if (!strcmp(arights, "write"))
950 PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
951 PRSFS_WRITE | PRSFS_LOCK;
952 else if (!strcmp(arights, "all"))
954 PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
955 PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER;
957 len = strlen(arights);
958 for (i = 0; i < len; i++) {
963 mode |= PRSFS_LOOKUP;
965 mode |= PRSFS_INSERT;
967 mode |= PRSFS_DELETE;
973 mode |= PRSFS_ADMINISTER;
991 printf("Illegal -implicit rights character '%c'.\n", tc);
1000 * Limit MAX_FILESERVER_THREAD by the system limit on the number of
1001 * pthreads (sysconf(_SC_THREAD_THREADS_MAX)), if applicable and
1004 * AIX: sysconf() limit is real
1005 * HP-UX: sysconf() limit is real
1006 * IRIX: sysconf() limit is apparently NOT real -- too small
1007 * DUX: sysconf() limit is apparently NOT real -- too big
1008 * Linux: sysconf() limit is apparently NOT real -- too big
1009 * Solaris: no sysconf() limit
1012 max_fileserver_thread(void)
1014 #if defined(AFS_PTHREAD_ENV)
1015 #if defined(AFS_AIX_ENV) || defined(AFS_HPUX_ENV)
1018 ans = sysconf(_SC_THREAD_THREADS_MAX);
1019 if (0 < ans && ans < MAX_FILESERVER_THREAD)
1022 #endif /* defined(AFS_PTHREAD_ENV) */
1023 return MAX_FILESERVER_THREAD;
1027 ParseArgs(int argc, char *argv[])
1029 int SawL = 0, SawS = 0, SawVC = 0;
1030 int Sawrxpck = 0, Sawsmall = 0, Sawlarge = 0, Sawcbs = 0, Sawlwps =
1034 int bufSize = 0; /* temp variable to read in udp socket buf size */
1036 for (i = 1; i < argc; i++) {
1037 if (!strcmp(argv[i], "-d")) {
1038 if ((i + 1) >= argc) {
1039 fprintf(stderr, "missing argument for -d\n");
1042 debuglevel = atoi(argv[++i]);
1043 LogLevel = debuglevel;
1044 } else if (!strcmp(argv[i], "-banner")) {
1046 } else if (!strcmp(argv[i], "-implicit")) {
1047 if ((i + 1) >= argc) {
1048 fprintf(stderr, "missing argument for -implicit\n");
1051 implicitAdminRights = ParseRights(argv[++i]);
1052 if (implicitAdminRights < 0)
1053 return implicitAdminRights;
1054 } else if (!strcmp(argv[i], "-readonly")) {
1056 } else if (!strcmp(argv[i], "-L")) {
1058 } else if (!strcmp(argv[i], "-S")) {
1060 } else if (!strcmp(argv[i], "-p")) {
1062 max_fileserver_thread() - FILESERVER_HELPER_THREADS;
1064 if ((i + 1) >= argc) {
1065 fprintf(stderr, "missing argument for -p\n");
1068 lwps = atoi(argv[++i]);
1069 if (lwps > lwps_max)
1073 } else if (!strcmp(argv[i], "-b")) {
1075 if ((i + 1) >= argc) {
1076 fprintf(stderr, "missing argument for -b\n");
1079 buffs = atoi(argv[++i]);
1080 } else if (!strcmp(argv[i], "-l")) {
1082 if ((i + 1) >= argc) {
1083 fprintf(stderr, "missing argument for -l\n");
1086 large = atoi(argv[++i]);
1087 } else if (!strcmp(argv[i], "-vc")) {
1089 if ((i + 1) >= argc) {
1090 fprintf(stderr, "missing argument for -vc\n");
1093 volcache = atoi(argv[++i]);
1094 } else if (!strcmp(argv[i], "-novbc")) {
1096 } else if (!strcmp(argv[i], "-rxpck")) {
1098 if ((i + 1) >= argc) {
1099 fprintf(stderr, "missing argument for -rxpck\n");
1102 rxpackets = atoi(argv[++i]);
1103 #ifdef AFS_PTHREAD_ENV
1104 } else if (!strcmp(argv[i], "-vattachpar")) {
1105 if ((i + 1) >= argc) {
1106 fprintf(stderr, "missing argument for %s\n", argv[i]);
1109 vol_attach_threads = atoi(argv[++i]);
1110 #endif /* AFS_PTHREAD_ENV */
1111 #ifdef AFS_DEMAND_ATTACH_FS
1112 } else if (!strcmp(argv[i], "-fs-state-dont-save")) {
1113 fs_state.options.fs_state_save = 0;
1114 } else if (!strcmp(argv[i], "-fs-state-dont-restore")) {
1115 fs_state.options.fs_state_restore = 0;
1116 } else if (!strcmp(argv[i], "-fs-state-verify")) {
1117 if ((i + 1) >= argc) {
1118 fprintf(stderr, "missing argument for %s\n", argv[i]);
1122 if (!strcmp(argv[i], "none")) {
1123 fs_state.options.fs_state_verify_before_save = 0;
1124 fs_state.options.fs_state_verify_after_restore = 0;
1125 } else if (!strcmp(argv[i], "save")) {
1126 fs_state.options.fs_state_verify_after_restore = 0;
1127 } else if (!strcmp(argv[i], "restore")) {
1128 fs_state.options.fs_state_verify_before_save = 0;
1129 } else if (!strcmp(argv[i], "both")) {
1132 fprintf(stderr, "invalid argument for %s\n", argv[i-1]);
1135 } else if (!strcmp(argv[i], "-vhashsize")) {
1136 if ((i + 1) >= argc) {
1137 fprintf(stderr, "missing argument for %s\n", argv[i]);
1140 VSetVolHashSize(atoi(argv[++i]));
1141 } else if (!strcmp(argv[i], "-vlrudisable")) {
1142 VLRU_SetOptions(VLRU_SET_ENABLED, 0);
1143 } else if (!strcmp(argv[i], "-vlruthresh")) {
1144 if ((i + 1) >= argc) {
1145 fprintf(stderr, "missing argument for %s\n", argv[i]);
1148 VLRU_SetOptions(VLRU_SET_THRESH, 60*atoi(argv[++i]));
1149 } else if (!strcmp(argv[i], "-vlruinterval")) {
1150 if ((i + 1) >= argc) {
1151 fprintf(stderr, "missing argument for %s\n", argv[i]);
1154 VLRU_SetOptions(VLRU_SET_INTERVAL, atoi(argv[++i]));
1155 } else if (!strcmp(argv[i], "-vlrumax")) {
1156 if ((i + 1) >= argc) {
1157 fprintf(stderr, "missing argument for %s\n", argv[i]);
1160 VLRU_SetOptions(VLRU_SET_MAX, atoi(argv[++i]));
1161 #endif /* AFS_DEMAND_ATTACH_FS */
1162 } else if (!strcmp(argv[i], "-s")) {
1164 if ((i + 1) >= argc) {
1165 fprintf(stderr, "missing argument for -s\n");
1168 nSmallVns = atoi(argv[++i]);
1169 } else if (!strcmp(argv[i], "-abortthreshold")) {
1170 if ((i + 1) >= argc) {
1171 fprintf(stderr, "missing argument for -abortthreshold\n");
1174 abort_threshold = atoi(argv[++i]);
1175 } else if (!strcmp(argv[i], "-k")) {
1176 if ((i + 1) >= argc) {
1177 fprintf(stderr, "missing argument for -k\n");
1180 stack = atoi(argv[++i]);
1182 #if defined(AFS_SGI_ENV)
1183 else if (!strcmp(argv[i], "-lock")) {
1187 else if (!strcmp(argv[i], "-spare")) {
1188 if ((i + 1) >= argc) {
1189 fprintf(stderr, "missing argument for -spare\n");
1192 BlocksSpare = atoi(argv[++i]);
1194 } else if (!strcmp(argv[i], "-pctspare")) {
1195 if ((i + 1) >= argc) {
1196 fprintf(stderr, "missing argument for -pctspare\n");
1199 PctSpare = atoi(argv[++i]);
1200 BlocksSpare = 0; /* has non-zero default */
1202 } else if (!strcmp(argv[i], "-w")) {
1203 if ((i + 1) >= argc) {
1204 fprintf(stderr, "missing argument for -w\n");
1207 fiveminutes = atoi(argv[++i]);
1208 } else if (!strcmp(argv[i], "-hr")) {
1210 if ((i + 1) >= argc) {
1211 fprintf(stderr, "missing argument for -hr\n");
1214 hr = atoi(argv[++i]);
1215 if ((hr < 1) || (hr > 36)) {
1217 ("host acl refresh interval of %d hours is invalid; hours must be between 1 and 36\n\n",
1221 hostaclRefresh = hr * 60 * 60;
1222 } else if (!strcmp(argv[i], "-rxdbg"))
1224 else if (!strcmp(argv[i], "-rxdbge"))
1226 else if (!strcmp(argv[i], "-cb")) {
1228 if ((i + 1) >= argc) {
1229 fprintf(stderr, "missing argument for -cb\n");
1232 numberofcbs = atoi(argv[++i]);
1233 if ((numberofcbs < 10000) || (numberofcbs > 2147483647)) {
1235 ("number of cbs %d invalid; must be between 10000 and 2147483647\n",
1239 } else if (!strcmp(argv[i], "-busyat")) {
1241 if ((i + 1) >= argc) {
1242 fprintf(stderr, "missing argument for -busyat\n");
1245 busy_threshold = atoi(argv[++i]);
1246 if (busy_threshold < 10) {
1248 ("Busy threshold %d is too low, will compute default.\n",
1252 } else if (!strcmp(argv[i], "-nobusy"))
1254 #ifdef AFS_AIX32_ENV
1255 else if (!strcmp(argv[i], "-m")) {
1256 extern int aixlow_water;
1257 if ((i + 1) >= argc) {
1258 fprintf(stderr, "missing argument for -m\n");
1261 aixlow_water = atoi(argv[++i]);
1262 if ((aixlow_water < 0) || (aixlow_water > 30)) {
1263 printf("space reserved %d% invalid; must be between 0-30%\n",
1269 else if (!strcmp(argv[i], "-nojumbo")) {
1271 } else if (!strcmp(argv[i], "-rxbind")) {
1273 } else if (!strcmp(argv[i], "-rxmaxmtu")) {
1274 if ((i + 1) >= argc) {
1275 fprintf(stderr, "missing argument for -rxmaxmtu\n");
1278 rxMaxMTU = atoi(argv[++i]);
1279 if ((rxMaxMTU < RX_MIN_PACKET_SIZE) ||
1280 (rxMaxMTU > RX_MAX_PACKET_DATA_SIZE)) {
1281 printf("rxMaxMTU %d%% invalid; must be between %d-%d\n",
1282 rxMaxMTU, RX_MIN_PACKET_SIZE,
1283 RX_MAX_PACKET_DATA_SIZE);
1286 } else if (!strcmp(argv[i], "-realm")) {
1287 extern char local_realms[AFS_NUM_LREALMS][AFS_REALM_SZ];
1288 extern int num_lrealms;
1289 if ((i + 1) >= argc) {
1290 fprintf(stderr, "missing argument for -realm\n");
1293 if (strlen(argv[++i]) >= AFS_REALM_SZ) {
1295 ("-realm argument must contain fewer than %d characters.\n",
1299 if (num_lrealms == -1)
1301 if (num_lrealms >= AFS_NUM_LREALMS) {
1303 ("a maximum of %d -realm arguments can be specified.\n",
1307 strncpy(local_realms[num_lrealms++], argv[i], AFS_REALM_SZ);
1308 } else if (!strcmp(argv[i], "-udpsize")) {
1309 if ((i + 1) >= argc) {
1310 printf("You have to specify -udpsize <integer value>\n");
1313 bufSize = atoi(argv[++i]);
1314 if (bufSize < rx_GetMinUdpBufSize())
1316 ("Warning:udpsize %d is less than minimum %d; ignoring\n",
1317 bufSize, rx_GetMinUdpBufSize());
1319 udpBufSize = bufSize;
1320 } else if (!strcmp(argv[i], "-sendsize")) {
1321 if ((i + 1) >= argc) {
1322 printf("You have to specify -sendsize <integer value>\n");
1325 bufSize = atoi(argv[++i]);
1326 if (bufSize < 16384)
1328 ("Warning:sendsize %d is less than minimum %d; ignoring\n",
1331 sendBufSize = bufSize;
1332 } else if (!strcmp(argv[i], "-enable_peer_stats")) {
1333 rx_enablePeerRPCStats();
1334 } else if (!strcmp(argv[i], "-enable_process_stats")) {
1335 rx_enableProcessRPCStats();
1337 else if (strcmp(argv[i], "-auditlog") == 0) {
1340 char oldName[MAXPATHLEN];
1341 char *fileName = argv[++i];
1343 #ifndef AFS_NT40_ENV
1344 struct stat statbuf;
1346 if ((lstat(fileName, &statbuf) == 0)
1347 && (S_ISFIFO(statbuf.st_mode))) {
1348 flags = O_WRONLY | O_NONBLOCK;
1352 strcpy(oldName, fileName);
1353 strcat(oldName, ".old");
1354 renamefile(fileName, oldName);
1355 flags = O_WRONLY | O_TRUNC | O_CREAT;
1357 tempfd = open(fileName, flags, 0666);
1359 auditout = fdopen(tempfd, "a");
1361 osi_audit_file(auditout);
1363 printf("Warning: auditlog %s not writable, ignored.\n", fileName);
1365 printf("Warning: auditlog %s not writable, ignored.\n", fileName);
1367 #ifndef AFS_NT40_ENV
1368 else if (strcmp(argv[i], "-syslog") == 0) {
1369 /* set syslog logging flag */
1370 serverLogSyslog = 1;
1371 } else if (strncmp(argv[i], "-syslog=", 8) == 0) {
1372 serverLogSyslog = 1;
1373 serverLogSyslogFacility = atoi(argv[i] + 8);
1376 else if (strcmp(argv[i], "-mrafslogs") == 0) {
1377 /* set syslog logging flag */
1385 printf("Only one of -L, or -S must be specified\n");
1396 numberofcbs = 20000;
1412 numberofcbs = 64000;
1421 busy_threshold = 3 * rxpackets / 2;
1431 NewParms(int initializing)
1433 static struct afs_stat sbuf;
1436 char *argv[MAXPARMS];
1439 if (!(afs_stat("/vice/file/parms", &sbuf))) {
1440 parms = (char *)malloc(sbuf.st_size);
1443 fd = afs_open("parms", O_RDONLY, 0666);
1445 ViceLog(0, ("Open for parms failed with errno = %d\n", errno));
1449 i = read(fd, parms, sbuf.st_size);
1451 if (i != sbuf.st_size) {
1453 ViceLog(0, ("Read on parms failed with errno = %d\n", errno));
1456 ("Read on parms failed; expected %d bytes but read %d\n",
1463 for (i = 0; i < MAXPARMS; argv[i++] = 0);
1465 for (argc = i = 0; i < sbuf.st_size; i++) {
1466 if ((*(parms + i) != ' ') && (*(parms + i) != '\n')) {
1467 if (argv[argc] == 0)
1468 argv[argc] = (parms + i);
1470 *(parms + i) = '\0';
1471 if (argv[argc] != 0) {
1472 if (++argc == MAXPARMS)
1475 while ((*(parms + i + 1) == ' ')
1476 || (*(parms + i + 1) == '\n'))
1480 if (ParseArgs(argc, argv) == 0) {
1481 ViceLog(0, ("Change parameters to:"));
1483 ViceLog(0, ("Invalid parameter in:"));
1485 for (i = 0; i < argc; i++) {
1486 ViceLog(0, (" %s", argv[i]));
1490 } else if (!initializing)
1492 ("Received request to change parms but no parms file exists\n"));
1497 /* Miscellaneous routines */
1501 ViceLog(0, ("%s\n", msg));
1513 * If this fails, it's because something major is wrong, and is not
1514 * likely to be time dependent.
1516 code = pr_Initialize(2, AFSDIR_SERVER_ETC_DIRPATH, 0);
1519 ("Couldn't initialize protection library; code=%d.\n", code));
1522 SystemId = SYSADMINID;
1523 SystemAnyUser = ANYUSERID;
1524 SystemAnyUserCPS.prlist_len = 0;
1525 SystemAnyUserCPS.prlist_val = NULL;
1526 AnonCPS.prlist_len = 0;
1527 AnonCPS.prlist_val = NULL;
1529 code = pr_GetCPS(SystemAnyUser, &SystemAnyUserCPS);
1532 ("Couldn't get CPS for AnyUser, will try again in 30 seconds; code=%d.\n",
1536 code = pr_GetCPS(ANONYMOUSID, &AnonCPS);
1539 ("Couldn't get Anonymous CPS, exiting; code=%d.\n",
1543 AnonymousID = ANONYMOUSID;
1546 #ifdef AFS_PTHREAD_ENV
1548 #else /* AFS_PTHREAD_ENV */
1550 #endif /* AFS_PTHREAD_ENV */
1554 struct rx_connection *serverconns[MAXSERVERS];
1555 struct ubik_client *cstruct;
1558 vl_Initialize(const char *confDir)
1560 afs_int32 code, scIndex = 0, i;
1561 struct afsconf_dir *tdir;
1562 struct rx_securityClass *sc;
1563 struct afsconf_cell info;
1565 tdir = afsconf_Open(confDir);
1568 ("Could not open configuration directory (%s).\n", confDir));
1571 code = afsconf_ClientAuth(tdir, &sc, &scIndex);
1573 ViceLog(0, ("Could not get security object for localAuth\n"));
1576 code = afsconf_GetCellInfo(tdir, NULL, AFSCONF_VLDBSERVICE, &info);
1577 if (info.numServers > MAXSERVERS) {
1579 ("vl_Initialize: info.numServers=%d (> MAXSERVERS=%d)\n",
1580 info.numServers, MAXSERVERS));
1583 for (i = 0; i < info.numServers; i++)
1585 rx_NewConnection(info.hostAddr[i].sin_addr.s_addr,
1586 info.hostAddr[i].sin_port, USER_SERVICE_ID, sc,
1588 code = ubik_ClientInit(serverconns, &cstruct);
1590 ViceLog(0, ("vl_Initialize: ubik client init failed.\n"));
1596 #define SYSIDMAGIC 0x88aabbcc
1597 #define SYSIDVERSION 1
1602 afs_int32 fd, nentries, i;
1603 struct versionStamp vsn;
1604 struct afs_stat status;
1607 if ((afs_stat(AFSDIR_SERVER_SYSID_FILEPATH, &status))
1608 || (status.st_size <= 0)) {
1609 ViceLog(0, ("%s: doesn't exist\n", AFSDIR_SERVER_SYSID_FILEPATH));
1612 if (!(fd = afs_open(AFSDIR_SERVER_SYSID_FILEPATH, O_RDONLY, 0))) {
1614 ("%s: can't open (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1618 if ((i = read(fd, (char *)&vsn, sizeof(vsn))) != sizeof(vsn)) {
1620 ("%s: Read failed (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1624 if (vsn.magic != SYSIDMAGIC) {
1626 ("%s: wrong magic %x (we support %x)\n",
1627 AFSDIR_SERVER_SYSID_FILEPATH, vsn.magic, SYSIDMAGIC));
1630 if (vsn.version != SYSIDVERSION) {
1632 ("%s: wrong version %d (we support %d)\n",
1633 AFSDIR_SERVER_SYSID_FILEPATH, vsn.version, SYSIDVERSION));
1637 read(fd, (char *)&uuid,
1638 sizeof(struct afsUUID))) != sizeof(struct afsUUID)) {
1640 ("%s: read of uuid failed (%d)\n",
1641 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1644 afs_ntohuuid(&uuid);
1647 read(fd, (char *)&nentries,
1648 sizeof(afs_int32))) != sizeof(afs_int32)) {
1650 ("%s: Read of entries failed (%d)\n",
1651 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1654 if (nentries <= 0 || nentries > ADDRSPERSITE) {
1656 ("%s: invalid num of interfaces: %d\n",
1657 AFSDIR_SERVER_SYSID_FILEPATH, nentries));
1660 FS_HostAddr_cnt = nentries;
1661 for (i = 0; i < nentries; i++) {
1662 if (read(fd, (char *)&FS_HostAddrs[i], sizeof(afs_int32)) !=
1663 sizeof(afs_int32)) {
1665 ("%s: Read of addresses failed (%d)\n",
1666 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1667 FS_HostAddr_cnt = 0; /* reset it */
1679 struct versionStamp vsn;
1680 struct afs_stat status;
1683 if (!afs_stat(AFSDIR_SERVER_SYSID_FILEPATH, &status)) {
1685 * File exists; keep the old one around
1687 renamefile(AFSDIR_SERVER_SYSID_FILEPATH,
1688 AFSDIR_SERVER_OLDSYSID_FILEPATH);
1690 fd = afs_open(AFSDIR_SERVER_SYSID_FILEPATH, O_WRONLY | O_TRUNC | O_CREAT,
1694 ("%s: can't create (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1698 vsn.magic = SYSIDMAGIC;
1700 if ((i = write(fd, (char *)&vsn, sizeof(vsn))) != sizeof(vsn)) {
1702 ("%s: write failed (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1707 afs_htonuuid(&uuid);
1709 write(fd, (char *)&uuid,
1710 sizeof(struct afsUUID))) != sizeof(struct afsUUID)) {
1712 ("%s: write of uuid failed (%d)\n",
1713 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1717 write(fd, (char *)&FS_HostAddr_cnt,
1718 sizeof(afs_int32))) != sizeof(afs_int32)) {
1720 ("%s: write of # of entries failed (%d)\n",
1721 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1724 for (i = 0; i < FS_HostAddr_cnt; i++) {
1725 if (write(fd, (char *)&FS_HostAddrs[i], sizeof(afs_int32)) !=
1726 sizeof(afs_int32)) {
1728 ("%s: write of addresses failed (%d)\n",
1729 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1739 * This routine sets up the buffers for the VL_RegisterAddrs RPC. All addresses
1740 * in FS_HostAddrs[] are in NBO, while the RPC treats them as a "blob" of data
1741 * and so we need to convert each of them into HBO which is what the extra
1742 * array called FS_HostAddrs_HBO is used here.
1749 extern int VL_RegisterAddrs();
1750 afs_uint32 FS_HostAddrs_HBO[ADDRSPERSITE];
1753 for (i = 0; i < FS_HostAddr_cnt; i++)
1754 FS_HostAddrs_HBO[i] = ntohl(FS_HostAddrs[i]);
1755 addrs.bulkaddrs_len = FS_HostAddr_cnt;
1756 addrs.bulkaddrs_val = (afs_uint32 *) FS_HostAddrs_HBO;
1757 code = ubik_Call(VL_RegisterAddrs, cstruct, 0, &FS_HostUUID, 0, &addrs);
1759 if (code == VL_MULTIPADDR) {
1761 ("VL_RegisterAddrs rpc failed; The IP address exists on a different server; repair it\n"));
1763 ("VL_RegisterAddrs rpc failed; See VLLog for details\n"));
1765 } else if (code == RXGEN_OPCODE) {
1767 ("vlserver doesn't support VL_RegisterAddrs rpc; ignored\n"));
1768 FS_registered = 2; /* So we don't have to retry in the gc daemon */
1771 ("VL_RegisterAddrs rpc failed; will retry periodically (code=%d, err=%d)\n",
1775 FS_registered = 2; /* So we don't have to retry in the gc daemon */
1786 extern int rxi_numNetAddrs;
1787 extern afs_uint32 rxi_NetAddrs[];
1789 #ifndef AFS_NT40_ENV
1790 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH || AFSDIR_SERVER_NETINFO_FILEPATH) {
1792 * Find addresses we are supposed to register as per the netrestrict
1793 * and netinfo files (/usr/afs/local/NetInfo and
1794 * /usr/afs/local/NetRestict)
1797 afs_int32 code = parseNetFiles(FS_HostAddrs, NULL, NULL,
1798 ADDRSPERSITE, reason,
1799 AFSDIR_SERVER_NETINFO_FILEPATH,
1800 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
1802 ViceLog(0, ("Can't register any valid addresses: %s\n", reason));
1805 FS_HostAddr_cnt = (afs_uint32) code;
1809 FS_HostAddr_cnt = rx_getAllAddr(FS_HostAddrs, ADDRSPERSITE);
1812 if (FS_HostAddr_cnt == 1 && rxBind == 1)
1813 code = FS_HostAddrs[0];
1815 code = htonl(INADDR_ANY);
1825 * If this fails, it's because something major is wrong, and is not
1826 * likely to be time dependent.
1828 code = vl_Initialize(AFSDIR_SERVER_ETC_DIRPATH);
1831 ("Couldn't initialize protection library; code=%d.\n", code));
1835 /* Read or create the sysid file and register the fileserver's
1836 * IP addresses with the vlserver.
1838 code = ReadSysIdFile();
1840 /* Need to create the file */
1841 ViceLog(0, ("Creating new SysID file\n"));
1842 if ((code = afs_uuid_create(&FS_HostUUID))) {
1843 ViceLog(0, ("Failed to create new uuid: %d\n", code));
1847 /* A good sysid file exists; inform the vlserver. If any conflicts,
1848 * we always use the latest interface available as the real truth.
1851 code = Do_VLRegisterRPC();
1856 main(int argc, char *argv[])
1860 struct rx_securityClass *sc[4];
1861 struct rx_service *tservice;
1862 #ifdef AFS_PTHREAD_ENV
1863 pthread_t serverPid;
1864 pthread_attr_t tattr;
1865 #else /* AFS_PTHREAD_ENV */
1866 PROCESS parentPid, serverPid;
1867 #endif /* AFS_PTHREAD_ENV */
1869 int minVnodesRequired; /* min size of vnode cache */
1870 #ifndef AFS_NT40_ENV
1871 struct rlimit rlim; /* max number of open file descriptors */
1875 afs_uint32 rx_bindhost;
1877 #ifdef AFS_AIX32_ENV
1878 struct sigaction nsa;
1880 sigemptyset(&nsa.sa_mask);
1881 nsa.sa_handler = SIG_DFL;
1882 nsa.sa_flags = SA_FULLDUMP;
1883 sigaction(SIGABRT, &nsa, NULL);
1884 sigaction(SIGSEGV, &nsa, NULL);
1888 /* Initialize dirpaths */
1889 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
1891 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
1893 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
1897 #ifndef AFS_QUIETFS_ENV
1898 console = afs_fopen("/dev/console", "w");
1901 if (ParseArgs(argc, argv)) {
1905 #ifdef AFS_PTHREAD_ENV
1906 assert(pthread_mutex_init(&fileproc_glock_mutex, NULL) == 0);
1907 #endif /* AFS_PTHREAD_ENV */
1909 #ifdef AFS_SGI_VNODE_GLUE
1910 if (afs_init_kernel_config(-1) < 0) {
1912 ("Can't determine NUMA configuration, not starting fileserver.\n");
1916 confDir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
1918 fprintf(stderr, "Unable to open config directory %s\n",
1919 AFSDIR_SERVER_ETC_DIRPATH);
1925 /* Open FileLog on stdout, stderr, fd 1 and fd2 (for perror), sigh. */
1926 #ifndef AFS_NT40_ENV
1927 serverLogSyslogTag = "fileserver";
1929 OpenLog(AFSDIR_SERVER_FILELOG_FILEPATH);
1932 if (SawSpare && SawPctSpare) {
1933 ViceLog(0, ("Both -spare and -pctspare specified, exiting.\n"));
1936 #ifdef AFS_SGI_XFS_IOPS_ENV
1937 ViceLog(0, ("XFS/EFS File server starting\n"));
1939 ViceLog(0, ("File server starting\n"));
1942 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
1943 /* initialize the pthread soft signal handler thread */
1947 /* install signal handlers for controlling the fileserver process */
1948 ResetCheckSignal(); /* set CheckSignal_Signal() sig handler */
1949 ResetCheckDescriptors(); /* set CheckDescriptors_Signal() sig handler */
1951 #if defined(AFS_SGI_ENV)
1952 /* give this guy a non-degrading priority so help busy servers */
1953 schedctl(NDPRI, 0, NDPNORMMAX);
1957 #ifndef AFS_NT40_ENV
1958 nice(-5); /* TODO: */
1961 assert(DInit(buffs) == 0);
1964 if (afs_winsockInit() < 0) {
1965 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
1966 ViceLog(0, ("File server failed to intialize winsock.\n"));
1972 /* if we support more than 16 threads, then we better have the ability
1973 ** to keep open a large number of files simultaneously
1975 #if defined(AFS_AIX_ENV) && !defined(AFS_AIX42_ENV)
1976 curLimit = OPEN_MAX; /* for pre AIX 4.2 systems */
1977 #elif defined(AFS_NT40_ENV)
1978 curLimit = NT_OPEN_MAX; /* open file descriptor limit on NT */
1981 curLimit = 0; /* the number of open file descriptors */
1982 code = getrlimit(RLIMIT_NOFILE, &rlim);
1984 curLimit = rlim.rlim_cur;
1985 rlim.rlim_cur = rlim.rlim_max;
1986 code = setrlimit(RLIMIT_NOFILE, &rlim);
1988 curLimit = rlim.rlim_max;
1991 ViceLog(0, ("Failed to increase open file limit, using default\n"));
1993 #endif /* defined(AFS_AIX_ENV) && !defined(AFS_AIX42_ENV) */
1995 curLimit -= 32; /* leave a slack of 32 file descriptors */
1996 if (lwps > curLimit) {
2000 lwps = 16; /* default to a maximum of 16 threads */
2002 ("The system supports a max of %d open files and we are starting %d threads\n",
2005 #ifndef AFS_PTHREAD_ENV
2006 assert(LWP_InitializeProcessSupport(LWP_MAX_PRIORITY - 2, &parentPid) ==
2008 #endif /* !AFS_PTHREAD_ENV */
2010 /* Initialize volume support */
2012 V_BreakVolumeCallbacks = BreakVolumeCallBacksLater;
2015 #ifdef AFS_PTHREAD_ENV
2016 SetLogThreadNumProgram( threadNum );
2019 /* initialize libacl routines */
2020 acl_Initialize(ACL_VERSION);
2022 /* initialize RX support */
2023 #ifndef AFS_NT40_ENV
2024 rxi_syscallp = viced_syscall;
2026 rx_extraPackets = rxpackets;
2027 rx_extraQuota = 4; /* for outgoing prserver calls from R threads */
2028 rx_SetBusyThreshold(busy_threshold, VBUSY);
2029 rx_SetCallAbortThreshold(abort_threshold);
2030 rx_SetConnAbortThreshold(abort_threshold);
2031 stackSize = lwps * 4000;
2032 if (stackSize < 32000)
2034 else if (stackSize > 44000)
2036 #if defined(AFS_HPUX_ENV) || defined(AFS_SUN_ENV) || defined(AFS_SGI51_ENV)
2037 rx_SetStackSize(1, stackSize);
2040 rx_SetUdpBufSize(udpBufSize); /* set the UDP buffer size for receive */
2041 rx_bindhost = SetupVL();
2043 if (rx_InitHost(rx_bindhost, (int)htons(7000)) < 0) {
2044 ViceLog(0, ("Cannot initialize RX\n"));
2047 if (!rxJumbograms) {
2048 /* Don't send and don't allow 3.4 clients to send jumbograms. */
2051 if (rxMaxMTU != -1) {
2052 rx_SetMaxMTU(rxMaxMTU);
2055 rx_SetRxDeadTime(30);
2056 sc[0] = rxnull_NewServerSecurityObject();
2057 sc[1] = 0; /* rxvab_NewServerSecurityObject(key1, 0) */
2058 sc[2] = rxkad_NewServerSecurityObject(rxkad_clear, NULL, get_key, NULL);
2059 sc[3] = rxkad_NewServerSecurityObject(rxkad_crypt, NULL, get_key, NULL);
2060 tservice = rx_NewServiceHost(rx_bindhost, /* port */ 0, /* service id */
2061 1, /*service name */
2063 /* security classes */ sc,
2064 /* numb sec classes */
2065 4, RXAFS_ExecuteRequest);
2068 ("Failed to initialize RX, probably two servers running.\n"));
2071 rx_SetMinProcs(tservice, 3);
2072 rx_SetMaxProcs(tservice, lwps);
2073 rx_SetCheckReach(tservice, 1);
2076 rx_NewService(0, RX_STATS_SERVICE_ID, "rpcstats", sc, 4,
2077 RXSTATS_ExecuteRequest);
2079 ViceLog(0, ("Failed to initialize rpc stat service.\n"));
2082 rx_SetMinProcs(tservice, 2);
2083 rx_SetMaxProcs(tservice, 4);
2086 * Enable RX hot threads, which allows the listener thread to trade
2087 * places with an idle thread and moves the context switch from listener
2088 * to worker out of the critical path.
2090 rx_EnableHotThread();
2092 /* Some rx debugging */
2093 if (rxlog || eventlog) {
2094 debugFile = afs_fopen("rx_dbg", "w");
2096 rx_debugFile = debugFile;
2098 rxevent_debugFile = debugFile;
2101 init_sys_error_to_et(); /* Set up error table translation */
2102 h_InitHostPackage(); /* set up local cellname and realmname */
2103 InitCallBack(numberofcbs);
2108 ViceLog(0, ("Fatal error in library initialization, exiting!!\n"));
2114 ViceLog(0, ("Fatal error in protection initialization, exiting!!\n"));
2118 /* allow super users to manage RX statistics */
2119 rx_SetRxStatUserOk(fs_rxstat_userok);
2121 rx_StartServer(0); /* now start handling requests */
2123 /* we ensure that there is enough space in the vnode buffer to satisfy
2124 ** requests from all concurrent threads.
2125 ** the maximum number of vnodes used by a single thread at any one time
2126 ** is three ( "link" uses three vnodes simultaneously, one vLarge and
2127 ** two vSmall for linking files and two vLarge and one vSmall for linking
2130 minVnodesRequired = 2 * lwps + 1;
2131 if (minVnodesRequired > nSmallVns) {
2132 nSmallVns = minVnodesRequired;
2134 ("Overriding -s command line parameter with %d\n",
2137 if (minVnodesRequired > large) {
2138 large = minVnodesRequired;
2139 ViceLog(0, ("Overriding -l command line parameter with %d\n", large));
2142 /* We now do this after getting the listener up and running, so that client
2143 * connections don't timeout (maybe) if a file server is restarted, since it
2144 * will be available "real soon now". Worry about whether we can satisfy the
2145 * calls in the volume package itself.
2147 if (VInitVolumePackage(fileServer, large, nSmallVns, 0, volcache)) {
2149 ("Shutting down: errors encountered initializing volume package\n"));
2154 #ifdef AFS_DEMAND_ATTACH_FS
2155 if (fs_state.options.fs_state_restore) {
2158 * restore fileserver state */
2161 #endif /* AFS_DEMAND_ATTACH_FS */
2164 * We are done calling fopen/fdopen. It is safe to use a large
2165 * of the file descriptor cache.
2169 #ifdef AFS_PTHREAD_ENV
2170 ViceLog(5, ("Starting pthreads\n"));
2171 assert(pthread_attr_init(&tattr) == 0);
2172 assert(pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED) == 0);
2174 assert(pthread_create
2175 (&serverPid, &tattr, (void *)FiveMinuteCheckLWP,
2176 &fiveminutes) == 0);
2177 assert(pthread_create
2178 (&serverPid, &tattr, (void *)HostCheckLWP, &fiveminutes) == 0);
2179 assert(pthread_create
2180 (&serverPid, &tattr, (void *)FsyncCheckLWP, &fiveminutes) == 0);
2181 #else /* AFS_PTHREAD_ENV */
2182 ViceLog(5, ("Starting LWP\n"));
2183 assert(LWP_CreateProcess
2184 (FiveMinuteCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
2185 (void *)&fiveminutes, "FiveMinuteChecks",
2186 &serverPid) == LWP_SUCCESS);
2188 assert(LWP_CreateProcess
2189 (HostCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
2190 (void *)&fiveminutes, "HostCheck", &serverPid) == LWP_SUCCESS);
2191 assert(LWP_CreateProcess
2192 (FsyncCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
2193 (void *)&fiveminutes, "FsyncCheck", &serverPid) == LWP_SUCCESS);
2194 #endif /* AFS_PTHREAD_ENV */
2196 TM_GetTimeOfDay(&tp, 0);
2198 #ifndef AFS_QUIETFS_ENV
2199 if (console != NULL) {
2200 time_t t = tp.tv_sec;
2201 fprintf(console, "File server has started at %s\r",
2202 afs_ctime(&t, tbuffer, sizeof(tbuffer)));
2207 * Figure out the FileServer's name and primary address.
2209 ViceLog(0, ("Getting FileServer name...\n"));
2210 code = gethostname(FS_HostName, 64);
2212 ViceLog(0, ("gethostname() failed\n"));
2214 ViceLog(0, ("FileServer host name is '%s'\n", FS_HostName));
2216 ViceLog(0, ("Getting FileServer address...\n"));
2217 he = gethostbyname(FS_HostName);
2219 ViceLog(0, ("Can't find address for FileServer '%s'\n", FS_HostName));
2222 memcpy(&FS_HostAddr_NBO, he->h_addr, 4);
2223 (void)afs_inet_ntoa_r(FS_HostAddr_NBO, hoststr);
2224 FS_HostAddr_HBO = ntohl(FS_HostAddr_NBO);
2226 ("FileServer %s has address %s (0x%x or 0x%x in host byte order)\n",
2227 FS_HostName, hoststr, FS_HostAddr_NBO, FS_HostAddr_HBO));
2230 /* Install handler to catch the shutdown signal;
2231 * bosserver assumes SIGQUIT shutdown
2233 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
2234 softsig_signal(SIGQUIT, ShutDown_Signal);
2236 (void)signal(SIGQUIT, ShutDown_Signal);
2241 ("File Server started %s",
2242 afs_ctime(&t, tbuffer, sizeof(tbuffer))));
2243 #if FS_STATS_DETAILED
2244 afs_FullPerfStats.det.epoch.tv_sec = StartTime = tp.tv_sec;
2246 #ifdef AFS_PTHREAD_ENV
2248 sleep(1000); /* long time */
2250 #else /* AFS_PTHREAD_ENV */
2251 assert(LWP_WaitProcess(&parentPid) == LWP_SUCCESS);
2252 #endif /* AFS_PTHREAD_ENV */