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>
14 #include <sys/types.h>
20 #include <WINNT/afsevent.h>
24 #include <netinet/in.h>
28 #include <afs/afsint.h>
31 #ifdef AFS_PTHREAD_ENV
33 #else /* AFS_PTHREAD_ENV */
34 #include <afs/assert.h>
35 #endif /* AFS_PTHREAD_ENV */
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>
61 #include <afs/audit.h>
62 #include <afs/afsutil.h>
66 #include "volser_prototypes.h"
68 /*@printflike@*/ extern void Log(const char *format, ...);
69 /*@printflike@*/ extern void Abort(const char *format, ...);
71 #define VolserVersion "2.0"
72 #define N_SECURITY_OBJECTS 3
74 extern struct Lock localLock;
75 char *GlobalNameHack = NULL;
77 afs_int32 GlobalVolCloneId, GlobalVolParentId;
79 int VolumeChanged; /* XXXX */
80 static char busyFlags[MAXHELPERS];
81 struct volser_trans *QI_GlobalWriteTrans = 0;
82 struct afsconf_dir *tdir;
83 static afs_int32 runningCalls = 0;
88 int udpBufSize = 0; /* UDP buffer size for receive */
91 int rxkadDisableDotCheck = 0;
93 #define ADDRSPERSITE 16 /* Same global is in rx/rx_user.c */
94 afs_uint32 SHostAddrs[ADDRSPERSITE];
96 #define VS_EXIT(code) { \
97 osi_audit(VS_ExitEvent, code, AUD_END); \
101 #if defined(AFS_PTHREAD_ENV)
105 return (intptr_t)pthread_getspecific(rx_thread_id_key);
110 MyBeforeProc(struct rx_call *acall)
119 MyAfterProc(struct rx_call *acall, afs_int32 code)
127 /* Called every GCWAKEUP seconds to try to unlock all our partitions,
128 * if we're idle and there are no active transactions
133 /* if there are no running calls, and there are no active transactions, then
134 * it should be safe to release any partition locks we've accumulated */
136 if (runningCalls == 0 && TransList() == (struct volser_trans *)0) {
138 VPFullUnlock(); /* in volprocs.c */
143 /* background daemon for timing out transactions */
145 BKGLoop(void *unused)
151 tv.tv_sec = GCWAKEUP;
153 #ifdef AFS_PTHREAD_ENV
154 select(0, 0, 0, 0, &tv);
156 (void)IOMGR_Select(0, 0, 0, 0, &tv);
161 if (loop == 10) { /* reopen log every 5 minutes */
163 ReOpenLog(AFSDIR_SERVER_VOLSERLOG_FILEPATH);
170 /* Background daemon for sleeping so the volserver does not become I/O bound */
171 afs_int32 TTsleep, TTrun;
172 #ifndef AFS_PTHREAD_ENV
174 BKGSleep(void *unused)
176 struct volser_trans *tt;
180 #ifdef AFS_PTHREAD_ENV
182 #else /* AFS_PTHREAD_ENV */
186 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))
208 volser_syscall(afs_uint32 a3, afs_uint32 a4, void *a5)
211 #ifndef AFS_LINUX20_ENV
214 old = signal(SIGSYS, SIG_IGN);
217 syscall(AFS_SYSCALL /* AFS_SYSCALL */ , 28 /* AFSCALL_CALL */ , a3,
219 #ifndef AFS_LINUX20_ENV
228 /* check whether caller is authorized to manage RX statistics */
230 vol_rxstat_userok(struct rx_call *call)
232 return afsconf_SuperUser(tdir, call, NULL);
235 #include "AFS_component_version_number.c"
237 main(int argc, char **argv)
239 register afs_int32 code;
240 struct rx_securityClass *(securityObjects[3]);
241 struct rx_service *service;
242 struct ktc_encryptionKey tkey;
244 char commandLine[150];
246 int rxJumbograms = 0; /* default is to send and receive jumbograms. */
248 int bufSize = 0; /* temp variable to read in udp socket buf size */
249 afs_uint32 host = ntohl(INADDR_ANY);
250 char *auditFileName = NULL;
254 * The following signal action for AIX is necessary so that in case of a
255 * crash (i.e. core is generated) we can include the user's data section
256 * in the core dump. Unfortunately, by default, only a partial core is
257 * generated which, in many cases, isn't too useful.
259 struct sigaction nsa;
261 sigemptyset(&nsa.sa_mask);
262 nsa.sa_handler = SIG_DFL;
263 nsa.sa_flags = SA_FULLDUMP;
264 sigaction(SIGABRT, &nsa, NULL);
265 sigaction(SIGSEGV, &nsa, NULL);
268 osi_audit(VS_StartEvent, 0, AUD_END);
270 /* Initialize dirpaths */
271 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
273 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
275 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
280 for (commandLine[0] = '\0', i = 0; i < argc; i++) {
282 strcat(commandLine, " ");
283 strcat(commandLine, argv[i]);
289 for (code = 1; code < argc; code++) {
290 if (strcmp(argv[code], "-log") == 0) {
291 /* set extra logging flag */
293 } else if (strcmp(argv[code], "-help") == 0) {
295 } else if (strcmp(argv[code], "-rxbind") == 0) {
297 } else if (strcmp(argv[code], "-allow-dotted-principals") == 0) {
298 rxkadDisableDotCheck = 1;
299 } else if (strcmp(argv[code], "-d") == 0) {
300 if ((code + 1) >= argc) {
301 fprintf(stderr, "missing argument for -d\n");
304 debuglevel = atoi(argv[++code]);
305 LogLevel = debuglevel;
306 } else if (strcmp(argv[code], "-p") == 0) {
307 lwps = atoi(argv[++code]);
309 printf("Warning: '-p %d' is too big; using %d instead\n",
313 } else if (strcmp(argv[code], "-auditlog") == 0) {
314 auditFileName = argv[++code];
316 } else if (strcmp(argv[code], "-audit-interface") == 0) {
317 char *interface = argv[++code];
319 if (osi_audit_interface(interface)) {
320 printf("Invalid audit interface '%s'\n", interface);
323 } else if (strcmp(argv[code], "-nojumbo") == 0) {
325 } else if (strcmp(argv[code], "-jumbo") == 0) {
327 } else if (!strcmp(argv[code], "-rxmaxmtu")) {
328 if ((code + 1) >= argc) {
329 fprintf(stderr, "missing argument for -rxmaxmtu\n");
332 rxMaxMTU = atoi(argv[++code]);
333 if ((rxMaxMTU < RX_MIN_PACKET_SIZE) ||
334 (rxMaxMTU > RX_MAX_PACKET_DATA_SIZE)) {
335 printf("rxMaxMTU %d invalid; must be between %d-%" AFS_SIZET_FMT "\n",
336 rxMaxMTU, RX_MIN_PACKET_SIZE,
337 RX_MAX_PACKET_DATA_SIZE);
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( threadNum );
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; VInitVolumePackage can
421 log, so we need to do this here */
422 OpenLog(AFSDIR_SERVER_VOLSERLOG_FILEPATH);
424 VInitVolumePackage(volumeUtility, 0, 0, CONNECT_FS, 0);
426 Lock_Init(&localLock);
428 #ifndef AFS_PTHREAD_ENV
429 vol_PollProc = IOMGR_Poll; /* tell vol pkg to poll io system periodically */
432 rxi_syscallp = volser_syscall;
434 rx_nPackets = rxpackets; /* set the max number of packets */
436 rx_SetUdpBufSize(udpBufSize); /* set the UDP buffer size for receive */
439 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH ||
440 AFSDIR_SERVER_NETINFO_FILEPATH) {
442 ccode = parseNetFiles(SHostAddrs, NULL, NULL,
443 ADDRSPERSITE, reason,
444 AFSDIR_SERVER_NETINFO_FILEPATH,
445 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
448 ccode = rx_getAllAddr(SHostAddrs, ADDRSPERSITE);
451 host = SHostAddrs[0];
454 code = rx_InitHost(host, (int)htons(AFSCONF_VOLUMEPORT));
456 fprintf(stderr, "rx init failed on socket AFSCONF_VOLUMEPORT %u\n",
461 /* Don't allow 3.4 vos clients to send jumbograms and we don't send. */
464 if (rxMaxMTU != -1) {
465 rx_SetMaxMTU(rxMaxMTU);
468 rx_SetRxDeadTime(420);
469 memset(busyFlags, 0, sizeof(busyFlags));
474 #ifdef AFS_PTHREAD_ENV
476 pthread_attr_t tattr;
477 assert(pthread_attr_init(&tattr) == 0);
478 assert(pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED) == 0);
480 assert(pthread_create(&tid, &tattr, BKGLoop, NULL) == 0);
483 LWP_CreateProcess(BKGLoop, 16*1024, 3, 0, "vol bkg daemon", &pid);
484 LWP_CreateProcess(BKGSleep,16*1024, 3, 0, "vol slp daemon", &pid);
488 /* 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 */
490 tdir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
492 Abort("volser: could not open conf files in %s\n",
493 AFSDIR_SERVER_ETC_DIRPATH);
496 afsconf_GetKey(tdir, 999, &tkey);
497 securityObjects[0] = rxnull_NewServerSecurityObject();
498 securityObjects[1] = (struct rx_securityClass *)0; /* don't bother with rxvab */
500 rxkad_NewServerSecurityObject(0, tdir, afsconf_GetKey, NULL);
501 if (securityObjects[0] == (struct rx_securityClass *)0)
502 Abort("rxnull_NewServerSecurityObject");
504 rx_NewServiceHost(host, 0, VOLSERVICE_ID, "VOLSER", securityObjects, 3,
505 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", securityObjects, 3,
529 RXSTATS_ExecuteRequest);
530 if (service == (struct rx_service *)0)
531 Abort("rx_NewService");
532 rx_SetMinProcs(service, 2);
533 rx_SetMaxProcs(service, 4);
535 Log("Starting AFS Volserver %s (%s)\n", VolserVersion, commandLine);
537 Log("Will sleep %d second%s every %d second%s\n", TTsleep,
538 (TTsleep > 1) ? "s" : "", TTrun + TTsleep,
539 (TTrun + TTsleep > 1) ? "s" : "");
542 /* allow super users to manage RX statistics */
543 rx_SetRxStatUserOk(vol_rxstat_userok);
545 rx_StartServer(1); /* Donate this process to the server process pool */
547 osi_audit(VS_FinishEvent, (-1), AUD_END);
548 Abort("StartServer returned?");
549 return 0; /* not reached */