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;
114 void *ShutDown(void *);
115 static void ClearXStatValues(), NewParms(), PrintCounters();
116 static void ResetCheckDescriptors(void), ResetCheckSignal(void);
117 static void *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 = 0; /* default is to not send and receive jumbograms. */
166 int rxBind = 0; /* don't bind */
167 int rxkadDisableDotCheck = 0; /* disable check for dot in principal name */
169 afs_int32 implicitAdminRights = PRSFS_LOOKUP; /* The ADMINISTER right is
171 afs_int32 readonlyServer = 0;
174 int stackSize = 24000;
175 int fiveminutes = 300; /* 5 minutes. Change this for debugging only */
176 int CurrentConnections = 0;
177 int hostaclRefresh = 7200; /* refresh host clients' acls every 2 hrs */
178 #if defined(AFS_SGI_ENV)
183 int rxpackets = 150; /* 100 */
184 int nSmallVns = 400; /* 200 */
185 int large = 400; /* 200 */
186 int volcache = 400; /* 400 */
187 int numberofcbs = 60000; /* 60000 */
188 int lwps = 9; /* 6 */
189 int buffs = 90; /* 70 */
190 int novbc = 0; /* Enable Volume Break calls */
191 int busy_threshold = 600;
192 int abort_threshold = 10;
193 int udpBufSize = 0; /* UDP buffer size for receive */
194 int sendBufSize = 16384; /* send buffer size */
195 int saneacls = 0; /* Sane ACLs Flag */
199 #ifdef AFS_PTHREAD_ENV
200 pthread_key_t viced_uclient_key;
204 * FileServer's name and IP address, both network byte order and
207 #define ADDRSPERSITE 16 /* Same global is in rx/rx_user.c */
209 char FS_HostName[128] = "localhost";
210 afs_uint32 FS_HostAddr_NBO;
211 afs_uint32 FS_HostAddr_HBO;
212 afs_uint32 FS_HostAddrs[ADDRSPERSITE], FS_HostAddr_cnt = 0, FS_registered = 0;
213 /* All addresses in FS_HostAddrs are in NBO */
216 static void FlagMsg();
218 #ifdef AFS_DEMAND_ATTACH_FS
221 * fileserver mode support
223 * during fileserver shutdown, we have to track the graceful shutdown of
224 * certain background threads before we are allowed to dump state to
228 #if !defined(PTHREAD_RWLOCK_INITIALIZER) && defined(AFS_DARWIN80_ENV)
229 #define PTHREAD_RWLOCK_INITIALIZER {0x2DA8B3B4, {0}}
232 struct fs_state fs_state =
239 PTHREAD_COND_INITIALIZER,
240 PTHREAD_RWLOCK_INITIALIZER
242 #endif /* AFS_DEMAND_ATTACH_FS */
245 * Home for the performance statistics.
250 CheckDescriptors(void *unused)
253 struct afs_stat status;
254 register int tsize = getdtablesize();
256 for (i = 0; i < tsize; i++) {
257 if (afs_fstat(i, &status) != -1) {
258 printf("%d: dev %x, inode %u, length %u, type/mode %x\n", i,
259 status.st_dev, status.st_ino,
260 (unsigned int) status.st_size,
265 ResetCheckDescriptors();
268 } /*CheckDescriptors */
271 #ifdef AFS_PTHREAD_ENV
273 CheckSignal_Signal(x)
285 CheckDescriptors_Signal(x)
287 CheckDescriptors(NULL);
289 #else /* AFS_PTHREAD_ENV */
291 CheckSignal_Signal(x)
293 IOMGR_SoftSig(CheckSignal, 0);
299 IOMGR_SoftSig(ShutDown, 0);
303 CheckDescriptors_Signal(x)
305 IOMGR_SoftSig(CheckDescriptors, 0);
307 #endif /* AFS_PTHREAD_ENV */
309 /* check whether caller is authorized to manage RX statistics */
311 fs_rxstat_userok(struct rx_call *call)
313 return afsconf_SuperUser(confDir, call, NULL);
317 ResetCheckSignal(void)
321 #if defined(AFS_HPUX_ENV)
324 #if defined(AFS_NT40_ENV)
331 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
332 softsig_signal(signo, CheckSignal_Signal);
334 signal(signo, CheckSignal_Signal);
339 ResetCheckDescriptors(void)
342 #if defined(AFS_PTHREAD_ENV)
343 softsig_signal(SIGTERM, CheckDescriptors_Signal);
345 (void)signal(SIGTERM, CheckDescriptors_Signal);
350 #if defined(AFS_PTHREAD_ENV)
354 return pthread_getspecific(rx_thread_id_key);
358 /* proc called by rxkad module to get a key */
360 get_key(char *arock, register afs_int32 akvno, char *akey)
363 static struct afsconf_key tkey;
364 register afs_int32 code;
367 ViceLog(0, ("conf dir not open\n"));
370 code = afsconf_GetKey(confDir, akvno, tkey.key);
372 ViceLog(0, ("afsconf_GetKey failure: kvno %d code %d\n", akvno, code));
375 memcpy(akey, tkey.key, sizeof(tkey.key));
382 viced_syscall(afs_uint32 a3, afs_uint32 a4, void *a5)
387 #ifndef AFS_LINUX20_ENV
388 old = (void (*)())signal(SIGSYS, SIG_IGN);
390 rcode = syscall(AFS_SYSCALL, 28 /* AFSCALL_CALL */ , a3, a4, a5);
391 #ifndef AFS_LINUX20_ENV
399 #if !defined(AFS_NT40_ENV)
400 #include "AFS_component_version_number.c"
401 #endif /* !AFS_NT40_ENV */
403 #define MAXADMINNAME 64
404 char adminName[MAXADMINNAME];
410 struct afs_stat status;
412 if ((afs_stat("/AdminName", &status)) || /* if file does not exist */
413 (status.st_size <= 0) || /* or it is too short */
414 (status.st_size >= (MAXADMINNAME)) || /* or it is too long */
415 !(fd = afs_open("/AdminName", O_RDONLY, 0))) { /* or the open fails */
416 strcpy(adminName, "System:Administrators"); /* use the default name */
418 (void)read(fd, adminName, status.st_size); /* use name from the file */
421 close(fd); /* close fd if it was opened */
423 } /*CheckAdminName */
429 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
430 /* set our 'thread-id' so that the host hold table works */
431 MUTEX_ENTER(&rx_stats_mutex); /* protects rxi_pthread_hinum */
433 pthread_setspecific(rx_thread_id_key, (void *)rxi_pthread_hinum);
434 MUTEX_EXIT(&rx_stats_mutex);
436 ("Set thread id %d for '%s'\n",
437 pthread_getspecific(rx_thread_id_key), s));
441 /* This LWP does things roughly every 5 minutes */
443 FiveMinuteCheckLWP(void *unused)
448 ViceLog(1, ("Starting five minute check process\n"));
449 setThreadId("FiveMinuteCheckLWP");
451 #ifdef AFS_DEMAND_ATTACH_FS
453 while (fs_state.mode == FS_MODE_NORMAL) {
454 fs_state.FiveMinuteLWP_tranquil = 1;
460 #ifdef AFS_PTHREAD_ENV
462 #else /* AFS_PTHREAD_ENV */
463 IOMGR_Sleep(fiveminutes);
464 #endif /* AFS_PTHREAD_ENV */
466 #ifdef AFS_DEMAND_ATTACH_FS
468 if (fs_state.mode != FS_MODE_NORMAL) {
471 fs_state.FiveMinuteLWP_tranquil = 0;
475 /* close the log so it can be removed */
476 ReOpenLog(AFSDIR_SERVER_FILELOG_FILEPATH); /* don't trunc, just append */
477 ViceLog(2, ("Cleaning up timed out callbacks\n"));
478 if (CleanupTimedOutCallBacks())
479 ViceLog(5, ("Timed out callbacks deleted\n"));
480 ViceLog(2, ("Set disk usage statistics\n"));
482 if (FS_registered == 1)
484 /* Force wakeup in case we missed something; pthreads does timedwait */
485 #ifndef AFS_PTHREAD_ENV
486 LWP_NoYieldSignal(fsync_wait);
488 if (printBanner && (++msg & 1)) { /* Every 10 minutes */
489 time_t now = FT_ApproxTime();
490 if (console != NULL) {
491 #ifndef AFS_QUIETFS_ENV
492 fprintf(console, "File server is running at %s\r",
493 afs_ctime(&now, tbuffer, sizeof(tbuffer)));
494 #endif /* AFS_QUIETFS_ENV */
496 ("File server is running at %s\n",
497 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
500 #ifdef AFS_DEMAND_ATTACH_FS
504 #ifdef AFS_DEMAND_ATTACH_FS
505 fs_state.FiveMinuteLWP_tranquil = 1;
507 assert(pthread_cond_broadcast(&fs_state.worker_done_cv)==0);
512 } /*FiveMinuteCheckLWP */
515 /* This LWP does host checks every 5 minutes: it should not be used for
516 * other 5 minute activities because it may be delayed by timeouts when
517 * it probes the workstations
521 HostCheckLWP(void *unused)
523 ViceLog(1, ("Starting Host check process\n"));
524 setThreadId("HostCheckLWP");
525 #ifdef AFS_DEMAND_ATTACH_FS
527 while (fs_state.mode == FS_MODE_NORMAL) {
528 fs_state.HostCheckLWP_tranquil = 1;
534 #ifdef AFS_PTHREAD_ENV
536 #else /* AFS_PTHREAD_ENV */
537 IOMGR_Sleep(fiveminutes);
538 #endif /* AFS_PTHREAD_ENV */
540 #ifdef AFS_DEMAND_ATTACH_FS
542 if (fs_state.mode != FS_MODE_NORMAL) {
545 fs_state.HostCheckLWP_tranquil = 0;
549 ViceLog(2, ("Checking for dead venii & clients\n"));
552 #ifdef AFS_DEMAND_ATTACH_FS
556 #ifdef AFS_DEMAND_ATTACH_FS
557 fs_state.HostCheckLWP_tranquil = 1;
559 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
571 FsyncCheckLWP(void *unused)
574 #ifdef AFS_PTHREAD_ENV
575 struct timespec fsync_next;
577 ViceLog(1, ("Starting fsync check process\n"));
579 setThreadId("FsyncCheckLWP");
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 */
633 /*------------------------------------------------------------------------
634 * PRIVATE ClearXStatValues
637 * Initialize all of the values collected via the xstat
647 * Must be called during File Server initialization.
651 *------------------------------------------------------------------------*/
655 { /*ClearXStatValues */
657 struct fs_stats_opTimingData *opTimeP; /*Ptr to timing struct */
658 struct fs_stats_xferData *opXferP; /*Ptr to xfer struct */
659 int i; /*Loop counter */
662 * Zero all xstat-related structures.
664 memset((char *)(&afs_perfstats), 0, sizeof(struct afs_PerfStats));
665 #if FS_STATS_DETAILED
666 memset((char *)(&afs_FullPerfStats), 0,
667 sizeof(struct fs_stats_FullPerfStats));
670 * That's not enough. We have to set reasonable minima for
671 * time and xfer values in the detailed stats.
673 opTimeP = &(afs_FullPerfStats.det.rpcOpTimes[0]);
674 for (i = 0; i < FS_STATS_NUM_RPC_OPS; i++, opTimeP++)
675 opTimeP->minTime.tv_sec = 999999;
677 opXferP = &(afs_FullPerfStats.det.xferOpTimes[0]);
678 for (i = 0; i < FS_STATS_NUM_XFER_OPS; i++, opXferP++) {
679 opXferP->minTime.tv_sec = 999999;
680 opXferP->minBytes = 999999999;
684 * There's more. We have to set our unique system identifier, as
685 * declared in param.h. If such a thing is not defined, we bitch
686 * and declare ourselves to be an unknown system type.
689 afs_perfstats.sysname_ID = SYS_NAME_ID;
692 ViceLog(0, ("Sys name ID constant not defined in param.h!!\n"));
693 ViceLog(0, ("[Choosing ``undefined'' sys name ID.\n"));
695 afs_perfstats.sysname_ID = SYS_NAME_ID_UNDEFINED;
696 #endif /* SYS_NAME_ID */
699 } /*ClearXStatValues */
705 int dirbuff, dircall, dirio;
707 int workstations, activeworkstations, delworkstations;
711 TM_GetTimeOfDay(&tpl, 0);
714 ("Vice was last started at %s\n",
715 afs_ctime(&StartTime, tbuffer, sizeof(tbuffer))));
717 #ifdef AFS_DEMAND_ATTACH_FS
718 /* XXX perhaps set extended stats verbosity flags
719 * based upon LogLevel ?? */
720 VPrintExtendedCacheStats(VOL_STATS_PER_CHAIN2);
724 DStat(&dirbuff, &dircall, &dirio);
726 ("With %d directory buffers; %d reads resulted in %d read I/Os\n",
727 dirbuff, dircall, dirio));
728 rx_PrintStats(stderr);
730 PrintCallBackStats();
732 processSize = -1; /* TODO: */
734 processSize = (int)((long)sbrk(0) >> 10);
737 ("There are %d connections, process size %d\n",
738 CurrentConnections, processSize));
739 h_GetWorkStats(&workstations, &activeworkstations, &delworkstations,
740 tpl.tv_sec - 15 * 60);
742 ("There are %d workstations, %d are active (req in < 15 mins), %d marked \"down\"\n",
743 workstations, activeworkstations, delworkstations));
751 CheckSignal(void *unused)
753 if (FS_registered > 0) {
755 * We have proper ip addresses; tell the vlserver what we got; the following
756 * routine will do the proper reporting for us
769 ShutDownAndCore(int dopanic)
771 time_t now = time(0);
774 /* do not allows new reqests to be served from now on, all new requests
775 * are returned with an error code of RX_RESTARTING ( transient failure ) */
776 rx_SetRxTranquil(); /* dhruba */
778 #ifdef AFS_DEMAND_ATTACH_FS
780 fs_state.mode = FS_MODE_SHUTDOWN;
785 ("Shutting down file server at %s",
786 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
788 ViceLog(0, ("ABNORMAL SHUTDOWN, see core file.\n"));
789 #ifndef AFS_QUIETFS_ENV
790 if (console != NULL) {
791 fprintf(console, "File server restart/shutdown received at %s\r",
792 afs_ctime(&now, tbuffer, sizeof(tbuffer)));
799 /* shut down volume package */
802 #ifdef AFS_DEMAND_ATTACH_FS
803 if (fs_state.options.fs_state_save) {
806 * save fileserver state to disk */
808 /* make sure background threads have finished all of their asynchronous
809 * work on host and callback structures */
811 while (!fs_state.FiveMinuteLWP_tranquil ||
812 !fs_state.HostCheckLWP_tranquil ||
813 !fs_state.FsyncCheckLWP_tranquil) {
816 ViceLog(0, ("waiting for background host/callback threads to quiesce before saving fileserver state...\n"));
817 assert(pthread_cond_wait(&fs_state.worker_done_cv, &fileproc_glock_mutex) == 0);
822 /* ok. it should now be fairly safe. let's do the state dump */
825 #endif /* AFS_DEMAND_ATTACH_FS */
828 rx_PrintStats(debugFile);
831 if (console != NULL) {
834 #ifndef AFS_QUIETFS_ENV
835 fprintf(console, "File server has terminated abnormally at %s\r",
836 afs_ctime(&now, tbuffer, sizeof(tbuffer)));
839 ("File server has terminated abnormally at %s\n",
840 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
842 #ifndef AFS_QUIETFS_ENV
843 fprintf(console, "File server has terminated normally at %s\r",
844 afs_ctime(&now, tbuffer, sizeof(tbuffer)));
847 ("File server has terminated normally at %s\n",
848 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
859 ShutDown(void *unused)
860 { /* backward compatibility */
861 ShutDownAndCore(DONTPANIC);
871 /* default supports help flag */
873 strcpy(buffer, "Usage: fileserver ");
874 strcpy(buffer, "[-auditlog <log path>] ");
875 strcat(buffer, "[-d <debug level>] ");
876 strcat(buffer, "[-p <number of processes>] ");
877 strcat(buffer, "[-spare <number of spare blocks>] ");
878 strcat(buffer, "[-pctspare <percentage spare>] ");
879 strcat(buffer, "[-b <buffers>] ");
880 strcat(buffer, "[-l <large vnodes>] ");
881 strcat(buffer, "[-s <small vnodes>] ");
882 strcat(buffer, "[-vc <volume cachesize>] ");
883 strcat(buffer, "[-w <call back wait interval>] ");
884 strcat(buffer, "[-cb <number of call backs>] ");
885 strcat(buffer, "[-banner (print banner every 10 minutes)] ");
886 strcat(buffer, "[-novbc (whole volume cbs disabled)] ");
887 strcat(buffer, "[-implicit <admin mode bits: rlidwka>] ");
888 strcat(buffer, "[-readonly (read-only file server)] ");
890 "[-hr <number of hours between refreshing the host cps>] ");
891 strcat(buffer, "[-busyat <redirect clients when queue > n>] ");
892 strcat(buffer, "[-nobusy <no VBUSY before a volume is attached>] ");
893 strcat(buffer, "[-rxpck <number of rx extra packets>] ");
894 strcat(buffer, "[-rxdbg (enable rx debugging)] ");
895 strcat(buffer, "[-rxdbge (enable rxevent debugging)] ");
896 strcat(buffer, "[-rxmaxmtu <bytes>] ");
897 strcat(buffer, "[-rxbind (bind the Rx socket to one address)] ");
898 strcat(buffer, "[-allow-dotted-principals (disable the rxkad principal name dot check)] ");
899 #ifdef AFS_DEMAND_ATTACH_FS
900 strcat(buffer, "[-fs-state-dont-save (disable state save during shutdown)] ");
901 strcat(buffer, "[-fs-state-dont-restore (disable state restore during startup)] ");
902 strcat(buffer, "[-fs-state-verify <none|save|restore|both> (default is both)] ");
903 strcat(buffer, "[-vattachpar <max number of volume attach/shutdown threads> (default is 1)] ");
904 strcat(buffer, "[-vhashsize <log(2) of number of volume hash buckets> (default is 8)] ");
905 strcat(buffer, "[-vlrudisable (disable VLRU functionality)] ");
906 strcat(buffer, "[-vlruthresh <minutes before unused volumes become eligible for soft detach> (default is 2 hours)] ");
907 strcat(buffer, "[-vlruinterval <seconds between VLRU scans> (default is 2 minutes)] ");
908 strcat(buffer, "[-vlrumax <max volumes to soft detach in one VLRU scan> (default is 8)] ");
909 #elif AFS_PTHREAD_ENV
910 strcat(buffer, "[-vattachpar <number of volume attach threads> (default is 1)] ");
913 strcat(buffer, "[-m <min percentage spare in partition>] ");
915 #if defined(AFS_SGI_ENV)
916 strcat(buffer, "[-lock (keep fileserver from swapping)] ");
918 strcat(buffer, "[-L (large server conf)] ");
919 strcat(buffer, "[-S (small server conf)] ");
920 strcat(buffer, "[-k <stack size>] ");
921 strcat(buffer, "[-realm <Kerberos realm name>] ");
922 strcat(buffer, "[-udpsize <size of socket buffer in bytes>] ");
923 strcat(buffer, "[-sendsize <size of send buffer in bytes>] ");
924 strcat(buffer, "[-abortthreshold <abort threshold>] ");
925 strcat(buffer, "[-nojumbo (disable jumbogram network packets - deprecated)] ");
926 strcat(buffer, "[-jumbo (enable jumbogram network packets)] ");
927 /* strcat(buffer, "[-enable_peer_stats] "); */
928 /* strcat(buffer, "[-enable_process_stats] "); */
929 strcat(buffer, "[-help]\n");
931 ViceLog(0, ("%s", buffer));
934 printf("%s", buffer);
941 ParseRights(char *arights)
947 if (!arights || !strcmp(arights, "")) {
948 printf("Missing list of mode bits on -implicit option\n");
951 if (!strcmp(arights, "none"))
953 else if (!strcmp(arights, "read"))
954 mode = PRSFS_READ | PRSFS_LOOKUP;
955 else if (!strcmp(arights, "write"))
957 PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
958 PRSFS_WRITE | PRSFS_LOCK;
959 else if (!strcmp(arights, "all"))
961 PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
962 PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER;
964 len = strlen(arights);
965 for (i = 0; i < len; i++) {
970 mode |= PRSFS_LOOKUP;
972 mode |= PRSFS_INSERT;
974 mode |= PRSFS_DELETE;
980 mode |= PRSFS_ADMINISTER;
998 printf("Illegal -implicit rights character '%c'.\n", tc);
1007 * Limit MAX_FILESERVER_THREAD by the system limit on the number of
1008 * pthreads (sysconf(_SC_THREAD_THREADS_MAX)), if applicable and
1011 * AIX: sysconf() limit is real
1012 * HP-UX: sysconf() limit is real
1013 * IRIX: sysconf() limit is apparently NOT real -- too small
1014 * DUX: sysconf() limit is apparently NOT real -- too big
1015 * Linux: sysconf() limit is apparently NOT real -- too big
1016 * Solaris: no sysconf() limit
1019 max_fileserver_thread(void)
1021 #if defined(AFS_PTHREAD_ENV)
1022 #if defined(AFS_AIX_ENV) || defined(AFS_HPUX_ENV)
1025 ans = sysconf(_SC_THREAD_THREADS_MAX);
1026 if (0 < ans && ans < MAX_FILESERVER_THREAD)
1029 #endif /* defined(AFS_PTHREAD_ENV) */
1030 return MAX_FILESERVER_THREAD;
1034 ParseArgs(int argc, char *argv[])
1036 int SawL = 0, SawS = 0, SawVC = 0;
1037 int Sawrxpck = 0, Sawsmall = 0, Sawlarge = 0, Sawcbs = 0, Sawlwps =
1041 int bufSize = 0; /* temp variable to read in udp socket buf size */
1043 for (i = 1; i < argc; i++) {
1044 if (!strcmp(argv[i], "-d")) {
1045 if ((i + 1) >= argc) {
1046 fprintf(stderr, "missing argument for -d\n");
1049 debuglevel = atoi(argv[++i]);
1050 LogLevel = debuglevel;
1051 } else if (!strcmp(argv[i], "-banner")) {
1053 } else if (!strcmp(argv[i], "-implicit")) {
1054 if ((i + 1) >= argc) {
1055 fprintf(stderr, "missing argument for -implicit\n");
1058 implicitAdminRights = ParseRights(argv[++i]);
1059 if (implicitAdminRights < 0)
1060 return implicitAdminRights;
1061 } else if (!strcmp(argv[i], "-readonly")) {
1063 } else if (!strcmp(argv[i], "-L")) {
1065 } else if (!strcmp(argv[i], "-S")) {
1067 } else if (!strcmp(argv[i], "-p")) {
1069 max_fileserver_thread() - FILESERVER_HELPER_THREADS;
1071 if ((i + 1) >= argc) {
1072 fprintf(stderr, "missing argument for -p\n");
1075 lwps = atoi(argv[++i]);
1076 if (lwps > lwps_max)
1080 } else if (!strcmp(argv[i], "-b")) {
1082 if ((i + 1) >= argc) {
1083 fprintf(stderr, "missing argument for -b\n");
1086 buffs = atoi(argv[++i]);
1087 } else if (!strcmp(argv[i], "-l")) {
1089 if ((i + 1) >= argc) {
1090 fprintf(stderr, "missing argument for -l\n");
1093 large = atoi(argv[++i]);
1094 } else if (!strcmp(argv[i], "-vc")) {
1096 if ((i + 1) >= argc) {
1097 fprintf(stderr, "missing argument for -vc\n");
1100 volcache = atoi(argv[++i]);
1101 } else if (!strcmp(argv[i], "-novbc")) {
1103 } else if (!strcmp(argv[i], "-rxpck")) {
1105 if ((i + 1) >= argc) {
1106 fprintf(stderr, "missing argument for -rxpck\n");
1109 rxpackets = atoi(argv[++i]);
1110 #ifdef AFS_PTHREAD_ENV
1111 } else if (!strcmp(argv[i], "-vattachpar")) {
1112 if ((i + 1) >= argc) {
1113 fprintf(stderr, "missing argument for %s\n", argv[i]);
1116 vol_attach_threads = atoi(argv[++i]);
1117 #endif /* AFS_PTHREAD_ENV */
1118 #ifdef AFS_DEMAND_ATTACH_FS
1119 } else if (!strcmp(argv[i], "-fs-state-dont-save")) {
1120 fs_state.options.fs_state_save = 0;
1121 } else if (!strcmp(argv[i], "-fs-state-dont-restore")) {
1122 fs_state.options.fs_state_restore = 0;
1123 } else if (!strcmp(argv[i], "-fs-state-verify")) {
1124 if ((i + 1) >= argc) {
1125 fprintf(stderr, "missing argument for %s\n", argv[i]);
1129 if (!strcmp(argv[i], "none")) {
1130 fs_state.options.fs_state_verify_before_save = 0;
1131 fs_state.options.fs_state_verify_after_restore = 0;
1132 } else if (!strcmp(argv[i], "save")) {
1133 fs_state.options.fs_state_verify_after_restore = 0;
1134 } else if (!strcmp(argv[i], "restore")) {
1135 fs_state.options.fs_state_verify_before_save = 0;
1136 } else if (!strcmp(argv[i], "both")) {
1139 fprintf(stderr, "invalid argument for %s\n", argv[i-1]);
1142 } else if (!strcmp(argv[i], "-vhashsize")) {
1143 if ((i + 1) >= argc) {
1144 fprintf(stderr, "missing argument for %s\n", argv[i]);
1147 VSetVolHashSize(atoi(argv[++i]));
1148 } else if (!strcmp(argv[i], "-vlrudisable")) {
1149 VLRU_SetOptions(VLRU_SET_ENABLED, 0);
1150 } else if (!strcmp(argv[i], "-vlruthresh")) {
1151 if ((i + 1) >= argc) {
1152 fprintf(stderr, "missing argument for %s\n", argv[i]);
1155 VLRU_SetOptions(VLRU_SET_THRESH, 60*atoi(argv[++i]));
1156 } else if (!strcmp(argv[i], "-vlruinterval")) {
1157 if ((i + 1) >= argc) {
1158 fprintf(stderr, "missing argument for %s\n", argv[i]);
1161 VLRU_SetOptions(VLRU_SET_INTERVAL, atoi(argv[++i]));
1162 } else if (!strcmp(argv[i], "-vlrumax")) {
1163 if ((i + 1) >= argc) {
1164 fprintf(stderr, "missing argument for %s\n", argv[i]);
1167 VLRU_SetOptions(VLRU_SET_MAX, atoi(argv[++i]));
1168 #endif /* AFS_DEMAND_ATTACH_FS */
1169 } else if (!strcmp(argv[i], "-s")) {
1171 if ((i + 1) >= argc) {
1172 fprintf(stderr, "missing argument for -s\n");
1175 nSmallVns = atoi(argv[++i]);
1176 } else if (!strcmp(argv[i], "-abortthreshold")) {
1177 if ((i + 1) >= argc) {
1178 fprintf(stderr, "missing argument for -abortthreshold\n");
1181 abort_threshold = atoi(argv[++i]);
1182 } else if (!strcmp(argv[i], "-k")) {
1183 if ((i + 1) >= argc) {
1184 fprintf(stderr, "missing argument for -k\n");
1187 stack = atoi(argv[++i]);
1189 #if defined(AFS_SGI_ENV)
1190 else if (!strcmp(argv[i], "-lock")) {
1194 else if (!strcmp(argv[i], "-spare")) {
1195 if ((i + 1) >= argc) {
1196 fprintf(stderr, "missing argument for -spare\n");
1199 BlocksSpare = atoi(argv[++i]);
1201 } else if (!strcmp(argv[i], "-pctspare")) {
1202 if ((i + 1) >= argc) {
1203 fprintf(stderr, "missing argument for -pctspare\n");
1206 PctSpare = atoi(argv[++i]);
1207 BlocksSpare = 0; /* has non-zero default */
1209 } else if (!strcmp(argv[i], "-w")) {
1210 if ((i + 1) >= argc) {
1211 fprintf(stderr, "missing argument for -w\n");
1214 fiveminutes = atoi(argv[++i]);
1215 } else if (!strcmp(argv[i], "-hr")) {
1217 if ((i + 1) >= argc) {
1218 fprintf(stderr, "missing argument for -hr\n");
1221 hr = atoi(argv[++i]);
1222 if ((hr < 1) || (hr > 36)) {
1224 ("host acl refresh interval of %d hours is invalid; hours must be between 1 and 36\n\n",
1228 hostaclRefresh = hr * 60 * 60;
1229 } else if (!strcmp(argv[i], "-rxdbg"))
1231 else if (!strcmp(argv[i], "-rxdbge"))
1233 else if (!strcmp(argv[i], "-cb")) {
1235 if ((i + 1) >= argc) {
1236 fprintf(stderr, "missing argument for -cb\n");
1239 numberofcbs = atoi(argv[++i]);
1240 if ((numberofcbs < 10000) || (numberofcbs > 2147483647)) {
1242 ("number of cbs %d invalid; must be between 10000 and 2147483647\n",
1246 } else if (!strcmp(argv[i], "-busyat")) {
1248 if ((i + 1) >= argc) {
1249 fprintf(stderr, "missing argument for -busyat\n");
1252 busy_threshold = atoi(argv[++i]);
1253 if (busy_threshold < 10) {
1255 ("Busy threshold %d is too low, will compute default.\n",
1259 } else if (!strcmp(argv[i], "-nobusy"))
1261 #ifdef AFS_AIX32_ENV
1262 else if (!strcmp(argv[i], "-m")) {
1263 extern int aixlow_water;
1264 if ((i + 1) >= argc) {
1265 fprintf(stderr, "missing argument for -m\n");
1268 aixlow_water = atoi(argv[++i]);
1269 if ((aixlow_water < 0) || (aixlow_water > 30)) {
1270 printf("space reserved %d% invalid; must be between 0-30%\n",
1276 else if (!strcmp(argv[i], "-nojumbo")) {
1278 } else if (!strcmp(argv[i], "-jumbo")) {
1280 } else if (!strcmp(argv[i], "-rxbind")) {
1282 } else if (!strcmp(argv[i], "-allow-dotted-principals")) {
1283 rxkadDisableDotCheck = 1;
1284 } else if (!strcmp(argv[i], "-rxmaxmtu")) {
1285 if ((i + 1) >= argc) {
1286 fprintf(stderr, "missing argument for -rxmaxmtu\n");
1289 rxMaxMTU = atoi(argv[++i]);
1290 if ((rxMaxMTU < RX_MIN_PACKET_SIZE) ||
1291 (rxMaxMTU > RX_MAX_PACKET_DATA_SIZE)) {
1292 printf("rxMaxMTU %d%% invalid; must be between %d-%d\n",
1293 rxMaxMTU, RX_MIN_PACKET_SIZE,
1294 RX_MAX_PACKET_DATA_SIZE);
1297 } else if (!strcmp(argv[i], "-realm")) {
1298 extern char local_realms[AFS_NUM_LREALMS][AFS_REALM_SZ];
1299 extern int num_lrealms;
1300 if ((i + 1) >= argc) {
1301 fprintf(stderr, "missing argument for -realm\n");
1304 if (strlen(argv[++i]) >= AFS_REALM_SZ) {
1306 ("-realm argument must contain fewer than %d characters.\n",
1310 if (num_lrealms == -1)
1312 if (num_lrealms >= AFS_NUM_LREALMS) {
1314 ("a maximum of %d -realm arguments can be specified.\n",
1318 strncpy(local_realms[num_lrealms++], argv[i], AFS_REALM_SZ);
1319 } else if (!strcmp(argv[i], "-udpsize")) {
1320 if ((i + 1) >= argc) {
1321 printf("You have to specify -udpsize <integer value>\n");
1324 bufSize = atoi(argv[++i]);
1325 if (bufSize < rx_GetMinUdpBufSize())
1327 ("Warning:udpsize %d is less than minimum %d; ignoring\n",
1328 bufSize, rx_GetMinUdpBufSize());
1330 udpBufSize = bufSize;
1331 } else if (!strcmp(argv[i], "-sendsize")) {
1332 if ((i + 1) >= argc) {
1333 printf("You have to specify -sendsize <integer value>\n");
1336 bufSize = atoi(argv[++i]);
1337 if (bufSize < 16384)
1339 ("Warning:sendsize %d is less than minimum %d; ignoring\n",
1342 sendBufSize = bufSize;
1343 } else if (!strcmp(argv[i], "-enable_peer_stats")) {
1344 rx_enablePeerRPCStats();
1345 } else if (!strcmp(argv[i], "-enable_process_stats")) {
1346 rx_enableProcessRPCStats();
1348 else if (strcmp(argv[i], "-auditlog") == 0) {
1351 char oldName[MAXPATHLEN];
1352 char *fileName = argv[++i];
1354 #ifndef AFS_NT40_ENV
1355 struct stat statbuf;
1357 if ((lstat(fileName, &statbuf) == 0)
1358 && (S_ISFIFO(statbuf.st_mode))) {
1359 flags = O_WRONLY | O_NONBLOCK;
1363 strcpy(oldName, fileName);
1364 strcat(oldName, ".old");
1365 renamefile(fileName, oldName);
1366 flags = O_WRONLY | O_TRUNC | O_CREAT;
1368 tempfd = open(fileName, flags, 0666);
1370 auditout = fdopen(tempfd, "a");
1372 osi_audit_file(auditout);
1374 printf("Warning: auditlog %s not writable, ignored.\n", fileName);
1376 printf("Warning: auditlog %s not writable, ignored.\n", fileName);
1378 #ifndef AFS_NT40_ENV
1379 else if (strcmp(argv[i], "-syslog") == 0) {
1380 /* set syslog logging flag */
1381 serverLogSyslog = 1;
1382 } else if (strncmp(argv[i], "-syslog=", 8) == 0) {
1383 serverLogSyslog = 1;
1384 serverLogSyslogFacility = atoi(argv[i] + 8);
1387 else if (strcmp(argv[i], "-mrafslogs") == 0) {
1388 /* set syslog logging flag */
1391 else if (strcmp(argv[i], "-saneacls") == 0) {
1399 printf("Only one of -L, or -S must be specified\n");
1410 numberofcbs = 20000;
1426 numberofcbs = 64000;
1435 busy_threshold = 3 * rxpackets / 2;
1445 NewParms(int initializing)
1447 static struct afs_stat sbuf;
1450 char *argv[MAXPARMS];
1453 if (!(afs_stat("/vice/file/parms", &sbuf))) {
1454 parms = (char *)malloc(sbuf.st_size);
1457 fd = afs_open("parms", O_RDONLY, 0666);
1459 ViceLog(0, ("Open for parms failed with errno = %d\n", errno));
1463 i = read(fd, parms, sbuf.st_size);
1465 if (i != sbuf.st_size) {
1467 ViceLog(0, ("Read on parms failed with errno = %d\n", errno));
1470 ("Read on parms failed; expected %d bytes but read %d\n",
1477 for (i = 0; i < MAXPARMS; argv[i++] = 0);
1479 for (argc = i = 0; i < sbuf.st_size; i++) {
1480 if ((*(parms + i) != ' ') && (*(parms + i) != '\n')) {
1481 if (argv[argc] == 0)
1482 argv[argc] = (parms + i);
1484 *(parms + i) = '\0';
1485 if (argv[argc] != 0) {
1486 if (++argc == MAXPARMS)
1489 while ((*(parms + i + 1) == ' ')
1490 || (*(parms + i + 1) == '\n'))
1494 if (ParseArgs(argc, argv) == 0) {
1495 ViceLog(0, ("Change parameters to:"));
1497 ViceLog(0, ("Invalid parameter in:"));
1499 for (i = 0; i < argc; i++) {
1500 ViceLog(0, (" %s", argv[i]));
1504 } else if (!initializing)
1506 ("Received request to change parms but no parms file exists\n"));
1511 /* Miscellaneous routines */
1515 ViceLog(0, ("%s\n", msg));
1527 * If this fails, it's because something major is wrong, and is not
1528 * likely to be time dependent.
1530 code = pr_Initialize(2, AFSDIR_SERVER_ETC_DIRPATH, 0);
1533 ("Couldn't initialize protection library; code=%d.\n", code));
1537 #ifdef AFS_PTHREAD_ENV
1538 assert(pthread_key_create(&viced_uclient_key, NULL) == 0);
1541 SystemId = SYSADMINID;
1542 SystemAnyUser = ANYUSERID;
1543 SystemAnyUserCPS.prlist_len = 0;
1544 SystemAnyUserCPS.prlist_val = NULL;
1545 AnonCPS.prlist_len = 0;
1546 AnonCPS.prlist_val = NULL;
1548 code = pr_GetCPS(SystemAnyUser, &SystemAnyUserCPS);
1551 ("Couldn't get CPS for AnyUser, will try again in 30 seconds; code=%d.\n",
1555 code = pr_GetCPS(ANONYMOUSID, &AnonCPS);
1558 ("Couldn't get Anonymous CPS, exiting; code=%d.\n",
1562 AnonymousID = ANONYMOUSID;
1565 #ifdef AFS_PTHREAD_ENV
1567 #else /* AFS_PTHREAD_ENV */
1569 #endif /* AFS_PTHREAD_ENV */
1573 struct rx_connection *serverconns[MAXSERVERS];
1574 struct ubik_client *cstruct;
1577 vl_Initialize(const char *confDir)
1579 afs_int32 code, scIndex = 0, i;
1580 struct afsconf_dir *tdir;
1581 struct rx_securityClass *sc;
1582 struct afsconf_cell info;
1584 tdir = afsconf_Open(confDir);
1587 ("Could not open configuration directory (%s).\n", confDir));
1590 code = afsconf_ClientAuth(tdir, &sc, &scIndex);
1592 ViceLog(0, ("Could not get security object for localAuth\n"));
1595 code = afsconf_GetCellInfo(tdir, NULL, AFSCONF_VLDBSERVICE, &info);
1596 if (info.numServers > MAXSERVERS) {
1598 ("vl_Initialize: info.numServers=%d (> MAXSERVERS=%d)\n",
1599 info.numServers, MAXSERVERS));
1602 for (i = 0; i < info.numServers; i++)
1604 rx_NewConnection(info.hostAddr[i].sin_addr.s_addr,
1605 info.hostAddr[i].sin_port, USER_SERVICE_ID, sc,
1607 code = ubik_ClientInit(serverconns, &cstruct);
1608 afsconf_Close(tdir);
1610 ViceLog(0, ("vl_Initialize: ubik client init failed.\n"));
1616 #define SYSIDMAGIC 0x88aabbcc
1617 #define SYSIDVERSION 1
1622 afs_int32 fd, nentries, i;
1623 struct versionStamp vsn;
1624 struct afs_stat status;
1627 if ((afs_stat(AFSDIR_SERVER_SYSID_FILEPATH, &status))
1628 || (status.st_size <= 0)) {
1629 ViceLog(0, ("%s: doesn't exist\n", AFSDIR_SERVER_SYSID_FILEPATH));
1632 if (!(fd = afs_open(AFSDIR_SERVER_SYSID_FILEPATH, O_RDONLY, 0))) {
1634 ("%s: can't open (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1638 if ((i = read(fd, (char *)&vsn, sizeof(vsn))) != sizeof(vsn)) {
1640 ("%s: Read failed (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1644 if (vsn.magic != SYSIDMAGIC) {
1646 ("%s: wrong magic %x (we support %x)\n",
1647 AFSDIR_SERVER_SYSID_FILEPATH, vsn.magic, SYSIDMAGIC));
1650 if (vsn.version != SYSIDVERSION) {
1652 ("%s: wrong version %d (we support %d)\n",
1653 AFSDIR_SERVER_SYSID_FILEPATH, vsn.version, SYSIDVERSION));
1657 read(fd, (char *)&uuid,
1658 sizeof(struct afsUUID))) != sizeof(struct afsUUID)) {
1660 ("%s: read of uuid failed (%d)\n",
1661 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1664 afs_ntohuuid(&uuid);
1667 read(fd, (char *)&nentries,
1668 sizeof(afs_int32))) != sizeof(afs_int32)) {
1670 ("%s: Read of entries failed (%d)\n",
1671 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1674 if (nentries <= 0 || nentries > ADDRSPERSITE) {
1676 ("%s: invalid num of interfaces: %d\n",
1677 AFSDIR_SERVER_SYSID_FILEPATH, nentries));
1680 if (FS_HostAddr_cnt == 0) {
1681 FS_HostAddr_cnt = nentries;
1682 for (i = 0; i < nentries; i++) {
1683 if (read(fd, (char *)&FS_HostAddrs[i], sizeof(afs_int32)) !=
1684 sizeof(afs_int32)) {
1686 ("%s: Read of addresses failed (%d)\n",
1687 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1688 FS_HostAddr_cnt = 0; /* reset it */
1694 ("%s: address list ignored (NetInfo/NetRestrict override)\n",
1695 AFSDIR_SERVER_SYSID_FILEPATH));
1705 struct versionStamp vsn;
1706 struct afs_stat status;
1709 if (!afs_stat(AFSDIR_SERVER_SYSID_FILEPATH, &status)) {
1711 * File exists; keep the old one around
1713 renamefile(AFSDIR_SERVER_SYSID_FILEPATH,
1714 AFSDIR_SERVER_OLDSYSID_FILEPATH);
1716 fd = afs_open(AFSDIR_SERVER_SYSID_FILEPATH, O_WRONLY | O_TRUNC | O_CREAT,
1720 ("%s: can't create (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1724 vsn.magic = SYSIDMAGIC;
1726 if ((i = write(fd, (char *)&vsn, sizeof(vsn))) != sizeof(vsn)) {
1728 ("%s: write failed (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1733 afs_htonuuid(&uuid);
1735 write(fd, (char *)&uuid,
1736 sizeof(struct afsUUID))) != sizeof(struct afsUUID)) {
1738 ("%s: write of uuid failed (%d)\n",
1739 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1743 write(fd, (char *)&FS_HostAddr_cnt,
1744 sizeof(afs_int32))) != sizeof(afs_int32)) {
1746 ("%s: write of # of entries failed (%d)\n",
1747 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1750 for (i = 0; i < FS_HostAddr_cnt; i++) {
1751 if (write(fd, (char *)&FS_HostAddrs[i], sizeof(afs_int32)) !=
1752 sizeof(afs_int32)) {
1754 ("%s: write of addresses failed (%d)\n",
1755 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1765 * This routine sets up the buffers for the VL_RegisterAddrs RPC. All addresses
1766 * in FS_HostAddrs[] are in NBO, while the RPC treats them as a "blob" of data
1767 * and so we need to convert each of them into HBO which is what the extra
1768 * array called FS_HostAddrs_HBO is used here.
1775 extern int VL_RegisterAddrs();
1776 afs_uint32 FS_HostAddrs_HBO[ADDRSPERSITE];
1779 for (i = 0; i < FS_HostAddr_cnt; i++)
1780 FS_HostAddrs_HBO[i] = ntohl(FS_HostAddrs[i]);
1781 addrs.bulkaddrs_len = FS_HostAddr_cnt;
1782 addrs.bulkaddrs_val = (afs_uint32 *) FS_HostAddrs_HBO;
1783 code = ubik_VL_RegisterAddrs(cstruct, 0, &FS_HostUUID, 0, &addrs);
1785 if (code == VL_MULTIPADDR) {
1787 ("VL_RegisterAddrs rpc failed; The IP address exists on a different server; repair it\n"));
1789 ("VL_RegisterAddrs rpc failed; See VLLog for details\n"));
1791 } else if (code == RXGEN_OPCODE) {
1793 ("vlserver doesn't support VL_RegisterAddrs rpc; ignored\n"));
1794 FS_registered = 2; /* So we don't have to retry in the gc daemon */
1797 ("VL_RegisterAddrs rpc failed; will retry periodically (code=%d, err=%d)\n",
1801 FS_registered = 2; /* So we don't have to retry in the gc daemon */
1812 extern int rxi_numNetAddrs;
1813 extern afs_uint32 rxi_NetAddrs[];
1815 #ifndef AFS_NT40_ENV
1816 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH || AFSDIR_SERVER_NETINFO_FILEPATH) {
1818 * Find addresses we are supposed to register as per the netrestrict
1819 * and netinfo files (/usr/afs/local/NetInfo and
1820 * /usr/afs/local/NetRestict)
1823 afs_int32 code = parseNetFiles(FS_HostAddrs, NULL, NULL,
1824 ADDRSPERSITE, reason,
1825 AFSDIR_SERVER_NETINFO_FILEPATH,
1826 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
1828 ViceLog(0, ("Can't register any valid addresses: %s\n", reason));
1831 FS_HostAddr_cnt = (afs_uint32) code;
1835 FS_HostAddr_cnt = rx_getAllAddr(FS_HostAddrs, ADDRSPERSITE);
1838 if (FS_HostAddr_cnt == 1 && rxBind == 1)
1839 code = FS_HostAddrs[0];
1841 code = htonl(INADDR_ANY);
1851 * If this fails, it's because something major is wrong, and is not
1852 * likely to be time dependent.
1854 code = vl_Initialize(AFSDIR_SERVER_ETC_DIRPATH);
1857 ("Couldn't initialize protection library; code=%d.\n", code));
1861 /* Read or create the sysid file and register the fileserver's
1862 * IP addresses with the vlserver.
1864 code = ReadSysIdFile();
1866 /* Need to create the file */
1867 ViceLog(0, ("Creating new SysID file\n"));
1868 if ((code = afs_uuid_create(&FS_HostUUID))) {
1869 ViceLog(0, ("Failed to create new uuid: %d\n", code));
1873 /* A good sysid file exists; inform the vlserver. If any conflicts,
1874 * we always use the latest interface available as the real truth.
1877 code = Do_VLRegisterRPC();
1882 main(int argc, char *argv[])
1886 struct rx_securityClass *sc[4];
1887 struct rx_service *tservice;
1888 #ifdef AFS_PTHREAD_ENV
1889 pthread_t serverPid;
1890 pthread_attr_t tattr;
1891 #else /* AFS_PTHREAD_ENV */
1892 PROCESS parentPid, serverPid;
1893 #endif /* AFS_PTHREAD_ENV */
1895 int minVnodesRequired; /* min size of vnode cache */
1896 #ifndef AFS_NT40_ENV
1897 struct rlimit rlim; /* max number of open file descriptors */
1901 afs_uint32 rx_bindhost;
1903 #ifdef AFS_AIX32_ENV
1904 struct sigaction nsa;
1906 sigemptyset(&nsa.sa_mask);
1907 nsa.sa_handler = SIG_DFL;
1908 nsa.sa_flags = SA_FULLDUMP;
1909 sigaction(SIGABRT, &nsa, NULL);
1910 sigaction(SIGSEGV, &nsa, NULL);
1914 /* Initialize dirpaths */
1915 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
1917 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
1919 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
1923 #ifndef AFS_QUIETFS_ENV
1924 console = afs_fopen("/dev/console", "w");
1927 if (ParseArgs(argc, argv)) {
1931 #ifdef AFS_PTHREAD_ENV
1932 assert(pthread_mutex_init(&fileproc_glock_mutex, NULL) == 0);
1933 #endif /* AFS_PTHREAD_ENV */
1935 #ifdef AFS_SGI_VNODE_GLUE
1936 if (afs_init_kernel_config(-1) < 0) {
1938 ("Can't determine NUMA configuration, not starting fileserver.\n");
1942 confDir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
1944 fprintf(stderr, "Unable to open config directory %s\n",
1945 AFSDIR_SERVER_ETC_DIRPATH);
1951 /* Open FileLog on stdout, stderr, fd 1 and fd2 (for perror), sigh. */
1952 #ifndef AFS_NT40_ENV
1953 serverLogSyslogTag = "fileserver";
1955 OpenLog(AFSDIR_SERVER_FILELOG_FILEPATH);
1958 if (SawSpare && SawPctSpare) {
1959 ViceLog(0, ("Both -spare and -pctspare specified, exiting.\n"));
1962 #ifdef AFS_SGI_XFS_IOPS_ENV
1963 ViceLog(0, ("XFS/EFS File server starting\n"));
1965 ViceLog(0, ("File server starting\n"));
1968 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
1969 /* initialize the pthread soft signal handler thread */
1973 /* install signal handlers for controlling the fileserver process */
1974 ResetCheckSignal(); /* set CheckSignal_Signal() sig handler */
1975 ResetCheckDescriptors(); /* set CheckDescriptors_Signal() sig handler */
1977 #if defined(AFS_SGI_ENV)
1978 /* give this guy a non-degrading priority so help busy servers */
1979 schedctl(NDPRI, 0, NDPNORMMAX);
1983 #ifndef AFS_NT40_ENV
1984 nice(-5); /* TODO: */
1987 assert(DInit(buffs) == 0);
1990 if (afs_winsockInit() < 0) {
1991 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
1992 ViceLog(0, ("File server failed to intialize winsock.\n"));
1998 /* if we support more than 16 threads, then we better have the ability
1999 ** to keep open a large number of files simultaneously
2001 #if defined(AFS_AIX_ENV) && !defined(AFS_AIX42_ENV)
2002 curLimit = OPEN_MAX; /* for pre AIX 4.2 systems */
2003 #elif defined(AFS_NT40_ENV)
2004 curLimit = NT_OPEN_MAX; /* open file descriptor limit on NT */
2007 curLimit = 0; /* the number of open file descriptors */
2008 code = getrlimit(RLIMIT_NOFILE, &rlim);
2010 curLimit = rlim.rlim_cur;
2011 rlim.rlim_cur = rlim.rlim_max;
2012 code = setrlimit(RLIMIT_NOFILE, &rlim);
2014 curLimit = rlim.rlim_max;
2017 ViceLog(0, ("Failed to increase open file limit, using default\n"));
2019 #endif /* defined(AFS_AIX_ENV) && !defined(AFS_AIX42_ENV) */
2021 curLimit -= 32; /* leave a slack of 32 file descriptors */
2022 if (lwps > curLimit) {
2026 lwps = 16; /* default to a maximum of 16 threads */
2028 ("The system supports a max of %d open files and we are starting %d threads\n",
2031 #ifndef AFS_PTHREAD_ENV
2032 assert(LWP_InitializeProcessSupport(LWP_MAX_PRIORITY - 2, &parentPid) ==
2034 #endif /* !AFS_PTHREAD_ENV */
2036 /* Initialize volume support */
2038 V_BreakVolumeCallbacks = BreakVolumeCallBacksLater;
2041 #ifdef AFS_PTHREAD_ENV
2042 SetLogThreadNumProgram( threadNum );
2045 /* initialize libacl routines */
2046 acl_Initialize(ACL_VERSION);
2048 /* initialize RX support */
2049 #ifndef AFS_NT40_ENV
2050 rxi_syscallp = viced_syscall;
2052 rx_extraPackets = rxpackets;
2053 rx_extraQuota = 4; /* for outgoing prserver calls from R threads */
2054 rx_SetBusyThreshold(busy_threshold, VBUSY);
2055 rx_SetCallAbortThreshold(abort_threshold);
2056 rx_SetConnAbortThreshold(abort_threshold);
2057 stackSize = lwps * 4000;
2058 if (stackSize < 32000)
2060 else if (stackSize > 44000)
2062 #if defined(AFS_HPUX_ENV) || defined(AFS_SUN_ENV) || defined(AFS_SGI51_ENV)
2063 rx_SetStackSize(1, stackSize);
2066 rx_SetUdpBufSize(udpBufSize); /* set the UDP buffer size for receive */
2067 rx_bindhost = SetupVL();
2069 if (rx_InitHost(rx_bindhost, (int)htons(7000)) < 0) {
2070 ViceLog(0, ("Cannot initialize RX\n"));
2073 if (!rxJumbograms) {
2074 /* Don't send and don't allow 3.4 clients to send jumbograms. */
2077 if (rxMaxMTU != -1) {
2078 rx_SetMaxMTU(rxMaxMTU);
2081 rx_SetRxDeadTime(30);
2082 sc[0] = rxnull_NewServerSecurityObject();
2083 sc[1] = 0; /* rxvab_NewServerSecurityObject(key1, 0) */
2084 sc[2] = rxkad_NewServerSecurityObject(rxkad_clear, NULL, get_key, NULL);
2085 sc[3] = rxkad_NewServerSecurityObject(rxkad_crypt, NULL, get_key, NULL);
2086 tservice = rx_NewServiceHost(rx_bindhost, /* port */ 0, /* service id */
2087 1, /*service name */
2089 /* security classes */ sc,
2090 /* numb sec classes */
2091 4, RXAFS_ExecuteRequest);
2094 ("Failed to initialize RX, probably two servers running.\n"));
2097 if (rxkadDisableDotCheck) {
2098 rx_SetSecurityConfiguration(tservice, RXS_CONFIG_FLAGS,
2099 (void *)RXS_CONFIG_FLAGS_DISABLE_DOTCHECK);
2101 rx_SetMinProcs(tservice, 3);
2102 rx_SetMaxProcs(tservice, lwps);
2103 rx_SetCheckReach(tservice, 1);
2104 rx_SetServerIdleDeadErr(tservice, VNOSERVICE);
2107 rx_NewService(0, RX_STATS_SERVICE_ID, "rpcstats", sc, 4,
2108 RXSTATS_ExecuteRequest);
2110 ViceLog(0, ("Failed to initialize rpc stat service.\n"));
2113 rx_SetMinProcs(tservice, 2);
2114 rx_SetMaxProcs(tservice, 4);
2117 * Enable RX hot threads, which allows the listener thread to trade
2118 * places with an idle thread and moves the context switch from listener
2119 * to worker out of the critical path.
2121 rx_EnableHotThread();
2123 /* Some rx debugging */
2124 if (rxlog || eventlog) {
2125 debugFile = afs_fopen("rx_dbg", "w");
2127 rx_debugFile = debugFile;
2129 rxevent_debugFile = debugFile;
2132 init_sys_error_to_et(); /* Set up error table translation */
2133 h_InitHostPackage(); /* set up local cellname and realmname */
2134 InitCallBack(numberofcbs);
2139 ViceLog(0, ("Fatal error in library initialization, exiting!!\n"));
2145 ViceLog(0, ("Fatal error in protection initialization, exiting!!\n"));
2149 /* allow super users to manage RX statistics */
2150 rx_SetRxStatUserOk(fs_rxstat_userok);
2152 #ifdef AFS_PTHREAD_ENV
2153 assert(pthread_cond_init(&fsync_cond, NULL) == 0);
2154 assert(pthread_mutex_init(&fsync_glock_mutex, NULL) == 0);
2157 #if !defined(AFS_DEMAND_ATTACH_FS)
2159 * For DAFS, we do not start the Rx server threads until after
2160 * the volume package is initialized, and fileserver state is
2161 * restored. This is necessary in order to keep host and callback
2162 * package state pristine until we have a chance to restore state.
2164 * Furthermore, startup latency is much lower with dafs, so this
2165 * shouldn't pose a serious problem.
2167 rx_StartServer(0); /* now start handling requests */
2170 /* we ensure that there is enough space in the vnode buffer to satisfy
2171 ** requests from all concurrent threads.
2172 ** the maximum number of vnodes used by a single thread at any one time
2173 ** is three ( "link" uses three vnodes simultaneously, one vLarge and
2174 ** two vSmall for linking files and two vLarge and one vSmall for linking
2177 minVnodesRequired = 2 * lwps + 1;
2178 if (minVnodesRequired > nSmallVns) {
2179 nSmallVns = minVnodesRequired;
2181 ("Overriding -s command line parameter with %d\n",
2184 if (minVnodesRequired > large) {
2185 large = minVnodesRequired;
2186 ViceLog(0, ("Overriding -l command line parameter with %d\n", large));
2189 /* We now do this after getting the listener up and running, so that client
2190 * connections don't timeout (maybe) if a file server is restarted, since it
2191 * will be available "real soon now". Worry about whether we can satisfy the
2192 * calls in the volume package itself.
2194 if (VInitVolumePackage(fileServer, large, nSmallVns, 0, volcache)) {
2196 ("Shutting down: errors encountered initializing volume package\n"));
2201 #ifdef AFS_DEMAND_ATTACH_FS
2202 if (fs_state.options.fs_state_restore) {
2205 * restore fileserver state */
2208 rx_StartServer(0); /* now start handling requests */
2209 #endif /* AFS_DEMAND_ATTACH_FS */
2212 * We are done calling fopen/fdopen. It is safe to use a large
2213 * of the file descriptor cache.
2217 #ifdef AFS_PTHREAD_ENV
2218 ViceLog(5, ("Starting pthreads\n"));
2219 #ifdef AFS_DEMAND_ATTACH_FS
2222 assert(pthread_attr_init(&tattr) == 0);
2223 assert(pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED) == 0);
2225 assert(pthread_create
2226 (&serverPid, &tattr, FiveMinuteCheckLWP,
2227 &fiveminutes) == 0);
2228 assert(pthread_create
2229 (&serverPid, &tattr, HostCheckLWP, &fiveminutes) == 0);
2230 assert(pthread_create
2231 (&serverPid, &tattr, FsyncCheckLWP, &fiveminutes) == 0);
2232 #else /* AFS_PTHREAD_ENV */
2233 ViceLog(5, ("Starting LWP\n"));
2234 assert(LWP_CreateProcess
2235 (FiveMinuteCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
2236 (void *)&fiveminutes, "FiveMinuteChecks",
2237 &serverPid) == LWP_SUCCESS);
2239 assert(LWP_CreateProcess
2240 (HostCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
2241 (void *)&fiveminutes, "HostCheck", &serverPid) == LWP_SUCCESS);
2242 assert(LWP_CreateProcess
2243 (FsyncCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
2244 (void *)&fiveminutes, "FsyncCheck", &serverPid) == LWP_SUCCESS);
2245 #endif /* AFS_PTHREAD_ENV */
2247 TM_GetTimeOfDay(&tp, 0);
2249 #ifndef AFS_QUIETFS_ENV
2250 if (console != NULL) {
2251 time_t t = tp.tv_sec;
2252 fprintf(console, "File server has started at %s\r",
2253 afs_ctime(&t, tbuffer, sizeof(tbuffer)));
2258 * Figure out the FileServer's name and primary address.
2260 ViceLog(0, ("Getting FileServer name...\n"));
2261 code = gethostname(FS_HostName, 64);
2263 ViceLog(0, ("gethostname() failed\n"));
2265 ViceLog(0, ("FileServer host name is '%s'\n", FS_HostName));
2267 ViceLog(0, ("Getting FileServer address...\n"));
2268 he = gethostbyname(FS_HostName);
2270 ViceLog(0, ("Can't find address for FileServer '%s'\n", FS_HostName));
2273 memcpy(&FS_HostAddr_NBO, he->h_addr, 4);
2274 (void)afs_inet_ntoa_r(FS_HostAddr_NBO, hoststr);
2275 FS_HostAddr_HBO = ntohl(FS_HostAddr_NBO);
2277 ("FileServer %s has address %s (0x%x or 0x%x in host byte order)\n",
2278 FS_HostName, hoststr, FS_HostAddr_NBO, FS_HostAddr_HBO));
2281 /* Install handler to catch the shutdown signal;
2282 * bosserver assumes SIGQUIT shutdown
2284 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
2285 softsig_signal(SIGQUIT, ShutDown_Signal);
2287 (void)signal(SIGQUIT, ShutDown_Signal);
2292 ("File Server started %s",
2293 afs_ctime(&t, tbuffer, sizeof(tbuffer))));
2294 #if FS_STATS_DETAILED
2295 afs_FullPerfStats.det.epoch.tv_sec = StartTime = tp.tv_sec;
2297 #ifdef AFS_PTHREAD_ENV
2299 sleep(1000); /* long time */
2301 #else /* AFS_PTHREAD_ENV */
2302 assert(LWP_WaitProcess(&parentPid) == LWP_SUCCESS);
2303 #endif /* AFS_PTHREAD_ENV */