Skip to content

Commit

Permalink
added stats file with bytes and packet count
Browse files Browse the repository at this point in the history
  • Loading branch information
beraldoleal committed Jun 1, 2013
1 parent 8c5a582 commit 2292d00
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 12 deletions.
40 changes: 28 additions & 12 deletions inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,39 @@ struct netsfs_file_private {
netsfs_file_type_t type;
};

struct netsfs_dir_private {
u64 count; // how many frames/packets
u64 errors; // how many errors
loff_t bytes; // total bytes
};

static ssize_t netsfs_file_read(struct file *file, char __user *buf,
size_t count, loff_t *ppos)
{
ssize_t length;
struct netsfs_file_private *f_private;
struct netsfs_dir_private *d_private;
char line[100];


length = -ENOMEM;
length = sprintf(line, "type: %d\n", ((struct netsfs_file_private *) file->f_dentry->d_inode->i_private)->type);
if (length >0)
length = simple_read_from_buffer(buf, count, ppos, line, length);
f_private = file->f_dentry->d_inode->i_private;
d_private = file->f_dentry->d_parent->d_inode->i_private;

if (f_private->type == NETSFS_STATS) {
length = sprintf(line, "bytes: %lld\ncount: %lld\n", d_private->bytes, d_private->count);
if (length >0)
length = simple_read_from_buffer(buf, count, ppos, line, length);
return length;
}

/*
printk("AQUI: %lld\n",
((struct netsfs_dir_private *) file->f_dentry->d_parent->d_inode->i_private)->bytes);
*/


return length;
return 0;
}

const struct inode_operations netsfs_dir_inode_operations = {
Expand Down Expand Up @@ -80,11 +101,6 @@ const match_table_t tokens = {
{Opt_err, NULL}
};

struct netsfs_dir_private {
u64 count; // how many frames/packets
u64 errors; // how many errors
loff_t bytes; // total bytes
};



Expand All @@ -102,15 +118,17 @@ extern void netsfs_inc_inode_size(struct inode *inode, loff_t inc)
oldsize = i_size_read(inode);
newsize = oldsize + inc;
i_size_write(inode, newsize);
spin_unlock(&inode->i_lock);

if (inode->i_private == NULL) {
private = kmalloc(sizeof(struct netsfs_dir_private), GFP_KERNEL);
private->bytes = newsize;
private->count = 1;
inode->i_private = private; // LOCK HERE
}else{
((struct netsfs_dir_private *) inode->i_private)->bytes = newsize;
((struct netsfs_dir_private *) inode->i_private)->count += 1;
}
spin_unlock(&inode->i_lock);
}


Expand Down Expand Up @@ -199,8 +217,6 @@ extern int netsfs_mkdir(struct inode * dir, struct dentry * dentry, int mode)
}

return retval;


}

extern int netsfs_create(struct inode *dir, struct dentry *dentry, int mode,
Expand Down
13 changes: 13 additions & 0 deletions proto.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,34 @@ static void netsfs_go(struct work_struct *work)

printk("Worker: %s %s %d\n", netsfsinfo->mac_name, netsfsinfo->network_name, netsfsinfo->len);

/* Create mac dir */
netsfs_create_by_name(netsfsinfo->mac_name, S_IFDIR, NULL, &mac_dentry, NULL, NETSFS_DIR);
/* Create top level stats and stream files */
netsfs_create_by_name("stats", S_IFREG, NULL, &network_stats_dentry, NULL, NETSFS_STATS);
netsfs_create_by_name("stream", S_IFREG, NULL, &network_stats_dentry, NULL, NETSFS_STREAM);

if (mac_dentry) {
netsfs_create_by_name("stats", S_IFREG, mac_dentry, &network_stats_dentry, NULL, NETSFS_STATS);
netsfs_create_by_name("stream", S_IFREG, mac_dentry, &network_stats_dentry, NULL, NETSFS_STREAM);
netsfs_create_by_name(netsfsinfo->network_name, S_IFDIR, mac_dentry, &network_dentry, NULL, NETSFS_DIR);
if (network_dentry) {
netsfs_create_by_name("stats", S_IFREG, network_dentry, &network_stats_dentry, NULL, NETSFS_STATS);
netsfs_create_by_name("stream", S_IFREG, network_dentry, &network_stats_dentry, NULL, NETSFS_STREAM);
}
}

/* Increment size of inode */
netsfs_inc_inode_size(mac_dentry->d_parent->d_inode, netsfsinfo->len);
netsfs_inc_inode_size(mac_dentry->d_inode, netsfsinfo->len);
netsfs_inc_inode_size(network_dentry->d_inode, netsfsinfo->len);


kfree( (void *) work);
}

/* Bottom Halve.
* Grab the packet in Interrupt Context, we need be fast here.
*/
int netsfs_packet_handler(struct sk_buff *skb, struct net_device *dev, struct packet_type *pkt,
struct net_device *dev2)
{
Expand Down

0 comments on commit 2292d00

Please sign in to comment.