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 <afs/ptclient.h>
50 #include <afs/afsint.h>
51 #include <afs/vldbint.h>
52 #include <afs/errors.h>
53 #include <afs/ihandle.h>
54 #include <afs/vnode.h>
55 #include <afs/volume.h>
57 #include <afs/cellconfig.h>
59 #include <afs/prs_fs.h>
61 #include <rx/rxstat.h>
63 #include <afs/afs_args.h>
64 #include <afs/vlserver.h>
65 #include <afs/afsutil.h>
66 #include <afs/fileutil.h>
67 #include <afs/ptuser.h>
68 #include <afs/audit.h>
69 #include <afs/partition.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;
98 pthread_mutex_t fsync_glock_mutex;
99 pthread_cond_t fsync_cond;
102 # define NT_OPEN_MAX 1024 /* This is an arbitrary no. we came up with for
103 * now. We hope this will be replaced by a more
104 * intelligent estimate later. */
107 int SystemId; /* ViceID of "Administrators" */
108 int SystemAnyUser; /* Viceid of "System:AnyUser" */
109 prlist SystemAnyUserCPS; /* CPS for "system:AnyUser */
110 int AnonymousID = 0; /* ViceId of "Anonymous" */
111 prlist AnonCPS; /* CPS for "Anonymous" */
113 struct afsconf_dir *confDir; /* Configuration dir object */
115 int restartMode = RESTART_ORDINARY;
118 * Home for the performance statistics.
120 struct afs_PerfStats afs_perfstats;
123 extern int Statistics;
128 int rxJumbograms = 0; /* default is to not send and receive jumbograms. */
129 int rxBind = 0; /* don't bind */
130 int rxkadDisableDotCheck = 0; /* disable check for dot in principal name */
132 afs_int32 implicitAdminRights = PRSFS_LOOKUP; /* The ADMINISTER right is
134 afs_int32 readonlyServer = 0;
137 int stackSize = 24000;
138 int fiveminutes = 300; /* 5 minutes. Change this for debugging only */
139 int CurrentConnections = 0;
140 int hostaclRefresh = 7200; /* refresh host clients' acls every 2 hrs */
141 #if defined(AFS_SGI_ENV)
147 * seconds to wait until forcing a panic during ShutDownAndCore(PANIC)
148 * in case we get stuck.
150 #ifdef AFS_DEMAND_ATTACH_FS
151 static int panic_timeout = 2 * 60;
153 static int panic_timeout = 30 * 60;
156 int rxpackets = 150; /* 100 */
157 int nSmallVns = 400; /* 200 */
158 int large = 400; /* 200 */
159 int volcache = 400; /* 400 */
160 int numberofcbs = 60000; /* 60000 */
161 int lwps = 9; /* 6 */
162 int buffs = 90; /* 70 */
163 int novbc = 0; /* Enable Volume Break calls */
164 int busy_threshold = 600;
165 int abort_threshold = 10;
166 int udpBufSize = 0; /* UDP buffer size for receive */
167 int sendBufSize = 16384; /* send buffer size */
168 int saneacls = 0; /* Sane ACLs Flag */
169 static int unsafe_attach = 0; /* avoid inUse check on vol attach? */
170 static int offline_timeout = -1; /* -offline-timeout option */
171 static int offline_shutdown_timeout = -1; /* -offline-shutdown-timeout option */
175 pthread_key_t viced_uclient_key;
178 * FileServer's name and IP address, both network byte order and
181 #define ADDRSPERSITE 16 /* Same global is in rx/rx_user.c */
183 char FS_HostName[128] = "localhost";
184 char *FS_configPath = NULL;
185 afs_uint32 FS_HostAddr_NBO;
186 afs_uint32 FS_HostAddr_HBO;
187 afs_uint32 FS_HostAddrs[ADDRSPERSITE], FS_HostAddr_cnt = 0, FS_registered = 0;
188 /* All addresses in FS_HostAddrs are in NBO */
191 #ifdef AFS_DEMAND_ATTACH_FS
194 * fileserver mode support
196 * during fileserver shutdown, we have to track the graceful shutdown of
197 * certain background threads before we are allowed to dump state to
201 # if !defined(PTHREAD_RWLOCK_INITIALIZER) && defined(AFS_DARWIN80_ENV)
202 # define PTHREAD_RWLOCK_INITIALIZER {0x2DA8B3B4, {0}}
205 # ifndef AFS_NT40_ENV
206 struct fs_state fs_state =
213 PTHREAD_COND_INITIALIZER,
214 PTHREAD_RWLOCK_INITIALIZER
216 # else /* AFS_NT40_ENV */
217 struct fs_state fs_state;
219 static int fs_stateInit(void)
221 fs_state.mode = FS_MODE_NORMAL;
222 fs_state.FiveMinuteLWP_tranquil = 0;
223 fs_state.HostCheckLWP_tranquil = 0;
224 fs_state.FsyncCheckLWP_tranquil = 0;
225 fs_state.salvsync_fatal_error = 0;
227 fs_state.options.fs_state_save = 1;
228 fs_state.options.fs_state_restore = 1;
229 fs_state.options.fs_state_verify_before_save = 1;
230 fs_state.options.fs_state_verify_after_restore = 1;
232 opr_cv_init(&fs_state.worker_done_cv, "worker done");
233 opr_Verify(pthread_rwlock_init(&fs_state.state_lock, NULL) == 0);
235 # endif /* AFS_NT40_ENV */
236 #endif /* AFS_DEMAND_ATTACH_FS */
239 * Home for the performance statistics.
244 CheckDescriptors(void *unused)
247 struct afs_stat status;
248 int tsize = getdtablesize();
250 for (i = 0; i < tsize; i++) {
251 if (afs_fstat(i, &status) != -1) {
252 printf("%d: dev %x, inode %u, length %u, type/mode %x\n", i,
253 (unsigned int) status.st_dev,
254 (unsigned int) status.st_ino,
255 (unsigned int) status.st_size,
260 ResetCheckDescriptors();
263 } /*CheckDescriptors */
267 CheckSignal_Signal(int x)
273 ShutDown_Signal(int x)
279 CheckDescriptors_Signal(int x)
281 CheckDescriptors(NULL);
284 /* check whether caller is authorized to perform admin operations */
286 viced_SuperUser(struct rx_call *call)
288 return afsconf_SuperUser(confDir, call, NULL);
292 * Return true if this name is a member of the local realm.
295 fs_IsLocalRealmMatch(void *rock, char *name, char *inst, char *cell)
297 struct afsconf_dir *dir = (struct afsconf_dir *)rock;
298 afs_int32 islocal = 0; /* default to no */
301 code = afsconf_IsLocalRealmMatch(dir, &islocal, name, inst, cell);
304 ("Failed local realm check; code=%d, name=%s, inst=%s, cell=%s\n",
305 code, name, inst, cell));
311 ResetCheckSignal(void)
315 #if defined(AFS_HPUX_ENV)
317 #elif defined(AFS_NT40_ENV)
323 #if !defined(AFS_NT40_ENV)
324 softsig_signal(signo, CheckSignal_Signal);
326 signal(signo, CheckSignal_Signal);
331 ResetCheckDescriptors(void)
334 softsig_signal(SIGTERM, CheckDescriptors_Signal);
340 viced_syscall(afs_uint32 a3, afs_uint32 a4, void *a5)
343 # ifndef AFS_LINUX20_ENV
346 old = (void (*)(int))signal(SIGSYS, SIG_IGN);
348 rcode = syscall(AFS_SYSCALL, 28 /* AFSCALL_CALL */ , a3, a4, a5);
349 # ifndef AFS_LINUX20_ENV
357 #if !defined(AFS_NT40_ENV)
358 # include "AFS_component_version_number.c"
359 #endif /* !AFS_NT40_ENV */
361 #define MAXADMINNAME 64
362 char adminName[MAXADMINNAME];
368 struct afs_stat status;
370 if ((afs_stat("/AdminName", &status)) || /* if file does not exist */
371 (status.st_size <= 0) || /* or it is too short */
372 (status.st_size >= (MAXADMINNAME)) || /* or it is too long */
373 !(fd = afs_open("/AdminName", O_RDONLY, 0))) { /* or the open fails */
374 strcpy(adminName, "System:Administrators"); /* use the default name */
376 (void)read(fd, adminName, status.st_size); /* use name from the file */
379 close(fd); /* close fd if it was opened */
381 } /*CheckAdminName */
387 #if !defined(AFS_NT40_ENV)
390 /* set our 'thread-id' so that the host hold table works */
391 threadId = rx_SetThreadNum();
392 afs_pthread_setname_self(s);
393 ViceLog(0, ("Set thread id 0x%x for '%s'\n", threadId, s));
397 /* This LWP does things roughly every 5 minutes */
399 FiveMinuteCheckLWP(void *unused)
404 ViceLog(1, ("Starting five minute check process\n"));
405 setThreadId("FiveMinuteCheckLWP");
407 #ifdef AFS_DEMAND_ATTACH_FS
409 while (fs_state.mode == FS_MODE_NORMAL) {
410 fs_state.FiveMinuteLWP_tranquil = 1;
418 #ifdef AFS_DEMAND_ATTACH_FS
420 if (fs_state.mode != FS_MODE_NORMAL) {
423 fs_state.FiveMinuteLWP_tranquil = 0;
427 /* close the log so it can be removed */
428 ReOpenLog(AFSDIR_SERVER_FILELOG_FILEPATH); /* don't trunc, just append */
429 ViceLog(2, ("Cleaning up timed out callbacks\n"));
430 if (CleanupTimedOutCallBacks())
431 ViceLog(5, ("Timed out callbacks deleted\n"));
432 ViceLog(2, ("Set disk usage statistics\n"));
434 if (FS_registered == 1)
436 /* Force wakeup in case we missed something; pthreads does timedwait */
437 if (printBanner && (++msg & 1)) { /* Every 10 minutes */
438 time_t now = time(NULL);
440 strftime(tbuffer, sizeof(tbuffer), "%a %b %d %H:%M:%S %Y",
441 localtime_r(&now, &tm));
443 ("File server is running at %s\n", tbuffer));
445 #ifdef AFS_DEMAND_ATTACH_FS
449 #ifdef AFS_DEMAND_ATTACH_FS
450 fs_state.FiveMinuteLWP_tranquil = 1;
452 opr_cv_broadcast(&fs_state.worker_done_cv);
457 } /*FiveMinuteCheckLWP */
460 /* This LWP does host checks every 5 minutes: it should not be used for
461 * other 5 minute activities because it may be delayed by timeouts when
462 * it probes the workstations
466 HostCheckLWP(void *unused)
468 ViceLog(1, ("Starting Host check process\n"));
469 setThreadId("HostCheckLWP");
470 #ifdef AFS_DEMAND_ATTACH_FS
472 while (fs_state.mode == FS_MODE_NORMAL) {
473 fs_state.HostCheckLWP_tranquil = 1;
481 #ifdef AFS_DEMAND_ATTACH_FS
483 if (fs_state.mode != FS_MODE_NORMAL) {
486 fs_state.HostCheckLWP_tranquil = 0;
490 ViceLog(2, ("Checking for dead venii & clients\n"));
493 #ifdef AFS_DEMAND_ATTACH_FS
497 #ifdef AFS_DEMAND_ATTACH_FS
498 fs_state.HostCheckLWP_tranquil = 1;
500 opr_cv_broadcast(&fs_state.worker_done_cv);
507 /* This LWP does fsync checks every 5 minutes: it should not be used for
508 * other 5 minute activities because it may be delayed by timeouts when
509 * it probes the workstations
512 FsyncCheckLWP(void *unused)
515 struct timespec fsync_next;
516 ViceLog(1, ("Starting fsync check process\n"));
518 setThreadId("FsyncCheckLWP");
520 #ifdef AFS_DEMAND_ATTACH_FS
522 while (fs_state.mode == FS_MODE_NORMAL) {
523 fs_state.FsyncCheckLWP_tranquil = 1;
529 /* rounding is fine */
530 fsync_next.tv_nsec = 0;
531 fsync_next.tv_sec = time(0) + fiveminutes;
533 code = opr_cv_timedwait(&fsync_cond, &fsync_glock_mutex,
535 if (code != 0 && code != ETIMEDOUT)
536 ViceLog(0, ("pthread_cond_timedwait returned %d\n", code));
539 #ifdef AFS_DEMAND_ATTACH_FS
541 if (fs_state.mode != FS_MODE_NORMAL) {
544 fs_state.FsyncCheckLWP_tranquil = 0;
546 #endif /* AFS_DEMAND_ATTACH_FS */
548 ViceLog(2, ("Checking for fsync events\n"));
550 code = BreakLaterCallBacks();
552 #ifdef AFS_DEMAND_ATTACH_FS
556 #ifdef AFS_DEMAND_ATTACH_FS
557 fs_state.FsyncCheckLWP_tranquil = 1;
559 opr_cv_broadcast(&fs_state.worker_done_cv);
562 #endif /* AFS_DEMAND_ATTACH_FS */
566 /*------------------------------------------------------------------------
567 * PRIVATE ClearXStatValues
570 * Initialize all of the values collected via the xstat
580 * Must be called during File Server initialization.
584 *------------------------------------------------------------------------*/
587 ClearXStatValues(void)
588 { /*ClearXStatValues */
590 struct fs_stats_opTimingData *opTimeP; /*Ptr to timing struct */
591 struct fs_stats_xferData *opXferP; /*Ptr to xfer struct */
592 int i; /*Loop counter */
595 * Zero all xstat-related structures.
597 memset((&afs_perfstats), 0, sizeof(struct afs_PerfStats));
598 memset((&afs_FullPerfStats), 0,
599 sizeof(struct fs_stats_FullPerfStats));
602 * That's not enough. We have to set reasonable minima for
603 * time and xfer values in the detailed stats.
605 opTimeP = &(afs_FullPerfStats.det.rpcOpTimes[0]);
606 for (i = 0; i < FS_STATS_NUM_RPC_OPS; i++, opTimeP++)
607 opTimeP->minTime.tv_sec = 999999;
609 opXferP = &(afs_FullPerfStats.det.xferOpTimes[0]);
610 for (i = 0; i < FS_STATS_NUM_XFER_OPS; i++, opXferP++) {
611 opXferP->minTime.tv_sec = 999999;
612 opXferP->minBytes = 999999999;
616 * There's more. We have to set our unique system identifier, as
617 * declared in param.h. If such a thing is not defined, we bitch
618 * and declare ourselves to be an unknown system type.
621 afs_perfstats.sysname_ID = SYS_NAME_ID;
623 # ifndef AFS_NT40_ENV
624 ViceLog(0, ("Sys name ID constant not defined in param.h!!\n"));
625 ViceLog(0, ("[Choosing ``undefined'' sys name ID.\n"));
627 afs_perfstats.sysname_ID = SYS_NAME_ID_UNDEFINED;
628 # endif /* SYS_NAME_ID */
630 } /*ClearXStatValues */
632 int CopyOnWrite_calls = 0, CopyOnWrite_off0 = 0, CopyOnWrite_size0 = 0;
633 afs_fsize_t CopyOnWrite_maxsize = 0;
638 int dirbuff, dircall, dirio;
640 int workstations, activeworkstations, delworkstations;
644 #ifdef AFS_DEMAND_ATTACH_FS
648 gettimeofday(&tpl, 0);
650 strftime(tbuffer, sizeof(tbuffer), "%a %b %d %H:%M:%S %Y",
651 localtime_r(&StartTime, &tm));
652 ViceLog(0, ("Vice was last started at %s\n", tbuffer));
654 #ifdef AFS_DEMAND_ATTACH_FS
655 if (LogLevel >= 125) {
656 stats_flags = VOL_STATS_PER_CHAIN2;
657 } else if (LogLevel >= 25) {
658 stats_flags = VOL_STATS_PER_CHAIN;
660 VPrintExtendedCacheStats(stats_flags);
664 DStat(&dirbuff, &dircall, &dirio);
666 ("With %d directory buffers; %d reads resulted in %d read I/Os\n",
667 dirbuff, dircall, dirio));
668 rx_PrintStats(stderr);
669 audit_PrintStats(stderr);
671 PrintCallBackStats();
673 processSize = -1; /* TODO: */
675 processSize = (int)((long)sbrk(0) >> 10);
678 ("There are %d connections, process size %d\n",
679 CurrentConnections, processSize));
680 h_GetWorkStats(&workstations, &activeworkstations, &delworkstations,
681 tpl.tv_sec - 15 * 60);
683 ("There are %d workstations, %d are active (req in < 15 mins), %d marked \"down\"\n",
684 workstations, activeworkstations, delworkstations));
685 ViceLog(0, ("CopyOnWrite: calls %d off0 %d size0 %d maxsize 0x%llx\n",
686 CopyOnWrite_calls, CopyOnWrite_off0, CopyOnWrite_size0, CopyOnWrite_maxsize));
695 CheckSignal(void *unused)
697 if (FS_registered > 0) {
699 * We have proper ip addresses; tell the vlserver what we got; the following
700 * routine will do the proper reporting for us
713 ShutdownWatchdogLWP(void *unused)
715 afs_pthread_setname_self("ShutdownWatchdog");
716 sleep(panic_timeout);
717 ViceLogThenPanic(0, ("ShutdownWatchdogLWP: Failed to shutdown and panic "
718 "within %d seconds; forcing panic\n",
724 ShutDownAndCore(int dopanic)
726 time_t now = time(NULL);
731 pthread_t watchdogPid;
732 pthread_attr_t tattr;
733 opr_Verify(pthread_attr_init(&tattr) == 0);
734 opr_Verify(pthread_create(&watchdogPid, &tattr,
735 ShutdownWatchdogLWP, NULL) == 0);
738 /* do not allows new reqests to be served from now on, all new requests
739 * are returned with an error code of RX_RESTARTING ( transient failure ) */
740 rx_SetRxTranquil(); /* dhruba */
744 #ifdef AFS_DEMAND_ATTACH_FS
746 if (fs_state.mode == FS_MODE_SHUTDOWN) {
747 /* it is possible for at least fs_stateSave() (called below) to call
748 * ShutDownAndCore if there's host list corruption; prevent
749 * deinitializing some stuff twice */
750 ViceLog(0, ("ShutDownAndCore called during shutdown? Skipping volume "
751 "and host package shutdown\n"));
755 fs_state.mode = FS_MODE_SHUTDOWN;
759 strftime(tbuffer, sizeof(tbuffer), "%a %b %d %H:%M:%S %Y",
760 localtime_r(&now, &tm));
761 ViceLog(0, ("Shutting down file server at %s\n", tbuffer));
763 ViceLog(0, ("ABNORMAL SHUTDOWN, see core file.\n"));
768 /* shut down volume package */
771 #ifdef AFS_DEMAND_ATTACH_FS
772 if (fs_state.options.fs_state_save) {
775 * save fileserver state to disk */
778 ViceLog(0, ("Not saving fileserver state; abnormal shutdown\n"));
781 /* make sure background threads have finished all of their asynchronous
782 * work on host and callback structures */
784 while (!fs_state.FiveMinuteLWP_tranquil ||
785 !fs_state.HostCheckLWP_tranquil ||
786 !fs_state.FsyncCheckLWP_tranquil) {
789 ViceLog(0, ("waiting for background host/callback threads to quiesce before saving fileserver state...\n"));
790 opr_cv_wait(&fs_state.worker_done_cv, &fileproc_glock_mutex);
796 /* ok. it should now be fairly safe. let's do the state dump */
802 #endif /* AFS_DEMAND_ATTACH_FS */
805 rx_PrintStats(debugFile);
809 strftime(tbuffer, sizeof(tbuffer), "%a %b %d %H:%M:%S %Y",
810 localtime_r(&now, &tm));
812 ViceLog(0, ("File server has terminated abnormally at %s\n", tbuffer));
814 ViceLog(0, ("File server has terminated normally at %s\n", tbuffer));
817 if (dopanic) /* XXX pass in file and line? */
818 osi_Panic("Panic requested\n");
824 ShutDown(void *unused)
825 { /* backward compatibility */
826 ShutDownAndCore(DONTPANIC);
831 ParseRights(char *arights)
837 if (!arights || !strcmp(arights, "")) {
838 printf("Missing list of mode bits on -implicit option\n");
841 if (!strcmp(arights, "none"))
843 else if (!strcmp(arights, "read"))
844 mode = PRSFS_READ | PRSFS_LOOKUP;
845 else if (!strcmp(arights, "write"))
847 PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
848 PRSFS_WRITE | PRSFS_LOCK;
849 else if (!strcmp(arights, "all"))
851 PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
852 PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER;
854 len = strlen(arights);
855 for (i = 0; i < len; i++) {
860 mode |= PRSFS_LOOKUP;
862 mode |= PRSFS_INSERT;
864 mode |= PRSFS_DELETE;
870 mode |= PRSFS_ADMINISTER;
888 printf("Illegal -implicit rights character '%c'.\n", tc);
897 * Limit MAX_FILESERVER_THREAD by the system limit on the number of
898 * pthreads (sysconf(_SC_THREAD_THREADS_MAX)), if applicable and
901 * AIX: sysconf() limit is real
902 * HP-UX: sysconf() limit is real
903 * IRIX: sysconf() limit is apparently NOT real -- too small
904 * DUX: sysconf() limit is apparently NOT real -- too big
905 * Linux: sysconf() limit is apparently NOT real -- too big
906 * Solaris: no sysconf() limit
909 max_fileserver_thread(void)
911 #if defined(AFS_AIX_ENV) || defined(AFS_HPUX_ENV)
914 ans = sysconf(_SC_THREAD_THREADS_MAX);
915 if (0 < ans && ans < MAX_FILESERVER_THREAD)
918 return MAX_FILESERVER_THREAD;
922 extern ih_init_params vol_io_params;
947 OPT_offline_shutdown_timeout,
948 OPT_vhandle_setaside,
949 OPT_vhandle_max_cachesize,
950 OPT_vhandle_initial_cachesize,
951 OPT_fs_state_dont_save,
952 OPT_fs_state_dont_restore,
959 OPT_unsafe_nosalvage,
987 ParseArgs(int argc, char *argv[])
991 char *optstring = NULL;
992 struct cmd_item *optlist;
993 struct cmd_syndesc *opts;
996 char *auditFileName = NULL;
997 char *sync_behavior = NULL;
999 #if defined(AFS_AIX32_ENV)
1000 extern int aixlow_water;
1003 opts = cmd_CreateSyntax(NULL, NULL, NULL, NULL);
1005 /* fileserver options */
1006 cmd_AddParmAtOffset(opts, OPT_large, "-L", CMD_FLAG,
1007 CMD_OPTIONAL, "defaults for a 'large' server");
1008 cmd_AddParmAtOffset(opts, OPT_small, "-S", CMD_FLAG,
1009 CMD_OPTIONAL, "defaults for a 'small' server");
1011 cmd_AddParmAtOffset(opts, OPT_banner, "-banner", CMD_FLAG,
1012 CMD_OPTIONAL, "print regular banners to log");
1013 cmd_AddParmAtOffset(opts, OPT_implicit, "-implicit", CMD_SINGLE,
1014 CMD_OPTIONAL, "implicit admin access bits");
1016 #if defined(AFS_SGI_ENV)
1017 cmd_AddParmAtOffset(opts, OPT_lock, "-lock", CMD_FLAG,
1018 CMD_OPTIONAL, "lock filserver binary in memory");
1020 cmd_AddParmAtOffset(opts, OPT_readonly, "-readonly", CMD_FLAG,
1021 CMD_OPTIONAL, "be a readonly fileserver");
1022 cmd_AddParmAtOffset(opts, OPT_saneacls, "-saneacls", CMD_FLAG,
1023 CMD_OPTIONAL, "set the saneacls capability bit");
1025 cmd_AddParmAtOffset(opts, OPT_buffers, "-b", CMD_SINGLE,
1026 CMD_OPTIONAL, "buffers");
1027 cmd_AddParmAtOffset(opts, OPT_callbacks, "-cb", CMD_SINGLE,
1028 CMD_OPTIONAL, "number of callbacks");
1029 cmd_AddParmAtOffset(opts, OPT_vcsize, "-vc", CMD_SINGLE,
1030 CMD_OPTIONAL, "volume cachesize");
1031 cmd_AddParmAtOffset(opts, OPT_lvnodes, "-l", CMD_SINGLE,
1032 CMD_OPTIONAL, "large vnodes");
1033 cmd_AddParmAtOffset(opts, OPT_svnodes, "-s", CMD_SINGLE,
1034 CMD_OPTIONAL, "small vnodes");
1035 cmd_AddParmAtOffset(opts, OPT_sendsize, "-sendsize", CMD_SINGLE,
1036 CMD_OPTIONAL, "size of send buffer in bytes");
1038 #if defined(AFS_AIX32_ENV)
1039 cmd_AddParmAtOffset(opts, OPT_minspare, "-m", CMD_SINGLE,
1040 CMD_OPTIONAL, "minimum percentage spare in partition");
1043 cmd_AddParmAtOffset(opts, OPT_spare, "-spare", CMD_SINGLE,
1044 CMD_OPTIONAL, "kB overage on volume quota");
1045 cmd_AddParmAtOffset(opts, OPT_pctspare, "pctspare", CMD_SINGLE,
1046 CMD_OPTIONAL, "percentage overage on volume quota");
1048 cmd_AddParmAtOffset(opts, OPT_hostcpsrefresh, "-hr", CMD_SINGLE,
1049 CMD_OPTIONAL, "hours between host CPS refreshes");
1051 cmd_AddParmAtOffset(opts, OPT_vattachthreads, "-vattachpar", CMD_SINGLE,
1052 CMD_OPTIONAL, "# of volume attachment threads");
1054 cmd_AddParmAtOffset(opts, OPT_abortthreshold, "-abortthreshold",
1055 CMD_SINGLE, CMD_OPTIONAL,
1057 cmd_AddParmAtOffset(opts, OPT_busyat, "-busyat", CMD_SINGLE, CMD_OPTIONAL,
1058 "# of queued entries after which server is busy");
1059 cmd_AddParmAtOffset(opts, OPT_nobusy, "-nobusy", CMD_FLAG, CMD_OPTIONAL,
1060 "send VRESTARTING while restarting the server");
1062 cmd_AddParmAtOffset(opts, OPT_offline_timeout, "-offline-timeout",
1063 CMD_SINGLE, CMD_OPTIONAL,
1064 "timeout for offlining volumes");
1065 cmd_AddParmAtOffset(opts, OPT_offline_shutdown_timeout,
1066 "-offline-shutdown-timeout", CMD_SINGLE, CMD_OPTIONAL,
1067 "timeout offlining volumes during shutdown");
1069 cmd_AddParmAtOffset(opts, OPT_vhandle_setaside, "-vhandle-setaside",
1070 CMD_SINGLE, CMD_OPTIONAL,
1071 "# fds reserved for non-cache IO");
1072 cmd_AddParmAtOffset(opts, OPT_vhandle_max_cachesize,
1073 "-vhandle-max-cachesize", CMD_SINGLE, CMD_OPTIONAL,
1075 cmd_AddParmAtOffset(opts, OPT_vhandle_initial_cachesize,
1076 "-vhandle-initial-cachesize", CMD_SINGLE,
1077 CMD_OPTIONAL, "# fds reserved for cache IO");
1079 #ifdef AFS_DEMAND_ATTACH_FS
1081 cmd_AddParmAtOffset(opts, OPT_fs_state_dont_save,
1082 "-fs-state-dont-save", CMD_FLAG, CMD_OPTIONAL,
1083 "disable state save during shutdown");
1084 cmd_AddParmAtOffset(opts, OPT_fs_state_dont_restore,
1085 "-fs-state-dont-restore", CMD_FLAG, CMD_OPTIONAL,
1086 "disable state restore during startup");
1087 cmd_AddParmAtOffset(opts, OPT_fs_state_verify, "-fs-state-verify",
1088 CMD_SINGLE, CMD_OPTIONAL, "none|save|restore|both");
1089 cmd_AddParmAtOffset(opts, OPT_vhashsize, "-vhashsize",
1090 CMD_SINGLE, CMD_OPTIONAL,
1091 "log(2) of # of volume hash buckets");
1092 cmd_AddParmAtOffset(opts, OPT_vlrudisable, "-vlrudisable",
1093 CMD_FLAG, CMD_OPTIONAL, "disable VLRU functionality");
1094 cmd_AddParmAtOffset(opts, OPT_vlruthresh, "-vlruthresh",
1095 CMD_FLAG, CMD_OPTIONAL,
1096 "mins before unused vols become eligible for detach");
1097 cmd_AddParmAtOffset(opts, OPT_vlruinterval, "-vlruinterval",
1098 CMD_FLAG, CMD_OPTIONAL, "secs between VLRU scans");
1099 cmd_AddParmAtOffset(opts, OPT_vlrumax, "-vlrumax", CMD_FLAG, CMD_OPTIONAL,
1100 "max volumes to detach in one scan");
1101 cmd_AddParmAtOffset(opts, OPT_unsafe_nosalvage, "-unsafe-nosalvage",
1102 CMD_FLAG, CMD_OPTIONAL,
1103 "bybass safety checks on volume attach");
1106 /* unrecommend options - should perhaps be CMD_HIDE */
1107 cmd_AddParmAtOffset(opts, OPT_stack, "-k", CMD_SINGLE, CMD_OPTIONAL,
1109 cmd_AddParmAtOffset(opts, OPT_cbwait, "-w", CMD_SINGLE, CMD_OPTIONAL,
1110 "callback wait interval");
1111 cmd_AddParmAtOffset(opts, OPT_novbc, "-novbc", CMD_SINGLE, CMD_FLAG,
1112 "disable callback breaks on reattach");
1114 /* general options */
1115 cmd_AddParmAtOffset(opts, OPT_auditlog, "-auditlog", CMD_SINGLE,
1116 CMD_OPTIONAL, "location of audit log");
1117 cmd_AddParmAtOffset(opts, OPT_auditiface, "-audit-interface", CMD_SINGLE,
1118 CMD_OPTIONAL, "interface to use for audit logging");
1119 cmd_AddParmAtOffset(opts, OPT_config, "-config", CMD_SINGLE, CMD_OPTIONAL,
1120 "configuration location");
1121 cmd_AddParmAtOffset(opts, OPT_debug, "-d", CMD_SINGLE, CMD_OPTIONAL,
1123 cmd_AddParmAtOffset(opts, OPT_logfile, "-logfile", CMD_SINGLE,
1124 CMD_OPTIONAL, "location of logfile");
1125 cmd_AddParmAtOffset(opts, OPT_mrafslogs, "-mrafslogs", CMD_FLAG,
1126 CMD_OPTIONAL, "enable MRAFS style logging");
1127 cmd_AddParmAtOffset(opts, OPT_threads, "-p", CMD_SINGLE, CMD_OPTIONAL,
1128 "number of threads");
1129 #if !defined(AFS_NT40_ENV)
1130 cmd_AddParmAtOffset(opts, OPT_syslog, "-syslog", CMD_SINGLE_OR_FLAG,
1131 CMD_OPTIONAL, "log to syslog");
1135 cmd_AddParmAtOffset(opts, OPT_peer, "-enable_peer_stats", CMD_FLAG,
1136 CMD_OPTIONAL, "enable RX transport statistics");
1137 cmd_AddParmAtOffset(opts, OPT_process, "-enable_process_stats", CMD_FLAG,
1138 CMD_OPTIONAL, "enable RX RPC statistics");
1139 cmd_AddParmAtOffset(opts, OPT_nojumbo, "-nojumbo", CMD_FLAG,
1140 CMD_OPTIONAL, "disable jumbograms");
1141 cmd_AddParmAtOffset(opts, OPT_jumbo, "-jumbo", CMD_FLAG, CMD_OPTIONAL,
1142 "enable jumbograms");
1143 cmd_AddParmAtOffset(opts, OPT_rxbind, "-rxbind", CMD_FLAG, CMD_OPTIONAL,
1144 "bind only to the primary interface");
1145 cmd_AddParmAtOffset(opts, OPT_rxdbg, "-rxdbg", CMD_FLAG, CMD_OPTIONAL,
1146 "enable rx debugging");
1147 cmd_AddParmAtOffset(opts, OPT_rxdbge, "-rxdbge", CMD_FLAG, CMD_OPTIONAL,
1148 "enable rx event debugging");
1149 cmd_AddParmAtOffset(opts, OPT_rxpck, "-rxpck", CMD_SINGLE, CMD_OPTIONAL,
1150 "# of extra rx packets");
1151 cmd_AddParmAtOffset(opts, OPT_rxmaxmtu, "-rxmaxmtu", CMD_SINGLE,
1152 CMD_OPTIONAL, "maximum MTU for RX");
1153 cmd_AddParmAtOffset(opts, OPT_udpsize, "-udpsize", CMD_SINGLE,
1154 CMD_OPTIONAL, "size of socket buffer in bytes");
1157 cmd_AddParmAtOffset(opts, OPT_dotted, "-allow-dotted-principals",
1158 CMD_FLAG, CMD_OPTIONAL,
1159 "permit Kerberos 5 principals with dots");
1160 cmd_AddParmAtOffset(opts, OPT_realm, "-realm",
1161 CMD_LIST, CMD_OPTIONAL, "local realm");
1162 cmd_AddParmAtOffset(opts, OPT_sync, "-sync",
1163 CMD_SINGLE, CMD_OPTIONAL, "always | onclose | never");
1165 /* testing options */
1166 cmd_AddParmAtOffset(opts, OPT_logfile, "-logfile", CMD_SINGLE,
1167 CMD_OPTIONAL, "location of log file");
1168 cmd_AddParmAtOffset(opts, OPT_config, "-config", CMD_SINGLE,
1169 CMD_OPTIONAL, "configuration location");
1171 code = cmd_Parse(argc, argv, &opts);
1175 cmd_OpenConfigFile(AFSDIR_SERVER_CONFIG_FILE_FILEPATH);
1176 cmd_SetCommandName("fileserver");
1178 if (cmd_OptionPresent(opts, OPT_large)
1179 && cmd_OptionPresent(opts, OPT_small)) {
1180 printf("Only one of -L or -S must be specified\n");
1184 if (cmd_OptionPresent(opts, OPT_spare)
1185 && cmd_OptionPresent(opts, OPT_pctspare)) {
1186 printf("Both -spare and -pctspare specified, exiting.\n");
1190 if (cmd_OptionPresent(opts, OPT_large)) {
1194 numberofcbs = 64000;
1200 if (cmd_OptionPresent(opts, OPT_small)) {
1204 numberofcbs = 20000;
1210 cmd_OptionAsFlag(opts, OPT_banner, &printBanner);
1212 if (cmd_OptionAsString(opts, OPT_implicit, &optstring) == 0) {
1213 implicitAdminRights = ParseRights(optstring);
1216 if (implicitAdminRights < 0)
1217 return implicitAdminRights;
1220 #if defined(AFS_SGI_ENV)
1221 cmd_OptionAsFlag(opts, OPT_lock, &SawLock);
1223 cmd_OptionAsFlag(opts, OPT_readonly, &readonlyServer);
1224 cmd_OptionAsFlag(opts, OPT_saneacls, &saneacls);
1225 cmd_OptionAsInt(opts, OPT_buffers, &buffs);
1227 if (cmd_OptionAsInt(opts, OPT_callbacks, &numberofcbs) == 0) {
1228 if ((numberofcbs < 10000) || (numberofcbs > 2147483647)) {
1229 printf("number of cbs %d invalid; "
1230 "must be between 10000 and 2147483647\n", numberofcbs);
1235 cmd_OptionAsInt(opts, OPT_vcsize, &volcache);
1236 cmd_OptionAsInt(opts, OPT_lvnodes, &large);
1237 cmd_OptionAsInt(opts, OPT_svnodes, &nSmallVns);
1238 if (cmd_OptionAsInt(opts, OPT_sendsize, &optval) == 0) {
1239 if (optval < 16384) {
1240 printf("Warning:sendsize %d is less than minimum %d; ignoring\n",
1243 sendBufSize = optval;
1246 #if defined(AFS_AIX32_ENV)
1247 if (cmd_OptionAsInt(opts, OPT_minspare, &aixlow_water) == 0) {
1248 if ((aixlow_water < 0) || (aixlow_water > 30)) {
1249 printf("space reserved %d%% invalid; must be between 0-30%\n",
1256 cmd_OptionAsInt(opts, OPT_spare, &BlocksSpare);
1257 if (cmd_OptionAsInt(opts, OPT_pctspare, &PctSpare) == 0) {
1261 if (cmd_OptionAsInt(opts, OPT_hostcpsrefresh, &optval) == 0) {
1262 if ((optval < 1) || (optval > 36)) {
1263 printf("host acl refresh interval of %d hours is invalid; "
1264 "hours must be between 1 and 36\n\n", optval);
1267 hostaclRefresh = optval * 60 * 60;
1270 cmd_OptionAsInt(opts, OPT_vattachthreads, &vol_attach_threads);
1272 cmd_OptionAsInt(opts, OPT_abortthreshold, &abort_threshold);
1274 /* busyat is at the end, as rxpackets has to be set before we can use it */
1275 if (cmd_OptionPresent(opts, OPT_nobusy))
1278 if (cmd_OptionAsInt(opts, OPT_offline_timeout, &offline_timeout) == 0) {
1279 if (offline_timeout < -1) {
1280 printf("Invalid -offline-timeout value %d; the only valid "
1281 "negative value is -1\n", offline_timeout);
1286 if (cmd_OptionAsInt(opts, OPT_offline_shutdown_timeout,
1287 &offline_shutdown_timeout) == 0) {
1288 if (offline_shutdown_timeout < -1) {
1289 printf("Invalid -offline-timeout value %d; the only valid "
1290 "negative value is -1\n", offline_shutdown_timeout);
1295 cmd_OptionAsUint(opts, OPT_vhandle_setaside,
1296 &vol_io_params.fd_handle_setaside);
1297 cmd_OptionAsUint(opts, OPT_vhandle_max_cachesize,
1298 &vol_io_params.fd_max_cachesize);
1299 cmd_OptionAsUint(opts, OPT_vhandle_initial_cachesize,
1300 &vol_io_params.fd_initial_cachesize);
1301 if (cmd_OptionAsString(opts, OPT_sync, &sync_behavior) == 0) {
1302 if (ih_SetSyncBehavior(sync_behavior)) {
1303 printf("Invalid -sync value %s\n", sync_behavior);
1308 #ifdef AFS_DEMAND_ATTACH_FS
1309 if (cmd_OptionPresent(opts, OPT_fs_state_dont_save))
1310 fs_state.options.fs_state_save = 0;
1311 if (cmd_OptionPresent(opts, OPT_fs_state_dont_restore))
1312 fs_state.options.fs_state_restore = 0;
1313 if (cmd_OptionAsString(opts, OPT_fs_state_verify, &optstring) == 0) {
1314 if (strcmp(optstring, "none") == 0) {
1315 fs_state.options.fs_state_verify_before_save = 0;
1316 fs_state.options.fs_state_verify_after_restore = 0;
1317 } else if (strcmp(optstring, "save") == 0) {
1318 fs_state.options.fs_state_verify_after_restore = 0;
1319 } else if (strcmp(optstring, "restore") == 0) {
1320 fs_state.options.fs_state_verify_before_save = 0;
1321 } else if (strcmp(optstring, "both") == 0) {
1324 fprintf(stderr, "invalid argument for -fs-state-verify\n");
1328 if (cmd_OptionAsInt(opts, OPT_vhashsize, &optval) == 0) {
1329 if (VSetVolHashSize(optval)) {
1330 fprintf(stderr, "specified -vhashsize (%d) is invalid or out "
1331 "of range\n", optval);
1335 if (cmd_OptionPresent(opts, OPT_vlrudisable))
1336 VLRU_SetOptions(VLRU_SET_ENABLED, 0);
1337 if (cmd_OptionAsInt(opts, OPT_vlruthresh, &optval) == 0)
1338 VLRU_SetOptions(VLRU_SET_THRESH, 60*optval);
1339 if (cmd_OptionAsInt(opts, OPT_vlruinterval, &optval) == 0)
1340 VLRU_SetOptions(VLRU_SET_INTERVAL, optval);
1341 if (cmd_OptionAsInt(opts, OPT_vlrumax, &optval) == 0)
1342 VLRU_SetOptions(VLRU_SET_MAX, optval);
1343 cmd_OptionAsFlag(opts, OPT_unsafe_nosalvage, &unsafe_attach);
1344 #endif /* AFS_DEMAND_ATTACH_FS */
1346 cmd_OptionAsInt(opts, OPT_stack, &stack);
1347 cmd_OptionAsInt(opts, OPT_cbwait, &fiveminutes);
1348 cmd_OptionAsFlag(opts, OPT_novbc, &novbc);
1350 /* general server options */
1351 cmd_OptionAsString(opts, OPT_auditlog, &auditFileName);
1353 if (cmd_OptionAsString(opts, OPT_auditiface, &optstring) == 0) {
1354 if (osi_audit_interface(optstring)) {
1355 printf("Invalid audit interface '%s'\n", optstring);
1362 cmd_OptionAsInt(opts, OPT_debug, &LogLevel);
1363 cmd_OptionAsFlag(opts, OPT_mrafslogs, &mrafsStyleLogs);
1365 if (cmd_OptionAsInt(opts, OPT_threads, &lwps) == 0) {
1366 lwps_max = max_fileserver_thread() - FILESERVER_HELPER_THREADS;
1367 if (lwps > lwps_max)
1373 #ifndef AFS_NT40_ENV
1374 if (cmd_OptionPresent(opts, OPT_syslog)) {
1375 serverLogSyslog = 1;
1376 cmd_OptionAsInt(opts, OPT_syslog, &serverLogSyslogFacility);
1380 if (cmd_OptionPresent(opts, OPT_peer))
1381 rx_enablePeerRPCStats();
1382 if (cmd_OptionPresent(opts, OPT_process))
1383 rx_enableProcessRPCStats();
1384 if (cmd_OptionPresent(opts, OPT_nojumbo))
1386 if (cmd_OptionPresent(opts, OPT_jumbo))
1388 cmd_OptionAsFlag(opts, OPT_rxbind, &rxBind);
1389 cmd_OptionAsFlag(opts, OPT_rxdbg, &rxlog);
1390 cmd_OptionAsFlag(opts, OPT_rxdbge, &eventlog);
1391 cmd_OptionAsInt(opts, OPT_rxpck, &rxpackets);
1393 cmd_OptionAsInt(opts, OPT_rxmaxmtu, &rxMaxMTU);
1395 if (cmd_OptionAsInt(opts, OPT_udpsize, &optval) == 0) {
1396 if (optval < rx_GetMinUdpBufSize()) {
1397 printf("Warning:udpsize %d is less than minimum %d; ignoring\n",
1398 optval, rx_GetMinUdpBufSize());
1400 udpBufSize = optval;
1404 cmd_OptionAsFlag(opts, OPT_dotted, &rxkadDisableDotCheck);
1405 if (cmd_OptionAsList(opts, OPT_realm, &optlist) == 0) {
1407 for (; optlist != NULL; optlist=optlist->next) {
1408 if (strlen(optlist->data) >= AFS_REALM_SZ) {
1409 printf("-realm argument must contain fewer than %d "
1410 "characters.\n", AFS_REALM_SZ);
1413 afsconf_SetLocalRealm(optlist->data); /* overrides krb.conf file, if one */
1417 /* anything setting rxpackets must come before this */
1418 if (cmd_OptionAsInt(opts, OPT_busyat, &optval) == 0) {
1420 printf("Busy threshold %d is too low, will use default.\n",
1422 busy_threshold = 3 * rxpackets / 2;
1424 busy_threshold = optval;
1427 busy_threshold = 3 * rxpackets / 2;
1430 cmd_OptionAsString(opts, OPT_logfile, &logFile);
1431 cmd_OptionAsString(opts, OPT_config, &FS_configPath);
1435 osi_audit_file(auditFileName);
1440 /* Once upon a time, in a galaxy far far away, IBM AFS supported the use of
1441 * a file /vice/file/parms, the contents of which would override any command
1442 * line parameters. We no longer support the use of such a file, but we warn
1443 * if we encounter its presence from an older release
1448 struct afs_stat sbuf;
1450 if (afs_stat("/vice/file/parms", &sbuf) == 0) {
1451 ViceLog(0, ("Using /vice/file/parms to override command line "
1452 "options is no longer supported"));
1456 /* Miscellaneous routines */
1458 Die(const char *msg)
1461 ViceLogThenPanic(0, ("%s\n", msg));
1471 * If this fails, it's because something major is wrong, and is not
1472 * likely to be time dependent.
1474 code = pr_Initialize(2, AFSDIR_SERVER_ETC_DIRPATH, 0);
1477 ("Couldn't initialize protection library; code=%d.\n", code));
1481 opr_Verify(pthread_key_create(&viced_uclient_key, NULL) == 0);
1483 SystemId = SYSADMINID;
1484 SystemAnyUser = ANYUSERID;
1485 SystemAnyUserCPS.prlist_len = 0;
1486 SystemAnyUserCPS.prlist_val = NULL;
1487 AnonCPS.prlist_len = 0;
1488 AnonCPS.prlist_val = NULL;
1490 code = pr_GetCPS(SystemAnyUser, &SystemAnyUserCPS);
1493 ("Couldn't get CPS for AnyUser, will try again in 30 seconds; code=%d.\n",
1497 code = pr_GetCPS(ANONYMOUSID, &AnonCPS);
1500 ("Couldn't get Anonymous CPS, exiting; code=%d.\n",
1504 AnonymousID = ANONYMOUSID;
1511 static struct ubik_client *cstruct;
1514 vl_Initialize(struct afsconf_dir *dir)
1517 afs_int32 scIndex = RX_SECIDX_NULL;
1518 struct afsconf_cell info;
1519 struct rx_securityClass *sc;
1520 struct rx_connection *serverconns[MAXSERVERS];
1522 memset(serverconns, 0, sizeof(serverconns));
1523 code = afsconf_ClientAuth(dir, &sc, &scIndex);
1525 ViceLog(0, ("Could not get security object for localAuth\n"));
1528 code = afsconf_GetCellInfo(dir, NULL, AFSCONF_VLDBSERVICE, &info);
1531 ("vl_Initialize: Failed to get cell information\n"));
1534 if (info.numServers > MAXSERVERS) {
1536 ("vl_Initialize: info.numServers=%d (> MAXSERVERS=%d)\n",
1537 info.numServers, MAXSERVERS));
1540 for (i = 0; i < info.numServers; i++)
1542 rx_NewConnection(info.hostAddr[i].sin_addr.s_addr,
1543 info.hostAddr[i].sin_port, USER_SERVICE_ID, sc,
1545 code = ubik_ClientInit(serverconns, &cstruct);
1547 ViceLog(0, ("vl_Initialize: ubik client init failed.\n"));
1553 #define SYSIDMAGIC 0x88aabbcc
1554 #define SYSIDVERSION 1
1559 afs_int32 fd, nentries, i;
1560 struct versionStamp vsn;
1561 struct afs_stat status;
1564 if ((afs_stat(AFSDIR_SERVER_SYSID_FILEPATH, &status))
1565 || (status.st_size <= 0)) {
1566 ViceLog(0, ("%s: doesn't exist\n", AFSDIR_SERVER_SYSID_FILEPATH));
1569 if (!(fd = afs_open(AFSDIR_SERVER_SYSID_FILEPATH, O_RDONLY, 0))) {
1571 ("%s: can't open (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1575 if (read(fd, (char *)&vsn, sizeof(vsn)) != sizeof(vsn)) {
1577 ("%s: Read failed (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1581 if (vsn.magic != SYSIDMAGIC) {
1583 ("%s: wrong magic %x (we support %x)\n",
1584 AFSDIR_SERVER_SYSID_FILEPATH, vsn.magic, SYSIDMAGIC));
1587 if (vsn.version != SYSIDVERSION) {
1589 ("%s: wrong version %d (we support %d)\n",
1590 AFSDIR_SERVER_SYSID_FILEPATH, vsn.version, SYSIDVERSION));
1593 if (read(fd, (char *)&uuid, sizeof(struct afsUUID))
1594 != sizeof(struct afsUUID)) {
1596 ("%s: read of uuid failed (%d)\n",
1597 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1600 afs_ntohuuid(&uuid);
1602 if (read(fd, (char *)&nentries, sizeof(afs_int32)) != sizeof(afs_int32)) {
1604 ("%s: Read of entries failed (%d)\n",
1605 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1608 if (nentries <= 0 || nentries > ADDRSPERSITE) {
1610 ("%s: invalid num of interfaces: %d\n",
1611 AFSDIR_SERVER_SYSID_FILEPATH, nentries));
1614 if (FS_HostAddr_cnt == 0) {
1615 FS_HostAddr_cnt = nentries;
1616 for (i = 0; i < nentries; i++) {
1617 if (read(fd, (char *)&FS_HostAddrs[i], sizeof(afs_int32)) !=
1618 sizeof(afs_int32)) {
1620 ("%s: Read of addresses failed (%d)\n",
1621 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1622 FS_HostAddr_cnt = 0; /* reset it */
1628 ("%s: address list ignored (NetInfo/NetRestrict override)\n",
1629 AFSDIR_SERVER_SYSID_FILEPATH));
1636 WriteSysIdFile(void)
1639 struct versionStamp vsn;
1640 struct afs_stat status;
1643 if (!afs_stat(AFSDIR_SERVER_SYSID_FILEPATH, &status)) {
1645 * File exists; keep the old one around
1647 rk_rename(AFSDIR_SERVER_SYSID_FILEPATH,
1648 AFSDIR_SERVER_OLDSYSID_FILEPATH);
1650 fd = afs_open(AFSDIR_SERVER_SYSID_FILEPATH, O_WRONLY | O_TRUNC | O_CREAT,
1654 ("%s: can't create (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1658 vsn.magic = SYSIDMAGIC;
1660 if ((i = write(fd, (char *)&vsn, sizeof(vsn))) != sizeof(vsn)) {
1662 ("%s: write failed (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1667 afs_htonuuid(&uuid);
1669 write(fd, (char *)&uuid,
1670 sizeof(struct afsUUID))) != sizeof(struct afsUUID)) {
1672 ("%s: write of uuid failed (%d)\n",
1673 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1677 write(fd, (char *)&FS_HostAddr_cnt,
1678 sizeof(afs_int32))) != sizeof(afs_int32)) {
1680 ("%s: write of # of entries failed (%d)\n",
1681 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1684 for (i = 0; i < FS_HostAddr_cnt; i++) {
1685 if (write(fd, (char *)&FS_HostAddrs[i], sizeof(afs_int32)) !=
1686 sizeof(afs_int32)) {
1688 ("%s: write of addresses failed (%d)\n",
1689 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1699 * This routine sets up the buffers for the VL_RegisterAddrs RPC. All addresses
1700 * in FS_HostAddrs[] are in NBO, while the RPC treats them as a "blob" of data
1701 * and so we need to convert each of them into HBO which is what the extra
1702 * array called FS_HostAddrs_HBO is used here.
1705 Do_VLRegisterRPC(void)
1709 afs_uint32 FS_HostAddrs_HBO[ADDRSPERSITE];
1712 for (i = 0; i < FS_HostAddr_cnt; i++)
1713 FS_HostAddrs_HBO[i] = ntohl(FS_HostAddrs[i]);
1714 addrs.bulkaddrs_len = FS_HostAddr_cnt;
1715 addrs.bulkaddrs_val = (afs_uint32 *) FS_HostAddrs_HBO;
1716 code = ubik_VL_RegisterAddrs(cstruct, 0, &FS_HostUUID, 0, &addrs);
1718 if (code == VL_MULTIPADDR) {
1720 ("VL_RegisterAddrs rpc failed; The IP address exists on a different server; repair it\n"));
1722 ("VL_RegisterAddrs rpc failed; See VLLog for details\n"));
1724 } else if (code == RXGEN_OPCODE) {
1726 ("vlserver doesn't support VL_RegisterAddrs rpc; ignored\n"));
1727 FS_registered = 2; /* So we don't have to retry in the gc daemon */
1730 ("VL_RegisterAddrs rpc failed; will retry periodically (code=%d, err=%d)\n",
1732 FS_registered = 1; /* Retry in the gc daemon */
1735 FS_registered = 2; /* So we don't have to retry in the gc daemon */
1747 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH || AFSDIR_SERVER_NETINFO_FILEPATH) {
1749 * Find addresses we are supposed to register as per the netrestrict
1750 * and netinfo files (/usr/afs/local/NetInfo and
1751 * /usr/afs/local/NetRestict)
1756 code = afsconf_ParseNetFiles(FS_HostAddrs, NULL, NULL,
1757 ADDRSPERSITE, reason,
1758 AFSDIR_SERVER_NETINFO_FILEPATH,
1759 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
1761 ViceLog(0, ("Can't register any valid addresses: %s\n", reason));
1764 FS_HostAddr_cnt = (afs_uint32) code;
1767 FS_HostAddr_cnt = rx_getAllAddr(FS_HostAddrs, ADDRSPERSITE);
1770 if (FS_HostAddr_cnt == 1 && rxBind == 1)
1771 code = FS_HostAddrs[0];
1773 code = htonl(INADDR_ANY);
1778 InitVL(struct afsconf_dir *dir)
1783 * If this fails, it's because something major is wrong, and is not
1784 * likely to be time dependent.
1786 code = vl_Initialize(dir);
1789 ("Couldn't initialize volume location library; code=%d.\n", code));
1793 /* Read or create the sysid file and register the fileserver's
1794 * IP addresses with the vlserver.
1796 code = ReadSysIdFile();
1798 /* Need to create the file */
1799 ViceLog(0, ("Creating new SysID file\n"));
1800 if ((code = afs_uuid_create(&FS_HostUUID))) {
1801 ViceLog(0, ("Failed to create new uuid: %d\n", code));
1805 /* A good sysid file exists; inform the vlserver. If any conflicts,
1806 * we always use the latest interface available as the real truth.
1809 code = Do_VLRegisterRPC();
1814 main(int argc, char *argv[])
1818 struct rx_securityClass **securityClasses;
1819 afs_int32 numClasses;
1820 struct rx_service *tservice;
1821 pthread_t serverPid;
1822 pthread_attr_t tattr;
1824 int minVnodesRequired; /* min size of vnode cache */
1825 #ifndef AFS_NT40_ENV
1826 struct rlimit rlim; /* max number of open file descriptors */
1831 afs_uint32 rx_bindhost;
1832 VolumePackageOptions opts;
1834 #ifdef AFS_AIX32_ENV
1835 struct sigaction nsa;
1837 sigemptyset(&nsa.sa_mask);
1838 nsa.sa_handler = SIG_DFL;
1839 nsa.sa_flags = SA_FULLDUMP;
1840 sigaction(SIGABRT, &nsa, NULL);
1841 sigaction(SIGSEGV, &nsa, NULL);
1845 /* Initialize dirpaths */
1846 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
1848 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
1850 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
1854 /* set ihandle package defaults prior to parsing args */
1857 /* check for the parameter file */
1860 FS_configPath = strdup(AFSDIR_SERVER_ETC_DIRPATH);
1861 logFile = strdup(AFSDIR_SERVER_FILELOG_FILEPATH);
1863 if (ParseArgs(argc, argv)) {
1866 opr_mutex_init(&fileproc_glock_mutex);
1868 #ifdef AFS_SGI_VNODE_GLUE
1869 if (afs_init_kernel_config(-1) < 0) {
1871 ("Can't determine NUMA configuration, not starting fileserver.\n");
1876 confDir = afsconf_Open(FS_configPath);
1878 fprintf(stderr, "Unable to open config directory %s\n",
1883 /* initialize audit user check */
1884 osi_audit_set_user_check(confDir, fs_IsLocalRealmMatch);
1886 /* Open FileLog on stdout, stderr, fd 1 and fd2 (for perror), sigh. */
1887 #ifndef AFS_NT40_ENV
1888 serverLogSyslogTag = "fileserver";
1893 LogCommandLine(argc, argv, "starting", "", "File server", FSLog);
1894 if (afsconf_GetLatestKey(confDir, NULL, NULL) == 0) {
1898 #if !defined(AFS_NT40_ENV)
1899 /* initialize the pthread soft signal handler thread */
1903 /* install signal handlers for controlling the fileserver process */
1904 ResetCheckSignal(); /* set CheckSignal_Signal() sig handler */
1905 ResetCheckDescriptors(); /* set CheckDescriptors_Signal() sig handler */
1907 #if defined(AFS_SGI_ENV)
1908 /* give this guy a non-degrading priority so help busy servers */
1909 schedctl(NDPRI, 0, NDPNORMMAX);
1912 #elif !defined(AFS_NT40_ENV)
1913 nice(-5); /* TODO: */
1916 #ifdef AFS_DEMAND_ATTACH_FS
1921 if (afs_winsockInit() < 0) {
1922 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
1923 ViceLog(0, ("File server failed to intialize winsock.\n"));
1929 /* if we support more than 16 threads, then we better have the ability
1930 ** to keep open a large number of files simultaneously
1932 #if defined(AFS_AIX_ENV) && !defined(AFS_AIX42_ENV)
1933 curLimit = OPEN_MAX; /* for pre AIX 4.2 systems */
1934 #elif defined(AFS_NT40_ENV)
1935 curLimit = NT_OPEN_MAX; /* open file descriptor limit on NT */
1938 curLimit = 0; /* the number of open file descriptors */
1939 code = getrlimit(RLIMIT_NOFILE, &rlim);
1941 curLimit = rlim.rlim_cur;
1942 rlim.rlim_cur = rlim.rlim_max;
1943 code = setrlimit(RLIMIT_NOFILE, &rlim);
1945 curLimit = rlim.rlim_max;
1948 ViceLog(0, ("Failed to increase open file limit, using default\n"));
1950 #endif /* defined(AFS_AIX_ENV) && !defined(AFS_AIX42_ENV) */
1952 curLimit -= 32; /* leave a slack of 32 file descriptors */
1953 if (lwps > curLimit) {
1957 lwps = 16; /* default to a maximum of 16 threads */
1959 /* tune the ihandle fd cache accordingly */
1960 if (vol_io_params.fd_max_cachesize < curLimit)
1961 vol_io_params.fd_max_cachesize = curLimit + 1;
1964 ("The system supports a max of %d open files and we are starting %d threads (ihandle fd cache is %d)\n",
1965 curLimit, lwps, vol_io_params.fd_max_cachesize));
1968 /* Initialize volume support */
1970 V_BreakVolumeCallbacks = BreakVolumeCallBacksLater;
1973 SetLogThreadNumProgram( rx_GetThreadNum );
1975 /* initialize libacl routines */
1976 acl_Initialize(ACL_VERSION);
1978 /* initialize RX support */
1979 #ifndef AFS_NT40_ENV
1980 rxi_syscallp = viced_syscall;
1982 rx_extraPackets = rxpackets;
1983 rx_extraQuota = 4; /* for outgoing prserver calls from R threads */
1984 rx_SetBusyThreshold(busy_threshold, VBUSY);
1985 rx_SetCallAbortThreshold(abort_threshold);
1986 rx_SetConnAbortThreshold(abort_threshold);
1988 stackSize = 128 * 1024;
1990 stackSize = lwps * 4000;
1991 if (stackSize < 32000)
1993 else if (stackSize > 44000)
1996 #if defined(AFS_HPUX_ENV) || defined(AFS_SUN_ENV) || defined(AFS_SGI51_ENV) || defined(AFS_XBSD_ENV)
1997 rx_SetStackSize(1, stackSize);
2000 rx_SetUdpBufSize(udpBufSize); /* set the UDP buffer size for receive */
2001 rx_bindhost = SetupVL();
2003 if (rx_InitHost(rx_bindhost, (int)htons(7000)) < 0) {
2004 ViceLog(0, ("Cannot initialize RX\n"));
2007 if (!rxJumbograms) {
2008 /* Don't send and don't allow 3.4 clients to send jumbograms. */
2011 if (rxMaxMTU != -1) {
2012 if (rx_SetMaxMTU(rxMaxMTU) != 0) {
2013 ViceLog(0, ("rxMaxMTU %d is invalid\n", rxMaxMTU));
2018 rx_SetRxDeadTime(30);
2019 afsconf_SetSecurityFlags(confDir, AFSCONF_SECOPTS_ALWAYSENCRYPT);
2020 afsconf_BuildServerSecurityObjects(confDir, &securityClasses, &numClasses);
2022 tservice = rx_NewServiceHost(rx_bindhost, /* port */ 0, /* service id */
2023 1, /*service name */
2025 securityClasses, numClasses,
2026 RXAFS_ExecuteRequest);
2029 ("Failed to initialize RX, probably two servers running.\n"));
2032 if (rxkadDisableDotCheck) {
2033 rx_SetSecurityConfiguration(tservice, RXS_CONFIG_FLAGS,
2034 (void *)RXS_CONFIG_FLAGS_DISABLE_DOTCHECK);
2036 rx_SetMinProcs(tservice, 3);
2037 rx_SetMaxProcs(tservice, lwps);
2038 rx_SetCheckReach(tservice, 1);
2039 rx_SetServerIdleDeadErr(tservice, VNOSERVICE);
2042 rx_NewService(0, RX_STATS_SERVICE_ID, "rpcstats", securityClasses,
2043 numClasses, RXSTATS_ExecuteRequest);
2045 ViceLog(0, ("Failed to initialize rpc stat service.\n"));
2048 rx_SetMinProcs(tservice, 2);
2049 rx_SetMaxProcs(tservice, 4);
2052 * Enable RX hot threads, which allows the listener thread to trade
2053 * places with an idle thread and moves the context switch from listener
2054 * to worker out of the critical path.
2056 rx_EnableHotThread();
2058 /* Some rx debugging */
2059 if (rxlog || eventlog) {
2060 debugFile = afs_fopen("rx_dbg", "w");
2062 rx_debugFile = debugFile;
2064 rxevent_debugFile = debugFile;
2067 init_sys_error_to_et(); /* Set up error table translation */
2068 h_InitHostPackage(); /* set up local cellname and realmname */
2069 InitCallBack(numberofcbs);
2072 code = InitVL(confDir);
2073 if (code && code != VL_MULTIPADDR) {
2074 ViceLog(0, ("Fatal error in library initialization, exiting!!\n"));
2079 if (code && code != -1) {
2080 ViceLog(0, ("Fatal error in protection initialization, exiting!!\n"));
2084 /* allow super users to manage RX statistics */
2085 rx_SetRxStatUserOk(viced_SuperUser);
2087 opr_cv_init(&fsync_cond);
2088 opr_mutex_init(&fsync_glock_mutex);
2090 #if !defined(AFS_DEMAND_ATTACH_FS)
2092 * For DAFS, we do not start the Rx server threads until after
2093 * the volume package is initialized, and fileserver state is
2094 * restored. This is necessary in order to keep host and callback
2095 * package state pristine until we have a chance to restore state.
2097 * Furthermore, startup latency is much lower with dafs, so this
2098 * shouldn't pose a serious problem.
2100 rx_StartServer(0); /* now start handling requests */
2103 /* we ensure that there is enough space in the vnode buffer to satisfy
2104 ** requests from all concurrent threads.
2105 ** the maximum number of vnodes used by a single thread at any one time
2106 ** is three ( "link" uses three vnodes simultaneously, one vLarge and
2107 ** two vSmall for linking files and two vLarge and one vSmall for linking
2110 minVnodesRequired = 2 * lwps + 1;
2111 if (minVnodesRequired > nSmallVns) {
2112 nSmallVns = minVnodesRequired;
2114 ("Overriding -s command line parameter with %d\n",
2117 if (minVnodesRequired > large) {
2118 large = minVnodesRequired;
2119 ViceLog(0, ("Overriding -l command line parameter with %d\n", large));
2122 /* We now do this after getting the listener up and running, so that client
2123 * connections don't timeout (maybe) if a file server is restarted, since it
2124 * will be available "real soon now". Worry about whether we can satisfy the
2125 * calls in the volume package itself.
2127 VOptDefaults(fileServer, &opts);
2128 opts.nLargeVnodes = large;
2129 opts.nSmallVnodes = nSmallVns;
2130 opts.volcache = volcache;
2131 opts.unsafe_attach = unsafe_attach;
2132 if (offline_timeout != -1) {
2133 opts.interrupt_rxcall = rx_InterruptCall;
2134 opts.offline_timeout = offline_timeout;
2136 if (offline_shutdown_timeout == -1) {
2137 /* default to -offline-timeout, if shutdown-specific timeout is not
2139 opts.offline_shutdown_timeout = offline_timeout;
2141 opts.interrupt_rxcall = rx_InterruptCall;
2142 opts.offline_shutdown_timeout = offline_shutdown_timeout;
2145 if (VInitVolumePackage2(fileServer, &opts)) {
2147 ("Shutting down: errors encountered initializing volume package\n"));
2152 /* Install handler to catch the shutdown signal;
2153 * bosserver assumes SIGQUIT shutdown
2155 #if !defined(AFS_NT40_ENV)
2156 softsig_signal(SIGQUIT, ShutDown_Signal);
2158 (void)signal(SIGQUIT, ShutDown_Signal);
2161 if (VInitAttachVolumes(fileServer)) {
2163 ("Shutting down: errors encountered initializing volume package\n"));
2168 #ifdef AFS_DEMAND_ATTACH_FS
2169 if (fs_state.options.fs_state_restore) {
2172 * restore fileserver state */
2175 rx_StartServer(0); /* now start handling requests */
2176 #endif /* AFS_DEMAND_ATTACH_FS */
2179 * We are done calling fopen/fdopen. It is safe to use a large
2180 * of the file descriptor cache.
2184 ViceLog(5, ("Starting pthreads\n"));
2185 opr_Verify(pthread_attr_init(&tattr) == 0);
2186 opr_Verify(pthread_attr_setdetachstate(&tattr,
2187 PTHREAD_CREATE_DETACHED) == 0);
2189 opr_Verify(pthread_create(&serverPid, &tattr, FiveMinuteCheckLWP,
2190 &fiveminutes) == 0);
2191 opr_Verify(pthread_create(&serverPid, &tattr, HostCheckLWP,
2192 &fiveminutes) == 0);
2193 opr_Verify(pthread_create(&serverPid, &tattr, FsyncCheckLWP,
2194 &fiveminutes) == 0);
2196 gettimeofday(&tp, 0);
2199 * Figure out the FileServer's name and primary address.
2201 ViceLog(0, ("Getting FileServer name...\n"));
2202 code = gethostname(FS_HostName, 64);
2204 ViceLog(0, ("gethostname() failed\n"));
2206 ViceLog(0, ("FileServer host name is '%s'\n", FS_HostName));
2208 ViceLog(0, ("Getting FileServer address...\n"));
2209 he = gethostbyname(FS_HostName);
2211 ViceLog(0, ("Can't find address for FileServer '%s'\n", FS_HostName));
2214 memcpy(&FS_HostAddr_NBO, he->h_addr, 4);
2215 (void)afs_inet_ntoa_r(FS_HostAddr_NBO, hoststr);
2216 FS_HostAddr_HBO = ntohl(FS_HostAddr_NBO);
2218 ("FileServer %s has address %s (0x%x or 0x%x in host byte order)\n",
2219 FS_HostName, hoststr, FS_HostAddr_NBO, FS_HostAddr_HBO));
2223 strftime(tbuffer, sizeof(tbuffer), "%a %b %d %H:%M:%S %Y",
2224 localtime_r(&t, &tm));
2225 ViceLog(0, ("File Server started %s\n", tbuffer));
2226 afs_FullPerfStats.det.epoch.tv_sec = StartTime = tp.tv_sec;
2228 sleep(1000); /* long time */