| [2414] | 1 | From eafc370c0eba7949d85547ebc27574aa106d3355 Mon Sep 17 00:00:00 2001 | 
|---|
|  | 2 | From: Anders Kaseorg <andersk@mit.edu> | 
|---|
|  | 3 | Date: Tue, 7 May 2013 00:27:33 -0400 | 
|---|
|  | 4 | Subject: [PATCH] =?UTF-8?q?Linux:=20osi=5FTryEvictVCache:=20Don=E2=80=99t?= | 
|---|
|  | 5 | =?UTF-8?q?=20skip=20the=20first=20dentry=20if=20D=5FALIAS=5FIS=5FHLIST?= | 
|---|
|  | 6 | MIME-Version: 1.0 | 
|---|
|  | 7 | Content-Type: text/plain; charset=UTF-8 | 
|---|
|  | 8 | Content-Transfer-Encoding: 8bit | 
|---|
|  | 9 |  | 
|---|
|  | 10 | An hlist doesn’t begin with a sentinel like a list does, so the old | 
|---|
|  | 11 | code would skip the first dentry or crash with a NULL dereference if | 
|---|
|  | 12 | there wasn’t one.  Use the kernel’s list_for_each_entry or | 
|---|
|  | 13 | hlist_for_each_entry macros instead of trying to do it manually. | 
|---|
|  | 14 |  | 
|---|
|  | 15 | Should fix a crash observed by Alex Chernyakhovsky on kernel 3.6 and | 
|---|
|  | 16 | newer. | 
|---|
|  | 17 |  | 
|---|
|  | 18 | Change-Id: I6d7bd190013a0250ca896af8d5182df55a3376b0 | 
|---|
|  | 19 | Signed-off-by: Anders Kaseorg <andersk@mit.edu> | 
|---|
|  | 20 | --- | 
|---|
|  | 21 | src/afs/LINUX/osi_vcache.c | 30 +++++++++--------------------- | 
|---|
|  | 22 | 1 file changed, 9 insertions(+), 21 deletions(-) | 
|---|
|  | 23 |  | 
|---|
|  | 24 | diff --git a/src/afs/LINUX/osi_vcache.c b/src/afs/LINUX/osi_vcache.c | 
|---|
|  | 25 | index dc3685b..99aab91 100644 | 
|---|
|  | 26 | --- a/src/afs/LINUX/osi_vcache.c | 
|---|
|  | 27 | +++ b/src/afs/LINUX/osi_vcache.c | 
|---|
|  | 28 | @@ -19,10 +19,8 @@ osi_TryEvictVCache(struct vcache *avc, int *slept, int defersleep) { | 
|---|
|  | 29 |  | 
|---|
|  | 30 | struct dentry *dentry; | 
|---|
|  | 31 | struct inode *inode = AFSTOV(avc); | 
|---|
|  | 32 | -#if defined(D_ALIAS_IS_HLIST) | 
|---|
|  | 33 | -    struct hlist_node *cur, *head, *list_end; | 
|---|
|  | 34 | -#else | 
|---|
|  | 35 | -    struct list_head *cur, *head, *list_end; | 
|---|
|  | 36 | +#if defined(D_ALIAS_IS_HLIST) && !defined(HLIST_ITERATOR_NO_NODE) | 
|---|
|  | 37 | +    struct hlist_node *p; | 
|---|
|  | 38 | #endif | 
|---|
|  | 39 |  | 
|---|
|  | 40 | /* First, see if we can evict the inode from the dcache */ | 
|---|
|  | 41 | @@ -33,13 +31,9 @@ osi_TryEvictVCache(struct vcache *avc, int *slept, int defersleep) { | 
|---|
|  | 42 |  | 
|---|
|  | 43 | #if defined(HAVE_DCACHE_LOCK) | 
|---|
|  | 44 | spin_lock(&dcache_lock); | 
|---|
|  | 45 | -       head = &inode->i_dentry; | 
|---|
|  | 46 |  | 
|---|
|  | 47 | restart: | 
|---|
|  | 48 | -        cur = head; | 
|---|
|  | 49 | -       while ((cur = cur->next) != head) { | 
|---|
|  | 50 | -           dentry = list_entry(cur, struct dentry, d_alias); | 
|---|
|  | 51 | - | 
|---|
|  | 52 | +       list_for_each_entry(dentry, &inode->i_dentry, d_alias) { | 
|---|
|  | 53 | if (d_unhashed(dentry)) | 
|---|
|  | 54 | continue; | 
|---|
|  | 55 | dget_locked(dentry); | 
|---|
|  | 56 | @@ -57,23 +51,17 @@ restart: | 
|---|
|  | 57 | spin_unlock(&dcache_lock); | 
|---|
|  | 58 | #else /* HAVE_DCACHE_LOCK */ | 
|---|
|  | 59 | spin_lock(&inode->i_lock); | 
|---|
|  | 60 | -#if defined(D_ALIAS_IS_HLIST) | 
|---|
|  | 61 | -       head = inode->i_dentry.first; | 
|---|
|  | 62 | -       list_end = NULL; | 
|---|
|  | 63 | -#else | 
|---|
|  | 64 | -       head = &inode->i_dentry; | 
|---|
|  | 65 | -       list_end = head; | 
|---|
|  | 66 | -#endif | 
|---|
|  | 67 |  | 
|---|
|  | 68 | restart: | 
|---|
|  | 69 | -       cur = head; | 
|---|
|  | 70 | -       while ((cur = cur->next) != list_end) { | 
|---|
|  | 71 | #if defined(D_ALIAS_IS_HLIST) | 
|---|
|  | 72 | -           dentry = hlist_entry(cur, struct dentry, d_alias); | 
|---|
|  | 73 | +# if defined(HLIST_ITERATOR_NO_NODE) | 
|---|
|  | 74 | +       hlist_for_each_entry(dentry, &inode->i_dentry, d_alias) { | 
|---|
|  | 75 | +# else | 
|---|
|  | 76 | +       hlist_for_each_entry(dentry, p, &inode->i_dentry, d_alias) { | 
|---|
|  | 77 | +# endif | 
|---|
|  | 78 | #else | 
|---|
|  | 79 | -           dentry = list_entry(cur, struct dentry, d_alias); | 
|---|
|  | 80 | +       list_for_each_entry(dentry, &inode->i_dentry, d_alias) { | 
|---|
|  | 81 | #endif | 
|---|
|  | 82 | - | 
|---|
|  | 83 | spin_lock(&dentry->d_lock); | 
|---|
|  | 84 | if (d_unhashed(dentry)) { | 
|---|
|  | 85 | spin_unlock(&dentry->d_lock); | 
|---|
|  | 86 | -- | 
|---|
|  | 87 | 1.8.3.rc1 | 
|---|
|  | 88 |  | 
|---|