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>
17 # include <opr/softsig.h>
22 #include <WINNT/afsevent.h>
25 #include <rx/rx_queue.h>
26 #include <afs/afsint.h>
27 #include <afs/prs_fs.h>
31 #include <afs/afssyscalls.h>
32 #include <afs/ihandle.h>
34 #include <afs/ntops.h>
36 #include <afs/vnode.h>
37 #include <afs/volume.h>
38 #include <afs/partition.h>
40 #include <rx/rxstat.h>
41 #include <rx/rx_globals.h>
43 #include <afs/cellconfig.h>
47 #include <afs/audit.h>
48 #include <afs/afsutil.h>
54 #include "volser_internal.h"
56 #define VolserVersion "2.0"
57 #define N_SECURITY_OBJECTS 3
59 extern struct Lock localLock;
60 char *GlobalNameHack = NULL;
62 afs_int32 GlobalVolCloneId, GlobalVolParentId;
64 int VolumeChanged; /* XXXX */
65 static char busyFlags[MAXHELPERS];
66 struct volser_trans *QI_GlobalWriteTrans = 0;
67 struct afsconf_dir *tdir;
68 static afs_int32 runningCalls = 0;
73 int udpBufSize = 0; /* UDP buffer size for receive */
74 int restrictedQueryLevel = RESTRICTED_QUERY_ANYUSER;
77 int rxkadDisableDotCheck = 0;
78 int DoPreserveVolumeStats = 1;
79 int rxJumbograms = 0; /* default is to not send and receive jumbograms. */
81 char *auditFileName = NULL;
82 static struct logOptions logopts;
83 char *configDir = NULL;
85 enum vol_s2s_crypt doCrypt = VS2SC_NEVER;
87 #define ADDRSPERSITE 16 /* Same global is in rx/rx_user.c */
88 afs_uint32 SHostAddrs[ADDRSPERSITE];
90 #define VS_EXIT(code) { \
91 osi_audit(VS_ExitEvent, code, AUD_END); \
96 MyBeforeProc(struct rx_call *acall)
105 MyAfterProc(struct rx_call *acall, afs_int32 code)
113 /* Called every GCWAKEUP seconds to try to unlock all our partitions,
114 * if we're idle and there are no active transactions
119 /* if there are no running calls, and there are no active transactions, then
120 * it should be safe to release any partition locks we've accumulated */
122 if (runningCalls == 0 && TransList() == (struct volser_trans *)0) {
124 VPFullUnlock(); /* in volprocs.c */
129 /* background daemon for timing out transactions */
131 BKGLoop(void *unused)
136 opr_threadname_set("vol bkg");
138 tv.tv_sec = GCWAKEUP;
140 #ifdef AFS_PTHREAD_ENV
142 Sleep(GCWAKEUP * 1000);
144 select(0, 0, 0, 0, &tv);
147 (void)IOMGR_Select(0, 0, 0, 0, &tv);
152 if (loop == 10) { /* reopen log every 5 minutes */
158 AFS_UNREACHED(return(NULL));
161 #if defined(AFS_NT40_ENV) || defined(AFS_DARWIN160_ENV)
162 /* no volser_syscall */
163 #elif defined(AFS_SUN511_ENV)
165 volser_syscall(afs_uint32 a3, afs_uint32 a4, void *a5)
168 code = ioctl_sun_afs_syscall(28 /* AFSCALL_CALL */, a3, a4, a5, 0, 0, 0,
175 #elif !defined(AFS_SYSCALL)
177 volser_syscall(afs_uint32 a3, afs_uint32 a4, void *a5)
184 volser_syscall(afs_uint32 a3, afs_uint32 a4, void *a5)
187 #ifndef AFS_LINUX20_ENV
190 old = signal(SIGSYS, SIG_IGN);
193 syscall(AFS_SYSCALL /* AFS_SYSCALL */ , 28 /* AFSCALL_CALL */ , a3,
195 #ifndef AFS_LINUX20_ENV
204 /* check whether caller is authorized to manage RX statistics */
206 vol_rxstat_userok(struct rx_call *call)
208 return afsconf_SuperUser(tdir, call, NULL);
212 * Return true if this name is a member of the local realm.
215 vol_IsLocalRealmMatch(void *rock, char *name, char *inst, char *cell)
217 struct afsconf_dir *dir = (struct afsconf_dir *)rock;
218 afs_int32 islocal = 0; /* default to no */
221 code = afsconf_IsLocalRealmMatch(dir, &islocal, name, inst, cell);
224 ("Failed local realm check; code=%d, name=%s, inst=%s, cell=%s\n",
225 code, name, inst, cell));
245 OPT_preserve_vol_stats,
253 OPT_restricted_query,
259 ParseArgs(int argc, char **argv) {
262 char *optstring = NULL;
263 struct cmd_syndesc *opts;
264 char *sleepSpec = NULL;
265 char *sync_behavior = NULL;
266 char *restricted_query_parameter = NULL;
267 char *s2s_crypt_behavior = NULL;
269 opts = cmd_CreateSyntax(NULL, NULL, NULL, 0, NULL);
270 cmd_AddParmAtOffset(opts, OPT_log, "-log", CMD_FLAG, CMD_OPTIONAL,
272 cmd_AddParmAtOffset(opts, OPT_rxbind, "-rxbind", CMD_FLAG, CMD_OPTIONAL,
273 "bind only to the primary interface");
274 cmd_AddParmAtOffset(opts, OPT_dotted, "-allow-dotted-principals", CMD_FLAG, CMD_OPTIONAL,
275 "permit Kerberos 5 principals with dots");
276 cmd_AddParmAtOffset(opts, OPT_debug, "-d", CMD_SINGLE, CMD_OPTIONAL,
278 cmd_AddParmAtOffset(opts, OPT_threads, "-p", CMD_SINGLE, CMD_OPTIONAL,
279 "number of threads");
280 cmd_AddParmAtOffset(opts, OPT_auditlog, "-auditlog", CMD_SINGLE,
281 CMD_OPTIONAL, "location of audit log");
282 cmd_AddParmAtOffset(opts, OPT_audit_interface, "-audit-interface",
283 CMD_SINGLE, CMD_OPTIONAL, "interface to use for audit logging");
284 cmd_AddParmAtOffset(opts, OPT_nojumbo, "-nojumbo", CMD_FLAG, CMD_OPTIONAL,
285 "disable jumbograms");
286 cmd_AddParmAtOffset(opts, OPT_jumbo, "-jumbo", CMD_FLAG, CMD_OPTIONAL,
287 "enable jumbograms");
288 cmd_AddParmAtOffset(opts, OPT_rxmaxmtu, "-rxmaxmtu", CMD_SINGLE,
289 CMD_OPTIONAL, "maximum MTU for RX");
290 cmd_AddParmAtOffset(opts, OPT_udpsize, "-udpsize", CMD_SINGLE,
291 CMD_OPTIONAL, "size of socket buffer in bytes");
292 cmd_AddParmAtOffset(opts, OPT_sleep, "-sleep", CMD_SINGLE,
293 CMD_OPTIONAL, "make background daemon sleep (LWP only)");
294 cmd_AddParmAtOffset(opts, OPT_peer, "-enable_peer_stats", CMD_FLAG,
295 CMD_OPTIONAL, "enable RX transport statistics");
296 cmd_AddParmAtOffset(opts, OPT_process, "-enable_process_stats", CMD_FLAG,
297 CMD_OPTIONAL, "enable RX RPC statistics");
298 /* -preserve-vol-stats on by default now. */
299 cmd_AddParmAtOffset(opts, OPT_preserve_vol_stats, "-preserve-vol-stats", CMD_FLAG,
300 CMD_OPTIONAL|CMD_HIDDEN,
301 "preserve volume statistics when restoring/recloning");
302 cmd_AddParmAtOffset(opts, OPT_clear_vol_stats, "-clear-vol-stats", CMD_FLAG,
303 CMD_OPTIONAL, "clear volume statistics when restoring/recloning");
305 cmd_AddParmAtOffset(opts, OPT_syslog, "-syslog", CMD_SINGLE_OR_FLAG,
306 CMD_OPTIONAL, "log to syslog");
308 cmd_AddParmAtOffset(opts, OPT_transarc_logs, "-transarc-logs", CMD_FLAG,
309 CMD_OPTIONAL, "enable Transarc style logging");
310 cmd_AddParmAtOffset(opts, OPT_sync, "-sync",
311 CMD_SINGLE, CMD_OPTIONAL, "always | onclose | never");
312 cmd_AddParmAtOffset(opts, OPT_logfile, "-logfile", CMD_SINGLE,
313 CMD_OPTIONAL, "location of log file");
314 cmd_AddParmAtOffset(opts, OPT_config, "-config", CMD_SINGLE,
315 CMD_OPTIONAL, "configuration location");
316 cmd_AddParmAtOffset(opts, OPT_restricted_query, "-restricted_query",
317 CMD_SINGLE, CMD_OPTIONAL, "anyuser | admin");
318 cmd_AddParmAtOffset(opts, OPT_s2s_crypt, "-s2scrypt",
319 CMD_SINGLE, CMD_OPTIONAL, "always | inherit | never");
321 code = cmd_Parse(argc, argv, &opts);
322 if (code == CMD_HELP) {
328 cmd_OptionAsFlag(opts, OPT_log, &DoLogging);
329 cmd_OptionAsFlag(opts, OPT_rxbind, &rxBind);
330 cmd_OptionAsFlag(opts, OPT_dotted, &rxkadDisableDotCheck);
331 if (cmd_OptionPresent(opts, OPT_clear_vol_stats))
332 DoPreserveVolumeStats = 0;
333 if (cmd_OptionPresent(opts, OPT_peer))
334 rx_enablePeerRPCStats();
335 if (cmd_OptionPresent(opts, OPT_process))
336 rx_enableProcessRPCStats();
337 if (cmd_OptionPresent(opts, OPT_nojumbo))
339 if (cmd_OptionPresent(opts, OPT_jumbo))
343 if (cmd_OptionPresent(opts, OPT_syslog)) {
344 if (cmd_OptionPresent(opts, OPT_logfile)) {
345 fprintf(stderr, "Invalid options: -syslog and -logfile are exclusive.\n");
348 if (cmd_OptionPresent(opts, OPT_transarc_logs)) {
349 fprintf(stderr, "Invalid options: -syslog and -transarc-logs are exclusive.\n");
352 logopts.lopt_dest = logDest_syslog;
353 logopts.lopt_facility = LOG_DAEMON;
354 logopts.lopt_tag = "volserver";
355 cmd_OptionAsInt(opts, OPT_syslog, &logopts.lopt_facility);
359 logopts.lopt_dest = logDest_file;
360 if (cmd_OptionPresent(opts, OPT_transarc_logs)) {
361 logopts.lopt_rotateOnOpen = 1;
362 logopts.lopt_rotateStyle = logRotate_old;
364 if (cmd_OptionPresent(opts, OPT_logfile))
365 cmd_OptionAsString(opts, OPT_logfile, (char**)&logopts.lopt_filename);
367 logopts.lopt_filename = AFSDIR_SERVER_VOLSERLOG_FILEPATH;
369 cmd_OptionAsInt(opts, OPT_debug, &logopts.lopt_logLevel);
371 cmd_OptionAsInt(opts, OPT_rxmaxmtu, &rxMaxMTU);
372 if (cmd_OptionAsInt(opts, OPT_udpsize, &optval) == 0) {
373 if (optval < rx_GetMinUdpBufSize()) {
374 printf("Warning:udpsize %d is less than minimum %d; ignoring\n",
375 optval, rx_GetMinUdpBufSize());
379 cmd_OptionAsString(opts, OPT_auditlog, &auditFileName);
381 if (cmd_OptionAsString(opts, OPT_audit_interface, &optstring) == 0) {
382 if (osi_audit_interface(optstring)) {
383 printf("Invalid audit interface '%s'\n", optstring);
389 if (cmd_OptionAsInt(opts, OPT_threads, &lwps) == 0) {
391 printf("Warning: '-p %d' is too big; using %d instead\n", lwps, MAXLWP);
395 if (cmd_OptionAsString(opts, OPT_sleep, &sleepSpec) == 0) {
396 printf("Warning: -sleep option ignored; this option is obsolete\n");
398 if (cmd_OptionAsString(opts, OPT_sync, &sync_behavior) == 0) {
399 if (ih_SetSyncBehavior(sync_behavior)) {
400 printf("Invalid -sync value %s\n", sync_behavior);
404 cmd_OptionAsString(opts, OPT_config, &configDir);
405 if (cmd_OptionAsString(opts, OPT_restricted_query,
406 &restricted_query_parameter) == 0) {
407 if (strcmp(restricted_query_parameter, "anyuser") == 0)
408 restrictedQueryLevel = RESTRICTED_QUERY_ANYUSER;
409 else if (strcmp(restricted_query_parameter, "admin") == 0)
410 restrictedQueryLevel = RESTRICTED_QUERY_ADMIN;
412 printf("invalid argument for -restricted_query: %s\n",
413 restricted_query_parameter);
416 free(restricted_query_parameter);
418 if (cmd_OptionAsString(opts, OPT_s2s_crypt, &s2s_crypt_behavior) == 0) {
419 if (strcmp(s2s_crypt_behavior, "always") == 0)
420 doCrypt = VS2SC_ALWAYS;
421 else if (strcmp(s2s_crypt_behavior, "never") == 0)
422 doCrypt = VS2SC_NEVER;
423 else if (strcmp(s2s_crypt_behavior, "inherit") == 0)
424 doCrypt = VS2SC_INHERIT;
426 printf("invalid argument for -s2scrypt: %s\n", s2s_crypt_behavior);
429 free(s2s_crypt_behavior);
435 #include "AFS_component_version_number.c"
437 main(int argc, char **argv)
440 struct rx_securityClass **securityClasses;
441 afs_int32 numClasses;
442 struct rx_service *service;
445 afs_uint32 host = ntohl(INADDR_ANY);
446 VolumePackageOptions opts;
450 * The following signal action for AIX is necessary so that in case of a
451 * crash (i.e. core is generated) we can include the user's data section
452 * in the core dump. Unfortunately, by default, only a partial core is
453 * generated which, in many cases, isn't too useful.
455 struct sigaction nsa;
457 sigemptyset(&nsa.sa_mask);
458 nsa.sa_handler = SIG_DFL;
459 nsa.sa_flags = SA_FULLDUMP;
460 sigaction(SIGABRT, &nsa, NULL);
461 sigaction(SIGSEGV, &nsa, NULL);
464 osi_audit(VS_StartEvent, 0, AUD_END);
466 /* Initialize dirpaths */
467 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
469 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
471 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
476 configDir = strdup(AFSDIR_SERVER_ETC_DIRPATH);
478 if (ParseArgs(argc, argv)) {
483 osi_audit_file(auditFileName);
484 osi_audit(VS_StartEvent, 0, AUD_END);
486 #ifdef AFS_SGI_VNODE_GLUE
487 if (afs_init_kernel_config(-1) < 0) {
489 ("Can't determine NUMA configuration, not starting volserver.\n");
495 #ifdef AFS_PTHREAD_ENV
496 SetLogThreadNumProgram( rx_GetThreadNum );
500 if (afs_winsockInit() < 0) {
501 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
502 printf("Volume server unable to start winsock, exiting.\n");
509 VOptDefaults(volumeServer, &opts);
510 if (VInitVolumePackage2(volumeServer, &opts)) {
511 Log("Shutting down: errors encountered initializing volume package\n");
515 Lock_Init(&localLock);
517 #ifndef AFS_PTHREAD_ENV
518 vol_PollProc = IOMGR_Poll; /* tell vol pkg to poll io system periodically */
520 #if !defined( AFS_NT40_ENV ) && !defined(AFS_DARWIN160_ENV)
521 rxi_syscallp = volser_syscall;
523 rx_nPackets = rxpackets; /* set the max number of packets */
525 rx_SetUdpBufSize(udpBufSize); /* set the UDP buffer size for receive */
528 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH ||
529 AFSDIR_SERVER_NETINFO_FILEPATH) {
531 ccode = afsconf_ParseNetFiles(SHostAddrs, NULL, NULL,
532 ADDRSPERSITE, reason,
533 AFSDIR_SERVER_NETINFO_FILEPATH,
534 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
537 ccode = rx_getAllAddr(SHostAddrs, ADDRSPERSITE);
540 host = SHostAddrs[0];
543 Log("Volserver binding rx to %s:%d\n",
544 afs_inet_ntoa_r(host, hoststr), AFSCONF_VOLUMEPORT);
545 code = rx_InitHost(host, (int)htons(AFSCONF_VOLUMEPORT));
547 fprintf(stderr, "rx init failed on socket AFSCONF_VOLUMEPORT %u\n",
552 /* Don't allow 3.4 vos clients to send jumbograms and we don't send. */
555 if (rxMaxMTU != -1) {
556 if (rx_SetMaxMTU(rxMaxMTU) != 0) {
557 fprintf(stderr, "rxMaxMTU %d is invalid\n", rxMaxMTU);
562 rx_SetRxDeadTime(420);
563 memset(busyFlags, 0, sizeof(busyFlags));
565 #ifdef AFS_PTHREAD_ENV
567 SetupLogSoftSignals();
573 #ifdef AFS_PTHREAD_ENV
575 pthread_attr_t tattr;
576 opr_Verify(pthread_attr_init(&tattr) == 0);
577 opr_Verify(pthread_attr_setdetachstate(&tattr,
578 PTHREAD_CREATE_DETACHED) == 0);
579 opr_Verify(pthread_create(&tid, &tattr, BKGLoop, NULL) == 0);
582 LWP_CreateProcess(BKGLoop, 16*1024, 3, 0, "vol bkg daemon", &pid);
586 /* 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 */
588 tdir = afsconf_Open(configDir);
590 Abort("volser: could not open conf files in %s\n",
592 AFS_UNREACHED(VS_EXIT(1));
595 /* initialize audit user check */
596 osi_audit_set_user_check(tdir, vol_IsLocalRealmMatch);
598 afsconf_BuildServerSecurityObjects(tdir, &securityClasses, &numClasses);
599 if (securityClasses[0] == NULL)
600 Abort("rxnull_NewServerSecurityObject");
602 rx_NewServiceHost(host, 0, VOLSERVICE_ID, "VOLSER", securityClasses,
603 numClasses, AFSVolExecuteRequest);
604 if (service == (struct rx_service *)0)
605 Abort("rx_NewService");
606 rx_SetBeforeProc(service, MyBeforeProc);
607 rx_SetAfterProc(service, MyAfterProc);
608 rx_SetIdleDeadTime(service, 0); /* never timeout */
611 rx_SetMaxProcs(service, lwps);
612 #if defined(AFS_XBSD_ENV)
613 rx_SetStackSize(service, (128 * 1024));
614 #elif defined(AFS_SGI_ENV)
615 rx_SetStackSize(service, (48 * 1024));
617 rx_SetStackSize(service, (32 * 1024));
620 if (rxkadDisableDotCheck) {
621 code = rx_SetSecurityConfiguration(service, RXS_CONFIG_FLAGS,
622 (void *)RXS_CONFIG_FLAGS_DISABLE_DOTCHECK);
625 "volser: failed to allow dotted principals: code %d\n",
632 rx_NewService(0, RX_STATS_SERVICE_ID, "rpcstats", securityClasses,
633 numClasses, RXSTATS_ExecuteRequest);
634 if (service == (struct rx_service *)0)
635 Abort("rx_NewService");
636 rx_SetMinProcs(service, 2);
637 rx_SetMaxProcs(service, 4);
639 LogCommandLine(argc, argv, "Volserver", VolserVersion, "Starting AFS",
641 if (afsconf_GetLatestKey(tdir, NULL, NULL) == 0) {
645 /* allow super users to manage RX statistics */
646 rx_SetRxStatUserOk(vol_rxstat_userok);
648 rx_StartServer(1); /* Donate this process to the server process pool */
650 osi_audit(VS_FinishEvent, (-1), AUD_END);
651 Abort("StartServer returned?");
652 AFS_UNREACHED(return 0);