History

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.

Anna Schumaker committed 5 years ago

Commit d755ad81 parent d4a95a74 files · +36 −20Browse files

Unified · Split

4 files
  1. fs/nfs/getroot.c +6 −11
  2. fs/nfs/inode.c +17 −0
  3. fs/nfs/internal.h +0 −9
  4. include/linux/nfs_fs.h +13 −0
fs/nfs/getroot.c+6−11
@@ -80,18 +80,15 @@ int nfs_get_root(struct super_block *s, struct fs_context *fc) · 79 unmodified lines
80 goto out;80 goto out;
81 81
82 /* get the actual root for this mount */82 /* get the actual root for this mount */
83 fsinfo.fattr = nfs_alloc_fattr();83 fsinfo.fattr = nfs_alloc_fattr_with_label(server);
84 if (fsinfo.fattr == NULL)84 if (fsinfo.fattr == NULL)
85 goto out_name;85 goto out_name;
86 86
87 fsinfo.fattr->label = nfs4_label_alloc(server, GFP_KERNEL);
88 if (IS_ERR(fsinfo.fattr->label))
89 goto out_fattr;
90 error = server->nfs_client->rpc_ops->getroot(server, ctx->mntfh, &fsinfo);87 error = server->nfs_client->rpc_ops->getroot(server, ctx->mntfh, &fsinfo);
91 if (error < 0) {88 if (error < 0) {
92 dprintk("nfs_get_root: getattr error = %d\n", -error);89 dprintk("nfs_get_root: getattr error = %d\n", -error);
93 nfs_errorf(fc, "NFS: Couldn't getattr on root");90 nfs_errorf(fc, "NFS: Couldn't getattr on root");
94 goto out_label;91 goto out_fattr;
95 }92 }
96 93
97 inode = nfs_fhget(s, ctx->mntfh, fsinfo.fattr, NULL);94 inode = nfs_fhget(s, ctx->mntfh, fsinfo.fattr, NULL);
@@ -99,12 +96,12 @@ int nfs_get_root(struct super_block *s, struct fs_context *fc) · 1 unmodified line
99 dprintk("nfs_get_root: get root inode failed\n");96 dprintk("nfs_get_root: get root inode failed\n");
100 error = PTR_ERR(inode);97 error = PTR_ERR(inode);
101 nfs_errorf(fc, "NFS: Couldn't get root inode");98 nfs_errorf(fc, "NFS: Couldn't get root inode");
102 goto out_label;99 goto out_fattr;
103 }100 }
104 101
105 error = nfs_superblock_set_dummy_root(s, inode);102 error = nfs_superblock_set_dummy_root(s, inode);
106 if (error != 0)103 if (error != 0)
107 goto out_label;104 goto out_fattr;
108 105
109 /* root dentries normally start off anonymous and get spliced in later106 /* root dentries normally start off anonymous and get spliced in later
110 * if the dentry tree reaches them; however if the dentry already107 * 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) · 4 unmodified lines
115 dprintk("nfs_get_root: get root dentry failed\n");112 dprintk("nfs_get_root: get root dentry failed\n");
116 error = PTR_ERR(root);113 error = PTR_ERR(root);
117 nfs_errorf(fc, "NFS: Couldn't get root dentry");114 nfs_errorf(fc, "NFS: Couldn't get root dentry");
118 goto out_label;115 goto out_fattr;
119 }116 }
120 117
121 security_d_instantiate(root, inode);118 security_d_instantiate(root, inode);
@@ -154,8 +151,6 @@ int nfs_get_root(struct super_block *s, struct fs_context *fc) · 32 unmodified lines
154 nfs_setsecurity(inode, fsinfo.fattr, fsinfo.fattr->label);151 nfs_setsecurity(inode, fsinfo.fattr, fsinfo.fattr->label);
155 error = 0;152 error = 0;
156 153
157out_label:
158 nfs4_label_free(fsinfo.fattr->label);
159out_fattr:154out_fattr:
160 nfs_free_fattr(fsinfo.fattr);155 nfs_free_fattr(fsinfo.fattr);
161out_name:156out_name:
@@ -165,5 +160,5 @@ out: · 3 unmodified lines
165error_splat_root:160error_splat_root:
166 dput(fc->root);161 dput(fc->root);
167 fc->root = NULL;162 fc->root = NULL;
168 goto out_label;163 goto out_fattr;
169}164}
fs/nfs/inode.c+17−0
@@ -1606,6 +1606,23 @@ struct nfs_fattr *nfs_alloc_fattr(void) · 1605 unmodified lines
1606}1606}
1607EXPORT_SYMBOL_GPL(nfs_alloc_fattr);1607EXPORT_SYMBOL_GPL(nfs_alloc_fattr);
1608 1608
1609struct 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}
1624EXPORT_SYMBOL_GPL(nfs_alloc_fattr_with_label);
1625
1609struct nfs_fh *nfs_alloc_fhandle(void)1626struct nfs_fh *nfs_alloc_fhandle(void)
1610{1627{
1611 struct nfs_fh *fh;1628 struct nfs_fh *fh;
fs/nfs/internal.h+0−9
@@ -342,14 +342,6 @@ nfs4_label_copy(struct nfs4_label *dst, struct nfs4_label *src) · 341 unmodified lines
342 342
343 return dst;343 return dst;
344}344}
345static inline void nfs4_label_free(struct nfs4_label *label)
346{
347 if (label) {
348 kfree(label->label);
349 kfree(label);
350 }
351 return;
352}
353 345
354static inline void nfs_zap_label_cache_locked(struct nfs_inode *nfsi)346static inline void nfs_zap_label_cache_locked(struct nfs_inode *nfsi)
355{347{
@@ -358,7 +350,6 @@ static inline void nfs_zap_label_cache_locked(struct nfs_inode *nfsi) · 2 unmodified lines
358}350}
359#else351#else
360static inline struct nfs4_label *nfs4_label_alloc(struct nfs_server *server, gfp_t flags) { return NULL; }352static inline struct nfs4_label *nfs4_label_alloc(struct nfs_server *server, gfp_t flags) { return NULL; }
361static inline void nfs4_label_free(void *label) {}
362static inline void nfs_zap_label_cache_locked(struct nfs_inode *nfsi)353static inline void nfs_zap_label_cache_locked(struct nfs_inode *nfsi)
363{354{
364}355}
include/linux/nfs_fs.h+13−0
@@ -426,9 +426,22 @@ extern void nfs_fattr_set_barrier(struct nfs_fattr *fattr); · 425 unmodified lines
426extern unsigned long nfs_inc_attr_generation_counter(void);426extern unsigned long nfs_inc_attr_generation_counter(void);
427 427
428extern struct nfs_fattr *nfs_alloc_fattr(void);428extern struct nfs_fattr *nfs_alloc_fattr(void);
429extern struct nfs_fattr *nfs_alloc_fattr_with_label(struct nfs_server *server);
430
431static 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}
429 440
430static inline void nfs_free_fattr(const struct nfs_fattr *fattr)441static inline void nfs_free_fattr(const struct nfs_fattr *fattr)
431{442{
443 if (fattr)
444 nfs4_label_free(fattr->label);
432 kfree(fattr);445 kfree(fattr);
433}446}
434 447

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t