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);
158 /* no volser_syscall */
159 #elif defined(AFS_SUN511_ENV)
161 volser_syscall(afs_uint32 a3, afs_uint32 a4, void *a5)
164 code = ioctl_sun_afs_syscall(28 /* AFSCALL_CALL */, a3, a4, a5, 0, 0, 0,
173 volser_syscall(afs_uint32 a3, afs_uint32 a4, void *a5)
176 #ifndef AFS_LINUX20_ENV
179 old = signal(SIGSYS, SIG_IGN);
182 syscall(AFS_SYSCALL /* AFS_SYSCALL */ , 28 /* AFSCALL_CALL */ , a3,
184 #ifndef AFS_LINUX20_ENV
193 /* check whether caller is authorized to manage RX statistics */
195 vol_rxstat_userok(struct rx_call *call)
197 return afsconf_SuperUser(tdir, call, NULL);
201 * Return true if this name is a member of the local realm.
204 vol_IsLocalRealmMatch(void *rock, char *name, char *inst, char *cell)
206 struct afsconf_dir *dir = (struct afsconf_dir *)rock;
207 afs_int32 islocal = 0; /* default to no */
210 code = afsconf_IsLocalRealmMatch(dir, &islocal, name, inst, cell);
213 ("Failed local realm check; code=%d, name=%s, inst=%s, cell=%s\n",
214 code, name, inst, cell));
234 OPT_preserve_vol_stats,
242 ParseArgs(int argc, char **argv) {
246 struct cmd_syndesc *opts;
250 opts = cmd_CreateSyntax(NULL, NULL, NULL, NULL);
251 cmd_AddParmAtOffset(opts, OPT_log, "-log", CMD_FLAG, CMD_OPTIONAL,
253 cmd_AddParmAtOffset(opts, OPT_rxbind, "-rxbind", CMD_FLAG, CMD_OPTIONAL,
254 "bind only to the primary interface");
255 cmd_AddParmAtOffset(opts, OPT_dotted, "-allow-dotted-principals", CMD_FLAG, CMD_OPTIONAL,
256 "permit Kerberos 5 principals with dots");
257 cmd_AddParmAtOffset(opts, OPT_debug, "-d", CMD_SINGLE, CMD_OPTIONAL,
259 cmd_AddParmAtOffset(opts, OPT_threads, "-p", CMD_SINGLE, CMD_OPTIONAL,
260 "number of threads");
261 cmd_AddParmAtOffset(opts, OPT_auditlog, "-auditlog", CMD_SINGLE,
262 CMD_OPTIONAL, "location of audit log");
263 cmd_AddParmAtOffset(opts, OPT_audit_interface, "-audit-interface",
264 CMD_SINGLE, CMD_OPTIONAL, "interface to use for audit logging");
265 cmd_AddParmAtOffset(opts, OPT_nojumbo, "-nojumbo", CMD_FLAG, CMD_OPTIONAL,
266 "disable jumbograms");
267 cmd_AddParmAtOffset(opts, OPT_jumbo, "-jumbo", CMD_FLAG, CMD_OPTIONAL,
268 "enable jumbograms");
269 cmd_AddParmAtOffset(opts, OPT_rxmaxmtu, "-rxmaxmtu", CMD_SINGLE,
270 CMD_OPTIONAL, "maximum MTU for RX");
271 cmd_AddParmAtOffset(opts, OPT_udpsize, "-udpsize", CMD_SINGLE,
272 CMD_OPTIONAL, "size of socket buffer in bytes");
273 cmd_AddParmAtOffset(opts, OPT_sleep, "-sleep", CMD_SINGLE,
274 CMD_OPTIONAL, "make background daemon sleep (LWP only)");
275 cmd_AddParmAtOffset(opts, OPT_peer, "-enable_peer_stats", CMD_FLAG,
276 CMD_OPTIONAL, "enable RX transport statistics");
277 cmd_AddParmAtOffset(opts, OPT_process, "-enable_process_stats", CMD_FLAG,
278 CMD_OPTIONAL, "enable RX RPC statistics");
279 cmd_AddParmAtOffset(opts, OPT_preserve_vol_stats, "-preserve-vol-stats", CMD_FLAG,
280 CMD_OPTIONAL, "preserve volume statistics");
281 #if !defined(AFS_NT40_ENV)
282 cmd_AddParmAtOffset(opts, OPT_syslog, "-syslog", CMD_SINGLE_OR_FLAG,
283 CMD_OPTIONAL, "log to syslog");
285 cmd_AddParmAtOffset(opts, OPT_sync, "-sync",
286 CMD_SINGLE, CMD_OPTIONAL, "always | onclose | never");
287 cmd_AddParmAtOffset(opts, OPT_logfile, "-logfile", CMD_SINGLE,
288 CMD_OPTIONAL, "location of log file");
289 cmd_AddParmAtOffset(opts, OPT_config, "-config", CMD_SINGLE,
290 CMD_OPTIONAL, "configuration location");
292 code = cmd_Parse(argc, argv, &opts);
293 if (code == CMD_HELP) {
299 cmd_OptionAsFlag(opts, OPT_log, &DoLogging);
300 cmd_OptionAsFlag(opts, OPT_rxbind, &rxBind);
301 cmd_OptionAsFlag(opts, OPT_dotted, &rxkadDisableDotCheck);
302 cmd_OptionAsFlag(opts, OPT_preserve_vol_stats, &DoPreserveVolumeStats);
303 cmd_OptionAsInt(opts, OPT_debug, &LogLevel);
304 if (cmd_OptionPresent(opts, OPT_peer))
305 rx_enablePeerRPCStats();
306 if (cmd_OptionPresent(opts, OPT_process))
307 rx_enableProcessRPCStats();
308 if (cmd_OptionPresent(opts, OPT_nojumbo))
310 if (cmd_OptionPresent(opts, OPT_jumbo))
313 if (cmd_OptionPresent(opts, OPT_syslog)) {
315 cmd_OptionAsInt(opts, OPT_syslog, &serverLogSyslogFacility);
318 cmd_OptionAsInt(opts, OPT_rxmaxmtu, &rxMaxMTU);
319 if (cmd_OptionAsInt(opts, OPT_udpsize, &optval) == 0) {
320 if (optval < rx_GetMinUdpBufSize()) {
321 printf("Warning:udpsize %d is less than minimum %d; ignoring\n",
322 optval, rx_GetMinUdpBufSize());
326 cmd_OptionAsString(opts, OPT_auditlog, &auditFileName);
328 if (cmd_OptionAsString(opts, OPT_audit_interface, &optstring) == 0) {
329 if (osi_audit_interface(optstring)) {
330 printf("Invalid audit interface '%s'\n", optstring);
336 if (cmd_OptionAsInt(opts, OPT_threads, &lwps) == 0) {
338 printf("Warning: '-p %d' is too big; using %d instead\n", lwps, MAXLWP);
342 if (cmd_OptionAsString(opts, OPT_sleep, &sleepSpec) == 0) {
343 printf("Warning: -sleep option ignored; this option is obsolete\n");
345 if (cmd_OptionAsString(opts, OPT_sync, &sync_behavior) == 0) {
346 if (ih_SetSyncBehavior(sync_behavior)) {
347 printf("Invalid -sync value %s\n", sync_behavior);
351 cmd_OptionAsString(opts, OPT_logfile, &logFile);
352 cmd_OptionAsString(opts, OPT_config, &configDir);
357 #include "AFS_component_version_number.c"
359 main(int argc, char **argv)
362 struct rx_securityClass **securityClasses;
363 afs_int32 numClasses;
364 struct rx_service *service;
366 afs_uint32 host = ntohl(INADDR_ANY);
367 VolumePackageOptions opts;
371 * The following signal action for AIX is necessary so that in case of a
372 * crash (i.e. core is generated) we can include the user's data section
373 * in the core dump. Unfortunately, by default, only a partial core is
374 * generated which, in many cases, isn't too useful.
376 struct sigaction nsa;
378 sigemptyset(&nsa.sa_mask);
379 nsa.sa_handler = SIG_DFL;
380 nsa.sa_flags = SA_FULLDUMP;
381 sigaction(SIGABRT, &nsa, NULL);
382 sigaction(SIGSEGV, &nsa, NULL);
385 osi_audit(VS_StartEvent, 0, AUD_END);
387 /* Initialize dirpaths */
388 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
390 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
392 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
397 configDir = strdup(AFSDIR_SERVER_ETC_DIRPATH);
398 logFile = strdup(AFSDIR_SERVER_VOLSERLOG_FILEPATH);
400 if (ParseArgs(argc, argv)) {
405 osi_audit_file(auditFileName);
406 osi_audit(VS_StartEvent, 0, AUD_END);
408 #ifdef AFS_SGI_VNODE_GLUE
409 if (afs_init_kernel_config(-1) < 0) {
411 ("Can't determine NUMA configuration, not starting volserver.\n");
417 #ifdef AFS_PTHREAD_ENV
418 SetLogThreadNumProgram( rx_GetThreadNum );
422 if (afs_winsockInit() < 0) {
423 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
424 printf("Volume server unable to start winsock, exiting.\n");
428 /* Open VolserLog and map stdout, stderr into it; VInitVolumePackage2 can
429 log, so we need to do this here */
432 VOptDefaults(volumeServer, &opts);
433 if (VInitVolumePackage2(volumeServer, &opts)) {
434 Log("Shutting down: errors encountered initializing volume package\n");
438 Lock_Init(&localLock);
440 #ifndef AFS_PTHREAD_ENV
441 vol_PollProc = IOMGR_Poll; /* tell vol pkg to poll io system periodically */
444 rxi_syscallp = volser_syscall;
446 rx_nPackets = rxpackets; /* set the max number of packets */
448 rx_SetUdpBufSize(udpBufSize); /* set the UDP buffer size for receive */
451 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH ||
452 AFSDIR_SERVER_NETINFO_FILEPATH) {
454 ccode = afsconf_ParseNetFiles(SHostAddrs, NULL, NULL,
455 ADDRSPERSITE, reason,
456 AFSDIR_SERVER_NETINFO_FILEPATH,
457 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
460 ccode = rx_getAllAddr(SHostAddrs, ADDRSPERSITE);
463 host = SHostAddrs[0];
466 code = rx_InitHost(host, (int)htons(AFSCONF_VOLUMEPORT));
468 fprintf(stderr, "rx init failed on socket AFSCONF_VOLUMEPORT %u\n",
473 /* Don't allow 3.4 vos clients to send jumbograms and we don't send. */
476 if (rxMaxMTU != -1) {
477 if (rx_SetMaxMTU(rxMaxMTU) != 0) {
478 fprintf(stderr, "rxMaxMTU %d is invalid\n", rxMaxMTU);
483 rx_SetRxDeadTime(420);
484 memset(busyFlags, 0, sizeof(busyFlags));
489 #ifdef AFS_PTHREAD_ENV
491 pthread_attr_t tattr;
492 opr_Verify(pthread_attr_init(&tattr) == 0);
493 opr_Verify(pthread_attr_setdetachstate(&tattr,
494 PTHREAD_CREATE_DETACHED) == 0);
495 opr_Verify(pthread_create(&tid, &tattr, BKGLoop, NULL) == 0);
498 LWP_CreateProcess(BKGLoop, 16*1024, 3, 0, "vol bkg daemon", &pid);
502 /* 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 */
504 tdir = afsconf_Open(configDir);
506 Abort("volser: could not open conf files in %s\n",
511 /* initialize audit user check */
512 osi_audit_set_user_check(tdir, vol_IsLocalRealmMatch);
514 afsconf_BuildServerSecurityObjects(tdir, &securityClasses, &numClasses);
515 if (securityClasses[0] == NULL)
516 Abort("rxnull_NewServerSecurityObject");
518 rx_NewServiceHost(host, 0, VOLSERVICE_ID, "VOLSER", securityClasses,
519 numClasses, AFSVolExecuteRequest);
520 if (service == (struct rx_service *)0)
521 Abort("rx_NewService");
522 rx_SetBeforeProc(service, MyBeforeProc);
523 rx_SetAfterProc(service, MyAfterProc);
524 rx_SetIdleDeadTime(service, 0); /* never timeout */
527 rx_SetMaxProcs(service, lwps);
528 #if defined(AFS_XBSD_ENV)
529 rx_SetStackSize(service, (128 * 1024));
530 #elif defined(AFS_SGI_ENV)
531 rx_SetStackSize(service, (48 * 1024));
533 rx_SetStackSize(service, (32 * 1024));
536 if (rxkadDisableDotCheck) {
537 rx_SetSecurityConfiguration(service, RXS_CONFIG_FLAGS,
538 (void *)RXS_CONFIG_FLAGS_DISABLE_DOTCHECK);
542 rx_NewService(0, RX_STATS_SERVICE_ID, "rpcstats", securityClasses,
543 numClasses, RXSTATS_ExecuteRequest);
544 if (service == (struct rx_service *)0)
545 Abort("rx_NewService");
546 rx_SetMinProcs(service, 2);
547 rx_SetMaxProcs(service, 4);
549 LogCommandLine(argc, argv, "Volserver", VolserVersion, "Starting AFS",
551 if (afsconf_GetLatestKey(tdir, NULL, NULL) == 0) {
555 /* allow super users to manage RX statistics */
556 rx_SetRxStatUserOk(vol_rxstat_userok);
558 rx_StartServer(1); /* Donate this process to the server process pool */
560 osi_audit(VS_FinishEvent, (-1), AUD_END);
561 Abort("StartServer returned?");
562 return 0; /* not reached */