Whamcloud - gitweb
f258ec92a1661c0b06e31ae70c83d18bc69231af
[fs/lustre-release.git] / lustre / liblustre / llite_lib.h
1 #ifndef __LLU_H_
2 #define __LLU_H_
3
4 #include <liblustre.h>
5 #include <linux/obd.h>
6 #include <linux/obd_class.h>
7 #include <linux/lustre_mds.h>
8 #include <linux/lustre_lite.h>
9
10 #include <sys/types.h>
11 #include <sys/stat.h>
12
13 #define PAGE_CACHE_MAXBYTES ((__u64)(~0UL) << PAGE_CACHE_SHIFT)
14
15 struct ll_file_data {
16         struct obd_client_handle fd_mds_och;
17         __u32 fd_flags;
18 };
19
20 struct llu_sb_info
21 {
22         struct obd_uuid         ll_sb_uuid;
23         struct obd_export      *ll_mdc_exp;
24         struct obd_export      *ll_osc_exp;
25         obd_id                  ll_rootino;
26         int                     ll_flags;
27         struct list_head        ll_conn_chain;
28
29         struct obd_uuid         ll_mds_uuid;
30         struct obd_uuid         ll_mds_peer_uuid;
31         char                   *ll_instance; 
32 };
33
34 #define LLI_F_HAVE_OST_SIZE_LOCK        0
35 #define LLI_F_HAVE_MDS_SIZE_LOCK        1
36 #define LLI_F_PREFER_EXTENDED_SIZE      2
37
38 struct llu_inode_info {
39         struct llu_sb_info     *lli_sbi;
40         struct ll_fid           lli_fid;
41
42         struct lov_stripe_md   *lli_smd;
43         char                   *lli_symlink_name;
44         struct semaphore        lli_open_sem;
45         __u64                   lli_maxbytes;
46         unsigned long           lli_flags;
47
48         /* for libsysio */
49         struct file_identifier  lli_sysio_fid;
50
51         struct lookup_intent   *lli_it;
52
53         /* XXX workaround for libsysio */
54         int                     lli_stale_flag;
55
56         /* in libsysio we have no chance to store data in file,
57          * so place it here. since it's possible that an file
58          * was opened several times without close, we track an
59          * open_count here */
60         struct ll_file_data    *lli_file_data;
61         int                     lli_open_count;
62
63         /* stat FIXME not 64 bit clean */
64         dev_t                   lli_st_dev;
65         ino_t                   lli_st_ino;
66         mode_t                  lli_st_mode;
67         nlink_t                 lli_st_nlink;
68         uid_t                   lli_st_uid;
69         gid_t                   lli_st_gid;
70         dev_t                   lli_st_rdev;
71         loff_t                  lli_st_size;
72         unsigned int            lli_st_blksize;
73         unsigned int            lli_st_blocks;
74         time_t                  lli_st_atime;
75         time_t                  lli_st_mtime;
76         time_t                  lli_st_ctime;
77
78         /* not for stat, change it later */
79         int                     lli_st_flags;
80         unsigned long           lli_st_generation;
81 };
82
83 #define LLU_SYSIO_COOKIE_SIZE(x) \
84         (sizeof(struct llu_sysio_cookie) + \
85          sizeof(struct ll_async_page) * (x) + \
86          sizeof(struct page) * (x))
87
88 struct llu_sysio_cookie {
89         struct obd_sync_io_container lsc_osic;
90         struct inode           *lsc_inode;
91         int                     lsc_npages;
92         struct ll_async_page   *lsc_llap;
93         struct page            *lsc_pages;
94         __u64                   lsc_rwcount;
95 };
96
97 /* XXX why uio.h haven't the definition? */
98 #define MAX_IOVEC 32
99
100 struct llu_sysio_callback_args
101 {
102         int ncookies;
103         struct llu_sysio_cookie *cookies[MAX_IOVEC];
104 };
105
106 static inline struct llu_sb_info *llu_fs2sbi(struct filesys *fs)
107 {
108         return (struct llu_sb_info*)(fs->fs_private);
109 }
110
111 static inline struct llu_inode_info *llu_i2info(struct inode *inode)
112 {
113         return (struct llu_inode_info*)(inode->i_private);
114 }
115
116 static inline struct llu_sb_info *llu_i2sbi(struct inode *inode)
117 {
118         return llu_i2info(inode)->lli_sbi;
119 }
120
121 #if 0
122 static inline struct client_obd *sbi2mdc(struct llu_sb_info *sbi)
123 {
124         struct obd_device *obd = class_conn2obd(&sbi->ll_mdc_conn);
125         if (obd == NULL)
126                 LBUG();
127         return &obd->u.cli;
128 }
129 #endif
130
131 static inline struct obd_export *llu_i2obdexp(struct inode *inode)
132 {
133         return llu_i2info(inode)->lli_sbi->ll_osc_exp;
134 }
135
136 static inline struct obd_export *llu_i2mdcexp(struct inode *inode)
137 {
138         return llu_i2info(inode)->lli_sbi->ll_mdc_exp;
139 }
140
141
142 #define LL_SAVE_INTENT(inode, it)                                              \
143 do {                                                                           \
144         struct lookup_intent *temp;                                            \
145         LASSERT(llu_i2info(inode)->lli_it == NULL);                            \
146         OBD_ALLOC(temp, sizeof(*temp));                                        \
147         memcpy(temp, it, sizeof(*temp));                                       \
148         llu_i2info(inode)->lli_it = temp;                                      \
149         CDEBUG(D_DENTRY, "alloc intent %p to inode %p(ino %lu)\n",             \
150                         temp, inode, llu_i2info(inode)->lli_st_ino);           \
151 } while(0)
152
153
154 #define LL_GET_INTENT(inode, it)                                               \
155 do {                                                                           \
156         it = llu_i2info(inode)->lli_it;                                        \
157                                                                                \
158         LASSERT(it);                                                           \
159         llu_i2info(inode)->lli_it = NULL;                                      \
160         CDEBUG(D_DENTRY, "dettach intent %p from inode %p(ino %lu)\n",         \
161                         it, inode, llu_i2info(inode)->lli_st_ino);             \
162 } while(0)
163
164 /* interpet return codes from intent lookup */
165 #define LL_LOOKUP_POSITIVE 1
166 #define LL_LOOKUP_NEGATIVE 2
167
168 static inline void ll_inode2fid(struct ll_fid *fid, struct inode *inode)
169 {
170         *fid = llu_i2info(inode)->lli_fid;
171 }
172
173 struct it_cb_data {
174         struct inode *icbd_parent;
175         struct pnode *icbd_child;
176         obd_id hash;
177 };
178
179 static inline void ll_i2uctxt(struct ll_uctxt *ctxt, struct inode *i1,
180                               struct inode *i2)
181 {
182         struct llu_inode_info *lli1 = llu_i2info(i1);
183         struct llu_inode_info *lli2;
184
185         LASSERT(i1);
186         LASSERT(ctxt);
187
188         if (in_group_p(lli1->lli_st_gid))
189                 ctxt->gid1 = lli1->lli_st_gid;
190         else
191                 ctxt->gid1 = -1;
192
193         if (i2) {
194                 lli2 = llu_i2info(i2);
195                 if (in_group_p(lli2->lli_st_gid))
196                         ctxt->gid2 = lli2->lli_st_gid;
197                 else
198                         ctxt->gid2 = -1;
199         } else 
200                 ctxt->gid2 = 0;
201 }
202
203
204 typedef int (*intent_finish_cb)(struct ptlrpc_request *,
205                                 struct inode *parent, struct pnode *pnode, 
206                                 struct lookup_intent *, int offset, obd_id ino);
207 int llu_intent_lock(struct inode *parent, struct pnode *pnode,
208                     struct lookup_intent *, int flags, intent_finish_cb);
209
210 /* FIXME */
211 static inline int ll_permission(struct inode *inode, int flag, void * unused)
212 {
213         return 0;
214 }
215
216 #if 0
217 static inline int it_disposition(struct lookup_intent *it, int flag)
218 {
219         return it->d.lustre.it_disposition & flag;
220 }
221
222 static inline void it_set_disposition(struct lookup_intent *it, int flag)
223 {
224         it->d.lustre.it_disposition |= flag;
225 }
226 #endif
227
228 static inline __u64 ll_file_maxbytes(struct inode *inode)
229 {
230         return llu_i2info(inode)->lli_maxbytes;
231 }
232
233 struct mount_option_s
234 {
235         char *mdc_uuid;
236         char *osc_uuid;
237 };
238
239 /* llite_lib.c */
240 void generate_random_uuid(unsigned char uuid_out[16]);
241 int liblustre_process_log(struct config_llog_instance *cfg);
242 int ll_parse_mount_target(const char *target, char **mdsnid,
243                           char **mdsname, char **profile);
244
245 extern int g_zconf;
246 extern char   *g_zconf_mdsnid;
247 extern char   *g_zconf_mdsname;
248 extern char   *g_zconf_profile;
249 extern struct mount_option_s mount_option;
250
251 /* super.c */
252 void llu_update_inode(struct inode *inode, struct mds_body *body,
253                       struct lov_stripe_md *lmm);
254 void obdo_to_inode(struct inode *dst, struct obdo *src, obd_flag valid);
255 void obdo_from_inode(struct obdo *dst, struct inode *src, obd_flag valid);
256 //struct inode* llu_new_inode(struct filesys *fs, ino_t ino, mode_t mode);
257 //int llu_inode_getattr(struct inode *inode, struct lov_stripe_md *lsm, void *ostdata);
258 int ll_it_open_error(int phase, struct lookup_intent *it);
259 struct inode *llu_iget(struct filesys *fs, struct lustre_md *md);
260 int llu_inode_getattr(struct inode *inode, struct lov_stripe_md *lsm);
261
262 extern struct fssw_ops llu_fssw_ops;
263
264 /* file.c */
265 void llu_prepare_mdc_op_data(struct mdc_op_data *data,
266                              struct inode *i1,
267                              struct inode *i2,
268                              const char *name,
269                              int namelen,
270                              int mode);
271 int llu_create(struct inode *dir, struct pnode_base *pnode, int mode);
272 int llu_iop_open(struct pnode *pnode, int flags, mode_t mode);
273 int llu_mdc_close(struct obd_export *mdc_exp, struct inode *inode);
274 int llu_iop_close(struct inode *inode);
275 int llu_iop_ipreadv(struct inode *ino, struct ioctx *ioctxp);
276 int llu_iop_ipwritev(struct inode *ino, struct ioctx *ioctxp);
277 int llu_vmtruncate(struct inode * inode, loff_t offset);
278 void obdo_refresh_inode(struct inode *dst, struct obdo *src, obd_flag valid);
279 int llu_objects_destroy(struct ptlrpc_request *request, struct inode *dir);
280
281 /* rw.c */
282 int llu_iop_iodone(struct ioctx *ioctxp __IS_UNUSED);
283 struct llu_sysio_callback_args*
284 llu_file_write(struct inode *inode, const struct iovec *iovec,
285                        size_t iovlen, loff_t pos);
286 struct llu_sysio_callback_args*
287 llu_file_read(struct inode *inode, const struct iovec *iovec,
288                        size_t iovlen, loff_t pos);
289 int llu_extent_lock_no_validate(struct ll_file_data *fd,
290                                struct inode *inode,
291                                struct lov_stripe_md *lsm,
292                                int mode,
293                                struct ldlm_extent *extent,
294                                struct lustre_handle *lockh,
295                                int ast_flags);
296 int llu_extent_lock(struct ll_file_data *fd, struct inode *inode,
297                    struct lov_stripe_md *lsm,
298                    int mode, struct ldlm_extent *extent,
299                    struct lustre_handle *lockh);
300 int llu_extent_unlock(struct ll_file_data *fd, struct inode *inode,
301                 struct lov_stripe_md *lsm, int mode,
302                 struct lustre_handle *lockh);
303
304 /* namei.c */
305 int llu_iop_lookup(struct pnode *pnode,
306                    struct inode **inop,
307                    struct intent *intnt,
308                    const char *path);
309 void unhook_stale_inode(struct pnode *pno);
310 struct inode *llu_inode_from_lock(struct ldlm_lock *lock);
311
312 #endif