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