Whamcloud - gitweb
b=596503
[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  * This code is issued under the GNU General Public License.
5  * See the file COPYING in this distribution
6  *
7  * Copyright (C) 2001, 2002 Cluster File Systems, Inc.
8  *
9  */
10
11 #include <linux/fs.h>
12 #include <linux/locks.h>
13 #include <linux/quotaops.h>
14
15 #define DEBUG_SUBSYSTEM S_LLITE
16
17 #include <linux/obd_support.h>
18 #include <linux/lustre_lite.h>
19 #include <linux/lustre_dlm.h>
20
21 extern struct address_space_operations ll_aops;
22
23 void ll_intent_release(struct dentry *de)
24 {
25         struct lustre_handle *handle;
26         ENTRY;
27
28         if (de->d_it == NULL) {
29                 EXIT;
30                 return;
31         }
32         if (de->d_it->it_lock_mode) {
33                 handle = (struct lustre_handle *)de->d_it->it_lock_handle;
34                 if (de->d_it->it_op == IT_SETATTR) {
35                         int rc;
36                         ldlm_lock_decref(handle, de->d_it->it_lock_mode);
37                         rc = ldlm_cli_cancel(handle);
38                         if (rc < 0)
39                                 CERROR("ldlm_cli_cancel: %d\n", rc);
40                 } else
41                         ldlm_lock_decref(handle, de->d_it->it_lock_mode);
42         }
43         de->d_it = NULL;
44         EXIT;
45 }
46
47 int ll_revalidate2(struct dentry *de, int flags, struct lookup_intent *it)
48 {
49         struct ll_sb_info *sbi = ll_s2sbi(de->d_sb);
50         struct lustre_handle lockh;
51         __u64 res_id[RES_NAME_SIZE] = {0};
52         struct obd_device *obddev;
53         ENTRY;
54
55         if (it)
56                 RETURN(0); /* lookups will have NULL it */
57
58         if (!de->d_inode)
59                 RETURN(0);
60
61         obddev = class_conn2obd(&sbi->ll_mdc_conn);
62         res_id[0] = de->d_inode->i_ino;
63
64         CDEBUG(D_INFO, "trying to match res "LPU64"\n", res_id[0]);
65
66         if (ldlm_lock_match(obddev->obd_namespace, res_id, LDLM_MDSINTENT,
67                             NULL, 0, LCK_PR, &lockh)) {
68                 ldlm_lock_decref(&lockh, LCK_PR);
69                 RETURN(1);
70         }
71
72         if (ldlm_lock_match(obddev->obd_namespace, res_id, LDLM_MDSINTENT,
73                             NULL, 0, LCK_PW, &lockh)) {
74                 ldlm_lock_decref(&lockh, LCK_PW);
75                 RETURN(1);
76         }
77
78         RETURN(0);
79 }
80
81 struct dentry_operations ll_d_ops = {
82         d_revalidate2: ll_revalidate2,
83         d_intent_release: ll_intent_release
84 };