From: Simon Wilkinson Date: Mon, 7 Nov 2011 09:48:14 +0000 (+0000) Subject: viced: Remove the LWP fileserver X-Git-Tag: upstream/1.8.0_pre1^2~2802 X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=ca0fdd84a4311628b8310be66c62aaec51c86d4d;p=packages%2Fo%2Fopenafs.git viced: Remove the LWP fileserver *) Remove all LWP specific code from the fileserver, and make pthread the default *) Build the pthreaded fileserver in the 'viced' directory, rather than in tviced *) Move the DAFS specific files from tviced to viced (arguably, these should move into dviced, but there are currently no source files in that directory) *) Remove tviced from the build Change-Id: I6e186c9fad6d9dccd04cf1317a80c087587ef25f Reviewed-on: http://gerrit.openafs.org/5816 Reviewed-by: Derrick Brashear Tested-by: BuildBot --- diff --git a/Makefile.in b/Makefile.in index 8dd74d338..a8761ab28 100644 --- a/Makefile.in +++ b/Makefile.in @@ -289,17 +289,9 @@ tvlserver: cmd comerr vol audit tubik libafsrpc libafsauthent tvlserver_depinsta esac -viced: cmd comerr vlserver tvlserver audit +viced: cmd comerr vlserver tvlserver libafsrpc libafsauthent audit +${COMPILE_PART1} viced ${COMPILE_PART2} -tviced: cmd comerr viced vlserver tvlserver libafsrpc libafsauthent - +case ${SYS_NAME} in \ - alpha_dux*|sgi_*|sun*_5*|rs_aix*|*linux*|hp_ux11*|ia64_hpux*|*[nof]bsd*|*_darwin_*) \ - ${COMPILE_PART1} tviced ${COMPILE_PART2} ;; \ - *) \ - echo Not building MT viced for ${SYS_NAME} ;; \ - esac - dviced: cmd comerr viced vlserver tvlserver libafsrpc libafsauthent +case ${SYS_NAME} in \ alpha_dux*|sgi_*|sun*_5*|rs_aix*|*linux*|hp_ux11*|ia64_hpux*|*[nof]bsd*|*_darwin_*) \ @@ -311,7 +303,7 @@ dviced: cmd comerr viced vlserver tvlserver libafsrpc libafsauthent volser: cmd comerr usd kauth vlserver audit +${COMPILE_PART1} volser ${COMPILE_PART2} -tvolser: project tviced usd libafsrpc libafsauthent volser +tvolser: project viced usd libafsrpc libafsauthent volser +@case ${SYS_NAME} in \ *_darwin_*|alpha_dux*|sgi_*|sun*_5*|rs_aix*|*linux*|hp_ux11*|ia64_hpux*|*[no]bsd*) \ ${COMPILE_PART1} tvolser ${COMPILE_PART2} ;; \ @@ -319,7 +311,7 @@ tvolser: project tviced usd libafsrpc libafsauthent volser echo Not building MT volser for ${SYS_NAME} ;; \ esac -dvolser: project tviced usd libafsrpc libafsauthent volser +dvolser: project viced usd libafsrpc libafsauthent volser +@case ${SYS_NAME} in \ *_darwin_*|alpha_dux*|sgi_*|sun*_5*|rs_aix*|*linux*|hp_ux11*|ia64_hpux*|*[no]bsd*) \ ${COMPILE_PART1} dvolser ${COMPILE_PART2} ;; \ @@ -724,7 +716,6 @@ clean2: -${COMPILE_PART1} vlserver ${COMPILE_CLEAN} -${COMPILE_PART1} tvlserver ${COMPILE_CLEAN} -${COMPILE_PART1} viced ${COMPILE_CLEAN} - -${COMPILE_PART1} tviced ${COMPILE_CLEAN} -${COMPILE_PART1} dviced ${COMPILE_CLEAN} -${COMPILE_PART1} volser ${COMPILE_CLEAN} -${COMPILE_PART1} tvolser ${COMPILE_CLEAN} @@ -915,7 +906,6 @@ distclean: clean src/tests/auth/Makefile \ src/tsalvaged/Makefile \ src/tsm41/Makefile \ - src/tviced/Makefile \ src/tvolser/Makefile \ src/ubik/Makefile \ src/tubik/Makefile \ diff --git a/NTMakefile b/NTMakefile index d96c8840f..31acf7366 100644 --- a/NTMakefile +++ b/NTMakefile @@ -410,14 +410,7 @@ volser: vol $(NTMAKE) $(CD) ..\.. -viced: volser - @echo ***** $@ - $(DOCD) $(SRC)\$@ - $(CD) $(SRC)\$@ - $(NTMAKE) - $(CD) ..\.. - -update: viced +update: volser @echo ***** $@ $(DOCD) $(SRC)\$@ $(CD) $(SRC)\$@ @@ -466,14 +459,14 @@ libafsauthent: bu_utils $(NTMAKE) $(CD) ..\.. -tviced: libafsauthent +viced: libafsauthent @echo ***** $@ $(DOCD) $(SRC)\$@ $(CD) $(SRC)\$@ $(NTMAKE) $(CD) ..\.. -tvolser: tviced +tvolser: viced @echo ***** $@ $(DOCD) $(SRC)\$@ $(CD) $(SRC)\$@ diff --git a/configure.ac b/configure.ac index 588b50a1a..41789541e 100644 --- a/configure.ac +++ b/configure.ac @@ -229,7 +229,6 @@ src/tests/Makefile \ src/tests/run-tests \ src/tsalvaged/Makefile \ src/tsm41/Makefile \ -src/tviced/Makefile \ src/tvolser/Makefile \ src/ubik/Makefile \ src/tubik/Makefile \ diff --git a/doc/arch/dafs-overview.txt b/doc/arch/dafs-overview.txt index ac3e53a26..2b2e58668 100644 --- a/doc/arch/dafs-overview.txt +++ b/doc/arch/dafs-overview.txt @@ -245,7 +245,7 @@ the reader count. - viced state serialization -See src/tviced/serialize_state.* and ShutDownAndCore in +See src/viced/serialize_state.* and ShutDownAndCore in src/viced/viced.c Before DAFS, whenever a fileserver restarted, it lost all information diff --git a/src/NTObjdir b/src/NTObjdir index 51066e7f9..f4ebaba7a 100755 --- a/src/NTObjdir +++ b/src/NTObjdir @@ -192,7 +192,6 @@ dirs="\ vol \ volser \ viced \ - tviced \ bozo \ update \ bu_utils \ diff --git a/src/SOURCE-MAP b/src/SOURCE-MAP index b35059041..10a47b4da 100644 --- a/src/SOURCE-MAP +++ b/src/SOURCE-MAP @@ -267,10 +267,6 @@ Tivoli storage manager support for the backup system. Pthreaded ubik build dir. - -- tviced - -Pthreaded version of the fileserver. - -- tvlsever Pthreaded vlserver build dir. @@ -327,4 +323,4 @@ Volume server package. includes volserver and vos client. -- xstat Extended statistics clients for cachemanagers and fileservers, -includes xstat library and xstatcommand line clients. \ No newline at end of file +includes xstat library and xstatcommand line clients. diff --git a/src/config/NTMakefile b/src/config/NTMakefile index 1a92f834a..ff94d5c61 100644 --- a/src/config/NTMakefile +++ b/src/config/NTMakefile @@ -211,9 +211,6 @@ idirs: doclink ! IF (!EXIST($(OJT)\tbutc)) $(MKDIR) $(OJT)\tbutc ! ENDIF -! IF (!EXIST($(OJT)\tviced)) - $(MKDIR) $(OJT)\tviced -! ENDIF ! IF (!EXIST($(OJT)\tvolser)) $(MKDIR) $(OJT)\tvolser ! ENDIF diff --git a/src/dviced/Makefile.in b/src/dviced/Makefile.in index d2edc388b..30fbefec5 100644 --- a/src/dviced/Makefile.in +++ b/src/dviced/Makefile.in @@ -17,7 +17,6 @@ MODULE_CFLAGS=-DRXDEBUG -DFSSYNC_BUILD_SERVER \ RX=$(srcdir)/../rx VICED=$(srcdir)/../viced -TVICED=$(srcdir)/../tviced VLSERVER=$(srcdir)/../vlserver LWP=$(srcdir)/../lwp LIBACL=$(srcdir)/../libacl @@ -83,8 +82,8 @@ callback.o: ${VICED}/callback.c fsstats.o: ${VICED}/fsstats.c $(AFS_CCRULE) $(VICED)/fsstats.c -serialize_state.o: ${TVICED}/serialize_state.c - $(AFS_CCRULE) $(TVICED)/serialize_state.c +serialize_state.o: ${VICED}/serialize_state.c + $(AFS_CCRULE) $(VICED)/serialize_state.c uuid.o: ${UTIL}/uuid.c $(AFS_CCRULE) $(UTIL)/uuid.c @@ -211,8 +210,8 @@ afsint.ss.o: ../fsint/afsint.ss.c afsint.xdr.o: ../fsint/afsint.xdr.c $(AFS_CCRULE) ../fsint/afsint.xdr.c -state_analyzer.o: ${TVICED}/state_analyzer.c - $(AFS_CCRULE) $(TVICED)/state_analyzer.c +state_analyzer.o: ${VICED}/state_analyzer.c + $(AFS_CCRULE) $(VICED)/state_analyzer.c dafileserver: ${objects} ${LIBS} $(AFS_LDRULE) ${objects} \ diff --git a/src/dviced/NTMakefile b/src/dviced/NTMakefile index 9dcf58d9a..a73975f04 100644 --- a/src/dviced/NTMakefile +++ b/src/dviced/NTMakefile @@ -17,7 +17,6 @@ RELDIR=dviced EXEFILE = $(DESTDIR)\root.server\usr\afs\bin\dafileserver.exe VICED = ..\viced -TVICED = ..\tviced LIBACL = ..\libacl DIR = ..\dir FSINT = ..\fsint @@ -26,9 +25,8 @@ RX = ..\rx RXOBJS = $(OUT)\xdr_int64.obj \ $(OUT)\xdr_int32.obj -VICEDOBJS = $(OUT)\viced.obj $(OUT)\afsfileprocs.obj $(OUT)\fsstats.obj $(OUT)\host.obj $(OUT)\physio.obj $(OUT)\callback.obj - -TVICEDOBJS = $(OUT)\serialize_state.obj +VICEDOBJS = $(OUT)\viced.obj $(OUT)\afsfileprocs.obj $(OUT)\fsstats.obj $(OUT)\host.obj $(OUT)\physio.obj \ + $(OUT)\callback.obj $(OUT)\serialize_state.obj DAFS_VICEDRES = $(OUT)\dafileserver.res @@ -54,9 +52,6 @@ $(VICEDOBJS): $(VICED)\$$(@B).c $(DAFS_VICEDRES): dafileserver.rc AFS_component_version_number.h $(RC) /fo $(DAFS_VICEDRES) dafileserver.rc -$(TVICEDOBJS): $(TVICED)\$$(@B).c - $(C2OBJ) -I$(TVICED) $** - $(LIBACLOBJS): $(LIBACL)\$$(@B).C $(C2OBJ) -I$(LIBACL) $** diff --git a/src/tviced/.gitignore b/src/tviced/.gitignore deleted file mode 100644 index aec943525..000000000 --- a/src/tviced/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -# After changing this file, please run -# git ls-files -i --exclude-standard -# to check that you haven't inadvertently ignored any tracked files. - -/fileserver -/state_analyzer diff --git a/src/tviced/Makefile.in b/src/tviced/Makefile.in deleted file mode 100644 index f35b2f987..000000000 --- a/src/tviced/Makefile.in +++ /dev/null @@ -1,231 +0,0 @@ -# Copyright 2000, International Business Machines Corporation and others. -# All Rights Reserved. -# -# This software has been released under the terms of the IBM Public -# License. For details, see the LICENSE file in the top-level source -# directory or online at http://www.openafs.org/dl/license10.html -# -# Portions Copyright (c) 2003 Apple Computer, Inc. - -srcdir=@srcdir@ -include @TOP_OBJDIR@/src/config/Makefile.config -include @TOP_OBJDIR@/src/config/Makefile.pthread - - -MODULE_CFLAGS = -DRXDEBUG -DFSSYNC_BUILD_SERVER -DSALVSYNC_BUILD_CLIENT - -RX=$(srcdir)/../rx -VICED=$(srcdir)/../viced -VLSERVER=$(srcdir)/../vlserver -LWP=$(srcdir)/../lwp -LIBACL=$(srcdir)/../libacl -UTIL=$(srcdir)/../util -DIR=$(srcdir)/../dir -VOL=$(srcdir)/../vol -FSINT=$(srcdir)/../fsint - -VICEDOBJS=viced.o afsfileprocs.o host.o physio.o callback.o serialize_state.o \ - fsstats.o - -VLSERVEROBJS=vldbint.cs.o vldbint.xdr.o - -LWPOBJS=lock.o threadname.o - -LIBACLOBJS=aclprocs.o netprocs.o - -UTILOBJS=uuid.o serverLog.o fileutil.o netutils.o dirpath.o volparse.o flipbase64.o softsig.o pthread_threadname.o - -DIROBJS=buffer.o dir.o salvage.o - -VOLOBJS= vnode.o volume.o vutil.o partition.o fssync-server.o \ - clone.o devname.o common.o ihandle.o listinodes.o namei_ops.o \ - fstab.o salvsync-client.o daemon_com.o vg_cache.o vg_scan.o - -FSINTOBJS= afsaux.o afscbint.cs.o afsint.ss.o afsint.xdr.o - -RXOBJS = rx_pthread.o - -objects= ${VICEDOBJS} ${VLSERVEROBJS} ${LWPOBJS} ${LIBACLOBJS} \ - ${UTILOBJS} ${DIROBJS} ${VOLOBJS} ${FSINTOBJS} ${RXOBJS} - -LIBS=${TOP_LIBDIR}/libafsauthent.a \ - ${TOP_LIBDIR}/libafsrpc.a \ - $(TOP_LIBDIR)/libcmd.a \ - $(TOP_LIBDIR)/libopr.a \ - ${TOP_LIBDIR}/util.a - -all: fileserver - -CFLAGS_rx_pthread.o = -DDPF_FSLOG -rx_pthread.o: ${RX}/rx_pthread.c - $(AFS_CCRULE) $(RX)/rx_pthread.c - -viced.o: ${VICED}/viced.c - $(AFS_CCRULE) $(VICED)/viced.c - -afsfileprocs.o: ${VICED}/afsfileprocs.c - $(AFS_CCRULE) $(VICED)/afsfileprocs.c - -host.o: ${VICED}/host.c - $(AFS_CCRULE) $(VICED)/host.c - -physio.o: ${VICED}/physio.c - $(AFS_CCRULE) $(VICED)/physio.c - -callback.o: ${VICED}/callback.c - $(AFS_CCRULE) $(VICED)/callback.c - -fsstats.o: ${VICED}/fsstats.c - $(AFS_CCRULE) $(VICED)/fsstats.c - -assert.o: ${UTIL}/assert.c - $(AFS_CCRULE) $(UTIL)/assert.c - -uuid.o: ${UTIL}/uuid.c - $(AFS_CCRULE) $(UTIL)/uuid.c - -serverLog.o: ${UTIL}/serverLog.c - $(AFS_CCRULE) $(UTIL)/serverLog.c - -fileutil.o: ${UTIL}/fileutil.c - $(AFS_CCRULE) $(UTIL)/fileutil.c - -volparse.o: ${UTIL}/volparse.c - $(AFS_CCRULE) $(UTIL)/volparse.c - -flipbase64.o: ${UTIL}/flipbase64.c - $(AFS_CCRULE) $(UTIL)/flipbase64.c - -netutils.o: ${UTIL}/netutils.c - $(AFS_CCRULE) -I../util $(UTIL)/netutils.c - -dirpath.o: ${UTIL}/dirpath.c - $(AFS_CCRULE) $(UTIL)/dirpath.c - -softsig.o: ${UTIL}/softsig.c - $(AFS_CCRULE) $(UTIL)/softsig.c - -pthread_threadname.o: ${UTIL}/pthread_threadname.c - $(AFS_CCRULE) $(UTIL)/pthread_threadname.c - -lock.o: ${LWP}/lock.c - $(AFS_CCRULE) $(LWP)/lock.c - -threadname.o: ${LWP}/threadname.c - $(AFS_CCRULE) $(LWP)/threadname.c - -aclprocs.o: ${LIBACL}/aclprocs.c - $(AFS_CCRULE) $(LIBACL)/aclprocs.c - -netprocs.o: ${LIBACL}/netprocs.c - $(AFS_CCRULE) $(LIBACL)/netprocs.c - - -vldbint.cs.o: ../vlserver/vldbint.cs.c - $(AFS_CCRULE) -I$(VLSERVER) ../vlserver/vldbint.cs.c - -vldbint.xdr.o: ../vlserver/vldbint.xdr.c - $(AFS_CCRULE) -I$(VLSERVER) ../vlserver/vldbint.xdr.c - - -buffer.o: ${DIR}/buffer.c - $(AFS_CCRULE) $(DIR)/buffer.c - -dir.o: ${DIR}/dir.c - $(AFS_CCRULE) $(DIR)/dir.c - -salvage.o: ${DIR}/salvage.c - $(AFS_CCRULE) $(DIR)/salvage.c - -vnode.o: ${VOL}/vnode.c - $(AFS_CCRULE) $(VOL)/vnode.c - -volume.o: ${VOL}/volume.c - $(AFS_CCRULE) $(VOL)/volume.c - -vutil.o: ${VOL}/vutil.c - $(AFS_CCRULE) $(VOL)/vutil.c - -partition.o: ${VOL}/partition.c - $(AFS_CCRULE) $(VOL)/partition.c - -vg_cache.o: ${VOL}/vg_cache.c - $(AFS_CCRULE) $(VOL)/vg_cache.c - -vg_scan.o: ${VOL}/vg_scan.c - $(AFS_CCRULE) $(VOL)/vg_scan.c - -fssync-server.o: ${VOL}/fssync-server.c - $(AFS_CCRULE) $(VOL)/fssync-server.c - -fssync-client.o: ${VOL}/fssync-client.c - $(AFS_CCRULE) $(VOL)/fssync-client.c - -salvsync-client.o: ${VOL}/salvsync-client.c - $(AFS_CCRULE) $(VOL)/salvsync-client.c - -daemon_com.o: ${VOL}/daemon_com.c - $(AFS_CCRULE) $(VOL)/daemon_com.c - -clone.o: ${VOL}/clone.c - $(AFS_CCRULE) $(VOL)/clone.c - -nuke.o: ${VOL}/nuke.c - $(AFS_CCRULE) $(VOL)/nuke.c - -devname.o: ${VOL}/devname.c - $(AFS_CCRULE) $(VOL)/devname.c - -# only for darwin? -fstab.o: ${UTIL}/fstab.c - $(AFS_CCRULE) $(UTIL)/fstab.c - -common.o: ${VOL}/common.c - $(AFS_CCRULE) $(VOL)/common.c - -listinodes.o: ${VOL}/listinodes.c - $(AFS_CCRULE) $(VOL)/listinodes.c - -ihandle.o: ${VOL}/ihandle.c - $(AFS_CCRULE) $(VOL)/ihandle.c - -namei_ops.o: ${VOL}/namei_ops.c - $(AFS_CCRULE) $(VOL)/namei_ops.c - -afsaux.o: ${FSINT}/afsaux.c - $(AFS_CCRULE) -I../fsint $(FSINT)/afsaux.c - -afscbint.cs.o: ../fsint/afscbint.cs.c - $(AFS_CCRULE) ../fsint/afscbint.cs.c - -afscbint.ss.o: ../fsint/afscbint.ss.c - $(AFS_CCRULE) ../fsint/afscbint.ss.c - -afsint.cs.o: ../fsint/afsint.cs.c - $(AFS_CCRULE) ../fsint/afsint.cs.c - -afsint.ss.o: ../fsint/afsint.ss.c - $(AFS_CCRULE) ../fsint/afsint.ss.c - -afsint.xdr.o: ../fsint/afsint.xdr.c - $(AFS_CCRULE) ../fsint/afsint.xdr.c - -fileserver: ${objects} ${LIBS} - $(AFS_LDRULE) ${objects} \ - ${LIBS} $(LIB_hcrypto) $(LIB_roken) ${MT_LIBS} ${XLIBS} - -install: fileserver - ${INSTALL} -d ${DESTDIR}${afssrvlibexecdir} - ${INSTALL} -d ${DESTDIR}${afssrvsbindir} - ${INSTALL} fileserver \ - ${DESTDIR}${afssrvlibexecdir}/fileserver - -dest: fileserver - ${INSTALL} -d ${DEST}/root.server/usr/afs/bin - ${INSTALL} fileserver \ - ${DEST}/root.server/usr/afs/bin/fileserver - -clean: - $(RM) -f *.o fileserver core AFS_component_version_number.c - -include ../config/Makefile.version diff --git a/src/tviced/NTMakefile b/src/tviced/NTMakefile deleted file mode 100644 index 557338298..000000000 --- a/src/tviced/NTMakefile +++ /dev/null @@ -1,101 +0,0 @@ -# Copyright 2000, International Business Machines Corporation and others. -# All Rights Reserved. -# -# This software has been released under the terms of the IBM Public -# License. For details, see the LICENSE file in the top-level source -# directory or online at http://www.openafs.org/dl/license10.html - -AFSDEV_AUXCDEFINES = -DAFS_PTHREAD_ENV -DRXDEBUG -DFSSYNC_BUILD_SERVER #-DAFS_DEMAND_ATTACH_FS - -RELDIR=tviced -!INCLUDE ..\config\NTMakefile.$(SYS_NAME) -!INCLUDE ..\config\NTMakefile.version - -SRC_DIR = ..\viced - -############################################################################ -# Build the fileserver - -EXEFILE = $(DESTDIR)\root.server\usr\afs\bin\fileserver.exe - -VICED = ..\viced -TVICED = . -LWP = ..\lwp -LIBACL = ..\libacl -FSINT = ..\fsint -RX = ..\rx - -RXOBJS = $(OUT)\xdr_int64.obj \ - $(OUT)\xdr_int32.obj - -VICEDOBJS = $(OUT)\viced.obj $(OUT)\afsfileprocs.obj $(OUT)\fsstats.obj $(OUT)\host.obj $(OUT)\physio.obj $(OUT)\callback.obj - -TVICEDRES = $(OUT)\fileserver.res - -TVICEDOBJS = $(OUT)\serialize_state.obj - -LWPOBJS = $(OUT)\lock.obj $(OUT)\fasttime.obj $(OUT)\threadname.obj - -LIBACLOBJS = $(OUT)\aclprocs.obj $(OUT)\netprocs.obj - -FSINTOBJS = $(OUT)\afsaux.obj $(OUT)\afscbint.cs.obj $(OUT)\afsint.ss.obj $(OUT)\afsint.xdr.obj - -EXEOBJS = $(VICEDOBJS) $(TVICEDRES) $(LWPOBJS) $(LIBACLOBJS) \ - $(FSINTOBJS) $(RXOBJS) #$(TVICEDOBJS) - -noversion: install - -all: fileserver - -$(RXOBJS): $(RX)\$$(@B).c - $(C2OBJ) -I$(RX) $** - -$(VICEDOBJS): $(VICED)\$$(@B).c - $(C2OBJ) -I$(VICED) $** - -$(TVICEDRES): $(VICED)\fileserver.rc AFS_component_version_number.h - $(RC) /fo $(TVICEDRES) $(VICED)\fileserver.rc - -$(TVICEDOBJS): $(TVICED)\$$(@B).c - $(C2OBJ) -I$(TVICED) $** - -$(LWPOBJS): $(LWP)\$$(@B).C - $(C2OBJ) -I$(LWP) $** - -$(LIBACLOBJS): $(LIBACL)\$$(@B).C - $(C2OBJ) -I$(LIBACL) $** - -$(FSINTOBJS): $(FSINT)\$$(@B).C - $(C2OBJ) -I$(FSINT) $** - -EXELIBS = \ - $(DESTDIR)\lib\afsauthent.lib \ - $(DESTDIR)\lib\afsrpc.lib \ - $(DESTDIR)\lib\afs\afscmd.lib \ - $(DESTDIR)\lib\afs\afsaudit.lib \ - $(DESTDIR)\lib/afs/afscom_err.lib \ - $(DESTDIR)\lib\afs\afsreg.lib \ - $(DESTDIR)\lib\afs\afsprocmgmt.lib \ - $(DESTDIR)\lib\afs\afseventlog.lib \ - $(DESTDIR)\lib\afs\mtafsutil.lib \ - $(DESTDIR)\lib\afs\mtafsvol.lib \ - $(DESTDIR)\lib\afs\mtafsvldb.lib \ - $(DESTDIR)\lib\afs\mtafsdir.lib \ - $(DESTDIR)\lib\opr.lib \ - $(DESTDIR)\lib\afspthread.lib \ - $(DESTDIR)\lib\afsroken.lib - -$(EXEFILE): $(EXEOBJS) $(EXELIBS) - $(EXECONLINK) - $(_VC_MANIFEST_EMBED_EXE) - $(EXEPREP) - $(CODESIGN_USERLAND) - $(SYMSTORE_IMPORT) - -install: $(EXEFILE) - -mkdir: - -clean:: - $(DEL) $(TVICEDRES) - diff --git a/src/tviced/fileserver.rc b/src/tviced/fileserver.rc deleted file mode 100644 index 84bd52857..000000000 --- a/src/tviced/fileserver.rc +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright 2000, International Business Machines Corporation and others. - * All Rights Reserved. - * - * This software has been released under the terms of the IBM Public - * License. For details, see the LICENSE file in the top-level source - * directory or online at http://www.openafs.org/dl/license10.html - */ - -/* Define VERSIONINFO resource */ - -#define AFS_VERINFO_FILE_DESCRIPTION "AFS File Server (Threaded)" -#define AFS_VERINFO_NAME "fileserver" -#define AFS_VERINFO_FILENAME "fileserver.exe" - -#include "AFS_component_version_number.h" -#include "..\config\NTVersioninfo.rc" diff --git a/src/tviced/serialize_state.c b/src/tviced/serialize_state.c deleted file mode 100644 index 5c86e3f88..000000000 --- a/src/tviced/serialize_state.c +++ /dev/null @@ -1,1048 +0,0 @@ -/* - * Copyright 2006, Sine Nomine Associates and others. - * All Rights Reserved. - * - * This software has been released under the terms of the IBM Public - * License. For details, see the LICENSE file in the top-level source - * directory or online at http://www.openafs.org/dl/license10.html - */ - -/* - * demand attach fs - * fileserver state serialization - */ - -#include -#include - -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "../viced/viced_prototypes.h" -#include "../viced/viced.h" -#include "../viced/host.h" -#include "../viced/callback.h" -#include "serialize_state.h" - -#ifdef AFS_DEMAND_ATTACH_FS - -/* - * demand attach fs - * state dump routines - * - * in order to make state dump/restore as fast as possible, - * we use memory mapped files - * - * if this causes problems on certain platforms, the APIs - * have been written so that it will be very simple to go - * back to standard I/O for just those poorly written platforms - */ -#ifndef AFS_NT40_ENV -#define FS_STATE_USE_MMAP 1 -#endif - -#ifdef FS_STATE_USE_MMAP -#define FS_STATE_INIT_FILESIZE (8 * 1024 * 1024) /* truncate to 8MB initially */ -#ifndef AFS_NT40_ENV -#include -#endif -#endif - -static int fs_stateCreateDump(struct fs_dump_state * state); -static int fs_stateLoadDump(struct fs_dump_state * state); -static int fs_stateInvalidateDump(struct fs_dump_state * state); -static int fs_stateCommitDump(struct fs_dump_state * state); -static int fs_stateCloseDump(struct fs_dump_state * state); - -#ifdef FS_STATE_USE_MMAP -static int fs_stateSizeFile(struct fs_dump_state * state); -static int fs_stateResizeFile(struct fs_dump_state * state, size_t min_add); -static int fs_stateTruncateFile(struct fs_dump_state * state); - -static int fs_stateMapFile(struct fs_dump_state * state); -static int fs_stateUnmapFile(struct fs_dump_state * state); - -static int fs_stateIncCursor(struct fs_dump_state * state, size_t len); -static int fs_stateCheckIOSafety(struct fs_dump_state * state, - size_t len); -#endif - -static int fs_stateFillHeader(struct fs_state_header * hdr); -static int fs_stateCheckHeader(struct fs_state_header * hdr); - -static int fs_stateAlloc(struct fs_dump_state * state); -static int fs_stateFree(struct fs_dump_state * state); - -extern afsUUID FS_HostUUID; -extern char cml_version_number[]; - -int -fs_stateFileOpen(struct fs_dump_state *state) -{ -#ifdef AFS_NT40_ENV - return(state->fd != -1); -#else - return(state->fd >= 0); -#endif -} - - -/* - * demand attach fs - * save all fileserver state - */ -int -fs_stateSave(void) -{ - int ret = 0, verified = 1; - struct fs_dump_state state; - - /* save and restore need to be atomic wrt other host package operations */ - H_LOCK; - - ViceLog(0, ("fs_stateSave: commencing fileserver state dump\n")); - - if (fs_stateAlloc(&state)) { - ViceLog(0, ("fs_stateSave: memory allocation failed; dump aborted\n")); - ret = 1; - goto done; - } - - /* XXX - * on busy servers, these checks will inevitably fail since stuff drops H_LOCK - * all over the place (with structs left in inconsistent states) while RPCs to - * clients happen (grumble, grumble, the host package needs to be rewritten...) - * - * the current hack is to force the background threads that deal with host and - * callback state offline early in the shutdown process, do VShutdown, come - * back and wait for those threads to die, THEN do the state dump - * - * BUT, this still has one flaw -- what do we do about rx worker threads that - * are blocked in the host package making an RPC call to a cm??? - * - * currently we try to detect if a host struct is in an inconsistent state - * when we go to save it to disk, and just skip the hosts that we think may - * be inconsistent (see h_isBusy_r in host.c). This has the problem of causing - * more InitCallBackState's when we come back up, but the number of hosts in - * such a state should be small. In the future, we could try to lock hosts - * (with some deadline so we don't wait forever) before serializing, but at - * least for now it does not seem worth the trouble. - */ - - if (fs_state.options.fs_state_verify_before_save) { - ViceLog(0, ("fs_stateSave: performing internal consistency checks before proceeding with state dump\n")); - - if (h_stateVerify(&state)) { - ViceLog(0, ("fs_stateSave: error: host table consistency checks failed; state dump will not be marked clean\n")); - verified = 0; - ret = 1; - } - - if (cb_stateVerify(&state)) { - ViceLog(0, ("fs_stateSave: error: callback table consistency checks failed; state dump will not be marked clean\n")); - verified = 0; - ret = 1; - } - - /* if a consistency check asserted the bail flag, reset it */ - state.bail = 0; - - ViceLog(0, ("fs_stateSave: proceeding with dump\n")); - } - - if (fs_stateCreateDump(&state)) { - ViceLog(0, ("fs_stateSave: error: dump create failed\n")); - ret = 1; - goto done; - } - - if (h_stateSave(&state)) { - ViceLog(0, ("fs_stateSave: error: host state dump failed\n")); - ret = 1; - goto done; - } - - if (cb_stateSave(&state)) { - ViceLog(0, ("fs_stateSave: error: callback state dump failed\n")); - ret = 1; - goto done; - } - - if (!verified) { - state.bail = 1; - } - - if (fs_stateCommitDump(&state)) { - ViceLog(0, ("fs_stateSave: error: dump commit failed\n")); - ret = 1; - goto done; - } - - if (verified) { - ViceLog(0, ("fs_stateSave: fileserver state dump completed successfully\n")); - } else { - ViceLog(0, ("fs_stateSave: fileserver state dump completed, but not marked clean.\n")); - ViceLog(0, ("fs_stateSave: please save a copy of '%s' for use by technical support\n", - state.fn)); - } - - done: - if (fs_stateFileOpen(&state)) - fs_stateCloseDump(&state); - fs_stateFree(&state); - H_UNLOCK; - return ret; -} - -/* - * demand attach fs - * restore all fileserver state - * - * this function must appear as one atomic operation to the host and callback - * packages, hence H_LOCK is held for the entirety of the process. - */ -int -fs_stateRestore(void) -{ - int ret = 0; - struct fs_dump_state state; - - /* save and restore need to be atomic wrt other host package operations */ - H_LOCK; - - ViceLog(0, ("fs_stateRestore: commencing fileserver state restore\n")); - - if (fs_stateAlloc(&state)) { - ViceLog(0, ("fs_stateRestore: memory allocation failed\n")); - ret = 1; - goto done; - } - - if (fs_stateLoadDump(&state)) { - ViceLog(0, ("fs_stateRestore: failed to load dump file '%s'\n", state.fn)); - ret = 1; - goto done; - } - - if (fs_stateInvalidateDump(&state)) { - ViceLog(0, ("fs_stateRestore: failed to invalidate dump file '%s'\n", state.fn)); - ret = 1; - goto done; - } - - - if (state.flags.do_host_restore) { - if (h_stateRestore(&state)) { - ViceLog(0, ("fs_stateRestore: error: host state restore failed. exiting avoid further corruption\n")); - exit(0); - } - ViceLog(0, ("fs_stateRestore: host table restored\n")); - - if (cb_stateRestore(&state)) { - ViceLog(0, ("fs_stateRestore: error: callback state restore failed. exiting to avoid further corruption\n")); - exit(0); - } - ViceLog(0, ("fs_stateRestore: FileEntry and CallBack tables restored\n")); - - if (h_stateRestoreIndices(&state)) { - ViceLog(0, ("fs_stateRestore: error: host index remapping failed. exiting to avoid further corruption\n")); - exit(0); - } - ViceLog(0, ("fs_stateRestore: host table indices remapped\n")); - - if (cb_stateRestoreIndices(&state)) { - ViceLog(0, ("fs_stateRestore: error: callback index remapping failed. exiting to avoid further corruption\n")); - exit(0); - } - ViceLog(0, ("fs_stateRestore: FileEntry and CallBack indices remapped\n")); - } - - ViceLog(0, ("fs_stateRestore: restore phase complete\n")); - - if (fs_state.options.fs_state_verify_after_restore) { - ViceLog(0, ("fs_stateRestore: beginning state verification phase\n")); - - if (state.flags.do_host_restore) { - if (h_stateVerify(&state)) { - ViceLog(0, ("fs_stateRestore: error: host table consistency checks failed; exiting to avoid further corruption\n")); - exit(0); - } - - if (cb_stateVerify(&state)) { - ViceLog(0, ("fs_stateRestore: error: callback table consistency checks failed; exiting to avoid further corruption\n")); - exit(0); - } - } - - ViceLog(0, ("fs_stateRestore: fileserver state verification complete\n")); - } - - ViceLog(0, ("fs_stateRestore: restore was successful\n")); - - done: - if (state.fd >= 0) { - fs_stateInvalidateDump(&state); - fs_stateCloseDump(&state); - } - fs_stateFree(&state); - H_UNLOCK; - return ret; -} - -static int -fs_stateCreateDump(struct fs_dump_state * state) -{ - int fd, ret = 0; - char savedump[MAXPATHLEN]; - struct afs_stat status; - - snprintf(savedump, sizeof(savedump), "%s.old", state->fn); - - if (afs_stat(state->fn, &status) == 0) { - renamefile(state->fn, savedump); - } - - if (((fd = afs_open(state->fn, - O_RDWR | O_CREAT | O_TRUNC, - S_IRUSR | S_IWUSR)) == -1) || - (afs_fstat(fd, &status) == -1)) { - ViceLog(0, ("fs_stateCreateDump: failed to create state dump file '%s'\n", - state->fn)); - ret = 1; - goto done; - } - - state->fd = fd; - state->mode = FS_STATE_DUMP_MODE; - memset(state->hdr, 0, sizeof(struct fs_state_header)); - fs_stateIncEOF(state, sizeof(struct fs_state_header)); - -#ifdef FS_STATE_USE_MMAP - if (fs_stateSizeFile(state)) { - ViceLog(0, ("fs_stateCreateDump: failed to resize state dump file '%s'\n", - state->fn)); - ret = 1; - goto done; - } - - if (fs_stateMapFile(state)) { - ViceLog(0, ("fs_stateCreateDump: failed to memory map state dump file '%s'\n", - state->fn)); - ret = 1; - goto done; - } -#endif - - ret = fs_stateInvalidateDump(state); - - done: - return ret; -} - -static int -fs_stateInvalidateDump(struct fs_dump_state * state) -{ - afs_uint64 z; - int ret = 0; - struct fs_state_header hdr; - -#ifdef FS_STATE_USE_MMAP - if (state->mmap.map == NULL) { - return 1; - } -#endif - - memcpy(&hdr, state->hdr, sizeof(hdr)); - hdr.valid = 0; - ZeroInt64(z); - - /* write a bogus header to flag dump in progress */ - if (fs_stateWriteHeader(state, &z, &hdr, sizeof(hdr))) { - ViceLog(0, ("fs_stateInvalidateDump: failed to invalidate old dump file header '%s'\n", - state->fn)); - ret = 1; - goto done; - } - if (fs_stateSync(state)) { - ViceLog(0, ("fs_stateInvalidateDump: failed to sync changes to disk\n")); - ret = 1; - goto done; - } - - done: - return ret; -} - -static int -fs_stateCommitDump(struct fs_dump_state * state) -{ - afs_uint64 z; - int ret = 0; - - ZeroInt64(z); - -#ifdef FS_STATE_USE_MMAP - if (fs_stateTruncateFile(state)) { - ViceLog(0, ("fs_stateCommitDump: failed to truncate dump file to proper size\n")); - ret = 1; - goto done; - } -#endif - - /* ensure that all pending data I/Os for the state file have been committed - * _before_ we make the metadata I/Os */ - if (fs_stateSync(state)) { - ViceLog(0, ("fs_stateCommitDump: failed to sync changes to disk\n")); - ret = 1; - goto done; - } - -#ifdef FS_STATE_USE_MMAP - /* XXX madvise may not exist on all platforms, so - * we may need to add some ifdefs at some point... */ - { - madvise((((char *)state->mmap.map) + sizeof(struct fs_state_header)), - state->mmap.size - sizeof(struct fs_state_header), - MADV_DONTNEED); - } -#endif - - /* build the header, and write it to disk */ - fs_stateFillHeader(state->hdr); - if (state->bail) { - state->hdr->valid = 0; - } - if (fs_stateWriteHeader(state, &z, state->hdr, sizeof(struct fs_state_header))) { - ViceLog(0, ("fs_stateCommitDump: failed to write header to dump file '%s'\n", - state->fn)); - ret = 1; - goto done; - } - if (fs_stateSync(state)) { - ViceLog(0, ("fs_stateCommitDump: failed to sync new header to disk\n")); - ret = 1; - goto done; - } - - done: - return ret; -} - -static int -fs_stateLoadDump(struct fs_dump_state * state) -{ - afs_uint64 z; - int fd, ret = 0; - struct afs_stat status; - afs_int32 now = FT_ApproxTime(); - - ZeroInt64(z); - - if ((fd = afs_open(state->fn, O_RDWR)) == -1 || - (afs_fstat(fd, &status) == -1)) { - ViceLog(0, ("fs_stateLoadDump: failed to load state dump file '%s'\n", - state->fn)); - ret = 1; - goto done; - } - state->fd = fd; - state->mode = FS_STATE_LOAD_MODE; - state->file_len = status.st_size; - -#ifdef FS_STATE_USE_MMAP - if (fs_stateMapFile(state)) { - ViceLog(0, ("fs_stateLoadDump: failed to memory map state dump file '%s'\n", - state->fn)); - ret = 1; - goto done; - } -#endif - - if (fs_stateReadHeader(state, &z, state->hdr, sizeof(struct fs_state_header))) { - ViceLog(0, ("fs_stateLoadDump: failed to read header from dump file '%s'\n", - state->fn)); - ret = 1; - goto done; - } - - /* check the validity of the header */ - if (fs_stateCheckHeader(state->hdr)) { - ViceLog(1, ("fs_stateLoadDump: header failed validity checks; not restoring '%s'\n", - state->fn)); - ret = 1; - goto done; - } - - if ((state->hdr->timestamp + HOST_STATE_VALID_WINDOW) >= now) { - state->flags.do_host_restore = 1; - } else { - ViceLog(0, ("fs_stateLoadDump: warning: dump is too old for host and callback restore; skipping those steps\n")); - } - - done: - return ret; -} - -static int -fs_stateCloseDump(struct fs_dump_state * state) -{ -#ifdef FS_STATE_USE_MMAP - fs_stateUnmapFile(state); -#endif - close(state->fd); - return 0; -} - -int -fs_stateWrite(struct fs_dump_state * state, - void * buf, size_t len) -{ - int ret = 0; - -#ifdef FS_STATE_USE_MMAP - if (fs_stateCheckIOSafety(state, len)) { - if (fs_stateResizeFile(state, len)) { - ViceLog(0, ("fs_stateWrite: could not resize dump file '%s'\n", - state->fn)); - ret = 1; - goto done; - } - } - - memcpy(state->mmap.cursor, buf, len); - fs_stateIncCursor(state, len); -#else - if (write(state->fd, buf, len) != len) { - ViceLog(0, ("fs_stateWrite: write failed\n")); - ret = 1; - goto done; - } -#endif - - done: - return ret; -} - -int -fs_stateRead(struct fs_dump_state * state, - void * buf, size_t len) -{ - int ret = 0; - -#ifdef FS_STATE_USE_MMAP - if (fs_stateCheckIOSafety(state, len)) { - ViceLog(0, ("fs_stateRead: read beyond EOF for dump file '%s'\n", - state->fn)); - ret = 1; - goto done; - } - - memcpy(buf, state->mmap.cursor, len); - fs_stateIncCursor(state, len); -#else - if (read(state->fd, buf, len) != len) { - ViceLog(0, ("fs_stateRead: read failed\n")); - ret = 1; - goto done; - } -#endif - - done: - return ret; -} - -int -fs_stateWriteV(struct fs_dump_state * state, - struct iovec * iov, int niov) -{ - int i, ret = 0; - size_t len = 0; - - for (i=0; i < niov; i++) { - len += iov[i].iov_len; - } - -#ifdef FS_STATE_USE_MMAP - if (fs_stateCheckIOSafety(state, len)) { - if (fs_stateResizeFile(state, len)) { - ViceLog(0, ("fs_stateWrite: could not resize dump file '%s'\n", - state->fn)); - ret = 1; - goto done; - } - } - - for (i=0; i < niov; i++) { - memcpy(state->mmap.cursor, iov[i].iov_base, iov[i].iov_len); - fs_stateIncCursor(state, iov[i].iov_len); - } -#else -#ifndef AFS_NT40_ENV - if (writev(state->fd, iov, niov) != len) { - ViceLog(0, ("fs_stateWriteV: write failed\n")); - ret = 1; - goto done; - } -#else /* AFS_NT40_ENV */ - for (i=0; i < niov; i++) { - if (write(state->fd, iov[i].iov_base, iov[i].iov_len) != iov[i].iov_len) { - ViceLog(0, ("fs_stateWriteV: write failed\n")); - ret = 1; - goto done; - } - } -#endif /* AFS_NT40_ENV */ -#endif - - done: - return ret; -} - -int -fs_stateReadV(struct fs_dump_state * state, - struct iovec * iov, int niov) -{ - int i, ret = 0; - size_t len = 0; - - for (i=0; i < niov; i++) { - len += iov[i].iov_len; - } - -#ifdef FS_STATE_USE_MMAP - if (fs_stateCheckIOSafety(state, len)) { - ViceLog(0, ("fs_stateRead: read beyond EOF for dump file '%s'\n", - state->fn)); - ret = 1; - goto done; - } - - for (i=0; i < niov; i++) { - memcpy(iov[i].iov_base, state->mmap.cursor, iov[i].iov_len); - fs_stateIncCursor(state, iov[i].iov_len); - } -#else -#ifndef AFS_NT40_ENV - if (readv(state->fd, iov, niov) != len) { - ViceLog(0, ("fs_stateReadV: read failed\n")); - ret = 1; - goto done; - } -#else - for (i=0; i < niov; i++) { - if (read(state->fd, iov[i].iov_base, iov[i].iov_len) != iov[i].iov_len) { - ViceLog(0, ("fs_stateReadV: read failed\n")); - ret = 1; - goto done; - } - } -#endif /* AFS_NT40_ENV */ -#endif - - done: - return ret; -} - -int -fs_stateWriteHeader(struct fs_dump_state * state, - afs_uint64 * offset, - void * hdr, size_t len) -{ - int ret = 0; - - if (fs_stateSeek(state, offset)) { - ViceLog(0, ("fs_stateWriteHeader: could not seek to correct position in dump file '%s'\n", - state->fn)); - ret = 1; - goto done; - } - - if (fs_stateWrite(state, hdr, len)) { - ViceLog(0, ("fs_stateWriteHeader: write failed\n")); - ret = 1; - goto done; - } - - done: - return ret; -} - -int -fs_stateReadHeader(struct fs_dump_state * state, - afs_uint64 * offset, - void * hdr, size_t len) -{ - int ret = 0; - - if (fs_stateSeek(state, offset)) { - ViceLog(0, ("fs_stateReadHeader: could not seek to correct position in dump file '%s'\n", - state->fn)); - ret = 1; - goto done; - } - - if (fs_stateRead(state, hdr,len)) { - ViceLog(0, ("fs_stateReadHeader: read failed\n")); - ret = 1; - goto done; - } - - done: - return ret; -} - -#ifdef FS_STATE_USE_MMAP -static int -fs_stateSizeFile(struct fs_dump_state * state) -{ - int ret = 0; - state->file_len = FS_STATE_INIT_FILESIZE; - if (afs_ftruncate(state->fd, state->file_len) != 0) - ret = 1; - return ret; -} - -static int -fs_stateResizeFile(struct fs_dump_state * state, size_t min_add) -{ - int ret = 0; - afs_foff_t inc; - - fs_stateUnmapFile(state); - - inc = ((min_add / FS_STATE_INIT_FILESIZE)+1) * FS_STATE_INIT_FILESIZE; - state->file_len += inc; - - if (afs_ftruncate(state->fd, state->file_len) != 0) { - ViceLog(0, ("fs_stateResizeFile: truncate failed\n")); - ret = 1; - goto done; - } - - if (fs_stateMapFile(state)) { - ViceLog(0, ("fs_stateResizeFile: remapping memory mapped file failed\n")); - ret = 1; - goto done; - } - - done: - return ret; -} - -static int -fs_stateTruncateFile(struct fs_dump_state * state) -{ - int ret = 0; - - if (afs_ftruncate(state->fd, state->eof_offset) != 0) { - ret = 1; - } - - return ret; -} - -static int -fs_stateMapFile(struct fs_dump_state * state) -{ - int ret = 0, flags; - - switch(state->mode) { - case FS_STATE_LOAD_MODE: - flags = PROT_READ | PROT_WRITE; /* loading involves a header invalidation */ - break; - case FS_STATE_DUMP_MODE: - flags = PROT_WRITE; - break; - default: - ViceLog(0, ("fs_stateMapFile: invalid dump state mode\n")); - return 1; - } - - state->mmap.map = afs_mmap(NULL, - state->file_len, - flags, - MAP_SHARED, - state->fd, - 0); - - if (state->mmap.map == MAP_FAILED) { - state->mmap.size = 0; - state->mmap.map = NULL; - ViceLog(0, ("fs_stateMapFile: failed to memory map file '%s'\n", - state->fn)); - ret = 1; - goto done; - } - - state->mmap.size = state->file_len; - state->mmap.cursor = state->mmap.map; - state->mmap.offset = 0; - - /* for state loading, accesses will be sequential, so let's give - * the VM subsystem a heads up */ - if (state->mode == FS_STATE_LOAD_MODE) { - /* XXX madvise may not exist on all platforms, so - * we may need to add some ifdefs at some point... */ - flags = MADV_SEQUENTIAL | MADV_WILLNEED; -#ifdef AFS_SUN510_ENV - flags |= MADV_ACCESS_LWP; /* added in solaris 9 12/02 */ -#endif - madvise(state->mmap.map, state->mmap.size, flags); - } - - done: - return ret; -} - -static int -fs_stateUnmapFile(struct fs_dump_state * state) -{ - int ret = 0; - - if (munmap(state->mmap.map, state->mmap.size) == -1) { - ViceLog(0, ("fs_stateUnmapFile: failed to unmap dump file '%s'\n", - state->fn)); - ret = 1; - goto done; - } - - done: - return ret; -} - -int -fs_stateSync(struct fs_dump_state * state) -{ - int ret = 0; - - msync(state->mmap.map, state->mmap.size, MS_SYNC); - - return ret; -} -#else /* !FS_STATE_USE_MMAP */ -int -fs_stateSync(struct fs_dump_state * state) -{ - int ret = 0; - - if (fsync(state->fd) == -1) - ret = 1; - - return ret; -} -#endif /* !FS_STATE_USE_MMAP */ - -int -fs_stateIncEOF(struct fs_dump_state * state, afs_int32 len) -{ - afs_uint64 temp; - FillInt64(temp, 0, len); - AddUInt64(state->eof_offset, temp, &state->eof_offset); - return 0; -} - -#ifdef FS_STATE_USE_MMAP -static int -fs_stateIncCursor(struct fs_dump_state * state, size_t len) -{ - char * p; - - state->mmap.offset += len; - - p = (char *) state->mmap.cursor; - p += len; - state->mmap.cursor = (void *) p; - - return 0; -} - -static int -fs_stateCheckIOSafety(struct fs_dump_state * state, size_t len) -{ - int ret = 0; - - if ((state->mmap.offset + len) > state->mmap.size) { - ret = 1; - } - return ret; -} -#endif /* FS_STATE_USE_MMAP */ - -#ifdef FS_STATE_USE_MMAP -int -fs_stateSeek(struct fs_dump_state * state, afs_uint64 * offset) -{ - int ret = 0; - char * p; - - /* update cursor */ - p = (char *) state->mmap.map; - p += *offset; - state->mmap.cursor = (void *) p; - - /* update offset */ - state->mmap.offset = *offset; - - return ret; -} -#else /* !FS_STATE_USE_MMAP */ -int -fs_stateSeek(struct fs_dump_state * state, afs_uint64 * offset) -{ - int ret = 0; - - if (afs_lseek(state->fd, *offset, SEEK_SET) == -1) - ret = 1; - - return ret; -} -#endif /* !FS_STATE_USE_MMAP */ - -static int -fs_stateFillHeader(struct fs_state_header * hdr) -{ - hdr->stamp.magic = FS_STATE_MAGIC; - hdr->stamp.version = FS_STATE_VERSION; -#ifdef SYS_NAME_ID - hdr->sys_name = SYS_NAME_ID; -#else - hdr->sys_name = 0xFFFFFFFF; -#endif - hdr->timestamp = FT_ApproxTime(); - hdr->server_uuid = FS_HostUUID; - hdr->valid = 1; -#ifdef WORDS_BIGENDIAN - hdr->endianness = 1; -#else - hdr->endianness = 0; -#endif - hdr->stats_detailed = 1; - if (strlcpy(hdr->server_version_string, cml_version_number, sizeof(hdr->server_version_string)) - >= sizeof(hdr->server_version_string)) { - ViceLog(0, ("fs_stateFillHeader: WARNING -- cml_version_number field truncated\n")); - } - return 0; -} - -static int -fs_stateCheckHeader(struct fs_state_header * hdr) -{ - int ret = 0; - - if (!hdr->valid) { - ViceLog(0, ("fs_stateCheckHeader: dump was previously flagged invalid\n")); - ret = 1; - } -#ifdef WORDS_BIGENDIAN - else if (!hdr->endianness) { - ViceLog(0, ("fs_stateCheckHeader: wrong endianness\n")); - ret = 1; - } -#else /* AFSLITTLE_ENDIAN */ - else if (hdr->endianness) { - ViceLog(0, ("fs_stateCheckHeader: wrong endianness\n")); - ret = 1; - } -#endif /* AFSLITTLE_ENDIAN */ - - else if (hdr->stamp.magic != FS_STATE_MAGIC) { - ViceLog(0, ("fs_stateCheckHeader: invalid dump header\n")); - ret = 1; - } - else if (hdr->stamp.version != FS_STATE_VERSION) { - ViceLog(0, ("fs_stateCheckHeader: unknown dump format version number\n")); - ret = 1; - } - - else if (!hdr->stats_detailed) { - ViceLog(0, ("fs_stateCheckHeader: wrong config flags\n")); - ret = 1; - } - - else if (!afs_uuid_equal(&hdr->server_uuid, &FS_HostUUID)) { - ViceLog(0, ("fs_stateCheckHeader: server UUID does not match this server's UUID\n")); - ret = 1; - } - - /* the cml_version_string is included for informational purposes only. If someone ever - * wants to limit state dump reloading based upon the contents of this string, just - * uncomment the following code. uncommenting this code is _strongly discouraged_ because - * we already make use of the version stamps in the various dump headers to deal with - * data structure version incompatabilities. - else if (strncmp(hdr->server_version_string, cml_version_number, - sizeof(hdr->server_version_string)) != 0) { - ViceLog(0, ("fs_stateCheckHeader: dump from different server version\n")); - ret = 1; - } - */ - - else if (strncmp(hdr->server_version_string, cml_version_number, - sizeof(hdr->server_version_string)) != 0) { - ViceLog(0, ("fs_stateCheckHeader: dump from different server version ; attempting state reload anyway\n")); - } - - - return ret; -} - -static int -fs_stateAlloc(struct fs_dump_state * state) -{ - int ret = 0; - memset(state, 0, sizeof(struct fs_dump_state)); - state->fd = -1; - state->fn = (char *)AFSDIR_SERVER_FSSTATE_FILEPATH; - state->hdr = (struct fs_state_header *)malloc(sizeof(struct fs_state_header)); - state->h_hdr = (struct host_state_header *)malloc(sizeof(struct host_state_header)); - state->cb_hdr = (struct callback_state_header *)malloc(sizeof(struct callback_state_header)); - state->cb_timeout_hdr = (struct callback_state_timeout_header *) - malloc(sizeof(struct callback_state_timeout_header)); - state->cb_fehash_hdr = (struct callback_state_fehash_header *) - malloc(sizeof(struct callback_state_fehash_header)); - if ((state->hdr == NULL) || (state->h_hdr == NULL) || (state->cb_hdr == NULL) || - (state->cb_timeout_hdr == NULL) || (state->cb_fehash_hdr == NULL)) - ret = 1; - return ret; -} - -static int -fs_stateFree(struct fs_dump_state * state) -{ - if (state->hdr) - free(state->hdr); - if (state->h_hdr) - free(state->h_hdr); - if (state->cb_hdr) - free(state->cb_hdr); - if (state->cb_timeout_hdr) - free(state->cb_timeout_hdr); - if (state->cb_fehash_hdr) - free(state->cb_fehash_hdr); - if (state->h_map.entries) - free(state->h_map.entries); - if (state->fe_map.entries) - free(state->fe_map.entries); - if (state->cb_map.entries) - free(state->cb_map.entries); - return 0; -} - -#endif /* AFS_DEMAND_ATTACH_FS */ diff --git a/src/tviced/serialize_state.h b/src/tviced/serialize_state.h deleted file mode 100644 index 2d095dfdc..000000000 --- a/src/tviced/serialize_state.h +++ /dev/null @@ -1,312 +0,0 @@ -/* - * Copyright 2006, Sine Nomine Associates and others. - * All Rights Reserved. - * - * This software has been released under the terms of the IBM Public - * License. For details, see the LICENSE file in the top-level source - * directory or online at http://www.openafs.org/dl/license10.html - */ - -/* - * demand attach fs - * fileserver state serialization - */ - -#ifndef _AFS_TVICED_SERIALIZE_STATE_H -#define _AFS_TVICED_SERIALIZE_STATE_H - -#ifdef AFS_DEMAND_ATTACH_FS - -#define FS_STATE_MAGIC 0x62FA841C -#define FS_STATE_VERSION 2 - -#define HOST_STATE_MAGIC 0x7B8C9DAE -#define HOST_STATE_VERSION 2 - -#define HOST_STATE_ENTRY_MAGIC 0xA8B9CADB - -#define CALLBACK_STATE_MAGIC 0x89DE67BC -#define CALLBACK_STATE_VERSION 1 - -#define CALLBACK_STATE_TIMEOUT_MAGIC 0x99DD5511 -#define CALLBACK_STATE_FEHASH_MAGIC 0x77BB33FF -#define CALLBACK_STATE_ENTRY_MAGIC 0x54637281 - -#define ACTIVE_VOLUME_STATE_MAGIC 0xAC7557CA -#define ACTIVE_VOLUME_STATE_VERSION 1 - -#define ACTIVE_VOLUME_STATE_AVEHASH_MAGIC 0xBADDF00D - -#define HOST_STATE_VALID_WINDOW 1800 /* 30 minutes */ - -/* values for the 'valid' field in idx_map_entry_t */ -#define FS_STATE_IDX_VALID 1 -#define FS_STATE_IDX_SKIPPED 2 - -/* - * on-disk structures - */ -struct disk_version_stamp { - afs_uint32 magic; - afs_uint32 version; -}; - -/* 1024 byte header structure */ -struct fs_state_header { - struct disk_version_stamp stamp; /* version stamp */ - time_t timestamp; /* timestamp of save */ - afs_uint32 sys_name; /* sys name id for this machine */ - afsUUID server_uuid; /* server's UUID */ - byte valid; /* whether header contents are valid */ - byte endianness; /* endianness sanity check (0 for LE, 1 for BE) */ - byte stats_detailed; /* fs stats detailed sanity check */ - byte padding1[1]; /* padding */ - afs_uint32 reserved1[23]; /* for expansion */ - afs_uint64 avol_offset; /* offset of active volumes structure */ - afs_uint64 h_offset; /* offset of host_state_header structure */ - afs_uint64 cb_offset; /* offset of callback_state_header structure */ - afs_uint64 vlru_offset; /* offset of vlru state structure */ - afs_uint32 reserved2[56]; /* for expansion */ - char server_version_string[128]; /* version string from AFS_component_version_number.c */ - afs_uint32 reserved3[128]; /* for expansion */ -}; - -/* - * host package serialization - */ - -/* 256 byte header for the host state data */ -struct host_state_header { - struct disk_version_stamp stamp; /* host state version stamp */ - afs_uint32 records; /* number of stored host records */ - afs_uint32 index_max; /* max index value encountered */ - afs_uint32 reserved[60]; /* for expansion */ -}; - -/* 32 byte host entry header */ -struct host_state_entry_header { - afs_uint32 magic; /* stamp */ - afs_uint32 len; /* number of bytes in this record */ - afs_uint32 interfaces; /* number of interfaces included in record */ - afs_uint32 hcps; /* number of hcps entries in record */ - afs_uint32 reserved[4]; -}; - -/* 36 byte host entry structure */ -struct hostDiskEntry { - afs_uint32 host; /* IP address of host interface that is - * currently being used, in network - * byte order */ - afs_uint16 port; /* port address of host */ - afs_uint16 hostFlags; /* bit map */ - byte Console; /* XXXX This host is a console */ - byte hcpsfailed; /* Retry the cps call next time */ - byte hcps_valid; /* prlist_val not null */ - byte InSameNetwork; /*Is host's addr in the same network as - * the File Server's? */ - afs_uint32 hcps_len; /* length of hcps */ - afs_uint32 LastCall; /* time of last call from host */ - afs_uint32 ActiveCall; /* time of any call but gettime */ - afs_uint32 cpsCall; /* time of last cps call from this host */ - afs_uint32 cblist; /* Call back list for this host */ - afs_uint32 index; /* index for correlating w/ callback dumps */ -}; - -/* - * callback package serialization - */ - -/* 512 byte header */ -struct callback_state_header { - struct disk_version_stamp stamp; /* callback state version stamp */ - afs_uint32 nFEs; /* number of FileEntry records */ - afs_uint32 nCBs; /* number of CallBack records */ - afs_uint32 fe_max; /* max FileEntry index */ - afs_uint32 cb_max; /* max CallBack index */ - afs_int32 tfirst; /* first valid timeout */ - afs_uint32 reserved[115]; /* for expansion */ - afs_uint64 timeout_offset; /* offset of timeout queue heads */ - afs_uint64 fehash_offset; /* offset of file entry hash buckets */ - afs_uint64 fe_offset; /* offset of first file entry */ -}; - -/* 32 byte header */ -struct callback_state_timeout_header { - afs_uint32 magic; /* magic number for timeout header */ - afs_uint32 len; /* total length of header and timeout records */ - afs_uint32 records; /* number of timeout records */ - afs_uint32 reserved[5]; -}; - -/* 32 byte header */ -struct callback_state_fehash_header { - afs_uint32 magic; /* magic number for fehash header */ - afs_uint32 len; /* total length of header and fehash bucket heads */ - afs_uint32 records; /* number of hash buckets */ - afs_uint32 reserved[5]; -}; - -/* 32 byte header */ -struct callback_state_entry_header { - afs_uint32 magic; /* magic number for FE entry */ - afs_uint32 len; /* number of bytes in this record */ - afs_uint32 nCBs; /* number of callbacks for this FE */ - afs_uint32 reserved[5]; -}; - -struct FEDiskEntry { - struct FileEntry fe; - afs_uint32 index; -}; - -struct CBDiskEntry { - struct CallBack cb; - afs_uint32 index; -}; - -/* - * active volumes state serialization - * - * these structures are meant to support - * automated salvaging of active volumes - * in the event of a fileserver crash - */ - -/* 512 byte header */ -struct active_volume_state_header { - struct disk_version_stamp stamp; /* callback state version stamp */ - afs_uint32 nAVEs; /* number of ActiveVolumeEntry records */ - afs_uint32 init_timestamp; /* timestamp of AVE initialization */ - afs_uint32 update_timetamp; /* timestamp of last AVE update */ - afs_uint32 reserved[119]; /* for expansion */ - afs_uint64 avehash_offset; /* offset of active volume entry hash buckets */ - afs_uint64 ave_offset; /* offset of first active volume entry */ -}; - -/* 32 byte header */ -struct active_volume_state_avehash_header { - afs_uint32 magic; /* magic number for avehash header */ - afs_uint32 len; /* total length of header and avehash bucket heads */ - afs_uint32 records; /* number of hash buckets */ - afs_uint32 reserved[5]; -}; - -typedef afs_uint32 active_volume_state_avehash_entry; - -/* active volume entry */ -struct AVDiskEntry { - afs_uint32 volume; - afs_uint32 partition; - afs_uint32 hash_next; -}; - - -/* - * dump runtime state - */ -struct idx_map_entry_t { - byte valid; /* whether or not this entry has been populated */ - afs_uint32 old_idx; /* host hash id from last runtime */ - afs_uint32 new_idx; /* host hash id for this runtime */ -}; - - -/* verification process sanity check constants - * - * make them fairly large so we don't get - * false positives - */ -#define FS_STATE_H_MAX_UUID_HASH_CHAIN_LEN 100000 /* max elements in a host uuid-hash chain */ -#define FS_STATE_H_MAX_ADDR_HASH_CHAIN_LEN 2000000 /* max elements in a host ipv4-hash chain */ -#define FS_STATE_FE_MAX_HASH_CHAIN_LEN 100000 /* max elements in a FE fid-hash chain */ -#define FS_STATE_FCB_MAX_LIST_LEN 100000 /* max elements in a per-FE CB list */ -#define FS_STATE_HCB_MAX_LIST_LEN 100000 /* max elements in a per-host CB list */ -#define FS_STATE_TCB_MAX_LIST_LEN 100000 /* max elements in a per-timeout CB list */ - - -/* - * main state serialization state structure - */ - -struct fs_dump_state { - enum { - FS_STATE_DUMP_MODE, - FS_STATE_LOAD_MODE - } mode; - struct { - byte do_host_restore; /* whether host restore should be done */ - byte some_steps_skipped; /* whether some steps were skipped */ - byte warnings_generated; /* whether any warnings were generated during restore */ - } flags; - afs_fsize_t file_len; - int fd; /* fd of the current dump file */ - int bail; /* non-zero if something went wrong */ - char * fn; /* name of the current dump file */ - struct { /* memory map of dump file */ - void * map; - void * cursor; - afs_foff_t offset; - afs_fsize_t size; - } mmap; - struct fs_state_header * hdr; /* main header */ - struct host_state_header * h_hdr; /* header for host state data */ - struct callback_state_header * cb_hdr; /* header for callback state data */ - struct callback_state_timeout_header * cb_timeout_hdr; - struct callback_state_fehash_header * cb_fehash_hdr; - afs_uint64 eof_offset; /* current end of file offset */ - struct { - int len; /* number of host entries in map */ - struct idx_map_entry_t * entries; - } h_map; - struct { - int len; - struct idx_map_entry_t * entries; - } fe_map; - struct { - int len; - struct idx_map_entry_t * entries; - } cb_map; -}; - -/* prototypes */ - -/* serialize_state.c */ -extern int fs_stateFileOpen(struct fs_dump_state *state); -extern int fs_stateWrite(struct fs_dump_state * state, - void * buf, size_t len); -extern int fs_stateRead(struct fs_dump_state * state, - void * buf, size_t len); -extern int fs_stateWriteV(struct fs_dump_state * state, - struct iovec * iov, int niov); -extern int fs_stateReadV(struct fs_dump_state * state, - struct iovec * iov, int niov); -extern int fs_stateSync(struct fs_dump_state * state); -extern int fs_stateWriteHeader(struct fs_dump_state * state, - afs_uint64 * offset, - void * hdr, size_t len); -extern int fs_stateReadHeader(struct fs_dump_state * state, - afs_uint64 * offset, - void * hdr, size_t len); -extern int fs_stateIncEOF(struct fs_dump_state * state, - afs_int32 len); -extern int fs_stateSeek(struct fs_dump_state * state, - afs_uint64 * offset); - -/* host.c */ -extern int h_stateSave(struct fs_dump_state * state); -extern int h_stateRestore(struct fs_dump_state * state); -extern int h_stateRestoreIndices(struct fs_dump_state * state); -extern int h_stateVerify(struct fs_dump_state * state); -extern int h_OldToNew(struct fs_dump_state * state, afs_uint32 old, afs_uint32 * new); - -/* callback.c */ -extern int cb_stateSave(struct fs_dump_state * state); -extern int cb_stateRestore(struct fs_dump_state * state); -extern int cb_stateRestoreIndices(struct fs_dump_state * state); -extern int cb_stateVerify(struct fs_dump_state * state); -extern int cb_stateVerifyHCBList(struct fs_dump_state * state, struct host * host); -extern int fe_OldToNew(struct fs_dump_state * state, afs_uint32 old, afs_uint32 * new); -extern int cb_OldToNew(struct fs_dump_state * state, afs_uint32 old, afs_uint32 * new); - -#endif /* AFS_DEMAND_ATTACH_FS */ -#endif /* _AFS_TVICED_SERIALIZE_STATE_H */ diff --git a/src/tviced/state_analyzer.c b/src/tviced/state_analyzer.c deleted file mode 100644 index 5302d1d11..000000000 --- a/src/tviced/state_analyzer.c +++ /dev/null @@ -1,1949 +0,0 @@ -/* - * Copyright 2006, Sine Nomine Associates and others. - * All Rights Reserved. - * - * This software has been released under the terms of the IBM Public - * License. For details, see the LICENSE file in the top-level source - * directory or online at http://www.openafs.org/dl/license10.html - */ - -/* - * demand attach fs - * fileserver state serialization - * - * state analyzer - */ - -#include -#include -#include - -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#ifdef AFS_ATHENA_STDENV -#include -#endif -#include -#include -#include -#include -#include -#include -#include "../util/afsutil_prototypes.h" -#include "../viced/viced.h" -#include "../viced/host.h" -#include "../viced/callback.h" -#include "serialize_state.h" - -#ifndef AFS_DEMAND_ATTACH_FS -int -main (int argc, char ** argv) -{ - fprintf(stderr, "%s is only supported for demand attach fileservers\n", - argv[0] ? argv[0] : "state analyzer"); - return 1; -} -#else /* AFS_DEMAND_ATTACH_FS */ - -static void usage(char * prog); -static int openFile(char * path); -static void initState(void); - -static void banner(void); -static void prompt(void); - -static void print_help(void); -static void print_global_help(void); -static void print_h_help(void); -static void print_fe_help(void); -static void print_cb_help(void); - -static void dump_hdr(void); -static void dump_h_hdr(void); -static void dump_cb_hdr(void); - -static void dump_cb_timeout(void); -static void dump_cb_fehash(void); - -static void dump_all_hes(void); -static void dump_all_fes(void); -static void dump_all_cbs(void); - -static void dump_he(afs_uint32 idx); -static void dump_fe(afs_uint32 idx); -static void dump_cb(afs_uint32 idx); -static void dump_this_he(void); -static void dump_this_fe(void); -static void dump_this_cb(void); -static void dump_next_he(void); -static void dump_next_fe(void); -static void dump_next_cb(void); -static void dump_prev_he(void); -static void dump_prev_fe(void); -static void dump_prev_cb(void); -static void dump_first_he(void); -static void dump_first_fe(void); -static void dump_first_cb(void); -static void dump_last_he(void); -static void dump_last_fe(void); -static void dump_last_cb(void); -static void dump_he_hdr(void); -static void dump_he_entry(void); -static void dump_he_interfaces(void); -static void dump_he_hcps(void); -static void dump_fe_hdr(void); -static void dump_fe_entry(void); -static void dump_cb_entry(void); - -static void hexdump_map(afs_uint32 offset, afs_uint32 len); - -static int get_hdr(void); -static int get_h_hdr(void); -static int get_cb_hdr(void); -static int get_cb_timeout_hdr(void); -static int get_cb_timeout(void); -static int get_cb_fehash_hdr(void); -static int get_cb_fehash(void); -static int get_he(afs_uint32 idx); -static int get_he_hdr(void); -static int get_he_entry(void); -static int get_fe(afs_uint32 idx); -static int get_fe_hdr(void); -static int get_fe_entry(void); -static int get_cb(afs_uint32 idx); -static int get_cb_entry(void); - -static int find_fe_by_index(afs_uint32 idx); -static int find_cb_by_index(afs_uint32 idx); -static int find_fe_by_fid(afs_uint32 vol, afs_uint32 vn, afs_uint32 uniq); - - -static int dump_fd = -1; -static void * map = NULL; -static size_t map_len; - -static struct { - struct fs_state_header hdr; - struct host_state_header h_hdr; - struct callback_state_header cb_hdr; - struct callback_state_timeout_header timeout_hdr; - struct callback_state_fehash_header fehash_hdr; - afs_uint32 * timeout; - afs_uint32 * fehash; - - /* pointers into the memory map */ - void * hdr_p; - void * h_hdr_p; - void * cb_hdr_p; - void * timeout_hdr_p; - void * timeout_p; - void * fehash_hdr_p; - void * fehash_p; - - byte hdr_valid; - byte h_hdr_valid; - byte cb_hdr_valid; - byte timeout_hdr_valid; - byte fehash_hdr_valid; -} hdrs; - -static struct { - void * fh; - void * cursor; - void * ifp; - void * hcps; - struct host_state_entry_header hdr; - struct hostDiskEntry he; - afs_uint32 idx; - byte hdr_valid; - byte he_valid; -} he_cursor; - -static struct { - void ** cursor; -} he_cache; - -static struct { - void * ffe; - void * cursor; - void * fcb; - struct callback_state_entry_header hdr; - struct FEDiskEntry fe; - afs_uint32 idx; - byte hdr_valid; - byte fe_valid; -} fe_cursor; - -static struct { - void ** cursor; -} fe_cache; - -static struct { - void * cursor; - struct CBDiskEntry cb; - afs_uint32 idx; - byte cb_valid; -} cb_cursor; - -static void -usage(char * prog) -{ - fprintf(stderr, "usage: %s []\n", prog); -} - -int -main(int argc, char ** argv) -{ - banner(); - if (argc > 2 || (argc == 2 && !strcmp(argv[1], "-h"))) { - usage(argv[0]); - return 1; - } - - initState(); - - if (argc > 1) { - if (openFile(argv[1])) - return 1; - } else { - if (openFile((char *)AFSDIR_SERVER_FSSTATE_FILEPATH)) - return 1; - } - - prompt(); - return 0; -} - - -static int -openFile(char * path) -{ - int ret = 0; - struct afs_stat status; - - dump_fd = afs_open(path, O_RDWR); - if (dump_fd == -1) { - fprintf(stderr, "dump file '%s' failed to open\n", path); - ret = 1; - goto done; - } - - printf("opened dump file '%s'\n", path); - - if (afs_fstat(dump_fd, &status) == -1) { - fprintf(stderr, "failed to stat file\n"); - ret = 1; - goto done; - } - - map_len = status.st_size; - - map = afs_mmap(NULL, map_len, PROT_READ, MAP_SHARED, dump_fd, 0); - if (map == MAP_FAILED) { - fprintf(stderr, "failed to mmap file\n"); - ret = 1; - goto done; - } - - printf("mapped %lu bytes at %"AFS_PTR_FMT"\n", (unsigned long)map_len, map); - - done: - if (ret) { - if (map) { - munmap(map, map_len); - map = NULL; - } - if (dump_fd != -1) { - close(dump_fd); - dump_fd = -1; - } - } - return ret; -} - -static void -initState(void) -{ - hdrs.hdr_valid = hdrs.h_hdr_valid = hdrs.cb_hdr_valid = 0; - he_cursor.cursor = fe_cursor.cursor = cb_cursor.cursor = NULL; - he_cursor.fh = fe_cursor.ffe = fe_cursor.fcb = NULL; - he_cache.cursor = fe_cache.cursor = NULL; -} - -static void -banner(void) -{ - fprintf(stderr, "demand attach fs\n"); - fprintf(stderr, "fileserver state analyzer\n"); - fprintf(stderr, "version 0.1\n"); -} - -#define PROGNAME "fs state analyzer" - -static void -prompt(void) -{ - char input[256]; - char prev_input[256]; - char * tok = NULL; - afs_uint32 x, y, z; - enum { - PR_GLOBAL_MODE, - PR_H_MODE, - PR_FE_MODE, - PR_CB_MODE - } mode = PR_GLOBAL_MODE, next_mode; - - next_mode = mode; - input[0] = prev_input[0] = '\0'; - - while (1) { - if (!tok) { - switch(mode) { - case PR_GLOBAL_MODE: - printf(PROGNAME "> "); - break; - case PR_H_MODE: - printf(PROGNAME ": h(%d)> ", he_cursor.idx); - break; - case PR_FE_MODE: - printf(PROGNAME ": fe(%d)> ", fe_cursor.idx); - break; - case PR_CB_MODE: - printf(PROGNAME ": fe(%d):cb(%d)> ", fe_cursor.idx, cb_cursor.idx); - break; - default: - fprintf(stderr, "prompt state broken; aborting\n"); - return; - } - fgets(input, 256, stdin); - - if (!strcmp(input, "")) { - /* repeat last command */ - if (!strcmp(prev_input, "")) { - continue; - } - strlcpy(input, prev_input, sizeof(input)); - } else { - /* save command for repetition */ - strlcpy(prev_input, input, sizeof(prev_input)); - } - - tok = strtok(input, " \t\n"); - } - while (tok && !strcmp(tok, ";")) { - tok = strtok(NULL, "; \t\n"); - } - - if (!tok) { - continue; - } - - if (!strcasecmp(tok, "exit")) { - return; - } else if (!strcasecmp(tok, "quit")) { - switch(mode) { - case PR_CB_MODE: - next_mode = PR_FE_MODE; - break; - case PR_FE_MODE: - case PR_H_MODE: - next_mode = PR_GLOBAL_MODE; - break; - default: - return; - } - } else if (!strcasecmp(tok, "h")) { - tok = strtok(NULL, " \t"); - mode = PR_H_MODE; - if (!tok) { - next_mode = mode; - } - continue; - } else if (!strcasecmp(tok, "fe")) { - tok = strtok(NULL, " \t"); - mode = PR_FE_MODE; - if (!tok) { - next_mode = mode; - } - continue; - } else if (!strcasecmp(tok, "fs")) { - tok = strtok(NULL, " \t"); - mode = PR_GLOBAL_MODE; - if (!tok) { - next_mode = mode; - } - continue; - } else if (!strcasecmp(tok, "cb")) { - tok = strtok(NULL, " \t"); - mode = PR_CB_MODE; - if (!tok) { - next_mode = mode; - } - continue; - } else if (!strcasecmp(tok, "help")) { - switch(mode) { - case PR_H_MODE: - print_h_help(); - break; - case PR_FE_MODE: - print_fe_help(); - break; - case PR_CB_MODE: - print_cb_help(); - break; - default: - print_global_help(); - } - print_help(); - } else if (!strcasecmp(tok, "hexdump")) { - tok = strtok(NULL, " \t"); - if (!tok) { - hexdump_map(0, map_len); - continue; - } - if (sscanf(tok, "%u", &x) != 1) { - fprintf(stderr, "hexdump parse error 1\n"); - tok = NULL; - continue; - } - tok = strtok(NULL, " \t"); - if (!tok) { - hexdump_map(x, map_len - x); - continue; - } - if (sscanf(tok, "%u", &y) != 1) { - fprintf(stderr, "hexdump parse error 2\n"); - continue; - } - hexdump_map(x,y); - } else if (!strcasecmp(tok, "hdr")) { - switch(mode) { - case PR_H_MODE: - dump_h_hdr(); - break; - case PR_FE_MODE: - dump_cb_hdr(); - break; - case PR_CB_MODE: - dump_this_fe(); - break; - default: - dump_hdr(); - } - } else if (!strcasecmp(tok, "this")) { - switch(mode) { - case PR_H_MODE: - dump_this_he(); - break; - case PR_FE_MODE: - dump_this_fe(); - break; - case PR_CB_MODE: - dump_this_cb(); - break; - default: - fprintf(stderr, "command not valid for this mode\n"); - } - } else if (!strcasecmp(tok, "next")) { - switch(mode) { - case PR_H_MODE: - dump_next_he(); - break; - case PR_FE_MODE: - dump_next_fe(); - break; - case PR_CB_MODE: - dump_next_cb(); - break; - default: - fprintf(stderr, "command not valid for this mode\n"); - } - } else if (!strcasecmp(tok, "prev")) { - switch(mode) { - case PR_H_MODE: - dump_prev_he(); - break; - case PR_FE_MODE: - dump_prev_fe(); - break; - case PR_CB_MODE: - dump_prev_cb(); - break; - default: - fprintf(stderr, "command not valid for this mode\n"); - } - } else if (!strcasecmp(tok, "first")) { - switch(mode) { - case PR_H_MODE: - dump_first_he(); - break; - case PR_FE_MODE: - dump_first_fe(); - break; - case PR_CB_MODE: - dump_first_cb(); - break; - default: - fprintf(stderr, "command not valid for this mode\n"); - } - } else if (!strcasecmp(tok, "last")) { - switch(mode) { - case PR_H_MODE: - dump_last_he(); - break; - case PR_FE_MODE: - dump_last_fe(); - break; - case PR_CB_MODE: - dump_last_cb(); - break; - default: - fprintf(stderr, "command not valid for this mode\n"); - } - } else if (!strcasecmp(tok, "dump")) { - switch(mode) { - case PR_H_MODE: - dump_all_hes(); - break; - case PR_FE_MODE: - dump_all_fes(); - break; - case PR_CB_MODE: - dump_all_cbs(); - break; - default: - fprintf(stderr, "command not valid for this mode\n"); - } - } else if (!strcasecmp(tok, "find")) { - tok = strtok(NULL, " \t"); - if (!tok || strcasecmp(tok, "by")) { - tok = NULL; - fprintf(stderr, "find syntax error 1 (%s)\n", - (tok) ? tok : "nil"); - continue; - } - tok = strtok(NULL, " \t"); - if (!tok) { - fprintf(stderr, "find syntax error 2\n"); - continue; - } - switch(mode) { - case PR_H_MODE: - fprintf(stderr, "not implemented yet\n"); - break; - case PR_FE_MODE: - if (!strcasecmp(tok, "index")) { - tok = strtok(NULL, " \t"); - if (!tok || sscanf(tok, "%u", &x) != 1) { - tok = NULL; - fprintf(stderr, "find syntax error 3\n"); - continue; - } - if (find_fe_by_index(x)) { - fprintf(stderr, "find returned no results\n"); - } - } else if (!strcasecmp(tok, "fid")) { - tok = strtok(NULL, "(), \t"); - if (!tok || sscanf(tok, "%u", &x) != 1) { - tok = NULL; - fprintf(stderr, "find syntax error 4\n"); - continue; - } - tok = strtok(NULL, "(), \t"); - if (!tok || sscanf(tok, "%u", &y) != 1) { - tok = NULL; - fprintf(stderr, "find syntax error 5\n"); - continue; - } - tok = strtok(NULL, "(), \t"); - if (!tok || sscanf(tok, "%u", &z) != 1) { - tok = NULL; - fprintf(stderr, "find syntax error 6\n"); - continue; - } - if (find_fe_by_fid(x,y,z)) { - fprintf(stderr, "find returned no results\n"); - } - } else { - fprintf(stderr, "unsupported filter type\n"); - } - break; - case PR_CB_MODE: - if (!strcasecmp(tok, "index")) { - tok = strtok(NULL, " \t"); - if (!tok || sscanf(tok, "%u", &x) != 1) { - tok = NULL; - fprintf(stderr, "find syntax error 3\n"); - continue; - } - if (find_cb_by_index(x)) { - fprintf(stderr, "find returned no results\n"); - } - } else { - fprintf(stderr, "unsupported filter type\n"); - } - break; - default: - fprintf(stderr, "find not supported for this menu\n"); - } - } else if (!strcspn(tok, "0123456789")) { - if (sscanf(tok, "%u", &x) == 1) { - switch(mode) { - case PR_H_MODE: - dump_he(x); - break; - case PR_FE_MODE: - dump_fe(x); - break; - case PR_CB_MODE: - dump_cb(x); - break; - default: - fprintf(stderr, "command not available from this menu\n"); - } - } else { - fprintf(stderr, "input parse error ('%s')\n", tok); - } - } else if (mode == PR_FE_MODE) { - if (!strcmp(tok, "timeout")) { - dump_cb_timeout(); - } else if (!strcmp(tok, "hash")) { - dump_cb_fehash(); - } - } else { - fprintf(stderr, "unknown command\n"); - } - tok = strtok(NULL, " \t"); - mode = next_mode; - } -} - -static void -print_help(void) -{ - printf("\th <...> -- host menu commands\n"); - printf("\tfe <...> -- FileEntry menu commands\n"); - printf("\tcb <...> -- CallBack menu commands\n"); - printf("\thexdump [ []]\n\t\t -- hex dump the raw data\n"); - printf("\tquit -- quit this menu\n"); - printf("\texit -- exit the debugger\n"); - printf("\thelp -- this help message\n"); -} - -static void -print_global_help(void) -{ - printf("\thdr -- display the fs_state_header struct\n"); -} - -static void -print_h_help(void) -{ - printf("\thdr -- display the host_state_header struct\n"); - printf("\tfirst -- display the first host\n"); - printf("\tprev -- display the previous host\n"); - printf("\tthis -- display this host\n"); - printf("\tnext -- display the next host\n"); - printf("\tlast -- display the last host\n"); - printf("\tdump -- display all hosts\n"); -} - -static void -print_fe_help(void) -{ - printf("\thdr -- display the callback_state_header struct\n"); - printf("\tfirst -- display the first FE\n"); - printf("\tprev -- display the previous FE\n"); - printf("\tthis -- display this FE\n"); - printf("\tnext -- display the next FE\n"); - printf("\tlast -- display the last FE\n"); - printf("\tdump -- display all FEs\n"); - printf("\ttimeout -- display the timeout queue heads\n"); - printf("\thash -- display the file entry hash buckets\n"); - printf("\tfind by index \n\t\t -- find an fe by its array index\n"); - printf("\tfind by fid <(vol,vnode,unique)>\n\t\t -- find an fe by its AFSFid\n"); -} - -static void -print_cb_help(void) -{ - printf("\thdr -- display the callback_state_entry_header struct\n"); - printf("\tfirst -- display the first CB\n"); - printf("\tprev -- display the previous CB\n"); - printf("\tthis -- display this CB\n"); - printf("\tnext -- display the next CB\n"); - printf("\tlast -- display the last CB\n"); - printf("\tdump -- display all CBs\n"); -} - -#define DPFTB0 "\t" -#define DPFTB1 "\t\t" -#define DPFTB2 "\t\t\t" - -#define DPFOFF(addr) \ - do { \ - char * _p = (char *)addr; \ - char * _m = (char *)map; \ - printf("loading structure from address %"AFS_PTR_FMT" (offset %ld)\n", \ - addr, (long)(_p-_m)); \ - } while (0) - -/* structs */ -#define DPFSO(T, name) printf(T "%s = {\n", name) -#define DPFSO0(name) DPFSO(DPFTB0, name) -#define DPFSO1(name) DPFSO(DPFTB1, name) -#define DPFSC(T) printf(T "}\n") -#define DPFSC0 DPFSC(DPFTB0) -#define DPFSC1 DPFSC(DPFTB1) - -/* arrays */ -#define DPFAO(T1, T2, name) printf(T1 "%s =\n" T2 "{ ", name) -#define DPFAO0(name) DPFAO(DPFTB0, DPFTB1, name) -#define DPFAO1(name) DPFAO(DPFTB1, DPFTB2, name) -#define DPFAC0 printf(" }\n") -#define DPFAC1 DPFAC0 -#define DPFA1 printf(DPFTB1 " ") -#define DPFA2 printf(DPFTB2 " ") -#define DPFAN printf("\n") -#define DPFALE(type, var) printf("%" type, var) -#define DPFAE(type, var) printf("%" type ",\t", var) - -/* normal vars */ -#define DPFV(T, name, type, var) printf(T "%s = %" type "\n", name, var) -#define DPFV1(name, type, var) DPFV(DPFTB1, name, type, var) -#define DPFV2(name, type, var) DPFV(DPFTB2, name, type, var) - -/* hex */ -#define DPFX(T, name, var) printf(T "%s = 0x%x\n", name, var) -#define DPFX1(name, var) DPFX(DPFTB1, name, var) -#define DPFX2(name, var) DPFX(DPFTB2, name, var) - -/* strings */ -#define DPFS(T, name, var) printf(T "%s = \"%s\"\n", name, var) -#define DPFS1(name, var) DPFS(DPFTB1, name, var) -#define DPFS2(name, var) DPFS(DPFTB2, name, var) - -/* time */ -#define DPFT(T, name, var) \ - do { \ - time_t t = var; \ - printf(T "%s = \"%.24s\"\n", name, ctime(&t)); \ - } while(0) -#define DPFT1(name, var) DPFT(DPFTB1, name, var) -#define DPFT2(name, var) DPFT(DPFTB2, name, var) - -static void -dump_hdr(void) -{ - char uuid_str[40]; - afs_uint32 hi, lo; - - if (get_hdr()) - return; - - DPFOFF(map); - DPFSO0("fs_state_header"); - DPFSO1("stamp"); - DPFX2("magic", hdrs.hdr.stamp.magic); - DPFV2("version", "u", hdrs.hdr.stamp.version); - DPFSC1; - DPFT1("timestamp", hdrs.hdr.timestamp); - DPFV1("sys_name", "u", hdrs.hdr.sys_name); - - afsUUID_to_string(&hdrs.hdr.server_uuid, uuid_str, sizeof(uuid_str)); - DPFS1("server_uuid", uuid_str); - DPFV1("valid", "d", hdrs.hdr.valid); - DPFV1("endianness", "d", hdrs.hdr.endianness); - DPFV1("stats_detailed", "d", hdrs.hdr.stats_detailed); - - SplitInt64(hdrs.hdr.h_offset, hi, lo); - DPFSO1("h_offset"); - DPFV2("hi", "u", hi); - DPFV2("lo", "u", lo); - DPFSC1; - - SplitInt64(hdrs.hdr.cb_offset, hi, lo); - DPFSO1("cb_offset"); - DPFV2("hi", "u", hi); - DPFV2("lo", "u", lo); - DPFSC1; - - DPFS1("server_version_string", hdrs.hdr.server_version_string); - DPFSC0; - - if (hdrs.hdr.stamp.magic != FS_STATE_MAGIC) { - fprintf(stderr, "* magic check failed\n"); - } - if (hdrs.hdr.stamp.version != FS_STATE_VERSION) { - fprintf(stderr, "* version check failed\n"); - } -} - -static void -dump_h_hdr(void) -{ - if (get_h_hdr()) - return; - - DPFOFF(hdrs.h_hdr_p); - DPFSO0("host_state_header"); - DPFSO1("stamp"); - DPFX2("magic", hdrs.h_hdr.stamp.magic); - DPFV2("version", "u", hdrs.h_hdr.stamp.version); - DPFSC1; - DPFV1("records", "u", hdrs.h_hdr.records); - DPFV1("index_max", "u", hdrs.h_hdr.index_max); - DPFSC0; - - if (hdrs.h_hdr.stamp.magic != HOST_STATE_MAGIC) { - fprintf(stderr, "* magic check failed\n"); - } - if (hdrs.h_hdr.stamp.version != HOST_STATE_VERSION) { - fprintf(stderr, "* version check failed\n"); - } -} - -static void -dump_cb_hdr(void) -{ - afs_uint32 hi, lo; - - if (get_cb_hdr()) - return; - - DPFOFF(hdrs.cb_hdr_p); - DPFSO0("callback_state_header"); - DPFSO1("stamp"); - DPFX2("magic", hdrs.cb_hdr.stamp.magic); - DPFV2("version", "u", hdrs.cb_hdr.stamp.version); - DPFSC1; - DPFV1("nFEs", "u", hdrs.cb_hdr.nFEs); - DPFV1("nCBs", "u", hdrs.cb_hdr.nCBs); - DPFV1("fe_max", "u", hdrs.cb_hdr.fe_max); - DPFV1("cb_max", "u", hdrs.cb_hdr.cb_max); - DPFV1("tfirst", "d", hdrs.cb_hdr.tfirst); - - SplitInt64(hdrs.cb_hdr.timeout_offset, hi, lo); - DPFSO1("timeout_offset"); - DPFV2("hi", "u", hi); - DPFV2("lo", "u", lo); - DPFSC1; - - SplitInt64(hdrs.cb_hdr.fehash_offset, hi, lo); - DPFSO1("fehash_offset"); - DPFV2("hi", "u", hi); - DPFV2("lo", "u", lo); - DPFSC1; - - SplitInt64(hdrs.cb_hdr.fe_offset, hi, lo); - DPFSO1("fe_offset"); - DPFV2("hi", "u", hi); - DPFV2("lo", "u", lo); - DPFSC1; - - DPFSC0; - - if (hdrs.cb_hdr.stamp.magic != CALLBACK_STATE_MAGIC) { - fprintf(stderr, "* magic check failed\n"); - } - if (hdrs.cb_hdr.stamp.version != CALLBACK_STATE_VERSION) { - fprintf(stderr, "* version check failed\n"); - } -} - -static void -dump_cb_timeout(void) -{ - int i; - - if (get_cb_hdr()) - return; - - if (get_cb_timeout_hdr()) - return; - - if (get_cb_timeout()) - return; - - DPFOFF(hdrs.timeout_hdr_p); - DPFSO0("callback_state_timeout_header"); - DPFX1("magic", hdrs.timeout_hdr.magic); - DPFV1("len", "u", hdrs.timeout_hdr.len); - DPFV1("records", "u", hdrs.timeout_hdr.records); - DPFSC0; - - if (hdrs.timeout_hdr.magic != CALLBACK_STATE_TIMEOUT_MAGIC) { - fprintf(stderr, "* magic check failed\n"); - } - - DPFOFF(hdrs.timeout_p); - DPFAO0("timeout"); - for (i = 0; i < 127; i++) { - DPFAE("u", hdrs.timeout[i]); - if ((i % 8) == 7) { - DPFAN; - DPFA1; - } - } - DPFALE("u", hdrs.timeout[127]); - DPFAC0; -} - -static void -dump_cb_fehash(void) -{ - int i; - - if (get_cb_hdr()) - return; - - if (get_cb_fehash_hdr()) - return; - - if (get_cb_fehash()) - return; - - DPFOFF(hdrs.fehash_hdr_p); - DPFSO0("callback_state_fehash_header"); - DPFX1("magic", hdrs.fehash_hdr.magic); - DPFV1("len", "u", hdrs.fehash_hdr.len); - DPFV1("records", "u", hdrs.fehash_hdr.records); - DPFSC0; - - if (hdrs.fehash_hdr.magic != CALLBACK_STATE_FEHASH_MAGIC) { - fprintf(stderr, "* magic check failed\n"); - } - - DPFOFF(hdrs.fehash_p); - DPFAO0("fehash"); - for (i = 0; i < hdrs.fehash_hdr.records - 1; i++) { - DPFAE("u", hdrs.fehash[i]); - if ((i % 8) == 7) { - DPFAN; - DPFA1; - } - } - DPFALE("u", hdrs.fehash[hdrs.fehash_hdr.records-1]); - DPFAC0; -} - -static void -dump_all_hes(void) -{ - int i; - - if (get_h_hdr()) { - fprintf(stderr, "error getting host_state_header\n"); - return; - } - - for (i = 0; i < hdrs.h_hdr.records; i++) { - dump_he(i); - } -} - -static void -dump_all_fes(void) -{ - int i; - - if (get_cb_hdr()) { - fprintf(stderr, "error getting callback_state_header\n"); - return; - } - - for (i = 0; i < hdrs.cb_hdr.nFEs; i++) { - dump_fe(i); - } -} - -static void -dump_all_cbs(void) -{ - int i; - - if (get_fe_hdr()) { - fprintf(stderr, "error getting callback_state_entry_header\n"); - return; - } - - for (i = 0; i < fe_cursor.hdr.nCBs; i++) { - dump_cb(i); - } -} - -static void -dump_he(afs_uint32 idx) -{ - if (get_he(idx)) { - fprintf(stderr, "error getting he %d\n", idx); - return; - } - - DPFOFF(he_cursor.cursor); - dump_he_hdr(); - dump_he_entry(); - dump_he_interfaces(); - dump_he_hcps(); -} - -static void -dump_fe(afs_uint32 idx) -{ - if (get_fe(idx)) { - fprintf(stderr, "error getting fe %d\n", idx); - return; - } - - DPFOFF(fe_cursor.cursor); - dump_fe_hdr(); - dump_fe_entry(); -} - -static void -dump_cb(afs_uint32 idx) -{ - if (get_cb(idx)) { - fprintf(stderr, "error getting cb %d\n", idx); - return; - } - - DPFOFF(cb_cursor.cursor); - dump_cb_entry(); -} - -static void -dump_this_he(void) -{ - dump_he(he_cursor.idx); -} - -static void -dump_this_fe(void) -{ - dump_fe(fe_cursor.idx); -} - -static void -dump_this_cb(void) -{ - dump_cb(cb_cursor.idx); -} - -static void -dump_next_he(void) -{ - if (get_h_hdr()) { - fprintf(stderr, "error getting host_state_header\n"); - return; - } - - if ((he_cursor.idx + 1) >= hdrs.h_hdr.records) { - fprintf(stderr, "no more HEs\n"); - return; - } - - dump_he(he_cursor.idx+1); -} - -static void -dump_next_fe(void) -{ - if (get_cb_hdr()) { - fprintf(stderr, "error getting callback_state_header\n"); - return; - } - - if ((fe_cursor.idx + 1) >= hdrs.cb_hdr.nFEs) { - fprintf(stderr, "no more FEs\n"); - return; - } - - dump_fe(fe_cursor.idx+1); -} - -static void -dump_next_cb(void) -{ - if (get_fe_hdr()) { - fprintf(stderr, "error getting callback_state_entry_header\n"); - return; - } - - if ((cb_cursor.idx + 1) >= fe_cursor.hdr.nCBs) { - fprintf(stderr, "no more CBs\n"); - return; - } - - dump_cb(cb_cursor.idx+1); -} - -static void -dump_prev_he(void) -{ - if (!he_cursor.idx) { - fprintf(stderr, "no more HEs\n"); - return; - } - - dump_he(he_cursor.idx-1); -} - -static void -dump_prev_fe(void) -{ - if (!fe_cursor.idx) { - fprintf(stderr, "no more FEs\n"); - return; - } - - dump_fe(fe_cursor.idx-1); -} - -static void -dump_prev_cb(void) -{ - if (!cb_cursor.idx) { - fprintf(stderr, "no more CBs\n"); - return; - } - - dump_cb(cb_cursor.idx-1); -} - -static void -dump_first_fe(void) -{ - if (get_cb_hdr()) { - fprintf(stderr, "error getting callback_state_header\n"); - return; - } - - if (!hdrs.cb_hdr.nFEs) { - fprintf(stderr, "no FEs present\n"); - return; - } - - dump_fe(0); -} - -static void -dump_first_he(void) -{ - if (get_h_hdr()) { - fprintf(stderr, "error getting host_state_header\n"); - return; - } - - if (!hdrs.h_hdr.records) { - fprintf(stderr, "no HEs present\n"); - return; - } - - dump_he(0); -} - -static void -dump_first_cb(void) -{ - if (get_fe_hdr()) { - fprintf(stderr, "error getting callback_state_entry_header\n"); - return; - } - - if (!fe_cursor.hdr.nCBs) { - fprintf(stderr, "no CBs present\n"); - return; - } - - dump_cb(0); -} - -static void -dump_last_he(void) -{ - if (get_h_hdr()) { - fprintf(stderr, "error getting host_state_header\n"); - return; - } - - if (!hdrs.h_hdr.records) { - fprintf(stderr, "no HEs present\n"); - return; - } - - dump_he(hdrs.h_hdr.records-1); -} - -static void -dump_last_fe(void) -{ - if (get_cb_hdr()) { - fprintf(stderr, "error getting callback_state_header\n"); - return; - } - - if (!hdrs.cb_hdr.nFEs) { - fprintf(stderr, "no FEs present\n"); - return; - } - - dump_fe(hdrs.cb_hdr.nFEs-1); -} - -static void -dump_last_cb(void) -{ - if (get_fe_hdr()) { - fprintf(stderr, "error getting callback_state_entry_header\n"); - return; - } - - if (!fe_cursor.hdr.nCBs) { - fprintf(stderr, "no CBs present\n"); - return; - } - - dump_cb(fe_cursor.hdr.nCBs-1); -} - -static void -dump_he_hdr(void) -{ - DPFSO0("host_state_entry_header"); - DPFX1("magic", he_cursor.hdr.magic); - DPFV1("len", "u", he_cursor.hdr.len); - DPFV1("interfaces", "u", he_cursor.hdr.interfaces); - DPFV1("hcps", "u", he_cursor.hdr.hcps); - DPFSC0; - - if (he_cursor.hdr.magic != HOST_STATE_ENTRY_MAGIC) { - fprintf(stderr, "* magic check failed\n"); - } -} - -static void -dump_he_entry(void) -{ - char hoststr[16]; - DPFSO0("hostDiskEntry"); - DPFS1("host", afs_inet_ntoa_r(he_cursor.he.host, hoststr)); - DPFV1("port", "u", he_cursor.he.port); - DPFX1("hostFlags", he_cursor.he.hostFlags); - DPFV1("Console", "u", he_cursor.he.Console); - DPFV1("hcpsfailed", "u", he_cursor.he.hcpsfailed); - DPFV1("hcps_valid", "u", he_cursor.he.hcps_valid); - if (hdrs.hdr.stats_detailed) { - DPFV1("InSameNetwork", "u", he_cursor.he.InSameNetwork); - } - DPFV1("hcps_len", "u", he_cursor.he.hcps_len); - DPFT1("LastCall", he_cursor.he.LastCall); - DPFT1("ActiveCall", he_cursor.he.ActiveCall); - DPFT1("cpsCall", he_cursor.he.cpsCall); - DPFV1("cblist", "u", he_cursor.he.cblist); - DPFV1("index", "u", he_cursor.he.index); - DPFSC0; -} - -static void -dump_he_interfaces(void) -{ - char temp_str[40]; - struct Interface * ifp; - int len, i; - char hoststr[16]; - - if (!he_cursor.hdr.interfaces) - return; - - len = sizeof(struct Interface) + ((he_cursor.hdr.interfaces-1)*sizeof(struct AddrPort)); - ifp = (struct Interface *) malloc(len); - assert(ifp != NULL); - - memcpy(ifp, he_cursor.ifp, len); - - DPFSO0("Interface"); - DPFV1("numberOfInterfaces", "u", ifp->numberOfInterfaces); - - afsUUID_to_string(&ifp->uuid, temp_str, sizeof(temp_str)); - DPFS1("uuid", temp_str); - for (i = 0; i < he_cursor.hdr.interfaces; i++) { - snprintf(temp_str, sizeof(temp_str), "interface[%d]", i); - DPFSO1(temp_str); - DPFS2("addr", afs_inet_ntoa_r(ifp->interface[i].addr, hoststr)); - DPFV2("port", "u", ifp->interface[i].port); - DPFSC1; - } - - DPFSC0; - - if (he_cursor.hdr.interfaces != ifp->numberOfInterfaces) { - fprintf(stderr, "* interface count mismatch between header and Interface struct\n"); - } - free(ifp); -} - -static void -dump_he_hcps(void) -{ - afs_int32 * hcps; - int len, i; - - if (!he_cursor.hdr.hcps) - return; - - len = (he_cursor.hdr.hcps)*sizeof(afs_uint32); - hcps = (afs_int32 *) malloc(len); - assert(hcps != NULL); - memcpy(hcps, he_cursor.hcps, len); - - DPFSO0("hcps"); - DPFAO1("prlist_val"); - for (i = 0; i < he_cursor.hdr.hcps - 1; i++) { - DPFAE("d", hcps[i]); - if ((i % 8) == 7) { - DPFAN; - DPFA2; - } - } - DPFALE("d", hcps[he_cursor.hdr.hcps-1]); - DPFAC1; - DPFSC0; - free(hcps); -} - -static void -dump_fe_hdr(void) -{ - DPFSO0("callback_state_entry_header"); - DPFX1("magic", fe_cursor.hdr.magic); - DPFV1("len", "u", fe_cursor.hdr.len); - DPFV1("nCBs", "u", fe_cursor.hdr.nCBs); - DPFSC0; - - if (fe_cursor.hdr.magic != CALLBACK_STATE_ENTRY_MAGIC) { - fprintf(stderr, "* magic check failed\n"); - } -} - -static void -dump_fe_entry(void) -{ - DPFSO0("FEDiskEntry"); - DPFSO1("fe"); - DPFV2("vnode", "u", fe_cursor.fe.fe.vnode); - DPFV2("unique", "u", fe_cursor.fe.fe.unique); - DPFV2("volid", "u", fe_cursor.fe.fe.volid); - DPFV2("fnext", "u", fe_cursor.fe.fe.fnext); - DPFV2("ncbs", "u", fe_cursor.fe.fe.ncbs); - DPFV2("firstcb", "u", fe_cursor.fe.fe.firstcb); - DPFV2("status", "u", fe_cursor.fe.fe.status); - DPFSC1; - DPFV1("index", "u", fe_cursor.fe.index); - DPFSC0; -} - -static void -dump_cb_entry(void) -{ - DPFSO0("CBDiskEntry"); - DPFSO1("cb"); - DPFV2("cnext", "u", cb_cursor.cb.cb.cnext); - DPFV2("fhead", "u", cb_cursor.cb.cb.fhead); - DPFV2("thead", "u", (afs_uint32)cb_cursor.cb.cb.thead); - DPFV2("status", "u", (afs_uint32)cb_cursor.cb.cb.status); - DPFV2("hhead", "u", cb_cursor.cb.cb.hhead); - DPFV2("tprev", "u", cb_cursor.cb.cb.tprev); - DPFV2("tnext", "u", cb_cursor.cb.cb.tnext); - DPFV2("hprev", "u", cb_cursor.cb.cb.hprev); - DPFV2("hnext", "u", cb_cursor.cb.cb.hnext); - DPFSC1; - DPFV1("index", "u", cb_cursor.cb.index); - DPFSC0; -} - -#define DPFHMS printf(" ") -#define DPFHS printf(" ") -#define DPFHN(offset) printf("\n%u\t", offset) -#define DPFHD(x) printf("%02X ", x) -#define DPFHE printf("\n") - -static void -hexdump_map(afs_uint32 offset, afs_uint32 len) -{ - int i; - unsigned char * p = (unsigned char *)map; - - if (!len) - return; - - if ((offset + len) > map_len) { - fprintf(stderr, "offset + length exceeds memory map size (%u > %lu)\n", - offset+len, (unsigned long)map_len); - return; - } - - p += offset; - DPFOFF(p); - DPFHN(offset); - - for (i = offset % 16; i > 0; i--) { - DPFHS; - } - - for (i=0; i < len; i++, p++, offset++) { - if (!(offset % 16)) { - DPFHN(offset); - } else if (!(offset % 8)) { - DPFHMS; - } - DPFHD(*p); - } - DPFHE; -} - -static int -get_hdr(void) -{ - if (!hdrs.hdr_valid) { - if (map_len < sizeof(struct fs_state_header)) { - fprintf(stderr, "corrupt state dump: fs_state_header larger than memory map\n"); - return 1; - } - memcpy(&hdrs.hdr, map, sizeof(hdrs.hdr)); - hdrs.hdr_p = map; - hdrs.hdr_valid = 1; - } - return 0; -} - -static int -get_h_hdr(void) -{ - char * buf; - afs_uint32 hi, lo; - - if (hdrs.h_hdr_valid) - return 0; - - if (get_hdr()) - return 1; - - SplitInt64(hdrs.hdr.h_offset, hi, lo); - - if (hi) { - fprintf(stderr, "hi offset bits set in h_offset; can't get host_state_header\n"); - return 1; - } - if ((lo >= map_len) || - ((lo + sizeof(struct host_state_header)) > map_len) || - (lo + sizeof(struct host_state_header) < lo)) { - fprintf(stderr, "h_offset puts host_state_header beyond end of memory map\n"); - return 1; - } - - buf = (char *) map; - buf += lo; - memcpy(&hdrs.h_hdr, buf, sizeof(struct host_state_header)); - hdrs.h_hdr_p = buf; - buf += sizeof(struct host_state_header); - he_cursor.fh = (void *)buf; - return 0; -} - -static int -get_cb_hdr(void) -{ - char * buf; - afs_uint32 hi, lo; - - if (hdrs.cb_hdr_valid) - return 0; - - if (get_hdr()) - return 1; - - SplitInt64(hdrs.hdr.cb_offset, hi, lo); - - if (hi) { - fprintf(stderr, "hi offset bits set in cb_offset; can't get callback_state_header\n"); - return 1; - } - if ((lo >= map_len) || - ((lo + sizeof(struct callback_state_header)) > map_len) || - (lo + sizeof(struct callback_state_header) < lo)) { - fprintf(stderr, "cb_offset puts callback_state_header beyond end of memory map\n"); - return 1; - } - - buf = (char *) map; - buf += lo; - memcpy(&hdrs.cb_hdr, buf, sizeof(struct callback_state_header)); - hdrs.cb_hdr_p = buf; - hdrs.cb_hdr_valid = 1; - - SplitInt64(hdrs.cb_hdr.fe_offset, hi, lo); - - if (hi) { - fprintf(stderr, "hi offset bits set in fe_offset; can't get callback_state_entry_header\n"); - return 1; - } - hi = lo + (hdrs.cb_hdr.nFEs * (sizeof(struct callback_state_entry_header) + - sizeof(struct FEDiskEntry)) + - hdrs.cb_hdr.nCBs * sizeof(struct CBDiskEntry)); - if ((hi > map_len) || - (lo > hi)) { - fprintf(stderr, "fe_offset puts callback_state_entry_header beyond end of memory map\n"); - return 1; - } - - buf = (char *) map; - buf += lo; - fe_cursor.ffe = (void *)buf; - - return 0; -} - -static int -get_cb_timeout_hdr(void) -{ - char * buf; - afs_uint32 hi, lo; - - if (hdrs.timeout_hdr_valid) - return 0; - - if (get_cb_hdr()) - return 1; - - SplitInt64(hdrs.cb_hdr.timeout_offset, hi, lo); - - if (hi) { - fprintf(stderr, "hi offset bits set in timeout_offset; can't get callback_state_timeout_header\n"); - return 1; - } - if ((lo >= map_len) || - ((lo + sizeof(struct callback_state_timeout_header)) > map_len) || - (lo + sizeof(struct callback_state_timeout_header) < lo)) { - fprintf(stderr, "timeout_offset puts callback_state_timeout_header beyond end of memory map\n"); - return 1; - } - - buf = (char *) map; - buf += lo; - memcpy(&hdrs.timeout_hdr, buf, sizeof(struct callback_state_timeout_header)); - hdrs.timeout_hdr_p = buf; - hdrs.timeout_hdr_valid = 1; - buf += sizeof(struct callback_state_timeout_header); - hdrs.timeout_p = buf; - - return 0; -} - -static int -get_cb_timeout(void) -{ - if (hdrs.timeout) - return 0; - - if (get_cb_timeout_hdr()) - return 1; - - hdrs.timeout = (afs_uint32 *) calloc(hdrs.timeout_hdr.records, sizeof(afs_uint32)); - assert(hdrs.timeout != NULL); - memcpy(hdrs.timeout, hdrs.timeout_p, hdrs.timeout_hdr.records * sizeof(afs_uint32)); - return 0; -} - -static int -get_cb_fehash_hdr(void) -{ - char * buf; - afs_uint32 hi, lo; - - if (hdrs.fehash_hdr_valid) - return 0; - - if (get_cb_hdr()) - return 1; - - SplitInt64(hdrs.cb_hdr.fehash_offset, hi, lo); - - if (hi) { - fprintf(stderr, "hi offset bits set in fehash_offset; can't get callback_state_fehash_header\n"); - return 1; - } - if ((lo >= map_len) || - ((lo + sizeof(struct callback_state_fehash_header)) > map_len) || - (lo + sizeof(struct callback_state_fehash_header) < lo)) { - fprintf(stderr, "timeout_offset puts callback_state_fehash_header beyond end of memory map\n"); - return 1; - } - - buf = (char *) map; - buf += lo; - memcpy(&hdrs.fehash_hdr, buf, sizeof(struct callback_state_fehash_header)); - hdrs.fehash_hdr_p = buf; - hdrs.fehash_hdr_valid = 1; - buf += sizeof(struct callback_state_fehash_header); - hdrs.fehash_p = buf; - - return 0; -} - -static int -get_cb_fehash(void) -{ - if (hdrs.fehash) - return 0; - - if (get_cb_fehash_hdr()) - return 1; - - hdrs.fehash = (afs_uint32 *) calloc(hdrs.fehash_hdr.records, sizeof(afs_uint32)); - assert(hdrs.fehash != NULL); - memcpy(hdrs.fehash, hdrs.fehash_p, hdrs.fehash_hdr.records * sizeof(afs_uint32)); - return 0; -} - -static int -get_he(afs_uint32 idx) -{ - int i; - char * p; - - if (get_h_hdr()) - return 1; - - if (idx >= hdrs.h_hdr.records) - return 1; - - if (he_cursor.idx == idx && he_cursor.hdr_valid && he_cursor.he_valid) - return 0; - - he_cursor.hdr_valid = he_cursor.he_valid = 0; - - if (he_cache.cursor == NULL) { - he_cache.cursor = (void **) calloc(hdrs.h_hdr.records, sizeof(void *)); - assert(he_cache.cursor != NULL); - } - - if (idx && he_cache.cursor[idx-1] == NULL) { - for (i = 0; i < idx; i++) { - if (he_cache.cursor[i] == NULL) { - get_he(i); - } - } - } - - if (!idx) { - he_cursor.cursor = he_cursor.fh; - } else if (he_cursor.cursor == he_cache.cursor[idx-1]) { - p = (char *)he_cursor.cursor; - p += he_cursor.hdr.len; - he_cursor.cursor = (void *)p; - } else { - he_cursor.cursor = he_cache.cursor[idx-1]; - if (get_he_hdr()) - return 1; - p = (char *)he_cursor.cursor; - p += he_cursor.hdr.len; - he_cursor.cursor = (void *)p; - } - - he_cursor.idx = idx; - he_cache.cursor[idx] = he_cursor.cursor; - - if (get_he_hdr()) - return 1; - if (get_he_entry()) - return 1; - - return 0; -} - -static int -get_he_hdr(void) -{ - memcpy(&he_cursor.hdr, he_cursor.cursor, sizeof(struct host_state_entry_header)); - he_cursor.hdr_valid = 1; - return 0; -} - -static int -get_he_entry(void) -{ - char * p; - - if (!he_cursor.hdr_valid) { - if (get_he_hdr()) { - return 1; - } - } - - p = (char *) he_cursor.cursor; - p += sizeof(struct host_state_entry_header); - - memcpy(&he_cursor.he, p, sizeof(struct hostDiskEntry)); - - he_cursor.he_valid = 1; - p += sizeof(struct hostDiskEntry); - he_cursor.ifp = (void *)p; - if (he_cursor.hdr.interfaces) { - p += sizeof(struct Interface) + ((he_cursor.hdr.interfaces-1)*sizeof(struct AddrPort)); - he_cursor.hcps = (void *)p; - } else { - he_cursor.hcps = he_cursor.ifp; - } - return 0; -} - -static int -get_fe(afs_uint32 idx) -{ - int i; - char * p; - - cb_cursor.cb_valid = 0; - - if (get_cb_hdr()) - return 1; - - if (idx >= hdrs.cb_hdr.nFEs) - return 1; - - if (fe_cursor.idx == idx && fe_cursor.hdr_valid && fe_cursor.fe_valid) - return 0; - - fe_cursor.hdr_valid = fe_cursor.fe_valid = 0; - - if (fe_cache.cursor == NULL) { - fe_cache.cursor = (void **) calloc(hdrs.cb_hdr.nFEs, sizeof(void *)); - assert(fe_cache.cursor != NULL); - } - - if (idx && fe_cache.cursor[idx-1] == NULL) { - for (i = 0; i < idx; i++) { - if (fe_cache.cursor[i] == NULL) { - get_fe(i); - } - } - } - - if (!idx) { - fe_cursor.cursor = fe_cursor.ffe; - } else if (fe_cursor.cursor == fe_cache.cursor[idx-1]) { - p = (char *)fe_cursor.cursor; - p += fe_cursor.hdr.len; - fe_cursor.cursor = (void *)p; - } else { - fe_cursor.cursor = fe_cache.cursor[idx-1]; - if (get_fe_hdr()) - return 1; - p = (char *)fe_cursor.cursor; - p += fe_cursor.hdr.len; - fe_cursor.cursor = (void *)p; - } - - fe_cursor.idx = idx; - fe_cache.cursor[idx] = fe_cursor.cursor; - - if (get_fe_hdr()) - return 1; - if (get_fe_entry()) - return 1; - - return 0; -} - -static int -get_fe_hdr(void) -{ - if (!fe_cursor.cursor) { - if(get_fe(fe_cursor.idx)) { - return 1; - } - } - - memcpy(&fe_cursor.hdr, fe_cursor.cursor, sizeof(struct callback_state_entry_header)); - fe_cursor.hdr_valid = 1; - return 0; -} - -static int -get_fe_entry(void) -{ - char * p; - - if (!fe_cursor.hdr_valid) { - if (get_fe_hdr()) { - return 1; - } - } - - p = (char *) fe_cursor.cursor; - p += sizeof(struct callback_state_entry_header); - - memcpy(&fe_cursor.fe, p, sizeof(struct FEDiskEntry)); - - fe_cursor.fe_valid = 1; - p += sizeof(struct FEDiskEntry); - fe_cursor.fcb = (void *)p; - return 0; -} - -static int -get_cb(afs_uint32 idx) -{ - char * p; - - if (get_fe(fe_cursor.idx)) - return 1; - - if (idx >= fe_cursor.hdr.nCBs) - return 1; - - if (idx == cb_cursor.idx && cb_cursor.cb_valid) - return 0; - - cb_cursor.cb_valid = 0; - - p = (char *)fe_cursor.fcb; - p += idx * sizeof(struct CBDiskEntry); - cb_cursor.cursor = (void *)p; - - cb_cursor.idx = idx; - - if (get_cb_entry()) - return 1; - - return 0; -} - -static int -get_cb_entry(void) -{ - memcpy(&cb_cursor.cb, cb_cursor.cursor, sizeof(struct CBDiskEntry)); - cb_cursor.cb_valid = 1; - return 0; -} - -#if 0 -static int -find_he_by_index(afs_uint32 idx) -{ - int i; - - if (get_h_hdr()) { - return 1; - } - - for (i = 0; i < hdrs.h_hdr.records; i++) { - if (get_he(i)) { - fprintf(stderr, "error getting he %d\n", i); - return 1; - } - if (he_cursor.he.index == idx) - break; - } - - if (i < hdrs.h_hdr.records) { - dump_this_he(); - return 0; - } - return 1; -} -#endif - -static int -find_fe_by_index(afs_uint32 idx) -{ - int i; - - if (get_cb_hdr()) { - return 1; - } - - for (i = 0; i < hdrs.cb_hdr.nFEs; i++) { - if (get_fe(i)) { - fprintf(stderr, "error getting fe %d\n", i); - return 1; - } - if (fe_cursor.fe.index == idx) - break; - } - - if (i < hdrs.cb_hdr.nFEs) { - dump_this_fe(); - return 0; - } - return 1; -} - -static int -find_fe_by_fid(afs_uint32 volid, afs_uint32 vnode, afs_uint32 unique) -{ - int i; - - if (get_cb_hdr()) { - return 1; - } - - for (i = 0; i < hdrs.cb_hdr.nFEs; i++) { - if (get_fe(i)) { - fprintf(stderr, "error getting fe %d\n", i); - return 1; - } - if ((fe_cursor.fe.fe.unique == unique) && - (fe_cursor.fe.fe.volid == volid) && - (fe_cursor.fe.fe.vnode == vnode)) - break; - } - - if (i < hdrs.cb_hdr.nFEs) { - dump_this_fe(); - return 0; - } - return 1; -} - -static int -find_cb_by_index(afs_uint32 idx) -{ - int i; - - if (get_fe_hdr()) { - return 1; - } - - for (i = 0; i < fe_cursor.hdr.nCBs; i++) { - if (get_cb(i)) { - fprintf(stderr, "error getting cb %d\n", i); - return 1; - } - if (cb_cursor.cb.index == idx) - break; - } - - if (i < fe_cursor.hdr.nCBs) { - dump_this_cb(); - return 0; - } - return 1; -} - -#endif /* AFS_DEMAND_ATTACH_FS */ diff --git a/src/viced/Makefile.in b/src/viced/Makefile.in index 84bf59d59..cbaf1694c 100644 --- a/src/viced/Makefile.in +++ b/src/viced/Makefile.in @@ -9,77 +9,59 @@ srcdir=@srcdir@ include @TOP_OBJDIR@/src/config/Makefile.config -include @TOP_OBJDIR@/src/config/Makefile.lwp -HELPER_SPLINT=@HELPER_SPLINT@ - -LIBS=${TOP_LIBDIR}/libacl.a \ - ${TOP_LIBDIR}/libvldb.a \ - ${TOP_LIBDIR}/libprot.a \ - ${TOP_LIBDIR}/libauth.a \ - ${TOP_LIBDIR}/librxkad.a \ - ${TOP_LIBDIR}/libubik.a \ - ${TOP_LIBDIR}/vlib.a \ - ${TOP_LIBDIR}/libdir.a \ - ${TOP_LIBDIR}/util.a \ - ${TOP_LIBDIR}/libsys.a \ - ${TOP_LIBDIR}/libafsint.a \ - ${TOP_LIBDIR}/librxstat.a \ - ${TOP_LIBDIR}/librx.a \ - ${TOP_LIBDIR}/libsys.a \ - ${TOP_LIBDIR}/libafscom_err.a \ - ${TOP_LIBDIR}/libcmd.a \ - ${TOP_LIBDIR}/liblwp.a \ - ${TOP_LIBDIR}/libafsutil.a \ - $(TOP_LIBDIR)/libopr.a \ - ${TOP_LIBDIR}/libafshcrypto_lwp.a - -headers=${TOP_INCDIR}/lwp.h \ - ${TOP_INCDIR}/afs/acl.h \ - ${TOP_INCDIR}/afs/errors.h \ - ${TOP_INCDIR}/afs/ptclient.h \ - ${TOP_INCDIR}/lock.h \ - ${TOP_INCDIR}/afs/volume.h \ - ${TOP_INCDIR}/afs/vnode.h \ - ${TOP_INCDIR}/rx/rx.h \ - ${TOP_INCDIR}/rx/xdr.h \ - ${TOP_INCDIR}/afs/auth.h \ - ${TOP_INCDIR}/afs/afsint.h \ - viced.h \ - host.h \ - callback.h \ - fs_stats.h - -objects=viced.o \ - afsfileprocs.o \ - host.o \ - physio.o \ - callback.o \ - fsstats.o +include @TOP_OBJDIR@/src/config/Makefile.pthread + + +MODULE_CFLAGS = -DRXDEBUG -DFSSYNC_BUILD_SERVER -DSALVSYNC_BUILD_CLIENT + +RX=$(srcdir)/../rx +VLSERVER=$(srcdir)/../vlserver +LWP=$(srcdir)/../lwp +LIBACL=$(srcdir)/../libacl +UTIL=$(srcdir)/../util +DIR=$(srcdir)/../dir +VOL=$(srcdir)/../vol +FSINT=$(srcdir)/../fsint + +VICEDOBJS=viced.o afsfileprocs.o host.o physio.o callback.o serialize_state.o \ + fsstats.o + +VLSERVEROBJS=vldbint.cs.o vldbint.xdr.o + +LWPOBJS=lock.o threadname.o + +LIBACLOBJS=aclprocs.o netprocs.o + +UTILOBJS=uuid.o serverLog.o fileutil.o netutils.o dirpath.o volparse.o flipbase64.o softsig.o pthread_threadname.o + +DIROBJS=buffer.o dir.o salvage.o + +VOLOBJS= vnode.o volume.o vutil.o partition.o fssync-server.o \ + clone.o devname.o common.o ihandle.o listinodes.o namei_ops.o \ + fstab.o salvsync-client.o daemon_com.o vg_cache.o vg_scan.o + +FSINTOBJS= afsaux.o afscbint.cs.o afsint.ss.o afsint.xdr.o + +RXOBJS = rx_pthread.o + +objects= ${VICEDOBJS} ${VLSERVEROBJS} ${LWPOBJS} ${LIBACLOBJS} \ + ${UTILOBJS} ${DIROBJS} ${VOLOBJS} ${FSINTOBJS} ${RXOBJS} + +LIBS=${TOP_LIBDIR}/libafsauthent.a \ + ${TOP_LIBDIR}/libafsrpc.a \ + $(TOP_LIBDIR)/libcmd.a \ + $(TOP_LIBDIR)/libopr.a \ + ${TOP_LIBDIR}/util.a all: cbd fsprobe check_sysid fileserver ${TOP_INCDIR}/afs/fs_stats.h ${TOP_INCDIR}/afs/fs_stats.h: fs_stats.h ${INSTALL_DATA} $? $@ -${objects}: ${headers} - -viced.o: AFS_component_version_number.o - check_sysid: check_sysid.c ${CC} ${AFS_CFLAGS} ${AFS_LDFLAGS} -o check_sysid \ ${srcdir}/check_sysid.c -fileserver: ${objects} ${headers} ${LIBS} - $(Q)set -x; \ - case ${SYS_NAME} in \ - rs_aix*) \ - ${CC} -K ${AFS_LDFLAGS} -o fileserver ${objects} \ - ${TOP_LIBDIR}/libaudit.a ${LIBS} $(LIB_roken) ${XLIBS} ;; \ - *) \ - $(AFS_LDRULE_NOQ) ${objects} ${TOP_LIBDIR}/libaudit.a \ - ${LIBS} $(LIB_roken) ${XLIBS} ;; \ - esac - fsprobe.o: fsprobe.c AFS_component_version_number.c fsprobe: fsprobe.o @@ -92,49 +74,156 @@ cbd.o: callback.c AFS_component_version_number.c cbd: cbd.o $(AFS_LDRULE) cbd.o ${LIBS} $(LIB_roken) ${XLIBS} -install: fileserver fs_stats.h +CFLAGS_rx_pthread.o = -DDPF_FSLOG +rx_pthread.o: ${RX}/rx_pthread.c + $(AFS_CCRULE) $(RX)/rx_pthread.c + +uuid.o: ${UTIL}/uuid.c + $(AFS_CCRULE) $(UTIL)/uuid.c + +serverLog.o: ${UTIL}/serverLog.c + $(AFS_CCRULE) $(UTIL)/serverLog.c + +fileutil.o: ${UTIL}/fileutil.c + $(AFS_CCRULE) $(UTIL)/fileutil.c + +volparse.o: ${UTIL}/volparse.c + $(AFS_CCRULE) $(UTIL)/volparse.c + +flipbase64.o: ${UTIL}/flipbase64.c + $(AFS_CCRULE) $(UTIL)/flipbase64.c + +netutils.o: ${UTIL}/netutils.c + $(AFS_CCRULE) -I../util $(UTIL)/netutils.c + +dirpath.o: ${UTIL}/dirpath.c + $(AFS_CCRULE) $(UTIL)/dirpath.c + +softsig.o: ${UTIL}/softsig.c + $(AFS_CCRULE) $(UTIL)/softsig.c + +pthread_threadname.o: ${UTIL}/pthread_threadname.c + $(AFS_CCRULE) $(UTIL)/pthread_threadname.c + +lock.o: ${LWP}/lock.c + $(AFS_CCRULE) $(LWP)/lock.c + +threadname.o: ${LWP}/threadname.c + $(AFS_CCRULE) $(LWP)/threadname.c + +aclprocs.o: ${LIBACL}/aclprocs.c + $(AFS_CCRULE) $(LIBACL)/aclprocs.c + +netprocs.o: ${LIBACL}/netprocs.c + $(AFS_CCRULE) $(LIBACL)/netprocs.c + + +vldbint.cs.o: ../vlserver/vldbint.cs.c + $(AFS_CCRULE) -I$(VLSERVER) ../vlserver/vldbint.cs.c + +vldbint.xdr.o: ../vlserver/vldbint.xdr.c + $(AFS_CCRULE) -I$(VLSERVER) ../vlserver/vldbint.xdr.c + + +buffer.o: ${DIR}/buffer.c + $(AFS_CCRULE) $(DIR)/buffer.c + +dir.o: ${DIR}/dir.c + $(AFS_CCRULE) $(DIR)/dir.c + +salvage.o: ${DIR}/salvage.c + $(AFS_CCRULE) $(DIR)/salvage.c + +vnode.o: ${VOL}/vnode.c + $(AFS_CCRULE) $(VOL)/vnode.c + +volume.o: ${VOL}/volume.c + $(AFS_CCRULE) $(VOL)/volume.c + +vutil.o: ${VOL}/vutil.c + $(AFS_CCRULE) $(VOL)/vutil.c + +partition.o: ${VOL}/partition.c + $(AFS_CCRULE) $(VOL)/partition.c + +vg_cache.o: ${VOL}/vg_cache.c + $(AFS_CCRULE) $(VOL)/vg_cache.c + +vg_scan.o: ${VOL}/vg_scan.c + $(AFS_CCRULE) $(VOL)/vg_scan.c + +fssync-server.o: ${VOL}/fssync-server.c + $(AFS_CCRULE) $(VOL)/fssync-server.c + +fssync-client.o: ${VOL}/fssync-client.c + $(AFS_CCRULE) $(VOL)/fssync-client.c + +salvsync-client.o: ${VOL}/salvsync-client.c + $(AFS_CCRULE) $(VOL)/salvsync-client.c + +daemon_com.o: ${VOL}/daemon_com.c + $(AFS_CCRULE) $(VOL)/daemon_com.c + +clone.o: ${VOL}/clone.c + $(AFS_CCRULE) $(VOL)/clone.c + +nuke.o: ${VOL}/nuke.c + $(AFS_CCRULE) $(VOL)/nuke.c + +devname.o: ${VOL}/devname.c + $(AFS_CCRULE) $(VOL)/devname.c + +# only for darwin? +fstab.o: ${UTIL}/fstab.c + $(AFS_CCRULE) $(UTIL)/fstab.c + +common.o: ${VOL}/common.c + $(AFS_CCRULE) $(VOL)/common.c + +listinodes.o: ${VOL}/listinodes.c + $(AFS_CCRULE) $(VOL)/listinodes.c + +ihandle.o: ${VOL}/ihandle.c + $(AFS_CCRULE) $(VOL)/ihandle.c + +namei_ops.o: ${VOL}/namei_ops.c + $(AFS_CCRULE) $(VOL)/namei_ops.c + +afsaux.o: ${FSINT}/afsaux.c + $(AFS_CCRULE) -I../fsint $(FSINT)/afsaux.c + +afscbint.cs.o: ../fsint/afscbint.cs.c + $(AFS_CCRULE) ../fsint/afscbint.cs.c + +afscbint.ss.o: ../fsint/afscbint.ss.c + $(AFS_CCRULE) ../fsint/afscbint.ss.c + +afsint.cs.o: ../fsint/afsint.cs.c + $(AFS_CCRULE) ../fsint/afsint.cs.c + +afsint.ss.o: ../fsint/afsint.ss.c + $(AFS_CCRULE) ../fsint/afsint.ss.c + +afsint.xdr.o: ../fsint/afsint.xdr.c + $(AFS_CCRULE) ../fsint/afsint.xdr.c + +fileserver: ${objects} ${LIBS} + $(AFS_LDRULE) ${objects} \ + ${LIBS} $(LIB_hcrypto) $(LIB_roken) ${MT_LIBS} ${XLIBS} + +install: fileserver ${INSTALL} -d ${DESTDIR}${afssrvlibexecdir} - ${INSTALL} -d ${DESTDIR}${includedir}/afs - ${INSTALL_DATA} ${srcdir}/fs_stats.h ${DESTDIR}${includedir}/afs/fs_stats.h - @case ${SYS_NAME} in \ - alpha_dux4*|*linux*|rs_aix*|sgi_6*|sun4x*|sunx86*) \ - echo "Don't install fileserver for ${SYS_NAME}" ;; \ - *_darwin_[1-6][0-9]) \ - echo ${INSTALL} fileserver ${DESTDIR}${afssrvlibexecdir}/fileserver ; \ - ${INSTALL} fileserver ${DESTDIR}${afssrvlibexecdir}/fileserver ;; \ - *_darwin_*) \ - echo "Don't install fileserver for ${SYS_NAME}" ;; \ - *) \ - echo ${INSTALL} fileserver ${DESTDIR}${afssrvlibexecdir}/fileserver ; \ - ${INSTALL} fileserver ${DESTDIR}${afssrvlibexecdir}/fileserver ;; \ - esac - -dest: fileserver fs_stats.h + ${INSTALL} -d ${DESTDIR}${afssrvsbindir} + ${INSTALL} fileserver \ + ${DESTDIR}${afssrvlibexecdir}/fileserver + +dest: fileserver ${INSTALL} -d ${DEST}/root.server/usr/afs/bin - ${INSTALL} -d ${DEST}/include/afs - ${INSTALL_DATA} ${srcdir}/fs_stats.h ${DEST}/include/afs/fs_stats.h - @case ${SYS_NAME} in \ - alpha_dux4*|*linux*|rs_aix*|sgi_6*|sun4x*|sunx86*) \ - echo "Don't install fileserver for ${SYS_NAME}" ;; \ - *_darwin_[1-6][0-9]) \ - echo ${INSTALL} fileserver ${DEST}/root.server/usr/afs/bin/fileserver ; \ - ${INSTALL} fileserver ${DEST}/root.server/usr/afs/bin/fileserver ;; \ - *_darwin_*) \ - echo "Don't install fileserver for ${SYS_NAME}" ;; \ - *) \ - echo ${INSTALL} fileserver ${DEST}/root.server/usr/afs/bin/fileserver ; \ - ${INSTALL} fileserver ${DEST}/root.server/usr/afs/bin/fileserver ;; \ - esac + ${INSTALL} fileserver \ + ${DEST}/root.server/usr/afs/bin/fileserver clean: - $(RM) -f *.o fileserver core AFS_component_version_number.c cbd check_sysid fsprobe + $(RM) -f *.o fileserver core AFS_component_version_number.c \ + cbd check_sysid fsprobe include ../config/Makefile.version -check-splint:: - sh $(HELPER_SPLINT) $(CFLAGS) \ - viced.c \ - afsfileprocs.c \ - host.c \ - physio.c \ - callback.c - diff --git a/src/viced/NTMakefile b/src/viced/NTMakefile index 1da16aae2..a5981e8bb 100644 --- a/src/viced/NTMakefile +++ b/src/viced/NTMakefile @@ -5,7 +5,7 @@ # License. For details, see the LICENSE file in the top-level source # directory or online at http://www.openafs.org/dl/license10.html -AFSDEV_AUXCDEFINES = -DFSSYNC_BUILD_SERVER +AFSDEV_AUXCDEFINES = -DAFS_PTHREAD_ENV -DRXDEBUG -DFSSYNC_BUILD_SERVER RELDIR=viced !INCLUDE ..\config\NTMakefile.$(SYS_NAME) @@ -16,55 +16,75 @@ RELDIR=viced INCFILEDIR = $(DESTDIR)\include\afs -INCFILES =\ - $(INCFILEDIR)\fs_stats.h - +INCFILES = $(INCFILEDIR)\fs_stats.h ############################################################################ # Build the fileserver -# This is now done in tviced EXEFILE = $(DESTDIR)\root.server\usr\afs\bin\fileserver.exe -EXERES = $(OUT)\fileserver.res +EXERES= $(OUT)\fileserver.res + +LWP = ..\lwp +LIBACL = ..\libacl +FSINT = ..\fsint +RX = ..\rx + +RXOBJS = $(OUT)\xdr_int64.obj \ + $(OUT)\xdr_int32.obj + +VICEDOBJS = $(OUT)\viced.obj $(OUT)\afsfileprocs.obj $(OUT)\fsstats.obj $(OUT)\host.obj $(OUT)\physio.obj $(OUT)\callback.obj + + +LWPOBJS = $(OUT)\lock.obj $(OUT)\fasttime.obj $(OUT)\threadname.obj + +LIBACLOBJS = $(OUT)\aclprocs.obj $(OUT)\netprocs.obj + +FSINTOBJS = $(OUT)\afsaux.obj $(OUT)\afscbint.cs.obj $(OUT)\afsint.ss.obj $(OUT)\afsint.xdr.obj + +EXEOBJS = $(EXERES) $(VICEDOBJS) $(LWPOBJS) $(LIBACLOBJS) \ + $(FSINTOBJS) $(RXOBJS) + +noversion: install + +all: fileserver -EXEOBJS =\ - $(OUT)\afsfileprocs.obj \ - $(OUT)\callback.obj \ - $(OUT)\fsstats.obj \ - $(OUT)\host.obj \ - $(OUT)\physio.obj \ - $(OUT)\viced.obj \ - $(OUT)\AFS_component_version_number.obj +$(EXERES): fileserver.rc AFS_component_version_number.h + +$(RXOBJS): $(RX)\$$(@B).c + $(C2OBJ) -I$(RX) $** + +$(VICEDOBJS): $$(@B).c + $(C2OBJ) $** + +$(LWPOBJS): $(LWP)\$$(@B).C + $(C2OBJ) -I$(LWP) $** + +$(LIBACLOBJS): $(LIBACL)\$$(@B).C + $(C2OBJ) -I$(LIBACL) $** + +$(FSINTOBJS): $(FSINT)\$$(@B).C + $(C2OBJ) -I$(FSINT) $** EXELIBS = \ + $(DESTDIR)\lib\afsauthent.lib \ + $(DESTDIR)\lib\afsrpc.lib \ $(DESTDIR)\lib\afs\afscmd.lib \ - $(DESTDIR)\lib\afs\afsvol.lib \ - $(DESTDIR)\lib\afs\afsutil.lib \ - $(DESTDIR)\lib\afs\afsdir.lib \ - $(DESTDIR)\lib\afs\afsvol.lib \ $(DESTDIR)\lib\afs\afsaudit.lib \ - $(DESTDIR)\lib\afs\afsauth.lib \ - $(DESTDIR)\lib\afs\afsvldb.lib \ - $(DESTDIR)\lib\afs\afsprot.lib \ - $(DESTDIR)\lib\afs\afskauth.lib \ $(DESTDIR)\lib/afs/afscom_err.lib \ - $(DESTDIR)\lib\afsubik.lib \ - $(DESTDIR)\lib\afsrxkad.lib \ - $(DESTDIR)\lib\afs\afsint.lib \ - $(DESTDIR)\lib\afsrx.lib \ - $(DESTDIR)\lib\afslwp.lib \ - $(DESTDIR)\lib\afs\afsacl.lib \ $(DESTDIR)\lib\afs\afsreg.lib \ $(DESTDIR)\lib\afs\afsprocmgmt.lib \ $(DESTDIR)\lib\afs\afseventlog.lib \ - $(DESTDIR)\lib\afs\afspioctl.lib \ + $(DESTDIR)\lib\afs\mtafsutil.lib \ + $(DESTDIR)\lib\afs\mtafsvol.lib \ + $(DESTDIR)\lib\afs\mtafsvldb.lib \ + $(DESTDIR)\lib\afs\mtafsdir.lib \ $(DESTDIR)\lib\opr.lib \ - $(DESTDIR)\lib\afshcrypto.lib \ + $(DESTDIR)\lib\afspthread.lib \ $(DESTDIR)\lib\afsroken.lib -$(EXEFILE): $(EXEOBJS) $(EXERES) $(EXELIBS) +$(EXEFILE): $(EXEOBJS) $(EXELIBS) $(EXECONLINK) $(_VC_MANIFEST_EMBED_EXE) $(EXEPREP) @@ -82,21 +102,19 @@ $(OUT)\cbd.obj: callback.c AFS_component_version_number.h $(CBD): $(OUT)\cbd.obj $(CBDRES) $(EXECONLINK) - $(_VC_MANIFEST_EMBED_EXE) - $(CODESIGN_USERLAND) - $(SYMSTORE_IMPORT) + $(_VC_MANIFEST_EMBED_EXE) + $(CODESIGN_USERLAND) + $(SYMSTORE_IMPORT) ############################################################################ # generate versioninfo resources -$(EXERES): fileserver.rc AFS_component_version_number.h $(CBDRES): cbd.rc AFS_component_version_number.h -install: $(INCFILES) $(CBD) +install: $(INCFILES) $(CBD) $(EXEFILE) mkdir: clean:: $(DEL) $(EXERES) $(DEL) $(CBDRES) - diff --git a/src/viced/afsfileprocs.c b/src/viced/afsfileprocs.c index 4432ae6b9..582d50895 100644 --- a/src/viced/afsfileprocs.c +++ b/src/viced/afsfileprocs.c @@ -107,9 +107,7 @@ extern void SetDirHandle(DirHandle * dir, Vnode * vnode); extern void FidZap(DirHandle * file); extern void FidZero(DirHandle * file); -#ifdef AFS_PTHREAD_ENV pthread_mutex_t fileproc_glock_mutex; -#endif /* AFS_PTHREAD_ENV */ /* Useful local defines used by this module */ @@ -334,9 +332,7 @@ CallPreamble(struct rx_call *acall, int activecall, int retry_flag = 1; int code = 0; char hoststr[16], hoststr2[16]; -#ifdef AFS_PTHREAD_ENV struct ubik_client *uclient; -#endif *ahostp = NULL; if (!tconn) { @@ -367,7 +363,6 @@ CallPreamble(struct rx_call *acall, int activecall, /* Take down the old connection and re-read the key file */ ViceLog(0, ("CallPreamble: Couldn't get CPS. Reconnect to ptserver\n")); -#ifdef AFS_PTHREAD_ENV uclient = (struct ubik_client *)pthread_getspecific(viced_uclient_key); /* Is it still necessary to drop this? We hit the net, we should... */ @@ -381,9 +376,7 @@ CallPreamble(struct rx_call *acall, int activecall, if (!code) osi_Assert(pthread_setspecific(viced_uclient_key, (void *)uclient) == 0); H_LOCK; -#else - code = pr_Initialize(2, AFSDIR_SERVER_ETC_DIRPATH, 0); -#endif + if (code) { h_ReleaseClient_r(tclient); h_Release_r(thost); @@ -523,12 +516,8 @@ CheckVnodeWithCall(AFSFid * fid, Volume ** volptr, struct VCallByVol *cbv, VRESTARTING #endif ; -#ifdef AFS_PTHREAD_ENV static const struct timespec timeout_ts = { 0, 0 }; static const struct timespec * const ts = &timeout_ts; -#else - static const struct timespec * const ts = NULL; -#endif errorCode = 0; *volptr = VGetVolumeWithCall(&local_errorCode, &errorCode, @@ -732,9 +721,6 @@ GetRights(struct client *client, struct acl_accessList *ACL, { extern prlist SystemAnyUserCPS; afs_int32 hrights = 0; -#ifndef AFS_PTHREAD_ENV - int code; -#endif if (acl_CheckRights(ACL, &SystemAnyUserCPS, anyrights) != 0) { ViceLog(0, ("CheckRights failed\n")); @@ -748,13 +734,7 @@ GetRights(struct client *client, struct acl_accessList *ACL, H_LOCK; while (client->host->hostFlags & HCPS_INPROGRESS) { client->host->hostFlags |= HCPS_WAITING; /* I am waiting */ -#ifdef AFS_PTHREAD_ENV CV_WAIT(&client->host->cond, &host_glock_mutex); -#else /* AFS_PTHREAD_ENV */ - if ((code = - LWP_WaitProcess(&(client->host->hostFlags))) != LWP_SUCCESS) - ViceLog(0, ("LWP_WaitProcess returned %d\n", code)); -#endif /* AFS_PTHREAD_ENV */ } if (!client->host->hcps.prlist_len || !client->host->hcps.prlist_val) { @@ -1380,9 +1360,6 @@ CopyOnWrite(Vnode * targetptr, Volume * volptr, afs_foff_t off, afs_fsize_t len) return EIO; } } -#ifndef AFS_PTHREAD_ENV - IOMGR_Poll(); -#endif /* !AFS_PTHREAD_ENV */ } FDH_REALLYCLOSE(targFdP); rc = IH_DEC(V_linkHandle(volptr), VN_GET_INO(targetptr), diff --git a/src/viced/callback.c b/src/viced/callback.c index 3533906c2..07f52f6eb 100644 --- a/src/viced/callback.c +++ b/src/viced/callback.c @@ -107,7 +107,7 @@ #include "host.h" #include "callback.h" #ifdef AFS_DEMAND_ATTACH_FS -#include "../tviced/serialize_state.h" +#include "serialize_state.h" #endif /* AFS_DEMAND_ATTACH_FS */ @@ -1187,11 +1187,7 @@ MultiBreakVolumeLaterCallBack(struct host *host, void *rock) * Now uses multi-RX for CallBack RPC in a different thread, * only marking them here. */ -#ifdef AFS_PTHREAD_ENV extern pthread_cond_t fsync_cond; -#else -extern char fsync_wait[]; -#endif int BreakVolumeCallBacksLater(afs_uint32 volume) @@ -1230,13 +1226,9 @@ BreakVolumeCallBacksLater(afs_uint32 volume) } ViceLog(25, ("Fsync thread wakeup\n")); -#ifdef AFS_PTHREAD_ENV FSYNC_LOCK; CV_BROADCAST(&fsync_cond); FSYNC_UNLOCK; -#else - LWP_NoYieldSignal(fsync_wait); -#endif return 0; } diff --git a/src/viced/fileserver.rc b/src/viced/fileserver.rc index 1fbc5cdda..84bd52857 100644 --- a/src/viced/fileserver.rc +++ b/src/viced/fileserver.rc @@ -9,7 +9,7 @@ /* Define VERSIONINFO resource */ -#define AFS_VERINFO_FILE_DESCRIPTION "AFS File Server" +#define AFS_VERINFO_FILE_DESCRIPTION "AFS File Server (Threaded)" #define AFS_VERINFO_NAME "fileserver" #define AFS_VERINFO_FILENAME "fileserver.exe" diff --git a/src/viced/host.c b/src/viced/host.c index c1b8da9a6..4922c8332 100644 --- a/src/viced/host.c +++ b/src/viced/host.c @@ -50,12 +50,10 @@ #include "callback.h" #ifdef AFS_DEMAND_ATTACH_FS #include "../util/afsutil_prototypes.h" -#include "../tviced/serialize_state.h" +#include "serialize_state.h" #endif /* AFS_DEMAND_ATTACH_FS */ -#ifdef AFS_PTHREAD_ENV pthread_mutex_t host_glock_mutex; -#endif /* AFS_PTHREAD_ENV */ extern int Console; extern int CurrentConnections; @@ -208,10 +206,8 @@ GetHTBlock(void) ViceLog(0, ("Failed malloc in GetHTBlock\n")); ShutDownAndCore(PANIC); } -#ifdef AFS_PTHREAD_ENV for (i = 0; i < (h_HTSPERBLOCK); i++) CV_INIT(&block->entry[i].cond, "block entry", CV_DEFAULT, 0); -#endif /* AFS_PTHREAD_ENV */ for (i = 0; i < (h_HTSPERBLOCK); i++) Lock_Init(&block->entry[i].lock); for (i = 0; i < (h_HTSPERBLOCK - 1); i++) @@ -340,7 +336,6 @@ hpr_End(struct ubik_client *uclient) int hpr_GetHostCPS(afs_int32 host, prlist *CPS) { -#ifdef AFS_PTHREAD_ENV afs_int32 code; afs_int32 over; struct ubik_client *uclient = @@ -366,15 +361,11 @@ hpr_GetHostCPS(afs_int32 host, prlist *CPS) host); } return 0; -#else - return pr_GetHostCPS(host, CPS); -#endif } int hpr_NameToId(namelist *names, idlist *ids) { -#ifdef AFS_PTHREAD_ENV afs_int32 code; afs_int32 i; struct ubik_client *uclient = @@ -392,15 +383,11 @@ hpr_NameToId(namelist *names, idlist *ids) stolower(names->namelist_val[i]); code = ubik_PR_NameToID(uclient, 0, names, ids); return code; -#else - return pr_NameToId(names, ids); -#endif } int hpr_IdToName(idlist *ids, namelist *names) { -#ifdef AFS_PTHREAD_ENV afs_int32 code; struct ubik_client *uclient = (struct ubik_client *)pthread_getspecific(viced_uclient_key); @@ -415,15 +402,11 @@ hpr_IdToName(idlist *ids, namelist *names) code = ubik_PR_IDToName(uclient, 0, ids, names); return code; -#else - return pr_IdToName(ids, names); -#endif } int hpr_GetCPS(afs_int32 id, prlist *CPS) { -#ifdef AFS_PTHREAD_ENV afs_int32 code; afs_int32 over; struct ubik_client *uclient = @@ -448,9 +431,6 @@ hpr_GetCPS(afs_int32 id, prlist *CPS) id); } return 0; -#else - return pr_GetCPS(id, CPS); -#endif } static short consolePort = 0; @@ -580,12 +560,7 @@ h_gethostcps_r(struct host *host, afs_int32 now) while (host->hostFlags & HCPS_INPROGRESS) { slept = 1; /* I did sleep */ host->hostFlags |= HCPS_WAITING; /* I am sleeping now */ -#ifdef AFS_PTHREAD_ENV CV_WAIT(&host->cond, &host_glock_mutex); -#else /* AFS_PTHREAD_ENV */ - if ((code = LWP_WaitProcess(&(host->hostFlags))) != LWP_SUCCESS) - ViceLog(0, ("LWP_WaitProcess returned %d\n", code)); -#endif /* AFS_PTHREAD_ENV */ } @@ -641,12 +616,7 @@ h_gethostcps_r(struct host *host, afs_int32 now) /* signal all who are waiting */ if (host->hostFlags & HCPS_WAITING) { /* somebody is waiting */ host->hostFlags &= ~HCPS_WAITING; -#ifdef AFS_PTHREAD_ENV CV_BROADCAST(&host->cond); -#else /* AFS_PTHREAD_ENV */ - if ((code = LWP_NoYieldSignal(&(host->hostFlags))) != LWP_SUCCESS) - ViceLog(0, ("LWP_NoYieldSignal returns %d\n", code)); -#endif /* AFS_PTHREAD_ENV */ } } diff --git a/src/viced/host.h b/src/viced/host.h index e6c63cdef..e056074ad 100644 --- a/src/viced/host.h +++ b/src/viced/host.h @@ -14,7 +14,6 @@ #include "fs_stats.h" /*File Server stats package */ -#ifdef AFS_PTHREAD_ENV /* * There are three locks in the host package. * the global hash lock protects hash chains. @@ -28,10 +27,6 @@ extern pthread_mutex_t host_glock_mutex; #define H_LOCK MUTEX_ENTER(&host_glock_mutex); #define H_UNLOCK MUTEX_EXIT(&host_glock_mutex); extern pthread_key_t viced_uclient_key; -#else /* AFS_PTHREAD_ENV */ -#define H_LOCK -#define H_UNLOCK -#endif /* AFS_PTHREAD_ENV */ #define h_MAXHOSTTABLEENTRIES 1000 #define h_HASHENTRIES 256 /* Power of 2 */ @@ -87,9 +82,7 @@ struct host { afs_uint32 index; /* Host table index, for vicecb.c */ struct Lock lock; /* Write lock for synchronization of * VenusDown flag */ -#ifdef AFS_PTHREAD_ENV pthread_cond_t cond; /* used to wait on hcpsValid */ -#endif /* AFS_PTHREAD_ENV */ }; /* * Don't zero the index, lock or condition varialbles */ diff --git a/src/viced/serialize_state.c b/src/viced/serialize_state.c new file mode 100644 index 000000000..5c86e3f88 --- /dev/null +++ b/src/viced/serialize_state.c @@ -0,0 +1,1048 @@ +/* + * Copyright 2006, Sine Nomine Associates and others. + * All Rights Reserved. + * + * This software has been released under the terms of the IBM Public + * License. For details, see the LICENSE file in the top-level source + * directory or online at http://www.openafs.org/dl/license10.html + */ + +/* + * demand attach fs + * fileserver state serialization + */ + +#include +#include + +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../viced/viced_prototypes.h" +#include "../viced/viced.h" +#include "../viced/host.h" +#include "../viced/callback.h" +#include "serialize_state.h" + +#ifdef AFS_DEMAND_ATTACH_FS + +/* + * demand attach fs + * state dump routines + * + * in order to make state dump/restore as fast as possible, + * we use memory mapped files + * + * if this causes problems on certain platforms, the APIs + * have been written so that it will be very simple to go + * back to standard I/O for just those poorly written platforms + */ +#ifndef AFS_NT40_ENV +#define FS_STATE_USE_MMAP 1 +#endif + +#ifdef FS_STATE_USE_MMAP +#define FS_STATE_INIT_FILESIZE (8 * 1024 * 1024) /* truncate to 8MB initially */ +#ifndef AFS_NT40_ENV +#include +#endif +#endif + +static int fs_stateCreateDump(struct fs_dump_state * state); +static int fs_stateLoadDump(struct fs_dump_state * state); +static int fs_stateInvalidateDump(struct fs_dump_state * state); +static int fs_stateCommitDump(struct fs_dump_state * state); +static int fs_stateCloseDump(struct fs_dump_state * state); + +#ifdef FS_STATE_USE_MMAP +static int fs_stateSizeFile(struct fs_dump_state * state); +static int fs_stateResizeFile(struct fs_dump_state * state, size_t min_add); +static int fs_stateTruncateFile(struct fs_dump_state * state); + +static int fs_stateMapFile(struct fs_dump_state * state); +static int fs_stateUnmapFile(struct fs_dump_state * state); + +static int fs_stateIncCursor(struct fs_dump_state * state, size_t len); +static int fs_stateCheckIOSafety(struct fs_dump_state * state, + size_t len); +#endif + +static int fs_stateFillHeader(struct fs_state_header * hdr); +static int fs_stateCheckHeader(struct fs_state_header * hdr); + +static int fs_stateAlloc(struct fs_dump_state * state); +static int fs_stateFree(struct fs_dump_state * state); + +extern afsUUID FS_HostUUID; +extern char cml_version_number[]; + +int +fs_stateFileOpen(struct fs_dump_state *state) +{ +#ifdef AFS_NT40_ENV + return(state->fd != -1); +#else + return(state->fd >= 0); +#endif +} + + +/* + * demand attach fs + * save all fileserver state + */ +int +fs_stateSave(void) +{ + int ret = 0, verified = 1; + struct fs_dump_state state; + + /* save and restore need to be atomic wrt other host package operations */ + H_LOCK; + + ViceLog(0, ("fs_stateSave: commencing fileserver state dump\n")); + + if (fs_stateAlloc(&state)) { + ViceLog(0, ("fs_stateSave: memory allocation failed; dump aborted\n")); + ret = 1; + goto done; + } + + /* XXX + * on busy servers, these checks will inevitably fail since stuff drops H_LOCK + * all over the place (with structs left in inconsistent states) while RPCs to + * clients happen (grumble, grumble, the host package needs to be rewritten...) + * + * the current hack is to force the background threads that deal with host and + * callback state offline early in the shutdown process, do VShutdown, come + * back and wait for those threads to die, THEN do the state dump + * + * BUT, this still has one flaw -- what do we do about rx worker threads that + * are blocked in the host package making an RPC call to a cm??? + * + * currently we try to detect if a host struct is in an inconsistent state + * when we go to save it to disk, and just skip the hosts that we think may + * be inconsistent (see h_isBusy_r in host.c). This has the problem of causing + * more InitCallBackState's when we come back up, but the number of hosts in + * such a state should be small. In the future, we could try to lock hosts + * (with some deadline so we don't wait forever) before serializing, but at + * least for now it does not seem worth the trouble. + */ + + if (fs_state.options.fs_state_verify_before_save) { + ViceLog(0, ("fs_stateSave: performing internal consistency checks before proceeding with state dump\n")); + + if (h_stateVerify(&state)) { + ViceLog(0, ("fs_stateSave: error: host table consistency checks failed; state dump will not be marked clean\n")); + verified = 0; + ret = 1; + } + + if (cb_stateVerify(&state)) { + ViceLog(0, ("fs_stateSave: error: callback table consistency checks failed; state dump will not be marked clean\n")); + verified = 0; + ret = 1; + } + + /* if a consistency check asserted the bail flag, reset it */ + state.bail = 0; + + ViceLog(0, ("fs_stateSave: proceeding with dump\n")); + } + + if (fs_stateCreateDump(&state)) { + ViceLog(0, ("fs_stateSave: error: dump create failed\n")); + ret = 1; + goto done; + } + + if (h_stateSave(&state)) { + ViceLog(0, ("fs_stateSave: error: host state dump failed\n")); + ret = 1; + goto done; + } + + if (cb_stateSave(&state)) { + ViceLog(0, ("fs_stateSave: error: callback state dump failed\n")); + ret = 1; + goto done; + } + + if (!verified) { + state.bail = 1; + } + + if (fs_stateCommitDump(&state)) { + ViceLog(0, ("fs_stateSave: error: dump commit failed\n")); + ret = 1; + goto done; + } + + if (verified) { + ViceLog(0, ("fs_stateSave: fileserver state dump completed successfully\n")); + } else { + ViceLog(0, ("fs_stateSave: fileserver state dump completed, but not marked clean.\n")); + ViceLog(0, ("fs_stateSave: please save a copy of '%s' for use by technical support\n", + state.fn)); + } + + done: + if (fs_stateFileOpen(&state)) + fs_stateCloseDump(&state); + fs_stateFree(&state); + H_UNLOCK; + return ret; +} + +/* + * demand attach fs + * restore all fileserver state + * + * this function must appear as one atomic operation to the host and callback + * packages, hence H_LOCK is held for the entirety of the process. + */ +int +fs_stateRestore(void) +{ + int ret = 0; + struct fs_dump_state state; + + /* save and restore need to be atomic wrt other host package operations */ + H_LOCK; + + ViceLog(0, ("fs_stateRestore: commencing fileserver state restore\n")); + + if (fs_stateAlloc(&state)) { + ViceLog(0, ("fs_stateRestore: memory allocation failed\n")); + ret = 1; + goto done; + } + + if (fs_stateLoadDump(&state)) { + ViceLog(0, ("fs_stateRestore: failed to load dump file '%s'\n", state.fn)); + ret = 1; + goto done; + } + + if (fs_stateInvalidateDump(&state)) { + ViceLog(0, ("fs_stateRestore: failed to invalidate dump file '%s'\n", state.fn)); + ret = 1; + goto done; + } + + + if (state.flags.do_host_restore) { + if (h_stateRestore(&state)) { + ViceLog(0, ("fs_stateRestore: error: host state restore failed. exiting avoid further corruption\n")); + exit(0); + } + ViceLog(0, ("fs_stateRestore: host table restored\n")); + + if (cb_stateRestore(&state)) { + ViceLog(0, ("fs_stateRestore: error: callback state restore failed. exiting to avoid further corruption\n")); + exit(0); + } + ViceLog(0, ("fs_stateRestore: FileEntry and CallBack tables restored\n")); + + if (h_stateRestoreIndices(&state)) { + ViceLog(0, ("fs_stateRestore: error: host index remapping failed. exiting to avoid further corruption\n")); + exit(0); + } + ViceLog(0, ("fs_stateRestore: host table indices remapped\n")); + + if (cb_stateRestoreIndices(&state)) { + ViceLog(0, ("fs_stateRestore: error: callback index remapping failed. exiting to avoid further corruption\n")); + exit(0); + } + ViceLog(0, ("fs_stateRestore: FileEntry and CallBack indices remapped\n")); + } + + ViceLog(0, ("fs_stateRestore: restore phase complete\n")); + + if (fs_state.options.fs_state_verify_after_restore) { + ViceLog(0, ("fs_stateRestore: beginning state verification phase\n")); + + if (state.flags.do_host_restore) { + if (h_stateVerify(&state)) { + ViceLog(0, ("fs_stateRestore: error: host table consistency checks failed; exiting to avoid further corruption\n")); + exit(0); + } + + if (cb_stateVerify(&state)) { + ViceLog(0, ("fs_stateRestore: error: callback table consistency checks failed; exiting to avoid further corruption\n")); + exit(0); + } + } + + ViceLog(0, ("fs_stateRestore: fileserver state verification complete\n")); + } + + ViceLog(0, ("fs_stateRestore: restore was successful\n")); + + done: + if (state.fd >= 0) { + fs_stateInvalidateDump(&state); + fs_stateCloseDump(&state); + } + fs_stateFree(&state); + H_UNLOCK; + return ret; +} + +static int +fs_stateCreateDump(struct fs_dump_state * state) +{ + int fd, ret = 0; + char savedump[MAXPATHLEN]; + struct afs_stat status; + + snprintf(savedump, sizeof(savedump), "%s.old", state->fn); + + if (afs_stat(state->fn, &status) == 0) { + renamefile(state->fn, savedump); + } + + if (((fd = afs_open(state->fn, + O_RDWR | O_CREAT | O_TRUNC, + S_IRUSR | S_IWUSR)) == -1) || + (afs_fstat(fd, &status) == -1)) { + ViceLog(0, ("fs_stateCreateDump: failed to create state dump file '%s'\n", + state->fn)); + ret = 1; + goto done; + } + + state->fd = fd; + state->mode = FS_STATE_DUMP_MODE; + memset(state->hdr, 0, sizeof(struct fs_state_header)); + fs_stateIncEOF(state, sizeof(struct fs_state_header)); + +#ifdef FS_STATE_USE_MMAP + if (fs_stateSizeFile(state)) { + ViceLog(0, ("fs_stateCreateDump: failed to resize state dump file '%s'\n", + state->fn)); + ret = 1; + goto done; + } + + if (fs_stateMapFile(state)) { + ViceLog(0, ("fs_stateCreateDump: failed to memory map state dump file '%s'\n", + state->fn)); + ret = 1; + goto done; + } +#endif + + ret = fs_stateInvalidateDump(state); + + done: + return ret; +} + +static int +fs_stateInvalidateDump(struct fs_dump_state * state) +{ + afs_uint64 z; + int ret = 0; + struct fs_state_header hdr; + +#ifdef FS_STATE_USE_MMAP + if (state->mmap.map == NULL) { + return 1; + } +#endif + + memcpy(&hdr, state->hdr, sizeof(hdr)); + hdr.valid = 0; + ZeroInt64(z); + + /* write a bogus header to flag dump in progress */ + if (fs_stateWriteHeader(state, &z, &hdr, sizeof(hdr))) { + ViceLog(0, ("fs_stateInvalidateDump: failed to invalidate old dump file header '%s'\n", + state->fn)); + ret = 1; + goto done; + } + if (fs_stateSync(state)) { + ViceLog(0, ("fs_stateInvalidateDump: failed to sync changes to disk\n")); + ret = 1; + goto done; + } + + done: + return ret; +} + +static int +fs_stateCommitDump(struct fs_dump_state * state) +{ + afs_uint64 z; + int ret = 0; + + ZeroInt64(z); + +#ifdef FS_STATE_USE_MMAP + if (fs_stateTruncateFile(state)) { + ViceLog(0, ("fs_stateCommitDump: failed to truncate dump file to proper size\n")); + ret = 1; + goto done; + } +#endif + + /* ensure that all pending data I/Os for the state file have been committed + * _before_ we make the metadata I/Os */ + if (fs_stateSync(state)) { + ViceLog(0, ("fs_stateCommitDump: failed to sync changes to disk\n")); + ret = 1; + goto done; + } + +#ifdef FS_STATE_USE_MMAP + /* XXX madvise may not exist on all platforms, so + * we may need to add some ifdefs at some point... */ + { + madvise((((char *)state->mmap.map) + sizeof(struct fs_state_header)), + state->mmap.size - sizeof(struct fs_state_header), + MADV_DONTNEED); + } +#endif + + /* build the header, and write it to disk */ + fs_stateFillHeader(state->hdr); + if (state->bail) { + state->hdr->valid = 0; + } + if (fs_stateWriteHeader(state, &z, state->hdr, sizeof(struct fs_state_header))) { + ViceLog(0, ("fs_stateCommitDump: failed to write header to dump file '%s'\n", + state->fn)); + ret = 1; + goto done; + } + if (fs_stateSync(state)) { + ViceLog(0, ("fs_stateCommitDump: failed to sync new header to disk\n")); + ret = 1; + goto done; + } + + done: + return ret; +} + +static int +fs_stateLoadDump(struct fs_dump_state * state) +{ + afs_uint64 z; + int fd, ret = 0; + struct afs_stat status; + afs_int32 now = FT_ApproxTime(); + + ZeroInt64(z); + + if ((fd = afs_open(state->fn, O_RDWR)) == -1 || + (afs_fstat(fd, &status) == -1)) { + ViceLog(0, ("fs_stateLoadDump: failed to load state dump file '%s'\n", + state->fn)); + ret = 1; + goto done; + } + state->fd = fd; + state->mode = FS_STATE_LOAD_MODE; + state->file_len = status.st_size; + +#ifdef FS_STATE_USE_MMAP + if (fs_stateMapFile(state)) { + ViceLog(0, ("fs_stateLoadDump: failed to memory map state dump file '%s'\n", + state->fn)); + ret = 1; + goto done; + } +#endif + + if (fs_stateReadHeader(state, &z, state->hdr, sizeof(struct fs_state_header))) { + ViceLog(0, ("fs_stateLoadDump: failed to read header from dump file '%s'\n", + state->fn)); + ret = 1; + goto done; + } + + /* check the validity of the header */ + if (fs_stateCheckHeader(state->hdr)) { + ViceLog(1, ("fs_stateLoadDump: header failed validity checks; not restoring '%s'\n", + state->fn)); + ret = 1; + goto done; + } + + if ((state->hdr->timestamp + HOST_STATE_VALID_WINDOW) >= now) { + state->flags.do_host_restore = 1; + } else { + ViceLog(0, ("fs_stateLoadDump: warning: dump is too old for host and callback restore; skipping those steps\n")); + } + + done: + return ret; +} + +static int +fs_stateCloseDump(struct fs_dump_state * state) +{ +#ifdef FS_STATE_USE_MMAP + fs_stateUnmapFile(state); +#endif + close(state->fd); + return 0; +} + +int +fs_stateWrite(struct fs_dump_state * state, + void * buf, size_t len) +{ + int ret = 0; + +#ifdef FS_STATE_USE_MMAP + if (fs_stateCheckIOSafety(state, len)) { + if (fs_stateResizeFile(state, len)) { + ViceLog(0, ("fs_stateWrite: could not resize dump file '%s'\n", + state->fn)); + ret = 1; + goto done; + } + } + + memcpy(state->mmap.cursor, buf, len); + fs_stateIncCursor(state, len); +#else + if (write(state->fd, buf, len) != len) { + ViceLog(0, ("fs_stateWrite: write failed\n")); + ret = 1; + goto done; + } +#endif + + done: + return ret; +} + +int +fs_stateRead(struct fs_dump_state * state, + void * buf, size_t len) +{ + int ret = 0; + +#ifdef FS_STATE_USE_MMAP + if (fs_stateCheckIOSafety(state, len)) { + ViceLog(0, ("fs_stateRead: read beyond EOF for dump file '%s'\n", + state->fn)); + ret = 1; + goto done; + } + + memcpy(buf, state->mmap.cursor, len); + fs_stateIncCursor(state, len); +#else + if (read(state->fd, buf, len) != len) { + ViceLog(0, ("fs_stateRead: read failed\n")); + ret = 1; + goto done; + } +#endif + + done: + return ret; +} + +int +fs_stateWriteV(struct fs_dump_state * state, + struct iovec * iov, int niov) +{ + int i, ret = 0; + size_t len = 0; + + for (i=0; i < niov; i++) { + len += iov[i].iov_len; + } + +#ifdef FS_STATE_USE_MMAP + if (fs_stateCheckIOSafety(state, len)) { + if (fs_stateResizeFile(state, len)) { + ViceLog(0, ("fs_stateWrite: could not resize dump file '%s'\n", + state->fn)); + ret = 1; + goto done; + } + } + + for (i=0; i < niov; i++) { + memcpy(state->mmap.cursor, iov[i].iov_base, iov[i].iov_len); + fs_stateIncCursor(state, iov[i].iov_len); + } +#else +#ifndef AFS_NT40_ENV + if (writev(state->fd, iov, niov) != len) { + ViceLog(0, ("fs_stateWriteV: write failed\n")); + ret = 1; + goto done; + } +#else /* AFS_NT40_ENV */ + for (i=0; i < niov; i++) { + if (write(state->fd, iov[i].iov_base, iov[i].iov_len) != iov[i].iov_len) { + ViceLog(0, ("fs_stateWriteV: write failed\n")); + ret = 1; + goto done; + } + } +#endif /* AFS_NT40_ENV */ +#endif + + done: + return ret; +} + +int +fs_stateReadV(struct fs_dump_state * state, + struct iovec * iov, int niov) +{ + int i, ret = 0; + size_t len = 0; + + for (i=0; i < niov; i++) { + len += iov[i].iov_len; + } + +#ifdef FS_STATE_USE_MMAP + if (fs_stateCheckIOSafety(state, len)) { + ViceLog(0, ("fs_stateRead: read beyond EOF for dump file '%s'\n", + state->fn)); + ret = 1; + goto done; + } + + for (i=0; i < niov; i++) { + memcpy(iov[i].iov_base, state->mmap.cursor, iov[i].iov_len); + fs_stateIncCursor(state, iov[i].iov_len); + } +#else +#ifndef AFS_NT40_ENV + if (readv(state->fd, iov, niov) != len) { + ViceLog(0, ("fs_stateReadV: read failed\n")); + ret = 1; + goto done; + } +#else + for (i=0; i < niov; i++) { + if (read(state->fd, iov[i].iov_base, iov[i].iov_len) != iov[i].iov_len) { + ViceLog(0, ("fs_stateReadV: read failed\n")); + ret = 1; + goto done; + } + } +#endif /* AFS_NT40_ENV */ +#endif + + done: + return ret; +} + +int +fs_stateWriteHeader(struct fs_dump_state * state, + afs_uint64 * offset, + void * hdr, size_t len) +{ + int ret = 0; + + if (fs_stateSeek(state, offset)) { + ViceLog(0, ("fs_stateWriteHeader: could not seek to correct position in dump file '%s'\n", + state->fn)); + ret = 1; + goto done; + } + + if (fs_stateWrite(state, hdr, len)) { + ViceLog(0, ("fs_stateWriteHeader: write failed\n")); + ret = 1; + goto done; + } + + done: + return ret; +} + +int +fs_stateReadHeader(struct fs_dump_state * state, + afs_uint64 * offset, + void * hdr, size_t len) +{ + int ret = 0; + + if (fs_stateSeek(state, offset)) { + ViceLog(0, ("fs_stateReadHeader: could not seek to correct position in dump file '%s'\n", + state->fn)); + ret = 1; + goto done; + } + + if (fs_stateRead(state, hdr,len)) { + ViceLog(0, ("fs_stateReadHeader: read failed\n")); + ret = 1; + goto done; + } + + done: + return ret; +} + +#ifdef FS_STATE_USE_MMAP +static int +fs_stateSizeFile(struct fs_dump_state * state) +{ + int ret = 0; + state->file_len = FS_STATE_INIT_FILESIZE; + if (afs_ftruncate(state->fd, state->file_len) != 0) + ret = 1; + return ret; +} + +static int +fs_stateResizeFile(struct fs_dump_state * state, size_t min_add) +{ + int ret = 0; + afs_foff_t inc; + + fs_stateUnmapFile(state); + + inc = ((min_add / FS_STATE_INIT_FILESIZE)+1) * FS_STATE_INIT_FILESIZE; + state->file_len += inc; + + if (afs_ftruncate(state->fd, state->file_len) != 0) { + ViceLog(0, ("fs_stateResizeFile: truncate failed\n")); + ret = 1; + goto done; + } + + if (fs_stateMapFile(state)) { + ViceLog(0, ("fs_stateResizeFile: remapping memory mapped file failed\n")); + ret = 1; + goto done; + } + + done: + return ret; +} + +static int +fs_stateTruncateFile(struct fs_dump_state * state) +{ + int ret = 0; + + if (afs_ftruncate(state->fd, state->eof_offset) != 0) { + ret = 1; + } + + return ret; +} + +static int +fs_stateMapFile(struct fs_dump_state * state) +{ + int ret = 0, flags; + + switch(state->mode) { + case FS_STATE_LOAD_MODE: + flags = PROT_READ | PROT_WRITE; /* loading involves a header invalidation */ + break; + case FS_STATE_DUMP_MODE: + flags = PROT_WRITE; + break; + default: + ViceLog(0, ("fs_stateMapFile: invalid dump state mode\n")); + return 1; + } + + state->mmap.map = afs_mmap(NULL, + state->file_len, + flags, + MAP_SHARED, + state->fd, + 0); + + if (state->mmap.map == MAP_FAILED) { + state->mmap.size = 0; + state->mmap.map = NULL; + ViceLog(0, ("fs_stateMapFile: failed to memory map file '%s'\n", + state->fn)); + ret = 1; + goto done; + } + + state->mmap.size = state->file_len; + state->mmap.cursor = state->mmap.map; + state->mmap.offset = 0; + + /* for state loading, accesses will be sequential, so let's give + * the VM subsystem a heads up */ + if (state->mode == FS_STATE_LOAD_MODE) { + /* XXX madvise may not exist on all platforms, so + * we may need to add some ifdefs at some point... */ + flags = MADV_SEQUENTIAL | MADV_WILLNEED; +#ifdef AFS_SUN510_ENV + flags |= MADV_ACCESS_LWP; /* added in solaris 9 12/02 */ +#endif + madvise(state->mmap.map, state->mmap.size, flags); + } + + done: + return ret; +} + +static int +fs_stateUnmapFile(struct fs_dump_state * state) +{ + int ret = 0; + + if (munmap(state->mmap.map, state->mmap.size) == -1) { + ViceLog(0, ("fs_stateUnmapFile: failed to unmap dump file '%s'\n", + state->fn)); + ret = 1; + goto done; + } + + done: + return ret; +} + +int +fs_stateSync(struct fs_dump_state * state) +{ + int ret = 0; + + msync(state->mmap.map, state->mmap.size, MS_SYNC); + + return ret; +} +#else /* !FS_STATE_USE_MMAP */ +int +fs_stateSync(struct fs_dump_state * state) +{ + int ret = 0; + + if (fsync(state->fd) == -1) + ret = 1; + + return ret; +} +#endif /* !FS_STATE_USE_MMAP */ + +int +fs_stateIncEOF(struct fs_dump_state * state, afs_int32 len) +{ + afs_uint64 temp; + FillInt64(temp, 0, len); + AddUInt64(state->eof_offset, temp, &state->eof_offset); + return 0; +} + +#ifdef FS_STATE_USE_MMAP +static int +fs_stateIncCursor(struct fs_dump_state * state, size_t len) +{ + char * p; + + state->mmap.offset += len; + + p = (char *) state->mmap.cursor; + p += len; + state->mmap.cursor = (void *) p; + + return 0; +} + +static int +fs_stateCheckIOSafety(struct fs_dump_state * state, size_t len) +{ + int ret = 0; + + if ((state->mmap.offset + len) > state->mmap.size) { + ret = 1; + } + return ret; +} +#endif /* FS_STATE_USE_MMAP */ + +#ifdef FS_STATE_USE_MMAP +int +fs_stateSeek(struct fs_dump_state * state, afs_uint64 * offset) +{ + int ret = 0; + char * p; + + /* update cursor */ + p = (char *) state->mmap.map; + p += *offset; + state->mmap.cursor = (void *) p; + + /* update offset */ + state->mmap.offset = *offset; + + return ret; +} +#else /* !FS_STATE_USE_MMAP */ +int +fs_stateSeek(struct fs_dump_state * state, afs_uint64 * offset) +{ + int ret = 0; + + if (afs_lseek(state->fd, *offset, SEEK_SET) == -1) + ret = 1; + + return ret; +} +#endif /* !FS_STATE_USE_MMAP */ + +static int +fs_stateFillHeader(struct fs_state_header * hdr) +{ + hdr->stamp.magic = FS_STATE_MAGIC; + hdr->stamp.version = FS_STATE_VERSION; +#ifdef SYS_NAME_ID + hdr->sys_name = SYS_NAME_ID; +#else + hdr->sys_name = 0xFFFFFFFF; +#endif + hdr->timestamp = FT_ApproxTime(); + hdr->server_uuid = FS_HostUUID; + hdr->valid = 1; +#ifdef WORDS_BIGENDIAN + hdr->endianness = 1; +#else + hdr->endianness = 0; +#endif + hdr->stats_detailed = 1; + if (strlcpy(hdr->server_version_string, cml_version_number, sizeof(hdr->server_version_string)) + >= sizeof(hdr->server_version_string)) { + ViceLog(0, ("fs_stateFillHeader: WARNING -- cml_version_number field truncated\n")); + } + return 0; +} + +static int +fs_stateCheckHeader(struct fs_state_header * hdr) +{ + int ret = 0; + + if (!hdr->valid) { + ViceLog(0, ("fs_stateCheckHeader: dump was previously flagged invalid\n")); + ret = 1; + } +#ifdef WORDS_BIGENDIAN + else if (!hdr->endianness) { + ViceLog(0, ("fs_stateCheckHeader: wrong endianness\n")); + ret = 1; + } +#else /* AFSLITTLE_ENDIAN */ + else if (hdr->endianness) { + ViceLog(0, ("fs_stateCheckHeader: wrong endianness\n")); + ret = 1; + } +#endif /* AFSLITTLE_ENDIAN */ + + else if (hdr->stamp.magic != FS_STATE_MAGIC) { + ViceLog(0, ("fs_stateCheckHeader: invalid dump header\n")); + ret = 1; + } + else if (hdr->stamp.version != FS_STATE_VERSION) { + ViceLog(0, ("fs_stateCheckHeader: unknown dump format version number\n")); + ret = 1; + } + + else if (!hdr->stats_detailed) { + ViceLog(0, ("fs_stateCheckHeader: wrong config flags\n")); + ret = 1; + } + + else if (!afs_uuid_equal(&hdr->server_uuid, &FS_HostUUID)) { + ViceLog(0, ("fs_stateCheckHeader: server UUID does not match this server's UUID\n")); + ret = 1; + } + + /* the cml_version_string is included for informational purposes only. If someone ever + * wants to limit state dump reloading based upon the contents of this string, just + * uncomment the following code. uncommenting this code is _strongly discouraged_ because + * we already make use of the version stamps in the various dump headers to deal with + * data structure version incompatabilities. + else if (strncmp(hdr->server_version_string, cml_version_number, + sizeof(hdr->server_version_string)) != 0) { + ViceLog(0, ("fs_stateCheckHeader: dump from different server version\n")); + ret = 1; + } + */ + + else if (strncmp(hdr->server_version_string, cml_version_number, + sizeof(hdr->server_version_string)) != 0) { + ViceLog(0, ("fs_stateCheckHeader: dump from different server version ; attempting state reload anyway\n")); + } + + + return ret; +} + +static int +fs_stateAlloc(struct fs_dump_state * state) +{ + int ret = 0; + memset(state, 0, sizeof(struct fs_dump_state)); + state->fd = -1; + state->fn = (char *)AFSDIR_SERVER_FSSTATE_FILEPATH; + state->hdr = (struct fs_state_header *)malloc(sizeof(struct fs_state_header)); + state->h_hdr = (struct host_state_header *)malloc(sizeof(struct host_state_header)); + state->cb_hdr = (struct callback_state_header *)malloc(sizeof(struct callback_state_header)); + state->cb_timeout_hdr = (struct callback_state_timeout_header *) + malloc(sizeof(struct callback_state_timeout_header)); + state->cb_fehash_hdr = (struct callback_state_fehash_header *) + malloc(sizeof(struct callback_state_fehash_header)); + if ((state->hdr == NULL) || (state->h_hdr == NULL) || (state->cb_hdr == NULL) || + (state->cb_timeout_hdr == NULL) || (state->cb_fehash_hdr == NULL)) + ret = 1; + return ret; +} + +static int +fs_stateFree(struct fs_dump_state * state) +{ + if (state->hdr) + free(state->hdr); + if (state->h_hdr) + free(state->h_hdr); + if (state->cb_hdr) + free(state->cb_hdr); + if (state->cb_timeout_hdr) + free(state->cb_timeout_hdr); + if (state->cb_fehash_hdr) + free(state->cb_fehash_hdr); + if (state->h_map.entries) + free(state->h_map.entries); + if (state->fe_map.entries) + free(state->fe_map.entries); + if (state->cb_map.entries) + free(state->cb_map.entries); + return 0; +} + +#endif /* AFS_DEMAND_ATTACH_FS */ diff --git a/src/viced/serialize_state.h b/src/viced/serialize_state.h new file mode 100644 index 000000000..2d095dfdc --- /dev/null +++ b/src/viced/serialize_state.h @@ -0,0 +1,312 @@ +/* + * Copyright 2006, Sine Nomine Associates and others. + * All Rights Reserved. + * + * This software has been released under the terms of the IBM Public + * License. For details, see the LICENSE file in the top-level source + * directory or online at http://www.openafs.org/dl/license10.html + */ + +/* + * demand attach fs + * fileserver state serialization + */ + +#ifndef _AFS_TVICED_SERIALIZE_STATE_H +#define _AFS_TVICED_SERIALIZE_STATE_H + +#ifdef AFS_DEMAND_ATTACH_FS + +#define FS_STATE_MAGIC 0x62FA841C +#define FS_STATE_VERSION 2 + +#define HOST_STATE_MAGIC 0x7B8C9DAE +#define HOST_STATE_VERSION 2 + +#define HOST_STATE_ENTRY_MAGIC 0xA8B9CADB + +#define CALLBACK_STATE_MAGIC 0x89DE67BC +#define CALLBACK_STATE_VERSION 1 + +#define CALLBACK_STATE_TIMEOUT_MAGIC 0x99DD5511 +#define CALLBACK_STATE_FEHASH_MAGIC 0x77BB33FF +#define CALLBACK_STATE_ENTRY_MAGIC 0x54637281 + +#define ACTIVE_VOLUME_STATE_MAGIC 0xAC7557CA +#define ACTIVE_VOLUME_STATE_VERSION 1 + +#define ACTIVE_VOLUME_STATE_AVEHASH_MAGIC 0xBADDF00D + +#define HOST_STATE_VALID_WINDOW 1800 /* 30 minutes */ + +/* values for the 'valid' field in idx_map_entry_t */ +#define FS_STATE_IDX_VALID 1 +#define FS_STATE_IDX_SKIPPED 2 + +/* + * on-disk structures + */ +struct disk_version_stamp { + afs_uint32 magic; + afs_uint32 version; +}; + +/* 1024 byte header structure */ +struct fs_state_header { + struct disk_version_stamp stamp; /* version stamp */ + time_t timestamp; /* timestamp of save */ + afs_uint32 sys_name; /* sys name id for this machine */ + afsUUID server_uuid; /* server's UUID */ + byte valid; /* whether header contents are valid */ + byte endianness; /* endianness sanity check (0 for LE, 1 for BE) */ + byte stats_detailed; /* fs stats detailed sanity check */ + byte padding1[1]; /* padding */ + afs_uint32 reserved1[23]; /* for expansion */ + afs_uint64 avol_offset; /* offset of active volumes structure */ + afs_uint64 h_offset; /* offset of host_state_header structure */ + afs_uint64 cb_offset; /* offset of callback_state_header structure */ + afs_uint64 vlru_offset; /* offset of vlru state structure */ + afs_uint32 reserved2[56]; /* for expansion */ + char server_version_string[128]; /* version string from AFS_component_version_number.c */ + afs_uint32 reserved3[128]; /* for expansion */ +}; + +/* + * host package serialization + */ + +/* 256 byte header for the host state data */ +struct host_state_header { + struct disk_version_stamp stamp; /* host state version stamp */ + afs_uint32 records; /* number of stored host records */ + afs_uint32 index_max; /* max index value encountered */ + afs_uint32 reserved[60]; /* for expansion */ +}; + +/* 32 byte host entry header */ +struct host_state_entry_header { + afs_uint32 magic; /* stamp */ + afs_uint32 len; /* number of bytes in this record */ + afs_uint32 interfaces; /* number of interfaces included in record */ + afs_uint32 hcps; /* number of hcps entries in record */ + afs_uint32 reserved[4]; +}; + +/* 36 byte host entry structure */ +struct hostDiskEntry { + afs_uint32 host; /* IP address of host interface that is + * currently being used, in network + * byte order */ + afs_uint16 port; /* port address of host */ + afs_uint16 hostFlags; /* bit map */ + byte Console; /* XXXX This host is a console */ + byte hcpsfailed; /* Retry the cps call next time */ + byte hcps_valid; /* prlist_val not null */ + byte InSameNetwork; /*Is host's addr in the same network as + * the File Server's? */ + afs_uint32 hcps_len; /* length of hcps */ + afs_uint32 LastCall; /* time of last call from host */ + afs_uint32 ActiveCall; /* time of any call but gettime */ + afs_uint32 cpsCall; /* time of last cps call from this host */ + afs_uint32 cblist; /* Call back list for this host */ + afs_uint32 index; /* index for correlating w/ callback dumps */ +}; + +/* + * callback package serialization + */ + +/* 512 byte header */ +struct callback_state_header { + struct disk_version_stamp stamp; /* callback state version stamp */ + afs_uint32 nFEs; /* number of FileEntry records */ + afs_uint32 nCBs; /* number of CallBack records */ + afs_uint32 fe_max; /* max FileEntry index */ + afs_uint32 cb_max; /* max CallBack index */ + afs_int32 tfirst; /* first valid timeout */ + afs_uint32 reserved[115]; /* for expansion */ + afs_uint64 timeout_offset; /* offset of timeout queue heads */ + afs_uint64 fehash_offset; /* offset of file entry hash buckets */ + afs_uint64 fe_offset; /* offset of first file entry */ +}; + +/* 32 byte header */ +struct callback_state_timeout_header { + afs_uint32 magic; /* magic number for timeout header */ + afs_uint32 len; /* total length of header and timeout records */ + afs_uint32 records; /* number of timeout records */ + afs_uint32 reserved[5]; +}; + +/* 32 byte header */ +struct callback_state_fehash_header { + afs_uint32 magic; /* magic number for fehash header */ + afs_uint32 len; /* total length of header and fehash bucket heads */ + afs_uint32 records; /* number of hash buckets */ + afs_uint32 reserved[5]; +}; + +/* 32 byte header */ +struct callback_state_entry_header { + afs_uint32 magic; /* magic number for FE entry */ + afs_uint32 len; /* number of bytes in this record */ + afs_uint32 nCBs; /* number of callbacks for this FE */ + afs_uint32 reserved[5]; +}; + +struct FEDiskEntry { + struct FileEntry fe; + afs_uint32 index; +}; + +struct CBDiskEntry { + struct CallBack cb; + afs_uint32 index; +}; + +/* + * active volumes state serialization + * + * these structures are meant to support + * automated salvaging of active volumes + * in the event of a fileserver crash + */ + +/* 512 byte header */ +struct active_volume_state_header { + struct disk_version_stamp stamp; /* callback state version stamp */ + afs_uint32 nAVEs; /* number of ActiveVolumeEntry records */ + afs_uint32 init_timestamp; /* timestamp of AVE initialization */ + afs_uint32 update_timetamp; /* timestamp of last AVE update */ + afs_uint32 reserved[119]; /* for expansion */ + afs_uint64 avehash_offset; /* offset of active volume entry hash buckets */ + afs_uint64 ave_offset; /* offset of first active volume entry */ +}; + +/* 32 byte header */ +struct active_volume_state_avehash_header { + afs_uint32 magic; /* magic number for avehash header */ + afs_uint32 len; /* total length of header and avehash bucket heads */ + afs_uint32 records; /* number of hash buckets */ + afs_uint32 reserved[5]; +}; + +typedef afs_uint32 active_volume_state_avehash_entry; + +/* active volume entry */ +struct AVDiskEntry { + afs_uint32 volume; + afs_uint32 partition; + afs_uint32 hash_next; +}; + + +/* + * dump runtime state + */ +struct idx_map_entry_t { + byte valid; /* whether or not this entry has been populated */ + afs_uint32 old_idx; /* host hash id from last runtime */ + afs_uint32 new_idx; /* host hash id for this runtime */ +}; + + +/* verification process sanity check constants + * + * make them fairly large so we don't get + * false positives + */ +#define FS_STATE_H_MAX_UUID_HASH_CHAIN_LEN 100000 /* max elements in a host uuid-hash chain */ +#define FS_STATE_H_MAX_ADDR_HASH_CHAIN_LEN 2000000 /* max elements in a host ipv4-hash chain */ +#define FS_STATE_FE_MAX_HASH_CHAIN_LEN 100000 /* max elements in a FE fid-hash chain */ +#define FS_STATE_FCB_MAX_LIST_LEN 100000 /* max elements in a per-FE CB list */ +#define FS_STATE_HCB_MAX_LIST_LEN 100000 /* max elements in a per-host CB list */ +#define FS_STATE_TCB_MAX_LIST_LEN 100000 /* max elements in a per-timeout CB list */ + + +/* + * main state serialization state structure + */ + +struct fs_dump_state { + enum { + FS_STATE_DUMP_MODE, + FS_STATE_LOAD_MODE + } mode; + struct { + byte do_host_restore; /* whether host restore should be done */ + byte some_steps_skipped; /* whether some steps were skipped */ + byte warnings_generated; /* whether any warnings were generated during restore */ + } flags; + afs_fsize_t file_len; + int fd; /* fd of the current dump file */ + int bail; /* non-zero if something went wrong */ + char * fn; /* name of the current dump file */ + struct { /* memory map of dump file */ + void * map; + void * cursor; + afs_foff_t offset; + afs_fsize_t size; + } mmap; + struct fs_state_header * hdr; /* main header */ + struct host_state_header * h_hdr; /* header for host state data */ + struct callback_state_header * cb_hdr; /* header for callback state data */ + struct callback_state_timeout_header * cb_timeout_hdr; + struct callback_state_fehash_header * cb_fehash_hdr; + afs_uint64 eof_offset; /* current end of file offset */ + struct { + int len; /* number of host entries in map */ + struct idx_map_entry_t * entries; + } h_map; + struct { + int len; + struct idx_map_entry_t * entries; + } fe_map; + struct { + int len; + struct idx_map_entry_t * entries; + } cb_map; +}; + +/* prototypes */ + +/* serialize_state.c */ +extern int fs_stateFileOpen(struct fs_dump_state *state); +extern int fs_stateWrite(struct fs_dump_state * state, + void * buf, size_t len); +extern int fs_stateRead(struct fs_dump_state * state, + void * buf, size_t len); +extern int fs_stateWriteV(struct fs_dump_state * state, + struct iovec * iov, int niov); +extern int fs_stateReadV(struct fs_dump_state * state, + struct iovec * iov, int niov); +extern int fs_stateSync(struct fs_dump_state * state); +extern int fs_stateWriteHeader(struct fs_dump_state * state, + afs_uint64 * offset, + void * hdr, size_t len); +extern int fs_stateReadHeader(struct fs_dump_state * state, + afs_uint64 * offset, + void * hdr, size_t len); +extern int fs_stateIncEOF(struct fs_dump_state * state, + afs_int32 len); +extern int fs_stateSeek(struct fs_dump_state * state, + afs_uint64 * offset); + +/* host.c */ +extern int h_stateSave(struct fs_dump_state * state); +extern int h_stateRestore(struct fs_dump_state * state); +extern int h_stateRestoreIndices(struct fs_dump_state * state); +extern int h_stateVerify(struct fs_dump_state * state); +extern int h_OldToNew(struct fs_dump_state * state, afs_uint32 old, afs_uint32 * new); + +/* callback.c */ +extern int cb_stateSave(struct fs_dump_state * state); +extern int cb_stateRestore(struct fs_dump_state * state); +extern int cb_stateRestoreIndices(struct fs_dump_state * state); +extern int cb_stateVerify(struct fs_dump_state * state); +extern int cb_stateVerifyHCBList(struct fs_dump_state * state, struct host * host); +extern int fe_OldToNew(struct fs_dump_state * state, afs_uint32 old, afs_uint32 * new); +extern int cb_OldToNew(struct fs_dump_state * state, afs_uint32 old, afs_uint32 * new); + +#endif /* AFS_DEMAND_ATTACH_FS */ +#endif /* _AFS_TVICED_SERIALIZE_STATE_H */ diff --git a/src/viced/state_analyzer.c b/src/viced/state_analyzer.c new file mode 100644 index 000000000..5302d1d11 --- /dev/null +++ b/src/viced/state_analyzer.c @@ -0,0 +1,1949 @@ +/* + * Copyright 2006, Sine Nomine Associates and others. + * All Rights Reserved. + * + * This software has been released under the terms of the IBM Public + * License. For details, see the LICENSE file in the top-level source + * directory or online at http://www.openafs.org/dl/license10.html + */ + +/* + * demand attach fs + * fileserver state serialization + * + * state analyzer + */ + +#include +#include +#include + +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef AFS_ATHENA_STDENV +#include +#endif +#include +#include +#include +#include +#include +#include +#include "../util/afsutil_prototypes.h" +#include "../viced/viced.h" +#include "../viced/host.h" +#include "../viced/callback.h" +#include "serialize_state.h" + +#ifndef AFS_DEMAND_ATTACH_FS +int +main (int argc, char ** argv) +{ + fprintf(stderr, "%s is only supported for demand attach fileservers\n", + argv[0] ? argv[0] : "state analyzer"); + return 1; +} +#else /* AFS_DEMAND_ATTACH_FS */ + +static void usage(char * prog); +static int openFile(char * path); +static void initState(void); + +static void banner(void); +static void prompt(void); + +static void print_help(void); +static void print_global_help(void); +static void print_h_help(void); +static void print_fe_help(void); +static void print_cb_help(void); + +static void dump_hdr(void); +static void dump_h_hdr(void); +static void dump_cb_hdr(void); + +static void dump_cb_timeout(void); +static void dump_cb_fehash(void); + +static void dump_all_hes(void); +static void dump_all_fes(void); +static void dump_all_cbs(void); + +static void dump_he(afs_uint32 idx); +static void dump_fe(afs_uint32 idx); +static void dump_cb(afs_uint32 idx); +static void dump_this_he(void); +static void dump_this_fe(void); +static void dump_this_cb(void); +static void dump_next_he(void); +static void dump_next_fe(void); +static void dump_next_cb(void); +static void dump_prev_he(void); +static void dump_prev_fe(void); +static void dump_prev_cb(void); +static void dump_first_he(void); +static void dump_first_fe(void); +static void dump_first_cb(void); +static void dump_last_he(void); +static void dump_last_fe(void); +static void dump_last_cb(void); +static void dump_he_hdr(void); +static void dump_he_entry(void); +static void dump_he_interfaces(void); +static void dump_he_hcps(void); +static void dump_fe_hdr(void); +static void dump_fe_entry(void); +static void dump_cb_entry(void); + +static void hexdump_map(afs_uint32 offset, afs_uint32 len); + +static int get_hdr(void); +static int get_h_hdr(void); +static int get_cb_hdr(void); +static int get_cb_timeout_hdr(void); +static int get_cb_timeout(void); +static int get_cb_fehash_hdr(void); +static int get_cb_fehash(void); +static int get_he(afs_uint32 idx); +static int get_he_hdr(void); +static int get_he_entry(void); +static int get_fe(afs_uint32 idx); +static int get_fe_hdr(void); +static int get_fe_entry(void); +static int get_cb(afs_uint32 idx); +static int get_cb_entry(void); + +static int find_fe_by_index(afs_uint32 idx); +static int find_cb_by_index(afs_uint32 idx); +static int find_fe_by_fid(afs_uint32 vol, afs_uint32 vn, afs_uint32 uniq); + + +static int dump_fd = -1; +static void * map = NULL; +static size_t map_len; + +static struct { + struct fs_state_header hdr; + struct host_state_header h_hdr; + struct callback_state_header cb_hdr; + struct callback_state_timeout_header timeout_hdr; + struct callback_state_fehash_header fehash_hdr; + afs_uint32 * timeout; + afs_uint32 * fehash; + + /* pointers into the memory map */ + void * hdr_p; + void * h_hdr_p; + void * cb_hdr_p; + void * timeout_hdr_p; + void * timeout_p; + void * fehash_hdr_p; + void * fehash_p; + + byte hdr_valid; + byte h_hdr_valid; + byte cb_hdr_valid; + byte timeout_hdr_valid; + byte fehash_hdr_valid; +} hdrs; + +static struct { + void * fh; + void * cursor; + void * ifp; + void * hcps; + struct host_state_entry_header hdr; + struct hostDiskEntry he; + afs_uint32 idx; + byte hdr_valid; + byte he_valid; +} he_cursor; + +static struct { + void ** cursor; +} he_cache; + +static struct { + void * ffe; + void * cursor; + void * fcb; + struct callback_state_entry_header hdr; + struct FEDiskEntry fe; + afs_uint32 idx; + byte hdr_valid; + byte fe_valid; +} fe_cursor; + +static struct { + void ** cursor; +} fe_cache; + +static struct { + void * cursor; + struct CBDiskEntry cb; + afs_uint32 idx; + byte cb_valid; +} cb_cursor; + +static void +usage(char * prog) +{ + fprintf(stderr, "usage: %s []\n", prog); +} + +int +main(int argc, char ** argv) +{ + banner(); + if (argc > 2 || (argc == 2 && !strcmp(argv[1], "-h"))) { + usage(argv[0]); + return 1; + } + + initState(); + + if (argc > 1) { + if (openFile(argv[1])) + return 1; + } else { + if (openFile((char *)AFSDIR_SERVER_FSSTATE_FILEPATH)) + return 1; + } + + prompt(); + return 0; +} + + +static int +openFile(char * path) +{ + int ret = 0; + struct afs_stat status; + + dump_fd = afs_open(path, O_RDWR); + if (dump_fd == -1) { + fprintf(stderr, "dump file '%s' failed to open\n", path); + ret = 1; + goto done; + } + + printf("opened dump file '%s'\n", path); + + if (afs_fstat(dump_fd, &status) == -1) { + fprintf(stderr, "failed to stat file\n"); + ret = 1; + goto done; + } + + map_len = status.st_size; + + map = afs_mmap(NULL, map_len, PROT_READ, MAP_SHARED, dump_fd, 0); + if (map == MAP_FAILED) { + fprintf(stderr, "failed to mmap file\n"); + ret = 1; + goto done; + } + + printf("mapped %lu bytes at %"AFS_PTR_FMT"\n", (unsigned long)map_len, map); + + done: + if (ret) { + if (map) { + munmap(map, map_len); + map = NULL; + } + if (dump_fd != -1) { + close(dump_fd); + dump_fd = -1; + } + } + return ret; +} + +static void +initState(void) +{ + hdrs.hdr_valid = hdrs.h_hdr_valid = hdrs.cb_hdr_valid = 0; + he_cursor.cursor = fe_cursor.cursor = cb_cursor.cursor = NULL; + he_cursor.fh = fe_cursor.ffe = fe_cursor.fcb = NULL; + he_cache.cursor = fe_cache.cursor = NULL; +} + +static void +banner(void) +{ + fprintf(stderr, "demand attach fs\n"); + fprintf(stderr, "fileserver state analyzer\n"); + fprintf(stderr, "version 0.1\n"); +} + +#define PROGNAME "fs state analyzer" + +static void +prompt(void) +{ + char input[256]; + char prev_input[256]; + char * tok = NULL; + afs_uint32 x, y, z; + enum { + PR_GLOBAL_MODE, + PR_H_MODE, + PR_FE_MODE, + PR_CB_MODE + } mode = PR_GLOBAL_MODE, next_mode; + + next_mode = mode; + input[0] = prev_input[0] = '\0'; + + while (1) { + if (!tok) { + switch(mode) { + case PR_GLOBAL_MODE: + printf(PROGNAME "> "); + break; + case PR_H_MODE: + printf(PROGNAME ": h(%d)> ", he_cursor.idx); + break; + case PR_FE_MODE: + printf(PROGNAME ": fe(%d)> ", fe_cursor.idx); + break; + case PR_CB_MODE: + printf(PROGNAME ": fe(%d):cb(%d)> ", fe_cursor.idx, cb_cursor.idx); + break; + default: + fprintf(stderr, "prompt state broken; aborting\n"); + return; + } + fgets(input, 256, stdin); + + if (!strcmp(input, "")) { + /* repeat last command */ + if (!strcmp(prev_input, "")) { + continue; + } + strlcpy(input, prev_input, sizeof(input)); + } else { + /* save command for repetition */ + strlcpy(prev_input, input, sizeof(prev_input)); + } + + tok = strtok(input, " \t\n"); + } + while (tok && !strcmp(tok, ";")) { + tok = strtok(NULL, "; \t\n"); + } + + if (!tok) { + continue; + } + + if (!strcasecmp(tok, "exit")) { + return; + } else if (!strcasecmp(tok, "quit")) { + switch(mode) { + case PR_CB_MODE: + next_mode = PR_FE_MODE; + break; + case PR_FE_MODE: + case PR_H_MODE: + next_mode = PR_GLOBAL_MODE; + break; + default: + return; + } + } else if (!strcasecmp(tok, "h")) { + tok = strtok(NULL, " \t"); + mode = PR_H_MODE; + if (!tok) { + next_mode = mode; + } + continue; + } else if (!strcasecmp(tok, "fe")) { + tok = strtok(NULL, " \t"); + mode = PR_FE_MODE; + if (!tok) { + next_mode = mode; + } + continue; + } else if (!strcasecmp(tok, "fs")) { + tok = strtok(NULL, " \t"); + mode = PR_GLOBAL_MODE; + if (!tok) { + next_mode = mode; + } + continue; + } else if (!strcasecmp(tok, "cb")) { + tok = strtok(NULL, " \t"); + mode = PR_CB_MODE; + if (!tok) { + next_mode = mode; + } + continue; + } else if (!strcasecmp(tok, "help")) { + switch(mode) { + case PR_H_MODE: + print_h_help(); + break; + case PR_FE_MODE: + print_fe_help(); + break; + case PR_CB_MODE: + print_cb_help(); + break; + default: + print_global_help(); + } + print_help(); + } else if (!strcasecmp(tok, "hexdump")) { + tok = strtok(NULL, " \t"); + if (!tok) { + hexdump_map(0, map_len); + continue; + } + if (sscanf(tok, "%u", &x) != 1) { + fprintf(stderr, "hexdump parse error 1\n"); + tok = NULL; + continue; + } + tok = strtok(NULL, " \t"); + if (!tok) { + hexdump_map(x, map_len - x); + continue; + } + if (sscanf(tok, "%u", &y) != 1) { + fprintf(stderr, "hexdump parse error 2\n"); + continue; + } + hexdump_map(x,y); + } else if (!strcasecmp(tok, "hdr")) { + switch(mode) { + case PR_H_MODE: + dump_h_hdr(); + break; + case PR_FE_MODE: + dump_cb_hdr(); + break; + case PR_CB_MODE: + dump_this_fe(); + break; + default: + dump_hdr(); + } + } else if (!strcasecmp(tok, "this")) { + switch(mode) { + case PR_H_MODE: + dump_this_he(); + break; + case PR_FE_MODE: + dump_this_fe(); + break; + case PR_CB_MODE: + dump_this_cb(); + break; + default: + fprintf(stderr, "command not valid for this mode\n"); + } + } else if (!strcasecmp(tok, "next")) { + switch(mode) { + case PR_H_MODE: + dump_next_he(); + break; + case PR_FE_MODE: + dump_next_fe(); + break; + case PR_CB_MODE: + dump_next_cb(); + break; + default: + fprintf(stderr, "command not valid for this mode\n"); + } + } else if (!strcasecmp(tok, "prev")) { + switch(mode) { + case PR_H_MODE: + dump_prev_he(); + break; + case PR_FE_MODE: + dump_prev_fe(); + break; + case PR_CB_MODE: + dump_prev_cb(); + break; + default: + fprintf(stderr, "command not valid for this mode\n"); + } + } else if (!strcasecmp(tok, "first")) { + switch(mode) { + case PR_H_MODE: + dump_first_he(); + break; + case PR_FE_MODE: + dump_first_fe(); + break; + case PR_CB_MODE: + dump_first_cb(); + break; + default: + fprintf(stderr, "command not valid for this mode\n"); + } + } else if (!strcasecmp(tok, "last")) { + switch(mode) { + case PR_H_MODE: + dump_last_he(); + break; + case PR_FE_MODE: + dump_last_fe(); + break; + case PR_CB_MODE: + dump_last_cb(); + break; + default: + fprintf(stderr, "command not valid for this mode\n"); + } + } else if (!strcasecmp(tok, "dump")) { + switch(mode) { + case PR_H_MODE: + dump_all_hes(); + break; + case PR_FE_MODE: + dump_all_fes(); + break; + case PR_CB_MODE: + dump_all_cbs(); + break; + default: + fprintf(stderr, "command not valid for this mode\n"); + } + } else if (!strcasecmp(tok, "find")) { + tok = strtok(NULL, " \t"); + if (!tok || strcasecmp(tok, "by")) { + tok = NULL; + fprintf(stderr, "find syntax error 1 (%s)\n", + (tok) ? tok : "nil"); + continue; + } + tok = strtok(NULL, " \t"); + if (!tok) { + fprintf(stderr, "find syntax error 2\n"); + continue; + } + switch(mode) { + case PR_H_MODE: + fprintf(stderr, "not implemented yet\n"); + break; + case PR_FE_MODE: + if (!strcasecmp(tok, "index")) { + tok = strtok(NULL, " \t"); + if (!tok || sscanf(tok, "%u", &x) != 1) { + tok = NULL; + fprintf(stderr, "find syntax error 3\n"); + continue; + } + if (find_fe_by_index(x)) { + fprintf(stderr, "find returned no results\n"); + } + } else if (!strcasecmp(tok, "fid")) { + tok = strtok(NULL, "(), \t"); + if (!tok || sscanf(tok, "%u", &x) != 1) { + tok = NULL; + fprintf(stderr, "find syntax error 4\n"); + continue; + } + tok = strtok(NULL, "(), \t"); + if (!tok || sscanf(tok, "%u", &y) != 1) { + tok = NULL; + fprintf(stderr, "find syntax error 5\n"); + continue; + } + tok = strtok(NULL, "(), \t"); + if (!tok || sscanf(tok, "%u", &z) != 1) { + tok = NULL; + fprintf(stderr, "find syntax error 6\n"); + continue; + } + if (find_fe_by_fid(x,y,z)) { + fprintf(stderr, "find returned no results\n"); + } + } else { + fprintf(stderr, "unsupported filter type\n"); + } + break; + case PR_CB_MODE: + if (!strcasecmp(tok, "index")) { + tok = strtok(NULL, " \t"); + if (!tok || sscanf(tok, "%u", &x) != 1) { + tok = NULL; + fprintf(stderr, "find syntax error 3\n"); + continue; + } + if (find_cb_by_index(x)) { + fprintf(stderr, "find returned no results\n"); + } + } else { + fprintf(stderr, "unsupported filter type\n"); + } + break; + default: + fprintf(stderr, "find not supported for this menu\n"); + } + } else if (!strcspn(tok, "0123456789")) { + if (sscanf(tok, "%u", &x) == 1) { + switch(mode) { + case PR_H_MODE: + dump_he(x); + break; + case PR_FE_MODE: + dump_fe(x); + break; + case PR_CB_MODE: + dump_cb(x); + break; + default: + fprintf(stderr, "command not available from this menu\n"); + } + } else { + fprintf(stderr, "input parse error ('%s')\n", tok); + } + } else if (mode == PR_FE_MODE) { + if (!strcmp(tok, "timeout")) { + dump_cb_timeout(); + } else if (!strcmp(tok, "hash")) { + dump_cb_fehash(); + } + } else { + fprintf(stderr, "unknown command\n"); + } + tok = strtok(NULL, " \t"); + mode = next_mode; + } +} + +static void +print_help(void) +{ + printf("\th <...> -- host menu commands\n"); + printf("\tfe <...> -- FileEntry menu commands\n"); + printf("\tcb <...> -- CallBack menu commands\n"); + printf("\thexdump [ []]\n\t\t -- hex dump the raw data\n"); + printf("\tquit -- quit this menu\n"); + printf("\texit -- exit the debugger\n"); + printf("\thelp -- this help message\n"); +} + +static void +print_global_help(void) +{ + printf("\thdr -- display the fs_state_header struct\n"); +} + +static void +print_h_help(void) +{ + printf("\thdr -- display the host_state_header struct\n"); + printf("\tfirst -- display the first host\n"); + printf("\tprev -- display the previous host\n"); + printf("\tthis -- display this host\n"); + printf("\tnext -- display the next host\n"); + printf("\tlast -- display the last host\n"); + printf("\tdump -- display all hosts\n"); +} + +static void +print_fe_help(void) +{ + printf("\thdr -- display the callback_state_header struct\n"); + printf("\tfirst -- display the first FE\n"); + printf("\tprev -- display the previous FE\n"); + printf("\tthis -- display this FE\n"); + printf("\tnext -- display the next FE\n"); + printf("\tlast -- display the last FE\n"); + printf("\tdump -- display all FEs\n"); + printf("\ttimeout -- display the timeout queue heads\n"); + printf("\thash -- display the file entry hash buckets\n"); + printf("\tfind by index \n\t\t -- find an fe by its array index\n"); + printf("\tfind by fid <(vol,vnode,unique)>\n\t\t -- find an fe by its AFSFid\n"); +} + +static void +print_cb_help(void) +{ + printf("\thdr -- display the callback_state_entry_header struct\n"); + printf("\tfirst -- display the first CB\n"); + printf("\tprev -- display the previous CB\n"); + printf("\tthis -- display this CB\n"); + printf("\tnext -- display the next CB\n"); + printf("\tlast -- display the last CB\n"); + printf("\tdump -- display all CBs\n"); +} + +#define DPFTB0 "\t" +#define DPFTB1 "\t\t" +#define DPFTB2 "\t\t\t" + +#define DPFOFF(addr) \ + do { \ + char * _p = (char *)addr; \ + char * _m = (char *)map; \ + printf("loading structure from address %"AFS_PTR_FMT" (offset %ld)\n", \ + addr, (long)(_p-_m)); \ + } while (0) + +/* structs */ +#define DPFSO(T, name) printf(T "%s = {\n", name) +#define DPFSO0(name) DPFSO(DPFTB0, name) +#define DPFSO1(name) DPFSO(DPFTB1, name) +#define DPFSC(T) printf(T "}\n") +#define DPFSC0 DPFSC(DPFTB0) +#define DPFSC1 DPFSC(DPFTB1) + +/* arrays */ +#define DPFAO(T1, T2, name) printf(T1 "%s =\n" T2 "{ ", name) +#define DPFAO0(name) DPFAO(DPFTB0, DPFTB1, name) +#define DPFAO1(name) DPFAO(DPFTB1, DPFTB2, name) +#define DPFAC0 printf(" }\n") +#define DPFAC1 DPFAC0 +#define DPFA1 printf(DPFTB1 " ") +#define DPFA2 printf(DPFTB2 " ") +#define DPFAN printf("\n") +#define DPFALE(type, var) printf("%" type, var) +#define DPFAE(type, var) printf("%" type ",\t", var) + +/* normal vars */ +#define DPFV(T, name, type, var) printf(T "%s = %" type "\n", name, var) +#define DPFV1(name, type, var) DPFV(DPFTB1, name, type, var) +#define DPFV2(name, type, var) DPFV(DPFTB2, name, type, var) + +/* hex */ +#define DPFX(T, name, var) printf(T "%s = 0x%x\n", name, var) +#define DPFX1(name, var) DPFX(DPFTB1, name, var) +#define DPFX2(name, var) DPFX(DPFTB2, name, var) + +/* strings */ +#define DPFS(T, name, var) printf(T "%s = \"%s\"\n", name, var) +#define DPFS1(name, var) DPFS(DPFTB1, name, var) +#define DPFS2(name, var) DPFS(DPFTB2, name, var) + +/* time */ +#define DPFT(T, name, var) \ + do { \ + time_t t = var; \ + printf(T "%s = \"%.24s\"\n", name, ctime(&t)); \ + } while(0) +#define DPFT1(name, var) DPFT(DPFTB1, name, var) +#define DPFT2(name, var) DPFT(DPFTB2, name, var) + +static void +dump_hdr(void) +{ + char uuid_str[40]; + afs_uint32 hi, lo; + + if (get_hdr()) + return; + + DPFOFF(map); + DPFSO0("fs_state_header"); + DPFSO1("stamp"); + DPFX2("magic", hdrs.hdr.stamp.magic); + DPFV2("version", "u", hdrs.hdr.stamp.version); + DPFSC1; + DPFT1("timestamp", hdrs.hdr.timestamp); + DPFV1("sys_name", "u", hdrs.hdr.sys_name); + + afsUUID_to_string(&hdrs.hdr.server_uuid, uuid_str, sizeof(uuid_str)); + DPFS1("server_uuid", uuid_str); + DPFV1("valid", "d", hdrs.hdr.valid); + DPFV1("endianness", "d", hdrs.hdr.endianness); + DPFV1("stats_detailed", "d", hdrs.hdr.stats_detailed); + + SplitInt64(hdrs.hdr.h_offset, hi, lo); + DPFSO1("h_offset"); + DPFV2("hi", "u", hi); + DPFV2("lo", "u", lo); + DPFSC1; + + SplitInt64(hdrs.hdr.cb_offset, hi, lo); + DPFSO1("cb_offset"); + DPFV2("hi", "u", hi); + DPFV2("lo", "u", lo); + DPFSC1; + + DPFS1("server_version_string", hdrs.hdr.server_version_string); + DPFSC0; + + if (hdrs.hdr.stamp.magic != FS_STATE_MAGIC) { + fprintf(stderr, "* magic check failed\n"); + } + if (hdrs.hdr.stamp.version != FS_STATE_VERSION) { + fprintf(stderr, "* version check failed\n"); + } +} + +static void +dump_h_hdr(void) +{ + if (get_h_hdr()) + return; + + DPFOFF(hdrs.h_hdr_p); + DPFSO0("host_state_header"); + DPFSO1("stamp"); + DPFX2("magic", hdrs.h_hdr.stamp.magic); + DPFV2("version", "u", hdrs.h_hdr.stamp.version); + DPFSC1; + DPFV1("records", "u", hdrs.h_hdr.records); + DPFV1("index_max", "u", hdrs.h_hdr.index_max); + DPFSC0; + + if (hdrs.h_hdr.stamp.magic != HOST_STATE_MAGIC) { + fprintf(stderr, "* magic check failed\n"); + } + if (hdrs.h_hdr.stamp.version != HOST_STATE_VERSION) { + fprintf(stderr, "* version check failed\n"); + } +} + +static void +dump_cb_hdr(void) +{ + afs_uint32 hi, lo; + + if (get_cb_hdr()) + return; + + DPFOFF(hdrs.cb_hdr_p); + DPFSO0("callback_state_header"); + DPFSO1("stamp"); + DPFX2("magic", hdrs.cb_hdr.stamp.magic); + DPFV2("version", "u", hdrs.cb_hdr.stamp.version); + DPFSC1; + DPFV1("nFEs", "u", hdrs.cb_hdr.nFEs); + DPFV1("nCBs", "u", hdrs.cb_hdr.nCBs); + DPFV1("fe_max", "u", hdrs.cb_hdr.fe_max); + DPFV1("cb_max", "u", hdrs.cb_hdr.cb_max); + DPFV1("tfirst", "d", hdrs.cb_hdr.tfirst); + + SplitInt64(hdrs.cb_hdr.timeout_offset, hi, lo); + DPFSO1("timeout_offset"); + DPFV2("hi", "u", hi); + DPFV2("lo", "u", lo); + DPFSC1; + + SplitInt64(hdrs.cb_hdr.fehash_offset, hi, lo); + DPFSO1("fehash_offset"); + DPFV2("hi", "u", hi); + DPFV2("lo", "u", lo); + DPFSC1; + + SplitInt64(hdrs.cb_hdr.fe_offset, hi, lo); + DPFSO1("fe_offset"); + DPFV2("hi", "u", hi); + DPFV2("lo", "u", lo); + DPFSC1; + + DPFSC0; + + if (hdrs.cb_hdr.stamp.magic != CALLBACK_STATE_MAGIC) { + fprintf(stderr, "* magic check failed\n"); + } + if (hdrs.cb_hdr.stamp.version != CALLBACK_STATE_VERSION) { + fprintf(stderr, "* version check failed\n"); + } +} + +static void +dump_cb_timeout(void) +{ + int i; + + if (get_cb_hdr()) + return; + + if (get_cb_timeout_hdr()) + return; + + if (get_cb_timeout()) + return; + + DPFOFF(hdrs.timeout_hdr_p); + DPFSO0("callback_state_timeout_header"); + DPFX1("magic", hdrs.timeout_hdr.magic); + DPFV1("len", "u", hdrs.timeout_hdr.len); + DPFV1("records", "u", hdrs.timeout_hdr.records); + DPFSC0; + + if (hdrs.timeout_hdr.magic != CALLBACK_STATE_TIMEOUT_MAGIC) { + fprintf(stderr, "* magic check failed\n"); + } + + DPFOFF(hdrs.timeout_p); + DPFAO0("timeout"); + for (i = 0; i < 127; i++) { + DPFAE("u", hdrs.timeout[i]); + if ((i % 8) == 7) { + DPFAN; + DPFA1; + } + } + DPFALE("u", hdrs.timeout[127]); + DPFAC0; +} + +static void +dump_cb_fehash(void) +{ + int i; + + if (get_cb_hdr()) + return; + + if (get_cb_fehash_hdr()) + return; + + if (get_cb_fehash()) + return; + + DPFOFF(hdrs.fehash_hdr_p); + DPFSO0("callback_state_fehash_header"); + DPFX1("magic", hdrs.fehash_hdr.magic); + DPFV1("len", "u", hdrs.fehash_hdr.len); + DPFV1("records", "u", hdrs.fehash_hdr.records); + DPFSC0; + + if (hdrs.fehash_hdr.magic != CALLBACK_STATE_FEHASH_MAGIC) { + fprintf(stderr, "* magic check failed\n"); + } + + DPFOFF(hdrs.fehash_p); + DPFAO0("fehash"); + for (i = 0; i < hdrs.fehash_hdr.records - 1; i++) { + DPFAE("u", hdrs.fehash[i]); + if ((i % 8) == 7) { + DPFAN; + DPFA1; + } + } + DPFALE("u", hdrs.fehash[hdrs.fehash_hdr.records-1]); + DPFAC0; +} + +static void +dump_all_hes(void) +{ + int i; + + if (get_h_hdr()) { + fprintf(stderr, "error getting host_state_header\n"); + return; + } + + for (i = 0; i < hdrs.h_hdr.records; i++) { + dump_he(i); + } +} + +static void +dump_all_fes(void) +{ + int i; + + if (get_cb_hdr()) { + fprintf(stderr, "error getting callback_state_header\n"); + return; + } + + for (i = 0; i < hdrs.cb_hdr.nFEs; i++) { + dump_fe(i); + } +} + +static void +dump_all_cbs(void) +{ + int i; + + if (get_fe_hdr()) { + fprintf(stderr, "error getting callback_state_entry_header\n"); + return; + } + + for (i = 0; i < fe_cursor.hdr.nCBs; i++) { + dump_cb(i); + } +} + +static void +dump_he(afs_uint32 idx) +{ + if (get_he(idx)) { + fprintf(stderr, "error getting he %d\n", idx); + return; + } + + DPFOFF(he_cursor.cursor); + dump_he_hdr(); + dump_he_entry(); + dump_he_interfaces(); + dump_he_hcps(); +} + +static void +dump_fe(afs_uint32 idx) +{ + if (get_fe(idx)) { + fprintf(stderr, "error getting fe %d\n", idx); + return; + } + + DPFOFF(fe_cursor.cursor); + dump_fe_hdr(); + dump_fe_entry(); +} + +static void +dump_cb(afs_uint32 idx) +{ + if (get_cb(idx)) { + fprintf(stderr, "error getting cb %d\n", idx); + return; + } + + DPFOFF(cb_cursor.cursor); + dump_cb_entry(); +} + +static void +dump_this_he(void) +{ + dump_he(he_cursor.idx); +} + +static void +dump_this_fe(void) +{ + dump_fe(fe_cursor.idx); +} + +static void +dump_this_cb(void) +{ + dump_cb(cb_cursor.idx); +} + +static void +dump_next_he(void) +{ + if (get_h_hdr()) { + fprintf(stderr, "error getting host_state_header\n"); + return; + } + + if ((he_cursor.idx + 1) >= hdrs.h_hdr.records) { + fprintf(stderr, "no more HEs\n"); + return; + } + + dump_he(he_cursor.idx+1); +} + +static void +dump_next_fe(void) +{ + if (get_cb_hdr()) { + fprintf(stderr, "error getting callback_state_header\n"); + return; + } + + if ((fe_cursor.idx + 1) >= hdrs.cb_hdr.nFEs) { + fprintf(stderr, "no more FEs\n"); + return; + } + + dump_fe(fe_cursor.idx+1); +} + +static void +dump_next_cb(void) +{ + if (get_fe_hdr()) { + fprintf(stderr, "error getting callback_state_entry_header\n"); + return; + } + + if ((cb_cursor.idx + 1) >= fe_cursor.hdr.nCBs) { + fprintf(stderr, "no more CBs\n"); + return; + } + + dump_cb(cb_cursor.idx+1); +} + +static void +dump_prev_he(void) +{ + if (!he_cursor.idx) { + fprintf(stderr, "no more HEs\n"); + return; + } + + dump_he(he_cursor.idx-1); +} + +static void +dump_prev_fe(void) +{ + if (!fe_cursor.idx) { + fprintf(stderr, "no more FEs\n"); + return; + } + + dump_fe(fe_cursor.idx-1); +} + +static void +dump_prev_cb(void) +{ + if (!cb_cursor.idx) { + fprintf(stderr, "no more CBs\n"); + return; + } + + dump_cb(cb_cursor.idx-1); +} + +static void +dump_first_fe(void) +{ + if (get_cb_hdr()) { + fprintf(stderr, "error getting callback_state_header\n"); + return; + } + + if (!hdrs.cb_hdr.nFEs) { + fprintf(stderr, "no FEs present\n"); + return; + } + + dump_fe(0); +} + +static void +dump_first_he(void) +{ + if (get_h_hdr()) { + fprintf(stderr, "error getting host_state_header\n"); + return; + } + + if (!hdrs.h_hdr.records) { + fprintf(stderr, "no HEs present\n"); + return; + } + + dump_he(0); +} + +static void +dump_first_cb(void) +{ + if (get_fe_hdr()) { + fprintf(stderr, "error getting callback_state_entry_header\n"); + return; + } + + if (!fe_cursor.hdr.nCBs) { + fprintf(stderr, "no CBs present\n"); + return; + } + + dump_cb(0); +} + +static void +dump_last_he(void) +{ + if (get_h_hdr()) { + fprintf(stderr, "error getting host_state_header\n"); + return; + } + + if (!hdrs.h_hdr.records) { + fprintf(stderr, "no HEs present\n"); + return; + } + + dump_he(hdrs.h_hdr.records-1); +} + +static void +dump_last_fe(void) +{ + if (get_cb_hdr()) { + fprintf(stderr, "error getting callback_state_header\n"); + return; + } + + if (!hdrs.cb_hdr.nFEs) { + fprintf(stderr, "no FEs present\n"); + return; + } + + dump_fe(hdrs.cb_hdr.nFEs-1); +} + +static void +dump_last_cb(void) +{ + if (get_fe_hdr()) { + fprintf(stderr, "error getting callback_state_entry_header\n"); + return; + } + + if (!fe_cursor.hdr.nCBs) { + fprintf(stderr, "no CBs present\n"); + return; + } + + dump_cb(fe_cursor.hdr.nCBs-1); +} + +static void +dump_he_hdr(void) +{ + DPFSO0("host_state_entry_header"); + DPFX1("magic", he_cursor.hdr.magic); + DPFV1("len", "u", he_cursor.hdr.len); + DPFV1("interfaces", "u", he_cursor.hdr.interfaces); + DPFV1("hcps", "u", he_cursor.hdr.hcps); + DPFSC0; + + if (he_cursor.hdr.magic != HOST_STATE_ENTRY_MAGIC) { + fprintf(stderr, "* magic check failed\n"); + } +} + +static void +dump_he_entry(void) +{ + char hoststr[16]; + DPFSO0("hostDiskEntry"); + DPFS1("host", afs_inet_ntoa_r(he_cursor.he.host, hoststr)); + DPFV1("port", "u", he_cursor.he.port); + DPFX1("hostFlags", he_cursor.he.hostFlags); + DPFV1("Console", "u", he_cursor.he.Console); + DPFV1("hcpsfailed", "u", he_cursor.he.hcpsfailed); + DPFV1("hcps_valid", "u", he_cursor.he.hcps_valid); + if (hdrs.hdr.stats_detailed) { + DPFV1("InSameNetwork", "u", he_cursor.he.InSameNetwork); + } + DPFV1("hcps_len", "u", he_cursor.he.hcps_len); + DPFT1("LastCall", he_cursor.he.LastCall); + DPFT1("ActiveCall", he_cursor.he.ActiveCall); + DPFT1("cpsCall", he_cursor.he.cpsCall); + DPFV1("cblist", "u", he_cursor.he.cblist); + DPFV1("index", "u", he_cursor.he.index); + DPFSC0; +} + +static void +dump_he_interfaces(void) +{ + char temp_str[40]; + struct Interface * ifp; + int len, i; + char hoststr[16]; + + if (!he_cursor.hdr.interfaces) + return; + + len = sizeof(struct Interface) + ((he_cursor.hdr.interfaces-1)*sizeof(struct AddrPort)); + ifp = (struct Interface *) malloc(len); + assert(ifp != NULL); + + memcpy(ifp, he_cursor.ifp, len); + + DPFSO0("Interface"); + DPFV1("numberOfInterfaces", "u", ifp->numberOfInterfaces); + + afsUUID_to_string(&ifp->uuid, temp_str, sizeof(temp_str)); + DPFS1("uuid", temp_str); + for (i = 0; i < he_cursor.hdr.interfaces; i++) { + snprintf(temp_str, sizeof(temp_str), "interface[%d]", i); + DPFSO1(temp_str); + DPFS2("addr", afs_inet_ntoa_r(ifp->interface[i].addr, hoststr)); + DPFV2("port", "u", ifp->interface[i].port); + DPFSC1; + } + + DPFSC0; + + if (he_cursor.hdr.interfaces != ifp->numberOfInterfaces) { + fprintf(stderr, "* interface count mismatch between header and Interface struct\n"); + } + free(ifp); +} + +static void +dump_he_hcps(void) +{ + afs_int32 * hcps; + int len, i; + + if (!he_cursor.hdr.hcps) + return; + + len = (he_cursor.hdr.hcps)*sizeof(afs_uint32); + hcps = (afs_int32 *) malloc(len); + assert(hcps != NULL); + memcpy(hcps, he_cursor.hcps, len); + + DPFSO0("hcps"); + DPFAO1("prlist_val"); + for (i = 0; i < he_cursor.hdr.hcps - 1; i++) { + DPFAE("d", hcps[i]); + if ((i % 8) == 7) { + DPFAN; + DPFA2; + } + } + DPFALE("d", hcps[he_cursor.hdr.hcps-1]); + DPFAC1; + DPFSC0; + free(hcps); +} + +static void +dump_fe_hdr(void) +{ + DPFSO0("callback_state_entry_header"); + DPFX1("magic", fe_cursor.hdr.magic); + DPFV1("len", "u", fe_cursor.hdr.len); + DPFV1("nCBs", "u", fe_cursor.hdr.nCBs); + DPFSC0; + + if (fe_cursor.hdr.magic != CALLBACK_STATE_ENTRY_MAGIC) { + fprintf(stderr, "* magic check failed\n"); + } +} + +static void +dump_fe_entry(void) +{ + DPFSO0("FEDiskEntry"); + DPFSO1("fe"); + DPFV2("vnode", "u", fe_cursor.fe.fe.vnode); + DPFV2("unique", "u", fe_cursor.fe.fe.unique); + DPFV2("volid", "u", fe_cursor.fe.fe.volid); + DPFV2("fnext", "u", fe_cursor.fe.fe.fnext); + DPFV2("ncbs", "u", fe_cursor.fe.fe.ncbs); + DPFV2("firstcb", "u", fe_cursor.fe.fe.firstcb); + DPFV2("status", "u", fe_cursor.fe.fe.status); + DPFSC1; + DPFV1("index", "u", fe_cursor.fe.index); + DPFSC0; +} + +static void +dump_cb_entry(void) +{ + DPFSO0("CBDiskEntry"); + DPFSO1("cb"); + DPFV2("cnext", "u", cb_cursor.cb.cb.cnext); + DPFV2("fhead", "u", cb_cursor.cb.cb.fhead); + DPFV2("thead", "u", (afs_uint32)cb_cursor.cb.cb.thead); + DPFV2("status", "u", (afs_uint32)cb_cursor.cb.cb.status); + DPFV2("hhead", "u", cb_cursor.cb.cb.hhead); + DPFV2("tprev", "u", cb_cursor.cb.cb.tprev); + DPFV2("tnext", "u", cb_cursor.cb.cb.tnext); + DPFV2("hprev", "u", cb_cursor.cb.cb.hprev); + DPFV2("hnext", "u", cb_cursor.cb.cb.hnext); + DPFSC1; + DPFV1("index", "u", cb_cursor.cb.index); + DPFSC0; +} + +#define DPFHMS printf(" ") +#define DPFHS printf(" ") +#define DPFHN(offset) printf("\n%u\t", offset) +#define DPFHD(x) printf("%02X ", x) +#define DPFHE printf("\n") + +static void +hexdump_map(afs_uint32 offset, afs_uint32 len) +{ + int i; + unsigned char * p = (unsigned char *)map; + + if (!len) + return; + + if ((offset + len) > map_len) { + fprintf(stderr, "offset + length exceeds memory map size (%u > %lu)\n", + offset+len, (unsigned long)map_len); + return; + } + + p += offset; + DPFOFF(p); + DPFHN(offset); + + for (i = offset % 16; i > 0; i--) { + DPFHS; + } + + for (i=0; i < len; i++, p++, offset++) { + if (!(offset % 16)) { + DPFHN(offset); + } else if (!(offset % 8)) { + DPFHMS; + } + DPFHD(*p); + } + DPFHE; +} + +static int +get_hdr(void) +{ + if (!hdrs.hdr_valid) { + if (map_len < sizeof(struct fs_state_header)) { + fprintf(stderr, "corrupt state dump: fs_state_header larger than memory map\n"); + return 1; + } + memcpy(&hdrs.hdr, map, sizeof(hdrs.hdr)); + hdrs.hdr_p = map; + hdrs.hdr_valid = 1; + } + return 0; +} + +static int +get_h_hdr(void) +{ + char * buf; + afs_uint32 hi, lo; + + if (hdrs.h_hdr_valid) + return 0; + + if (get_hdr()) + return 1; + + SplitInt64(hdrs.hdr.h_offset, hi, lo); + + if (hi) { + fprintf(stderr, "hi offset bits set in h_offset; can't get host_state_header\n"); + return 1; + } + if ((lo >= map_len) || + ((lo + sizeof(struct host_state_header)) > map_len) || + (lo + sizeof(struct host_state_header) < lo)) { + fprintf(stderr, "h_offset puts host_state_header beyond end of memory map\n"); + return 1; + } + + buf = (char *) map; + buf += lo; + memcpy(&hdrs.h_hdr, buf, sizeof(struct host_state_header)); + hdrs.h_hdr_p = buf; + buf += sizeof(struct host_state_header); + he_cursor.fh = (void *)buf; + return 0; +} + +static int +get_cb_hdr(void) +{ + char * buf; + afs_uint32 hi, lo; + + if (hdrs.cb_hdr_valid) + return 0; + + if (get_hdr()) + return 1; + + SplitInt64(hdrs.hdr.cb_offset, hi, lo); + + if (hi) { + fprintf(stderr, "hi offset bits set in cb_offset; can't get callback_state_header\n"); + return 1; + } + if ((lo >= map_len) || + ((lo + sizeof(struct callback_state_header)) > map_len) || + (lo + sizeof(struct callback_state_header) < lo)) { + fprintf(stderr, "cb_offset puts callback_state_header beyond end of memory map\n"); + return 1; + } + + buf = (char *) map; + buf += lo; + memcpy(&hdrs.cb_hdr, buf, sizeof(struct callback_state_header)); + hdrs.cb_hdr_p = buf; + hdrs.cb_hdr_valid = 1; + + SplitInt64(hdrs.cb_hdr.fe_offset, hi, lo); + + if (hi) { + fprintf(stderr, "hi offset bits set in fe_offset; can't get callback_state_entry_header\n"); + return 1; + } + hi = lo + (hdrs.cb_hdr.nFEs * (sizeof(struct callback_state_entry_header) + + sizeof(struct FEDiskEntry)) + + hdrs.cb_hdr.nCBs * sizeof(struct CBDiskEntry)); + if ((hi > map_len) || + (lo > hi)) { + fprintf(stderr, "fe_offset puts callback_state_entry_header beyond end of memory map\n"); + return 1; + } + + buf = (char *) map; + buf += lo; + fe_cursor.ffe = (void *)buf; + + return 0; +} + +static int +get_cb_timeout_hdr(void) +{ + char * buf; + afs_uint32 hi, lo; + + if (hdrs.timeout_hdr_valid) + return 0; + + if (get_cb_hdr()) + return 1; + + SplitInt64(hdrs.cb_hdr.timeout_offset, hi, lo); + + if (hi) { + fprintf(stderr, "hi offset bits set in timeout_offset; can't get callback_state_timeout_header\n"); + return 1; + } + if ((lo >= map_len) || + ((lo + sizeof(struct callback_state_timeout_header)) > map_len) || + (lo + sizeof(struct callback_state_timeout_header) < lo)) { + fprintf(stderr, "timeout_offset puts callback_state_timeout_header beyond end of memory map\n"); + return 1; + } + + buf = (char *) map; + buf += lo; + memcpy(&hdrs.timeout_hdr, buf, sizeof(struct callback_state_timeout_header)); + hdrs.timeout_hdr_p = buf; + hdrs.timeout_hdr_valid = 1; + buf += sizeof(struct callback_state_timeout_header); + hdrs.timeout_p = buf; + + return 0; +} + +static int +get_cb_timeout(void) +{ + if (hdrs.timeout) + return 0; + + if (get_cb_timeout_hdr()) + return 1; + + hdrs.timeout = (afs_uint32 *) calloc(hdrs.timeout_hdr.records, sizeof(afs_uint32)); + assert(hdrs.timeout != NULL); + memcpy(hdrs.timeout, hdrs.timeout_p, hdrs.timeout_hdr.records * sizeof(afs_uint32)); + return 0; +} + +static int +get_cb_fehash_hdr(void) +{ + char * buf; + afs_uint32 hi, lo; + + if (hdrs.fehash_hdr_valid) + return 0; + + if (get_cb_hdr()) + return 1; + + SplitInt64(hdrs.cb_hdr.fehash_offset, hi, lo); + + if (hi) { + fprintf(stderr, "hi offset bits set in fehash_offset; can't get callback_state_fehash_header\n"); + return 1; + } + if ((lo >= map_len) || + ((lo + sizeof(struct callback_state_fehash_header)) > map_len) || + (lo + sizeof(struct callback_state_fehash_header) < lo)) { + fprintf(stderr, "timeout_offset puts callback_state_fehash_header beyond end of memory map\n"); + return 1; + } + + buf = (char *) map; + buf += lo; + memcpy(&hdrs.fehash_hdr, buf, sizeof(struct callback_state_fehash_header)); + hdrs.fehash_hdr_p = buf; + hdrs.fehash_hdr_valid = 1; + buf += sizeof(struct callback_state_fehash_header); + hdrs.fehash_p = buf; + + return 0; +} + +static int +get_cb_fehash(void) +{ + if (hdrs.fehash) + return 0; + + if (get_cb_fehash_hdr()) + return 1; + + hdrs.fehash = (afs_uint32 *) calloc(hdrs.fehash_hdr.records, sizeof(afs_uint32)); + assert(hdrs.fehash != NULL); + memcpy(hdrs.fehash, hdrs.fehash_p, hdrs.fehash_hdr.records * sizeof(afs_uint32)); + return 0; +} + +static int +get_he(afs_uint32 idx) +{ + int i; + char * p; + + if (get_h_hdr()) + return 1; + + if (idx >= hdrs.h_hdr.records) + return 1; + + if (he_cursor.idx == idx && he_cursor.hdr_valid && he_cursor.he_valid) + return 0; + + he_cursor.hdr_valid = he_cursor.he_valid = 0; + + if (he_cache.cursor == NULL) { + he_cache.cursor = (void **) calloc(hdrs.h_hdr.records, sizeof(void *)); + assert(he_cache.cursor != NULL); + } + + if (idx && he_cache.cursor[idx-1] == NULL) { + for (i = 0; i < idx; i++) { + if (he_cache.cursor[i] == NULL) { + get_he(i); + } + } + } + + if (!idx) { + he_cursor.cursor = he_cursor.fh; + } else if (he_cursor.cursor == he_cache.cursor[idx-1]) { + p = (char *)he_cursor.cursor; + p += he_cursor.hdr.len; + he_cursor.cursor = (void *)p; + } else { + he_cursor.cursor = he_cache.cursor[idx-1]; + if (get_he_hdr()) + return 1; + p = (char *)he_cursor.cursor; + p += he_cursor.hdr.len; + he_cursor.cursor = (void *)p; + } + + he_cursor.idx = idx; + he_cache.cursor[idx] = he_cursor.cursor; + + if (get_he_hdr()) + return 1; + if (get_he_entry()) + return 1; + + return 0; +} + +static int +get_he_hdr(void) +{ + memcpy(&he_cursor.hdr, he_cursor.cursor, sizeof(struct host_state_entry_header)); + he_cursor.hdr_valid = 1; + return 0; +} + +static int +get_he_entry(void) +{ + char * p; + + if (!he_cursor.hdr_valid) { + if (get_he_hdr()) { + return 1; + } + } + + p = (char *) he_cursor.cursor; + p += sizeof(struct host_state_entry_header); + + memcpy(&he_cursor.he, p, sizeof(struct hostDiskEntry)); + + he_cursor.he_valid = 1; + p += sizeof(struct hostDiskEntry); + he_cursor.ifp = (void *)p; + if (he_cursor.hdr.interfaces) { + p += sizeof(struct Interface) + ((he_cursor.hdr.interfaces-1)*sizeof(struct AddrPort)); + he_cursor.hcps = (void *)p; + } else { + he_cursor.hcps = he_cursor.ifp; + } + return 0; +} + +static int +get_fe(afs_uint32 idx) +{ + int i; + char * p; + + cb_cursor.cb_valid = 0; + + if (get_cb_hdr()) + return 1; + + if (idx >= hdrs.cb_hdr.nFEs) + return 1; + + if (fe_cursor.idx == idx && fe_cursor.hdr_valid && fe_cursor.fe_valid) + return 0; + + fe_cursor.hdr_valid = fe_cursor.fe_valid = 0; + + if (fe_cache.cursor == NULL) { + fe_cache.cursor = (void **) calloc(hdrs.cb_hdr.nFEs, sizeof(void *)); + assert(fe_cache.cursor != NULL); + } + + if (idx && fe_cache.cursor[idx-1] == NULL) { + for (i = 0; i < idx; i++) { + if (fe_cache.cursor[i] == NULL) { + get_fe(i); + } + } + } + + if (!idx) { + fe_cursor.cursor = fe_cursor.ffe; + } else if (fe_cursor.cursor == fe_cache.cursor[idx-1]) { + p = (char *)fe_cursor.cursor; + p += fe_cursor.hdr.len; + fe_cursor.cursor = (void *)p; + } else { + fe_cursor.cursor = fe_cache.cursor[idx-1]; + if (get_fe_hdr()) + return 1; + p = (char *)fe_cursor.cursor; + p += fe_cursor.hdr.len; + fe_cursor.cursor = (void *)p; + } + + fe_cursor.idx = idx; + fe_cache.cursor[idx] = fe_cursor.cursor; + + if (get_fe_hdr()) + return 1; + if (get_fe_entry()) + return 1; + + return 0; +} + +static int +get_fe_hdr(void) +{ + if (!fe_cursor.cursor) { + if(get_fe(fe_cursor.idx)) { + return 1; + } + } + + memcpy(&fe_cursor.hdr, fe_cursor.cursor, sizeof(struct callback_state_entry_header)); + fe_cursor.hdr_valid = 1; + return 0; +} + +static int +get_fe_entry(void) +{ + char * p; + + if (!fe_cursor.hdr_valid) { + if (get_fe_hdr()) { + return 1; + } + } + + p = (char *) fe_cursor.cursor; + p += sizeof(struct callback_state_entry_header); + + memcpy(&fe_cursor.fe, p, sizeof(struct FEDiskEntry)); + + fe_cursor.fe_valid = 1; + p += sizeof(struct FEDiskEntry); + fe_cursor.fcb = (void *)p; + return 0; +} + +static int +get_cb(afs_uint32 idx) +{ + char * p; + + if (get_fe(fe_cursor.idx)) + return 1; + + if (idx >= fe_cursor.hdr.nCBs) + return 1; + + if (idx == cb_cursor.idx && cb_cursor.cb_valid) + return 0; + + cb_cursor.cb_valid = 0; + + p = (char *)fe_cursor.fcb; + p += idx * sizeof(struct CBDiskEntry); + cb_cursor.cursor = (void *)p; + + cb_cursor.idx = idx; + + if (get_cb_entry()) + return 1; + + return 0; +} + +static int +get_cb_entry(void) +{ + memcpy(&cb_cursor.cb, cb_cursor.cursor, sizeof(struct CBDiskEntry)); + cb_cursor.cb_valid = 1; + return 0; +} + +#if 0 +static int +find_he_by_index(afs_uint32 idx) +{ + int i; + + if (get_h_hdr()) { + return 1; + } + + for (i = 0; i < hdrs.h_hdr.records; i++) { + if (get_he(i)) { + fprintf(stderr, "error getting he %d\n", i); + return 1; + } + if (he_cursor.he.index == idx) + break; + } + + if (i < hdrs.h_hdr.records) { + dump_this_he(); + return 0; + } + return 1; +} +#endif + +static int +find_fe_by_index(afs_uint32 idx) +{ + int i; + + if (get_cb_hdr()) { + return 1; + } + + for (i = 0; i < hdrs.cb_hdr.nFEs; i++) { + if (get_fe(i)) { + fprintf(stderr, "error getting fe %d\n", i); + return 1; + } + if (fe_cursor.fe.index == idx) + break; + } + + if (i < hdrs.cb_hdr.nFEs) { + dump_this_fe(); + return 0; + } + return 1; +} + +static int +find_fe_by_fid(afs_uint32 volid, afs_uint32 vnode, afs_uint32 unique) +{ + int i; + + if (get_cb_hdr()) { + return 1; + } + + for (i = 0; i < hdrs.cb_hdr.nFEs; i++) { + if (get_fe(i)) { + fprintf(stderr, "error getting fe %d\n", i); + return 1; + } + if ((fe_cursor.fe.fe.unique == unique) && + (fe_cursor.fe.fe.volid == volid) && + (fe_cursor.fe.fe.vnode == vnode)) + break; + } + + if (i < hdrs.cb_hdr.nFEs) { + dump_this_fe(); + return 0; + } + return 1; +} + +static int +find_cb_by_index(afs_uint32 idx) +{ + int i; + + if (get_fe_hdr()) { + return 1; + } + + for (i = 0; i < fe_cursor.hdr.nCBs; i++) { + if (get_cb(i)) { + fprintf(stderr, "error getting cb %d\n", i); + return 1; + } + if (cb_cursor.cb.index == idx) + break; + } + + if (i < fe_cursor.hdr.nCBs) { + dump_this_cb(); + return 0; + } + return 1; +} + +#endif /* AFS_DEMAND_ATTACH_FS */ diff --git a/src/viced/viced.c b/src/viced/viced.c index da464fe08..f150d25f4 100644 --- a/src/viced/viced.c +++ b/src/viced/viced.c @@ -73,9 +73,7 @@ #include "viced_prototypes.h" #include "viced.h" #include "host.h" -#ifdef AFS_PTHREAD_ENV -# include -#endif +#include #if defined(AFS_SGI_ENV) # include "sys/schedctl.h" # include "sys/lock.h" @@ -96,12 +94,8 @@ static afs_int32 Do_VLRegisterRPC(void); int eventlog = 0, rxlog = 0; FILE *debugFile; -#ifdef AFS_PTHREAD_ENV pthread_mutex_t fsync_glock_mutex; pthread_cond_t fsync_cond; -#else -char fsync_wait[1]; -#endif /* AFS_PTHREAD_ENV */ #ifdef AFS_NT40_ENV # define NT_OPEN_MAX 1024 /* This is an arbitrary no. we came up with for @@ -177,9 +171,7 @@ static int offline_shutdown_timeout = -1; /* -offline-shutdown-timeout option */ struct timeval tp; -#ifdef AFS_PTHREAD_ENV pthread_key_t viced_uclient_key; -#endif /* * FileServer's name and IP address, both network byte order and @@ -269,7 +261,6 @@ CheckDescriptors(void *unused) } /*CheckDescriptors */ -#ifdef AFS_PTHREAD_ENV void CheckSignal_Signal(int x) { @@ -287,25 +278,6 @@ CheckDescriptors_Signal(int x) { CheckDescriptors(NULL); } -#else /* AFS_PTHREAD_ENV */ -void -CheckSignal_Signal(int x) -{ - IOMGR_SoftSig(CheckSignal, 0); -} - -void -ShutDown_Signal(int x) -{ - IOMGR_SoftSig(ShutDown, 0); -} - -void -CheckDescriptors_Signal(int x) -{ - IOMGR_SoftSig(CheckDescriptors, 0); -} -#endif /* AFS_PTHREAD_ENV */ /* check whether caller is authorized to manage RX statistics */ int @@ -327,7 +299,7 @@ ResetCheckSignal(void) signo = SIGXCPU; #endif -#if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV) +#if !defined(AFS_NT40_ENV) softsig_signal(signo, CheckSignal_Signal); #else signal(signo, CheckSignal_Signal); @@ -338,11 +310,7 @@ static void ResetCheckDescriptors(void) { #ifndef AFS_NT40_ENV -# if defined(AFS_PTHREAD_ENV) softsig_signal(SIGTERM, CheckDescriptors_Signal); -# else - (void)signal(SIGTERM, CheckDescriptors_Signal); -# endif #endif } @@ -395,7 +363,7 @@ CheckAdminName(void) static void setThreadId(char *s) { -#if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV) +#if !defined(AFS_NT40_ENV) int threadId; /* set our 'thread-id' so that the host hold table works */ @@ -424,11 +392,7 @@ FiveMinuteCheckLWP(void *unused) while (1) { #endif -#ifdef AFS_PTHREAD_ENV sleep(fiveminutes); -#else /* AFS_PTHREAD_ENV */ - IOMGR_Sleep(fiveminutes); -#endif /* AFS_PTHREAD_ENV */ #ifdef AFS_DEMAND_ATTACH_FS FS_STATE_WRLOCK; @@ -449,9 +413,6 @@ FiveMinuteCheckLWP(void *unused) if (FS_registered == 1) Do_VLRegisterRPC(); /* Force wakeup in case we missed something; pthreads does timedwait */ -#ifndef AFS_PTHREAD_ENV - LWP_NoYieldSignal(fsync_wait); -#endif if (printBanner && (++msg & 1)) { /* Every 10 minutes */ time_t now = FT_ApproxTime(); struct tm tm; @@ -494,11 +455,7 @@ HostCheckLWP(void *unused) while(1) { #endif -#ifdef AFS_PTHREAD_ENV sleep(fiveminutes); -#else /* AFS_PTHREAD_ENV */ - IOMGR_Sleep(fiveminutes); -#endif /* AFS_PTHREAD_ENV */ #ifdef AFS_DEMAND_ATTACH_FS FS_STATE_WRLOCK; @@ -534,9 +491,7 @@ static void * FsyncCheckLWP(void *unused) { afs_int32 code; -#ifdef AFS_PTHREAD_ENV struct timespec fsync_next; -#endif ViceLog(1, ("Starting fsync check process\n")); setThreadId("FsyncCheckLWP"); @@ -550,7 +505,6 @@ FsyncCheckLWP(void *unused) while(1) { #endif FSYNC_LOCK; -#ifdef AFS_PTHREAD_ENV /* rounding is fine */ fsync_next.tv_nsec = 0; fsync_next.tv_sec = time(0) + fiveminutes; @@ -559,10 +513,6 @@ FsyncCheckLWP(void *unused) &fsync_next); if (code != 0 && code != ETIMEDOUT) ViceLog(0, ("pthread_cond_timedwait returned %d\n", code)); -#else /* AFS_PTHREAD_ENV */ - if ((code = LWP_WaitProcess(fsync_wait)) != LWP_SUCCESS) - ViceLog(0, ("LWP_WaitProcess returned %d\n", code)); -#endif /* AFS_PTHREAD_ENV */ FSYNC_UNLOCK; #ifdef AFS_DEMAND_ATTACH_FS @@ -757,17 +707,10 @@ ShutDownAndCore(int dopanic) char tbuffer[32]; if (dopanic) { -#ifdef AFS_PTHREAD_ENV pthread_t watchdogPid; pthread_attr_t tattr; osi_Assert(pthread_attr_init(&tattr) == 0); osi_Assert(pthread_create(&watchdogPid, &tattr, ShutdownWatchdogLWP, NULL) == 0); -#else - PROCESS watchdogPid; - osi_Assert(LWP_CreateProcess - (ShutdownWatchdogLWP, stack * 1024, LWP_MAX_PRIORITY - 2, - NULL, "ShutdownWatchdog", &watchdogPid) == LWP_SUCCESS); -#endif } /* do not allows new reqests to be served from now on, all new requests @@ -943,13 +886,13 @@ ParseRights(char *arights) static int max_fileserver_thread(void) { -#if defined(AFS_PTHREAD_ENV) && (defined(AFS_AIX_ENV) || defined(AFS_HPUX_ENV)) +#if defined(AFS_AIX_ENV) || defined(AFS_HPUX_ENV) long ans; ans = sysconf(_SC_THREAD_THREADS_MAX); if (0 < ans && ans < MAX_FILESERVER_THREAD) return (int)ans; -#endif /* defined(AFS_PTHREAD_ENV) */ +#endif return MAX_FILESERVER_THREAD; } @@ -1081,10 +1024,8 @@ ParseArgs(int argc, char *argv[]) cmd_AddParmAtOffset(opts, OPT_hostcpsrefresh, "-hr", CMD_SINGLE, CMD_OPTIONAL, "hours between host CPS refreshes"); -#if defined(AFS_PTHREAD_ENV) cmd_AddParmAtOffset(opts, OPT_vattachthreads, "-vattachpar", CMD_SINGLE, CMD_OPTIONAL, "# of volume attachment threads"); -#endif cmd_AddParmAtOffset(opts, OPT_abortthreshold, "-abortthreshold", CMD_SINGLE, CMD_OPTIONAL, @@ -1289,9 +1230,7 @@ ParseArgs(int argc, char *argv[]) hostaclRefresh = optval * 60 * 60; } -#ifdef AFS_PTHREAD_ENV cmd_OptionAsInt(opts, OPT_vattachthreads, &vol_attach_threads); -#endif /* AFS_PTHREAD_ENV */ cmd_OptionAsInt(opts, OPT_abortthreshold, &abort_threshold); @@ -1300,13 +1239,6 @@ ParseArgs(int argc, char *argv[]) busyonrst = 0; if (cmd_OptionAsInt(opts, OPT_offline_timeout, &offline_timeout) == 0) { -#ifndef AFS_PTHREAD_ENV - if (offline_timeout != -1) { - printf("The only valid -offline-timeout value for the LWP " - "fileserver is -1\n"); - return -1; - } -#endif /* AFS_PTHREAD_ENV */ if (offline_timeout < -1) { printf("Invalid -offline-timeout value %d; the only valid " "negative value is -1\n", offline_timeout); @@ -1316,13 +1248,6 @@ ParseArgs(int argc, char *argv[]) if (cmd_OptionAsInt(opts, OPT_offline_shutdown_timeout, &offline_shutdown_timeout) == 0) { -#ifndef AFS_PTHREAD_ENV - if (offline_shutdown_timeout != -1) { - printf("The only valid -offline-shutdown-timeout value for the " - "LWP fileserver is -1\n"); - return -1; - } -#endif /* AFS_PTHREAD_ENV */ if (offline_shutdown_timeout < -1) { printf("Invalid -offline-timeout value %d; the only valid " "negative value is -1\n", offline_shutdown_timeout); @@ -1520,9 +1445,7 @@ InitPR(void) return code; } -#ifdef AFS_PTHREAD_ENV osi_Assert(pthread_key_create(&viced_uclient_key, NULL) == 0); -#endif SystemId = SYSADMINID; SystemAnyUser = ANYUSERID; @@ -1548,11 +1471,7 @@ InitPR(void) AnonymousID = ANONYMOUSID; return 0; sleep: -#ifdef AFS_PTHREAD_ENV sleep(30); -#else /* AFS_PTHREAD_ENV */ - IOMGR_Sleep(30); -#endif /* AFS_PTHREAD_ENV */ } } /*InitPR */ @@ -1866,12 +1785,8 @@ main(int argc, char *argv[]) struct rx_securityClass **securityClasses; afs_int32 numClasses; struct rx_service *tservice; -#ifdef AFS_PTHREAD_ENV pthread_t serverPid; pthread_attr_t tattr; -#else /* AFS_PTHREAD_ENV */ - PROCESS parentPid, serverPid; -#endif /* AFS_PTHREAD_ENV */ struct hostent *he; int minVnodesRequired; /* min size of vnode cache */ #ifndef AFS_NT40_ENV @@ -1912,9 +1827,7 @@ main(int argc, char *argv[]) if (ParseArgs(argc, argv)) { exit(-1); } -#ifdef AFS_PTHREAD_ENV MUTEX_INIT(&fileproc_glock_mutex, "fileproc", MUTEX_DEFAULT, 0); -#endif /* AFS_PTHREAD_ENV */ #ifdef AFS_SGI_VNODE_GLUE if (afs_init_kernel_config(-1) < 0) { @@ -1939,7 +1852,7 @@ main(int argc, char *argv[]) LogCommandLine(argc, argv, "starting", "", "File server", FSLog); -#if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV) +#if !defined(AFS_NT40_ENV) /* initialize the pthread soft signal handler thread */ softsig_init(); #endif @@ -2008,19 +1921,13 @@ main(int argc, char *argv[]) ("The system supports a max of %d open files and we are starting %d threads (ihandle fd cache is %d)\n", curLimit, lwps, vol_io_params.fd_max_cachesize)); } -#ifndef AFS_PTHREAD_ENV - osi_Assert(LWP_InitializeProcessSupport(LWP_MAX_PRIORITY - 2, &parentPid) == - LWP_SUCCESS); -#endif /* !AFS_PTHREAD_ENV */ /* Initialize volume support */ if (!novbc) { V_BreakVolumeCallbacks = BreakVolumeCallBacksLater; } -#ifdef AFS_PTHREAD_ENV SetLogThreadNumProgram( rx_GetThreadNum ); -#endif /* initialize libacl routines */ acl_Initialize(ACL_VERSION); @@ -2202,7 +2109,7 @@ main(int argc, char *argv[]) /* Install handler to catch the shutdown signal; * bosserver assumes SIGQUIT shutdown */ -#if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV) +#if !defined(AFS_NT40_ENV) softsig_signal(SIGQUIT, ShutDown_Signal); #else (void)signal(SIGQUIT, ShutDown_Signal); @@ -2231,7 +2138,6 @@ main(int argc, char *argv[]) */ ih_UseLargeCache(); -#ifdef AFS_PTHREAD_ENV ViceLog(5, ("Starting pthreads\n")); osi_Assert(pthread_attr_init(&tattr) == 0); osi_Assert(pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED) == 0); @@ -2243,20 +2149,6 @@ main(int argc, char *argv[]) (&serverPid, &tattr, HostCheckLWP, &fiveminutes) == 0); osi_Assert(pthread_create (&serverPid, &tattr, FsyncCheckLWP, &fiveminutes) == 0); -#else /* AFS_PTHREAD_ENV */ - ViceLog(5, ("Starting LWP\n")); - osi_Assert(LWP_CreateProcess - (FiveMinuteCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2, - (void *)&fiveminutes, "FiveMinuteChecks", - &serverPid) == LWP_SUCCESS); - - osi_Assert(LWP_CreateProcess - (HostCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2, - (void *)&fiveminutes, "HostCheck", &serverPid) == LWP_SUCCESS); - osi_Assert(LWP_CreateProcess - (FsyncCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2, - (void *)&fiveminutes, "FsyncCheck", &serverPid) == LWP_SUCCESS); -#endif /* AFS_PTHREAD_ENV */ FT_GetTimeOfDay(&tp, 0); @@ -2289,12 +2181,8 @@ main(int argc, char *argv[]) localtime_r(&t, &tm)); ViceLog(0, ("File Server started %s\n", tbuffer)); afs_FullPerfStats.det.epoch.tv_sec = StartTime = tp.tv_sec; -#ifdef AFS_PTHREAD_ENV while (1) { sleep(1000); /* long time */ } -#else /* AFS_PTHREAD_ENV */ - osi_Assert(LWP_WaitProcess(&parentPid) == LWP_SUCCESS); -#endif /* AFS_PTHREAD_ENV */ return 0; } diff --git a/src/viced/viced.h b/src/viced/viced.h index 3db60784a..64a03d4b3 100644 --- a/src/viced/viced.h +++ b/src/viced/viced.h @@ -193,7 +193,6 @@ extern int saneacls; #define MAX_FILESERVER_THREAD 16384 /* max number of threads in fileserver */ #define FILESERVER_HELPER_THREADS 8 /* Listner, IOMGR, FiveMinute, FsyncCk * HostCheck, Signal, min 2 for RXSTATS */ -#ifdef AFS_PTHREAD_ENV #include extern pthread_mutex_t fileproc_glock_mutex; #define FS_LOCK MUTEX_ENTER(&fileproc_glock_mutex); @@ -201,12 +200,6 @@ extern pthread_mutex_t fileproc_glock_mutex; extern pthread_mutex_t fsync_glock_mutex; #define FSYNC_LOCK MUTEX_ENTER(&fsync_glock_mutex); #define FSYNC_UNLOCK MUTEX_EXIT(&fsync_glock_mutex); -#else /* AFS_PTHREAD_ENV */ -#define FS_LOCK -#define FS_UNLOCK -#define FSYNC_LOCK -#define FSYNC_UNLOCK -#endif /* AFS_PTHREAD_ENV */ #ifdef AFS_DEMAND_ATTACH_FS diff --git a/tests/volser/Makefile.in b/tests/volser/Makefile.in index c859f39d2..dc495f71c 100644 --- a/tests/volser/Makefile.in +++ b/tests/volser/Makefile.in @@ -10,13 +10,13 @@ MODULE_CFLAGS=-I$(srcdir)/.. -I$(srcdir)/../common/ all check test tests: $(TESTS) -# The direct reference of tviced libraries here is a colossal hack, but +# The direct reference of viced libraries here is a colossal hack, but # we're just not building pthreaded versions of the vldb interface at the moment. # Soon, I hope ... MODULE_LIBS = ../tap/libtap.a \ - $(abs_top_builddir)/src/tviced/vldbint.cs.o \ - $(abs_top_builddir)/src/tviced/vldbint.xdr.o \ + $(abs_top_builddir)/src/viced/vldbint.cs.o \ + $(abs_top_builddir)/src/viced/vldbint.xdr.o \ $(abs_top_builddir)/lib/libafsauthent.a \ $(abs_top_builddir)/lib/libafsrpc.a \ $(abs_top_builddir)/lib/libafshcrypto.a \