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-2004 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;
41 struct lustre_handle fd_cwlockh;
47 struct obd_uuid ll_sb_uuid;
48 struct obd_export *ll_lmv_exp;
49 struct obd_export *ll_lov_exp;
52 struct list_head ll_conn_chain;
54 struct obd_uuid ll_mds_uuid;
55 struct obd_uuid ll_mds_peer_uuid;
59 #define LL_SBI_NOLCK 0x1
60 #define LL_SBI_READAHEAD 0x2
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
66 struct llu_inode_info {
67 struct llu_sb_info *lli_sbi;
68 struct lustre_id lli_id;
70 struct lov_stripe_md *lli_smd;
71 char *lli_symlink_name;
72 struct semaphore lli_open_sem;
74 unsigned long lli_flags;
77 struct file_identifier lli_sysio_fid;
79 struct lookup_intent *lli_it;
81 /* XXX workaround for libsysio readdir */
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;
91 /* stat FIXME not 64 bit clean */
100 unsigned int lli_st_blksize;
101 unsigned long lli_st_blocks;
106 /* not for stat, change it later */
108 unsigned long lli_st_generation;
111 static inline struct llu_sb_info *llu_fs2sbi(struct filesys *fs)
113 return (struct llu_sb_info*)(fs->fs_private);
116 static inline struct llu_inode_info *llu_i2info(struct inode *inode)
118 return (struct llu_inode_info*)(inode->i_private);
121 static inline struct llu_sb_info *llu_i2sbi(struct inode *inode)
123 return llu_i2info(inode)->lli_sbi;
126 static inline struct obd_export *llu_i2obdexp(struct inode *inode)
128 return llu_i2info(inode)->lli_sbi->ll_lov_exp;
131 static inline struct obd_export *llu_i2mdcexp(struct inode *inode)
133 return llu_i2info(inode)->lli_sbi->ll_lmv_exp;
136 static inline int llu_is_root_inode(struct inode *inode)
138 return (llu_i2info(inode)->lli_id.li_stc.u.e3s.l3s_ino ==
139 llu_i2info(inode)->lli_sbi->ll_rootino);
142 #define LL_SAVE_INTENT(inode, it) \
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); \
154 #define LL_GET_INTENT(inode, it) \
156 it = llu_i2info(inode)->lli_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); \
164 /* interpet return codes from intent lookup */
165 #define LL_LOOKUP_POSITIVE 1
166 #define LL_LOOKUP_NEGATIVE 2
169 struct inode *icbd_parent;
170 struct pnode *icbd_child;
174 static inline void ll_inode2id(struct lustre_id *id,
177 *id = llu_i2info(inode)->lli_id;
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);
186 static inline __u64 ll_file_maxbytes(struct inode *inode)
188 return llu_i2info(inode)->lli_maxbytes;
191 struct mount_option_s
197 #define IS_BAD_PTR(ptr) \
198 ((unsigned long)(ptr) == 0 || (unsigned long)(ptr) > -1000UL)
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);
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;
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);
221 extern struct fssw_ops llu_fssw_ops;
224 void llu_prepare_mdc_data(struct mdc_op_data *data, struct inode *i1,
225 struct inode *i2, const char *name, int namelen,
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);
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,
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);
251 int llu_iop_lookup(struct pnode *pnode,
253 struct intent *intnt,
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);
262 ssize_t llu_iop_getdirentries(struct inode *ino, char *buf, size_t nbytes,
263 _SYSIO_OFF_T *basep);
266 #define EXT2_NAME_LEN (255)
273 char name[EXT2_NAME_LEN];
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) & \
281 static inline struct ext2_dirent *ext2_next_entry(struct ext2_dirent *p)
283 return (struct ext2_dirent*)((char*) p + le16_to_cpu(p->rec_len));