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/prs_fs.h>
26 #include <afs/afssyscalls.h>
27 #include <afs/ihandle.h>
29 #include <afs/ntops.h>
31 #include <afs/vnode.h>
32 #include <afs/volume.h>
33 #include <afs/partition.h>
35 #include <rx/rxstat.h>
36 #include <rx/rx_globals.h>
38 #include <afs/cellconfig.h>
42 #include <afs/audit.h>
43 #include <afs/afsutil.h>
48 #include "volser_internal.h"
50 #define VolserVersion "2.0"
51 #define N_SECURITY_OBJECTS 3
53 extern struct Lock localLock;
54 char *GlobalNameHack = NULL;
56 afs_int32 GlobalVolCloneId, GlobalVolParentId;
58 int VolumeChanged; /* XXXX */
59 static char busyFlags[MAXHELPERS];
60 struct volser_trans *QI_GlobalWriteTrans = 0;
61 struct afsconf_dir *tdir;
62 static afs_int32 runningCalls = 0;
67 int udpBufSize = 0; /* UDP buffer size for receive */
70 int rxkadDisableDotCheck = 0;
72 #define ADDRSPERSITE 16 /* Same global is in rx/rx_user.c */
73 afs_uint32 SHostAddrs[ADDRSPERSITE];
75 #define VS_EXIT(code) { \
76 osi_audit(VS_ExitEvent, code, AUD_END); \
81 MyBeforeProc(struct rx_call *acall)
90 MyAfterProc(struct rx_call *acall, afs_int32 code)
98 /* Called every GCWAKEUP seconds to try to unlock all our partitions,
99 * if we're idle and there are no active transactions
104 /* if there are no running calls, and there are no active transactions, then
105 * it should be safe to release any partition locks we've accumulated */
107 if (runningCalls == 0 && TransList() == (struct volser_trans *)0) {
109 VPFullUnlock(); /* in volprocs.c */
114 /* background daemon for timing out transactions */
116 BKGLoop(void *unused)
121 afs_pthread_setname_self("vol bkg");
123 tv.tv_sec = GCWAKEUP;
125 #ifdef AFS_PTHREAD_ENV
127 Sleep(GCWAKEUP * 1000);
129 select(0, 0, 0, 0, &tv);
132 (void)IOMGR_Select(0, 0, 0, 0, &tv);
137 if (loop == 10) { /* reopen log every 5 minutes */
139 ReOpenLog(AFSDIR_SERVER_VOLSERLOG_FILEPATH);
146 /* Background daemon for sleeping so the volserver does not become I/O bound */
147 afs_int32 TTsleep, TTrun;
148 #ifndef AFS_PTHREAD_ENV
150 BKGSleep(void *unused)
152 struct volser_trans *tt;
156 #ifdef AFS_PTHREAD_ENV
158 #else /* AFS_PTHREAD_ENV */
162 for (tt = TransList(); tt; tt = tt->next) {
164 if ((strcmp(tt->lastProcName, "DeleteVolume") == 0)
165 || (strcmp(tt->lastProcName, "Clone") == 0)
166 || (strcmp(tt->lastProcName, "ReClone") == 0)
167 || (strcmp(tt->lastProcName, "Forward") == 0)
168 || (strcmp(tt->lastProcName, "Restore") == 0)
169 || (strcmp(tt->lastProcName, "ForwardMulti") == 0)) {
170 VTRANS_OBJ_UNLOCK(tt);
173 VTRANS_OBJ_UNLOCK(tt);
187 /* no volser_syscall */
188 #elif defined(AFS_SUN511_ENV)
190 volser_syscall(afs_uint32 a3, afs_uint32 a4, void *a5)
193 code = ioctl_sun_afs_syscall(28 /* AFSCALL_CALL */, a3, a4, a5, 0, 0, 0,
202 volser_syscall(afs_uint32 a3, afs_uint32 a4, void *a5)
205 #ifndef AFS_LINUX20_ENV
208 old = signal(SIGSYS, SIG_IGN);
211 syscall(AFS_SYSCALL /* AFS_SYSCALL */ , 28 /* AFSCALL_CALL */ , a3,
213 #ifndef AFS_LINUX20_ENV
222 /* check whether caller is authorized to manage RX statistics */
224 vol_rxstat_userok(struct rx_call *call)
226 return afsconf_SuperUser(tdir, call, NULL);
229 #include "AFS_component_version_number.c"
231 main(int argc, char **argv)
234 struct rx_securityClass **securityClasses;
235 afs_int32 numClasses;
236 struct rx_service *service;
237 struct ktc_encryptionKey tkey;
239 int rxJumbograms = 0; /* default is to send and receive jumbograms. */
241 int bufSize = 0; /* temp variable to read in udp socket buf size */
242 afs_uint32 host = ntohl(INADDR_ANY);
243 char *auditFileName = NULL;
244 VolumePackageOptions opts;
248 * The following signal action for AIX is necessary so that in case of a
249 * crash (i.e. core is generated) we can include the user's data section
250 * in the core dump. Unfortunately, by default, only a partial core is
251 * generated which, in many cases, isn't too useful.
253 struct sigaction nsa;
255 sigemptyset(&nsa.sa_mask);
256 nsa.sa_handler = SIG_DFL;
257 nsa.sa_flags = SA_FULLDUMP;
258 sigaction(SIGABRT, &nsa, NULL);
259 sigaction(SIGSEGV, &nsa, NULL);
262 osi_audit(VS_StartEvent, 0, AUD_END);
264 /* Initialize dirpaths */
265 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
267 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
269 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
277 for (code = 1; code < argc; code++) {
278 if (strcmp(argv[code], "-log") == 0) {
279 /* set extra logging flag */
281 } else if (strcmp(argv[code], "-help") == 0) {
283 } else if (strcmp(argv[code], "-rxbind") == 0) {
285 } else if (strcmp(argv[code], "-allow-dotted-principals") == 0) {
286 rxkadDisableDotCheck = 1;
287 } else if (strcmp(argv[code], "-d") == 0) {
288 if ((code + 1) >= argc) {
289 fprintf(stderr, "missing argument for -d\n");
292 debuglevel = atoi(argv[++code]);
293 LogLevel = debuglevel;
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) {
302 auditFileName = argv[++code];
304 } else if (strcmp(argv[code], "-audit-interface") == 0) {
305 char *interface = argv[++code];
307 if (osi_audit_interface(interface)) {
308 printf("Invalid audit interface '%s'\n", interface);
311 } else if (strcmp(argv[code], "-nojumbo") == 0) {
313 } else if (strcmp(argv[code], "-jumbo") == 0) {
315 } else if (!strcmp(argv[code], "-rxmaxmtu")) {
316 if ((code + 1) >= argc) {
317 fprintf(stderr, "missing argument for -rxmaxmtu\n");
320 rxMaxMTU = atoi(argv[++code]);
321 } else if (strcmp(argv[code], "-sleep") == 0) {
322 sscanf(argv[++code], "%d/%d", &TTsleep, &TTrun);
323 if ((TTsleep < 0) || (TTrun <= 0)) {
324 printf("Warning: '-sleep %d/%d' is incorrect; ignoring\n",
328 } else if (strcmp(argv[code], "-udpsize") == 0) {
329 if ((code + 1) >= argc) {
330 printf("You have to specify -udpsize <integer value>\n");
333 sscanf(argv[++code], "%d", &bufSize);
334 if (bufSize < rx_GetMinUdpBufSize())
336 ("Warning:udpsize %d is less than minimum %d; ignoring\n",
337 bufSize, rx_GetMinUdpBufSize());
339 udpBufSize = bufSize;
340 } else if (strcmp(argv[code], "-enable_peer_stats") == 0) {
341 rx_enablePeerRPCStats();
342 } else if (strcmp(argv[code], "-enable_process_stats") == 0) {
343 rx_enableProcessRPCStats();
346 else if (strcmp(argv[code], "-syslog") == 0) {
347 /* set syslog logging flag */
349 } else if (strncmp(argv[code], "-syslog=", 8) == 0) {
351 serverLogSyslogFacility = atoi(argv[code] + 8);
355 printf("volserver: unrecognized flag '%s'\n", argv[code]);
358 printf("Usage: volserver [-log] [-p <number of processes>] "
359 "[-auditlog <log path>] [-d <debug level>] "
360 "[-nojumbo] [-jumbo] [-rxmaxmtu <bytes>] [-rxbind] [-allow-dotted-principals] "
361 "[-udpsize <size of socket buffer in bytes>] "
362 "[-syslog[=FACILITY]] "
363 "[-enable_peer_stats] [-enable_process_stats] "
366 printf("Usage: volserver [-log] [-p <number of processes>] "
367 "[-auditlog <log path>] [-d <debug level>] "
368 "[-nojumbo] [-jumbo] [-rxmaxmtu <bytes>] [-rxbind] [-allow-dotted-principals] "
369 "[-udpsize <size of socket buffer in bytes>] "
370 "[-enable_peer_stats] [-enable_process_stats] "
378 osi_audit_file(auditFileName);
379 osi_audit(VS_StartEvent, 0, AUD_END);
381 #ifdef AFS_SGI_VNODE_GLUE
382 if (afs_init_kernel_config(-1) < 0) {
384 ("Can't determine NUMA configuration, not starting volserver.\n");
390 #ifdef AFS_PTHREAD_ENV
391 SetLogThreadNumProgram( rx_GetThreadNum );
395 if (afs_winsockInit() < 0) {
396 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
397 printf("Volume server unable to start winsock, exiting.\n");
401 /* Open VolserLog and map stdout, stderr into it; VInitVolumePackage2 can
402 log, so we need to do this here */
403 OpenLog(AFSDIR_SERVER_VOLSERLOG_FILEPATH);
405 VOptDefaults(volumeServer, &opts);
406 if (VInitVolumePackage2(volumeServer, &opts)) {
407 Log("Shutting down: errors encountered initializing volume package\n");
411 Lock_Init(&localLock);
413 #ifndef AFS_PTHREAD_ENV
414 vol_PollProc = IOMGR_Poll; /* tell vol pkg to poll io system periodically */
417 rxi_syscallp = volser_syscall;
419 rx_nPackets = rxpackets; /* set the max number of packets */
421 rx_SetUdpBufSize(udpBufSize); /* set the UDP buffer size for receive */
424 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH ||
425 AFSDIR_SERVER_NETINFO_FILEPATH) {
427 ccode = parseNetFiles(SHostAddrs, NULL, NULL,
428 ADDRSPERSITE, reason,
429 AFSDIR_SERVER_NETINFO_FILEPATH,
430 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
433 ccode = rx_getAllAddr(SHostAddrs, ADDRSPERSITE);
436 host = SHostAddrs[0];
439 code = rx_InitHost(host, (int)htons(AFSCONF_VOLUMEPORT));
441 fprintf(stderr, "rx init failed on socket AFSCONF_VOLUMEPORT %u\n",
446 /* Don't allow 3.4 vos clients to send jumbograms and we don't send. */
449 if (rxMaxMTU != -1) {
450 if (rx_SetMaxMTU(rxMaxMTU) != 0) {
451 fprintf(stderr, "rxMaxMTU %d is invalid\n", rxMaxMTU);
456 rx_SetRxDeadTime(420);
457 memset(busyFlags, 0, sizeof(busyFlags));
462 #ifdef AFS_PTHREAD_ENV
464 pthread_attr_t tattr;
465 osi_Assert(pthread_attr_init(&tattr) == 0);
466 osi_Assert(pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED) == 0);
468 osi_Assert(pthread_create(&tid, &tattr, BKGLoop, NULL) == 0);
471 LWP_CreateProcess(BKGLoop, 16*1024, 3, 0, "vol bkg daemon", &pid);
472 LWP_CreateProcess(BKGSleep,16*1024, 3, 0, "vol slp daemon", &pid);
476 /* 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 */
478 tdir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
480 Abort("volser: could not open conf files in %s\n",
481 AFSDIR_SERVER_ETC_DIRPATH);
484 afsconf_GetKey(tdir, 999, &tkey);
485 afsconf_BuildServerSecurityObjects(tdir, &securityClasses, &numClasses);
486 if (securityClasses[0] == NULL)
487 Abort("rxnull_NewServerSecurityObject");
489 rx_NewServiceHost(host, 0, VOLSERVICE_ID, "VOLSER", securityClasses,
490 numClasses, AFSVolExecuteRequest);
491 if (service == (struct rx_service *)0)
492 Abort("rx_NewService");
493 rx_SetBeforeProc(service, MyBeforeProc);
494 rx_SetAfterProc(service, MyAfterProc);
495 rx_SetIdleDeadTime(service, 0); /* never timeout */
498 rx_SetMaxProcs(service, lwps);
499 #if defined(AFS_XBSD_ENV)
500 rx_SetStackSize(service, (128 * 1024));
501 #elif defined(AFS_SGI_ENV)
502 rx_SetStackSize(service, (48 * 1024));
504 rx_SetStackSize(service, (32 * 1024));
507 if (rxkadDisableDotCheck) {
508 rx_SetSecurityConfiguration(service, RXS_CONFIG_FLAGS,
509 (void *)RXS_CONFIG_FLAGS_DISABLE_DOTCHECK);
513 rx_NewService(0, RX_STATS_SERVICE_ID, "rpcstats", securityClasses,
514 numClasses, RXSTATS_ExecuteRequest);
515 if (service == (struct rx_service *)0)
516 Abort("rx_NewService");
517 rx_SetMinProcs(service, 2);
518 rx_SetMaxProcs(service, 4);
520 LogCommandLine(argc, argv, "Volserver", VolserVersion, "Starting AFS",
523 Log("Will sleep %d second%s every %d second%s\n", TTsleep,
524 (TTsleep > 1) ? "s" : "", TTrun + TTsleep,
525 (TTrun + TTsleep > 1) ? "s" : "");
528 /* allow super users to manage RX statistics */
529 rx_SetRxStatUserOk(vol_rxstat_userok);
531 rx_StartServer(1); /* Donate this process to the server process pool */
533 osi_audit(VS_FinishEvent, (-1), AUD_END);
534 Abort("StartServer returned?");
535 return 0; /* not reached */