2
* Copyright (C) 2007-2008 Junjiro Okajima
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.
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.
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
20
* sub-routines for VFS
22
* $Id: vfsub.h,v 1.2 2008/04/21 01:49:22 sfjro Exp $
25
#ifndef __AUFS_VFSUB_H__
26
#define __AUFS_VFSUB_H__
31
#include <linux/namei.h>
32
#include <linux/splice.h>
33
#include <linux/inotify.h>
35
/* ---------------------------------------------------------------------- */
38
#define Vfsub_DLGT 1 /* operation with delegation */
39
#define Vfsub_FORCE_UNLINK (1 << 1) /* force unlinking */
40
#define vfsub_ftest(flags, name) ((flags) & Vfsub_##name)
41
#define vfsub_fset(flags, name) { (flags) |= Vfsub_##name; }
42
#define vfsub_fclr(flags, name) { (flags) &= ~Vfsub_##name; }
43
#ifndef CONFIG_AUFS_DLGT
50
#ifdef CONFIG_AUFS_HINOTIFY
51
/* inotify events to be ignored */
53
struct au_hin_ignore *ignore;
60
#ifdef CONFIG_AUFS_HINOTIFY
62
void do_vfsub_args_reinit(struct vfsub_args *vargs, struct au_hin_ignore *ign)
68
static inline void vfsub_args_reinit(struct vfsub_args *vargs)
73
__u32 vfsub_events_notify_change(struct iattr *ia);
74
void vfsub_ign_hinode(struct vfsub_args *vargs, __u32 events,
75
struct au_hinode *hinode);
76
void vfsub_ign_inode(struct vfsub_args *vargs, __u32 events,
77
struct inode *inode, struct inode *h_inode);
79
void vfsub_ignore(struct vfsub_args *vargs);
80
void vfsub_unignore(struct vfsub_args *vargs);
83
void do_vfsub_args_reinit(struct vfsub_args *vargs, struct au_hin_ignore *ign)
88
static inline void vfsub_args_reinit(struct vfsub_args *vargs)
93
static inline __u32 vfsub_events_notify_change(struct iattr *ia)
98
static inline void vfsub_ign_hinode(struct vfsub_args *vargs, __u32 events,
99
struct au_hinode *hinode)
104
static inline void vfsub_ign_inode(struct vfsub_args *vargs, __u32 events,
105
struct inode *inode, struct inode *h_inode)
110
static inline void vfsub_ignore(struct vfsub_args *vargs)
115
static inline void vfsub_unignore(struct vfsub_args *vargs)
119
#endif /* CONFIG_AUFS_HINOTIFY */
121
void vfsub_args_init(struct vfsub_args *vargs, struct au_hin_ignore *ign,
122
int dlgt, int force_unlink);
124
/* ---------------------------------------------------------------------- */
126
/* inotify_inode_watched() is not exported */
127
static inline int au_test_inotify(struct inode *inode)
129
#ifdef CONFIG_INOTIFY
130
return !list_empty(&inode->inotify_watches);
135
/* ---------------------------------------------------------------------- */
137
/* lock subclass for hidden inode */
138
/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
141
AuLsc_I_Begin = I_MUTEX_QUOTA, /* 4 */
142
AuLsc_I_PARENT, /* hidden inode, parent first */
144
AuLsc_I_PARENT2, /* copyup dirs */
149
#define IMustLock(i) MtxMustLock(&(i)->i_mutex)
152
struct dentry *vfsub_lock_rename(struct dentry *d1, struct dentry *d2)
157
d = lock_rename(d1, d2);
162
static inline void vfsub_unlock_rename(struct dentry *d1, struct dentry *d2)
165
unlock_rename(d1, d2);
169
/* ---------------------------------------------------------------------- */
171
#ifdef CONFIG_AUFS_WORKAROUND_FUSE
173
int au_update_fuse_h_inode(struct vfsmount *h_mnt, struct dentry *h_dentry);
176
int au_update_fuse_h_inode(struct vfsmount *h_mnt, struct dentry *h_dentry)
182
#ifdef CONFIG_AUFS_BR_XFS
184
dev_t au_h_rdev(struct inode *h_inode, struct vfsmount *h_mnt,
185
struct dentry *h_dentry);
188
dev_t au_h_rdev(struct inode *h_inode, struct vfsmount *h_mnt,
189
struct dentry *h_dentry)
191
return h_inode->i_rdev;
195
/* simple abstractions, for future use */
197
int do_vfsub_permission(struct inode *inode, int mask, struct nameidata *nd)
199
LKTRTrace("i%lu, mask 0x%x, nd %d\n", inode->i_ino, mask, !!nd);
201
return permission(inode, mask, nd);
204
/* ---------------------------------------------------------------------- */
206
struct file *vfsub_filp_open(const char *path, int oflags, int mode);
207
int vfsub_path_lookup(const char *name, unsigned int flags,
208
struct nameidata *nd);
209
struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
212
#ifdef CONFIG_AUFS_LHASH_PATCH
213
struct dentry *vfsub__lookup_hash(struct qstr *name, struct dentry *parent,
214
struct nameidata *nd);
217
/* ---------------------------------------------------------------------- */
219
int do_vfsub_create(struct inode *dir, struct dentry *dentry, int mode,
220
struct nameidata *nd);
221
int do_vfsub_symlink(struct inode *dir, struct dentry *dentry,
222
const char *symname, int mode);
223
int do_vfsub_mknod(struct inode *dir, struct dentry *dentry, int mode,
225
int do_vfsub_link(struct dentry *src_dentry, struct inode *dir,
226
struct dentry *dentry);
227
int do_vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
228
struct inode *dir, struct dentry *dentry);
229
int do_vfsub_mkdir(struct inode *dir, struct dentry *dentry, int mode);
230
int do_vfsub_rmdir(struct inode *dir, struct dentry *dentry);
231
int do_vfsub_unlink(struct inode *dir, struct dentry *dentry);
233
/* ---------------------------------------------------------------------- */
235
ssize_t do_vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
238
ssize_t do_vfsub_read_k(struct file *file, void *kbuf, size_t count,
240
ssize_t do_vfsub_write_u(struct file *file, const char __user *ubuf,
241
size_t count, loff_t *ppos);
242
ssize_t do_vfsub_write_k(struct file *file, void *kbuf, size_t count,
244
int do_vfsub_readdir(struct file *file, filldir_t filldir, void *arg);
246
/* ---------------------------------------------------------------------- */
248
#ifdef CONFIG_AUFS_SPLICE_PATCH
249
long do_vfsub_splice_to(struct file *in, loff_t *ppos,
250
struct pipe_inode_info *pipe, size_t len,
252
long do_vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
253
loff_t *ppos, size_t len, unsigned int flags);
256
long do_vfsub_splice_to(struct file *in, loff_t *ppos,
257
struct pipe_inode_info *pipe, size_t len,
264
long do_vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
265
loff_t *ppos, size_t len, unsigned int flags)
269
#endif /* CONFIG_AUFS_SPLICE_PATCH */
271
/* ---------------------------------------------------------------------- */
273
static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin)
277
LKTRTrace("%.*s\n", AuDLNPair(file->f_dentry));
280
err = vfs_llseek(file, offset, origin);
285
static inline int do_vfsub_getattr(struct vfsmount *mnt, struct dentry *dentry,
288
LKTRTrace("%.*s\n", AuDLNPair(dentry));
289
return vfs_getattr(mnt, dentry, st);
292
/* ---------------------------------------------------------------------- */
294
#if defined(CONFIG_AUFS_HINOTIFY) || defined(CONFIG_AUFS_DLGT)
296
int vfsub_permission(struct inode *inode, int mask, struct nameidata *nd,
299
int vfsub_create(struct inode *dir, struct dentry *dentry, int mode,
300
struct nameidata *nd, int dlgt);
301
int vfsub_symlink(struct inode *dir, struct dentry *dentry, const char *symname,
303
int vfsub_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev,
305
int vfsub_link(struct dentry *src_dentry, struct inode *dir,
306
struct dentry *dentry, int dlgt);
307
int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
308
struct inode *dir, struct dentry *dentry,
309
struct vfsub_args *vargs);
310
int vfsub_mkdir(struct inode *dir, struct dentry *dentry, int mode, int dlgt);
311
int vfsub_rmdir(struct inode *dir, struct dentry *dentry,
312
struct vfsub_args *vargs);
314
ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
315
loff_t *ppos, int dlgt);
316
ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count, loff_t *ppos,
318
ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
319
loff_t *ppos, struct vfsub_args *vargs);
320
ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos,
321
struct vfsub_args *vargs);
322
int vfsub_readdir(struct file *file, filldir_t filldir, void *arg, int dlgt);
323
long vfsub_splice_to(struct file *in, loff_t *ppos,
324
struct pipe_inode_info *pipe, size_t len,
325
unsigned int flags, int dlgt);
326
long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
327
loff_t *ppos, size_t len, unsigned int flags,
328
struct vfsub_args *vargs);
330
int vfsub_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *st,
335
int vfsub_permission(struct inode *inode, int mask, struct nameidata *nd,
338
return do_vfsub_permission(inode, mask, nd);
342
int vfsub_create(struct inode *dir, struct dentry *dentry, int mode,
343
struct nameidata *nd, int dlgt)
345
return do_vfsub_create(dir, dentry, mode, nd);
349
int vfsub_symlink(struct inode *dir, struct dentry *dentry, const char *symname,
352
return do_vfsub_symlink(dir, dentry, symname, mode);
356
int vfsub_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev,
359
return do_vfsub_mknod(dir, dentry, mode, dev);
363
int vfsub_link(struct dentry *src_dentry, struct inode *dir,
364
struct dentry *dentry, int dlgt)
366
return do_vfsub_link(src_dentry, dir, dentry);
370
int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
371
struct inode *dir, struct dentry *dentry,
372
struct vfsub_args *vargs)
377
err = do_vfsub_rename(src_dir, src_dentry, dir, dentry);
379
vfsub_unignore(vargs);
384
int vfsub_mkdir(struct inode *dir, struct dentry *dentry, int mode, int dlgt)
386
return do_vfsub_mkdir(dir, dentry, mode);
390
int vfsub_rmdir(struct inode *dir, struct dentry *dentry,
391
struct vfsub_args *vargs)
396
err = do_vfsub_rmdir(dir, dentry);
398
vfsub_unignore(vargs);
403
ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
404
loff_t *ppos, int dlgt)
406
return do_vfsub_read_u(file, ubuf, count, ppos);
410
ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count, loff_t *ppos,
413
return do_vfsub_read_k(file, kbuf, count, ppos);
417
ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
418
loff_t *ppos, struct vfsub_args *vargs)
423
err = do_vfsub_write_u(file, ubuf, count, ppos);
424
if (unlikely(err < 0))
425
vfsub_unignore(vargs);
430
ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos,
431
struct vfsub_args *vargs)
436
err = do_vfsub_write_k(file, kbuf, count, ppos);
437
if (unlikely(err < 0))
438
vfsub_unignore(vargs);
443
int vfsub_readdir(struct file *file, filldir_t filldir, void *arg, int dlgt)
445
return do_vfsub_readdir(file, filldir, arg);
449
long vfsub_splice_to(struct file *in, loff_t *ppos,
450
struct pipe_inode_info *pipe, size_t len,
451
unsigned int flags, int dlgt)
453
return do_vfsub_splice_to(in, ppos, pipe, len, flags);
457
long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
458
loff_t *ppos, size_t len, unsigned int flags,
459
struct vfsub_args *vargs)
464
err = do_vfsub_splice_from(pipe, out, ppos, len, flags);
465
if (unlikely(err < 0))
466
vfsub_unignore(vargs);
471
int vfsub_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *st,
474
return do_vfsub_getattr(mnt, dentry, st);
476
#endif /* CONFIG_AUFS_DLGT || CONFIG_AUFS_HINOTIFY */
478
/* ---------------------------------------------------------------------- */
480
int vfsub_sio_mkdir(struct inode *dir, struct dentry *dentry, int mode,
482
int vfsub_sio_rmdir(struct inode *dir, struct dentry *dentry, int dlgt);
484
/* ---------------------------------------------------------------------- */
486
int vfsub_notify_change(struct dentry *dentry, struct iattr *ia,
487
struct vfsub_args *vargs);
488
int vfsub_unlink(struct inode *dir, struct dentry *dentry,
489
struct vfsub_args *vargs);
490
int vfsub_statfs(void *arg, struct kstatfs *buf, int dlgt);
492
#endif /* __KERNEL__ */
493
#endif /* __AUFS_VFSUB_H__ */