Commit b5bd8ebf authored by J. R. Okajima's avatar J. R. Okajima
Browse files

aufs: file op, open non-dir



Implement f_op->open() for non-directory.
Signed-off-by: default avatarJ. R. Okajima <hooanon05g@gmail.com>
parent a76ab411
...@@ -15,7 +15,7 @@ aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o \ ...@@ -15,7 +15,7 @@ aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o \
cpup.o whout.o wbr_policy.o \ cpup.o whout.o wbr_policy.o \
dinfo.o dentry.o \ dinfo.o dentry.o \
dynop.o \ dynop.o \
finfo.o file.o \ finfo.o file.o f_op.o \
dir.o vdir.o \ dir.o vdir.o \
iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o
......
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2005-2019 Junjiro R. Okajima
*/
/*
* file and vm operations
*/
#include "aufs.h"
int au_do_open_nondir(struct file *file, int flags)
{
int err;
aufs_bindex_t bindex;
struct file *h_file;
struct dentry *dentry;
struct au_finfo *finfo;
struct inode *h_inode;
FiMustWriteLock(file);
err = 0;
dentry = file->f_path.dentry;
finfo = au_fi(file);
memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop));
bindex = au_dbtop(dentry);
h_file = au_h_open(dentry, bindex, flags, file);
if (IS_ERR(h_file))
err = PTR_ERR(h_file);
else {
if ((flags & __O_TMPFILE)
&& !(flags & O_EXCL)) {
h_inode = file_inode(h_file);
spin_lock(&h_inode->i_lock);
h_inode->i_state |= I_LINKABLE;
spin_unlock(&h_inode->i_lock);
}
au_set_fbtop(file, bindex);
au_set_h_fptr(file, bindex, h_file);
au_update_figen(file);
/* todo: necessary? */
/* file->f_ra = h_file->f_ra; */
}
return err;
}
static int aufs_open_nondir(struct inode *inode __maybe_unused,
struct file *file)
{
int err;
struct super_block *sb;
struct au_do_open_args args = {
.open = au_do_open_nondir
};
AuDbg("%pD, f_flags 0x%x, f_mode 0x%x\n",
file, vfsub_file_flags(file), file->f_mode);
sb = file->f_path.dentry->d_sb;
si_read_lock(sb, AuLock_FLUSH);
err = au_do_open(file, &args);
si_read_unlock(sb);
return err;
}
int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file)
{
struct au_finfo *finfo;
aufs_bindex_t bindex;
finfo = au_fi(file);
bindex = finfo->fi_btop;
if (bindex >= 0)
au_set_h_fptr(file, bindex, NULL);
au_finfo_fin(file);
return 0;
}
/* ---------------------------------------------------------------------- */
const struct file_operations aufs_file_fop = {
.owner = THIS_MODULE,
.open = aufs_open_nondir,
.release = aufs_release_nondir
};
...@@ -82,6 +82,33 @@ out: ...@@ -82,6 +82,33 @@ out:
return h_file; return h_file;
} }
int au_do_open(struct file *file, struct au_do_open_args *args)
{
int err;
struct dentry *dentry;
struct au_finfo *finfo;
err = au_finfo_init(file, args->fidir);
if (unlikely(err))
goto out;
dentry = file->f_path.dentry;
di_read_lock_child(dentry, AuLock_IR);
err = args->open(file, vfsub_file_flags(file));
di_read_unlock(dentry, AuLock_IR);
finfo = au_fi(file);
fi_write_unlock(file);
if (unlikely(err)) {
finfo->fi_hdir = NULL;
au_finfo_fin(file);
}
out:
AuTraceErr(err);
return err;
}
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
static int au_file_refresh_by_inode(struct file *file, int *need_reopen) static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
......
...@@ -55,9 +55,20 @@ extern const struct address_space_operations aufs_aop; ...@@ -55,9 +55,20 @@ extern const struct address_space_operations aufs_aop;
unsigned int au_file_roflags(unsigned int flags); unsigned int au_file_roflags(unsigned int flags);
struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags, struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
struct file *file); struct file *file);
struct au_do_open_args {
int (*open)(struct file *file, int flags);
struct au_fidir *fidir;
/* add more later */
};
int au_do_open(struct file *file, struct au_do_open_args *args);
int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file), int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
int wlock, unsigned int fi_lsc); int wlock, unsigned int fi_lsc);
/* f_op.c */
extern const struct file_operations aufs_file_fop;
int au_do_open_nondir(struct file *file, int flags);
int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file);
/* finfo.c */ /* finfo.c */
void au_hfput(struct au_hfile *hf, int execed); void au_hfput(struct au_hfile *hf, int execed);
void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
......
...@@ -214,9 +214,7 @@ static int set_inode(struct inode *inode, struct dentry *dentry) ...@@ -214,9 +214,7 @@ static int set_inode(struct inode *inode, struct dentry *dentry)
case S_IFREG: case S_IFREG:
btail = au_dbtail(dentry); btail = au_dbtail(dentry);
inode->i_op = iop + AuIop_OTHER; inode->i_op = iop + AuIop_OTHER;
#if 0 /* re-commit later */
inode->i_fop = &aufs_file_fop; inode->i_fop = &aufs_file_fop;
#endif
err = au_dy_iaop(inode, btop, h_inode); err = au_dy_iaop(inode, btop, h_inode);
if (unlikely(err)) if (unlikely(err))
goto out; goto out;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment