Skip to content

Commit d755ad8

Browse files
amschuma-ntapTrond Myklebust
authored andcommitted
NFS: Create a new nfs_alloc_fattr_with_label() function
For creating fattrs with the label field already allocated for us. I also update nfs_free_fattr() to free the label in the end. Signed-off-by: Anna Schumaker <[email protected]> Signed-off-by: Trond Myklebust <[email protected]>
1 parent d4a95a7 commit d755ad8

File tree

4 files changed

+36
-20
lines changed

4 files changed

+36
-20
lines changed

fs/nfs/getroot.c

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -80,31 +80,28 @@ int nfs_get_root(struct super_block *s, struct fs_context *fc)
8080
goto out;
8181

8282
/* get the actual root for this mount */
83-
fsinfo.fattr = nfs_alloc_fattr();
83+
fsinfo.fattr = nfs_alloc_fattr_with_label(server);
8484
if (fsinfo.fattr == NULL)
8585
goto out_name;
8686

87-
fsinfo.fattr->label = nfs4_label_alloc(server, GFP_KERNEL);
88-
if (IS_ERR(fsinfo.fattr->label))
89-
goto out_fattr;
9087
error = server->nfs_client->rpc_ops->getroot(server, ctx->mntfh, &fsinfo);
9188
if (error < 0) {
9289
dprintk("nfs_get_root: getattr error = %d\n", -error);
9390
nfs_errorf(fc, "NFS: Couldn't getattr on root");
94-
goto out_label;
91+
goto out_fattr;
9592
}
9693

9794
inode = nfs_fhget(s, ctx->mntfh, fsinfo.fattr, NULL);
9895
if (IS_ERR(inode)) {
9996
dprintk("nfs_get_root: get root inode failed\n");
10097
error = PTR_ERR(inode);
10198
nfs_errorf(fc, "NFS: Couldn't get root inode");
102-
goto out_label;
99+
goto out_fattr;
103100
}
104101

105102
error = nfs_superblock_set_dummy_root(s, inode);
106103
if (error != 0)
107-
goto out_label;
104+
goto out_fattr;
108105

109106
/* root dentries normally start off anonymous and get spliced in later
110107
* if the dentry tree reaches them; however if the dentry already
@@ -115,7 +112,7 @@ int nfs_get_root(struct super_block *s, struct fs_context *fc)
115112
dprintk("nfs_get_root: get root dentry failed\n");
116113
error = PTR_ERR(root);
117114
nfs_errorf(fc, "NFS: Couldn't get root dentry");
118-
goto out_label;
115+
goto out_fattr;
119116
}
120117

121118
security_d_instantiate(root, inode);
@@ -154,8 +151,6 @@ int nfs_get_root(struct super_block *s, struct fs_context *fc)
154151
nfs_setsecurity(inode, fsinfo.fattr, fsinfo.fattr->label);
155152
error = 0;
156153

157-
out_label:
158-
nfs4_label_free(fsinfo.fattr->label);
159154
out_fattr:
160155
nfs_free_fattr(fsinfo.fattr);
161156
out_name:
@@ -165,5 +160,5 @@ int nfs_get_root(struct super_block *s, struct fs_context *fc)
165160
error_splat_root:
166161
dput(fc->root);
167162
fc->root = NULL;
168-
goto out_label;
163+
goto out_fattr;
169164
}

fs/nfs/inode.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1606,6 +1606,23 @@ struct nfs_fattr *nfs_alloc_fattr(void)
16061606
}
16071607
EXPORT_SYMBOL_GPL(nfs_alloc_fattr);
16081608

1609+
struct nfs_fattr *nfs_alloc_fattr_with_label(struct nfs_server *server)
1610+
{
1611+
struct nfs_fattr *fattr = nfs_alloc_fattr();
1612+
1613+
if (!fattr)
1614+
return NULL;
1615+
1616+
fattr->label = nfs4_label_alloc(server, GFP_NOFS);
1617+
if (IS_ERR(fattr->label)) {
1618+
kfree(fattr);
1619+
return NULL;
1620+
}
1621+
1622+
return fattr;
1623+
}
1624+
EXPORT_SYMBOL_GPL(nfs_alloc_fattr_with_label);
1625+
16091626
struct nfs_fh *nfs_alloc_fhandle(void)
16101627
{
16111628
struct nfs_fh *fh;

fs/nfs/internal.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -342,14 +342,6 @@ nfs4_label_copy(struct nfs4_label *dst, struct nfs4_label *src)
342342

343343
return dst;
344344
}
345-
static inline void nfs4_label_free(struct nfs4_label *label)
346-
{
347-
if (label) {
348-
kfree(label->label);
349-
kfree(label);
350-
}
351-
return;
352-
}
353345

354346
static inline void nfs_zap_label_cache_locked(struct nfs_inode *nfsi)
355347
{
@@ -358,7 +350,6 @@ static inline void nfs_zap_label_cache_locked(struct nfs_inode *nfsi)
358350
}
359351
#else
360352
static inline struct nfs4_label *nfs4_label_alloc(struct nfs_server *server, gfp_t flags) { return NULL; }
361-
static inline void nfs4_label_free(void *label) {}
362353
static inline void nfs_zap_label_cache_locked(struct nfs_inode *nfsi)
363354
{
364355
}

include/linux/nfs_fs.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,9 +426,22 @@ extern void nfs_fattr_set_barrier(struct nfs_fattr *fattr);
426426
extern unsigned long nfs_inc_attr_generation_counter(void);
427427

428428
extern struct nfs_fattr *nfs_alloc_fattr(void);
429+
extern struct nfs_fattr *nfs_alloc_fattr_with_label(struct nfs_server *server);
430+
431+
static inline void nfs4_label_free(struct nfs4_label *label)
432+
{
433+
#ifdef CONFIG_NFS_V4_SECURITY_LABEL
434+
if (label) {
435+
kfree(label->label);
436+
kfree(label);
437+
}
438+
#endif
439+
}
429440

430441
static inline void nfs_free_fattr(const struct nfs_fattr *fattr)
431442
{
443+
if (fattr)
444+
nfs4_label_free(fattr->label);
432445
kfree(fattr);
433446
}
434447

0 commit comments

Comments
 (0)