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>
45 #include <rx/rx_queue.h>
49 #include <opr/softsig.h>
50 #include <afs/procmgmt_softsig.h> /* must come after softsig.h */
52 #include <afs/ptclient.h>
53 #include <afs/afsint.h>
54 #include <afs/vldbint.h>
55 #include <afs/errors.h>
56 #include <afs/ihandle.h>
57 #include <afs/vnode.h>
58 #include <afs/volume.h>
60 #include <afs/cellconfig.h>
62 #include <afs/prs_fs.h>
64 #include <rx/rxstat.h>
66 #include <afs/afs_args.h>
67 #include <afs/vlserver.h>
68 #include <afs/afsutil.h>
69 #include <afs/fileutil.h>
70 #include <afs/ptuser.h>
71 #include <afs/audit.h>
72 #include <afs/partition.h>
74 #include <afs/afsutil.h>
75 #include "viced_prototypes.h"
78 #if defined(AFS_SGI_ENV)
79 # include "sys/schedctl.h"
80 # include "sys/lock.h"
82 #include <rx/rx_globals.h>
86 static void ClearXStatValues(void);
87 static void PrintCounters(void);
89 static afs_int32 Do_VLRegisterRPC(void);
91 int eventlog = 0, rxlog = 0;
93 static struct logOptions logopts;
95 pthread_mutex_t fsync_glock_mutex;
96 pthread_cond_t fsync_cond;
99 # define NT_OPEN_MAX 1024 /* This is an arbitrary no. we came up with for
100 * now. We hope this will be replaced by a more
101 * intelligent estimate later. */
104 int SystemId; /* ViceID of "Administrators" */
105 int SystemAnyUser; /* Viceid of "System:AnyUser" */
106 prlist SystemAnyUserCPS; /* CPS for "system:AnyUser */
107 int AnonymousID = 0; /* ViceId of "Anonymous" */
108 prlist AnonCPS; /* CPS for "Anonymous" */
110 struct afsconf_dir *confDir; /* Configuration dir object */
112 int restartMode = RESTART_ORDINARY;
115 * Home for the performance statistics.
117 struct afs_PerfStats afs_perfstats;
119 extern int Statistics;
124 int rxJumbograms = 0; /* default is to not send and receive jumbograms. */
125 int rxBind = 0; /* don't bind */
126 int rxkadDisableDotCheck = 0; /* disable check for dot in principal name */
128 afs_int32 implicitAdminRights = PRSFS_LOOKUP; /* The ADMINISTER right is
130 afs_int32 readonlyServer = 0;
132 int stackSize = 24000;
133 int fiveminutes = 300; /* 5 minutes. Change this for debugging only */
134 int CurrentConnections = 0;
135 int hostaclRefresh = 7200; /* refresh host clients' acls every 2 hrs */
136 #if defined(AFS_SGI_ENV)
142 * seconds to wait until forcing a panic during ShutDownAndCore(PANIC)
143 * in case we get stuck.
145 #ifdef AFS_DEMAND_ATTACH_FS
146 static int panic_timeout = 2 * 60;
148 static int panic_timeout = 30 * 60;
151 static int host_thread_quota;
152 int rxpackets = 150; /* 100 */
153 int nSmallVns = 400; /* 200 */
154 int large = 400; /* 200 */
155 int volcache = 400; /* 400 */
156 int numberofcbs = 60000; /* 60000 */
157 int lwps = 9; /* 6 */
158 int buffs = 90; /* 70 */
159 int novbc = 0; /* Enable Volume Break calls */
160 int busy_threshold = 600;
161 int abort_threshold = 10;
162 int udpBufSize = 0; /* UDP buffer size for receive */
163 int sendBufSize = 16384; /* send buffer size */
164 int saneacls = 0; /* Sane ACLs Flag */
165 static int unsafe_attach = 0; /* avoid inUse check on vol attach? */
166 static int offline_timeout = -1; /* -offline-timeout option */
167 static int offline_shutdown_timeout = -1; /* -offline-shutdown-timeout option */
171 pthread_key_t viced_uclient_key;
174 * FileServer's name and IP address, both network byte order and
177 #define ADDRSPERSITE 16 /* Same global is in rx/rx_user.c */
179 char FS_HostName[128] = "localhost";
180 char *FS_configPath = NULL;
181 afs_uint32 FS_HostAddr_NBO;
182 afs_uint32 FS_HostAddr_HBO;
183 afs_uint32 FS_HostAddrs[ADDRSPERSITE], FS_HostAddr_cnt = 0, FS_registered = 0;
184 /* All addresses in FS_HostAddrs are in NBO */
187 #ifdef AFS_DEMAND_ATTACH_FS
190 * fileserver mode support
192 * during fileserver shutdown, we have to track the graceful shutdown of
193 * certain background threads before we are allowed to dump state to
197 # if !defined(PTHREAD_RWLOCK_INITIALIZER) && defined(AFS_DARWIN80_ENV)
198 # define PTHREAD_RWLOCK_INITIALIZER {0x2DA8B3B4, {0}}
201 # ifndef AFS_NT40_ENV
202 struct fs_state fs_state =
209 PTHREAD_COND_INITIALIZER,
210 PTHREAD_RWLOCK_INITIALIZER
212 # else /* AFS_NT40_ENV */
213 struct fs_state fs_state;
215 static int fs_stateInit(void)
217 fs_state.mode = FS_MODE_NORMAL;
218 fs_state.FiveMinuteLWP_tranquil = 0;
219 fs_state.HostCheckLWP_tranquil = 0;
220 fs_state.FsyncCheckLWP_tranquil = 0;
221 fs_state.salvsync_fatal_error = 0;
223 fs_state.options.fs_state_save = 1;
224 fs_state.options.fs_state_restore = 1;
225 fs_state.options.fs_state_verify_before_save = 1;
226 fs_state.options.fs_state_verify_after_restore = 1;
228 opr_cv_init(&fs_state.worker_done_cv, "worker done");
229 opr_Verify(pthread_rwlock_init(&fs_state.state_lock, NULL) == 0);
231 # endif /* AFS_NT40_ENV */
232 #endif /* AFS_DEMAND_ATTACH_FS */
235 * Home for the performance statistics.
241 CheckDescriptors_Signal(int signo)
243 struct afs_stat status;
244 int tsize = getdtablesize();
246 for (i = 0; i < tsize; i++) {
247 if (afs_fstat(i, &status) != -1) {
248 printf("%d: dev %x, inode %u, length %u, type/mode %x\n", i,
249 (unsigned int) status.st_dev,
250 (unsigned int) status.st_ino,
251 (unsigned int) status.st_size,
259 /* Signal number for dumping debug info is platform dependent. */
260 #if defined(AFS_HPUX_ENV)
261 # define AFS_SIG_CHECK SIGPOLL
262 #elif defined(AFS_NT40_ENV)
263 # define AFS_SIG_CHECK SIGUSR2
265 # define AFS_SIG_CHECK SIGXCPU
268 CheckSignal_Signal(int x)
270 if (FS_registered > 0) {
272 * We have proper ip addresses; tell the vlserver what we got; the following
273 * routine will do the proper reporting for us
284 ShutDown_Signal(int x)
286 ShutDownAndCore(DONTPANIC);
289 /* check whether caller is authorized to perform admin operations */
291 viced_SuperUser(struct rx_call *call)
293 return afsconf_SuperUser(confDir, call, NULL);
297 * Return true if this name is a member of the local realm.
300 fs_IsLocalRealmMatch(void *rock, char *name, char *inst, char *cell)
302 struct afsconf_dir *dir = (struct afsconf_dir *)rock;
303 afs_int32 islocal = 0; /* default to no */
306 code = afsconf_IsLocalRealmMatch(dir, &islocal, name, inst, cell);
309 ("Failed local realm check; code=%d, name=%s, inst=%s, cell=%s\n",
310 code, name, inst, cell));
317 viced_syscall(afs_uint32 a3, afs_uint32 a4, void *a5)
320 # ifndef AFS_LINUX20_ENV
323 old = (void (*)(int))signal(SIGSYS, SIG_IGN);
325 rcode = syscall(AFS_SYSCALL, 28 /* AFSCALL_CALL */ , a3, a4, a5);
326 # ifndef AFS_LINUX20_ENV
334 #if !defined(AFS_NT40_ENV)
335 # include "AFS_component_version_number.c"
336 #endif /* !AFS_NT40_ENV */
338 #define MAXADMINNAME 64
339 char adminName[MAXADMINNAME];
345 struct afs_stat status;
347 if ((afs_stat("/AdminName", &status)) || /* if file does not exist */
348 (status.st_size <= 0) || /* or it is too short */
349 (status.st_size >= (MAXADMINNAME)) || /* or it is too long */
350 (fd = afs_open("/AdminName", O_RDONLY, 0)) < 0 || /* or open fails */
351 read(fd, adminName, status.st_size) != status.st_size) { /* or read */
353 strcpy(adminName, "System:Administrators"); /* use the default name */
356 close(fd); /* close fd if it was opened */
358 } /*CheckAdminName */
364 #if !defined(AFS_NT40_ENV)
367 /* set our 'thread-id' so that the host hold table works */
368 threadId = rx_SetThreadNum();
369 afs_pthread_setname_self(s);
370 ViceLog(0, ("Set thread id 0x%x for '%s'\n", threadId, s));
374 /* This LWP does things roughly every 5 minutes */
376 FiveMinuteCheckLWP(void *unused)
381 ViceLog(1, ("Starting five minute check process\n"));
382 setThreadId("FiveMinuteCheckLWP");
384 #ifdef AFS_DEMAND_ATTACH_FS
386 while (fs_state.mode == FS_MODE_NORMAL) {
387 fs_state.FiveMinuteLWP_tranquil = 1;
395 #ifdef AFS_DEMAND_ATTACH_FS
397 if (fs_state.mode != FS_MODE_NORMAL) {
400 fs_state.FiveMinuteLWP_tranquil = 0;
404 /* close the log so it can be removed */
405 ReOpenLog(); /* don't trunc, just append */
406 ViceLog(2, ("Cleaning up timed out callbacks\n"));
407 if (CleanupTimedOutCallBacks())
408 ViceLog(5, ("Timed out callbacks deleted\n"));
409 ViceLog(2, ("Set disk usage statistics\n"));
411 if (FS_registered == 1)
413 /* Force wakeup in case we missed something; pthreads does timedwait */
414 if (printBanner && (++msg & 1)) { /* Every 10 minutes */
415 time_t now = time(NULL);
417 strftime(tbuffer, sizeof(tbuffer), "%a %b %d %H:%M:%S %Y",
418 localtime_r(&now, &tm));
420 ("File server is running at %s\n", tbuffer));
422 #ifdef AFS_DEMAND_ATTACH_FS
426 #ifdef AFS_DEMAND_ATTACH_FS
427 fs_state.FiveMinuteLWP_tranquil = 1;
429 opr_cv_broadcast(&fs_state.worker_done_cv);
434 } /*FiveMinuteCheckLWP */
437 /* This LWP does host checks every 5 minutes: it should not be used for
438 * other 5 minute activities because it may be delayed by timeouts when
439 * it probes the workstations
443 HostCheckLWP(void *unused)
445 ViceLog(1, ("Starting Host check process\n"));
446 setThreadId("HostCheckLWP");
447 #ifdef AFS_DEMAND_ATTACH_FS
449 while (fs_state.mode == FS_MODE_NORMAL) {
450 fs_state.HostCheckLWP_tranquil = 1;
458 #ifdef AFS_DEMAND_ATTACH_FS
460 if (fs_state.mode != FS_MODE_NORMAL) {
463 fs_state.HostCheckLWP_tranquil = 0;
467 ViceLog(2, ("Checking for dead venii & clients\n"));
470 #ifdef AFS_DEMAND_ATTACH_FS
474 #ifdef AFS_DEMAND_ATTACH_FS
475 fs_state.HostCheckLWP_tranquil = 1;
477 opr_cv_broadcast(&fs_state.worker_done_cv);
484 /* This LWP does fsync checks every 5 minutes: it should not be used for
485 * other 5 minute activities because it may be delayed by timeouts when
486 * it probes the workstations
489 FsyncCheckLWP(void *unused)
492 struct timespec fsync_next;
493 ViceLog(1, ("Starting fsync check process\n"));
495 setThreadId("FsyncCheckLWP");
497 #ifdef AFS_DEMAND_ATTACH_FS
499 while (fs_state.mode == FS_MODE_NORMAL) {
500 fs_state.FsyncCheckLWP_tranquil = 1;
506 /* rounding is fine */
507 fsync_next.tv_nsec = 0;
508 fsync_next.tv_sec = time(0) + fiveminutes;
510 code = opr_cv_timedwait(&fsync_cond, &fsync_glock_mutex,
512 if (code != 0 && code != ETIMEDOUT)
513 ViceLog(0, ("pthread_cond_timedwait returned %d\n", code));
516 #ifdef AFS_DEMAND_ATTACH_FS
518 if (fs_state.mode != FS_MODE_NORMAL) {
521 fs_state.FsyncCheckLWP_tranquil = 0;
523 #endif /* AFS_DEMAND_ATTACH_FS */
525 ViceLog(2, ("Checking for fsync events\n"));
527 code = BreakLaterCallBacks();
529 #ifdef AFS_DEMAND_ATTACH_FS
533 #ifdef AFS_DEMAND_ATTACH_FS
534 fs_state.FsyncCheckLWP_tranquil = 1;
536 opr_cv_broadcast(&fs_state.worker_done_cv);
539 #endif /* AFS_DEMAND_ATTACH_FS */
543 /*------------------------------------------------------------------------
544 * PRIVATE ClearXStatValues
547 * Initialize all of the values collected via the xstat
557 * Must be called during File Server initialization.
561 *------------------------------------------------------------------------*/
564 ClearXStatValues(void)
565 { /*ClearXStatValues */
567 struct fs_stats_opTimingData *opTimeP; /*Ptr to timing struct */
568 struct fs_stats_xferData *opXferP; /*Ptr to xfer struct */
569 int i; /*Loop counter */
572 * Zero all xstat-related structures.
574 memset((&afs_perfstats), 0, sizeof(struct afs_PerfStats));
575 memset((&afs_FullPerfStats), 0,
576 sizeof(struct fs_stats_FullPerfStats));
579 * That's not enough. We have to set reasonable minima for
580 * time and xfer values in the detailed stats.
582 opTimeP = &(afs_FullPerfStats.det.rpcOpTimes[0]);
583 for (i = 0; i < FS_STATS_NUM_RPC_OPS; i++, opTimeP++)
584 opTimeP->minTime.tv_sec = 999999;
586 opXferP = &(afs_FullPerfStats.det.xferOpTimes[0]);
587 for (i = 0; i < FS_STATS_NUM_XFER_OPS; i++, opXferP++) {
588 opXferP->minTime.tv_sec = 999999;
589 opXferP->minBytes = 999999999;
593 * There's more. We have to set our unique system identifier, as
594 * declared in param.h. If such a thing is not defined, we bitch
595 * and declare ourselves to be an unknown system type.
598 afs_perfstats.sysname_ID = SYS_NAME_ID;
600 # ifndef AFS_NT40_ENV
601 ViceLog(0, ("Sys name ID constant not defined in param.h!!\n"));
602 ViceLog(0, ("[Choosing ``undefined'' sys name ID.\n"));
604 afs_perfstats.sysname_ID = SYS_NAME_ID_UNDEFINED;
605 # endif /* SYS_NAME_ID */
607 } /*ClearXStatValues */
609 int CopyOnWrite_calls = 0, CopyOnWrite_off0 = 0, CopyOnWrite_size0 = 0;
610 afs_fsize_t CopyOnWrite_maxsize = 0;
615 int dirbuff, dircall, dirio;
617 int workstations, activeworkstations, delworkstations;
621 #ifdef AFS_DEMAND_ATTACH_FS
625 gettimeofday(&tpl, 0);
627 strftime(tbuffer, sizeof(tbuffer), "%a %b %d %H:%M:%S %Y",
628 localtime_r(&StartTime, &tm));
629 ViceLog(0, ("Vice was last started at %s\n", tbuffer));
631 #ifdef AFS_DEMAND_ATTACH_FS
632 if (GetLogLevel() >= 125) {
633 stats_flags = VOL_STATS_PER_CHAIN2;
634 } else if (GetLogLevel() >= 25) {
635 stats_flags = VOL_STATS_PER_CHAIN;
637 VPrintExtendedCacheStats(stats_flags);
641 DStat(&dirbuff, &dircall, &dirio);
643 ("With %d directory buffers; %d reads resulted in %d read I/Os\n",
644 dirbuff, dircall, dirio));
645 rx_PrintStats(stderr);
646 audit_PrintStats(stderr);
648 PrintCallBackStats();
649 processSize = opr_procsize();
651 ("There are %d connections, process size %d\n",
652 CurrentConnections, processSize));
653 h_GetWorkStats(&workstations, &activeworkstations, &delworkstations,
654 tpl.tv_sec - 15 * 60);
656 ("There are %d workstations, %d are active (req in < 15 mins), %d marked \"down\"\n",
657 workstations, activeworkstations, delworkstations));
658 ViceLog(0, ("CopyOnWrite: calls %d off0 %d size0 %d maxsize 0x%llx\n",
659 CopyOnWrite_calls, CopyOnWrite_off0, CopyOnWrite_size0, CopyOnWrite_maxsize));
666 ShutdownWatchdogLWP(void *unused)
668 afs_pthread_setname_self("ShutdownWatchdog");
669 sleep(panic_timeout);
670 ViceLogThenPanic(0, ("ShutdownWatchdogLWP: Failed to shutdown and panic "
671 "within %d seconds; forcing panic\n",
677 ShutDownAndCore(int dopanic)
679 time_t now = time(NULL);
684 pthread_t watchdogPid;
685 pthread_attr_t tattr;
686 opr_Verify(pthread_attr_init(&tattr) == 0);
687 opr_Verify(pthread_create(&watchdogPid, &tattr,
688 ShutdownWatchdogLWP, NULL) == 0);
691 /* do not allows new reqests to be served from now on, all new requests
692 * are returned with an error code of RX_RESTARTING ( transient failure ) */
693 rx_SetRxTranquil(); /* dhruba */
697 #ifdef AFS_DEMAND_ATTACH_FS
699 if (fs_state.mode == FS_MODE_SHUTDOWN) {
700 /* it is possible for at least fs_stateSave() (called below) to call
701 * ShutDownAndCore if there's host list corruption; prevent
702 * deinitializing some stuff twice */
703 ViceLog(0, ("ShutDownAndCore called during shutdown? Skipping volume "
704 "and host package shutdown\n"));
708 fs_state.mode = FS_MODE_SHUTDOWN;
712 strftime(tbuffer, sizeof(tbuffer), "%a %b %d %H:%M:%S %Y",
713 localtime_r(&now, &tm));
714 ViceLog(0, ("Shutting down file server at %s\n", tbuffer));
716 ViceLog(0, ("ABNORMAL SHUTDOWN, see core file.\n"));
721 /* shut down volume package */
724 #ifdef AFS_DEMAND_ATTACH_FS
725 if (fs_state.options.fs_state_save) {
728 * save fileserver state to disk */
731 ViceLog(0, ("Not saving fileserver state; abnormal shutdown\n"));
734 /* make sure background threads have finished all of their asynchronous
735 * work on host and callback structures */
737 while (!fs_state.FiveMinuteLWP_tranquil ||
738 !fs_state.HostCheckLWP_tranquil ||
739 !fs_state.FsyncCheckLWP_tranquil) {
742 ViceLog(0, ("waiting for background host/callback threads to quiesce before saving fileserver state...\n"));
743 opr_cv_wait(&fs_state.worker_done_cv, &fileproc_glock_mutex);
749 /* ok. it should now be fairly safe. let's do the state dump */
755 #endif /* AFS_DEMAND_ATTACH_FS */
758 rx_PrintStats(debugFile);
762 strftime(tbuffer, sizeof(tbuffer), "%a %b %d %H:%M:%S %Y",
763 localtime_r(&now, &tm));
765 ViceLog(0, ("File server has terminated abnormally at %s\n", tbuffer));
767 ViceLog(0, ("File server has terminated normally at %s\n", tbuffer));
770 if (dopanic) /* XXX pass in file and line? */
771 osi_Panic("Panic requested\n");
777 ParseRights(char *arights)
783 if (!arights || !strcmp(arights, "")) {
784 printf("Missing list of mode bits on -implicit option\n");
787 if (!strcmp(arights, "none"))
789 else if (!strcmp(arights, "read"))
790 mode = PRSFS_READ | PRSFS_LOOKUP;
791 else if (!strcmp(arights, "write"))
793 PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
794 PRSFS_WRITE | PRSFS_LOCK;
795 else if (!strcmp(arights, "all"))
797 PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
798 PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER;
800 len = strlen(arights);
801 for (i = 0; i < len; i++) {
806 mode |= PRSFS_LOOKUP;
808 mode |= PRSFS_INSERT;
810 mode |= PRSFS_DELETE;
816 mode |= PRSFS_ADMINISTER;
834 printf("Illegal -implicit rights character '%c'.\n", tc);
843 * Limit MAX_FILESERVER_THREAD by the system limit on the number of
844 * pthreads (sysconf(_SC_THREAD_THREADS_MAX)), if applicable and
847 * AIX: sysconf() limit is real
848 * HP-UX: sysconf() limit is real
849 * IRIX: sysconf() limit is apparently NOT real -- too small
850 * DUX: sysconf() limit is apparently NOT real -- too big
851 * Linux: sysconf() limit is apparently NOT real -- too big
852 * Solaris: no sysconf() limit
855 max_fileserver_thread(void)
857 #if defined(AFS_AIX_ENV) || defined(AFS_HPUX_ENV)
860 ans = sysconf(_SC_THREAD_THREADS_MAX);
861 if (0 < ans && ans < MAX_FILESERVER_THREAD)
864 return MAX_FILESERVER_THREAD;
868 extern ih_init_params vol_io_params;
893 OPT_offline_shutdown_timeout,
894 OPT_vhandle_setaside,
895 OPT_vhandle_max_cachesize,
896 OPT_vhandle_initial_cachesize,
897 OPT_fs_state_dont_save,
898 OPT_fs_state_dont_restore,
905 OPT_unsafe_nosalvage,
935 ParseArgs(int argc, char *argv[])
939 char *optstring = NULL;
940 struct cmd_item *optlist;
941 struct cmd_syndesc *opts;
944 char *auditFileName = NULL;
945 char *sync_behavior = NULL;
947 #if defined(AFS_AIX32_ENV)
948 extern int aixlow_water;
951 opts = cmd_CreateSyntax(NULL, NULL, NULL, 0, NULL);
953 /* fileserver options */
954 cmd_AddParmAtOffset(opts, OPT_large, "-L", CMD_FLAG,
955 CMD_OPTIONAL, "defaults for a 'large' server");
956 cmd_AddParmAtOffset(opts, OPT_small, "-S", CMD_FLAG,
957 CMD_OPTIONAL, "defaults for a 'small' server");
959 cmd_AddParmAtOffset(opts, OPT_banner, "-banner", CMD_FLAG,
960 CMD_OPTIONAL, "print regular banners to log");
961 cmd_AddParmAtOffset(opts, OPT_implicit, "-implicit", CMD_SINGLE,
962 CMD_OPTIONAL, "implicit admin access bits");
964 #if defined(AFS_SGI_ENV)
965 cmd_AddParmAtOffset(opts, OPT_lock, "-lock", CMD_FLAG,
966 CMD_OPTIONAL, "lock filserver binary in memory");
968 cmd_AddParmAtOffset(opts, OPT_readonly, "-readonly", CMD_FLAG,
969 CMD_OPTIONAL, "be a readonly fileserver");
970 cmd_AddParmAtOffset(opts, OPT_saneacls, "-saneacls", CMD_FLAG,
971 CMD_OPTIONAL, "set the saneacls capability bit");
973 cmd_AddParmAtOffset(opts, OPT_buffers, "-b", CMD_SINGLE,
974 CMD_OPTIONAL, "buffers");
975 cmd_AddParmAtOffset(opts, OPT_callbacks, "-cb", CMD_SINGLE,
976 CMD_OPTIONAL, "number of callbacks");
977 cmd_AddParmAtOffset(opts, OPT_vcsize, "-vc", CMD_SINGLE,
978 CMD_OPTIONAL, "volume cachesize");
979 cmd_AddParmAtOffset(opts, OPT_lvnodes, "-l", CMD_SINGLE,
980 CMD_OPTIONAL, "large vnodes");
981 cmd_AddParmAtOffset(opts, OPT_svnodes, "-s", CMD_SINGLE,
982 CMD_OPTIONAL, "small vnodes");
983 cmd_AddParmAtOffset(opts, OPT_sendsize, "-sendsize", CMD_SINGLE,
984 CMD_OPTIONAL, "size of send buffer in bytes");
986 #if defined(AFS_AIX32_ENV)
987 cmd_AddParmAtOffset(opts, OPT_minspare, "-m", CMD_SINGLE,
988 CMD_OPTIONAL, "minimum percentage spare in partition");
991 cmd_AddParmAtOffset(opts, OPT_spare, "-spare", CMD_SINGLE,
992 CMD_OPTIONAL, "kB overage on volume quota");
993 cmd_AddParmAtOffset(opts, OPT_pctspare, "-pctspare", CMD_SINGLE,
994 CMD_OPTIONAL, "percentage overage on volume quota");
996 cmd_AddParmAtOffset(opts, OPT_hostcpsrefresh, "-hr", CMD_SINGLE,
997 CMD_OPTIONAL, "hours between host CPS refreshes");
999 cmd_AddParmAtOffset(opts, OPT_vattachthreads, "-vattachpar", CMD_SINGLE,
1000 CMD_OPTIONAL, "# of volume attachment threads");
1002 cmd_AddParmAtOffset(opts, OPT_abortthreshold, "-abortthreshold",
1003 CMD_SINGLE, CMD_OPTIONAL,
1005 cmd_AddParmAtOffset(opts, OPT_busyat, "-busyat", CMD_SINGLE, CMD_OPTIONAL,
1006 "# of queued entries after which server is busy");
1007 cmd_AddParmAtOffset(opts, OPT_nobusy, "-nobusy", CMD_FLAG, CMD_OPTIONAL,
1008 "send VRESTARTING while restarting the server");
1010 cmd_AddParmAtOffset(opts, OPT_offline_timeout, "-offline-timeout",
1011 CMD_SINGLE, CMD_OPTIONAL,
1012 "timeout for offlining volumes");
1013 cmd_AddParmAtOffset(opts, OPT_offline_shutdown_timeout,
1014 "-offline-shutdown-timeout", CMD_SINGLE, CMD_OPTIONAL,
1015 "timeout offlining volumes during shutdown");
1017 cmd_AddParmAtOffset(opts, OPT_vhandle_setaside, "-vhandle-setaside",
1018 CMD_SINGLE, CMD_OPTIONAL,
1019 "# fds reserved for non-cache IO");
1020 cmd_AddParmAtOffset(opts, OPT_vhandle_max_cachesize,
1021 "-vhandle-max-cachesize", CMD_SINGLE, CMD_OPTIONAL,
1023 cmd_AddParmAtOffset(opts, OPT_vhandle_initial_cachesize,
1024 "-vhandle-initial-cachesize", CMD_SINGLE,
1025 CMD_OPTIONAL, "# fds reserved for cache IO");
1027 #ifdef AFS_DEMAND_ATTACH_FS
1029 cmd_AddParmAtOffset(opts, OPT_fs_state_dont_save,
1030 "-fs-state-dont-save", CMD_FLAG, CMD_OPTIONAL,
1031 "disable state save during shutdown");
1032 cmd_AddParmAtOffset(opts, OPT_fs_state_dont_restore,
1033 "-fs-state-dont-restore", CMD_FLAG, CMD_OPTIONAL,
1034 "disable state restore during startup");
1035 cmd_AddParmAtOffset(opts, OPT_fs_state_verify, "-fs-state-verify",
1036 CMD_SINGLE, CMD_OPTIONAL, "none|save|restore|both");
1037 cmd_AddParmAtOffset(opts, OPT_vhashsize, "-vhashsize",
1038 CMD_SINGLE, CMD_OPTIONAL,
1039 "log(2) of # of volume hash buckets");
1040 cmd_AddParmAtOffset(opts, OPT_vlrudisable, "-vlrudisable",
1041 CMD_FLAG, CMD_OPTIONAL, "disable VLRU functionality");
1042 cmd_AddParmAtOffset(opts, OPT_vlruthresh, "-vlruthresh",
1043 CMD_FLAG, CMD_OPTIONAL,
1044 "mins before unused vols become eligible for detach");
1045 cmd_AddParmAtOffset(opts, OPT_vlruinterval, "-vlruinterval",
1046 CMD_FLAG, CMD_OPTIONAL, "secs between VLRU scans");
1047 cmd_AddParmAtOffset(opts, OPT_vlrumax, "-vlrumax", CMD_FLAG, CMD_OPTIONAL,
1048 "max volumes to detach in one scan");
1049 cmd_AddParmAtOffset(opts, OPT_unsafe_nosalvage, "-unsafe-nosalvage",
1050 CMD_FLAG, CMD_OPTIONAL,
1051 "bybass safety checks on volume attach");
1054 /* unrecommend options - should perhaps be CMD_HIDE */
1055 cmd_AddParmAtOffset(opts, OPT_cbwait, "-w", CMD_SINGLE, CMD_OPTIONAL,
1056 "callback wait interval");
1057 cmd_AddParmAtOffset(opts, OPT_novbc, "-novbc", CMD_SINGLE, CMD_FLAG,
1058 "disable callback breaks on reattach");
1060 /* general options */
1061 cmd_AddParmAtOffset(opts, OPT_auditlog, "-auditlog", CMD_SINGLE,
1062 CMD_OPTIONAL, "location of audit log");
1063 cmd_AddParmAtOffset(opts, OPT_auditiface, "-audit-interface", CMD_SINGLE,
1064 CMD_OPTIONAL, "interface to use for audit logging");
1065 cmd_AddParmAtOffset(opts, OPT_debug, "-d", CMD_SINGLE, CMD_OPTIONAL,
1067 cmd_AddParmAtOffset(opts, OPT_mrafslogs, "-mrafslogs", CMD_FLAG,
1068 CMD_OPTIONAL, "enable MRAFS style logging");
1069 cmd_AddParmAtOffset(opts, OPT_transarc_logs, "-transarc-logs", CMD_FLAG,
1070 CMD_OPTIONAL, "enable Transarc style logging");
1071 cmd_AddParmAtOffset(opts, OPT_threads, "-p", CMD_SINGLE, CMD_OPTIONAL,
1072 "number of threads");
1074 cmd_AddParmAtOffset(opts, OPT_syslog, "-syslog", CMD_SINGLE_OR_FLAG,
1075 CMD_OPTIONAL, "log to syslog");
1079 cmd_AddParmAtOffset(opts, OPT_peer, "-enable_peer_stats", CMD_FLAG,
1080 CMD_OPTIONAL, "enable RX transport statistics");
1081 cmd_AddParmAtOffset(opts, OPT_process, "-enable_process_stats", CMD_FLAG,
1082 CMD_OPTIONAL, "enable RX RPC statistics");
1083 cmd_AddParmAtOffset(opts, OPT_nojumbo, "-nojumbo", CMD_FLAG,
1084 CMD_OPTIONAL, "disable jumbograms");
1085 cmd_AddParmAtOffset(opts, OPT_jumbo, "-jumbo", CMD_FLAG, CMD_OPTIONAL,
1086 "enable jumbograms");
1087 cmd_AddParmAtOffset(opts, OPT_rxbind, "-rxbind", CMD_FLAG, CMD_OPTIONAL,
1088 "bind only to the primary interface");
1089 cmd_AddParmAtOffset(opts, OPT_rxdbg, "-rxdbg", CMD_FLAG, CMD_OPTIONAL,
1090 "enable rx debugging");
1091 cmd_AddParmAtOffset(opts, OPT_rxdbge, "-rxdbge", CMD_FLAG, CMD_OPTIONAL,
1092 "enable rx event debugging");
1093 cmd_AddParmAtOffset(opts, OPT_rxpck, "-rxpck", CMD_SINGLE, CMD_OPTIONAL,
1094 "# of extra rx packets");
1095 cmd_AddParmAtOffset(opts, OPT_rxmaxmtu, "-rxmaxmtu", CMD_SINGLE,
1096 CMD_OPTIONAL, "maximum MTU for RX");
1097 cmd_AddParmAtOffset(opts, OPT_udpsize, "-udpsize", CMD_SINGLE,
1098 CMD_OPTIONAL, "size of socket buffer in bytes");
1101 cmd_AddParmAtOffset(opts, OPT_dotted, "-allow-dotted-principals",
1102 CMD_FLAG, CMD_OPTIONAL,
1103 "permit Kerberos 5 principals with dots");
1104 cmd_AddParmAtOffset(opts, OPT_realm, "-realm",
1105 CMD_LIST, CMD_OPTIONAL, "local realm");
1106 cmd_AddParmAtOffset(opts, OPT_sync, "-sync",
1107 CMD_SINGLE, CMD_OPTIONAL, "always | onclose | never");
1109 /* testing options */
1110 cmd_AddParmAtOffset(opts, OPT_logfile, "-logfile", CMD_SINGLE,
1111 CMD_OPTIONAL, "location of log file");
1112 cmd_AddParmAtOffset(opts, OPT_config, "-config", CMD_SINGLE,
1113 CMD_OPTIONAL, "configuration location");
1115 code = cmd_Parse(argc, argv, &opts);
1116 if (code == CMD_HELP) {
1122 cmd_OpenConfigFile(AFSDIR_SERVER_CONFIG_FILE_FILEPATH);
1123 cmd_SetCommandName("fileserver");
1125 if (cmd_OptionPresent(opts, OPT_large)
1126 && cmd_OptionPresent(opts, OPT_small)) {
1127 printf("Only one of -L or -S must be specified\n");
1131 if (cmd_OptionPresent(opts, OPT_spare)
1132 && cmd_OptionPresent(opts, OPT_pctspare)) {
1133 printf("Both -spare and -pctspare specified, exiting.\n");
1137 if (cmd_OptionPresent(opts, OPT_large)) {
1141 numberofcbs = 64000;
1147 if (cmd_OptionPresent(opts, OPT_small)) {
1151 numberofcbs = 20000;
1157 cmd_OptionAsFlag(opts, OPT_banner, &printBanner);
1159 if (cmd_OptionAsString(opts, OPT_implicit, &optstring) == 0) {
1160 implicitAdminRights = ParseRights(optstring);
1163 if (implicitAdminRights < 0)
1164 return implicitAdminRights;
1167 #if defined(AFS_SGI_ENV)
1168 cmd_OptionAsFlag(opts, OPT_lock, &SawLock);
1170 cmd_OptionAsFlag(opts, OPT_readonly, &readonlyServer);
1171 cmd_OptionAsFlag(opts, OPT_saneacls, &saneacls);
1172 cmd_OptionAsInt(opts, OPT_buffers, &buffs);
1174 if (cmd_OptionAsInt(opts, OPT_callbacks, &numberofcbs) == 0) {
1175 if ((numberofcbs < 10000) || (numberofcbs > 2147483647)) {
1176 printf("number of cbs %d invalid; "
1177 "must be between 10000 and 2147483647\n", numberofcbs);
1182 cmd_OptionAsInt(opts, OPT_vcsize, &volcache);
1183 cmd_OptionAsInt(opts, OPT_lvnodes, &large);
1184 cmd_OptionAsInt(opts, OPT_svnodes, &nSmallVns);
1185 if (cmd_OptionAsInt(opts, OPT_sendsize, &optval) == 0) {
1186 if (optval < 16384) {
1187 printf("Warning:sendsize %d is less than minimum %d; ignoring\n",
1190 sendBufSize = optval;
1193 #if defined(AFS_AIX32_ENV)
1194 if (cmd_OptionAsInt(opts, OPT_minspare, &aixlow_water) == 0) {
1195 if ((aixlow_water < 0) || (aixlow_water > 30)) {
1196 printf("space reserved %d%% invalid; must be between 0-30%\n",
1203 cmd_OptionAsInt(opts, OPT_spare, &BlocksSpare);
1204 if (cmd_OptionAsInt(opts, OPT_pctspare, &PctSpare) == 0) {
1208 if (cmd_OptionAsInt(opts, OPT_hostcpsrefresh, &optval) == 0) {
1209 if ((optval < 1) || (optval > 36)) {
1210 printf("host acl refresh interval of %d hours is invalid; "
1211 "hours must be between 1 and 36\n\n", optval);
1214 hostaclRefresh = optval * 60 * 60;
1217 cmd_OptionAsInt(opts, OPT_vattachthreads, &vol_attach_threads);
1219 cmd_OptionAsInt(opts, OPT_abortthreshold, &abort_threshold);
1221 /* busyat is at the end, as rxpackets has to be set before we can use it */
1222 if (cmd_OptionPresent(opts, OPT_nobusy))
1225 if (cmd_OptionAsInt(opts, OPT_offline_timeout, &offline_timeout) == 0) {
1226 if (offline_timeout < -1) {
1227 printf("Invalid -offline-timeout value %d; the only valid "
1228 "negative value is -1\n", offline_timeout);
1233 if (cmd_OptionAsInt(opts, OPT_offline_shutdown_timeout,
1234 &offline_shutdown_timeout) == 0) {
1235 if (offline_shutdown_timeout < -1) {
1236 printf("Invalid -offline-timeout value %d; the only valid "
1237 "negative value is -1\n", offline_shutdown_timeout);
1242 cmd_OptionAsUint(opts, OPT_vhandle_setaside,
1243 &vol_io_params.fd_handle_setaside);
1244 cmd_OptionAsUint(opts, OPT_vhandle_max_cachesize,
1245 &vol_io_params.fd_max_cachesize);
1246 cmd_OptionAsUint(opts, OPT_vhandle_initial_cachesize,
1247 &vol_io_params.fd_initial_cachesize);
1248 if (cmd_OptionAsString(opts, OPT_sync, &sync_behavior) == 0) {
1249 if (ih_SetSyncBehavior(sync_behavior)) {
1250 printf("Invalid -sync value %s\n", sync_behavior);
1255 #ifdef AFS_DEMAND_ATTACH_FS
1256 if (cmd_OptionPresent(opts, OPT_fs_state_dont_save))
1257 fs_state.options.fs_state_save = 0;
1258 if (cmd_OptionPresent(opts, OPT_fs_state_dont_restore))
1259 fs_state.options.fs_state_restore = 0;
1260 if (cmd_OptionAsString(opts, OPT_fs_state_verify, &optstring) == 0) {
1261 if (strcmp(optstring, "none") == 0) {
1262 fs_state.options.fs_state_verify_before_save = 0;
1263 fs_state.options.fs_state_verify_after_restore = 0;
1264 } else if (strcmp(optstring, "save") == 0) {
1265 fs_state.options.fs_state_verify_after_restore = 0;
1266 } else if (strcmp(optstring, "restore") == 0) {
1267 fs_state.options.fs_state_verify_before_save = 0;
1268 } else if (strcmp(optstring, "both") == 0) {
1271 fprintf(stderr, "invalid argument for -fs-state-verify\n");
1275 if (cmd_OptionAsInt(opts, OPT_vhashsize, &optval) == 0) {
1276 if (VSetVolHashSize(optval)) {
1277 fprintf(stderr, "specified -vhashsize (%d) is invalid or out "
1278 "of range\n", optval);
1282 if (cmd_OptionPresent(opts, OPT_vlrudisable))
1283 VLRU_SetOptions(VLRU_SET_ENABLED, 0);
1284 if (cmd_OptionAsInt(opts, OPT_vlruthresh, &optval) == 0)
1285 VLRU_SetOptions(VLRU_SET_THRESH, 60*optval);
1286 if (cmd_OptionAsInt(opts, OPT_vlruinterval, &optval) == 0)
1287 VLRU_SetOptions(VLRU_SET_INTERVAL, optval);
1288 if (cmd_OptionAsInt(opts, OPT_vlrumax, &optval) == 0)
1289 VLRU_SetOptions(VLRU_SET_MAX, optval);
1290 cmd_OptionAsFlag(opts, OPT_unsafe_nosalvage, &unsafe_attach);
1291 #endif /* AFS_DEMAND_ATTACH_FS */
1293 cmd_OptionAsInt(opts, OPT_cbwait, &fiveminutes);
1294 cmd_OptionAsFlag(opts, OPT_novbc, &novbc);
1296 /* general server options */
1297 cmd_OptionAsString(opts, OPT_auditlog, &auditFileName);
1299 if (cmd_OptionAsString(opts, OPT_auditiface, &optstring) == 0) {
1300 if (osi_audit_interface(optstring)) {
1301 printf("Invalid audit interface '%s'\n", optstring);
1308 if (cmd_OptionAsInt(opts, OPT_threads, &lwps) == 0) {
1309 lwps_max = max_fileserver_thread() - FILESERVER_HELPER_THREADS;
1310 if (lwps > lwps_max)
1316 /* Logging options. */
1318 if (cmd_OptionPresent(opts, OPT_syslog)) {
1319 if (cmd_OptionPresent(opts, OPT_logfile)) {
1320 fprintf(stderr, "Invalid options: -syslog and -logfile are exclusive.\n");
1323 if (cmd_OptionPresent(opts, OPT_transarc_logs)) {
1324 fprintf(stderr, "Invalid options: -syslog and -transarc-logs are exclusive.\n");
1327 if (cmd_OptionPresent(opts, OPT_mrafslogs)) {
1328 fprintf(stderr, "Invalid options: -syslog and -mrafslogs are exclusive.\n");
1332 logopts.lopt_dest = logDest_syslog;
1333 logopts.lopt_facility = LOG_DAEMON;
1334 logopts.lopt_tag = "fileserver";
1335 cmd_OptionAsInt(opts, OPT_syslog, &logopts.lopt_facility);
1339 logopts.lopt_dest = logDest_file;
1341 if (cmd_OptionPresent(opts, OPT_transarc_logs)) {
1342 if (cmd_OptionPresent(opts, OPT_mrafslogs)) {
1344 "Invalid options: -transarc-logs and -mrafslogs are exclusive.\n");
1347 logopts.lopt_rotateOnOpen = 1;
1348 logopts.lopt_rotateStyle = logRotate_old;
1349 } else if (cmd_OptionPresent(opts, OPT_mrafslogs)) {
1350 logopts.lopt_rotateOnOpen = 1;
1351 logopts.lopt_rotateOnReset = 1;
1352 logopts.lopt_rotateStyle = logRotate_timestamp;
1355 if (cmd_OptionPresent(opts, OPT_logfile))
1356 cmd_OptionAsString(opts, OPT_logfile, (char**)&logopts.lopt_filename);
1358 logopts.lopt_filename = AFSDIR_SERVER_FILELOG_FILEPATH;
1361 cmd_OptionAsInt(opts, OPT_debug, &logopts.lopt_logLevel);
1363 if (cmd_OptionPresent(opts, OPT_peer))
1364 rx_enablePeerRPCStats();
1365 if (cmd_OptionPresent(opts, OPT_process))
1366 rx_enableProcessRPCStats();
1367 if (cmd_OptionPresent(opts, OPT_nojumbo))
1369 if (cmd_OptionPresent(opts, OPT_jumbo))
1371 cmd_OptionAsFlag(opts, OPT_rxbind, &rxBind);
1372 cmd_OptionAsFlag(opts, OPT_rxdbg, &rxlog);
1373 cmd_OptionAsFlag(opts, OPT_rxdbge, &eventlog);
1374 cmd_OptionAsInt(opts, OPT_rxpck, &rxpackets);
1376 cmd_OptionAsInt(opts, OPT_rxmaxmtu, &rxMaxMTU);
1378 if (cmd_OptionAsInt(opts, OPT_udpsize, &optval) == 0) {
1379 if (optval < rx_GetMinUdpBufSize()) {
1380 printf("Warning:udpsize %d is less than minimum %d; ignoring\n",
1381 optval, rx_GetMinUdpBufSize());
1383 udpBufSize = optval;
1387 cmd_OptionAsFlag(opts, OPT_dotted, &rxkadDisableDotCheck);
1388 if (cmd_OptionAsList(opts, OPT_realm, &optlist) == 0) {
1390 for (; optlist != NULL; optlist=optlist->next) {
1391 if (strlen(optlist->data) >= AFS_REALM_SZ) {
1392 printf("-realm argument must contain fewer than %d "
1393 "characters.\n", AFS_REALM_SZ);
1396 afsconf_SetLocalRealm(optlist->data); /* overrides krb.conf file, if one */
1400 /* anything setting rxpackets must come before this */
1401 if (cmd_OptionAsInt(opts, OPT_busyat, &optval) == 0) {
1403 printf("Busy threshold %d is too low, will use default.\n",
1405 busy_threshold = 3 * rxpackets / 2;
1407 busy_threshold = optval;
1410 busy_threshold = 3 * rxpackets / 2;
1413 cmd_OptionAsString(opts, OPT_config, &FS_configPath);
1417 osi_audit_file(auditFileName);
1420 host_thread_quota = 5;
1421 } else if (lwps > 32) {
1422 host_thread_quota = 4;
1423 } else if (lwps > 16) {
1424 host_thread_quota = 3;
1426 host_thread_quota = 2;
1432 /* Once upon a time, in a galaxy far far away, IBM AFS supported the use of
1433 * a file /vice/file/parms, the contents of which would override any command
1434 * line parameters. We no longer support the use of such a file, but we warn
1435 * if we encounter its presence from an older release
1440 struct afs_stat sbuf;
1442 if (afs_stat("/vice/file/parms", &sbuf) == 0) {
1443 ViceLog(0, ("Using /vice/file/parms to override command line "
1444 "options is no longer supported"));
1448 /* Miscellaneous routines */
1450 Die(const char *msg)
1453 ViceLogThenPanic(0, ("%s\n", msg));
1463 * If this fails, it's because something major is wrong, and is not
1464 * likely to be time dependent.
1466 code = pr_Initialize(2, AFSDIR_SERVER_ETC_DIRPATH, 0);
1469 ("Couldn't initialize protection library; code=%d.\n", code));
1473 opr_Verify(pthread_key_create(&viced_uclient_key, NULL) == 0);
1475 SystemId = SYSADMINID;
1476 SystemAnyUser = ANYUSERID;
1477 SystemAnyUserCPS.prlist_len = 0;
1478 SystemAnyUserCPS.prlist_val = NULL;
1479 AnonCPS.prlist_len = 0;
1480 AnonCPS.prlist_val = NULL;
1482 code = pr_GetCPS(SystemAnyUser, &SystemAnyUserCPS);
1485 ("Couldn't get CPS for AnyUser, will try again in 30 seconds; code=%d.\n",
1489 code = pr_GetCPS(ANONYMOUSID, &AnonCPS);
1492 ("Couldn't get Anonymous CPS, exiting; code=%d.\n",
1496 AnonymousID = ANONYMOUSID;
1503 static struct ubik_client *cstruct;
1506 vl_Initialize(struct afsconf_dir *dir)
1509 afs_int32 scIndex = RX_SECIDX_NULL;
1510 struct afsconf_cell info;
1511 struct rx_securityClass *sc;
1512 struct rx_connection *serverconns[MAXSERVERS];
1514 memset(serverconns, 0, sizeof(serverconns));
1515 code = afsconf_ClientAuth(dir, &sc, &scIndex);
1517 ViceLog(0, ("Could not get security object for localAuth\n"));
1520 code = afsconf_GetCellInfo(dir, NULL, AFSCONF_VLDBSERVICE, &info);
1523 ("vl_Initialize: Failed to get cell information\n"));
1526 if (info.numServers > MAXSERVERS) {
1528 ("vl_Initialize: info.numServers=%d (> MAXSERVERS=%d)\n",
1529 info.numServers, MAXSERVERS));
1532 for (i = 0; i < info.numServers; i++)
1534 rx_NewConnection(info.hostAddr[i].sin_addr.s_addr,
1535 info.hostAddr[i].sin_port, USER_SERVICE_ID, sc,
1537 code = ubik_ClientInit(serverconns, &cstruct);
1539 ViceLog(0, ("vl_Initialize: ubik client init failed.\n"));
1545 #define SYSIDMAGIC 0x88aabbcc
1546 #define SYSIDVERSION 1
1551 afs_int32 fd, nentries, i;
1552 struct versionStamp vsn;
1553 struct afs_stat status;
1556 if ((afs_stat(AFSDIR_SERVER_SYSID_FILEPATH, &status))
1557 || (status.st_size <= 0)) {
1558 ViceLog(0, ("%s: doesn't exist\n", AFSDIR_SERVER_SYSID_FILEPATH));
1561 if (!(fd = afs_open(AFSDIR_SERVER_SYSID_FILEPATH, O_RDONLY, 0))) {
1563 ("%s: can't open (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1567 if (read(fd, (char *)&vsn, sizeof(vsn)) != sizeof(vsn)) {
1569 ("%s: Read failed (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1573 if (vsn.magic != SYSIDMAGIC) {
1575 ("%s: wrong magic %x (we support %x)\n",
1576 AFSDIR_SERVER_SYSID_FILEPATH, vsn.magic, SYSIDMAGIC));
1579 if (vsn.version != SYSIDVERSION) {
1581 ("%s: wrong version %d (we support %d)\n",
1582 AFSDIR_SERVER_SYSID_FILEPATH, vsn.version, SYSIDVERSION));
1585 if (read(fd, (char *)&uuid, sizeof(struct afsUUID))
1586 != sizeof(struct afsUUID)) {
1588 ("%s: read of uuid failed (%d)\n",
1589 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1592 afs_ntohuuid(&uuid);
1594 if (read(fd, (char *)&nentries, sizeof(afs_int32)) != sizeof(afs_int32)) {
1596 ("%s: Read of entries failed (%d)\n",
1597 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1600 if (nentries <= 0 || nentries > ADDRSPERSITE) {
1602 ("%s: invalid num of interfaces: %d\n",
1603 AFSDIR_SERVER_SYSID_FILEPATH, nentries));
1606 if (FS_HostAddr_cnt == 0) {
1607 FS_HostAddr_cnt = nentries;
1608 for (i = 0; i < nentries; i++) {
1609 if (read(fd, (char *)&FS_HostAddrs[i], sizeof(afs_int32)) !=
1610 sizeof(afs_int32)) {
1612 ("%s: Read of addresses failed (%d)\n",
1613 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1614 FS_HostAddr_cnt = 0; /* reset it */
1620 ("%s: address list ignored (NetInfo/NetRestrict override)\n",
1621 AFSDIR_SERVER_SYSID_FILEPATH));
1628 WriteSysIdFile(void)
1631 struct versionStamp vsn;
1632 struct afs_stat status;
1635 if (!afs_stat(AFSDIR_SERVER_SYSID_FILEPATH, &status)) {
1637 * File exists; keep the old one around
1639 rk_rename(AFSDIR_SERVER_SYSID_FILEPATH,
1640 AFSDIR_SERVER_OLDSYSID_FILEPATH);
1642 fd = afs_open(AFSDIR_SERVER_SYSID_FILEPATH, O_WRONLY | O_TRUNC | O_CREAT,
1646 ("%s: can't create (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1650 vsn.magic = SYSIDMAGIC;
1652 if ((i = write(fd, (char *)&vsn, sizeof(vsn))) != sizeof(vsn)) {
1654 ("%s: write failed (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1659 afs_htonuuid(&uuid);
1661 write(fd, (char *)&uuid,
1662 sizeof(struct afsUUID))) != sizeof(struct afsUUID)) {
1664 ("%s: write of uuid failed (%d)\n",
1665 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1669 write(fd, (char *)&FS_HostAddr_cnt,
1670 sizeof(afs_int32))) != sizeof(afs_int32)) {
1672 ("%s: write of # of entries failed (%d)\n",
1673 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1676 for (i = 0; i < FS_HostAddr_cnt; i++) {
1677 if (write(fd, (char *)&FS_HostAddrs[i], sizeof(afs_int32)) !=
1678 sizeof(afs_int32)) {
1680 ("%s: write of addresses failed (%d)\n",
1681 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1691 * This routine sets up the buffers for the VL_RegisterAddrs RPC. All addresses
1692 * in FS_HostAddrs[] are in NBO, while the RPC treats them as a "blob" of data
1693 * and so we need to convert each of them into HBO which is what the extra
1694 * array called FS_HostAddrs_HBO is used here.
1697 Do_VLRegisterRPC(void)
1701 afs_uint32 FS_HostAddrs_HBO[ADDRSPERSITE];
1704 for (i = 0; i < FS_HostAddr_cnt; i++)
1705 FS_HostAddrs_HBO[i] = ntohl(FS_HostAddrs[i]);
1706 addrs.bulkaddrs_len = FS_HostAddr_cnt;
1707 addrs.bulkaddrs_val = (afs_uint32 *) FS_HostAddrs_HBO;
1708 code = ubik_VL_RegisterAddrs(cstruct, 0, &FS_HostUUID, 0, &addrs);
1710 if (code == VL_MULTIPADDR) {
1712 ("VL_RegisterAddrs rpc failed; The IP address exists on a different server; repair it\n"));
1714 ("VL_RegisterAddrs rpc failed; See VLLog for details\n"));
1716 } else if (code == RXGEN_OPCODE) {
1718 ("vlserver doesn't support VL_RegisterAddrs rpc; ignored\n"));
1719 FS_registered = 2; /* So we don't have to retry in the gc daemon */
1722 ("VL_RegisterAddrs rpc failed; will retry periodically (code=%d, err=%d)\n",
1724 FS_registered = 1; /* Retry in the gc daemon */
1727 FS_registered = 2; /* So we don't have to retry in the gc daemon */
1739 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH || AFSDIR_SERVER_NETINFO_FILEPATH) {
1741 * Find addresses we are supposed to register as per the netrestrict
1742 * and netinfo files (/usr/afs/local/NetInfo and
1743 * /usr/afs/local/NetRestict)
1748 code = afsconf_ParseNetFiles(FS_HostAddrs, NULL, NULL,
1749 ADDRSPERSITE, reason,
1750 AFSDIR_SERVER_NETINFO_FILEPATH,
1751 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
1753 ViceLog(0, ("Can't register any valid addresses: %s\n", reason));
1756 FS_HostAddr_cnt = (afs_uint32) code;
1759 FS_HostAddr_cnt = rx_getAllAddr(FS_HostAddrs, ADDRSPERSITE);
1762 if (FS_HostAddr_cnt == 1 && rxBind == 1)
1763 code = FS_HostAddrs[0];
1765 code = htonl(INADDR_ANY);
1770 InitVL(struct afsconf_dir *dir)
1775 * If this fails, it's because something major is wrong, and is not
1776 * likely to be time dependent.
1778 code = vl_Initialize(dir);
1781 ("Couldn't initialize volume location library; code=%d.\n", code));
1785 /* Read or create the sysid file and register the fileserver's
1786 * IP addresses with the vlserver.
1788 code = ReadSysIdFile();
1790 /* Need to create the file */
1791 ViceLog(0, ("Creating new SysID file\n"));
1792 if ((code = afs_uuid_create(&FS_HostUUID))) {
1793 ViceLog(0, ("Failed to create new uuid: %d\n", code));
1797 /* A good sysid file exists; inform the vlserver. If any conflicts,
1798 * we always use the latest interface available as the real truth.
1801 code = Do_VLRegisterRPC();
1806 main(int argc, char *argv[])
1810 struct rx_securityClass **securityClasses;
1811 afs_int32 numClasses;
1812 struct rx_service *tservice;
1813 pthread_t serverPid;
1814 pthread_attr_t tattr;
1816 int minVnodesRequired; /* min size of vnode cache */
1817 #ifndef AFS_NT40_ENV
1818 struct rlimit rlim; /* max number of open file descriptors */
1823 afs_uint32 rx_bindhost;
1824 VolumePackageOptions opts;
1826 #ifdef AFS_AIX32_ENV
1827 struct sigaction nsa;
1829 sigemptyset(&nsa.sa_mask);
1830 nsa.sa_handler = SIG_DFL;
1831 nsa.sa_flags = SA_FULLDUMP;
1832 sigaction(SIGABRT, &nsa, NULL);
1833 sigaction(SIGSEGV, &nsa, NULL);
1837 /* Initialize dirpaths */
1838 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
1840 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
1842 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
1846 /* set ihandle package defaults prior to parsing args */
1849 /* check for the parameter file */
1852 FS_configPath = strdup(AFSDIR_SERVER_ETC_DIRPATH);
1853 memset(&logopts, 0, sizeof(logopts));
1855 if (ParseArgs(argc, argv)) {
1858 opr_mutex_init(&fileproc_glock_mutex);
1860 #ifdef AFS_SGI_VNODE_GLUE
1861 if (afs_init_kernel_config(-1) < 0) {
1863 ("Can't determine NUMA configuration, not starting fileserver.\n");
1868 confDir = afsconf_Open(FS_configPath);
1870 fprintf(stderr, "Unable to open config directory %s\n",
1875 /* initialize audit user check */
1876 osi_audit_set_user_check(confDir, fs_IsLocalRealmMatch);
1880 LogCommandLine(argc, argv, "starting", "", "File server", FSLog);
1881 if (afsconf_GetLatestKey(confDir, NULL, NULL) == 0) {
1885 /* initialize the pthread soft signal handler thread */
1887 SetupLogSoftSignals();
1888 opr_softsig_Register(AFS_SIG_CHECK, CheckSignal_Signal);
1889 #ifndef AFS_NT40_ENV
1890 opr_softsig_Register(SIGTERM, CheckDescriptors_Signal);
1893 #if defined(AFS_SGI_ENV)
1894 /* give this guy a non-degrading priority so help busy servers */
1895 schedctl(NDPRI, 0, NDPNORMMAX);
1898 #elif !defined(AFS_NT40_ENV)
1903 #ifdef AFS_DEMAND_ATTACH_FS
1908 if (afs_winsockInit() < 0) {
1909 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
1910 ViceLog(0, ("File server failed to intialize winsock.\n"));
1916 /* if we support more than 16 threads, then we better have the ability
1917 ** to keep open a large number of files simultaneously
1919 #if defined(AFS_AIX_ENV) && !defined(AFS_AIX42_ENV)
1920 curLimit = OPEN_MAX; /* for pre AIX 4.2 systems */
1921 #elif defined(AFS_NT40_ENV)
1922 curLimit = NT_OPEN_MAX; /* open file descriptor limit on NT */
1925 curLimit = 0; /* the number of open file descriptors */
1926 code = getrlimit(RLIMIT_NOFILE, &rlim);
1928 curLimit = rlim.rlim_cur;
1929 rlim.rlim_cur = rlim.rlim_max;
1930 code = setrlimit(RLIMIT_NOFILE, &rlim);
1932 curLimit = rlim.rlim_max;
1935 ViceLog(0, ("Failed to increase open file limit, using default\n"));
1937 #endif /* defined(AFS_AIX_ENV) && !defined(AFS_AIX42_ENV) */
1939 curLimit -= 32; /* leave a slack of 32 file descriptors */
1940 if (lwps > curLimit) {
1944 lwps = 16; /* default to a maximum of 16 threads */
1946 /* tune the ihandle fd cache accordingly */
1947 if (vol_io_params.fd_max_cachesize < curLimit)
1948 vol_io_params.fd_max_cachesize = curLimit + 1;
1951 ("The system supports a max of %d open files and we are starting %d threads (ihandle fd cache is %d)\n",
1952 curLimit, lwps, vol_io_params.fd_max_cachesize));
1955 /* Initialize volume support */
1957 V_BreakVolumeCallbacks = BreakVolumeCallBacksLater;
1960 SetLogThreadNumProgram( rx_GetThreadNum );
1962 /* initialize libacl routines */
1963 acl_Initialize(ACL_VERSION);
1965 /* initialize RX support */
1966 #ifndef AFS_NT40_ENV
1967 rxi_syscallp = viced_syscall;
1969 rx_extraPackets = rxpackets;
1970 rx_extraQuota = 4; /* for outgoing prserver calls from R threads */
1971 rx_SetBusyThreshold(busy_threshold, VBUSY);
1972 rx_SetCallAbortThreshold(abort_threshold);
1973 rx_SetConnAbortThreshold(abort_threshold);
1975 stackSize = 128 * 1024;
1977 stackSize = lwps * 4000;
1978 if (stackSize < 32000)
1980 else if (stackSize > 44000)
1983 #if defined(AFS_HPUX_ENV) || defined(AFS_SUN_ENV) || defined(AFS_SGI51_ENV) || defined(AFS_XBSD_ENV)
1984 rx_SetStackSize(1, stackSize);
1987 rx_SetUdpBufSize(udpBufSize); /* set the UDP buffer size for receive */
1988 rx_bindhost = SetupVL();
1990 if (rx_InitHost(rx_bindhost, (int)htons(7000)) < 0) {
1991 ViceLog(0, ("Cannot initialize RX\n"));
1994 if (!rxJumbograms) {
1995 /* Don't send and don't allow 3.4 clients to send jumbograms. */
1998 if (rxMaxMTU != -1) {
1999 if (rx_SetMaxMTU(rxMaxMTU) != 0) {
2000 ViceLog(0, ("rxMaxMTU %d is invalid\n", rxMaxMTU));
2005 rx_SetRxDeadTime(30);
2006 afsconf_SetSecurityFlags(confDir, AFSCONF_SECOPTS_ALWAYSENCRYPT);
2007 afsconf_BuildServerSecurityObjects(confDir, &securityClasses, &numClasses);
2009 tservice = rx_NewServiceHost(rx_bindhost, /* port */ 0, /* service id */
2010 1, /*service name */
2012 securityClasses, numClasses,
2013 RXAFS_ExecuteRequest);
2016 ("Failed to initialize RX, probably two servers running.\n"));
2019 if (rxkadDisableDotCheck) {
2020 rx_SetSecurityConfiguration(tservice, RXS_CONFIG_FLAGS,
2021 (void *)RXS_CONFIG_FLAGS_DISABLE_DOTCHECK);
2023 rx_SetMinProcs(tservice, 3);
2024 rx_SetMaxProcs(tservice, lwps);
2025 rx_SetCheckReach(tservice, 1);
2028 rx_NewService(0, RX_STATS_SERVICE_ID, "rpcstats", securityClasses,
2029 numClasses, RXSTATS_ExecuteRequest);
2031 ViceLog(0, ("Failed to initialize rpc stat service.\n"));
2034 rx_SetMinProcs(tservice, 2);
2035 rx_SetMaxProcs(tservice, 4);
2037 /* Some rx debugging */
2038 if (rxlog || eventlog) {
2039 debugFile = afs_fopen("rx_dbg", "w");
2041 rx_debugFile = debugFile;
2043 rxevent_debugFile = debugFile;
2046 init_sys_error_to_et(); /* Set up error table translation */
2047 h_InitHostPackage(host_thread_quota); /* set up local cellname and realmname */
2048 InitCallBack(numberofcbs);
2051 code = InitVL(confDir);
2052 if (code && code != VL_MULTIPADDR) {
2053 ViceLog(0, ("Fatal error in library initialization, exiting!!\n"));
2058 if (code && code != -1) {
2059 ViceLog(0, ("Fatal error in protection initialization, exiting!!\n"));
2063 /* allow super users to manage RX statistics */
2064 rx_SetRxStatUserOk(viced_SuperUser);
2066 opr_cv_init(&fsync_cond);
2067 opr_mutex_init(&fsync_glock_mutex);
2069 #if !defined(AFS_DEMAND_ATTACH_FS)
2071 * For DAFS, we do not start the Rx server threads until after
2072 * the volume package is initialized, and fileserver state is
2073 * restored. This is necessary in order to keep host and callback
2074 * package state pristine until we have a chance to restore state.
2076 * Furthermore, startup latency is much lower with dafs, so this
2077 * shouldn't pose a serious problem.
2079 rx_StartServer(0); /* now start handling requests */
2082 /* we ensure that there is enough space in the vnode buffer to satisfy
2083 ** requests from all concurrent threads.
2084 ** the maximum number of vnodes used by a single thread at any one time
2085 ** is three ( "link" uses three vnodes simultaneously, one vLarge and
2086 ** two vSmall for linking files and two vLarge and one vSmall for linking
2089 minVnodesRequired = 2 * lwps + 1;
2090 if (minVnodesRequired > nSmallVns) {
2091 nSmallVns = minVnodesRequired;
2093 ("Overriding -s command line parameter with %d\n",
2096 if (minVnodesRequired > large) {
2097 large = minVnodesRequired;
2098 ViceLog(0, ("Overriding -l command line parameter with %d\n", large));
2101 /* We now do this after getting the listener up and running, so that client
2102 * connections don't timeout (maybe) if a file server is restarted, since it
2103 * will be available "real soon now". Worry about whether we can satisfy the
2104 * calls in the volume package itself.
2106 VOptDefaults(fileServer, &opts);
2107 opts.nLargeVnodes = large;
2108 opts.nSmallVnodes = nSmallVns;
2109 opts.volcache = volcache;
2110 opts.unsafe_attach = unsafe_attach;
2111 if (offline_timeout != -1) {
2112 opts.interrupt_rxcall = rx_InterruptCall;
2113 opts.offline_timeout = offline_timeout;
2115 if (offline_shutdown_timeout == -1) {
2116 /* default to -offline-timeout, if shutdown-specific timeout is not
2118 opts.offline_shutdown_timeout = offline_timeout;
2120 opts.interrupt_rxcall = rx_InterruptCall;
2121 opts.offline_shutdown_timeout = offline_shutdown_timeout;
2124 if (VInitVolumePackage2(fileServer, &opts)) {
2126 ("Shutting down: errors encountered initializing volume package\n"));
2131 /* Install handler to catch the shutdown signal;
2132 * bosserver assumes SIGQUIT shutdown
2134 opr_softsig_Register(SIGQUIT, ShutDown_Signal);
2136 if (VInitAttachVolumes(fileServer)) {
2138 ("Shutting down: errors encountered initializing volume package\n"));
2143 #ifdef AFS_DEMAND_ATTACH_FS
2144 if (fs_state.options.fs_state_restore) {
2147 * restore fileserver state */
2150 rx_StartServer(0); /* now start handling requests */
2151 #endif /* AFS_DEMAND_ATTACH_FS */
2154 * We are done calling fopen/fdopen. It is safe to use a large
2155 * of the file descriptor cache.
2159 ViceLog(5, ("Starting pthreads\n"));
2160 opr_Verify(pthread_attr_init(&tattr) == 0);
2161 opr_Verify(pthread_attr_setdetachstate(&tattr,
2162 PTHREAD_CREATE_DETACHED) == 0);
2164 opr_Verify(pthread_create(&serverPid, &tattr, FiveMinuteCheckLWP,
2165 &fiveminutes) == 0);
2166 opr_Verify(pthread_create(&serverPid, &tattr, HostCheckLWP,
2167 &fiveminutes) == 0);
2168 opr_Verify(pthread_create(&serverPid, &tattr, FsyncCheckLWP,
2169 &fiveminutes) == 0);
2171 gettimeofday(&tp, 0);
2174 * Figure out the FileServer's name and primary address.
2176 ViceLog(0, ("Getting FileServer name...\n"));
2177 code = gethostname(FS_HostName, 64);
2179 ViceLog(0, ("gethostname() failed\n"));
2181 ViceLog(0, ("FileServer host name is '%s'\n", FS_HostName));
2183 ViceLog(0, ("Getting FileServer address...\n"));
2184 he = gethostbyname(FS_HostName);
2186 ViceLog(0, ("Can't find address for FileServer '%s'\n", FS_HostName));
2189 memcpy(&FS_HostAddr_NBO, he->h_addr, 4);
2190 (void)afs_inet_ntoa_r(FS_HostAddr_NBO, hoststr);
2191 FS_HostAddr_HBO = ntohl(FS_HostAddr_NBO);
2193 ("FileServer %s has address %s (0x%x or 0x%x in host byte order)\n",
2194 FS_HostName, hoststr, FS_HostAddr_NBO, FS_HostAddr_HBO));
2198 strftime(tbuffer, sizeof(tbuffer), "%a %b %d %H:%M:%S %Y",
2199 localtime_r(&t, &tm));
2200 ViceLog(0, ("File Server started %s\n", tbuffer));
2201 afs_FullPerfStats.det.epoch.tv_sec = StartTime = tp.tv_sec;
2203 sleep(1000); /* long time */