afs/fs/cachefs super.c,1.26,1.27 interface.c,1.4,1.5
index.c,1.15,1.16 cachefs-int.h,1.29,1.30 block.c,1.3,1.4aops.c,1.27,1.28
dwh at infradead.org
dwh at infradead.org
Tue Apr 29 17:24:09 BST 2003
Update of /home/cvs/afs/fs/cachefs
In directory phoenix.infradead.org:/tmp/cvs-serv2191/fs/cachefs
Modified Files:
super.c interface.c index.c cachefs-int.h block.c aops.c
Log Message:
merged struct cachefs_active_inode into struct cachefs_inode
Index: super.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/super.c,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- super.c 24 Apr 2003 12:02:33 -0000 1.26
+++ super.c 29 Apr 2003 15:24:06 -0000 1.27
@@ -118,7 +118,7 @@
char *dev_name,
void *options)
{
- struct cachefs_active_inode *active;
+ struct cachefs_search_result *srch;
struct super_block *sb;
_enter(",,%s,%p",dev_name,options);
@@ -127,8 +127,8 @@
* - we don't want to have to try and get rid of the superblock due to an error after
* we've got it
*/
- active = kmalloc(sizeof(*active),GFP_KERNEL);
- if (!active) {
+ srch = kmalloc(sizeof(*srch),GFP_KERNEL);
+ if (!srch) {
kleave(" = -ENOMEM");
return ERR_PTR(-ENOMEM);
}
@@ -138,9 +138,9 @@
/* if successful add to the list of available caches */
if (!IS_ERR(sb) && sb->s_fs_info)
- cachefs_add_cache((struct cachefs_super *)sb->s_fs_info,active);
+ cachefs_add_cache((struct cachefs_super *)sb->s_fs_info,srch);
else
- kfree(active);
+ kfree(srch);
_leave(" = %p",sb);
return sb;
@@ -273,6 +273,9 @@
INIT_LIST_HEAD(&super->mnt_link);
+ INIT_LIST_HEAD(&super->ino_list);
+ spin_lock_init(&super->ino_list_lock);
+
rwlock_init(&super->blk_tree_lock);
spin_lock_init(&super->rcm_lock);
@@ -309,8 +312,6 @@
init_completion(&super->dmn_dead);
init_waitqueue_head(&super->dmn_sleepq);
- spin_lock_init(&super->ino_tree_lock);
-
/* create the linear-mapping inode */
ret = cachefs_iget(super,CACHEFS_INO_MISC,&inode2);
if (ret<0)
@@ -779,6 +780,9 @@
if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) == SLAB_CTOR_CONSTRUCTOR) {
memset(inode,0,sizeof(*inode));
inode_init_once(&inode->vfs_inode);
+
+ INIT_LIST_HEAD(&inode->cookie_link);
+ INIT_LIST_HEAD(&inode->super_link);
}
} /* end cachefs_i_init_once() */
Index: interface.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/interface.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- interface.c 24 Apr 2003 15:14:10 -0000 1.4
+++ interface.c 29 Apr 2003 15:24:06 -0000 1.5
@@ -33,7 +33,8 @@
.usage = ATOMIC_INIT(1),
.idef = &cachefs_fsdef_index_def,
.sem = __RWSEM_INITIALIZER(cachefs_fsdef_index.sem),
- .active_inodes = LIST_HEAD_INIT(cachefs_fsdef_index.active_inodes),
+ .search_results = LIST_HEAD_INIT(cachefs_fsdef_index.search_results),
+ .backing_inodes = LIST_HEAD_INIT(cachefs_fsdef_index.backing_inodes),
};
static void __cachefs_cookie_put(struct cachefs_cookie *cookie);
@@ -45,15 +46,6 @@
BUG();
}
-static void __cachefs_put_active_inode(struct cachefs_active_inode *active);
-static inline void cachefs_put_active_inode(struct cachefs_active_inode *active)
-{
- if (atomic_dec_and_lock(&active->usage,&active->super->ino_tree_lock))
- __cachefs_put_active_inode(active);
- else if (atomic_read(&active->usage)<0)
- BUG();
-}
-
/*****************************************************************************/
/*
* register a network filesystem for caching
@@ -81,12 +73,14 @@
netfs->primary_index->idef = primary_idef;
netfs->primary_index->iparent = &cachefs_fsdef_index;
+ netfs->primary_index->netfs = netfs;
netfs->primary_index->netfs_data = netfs;
atomic_inc(&netfs->primary_index->iparent->usage);
atomic_inc(&netfs->primary_index->iparent->children);
- INIT_LIST_HEAD(&netfs->primary_index->active_inodes);
+ INIT_LIST_HEAD(&netfs->primary_index->search_results);
+ INIT_LIST_HEAD(&netfs->primary_index->backing_inodes);
init_rwsem(&netfs->primary_index->sem);
/* check it's not already present */
@@ -135,45 +129,46 @@
/*****************************************************************************/
/*
* declare a mounted cache as being open for business
- * - we don't want to do any memory allocation here, lest we have to try and free super on error
+ * - try not to allocate memory as disposing of the superblock is a pain
*/
-void cachefs_add_cache(struct cachefs_super *super, struct cachefs_active_inode *active)
+void cachefs_add_cache(struct cachefs_super *super, struct cachefs_search_result *srch)
{
+ struct cachefs_inode *ifsdef;
+
printk("\n\n\n");
kenter("");
/* prepare an active-inode record for the FSDEF index of this cache */
- memset(active,0,sizeof(*active));
+ if (cachefs_iget(super,CACHEFS_INO_FSDEF_CATALOGUE,&ifsdef)<0)
+ BUG(); /* shouldn't happen as FSDEF is the root dir of the FS */
- atomic_set(&active->usage,2);
+ if (!cachefs_igrab(ifsdef))
+ BUG();
- active->super = super;
- active->ino = CACHEFS_INO_FSDEF_CATALOGUE;
- active->flags = (1 << CACHEFS_ACTIVE_INODE_ISINDEX | 1 << CACHEFS_ACTIVE_INODE_LIVE);
- active->storage = NULL;
- active->cookie = &cachefs_fsdef_index;
+ ifsdef->cookie = &cachefs_fsdef_index;
- init_waitqueue_head(&active->initwq);
- init_rwsem(&active->sem);
+ srch->super = super;
+ srch->ino = CACHEFS_INO_FSDEF_CATALOGUE;
/* actually do the stuff */
down_write(&cachefs_addremove_sem);
list_add(&super->mnt_link,&cachefs_cache_list);
- up_write(&cachefs_addremove_sem);
-
- spin_lock(&super->ino_tree_lock);
- rb_link_node(&active->node,NULL,&super->ino_tree.rb_node);
- rb_insert_color(&active->node,&super->ino_tree);
- spin_unlock(&super->ino_tree_lock);
+ spin_lock(&super->ino_list_lock);
+ list_add_tail(&ifsdef->super_link,&super->ino_list);
+ spin_unlock(&super->ino_list_lock);
down_write(&cachefs_fsdef_index.sem);
- list_add_tail(&active->link,&cachefs_fsdef_index.active_inodes);
+ list_add_tail(&srch->link,&cachefs_fsdef_index.search_results);
+ list_add_tail(&ifsdef->cookie_link,&cachefs_fsdef_index.backing_inodes);
atomic_inc(&cachefs_fsdef_index.usage);
+
up_write(&cachefs_fsdef_index.sem);
+ up_write(&cachefs_addremove_sem);
+
kleave("");
} /* end cachefs_add_cache() */
@@ -183,8 +178,7 @@
*/
void cachefs_withdraw_cache(struct cachefs_super *super)
{
- struct cachefs_active_inode *active;
- struct rb_node *n;
+ struct cachefs_inode *inode;
kenter("");
@@ -196,39 +190,34 @@
up_write(&cachefs_addremove_sem);
/* we now have to destroy all the active inodes pertaining to this superblock */
- spin_lock(&super->ino_tree_lock);
- while ((n = rb_first(&super->ino_tree))) {
- active = rb_entry(n,struct cachefs_active_inode,node);
- rb_erase(n,&super->ino_tree);
- spin_unlock(&super->ino_tree_lock);
+ spin_lock(&super->ino_list_lock);
+ while (!list_empty(&super->ino_list)) {
+ inode = list_entry(super->ino_list.next,struct cachefs_inode,super_link);
+ list_del(&inode->super_link);
+ spin_unlock(&super->ino_list_lock);
/* we've extracted an active inode from the tree */
- cachefs_withdraw_active_inode(active);
- cachefs_put_active_inode(active);
+ cachefs_withdraw_inode(inode);
+ cachefs_iput(inode);
- spin_lock(&super->ino_tree_lock);
+ spin_lock(&super->ino_list_lock);
}
- spin_unlock(&super->ino_tree_lock);
+ spin_unlock(&super->ino_list_lock);
kleave("");
} /* end cachefs_withdraw_cache() */
/*****************************************************************************/
/*
- * look the object up in the specified cache
- * - the specified object must be write-locked by the caller
- * - an inode is created on disc if not present if "create" is true
- * - all parent index objects are created if necessary
- * - returns -ENODATA if the object doesn't exist and "create" is false
- */
-static int cachefs_lookup_object(struct cachefs_cookie *cookie,
- struct cachefs_super *super,
- int create)
+ * search for representation of an object in its parent cache
+ * - the cookie must be locked by the caller
+ * - returns -ENODATA if the object or one of its ancestors doesn't exist
+ */
+static int cachefs_search_for_object(struct cachefs_cookie *cookie, struct cachefs_super *super)
{
- struct cachefs_active_inode *ipactive, *active, *xactive;
+ struct cachefs_search_result *srch;
struct cachefs_cookie *iparent;
- struct rb_node *parent, **p;
- unsigned long flags;
+ struct cachefs_inode *ipinode, *inode;
int ret;
iparent = cookie->iparent;
@@ -236,76 +225,57 @@
kenter("{%s/%s},",iparent->idef->name,cookie->idef ? (char*)cookie->idef->name : "<file>");
- /* see if there's an entry for this object already */
- list_for_each_entry(active,&cookie->active_inodes,link) {
- kdebug("check entry %p x %p [ino %u]",cookie,super,active->ino);
+ /* see if there's a search result for this object already */
+ list_for_each_entry(srch,&cookie->search_results,link) {
+ kdebug("check entry %p x %p [ino %u]",cookie,super,srch->ino);
- if (active->super==super) {
+ if (srch->super==super) {
kdebug("found entry");
- if (active->ino) {
- kleave(" = 0 [found ino %u]",active->ino);
+
+ if (srch->ino) {
+ kleave(" = 0 [found ino %u]",srch->ino);
return 0;
}
/* entry is negative */
- if (!create)
- goto nodata;
-
- goto found_entry;
+ kleave(" = -ENODATA");
+ return -ENODATA;
}
}
- /* allocate an entry for this object */
+ /* allocate an initially negative entry for this object */
kdebug("alloc entry %p x %p",cookie,super);
- active = kmalloc(sizeof(*active),GFP_KERNEL);
- if (!active) {
+ srch = kmalloc(sizeof(*srch),GFP_KERNEL);
+ if (!srch) {
kleave(" = -ENOMEM");
return -ENOMEM;
}
- memset(active,0,sizeof(*active));
+ memset(srch,0,sizeof(*srch));
- active->super = super;
- active->ino = 0;
- active->flags = 1 << CACHEFS_ACTIVE_INODE_LIVE;
- active->storage = NULL;
- active->cookie = cookie;
-
- if (cookie->idef)
- active->flags |= 1 << CACHEFS_ACTIVE_INODE_ISINDEX;
-
- atomic_set(&active->usage,1);
- INIT_LIST_HEAD(&active->link);
- init_waitqueue_head(&active->initwq);
- init_rwsem(&active->sem);
+ srch->super = super;
+ srch->ino = 0;
+ INIT_LIST_HEAD(&srch->link);
- found_entry:
- down_write(&active->sem);
-
- /* we need to insert an entry for this cache in the object's parent index, so the first
- * thing to do is to see if the parent index is represented on disc, and if not, create it
- * if necessary
+ /* we need see if there's an entry for this cache in this object's parent index, so the
+ * first thing to do is to see if the parent index is represented on disc
*/
- down_write(&iparent->sem);
+ down_read(&iparent->sem);
- ret = cachefs_lookup_object(iparent,super,create);
+ ret = cachefs_search_for_object(iparent,super);
if (ret<0) {
- if (ret==-ENODATA) {
- /* set a negative entry */
- if (list_empty(&active->link)) {
- list_add_tail(&active->link,&cookie->active_inodes);
- atomic_inc(&cookie->usage);
- }
- }
+ if (ret!=-ENODATA)
+ goto error;
- up_write(&iparent->sem);
- goto error2;
+ /* set a negative entry */
+ list_add_tail(&srch->link,&cookie->search_results);
+ goto done;
}
- /* it should now be present - find it */
- list_for_each_entry(ipactive,&iparent->active_inodes,link) {
- if (ipactive->super==super && ipactive->ino)
+ /* find the parent's backing inode */
+ list_for_each_entry(ipinode,&iparent->backing_inodes,cookie_link) {
+ if (ipinode->vfs_inode.i_sb->s_fs_info==super)
goto found_parent_entry;
}
@@ -314,89 +284,151 @@
found_parent_entry:
kdebug("found_parent_entry");
- /* we only need a read-lock on the parent for the rest of this */
- downgrade_write(&iparent->sem);
-
/* search the parent index for a reference compatible with this object */
- ret = cachefs_index_search(ipactive,active);
+ ret = cachefs_index_search(ipinode,cookie,&srch->ino);
switch (ret) {
default:
goto error;
case 0:
- if (list_empty(&active->link)) {
- list_add_tail(&active->link,&cookie->active_inodes);
- atomic_inc(&cookie->usage);
- }
- goto add_to_active_tree;
+ /* found - allocate an inode */
+ ret = cachefs_iget(super,srch->ino,&inode);
+ if (ret<0)
+ goto error;
- case -ENOENT:
- /* we can at least set a valid negative entry */
- if (list_empty(&active->link)) {
- list_add_tail(&active->link,&cookie->active_inodes);
- atomic_inc(&cookie->usage);
- }
+ if (!cachefs_igrab(inode))
+ goto error_i;
- if (!create) {
- up_write(&active->sem);
- up_read(&iparent->sem);
- goto nodata;
- }
+ down(&inode->vfs_inode.i_sem);
+ inode->cookie = cookie;
+ list_add_tail(&srch->link,&cookie->search_results);
+ list_add_tail(&inode->cookie_link,&cookie->backing_inodes);
+ atomic_inc(&cookie->usage);
+ up(&inode->vfs_inode.i_sem);
+ break;
- /* we need to add the object to the index */
- ret = cachefs_index_add(ipactive,active);
- if (ret<0)
- goto error;
+ case -ENOENT:
+ /* we can at least set a valid negative entry */
+ list_add_tail(&srch->link,&cookie->search_results);
+ ret = -ENODATA;
break;
}
- /* add the inode to the active tree */
- add_to_active_tree:
- kdebug("add_to_active_tree");
+ done:
+ up_read(&iparent->sem);
+ kleave(" = %d",ret);
+ return ret;
- parent = NULL;
+ error_i:
+ cachefs_iput(inode);
+ ret = -ENOENT;
+ error:
+ up_read(&iparent->sem);
+ kfree(srch);
+ kleave(" = %d",ret);
+ return ret;
- atomic_inc(&active->usage);
+} /* end cachefs_search_for_object() */
- spin_lock_irqsave(&super->ino_tree_lock,flags);
+/*****************************************************************************/
+/*
+ * instantiate the object in the specified cache
+ * - the cookie must be write-locked by the caller
+ * - search must have been performed first (so lists of search results are filled out)
+ * - all parent index objects are instantiated if necessary
+ */
+static int cachefs_instantiate_object(struct cachefs_cookie *cookie, struct cachefs_super *super)
+{
+ struct cachefs_search_result *srch;
+ struct cachefs_cookie *iparent;
+ struct cachefs_inode *ipinode, *inode;
+ int ret;
- p = &super->ino_tree.rb_node;
- while (*p) {
- parent = *p;
- xactive = rb_entry(parent,struct cachefs_active_inode,node);
+ iparent = cookie->iparent;
+ if (!iparent) return 0; /* FSDEF entries don't have a parent */
- if (active->ino < xactive->ino)
- p = &(*p)->rb_left;
- else if (active->ino > xactive->ino)
- p = &(*p)->rb_right;
- else
- BUG();
+ kenter("{%s/%s},",iparent->idef->name,cookie->idef ? (char*)cookie->idef->name : "<file>");
+
+ /* find the search result for this object */
+ list_for_each_entry(srch,&cookie->search_results,link) {
+ if (srch->super==super)
+ goto found_entry;
}
- rb_link_node(&active->node,parent,p);
- rb_insert_color(&active->node,&super->ino_tree);
+ BUG();
- spin_unlock_irqrestore(&super->ino_tree_lock,flags);
+ found_entry:
+ if (srch->ino) {
+ kleave(" = 0 [found ino %u]",srch->ino);
+ return 0;
+ }
- up_write(&active->sem);
- up_read(&iparent->sem);
+ /* we need to insert an entry for this cache in the object's parent index, so the first
+ * thing to do is make sure that the parent index is represented on disc
+ */
+ down_write(&iparent->sem);
+
+ ret = cachefs_instantiate_object(iparent,super);
+ if (ret<0)
+ goto error;
+
+ /* the parent index's inode should now be available */
+ list_for_each_entry(ipinode,&iparent->backing_inodes,cookie_link) {
+ if (ipinode->vfs_inode.i_sb->s_fs_info==super)
+ goto found_parent_inode;
+ }
+
+ BUG();
+
+ found_parent_inode:
+ kdebug("found_parent_inode: ino=%lu",ipinode->vfs_inode.i_ino);
+
+ BUG_ON(ipinode->cookie!=iparent);
+
+ ret = cachefs_index_add(ipinode,cookie,&srch->ino);
+ if (ret<0)
+ goto error;
+
+ /* we're going to need an in-memory reflection of the inode too */
+ ret = cachefs_iget(super,srch->ino,&inode);
+ if (ret<0)
+ goto error_x; /* uh-oh... our search record is now wrong */
+
+ if (!cachefs_igrab(inode))
+ goto error_xi;
+
+ down(&inode->vfs_inode.i_sem);
+ inode->cookie = cookie;
+ list_add_tail(&inode->cookie_link,&cookie->backing_inodes);
+ atomic_inc(&cookie->usage);
+
+ spin_lock(&super->ino_list_lock);
+
+ list_add_tail(&inode->super_link,&super->ino_list);
+
+ spin_unlock(&super->ino_list_lock);
+
+ up(&inode->vfs_inode.i_sem);
+ up_write(&iparent->sem);
kleave(" = 0");
return 0;
+ /* if we get an error after having instantiated an inode on disc, just discard the search
+ * record so we find it next time */
+ error_xi:
+ cachefs_iput(inode);
+ ret = -ENOENT;
+ error_x:
+ list_del(&srch->link);
+ kfree(srch);
+ srch = NULL;
+
error:
- up_read(&iparent->sem);
- error2:
- up_write(&active->sem);
- if (list_empty(&active->link))
- kfree(active);
+ up_write(&iparent->sem);
kleave(" = %d",ret);
return ret;
- nodata:
- kleave(" = -ENODATA");
- return -ENODATA;
-
-} /* end cachefs_lookup_object() */
+} /* end cachefs_instantiate_object() */
/*****************************************************************************/
/*
@@ -438,10 +470,8 @@
void *netfs_data,
struct cachefs_cookie **_cookie)
{
- struct cachefs_active_inode *active;
struct cachefs_cookie *cookie;
struct cachefs_super *super;
- struct list_head *_p, *_n;
int ret = 0;
*_cookie = NULL;
@@ -474,6 +504,7 @@
cookie->idef = idef;
cookie->iparent = iparent;
+ cookie->netfs = iparent->netfs;
cookie->netfs_data = netfs_data;
*_cookie = cookie;
@@ -490,7 +521,7 @@
/* search every cache to see if the object is already present */
list_for_each_entry(super,&cachefs_cache_list,mnt_link) {
- ret = cachefs_lookup_object(cookie,super,0);
+ ret = cachefs_search_for_object(cookie,super);
switch (ret) {
case 0:
if (!cookie->idef)
@@ -505,35 +536,15 @@
/* if this object is a file, select a cache on which to store it */
if (!cookie->idef) {
+ ret = -ENOMEDIUM;
super = cachefs_select_cache_for_file();
-
- /* we don't want to keep any negative records for a file other than the one for the
- * chosen superblock (which we'll turn into a positive entry)
- */
- list_for_each_safe(_p,_n,&cookie->active_inodes) {
- active = list_entry(_p,struct cachefs_active_inode,link);
- if (active->super!=super || active->ino==0) {
- list_del(&active->link);
-
- down_write(&active->sem);
- active->cookie = NULL;
- up_write(&active->sem);
-
- cachefs_cookie_put(cookie);
- cachefs_put_active_inode(active);
- }
- }
-
- ret = 0;
if (!super)
goto error; /* couldn't decide on a cache */
/* instantiate the file */
- ret = cachefs_lookup_object(cookie,super,1);
+ ret = cachefs_instantiate_object(cookie,super);
if (ret==0)
goto done;
- if (ret==-ENODATA)
- BUG();
}
error:
@@ -554,7 +565,7 @@
*/
void cachefs_relinquish_cookie(struct cachefs_cookie *cookie, int retire)
{
- struct cachefs_active_inode *active;
+ struct cachefs_inode *inode;
kenter("{%s},%d",
cookie && cookie->idef ? (char*)cookie->idef->name : "<file>",
@@ -578,28 +589,28 @@
/* note that all the inodes supporting this object need recycling */
if (retire) {
- list_for_each_entry(active,&cookie->active_inodes,link) {
- set_bit(CACHEFS_ACTIVE_INODE_RECYCLING,&active->flags);
+ list_for_each_entry(inode,&cookie->backing_inodes,cookie_link) {
+ set_bit(CACHEFS_ACTIVE_INODE_RECYCLING,&inode->flags);
}
}
/* break links with all the active inodes */
- while (!list_empty(&cookie->active_inodes)) {
- active = list_entry(cookie->active_inodes.next, struct cachefs_active_inode,link);
+ while (!list_empty(&cookie->backing_inodes)) {
+ inode = list_entry(cookie->backing_inodes.next,struct cachefs_inode,cookie_link);
/* detach the cache inode from the cached object cookie */
- set_bit(CACHEFS_ACTIVE_INODE_RELEASING,&active->flags);
+ set_bit(CACHEFS_ACTIVE_INODE_RELEASING,&inode->flags);
- list_del_init(&active->link);
+ list_del_init(&inode->cookie_link);
- down_write(&active->sem);
- active->cookie = NULL;
- up_write(&active->sem);
+ down(&inode->vfs_inode.i_sem);
+ inode->cookie = NULL;
+ up(&inode->vfs_inode.i_sem);
if (atomic_dec_and_test(&cookie->usage))
BUG(); /* shouldn't've reduced the cookie usership to 0 yet */
- cachefs_put_active_inode(active);
+ cachefs_iput(inode);
}
up_write(&cookie->sem);
@@ -624,43 +635,52 @@
* - have to take care as the cookie can be being relinquished by the netfs simultaneously
* - the active inode is pinned by the caller holding a refcount on it
*/
-void cachefs_withdraw_active_inode(struct cachefs_active_inode *active)
+void cachefs_withdraw_inode(struct cachefs_inode *inode)
{
+ struct cachefs_search_result *srch;
struct cachefs_cookie *cookie, *xcookie = NULL;
- kenter("%p",active);
+ kenter("{%lu}",inode->vfs_inode.i_ino);
- set_bit(CACHEFS_ACTIVE_INODE_WITHDRAWN,&active->flags);
+ set_bit(CACHEFS_ACTIVE_INODE_WITHDRAWN,&inode->flags);
- /* first of all we have to break the links between the active inode and the cookie
- * - we have to hold both writelocks BUT we have to get the cookie lock FIRST
+ /* first of all we have to break the links between the inode and the cookie
+ * - we have to hold both semaphores BUT we have to get the cookie sem FIRST
*/
- down_write(&active->sem);
+ down(&inode->vfs_inode.i_sem);
- cookie = active->cookie;
+ cookie = inode->cookie;
if (cookie) {
atomic_inc(&cookie->usage); /* pin the cookie */
- up_write(&active->sem); /* re-order the locks to avoid deadlock */
+ up(&inode->vfs_inode.i_sem); /* re-order the locks to avoid deadlock */
down_write(&cookie->sem);
- down_write(&active->sem);
+ down(&inode->vfs_inode.i_sem);
+
+ list_del_init(&inode->cookie_link);
- list_del_init(&active->link);
+ xcookie = inode->cookie;
+ inode->cookie = NULL;
- xcookie = active->cookie;
- active->cookie = NULL;
+ list_for_each_entry(srch,&cookie->search_results,link) {
+ if (srch->super==inode->vfs_inode.i_sb->s_fs_info)
+ goto found_srch;
+ }
+ found_srch:
+ list_del(&srch->link);
+ kfree(srch);
up_write(&cookie->sem);
}
- up_write(&active->sem);
+ up(&inode->vfs_inode.i_sem);
if (cookie)
cachefs_cookie_put(cookie);
if (xcookie) {
cachefs_cookie_put(xcookie);
- cachefs_put_active_inode(active);
+ cachefs_iput(inode);
}
kleave("");
@@ -731,6 +751,7 @@
* destroy an active inode
* - called with super->ino_tree_lock held
*/
+#if 0 // TODO: remove
static void __cachefs_put_active_inode(struct cachefs_active_inode *active)
{
struct cachefs_super *super;
@@ -754,6 +775,7 @@
kleave("");
} /* end __cachefs_put_active_inode() */
+#endif
/*****************************************************************************/
/*
@@ -765,8 +787,137 @@
if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) == SLAB_CTOR_CONSTRUCTOR) {
memset(cookie,0,sizeof(*cookie));
- INIT_LIST_HEAD(&cookie->active_inodes);
+ INIT_LIST_HEAD(&cookie->search_results);
+ INIT_LIST_HEAD(&cookie->backing_inodes);
init_rwsem(&cookie->sem);
}
} /* end cachefs_cookie_init_once() */
+
+/*****************************************************************************/
+/*
+ * see if a page is cached in a block attached to the cookie
+ * - if it is:
+ * - the page cookie will have been changed so that mapped_block refers to the block
+ * - a BIO will have been dispatched to load the page with end_io as the completion func
+ * - end_io can be NULL, in which case a default function will just unlock the page
+ * - 0 will be returned
+ * - if it is not:
+ * - no cache space will be allocated
+ * - -ENODATA will be returned
+ * - the page must be locked before calling
+ * - netfs->ops->get_page_cookie() will be called to gain access to the page cookie
+ */
+#if 0
+int cachefs_read_page(struct cachefs_cookie *cookie, struct page *page, bio_end_io_t end_io)
+{
+ struct cachefs_block *block;
+ struct cachefs_page *pageio;
+ struct super_block *sb;
+ unsigned long flags;
+ struct bio *bio;
+ int ret;
+
+ kenter("{%s},{%lu}",netfs->name,page->index);
+
+ /* not supposed to use this for indexes */
+ BUG_ON(cookie->idef);
+
+ ret = cookie->netfs->ops->get_page_cookie(page,&pageio);
+ if (ret<0)
+ goto error;
+
+ /* protect against cache removal */
+ read_lock_irqsave(&pageio->lock,flags);
+
+ block = pageio->mapped_block;
+ if (block) {
+ if (!test_bit(CACHEFS_SUPER_WITHDRAWN,&block->super->flags))
+ cachefs_block_get(block);
+ else
+ block = NULL;
+ }
+
+ read_unlock_irqrestore(&pageio->lock,flags);
+
+ ret = -ENODATA;
+ if (!block)
+ goto error;
+
+ /* generate a BIO to read the page */
+ ret = -ENOMEM;
+ bio = bio_alloc(GFP_KERNEL,1);
+ if (!bio)
+ goto error;
+
+ sb = block->super->sb;
+
+ bio->bi_bdev = sb->s_bdev;
+ bio->bi_sector = block->bix << (PAGE_SHIFT - sb->s_blocksize_bits);
+ bio->bi_end_io = cachefs_io_end_io_read;
+ //dump_bio(bio,1);
+ submit_bio(READ,bio);
+ ret = 0;
+
+ error:
+ kleave(" = %d",ret);
+ return ret;
+} /* end cachefs_read_page() */
+#endif
+
+/*****************************************************************************/
+/*
+ * write a page to the cache
+ */
+#if 0
+int __cachefs_write_page(struct cachefs_cookie *cookie,
+ struct page *page,
+ cachefs_rw_complete_t end_io,
+ void *end_io_data)
+{
+ struct cachefs_block *block;
+ struct cachefs_page *pageio;
+ struct super_block *sb;
+ struct bio *bio;
+ int ret;
+
+ kenter("%p,{%lu},",page->index);
+
+ if (!cookie) {
+ kleave(" -ENOBUFS [no cookie]");
+ return -ENOBUFS; /* no actual cookie */
+ }
+
+ BUG_ON(cookie->idef); /* not supposed to use this for indexes */
+
+ ret = cookie->netfs->ops->get_page_cookie(page,&pageio);
+ if (ret<0)
+ goto error;
+
+ /* prevent the file from been uncached whilst we deal with it */
+ down_read(&cookie->sem);
+
+ if (list_empty(&cookie->active_inodes)) {
+ up_read(&cookie->sem);
+ kleave(" -ENOBUFS [no inode]");
+ return -ENOBUFS;
+ }
+
+ /* handle the case of there already being a mapping,
+ * - must protect against cache removal
+ */
+ read_lock(&pageio->lock);
+
+ block = pageio->mapped_block;
+ if (block && !test_bit(CACHEFS_SUPER_WITHDRAWN,&block->super->flags)) {
+ cachefs_block_get(block);
+ read_unlock(&pageio->lock);
+
+
+ }
+
+ read_unlock(&pageio->lock);
+
+
+} /* end __cachefs_write_page() */
+#endif
Index: index.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/index.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- index.c 24 Apr 2003 12:02:34 -0000 1.15
+++ index.c 29 Apr 2003 15:24:06 -0000 1.16
@@ -104,10 +104,11 @@
/*
* search for the specified target object in an index in one cache
* - returns -ENOENT if not found
- * - returns index number (>=0) if found and updates the atime for that entry
+ * - returns 0 if found, and stores the entry number in *_entry
*/
-int cachefs_index_search(struct cachefs_active_inode *index,
- struct cachefs_active_inode *target)
+int cachefs_index_search(struct cachefs_inode *index,
+ struct cachefs_cookie *target,
+ unsigned *_entry)
{
struct cachefs_index_search_record rec;
struct file_ra_state ra;
@@ -115,15 +116,13 @@
loff_t pos;
int ret;
- kenter("{%s,%u}",index->cookie->idef->name,index->ino);
+ kenter("{%s,%lu}",index->cookie->idef->name,index->vfs_inode.i_ino);
- /* get the inode */
- ret = cachefs_iget(index->super,index->ino,&rec.iinode);
- if (ret<0)
- goto error;
+ *_entry = 0;
+ rec.iinode = index;
rec.index = index->cookie;
- rec.target = target->cookie;
+ rec.target = target;
rec.entry = UINT_MAX;
rec.entsize = rec.iinode->index_esize;
@@ -140,11 +139,19 @@
do_generic_mapping_read(rec.iinode->vfs_inode.i_mapping,&ra,NULL,
&pos,&desc,cachefs_index_search_actor);
- ret = desc.error ? desc.error : (rec.entry==UINT_MAX) ? -ENOENT : rec.entry;
+ if (desc.error) {
+ ret = desc.error;
+
+ }
+ else if (rec.entry==UINT_MAX) {
+ ret = -ENOENT;
+ }
+ else {
+ *_entry = rec.entry;
+ ret = 0;
+ }
- cachefs_iput(rec.iinode);
- error:
- kleave(" = %d",ret);
+ kleave(" = %d [ent %u]",ret,*_entry);
return ret;
} /* end cachefs_index_search() */
@@ -297,29 +304,32 @@
/*
* allocate an entry in the specified index file and associate an inode with it
* - target->cookie->def determines whether the new inode will be a file or an index
- * - if an inode is successfully allocated, target->ino will be set with the inode number
+ * - if an inode is successfully allocated, *_newino will be set with the inode number
*/
-int cachefs_index_allocate(struct cachefs_inode *iinode,
- struct cachefs_active_inode *index,
- struct cachefs_active_inode *target)
+int cachefs_index_add(struct cachefs_inode *index,
+ struct cachefs_cookie *cookie,
+ unsigned *_newino)
{
struct cachefs_ondisc_index_entry *xent;
struct cachefs_ondisc_storage *storage;
+ struct cachefs_search_result *srch;
struct cachefs_transaction *trans;
struct cachefs_super *super;
struct page *inopage, *ixpage;
unsigned ino, ixentry, offset, inonext, ixnext, ino_offset;
int ret, loop;
- kenter("{%lu},{%s},",iinode->vfs_inode.i_ino,index->cookie->idef->name);
+ kenter("{%lu},{%s},",index->vfs_inode.i_ino,index->cookie->idef->name);
- super = index->super;
- inopage = NULL;
- ixpage = NULL;
- trans = NULL;
+ *_newino = 0;
+
+ super = index->vfs_inode.i_sb->s_fs_info;
+ inopage = NULL;
+ ixpage = NULL;
+ trans = NULL;
/* we need an index entry and a inode */
- ret = cachefs_index_select_free_entry(iinode,&ixpage,&ixentry,&ixnext);
+ ret = cachefs_index_select_free_entry(index,&ixpage,&ixentry,&ixnext);
if (ret<0)
goto error;
@@ -335,28 +345,28 @@
if (!trans)
goto error;
- offset = (ixentry % iinode->index_epp) * iinode->index_esize;
+ offset = (ixentry % index->index_epp) * index->index_esize;
trans->jentry->mark = CACHEFS_ONDISC_UJNL_INDEX_ALLOCING;
- if (!target->cookie->idef)
+ if (!cookie->idef)
trans->jentry->mark = CACHEFS_ONDISC_UJNL_INODE_ALLOCING;
- trans->jentry->index = iinode->vfs_inode.i_ino;
+ trans->jentry->index = index->vfs_inode.i_ino;
trans->jentry->ixentry = ixentry;
trans->jentry->ino = ino;
- trans->jentry->size = iinode->vfs_inode.i_size;
+ trans->jentry->size = index->vfs_inode.i_size;
trans->jentry->pgnum = ixpage->index;
trans->jentry->block = __cachefs_get_page_block(ixpage)->bix;
trans->jentry->entry = offset;
- trans->jentry->count = iinode->index_esize;
+ trans->jentry->count = index->index_esize;
trans->jentry->auxblock = inonext;
trans->jentry->upblock = ixnext;
ino_offset = ino % super->istorage->index_epp;
ino_offset <<= super->layout->storage_bits;
- cachefs_trans_affects_page(trans,ixpage,offset,iinode->index_esize);
- cachefs_trans_affects_inode(trans,iinode);
+ cachefs_trans_affects_page(trans,ixpage,offset,index->index_esize);
+ cachefs_trans_affects_inode(trans,index);
cachefs_trans_affects_page(trans,inopage,ino_offset,super->layout->storage_size);
cachefs_trans_affects_inode(trans,super->istorage);
@@ -373,18 +383,18 @@
xent->ino = ino;
xent->type = CACHEFS_ONDISC_INDEX_DATAFILE;
- if (target->cookie->idef)
+ if (cookie->idef)
xent->type = CACHEFS_ONDISC_INDEX_INDEXFILE;
- index->cookie->idef->update(target->cookie->netfs_data,xent->data);
+ index->cookie->idef->update(cookie->netfs_data,xent->data);
kunmap(ixpage);
/* modify the index inode storage entry */
- storage = kmap(iinode->storage) + iinode->storage_offset;
+ storage = kmap(index->storage) + index->storage_offset;
storage->freelink = ixnext;
storage->atime = CURRENT_TIME.tv_sec;
- kunmap(iinode->storage);
+ kunmap(index->storage);
/* fill the inode definition */
storage = kmap(inopage) + ino_offset;
@@ -396,11 +406,11 @@
storage->freelink = UINT_MAX;
storage->mtime = CURRENT_TIME.tv_sec;
storage->atime = CURRENT_TIME.tv_sec;
- storage->pindex = iinode->vfs_inode.i_ino;
+ storage->pindex = index->vfs_inode.i_ino;
storage->pindex_entry = ixentry;
- if (target->cookie->idef) {
- struct cachefs_index_def *definition = target->cookie->idef;
+ if (cookie->idef) {
+ struct cachefs_index_def *definition = cookie->idef;
storage->index_dsize = definition->data_size;
storage->index_esize = storage->index_dsize;
@@ -427,38 +437,21 @@
cachefs_trans_commit(trans);
trans = NULL;
- target->ino = ino;
+ /* note that it is now present */
+ list_for_each_entry(srch,&cookie->search_results,link) {
+ if (srch->super==super) {
+ srch->ino = ino;
+ break;
+ }
+ }
+
+ *_newino = ino;
error:
if (trans) cachefs_trans_put(trans);
if (inopage) page_cache_release(inopage);
if (ixpage) page_cache_release(ixpage);
- kleave(" = %d",ret);
- return ret;
-} /* end cachefs_index_allocate() */
-
-/*****************************************************************************/
-/*
- * allocate an entry in the specified index and associate a new inode with it
- */
-int cachefs_index_add(struct cachefs_active_inode *index,
- struct cachefs_active_inode *target)
-{
- struct cachefs_inode *iinode;
- int ret;
-
- kenter("{%u,%s},",index->ino,index->cookie->idef->name);
-
- /* get the index inode */
- ret = cachefs_iget(index->super,index->ino,&iinode);
- if (ret<0)
- goto error;
-
- ret = cachefs_index_allocate(iinode,index,target);
-
- cachefs_iput(iinode);
- error:
kleave(" = %d",ret);
return ret;
} /* end cachefs_index_add() */
Index: cachefs-int.h
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/cachefs-int.h,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -r1.29 -r1.30
--- cachefs-int.h 24 Apr 2003 15:14:10 -0000 1.29
+++ cachefs-int.h 29 Apr 2003 15:24:06 -0000 1.30
@@ -27,7 +27,8 @@
struct cachefs_super;
struct cachefs_block;
-struct cachefs_active_inode;
+struct cachefs_inode;
+struct cachefs_search_result;
extern struct address_space_operations cachefs_addrspace_operations;
extern struct address_space_operations cachefs_vio_addrspace_operations;
@@ -75,6 +76,10 @@
* reclaimable inodes */
#define CACHEFS_SUPER_WITHDRAWN 4 /* true if cache has been withdrawn */
+ /* index management */
+ struct list_head ino_list; /* list of data/index inodes */
+ spinlock_t ino_list_lock;
+
/* block allocation and recycling management */
struct rb_root blk_tree; /* block mapping tree */
rwlock_t blk_tree_lock;
@@ -167,15 +172,11 @@
atomic_t cnt_ujnl_akwr; /* number of ACKs written */
atomic_t cnt_ujnl_free; /* number of marks freed */
- /* index management */
- struct rb_root ino_tree; /* tree of active inodes */
- spinlock_t ino_tree_lock;
-
/* superblock copy */
struct cachefs_ondisc_superblock *layout;
};
-extern void cachefs_add_cache(struct cachefs_super *super, struct cachefs_active_inode *active);
+extern void cachefs_add_cache(struct cachefs_super *super, struct cachefs_search_result *srch);
extern void cachefs_withdraw_cache(struct cachefs_super *super);
extern void cachefs_recycle_unready_blocks(struct cachefs_super *super);
@@ -196,51 +197,22 @@
atomic_t children; /* number of children of this cookie */
struct cachefs_index_def *idef; /* index definition */
struct cachefs_cookie *iparent; /* index holding this entry */
- struct list_head active_inodes; /* inode(s) backing this file/index */
+ struct list_head search_results; /* results of searching iparent */
+ struct list_head backing_inodes; /* inode(s) backing this file/index */
struct rw_semaphore sem;
+ struct cachefs_netfs *netfs; /* owner network fs definition */
void *netfs_data; /* back pointer to netfs */
};
-extern kmem_cache_t *cachefs_cookie_jar;
-
-extern void cachefs_cookie_init_once(void *_cookie, kmem_cache_t *cachep, unsigned long flags);
-
-/*****************************************************************************/
-/*
- * cache file and directory management
- * - negative entry if .ino==0 (and node will be unused)
- */
-struct cachefs_active_inode
-{
- struct rb_node node; /* node in active inode tracking tree */
- atomic_t usage; /* usage count */
- struct cachefs_super *super; /* cache in which resident */
- unsigned ino; /* inode in cache */
- unsigned long flags;
-#define CACHEFS_ACTIVE_INODE_ISINDEX 0 /* T if inode is index file (F if file) */
-#define CACHEFS_ACTIVE_INODE_LIVE 1 /* T if struct is live */
-#define CACHEFS_ACTIVE_INODE_INITING 2 /* T if struct is being initialised */
-#define CACHEFS_ACTIVE_INODE_RELEASING 3 /* T if inode is being released */
-#define CACHEFS_ACTIVE_INODE_RECYCLING 4 /* T if inode is being retired */
-#define CACHEFS_ACTIVE_INODE_WITHDRAWN 5 /* T if inode has been withdrawn */
-
- struct cachefs_block *storage; /* block containing data storage info */
- wait_queue_head_t initwq; /* initialisation wait queue */
-
- struct list_head link; /* link in object->active_inodes */
- struct cachefs_cookie *cookie; /* netfs's file/index object */
- struct rw_semaphore sem; /* guard on object pointer */
+struct cachefs_search_result {
+ struct list_head link; /* link in search_results */
+ struct cachefs_super *super; /* superblock searched */
+ unsigned ino; /* inode number (or 0 if negative) */
};
-extern void cachefs_withdraw_active_inode(struct cachefs_active_inode *active);
-
-extern int cachefs_index_search(struct cachefs_active_inode *index,
- struct cachefs_active_inode *target);
-
-extern int cachefs_index_add(struct cachefs_active_inode *index,
- struct cachefs_active_inode *target);
+extern kmem_cache_t *cachefs_cookie_jar;
-extern int cachefs_index_zap(struct cachefs_super *super);
+extern void cachefs_cookie_init_once(void *_cookie, kmem_cache_t *cachep, unsigned long flags);
/*****************************************************************************/
/*
@@ -249,14 +221,28 @@
struct cachefs_inode
{
struct inode vfs_inode; /* VFS inode record for this file */
- struct cachefs_active_inode *active; /* inode management */
- unsigned storage_offset; /* data storage record offset */
+
+ struct page *storage; /* page in mem containing storage info */
+ unsigned short storage_offset; /* data storage record offset */
+
unsigned short index_dsize; /* size of data in each index entry */
unsigned short index_esize; /* size of index entries */
unsigned short index_epp; /* number of index entries per page */
- struct page *storage; /* page holding storage record */
+
+ unsigned long flags;
+#define CACHEFS_ACTIVE_INODE_ISINDEX 0 /* T if inode is index file (F if file) */
+#define CACHEFS_ACTIVE_INODE_RELEASING 1 /* T if inode is being released */
+#define CACHEFS_ACTIVE_INODE_RECYCLING 2 /* T if inode is being retired */
+#define CACHEFS_ACTIVE_INODE_WITHDRAWN 3 /* T if inode has been withdrawn */
+
+ struct list_head super_link; /* link in super->ino_list */
+ struct list_head cookie_link; /* link in cookie->backing_inodes */
+ struct cachefs_cookie *cookie; /* netfs's file/index object */
};
+extern struct inode_operations cachefs_status_inode_operations;
+extern struct file_operations cachefs_status_file_operations;
+
#define CACHEFS_FS_I(inode) container_of((inode),struct cachefs_inode,vfs_inode)
extern int cachefs_iget(struct cachefs_super *super, ino_t ino, struct cachefs_inode **_inode);
@@ -281,8 +267,17 @@
page_cache_release(page);
}
-extern struct inode_operations cachefs_status_inode_operations;
-extern struct file_operations cachefs_status_file_operations;
+extern void cachefs_withdraw_inode(struct cachefs_inode *inode);
+
+extern int cachefs_index_search(struct cachefs_inode *index,
+ struct cachefs_cookie *target,
+ unsigned *_entry);
+
+extern int cachefs_index_add(struct cachefs_inode *index,
+ struct cachefs_cookie *cookie,
+ unsigned *_newino);
+
+extern int cachefs_index_zap(struct cachefs_super *super);
/*****************************************************************************/
/*
Index: block.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/block.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- block.c 24 Apr 2003 12:02:34 -0000 1.3
+++ block.c 29 Apr 2003 15:24:06 -0000 1.4
@@ -370,6 +370,7 @@
/*****************************************************************************/
/*
* indicate that we're going to modify a block
+ * - the page pointed to by *_page may be COW'd and replaced with a different page
*/
void cachefs_block_modify(struct cachefs_super *super,
struct cachefs_block *block,
@@ -383,7 +384,7 @@
page = block->page;
get_page(page);
page = xchg(_page,page);
- put_page(page);
+ if (page) put_page(page);
}
_leave("");
Index: aops.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/aops.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -r1.27 -r1.28
--- aops.c 25 Apr 2003 16:04:10 -0000 1.27
+++ aops.c 29 Apr 2003 15:24:06 -0000 1.28
@@ -69,25 +69,25 @@
.invalidatepage = cachefs_invalidatepage,
};
-int cachefs_get_page_private(struct page *page, struct cachefs_page **_cookie, unsigned gfp_flags)
+int cachefs_get_page_private(struct page *page, struct cachefs_page **_pageio, unsigned gfp_flags)
{
- struct cachefs_page *cookie = (struct cachefs_page*) page->private;
+ struct cachefs_page *pageio = (struct cachefs_page*) page->private;
- *_cookie = NULL;
+ *_pageio = NULL;
- if (!cookie) {
- cookie = kmalloc(sizeof(*cookie),gfp_flags);
- if (!cookie)
+ if (!pageio) {
+ pageio = kmalloc(sizeof(*pageio),gfp_flags);
+ if (!pageio)
return -ENOMEM;
- memset(cookie,0,sizeof(*cookie));
- rwlock_init(&cookie->lock);
+ memset(pageio,0,sizeof(*pageio));
+ rwlock_init(&pageio->lock);
- page->private = (unsigned long) cookie;
+ page->private = (unsigned long) pageio;
SetPagePrivate(page);
}
- *_cookie = cookie;
+ *_pageio = pageio;
return 0;
}
@@ -278,14 +278,14 @@
static int cachefs_do_readpage(struct bio **_bio, struct page *page, unsigned nr_pages,
sector_t *last_block_in_bio)
{
- struct cachefs_page *cookie;
+ struct cachefs_page *pageio;
struct inode *inode = page->mapping->host;
sector_t last_block;
int ret;
_enter("");
- ret = cachefs_get_page_private(page,&cookie,GFP_KERNEL);
+ ret = cachefs_get_page_private(page,&pageio,GFP_KERNEL);
if (ret<0)
goto error;
@@ -304,7 +304,7 @@
}
/* handle a hole */
- if (!cookie->mapped_block) {
+ if (!pageio->mapped_block) {
memset(kmap(page),0,PAGE_SIZE);
flush_dcache_page(page);
kunmap(page);
@@ -313,12 +313,12 @@
}
else {
/* this page will go to BIO. Do we need to send this BIO off first? */
- if (*_bio && *last_block_in_bio != cookie->mapped_block->bix-1)
+ if (*_bio && *last_block_in_bio != pageio->mapped_block->bix-1)
cachefs_io_bio_submit(READ,_bio);
alloc_new:
if (!*_bio) {
- ret = cachefs_io_alloc(inode->i_sb,cookie->mapped_block->bix,
+ ret = cachefs_io_alloc(inode->i_sb,pageio->mapped_block->bix,
nr_pages,GFP_KERNEL,_bio);
if (ret<0)
goto error;
@@ -329,10 +329,10 @@
goto alloc_new;
}
- if (test_bit(CACHEFS_PAGE_BOUNDARY,&cookie->flags))
+ if (test_bit(CACHEFS_PAGE_BOUNDARY,&pageio->flags))
cachefs_io_bio_submit(READ,_bio);
else
- *last_block_in_bio = cookie->mapped_block->bix;
+ *last_block_in_bio = pageio->mapped_block->bix;
}
_leave(" = 0");
@@ -425,19 +425,19 @@
void cachefs_do_writepage(struct bio **_bio, struct page *page,
sector_t *last_block_in_bio, int *_ret)
{
- struct cachefs_page *cookie;
+ struct cachefs_page *pageio;
struct inode *inode = page->mapping->host;
unsigned long end_index;
int ret;
_enter(",{%lu},%llu,",page->index,*last_block_in_bio);
- ret = cachefs_get_page_private(page,&cookie,GFP_KERNEL);
+ ret = cachefs_get_page_private(page,&pageio,GFP_KERNEL);
if (ret<0)
goto error;
/* deal with a block not that's yet mapped */
- if (!cookie->mapped_block) {
+ if (!pageio->mapped_block) {
/* map the page to a block on the blockdev */
BUG_ON(!PageUptodate(page));
@@ -447,8 +447,8 @@
goto out;
}
- if (test_bit(CACHEFS_PAGE_NEW,&cookie->flags))
- BUG();//unmap_underlying_metadata(inode->i_sb->s_bdev,cookie->mapped_block)
+ if (test_bit(CACHEFS_PAGE_NEW,&pageio->flags))
+ BUG();//unmap_underlying_metadata(inode->i_sb->s_bdev,pageio->mapped_block)
/* clear the tail end of the last block */
end_index = inode->i_size >> PAGE_CACHE_SHIFT;
@@ -464,13 +464,13 @@
}
/* dispatch the outstanding BIO if not immediately preceding this page */
- if (*_bio && *last_block_in_bio != cookie->mapped_block->bix-1)
+ if (*_bio && *last_block_in_bio != pageio->mapped_block->bix-1)
cachefs_io_bio_submit(WRITE,_bio);
alloc_new:
if (!*_bio) {
ret = cachefs_io_alloc(inode->i_sb,
- cookie->mapped_block->bix,
+ pageio->mapped_block->bix,
bio_get_nr_vecs(inode->i_sb->s_bdev),
GFP_NOFS|__GFP_HIGH,
_bio);
@@ -487,12 +487,12 @@
BUG_ON(PageWriteback(page));
SetPageWriteback(page);
unlock_page(page);
- if (test_bit(CACHEFS_PAGE_BOUNDARY,&cookie->flags)) {
+ if (test_bit(CACHEFS_PAGE_BOUNDARY,&pageio->flags)) {
cachefs_io_bio_submit(WRITE,_bio);
// write_boundary_block(inode->i_sb->s_bdev,
-// cookie->mapped_block->bix, 1 << PAGE_CACHE_SHIFT);
+// pageio->mapped_block->bix, 1 << PAGE_CACHE_SHIFT);
} else {
- *last_block_in_bio = cookie->mapped_block->bix;
+ *last_block_in_bio = pageio->mapped_block->bix;
}
goto out;
@@ -629,7 +629,7 @@
*/
static int cachefs_writepage(struct page *page, struct writeback_control *wbc)
{
- struct cachefs_page *cookie;
+ struct cachefs_page *pageio;
unsigned long end_index;
struct inode * const inode = page->mapping->host;
struct bio *bio;
@@ -641,7 +641,7 @@
BUG_ON(!PageUptodate(page));
BUG_ON(PageWriteback(page));
- ret = cachefs_get_page_private(page,&cookie,GFP_NOFS);
+ ret = cachefs_get_page_private(page,&pageio,GFP_NOFS);
if (ret<0)
goto error;
@@ -663,20 +663,20 @@
kunmap_atomic(kaddr, KM_USER0);
}
- if (!cookie->mapped_block) {
+ if (!pageio->mapped_block) {
ret = cachefs_get_block(inode,page,1);
if (ret<0)
goto error;
- if (!cookie->mapped_block) BUG();
+ if (!pageio->mapped_block) BUG();
- if (test_bit(CACHEFS_PAGE_NEW,&cookie->flags)) {
+ if (test_bit(CACHEFS_PAGE_NEW,&pageio->flags)) {
//unmap_underlying_metadata(bh->b_bdev,bh->b_blocknr);
- clear_bit(CACHEFS_PAGE_NEW,&cookie->flags);
+ clear_bit(CACHEFS_PAGE_NEW,&pageio->flags);
}
}
- ret = cachefs_io_alloc(inode->i_sb,cookie->mapped_block->bix,1,GFP_NOFS,&bio);
+ ret = cachefs_io_alloc(inode->i_sb,pageio->mapped_block->bix,1,GFP_NOFS,&bio);
if (ret<0)
goto error;
@@ -699,7 +699,7 @@
*/
static int cachefs_prepare_write(struct file *file, struct page *page, unsigned from, unsigned to)
{
- struct cachefs_page *cookie;
+ struct cachefs_page *pageio;
struct inode *inode = page->mapping->host;
struct bio *bio = NULL;
int ret;
@@ -708,21 +708,21 @@
_enter(",{%lu},%u,%u",page->index,from,to);
- ret = cachefs_get_page_private(page,&cookie,GFP_NOFS);
+ ret = cachefs_get_page_private(page,&pageio,GFP_NOFS);
if (ret<0)
goto error;
/* map the page to a disc block and prepare a new page for writing */
- if (!cookie->mapped_block) {
+ if (!pageio->mapped_block) {
ret = cachefs_get_block(inode,page,1);
if (ret<0)
goto error;
- BUG_ON(!cookie->mapped_block);
+ BUG_ON(!pageio->mapped_block);
}
if (!PageUptodate(page)) {
- if (test_bit(CACHEFS_PAGE_NEW,&cookie->flags)) {
+ if (test_bit(CACHEFS_PAGE_NEW,&pageio->flags)) {
//unmap_underlying_metadata(bh->b_bdev,bh->b_blocknr);
if (from>0 || to<PAGE_SIZE) {
void *kaddr;
@@ -744,7 +744,7 @@
goto error;
bio->bi_bdev = inode->i_sb->s_bdev;
- bio->bi_sector = cookie->mapped_block->bix;
+ bio->bi_sector = pageio->mapped_block->bix;
bio->bi_sector <<= (PAGE_SHIFT - inode->i_sb->s_blocksize_bits);
bio->bi_end_io = cachefs_io_end_io_prepare;
bio->bi_private = &cpl;
@@ -757,19 +757,19 @@
wait_for_completion(&cpl);
}
- clear_bit(CACHEFS_PAGE_NEW,&cookie->flags);
+ clear_bit(CACHEFS_PAGE_NEW,&pageio->flags);
_leave(" = 0");
return 0;
error:
- if (test_bit(CACHEFS_PAGE_NEW,&cookie->flags)) {
+ if (test_bit(CACHEFS_PAGE_NEW,&pageio->flags)) {
memset(kmap(page),0,PAGE_SIZE);
flush_dcache_page(page);
kunmap(page);
SetPageUptodate(page);
set_page_dirty(page);
- clear_bit(CACHEFS_PAGE_NEW,&cookie->flags);
+ clear_bit(CACHEFS_PAGE_NEW,&pageio->flags);
}
_leave(" = %d",ret);
@@ -806,7 +806,7 @@
static int cachefs_invalidatepage(struct page *page, unsigned long offset)
{
struct cachefs_block *block;
- struct cachefs_page *cookie;
+ struct cachefs_page *pageio;
int ret = 1;
_enter("{%lu},%lu",page->index,offset);
@@ -815,10 +815,10 @@
if (!PagePrivate(page))
goto out;
- cookie = (struct cachefs_page*) page->private;
- block = xchg(&cookie->mapped_block,NULL);
+ pageio = (struct cachefs_page*) page->private;
+ block = xchg(&pageio->mapped_block,NULL);
ClearPageMappedToDisk(page);
- cookie->flags = 0;
+ pageio->flags = 0;
if (block) cachefs_block_put(page->mapping->host->i_sb->s_fs_info,block);
@@ -843,22 +843,22 @@
static int cachefs_releasepage(struct page *page, int gfp_flags)
{
struct cachefs_block *block;
- struct cachefs_page *cookie;
+ struct cachefs_page *pageio;
_enter("{%lu},%x",page->index,gfp_flags);
if (PagePrivate(page)) {
- cookie = (struct cachefs_page*) page->private;
+ pageio = (struct cachefs_page*) page->private;
page->private = 0;
ClearPagePrivate(page);
ClearPageMappedToDisk(page);
- if (cookie) {
- block = xchg(&cookie->mapped_block,NULL);
+ if (pageio) {
+ block = xchg(&pageio->mapped_block,NULL);
if (block)
cachefs_block_put(page->mapping->host->i_sb->s_fs_info,block);
- dbgfree(cookie);
- kfree(cookie);
+ dbgfree(pageio);
+ kfree(pageio);
}
}
@@ -1104,7 +1104,7 @@
struct cachefs_io_block_path path[4];
struct cachefs_inode *inode = CACHEFS_FS_I(vfs_inode);
struct cachefs_super *super = inode->vfs_inode.i_sb->s_fs_info;
- struct cachefs_page *cookie = __cachefs_get_page_private(page);
+ struct cachefs_page *pageio = __cachefs_get_page_private(page);
const size_t ptrperblk = PAGE_SIZE / sizeof(cachefs_blockix_t);
sector_t iblock;
size_t ptrqty, notboundary = 1;
@@ -1113,7 +1113,7 @@
#if 0
if (inode->vfs_inode.i_ino == CACHEFS_INO_WIBBLE) {
ret = cachefs_block_insert(inode->vfs_inode.i_sb->s_fs_info,page->index+1000,
- &cookie->mapped_block);
+ &pageio->mapped_block);
if (ret==0)
SetPageMappedToDisk(page);
return ret;
@@ -1123,7 +1123,7 @@
_enter("%lu,{%p}%lu,%d",inode->vfs_inode.i_ino,page,page->index,create);
- BUG_ON(cookie->mapped_block);
+ BUG_ON(pageio->mapped_block);
if (page->index/ptrperblk >= ptrperblk) {
_leave(" = -EIO [range]");
@@ -1295,7 +1295,7 @@
}
if (ret<0) {
- struct cachefs_block *block = xchg(&cookie->mapped_block,NULL);
+ struct cachefs_block *block = xchg(&pageio->mapped_block,NULL);
if (block)
cachefs_block_put(inode->vfs_inode.i_sb->s_fs_info,block);
_leave(" = %d",ret);
@@ -1304,16 +1304,16 @@
/* got the block - set the block offset in the page mapping record */
if (path[0].flags & CACHEFS_BLOCK_NEW)
- set_bit(CACHEFS_PAGE_NEW,&cookie->flags);
+ set_bit(CACHEFS_PAGE_NEW,&pageio->flags);
_debug("notboundary = %u",notboundary);
if (!notboundary)
- set_bit(CACHEFS_PAGE_BOUNDARY,&cookie->flags);
+ set_bit(CACHEFS_PAGE_BOUNDARY,&pageio->flags);
_leave(" = 0 [bix=%u %c%c]",
- cookie->mapped_block->bix,
- test_bit(CACHEFS_PAGE_BOUNDARY,&cookie->flags) ? 'b' : '-',
- test_bit(CACHEFS_PAGE_NEW,&cookie->flags) ? 'n' : '-'
+ pageio->mapped_block->bix,
+ test_bit(CACHEFS_PAGE_BOUNDARY,&pageio->flags) ? 'b' : '-',
+ test_bit(CACHEFS_PAGE_NEW,&pageio->flags) ? 'n' : '-'
);
return 0;
} /* end cachefs_get_block() */
@@ -1364,7 +1364,7 @@
int cachefs_file_readpage(struct cachefs_netfs *netfs, struct page *page)
{
struct cachefs_block *block;
- struct cachefs_page *cookie;
+ struct cachefs_page *pageio;
struct super_block *sb;
unsigned long flags;
struct bio *bio;
@@ -1372,18 +1372,18 @@
kenter("{%s},{%lu}",netfs->name,page->index);
- ret = netfs->ops->get_page_cookie(page,&cookie);
+ ret = netfs->ops->get_page_cookie(page,&pageio);
if (ret<0)
goto error;
/* protect against cache removal */
- read_lock_irqsave(&cookie->lock,flags);
+ read_lock_irqsave(&pageio->lock,flags);
- block = cookie->mapped_block;
+ block = pageio->mapped_block;
if (block)
cachefs_block_get(block);
- read_unlock_irqrestore(&cookie->lock,flags);
+ read_unlock_irqrestore(&pageio->lock,flags);
ret = -ENODATA;
if (!block)
More information about the linux-afs-cvs
mailing list