2
* Copyright (C) 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 in hinotify or dlgt mode
22
* $Id: hin_or_dlgt.c,v 1.2 2008/04/21 02:00:37 sfjro Exp $
24
// I'm going to slightly mad
26
#include <linux/uaccess.h>
29
#if !defined(CONFIG_AUFS_HINOTIFY) && !defined(CONFIG_AUFS_DLGT)
30
#error mis-configuraion or Makefile
33
/* ---------------------------------------------------------------------- */
35
struct permission_args {
42
static void call_permission(void *args)
44
struct permission_args *a = args;
45
*a->errp = do_vfsub_permission(a->inode, a->mask, a->nd);
48
int vfsub_permission(struct inode *inode, int mask, struct nameidata *nd,
52
return do_vfsub_permission(inode, mask, nd);
55
struct permission_args args = {
61
wkq_err = au_wkq_wait(call_permission, &args, /*dlgt*/1);
62
if (unlikely(wkq_err))
68
/* ---------------------------------------------------------------------- */
73
struct dentry *dentry;
78
static void call_create(void *args)
80
struct create_args *a = args;
81
*a->errp = do_vfsub_create(a->dir, a->dentry, a->mode, a->nd);
84
int vfsub_create(struct inode *dir, struct dentry *dentry, int mode,
85
struct nameidata *nd, int dlgt)
88
return do_vfsub_create(dir, dentry, mode, nd);
91
struct create_args args = {
98
wkq_err = au_wkq_wait(call_create, &args, /*dlgt*/1);
99
if (unlikely(wkq_err))
105
struct symlink_args {
108
struct dentry *dentry;
113
static void call_symlink(void *args)
115
struct symlink_args *a = args;
116
*a->errp = do_vfsub_symlink(a->dir, a->dentry, a->symname, a->mode);
119
int vfsub_symlink(struct inode *dir, struct dentry *dentry, const char *symname,
123
return do_vfsub_symlink(dir, dentry, symname, mode);
126
struct symlink_args args = {
133
wkq_err = au_wkq_wait(call_symlink, &args, /*dlgt*/1);
134
if (unlikely(wkq_err))
143
struct dentry *dentry;
148
static void call_mknod(void *args)
150
struct mknod_args *a = args;
151
*a->errp = do_vfsub_mknod(a->dir, a->dentry, a->mode, a->dev);
154
int vfsub_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev,
158
return do_vfsub_mknod(dir, dentry, mode, dev);
161
struct mknod_args args = {
168
wkq_err = au_wkq_wait(call_mknod, &args, /*dlgt*/1);
169
if (unlikely(wkq_err))
178
struct dentry *dentry;
182
static void call_mkdir(void *args)
184
struct mkdir_args *a = args;
185
*a->errp = do_vfsub_mkdir(a->dir, a->dentry, a->mode);
188
int vfsub_mkdir(struct inode *dir, struct dentry *dentry, int mode, int dlgt)
191
return do_vfsub_mkdir(dir, dentry, mode);
194
struct mkdir_args args = {
200
wkq_err = au_wkq_wait(call_mkdir, &args, /*dlgt*/1);
201
if (unlikely(wkq_err))
207
/* ---------------------------------------------------------------------- */
212
struct dentry *src_dentry, *dentry;
215
static void call_link(void *args)
217
struct link_args *a = args;
218
*a->errp = do_vfsub_link(a->src_dentry, a->dir, a->dentry);
221
int vfsub_link(struct dentry *src_dentry, struct inode *dir,
222
struct dentry *dentry, int dlgt)
225
return do_vfsub_link(src_dentry, dir, dentry);
228
struct link_args args = {
230
.src_dentry = src_dentry,
234
wkq_err = au_wkq_wait(call_link, &args, /*dlgt*/1);
235
if (unlikely(wkq_err))
243
struct inode *src_dir, *dir;
244
struct dentry *src_dentry, *dentry;
245
struct vfsub_args *vargs;
248
static void call_rename(void *args)
250
struct rename_args *a = args;
251
vfsub_ignore(a->vargs);
252
*a->errp = do_vfsub_rename(a->src_dir, a->src_dentry, a->dir,
254
if (unlikely(*a->errp))
255
vfsub_unignore(a->vargs);
258
int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
259
struct inode *dir, struct dentry *dentry,
260
struct vfsub_args *vargs)
264
if (!vfsub_ftest(vargs->flags, DLGT)) {
266
err = do_vfsub_rename(src_dir, src_dentry, dir, dentry);
268
vfsub_unignore(vargs);
271
struct rename_args args = {
274
.src_dentry = src_dentry,
279
wkq_err = au_wkq_wait(call_rename, &args, /*dlgt*/1);
280
if (unlikely(wkq_err))
289
struct dentry *dentry;
290
struct vfsub_args *vargs;
293
static void call_rmdir(void *args)
295
struct rmdir_args *a = args;
296
vfsub_ignore(a->vargs);
297
*a->errp = do_vfsub_rmdir(a->dir, a->dentry);
298
if (unlikely(*a->errp))
299
vfsub_unignore(a->vargs);
302
int vfsub_rmdir(struct inode *dir, struct dentry *dentry,
303
struct vfsub_args *vargs)
307
if (!vfsub_ftest(vargs->flags, DLGT)) {
309
err = do_vfsub_rmdir(dir, dentry);
311
vfsub_unignore(vargs);
314
struct rmdir_args args = {
320
wkq_err = au_wkq_wait(call_rmdir, &args, /*dlgt*/1);
321
if (unlikely(wkq_err))
327
/* ---------------------------------------------------------------------- */
340
static void call_read_k(void *args)
342
struct read_args *a = args;
343
LKTRTrace("%.*s, cnt %lu, pos %Ld\n",
344
AuDLNPair(a->file->f_dentry), (unsigned long)a->count,
346
*a->errp = do_vfsub_read_k(a->file, a->kbuf, a->count, a->ppos);
349
ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
350
loff_t *ppos, int dlgt)
353
return do_vfsub_read_u(file, ubuf, count, ppos);
357
struct read_args args = {
364
if (unlikely(!count))
368
* workaround an application bug.
369
* generally, read(2) or write(2) may return the value shorter
370
* than requested. But many applications don't support it,
374
if (args.count > PAGE_SIZE)
375
args.count = PAGE_SIZE;
376
args.kbuf = kmalloc(args.count, GFP_TEMPORARY);
377
if (unlikely(!args.kbuf))
382
wkq_err = au_wkq_wait(call_read_k, &args, /*dlgt*/1);
383
if (unlikely(wkq_err))
386
&& copy_to_user(ubuf, args.kbuf, err))) {
391
else if (unlikely(err < 0))
394
/* do not read too much because of file i/o pointer */
395
if (count < args.count)
400
smp_mb(); /* flush ubuf */
410
ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count, loff_t *ppos,
414
return do_vfsub_read_k(file, kbuf, count, ppos);
418
struct read_args args = {
425
wkq_err = au_wkq_wait(call_read_k, &args, /*dlgt*/1);
426
if (unlikely(wkq_err))
437
const char __user *ubuf;
442
struct vfsub_args *vargs;
445
static void call_write_k(void *args)
447
struct write_args *a = args;
448
LKTRTrace("%.*s, cnt %lu, pos %Ld\n",
449
AuDLNPair(a->file->f_dentry), (unsigned long)a->count,
451
vfsub_ignore(a->vargs);
452
*a->errp = do_vfsub_write_k(a->file, a->kbuf, a->count, a->ppos);
453
if (unlikely(*a->errp < 0))
454
vfsub_unignore(a->vargs);
457
ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
458
loff_t *ppos, struct vfsub_args *vargs)
462
if (!vfsub_ftest(vargs->flags, DLGT)) {
464
err = do_vfsub_write_u(file, ubuf, count, ppos);
465
if (unlikely(err < 0))
466
vfsub_unignore(vargs);
470
struct write_args args = {
478
if (unlikely(!count))
482
* workaround an application bug.
483
* generally, read(2) or write(2) may return the value shorter
484
* than requested. But many applications don't support it,
488
if (args.count > PAGE_SIZE)
489
args.count = PAGE_SIZE;
490
args.kbuf = kmalloc(args.count, GFP_TEMPORARY);
491
if (unlikely(!args.kbuf))
496
if (unlikely(copy_from_user(args.kbuf, ubuf,
502
wkq_err = au_wkq_wait(call_write_k, &args, /*dlgt*/1);
503
if (unlikely(wkq_err))
507
if (count < args.count)
513
else if (unlikely(err < 0))
525
ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos,
526
struct vfsub_args *vargs)
530
if (!vfsub_ftest(vargs->flags, DLGT)) {
532
err = do_vfsub_write_k(file, kbuf, count, ppos);
533
if (unlikely(err < 0))
534
vfsub_unignore(vargs);
537
struct write_args args = {
545
wkq_err = au_wkq_wait(call_write_k, &args, /*dlgt*/1);
546
if (unlikely(wkq_err))
552
struct readdir_args {
559
static void call_readdir(void *args)
561
struct readdir_args *a = args;
562
*a->errp = do_vfsub_readdir(a->file, a->filldir, a->arg);
565
int vfsub_readdir(struct file *file, filldir_t filldir, void *arg, int dlgt)
568
return do_vfsub_readdir(file, filldir, arg);
571
struct readdir_args args = {
577
wkq_err = au_wkq_wait(call_readdir, &args, /*dlgt*/1);
578
if (unlikely(wkq_err))
584
/* ---------------------------------------------------------------------- */
586
struct splice_to_args {
590
struct pipe_inode_info *pipe;
595
static void call_splice_to(void *args)
597
struct splice_to_args *a = args;
598
*a->errp = do_vfsub_splice_to(a->in, a->ppos, a->pipe, a->len,
602
long vfsub_splice_to(struct file *in, loff_t *ppos,
603
struct pipe_inode_info *pipe, size_t len,
604
unsigned int flags, int dlgt)
607
return do_vfsub_splice_to(in, ppos, pipe, len, flags);
611
struct splice_to_args args = {
619
wkq_err = au_wkq_wait(call_splice_to, &args, /*dlgt*/1);
620
if (unlikely(wkq_err))
626
struct splice_from_args {
628
struct pipe_inode_info *pipe;
633
struct vfsub_args *vargs;
636
static void call_splice_from(void *args)
638
struct splice_from_args *a = args;
639
vfsub_ignore(a->vargs);
640
*a->errp = do_vfsub_splice_from(a->pipe, a->out, a->ppos, a->len,
642
if (unlikely(*a->errp < 0))
643
vfsub_unignore(a->vargs);
646
long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
647
loff_t *ppos, size_t len, unsigned int flags,
648
struct vfsub_args *vargs)
652
if (!vfsub_ftest(vargs->flags, DLGT)) {
654
err = do_vfsub_splice_from(pipe, out, ppos, len, flags);
655
if (unlikely(err < 0))
656
vfsub_unignore(vargs);
659
struct splice_from_args args = {
668
wkq_err = au_wkq_wait(call_splice_from, &args, /*dlgt*/1);
669
if (unlikely(wkq_err))
675
/* ---------------------------------------------------------------------- */
677
struct getattr_args {
679
struct vfsmount *mnt;
680
struct dentry *dentry;
684
static void call_getattr(void *args)
686
struct getattr_args *a = args;
687
*a->errp = do_vfsub_getattr(a->mnt, a->dentry, a->st);
690
int vfsub_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *st,
694
return do_vfsub_getattr(mnt, dentry, st);
697
struct getattr_args args = {
703
wkq_err = au_wkq_wait(call_getattr, &args, /*dlgt*/1);
704
if (unlikely(wkq_err))