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