Whamcloud - gitweb
b=618962
[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_intent_release(struct dentry *de)
35 {
36         struct lustre_handle *handle;
37         ENTRY;
38
39         if (de->d_it == NULL) {
40                 EXIT;
41                 return;
42         }
43         if (de->d_it->it_lock_mode) {
44                 handle = (struct lustre_handle *)de->d_it->it_lock_handle;
45                 if (de->d_it->it_op == IT_SETATTR) {
46                         int rc;
47                         ldlm_lock_decref(handle, de->d_it->it_lock_mode);
48                         rc = ldlm_cli_cancel(handle);
49                         if (rc < 0)
50                                 CERROR("ldlm_cli_cancel: %d\n", rc);
51                 } else
52                         ldlm_lock_decref(handle, de->d_it->it_lock_mode);
53         }
54         de->d_it = NULL;
55         EXIT;
56 }
57
58 int ll_revalidate2(struct dentry *de, int flags, struct lookup_intent *it)
59 {
60         struct ll_sb_info *sbi = ll_s2sbi(de->d_sb);
61         struct lustre_handle lockh;
62         __u64 res_id[RES_NAME_SIZE] = {0};
63         struct obd_device *obddev;
64         ENTRY;
65
66         /* right now we're only interested in IT_OPEN and IT_LOOKUP */
67         if (it) {
68                 CDEBUG(D_INFO, "name: %*s, intent: %s\n", de->d_name.len,
69                        de->d_name.name, ldlm_it2str(it->it_op));
70                 if (!(it->it_op & IT_OPEN))
71                         RETURN(0);
72         }
73
74         if (!de->d_inode)
75                 RETURN(0);
76
77         obddev = class_conn2obd(&sbi->ll_mdc_conn);
78         res_id[0] = de->d_inode->i_ino;
79
80         CDEBUG(D_INFO, "trying to match res "LPU64"\n", res_id[0]);
81
82         if (ldlm_lock_match(obddev->obd_namespace, res_id, LDLM_MDSINTENT,
83                             NULL, 0, LCK_PR, &lockh)) {
84                 ldlm_lock_decref(&lockh, LCK_PR);
85                 RETURN(1);
86         }
87
88         if (ldlm_lock_match(obddev->obd_namespace, res_id, LDLM_MDSINTENT,
89                             NULL, 0, LCK_PW, &lockh)) {
90                 ldlm_lock_decref(&lockh, LCK_PW);
91                 RETURN(1);
92         }
93
94         /* If we're acting on an IT_OPEN intent and the file is already open,
95          * we won't get called in lookup2 if we return 0, so return 1.
96          *
97          * This is a temporary fix for bug 618962, but is one of the causes of
98          * 619078. */
99         CDEBUG(D_INFO, "d_count: %d\n", atomic_read(&de->d_count));
100         if (atomic_read(&de->d_count) > 0)
101                 RETURN(1);
102
103         RETURN(0);
104 }
105
106 struct dentry_operations ll_d_ops = {
107         d_revalidate2: ll_revalidate2,
108         d_intent_release: ll_intent_release
109 };