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>
17 #include <WINNT/afsevent.h>
21 #include <afs/afsint.h>
22 #include <afs/prs_fs.h>
26 #include <afs/afssyscalls.h>
27 #include <afs/ihandle.h>
29 #include <afs/ntops.h>
31 #include <afs/vnode.h>
32 #include <afs/volume.h>
33 #include <afs/partition.h>
35 #include <rx/rxstat.h>
36 #include <rx/rx_globals.h>
38 #include <afs/cellconfig.h>
42 #include <afs/audit.h>
43 #include <afs/afsutil.h>
48 #include "volser_internal.h"
50 #define VolserVersion "2.0"
51 #define N_SECURITY_OBJECTS 3
53 extern struct Lock localLock;
54 char *GlobalNameHack = NULL;
56 afs_int32 GlobalVolCloneId, GlobalVolParentId;
58 int VolumeChanged; /* XXXX */
59 static char busyFlags[MAXHELPERS];
60 struct volser_trans *QI_GlobalWriteTrans = 0;
61 struct afsconf_dir *tdir;
62 static afs_int32 runningCalls = 0;
67 int udpBufSize = 0; /* UDP buffer size for receive */
70 int rxkadDisableDotCheck = 0;
71 int DoPreserveVolumeStats = 0;
73 #define ADDRSPERSITE 16 /* Same global is in rx/rx_user.c */
74 afs_uint32 SHostAddrs[ADDRSPERSITE];
76 #define VS_EXIT(code) { \
77 osi_audit(VS_ExitEvent, code, AUD_END); \
82 MyBeforeProc(struct rx_call *acall)
91 MyAfterProc(struct rx_call *acall, afs_int32 code)
99 /* Called every GCWAKEUP seconds to try to unlock all our partitions,
100 * if we're idle and there are no active transactions
105 /* if there are no running calls, and there are no active transactions, then
106 * it should be safe to release any partition locks we've accumulated */
108 if (runningCalls == 0 && TransList() == (struct volser_trans *)0) {
110 VPFullUnlock(); /* in volprocs.c */
115 /* background daemon for timing out transactions */
117 BKGLoop(void *unused)
122 afs_pthread_setname_self("vol bkg");
124 tv.tv_sec = GCWAKEUP;
126 #ifdef AFS_PTHREAD_ENV
128 Sleep(GCWAKEUP * 1000);
130 select(0, 0, 0, 0, &tv);
133 (void)IOMGR_Select(0, 0, 0, 0, &tv);
138 if (loop == 10) { /* reopen log every 5 minutes */
140 ReOpenLog(AFSDIR_SERVER_VOLSERLOG_FILEPATH);
147 /* Background daemon for sleeping so the volserver does not become I/O bound */
148 afs_int32 TTsleep, TTrun;
149 #ifndef AFS_PTHREAD_ENV
151 BKGSleep(void *unused)
153 struct volser_trans *tt;
157 #ifdef AFS_PTHREAD_ENV
159 #else /* AFS_PTHREAD_ENV */
163 for (tt = TransList(); tt; tt = tt->next) {
165 if ((strcmp(tt->lastProcName, "DeleteVolume") == 0)
166 || (strcmp(tt->lastProcName, "Clone") == 0)
167 || (strcmp(tt->lastProcName, "ReClone") == 0)
168 || (strcmp(tt->lastProcName, "Forward") == 0)
169 || (strcmp(tt->lastProcName, "Restore") == 0)
170 || (strcmp(tt->lastProcName, "ForwardMulti") == 0)) {
171 VTRANS_OBJ_UNLOCK(tt);
174 VTRANS_OBJ_UNLOCK(tt);
188 /* no volser_syscall */
189 #elif defined(AFS_SUN511_ENV)
191 volser_syscall(afs_uint32 a3, afs_uint32 a4, void *a5)
194 code = ioctl_sun_afs_syscall(28 /* AFSCALL_CALL */, a3, a4, a5, 0, 0, 0,
203 volser_syscall(afs_uint32 a3, afs_uint32 a4, void *a5)
206 #ifndef AFS_LINUX20_ENV
209 old = signal(SIGSYS, SIG_IGN);
212 syscall(AFS_SYSCALL /* AFS_SYSCALL */ , 28 /* AFSCALL_CALL */ , a3,
214 #ifndef AFS_LINUX20_ENV
223 /* check whether caller is authorized to manage RX statistics */
225 vol_rxstat_userok(struct rx_call *call)
227 return afsconf_SuperUser(tdir, call, NULL);
231 * Return true if this name is a member of the local realm.
234 vol_IsLocalRealmMatch(void *rock, char *name, char *inst, char *cell)
236 struct afsconf_dir *dir = (struct afsconf_dir *)rock;
237 afs_int32 islocal = 0; /* default to no */
240 code = afsconf_IsLocalRealmMatch(dir, &islocal, name, inst, cell);
243 ("Failed local realm check; code=%d, name=%s, inst=%s, cell=%s\n",
244 code, name, inst, cell));
249 #include "AFS_component_version_number.c"
251 main(int argc, char **argv)
254 struct rx_securityClass **securityClasses;
255 afs_int32 numClasses;
256 struct rx_service *service;
257 struct ktc_encryptionKey tkey;
259 int rxJumbograms = 0; /* default is to send and receive jumbograms. */
261 int bufSize = 0; /* temp variable to read in udp socket buf size */
262 afs_uint32 host = ntohl(INADDR_ANY);
263 char *auditFileName = NULL;
264 VolumePackageOptions opts;
268 * The following signal action for AIX is necessary so that in case of a
269 * crash (i.e. core is generated) we can include the user's data section
270 * in the core dump. Unfortunately, by default, only a partial core is
271 * generated which, in many cases, isn't too useful.
273 struct sigaction nsa;
275 sigemptyset(&nsa.sa_mask);
276 nsa.sa_handler = SIG_DFL;
277 nsa.sa_flags = SA_FULLDUMP;
278 sigaction(SIGABRT, &nsa, NULL);
279 sigaction(SIGSEGV, &nsa, NULL);
282 osi_audit(VS_StartEvent, 0, AUD_END);
284 /* Initialize dirpaths */
285 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
287 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
289 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
297 for (code = 1; code < argc; code++) {
298 if (strcmp(argv[code], "-log") == 0) {
299 /* set extra logging flag */
301 } else if (strcmp(argv[code], "-help") == 0) {
303 } else if (strcmp(argv[code], "-rxbind") == 0) {
305 } else if (strcmp(argv[code], "-allow-dotted-principals") == 0) {
306 rxkadDisableDotCheck = 1;
307 } else if (strcmp(argv[code], "-d") == 0) {
308 if ((code + 1) >= argc) {
309 fprintf(stderr, "missing argument for -d\n");
312 debuglevel = atoi(argv[++code]);
313 LogLevel = debuglevel;
314 } else if (strcmp(argv[code], "-p") == 0) {
315 lwps = atoi(argv[++code]);
317 printf("Warning: '-p %d' is too big; using %d instead\n",
321 } else if (strcmp(argv[code], "-auditlog") == 0) {
322 auditFileName = argv[++code];
324 } else if (strcmp(argv[code], "-audit-interface") == 0) {
325 char *interface = argv[++code];
327 if (osi_audit_interface(interface)) {
328 printf("Invalid audit interface '%s'\n", interface);
331 } else if (strcmp(argv[code], "-nojumbo") == 0) {
333 } else if (strcmp(argv[code], "-jumbo") == 0) {
335 } else if (!strcmp(argv[code], "-rxmaxmtu")) {
336 if ((code + 1) >= argc) {
337 fprintf(stderr, "missing argument for -rxmaxmtu\n");
340 rxMaxMTU = atoi(argv[++code]);
341 } else if (strcmp(argv[code], "-sleep") == 0) {
342 sscanf(argv[++code], "%d/%d", &TTsleep, &TTrun);
343 if ((TTsleep < 0) || (TTrun <= 0)) {
344 printf("Warning: '-sleep %d/%d' is incorrect; ignoring\n",
348 } else if (strcmp(argv[code], "-udpsize") == 0) {
349 if ((code + 1) >= argc) {
350 printf("You have to specify -udpsize <integer value>\n");
353 sscanf(argv[++code], "%d", &bufSize);
354 if (bufSize < rx_GetMinUdpBufSize())
356 ("Warning:udpsize %d is less than minimum %d; ignoring\n",
357 bufSize, rx_GetMinUdpBufSize());
359 udpBufSize = bufSize;
360 } else if (strcmp(argv[code], "-enable_peer_stats") == 0) {
361 rx_enablePeerRPCStats();
362 } else if (strcmp(argv[code], "-enable_process_stats") == 0) {
363 rx_enableProcessRPCStats();
364 } else if (strcmp(argv[code], "-preserve-vol-stats") == 0) {
365 DoPreserveVolumeStats = 1;
368 else if (strcmp(argv[code], "-syslog") == 0) {
369 /* set syslog logging flag */
371 } else if (strncmp(argv[code], "-syslog=", 8) == 0) {
373 serverLogSyslogFacility = atoi(argv[code] + 8);
377 printf("volserver: unrecognized flag '%s'\n", argv[code]);
380 printf("Usage: volserver [-log] [-p <number of processes>] "
381 "[-auditlog <log path>] [-d <debug level>] "
382 "[-nojumbo] [-jumbo] [-rxmaxmtu <bytes>] [-rxbind] [-allow-dotted-principals] "
383 "[-udpsize <size of socket buffer in bytes>] "
384 "[-syslog[=FACILITY]] "
385 "[-enable_peer_stats] [-enable_process_stats] "
388 printf("Usage: volserver [-log] [-p <number of processes>] "
389 "[-auditlog <log path>] [-d <debug level>] "
390 "[-nojumbo] [-jumbo] [-rxmaxmtu <bytes>] [-rxbind] [-allow-dotted-principals] "
391 "[-udpsize <size of socket buffer in bytes>] "
392 "[-enable_peer_stats] [-enable_process_stats] "
400 osi_audit_file(auditFileName);
401 osi_audit(VS_StartEvent, 0, AUD_END);
403 #ifdef AFS_SGI_VNODE_GLUE
404 if (afs_init_kernel_config(-1) < 0) {
406 ("Can't determine NUMA configuration, not starting volserver.\n");
412 #ifdef AFS_PTHREAD_ENV
413 SetLogThreadNumProgram( rx_GetThreadNum );
417 if (afs_winsockInit() < 0) {
418 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
419 printf("Volume server unable to start winsock, exiting.\n");
423 /* Open VolserLog and map stdout, stderr into it; VInitVolumePackage2 can
424 log, so we need to do this here */
425 OpenLog(AFSDIR_SERVER_VOLSERLOG_FILEPATH);
427 VOptDefaults(volumeServer, &opts);
428 if (VInitVolumePackage2(volumeServer, &opts)) {
429 Log("Shutting down: errors encountered initializing volume package\n");
433 Lock_Init(&localLock);
435 #ifndef AFS_PTHREAD_ENV
436 vol_PollProc = IOMGR_Poll; /* tell vol pkg to poll io system periodically */
439 rxi_syscallp = volser_syscall;
441 rx_nPackets = rxpackets; /* set the max number of packets */
443 rx_SetUdpBufSize(udpBufSize); /* set the UDP buffer size for receive */
446 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH ||
447 AFSDIR_SERVER_NETINFO_FILEPATH) {
449 ccode = parseNetFiles(SHostAddrs, NULL, NULL,
450 ADDRSPERSITE, reason,
451 AFSDIR_SERVER_NETINFO_FILEPATH,
452 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
455 ccode = rx_getAllAddr(SHostAddrs, ADDRSPERSITE);
458 host = SHostAddrs[0];
461 code = rx_InitHost(host, (int)htons(AFSCONF_VOLUMEPORT));
463 fprintf(stderr, "rx init failed on socket AFSCONF_VOLUMEPORT %u\n",
468 /* Don't allow 3.4 vos clients to send jumbograms and we don't send. */
471 if (rxMaxMTU != -1) {
472 if (rx_SetMaxMTU(rxMaxMTU) != 0) {
473 fprintf(stderr, "rxMaxMTU %d is invalid\n", rxMaxMTU);
478 rx_SetRxDeadTime(420);
479 memset(busyFlags, 0, sizeof(busyFlags));
484 #ifdef AFS_PTHREAD_ENV
486 pthread_attr_t tattr;
487 osi_Assert(pthread_attr_init(&tattr) == 0);
488 osi_Assert(pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED) == 0);
490 osi_Assert(pthread_create(&tid, &tattr, BKGLoop, NULL) == 0);
493 LWP_CreateProcess(BKGLoop, 16*1024, 3, 0, "vol bkg daemon", &pid);
494 LWP_CreateProcess(BKGSleep,16*1024, 3, 0, "vol slp daemon", &pid);
498 /* 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 */
500 tdir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
502 Abort("volser: could not open conf files in %s\n",
503 AFSDIR_SERVER_ETC_DIRPATH);
507 /* initialize audit user check */
508 osi_audit_set_user_check(tdir, vol_IsLocalRealmMatch);
510 afsconf_GetKey(tdir, 999, &tkey);
511 afsconf_BuildServerSecurityObjects(tdir, &securityClasses, &numClasses);
512 if (securityClasses[0] == NULL)
513 Abort("rxnull_NewServerSecurityObject");
515 rx_NewServiceHost(host, 0, VOLSERVICE_ID, "VOLSER", securityClasses,
516 numClasses, AFSVolExecuteRequest);
517 if (service == (struct rx_service *)0)
518 Abort("rx_NewService");
519 rx_SetBeforeProc(service, MyBeforeProc);
520 rx_SetAfterProc(service, MyAfterProc);
521 rx_SetIdleDeadTime(service, 0); /* never timeout */
524 rx_SetMaxProcs(service, lwps);
525 #if defined(AFS_XBSD_ENV)
526 rx_SetStackSize(service, (128 * 1024));
527 #elif defined(AFS_SGI_ENV)
528 rx_SetStackSize(service, (48 * 1024));
530 rx_SetStackSize(service, (32 * 1024));
533 if (rxkadDisableDotCheck) {
534 rx_SetSecurityConfiguration(service, RXS_CONFIG_FLAGS,
535 (void *)RXS_CONFIG_FLAGS_DISABLE_DOTCHECK);
539 rx_NewService(0, RX_STATS_SERVICE_ID, "rpcstats", securityClasses,
540 numClasses, RXSTATS_ExecuteRequest);
541 if (service == (struct rx_service *)0)
542 Abort("rx_NewService");
543 rx_SetMinProcs(service, 2);
544 rx_SetMaxProcs(service, 4);
546 LogCommandLine(argc, argv, "Volserver", VolserVersion, "Starting AFS",
549 Log("Will sleep %d second%s every %d second%s\n", TTsleep,
550 (TTsleep > 1) ? "s" : "", TTrun + TTsleep,
551 (TTrun + TTsleep > 1) ? "s" : "");
554 /* allow super users to manage RX statistics */
555 rx_SetRxStatUserOk(vol_rxstat_userok);
557 rx_StartServer(1); /* Donate this process to the server process pool */
559 osi_audit(VS_FinishEvent, (-1), AUD_END);
560 Abort("StartServer returned?");
561 return 0; /* not reached */