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