Whamcloud - gitweb
libcfs: fixes to CDEBUG(), LASSERT() and friends to reduce stack consumption (Attempt 2.)
[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 __LVFS_H__
25 #define __LVFS_H__
26
27 #include <libcfs/kp30.h>
28 #include <linux/lustre_ucache.h>
29
30 #define LL_FID_NAMELEN (16 + 1 + 8 + 1)
31
32 #if defined __KERNEL__
33 #include <linux/lustre_compat25.h>
34 #include <linux/lvfs_linux.h>
35 #else
36 struct group_info { /* unused */ };
37 #endif
38
39 #ifdef LIBLUSTRE
40 #include <lvfs_user_fs.h>
41 #endif
42
43 /* simple.c */
44
45 struct lvfs_ucred {
46         struct upcall_cache_entry *luc_uce;
47         __u32 luc_fsuid;
48         __u32 luc_fsgid;
49         __u32 luc_cap;
50         __u32 luc_suppgid1;
51         __u32 luc_suppgid2;
52         __u32 luc_umask;
53 };
54
55 struct lvfs_callback_ops {
56         struct dentry *(*l_fid2dentry)(__u64 id_ino, __u32 gen, __u64 gr, void *data);
57 };
58
59 #define OBD_RUN_CTXT_MAGIC      0xC0FFEEAA
60 #define OBD_CTXT_DEBUG          /* development-only debugging */
61 struct lvfs_run_ctxt {
62         struct vfsmount         *pwdmnt;
63         struct dentry           *pwd;
64         mm_segment_t             fs;
65         struct lvfs_ucred        luc;
66         int                      ngroups;
67         struct lvfs_callback_ops cb_ops;
68 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,4)
69         struct group_info       *group_info;
70 #else
71         struct group_info        group_info;
72 #endif
73 #ifdef OBD_CTXT_DEBUG
74         __u32                    magic;
75 #endif
76 };
77
78 #ifdef OBD_CTXT_DEBUG
79 #define OBD_SET_CTXT_MAGIC(ctxt) (ctxt)->magic = OBD_RUN_CTXT_MAGIC
80 #else
81 #define OBD_SET_CTXT_MAGIC(ctxt) do {} while(0)
82 #endif
83
84 /* lvfs_common.c */
85 struct dentry *lvfs_fid2dentry(struct lvfs_run_ctxt *, __u64, __u32, __u64 ,void *data);
86
87 void push_ctxt(struct lvfs_run_ctxt *save, struct lvfs_run_ctxt *new_ctx,
88                struct lvfs_ucred *cred);
89 void pop_ctxt(struct lvfs_run_ctxt *saved, struct lvfs_run_ctxt *new_ctx,
90               struct lvfs_ucred *cred);
91
92 #ifdef __KERNEL__
93
94 struct dentry *simple_mkdir(struct dentry *dir, char *name, int mode, int fix);
95 struct dentry *simple_mknod(struct dentry *dir, char *name, int mode, int fix);
96 int lustre_fread(struct file *file, void *buf, int len, loff_t *off);
97 int lustre_fwrite(struct file *file, const void *buf, int len, loff_t *off);
98 int lustre_fsync(struct file *file);
99 long l_readdir(struct file * file, struct list_head *dentry_list);
100
101 static inline void l_dput(struct dentry *de)
102 {
103         if (!de || IS_ERR(de))
104                 return;
105         //shrink_dcache_parent(de);
106         LASSERT(atomic_read(&de->d_count) > 0);
107         dput(de);
108 }
109
110 /* We need to hold the inode semaphore over the dcache lookup itself, or we
111  * run the risk of entering the filesystem lookup path concurrently on SMP
112  * systems, and instantiating two inodes for the same entry.  We still
113  * protect against concurrent addition/removal races with the DLM locking.
114  */
115 static inline struct dentry *ll_lookup_one_len(const char *fid_name,
116                                                struct dentry *dparent,
117                                                int fid_namelen)
118 {
119         struct dentry *dchild;
120
121         LOCK_INODE_MUTEX(dparent->d_inode);
122         dchild = lookup_one_len(fid_name, dparent, fid_namelen);
123         UNLOCK_INODE_MUTEX(dparent->d_inode);
124
125         if (IS_ERR(dchild) || dchild->d_inode == NULL)
126                 return dchild;
127
128         if (is_bad_inode(dchild->d_inode)) {
129                 CERROR("bad inode returned %lu/%u\n",
130                        dchild->d_inode->i_ino, dchild->d_inode->i_generation);
131                 dput(dchild);
132                 dchild = ERR_PTR(-ENOENT);
133         }
134         return dchild;
135 }
136
137 static inline void ll_sleep(int t)
138 {
139         set_current_state(TASK_INTERRUPTIBLE);
140         schedule_timeout(t * HZ);
141         set_current_state(TASK_RUNNING);
142 }
143 #endif
144
145 #endif