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>
15 #ifdef AFS_PTHREAD_ENV
16 # include <opr/lock.h>
21 #include <WINNT/afsevent.h>
24 #include <rx/rx_queue.h>
25 #include <afs/afsint.h>
26 #include <afs/prs_fs.h>
30 #include <afs/afssyscalls.h>
31 #include <afs/ihandle.h>
33 #include <afs/ntops.h>
35 #include <afs/vnode.h>
36 #include <afs/volume.h>
37 #include <afs/partition.h>
39 #include <rx/rxstat.h>
40 #include <rx/rx_globals.h>
42 #include <afs/cellconfig.h>
46 #include <afs/audit.h>
47 #include <afs/afsutil.h>
52 #include "volser_internal.h"
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;
75 int DoPreserveVolumeStats = 0;
77 #define ADDRSPERSITE 16 /* Same global is in rx/rx_user.c */
78 afs_uint32 SHostAddrs[ADDRSPERSITE];
80 #define VS_EXIT(code) { \
81 osi_audit(VS_ExitEvent, code, AUD_END); \
86 MyBeforeProc(struct rx_call *acall)
95 MyAfterProc(struct rx_call *acall, afs_int32 code)
103 /* Called every GCWAKEUP seconds to try to unlock all our partitions,
104 * if we're idle and there are no active transactions
109 /* if there are no running calls, and there are no active transactions, then
110 * it should be safe to release any partition locks we've accumulated */
112 if (runningCalls == 0 && TransList() == (struct volser_trans *)0) {
114 VPFullUnlock(); /* in volprocs.c */
119 /* background daemon for timing out transactions */
121 BKGLoop(void *unused)
126 afs_pthread_setname_self("vol bkg");
128 tv.tv_sec = GCWAKEUP;
130 #ifdef AFS_PTHREAD_ENV
132 Sleep(GCWAKEUP * 1000);
134 select(0, 0, 0, 0, &tv);
137 (void)IOMGR_Select(0, 0, 0, 0, &tv);
142 if (loop == 10) { /* reopen log every 5 minutes */
144 ReOpenLog(AFSDIR_SERVER_VOLSERLOG_FILEPATH);
151 /* Background daemon for sleeping so the volserver does not become I/O bound */
152 afs_int32 TTsleep, TTrun;
153 #ifndef AFS_PTHREAD_ENV
155 BKGSleep(void *unused)
157 struct volser_trans *tt;
161 #ifdef AFS_PTHREAD_ENV
163 #else /* AFS_PTHREAD_ENV */
167 for (tt = TransList(); tt; tt = tt->next) {
169 if ((strcmp(tt->lastProcName, "DeleteVolume") == 0)
170 || (strcmp(tt->lastProcName, "Clone") == 0)
171 || (strcmp(tt->lastProcName, "ReClone") == 0)
172 || (strcmp(tt->lastProcName, "Forward") == 0)
173 || (strcmp(tt->lastProcName, "Restore") == 0)
174 || (strcmp(tt->lastProcName, "ForwardMulti") == 0)) {
175 VTRANS_OBJ_UNLOCK(tt);
178 VTRANS_OBJ_UNLOCK(tt);
192 /* no volser_syscall */
193 #elif defined(AFS_SUN511_ENV)
195 volser_syscall(afs_uint32 a3, afs_uint32 a4, void *a5)
198 code = ioctl_sun_afs_syscall(28 /* AFSCALL_CALL */, a3, a4, a5, 0, 0, 0,
207 volser_syscall(afs_uint32 a3, afs_uint32 a4, void *a5)
210 #ifndef AFS_LINUX20_ENV
213 old = signal(SIGSYS, SIG_IGN);
216 syscall(AFS_SYSCALL /* AFS_SYSCALL */ , 28 /* AFSCALL_CALL */ , a3,
218 #ifndef AFS_LINUX20_ENV
227 /* check whether caller is authorized to manage RX statistics */
229 vol_rxstat_userok(struct rx_call *call)
231 return afsconf_SuperUser(tdir, call, NULL);
235 * Return true if this name is a member of the local realm.
238 vol_IsLocalRealmMatch(void *rock, char *name, char *inst, char *cell)
240 struct afsconf_dir *dir = (struct afsconf_dir *)rock;
241 afs_int32 islocal = 0; /* default to no */
244 code = afsconf_IsLocalRealmMatch(dir, &islocal, name, inst, cell);
247 ("Failed local realm check; code=%d, name=%s, inst=%s, cell=%s\n",
248 code, name, inst, cell));
253 #include "AFS_component_version_number.c"
255 main(int argc, char **argv)
258 struct rx_securityClass **securityClasses;
259 afs_int32 numClasses;
260 struct rx_service *service;
261 struct ktc_encryptionKey tkey;
263 int rxJumbograms = 0; /* default is to send and receive jumbograms. */
265 int bufSize = 0; /* temp variable to read in udp socket buf size */
266 afs_uint32 host = ntohl(INADDR_ANY);
267 char *auditFileName = NULL;
268 VolumePackageOptions opts;
272 * The following signal action for AIX is necessary so that in case of a
273 * crash (i.e. core is generated) we can include the user's data section
274 * in the core dump. Unfortunately, by default, only a partial core is
275 * generated which, in many cases, isn't too useful.
277 struct sigaction nsa;
279 sigemptyset(&nsa.sa_mask);
280 nsa.sa_handler = SIG_DFL;
281 nsa.sa_flags = SA_FULLDUMP;
282 sigaction(SIGABRT, &nsa, NULL);
283 sigaction(SIGSEGV, &nsa, NULL);
286 osi_audit(VS_StartEvent, 0, AUD_END);
288 /* Initialize dirpaths */
289 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
291 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
293 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
301 for (code = 1; code < argc; code++) {
302 if (strcmp(argv[code], "-log") == 0) {
303 /* set extra logging flag */
305 } else if (strcmp(argv[code], "-help") == 0) {
307 } else if (strcmp(argv[code], "-rxbind") == 0) {
309 } else if (strcmp(argv[code], "-allow-dotted-principals") == 0) {
310 rxkadDisableDotCheck = 1;
311 } else if (strcmp(argv[code], "-d") == 0) {
312 if ((code + 1) >= argc) {
313 fprintf(stderr, "missing argument for -d\n");
316 debuglevel = atoi(argv[++code]);
317 LogLevel = debuglevel;
318 } else if (strcmp(argv[code], "-p") == 0) {
319 lwps = atoi(argv[++code]);
321 printf("Warning: '-p %d' is too big; using %d instead\n",
325 } else if (strcmp(argv[code], "-auditlog") == 0) {
326 auditFileName = argv[++code];
328 } else if (strcmp(argv[code], "-audit-interface") == 0) {
329 char *interface = argv[++code];
331 if (osi_audit_interface(interface)) {
332 printf("Invalid audit interface '%s'\n", interface);
335 } else if (strcmp(argv[code], "-nojumbo") == 0) {
337 } else if (strcmp(argv[code], "-jumbo") == 0) {
339 } else if (!strcmp(argv[code], "-rxmaxmtu")) {
340 if ((code + 1) >= argc) {
341 fprintf(stderr, "missing argument for -rxmaxmtu\n");
344 rxMaxMTU = atoi(argv[++code]);
345 } else if (strcmp(argv[code], "-sleep") == 0) {
346 sscanf(argv[++code], "%d/%d", &TTsleep, &TTrun);
347 if ((TTsleep < 0) || (TTrun <= 0)) {
348 printf("Warning: '-sleep %d/%d' is incorrect; ignoring\n",
352 } else if (strcmp(argv[code], "-udpsize") == 0) {
353 if ((code + 1) >= argc) {
354 printf("You have to specify -udpsize <integer value>\n");
357 sscanf(argv[++code], "%d", &bufSize);
358 if (bufSize < rx_GetMinUdpBufSize())
360 ("Warning:udpsize %d is less than minimum %d; ignoring\n",
361 bufSize, rx_GetMinUdpBufSize());
363 udpBufSize = bufSize;
364 } else if (strcmp(argv[code], "-enable_peer_stats") == 0) {
365 rx_enablePeerRPCStats();
366 } else if (strcmp(argv[code], "-enable_process_stats") == 0) {
367 rx_enableProcessRPCStats();
368 } else if (strcmp(argv[code], "-preserve-vol-stats") == 0) {
369 DoPreserveVolumeStats = 1;
370 } else if (strcmp(argv[code], "-sync") == 0) {
371 if ((code + 1) >= argc) {
372 printf("You have to specify -sync <sync_behavior>\n");
376 if (ih_SetSyncBehavior(argv[++code])) {
377 printf("Invalid -sync value %s\n", argv[code]);
382 else if (strcmp(argv[code], "-syslog") == 0) {
383 /* set syslog logging flag */
385 } else if (strncmp(argv[code], "-syslog=", 8) == 0) {
387 serverLogSyslogFacility = atoi(argv[code] + 8);
391 printf("volserver: unrecognized flag '%s'\n", argv[code]);
394 printf("Usage: volserver [-log] [-p <number of processes>] "
395 "[-auditlog <log path>] [-d <debug level>] "
396 "[-nojumbo] [-jumbo] [-rxmaxmtu <bytes>] [-rxbind] [-allow-dotted-principals] "
397 "[-udpsize <size of socket buffer in bytes>] "
398 "[-syslog[=FACILITY]] "
399 "[-enable_peer_stats] [-enable_process_stats] "
400 "[-sync <always | onclose | never>] "
403 printf("Usage: volserver [-log] [-p <number of processes>] "
404 "[-auditlog <log path>] [-d <debug level>] "
405 "[-nojumbo] [-jumbo] [-rxmaxmtu <bytes>] [-rxbind] [-allow-dotted-principals] "
406 "[-udpsize <size of socket buffer in bytes>] "
407 "[-enable_peer_stats] [-enable_process_stats] "
408 "[-sync <always | onclose | never>] "
416 osi_audit_file(auditFileName);
417 osi_audit(VS_StartEvent, 0, AUD_END);
419 #ifdef AFS_SGI_VNODE_GLUE
420 if (afs_init_kernel_config(-1) < 0) {
422 ("Can't determine NUMA configuration, not starting volserver.\n");
428 #ifdef AFS_PTHREAD_ENV
429 SetLogThreadNumProgram( rx_GetThreadNum );
433 if (afs_winsockInit() < 0) {
434 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
435 printf("Volume server unable to start winsock, exiting.\n");
439 /* Open VolserLog and map stdout, stderr into it; VInitVolumePackage2 can
440 log, so we need to do this here */
441 OpenLog(AFSDIR_SERVER_VOLSERLOG_FILEPATH);
443 VOptDefaults(volumeServer, &opts);
444 if (VInitVolumePackage2(volumeServer, &opts)) {
445 Log("Shutting down: errors encountered initializing volume package\n");
449 Lock_Init(&localLock);
451 #ifndef AFS_PTHREAD_ENV
452 vol_PollProc = IOMGR_Poll; /* tell vol pkg to poll io system periodically */
455 rxi_syscallp = volser_syscall;
457 rx_nPackets = rxpackets; /* set the max number of packets */
459 rx_SetUdpBufSize(udpBufSize); /* set the UDP buffer size for receive */
462 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH ||
463 AFSDIR_SERVER_NETINFO_FILEPATH) {
465 ccode = afsconf_ParseNetFiles(SHostAddrs, NULL, NULL,
466 ADDRSPERSITE, reason,
467 AFSDIR_SERVER_NETINFO_FILEPATH,
468 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
471 ccode = rx_getAllAddr(SHostAddrs, ADDRSPERSITE);
474 host = SHostAddrs[0];
477 code = rx_InitHost(host, (int)htons(AFSCONF_VOLUMEPORT));
479 fprintf(stderr, "rx init failed on socket AFSCONF_VOLUMEPORT %u\n",
484 /* Don't allow 3.4 vos clients to send jumbograms and we don't send. */
487 if (rxMaxMTU != -1) {
488 if (rx_SetMaxMTU(rxMaxMTU) != 0) {
489 fprintf(stderr, "rxMaxMTU %d is invalid\n", rxMaxMTU);
494 rx_SetRxDeadTime(420);
495 memset(busyFlags, 0, sizeof(busyFlags));
500 #ifdef AFS_PTHREAD_ENV
502 pthread_attr_t tattr;
503 opr_Verify(pthread_attr_init(&tattr) == 0);
504 opr_Verify(pthread_attr_setdetachstate(&tattr,
505 PTHREAD_CREATE_DETACHED) == 0);
506 opr_Verify(pthread_create(&tid, &tattr, BKGLoop, NULL) == 0);
509 LWP_CreateProcess(BKGLoop, 16*1024, 3, 0, "vol bkg daemon", &pid);
510 LWP_CreateProcess(BKGSleep,16*1024, 3, 0, "vol slp daemon", &pid);
514 /* 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 */
516 tdir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
518 Abort("volser: could not open conf files in %s\n",
519 AFSDIR_SERVER_ETC_DIRPATH);
523 /* initialize audit user check */
524 osi_audit_set_user_check(tdir, vol_IsLocalRealmMatch);
526 afsconf_GetKey(tdir, 999, &tkey);
527 afsconf_BuildServerSecurityObjects(tdir, &securityClasses, &numClasses);
528 if (securityClasses[0] == NULL)
529 Abort("rxnull_NewServerSecurityObject");
531 rx_NewServiceHost(host, 0, VOLSERVICE_ID, "VOLSER", securityClasses,
532 numClasses, AFSVolExecuteRequest);
533 if (service == (struct rx_service *)0)
534 Abort("rx_NewService");
535 rx_SetBeforeProc(service, MyBeforeProc);
536 rx_SetAfterProc(service, MyAfterProc);
537 rx_SetIdleDeadTime(service, 0); /* never timeout */
540 rx_SetMaxProcs(service, lwps);
541 #if defined(AFS_XBSD_ENV)
542 rx_SetStackSize(service, (128 * 1024));
543 #elif defined(AFS_SGI_ENV)
544 rx_SetStackSize(service, (48 * 1024));
546 rx_SetStackSize(service, (32 * 1024));
549 if (rxkadDisableDotCheck) {
550 rx_SetSecurityConfiguration(service, RXS_CONFIG_FLAGS,
551 (void *)RXS_CONFIG_FLAGS_DISABLE_DOTCHECK);
555 rx_NewService(0, RX_STATS_SERVICE_ID, "rpcstats", securityClasses,
556 numClasses, RXSTATS_ExecuteRequest);
557 if (service == (struct rx_service *)0)
558 Abort("rx_NewService");
559 rx_SetMinProcs(service, 2);
560 rx_SetMaxProcs(service, 4);
562 LogCommandLine(argc, argv, "Volserver", VolserVersion, "Starting AFS",
565 Log("Will sleep %d second%s every %d second%s\n", TTsleep,
566 (TTsleep > 1) ? "s" : "", TTrun + TTsleep,
567 (TTrun + TTsleep > 1) ? "s" : "");
570 /* allow super users to manage RX statistics */
571 rx_SetRxStatUserOk(vol_rxstat_userok);
573 rx_StartServer(1); /* Donate this process to the server process pool */
575 osi_audit(VS_FinishEvent, (-1), AUD_END);
576 Abort("StartServer returned?");
577 return 0; /* not reached */