Whamcloud - gitweb
b=21592 BLKGETSIZE64 redefinition on some platform.
[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  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 only,
10  * as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License version 2 for more details (a copy is included
16  * in the LICENSE file that accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License
19  * version 2 along with this program; If not, see
20  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
21  *
22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23  * CA 95054 USA or visit www.sun.com if you need additional information or
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright  2008 Sun Microsystems, Inc. All rights reserved
30  * Use is subject to license terms.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  */
36
37 #ifndef __LLU_H_
38 #define __LLU_H_
39
40 #include <liblustre.h>
41 #include <obd.h>
42 #include <obd_class.h>
43 #include <lustre_mds.h>
44 #include <lustre_lite.h>
45 #include <lustre_ver.h>
46
47 #include <sys/types.h>
48 #include <sys/stat.h>
49
50 /* This should not be "optimized" use ~0ULL because page->index is a long and 
51  * 32-bit systems are therefore limited to 16TB in a mapping */
52 #define PAGE_CACHE_MAXBYTES ((__u64)(~0UL) << CFS_PAGE_SHIFT)
53
54 struct ll_file_data {
55         struct obd_client_handle fd_mds_och;
56         __u32 fd_flags;
57         struct lustre_handle fd_cwlockh;
58         unsigned long fd_gid;
59 };
60
61 struct llu_sb_info
62 {
63         struct obd_uuid          ll_sb_uuid;
64         struct obd_export       *ll_mdc_exp;
65         struct obd_export       *ll_osc_exp;
66         obd_id                   ll_rootino;
67         int                      ll_flags;
68         struct lustre_client_ocd ll_lco;
69         struct list_head         ll_conn_chain;
70
71         struct obd_uuid          ll_mds_uuid;
72         struct obd_uuid          ll_mds_peer_uuid;
73         char                    *ll_instance;
74 };
75
76 #define LL_SBI_NOLCK            0x1
77
78 #define LLI_F_HAVE_OST_SIZE_LOCK        0
79 #define LLI_F_HAVE_MDS_SIZE_LOCK        1
80
81 struct llu_inode_info {
82         struct llu_sb_info     *lli_sbi;
83         struct ll_fid           lli_fid;
84
85         struct lov_stripe_md   *lli_smd;
86         char                   *lli_symlink_name;
87         struct semaphore        lli_open_sem;
88         __u64                   lli_maxbytes;
89         unsigned long           lli_flags;
90
91         /* for libsysio */
92         struct file_identifier  lli_sysio_fid;
93
94         struct lookup_intent   *lli_it;
95
96         /* XXX workaround for libsysio readdir */
97         loff_t                  lli_dir_pos;
98
99         /* in libsysio we have no chance to store data in file,
100          * so place it here. since it's possible that an file
101          * was opened several times without close, we track an
102          * open_count here */
103         struct ll_file_data    *lli_file_data;
104         int                     lli_open_flags;
105         int                     lli_open_count;
106
107         /* not for stat, change it later */
108         int                     lli_st_flags;
109         unsigned long           lli_st_generation;
110         /* the most recent attributes from mds, it is used for timestampts
111          * only so far */
112         struct ost_lvb         lli_lvb;
113 };
114
115 static inline struct llu_sb_info *llu_fs2sbi(struct filesys *fs)
116 {
117         return (struct llu_sb_info*)(fs->fs_private);
118 }
119
120 static inline struct llu_inode_info *llu_i2info(struct inode *inode)
121 {
122         return (struct llu_inode_info*)(inode->i_private);
123 }
124
125 static inline struct intnl_stat *llu_i2stat(struct inode *inode)
126 {
127         return &inode->i_stbuf;
128 }
129
130 static inline struct llu_sb_info *llu_i2sbi(struct inode *inode)
131 {
132         return llu_i2info(inode)->lli_sbi;
133 }
134
135 static inline struct obd_export *llu_i2obdexp(struct inode *inode)
136 {
137         return llu_i2info(inode)->lli_sbi->ll_osc_exp;
138 }
139
140 static inline struct obd_export *llu_i2mdcexp(struct inode *inode)
141 {
142         return llu_i2info(inode)->lli_sbi->ll_mdc_exp;
143 }
144
145 static inline int llu_is_root_inode(struct inode *inode)
146 {
147         return (llu_i2info(inode)->lli_fid.id ==
148                 llu_i2info(inode)->lli_sbi->ll_rootino);
149 }
150
151 #define LL_SAVE_INTENT(inode, it)                                              \
152 do {                                                                           \
153         struct lookup_intent *temp;                                            \
154         LASSERT(llu_i2info(inode)->lli_it == NULL);                            \
155         OBD_ALLOC(temp, sizeof(*temp));                                        \
156         memcpy(temp, it, sizeof(*temp));                                       \
157         llu_i2info(inode)->lli_it = temp;                                      \
158         CDEBUG(D_DENTRY, "alloc intent %p to inode %p(ino %llu)\n",            \
159                         temp, inode, (long long)llu_i2stat(inode)->st_ino);    \
160 } while(0)
161
162
163 #define LL_GET_INTENT(inode, it)                                               \
164 do {                                                                           \
165         it = llu_i2info(inode)->lli_it;                                        \
166                                                                                \
167         LASSERT(it);                                                           \
168         llu_i2info(inode)->lli_it = NULL;                                      \
169         CDEBUG(D_DENTRY, "dettach intent %p from inode %p(ino %llu)\n",        \
170                         it, inode, (long long)llu_i2stat(inode)->st_ino);      \
171 } while(0)
172
173 /* interpet return codes from intent lookup */
174 #define LL_LOOKUP_POSITIVE 1
175 #define LL_LOOKUP_NEGATIVE 2
176
177 static inline void llu_inode2fid(struct ll_fid *fid, struct inode *inode)
178 {
179         *fid = llu_i2info(inode)->lli_fid;
180 }
181
182 struct it_cb_data {
183         struct inode *icbd_parent;
184         struct pnode *icbd_child;
185         obd_id hash;
186 };
187
188 void ll_i2gids(__u32 *suppgids, struct inode *i1,struct inode *i2);
189
190 typedef int (*intent_finish_cb)(struct ptlrpc_request *,
191                                 struct inode *parent, struct pnode *pnode,
192                                 struct lookup_intent *, int offset, obd_id ino);
193 int llu_intent_lock(struct inode *parent, struct pnode *pnode,
194                     struct lookup_intent *, int flags, intent_finish_cb);
195
196 static inline __u64 ll_file_maxbytes(struct inode *inode)
197 {
198         return llu_i2info(inode)->lli_maxbytes;
199 }
200
201 struct mount_option_s
202 {
203         char *mdc_uuid;
204         char *osc_uuid;
205 };
206
207 #define IS_BAD_PTR(ptr)         \
208         ((unsigned long)(ptr) == 0 || (unsigned long)(ptr) > -1000UL)
209
210 /* llite_lib.c */
211 int liblustre_process_log(struct config_llog_instance *cfg, char *mgsnid,
212                           char *profile, int allow_recov);
213 int ll_parse_mount_target(const char *target, char **mgsnid,
214                           char **fsname);
215
216 extern struct mount_option_s mount_option;
217
218 /* super.c */
219 void llu_update_inode(struct inode *inode, struct mds_body *body,
220                       struct lov_stripe_md *lmm);
221 void obdo_to_inode(struct inode *dst, struct obdo *src, obd_flag valid);
222 void obdo_from_inode(struct obdo *dst, struct inode *src, obd_flag valid);
223 int ll_it_open_error(int phase, struct lookup_intent *it);
224 struct inode *llu_iget(struct filesys *fs, struct lustre_md *md);
225 int llu_inode_getattr(struct inode *inode, struct lov_stripe_md *lsm);
226 int llu_setattr_raw(struct inode *inode, struct iattr *attr);
227 int llu_file_flock(struct inode *ino, int cmd, struct file_lock *file_lock);
228
229 extern struct fssw_ops llu_fssw_ops;
230
231 /* file.c */
232 void llu_prepare_mdc_op_data(struct mdc_op_data *data,
233                              struct inode *i1,
234                              struct inode *i2,
235                              const char *name,
236                              int namelen,
237                              int mode);
238 int llu_create(struct inode *dir, struct pnode_base *pnode, int mode);
239 int llu_local_open(struct llu_inode_info *lli, struct lookup_intent *it);
240 int llu_iop_open(struct pnode *pnode, int flags, mode_t mode);
241 int llu_mdc_close(struct obd_export *mdc_exp, struct inode *inode);
242 int llu_file_release(struct inode *inode);
243 int llu_iop_close(struct inode *inode);
244 _SYSIO_OFF_T llu_iop_pos(struct inode *ino, _SYSIO_OFF_T off);
245 int llu_vmtruncate(struct inode * inode, loff_t offset, obd_flag obd_flags);
246 void obdo_refresh_inode(struct inode *dst, struct obdo *src, obd_flag valid);
247 int llu_objects_destroy(struct ptlrpc_request *request, struct inode *dir);
248
249 /* rw.c */
250 int llu_iop_read(struct inode *ino, struct ioctx *ioctxp);
251 int llu_iop_write(struct inode *ino, struct ioctx *ioctxp);
252 int llu_iop_iodone(struct ioctx *ioctxp);
253 int llu_glimpse_size(struct inode *inode);
254 int llu_extent_lock_cancel_cb(struct ldlm_lock *lock,
255                                     struct ldlm_lock_desc *new, void *data,
256                                     int flag);
257 int llu_extent_lock(struct ll_file_data *fd, struct inode *inode,
258                     struct lov_stripe_md *lsm, int mode,
259                     ldlm_policy_data_t *policy, struct lustre_handle *lockh,
260                     int ast_flags);
261 int llu_extent_unlock(struct ll_file_data *fd, struct inode *inode,
262                       struct lov_stripe_md *lsm, int mode,
263                       struct lustre_handle *lockh);
264
265 /* namei.c */
266 int llu_iop_lookup(struct pnode *pnode,
267                    struct inode **inop,
268                    struct intent *intnt,
269                    const char *path);
270 void unhook_stale_inode(struct pnode *pno);
271 struct inode *llu_inode_from_lock(struct ldlm_lock *lock);
272 int llu_mdc_blocking_ast(struct ldlm_lock *lock,
273                          struct ldlm_lock_desc *desc,
274                          void *data, int flag);
275
276 /* dir.c */
277 ssize_t llu_iop_filldirentries(struct inode *ino, _SYSIO_OFF_T *basep, 
278                                char *buf, size_t nbytes);
279
280 /* ext2 related */
281 #define EXT2_NAME_LEN (255)
282
283 struct ext2_dirent {
284         __u32   inode;
285         __u16   rec_len;
286         __u8    name_len;
287         __u8    file_type;
288         char    name[EXT2_NAME_LEN];
289 };
290
291 #define EXT2_DIR_PAD                    4
292 #define EXT2_DIR_ROUND                  (EXT2_DIR_PAD - 1)
293 #define EXT2_DIR_REC_LEN(name_len)      (((name_len) + 8 + EXT2_DIR_ROUND) & \
294                                          ~EXT2_DIR_ROUND)
295
296 static inline struct ext2_dirent *ext2_next_entry(struct ext2_dirent *p)
297 {
298         return (struct ext2_dirent*)((char*) p + le16_to_cpu(p->rec_len));
299 }
300
301 static inline void inode_init_lvb(struct inode *inode, struct ost_lvb *lvb)
302 {
303         struct intnl_stat *st = llu_i2stat(inode);
304         lvb->lvb_size = st->st_size;
305         lvb->lvb_blocks = st->st_blocks;
306         lvb->lvb_mtime = st->st_mtime;
307         lvb->lvb_atime = st->st_atime;
308         lvb->lvb_ctime = st->st_ctime;
309 }
310
311 #endif