Whamcloud - gitweb
b=256
[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 void ll_intent_release(struct dentry *de, struct lookup_intent *it)
44 {
45         struct lustre_handle *handle;
46         ENTRY;
47
48         if (it == NULL) {
49                 EXIT;
50                 return;
51         }
52
53         LASSERT(ll_d2d(de) != NULL);
54
55         if (it->it_lock_mode) {
56                 handle = (struct lustre_handle *)it->it_lock_handle;
57                 if (it->it_op == IT_SETATTR) {
58                         int rc;
59                         ldlm_lock_decref(handle, it->it_lock_mode);
60                         rc = ldlm_cli_cancel(handle);
61                         if (rc < 0)
62                                 CERROR("ldlm_cli_cancel: %d\n", rc);
63                 } else
64                         ldlm_lock_decref(handle, it->it_lock_mode);
65         }
66
67         if (it->it_op != IT_RELEASED_MAGIC) {
68                 up(&ll_d2d(de)->lld_it_sem);
69                 it->it_op = IT_RELEASED_MAGIC;
70         }
71         EXIT;
72 }
73
74 int ll_revalidate2(struct dentry *de, int flags, struct lookup_intent *it)
75 {
76         int ll_intent_lock(struct inode *parent, struct dentry *dentry,
77                            struct lookup_intent *it, void *);
78         int rc;
79         ENTRY;
80
81         rc = ll_intent_lock(de->d_parent->d_inode, de, it, NULL);
82         if (rc < 0) {
83                 /* Something bad happened; overwrite it_status? */
84         }
85
86         if (it != NULL && it->it_status == 0) {
87                 LL_SAVE_INTENT(de, it);
88         } else if (it != NULL) {
89                 de->d_it = NULL;
90                 CDEBUG(D_DENTRY,
91                        "D_IT dentry %p fsdata %p intent: %s status %d\n",
92                        de, ll_d2d(de), ldlm_it2str(it->it_op), it->it_status);
93         }
94
95         RETURN(1);
96 #if 0
97         struct ll_sb_info *sbi = ll_s2sbi(de->d_sb);
98         struct lustre_handle lockh;
99         __u64 res_id[RES_NAME_SIZE] = {0};
100         struct obd_device *obddev;
101         int rc = 0;
102         ENTRY;
103
104         if (it) {
105                 CDEBUG(D_INFO, "name: %*s, intent: %s\n", de->d_name.len,
106                        de->d_name.name, ldlm_it2str(it->it_op));
107                 if (it->it_op == IT_RENAME)
108                         it->it_data = de;
109         }
110
111         if (!de->d_inode)
112                 GOTO(out, rc = 0);
113
114         obddev = class_conn2obd(&sbi->ll_mdc_conn);
115         res_id[0] = de->d_inode->i_ino;
116
117         CDEBUG(D_INFO, "trying to match res "LPU64"\n", res_id[0]);
118
119         if (ldlm_lock_match(obddev->obd_namespace, res_id, LDLM_MDSINTENT,
120                             NULL, 0, LCK_PR, &lockh)) {
121                 ldlm_lock_decref(&lockh, LCK_PR);
122                 GOTO(out, rc = 1);
123         }
124
125         if (ldlm_lock_match(obddev->obd_namespace, res_id, LDLM_MDSINTENT,
126                             NULL, 0, LCK_PW, &lockh)) {
127                 ldlm_lock_decref(&lockh, LCK_PW);
128                 GOTO(out, rc = 1);
129         }
130
131         /* If the dentry is busy, we won't get called in lookup2 if we
132          * return 0, so return 1.
133          *
134          * This is a temporary fix for bug 618962, but is one of the causes of
135          * 619078. */
136         CDEBUG(D_INFO, "d_count: %d\n", atomic_read(&de->d_count));
137         if (it && atomic_read(&de->d_count) > 1) {
138                 CDEBUG(D_INFO, "returning 1 for %*s during %s because d_count "
139                        "is %d\n", de->d_name.len, de->d_name.name,
140                        ldlm_it2str(it->it_op), atomic_read(&de->d_count));
141                 GOTO(out, rc = 1);
142         }
143
144  out:
145         if (ll_d2d(de) == NULL) {
146                 CERROR("allocating fsdata\n");
147                 ll_set_dd(de);
148         }
149         //down(&ll_d2d(de)->lld_it_sem);
150         de->d_it = it;
151
152         RETURN(rc);
153 #endif
154 }
155
156 int ll_set_dd(struct dentry *de)
157 {
158         ENTRY;
159         LASSERT(de != NULL);
160
161         lock_kernel();
162
163         if (de->d_fsdata != NULL) {
164                 CERROR("dentry %p already has d_fsdata set\n", de);
165         } else {
166                 OBD_ALLOC(de->d_fsdata, sizeof(struct ll_dentry_data));
167                 sema_init(&ll_d2d(de)->lld_it_sem, 1);
168         }
169
170         unlock_kernel();
171
172         RETURN(0);
173 }
174
175 struct dentry_operations ll_d_ops = {
176         .d_revalidate2 = ll_revalidate2,
177         .d_intent_release = ll_intent_release,
178         .d_release = ll_release,
179 };