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 #include <sys/types.h>
24 #include <WINNT/afsevent.h>
28 #include <netinet/in.h>
32 #include <afs/afsint.h>
35 #include <afs/afs_assert.h>
36 #include <afs/prs_fs.h>
40 #include <afs/afssyscalls.h>
41 #include <afs/ihandle.h>
43 #include <afs/ntops.h>
45 #include <afs/vnode.h>
46 #include <afs/volume.h>
47 #include <afs/partition.h>
49 #include <rx/rxstat.h>
50 #include <rx/rx_globals.h>
52 #include <afs/cellconfig.h>
60 #include <afs/audit.h>
61 #include <afs/afsutil.h>
65 #include "volser_internal.h"
67 /*@printflike@*/ extern void Log(const char *format, ...);
68 /*@printflike@*/ extern void Abort(const char *format, ...);
70 #define VolserVersion "2.0"
71 #define N_SECURITY_OBJECTS 3
73 extern struct Lock localLock;
74 char *GlobalNameHack = NULL;
76 afs_int32 GlobalVolCloneId, GlobalVolParentId;
78 int VolumeChanged; /* XXXX */
79 static char busyFlags[MAXHELPERS];
80 struct volser_trans *QI_GlobalWriteTrans = 0;
81 struct afsconf_dir *tdir;
82 static afs_int32 runningCalls = 0;
87 int udpBufSize = 0; /* UDP buffer size for receive */
90 int rxkadDisableDotCheck = 0;
92 #define ADDRSPERSITE 16 /* Same global is in rx/rx_user.c */
93 afs_uint32 SHostAddrs[ADDRSPERSITE];
95 #define VS_EXIT(code) { \
96 osi_audit(VS_ExitEvent, code, AUD_END); \
100 #if defined(AFS_PTHREAD_ENV)
104 return (intptr_t)pthread_getspecific(rx_thread_id_key);
109 MyBeforeProc(struct rx_call *acall)
118 MyAfterProc(struct rx_call *acall, afs_int32 code)
126 /* Called every GCWAKEUP seconds to try to unlock all our partitions,
127 * if we're idle and there are no active transactions
132 /* if there are no running calls, and there are no active transactions, then
133 * it should be safe to release any partition locks we've accumulated */
135 if (runningCalls == 0 && TransList() == (struct volser_trans *)0) {
137 VPFullUnlock(); /* in volprocs.c */
142 /* background daemon for timing out transactions */
144 BKGLoop(void *unused)
150 tv.tv_sec = GCWAKEUP;
152 #ifdef AFS_PTHREAD_ENV
153 select(0, 0, 0, 0, &tv);
155 (void)IOMGR_Select(0, 0, 0, 0, &tv);
160 if (loop == 10) { /* reopen log every 5 minutes */
162 ReOpenLog(AFSDIR_SERVER_VOLSERLOG_FILEPATH);
169 /* Background daemon for sleeping so the volserver does not become I/O bound */
170 afs_int32 TTsleep, TTrun;
171 #ifndef AFS_PTHREAD_ENV
173 BKGSleep(void *unused)
175 struct volser_trans *tt;
179 #ifdef AFS_PTHREAD_ENV
181 #else /* AFS_PTHREAD_ENV */
185 for (tt = TransList(); tt; tt = tt->next) {
187 if ((strcmp(tt->lastProcName, "DeleteVolume") == 0)
188 || (strcmp(tt->lastProcName, "Clone") == 0)
189 || (strcmp(tt->lastProcName, "ReClone") == 0)
190 || (strcmp(tt->lastProcName, "Forward") == 0)
191 || (strcmp(tt->lastProcName, "Restore") == 0)
192 || (strcmp(tt->lastProcName, "ForwardMulti") == 0)) {
193 VTRANS_OBJ_UNLOCK(tt);
196 VTRANS_OBJ_UNLOCK(tt);
210 /* no volser_syscall */
211 #elif defined(AFS_SUN511_ENV)
213 volser_syscall(afs_uint32 a3, afs_uint32 a4, void *a5)
216 code = ioctl_sun_afs_syscall(28 /* AFSCALL_CALL */, a3, a4, a5, 0, 0, 0,
225 volser_syscall(afs_uint32 a3, afs_uint32 a4, void *a5)
228 #ifndef AFS_LINUX20_ENV
231 old = signal(SIGSYS, SIG_IGN);
234 syscall(AFS_SYSCALL /* AFS_SYSCALL */ , 28 /* AFSCALL_CALL */ , a3,
236 #ifndef AFS_LINUX20_ENV
245 /* check whether caller is authorized to manage RX statistics */
247 vol_rxstat_userok(struct rx_call *call)
249 return afsconf_SuperUser(tdir, call, NULL);
252 #include "AFS_component_version_number.c"
254 main(int argc, char **argv)
257 struct rx_securityClass **securityClasses;
258 afs_int32 numClasses;
259 struct rx_service *service;
260 struct ktc_encryptionKey tkey;
262 int rxJumbograms = 0; /* default is to send and receive jumbograms. */
264 int bufSize = 0; /* temp variable to read in udp socket buf size */
265 afs_uint32 host = ntohl(INADDR_ANY);
266 char *auditFileName = NULL;
267 VolumePackageOptions opts;
271 * The following signal action for AIX is necessary so that in case of a
272 * crash (i.e. core is generated) we can include the user's data section
273 * in the core dump. Unfortunately, by default, only a partial core is
274 * generated which, in many cases, isn't too useful.
276 struct sigaction nsa;
278 sigemptyset(&nsa.sa_mask);
279 nsa.sa_handler = SIG_DFL;
280 nsa.sa_flags = SA_FULLDUMP;
281 sigaction(SIGABRT, &nsa, NULL);
282 sigaction(SIGSEGV, &nsa, NULL);
285 osi_audit(VS_StartEvent, 0, AUD_END);
287 /* Initialize dirpaths */
288 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
290 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
292 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
300 for (code = 1; code < argc; code++) {
301 if (strcmp(argv[code], "-log") == 0) {
302 /* set extra logging flag */
304 } else if (strcmp(argv[code], "-help") == 0) {
306 } else if (strcmp(argv[code], "-rxbind") == 0) {
308 } else if (strcmp(argv[code], "-allow-dotted-principals") == 0) {
309 rxkadDisableDotCheck = 1;
310 } else if (strcmp(argv[code], "-d") == 0) {
311 if ((code + 1) >= argc) {
312 fprintf(stderr, "missing argument for -d\n");
315 debuglevel = atoi(argv[++code]);
316 LogLevel = debuglevel;
317 } else if (strcmp(argv[code], "-p") == 0) {
318 lwps = atoi(argv[++code]);
320 printf("Warning: '-p %d' is too big; using %d instead\n",
324 } else if (strcmp(argv[code], "-auditlog") == 0) {
325 auditFileName = argv[++code];
327 } else if (strcmp(argv[code], "-audit-interface") == 0) {
328 char *interface = argv[++code];
330 if (osi_audit_interface(interface)) {
331 printf("Invalid audit interface '%s'\n", interface);
334 } else if (strcmp(argv[code], "-nojumbo") == 0) {
336 } else if (strcmp(argv[code], "-jumbo") == 0) {
338 } else if (!strcmp(argv[code], "-rxmaxmtu")) {
339 if ((code + 1) >= argc) {
340 fprintf(stderr, "missing argument for -rxmaxmtu\n");
343 rxMaxMTU = atoi(argv[++code]);
344 if ((rxMaxMTU < RX_MIN_PACKET_SIZE) ||
345 (rxMaxMTU > RX_MAX_PACKET_DATA_SIZE)) {
346 printf("rxMaxMTU %d invalid; must be between %d-%" AFS_SIZET_FMT "\n",
347 rxMaxMTU, RX_MIN_PACKET_SIZE,
348 RX_MAX_PACKET_DATA_SIZE);
351 } else if (strcmp(argv[code], "-sleep") == 0) {
352 sscanf(argv[++code], "%d/%d", &TTsleep, &TTrun);
353 if ((TTsleep < 0) || (TTrun <= 0)) {
354 printf("Warning: '-sleep %d/%d' is incorrect; ignoring\n",
358 } else if (strcmp(argv[code], "-udpsize") == 0) {
359 if ((code + 1) >= argc) {
360 printf("You have to specify -udpsize <integer value>\n");
363 sscanf(argv[++code], "%d", &bufSize);
364 if (bufSize < rx_GetMinUdpBufSize())
366 ("Warning:udpsize %d is less than minimum %d; ignoring\n",
367 bufSize, rx_GetMinUdpBufSize());
369 udpBufSize = bufSize;
370 } else if (strcmp(argv[code], "-enable_peer_stats") == 0) {
371 rx_enablePeerRPCStats();
372 } else if (strcmp(argv[code], "-enable_process_stats") == 0) {
373 rx_enableProcessRPCStats();
376 else if (strcmp(argv[code], "-syslog") == 0) {
377 /* set syslog logging flag */
379 } else if (strncmp(argv[code], "-syslog=", 8) == 0) {
381 serverLogSyslogFacility = atoi(argv[code] + 8);
385 printf("volserver: unrecognized flag '%s'\n", argv[code]);
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 "[-syslog[=FACILITY]] "
393 "[-enable_peer_stats] [-enable_process_stats] "
396 printf("Usage: volserver [-log] [-p <number of processes>] "
397 "[-auditlog <log path>] [-d <debug level>] "
398 "[-nojumbo] [-jumbo] [-rxmaxmtu <bytes>] [-rxbind] [-allow-dotted-principals] "
399 "[-udpsize <size of socket buffer in bytes>] "
400 "[-enable_peer_stats] [-enable_process_stats] "
408 osi_audit_file(auditFileName);
409 osi_audit(VS_StartEvent, 0, AUD_END);
411 #ifdef AFS_SGI_VNODE_GLUE
412 if (afs_init_kernel_config(-1) < 0) {
414 ("Can't determine NUMA configuration, not starting volserver.\n");
420 #ifdef AFS_PTHREAD_ENV
421 SetLogThreadNumProgram( threadNum );
425 if (afs_winsockInit() < 0) {
426 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
427 printf("Volume server unable to start winsock, exiting.\n");
431 /* Open VolserLog and map stdout, stderr into it; VInitVolumePackage2 can
432 log, so we need to do this here */
433 OpenLog(AFSDIR_SERVER_VOLSERLOG_FILEPATH);
435 VOptDefaults(volumeServer, &opts);
436 if (VInitVolumePackage2(volumeServer, &opts)) {
437 Log("Shutting down: errors encountered initializing volume package\n");
441 Lock_Init(&localLock);
443 #ifndef AFS_PTHREAD_ENV
444 vol_PollProc = IOMGR_Poll; /* tell vol pkg to poll io system periodically */
447 rxi_syscallp = volser_syscall;
449 rx_nPackets = rxpackets; /* set the max number of packets */
451 rx_SetUdpBufSize(udpBufSize); /* set the UDP buffer size for receive */
454 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH ||
455 AFSDIR_SERVER_NETINFO_FILEPATH) {
457 ccode = parseNetFiles(SHostAddrs, NULL, NULL,
458 ADDRSPERSITE, reason,
459 AFSDIR_SERVER_NETINFO_FILEPATH,
460 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
463 ccode = rx_getAllAddr(SHostAddrs, ADDRSPERSITE);
466 host = SHostAddrs[0];
469 code = rx_InitHost(host, (int)htons(AFSCONF_VOLUMEPORT));
471 fprintf(stderr, "rx init failed on socket AFSCONF_VOLUMEPORT %u\n",
476 /* Don't allow 3.4 vos clients to send jumbograms and we don't send. */
479 if (rxMaxMTU != -1) {
480 rx_SetMaxMTU(rxMaxMTU);
483 rx_SetRxDeadTime(420);
484 memset(busyFlags, 0, sizeof(busyFlags));
489 #ifdef AFS_PTHREAD_ENV
491 pthread_attr_t tattr;
492 osi_Assert(pthread_attr_init(&tattr) == 0);
493 osi_Assert(pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED) == 0);
495 osi_Assert(pthread_create(&tid, &tattr, BKGLoop, NULL) == 0);
498 LWP_CreateProcess(BKGLoop, 16*1024, 3, 0, "vol bkg daemon", &pid);
499 LWP_CreateProcess(BKGSleep,16*1024, 3, 0, "vol slp daemon", &pid);
503 /* 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 */
505 tdir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
507 Abort("volser: could not open conf files in %s\n",
508 AFSDIR_SERVER_ETC_DIRPATH);
511 afsconf_GetKey(tdir, 999, &tkey);
512 afsconf_BuildServerSecurityObjects(tdir, 0, &securityClasses, &numClasses);
513 if (securityClasses[0] == NULL)
514 Abort("rxnull_NewServerSecurityObject");
516 rx_NewServiceHost(host, 0, VOLSERVICE_ID, "VOLSER", securityClasses,
517 numClasses, AFSVolExecuteRequest);
518 if (service == (struct rx_service *)0)
519 Abort("rx_NewService");
520 rx_SetBeforeProc(service, MyBeforeProc);
521 rx_SetAfterProc(service, MyAfterProc);
522 rx_SetIdleDeadTime(service, 0); /* never timeout */
525 rx_SetMaxProcs(service, lwps);
526 #if defined(AFS_XBSD_ENV)
527 rx_SetStackSize(service, (128 * 1024));
528 #elif defined(AFS_SGI_ENV)
529 rx_SetStackSize(service, (48 * 1024));
531 rx_SetStackSize(service, (32 * 1024));
534 if (rxkadDisableDotCheck) {
535 rx_SetSecurityConfiguration(service, RXS_CONFIG_FLAGS,
536 (void *)RXS_CONFIG_FLAGS_DISABLE_DOTCHECK);
540 rx_NewService(0, RX_STATS_SERVICE_ID, "rpcstats", securityClasses,
541 numClasses, RXSTATS_ExecuteRequest);
542 if (service == (struct rx_service *)0)
543 Abort("rx_NewService");
544 rx_SetMinProcs(service, 2);
545 rx_SetMaxProcs(service, 4);
547 LogCommandLine(argc, argv, "Volserver", VolserVersion, "Starting AFS",
550 Log("Will sleep %d second%s every %d second%s\n", TTsleep,
551 (TTsleep > 1) ? "s" : "", TTrun + TTsleep,
552 (TTrun + TTsleep > 1) ? "s" : "");
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 */