1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
40 #include <liblustre.h>
42 #include <obd_class.h>
43 #include <lustre_mdc.h>
44 #include <lustre_lite.h>
45 #include <lustre_ver.h>
47 #include <sys/types.h>
50 /* This should not be "optimized" use ~0ULL because page->index is a long and
51 * 32-bit systems are therefore limited to 16TB in a mapping */
52 #define PAGE_CACHE_MAXBYTES ((__u64)(~0UL) << CFS_PAGE_SHIFT)
55 struct obd_client_handle fd_mds_och;
57 struct lustre_handle fd_cwlockh;
62 struct obd_uuid ll_sb_uuid;
63 struct obd_export *ll_md_exp;
64 struct obd_export *ll_dt_exp;
65 struct lu_fid ll_root_fid;
67 struct lustre_client_ocd ll_lco;
68 struct list_head ll_conn_chain;
70 struct obd_uuid ll_mds_uuid;
71 struct obd_uuid ll_mds_peer_uuid;
75 #define LL_SBI_NOLCK 0x1
78 /* MDS has an authority for the Size-on-MDS attributes. */
79 LLIF_MDS_SIZE_LOCK = (1 << 0),
82 struct llu_inode_info {
83 struct llu_sb_info *lli_sbi;
84 struct lu_fid lli_fid;
86 struct lov_stripe_md *lli_smd;
87 char *lli_symlink_name;
88 struct semaphore lli_open_sem;
90 unsigned long lli_flags;
94 struct file_identifier lli_sysio_fid;
96 struct lookup_intent *lli_it;
98 /* XXX workaround for libsysio readdir */
101 /* in libsysio we have no chance to store data in file,
102 * so place it here. since it's possible that an file
103 * was opened several times without close, we track an
105 struct ll_file_data *lli_file_data;
109 /* not for stat, change it later */
111 unsigned long lli_st_generation;
114 static inline struct llu_sb_info *llu_fs2sbi(struct filesys *fs)
116 return (struct llu_sb_info*)(fs->fs_private);
119 static inline struct llu_inode_info *llu_i2info(struct inode *inode)
121 return (struct llu_inode_info*)(inode->i_private);
124 static inline struct intnl_stat *llu_i2stat(struct inode *inode)
126 return &inode->i_stbuf;
129 static inline struct llu_sb_info *llu_i2sbi(struct inode *inode)
131 return llu_i2info(inode)->lli_sbi;
134 static inline struct obd_export *llu_i2obdexp(struct inode *inode)
136 return llu_i2info(inode)->lli_sbi->ll_dt_exp;
139 static inline struct obd_export *llu_i2mdexp(struct inode *inode)
141 return llu_i2info(inode)->lli_sbi->ll_md_exp;
144 static inline int llu_is_root_inode(struct inode *inode)
146 return (fid_seq(&llu_i2info(inode)->lli_fid) ==
147 fid_seq(&llu_i2info(inode)->lli_sbi->ll_root_fid) &&
148 fid_oid(&llu_i2info(inode)->lli_fid) ==
149 fid_oid(&llu_i2info(inode)->lli_sbi->ll_root_fid));
152 #define LL_SAVE_INTENT(inode, it) \
154 struct lookup_intent *temp; \
155 LASSERT(llu_i2info(inode)->lli_it == NULL); \
156 OBD_ALLOC(temp, sizeof(*temp)); \
157 memcpy(temp, it, sizeof(*temp)); \
158 llu_i2info(inode)->lli_it = temp; \
159 CDEBUG(D_DENTRY, "alloc intent %p to inode %p(ino %llu)\n", \
160 temp, inode, (long long)llu_i2stat(inode)->st_ino); \
164 #define LL_GET_INTENT(inode, it) \
166 it = llu_i2info(inode)->lli_it; \
169 llu_i2info(inode)->lli_it = NULL; \
170 CDEBUG(D_DENTRY, "dettach intent %p from inode %p(ino %llu)\n", \
171 it, inode, (long long)llu_i2stat(inode)->st_ino); \
174 /* interpet return codes from intent lookup */
175 #define LL_LOOKUP_POSITIVE 1
176 #define LL_LOOKUP_NEGATIVE 2
178 static inline struct lu_fid *ll_inode2fid(struct inode *inode)
180 LASSERT(inode != NULL);
181 return &llu_i2info(inode)->lli_fid;
185 struct inode *icbd_parent;
186 struct pnode *icbd_child;
190 void ll_i2gids(__u32 *suppgids, struct inode *i1,struct inode *i2);
192 typedef int (*intent_finish_cb)(struct ptlrpc_request *,
193 struct inode *parent, struct pnode *pnode,
194 struct lookup_intent *, int offset, obd_id ino);
195 int llu_intent_lock(struct inode *parent, struct pnode *pnode,
196 struct lookup_intent *, int flags, intent_finish_cb);
198 static inline __u64 ll_file_maxbytes(struct inode *inode)
200 return llu_i2info(inode)->lli_maxbytes;
203 struct mount_option_s
209 #define IS_BAD_PTR(ptr) \
210 ((unsigned long)(ptr) == 0 || (unsigned long)(ptr) > -1000UL)
213 int liblustre_process_log(struct config_llog_instance *cfg, char *mgsnid,
214 char *profile, int allow_recov);
215 int ll_parse_mount_target(const char *target, char **mgsnid,
218 extern struct mount_option_s mount_option;
221 void llu_update_inode(struct inode *inode, struct mdt_body *body,
222 struct lov_stripe_md *lmm);
223 void obdo_to_inode(struct inode *dst, struct obdo *src, obd_flag valid);
224 void obdo_from_inode(struct obdo *dst, struct inode *src, obd_flag valid);
225 int ll_it_open_error(int phase, struct lookup_intent *it);
226 struct inode *llu_iget(struct filesys *fs, struct lustre_md *md);
227 int llu_inode_getattr(struct inode *inode, struct obdo *obdo);
228 int llu_md_setattr(struct inode *inode, struct md_op_data *op_data,
229 struct md_open_data **mod);
230 int llu_setattr_raw(struct inode *inode, struct iattr *attr);
232 extern struct fssw_ops llu_fssw_ops;
235 void llu_prep_md_op_data(struct md_op_data *op_data, struct inode *i1,
236 struct inode *i2, const char *name, int namelen,
237 int mode, __u32 opc);
238 void llu_finish_md_op_data(struct md_op_data *op_data);
239 int llu_create(struct inode *dir, struct pnode_base *pnode, int mode);
240 int llu_local_open(struct llu_inode_info *lli, struct lookup_intent *it);
241 int llu_iop_open(struct pnode *pnode, int flags, mode_t mode);
242 int llu_md_close(struct obd_export *md_exp, struct inode *inode);
243 int llu_file_release(struct inode *inode);
244 int llu_sizeonmds_update(struct inode *inode, struct md_open_data *mod,
245 struct lustre_handle *fh, __u64 ioepoch);
246 int llu_iop_close(struct inode *inode);
247 _SYSIO_OFF_T llu_iop_pos(struct inode *ino, _SYSIO_OFF_T off);
248 int llu_vmtruncate(struct inode * inode, loff_t offset, obd_flag obd_flags);
249 void obdo_refresh_inode(struct inode *dst, struct obdo *src, obd_flag valid);
250 int llu_objects_destroy(struct ptlrpc_request *request, struct inode *dir);
253 int llu_iop_read(struct inode *ino, struct ioctx *ioctxp);
254 int llu_iop_write(struct inode *ino, struct ioctx *ioctxp);
255 int llu_iop_iodone(struct ioctx *ioctxp);
256 int llu_local_size(struct inode *inode);
257 int llu_glimpse_size(struct inode *inode);
258 int llu_extent_lock_cancel_cb(struct ldlm_lock *lock,
259 struct ldlm_lock_desc *new, void *data,
261 int llu_extent_lock(struct ll_file_data *fd, struct inode *inode,
262 struct lov_stripe_md *lsm, int mode,
263 ldlm_policy_data_t *policy, struct lustre_handle *lockh,
265 int llu_extent_unlock(struct ll_file_data *fd, struct inode *inode,
266 struct lov_stripe_md *lsm, int mode,
267 struct lustre_handle *lockh);
270 int llu_iop_lookup(struct pnode *pnode,
272 struct intent *intnt,
274 void unhook_stale_inode(struct pnode *pno);
275 struct inode *llu_inode_from_lock(struct ldlm_lock *lock);
276 int llu_md_blocking_ast(struct ldlm_lock *lock,
277 struct ldlm_lock_desc *desc,
278 void *data, int flag);
281 ssize_t llu_iop_filldirentries(struct inode *ino, _SYSIO_OFF_T *basep,
282 char *buf, size_t nbytes);
284 /* liblustre/llite_fid.c*/
285 unsigned long llu_fid_build_ino(struct llu_sb_info *sbi,
289 #define EXT2_NAME_LEN (255)
296 char name[EXT2_NAME_LEN];
299 #define EXT2_DIR_PAD 4
300 #define EXT2_DIR_ROUND (EXT2_DIR_PAD - 1)
301 #define EXT2_DIR_REC_LEN(name_len) (((name_len) + 8 + EXT2_DIR_ROUND) & \
304 static inline struct ext2_dirent *ext2_next_entry(struct ext2_dirent *p)
306 return (struct ext2_dirent*)((char*) p + le16_to_cpu(p->rec_len));
309 static inline void inode_init_lvb(struct inode *inode, struct ost_lvb *lvb)
311 struct intnl_stat *st = llu_i2stat(inode);
312 lvb->lvb_size = st->st_size;
313 lvb->lvb_blocks = st->st_blocks;
314 lvb->lvb_mtime = st->st_mtime;
315 lvb->lvb_atime = st->st_atime;
316 lvb->lvb_ctime = st->st_ctime;