Whamcloud - gitweb
- many fixes in liblustre related stuff. By now liblustre is at least build-able...
[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 #else
39 #include <liblustre.h>
40 #endif
41
42 struct mds_grp_hash_entry;
43
44 /* simple.c */
45 struct lvfs_ucred {
46         struct lustre_sec_desc *luc_lsd;
47         struct group_info      *luc_ginfo;
48         __u64                   luc_nid;
49         __u32                   luc_uid;
50         __u32                   luc_gid;
51         __u32                   luc_fsuid;
52         __u32                   luc_fsgid;
53         __u32                   luc_cap;
54         __u32                   luc_umask;
55 };
56
57 struct lvfs_callback_ops {
58         struct dentry *(*l_id2dentry)(__u64 ino, __u32 gen, 
59                                       __u64 gr, void *data);
60 };
61
62 #define OBD_RUN_CTXT_MAGIC      0xC0FFEEAA
63 #define OBD_CTXT_DEBUG          /* development-only debugging */
64 struct lvfs_run_ctxt {
65         struct vfsmount         *pwdmnt;
66         struct dentry           *pwd;
67         mm_segment_t             fs;
68         struct lvfs_ucred        luc;
69         struct lvfs_callback_ops cb_ops;
70         int                      ngroups;
71 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,4)
72         struct group_info       *group_info;
73 #else
74         struct group_info        group_info;
75 #endif
76 #ifdef OBD_CTXT_DEBUG
77         int                      pid;
78         __u32                    magic;
79 #endif
80 };
81
82 struct lvfs_obd_ctxt {
83         struct vfsmount *loc_mnt;
84         atomic_t         loc_refcount;
85         char            *loc_name;
86         struct list_head loc_list; 
87 };
88
89 #ifdef OBD_CTXT_DEBUG
90 #define OBD_SET_CTXT_MAGIC(ctxt) (ctxt)->magic = OBD_RUN_CTXT_MAGIC
91 #else
92 #define OBD_SET_CTXT_MAGIC(ctxt) do {} while(0)
93 #endif
94
95 /* lvfs_common.c */
96 struct dentry *lvfs_id2dentry(struct lvfs_run_ctxt *, __u64, 
97                               __u32, __u64 ,void *data);
98
99 void push_ctxt(struct lvfs_run_ctxt *save, struct lvfs_run_ctxt *new_ctx,
100                struct lvfs_ucred *cred);
101 void pop_ctxt(struct lvfs_run_ctxt *saved, struct lvfs_run_ctxt *new_ctx,
102               struct lvfs_ucred *cred);
103
104 #ifdef __KERNEL__
105 int lvfs_reint(struct super_block *sb, void *r_rec);
106 int lvfs_undo(struct super_block *sb, void *r_rec);
107 struct dentry *simple_mkdir(struct dentry *dir, char *name, int mode, int fix);
108 struct dentry *simple_mknod(struct dentry *dir, char *name, int mode, int fix);
109 int lustre_fread(struct file *file, void *buf, int len, loff_t *off);
110 int lustre_fwrite(struct file *file, const void *buf, int len, loff_t *off);
111 int lustre_fsync(struct file *file);
112 long l_readdir(struct file * file, struct list_head *dentry_list);
113 int lvfs_mount_fs(char *name, char *fstype, char *options, int flags, 
114                   struct lvfs_obd_ctxt **lvfs_ctxt);
115 void lvfs_umount_fs(struct lvfs_obd_ctxt *lvfs_ctxt);
116 static inline void l_dput(struct dentry *de)
117 {
118         if (!de || IS_ERR(de))
119                 return;
120         //shrink_dcache_parent(de);
121         LASSERT(atomic_read(&de->d_count) > 0);
122         dput(de);
123 }
124
125 #ifdef S_PDIROPS
126 void *lock_dir(struct inode *dir, struct qstr *name);
127 void unlock_dir(struct inode *dir, void *lock);
128 #endif
129
130 /*
131  * typeof here is to suppress gcc warnings (gcc4, maybe others too) about wrong
132  * type in assignment. As kernel type may be chnaged we doing it this way.
133  * --umka
134  */
135 #define qstr_assign(qstr, n, l)                 \
136 do {                                            \
137     typeof(l) _len = (l);                       \
138     typeof(n) _name = (n);                      \
139     (qstr)->name = (typeof((qstr)->name))_name; \
140     (qstr)->len = (typeof((qstr)->len))_len;    \
141 } while (0)
142
143 /* We need to hold the inode semaphore over the dcache lookup itself, or we run
144  * the risk of entering the filesystem lookup path concurrently on SMP systems,
145  * and instantiating two inodes for the same entry.  We still protect against
146  * concurrent addition/removal races with the DLM locking. */
147 static inline struct dentry *
148 ll_lookup_one_len(const char *name, struct dentry *dparent, int namelen)
149 {
150         struct dentry *dchild;
151         
152 #ifdef S_PDIROPS
153         struct qstr qstr;
154         void *lock;
155
156         qstr_assign(&qstr, name, namelen);
157         lock = lock_dir(dparent->d_inode, &qstr);
158 #else
159         down(&dparent->d_inode->i_sem);
160 #endif
161
162         dchild = lookup_one_len(name, dparent, namelen);
163
164 #ifdef S_PDIROPS
165         unlock_dir(dparent->d_inode, lock);
166 #else
167         up(&dparent->d_inode->i_sem);
168 #endif
169
170         if (IS_ERR(dchild) || dchild->d_inode == NULL)
171                 return dchild;
172
173         if (is_bad_inode(dchild->d_inode)) {
174                 CERROR("bad inode returned %lu/%u\n",
175                        dchild->d_inode->i_ino, dchild->d_inode->i_generation);
176                 dput(dchild);
177                 dchild = ERR_PTR(-ENOENT);
178         }
179
180         return dchild;
181 }
182
183 static inline void ll_sleep(int t)
184 {
185         set_current_state(TASK_INTERRUPTIBLE);
186         schedule_timeout(t * HZ);
187         set_current_state(TASK_RUNNING);
188 }
189 #endif
190
191 static inline int ll_id2str(char *str, __u64 id, __u32 generation)
192 {
193         return sprintf(str, "%llx:%08x", (unsigned long long)id, 
194                        generation);
195 }
196
197 #endif