Whamcloud - gitweb
f242b45b9f65ba0a8eace6f1f75e99fc4a226f2b
[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
5 #ifndef __LLU_H_
6 #define __LLU_H_
7
8 #include <liblustre.h>
9 #include <obd.h>
10 #include <obd_class.h>
11 #include <lustre_mdc.h>
12 #include <lustre_lite.h>
13 #include <lustre_ver.h>
14
15 #include <sys/types.h>
16 #include <sys/stat.h>
17
18 /* This should not be "optimized" use ~0ULL because page->index is a long and 
19  * 32-bit systems are therefore limited to 16TB in a mapping */
20 #define PAGE_CACHE_MAXBYTES ((__u64)(~0UL) << CFS_PAGE_SHIFT)
21
22 struct ll_file_data {
23         struct obd_client_handle fd_mds_och;
24         __u32 fd_flags;
25         struct lustre_handle fd_cwlockh;
26         unsigned long fd_gid;
27 };
28
29 struct llu_sb_info {
30         struct obd_uuid          ll_sb_uuid;
31         struct obd_export       *ll_md_exp;
32         struct obd_export       *ll_dt_exp;
33         struct lu_fid            ll_root_fid;
34         int                      ll_flags;
35         struct lustre_client_ocd ll_lco;
36         struct list_head         ll_conn_chain;
37
38         struct obd_uuid          ll_mds_uuid;
39         struct obd_uuid          ll_mds_peer_uuid;
40         char                    *ll_instance;
41 };
42
43 #define LL_SBI_NOLCK            0x1
44
45 enum lli_flags {
46         /* MDS has an authority for the Size-on-MDS attributes. */
47         LLIF_MDS_SIZE_LOCK      = (1 << 0),
48 };
49
50 struct llu_inode_info {
51         struct llu_sb_info     *lli_sbi;
52         struct lu_fid           lli_fid;
53
54         struct lov_stripe_md   *lli_smd;
55         char                   *lli_symlink_name;
56         struct semaphore        lli_open_sem;
57         __u64                   lli_maxbytes;
58         unsigned long           lli_flags;
59         __u64                   lli_ioepoch;
60
61         /* for libsysio */
62         struct file_identifier  lli_sysio_fid;
63
64         struct lookup_intent   *lli_it;
65
66         /* XXX workaround for libsysio readdir */
67         loff_t                  lli_dir_pos;
68
69         /* in libsysio we have no chance to store data in file,
70          * so place it here. since it's possible that an file
71          * was opened several times without close, we track an
72          * open_count here */
73         struct ll_file_data    *lli_file_data;
74         int                     lli_open_flags;
75         int                     lli_open_count;
76
77         /* not for stat, change it later */
78         int                     lli_st_flags;
79         unsigned long           lli_st_generation;
80 };
81
82 static inline struct llu_sb_info *llu_fs2sbi(struct filesys *fs)
83 {
84         return (struct llu_sb_info*)(fs->fs_private);
85 }
86
87 static inline struct llu_inode_info *llu_i2info(struct inode *inode)
88 {
89         return (struct llu_inode_info*)(inode->i_private);
90 }
91
92 static inline struct intnl_stat *llu_i2stat(struct inode *inode)
93 {
94         return &inode->i_stbuf;
95 }
96
97 static inline struct llu_sb_info *llu_i2sbi(struct inode *inode)
98 {
99         return llu_i2info(inode)->lli_sbi;
100 }
101
102 static inline struct obd_export *llu_i2obdexp(struct inode *inode)
103 {
104         return llu_i2info(inode)->lli_sbi->ll_dt_exp;
105 }
106
107 static inline struct obd_export *llu_i2mdcexp(struct inode *inode)
108 {
109         return llu_i2info(inode)->lli_sbi->ll_md_exp;
110 }
111
112 static inline int llu_is_root_inode(struct inode *inode)
113 {
114         return (fid_seq(&llu_i2info(inode)->lli_fid) ==
115                 fid_seq(&llu_i2info(inode)->lli_sbi->ll_root_fid) &&
116                 fid_oid(&llu_i2info(inode)->lli_fid) ==
117                 fid_oid(&llu_i2info(inode)->lli_sbi->ll_root_fid));
118 }
119
120 #define LL_SAVE_INTENT(inode, it)                                              \
121 do {                                                                           \
122         struct lookup_intent *temp;                                            \
123         LASSERT(llu_i2info(inode)->lli_it == NULL);                            \
124         OBD_ALLOC(temp, sizeof(*temp));                                        \
125         memcpy(temp, it, sizeof(*temp));                                       \
126         llu_i2info(inode)->lli_it = temp;                                      \
127         CDEBUG(D_DENTRY, "alloc intent %p to inode %p(ino %llu)\n",            \
128                         temp, inode, (long long)llu_i2stat(inode)->st_ino);    \
129 } while(0)
130
131
132 #define LL_GET_INTENT(inode, it)                                               \
133 do {                                                                           \
134         it = llu_i2info(inode)->lli_it;                                        \
135                                                                                \
136         LASSERT(it);                                                           \
137         llu_i2info(inode)->lli_it = NULL;                                      \
138         CDEBUG(D_DENTRY, "dettach intent %p from inode %p(ino %llu)\n",        \
139                         it, inode, (long long)llu_i2stat(inode)->st_ino);      \
140 } while(0)
141
142 /* interpet return codes from intent lookup */
143 #define LL_LOOKUP_POSITIVE 1
144 #define LL_LOOKUP_NEGATIVE 2
145
146 static inline struct lu_fid *ll_inode2fid(struct inode *inode)
147 {
148         LASSERT(inode != NULL);
149         return &llu_i2info(inode)->lli_fid;
150 }
151
152 struct it_cb_data {
153         struct inode *icbd_parent;
154         struct pnode *icbd_child;
155         obd_id hash;
156 };
157
158 void ll_i2gids(__u32 *suppgids, struct inode *i1,struct inode *i2);
159
160 typedef int (*intent_finish_cb)(struct ptlrpc_request *,
161                                 struct inode *parent, struct pnode *pnode,
162                                 struct lookup_intent *, int offset, obd_id ino);
163 int llu_intent_lock(struct inode *parent, struct pnode *pnode,
164                     struct lookup_intent *, int flags, intent_finish_cb);
165
166 static inline __u64 ll_file_maxbytes(struct inode *inode)
167 {
168         return llu_i2info(inode)->lli_maxbytes;
169 }
170
171 struct mount_option_s
172 {
173         char *md_uuid;
174         char *dt_uuid;
175 };
176
177 #define IS_BAD_PTR(ptr)         \
178         ((unsigned long)(ptr) == 0 || (unsigned long)(ptr) > -1000UL)
179
180 /* llite_lib.c */
181 int liblustre_process_log(struct config_llog_instance *cfg, char *mgsnid,
182                           char *profile, int allow_recov);
183 int ll_parse_mount_target(const char *target, char **mgsnid,
184                           char **fsname);
185
186 extern struct mount_option_s mount_option;
187
188 /* super.c */
189 void llu_update_inode(struct inode *inode, struct mdt_body *body,
190                       struct lov_stripe_md *lmm);
191 void obdo_to_inode(struct inode *dst, struct obdo *src, obd_flag valid);
192 void obdo_from_inode(struct obdo *dst, struct inode *src, obd_flag valid);
193 int ll_it_open_error(int phase, struct lookup_intent *it);
194 struct inode *llu_iget(struct filesys *fs, struct lustre_md *md);
195 int llu_inode_getattr(struct inode *inode, struct obdo *obdo);
196 int llu_md_setattr(struct inode *inode, struct md_op_data *op_data);
197 int llu_setattr_raw(struct inode *inode, struct iattr *attr);
198
199 extern struct fssw_ops llu_fssw_ops;
200
201 /* file.c */
202 void llu_prep_md_op_data(struct md_op_data *op_data, struct inode *i1,
203                          struct inode *i2, const char *name, int namelen,
204                          int mode, __u32 opc);
205 void llu_finish_md_op_data(struct md_op_data *op_data);
206 int llu_create(struct inode *dir, struct pnode_base *pnode, int mode);
207 int llu_local_open(struct llu_inode_info *lli, struct lookup_intent *it);
208 int llu_iop_open(struct pnode *pnode, int flags, mode_t mode);
209 int llu_md_close(struct obd_export *md_exp, struct inode *inode);
210 int llu_file_release(struct inode *inode);
211 int llu_sizeonmds_update(struct inode *inode, struct lustre_handle *fh,
212                          __u64 ioepoch);
213 int llu_iop_close(struct inode *inode);
214 _SYSIO_OFF_T llu_iop_pos(struct inode *ino, _SYSIO_OFF_T off);
215 int llu_vmtruncate(struct inode * inode, loff_t offset, obd_flag obd_flags);
216 void obdo_refresh_inode(struct inode *dst, struct obdo *src, obd_flag valid);
217 int llu_objects_destroy(struct ptlrpc_request *request, struct inode *dir);
218
219 /* rw.c */
220 int llu_iop_read(struct inode *ino, struct ioctx *ioctxp);
221 int llu_iop_write(struct inode *ino, struct ioctx *ioctxp);
222 int llu_iop_iodone(struct ioctx *ioctxp);
223 int llu_local_size(struct inode *inode);
224 int llu_glimpse_size(struct inode *inode);
225 int llu_extent_lock(struct ll_file_data *fd, struct inode *inode,
226                     struct lov_stripe_md *lsm, int mode,
227                     ldlm_policy_data_t *policy, struct lustre_handle *lockh,
228                     int ast_flags);
229 int llu_extent_unlock(struct ll_file_data *fd, struct inode *inode,
230                       struct lov_stripe_md *lsm, int mode,
231                       struct lustre_handle *lockh);
232
233 /* namei.c */
234 int llu_iop_lookup(struct pnode *pnode,
235                    struct inode **inop,
236                    struct intent *intnt,
237                    const char *path);
238 void unhook_stale_inode(struct pnode *pno);
239 struct inode *llu_inode_from_lock(struct ldlm_lock *lock);
240 int llu_md_blocking_ast(struct ldlm_lock *lock,
241                         struct ldlm_lock_desc *desc,
242                         void *data, int flag);
243
244 /* dir.c */
245 ssize_t llu_iop_filldirentries(struct inode *ino, _SYSIO_OFF_T *basep, 
246                                char *buf, size_t nbytes);
247
248 /* liblustre/llite_fid.c*/
249 unsigned long llu_fid_build_ino(struct llu_sb_info *sbi, 
250                                 struct lu_fid *fid);
251
252 /* ext2 related */
253 #define EXT2_NAME_LEN (255)
254
255 struct ext2_dirent {
256         __u32   inode;
257         __u16   rec_len;
258         __u8    name_len;
259         __u8    file_type;
260         char    name[EXT2_NAME_LEN];
261 };
262
263 #define EXT2_DIR_PAD                    4
264 #define EXT2_DIR_ROUND                  (EXT2_DIR_PAD - 1)
265 #define EXT2_DIR_REC_LEN(name_len)      (((name_len) + 8 + EXT2_DIR_ROUND) & \
266                                          ~EXT2_DIR_ROUND)
267
268 static inline struct ext2_dirent *ext2_next_entry(struct ext2_dirent *p)
269 {
270         return (struct ext2_dirent*)((char*) p + le16_to_cpu(p->rec_len));
271 }
272
273 static inline void inode_init_lvb(struct inode *inode, struct ost_lvb *lvb)
274 {
275         struct intnl_stat *st = llu_i2stat(inode);
276         lvb->lvb_size = st->st_size;
277         lvb->lvb_blocks = st->st_blocks;
278         lvb->lvb_mtime = st->st_mtime;
279         lvb->lvb_atime = st->st_atime;
280         lvb->lvb_ctime = st->st_ctime;
281 }
282
283 #endif