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>
29 #include <sys/types.h>
30 #include <afs/procmgmt.h> /* signal(), kill(), wait(), etc. */
36 #include <WINNT/afsevent.h>
39 #include <netinet/in.h>
41 #include <unistd.h> /* sysconf() */
45 #endif /* ITIMER_REAL */
46 #include <sys/resource.h>
47 #endif /* AFS_NT40_ENV */
52 #ifdef AFS_PTHREAD_ENV
54 #else /* AFS_PTHREAD_ENV */
55 #include <afs/assert.h>
56 #endif /* AFS_PTHREAD_ENV */
59 #include <afs/ptclient.h>
60 #include <afs/afsint.h>
61 #include <afs/vldbint.h>
62 #include <afs/errors.h>
63 #include <afs/ihandle.h>
64 #include <afs/vnode.h>
65 #include <afs/volume.h>
67 #include <afs/cellconfig.h>
69 #include <afs/prs_fs.h>
71 #include <rx/rxstat.h>
73 #include <afs/afs_args.h>
74 #include <afs/vlserver.h>
75 #include <afs/afsutil.h>
76 #include <afs/fileutil.h>
77 #include <afs/ptuser.h>
78 #include <afs/audit.h>
79 #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 */
110 void *ShutDown(void *);
111 static void ClearXStatValues(void);
112 static void NewParms(int);
113 static void PrintCounters(void);
114 static void ResetCheckDescriptors(void);
115 static void ResetCheckSignal(void);
116 static void *CheckSignal(void *);
118 static afs_int32 Do_VLRegisterRPC(void);
120 int eventlog = 0, rxlog = 0;
122 FILE *console = NULL;
124 #ifdef AFS_PTHREAD_ENV
125 pthread_mutex_t fsync_glock_mutex;
126 pthread_cond_t fsync_cond;
129 #endif /* AFS_PTHREAD_ENV */
132 #define AFS_QUIETFS_ENV 1
133 #define NT_OPEN_MAX 1024 /* This is an arbitrary no. we came up with for
134 * now. We hope this will be replaced by a more
135 * intelligent estimate later. */
138 int SystemId; /* ViceID of "Administrators" */
139 int SystemAnyUser; /* Viceid of "System:AnyUser" */
140 prlist SystemAnyUserCPS; /* CPS for "system:AnyUser */
141 int AnonymousID = 0; /* ViceId of "Anonymous" */
142 prlist AnonCPS; /* CPS for "Anonymous" */
144 struct afsconf_dir *confDir; /* Configuration dir object */
146 int restartMode = RESTART_ORDINARY;
149 * Home for the performance statistics.
151 struct afs_PerfStats afs_perfstats;
154 extern int Statistics;
162 int rxJumbograms = 0; /* default is to not send and receive jumbograms. */
163 int rxBind = 0; /* don't bind */
164 int rxkadDisableDotCheck = 0; /* disable check for dot in principal name */
166 afs_int32 implicitAdminRights = PRSFS_LOOKUP; /* The ADMINISTER right is
168 afs_int32 readonlyServer = 0;
171 int stackSize = 24000;
172 int fiveminutes = 300; /* 5 minutes. Change this for debugging only */
173 int CurrentConnections = 0;
174 int hostaclRefresh = 7200; /* refresh host clients' acls every 2 hrs */
175 #if defined(AFS_SGI_ENV)
180 int rxpackets = 150; /* 100 */
181 int nSmallVns = 400; /* 200 */
182 int large = 400; /* 200 */
183 int volcache = 400; /* 400 */
184 int numberofcbs = 60000; /* 60000 */
185 int lwps = 9; /* 6 */
186 int buffs = 90; /* 70 */
187 int novbc = 0; /* Enable Volume Break calls */
188 int busy_threshold = 600;
189 int abort_threshold = 10;
190 int udpBufSize = 0; /* UDP buffer size for receive */
191 int sendBufSize = 16384; /* send buffer size */
192 int saneacls = 0; /* Sane ACLs Flag */
196 #ifdef AFS_PTHREAD_ENV
197 pthread_key_t viced_uclient_key;
200 #ifdef AFS_PTHREAD_ENV
201 pthread_key_t viced_uclient_key;
205 * FileServer's name and IP address, both network byte order and
208 #define ADDRSPERSITE 16 /* Same global is in rx/rx_user.c */
210 char FS_HostName[128] = "localhost";
211 afs_uint32 FS_HostAddr_NBO;
212 afs_uint32 FS_HostAddr_HBO;
213 afs_uint32 FS_HostAddrs[ADDRSPERSITE], FS_HostAddr_cnt = 0, FS_registered = 0;
214 /* All addresses in FS_HostAddrs are in NBO */
217 static void FlagMsg(void);
219 #ifdef AFS_DEMAND_ATTACH_FS
222 * fileserver mode support
224 * during fileserver shutdown, we have to track the graceful shutdown of
225 * certain background threads before we are allowed to dump state to
229 #if !defined(PTHREAD_RWLOCK_INITIALIZER) && defined(AFS_DARWIN80_ENV)
230 #define PTHREAD_RWLOCK_INITIALIZER {0x2DA8B3B4, {0}}
233 struct fs_state fs_state =
240 PTHREAD_COND_INITIALIZER,
241 PTHREAD_RWLOCK_INITIALIZER
243 #endif /* AFS_DEMAND_ATTACH_FS */
246 * Home for the performance statistics.
251 CheckDescriptors(void *unused)
254 struct afs_stat status;
255 register int tsize = getdtablesize();
257 for (i = 0; i < tsize; i++) {
258 if (afs_fstat(i, &status) != -1) {
259 printf("%d: dev %x, inode %u, length %u, type/mode %x\n", i,
260 (unsigned int) status.st_dev,
261 (unsigned int) status.st_ino,
262 (unsigned int) status.st_size,
267 ResetCheckDescriptors();
270 } /*CheckDescriptors */
273 #ifdef AFS_PTHREAD_ENV
275 CheckSignal_Signal(int x)
281 ShutDown_Signal(int x)
287 CheckDescriptors_Signal(int x)
289 CheckDescriptors(NULL);
291 #else /* AFS_PTHREAD_ENV */
293 CheckSignal_Signal(int x)
295 IOMGR_SoftSig(CheckSignal, 0);
299 ShutDown_Signal(int x)
301 IOMGR_SoftSig(ShutDown, 0);
305 CheckDescriptors_Signal(int x)
307 IOMGR_SoftSig(CheckDescriptors, 0);
309 #endif /* AFS_PTHREAD_ENV */
311 /* check whether caller is authorized to manage RX statistics */
313 fs_rxstat_userok(struct rx_call *call)
315 return afsconf_SuperUser(confDir, call, NULL);
319 ResetCheckSignal(void)
323 #if defined(AFS_HPUX_ENV)
326 #if defined(AFS_NT40_ENV)
333 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
334 softsig_signal(signo, CheckSignal_Signal);
336 signal(signo, CheckSignal_Signal);
341 ResetCheckDescriptors(void)
344 #if defined(AFS_PTHREAD_ENV)
345 softsig_signal(SIGTERM, CheckDescriptors_Signal);
347 (void)signal(SIGTERM, CheckDescriptors_Signal);
352 #if defined(AFS_PTHREAD_ENV)
356 return (intptr_t)pthread_getspecific(rx_thread_id_key);
360 /* proc called by rxkad module to get a key */
362 get_key(void *arock, register afs_int32 akvno, struct ktc_encryptionKey *akey)
365 static struct afsconf_key tkey;
366 register afs_int32 code;
369 ViceLog(0, ("conf dir not open\n"));
372 code = afsconf_GetKey(confDir, akvno, (struct ktc_encryptionKey *)tkey.key);
374 ViceLog(0, ("afsconf_GetKey failure: kvno %d code %d\n", akvno, code));
377 memcpy(akey, tkey.key, sizeof(tkey.key));
383 viced_syscall(afs_uint32 a3, afs_uint32 a4, void *a5)
386 #ifndef AFS_LINUX20_ENV
389 old = (void (*)(int))signal(SIGSYS, SIG_IGN);
391 rcode = syscall(AFS_SYSCALL, 28 /* AFSCALL_CALL */ , a3, a4, a5);
392 #ifndef AFS_LINUX20_ENV
400 #if !defined(AFS_NT40_ENV)
401 #include "AFS_component_version_number.c"
402 #endif /* !AFS_NT40_ENV */
404 #define MAXADMINNAME 64
405 char adminName[MAXADMINNAME];
411 struct afs_stat status;
413 if ((afs_stat("/AdminName", &status)) || /* if file does not exist */
414 (status.st_size <= 0) || /* or it is too short */
415 (status.st_size >= (MAXADMINNAME)) || /* or it is too long */
416 !(fd = afs_open("/AdminName", O_RDONLY, 0))) { /* or the open fails */
417 strcpy(adminName, "System:Administrators"); /* use the default name */
419 (void)read(fd, adminName, status.st_size); /* use name from the file */
422 close(fd); /* close fd if it was opened */
424 } /*CheckAdminName */
430 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
431 /* set our 'thread-id' so that the host hold table works */
432 MUTEX_ENTER(&rx_stats_mutex); /* protects rxi_pthread_hinum */
434 pthread_setspecific(rx_thread_id_key, (void *)(intptr_t)rxi_pthread_hinum);
435 MUTEX_EXIT(&rx_stats_mutex);
437 ("Set thread id %d for '%s'\n",
438 pthread_getspecific(rx_thread_id_key), s));
442 /* This LWP does things roughly every 5 minutes */
444 FiveMinuteCheckLWP(void *unused)
449 ViceLog(1, ("Starting five minute check process\n"));
450 setThreadId("FiveMinuteCheckLWP");
452 #ifdef AFS_DEMAND_ATTACH_FS
454 while (fs_state.mode == FS_MODE_NORMAL) {
455 fs_state.FiveMinuteLWP_tranquil = 1;
461 #ifdef AFS_PTHREAD_ENV
463 #else /* AFS_PTHREAD_ENV */
464 IOMGR_Sleep(fiveminutes);
465 #endif /* AFS_PTHREAD_ENV */
467 #ifdef AFS_DEMAND_ATTACH_FS
469 if (fs_state.mode != FS_MODE_NORMAL) {
472 fs_state.FiveMinuteLWP_tranquil = 0;
476 /* close the log so it can be removed */
477 ReOpenLog(AFSDIR_SERVER_FILELOG_FILEPATH); /* don't trunc, just append */
478 ViceLog(2, ("Cleaning up timed out callbacks\n"));
479 if (CleanupTimedOutCallBacks())
480 ViceLog(5, ("Timed out callbacks deleted\n"));
481 ViceLog(2, ("Set disk usage statistics\n"));
483 if (FS_registered == 1)
485 /* Force wakeup in case we missed something; pthreads does timedwait */
486 #ifndef AFS_PTHREAD_ENV
487 LWP_NoYieldSignal(fsync_wait);
489 if (printBanner && (++msg & 1)) { /* Every 10 minutes */
490 time_t now = FT_ApproxTime();
491 if (console != NULL) {
492 #ifndef AFS_QUIETFS_ENV
493 fprintf(console, "File server is running at %s\r",
494 afs_ctime(&now, tbuffer, sizeof(tbuffer)));
495 #endif /* AFS_QUIETFS_ENV */
497 ("File server is running at %s\n",
498 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
501 #ifdef AFS_DEMAND_ATTACH_FS
505 #ifdef AFS_DEMAND_ATTACH_FS
506 fs_state.FiveMinuteLWP_tranquil = 1;
508 assert(pthread_cond_broadcast(&fs_state.worker_done_cv)==0);
513 } /*FiveMinuteCheckLWP */
516 /* This LWP does host checks every 5 minutes: it should not be used for
517 * other 5 minute activities because it may be delayed by timeouts when
518 * it probes the workstations
522 HostCheckLWP(void *unused)
524 ViceLog(1, ("Starting Host check process\n"));
525 setThreadId("HostCheckLWP");
526 #ifdef AFS_DEMAND_ATTACH_FS
528 while (fs_state.mode == FS_MODE_NORMAL) {
529 fs_state.HostCheckLWP_tranquil = 1;
535 #ifdef AFS_PTHREAD_ENV
537 #else /* AFS_PTHREAD_ENV */
538 IOMGR_Sleep(fiveminutes);
539 #endif /* AFS_PTHREAD_ENV */
541 #ifdef AFS_DEMAND_ATTACH_FS
543 if (fs_state.mode != FS_MODE_NORMAL) {
546 fs_state.HostCheckLWP_tranquil = 0;
550 ViceLog(2, ("Checking for dead venii & clients\n"));
553 #ifdef AFS_DEMAND_ATTACH_FS
557 #ifdef AFS_DEMAND_ATTACH_FS
558 fs_state.HostCheckLWP_tranquil = 1;
560 assert(pthread_cond_broadcast(&fs_state.worker_done_cv)==0);
567 /* This LWP does fsync checks every 5 minutes: it should not be used for
568 * other 5 minute activities because it may be delayed by timeouts when
569 * it probes the workstations
572 FsyncCheckLWP(void *unused)
575 #ifdef AFS_PTHREAD_ENV
576 struct timespec fsync_next;
578 ViceLog(1, ("Starting fsync check process\n"));
580 setThreadId("FsyncCheckLWP");
582 #ifdef AFS_DEMAND_ATTACH_FS
584 while (fs_state.mode == FS_MODE_NORMAL) {
585 fs_state.FsyncCheckLWP_tranquil = 1;
591 #ifdef AFS_PTHREAD_ENV
592 /* rounding is fine */
593 fsync_next.tv_nsec = 0;
594 fsync_next.tv_sec = time(0) + fiveminutes;
597 pthread_cond_timedwait(&fsync_cond, &fsync_glock_mutex,
599 if (code != 0 && code != ETIMEDOUT)
600 ViceLog(0, ("pthread_cond_timedwait returned %d\n", code));
601 #else /* AFS_PTHREAD_ENV */
602 if ((code = LWP_WaitProcess(fsync_wait)) != LWP_SUCCESS)
603 ViceLog(0, ("LWP_WaitProcess returned %d\n", code));
604 #endif /* AFS_PTHREAD_ENV */
607 #ifdef AFS_DEMAND_ATTACH_FS
609 if (fs_state.mode != FS_MODE_NORMAL) {
612 fs_state.FsyncCheckLWP_tranquil = 0;
614 #endif /* AFS_DEMAND_ATTACH_FS */
616 ViceLog(2, ("Checking for fsync events\n"));
618 code = BreakLaterCallBacks();
620 #ifdef AFS_DEMAND_ATTACH_FS
624 #ifdef AFS_DEMAND_ATTACH_FS
625 fs_state.FsyncCheckLWP_tranquil = 1;
627 assert(pthread_cond_broadcast(&fs_state.worker_done_cv)==0);
630 #endif /* AFS_DEMAND_ATTACH_FS */
634 /*------------------------------------------------------------------------
635 * PRIVATE ClearXStatValues
638 * Initialize all of the values collected via the xstat
648 * Must be called during File Server initialization.
652 *------------------------------------------------------------------------*/
655 ClearXStatValues(void)
656 { /*ClearXStatValues */
658 struct fs_stats_opTimingData *opTimeP; /*Ptr to timing struct */
659 struct fs_stats_xferData *opXferP; /*Ptr to xfer struct */
660 int i; /*Loop counter */
663 * Zero all xstat-related structures.
665 memset((&afs_perfstats), 0, sizeof(struct afs_PerfStats));
666 #if FS_STATS_DETAILED
667 memset((&afs_FullPerfStats), 0,
668 sizeof(struct fs_stats_FullPerfStats));
671 * That's not enough. We have to set reasonable minima for
672 * time and xfer values in the detailed stats.
674 opTimeP = &(afs_FullPerfStats.det.rpcOpTimes[0]);
675 for (i = 0; i < FS_STATS_NUM_RPC_OPS; i++, opTimeP++)
676 opTimeP->minTime.tv_sec = 999999;
678 opXferP = &(afs_FullPerfStats.det.xferOpTimes[0]);
679 for (i = 0; i < FS_STATS_NUM_XFER_OPS; i++, opXferP++) {
680 opXferP->minTime.tv_sec = 999999;
681 opXferP->minBytes = 999999999;
685 * There's more. We have to set our unique system identifier, as
686 * declared in param.h. If such a thing is not defined, we bitch
687 * and declare ourselves to be an unknown system type.
690 afs_perfstats.sysname_ID = SYS_NAME_ID;
693 ViceLog(0, ("Sys name ID constant not defined in param.h!!\n"));
694 ViceLog(0, ("[Choosing ``undefined'' sys name ID.\n"));
696 afs_perfstats.sysname_ID = SYS_NAME_ID_UNDEFINED;
697 #endif /* SYS_NAME_ID */
700 } /*ClearXStatValues */
702 int CopyOnWrite_calls = 0, CopyOnWrite_off0 = 0, CopyOnWrite_size0 = 0;
703 afs_fsize_t CopyOnWrite_maxsize = 0;
708 int dirbuff, dircall, dirio;
710 int workstations, activeworkstations, delworkstations;
714 FT_GetTimeOfDay(&tpl, 0);
717 ("Vice was last started at %s\n",
718 afs_ctime(&StartTime, tbuffer, sizeof(tbuffer))));
720 #ifdef AFS_DEMAND_ATTACH_FS
721 /* XXX perhaps set extended stats verbosity flags
722 * based upon LogLevel ?? */
723 VPrintExtendedCacheStats(VOL_STATS_PER_CHAIN2);
727 DStat(&dirbuff, &dircall, &dirio);
729 ("With %d directory buffers; %d reads resulted in %d read I/Os\n",
730 dirbuff, dircall, dirio));
731 rx_PrintStats(stderr);
732 audit_PrintStats(stderr);
734 PrintCallBackStats();
736 processSize = -1; /* TODO: */
738 processSize = (int)((long)sbrk(0) >> 10);
741 ("There are %d connections, process size %d\n",
742 CurrentConnections, processSize));
743 h_GetWorkStats(&workstations, &activeworkstations, &delworkstations,
744 tpl.tv_sec - 15 * 60);
746 ("There are %d workstations, %d are active (req in < 15 mins), %d marked \"down\"\n",
747 workstations, activeworkstations, delworkstations));
748 ViceLog(0, ("CopyOnWrite: calls %d off0 %d size0 %d maxsize 0x%llx\n",
749 CopyOnWrite_calls, CopyOnWrite_off0, CopyOnWrite_size0, CopyOnWrite_maxsize));
758 CheckSignal(void *unused)
760 if (FS_registered > 0) {
762 * We have proper ip addresses; tell the vlserver what we got; the following
763 * routine will do the proper reporting for us
776 ShutDownAndCore(int dopanic)
778 time_t now = time(0);
781 /* do not allows new reqests to be served from now on, all new requests
782 * are returned with an error code of RX_RESTARTING ( transient failure ) */
783 rx_SetRxTranquil(); /* dhruba */
787 #ifdef AFS_DEMAND_ATTACH_FS
789 fs_state.mode = FS_MODE_SHUTDOWN;
794 ("Shutting down file server at %s",
795 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
797 ViceLog(0, ("ABNORMAL SHUTDOWN, see core file.\n"));
798 #ifndef AFS_QUIETFS_ENV
799 if (console != NULL) {
800 fprintf(console, "File server restart/shutdown received at %s\r",
801 afs_ctime(&now, tbuffer, sizeof(tbuffer)));
808 /* shut down volume package */
811 #ifdef AFS_DEMAND_ATTACH_FS
812 if (fs_state.options.fs_state_save) {
815 * save fileserver state to disk */
817 /* make sure background threads have finished all of their asynchronous
818 * work on host and callback structures */
820 while (!fs_state.FiveMinuteLWP_tranquil ||
821 !fs_state.HostCheckLWP_tranquil ||
822 !fs_state.FsyncCheckLWP_tranquil) {
825 ViceLog(0, ("waiting for background host/callback threads to quiesce before saving fileserver state...\n"));
826 assert(pthread_cond_wait(&fs_state.worker_done_cv, &fileproc_glock_mutex) == 0);
831 /* ok. it should now be fairly safe. let's do the state dump */
834 #endif /* AFS_DEMAND_ATTACH_FS */
837 rx_PrintStats(debugFile);
840 if (console != NULL) {
843 #ifndef AFS_QUIETFS_ENV
844 fprintf(console, "File server has terminated abnormally at %s\r",
845 afs_ctime(&now, tbuffer, sizeof(tbuffer)));
848 ("File server has terminated abnormally at %s\n",
849 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
851 #ifndef AFS_QUIETFS_ENV
852 fprintf(console, "File server has terminated normally at %s\r",
853 afs_ctime(&now, tbuffer, sizeof(tbuffer)));
856 ("File server has terminated normally at %s\n",
857 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
868 ShutDown(void *unused)
869 { /* backward compatibility */
870 ShutDownAndCore(DONTPANIC);
878 /* default supports help flag */
880 fputs("Usage: fileserver ", stdout);
881 fputs("[-auditlog <log path>] ", stdout);
882 fputs("[-audit-interface <file|sysvmq> (default is file)] ", stdout);
883 fputs("[-d <debug level>] ", stdout);
884 fputs("[-p <number of processes>] ", stdout);
885 fputs("[-spare <number of spare blocks>] ", stdout);
886 fputs("[-pctspare <percentage spare>] ", stdout);
887 fputs("[-b <buffers>] ", stdout);
888 fputs("[-l <large vnodes>] ", stdout);
889 fputs("[-s <small vnodes>] ", stdout);
890 fputs("[-vc <volume cachesize>] ", stdout);
891 fputs("[-w <call back wait interval>] ", stdout);
892 fputs("[-cb <number of call backs>] ", stdout);
893 fputs("[-banner (print banner every 10 minutes)] ", stdout);
894 fputs("[-novbc (whole volume cbs disabled)] ", stdout);
895 fputs("[-implicit <admin mode bits: rlidwka>] ", stdout);
896 fputs("[-readonly (read-only file server)] ", stdout);
897 fputs("[-hr <number of hours between refreshing the host cps>] ", stdout);
898 fputs("[-busyat <redirect clients when queue > n>] ", stdout);
899 fputs("[-nobusy <no VBUSY before a volume is attached>] ", stdout);
900 fputs("[-rxpck <number of rx extra packets>] ", stdout);
901 fputs("[-rxdbg (enable rx debugging)] ", stdout);
902 fputs("[-rxdbge (enable rxevent debugging)] ", stdout);
903 fputs("[-rxmaxmtu <bytes>] ", stdout);
904 fputs("[-rxbind (bind the Rx socket to one address)] ", stdout);
905 fputs("[-allow-dotted-principals (disable the rxkad principal name dot check)] ", stdout);
906 #ifdef AFS_DEMAND_ATTACH_FS
907 fputs("[-fs-state-dont-save (disable state save during shutdown)] ", stdout);
908 fputs("[-fs-state-dont-restore (disable state restore during startup)] ", stdout);
909 fputs("[-fs-state-verify <none|save|restore|both> (default is both)] ", stdout);
910 fputs("[-vattachpar <max number of volume attach/shutdown threads> (default is 1)] ", stdout);
911 fputs("[-vhashsize <log(2) of number of volume hash buckets> (default is 8)] ", stdout);
912 fputs("[-vlrudisable (disable VLRU functionality)] ", stdout);
913 fputs("[-vlruthresh <minutes before unused volumes become eligible for soft detach> (default is 2 hours)] ", stdout);
914 fputs("[-vlruinterval <seconds between VLRU scans> (default is 2 minutes)] ", stdout);
915 fputs("[-vlrumax <max volumes to soft detach in one VLRU scan> (default is 8)] ", stdout);
916 #elif AFS_PTHREAD_ENV
917 fputs("[-vattachpar <number of volume attach threads> (default is 1)] ", stdout);
920 fputs("[-m <min percentage spare in partition>] ", stdout);
922 #if defined(AFS_SGI_ENV)
923 fputs("[-lock (keep fileserver from swapping)] ", stdout);
925 fputs("[-L (large server conf)] ", stdout);
926 fputs("[-S (small server conf)] ", stdout);
927 fputs("[-k <stack size>] ", stdout);
928 fputs("[-realm <Kerberos realm name>] ", stdout);
929 fputs("[-udpsize <size of socket buffer in bytes>] ", stdout);
930 fputs("[-sendsize <size of send buffer in bytes>] ", stdout);
931 fputs("[-abortthreshold <abort threshold>] ", stdout);
932 fputs("[-nojumbo (disable jumbogram network packets - deprecated)] ", stdout);
933 fputs("[-jumbo (enable jumbogram network packets)] ", stdout);
934 /* fputs("[-enable_peer_stats] ", stdout); */
935 /* fputs("[-enable_process_stats] ", stdout); */
936 fputs("[-help]\n", stdout);
938 ViceLog(0, ("%s", buffer));
947 ParseRights(char *arights)
953 if (!arights || !strcmp(arights, "")) {
954 printf("Missing list of mode bits on -implicit option\n");
957 if (!strcmp(arights, "none"))
959 else if (!strcmp(arights, "read"))
960 mode = PRSFS_READ | PRSFS_LOOKUP;
961 else if (!strcmp(arights, "write"))
963 PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
964 PRSFS_WRITE | PRSFS_LOCK;
965 else if (!strcmp(arights, "all"))
967 PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
968 PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER;
970 len = strlen(arights);
971 for (i = 0; i < len; i++) {
976 mode |= PRSFS_LOOKUP;
978 mode |= PRSFS_INSERT;
980 mode |= PRSFS_DELETE;
986 mode |= PRSFS_ADMINISTER;
1004 printf("Illegal -implicit rights character '%c'.\n", tc);
1013 * Limit MAX_FILESERVER_THREAD by the system limit on the number of
1014 * pthreads (sysconf(_SC_THREAD_THREADS_MAX)), if applicable and
1017 * AIX: sysconf() limit is real
1018 * HP-UX: sysconf() limit is real
1019 * IRIX: sysconf() limit is apparently NOT real -- too small
1020 * DUX: sysconf() limit is apparently NOT real -- too big
1021 * Linux: sysconf() limit is apparently NOT real -- too big
1022 * Solaris: no sysconf() limit
1025 max_fileserver_thread(void)
1027 #if defined(AFS_PTHREAD_ENV)
1028 #if defined(AFS_AIX_ENV) || defined(AFS_HPUX_ENV)
1031 ans = sysconf(_SC_THREAD_THREADS_MAX);
1032 if (0 < ans && ans < MAX_FILESERVER_THREAD)
1035 #endif /* defined(AFS_PTHREAD_ENV) */
1036 return MAX_FILESERVER_THREAD;
1040 ParseArgs(int argc, char *argv[])
1042 int SawL = 0, SawS = 0, SawVC = 0;
1043 int Sawrxpck = 0, Sawsmall = 0, Sawlarge = 0, Sawcbs = 0, Sawlwps =
1047 int bufSize = 0; /* temp variable to read in udp socket buf size */
1048 char *auditFileName = NULL;
1050 for (i = 1; i < argc; i++) {
1051 if (!strcmp(argv[i], "-d")) {
1052 if ((i + 1) >= argc) {
1053 fprintf(stderr, "missing argument for -d\n");
1056 debuglevel = atoi(argv[++i]);
1057 LogLevel = debuglevel;
1058 } else if (!strcmp(argv[i], "-banner")) {
1060 } else if (!strcmp(argv[i], "-implicit")) {
1061 if ((i + 1) >= argc) {
1062 fprintf(stderr, "missing argument for -implicit\n");
1065 implicitAdminRights = ParseRights(argv[++i]);
1066 if (implicitAdminRights < 0)
1067 return implicitAdminRights;
1068 } else if (!strcmp(argv[i], "-readonly")) {
1070 } else if (!strcmp(argv[i], "-L")) {
1072 } else if (!strcmp(argv[i], "-S")) {
1074 } else if (!strcmp(argv[i], "-p")) {
1076 max_fileserver_thread() - FILESERVER_HELPER_THREADS;
1078 if ((i + 1) >= argc) {
1079 fprintf(stderr, "missing argument for -p\n");
1082 lwps = atoi(argv[++i]);
1083 if (lwps > lwps_max)
1087 } else if (!strcmp(argv[i], "-b")) {
1089 if ((i + 1) >= argc) {
1090 fprintf(stderr, "missing argument for -b\n");
1093 buffs = atoi(argv[++i]);
1094 } else if (!strcmp(argv[i], "-l")) {
1096 if ((i + 1) >= argc) {
1097 fprintf(stderr, "missing argument for -l\n");
1100 large = atoi(argv[++i]);
1101 } else if (!strcmp(argv[i], "-vc")) {
1103 if ((i + 1) >= argc) {
1104 fprintf(stderr, "missing argument for -vc\n");
1107 volcache = atoi(argv[++i]);
1108 } else if (!strcmp(argv[i], "-novbc")) {
1110 } else if (!strcmp(argv[i], "-rxpck")) {
1112 if ((i + 1) >= argc) {
1113 fprintf(stderr, "missing argument for -rxpck\n");
1116 rxpackets = atoi(argv[++i]);
1117 #ifdef AFS_PTHREAD_ENV
1118 } else if (!strcmp(argv[i], "-vattachpar")) {
1119 if ((i + 1) >= argc) {
1120 fprintf(stderr, "missing argument for %s\n", argv[i]);
1123 vol_attach_threads = atoi(argv[++i]);
1124 #endif /* AFS_PTHREAD_ENV */
1125 #ifdef AFS_DEMAND_ATTACH_FS
1126 } else if (!strcmp(argv[i], "-fs-state-dont-save")) {
1127 fs_state.options.fs_state_save = 0;
1128 } else if (!strcmp(argv[i], "-fs-state-dont-restore")) {
1129 fs_state.options.fs_state_restore = 0;
1130 } else if (!strcmp(argv[i], "-fs-state-verify")) {
1131 if ((i + 1) >= argc) {
1132 fprintf(stderr, "missing argument for %s\n", argv[i]);
1136 if (!strcmp(argv[i], "none")) {
1137 fs_state.options.fs_state_verify_before_save = 0;
1138 fs_state.options.fs_state_verify_after_restore = 0;
1139 } else if (!strcmp(argv[i], "save")) {
1140 fs_state.options.fs_state_verify_after_restore = 0;
1141 } else if (!strcmp(argv[i], "restore")) {
1142 fs_state.options.fs_state_verify_before_save = 0;
1143 } else if (!strcmp(argv[i], "both")) {
1146 fprintf(stderr, "invalid argument for %s\n", argv[i-1]);
1149 } else if (!strcmp(argv[i], "-vhashsize")) {
1150 if ((i + 1) >= argc) {
1151 fprintf(stderr, "missing argument for %s\n", argv[i]);
1154 VSetVolHashSize(atoi(argv[++i]));
1155 } else if (!strcmp(argv[i], "-vlrudisable")) {
1156 VLRU_SetOptions(VLRU_SET_ENABLED, 0);
1157 } else if (!strcmp(argv[i], "-vlruthresh")) {
1158 if ((i + 1) >= argc) {
1159 fprintf(stderr, "missing argument for %s\n", argv[i]);
1162 VLRU_SetOptions(VLRU_SET_THRESH, 60*atoi(argv[++i]));
1163 } else if (!strcmp(argv[i], "-vlruinterval")) {
1164 if ((i + 1) >= argc) {
1165 fprintf(stderr, "missing argument for %s\n", argv[i]);
1168 VLRU_SetOptions(VLRU_SET_INTERVAL, atoi(argv[++i]));
1169 } else if (!strcmp(argv[i], "-vlrumax")) {
1170 if ((i + 1) >= argc) {
1171 fprintf(stderr, "missing argument for %s\n", argv[i]);
1174 VLRU_SetOptions(VLRU_SET_MAX, atoi(argv[++i]));
1175 #endif /* AFS_DEMAND_ATTACH_FS */
1176 } else if (!strcmp(argv[i], "-s")) {
1178 if ((i + 1) >= argc) {
1179 fprintf(stderr, "missing argument for -s\n");
1182 nSmallVns = atoi(argv[++i]);
1183 } else if (!strcmp(argv[i], "-abortthreshold")) {
1184 if ((i + 1) >= argc) {
1185 fprintf(stderr, "missing argument for -abortthreshold\n");
1188 abort_threshold = atoi(argv[++i]);
1189 } else if (!strcmp(argv[i], "-k")) {
1190 if ((i + 1) >= argc) {
1191 fprintf(stderr, "missing argument for -k\n");
1194 stack = atoi(argv[++i]);
1196 #if defined(AFS_SGI_ENV)
1197 else if (!strcmp(argv[i], "-lock")) {
1201 else if (!strcmp(argv[i], "-spare")) {
1202 if ((i + 1) >= argc) {
1203 fprintf(stderr, "missing argument for -spare\n");
1206 BlocksSpare = atoi(argv[++i]);
1208 } else if (!strcmp(argv[i], "-pctspare")) {
1209 if ((i + 1) >= argc) {
1210 fprintf(stderr, "missing argument for -pctspare\n");
1213 PctSpare = atoi(argv[++i]);
1214 BlocksSpare = 0; /* has non-zero default */
1216 } else if (!strcmp(argv[i], "-w")) {
1217 if ((i + 1) >= argc) {
1218 fprintf(stderr, "missing argument for -w\n");
1221 fiveminutes = atoi(argv[++i]);
1222 } else if (!strcmp(argv[i], "-hr")) {
1224 if ((i + 1) >= argc) {
1225 fprintf(stderr, "missing argument for -hr\n");
1228 hr = atoi(argv[++i]);
1229 if ((hr < 1) || (hr > 36)) {
1231 ("host acl refresh interval of %d hours is invalid; hours must be between 1 and 36\n\n",
1235 hostaclRefresh = hr * 60 * 60;
1236 } else if (!strcmp(argv[i], "-rxdbg"))
1238 else if (!strcmp(argv[i], "-rxdbge"))
1240 else if (!strcmp(argv[i], "-cb")) {
1242 if ((i + 1) >= argc) {
1243 fprintf(stderr, "missing argument for -cb\n");
1246 numberofcbs = atoi(argv[++i]);
1247 if ((numberofcbs < 10000) || (numberofcbs > 2147483647)) {
1249 ("number of cbs %d invalid; must be between 10000 and 2147483647\n",
1253 } else if (!strcmp(argv[i], "-busyat")) {
1255 if ((i + 1) >= argc) {
1256 fprintf(stderr, "missing argument for -busyat\n");
1259 busy_threshold = atoi(argv[++i]);
1260 if (busy_threshold < 10) {
1262 ("Busy threshold %d is too low, will compute default.\n",
1266 } else if (!strcmp(argv[i], "-nobusy"))
1268 #ifdef AFS_AIX32_ENV
1269 else if (!strcmp(argv[i], "-m")) {
1270 extern int aixlow_water;
1271 if ((i + 1) >= argc) {
1272 fprintf(stderr, "missing argument for -m\n");
1275 aixlow_water = atoi(argv[++i]);
1276 if ((aixlow_water < 0) || (aixlow_water > 30)) {
1277 printf("space reserved %d% invalid; must be between 0-30%\n",
1283 else if (!strcmp(argv[i], "-nojumbo")) {
1285 } else if (!strcmp(argv[i], "-jumbo")) {
1287 } else if (!strcmp(argv[i], "-rxbind")) {
1289 } else if (!strcmp(argv[i], "-allow-dotted-principals")) {
1290 rxkadDisableDotCheck = 1;
1291 } else if (!strcmp(argv[i], "-rxmaxmtu")) {
1292 if ((i + 1) >= argc) {
1293 fprintf(stderr, "missing argument for -rxmaxmtu\n");
1296 rxMaxMTU = atoi(argv[++i]);
1297 if ((rxMaxMTU < RX_MIN_PACKET_SIZE) ||
1298 (rxMaxMTU > RX_MAX_PACKET_DATA_SIZE)) {
1299 printf("rxMaxMTU %d%% invalid; must be between %d-%" AFS_SIZET_FMT "\n",
1300 rxMaxMTU, RX_MIN_PACKET_SIZE,
1301 RX_MAX_PACKET_DATA_SIZE);
1304 } else if (!strcmp(argv[i], "-realm")) {
1305 extern char local_realms[AFS_NUM_LREALMS][AFS_REALM_SZ];
1306 extern int num_lrealms;
1307 if ((i + 1) >= argc) {
1308 fprintf(stderr, "missing argument for -realm\n");
1311 if (strlen(argv[++i]) >= AFS_REALM_SZ) {
1313 ("-realm argument must contain fewer than %d characters.\n",
1317 if (num_lrealms == -1)
1319 if (num_lrealms >= AFS_NUM_LREALMS) {
1321 ("a maximum of %d -realm arguments can be specified.\n",
1325 strncpy(local_realms[num_lrealms++], argv[i], AFS_REALM_SZ);
1326 } else if (!strcmp(argv[i], "-udpsize")) {
1327 if ((i + 1) >= argc) {
1328 printf("You have to specify -udpsize <integer value>\n");
1331 bufSize = atoi(argv[++i]);
1332 if (bufSize < rx_GetMinUdpBufSize())
1334 ("Warning:udpsize %d is less than minimum %d; ignoring\n",
1335 bufSize, rx_GetMinUdpBufSize());
1337 udpBufSize = bufSize;
1338 } else if (!strcmp(argv[i], "-sendsize")) {
1339 if ((i + 1) >= argc) {
1340 printf("You have to specify -sendsize <integer value>\n");
1343 bufSize = atoi(argv[++i]);
1344 if (bufSize < 16384)
1346 ("Warning:sendsize %d is less than minimum %d; ignoring\n",
1349 sendBufSize = bufSize;
1350 } else if (!strcmp(argv[i], "-enable_peer_stats")) {
1351 rx_enablePeerRPCStats();
1352 } else if (!strcmp(argv[i], "-enable_process_stats")) {
1353 rx_enableProcessRPCStats();
1355 else if (strcmp(argv[i], "-auditlog") == 0) {
1356 auditFileName = argv[++i];
1358 else if (strcmp(argv[i], "-audit-interface") == 0) {
1359 char *interface = argv[++i];
1361 if (osi_audit_interface(interface)) {
1362 printf("Invalid audit interface '%s'\n", interface);
1366 #ifndef AFS_NT40_ENV
1367 else if (strcmp(argv[i], "-syslog") == 0) {
1368 /* set syslog logging flag */
1369 serverLogSyslog = 1;
1370 } else if (strncmp(argv[i], "-syslog=", 8) == 0) {
1371 serverLogSyslog = 1;
1372 serverLogSyslogFacility = atoi(argv[i] + 8);
1375 else if (strcmp(argv[i], "-mrafslogs") == 0) {
1376 /* set syslog logging flag */
1379 else if (strcmp(argv[i], "-saneacls") == 0) {
1387 printf("Only one of -L, or -S must be specified\n");
1398 numberofcbs = 20000;
1414 numberofcbs = 64000;
1423 busy_threshold = 3 * rxpackets / 2;
1425 osi_audit_file(auditFileName);
1435 NewParms(int initializing)
1437 static struct afs_stat sbuf;
1440 char *argv[MAXPARMS];
1443 if (!(afs_stat("/vice/file/parms", &sbuf))) {
1444 parms = (char *)malloc(sbuf.st_size);
1447 fd = afs_open("parms", O_RDONLY, 0666);
1449 ViceLog(0, ("Open for parms failed with errno = %d\n", errno));
1453 i = read(fd, parms, sbuf.st_size);
1455 if (i != sbuf.st_size) {
1457 ViceLog(0, ("Read on parms failed with errno = %d\n", errno));
1460 ("Read on parms failed; expected %d bytes but read %d\n",
1467 for (i = 0; i < MAXPARMS; argv[i++] = 0);
1469 for (argc = i = 0; i < sbuf.st_size; i++) {
1470 if ((*(parms + i) != ' ') && (*(parms + i) != '\n')) {
1471 if (argv[argc] == 0)
1472 argv[argc] = (parms + i);
1474 *(parms + i) = '\0';
1475 if (argv[argc] != 0) {
1476 if (++argc == MAXPARMS)
1479 while ((*(parms + i + 1) == ' ')
1480 || (*(parms + i + 1) == '\n'))
1484 if (ParseArgs(argc, argv) == 0) {
1485 ViceLog(0, ("Change parameters to:"));
1487 ViceLog(0, ("Invalid parameter in:"));
1489 for (i = 0; i < argc; i++) {
1490 ViceLog(0, (" %s", argv[i]));
1494 } else if (!initializing)
1496 ("Received request to change parms but no parms file exists\n"));
1501 /* Miscellaneous routines */
1505 ViceLog(0, ("%s\n", msg));
1517 * If this fails, it's because something major is wrong, and is not
1518 * likely to be time dependent.
1520 code = pr_Initialize(2, AFSDIR_SERVER_ETC_DIRPATH, 0);
1523 ("Couldn't initialize protection library; code=%d.\n", code));
1527 #ifdef AFS_PTHREAD_ENV
1528 assert(pthread_key_create(&viced_uclient_key, NULL) == 0);
1531 SystemId = SYSADMINID;
1532 SystemAnyUser = ANYUSERID;
1533 SystemAnyUserCPS.prlist_len = 0;
1534 SystemAnyUserCPS.prlist_val = NULL;
1535 AnonCPS.prlist_len = 0;
1536 AnonCPS.prlist_val = NULL;
1538 code = pr_GetCPS(SystemAnyUser, &SystemAnyUserCPS);
1541 ("Couldn't get CPS for AnyUser, will try again in 30 seconds; code=%d.\n",
1545 code = pr_GetCPS(ANONYMOUSID, &AnonCPS);
1548 ("Couldn't get Anonymous CPS, exiting; code=%d.\n",
1552 AnonymousID = ANONYMOUSID;
1555 #ifdef AFS_PTHREAD_ENV
1557 #else /* AFS_PTHREAD_ENV */
1559 #endif /* AFS_PTHREAD_ENV */
1563 struct rx_connection *serverconns[MAXSERVERS];
1564 struct ubik_client *cstruct;
1567 vl_Initialize(const char *confDir)
1569 afs_int32 code, scIndex = 0, i;
1570 struct afsconf_dir *tdir;
1571 struct rx_securityClass *sc;
1572 struct afsconf_cell info;
1574 tdir = afsconf_Open(confDir);
1577 ("Could not open configuration directory (%s).\n", confDir));
1580 code = afsconf_ClientAuth(tdir, &sc, &scIndex);
1582 ViceLog(0, ("Could not get security object for localAuth\n"));
1585 code = afsconf_GetCellInfo(tdir, NULL, AFSCONF_VLDBSERVICE, &info);
1586 if (info.numServers > MAXSERVERS) {
1588 ("vl_Initialize: info.numServers=%d (> MAXSERVERS=%d)\n",
1589 info.numServers, MAXSERVERS));
1592 for (i = 0; i < info.numServers; i++)
1594 rx_NewConnection(info.hostAddr[i].sin_addr.s_addr,
1595 info.hostAddr[i].sin_port, USER_SERVICE_ID, sc,
1597 code = ubik_ClientInit(serverconns, &cstruct);
1598 afsconf_Close(tdir);
1600 ViceLog(0, ("vl_Initialize: ubik client init failed.\n"));
1606 #define SYSIDMAGIC 0x88aabbcc
1607 #define SYSIDVERSION 1
1612 afs_int32 fd, nentries, i;
1613 struct versionStamp vsn;
1614 struct afs_stat status;
1617 if ((afs_stat(AFSDIR_SERVER_SYSID_FILEPATH, &status))
1618 || (status.st_size <= 0)) {
1619 ViceLog(0, ("%s: doesn't exist\n", AFSDIR_SERVER_SYSID_FILEPATH));
1622 if (!(fd = afs_open(AFSDIR_SERVER_SYSID_FILEPATH, O_RDONLY, 0))) {
1624 ("%s: can't open (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1628 if ((i = read(fd, (char *)&vsn, sizeof(vsn))) != sizeof(vsn)) {
1630 ("%s: Read failed (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1634 if (vsn.magic != SYSIDMAGIC) {
1636 ("%s: wrong magic %x (we support %x)\n",
1637 AFSDIR_SERVER_SYSID_FILEPATH, vsn.magic, SYSIDMAGIC));
1640 if (vsn.version != SYSIDVERSION) {
1642 ("%s: wrong version %d (we support %d)\n",
1643 AFSDIR_SERVER_SYSID_FILEPATH, vsn.version, SYSIDVERSION));
1647 read(fd, (char *)&uuid,
1648 sizeof(struct afsUUID))) != sizeof(struct afsUUID)) {
1650 ("%s: read of uuid failed (%d)\n",
1651 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1654 afs_ntohuuid(&uuid);
1657 read(fd, (char *)&nentries,
1658 sizeof(afs_int32))) != sizeof(afs_int32)) {
1660 ("%s: Read of entries failed (%d)\n",
1661 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1664 if (nentries <= 0 || nentries > ADDRSPERSITE) {
1666 ("%s: invalid num of interfaces: %d\n",
1667 AFSDIR_SERVER_SYSID_FILEPATH, nentries));
1670 if (FS_HostAddr_cnt == 0) {
1671 FS_HostAddr_cnt = nentries;
1672 for (i = 0; i < nentries; i++) {
1673 if (read(fd, (char *)&FS_HostAddrs[i], sizeof(afs_int32)) !=
1674 sizeof(afs_int32)) {
1676 ("%s: Read of addresses failed (%d)\n",
1677 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1678 FS_HostAddr_cnt = 0; /* reset it */
1684 ("%s: address list ignored (NetInfo/NetRestrict override)\n",
1685 AFSDIR_SERVER_SYSID_FILEPATH));
1692 WriteSysIdFile(void)
1695 struct versionStamp vsn;
1696 struct afs_stat status;
1699 if (!afs_stat(AFSDIR_SERVER_SYSID_FILEPATH, &status)) {
1701 * File exists; keep the old one around
1703 renamefile(AFSDIR_SERVER_SYSID_FILEPATH,
1704 AFSDIR_SERVER_OLDSYSID_FILEPATH);
1706 fd = afs_open(AFSDIR_SERVER_SYSID_FILEPATH, O_WRONLY | O_TRUNC | O_CREAT,
1710 ("%s: can't create (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1714 vsn.magic = SYSIDMAGIC;
1716 if ((i = write(fd, (char *)&vsn, sizeof(vsn))) != sizeof(vsn)) {
1718 ("%s: write failed (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1723 afs_htonuuid(&uuid);
1725 write(fd, (char *)&uuid,
1726 sizeof(struct afsUUID))) != sizeof(struct afsUUID)) {
1728 ("%s: write of uuid failed (%d)\n",
1729 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1733 write(fd, (char *)&FS_HostAddr_cnt,
1734 sizeof(afs_int32))) != sizeof(afs_int32)) {
1736 ("%s: write of # of entries failed (%d)\n",
1737 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1740 for (i = 0; i < FS_HostAddr_cnt; i++) {
1741 if (write(fd, (char *)&FS_HostAddrs[i], sizeof(afs_int32)) !=
1742 sizeof(afs_int32)) {
1744 ("%s: write of addresses failed (%d)\n",
1745 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1755 * This routine sets up the buffers for the VL_RegisterAddrs RPC. All addresses
1756 * in FS_HostAddrs[] are in NBO, while the RPC treats them as a "blob" of data
1757 * and so we need to convert each of them into HBO which is what the extra
1758 * array called FS_HostAddrs_HBO is used here.
1761 Do_VLRegisterRPC(void)
1765 afs_uint32 FS_HostAddrs_HBO[ADDRSPERSITE];
1768 for (i = 0; i < FS_HostAddr_cnt; i++)
1769 FS_HostAddrs_HBO[i] = ntohl(FS_HostAddrs[i]);
1770 addrs.bulkaddrs_len = FS_HostAddr_cnt;
1771 addrs.bulkaddrs_val = (afs_uint32 *) FS_HostAddrs_HBO;
1772 code = ubik_VL_RegisterAddrs(cstruct, 0, &FS_HostUUID, 0, &addrs);
1774 if (code == VL_MULTIPADDR) {
1776 ("VL_RegisterAddrs rpc failed; The IP address exists on a different server; repair it\n"));
1778 ("VL_RegisterAddrs rpc failed; See VLLog for details\n"));
1780 } else if (code == RXGEN_OPCODE) {
1782 ("vlserver doesn't support VL_RegisterAddrs rpc; ignored\n"));
1783 FS_registered = 2; /* So we don't have to retry in the gc daemon */
1786 ("VL_RegisterAddrs rpc failed; will retry periodically (code=%d, err=%d)\n",
1788 FS_registered = 1; /* Retry in the gc daemon */
1791 FS_registered = 2; /* So we don't have to retry in the gc daemon */
1803 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH || AFSDIR_SERVER_NETINFO_FILEPATH) {
1805 * Find addresses we are supposed to register as per the netrestrict
1806 * and netinfo files (/usr/afs/local/NetInfo and
1807 * /usr/afs/local/NetRestict)
1810 afs_int32 code = parseNetFiles(FS_HostAddrs, NULL, NULL,
1811 ADDRSPERSITE, reason,
1812 AFSDIR_SERVER_NETINFO_FILEPATH,
1813 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
1815 ViceLog(0, ("Can't register any valid addresses: %s\n", reason));
1818 FS_HostAddr_cnt = (afs_uint32) code;
1821 FS_HostAddr_cnt = rx_getAllAddr(FS_HostAddrs, ADDRSPERSITE);
1824 if (FS_HostAddr_cnt == 1 && rxBind == 1)
1825 code = FS_HostAddrs[0];
1827 code = htonl(INADDR_ANY);
1837 * If this fails, it's because something major is wrong, and is not
1838 * likely to be time dependent.
1840 code = vl_Initialize(AFSDIR_SERVER_ETC_DIRPATH);
1843 ("Couldn't initialize protection library; code=%d.\n", code));
1847 /* Read or create the sysid file and register the fileserver's
1848 * IP addresses with the vlserver.
1850 code = ReadSysIdFile();
1852 /* Need to create the file */
1853 ViceLog(0, ("Creating new SysID file\n"));
1854 if ((code = afs_uuid_create(&FS_HostUUID))) {
1855 ViceLog(0, ("Failed to create new uuid: %d\n", code));
1859 /* A good sysid file exists; inform the vlserver. If any conflicts,
1860 * we always use the latest interface available as the real truth.
1863 code = Do_VLRegisterRPC();
1868 main(int argc, char *argv[])
1872 struct rx_securityClass *sc[4];
1873 struct rx_service *tservice;
1874 #ifdef AFS_PTHREAD_ENV
1875 pthread_t serverPid;
1876 pthread_attr_t tattr;
1877 #else /* AFS_PTHREAD_ENV */
1878 PROCESS parentPid, serverPid;
1879 #endif /* AFS_PTHREAD_ENV */
1881 int minVnodesRequired; /* min size of vnode cache */
1882 #ifndef AFS_NT40_ENV
1883 struct rlimit rlim; /* max number of open file descriptors */
1887 afs_uint32 rx_bindhost;
1889 #ifdef AFS_AIX32_ENV
1890 struct sigaction nsa;
1892 sigemptyset(&nsa.sa_mask);
1893 nsa.sa_handler = SIG_DFL;
1894 nsa.sa_flags = SA_FULLDUMP;
1895 sigaction(SIGABRT, &nsa, NULL);
1896 sigaction(SIGSEGV, &nsa, NULL);
1900 /* Initialize dirpaths */
1901 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
1903 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
1905 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
1909 #ifndef AFS_QUIETFS_ENV
1910 console = afs_fopen("/dev/console", "w");
1913 if (ParseArgs(argc, argv)) {
1917 #ifdef AFS_PTHREAD_ENV
1918 assert(pthread_mutex_init(&fileproc_glock_mutex, NULL) == 0);
1919 #endif /* AFS_PTHREAD_ENV */
1921 #ifdef AFS_SGI_VNODE_GLUE
1922 if (afs_init_kernel_config(-1) < 0) {
1924 ("Can't determine NUMA configuration, not starting fileserver.\n");
1928 confDir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
1930 fprintf(stderr, "Unable to open config directory %s\n",
1931 AFSDIR_SERVER_ETC_DIRPATH);
1937 /* Open FileLog on stdout, stderr, fd 1 and fd2 (for perror), sigh. */
1938 #ifndef AFS_NT40_ENV
1939 serverLogSyslogTag = "fileserver";
1941 OpenLog(AFSDIR_SERVER_FILELOG_FILEPATH);
1944 if (SawSpare && SawPctSpare) {
1945 ViceLog(0, ("Both -spare and -pctspare specified, exiting.\n"));
1948 #ifdef AFS_SGI_XFS_IOPS_ENV
1949 ViceLog(0, ("XFS/EFS File server starting\n"));
1951 ViceLog(0, ("File server starting\n"));
1954 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
1955 /* initialize the pthread soft signal handler thread */
1959 /* install signal handlers for controlling the fileserver process */
1960 ResetCheckSignal(); /* set CheckSignal_Signal() sig handler */
1961 ResetCheckDescriptors(); /* set CheckDescriptors_Signal() sig handler */
1963 #if defined(AFS_SGI_ENV)
1964 /* give this guy a non-degrading priority so help busy servers */
1965 schedctl(NDPRI, 0, NDPNORMMAX);
1969 #ifndef AFS_NT40_ENV
1970 nice(-5); /* TODO: */
1973 assert(DInit(buffs) == 0);
1976 if (afs_winsockInit() < 0) {
1977 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
1978 ViceLog(0, ("File server failed to intialize winsock.\n"));
1984 /* if we support more than 16 threads, then we better have the ability
1985 ** to keep open a large number of files simultaneously
1987 #if defined(AFS_AIX_ENV) && !defined(AFS_AIX42_ENV)
1988 curLimit = OPEN_MAX; /* for pre AIX 4.2 systems */
1989 #elif defined(AFS_NT40_ENV)
1990 curLimit = NT_OPEN_MAX; /* open file descriptor limit on NT */
1993 curLimit = 0; /* the number of open file descriptors */
1994 code = getrlimit(RLIMIT_NOFILE, &rlim);
1996 curLimit = rlim.rlim_cur;
1997 rlim.rlim_cur = rlim.rlim_max;
1998 code = setrlimit(RLIMIT_NOFILE, &rlim);
2000 curLimit = rlim.rlim_max;
2003 ViceLog(0, ("Failed to increase open file limit, using default\n"));
2005 #endif /* defined(AFS_AIX_ENV) && !defined(AFS_AIX42_ENV) */
2007 curLimit -= 32; /* leave a slack of 32 file descriptors */
2008 if (lwps > curLimit) {
2012 lwps = 16; /* default to a maximum of 16 threads */
2014 ("The system supports a max of %d open files and we are starting %d threads\n",
2017 #ifndef AFS_PTHREAD_ENV
2018 assert(LWP_InitializeProcessSupport(LWP_MAX_PRIORITY - 2, &parentPid) ==
2020 #endif /* !AFS_PTHREAD_ENV */
2022 /* Initialize volume support */
2024 V_BreakVolumeCallbacks = BreakVolumeCallBacksLater;
2027 #ifdef AFS_PTHREAD_ENV
2028 SetLogThreadNumProgram( threadNum );
2031 /* initialize libacl routines */
2032 acl_Initialize(ACL_VERSION);
2034 /* initialize RX support */
2035 #ifndef AFS_NT40_ENV
2036 rxi_syscallp = viced_syscall;
2038 rx_extraPackets = rxpackets;
2039 rx_extraQuota = 4; /* for outgoing prserver calls from R threads */
2040 rx_SetBusyThreshold(busy_threshold, VBUSY);
2041 rx_SetCallAbortThreshold(abort_threshold);
2042 rx_SetConnAbortThreshold(abort_threshold);
2044 stackSize = 128 * 1024;
2046 stackSize = lwps * 4000;
2047 if (stackSize < 32000)
2049 else if (stackSize > 44000)
2052 #if defined(AFS_HPUX_ENV) || defined(AFS_SUN_ENV) || defined(AFS_SGI51_ENV) || defined(AFS_XBSD_ENV)
2053 rx_SetStackSize(1, stackSize);
2056 rx_SetUdpBufSize(udpBufSize); /* set the UDP buffer size for receive */
2057 rx_bindhost = SetupVL();
2059 if (rx_InitHost(rx_bindhost, (int)htons(7000)) < 0) {
2060 ViceLog(0, ("Cannot initialize RX\n"));
2063 if (!rxJumbograms) {
2064 /* Don't send and don't allow 3.4 clients to send jumbograms. */
2067 if (rxMaxMTU != -1) {
2068 rx_SetMaxMTU(rxMaxMTU);
2071 rx_SetRxDeadTime(30);
2072 sc[0] = rxnull_NewServerSecurityObject();
2073 sc[1] = 0; /* rxvab_NewServerSecurityObject(key1, 0) */
2074 sc[2] = rxkad_NewServerSecurityObject(rxkad_clear, NULL, get_key, NULL);
2075 sc[3] = rxkad_NewServerSecurityObject(rxkad_crypt, NULL, get_key, NULL);
2076 tservice = rx_NewServiceHost(rx_bindhost, /* port */ 0, /* service id */
2077 1, /*service name */
2079 /* security classes */ sc,
2080 /* numb sec classes */
2081 4, RXAFS_ExecuteRequest);
2084 ("Failed to initialize RX, probably two servers running.\n"));
2087 if (rxkadDisableDotCheck) {
2088 rx_SetSecurityConfiguration(tservice, RXS_CONFIG_FLAGS,
2089 (void *)RXS_CONFIG_FLAGS_DISABLE_DOTCHECK);
2091 rx_SetMinProcs(tservice, 3);
2092 rx_SetMaxProcs(tservice, lwps);
2093 rx_SetCheckReach(tservice, 1);
2094 rx_SetServerIdleDeadErr(tservice, VNOSERVICE);
2097 rx_NewService(0, RX_STATS_SERVICE_ID, "rpcstats", sc, 4,
2098 RXSTATS_ExecuteRequest);
2100 ViceLog(0, ("Failed to initialize rpc stat service.\n"));
2103 rx_SetMinProcs(tservice, 2);
2104 rx_SetMaxProcs(tservice, 4);
2107 * Enable RX hot threads, which allows the listener thread to trade
2108 * places with an idle thread and moves the context switch from listener
2109 * to worker out of the critical path.
2111 rx_EnableHotThread();
2113 /* Some rx debugging */
2114 if (rxlog || eventlog) {
2115 debugFile = afs_fopen("rx_dbg", "w");
2117 rx_debugFile = debugFile;
2119 rxevent_debugFile = debugFile;
2122 init_sys_error_to_et(); /* Set up error table translation */
2123 h_InitHostPackage(); /* set up local cellname and realmname */
2124 InitCallBack(numberofcbs);
2128 if (code && code != VL_MULTIPADDR) {
2129 ViceLog(0, ("Fatal error in library initialization, exiting!!\n"));
2134 if (code && code != -1) {
2135 ViceLog(0, ("Fatal error in protection initialization, exiting!!\n"));
2139 /* allow super users to manage RX statistics */
2140 rx_SetRxStatUserOk(fs_rxstat_userok);
2142 #ifdef AFS_PTHREAD_ENV
2143 assert(pthread_cond_init(&fsync_cond, NULL) == 0);
2144 assert(pthread_mutex_init(&fsync_glock_mutex, NULL) == 0);
2147 #if !defined(AFS_DEMAND_ATTACH_FS)
2149 * For DAFS, we do not start the Rx server threads until after
2150 * the volume package is initialized, and fileserver state is
2151 * restored. This is necessary in order to keep host and callback
2152 * package state pristine until we have a chance to restore state.
2154 * Furthermore, startup latency is much lower with dafs, so this
2155 * shouldn't pose a serious problem.
2157 rx_StartServer(0); /* now start handling requests */
2160 /* we ensure that there is enough space in the vnode buffer to satisfy
2161 ** requests from all concurrent threads.
2162 ** the maximum number of vnodes used by a single thread at any one time
2163 ** is three ( "link" uses three vnodes simultaneously, one vLarge and
2164 ** two vSmall for linking files and two vLarge and one vSmall for linking
2167 minVnodesRequired = 2 * lwps + 1;
2168 if (minVnodesRequired > nSmallVns) {
2169 nSmallVns = minVnodesRequired;
2171 ("Overriding -s command line parameter with %d\n",
2174 if (minVnodesRequired > large) {
2175 large = minVnodesRequired;
2176 ViceLog(0, ("Overriding -l command line parameter with %d\n", large));
2179 /* We now do this after getting the listener up and running, so that client
2180 * connections don't timeout (maybe) if a file server is restarted, since it
2181 * will be available "real soon now". Worry about whether we can satisfy the
2182 * calls in the volume package itself.
2184 if (VInitVolumePackage(fileServer, large, nSmallVns, 0, volcache)) {
2186 ("Shutting down: errors encountered initializing volume package\n"));
2191 #ifdef AFS_DEMAND_ATTACH_FS
2192 if (fs_state.options.fs_state_restore) {
2195 * restore fileserver state */
2198 rx_StartServer(0); /* now start handling requests */
2199 #endif /* AFS_DEMAND_ATTACH_FS */
2202 * We are done calling fopen/fdopen. It is safe to use a large
2203 * of the file descriptor cache.
2207 #ifdef AFS_PTHREAD_ENV
2208 ViceLog(5, ("Starting pthreads\n"));
2209 #ifdef AFS_DEMAND_ATTACH_FS
2212 assert(pthread_attr_init(&tattr) == 0);
2213 assert(pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED) == 0);
2215 assert(pthread_create
2216 (&serverPid, &tattr, FiveMinuteCheckLWP,
2217 &fiveminutes) == 0);
2218 assert(pthread_create
2219 (&serverPid, &tattr, HostCheckLWP, &fiveminutes) == 0);
2220 assert(pthread_create
2221 (&serverPid, &tattr, FsyncCheckLWP, &fiveminutes) == 0);
2222 #else /* AFS_PTHREAD_ENV */
2223 ViceLog(5, ("Starting LWP\n"));
2224 assert(LWP_CreateProcess
2225 (FiveMinuteCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
2226 (void *)&fiveminutes, "FiveMinuteChecks",
2227 &serverPid) == LWP_SUCCESS);
2229 assert(LWP_CreateProcess
2230 (HostCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
2231 (void *)&fiveminutes, "HostCheck", &serverPid) == LWP_SUCCESS);
2232 assert(LWP_CreateProcess
2233 (FsyncCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
2234 (void *)&fiveminutes, "FsyncCheck", &serverPid) == LWP_SUCCESS);
2235 #endif /* AFS_PTHREAD_ENV */
2237 FT_GetTimeOfDay(&tp, 0);
2239 #ifndef AFS_QUIETFS_ENV
2240 if (console != NULL) {
2241 time_t t = tp.tv_sec;
2242 fprintf(console, "File server has started at %s\r",
2243 afs_ctime(&t, tbuffer, sizeof(tbuffer)));
2248 * Figure out the FileServer's name and primary address.
2250 ViceLog(0, ("Getting FileServer name...\n"));
2251 code = gethostname(FS_HostName, 64);
2253 ViceLog(0, ("gethostname() failed\n"));
2255 ViceLog(0, ("FileServer host name is '%s'\n", FS_HostName));
2257 ViceLog(0, ("Getting FileServer address...\n"));
2258 he = gethostbyname(FS_HostName);
2260 ViceLog(0, ("Can't find address for FileServer '%s'\n", FS_HostName));
2263 memcpy(&FS_HostAddr_NBO, he->h_addr, 4);
2264 (void)afs_inet_ntoa_r(FS_HostAddr_NBO, hoststr);
2265 FS_HostAddr_HBO = ntohl(FS_HostAddr_NBO);
2267 ("FileServer %s has address %s (0x%x or 0x%x in host byte order)\n",
2268 FS_HostName, hoststr, FS_HostAddr_NBO, FS_HostAddr_HBO));
2271 /* Install handler to catch the shutdown signal;
2272 * bosserver assumes SIGQUIT shutdown
2274 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
2275 softsig_signal(SIGQUIT, ShutDown_Signal);
2277 (void)signal(SIGQUIT, ShutDown_Signal);
2282 ("File Server started %s",
2283 afs_ctime(&t, tbuffer, sizeof(tbuffer))));
2284 #if FS_STATS_DETAILED
2285 afs_FullPerfStats.det.epoch.tv_sec = StartTime = tp.tv_sec;
2287 #ifdef AFS_PTHREAD_ENV
2289 sleep(1000); /* long time */
2291 #else /* AFS_PTHREAD_ENV */
2292 assert(LWP_WaitProcess(&parentPid) == LWP_SUCCESS);
2293 #endif /* AFS_PTHREAD_ENV */