]> err.no Git - linux-2.6/blobdiff - fs/relayfs/inode.c
[PATCH] relayfs: add support for global relay buffers
[linux-2.6] / fs / relayfs / inode.c
index 0f7f88d067adad67b0d846fc9ebfb2f7109f3202..b4c3e0466e987f0d9a5ae060bcdc25bb67d49e12 100644 (file)
 
 static struct vfsmount *               relayfs_mount;
 static int                             relayfs_mount_count;
-static kmem_cache_t *                  relayfs_inode_cachep;
 
 static struct backing_dev_info         relayfs_backing_dev_info = {
        .ra_pages       = 0,    /* No readahead */
        .capabilities   = BDI_CAP_NO_ACCT_DIRTY | BDI_CAP_NO_WRITEBACK,
 };
 
-static struct inode *relayfs_get_inode(struct super_block *sb, int mode,
-                                      struct rchan *chan)
+static struct inode *relayfs_get_inode(struct super_block *sb,
+                                      int mode,
+                                      struct file_operations *fops,
+                                      void *data)
 {
-       struct rchan_buf *buf = NULL;
        struct inode *inode;
 
-       if (S_ISREG(mode)) {
-               BUG_ON(!chan);
-               buf = relay_create_buf(chan);
-               if (!buf)
-                       return NULL;
-       }
-
        inode = new_inode(sb);
-       if (!inode) {
-               relay_destroy_buf(buf);
+       if (!inode)
                return NULL;
-       }
 
        inode->i_mode = mode;
        inode->i_uid = 0;
@@ -61,8 +52,9 @@ static struct inode *relayfs_get_inode(struct super_block *sb, int mode,
        inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
        switch (mode & S_IFMT) {
        case S_IFREG:
-               inode->i_fop = &relayfs_file_operations;
-               RELAYFS_I(inode)->buf = buf;
+               inode->i_fop = fops;
+               if (data)
+                       inode->u.generic_ip = data;
                break;
        case S_IFDIR:
                inode->i_op = &simple_dir_inode_operations;
@@ -83,7 +75,8 @@ static struct inode *relayfs_get_inode(struct super_block *sb, int mode,
  *     @name: the name of the file to create
  *     @parent: parent directory
  *     @mode: mode
- *     @chan: relay channel associated with the file
+ *     @fops: file operations to use for the file
+ *     @data: user-associated data for this file
  *
  *     Returns the new dentry, NULL on failure
  *
@@ -92,7 +85,8 @@ static struct inode *relayfs_get_inode(struct super_block *sb, int mode,
 static struct dentry *relayfs_create_entry(const char *name,
                                           struct dentry *parent,
                                           int mode,
-                                          struct rchan *chan)
+                                          struct file_operations *fops,
+                                          void *data)
 {
        struct dentry *d;
        struct inode *inode;
@@ -127,7 +121,7 @@ static struct dentry *relayfs_create_entry(const char *name,
                goto release_mount;
        }
 
-       inode = relayfs_get_inode(parent->d_inode->i_sb, mode, chan);
+       inode = relayfs_get_inode(parent->d_inode->i_sb, mode, fops, data);
        if (!inode) {
                d = NULL;
                goto release_mount;
@@ -155,20 +149,26 @@ exit:
  *     @name: the name of the file to create
  *     @parent: parent directory
  *     @mode: mode, if not specied the default perms are used
- *     @chan: channel associated with the file
+ *     @fops: file operations to use for the file
+ *     @data: user-associated data for this file
  *
  *     Returns file dentry if successful, NULL otherwise.
  *
  *     The file will be created user r on behalf of current user.
  */
-struct dentry *relayfs_create_file(const char *name, struct dentry *parent,
-                                  int mode, struct rchan *chan)
+struct dentry *relayfs_create_file(const char *name,
+                                  struct dentry *parent,
+                                  int mode,
+                                  struct file_operations *fops,
+                                  void *data)
 {
+       BUG_ON(!fops);
+
        if (!mode)
                mode = S_IRUSR;
        mode = (mode & S_IALLUGO) | S_IFREG;
 
-       return relayfs_create_entry(name, parent, mode, chan);
+       return relayfs_create_entry(name, parent, mode, fops, data);
 }
 
 /**
@@ -183,7 +183,7 @@ struct dentry *relayfs_create_file(const char *name, struct dentry *parent,
 struct dentry *relayfs_create_dir(const char *name, struct dentry *parent)
 {
        int mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
-       return relayfs_create_entry(name, parent, mode, NULL);
+       return relayfs_create_entry(name, parent, mode, NULL, NULL);
 }
 
 /**
@@ -224,6 +224,17 @@ int relayfs_remove(struct dentry *dentry)
        return error;
 }
 
+/**
+ *     relayfs_remove_file - remove a file from relay filesystem
+ *     @dentry: directory dentry
+ *
+ *     Returns 0 if successful, negative otherwise.
+ */
+int relayfs_remove_file(struct dentry *dentry)
+{
+       return relayfs_remove(dentry);
+}
+
 /**
  *     relayfs_remove_dir - remove a directory in the relay filesystem
  *     @dentry: directory dentry
@@ -244,8 +255,9 @@ int relayfs_remove_dir(struct dentry *dentry)
  */
 static int relayfs_open(struct inode *inode, struct file *filp)
 {
-       struct rchan_buf *buf = RELAYFS_I(inode)->buf;
+       struct rchan_buf *buf = inode->u.generic_ip;
        kref_get(&buf->kref);
+       filp->private_data = buf;
 
        return 0;
 }
@@ -259,8 +271,8 @@ static int relayfs_open(struct inode *inode, struct file *filp)
  */
 static int relayfs_mmap(struct file *filp, struct vm_area_struct *vma)
 {
-       struct inode *inode = filp->f_dentry->d_inode;
-       return relay_mmap_buf(RELAYFS_I(inode)->buf, vma);
+       struct rchan_buf *buf = filp->private_data;
+       return relay_mmap_buf(buf, vma);
 }
 
 /**
@@ -273,8 +285,7 @@ static int relayfs_mmap(struct file *filp, struct vm_area_struct *vma)
 static unsigned int relayfs_poll(struct file *filp, poll_table *wait)
 {
        unsigned int mask = 0;
-       struct inode *inode = filp->f_dentry->d_inode;
-       struct rchan_buf *buf = RELAYFS_I(inode)->buf;
+       struct rchan_buf *buf = filp->private_data;
 
        if (buf->finalized)
                return POLLERR;
@@ -298,7 +309,7 @@ static unsigned int relayfs_poll(struct file *filp, poll_table *wait)
  */
 static int relayfs_release(struct inode *inode, struct file *filp)
 {
-       struct rchan_buf *buf = RELAYFS_I(inode)->buf;
+       struct rchan_buf *buf = filp->private_data;
        kref_put(&buf->kref, relay_remove_buf);
 
        return 0;
@@ -459,8 +470,8 @@ static ssize_t relayfs_read(struct file *filp,
                            size_t count,
                            loff_t *ppos)
 {
+       struct rchan_buf *buf = filp->private_data;
        struct inode *inode = filp->f_dentry->d_inode;
-       struct rchan_buf *buf = RELAYFS_I(inode)->buf;
        size_t read_start, avail;
        ssize_t ret = 0;
        void *from;
@@ -487,37 +498,6 @@ out:
        return ret;
 }
 
-/**
- *     relayfs alloc_inode() implementation
- */
-static struct inode *relayfs_alloc_inode(struct super_block *sb)
-{
-       struct relayfs_inode_info *p = kmem_cache_alloc(relayfs_inode_cachep, SLAB_KERNEL);
-       if (!p)
-               return NULL;
-       p->buf = NULL;
-
-       return &p->vfs_inode;
-}
-
-/**
- *     relayfs destroy_inode() implementation
- */
-static void relayfs_destroy_inode(struct inode *inode)
-{
-       if (RELAYFS_I(inode)->buf)
-               relay_destroy_buf(RELAYFS_I(inode)->buf);
-
-       kmem_cache_free(relayfs_inode_cachep, RELAYFS_I(inode));
-}
-
-static void init_once(void *p, kmem_cache_t *cachep, unsigned long flags)
-{
-       struct relayfs_inode_info *i = p;
-       if ((flags & (SLAB_CTOR_VERIFY | SLAB_CTOR_CONSTRUCTOR)) == SLAB_CTOR_CONSTRUCTOR)
-               inode_init_once(&i->vfs_inode);
-}
-
 struct file_operations relayfs_file_operations = {
        .open           = relayfs_open,
        .poll           = relayfs_poll,
@@ -530,8 +510,6 @@ struct file_operations relayfs_file_operations = {
 static struct super_operations relayfs_ops = {
        .statfs         = simple_statfs,
        .drop_inode     = generic_delete_inode,
-       .alloc_inode    = relayfs_alloc_inode,
-       .destroy_inode  = relayfs_destroy_inode,
 };
 
 static int relayfs_fill_super(struct super_block * sb, void * data, int silent)
@@ -544,7 +522,7 @@ static int relayfs_fill_super(struct super_block * sb, void * data, int silent)
        sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
        sb->s_magic = RELAYFS_MAGIC;
        sb->s_op = &relayfs_ops;
-       inode = relayfs_get_inode(sb, mode, NULL);
+       inode = relayfs_get_inode(sb, mode, NULL, NULL);
 
        if (!inode)
                return -ENOMEM;
@@ -575,25 +553,12 @@ static struct file_system_type relayfs_fs_type = {
 
 static int __init init_relayfs_fs(void)
 {
-       int err;
-
-       relayfs_inode_cachep = kmem_cache_create("relayfs_inode_cache",
-                               sizeof(struct relayfs_inode_info), 0,
-                               0, init_once, NULL);
-       if (!relayfs_inode_cachep)
-               return -ENOMEM;
-
-       err = register_filesystem(&relayfs_fs_type);
-       if (err)
-               kmem_cache_destroy(relayfs_inode_cachep);
-
-       return err;
+       return register_filesystem(&relayfs_fs_type);
 }
 
 static void __exit exit_relayfs_fs(void)
 {
        unregister_filesystem(&relayfs_fs_type);
-       kmem_cache_destroy(relayfs_inode_cachep);
 }
 
 module_init(init_relayfs_fs)
@@ -602,6 +567,8 @@ module_exit(exit_relayfs_fs)
 EXPORT_SYMBOL_GPL(relayfs_file_operations);
 EXPORT_SYMBOL_GPL(relayfs_create_dir);
 EXPORT_SYMBOL_GPL(relayfs_remove_dir);
+EXPORT_SYMBOL_GPL(relayfs_create_file);
+EXPORT_SYMBOL_GPL(relayfs_remove_file);
 
 MODULE_AUTHOR("Tom Zanussi <zanussi@us.ibm.com> and Karim Yaghmour <karim@opersys.com>");
 MODULE_DESCRIPTION("Relay Filesystem");