Whamcloud - gitweb
comment for ll_readahead_state and assertion in osc_send_oap_request() from b1_4
[fs/lustre-release.git] / lustre / llite / llite_internal.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * Copyright (C) 2003 Cluster File Systems, Inc.
5  *
6  * This code is issued under the GNU General Public License.
7  * See the file COPYING in this distribution
8  */
9
10 #ifndef LLITE_INTERNAL_H
11 #define LLITE_INTERNAL_H
12
13 #include <linux/lustre_debug.h>
14
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)
18
19 enum ra_stat {
20         RA_STAT_HIT = 0,
21         RA_STAT_MISS,
22         RA_STAT_DISTANT_READPAGE,
23         RA_STAT_MISS_IN_WINDOW,
24         RA_STAT_FAILED_MATCH,
25         RA_STAT_DISCARDED,
26         RA_STAT_ZERO_LEN,
27         RA_STAT_ZERO_WINDOW,
28         RA_STAT_EOF,
29         RA_STAT_MAX_IN_FLIGHT,
30         _NR_RA_STAT,
31 };
32
33 struct ll_ra_info {
34         unsigned long             ra_cur_pages;
35         unsigned long             ra_max_pages;
36         unsigned long             ra_stats[_NR_RA_STAT];
37 };
38
39 /* after roughly how long should we remove an inactive mount? */
40 #define GNS_MOUNT_TIMEOUT 120
41
42 /* how often should the GNS timer look for mounts to cleanup? */
43 #define GNS_TICK_TIMEOUT  1
44
45 /* how many times GNS will try to wait for 1 second for mount */
46 #define GNS_WAIT_ATTEMPTS 10
47
48 struct ll_sb_info {
49         /* this protects pglist and max_r_a_pages.  It isn't safe to grab from
50          * interrupt contexts. */
51         spinlock_t                ll_lock;
52
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 */
59
60         struct lustre_mount_data *ll_lmd;
61         char                     *ll_instance;
62
63         int                       ll_flags;
64         struct list_head          ll_conn_chain; /* per-conn chain of SBs */
65
66         struct hlist_head         ll_orphan_dentry_list; /*please don't ask -p*/
67         struct ll_close_queue    *ll_lcq;
68
69         struct lprocfs_stats     *ll_stats;      /* lprocfs stats counter */
70
71         unsigned long             ll_pglist_gen;
72         struct list_head          ll_pglist;
73
74         struct ll_ra_info         ll_ra_info;
75
76         unsigned int              ll_remote;      /* remote client? */
77
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;
87
88         int                       ll_config_version; /* last-applied update */
89
90         /* list of GNS mounts; protected by the dcache_lock */
91         struct list_head          ll_mnt_list;
92
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;
97         int                       ll_gns_state;
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;
102
103         unsigned long             ll_gns_tick;
104         unsigned long             ll_gns_timeout;
105
106         /* path to upcall */
107         char                      ll_gns_upcall[PATH_MAX];
108
109         /* mount object entry name */
110         char                      ll_gns_oname[PATH_MAX];
111         void                      *ll_crypto_info;
112 };
113
114 struct ll_gns_ctl {
115         struct completion gc_starting;
116         struct completion gc_finishing;
117 };
118
119 /* mounting states */
120 #define LL_GNS_IDLE               (1 << 0)
121 #define LL_GNS_MOUNTING           (1 << 1)
122 #define LL_GNS_FINISHED           (1 << 2)
123
124 /* mounts checking flags */
125 #define LL_GNS_UMOUNT             (1 << 0)
126 #define LL_GNS_CHECK              (1 << 1)
127
128 /*
129  * per file-descriptor read-ahead data.
130  */
131 struct ll_readahead_state {
132         spinlock_t      ras_lock;
133         /*
134          * index of the last page that read(2) needed and that wasn't in the
135          * cache. Used by ras_update() to detect seeks.
136          *
137          * XXX nikita: if access seeks into cached region, Lustre doesn't see
138          * this.
139          */
140         unsigned long   ras_last_readpage;
141         /*
142          * number of pages read after last read-ahead window reset. As window
143          * is reset on each seek, this is effectively a number of consecutive
144          * accesses. Maybe ->ras_accessed_in_window is better name.
145          *
146          * XXX nikita: window is also reset (by ras_update()) when Lustre
147          * believes that memory pressure evicts read-ahead pages. In that
148          * case, it probably doesn't make sense to expand window to
149          * PTLRPC_MAX_BRW_PAGES on the third access.
150          */
151         unsigned long   ras_consecutive;
152         /*
153          * Parameters of current read-ahead window. Handled by
154          * ras_update(). On the initial access to the file or after a seek,
155          * window is reset to 0. After 3 consecutive accesses, window is
156          * expanded to PTLRPC_MAX_BRW_PAGES. Afterwards, window is enlarged by
157          * PTLRPC_MAX_BRW_PAGES chunks up to ->ra_max_pages.
158          */
159         unsigned long   ras_window_start, ras_window_len;
160         /*
161          * Where next read-ahead should start at. This lies within read-ahead
162          * window. Read-ahead window is read in pieces rather than at once
163          * because: 1. lustre limits total number of pages under read-ahead by
164          * ->ra_max_pages (see ll_ra_count_get()), 2. client cannot read pages
165          * not covered by DLM lock.
166          */
167         unsigned long   ras_next_readahead;
168
169 };
170
171 extern kmem_cache_t *ll_file_data_slab;
172 extern kmem_cache_t *ll_intent_slab;
173 struct lustre_handle;
174
175 struct ll_file_data {
176         struct ll_readahead_state fd_ras;
177         __u32 fd_flags;
178         int fd_omode;
179         struct lustre_handle fd_cwlockh;
180         unsigned long fd_gid;
181 };
182
183 struct lov_stripe_md;
184
185 extern spinlock_t inode_lock;
186
187 extern void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi);
188 extern struct proc_dir_entry *proc_lustre_fs_root;
189
190 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
191 # define hlist_del_init list_del_init
192 #endif
193
194 static inline struct inode *ll_info2i(struct ll_inode_info *lli)
195 {
196 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
197         return &lli->lli_vfs_inode;
198 #else
199         return list_entry(lli, struct inode, u.generic_ip);
200 #endif
201 }
202
203
204 struct it_cb_data {
205         struct inode *icbd_parent;
206         struct dentry **icbd_childp;
207         obd_id hash;
208 };
209
210 #define LLAP_MAGIC 98764321
211
212 struct ll_async_page {
213         int             llap_magic;
214         void            *llap_cookie;
215         struct page     *llap_page;
216         struct list_head llap_pending_write;
217          /* only trust these if the page lock is providing exclusion */
218         unsigned         llap_write_queued:1,
219                          llap_defer_uptodate:1,
220                          llap_origin:3,
221                          llap_ra_used:1;
222
223         struct list_head llap_proc_item;
224 };
225
226 enum {
227         LLAP_ORIGIN_UNKNOWN = 0,
228         LLAP_ORIGIN_READPAGE,
229         LLAP_ORIGIN_READAHEAD,
230         LLAP_ORIGIN_COMMIT_WRITE,
231         LLAP_ORIGIN_WRITEPAGE,
232         LLAP__ORIGIN_MAX,
233 };
234
235 /*
236  * remote ACL stuff
237  */
238 #define REMOTE_ACL_HASHSIZE     16
239
240 struct remote_acl {
241         struct list_head        ra_perm_cache[REMOTE_ACL_HASHSIZE];
242         spinlock_t              ra_lock;
243         /* we use one sem per inode, it's kind of coarse: one user must
244          * wait if another user is updating the perm on this inode. but
245          * I guess this is fine is real world usage.
246          */
247         struct semaphore        ra_update_sem;
248 };
249
250 struct lustre_remote_perm {
251         struct list_head        lrp_list;
252         uid_t                   lrp_auth_uid;       /* authenticated uid */
253         gid_t                   lrp_auth_gid;       /* authenticated gid */
254         uint16_t                lrp_perm;           /* permission bits */
255         uint16_t                lrp_valid:1,        /* lrp_perm is valid */
256                                 lrp_setuid:1,       /* allow setuid */
257                                 lrp_setgid:1;       /* allow setgid */
258         struct list_head        lrp_setxid_perms;   /* setxid perms list */
259 };
260
261 struct remote_perm_setxid {
262         struct list_head        list; /* permission list */
263         uid_t                   uid;
264         gid_t                   gid;
265         uint16_t                perm;
266 };
267
268 /* llite/lproc_llite.c */
269 int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
270                                 struct super_block *sb, char *lov,
271                                 char *lmv);
272 void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi);
273
274 /* llite/dir.c */
275 extern struct file_operations ll_dir_operations;
276 extern struct inode_operations ll_dir_inode_operations;
277
278 /* llite/namei.c */
279 int ll_objects_destroy(struct ptlrpc_request *request,
280                        struct inode *dir, int offset);
281 struct inode *ll_iget(struct super_block *sb, ino_t hash,
282                       struct lustre_md *lic);
283 struct dentry *ll_find_alias(struct inode *, struct dentry *);
284 int ll_mdc_blocking_ast(struct ldlm_lock *, struct ldlm_lock_desc *,
285                         void *data, int flag);
286 /* llite/rw.c */
287 int ll_prepare_write(struct file *, struct page *, unsigned from, unsigned to);
288 int ll_commit_write(struct file *, struct page *, unsigned from, unsigned to);
289 int ll_writepage(struct page *page);
290 void ll_inode_fill_obdo(struct inode *inode, int cmd, struct obdo *oa);
291 void ll_ap_completion(void *data, int cmd, struct obdo *oa, int rc);
292 void ll_removepage(struct page *page);
293 int ll_readpage(struct file *file, struct page *page);
294 struct ll_async_page *llap_from_cookie(void *cookie);
295 struct ll_async_page *llap_from_page(struct page *page, unsigned origin);
296 void ll_readahead_init(struct inode *inode, struct ll_readahead_state *ras);
297
298 struct lpage_data *lpd_cast_private(struct page *page);
299
300 void ll_ra_accounting(struct page *page, struct address_space *mapping);
301 void ll_truncate(struct inode *inode);
302
303 /* llite/file.c */
304 extern struct file_operations ll_file_operations;
305 extern struct inode_operations ll_file_inode_operations;
306 int ll_md_real_close(struct obd_export *md_exp,
307                      struct inode *inode, int flags);
308 extern int ll_inode_revalidate_it(struct dentry *);
309 int ll_setxattr(struct dentry *, const char *, const void *,
310                 size_t, int);
311 int ll_getxattr(struct dentry *, const char *, void *, size_t);
312 int ll_listxattr(struct dentry *, char *, size_t);
313 int ll_removexattr(struct dentry *, const char *);
314 extern int ll_inode_permission(struct inode *, int, struct nameidata *);
315 int ll_get_acl(struct inode *, struct posix_acl **acl,
316                struct ptlrpc_request **req);
317 int ll_refresh_lsm(struct inode *inode, struct lov_stripe_md *lsm);
318 int ll_extent_lock(struct ll_file_data *, struct inode *,
319                    struct lov_stripe_md *, int mode, ldlm_policy_data_t *,
320                    struct lustre_handle *, int ast_flags,
321                    struct obd_service_time *);
322 int ll_extent_unlock(struct ll_file_data *, struct inode *,
323                      struct lov_stripe_md *, int mode, struct lustre_handle *);
324 int ll_file_open(struct inode *inode, struct file *file);
325 int ll_file_release(struct inode *inode, struct file *file);
326 int ll_lsm_getattr(struct obd_export *, struct lov_stripe_md *, struct obdo *);
327 int ll_glimpse_size(struct inode *inode);
328 int ll_local_open(struct file *file, struct lookup_intent *it,
329                   struct obd_client_handle *och);
330 int ll_md_close(struct obd_export *md_exp, struct inode *inode,
331                 struct file *file);
332 int ll_md_och_close(struct obd_export *md_exp, struct inode *inode,
333                     struct obd_client_handle *och, int dirty);
334 void ll_och_fill(struct inode *inode, struct lookup_intent *it,
335                  struct obd_client_handle *och);
336
337 int ll_getxattr_internal(struct inode *inode, const char *name,
338                          void *value, size_t size, __u64 valid);
339 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
340 int ll_getattr(struct vfsmount *mnt, struct dentry *de, struct kstat *stat);
341 #endif
342 void ll_stime_record(struct ll_sb_info *sbi, struct timeval *start,
343                      struct obd_service_time *stime);
344
345 /* llite/dcache.c */
346 void ll_intent_drop_lock(struct lookup_intent *);
347 void ll_intent_release(struct lookup_intent *);
348 int ll_intent_alloc(struct lookup_intent *);
349 void ll_intent_free(struct lookup_intent *it);
350 extern void ll_set_dd(struct dentry *de);
351 void ll_unhash_aliases(struct inode *);
352 void ll_frob_intent(struct lookup_intent **itp, struct lookup_intent *deft);
353 void ll_lookup_finish_locks(struct lookup_intent *it, struct dentry *dentry);
354 int revalidate_it_finish(struct ptlrpc_request *request, int offset,
355                          struct lookup_intent *it, struct dentry *de);
356
357
358 /* llite/llite_gns.c */
359 int ll_gns_start_thread(void);
360 void ll_gns_stop_thread(void);
361
362 int ll_gns_mount_object(struct dentry *dentry,
363                         struct vfsmount *mnt);
364 int ll_gns_umount_object(struct vfsmount *mnt);
365
366 int ll_gns_check_mounts(struct ll_sb_info *sbi,
367                         int flags);
368
369 void ll_gns_timer_callback(unsigned long data);
370 void ll_gns_add_timer(struct ll_sb_info *sbi);
371 void ll_gns_del_timer(struct ll_sb_info *sbi);
372
373 /* llite/llite_lib.c */
374 extern struct super_operations lustre_super_operations;
375
376 char *ll_read_opt(const char *opt, char *data);
377 int ll_set_opt(const char *opt, char *data, int fl);
378 void ll_options(char *options, char **ost, char **mds, char **gss,
379                 char **mds_sec, char **oss_sec, int *async, int *flags);
380 void ll_lli_init(struct ll_inode_info *lli);
381 int ll_fill_super(struct super_block *sb, void *data, int silent);
382 int lustre_fill_super(struct super_block *sb, void *data, int silent);
383 void lustre_put_super(struct super_block *sb);
384 struct inode *ll_inode_from_lock(struct ldlm_lock *lock);
385 void ll_clear_inode(struct inode *inode);
386 int ll_attr2inode(struct inode *inode, struct iattr *attr, int trunc);
387 int ll_setattr_raw(struct inode *inode, struct iattr *attr);
388 int ll_setattr(struct dentry *de, struct iattr *attr);
389 int ll_statfs(struct super_block *sb, struct kstatfs *sfs);
390 int ll_statfs_internal(struct super_block *sb, struct obd_statfs *osfs,
391                        unsigned long maxage);
392 void ll_update_inode(struct inode *inode, struct lustre_md *);
393 int ll_fetch_remote_perm(struct inode *inode, struct ptlrpc_request *req,
394                          uint16_t *perm);
395 int it_disposition(struct lookup_intent *it, int flag);
396 void it_set_disposition(struct lookup_intent *it, int flag);
397 void ll_read_inode2(struct inode *inode, void *opaque);
398 void ll_delete_inode(struct inode *inode);
399 int ll_iocontrol(struct inode *inode, struct file *file,
400                  unsigned int cmd, unsigned long arg);
401 void ll_umount_begin(struct super_block *sb);
402 int ll_prep_inode(struct obd_export *, struct obd_export *, struct inode **inode,
403                   struct ptlrpc_request *req, int offset, struct super_block *);
404 __u32 get_uuid2int(const char *name, int len);
405 struct dentry *ll_fh_to_dentry(struct super_block *sb, __u32 *data, int len,
406                                int fhtype, int parent);
407 int ll_dentry_to_fh(struct dentry *, __u32 *datap, int *lenp, int need_parent);
408 int null_if_equal(struct ldlm_lock *lock, void *data);
409 int ll_process_config_update(struct ll_sb_info *sbi, int clean);
410 int ll_show_options(struct seq_file *m, struct vfsmount *mnt);
411 int ll_flush_cred(struct inode *inode);
412
413 int ll_remote_acl_permission(struct inode *inode, int mode);
414 int ll_remote_acl_update(struct inode *inode, struct mds_remote_perm *perm);
415 void ll_inode_invalidate_acl(struct inode *inode);
416
417 /* llite/special.c */
418 extern struct inode_operations ll_special_inode_operations;
419 extern struct file_operations ll_special_chr_inode_fops;
420 extern struct file_operations ll_special_chr_file_fops;
421 extern struct file_operations ll_special_blk_inode_fops;
422 extern struct file_operations ll_special_fifo_inode_fops;
423 extern struct file_operations ll_special_fifo_file_fops;
424 extern struct file_operations ll_special_sock_inode_fops;
425
426 /* llite/symlink.c */
427 extern struct inode_operations ll_fast_symlink_inode_operations;
428
429 /* llite/llite_close.c */
430 struct ll_close_queue {
431         spinlock_t              lcq_lock;
432         struct list_head        lcq_list;
433         wait_queue_head_t       lcq_waitq;
434         struct completion       lcq_comp;
435 };
436
437 void llap_write_pending(struct inode *inode, struct ll_async_page *llap);
438 void llap_write_complete(struct inode *inode, struct ll_async_page *llap);
439 void ll_open_complete(struct inode *inode);
440 int ll_is_inode_dirty(struct inode *inode);
441 void ll_try_done_writing(struct inode *inode);
442 void ll_queue_done_writing(struct inode *inode);
443 void ll_close_thread_shutdown(struct ll_close_queue *lcq);
444 int ll_close_thread_start(struct ll_close_queue **lcq_ret);
445
446
447 /* llite/llite_mmap.c */
448 #if  (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
449 typedef struct rb_root  rb_root_t;
450 typedef struct rb_node  rb_node_t;
451 #endif
452
453 struct ll_lock_tree_node;
454 struct ll_lock_tree {
455         rb_root_t                       lt_root;
456         struct list_head                lt_locked_list;
457         struct ll_file_data             *lt_fd;
458 };
459 int ll_teardown_mmaps(struct address_space *mapping, __u64 first,
460                       __u64 last);
461 int ll_file_mmap(struct file * file, struct vm_area_struct * vma);
462 struct ll_lock_tree_node * ll_node_from_inode(struct inode *inode, __u64 start,
463                                               __u64 end, ldlm_mode_t mode);
464 int ll_tree_lock(struct ll_lock_tree *tree,
465                  struct ll_lock_tree_node *first_node, struct inode *inode,
466                  const char *buf, size_t count, int ast_flags);
467 int ll_tree_unlock(struct ll_lock_tree *tree, struct inode *inode);
468
469 int ll_get_fid(struct obd_export *exp, struct lustre_id *idp,
470                char *filename, struct lustre_id *ret);
471
472 /* generic */
473 #define LL_SBI_NOLCK           0x1
474 #define LL_SBI_READAHEAD       0x2
475 #define LL_SUPER_MAGIC         0x0BD00BD0
476 #define LL_MAX_BLKSIZE         (4UL * 1024 * 1024)
477
478 #if  (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
479 #define    ll_s2sbi(sb)        ((struct ll_sb_info *)((sb)->s_fs_info))
480 #define    ll_set_sbi(sb, sbi) ((sb)->s_fs_info = sbi)
481 static inline __u64 ll_ts2u64(struct timespec *time)
482 {
483         __u64 t = time->tv_sec;
484         return t;
485 }
486 #else  /* 2.4 here */
487 #define    ll_s2sbi(sb)        ((struct ll_sb_info *)((sb)->u.generic_sbp))
488 #define    ll_set_sbi(sb, sbi) ((sb)->u.generic_sbp = sbi)
489 static inline __u64 ll_ts2u64(time_t *time)
490 {
491         return *time;
492 }
493 #endif
494
495 /* don't need an addref as the sb_info should be holding one */
496 static inline struct obd_export *ll_s2dtexp(struct super_block *sb)
497 {
498         return ll_s2sbi(sb)->ll_dt_exp;
499 }
500
501 /* don't need an addref as the sb_info should be holding one */
502 static inline struct obd_export *ll_s2mdexp(struct super_block *sb)
503 {
504         return ll_s2sbi(sb)->ll_md_exp;
505 }
506
507 static inline struct client_obd *sbi2md(struct ll_sb_info *sbi)
508 {
509         struct obd_device *obd = sbi->ll_md_exp->exp_obd;
510         if (obd == NULL)
511                 LBUG();
512         return &obd->u.cli;
513 }
514
515 // FIXME: replace the name of this with LL_SB to conform to kernel stuff
516 static inline struct ll_sb_info *ll_i2sbi(struct inode *inode)
517 {
518         return ll_s2sbi(inode->i_sb);
519 }
520
521 static inline struct obd_export *ll_i2dtexp(struct inode *inode)
522 {
523         return ll_s2dtexp(inode->i_sb);
524 }
525
526 static inline struct obd_export *ll_i2mdexp(struct inode *inode)
527 {
528         return ll_s2mdexp(inode->i_sb);
529 }
530 static inline int ll_mds_max_easize(struct super_block *sb)
531 {
532         return sbi2md(ll_s2sbi(sb))->cl_max_mds_easize;
533 }
534
535 static inline __u64 ll_file_maxbytes(struct inode *inode)
536 {
537         return ll_i2info(inode)->lli_maxbytes;
538 }
539
540
541 static inline void
542 ll_inode2id(struct lustre_id *id, struct inode *inode)
543 {
544         struct lustre_id *lid = &ll_i2info(inode)->lli_id;
545
546         mdc_pack_id(id, inode->i_ino, inode->i_generation,
547                     (inode->i_mode & S_IFMT), id_group(lid),
548                     id_fid(lid));
549 }
550
551 static inline void
552 ll_prepare_mdc_data(struct mdc_op_data *data, struct inode *i1,
553                     struct inode *i2, const char *name, int namelen,
554                     int mode)
555 {
556         LASSERT(i1);
557         ll_inode2id(&data->id1, i1);
558
559         /* it could be directory with mea */
560         data->mea1 = ll_i2info(i1)->lli_mea;
561
562         if (i2) {
563                 ll_inode2id(&data->id2, i2);
564                 data->mea2 = ll_i2info(i2)->lli_mea;
565         }
566
567         data->valid = 0;
568         data->name = name;
569         data->namelen = namelen;
570         data->create_mode = mode;
571         data->mod_time = LTIME_S(CURRENT_TIME);
572 }
573
574 struct crypto_helper_ops {
575        int (*init_it_key)(struct inode *inode, struct lookup_intent *it);
576        int (*create_key)(struct inode *dir, mode_t mode, void **key,
577                          int* key_size);
578        int (*get_mac)(struct inode *inode, struct iattr *iattr, void*value,
579                       int size, void **key, int* key_size);
580        int (*decrypt_key)(struct inode *inode, struct lookup_intent *it);
581        int (*init_inode_key)(struct inode *inode, void *md_key);
582        int (*destroy_key)(struct inode *inode);
583 };
584
585 /*llite crypto ops for crypto api*/
586 struct ll_crypto_info {
587         struct obd_export    *ll_gt_exp;
588         struct list_head     ll_cops_list;
589         struct crypto_helper_ops *ll_cops;
590         int    ll_c_flags;
591 };
592 #define ll_page2key(page)  ((ll_i2info(page->mapping->host))->lli_key_info)
593 static inline struct ll_crypto_info* ll_s2crpi(struct super_block *sb)
594 {
595         return (struct ll_crypto_info*)ll_s2sbi(sb)->ll_crypto_info;
596 }
597 static inline struct ll_crypto_info* ll_i2crpi(struct inode *inode)
598 {
599         return (struct ll_crypto_info*)ll_i2sbi(inode)->ll_crypto_info;
600 }
601
602 static inline struct crypto_helper_ops* ll_i2crpops(struct inode *inode)
603 {
604         return ll_i2crpi(inode)->ll_cops;
605 }
606
607 static inline struct crypto_helper_ops* ll_s2crpops(struct super_block *sb)
608 {
609         return ll_s2crpi(sb)->ll_cops;
610 }
611
612 static inline struct obd_export *ll_s2gsexp(struct super_block *sb)
613 {
614         struct ll_crypto_info *llci = ll_s2crpi(sb);
615         if (llci)
616                 return llci->ll_gt_exp;
617         return NULL;
618 }
619 static inline struct obd_export *ll_i2gsexp(struct inode *inode)
620 {
621         return ll_s2gsexp(inode->i_sb);
622 }
623
624 static inline
625 int ll_crypto_init_it_key(struct inode *inode, struct lookup_intent *it)
626 {
627         struct ll_crypto_info *lci = ll_i2crpi(inode);
628         if (lci) {
629                 struct crypto_helper_ops *ops = lci->ll_cops;;
630                 if (ops && ops->init_it_key)
631                         return ops->init_it_key(inode, it);
632         }
633         return 0;
634 }
635
636 static inline
637 int ll_crypto_create_key(struct inode *inode, mode_t mode, void **key,
638                          int* key_size)
639 {
640         struct ll_crypto_info *lci = ll_i2crpi(inode);
641         if (lci) {
642                 struct crypto_helper_ops *ops = lci->ll_cops;;
643                 if (ops && ops->create_key)
644                         return ops->create_key(inode, mode, key, key_size);
645         }
646         return 0;
647 }
648
649 static inline
650 int ll_crypto_get_mac(struct inode *inode, struct iattr *attr, void *acl,
651                       int acl_size, void **mac, int *mac_size)
652 {
653         struct ll_crypto_info *lci = ll_i2crpi(inode);
654         if (lci) {
655                 struct crypto_helper_ops *ops = lci->ll_cops;
656                 if (ops && ops->get_mac)
657                         return ops->get_mac(inode, attr, acl, acl_size,
658                                             mac, mac_size);
659         }
660         return 0;
661 }
662
663 static inline
664 int ll_crypto_decrypt_key(struct inode *inode, struct lookup_intent *it)
665 {
666         struct ll_crypto_info *lci = ll_i2crpi(inode);
667         if (lci) {
668                 struct crypto_helper_ops *ops = lci->ll_cops;
669                 if (ops && ops->decrypt_key)
670                         return ops->decrypt_key(inode, it);
671         }
672         return 0;
673 }
674
675 static inline
676 int ll_crypto_init_inode_key(struct inode *inode, void *md_key)
677 {
678         struct ll_crypto_info *lci = ll_i2crpi(inode);
679         if (lci) {
680                 struct crypto_helper_ops *ops = lci->ll_cops;
681                 if (ops && ops->init_inode_key)
682                         return ops->init_inode_key(inode, md_key);
683         }
684         return 0;
685 }
686
687 static inline
688 int ll_crypto_destroy_inode_key(struct inode *inode)
689 {
690         struct ll_crypto_info *lci = ll_i2crpi(inode);
691         if (lci) {
692                 struct crypto_helper_ops *ops = lci->ll_cops;
693                 if (ops && ops->destroy_key)
694                         return ops->destroy_key(inode);
695         }
696         return 0;
697 }
698
699 int lustre_init_crypto(struct super_block *sb, char *gkc,
700                        struct obd_connect_data *data, int async);
701 int lustre_destroy_crypto(struct super_block *sb);
702 int ll_set_sb_gksinfo(struct super_block *sb, char *type);
703 /* pass this flag to ll_md_real_close() to send close rpc right away */
704 #define FMODE_SYNC               00000010
705 #endif /* LLITE_INTERNAL_H */