summaryrefslogtreecommitdiffstats
path: root/fs/nfs/cache.c
blob: 57f3cc411ea9656a7dd9862a2011bc3d10974f42 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63

void nfs_bl_cache_invalidate(nfs_cache *nh)
{
	unsigned long flags;
	save_flags(flags);
	cli();
	if(nh->inuse)
		nh->dead=1;
	else
	{
		kfree_s(nh->data);
		nh->data=NULL;
		nh->free=1;
	}
}

void nfs_bl_cache_revalidate(nfs_cache *nh, struct fattr fa)
{
	nh->fattr=fattr;
	nh->time=jiffies;
}

/*
 *	Find a block in the cache. We know the cache is block sized in block
 *	aligned space.
 */
 
nfs_cache *nfs_cache_find(struct inode *inode, off_t pos)
{
	nfs_cache *nh=&nfs_cache_slot[0];
	nfs_cache *ffree=NULL;
	struct nfs_fattr fattr;
	int ct=0;
	while(ct<NH_CACHE_SIZE)
	{
		if(nh->inode_num==inode->i_no && !nh->dead&&!nh->free&&nh->file_pos==pos)
		{
			if(abs(jiffies-nh->time)<EXPIRE_CACHE)
				return nh;
			/*
			 *	Revalidate
			 */
			
			if(nfs_proc_getattr(NFS_SERVER(inode), NFS_FH(inode), &fattr))
			{
				nfs_bl_cache_invalidate(nh);
				continue;	/* get attr failed */
			}
			if(nh->fattr.modified!=fattr.modified)
			{
				nfs_bl_cache_invalidate(nh);
				continue;	/* cache is out of date */
			}
			nfs_refresh_inode(inode, fattr);
			nh->fattr=fattr;
			nfs_bl_cache_revalidate(nh);
			return nh;
		}
		if(nh->free)
			ffree=nh;
	}
	return ffree;
}