Whamcloud - gitweb
LU-2675 lov: remove unused lov obd functions
[fs/lustre-release.git] / lustre / liblustre / llite_lib.h
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2012, 2013, Intel Corporation.
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 #include <fcntl.h>
40 #include <sys/queue.h>
41 #include <sysio.h>
42 #ifdef HAVE_XTIO_H
43 #include <xtio.h>
44 #endif
45 #include <fs.h>
46 #include <mount.h>
47 #include <inode.h>
48 #ifdef HAVE_FILE_H
49 #include <file.h>
50 #endif
51
52 #include <liblustre.h>
53 #include <obd.h>
54 #include <obd_class.h>
55 #include <lustre_mdc.h>
56 #include <lustre_lite.h>
57 #include <lustre_ver.h>
58
59 #include <sys/types.h>
60 #include <sys/stat.h>
61
62 /* for struct cl_lock_descr and struct cl_io */
63 #include <cl_object.h>
64 #include <lclient.h>
65
66 /* This should not be "optimized" use ~0ULL because page->index is a long and
67  * 32-bit systems are therefore limited to 16TB in a mapping */
68 #define MAX_LFS_FILESIZE ((__u64)(~0UL) << PAGE_CACHE_SHIFT)
69 struct ll_file_data {
70         struct obd_client_handle fd_mds_och;
71         __u32 fd_flags;
72         struct ccc_grouplock fd_grouplock;
73 };
74
75 struct llu_sb_info {
76         struct obd_uuid          ll_sb_uuid;
77         struct obd_export       *ll_md_exp;
78         struct obd_export       *ll_dt_exp;
79         struct lu_fid            ll_root_fid;
80         int                      ll_flags;
81         struct lustre_client_ocd ll_lco;
82         cfs_list_t               ll_conn_chain;
83
84         struct obd_uuid          ll_mds_uuid;
85         struct obd_uuid          ll_mds_peer_uuid;
86         char                    *ll_instance;
87         struct lu_site           *ll_site;
88         struct cl_device         *ll_cl;
89 };
90
91 #define LL_SBI_NOLCK            0x1
92
93 enum lli_flags {
94         /* MDS has an authority for the Size-on-MDS attributes. */
95         LLIF_MDS_SIZE_LOCK      = (1 << 0),
96 };
97
98 struct llu_inode_info {
99         struct llu_sb_info     *lli_sbi;
100         struct lu_fid           lli_fid;
101
102         char                   *lli_symlink_name;
103         __u64                   lli_maxbytes;
104         unsigned long           lli_flags;
105         __u64                   lli_ioepoch;
106
107         /* for libsysio */
108         struct file_identifier  lli_sysio_fid;
109
110         struct lookup_intent   *lli_it;
111
112         /* XXX workaround for libsysio readdir */
113         loff_t                  lli_dir_pos;
114
115         /* in libsysio we have no chance to store data in file,
116          * so place it here. since it's possible that an file
117          * was opened several times without close, we track an
118          * open_count here */
119         struct ll_file_data    *lli_file_data;
120         /* checking lli_has_smd is reliable only inside an IO
121          * i.e, lov stripe has been held. */
122         bool                    lli_has_smd;
123         int                     lli_open_flags;
124         int                     lli_open_count;
125
126         /* not for stat, change it later */
127         int                     lli_st_flags;
128         unsigned long           lli_st_generation;
129         struct cl_object       *lli_clob;
130         /* the most recent timestamps obtained from mds */
131         struct ost_lvb          lli_lvb;
132 };
133
134 static inline struct llu_sb_info *llu_fs2sbi(struct filesys *fs)
135 {
136         return (struct llu_sb_info*)(fs->fs_private);
137 }
138
139 static inline struct llu_inode_info *llu_i2info(struct inode *inode)
140 {
141         return (struct llu_inode_info*)(inode->i_private);
142 }
143
144 static inline int ll_inode_flags(struct inode *inode)
145 {
146         return llu_i2info(inode)->lli_st_flags;
147 }
148
149 static inline struct intnl_stat *llu_i2stat(struct inode *inode)
150 {
151         return &inode->i_stbuf;
152 }
153
154 #define ll_inode_blksize(inode)     (llu_i2stat(inode)->st_blksize)
155
156 static inline struct llu_sb_info *llu_i2sbi(struct inode *inode)
157 {
158         return llu_i2info(inode)->lli_sbi;
159 }
160
161 static inline struct obd_export *llu_i2obdexp(struct inode *inode)
162 {
163         return llu_i2info(inode)->lli_sbi->ll_dt_exp;
164 }
165
166 static inline struct obd_export *llu_i2mdexp(struct inode *inode)
167 {
168         return llu_i2info(inode)->lli_sbi->ll_md_exp;
169 }
170
171 static inline int llu_is_root_inode(struct inode *inode)
172 {
173         return (fid_seq(&llu_i2info(inode)->lli_fid) ==
174                 fid_seq(&llu_i2info(inode)->lli_sbi->ll_root_fid) &&
175                 fid_oid(&llu_i2info(inode)->lli_fid) ==
176                 fid_oid(&llu_i2info(inode)->lli_sbi->ll_root_fid));
177 }
178
179 #define LL_SAVE_INTENT(inode, it)                                              \
180 do {                                                                           \
181         struct lookup_intent *temp;                                            \
182         LASSERT(llu_i2info(inode)->lli_it == NULL);                            \
183         OBD_ALLOC(temp, sizeof(*temp));                                        \
184         memcpy(temp, it, sizeof(*temp));                                       \
185         llu_i2info(inode)->lli_it = temp;                                      \
186         CDEBUG(D_DENTRY, "alloc intent %p to inode %p(ino %llu)\n",            \
187                         temp, inode, (long long)llu_i2stat(inode)->st_ino);    \
188 } while(0)
189
190
191 #define LL_GET_INTENT(inode, it)                                               \
192 do {                                                                           \
193         it = llu_i2info(inode)->lli_it;                                        \
194                                                                                \
195         LASSERT(it);                                                           \
196         llu_i2info(inode)->lli_it = NULL;                                      \
197         CDEBUG(D_DENTRY, "dettach intent %p from inode %p(ino %llu)\n",        \
198                         it, inode, (long long)llu_i2stat(inode)->st_ino);      \
199 } while(0)
200
201 /* interpet return codes from intent lookup */
202 #define LL_LOOKUP_POSITIVE 1
203 #define LL_LOOKUP_NEGATIVE 2
204
205 static inline struct lu_fid *ll_inode2fid(struct inode *inode)
206 {
207         LASSERT(inode != NULL);
208         return &llu_i2info(inode)->lli_fid;
209 }
210
211 struct it_cb_data {
212         struct inode *icbd_parent;
213         struct pnode *icbd_child;
214         obd_id hash;
215 };
216
217 void ll_i2gids(__u32 *suppgids, struct inode *i1,struct inode *i2);
218
219 typedef int (*intent_finish_cb)(struct ptlrpc_request *,
220                                 struct inode *parent, struct pnode *pnode,
221                                 struct lookup_intent *, int offset, obd_id ino);
222
223 static inline __u64 ll_file_maxbytes(struct inode *inode)
224 {
225         return llu_i2info(inode)->lli_maxbytes;
226 }
227
228 struct mount_option_s
229 {
230         char *md_uuid;
231         char *dt_uuid;
232 };
233
234 #define IS_BAD_PTR(ptr)         \
235         ((unsigned long)(ptr) == 0 || (unsigned long)(ptr) > -1000UL)
236
237 /* llite_lib.c */
238 int liblustre_process_log(struct config_llog_instance *cfg, char *mgsnid,
239                           char *profile, int allow_recov);
240 int ll_parse_mount_target(const char *target, char **mgsnid,
241                           char **fsname);
242
243 extern struct mount_option_s mount_option;
244
245 /* super.c */
246 void llu_update_inode(struct inode *inode, struct lustre_md *md);
247 void obdo_to_inode(struct inode *dst, struct obdo *src, obd_flag valid);
248 int ll_it_open_error(int phase, struct lookup_intent *it);
249 struct inode *llu_iget(struct filesys *fs, struct lustre_md *md);
250 int llu_inode_getattr(struct inode *inode, struct obdo *obdo,
251                       __u64 ioepoch, int sync);
252 int llu_md_setattr(struct inode *inode, struct md_op_data *op_data,
253                    struct md_open_data **mod);
254 int llu_setattr_raw(struct inode *inode, struct iattr *attr);
255 int llu_put_grouplock(struct inode *inode, unsigned long arg);
256
257 extern struct fssw_ops llu_fssw_ops;
258
259 /* file.c */
260 void llu_prep_md_op_data(struct md_op_data *op_data, struct inode *i1,
261                          struct inode *i2, const char *name, int namelen,
262                          int mode, __u32 opc);
263 int llu_create(struct inode *dir, struct pnode_base *pnode, int mode);
264 int llu_local_open(struct llu_inode_info *lli, struct lookup_intent *it);
265 int llu_iop_open(struct pnode *pnode, int flags, mode_t mode);
266 void llu_done_writing_attr(struct inode *inode, struct md_op_data *op_data);
267 int llu_md_close(struct obd_export *md_exp, struct inode *inode);
268 void llu_pack_inode2opdata(struct inode *inode, struct md_op_data *op_data,
269                            struct lustre_handle *fh);
270 int llu_file_release(struct inode *inode);
271 int llu_som_update(struct inode *inode, struct md_op_data *op_data);
272 int llu_iop_close(struct inode *inode);
273 _SYSIO_OFF_T llu_iop_pos(struct inode *ino, _SYSIO_OFF_T off);
274 int llu_vmtruncate(struct inode * inode, loff_t offset, obd_flag obd_flags);
275 void obdo_refresh_inode(struct inode *dst, struct obdo *src, obd_flag valid);
276 int llu_objects_destroy(struct ptlrpc_request *request, struct inode *dir);
277 void llu_ioepoch_open(struct llu_inode_info *lli, __u64 ioepoch);
278
279 /* rw.c */
280 int llu_iop_read(struct inode *ino, struct ioctx *ioctxp);
281 int llu_iop_write(struct inode *ino, struct ioctx *ioctxp);
282 int llu_iop_iodone(struct ioctx *ioctxp);
283
284 /* namei.c */
285 int llu_iop_lookup(struct pnode *pnode,
286                    struct inode **inop,
287                    struct intent *intnt,
288                    const char *path);
289 void unhook_stale_inode(struct pnode *pno);
290 struct inode *llu_inode_from_resource_lock(struct ldlm_lock *lock);
291 struct inode *llu_inode_from_lock(struct ldlm_lock *lock);
292 int llu_md_blocking_ast(struct ldlm_lock *lock,
293                         struct ldlm_lock_desc *desc,
294                         void *data, int flag);
295
296 /* dir.c */
297 ssize_t llu_iop_filldirentries(struct inode *ino, _SYSIO_OFF_T *basep,
298                                char *buf, size_t nbytes);
299
300 /* liblustre/llite_fid.c*/
301 unsigned long llu_fid_build_ino(struct llu_sb_info *sbi,
302                                 struct lu_fid *fid);
303
304 /* ext2 related */
305 #define EXT2_NAME_LEN (255)
306
307 struct ext2_dirent {
308         __u32   inode;
309         __u16   rec_len;
310         __u8    name_len;
311         __u8    file_type;
312         char    name[EXT2_NAME_LEN];
313 };
314
315 #define EXT2_DIR_PAD                    4
316 #define EXT2_DIR_ROUND                  (EXT2_DIR_PAD - 1)
317 #define EXT2_DIR_REC_LEN(name_len)      (((name_len) + 8 + EXT2_DIR_ROUND) & \
318                                          ~EXT2_DIR_ROUND)
319
320 static inline struct ext2_dirent *ext2_next_entry(struct ext2_dirent *p)
321 {
322         return (struct ext2_dirent*)((char*) p + le16_to_cpu(p->rec_len));
323 }
324
325 int llu_merge_lvb(const struct lu_env *env, struct inode *inode);
326
327 static inline void inode_init_lvb(struct inode *inode, struct ost_lvb *lvb)
328 {
329         struct intnl_stat *st = llu_i2stat(inode);
330         lvb->lvb_size = st->st_size;
331         lvb->lvb_blocks = st->st_blocks;
332         lvb->lvb_mtime = st->st_mtime;
333         lvb->lvb_atime = st->st_atime;
334         lvb->lvb_ctime = st->st_ctime;
335 }
336
337 #define LLU_IO_GROUP_SIZE(x) \
338         (sizeof(struct llu_io_group) + \
339          (sizeof(struct ll_async_page) + \
340           sizeof(struct page) + \
341           llap_cookie_size) * (x))
342
343 struct llu_io_session {
344         struct inode           *lis_inode;
345         int                     lis_cmd;
346         int                     lis_max_groups;
347         int                     lis_ngroups;
348         int                     lis_rc;
349         __u64                   lis_rwcount;
350 };
351
352 struct llu_io_group
353 {
354         struct lustre_rw_params *lig_params;
355         int                     lig_rc;
356         __u64                   lig_rwcount;
357 };
358
359 struct llu_io_session;
360 void put_io_group(struct llu_io_group *group);
361
362 int cl_sb_init(struct llu_sb_info *sbi);
363 int cl_sb_fini(struct llu_sb_info *sbi);
364
365 void llu_io_init(struct cl_io *io, struct inode *inode, int write);
366
367 struct slp_io {
368         struct llu_io_session *sio_session;
369 };
370
371 struct slp_session {
372         struct slp_io ss_ios;
373 };
374
375 static inline struct slp_session *slp_env_session(const struct lu_env *env)
376 {
377         extern struct lu_context_key slp_session_key;
378         struct slp_session *ses;
379         ses = lu_context_key_get(env->le_ses, &slp_session_key);
380         LASSERT(ses != NULL);
381         return ses;
382 }
383 static inline struct slp_io *slp_env_io(const struct lu_env *env)
384 {
385         return &slp_env_session(env)->ss_ios;
386 }
387
388 /* lclient compat stuff */
389 #define cl_inode_info llu_inode_info
390 #define cl_i2info(info) llu_i2info(info)
391 #define cl_inode_mode(inode) (llu_i2stat(inode)->st_mode)
392 #define cl_i2sbi llu_i2sbi
393 #define cl_isize_read(inode)             (llu_i2stat(inode)->st_size)
394 #define cl_isize_write(inode,kms)        do{llu_i2stat(inode)->st_size = kms;}while(0)
395 #define cl_isize_write_nolock(inode,kms) cl_isize_write(inode,kms)
396
397 static inline struct ll_file_data *cl_iattr2fd(struct inode *inode,
398                                                const struct iattr *attr)
399 {
400         return llu_i2info(inode)->lli_file_data;
401 }
402
403 static inline void cl_isize_lock(struct inode *inode)
404 {
405 }
406
407 static inline void cl_isize_unlock(struct inode *inode)
408 {
409 }
410
411 static inline int cl_merge_lvb(const struct lu_env *env, struct inode *inode)
412 {
413         return llu_merge_lvb(env, inode);
414 }
415
416 #define cl_inode_atime(inode) (llu_i2stat(inode)->st_atime)
417 #define cl_inode_ctime(inode) (llu_i2stat(inode)->st_ctime)
418 #define cl_inode_mtime(inode) (llu_i2stat(inode)->st_mtime)
419
420 static inline struct obd_capa *cl_capa_lookup(struct inode *inode,
421                                               enum cl_req_type crt)
422 {
423         return NULL;
424 }
425
426 static inline void cl_stats_tally(struct cl_device *dev, enum cl_req_type crt,
427                                   int rc)
428 {
429 }
430
431 static inline loff_t i_size_read(struct inode *inode)
432 {
433         return inode->i_stbuf.st_size;
434 }
435
436 static inline void i_size_write(struct inode *inode, loff_t i_sz)
437 {
438         inode->i_stbuf.st_size = i_sz;
439 }
440
441 static inline __u64 hash_x_index(__u64 hash, int hash64)
442 {
443         if (BITS_PER_LONG == 32 && hash64)
444                 hash >>= 32;
445         /* save hash 0 as index 0 because otherwise we'll save it at
446          * page index end (~0UL) and it causes truncate_inode_pages_range()
447          * to loop forever. */
448         return ~0ULL - (hash + !hash);
449 }
450 #endif