Whamcloud - gitweb
99d93b21a9f1e1af2d08ebe431d7aa6290a3d577
[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
22 #include <linux/obd_class.h>
23 #include <linux/lustre_net.h>
24 #include <linux/lustre_mds.h>
25 #include <linux/lustre_ha.h>
26
27 extern kmem_cache_t *ll_file_data_slab;
28 struct ll_file_data {
29         struct lustre_handle fd_mdshandle;
30         struct lustre_handle fd_osthandle;
31         struct ptlrpc_request *fd_req;
32         __u32 fd_flags;
33 };
34
35 struct ll_dentry_data {
36         struct semaphore      lld_it_sem;
37 };
38
39 #define ll_d2d(dentry) ((struct ll_dentry_data*) dentry->d_fsdata)
40
41 struct ll_read_inode2_cookie {
42         struct mds_body *lic_body;
43         struct lov_mds_md *lic_lmm;
44 };
45
46 #define LL_INLINESZ      60
47 struct ll_inode_info {
48         struct lov_stripe_md *lli_smd;
49         char                 *lli_symlink_name;
50         struct lustre_handle  lli_intent_lock_handle;
51         struct semaphore      lli_open_sem;
52 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
53         struct inode          lli_vfs_inode;
54 #endif
55 };
56
57 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
58 static inline struct ll_inode_info *LL_I(struct inode *inode)
59 {
60         return container_of(inode, struct ll_inode_info, lli_vfs_inode);
61 }
62 #endif
63
64
65 #define LL_SUPER_MAGIC 0x0BD00BD0
66
67 #define LL_COMMITCBD_STOPPING  0x1
68 #define LL_COMMITCBD_STOPPED   0x2
69 #define LL_COMMITCBD_RUNNING   0x4
70
71 #define LL_SBI_NOLCK   0x1
72
73 struct ll_sb_info {
74         obd_uuid_t                ll_sb_uuid;
75         struct lustre_handle      ll_mdc_conn;
76         struct lustre_handle      ll_osc_conn;
77         obd_id                    ll_rootino; /* number of root inode */
78
79         int                       ll_flags;
80         wait_queue_head_t         ll_commitcbd_waitq;
81         wait_queue_head_t         ll_commitcbd_ctl_waitq;
82         int                       ll_commitcbd_flags;
83         struct task_struct       *ll_commitcbd_thread;
84         time_t                    ll_commitcbd_waketime;
85         time_t                    ll_commitcbd_timeout;
86         spinlock_t                ll_commitcbd_lock;
87         struct list_head          ll_conn_chain; /* per-conn chain of SBs */
88 };
89
90 static inline struct ll_sb_info *ll_s2sbi(struct super_block *sb)
91 {
92 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
93         return (struct ll_sb_info *)(sb->s_fs_info);
94 #else
95         return (struct ll_sb_info *)(sb->u.generic_sbp);
96 #endif
97 }
98
99 static inline struct lustre_handle *ll_s2obdconn(struct super_block *sb)
100 {
101         return &(ll_s2sbi(sb))->ll_osc_conn;
102 }
103
104 static inline struct client_obd *sbi2mdc(struct ll_sb_info *sbi)
105 {
106         struct obd_device *obd = class_conn2obd(&sbi->ll_mdc_conn);
107         if (obd == NULL)
108                 LBUG();
109         return &obd->u.cli;
110 }
111
112 static inline struct ll_sb_info *ll_i2sbi(struct inode *inode)
113 {
114         return ll_s2sbi(inode->i_sb);
115 }
116
117 static inline struct ll_inode_info *ll_i2info(struct inode *inode)
118 {
119         return (struct ll_inode_info *)&(inode->u.generic_ip);
120 }
121
122 static inline struct lustre_handle *ll_i2obdconn(struct inode *inode)
123 {
124         return ll_s2obdconn(inode->i_sb);
125 }
126
127 static inline void ll_ino2fid(struct ll_fid *fid, obd_id ino, __u32 generation,
128                               int type)
129 {
130         fid->id = ino;
131         fid->generation = generation;
132         fid->f_type = type;
133 }
134
135 static inline void ll_inode2fid(struct ll_fid *fid, struct inode *inode)
136 {
137         ll_ino2fid(fid, inode->i_ino, inode->i_generation,
138                    inode->i_mode & S_IFMT);
139 }
140
141 static inline int ll_mds_easize(struct super_block *sb)
142 {
143         return sbi2mdc(ll_s2sbi(sb))->cl_max_mds_easize;
144 }
145
146 static inline int ll_ost_easize(struct super_block *sb)
147 {
148         return sbi2mdc(ll_s2sbi(sb))->cl_max_ost_easize;
149 }
150
151 /* namei.c */
152 int ll_lock(struct inode *dir, struct dentry *dentry,
153             struct lookup_intent *it, struct lustre_handle *lockh);
154 int ll_unlock(__u32 mode, struct lustre_handle *lockh);
155
156 typedef int (*intent_finish_cb)(int flag, struct ptlrpc_request *,
157                                 struct dentry **, struct lookup_intent *,
158                                 int offset, obd_id ino);
159 int ll_intent_lock(struct inode *parent, struct dentry **,
160                    struct lookup_intent *, intent_finish_cb);
161
162 /* dcache.c */
163 void ll_intent_release(struct dentry *, struct lookup_intent *);
164 int ll_set_dd(struct dentry *de);
165
166 /****
167
168 I originally implmented these as functions, then realized a macro
169 would be more helpful for debugging, so the CDEBUG messages show
170 the current calling function.  The orignal functions are in llite/dcache.c
171
172 int ll_save_intent(struct dentry * de, struct lookup_intent * it);
173 struct lookup_intent * ll_get_intent(struct dentry * de);
174 ****/
175
176 #define IT_RELEASED_MAGIC 0xDEADCAFE
177
178 #define LL_SAVE_INTENT(de, it)                                                 \
179 do {                                                                           \
180         LASSERT(ll_d2d(de) != NULL);                                           \
181                                                                                \
182         down(&ll_d2d(de)->lld_it_sem);                                         \
183         de->d_it = it;                                                         \
184         CDEBUG(D_DENTRY, "D_IT DOWN dentry %p fsdata %p intent: %s sem %d\n",  \
185                de, ll_d2d(de), ldlm_it2str(de->d_it->it_op),                   \
186                atomic_read(&(ll_d2d(de)->lld_it_sem.count)));                  \
187 } while(0)
188
189 #define LL_GET_INTENT(de, it)                                                  \
190 do {                                                                           \
191         it = de->d_it;                                                         \
192                                                                                \
193         LASSERT(ll_d2d(de) != NULL);                                           \
194         LASSERT(it->it_op != IT_RELEASED_MAGIC);                               \
195                                                                                \
196         CDEBUG(D_DENTRY, "D_IT UP dentry %p fsdata %p intent: %s\n",           \
197                de, ll_d2d(de), ldlm_it2str(de->d_it->it_op));                  \
198         de->d_it = NULL;                                                       \
199         it->it_op = IT_RELEASED_MAGIC;                                         \
200         up(&ll_d2d(de)->lld_it_sem);                                           \
201 } while(0)
202
203 /* dir.c */
204 extern struct file_operations ll_dir_operations;
205 extern struct inode_operations ll_dir_inode_operations;
206
207 /* file.c */
208 extern struct file_operations ll_file_operations;
209 extern struct inode_operations ll_file_inode_operations;
210 struct ldlm_lock;
211 int ll_lock_callback(struct ldlm_lock *, struct ldlm_lock_desc *, void *data,
212                      __u32 data_len, int flag);
213 int ll_size_lock(struct inode *, struct lov_stripe_md *, obd_off start,
214                  int mode, struct lustre_handle **);
215 int ll_size_unlock(struct inode *, struct lov_stripe_md *, int mode,
216                    struct lustre_handle *);
217 int ll_file_size(struct inode *inode, struct lov_stripe_md *md);
218 int ll_create_objects(struct super_block *sb, obd_id id, uid_t uid,
219                       gid_t gid, struct lov_stripe_md **lsmp);
220
221 /* rw.c */
222 struct page *ll_getpage(struct inode *inode, unsigned long offset,
223                         int create, int locked);
224 void ll_truncate(struct inode *inode);
225
226 /* super.c */
227 void ll_update_inode(struct inode *, struct mds_body *);
228
229 /* symlink.c */
230 extern struct inode_operations ll_fast_symlink_inode_operations;
231 extern struct inode_operations ll_symlink_inode_operations;
232
233 /* sysctl.c */
234 void ll_sysctl_init(void);
235 void ll_sysctl_clean(void);
236
237 #endif /* __KERNEL__ */
238
239 #include <asm/types.h>
240
241 #define LL_IOC_GETFLAGS                 _IOR ('f', 151, long)
242 #define LL_IOC_SETFLAGS                 _IOW ('f', 152, long)
243 #define LL_IOC_CLRFLAGS                 _IOW ('f', 153, long)
244 #define LL_IOC_LOV_SETSTRIPE            _IOW ('f', 154, long)
245
246 struct lov_user_md {
247         __u64 lum_stripe_size;
248         __u32 lum_stripe_pattern;
249         __u32 lum_stripe_offset;
250         __u32 lum_stripe_count;
251 };
252
253 #define O_LOV_DELAY_CREATE 0100000000  /* hopefully this does not conflict */
254
255 #define LL_FILE_IGNORE_LOCK             0x00000001
256
257 #endif