1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Lustre Light Super operations
6 * Copyright (c) 2002, 2003 Cluster File Systems, Inc.
8 * This file is part of Lustre, http://www.lustre.org.
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.
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.
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.
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>
33 #include <sys/types.h>
36 #define PAGE_CACHE_MAXBYTES ((__u64)(~0UL) << PAGE_CACHE_SHIFT)
39 struct obd_client_handle fd_mds_och;
45 struct obd_uuid ll_sb_uuid;
46 struct obd_export *ll_mdc_exp;
47 struct obd_export *ll_osc_exp;
50 struct list_head ll_conn_chain;
52 struct obd_uuid ll_mds_uuid;
53 struct obd_uuid ll_mds_peer_uuid;
57 #define LL_SBI_NOLCK 0x1
58 #define LL_SBI_READAHEAD 0x2
60 #define LLI_F_HAVE_OST_SIZE_LOCK 0
61 #define LLI_F_HAVE_MDS_SIZE_LOCK 1
62 #define LLI_F_PREFER_EXTENDED_SIZE 2
64 struct llu_inode_info {
65 struct llu_sb_info *lli_sbi;
66 struct ll_fid lli_fid;
68 struct lov_stripe_md *lli_smd;
69 char *lli_symlink_name;
70 struct semaphore lli_open_sem;
72 unsigned long lli_flags;
75 struct file_identifier lli_sysio_fid;
77 struct lookup_intent *lli_it;
79 /* XXX workaround for libsysio unlink */
81 /* XXX workaround for libsysio readdir */
84 /* in libsysio we have no chance to store data in file,
85 * so place it here. since it's possible that an file
86 * was opened several times without close, we track an
88 struct ll_file_data *lli_file_data;
91 /* stat FIXME not 64 bit clean */
100 unsigned int lli_st_blksize;
101 unsigned int lli_st_blocks;
106 /* not for stat, change it later */
108 unsigned long lli_st_generation;
111 #define LLU_SYSIO_COOKIE_SIZE(x) \
112 (sizeof(struct llu_sysio_cookie) + \
113 sizeof(struct ll_async_page) * (x) + \
114 sizeof(struct page) * (x))
116 struct llu_sysio_cookie {
117 struct obd_sync_io_container *lsc_osic;
118 struct inode *lsc_inode;
121 struct ll_async_page *lsc_llap;
122 struct page *lsc_pages;
126 /* XXX why uio.h haven't the definition? */
129 struct llu_sysio_callback_args
132 struct llu_sysio_cookie *cookies[MAX_IOVEC];
135 static inline struct llu_sb_info *llu_fs2sbi(struct filesys *fs)
137 return (struct llu_sb_info*)(fs->fs_private);
140 static inline struct llu_inode_info *llu_i2info(struct inode *inode)
142 return (struct llu_inode_info*)(inode->i_private);
145 static inline struct llu_sb_info *llu_i2sbi(struct inode *inode)
147 return llu_i2info(inode)->lli_sbi;
150 static inline struct obd_export *llu_i2obdexp(struct inode *inode)
152 return llu_i2info(inode)->lli_sbi->ll_osc_exp;
155 static inline struct obd_export *llu_i2mdcexp(struct inode *inode)
157 return llu_i2info(inode)->lli_sbi->ll_mdc_exp;
160 static inline int llu_is_root_inode(struct inode *inode)
162 return (llu_i2info(inode)->lli_fid.id ==
163 llu_i2info(inode)->lli_sbi->ll_rootino);
166 #define LL_SAVE_INTENT(inode, it) \
168 struct lookup_intent *temp; \
169 LASSERT(llu_i2info(inode)->lli_it == NULL); \
170 OBD_ALLOC(temp, sizeof(*temp)); \
171 memcpy(temp, it, sizeof(*temp)); \
172 llu_i2info(inode)->lli_it = temp; \
173 CDEBUG(D_DENTRY, "alloc intent %p to inode %p(ino %lu)\n", \
174 temp, inode, llu_i2info(inode)->lli_st_ino); \
178 #define LL_GET_INTENT(inode, it) \
180 it = llu_i2info(inode)->lli_it; \
183 llu_i2info(inode)->lli_it = NULL; \
184 CDEBUG(D_DENTRY, "dettach intent %p from inode %p(ino %lu)\n", \
185 it, inode, llu_i2info(inode)->lli_st_ino); \
188 /* interpet return codes from intent lookup */
189 #define LL_LOOKUP_POSITIVE 1
190 #define LL_LOOKUP_NEGATIVE 2
192 static inline void ll_inode2fid(struct ll_fid *fid, struct inode *inode)
194 *fid = llu_i2info(inode)->lli_fid;
198 struct inode *icbd_parent;
199 struct pnode *icbd_child;
203 static inline void ll_i2uctxt(struct ll_uctxt *ctxt, struct inode *i1,
206 struct llu_inode_info *lli1 = llu_i2info(i1);
207 struct llu_inode_info *lli2;
212 if (in_group_p(lli1->lli_st_gid))
213 ctxt->gid1 = lli1->lli_st_gid;
218 lli2 = llu_i2info(i2);
219 if (in_group_p(lli2->lli_st_gid))
220 ctxt->gid2 = lli2->lli_st_gid;
228 typedef int (*intent_finish_cb)(struct ptlrpc_request *,
229 struct inode *parent, struct pnode *pnode,
230 struct lookup_intent *, int offset, obd_id ino);
231 int llu_intent_lock(struct inode *parent, struct pnode *pnode,
232 struct lookup_intent *, int flags, intent_finish_cb);
235 static inline int ll_permission(struct inode *inode, int flag, void * unused)
240 static inline __u64 ll_file_maxbytes(struct inode *inode)
242 return llu_i2info(inode)->lli_maxbytes;
245 struct mount_option_s
252 void generate_random_uuid(unsigned char uuid_out[16]);
253 int liblustre_process_log(struct config_llog_instance *cfg, int allow_recov);
254 int ll_parse_mount_target(const char *target, char **mdsnid,
255 char **mdsname, char **profile);
258 extern char *g_zconf_mdsnid;
259 extern char *g_zconf_mdsname;
260 extern char *g_zconf_profile;
261 extern struct mount_option_s mount_option;
264 void llu_update_inode(struct inode *inode, struct mds_body *body,
265 struct lov_stripe_md *lmm);
266 void obdo_to_inode(struct inode *dst, struct obdo *src, obd_flag valid);
267 void obdo_from_inode(struct obdo *dst, struct inode *src, obd_flag valid);
268 int ll_it_open_error(int phase, struct lookup_intent *it);
269 struct inode *llu_iget(struct filesys *fs, struct lustre_md *md);
270 int llu_inode_getattr(struct inode *inode, struct lov_stripe_md *lsm);
272 extern struct fssw_ops llu_fssw_ops;
275 void llu_prepare_mdc_op_data(struct mdc_op_data *data,
281 int llu_create(struct inode *dir, struct pnode_base *pnode, int mode);
282 int llu_iop_open(struct pnode *pnode, int flags, mode_t mode);
283 int llu_mdc_close(struct obd_export *mdc_exp, struct inode *inode);
284 int llu_iop_close(struct inode *inode);
285 int llu_iop_ipreadv(struct inode *ino, struct ioctx *ioctxp);
286 int llu_iop_ipwritev(struct inode *ino, struct ioctx *ioctxp);
287 int llu_vmtruncate(struct inode * inode, loff_t offset);
288 void obdo_refresh_inode(struct inode *dst, struct obdo *src, obd_flag valid);
289 int llu_objects_destroy(struct ptlrpc_request *request, struct inode *dir);
292 int llu_iop_iodone(struct ioctx *ioctxp __IS_UNUSED);
293 struct llu_sysio_callback_args*
294 llu_file_write(struct inode *inode, const struct iovec *iovec,
295 size_t iovlen, loff_t pos);
296 struct llu_sysio_callback_args*
297 llu_file_read(struct inode *inode, const struct iovec *iovec,
298 size_t iovlen, loff_t pos);
299 int llu_extent_lock_no_validate(struct ll_file_data *fd,
301 struct lov_stripe_md *lsm,
303 struct ldlm_extent *extent,
304 struct lustre_handle *lockh,
306 int llu_extent_lock(struct ll_file_data *fd, struct inode *inode,
307 struct lov_stripe_md *lsm,
308 int mode, struct ldlm_extent *extent,
309 struct lustre_handle *lockh);
310 int llu_extent_unlock(struct ll_file_data *fd, struct inode *inode,
311 struct lov_stripe_md *lsm, int mode,
312 struct lustre_handle *lockh);
315 int llu_iop_lookup(struct pnode *pnode,
317 struct intent *intnt,
319 void unhook_stale_inode(struct pnode *pno);
320 struct inode *llu_inode_from_lock(struct ldlm_lock *lock);
321 int llu_mdc_blocking_ast(struct ldlm_lock *lock,
322 struct ldlm_lock_desc *desc,
323 void *data, int flag);
326 ssize_t llu_iop_getdirentries(struct inode *ino, char *buf, size_t nbytes,
327 _SYSIO_OFF_T *basep);
330 #define EXT2_NAME_LEN (255)
337 char name[EXT2_NAME_LEN];
340 #define EXT2_DIR_PAD 4
341 #define EXT2_DIR_ROUND (EXT2_DIR_PAD - 1)
342 #define EXT2_DIR_REC_LEN(name_len) (((name_len) + 8 + EXT2_DIR_ROUND) & \
345 static inline struct ext2_dirent *ext2_next_entry(struct ext2_dirent *p)
347 return (struct ext2_dirent*)((char*) p + le16_to_cpu(p->rec_len));