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/afs_assert.h>
23 #include <afs/prs_fs.h>
27 #include <afs/afssyscalls.h>
28 #include <afs/ihandle.h>
30 #include <afs/ntops.h>
32 #include <afs/vnode.h>
33 #include <afs/volume.h>
34 #include <afs/partition.h>
36 #include <rx/rxstat.h>
37 #include <rx/rx_globals.h>
39 #include <afs/cellconfig.h>
43 #include <afs/audit.h>
44 #include <afs/afsutil.h>
49 #include "volser_internal.h"
51 /*@printflike@*/ extern void Log(const char *format, ...);
52 /*@printflike@*/ extern void Abort(const char *format, ...);
54 #define VolserVersion "2.0"
55 #define N_SECURITY_OBJECTS 3
57 extern struct Lock localLock;
58 char *GlobalNameHack = NULL;
60 afs_int32 GlobalVolCloneId, GlobalVolParentId;
62 int VolumeChanged; /* XXXX */
63 static char busyFlags[MAXHELPERS];
64 struct volser_trans *QI_GlobalWriteTrans = 0;
65 struct afsconf_dir *tdir;
66 static afs_int32 runningCalls = 0;
71 int udpBufSize = 0; /* UDP buffer size for receive */
74 int rxkadDisableDotCheck = 0;
76 #define ADDRSPERSITE 16 /* Same global is in rx/rx_user.c */
77 afs_uint32 SHostAddrs[ADDRSPERSITE];
79 #define VS_EXIT(code) { \
80 osi_audit(VS_ExitEvent, code, AUD_END); \
84 #if defined(AFS_PTHREAD_ENV)
88 return (intptr_t)pthread_getspecific(rx_thread_id_key);
93 MyBeforeProc(struct rx_call *acall)
102 MyAfterProc(struct rx_call *acall, afs_int32 code)
110 /* Called every GCWAKEUP seconds to try to unlock all our partitions,
111 * if we're idle and there are no active transactions
116 /* if there are no running calls, and there are no active transactions, then
117 * it should be safe to release any partition locks we've accumulated */
119 if (runningCalls == 0 && TransList() == (struct volser_trans *)0) {
121 VPFullUnlock(); /* in volprocs.c */
126 /* background daemon for timing out transactions */
128 BKGLoop(void *unused)
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);
157 /* Background daemon for sleeping so the volserver does not become I/O bound */
158 afs_int32 TTsleep, TTrun;
159 #ifndef AFS_PTHREAD_ENV
161 BKGSleep(void *unused)
163 struct volser_trans *tt;
167 #ifdef AFS_PTHREAD_ENV
169 #else /* AFS_PTHREAD_ENV */
173 for (tt = TransList(); tt; tt = tt->next) {
175 if ((strcmp(tt->lastProcName, "DeleteVolume") == 0)
176 || (strcmp(tt->lastProcName, "Clone") == 0)
177 || (strcmp(tt->lastProcName, "ReClone") == 0)
178 || (strcmp(tt->lastProcName, "Forward") == 0)
179 || (strcmp(tt->lastProcName, "Restore") == 0)
180 || (strcmp(tt->lastProcName, "ForwardMulti") == 0)) {
181 VTRANS_OBJ_UNLOCK(tt);
184 VTRANS_OBJ_UNLOCK(tt);
198 /* no volser_syscall */
199 #elif defined(AFS_SUN511_ENV)
201 volser_syscall(afs_uint32 a3, afs_uint32 a4, void *a5)
204 code = ioctl_sun_afs_syscall(28 /* AFSCALL_CALL */, a3, a4, a5, 0, 0, 0,
213 volser_syscall(afs_uint32 a3, afs_uint32 a4, void *a5)
216 #ifndef AFS_LINUX20_ENV
219 old = signal(SIGSYS, SIG_IGN);
222 syscall(AFS_SYSCALL /* AFS_SYSCALL */ , 28 /* AFSCALL_CALL */ , a3,
224 #ifndef AFS_LINUX20_ENV
233 /* check whether caller is authorized to manage RX statistics */
235 vol_rxstat_userok(struct rx_call *call)
237 return afsconf_SuperUser(tdir, call, NULL);
240 #include "AFS_component_version_number.c"
242 main(int argc, char **argv)
245 struct rx_securityClass **securityClasses;
246 afs_int32 numClasses;
247 struct rx_service *service;
248 struct ktc_encryptionKey tkey;
250 int rxJumbograms = 0; /* default is to send and receive jumbograms. */
252 int bufSize = 0; /* temp variable to read in udp socket buf size */
253 afs_uint32 host = ntohl(INADDR_ANY);
254 char *auditFileName = NULL;
255 VolumePackageOptions opts;
259 * The following signal action for AIX is necessary so that in case of a
260 * crash (i.e. core is generated) we can include the user's data section
261 * in the core dump. Unfortunately, by default, only a partial core is
262 * generated which, in many cases, isn't too useful.
264 struct sigaction nsa;
266 sigemptyset(&nsa.sa_mask);
267 nsa.sa_handler = SIG_DFL;
268 nsa.sa_flags = SA_FULLDUMP;
269 sigaction(SIGABRT, &nsa, NULL);
270 sigaction(SIGSEGV, &nsa, NULL);
273 osi_audit(VS_StartEvent, 0, AUD_END);
275 /* Initialize dirpaths */
276 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
278 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
280 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
288 for (code = 1; code < argc; code++) {
289 if (strcmp(argv[code], "-log") == 0) {
290 /* set extra logging flag */
292 } else if (strcmp(argv[code], "-help") == 0) {
294 } else if (strcmp(argv[code], "-rxbind") == 0) {
296 } else if (strcmp(argv[code], "-allow-dotted-principals") == 0) {
297 rxkadDisableDotCheck = 1;
298 } else if (strcmp(argv[code], "-d") == 0) {
299 if ((code + 1) >= argc) {
300 fprintf(stderr, "missing argument for -d\n");
303 debuglevel = atoi(argv[++code]);
304 LogLevel = debuglevel;
305 } else if (strcmp(argv[code], "-p") == 0) {
306 lwps = atoi(argv[++code]);
308 printf("Warning: '-p %d' is too big; using %d instead\n",
312 } else if (strcmp(argv[code], "-auditlog") == 0) {
313 auditFileName = argv[++code];
315 } else if (strcmp(argv[code], "-audit-interface") == 0) {
316 char *interface = argv[++code];
318 if (osi_audit_interface(interface)) {
319 printf("Invalid audit interface '%s'\n", interface);
322 } else if (strcmp(argv[code], "-nojumbo") == 0) {
324 } else if (strcmp(argv[code], "-jumbo") == 0) {
326 } else if (!strcmp(argv[code], "-rxmaxmtu")) {
327 if ((code + 1) >= argc) {
328 fprintf(stderr, "missing argument for -rxmaxmtu\n");
331 rxMaxMTU = atoi(argv[++code]);
332 if ((rxMaxMTU < RX_MIN_PACKET_SIZE) ||
333 (rxMaxMTU > RX_MAX_PACKET_DATA_SIZE)) {
334 printf("rxMaxMTU %d invalid; must be between %d-%" AFS_SIZET_FMT "\n",
335 rxMaxMTU, RX_MIN_PACKET_SIZE,
336 RX_MAX_PACKET_DATA_SIZE);
339 } else if (strcmp(argv[code], "-sleep") == 0) {
340 sscanf(argv[++code], "%d/%d", &TTsleep, &TTrun);
341 if ((TTsleep < 0) || (TTrun <= 0)) {
342 printf("Warning: '-sleep %d/%d' is incorrect; ignoring\n",
346 } else if (strcmp(argv[code], "-udpsize") == 0) {
347 if ((code + 1) >= argc) {
348 printf("You have to specify -udpsize <integer value>\n");
351 sscanf(argv[++code], "%d", &bufSize);
352 if (bufSize < rx_GetMinUdpBufSize())
354 ("Warning:udpsize %d is less than minimum %d; ignoring\n",
355 bufSize, rx_GetMinUdpBufSize());
357 udpBufSize = bufSize;
358 } else if (strcmp(argv[code], "-enable_peer_stats") == 0) {
359 rx_enablePeerRPCStats();
360 } else if (strcmp(argv[code], "-enable_process_stats") == 0) {
361 rx_enableProcessRPCStats();
364 else if (strcmp(argv[code], "-syslog") == 0) {
365 /* set syslog logging flag */
367 } else if (strncmp(argv[code], "-syslog=", 8) == 0) {
369 serverLogSyslogFacility = atoi(argv[code] + 8);
373 printf("volserver: unrecognized flag '%s'\n", argv[code]);
376 printf("Usage: volserver [-log] [-p <number of processes>] "
377 "[-auditlog <log path>] [-d <debug level>] "
378 "[-nojumbo] [-jumbo] [-rxmaxmtu <bytes>] [-rxbind] [-allow-dotted-principals] "
379 "[-udpsize <size of socket buffer in bytes>] "
380 "[-syslog[=FACILITY]] "
381 "[-enable_peer_stats] [-enable_process_stats] "
384 printf("Usage: volserver [-log] [-p <number of processes>] "
385 "[-auditlog <log path>] [-d <debug level>] "
386 "[-nojumbo] [-jumbo] [-rxmaxmtu <bytes>] [-rxbind] [-allow-dotted-principals] "
387 "[-udpsize <size of socket buffer in bytes>] "
388 "[-enable_peer_stats] [-enable_process_stats] "
396 osi_audit_file(auditFileName);
397 osi_audit(VS_StartEvent, 0, AUD_END);
399 #ifdef AFS_SGI_VNODE_GLUE
400 if (afs_init_kernel_config(-1) < 0) {
402 ("Can't determine NUMA configuration, not starting volserver.\n");
408 #ifdef AFS_PTHREAD_ENV
409 SetLogThreadNumProgram( threadNum );
413 if (afs_winsockInit() < 0) {
414 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
415 printf("Volume server unable to start winsock, exiting.\n");
419 /* Open VolserLog and map stdout, stderr into it; VInitVolumePackage2 can
420 log, so we need to do this here */
421 OpenLog(AFSDIR_SERVER_VOLSERLOG_FILEPATH);
423 VOptDefaults(volumeServer, &opts);
424 if (VInitVolumePackage2(volumeServer, &opts)) {
425 Log("Shutting down: errors encountered initializing volume package\n");
429 Lock_Init(&localLock);
431 #ifndef AFS_PTHREAD_ENV
432 vol_PollProc = IOMGR_Poll; /* tell vol pkg to poll io system periodically */
435 rxi_syscallp = volser_syscall;
437 rx_nPackets = rxpackets; /* set the max number of packets */
439 rx_SetUdpBufSize(udpBufSize); /* set the UDP buffer size for receive */
442 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH ||
443 AFSDIR_SERVER_NETINFO_FILEPATH) {
445 ccode = parseNetFiles(SHostAddrs, NULL, NULL,
446 ADDRSPERSITE, reason,
447 AFSDIR_SERVER_NETINFO_FILEPATH,
448 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
451 ccode = rx_getAllAddr(SHostAddrs, ADDRSPERSITE);
454 host = SHostAddrs[0];
457 code = rx_InitHost(host, (int)htons(AFSCONF_VOLUMEPORT));
459 fprintf(stderr, "rx init failed on socket AFSCONF_VOLUMEPORT %u\n",
464 /* Don't allow 3.4 vos clients to send jumbograms and we don't send. */
467 if (rxMaxMTU != -1) {
468 rx_SetMaxMTU(rxMaxMTU);
471 rx_SetRxDeadTime(420);
472 memset(busyFlags, 0, sizeof(busyFlags));
477 #ifdef AFS_PTHREAD_ENV
479 pthread_attr_t tattr;
480 osi_Assert(pthread_attr_init(&tattr) == 0);
481 osi_Assert(pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED) == 0);
483 osi_Assert(pthread_create(&tid, &tattr, BKGLoop, NULL) == 0);
486 LWP_CreateProcess(BKGLoop, 16*1024, 3, 0, "vol bkg daemon", &pid);
487 LWP_CreateProcess(BKGSleep,16*1024, 3, 0, "vol slp daemon", &pid);
491 /* 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 */
493 tdir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
495 Abort("volser: could not open conf files in %s\n",
496 AFSDIR_SERVER_ETC_DIRPATH);
499 afsconf_GetKey(tdir, 999, &tkey);
500 afsconf_BuildServerSecurityObjects(tdir, &securityClasses, &numClasses);
501 if (securityClasses[0] == NULL)
502 Abort("rxnull_NewServerSecurityObject");
504 rx_NewServiceHost(host, 0, VOLSERVICE_ID, "VOLSER", securityClasses,
505 numClasses, AFSVolExecuteRequest);
506 if (service == (struct rx_service *)0)
507 Abort("rx_NewService");
508 rx_SetBeforeProc(service, MyBeforeProc);
509 rx_SetAfterProc(service, MyAfterProc);
510 rx_SetIdleDeadTime(service, 0); /* never timeout */
513 rx_SetMaxProcs(service, lwps);
514 #if defined(AFS_XBSD_ENV)
515 rx_SetStackSize(service, (128 * 1024));
516 #elif defined(AFS_SGI_ENV)
517 rx_SetStackSize(service, (48 * 1024));
519 rx_SetStackSize(service, (32 * 1024));
522 if (rxkadDisableDotCheck) {
523 rx_SetSecurityConfiguration(service, RXS_CONFIG_FLAGS,
524 (void *)RXS_CONFIG_FLAGS_DISABLE_DOTCHECK);
528 rx_NewService(0, RX_STATS_SERVICE_ID, "rpcstats", securityClasses,
529 numClasses, RXSTATS_ExecuteRequest);
530 if (service == (struct rx_service *)0)
531 Abort("rx_NewService");
532 rx_SetMinProcs(service, 2);
533 rx_SetMaxProcs(service, 4);
535 LogCommandLine(argc, argv, "Volserver", VolserVersion, "Starting AFS",
538 Log("Will sleep %d second%s every %d second%s\n", TTsleep,
539 (TTsleep > 1) ? "s" : "", TTrun + TTsleep,
540 (TTrun + TTsleep > 1) ? "s" : "");
543 /* allow super users to manage RX statistics */
544 rx_SetRxStatUserOk(vol_rxstat_userok);
546 rx_StartServer(1); /* Donate this process to the server process pool */
548 osi_audit(VS_FinishEvent, (-1), AUD_END);
549 Abort("StartServer returned?");
550 return 0; /* not reached */