From 21cbf7fee0a089d94f62baa7df2422e7bc8293f7 Mon Sep 17 00:00:00 2001 From: Derrick Brashear Date: Wed, 20 Jan 2010 11:15:29 -0500 Subject: [PATCH] simplify ufs cache mechanisms available instead of having use_fh for linux, vnode_path for solaris and darwin, use the same mechanism for both. for darwin/solaris we cache the path (tested via gop_lookupname) instead of an fh, freeing the path at shutdown. Change-Id: Id22052db0803264bdaba6b870d9e511953e348bc Reviewed-on: http://gerrit.openafs.org/1132 Tested-by: Derrick Brashear Reviewed-by: Derrick Brashear --- src/afs/DARWIN/osi_file.c | 21 +++--------------- src/afs/SOLARIS/osi_file.c | 38 ++++++++++---------------------- src/afs/afs.h | 4 +++- src/afs/afs_call.c | 45 ++------------------------------------ src/afs/afs_cell.c | 5 +++++ src/afs/afs_dcache.c | 14 +++++++++++- src/afs/afs_init.c | 20 ++++++++++------- src/afsd/afsd.c | 23 +------------------ 8 files changed, 50 insertions(+), 120 deletions(-) diff --git a/src/afs/DARWIN/osi_file.c b/src/afs/DARWIN/osi_file.c index 3edd4967f..ca1976fcc 100644 --- a/src/afs/DARWIN/osi_file.c +++ b/src/afs/DARWIN/osi_file.c @@ -156,26 +156,11 @@ osi_UFSOpen(afs_dcache_id_t *ainode) afile = (struct osi_file *)osi_AllocSmallSpace(sizeof(struct osi_file)); AFS_GUNLOCK(); #ifdef AFS_CACHE_VNODE_PATH - if (ainode->ufs < 0) { - switch (ainode->ufs) { - case AFS_CACHE_CELLS_INODE: - snprintf(fname, 1024, "%s/%s", afs_cachebasedir, "CellItems"); - break; - case AFS_CACHE_ITEMS_INODE: - snprintf(fname, 1024, "%s/%s", afs_cachebasedir, "CacheItems"); - break; - case AFS_CACHE_VOLUME_INODE: - snprintf(fname, 1024, "%s/%s", afs_cachebasedir, "VolumeItems"); - break; - default: - osi_Panic("Invalid negative inode"); - } - } else { - dummy = ainode->ufs / afs_numfilesperdir; - snprintf(fname, 1024, "%s/D%d/V%d", afs_cachebasedir, dummy, ainode->ufs); + if (!ainode->ufs) { + osi_Panic("No cache inode\n"); } - code = vnode_open(fname, O_RDWR, 0, 0, &vp, afs_osi_ctxtp); + code = vnode_open(ainode->ufs, O_RDWR, 0, 0, &vp, afs_osi_ctxtp); #else #ifndef AFS_DARWIN80_ENV if (afs_CacheFSType == AFS_APPL_HFS_CACHE) diff --git a/src/afs/SOLARIS/osi_file.c b/src/afs/SOLARIS/osi_file.c index 5b18303aa..04f4eb0ce 100644 --- a/src/afs/SOLARIS/osi_file.c +++ b/src/afs/SOLARIS/osi_file.c @@ -175,7 +175,6 @@ osi_UfsOpen(afs_dcache_id_t *ainode) register struct osi_file *afile = NULL; afs_int32 code = 0; int dummy; - char fname[1024]; #ifdef AFS_CACHE_VNODE_PATH char namebuf[1024]; struct pathname lookpn; @@ -186,38 +185,23 @@ osi_UfsOpen(afs_dcache_id_t *ainode) /* * AFS_CACHE_VNODE_PATH can be used with any file system, including ZFS or tmpfs. - * The ainode is not an inode number but a signed index used to generate file names. + * The ainode is not an inode number but a path. */ #ifdef AFS_CACHE_VNODE_PATH - switch (ainode->ufs) { - case AFS_CACHE_CELLS_INODE: - snprintf(fname, 1024, "%s/%s", afs_cachebasedir, "CellItems"); - break; - case AFS_CACHE_ITEMS_INODE: - snprintf(fname, 1024, "%s/%s", afs_cachebasedir, "CacheItems"); - break; - case AFS_CACHE_VOLUME_INODE: - snprintf(fname, 1024, "%s/%s", afs_cachebasedir, "VolumeItems"); - break; - default: - dummy = ainode->ufs / afs_numfilesperdir; - snprintf(fname, 1024, "%s/D%d/V%d", afs_cachebasedir, dummy, ainode->ufs); - } - /* Can not use vn_open or lookupname, they use user's CRED() - * We need to run as root So must use low level lookuppnvp - * assume fname starts with / + * We need to run as root So must use low level lookuppnvp + * assume fname starts with / */ - code = pn_get_buf(fname, AFS_UIOSYS, &lookpn, namebuf, sizeof(namebuf)); + code = pn_get_buf(ainode->ufs, AFS_UIOSYS, &lookpn, namebuf, sizeof(namebuf)); if (code != 0) - osi_Panic("UfsOpen: pn_get_buf failed %ld %s %ld", code, fname, ainode->ufs); + osi_Panic("UfsOpen: pn_get_buf failed %ld %s", code, ainode->ufs); VN_HOLD(rootdir); /* released in loopuppnvp */ code = lookuppnvp(&lookpn, NULL, FOLLOW, NULL, &vp, rootdir, rootdir, &afs_osi_cred); if (code != 0) - osi_Panic("UfsOpen: lookuppnvp failed %ld %s %ld", code, fname, ainode->ufs); + osi_Panic("UfsOpen: lookuppnvp failed %ld %s", code, ainode->ufs); #ifdef AFS_SUN511_ENV code = VOP_OPEN(&vp, FREAD|FWRITE, &afs_osi_cred, NULL); @@ -226,7 +210,7 @@ osi_UfsOpen(afs_dcache_id_t *ainode) #endif if (code != 0) - osi_Panic("UfsOpen: VOP_OPEN failed %ld %s %ld", code, fname, ainode->ufs); + osi_Panic("UfsOpen: VOP_OPEN failed %ld %s", code, ainode->ufs); #else code = @@ -236,12 +220,12 @@ osi_UfsOpen(afs_dcache_id_t *ainode) AFS_GLOCK(); if (code) { osi_FreeSmallSpace(afile); - osi_Panic("UfsOpen: igetinode failed %ld %s %ld", code, fname, ainode->ufs); + osi_Panic("UfsOpen: igetinode failed %ld %s", code, ainode->ufs); } #ifdef AFS_CACHE_VNODE_PATH - afile->vnode = vp; - code = afs_osi_Stat(afile, &tstat); - afile->size = tstat.size; + afile->vnode = vp; + code = afs_osi_Stat(afile, &tstat); + afile->size = tstat.size; #else afile->vnode = ITOV(ip); afile->size = VTOI(afile->vnode)->i_size; diff --git a/src/afs/afs.h b/src/afs/afs.h index 04e62f0c8..0164774f0 100644 --- a/src/afs/afs.h +++ b/src/afs/afs.h @@ -1039,7 +1039,9 @@ struct afs_fheader { afs_int32 otherCSize; }; -#if defined(AFS_CACHE_VNODE_PATH) || defined(UKERNEL) +#if defined(AFS_CACHE_VNODE_PATH) +typedef char *afs_ufs_dcache_id_t; +#elif defined(UKERNEL) typedef afs_int32 afs_ufs_dcache_id_t; #elif defined(AFS_SGI61_ENV) || defined(AFS_SUN57_64BIT_ENV) /* Using ino64_t here so that user level debugging programs compile diff --git a/src/afs/afs_call.c b/src/afs/afs_call.c index f7bfa4511..3f1e45909 100644 --- a/src/afs/afs_call.c +++ b/src/afs/afs_call.c @@ -464,18 +464,6 @@ afs_DaemonOp(long parm, long parm2, long parm3, long parm4, long parm5, } #endif -static void -wait_for_cachedefs(void) { -#ifdef AFS_CACHE_VNODE_PATH - if (cacheDiskType != AFS_FCACHE_TYPE_MEM) - while ((afs_numcachefiles < 1) || (afs_numfilesperdir < 1) || - (afs_cachebasedir[0] != '/')) { - printf("afs: waiting for cache parameter definitions\n"); - afs_osi_Sleep(&afs_initState); - } -#endif -} - #ifdef AFS_DARWIN100_ENV #define AFSKPTR(X) k ## X int @@ -861,8 +849,7 @@ afs_syscall_call(long parm, long parm2, long parm3, } else code = 0; } else if (parm == AFSOP_CACHEFILE || parm == AFSOP_CACHEINFO - || parm == AFSOP_VOLUMEINFO || parm == AFSOP_AFSLOG - || parm == AFSOP_CELLINFO || parm == AFSOP_CACHEBASEDIR) { + || parm == AFSOP_VOLUMEINFO || parm == AFSOP_CELLINFO) { char *tbuffer = osi_AllocSmallSpace(AFS_SMALLOCSIZ); code = 0; @@ -878,21 +865,13 @@ afs_syscall_call(long parm, long parm2, long parm3, #ifdef AFS_DARWIN80_ENV get_vfs_context(); #endif - if (parm == AFSOP_CACHEBASEDIR) { - strncpy(afs_cachebasedir, tbuffer, 1024); - afs_cachebasedir[1023] = '\0'; - afs_osi_Wakeup(&afs_initState); - } else if (parm == AFSOP_CACHEFILE) { - wait_for_cachedefs(); + if (parm == AFSOP_CACHEFILE) { code = afs_InitCacheFile(tbuffer, 0); } else if (parm == AFSOP_CACHEINFO) { - wait_for_cachedefs(); code = afs_InitCacheInfo(tbuffer); } else if (parm == AFSOP_VOLUMEINFO) { - wait_for_cachedefs(); code = afs_InitVolumeInfo(tbuffer); } else if (parm == AFSOP_CELLINFO) { - wait_for_cachedefs(); code = afs_InitCellInfo(tbuffer); } #ifdef AFS_DARWIN80_ENV @@ -901,26 +880,6 @@ afs_syscall_call(long parm, long parm2, long parm3, } osi_FreeSmallSpace(tbuffer); } else if (parm == AFSOP_GO) { -#ifdef AFS_CACHE_VNODE_PATH - if (cacheDiskType != AFS_FCACHE_TYPE_MEM) { - afs_int32 dummy; - - wait_for_cachedefs(); - -#ifdef AFS_DARWIN80_ENV - get_vfs_context(); -#endif - if ((afs_numcachefiles > 0) && (afs_numfilesperdir > 0) && - (afs_cachebasedir[0] == '/')) { - for (dummy = 0; dummy < afs_numcachefiles; dummy++) { - code = afs_InitCacheFile(NULL, dummy); - } - } -#ifdef AFS_DARWIN80_ENV - put_vfs_context(); -#endif - } -#endif /* the generic initialization calls come here. One parameter: should we do the * set-time operation on this workstation */ if (afs_Go_Done) diff --git a/src/afs/afs_cell.c b/src/afs/afs_cell.c index c228136c3..3fecdd59d 100644 --- a/src/afs/afs_cell.c +++ b/src/afs/afs_cell.c @@ -1053,6 +1053,11 @@ shutdown_cell(void) struct afs_q *cq, *tq; struct cell *tc; +#ifdef AFS_CACHE_VNODE_PATH + if (cacheDiskType != AFS_FCACHE_TYPE_MEM) { + afs_osi_FreeStr(afs_cellname_inode.ufs); + } +#endif AFS_RWLOCK_INIT(&afs_xcell, "afs_xcell"); for (cq = CellLRU.next; cq != &CellLRU; cq = tq) { diff --git a/src/afs/afs_dcache.c b/src/afs/afs_dcache.c index 0481b2974..32a4da09f 100644 --- a/src/afs/afs_dcache.c +++ b/src/afs/afs_dcache.c @@ -2884,7 +2884,7 @@ afs_InitCacheFile(char *afile, ino_t ainode) } } else { /* Add any other 'complex' inode types here ... */ -#if defined(UKERNEL) || !defined(LINUX_USE_FH) +#if defined(UKERNEL) || !(defined(LINUX_USE_FH) || defined(AFS_CACHE_VNODE_PATH)) tdc->f.inode.ufs = ainode; #else osi_Panic("Can't init cache with inode numbers when complex inodes are " @@ -3121,6 +3121,18 @@ shutdown_dcache(void) { int i; +#ifdef AFS_CACHE_VNODE_PATH + if (cacheDiskType != AFS_FCACHE_TYPE_MEM) { + struct dcache *tdc; + for (i = 0; i < afs_cacheFiles; i++) { + tdc = afs_indexTable[i]; + if (tdc) { + afs_osi_FreeStr(tdc->f.inode.ufs); + } + } + } +#endif + afs_osi_Free(afs_dvnextTbl, afs_cacheFiles * sizeof(afs_int32)); afs_osi_Free(afs_dcnextTbl, afs_cacheFiles * sizeof(afs_int32)); afs_osi_Free(afs_indexTable, afs_cacheFiles * sizeof(struct dcache *)); diff --git a/src/afs/afs_init.c b/src/afs/afs_init.c index 0c190c972..8e511cb0a 100644 --- a/src/afs/afs_init.c +++ b/src/afs/afs_init.c @@ -264,7 +264,11 @@ afs_LookupInodeByPath(char *filename, afs_ufs_dcache_id_t *inode, struct vnode * code = gop_lookupname(filename, AFS_UIOSYS, 0, &filevp); if (code) return code; +#ifdef AFS_CACHE_VNODE_PATH + *inode = afs_strdup(filename); +#else *inode = afs_vnodeToInumber(filevp); +#endif if (fvpp) *fvpp = filevp; else { @@ -281,11 +285,7 @@ afs_InitCellInfo(char *afile) afs_dcache_id_t inode; int code = 0; -#ifdef AFS_CACHE_VNODE_PATH - inode.ufs = AFS_CACHE_CELLS_INODE; -#else code = afs_LookupInodeByPath(afile, &inode.ufs, NULL); -#endif return afs_cellname_init(&inode, code); } @@ -327,8 +327,6 @@ afs_InitVolumeInfo(char *afile) * it in the cache... */ code = afs_LookupInodeByPath(afile, &volumeInode.ufs, &volumeVnode); -#elif defined(AFS_CACHE_VNODE_PATH) - volumeInode.ufs = AFS_CACHE_VOLUME_INODE; #else code = afs_LookupInodeByPath(afile, &volumeInode.ufs, NULL); #endif @@ -469,7 +467,7 @@ afs_InitCacheInfo(register char *afile) #endif cacheInode.ufs = afs_vnodeToInumber(filevp); #else - cacheInode.ufs = AFS_CACHE_ITEMS_INODE; + afs_LookupInodeByPath(afile, &cacheInode.ufs, NULL); #endif cacheDev.dev = afs_vnodeToDev(filevp); #endif /* AFS_LINUX20_ENV */ @@ -686,7 +684,7 @@ shutdown_cache(void) { AFS_STATCNT(shutdown_cache); afs_WriteThroughDSlots(); - if (afs_cold_shutdown) { + if (1/*afs_cold_shutdown*/) { afs_cacheinit_flag = 0; shutdown_dcache(); shutdown_vcache(); @@ -702,6 +700,12 @@ shutdown_cache(void) vrele(cacheDev.held_vnode); cacheDev.held_vnode = NULL; } +#endif +#ifdef AFS_CACHE_VNODE_PATH + if (cacheDiskType != AFS_FCACHE_TYPE_MEM) { + afs_osi_FreeStr(cacheInode.ufs); + afs_osi_FreeStr(volumeInode.ufs); + } #endif afs_reset_inode(&cacheInode); afs_reset_inode(&volumeInode); diff --git a/src/afsd/afsd.c b/src/afsd/afsd.c index 60372ad7b..c70990d23 100644 --- a/src/afsd/afsd.c +++ b/src/afsd/afsd.c @@ -1539,9 +1539,7 @@ mainproc(struct cmd_syndesc *as, void *arock) static char rn[] = "afsd"; /*Name of this routine */ afs_int32 code; /*Result of fork() */ int i; -#ifndef AFS_CACHE_VNODE_PATH int currVFile; /*Current AFS cache file number passed in */ -#endif int mountFlags; /*Flags passed to mount() */ int lookupResult; /*Result of GetLocalCellName() */ int cacheIteration; /*How many times through cache verification */ @@ -2163,23 +2161,6 @@ mainproc(struct cmd_syndesc *as, void *arock) rn, vFilesFound, cacheFiles, cacheIteration); } while ((vFilesFound < cacheFiles) && (cacheIteration < MAX_CACHE_LOOPS)); -#ifdef AFS_CACHE_VNODE_PATH - if (afsd_debug) - printf - ("%s: Calling AFSOP_CACHEBASEDIR with '%s'\n", - rn, cacheBaseDir); - call_syscall(AFSOP_CACHEBASEDIR, cacheBaseDir); - if (afsd_debug) - printf - ("%s: Calling AFSOP_CACHEDIRS with %d dirs\n", - rn, nFilesPerDir); - call_syscall(AFSOP_CACHEDIRS, nFilesPerDir); - if (afsd_debug) - printf - ("%s: Calling AFSOP_CACHEFILES with %d files\n", - rn, cacheFiles); - call_syscall(AFSOP_CACHEFILES, cacheFiles); -#endif } else if (afsd_verbose) printf("%s: Using memory cache, not swept\n", rn); @@ -2322,7 +2303,6 @@ mainproc(struct cmd_syndesc *as, void *arock) if (!(cacheFlags & AFSCALL_INIT_MEMCACHE)) call_syscall(AFSOP_VOLUMEINFO, fullpn_VolInfoFile); -#ifndef AFS_CACHE_VNODE_PATH /* * Give the kernel the names of the AFS files cached on the workstation's * disk. @@ -2338,7 +2318,7 @@ mainproc(struct cmd_syndesc *as, void *arock) (afs_uint32) (inode_for_V[currVFile] >> 32), (afs_uint32) (inode_for_V[currVFile] & 0xffffffff)); #else -#if defined(LINUX_USE_FH) +#if defined(LINUX_USE_FH) || defined(AFS_CACHE_VNODE_PATH) sprintf(fullpn_VFile, "%s/D%d/V%d", cacheBaseDir, dir_for_V[currVFile], currVFile); call_syscall(AFSOP_CACHEFILE, fullpn_VFile); #else @@ -2346,7 +2326,6 @@ mainproc(struct cmd_syndesc *as, void *arock) #endif #endif } -#endif /*end for */ /* -- 2.39.5