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>
50 #include <afs/ptclient.h>
51 #include <afs/afsint.h>
52 #include <afs/vldbint.h>
53 #include <afs/errors.h>
54 #include <afs/ihandle.h>
55 #include <afs/vnode.h>
56 #include <afs/volume.h>
58 #include <afs/cellconfig.h>
60 #include <afs/prs_fs.h>
62 #include <rx/rxstat.h>
64 #include <afs/afs_args.h>
65 #include <afs/vlserver.h>
66 #include <afs/afsutil.h>
67 #include <afs/fileutil.h>
68 #include <afs/ptuser.h>
69 #include <afs/audit.h>
70 #include <afs/partition.h>
73 # include <afs/softsig.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);
88 static void ResetCheckDescriptors(void);
89 static void ResetCheckSignal(void);
91 static afs_int32 Do_VLRegisterRPC(void);
93 int eventlog = 0, rxlog = 0;
97 pthread_mutex_t fsync_glock_mutex;
98 pthread_cond_t fsync_cond;
101 # define NT_OPEN_MAX 1024 /* This is an arbitrary no. we came up with for
102 * now. We hope this will be replaced by a more
103 * intelligent estimate later. */
106 int SystemId; /* ViceID of "Administrators" */
107 int SystemAnyUser; /* Viceid of "System:AnyUser" */
108 prlist SystemAnyUserCPS; /* CPS for "system:AnyUser */
109 int AnonymousID = 0; /* ViceId of "Anonymous" */
110 prlist AnonCPS; /* CPS for "Anonymous" */
112 struct afsconf_dir *confDir; /* Configuration dir object */
114 int restartMode = RESTART_ORDINARY;
117 * Home for the performance statistics.
119 struct afs_PerfStats afs_perfstats;
122 extern int Statistics;
127 int rxJumbograms = 0; /* default is to not send and receive jumbograms. */
128 int rxBind = 0; /* don't bind */
129 int rxkadDisableDotCheck = 0; /* disable check for dot in principal name */
131 afs_int32 implicitAdminRights = PRSFS_LOOKUP; /* The ADMINISTER right is
133 afs_int32 readonlyServer = 0;
135 int stackSize = 24000;
136 int fiveminutes = 300; /* 5 minutes. Change this for debugging only */
137 int CurrentConnections = 0;
138 int hostaclRefresh = 7200; /* refresh host clients' acls every 2 hrs */
139 #if defined(AFS_SGI_ENV)
145 * seconds to wait until forcing a panic during ShutDownAndCore(PANIC)
146 * in case we get stuck.
148 #ifdef AFS_DEMAND_ATTACH_FS
149 static int panic_timeout = 2 * 60;
151 static int panic_timeout = 30 * 60;
154 static int host_thread_quota;
155 int rxpackets = 150; /* 100 */
156 int nSmallVns = 400; /* 200 */
157 int large = 400; /* 200 */
158 int volcache = 400; /* 400 */
159 int numberofcbs = 60000; /* 60000 */
160 int lwps = 9; /* 6 */
161 int buffs = 90; /* 70 */
162 int novbc = 0; /* Enable Volume Break calls */
163 int busy_threshold = 600;
164 int abort_threshold = 10;
165 int udpBufSize = 0; /* UDP buffer size for receive */
166 int sendBufSize = 16384; /* send buffer size */
167 int saneacls = 0; /* Sane ACLs Flag */
168 static int unsafe_attach = 0; /* avoid inUse check on vol attach? */
169 static int offline_timeout = -1; /* -offline-timeout option */
170 static int offline_shutdown_timeout = -1; /* -offline-shutdown-timeout option */
174 pthread_key_t viced_uclient_key;
177 * FileServer's name and IP address, both network byte order and
180 #define ADDRSPERSITE 16 /* Same global is in rx/rx_user.c */
182 char FS_HostName[128] = "localhost";
183 char *FS_configPath = NULL;
184 afs_uint32 FS_HostAddr_NBO;
185 afs_uint32 FS_HostAddr_HBO;
186 afs_uint32 FS_HostAddrs[ADDRSPERSITE], FS_HostAddr_cnt = 0, FS_registered = 0;
187 /* All addresses in FS_HostAddrs are in NBO */
190 #ifdef AFS_DEMAND_ATTACH_FS
193 * fileserver mode support
195 * during fileserver shutdown, we have to track the graceful shutdown of
196 * certain background threads before we are allowed to dump state to
200 # if !defined(PTHREAD_RWLOCK_INITIALIZER) && defined(AFS_DARWIN80_ENV)
201 # define PTHREAD_RWLOCK_INITIALIZER {0x2DA8B3B4, {0}}
204 # ifndef AFS_NT40_ENV
205 struct fs_state fs_state =
212 PTHREAD_COND_INITIALIZER,
213 PTHREAD_RWLOCK_INITIALIZER
215 # else /* AFS_NT40_ENV */
216 struct fs_state fs_state;
218 static int fs_stateInit(void)
220 fs_state.mode = FS_MODE_NORMAL;
221 fs_state.FiveMinuteLWP_tranquil = 0;
222 fs_state.HostCheckLWP_tranquil = 0;
223 fs_state.FsyncCheckLWP_tranquil = 0;
224 fs_state.salvsync_fatal_error = 0;
226 fs_state.options.fs_state_save = 1;
227 fs_state.options.fs_state_restore = 1;
228 fs_state.options.fs_state_verify_before_save = 1;
229 fs_state.options.fs_state_verify_after_restore = 1;
231 opr_cv_init(&fs_state.worker_done_cv, "worker done");
232 opr_Verify(pthread_rwlock_init(&fs_state.state_lock, NULL) == 0);
234 # endif /* AFS_NT40_ENV */
235 #endif /* AFS_DEMAND_ATTACH_FS */
238 * Home for the performance statistics.
243 CheckDescriptors_Signal(int signo)
246 struct afs_stat status;
247 int tsize = getdtablesize();
249 for (i = 0; i < tsize; i++) {
250 if (afs_fstat(i, &status) != -1) {
251 printf("%d: dev %x, inode %u, length %u, type/mode %x\n", i,
252 (unsigned int) status.st_dev,
253 (unsigned int) status.st_ino,
254 (unsigned int) status.st_size,
259 ResetCheckDescriptors();
264 CheckSignal_Signal(int x)
266 if (FS_registered > 0) {
268 * We have proper ip addresses; tell the vlserver what we got; the following
269 * routine will do the proper reporting for us
281 ShutDown_Signal(int x)
283 ShutDownAndCore(DONTPANIC);
286 /* check whether caller is authorized to perform admin operations */
288 viced_SuperUser(struct rx_call *call)
290 return afsconf_SuperUser(confDir, call, NULL);
294 * Return true if this name is a member of the local realm.
297 fs_IsLocalRealmMatch(void *rock, char *name, char *inst, char *cell)
299 struct afsconf_dir *dir = (struct afsconf_dir *)rock;
300 afs_int32 islocal = 0; /* default to no */
303 code = afsconf_IsLocalRealmMatch(dir, &islocal, name, inst, cell);
306 ("Failed local realm check; code=%d, name=%s, inst=%s, cell=%s\n",
307 code, name, inst, cell));
313 ResetCheckSignal(void)
317 #if defined(AFS_HPUX_ENV)
319 #elif defined(AFS_NT40_ENV)
325 #if !defined(AFS_NT40_ENV)
326 softsig_signal(signo, CheckSignal_Signal);
328 signal(signo, CheckSignal_Signal);
333 ResetCheckDescriptors(void)
336 softsig_signal(SIGTERM, CheckDescriptors_Signal);
342 viced_syscall(afs_uint32 a3, afs_uint32 a4, void *a5)
345 # ifndef AFS_LINUX20_ENV
348 old = (void (*)(int))signal(SIGSYS, SIG_IGN);
350 rcode = syscall(AFS_SYSCALL, 28 /* AFSCALL_CALL */ , a3, a4, a5);
351 # ifndef AFS_LINUX20_ENV
359 #if !defined(AFS_NT40_ENV)
360 # include "AFS_component_version_number.c"
361 #endif /* !AFS_NT40_ENV */
363 #define MAXADMINNAME 64
364 char adminName[MAXADMINNAME];
370 struct afs_stat status;
372 if ((afs_stat("/AdminName", &status)) || /* if file does not exist */
373 (status.st_size <= 0) || /* or it is too short */
374 (status.st_size >= (MAXADMINNAME)) || /* or it is too long */
375 (fd = afs_open("/AdminName", O_RDONLY, 0)) < 0 || /* or open fails */
376 read(fd, adminName, status.st_size) != status.st_size) { /* or read */
378 strcpy(adminName, "System:Administrators"); /* use the default name */
381 close(fd); /* close fd if it was opened */
383 } /*CheckAdminName */
389 #if !defined(AFS_NT40_ENV)
392 /* set our 'thread-id' so that the host hold table works */
393 threadId = rx_SetThreadNum();
394 afs_pthread_setname_self(s);
395 ViceLog(0, ("Set thread id 0x%x for '%s'\n", threadId, s));
399 /* This LWP does things roughly every 5 minutes */
401 FiveMinuteCheckLWP(void *unused)
406 ViceLog(1, ("Starting five minute check process\n"));
407 setThreadId("FiveMinuteCheckLWP");
409 #ifdef AFS_DEMAND_ATTACH_FS
411 while (fs_state.mode == FS_MODE_NORMAL) {
412 fs_state.FiveMinuteLWP_tranquil = 1;
420 #ifdef AFS_DEMAND_ATTACH_FS
422 if (fs_state.mode != FS_MODE_NORMAL) {
425 fs_state.FiveMinuteLWP_tranquil = 0;
429 /* close the log so it can be removed */
430 ReOpenLog(AFSDIR_SERVER_FILELOG_FILEPATH); /* don't trunc, just append */
431 ViceLog(2, ("Cleaning up timed out callbacks\n"));
432 if (CleanupTimedOutCallBacks())
433 ViceLog(5, ("Timed out callbacks deleted\n"));
434 ViceLog(2, ("Set disk usage statistics\n"));
436 if (FS_registered == 1)
438 /* Force wakeup in case we missed something; pthreads does timedwait */
439 if (printBanner && (++msg & 1)) { /* Every 10 minutes */
440 time_t now = time(NULL);
442 strftime(tbuffer, sizeof(tbuffer), "%a %b %d %H:%M:%S %Y",
443 localtime_r(&now, &tm));
445 ("File server is running at %s\n", tbuffer));
447 #ifdef AFS_DEMAND_ATTACH_FS
451 #ifdef AFS_DEMAND_ATTACH_FS
452 fs_state.FiveMinuteLWP_tranquil = 1;
454 opr_cv_broadcast(&fs_state.worker_done_cv);
459 } /*FiveMinuteCheckLWP */
462 /* This LWP does host checks every 5 minutes: it should not be used for
463 * other 5 minute activities because it may be delayed by timeouts when
464 * it probes the workstations
468 HostCheckLWP(void *unused)
470 ViceLog(1, ("Starting Host check process\n"));
471 setThreadId("HostCheckLWP");
472 #ifdef AFS_DEMAND_ATTACH_FS
474 while (fs_state.mode == FS_MODE_NORMAL) {
475 fs_state.HostCheckLWP_tranquil = 1;
483 #ifdef AFS_DEMAND_ATTACH_FS
485 if (fs_state.mode != FS_MODE_NORMAL) {
488 fs_state.HostCheckLWP_tranquil = 0;
492 ViceLog(2, ("Checking for dead venii & clients\n"));
495 #ifdef AFS_DEMAND_ATTACH_FS
499 #ifdef AFS_DEMAND_ATTACH_FS
500 fs_state.HostCheckLWP_tranquil = 1;
502 opr_cv_broadcast(&fs_state.worker_done_cv);
509 /* This LWP does fsync checks every 5 minutes: it should not be used for
510 * other 5 minute activities because it may be delayed by timeouts when
511 * it probes the workstations
514 FsyncCheckLWP(void *unused)
517 struct timespec fsync_next;
518 ViceLog(1, ("Starting fsync check process\n"));
520 setThreadId("FsyncCheckLWP");
522 #ifdef AFS_DEMAND_ATTACH_FS
524 while (fs_state.mode == FS_MODE_NORMAL) {
525 fs_state.FsyncCheckLWP_tranquil = 1;
531 /* rounding is fine */
532 fsync_next.tv_nsec = 0;
533 fsync_next.tv_sec = time(0) + fiveminutes;
535 code = opr_cv_timedwait(&fsync_cond, &fsync_glock_mutex,
537 if (code != 0 && code != ETIMEDOUT)
538 ViceLog(0, ("pthread_cond_timedwait returned %d\n", code));
541 #ifdef AFS_DEMAND_ATTACH_FS
543 if (fs_state.mode != FS_MODE_NORMAL) {
546 fs_state.FsyncCheckLWP_tranquil = 0;
548 #endif /* AFS_DEMAND_ATTACH_FS */
550 ViceLog(2, ("Checking for fsync events\n"));
552 code = BreakLaterCallBacks();
554 #ifdef AFS_DEMAND_ATTACH_FS
558 #ifdef AFS_DEMAND_ATTACH_FS
559 fs_state.FsyncCheckLWP_tranquil = 1;
561 opr_cv_broadcast(&fs_state.worker_done_cv);
564 #endif /* AFS_DEMAND_ATTACH_FS */
568 /*------------------------------------------------------------------------
569 * PRIVATE ClearXStatValues
572 * Initialize all of the values collected via the xstat
582 * Must be called during File Server initialization.
586 *------------------------------------------------------------------------*/
589 ClearXStatValues(void)
590 { /*ClearXStatValues */
592 struct fs_stats_opTimingData *opTimeP; /*Ptr to timing struct */
593 struct fs_stats_xferData *opXferP; /*Ptr to xfer struct */
594 int i; /*Loop counter */
597 * Zero all xstat-related structures.
599 memset((&afs_perfstats), 0, sizeof(struct afs_PerfStats));
600 memset((&afs_FullPerfStats), 0,
601 sizeof(struct fs_stats_FullPerfStats));
604 * That's not enough. We have to set reasonable minima for
605 * time and xfer values in the detailed stats.
607 opTimeP = &(afs_FullPerfStats.det.rpcOpTimes[0]);
608 for (i = 0; i < FS_STATS_NUM_RPC_OPS; i++, opTimeP++)
609 opTimeP->minTime.tv_sec = 999999;
611 opXferP = &(afs_FullPerfStats.det.xferOpTimes[0]);
612 for (i = 0; i < FS_STATS_NUM_XFER_OPS; i++, opXferP++) {
613 opXferP->minTime.tv_sec = 999999;
614 opXferP->minBytes = 999999999;
618 * There's more. We have to set our unique system identifier, as
619 * declared in param.h. If such a thing is not defined, we bitch
620 * and declare ourselves to be an unknown system type.
623 afs_perfstats.sysname_ID = SYS_NAME_ID;
625 # ifndef AFS_NT40_ENV
626 ViceLog(0, ("Sys name ID constant not defined in param.h!!\n"));
627 ViceLog(0, ("[Choosing ``undefined'' sys name ID.\n"));
629 afs_perfstats.sysname_ID = SYS_NAME_ID_UNDEFINED;
630 # endif /* SYS_NAME_ID */
632 } /*ClearXStatValues */
634 int CopyOnWrite_calls = 0, CopyOnWrite_off0 = 0, CopyOnWrite_size0 = 0;
635 afs_fsize_t CopyOnWrite_maxsize = 0;
640 int dirbuff, dircall, dirio;
642 int workstations, activeworkstations, delworkstations;
646 #ifdef AFS_DEMAND_ATTACH_FS
650 gettimeofday(&tpl, 0);
652 strftime(tbuffer, sizeof(tbuffer), "%a %b %d %H:%M:%S %Y",
653 localtime_r(&StartTime, &tm));
654 ViceLog(0, ("Vice was last started at %s\n", tbuffer));
656 #ifdef AFS_DEMAND_ATTACH_FS
657 if (LogLevel >= 125) {
658 stats_flags = VOL_STATS_PER_CHAIN2;
659 } else if (LogLevel >= 25) {
660 stats_flags = VOL_STATS_PER_CHAIN;
662 VPrintExtendedCacheStats(stats_flags);
666 DStat(&dirbuff, &dircall, &dirio);
668 ("With %d directory buffers; %d reads resulted in %d read I/Os\n",
669 dirbuff, dircall, dirio));
670 rx_PrintStats(stderr);
671 audit_PrintStats(stderr);
673 PrintCallBackStats();
674 processSize = opr_procsize();
676 ("There are %d connections, process size %d\n",
677 CurrentConnections, processSize));
678 h_GetWorkStats(&workstations, &activeworkstations, &delworkstations,
679 tpl.tv_sec - 15 * 60);
681 ("There are %d workstations, %d are active (req in < 15 mins), %d marked \"down\"\n",
682 workstations, activeworkstations, delworkstations));
683 ViceLog(0, ("CopyOnWrite: calls %d off0 %d size0 %d maxsize 0x%llx\n",
684 CopyOnWrite_calls, CopyOnWrite_off0, CopyOnWrite_size0, CopyOnWrite_maxsize));
691 ShutdownWatchdogLWP(void *unused)
693 afs_pthread_setname_self("ShutdownWatchdog");
694 sleep(panic_timeout);
695 ViceLogThenPanic(0, ("ShutdownWatchdogLWP: Failed to shutdown and panic "
696 "within %d seconds; forcing panic\n",
702 ShutDownAndCore(int dopanic)
704 time_t now = time(NULL);
709 pthread_t watchdogPid;
710 pthread_attr_t tattr;
711 opr_Verify(pthread_attr_init(&tattr) == 0);
712 opr_Verify(pthread_create(&watchdogPid, &tattr,
713 ShutdownWatchdogLWP, NULL) == 0);
716 /* do not allows new reqests to be served from now on, all new requests
717 * are returned with an error code of RX_RESTARTING ( transient failure ) */
718 rx_SetRxTranquil(); /* dhruba */
722 #ifdef AFS_DEMAND_ATTACH_FS
724 if (fs_state.mode == FS_MODE_SHUTDOWN) {
725 /* it is possible for at least fs_stateSave() (called below) to call
726 * ShutDownAndCore if there's host list corruption; prevent
727 * deinitializing some stuff twice */
728 ViceLog(0, ("ShutDownAndCore called during shutdown? Skipping volume "
729 "and host package shutdown\n"));
733 fs_state.mode = FS_MODE_SHUTDOWN;
737 strftime(tbuffer, sizeof(tbuffer), "%a %b %d %H:%M:%S %Y",
738 localtime_r(&now, &tm));
739 ViceLog(0, ("Shutting down file server at %s\n", tbuffer));
741 ViceLog(0, ("ABNORMAL SHUTDOWN, see core file.\n"));
746 /* shut down volume package */
749 #ifdef AFS_DEMAND_ATTACH_FS
750 if (fs_state.options.fs_state_save) {
753 * save fileserver state to disk */
756 ViceLog(0, ("Not saving fileserver state; abnormal shutdown\n"));
759 /* make sure background threads have finished all of their asynchronous
760 * work on host and callback structures */
762 while (!fs_state.FiveMinuteLWP_tranquil ||
763 !fs_state.HostCheckLWP_tranquil ||
764 !fs_state.FsyncCheckLWP_tranquil) {
767 ViceLog(0, ("waiting for background host/callback threads to quiesce before saving fileserver state...\n"));
768 opr_cv_wait(&fs_state.worker_done_cv, &fileproc_glock_mutex);
774 /* ok. it should now be fairly safe. let's do the state dump */
780 #endif /* AFS_DEMAND_ATTACH_FS */
783 rx_PrintStats(debugFile);
787 strftime(tbuffer, sizeof(tbuffer), "%a %b %d %H:%M:%S %Y",
788 localtime_r(&now, &tm));
790 ViceLog(0, ("File server has terminated abnormally at %s\n", tbuffer));
792 ViceLog(0, ("File server has terminated normally at %s\n", tbuffer));
795 if (dopanic) /* XXX pass in file and line? */
796 osi_Panic("Panic requested\n");
802 ParseRights(char *arights)
808 if (!arights || !strcmp(arights, "")) {
809 printf("Missing list of mode bits on -implicit option\n");
812 if (!strcmp(arights, "none"))
814 else if (!strcmp(arights, "read"))
815 mode = PRSFS_READ | PRSFS_LOOKUP;
816 else if (!strcmp(arights, "write"))
818 PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
819 PRSFS_WRITE | PRSFS_LOCK;
820 else if (!strcmp(arights, "all"))
822 PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
823 PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER;
825 len = strlen(arights);
826 for (i = 0; i < len; i++) {
831 mode |= PRSFS_LOOKUP;
833 mode |= PRSFS_INSERT;
835 mode |= PRSFS_DELETE;
841 mode |= PRSFS_ADMINISTER;
859 printf("Illegal -implicit rights character '%c'.\n", tc);
868 * Limit MAX_FILESERVER_THREAD by the system limit on the number of
869 * pthreads (sysconf(_SC_THREAD_THREADS_MAX)), if applicable and
872 * AIX: sysconf() limit is real
873 * HP-UX: sysconf() limit is real
874 * IRIX: sysconf() limit is apparently NOT real -- too small
875 * DUX: sysconf() limit is apparently NOT real -- too big
876 * Linux: sysconf() limit is apparently NOT real -- too big
877 * Solaris: no sysconf() limit
880 max_fileserver_thread(void)
882 #if defined(AFS_AIX_ENV) || defined(AFS_HPUX_ENV)
885 ans = sysconf(_SC_THREAD_THREADS_MAX);
886 if (0 < ans && ans < MAX_FILESERVER_THREAD)
889 return MAX_FILESERVER_THREAD;
893 extern ih_init_params vol_io_params;
918 OPT_offline_shutdown_timeout,
919 OPT_vhandle_setaside,
920 OPT_vhandle_max_cachesize,
921 OPT_vhandle_initial_cachesize,
922 OPT_fs_state_dont_save,
923 OPT_fs_state_dont_restore,
930 OPT_unsafe_nosalvage,
957 ParseArgs(int argc, char *argv[])
961 char *optstring = NULL;
962 struct cmd_item *optlist;
963 struct cmd_syndesc *opts;
966 char *auditFileName = NULL;
967 char *sync_behavior = NULL;
969 #if defined(AFS_AIX32_ENV)
970 extern int aixlow_water;
973 opts = cmd_CreateSyntax(NULL, NULL, NULL, 0, NULL);
975 /* fileserver options */
976 cmd_AddParmAtOffset(opts, OPT_large, "-L", CMD_FLAG,
977 CMD_OPTIONAL, "defaults for a 'large' server");
978 cmd_AddParmAtOffset(opts, OPT_small, "-S", CMD_FLAG,
979 CMD_OPTIONAL, "defaults for a 'small' server");
981 cmd_AddParmAtOffset(opts, OPT_banner, "-banner", CMD_FLAG,
982 CMD_OPTIONAL, "print regular banners to log");
983 cmd_AddParmAtOffset(opts, OPT_implicit, "-implicit", CMD_SINGLE,
984 CMD_OPTIONAL, "implicit admin access bits");
986 #if defined(AFS_SGI_ENV)
987 cmd_AddParmAtOffset(opts, OPT_lock, "-lock", CMD_FLAG,
988 CMD_OPTIONAL, "lock filserver binary in memory");
990 cmd_AddParmAtOffset(opts, OPT_readonly, "-readonly", CMD_FLAG,
991 CMD_OPTIONAL, "be a readonly fileserver");
992 cmd_AddParmAtOffset(opts, OPT_saneacls, "-saneacls", CMD_FLAG,
993 CMD_OPTIONAL, "set the saneacls capability bit");
995 cmd_AddParmAtOffset(opts, OPT_buffers, "-b", CMD_SINGLE,
996 CMD_OPTIONAL, "buffers");
997 cmd_AddParmAtOffset(opts, OPT_callbacks, "-cb", CMD_SINGLE,
998 CMD_OPTIONAL, "number of callbacks");
999 cmd_AddParmAtOffset(opts, OPT_vcsize, "-vc", CMD_SINGLE,
1000 CMD_OPTIONAL, "volume cachesize");
1001 cmd_AddParmAtOffset(opts, OPT_lvnodes, "-l", CMD_SINGLE,
1002 CMD_OPTIONAL, "large vnodes");
1003 cmd_AddParmAtOffset(opts, OPT_svnodes, "-s", CMD_SINGLE,
1004 CMD_OPTIONAL, "small vnodes");
1005 cmd_AddParmAtOffset(opts, OPT_sendsize, "-sendsize", CMD_SINGLE,
1006 CMD_OPTIONAL, "size of send buffer in bytes");
1008 #if defined(AFS_AIX32_ENV)
1009 cmd_AddParmAtOffset(opts, OPT_minspare, "-m", CMD_SINGLE,
1010 CMD_OPTIONAL, "minimum percentage spare in partition");
1013 cmd_AddParmAtOffset(opts, OPT_spare, "-spare", CMD_SINGLE,
1014 CMD_OPTIONAL, "kB overage on volume quota");
1015 cmd_AddParmAtOffset(opts, OPT_pctspare, "-pctspare", CMD_SINGLE,
1016 CMD_OPTIONAL, "percentage overage on volume quota");
1018 cmd_AddParmAtOffset(opts, OPT_hostcpsrefresh, "-hr", CMD_SINGLE,
1019 CMD_OPTIONAL, "hours between host CPS refreshes");
1021 cmd_AddParmAtOffset(opts, OPT_vattachthreads, "-vattachpar", CMD_SINGLE,
1022 CMD_OPTIONAL, "# of volume attachment threads");
1024 cmd_AddParmAtOffset(opts, OPT_abortthreshold, "-abortthreshold",
1025 CMD_SINGLE, CMD_OPTIONAL,
1027 cmd_AddParmAtOffset(opts, OPT_busyat, "-busyat", CMD_SINGLE, CMD_OPTIONAL,
1028 "# of queued entries after which server is busy");
1029 cmd_AddParmAtOffset(opts, OPT_nobusy, "-nobusy", CMD_FLAG, CMD_OPTIONAL,
1030 "send VRESTARTING while restarting the server");
1032 cmd_AddParmAtOffset(opts, OPT_offline_timeout, "-offline-timeout",
1033 CMD_SINGLE, CMD_OPTIONAL,
1034 "timeout for offlining volumes");
1035 cmd_AddParmAtOffset(opts, OPT_offline_shutdown_timeout,
1036 "-offline-shutdown-timeout", CMD_SINGLE, CMD_OPTIONAL,
1037 "timeout offlining volumes during shutdown");
1039 cmd_AddParmAtOffset(opts, OPT_vhandle_setaside, "-vhandle-setaside",
1040 CMD_SINGLE, CMD_OPTIONAL,
1041 "# fds reserved for non-cache IO");
1042 cmd_AddParmAtOffset(opts, OPT_vhandle_max_cachesize,
1043 "-vhandle-max-cachesize", CMD_SINGLE, CMD_OPTIONAL,
1045 cmd_AddParmAtOffset(opts, OPT_vhandle_initial_cachesize,
1046 "-vhandle-initial-cachesize", CMD_SINGLE,
1047 CMD_OPTIONAL, "# fds reserved for cache IO");
1049 #ifdef AFS_DEMAND_ATTACH_FS
1051 cmd_AddParmAtOffset(opts, OPT_fs_state_dont_save,
1052 "-fs-state-dont-save", CMD_FLAG, CMD_OPTIONAL,
1053 "disable state save during shutdown");
1054 cmd_AddParmAtOffset(opts, OPT_fs_state_dont_restore,
1055 "-fs-state-dont-restore", CMD_FLAG, CMD_OPTIONAL,
1056 "disable state restore during startup");
1057 cmd_AddParmAtOffset(opts, OPT_fs_state_verify, "-fs-state-verify",
1058 CMD_SINGLE, CMD_OPTIONAL, "none|save|restore|both");
1059 cmd_AddParmAtOffset(opts, OPT_vhashsize, "-vhashsize",
1060 CMD_SINGLE, CMD_OPTIONAL,
1061 "log(2) of # of volume hash buckets");
1062 cmd_AddParmAtOffset(opts, OPT_vlrudisable, "-vlrudisable",
1063 CMD_FLAG, CMD_OPTIONAL, "disable VLRU functionality");
1064 cmd_AddParmAtOffset(opts, OPT_vlruthresh, "-vlruthresh",
1065 CMD_FLAG, CMD_OPTIONAL,
1066 "mins before unused vols become eligible for detach");
1067 cmd_AddParmAtOffset(opts, OPT_vlruinterval, "-vlruinterval",
1068 CMD_FLAG, CMD_OPTIONAL, "secs between VLRU scans");
1069 cmd_AddParmAtOffset(opts, OPT_vlrumax, "-vlrumax", CMD_FLAG, CMD_OPTIONAL,
1070 "max volumes to detach in one scan");
1071 cmd_AddParmAtOffset(opts, OPT_unsafe_nosalvage, "-unsafe-nosalvage",
1072 CMD_FLAG, CMD_OPTIONAL,
1073 "bybass safety checks on volume attach");
1076 /* unrecommend options - should perhaps be CMD_HIDE */
1077 cmd_AddParmAtOffset(opts, OPT_cbwait, "-w", CMD_SINGLE, CMD_OPTIONAL,
1078 "callback wait interval");
1079 cmd_AddParmAtOffset(opts, OPT_novbc, "-novbc", CMD_SINGLE, CMD_FLAG,
1080 "disable callback breaks on reattach");
1082 /* general options */
1083 cmd_AddParmAtOffset(opts, OPT_auditlog, "-auditlog", CMD_SINGLE,
1084 CMD_OPTIONAL, "location of audit log");
1085 cmd_AddParmAtOffset(opts, OPT_auditiface, "-audit-interface", CMD_SINGLE,
1086 CMD_OPTIONAL, "interface to use for audit logging");
1087 cmd_AddParmAtOffset(opts, OPT_debug, "-d", CMD_SINGLE, CMD_OPTIONAL,
1089 cmd_AddParmAtOffset(opts, OPT_mrafslogs, "-mrafslogs", CMD_FLAG,
1090 CMD_OPTIONAL, "enable MRAFS style logging");
1091 cmd_AddParmAtOffset(opts, OPT_threads, "-p", CMD_SINGLE, CMD_OPTIONAL,
1092 "number of threads");
1093 #if !defined(AFS_NT40_ENV)
1094 cmd_AddParmAtOffset(opts, OPT_syslog, "-syslog", CMD_SINGLE_OR_FLAG,
1095 CMD_OPTIONAL, "log to syslog");
1099 cmd_AddParmAtOffset(opts, OPT_peer, "-enable_peer_stats", CMD_FLAG,
1100 CMD_OPTIONAL, "enable RX transport statistics");
1101 cmd_AddParmAtOffset(opts, OPT_process, "-enable_process_stats", CMD_FLAG,
1102 CMD_OPTIONAL, "enable RX RPC statistics");
1103 cmd_AddParmAtOffset(opts, OPT_nojumbo, "-nojumbo", CMD_FLAG,
1104 CMD_OPTIONAL, "disable jumbograms");
1105 cmd_AddParmAtOffset(opts, OPT_jumbo, "-jumbo", CMD_FLAG, CMD_OPTIONAL,
1106 "enable jumbograms");
1107 cmd_AddParmAtOffset(opts, OPT_rxbind, "-rxbind", CMD_FLAG, CMD_OPTIONAL,
1108 "bind only to the primary interface");
1109 cmd_AddParmAtOffset(opts, OPT_rxdbg, "-rxdbg", CMD_FLAG, CMD_OPTIONAL,
1110 "enable rx debugging");
1111 cmd_AddParmAtOffset(opts, OPT_rxdbge, "-rxdbge", CMD_FLAG, CMD_OPTIONAL,
1112 "enable rx event debugging");
1113 cmd_AddParmAtOffset(opts, OPT_rxpck, "-rxpck", CMD_SINGLE, CMD_OPTIONAL,
1114 "# of extra rx packets");
1115 cmd_AddParmAtOffset(opts, OPT_rxmaxmtu, "-rxmaxmtu", CMD_SINGLE,
1116 CMD_OPTIONAL, "maximum MTU for RX");
1117 cmd_AddParmAtOffset(opts, OPT_udpsize, "-udpsize", CMD_SINGLE,
1118 CMD_OPTIONAL, "size of socket buffer in bytes");
1121 cmd_AddParmAtOffset(opts, OPT_dotted, "-allow-dotted-principals",
1122 CMD_FLAG, CMD_OPTIONAL,
1123 "permit Kerberos 5 principals with dots");
1124 cmd_AddParmAtOffset(opts, OPT_realm, "-realm",
1125 CMD_LIST, CMD_OPTIONAL, "local realm");
1126 cmd_AddParmAtOffset(opts, OPT_sync, "-sync",
1127 CMD_SINGLE, CMD_OPTIONAL, "always | onclose | never");
1129 /* testing options */
1130 cmd_AddParmAtOffset(opts, OPT_logfile, "-logfile", CMD_SINGLE,
1131 CMD_OPTIONAL, "location of log file");
1132 cmd_AddParmAtOffset(opts, OPT_config, "-config", CMD_SINGLE,
1133 CMD_OPTIONAL, "configuration location");
1135 code = cmd_Parse(argc, argv, &opts);
1136 if (code == CMD_HELP) {
1142 cmd_OpenConfigFile(AFSDIR_SERVER_CONFIG_FILE_FILEPATH);
1143 cmd_SetCommandName("fileserver");
1145 if (cmd_OptionPresent(opts, OPT_large)
1146 && cmd_OptionPresent(opts, OPT_small)) {
1147 printf("Only one of -L or -S must be specified\n");
1151 if (cmd_OptionPresent(opts, OPT_spare)
1152 && cmd_OptionPresent(opts, OPT_pctspare)) {
1153 printf("Both -spare and -pctspare specified, exiting.\n");
1157 if (cmd_OptionPresent(opts, OPT_large)) {
1161 numberofcbs = 64000;
1167 if (cmd_OptionPresent(opts, OPT_small)) {
1171 numberofcbs = 20000;
1177 cmd_OptionAsFlag(opts, OPT_banner, &printBanner);
1179 if (cmd_OptionAsString(opts, OPT_implicit, &optstring) == 0) {
1180 implicitAdminRights = ParseRights(optstring);
1183 if (implicitAdminRights < 0)
1184 return implicitAdminRights;
1187 #if defined(AFS_SGI_ENV)
1188 cmd_OptionAsFlag(opts, OPT_lock, &SawLock);
1190 cmd_OptionAsFlag(opts, OPT_readonly, &readonlyServer);
1191 cmd_OptionAsFlag(opts, OPT_saneacls, &saneacls);
1192 cmd_OptionAsInt(opts, OPT_buffers, &buffs);
1194 if (cmd_OptionAsInt(opts, OPT_callbacks, &numberofcbs) == 0) {
1195 if ((numberofcbs < 10000) || (numberofcbs > 2147483647)) {
1196 printf("number of cbs %d invalid; "
1197 "must be between 10000 and 2147483647\n", numberofcbs);
1202 cmd_OptionAsInt(opts, OPT_vcsize, &volcache);
1203 cmd_OptionAsInt(opts, OPT_lvnodes, &large);
1204 cmd_OptionAsInt(opts, OPT_svnodes, &nSmallVns);
1205 if (cmd_OptionAsInt(opts, OPT_sendsize, &optval) == 0) {
1206 if (optval < 16384) {
1207 printf("Warning:sendsize %d is less than minimum %d; ignoring\n",
1210 sendBufSize = optval;
1213 #if defined(AFS_AIX32_ENV)
1214 if (cmd_OptionAsInt(opts, OPT_minspare, &aixlow_water) == 0) {
1215 if ((aixlow_water < 0) || (aixlow_water > 30)) {
1216 printf("space reserved %d%% invalid; must be between 0-30%\n",
1223 cmd_OptionAsInt(opts, OPT_spare, &BlocksSpare);
1224 if (cmd_OptionAsInt(opts, OPT_pctspare, &PctSpare) == 0) {
1228 if (cmd_OptionAsInt(opts, OPT_hostcpsrefresh, &optval) == 0) {
1229 if ((optval < 1) || (optval > 36)) {
1230 printf("host acl refresh interval of %d hours is invalid; "
1231 "hours must be between 1 and 36\n\n", optval);
1234 hostaclRefresh = optval * 60 * 60;
1237 cmd_OptionAsInt(opts, OPT_vattachthreads, &vol_attach_threads);
1239 cmd_OptionAsInt(opts, OPT_abortthreshold, &abort_threshold);
1241 /* busyat is at the end, as rxpackets has to be set before we can use it */
1242 if (cmd_OptionPresent(opts, OPT_nobusy))
1245 if (cmd_OptionAsInt(opts, OPT_offline_timeout, &offline_timeout) == 0) {
1246 if (offline_timeout < -1) {
1247 printf("Invalid -offline-timeout value %d; the only valid "
1248 "negative value is -1\n", offline_timeout);
1253 if (cmd_OptionAsInt(opts, OPT_offline_shutdown_timeout,
1254 &offline_shutdown_timeout) == 0) {
1255 if (offline_shutdown_timeout < -1) {
1256 printf("Invalid -offline-timeout value %d; the only valid "
1257 "negative value is -1\n", offline_shutdown_timeout);
1262 cmd_OptionAsUint(opts, OPT_vhandle_setaside,
1263 &vol_io_params.fd_handle_setaside);
1264 cmd_OptionAsUint(opts, OPT_vhandle_max_cachesize,
1265 &vol_io_params.fd_max_cachesize);
1266 cmd_OptionAsUint(opts, OPT_vhandle_initial_cachesize,
1267 &vol_io_params.fd_initial_cachesize);
1268 if (cmd_OptionAsString(opts, OPT_sync, &sync_behavior) == 0) {
1269 if (ih_SetSyncBehavior(sync_behavior)) {
1270 printf("Invalid -sync value %s\n", sync_behavior);
1275 #ifdef AFS_DEMAND_ATTACH_FS
1276 if (cmd_OptionPresent(opts, OPT_fs_state_dont_save))
1277 fs_state.options.fs_state_save = 0;
1278 if (cmd_OptionPresent(opts, OPT_fs_state_dont_restore))
1279 fs_state.options.fs_state_restore = 0;
1280 if (cmd_OptionAsString(opts, OPT_fs_state_verify, &optstring) == 0) {
1281 if (strcmp(optstring, "none") == 0) {
1282 fs_state.options.fs_state_verify_before_save = 0;
1283 fs_state.options.fs_state_verify_after_restore = 0;
1284 } else if (strcmp(optstring, "save") == 0) {
1285 fs_state.options.fs_state_verify_after_restore = 0;
1286 } else if (strcmp(optstring, "restore") == 0) {
1287 fs_state.options.fs_state_verify_before_save = 0;
1288 } else if (strcmp(optstring, "both") == 0) {
1291 fprintf(stderr, "invalid argument for -fs-state-verify\n");
1295 if (cmd_OptionAsInt(opts, OPT_vhashsize, &optval) == 0) {
1296 if (VSetVolHashSize(optval)) {
1297 fprintf(stderr, "specified -vhashsize (%d) is invalid or out "
1298 "of range\n", optval);
1302 if (cmd_OptionPresent(opts, OPT_vlrudisable))
1303 VLRU_SetOptions(VLRU_SET_ENABLED, 0);
1304 if (cmd_OptionAsInt(opts, OPT_vlruthresh, &optval) == 0)
1305 VLRU_SetOptions(VLRU_SET_THRESH, 60*optval);
1306 if (cmd_OptionAsInt(opts, OPT_vlruinterval, &optval) == 0)
1307 VLRU_SetOptions(VLRU_SET_INTERVAL, optval);
1308 if (cmd_OptionAsInt(opts, OPT_vlrumax, &optval) == 0)
1309 VLRU_SetOptions(VLRU_SET_MAX, optval);
1310 cmd_OptionAsFlag(opts, OPT_unsafe_nosalvage, &unsafe_attach);
1311 #endif /* AFS_DEMAND_ATTACH_FS */
1313 cmd_OptionAsInt(opts, OPT_cbwait, &fiveminutes);
1314 cmd_OptionAsFlag(opts, OPT_novbc, &novbc);
1316 /* general server options */
1317 cmd_OptionAsString(opts, OPT_auditlog, &auditFileName);
1319 if (cmd_OptionAsString(opts, OPT_auditiface, &optstring) == 0) {
1320 if (osi_audit_interface(optstring)) {
1321 printf("Invalid audit interface '%s'\n", optstring);
1328 cmd_OptionAsInt(opts, OPT_debug, &LogLevel);
1329 cmd_OptionAsFlag(opts, OPT_mrafslogs, &mrafsStyleLogs);
1331 if (cmd_OptionAsInt(opts, OPT_threads, &lwps) == 0) {
1332 lwps_max = max_fileserver_thread() - FILESERVER_HELPER_THREADS;
1333 if (lwps > lwps_max)
1339 #ifndef AFS_NT40_ENV
1340 if (cmd_OptionPresent(opts, OPT_syslog)) {
1341 serverLogSyslog = 1;
1342 cmd_OptionAsInt(opts, OPT_syslog, &serverLogSyslogFacility);
1346 if (cmd_OptionPresent(opts, OPT_peer))
1347 rx_enablePeerRPCStats();
1348 if (cmd_OptionPresent(opts, OPT_process))
1349 rx_enableProcessRPCStats();
1350 if (cmd_OptionPresent(opts, OPT_nojumbo))
1352 if (cmd_OptionPresent(opts, OPT_jumbo))
1354 cmd_OptionAsFlag(opts, OPT_rxbind, &rxBind);
1355 cmd_OptionAsFlag(opts, OPT_rxdbg, &rxlog);
1356 cmd_OptionAsFlag(opts, OPT_rxdbge, &eventlog);
1357 cmd_OptionAsInt(opts, OPT_rxpck, &rxpackets);
1359 cmd_OptionAsInt(opts, OPT_rxmaxmtu, &rxMaxMTU);
1361 if (cmd_OptionAsInt(opts, OPT_udpsize, &optval) == 0) {
1362 if (optval < rx_GetMinUdpBufSize()) {
1363 printf("Warning:udpsize %d is less than minimum %d; ignoring\n",
1364 optval, rx_GetMinUdpBufSize());
1366 udpBufSize = optval;
1370 cmd_OptionAsFlag(opts, OPT_dotted, &rxkadDisableDotCheck);
1371 if (cmd_OptionAsList(opts, OPT_realm, &optlist) == 0) {
1373 for (; optlist != NULL; optlist=optlist->next) {
1374 if (strlen(optlist->data) >= AFS_REALM_SZ) {
1375 printf("-realm argument must contain fewer than %d "
1376 "characters.\n", AFS_REALM_SZ);
1379 afsconf_SetLocalRealm(optlist->data); /* overrides krb.conf file, if one */
1383 /* anything setting rxpackets must come before this */
1384 if (cmd_OptionAsInt(opts, OPT_busyat, &optval) == 0) {
1386 printf("Busy threshold %d is too low, will use default.\n",
1388 busy_threshold = 3 * rxpackets / 2;
1390 busy_threshold = optval;
1393 busy_threshold = 3 * rxpackets / 2;
1396 cmd_OptionAsString(opts, OPT_logfile, &logFile);
1397 cmd_OptionAsString(opts, OPT_config, &FS_configPath);
1401 osi_audit_file(auditFileName);
1404 host_thread_quota = 5;
1405 } else if (lwps > 32) {
1406 host_thread_quota = 4;
1407 } else if (lwps > 16) {
1408 host_thread_quota = 3;
1410 host_thread_quota = 2;
1416 /* Once upon a time, in a galaxy far far away, IBM AFS supported the use of
1417 * a file /vice/file/parms, the contents of which would override any command
1418 * line parameters. We no longer support the use of such a file, but we warn
1419 * if we encounter its presence from an older release
1424 struct afs_stat sbuf;
1426 if (afs_stat("/vice/file/parms", &sbuf) == 0) {
1427 ViceLog(0, ("Using /vice/file/parms to override command line "
1428 "options is no longer supported"));
1432 /* Miscellaneous routines */
1434 Die(const char *msg)
1437 ViceLogThenPanic(0, ("%s\n", msg));
1447 * If this fails, it's because something major is wrong, and is not
1448 * likely to be time dependent.
1450 code = pr_Initialize(2, AFSDIR_SERVER_ETC_DIRPATH, 0);
1453 ("Couldn't initialize protection library; code=%d.\n", code));
1457 opr_Verify(pthread_key_create(&viced_uclient_key, NULL) == 0);
1459 SystemId = SYSADMINID;
1460 SystemAnyUser = ANYUSERID;
1461 SystemAnyUserCPS.prlist_len = 0;
1462 SystemAnyUserCPS.prlist_val = NULL;
1463 AnonCPS.prlist_len = 0;
1464 AnonCPS.prlist_val = NULL;
1466 code = pr_GetCPS(SystemAnyUser, &SystemAnyUserCPS);
1469 ("Couldn't get CPS for AnyUser, will try again in 30 seconds; code=%d.\n",
1473 code = pr_GetCPS(ANONYMOUSID, &AnonCPS);
1476 ("Couldn't get Anonymous CPS, exiting; code=%d.\n",
1480 AnonymousID = ANONYMOUSID;
1487 static struct ubik_client *cstruct;
1490 vl_Initialize(struct afsconf_dir *dir)
1493 afs_int32 scIndex = RX_SECIDX_NULL;
1494 struct afsconf_cell info;
1495 struct rx_securityClass *sc;
1496 struct rx_connection *serverconns[MAXSERVERS];
1498 memset(serverconns, 0, sizeof(serverconns));
1499 code = afsconf_ClientAuth(dir, &sc, &scIndex);
1501 ViceLog(0, ("Could not get security object for localAuth\n"));
1504 code = afsconf_GetCellInfo(dir, NULL, AFSCONF_VLDBSERVICE, &info);
1507 ("vl_Initialize: Failed to get cell information\n"));
1510 if (info.numServers > MAXSERVERS) {
1512 ("vl_Initialize: info.numServers=%d (> MAXSERVERS=%d)\n",
1513 info.numServers, MAXSERVERS));
1516 for (i = 0; i < info.numServers; i++)
1518 rx_NewConnection(info.hostAddr[i].sin_addr.s_addr,
1519 info.hostAddr[i].sin_port, USER_SERVICE_ID, sc,
1521 code = ubik_ClientInit(serverconns, &cstruct);
1523 ViceLog(0, ("vl_Initialize: ubik client init failed.\n"));
1529 #define SYSIDMAGIC 0x88aabbcc
1530 #define SYSIDVERSION 1
1535 afs_int32 fd, nentries, i;
1536 struct versionStamp vsn;
1537 struct afs_stat status;
1540 if ((afs_stat(AFSDIR_SERVER_SYSID_FILEPATH, &status))
1541 || (status.st_size <= 0)) {
1542 ViceLog(0, ("%s: doesn't exist\n", AFSDIR_SERVER_SYSID_FILEPATH));
1545 if (!(fd = afs_open(AFSDIR_SERVER_SYSID_FILEPATH, O_RDONLY, 0))) {
1547 ("%s: can't open (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1551 if (read(fd, (char *)&vsn, sizeof(vsn)) != sizeof(vsn)) {
1553 ("%s: Read failed (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1557 if (vsn.magic != SYSIDMAGIC) {
1559 ("%s: wrong magic %x (we support %x)\n",
1560 AFSDIR_SERVER_SYSID_FILEPATH, vsn.magic, SYSIDMAGIC));
1563 if (vsn.version != SYSIDVERSION) {
1565 ("%s: wrong version %d (we support %d)\n",
1566 AFSDIR_SERVER_SYSID_FILEPATH, vsn.version, SYSIDVERSION));
1569 if (read(fd, (char *)&uuid, sizeof(struct afsUUID))
1570 != sizeof(struct afsUUID)) {
1572 ("%s: read of uuid failed (%d)\n",
1573 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1576 afs_ntohuuid(&uuid);
1578 if (read(fd, (char *)&nentries, sizeof(afs_int32)) != sizeof(afs_int32)) {
1580 ("%s: Read of entries failed (%d)\n",
1581 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1584 if (nentries <= 0 || nentries > ADDRSPERSITE) {
1586 ("%s: invalid num of interfaces: %d\n",
1587 AFSDIR_SERVER_SYSID_FILEPATH, nentries));
1590 if (FS_HostAddr_cnt == 0) {
1591 FS_HostAddr_cnt = nentries;
1592 for (i = 0; i < nentries; i++) {
1593 if (read(fd, (char *)&FS_HostAddrs[i], sizeof(afs_int32)) !=
1594 sizeof(afs_int32)) {
1596 ("%s: Read of addresses failed (%d)\n",
1597 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1598 FS_HostAddr_cnt = 0; /* reset it */
1604 ("%s: address list ignored (NetInfo/NetRestrict override)\n",
1605 AFSDIR_SERVER_SYSID_FILEPATH));
1612 WriteSysIdFile(void)
1615 struct versionStamp vsn;
1616 struct afs_stat status;
1619 if (!afs_stat(AFSDIR_SERVER_SYSID_FILEPATH, &status)) {
1621 * File exists; keep the old one around
1623 rk_rename(AFSDIR_SERVER_SYSID_FILEPATH,
1624 AFSDIR_SERVER_OLDSYSID_FILEPATH);
1626 fd = afs_open(AFSDIR_SERVER_SYSID_FILEPATH, O_WRONLY | O_TRUNC | O_CREAT,
1630 ("%s: can't create (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1634 vsn.magic = SYSIDMAGIC;
1636 if ((i = write(fd, (char *)&vsn, sizeof(vsn))) != sizeof(vsn)) {
1638 ("%s: write failed (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1643 afs_htonuuid(&uuid);
1645 write(fd, (char *)&uuid,
1646 sizeof(struct afsUUID))) != sizeof(struct afsUUID)) {
1648 ("%s: write of uuid failed (%d)\n",
1649 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1653 write(fd, (char *)&FS_HostAddr_cnt,
1654 sizeof(afs_int32))) != sizeof(afs_int32)) {
1656 ("%s: write of # of entries failed (%d)\n",
1657 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1660 for (i = 0; i < FS_HostAddr_cnt; i++) {
1661 if (write(fd, (char *)&FS_HostAddrs[i], sizeof(afs_int32)) !=
1662 sizeof(afs_int32)) {
1664 ("%s: write of addresses failed (%d)\n",
1665 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1675 * This routine sets up the buffers for the VL_RegisterAddrs RPC. All addresses
1676 * in FS_HostAddrs[] are in NBO, while the RPC treats them as a "blob" of data
1677 * and so we need to convert each of them into HBO which is what the extra
1678 * array called FS_HostAddrs_HBO is used here.
1681 Do_VLRegisterRPC(void)
1685 afs_uint32 FS_HostAddrs_HBO[ADDRSPERSITE];
1688 for (i = 0; i < FS_HostAddr_cnt; i++)
1689 FS_HostAddrs_HBO[i] = ntohl(FS_HostAddrs[i]);
1690 addrs.bulkaddrs_len = FS_HostAddr_cnt;
1691 addrs.bulkaddrs_val = (afs_uint32 *) FS_HostAddrs_HBO;
1692 code = ubik_VL_RegisterAddrs(cstruct, 0, &FS_HostUUID, 0, &addrs);
1694 if (code == VL_MULTIPADDR) {
1696 ("VL_RegisterAddrs rpc failed; The IP address exists on a different server; repair it\n"));
1698 ("VL_RegisterAddrs rpc failed; See VLLog for details\n"));
1700 } else if (code == RXGEN_OPCODE) {
1702 ("vlserver doesn't support VL_RegisterAddrs rpc; ignored\n"));
1703 FS_registered = 2; /* So we don't have to retry in the gc daemon */
1706 ("VL_RegisterAddrs rpc failed; will retry periodically (code=%d, err=%d)\n",
1708 FS_registered = 1; /* Retry in the gc daemon */
1711 FS_registered = 2; /* So we don't have to retry in the gc daemon */
1723 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH || AFSDIR_SERVER_NETINFO_FILEPATH) {
1725 * Find addresses we are supposed to register as per the netrestrict
1726 * and netinfo files (/usr/afs/local/NetInfo and
1727 * /usr/afs/local/NetRestict)
1732 code = afsconf_ParseNetFiles(FS_HostAddrs, NULL, NULL,
1733 ADDRSPERSITE, reason,
1734 AFSDIR_SERVER_NETINFO_FILEPATH,
1735 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
1737 ViceLog(0, ("Can't register any valid addresses: %s\n", reason));
1740 FS_HostAddr_cnt = (afs_uint32) code;
1743 FS_HostAddr_cnt = rx_getAllAddr(FS_HostAddrs, ADDRSPERSITE);
1746 if (FS_HostAddr_cnt == 1 && rxBind == 1)
1747 code = FS_HostAddrs[0];
1749 code = htonl(INADDR_ANY);
1754 InitVL(struct afsconf_dir *dir)
1759 * If this fails, it's because something major is wrong, and is not
1760 * likely to be time dependent.
1762 code = vl_Initialize(dir);
1765 ("Couldn't initialize volume location library; code=%d.\n", code));
1769 /* Read or create the sysid file and register the fileserver's
1770 * IP addresses with the vlserver.
1772 code = ReadSysIdFile();
1774 /* Need to create the file */
1775 ViceLog(0, ("Creating new SysID file\n"));
1776 if ((code = afs_uuid_create(&FS_HostUUID))) {
1777 ViceLog(0, ("Failed to create new uuid: %d\n", code));
1781 /* A good sysid file exists; inform the vlserver. If any conflicts,
1782 * we always use the latest interface available as the real truth.
1785 code = Do_VLRegisterRPC();
1790 main(int argc, char *argv[])
1794 struct rx_securityClass **securityClasses;
1795 afs_int32 numClasses;
1796 struct rx_service *tservice;
1797 pthread_t serverPid;
1798 pthread_attr_t tattr;
1800 int minVnodesRequired; /* min size of vnode cache */
1801 #ifndef AFS_NT40_ENV
1802 struct rlimit rlim; /* max number of open file descriptors */
1807 afs_uint32 rx_bindhost;
1808 VolumePackageOptions opts;
1810 #ifdef AFS_AIX32_ENV
1811 struct sigaction nsa;
1813 sigemptyset(&nsa.sa_mask);
1814 nsa.sa_handler = SIG_DFL;
1815 nsa.sa_flags = SA_FULLDUMP;
1816 sigaction(SIGABRT, &nsa, NULL);
1817 sigaction(SIGSEGV, &nsa, NULL);
1821 /* Initialize dirpaths */
1822 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
1824 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
1826 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
1830 /* set ihandle package defaults prior to parsing args */
1833 /* check for the parameter file */
1836 FS_configPath = strdup(AFSDIR_SERVER_ETC_DIRPATH);
1837 logFile = strdup(AFSDIR_SERVER_FILELOG_FILEPATH);
1839 if (ParseArgs(argc, argv)) {
1842 opr_mutex_init(&fileproc_glock_mutex);
1844 #ifdef AFS_SGI_VNODE_GLUE
1845 if (afs_init_kernel_config(-1) < 0) {
1847 ("Can't determine NUMA configuration, not starting fileserver.\n");
1852 confDir = afsconf_Open(FS_configPath);
1854 fprintf(stderr, "Unable to open config directory %s\n",
1859 /* initialize audit user check */
1860 osi_audit_set_user_check(confDir, fs_IsLocalRealmMatch);
1862 /* Open FileLog on stdout, stderr, fd 1 and fd2 (for perror), sigh. */
1863 #ifndef AFS_NT40_ENV
1864 serverLogSyslogTag = "fileserver";
1869 LogCommandLine(argc, argv, "starting", "", "File server", FSLog);
1870 if (afsconf_GetLatestKey(confDir, NULL, NULL) == 0) {
1874 #if !defined(AFS_NT40_ENV)
1875 /* initialize the pthread soft signal handler thread */
1879 /* install signal handlers for controlling the fileserver process */
1880 ResetCheckSignal(); /* set CheckSignal_Signal() sig handler */
1881 ResetCheckDescriptors(); /* set CheckDescriptors_Signal() sig handler */
1883 #if defined(AFS_SGI_ENV)
1884 /* give this guy a non-degrading priority so help busy servers */
1885 schedctl(NDPRI, 0, NDPNORMMAX);
1888 #elif !defined(AFS_NT40_ENV)
1893 #ifdef AFS_DEMAND_ATTACH_FS
1898 if (afs_winsockInit() < 0) {
1899 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
1900 ViceLog(0, ("File server failed to intialize winsock.\n"));
1906 /* if we support more than 16 threads, then we better have the ability
1907 ** to keep open a large number of files simultaneously
1909 #if defined(AFS_AIX_ENV) && !defined(AFS_AIX42_ENV)
1910 curLimit = OPEN_MAX; /* for pre AIX 4.2 systems */
1911 #elif defined(AFS_NT40_ENV)
1912 curLimit = NT_OPEN_MAX; /* open file descriptor limit on NT */
1915 curLimit = 0; /* the number of open file descriptors */
1916 code = getrlimit(RLIMIT_NOFILE, &rlim);
1918 curLimit = rlim.rlim_cur;
1919 rlim.rlim_cur = rlim.rlim_max;
1920 code = setrlimit(RLIMIT_NOFILE, &rlim);
1922 curLimit = rlim.rlim_max;
1925 ViceLog(0, ("Failed to increase open file limit, using default\n"));
1927 #endif /* defined(AFS_AIX_ENV) && !defined(AFS_AIX42_ENV) */
1929 curLimit -= 32; /* leave a slack of 32 file descriptors */
1930 if (lwps > curLimit) {
1934 lwps = 16; /* default to a maximum of 16 threads */
1936 /* tune the ihandle fd cache accordingly */
1937 if (vol_io_params.fd_max_cachesize < curLimit)
1938 vol_io_params.fd_max_cachesize = curLimit + 1;
1941 ("The system supports a max of %d open files and we are starting %d threads (ihandle fd cache is %d)\n",
1942 curLimit, lwps, vol_io_params.fd_max_cachesize));
1945 /* Initialize volume support */
1947 V_BreakVolumeCallbacks = BreakVolumeCallBacksLater;
1950 SetLogThreadNumProgram( rx_GetThreadNum );
1952 /* initialize libacl routines */
1953 acl_Initialize(ACL_VERSION);
1955 /* initialize RX support */
1956 #ifndef AFS_NT40_ENV
1957 rxi_syscallp = viced_syscall;
1959 rx_extraPackets = rxpackets;
1960 rx_extraQuota = 4; /* for outgoing prserver calls from R threads */
1961 rx_SetBusyThreshold(busy_threshold, VBUSY);
1962 rx_SetCallAbortThreshold(abort_threshold);
1963 rx_SetConnAbortThreshold(abort_threshold);
1965 stackSize = 128 * 1024;
1967 stackSize = lwps * 4000;
1968 if (stackSize < 32000)
1970 else if (stackSize > 44000)
1973 #if defined(AFS_HPUX_ENV) || defined(AFS_SUN_ENV) || defined(AFS_SGI51_ENV) || defined(AFS_XBSD_ENV)
1974 rx_SetStackSize(1, stackSize);
1977 rx_SetUdpBufSize(udpBufSize); /* set the UDP buffer size for receive */
1978 rx_bindhost = SetupVL();
1980 if (rx_InitHost(rx_bindhost, (int)htons(7000)) < 0) {
1981 ViceLog(0, ("Cannot initialize RX\n"));
1984 if (!rxJumbograms) {
1985 /* Don't send and don't allow 3.4 clients to send jumbograms. */
1988 if (rxMaxMTU != -1) {
1989 if (rx_SetMaxMTU(rxMaxMTU) != 0) {
1990 ViceLog(0, ("rxMaxMTU %d is invalid\n", rxMaxMTU));
1995 rx_SetRxDeadTime(30);
1996 afsconf_SetSecurityFlags(confDir, AFSCONF_SECOPTS_ALWAYSENCRYPT);
1997 afsconf_BuildServerSecurityObjects(confDir, &securityClasses, &numClasses);
1999 tservice = rx_NewServiceHost(rx_bindhost, /* port */ 0, /* service id */
2000 1, /*service name */
2002 securityClasses, numClasses,
2003 RXAFS_ExecuteRequest);
2006 ("Failed to initialize RX, probably two servers running.\n"));
2009 if (rxkadDisableDotCheck) {
2010 rx_SetSecurityConfiguration(tservice, RXS_CONFIG_FLAGS,
2011 (void *)RXS_CONFIG_FLAGS_DISABLE_DOTCHECK);
2013 rx_SetMinProcs(tservice, 3);
2014 rx_SetMaxProcs(tservice, lwps);
2015 rx_SetCheckReach(tservice, 1);
2018 rx_NewService(0, RX_STATS_SERVICE_ID, "rpcstats", securityClasses,
2019 numClasses, RXSTATS_ExecuteRequest);
2021 ViceLog(0, ("Failed to initialize rpc stat service.\n"));
2024 rx_SetMinProcs(tservice, 2);
2025 rx_SetMaxProcs(tservice, 4);
2027 /* Some rx debugging */
2028 if (rxlog || eventlog) {
2029 debugFile = afs_fopen("rx_dbg", "w");
2031 rx_debugFile = debugFile;
2033 rxevent_debugFile = debugFile;
2036 init_sys_error_to_et(); /* Set up error table translation */
2037 h_InitHostPackage(host_thread_quota); /* set up local cellname and realmname */
2038 InitCallBack(numberofcbs);
2041 code = InitVL(confDir);
2042 if (code && code != VL_MULTIPADDR) {
2043 ViceLog(0, ("Fatal error in library initialization, exiting!!\n"));
2048 if (code && code != -1) {
2049 ViceLog(0, ("Fatal error in protection initialization, exiting!!\n"));
2053 /* allow super users to manage RX statistics */
2054 rx_SetRxStatUserOk(viced_SuperUser);
2056 opr_cv_init(&fsync_cond);
2057 opr_mutex_init(&fsync_glock_mutex);
2059 #if !defined(AFS_DEMAND_ATTACH_FS)
2061 * For DAFS, we do not start the Rx server threads until after
2062 * the volume package is initialized, and fileserver state is
2063 * restored. This is necessary in order to keep host and callback
2064 * package state pristine until we have a chance to restore state.
2066 * Furthermore, startup latency is much lower with dafs, so this
2067 * shouldn't pose a serious problem.
2069 rx_StartServer(0); /* now start handling requests */
2072 /* we ensure that there is enough space in the vnode buffer to satisfy
2073 ** requests from all concurrent threads.
2074 ** the maximum number of vnodes used by a single thread at any one time
2075 ** is three ( "link" uses three vnodes simultaneously, one vLarge and
2076 ** two vSmall for linking files and two vLarge and one vSmall for linking
2079 minVnodesRequired = 2 * lwps + 1;
2080 if (minVnodesRequired > nSmallVns) {
2081 nSmallVns = minVnodesRequired;
2083 ("Overriding -s command line parameter with %d\n",
2086 if (minVnodesRequired > large) {
2087 large = minVnodesRequired;
2088 ViceLog(0, ("Overriding -l command line parameter with %d\n", large));
2091 /* We now do this after getting the listener up and running, so that client
2092 * connections don't timeout (maybe) if a file server is restarted, since it
2093 * will be available "real soon now". Worry about whether we can satisfy the
2094 * calls in the volume package itself.
2096 VOptDefaults(fileServer, &opts);
2097 opts.nLargeVnodes = large;
2098 opts.nSmallVnodes = nSmallVns;
2099 opts.volcache = volcache;
2100 opts.unsafe_attach = unsafe_attach;
2101 if (offline_timeout != -1) {
2102 opts.interrupt_rxcall = rx_InterruptCall;
2103 opts.offline_timeout = offline_timeout;
2105 if (offline_shutdown_timeout == -1) {
2106 /* default to -offline-timeout, if shutdown-specific timeout is not
2108 opts.offline_shutdown_timeout = offline_timeout;
2110 opts.interrupt_rxcall = rx_InterruptCall;
2111 opts.offline_shutdown_timeout = offline_shutdown_timeout;
2114 if (VInitVolumePackage2(fileServer, &opts)) {
2116 ("Shutting down: errors encountered initializing volume package\n"));
2121 /* Install handler to catch the shutdown signal;
2122 * bosserver assumes SIGQUIT shutdown
2124 #if !defined(AFS_NT40_ENV)
2125 softsig_signal(SIGQUIT, ShutDown_Signal);
2127 (void)signal(SIGQUIT, ShutDown_Signal);
2130 if (VInitAttachVolumes(fileServer)) {
2132 ("Shutting down: errors encountered initializing volume package\n"));
2137 #ifdef AFS_DEMAND_ATTACH_FS
2138 if (fs_state.options.fs_state_restore) {
2141 * restore fileserver state */
2144 rx_StartServer(0); /* now start handling requests */
2145 #endif /* AFS_DEMAND_ATTACH_FS */
2148 * We are done calling fopen/fdopen. It is safe to use a large
2149 * of the file descriptor cache.
2153 ViceLog(5, ("Starting pthreads\n"));
2154 opr_Verify(pthread_attr_init(&tattr) == 0);
2155 opr_Verify(pthread_attr_setdetachstate(&tattr,
2156 PTHREAD_CREATE_DETACHED) == 0);
2158 opr_Verify(pthread_create(&serverPid, &tattr, FiveMinuteCheckLWP,
2159 &fiveminutes) == 0);
2160 opr_Verify(pthread_create(&serverPid, &tattr, HostCheckLWP,
2161 &fiveminutes) == 0);
2162 opr_Verify(pthread_create(&serverPid, &tattr, FsyncCheckLWP,
2163 &fiveminutes) == 0);
2165 gettimeofday(&tp, 0);
2168 * Figure out the FileServer's name and primary address.
2170 ViceLog(0, ("Getting FileServer name...\n"));
2171 code = gethostname(FS_HostName, 64);
2173 ViceLog(0, ("gethostname() failed\n"));
2175 ViceLog(0, ("FileServer host name is '%s'\n", FS_HostName));
2177 ViceLog(0, ("Getting FileServer address...\n"));
2178 he = gethostbyname(FS_HostName);
2180 ViceLog(0, ("Can't find address for FileServer '%s'\n", FS_HostName));
2183 memcpy(&FS_HostAddr_NBO, he->h_addr, 4);
2184 (void)afs_inet_ntoa_r(FS_HostAddr_NBO, hoststr);
2185 FS_HostAddr_HBO = ntohl(FS_HostAddr_NBO);
2187 ("FileServer %s has address %s (0x%x or 0x%x in host byte order)\n",
2188 FS_HostName, hoststr, FS_HostAddr_NBO, FS_HostAddr_HBO));
2192 strftime(tbuffer, sizeof(tbuffer), "%a %b %d %H:%M:%S %Y",
2193 localtime_r(&t, &tm));
2194 ViceLog(0, ("File Server started %s\n", tbuffer));
2195 afs_FullPerfStats.det.epoch.tv_sec = StartTime = tp.tv_sec;
2197 sleep(1000); /* long time */