aboutsummaryrefslogtreecommitdiffstats
path: root/fs/kernfs/dir.c
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2013-12-11 16:03:00 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-12-17 11:59:15 -0500
commit80b9bbefc345079bddc4959de016ba4074b0c8d6 (patch)
tree24d24636b01d9f9e31b39e08a8cfd0978ce9fd9d /fs/kernfs/dir.c
parent19bbb926203dbcf3a03915e934c36d7681bf6e13 (diff)
kernfs: add kernfs_dir_ops
Add support for mkdir(2), rmdir(2) and rename(2) syscalls. This is implemented through optional kernfs_dir_ops callback table which can be specified on kernfs_create_root(). An implemented callback is invoked when the matching syscall is invoked. As kernfs keep dcache syncs with internal representation and revalidates dentries on each access, the implementation of these methods is extremely simple. Each just discovers the relevant kernfs_node(s) and invokes the requested callback which is allowed to do any kernfs operations and the end result doesn't necessarily have to match the expected semantics of the syscall. This will be used to convert cgroup to use kernfs instead of its own filesystem implementation. Signed-off-by: Tejun Heo <tj@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'fs/kernfs/dir.c')
-rw-r--r--fs/kernfs/dir.c44
1 files changed, 43 insertions, 1 deletions
diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
index 42c5b9f23b41..510b5062ef30 100644
--- a/fs/kernfs/dir.c
+++ b/fs/kernfs/dir.c
@@ -583,12 +583,13 @@ EXPORT_SYMBOL_GPL(kernfs_find_and_get_ns);
583 583
584/** 584/**
585 * kernfs_create_root - create a new kernfs hierarchy 585 * kernfs_create_root - create a new kernfs hierarchy
586 * @kdops: optional directory syscall operations for the hierarchy
586 * @priv: opaque data associated with the new directory 587 * @priv: opaque data associated with the new directory
587 * 588 *
588 * Returns the root of the new hierarchy on success, ERR_PTR() value on 589 * Returns the root of the new hierarchy on success, ERR_PTR() value on
589 * failure. 590 * failure.
590 */ 591 */
591struct kernfs_root *kernfs_create_root(void *priv) 592struct kernfs_root *kernfs_create_root(struct kernfs_dir_ops *kdops, void *priv)
592{ 593{
593 struct kernfs_root *root; 594 struct kernfs_root *root;
594 struct kernfs_node *kn; 595 struct kernfs_node *kn;
@@ -610,6 +611,7 @@ struct kernfs_root *kernfs_create_root(void *priv)
610 kn->priv = priv; 611 kn->priv = priv;
611 kn->dir.root = root; 612 kn->dir.root = root;
612 613
614 root->dir_ops = kdops;
613 root->kn = kn; 615 root->kn = kn;
614 616
615 return root; 617 return root;
@@ -706,6 +708,42 @@ static struct dentry *kernfs_iop_lookup(struct inode *dir,
706 return ret; 708 return ret;
707} 709}
708 710
711static int kernfs_iop_mkdir(struct inode *dir, struct dentry *dentry,
712 umode_t mode)
713{
714 struct kernfs_node *parent = dir->i_private;
715 struct kernfs_dir_ops *kdops = kernfs_root(parent)->dir_ops;
716
717 if (!kdops || !kdops->mkdir)
718 return -EPERM;
719
720 return kdops->mkdir(parent, dentry->d_name.name, mode);
721}
722
723static int kernfs_iop_rmdir(struct inode *dir, struct dentry *dentry)
724{
725 struct kernfs_node *kn = dentry->d_fsdata;
726 struct kernfs_dir_ops *kdops = kernfs_root(kn)->dir_ops;
727
728 if (!kdops || !kdops->rmdir)
729 return -EPERM;
730
731 return kdops->rmdir(kn);
732}
733
734static int kernfs_iop_rename(struct inode *old_dir, struct dentry *old_dentry,
735 struct inode *new_dir, struct dentry *new_dentry)
736{
737 struct kernfs_node *kn = old_dentry->d_fsdata;
738 struct kernfs_node *new_parent = new_dir->i_private;
739 struct kernfs_dir_ops *kdops = kernfs_root(kn)->dir_ops;
740
741 if (!kdops || !kdops->rename)
742 return -EPERM;
743
744 return kdops->rename(kn, new_parent, new_dentry->d_name.name);
745}
746
709const struct inode_operations kernfs_dir_iops = { 747const struct inode_operations kernfs_dir_iops = {
710 .lookup = kernfs_iop_lookup, 748 .lookup = kernfs_iop_lookup,
711 .permission = kernfs_iop_permission, 749 .permission = kernfs_iop_permission,
@@ -715,6 +753,10 @@ const struct inode_operations kernfs_dir_iops = {
715 .removexattr = kernfs_iop_removexattr, 753 .removexattr = kernfs_iop_removexattr,
716 .getxattr = kernfs_iop_getxattr, 754 .getxattr = kernfs_iop_getxattr,
717 .listxattr = kernfs_iop_listxattr, 755 .listxattr = kernfs_iop_listxattr,
756
757 .mkdir = kernfs_iop_mkdir,
758 .rmdir = kernfs_iop_rmdir,
759 .rename = kernfs_iop_rename,
718}; 760};
719 761
720static struct kernfs_node *kernfs_leftmost_descendant(struct kernfs_node *pos) 762static struct kernfs_node *kernfs_leftmost_descendant(struct kernfs_node *pos)