Whamcloud - gitweb
b=11270
[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 Cluster File Systems, Inc. <braam@clusterfs.com>
5  *
6  *   This file is part of Lustre, http://www.lustre.org.
7  *
8  *   Lustre is free software; you can redistribute it and/or
9  *   modify it under the terms of version 2 of the GNU General Public
10  *   License as published by the Free Software Foundation.
11  *
12  *   Lustre is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with Lustre; if not, write to the Free Software
19  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  *
21  * lustre VFS/process permission interface
22  */
23
24 #ifndef __LINUX_LVFS_H__
25 #define __LINUX_LVFS_H__
26
27 #ifndef __LVFS_H__
28 #error Do not #include this file directly. #include <lvfs.h> instead
29 #endif
30
31 #if defined __KERNEL__
32 #include <linux/lustre_compat25.h>
33 #include <linux/lvfs_linux.h>
34 #else
35 struct group_info { /* unused */ };
36 #endif
37
38 #define LLOG_LVFS
39
40 /* lvfs.c */
41 int obd_alloc_fail(const void *ptr, const char *name, const char *type,
42                    size_t size, const char *file, int line);
43
44 /* simple.c */
45
46 struct lvfs_ucred {
47         struct upcall_cache_entry *luc_uce;
48         __u32 luc_fsuid;
49         __u32 luc_fsgid;
50         __u32 luc_cap;
51         __u32 luc_suppgid1;
52         __u32 luc_suppgid2;
53         __u32 luc_umask;
54 };
55
56 struct lvfs_callback_ops {
57         struct dentry *(*l_fid2dentry)(__u64 id_ino, __u32 gen, __u64 gr, void *data);
58 };
59
60 #define OBD_RUN_CTXT_MAGIC      0xC0FFEEAA
61 #define OBD_CTXT_DEBUG          /* development-only debugging */
62 struct lvfs_run_ctxt {
63         struct vfsmount         *pwdmnt;
64         struct dentry           *pwd;
65         mm_segment_t             fs;
66         struct lvfs_ucred        luc;
67         int                      ngroups;
68         struct lvfs_callback_ops cb_ops;
69 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,4)
70         struct group_info       *group_info;
71 #else
72         struct group_info        group_info;
73 #endif
74 #ifdef OBD_CTXT_DEBUG
75         __u32                    magic;
76 #endif
77 };
78
79 #ifdef OBD_CTXT_DEBUG
80 #define OBD_SET_CTXT_MAGIC(ctxt) (ctxt)->magic = OBD_RUN_CTXT_MAGIC
81 #else
82 #define OBD_SET_CTXT_MAGIC(ctxt) do {} while(0)
83 #endif
84
85 #ifdef __KERNEL__
86
87 struct dentry *simple_mkdir(struct dentry *dir, char *name, int mode, int fix);
88 struct dentry *simple_mknod(struct dentry *dir, char *name, int mode, int fix);
89 int lustre_rename(struct dentry *dir, char *oldname, char *newname);
90 int lustre_fread(struct file *file, void *buf, int len, loff_t *off);
91 int lustre_fwrite(struct file *file, const void *buf, int len, loff_t *off);
92 int lustre_fsync(struct file *file);
93 long l_readdir(struct file * file, struct list_head *dentry_list);
94
95 static inline void l_dput(struct dentry *de)
96 {
97         if (!de || IS_ERR(de))
98                 return;
99         //shrink_dcache_parent(de);
100         LASSERT(atomic_read(&de->d_count) > 0);
101         dput(de);
102 }
103
104 /* We need to hold the inode semaphore over the dcache lookup itself, or we
105  * run the risk of entering the filesystem lookup path concurrently on SMP
106  * systems, and instantiating two inodes for the same entry.  We still
107  * protect against concurrent addition/removal races with the DLM locking.
108  */
109 static inline struct dentry *ll_lookup_one_len(const char *fid_name,
110                                                struct dentry *dparent,
111                                                int fid_namelen)
112 {
113         struct dentry *dchild;
114
115         LOCK_INODE_MUTEX(dparent->d_inode);
116         dchild = lookup_one_len(fid_name, dparent, fid_namelen);
117         UNLOCK_INODE_MUTEX(dparent->d_inode);
118
119         if (IS_ERR(dchild) || dchild->d_inode == NULL)
120                 return dchild;
121
122         if (is_bad_inode(dchild->d_inode)) {
123                 CERROR("bad inode returned %lu/%u\n",
124                        dchild->d_inode->i_ino, dchild->d_inode->i_generation);
125                 dput(dchild);
126                 dchild = ERR_PTR(-ENOENT);
127         }
128         return dchild;
129 }
130
131 static inline void ll_sleep(int t)
132 {
133         set_current_state(TASK_INTERRUPTIBLE);
134         schedule_timeout(t * HZ);
135         set_current_state(TASK_RUNNING);
136 }
137 #endif
138
139 #endif