Skip to content

Commit

Permalink
[PATCH] relayfs: decouple buffer creation from inode creation
Browse files Browse the repository at this point in the history
The patch series implementa or fixes 3 things that were specifically requested
or suggested by relayfs users:

- support for non-relay files (patches 1-6)

Currently, the relayfs API only supports the creation of directories
(relayfs_create_dir()) and relay files (relay_open()).  These patches adds
support for non-relay files (relayfs_create_file()).  This is so relayfs
applications can create 'control files' in relayfs itself rather than in /proc
or via a netlink channel, as is currently done in the relay-app examples.
Basically what this amounts to is exporting relayfs_create_file() with an
additional file_ops param that clients can use to supply file operations for
their own special-purpose files in relayfs.

- make exported relay file ops useful (patches 7-8)

The relayfs relay_file_operations have always been exported, the intent being
to make it possible to create relay files in other filesystems such as
debugfs.  The problem, though, is that currently the file operations are too
tightly coupled to relayfs to actually be used for this purpose.  This patch
fixes that by adding a couple of callback functions that allow a client to
hook into relay_open()/close() and supply the files that will be used to
represent the channel buffers; the default implementation if no callbacks are
defined is to create the files in relayfs.

- add an option to create global relay buffer (patches 9-10) The file creation
callback also supplies an optional param, is_global, that can be used by
clients to create a single global relayfs buffer instead of the default
per-cpu buffers.  This was suggested as being useful for certain debugging
applications where it's more convenient to be able to get all the data from a
single channel without having to go to the bother of dealing with per-cpu
files.

- cleanup, some renaming and Documentation updates (patches 11-12)

There were several comments that the use of netlink in the example code was
non-intuitive and in fact the whole relay-app business was needlessly
confusing.  Based on that feedback, the example code has been completely
converted over to relayfs control files as supported by this patch, and have
also been made completely self-contained.

The converted examples along with a couple of new examples that demonstrate
using exported relay files can be found in relay-apps tarball:
http://prdownloads.sourceforge.net/relayfs/relay-apps-0.9.tar.gz?download

This patch:

Separate buffer create/destroy from inode create/destroy.  We want to be able
to associate other data and not just relay buffers with inodes.  Buffer
create/destroy is moved out of inode.c and into relayfs core code.

Signed-off-by: Tom Zanussi <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Tom Zanussi authored and Linus Torvalds committed Jan 9, 2006
1 parent b33291c commit 6625b86
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 26 deletions.
1 change: 1 addition & 0 deletions fs/relayfs/buffers.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,5 @@ void relay_remove_buf(struct kref *kref)
{
struct rchan_buf *buf = container_of(kref, struct rchan_buf, kref);
relayfs_remove(buf->dentry);
relay_destroy_buf(buf);
}
31 changes: 9 additions & 22 deletions fs/relayfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,13 @@ static struct backing_dev_info relayfs_backing_dev_info = {
};

static struct inode *relayfs_get_inode(struct super_block *sb, int mode,
struct rchan *chan)
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;
Expand All @@ -62,7 +52,7 @@ static struct inode *relayfs_get_inode(struct super_block *sb, int mode,
switch (mode & S_IFMT) {
case S_IFREG:
inode->i_fop = &relayfs_file_operations;
RELAYFS_I(inode)->buf = buf;
RELAYFS_I(inode)->buf = data;
break;
case S_IFDIR:
inode->i_op = &simple_dir_inode_operations;
Expand All @@ -83,7 +73,7 @@ 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
* @data: user-associated data for this file
*
* Returns the new dentry, NULL on failure
*
Expand All @@ -92,7 +82,7 @@ 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)
void *data)
{
struct dentry *d;
struct inode *inode;
Expand Down Expand Up @@ -127,7 +117,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, data);
if (!inode) {
d = NULL;
goto release_mount;
Expand Down Expand Up @@ -155,20 +145,20 @@ static struct dentry *relayfs_create_entry(const char *name,
* @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
* @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)
int mode, void *data)
{
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, data);
}

/**
Expand Down Expand Up @@ -505,9 +495,6 @@ static struct inode *relayfs_alloc_inode(struct super_block *sb)
*/
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));
}

Expand Down
11 changes: 8 additions & 3 deletions fs/relayfs/relay.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,17 @@ static struct rchan_buf *relay_open_buf(struct rchan *chan,
struct rchan_buf *buf;
struct dentry *dentry;

buf = relay_create_buf(chan);
if (!buf)
return NULL;

/* Create file in fs */
dentry = relayfs_create_file(filename, parent, S_IRUSR, chan);
if (!dentry)
dentry = relayfs_create_file(filename, parent, S_IRUSR, buf);
if (!dentry) {
relay_destroy_buf(buf);
return NULL;
}

buf = RELAYFS_I(dentry->d_inode)->buf;
buf->dentry = dentry;
__relay_reset(buf, 1);

Expand Down
2 changes: 1 addition & 1 deletion fs/relayfs/relay.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
struct dentry *relayfs_create_file(const char *name,
struct dentry *parent,
int mode,
struct rchan *chan);
void *data);
extern int relayfs_remove(struct dentry *dentry);
extern int relay_buf_empty(struct rchan_buf *buf);
extern void relay_destroy_channel(struct kref *kref);
Expand Down

0 comments on commit 6625b86

Please sign in to comment.