Whamcloud - gitweb
merge b_devel into HEAD. Includes:
[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/fs.h>
20 #include <linux/ext2_fs.h>
21 #include <linux/proc_fs.h>
22
23 #include <linux/obd_class.h>
24 #include <linux/lustre_net.h>
25 #include <linux/lustre_mds.h>
26 #include <linux/lustre_ha.h>
27
28
29 extern kmem_cache_t *ll_file_data_slab;
30 struct ll_file_data {
31         struct lustre_handle fd_mdshandle;
32         struct ptlrpc_request *fd_req;
33         char fd_ostdata[FD_OSTDATA_SIZE];
34         __u32 fd_flags;
35 };
36
37 struct lustre_intent_data {
38         __u64 it_lock_handle[2];
39         __u32 it_disposition;
40         __u32 it_status;
41         __u32 it_lock_mode;
42 };
43
44 struct ll_dentry_data {
45         struct semaphore      lld_it_sem;
46 };
47
48 #define ll_d2d(dentry) ((struct ll_dentry_data*) dentry->d_fsdata)
49
50 struct ll_read_inode2_cookie {
51         struct mds_body *lic_body;
52         struct lov_mds_md *lic_lmm;
53 };
54
55 struct ll_inode_info {
56         struct lov_stripe_md *lli_smd;
57         char                 *lli_symlink_name;
58         struct semaphore      lli_open_sem;
59         atomic_t              lli_open_count; /* see ll_file_release */
60         /*
61          * the VALID flag and valid_sem are temporary measures to serialize
62          * the manual getattrs that we're doing at lock acquisition.  in
63          * the future the OST will always return its notion of the file
64          * size with the granted locks.
65          */
66         unsigned long         lli_flags;
67 #define LLI_F_DID_GETATTR      0
68         struct semaphore      lli_getattr_sem;
69         struct list_head      lli_read_extents;
70         spinlock_t            lli_read_extent_lock;
71
72 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
73         struct inode          lli_vfs_inode;
74 #endif
75 };
76
77 /*
78  * this lets ll_file_read tell ll_readpages how far ahead it can read
79  * and still be covered by ll_file_read's lock.  2.5 won't need this, but
80  * we have the other problem of other readpage callers making sure that
81  * they're covered by a lock..  
82  */
83 struct ll_read_extent {
84         struct list_head re_lli_item;
85         struct task_struct *re_task;
86         struct ldlm_extent re_extent;
87 };
88
89 int ll_check_dirty( struct super_block *sb );
90 int ll_batch_writepage( struct inode *inode, struct page *page );
91
92 /* interpet return codes from intent lookup */
93 #define LL_LOOKUP_POSITIVE 1
94 #define LL_LOOKUP_NEGATIVE 2
95
96 #define LL_SUPER_MAGIC 0x0BD00BD0
97
98 #define LL_COMMITCBD_STOPPING  0x1
99 #define LL_COMMITCBD_STOPPED   0x2
100 #define LL_COMMITCBD_RUNNING   0x4
101
102 #define LL_SBI_NOLCK   0x1
103
104 struct ll_sb_info {
105         struct obd_uuid           ll_sb_uuid;
106         struct lustre_handle      ll_mdc_conn;
107         struct lustre_handle      ll_osc_conn;
108         struct proc_dir_entry*    ll_proc_root;
109         obd_id                    ll_rootino; /* number of root inode */
110
111         int                       ll_flags;
112         wait_queue_head_t         ll_commitcbd_waitq;
113         wait_queue_head_t         ll_commitcbd_ctl_waitq;
114         int                       ll_commitcbd_flags;
115         struct task_struct       *ll_commitcbd_thread;
116         time_t                    ll_commitcbd_waketime;
117         time_t                    ll_commitcbd_timeout;
118         spinlock_t                ll_commitcbd_lock;
119         struct list_head          ll_conn_chain; /* per-conn chain of SBs */
120
121         struct list_head          ll_orphan_dentry_list; /*please don't ask -p*/
122 };
123
124 static inline struct ll_sb_info *ll_s2sbi(struct super_block *sb)
125 {
126 #if  (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
127         return (struct ll_sb_info *)(sb->s_fs_info);
128 #else
129         return (struct ll_sb_info *)(sb->u.generic_sbp);
130 #endif
131 }
132
133 static inline struct lustre_handle *ll_s2obdconn(struct super_block *sb)
134 {
135         return &(ll_s2sbi(sb))->ll_osc_conn;
136 }
137
138 static inline struct client_obd *sbi2mdc(struct ll_sb_info *sbi)
139 {
140         struct obd_device *obd = class_conn2obd(&sbi->ll_mdc_conn);
141         if (obd == NULL)
142                 LBUG();
143         return &obd->u.cli;
144 }
145
146 // FIXME: replace the name of this with LL_SB to conform to kernel stuff
147 static inline struct ll_sb_info *ll_i2sbi(struct inode *inode)
148 {
149         return ll_s2sbi(inode->i_sb);
150 }
151
152 static inline void d_unhash_aliases(struct inode *inode)
153 {
154         struct dentry *dentry = NULL;
155         struct list_head *tmp;
156         struct ll_sb_info *sbi = ll_i2sbi(inode);
157         ENTRY;
158
159         CDEBUG(D_INODE, "marking dentries for ino %lx/%x invalid\n",
160                inode->i_ino, inode->i_generation);
161
162         spin_lock(&dcache_lock);
163         list_for_each(tmp, &inode->i_dentry) {
164                 dentry = list_entry(tmp, struct dentry, d_alias);
165
166                 list_del_init(&dentry->d_hash);
167                 dentry->d_flags |= DCACHE_LUSTRE_INVALID;
168                 list_add(&dentry->d_hash, &sbi->ll_orphan_dentry_list);
169         }
170
171         spin_unlock(&dcache_lock);
172         EXIT;
173 }
174
175 // FIXME: replace the name of this with LL_I to conform to kernel stuff
176 // static inline struct ll_inode_info *LL_I(struct inode *inode)
177 static inline struct ll_inode_info *ll_i2info(struct inode *inode)
178 {
179 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
180         return container_of(inode, struct ll_inode_info, lli_vfs_inode);
181 #else
182         return (struct ll_inode_info *)&(inode->u.generic_ip);
183 #endif
184 }
185
186 static inline struct lustre_handle *ll_i2obdconn(struct inode *inode)
187 {
188         return ll_s2obdconn(inode->i_sb);
189 }
190
191 static inline void ll_ino2fid(struct ll_fid *fid, obd_id ino, __u32 generation,
192                               int type)
193 {
194         fid->id = ino;
195         fid->generation = generation;
196         fid->f_type = type;
197 }
198
199 static inline void ll_inode2fid(struct ll_fid *fid, struct inode *inode)
200 {
201         ll_ino2fid(fid, inode->i_ino, inode->i_generation,
202                    inode->i_mode & S_IFMT);
203 }
204
205 static inline int ll_mds_max_easize(struct super_block *sb)
206 {
207         return sbi2mdc(ll_s2sbi(sb))->cl_max_mds_easize;
208 }
209
210 /* namei.c */
211 int ll_lock(struct inode *dir, struct dentry *dentry,
212             struct lookup_intent *it, struct lustre_handle *lockh);
213 int ll_unlock(__u32 mode, struct lustre_handle *lockh);
214
215 typedef int (*intent_finish_cb)(int flag, struct ptlrpc_request *,
216                                 struct dentry **, struct lookup_intent *,
217                                 int offset, obd_id ino);
218 int ll_intent_lock(struct inode *parent, struct dentry **,
219                    struct lookup_intent *, intent_finish_cb);
220
221 /* dcache.c */
222 void ll_intent_release(struct dentry *, struct lookup_intent *);
223
224 /****
225
226 I originally implmented these as functions, then realized a macro
227 would be more helpful for debugging, so the CDEBUG messages show
228 the current calling function.  The orignal functions are in llite/dcache.c
229
230 int ll_save_intent(struct dentry * de, struct lookup_intent * it);
231 struct lookup_intent * ll_get_intent(struct dentry * de);
232 ****/
233
234 #define IT_RELEASED_MAGIC 0xDEADCAFE
235
236 #define LL_SAVE_INTENT(de, it)                                                 \
237 do {                                                                           \
238         LASSERT(ll_d2d(de) != NULL);                                           \
239                                                                                \
240         down(&ll_d2d(de)->lld_it_sem);                                         \
241         LASSERT(de->d_it == NULL);                                             \
242         de->d_it = it;                                                         \
243         CDEBUG(D_DENTRY, "D_IT DOWN dentry %p fsdata %p intent: %s sem %d\n",  \
244                de, ll_d2d(de), ldlm_it2str(de->d_it->it_op),                   \
245                atomic_read(&(ll_d2d(de)->lld_it_sem.count)));                  \
246 } while(0)
247
248 #define LL_GET_INTENT(de, it)                                                  \
249 do {                                                                           \
250         it = de->d_it;                                                         \
251                                                                                \
252         LASSERT(ll_d2d(de) != NULL);                                           \
253         LASSERT(it);                                                           \
254         LASSERT(it->it_op != IT_RELEASED_MAGIC);                               \
255                                                                                \
256         CDEBUG(D_DENTRY, "D_IT UP dentry %p fsdata %p intent: %s\n",           \
257                de, ll_d2d(de), ldlm_it2str(de->d_it->it_op));                  \
258         de->d_it = NULL;                                                       \
259         it->it_op = IT_RELEASED_MAGIC;                                         \
260         up(&ll_d2d(de)->lld_it_sem);                                           \
261 } while(0)
262
263 /* dcache.c */
264 int ll_have_md_lock(struct dentry *de);
265
266 /* dir.c */
267 extern struct file_operations ll_dir_operations;
268 extern struct inode_operations ll_dir_inode_operations;
269
270 /* file.c */
271 extern struct file_operations ll_file_operations;
272 extern struct inode_operations ll_file_inode_operations;
273 extern struct inode_operations ll_special_inode_operations;
274 struct ldlm_lock;
275 int ll_lock_callback(struct ldlm_lock *, struct ldlm_lock_desc *, void *data,
276                      int flag);
277 int ll_extent_lock_no_validate(struct ll_file_data *fd, struct inode *inode,
278                    struct lov_stripe_md *lsm, int mode,
279                    struct ldlm_extent *extent, struct lustre_handle *lockh);
280 int ll_extent_lock(struct ll_file_data *fd, struct inode *inode,
281                    struct lov_stripe_md *lsm, int mode,
282                    struct ldlm_extent *extent, struct lustre_handle *lockh);
283 int ll_extent_unlock(struct ll_file_data *fd, struct inode *inode,
284                      struct lov_stripe_md *lsm, int mode,
285                      struct lustre_handle *lockh);
286 int ll_create_objects(struct super_block *sb, obd_id id, uid_t uid,
287                       gid_t gid, struct lov_stripe_md **lsmp);
288
289 /* rw.c */
290 struct page *ll_getpage(struct inode *inode, unsigned long offset,
291                         int create, int locked);
292 void ll_truncate(struct inode *inode);
293
294 /* super.c */
295 void ll_update_inode(struct inode *, struct mds_body *, struct lov_mds_md *);
296 int ll_setattr_raw(struct inode *inode, struct iattr *attr);
297
298 /* symlink.c */
299 extern struct inode_operations ll_fast_symlink_inode_operations;
300 extern struct inode_operations ll_symlink_inode_operations;
301
302 /* sysctl.c */
303 void ll_sysctl_init(void);
304 void ll_sysctl_clean(void);
305
306 #endif /* __KERNEL__ */
307
308 #include <asm/types.h>
309
310 #define LL_IOC_GETFLAGS                 _IOR ('f', 151, long)
311 #define LL_IOC_SETFLAGS                 _IOW ('f', 152, long)
312 #define LL_IOC_CLRFLAGS                 _IOW ('f', 153, long)
313 #define LL_IOC_LOV_SETSTRIPE            _IOW ('f', 154, long)
314 #define LL_IOC_LOV_GETSTRIPE            _IOW ('f', 155, long)
315
316 #define O_LOV_DELAY_CREATE 0100000000  /* hopefully this does not conflict */
317
318 #define LL_FILE_IGNORE_LOCK             0x00000001
319
320 #endif