~ubuntu-branches/ubuntu/raring/aufs/raring

« back to all changes in this revision

Viewing changes to fs/aufs25/file.h

  • Committer: Bazaar Package Importer
  • Author(s): Julian Andres Klode
  • Date: 2008-05-06 18:35:50 UTC
  • mto: This revision was merged to the branch mainline in revision 9.
  • Revision ID: james.westby@ubuntu.com-20080506183550-7y7mrzkzkh2tjlfu
Tags: upstream-0+20080506
ImportĀ upstreamĀ versionĀ 0+20080506

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2005-2008 Junjiro Okajima
 
3
 *
 
4
 * This program, aufs is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License as published by
 
6
 * the Free Software Foundation; either version 2 of the License, or
 
7
 * (at your option) any later version.
 
8
 *
 
9
 * This program is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 * GNU General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public License
 
15
 * along with this program; if not, write to the Free Software
 
16
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
17
 */
 
18
 
 
19
/*
 
20
 * file operations
 
21
 *
 
22
 * $Id: file.h,v 1.2 2008/04/21 01:35:14 sfjro Exp $
 
23
 */
 
24
 
 
25
#ifndef __AUFS_FILE_H__
 
26
#define __AUFS_FILE_H__
 
27
 
 
28
#ifdef __KERNEL__
 
29
 
 
30
#include <linux/file.h>
 
31
#include <linux/fs.h>
 
32
#include <linux/mm.h>
 
33
#include <linux/aufs_type.h>
 
34
#include "dentry.h"
 
35
#include "misc.h"
 
36
#include "super.h"
 
37
 
 
38
/* ---------------------------------------------------------------------- */
 
39
 
 
40
struct au_branch;
 
41
struct au_hfile {
 
42
        struct file             *hf_file;
 
43
        struct au_branch        *hf_br;
 
44
};
 
45
 
 
46
struct au_vdir;
 
47
struct au_finfo {
 
48
        atomic_t                fi_generation;
 
49
 
 
50
        struct au_rwsem         fi_rwsem;
 
51
        struct au_hfile         *fi_hfile;
 
52
        aufs_bindex_t           fi_bstart, fi_bend;
 
53
 
 
54
        union {
 
55
                struct vm_operations_struct     *fi_h_vm_ops;
 
56
                struct au_vdir                  *fi_vdir_cache;
 
57
        };
 
58
};
 
59
 
 
60
/* ---------------------------------------------------------------------- */
 
61
 
 
62
/* file.c */
 
63
extern struct address_space_operations aufs_aop;
 
64
unsigned int au_file_roflags(unsigned int flags);
 
65
struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
 
66
                       struct file *file);
 
67
int au_do_open(struct inode *inode, struct file *file,
 
68
               int (*open)(struct file *file, int flags));
 
69
int au_reopen_nondir(struct file *file);
 
70
int au_ready_to_write(struct file *file, loff_t len);
 
71
int au_reval_and_lock_finfo(struct file *file, int (*reopen)(struct file *file),
 
72
                            int wlock, int locked);
 
73
 
 
74
/* f_op.c */
 
75
extern struct file_operations aufs_file_fop;
 
76
int aufs_flush(struct file *file, fl_owner_t id);
 
77
 
 
78
/* finfo.c */
 
79
struct au_finfo *au_fi(struct file *file);
 
80
struct au_branch *au_fbr(struct file *file, aufs_bindex_t bindex);
 
81
struct file *au_h_fptr(struct file *file, aufs_bindex_t bindex);
 
82
 
 
83
void au_hfput(struct au_hfile *hf);
 
84
void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
 
85
                   struct file *h_file);
 
86
 
 
87
void au_finfo_fin(struct file *file);
 
88
int au_finfo_init(struct file *file);
 
89
 
 
90
#ifdef CONFIG_AUFS_ROBR
 
91
/* robr.c */
 
92
struct file *au_robr_safe_file(struct vm_area_struct *vma);
 
93
void au_robr_reset_file(struct vm_area_struct *vma, struct file *file);
 
94
#else
 
95
static inline struct file *au_robr_safe_file(struct vm_area_struct *vma)
 
96
{
 
97
        struct file *file;
 
98
 
 
99
        file = vma->vm_file;
 
100
        if (file->private_data && au_test_aufs(file->f_dentry->d_sb))
 
101
                return file;
 
102
        return NULL;
 
103
}
 
104
 
 
105
static inline
 
106
void au_robr_reset_file(struct vm_area_struct *vma, struct file *file)
 
107
{
 
108
        vma->vm_file = file;
 
109
        smp_mb(); /* flush vm_file */
 
110
}
 
111
#endif /* CONFIG_AUFS_ROBR */
 
112
 
 
113
/* ---------------------------------------------------------------------- */
 
114
 
 
115
//todo: memory barrier?
 
116
static inline au_gen_t au_figen(struct file *f)
 
117
{
 
118
        return atomic_read(&au_fi(f)->fi_generation);
 
119
}
 
120
 
 
121
static inline int au_test_mmapped(struct file *f)
 
122
{
 
123
        return !!(au_fi(f)->fi_h_vm_ops);
 
124
}
 
125
 
 
126
static inline int au_test_aufs_file(struct file *f)
 
127
{
 
128
        return !(f->f_dentry->d_inode->i_mode
 
129
                 & (S_IFCHR | S_IFBLK | S_IFIFO | S_IFSOCK));
 
130
}
 
131
 
 
132
/* ---------------------------------------------------------------------- */
 
133
 
 
134
#if !defined(CONFIG_AUFS_MODULE) || defined(CONFIG_AUFS_DENY_WRITE_ACCESS_PATCH)
 
135
int au_store_fmode_exec(struct nameidata *nd, struct inode *inode);
 
136
 
 
137
static inline int au_deny_write_access(struct file *h_file)
 
138
{
 
139
        LKTRTrace("%.*s\n", AuDLNPair(h_file->f_dentry));
 
140
        return deny_write_access(h_file);
 
141
}
 
142
 
 
143
static inline void au_allow_write_access(struct file *h_file)
 
144
{
 
145
        allow_write_access(h_file);
 
146
}
 
147
 
 
148
#else
 
149
 
 
150
static inline int au_store_fmode_exec(struct nameidata *nd, struct inode *inode)
 
151
{
 
152
        /* nothing */
 
153
        return 0;
 
154
}
 
155
 
 
156
static inline int au_deny_write_access(struct file *h_file)
 
157
{
 
158
        /* nothing */
 
159
        return 0;
 
160
}
 
161
 
 
162
static inline void au_allow_write_access(struct file *h_file)
 
163
{
 
164
        /* nothing */
 
165
}
 
166
#endif /* CONFIG_AUFS_DENY_WRITE_ACCESS_PATCH */
 
167
 
 
168
/* ---------------------------------------------------------------------- */
 
169
 
 
170
/*
 
171
 * fi_read_lock, fi_write_lock,
 
172
 * fi_read_unlock, fi_write_unlock, fi_downgrade_lock
 
173
 */
 
174
AuSimpleRwsemFuncs(fi, struct file *f, au_fi(f)->fi_rwsem);
 
175
 
 
176
/* to debug easier, do not make them inlined functions */
 
177
#define FiMustReadLock(f) do { \
 
178
        SiMustAnyLock((f)->f_dentry->d_sb); \
 
179
        AuRwMustReadLock(&au_fi(f)->fi_rwsem); \
 
180
} while (0)
 
181
 
 
182
#define FiMustWriteLock(f) do { \
 
183
        SiMustAnyLock((f)->f_dentry->d_sb); \
 
184
        AuRwMustWriteLock(&au_fi(f)->fi_rwsem); \
 
185
} while (0)
 
186
 
 
187
#define FiMustAnyLock(f) do { \
 
188
        SiMustAnyLock((f)->f_dentry->d_sb); \
 
189
        AuRwMustAnyLock(&au_fi(f)->fi_rwsem); \
 
190
} while (0)
 
191
 
 
192
#define FiMustNoWaiters(f)      AuRwMustNoWaiters(&au_fi(f)->fi_rwsem)
 
193
 
 
194
/* ---------------------------------------------------------------------- */
 
195
 
 
196
// hard/soft set
 
197
static inline aufs_bindex_t au_fbstart(struct file *file)
 
198
{
 
199
        FiMustAnyLock(file);
 
200
        return au_fi(file)->fi_bstart;
 
201
}
 
202
 
 
203
static inline aufs_bindex_t au_fbend(struct file *file)
 
204
{
 
205
        FiMustAnyLock(file);
 
206
        return au_fi(file)->fi_bend;
 
207
}
 
208
 
 
209
static inline struct au_vdir *au_fvdir_cache(struct file *file)
 
210
{
 
211
        FiMustAnyLock(file);
 
212
        return au_fi(file)->fi_vdir_cache;
 
213
}
 
214
 
 
215
static inline void au_set_fbstart(struct file *file, aufs_bindex_t bindex)
 
216
{
 
217
        FiMustWriteLock(file);
 
218
        AuDebugOn(au_sbend(file->f_dentry->d_sb) < bindex);
 
219
        au_fi(file)->fi_bstart = bindex;
 
220
}
 
221
 
 
222
static inline void au_set_fbend(struct file *file, aufs_bindex_t bindex)
 
223
{
 
224
        FiMustWriteLock(file);
 
225
        AuDebugOn(au_sbend(file->f_dentry->d_sb) < bindex
 
226
                  || bindex < au_fbstart(file));
 
227
        au_fi(file)->fi_bend = bindex;
 
228
}
 
229
 
 
230
static inline void au_set_fvdir_cache(struct file *file,
 
231
                                      struct au_vdir *vdir_cache)
 
232
{
 
233
        FiMustWriteLock(file);
 
234
        AuDebugOn(!S_ISDIR(file->f_dentry->d_inode->i_mode)
 
235
                  || (au_fi(file)->fi_vdir_cache && vdir_cache));
 
236
        au_fi(file)->fi_vdir_cache = vdir_cache;
 
237
}
 
238
 
 
239
static inline void au_update_figen(struct file *file)
 
240
{
 
241
        atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_dentry));
 
242
        //smp_mb(); /* atomic_set */
 
243
}
 
244
 
 
245
#endif /* __KERNEL__ */
 
246
#endif /* __AUFS_FILE_H__ */