From 2f03d4e6e25d0db4986120e1d2ec6a200b0d0d39 Mon Sep 17 00:00:00 2001 From: Andrew Deason Date: Tue, 6 Apr 2010 16:57:27 -0500 Subject: [PATCH] Use AFS_CACHE_VNODE_PATH for UKERNEL Use the AFS_CACHE_VNODE_PATH cache mechanism for UKERNEL, to be compatible with new kernel caching code, and simplify the cache code a little bit. Change-Id: Ifc44790db08a336cca0032a1d05eedf70d2b24b8 Reviewed-on: http://gerrit.openafs.org/1721 Reviewed-by: Derrick Brashear Tested-by: Derrick Brashear --- acinclude.m4 | 1 + src/afs/UKERNEL/afs_usrops.c | 87 ++++++++++++++--------------------------- src/afs/afs.h | 4 +- src/afs/afs_dcache.c | 2 +- 4 files changed, 34 insertions(+), 60 deletions(-) diff --git a/acinclude.m4 b/acinclude.m4 index e450150..e2eb9c5 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -45,6 +45,7 @@ AH_BOTTOM([ * try and reduce potential confusion. */ #define _FILE_OFFSET_BITS 64 +#define AFS_CACHE_VNODE_PATH #endif #undef AFS_NAMEI_ENV diff --git a/src/afs/UKERNEL/afs_usrops.c b/src/afs/UKERNEL/afs_usrops.c index db55f11..e946b90 100644 --- a/src/afs/UKERNEL/afs_usrops.c +++ b/src/afs/UKERNEL/afs_usrops.c @@ -35,6 +35,10 @@ #undef VIRTUE #undef VICE +#ifndef AFS_CACHE_VNODE_PATH +#error You must compile UKERNEL code with -DAFS_CACHE_VNODE_PATH +#endif + #define CACHEINFOFILE "cacheinfo" #define AFSLOGFILE "AFSLog" #define DCACHEFILE "CacheItems" @@ -119,7 +123,7 @@ usr_mutex_t afs_global_lock; usr_thread_t afs_global_owner; usr_mutex_t rx_global_lock; usr_thread_t rx_global_owner; -usr_mutex_t osi_inode_lock; +usr_mutex_t osi_dummy_lock; usr_mutex_t osi_waitq_lock; usr_mutex_t osi_authenticate_lock; afs_lock_t afs_ftf; @@ -632,18 +636,19 @@ afs_osi_CheckTimedWaits(void) } /* - * I-node numbers are indeces into a table containing a filename - * i-node structure and a vnode structure. When we create an i-node, - * we copy the name into the array and initialize enough of the fields - * in the inode and vnode structures to get the client to work. + * 'dummy' vnode, for non-AFS files. We don't actually need most vnode + * information for non-AFS files, so point all of them towards this vnode + * to save memory. */ -typedef struct { - struct usr_inode i_node; - char *name; -} osi_file_table_t; -osi_file_table_t *osi_file_table; -int n_osi_files = 0; -int max_osi_files = 0; +static struct usr_vnode dummy_vnode = { + 0, /* v_flag */ + 1024, /* v_count */ + NULL, /* v_op */ + NULL, /* v_vfsp */ + 0, /* v_type */ + 0, /* v_rdev */ + NULL /* v_data */ +}; /* * Allocate a slot in the file table if there is not one there already, @@ -653,12 +658,7 @@ int lookupname(char *fnamep, int segflg, int followlink, struct usr_vnode **compvpp) { - int i; int code; - struct usr_inode *ip; - struct usr_vnode *vp; - - /*usr_assert(followlink == 0); */ /* * Assume relative pathnames refer to files in AFS @@ -670,34 +670,17 @@ lookupname(char *fnamep, int segflg, int followlink, return code; } - usr_mutex_lock(&osi_inode_lock); + /* For non-afs files, nobody really looks at the meaningful values in the + * returned vnode, so we can return a 'fake' one. The vnode can be held, + * released, etc. and some callers check for a NULL vnode anyway, so we + * to return something. */ - for (i = 0; i < n_osi_files; i++) { - if (strcmp(fnamep, osi_file_table[i].name) == 0) { - *compvpp = &osi_file_table[i].i_node.i_vnode; - (*compvpp)->v_count++; - usr_mutex_unlock(&osi_inode_lock); - return 0; - } - } + usr_mutex_lock(&osi_dummy_lock); + VN_HOLD(&dummy_vnode); + usr_mutex_unlock(&osi_dummy_lock); - if (n_osi_files == max_osi_files) { - usr_mutex_unlock(&osi_inode_lock); - return ENOSPC; - } + *compvpp = &dummy_vnode; - osi_file_table[n_osi_files].name = afs_osi_Alloc(strlen(fnamep) + 1); - usr_assert(osi_file_table[n_osi_files].name != NULL); - strcpy(osi_file_table[n_osi_files].name, fnamep); - ip = &osi_file_table[i].i_node; - vp = &ip->i_vnode; - vp->v_data = (caddr_t) ip; - ip->i_dev = -1; - n_osi_files++; - ip->i_number = n_osi_files; - vp->v_count = 2; - usr_mutex_unlock(&osi_inode_lock); - *compvpp = vp; return 0; } @@ -713,15 +696,13 @@ osi_UFSOpen(afs_dcache_id_t *ino) AFS_ASSERT_GLOCK(); - if (ino->ufs > n_osi_files) { - get_user_struct()->u_error = ENOENT; - return NULL; - } - AFS_GUNLOCK(); fp = (struct osi_file *)afs_osi_Alloc(sizeof(struct osi_file)); usr_assert(fp != NULL); - fp->fd = open(osi_file_table[ino->ufs - 1].name, O_RDWR | O_CREAT, 0); + + usr_assert(ino->ufs); + + fp->fd = open(ino->ufs, O_RDWR | O_CREAT, 0); if (fp->fd < 0) { get_user_struct()->u_error = errno; afs_osi_Free((char *)fp, sizeof(struct osi_file)); @@ -1075,14 +1056,6 @@ osi_Init(void) { int i; - /* - * Allocate the table used to implement psuedo-inodes. - */ - max_osi_files = cacheFiles + 100; - osi_file_table = (osi_file_table_t *) - afs_osi_Alloc(max_osi_files * sizeof(osi_file_table_t)); - usr_assert(osi_file_table != NULL); - #ifndef NETSCAPE_NSAPI /* * Initialize the mutex and condition variable used to implement @@ -1113,7 +1086,7 @@ osi_Init(void) */ usr_mutex_init(&afs_global_lock); usr_mutex_init(&rx_global_lock); - usr_mutex_init(&osi_inode_lock); + usr_mutex_init(&osi_dummy_lock); usr_mutex_init(&osi_waitq_lock); usr_mutex_init(&osi_authenticate_lock); diff --git a/src/afs/afs.h b/src/afs/afs.h index e142341..1b2ab15 100644 --- a/src/afs/afs.h +++ b/src/afs/afs.h @@ -1049,8 +1049,6 @@ struct afs_fheader { #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 * the size correctly. @@ -1350,6 +1348,8 @@ extern struct brequest afs_brs[NBRS]; /* request structures */ #ifndef afs_vnodeToDev #if defined(AFS_SGI62_ENV) || defined(AFS_HAVE_VXFS) || defined(AFS_DARWIN_ENV) #define afs_vnodeToDev(V) VnodeToDev(V) +#elif defined(UKERNEL) +#define afs_vnodeToDev(V) (VTOI(V) ? (VTOI(V)->i_dev) : (-1)) #else #define afs_vnodeToDev(V) (VTOI(V)->i_dev) #endif diff --git a/src/afs/afs_dcache.c b/src/afs/afs_dcache.c index 34ff630..03c8375 100644 --- a/src/afs/afs_dcache.c +++ b/src/afs/afs_dcache.c @@ -2909,7 +2909,7 @@ afs_InitCacheFile(char *afile, ino_t ainode) } } else { /* Add any other 'complex' inode types here ... */ -#if defined(UKERNEL) || !(defined(LINUX_USE_FH) || defined(AFS_CACHE_VNODE_PATH)) +#if !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 " -- 1.7.1