Whamcloud - gitweb
- changed name convention in cobd, thus all MD related methods have _md_ prefix like...
[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         obd_id                  ll_rootino;
50         int                     ll_flags;
51         struct list_head        ll_conn_chain;
52
53         struct obd_uuid         ll_mds_uuid;
54         struct obd_uuid         ll_mds_peer_uuid;
55         char                   *ll_instance; 
56 };
57
58 #define LL_SBI_NOLCK            0x1
59 #define LL_SBI_READAHEAD        0x2
60
61 #define LLI_F_HAVE_OST_SIZE_LOCK        0
62 #define LLI_F_HAVE_MDS_SIZE_LOCK        1
63 #define LLI_F_PREFER_EXTENDED_SIZE      2
64
65 struct llu_inode_info {
66         struct llu_sb_info     *lli_sbi;
67         struct lustre_id        lli_id;
68
69         struct lov_stripe_md   *lli_smd;
70         char                   *lli_symlink_name;
71         struct semaphore        lli_open_sem;
72         __u64                   lli_maxbytes;
73         unsigned long           lli_flags;
74
75         /* for libsysio */
76         struct file_identifier  lli_sysio_fid;
77
78         struct lookup_intent   *lli_it;
79
80         /* XXX workaround for libsysio readdir */
81         loff_t                  lli_dir_pos;
82
83         /* in libsysio we have no chance to store data in file, so place it
84          * here. since it's possible that an file was opened several times
85          * without close, we track an open_count here */
86         struct ll_file_data    *lli_file_data;
87         int                     lli_open_flags;
88         int                     lli_open_count;
89
90         /* stat FIXME not 64 bit clean */
91         dev_t                   lli_st_dev;
92         ino_t                   lli_st_ino;
93         mode_t                  lli_st_mode;
94         nlink_t                 lli_st_nlink;
95         uid_t                   lli_st_uid;
96         gid_t                   lli_st_gid;
97         dev_t                   lli_st_rdev;
98         loff_t                  lli_st_size;
99         unsigned int            lli_st_blksize;
100         unsigned long           lli_st_blocks;
101         time_t                  lli_st_atime;
102         time_t                  lli_st_mtime;
103         time_t                  lli_st_ctime;
104
105         /* not for stat, change it later */
106         int                     lli_st_flags;
107         unsigned long           lli_st_generation;
108 };
109
110 #define llu_fs2sbi(fs) (struct llu_sb_info *)(fs)->fs_private
111
112 static inline struct llu_inode_info *llu_i2info(struct inode *inode)
113 {
114         return (struct llu_inode_info *)inode->i_private;
115 }
116
117 static inline struct llu_sb_info *llu_i2sbi(struct inode *inode)
118 {
119         return llu_i2info(inode)->lli_sbi;
120 }
121
122 static inline struct obd_export *llu_i2dtexp(struct inode *inode)
123 {
124         return llu_i2info(inode)->lli_sbi->ll_dt_exp;
125 }
126
127 static inline struct obd_export *llu_i2mdexp(struct inode *inode)
128 {
129         return llu_i2info(inode)->lli_sbi->ll_md_exp;
130 }
131
132 static inline int llu_is_root_inode(struct inode *inode)
133 {
134         return (id_ino(&llu_i2info(inode)->lli_id) ==
135                 llu_i2info(inode)->lli_sbi->ll_rootino);
136 }
137
138 #define LL_SAVE_INTENT(inode, it)                                              \
139 do {                                                                           \
140         struct lookup_intent *temp;                                            \
141         LASSERT(llu_i2info(inode)->lli_it == NULL);                            \
142         OBD_ALLOC(temp, sizeof(*temp));                                        \
143         memcpy(temp, it, sizeof(*temp));                                       \
144         llu_i2info(inode)->lli_it = temp;                                      \
145         CDEBUG(D_DENTRY, "alloc intent %p to inode %p(ino %lu)\n",             \
146                         temp, inode, llu_i2info(inode)->lli_st_ino);           \
147 } while(0)
148
149
150 #define LL_GET_INTENT(inode, it)                                               \
151 do {                                                                           \
152         it = llu_i2info(inode)->lli_it;                                        \
153                                                                                \
154         LASSERT(it);                                                           \
155         llu_i2info(inode)->lli_it = NULL;                                      \
156         CDEBUG(D_DENTRY, "dettach intent %p from inode %p(ino %lu)\n",         \
157                         it, inode, llu_i2info(inode)->lli_st_ino);             \
158 } while(0)
159
160 /* interpet return codes from intent lookup */
161 #define LL_LOOKUP_POSITIVE 1
162 #define LL_LOOKUP_NEGATIVE 2
163
164 struct it_cb_data {
165         struct inode *icbd_parent;
166         struct pnode *icbd_child;
167         obd_id hash;
168 };
169
170 static inline void ll_inode2id(struct lustre_id *id,
171                                struct inode *inode)
172 {
173         *id = llu_i2info(inode)->lli_id;
174 }
175
176 typedef int (*intent_finish_cb)(struct ptlrpc_request *,
177                                 struct inode *parent, 
178                                 struct pnode *pnode, 
179                                 struct lookup_intent *, 
180                                 int offset, obd_id ino);
181                                 
182 int llu_intent_lock(struct inode *parent, struct pnode *pnode,
183                     struct lookup_intent *, int flags, 
184                     intent_finish_cb);
185
186 static inline __u64 ll_file_maxbytes(struct inode *inode)
187 {
188         return llu_i2info(inode)->lli_maxbytes;
189 }
190
191 struct mount_option_s
192 {
193         char *mdc_uuid;
194         char *osc_uuid;
195 };
196
197 #define IS_BAD_PTR(ptr) \
198         ((unsigned long)(ptr) == 0 || (unsigned long)(ptr) > -1000UL)
199
200 /* llite_lib.c */
201 void generate_random_uuid(unsigned char uuid_out[16]);
202
203 int liblustre_process_log(struct config_llog_instance *cfg, 
204                           int allow_recov);
205                           
206 int ll_parse_mount_target(const char *target, char **mdsnid,
207                           char **mdsname, char **profile);
208
209 extern char *g_zconf_mdsnid;
210 extern char *g_zconf_mdsname;
211 extern char *g_zconf_profile;
212 extern struct mount_option_s mount_option;
213
214 /* super.c */
215 void llu_update_inode(struct inode *inode, struct mds_body *body,
216                       struct lov_stripe_md *lmm);
217 void obdo_to_inode(struct inode *dst, struct obdo *src, obd_valid valid);
218 void obdo_from_inode(struct obdo *dst, struct inode *src, obd_valid valid);
219 int ll_it_open_error(int phase, struct lookup_intent *it);
220 struct inode *llu_iget(struct filesys *fs, struct lustre_md *md);
221 int llu_inode_getattr(struct inode *inode, struct lov_stripe_md *lsm);
222 int llu_setattr_raw(struct inode *inode, struct iattr *attr);
223
224 extern struct fssw_ops llu_fssw_ops;
225
226 /* file.c */
227 void llu_prepare_mdc_data(struct mdc_op_data *data, struct inode *i1,
228                           struct inode *i2, const char *name, int namelen,
229                           int mode);
230                           
231 int llu_create(struct inode *dir, struct pnode_base *pnode, int mode);
232 int llu_iop_open(struct pnode *pnode, int flags, mode_t mode);
233 int llu_mdc_close(struct obd_export *mdc_exp, struct inode *inode);
234 int llu_iop_close(struct inode *inode);
235 _SYSIO_OFF_T llu_iop_pos(struct inode *ino, _SYSIO_OFF_T off);
236 int llu_vmtruncate(struct inode * inode, loff_t offset);
237 void obdo_refresh_inode(struct inode *dst, struct obdo *src, obd_valid valid);
238 int llu_objects_destroy(struct ptlrpc_request *request, struct inode *dir);
239
240 /* rw.c */
241 int llu_iop_read(struct inode *ino, struct ioctx *ioctxp);
242 int llu_iop_write(struct inode *ino, struct ioctx *ioctxp);
243 int llu_iop_iodone(struct ioctx *ioctxp);
244 int llu_glimpse_size(struct inode *inode);
245 int llu_extent_lock(struct ll_file_data *fd, struct inode *inode,
246                     struct lov_stripe_md *lsm, int mode,
247                     ldlm_policy_data_t *policy, struct lustre_handle *lockh,
248                     int ast_flags);
249 int llu_extent_unlock(struct ll_file_data *fd, struct inode *inode,
250                       struct lov_stripe_md *lsm, int mode,
251                       struct lustre_handle *lockh);
252
253 /* namei.c */
254 int llu_iop_lookup(struct pnode *pnode,
255                    struct inode **inop,
256                    struct intent *intnt,
257                    const char *path);
258 void unhook_stale_inode(struct pnode *pno);
259 struct inode *llu_inode_from_lock(struct ldlm_lock *lock);
260 int llu_mdc_blocking_ast(struct ldlm_lock *lock,
261                          struct ldlm_lock_desc *desc,
262                          void *data, int flag);
263
264 /* dir.c */
265 ssize_t llu_iop_getdirentries(struct inode *ino, char *buf, size_t nbytes,
266                               _SYSIO_OFF_T *basep);
267
268 /* ext2 related */
269 #define EXT2_NAME_LEN (255)
270
271 struct ext2_dirent {
272         __u32   inode;
273         __u16   rec_len;
274         __u8    name_len;
275         __u8    file_type;
276         char    name[EXT2_NAME_LEN];
277 };
278
279 #define EXT2_DIR_PAD                    4
280 #define EXT2_DIR_ROUND                  (EXT2_DIR_PAD - 1)
281 #define EXT2_DIR_REC_LEN(name_len)      (((name_len) + 8 + EXT2_DIR_ROUND) & \
282                                          ~EXT2_DIR_ROUND)
283
284 static inline struct ext2_dirent *ext2_next_entry(struct ext2_dirent *p)
285 {
286         return (struct ext2_dirent*)((char*) p + le16_to_cpu(p->rec_len));
287 }
288
289 #endif