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