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