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;
49 struct obd_export *ll_gt_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 #define llu_fs2sbi(fs) (struct llu_sb_info *)(fs)->fs_private
113 static inline struct llu_inode_info *llu_i2info(struct inode *inode)
115 return (struct llu_inode_info *)inode->i_private;
118 static inline struct llu_sb_info *llu_i2sbi(struct inode *inode)
120 return llu_i2info(inode)->lli_sbi;
123 static inline struct obd_export *llu_i2dtexp(struct inode *inode)
125 return llu_i2info(inode)->lli_sbi->ll_dt_exp;
128 static inline struct obd_export *llu_i2mdexp(struct inode *inode)
130 return llu_i2info(inode)->lli_sbi->ll_md_exp;
133 static inline int llu_is_root_inode(struct inode *inode)
135 return (id_ino(&llu_i2info(inode)->lli_id) ==
136 llu_i2info(inode)->lli_sbi->ll_rootino);
139 #define LL_SAVE_INTENT(inode, it) \
141 struct lookup_intent *temp; \
142 LASSERT(llu_i2info(inode)->lli_it == NULL); \
143 OBD_ALLOC(temp, sizeof(*temp)); \
144 memcpy(temp, it, sizeof(*temp)); \
145 llu_i2info(inode)->lli_it = temp; \
146 CDEBUG(D_DENTRY, "alloc intent %p to inode %p(ino %lu)\n", \
147 temp, inode, llu_i2info(inode)->lli_st_ino); \
151 #define LL_GET_INTENT(inode, it) \
153 it = llu_i2info(inode)->lli_it; \
156 llu_i2info(inode)->lli_it = NULL; \
157 CDEBUG(D_DENTRY, "dettach intent %p from inode %p(ino %lu)\n", \
158 it, inode, llu_i2info(inode)->lli_st_ino); \
161 /* interpet return codes from intent lookup */
162 #define LL_LOOKUP_POSITIVE 1
163 #define LL_LOOKUP_NEGATIVE 2
166 struct inode *icbd_parent;
167 struct pnode *icbd_child;
171 static inline void ll_inode2id(struct lustre_id *id,
174 *id = llu_i2info(inode)->lli_id;
177 typedef int (*intent_finish_cb)(struct ptlrpc_request *,
178 struct inode *parent,
180 struct lookup_intent *,
181 int offset, obd_id ino);
183 int llu_intent_lock(struct inode *parent, struct pnode *pnode,
184 struct lookup_intent *, int flags,
187 static inline __u64 ll_file_maxbytes(struct inode *inode)
189 return llu_i2info(inode)->lli_maxbytes;
192 struct mount_option_s
198 #define IS_BAD_PTR(ptr) \
199 ((unsigned long)(ptr) == 0 || (unsigned long)(ptr) > -1000UL)
202 void generate_random_uuid(unsigned char uuid_out[16]);
204 int liblustre_process_log(struct config_llog_instance *cfg,
207 int ll_parse_mount_target(const char *target, char **mdsnid,
208 char **mdsname, char **profile);
210 extern char *g_zconf_mdsnid;
211 extern char *g_zconf_mdsname;
212 extern char *g_zconf_profile;
213 extern struct mount_option_s mount_option;
216 void llu_update_inode(struct inode *inode, struct mds_body *body,
217 struct lov_stripe_md *lmm);
218 void obdo_to_inode(struct inode *dst, struct obdo *src, obd_valid valid);
219 void obdo_from_inode(struct obdo *dst, struct inode *src, obd_valid valid);
220 int ll_it_open_error(int phase, struct lookup_intent *it);
221 struct inode *llu_iget(struct filesys *fs, struct lustre_md *md);
222 int llu_inode_getattr(struct inode *inode, struct lov_stripe_md *lsm);
223 int llu_setattr_raw(struct inode *inode, struct iattr *attr);
225 extern struct fssw_ops llu_fssw_ops;
228 void llu_prepare_mdc_data(struct mdc_op_data *data, struct inode *i1,
229 struct inode *i2, const char *name, int namelen,
232 int llu_create(struct inode *dir, struct pnode_base *pnode, int mode);
233 int llu_iop_open(struct pnode *pnode, int flags, mode_t mode);
234 int llu_mdc_close(struct obd_export *mdc_exp, struct inode *inode);
235 int llu_iop_close(struct inode *inode);
236 _SYSIO_OFF_T llu_iop_pos(struct inode *ino, _SYSIO_OFF_T off);
237 int llu_vmtruncate(struct inode * inode, loff_t offset);
238 void obdo_refresh_inode(struct inode *dst, struct obdo *src, obd_valid valid);
239 int llu_objects_destroy(struct ptlrpc_request *request, struct inode *dir);
242 int llu_iop_read(struct inode *ino, struct ioctx *ioctxp);
243 int llu_iop_write(struct inode *ino, struct ioctx *ioctxp);
244 int llu_iop_iodone(struct ioctx *ioctxp);
245 int llu_glimpse_size(struct inode *inode);
246 int llu_extent_lock(struct ll_file_data *fd, struct inode *inode,
247 struct lov_stripe_md *lsm, int mode,
248 ldlm_policy_data_t *policy, struct lustre_handle *lockh,
250 int llu_extent_unlock(struct ll_file_data *fd, struct inode *inode,
251 struct lov_stripe_md *lsm, int mode,
252 struct lustre_handle *lockh);
255 int llu_iop_lookup(struct pnode *pnode,
257 struct intent *intnt,
259 void unhook_stale_inode(struct pnode *pno);
260 struct inode *llu_inode_from_lock(struct ldlm_lock *lock);
261 int llu_mdc_blocking_ast(struct ldlm_lock *lock,
262 struct ldlm_lock_desc *desc,
263 void *data, int flag);
266 ssize_t llu_iop_getdirentries(struct inode *ino, char *buf, size_t nbytes,
267 _SYSIO_OFF_T *basep);
270 #define EXT2_NAME_LEN (255)
277 char name[EXT2_NAME_LEN];
280 #define EXT2_DIR_PAD 4
281 #define EXT2_DIR_ROUND (EXT2_DIR_PAD - 1)
282 #define EXT2_DIR_REC_LEN(name_len) (((name_len) + 8 + EXT2_DIR_ROUND) & \
285 static inline struct ext2_dirent *ext2_next_entry(struct ext2_dirent *p)
287 return (struct ext2_dirent*)((char*) p + le16_to_cpu(p->rec_len));