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>
25 #include <afs/procmgmt.h>
30 # include <WINNT/afsevent.h>
33 #ifdef HAVE_SYS_FILE_H
34 # include <sys/file.h>
37 #ifdef HAVE_SYS_RESOURCE_H
38 # include <sys/resource.h>
48 #include <afs/ptclient.h>
49 #include <afs/afsint.h>
50 #include <afs/vldbint.h>
51 #include <afs/errors.h>
52 #include <afs/ihandle.h>
53 #include <afs/vnode.h>
54 #include <afs/volume.h>
56 #include <afs/cellconfig.h>
58 #include <afs/prs_fs.h>
60 #include <rx/rxstat.h>
62 #include <afs/afs_args.h>
63 #include <afs/vlserver.h>
64 #include <afs/afsutil.h>
65 #include <afs/fileutil.h>
66 #include <afs/ptuser.h>
67 #include <afs/audit.h>
68 #include <afs/partition.h>
71 # include <afs/softsig.h>
73 #include "viced_prototypes.h"
76 #if defined(AFS_SGI_ENV)
77 # include "sys/schedctl.h"
78 # include "sys/lock.h"
80 #include <rx/rx_globals.h>
84 void *ShutDown(void *);
85 static void ClearXStatValues(void);
86 static void PrintCounters(void);
87 static void ResetCheckDescriptors(void);
88 static void ResetCheckSignal(void);
89 static void *CheckSignal(void *);
91 static afs_int32 Do_VLRegisterRPC(void);
93 int eventlog = 0, rxlog = 0;
96 pthread_mutex_t fsync_glock_mutex;
97 pthread_cond_t fsync_cond;
100 # define NT_OPEN_MAX 1024 /* This is an arbitrary no. we came up with for
101 * now. We hope this will be replaced by a more
102 * intelligent estimate later. */
105 int SystemId; /* ViceID of "Administrators" */
106 int SystemAnyUser; /* Viceid of "System:AnyUser" */
107 prlist SystemAnyUserCPS; /* CPS for "system:AnyUser */
108 int AnonymousID = 0; /* ViceId of "Anonymous" */
109 prlist AnonCPS; /* CPS for "Anonymous" */
111 struct afsconf_dir *confDir; /* Configuration dir object */
113 int restartMode = RESTART_ORDINARY;
116 * Home for the performance statistics.
118 struct afs_PerfStats afs_perfstats;
121 extern int Statistics;
126 int rxJumbograms = 0; /* default is to not send and receive jumbograms. */
127 int rxBind = 0; /* don't bind */
128 int rxkadDisableDotCheck = 0; /* disable check for dot in principal name */
130 afs_int32 implicitAdminRights = PRSFS_LOOKUP; /* The ADMINISTER right is
132 afs_int32 readonlyServer = 0;
135 int stackSize = 24000;
136 int fiveminutes = 300; /* 5 minutes. Change this for debugging only */
137 int CurrentConnections = 0;
138 int hostaclRefresh = 7200; /* refresh host clients' acls every 2 hrs */
139 #if defined(AFS_SGI_ENV)
145 * seconds to wait until forcing a panic during ShutDownAndCore(PANIC)
146 * in case we get stuck.
148 #ifdef AFS_DEMAND_ATTACH_FS
149 static int panic_timeout = 2 * 60;
151 static int panic_timeout = 30 * 60;
154 int rxpackets = 150; /* 100 */
155 int nSmallVns = 400; /* 200 */
156 int large = 400; /* 200 */
157 int volcache = 400; /* 400 */
158 int numberofcbs = 60000; /* 60000 */
159 int lwps = 9; /* 6 */
160 int buffs = 90; /* 70 */
161 int novbc = 0; /* Enable Volume Break calls */
162 int busy_threshold = 600;
163 int abort_threshold = 10;
164 int udpBufSize = 0; /* UDP buffer size for receive */
165 int sendBufSize = 16384; /* send buffer size */
166 int saneacls = 0; /* Sane ACLs Flag */
167 static int unsafe_attach = 0; /* avoid inUse check on vol attach? */
168 static int offline_timeout = -1; /* -offline-timeout option */
169 static int offline_shutdown_timeout = -1; /* -offline-shutdown-timeout option */
173 pthread_key_t viced_uclient_key;
176 * FileServer's name and IP address, both network byte order and
179 #define ADDRSPERSITE 16 /* Same global is in rx/rx_user.c */
181 char FS_HostName[128] = "localhost";
182 char *FS_configPath = NULL;
183 afs_uint32 FS_HostAddr_NBO;
184 afs_uint32 FS_HostAddr_HBO;
185 afs_uint32 FS_HostAddrs[ADDRSPERSITE], FS_HostAddr_cnt = 0, FS_registered = 0;
186 /* All addresses in FS_HostAddrs are in NBO */
189 #ifdef AFS_DEMAND_ATTACH_FS
192 * fileserver mode support
194 * during fileserver shutdown, we have to track the graceful shutdown of
195 * certain background threads before we are allowed to dump state to
199 # if !defined(PTHREAD_RWLOCK_INITIALIZER) && defined(AFS_DARWIN80_ENV)
200 # define PTHREAD_RWLOCK_INITIALIZER {0x2DA8B3B4, {0}}
203 # ifndef AFS_NT40_ENV
204 struct fs_state fs_state =
211 PTHREAD_COND_INITIALIZER,
212 PTHREAD_RWLOCK_INITIALIZER
214 # else /* AFS_NT40_ENV */
215 struct fs_state fs_state;
217 static int fs_stateInit(void)
219 fs_state.mode = FS_MODE_NORMAL;
220 fs_state.FiveMinuteLWP_tranquil = 0;
221 fs_state.HostCheckLWP_tranquil = 0;
222 fs_state.FsyncCheckLWP_tranquil = 0;
223 fs_state.salvsync_fatal_error = 0;
225 fs_state.options.fs_state_save = 1;
226 fs_state.options.fs_state_restore = 1;
227 fs_state.options.fs_state_verify_before_save = 1;
228 fs_state.options.fs_state_verify_after_restore = 1;
230 CV_INIT(&fs_state.worker_done_cv, "worker done", CV_DEFAULT, 0);
231 osi_Assert(pthread_rwlock_init(&fs_state.state_lock, NULL) == 0);
233 # endif /* AFS_NT40_ENV */
234 #endif /* AFS_DEMAND_ATTACH_FS */
237 * Home for the performance statistics.
242 CheckDescriptors(void *unused)
245 struct afs_stat status;
246 int tsize = getdtablesize();
248 for (i = 0; i < tsize; i++) {
249 if (afs_fstat(i, &status) != -1) {
250 printf("%d: dev %x, inode %u, length %u, type/mode %x\n", i,
251 (unsigned int) status.st_dev,
252 (unsigned int) status.st_ino,
253 (unsigned int) status.st_size,
258 ResetCheckDescriptors();
261 } /*CheckDescriptors */
265 CheckSignal_Signal(int x)
271 ShutDown_Signal(int x)
277 CheckDescriptors_Signal(int x)
279 CheckDescriptors(NULL);
282 /* check whether caller is authorized to perform admin operations */
284 viced_SuperUser(struct rx_call *call)
286 return afsconf_SuperUser(confDir, call, NULL);
290 * Return true if this name is a member of the local realm.
293 fs_IsLocalRealmMatch(void *rock, char *name, char *inst, char *cell)
295 struct afsconf_dir *dir = (struct afsconf_dir *)rock;
296 afs_int32 islocal = 0; /* default to no */
299 code = afsconf_IsLocalRealmMatch(dir, &islocal, name, inst, cell);
302 ("Failed local realm check; code=%d, name=%s, inst=%s, cell=%s\n",
303 code, name, inst, cell));
309 ResetCheckSignal(void)
313 #if defined(AFS_HPUX_ENV)
315 #elif defined(AFS_NT40_ENV)
321 #if !defined(AFS_NT40_ENV)
322 softsig_signal(signo, CheckSignal_Signal);
324 signal(signo, CheckSignal_Signal);
329 ResetCheckDescriptors(void)
332 softsig_signal(SIGTERM, CheckDescriptors_Signal);
338 viced_syscall(afs_uint32 a3, afs_uint32 a4, void *a5)
341 # ifndef AFS_LINUX20_ENV
344 old = (void (*)(int))signal(SIGSYS, SIG_IGN);
346 rcode = syscall(AFS_SYSCALL, 28 /* AFSCALL_CALL */ , a3, a4, a5);
347 # ifndef AFS_LINUX20_ENV
355 #if !defined(AFS_NT40_ENV)
356 # include "AFS_component_version_number.c"
357 #endif /* !AFS_NT40_ENV */
359 #define MAXADMINNAME 64
360 char adminName[MAXADMINNAME];
366 struct afs_stat status;
368 if ((afs_stat("/AdminName", &status)) || /* if file does not exist */
369 (status.st_size <= 0) || /* or it is too short */
370 (status.st_size >= (MAXADMINNAME)) || /* or it is too long */
371 !(fd = afs_open("/AdminName", O_RDONLY, 0))) { /* or the open fails */
372 strcpy(adminName, "System:Administrators"); /* use the default name */
374 (void)read(fd, adminName, status.st_size); /* use name from the file */
377 close(fd); /* close fd if it was opened */
379 } /*CheckAdminName */
385 #if !defined(AFS_NT40_ENV)
388 /* set our 'thread-id' so that the host hold table works */
389 threadId = rx_SetThreadNum();
390 afs_pthread_setname_self(s);
391 ViceLog(0, ("Set thread id 0x%x for '%s'\n", threadId, s));
395 /* This LWP does things roughly every 5 minutes */
397 FiveMinuteCheckLWP(void *unused)
402 ViceLog(1, ("Starting five minute check process\n"));
403 setThreadId("FiveMinuteCheckLWP");
405 #ifdef AFS_DEMAND_ATTACH_FS
407 while (fs_state.mode == FS_MODE_NORMAL) {
408 fs_state.FiveMinuteLWP_tranquil = 1;
416 #ifdef AFS_DEMAND_ATTACH_FS
418 if (fs_state.mode != FS_MODE_NORMAL) {
421 fs_state.FiveMinuteLWP_tranquil = 0;
425 /* close the log so it can be removed */
426 ReOpenLog(AFSDIR_SERVER_FILELOG_FILEPATH); /* don't trunc, just append */
427 ViceLog(2, ("Cleaning up timed out callbacks\n"));
428 if (CleanupTimedOutCallBacks())
429 ViceLog(5, ("Timed out callbacks deleted\n"));
430 ViceLog(2, ("Set disk usage statistics\n"));
432 if (FS_registered == 1)
434 /* Force wakeup in case we missed something; pthreads does timedwait */
435 if (printBanner && (++msg & 1)) { /* Every 10 minutes */
436 time_t now = FT_ApproxTime();
438 strftime(tbuffer, sizeof(tbuffer), "%a %b %d %H:%M:%S %Y",
439 localtime_r(&now, &tm));
441 ("File server is running at %s\n", tbuffer));
443 #ifdef AFS_DEMAND_ATTACH_FS
447 #ifdef AFS_DEMAND_ATTACH_FS
448 fs_state.FiveMinuteLWP_tranquil = 1;
450 CV_BROADCAST(&fs_state.worker_done_cv);
455 } /*FiveMinuteCheckLWP */
458 /* This LWP does host checks every 5 minutes: it should not be used for
459 * other 5 minute activities because it may be delayed by timeouts when
460 * it probes the workstations
464 HostCheckLWP(void *unused)
466 ViceLog(1, ("Starting Host check process\n"));
467 setThreadId("HostCheckLWP");
468 #ifdef AFS_DEMAND_ATTACH_FS
470 while (fs_state.mode == FS_MODE_NORMAL) {
471 fs_state.HostCheckLWP_tranquil = 1;
479 #ifdef AFS_DEMAND_ATTACH_FS
481 if (fs_state.mode != FS_MODE_NORMAL) {
484 fs_state.HostCheckLWP_tranquil = 0;
488 ViceLog(2, ("Checking for dead venii & clients\n"));
491 #ifdef AFS_DEMAND_ATTACH_FS
495 #ifdef AFS_DEMAND_ATTACH_FS
496 fs_state.HostCheckLWP_tranquil = 1;
498 CV_BROADCAST(&fs_state.worker_done_cv);
505 /* This LWP does fsync checks every 5 minutes: it should not be used for
506 * other 5 minute activities because it may be delayed by timeouts when
507 * it probes the workstations
510 FsyncCheckLWP(void *unused)
513 struct timespec fsync_next;
514 ViceLog(1, ("Starting fsync check process\n"));
516 setThreadId("FsyncCheckLWP");
518 #ifdef AFS_DEMAND_ATTACH_FS
520 while (fs_state.mode == FS_MODE_NORMAL) {
521 fs_state.FsyncCheckLWP_tranquil = 1;
527 /* rounding is fine */
528 fsync_next.tv_nsec = 0;
529 fsync_next.tv_sec = time(0) + fiveminutes;
531 code = CV_TIMEDWAIT(&fsync_cond, &fsync_glock_mutex,
533 if (code != 0 && code != ETIMEDOUT)
534 ViceLog(0, ("pthread_cond_timedwait returned %d\n", code));
537 #ifdef AFS_DEMAND_ATTACH_FS
539 if (fs_state.mode != FS_MODE_NORMAL) {
542 fs_state.FsyncCheckLWP_tranquil = 0;
544 #endif /* AFS_DEMAND_ATTACH_FS */
546 ViceLog(2, ("Checking for fsync events\n"));
548 code = BreakLaterCallBacks();
550 #ifdef AFS_DEMAND_ATTACH_FS
554 #ifdef AFS_DEMAND_ATTACH_FS
555 fs_state.FsyncCheckLWP_tranquil = 1;
557 CV_BROADCAST(&fs_state.worker_done_cv);
560 #endif /* AFS_DEMAND_ATTACH_FS */
564 /*------------------------------------------------------------------------
565 * PRIVATE ClearXStatValues
568 * Initialize all of the values collected via the xstat
578 * Must be called during File Server initialization.
582 *------------------------------------------------------------------------*/
585 ClearXStatValues(void)
586 { /*ClearXStatValues */
588 struct fs_stats_opTimingData *opTimeP; /*Ptr to timing struct */
589 struct fs_stats_xferData *opXferP; /*Ptr to xfer struct */
590 int i; /*Loop counter */
593 * Zero all xstat-related structures.
595 memset((&afs_perfstats), 0, sizeof(struct afs_PerfStats));
596 memset((&afs_FullPerfStats), 0,
597 sizeof(struct fs_stats_FullPerfStats));
600 * That's not enough. We have to set reasonable minima for
601 * time and xfer values in the detailed stats.
603 opTimeP = &(afs_FullPerfStats.det.rpcOpTimes[0]);
604 for (i = 0; i < FS_STATS_NUM_RPC_OPS; i++, opTimeP++)
605 opTimeP->minTime.tv_sec = 999999;
607 opXferP = &(afs_FullPerfStats.det.xferOpTimes[0]);
608 for (i = 0; i < FS_STATS_NUM_XFER_OPS; i++, opXferP++) {
609 opXferP->minTime.tv_sec = 999999;
610 opXferP->minBytes = 999999999;
614 * There's more. We have to set our unique system identifier, as
615 * declared in param.h. If such a thing is not defined, we bitch
616 * and declare ourselves to be an unknown system type.
619 afs_perfstats.sysname_ID = SYS_NAME_ID;
621 # ifndef AFS_NT40_ENV
622 ViceLog(0, ("Sys name ID constant not defined in param.h!!\n"));
623 ViceLog(0, ("[Choosing ``undefined'' sys name ID.\n"));
625 afs_perfstats.sysname_ID = SYS_NAME_ID_UNDEFINED;
626 # endif /* SYS_NAME_ID */
628 } /*ClearXStatValues */
630 int CopyOnWrite_calls = 0, CopyOnWrite_off0 = 0, CopyOnWrite_size0 = 0;
631 afs_fsize_t CopyOnWrite_maxsize = 0;
636 int dirbuff, dircall, dirio;
638 int workstations, activeworkstations, delworkstations;
642 #ifdef AFS_DEMAND_ATTACH_FS
646 FT_GetTimeOfDay(&tpl, 0);
648 strftime(tbuffer, sizeof(tbuffer), "%a %b %d %H:%M:%S %Y",
649 localtime_r(&StartTime, &tm));
650 ViceLog(0, ("Vice was last started at %s\n", tbuffer));
652 #ifdef AFS_DEMAND_ATTACH_FS
653 if (LogLevel >= 125) {
654 stats_flags = VOL_STATS_PER_CHAIN2;
655 } else if (LogLevel >= 25) {
656 stats_flags = VOL_STATS_PER_CHAIN;
658 VPrintExtendedCacheStats(stats_flags);
662 DStat(&dirbuff, &dircall, &dirio);
664 ("With %d directory buffers; %d reads resulted in %d read I/Os\n",
665 dirbuff, dircall, dirio));
666 rx_PrintStats(stderr);
667 audit_PrintStats(stderr);
669 PrintCallBackStats();
671 processSize = -1; /* TODO: */
673 processSize = (int)((long)sbrk(0) >> 10);
676 ("There are %d connections, process size %d\n",
677 CurrentConnections, processSize));
678 h_GetWorkStats(&workstations, &activeworkstations, &delworkstations,
679 tpl.tv_sec - 15 * 60);
681 ("There are %d workstations, %d are active (req in < 15 mins), %d marked \"down\"\n",
682 workstations, activeworkstations, delworkstations));
683 ViceLog(0, ("CopyOnWrite: calls %d off0 %d size0 %d maxsize 0x%llx\n",
684 CopyOnWrite_calls, CopyOnWrite_off0, CopyOnWrite_size0, CopyOnWrite_maxsize));
693 CheckSignal(void *unused)
695 if (FS_registered > 0) {
697 * We have proper ip addresses; tell the vlserver what we got; the following
698 * routine will do the proper reporting for us
711 ShutdownWatchdogLWP(void *unused)
713 afs_pthread_setname_self("ShutdownWatchdog");
714 sleep(panic_timeout);
715 ViceLogThenPanic(0, ("ShutdownWatchdogLWP: Failed to shutdown and panic "
716 "within %d seconds; forcing panic\n",
722 ShutDownAndCore(int dopanic)
724 time_t now = time(NULL);
729 pthread_t watchdogPid;
730 pthread_attr_t tattr;
731 osi_Assert(pthread_attr_init(&tattr) == 0);
732 osi_Assert(pthread_create(&watchdogPid, &tattr, ShutdownWatchdogLWP, NULL) == 0);
735 /* do not allows new reqests to be served from now on, all new requests
736 * are returned with an error code of RX_RESTARTING ( transient failure ) */
737 rx_SetRxTranquil(); /* dhruba */
741 #ifdef AFS_DEMAND_ATTACH_FS
743 if (fs_state.mode == FS_MODE_SHUTDOWN) {
744 /* it is possible for at least fs_stateSave() (called below) to call
745 * ShutDownAndCore if there's host list corruption; prevent
746 * deinitializing some stuff twice */
747 ViceLog(0, ("ShutDownAndCore called during shutdown? Skipping volume "
748 "and host package shutdown\n"));
752 fs_state.mode = FS_MODE_SHUTDOWN;
756 strftime(tbuffer, sizeof(tbuffer), "%a %b %d %H:%M:%S %Y",
757 localtime_r(&now, &tm));
758 ViceLog(0, ("Shutting down file server at %s\n", tbuffer));
760 ViceLog(0, ("ABNORMAL SHUTDOWN, see core file.\n"));
765 /* shut down volume package */
768 #ifdef AFS_DEMAND_ATTACH_FS
769 if (fs_state.options.fs_state_save) {
772 * save fileserver state to disk */
775 ViceLog(0, ("Not saving fileserver state; abnormal shutdown\n"));
778 /* make sure background threads have finished all of their asynchronous
779 * work on host and callback structures */
781 while (!fs_state.FiveMinuteLWP_tranquil ||
782 !fs_state.HostCheckLWP_tranquil ||
783 !fs_state.FsyncCheckLWP_tranquil) {
786 ViceLog(0, ("waiting for background host/callback threads to quiesce before saving fileserver state...\n"));
787 CV_WAIT(&fs_state.worker_done_cv, &fileproc_glock_mutex);
793 /* ok. it should now be fairly safe. let's do the state dump */
799 #endif /* AFS_DEMAND_ATTACH_FS */
802 rx_PrintStats(debugFile);
806 strftime(tbuffer, sizeof(tbuffer), "%a %b %d %H:%M:%S %Y",
807 localtime_r(&now, &tm));
809 ViceLog(0, ("File server has terminated abnormally at %s\n", tbuffer));
811 ViceLog(0, ("File server has terminated normally at %s\n", tbuffer));
814 if (dopanic) /* XXX pass in file and line? */
815 osi_Panic("Panic requested\n");
821 ShutDown(void *unused)
822 { /* backward compatibility */
823 ShutDownAndCore(DONTPANIC);
828 ParseRights(char *arights)
834 if (!arights || !strcmp(arights, "")) {
835 printf("Missing list of mode bits on -implicit option\n");
838 if (!strcmp(arights, "none"))
840 else if (!strcmp(arights, "read"))
841 mode = PRSFS_READ | PRSFS_LOOKUP;
842 else if (!strcmp(arights, "write"))
844 PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
845 PRSFS_WRITE | PRSFS_LOCK;
846 else if (!strcmp(arights, "all"))
848 PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
849 PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER;
851 len = strlen(arights);
852 for (i = 0; i < len; i++) {
857 mode |= PRSFS_LOOKUP;
859 mode |= PRSFS_INSERT;
861 mode |= PRSFS_DELETE;
867 mode |= PRSFS_ADMINISTER;
885 printf("Illegal -implicit rights character '%c'.\n", tc);
894 * Limit MAX_FILESERVER_THREAD by the system limit on the number of
895 * pthreads (sysconf(_SC_THREAD_THREADS_MAX)), if applicable and
898 * AIX: sysconf() limit is real
899 * HP-UX: sysconf() limit is real
900 * IRIX: sysconf() limit is apparently NOT real -- too small
901 * DUX: sysconf() limit is apparently NOT real -- too big
902 * Linux: sysconf() limit is apparently NOT real -- too big
903 * Solaris: no sysconf() limit
906 max_fileserver_thread(void)
908 #if defined(AFS_AIX_ENV) || defined(AFS_HPUX_ENV)
911 ans = sysconf(_SC_THREAD_THREADS_MAX);
912 if (0 < ans && ans < MAX_FILESERVER_THREAD)
915 return MAX_FILESERVER_THREAD;
919 extern ih_init_params vol_io_params;
944 OPT_offline_shutdown_timeout,
945 OPT_vhandle_setaside,
946 OPT_vhandle_max_cachesize,
947 OPT_vhandle_initial_cachesize,
948 OPT_fs_state_dont_save,
949 OPT_fs_state_dont_restore,
956 OPT_unsafe_nosalvage,
983 ParseArgs(int argc, char *argv[])
987 char *optstring = NULL;
988 struct cmd_item *optlist;
989 struct cmd_syndesc *opts;
992 char *auditFileName = NULL;
994 #if defined(AFS_AIX32_ENV)
995 extern int aixlow_water;
998 opts = cmd_CreateSyntax(NULL, NULL, NULL, NULL);
1000 /* fileserver options */
1001 cmd_AddParmAtOffset(opts, OPT_large, "-L", CMD_FLAG,
1002 CMD_OPTIONAL, "defaults for a 'large' server");
1003 cmd_AddParmAtOffset(opts, OPT_small, "-S", CMD_FLAG,
1004 CMD_OPTIONAL, "defaults for a 'small' server");
1006 cmd_AddParmAtOffset(opts, OPT_banner, "-banner", CMD_FLAG,
1007 CMD_OPTIONAL, "print regular banners to log");
1008 cmd_AddParmAtOffset(opts, OPT_implicit, "-implicit", CMD_SINGLE,
1009 CMD_OPTIONAL, "implicit admin access bits");
1011 #if defined(AFS_SGI_ENV)
1012 cmd_AddParmAtOffset(opts, OPT_lock, "-lock", CMD_FLAG,
1013 CMD_OPTIONAL, "lock filserver binary in memory");
1015 cmd_AddParmAtOffset(opts, OPT_readonly, "-readonly", CMD_FLAG,
1016 CMD_OPTIONAL, "be a readonly fileserver");
1017 cmd_AddParmAtOffset(opts, OPT_saneacls, "-saneacls", CMD_FLAG,
1018 CMD_OPTIONAL, "set the saneacls capability bit");
1020 cmd_AddParmAtOffset(opts, OPT_buffers, "-b", CMD_SINGLE,
1021 CMD_OPTIONAL, "buffers");
1022 cmd_AddParmAtOffset(opts, OPT_callbacks, "-cb", CMD_SINGLE,
1023 CMD_OPTIONAL, "number of callbacks");
1024 cmd_AddParmAtOffset(opts, OPT_vcsize, "-vc", CMD_SINGLE,
1025 CMD_OPTIONAL, "volume cachesize");
1026 cmd_AddParmAtOffset(opts, OPT_lvnodes, "-l", CMD_SINGLE,
1027 CMD_OPTIONAL, "large vnodes");
1028 cmd_AddParmAtOffset(opts, OPT_svnodes, "-s", CMD_SINGLE,
1029 CMD_OPTIONAL, "small vnodes");
1030 cmd_AddParmAtOffset(opts, OPT_sendsize, "-sendsize", CMD_SINGLE,
1031 CMD_OPTIONAL, "size of send buffer in bytes");
1033 #if defined(AFS_AIX32_ENV)
1034 cmd_AddParmAtOffset(opts, OPT_minspare, "-m", CMD_SINGLE,
1035 CMD_OPTIONAL, "minimum percentage spare in partition");
1038 cmd_AddParmAtOffset(opts, OPT_spare, "-spare", CMD_SINGLE,
1039 CMD_OPTIONAL, "kB overage on volume quota");
1040 cmd_AddParmAtOffset(opts, OPT_pctspare, "pctspare", CMD_SINGLE,
1041 CMD_OPTIONAL, "percentage overage on volume quota");
1043 cmd_AddParmAtOffset(opts, OPT_hostcpsrefresh, "-hr", CMD_SINGLE,
1044 CMD_OPTIONAL, "hours between host CPS refreshes");
1046 cmd_AddParmAtOffset(opts, OPT_vattachthreads, "-vattachpar", CMD_SINGLE,
1047 CMD_OPTIONAL, "# of volume attachment threads");
1049 cmd_AddParmAtOffset(opts, OPT_abortthreshold, "-abortthreshold",
1050 CMD_SINGLE, CMD_OPTIONAL,
1052 cmd_AddParmAtOffset(opts, OPT_busyat, "-busyat", CMD_SINGLE, CMD_OPTIONAL,
1053 "# of queued entries after which server is busy");
1054 cmd_AddParmAtOffset(opts, OPT_nobusy, "-nobusy", CMD_FLAG, CMD_OPTIONAL,
1055 "send VRESTARTING while restarting the server");
1057 cmd_AddParmAtOffset(opts, OPT_offline_timeout, "-offline-timeout",
1058 CMD_SINGLE, CMD_OPTIONAL,
1059 "timeout for offlining volumes");
1060 cmd_AddParmAtOffset(opts, OPT_offline_shutdown_timeout,
1061 "-offline-shutdown-timeout", CMD_SINGLE, CMD_OPTIONAL,
1062 "timeout offlining volumes during shutdown");
1064 cmd_AddParmAtOffset(opts, OPT_vhandle_setaside, "-vhandle-setaside",
1065 CMD_SINGLE, CMD_OPTIONAL,
1066 "# fds reserved for non-cache IO");
1067 cmd_AddParmAtOffset(opts, OPT_vhandle_max_cachesize,
1068 "-vhandle-max-cachesize", CMD_SINGLE, CMD_OPTIONAL,
1070 cmd_AddParmAtOffset(opts, OPT_vhandle_initial_cachesize,
1071 "-vhandle-initial-cachesize", CMD_SINGLE,
1072 CMD_OPTIONAL, "# fds reserved for cache IO");
1074 #ifdef AFS_DEMAND_ATTACH_FS
1076 cmd_AddParmAtOffset(opts, OPT_fs_state_dont_save,
1077 "-fs-state-dont-save", CMD_FLAG, CMD_OPTIONAL,
1078 "disable state save during shutdown");
1079 cmd_AddParmAtOffset(opts, OPT_fs_state_dont_restore,
1080 "-fs-state-dont-restore", CMD_FLAG, CMD_OPTIONAL,
1081 "disable state restore during startup");
1082 cmd_AddParmAtOffset(opts, OPT_fs_state_verify, "-fs-state-verify",
1083 CMD_SINGLE, CMD_OPTIONAL, "none|save|restore|both");
1084 cmd_AddParmAtOffset(opts, OPT_vhashsize, "-vhashsize",
1085 CMD_SINGLE, CMD_OPTIONAL,
1086 "log(2) of # of volume hash buckets");
1087 cmd_AddParmAtOffset(opts, OPT_vlrudisable, "-vlrudisable",
1088 CMD_FLAG, CMD_OPTIONAL, "disable VLRU functionality");
1089 cmd_AddParmAtOffset(opts, OPT_vlruthresh, "-vlruthresh",
1090 CMD_FLAG, CMD_OPTIONAL,
1091 "mins before unused vols become eligible for detach");
1092 cmd_AddParmAtOffset(opts, OPT_vlruinterval, "-vlruinterval",
1093 CMD_FLAG, CMD_OPTIONAL, "secs between VLRU scans");
1094 cmd_AddParmAtOffset(opts, OPT_vlrumax, "-vlrumax", CMD_FLAG, CMD_OPTIONAL,
1095 "max volumes to detach in one scan");
1096 cmd_AddParmAtOffset(opts, OPT_unsafe_nosalvage, "-unsafe-nosalvage",
1097 CMD_FLAG, CMD_OPTIONAL,
1098 "bybass safety checks on volume attach");
1101 /* unrecommend options - should perhaps be CMD_HIDE */
1102 cmd_AddParmAtOffset(opts, OPT_stack, "-k", CMD_SINGLE, CMD_OPTIONAL,
1104 cmd_AddParmAtOffset(opts, OPT_cbwait, "-w", CMD_SINGLE, CMD_OPTIONAL,
1105 "callback wait interval");
1106 cmd_AddParmAtOffset(opts, OPT_novbc, "-novbc", CMD_SINGLE, CMD_FLAG,
1107 "disable callback breaks on reattach");
1109 /* general options */
1110 cmd_AddParmAtOffset(opts, OPT_auditlog, "-auditlog", CMD_SINGLE,
1111 CMD_OPTIONAL, "location of audit log");
1112 cmd_AddParmAtOffset(opts, OPT_auditiface, "-audit-interface", CMD_SINGLE,
1113 CMD_OPTIONAL, "interface to use for audit logging");
1114 cmd_AddParmAtOffset(opts, OPT_config, "-config", CMD_SINGLE, CMD_OPTIONAL,
1115 "configuration location");
1116 cmd_AddParmAtOffset(opts, OPT_debug, "-d", CMD_SINGLE, CMD_OPTIONAL,
1118 cmd_AddParmAtOffset(opts, OPT_logfile, "-logfile", CMD_SINGLE,
1119 CMD_OPTIONAL, "location of logfile");
1120 cmd_AddParmAtOffset(opts, OPT_mrafslogs, "-mrafslogs", CMD_FLAG,
1121 CMD_OPTIONAL, "enable MRAFS style logging");
1122 cmd_AddParmAtOffset(opts, OPT_threads, "-p", CMD_SINGLE, CMD_OPTIONAL,
1123 "number of threads");
1124 #if !defined(AFS_NT40_ENV)
1125 cmd_AddParmAtOffset(opts, OPT_syslog, "-syslog", CMD_SINGLE_OR_FLAG,
1126 CMD_OPTIONAL, "log to syslog");
1130 cmd_AddParmAtOffset(opts, OPT_peer, "-enable_peer_stats", CMD_FLAG,
1131 CMD_OPTIONAL, "enable RX transport statistics");
1132 cmd_AddParmAtOffset(opts, OPT_process, "-enable_process_stats", CMD_FLAG,
1133 CMD_OPTIONAL, "enable RX RPC statistics");
1134 cmd_AddParmAtOffset(opts, OPT_nojumbo, "-nojumbo", CMD_FLAG,
1135 CMD_OPTIONAL, "disable jumbograms");
1136 cmd_AddParmAtOffset(opts, OPT_jumbo, "-jumbo", CMD_FLAG, CMD_OPTIONAL,
1137 "enable jumbograms");
1138 cmd_AddParmAtOffset(opts, OPT_rxbind, "-rxbind", CMD_FLAG, CMD_OPTIONAL,
1139 "bind only to the primary interface");
1140 cmd_AddParmAtOffset(opts, OPT_rxdbg, "-rxdbg", CMD_FLAG, CMD_OPTIONAL,
1141 "enable rx debugging");
1142 cmd_AddParmAtOffset(opts, OPT_rxdbge, "-rxdbge", CMD_FLAG, CMD_OPTIONAL,
1143 "enable rx event debugging");
1144 cmd_AddParmAtOffset(opts, OPT_rxpck, "-rxpck", CMD_SINGLE, CMD_OPTIONAL,
1145 "# of extra rx packets");
1146 cmd_AddParmAtOffset(opts, OPT_rxmaxmtu, "-rxmaxmtu", CMD_SINGLE,
1147 CMD_OPTIONAL, "maximum MTU for RX");
1148 cmd_AddParmAtOffset(opts, OPT_udpsize, "-udpsize", CMD_SINGLE,
1149 CMD_OPTIONAL, "size of socket buffer in bytes");
1152 cmd_AddParmAtOffset(opts, OPT_dotted, "-allow-dotted-principals",
1153 CMD_FLAG, CMD_OPTIONAL,
1154 "permit Kerberos 5 principals with dots");
1155 cmd_AddParmAtOffset(opts, OPT_realm, "-realm",
1156 CMD_LIST, CMD_OPTIONAL, "local realm");
1158 code = cmd_Parse(argc, argv, &opts);
1162 /* XXX - cmd_OptionAsString(opts, OPT_config, &configDir); */
1164 cmd_OpenConfigFile(AFSDIR_SERVER_CONFIG_FILE_FILEPATH);
1165 cmd_SetCommandName("fileserver");
1167 if (cmd_OptionPresent(opts, OPT_large)
1168 && cmd_OptionPresent(opts, OPT_small)) {
1169 printf("Only one of -L or -S must be specified\n");
1173 if (cmd_OptionPresent(opts, OPT_spare)
1174 && cmd_OptionPresent(opts, OPT_pctspare)) {
1175 printf("Both -spare and -pctspare specified, exiting.\n");
1179 if (cmd_OptionPresent(opts, OPT_large)) {
1183 numberofcbs = 64000;
1189 if (cmd_OptionPresent(opts, OPT_small)) {
1193 numberofcbs = 20000;
1199 cmd_OptionAsFlag(opts, OPT_banner, &printBanner);
1201 if (cmd_OptionAsString(opts, OPT_implicit, &optstring) == 0) {
1202 implicitAdminRights = ParseRights(optstring);
1205 if (implicitAdminRights < 0)
1206 return implicitAdminRights;
1209 #if defined(AFS_SGI_ENV)
1210 cmd_OptionAsFlag(opts, OPT_lock, &SawLock);
1212 cmd_OptionAsFlag(opts, OPT_readonly, &readonlyServer);
1213 cmd_OptionAsFlag(opts, OPT_saneacls, &saneacls);
1214 cmd_OptionAsInt(opts, OPT_buffers, &buffs);
1216 if (cmd_OptionAsInt(opts, OPT_callbacks, &numberofcbs) == 0) {
1217 printf("number of cbs %d invalid; "
1218 "must be between 10000 and 2147483647\n", numberofcbs);
1222 cmd_OptionAsInt(opts, OPT_vcsize, &volcache);
1223 cmd_OptionAsInt(opts, OPT_lvnodes, &large);
1224 cmd_OptionAsInt(opts, OPT_svnodes, &nSmallVns);
1225 if (cmd_OptionAsInt(opts, OPT_sendsize, &optval) == 0) {
1226 if (optval < 16384) {
1227 printf("Warning:sendsize %d is less than minimum %d; ignoring\n",
1230 sendBufSize = optval;
1233 #if defined(AFS_AIX32_ENV)
1234 if (cmd_OptionAsInt(opts, OPT_minspare, &aixlow_water) == 0) {
1235 if ((aixlow_water < 0) || (aixlow_water > 30)) {
1236 printf("space reserved %d%% invalid; must be between 0-30%\n",
1243 cmd_OptionAsInt(opts, OPT_spare, &BlocksSpare);
1244 if (cmd_OptionAsInt(opts, OPT_pctspare, &PctSpare) == 0) {
1248 if (cmd_OptionAsInt(opts, OPT_hostcpsrefresh, &optval) == 0) {
1249 if ((optval < 1) || (optval > 36)) {
1250 printf("host acl refresh interval of %d hours is invalid; "
1251 "hours must be between 1 and 36\n\n", optval);
1254 hostaclRefresh = optval * 60 * 60;
1257 cmd_OptionAsInt(opts, OPT_vattachthreads, &vol_attach_threads);
1259 cmd_OptionAsInt(opts, OPT_abortthreshold, &abort_threshold);
1261 /* busyat is at the end, as rxpackets has to be set before we can use it */
1262 if (cmd_OptionPresent(opts, OPT_nobusy))
1265 if (cmd_OptionAsInt(opts, OPT_offline_timeout, &offline_timeout) == 0) {
1266 if (offline_timeout < -1) {
1267 printf("Invalid -offline-timeout value %d; the only valid "
1268 "negative value is -1\n", offline_timeout);
1273 if (cmd_OptionAsInt(opts, OPT_offline_shutdown_timeout,
1274 &offline_shutdown_timeout) == 0) {
1275 if (offline_shutdown_timeout < -1) {
1276 printf("Invalid -offline-timeout value %d; the only valid "
1277 "negative value is -1\n", offline_shutdown_timeout);
1282 cmd_OptionAsUint(opts, OPT_vhandle_setaside,
1283 &vol_io_params.fd_handle_setaside);
1284 cmd_OptionAsUint(opts, OPT_vhandle_max_cachesize,
1285 &vol_io_params.fd_max_cachesize);
1286 cmd_OptionAsUint(opts, OPT_vhandle_initial_cachesize,
1287 &vol_io_params.fd_initial_cachesize);
1289 #ifdef AFS_DEMAND_ATTACH_FS
1290 if (cmd_OptionPresent(opts, OPT_fs_state_dont_save))
1291 fs_state.options.fs_state_save = 0;
1292 if (cmd_OptionPresent(opts, OPT_fs_state_dont_restore))
1293 fs_state.options.fs_state_restore = 0;
1294 if (cmd_OptionAsString(opts, OPT_fs_state_verify, &optstring) == 0) {
1295 if (strcmp(optstring, "none") == 0) {
1296 fs_state.options.fs_state_verify_before_save = 0;
1297 fs_state.options.fs_state_verify_after_restore = 0;
1298 } else if (strcmp(optstring, "save") == 0) {
1299 fs_state.options.fs_state_verify_after_restore = 0;
1300 } else if (strcmp(optstring, "restore") == 0) {
1301 fs_state.options.fs_state_verify_before_save = 0;
1302 } else if (strcmp(optstring, "both") == 0) {
1305 fprintf(stderr, "invalid argument for -fs-state-verify\n");
1309 if (cmd_OptionAsInt(opts, OPT_vhashsize, &optval) == 0) {
1310 if (VSetVolHashSize(optval)) {
1311 fprintf(stderr, "specified -vhashsize (%d) is invalid or out "
1312 "of range\n", optval);
1316 if (cmd_OptionPresent(opts, OPT_vlrudisable))
1317 VLRU_SetOptions(VLRU_SET_ENABLED, 0);
1318 if (cmd_OptionAsInt(opts, OPT_vlruthresh, &optval) == 0)
1319 VLRU_SetOptions(VLRU_SET_THRESH, 60*optval);
1320 if (cmd_OptionAsInt(opts, OPT_vlruinterval, &optval) == 0)
1321 VLRU_SetOptions(VLRU_SET_INTERVAL, optval);
1322 if (cmd_OptionAsInt(opts, OPT_vlrumax, &optval) == 0)
1323 VLRU_SetOptions(VLRU_SET_MAX, optval);
1324 cmd_OptionAsFlag(opts, OPT_unsafe_nosalvage, &unsafe_attach);
1325 #endif /* AFS_DEMAND_ATTACH_FS */
1327 cmd_OptionAsInt(opts, OPT_stack, &stack);
1328 cmd_OptionAsInt(opts, OPT_cbwait, &fiveminutes);
1329 cmd_OptionAsFlag(opts, OPT_novbc, &novbc);
1331 /* general server options */
1332 cmd_OptionAsString(opts, OPT_auditlog, &auditFileName);
1334 if (cmd_OptionAsString(opts, OPT_auditiface, &optstring) == 0) {
1335 if (osi_audit_interface(optstring)) {
1336 printf("Invalid audit interface '%s'\n", optstring);
1343 cmd_OptionAsInt(opts, OPT_debug, &LogLevel);
1344 /* XXX - cmd_OptionAsString(opts, OPT_logfile, &logFile); */
1345 cmd_OptionAsFlag(opts, OPT_mrafslogs, &mrafsStyleLogs);
1347 if (cmd_OptionAsInt(opts, OPT_threads, &lwps) == 0) {
1348 lwps_max = max_fileserver_thread() - FILESERVER_HELPER_THREADS;
1349 if (lwps > lwps_max)
1355 #ifndef AFS_NT40_ENV
1356 if (cmd_OptionPresent(opts, OPT_syslog)) {
1357 serverLogSyslog = 1;
1358 cmd_OptionAsInt(opts, OPT_syslog, &serverLogSyslogFacility);
1362 if (cmd_OptionPresent(opts, OPT_peer))
1363 rx_enablePeerRPCStats();
1364 if (cmd_OptionPresent(opts, OPT_process))
1365 rx_enableProcessRPCStats();
1366 if (cmd_OptionPresent(opts, OPT_nojumbo))
1368 if (cmd_OptionPresent(opts, OPT_jumbo))
1370 cmd_OptionAsFlag(opts, OPT_rxbind, &rxBind);
1371 cmd_OptionAsFlag(opts, OPT_rxdbg, &rxlog);
1372 cmd_OptionAsFlag(opts, OPT_rxdbge, &eventlog);
1373 cmd_OptionAsInt(opts, OPT_rxpck, &rxpackets);
1375 cmd_OptionAsInt(opts, OPT_rxmaxmtu, &rxMaxMTU);
1377 if (cmd_OptionAsInt(opts, OPT_udpsize, &optval) == 0) {
1378 if (optval < rx_GetMinUdpBufSize()) {
1379 printf("Warning:udpsize %d is less than minimum %d; ignoring\n",
1380 optval, rx_GetMinUdpBufSize());
1382 udpBufSize = optval;
1386 cmd_OptionAsFlag(opts, OPT_dotted, &rxkadDisableDotCheck);
1387 if (cmd_OptionAsList(opts, OPT_realm, &optlist) == 0) {
1389 for (; optlist != NULL; optlist=optlist->next) {
1390 if (strlen(optlist->data) >= AFS_REALM_SZ) {
1391 printf("-realm argument must contain fewer than %d "
1392 "characters.\n", AFS_REALM_SZ);
1395 afsconf_SetLocalRealm(optlist->data); /* overrides krb.conf file, if one */
1399 /* anything setting rxpackets must come before this */
1400 if (cmd_OptionAsInt(opts, OPT_busyat, &optval) == 0) {
1402 printf("Busy threshold %d is too low, will use default.\n",
1404 busy_threshold = 3 * rxpackets / 2;
1406 busy_threshold = optval;
1409 busy_threshold = 3 * rxpackets / 2;
1413 osi_audit_file(auditFileName);
1418 /* Once upon a time, in a galaxy far far away, IBM AFS supported the use of
1419 * a file /vice/file/parms, the contents of which would override any command
1420 * line parameters. We no longer support the use of such a file, but we warn
1421 * if we encounter its presence from an older release
1426 struct afs_stat sbuf;
1428 if (afs_stat("/vice/file/parms", &sbuf) == 0) {
1429 ViceLog(0, ("Using /vice/file/parms to override command line "
1430 "options is no longer supported"));
1434 /* Miscellaneous routines */
1436 Die(const char *msg)
1439 ViceLogThenPanic(0, ("%s\n", msg));
1449 * If this fails, it's because something major is wrong, and is not
1450 * likely to be time dependent.
1452 code = pr_Initialize(2, AFSDIR_SERVER_ETC_DIRPATH, 0);
1455 ("Couldn't initialize protection library; code=%d.\n", code));
1459 osi_Assert(pthread_key_create(&viced_uclient_key, NULL) == 0);
1461 SystemId = SYSADMINID;
1462 SystemAnyUser = ANYUSERID;
1463 SystemAnyUserCPS.prlist_len = 0;
1464 SystemAnyUserCPS.prlist_val = NULL;
1465 AnonCPS.prlist_len = 0;
1466 AnonCPS.prlist_val = NULL;
1468 code = pr_GetCPS(SystemAnyUser, &SystemAnyUserCPS);
1471 ("Couldn't get CPS for AnyUser, will try again in 30 seconds; code=%d.\n",
1475 code = pr_GetCPS(ANONYMOUSID, &AnonCPS);
1478 ("Couldn't get Anonymous CPS, exiting; code=%d.\n",
1482 AnonymousID = ANONYMOUSID;
1489 static struct ubik_client *cstruct;
1492 vl_Initialize(struct afsconf_dir *dir)
1495 afs_int32 scIndex = RX_SECIDX_NULL;
1496 struct afsconf_cell info;
1497 struct rx_securityClass *sc;
1498 struct rx_connection *serverconns[MAXSERVERS];
1500 memset(serverconns, 0, sizeof(serverconns));
1501 code = afsconf_ClientAuth(dir, &sc, &scIndex);
1503 ViceLog(0, ("Could not get security object for localAuth\n"));
1506 code = afsconf_GetCellInfo(dir, NULL, AFSCONF_VLDBSERVICE, &info);
1507 if (info.numServers > MAXSERVERS) {
1509 ("vl_Initialize: info.numServers=%d (> MAXSERVERS=%d)\n",
1510 info.numServers, MAXSERVERS));
1513 for (i = 0; i < info.numServers; i++)
1515 rx_NewConnection(info.hostAddr[i].sin_addr.s_addr,
1516 info.hostAddr[i].sin_port, USER_SERVICE_ID, sc,
1518 code = ubik_ClientInit(serverconns, &cstruct);
1520 ViceLog(0, ("vl_Initialize: ubik client init failed.\n"));
1526 #define SYSIDMAGIC 0x88aabbcc
1527 #define SYSIDVERSION 1
1532 afs_int32 fd, nentries, i;
1533 struct versionStamp vsn;
1534 struct afs_stat status;
1537 if ((afs_stat(AFSDIR_SERVER_SYSID_FILEPATH, &status))
1538 || (status.st_size <= 0)) {
1539 ViceLog(0, ("%s: doesn't exist\n", AFSDIR_SERVER_SYSID_FILEPATH));
1542 if (!(fd = afs_open(AFSDIR_SERVER_SYSID_FILEPATH, O_RDONLY, 0))) {
1544 ("%s: can't open (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1548 if (read(fd, (char *)&vsn, sizeof(vsn)) != sizeof(vsn)) {
1550 ("%s: Read failed (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1554 if (vsn.magic != SYSIDMAGIC) {
1556 ("%s: wrong magic %x (we support %x)\n",
1557 AFSDIR_SERVER_SYSID_FILEPATH, vsn.magic, SYSIDMAGIC));
1560 if (vsn.version != SYSIDVERSION) {
1562 ("%s: wrong version %d (we support %d)\n",
1563 AFSDIR_SERVER_SYSID_FILEPATH, vsn.version, SYSIDVERSION));
1566 if (read(fd, (char *)&uuid, sizeof(struct afsUUID))
1567 != sizeof(struct afsUUID)) {
1569 ("%s: read of uuid failed (%d)\n",
1570 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1573 afs_ntohuuid(&uuid);
1575 if (read(fd, (char *)&nentries, sizeof(afs_int32)) != sizeof(afs_int32)) {
1577 ("%s: Read of entries failed (%d)\n",
1578 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1581 if (nentries <= 0 || nentries > ADDRSPERSITE) {
1583 ("%s: invalid num of interfaces: %d\n",
1584 AFSDIR_SERVER_SYSID_FILEPATH, nentries));
1587 if (FS_HostAddr_cnt == 0) {
1588 FS_HostAddr_cnt = nentries;
1589 for (i = 0; i < nentries; i++) {
1590 if (read(fd, (char *)&FS_HostAddrs[i], sizeof(afs_int32)) !=
1591 sizeof(afs_int32)) {
1593 ("%s: Read of addresses failed (%d)\n",
1594 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1595 FS_HostAddr_cnt = 0; /* reset it */
1601 ("%s: address list ignored (NetInfo/NetRestrict override)\n",
1602 AFSDIR_SERVER_SYSID_FILEPATH));
1609 WriteSysIdFile(void)
1612 struct versionStamp vsn;
1613 struct afs_stat status;
1616 if (!afs_stat(AFSDIR_SERVER_SYSID_FILEPATH, &status)) {
1618 * File exists; keep the old one around
1620 rk_rename(AFSDIR_SERVER_SYSID_FILEPATH,
1621 AFSDIR_SERVER_OLDSYSID_FILEPATH);
1623 fd = afs_open(AFSDIR_SERVER_SYSID_FILEPATH, O_WRONLY | O_TRUNC | O_CREAT,
1627 ("%s: can't create (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1631 vsn.magic = SYSIDMAGIC;
1633 if ((i = write(fd, (char *)&vsn, sizeof(vsn))) != sizeof(vsn)) {
1635 ("%s: write failed (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1640 afs_htonuuid(&uuid);
1642 write(fd, (char *)&uuid,
1643 sizeof(struct afsUUID))) != sizeof(struct afsUUID)) {
1645 ("%s: write of uuid failed (%d)\n",
1646 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1650 write(fd, (char *)&FS_HostAddr_cnt,
1651 sizeof(afs_int32))) != sizeof(afs_int32)) {
1653 ("%s: write of # of entries failed (%d)\n",
1654 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1657 for (i = 0; i < FS_HostAddr_cnt; i++) {
1658 if (write(fd, (char *)&FS_HostAddrs[i], sizeof(afs_int32)) !=
1659 sizeof(afs_int32)) {
1661 ("%s: write of addresses failed (%d)\n",
1662 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1672 * This routine sets up the buffers for the VL_RegisterAddrs RPC. All addresses
1673 * in FS_HostAddrs[] are in NBO, while the RPC treats them as a "blob" of data
1674 * and so we need to convert each of them into HBO which is what the extra
1675 * array called FS_HostAddrs_HBO is used here.
1678 Do_VLRegisterRPC(void)
1682 afs_uint32 FS_HostAddrs_HBO[ADDRSPERSITE];
1685 for (i = 0; i < FS_HostAddr_cnt; i++)
1686 FS_HostAddrs_HBO[i] = ntohl(FS_HostAddrs[i]);
1687 addrs.bulkaddrs_len = FS_HostAddr_cnt;
1688 addrs.bulkaddrs_val = (afs_uint32 *) FS_HostAddrs_HBO;
1689 code = ubik_VL_RegisterAddrs(cstruct, 0, &FS_HostUUID, 0, &addrs);
1691 if (code == VL_MULTIPADDR) {
1693 ("VL_RegisterAddrs rpc failed; The IP address exists on a different server; repair it\n"));
1695 ("VL_RegisterAddrs rpc failed; See VLLog for details\n"));
1697 } else if (code == RXGEN_OPCODE) {
1699 ("vlserver doesn't support VL_RegisterAddrs rpc; ignored\n"));
1700 FS_registered = 2; /* So we don't have to retry in the gc daemon */
1703 ("VL_RegisterAddrs rpc failed; will retry periodically (code=%d, err=%d)\n",
1705 FS_registered = 1; /* Retry in the gc daemon */
1708 FS_registered = 2; /* So we don't have to retry in the gc daemon */
1720 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH || AFSDIR_SERVER_NETINFO_FILEPATH) {
1722 * Find addresses we are supposed to register as per the netrestrict
1723 * and netinfo files (/usr/afs/local/NetInfo and
1724 * /usr/afs/local/NetRestict)
1729 code = afsconf_ParseNetFiles(FS_HostAddrs, NULL, NULL,
1730 ADDRSPERSITE, reason,
1731 AFSDIR_SERVER_NETINFO_FILEPATH,
1732 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
1734 ViceLog(0, ("Can't register any valid addresses: %s\n", reason));
1737 FS_HostAddr_cnt = (afs_uint32) code;
1740 FS_HostAddr_cnt = rx_getAllAddr(FS_HostAddrs, ADDRSPERSITE);
1743 if (FS_HostAddr_cnt == 1 && rxBind == 1)
1744 code = FS_HostAddrs[0];
1746 code = htonl(INADDR_ANY);
1751 InitVL(struct afsconf_dir *dir)
1756 * If this fails, it's because something major is wrong, and is not
1757 * likely to be time dependent.
1759 code = vl_Initialize(dir);
1762 ("Couldn't initialize volume location library; code=%d.\n", code));
1766 /* Read or create the sysid file and register the fileserver's
1767 * IP addresses with the vlserver.
1769 code = ReadSysIdFile();
1771 /* Need to create the file */
1772 ViceLog(0, ("Creating new SysID file\n"));
1773 if ((code = afs_uuid_create(&FS_HostUUID))) {
1774 ViceLog(0, ("Failed to create new uuid: %d\n", code));
1778 /* A good sysid file exists; inform the vlserver. If any conflicts,
1779 * we always use the latest interface available as the real truth.
1782 code = Do_VLRegisterRPC();
1787 main(int argc, char *argv[])
1791 struct rx_securityClass **securityClasses;
1792 afs_int32 numClasses;
1793 struct rx_service *tservice;
1794 pthread_t serverPid;
1795 pthread_attr_t tattr;
1797 int minVnodesRequired; /* min size of vnode cache */
1798 #ifndef AFS_NT40_ENV
1799 struct rlimit rlim; /* max number of open file descriptors */
1804 afs_uint32 rx_bindhost;
1805 VolumePackageOptions opts;
1807 #ifdef AFS_AIX32_ENV
1808 struct sigaction nsa;
1810 sigemptyset(&nsa.sa_mask);
1811 nsa.sa_handler = SIG_DFL;
1812 nsa.sa_flags = SA_FULLDUMP;
1813 sigaction(SIGABRT, &nsa, NULL);
1814 sigaction(SIGSEGV, &nsa, NULL);
1818 /* Initialize dirpaths */
1819 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
1821 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
1823 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
1827 /* set ihandle package defaults prior to parsing args */
1830 /* check for the parameter file */
1833 if (ParseArgs(argc, argv)) {
1836 MUTEX_INIT(&fileproc_glock_mutex, "fileproc", MUTEX_DEFAULT, 0);
1838 #ifdef AFS_SGI_VNODE_GLUE
1839 if (afs_init_kernel_config(-1) < 0) {
1841 ("Can't determine NUMA configuration, not starting fileserver.\n");
1845 FS_configPath = strdup(AFSDIR_SERVER_ETC_DIRPATH);
1847 confDir = afsconf_Open(FS_configPath);
1849 fprintf(stderr, "Unable to open config directory %s\n",
1854 /* initialize audit user check */
1855 osi_audit_set_user_check(confDir, fs_IsLocalRealmMatch);
1857 /* Open FileLog on stdout, stderr, fd 1 and fd2 (for perror), sigh. */
1858 #ifndef AFS_NT40_ENV
1859 serverLogSyslogTag = "fileserver";
1861 OpenLog(AFSDIR_SERVER_FILELOG_FILEPATH);
1864 LogCommandLine(argc, argv, "starting", "", "File server", FSLog);
1866 #if !defined(AFS_NT40_ENV)
1867 /* initialize the pthread soft signal handler thread */
1871 /* install signal handlers for controlling the fileserver process */
1872 ResetCheckSignal(); /* set CheckSignal_Signal() sig handler */
1873 ResetCheckDescriptors(); /* set CheckDescriptors_Signal() sig handler */
1875 #if defined(AFS_SGI_ENV)
1876 /* give this guy a non-degrading priority so help busy servers */
1877 schedctl(NDPRI, 0, NDPNORMMAX);
1880 #elif !defined(AFS_NT40_ENV)
1881 nice(-5); /* TODO: */
1884 #ifdef AFS_DEMAND_ATTACH_FS
1889 if (afs_winsockInit() < 0) {
1890 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
1891 ViceLog(0, ("File server failed to intialize winsock.\n"));
1897 /* if we support more than 16 threads, then we better have the ability
1898 ** to keep open a large number of files simultaneously
1900 #if defined(AFS_AIX_ENV) && !defined(AFS_AIX42_ENV)
1901 curLimit = OPEN_MAX; /* for pre AIX 4.2 systems */
1902 #elif defined(AFS_NT40_ENV)
1903 curLimit = NT_OPEN_MAX; /* open file descriptor limit on NT */
1906 curLimit = 0; /* the number of open file descriptors */
1907 code = getrlimit(RLIMIT_NOFILE, &rlim);
1909 curLimit = rlim.rlim_cur;
1910 rlim.rlim_cur = rlim.rlim_max;
1911 code = setrlimit(RLIMIT_NOFILE, &rlim);
1913 curLimit = rlim.rlim_max;
1916 ViceLog(0, ("Failed to increase open file limit, using default\n"));
1918 #endif /* defined(AFS_AIX_ENV) && !defined(AFS_AIX42_ENV) */
1920 curLimit -= 32; /* leave a slack of 32 file descriptors */
1921 if (lwps > curLimit) {
1925 lwps = 16; /* default to a maximum of 16 threads */
1927 /* tune the ihandle fd cache accordingly */
1928 if (vol_io_params.fd_max_cachesize < curLimit)
1929 vol_io_params.fd_max_cachesize = curLimit + 1;
1932 ("The system supports a max of %d open files and we are starting %d threads (ihandle fd cache is %d)\n",
1933 curLimit, lwps, vol_io_params.fd_max_cachesize));
1936 /* Initialize volume support */
1938 V_BreakVolumeCallbacks = BreakVolumeCallBacksLater;
1941 SetLogThreadNumProgram( rx_GetThreadNum );
1943 /* initialize libacl routines */
1944 acl_Initialize(ACL_VERSION);
1946 /* initialize RX support */
1947 #ifndef AFS_NT40_ENV
1948 rxi_syscallp = viced_syscall;
1950 rx_extraPackets = rxpackets;
1951 rx_extraQuota = 4; /* for outgoing prserver calls from R threads */
1952 rx_SetBusyThreshold(busy_threshold, VBUSY);
1953 rx_SetCallAbortThreshold(abort_threshold);
1954 rx_SetConnAbortThreshold(abort_threshold);
1956 stackSize = 128 * 1024;
1958 stackSize = lwps * 4000;
1959 if (stackSize < 32000)
1961 else if (stackSize > 44000)
1964 #if defined(AFS_HPUX_ENV) || defined(AFS_SUN_ENV) || defined(AFS_SGI51_ENV) || defined(AFS_XBSD_ENV)
1965 rx_SetStackSize(1, stackSize);
1968 rx_SetUdpBufSize(udpBufSize); /* set the UDP buffer size for receive */
1969 rx_bindhost = SetupVL();
1971 if (rx_InitHost(rx_bindhost, (int)htons(7000)) < 0) {
1972 ViceLog(0, ("Cannot initialize RX\n"));
1975 if (!rxJumbograms) {
1976 /* Don't send and don't allow 3.4 clients to send jumbograms. */
1979 if (rxMaxMTU != -1) {
1980 if (rx_SetMaxMTU(rxMaxMTU) != 0) {
1981 ViceLog(0, ("rxMaxMTU %d is invalid\n", rxMaxMTU));
1986 rx_SetRxDeadTime(30);
1987 afsconf_SetSecurityFlags(confDir, AFSCONF_SECOPTS_ALWAYSENCRYPT);
1988 afsconf_BuildServerSecurityObjects(confDir, &securityClasses, &numClasses);
1990 tservice = rx_NewServiceHost(rx_bindhost, /* port */ 0, /* service id */
1991 1, /*service name */
1993 securityClasses, numClasses,
1994 RXAFS_ExecuteRequest);
1997 ("Failed to initialize RX, probably two servers running.\n"));
2000 if (rxkadDisableDotCheck) {
2001 rx_SetSecurityConfiguration(tservice, RXS_CONFIG_FLAGS,
2002 (void *)RXS_CONFIG_FLAGS_DISABLE_DOTCHECK);
2004 rx_SetMinProcs(tservice, 3);
2005 rx_SetMaxProcs(tservice, lwps);
2006 rx_SetCheckReach(tservice, 1);
2007 rx_SetServerIdleDeadErr(tservice, VNOSERVICE);
2010 rx_NewService(0, RX_STATS_SERVICE_ID, "rpcstats", securityClasses,
2011 numClasses, RXSTATS_ExecuteRequest);
2013 ViceLog(0, ("Failed to initialize rpc stat service.\n"));
2016 rx_SetMinProcs(tservice, 2);
2017 rx_SetMaxProcs(tservice, 4);
2020 * Enable RX hot threads, which allows the listener thread to trade
2021 * places with an idle thread and moves the context switch from listener
2022 * to worker out of the critical path.
2024 rx_EnableHotThread();
2026 /* Some rx debugging */
2027 if (rxlog || eventlog) {
2028 debugFile = afs_fopen("rx_dbg", "w");
2030 rx_debugFile = debugFile;
2032 rxevent_debugFile = debugFile;
2035 init_sys_error_to_et(); /* Set up error table translation */
2036 h_InitHostPackage(); /* set up local cellname and realmname */
2037 InitCallBack(numberofcbs);
2040 code = InitVL(confDir);
2041 if (code && code != VL_MULTIPADDR) {
2042 ViceLog(0, ("Fatal error in library initialization, exiting!!\n"));
2047 if (code && code != -1) {
2048 ViceLog(0, ("Fatal error in protection initialization, exiting!!\n"));
2052 /* allow super users to manage RX statistics */
2053 rx_SetRxStatUserOk(viced_SuperUser);
2055 CV_INIT(&fsync_cond, "fsync", CV_DEFAULT, 0);
2056 MUTEX_INIT(&fsync_glock_mutex, "fsync", MUTEX_DEFAULT, 0);
2058 #if !defined(AFS_DEMAND_ATTACH_FS)
2060 * For DAFS, we do not start the Rx server threads until after
2061 * the volume package is initialized, and fileserver state is
2062 * restored. This is necessary in order to keep host and callback
2063 * package state pristine until we have a chance to restore state.
2065 * Furthermore, startup latency is much lower with dafs, so this
2066 * shouldn't pose a serious problem.
2068 rx_StartServer(0); /* now start handling requests */
2071 /* we ensure that there is enough space in the vnode buffer to satisfy
2072 ** requests from all concurrent threads.
2073 ** the maximum number of vnodes used by a single thread at any one time
2074 ** is three ( "link" uses three vnodes simultaneously, one vLarge and
2075 ** two vSmall for linking files and two vLarge and one vSmall for linking
2078 minVnodesRequired = 2 * lwps + 1;
2079 if (minVnodesRequired > nSmallVns) {
2080 nSmallVns = minVnodesRequired;
2082 ("Overriding -s command line parameter with %d\n",
2085 if (minVnodesRequired > large) {
2086 large = minVnodesRequired;
2087 ViceLog(0, ("Overriding -l command line parameter with %d\n", large));
2090 /* We now do this after getting the listener up and running, so that client
2091 * connections don't timeout (maybe) if a file server is restarted, since it
2092 * will be available "real soon now". Worry about whether we can satisfy the
2093 * calls in the volume package itself.
2095 VOptDefaults(fileServer, &opts);
2096 opts.nLargeVnodes = large;
2097 opts.nSmallVnodes = nSmallVns;
2098 opts.volcache = volcache;
2099 opts.unsafe_attach = unsafe_attach;
2100 if (offline_timeout != -1) {
2101 opts.interrupt_rxcall = rx_InterruptCall;
2102 opts.offline_timeout = offline_timeout;
2104 if (offline_shutdown_timeout == -1) {
2105 /* default to -offline-timeout, if shutdown-specific timeout is not
2107 opts.offline_shutdown_timeout = offline_timeout;
2109 opts.interrupt_rxcall = rx_InterruptCall;
2110 opts.offline_shutdown_timeout = offline_shutdown_timeout;
2113 if (VInitVolumePackage2(fileServer, &opts)) {
2115 ("Shutting down: errors encountered initializing volume package\n"));
2120 /* Install handler to catch the shutdown signal;
2121 * bosserver assumes SIGQUIT shutdown
2123 #if !defined(AFS_NT40_ENV)
2124 softsig_signal(SIGQUIT, ShutDown_Signal);
2126 (void)signal(SIGQUIT, ShutDown_Signal);
2129 if (VInitAttachVolumes(fileServer)) {
2131 ("Shutting down: errors encountered initializing volume package\n"));
2136 #ifdef AFS_DEMAND_ATTACH_FS
2137 if (fs_state.options.fs_state_restore) {
2140 * restore fileserver state */
2143 rx_StartServer(0); /* now start handling requests */
2144 #endif /* AFS_DEMAND_ATTACH_FS */
2147 * We are done calling fopen/fdopen. It is safe to use a large
2148 * of the file descriptor cache.
2152 ViceLog(5, ("Starting pthreads\n"));
2153 osi_Assert(pthread_attr_init(&tattr) == 0);
2154 osi_Assert(pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED) == 0);
2156 osi_Assert(pthread_create
2157 (&serverPid, &tattr, FiveMinuteCheckLWP,
2158 &fiveminutes) == 0);
2159 osi_Assert(pthread_create
2160 (&serverPid, &tattr, HostCheckLWP, &fiveminutes) == 0);
2161 osi_Assert(pthread_create
2162 (&serverPid, &tattr, FsyncCheckLWP, &fiveminutes) == 0);
2164 FT_GetTimeOfDay(&tp, 0);
2167 * Figure out the FileServer's name and primary address.
2169 ViceLog(0, ("Getting FileServer name...\n"));
2170 code = gethostname(FS_HostName, 64);
2172 ViceLog(0, ("gethostname() failed\n"));
2174 ViceLog(0, ("FileServer host name is '%s'\n", FS_HostName));
2176 ViceLog(0, ("Getting FileServer address...\n"));
2177 he = gethostbyname(FS_HostName);
2179 ViceLog(0, ("Can't find address for FileServer '%s'\n", FS_HostName));
2182 memcpy(&FS_HostAddr_NBO, he->h_addr, 4);
2183 (void)afs_inet_ntoa_r(FS_HostAddr_NBO, hoststr);
2184 FS_HostAddr_HBO = ntohl(FS_HostAddr_NBO);
2186 ("FileServer %s has address %s (0x%x or 0x%x in host byte order)\n",
2187 FS_HostName, hoststr, FS_HostAddr_NBO, FS_HostAddr_HBO));
2191 strftime(tbuffer, sizeof(tbuffer), "%a %b %d %H:%M:%S %Y",
2192 localtime_r(&t, &tm));
2193 ViceLog(0, ("File Server started %s\n", tbuffer));
2194 afs_FullPerfStats.det.epoch.tv_sec = StartTime = tp.tv_sec;
2196 sleep(1000); /* long time */