[25/25] NFS: Remove redundant open context from nfs_page
diff mbox series

Message ID 20190328205239.29674-26-trond.myklebust@hammerspace.com
State New
Headers show
Series
  • Fix up soft mounts for NFSv4.x
Related show

Commit Message

Trond Myklebust March 28, 2019, 8:52 p.m. UTC
The lock context already references and tracks the open context, so
take the opportunity to save some space in struct nfs_page.

Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
---
 fs/nfs/pagelist.c        | 7 +------
 include/linux/nfs_page.h | 3 +--
 2 files changed, 2 insertions(+), 8 deletions(-)

Comments

Dan Carpenter April 1, 2019, 6:37 a.m. UTC | #1
Hi Trond,

url:    https://github.com/0day-ci/linux/commits/Trond-Myklebust/Fix-up-soft-mounts-for-NFSv4-x/20190331-130454
base:   git://git.linux-nfs.org/projects/trondmy/linux-nfs.git linux-next

New smatch warnings:
fs/nfs/pagelist.c:423 nfs_clear_request() warn: variable dereferenced before check 'l_ctx' (see line 417)

# https://github.com/0day-ci/linux/commit/1f204cd821631257d43efaaf86b8d1541f818585
git remote add linux-review https://github.com/0day-ci/linux
git remote update linux-review
git checkout 1f204cd821631257d43efaaf86b8d1541f818585
vim +/l_ctx +423 fs/nfs/pagelist.c

^1da177e Linus Torvalds      2005-04-16  405  
4d65c520 Trond Myklebust     2011-03-25  406  /*
^1da177e Linus Torvalds      2005-04-16  407   * nfs_clear_request - Free up all resources allocated to the request
^1da177e Linus Torvalds      2005-04-16  408   * @req:
^1da177e Linus Torvalds      2005-04-16  409   *
bb6fbc45 Trond Myklebust     2010-03-11  410   * Release page and open context resources associated with a read/write
bb6fbc45 Trond Myklebust     2010-03-11  411   * request after it has completed.
^1da177e Linus Torvalds      2005-04-16  412   */
4d65c520 Trond Myklebust     2011-03-25  413  static void nfs_clear_request(struct nfs_page *req)
^1da177e Linus Torvalds      2005-04-16  414  {
cd52ed35 Trond Myklebust     2006-03-20  415  	struct page *page = req->wb_page;
f11ac8db Trond Myklebust     2010-06-25  416  	struct nfs_lock_context *l_ctx = req->wb_lock_context;
1f204cd8 Trond Myklebust     2019-03-28 @417  	struct nfs_open_context *ctx = l_ctx->open_context;
                                                                               ^^^^^^^^^^^^^^^^^^^
Dereferenced

bb6fbc45 Trond Myklebust     2010-03-11  418  
cd52ed35 Trond Myklebust     2006-03-20  419  	if (page != NULL) {
09cbfeaf Kirill A. Shutemov  2016-04-01  420  		put_page(page);
^1da177e Linus Torvalds      2005-04-16  421  		req->wb_page = NULL;
^1da177e Linus Torvalds      2005-04-16  422  	}
f11ac8db Trond Myklebust     2010-06-25 @423  	if (l_ctx != NULL) {
                                                    ^^^^^^^^^^^^^
Check

7d6ddf88 Benjamin Coddington 2017-04-11  424  		if (atomic_dec_and_test(&l_ctx->io_count)) {
723c921e Peter Zijlstra      2018-03-15  425  			wake_up_var(&l_ctx->io_count);
7d6ddf88 Benjamin Coddington 2017-04-11  426  			if (test_bit(NFS_CONTEXT_UNLOCK, &ctx->flags))
7d6ddf88 Benjamin Coddington 2017-04-11  427  				rpc_wake_up(&NFS_SERVER(d_inode(ctx->dentry))->uoc_rpcwaitq);
7d6ddf88 Benjamin Coddington 2017-04-11  428  		}
f11ac8db Trond Myklebust     2010-06-25  429  		nfs_put_lock_context(l_ctx);
f11ac8db Trond Myklebust     2010-06-25  430  		req->wb_lock_context = NULL;
f11ac8db Trond Myklebust     2010-06-25  431  	}
^1da177e Linus Torvalds      2005-04-16  432  }
^1da177e Linus Torvalds      2005-04-16  433  

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

Patch
diff mbox series

diff --git a/fs/nfs/pagelist.c b/fs/nfs/pagelist.c
index ce6440b79328..5d5ac5df93e2 100644
--- a/fs/nfs/pagelist.c
+++ b/fs/nfs/pagelist.c
@@ -325,7 +325,6 @@  __nfs_create_request(struct nfs_lock_context *l_ctx, struct page *page,
 	req->wb_offset  = offset;
 	req->wb_pgbase	= pgbase;
 	req->wb_bytes   = count;
-	req->wb_context = get_nfs_open_context(ctx);
 	kref_init(&req->wb_kref);
 	req->wb_nio = 0;
 	return req;
@@ -414,8 +413,8 @@  void nfs_unlock_and_release_request(struct nfs_page *req)
 static void nfs_clear_request(struct nfs_page *req)
 {
 	struct page *page = req->wb_page;
-	struct nfs_open_context *ctx = req->wb_context;
 	struct nfs_lock_context *l_ctx = req->wb_lock_context;
+	struct nfs_open_context *ctx = l_ctx->open_context;
 
 	if (page != NULL) {
 		put_page(page);
@@ -430,10 +429,6 @@  static void nfs_clear_request(struct nfs_page *req)
 		nfs_put_lock_context(l_ctx);
 		req->wb_lock_context = NULL;
 	}
-	if (ctx != NULL) {
-		put_nfs_open_context(ctx);
-		req->wb_context = NULL;
-	}
 }
 
 /**
diff --git a/include/linux/nfs_page.h b/include/linux/nfs_page.h
index 1ea13e94feb7..0bbd587fac6a 100644
--- a/include/linux/nfs_page.h
+++ b/include/linux/nfs_page.h
@@ -42,7 +42,6 @@  struct nfs_inode;
 struct nfs_page {
 	struct list_head	wb_list;	/* Defines state of page: */
 	struct page		*wb_page;	/* page to read in/write out */
-	struct nfs_open_context	*wb_context;	/* File state context info */
 	struct nfs_lock_context	*wb_lock_context;	/* lock context info */
 	pgoff_t			wb_index;	/* Offset >> PAGE_SHIFT */
 	unsigned int		wb_offset,	/* Offset & ~PAGE_MASK */
@@ -203,7 +202,7 @@  loff_t req_offset(struct nfs_page *req)
 static inline struct nfs_open_context *
 nfs_req_openctx(struct nfs_page *req)
 {
-	return req->wb_context;
+	return req->wb_lock_context->open_context;
 }
 
 #endif /* _LINUX_NFS_PAGE_H */