[2655] | 1 | From 1c576fdf9f05c6af7b5b029ba010a76bed48488e Mon Sep 17 00:00:00 2001 |
---|
| 2 | From: Marc Dionne <marc.dionne@your-file-system.com> |
---|
| 3 | Date: Thu, 18 Dec 2014 08:43:22 -0500 |
---|
| 4 | Subject: [PATCH] Linux: d_splice_alias may drop inode reference on error |
---|
| 5 | |
---|
| 6 | d_splice_alias now drops the inode reference on error, so we |
---|
| 7 | need to grab an extra one to make sure that the inode doesn't |
---|
| 8 | go away, and release it when done if there was no error. |
---|
| 9 | |
---|
| 10 | For kernels that may not drop the reference, provide an |
---|
| 11 | additional iput() within an ifdef. This could be hooked up |
---|
| 12 | to a configure option to allow building a module for a kernel |
---|
| 13 | that is known not to drop the reference on error. That hook |
---|
| 14 | is not provided here. Affected kernels should be the early |
---|
| 15 | 3.17 ones (3.17 - 3.17.2); 3.16 and older kernels should not |
---|
| 16 | return errors here. |
---|
| 17 | |
---|
| 18 | Change-Id: Id1786ac2227b4d8e0ae801fe59c15a0ecd975bed |
---|
| 19 | --- |
---|
| 20 | src/afs/LINUX/osi_vnodeops.c | 25 ++++++++++++++++++++++--- |
---|
| 21 | 1 file changed, 22 insertions(+), 3 deletions(-) |
---|
| 22 | |
---|
| 23 | diff --git a/src/afs/LINUX/osi_vnodeops.c b/src/afs/LINUX/osi_vnodeops.c |
---|
| 24 | index b2ab9d5..3723cf8 100644 |
---|
| 25 | --- a/src/afs/LINUX/osi_vnodeops.c |
---|
| 26 | +++ b/src/afs/LINUX/osi_vnodeops.c |
---|
| 27 | @@ -1612,6 +1612,13 @@ afs_linux_lookup(struct inode *dip, struct dentry *dp) |
---|
| 28 | ip->i_flags |= S_AUTOMOUNT; |
---|
| 29 | #endif |
---|
| 30 | } |
---|
| 31 | + /* |
---|
| 32 | + * Take an extra reference so the inode doesn't go away if |
---|
| 33 | + * d_splice_alias drops our reference on error. |
---|
| 34 | + */ |
---|
| 35 | + if (ip) |
---|
| 36 | + igrab(ip); |
---|
| 37 | + |
---|
| 38 | newdp = d_splice_alias(ip, dp); |
---|
| 39 | |
---|
| 40 | done: |
---|
| 41 | @@ -1625,14 +1632,26 @@ afs_linux_lookup(struct inode *dip, struct dentry *dp) |
---|
| 42 | * d_splice_alias can return an error (EIO) if there is an existing |
---|
| 43 | * connected directory alias for this dentry. |
---|
| 44 | */ |
---|
| 45 | - if (!IS_ERR(newdp)) |
---|
| 46 | + if (!IS_ERR(newdp)) { |
---|
| 47 | + iput(ip); |
---|
| 48 | return newdp; |
---|
| 49 | - else { |
---|
| 50 | + } else { |
---|
| 51 | d_add(dp, ip); |
---|
| 52 | + /* |
---|
| 53 | + * Depending on the kernel version, d_splice_alias may or may |
---|
| 54 | + * not drop the inode reference on error. If it didn't, do it |
---|
| 55 | + * here. |
---|
| 56 | + */ |
---|
| 57 | +#if defined(D_SPLICE_ALIAS_LEAK_ON_ERROR) |
---|
| 58 | + iput(ip); |
---|
| 59 | +#endif |
---|
| 60 | return NULL; |
---|
| 61 | } |
---|
| 62 | - } else |
---|
| 63 | + } else { |
---|
| 64 | + if (ip) |
---|
| 65 | + iput(ip); |
---|
| 66 | return ERR_PTR(afs_convert_code(code)); |
---|
| 67 | + } |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | static int |
---|
| 71 | -- |
---|
| 72 | 2.2.1 |
---|
| 73 | |
---|