1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33#ifndef LLITE_INTERNAL_H
34#define LLITE_INTERNAL_H
35#include "../include/lustre_debug.h"
36#include "../include/lustre_ver.h"
37#include "../include/lustre_disk.h"
38#include "../include/lustre_eacl.h"
39#include "../include/lustre_linkea.h"
40
41
42#include "../include/lustre_patchless_compat.h"
43#include "../include/lustre_compat.h"
44#include "../include/cl_object.h"
45#include "../include/lustre_lmv.h"
46#include "../include/lustre_mdc.h"
47#include "../include/lustre_intent.h"
48#include <linux/compat.h>
49#include <linux/namei.h>
50#include <linux/xattr.h>
51#include <linux/posix_acl_xattr.h>
52#include "vvp_internal.h"
53#include "range_lock.h"
54
55#ifndef FMODE_EXEC
56#define FMODE_EXEC 0
57#endif
58
59#ifndef VM_FAULT_RETRY
60#define VM_FAULT_RETRY 0
61#endif
62
63
64#define LL_DIR_END_OFF 0x7fffffffffffffffULL
65#define LL_DIR_END_OFF_32BIT 0x7fffffffUL
66
67
68#define LL_MAX_BLKSIZE_BITS 22
69
70#define LL_IT2STR(it) ((it) ? ldlm_it2str((it)->it_op) : "0")
71#define LUSTRE_FPRIVATE(file) ((file)->private_data)
72
73struct ll_dentry_data {
74 struct lookup_intent *lld_it;
75 unsigned int lld_sa_generation;
76 unsigned int lld_invalid:1;
77 unsigned int lld_nfs_dentry:1;
78 struct rcu_head lld_rcu_head;
79};
80
81#define ll_d2d(de) ((struct ll_dentry_data *)((de)->d_fsdata))
82
83#define LLI_INODE_MAGIC 0x111d0de5
84#define LLI_INODE_DEAD 0xdeadd00d
85
86struct ll_getname_data {
87 struct dir_context ctx;
88 char *lgd_name;
89 struct lu_fid lgd_fid;
90 int lgd_found;
91};
92
93struct ll_grouplock {
94 struct lu_env *lg_env;
95 struct cl_io *lg_io;
96 struct cl_lock *lg_lock;
97 unsigned long lg_gid;
98};
99
100enum lli_flags {
101
102 LLIF_MDS_SIZE_LOCK = (1 << 0),
103
104 LLIF_EPOCH_PENDING = (1 << 1),
105
106 LLIF_DONE_WRITING = (1 << 2),
107
108
109
110 LLIF_SOM_DIRTY = (1 << 3),
111
112 LLIF_DATA_MODIFIED = (1 << 4),
113
114 LLIF_FILE_RESTORING = (1 << 5),
115
116 LLIF_XATTR_CACHE = (1 << 6),
117};
118
119struct ll_inode_info {
120 __u32 lli_inode_magic;
121 __u32 lli_flags;
122 __u64 lli_ioepoch;
123
124 spinlock_t lli_lock;
125 struct posix_acl *lli_posix_acl;
126
127
128 struct lu_fid lli_fid;
129
130 struct lu_fid lli_pfid;
131
132 struct list_head lli_close_list;
133
134
135
136
137
138 struct obd_client_handle *lli_pending_och;
139
140
141
142
143 struct obd_client_handle *lli_mds_read_och;
144 struct obd_client_handle *lli_mds_write_och;
145 struct obd_client_handle *lli_mds_exec_och;
146 __u64 lli_open_fd_read_count;
147 __u64 lli_open_fd_write_count;
148 __u64 lli_open_fd_exec_count;
149
150 struct mutex lli_och_mutex;
151
152 struct inode lli_vfs_inode;
153
154
155 s64 lli_atime;
156 s64 lli_mtime;
157 s64 lli_ctime;
158 spinlock_t lli_agl_lock;
159
160
161
162
163 union {
164
165 struct {
166
167 struct mutex lli_readdir_mutex;
168
169
170
171
172
173
174
175 void *lli_opendir_key;
176 struct ll_statahead_info *lli_sai;
177
178 spinlock_t lli_sa_lock;
179
180
181
182 pid_t lli_opendir_pid;
183
184
185
186
187
188
189 unsigned int lli_sa_enabled:1;
190
191 unsigned int lli_sa_generation;
192
193 struct lmv_stripe_md *lli_lsm_md;
194
195
196
197
198
199
200 __u32 lli_def_stripe_offset;
201 };
202
203
204 struct {
205 struct mutex lli_size_mutex;
206 char *lli_symlink_name;
207 __u64 lli_maxbytes;
208
209
210
211
212
213
214
215 struct rw_semaphore lli_trunc_sem;
216 struct range_lock_tree lli_write_tree;
217
218 struct rw_semaphore lli_glimpse_sem;
219 unsigned long lli_glimpse_time;
220 struct list_head lli_agl_list;
221 __u64 lli_agl_index;
222
223
224 int lli_async_rc;
225
226
227
228
229
230
231
232
233
234 char lli_jobid[LUSTRE_JOBID_SIZE];
235 };
236 };
237
238
239
240
241
242
243
244
245
246
247
248 bool lli_has_smd;
249 struct cl_object *lli_clob;
250
251
252 struct mutex lli_layout_mutex;
253
254 __u32 lli_layout_gen;
255 spinlock_t lli_layout_lock;
256
257 struct rw_semaphore lli_xattrs_list_rwsem;
258 struct mutex lli_xattrs_enq_lock;
259 struct list_head lli_xattrs;
260};
261
262static inline __u32 ll_layout_version_get(struct ll_inode_info *lli)
263{
264 __u32 gen;
265
266 spin_lock(&lli->lli_layout_lock);
267 gen = lli->lli_layout_gen;
268 spin_unlock(&lli->lli_layout_lock);
269
270 return gen;
271}
272
273static inline void ll_layout_version_set(struct ll_inode_info *lli, __u32 gen)
274{
275 spin_lock(&lli->lli_layout_lock);
276 lli->lli_layout_gen = gen;
277 spin_unlock(&lli->lli_layout_lock);
278}
279
280int ll_xattr_cache_destroy(struct inode *inode);
281
282int ll_xattr_cache_get(struct inode *inode, const char *name,
283 char *buffer, size_t size, __u64 valid);
284
285
286
287
288
289
290
291
292void ll_inode_size_lock(struct inode *inode);
293void ll_inode_size_unlock(struct inode *inode);
294
295
296
297static inline struct ll_inode_info *ll_i2info(struct inode *inode)
298{
299 return container_of(inode, struct ll_inode_info, lli_vfs_inode);
300}
301
302
303
304
305#define SBI_DEFAULT_READAHEAD_MAX (40UL << (20 - PAGE_SHIFT))
306
307
308#define SBI_DEFAULT_READAHEAD_WHOLE_MAX (2UL << (20 - PAGE_SHIFT))
309
310enum ra_stat {
311 RA_STAT_HIT = 0,
312 RA_STAT_MISS,
313 RA_STAT_DISTANT_READPAGE,
314 RA_STAT_MISS_IN_WINDOW,
315 RA_STAT_FAILED_GRAB_PAGE,
316 RA_STAT_FAILED_MATCH,
317 RA_STAT_DISCARDED,
318 RA_STAT_ZERO_LEN,
319 RA_STAT_ZERO_WINDOW,
320 RA_STAT_EOF,
321 RA_STAT_MAX_IN_FLIGHT,
322 RA_STAT_WRONG_GRAB_PAGE,
323 RA_STAT_FAILED_REACH_END,
324 _NR_RA_STAT,
325};
326
327struct ll_ra_info {
328 atomic_t ra_cur_pages;
329 unsigned long ra_max_pages;
330 unsigned long ra_max_pages_per_file;
331 unsigned long ra_max_read_ahead_whole_pages;
332};
333
334
335
336
337
338
339struct ra_io_arg {
340 unsigned long ria_start;
341 unsigned long ria_end;
342
343
344
345
346 pgoff_t ria_stoff;
347
348
349
350
351 unsigned long ria_length;
352 unsigned long ria_pages;
353};
354
355
356#define LL_HIST_MAX 28
357#define LL_HIST_START 12
358#define LL_PROCESS_HIST_MAX 10
359struct per_process_info {
360 pid_t pid;
361 struct obd_histogram pp_r_hist;
362 struct obd_histogram pp_w_hist;
363};
364
365
366struct ll_rw_extents_info {
367 struct per_process_info pp_extents[LL_PROCESS_HIST_MAX + 1];
368};
369
370#define LL_OFFSET_HIST_MAX 100
371struct ll_rw_process_info {
372 pid_t rw_pid;
373 int rw_op;
374 loff_t rw_range_start;
375 loff_t rw_range_end;
376 loff_t rw_last_file_pos;
377 loff_t rw_offset;
378 size_t rw_smallest_extent;
379 size_t rw_largest_extent;
380 struct ll_file_data *rw_last_file;
381};
382
383enum stats_track_type {
384 STATS_TRACK_ALL = 0,
385 STATS_TRACK_PID,
386 STATS_TRACK_PPID,
387 STATS_TRACK_GID,
388 STATS_TRACK_LAST,
389};
390
391
392#define LL_SBI_NOLCK 0x01
393#define LL_SBI_CHECKSUM 0x02
394#define LL_SBI_FLOCK 0x04
395#define LL_SBI_USER_XATTR 0x08
396#define LL_SBI_ACL 0x10
397
398#define LL_SBI_MDS_CAPA 0x80
399#define LL_SBI_OSS_CAPA 0x100
400#define LL_SBI_LOCALFLOCK 0x200
401#define LL_SBI_LRU_RESIZE 0x400
402#define LL_SBI_LAZYSTATFS 0x800
403#define LL_SBI_SOM_PREVIEW 0x1000
404#define LL_SBI_32BIT_API 0x2000
405#define LL_SBI_64BIT_HASH 0x4000
406#define LL_SBI_AGL_ENABLED 0x8000
407#define LL_SBI_VERBOSE 0x10000
408#define LL_SBI_LAYOUT_LOCK 0x20000
409#define LL_SBI_USER_FID2PATH 0x40000
410#define LL_SBI_XATTR_CACHE 0x80000
411#define LL_SBI_NOROOTSQUASH 0x100000
412
413#define LL_SBI_FLAGS { \
414 "nolck", \
415 "checksum", \
416 "flock", \
417 "user_xattr", \
418 "acl", \
419 "???", \
420 "???", \
421 "mds_capa", \
422 "oss_capa", \
423 "flock", \
424 "lru_resize", \
425 "lazy_statfs", \
426 "som", \
427 "32bit_api", \
428 "64bit_hash", \
429 "agl", \
430 "verbose", \
431 "layout", \
432 "user_fid2path",\
433 "xattr_cache", \
434 "norootsquash", \
435}
436
437
438
439
440
441
442struct lustre_client_ocd {
443
444
445
446
447
448 __u64 lco_flags;
449 struct mutex lco_lock;
450 struct obd_export *lco_md_exp;
451 struct obd_export *lco_dt_exp;
452};
453
454struct ll_sb_info {
455
456
457
458 spinlock_t ll_lock;
459 spinlock_t ll_pp_extent_lock;
460 spinlock_t ll_process_lock;
461 struct obd_uuid ll_sb_uuid;
462 struct obd_export *ll_md_exp;
463 struct obd_export *ll_dt_exp;
464 struct dentry *ll_debugfs_entry;
465 struct lu_fid ll_root_fid;
466
467 int ll_flags;
468 unsigned int ll_umounting:1,
469 ll_xattr_cache_enabled:1;
470 struct lustre_client_ocd ll_lco;
471
472 struct ll_close_queue *ll_lcq;
473
474 struct lprocfs_stats *ll_stats;
475
476
477
478
479
480
481
482 struct cl_client_cache *ll_cache;
483
484 struct lprocfs_stats *ll_ra_stats;
485
486 struct ll_ra_info ll_ra_info;
487 unsigned int ll_namelen;
488 struct file_operations *ll_fop;
489
490 unsigned int ll_md_brw_pages;
491
492 struct lu_site *ll_site;
493 struct cl_device *ll_cl;
494
495 struct ll_rw_extents_info ll_rw_extents_info;
496 int ll_extent_process_count;
497 struct ll_rw_process_info ll_rw_process_info[LL_PROCESS_HIST_MAX];
498 unsigned int ll_offset_process_count;
499 struct ll_rw_process_info ll_rw_offset_info[LL_OFFSET_HIST_MAX];
500 unsigned int ll_rw_offset_entry_count;
501 int ll_stats_track_id;
502 enum stats_track_type ll_stats_track_type;
503 int ll_rw_stats_on;
504
505
506 unsigned int ll_sa_max;
507 atomic_t ll_sa_total;
508
509
510 atomic_t ll_sa_wrong;
511
512
513 atomic_t ll_sa_running;
514
515
516 atomic_t ll_agl_total;
517
518 dev_t ll_sdev_orig;
519
520
521
522 struct root_squash_info ll_squash;
523
524 __kernel_fsid_t ll_fsid;
525 struct kobject ll_kobj;
526 struct super_block *ll_sb;
527 struct completion ll_kobj_unregister;
528};
529
530
531
532
533struct ll_readahead_state {
534 spinlock_t ras_lock;
535
536
537
538
539
540
541
542 unsigned long ras_last_readpage;
543
544
545
546
547
548
549
550
551
552
553 unsigned long ras_consecutive_pages;
554
555
556
557
558
559 unsigned long ras_consecutive_requests;
560
561
562
563
564
565
566
567 unsigned long ras_window_start, ras_window_len;
568
569
570
571
572
573
574
575 unsigned long ras_next_readahead;
576
577
578
579
580
581 unsigned long ras_requests;
582
583
584
585
586 unsigned long ras_request_index;
587
588
589
590
591
592
593
594
595
596
597
598 unsigned long ras_stride_length;
599 unsigned long ras_stride_pages;
600 pgoff_t ras_stride_offset;
601
602
603
604
605
606
607 unsigned long ras_consecutive_stride_requests;
608};
609
610extern struct kmem_cache *ll_file_data_slab;
611struct lustre_handle;
612struct ll_file_data {
613 struct ll_readahead_state fd_ras;
614 struct ll_grouplock fd_grouplock;
615 __u64 lfd_pos;
616 __u32 fd_flags;
617 fmode_t fd_omode;
618
619
620
621 struct obd_client_handle *fd_lease_och;
622 struct obd_client_handle *fd_och;
623 struct file *fd_file;
624
625
626
627
628 bool fd_write_failed;
629 rwlock_t fd_lock;
630 struct list_head fd_lccs;
631};
632
633struct lov_stripe_md;
634
635extern struct dentry *llite_root;
636extern struct kset *llite_kset;
637
638static inline struct inode *ll_info2i(struct ll_inode_info *lli)
639{
640 return &lli->lli_vfs_inode;
641}
642
643__u32 ll_i2suppgid(struct inode *i);
644void ll_i2gids(__u32 *suppgids, struct inode *i1, struct inode *i2);
645
646static inline int ll_need_32bit_api(struct ll_sb_info *sbi)
647{
648#if BITS_PER_LONG == 32
649 return 1;
650#elif defined(CONFIG_COMPAT)
651 return unlikely(in_compat_syscall() || (sbi->ll_flags & LL_SBI_32BIT_API));
652#else
653 return unlikely(sbi->ll_flags & LL_SBI_32BIT_API);
654#endif
655}
656
657void ll_ras_enter(struct file *f);
658
659
660int cl_init_ea_size(struct obd_export *md_exp, struct obd_export *dt_exp);
661int cl_ocd_update(struct obd_device *host,
662 struct obd_device *watched,
663 enum obd_notify_event ev, void *owner, void *data);
664int cl_get_grouplock(struct cl_object *obj, unsigned long gid, int nonblock,
665 struct ll_grouplock *cg);
666void cl_put_grouplock(struct ll_grouplock *cg);
667
668
669int ldebugfs_register_mountpoint(struct dentry *parent,
670 struct super_block *sb, char *osc, char *mdc);
671void ldebugfs_unregister_mountpoint(struct ll_sb_info *sbi);
672void ll_stats_ops_tally(struct ll_sb_info *sbi, int op, int count);
673void lprocfs_llite_init_vars(struct lprocfs_static_vars *lvars);
674void ll_rw_stats_tally(struct ll_sb_info *sbi, pid_t pid,
675 struct ll_file_data *file, loff_t pos,
676 size_t count, int rw);
677
678enum {
679 LPROC_LL_DIRTY_HITS,
680 LPROC_LL_DIRTY_MISSES,
681 LPROC_LL_READ_BYTES,
682 LPROC_LL_WRITE_BYTES,
683 LPROC_LL_BRW_READ,
684 LPROC_LL_BRW_WRITE,
685 LPROC_LL_OSC_READ,
686 LPROC_LL_OSC_WRITE,
687 LPROC_LL_IOCTL,
688 LPROC_LL_OPEN,
689 LPROC_LL_RELEASE,
690 LPROC_LL_MAP,
691 LPROC_LL_LLSEEK,
692 LPROC_LL_FSYNC,
693 LPROC_LL_READDIR,
694 LPROC_LL_SETATTR,
695 LPROC_LL_TRUNC,
696 LPROC_LL_FLOCK,
697 LPROC_LL_GETATTR,
698 LPROC_LL_CREATE,
699 LPROC_LL_LINK,
700 LPROC_LL_UNLINK,
701 LPROC_LL_SYMLINK,
702 LPROC_LL_MKDIR,
703 LPROC_LL_RMDIR,
704 LPROC_LL_MKNOD,
705 LPROC_LL_RENAME,
706 LPROC_LL_STAFS,
707 LPROC_LL_ALLOC_INODE,
708 LPROC_LL_SETXATTR,
709 LPROC_LL_GETXATTR,
710 LPROC_LL_GETXATTR_HITS,
711 LPROC_LL_LISTXATTR,
712 LPROC_LL_REMOVEXATTR,
713 LPROC_LL_INODE_PERM,
714 LPROC_LL_FILE_OPCODES
715};
716
717
718extern const struct file_operations ll_dir_operations;
719extern const struct inode_operations ll_dir_inode_operations;
720int ll_dir_read(struct inode *inode, __u64 *ppos, struct md_op_data *op_data,
721 struct dir_context *ctx);
722int ll_get_mdt_idx(struct inode *inode);
723int ll_get_mdt_idx_by_fid(struct ll_sb_info *sbi, const struct lu_fid *fid);
724struct page *ll_get_dir_page(struct inode *dir, struct md_op_data *op_data,
725 __u64 offset);
726void ll_release_page(struct inode *inode, struct page *page, bool remove);
727
728
729extern const struct inode_operations ll_special_inode_operations;
730
731struct inode *ll_iget(struct super_block *sb, ino_t hash,
732 struct lustre_md *lic);
733int ll_test_inode_by_fid(struct inode *inode, void *opaque);
734int ll_md_blocking_ast(struct ldlm_lock *, struct ldlm_lock_desc *,
735 void *data, int flag);
736struct dentry *ll_splice_alias(struct inode *inode, struct dentry *de);
737void ll_update_times(struct ptlrpc_request *request, struct inode *inode);
738
739
740int ll_writepage(struct page *page, struct writeback_control *wbc);
741int ll_writepages(struct address_space *, struct writeback_control *wbc);
742int ll_readpage(struct file *file, struct page *page);
743void ll_readahead_init(struct inode *inode, struct ll_readahead_state *ras);
744int ll_readahead(const struct lu_env *env, struct cl_io *io,
745 struct cl_page_list *queue, struct ll_readahead_state *ras,
746 bool hit);
747struct ll_cl_context *ll_cl_find(struct file *file);
748void ll_cl_add(struct file *file, const struct lu_env *env, struct cl_io *io);
749void ll_cl_remove(struct file *file, const struct lu_env *env);
750
751extern const struct address_space_operations ll_aops;
752
753
754extern struct file_operations ll_file_operations;
755extern struct file_operations ll_file_operations_flock;
756extern struct file_operations ll_file_operations_noflock;
757extern const struct inode_operations ll_file_inode_operations;
758int ll_have_md_lock(struct inode *inode, __u64 *bits,
759 enum ldlm_mode l_req_mode);
760enum ldlm_mode ll_take_md_lock(struct inode *inode, __u64 bits,
761 struct lustre_handle *lockh, __u64 flags,
762 enum ldlm_mode mode);
763int ll_file_open(struct inode *inode, struct file *file);
764int ll_file_release(struct inode *inode, struct file *file);
765int ll_glimpse_ioctl(struct ll_sb_info *sbi,
766 struct lov_stripe_md *lsm, lstat_t *st);
767void ll_ioepoch_open(struct ll_inode_info *lli, __u64 ioepoch);
768int ll_release_openhandle(struct inode *, struct lookup_intent *);
769int ll_md_real_close(struct inode *inode, fmode_t fmode);
770void ll_ioepoch_close(struct inode *inode, struct md_op_data *op_data,
771 struct obd_client_handle **och, unsigned long flags);
772void ll_done_writing_attr(struct inode *inode, struct md_op_data *op_data);
773int ll_som_update(struct inode *inode, struct md_op_data *op_data);
774int ll_inode_getattr(struct inode *inode, struct obdo *obdo,
775 __u64 ioepoch, int sync);
776void ll_pack_inode2opdata(struct inode *inode, struct md_op_data *op_data,
777 struct lustre_handle *fh);
778int ll_getattr(struct vfsmount *mnt, struct dentry *de, struct kstat *stat);
779struct posix_acl *ll_get_acl(struct inode *inode, int type);
780int ll_migrate(struct inode *parent, struct file *file, int mdtidx,
781 const char *name, int namelen);
782int ll_get_fid_by_name(struct inode *parent, const char *name,
783 int namelen, struct lu_fid *fid);
784int ll_inode_permission(struct inode *inode, int mask);
785
786int ll_lov_setstripe_ea_info(struct inode *inode, struct dentry *dentry,
787 __u64 flags, struct lov_user_md *lum,
788 int lum_size);
789int ll_lov_getstripe_ea_info(struct inode *inode, const char *filename,
790 struct lov_mds_md **lmm, int *lmm_size,
791 struct ptlrpc_request **request);
792int ll_dir_setstripe(struct inode *inode, struct lov_user_md *lump,
793 int set_default);
794int ll_dir_getstripe(struct inode *inode, void **lmmp, int *lmm_size,
795 struct ptlrpc_request **request, u64 valid);
796int ll_fsync(struct file *file, loff_t start, loff_t end, int data);
797int ll_merge_attr(const struct lu_env *env, struct inode *inode);
798int ll_fid2path(struct inode *inode, void __user *arg);
799int ll_data_version(struct inode *inode, __u64 *data_version, int flags);
800int ll_hsm_release(struct inode *inode);
801
802
803
804int ll_d_init(struct dentry *de);
805extern const struct dentry_operations ll_d_ops;
806void ll_intent_drop_lock(struct lookup_intent *);
807void ll_intent_release(struct lookup_intent *);
808void ll_invalidate_aliases(struct inode *);
809void ll_lookup_finish_locks(struct lookup_intent *it, struct inode *inode);
810int ll_revalidate_it_finish(struct ptlrpc_request *request,
811 struct lookup_intent *it, struct inode *inode);
812
813
814extern struct super_operations lustre_super_operations;
815
816void ll_lli_init(struct ll_inode_info *lli);
817int ll_fill_super(struct super_block *sb, struct vfsmount *mnt);
818void ll_put_super(struct super_block *sb);
819void ll_kill_super(struct super_block *sb);
820struct inode *ll_inode_from_resource_lock(struct ldlm_lock *lock);
821void ll_clear_inode(struct inode *inode);
822int ll_setattr_raw(struct dentry *dentry, struct iattr *attr, bool hsm_import);
823int ll_setattr(struct dentry *de, struct iattr *attr);
824int ll_statfs(struct dentry *de, struct kstatfs *sfs);
825int ll_statfs_internal(struct super_block *sb, struct obd_statfs *osfs,
826 __u64 max_age, __u32 flags);
827int ll_update_inode(struct inode *inode, struct lustre_md *md);
828int ll_read_inode2(struct inode *inode, void *opaque);
829void ll_delete_inode(struct inode *inode);
830int ll_iocontrol(struct inode *inode, struct file *file,
831 unsigned int cmd, unsigned long arg);
832int ll_flush_ctx(struct inode *inode);
833void ll_umount_begin(struct super_block *sb);
834int ll_remount_fs(struct super_block *sb, int *flags, char *data);
835int ll_show_options(struct seq_file *seq, struct dentry *dentry);
836void ll_dirty_page_discard_warn(struct page *page, int ioret);
837int ll_prep_inode(struct inode **inode, struct ptlrpc_request *req,
838 struct super_block *, struct lookup_intent *);
839int ll_obd_statfs(struct inode *inode, void __user *arg);
840int ll_get_max_mdsize(struct ll_sb_info *sbi, int *max_mdsize);
841int ll_get_default_mdsize(struct ll_sb_info *sbi, int *default_mdsize);
842int ll_set_default_mdsize(struct ll_sb_info *sbi, int default_mdsize);
843int ll_process_config(struct lustre_cfg *lcfg);
844
845enum {
846 LUSTRE_OPC_MKDIR = 0,
847 LUSTRE_OPC_SYMLINK = 1,
848 LUSTRE_OPC_MKNOD = 2,
849 LUSTRE_OPC_CREATE = 3,
850 LUSTRE_OPC_ANY = 5,
851};
852
853struct md_op_data *ll_prep_md_op_data(struct md_op_data *op_data,
854 struct inode *i1, struct inode *i2,
855 const char *name, size_t namelen,
856 u32 mode, __u32 opc, void *data);
857void ll_finish_md_op_data(struct md_op_data *op_data);
858int ll_get_obd_name(struct inode *inode, unsigned int cmd, unsigned long arg);
859char *ll_get_fsname(struct super_block *sb, char *buf, int buflen);
860void ll_compute_rootsquash_state(struct ll_sb_info *sbi);
861void ll_open_cleanup(struct super_block *sb, struct ptlrpc_request *open_req);
862ssize_t ll_copy_user_md(const struct lov_user_md __user *md,
863 struct lov_user_md **kbuf);
864
865
866static inline ssize_t ll_lov_user_md_size(const struct lov_user_md *lum)
867{
868 switch (lum->lmm_magic) {
869 case LOV_USER_MAGIC_V1:
870 return sizeof(struct lov_user_md_v1);
871 case LOV_USER_MAGIC_V3:
872 return sizeof(struct lov_user_md_v3);
873 case LOV_USER_MAGIC_SPECIFIC:
874 if (lum->lmm_stripe_count > LOV_MAX_STRIPE_COUNT)
875 return -EINVAL;
876
877 return lov_user_md_size(lum->lmm_stripe_count,
878 LOV_USER_MAGIC_SPECIFIC);
879 }
880 return -EINVAL;
881}
882
883
884extern const struct export_operations lustre_export_operations;
885__u32 get_uuid2int(const char *name, int len);
886void get_uuid2fsid(const char *name, int len, __kernel_fsid_t *fsid);
887struct inode *search_inode_for_lustre(struct super_block *sb,
888 const struct lu_fid *fid);
889int ll_dir_get_parent_fid(struct inode *dir, struct lu_fid *parent_fid);
890
891
892extern const struct inode_operations ll_fast_symlink_inode_operations;
893
894
895struct ll_close_queue {
896 spinlock_t lcq_lock;
897 struct list_head lcq_head;
898 wait_queue_head_t lcq_waitq;
899 struct completion lcq_comp;
900 atomic_t lcq_stop;
901};
902
903void vvp_write_pending(struct vvp_object *club, struct vvp_page *page);
904void vvp_write_complete(struct vvp_object *club, struct vvp_page *page);
905
906
907
908
909struct vvp_io_args {
910
911 union {
912 struct {
913 struct kiocb *via_iocb;
914 struct iov_iter *via_iter;
915 } normal;
916 } u;
917};
918
919struct ll_cl_context {
920 struct list_head lcc_list;
921 void *lcc_cookie;
922 const struct lu_env *lcc_env;
923 struct cl_io *lcc_io;
924 struct cl_page *lcc_page;
925};
926
927struct ll_thread_info {
928 struct vvp_io_args lti_args;
929 struct ra_io_arg lti_ria;
930 struct ll_cl_context lti_io_ctx;
931};
932
933extern struct lu_context_key ll_thread_key;
934static inline struct ll_thread_info *ll_env_info(const struct lu_env *env)
935{
936 struct ll_thread_info *lti;
937
938 lti = lu_context_key_get(&env->le_ctx, &ll_thread_key);
939 LASSERT(lti);
940 return lti;
941}
942
943static inline struct vvp_io_args *ll_env_args(const struct lu_env *env)
944{
945 return &ll_env_info(env)->lti_args;
946}
947
948void ll_queue_done_writing(struct inode *inode, unsigned long flags);
949void ll_close_thread_shutdown(struct ll_close_queue *lcq);
950int ll_close_thread_start(struct ll_close_queue **lcq_ret);
951
952
953
954int ll_teardown_mmaps(struct address_space *mapping, __u64 first, __u64 last);
955int ll_file_mmap(struct file *file, struct vm_area_struct *vma);
956void policy_from_vma(ldlm_policy_data_t *policy, struct vm_area_struct *vma,
957 unsigned long addr, size_t count);
958struct vm_area_struct *our_vma(struct mm_struct *mm, unsigned long addr,
959 size_t count);
960
961static inline void ll_invalidate_page(struct page *vmpage)
962{
963 struct address_space *mapping = vmpage->mapping;
964 loff_t offset = vmpage->index << PAGE_SHIFT;
965
966 LASSERT(PageLocked(vmpage));
967 if (!mapping)
968 return;
969
970
971
972
973
974 ll_teardown_mmaps(mapping, offset, offset + PAGE_SIZE);
975 truncate_complete_page(mapping, vmpage);
976}
977
978#define ll_s2sbi(sb) (s2lsi(sb)->lsi_llsbi)
979
980
981static inline struct obd_export *ll_s2dtexp(struct super_block *sb)
982{
983 return ll_s2sbi(sb)->ll_dt_exp;
984}
985
986
987static inline struct obd_export *ll_s2mdexp(struct super_block *sb)
988{
989 return ll_s2sbi(sb)->ll_md_exp;
990}
991
992static inline struct client_obd *sbi2mdc(struct ll_sb_info *sbi)
993{
994 struct obd_device *obd = sbi->ll_md_exp->exp_obd;
995
996 if (!obd)
997 LBUG();
998 return &obd->u.cli;
999}
1000
1001
1002static inline struct ll_sb_info *ll_i2sbi(struct inode *inode)
1003{
1004 return ll_s2sbi(inode->i_sb);
1005}
1006
1007static inline struct obd_export *ll_i2dtexp(struct inode *inode)
1008{
1009 return ll_s2dtexp(inode->i_sb);
1010}
1011
1012static inline struct obd_export *ll_i2mdexp(struct inode *inode)
1013{
1014 return ll_s2mdexp(inode->i_sb);
1015}
1016
1017static inline struct lu_fid *ll_inode2fid(struct inode *inode)
1018{
1019 struct lu_fid *fid;
1020
1021 LASSERT(inode);
1022 fid = &ll_i2info(inode)->lli_fid;
1023
1024 return fid;
1025}
1026
1027static inline __u64 ll_file_maxbytes(struct inode *inode)
1028{
1029 return ll_i2info(inode)->lli_maxbytes;
1030}
1031
1032
1033extern const struct xattr_handler *ll_xattr_handlers[];
1034
1035#define XATTR_USER_T 1
1036#define XATTR_TRUSTED_T 2
1037#define XATTR_SECURITY_T 3
1038#define XATTR_ACL_ACCESS_T 4
1039#define XATTR_ACL_DEFAULT_T 5
1040#define XATTR_LUSTRE_T 6
1041#define XATTR_OTHER_T 7
1042
1043ssize_t ll_listxattr(struct dentry *dentry, char *buffer, size_t size);
1044int ll_xattr_list(struct inode *inode, const char *name, int type,
1045 void *buffer, size_t size, __u64 valid);
1046
1047
1048
1049
1050int cl_sb_init(struct super_block *sb);
1051int cl_sb_fini(struct super_block *sb);
1052void ll_io_init(struct cl_io *io, const struct file *file, int write);
1053
1054void ras_update(struct ll_sb_info *sbi, struct inode *inode,
1055 struct ll_readahead_state *ras, unsigned long index,
1056 unsigned hit);
1057void ll_ra_count_put(struct ll_sb_info *sbi, unsigned long len);
1058void ll_ra_stats_inc(struct inode *inode, enum ra_stat which);
1059
1060
1061#define LL_SA_RPC_MIN 2
1062#define LL_SA_RPC_DEF 32
1063#define LL_SA_RPC_MAX 8192
1064
1065#define LL_SA_CACHE_BIT 5
1066#define LL_SA_CACHE_SIZE (1 << LL_SA_CACHE_BIT)
1067#define LL_SA_CACHE_MASK (LL_SA_CACHE_SIZE - 1)
1068
1069
1070struct ll_statahead_info {
1071 struct dentry *sai_dentry;
1072 atomic_t sai_refcount;
1073
1074
1075 unsigned int sai_max;
1076 __u64 sai_sent;
1077 __u64 sai_replied;
1078
1079
1080 __u64 sai_index;
1081 __u64 sai_index_wait;
1082
1083
1084 __u64 sai_hit;
1085 __u64 sai_miss;
1086
1087
1088
1089
1090
1091
1092
1093 unsigned int sai_consecutive_miss;
1094 unsigned int sai_miss_hidden;
1095
1096
1097 unsigned int sai_skip_hidden;
1098 unsigned int sai_ls_all:1,
1099
1100
1101 sai_agl_valid:1,
1102 sai_in_readpage:1;
1103 wait_queue_head_t sai_waitq;
1104 struct ptlrpc_thread sai_thread;
1105 struct ptlrpc_thread sai_agl_thread;
1106 struct list_head sai_interim_entries;
1107
1108
1109
1110 struct list_head sai_entries;
1111 struct list_head sai_agls;
1112 struct list_head sai_cache[LL_SA_CACHE_SIZE];
1113 spinlock_t sai_cache_lock[LL_SA_CACHE_SIZE];
1114 atomic_t sai_cache_count;
1115};
1116
1117int ll_statahead(struct inode *dir, struct dentry **dentry, bool unplug);
1118void ll_authorize_statahead(struct inode *dir, void *key);
1119void ll_deauthorize_statahead(struct inode *dir, void *key);
1120
1121blkcnt_t dirty_cnt(struct inode *inode);
1122
1123int cl_glimpse_size0(struct inode *inode, int agl);
1124int cl_glimpse_lock(const struct lu_env *env, struct cl_io *io,
1125 struct inode *inode, struct cl_object *clob, int agl);
1126
1127static inline int cl_glimpse_size(struct inode *inode)
1128{
1129 return cl_glimpse_size0(inode, 0);
1130}
1131
1132static inline int cl_agl(struct inode *inode)
1133{
1134 return cl_glimpse_size0(inode, 1);
1135}
1136
1137static inline int ll_glimpse_size(struct inode *inode)
1138{
1139 struct ll_inode_info *lli = ll_i2info(inode);
1140 int rc;
1141
1142 down_read(&lli->lli_glimpse_sem);
1143 rc = cl_glimpse_size(inode);
1144 lli->lli_glimpse_time = cfs_time_current();
1145 up_read(&lli->lli_glimpse_sem);
1146 return rc;
1147}
1148
1149
1150
1151
1152
1153static inline bool
1154dentry_may_statahead(struct inode *dir, struct dentry *dentry)
1155{
1156 struct ll_inode_info *lli;
1157 struct ll_dentry_data *ldd;
1158
1159 if (ll_i2sbi(dir)->ll_sa_max == 0)
1160 return false;
1161
1162 lli = ll_i2info(dir);
1163
1164
1165
1166
1167
1168
1169
1170 if (!lli->lli_sa_enabled)
1171 return false;
1172
1173
1174 if (lli->lli_opendir_pid != current_pid())
1175 return false;
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191 ldd = ll_d2d(dentry);
1192 if (ldd && ldd->lld_sa_generation == lli->lli_sa_generation)
1193 return false;
1194
1195 return true;
1196}
1197
1198
1199enum llioc_iter {
1200 LLIOC_CONT = 0,
1201 LLIOC_STOP
1202};
1203
1204#define LLIOC_MAX_CMD 256
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220typedef enum llioc_iter (*llioc_callback_t)(struct inode *inode,
1221 struct file *file, unsigned int cmd, unsigned long arg,
1222 void *magic, int *rcp);
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236void *ll_iocontrol_register(llioc_callback_t cb, int count, unsigned int *cmd);
1237void ll_iocontrol_unregister(void *magic);
1238
1239int cl_sync_file_range(struct inode *inode, loff_t start, loff_t end,
1240 enum cl_fsync_mode mode, int ignore_layout);
1241
1242
1243struct ll_dio_pages {
1244
1245
1246
1247 struct page **ldp_pages;
1248
1249 loff_t *ldp_offsets;
1250
1251
1252
1253
1254 loff_t ldp_start_offset;
1255
1256 size_t ldp_size;
1257
1258 int ldp_nr;
1259};
1260
1261static inline void cl_stats_tally(struct cl_device *dev, enum cl_req_type crt,
1262 int rc)
1263{
1264 int opc = (crt == CRT_READ) ? LPROC_LL_OSC_READ :
1265 LPROC_LL_OSC_WRITE;
1266
1267 ll_stats_ops_tally(ll_s2sbi(cl2vvp_dev(dev)->vdv_sb), opc, rc);
1268}
1269
1270ssize_t ll_direct_rw_pages(const struct lu_env *env, struct cl_io *io,
1271 int rw, struct inode *inode,
1272 struct ll_dio_pages *pv);
1273
1274static inline int ll_file_nolock(const struct file *file)
1275{
1276 struct ll_file_data *fd = LUSTRE_FPRIVATE(file);
1277 struct inode *inode = file_inode(file);
1278
1279 return ((fd->fd_flags & LL_FILE_IGNORE_LOCK) ||
1280 (ll_i2sbi(inode)->ll_flags & LL_SBI_NOLCK));
1281}
1282
1283static inline void ll_set_lock_data(struct obd_export *exp, struct inode *inode,
1284 struct lookup_intent *it, __u64 *bits)
1285{
1286 if (!it->it_lock_set) {
1287 struct lustre_handle handle;
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297 if (it->it_remote_lock_mode) {
1298 handle.cookie = it->it_remote_lock_handle;
1299 CDEBUG(D_DLMTRACE, "setting l_data to inode "DFID"%p for remote lock %#llx\n",
1300 PFID(ll_inode2fid(inode)), inode,
1301 handle.cookie);
1302 md_set_lock_data(exp, &handle, inode, NULL);
1303 }
1304
1305 handle.cookie = it->it_lock_handle;
1306
1307 CDEBUG(D_DLMTRACE, "setting l_data to inode "DFID"%p for lock %#llx\n",
1308 PFID(ll_inode2fid(inode)), inode, handle.cookie);
1309
1310 md_set_lock_data(exp, &handle, inode, &it->it_lock_bits);
1311 it->it_lock_set = 1;
1312 }
1313
1314 if (bits)
1315 *bits = it->it_lock_bits;
1316}
1317
1318static inline int d_lustre_invalid(const struct dentry *dentry)
1319{
1320 struct ll_dentry_data *lld = ll_d2d(dentry);
1321
1322 return !lld || lld->lld_invalid;
1323}
1324
1325static inline void __d_lustre_invalidate(struct dentry *dentry)
1326{
1327 struct ll_dentry_data *lld = ll_d2d(dentry);
1328
1329 if (lld)
1330 lld->lld_invalid = 1;
1331}
1332
1333
1334
1335
1336
1337
1338static inline void d_lustre_invalidate(struct dentry *dentry, int nested)
1339{
1340 CDEBUG(D_DENTRY, "invalidate dentry %pd (%p) parent %p inode %p refc %d\n",
1341 dentry, dentry,
1342 dentry->d_parent, d_inode(dentry), d_count(dentry));
1343
1344 spin_lock_nested(&dentry->d_lock,
1345 nested ? DENTRY_D_LOCK_NESTED : DENTRY_D_LOCK_NORMAL);
1346 __d_lustre_invalidate(dentry);
1347
1348
1349
1350
1351
1352
1353
1354
1355 if (d_count(dentry) == 0 && !(dentry->d_flags & DCACHE_DISCONNECTED))
1356 __d_drop(dentry);
1357 spin_unlock(&dentry->d_lock);
1358}
1359
1360static inline void d_lustre_revalidate(struct dentry *dentry)
1361{
1362 spin_lock(&dentry->d_lock);
1363 LASSERT(ll_d2d(dentry));
1364 ll_d2d(dentry)->lld_invalid = 0;
1365 spin_unlock(&dentry->d_lock);
1366}
1367
1368enum {
1369 LL_LAYOUT_GEN_NONE = ((__u32)-2),
1370 LL_LAYOUT_GEN_EMPTY = ((__u32)-1)
1371};
1372
1373int ll_layout_conf(struct inode *inode, const struct cl_object_conf *conf);
1374int ll_layout_refresh(struct inode *inode, __u32 *gen);
1375int ll_layout_restore(struct inode *inode, loff_t start, __u64 length);
1376
1377int ll_xattr_init(void);
1378void ll_xattr_fini(void);
1379
1380int ll_page_sync_io(const struct lu_env *env, struct cl_io *io,
1381 struct cl_page *page, enum cl_req_type crt);
1382
1383int ll_getparent(struct file *file, struct getparent __user *arg);
1384
1385
1386int cl_setattr_ost(struct inode *inode, const struct iattr *attr);
1387
1388extern struct lu_env *cl_inode_fini_env;
1389extern int cl_inode_fini_refcheck;
1390
1391int cl_file_inode_init(struct inode *inode, struct lustre_md *md);
1392void cl_inode_fini(struct inode *inode);
1393int cl_local_size(struct inode *inode);
1394
1395__u64 cl_fid_build_ino(const struct lu_fid *fid, int api32);
1396__u32 cl_fid_build_gen(const struct lu_fid *fid);
1397
1398#endif
1399