Whamcloud - gitweb
b80562236f7e5408bc9071e2e3c192731e87d2c6
[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 {
47         struct obd_uuid         ll_sb_uuid;
48         struct obd_export      *ll_lmv_exp;
49         struct obd_export      *ll_lov_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 static inline struct llu_sb_info *llu_fs2sbi(struct filesys *fs)
112 {
113         return (struct llu_sb_info*)(fs->fs_private);
114 }
115
116 static inline struct llu_inode_info *llu_i2info(struct inode *inode)
117 {
118         return (struct llu_inode_info*)(inode->i_private);
119 }
120
121 static inline struct llu_sb_info *llu_i2sbi(struct inode *inode)
122 {
123         return llu_i2info(inode)->lli_sbi;
124 }
125
126 static inline struct obd_export *llu_i2obdexp(struct inode *inode)
127 {
128         return llu_i2info(inode)->lli_sbi->ll_lov_exp;
129 }
130
131 static inline struct obd_export *llu_i2mdcexp(struct inode *inode)
132 {
133         return llu_i2info(inode)->lli_sbi->ll_lmv_exp;
134 }
135
136 static inline int llu_is_root_inode(struct inode *inode)
137 {
138         return (llu_i2info(inode)->lli_id.li_stc.u.e3s.l3s_ino ==
139                 llu_i2info(inode)->lli_sbi->ll_rootino);
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 struct it_cb_data {
169         struct inode *icbd_parent;
170         struct pnode *icbd_child;
171         obd_id hash;
172 };
173
174 static inline void ll_inode2id(struct lustre_id *id,
175                                struct inode *inode)
176 {
177         *id = llu_i2info(inode)->lli_id;
178 }
179
180 typedef int (*intent_finish_cb)(struct ptlrpc_request *,
181                                 struct inode *parent, struct pnode *pnode, 
182                                 struct lookup_intent *, int offset, obd_id ino);
183 int llu_intent_lock(struct inode *parent, struct pnode *pnode,
184                     struct lookup_intent *, int flags, 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 int liblustre_process_log(struct config_llog_instance *cfg, int allow_recov);
203 int ll_parse_mount_target(const char *target, char **mdsnid,
204                           char **mdsname, char **profile);
205
206 extern char   *g_zconf_mdsnid;
207 extern char   *g_zconf_mdsname;
208 extern char   *g_zconf_profile;
209 extern struct mount_option_s mount_option;
210
211 /* super.c */
212 void llu_update_inode(struct inode *inode, struct mds_body *body,
213                       struct lov_stripe_md *lmm);
214 void obdo_to_inode(struct inode *dst, struct obdo *src, obd_valid valid);
215 void obdo_from_inode(struct obdo *dst, struct inode *src, obd_valid valid);
216 int ll_it_open_error(int phase, struct lookup_intent *it);
217 struct inode *llu_iget(struct filesys *fs, struct lustre_md *md);
218 int llu_inode_getattr(struct inode *inode, struct lov_stripe_md *lsm);
219 int llu_setattr_raw(struct inode *inode, struct iattr *attr);
220
221 extern struct fssw_ops llu_fssw_ops;
222
223 /* file.c */
224 void llu_prepare_mdc_data(struct mdc_op_data *data, struct inode *i1,
225                           struct inode *i2, const char *name, int namelen,
226                           int mode);
227                           
228 int llu_create(struct inode *dir, struct pnode_base *pnode, int mode);
229 int llu_iop_open(struct pnode *pnode, int flags, mode_t mode);
230 int llu_mdc_close(struct obd_export *mdc_exp, struct inode *inode);
231 int llu_iop_close(struct inode *inode);
232 _SYSIO_OFF_T llu_iop_pos(struct inode *ino, _SYSIO_OFF_T off);
233 int llu_vmtruncate(struct inode * inode, loff_t offset);
234 void obdo_refresh_inode(struct inode *dst, struct obdo *src, obd_valid valid);
235 int llu_objects_destroy(struct ptlrpc_request *request, struct inode *dir);
236
237 /* rw.c */
238 int llu_iop_read(struct inode *ino, struct ioctx *ioctxp);
239 int llu_iop_write(struct inode *ino, struct ioctx *ioctxp);
240 int llu_iop_iodone(struct ioctx *ioctxp);
241 int llu_glimpse_size(struct inode *inode);
242 int llu_extent_lock(struct ll_file_data *fd, struct inode *inode,
243                     struct lov_stripe_md *lsm, int mode,
244                     ldlm_policy_data_t *policy, struct lustre_handle *lockh,
245                     int ast_flags);
246 int llu_extent_unlock(struct ll_file_data *fd, struct inode *inode,
247                       struct lov_stripe_md *lsm, int mode,
248                       struct lustre_handle *lockh);
249
250 /* namei.c */
251 int llu_iop_lookup(struct pnode *pnode,
252                    struct inode **inop,
253                    struct intent *intnt,
254                    const char *path);
255 void unhook_stale_inode(struct pnode *pno);
256 struct inode *llu_inode_from_lock(struct ldlm_lock *lock);
257 int llu_mdc_blocking_ast(struct ldlm_lock *lock,
258                          struct ldlm_lock_desc *desc,
259                          void *data, int flag);
260
261 /* dir.c */
262 ssize_t llu_iop_getdirentries(struct inode *ino, char *buf, size_t nbytes,
263                               _SYSIO_OFF_T *basep);
264
265 /* ext2 related */
266 #define EXT2_NAME_LEN (255)
267
268 struct ext2_dirent {
269         __u32   inode;
270         __u16   rec_len;
271         __u8    name_len;
272         __u8    file_type;
273         char    name[EXT2_NAME_LEN];
274 };
275
276 #define EXT2_DIR_PAD                    4
277 #define EXT2_DIR_ROUND                  (EXT2_DIR_PAD - 1)
278 #define EXT2_DIR_REC_LEN(name_len)      (((name_len) + 8 + EXT2_DIR_ROUND) & \
279                                          ~EXT2_DIR_ROUND)
280
281 static inline struct ext2_dirent *ext2_next_entry(struct ext2_dirent *p)
282 {
283         return (struct ext2_dirent*)((char*) p + le16_to_cpu(p->rec_len));
284 }
285
286 #endif