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;
72 #define ADDRSPERSITE 16 /* Same global is in rx/rx_user.c */
73 afs_uint32 SHostAddrs[ADDRSPERSITE];
75 #define VS_EXIT(code) { \
76 osi_audit(VS_ExitEvent, code, AUD_END); \
81 MyBeforeProc(struct rx_call *acall)
90 MyAfterProc(struct rx_call *acall, afs_int32 code)
98 /* Called every GCWAKEUP seconds to try to unlock all our partitions,
99 * if we're idle and there are no active transactions
104 /* if there are no running calls, and there are no active transactions, then
105 * it should be safe to release any partition locks we've accumulated */
107 if (runningCalls == 0 && TransList() == (struct volser_trans *)0) {
109 VPFullUnlock(); /* in volprocs.c */
114 /* background daemon for timing out transactions */
116 BKGLoop(void *unused)
121 afs_pthread_setname_self("vol bkg");
123 tv.tv_sec = GCWAKEUP;
125 #ifdef AFS_PTHREAD_ENV
127 Sleep(GCWAKEUP * 1000);
129 select(0, 0, 0, 0, &tv);
132 (void)IOMGR_Select(0, 0, 0, 0, &tv);
137 if (loop == 10) { /* reopen log every 5 minutes */
139 ReOpenLog(AFSDIR_SERVER_VOLSERLOG_FILEPATH);
146 /* Background daemon for sleeping so the volserver does not become I/O bound */
147 afs_int32 TTsleep, TTrun;
148 #ifndef AFS_PTHREAD_ENV
150 BKGSleep(void *unused)
152 struct volser_trans *tt;
156 #ifdef AFS_PTHREAD_ENV
158 #else /* AFS_PTHREAD_ENV */
162 for (tt = TransList(); tt; tt = tt->next) {
164 if ((strcmp(tt->lastProcName, "DeleteVolume") == 0)
165 || (strcmp(tt->lastProcName, "Clone") == 0)
166 || (strcmp(tt->lastProcName, "ReClone") == 0)
167 || (strcmp(tt->lastProcName, "Forward") == 0)
168 || (strcmp(tt->lastProcName, "Restore") == 0)
169 || (strcmp(tt->lastProcName, "ForwardMulti") == 0)) {
170 VTRANS_OBJ_UNLOCK(tt);
173 VTRANS_OBJ_UNLOCK(tt);
187 /* no volser_syscall */
188 #elif defined(AFS_SUN511_ENV)
190 volser_syscall(afs_uint32 a3, afs_uint32 a4, void *a5)
193 code = ioctl_sun_afs_syscall(28 /* AFSCALL_CALL */, a3, a4, a5, 0, 0, 0,
202 volser_syscall(afs_uint32 a3, afs_uint32 a4, void *a5)
205 #ifndef AFS_LINUX20_ENV
208 old = signal(SIGSYS, SIG_IGN);
211 syscall(AFS_SYSCALL /* AFS_SYSCALL */ , 28 /* AFSCALL_CALL */ , a3,
213 #ifndef AFS_LINUX20_ENV
222 /* check whether caller is authorized to manage RX statistics */
224 vol_rxstat_userok(struct rx_call *call)
226 return afsconf_SuperUser(tdir, call, NULL);
230 * Return true if this name is a member of the local realm.
233 vol_IsLocalRealmMatch(void *rock, char *name, char *inst, char *cell)
235 struct afsconf_dir *dir = (struct afsconf_dir *)rock;
236 afs_int32 islocal = 0; /* default to no */
239 code = afsconf_IsLocalRealmMatch(dir, &islocal, name, inst, cell);
242 ("Failed local realm check; code=%d, name=%s, inst=%s, cell=%s\n",
243 code, name, inst, cell));
248 #include "AFS_component_version_number.c"
250 main(int argc, char **argv)
253 struct rx_securityClass **securityClasses;
254 afs_int32 numClasses;
255 struct rx_service *service;
256 struct ktc_encryptionKey tkey;
258 int rxJumbograms = 0; /* default is to send and receive jumbograms. */
260 int bufSize = 0; /* temp variable to read in udp socket buf size */
261 afs_uint32 host = ntohl(INADDR_ANY);
262 char *auditFileName = NULL;
263 VolumePackageOptions opts;
267 * The following signal action for AIX is necessary so that in case of a
268 * crash (i.e. core is generated) we can include the user's data section
269 * in the core dump. Unfortunately, by default, only a partial core is
270 * generated which, in many cases, isn't too useful.
272 struct sigaction nsa;
274 sigemptyset(&nsa.sa_mask);
275 nsa.sa_handler = SIG_DFL;
276 nsa.sa_flags = SA_FULLDUMP;
277 sigaction(SIGABRT, &nsa, NULL);
278 sigaction(SIGSEGV, &nsa, NULL);
281 osi_audit(VS_StartEvent, 0, AUD_END);
283 /* Initialize dirpaths */
284 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
286 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
288 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
296 for (code = 1; code < argc; code++) {
297 if (strcmp(argv[code], "-log") == 0) {
298 /* set extra logging flag */
300 } else if (strcmp(argv[code], "-help") == 0) {
302 } else if (strcmp(argv[code], "-rxbind") == 0) {
304 } else if (strcmp(argv[code], "-allow-dotted-principals") == 0) {
305 rxkadDisableDotCheck = 1;
306 } else if (strcmp(argv[code], "-d") == 0) {
307 if ((code + 1) >= argc) {
308 fprintf(stderr, "missing argument for -d\n");
311 debuglevel = atoi(argv[++code]);
312 LogLevel = debuglevel;
313 } else if (strcmp(argv[code], "-p") == 0) {
314 lwps = atoi(argv[++code]);
316 printf("Warning: '-p %d' is too big; using %d instead\n",
320 } else if (strcmp(argv[code], "-auditlog") == 0) {
321 auditFileName = argv[++code];
323 } else if (strcmp(argv[code], "-audit-interface") == 0) {
324 char *interface = argv[++code];
326 if (osi_audit_interface(interface)) {
327 printf("Invalid audit interface '%s'\n", interface);
330 } else if (strcmp(argv[code], "-nojumbo") == 0) {
332 } else if (strcmp(argv[code], "-jumbo") == 0) {
334 } else if (!strcmp(argv[code], "-rxmaxmtu")) {
335 if ((code + 1) >= argc) {
336 fprintf(stderr, "missing argument for -rxmaxmtu\n");
339 rxMaxMTU = atoi(argv[++code]);
340 } else if (strcmp(argv[code], "-sleep") == 0) {
341 sscanf(argv[++code], "%d/%d", &TTsleep, &TTrun);
342 if ((TTsleep < 0) || (TTrun <= 0)) {
343 printf("Warning: '-sleep %d/%d' is incorrect; ignoring\n",
347 } else if (strcmp(argv[code], "-udpsize") == 0) {
348 if ((code + 1) >= argc) {
349 printf("You have to specify -udpsize <integer value>\n");
352 sscanf(argv[++code], "%d", &bufSize);
353 if (bufSize < rx_GetMinUdpBufSize())
355 ("Warning:udpsize %d is less than minimum %d; ignoring\n",
356 bufSize, rx_GetMinUdpBufSize());
358 udpBufSize = bufSize;
359 } else if (strcmp(argv[code], "-enable_peer_stats") == 0) {
360 rx_enablePeerRPCStats();
361 } else if (strcmp(argv[code], "-enable_process_stats") == 0) {
362 rx_enableProcessRPCStats();
365 else if (strcmp(argv[code], "-syslog") == 0) {
366 /* set syslog logging flag */
368 } else if (strncmp(argv[code], "-syslog=", 8) == 0) {
370 serverLogSyslogFacility = atoi(argv[code] + 8);
374 printf("volserver: unrecognized flag '%s'\n", argv[code]);
377 printf("Usage: volserver [-log] [-p <number of processes>] "
378 "[-auditlog <log path>] [-d <debug level>] "
379 "[-nojumbo] [-jumbo] [-rxmaxmtu <bytes>] [-rxbind] [-allow-dotted-principals] "
380 "[-udpsize <size of socket buffer in bytes>] "
381 "[-syslog[=FACILITY]] "
382 "[-enable_peer_stats] [-enable_process_stats] "
385 printf("Usage: volserver [-log] [-p <number of processes>] "
386 "[-auditlog <log path>] [-d <debug level>] "
387 "[-nojumbo] [-jumbo] [-rxmaxmtu <bytes>] [-rxbind] [-allow-dotted-principals] "
388 "[-udpsize <size of socket buffer in bytes>] "
389 "[-enable_peer_stats] [-enable_process_stats] "
397 osi_audit_file(auditFileName);
398 osi_audit(VS_StartEvent, 0, AUD_END);
400 #ifdef AFS_SGI_VNODE_GLUE
401 if (afs_init_kernel_config(-1) < 0) {
403 ("Can't determine NUMA configuration, not starting volserver.\n");
409 #ifdef AFS_PTHREAD_ENV
410 SetLogThreadNumProgram( rx_GetThreadNum );
414 if (afs_winsockInit() < 0) {
415 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
416 printf("Volume server unable to start winsock, exiting.\n");
420 /* Open VolserLog and map stdout, stderr into it; VInitVolumePackage2 can
421 log, so we need to do this here */
422 OpenLog(AFSDIR_SERVER_VOLSERLOG_FILEPATH);
424 VOptDefaults(volumeServer, &opts);
425 if (VInitVolumePackage2(volumeServer, &opts)) {
426 Log("Shutting down: errors encountered initializing volume package\n");
430 Lock_Init(&localLock);
432 #ifndef AFS_PTHREAD_ENV
433 vol_PollProc = IOMGR_Poll; /* tell vol pkg to poll io system periodically */
436 rxi_syscallp = volser_syscall;
438 rx_nPackets = rxpackets; /* set the max number of packets */
440 rx_SetUdpBufSize(udpBufSize); /* set the UDP buffer size for receive */
443 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH ||
444 AFSDIR_SERVER_NETINFO_FILEPATH) {
446 ccode = parseNetFiles(SHostAddrs, NULL, NULL,
447 ADDRSPERSITE, reason,
448 AFSDIR_SERVER_NETINFO_FILEPATH,
449 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
452 ccode = rx_getAllAddr(SHostAddrs, ADDRSPERSITE);
455 host = SHostAddrs[0];
458 code = rx_InitHost(host, (int)htons(AFSCONF_VOLUMEPORT));
460 fprintf(stderr, "rx init failed on socket AFSCONF_VOLUMEPORT %u\n",
465 /* Don't allow 3.4 vos clients to send jumbograms and we don't send. */
468 if (rxMaxMTU != -1) {
469 if (rx_SetMaxMTU(rxMaxMTU) != 0) {
470 fprintf(stderr, "rxMaxMTU %d is invalid\n", rxMaxMTU);
475 rx_SetRxDeadTime(420);
476 memset(busyFlags, 0, sizeof(busyFlags));
481 #ifdef AFS_PTHREAD_ENV
483 pthread_attr_t tattr;
484 osi_Assert(pthread_attr_init(&tattr) == 0);
485 osi_Assert(pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED) == 0);
487 osi_Assert(pthread_create(&tid, &tattr, BKGLoop, NULL) == 0);
490 LWP_CreateProcess(BKGLoop, 16*1024, 3, 0, "vol bkg daemon", &pid);
491 LWP_CreateProcess(BKGSleep,16*1024, 3, 0, "vol slp daemon", &pid);
495 /* 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 */
497 tdir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
499 Abort("volser: could not open conf files in %s\n",
500 AFSDIR_SERVER_ETC_DIRPATH);
504 /* initialize audit user check */
505 osi_audit_set_user_check(tdir, vol_IsLocalRealmMatch);
507 afsconf_GetKey(tdir, 999, &tkey);
508 afsconf_BuildServerSecurityObjects(tdir, &securityClasses, &numClasses);
509 if (securityClasses[0] == NULL)
510 Abort("rxnull_NewServerSecurityObject");
512 rx_NewServiceHost(host, 0, VOLSERVICE_ID, "VOLSER", securityClasses,
513 numClasses, AFSVolExecuteRequest);
514 if (service == (struct rx_service *)0)
515 Abort("rx_NewService");
516 rx_SetBeforeProc(service, MyBeforeProc);
517 rx_SetAfterProc(service, MyAfterProc);
518 rx_SetIdleDeadTime(service, 0); /* never timeout */
521 rx_SetMaxProcs(service, lwps);
522 #if defined(AFS_XBSD_ENV)
523 rx_SetStackSize(service, (128 * 1024));
524 #elif defined(AFS_SGI_ENV)
525 rx_SetStackSize(service, (48 * 1024));
527 rx_SetStackSize(service, (32 * 1024));
530 if (rxkadDisableDotCheck) {
531 rx_SetSecurityConfiguration(service, RXS_CONFIG_FLAGS,
532 (void *)RXS_CONFIG_FLAGS_DISABLE_DOTCHECK);
536 rx_NewService(0, RX_STATS_SERVICE_ID, "rpcstats", securityClasses,
537 numClasses, RXSTATS_ExecuteRequest);
538 if (service == (struct rx_service *)0)
539 Abort("rx_NewService");
540 rx_SetMinProcs(service, 2);
541 rx_SetMaxProcs(service, 4);
543 LogCommandLine(argc, argv, "Volserver", VolserVersion, "Starting AFS",
546 Log("Will sleep %d second%s every %d second%s\n", TTsleep,
547 (TTsleep > 1) ? "s" : "", TTrun + TTsleep,
548 (TTrun + TTsleep > 1) ? "s" : "");
551 /* allow super users to manage RX statistics */
552 rx_SetRxStatUserOk(vol_rxstat_userok);
554 rx_StartServer(1); /* Donate this process to the server process pool */
556 osi_audit(VS_FinishEvent, (-1), AUD_END);
557 Abort("StartServer returned?");
558 return 0; /* not reached */