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); \
85 MyBeforeProc(struct rx_call *acall)
94 MyAfterProc(struct rx_call *acall, afs_int32 code)
102 /* Called every GCWAKEUP seconds to try to unlock all our partitions,
103 * if we're idle and there are no active transactions
108 /* if there are no running calls, and there are no active transactions, then
109 * it should be safe to release any partition locks we've accumulated */
111 if (runningCalls == 0 && TransList() == (struct volser_trans *)0) {
113 VPFullUnlock(); /* in volprocs.c */
118 /* background daemon for timing out transactions */
120 BKGLoop(void *unused)
125 afs_pthread_setname_self("vol bkg");
127 tv.tv_sec = GCWAKEUP;
129 #ifdef AFS_PTHREAD_ENV
131 Sleep(GCWAKEUP * 1000);
133 select(0, 0, 0, 0, &tv);
136 (void)IOMGR_Select(0, 0, 0, 0, &tv);
141 if (loop == 10) { /* reopen log every 5 minutes */
143 ReOpenLog(AFSDIR_SERVER_VOLSERLOG_FILEPATH);
150 /* Background daemon for sleeping so the volserver does not become I/O bound */
151 afs_int32 TTsleep, TTrun;
152 #ifndef AFS_PTHREAD_ENV
154 BKGSleep(void *unused)
156 struct volser_trans *tt;
160 #ifdef AFS_PTHREAD_ENV
162 #else /* AFS_PTHREAD_ENV */
166 for (tt = TransList(); tt; tt = tt->next) {
168 if ((strcmp(tt->lastProcName, "DeleteVolume") == 0)
169 || (strcmp(tt->lastProcName, "Clone") == 0)
170 || (strcmp(tt->lastProcName, "ReClone") == 0)
171 || (strcmp(tt->lastProcName, "Forward") == 0)
172 || (strcmp(tt->lastProcName, "Restore") == 0)
173 || (strcmp(tt->lastProcName, "ForwardMulti") == 0)) {
174 VTRANS_OBJ_UNLOCK(tt);
177 VTRANS_OBJ_UNLOCK(tt);
191 /* no volser_syscall */
192 #elif defined(AFS_SUN511_ENV)
194 volser_syscall(afs_uint32 a3, afs_uint32 a4, void *a5)
197 code = ioctl_sun_afs_syscall(28 /* AFSCALL_CALL */, a3, a4, a5, 0, 0, 0,
206 volser_syscall(afs_uint32 a3, afs_uint32 a4, void *a5)
209 #ifndef AFS_LINUX20_ENV
212 old = signal(SIGSYS, SIG_IGN);
215 syscall(AFS_SYSCALL /* AFS_SYSCALL */ , 28 /* AFSCALL_CALL */ , a3,
217 #ifndef AFS_LINUX20_ENV
226 /* check whether caller is authorized to manage RX statistics */
228 vol_rxstat_userok(struct rx_call *call)
230 return afsconf_SuperUser(tdir, call, NULL);
233 #include "AFS_component_version_number.c"
235 main(int argc, char **argv)
238 struct rx_securityClass **securityClasses;
239 afs_int32 numClasses;
240 struct rx_service *service;
241 struct ktc_encryptionKey tkey;
243 int rxJumbograms = 0; /* default is to send and receive jumbograms. */
245 int bufSize = 0; /* temp variable to read in udp socket buf size */
246 afs_uint32 host = ntohl(INADDR_ANY);
247 char *auditFileName = NULL;
248 VolumePackageOptions opts;
252 * The following signal action for AIX is necessary so that in case of a
253 * crash (i.e. core is generated) we can include the user's data section
254 * in the core dump. Unfortunately, by default, only a partial core is
255 * generated which, in many cases, isn't too useful.
257 struct sigaction nsa;
259 sigemptyset(&nsa.sa_mask);
260 nsa.sa_handler = SIG_DFL;
261 nsa.sa_flags = SA_FULLDUMP;
262 sigaction(SIGABRT, &nsa, NULL);
263 sigaction(SIGSEGV, &nsa, NULL);
266 osi_audit(VS_StartEvent, 0, AUD_END);
268 /* Initialize dirpaths */
269 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
271 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
273 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
281 for (code = 1; code < argc; code++) {
282 if (strcmp(argv[code], "-log") == 0) {
283 /* set extra logging flag */
285 } else if (strcmp(argv[code], "-help") == 0) {
287 } else if (strcmp(argv[code], "-rxbind") == 0) {
289 } else if (strcmp(argv[code], "-allow-dotted-principals") == 0) {
290 rxkadDisableDotCheck = 1;
291 } else if (strcmp(argv[code], "-d") == 0) {
292 if ((code + 1) >= argc) {
293 fprintf(stderr, "missing argument for -d\n");
296 debuglevel = atoi(argv[++code]);
297 LogLevel = debuglevel;
298 } else if (strcmp(argv[code], "-p") == 0) {
299 lwps = atoi(argv[++code]);
301 printf("Warning: '-p %d' is too big; using %d instead\n",
305 } else if (strcmp(argv[code], "-auditlog") == 0) {
306 auditFileName = argv[++code];
308 } else if (strcmp(argv[code], "-audit-interface") == 0) {
309 char *interface = argv[++code];
311 if (osi_audit_interface(interface)) {
312 printf("Invalid audit interface '%s'\n", interface);
315 } else if (strcmp(argv[code], "-nojumbo") == 0) {
317 } else if (strcmp(argv[code], "-jumbo") == 0) {
319 } else if (!strcmp(argv[code], "-rxmaxmtu")) {
320 if ((code + 1) >= argc) {
321 fprintf(stderr, "missing argument for -rxmaxmtu\n");
324 rxMaxMTU = atoi(argv[++code]);
325 if ((rxMaxMTU < RX_MIN_PACKET_SIZE) ||
326 (rxMaxMTU > RX_MAX_PACKET_DATA_SIZE)) {
327 printf("rxMaxMTU %d invalid; must be between %d-%" AFS_SIZET_FMT "\n",
328 rxMaxMTU, RX_MIN_PACKET_SIZE,
329 RX_MAX_PACKET_DATA_SIZE);
332 } else if (strcmp(argv[code], "-sleep") == 0) {
333 sscanf(argv[++code], "%d/%d", &TTsleep, &TTrun);
334 if ((TTsleep < 0) || (TTrun <= 0)) {
335 printf("Warning: '-sleep %d/%d' is incorrect; ignoring\n",
339 } else if (strcmp(argv[code], "-udpsize") == 0) {
340 if ((code + 1) >= argc) {
341 printf("You have to specify -udpsize <integer value>\n");
344 sscanf(argv[++code], "%d", &bufSize);
345 if (bufSize < rx_GetMinUdpBufSize())
347 ("Warning:udpsize %d is less than minimum %d; ignoring\n",
348 bufSize, rx_GetMinUdpBufSize());
350 udpBufSize = bufSize;
351 } else if (strcmp(argv[code], "-enable_peer_stats") == 0) {
352 rx_enablePeerRPCStats();
353 } else if (strcmp(argv[code], "-enable_process_stats") == 0) {
354 rx_enableProcessRPCStats();
357 else if (strcmp(argv[code], "-syslog") == 0) {
358 /* set syslog logging flag */
360 } else if (strncmp(argv[code], "-syslog=", 8) == 0) {
362 serverLogSyslogFacility = atoi(argv[code] + 8);
366 printf("volserver: unrecognized flag '%s'\n", argv[code]);
369 printf("Usage: volserver [-log] [-p <number of processes>] "
370 "[-auditlog <log path>] [-d <debug level>] "
371 "[-nojumbo] [-jumbo] [-rxmaxmtu <bytes>] [-rxbind] [-allow-dotted-principals] "
372 "[-udpsize <size of socket buffer in bytes>] "
373 "[-syslog[=FACILITY]] "
374 "[-enable_peer_stats] [-enable_process_stats] "
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 "[-enable_peer_stats] [-enable_process_stats] "
389 osi_audit_file(auditFileName);
390 osi_audit(VS_StartEvent, 0, AUD_END);
392 #ifdef AFS_SGI_VNODE_GLUE
393 if (afs_init_kernel_config(-1) < 0) {
395 ("Can't determine NUMA configuration, not starting volserver.\n");
401 #ifdef AFS_PTHREAD_ENV
402 SetLogThreadNumProgram( rx_GetThreadNum );
406 if (afs_winsockInit() < 0) {
407 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
408 printf("Volume server unable to start winsock, exiting.\n");
412 /* Open VolserLog and map stdout, stderr into it; VInitVolumePackage2 can
413 log, so we need to do this here */
414 OpenLog(AFSDIR_SERVER_VOLSERLOG_FILEPATH);
416 VOptDefaults(volumeServer, &opts);
417 if (VInitVolumePackage2(volumeServer, &opts)) {
418 Log("Shutting down: errors encountered initializing volume package\n");
422 Lock_Init(&localLock);
424 #ifndef AFS_PTHREAD_ENV
425 vol_PollProc = IOMGR_Poll; /* tell vol pkg to poll io system periodically */
428 rxi_syscallp = volser_syscall;
430 rx_nPackets = rxpackets; /* set the max number of packets */
432 rx_SetUdpBufSize(udpBufSize); /* set the UDP buffer size for receive */
435 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH ||
436 AFSDIR_SERVER_NETINFO_FILEPATH) {
438 ccode = parseNetFiles(SHostAddrs, NULL, NULL,
439 ADDRSPERSITE, reason,
440 AFSDIR_SERVER_NETINFO_FILEPATH,
441 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
444 ccode = rx_getAllAddr(SHostAddrs, ADDRSPERSITE);
447 host = SHostAddrs[0];
450 code = rx_InitHost(host, (int)htons(AFSCONF_VOLUMEPORT));
452 fprintf(stderr, "rx init failed on socket AFSCONF_VOLUMEPORT %u\n",
457 /* Don't allow 3.4 vos clients to send jumbograms and we don't send. */
460 if (rxMaxMTU != -1) {
461 rx_SetMaxMTU(rxMaxMTU);
464 rx_SetRxDeadTime(420);
465 memset(busyFlags, 0, sizeof(busyFlags));
470 #ifdef AFS_PTHREAD_ENV
472 pthread_attr_t tattr;
473 osi_Assert(pthread_attr_init(&tattr) == 0);
474 osi_Assert(pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED) == 0);
476 osi_Assert(pthread_create(&tid, &tattr, BKGLoop, NULL) == 0);
479 LWP_CreateProcess(BKGLoop, 16*1024, 3, 0, "vol bkg daemon", &pid);
480 LWP_CreateProcess(BKGSleep,16*1024, 3, 0, "vol slp daemon", &pid);
484 /* 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 */
486 tdir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
488 Abort("volser: could not open conf files in %s\n",
489 AFSDIR_SERVER_ETC_DIRPATH);
492 afsconf_GetKey(tdir, 999, &tkey);
493 afsconf_BuildServerSecurityObjects(tdir, &securityClasses, &numClasses);
494 if (securityClasses[0] == NULL)
495 Abort("rxnull_NewServerSecurityObject");
497 rx_NewServiceHost(host, 0, VOLSERVICE_ID, "VOLSER", securityClasses,
498 numClasses, AFSVolExecuteRequest);
499 if (service == (struct rx_service *)0)
500 Abort("rx_NewService");
501 rx_SetBeforeProc(service, MyBeforeProc);
502 rx_SetAfterProc(service, MyAfterProc);
503 rx_SetIdleDeadTime(service, 0); /* never timeout */
506 rx_SetMaxProcs(service, lwps);
507 #if defined(AFS_XBSD_ENV)
508 rx_SetStackSize(service, (128 * 1024));
509 #elif defined(AFS_SGI_ENV)
510 rx_SetStackSize(service, (48 * 1024));
512 rx_SetStackSize(service, (32 * 1024));
515 if (rxkadDisableDotCheck) {
516 rx_SetSecurityConfiguration(service, RXS_CONFIG_FLAGS,
517 (void *)RXS_CONFIG_FLAGS_DISABLE_DOTCHECK);
521 rx_NewService(0, RX_STATS_SERVICE_ID, "rpcstats", securityClasses,
522 numClasses, RXSTATS_ExecuteRequest);
523 if (service == (struct rx_service *)0)
524 Abort("rx_NewService");
525 rx_SetMinProcs(service, 2);
526 rx_SetMaxProcs(service, 4);
528 LogCommandLine(argc, argv, "Volserver", VolserVersion, "Starting AFS",
531 Log("Will sleep %d second%s every %d second%s\n", TTsleep,
532 (TTsleep > 1) ? "s" : "", TTrun + TTsleep,
533 (TTrun + TTsleep > 1) ? "s" : "");
536 /* allow super users to manage RX statistics */
537 rx_SetRxStatUserOk(vol_rxstat_userok);
539 rx_StartServer(1); /* Donate this process to the server process pool */
541 osi_audit(VS_FinishEvent, (-1), AUD_END);
542 Abort("StartServer returned?");
543 return 0; /* not reached */