Whamcloud - gitweb
landing b_cmobd_merge on HEAD
[fs/lustre-release.git] / lustre / include / linux / lustre_lite.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * lustre lite cluster file system
5  *
6  * This code is issued under the GNU General Public License.
7  * See the file COPYING in this distribution
8  *
9  * Copyright (C) 2002 Cluster File Systems, Inc. <info@clusterfs.com>
10  */
11
12
13
14 #ifndef _LL_H
15 #define _LL_H
16
17 #ifdef __KERNEL__
18
19 #include <linux/version.h>
20
21 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
22 #include <asm/statfs.h>
23 #endif
24
25 #include <linux/fs.h>
26 #include <linux/dcache.h>
27 #include <linux/jbd.h>
28 #include <linux/ext3_fs.h>
29 #include <linux/proc_fs.h>
30
31 #include <linux/obd_class.h>
32 #include <linux/lustre_net.h>
33 #include <linux/lustre_mds.h>
34 #include <linux/lustre_ha.h>
35
36 #include <linux/rbtree.h>
37 #include <linux/lustre_compat25.h>
38 #include <linux/pagemap.h>
39
40 /* careful, this is easy to screw up */
41 #define PAGE_CACHE_MAXBYTES ((__u64)(~0UL) << PAGE_CACHE_SHIFT)
42
43
44 /*
45 struct lustre_intent_data {
46         __u64 it_lock_handle[2];
47         __u32 it_disposition;
48         __u32 it_status;
49         __u32 it_lock_mode;
50         }; */
51
52 #define LL_IT2STR(it) ((it) ? ldlm_it2str((it)->it_op) : "0")
53
54 static inline struct lookup_intent *ll_nd2it(struct nameidata *nd)
55 {
56 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
57         return &nd->intent;
58 #else
59         return nd->intent;
60 #endif
61 }
62
63 struct ll_dentry_data {
64         int                      lld_cwd_count;
65         int                      lld_mnt_count;
66         struct obd_client_handle lld_cwd_och;
67         struct obd_client_handle lld_mnt_och;
68 };
69
70 #define ll_d2d(de) ((struct ll_dentry_data*) de->d_fsdata)
71
72 extern struct file_operations ll_pgcache_seq_fops;
73
74 #define LLI_F_HAVE_OST_SIZE_LOCK        0
75 #define LLI_F_HAVE_MDS_SIZE_LOCK        1
76 #define LLI_F_PREFER_EXTENDED_SIZE      2
77 struct ll_inode_info {
78         struct lov_stripe_md   *lli_smd;
79         struct mea             *lli_mea;
80         char                   *lli_symlink_name;
81         struct semaphore        lli_open_sem;
82         __u64                   lli_maxbytes;
83         __u64                   lli_io_epoch;
84         unsigned long           lli_flags;
85         __u32                   lli_mds;
86
87         /* this lock protects s_d_w and p_w_ll */
88         spinlock_t              lli_lock;
89         int                     lli_send_done_writing;
90         struct list_head        lli_pending_write_llaps;
91
92         struct list_head        lli_close_item;
93
94         struct file_operations *ll_save_ifop;
95         struct file_operations *ll_save_ffop;
96         struct file_operations *ll_save_wfop;
97         struct file_operations *ll_save_wrfop;
98 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
99         struct inode            lli_vfs_inode;
100 #endif
101 };
102
103 // FIXME: replace the name of this with LL_I to conform to kernel stuff
104 // static inline struct ll_inode_info *LL_I(struct inode *inode)
105 static inline struct ll_inode_info *ll_i2info(struct inode *inode)
106 {
107 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
108         return container_of(inode, struct ll_inode_info, lli_vfs_inode);
109 #else
110         return (struct ll_inode_info *)&(inode->u.generic_ip);
111 #endif
112 }
113
114 /* lprocfs.c */
115 enum {
116          LPROC_LL_DIRTY_HITS = 0,
117          LPROC_LL_DIRTY_MISSES,
118          LPROC_LL_WB_WRITEPAGE,
119          LPROC_LL_WB_PRESSURE,
120          LPROC_LL_WB_OK,
121          LPROC_LL_WB_FAIL,
122          LPROC_LL_READ_BYTES,
123          LPROC_LL_WRITE_BYTES,
124          LPROC_LL_BRW_READ,
125          LPROC_LL_BRW_WRITE,
126          LPROC_LL_IOCTL,
127          LPROC_LL_OPEN,
128          LPROC_LL_RELEASE,
129          LPROC_LL_MAP,
130          LPROC_LL_LLSEEK,
131          LPROC_LL_FSYNC,
132          LPROC_LL_SETATTR,
133          LPROC_LL_TRUNC,
134
135 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
136          LPROC_LL_GETATTR,
137 #else
138          LPROC_LL_REVALIDATE,
139 #endif
140          LPROC_LL_STAFS,
141          LPROC_LL_ALLOC_INODE,
142
143          LPROC_LL_DIRECT_READ,
144          LPROC_LL_DIRECT_WRITE,
145          LPROC_LL_FILE_OPCODES
146 };
147
148 static inline void ll_inode2fid(struct ll_fid *fid, struct inode *inode)
149 {
150         mdc_pack_fid(fid, inode->i_ino, inode->i_generation,
151                      inode->i_mode & S_IFMT);
152         LASSERT(ll_i2info(inode));
153         fid->mds = ll_i2info(inode)->lli_mds;
154 }
155
156 static inline void ll_i2uctxt(struct ll_uctxt *ctxt, struct inode *i1,
157                               struct inode *i2)
158 {
159         LASSERT(i1);
160         LASSERT(ctxt);
161
162         if (in_group_p(i1->i_gid))
163                 ctxt->gid1 = i1->i_gid;
164         else
165                 ctxt->gid1 = -1;
166
167         if (i2) {
168                 if (in_group_p(i2->i_gid))
169                         ctxt->gid2 = i2->i_gid;
170                 else
171                         ctxt->gid2 = -1;
172         } else
173                 ctxt->gid2 = 0;
174 }
175
176 static inline void 
177 ll_prepare_mdc_op_data(struct mdc_op_data *data, struct inode *i1,
178                        struct inode *i2, const char *name, int namelen,
179                        int mode)
180 {
181         LASSERT(i1);
182
183         ll_i2uctxt(&data->ctxt, i1, i2);
184         ll_inode2fid(&data->fid1, i1);
185
186         /* it could be directory with mea */
187         data->mea1 = ll_i2info(i1)->lli_mea;
188
189         if (i2) {
190                 ll_inode2fid(&data->fid2, i2);
191                 data->mea2 = ll_i2info(i2)->lli_mea;
192         }
193
194         data->name = name;
195         data->namelen = namelen;
196         data->create_mode = mode;
197         data->mod_time = LTIME_S(CURRENT_TIME);
198 }
199
200 #else
201 #include <linux/lustre_idl.h>
202 #endif /* __KERNEL__ */
203
204 #include <lustre/lustre_user.h>
205
206 #endif