Whamcloud - gitweb
- fixes for dentry problems from Phil and myself
[fs/lustre-release.git] / lustre / llite / dcache.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (c) 2001, 2002 Cluster File Systems, Inc.
5  *
6  *   This file is part of Lustre, http://www.lustre.org.
7  *
8  *   Lustre is free software; you can redistribute it and/or
9  *   modify it under the terms of version 2 of the GNU General Public
10  *   License as published by the Free Software Foundation.
11  *
12  *   Lustre is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with Lustre; if not, write to the Free Software
19  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  */
21
22 #include <linux/fs.h>
23 #include <linux/sched.h>
24 #include <linux/smp_lock.h>
25 #include <linux/quotaops.h>
26
27 #define DEBUG_SUBSYSTEM S_LLITE
28
29 #include <linux/obd_support.h>
30 #include <linux/lustre_lite.h>
31 #include <linux/lustre_dlm.h>
32
33 extern struct address_space_operations ll_aops;
34
35 void ll_release(struct dentry *de)
36 {
37         ENTRY;
38
39         OBD_FREE(de->d_fsdata, sizeof(struct ll_dentry_data));
40         EXIT;
41 }
42
43 extern void d_delete_aliases(struct inode *);
44 void ll_intent_release(struct dentry *de, struct lookup_intent *it)
45 {
46         struct lustre_handle *handle;
47         ENTRY;
48
49         if (it == NULL || it->it_op == IT_RENAME2) {
50                 EXIT;
51                 return;
52         }
53
54         LASSERT(ll_d2d(de) != NULL);
55
56         if (it->it_lock_mode) {
57                 handle = (struct lustre_handle *)it->it_lock_handle;
58                 if (it->it_op == IT_SETATTR) {
59                         int rc;
60                         struct inode *inode = de->d_inode;
61                         ldlm_lock_decref(handle, it->it_lock_mode);
62                         rc = ldlm_cli_cancel(handle);
63                         if (rc < 0)
64                                 CERROR("ldlm_cli_cancel: %d\n", rc);
65                         /* XXX should we only do this when the last lock goes? */
66                         LASSERT(igrab(inode) == inode);
67                         d_delete_aliases(inode);
68                         iput(inode);
69                 } else
70                         ldlm_lock_decref(handle, it->it_lock_mode);
71         }
72
73         if (it->it_op != IT_RELEASED_MAGIC) {
74                 up(&ll_d2d(de)->lld_it_sem);
75                 it->it_op = IT_RELEASED_MAGIC;
76         }
77         EXIT;
78 }
79
80 extern struct dentry *ll_find_alias(struct inode *, struct dentry *);
81
82 static int revalidate2_finish(int flag, struct ptlrpc_request *request, 
83                           struct dentry **de,
84                           struct lookup_intent *it, 
85                           int offset, obd_id ino)
86 {
87         ldlm_lock_set_data((struct lustre_handle *)it->it_lock_handle,
88                            (*de)->d_inode, sizeof(*((*de)->d_inode)));
89         ptlrpc_req_finished(request);
90         return 0;
91 }
92
93 int ll_revalidate2(struct dentry *de, int flags, struct lookup_intent *it)
94 {
95         int rc;
96         ENTRY;
97
98         /* We don't want to cache negative dentries, so return 0 immediately.
99          * We believe that this is safe, that negative dentries cannot be
100          * pinned by someone else */
101         if (de->d_inode == NULL) {
102                 CDEBUG(D_INODE, "negative dentry: ret 0 to force lookup2\n");
103                 RETURN(0);
104         }
105
106         rc = ll_intent_lock(de->d_parent->d_inode, &de, it, revalidate2_finish);
107         if (rc < 0) {
108                 /* Something bad happened; overwrite it_status? */
109                 CERROR("ll_intent_lock: %d\n", rc);
110         }
111         /* unfortunately ll_intent_lock may cause a callback and revoke our 
112            dentry */
113         spin_lock(&dcache_lock);
114         list_del_init(&de->d_hash);
115         spin_unlock(&dcache_lock);
116         d_rehash(de);
117
118         if (it != NULL) { 
119                 LL_SAVE_INTENT(de, it);
120         } else {
121                 de->d_it = NULL;
122         }
123
124         RETURN(1);
125 }
126
127 int ll_set_dd(struct dentry *de)
128 {
129         ENTRY;
130         LASSERT(de != NULL);
131
132         lock_kernel();
133
134         if (de->d_fsdata != NULL) {
135                 CERROR("dentry %p already has d_fsdata set\n", de);
136         } else {
137                 OBD_ALLOC(de->d_fsdata, sizeof(struct ll_dentry_data));
138                 sema_init(&ll_d2d(de)->lld_it_sem, 1);
139         }
140
141         unlock_kernel();
142
143         RETURN(0);
144 }
145
146 struct dentry_operations ll_d_ops = {
147         .d_revalidate2 = ll_revalidate2,
148         .d_intent_release = ll_intent_release,
149         .d_release = ll_release,
150 };