Skip to content

Commit a78ce05

Browse files
kvaneeshericvh
authored andcommitted
fs/9p: Add v9fs_inode
Switch to the fscache code to v9fs_inode. We will later use v9fs_inode in cache=loose mode to track the inode cache validity timeout. Ie if we find an inode in cache older that a specific jiffie range we will consider it stale Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> Signed-off-by: Venkateswararao Jujjuri <jvrao@linux.vnet.ibm.com> Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
1 parent a121190 commit a78ce05

8 files changed

Lines changed: 184 additions & 220 deletions

File tree

‎fs/9p/cache.c‎

Lines changed: 70 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -33,67 +33,11 @@
3333

3434
#define CACHETAG_LEN 11
3535

36-
struct kmem_cache *vcookie_cache;
37-
3836
struct fscache_netfs v9fs_cache_netfs = {
3937
.name = "9p",
4038
.version = 0,
4139
};
4240

43-
static void init_once(void *foo)
44-
{
45-
struct v9fs_cookie *vcookie = (struct v9fs_cookie *) foo;
46-
vcookie->fscache = NULL;
47-
vcookie->qid = NULL;
48-
inode_init_once(&vcookie->inode);
49-
}
50-
51-
/**
52-
* v9fs_init_vcookiecache - initialize a cache for vcookies to maintain
53-
* vcookie to inode mapping
54-
*
55-
* Returns 0 on success.
56-
*/
57-
58-
static int v9fs_init_vcookiecache(void)
59-
{
60-
vcookie_cache = kmem_cache_create("vcookie_cache",
61-
sizeof(struct v9fs_cookie),
62-
0, (SLAB_RECLAIM_ACCOUNT|
63-
SLAB_MEM_SPREAD),
64-
init_once);
65-
if (!vcookie_cache)
66-
return -ENOMEM;
67-
68-
return 0;
69-
}
70-
71-
/**
72-
* v9fs_destroy_vcookiecache - destroy the cache of vcookies
73-
*
74-
*/
75-
76-
static void v9fs_destroy_vcookiecache(void)
77-
{
78-
kmem_cache_destroy(vcookie_cache);
79-
}
80-
81-
int __v9fs_cache_register(void)
82-
{
83-
int ret;
84-
ret = v9fs_init_vcookiecache();
85-
if (ret < 0)
86-
return ret;
87-
88-
return fscache_register_netfs(&v9fs_cache_netfs);
89-
}
90-
91-
void __v9fs_cache_unregister(void)
92-
{
93-
v9fs_destroy_vcookiecache();
94-
fscache_unregister_netfs(&v9fs_cache_netfs);
95-
}
96-
9741
/**
9842
* v9fs_random_cachetag - Generate a random tag to be associated
9943
* with a new cache session.
@@ -133,9 +77,9 @@ static uint16_t v9fs_cache_session_get_key(const void *cookie_netfs_data,
13377
}
13478

13579
const struct fscache_cookie_def v9fs_cache_session_index_def = {
136-
.name = "9P.session",
137-
.type = FSCACHE_COOKIE_TYPE_INDEX,
138-
.get_key = v9fs_cache_session_get_key,
80+
.name = "9P.session",
81+
.type = FSCACHE_COOKIE_TYPE_INDEX,
82+
.get_key = v9fs_cache_session_get_key,
13983
};
14084

14185
void v9fs_cache_session_get_cookie(struct v9fs_session_info *v9ses)
@@ -163,55 +107,55 @@ void v9fs_cache_session_put_cookie(struct v9fs_session_info *v9ses)
163107
static uint16_t v9fs_cache_inode_get_key(const void *cookie_netfs_data,
164108
void *buffer, uint16_t bufmax)
165109
{
166-
const struct v9fs_cookie *vcookie = cookie_netfs_data;
167-
memcpy(buffer, &vcookie->qid->path, sizeof(vcookie->qid->path));
168-
169-
P9_DPRINTK(P9_DEBUG_FSC, "inode %p get key %llu", &vcookie->inode,
170-
vcookie->qid->path);
171-
return sizeof(vcookie->qid->path);
110+
const struct v9fs_inode *v9inode = cookie_netfs_data;
111+
memcpy(buffer, &v9inode->fscache_key->path,
112+
sizeof(v9inode->fscache_key->path));
113+
P9_DPRINTK(P9_DEBUG_FSC, "inode %p get key %llu", &v9inode->vfs_inode,
114+
v9inode->fscache_key->path);
115+
return sizeof(v9inode->fscache_key->path);
172116
}
173117

174118
static void v9fs_cache_inode_get_attr(const void *cookie_netfs_data,
175119
uint64_t *size)
176120
{
177-
const struct v9fs_cookie *vcookie = cookie_netfs_data;
178-
*size = i_size_read(&vcookie->inode);
121+
const struct v9fs_inode *v9inode = cookie_netfs_data;
122+
*size = i_size_read(&v9inode->vfs_inode);
179123

180-
P9_DPRINTK(P9_DEBUG_FSC, "inode %p get attr %llu", &vcookie->inode,
124+
P9_DPRINTK(P9_DEBUG_FSC, "inode %p get attr %llu", &v9inode->vfs_inode,
181125
*size);
182126
}
183127

184128
static uint16_t v9fs_cache_inode_get_aux(const void *cookie_netfs_data,
185129
void *buffer, uint16_t buflen)
186130
{
187-
const struct v9fs_cookie *vcookie = cookie_netfs_data;
188-
memcpy(buffer, &vcookie->qid->version, sizeof(vcookie->qid->version));
189-
190-
P9_DPRINTK(P9_DEBUG_FSC, "inode %p get aux %u", &vcookie->inode,
191-
vcookie->qid->version);
192-
return sizeof(vcookie->qid->version);
131+
const struct v9fs_inode *v9inode = cookie_netfs_data;
132+
memcpy(buffer, &v9inode->fscache_key->version,
133+
sizeof(v9inode->fscache_key->version));
134+
P9_DPRINTK(P9_DEBUG_FSC, "inode %p get aux %u", &v9inode->vfs_inode,
135+
v9inode->fscache_key->version);
136+
return sizeof(v9inode->fscache_key->version);
193137
}
194138

195139
static enum
196140
fscache_checkaux v9fs_cache_inode_check_aux(void *cookie_netfs_data,
197141
const void *buffer,
198142
uint16_t buflen)
199143
{
200-
const struct v9fs_cookie *vcookie = cookie_netfs_data;
144+
const struct v9fs_inode *v9inode = cookie_netfs_data;
201145

202-
if (buflen != sizeof(vcookie->qid->version))
146+
if (buflen != sizeof(v9inode->fscache_key->version))
203147
return FSCACHE_CHECKAUX_OBSOLETE;
204148

205-
if (memcmp(buffer, &vcookie->qid->version,
206-
sizeof(vcookie->qid->version)))
149+
if (memcmp(buffer, &v9inode->fscache_key->version,
150+
sizeof(v9inode->fscache_key->version)))
207151
return FSCACHE_CHECKAUX_OBSOLETE;
208152

209153
return FSCACHE_CHECKAUX_OKAY;
210154
}
211155

212156
static void v9fs_cache_inode_now_uncached(void *cookie_netfs_data)
213157
{
214-
struct v9fs_cookie *vcookie = cookie_netfs_data;
158+
struct v9fs_inode *v9inode = cookie_netfs_data;
215159
struct pagevec pvec;
216160
pgoff_t first;
217161
int loop, nr_pages;
@@ -220,7 +164,7 @@ static void v9fs_cache_inode_now_uncached(void *cookie_netfs_data)
220164
first = 0;
221165

222166
for (;;) {
223-
nr_pages = pagevec_lookup(&pvec, vcookie->inode.i_mapping,
167+
nr_pages = pagevec_lookup(&pvec, v9inode->vfs_inode.i_mapping,
224168
first,
225169
PAGEVEC_SIZE - pagevec_count(&pvec));
226170
if (!nr_pages)
@@ -249,115 +193,114 @@ const struct fscache_cookie_def v9fs_cache_inode_index_def = {
249193

250194
void v9fs_cache_inode_get_cookie(struct inode *inode)
251195
{
252-
struct v9fs_cookie *vcookie;
196+
struct v9fs_inode *v9inode;
253197
struct v9fs_session_info *v9ses;
254198

255199
if (!S_ISREG(inode->i_mode))
256200
return;
257201

258-
vcookie = v9fs_inode2cookie(inode);
259-
if (vcookie->fscache)
202+
v9inode = V9FS_I(inode);
203+
if (v9inode->fscache)
260204
return;
261205

262206
v9ses = v9fs_inode2v9ses(inode);
263-
vcookie->fscache = fscache_acquire_cookie(v9ses->fscache,
207+
v9inode->fscache = fscache_acquire_cookie(v9ses->fscache,
264208
&v9fs_cache_inode_index_def,
265-
vcookie);
209+
v9inode);
266210

267211
P9_DPRINTK(P9_DEBUG_FSC, "inode %p get cookie %p", inode,
268-
vcookie->fscache);
212+
v9inode->fscache);
269213
}
270214

271215
void v9fs_cache_inode_put_cookie(struct inode *inode)
272216
{
273-
struct v9fs_cookie *vcookie = v9fs_inode2cookie(inode);
217+
struct v9fs_inode *v9inode = V9FS_I(inode);
274218

275-
if (!vcookie->fscache)
219+
if (!v9inode->fscache)
276220
return;
277221
P9_DPRINTK(P9_DEBUG_FSC, "inode %p put cookie %p", inode,
278-
vcookie->fscache);
222+
v9inode->fscache);
279223

280-
fscache_relinquish_cookie(vcookie->fscache, 0);
281-
vcookie->fscache = NULL;
224+
fscache_relinquish_cookie(v9inode->fscache, 0);
225+
v9inode->fscache = NULL;
282226
}
283227

284228
void v9fs_cache_inode_flush_cookie(struct inode *inode)
285229
{
286-
struct v9fs_cookie *vcookie = v9fs_inode2cookie(inode);
230+
struct v9fs_inode *v9inode = V9FS_I(inode);
287231

288-
if (!vcookie->fscache)
232+
if (!v9inode->fscache)
289233
return;
290234
P9_DPRINTK(P9_DEBUG_FSC, "inode %p flush cookie %p", inode,
291-
vcookie->fscache);
235+
v9inode->fscache);
292236

293-
fscache_relinquish_cookie(vcookie->fscache, 1);
294-
vcookie->fscache = NULL;
237+
fscache_relinquish_cookie(v9inode->fscache, 1);
238+
v9inode->fscache = NULL;
295239
}
296240

297241
void v9fs_cache_inode_set_cookie(struct inode *inode, struct file *filp)
298242
{
299-
struct v9fs_cookie *vcookie = v9fs_inode2cookie(inode);
243+
struct v9fs_inode *v9inode = V9FS_I(inode);
300244
struct p9_fid *fid;
301245

302-
if (!vcookie->fscache)
246+
if (!v9inode->fscache)
303247
return;
304248

305-
spin_lock(&vcookie->lock);
249+
spin_lock(&v9inode->fscache_lock);
306250
fid = filp->private_data;
307251
if ((filp->f_flags & O_ACCMODE) != O_RDONLY)
308252
v9fs_cache_inode_flush_cookie(inode);
309253
else
310254
v9fs_cache_inode_get_cookie(inode);
311255

312-
spin_unlock(&vcookie->lock);
256+
spin_unlock(&v9inode->fscache_lock);
313257
}
314258

315259
void v9fs_cache_inode_reset_cookie(struct inode *inode)
316260
{
317-
struct v9fs_cookie *vcookie = v9fs_inode2cookie(inode);
261+
struct v9fs_inode *v9inode = V9FS_I(inode);
318262
struct v9fs_session_info *v9ses;
319263
struct fscache_cookie *old;
320264

321-
if (!vcookie->fscache)
265+
if (!v9inode->fscache)
322266
return;
323267

324-
old = vcookie->fscache;
268+
old = v9inode->fscache;
325269

326-
spin_lock(&vcookie->lock);
327-
fscache_relinquish_cookie(vcookie->fscache, 1);
270+
spin_lock(&v9inode->fscache_lock);
271+
fscache_relinquish_cookie(v9inode->fscache, 1);
328272

329273
v9ses = v9fs_inode2v9ses(inode);
330-
vcookie->fscache = fscache_acquire_cookie(v9ses->fscache,
274+
v9inode->fscache = fscache_acquire_cookie(v9ses->fscache,
331275
&v9fs_cache_inode_index_def,
332-
vcookie);
333-
276+
v9inode);
334277
P9_DPRINTK(P9_DEBUG_FSC, "inode %p revalidating cookie old %p new %p",
335-
inode, old, vcookie->fscache);
278+
inode, old, v9inode->fscache);
336279

337-
spin_unlock(&vcookie->lock);
280+
spin_unlock(&v9inode->fscache_lock);
338281
}
339282

340283
int __v9fs_fscache_release_page(struct page *page, gfp_t gfp)
341284
{
342285
struct inode *inode = page->mapping->host;
343-
struct v9fs_cookie *vcookie = v9fs_inode2cookie(inode);
286+
struct v9fs_inode *v9inode = V9FS_I(inode);
344287

345-
BUG_ON(!vcookie->fscache);
288+
BUG_ON(!v9inode->fscache);
346289

347-
return fscache_maybe_release_page(vcookie->fscache, page, gfp);
290+
return fscache_maybe_release_page(v9inode->fscache, page, gfp);
348291
}
349292

350293
void __v9fs_fscache_invalidate_page(struct page *page)
351294
{
352295
struct inode *inode = page->mapping->host;
353-
struct v9fs_cookie *vcookie = v9fs_inode2cookie(inode);
296+
struct v9fs_inode *v9inode = V9FS_I(inode);
354297

355-
BUG_ON(!vcookie->fscache);
298+
BUG_ON(!v9inode->fscache);
356299

357300
if (PageFsCache(page)) {
358-
fscache_wait_on_page_write(vcookie->fscache, page);
301+
fscache_wait_on_page_write(v9inode->fscache, page);
359302
BUG_ON(!PageLocked(page));
360-
fscache_uncache_page(vcookie->fscache, page);
303+
fscache_uncache_page(v9inode->fscache, page);
361304
}
362305
}
363306

@@ -380,13 +323,13 @@ static void v9fs_vfs_readpage_complete(struct page *page, void *data,
380323
int __v9fs_readpage_from_fscache(struct inode *inode, struct page *page)
381324
{
382325
int ret;
383-
const struct v9fs_cookie *vcookie = v9fs_inode2cookie(inode);
326+
const struct v9fs_inode *v9inode = V9FS_I(inode);
384327

385328
P9_DPRINTK(P9_DEBUG_FSC, "inode %p page %p", inode, page);
386-
if (!vcookie->fscache)
329+
if (!v9inode->fscache)
387330
return -ENOBUFS;
388331

389-
ret = fscache_read_or_alloc_page(vcookie->fscache,
332+
ret = fscache_read_or_alloc_page(v9inode->fscache,
390333
page,
391334
v9fs_vfs_readpage_complete,
392335
NULL,
@@ -418,13 +361,13 @@ int __v9fs_readpages_from_fscache(struct inode *inode,
418361
unsigned *nr_pages)
419362
{
420363
int ret;
421-
const struct v9fs_cookie *vcookie = v9fs_inode2cookie(inode);
364+
const struct v9fs_inode *v9inode = V9FS_I(inode);
422365

423366
P9_DPRINTK(P9_DEBUG_FSC, "inode %p pages %u", inode, *nr_pages);
424-
if (!vcookie->fscache)
367+
if (!v9inode->fscache)
425368
return -ENOBUFS;
426369

427-
ret = fscache_read_or_alloc_pages(vcookie->fscache,
370+
ret = fscache_read_or_alloc_pages(v9inode->fscache,
428371
mapping, pages, nr_pages,
429372
v9fs_vfs_readpage_complete,
430373
NULL,
@@ -453,10 +396,10 @@ int __v9fs_readpages_from_fscache(struct inode *inode,
453396
void __v9fs_readpage_to_fscache(struct inode *inode, struct page *page)
454397
{
455398
int ret;
456-
const struct v9fs_cookie *vcookie = v9fs_inode2cookie(inode);
399+
const struct v9fs_inode *v9inode = V9FS_I(inode);
457400

458401
P9_DPRINTK(P9_DEBUG_FSC, "inode %p page %p", inode, page);
459-
ret = fscache_write_page(vcookie->fscache, page, GFP_KERNEL);
402+
ret = fscache_write_page(v9inode->fscache, page, GFP_KERNEL);
460403
P9_DPRINTK(P9_DEBUG_FSC, "ret = %d", ret);
461404
if (ret != 0)
462405
v9fs_uncache_page(inode, page);
@@ -467,8 +410,8 @@ void __v9fs_readpage_to_fscache(struct inode *inode, struct page *page)
467410
*/
468411
void __v9fs_fscache_wait_on_page_write(struct inode *inode, struct page *page)
469412
{
470-
const struct v9fs_cookie *vcookie = v9fs_inode2cookie(inode);
413+
const struct v9fs_inode *v9inode = V9FS_I(inode);
471414
P9_DPRINTK(P9_DEBUG_FSC, "inode %p page %p", inode, page);
472415
if (PageFsCache(page))
473-
fscache_wait_on_page_write(vcookie->fscache, page);
416+
fscache_wait_on_page_write(v9inode->fscache, page);
474417
}

0 commit comments

Comments
 (0)