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