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 int AFSVolExecuteRequest(struct rx_call*);
83 extern int RXSTATS_ExecuteRequest(struct rx_call*);
84 struct afsconf_dir *tdir;
85 static afs_int32 runningCalls = 0;
90 int udpBufSize = 0; /* UDP buffer size for receive */
93 int rxkadDisableDotCheck = 0;
95 #define ADDRSPERSITE 16 /* Same global is in rx/rx_user.c */
96 afs_uint32 SHostAddrs[ADDRSPERSITE];
98 #define VS_EXIT(code) { \
99 osi_audit(VS_ExitEvent, code, AUD_END); \
103 #if defined(AFS_PTHREAD_ENV)
107 return (int)pthread_getspecific(rx_thread_id_key);
112 MyBeforeProc(struct rx_call *acall)
121 MyAfterProc(struct rx_call *acall, afs_int32 code)
129 /* Called every GCWAKEUP seconds to try to unlock all our partitions,
130 * if we're idle and there are no active transactions
135 /* if there are no running calls, and there are no active transactions, then
136 * it should be safe to release any partition locks we've accumulated */
138 if (runningCalls == 0 && TransList() == (struct volser_trans *)0) {
140 VPFullUnlock(); /* in volprocs.c */
145 /* background daemon for timing out transactions */
147 BKGLoop(void *unused)
153 tv.tv_sec = GCWAKEUP;
155 #ifdef AFS_PTHREAD_ENV
156 select(0, 0, 0, 0, &tv);
158 (void)IOMGR_Select(0, 0, 0, 0, &tv);
163 if (loop == 10) { /* reopen log every 5 minutes */
165 ReOpenLog(AFSDIR_SERVER_VOLSERLOG_FILEPATH);
172 /* Background daemon for sleeping so the volserver does not become I/O bound */
173 afs_int32 TTsleep, TTrun;
175 BKGSleep(void *unused)
177 struct volser_trans *tt;
181 #ifdef AFS_PTHREAD_ENV
183 #else /* AFS_PTHREAD_ENV */
187 for (tt = TransList(); tt; tt = tt->next) {
188 if ((strcmp(tt->lastProcName, "DeleteVolume") == 0)
189 || (strcmp(tt->lastProcName, "Clone") == 0)
190 || (strcmp(tt->lastProcName, "ReClone") == 0)
191 || (strcmp(tt->lastProcName, "Forward") == 0)
192 || (strcmp(tt->lastProcName, "Restore") == 0)
193 || (strcmp(tt->lastProcName, "ForwardMulti") == 0))
208 volser_syscall(afs_uint32 a3, afs_uint32 a4, void *a5)
213 #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);
253 * The following signal action for AIX is necessary so that in case of a
254 * crash (i.e. core is generated) we can include the user's data section
255 * in the core dump. Unfortunately, by default, only a partial core is
256 * generated which, in many cases, isn't too useful.
258 struct sigaction nsa;
260 sigemptyset(&nsa.sa_mask);
261 nsa.sa_handler = SIG_DFL;
262 nsa.sa_flags = SA_FULLDUMP;
263 sigaction(SIGABRT, &nsa, NULL);
264 sigaction(SIGSEGV, &nsa, NULL);
267 osi_audit(VS_StartEvent, 0, AUD_END);
269 /* Initialize dirpaths */
270 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
272 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
274 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
279 for (commandLine[0] = '\0', i = 0; i < argc; i++) {
281 strcat(commandLine, " ");
282 strcat(commandLine, argv[i]);
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 char *fileName = argv[++code];
315 osi_audit_file(fileName);
316 osi_audit(VS_StartEvent, 0, AUD_END);
317 } else if (strcmp(argv[code], "-nojumbo") == 0) {
319 } else if (strcmp(argv[code], "-jumbo") == 0) {
321 } else if (!strcmp(argv[code], "-rxmaxmtu")) {
322 if ((code + 1) >= argc) {
323 fprintf(stderr, "missing argument for -rxmaxmtu\n");
326 rxMaxMTU = atoi(argv[++code]);
327 if ((rxMaxMTU < RX_MIN_PACKET_SIZE) ||
328 (rxMaxMTU > RX_MAX_PACKET_DATA_SIZE)) {
329 printf("rxMaxMTU %lu invalid; must be between %d-%d\n",
330 rxMaxMTU, RX_MIN_PACKET_SIZE,
331 RX_MAX_PACKET_DATA_SIZE);
334 } else if (strcmp(argv[code], "-sleep") == 0) {
335 sscanf(argv[++code], "%d/%d", &TTsleep, &TTrun);
336 if ((TTsleep < 0) || (TTrun <= 0)) {
337 printf("Warning: '-sleep %d/%d' is incorrect; ignoring\n",
341 } else if (strcmp(argv[code], "-udpsize") == 0) {
342 if ((code + 1) >= argc) {
343 printf("You have to specify -udpsize <integer value>\n");
346 sscanf(argv[++code], "%d", &bufSize);
347 if (bufSize < rx_GetMinUdpBufSize())
349 ("Warning:udpsize %d is less than minimum %d; ignoring\n",
350 bufSize, rx_GetMinUdpBufSize());
352 udpBufSize = bufSize;
353 } else if (strcmp(argv[code], "-enable_peer_stats") == 0) {
354 rx_enablePeerRPCStats();
355 } else if (strcmp(argv[code], "-enable_process_stats") == 0) {
356 rx_enableProcessRPCStats();
359 else if (strcmp(argv[code], "-syslog") == 0) {
360 /* set syslog logging flag */
362 } else if (strncmp(argv[code], "-syslog=", 8) == 0) {
364 serverLogSyslogFacility = atoi(argv[code] + 8);
368 printf("volserver: unrecognized flag '%s'\n", argv[code]);
371 printf("Usage: volserver [-log] [-p <number of processes>] "
372 "[-auditlog <log path>] [-d <debug level>] "
373 "[-nojumbo] [-jumbo] [-rxmaxmtu <bytes>] [-rxbind] [-allow-dotted-principals] "
374 "[-udpsize <size of socket buffer in bytes>] "
375 "[-syslog[=FACILITY]] "
376 "[-enable_peer_stats] [-enable_process_stats] "
379 printf("Usage: volserver [-log] [-p <number of processes>] "
380 "[-auditlog <log path>] [-d <debug level>] "
381 "[-nojumbo] [-jumbo] [-rxmaxmtu <bytes>] [-rxbind] [-allow-dotted-principals] "
382 "[-udpsize <size of socket buffer in bytes>] "
383 "[-enable_peer_stats] [-enable_process_stats] "
389 #ifdef AFS_SGI_VNODE_GLUE
390 if (afs_init_kernel_config(-1) < 0) {
392 ("Can't determine NUMA configuration, not starting volserver.\n");
398 #ifdef AFS_PTHREAD_ENV
399 SetLogThreadNumProgram( threadNum );
403 if (afs_winsockInit() < 0) {
404 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
405 printf("Volume server unable to start winsock, exiting.\n");
409 /* Open VolserLog and map stdout, stderr into it; VInitVolumePackage can
410 log, so we need to do this here */
411 OpenLog(AFSDIR_SERVER_VOLSERLOG_FILEPATH);
413 VInitVolumePackage(volumeUtility, 0, 0, CONNECT_FS, 0);
415 Lock_Init(&localLock);
417 #ifndef AFS_PTHREAD_ENV
418 vol_PollProc = IOMGR_Poll; /* tell vol pkg to poll io system periodically */
421 rxi_syscallp = volser_syscall;
423 rx_nPackets = rxpackets; /* set the max number of packets */
425 rx_SetUdpBufSize(udpBufSize); /* set the UDP buffer size for receive */
428 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH ||
429 AFSDIR_SERVER_NETINFO_FILEPATH) {
431 ccode = parseNetFiles(SHostAddrs, NULL, NULL,
432 ADDRSPERSITE, reason,
433 AFSDIR_SERVER_NETINFO_FILEPATH,
434 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
437 ccode = rx_getAllAddr(SHostAddrs, ADDRSPERSITE);
440 host = SHostAddrs[0];
443 code = rx_InitHost(host, (int)htons(AFSCONF_VOLUMEPORT));
445 fprintf(stderr, "rx init failed on socket AFSCONF_VOLUMEPORT %u\n",
450 /* Don't allow 3.4 vos clients to send jumbograms and we don't send. */
453 if (rxMaxMTU != -1) {
454 rx_SetMaxMTU(rxMaxMTU);
457 rx_SetRxDeadTime(420);
458 memset(busyFlags, 0, sizeof(busyFlags));
463 #ifdef AFS_PTHREAD_ENV
465 pthread_attr_t tattr;
466 assert(pthread_attr_init(&tattr) == 0);
467 assert(pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED) == 0);
469 assert(pthread_create(&tid, &tattr, BKGLoop, NULL) == 0);
472 LWP_CreateProcess(BKGLoop, 16*1024, 3, 0, "vol bkg daemon", &pid);
473 LWP_CreateProcess(BKGSleep,16*1024, 3, 0, "vol slp daemon", &pid);
477 /* 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 */
479 tdir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
481 Abort("volser: could not open conf files in %s\n",
482 AFSDIR_SERVER_ETC_DIRPATH);
485 afsconf_GetKey(tdir, 999, &tkey);
486 securityObjects[0] = rxnull_NewServerSecurityObject();
487 securityObjects[1] = (struct rx_securityClass *)0; /* don't bother with rxvab */
489 rxkad_NewServerSecurityObject(0, tdir, afsconf_GetKey, NULL);
490 if (securityObjects[0] == (struct rx_securityClass *)0)
491 Abort("rxnull_NewServerSecurityObject");
493 rx_NewServiceHost(host, 0, VOLSERVICE_ID, "VOLSER", securityObjects, 3,
494 AFSVolExecuteRequest);
495 if (service == (struct rx_service *)0)
496 Abort("rx_NewService");
497 rx_SetBeforeProc(service, MyBeforeProc);
498 rx_SetAfterProc(service, MyAfterProc);
499 rx_SetIdleDeadTime(service, 0); /* never timeout */
502 rx_SetMaxProcs(service, lwps);
503 #if defined(AFS_XBSD_ENV)
504 rx_SetStackSize(service, (128 * 1024));
505 #elif defined(AFS_SGI_ENV)
506 rx_SetStackSize(service, (48 * 1024));
508 rx_SetStackSize(service, (32 * 1024));
511 if (rxkadDisableDotCheck) {
512 rx_SetSecurityConfiguration(service, RXS_CONFIG_FLAGS,
513 (void *)RXS_CONFIG_FLAGS_DISABLE_DOTCHECK);
517 rx_NewService(0, RX_STATS_SERVICE_ID, "rpcstats", securityObjects, 3,
518 RXSTATS_ExecuteRequest);
519 if (service == (struct rx_service *)0)
520 Abort("rx_NewService");
521 rx_SetMinProcs(service, 2);
522 rx_SetMaxProcs(service, 4);
524 Log("Starting AFS Volserver %s (%s)\n", VolserVersion, commandLine);
526 Log("Will sleep %d second%s every %d second%s\n", TTsleep,
527 (TTsleep > 1) ? "s" : "", TTrun + TTsleep,
528 (TTrun + TTsleep > 1) ? "s" : "");
531 /* allow super users to manage RX statistics */
532 rx_SetRxStatUserOk(vol_rxstat_userok);
534 rx_StartServer(1); /* Donate this process to the server process pool */
536 osi_audit(VS_FinishEvent, (-1), AUD_END);
537 Abort("StartServer returned?");
538 return 0; /* not reached */