Skip to content

Commit f003a71

Browse files
Matthew Wilcox (Oracle)Trond Myklebust
authored andcommitted
nfs: Convert nfs_symlink() to use a folio
Use the folio APIs, saving about four calls to compound_head(). Convert back to a page in each of the individual protocol implementations. Signed-off-by: Matthew Wilcox (Oracle) <[email protected]> Signed-off-by: Trond Myklebust <[email protected]>
1 parent bfca5fb commit f003a71

File tree

5 files changed

+21
-23
lines changed

5 files changed

+21
-23
lines changed

fs/nfs/dir.c

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2532,7 +2532,7 @@ EXPORT_SYMBOL_GPL(nfs_unlink);
25322532
int nfs_symlink(struct mnt_idmap *idmap, struct inode *dir,
25332533
struct dentry *dentry, const char *symname)
25342534
{
2535-
struct page *page;
2535+
struct folio *folio;
25362536
char *kaddr;
25372537
struct iattr attr;
25382538
unsigned int pathlen = strlen(symname);
@@ -2547,24 +2547,24 @@ int nfs_symlink(struct mnt_idmap *idmap, struct inode *dir,
25472547
attr.ia_mode = S_IFLNK | S_IRWXUGO;
25482548
attr.ia_valid = ATTR_MODE;
25492549

2550-
page = alloc_page(GFP_USER);
2551-
if (!page)
2550+
folio = folio_alloc(GFP_USER, 0);
2551+
if (!folio)
25522552
return -ENOMEM;
25532553

2554-
kaddr = page_address(page);
2554+
kaddr = folio_address(folio);
25552555
memcpy(kaddr, symname, pathlen);
25562556
if (pathlen < PAGE_SIZE)
25572557
memset(kaddr + pathlen, 0, PAGE_SIZE - pathlen);
25582558

25592559
trace_nfs_symlink_enter(dir, dentry);
2560-
error = NFS_PROTO(dir)->symlink(dir, dentry, page, pathlen, &attr);
2560+
error = NFS_PROTO(dir)->symlink(dir, dentry, folio, pathlen, &attr);
25612561
trace_nfs_symlink_exit(dir, dentry, error);
25622562
if (error != 0) {
25632563
dfprintk(VFS, "NFS: symlink(%s/%lu, %pd, %s) error %d\n",
25642564
dir->i_sb->s_id, dir->i_ino,
25652565
dentry, symname, error);
25662566
d_drop(dentry);
2567-
__free_page(page);
2567+
folio_put(folio);
25682568
return error;
25692569
}
25702570

@@ -2574,18 +2574,13 @@ int nfs_symlink(struct mnt_idmap *idmap, struct inode *dir,
25742574
* No big deal if we can't add this page to the page cache here.
25752575
* READLINK will get the missing page from the server if needed.
25762576
*/
2577-
if (!add_to_page_cache_lru(page, d_inode(dentry)->i_mapping, 0,
2578-
GFP_KERNEL)) {
2579-
SetPageUptodate(page);
2580-
unlock_page(page);
2581-
/*
2582-
* add_to_page_cache_lru() grabs an extra page refcount.
2583-
* Drop it here to avoid leaking this page later.
2584-
*/
2585-
put_page(page);
2586-
} else
2587-
__free_page(page);
2577+
if (filemap_add_folio(d_inode(dentry)->i_mapping, folio, 0,
2578+
GFP_KERNEL) == 0) {
2579+
folio_mark_uptodate(folio);
2580+
folio_unlock(folio);
2581+
}
25882582

2583+
folio_put(folio);
25892584
return 0;
25902585
}
25912586
EXPORT_SYMBOL_GPL(nfs_symlink);

fs/nfs/nfs3proc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,9 +543,10 @@ nfs3_proc_link(struct inode *inode, struct inode *dir, const struct qstr *name)
543543
}
544544

545545
static int
546-
nfs3_proc_symlink(struct inode *dir, struct dentry *dentry, struct page *page,
546+
nfs3_proc_symlink(struct inode *dir, struct dentry *dentry, struct folio *folio,
547547
unsigned int len, struct iattr *sattr)
548548
{
549+
struct page *page = &folio->page;
549550
struct nfs3_createdata *data;
550551
struct dentry *d_alias;
551552
int status = -ENOMEM;

fs/nfs/nfs4proc.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5036,9 +5036,10 @@ static void nfs4_free_createdata(struct nfs4_createdata *data)
50365036
}
50375037

50385038
static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry,
5039-
struct page *page, unsigned int len, struct iattr *sattr,
5039+
struct folio *folio, unsigned int len, struct iattr *sattr,
50405040
struct nfs4_label *label)
50415041
{
5042+
struct page *page = &folio->page;
50425043
struct nfs4_createdata *data;
50435044
int status = -ENAMETOOLONG;
50445045

@@ -5063,7 +5064,7 @@ static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry,
50635064
}
50645065

50655066
static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry,
5066-
struct page *page, unsigned int len, struct iattr *sattr)
5067+
struct folio *folio, unsigned int len, struct iattr *sattr)
50675068
{
50685069
struct nfs4_exception exception = {
50695070
.interruptible = true,
@@ -5074,7 +5075,7 @@ static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry,
50745075
label = nfs4_label_init_security(dir, dentry, sattr, &l);
50755076

50765077
do {
5077-
err = _nfs4_proc_symlink(dir, dentry, page, len, sattr, label);
5078+
err = _nfs4_proc_symlink(dir, dentry, folio, len, sattr, label);
50785079
trace_nfs4_symlink(dir, &dentry->d_name, err);
50795080
err = nfs4_handle_exception(NFS_SERVER(dir), err,
50805081
&exception);

fs/nfs/proc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,9 +396,10 @@ nfs_proc_link(struct inode *inode, struct inode *dir, const struct qstr *name)
396396
}
397397

398398
static int
399-
nfs_proc_symlink(struct inode *dir, struct dentry *dentry, struct page *page,
399+
nfs_proc_symlink(struct inode *dir, struct dentry *dentry, struct folio *folio,
400400
unsigned int len, struct iattr *sattr)
401401
{
402+
struct page *page = &folio->page;
402403
struct nfs_fh *fh;
403404
struct nfs_fattr *fattr;
404405
struct nfs_symlinkargs arg = {

include/linux/nfs_xdr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1772,7 +1772,7 @@ struct nfs_rpc_ops {
17721772
void (*rename_rpc_prepare)(struct rpc_task *task, struct nfs_renamedata *);
17731773
int (*rename_done) (struct rpc_task *task, struct inode *old_dir, struct inode *new_dir);
17741774
int (*link) (struct inode *, struct inode *, const struct qstr *);
1775-
int (*symlink) (struct inode *, struct dentry *, struct page *,
1775+
int (*symlink) (struct inode *, struct dentry *, struct folio *,
17761776
unsigned int, struct iattr *);
17771777
int (*mkdir) (struct inode *, struct dentry *, struct iattr *);
17781778
int (*rmdir) (struct inode *, const struct qstr *);

0 commit comments

Comments
 (0)