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
10 #include <afsconfig.h>
11 #include <afs/param.h>
15 #ifdef AFS_PTHREAD_ENV
16 # include <opr/lock.h>
21 #include <WINNT/afsevent.h>
24 #include <rx/rx_queue.h>
25 #include <afs/afsint.h>
26 #include <afs/prs_fs.h>
30 #include <afs/afssyscalls.h>
31 #include <afs/ihandle.h>
33 #include <afs/ntops.h>
35 #include <afs/vnode.h>
36 #include <afs/volume.h>
37 #include <afs/partition.h>
39 #include <rx/rxstat.h>
40 #include <rx/rx_globals.h>
42 #include <afs/cellconfig.h>
46 #include <afs/audit.h>
47 #include <afs/afsutil.h>
53 #include "volser_internal.h"
55 #define VolserVersion "2.0"
56 #define N_SECURITY_OBJECTS 3
58 extern struct Lock localLock;
59 char *GlobalNameHack = NULL;
61 afs_int32 GlobalVolCloneId, GlobalVolParentId;
63 int VolumeChanged; /* XXXX */
64 static char busyFlags[MAXHELPERS];
65 struct volser_trans *QI_GlobalWriteTrans = 0;
66 struct afsconf_dir *tdir;
67 static afs_int32 runningCalls = 0;
72 int udpBufSize = 0; /* UDP buffer size for receive */
75 int rxkadDisableDotCheck = 0;
76 int DoPreserveVolumeStats = 0;
77 int rxJumbograms = 0; /* default is to not send and receive jumbograms. */
79 char *auditFileName = NULL;
81 char *configDir = NULL;
83 #define ADDRSPERSITE 16 /* Same global is in rx/rx_user.c */
84 afs_uint32 SHostAddrs[ADDRSPERSITE];
86 #define VS_EXIT(code) { \
87 osi_audit(VS_ExitEvent, code, AUD_END); \
92 MyBeforeProc(struct rx_call *acall)
101 MyAfterProc(struct rx_call *acall, afs_int32 code)
109 /* Called every GCWAKEUP seconds to try to unlock all our partitions,
110 * if we're idle and there are no active transactions
115 /* if there are no running calls, and there are no active transactions, then
116 * it should be safe to release any partition locks we've accumulated */
118 if (runningCalls == 0 && TransList() == (struct volser_trans *)0) {
120 VPFullUnlock(); /* in volprocs.c */
125 /* background daemon for timing out transactions */
127 BKGLoop(void *unused)
132 afs_pthread_setname_self("vol bkg");
134 tv.tv_sec = GCWAKEUP;
136 #ifdef AFS_PTHREAD_ENV
138 Sleep(GCWAKEUP * 1000);
140 select(0, 0, 0, 0, &tv);
143 (void)IOMGR_Select(0, 0, 0, 0, &tv);
148 if (loop == 10) { /* reopen log every 5 minutes */
150 ReOpenLog(AFSDIR_SERVER_VOLSERLOG_FILEPATH);
157 /* Background daemon for sleeping so the volserver does not become I/O bound */
158 afs_int32 TTsleep, TTrun;
159 #ifndef AFS_PTHREAD_ENV
161 BKGSleep(void *unused)
163 struct volser_trans *tt;
167 #ifdef AFS_PTHREAD_ENV
169 #else /* AFS_PTHREAD_ENV */
173 for (tt = TransList(); tt; tt = tt->next) {
175 if ((strcmp(tt->lastProcName, "DeleteVolume") == 0)
176 || (strcmp(tt->lastProcName, "Clone") == 0)
177 || (strcmp(tt->lastProcName, "ReClone") == 0)
178 || (strcmp(tt->lastProcName, "Forward") == 0)
179 || (strcmp(tt->lastProcName, "Restore") == 0)
180 || (strcmp(tt->lastProcName, "ForwardMulti") == 0)) {
181 VTRANS_OBJ_UNLOCK(tt);
184 VTRANS_OBJ_UNLOCK(tt);
198 /* no volser_syscall */
199 #elif defined(AFS_SUN511_ENV)
201 volser_syscall(afs_uint32 a3, afs_uint32 a4, void *a5)
204 code = ioctl_sun_afs_syscall(28 /* AFSCALL_CALL */, a3, a4, a5, 0, 0, 0,
213 volser_syscall(afs_uint32 a3, afs_uint32 a4, void *a5)
216 #ifndef AFS_LINUX20_ENV
219 old = signal(SIGSYS, SIG_IGN);
222 syscall(AFS_SYSCALL /* AFS_SYSCALL */ , 28 /* AFSCALL_CALL */ , a3,
224 #ifndef AFS_LINUX20_ENV
233 /* check whether caller is authorized to manage RX statistics */
235 vol_rxstat_userok(struct rx_call *call)
237 return afsconf_SuperUser(tdir, call, NULL);
241 * Return true if this name is a member of the local realm.
244 vol_IsLocalRealmMatch(void *rock, char *name, char *inst, char *cell)
246 struct afsconf_dir *dir = (struct afsconf_dir *)rock;
247 afs_int32 islocal = 0; /* default to no */
250 code = afsconf_IsLocalRealmMatch(dir, &islocal, name, inst, cell);
253 ("Failed local realm check; code=%d, name=%s, inst=%s, cell=%s\n",
254 code, name, inst, cell));
274 OPT_preserve_vol_stats,
282 ParseArgs(int argc, char **argv) {
286 struct cmd_syndesc *opts;
290 opts = cmd_CreateSyntax(NULL, NULL, NULL, NULL);
291 cmd_AddParmAtOffset(opts, OPT_log, "-log", CMD_FLAG, CMD_OPTIONAL,
293 cmd_AddParmAtOffset(opts, OPT_rxbind, "-rxbind", CMD_FLAG, CMD_OPTIONAL,
294 "bind only to the primary interface");
295 cmd_AddParmAtOffset(opts, OPT_dotted, "-allow-dotted-principals", CMD_FLAG, CMD_OPTIONAL,
296 "permit Kerberos 5 principals with dots");
297 cmd_AddParmAtOffset(opts, OPT_debug, "-d", CMD_SINGLE, CMD_OPTIONAL,
299 cmd_AddParmAtOffset(opts, OPT_threads, "-p", CMD_SINGLE, CMD_OPTIONAL,
300 "number of threads");
301 cmd_AddParmAtOffset(opts, OPT_auditlog, "-auditlog", CMD_SINGLE,
302 CMD_OPTIONAL, "location of audit log");
303 cmd_AddParmAtOffset(opts, OPT_audit_interface, "-audit-interface",
304 CMD_SINGLE, CMD_OPTIONAL, "interface to use for audit logging");
305 cmd_AddParmAtOffset(opts, OPT_nojumbo, "-nojumbo", CMD_FLAG, CMD_OPTIONAL,
306 "disable jumbograms");
307 cmd_AddParmAtOffset(opts, OPT_jumbo, "-jumbo", CMD_FLAG, CMD_OPTIONAL,
308 "enable jumbograms");
309 cmd_AddParmAtOffset(opts, OPT_rxmaxmtu, "-rxmaxmtu", CMD_SINGLE,
310 CMD_OPTIONAL, "maximum MTU for RX");
311 cmd_AddParmAtOffset(opts, OPT_udpsize, "-udpsize", CMD_SINGLE,
312 CMD_OPTIONAL, "size of socket buffer in bytes");
313 cmd_AddParmAtOffset(opts, OPT_sleep, "-sleep", CMD_SINGLE,
314 CMD_OPTIONAL, "make background daemon sleep (LWP only)");
315 cmd_AddParmAtOffset(opts, OPT_peer, "-enable_peer_stats", CMD_FLAG,
316 CMD_OPTIONAL, "enable RX transport statistics");
317 cmd_AddParmAtOffset(opts, OPT_process, "-enable_process_stats", CMD_FLAG,
318 CMD_OPTIONAL, "enable RX RPC statistics");
319 cmd_AddParmAtOffset(opts, OPT_preserve_vol_stats, "-preserve-vol-stats", CMD_FLAG,
320 CMD_OPTIONAL, "preserve volume statistics");
321 #if !defined(AFS_NT40_ENV)
322 cmd_AddParmAtOffset(opts, OPT_syslog, "-syslog", CMD_SINGLE_OR_FLAG,
323 CMD_OPTIONAL, "log to syslog");
325 cmd_AddParmAtOffset(opts, OPT_sync, "-sync",
326 CMD_SINGLE, CMD_OPTIONAL, "always | onclose | never");
327 cmd_AddParmAtOffset(opts, OPT_logfile, "-logfile", CMD_SINGLE,
328 CMD_OPTIONAL, "location of log file");
329 cmd_AddParmAtOffset(opts, OPT_config, "-config", CMD_SINGLE,
330 CMD_OPTIONAL, "configuration location");
332 code = cmd_Parse(argc, argv, &opts);
333 if (code == CMD_HELP) {
339 cmd_OptionAsFlag(opts, OPT_log, &DoLogging);
340 cmd_OptionAsFlag(opts, OPT_rxbind, &rxBind);
341 cmd_OptionAsFlag(opts, OPT_dotted, &rxkadDisableDotCheck);
342 cmd_OptionAsFlag(opts, OPT_preserve_vol_stats, &DoPreserveVolumeStats);
343 cmd_OptionAsInt(opts, OPT_debug, &LogLevel);
344 if (cmd_OptionPresent(opts, OPT_peer))
345 rx_enablePeerRPCStats();
346 if (cmd_OptionPresent(opts, OPT_process))
347 rx_enableProcessRPCStats();
348 if (cmd_OptionPresent(opts, OPT_nojumbo))
350 if (cmd_OptionPresent(opts, OPT_jumbo))
353 if (cmd_OptionPresent(opts, OPT_syslog)) {
355 cmd_OptionAsInt(opts, OPT_syslog, &serverLogSyslogFacility);
358 cmd_OptionAsInt(opts, OPT_rxmaxmtu, &rxMaxMTU);
359 if (cmd_OptionAsInt(opts, OPT_udpsize, &optval) == 0) {
360 if (optval < rx_GetMinUdpBufSize()) {
361 printf("Warning:udpsize %d is less than minimum %d; ignoring\n",
362 optval, rx_GetMinUdpBufSize());
366 cmd_OptionAsString(opts, OPT_auditlog, &auditFileName);
368 if (cmd_OptionAsString(opts, OPT_audit_interface, &optstring) == 0) {
369 if (osi_audit_interface(optstring)) {
370 printf("Invalid audit interface '%s'\n", optstring);
376 if (cmd_OptionAsInt(opts, OPT_threads, &lwps) == 0) {
378 printf("Warning: '-p %d' is too big; using %d instead\n", lwps, MAXLWP);
382 if (cmd_OptionAsString(opts, OPT_sleep, &sleepSpec) == 0) {
383 sscanf(sleepSpec, "%d/%d", &TTsleep, &TTrun);
384 if ((TTsleep < 0) || (TTrun <= 0)) {
385 printf("Warning: '-sleep %d/%d' is incorrect; ignoring\n",
391 if (cmd_OptionAsString(opts, OPT_sync, &sync_behavior) == 0) {
392 if (ih_SetSyncBehavior(sync_behavior)) {
393 printf("Invalid -sync value %s\n", sync_behavior);
397 cmd_OptionAsString(opts, OPT_logfile, &logFile);
398 cmd_OptionAsString(opts, OPT_config, &configDir);
403 #include "AFS_component_version_number.c"
405 main(int argc, char **argv)
408 struct rx_securityClass **securityClasses;
409 afs_int32 numClasses;
410 struct rx_service *service;
412 afs_uint32 host = ntohl(INADDR_ANY);
413 VolumePackageOptions opts;
417 * The following signal action for AIX is necessary so that in case of a
418 * crash (i.e. core is generated) we can include the user's data section
419 * in the core dump. Unfortunately, by default, only a partial core is
420 * generated which, in many cases, isn't too useful.
422 struct sigaction nsa;
424 sigemptyset(&nsa.sa_mask);
425 nsa.sa_handler = SIG_DFL;
426 nsa.sa_flags = SA_FULLDUMP;
427 sigaction(SIGABRT, &nsa, NULL);
428 sigaction(SIGSEGV, &nsa, NULL);
431 osi_audit(VS_StartEvent, 0, AUD_END);
433 /* Initialize dirpaths */
434 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
436 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
438 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
445 configDir = strdup(AFSDIR_SERVER_ETC_DIRPATH);
446 logFile = strdup(AFSDIR_SERVER_VOLSERLOG_FILEPATH);
448 if (ParseArgs(argc, argv)) {
453 osi_audit_file(auditFileName);
454 osi_audit(VS_StartEvent, 0, AUD_END);
456 #ifdef AFS_SGI_VNODE_GLUE
457 if (afs_init_kernel_config(-1) < 0) {
459 ("Can't determine NUMA configuration, not starting volserver.\n");
465 #ifdef AFS_PTHREAD_ENV
466 SetLogThreadNumProgram( rx_GetThreadNum );
470 if (afs_winsockInit() < 0) {
471 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
472 printf("Volume server unable to start winsock, exiting.\n");
476 /* Open VolserLog and map stdout, stderr into it; VInitVolumePackage2 can
477 log, so we need to do this here */
480 VOptDefaults(volumeServer, &opts);
481 if (VInitVolumePackage2(volumeServer, &opts)) {
482 Log("Shutting down: errors encountered initializing volume package\n");
486 Lock_Init(&localLock);
488 #ifndef AFS_PTHREAD_ENV
489 vol_PollProc = IOMGR_Poll; /* tell vol pkg to poll io system periodically */
492 rxi_syscallp = volser_syscall;
494 rx_nPackets = rxpackets; /* set the max number of packets */
496 rx_SetUdpBufSize(udpBufSize); /* set the UDP buffer size for receive */
499 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH ||
500 AFSDIR_SERVER_NETINFO_FILEPATH) {
502 ccode = afsconf_ParseNetFiles(SHostAddrs, NULL, NULL,
503 ADDRSPERSITE, reason,
504 AFSDIR_SERVER_NETINFO_FILEPATH,
505 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
508 ccode = rx_getAllAddr(SHostAddrs, ADDRSPERSITE);
511 host = SHostAddrs[0];
514 code = rx_InitHost(host, (int)htons(AFSCONF_VOLUMEPORT));
516 fprintf(stderr, "rx init failed on socket AFSCONF_VOLUMEPORT %u\n",
521 /* Don't allow 3.4 vos clients to send jumbograms and we don't send. */
524 if (rxMaxMTU != -1) {
525 if (rx_SetMaxMTU(rxMaxMTU) != 0) {
526 fprintf(stderr, "rxMaxMTU %d is invalid\n", rxMaxMTU);
531 rx_SetRxDeadTime(420);
532 memset(busyFlags, 0, sizeof(busyFlags));
537 #ifdef AFS_PTHREAD_ENV
539 pthread_attr_t tattr;
540 opr_Verify(pthread_attr_init(&tattr) == 0);
541 opr_Verify(pthread_attr_setdetachstate(&tattr,
542 PTHREAD_CREATE_DETACHED) == 0);
543 opr_Verify(pthread_create(&tid, &tattr, BKGLoop, NULL) == 0);
546 LWP_CreateProcess(BKGLoop, 16*1024, 3, 0, "vol bkg daemon", &pid);
547 LWP_CreateProcess(BKGSleep,16*1024, 3, 0, "vol slp daemon", &pid);
551 /* Create a single security object, in this case the null security object, for unauthenticated connections, which will be used to control security on connections made to this server */
553 tdir = afsconf_Open(configDir);
555 Abort("volser: could not open conf files in %s\n",
560 /* initialize audit user check */
561 osi_audit_set_user_check(tdir, vol_IsLocalRealmMatch);
563 afsconf_BuildServerSecurityObjects(tdir, &securityClasses, &numClasses);
564 if (securityClasses[0] == NULL)
565 Abort("rxnull_NewServerSecurityObject");
567 rx_NewServiceHost(host, 0, VOLSERVICE_ID, "VOLSER", securityClasses,
568 numClasses, AFSVolExecuteRequest);
569 if (service == (struct rx_service *)0)
570 Abort("rx_NewService");
571 rx_SetBeforeProc(service, MyBeforeProc);
572 rx_SetAfterProc(service, MyAfterProc);
573 rx_SetIdleDeadTime(service, 0); /* never timeout */
576 rx_SetMaxProcs(service, lwps);
577 #if defined(AFS_XBSD_ENV)
578 rx_SetStackSize(service, (128 * 1024));
579 #elif defined(AFS_SGI_ENV)
580 rx_SetStackSize(service, (48 * 1024));
582 rx_SetStackSize(service, (32 * 1024));
585 if (rxkadDisableDotCheck) {
586 rx_SetSecurityConfiguration(service, RXS_CONFIG_FLAGS,
587 (void *)RXS_CONFIG_FLAGS_DISABLE_DOTCHECK);
591 rx_NewService(0, RX_STATS_SERVICE_ID, "rpcstats", securityClasses,
592 numClasses, RXSTATS_ExecuteRequest);
593 if (service == (struct rx_service *)0)
594 Abort("rx_NewService");
595 rx_SetMinProcs(service, 2);
596 rx_SetMaxProcs(service, 4);
598 LogCommandLine(argc, argv, "Volserver", VolserVersion, "Starting AFS",
600 if (afsconf_GetLatestKey(tdir, NULL, NULL) == 0) {
604 Log("Will sleep %d second%s every %d second%s\n", TTsleep,
605 (TTsleep > 1) ? "s" : "", TTrun + TTsleep,
606 (TTrun + TTsleep > 1) ? "s" : "");
609 /* allow super users to manage RX statistics */
610 rx_SetRxStatUserOk(vol_rxstat_userok);
612 rx_StartServer(1); /* Donate this process to the server process pool */
614 osi_audit(VS_FinishEvent, (-1), AUD_END);
615 Abort("StartServer returned?");
616 return 0; /* not reached */