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>
21 #include <WINNT/afsevent.h>
25 #include <netinet/in.h>
35 #include <afs/afsint.h>
38 #ifdef AFS_PTHREAD_ENV
40 #else /* AFS_PTHREAD_ENV */
41 #include <afs/assert.h>
42 #endif /* AFS_PTHREAD_ENV */
43 #include <afs/prs_fs.h>
47 #include <afs/afssyscalls.h>
48 #include <afs/ihandle.h>
50 #include <afs/ntops.h>
52 #include <afs/vnode.h>
53 #include <afs/volume.h>
54 #include <afs/partition.h>
56 #include <rx/rx_globals.h>
59 #include <afs/cellconfig.h>
65 #include <afs/audit.h>
66 #include <afs/afsutil.h>
68 /*@printflike@*/ extern void Log(const char *format, ...);
69 /*@printflike@*/ extern void Abort(const char *format, ...);
71 #define VolserVersion "2.0"
72 #define N_SECURITY_OBJECTS 3
74 extern struct volser_trans *TransList();
75 #ifndef AFS_PTHREAD_ENV
76 extern int (*vol_PollProc) ();
77 extern int IOMGR_Poll();
79 char *GlobalNameHack = NULL;
81 afs_int32 GlobalVolCloneId, GlobalVolParentId;
83 int VolumeChanged; /* XXXX */
84 static char busyFlags[MAXHELPERS];
85 struct volser_trans *QI_GlobalWriteTrans = 0;
86 extern void AFSVolExecuteRequest();
87 extern void RXSTATS_ExecuteRequest();
88 struct afsconf_dir *tdir;
89 static afs_int32 runningCalls = 0;
93 int udpBufSize = 0; /* UDP buffer size for receive */
95 int Testing = 0; /* for ListViceInodes */
97 #define VS_EXIT(code) { \
98 osi_audit(VS_ExitEvent, code, AUD_END); \
104 MyBeforeProc(struct rx_call *acall)
113 MyAfterProc(struct rx_call *acall, afs_int32 code)
121 /* Called every GCWAKEUP seconds to try to unlock all our partitions,
122 * if we're idle and there are no active transactions
127 /* if there are no running calls, and there are no active transactions, then
128 * it should be safe to release any partition locks we've accumulated */
130 if (runningCalls == 0 && TransList() == (struct volser_trans *)0) {
132 VPFullUnlock(); /* in volprocs.c */
137 /* background daemon for timing out transactions */
145 tv.tv_sec = GCWAKEUP;
147 #ifdef AFS_PTHREAD_ENV
148 select(0, 0, 0, 0, &tv);
150 (void)IOMGR_Select(0, 0, 0, 0, &tv);
155 if (loop == 10) { /* reopen log every 5 minutes */
157 ReOpenLog(AFSDIR_SERVER_VOLSERLOG_FILEPATH);
162 /* Background daemon for sleeping so the volserver does not become I/O bound */
163 afs_int32 TTsleep, TTrun;
167 struct volser_trans *tt;
171 #ifdef AFS_PTHREAD_ENV
173 #else /* AFS_PTHREAD_ENV */
177 for (tt = TransList(); tt; tt = tt->next) {
178 if ((strcmp(tt->lastProcName, "DeleteVolume") == 0)
179 || (strcmp(tt->lastProcName, "Clone") == 0)
180 || (strcmp(tt->lastProcName, "ReClone") == 0)
181 || (strcmp(tt->lastProcName, "Forward") == 0)
182 || (strcmp(tt->lastProcName, "Restore") == 0)
183 || (strcmp(tt->lastProcName, "ForwardMulti") == 0))
197 volser_syscall(afs_uint32 a3, afs_uint32 a4, void *a5)
202 #ifndef AFS_LINUX20_ENV
203 old = signal(SIGSYS, SIG_IGN);
206 syscall(AFS_SYSCALL /* AFS_SYSCALL */ , 28 /* AFSCALL_CALL */ , a3,
208 #ifndef AFS_LINUX20_ENV
217 /* check whether caller is authorized to manage RX statistics */
219 vol_rxstat_userok(struct rx_call *call)
221 return afsconf_SuperUser(tdir, call, NULL);
224 #include "AFS_component_version_number.c"
226 main(int argc, char **argv)
228 register afs_int32 code;
229 struct rx_securityClass *(securityObjects[3]);
230 struct rx_service *service;
231 struct ktc_encryptionKey tkey;
233 char commandLine[150];
235 int rxJumbograms = 1; /* default is to send and receive jumbograms. */
236 int bufSize = 0; /* temp variable to read in udp socket buf size */
240 * The following signal action for AIX is necessary so that in case of a
241 * crash (i.e. core is generated) we can include the user's data section
242 * in the core dump. Unfortunately, by default, only a partial core is
243 * generated which, in many cases, isn't too useful.
245 struct sigaction nsa;
247 sigemptyset(&nsa.sa_mask);
248 nsa.sa_handler = SIG_DFL;
249 nsa.sa_flags = SA_FULLDUMP;
250 sigaction(SIGABRT, &nsa, NULL);
251 sigaction(SIGSEGV, &nsa, NULL);
253 osi_audit(VS_StartEvent, 0, AUD_END);
255 /* Initialize dirpaths */
256 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
258 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
260 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
265 for (commandLine[0] = '\0', i = 0; i < argc; i++) {
267 strcat(commandLine, " ");
268 strcat(commandLine, argv[i]);
274 for (code = 1; code < argc; code++) {
275 if (strcmp(argv[code], "-log") == 0) {
276 /* set extra logging flag */
278 } else if (strcmp(argv[code], "-help") == 0) {
280 } else if (strcmp(argv[code], "-p") == 0) {
281 lwps = atoi(argv[++code]);
283 printf("Warning: '-p %d' is too big; using %d instead\n",
287 } else if (strcmp(argv[code], "-nojumbo") == 0) {
289 } else if (strcmp(argv[code], "-sleep") == 0) {
290 sscanf(argv[++code], "%d/%d", &TTsleep, &TTrun);
291 if ((TTsleep < 0) || (TTrun <= 0)) {
292 printf("Warning: '-sleep %d/%d' is incorrect; ignoring\n",
296 } else if (strcmp(argv[code], "-udpsize") == 0) {
297 if ((code + 1) >= argc) {
298 printf("You have to specify -udpsize <integer value>\n");
301 sscanf(argv[++code], "%d", &bufSize);
302 if (bufSize < rx_GetMinUdpBufSize())
304 ("Warning:udpsize %d is less than minimum %d; ignoring\n",
305 bufSize, rx_GetMinUdpBufSize());
307 udpBufSize = bufSize;
308 } else if (strcmp(argv[code], "-enable_peer_stats") == 0) {
309 rx_enablePeerRPCStats();
310 } else if (strcmp(argv[code], "-enable_process_stats") == 0) {
311 rx_enableProcessRPCStats();
314 else if (strcmp(argv[code], "-syslog") == 0) {
315 /* set syslog logging flag */
317 } else if (strncmp(argv[code], "-syslog=", 8) == 0) {
319 serverLogSyslogFacility = atoi(argv[code] + 8);
323 printf("volserver: unrecognized flag '%s'\n", argv[code]);
326 printf("Usage: volserver [-log] [-p <number of processes>] "
327 "[-udpsize <size of socket buffer in bytes>] "
328 "[-syslog[=FACILITY]] "
329 "[-enable_peer_stats] [-enable_process_stats] "
332 printf("Usage: volserver [-log] [-p <number of processes>] "
333 "[-udpsize <size of socket buffer in bytes>] "
334 "[-enable_peer_stats] [-enable_process_stats] "
340 #ifdef AFS_SGI_VNODE_GLUE
341 if (afs_init_kernel_config(-1) < 0) {
343 ("Can't determine NUMA configuration, not starting volserver.\n");
350 if (afs_winsockInit() < 0) {
351 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
352 printf("Volume server unable to start winsock, exiting.\n");
356 VInitVolumePackage(volumeUtility, 0, 0, CONNECT_FS, 0);
358 #ifndef AFS_PTHREAD_ENV
359 vol_PollProc = IOMGR_Poll; /* tell vol pkg to poll io system periodically */
362 rxi_syscallp = volser_syscall;
364 rx_nPackets = rxpackets; /* set the max number of packets */
366 rx_SetUdpBufSize(udpBufSize); /* set the UDP buffer size for receive */
367 code = rx_Init((int)htons(AFSCONF_VOLUMEPORT));
369 fprintf(stderr, "rx init failed on socket AFSCONF_VOLUMEPORT %u\n",
374 /* Don't allow 3.4 vos clients to send jumbograms and we don't send. */
378 rx_SetRxDeadTime(420);
379 memset(busyFlags, 0, sizeof(busyFlags));
381 /* Open FileLog and map stdout, stderr into it */
382 OpenLog(AFSDIR_SERVER_VOLSERLOG_FILEPATH);
386 #ifdef AFS_PTHREAD_ENV
388 pthread_attr_t tattr;
389 assert(pthread_attr_init(&tattr) == 0);
390 assert(pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED) == 0);
392 assert(pthread_create(&tid, &tattr, (void *)BKGLoop, NULL) == 0);
395 LWP_CreateProcess(BKGLoop, 16*1024, 3, 0, "vol bkg daemon", &pid);
396 LWP_CreateProcess(BKGSleep,16*1024, 3, 0, "vol slp daemon", &pid);
400 /* 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 */
402 tdir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
404 Abort("volser: could not open conf files in %s\n",
405 AFSDIR_SERVER_ETC_DIRPATH);
408 afsconf_GetKey(tdir, 999, &tkey);
409 securityObjects[0] = rxnull_NewServerSecurityObject();
410 securityObjects[1] = (struct rx_securityClass *)0; /* don't bother with rxvab */
412 rxkad_NewServerSecurityObject(0, tdir, afsconf_GetKey, NULL);
413 if (securityObjects[0] == (struct rx_securityClass *)0)
414 Abort("rxnull_NewServerSecurityObject");
416 rx_NewService(0, VOLSERVICE_ID, "VOLSER", securityObjects, 3,
417 AFSVolExecuteRequest);
418 if (service == (struct rx_service *)0)
419 Abort("rx_NewService");
420 rx_SetBeforeProc(service, MyBeforeProc);
421 rx_SetAfterProc(service, MyAfterProc);
422 rx_SetIdleDeadTime(service, 0); /* never timeout */
425 rx_SetMaxProcs(service, lwps);
427 rx_SetStackSize(service, 49152);
429 rx_SetStackSize(service, 32768);
433 rx_NewService(0, RX_STATS_SERVICE_ID, "rpcstats", securityObjects, 3,
434 RXSTATS_ExecuteRequest);
435 if (service == (struct rx_service *)0)
436 Abort("rx_NewService");
437 rx_SetMinProcs(service, 2);
438 rx_SetMaxProcs(service, 4);
440 Log("Starting AFS Volserver %s (%s)\n", VolserVersion, commandLine);
442 Log("Will sleep %d second%s every %d second%s\n", TTsleep,
443 (TTsleep > 1) ? "s" : "", TTrun + TTsleep,
444 (TTrun + TTsleep > 1) ? "s" : "");
447 /* allow super users to manage RX statistics */
448 rx_SetRxStatUserOk(vol_rxstat_userok);
450 rx_StartServer(1); /* Donate this process to the server process pool */
452 osi_audit(VS_FinishEvent, (-1), AUD_END);
453 Abort("StartServer returned?");