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>
18 # include <afs/procmgmt_softsig.h> /* must come after softsig */
23 #include <WINNT/afsevent.h>
26 #include <rx/rx_queue.h>
27 #include <afs/afsint.h>
28 #include <afs/prs_fs.h>
32 #include <afs/afssyscalls.h>
33 #include <afs/ihandle.h>
35 #include <afs/ntops.h>
37 #include <afs/vnode.h>
38 #include <afs/volume.h>
39 #include <afs/partition.h>
41 #include <rx/rxstat.h>
42 #include <rx/rx_globals.h>
44 #include <afs/cellconfig.h>
48 #include <afs/audit.h>
49 #include <afs/afsutil.h>
55 #include "volser_internal.h"
57 #define VolserVersion "2.0"
58 #define N_SECURITY_OBJECTS 3
60 extern struct Lock localLock;
61 char *GlobalNameHack = NULL;
63 afs_int32 GlobalVolCloneId, GlobalVolParentId;
65 int VolumeChanged; /* XXXX */
66 static char busyFlags[MAXHELPERS];
67 struct volser_trans *QI_GlobalWriteTrans = 0;
68 struct afsconf_dir *tdir;
69 static afs_int32 runningCalls = 0;
74 int udpBufSize = 0; /* UDP buffer size for receive */
75 int restrictedQueryLevel = RESTRICTED_QUERY_ANYUSER;
78 int rxkadDisableDotCheck = 0;
79 int DoPreserveVolumeStats = 0;
80 int rxJumbograms = 0; /* default is to not send and receive jumbograms. */
82 char *auditFileName = NULL;
83 static struct logOptions logopts;
84 char *configDir = NULL;
86 #define ADDRSPERSITE 16 /* Same global is in rx/rx_user.c */
87 afs_uint32 SHostAddrs[ADDRSPERSITE];
89 #define VS_EXIT(code) { \
90 osi_audit(VS_ExitEvent, code, AUD_END); \
95 MyBeforeProc(struct rx_call *acall)
104 MyAfterProc(struct rx_call *acall, afs_int32 code)
112 /* Called every GCWAKEUP seconds to try to unlock all our partitions,
113 * if we're idle and there are no active transactions
118 /* if there are no running calls, and there are no active transactions, then
119 * it should be safe to release any partition locks we've accumulated */
121 if (runningCalls == 0 && TransList() == (struct volser_trans *)0) {
123 VPFullUnlock(); /* in volprocs.c */
128 /* background daemon for timing out transactions */
130 BKGLoop(void *unused)
135 afs_pthread_setname_self("vol bkg");
137 tv.tv_sec = GCWAKEUP;
139 #ifdef AFS_PTHREAD_ENV
141 Sleep(GCWAKEUP * 1000);
143 select(0, 0, 0, 0, &tv);
146 (void)IOMGR_Select(0, 0, 0, 0, &tv);
151 if (loop == 10) { /* reopen log every 5 minutes */
161 /* no volser_syscall */
162 #elif defined(AFS_SUN511_ENV)
164 volser_syscall(afs_uint32 a3, afs_uint32 a4, void *a5)
167 code = ioctl_sun_afs_syscall(28 /* AFSCALL_CALL */, a3, a4, a5, 0, 0, 0,
176 volser_syscall(afs_uint32 a3, afs_uint32 a4, void *a5)
179 #ifndef AFS_LINUX20_ENV
182 old = signal(SIGSYS, SIG_IGN);
185 syscall(AFS_SYSCALL /* AFS_SYSCALL */ , 28 /* AFSCALL_CALL */ , a3,
187 #ifndef AFS_LINUX20_ENV
196 /* check whether caller is authorized to manage RX statistics */
198 vol_rxstat_userok(struct rx_call *call)
200 return afsconf_SuperUser(tdir, call, NULL);
204 * Return true if this name is a member of the local realm.
207 vol_IsLocalRealmMatch(void *rock, char *name, char *inst, char *cell)
209 struct afsconf_dir *dir = (struct afsconf_dir *)rock;
210 afs_int32 islocal = 0; /* default to no */
213 code = afsconf_IsLocalRealmMatch(dir, &islocal, name, inst, cell);
216 ("Failed local realm check; code=%d, name=%s, inst=%s, cell=%s\n",
217 code, name, inst, cell));
237 OPT_preserve_vol_stats,
248 ParseArgs(int argc, char **argv) {
251 char *optstring = NULL;
252 struct cmd_syndesc *opts;
253 char *sleepSpec = NULL;
254 char *sync_behavior = NULL;
255 char *restricted_query_parameter = NULL;
257 opts = cmd_CreateSyntax(NULL, NULL, NULL, 0, NULL);
258 cmd_AddParmAtOffset(opts, OPT_log, "-log", CMD_FLAG, CMD_OPTIONAL,
260 cmd_AddParmAtOffset(opts, OPT_rxbind, "-rxbind", CMD_FLAG, CMD_OPTIONAL,
261 "bind only to the primary interface");
262 cmd_AddParmAtOffset(opts, OPT_dotted, "-allow-dotted-principals", CMD_FLAG, CMD_OPTIONAL,
263 "permit Kerberos 5 principals with dots");
264 cmd_AddParmAtOffset(opts, OPT_debug, "-d", CMD_SINGLE, CMD_OPTIONAL,
266 cmd_AddParmAtOffset(opts, OPT_threads, "-p", CMD_SINGLE, CMD_OPTIONAL,
267 "number of threads");
268 cmd_AddParmAtOffset(opts, OPT_auditlog, "-auditlog", CMD_SINGLE,
269 CMD_OPTIONAL, "location of audit log");
270 cmd_AddParmAtOffset(opts, OPT_audit_interface, "-audit-interface",
271 CMD_SINGLE, CMD_OPTIONAL, "interface to use for audit logging");
272 cmd_AddParmAtOffset(opts, OPT_nojumbo, "-nojumbo", CMD_FLAG, CMD_OPTIONAL,
273 "disable jumbograms");
274 cmd_AddParmAtOffset(opts, OPT_jumbo, "-jumbo", CMD_FLAG, CMD_OPTIONAL,
275 "enable jumbograms");
276 cmd_AddParmAtOffset(opts, OPT_rxmaxmtu, "-rxmaxmtu", CMD_SINGLE,
277 CMD_OPTIONAL, "maximum MTU for RX");
278 cmd_AddParmAtOffset(opts, OPT_udpsize, "-udpsize", CMD_SINGLE,
279 CMD_OPTIONAL, "size of socket buffer in bytes");
280 cmd_AddParmAtOffset(opts, OPT_sleep, "-sleep", CMD_SINGLE,
281 CMD_OPTIONAL, "make background daemon sleep (LWP only)");
282 cmd_AddParmAtOffset(opts, OPT_peer, "-enable_peer_stats", CMD_FLAG,
283 CMD_OPTIONAL, "enable RX transport statistics");
284 cmd_AddParmAtOffset(opts, OPT_process, "-enable_process_stats", CMD_FLAG,
285 CMD_OPTIONAL, "enable RX RPC statistics");
286 cmd_AddParmAtOffset(opts, OPT_preserve_vol_stats, "-preserve-vol-stats", CMD_FLAG,
287 CMD_OPTIONAL, "preserve volume statistics");
289 cmd_AddParmAtOffset(opts, OPT_syslog, "-syslog", CMD_SINGLE_OR_FLAG,
290 CMD_OPTIONAL, "log to syslog");
292 cmd_AddParmAtOffset(opts, OPT_sync, "-sync",
293 CMD_SINGLE, CMD_OPTIONAL, "always | onclose | never");
294 cmd_AddParmAtOffset(opts, OPT_logfile, "-logfile", CMD_SINGLE,
295 CMD_OPTIONAL, "location of log file");
296 cmd_AddParmAtOffset(opts, OPT_config, "-config", CMD_SINGLE,
297 CMD_OPTIONAL, "configuration location");
298 cmd_AddParmAtOffset(opts, OPT_restricted_query, "-restricted_query",
299 CMD_SINGLE, CMD_OPTIONAL, "anyuser | admin");
301 code = cmd_Parse(argc, argv, &opts);
302 if (code == CMD_HELP) {
308 cmd_OptionAsFlag(opts, OPT_log, &DoLogging);
309 cmd_OptionAsFlag(opts, OPT_rxbind, &rxBind);
310 cmd_OptionAsFlag(opts, OPT_dotted, &rxkadDisableDotCheck);
311 cmd_OptionAsFlag(opts, OPT_preserve_vol_stats, &DoPreserveVolumeStats);
312 if (cmd_OptionPresent(opts, OPT_peer))
313 rx_enablePeerRPCStats();
314 if (cmd_OptionPresent(opts, OPT_process))
315 rx_enableProcessRPCStats();
316 if (cmd_OptionPresent(opts, OPT_nojumbo))
318 if (cmd_OptionPresent(opts, OPT_jumbo))
322 if (cmd_OptionPresent(opts, OPT_syslog)) {
323 if (cmd_OptionPresent(opts, OPT_logfile)) {
324 fprintf(stderr, "Invalid options: -syslog and -logfile are exclusive.\n");
327 logopts.lopt_dest = logDest_syslog;
328 logopts.lopt_facility = LOG_DAEMON;
329 logopts.lopt_tag = "volserver";
330 cmd_OptionAsInt(opts, OPT_syslog, &logopts.lopt_facility);
334 logopts.lopt_dest = logDest_file;
335 logopts.lopt_rotateOnOpen = 1;
336 logopts.lopt_rotateStyle = logRotate_old;
338 if (cmd_OptionPresent(opts, OPT_logfile))
339 cmd_OptionAsString(opts, OPT_logfile, (char**)&logopts.lopt_filename);
341 logopts.lopt_filename = AFSDIR_SERVER_VOLSERLOG_FILEPATH;
343 cmd_OptionAsInt(opts, OPT_debug, &logopts.lopt_logLevel);
345 cmd_OptionAsInt(opts, OPT_rxmaxmtu, &rxMaxMTU);
346 if (cmd_OptionAsInt(opts, OPT_udpsize, &optval) == 0) {
347 if (optval < rx_GetMinUdpBufSize()) {
348 printf("Warning:udpsize %d is less than minimum %d; ignoring\n",
349 optval, rx_GetMinUdpBufSize());
353 cmd_OptionAsString(opts, OPT_auditlog, &auditFileName);
355 if (cmd_OptionAsString(opts, OPT_audit_interface, &optstring) == 0) {
356 if (osi_audit_interface(optstring)) {
357 printf("Invalid audit interface '%s'\n", optstring);
363 if (cmd_OptionAsInt(opts, OPT_threads, &lwps) == 0) {
365 printf("Warning: '-p %d' is too big; using %d instead\n", lwps, MAXLWP);
369 if (cmd_OptionAsString(opts, OPT_sleep, &sleepSpec) == 0) {
370 printf("Warning: -sleep option ignored; this option is obsolete\n");
372 if (cmd_OptionAsString(opts, OPT_sync, &sync_behavior) == 0) {
373 if (ih_SetSyncBehavior(sync_behavior)) {
374 printf("Invalid -sync value %s\n", sync_behavior);
378 cmd_OptionAsString(opts, OPT_config, &configDir);
379 if (cmd_OptionAsString(opts, OPT_restricted_query,
380 &restricted_query_parameter) == 0) {
381 if (strcmp(restricted_query_parameter, "anyuser") == 0)
382 restrictedQueryLevel = RESTRICTED_QUERY_ANYUSER;
383 else if (strcmp(restricted_query_parameter, "admin") == 0)
384 restrictedQueryLevel = RESTRICTED_QUERY_ADMIN;
386 printf("invalid argument for -restricted_query: %s\n",
387 restricted_query_parameter);
390 free(restricted_query_parameter);
396 #include "AFS_component_version_number.c"
398 main(int argc, char **argv)
401 struct rx_securityClass **securityClasses;
402 afs_int32 numClasses;
403 struct rx_service *service;
405 afs_uint32 host = ntohl(INADDR_ANY);
406 VolumePackageOptions opts;
410 * The following signal action for AIX is necessary so that in case of a
411 * crash (i.e. core is generated) we can include the user's data section
412 * in the core dump. Unfortunately, by default, only a partial core is
413 * generated which, in many cases, isn't too useful.
415 struct sigaction nsa;
417 sigemptyset(&nsa.sa_mask);
418 nsa.sa_handler = SIG_DFL;
419 nsa.sa_flags = SA_FULLDUMP;
420 sigaction(SIGABRT, &nsa, NULL);
421 sigaction(SIGSEGV, &nsa, NULL);
424 osi_audit(VS_StartEvent, 0, AUD_END);
426 /* Initialize dirpaths */
427 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
429 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
431 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
436 configDir = strdup(AFSDIR_SERVER_ETC_DIRPATH);
438 if (ParseArgs(argc, argv)) {
443 osi_audit_file(auditFileName);
444 osi_audit(VS_StartEvent, 0, AUD_END);
446 #ifdef AFS_SGI_VNODE_GLUE
447 if (afs_init_kernel_config(-1) < 0) {
449 ("Can't determine NUMA configuration, not starting volserver.\n");
455 #ifdef AFS_PTHREAD_ENV
456 SetLogThreadNumProgram( rx_GetThreadNum );
460 if (afs_winsockInit() < 0) {
461 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
462 printf("Volume server unable to start winsock, exiting.\n");
469 VOptDefaults(volumeServer, &opts);
470 if (VInitVolumePackage2(volumeServer, &opts)) {
471 Log("Shutting down: errors encountered initializing volume package\n");
475 Lock_Init(&localLock);
477 #ifndef AFS_PTHREAD_ENV
478 vol_PollProc = IOMGR_Poll; /* tell vol pkg to poll io system periodically */
481 rxi_syscallp = volser_syscall;
483 rx_nPackets = rxpackets; /* set the max number of packets */
485 rx_SetUdpBufSize(udpBufSize); /* set the UDP buffer size for receive */
488 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH ||
489 AFSDIR_SERVER_NETINFO_FILEPATH) {
491 ccode = afsconf_ParseNetFiles(SHostAddrs, NULL, NULL,
492 ADDRSPERSITE, reason,
493 AFSDIR_SERVER_NETINFO_FILEPATH,
494 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
497 ccode = rx_getAllAddr(SHostAddrs, ADDRSPERSITE);
500 host = SHostAddrs[0];
503 code = rx_InitHost(host, (int)htons(AFSCONF_VOLUMEPORT));
505 fprintf(stderr, "rx init failed on socket AFSCONF_VOLUMEPORT %u\n",
510 /* Don't allow 3.4 vos clients to send jumbograms and we don't send. */
513 if (rxMaxMTU != -1) {
514 if (rx_SetMaxMTU(rxMaxMTU) != 0) {
515 fprintf(stderr, "rxMaxMTU %d is invalid\n", rxMaxMTU);
520 rx_SetRxDeadTime(420);
521 memset(busyFlags, 0, sizeof(busyFlags));
523 #ifdef AFS_PTHREAD_ENV
525 SetupLogSoftSignals();
531 #ifdef AFS_PTHREAD_ENV
533 pthread_attr_t tattr;
534 opr_Verify(pthread_attr_init(&tattr) == 0);
535 opr_Verify(pthread_attr_setdetachstate(&tattr,
536 PTHREAD_CREATE_DETACHED) == 0);
537 opr_Verify(pthread_create(&tid, &tattr, BKGLoop, NULL) == 0);
540 LWP_CreateProcess(BKGLoop, 16*1024, 3, 0, "vol bkg daemon", &pid);
544 /* 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 */
546 tdir = afsconf_Open(configDir);
548 Abort("volser: could not open conf files in %s\n",
553 /* initialize audit user check */
554 osi_audit_set_user_check(tdir, vol_IsLocalRealmMatch);
556 afsconf_BuildServerSecurityObjects(tdir, &securityClasses, &numClasses);
557 if (securityClasses[0] == NULL)
558 Abort("rxnull_NewServerSecurityObject");
560 rx_NewServiceHost(host, 0, VOLSERVICE_ID, "VOLSER", securityClasses,
561 numClasses, AFSVolExecuteRequest);
562 if (service == (struct rx_service *)0)
563 Abort("rx_NewService");
564 rx_SetBeforeProc(service, MyBeforeProc);
565 rx_SetAfterProc(service, MyAfterProc);
566 rx_SetIdleDeadTime(service, 0); /* never timeout */
569 rx_SetMaxProcs(service, lwps);
570 #if defined(AFS_XBSD_ENV)
571 rx_SetStackSize(service, (128 * 1024));
572 #elif defined(AFS_SGI_ENV)
573 rx_SetStackSize(service, (48 * 1024));
575 rx_SetStackSize(service, (32 * 1024));
578 if (rxkadDisableDotCheck) {
579 rx_SetSecurityConfiguration(service, RXS_CONFIG_FLAGS,
580 (void *)RXS_CONFIG_FLAGS_DISABLE_DOTCHECK);
584 rx_NewService(0, RX_STATS_SERVICE_ID, "rpcstats", securityClasses,
585 numClasses, RXSTATS_ExecuteRequest);
586 if (service == (struct rx_service *)0)
587 Abort("rx_NewService");
588 rx_SetMinProcs(service, 2);
589 rx_SetMaxProcs(service, 4);
591 LogCommandLine(argc, argv, "Volserver", VolserVersion, "Starting AFS",
593 if (afsconf_GetLatestKey(tdir, NULL, NULL) == 0) {
597 /* allow super users to manage RX statistics */
598 rx_SetRxStatUserOk(vol_rxstat_userok);
600 rx_StartServer(1); /* Donate this process to the server process pool */
602 osi_audit(VS_FinishEvent, (-1), AUD_END);
603 Abort("StartServer returned?");
604 return 0; /* not reached */