1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (c) 2001-2003 Cluster File Systems, Inc.
6 * This file is part of Lustre, http://www.lustre.org.
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.
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.
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.
23 #include <linux/sched.h>
24 #include <linux/smp_lock.h>
25 #include <linux/quotaops.h>
27 #define DEBUG_SUBSYSTEM S_LLITE
29 #include <linux/obd_support.h>
30 #include <linux/lustre_lite.h>
31 #include <linux/lustre_idl.h>
32 #include <linux/lustre_dlm.h>
34 /* should NOT be called with the dcache lock, see fs/dcache.c */
35 void ll_release(struct dentry *de)
38 OBD_FREE(de->d_fsdata, sizeof(struct ll_dentry_data));
42 void ll_set_dd(struct dentry *de)
49 if (de->d_fsdata == NULL) {
50 OBD_ALLOC(de->d_fsdata, sizeof(struct ll_dentry_data));
51 sema_init(&ll_d2d(de)->lld_it_sem, 1);
59 void ll_intent_release(struct dentry *de, struct lookup_intent *it)
61 struct lustre_handle *handle;
64 LASSERT(ll_d2d(de) != NULL);
65 mdc_put_rpc_lock(&mdc_rpc_lock, it);
67 if (it->it_lock_mode) {
68 handle = (struct lustre_handle *)it->it_lock_handle;
69 if (it->it_op == IT_SETATTR)
70 ldlm_lock_decref_and_cancel(handle, it->it_lock_mode);
72 ldlm_lock_decref(handle, it->it_lock_mode);
74 /* intent_release may be called multiple times, from
75 this thread and we don't want to double-decref this
80 if (!de->d_it || it->it_op == IT_RELEASED_MAGIC) {
86 LL_GET_INTENT(de, it);
88 CERROR("STRANGE intent release: %p %p\n", de->d_it, it);
93 extern struct dentry *ll_find_alias(struct inode *, struct dentry *);
95 static int revalidate2_finish(int flag, struct ptlrpc_request *request,
96 struct dentry **de, struct lookup_intent *it,
97 int offset, obd_id ino)
99 struct mds_body *body;
100 struct lov_mds_md *lmm = NULL;
104 if (!(flag & LL_LOOKUP_NEGATIVE)) {
105 body = lustre_msg_buf(request->rq_repmsg, offset);
106 if (body->valid & OBD_MD_FLEASIZE)
107 lmm = lustre_msg_buf(request->rq_repmsg, offset + 1);
108 ll_update_inode((*de)->d_inode, body, lmm);
109 mdc_lock_set_inode((struct lustre_handle *)it->it_lock_handle,
114 ptlrpc_req_finished(request);
118 int ll_have_md_lock(struct dentry *de)
120 struct ll_sb_info *sbi = ll_s2sbi(de->d_sb);
121 struct lustre_handle lockh;
122 struct ldlm_res_id res_id = { .name = {0} };
123 struct obd_device *obddev;
129 obddev = class_conn2obd(&sbi->ll_mdc_conn);
130 res_id.name[0] = de->d_inode->i_ino;
131 res_id.name[1] = de->d_inode->i_generation;
133 CDEBUG(D_INFO, "trying to match res "LPU64"\n", res_id.name[0]);
135 if (ldlm_lock_match(obddev->obd_namespace, LDLM_FL_BLOCK_GRANTED,
136 &res_id, LDLM_PLAIN, NULL, 0, LCK_PR, &lockh)) {
137 ldlm_lock_decref(&lockh, LCK_PR);
141 if (ldlm_lock_match(obddev->obd_namespace, LDLM_FL_BLOCK_GRANTED,
142 &res_id, LDLM_PLAIN, NULL, 0, LCK_PW, &lockh)) {
143 ldlm_lock_decref(&lockh, LCK_PW);
149 int ll_revalidate2(struct dentry *de, int flags, struct lookup_intent *it)
154 /* We don't want to cache negative dentries, so return 0 immediately.
155 * We believe that this is safe, that negative dentries cannot be
156 * pinned by someone else */
157 if (de->d_inode == NULL) {
158 CDEBUG(D_INODE, "negative dentry: ret 0 to force lookup2\n");
162 if (it && it->it_op == IT_TRUNC)
163 it->it_op = IT_SETATTR;
165 if (it == NULL || it->it_op == IT_GETATTR) {
166 /* We could just return 1 immediately, but since we should only
167 * be called in revalidate2 if we already have a lock, let's
169 struct inode *inode = de->d_inode;
170 struct ll_sb_info *sbi = ll_i2sbi(inode);
171 struct obd_device *obddev = class_conn2obd(&sbi->ll_mdc_conn);
172 struct ldlm_res_id res_id =
173 { .name = {inode->i_ino, (__u64)inode->i_generation} };
174 struct lustre_handle lockh;
175 rc = ldlm_lock_match(obddev->obd_namespace,
176 LDLM_FL_BLOCK_GRANTED, &res_id,
177 LDLM_PLAIN, NULL, 0, LCK_PR, &lockh);
179 de->d_flags &= ~DCACHE_LUSTRE_INVALID;
180 if (it && it->it_op == IT_GETATTR) {
181 memcpy(it->it_lock_handle, &lockh,
183 it->it_lock_mode = LCK_PR;
184 LL_SAVE_INTENT(de, it);
186 ldlm_lock_decref(&lockh, LCK_PR);
190 rc = ldlm_lock_match(obddev->obd_namespace,
191 LDLM_FL_BLOCK_GRANTED, &res_id,
192 LDLM_PLAIN, NULL, 0, LCK_PW, &lockh);
194 de->d_flags &= ~DCACHE_LUSTRE_INVALID;
195 if (it && it->it_op == IT_GETATTR) {
196 memcpy(it->it_lock_handle, &lockh,
198 it->it_lock_mode = LCK_PW;
199 LL_SAVE_INTENT(de, it);
201 ldlm_lock_decref(&lockh, LCK_PW);
205 if (S_ISDIR(de->d_inode->i_mode))
206 ll_invalidate_inode_pages(de->d_inode);
207 d_unhash_aliases(de->d_inode);
211 rc = ll_intent_lock(de->d_parent->d_inode, &de, it, revalidate2_finish);
214 if (rc < 0 && it->it_status) {
215 CERROR("ll_intent_lock: rc %d : it->it_status %d\n", rc,
219 /* unfortunately ll_intent_lock may cause a callback and revoke our
221 spin_lock(&dcache_lock);
222 list_del_init(&de->d_hash);
223 spin_unlock(&dcache_lock);
229 struct dentry_operations ll_d_ops = {
230 .d_revalidate2 = ll_revalidate2,
231 .d_intent_release = ll_intent_release,
232 .d_release = ll_release,