1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (c) 2001, 2002 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_dlm.h>
33 extern struct address_space_operations ll_aops;
35 void ll_release(struct dentry *de)
39 OBD_FREE(de->d_fsdata, sizeof(struct ll_dentry_data));
43 void ll_intent_release(struct dentry *de, struct lookup_intent *it)
45 struct lustre_handle *handle;
53 LASSERT(ll_d2d(de) != NULL);
55 if (it->it_lock_mode) {
56 handle = (struct lustre_handle *)it->it_lock_handle;
57 if (it->it_op == IT_SETATTR) {
59 ldlm_lock_decref(handle, it->it_lock_mode);
60 rc = ldlm_cli_cancel(handle);
62 CERROR("ldlm_cli_cancel: %d\n", rc);
64 ldlm_lock_decref(handle, it->it_lock_mode);
67 if (it->it_op != IT_RELEASED_MAGIC) {
68 up(&ll_d2d(de)->lld_it_sem);
69 it->it_op = IT_RELEASED_MAGIC;
74 int ll_revalidate2(struct dentry *de, int flags, struct lookup_intent *it)
79 /* We don't want to cache negative dentries, so return 0 immediately.
80 * We believe that this is safe, that negative dentries cannot be
81 * pinned by someone else */
82 if (de->d_inode == NULL) {
83 CDEBUG(D_INODE, "negative dentry: ret 0 to force lookup2\n");
87 rc = ll_intent_lock(de->d_parent->d_inode, &de, it, NULL);
89 /* Something bad happened; overwrite it_status? */
90 CERROR("ll_intent_lock: %d\n", rc);
93 if (it != NULL && it->it_status == 0) {
94 LL_SAVE_INTENT(de, it);
95 } else if (it != NULL) {
98 "D_IT dentry %p fsdata %p intent: %s status %d\n",
99 de, ll_d2d(de), ldlm_it2str(it->it_op), it->it_status);
104 struct ll_sb_info *sbi = ll_s2sbi(de->d_sb);
105 struct lustre_handle lockh;
106 __u64 res_id[RES_NAME_SIZE] = {0};
107 struct obd_device *obddev;
112 CDEBUG(D_INFO, "name: %*s, intent: %s\n", de->d_name.len,
113 de->d_name.name, ldlm_it2str(it->it_op));
114 if (it->it_op == IT_RENAME)
121 obddev = class_conn2obd(&sbi->ll_mdc_conn);
122 res_id[0] = de->d_inode->i_ino;
124 CDEBUG(D_INFO, "trying to match res "LPU64"\n", res_id[0]);
126 if (ldlm_lock_match(obddev->obd_namespace, res_id, LDLM_MDSINTENT,
127 NULL, 0, LCK_PR, &lockh)) {
128 ldlm_lock_decref(&lockh, LCK_PR);
132 if (ldlm_lock_match(obddev->obd_namespace, res_id, LDLM_MDSINTENT,
133 NULL, 0, LCK_PW, &lockh)) {
134 ldlm_lock_decref(&lockh, LCK_PW);
138 /* If the dentry is busy, we won't get called in lookup2 if we
139 * return 0, so return 1.
141 * This is a temporary fix for bug 224, but is one of the causes of
143 CDEBUG(D_INFO, "d_count: %d\n", atomic_read(&de->d_count));
144 if (it && atomic_read(&de->d_count) > 1) {
145 CDEBUG(D_INFO, "returning 1 for %*s during %s because d_count "
146 "is %d\n", de->d_name.len, de->d_name.name,
147 ldlm_it2str(it->it_op), atomic_read(&de->d_count));
152 if (ll_d2d(de) == NULL) {
153 CERROR("allocating fsdata\n");
156 //down(&ll_d2d(de)->lld_it_sem);
163 int ll_set_dd(struct dentry *de)
170 if (de->d_fsdata != NULL) {
171 CERROR("dentry %p already has d_fsdata set\n", de);
173 OBD_ALLOC(de->d_fsdata, sizeof(struct ll_dentry_data));
174 sema_init(&ll_d2d(de)->lld_it_sem, 1);
182 struct dentry_operations ll_d_ops = {
183 .d_revalidate2 = ll_revalidate2,
184 .d_intent_release = ll_intent_release,
185 .d_release = ll_release,