Whamcloud - gitweb
- b_hd_audit landing
[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  *  Copyright (C) 2001, 2002, 2003, 2004 Cluster File Systems, Inc.
5  *
6  *  Author: <braam@clusterfs.com>
7  *
8  *   This file is part of Lustre, http://www.lustre.org.
9  *
10  *   Lustre is free software; you can redistribute it and/or
11  *   modify it under the terms of version 2 of the GNU General Public
12  *   License as published by the Free Software Foundation.
13  *
14  *   Lustre is distributed in the hope that it will be useful,
15  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *   GNU General Public License for more details.
18  *
19  *   You should have received a copy of the GNU General Public License
20  *   along with Lustre; if not, write to the Free Software
21  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22  *
23  * lustre VFS/process permission interface
24  */
25
26 #ifndef __LVFS_H__
27 #define __LVFS_H__
28
29 #include <libcfs/kp30.h>
30
31 #define LL_ID_NAMELEN (16 + 1 + 8 + 1)
32
33 #if defined __KERNEL__
34 #include <linux/dcache.h>
35 #include <linux/namei.h>
36 #include <linux/lustre_compat25.h>
37 #include <linux/lvfs_linux.h>
38 #endif
39
40 #ifdef LIBLUSTRE
41 #include <lvfs_user_fs.h>
42 #endif
43
44 struct mds_grp_hash_entry;
45
46 /* simple.c */
47 struct lvfs_ucred {
48         struct lustre_sec_desc *luc_lsd;
49         struct group_info      *luc_ginfo;
50         __u64                   luc_nid;
51         __u32                   luc_uid;
52         __u32                   luc_gid;
53         __u32                   luc_fsuid;
54         __u32                   luc_fsgid;
55         __u32                   luc_cap;
56         __u32                   luc_umask;
57 };
58
59 struct lvfs_callback_ops {
60         struct dentry *(*l_id2dentry)(__u64 ino, __u32 gen, 
61                                       __u64 gr, void *data);
62 };
63
64 #define OBD_RUN_CTXT_MAGIC      0xC0FFEEAA
65 #define OBD_CTXT_DEBUG          /* development-only debugging */
66 struct lvfs_run_ctxt {
67         struct vfsmount         *pwdmnt;
68         struct dentry           *pwd;
69         mm_segment_t             fs;
70         struct lvfs_ucred        luc;
71         struct lvfs_callback_ops cb_ops;
72         int                      ngroups;
73 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,4)
74         struct group_info       *group_info;
75 #else
76         struct group_info        group_info;
77 #endif
78 #ifdef OBD_CTXT_DEBUG
79         int                      pid;
80         __u32                    magic;
81 #endif
82 };
83
84 struct lvfs_obd_ctxt {
85         struct vfsmount *loc_mnt;
86         atomic_t         loc_refcount;
87         char            *loc_name;
88         struct list_head loc_list; 
89 };
90
91 #ifdef OBD_CTXT_DEBUG
92 #define OBD_SET_CTXT_MAGIC(ctxt) (ctxt)->magic = OBD_RUN_CTXT_MAGIC
93 #else
94 #define OBD_SET_CTXT_MAGIC(ctxt) do {} while(0)
95 #endif
96
97 /* lvfs_common.c */
98 struct dentry *lvfs_id2dentry(struct lvfs_run_ctxt *, __u64, 
99                               __u32, __u64 ,void *data);
100
101 void push_ctxt(struct lvfs_run_ctxt *save, struct lvfs_run_ctxt *new_ctx,
102                struct lvfs_ucred *cred);
103 void pop_ctxt(struct lvfs_run_ctxt *saved, struct lvfs_run_ctxt *new_ctx,
104               struct lvfs_ucred *cred);
105
106 #ifdef __KERNEL__
107 int lvfs_reint(struct super_block *sb, void *r_rec);
108 int lvfs_undo(struct super_block *sb, void *r_rec);
109 struct dentry *simple_mkdir(struct dentry *dir, char *name, int mode, int fix);
110 struct dentry *simple_mknod(struct dentry *dir, char *name, int mode, int fix);
111 int lustre_fread(struct file *file, void *buf, int len, loff_t *off);
112 int lustre_fwrite(struct file *file, const void *buf, int len, loff_t *off);
113 int lustre_fsync(struct file *file);
114 long l_readdir(struct file * file, struct list_head *dentry_list);
115 int lvfs_mount_fs(char *name, char *fstype, char *options, int flags, 
116                   struct lvfs_obd_ctxt **lvfs_ctxt);
117 void lvfs_umount_fs(struct lvfs_obd_ctxt *lvfs_ctxt);
118 static inline void l_dput(struct dentry *de)
119 {
120         if (!de || IS_ERR(de))
121                 return;
122         //shrink_dcache_parent(de);
123         LASSERT(atomic_read(&de->d_count) > 0);
124         dput(de);
125 }
126
127 #ifdef S_PDIROPS
128 void *lock_dir(struct inode *dir, struct qstr *name);
129 void unlock_dir(struct inode *dir, void *lock);
130 #endif
131
132 /*
133  * typeof here is to suppress gcc warnings (gcc4, maybe others too) about wrong
134  * type in assignment. As kernel type may be chnaged we doing it this way.
135  * --umka
136  */
137 #define qstr_assign(qstr, n, l)                 \
138 do {                                            \
139     typeof(l) _len = (l);                       \
140     typeof(n) _name = (n);                      \
141     (qstr)->name = (typeof((qstr)->name))_name; \
142     (qstr)->len = (typeof((qstr)->len))_len;    \
143 } while (0)
144
145 /* We need to hold the inode semaphore over the dcache lookup itself, or we run
146  * the risk of entering the filesystem lookup path concurrently on SMP systems,
147  * and instantiating two inodes for the same entry.  We still protect against
148  * concurrent addition/removal races with the DLM locking. */
149 static inline struct dentry *
150 ll_lookup_one_len(const char *name, struct dentry *dparent, int namelen)
151 {
152         struct dentry *dchild;
153         
154 #ifdef S_PDIROPS
155         struct qstr qstr;
156         void *lock;
157
158         qstr_assign(&qstr, name, namelen);
159         lock = lock_dir(dparent->d_inode, &qstr);
160 #else
161         down(&dparent->d_inode->i_sem);
162 #endif
163
164         dchild = lookup_one_len(name, dparent, namelen);
165
166 #ifdef S_PDIROPS
167         unlock_dir(dparent->d_inode, lock);
168 #else
169         up(&dparent->d_inode->i_sem);
170 #endif
171
172         if (IS_ERR(dchild) || dchild->d_inode == NULL)
173                 return dchild;
174
175         if (is_bad_inode(dchild->d_inode)) {
176                 CERROR("bad inode returned %lu/%u\n",
177                        dchild->d_inode->i_ino, dchild->d_inode->i_generation);
178                 dput(dchild);
179                 dchild = ERR_PTR(-ENOENT);
180         }
181
182         return dchild;
183 }
184
185 static inline void ll_sleep(int t)
186 {
187         set_current_state(TASK_INTERRUPTIBLE);
188         schedule_timeout(t * HZ);
189         set_current_state(TASK_RUNNING);
190 }
191 #endif
192
193 static inline int ll_id2str(char *str, __u64 id, __u32 generation)
194 {
195         return sprintf(str, "%llx:%08x", (unsigned long long)id, 
196                        generation);
197 }
198
199 #endif