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_mds.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;
63 struct obd_uuid ll_sb_uuid;
64 struct obd_export *ll_mdc_exp;
65 struct obd_export *ll_osc_exp;
68 struct lustre_client_ocd ll_lco;
69 struct list_head ll_conn_chain;
71 struct obd_uuid ll_mds_uuid;
72 struct obd_uuid ll_mds_peer_uuid;
76 #define LL_SBI_NOLCK 0x1
78 #define LLI_F_HAVE_OST_SIZE_LOCK 0
79 #define LLI_F_HAVE_MDS_SIZE_LOCK 1
81 struct llu_inode_info {
82 struct llu_sb_info *lli_sbi;
83 struct ll_fid lli_fid;
85 struct lov_stripe_md *lli_smd;
86 char *lli_symlink_name;
87 struct semaphore lli_open_sem;
89 unsigned long lli_flags;
92 struct file_identifier lli_sysio_fid;
94 struct lookup_intent *lli_it;
96 /* XXX workaround for libsysio readdir */
99 /* in libsysio we have no chance to store data in file,
100 * so place it here. since it's possible that an file
101 * was opened several times without close, we track an
103 struct ll_file_data *lli_file_data;
107 /* not for stat, change it later */
109 unsigned long lli_st_generation;
110 /* the most recent attributes from mds, it is used for timestampts
112 struct ost_lvb lli_lvb;
115 static inline struct llu_sb_info *llu_fs2sbi(struct filesys *fs)
117 return (struct llu_sb_info*)(fs->fs_private);
120 static inline struct llu_inode_info *llu_i2info(struct inode *inode)
122 return (struct llu_inode_info*)(inode->i_private);
125 static inline struct intnl_stat *llu_i2stat(struct inode *inode)
127 return &inode->i_stbuf;
130 static inline struct llu_sb_info *llu_i2sbi(struct inode *inode)
132 return llu_i2info(inode)->lli_sbi;
135 static inline struct obd_export *llu_i2obdexp(struct inode *inode)
137 return llu_i2info(inode)->lli_sbi->ll_osc_exp;
140 static inline struct obd_export *llu_i2mdcexp(struct inode *inode)
142 return llu_i2info(inode)->lli_sbi->ll_mdc_exp;
145 static inline int llu_is_root_inode(struct inode *inode)
147 return (llu_i2info(inode)->lli_fid.id ==
148 llu_i2info(inode)->lli_sbi->ll_rootino);
151 #define LL_SAVE_INTENT(inode, it) \
153 struct lookup_intent *temp; \
154 LASSERT(llu_i2info(inode)->lli_it == NULL); \
155 OBD_ALLOC(temp, sizeof(*temp)); \
156 memcpy(temp, it, sizeof(*temp)); \
157 llu_i2info(inode)->lli_it = temp; \
158 CDEBUG(D_DENTRY, "alloc intent %p to inode %p(ino %llu)\n", \
159 temp, inode, (long long)llu_i2stat(inode)->st_ino); \
163 #define LL_GET_INTENT(inode, it) \
165 it = llu_i2info(inode)->lli_it; \
168 llu_i2info(inode)->lli_it = NULL; \
169 CDEBUG(D_DENTRY, "dettach intent %p from inode %p(ino %llu)\n", \
170 it, inode, (long long)llu_i2stat(inode)->st_ino); \
173 /* interpet return codes from intent lookup */
174 #define LL_LOOKUP_POSITIVE 1
175 #define LL_LOOKUP_NEGATIVE 2
177 static inline void llu_inode2fid(struct ll_fid *fid, struct inode *inode)
179 *fid = llu_i2info(inode)->lli_fid;
183 struct inode *icbd_parent;
184 struct pnode *icbd_child;
188 void ll_i2gids(__u32 *suppgids, struct inode *i1,struct inode *i2);
190 typedef int (*intent_finish_cb)(struct ptlrpc_request *,
191 struct inode *parent, struct pnode *pnode,
192 struct lookup_intent *, int offset, obd_id ino);
193 int llu_intent_lock(struct inode *parent, struct pnode *pnode,
194 struct lookup_intent *, int flags, intent_finish_cb);
196 static inline __u64 ll_file_maxbytes(struct inode *inode)
198 return llu_i2info(inode)->lli_maxbytes;
201 struct mount_option_s
207 #define IS_BAD_PTR(ptr) \
208 ((unsigned long)(ptr) == 0 || (unsigned long)(ptr) > -1000UL)
211 int liblustre_process_log(struct config_llog_instance *cfg, char *mgsnid,
212 char *profile, int allow_recov);
213 int ll_parse_mount_target(const char *target, char **mgsnid,
216 extern struct mount_option_s mount_option;
219 void llu_update_inode(struct inode *inode, struct mds_body *body,
220 struct lov_stripe_md *lmm);
221 void obdo_to_inode(struct inode *dst, struct obdo *src, obd_flag valid);
222 void obdo_from_inode(struct obdo *dst, struct inode *src, obd_flag valid);
223 int ll_it_open_error(int phase, struct lookup_intent *it);
224 struct inode *llu_iget(struct filesys *fs, struct lustre_md *md);
225 int llu_inode_getattr(struct inode *inode, struct lov_stripe_md *lsm);
226 int llu_setattr_raw(struct inode *inode, struct iattr *attr);
227 int llu_file_flock(struct inode *ino, int cmd, struct file_lock *file_lock);
229 extern struct fssw_ops llu_fssw_ops;
232 void llu_prepare_mdc_op_data(struct mdc_op_data *data,
238 int llu_create(struct inode *dir, struct pnode_base *pnode, int mode);
239 int llu_local_open(struct llu_inode_info *lli, struct lookup_intent *it);
240 int llu_iop_open(struct pnode *pnode, int flags, mode_t mode);
241 int llu_mdc_close(struct obd_export *mdc_exp, struct inode *inode);
242 int llu_file_release(struct inode *inode);
243 int llu_iop_close(struct inode *inode);
244 _SYSIO_OFF_T llu_iop_pos(struct inode *ino, _SYSIO_OFF_T off);
245 int llu_vmtruncate(struct inode * inode, loff_t offset, obd_flag obd_flags);
246 void obdo_refresh_inode(struct inode *dst, struct obdo *src, obd_flag valid);
247 int llu_objects_destroy(struct ptlrpc_request *request, struct inode *dir);
250 int llu_iop_read(struct inode *ino, struct ioctx *ioctxp);
251 int llu_iop_write(struct inode *ino, struct ioctx *ioctxp);
252 int llu_iop_iodone(struct ioctx *ioctxp);
253 int llu_glimpse_size(struct inode *inode);
254 int llu_extent_lock_cancel_cb(struct ldlm_lock *lock,
255 struct ldlm_lock_desc *new, void *data,
257 int llu_extent_lock(struct ll_file_data *fd, struct inode *inode,
258 struct lov_stripe_md *lsm, int mode,
259 ldlm_policy_data_t *policy, struct lustre_handle *lockh,
261 int llu_extent_unlock(struct ll_file_data *fd, struct inode *inode,
262 struct lov_stripe_md *lsm, int mode,
263 struct lustre_handle *lockh);
266 int llu_iop_lookup(struct pnode *pnode,
268 struct intent *intnt,
270 void unhook_stale_inode(struct pnode *pno);
271 struct inode *llu_inode_from_lock(struct ldlm_lock *lock);
272 int llu_mdc_blocking_ast(struct ldlm_lock *lock,
273 struct ldlm_lock_desc *desc,
274 void *data, int flag);
277 ssize_t llu_iop_filldirentries(struct inode *ino, _SYSIO_OFF_T *basep,
278 char *buf, size_t nbytes);
281 #define EXT2_NAME_LEN (255)
288 char name[EXT2_NAME_LEN];
291 #define EXT2_DIR_PAD 4
292 #define EXT2_DIR_ROUND (EXT2_DIR_PAD - 1)
293 #define EXT2_DIR_REC_LEN(name_len) (((name_len) + 8 + EXT2_DIR_ROUND) & \
296 static inline struct ext2_dirent *ext2_next_entry(struct ext2_dirent *p)
298 return (struct ext2_dirent*)((char*) p + le16_to_cpu(p->rec_len));
301 static inline void inode_init_lvb(struct inode *inode, struct ost_lvb *lvb)
303 struct intnl_stat *st = llu_i2stat(inode);
304 lvb->lvb_size = st->st_size;
305 lvb->lvb_blocks = st->st_blocks;
306 lvb->lvb_mtime = st->st_mtime;
307 lvb->lvb_atime = st->st_atime;
308 lvb->lvb_ctime = st->st_ctime;