For creating fattrs with the label field already allocated for us. I also update nfs_free_fattr() to free the label in the end.
Unified · Split
| @@ -80,18 +80,15 @@ int nfs_get_root(struct super_block *s, struct fs_context *fc) · 79 unmodified lines | ||
| 80 | 80 | goto out; |
| 81 | 81 | |
| 82 | 82 | /* get the actual root for this mount */ |
| 83 | − fsinfo.fattr = nfs_alloc_fattr(); | |
| 83 | + fsinfo.fattr = nfs_alloc_fattr_with_label(server); | |
| 84 | 84 | if (fsinfo.fattr == NULL) |
| 85 | 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 | 87 | error = server->nfs_client->rpc_ops->getroot(server, ctx->mntfh, &fsinfo); |
| 91 | 88 | if (error < 0) { |
| 92 | 89 | dprintk("nfs_get_root: getattr error = %d\n", -error); |
| 93 | 90 | nfs_errorf(fc, "NFS: Couldn't getattr on root"); |
| 94 | − goto out_label; | |
| 91 | + goto out_fattr; | |
| 95 | 92 | } |
| 96 | 93 | |
| 97 | 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 | 96 | dprintk("nfs_get_root: get root inode failed\n"); |
| 100 | 97 | error = PTR_ERR(inode); |
| 101 | 98 | nfs_errorf(fc, "NFS: Couldn't get root inode"); |
| 102 | − goto out_label; | |
| 99 | + goto out_fattr; | |
| 103 | 100 | } |
| 104 | 101 | |
| 105 | 102 | error = nfs_superblock_set_dummy_root(s, inode); |
| 106 | 103 | if (error != 0) |
| 107 | − goto out_label; | |
| 104 | + goto out_fattr; | |
| 108 | 105 | |
| 109 | 106 | /* root dentries normally start off anonymous and get spliced in later |
| 110 | 107 | * 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 | 112 | dprintk("nfs_get_root: get root dentry failed\n"); |
| 116 | 113 | error = PTR_ERR(root); |
| 117 | 114 | nfs_errorf(fc, "NFS: Couldn't get root dentry"); |
| 118 | − goto out_label; | |
| 115 | + goto out_fattr; | |
| 119 | 116 | } |
| 120 | 117 | |
| 121 | 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 | 151 | nfs_setsecurity(inode, fsinfo.fattr, fsinfo.fattr->label); |
| 155 | 152 | error = 0; |
| 156 | 153 | |
| 157 | −out_label: | |
| 158 | − nfs4_label_free(fsinfo.fattr->label); | |
| 159 | 154 | out_fattr: |
| 160 | 155 | nfs_free_fattr(fsinfo.fattr); |
| 161 | 156 | out_name: |
| @@ -165,5 +160,5 @@ out: · 3 unmodified lines | ||
| 165 | 160 | error_splat_root: |
| 166 | 161 | dput(fc->root); |
| 167 | 162 | fc->root = NULL; |
| 168 | − goto out_label; | |
| 163 | + goto out_fattr; | |
| 169 | 164 | } |
| @@ -1606,6 +1606,23 @@ struct nfs_fattr *nfs_alloc_fattr(void) · 1605 unmodified lines | ||
| 1606 | 1606 | } |
| 1607 | 1607 | EXPORT_SYMBOL_GPL(nfs_alloc_fattr); |
| 1608 | 1608 | |
| 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 | + | |
| 1609 | 1626 | struct nfs_fh *nfs_alloc_fhandle(void) |
| 1610 | 1627 | { |
| 1611 | 1628 | struct nfs_fh *fh; |
| @@ -342,14 +342,6 @@ nfs4_label_copy(struct nfs4_label *dst, struct nfs4_label *src) · 341 unmodified lines | ||
| 342 | 342 | |
| 343 | 343 | return dst; |
| 344 | 344 | } |
| 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 | −} | |
| 353 | 345 | |
| 354 | 346 | static 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 | 351 | #else |
| 360 | 352 | 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) {} | |
| 362 | 353 | static inline void nfs_zap_label_cache_locked(struct nfs_inode *nfsi) |
| 363 | 354 | { |
| 364 | 355 | } |
| @@ -426,9 +426,22 @@ extern void nfs_fattr_set_barrier(struct nfs_fattr *fattr); · 425 unmodified lines | ||
| 426 | 426 | extern unsigned long nfs_inc_attr_generation_counter(void); |
| 427 | 427 | |
| 428 | 428 | 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 | +} | |
| 429 | 440 | |
| 430 | 441 | static inline void nfs_free_fattr(const struct nfs_fattr *fattr) |
| 431 | 442 | { |
| 443 | + if (fattr) | |
| 444 | + nfs4_label_free(fattr->label); | |
| 432 | 445 | kfree(fattr); |
| 433 | 446 | } |
| 434 | 447 | |