Whamcloud - gitweb
Branch: HEAD
[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  * Lustre Light Super operations
5  *
6  *  Copyright (c) 2002-2004 Cluster File Systems, Inc.
7  *
8  *   This file is part of Lustre, http://www.lustre.org.
9  *
10  *   Lustre is free software; you can redistribute it and/or
11  *   modify it under the terms of version 2 of the GNU General Public
12  *   License as published by the Free Software Foundation.
13  *
14  *   Lustre is distributed in the hope that it will be useful,
15  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *   GNU General Public License for more details.
18  *
19  *   You should have received a copy of the GNU General Public License
20  *   along with Lustre; if not, write to the Free Software
21  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22  */
23
24 #ifndef __LLU_H_
25 #define __LLU_H_
26
27 #include <liblustre.h>
28 #include <linux/obd.h>
29 #include <linux/obd_class.h>
30 #include <linux/lustre_mds.h>
31 #include <linux/lustre_lite.h>
32
33 #include <sys/types.h>
34 #include <sys/stat.h>
35
36 #define PAGE_CACHE_MAXBYTES ((__u64)(~0UL) << PAGE_CACHE_SHIFT)
37
38 struct ll_file_data {
39         struct obd_client_handle fd_mds_och;
40         __u32 fd_flags;
41         struct lustre_handle fd_cwlockh;
42         unsigned long fd_gid;
43 };
44
45 struct llu_sb_info {
46         struct obd_uuid         ll_sb_uuid;
47         struct obd_export      *ll_md_exp;
48         struct obd_export      *ll_dt_exp;
49         struct obd_export      *ll_gt_exp;
50         obd_id                  ll_rootino;
51         int                     ll_flags;
52         struct list_head        ll_conn_chain;
53
54         struct obd_uuid         ll_mds_uuid;
55         struct obd_uuid         ll_mds_peer_uuid;
56         char                   *ll_instance; 
57 };
58
59 #define LL_SBI_NOLCK            0x1
60 #define LL_SBI_READAHEAD        0x2
61
62 #define LLI_F_HAVE_OST_SIZE_LOCK        0
63 #define LLI_F_HAVE_MDS_SIZE_LOCK        1
64 #define LLI_F_PREFER_EXTENDED_SIZE      2
65
66 struct llu_inode_info {
67         struct llu_sb_info     *lli_sbi;
68         struct lustre_id        lli_id;
69
70         struct lov_stripe_md   *lli_smd;
71         char                   *lli_symlink_name;
72         struct semaphore        lli_open_sem;
73         __u64                   lli_maxbytes;
74         unsigned long           lli_flags;
75
76         /* for libsysio */
77         struct file_identifier  lli_sysio_fid;
78
79         struct lookup_intent   *lli_it;
80
81         /* XXX workaround for libsysio readdir */
82         loff_t                  lli_dir_pos;
83
84         /* in libsysio we have no chance to store data in file, so place it
85          * here. since it's possible that an file was opened several times
86          * without close, we track an open_count here */
87         struct ll_file_data    *lli_file_data;
88         int                     lli_open_flags;
89         int                     lli_open_count;
90
91         /* stat FIXME not 64 bit clean */
92         dev_t                   lli_st_dev;
93         ino_t                   lli_st_ino;
94         mode_t                  lli_st_mode;
95         nlink_t                 lli_st_nlink;
96         uid_t                   lli_st_uid;
97         gid_t                   lli_st_gid;
98         dev_t                   lli_st_rdev;
99         loff_t                  lli_st_size;
100         unsigned int            lli_st_blksize;
101         unsigned long           lli_st_blocks;
102         time_t                  lli_st_atime;
103         time_t                  lli_st_mtime;
104         time_t                  lli_st_ctime;
105
106         /* not for stat, change it later */
107         int                     lli_st_flags;
108         unsigned long           lli_st_generation;
109 };
110
111 #define llu_fs2sbi(fs) (struct llu_sb_info *)(fs)->fs_private
112
113 static inline struct llu_inode_info *llu_i2info(struct inode *inode)
114 {
115         return (struct llu_inode_info *)inode->i_private;
116 }
117
118 static inline struct llu_sb_info *llu_i2sbi(struct inode *inode)
119 {
120         return llu_i2info(inode)->lli_sbi;
121 }
122
123 static inline struct obd_export *llu_i2dtexp(struct inode *inode)
124 {
125         return llu_i2info(inode)->lli_sbi->ll_dt_exp;
126 }
127
128 static inline struct obd_export *llu_i2mdexp(struct inode *inode)
129 {
130         return llu_i2info(inode)->lli_sbi->ll_md_exp;
131 }
132
133 static inline int llu_is_root_inode(struct inode *inode)
134 {
135         return (id_ino(&llu_i2info(inode)->lli_id) ==
136                 llu_i2info(inode)->lli_sbi->ll_rootino);
137 }
138
139 #define LL_SAVE_INTENT(inode, it)                                              \
140 do {                                                                           \
141         struct lookup_intent *temp;                                            \
142         LASSERT(llu_i2info(inode)->lli_it == NULL);                            \
143         OBD_ALLOC(temp, sizeof(*temp));                                        \
144         memcpy(temp, it, sizeof(*temp));                                       \
145         llu_i2info(inode)->lli_it = temp;                                      \
146         CDEBUG(D_DENTRY, "alloc intent %p to inode %p(ino %lu)\n",             \
147                         temp, inode, llu_i2info(inode)->lli_st_ino);           \
148 } while(0)
149
150
151 #define LL_GET_INTENT(inode, it)                                               \
152 do {                                                                           \
153         it = llu_i2info(inode)->lli_it;                                        \
154                                                                                \
155         LASSERT(it);                                                           \
156         llu_i2info(inode)->lli_it = NULL;                                      \
157         CDEBUG(D_DENTRY, "dettach intent %p from inode %p(ino %lu)\n",         \
158                         it, inode, llu_i2info(inode)->lli_st_ino);             \
159 } while(0)
160
161 /* interpet return codes from intent lookup */
162 #define LL_LOOKUP_POSITIVE 1
163 #define LL_LOOKUP_NEGATIVE 2
164
165 struct it_cb_data {
166         struct inode *icbd_parent;
167         struct pnode *icbd_child;
168         obd_id hash;
169 };
170
171 static inline void ll_inode2id(struct lustre_id *id,
172                                struct inode *inode)
173 {
174         *id = llu_i2info(inode)->lli_id;
175 }
176
177 typedef int (*intent_finish_cb)(struct ptlrpc_request *,
178                                 struct inode *parent, 
179                                 struct pnode *pnode, 
180                                 struct lookup_intent *, 
181                                 int offset, obd_id ino);
182                                 
183 int llu_intent_lock(struct inode *parent, struct pnode *pnode,
184                     struct lookup_intent *, int flags, 
185                     intent_finish_cb);
186
187 static inline __u64 ll_file_maxbytes(struct inode *inode)
188 {
189         return llu_i2info(inode)->lli_maxbytes;
190 }
191
192 struct mount_option_s
193 {
194         char *mdc_uuid;
195         char *osc_uuid;
196 };
197
198 #define IS_BAD_PTR(ptr) \
199         ((unsigned long)(ptr) == 0 || (unsigned long)(ptr) > -1000UL)
200
201 /* llite_lib.c */
202 void generate_random_uuid(unsigned char uuid_out[16]);
203
204 int liblustre_process_log(struct config_llog_instance *cfg, 
205                           int allow_recov);
206                           
207 int ll_parse_mount_target(const char *target, char **mdsnid,
208                           char **mdsname, char **profile);
209
210 extern char *g_zconf_mdsnid;
211 extern char *g_zconf_mdsname;
212 extern char *g_zconf_profile;
213 extern struct mount_option_s mount_option;
214
215 /* super.c */
216 void llu_update_inode(struct inode *inode, struct mds_body *body,
217                       struct lov_stripe_md *lmm);
218 void obdo_to_inode(struct inode *dst, struct obdo *src, obd_valid valid);
219 void obdo_from_inode(struct obdo *dst, struct inode *src, obd_valid valid);
220 int ll_it_open_error(int phase, struct lookup_intent *it);
221 struct inode *llu_iget(struct filesys *fs, struct lustre_md *md);
222 int llu_inode_getattr(struct inode *inode, struct lov_stripe_md *lsm);
223 int llu_setattr_raw(struct inode *inode, struct iattr *attr);
224
225 extern struct fssw_ops llu_fssw_ops;
226
227 /* file.c */
228 void llu_prepare_mdc_data(struct mdc_op_data *data, struct inode *i1,
229                           struct inode *i2, const char *name, int namelen,
230                           int mode);
231                           
232 int llu_create(struct inode *dir, struct pnode_base *pnode, int mode);
233 int llu_iop_open(struct pnode *pnode, int flags, mode_t mode);
234 int llu_mdc_close(struct obd_export *mdc_exp, struct inode *inode);
235 int llu_iop_close(struct inode *inode);
236 _SYSIO_OFF_T llu_iop_pos(struct inode *ino, _SYSIO_OFF_T off);
237 int llu_vmtruncate(struct inode * inode, loff_t offset);
238 void obdo_refresh_inode(struct inode *dst, struct obdo *src, obd_valid valid);
239 int llu_objects_destroy(struct ptlrpc_request *request, struct inode *dir);
240
241 /* rw.c */
242 int llu_iop_read(struct inode *ino, struct ioctx *ioctxp);
243 int llu_iop_write(struct inode *ino, struct ioctx *ioctxp);
244 int llu_iop_iodone(struct ioctx *ioctxp);
245 int llu_glimpse_size(struct inode *inode);
246 int llu_extent_lock(struct ll_file_data *fd, struct inode *inode,
247                     struct lov_stripe_md *lsm, int mode,
248                     ldlm_policy_data_t *policy, struct lustre_handle *lockh,
249                     int ast_flags);
250 int llu_extent_unlock(struct ll_file_data *fd, struct inode *inode,
251                       struct lov_stripe_md *lsm, int mode,
252                       struct lustre_handle *lockh);
253
254 /* namei.c */
255 int llu_iop_lookup(struct pnode *pnode,
256                    struct inode **inop,
257                    struct intent *intnt,
258                    const char *path);
259 void unhook_stale_inode(struct pnode *pno);
260 struct inode *llu_inode_from_lock(struct ldlm_lock *lock);
261 int llu_mdc_blocking_ast(struct ldlm_lock *lock,
262                          struct ldlm_lock_desc *desc,
263                          void *data, int flag);
264
265 /* dir.c */
266 ssize_t llu_iop_getdirentries(struct inode *ino, char *buf, size_t nbytes,
267                               _SYSIO_OFF_T *basep);
268
269 /* ext2 related */
270 #define EXT2_NAME_LEN (255)
271
272 struct ext2_dirent {
273         __u32   inode;
274         __u16   rec_len;
275         __u8    name_len;
276         __u8    file_type;
277         char    name[EXT2_NAME_LEN];
278 };
279
280 #define EXT2_DIR_PAD                    4
281 #define EXT2_DIR_ROUND                  (EXT2_DIR_PAD - 1)
282 #define EXT2_DIR_REC_LEN(name_len)      (((name_len) + 8 + EXT2_DIR_ROUND) & \
283                                          ~EXT2_DIR_ROUND)
284
285 static inline struct ext2_dirent *ext2_next_entry(struct ext2_dirent *p)
286 {
287         return (struct ext2_dirent*)((char*) p + le16_to_cpu(p->rec_len));
288 }
289
290 #endif