1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2003 Cluster File Systems, Inc.
6 * This code is issued under the GNU General Public License.
7 * See the file COPYING in this distribution
10 #ifndef LLITE_INTERNAL_H
11 #define LLITE_INTERNAL_H
13 #include <linux/lustre_debug.h>
15 /* default to about 40meg of readahead on a given system. That much tied
16 * up in 512k readahead requests serviced at 40ms each is about 1GB/s. */
17 #define SBI_DEFAULT_RA_MAX ((40 << 20) >> PAGE_CACHE_SHIFT)
22 RA_STAT_DISTANT_READPAGE,
23 RA_STAT_MISS_IN_WINDOW,
29 RA_STAT_MAX_IN_FLIGHT,
34 unsigned long ra_cur_pages;
35 unsigned long ra_max_pages;
36 unsigned long ra_stats[_NR_RA_STAT];
39 /* after roughly how long should we remove an inactive mount? */
40 #define GNS_MOUNT_TIMEOUT 120
42 /* how often should the GNS timer look for mounts to cleanup? */
43 #define GNS_TICK_TIMEOUT 1
45 /* how many times GNS will try to wait for 1 second for mount */
46 #define GNS_WAIT_ATTEMPTS 10
49 /* this protects pglist and max_r_a_pages. It isn't safe to grab from
50 * interrupt contexts. */
53 struct obd_uuid ll_sb_uuid;
54 struct obd_export *ll_md_exp;
55 struct obd_export *ll_dt_exp;
56 struct lov_desc ll_dt_desc;
57 struct proc_dir_entry *ll_proc_root;
58 struct lustre_id ll_rootid; /* root lustre id */
60 struct lustre_mount_data *ll_lmd;
64 struct list_head ll_conn_chain; /* per-conn chain of SBs */
66 struct hlist_head ll_orphan_dentry_list; /*please don't ask -p*/
67 struct ll_close_queue *ll_lcq;
69 struct lprocfs_stats *ll_stats; /* lprocfs stats counter */
71 unsigned long ll_pglist_gen;
72 struct list_head ll_pglist;
74 struct ll_ra_info ll_ra_info;
76 unsigned int ll_remote; /* remote client? */
78 /* times spent waiting for locks in each call site. These are
79 * all protected by the ll_lock */
80 struct obd_service_time ll_read_stime;
81 struct obd_service_time ll_write_stime;
82 struct obd_service_time ll_grouplock_stime;
83 struct obd_service_time ll_seek_stime;
84 struct obd_service_time ll_setattr_stime;
85 struct obd_service_time ll_brw_stime;
86 // struct obd_service_time ll_done_stime;
88 int ll_config_version; /* last-applied update */
90 /* list of GNS mounts; protected by the dcache_lock */
91 struct list_head ll_mnt_list;
93 struct semaphore ll_gns_sem;
94 spinlock_t ll_gns_lock;
95 wait_queue_head_t ll_gns_waitq;
96 atomic_t ll_gns_enabled;
98 struct timer_list ll_gns_timer;
99 struct list_head ll_gns_sbi_head;
100 struct completion ll_gns_mount_finished;
101 struct dentry *ll_gns_pending_dentry;
103 unsigned long ll_gns_tick;
104 unsigned long ll_gns_timeout;
107 char ll_gns_upcall[PATH_MAX];
109 /* mount object entry name */
110 char ll_gns_oname[PATH_MAX];
111 void *ll_crypto_info;
115 struct completion gc_starting;
116 struct completion gc_finishing;
119 /* mounting states */
120 #define LL_GNS_IDLE (1 << 0)
121 #define LL_GNS_MOUNTING (1 << 1)
122 #define LL_GNS_FINISHED (1 << 2)
124 /* mounts checking flags */
125 #define LL_GNS_UMOUNT (1 << 0)
126 #define LL_GNS_CHECK (1 << 1)
128 struct ll_readahead_state {
130 unsigned long ras_last_readpage, ras_consecutive;
131 unsigned long ras_window_start, ras_window_len;
132 unsigned long ras_next_readahead;
136 extern kmem_cache_t *ll_file_data_slab;
137 extern kmem_cache_t *ll_intent_slab;
138 struct lustre_handle;
140 struct ll_file_data {
141 struct ll_readahead_state fd_ras;
144 struct lustre_handle fd_cwlockh;
145 unsigned long fd_gid;
148 struct lov_stripe_md;
150 extern spinlock_t inode_lock;
152 extern void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi);
153 extern struct proc_dir_entry *proc_lustre_fs_root;
155 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
156 # define hlist_del_init list_del_init
159 static inline struct inode *ll_info2i(struct ll_inode_info *lli)
161 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
162 return &lli->lli_vfs_inode;
164 return list_entry(lli, struct inode, u.generic_ip);
170 struct inode *icbd_parent;
171 struct dentry **icbd_childp;
175 #define LLAP_MAGIC 98764321
177 struct ll_async_page {
180 struct page *llap_page;
181 struct list_head llap_pending_write;
182 /* only trust these if the page lock is providing exclusion */
183 unsigned llap_write_queued:1,
184 llap_defer_uptodate:1,
188 struct list_head llap_proc_item;
192 LLAP_ORIGIN_UNKNOWN = 0,
193 LLAP_ORIGIN_READPAGE,
194 LLAP_ORIGIN_READAHEAD,
195 LLAP_ORIGIN_COMMIT_WRITE,
196 LLAP_ORIGIN_WRITEPAGE,
203 #define REMOTE_ACL_HASHSIZE 16
206 struct list_head ra_perm_cache[REMOTE_ACL_HASHSIZE];
208 /* we use one sem per inode, it's kind of coarse: one user must
209 * wait if another user is updating the perm on this inode. but
210 * I guess this is fine is real world usage.
212 struct semaphore ra_update_sem;
215 struct lustre_remote_perm {
216 struct list_head lrp_list;
217 uid_t lrp_auth_uid; /* authenticated uid */
218 gid_t lrp_auth_gid; /* authenticated gid */
219 uint16_t lrp_perm; /* permission bits */
220 uint16_t lrp_valid:1, /* lrp_perm is valid */
221 lrp_setuid:1, /* allow setuid */
222 lrp_setgid:1; /* allow setgid */
223 struct list_head lrp_setxid_perms; /* setxid perms list */
226 struct remote_perm_setxid {
227 struct list_head list; /* permission list */
233 /* llite/lproc_llite.c */
234 int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
235 struct super_block *sb, char *lov,
237 void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi);
240 extern struct file_operations ll_dir_operations;
241 extern struct inode_operations ll_dir_inode_operations;
244 int ll_objects_destroy(struct ptlrpc_request *request,
245 struct inode *dir, int offset);
246 struct inode *ll_iget(struct super_block *sb, ino_t hash,
247 struct lustre_md *lic);
248 struct dentry *ll_find_alias(struct inode *, struct dentry *);
249 int ll_mdc_blocking_ast(struct ldlm_lock *, struct ldlm_lock_desc *,
250 void *data, int flag);
252 int ll_prepare_write(struct file *, struct page *, unsigned from, unsigned to);
253 int ll_commit_write(struct file *, struct page *, unsigned from, unsigned to);
254 int ll_writepage(struct page *page);
255 void ll_inode_fill_obdo(struct inode *inode, int cmd, struct obdo *oa);
256 void ll_ap_completion(void *data, int cmd, struct obdo *oa, int rc);
257 void ll_removepage(struct page *page);
258 int ll_readpage(struct file *file, struct page *page);
259 struct ll_async_page *llap_from_cookie(void *cookie);
260 struct ll_async_page *llap_from_page(struct page *page, unsigned origin);
261 void ll_readahead_init(struct inode *inode, struct ll_readahead_state *ras);
263 struct lpage_data *lpd_cast_private(struct page *page);
265 void ll_ra_accounting(struct page *page, struct address_space *mapping);
266 void ll_truncate(struct inode *inode);
269 extern struct file_operations ll_file_operations;
270 extern struct inode_operations ll_file_inode_operations;
271 int ll_md_real_close(struct obd_export *md_exp,
272 struct inode *inode, int flags);
273 extern int ll_inode_revalidate_it(struct dentry *);
274 int ll_setxattr(struct dentry *, const char *, const void *,
276 int ll_getxattr(struct dentry *, const char *, void *, size_t);
277 int ll_listxattr(struct dentry *, char *, size_t);
278 int ll_removexattr(struct dentry *, const char *);
279 extern int ll_inode_permission(struct inode *, int, struct nameidata *);
280 int ll_get_acl(struct inode *, struct posix_acl **acl,
281 struct ptlrpc_request **req);
282 int ll_refresh_lsm(struct inode *inode, struct lov_stripe_md *lsm);
283 int ll_extent_lock(struct ll_file_data *, struct inode *,
284 struct lov_stripe_md *, int mode, ldlm_policy_data_t *,
285 struct lustre_handle *, int ast_flags,
286 struct obd_service_time *);
287 int ll_extent_unlock(struct ll_file_data *, struct inode *,
288 struct lov_stripe_md *, int mode, struct lustre_handle *);
289 int ll_file_open(struct inode *inode, struct file *file);
290 int ll_file_release(struct inode *inode, struct file *file);
291 int ll_lsm_getattr(struct obd_export *, struct lov_stripe_md *, struct obdo *);
292 int ll_glimpse_size(struct inode *inode);
293 int ll_local_open(struct file *file, struct lookup_intent *it,
294 struct obd_client_handle *och);
295 int ll_md_close(struct obd_export *md_exp, struct inode *inode,
297 int ll_md_och_close(struct obd_export *md_exp, struct inode *inode,
298 struct obd_client_handle *och, int dirty);
299 void ll_och_fill(struct inode *inode, struct lookup_intent *it,
300 struct obd_client_handle *och);
302 int ll_getxattr_internal(struct inode *inode, const char *name,
303 void *value, size_t size, __u64 valid);
304 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
305 int ll_getattr(struct vfsmount *mnt, struct dentry *de, struct kstat *stat);
307 void ll_stime_record(struct ll_sb_info *sbi, struct timeval *start,
308 struct obd_service_time *stime);
311 void ll_intent_drop_lock(struct lookup_intent *);
312 void ll_intent_release(struct lookup_intent *);
313 int ll_intent_alloc(struct lookup_intent *);
314 void ll_intent_free(struct lookup_intent *it);
315 extern void ll_set_dd(struct dentry *de);
316 void ll_unhash_aliases(struct inode *);
317 void ll_frob_intent(struct lookup_intent **itp, struct lookup_intent *deft);
318 void ll_lookup_finish_locks(struct lookup_intent *it, struct dentry *dentry);
319 int revalidate_it_finish(struct ptlrpc_request *request, int offset,
320 struct lookup_intent *it, struct dentry *de);
323 /* llite/llite_gns.c */
324 int ll_gns_start_thread(void);
325 void ll_gns_stop_thread(void);
327 int ll_gns_mount_object(struct dentry *dentry,
328 struct vfsmount *mnt);
329 int ll_gns_umount_object(struct vfsmount *mnt);
331 int ll_gns_check_mounts(struct ll_sb_info *sbi,
334 void ll_gns_timer_callback(unsigned long data);
335 void ll_gns_add_timer(struct ll_sb_info *sbi);
336 void ll_gns_del_timer(struct ll_sb_info *sbi);
338 /* llite/llite_lib.c */
339 extern struct super_operations lustre_super_operations;
341 char *ll_read_opt(const char *opt, char *data);
342 int ll_set_opt(const char *opt, char *data, int fl);
343 void ll_options(char *options, char **ost, char **mds, char **gss,
344 char **mds_sec, char **oss_sec, int *async, int *flags);
345 void ll_lli_init(struct ll_inode_info *lli);
346 int ll_fill_super(struct super_block *sb, void *data, int silent);
347 int lustre_fill_super(struct super_block *sb, void *data, int silent);
348 void lustre_put_super(struct super_block *sb);
349 struct inode *ll_inode_from_lock(struct ldlm_lock *lock);
350 void ll_clear_inode(struct inode *inode);
351 int ll_attr2inode(struct inode *inode, struct iattr *attr, int trunc);
352 int ll_setattr_raw(struct inode *inode, struct iattr *attr);
353 int ll_setattr(struct dentry *de, struct iattr *attr);
354 int ll_statfs(struct super_block *sb, struct kstatfs *sfs);
355 int ll_statfs_internal(struct super_block *sb, struct obd_statfs *osfs,
356 unsigned long maxage);
357 void ll_update_inode(struct inode *inode, struct lustre_md *);
358 int ll_fetch_remote_perm(struct inode *inode, struct ptlrpc_request *req,
360 int it_disposition(struct lookup_intent *it, int flag);
361 void it_set_disposition(struct lookup_intent *it, int flag);
362 void ll_read_inode2(struct inode *inode, void *opaque);
363 void ll_delete_inode(struct inode *inode);
364 int ll_iocontrol(struct inode *inode, struct file *file,
365 unsigned int cmd, unsigned long arg);
366 void ll_umount_begin(struct super_block *sb);
367 int ll_prep_inode(struct obd_export *, struct obd_export *, struct inode **inode,
368 struct ptlrpc_request *req, int offset, struct super_block *);
369 __u32 get_uuid2int(const char *name, int len);
370 struct dentry *ll_fh_to_dentry(struct super_block *sb, __u32 *data, int len,
371 int fhtype, int parent);
372 int ll_dentry_to_fh(struct dentry *, __u32 *datap, int *lenp, int need_parent);
373 int null_if_equal(struct ldlm_lock *lock, void *data);
374 int ll_process_config_update(struct ll_sb_info *sbi, int clean);
375 int ll_show_options(struct seq_file *m, struct vfsmount *mnt);
376 int ll_flush_cred(struct inode *inode);
378 int ll_remote_acl_permission(struct inode *inode, int mode);
379 int ll_remote_acl_update(struct inode *inode, struct mds_remote_perm *perm);
380 void ll_inode_invalidate_acl(struct inode *inode);
382 /* llite/special.c */
383 extern struct inode_operations ll_special_inode_operations;
384 extern struct file_operations ll_special_chr_inode_fops;
385 extern struct file_operations ll_special_chr_file_fops;
386 extern struct file_operations ll_special_blk_inode_fops;
387 extern struct file_operations ll_special_fifo_inode_fops;
388 extern struct file_operations ll_special_fifo_file_fops;
389 extern struct file_operations ll_special_sock_inode_fops;
391 /* llite/symlink.c */
392 extern struct inode_operations ll_fast_symlink_inode_operations;
394 /* llite/llite_close.c */
395 struct ll_close_queue {
397 struct list_head lcq_list;
398 wait_queue_head_t lcq_waitq;
399 struct completion lcq_comp;
402 void llap_write_pending(struct inode *inode, struct ll_async_page *llap);
403 void llap_write_complete(struct inode *inode, struct ll_async_page *llap);
404 void ll_open_complete(struct inode *inode);
405 int ll_is_inode_dirty(struct inode *inode);
406 void ll_try_done_writing(struct inode *inode);
407 void ll_queue_done_writing(struct inode *inode);
408 void ll_close_thread_shutdown(struct ll_close_queue *lcq);
409 int ll_close_thread_start(struct ll_close_queue **lcq_ret);
412 /* llite/llite_mmap.c */
413 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
414 typedef struct rb_root rb_root_t;
415 typedef struct rb_node rb_node_t;
418 struct ll_lock_tree_node;
419 struct ll_lock_tree {
421 struct list_head lt_locked_list;
422 struct ll_file_data *lt_fd;
424 int ll_teardown_mmaps(struct address_space *mapping, __u64 first,
426 int ll_file_mmap(struct file * file, struct vm_area_struct * vma);
427 struct ll_lock_tree_node * ll_node_from_inode(struct inode *inode, __u64 start,
428 __u64 end, ldlm_mode_t mode);
429 int ll_tree_lock(struct ll_lock_tree *tree,
430 struct ll_lock_tree_node *first_node, struct inode *inode,
431 const char *buf, size_t count, int ast_flags);
432 int ll_tree_unlock(struct ll_lock_tree *tree, struct inode *inode);
434 int ll_get_fid(struct obd_export *exp, struct lustre_id *idp,
435 char *filename, struct lustre_id *ret);
438 #define LL_SBI_NOLCK 0x1
439 #define LL_SBI_READAHEAD 0x2
440 #define LL_SUPER_MAGIC 0x0BD00BD0
441 #define LL_MAX_BLKSIZE (4UL * 1024 * 1024)
443 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
444 #define ll_s2sbi(sb) ((struct ll_sb_info *)((sb)->s_fs_info))
445 #define ll_set_sbi(sb, sbi) ((sb)->s_fs_info = sbi)
446 static inline __u64 ll_ts2u64(struct timespec *time)
448 __u64 t = time->tv_sec;
452 #define ll_s2sbi(sb) ((struct ll_sb_info *)((sb)->u.generic_sbp))
453 #define ll_set_sbi(sb, sbi) ((sb)->u.generic_sbp = sbi)
454 static inline __u64 ll_ts2u64(time_t *time)
460 /* don't need an addref as the sb_info should be holding one */
461 static inline struct obd_export *ll_s2dtexp(struct super_block *sb)
463 return ll_s2sbi(sb)->ll_dt_exp;
466 /* don't need an addref as the sb_info should be holding one */
467 static inline struct obd_export *ll_s2mdexp(struct super_block *sb)
469 return ll_s2sbi(sb)->ll_md_exp;
472 static inline struct client_obd *sbi2md(struct ll_sb_info *sbi)
474 struct obd_device *obd = sbi->ll_md_exp->exp_obd;
480 // FIXME: replace the name of this with LL_SB to conform to kernel stuff
481 static inline struct ll_sb_info *ll_i2sbi(struct inode *inode)
483 return ll_s2sbi(inode->i_sb);
486 static inline struct obd_export *ll_i2dtexp(struct inode *inode)
488 return ll_s2dtexp(inode->i_sb);
491 static inline struct obd_export *ll_i2mdexp(struct inode *inode)
493 return ll_s2mdexp(inode->i_sb);
495 static inline int ll_mds_max_easize(struct super_block *sb)
497 return sbi2md(ll_s2sbi(sb))->cl_max_mds_easize;
500 static inline __u64 ll_file_maxbytes(struct inode *inode)
502 return ll_i2info(inode)->lli_maxbytes;
507 ll_inode2id(struct lustre_id *id, struct inode *inode)
509 struct lustre_id *lid = &ll_i2info(inode)->lli_id;
511 mdc_pack_id(id, inode->i_ino, inode->i_generation,
512 (inode->i_mode & S_IFMT), id_group(lid),
517 ll_prepare_mdc_data(struct mdc_op_data *data, struct inode *i1,
518 struct inode *i2, const char *name, int namelen,
522 ll_inode2id(&data->id1, i1);
524 /* it could be directory with mea */
525 data->mea1 = ll_i2info(i1)->lli_mea;
528 ll_inode2id(&data->id2, i2);
529 data->mea2 = ll_i2info(i2)->lli_mea;
534 data->namelen = namelen;
535 data->create_mode = mode;
536 data->mod_time = LTIME_S(CURRENT_TIME);
539 struct crypto_helper_ops {
540 int (*init_it_key)(struct inode *inode, struct lookup_intent *it);
541 int (*create_key)(struct inode *dir, mode_t mode, void **key,
543 int (*get_mac)(struct inode *inode, struct iattr *iattr, void*value,
544 int size, void **key, int* key_size);
545 int (*decrypt_key)(struct inode *inode, struct lookup_intent *it);
546 int (*init_inode_key)(struct inode *inode, void *md_key);
547 int (*destroy_key)(struct inode *inode);
550 /*llite crypto ops for crypto api*/
551 struct ll_crypto_info {
552 struct obd_export *ll_gt_exp;
553 struct list_head ll_cops_list;
554 struct crypto_helper_ops *ll_cops;
557 #define ll_page2key(page) ((ll_i2info(page->mapping->host))->lli_key_info)
558 static inline struct ll_crypto_info* ll_s2crpi(struct super_block *sb)
560 return (struct ll_crypto_info*)ll_s2sbi(sb)->ll_crypto_info;
562 static inline struct ll_crypto_info* ll_i2crpi(struct inode *inode)
564 return (struct ll_crypto_info*)ll_i2sbi(inode)->ll_crypto_info;
567 static inline struct crypto_helper_ops* ll_i2crpops(struct inode *inode)
569 return ll_i2crpi(inode)->ll_cops;
572 static inline struct crypto_helper_ops* ll_s2crpops(struct super_block *sb)
574 return ll_s2crpi(sb)->ll_cops;
577 static inline struct obd_export *ll_s2gsexp(struct super_block *sb)
579 struct ll_crypto_info *llci = ll_s2crpi(sb);
581 return llci->ll_gt_exp;
584 static inline struct obd_export *ll_i2gsexp(struct inode *inode)
586 return ll_s2gsexp(inode->i_sb);
590 int ll_crypto_init_it_key(struct inode *inode, struct lookup_intent *it)
592 struct ll_crypto_info *lci = ll_i2crpi(inode);
594 struct crypto_helper_ops *ops = lci->ll_cops;;
595 if (ops && ops->init_it_key)
596 return ops->init_it_key(inode, it);
602 int ll_crypto_create_key(struct inode *inode, mode_t mode, void **key,
605 struct ll_crypto_info *lci = ll_i2crpi(inode);
607 struct crypto_helper_ops *ops = lci->ll_cops;;
608 if (ops && ops->create_key)
609 return ops->create_key(inode, mode, key, key_size);
615 int ll_crypto_get_mac(struct inode *inode, struct iattr *attr, void *acl,
616 int acl_size, void **mac, int *mac_size)
618 struct ll_crypto_info *lci = ll_i2crpi(inode);
620 struct crypto_helper_ops *ops = lci->ll_cops;
621 if (ops && ops->get_mac)
622 return ops->get_mac(inode, attr, acl, acl_size,
629 int ll_crypto_decrypt_key(struct inode *inode, struct lookup_intent *it)
631 struct ll_crypto_info *lci = ll_i2crpi(inode);
633 struct crypto_helper_ops *ops = lci->ll_cops;
634 if (ops && ops->decrypt_key)
635 return ops->decrypt_key(inode, it);
641 int ll_crypto_init_inode_key(struct inode *inode, void *md_key)
643 struct ll_crypto_info *lci = ll_i2crpi(inode);
645 struct crypto_helper_ops *ops = lci->ll_cops;
646 if (ops && ops->init_inode_key)
647 return ops->init_inode_key(inode, md_key);
653 int ll_crypto_destroy_inode_key(struct inode *inode)
655 struct ll_crypto_info *lci = ll_i2crpi(inode);
657 struct crypto_helper_ops *ops = lci->ll_cops;
658 if (ops && ops->destroy_key)
659 return ops->destroy_key(inode);
664 int lustre_init_crypto(struct super_block *sb, char *gkc,
665 struct obd_connect_data *data, int async);
666 int lustre_destroy_crypto(struct super_block *sb);
667 int ll_set_sb_gksinfo(struct super_block *sb, char *type);
668 /* pass this flag to ll_md_real_close() to send close rpc right away */
669 #define FMODE_SYNC 00000010
670 #endif /* LLITE_INTERNAL_H */