Whamcloud - gitweb
7e4084a2f228c273cf6c8b38b1dd82f4a045fc97
[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 void generate_random_uuid(unsigned char uuid_out[16]);
177 int liblustre_process_log(struct config_llog_instance *cfg, char *mgsnid,
178                           char *profile, int allow_recov);
179 int ll_parse_mount_target(const char *target, char **mgsnid,
180                           char **fsname);
181
182 extern struct mount_option_s mount_option;
183
184 /* super.c */
185 void llu_update_inode(struct inode *inode, struct mds_body *body,
186                       struct lov_stripe_md *lmm);
187 void obdo_to_inode(struct inode *dst, struct obdo *src, obd_flag valid);
188 void obdo_from_inode(struct obdo *dst, struct inode *src, obd_flag valid);
189 int ll_it_open_error(int phase, struct lookup_intent *it);
190 struct inode *llu_iget(struct filesys *fs, struct lustre_md *md);
191 int llu_inode_getattr(struct inode *inode, struct lov_stripe_md *lsm);
192 int llu_setattr_raw(struct inode *inode, struct iattr *attr);
193
194 extern struct fssw_ops llu_fssw_ops;
195
196 /* file.c */
197 void llu_prepare_mdc_op_data(struct mdc_op_data *data,
198                              struct inode *i1,
199                              struct inode *i2,
200                              const char *name,
201                              int namelen,
202                              int mode);
203 int llu_create(struct inode *dir, struct pnode_base *pnode, int mode);
204 int llu_local_open(struct llu_inode_info *lli, struct lookup_intent *it);
205 int llu_iop_open(struct pnode *pnode, int flags, mode_t mode);
206 int llu_mdc_close(struct obd_export *mdc_exp, struct inode *inode);
207 int llu_file_release(struct inode *inode);
208 int llu_iop_close(struct inode *inode);
209 _SYSIO_OFF_T llu_iop_pos(struct inode *ino, _SYSIO_OFF_T off);
210 int llu_vmtruncate(struct inode * inode, loff_t offset, obd_flag obd_flags);
211 void obdo_refresh_inode(struct inode *dst, struct obdo *src, obd_flag valid);
212 int llu_objects_destroy(struct ptlrpc_request *request, struct inode *dir);
213
214 /* rw.c */
215 int llu_iop_read(struct inode *ino, struct ioctx *ioctxp);
216 int llu_iop_write(struct inode *ino, struct ioctx *ioctxp);
217 int llu_iop_iodone(struct ioctx *ioctxp);
218 int llu_glimpse_size(struct inode *inode);
219 int llu_extent_lock(struct ll_file_data *fd, struct inode *inode,
220                     struct lov_stripe_md *lsm, int mode,
221                     ldlm_policy_data_t *policy, struct lustre_handle *lockh,
222                     int ast_flags);
223 int llu_extent_unlock(struct ll_file_data *fd, struct inode *inode,
224                       struct lov_stripe_md *lsm, int mode,
225                       struct lustre_handle *lockh);
226
227 /* namei.c */
228 int llu_iop_lookup(struct pnode *pnode,
229                    struct inode **inop,
230                    struct intent *intnt,
231                    const char *path);
232 void unhook_stale_inode(struct pnode *pno);
233 struct inode *llu_inode_from_lock(struct ldlm_lock *lock);
234 int llu_mdc_blocking_ast(struct ldlm_lock *lock,
235                          struct ldlm_lock_desc *desc,
236                          void *data, int flag);
237
238 /* dir.c */
239 ssize_t llu_iop_filldirentries(struct inode *ino, _SYSIO_OFF_T *basep, 
240                                char *buf, size_t nbytes);
241
242 /* ext2 related */
243 #define EXT2_NAME_LEN (255)
244
245 struct ext2_dirent {
246         __u32   inode;
247         __u16   rec_len;
248         __u8    name_len;
249         __u8    file_type;
250         char    name[EXT2_NAME_LEN];
251 };
252
253 #define EXT2_DIR_PAD                    4
254 #define EXT2_DIR_ROUND                  (EXT2_DIR_PAD - 1)
255 #define EXT2_DIR_REC_LEN(name_len)      (((name_len) + 8 + EXT2_DIR_ROUND) & \
256                                          ~EXT2_DIR_ROUND)
257
258 static inline struct ext2_dirent *ext2_next_entry(struct ext2_dirent *p)
259 {
260         return (struct ext2_dirent*)((char*) p + le16_to_cpu(p->rec_len));
261 }
262
263 static inline void inode_init_lvb(struct inode *inode, struct ost_lvb *lvb)
264 {
265         struct intnl_stat *st = llu_i2stat(inode);
266         lvb->lvb_size = st->st_size;
267         lvb->lvb_blocks = st->st_blocks;
268         lvb->lvb_mtime = st->st_mtime;
269         lvb->lvb_atime = st->st_atime;
270         lvb->lvb_ctime = st->st_ctime;
271 }
272
273 #endif