Whamcloud - gitweb
land b_cray_delivery on HEAD
[fs/lustre-release.git] / lustre / liblustre / llite_lib.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * Lustre Light Super operations
5  *
6  *  Copyright (c) 2002, 2003 Cluster File Systems, Inc.
7  *
8  *   This file is part of Lustre, http://www.lustre.org.
9  *
10  *   Lustre is free software; you can redistribute it and/or
11  *   modify it under the terms of version 2 of the GNU General Public
12  *   License as published by the Free Software Foundation.
13  *
14  *   Lustre is distributed in the hope that it will be useful,
15  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *   GNU General Public License for more details.
18  *
19  *   You should have received a copy of the GNU General Public License
20  *   along with Lustre; if not, write to the Free Software
21  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22  */
23
24 #ifndef __LLU_H_
25 #define __LLU_H_
26
27 #include <liblustre.h>
28 #include <linux/obd.h>
29 #include <linux/obd_class.h>
30 #include <linux/lustre_mds.h>
31 #include <linux/lustre_lite.h>
32
33 #include <sys/types.h>
34 #include <sys/stat.h>
35
36 #define PAGE_CACHE_MAXBYTES ((__u64)(~0UL) << PAGE_CACHE_SHIFT)
37
38 struct ll_file_data {
39         struct obd_client_handle fd_mds_och;
40         __u32 fd_flags;
41         struct lustre_handle fd_cwlockh;
42         unsigned long fd_gid;
43 };
44
45 struct llu_sb_info
46 {
47         struct obd_uuid         ll_sb_uuid;
48         struct obd_export      *ll_mdc_exp;
49         struct obd_export      *ll_osc_exp;
50         obd_id                  ll_rootino;
51         int                     ll_flags;
52         struct list_head        ll_conn_chain;
53
54         struct obd_uuid         ll_mds_uuid;
55         struct obd_uuid         ll_mds_peer_uuid;
56         char                   *ll_instance; 
57 };
58
59 #define LL_SBI_NOLCK            0x1
60 #define LL_SBI_READAHEAD        0x2
61
62 #define LLI_F_HAVE_OST_SIZE_LOCK        0
63 #define LLI_F_HAVE_MDS_SIZE_LOCK        1
64 #define LLI_F_PREFER_EXTENDED_SIZE      2
65
66 struct llu_inode_info {
67         struct llu_sb_info     *lli_sbi;
68         struct ll_fid           lli_fid;
69
70         struct lov_stripe_md   *lli_smd;
71         char                   *lli_symlink_name;
72         struct semaphore        lli_open_sem;
73         __u64                   lli_maxbytes;
74         unsigned long           lli_flags;
75
76         /* for libsysio */
77         struct file_identifier  lli_sysio_fid;
78
79         struct lookup_intent   *lli_it;
80
81         /* XXX workaround for libsysio unlink */
82         int                     lli_stale_flag;
83         /* XXX workaround for libsysio readdir */
84         loff_t                  lli_dir_pos;
85
86         /* in libsysio we have no chance to store data in file,
87          * so place it here. since it's possible that an file
88          * was opened several times without close, we track an
89          * open_count here */
90         struct ll_file_data    *lli_file_data;
91         int                     lli_open_flags;
92         int                     lli_open_count;
93
94         /* stat FIXME not 64 bit clean */
95         dev_t                   lli_st_dev;
96         ino_t                   lli_st_ino;
97         mode_t                  lli_st_mode;
98         nlink_t                 lli_st_nlink;
99         uid_t                   lli_st_uid;
100         gid_t                   lli_st_gid;
101         dev_t                   lli_st_rdev;
102         loff_t                  lli_st_size;
103         unsigned int            lli_st_blksize;
104         unsigned int            lli_st_blocks;
105         time_t                  lli_st_atime;
106         time_t                  lli_st_mtime;
107         time_t                  lli_st_ctime;
108
109         /* not for stat, change it later */
110         int                     lli_st_flags;
111         unsigned long           lli_st_generation;
112 };
113
114 #define LLU_SYSIO_COOKIE_SIZE(x) \
115         (sizeof(struct llu_sysio_cookie) + \
116          sizeof(struct ll_async_page) * (x) + \
117          sizeof(struct page) * (x))
118
119 struct llu_sysio_cookie {
120         struct obd_io_group    *lsc_oig;
121         struct inode           *lsc_inode;
122         int                     lsc_maxpages;
123         int                     lsc_npages;
124         struct ll_async_page   *lsc_llap;
125         struct page            *lsc_pages;
126         __u64                   lsc_rwcount;
127 };
128
129 /* XXX why uio.h haven't the definition? */
130 #define MAX_IOVEC 32
131
132 struct llu_sysio_callback_args
133 {
134         int ncookies;
135         struct llu_sysio_cookie *cookies[MAX_IOVEC];
136 };
137
138 static inline struct llu_sb_info *llu_fs2sbi(struct filesys *fs)
139 {
140         return (struct llu_sb_info*)(fs->fs_private);
141 }
142
143 static inline struct llu_inode_info *llu_i2info(struct inode *inode)
144 {
145         return (struct llu_inode_info*)(inode->i_private);
146 }
147
148 static inline struct llu_sb_info *llu_i2sbi(struct inode *inode)
149 {
150         return llu_i2info(inode)->lli_sbi;
151 }
152
153 static inline struct obd_export *llu_i2obdexp(struct inode *inode)
154 {
155         return llu_i2info(inode)->lli_sbi->ll_osc_exp;
156 }
157
158 static inline struct obd_export *llu_i2mdcexp(struct inode *inode)
159 {
160         return llu_i2info(inode)->lli_sbi->ll_mdc_exp;
161 }
162
163 static inline int llu_is_root_inode(struct inode *inode)
164 {
165         return (llu_i2info(inode)->lli_fid.id ==
166                 llu_i2info(inode)->lli_sbi->ll_rootino);
167 }
168
169 #define LL_SAVE_INTENT(inode, it)                                              \
170 do {                                                                           \
171         struct lookup_intent *temp;                                            \
172         LASSERT(llu_i2info(inode)->lli_it == NULL);                            \
173         OBD_ALLOC(temp, sizeof(*temp));                                        \
174         memcpy(temp, it, sizeof(*temp));                                       \
175         llu_i2info(inode)->lli_it = temp;                                      \
176         CDEBUG(D_DENTRY, "alloc intent %p to inode %p(ino %lu)\n",             \
177                         temp, inode, llu_i2info(inode)->lli_st_ino);           \
178 } while(0)
179
180
181 #define LL_GET_INTENT(inode, it)                                               \
182 do {                                                                           \
183         it = llu_i2info(inode)->lli_it;                                        \
184                                                                                \
185         LASSERT(it);                                                           \
186         llu_i2info(inode)->lli_it = NULL;                                      \
187         CDEBUG(D_DENTRY, "dettach intent %p from inode %p(ino %lu)\n",         \
188                         it, inode, llu_i2info(inode)->lli_st_ino);             \
189 } while(0)
190
191 /* interpet return codes from intent lookup */
192 #define LL_LOOKUP_POSITIVE 1
193 #define LL_LOOKUP_NEGATIVE 2
194
195 static inline void ll_inode2fid(struct ll_fid *fid, struct inode *inode)
196 {
197         *fid = llu_i2info(inode)->lli_fid;
198 }
199
200 struct it_cb_data {
201         struct inode *icbd_parent;
202         struct pnode *icbd_child;
203         obd_id hash;
204 };
205
206 static inline void ll_i2uctxt(struct ll_uctxt *ctxt, struct inode *i1,
207                               struct inode *i2)
208 {
209         struct llu_inode_info *lli1 = llu_i2info(i1);
210         struct llu_inode_info *lli2;
211
212         LASSERT(i1);
213         LASSERT(ctxt);
214
215         if (in_group_p(lli1->lli_st_gid))
216                 ctxt->gid1 = lli1->lli_st_gid;
217         else
218                 ctxt->gid1 = -1;
219
220         if (i2) {
221                 lli2 = llu_i2info(i2);
222                 if (in_group_p(lli2->lli_st_gid))
223                         ctxt->gid2 = lli2->lli_st_gid;
224                 else
225                         ctxt->gid2 = -1;
226         } else 
227                 ctxt->gid2 = 0;
228 }
229
230
231 typedef int (*intent_finish_cb)(struct ptlrpc_request *,
232                                 struct inode *parent, struct pnode *pnode, 
233                                 struct lookup_intent *, int offset, obd_id ino);
234 int llu_intent_lock(struct inode *parent, struct pnode *pnode,
235                     struct lookup_intent *, int flags, intent_finish_cb);
236
237 /* FIXME */
238 static inline int ll_permission(struct inode *inode, int flag, void * unused)
239 {
240         return 0;
241 }
242
243 static inline __u64 ll_file_maxbytes(struct inode *inode)
244 {
245         return llu_i2info(inode)->lli_maxbytes;
246 }
247
248 struct mount_option_s
249 {
250         char *mdc_uuid;
251         char *osc_uuid;
252 };
253
254 /* llite_lib.c */
255 void generate_random_uuid(unsigned char uuid_out[16]);
256 int liblustre_process_log(struct config_llog_instance *cfg, int allow_recov);
257 int ll_parse_mount_target(const char *target, char **mdsnid,
258                           char **mdsname, char **profile);
259
260 extern int     g_zconf;
261 extern char   *g_zconf_mdsnid;
262 extern char   *g_zconf_mdsname;
263 extern char   *g_zconf_profile;
264 extern struct mount_option_s mount_option;
265
266 /* super.c */
267 void llu_update_inode(struct inode *inode, struct mds_body *body,
268                       struct lov_stripe_md *lmm);
269 void obdo_to_inode(struct inode *dst, struct obdo *src, obd_flag valid);
270 void obdo_from_inode(struct obdo *dst, struct inode *src, obd_flag valid);
271 int ll_it_open_error(int phase, struct lookup_intent *it);
272 struct inode *llu_iget(struct filesys *fs, struct lustre_md *md);
273 int llu_inode_getattr(struct inode *inode, struct lov_stripe_md *lsm);
274
275 extern struct fssw_ops llu_fssw_ops;
276
277 /* file.c */
278 void llu_prepare_mdc_op_data(struct mdc_op_data *data,
279                              struct inode *i1,
280                              struct inode *i2,
281                              const char *name,
282                              int namelen,
283                              int mode);
284 int llu_create(struct inode *dir, struct pnode_base *pnode, int mode);
285 int llu_iop_open(struct pnode *pnode, int flags, mode_t mode);
286 int llu_mdc_close(struct obd_export *mdc_exp, struct inode *inode);
287 int llu_iop_close(struct inode *inode);
288 int llu_iop_ipreadv(struct inode *ino, struct ioctx *ioctxp);
289 int llu_iop_ipwritev(struct inode *ino, struct ioctx *ioctxp);
290 int llu_vmtruncate(struct inode * inode, loff_t offset);
291 void obdo_refresh_inode(struct inode *dst, struct obdo *src, obd_flag valid);
292 int llu_objects_destroy(struct ptlrpc_request *request, struct inode *dir);
293
294 /* rw.c */
295 int llu_iop_iodone(struct ioctx *ioctxp __IS_UNUSED);
296 struct llu_sysio_callback_args*
297 llu_file_write(struct inode *inode, const struct iovec *iovec,
298                        size_t iovlen, loff_t pos);
299 struct llu_sysio_callback_args*
300 llu_file_read(struct inode *inode, const struct iovec *iovec,
301               size_t iovlen, loff_t pos);
302 int llu_glimpse_size(struct inode *inode, struct ost_lvb *lvb);
303 int llu_extent_lock(struct ll_file_data *fd, struct inode *inode,
304                     struct lov_stripe_md *lsm, int mode,
305                     ldlm_policy_data_t *policy, struct lustre_handle *lockh,
306                     int ast_flags);
307 int llu_extent_unlock(struct ll_file_data *fd, struct inode *inode,
308                       struct lov_stripe_md *lsm, int mode,
309                       struct lustre_handle *lockh);
310
311 /* namei.c */
312 int llu_iop_lookup(struct pnode *pnode,
313                    struct inode **inop,
314                    struct intent *intnt,
315                    const char *path);
316 void unhook_stale_inode(struct pnode *pno);
317 struct inode *llu_inode_from_lock(struct ldlm_lock *lock);
318 int llu_mdc_blocking_ast(struct ldlm_lock *lock,
319                          struct ldlm_lock_desc *desc,
320                          void *data, int flag);
321
322 /* dir.c */
323 ssize_t llu_iop_getdirentries(struct inode *ino, char *buf, size_t nbytes,
324                               _SYSIO_OFF_T *basep);
325
326 /* ext2 related */
327 #define EXT2_NAME_LEN (255)
328
329 struct ext2_dirent {
330         __u32   inode;
331         __u16   rec_len;
332         __u8    name_len;
333         __u8    file_type;
334         char    name[EXT2_NAME_LEN];
335 };
336
337 #define EXT2_DIR_PAD                    4
338 #define EXT2_DIR_ROUND                  (EXT2_DIR_PAD - 1)
339 #define EXT2_DIR_REC_LEN(name_len)      (((name_len) + 8 + EXT2_DIR_ROUND) & \
340                                          ~EXT2_DIR_ROUND)
341
342 static inline struct ext2_dirent *ext2_next_entry(struct ext2_dirent *p)
343 {
344         return (struct ext2_dirent*)((char*) p + le16_to_cpu(p->rec_len));
345 }
346
347 #endif