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