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>
16 #include <sys/types.h>
22 #include <WINNT/afsevent.h>
26 #include <netinet/in.h>
29 #include <afs/afsint.h>
32 #ifdef AFS_PTHREAD_ENV
34 #else /* AFS_PTHREAD_ENV */
35 #include <afs/assert.h>
36 #endif /* AFS_PTHREAD_ENV */
37 #include <afs/prs_fs.h>
41 #include <afs/afssyscalls.h>
42 #include <afs/ihandle.h>
44 #include <afs/ntops.h>
46 #include <afs/vnode.h>
47 #include <afs/volume.h>
48 #include <afs/partition.h>
50 #include <rx/rx_globals.h>
52 #include <afs/cellconfig.h>
60 #include <afs/audit.h>
61 #include <afs/afsutil.h>
63 /*@printflike@*/ extern void Log(const char *format, ...);
64 /*@printflike@*/ extern void Abort(const char *format, ...);
66 #define VolserVersion "2.0"
67 #define N_SECURITY_OBJECTS 3
69 extern struct Lock localLock;
70 extern struct volser_trans *TransList();
71 #ifndef AFS_PTHREAD_ENV
72 extern int (*vol_PollProc) ();
73 extern int IOMGR_Poll();
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 extern void AFSVolExecuteRequest();
83 extern void RXSTATS_ExecuteRequest();
84 struct afsconf_dir *tdir;
85 static afs_int32 runningCalls = 0;
89 int udpBufSize = 0; /* UDP buffer size for receive */
92 int rxkadDisableDotCheck = 0;
94 #define ADDRSPERSITE 16 /* Same global is in rx/rx_user.c */
95 afs_uint32 SHostAddrs[ADDRSPERSITE];
97 #define VS_EXIT(code) { \
98 osi_audit(VS_ExitEvent, code, AUD_END); \
102 #if defined(AFS_PTHREAD_ENV)
106 return pthread_getspecific(rx_thread_id_key);
111 MyBeforeProc(struct rx_call *acall)
120 MyAfterProc(struct rx_call *acall, afs_int32 code)
128 /* Called every GCWAKEUP seconds to try to unlock all our partitions,
129 * if we're idle and there are no active transactions
134 /* if there are no running calls, and there are no active transactions, then
135 * it should be safe to release any partition locks we've accumulated */
137 if (runningCalls == 0 && TransList() == (struct volser_trans *)0) {
139 VPFullUnlock(); /* in volprocs.c */
144 /* background daemon for timing out transactions */
152 tv.tv_sec = GCWAKEUP;
154 #ifdef AFS_PTHREAD_ENV
155 select(0, 0, 0, 0, &tv);
157 (void)IOMGR_Select(0, 0, 0, 0, &tv);
162 if (loop == 10) { /* reopen log every 5 minutes */
164 ReOpenLog(AFSDIR_SERVER_VOLSERLOG_FILEPATH);
169 /* Background daemon for sleeping so the volserver does not become I/O bound */
170 afs_int32 TTsleep, TTrun;
174 struct volser_trans *tt;
178 #ifdef AFS_PTHREAD_ENV
180 #else /* AFS_PTHREAD_ENV */
184 for (tt = TransList(); tt; tt = tt->next) {
185 if ((strcmp(tt->lastProcName, "DeleteVolume") == 0)
186 || (strcmp(tt->lastProcName, "Clone") == 0)
187 || (strcmp(tt->lastProcName, "ReClone") == 0)
188 || (strcmp(tt->lastProcName, "Forward") == 0)
189 || (strcmp(tt->lastProcName, "Restore") == 0)
190 || (strcmp(tt->lastProcName, "ForwardMulti") == 0))
204 volser_syscall(afs_uint32 a3, afs_uint32 a4, void *a5)
209 #ifndef AFS_LINUX20_ENV
210 old = signal(SIGSYS, SIG_IGN);
213 syscall(AFS_SYSCALL /* AFS_SYSCALL */ , 28 /* AFSCALL_CALL */ , a3,
215 #ifndef AFS_LINUX20_ENV
224 /* check whether caller is authorized to manage RX statistics */
226 vol_rxstat_userok(struct rx_call *call)
228 return afsconf_SuperUser(tdir, call, NULL);
231 #include "AFS_component_version_number.c"
233 main(int argc, char **argv)
235 register afs_int32 code;
236 struct rx_securityClass *(securityObjects[3]);
237 struct rx_service *service;
238 struct ktc_encryptionKey tkey;
240 char commandLine[150];
242 int rxJumbograms = 1; /* default is to send and receive jumbograms. */
244 int bufSize = 0; /* temp variable to read in udp socket buf size */
245 afs_uint32 host = ntohl(INADDR_ANY);
249 * The following signal action for AIX is necessary so that in case of a
250 * crash (i.e. core is generated) we can include the user's data section
251 * in the core dump. Unfortunately, by default, only a partial core is
252 * generated which, in many cases, isn't too useful.
254 struct sigaction nsa;
256 sigemptyset(&nsa.sa_mask);
257 nsa.sa_handler = SIG_DFL;
258 nsa.sa_flags = SA_FULLDUMP;
259 sigaction(SIGABRT, &nsa, NULL);
260 sigaction(SIGSEGV, &nsa, NULL);
263 osi_audit(VS_StartEvent, 0, AUD_END);
265 /* Initialize dirpaths */
266 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
268 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
270 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
275 for (commandLine[0] = '\0', i = 0; i < argc; i++) {
277 strcat(commandLine, " ");
278 strcat(commandLine, argv[i]);
284 for (code = 1; code < argc; code++) {
285 if (strcmp(argv[code], "-log") == 0) {
286 /* set extra logging flag */
288 } else if (strcmp(argv[code], "-help") == 0) {
290 } else if (strcmp(argv[code], "-rxbind") == 0) {
292 } else if (strcmp(argv[code], "-allow-dotted-principals") == 0) {
293 rxkadDisableDotCheck = 1;
294 } else if (strcmp(argv[code], "-p") == 0) {
295 lwps = atoi(argv[++code]);
297 printf("Warning: '-p %d' is too big; using %d instead\n",
301 } else if (strcmp(argv[code], "-auditlog") == 0) {
304 char oldName[MAXPATHLEN];
305 char *fileName = argv[++code];
310 if ((lstat(fileName, &statbuf) == 0)
311 && (S_ISFIFO(statbuf.st_mode))) {
312 flags = O_WRONLY | O_NONBLOCK;
316 strcpy(oldName, fileName);
317 strcat(oldName, ".old");
318 renamefile(fileName, oldName);
319 flags = O_WRONLY | O_TRUNC | O_CREAT;
321 tempfd = open(fileName, flags, 0666);
323 auditout = fdopen(tempfd, "a");
325 osi_audit_file(auditout);
326 osi_audit(VS_StartEvent, 0, AUD_END);
328 printf("Warning: auditlog %s not writable, ignored.\n", fileName);
330 printf("Warning: auditlog %s not writable, ignored.\n", fileName);
331 } else if (strcmp(argv[code], "-nojumbo") == 0) {
333 } else if (!strcmp(argv[code], "-rxmaxmtu")) {
334 if ((code + 1) >= argc) {
335 fprintf(stderr, "missing argument for -rxmaxmtu\n");
338 rxMaxMTU = atoi(argv[++code]);
339 if ((rxMaxMTU < RX_MIN_PACKET_SIZE) ||
340 (rxMaxMTU > RX_MAX_PACKET_DATA_SIZE)) {
341 printf("rxMaxMTU %d% invalid; must be between %d-%d\n",
342 rxMaxMTU, RX_MIN_PACKET_SIZE,
343 RX_MAX_PACKET_DATA_SIZE);
346 } else if (strcmp(argv[code], "-sleep") == 0) {
347 sscanf(argv[++code], "%d/%d", &TTsleep, &TTrun);
348 if ((TTsleep < 0) || (TTrun <= 0)) {
349 printf("Warning: '-sleep %d/%d' is incorrect; ignoring\n",
353 } else if (strcmp(argv[code], "-udpsize") == 0) {
354 if ((code + 1) >= argc) {
355 printf("You have to specify -udpsize <integer value>\n");
358 sscanf(argv[++code], "%d", &bufSize);
359 if (bufSize < rx_GetMinUdpBufSize())
361 ("Warning:udpsize %d is less than minimum %d; ignoring\n",
362 bufSize, rx_GetMinUdpBufSize());
364 udpBufSize = bufSize;
365 } else if (strcmp(argv[code], "-enable_peer_stats") == 0) {
366 rx_enablePeerRPCStats();
367 } else if (strcmp(argv[code], "-enable_process_stats") == 0) {
368 rx_enableProcessRPCStats();
371 else if (strcmp(argv[code], "-syslog") == 0) {
372 /* set syslog logging flag */
374 } else if (strncmp(argv[code], "-syslog=", 8) == 0) {
376 serverLogSyslogFacility = atoi(argv[code] + 8);
380 printf("volserver: unrecognized flag '%s'\n", argv[code]);
383 printf("Usage: volserver [-log] [-p <number of processes>] "
384 "[-auditlog <log path>] "
385 "[-nojumbo] [-rxmaxmtu <bytes>] [-rxbind] [-allow-dotted-principals] "
386 "[-udpsize <size of socket buffer in bytes>] "
387 "[-syslog[=FACILITY]] "
388 "[-enable_peer_stats] [-enable_process_stats] "
391 printf("Usage: volserver [-log] [-p <number of processes>] "
392 "[-auditlog <log path>] "
393 "[-nojumbo] [-rxmaxmtu <bytes>] [-rxbind] [-allow-dotted-principals] "
394 "[-udpsize <size of socket buffer in bytes>] "
395 "[-enable_peer_stats] [-enable_process_stats] "
401 #ifdef AFS_SGI_VNODE_GLUE
402 if (afs_init_kernel_config(-1) < 0) {
404 ("Can't determine NUMA configuration, not starting volserver.\n");
410 #ifdef AFS_PTHREAD_ENV
411 SetLogThreadNumProgram( threadNum );
415 if (afs_winsockInit() < 0) {
416 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
417 printf("Volume server unable to start winsock, exiting.\n");
421 /* Open VolserLog and map stdout, stderr into it; VInitVolumePackage can
422 log, so we need to do this here */
423 OpenLog(AFSDIR_SERVER_VOLSERLOG_FILEPATH);
425 VInitVolumePackage(volumeUtility, 0, 0, CONNECT_FS, 0);
427 Lock_Init(&localLock);
429 #ifndef AFS_PTHREAD_ENV
430 vol_PollProc = IOMGR_Poll; /* tell vol pkg to poll io system periodically */
433 rxi_syscallp = volser_syscall;
435 rx_nPackets = rxpackets; /* set the max number of packets */
437 rx_SetUdpBufSize(udpBufSize); /* set the UDP buffer size for receive */
441 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH ||
442 AFSDIR_SERVER_NETINFO_FILEPATH) {
444 ccode = parseNetFiles(SHostAddrs, NULL, NULL,
445 ADDRSPERSITE, reason,
446 AFSDIR_SERVER_NETINFO_FILEPATH,
447 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 assert(pthread_attr_init(&tattr) == 0);
481 assert(pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED) == 0);
483 assert(pthread_create(&tid, &tattr, (void *)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 securityObjects[0] = rxnull_NewServerSecurityObject();
501 securityObjects[1] = (struct rx_securityClass *)0; /* don't bother with rxvab */
503 rxkad_NewServerSecurityObject(0, tdir, afsconf_GetKey, NULL);
504 if (securityObjects[0] == (struct rx_securityClass *)0)
505 Abort("rxnull_NewServerSecurityObject");
507 rx_NewServiceHost(host, 0, VOLSERVICE_ID, "VOLSER", securityObjects, 3,
508 AFSVolExecuteRequest);
509 if (service == (struct rx_service *)0)
510 Abort("rx_NewService");
511 rx_SetBeforeProc(service, MyBeforeProc);
512 rx_SetAfterProc(service, MyAfterProc);
513 rx_SetIdleDeadTime(service, 0); /* never timeout */
516 rx_SetMaxProcs(service, lwps);
517 #if defined(AFS_XBSD_ENV)
518 rx_SetStackSize(service, (128 * 1024));
519 #elif defined(AFS_SGI_ENV)
520 rx_SetStackSize(service, (48 * 1024));
522 rx_SetStackSize(service, (32 * 1024));
525 if (rxkadDisableDotCheck) {
526 rx_SetSecurityConfiguration(service, RXS_CONFIG_FLAGS,
527 (void *)RXS_CONFIG_FLAGS_DISABLE_DOTCHECK,
532 rx_NewService(0, RX_STATS_SERVICE_ID, "rpcstats", securityObjects, 3,
533 RXSTATS_ExecuteRequest);
534 if (service == (struct rx_service *)0)
535 Abort("rx_NewService");
536 rx_SetMinProcs(service, 2);
537 rx_SetMaxProcs(service, 4);
539 Log("Starting AFS Volserver %s (%s)\n", VolserVersion, commandLine);
541 Log("Will sleep %d second%s every %d second%s\n", TTsleep,
542 (TTsleep > 1) ? "s" : "", TTrun + TTsleep,
543 (TTrun + TTsleep > 1) ? "s" : "");
546 /* allow super users to manage RX statistics */
547 rx_SetRxStatUserOk(vol_rxstat_userok);
549 rx_StartServer(1); /* Donate this process to the server process pool */
551 osi_audit(VS_FinishEvent, (-1), AUD_END);
552 Abort("StartServer returned?");
553 return 0; /* not reached */