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/netutils.h>
72 # include <afs/softsig.h>
74 #include "viced_prototypes.h"
77 #if defined(AFS_SGI_ENV)
78 # include "sys/schedctl.h"
79 # include "sys/lock.h"
81 #include <rx/rx_globals.h>
85 void *ShutDown(void *);
86 static void ClearXStatValues(void);
87 static void PrintCounters(void);
88 static void ResetCheckDescriptors(void);
89 static void ResetCheckSignal(void);
90 static void *CheckSignal(void *);
92 static afs_int32 Do_VLRegisterRPC(void);
94 int eventlog = 0, rxlog = 0;
97 pthread_mutex_t fsync_glock_mutex;
98 pthread_cond_t fsync_cond;
101 # define NT_OPEN_MAX 1024 /* This is an arbitrary no. we came up with for
102 * now. We hope this will be replaced by a more
103 * intelligent estimate later. */
106 int SystemId; /* ViceID of "Administrators" */
107 int SystemAnyUser; /* Viceid of "System:AnyUser" */
108 prlist SystemAnyUserCPS; /* CPS for "system:AnyUser */
109 int AnonymousID = 0; /* ViceId of "Anonymous" */
110 prlist AnonCPS; /* CPS for "Anonymous" */
112 struct afsconf_dir *confDir; /* Configuration dir object */
114 int restartMode = RESTART_ORDINARY;
117 * Home for the performance statistics.
119 struct afs_PerfStats afs_perfstats;
122 extern int Statistics;
127 int rxJumbograms = 0; /* default is to not send and receive jumbograms. */
128 int rxBind = 0; /* don't bind */
129 int rxkadDisableDotCheck = 0; /* disable check for dot in principal name */
131 afs_int32 implicitAdminRights = PRSFS_LOOKUP; /* The ADMINISTER right is
133 afs_int32 readonlyServer = 0;
136 int stackSize = 24000;
137 int fiveminutes = 300; /* 5 minutes. Change this for debugging only */
138 int CurrentConnections = 0;
139 int hostaclRefresh = 7200; /* refresh host clients' acls every 2 hrs */
140 #if defined(AFS_SGI_ENV)
146 * seconds to wait until forcing a panic during ShutDownAndCore(PANIC)
147 * in case we get stuck.
149 #ifdef AFS_DEMAND_ATTACH_FS
150 static int panic_timeout = 2 * 60;
152 static int panic_timeout = 30 * 60;
155 int rxpackets = 150; /* 100 */
156 int nSmallVns = 400; /* 200 */
157 int large = 400; /* 200 */
158 int volcache = 400; /* 400 */
159 int numberofcbs = 60000; /* 60000 */
160 int lwps = 9; /* 6 */
161 int buffs = 90; /* 70 */
162 int novbc = 0; /* Enable Volume Break calls */
163 int busy_threshold = 600;
164 int abort_threshold = 10;
165 int udpBufSize = 0; /* UDP buffer size for receive */
166 int sendBufSize = 16384; /* send buffer size */
167 int saneacls = 0; /* Sane ACLs Flag */
168 static int unsafe_attach = 0; /* avoid inUse check on vol attach? */
169 static int offline_timeout = -1; /* -offline-timeout option */
170 static int offline_shutdown_timeout = -1; /* -offline-shutdown-timeout option */
174 pthread_key_t viced_uclient_key;
177 * FileServer's name and IP address, both network byte order and
180 #define ADDRSPERSITE 16 /* Same global is in rx/rx_user.c */
182 char FS_HostName[128] = "localhost";
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 manage RX statistics */
284 fs_rxstat_userok(struct rx_call *call)
286 return afsconf_SuperUser(confDir, call, NULL);
290 ResetCheckSignal(void)
294 #if defined(AFS_HPUX_ENV)
296 #elif defined(AFS_NT40_ENV)
302 #if !defined(AFS_NT40_ENV)
303 softsig_signal(signo, CheckSignal_Signal);
305 signal(signo, CheckSignal_Signal);
310 ResetCheckDescriptors(void)
313 softsig_signal(SIGTERM, CheckDescriptors_Signal);
319 viced_syscall(afs_uint32 a3, afs_uint32 a4, void *a5)
322 # ifndef AFS_LINUX20_ENV
325 old = (void (*)(int))signal(SIGSYS, SIG_IGN);
327 rcode = syscall(AFS_SYSCALL, 28 /* AFSCALL_CALL */ , a3, a4, a5);
328 # ifndef AFS_LINUX20_ENV
336 #if !defined(AFS_NT40_ENV)
337 # include "AFS_component_version_number.c"
338 #endif /* !AFS_NT40_ENV */
340 #define MAXADMINNAME 64
341 char adminName[MAXADMINNAME];
347 struct afs_stat status;
349 if ((afs_stat("/AdminName", &status)) || /* if file does not exist */
350 (status.st_size <= 0) || /* or it is too short */
351 (status.st_size >= (MAXADMINNAME)) || /* or it is too long */
352 !(fd = afs_open("/AdminName", O_RDONLY, 0))) { /* or the open fails */
353 strcpy(adminName, "System:Administrators"); /* use the default name */
355 (void)read(fd, adminName, status.st_size); /* use name from the file */
358 close(fd); /* close fd if it was opened */
360 } /*CheckAdminName */
366 #if !defined(AFS_NT40_ENV)
369 /* set our 'thread-id' so that the host hold table works */
370 threadId = rx_SetThreadNum();
371 afs_pthread_setname_self(s);
372 ViceLog(0, ("Set thread id 0x%x for '%s'\n", threadId, s));
376 /* This LWP does things roughly every 5 minutes */
378 FiveMinuteCheckLWP(void *unused)
383 ViceLog(1, ("Starting five minute check process\n"));
384 setThreadId("FiveMinuteCheckLWP");
386 #ifdef AFS_DEMAND_ATTACH_FS
388 while (fs_state.mode == FS_MODE_NORMAL) {
389 fs_state.FiveMinuteLWP_tranquil = 1;
397 #ifdef AFS_DEMAND_ATTACH_FS
399 if (fs_state.mode != FS_MODE_NORMAL) {
402 fs_state.FiveMinuteLWP_tranquil = 0;
406 /* close the log so it can be removed */
407 ReOpenLog(AFSDIR_SERVER_FILELOG_FILEPATH); /* don't trunc, just append */
408 ViceLog(2, ("Cleaning up timed out callbacks\n"));
409 if (CleanupTimedOutCallBacks())
410 ViceLog(5, ("Timed out callbacks deleted\n"));
411 ViceLog(2, ("Set disk usage statistics\n"));
413 if (FS_registered == 1)
415 /* Force wakeup in case we missed something; pthreads does timedwait */
416 if (printBanner && (++msg & 1)) { /* Every 10 minutes */
417 time_t now = FT_ApproxTime();
419 strftime(tbuffer, sizeof(tbuffer), "%a %b %d %H:%M:%S %Y",
420 localtime_r(&now, &tm));
422 ("File server is running at %s\n", tbuffer));
424 #ifdef AFS_DEMAND_ATTACH_FS
428 #ifdef AFS_DEMAND_ATTACH_FS
429 fs_state.FiveMinuteLWP_tranquil = 1;
431 CV_BROADCAST(&fs_state.worker_done_cv);
436 } /*FiveMinuteCheckLWP */
439 /* This LWP does host checks every 5 minutes: it should not be used for
440 * other 5 minute activities because it may be delayed by timeouts when
441 * it probes the workstations
445 HostCheckLWP(void *unused)
447 ViceLog(1, ("Starting Host check process\n"));
448 setThreadId("HostCheckLWP");
449 #ifdef AFS_DEMAND_ATTACH_FS
451 while (fs_state.mode == FS_MODE_NORMAL) {
452 fs_state.HostCheckLWP_tranquil = 1;
460 #ifdef AFS_DEMAND_ATTACH_FS
462 if (fs_state.mode != FS_MODE_NORMAL) {
465 fs_state.HostCheckLWP_tranquil = 0;
469 ViceLog(2, ("Checking for dead venii & clients\n"));
472 #ifdef AFS_DEMAND_ATTACH_FS
476 #ifdef AFS_DEMAND_ATTACH_FS
477 fs_state.HostCheckLWP_tranquil = 1;
479 CV_BROADCAST(&fs_state.worker_done_cv);
486 /* This LWP does fsync checks every 5 minutes: it should not be used for
487 * other 5 minute activities because it may be delayed by timeouts when
488 * it probes the workstations
491 FsyncCheckLWP(void *unused)
494 struct timespec fsync_next;
495 ViceLog(1, ("Starting fsync check process\n"));
497 setThreadId("FsyncCheckLWP");
499 #ifdef AFS_DEMAND_ATTACH_FS
501 while (fs_state.mode == FS_MODE_NORMAL) {
502 fs_state.FsyncCheckLWP_tranquil = 1;
508 /* rounding is fine */
509 fsync_next.tv_nsec = 0;
510 fsync_next.tv_sec = time(0) + fiveminutes;
512 code = CV_TIMEDWAIT(&fsync_cond, &fsync_glock_mutex,
514 if (code != 0 && code != ETIMEDOUT)
515 ViceLog(0, ("pthread_cond_timedwait returned %d\n", code));
518 #ifdef AFS_DEMAND_ATTACH_FS
520 if (fs_state.mode != FS_MODE_NORMAL) {
523 fs_state.FsyncCheckLWP_tranquil = 0;
525 #endif /* AFS_DEMAND_ATTACH_FS */
527 ViceLog(2, ("Checking for fsync events\n"));
529 code = BreakLaterCallBacks();
531 #ifdef AFS_DEMAND_ATTACH_FS
535 #ifdef AFS_DEMAND_ATTACH_FS
536 fs_state.FsyncCheckLWP_tranquil = 1;
538 CV_BROADCAST(&fs_state.worker_done_cv);
541 #endif /* AFS_DEMAND_ATTACH_FS */
545 /*------------------------------------------------------------------------
546 * PRIVATE ClearXStatValues
549 * Initialize all of the values collected via the xstat
559 * Must be called during File Server initialization.
563 *------------------------------------------------------------------------*/
566 ClearXStatValues(void)
567 { /*ClearXStatValues */
569 struct fs_stats_opTimingData *opTimeP; /*Ptr to timing struct */
570 struct fs_stats_xferData *opXferP; /*Ptr to xfer struct */
571 int i; /*Loop counter */
574 * Zero all xstat-related structures.
576 memset((&afs_perfstats), 0, sizeof(struct afs_PerfStats));
577 memset((&afs_FullPerfStats), 0,
578 sizeof(struct fs_stats_FullPerfStats));
581 * That's not enough. We have to set reasonable minima for
582 * time and xfer values in the detailed stats.
584 opTimeP = &(afs_FullPerfStats.det.rpcOpTimes[0]);
585 for (i = 0; i < FS_STATS_NUM_RPC_OPS; i++, opTimeP++)
586 opTimeP->minTime.tv_sec = 999999;
588 opXferP = &(afs_FullPerfStats.det.xferOpTimes[0]);
589 for (i = 0; i < FS_STATS_NUM_XFER_OPS; i++, opXferP++) {
590 opXferP->minTime.tv_sec = 999999;
591 opXferP->minBytes = 999999999;
595 * There's more. We have to set our unique system identifier, as
596 * declared in param.h. If such a thing is not defined, we bitch
597 * and declare ourselves to be an unknown system type.
600 afs_perfstats.sysname_ID = SYS_NAME_ID;
602 # ifndef AFS_NT40_ENV
603 ViceLog(0, ("Sys name ID constant not defined in param.h!!\n"));
604 ViceLog(0, ("[Choosing ``undefined'' sys name ID.\n"));
606 afs_perfstats.sysname_ID = SYS_NAME_ID_UNDEFINED;
607 # endif /* SYS_NAME_ID */
609 } /*ClearXStatValues */
611 int CopyOnWrite_calls = 0, CopyOnWrite_off0 = 0, CopyOnWrite_size0 = 0;
612 afs_fsize_t CopyOnWrite_maxsize = 0;
617 int dirbuff, dircall, dirio;
619 int workstations, activeworkstations, delworkstations;
623 #ifdef AFS_DEMAND_ATTACH_FS
627 FT_GetTimeOfDay(&tpl, 0);
629 strftime(tbuffer, sizeof(tbuffer), "%a %b %d %H:%M:%S %Y",
630 localtime_r(&StartTime, &tm));
631 ViceLog(0, ("Vice was last started at %s\n", tbuffer));
633 #ifdef AFS_DEMAND_ATTACH_FS
634 if (LogLevel >= 125) {
635 stats_flags = VOL_STATS_PER_CHAIN2;
636 } else if (LogLevel >= 25) {
637 stats_flags = VOL_STATS_PER_CHAIN;
639 VPrintExtendedCacheStats(stats_flags);
643 DStat(&dirbuff, &dircall, &dirio);
645 ("With %d directory buffers; %d reads resulted in %d read I/Os\n",
646 dirbuff, dircall, dirio));
647 rx_PrintStats(stderr);
648 audit_PrintStats(stderr);
650 PrintCallBackStats();
652 processSize = -1; /* TODO: */
654 processSize = (int)((long)sbrk(0) >> 10);
657 ("There are %d connections, process size %d\n",
658 CurrentConnections, processSize));
659 h_GetWorkStats(&workstations, &activeworkstations, &delworkstations,
660 tpl.tv_sec - 15 * 60);
662 ("There are %d workstations, %d are active (req in < 15 mins), %d marked \"down\"\n",
663 workstations, activeworkstations, delworkstations));
664 ViceLog(0, ("CopyOnWrite: calls %d off0 %d size0 %d maxsize 0x%llx\n",
665 CopyOnWrite_calls, CopyOnWrite_off0, CopyOnWrite_size0, CopyOnWrite_maxsize));
674 CheckSignal(void *unused)
676 if (FS_registered > 0) {
678 * We have proper ip addresses; tell the vlserver what we got; the following
679 * routine will do the proper reporting for us
692 ShutdownWatchdogLWP(void *unused)
694 afs_pthread_setname_self("ShutdownWatchdog");
695 sleep(panic_timeout);
696 ViceLogThenPanic(0, ("ShutdownWatchdogLWP: Failed to shutdown and panic "
697 "within %d seconds; forcing panic\n",
703 ShutDownAndCore(int dopanic)
705 time_t now = time(NULL);
710 pthread_t watchdogPid;
711 pthread_attr_t tattr;
712 osi_Assert(pthread_attr_init(&tattr) == 0);
713 osi_Assert(pthread_create(&watchdogPid, &tattr, ShutdownWatchdogLWP, NULL) == 0);
716 /* do not allows new reqests to be served from now on, all new requests
717 * are returned with an error code of RX_RESTARTING ( transient failure ) */
718 rx_SetRxTranquil(); /* dhruba */
722 #ifdef AFS_DEMAND_ATTACH_FS
724 if (fs_state.mode == FS_MODE_SHUTDOWN) {
725 /* it is possible for at least fs_stateSave() (called below) to call
726 * ShutDownAndCore if there's host list corruption; prevent
727 * deinitializing some stuff twice */
728 ViceLog(0, ("ShutDownAndCore called during shutdown? Skipping volume "
729 "and host package shutdown\n"));
733 fs_state.mode = FS_MODE_SHUTDOWN;
737 strftime(tbuffer, sizeof(tbuffer), "%a %b %d %H:%M:%S %Y",
738 localtime_r(&now, &tm));
739 ViceLog(0, ("Shutting down file server at %s\n", tbuffer));
741 ViceLog(0, ("ABNORMAL SHUTDOWN, see core file.\n"));
746 /* shut down volume package */
749 #ifdef AFS_DEMAND_ATTACH_FS
750 if (fs_state.options.fs_state_save) {
753 * save fileserver state to disk */
756 ViceLog(0, ("Not saving fileserver state; abnormal shutdown\n"));
759 /* make sure background threads have finished all of their asynchronous
760 * work on host and callback structures */
762 while (!fs_state.FiveMinuteLWP_tranquil ||
763 !fs_state.HostCheckLWP_tranquil ||
764 !fs_state.FsyncCheckLWP_tranquil) {
767 ViceLog(0, ("waiting for background host/callback threads to quiesce before saving fileserver state...\n"));
768 CV_WAIT(&fs_state.worker_done_cv, &fileproc_glock_mutex);
774 /* ok. it should now be fairly safe. let's do the state dump */
780 #endif /* AFS_DEMAND_ATTACH_FS */
783 rx_PrintStats(debugFile);
787 strftime(tbuffer, sizeof(tbuffer), "%a %b %d %H:%M:%S %Y",
788 localtime_r(&now, &tm));
790 ViceLog(0, ("File server has terminated abnormally at %s\n", tbuffer));
792 ViceLog(0, ("File server has terminated normally at %s\n", tbuffer));
795 if (dopanic) /* XXX pass in file and line? */
796 osi_Panic("Panic requested\n");
802 ShutDown(void *unused)
803 { /* backward compatibility */
804 ShutDownAndCore(DONTPANIC);
809 ParseRights(char *arights)
815 if (!arights || !strcmp(arights, "")) {
816 printf("Missing list of mode bits on -implicit option\n");
819 if (!strcmp(arights, "none"))
821 else if (!strcmp(arights, "read"))
822 mode = PRSFS_READ | PRSFS_LOOKUP;
823 else if (!strcmp(arights, "write"))
825 PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
826 PRSFS_WRITE | PRSFS_LOCK;
827 else if (!strcmp(arights, "all"))
829 PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
830 PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER;
832 len = strlen(arights);
833 for (i = 0; i < len; i++) {
838 mode |= PRSFS_LOOKUP;
840 mode |= PRSFS_INSERT;
842 mode |= PRSFS_DELETE;
848 mode |= PRSFS_ADMINISTER;
866 printf("Illegal -implicit rights character '%c'.\n", tc);
875 * Limit MAX_FILESERVER_THREAD by the system limit on the number of
876 * pthreads (sysconf(_SC_THREAD_THREADS_MAX)), if applicable and
879 * AIX: sysconf() limit is real
880 * HP-UX: sysconf() limit is real
881 * IRIX: sysconf() limit is apparently NOT real -- too small
882 * DUX: sysconf() limit is apparently NOT real -- too big
883 * Linux: sysconf() limit is apparently NOT real -- too big
884 * Solaris: no sysconf() limit
887 max_fileserver_thread(void)
889 #if defined(AFS_AIX_ENV) || defined(AFS_HPUX_ENV)
892 ans = sysconf(_SC_THREAD_THREADS_MAX);
893 if (0 < ans && ans < MAX_FILESERVER_THREAD)
896 return MAX_FILESERVER_THREAD;
900 extern ih_init_params vol_io_params;
925 OPT_offline_shutdown_timeout,
926 OPT_vhandle_setaside,
927 OPT_vhandle_max_cachesize,
928 OPT_vhandle_initial_cachesize,
929 OPT_fs_state_dont_save,
930 OPT_fs_state_dont_restore,
937 OPT_unsafe_nosalvage,
964 ParseArgs(int argc, char *argv[])
969 struct cmd_item *optlist;
970 struct cmd_syndesc *opts;
973 char *auditFileName = NULL;
975 #if defined(AFS_AIX32_ENV)
976 extern int aixlow_water;
979 opts = cmd_CreateSyntax(NULL, NULL, NULL, NULL);
981 /* fileserver options */
982 cmd_AddParmAtOffset(opts, OPT_large, "-L", CMD_FLAG,
983 CMD_OPTIONAL, "defaults for a 'large' server");
984 cmd_AddParmAtOffset(opts, OPT_small, "-S", CMD_FLAG,
985 CMD_OPTIONAL, "defaults for a 'small' server");
987 cmd_AddParmAtOffset(opts, OPT_banner, "-banner", CMD_FLAG,
988 CMD_OPTIONAL, "print regular banners to log");
989 cmd_AddParmAtOffset(opts, OPT_implicit, "-implicit", CMD_SINGLE,
990 CMD_OPTIONAL, "implicit admin access bits");
992 #if defined(AFS_SGI_ENV)
993 cmd_AddParmAtOffset(opts, OPT_lock, "-lock", CMD_FLAG,
994 CMD_OPTIONAL, "lock filserver binary in memory");
996 cmd_AddParmAtOffset(opts, OPT_readonly, "-readonly", CMD_FLAG,
997 CMD_OPTIONAL, "be a readonly fileserver");
998 cmd_AddParmAtOffset(opts, OPT_saneacls, "-saneacls", CMD_FLAG,
999 CMD_OPTIONAL, "set the saneacls capability bit");
1001 cmd_AddParmAtOffset(opts, OPT_buffers, "-b", CMD_SINGLE,
1002 CMD_OPTIONAL, "buffers");
1003 cmd_AddParmAtOffset(opts, OPT_callbacks, "-cb", CMD_SINGLE,
1004 CMD_OPTIONAL, "number of callbacks");
1005 cmd_AddParmAtOffset(opts, OPT_vcsize, "-vc", CMD_SINGLE,
1006 CMD_OPTIONAL, "volume cachesize");
1007 cmd_AddParmAtOffset(opts, OPT_lvnodes, "-l", CMD_SINGLE,
1008 CMD_OPTIONAL, "large vnodes");
1009 cmd_AddParmAtOffset(opts, OPT_svnodes, "-s", CMD_SINGLE,
1010 CMD_OPTIONAL, "small vnodes");
1011 cmd_AddParmAtOffset(opts, OPT_sendsize, "-sendsize", CMD_SINGLE,
1012 CMD_OPTIONAL, "size of send buffer in bytes");
1014 #if defined(AFS_AIX32_ENV)
1015 cmd_AddParmAtOffset(opts, OPT_minspare, "-m", CMD_SINGLE,
1016 CMD_OPTIONAL, "minimum percentage spare in partition");
1019 cmd_AddParmAtOffset(opts, OPT_spare, "-spare", CMD_SINGLE,
1020 CMD_OPTIONAL, "kB overage on volume quota");
1021 cmd_AddParmAtOffset(opts, OPT_pctspare, "pctspare", CMD_SINGLE,
1022 CMD_OPTIONAL, "percentage overage on volume quota");
1024 cmd_AddParmAtOffset(opts, OPT_hostcpsrefresh, "-hr", CMD_SINGLE,
1025 CMD_OPTIONAL, "hours between host CPS refreshes");
1027 cmd_AddParmAtOffset(opts, OPT_vattachthreads, "-vattachpar", CMD_SINGLE,
1028 CMD_OPTIONAL, "# of volume attachment threads");
1030 cmd_AddParmAtOffset(opts, OPT_abortthreshold, "-abortthreshold",
1031 CMD_SINGLE, CMD_OPTIONAL,
1033 cmd_AddParmAtOffset(opts, OPT_busyat, "-busyat", CMD_SINGLE, CMD_OPTIONAL,
1034 "# of queued entries after which server is busy");
1035 cmd_AddParmAtOffset(opts, OPT_nobusy, "-nobusy", CMD_FLAG, CMD_OPTIONAL,
1036 "send VRESTARTING while restarting the server");
1038 cmd_AddParmAtOffset(opts, OPT_offline_timeout, "-offline-timeout",
1039 CMD_SINGLE, CMD_OPTIONAL,
1040 "timeout for offlining volumes");
1041 cmd_AddParmAtOffset(opts, OPT_offline_shutdown_timeout,
1042 "-offline-shutdown-timeout", CMD_SINGLE, CMD_OPTIONAL,
1043 "timeout offlining volumes during shutdown");
1045 cmd_AddParmAtOffset(opts, OPT_vhandle_setaside, "-vhandle-setaside",
1046 CMD_SINGLE, CMD_OPTIONAL,
1047 "# fds reserved for non-cache IO");
1048 cmd_AddParmAtOffset(opts, OPT_vhandle_max_cachesize,
1049 "-vhandle-max-cachesize", CMD_SINGLE, CMD_OPTIONAL,
1051 cmd_AddParmAtOffset(opts, OPT_vhandle_initial_cachesize,
1052 "-vhandle-initial-cachesize", CMD_SINGLE,
1053 CMD_OPTIONAL, "# fds reserved for cache IO");
1055 #ifdef AFS_DEMAND_ATTACH_FS
1057 cmd_AddParmAtOffset(opts, OPT_fs_state_dont_save,
1058 "-fs-state-dont-save", CMD_FLAG, CMD_OPTIONAL,
1059 "disable state save during shutdown");
1060 cmd_AddParmAtOffset(opts, OPT_fs_state_dont_restore,
1061 "-fs-state-dont-restore", CMD_FLAG, CMD_OPTIONAL,
1062 "disable state restore during startup");
1063 cmd_AddParmAtOffset(opts, OPT_fs_state_verify, "-fs-state-verify",
1064 CMD_SINGLE, CMD_OPTIONAL, "none|save|restore|both");
1065 cmd_AddParmAtOffset(opts, OPT_vhashsize, "-vhashsize",
1066 CMD_SINGLE, CMD_OPTIONAL,
1067 "log(2) of # of volume hash buckets");
1068 cmd_AddParmAtOffset(opts, OPT_vlrudisable, "-vlrudisable",
1069 CMD_FLAG, CMD_OPTIONAL, "disable VLRU functionality");
1070 cmd_AddParmAtOffset(opts, OPT_vlruthresh, "-vlruthresh",
1071 CMD_FLAG, CMD_OPTIONAL,
1072 "mins before unused vols become eligible for detach");
1073 cmd_AddParmAtOffset(opts, OPT_vlruinterval, "-vlruinterval",
1074 CMD_FLAG, CMD_OPTIONAL, "secs between VLRU scans");
1075 cmd_AddParmAtOffset(opts, OPT_vlrumax, "-vlrumax", CMD_FLAG, CMD_OPTIONAL,
1076 "max volumes to detach in one scan");
1077 cmd_AddParmAtOffset(opts, OPT_unsafe_nosalvage, "-unsafe-nosalvage",
1078 CMD_FLAG, CMD_OPTIONAL,
1079 "bybass safety checks on volume attach");
1082 /* unrecommend options - should perhaps be CMD_HIDE */
1083 cmd_AddParmAtOffset(opts, OPT_stack, "-k", CMD_SINGLE, CMD_OPTIONAL,
1085 cmd_AddParmAtOffset(opts, OPT_cbwait, "-w", CMD_SINGLE, CMD_OPTIONAL,
1086 "callback wait interval");
1087 cmd_AddParmAtOffset(opts, OPT_novbc, "-novbc", CMD_SINGLE, CMD_FLAG,
1088 "disable callback breaks on reattach");
1090 /* general options */
1091 cmd_AddParmAtOffset(opts, OPT_auditlog, "-auditlog", CMD_SINGLE,
1092 CMD_OPTIONAL, "location of audit log");
1093 cmd_AddParmAtOffset(opts, OPT_auditiface, "-audit-interface", CMD_SINGLE,
1094 CMD_OPTIONAL, "interface to use for audit logging");
1095 cmd_AddParmAtOffset(opts, OPT_config, "-config", CMD_SINGLE, CMD_OPTIONAL,
1096 "configuration location");
1097 cmd_AddParmAtOffset(opts, OPT_debug, "-d", CMD_SINGLE, CMD_OPTIONAL,
1099 cmd_AddParmAtOffset(opts, OPT_logfile, "-logfile", CMD_SINGLE,
1100 CMD_OPTIONAL, "location of logfile");
1101 cmd_AddParmAtOffset(opts, OPT_mrafslogs, "-mrafslogs", CMD_FLAG,
1102 CMD_OPTIONAL, "enable MRAFS style logging");
1103 cmd_AddParmAtOffset(opts, OPT_threads, "-p", CMD_SINGLE, CMD_OPTIONAL,
1104 "number of threads");
1105 #if !defined(AFS_NT40_ENV)
1106 cmd_AddParmAtOffset(opts, OPT_syslog, "-syslog", CMD_SINGLE_OR_FLAG,
1107 CMD_OPTIONAL, "log to syslog");
1111 cmd_AddParmAtOffset(opts, OPT_peer, "-enable_peer_stats", CMD_FLAG,
1112 CMD_OPTIONAL, "enable RX transport statistics");
1113 cmd_AddParmAtOffset(opts, OPT_process, "-enable_process_stats", CMD_FLAG,
1114 CMD_OPTIONAL, "enable RX RPC statistics");
1115 cmd_AddParmAtOffset(opts, OPT_nojumbo, "-nojumbo", CMD_FLAG,
1116 CMD_OPTIONAL, "disable jumbograms");
1117 cmd_AddParmAtOffset(opts, OPT_jumbo, "-jumbo", CMD_FLAG, CMD_OPTIONAL,
1118 "enable jumbograms");
1119 cmd_AddParmAtOffset(opts, OPT_rxbind, "-rxbind", CMD_FLAG, CMD_OPTIONAL,
1120 "bind only to the primary interface");
1121 cmd_AddParmAtOffset(opts, OPT_rxdbg, "-rxdbg", CMD_FLAG, CMD_OPTIONAL,
1122 "enable rx debugging");
1123 cmd_AddParmAtOffset(opts, OPT_rxdbge, "-rxdbge", CMD_FLAG, CMD_OPTIONAL,
1124 "enable rx event debugging");
1125 cmd_AddParmAtOffset(opts, OPT_rxpck, "-rxpck", CMD_SINGLE, CMD_OPTIONAL,
1126 "# of extra rx packets");
1127 cmd_AddParmAtOffset(opts, OPT_rxmaxmtu, "-rxmaxmtu", CMD_SINGLE,
1128 CMD_OPTIONAL, "maximum MTU for RX");
1129 cmd_AddParmAtOffset(opts, OPT_udpsize, "-udpsize", CMD_SINGLE,
1130 CMD_OPTIONAL, "size of socket buffer in bytes");
1133 cmd_AddParmAtOffset(opts, OPT_dotted, "-allow-dotted-principals",
1134 CMD_FLAG, CMD_OPTIONAL,
1135 "permit Kerberos 5 principals with dots");
1136 cmd_AddParmAtOffset(opts, OPT_realm, "-realm",
1137 CMD_LIST, CMD_OPTIONAL, "local realm");
1139 code = cmd_Parse(argc, argv, &opts);
1143 if (cmd_OptionPresent(opts, OPT_large)
1144 && cmd_OptionPresent(opts, OPT_small)) {
1145 printf("Only one of -L or -S must be specified\n");
1149 if (cmd_OptionPresent(opts, OPT_spare)
1150 && cmd_OptionPresent(opts, OPT_pctspare)) {
1151 printf("Both -spare and -pctspare specified, exiting.\n");
1155 if (cmd_OptionPresent(opts, OPT_large)) {
1159 numberofcbs = 64000;
1165 if (cmd_OptionPresent(opts, OPT_small)) {
1169 numberofcbs = 20000;
1175 cmd_OptionAsFlag(opts, OPT_banner, &printBanner);
1177 if (cmd_OptionAsString(opts, OPT_implicit, &optstring) == 0) {
1178 implicitAdminRights = ParseRights(optstring);
1181 if (implicitAdminRights < 0)
1182 return implicitAdminRights;
1185 #if defined(AFS_SGI_ENV)
1186 cmd_OptionAsFlag(opts, OPT_lock, &SawLock);
1188 cmd_OptionAsFlag(opts, OPT_readonly, &readonlyServer);
1189 cmd_OptionAsFlag(opts, OPT_saneacls, &saneacls);
1190 cmd_OptionAsInt(opts, OPT_buffers, &buffs);
1192 if (cmd_OptionAsInt(opts, OPT_callbacks, &numberofcbs) == 0) {
1193 printf("number of cbs %d invalid; "
1194 "must be between 10000 and 2147483647\n", numberofcbs);
1198 cmd_OptionAsInt(opts, OPT_vcsize, &volcache);
1199 cmd_OptionAsInt(opts, OPT_lvnodes, &large);
1200 cmd_OptionAsInt(opts, OPT_svnodes, &nSmallVns);
1201 if (cmd_OptionAsInt(opts, OPT_sendsize, &optval) == 0) {
1202 if (optval < 16384) {
1203 printf("Warning:sendsize %d is less than minimum %d; ignoring\n",
1206 sendBufSize = optval;
1209 #if defined(AFS_AIX32_ENV)
1210 if (cmd_OptionAsInt(opts, OPT_minspare, &aixlow_water) == 0) {
1211 if ((aixlow_water < 0) || (aixlow_water > 30)) {
1212 printf("space reserved %d%% invalid; must be between 0-30%\n",
1219 cmd_OptionAsInt(opts, OPT_spare, &BlocksSpare);
1220 if (cmd_OptionAsInt(opts, OPT_pctspare, &PctSpare) == 0) {
1224 if (cmd_OptionAsInt(opts, OPT_hostcpsrefresh, &optval) == 0) {
1225 if ((optval < 1) || (optval > 36)) {
1226 printf("host acl refresh interval of %d hours is invalid; "
1227 "hours must be between 1 and 36\n\n", optval);
1230 hostaclRefresh = optval * 60 * 60;
1233 cmd_OptionAsInt(opts, OPT_vattachthreads, &vol_attach_threads);
1235 cmd_OptionAsInt(opts, OPT_abortthreshold, &abort_threshold);
1237 /* busyat is at the end, as rxpackets has to be set before we can use it */
1238 if (cmd_OptionPresent(opts, OPT_nobusy))
1241 if (cmd_OptionAsInt(opts, OPT_offline_timeout, &offline_timeout) == 0) {
1242 if (offline_timeout < -1) {
1243 printf("Invalid -offline-timeout value %d; the only valid "
1244 "negative value is -1\n", offline_timeout);
1249 if (cmd_OptionAsInt(opts, OPT_offline_shutdown_timeout,
1250 &offline_shutdown_timeout) == 0) {
1251 if (offline_shutdown_timeout < -1) {
1252 printf("Invalid -offline-timeout value %d; the only valid "
1253 "negative value is -1\n", offline_shutdown_timeout);
1258 cmd_OptionAsUint(opts, OPT_vhandle_setaside,
1259 &vol_io_params.fd_handle_setaside);
1260 cmd_OptionAsUint(opts, OPT_vhandle_max_cachesize,
1261 &vol_io_params.fd_max_cachesize);
1262 cmd_OptionAsUint(opts, OPT_vhandle_initial_cachesize,
1263 &vol_io_params.fd_initial_cachesize);
1265 #ifdef AFS_DEMAND_ATTACH_FS
1266 if (cmd_OptionPresent(opts, OPT_fs_state_dont_save))
1267 fs_state.options.fs_state_save = 0;
1268 if (cmd_OptionPresent(opts, OPT_fs_state_dont_restore))
1269 fs_state.options.fs_state_restore = 0;
1270 if (cmd_OptionAsString(opts, OPT_fs_state_verify, &optstring) == 0) {
1271 if (strcmp(optstring, "none") == 0) {
1272 fs_state.options.fs_state_verify_before_save = 0;
1273 fs_state.options.fs_state_verify_after_restore = 0;
1274 } else if (strcmp(optstring, "save") == 0) {
1275 fs_state.options.fs_state_verify_after_restore = 0;
1276 } else if (strcmp(optstring, "restore") == 0) {
1277 fs_state.options.fs_state_verify_before_save = 0;
1278 } else if (strcmp(optstring, "both") == 0) {
1281 fprintf(stderr, "invalid argument for -fs-state-verify\n");
1285 if (cmd_OptionAsInt(opts, OPT_vhashsize, &optval) == 0) {
1286 if (VSetVolHashSize(optval)) {
1287 fprintf(stderr, "specified -vhashsize (%d) is invalid or out "
1288 "of range\n", optval);
1292 if (cmd_OptionPresent(opts, OPT_vlrudisable))
1293 VLRU_SetOptions(VLRU_SET_ENABLED, 0);
1294 if (cmd_OptionAsInt(opts, OPT_vlruthresh, &optval) == 0)
1295 VLRU_SetOptions(VLRU_SET_THRESH, 60*optval);
1296 if (cmd_OptionAsInt(opts, OPT_vlruinterval, &optval) == 0)
1297 VLRU_SetOptions(VLRU_SET_INTERVAL, optval);
1298 if (cmd_OptionAsInt(opts, OPT_vlrumax, &optval) == 0)
1299 VLRU_SetOptions(VLRU_SET_MAX, optval);
1300 cmd_OptionAsFlag(opts, OPT_unsafe_nosalvage, &unsafe_attach);
1301 #endif /* AFS_DEMAND_ATTACH_FS */
1303 cmd_OptionAsInt(opts, OPT_stack, &stack);
1304 cmd_OptionAsInt(opts, OPT_cbwait, &fiveminutes);
1305 cmd_OptionAsFlag(opts, OPT_novbc, &novbc);
1307 /* general server options */
1308 cmd_OptionAsString(opts, OPT_auditlog, &auditFileName);
1310 if (cmd_OptionAsString(opts, OPT_auditiface, &optstring) == 0) {
1311 if (osi_audit_interface(optstring)) {
1312 printf("Invalid audit interface '%s'\n", optstring);
1319 /* XXX - cmd_OptionAsString(opts, OPT_config, &configDir); */
1320 cmd_OptionAsInt(opts, OPT_debug, &LogLevel);
1321 /* XXX - cmd_OptionAsString(opts, OPT_logfile, &logFile); */
1322 cmd_OptionAsFlag(opts, OPT_mrafslogs, &mrafsStyleLogs);
1324 if (cmd_OptionAsInt(opts, OPT_threads, &lwps) == 0) {
1325 lwps_max = max_fileserver_thread() - FILESERVER_HELPER_THREADS;
1326 if (lwps > lwps_max)
1332 #ifndef AFS_NT40_ENV
1333 if (cmd_OptionPresent(opts, OPT_syslog)) {
1334 serverLogSyslog = 1;
1335 cmd_OptionAsInt(opts, OPT_syslog, &serverLogSyslogFacility);
1339 if (cmd_OptionPresent(opts, OPT_peer))
1340 rx_enablePeerRPCStats();
1341 if (cmd_OptionPresent(opts, OPT_process))
1342 rx_enableProcessRPCStats();
1343 if (cmd_OptionPresent(opts, OPT_nojumbo))
1345 if (cmd_OptionPresent(opts, OPT_jumbo))
1347 cmd_OptionAsFlag(opts, OPT_rxbind, &rxBind);
1348 cmd_OptionAsFlag(opts, OPT_rxdbg, &rxlog);
1349 cmd_OptionAsFlag(opts, OPT_rxdbge, &eventlog);
1350 cmd_OptionAsInt(opts, OPT_rxpck, &rxpackets);
1352 cmd_OptionAsInt(opts, OPT_rxmaxmtu, &rxMaxMTU);
1354 if (cmd_OptionAsInt(opts, OPT_udpsize, &optval) == 0) {
1355 if (optval < rx_GetMinUdpBufSize()) {
1356 printf("Warning:udpsize %d is less than minimum %d; ignoring\n",
1357 optval, rx_GetMinUdpBufSize());
1359 udpBufSize = optval;
1363 cmd_OptionAsFlag(opts, OPT_dotted, &rxkadDisableDotCheck);
1364 if (cmd_OptionAsList(opts, OPT_realm, &optlist) == 0) {
1366 for (; optlist != NULL; optlist=optlist->next) {
1367 if (strlen(optlist->data) >= AFS_REALM_SZ) {
1368 printf("-realm argument must contain fewer than %d "
1369 "characters.\n", AFS_REALM_SZ);
1372 afsconf_SetLocalRealm(optlist->data); /* overrides krb.conf file, if one */
1376 /* anything setting rxpackets must come before this */
1377 if (cmd_OptionAsInt(opts, OPT_busyat, &optval) == 0) {
1379 printf("Busy threshold %d is too low, will use default.\n",
1381 busy_threshold = 3 * rxpackets / 2;
1383 busy_threshold = optval;
1386 busy_threshold = 3 * rxpackets / 2;
1390 osi_audit_file(auditFileName);
1395 /* Once upon a time, in a galaxy far far away, IBM AFS supported the use of
1396 * a file /vice/file/parms, the contents of which would override any command
1397 * line parameters. We no longer support the use of such a file, but we warn
1398 * if we encounter its presence from an older release
1403 struct afs_stat sbuf;
1405 if (afs_stat("/vice/file/parms", &sbuf) == 0) {
1406 ViceLog(0, ("Using /vice/file/parms to override command line "
1407 "options is no longer supported"));
1411 /* Miscellaneous routines */
1413 Die(const char *msg)
1416 ViceLogThenPanic(0, ("%s\n", msg));
1426 * If this fails, it's because something major is wrong, and is not
1427 * likely to be time dependent.
1429 code = pr_Initialize(2, AFSDIR_SERVER_ETC_DIRPATH, 0);
1432 ("Couldn't initialize protection library; code=%d.\n", code));
1436 osi_Assert(pthread_key_create(&viced_uclient_key, NULL) == 0);
1438 SystemId = SYSADMINID;
1439 SystemAnyUser = ANYUSERID;
1440 SystemAnyUserCPS.prlist_len = 0;
1441 SystemAnyUserCPS.prlist_val = NULL;
1442 AnonCPS.prlist_len = 0;
1443 AnonCPS.prlist_val = NULL;
1445 code = pr_GetCPS(SystemAnyUser, &SystemAnyUserCPS);
1448 ("Couldn't get CPS for AnyUser, will try again in 30 seconds; code=%d.\n",
1452 code = pr_GetCPS(ANONYMOUSID, &AnonCPS);
1455 ("Couldn't get Anonymous CPS, exiting; code=%d.\n",
1459 AnonymousID = ANONYMOUSID;
1466 struct rx_connection *serverconns[MAXSERVERS];
1467 struct ubik_client *cstruct;
1470 vl_Initialize(const char *confDir)
1473 afs_int32 scIndex = RX_SECIDX_NULL;
1474 struct afsconf_dir *tdir;
1475 struct rx_securityClass *sc;
1476 struct afsconf_cell info;
1478 tdir = afsconf_Open(confDir);
1481 ("Could not open configuration directory (%s).\n", confDir));
1484 code = afsconf_ClientAuth(tdir, &sc, &scIndex);
1486 ViceLog(0, ("Could not get security object for localAuth\n"));
1489 code = afsconf_GetCellInfo(tdir, NULL, AFSCONF_VLDBSERVICE, &info);
1490 if (info.numServers > MAXSERVERS) {
1492 ("vl_Initialize: info.numServers=%d (> MAXSERVERS=%d)\n",
1493 info.numServers, MAXSERVERS));
1496 for (i = 0; i < info.numServers; i++)
1498 rx_NewConnection(info.hostAddr[i].sin_addr.s_addr,
1499 info.hostAddr[i].sin_port, USER_SERVICE_ID, sc,
1501 code = ubik_ClientInit(serverconns, &cstruct);
1502 afsconf_Close(tdir);
1504 ViceLog(0, ("vl_Initialize: ubik client init failed.\n"));
1510 #define SYSIDMAGIC 0x88aabbcc
1511 #define SYSIDVERSION 1
1516 afs_int32 fd, nentries, i;
1517 struct versionStamp vsn;
1518 struct afs_stat status;
1521 if ((afs_stat(AFSDIR_SERVER_SYSID_FILEPATH, &status))
1522 || (status.st_size <= 0)) {
1523 ViceLog(0, ("%s: doesn't exist\n", AFSDIR_SERVER_SYSID_FILEPATH));
1526 if (!(fd = afs_open(AFSDIR_SERVER_SYSID_FILEPATH, O_RDONLY, 0))) {
1528 ("%s: can't open (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1532 if (read(fd, (char *)&vsn, sizeof(vsn)) != sizeof(vsn)) {
1534 ("%s: Read failed (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1538 if (vsn.magic != SYSIDMAGIC) {
1540 ("%s: wrong magic %x (we support %x)\n",
1541 AFSDIR_SERVER_SYSID_FILEPATH, vsn.magic, SYSIDMAGIC));
1544 if (vsn.version != SYSIDVERSION) {
1546 ("%s: wrong version %d (we support %d)\n",
1547 AFSDIR_SERVER_SYSID_FILEPATH, vsn.version, SYSIDVERSION));
1550 if (read(fd, (char *)&uuid, sizeof(struct afsUUID))
1551 != sizeof(struct afsUUID)) {
1553 ("%s: read of uuid failed (%d)\n",
1554 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1557 afs_ntohuuid(&uuid);
1559 if (read(fd, (char *)&nentries, sizeof(afs_int32)) != sizeof(afs_int32)) {
1561 ("%s: Read of entries failed (%d)\n",
1562 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1565 if (nentries <= 0 || nentries > ADDRSPERSITE) {
1567 ("%s: invalid num of interfaces: %d\n",
1568 AFSDIR_SERVER_SYSID_FILEPATH, nentries));
1571 if (FS_HostAddr_cnt == 0) {
1572 FS_HostAddr_cnt = nentries;
1573 for (i = 0; i < nentries; i++) {
1574 if (read(fd, (char *)&FS_HostAddrs[i], sizeof(afs_int32)) !=
1575 sizeof(afs_int32)) {
1577 ("%s: Read of addresses failed (%d)\n",
1578 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1579 FS_HostAddr_cnt = 0; /* reset it */
1585 ("%s: address list ignored (NetInfo/NetRestrict override)\n",
1586 AFSDIR_SERVER_SYSID_FILEPATH));
1593 WriteSysIdFile(void)
1596 struct versionStamp vsn;
1597 struct afs_stat status;
1600 if (!afs_stat(AFSDIR_SERVER_SYSID_FILEPATH, &status)) {
1602 * File exists; keep the old one around
1604 renamefile(AFSDIR_SERVER_SYSID_FILEPATH,
1605 AFSDIR_SERVER_OLDSYSID_FILEPATH);
1607 fd = afs_open(AFSDIR_SERVER_SYSID_FILEPATH, O_WRONLY | O_TRUNC | O_CREAT,
1611 ("%s: can't create (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1615 vsn.magic = SYSIDMAGIC;
1617 if ((i = write(fd, (char *)&vsn, sizeof(vsn))) != sizeof(vsn)) {
1619 ("%s: write failed (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1624 afs_htonuuid(&uuid);
1626 write(fd, (char *)&uuid,
1627 sizeof(struct afsUUID))) != sizeof(struct afsUUID)) {
1629 ("%s: write of uuid failed (%d)\n",
1630 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1634 write(fd, (char *)&FS_HostAddr_cnt,
1635 sizeof(afs_int32))) != sizeof(afs_int32)) {
1637 ("%s: write of # of entries failed (%d)\n",
1638 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1641 for (i = 0; i < FS_HostAddr_cnt; i++) {
1642 if (write(fd, (char *)&FS_HostAddrs[i], sizeof(afs_int32)) !=
1643 sizeof(afs_int32)) {
1645 ("%s: write of addresses failed (%d)\n",
1646 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1656 * This routine sets up the buffers for the VL_RegisterAddrs RPC. All addresses
1657 * in FS_HostAddrs[] are in NBO, while the RPC treats them as a "blob" of data
1658 * and so we need to convert each of them into HBO which is what the extra
1659 * array called FS_HostAddrs_HBO is used here.
1662 Do_VLRegisterRPC(void)
1666 afs_uint32 FS_HostAddrs_HBO[ADDRSPERSITE];
1669 for (i = 0; i < FS_HostAddr_cnt; i++)
1670 FS_HostAddrs_HBO[i] = ntohl(FS_HostAddrs[i]);
1671 addrs.bulkaddrs_len = FS_HostAddr_cnt;
1672 addrs.bulkaddrs_val = (afs_uint32 *) FS_HostAddrs_HBO;
1673 code = ubik_VL_RegisterAddrs(cstruct, 0, &FS_HostUUID, 0, &addrs);
1675 if (code == VL_MULTIPADDR) {
1677 ("VL_RegisterAddrs rpc failed; The IP address exists on a different server; repair it\n"));
1679 ("VL_RegisterAddrs rpc failed; See VLLog for details\n"));
1681 } else if (code == RXGEN_OPCODE) {
1683 ("vlserver doesn't support VL_RegisterAddrs rpc; ignored\n"));
1684 FS_registered = 2; /* So we don't have to retry in the gc daemon */
1687 ("VL_RegisterAddrs rpc failed; will retry periodically (code=%d, err=%d)\n",
1689 FS_registered = 1; /* Retry in the gc daemon */
1692 FS_registered = 2; /* So we don't have to retry in the gc daemon */
1704 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH || AFSDIR_SERVER_NETINFO_FILEPATH) {
1706 * Find addresses we are supposed to register as per the netrestrict
1707 * and netinfo files (/usr/afs/local/NetInfo and
1708 * /usr/afs/local/NetRestict)
1711 afs_int32 code = parseNetFiles(FS_HostAddrs, NULL, NULL,
1712 ADDRSPERSITE, reason,
1713 AFSDIR_SERVER_NETINFO_FILEPATH,
1714 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
1716 ViceLog(0, ("Can't register any valid addresses: %s\n", reason));
1719 FS_HostAddr_cnt = (afs_uint32) code;
1722 FS_HostAddr_cnt = rx_getAllAddr(FS_HostAddrs, ADDRSPERSITE);
1725 if (FS_HostAddr_cnt == 1 && rxBind == 1)
1726 code = FS_HostAddrs[0];
1728 code = htonl(INADDR_ANY);
1738 * If this fails, it's because something major is wrong, and is not
1739 * likely to be time dependent.
1741 code = vl_Initialize(AFSDIR_SERVER_ETC_DIRPATH);
1744 ("Couldn't initialize volume location library; code=%d.\n", code));
1748 /* Read or create the sysid file and register the fileserver's
1749 * IP addresses with the vlserver.
1751 code = ReadSysIdFile();
1753 /* Need to create the file */
1754 ViceLog(0, ("Creating new SysID file\n"));
1755 if ((code = afs_uuid_create(&FS_HostUUID))) {
1756 ViceLog(0, ("Failed to create new uuid: %d\n", code));
1760 /* A good sysid file exists; inform the vlserver. If any conflicts,
1761 * we always use the latest interface available as the real truth.
1764 code = Do_VLRegisterRPC();
1769 main(int argc, char *argv[])
1773 struct rx_securityClass **securityClasses;
1774 afs_int32 numClasses;
1775 struct rx_service *tservice;
1776 pthread_t serverPid;
1777 pthread_attr_t tattr;
1779 int minVnodesRequired; /* min size of vnode cache */
1780 #ifndef AFS_NT40_ENV
1781 struct rlimit rlim; /* max number of open file descriptors */
1786 afs_uint32 rx_bindhost;
1787 VolumePackageOptions opts;
1789 #ifdef AFS_AIX32_ENV
1790 struct sigaction nsa;
1792 sigemptyset(&nsa.sa_mask);
1793 nsa.sa_handler = SIG_DFL;
1794 nsa.sa_flags = SA_FULLDUMP;
1795 sigaction(SIGABRT, &nsa, NULL);
1796 sigaction(SIGSEGV, &nsa, NULL);
1800 /* Initialize dirpaths */
1801 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
1803 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
1805 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
1809 /* set ihandle package defaults prior to parsing args */
1812 /* check for the parameter file */
1815 if (ParseArgs(argc, argv)) {
1818 MUTEX_INIT(&fileproc_glock_mutex, "fileproc", MUTEX_DEFAULT, 0);
1820 #ifdef AFS_SGI_VNODE_GLUE
1821 if (afs_init_kernel_config(-1) < 0) {
1823 ("Can't determine NUMA configuration, not starting fileserver.\n");
1827 confDir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
1829 fprintf(stderr, "Unable to open config directory %s\n",
1830 AFSDIR_SERVER_ETC_DIRPATH);
1834 /* Open FileLog on stdout, stderr, fd 1 and fd2 (for perror), sigh. */
1835 #ifndef AFS_NT40_ENV
1836 serverLogSyslogTag = "fileserver";
1838 OpenLog(AFSDIR_SERVER_FILELOG_FILEPATH);
1841 LogCommandLine(argc, argv, "starting", "", "File server", FSLog);
1843 #if !defined(AFS_NT40_ENV)
1844 /* initialize the pthread soft signal handler thread */
1848 /* install signal handlers for controlling the fileserver process */
1849 ResetCheckSignal(); /* set CheckSignal_Signal() sig handler */
1850 ResetCheckDescriptors(); /* set CheckDescriptors_Signal() sig handler */
1852 #if defined(AFS_SGI_ENV)
1853 /* give this guy a non-degrading priority so help busy servers */
1854 schedctl(NDPRI, 0, NDPNORMMAX);
1857 #elif !defined(AFS_NT40_ENV)
1858 nice(-5); /* TODO: */
1861 #ifdef AFS_DEMAND_ATTACH_FS
1866 if (afs_winsockInit() < 0) {
1867 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
1868 ViceLog(0, ("File server failed to intialize winsock.\n"));
1874 /* if we support more than 16 threads, then we better have the ability
1875 ** to keep open a large number of files simultaneously
1877 #if defined(AFS_AIX_ENV) && !defined(AFS_AIX42_ENV)
1878 curLimit = OPEN_MAX; /* for pre AIX 4.2 systems */
1879 #elif defined(AFS_NT40_ENV)
1880 curLimit = NT_OPEN_MAX; /* open file descriptor limit on NT */
1883 curLimit = 0; /* the number of open file descriptors */
1884 code = getrlimit(RLIMIT_NOFILE, &rlim);
1886 curLimit = rlim.rlim_cur;
1887 rlim.rlim_cur = rlim.rlim_max;
1888 code = setrlimit(RLIMIT_NOFILE, &rlim);
1890 curLimit = rlim.rlim_max;
1893 ViceLog(0, ("Failed to increase open file limit, using default\n"));
1895 #endif /* defined(AFS_AIX_ENV) && !defined(AFS_AIX42_ENV) */
1897 curLimit -= 32; /* leave a slack of 32 file descriptors */
1898 if (lwps > curLimit) {
1902 lwps = 16; /* default to a maximum of 16 threads */
1904 /* tune the ihandle fd cache accordingly */
1905 if (vol_io_params.fd_max_cachesize < curLimit)
1906 vol_io_params.fd_max_cachesize = curLimit + 1;
1909 ("The system supports a max of %d open files and we are starting %d threads (ihandle fd cache is %d)\n",
1910 curLimit, lwps, vol_io_params.fd_max_cachesize));
1913 /* Initialize volume support */
1915 V_BreakVolumeCallbacks = BreakVolumeCallBacksLater;
1918 SetLogThreadNumProgram( rx_GetThreadNum );
1920 /* initialize libacl routines */
1921 acl_Initialize(ACL_VERSION);
1923 /* initialize RX support */
1924 #ifndef AFS_NT40_ENV
1925 rxi_syscallp = viced_syscall;
1927 rx_extraPackets = rxpackets;
1928 rx_extraQuota = 4; /* for outgoing prserver calls from R threads */
1929 rx_SetBusyThreshold(busy_threshold, VBUSY);
1930 rx_SetCallAbortThreshold(abort_threshold);
1931 rx_SetConnAbortThreshold(abort_threshold);
1933 stackSize = 128 * 1024;
1935 stackSize = lwps * 4000;
1936 if (stackSize < 32000)
1938 else if (stackSize > 44000)
1941 #if defined(AFS_HPUX_ENV) || defined(AFS_SUN_ENV) || defined(AFS_SGI51_ENV) || defined(AFS_XBSD_ENV)
1942 rx_SetStackSize(1, stackSize);
1945 rx_SetUdpBufSize(udpBufSize); /* set the UDP buffer size for receive */
1946 rx_bindhost = SetupVL();
1948 if (rx_InitHost(rx_bindhost, (int)htons(7000)) < 0) {
1949 ViceLog(0, ("Cannot initialize RX\n"));
1952 if (!rxJumbograms) {
1953 /* Don't send and don't allow 3.4 clients to send jumbograms. */
1956 if (rxMaxMTU != -1) {
1957 if (rx_SetMaxMTU(rxMaxMTU) != 0) {
1958 ViceLog(0, ("rxMaxMTU %d is invalid\n", rxMaxMTU));
1963 rx_SetRxDeadTime(30);
1964 afsconf_SetSecurityFlags(confDir, AFSCONF_SECOPTS_ALWAYSENCRYPT);
1965 afsconf_BuildServerSecurityObjects(confDir, &securityClasses, &numClasses);
1967 tservice = rx_NewServiceHost(rx_bindhost, /* port */ 0, /* service id */
1968 1, /*service name */
1970 securityClasses, numClasses,
1971 RXAFS_ExecuteRequest);
1974 ("Failed to initialize RX, probably two servers running.\n"));
1977 if (rxkadDisableDotCheck) {
1978 rx_SetSecurityConfiguration(tservice, RXS_CONFIG_FLAGS,
1979 (void *)RXS_CONFIG_FLAGS_DISABLE_DOTCHECK);
1981 rx_SetMinProcs(tservice, 3);
1982 rx_SetMaxProcs(tservice, lwps);
1983 rx_SetCheckReach(tservice, 1);
1984 rx_SetServerIdleDeadErr(tservice, VNOSERVICE);
1987 rx_NewService(0, RX_STATS_SERVICE_ID, "rpcstats", securityClasses,
1988 numClasses, RXSTATS_ExecuteRequest);
1990 ViceLog(0, ("Failed to initialize rpc stat service.\n"));
1993 rx_SetMinProcs(tservice, 2);
1994 rx_SetMaxProcs(tservice, 4);
1997 * Enable RX hot threads, which allows the listener thread to trade
1998 * places with an idle thread and moves the context switch from listener
1999 * to worker out of the critical path.
2001 rx_EnableHotThread();
2003 /* Some rx debugging */
2004 if (rxlog || eventlog) {
2005 debugFile = afs_fopen("rx_dbg", "w");
2007 rx_debugFile = debugFile;
2009 rxevent_debugFile = debugFile;
2012 init_sys_error_to_et(); /* Set up error table translation */
2013 h_InitHostPackage(); /* set up local cellname and realmname */
2014 InitCallBack(numberofcbs);
2018 if (code && code != VL_MULTIPADDR) {
2019 ViceLog(0, ("Fatal error in library initialization, exiting!!\n"));
2024 if (code && code != -1) {
2025 ViceLog(0, ("Fatal error in protection initialization, exiting!!\n"));
2029 /* allow super users to manage RX statistics */
2030 rx_SetRxStatUserOk(fs_rxstat_userok);
2032 CV_INIT(&fsync_cond, "fsync", CV_DEFAULT, 0);
2033 MUTEX_INIT(&fsync_glock_mutex, "fsync", MUTEX_DEFAULT, 0);
2035 #if !defined(AFS_DEMAND_ATTACH_FS)
2037 * For DAFS, we do not start the Rx server threads until after
2038 * the volume package is initialized, and fileserver state is
2039 * restored. This is necessary in order to keep host and callback
2040 * package state pristine until we have a chance to restore state.
2042 * Furthermore, startup latency is much lower with dafs, so this
2043 * shouldn't pose a serious problem.
2045 rx_StartServer(0); /* now start handling requests */
2048 /* we ensure that there is enough space in the vnode buffer to satisfy
2049 ** requests from all concurrent threads.
2050 ** the maximum number of vnodes used by a single thread at any one time
2051 ** is three ( "link" uses three vnodes simultaneously, one vLarge and
2052 ** two vSmall for linking files and two vLarge and one vSmall for linking
2055 minVnodesRequired = 2 * lwps + 1;
2056 if (minVnodesRequired > nSmallVns) {
2057 nSmallVns = minVnodesRequired;
2059 ("Overriding -s command line parameter with %d\n",
2062 if (minVnodesRequired > large) {
2063 large = minVnodesRequired;
2064 ViceLog(0, ("Overriding -l command line parameter with %d\n", large));
2067 /* We now do this after getting the listener up and running, so that client
2068 * connections don't timeout (maybe) if a file server is restarted, since it
2069 * will be available "real soon now". Worry about whether we can satisfy the
2070 * calls in the volume package itself.
2072 VOptDefaults(fileServer, &opts);
2073 opts.nLargeVnodes = large;
2074 opts.nSmallVnodes = nSmallVns;
2075 opts.volcache = volcache;
2076 opts.unsafe_attach = unsafe_attach;
2077 if (offline_timeout != -1) {
2078 opts.interrupt_rxcall = rx_InterruptCall;
2079 opts.offline_timeout = offline_timeout;
2081 if (offline_shutdown_timeout == -1) {
2082 /* default to -offline-timeout, if shutdown-specific timeout is not
2084 opts.offline_shutdown_timeout = offline_timeout;
2086 opts.interrupt_rxcall = rx_InterruptCall;
2087 opts.offline_shutdown_timeout = offline_shutdown_timeout;
2090 if (VInitVolumePackage2(fileServer, &opts)) {
2092 ("Shutting down: errors encountered initializing volume package\n"));
2097 /* Install handler to catch the shutdown signal;
2098 * bosserver assumes SIGQUIT shutdown
2100 #if !defined(AFS_NT40_ENV)
2101 softsig_signal(SIGQUIT, ShutDown_Signal);
2103 (void)signal(SIGQUIT, ShutDown_Signal);
2106 if (VInitAttachVolumes(fileServer)) {
2108 ("Shutting down: errors encountered initializing volume package\n"));
2113 #ifdef AFS_DEMAND_ATTACH_FS
2114 if (fs_state.options.fs_state_restore) {
2117 * restore fileserver state */
2120 rx_StartServer(0); /* now start handling requests */
2121 #endif /* AFS_DEMAND_ATTACH_FS */
2124 * We are done calling fopen/fdopen. It is safe to use a large
2125 * of the file descriptor cache.
2129 ViceLog(5, ("Starting pthreads\n"));
2130 osi_Assert(pthread_attr_init(&tattr) == 0);
2131 osi_Assert(pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED) == 0);
2133 osi_Assert(pthread_create
2134 (&serverPid, &tattr, FiveMinuteCheckLWP,
2135 &fiveminutes) == 0);
2136 osi_Assert(pthread_create
2137 (&serverPid, &tattr, HostCheckLWP, &fiveminutes) == 0);
2138 osi_Assert(pthread_create
2139 (&serverPid, &tattr, FsyncCheckLWP, &fiveminutes) == 0);
2141 FT_GetTimeOfDay(&tp, 0);
2144 * Figure out the FileServer's name and primary address.
2146 ViceLog(0, ("Getting FileServer name...\n"));
2147 code = gethostname(FS_HostName, 64);
2149 ViceLog(0, ("gethostname() failed\n"));
2151 ViceLog(0, ("FileServer host name is '%s'\n", FS_HostName));
2153 ViceLog(0, ("Getting FileServer address...\n"));
2154 he = gethostbyname(FS_HostName);
2156 ViceLog(0, ("Can't find address for FileServer '%s'\n", FS_HostName));
2159 memcpy(&FS_HostAddr_NBO, he->h_addr, 4);
2160 (void)afs_inet_ntoa_r(FS_HostAddr_NBO, hoststr);
2161 FS_HostAddr_HBO = ntohl(FS_HostAddr_NBO);
2163 ("FileServer %s has address %s (0x%x or 0x%x in host byte order)\n",
2164 FS_HostName, hoststr, FS_HostAddr_NBO, FS_HostAddr_HBO));
2168 strftime(tbuffer, sizeof(tbuffer), "%a %b %d %H:%M:%S %Y",
2169 localtime_r(&t, &tm));
2170 ViceLog(0, ("File Server started %s\n", tbuffer));
2171 afs_FullPerfStats.det.epoch.tv_sec = StartTime = tp.tv_sec;
2173 sleep(1000); /* long time */