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