From 1fff7707f278bdead2fdb958745961c988d4d377 Mon Sep 17 00:00:00 2001 From: Shreyas Siravara Date: Thu, 26 Apr 2018 18:15:02 -0700 Subject: [PATCH] Add & export a call to initialize the pagecache --- include/nfsc/libnfs.h | 6 ++++++ lib/libnfs.c | 12 ++++++++++++ lib/nfs_v3.c | 13 +++---------- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/include/nfsc/libnfs.h b/include/nfsc/libnfs.h index 2f2406c9..09dcf1ce 100755 --- a/include/nfsc/libnfs.h +++ b/include/nfsc/libnfs.h @@ -278,6 +278,12 @@ EXTERN int nfs_set_version(struct nfs_context *nfs, int version); EXTERN void nfs_pagecache_invalidate(struct nfs_context *nfs, struct nfsfh *nfsfh); +/* + * Initialize the pagecache + */ +EXTERN void nfs_pagecache_init(struct nfs_context *nfs, + struct nfsfh *nfsfh); + /* * MOUNT THE EXPORT */ diff --git a/lib/libnfs.c b/lib/libnfs.c index c122af52..28464145 100755 --- a/lib/libnfs.c +++ b/lib/libnfs.c @@ -199,6 +199,18 @@ nfs_pagecache_get(struct nfs_pagecache *pagecache, uint64_t offset) return e->buf; } +void nfs_pagecache_init(struct nfs_context *nfs, struct nfsfh *nfsfh) { + /* init page cache */ + if (nfs->rpc->pagecache) { + nfsfh->pagecache.num_entries = nfs->rpc->pagecache; + nfsfh->pagecache.ttl = nfs->rpc->pagecache_ttl; + nfsfh->pagecache.entries = malloc(sizeof(struct nfs_pagecache_entry) * nfsfh->pagecache.num_entries); + nfs_pagecache_invalidate(nfs, nfsfh); + RPC_LOG(nfs->rpc, 2, "init pagecache entries %d pagesize %d\n", + nfsfh->pagecache.num_entries, NFS_BLKSIZE); + } +} + void nfs_set_auth(struct nfs_context *nfs, struct AUTH *auth) { diff --git a/lib/nfs_v3.c b/lib/nfs_v3.c index ed8b929b..52908250 100644 --- a/lib/nfs_v3.c +++ b/lib/nfs_v3.c @@ -4917,20 +4917,13 @@ nfs3_open_cb(struct rpc_context *rpc, int status, void *command_data, nfsfh->is_append = 1; } + /* init the pagecache */ + nfs_pagecache_init(nfs, nfsfh); + /* steal the filehandle */ nfsfh->fh = data->fh; data->fh.val = NULL; - /* init page cache */ - if (rpc->pagecache) { - nfsfh->pagecache.num_entries = rpc->pagecache; - nfsfh->pagecache.ttl = rpc->pagecache_ttl; - nfsfh->pagecache.entries = malloc(sizeof(struct nfs_pagecache_entry) * nfsfh->pagecache.num_entries); - nfs_pagecache_invalidate(nfs, nfsfh); - RPC_LOG(nfs->rpc, 2, "init pagecache entries %d pagesize %d\n", - nfsfh->pagecache.num_entries, NFS_BLKSIZE); - } - data->cb(0, nfs, nfsfh, data->private_data); free_nfs_cb_data(data); }