2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
9 * Portions Copyright (c) 2006 Sine Nomine Associates
12 /* viced.c - File Server main loop */
16 /* Function - This routine has the initialization code for */
19 /* ********************************************************************** */
21 #include <afsconfig.h>
22 #include <afs/param.h>
30 #include <sys/types.h>
31 #include <afs/procmgmt.h> /* signal(), kill(), wait(), etc. */
37 #include <WINNT/afsevent.h>
40 #include <netinet/in.h>
42 #include <unistd.h> /* sysconf() */
54 #endif /* ITIMER_REAL */
55 #include <sys/resource.h>
56 #endif /* AFS_NT40_ENV */
61 #ifdef AFS_PTHREAD_ENV
63 #else /* AFS_PTHREAD_ENV */
64 #include <afs/assert.h>
65 #endif /* AFS_PTHREAD_ENV */
68 #include <afs/ptclient.h>
69 #include <afs/afsint.h>
70 #include <afs/vldbint.h>
71 #include <afs/errors.h>
72 #include <afs/ihandle.h>
73 #include <afs/vnode.h>
74 #include <afs/volume.h>
76 #include <afs/cellconfig.h>
78 #include <afs/prs_fs.h>
82 #include <afs/afs_args.h>
83 #include <afs/vlserver.h>
84 #include <afs/afsutil.h>
85 #include <afs/fileutil.h>
86 #include <afs/ptuser.h>
87 #include <afs/audit.h>
88 #include <afs/partition.h>
90 #include <afs/netutils.h>
94 #ifdef AFS_PTHREAD_ENV
97 #if defined(AFS_SGI_ENV)
98 #include "sys/schedctl.h"
101 #include <rx/rx_globals.h>
104 #define afs_stat stat64
105 #define afs_fstat fstat64
106 #define afs_open open64
107 #define afs_fopen fopen64
108 #else /* !O_LARGEFILE */
109 #define afs_stat stat
110 #define afs_fstat fstat
111 #define afs_open open
112 #define afs_fopen fopen
113 #endif /* !O_LARGEFILE */
115 extern int BreakVolumeCallBacks(), InitCallBack();
116 extern int BreakVolumeCallBacks(), InitCallBack(), BreakLaterCallBacks();
117 extern int BreakVolumeCallBacksLater();
118 extern int LogLevel, etext;
119 extern afs_int32 BlocksSpare, PctSpare;
122 static void ClearXStatValues(), NewParms(), PrintCounters();
123 static void ResetCheckDescriptors(void), ResetCheckSignal(void);
124 static int CheckSignal(void);
125 extern int GetKeysFromToken();
126 extern int RXAFS_ExecuteRequest();
127 extern int RXSTATS_ExecuteRequest();
128 afs_int32 Do_VLRegisterRPC();
130 int eventlog = 0, rxlog = 0;
132 FILE *console = NULL;
134 #ifdef AFS_PTHREAD_ENV
135 pthread_mutex_t fsync_glock_mutex;
136 pthread_cond_t fsync_cond;
139 #endif /* AFS_PTHREAD_ENV */
142 #define AFS_QUIETFS_ENV 1
143 #define NT_OPEN_MAX 1024 /* This is an arbitrary no. we came up with for
144 * now. We hope this will be replaced by a more
145 * intelligent estimate later. */
148 int SystemId; /* ViceID of "Administrators" */
149 int SystemAnyUser; /* Viceid of "System:AnyUser" */
150 prlist SystemAnyUserCPS; /* CPS for "system:AnyUser */
151 int AnonymousID = 0; /* ViceId of "Anonymous" */
152 prlist AnonCPS; /* CPS for "Anonymous" */
154 struct afsconf_dir *confDir; /* Configuration dir object */
156 int restartMode = RESTART_ORDINARY;
158 int Testing = 0; /* for ListViceInodes */
161 * Home for the performance statistics.
163 struct afs_PerfStats afs_perfstats;
166 extern int Statistics;
174 int rxJumbograms = 1; /* default is to send and receive jumbograms. */
175 int rxBind = 0; /* don't bind */
177 afs_int32 implicitAdminRights = PRSFS_LOOKUP; /* The ADMINISTER right is
179 afs_int32 readonlyServer = 0;
182 int stackSize = 24000;
183 int fiveminutes = 300; /* 5 minutes. Change this for debugging only */
184 int CurrentConnections = 0;
185 int hostaclRefresh = 7200; /* refresh host clients' acls every 2 hrs */
186 #if defined(AFS_SGI_ENV)
191 int rxpackets = 150; /* 100 */
192 int nSmallVns = 400; /* 200 */
193 int large = 400; /* 200 */
194 int volcache = 400; /* 400 */
195 int numberofcbs = 60000; /* 60000 */
196 int lwps = 9; /* 6 */
197 int buffs = 90; /* 70 */
198 int novbc = 0; /* Enable Volume Break calls */
199 int busy_threshold = 600;
200 int abort_threshold = 10;
201 int udpBufSize = 0; /* UDP buffer size for receive */
202 int sendBufSize = 16384; /* send buffer size */
206 #ifdef AFS_PTHREAD_ENV
207 pthread_key_t viced_uclient_key;
210 #ifdef AFS_PTHREAD_ENV
211 pthread_key_t viced_uclient_key;
214 #ifdef AFS_PTHREAD_ENV
215 pthread_key_t viced_uclient_key;
219 * FileServer's name and IP address, both network byte order and
222 #define ADDRSPERSITE 16 /* Same global is in rx/rx_user.c */
224 char FS_HostName[128] = "localhost";
225 afs_uint32 FS_HostAddr_NBO;
226 afs_uint32 FS_HostAddr_HBO;
227 afs_uint32 FS_HostAddrs[ADDRSPERSITE], FS_HostAddr_cnt = 0, FS_registered = 0;
228 /* All addresses in FS_HostAddrs are in NBO */
231 static void FlagMsg();
233 #ifdef AFS_DEMAND_ATTACH_FS
236 * fileserver mode support
238 * during fileserver shutdown, we have to track the graceful shutdown of
239 * certain background threads before we are allowed to dump state to
242 struct fs_state fs_state =
249 PTHREAD_COND_INITIALIZER,
250 PTHREAD_RWLOCK_INITIALIZER
252 #endif /* AFS_DEMAND_ATTACH_FS */
255 * Home for the performance statistics.
263 struct afs_stat status;
264 register int tsize = getdtablesize();
266 for (i = 0; i < tsize; i++) {
267 if (afs_fstat(i, &status) != -1) {
268 printf("%d: dev %x, inode %u, length %u, type/mode %x\n", i,
269 status.st_dev, status.st_ino, status.st_size,
274 ResetCheckDescriptors();
277 } /*CheckDescriptors */
280 #ifdef AFS_PTHREAD_ENV
282 CheckSignal_Signal(x)
294 CheckDescriptors_Signal(x)
298 #else /* AFS_PTHREAD_ENV */
300 CheckSignal_Signal(x)
302 IOMGR_SoftSig(CheckSignal, 0);
308 IOMGR_SoftSig(ShutDown, 0);
312 CheckDescriptors_Signal(x)
314 IOMGR_SoftSig(CheckDescriptors, 0);
316 #endif /* AFS_PTHREAD_ENV */
318 /* check whether caller is authorized to manage RX statistics */
320 fs_rxstat_userok(struct rx_call *call)
322 return afsconf_SuperUser(confDir, call, NULL);
326 ResetCheckSignal(void)
330 #if defined(AFS_HPUX_ENV)
333 #if defined(AFS_NT40_ENV)
340 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
341 softsig_signal(signo, CheckSignal_Signal);
343 signal(signo, CheckSignal_Signal);
348 ResetCheckDescriptors(void)
351 #if defined(AFS_PTHREAD_ENV)
352 softsig_signal(SIGTERM, CheckDescriptors_Signal);
354 (void)signal(SIGTERM, CheckDescriptors_Signal);
359 #if defined(AFS_PTHREAD_ENV)
363 return pthread_getspecific(rx_thread_id_key);
367 /* proc called by rxkad module to get a key */
369 get_key(char *arock, register afs_int32 akvno, char *akey)
372 static struct afsconf_key tkey;
373 register afs_int32 code;
376 ViceLog(0, ("conf dir not open\n"));
379 code = afsconf_GetKey(confDir, akvno, tkey.key);
381 ViceLog(0, ("afsconf_GetKey failure: kvno %d code %d\n", akvno, code));
384 memcpy(akey, tkey.key, sizeof(tkey.key));
391 viced_syscall(afs_uint32 a3, afs_uint32 a4, void *a5)
396 #ifndef AFS_LINUX20_ENV
397 old = (void (*)())signal(SIGSYS, SIG_IGN);
399 rcode = syscall(AFS_SYSCALL, 28 /* AFSCALL_CALL */ , a3, a4, a5);
400 #ifndef AFS_LINUX20_ENV
408 #if !defined(AFS_NT40_ENV)
409 #include "AFS_component_version_number.c"
410 #endif /* !AFS_NT40_ENV */
412 #define MAXADMINNAME 64
413 char adminName[MAXADMINNAME];
419 struct afs_stat status;
421 if ((afs_stat("/AdminName", &status)) || /* if file does not exist */
422 (status.st_size <= 0) || /* or it is too short */
423 (status.st_size >= (MAXADMINNAME)) || /* or it is too long */
424 !(fd = afs_open("/AdminName", O_RDONLY, 0))) { /* or the open fails */
425 strcpy(adminName, "System:Administrators"); /* use the default name */
427 (void)read(fd, adminName, status.st_size); /* use name from the file */
430 close(fd); /* close fd if it was opened */
432 } /*CheckAdminName */
438 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
439 /* set our 'thread-id' so that the host hold table works */
440 MUTEX_ENTER(&rx_stats_mutex); /* protects rxi_pthread_hinum */
442 pthread_setspecific(rx_thread_id_key, (void *)rxi_pthread_hinum);
443 MUTEX_EXIT(&rx_stats_mutex);
445 ("Set thread id %d for '%s'\n",
446 pthread_getspecific(rx_thread_id_key), s));
450 /* This LWP does things roughly every 5 minutes */
457 ViceLog(1, ("Starting five minute check process\n"));
458 setThreadId("FiveMinuteCheckLWP");
460 #ifdef AFS_DEMAND_ATTACH_FS
462 while (fs_state.mode == FS_MODE_NORMAL) {
463 fs_state.FiveMinuteLWP_tranquil = 1;
469 #ifdef AFS_PTHREAD_ENV
471 #else /* AFS_PTHREAD_ENV */
472 IOMGR_Sleep(fiveminutes);
473 #endif /* AFS_PTHREAD_ENV */
475 #ifdef AFS_DEMAND_ATTACH_FS
477 if (fs_state.mode != FS_MODE_NORMAL) {
480 fs_state.FiveMinuteLWP_tranquil = 0;
484 /* close the log so it can be removed */
485 ReOpenLog(AFSDIR_SERVER_FILELOG_FILEPATH); /* don't trunc, just append */
486 ViceLog(2, ("Cleaning up timed out callbacks\n"));
487 if (CleanupTimedOutCallBacks())
488 ViceLog(5, ("Timed out callbacks deleted\n"));
489 ViceLog(2, ("Set disk usage statistics\n"));
491 if (FS_registered == 1)
493 /* Force wakeup in case we missed something; pthreads does timedwait */
494 #ifndef AFS_PTHREAD_ENV
495 LWP_NoYieldSignal(fsync_wait);
497 if (printBanner && (++msg & 1)) { /* Every 10 minutes */
498 time_t now = FT_ApproxTime();
499 if (console != NULL) {
500 #ifndef AFS_QUIETFS_ENV
501 fprintf(console, "File server is running at %s\r",
502 afs_ctime(&now, tbuffer, sizeof(tbuffer)));
503 #endif /* AFS_QUIETFS_ENV */
505 ("File server is running at %s\n",
506 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
509 #ifdef AFS_DEMAND_ATTACH_FS
513 #ifdef AFS_DEMAND_ATTACH_FS
514 fs_state.FiveMinuteLWP_tranquil = 1;
516 assert(pthread_cond_broadcast(&fs_state.worker_done_cv)==0);
520 } /*FiveMinuteCheckLWP */
523 /* This LWP does host checks every 5 minutes: it should not be used for
524 * other 5 minute activities because it may be delayed by timeouts when
525 * it probes the workstations
531 ViceLog(1, ("Starting Host check process\n"));
532 setThreadId("HostCheckLWP");
533 #ifdef AFS_DEMAND_ATTACH_FS
535 while (fs_state.mode == FS_MODE_NORMAL) {
536 fs_state.HostCheckLWP_tranquil = 1;
542 #ifdef AFS_PTHREAD_ENV
544 #else /* AFS_PTHREAD_ENV */
545 IOMGR_Sleep(fiveminutes);
546 #endif /* AFS_PTHREAD_ENV */
548 #ifdef AFS_DEMAND_ATTACH_FS
550 if (fs_state.mode != FS_MODE_NORMAL) {
553 fs_state.HostCheckLWP_tranquil = 0;
557 ViceLog(2, ("Checking for dead venii & clients\n"));
560 #ifdef AFS_DEMAND_ATTACH_FS
564 #ifdef AFS_DEMAND_ATTACH_FS
565 fs_state.HostCheckLWP_tranquil = 1;
567 assert(pthread_cond_broadcast(&fs_state.worker_done_cv)==0);
573 /* This LWP does fsync checks every 5 minutes: it should not be used for
574 * other 5 minute activities because it may be delayed by timeouts when
575 * it probes the workstations
581 #ifdef AFS_PTHREAD_ENV
582 struct timespec fsync_next;
584 ViceLog(1, ("Starting fsync check process\n"));
586 setThreadId("FsyncCheckLWP");
588 #ifdef AFS_PTHREAD_ENV
589 assert(pthread_cond_init(&fsync_cond, NULL) == 0);
590 assert(pthread_mutex_init(&fsync_glock_mutex, NULL) == 0);
593 #ifdef AFS_DEMAND_ATTACH_FS
595 while (fs_state.mode == FS_MODE_NORMAL) {
596 fs_state.FsyncCheckLWP_tranquil = 1;
602 #ifdef AFS_PTHREAD_ENV
603 /* rounding is fine */
604 fsync_next.tv_nsec = 0;
605 fsync_next.tv_sec = time(0) + fiveminutes;
608 pthread_cond_timedwait(&fsync_cond, &fsync_glock_mutex,
610 if (code != 0 && code != ETIMEDOUT)
611 ViceLog(0, ("pthread_cond_timedwait returned %d\n", code));
612 #else /* AFS_PTHREAD_ENV */
613 if ((code = LWP_WaitProcess(fsync_wait)) != LWP_SUCCESS)
614 ViceLog(0, ("LWP_WaitProcess returned %d\n", code));
615 #endif /* AFS_PTHREAD_ENV */
618 #ifdef AFS_DEMAND_ATTACH_FS
620 if (fs_state.mode != FS_MODE_NORMAL) {
623 fs_state.FsyncCheckLWP_tranquil = 0;
625 #endif /* AFS_DEMAND_ATTACH_FS */
627 ViceLog(2, ("Checking for fsync events\n"));
629 code = BreakLaterCallBacks();
631 #ifdef AFS_DEMAND_ATTACH_FS
635 #ifdef AFS_DEMAND_ATTACH_FS
636 fs_state.FsyncCheckLWP_tranquil = 1;
638 assert(pthread_cond_broadcast(&fs_state.worker_done_cv)==0);
641 #endif /* AFS_DEMAND_ATTACH_FS */
644 /*------------------------------------------------------------------------
645 * PRIVATE ClearXStatValues
648 * Initialize all of the values collected via the xstat
658 * Must be called during File Server initialization.
662 *------------------------------------------------------------------------*/
666 { /*ClearXStatValues */
668 struct fs_stats_opTimingData *opTimeP; /*Ptr to timing struct */
669 struct fs_stats_xferData *opXferP; /*Ptr to xfer struct */
670 int i; /*Loop counter */
673 * Zero all xstat-related structures.
675 memset((char *)(&afs_perfstats), 0, sizeof(struct afs_PerfStats));
676 #if FS_STATS_DETAILED
677 memset((char *)(&afs_FullPerfStats), 0,
678 sizeof(struct fs_stats_FullPerfStats));
681 * That's not enough. We have to set reasonable minima for
682 * time and xfer values in the detailed stats.
684 opTimeP = &(afs_FullPerfStats.det.rpcOpTimes[0]);
685 for (i = 0; i < FS_STATS_NUM_RPC_OPS; i++, opTimeP++)
686 opTimeP->minTime.tv_sec = 999999;
688 opXferP = &(afs_FullPerfStats.det.xferOpTimes[0]);
689 for (i = 0; i < FS_STATS_NUM_XFER_OPS; i++, opXferP++) {
690 opXferP->minTime.tv_sec = 999999;
691 opXferP->minBytes = 999999999;
695 * There's more. We have to set our unique system identifier, as
696 * declared in param.h. If such a thing is not defined, we bitch
697 * and declare ourselves to be an unknown system type.
700 afs_perfstats.sysname_ID = SYS_NAME_ID;
703 ViceLog(0, ("Sys name ID constant not defined in param.h!!\n"));
704 ViceLog(0, ("[Choosing ``undefined'' sys name ID.\n"));
706 afs_perfstats.sysname_ID = SYS_NAME_ID_UNDEFINED;
707 #endif /* SYS_NAME_ID */
710 } /*ClearXStatValues */
716 int dirbuff, dircall, dirio;
718 int workstations, activeworkstations, delworkstations;
722 TM_GetTimeOfDay(&tpl, 0);
725 ("Vice was last started at %s\n",
726 afs_ctime(&StartTime, tbuffer, sizeof(tbuffer))));
728 #ifdef AFS_DEMAND_ATTACH_FS
729 /* XXX perhaps set extended stats verbosity flags
730 * based upon LogLevel ?? */
731 VPrintExtendedCacheStats(VOL_STATS_PER_CHAIN2);
735 DStat(&dirbuff, &dircall, &dirio);
737 ("With %d directory buffers; %d reads resulted in %d read I/Os\n",
738 dirbuff, dircall, dirio));
739 rx_PrintStats(stderr);
741 PrintCallBackStats();
743 processSize = -1; /* TODO: */
745 processSize = (int)((long)sbrk(0) >> 10);
748 ("There are %d connections, process size %d\n",
749 CurrentConnections, processSize));
750 h_GetWorkStats(&workstations, &activeworkstations, &delworkstations,
751 tpl.tv_sec - 15 * 60);
753 ("There are %d workstations, %d are active (req in < 15 mins), %d marked \"down\"\n",
754 workstations, activeworkstations, delworkstations));
764 if (FS_registered > 0) {
766 * We have proper ip addresses; tell the vlserver what we got; the following
767 * routine will do the proper reporting for us
780 ShutDownAndCore(int dopanic)
782 time_t now = time(0);
785 /* do not allows new reqests to be served from now on, all new requests
786 * are returned with an error code of RX_RESTARTING ( transient failure ) */
787 rx_SetRxTranquil(); /* dhruba */
789 #ifdef AFS_DEMAND_ATTACH_FS
791 fs_state.mode = FS_MODE_SHUTDOWN;
796 ("Shutting down file server at %s",
797 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
799 ViceLog(0, ("ABNORMAL SHUTDOWN, see core file.\n"));
800 #ifndef AFS_QUIETFS_ENV
801 if (console != NULL) {
802 fprintf(console, "File server restart/shutdown received at %s\r",
803 afs_ctime(&now, tbuffer, sizeof(tbuffer)));
810 /* shut down volume package */
813 #ifdef AFS_DEMAND_ATTACH_FS
814 if (fs_state.options.fs_state_save) {
817 * save fileserver state to disk */
819 /* make sure background threads have finished all of their asynchronous
820 * work on host and callback structures */
822 while (!fs_state.FiveMinuteLWP_tranquil ||
823 !fs_state.HostCheckLWP_tranquil ||
824 !fs_state.FsyncCheckLWP_tranquil) {
827 ViceLog(0, ("waiting for background host/callback threads to quiesce before saving fileserver state...\n"));
828 assert(pthread_cond_wait(&fs_state.worker_done_cv, &fileproc_glock_mutex) == 0);
833 /* ok. it should now be fairly safe. let's do the state dump */
836 #endif /* AFS_DEMAND_ATTACH_FS */
839 rx_PrintStats(debugFile);
842 if (console != NULL) {
845 #ifndef AFS_QUIETFS_ENV
846 fprintf(console, "File server has terminated abnormally at %s\r",
847 afs_ctime(&now, tbuffer, sizeof(tbuffer)));
850 ("File server has terminated abnormally at %s\n",
851 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
853 #ifndef AFS_QUIETFS_ENV
854 fprintf(console, "File server has terminated normally at %s\r",
855 afs_ctime(&now, tbuffer, sizeof(tbuffer)));
858 ("File server has terminated normally at %s\n",
859 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
868 { /* backward compatibility */
869 ShutDownAndCore(DONTPANIC);
879 /* default supports help flag */
881 strcpy(buffer, "Usage: fileserver ");
882 strcpy(buffer, "[-auditlog <log path>] ");
883 strcat(buffer, "[-d <debug level>] ");
884 strcat(buffer, "[-p <number of processes>] ");
885 strcat(buffer, "[-spare <number of spare blocks>] ");
886 strcat(buffer, "[-pctspare <percentage spare>] ");
887 strcat(buffer, "[-b <buffers>] ");
888 strcat(buffer, "[-l <large vnodes>] ");
889 strcat(buffer, "[-s <small vnodes>] ");
890 strcat(buffer, "[-vc <volume cachesize>] ");
891 strcat(buffer, "[-w <call back wait interval>] ");
892 strcat(buffer, "[-cb <number of call backs>] ");
893 strcat(buffer, "[-banner (print banner every 10 minutes)] ");
894 strcat(buffer, "[-novbc (whole volume cbs disabled)] ");
895 strcat(buffer, "[-implicit <admin mode bits: rlidwka>] ");
896 strcat(buffer, "[-readonly (read-only file server)] ");
898 "[-hr <number of hours between refreshing the host cps>] ");
899 strcat(buffer, "[-busyat <redirect clients when queue > n>] ");
900 strcat(buffer, "[-nobusy <no VBUSY before a volume is attached>] ");
901 strcat(buffer, "[-rxpck <number of rx extra packets>] ");
902 strcat(buffer, "[-rxdbg (enable rx debugging)] ");
903 strcat(buffer, "[-rxdbge (enable rxevent debugging)] ");
904 strcat(buffer, "[-rxmaxmtu <bytes>] ");
905 strcat(buffer, "[-rxbind (bind the Rx socket to one address)] ");
906 #ifdef AFS_DEMAND_ATTACH_FS
907 strcat(buffer, "[-fs-state-dont-save (disable state save during shutdown)] ");
908 strcat(buffer, "[-fs-state-dont-restore (disable state restore during startup)] ");
909 strcat(buffer, "[-fs-state-verify <none|save|restore|both> (default is both)] ");
910 strcat(buffer, "[-vattachpar <max number of volume attach/shutdown threads> (default is 1)] ");
911 strcat(buffer, "[-vhashsize <log(2) of number of volume hash buckets> (default is 8)] ");
912 strcat(buffer, "[-vlrudisable (disable VLRU functionality)] ");
913 strcat(buffer, "[-vlruthresh <minutes before unused volumes become eligible for soft detach> (default is 2 hours)] ");
914 strcat(buffer, "[-vlruinterval <seconds between VLRU scans> (default is 2 minutes)] ");
915 strcat(buffer, "[-vlrumax <max volumes to soft detach in one VLRU scan> (default is 8)] ");
916 #elif AFS_PTHREAD_ENV
917 strcat(buffer, "[-vattachpar <number of volume attach threads> (default is 1)] ");
920 strcat(buffer, "[-m <min percentage spare in partition>] ");
922 #if defined(AFS_SGI_ENV)
923 strcat(buffer, "[-lock (keep fileserver from swapping)] ");
925 strcat(buffer, "[-L (large server conf)] ");
926 strcat(buffer, "[-S (small server conf)] ");
927 strcat(buffer, "[-k <stack size>] ");
928 strcat(buffer, "[-realm <Kerberos realm name>] ");
929 strcat(buffer, "[-udpsize <size of socket buffer in bytes>] ");
930 strcat(buffer, "[-sendsize <size of send buffer in bytes>] ");
931 strcat(buffer, "[-abortthreshold <abort threshold>] ");
932 /* strcat(buffer, "[-enable_peer_stats] "); */
933 /* strcat(buffer, "[-enable_process_stats] "); */
934 strcat(buffer, "[-help]\n");
936 ViceLog(0, ("%s", buffer));
939 printf("%s", buffer);
946 ParseRights(char *arights)
952 if (!arights || !strcmp(arights, "")) {
953 printf("Missing list of mode bits on -implicit option\n");
956 if (!strcmp(arights, "none"))
958 else if (!strcmp(arights, "read"))
959 mode = PRSFS_READ | PRSFS_LOOKUP;
960 else if (!strcmp(arights, "write"))
962 PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
963 PRSFS_WRITE | PRSFS_LOCK;
964 else if (!strcmp(arights, "all"))
966 PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
967 PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER;
969 len = strlen(arights);
970 for (i = 0; i < len; i++) {
975 mode |= PRSFS_LOOKUP;
977 mode |= PRSFS_INSERT;
979 mode |= PRSFS_DELETE;
985 mode |= PRSFS_ADMINISTER;
1003 printf("Illegal -implicit rights character '%c'.\n", tc);
1012 * Limit MAX_FILESERVER_THREAD by the system limit on the number of
1013 * pthreads (sysconf(_SC_THREAD_THREADS_MAX)), if applicable and
1016 * AIX: sysconf() limit is real
1017 * HP-UX: sysconf() limit is real
1018 * IRIX: sysconf() limit is apparently NOT real -- too small
1019 * DUX: sysconf() limit is apparently NOT real -- too big
1020 * Linux: sysconf() limit is apparently NOT real -- too big
1021 * Solaris: no sysconf() limit
1024 max_fileserver_thread(void)
1026 #if defined(AFS_PTHREAD_ENV)
1027 #if defined(AFS_AIX_ENV) || defined(AFS_HPUX_ENV)
1030 ans = sysconf(_SC_THREAD_THREADS_MAX);
1031 if (0 < ans && ans < MAX_FILESERVER_THREAD)
1034 #endif /* defined(AFS_PTHREAD_ENV) */
1035 return MAX_FILESERVER_THREAD;
1039 ParseArgs(int argc, char *argv[])
1041 int SawL = 0, SawS = 0, SawVC = 0;
1042 int Sawrxpck = 0, Sawsmall = 0, Sawlarge = 0, Sawcbs = 0, Sawlwps =
1046 int bufSize = 0; /* temp variable to read in udp socket buf size */
1048 for (i = 1; i < argc; i++) {
1049 if (!strcmp(argv[i], "-d")) {
1050 if ((i + 1) >= argc) {
1051 fprintf(stderr, "missing argument for -d\n");
1054 debuglevel = atoi(argv[++i]);
1055 LogLevel = debuglevel;
1056 } else if (!strcmp(argv[i], "-banner")) {
1058 } else if (!strcmp(argv[i], "-implicit")) {
1059 if ((i + 1) >= argc) {
1060 fprintf(stderr, "missing argument for -implicit\n");
1063 implicitAdminRights = ParseRights(argv[++i]);
1064 if (implicitAdminRights < 0)
1065 return implicitAdminRights;
1066 } else if (!strcmp(argv[i], "-readonly")) {
1068 } else if (!strcmp(argv[i], "-L")) {
1070 } else if (!strcmp(argv[i], "-S")) {
1072 } else if (!strcmp(argv[i], "-p")) {
1074 max_fileserver_thread() - FILESERVER_HELPER_THREADS;
1076 if ((i + 1) >= argc) {
1077 fprintf(stderr, "missing argument for -p\n");
1080 lwps = atoi(argv[++i]);
1081 if (lwps > lwps_max)
1085 } else if (!strcmp(argv[i], "-b")) {
1087 if ((i + 1) >= argc) {
1088 fprintf(stderr, "missing argument for -b\n");
1091 buffs = atoi(argv[++i]);
1092 } else if (!strcmp(argv[i], "-l")) {
1094 if ((i + 1) >= argc) {
1095 fprintf(stderr, "missing argument for -l\n");
1098 large = atoi(argv[++i]);
1099 } else if (!strcmp(argv[i], "-vc")) {
1101 if ((i + 1) >= argc) {
1102 fprintf(stderr, "missing argument for -vc\n");
1105 volcache = atoi(argv[++i]);
1106 } else if (!strcmp(argv[i], "-novbc")) {
1108 } else if (!strcmp(argv[i], "-rxpck")) {
1110 if ((i + 1) >= argc) {
1111 fprintf(stderr, "missing argument for -rxpck\n");
1114 rxpackets = atoi(argv[++i]);
1115 #ifdef AFS_PTHREAD_ENV
1116 } else if (!strcmp(argv[i], "-vattachpar")) {
1117 if ((i + 1) >= argc) {
1118 fprintf(stderr, "missing argument for %s\n", argv[i]);
1121 vol_attach_threads = atoi(argv[++i]);
1122 #endif /* AFS_PTHREAD_ENV */
1123 #ifdef AFS_DEMAND_ATTACH_FS
1124 } else if (!strcmp(argv[i], "-fs-state-dont-save")) {
1125 fs_state.options.fs_state_save = 0;
1126 } else if (!strcmp(argv[i], "-fs-state-dont-restore")) {
1127 fs_state.options.fs_state_restore = 0;
1128 } else if (!strcmp(argv[i], "-fs-state-verify")) {
1129 if ((i + 1) >= argc) {
1130 fprintf(stderr, "missing argument for %s\n", argv[i]);
1134 if (!strcmp(argv[i], "none")) {
1135 fs_state.options.fs_state_verify_before_save = 0;
1136 fs_state.options.fs_state_verify_after_restore = 0;
1137 } else if (!strcmp(argv[i], "save")) {
1138 fs_state.options.fs_state_verify_after_restore = 0;
1139 } else if (!strcmp(argv[i], "restore")) {
1140 fs_state.options.fs_state_verify_before_save = 0;
1141 } else if (!strcmp(argv[i], "both")) {
1144 fprintf(stderr, "invalid argument for %s\n", argv[i-1]);
1147 } else if (!strcmp(argv[i], "-vhashsize")) {
1148 if ((i + 1) >= argc) {
1149 fprintf(stderr, "missing argument for %s\n", argv[i]);
1152 VSetVolHashSize(atoi(argv[++i]));
1153 } else if (!strcmp(argv[i], "-vlrudisable")) {
1154 VLRU_SetOptions(VLRU_SET_ENABLED, 0);
1155 } else if (!strcmp(argv[i], "-vlruthresh")) {
1156 if ((i + 1) >= argc) {
1157 fprintf(stderr, "missing argument for %s\n", argv[i]);
1160 VLRU_SetOptions(VLRU_SET_THRESH, 60*atoi(argv[++i]));
1161 } else if (!strcmp(argv[i], "-vlruinterval")) {
1162 if ((i + 1) >= argc) {
1163 fprintf(stderr, "missing argument for %s\n", argv[i]);
1166 VLRU_SetOptions(VLRU_SET_INTERVAL, atoi(argv[++i]));
1167 } else if (!strcmp(argv[i], "-vlrumax")) {
1168 if ((i + 1) >= argc) {
1169 fprintf(stderr, "missing argument for %s\n", argv[i]);
1172 VLRU_SetOptions(VLRU_SET_MAX, atoi(argv[++i]));
1173 #endif /* AFS_DEMAND_ATTACH_FS */
1174 } else if (!strcmp(argv[i], "-s")) {
1176 if ((i + 1) >= argc) {
1177 fprintf(stderr, "missing argument for -s\n");
1180 nSmallVns = atoi(argv[++i]);
1181 } else if (!strcmp(argv[i], "-abortthreshold")) {
1182 if ((i + 1) >= argc) {
1183 fprintf(stderr, "missing argument for -abortthreshold\n");
1186 abort_threshold = atoi(argv[++i]);
1187 } else if (!strcmp(argv[i], "-k")) {
1188 if ((i + 1) >= argc) {
1189 fprintf(stderr, "missing argument for -k\n");
1192 stack = atoi(argv[++i]);
1194 #if defined(AFS_SGI_ENV)
1195 else if (!strcmp(argv[i], "-lock")) {
1199 else if (!strcmp(argv[i], "-spare")) {
1200 if ((i + 1) >= argc) {
1201 fprintf(stderr, "missing argument for -spare\n");
1204 BlocksSpare = atoi(argv[++i]);
1206 } else if (!strcmp(argv[i], "-pctspare")) {
1207 if ((i + 1) >= argc) {
1208 fprintf(stderr, "missing argument for -pctspare\n");
1211 PctSpare = atoi(argv[++i]);
1212 BlocksSpare = 0; /* has non-zero default */
1214 } else if (!strcmp(argv[i], "-w")) {
1215 if ((i + 1) >= argc) {
1216 fprintf(stderr, "missing argument for -w\n");
1219 fiveminutes = atoi(argv[++i]);
1220 } else if (!strcmp(argv[i], "-hr")) {
1222 if ((i + 1) >= argc) {
1223 fprintf(stderr, "missing argument for -hr\n");
1226 hr = atoi(argv[++i]);
1227 if ((hr < 1) || (hr > 36)) {
1229 ("host acl refresh interval of %d hours is invalid; hours must be between 1 and 36\n\n",
1233 hostaclRefresh = hr * 60 * 60;
1234 } else if (!strcmp(argv[i], "-rxdbg"))
1236 else if (!strcmp(argv[i], "-rxdbge"))
1238 else if (!strcmp(argv[i], "-cb")) {
1240 if ((i + 1) >= argc) {
1241 fprintf(stderr, "missing argument for -cb\n");
1244 numberofcbs = atoi(argv[++i]);
1245 if ((numberofcbs < 10000) || (numberofcbs > 2147483647)) {
1247 ("number of cbs %d invalid; must be between 10000 and 2147483647\n",
1251 } else if (!strcmp(argv[i], "-busyat")) {
1253 if ((i + 1) >= argc) {
1254 fprintf(stderr, "missing argument for -busyat\n");
1257 busy_threshold = atoi(argv[++i]);
1258 if (busy_threshold < 10) {
1260 ("Busy threshold %d is too low, will compute default.\n",
1264 } else if (!strcmp(argv[i], "-nobusy"))
1266 #ifdef AFS_AIX32_ENV
1267 else if (!strcmp(argv[i], "-m")) {
1268 extern int aixlow_water;
1269 if ((i + 1) >= argc) {
1270 fprintf(stderr, "missing argument for -m\n");
1273 aixlow_water = atoi(argv[++i]);
1274 if ((aixlow_water < 0) || (aixlow_water > 30)) {
1275 printf("space reserved %d% invalid; must be between 0-30%\n",
1281 else if (!strcmp(argv[i], "-nojumbo")) {
1283 } else if (!strcmp(argv[i], "-rxbind")) {
1285 } else if (!strcmp(argv[i], "-rxmaxmtu")) {
1286 if ((i + 1) >= argc) {
1287 fprintf(stderr, "missing argument for -rxmaxmtu\n");
1290 rxMaxMTU = atoi(argv[++i]);
1291 if ((rxMaxMTU < RX_MIN_PACKET_SIZE) ||
1292 (rxMaxMTU > RX_MAX_PACKET_DATA_SIZE)) {
1293 printf("rxMaxMTU %d%% invalid; must be between %d-%d\n",
1294 rxMaxMTU, RX_MIN_PACKET_SIZE,
1295 RX_MAX_PACKET_DATA_SIZE);
1298 } else if (!strcmp(argv[i], "-realm")) {
1299 extern char local_realms[AFS_NUM_LREALMS][AFS_REALM_SZ];
1300 extern int num_lrealms;
1301 if ((i + 1) >= argc) {
1302 fprintf(stderr, "missing argument for -realm\n");
1305 if (strlen(argv[++i]) >= AFS_REALM_SZ) {
1307 ("-realm argument must contain fewer than %d characters.\n",
1311 if (num_lrealms == -1)
1313 if (num_lrealms >= AFS_NUM_LREALMS) {
1315 ("a maximum of %d -realm arguments can be specified.\n",
1319 strncpy(local_realms[num_lrealms++], argv[i], AFS_REALM_SZ);
1320 } else if (!strcmp(argv[i], "-udpsize")) {
1321 if ((i + 1) >= argc) {
1322 printf("You have to specify -udpsize <integer value>\n");
1325 bufSize = atoi(argv[++i]);
1326 if (bufSize < rx_GetMinUdpBufSize())
1328 ("Warning:udpsize %d is less than minimum %d; ignoring\n",
1329 bufSize, rx_GetMinUdpBufSize());
1331 udpBufSize = bufSize;
1332 } else if (!strcmp(argv[i], "-sendsize")) {
1333 if ((i + 1) >= argc) {
1334 printf("You have to specify -sendsize <integer value>\n");
1337 bufSize = atoi(argv[++i]);
1338 if (bufSize < 16384)
1340 ("Warning:sendsize %d is less than minimum %d; ignoring\n",
1343 sendBufSize = bufSize;
1344 } else if (!strcmp(argv[i], "-enable_peer_stats")) {
1345 rx_enablePeerRPCStats();
1346 } else if (!strcmp(argv[i], "-enable_process_stats")) {
1347 rx_enableProcessRPCStats();
1349 else if (strcmp(argv[i], "-auditlog") == 0) {
1352 char oldName[MAXPATHLEN];
1353 char *fileName = argv[++i];
1355 #ifndef AFS_NT40_ENV
1356 struct stat statbuf;
1358 if ((lstat(fileName, &statbuf) == 0)
1359 && (S_ISFIFO(statbuf.st_mode))) {
1360 flags = O_WRONLY | O_NONBLOCK;
1364 strcpy(oldName, fileName);
1365 strcat(oldName, ".old");
1366 renamefile(fileName, oldName);
1367 flags = O_WRONLY | O_TRUNC | O_CREAT;
1369 tempfd = open(fileName, flags, 0666);
1371 auditout = fdopen(tempfd, "a");
1373 osi_audit_file(auditout);
1375 printf("Warning: auditlog %s not writable, ignored.\n", fileName);
1377 printf("Warning: auditlog %s not writable, ignored.\n", fileName);
1379 #ifndef AFS_NT40_ENV
1380 else if (strcmp(argv[i], "-syslog") == 0) {
1381 /* set syslog logging flag */
1382 serverLogSyslog = 1;
1383 } else if (strncmp(argv[i], "-syslog=", 8) == 0) {
1384 serverLogSyslog = 1;
1385 serverLogSyslogFacility = atoi(argv[i] + 8);
1388 else if (strcmp(argv[i], "-mrafslogs") == 0) {
1389 /* set syslog logging flag */
1397 printf("Only one of -L, or -S must be specified\n");
1408 numberofcbs = 20000;
1424 numberofcbs = 64000;
1433 busy_threshold = 3 * rxpackets / 2;
1443 NewParms(int initializing)
1445 static struct afs_stat sbuf;
1448 char *argv[MAXPARMS];
1451 if (!(afs_stat("/vice/file/parms", &sbuf))) {
1452 parms = (char *)malloc(sbuf.st_size);
1455 fd = afs_open("parms", O_RDONLY, 0666);
1457 ViceLog(0, ("Open for parms failed with errno = %d\n", errno));
1461 i = read(fd, parms, sbuf.st_size);
1463 if (i != sbuf.st_size) {
1465 ViceLog(0, ("Read on parms failed with errno = %d\n", errno));
1468 ("Read on parms failed; expected %d bytes but read %d\n",
1475 for (i = 0; i < MAXPARMS; argv[i++] = 0);
1477 for (argc = i = 0; i < sbuf.st_size; i++) {
1478 if ((*(parms + i) != ' ') && (*(parms + i) != '\n')) {
1479 if (argv[argc] == 0)
1480 argv[argc] = (parms + i);
1482 *(parms + i) = '\0';
1483 if (argv[argc] != 0) {
1484 if (++argc == MAXPARMS)
1487 while ((*(parms + i + 1) == ' ')
1488 || (*(parms + i + 1) == '\n'))
1492 if (ParseArgs(argc, argv) == 0) {
1493 ViceLog(0, ("Change parameters to:"));
1495 ViceLog(0, ("Invalid parameter in:"));
1497 for (i = 0; i < argc; i++) {
1498 ViceLog(0, (" %s", argv[i]));
1502 } else if (!initializing)
1504 ("Received request to change parms but no parms file exists\n"));
1509 /* Miscellaneous routines */
1513 ViceLog(0, ("%s\n", msg));
1525 * If this fails, it's because something major is wrong, and is not
1526 * likely to be time dependent.
1528 code = pr_Initialize(2, AFSDIR_SERVER_ETC_DIRPATH, 0);
1531 ("Couldn't initialize protection library; code=%d.\n", code));
1535 #ifdef AFS_PTHREAD_ENV
1536 assert(pthread_key_create(&viced_uclient_key, NULL) == 0);
1539 SystemId = SYSADMINID;
1540 SystemAnyUser = ANYUSERID;
1541 SystemAnyUserCPS.prlist_len = 0;
1542 SystemAnyUserCPS.prlist_val = NULL;
1543 AnonCPS.prlist_len = 0;
1544 AnonCPS.prlist_val = NULL;
1546 code = pr_GetCPS(SystemAnyUser, &SystemAnyUserCPS);
1549 ("Couldn't get CPS for AnyUser, will try again in 30 seconds; code=%d.\n",
1553 code = pr_GetCPS(ANONYMOUSID, &AnonCPS);
1556 ("Couldn't get Anonymous CPS, exiting; code=%d.\n",
1560 AnonymousID = ANONYMOUSID;
1563 #ifdef AFS_PTHREAD_ENV
1565 #else /* AFS_PTHREAD_ENV */
1567 #endif /* AFS_PTHREAD_ENV */
1571 struct rx_connection *serverconns[MAXSERVERS];
1572 struct ubik_client *cstruct;
1575 vl_Initialize(const char *confDir)
1577 afs_int32 code, scIndex = 0, i;
1578 struct afsconf_dir *tdir;
1579 struct rx_securityClass *sc;
1580 struct afsconf_cell info;
1582 tdir = afsconf_Open(confDir);
1585 ("Could not open configuration directory (%s).\n", confDir));
1588 code = afsconf_ClientAuth(tdir, &sc, &scIndex);
1590 ViceLog(0, ("Could not get security object for localAuth\n"));
1593 code = afsconf_GetCellInfo(tdir, NULL, AFSCONF_VLDBSERVICE, &info);
1594 if (info.numServers > MAXSERVERS) {
1596 ("vl_Initialize: info.numServers=%d (> MAXSERVERS=%d)\n",
1597 info.numServers, MAXSERVERS));
1600 for (i = 0; i < info.numServers; i++)
1602 rx_NewConnection(info.hostAddr[i].sin_addr.s_addr,
1603 info.hostAddr[i].sin_port, USER_SERVICE_ID, sc,
1605 code = ubik_ClientInit(serverconns, &cstruct);
1607 ViceLog(0, ("vl_Initialize: ubik client init failed.\n"));
1613 #define SYSIDMAGIC 0x88aabbcc
1614 #define SYSIDVERSION 1
1619 afs_int32 fd, nentries, i;
1620 struct versionStamp vsn;
1621 struct afs_stat status;
1624 if ((afs_stat(AFSDIR_SERVER_SYSID_FILEPATH, &status))
1625 || (status.st_size <= 0)) {
1626 ViceLog(0, ("%s: doesn't exist\n", AFSDIR_SERVER_SYSID_FILEPATH));
1629 if (!(fd = afs_open(AFSDIR_SERVER_SYSID_FILEPATH, O_RDONLY, 0))) {
1631 ("%s: can't open (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1635 if ((i = read(fd, (char *)&vsn, sizeof(vsn))) != sizeof(vsn)) {
1637 ("%s: Read failed (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1641 if (vsn.magic != SYSIDMAGIC) {
1643 ("%s: wrong magic %x (we support %x)\n",
1644 AFSDIR_SERVER_SYSID_FILEPATH, vsn.magic, SYSIDMAGIC));
1647 if (vsn.version != SYSIDVERSION) {
1649 ("%s: wrong version %d (we support %d)\n",
1650 AFSDIR_SERVER_SYSID_FILEPATH, vsn.version, SYSIDVERSION));
1654 read(fd, (char *)&uuid,
1655 sizeof(struct afsUUID))) != sizeof(struct afsUUID)) {
1657 ("%s: read of uuid failed (%d)\n",
1658 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1661 afs_ntohuuid(&uuid);
1664 read(fd, (char *)&nentries,
1665 sizeof(afs_int32))) != sizeof(afs_int32)) {
1667 ("%s: Read of entries failed (%d)\n",
1668 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1671 if (nentries <= 0 || nentries > ADDRSPERSITE) {
1673 ("%s: invalid num of interfaces: %d\n",
1674 AFSDIR_SERVER_SYSID_FILEPATH, nentries));
1677 FS_HostAddr_cnt = nentries;
1678 for (i = 0; i < nentries; i++) {
1679 if (read(fd, (char *)&FS_HostAddrs[i], sizeof(afs_int32)) !=
1680 sizeof(afs_int32)) {
1682 ("%s: Read of addresses failed (%d)\n",
1683 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1684 FS_HostAddr_cnt = 0; /* reset it */
1696 struct versionStamp vsn;
1697 struct afs_stat status;
1700 if (!afs_stat(AFSDIR_SERVER_SYSID_FILEPATH, &status)) {
1702 * File exists; keep the old one around
1704 renamefile(AFSDIR_SERVER_SYSID_FILEPATH,
1705 AFSDIR_SERVER_OLDSYSID_FILEPATH);
1707 fd = afs_open(AFSDIR_SERVER_SYSID_FILEPATH, O_WRONLY | O_TRUNC | O_CREAT,
1711 ("%s: can't create (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1715 vsn.magic = SYSIDMAGIC;
1717 if ((i = write(fd, (char *)&vsn, sizeof(vsn))) != sizeof(vsn)) {
1719 ("%s: write failed (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1724 afs_htonuuid(&uuid);
1726 write(fd, (char *)&uuid,
1727 sizeof(struct afsUUID))) != sizeof(struct afsUUID)) {
1729 ("%s: write of uuid failed (%d)\n",
1730 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1734 write(fd, (char *)&FS_HostAddr_cnt,
1735 sizeof(afs_int32))) != sizeof(afs_int32)) {
1737 ("%s: write of # of entries failed (%d)\n",
1738 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1741 for (i = 0; i < FS_HostAddr_cnt; i++) {
1742 if (write(fd, (char *)&FS_HostAddrs[i], sizeof(afs_int32)) !=
1743 sizeof(afs_int32)) {
1745 ("%s: write of addresses failed (%d)\n",
1746 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1756 * This routine sets up the buffers for the VL_RegisterAddrs RPC. All addresses
1757 * in FS_HostAddrs[] are in NBO, while the RPC treats them as a "blob" of data
1758 * and so we need to convert each of them into HBO which is what the extra
1759 * array called FS_HostAddrs_HBO is used here.
1766 extern int VL_RegisterAddrs();
1767 afs_uint32 FS_HostAddrs_HBO[ADDRSPERSITE];
1770 for (i = 0; i < FS_HostAddr_cnt; i++)
1771 FS_HostAddrs_HBO[i] = ntohl(FS_HostAddrs[i]);
1772 addrs.bulkaddrs_len = FS_HostAddr_cnt;
1773 addrs.bulkaddrs_val = (afs_uint32 *) FS_HostAddrs_HBO;
1774 code = ubik_VL_RegisterAddrs(cstruct, 0, &FS_HostUUID, 0, &addrs);
1776 if (code == VL_MULTIPADDR) {
1778 ("VL_RegisterAddrs rpc failed; The IP address exists on a different server; repair it\n"));
1780 ("VL_RegisterAddrs rpc failed; See VLLog for details\n"));
1782 } else if (code == RXGEN_OPCODE) {
1784 ("vlserver doesn't support VL_RegisterAddrs rpc; ignored\n"));
1785 FS_registered = 2; /* So we don't have to retry in the gc daemon */
1788 ("VL_RegisterAddrs rpc failed; will retry periodically (code=%d, err=%d)\n",
1792 FS_registered = 2; /* So we don't have to retry in the gc daemon */
1803 extern int rxi_numNetAddrs;
1804 extern afs_uint32 rxi_NetAddrs[];
1806 #ifndef AFS_NT40_ENV
1807 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH || AFSDIR_SERVER_NETINFO_FILEPATH) {
1809 * Find addresses we are supposed to register as per the netrestrict
1810 * and netinfo files (/usr/afs/local/NetInfo and
1811 * /usr/afs/local/NetRestict)
1814 afs_int32 code = parseNetFiles(FS_HostAddrs, NULL, NULL,
1815 ADDRSPERSITE, reason,
1816 AFSDIR_SERVER_NETINFO_FILEPATH,
1817 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
1819 ViceLog(0, ("Can't register any valid addresses: %s\n", reason));
1822 FS_HostAddr_cnt = (afs_uint32) code;
1826 FS_HostAddr_cnt = rx_getAllAddr(FS_HostAddrs, ADDRSPERSITE);
1829 if (FS_HostAddr_cnt == 1 && rxBind == 1)
1830 code = FS_HostAddrs[0];
1832 code = htonl(INADDR_ANY);
1842 * If this fails, it's because something major is wrong, and is not
1843 * likely to be time dependent.
1845 code = vl_Initialize(AFSDIR_SERVER_ETC_DIRPATH);
1848 ("Couldn't initialize protection library; code=%d.\n", code));
1852 /* Read or create the sysid file and register the fileserver's
1853 * IP addresses with the vlserver.
1855 code = ReadSysIdFile();
1857 /* Need to create the file */
1858 ViceLog(0, ("Creating new SysID file\n"));
1859 if ((code = afs_uuid_create(&FS_HostUUID))) {
1860 ViceLog(0, ("Failed to create new uuid: %d\n", code));
1864 /* A good sysid file exists; inform the vlserver. If any conflicts,
1865 * we always use the latest interface available as the real truth.
1868 code = Do_VLRegisterRPC();
1873 main(int argc, char *argv[])
1877 struct rx_securityClass *sc[4];
1878 struct rx_service *tservice;
1879 #ifdef AFS_PTHREAD_ENV
1880 pthread_t serverPid;
1881 pthread_attr_t tattr;
1882 #else /* AFS_PTHREAD_ENV */
1883 PROCESS parentPid, serverPid;
1884 #endif /* AFS_PTHREAD_ENV */
1886 int minVnodesRequired; /* min size of vnode cache */
1887 #ifndef AFS_NT40_ENV
1888 struct rlimit rlim; /* max number of open file descriptors */
1892 afs_uint32 rx_bindhost;
1894 #ifdef AFS_AIX32_ENV
1895 struct sigaction nsa;
1897 sigemptyset(&nsa.sa_mask);
1898 nsa.sa_handler = SIG_DFL;
1899 nsa.sa_flags = SA_FULLDUMP;
1900 sigaction(SIGABRT, &nsa, NULL);
1901 sigaction(SIGSEGV, &nsa, NULL);
1905 /* Initialize dirpaths */
1906 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
1908 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
1910 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
1914 #ifndef AFS_QUIETFS_ENV
1915 console = afs_fopen("/dev/console", "w");
1918 if (ParseArgs(argc, argv)) {
1922 #ifdef AFS_PTHREAD_ENV
1923 assert(pthread_mutex_init(&fileproc_glock_mutex, NULL) == 0);
1924 #endif /* AFS_PTHREAD_ENV */
1926 #ifdef AFS_SGI_VNODE_GLUE
1927 if (afs_init_kernel_config(-1) < 0) {
1929 ("Can't determine NUMA configuration, not starting fileserver.\n");
1933 confDir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
1935 fprintf(stderr, "Unable to open config directory %s\n",
1936 AFSDIR_SERVER_ETC_DIRPATH);
1942 /* Open FileLog on stdout, stderr, fd 1 and fd2 (for perror), sigh. */
1943 #ifndef AFS_NT40_ENV
1944 serverLogSyslogTag = "fileserver";
1946 OpenLog(AFSDIR_SERVER_FILELOG_FILEPATH);
1949 if (SawSpare && SawPctSpare) {
1950 ViceLog(0, ("Both -spare and -pctspare specified, exiting.\n"));
1953 #ifdef AFS_SGI_XFS_IOPS_ENV
1954 ViceLog(0, ("XFS/EFS File server starting\n"));
1956 ViceLog(0, ("File server starting\n"));
1959 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
1960 /* initialize the pthread soft signal handler thread */
1964 /* install signal handlers for controlling the fileserver process */
1965 ResetCheckSignal(); /* set CheckSignal_Signal() sig handler */
1966 ResetCheckDescriptors(); /* set CheckDescriptors_Signal() sig handler */
1968 #if defined(AFS_SGI_ENV)
1969 /* give this guy a non-degrading priority so help busy servers */
1970 schedctl(NDPRI, 0, NDPNORMMAX);
1974 #ifndef AFS_NT40_ENV
1975 nice(-5); /* TODO: */
1978 assert(DInit(buffs) == 0);
1981 if (afs_winsockInit() < 0) {
1982 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
1983 ViceLog(0, ("File server failed to intialize winsock.\n"));
1989 /* if we support more than 16 threads, then we better have the ability
1990 ** to keep open a large number of files simultaneously
1992 #if defined(AFS_AIX_ENV) && !defined(AFS_AIX42_ENV)
1993 curLimit = OPEN_MAX; /* for pre AIX 4.2 systems */
1994 #elif defined(AFS_NT40_ENV)
1995 curLimit = NT_OPEN_MAX; /* open file descriptor limit on NT */
1998 curLimit = 0; /* the number of open file descriptors */
1999 code = getrlimit(RLIMIT_NOFILE, &rlim);
2001 curLimit = rlim.rlim_cur;
2002 rlim.rlim_cur = rlim.rlim_max;
2003 code = setrlimit(RLIMIT_NOFILE, &rlim);
2005 curLimit = rlim.rlim_max;
2008 ViceLog(0, ("Failed to increase open file limit, using default\n"));
2010 #endif /* defined(AFS_AIX_ENV) && !defined(AFS_AIX42_ENV) */
2012 curLimit -= 32; /* leave a slack of 32 file descriptors */
2013 if (lwps > curLimit) {
2017 lwps = 16; /* default to a maximum of 16 threads */
2019 ("The system supports a max of %d open files and we are starting %d threads\n",
2022 #ifndef AFS_PTHREAD_ENV
2023 assert(LWP_InitializeProcessSupport(LWP_MAX_PRIORITY - 2, &parentPid) ==
2025 #endif /* !AFS_PTHREAD_ENV */
2027 /* Initialize volume support */
2029 V_BreakVolumeCallbacks = BreakVolumeCallBacksLater;
2032 #ifdef AFS_PTHREAD_ENV
2033 SetLogThreadNumProgram( threadNum );
2036 /* initialize libacl routines */
2037 acl_Initialize(ACL_VERSION);
2039 /* initialize RX support */
2040 #ifndef AFS_NT40_ENV
2041 rxi_syscallp = viced_syscall;
2043 rx_extraPackets = rxpackets;
2044 rx_extraQuota = 4; /* for outgoing prserver calls from R threads */
2045 rx_SetBusyThreshold(busy_threshold, VBUSY);
2046 rx_SetCallAbortThreshold(abort_threshold);
2047 rx_SetConnAbortThreshold(abort_threshold);
2048 stackSize = lwps * 4000;
2049 if (stackSize < 32000)
2051 else if (stackSize > 44000)
2053 #if defined(AFS_HPUX_ENV) || defined(AFS_SUN_ENV) || defined(AFS_SGI51_ENV)
2054 rx_SetStackSize(1, stackSize);
2057 rx_SetUdpBufSize(udpBufSize); /* set the UDP buffer size for receive */
2058 rx_bindhost = SetupVL();
2060 if (rx_InitHost(rx_bindhost, (int)htons(7000)) < 0) {
2061 ViceLog(0, ("Cannot initialize RX\n"));
2064 if (!rxJumbograms) {
2065 /* Don't send and don't allow 3.4 clients to send jumbograms. */
2068 if (rxMaxMTU != -1) {
2069 rx_SetMaxMTU(rxMaxMTU);
2072 rx_SetRxDeadTime(30);
2073 sc[0] = rxnull_NewServerSecurityObject();
2074 sc[1] = 0; /* rxvab_NewServerSecurityObject(key1, 0) */
2075 sc[2] = rxkad_NewServerSecurityObject(rxkad_clear, NULL, get_key, NULL);
2076 sc[3] = rxkad_NewServerSecurityObject(rxkad_crypt, NULL, get_key, NULL);
2077 tservice = rx_NewServiceHost(rx_bindhost, /* port */ 0, /* service id */
2078 1, /*service name */
2080 /* security classes */ sc,
2081 /* numb sec classes */
2082 4, RXAFS_ExecuteRequest);
2085 ("Failed to initialize RX, probably two servers running.\n"));
2088 rx_SetMinProcs(tservice, 3);
2089 rx_SetMaxProcs(tservice, lwps);
2090 rx_SetCheckReach(tservice, 1);
2093 rx_NewService(0, RX_STATS_SERVICE_ID, "rpcstats", sc, 4,
2094 RXSTATS_ExecuteRequest);
2096 ViceLog(0, ("Failed to initialize rpc stat service.\n"));
2099 rx_SetMinProcs(tservice, 2);
2100 rx_SetMaxProcs(tservice, 4);
2103 * Enable RX hot threads, which allows the listener thread to trade
2104 * places with an idle thread and moves the context switch from listener
2105 * to worker out of the critical path.
2107 rx_EnableHotThread();
2109 /* Some rx debugging */
2110 if (rxlog || eventlog) {
2111 debugFile = afs_fopen("rx_dbg", "w");
2113 rx_debugFile = debugFile;
2115 rxevent_debugFile = debugFile;
2118 init_sys_error_to_et(); /* Set up error table translation */
2119 h_InitHostPackage(); /* set up local cellname and realmname */
2120 InitCallBack(numberofcbs);
2125 ViceLog(0, ("Fatal error in library initialization, exiting!!\n"));
2131 ViceLog(0, ("Fatal error in protection initialization, exiting!!\n"));
2135 /* allow super users to manage RX statistics */
2136 rx_SetRxStatUserOk(fs_rxstat_userok);
2138 rx_StartServer(0); /* now start handling requests */
2140 /* we ensure that there is enough space in the vnode buffer to satisfy
2141 ** requests from all concurrent threads.
2142 ** the maximum number of vnodes used by a single thread at any one time
2143 ** is three ( "link" uses three vnodes simultaneously, one vLarge and
2144 ** two vSmall for linking files and two vLarge and one vSmall for linking
2147 minVnodesRequired = 2 * lwps + 1;
2148 if (minVnodesRequired > nSmallVns) {
2149 nSmallVns = minVnodesRequired;
2151 ("Overriding -s command line parameter with %d\n",
2154 if (minVnodesRequired > large) {
2155 large = minVnodesRequired;
2156 ViceLog(0, ("Overriding -l command line parameter with %d\n", large));
2159 /* We now do this after getting the listener up and running, so that client
2160 * connections don't timeout (maybe) if a file server is restarted, since it
2161 * will be available "real soon now". Worry about whether we can satisfy the
2162 * calls in the volume package itself.
2164 if (VInitVolumePackage(fileServer, large, nSmallVns, 0, volcache)) {
2166 ("Shutting down: errors encountered initializing volume package\n"));
2171 #ifdef AFS_DEMAND_ATTACH_FS
2172 if (fs_state.options.fs_state_restore) {
2175 * restore fileserver state */
2178 #endif /* AFS_DEMAND_ATTACH_FS */
2181 * We are done calling fopen/fdopen. It is safe to use a large
2182 * of the file descriptor cache.
2186 #ifdef AFS_PTHREAD_ENV
2187 ViceLog(5, ("Starting pthreads\n"));
2188 assert(pthread_attr_init(&tattr) == 0);
2189 assert(pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED) == 0);
2191 assert(pthread_create
2192 (&serverPid, &tattr, (void *)FiveMinuteCheckLWP,
2193 &fiveminutes) == 0);
2194 assert(pthread_create
2195 (&serverPid, &tattr, (void *)HostCheckLWP, &fiveminutes) == 0);
2196 assert(pthread_create
2197 (&serverPid, &tattr, (void *)FsyncCheckLWP, &fiveminutes) == 0);
2198 #else /* AFS_PTHREAD_ENV */
2199 ViceLog(5, ("Starting LWP\n"));
2200 assert(LWP_CreateProcess
2201 (FiveMinuteCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
2202 (void *)&fiveminutes, "FiveMinuteChecks",
2203 &serverPid) == LWP_SUCCESS);
2205 assert(LWP_CreateProcess
2206 (HostCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
2207 (void *)&fiveminutes, "HostCheck", &serverPid) == LWP_SUCCESS);
2208 assert(LWP_CreateProcess
2209 (FsyncCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
2210 (void *)&fiveminutes, "FsyncCheck", &serverPid) == LWP_SUCCESS);
2211 #endif /* AFS_PTHREAD_ENV */
2213 TM_GetTimeOfDay(&tp, 0);
2215 #ifndef AFS_QUIETFS_ENV
2216 if (console != NULL) {
2217 time_t t = tp.tv_sec;
2218 fprintf(console, "File server has started at %s\r",
2219 afs_ctime(&t, tbuffer, sizeof(tbuffer)));
2224 * Figure out the FileServer's name and primary address.
2226 ViceLog(0, ("Getting FileServer name...\n"));
2227 code = gethostname(FS_HostName, 64);
2229 ViceLog(0, ("gethostname() failed\n"));
2231 ViceLog(0, ("FileServer host name is '%s'\n", FS_HostName));
2233 ViceLog(0, ("Getting FileServer address...\n"));
2234 he = gethostbyname(FS_HostName);
2236 ViceLog(0, ("Can't find address for FileServer '%s'\n", FS_HostName));
2239 memcpy(&FS_HostAddr_NBO, he->h_addr, 4);
2240 (void)afs_inet_ntoa_r(FS_HostAddr_NBO, hoststr);
2241 FS_HostAddr_HBO = ntohl(FS_HostAddr_NBO);
2243 ("FileServer %s has address %s (0x%x or 0x%x in host byte order)\n",
2244 FS_HostName, hoststr, FS_HostAddr_NBO, FS_HostAddr_HBO));
2247 /* Install handler to catch the shutdown signal;
2248 * bosserver assumes SIGQUIT shutdown
2250 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
2251 softsig_signal(SIGQUIT, ShutDown_Signal);
2253 (void)signal(SIGQUIT, ShutDown_Signal);
2258 ("File Server started %s",
2259 afs_ctime(&t, tbuffer, sizeof(tbuffer))));
2260 #if FS_STATS_DETAILED
2261 afs_FullPerfStats.det.epoch.tv_sec = StartTime = tp.tv_sec;
2263 #ifdef AFS_PTHREAD_ENV
2265 sleep(1000); /* long time */
2267 #else /* AFS_PTHREAD_ENV */
2268 assert(LWP_WaitProcess(&parentPid) == LWP_SUCCESS);
2269 #endif /* AFS_PTHREAD_ENV */