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;
46 struct obd_uuid ll_sb_uuid;
47 struct obd_export *ll_md_exp;
48 struct obd_export *ll_dt_exp;
51 struct list_head ll_conn_chain;
53 struct obd_uuid ll_mds_uuid;
54 struct obd_uuid ll_mds_peer_uuid;
58 #define LL_SBI_NOLCK 0x1
59 #define LL_SBI_READAHEAD 0x2
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
65 struct llu_inode_info {
66 struct llu_sb_info *lli_sbi;
67 struct lustre_id lli_id;
69 struct lov_stripe_md *lli_smd;
70 char *lli_symlink_name;
71 struct semaphore lli_open_sem;
73 unsigned long lli_flags;
76 struct file_identifier lli_sysio_fid;
78 struct lookup_intent *lli_it;
80 /* XXX workaround for libsysio readdir */
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;
90 /* stat FIXME not 64 bit clean */
99 unsigned int lli_st_blksize;
100 unsigned long lli_st_blocks;
105 /* not for stat, change it later */
107 unsigned long lli_st_generation;
110 #define llu_fs2sbi(fs) (struct llu_sb_info *)(fs)->fs_private
112 static inline struct llu_inode_info *llu_i2info(struct inode *inode)
114 return (struct llu_inode_info *)inode->i_private;
117 static inline struct llu_sb_info *llu_i2sbi(struct inode *inode)
119 return llu_i2info(inode)->lli_sbi;
122 static inline struct obd_export *llu_i2dtexp(struct inode *inode)
124 return llu_i2info(inode)->lli_sbi->ll_dt_exp;
127 static inline struct obd_export *llu_i2mdexp(struct inode *inode)
129 return llu_i2info(inode)->lli_sbi->ll_md_exp;
132 static inline int llu_is_root_inode(struct inode *inode)
134 return (id_ino(&llu_i2info(inode)->lli_id) ==
135 llu_i2info(inode)->lli_sbi->ll_rootino);
138 #define LL_SAVE_INTENT(inode, it) \
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); \
150 #define LL_GET_INTENT(inode, it) \
152 it = llu_i2info(inode)->lli_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); \
160 /* interpet return codes from intent lookup */
161 #define LL_LOOKUP_POSITIVE 1
162 #define LL_LOOKUP_NEGATIVE 2
165 struct inode *icbd_parent;
166 struct pnode *icbd_child;
170 static inline void ll_inode2id(struct lustre_id *id,
173 *id = llu_i2info(inode)->lli_id;
176 typedef int (*intent_finish_cb)(struct ptlrpc_request *,
177 struct inode *parent,
179 struct lookup_intent *,
180 int offset, obd_id ino);
182 int llu_intent_lock(struct inode *parent, struct pnode *pnode,
183 struct lookup_intent *, int flags,
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]);
203 int liblustre_process_log(struct config_llog_instance *cfg,
206 int ll_parse_mount_target(const char *target, char **mdsnid,
207 char **mdsname, char **profile);
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;
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);
224 extern struct fssw_ops llu_fssw_ops;
227 void llu_prepare_mdc_data(struct mdc_op_data *data, struct inode *i1,
228 struct inode *i2, const char *name, int namelen,
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);
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,
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);
254 int llu_iop_lookup(struct pnode *pnode,
256 struct intent *intnt,
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);
265 ssize_t llu_iop_getdirentries(struct inode *ino, char *buf, size_t nbytes,
266 _SYSIO_OFF_T *basep);
269 #define EXT2_NAME_LEN (255)
276 char name[EXT2_NAME_LEN];
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) & \
284 static inline struct ext2_dirent *ext2_next_entry(struct ext2_dirent *p)
286 return (struct ext2_dirent*)((char*) p + le16_to_cpu(p->rec_len));