Whamcloud - gitweb
Merge some of the no-op intent changes to the core tree before branching.
[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/locks.h>
24 #include <linux/quotaops.h>
25
26 #define DEBUG_SUBSYSTEM S_LLITE
27
28 #include <linux/obd_support.h>
29 #include <linux/lustre_lite.h>
30 #include <linux/lustre_dlm.h>
31
32 extern struct address_space_operations ll_aops;
33
34 void ll_release(struct dentry *de)
35 {
36         ENTRY;
37
38         OBD_FREE(de->d_fsdata, sizeof(struct ll_dentry_data));
39         EXIT;
40 }
41
42 void ll_intent_release(struct dentry *de)
43 {
44         struct lookup_intent *it;
45         struct lustre_handle *handle;
46         ENTRY;
47
48         it = de->d_it;
49         if (it == NULL) {
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                         ldlm_lock_decref(handle, it->it_lock_mode);
61                         rc = ldlm_cli_cancel(handle);
62                         if (rc < 0)
63                                 CERROR("ldlm_cli_cancel: %d\n", rc);
64                 } else
65                         ldlm_lock_decref(handle, it->it_lock_mode);
66         }
67         de->d_it = NULL;
68         //up(&ll_d2d(de)->lld_it_sem);
69         EXIT;
70 }
71
72 int ll_revalidate2(struct dentry *de, int flags, struct lookup_intent *it)
73 {
74         struct ll_sb_info *sbi = ll_s2sbi(de->d_sb);
75         struct lustre_handle lockh;
76         __u64 res_id[RES_NAME_SIZE] = {0};
77         struct obd_device *obddev;
78         int rc = 0;
79         ENTRY;
80
81         if (it) {
82                 CDEBUG(D_INFO, "name: %*s, intent: %s\n", de->d_name.len,
83                        de->d_name.name, ldlm_it2str(it->it_op));
84                 if (it->it_op == IT_RENAME)
85                         it->it_data = de;
86         }
87
88         if (!de->d_inode)
89                 GOTO(out, rc = 0);
90
91         obddev = class_conn2obd(&sbi->ll_mdc_conn);
92         res_id[0] = de->d_inode->i_ino;
93
94         CDEBUG(D_INFO, "trying to match res "LPU64"\n", res_id[0]);
95
96         if (ldlm_lock_match(obddev->obd_namespace, res_id, LDLM_MDSINTENT,
97                             NULL, 0, LCK_PR, &lockh)) {
98                 ldlm_lock_decref(&lockh, LCK_PR);
99                 GOTO(out, rc = 1);
100         }
101
102         if (ldlm_lock_match(obddev->obd_namespace, res_id, LDLM_MDSINTENT,
103                             NULL, 0, LCK_PW, &lockh)) {
104                 ldlm_lock_decref(&lockh, LCK_PW);
105                 GOTO(out, rc = 1);
106         }
107
108         /* If the dentry is busy, we won't get called in lookup2 if we
109          * return 0, so return 1.
110          *
111          * This is a temporary fix for bug 618962, but is one of the causes of
112          * 619078. */
113         CDEBUG(D_INFO, "d_count: %d\n", atomic_read(&de->d_count));
114         if (it && atomic_read(&de->d_count) > 0) {
115                 CERROR("returning 1 for %*s during %s because d_count is %d\n",
116                        de->d_name.len, de->d_name.name, ldlm_it2str(it->it_op),
117                        atomic_read(&de->d_count));
118                 GOTO(out, rc = 1);
119         }
120
121  out:
122         if (ll_d2d(de) == NULL) {
123                 CERROR("allocating fsdata\n");
124                 ll_set_dd(de);
125         }
126         //down(&ll_d2d(de)->lld_it_sem);
127         //  de->d_it = it;
128
129         RETURN(rc);
130 }
131
132 int ll_set_dd(struct dentry *de)
133 {
134         ENTRY;
135         LASSERT(de != NULL);
136
137         lock_kernel();
138
139         if (de->d_fsdata != NULL) {
140                 CERROR("dentry %p already has d_fsdata set\n", de);
141         } else {
142                 OBD_ALLOC(de->d_fsdata, sizeof(struct ll_dentry_data));
143                 sema_init(&ll_d2d(de)->lld_it_sem, 1);
144         }
145
146         unlock_kernel();
147
148         RETURN(0);
149 }
150
151 struct dentry_operations ll_d_ops = {
152         .d_revalidate2 = ll_revalidate2,
153         .d_intent_release = ll_intent_release,
154         .d_release = ll_release,
155 };