Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added atomic_open hook #3

Merged
merged 2 commits into from
Jan 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/redirfs/redirfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#include <linux/aio.h>
#include <linux/version.h>

#define REDIRFS_VERSION "0.13 EXPERIMENTAL"
#define REDIRFS_VERSION "0.14 EXPERIMENTAL"

#define REDIRFS_PATH_INCLUDE 1
#define REDIRFS_PATH_EXCLUDE 2
Expand Down Expand Up @@ -283,6 +283,7 @@ enum redirfs_op_idc {
#endif
REDIRFS_DIR_IOP_PERMISSION = RFS_OP_IDC(RFS_INODE_DIR, RFS_OP_i_permission),
REDIRFS_DIR_IOP_SETATTR = RFS_OP_IDC(RFS_INODE_DIR, RFS_OP_i_setattr),
REDIRFS_DIR_IOP_ATOMIC_OPEN = RFS_OP_IDC(RFS_INODE_DIR, RFS_OP_i_atomic_open),

REDIRFS_CHR_IOP_PERMISSION = RFS_OP_IDC(RFS_INODE_CHAR, RFS_OP_i_permission),
REDIRFS_CHR_IOP_SETATTR = RFS_OP_IDC(RFS_INODE_CHAR, RFS_OP_i_setattr),
Expand Down Expand Up @@ -605,6 +606,17 @@ union redirfs_op_args {
struct iattr *iattr;
} i_setattr;

#if (LINUX_VERSION_CODE > KERNEL_VERSION(3,5,0))
struct {
struct inode *inode;
struct dentry *dentry;
struct file *file;
unsigned open_flag;
umode_t create_mode;
int *opened;
} i_atomic_open;
#endif

struct {
struct inode *inode;
struct file *file;
Expand Down
1 change: 1 addition & 0 deletions src/redirfs/rfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,7 @@ void rfs_file_put(struct rfs_file *rfile);
void rfs_file_set_ops(struct rfs_file *rfile);
int rfs_file_cache_create(void);
void rfs_file_cache_destory(void);
struct rfs_file *rfs_file_add(struct file *file);

void rfs_add_dir_subs(
struct rfs_file *rfile,
Expand Down
2 changes: 1 addition & 1 deletion src/redirfs/rfs_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ static void rfs_file_free(struct rfs_object *robject)

/*---------------------------------------------------------------------------*/

static struct rfs_file *rfs_file_add(struct file *file)
struct rfs_file *rfs_file_add(struct file *file)
{
struct rfs_file *rfile;
int err;
Expand Down
60 changes: 59 additions & 1 deletion src/redirfs/rfs_inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -1425,6 +1425,61 @@ int rfs_rename(struct inode *old_dir, struct dentry *old_dentry,
}
#endif //(LINUX_VERSION_CODE < KERNEL_VERSION(3,17,0))

#if (LINUX_VERSION_CODE > KERNEL_VERSION(3,5,0))
int rfs_atomic_open(struct inode *inode, struct dentry *dentry, struct file *file, unsigned open_flag, umode_t create_mode, int *opened)
{
struct rfs_inode *rinode;
struct rfs_info *rinfo;
struct rfs_context rcont;
struct rfs_file *rfile;
RFS_DEFINE_REDIRFS_ARGS(rargs);

rinode = rfs_inode_find(inode);
rinfo = rfs_inode_get_rinfo(rinode);
rfs_context_init(&rcont, 0);
rargs.type.id = REDIRFS_DIR_IOP_ATOMIC_OPEN;
rargs.args.i_atomic_open.inode = inode;
rargs.args.i_atomic_open.dentry = dentry;
rargs.args.i_atomic_open.file = file;
rargs.args.i_atomic_open.open_flag = open_flag;
rargs.args.i_atomic_open.create_mode = create_mode;
rargs.args.i_atomic_open.opened = opened;
rargs.rv.rv_int = -ENOSYS;

if (!RFS_IS_IOP_SET(rinode, rargs.type.id) ||
!rfs_precall_flts(rinfo->rchain, &rcont, &rargs)) {
if (rinode->op_old && rinode->op_old->atomic_open)
rargs.rv.rv_int = rinode->op_old->atomic_open(
rargs.args.i_atomic_open.inode,
rargs.args.i_atomic_open.dentry,
rargs.args.i_atomic_open.file,
rargs.args.i_atomic_open.open_flag,
rargs.args.i_atomic_open.create_mode,
rargs.args.i_atomic_open.opened);
} else {
rargs.rv.rv_int = -EACCES;
}

if (!rargs.rv.rv_int) {
if (rfs_dcache_rdentry_add(dentry, rinfo))
BUG();
rfile = rfs_file_add(file);
if (IS_ERR(rfile))
BUG();
rfs_file_put(rfile);
}

if (RFS_IS_IOP_SET(rinode, rargs.type.id))
rfs_postcall_flts(rinfo->rchain, &rcont, &rargs);

rfs_context_deinit(&rcont);

rfs_inode_put(rinode);
rfs_info_put(rinfo);
return rargs.rv.rv_int;
}
#endif

/*---------------------------------------------------------------------------*/

/*
Expand Down Expand Up @@ -1458,11 +1513,14 @@ static void rfs_inode_set_ops_dir(struct rfs_inode *rinode)
RFS_SET_IOP_MGT(rinode, REDIRFS_DIR_IOP_SYMLINK, symlink, rfs_symlink);

//
// the following two operations are required to support hooking,
// the following operations are required to support hooking,
// their registration do not dependent on registered filters
//
RFS_SET_IOP_MGT(rinode, REDIRFS_DIR_IOP_LOOKUP, lookup, rfs_lookup);
RFS_SET_IOP_MGT(rinode, REDIRFS_DIR_IOP_MKDIR, mkdir, rfs_mkdir);
#if (LINUX_VERSION_CODE > KERNEL_VERSION(3,5,0))
RFS_SET_IOP_MGT(rinode, REDIRFS_DIR_IOP_ATOMIC_OPEN, atomic_open, rfs_atomic_open);
#endif
}

static void rfs_inode_set_ops_lnk(struct rfs_inode *rinode)
Expand Down
5 changes: 4 additions & 1 deletion src/redirfs/rfs_path.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ static int rfs_path_add_dirs(struct dentry *dentry)

static int rfs_path_check_fs(struct file_system_type *type)
{
return 0;
/*
if (!strcmp("cifs", type->name))
goto notsup;

Expand All @@ -275,6 +277,7 @@ static int rfs_path_check_fs(struct file_system_type *type)
printk(KERN_ERR "redirfs does not support '%s' file system\n",
type->name);
return -1;
*/
}

static int rfs_path_add_include(struct rfs_path *rpath, struct rfs_flt *rflt)
Expand Down Expand Up @@ -1034,4 +1037,4 @@ EXPORT_SYMBOL(redirfs_get_path_id);

#ifdef RFS_DBG
#pragma GCC pop_options
#endif // RFS_DBG
#endif // RFS_DBG