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