Whamcloud - gitweb
b=11063 set mtime to past under PW EOF extent lock (v6)
[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_mdc.h>
44 #include <lustre_lite.h>
45 #include <lustre_ver.h>
46
47 #include <sys/types.h>
48 #include <sys/stat.h>
49
50 /* for struct cl_lock_descr and struct cl_io */
51 #include <cl_object.h>
52 #include <lclient.h>
53
54 /* This should not be "optimized" use ~0ULL because page->index is a long and
55  * 32-bit systems are therefore limited to 16TB in a mapping */
56 #define PAGE_CACHE_MAXBYTES ((__u64)(~0UL) << CFS_PAGE_SHIFT)
57
58 struct ll_file_data {
59         struct obd_client_handle fd_mds_och;
60         __u32 fd_flags;
61         struct ccc_grouplock fd_grouplock;
62 };
63
64 struct llu_sb_info {
65         struct obd_uuid          ll_sb_uuid;
66         struct obd_export       *ll_md_exp;
67         struct obd_export       *ll_dt_exp;
68         struct lu_fid            ll_root_fid;
69         int                      ll_flags;
70         struct lustre_client_ocd ll_lco;
71         cfs_list_t               ll_conn_chain;
72
73         struct obd_uuid          ll_mds_uuid;
74         struct obd_uuid          ll_mds_peer_uuid;
75         char                    *ll_instance;
76         struct lu_site           *ll_site;
77         struct cl_device         *ll_cl;
78 };
79
80 #define LL_SBI_NOLCK            0x1
81
82 enum lli_flags {
83         /* MDS has an authority for the Size-on-MDS attributes. */
84         LLIF_MDS_SIZE_LOCK      = (1 << 0),
85 };
86
87 struct llu_inode_info {
88         struct llu_sb_info     *lli_sbi;
89         struct lu_fid           lli_fid;
90
91         struct lov_stripe_md   *lli_smd;
92         char                   *lli_symlink_name;
93         cfs_semaphore_t         lli_open_sem;
94         __u64                   lli_maxbytes;
95         unsigned long           lli_flags;
96         __u64                   lli_ioepoch;
97
98         /* for libsysio */
99         struct file_identifier  lli_sysio_fid;
100
101         struct lookup_intent   *lli_it;
102
103         /* XXX workaround for libsysio readdir */
104         loff_t                  lli_dir_pos;
105
106         /* in libsysio we have no chance to store data in file,
107          * so place it here. since it's possible that an file
108          * was opened several times without close, we track an
109          * open_count here */
110         struct ll_file_data    *lli_file_data;
111         int                     lli_open_flags;
112         int                     lli_open_count;
113
114         /* not for stat, change it later */
115         int                     lli_st_flags;
116         unsigned long           lli_st_generation;
117         struct cl_object       *lli_clob;
118         /* the most recent timestamps obtained from mds */
119         struct ost_lvb          lli_lvb;
120 };
121
122
123 static inline struct llu_sb_info *llu_fs2sbi(struct filesys *fs)
124 {
125         return (struct llu_sb_info*)(fs->fs_private);
126 }
127
128 static inline struct llu_inode_info *llu_i2info(struct inode *inode)
129 {
130         return (struct llu_inode_info*)(inode->i_private);
131 }
132
133 static inline struct intnl_stat *llu_i2stat(struct inode *inode)
134 {
135         return &inode->i_stbuf;
136 }
137
138 static inline struct llu_sb_info *llu_i2sbi(struct inode *inode)
139 {
140         return llu_i2info(inode)->lli_sbi;
141 }
142
143 static inline struct obd_export *llu_i2obdexp(struct inode *inode)
144 {
145         return llu_i2info(inode)->lli_sbi->ll_dt_exp;
146 }
147
148 static inline struct obd_export *llu_i2mdexp(struct inode *inode)
149 {
150         return llu_i2info(inode)->lli_sbi->ll_md_exp;
151 }
152
153 static inline int llu_is_root_inode(struct inode *inode)
154 {
155         return (fid_seq(&llu_i2info(inode)->lli_fid) ==
156                 fid_seq(&llu_i2info(inode)->lli_sbi->ll_root_fid) &&
157                 fid_oid(&llu_i2info(inode)->lli_fid) ==
158                 fid_oid(&llu_i2info(inode)->lli_sbi->ll_root_fid));
159 }
160
161 #define LL_SAVE_INTENT(inode, it)                                              \
162 do {                                                                           \
163         struct lookup_intent *temp;                                            \
164         LASSERT(llu_i2info(inode)->lli_it == NULL);                            \
165         OBD_ALLOC(temp, sizeof(*temp));                                        \
166         memcpy(temp, it, sizeof(*temp));                                       \
167         llu_i2info(inode)->lli_it = temp;                                      \
168         CDEBUG(D_DENTRY, "alloc intent %p to inode %p(ino %llu)\n",            \
169                         temp, inode, (long long)llu_i2stat(inode)->st_ino);    \
170 } while(0)
171
172
173 #define LL_GET_INTENT(inode, it)                                               \
174 do {                                                                           \
175         it = llu_i2info(inode)->lli_it;                                        \
176                                                                                \
177         LASSERT(it);                                                           \
178         llu_i2info(inode)->lli_it = NULL;                                      \
179         CDEBUG(D_DENTRY, "dettach intent %p from inode %p(ino %llu)\n",        \
180                         it, inode, (long long)llu_i2stat(inode)->st_ino);      \
181 } while(0)
182
183 /* interpet return codes from intent lookup */
184 #define LL_LOOKUP_POSITIVE 1
185 #define LL_LOOKUP_NEGATIVE 2
186
187 static inline struct lu_fid *ll_inode2fid(struct inode *inode)
188 {
189         LASSERT(inode != NULL);
190         return &llu_i2info(inode)->lli_fid;
191 }
192
193 struct it_cb_data {
194         struct inode *icbd_parent;
195         struct pnode *icbd_child;
196         obd_id hash;
197 };
198
199 void ll_i2gids(__u32 *suppgids, struct inode *i1,struct inode *i2);
200
201 typedef int (*intent_finish_cb)(struct ptlrpc_request *,
202                                 struct inode *parent, struct pnode *pnode,
203                                 struct lookup_intent *, int offset, obd_id ino);
204 int llu_intent_lock(struct inode *parent, struct pnode *pnode,
205                     struct lookup_intent *, int flags, intent_finish_cb);
206
207 static inline __u64 ll_file_maxbytes(struct inode *inode)
208 {
209         return llu_i2info(inode)->lli_maxbytes;
210 }
211
212 struct mount_option_s
213 {
214         char *md_uuid;
215         char *dt_uuid;
216 };
217
218 #define IS_BAD_PTR(ptr)         \
219         ((unsigned long)(ptr) == 0 || (unsigned long)(ptr) > -1000UL)
220
221 /* llite_lib.c */
222 int liblustre_process_log(struct config_llog_instance *cfg, char *mgsnid,
223                           char *profile, int allow_recov);
224 int ll_parse_mount_target(const char *target, char **mgsnid,
225                           char **fsname);
226
227 extern struct mount_option_s mount_option;
228
229 /* super.c */
230 void llu_update_inode(struct inode *inode, struct lustre_md *md);
231 void obdo_to_inode(struct inode *dst, struct obdo *src, obd_flag valid);
232 void obdo_from_inode(struct obdo *dst, struct inode *src, obd_flag valid);
233 int ll_it_open_error(int phase, struct lookup_intent *it);
234 struct inode *llu_iget(struct filesys *fs, struct lustre_md *md);
235 int llu_inode_getattr(struct inode *inode, struct obdo *obdo,
236                       __u64 ioepoch, int sync);
237 int llu_md_setattr(struct inode *inode, struct md_op_data *op_data,
238                    struct md_open_data **mod);
239 int llu_setattr_raw(struct inode *inode, struct iattr *attr);
240 int llu_put_grouplock(struct inode *inode, unsigned long arg);
241
242 extern struct fssw_ops llu_fssw_ops;
243
244 /* file.c */
245 void llu_prep_md_op_data(struct md_op_data *op_data, struct inode *i1,
246                          struct inode *i2, const char *name, int namelen,
247                          int mode, __u32 opc);
248 void llu_finish_md_op_data(struct md_op_data *op_data);
249 int llu_create(struct inode *dir, struct pnode_base *pnode, int mode);
250 int llu_local_open(struct llu_inode_info *lli, struct lookup_intent *it);
251 int llu_iop_open(struct pnode *pnode, int flags, mode_t mode);
252 void llu_done_writing_attr(struct inode *inode, struct md_op_data *op_data);
253 int llu_md_close(struct obd_export *md_exp, struct inode *inode);
254 void llu_pack_inode2opdata(struct inode *inode, struct md_op_data *op_data,
255                            struct lustre_handle *fh);
256 int llu_file_release(struct inode *inode);
257 int llu_som_update(struct inode *inode, struct md_op_data *op_data);
258 int llu_iop_close(struct inode *inode);
259 _SYSIO_OFF_T llu_iop_pos(struct inode *ino, _SYSIO_OFF_T off);
260 int llu_vmtruncate(struct inode * inode, loff_t offset, obd_flag obd_flags);
261 void obdo_refresh_inode(struct inode *dst, struct obdo *src, obd_flag valid);
262 int llu_objects_destroy(struct ptlrpc_request *request, struct inode *dir);
263 void llu_ioepoch_open(struct llu_inode_info *lli, __u64 ioepoch);
264
265 /* rw.c */
266 int llu_iop_read(struct inode *ino, struct ioctx *ioctxp);
267 int llu_iop_write(struct inode *ino, struct ioctx *ioctxp);
268 int llu_iop_iodone(struct ioctx *ioctxp);
269 int llu_glimpse_size(struct inode *inode);
270 int llu_extent_lock(struct ll_file_data *fd, struct inode *inode,
271                     struct lov_stripe_md *lsm, int mode,
272                     ldlm_policy_data_t *policy, struct lustre_handle *lockh,
273                     int ast_flags);
274 int llu_extent_unlock(struct ll_file_data *fd, struct inode *inode,
275                       struct lov_stripe_md *lsm, int mode,
276                       struct lustre_handle *lockh);
277
278 /* namei.c */
279 int llu_iop_lookup(struct pnode *pnode,
280                    struct inode **inop,
281                    struct intent *intnt,
282                    const char *path);
283 void unhook_stale_inode(struct pnode *pno);
284 struct inode *llu_inode_from_lock(struct ldlm_lock *lock);
285 int llu_md_blocking_ast(struct ldlm_lock *lock,
286                         struct ldlm_lock_desc *desc,
287                         void *data, int flag);
288
289 /* dir.c */
290 ssize_t llu_iop_filldirentries(struct inode *ino, _SYSIO_OFF_T *basep,
291                                char *buf, size_t nbytes);
292
293 /* liblustre/llite_fid.c*/
294 unsigned long llu_fid_build_ino(struct llu_sb_info *sbi,
295                                 struct lu_fid *fid);
296
297 /* ext2 related */
298 #define EXT2_NAME_LEN (255)
299
300 struct ext2_dirent {
301         __u32   inode;
302         __u16   rec_len;
303         __u8    name_len;
304         __u8    file_type;
305         char    name[EXT2_NAME_LEN];
306 };
307
308 #define EXT2_DIR_PAD                    4
309 #define EXT2_DIR_ROUND                  (EXT2_DIR_PAD - 1)
310 #define EXT2_DIR_REC_LEN(name_len)      (((name_len) + 8 + EXT2_DIR_ROUND) & \
311                                          ~EXT2_DIR_ROUND)
312
313 static inline struct ext2_dirent *ext2_next_entry(struct ext2_dirent *p)
314 {
315         return (struct ext2_dirent*)((char*) p + le16_to_cpu(p->rec_len));
316 }
317
318 int llu_merge_lvb(struct inode *inode);
319
320 static inline void inode_init_lvb(struct inode *inode, struct ost_lvb *lvb)
321 {
322         struct intnl_stat *st = llu_i2stat(inode);
323         lvb->lvb_size = st->st_size;
324         lvb->lvb_blocks = st->st_blocks;
325         lvb->lvb_mtime = st->st_mtime;
326         lvb->lvb_atime = st->st_atime;
327         lvb->lvb_ctime = st->st_ctime;
328 }
329
330 #define LLU_IO_GROUP_SIZE(x) \
331         (sizeof(struct llu_io_group) + \
332          (sizeof(struct ll_async_page) + \
333           sizeof(cfs_page_t) + \
334           llap_cookie_size) * (x))
335
336 struct llu_io_session {
337         struct inode           *lis_inode;
338         int                     lis_cmd;
339         int                     lis_max_groups;
340         int                     lis_ngroups;
341         int                     lis_rc;
342         __u64                   lis_rwcount;
343 };
344
345 struct llu_io_group
346 {
347         struct lustre_rw_params *lig_params;
348         int                     lig_rc;
349         __u64                   lig_rwcount;
350 };
351
352 struct llu_io_session;
353 void put_io_group(struct llu_io_group *group);
354
355 int cl_sb_init(struct llu_sb_info *sbi);
356 int cl_sb_fini(struct llu_sb_info *sbi);
357 int cl_inode_init(struct inode *inode, struct lustre_md *md);
358 void cl_inode_fini(struct inode *inode);
359
360 void llu_io_init(struct cl_io *io, struct inode *inode, int write);
361
362 struct slp_io {
363         struct llu_io_session *sio_session;
364 };
365
366 struct slp_session {
367         struct slp_io ss_ios;
368 };
369
370 static inline struct slp_session *slp_env_session(const struct lu_env *env)
371 {
372         extern struct lu_context_key slp_session_key;
373         struct slp_session *ses;
374         ses = lu_context_key_get(env->le_ses, &slp_session_key);
375         LASSERT(ses != NULL);
376         return ses;
377 }
378 static inline struct slp_io *slp_env_io(const struct lu_env *env)
379 {
380         return &slp_env_session(env)->ss_ios;
381 }
382
383 /* lclient compat stuff */
384 #define cl_inode_info llu_inode_info
385 #define cl_i2info(info) llu_i2info(info)
386 #define cl_inode_mode(inode) (llu_i2stat(inode)->st_mode)
387 #define cl_i2sbi llu_i2sbi
388 #define cl_isize_read(inode)             (llu_i2stat(inode)->st_size)
389 #define cl_isize_write(inode,kms)        do{llu_i2stat(inode)->st_size = kms;}while(0)
390 #define cl_isize_write_nolock(inode,kms) cl_isize_write(inode,kms)
391
392 static inline void cl_isize_lock(struct inode *inode, int lsmlock)
393 {
394 }
395
396 static inline void cl_isize_unlock(struct inode *inode, int lsmlock)
397 {
398 }
399
400 static inline int cl_merge_lvb(struct inode *inode)
401 {
402         return llu_merge_lvb(inode);
403 }
404
405 #define cl_inode_atime(inode) (llu_i2stat(inode)->st_atime)
406 #define cl_inode_ctime(inode) (llu_i2stat(inode)->st_ctime)
407 #define cl_inode_mtime(inode) (llu_i2stat(inode)->st_mtime)
408
409 static inline struct obd_capa *cl_capa_lookup(struct inode *inode,
410                                               enum cl_req_type crt)
411 {
412         return NULL;
413 }
414
415 #endif