Whamcloud - gitweb
Branch 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  *  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 #include <liblustre.h>
37 #endif
38
39 #define LLOG_LVFS
40
41 /* lvfs.c */
42 int obd_alloc_fail(const void *ptr, const char *name, const char *type,
43                    size_t size, const char *file, int line);
44
45 /* simple.c */
46
47 struct lvfs_ucred {
48         __u32                   luc_uid;
49         __u32                   luc_gid;
50         __u32                   luc_fsuid;
51         __u32                   luc_fsgid;
52         __u32                   luc_cap;
53         __u32                   luc_umask;
54         struct group_info      *luc_ginfo;
55         struct mdt_identity    *luc_identity;
56 };
57
58 struct lvfs_callback_ops {
59         struct dentry *(*l_fid2dentry)(__u64 id_ino, __u32 gen, __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         int                      ngroups;
70         struct lvfs_callback_ops cb_ops;
71         struct group_info       *group_info;
72 #ifdef OBD_CTXT_DEBUG
73         __u32                    magic;
74 #endif
75 };
76
77 #ifdef OBD_CTXT_DEBUG
78 #define OBD_SET_CTXT_MAGIC(ctxt) (ctxt)->magic = OBD_RUN_CTXT_MAGIC
79 #else
80 #define OBD_SET_CTXT_MAGIC(ctxt) do {} while(0)
81 #endif
82
83 #ifdef __KERNEL__
84
85 struct dentry *simple_mkdir(struct dentry *dir, char *name, int mode, int fix);
86 struct dentry *simple_mknod(struct dentry *dir, char *name, int mode, int fix);
87 int lustre_rename(struct dentry *dir, char *oldname, char *newname);
88 int lustre_fread(struct file *file, void *buf, int len, loff_t *off);
89 int lustre_fwrite(struct file *file, const void *buf, int len, loff_t *off);
90 int lustre_fsync(struct file *file);
91 long l_readdir(struct file * file, struct list_head *dentry_list);
92
93 static inline void l_dput(struct dentry *de)
94 {
95         if (!de || IS_ERR(de))
96                 return;
97         //shrink_dcache_parent(de);
98         LASSERT(atomic_read(&de->d_count) > 0);
99         dput(de);
100 }
101
102 /* We need to hold the inode semaphore over the dcache lookup itself, or we
103  * run the risk of entering the filesystem lookup path concurrently on SMP
104  * systems, and instantiating two inodes for the same entry.  We still
105  * protect against concurrent addition/removal races with the DLM locking.
106  */
107 static inline struct dentry *ll_lookup_one_len(const char *fid_name,
108                                                struct dentry *dparent,
109                                                int fid_namelen)
110 {
111         struct dentry *dchild;
112
113         LOCK_INODE_MUTEX(dparent->d_inode);
114         dchild = lookup_one_len(fid_name, dparent, fid_namelen);
115         UNLOCK_INODE_MUTEX(dparent->d_inode);
116
117         if (IS_ERR(dchild) || dchild->d_inode == NULL)
118                 return dchild;
119
120         if (is_bad_inode(dchild->d_inode)) {
121                 CERROR("bad inode returned %lu/%u\n",
122                        dchild->d_inode->i_ino, dchild->d_inode->i_generation);
123                 dput(dchild);
124                 dchild = ERR_PTR(-ENOENT);
125         }
126         return dchild;
127 }
128
129 static inline void ll_sleep(int t)
130 {
131         set_current_state(TASK_INTERRUPTIBLE);
132         schedule_timeout(t * HZ);
133         set_current_state(TASK_RUNNING);
134 }
135 #endif
136
137 #endif