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>
18 #include <WINNT/afsevent.h>
22 #include <rx/rx_queue.h>
23 #include <afs/afsint.h>
24 #include <afs/prs_fs.h>
28 #include <afs/afssyscalls.h>
29 #include <afs/ihandle.h>
31 #include <afs/ntops.h>
33 #include <afs/vnode.h>
34 #include <afs/volume.h>
35 #include <afs/partition.h>
37 #include <rx/rxstat.h>
38 #include <rx/rx_globals.h>
40 #include <afs/cellconfig.h>
44 #include <afs/audit.h>
45 #include <afs/afsutil.h>
50 #include "volser_internal.h"
52 #define VolserVersion "2.0"
53 #define N_SECURITY_OBJECTS 3
55 extern struct Lock localLock;
56 char *GlobalNameHack = NULL;
58 afs_int32 GlobalVolCloneId, GlobalVolParentId;
60 int VolumeChanged; /* XXXX */
61 static char busyFlags[MAXHELPERS];
62 struct volser_trans *QI_GlobalWriteTrans = 0;
63 struct afsconf_dir *tdir;
64 static afs_int32 runningCalls = 0;
69 int udpBufSize = 0; /* UDP buffer size for receive */
72 int rxkadDisableDotCheck = 0;
73 int DoPreserveVolumeStats = 0;
75 #define ADDRSPERSITE 16 /* Same global is in rx/rx_user.c */
76 afs_uint32 SHostAddrs[ADDRSPERSITE];
78 #define VS_EXIT(code) { \
79 osi_audit(VS_ExitEvent, code, AUD_END); \
84 MyBeforeProc(struct rx_call *acall)
93 MyAfterProc(struct rx_call *acall, afs_int32 code)
101 /* Called every GCWAKEUP seconds to try to unlock all our partitions,
102 * if we're idle and there are no active transactions
107 /* if there are no running calls, and there are no active transactions, then
108 * it should be safe to release any partition locks we've accumulated */
110 if (runningCalls == 0 && TransList() == (struct volser_trans *)0) {
112 VPFullUnlock(); /* in volprocs.c */
117 /* background daemon for timing out transactions */
119 BKGLoop(void *unused)
124 afs_pthread_setname_self("vol bkg");
126 tv.tv_sec = GCWAKEUP;
128 #ifdef AFS_PTHREAD_ENV
130 Sleep(GCWAKEUP * 1000);
132 select(0, 0, 0, 0, &tv);
135 (void)IOMGR_Select(0, 0, 0, 0, &tv);
140 if (loop == 10) { /* reopen log every 5 minutes */
142 ReOpenLog(AFSDIR_SERVER_VOLSERLOG_FILEPATH);
149 /* Background daemon for sleeping so the volserver does not become I/O bound */
150 afs_int32 TTsleep, TTrun;
151 #ifndef AFS_PTHREAD_ENV
153 BKGSleep(void *unused)
155 struct volser_trans *tt;
159 #ifdef AFS_PTHREAD_ENV
161 #else /* AFS_PTHREAD_ENV */
165 for (tt = TransList(); tt; tt = tt->next) {
167 if ((strcmp(tt->lastProcName, "DeleteVolume") == 0)
168 || (strcmp(tt->lastProcName, "Clone") == 0)
169 || (strcmp(tt->lastProcName, "ReClone") == 0)
170 || (strcmp(tt->lastProcName, "Forward") == 0)
171 || (strcmp(tt->lastProcName, "Restore") == 0)
172 || (strcmp(tt->lastProcName, "ForwardMulti") == 0)) {
173 VTRANS_OBJ_UNLOCK(tt);
176 VTRANS_OBJ_UNLOCK(tt);
190 /* no volser_syscall */
191 #elif defined(AFS_SUN511_ENV)
193 volser_syscall(afs_uint32 a3, afs_uint32 a4, void *a5)
196 code = ioctl_sun_afs_syscall(28 /* AFSCALL_CALL */, a3, a4, a5, 0, 0, 0,
205 volser_syscall(afs_uint32 a3, afs_uint32 a4, void *a5)
208 #ifndef AFS_LINUX20_ENV
211 old = signal(SIGSYS, SIG_IGN);
214 syscall(AFS_SYSCALL /* AFS_SYSCALL */ , 28 /* AFSCALL_CALL */ , a3,
216 #ifndef AFS_LINUX20_ENV
225 /* check whether caller is authorized to manage RX statistics */
227 vol_rxstat_userok(struct rx_call *call)
229 return afsconf_SuperUser(tdir, call, NULL);
233 * Return true if this name is a member of the local realm.
236 vol_IsLocalRealmMatch(void *rock, char *name, char *inst, char *cell)
238 struct afsconf_dir *dir = (struct afsconf_dir *)rock;
239 afs_int32 islocal = 0; /* default to no */
242 code = afsconf_IsLocalRealmMatch(dir, &islocal, name, inst, cell);
245 ("Failed local realm check; code=%d, name=%s, inst=%s, cell=%s\n",
246 code, name, inst, cell));
251 #include "AFS_component_version_number.c"
253 main(int argc, char **argv)
256 struct rx_securityClass **securityClasses;
257 afs_int32 numClasses;
258 struct rx_service *service;
259 struct ktc_encryptionKey tkey;
261 int rxJumbograms = 0; /* default is to send and receive jumbograms. */
263 int bufSize = 0; /* temp variable to read in udp socket buf size */
264 afs_uint32 host = ntohl(INADDR_ANY);
265 char *auditFileName = NULL;
266 VolumePackageOptions opts;
270 * The following signal action for AIX is necessary so that in case of a
271 * crash (i.e. core is generated) we can include the user's data section
272 * in the core dump. Unfortunately, by default, only a partial core is
273 * generated which, in many cases, isn't too useful.
275 struct sigaction nsa;
277 sigemptyset(&nsa.sa_mask);
278 nsa.sa_handler = SIG_DFL;
279 nsa.sa_flags = SA_FULLDUMP;
280 sigaction(SIGABRT, &nsa, NULL);
281 sigaction(SIGSEGV, &nsa, NULL);
284 osi_audit(VS_StartEvent, 0, AUD_END);
286 /* Initialize dirpaths */
287 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
289 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
291 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
299 for (code = 1; code < argc; code++) {
300 if (strcmp(argv[code], "-log") == 0) {
301 /* set extra logging flag */
303 } else if (strcmp(argv[code], "-help") == 0) {
305 } else if (strcmp(argv[code], "-rxbind") == 0) {
307 } else if (strcmp(argv[code], "-allow-dotted-principals") == 0) {
308 rxkadDisableDotCheck = 1;
309 } else if (strcmp(argv[code], "-d") == 0) {
310 if ((code + 1) >= argc) {
311 fprintf(stderr, "missing argument for -d\n");
314 debuglevel = atoi(argv[++code]);
315 LogLevel = debuglevel;
316 } else if (strcmp(argv[code], "-p") == 0) {
317 lwps = atoi(argv[++code]);
319 printf("Warning: '-p %d' is too big; using %d instead\n",
323 } else if (strcmp(argv[code], "-auditlog") == 0) {
324 auditFileName = argv[++code];
326 } else if (strcmp(argv[code], "-audit-interface") == 0) {
327 char *interface = argv[++code];
329 if (osi_audit_interface(interface)) {
330 printf("Invalid audit interface '%s'\n", interface);
333 } else if (strcmp(argv[code], "-nojumbo") == 0) {
335 } else if (strcmp(argv[code], "-jumbo") == 0) {
337 } else if (!strcmp(argv[code], "-rxmaxmtu")) {
338 if ((code + 1) >= argc) {
339 fprintf(stderr, "missing argument for -rxmaxmtu\n");
342 rxMaxMTU = atoi(argv[++code]);
343 } else if (strcmp(argv[code], "-sleep") == 0) {
344 sscanf(argv[++code], "%d/%d", &TTsleep, &TTrun);
345 if ((TTsleep < 0) || (TTrun <= 0)) {
346 printf("Warning: '-sleep %d/%d' is incorrect; ignoring\n",
350 } else if (strcmp(argv[code], "-udpsize") == 0) {
351 if ((code + 1) >= argc) {
352 printf("You have to specify -udpsize <integer value>\n");
355 sscanf(argv[++code], "%d", &bufSize);
356 if (bufSize < rx_GetMinUdpBufSize())
358 ("Warning:udpsize %d is less than minimum %d; ignoring\n",
359 bufSize, rx_GetMinUdpBufSize());
361 udpBufSize = bufSize;
362 } else if (strcmp(argv[code], "-enable_peer_stats") == 0) {
363 rx_enablePeerRPCStats();
364 } else if (strcmp(argv[code], "-enable_process_stats") == 0) {
365 rx_enableProcessRPCStats();
366 } else if (strcmp(argv[code], "-preserve-vol-stats") == 0) {
367 DoPreserveVolumeStats = 1;
370 else if (strcmp(argv[code], "-syslog") == 0) {
371 /* set syslog logging flag */
373 } else if (strncmp(argv[code], "-syslog=", 8) == 0) {
375 serverLogSyslogFacility = atoi(argv[code] + 8);
379 printf("volserver: unrecognized flag '%s'\n", argv[code]);
382 printf("Usage: volserver [-log] [-p <number of processes>] "
383 "[-auditlog <log path>] [-d <debug level>] "
384 "[-nojumbo] [-jumbo] [-rxmaxmtu <bytes>] [-rxbind] [-allow-dotted-principals] "
385 "[-udpsize <size of socket buffer in bytes>] "
386 "[-syslog[=FACILITY]] "
387 "[-enable_peer_stats] [-enable_process_stats] "
390 printf("Usage: volserver [-log] [-p <number of processes>] "
391 "[-auditlog <log path>] [-d <debug level>] "
392 "[-nojumbo] [-jumbo] [-rxmaxmtu <bytes>] [-rxbind] [-allow-dotted-principals] "
393 "[-udpsize <size of socket buffer in bytes>] "
394 "[-enable_peer_stats] [-enable_process_stats] "
402 osi_audit_file(auditFileName);
403 osi_audit(VS_StartEvent, 0, AUD_END);
405 #ifdef AFS_SGI_VNODE_GLUE
406 if (afs_init_kernel_config(-1) < 0) {
408 ("Can't determine NUMA configuration, not starting volserver.\n");
414 #ifdef AFS_PTHREAD_ENV
415 SetLogThreadNumProgram( rx_GetThreadNum );
419 if (afs_winsockInit() < 0) {
420 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
421 printf("Volume server unable to start winsock, exiting.\n");
425 /* Open VolserLog and map stdout, stderr into it; VInitVolumePackage2 can
426 log, so we need to do this here */
427 OpenLog(AFSDIR_SERVER_VOLSERLOG_FILEPATH);
429 VOptDefaults(volumeServer, &opts);
430 if (VInitVolumePackage2(volumeServer, &opts)) {
431 Log("Shutting down: errors encountered initializing volume package\n");
435 Lock_Init(&localLock);
437 #ifndef AFS_PTHREAD_ENV
438 vol_PollProc = IOMGR_Poll; /* tell vol pkg to poll io system periodically */
441 rxi_syscallp = volser_syscall;
443 rx_nPackets = rxpackets; /* set the max number of packets */
445 rx_SetUdpBufSize(udpBufSize); /* set the UDP buffer size for receive */
448 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH ||
449 AFSDIR_SERVER_NETINFO_FILEPATH) {
451 ccode = afsconf_ParseNetFiles(SHostAddrs, NULL, NULL,
452 ADDRSPERSITE, reason,
453 AFSDIR_SERVER_NETINFO_FILEPATH,
454 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
457 ccode = rx_getAllAddr(SHostAddrs, ADDRSPERSITE);
460 host = SHostAddrs[0];
463 code = rx_InitHost(host, (int)htons(AFSCONF_VOLUMEPORT));
465 fprintf(stderr, "rx init failed on socket AFSCONF_VOLUMEPORT %u\n",
470 /* Don't allow 3.4 vos clients to send jumbograms and we don't send. */
473 if (rxMaxMTU != -1) {
474 if (rx_SetMaxMTU(rxMaxMTU) != 0) {
475 fprintf(stderr, "rxMaxMTU %d is invalid\n", rxMaxMTU);
480 rx_SetRxDeadTime(420);
481 memset(busyFlags, 0, sizeof(busyFlags));
486 #ifdef AFS_PTHREAD_ENV
488 pthread_attr_t tattr;
489 opr_Verify(pthread_attr_init(&tattr) == 0);
490 opr_Verify(pthread_attr_setdetachstate(&tattr,
491 PTHREAD_CREATE_DETACHED) == 0);
492 opr_Verify(pthread_create(&tid, &tattr, BKGLoop, NULL) == 0);
495 LWP_CreateProcess(BKGLoop, 16*1024, 3, 0, "vol bkg daemon", &pid);
496 LWP_CreateProcess(BKGSleep,16*1024, 3, 0, "vol slp daemon", &pid);
500 /* 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 */
502 tdir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
504 Abort("volser: could not open conf files in %s\n",
505 AFSDIR_SERVER_ETC_DIRPATH);
509 /* initialize audit user check */
510 osi_audit_set_user_check(tdir, vol_IsLocalRealmMatch);
512 afsconf_GetKey(tdir, 999, &tkey);
513 afsconf_BuildServerSecurityObjects(tdir, &securityClasses, &numClasses);
514 if (securityClasses[0] == NULL)
515 Abort("rxnull_NewServerSecurityObject");
517 rx_NewServiceHost(host, 0, VOLSERVICE_ID, "VOLSER", securityClasses,
518 numClasses, AFSVolExecuteRequest);
519 if (service == (struct rx_service *)0)
520 Abort("rx_NewService");
521 rx_SetBeforeProc(service, MyBeforeProc);
522 rx_SetAfterProc(service, MyAfterProc);
523 rx_SetIdleDeadTime(service, 0); /* never timeout */
526 rx_SetMaxProcs(service, lwps);
527 #if defined(AFS_XBSD_ENV)
528 rx_SetStackSize(service, (128 * 1024));
529 #elif defined(AFS_SGI_ENV)
530 rx_SetStackSize(service, (48 * 1024));
532 rx_SetStackSize(service, (32 * 1024));
535 if (rxkadDisableDotCheck) {
536 rx_SetSecurityConfiguration(service, RXS_CONFIG_FLAGS,
537 (void *)RXS_CONFIG_FLAGS_DISABLE_DOTCHECK);
541 rx_NewService(0, RX_STATS_SERVICE_ID, "rpcstats", securityClasses,
542 numClasses, RXSTATS_ExecuteRequest);
543 if (service == (struct rx_service *)0)
544 Abort("rx_NewService");
545 rx_SetMinProcs(service, 2);
546 rx_SetMaxProcs(service, 4);
548 LogCommandLine(argc, argv, "Volserver", VolserVersion, "Starting AFS",
551 Log("Will sleep %d second%s every %d second%s\n", TTsleep,
552 (TTsleep > 1) ? "s" : "", TTrun + TTsleep,
553 (TTrun + TTsleep > 1) ? "s" : "");
556 /* allow super users to manage RX statistics */
557 rx_SetRxStatUserOk(vol_rxstat_userok);
559 rx_StartServer(1); /* Donate this process to the server process pool */
561 osi_audit(VS_FinishEvent, (-1), AUD_END);
562 Abort("StartServer returned?");
563 return 0; /* not reached */