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 */
73 int restrictedQueryLevel = RESTRICTED_QUERY_ANYUSER;
76 int rxkadDisableDotCheck = 0;
77 int DoPreserveVolumeStats = 0;
78 int rxJumbograms = 0; /* default is to not send and receive jumbograms. */
80 char *auditFileName = NULL;
82 char *configDir = NULL;
84 #define ADDRSPERSITE 16 /* Same global is in rx/rx_user.c */
85 afs_uint32 SHostAddrs[ADDRSPERSITE];
87 #define VS_EXIT(code) { \
88 osi_audit(VS_ExitEvent, code, AUD_END); \
93 MyBeforeProc(struct rx_call *acall)
102 MyAfterProc(struct rx_call *acall, afs_int32 code)
110 /* Called every GCWAKEUP seconds to try to unlock all our partitions,
111 * if we're idle and there are no active transactions
116 /* if there are no running calls, and there are no active transactions, then
117 * it should be safe to release any partition locks we've accumulated */
119 if (runningCalls == 0 && TransList() == (struct volser_trans *)0) {
121 VPFullUnlock(); /* in volprocs.c */
126 /* background daemon for timing out transactions */
128 BKGLoop(void *unused)
133 afs_pthread_setname_self("vol bkg");
135 tv.tv_sec = GCWAKEUP;
137 #ifdef AFS_PTHREAD_ENV
139 Sleep(GCWAKEUP * 1000);
141 select(0, 0, 0, 0, &tv);
144 (void)IOMGR_Select(0, 0, 0, 0, &tv);
149 if (loop == 10) { /* reopen log every 5 minutes */
151 ReOpenLog(AFSDIR_SERVER_VOLSERLOG_FILEPATH);
159 /* no volser_syscall */
160 #elif defined(AFS_SUN511_ENV)
162 volser_syscall(afs_uint32 a3, afs_uint32 a4, void *a5)
165 code = ioctl_sun_afs_syscall(28 /* AFSCALL_CALL */, a3, a4, a5, 0, 0, 0,
174 volser_syscall(afs_uint32 a3, afs_uint32 a4, void *a5)
177 #ifndef AFS_LINUX20_ENV
180 old = signal(SIGSYS, SIG_IGN);
183 syscall(AFS_SYSCALL /* AFS_SYSCALL */ , 28 /* AFSCALL_CALL */ , a3,
185 #ifndef AFS_LINUX20_ENV
194 /* check whether caller is authorized to manage RX statistics */
196 vol_rxstat_userok(struct rx_call *call)
198 return afsconf_SuperUser(tdir, call, NULL);
202 * Return true if this name is a member of the local realm.
205 vol_IsLocalRealmMatch(void *rock, char *name, char *inst, char *cell)
207 struct afsconf_dir *dir = (struct afsconf_dir *)rock;
208 afs_int32 islocal = 0; /* default to no */
211 code = afsconf_IsLocalRealmMatch(dir, &islocal, name, inst, cell);
214 ("Failed local realm check; code=%d, name=%s, inst=%s, cell=%s\n",
215 code, name, inst, cell));
235 OPT_preserve_vol_stats,
244 ParseArgs(int argc, char **argv) {
247 char *optstring = NULL;
248 struct cmd_syndesc *opts;
249 char *sleepSpec = NULL;
250 char *sync_behavior = NULL;
251 char *restricted_query_parameter = NULL;
253 opts = cmd_CreateSyntax(NULL, NULL, NULL, NULL);
254 cmd_AddParmAtOffset(opts, OPT_log, "-log", CMD_FLAG, CMD_OPTIONAL,
256 cmd_AddParmAtOffset(opts, OPT_rxbind, "-rxbind", CMD_FLAG, CMD_OPTIONAL,
257 "bind only to the primary interface");
258 cmd_AddParmAtOffset(opts, OPT_dotted, "-allow-dotted-principals", CMD_FLAG, CMD_OPTIONAL,
259 "permit Kerberos 5 principals with dots");
260 cmd_AddParmAtOffset(opts, OPT_debug, "-d", CMD_SINGLE, CMD_OPTIONAL,
262 cmd_AddParmAtOffset(opts, OPT_threads, "-p", CMD_SINGLE, CMD_OPTIONAL,
263 "number of threads");
264 cmd_AddParmAtOffset(opts, OPT_auditlog, "-auditlog", CMD_SINGLE,
265 CMD_OPTIONAL, "location of audit log");
266 cmd_AddParmAtOffset(opts, OPT_audit_interface, "-audit-interface",
267 CMD_SINGLE, CMD_OPTIONAL, "interface to use for audit logging");
268 cmd_AddParmAtOffset(opts, OPT_nojumbo, "-nojumbo", CMD_FLAG, CMD_OPTIONAL,
269 "disable jumbograms");
270 cmd_AddParmAtOffset(opts, OPT_jumbo, "-jumbo", CMD_FLAG, CMD_OPTIONAL,
271 "enable jumbograms");
272 cmd_AddParmAtOffset(opts, OPT_rxmaxmtu, "-rxmaxmtu", CMD_SINGLE,
273 CMD_OPTIONAL, "maximum MTU for RX");
274 cmd_AddParmAtOffset(opts, OPT_udpsize, "-udpsize", CMD_SINGLE,
275 CMD_OPTIONAL, "size of socket buffer in bytes");
276 cmd_AddParmAtOffset(opts, OPT_sleep, "-sleep", CMD_SINGLE,
277 CMD_OPTIONAL, "make background daemon sleep (LWP only)");
278 cmd_AddParmAtOffset(opts, OPT_peer, "-enable_peer_stats", CMD_FLAG,
279 CMD_OPTIONAL, "enable RX transport statistics");
280 cmd_AddParmAtOffset(opts, OPT_process, "-enable_process_stats", CMD_FLAG,
281 CMD_OPTIONAL, "enable RX RPC statistics");
282 cmd_AddParmAtOffset(opts, OPT_preserve_vol_stats, "-preserve-vol-stats", CMD_FLAG,
283 CMD_OPTIONAL, "preserve volume statistics");
284 #if !defined(AFS_NT40_ENV)
285 cmd_AddParmAtOffset(opts, OPT_syslog, "-syslog", CMD_SINGLE_OR_FLAG,
286 CMD_OPTIONAL, "log to syslog");
288 cmd_AddParmAtOffset(opts, OPT_sync, "-sync",
289 CMD_SINGLE, CMD_OPTIONAL, "always | onclose | never");
290 cmd_AddParmAtOffset(opts, OPT_logfile, "-logfile", CMD_SINGLE,
291 CMD_OPTIONAL, "location of log file");
292 cmd_AddParmAtOffset(opts, OPT_config, "-config", CMD_SINGLE,
293 CMD_OPTIONAL, "configuration location");
294 cmd_AddParmAtOffset(opts, OPT_restricted_query, "-restricted_query",
295 CMD_SINGLE, CMD_OPTIONAL, "anyuser | admin");
297 code = cmd_Parse(argc, argv, &opts);
298 if (code == CMD_HELP) {
304 cmd_OptionAsFlag(opts, OPT_log, &DoLogging);
305 cmd_OptionAsFlag(opts, OPT_rxbind, &rxBind);
306 cmd_OptionAsFlag(opts, OPT_dotted, &rxkadDisableDotCheck);
307 cmd_OptionAsFlag(opts, OPT_preserve_vol_stats, &DoPreserveVolumeStats);
308 cmd_OptionAsInt(opts, OPT_debug, &LogLevel);
309 if (cmd_OptionPresent(opts, OPT_peer))
310 rx_enablePeerRPCStats();
311 if (cmd_OptionPresent(opts, OPT_process))
312 rx_enableProcessRPCStats();
313 if (cmd_OptionPresent(opts, OPT_nojumbo))
315 if (cmd_OptionPresent(opts, OPT_jumbo))
318 if (cmd_OptionPresent(opts, OPT_syslog)) {
320 cmd_OptionAsInt(opts, OPT_syslog, &serverLogSyslogFacility);
323 cmd_OptionAsInt(opts, OPT_rxmaxmtu, &rxMaxMTU);
324 if (cmd_OptionAsInt(opts, OPT_udpsize, &optval) == 0) {
325 if (optval < rx_GetMinUdpBufSize()) {
326 printf("Warning:udpsize %d is less than minimum %d; ignoring\n",
327 optval, rx_GetMinUdpBufSize());
331 cmd_OptionAsString(opts, OPT_auditlog, &auditFileName);
333 if (cmd_OptionAsString(opts, OPT_audit_interface, &optstring) == 0) {
334 if (osi_audit_interface(optstring)) {
335 printf("Invalid audit interface '%s'\n", optstring);
341 if (cmd_OptionAsInt(opts, OPT_threads, &lwps) == 0) {
343 printf("Warning: '-p %d' is too big; using %d instead\n", lwps, MAXLWP);
347 if (cmd_OptionAsString(opts, OPT_sleep, &sleepSpec) == 0) {
348 printf("Warning: -sleep option ignored; this option is obsolete\n");
350 if (cmd_OptionAsString(opts, OPT_sync, &sync_behavior) == 0) {
351 if (ih_SetSyncBehavior(sync_behavior)) {
352 printf("Invalid -sync value %s\n", sync_behavior);
356 cmd_OptionAsString(opts, OPT_logfile, &logFile);
357 cmd_OptionAsString(opts, OPT_config, &configDir);
358 if (cmd_OptionAsString(opts, OPT_restricted_query,
359 &restricted_query_parameter) == 0) {
360 if (strcmp(restricted_query_parameter, "anyuser") == 0)
361 restrictedQueryLevel = RESTRICTED_QUERY_ANYUSER;
362 else if (strcmp(restricted_query_parameter, "admin") == 0)
363 restrictedQueryLevel = RESTRICTED_QUERY_ADMIN;
365 printf("invalid argument for -restricted_query: %s\n",
366 restricted_query_parameter);
369 free(restricted_query_parameter);
375 #include "AFS_component_version_number.c"
377 main(int argc, char **argv)
380 struct rx_securityClass **securityClasses;
381 afs_int32 numClasses;
382 struct rx_service *service;
384 afs_uint32 host = ntohl(INADDR_ANY);
385 VolumePackageOptions opts;
389 * The following signal action for AIX is necessary so that in case of a
390 * crash (i.e. core is generated) we can include the user's data section
391 * in the core dump. Unfortunately, by default, only a partial core is
392 * generated which, in many cases, isn't too useful.
394 struct sigaction nsa;
396 sigemptyset(&nsa.sa_mask);
397 nsa.sa_handler = SIG_DFL;
398 nsa.sa_flags = SA_FULLDUMP;
399 sigaction(SIGABRT, &nsa, NULL);
400 sigaction(SIGSEGV, &nsa, NULL);
403 osi_audit(VS_StartEvent, 0, AUD_END);
405 /* Initialize dirpaths */
406 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
408 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
410 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
415 configDir = strdup(AFSDIR_SERVER_ETC_DIRPATH);
416 logFile = strdup(AFSDIR_SERVER_VOLSERLOG_FILEPATH);
418 if (ParseArgs(argc, argv)) {
423 osi_audit_file(auditFileName);
424 osi_audit(VS_StartEvent, 0, AUD_END);
426 #ifdef AFS_SGI_VNODE_GLUE
427 if (afs_init_kernel_config(-1) < 0) {
429 ("Can't determine NUMA configuration, not starting volserver.\n");
435 #ifdef AFS_PTHREAD_ENV
436 SetLogThreadNumProgram( rx_GetThreadNum );
440 if (afs_winsockInit() < 0) {
441 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
442 printf("Volume server unable to start winsock, exiting.\n");
446 /* Open VolserLog and map stdout, stderr into it; VInitVolumePackage2 can
447 log, so we need to do this here */
450 VOptDefaults(volumeServer, &opts);
451 if (VInitVolumePackage2(volumeServer, &opts)) {
452 Log("Shutting down: errors encountered initializing volume package\n");
456 Lock_Init(&localLock);
458 #ifndef AFS_PTHREAD_ENV
459 vol_PollProc = IOMGR_Poll; /* tell vol pkg to poll io system periodically */
462 rxi_syscallp = volser_syscall;
464 rx_nPackets = rxpackets; /* set the max number of packets */
466 rx_SetUdpBufSize(udpBufSize); /* set the UDP buffer size for receive */
469 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH ||
470 AFSDIR_SERVER_NETINFO_FILEPATH) {
472 ccode = afsconf_ParseNetFiles(SHostAddrs, NULL, NULL,
473 ADDRSPERSITE, reason,
474 AFSDIR_SERVER_NETINFO_FILEPATH,
475 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
478 ccode = rx_getAllAddr(SHostAddrs, ADDRSPERSITE);
481 host = SHostAddrs[0];
484 code = rx_InitHost(host, (int)htons(AFSCONF_VOLUMEPORT));
486 fprintf(stderr, "rx init failed on socket AFSCONF_VOLUMEPORT %u\n",
491 /* Don't allow 3.4 vos clients to send jumbograms and we don't send. */
494 if (rxMaxMTU != -1) {
495 if (rx_SetMaxMTU(rxMaxMTU) != 0) {
496 fprintf(stderr, "rxMaxMTU %d is invalid\n", rxMaxMTU);
501 rx_SetRxDeadTime(420);
502 memset(busyFlags, 0, sizeof(busyFlags));
507 #ifdef AFS_PTHREAD_ENV
509 pthread_attr_t tattr;
510 opr_Verify(pthread_attr_init(&tattr) == 0);
511 opr_Verify(pthread_attr_setdetachstate(&tattr,
512 PTHREAD_CREATE_DETACHED) == 0);
513 opr_Verify(pthread_create(&tid, &tattr, BKGLoop, NULL) == 0);
516 LWP_CreateProcess(BKGLoop, 16*1024, 3, 0, "vol bkg daemon", &pid);
520 /* 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 */
522 tdir = afsconf_Open(configDir);
524 Abort("volser: could not open conf files in %s\n",
529 /* initialize audit user check */
530 osi_audit_set_user_check(tdir, vol_IsLocalRealmMatch);
532 afsconf_BuildServerSecurityObjects(tdir, &securityClasses, &numClasses);
533 if (securityClasses[0] == NULL)
534 Abort("rxnull_NewServerSecurityObject");
536 rx_NewServiceHost(host, 0, VOLSERVICE_ID, "VOLSER", securityClasses,
537 numClasses, AFSVolExecuteRequest);
538 if (service == (struct rx_service *)0)
539 Abort("rx_NewService");
540 rx_SetBeforeProc(service, MyBeforeProc);
541 rx_SetAfterProc(service, MyAfterProc);
542 rx_SetIdleDeadTime(service, 0); /* never timeout */
545 rx_SetMaxProcs(service, lwps);
546 #if defined(AFS_XBSD_ENV)
547 rx_SetStackSize(service, (128 * 1024));
548 #elif defined(AFS_SGI_ENV)
549 rx_SetStackSize(service, (48 * 1024));
551 rx_SetStackSize(service, (32 * 1024));
554 if (rxkadDisableDotCheck) {
555 rx_SetSecurityConfiguration(service, RXS_CONFIG_FLAGS,
556 (void *)RXS_CONFIG_FLAGS_DISABLE_DOTCHECK);
560 rx_NewService(0, RX_STATS_SERVICE_ID, "rpcstats", securityClasses,
561 numClasses, RXSTATS_ExecuteRequest);
562 if (service == (struct rx_service *)0)
563 Abort("rx_NewService");
564 rx_SetMinProcs(service, 2);
565 rx_SetMaxProcs(service, 4);
567 LogCommandLine(argc, argv, "Volserver", VolserVersion, "Starting AFS",
569 if (afsconf_GetLatestKey(tdir, NULL, NULL) == 0) {
573 /* allow super users to manage RX statistics */
574 rx_SetRxStatUserOk(vol_rxstat_userok);
576 rx_StartServer(1); /* Donate this process to the server process pool */
578 osi_audit(VS_FinishEvent, (-1), AUD_END);
579 Abort("StartServer returned?");
580 return 0; /* not reached */