Whamcloud - gitweb
Update snapfs
[fs/lustre-release.git] / lustre / include / linux / lvfs.h
1 #ifndef __LVFS_H__
2 #define __LVFS_H__
3
4 #include <linux/kp30.h>
5
6 #define LL_FID_NAMELEN  (16 + 1 + 8 + 1)
7
8 #if defined __KERNEL__
9 #include <linux/lvfs_linux.h>
10 #endif 
11
12 #ifdef LIBLUSTRE
13 #include <lvfs_user_fs.h>
14 #endif
15
16 /* simple.c */
17 struct lvfs_ucred {
18         __u32 luc_fsuid;
19         __u32 luc_fsgid;
20         __u32 luc_cap;
21         __u32 luc_suppgid1;
22         __u32 luc_suppgid2;
23 };
24
25 struct lvfs_callback_ops {
26         struct dentry *(*l_fid2dentry)(__u64 id_ino, __u32 gen, __u64 gr, void *data);
27 };
28
29 #define OBD_RUN_CTXT_MAGIC      0xC0FFEEAA
30 #define OBD_CTXT_DEBUG          /* development-only debugging */
31 struct lvfs_run_ctxt {
32         struct vfsmount *pwdmnt;
33         struct dentry   *pwd;
34         mm_segment_t     fs;
35         struct lvfs_ucred luc;
36         int              ngroups;
37         struct lvfs_callback_ops cb_ops;
38 #ifdef OBD_CTXT_DEBUG
39         __u32            magic;
40 #endif
41 };
42
43 #ifdef OBD_CTXT_DEBUG
44 #define OBD_SET_CTXT_MAGIC(ctxt) (ctxt)->magic = OBD_RUN_CTXT_MAGIC
45 #else
46 #define OBD_SET_CTXT_MAGIC(ctxt) do {} while(0)
47 #endif
48
49 /* lvfs_common.c */
50 struct dentry *lvfs_fid2dentry(struct lvfs_run_ctxt *, __u64, __u32, __u64 ,void *data);
51
52 void push_ctxt(struct lvfs_run_ctxt *save, struct lvfs_run_ctxt *new_ctx,
53                struct lvfs_ucred *cred);
54 void pop_ctxt(struct lvfs_run_ctxt *saved, struct lvfs_run_ctxt *new_ctx,
55               struct lvfs_ucred *cred);
56
57 #ifdef __KERNEL__
58 int lvfs_reint(struct super_block *sb, void *r_rec);
59 int lvfs_undo(struct super_block *sb, void *r_rec);
60 struct dentry *simple_mkdir(struct dentry *dir, char *name, int mode, int fix);
61 struct dentry *simple_mknod(struct dentry *dir, char *name, int mode, int fix);
62 int lustre_fread(struct file *file, void *buf, int len, loff_t *off);
63 int lustre_fwrite(struct file *file, const void *buf, int len, loff_t *off);
64 int lustre_fsync(struct file *file);
65 long l_readdir(struct file * file, struct list_head *dentry_list);
66
67 static inline void l_dput(struct dentry *de)
68 {
69         if (!de || IS_ERR(de))
70                 return;
71         //shrink_dcache_parent(de);
72         LASSERT(atomic_read(&de->d_count) > 0);
73         dput(de);
74 }
75
76 #ifdef S_PDIROPS
77 void *lock_dir(struct inode *dir, struct qstr *name);
78 void unlock_dir(struct inode *dir, void *lock);
79 #endif
80
81 /* We need to hold the inode semaphore over the dcache lookup itself, or we
82  * run the risk of entering the filesystem lookup path concurrently on SMP
83  * systems, and instantiating two inodes for the same entry.  We still
84  * protect against concurrent addition/removal races with the DLM locking.
85  */
86 static inline struct dentry *ll_lookup_one_len(const char *fid_name,
87                                                struct dentry *dparent,
88                                                int fid_namelen)
89 {
90         struct dentry *dchild;
91 #ifdef S_PDIROPS
92         struct qstr qstr;
93         void *lock;
94         qstr.name = fid_name;
95         qstr.len = fid_namelen;
96         lock = lock_dir(dparent->d_inode, &qstr);
97 #else
98         down(&dparent->d_inode->i_sem);
99 #endif
100
101         dchild = lookup_one_len(fid_name, dparent, fid_namelen);
102
103 #ifdef S_PDIROPS
104         unlock_dir(dparent->d_inode, lock);
105 #else
106         up(&dparent->d_inode->i_sem);
107 #endif
108         return dchild;
109 }
110
111 static inline void ll_sleep(int t)
112 {
113         set_current_state(TASK_INTERRUPTIBLE);
114         schedule_timeout(t * HZ);
115         set_current_state(TASK_RUNNING);
116 }
117 #endif
118
119 static inline int ll_fid2str(char *str, __u64 id, __u32 generation)
120 {
121         return sprintf(str, "%llx:%08x", (unsigned long long)id, generation);
122 }
123
124 #endif