Commit 8d62fe94 authored by Tuomas Tynkkynen's avatar Tuomas Tynkkynen Committed by Greg Kroah-Hartman

virtio: virtconsole: Use seq_file for debugfs operations

Simplifies the code and is more conventional to what's used in the rest
of the kernel for debugfs ops.
Signed-off-by: default avatarTuomas Tynkkynen <tuomas@tuxera.com>
Reviewed-by: default avatarAmit Shah <amit@kernel.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 56620849
...@@ -1309,51 +1309,35 @@ static const struct attribute_group port_attribute_group = { ...@@ -1309,51 +1309,35 @@ static const struct attribute_group port_attribute_group = {
.attrs = port_sysfs_entries, .attrs = port_sysfs_entries,
}; };
static ssize_t debugfs_read(struct file *filp, char __user *ubuf, static int debugfs_show(struct seq_file *s, void *data)
size_t count, loff_t *offp)
{ {
struct port *port; struct port *port = s->private;
char *buf;
ssize_t ret, out_offset, out_count; seq_printf(s, "name: %s\n", port->name ? port->name : "");
seq_printf(s, "guest_connected: %d\n", port->guest_connected);
out_count = 1024; seq_printf(s, "host_connected: %d\n", port->host_connected);
buf = kmalloc(out_count, GFP_KERNEL); seq_printf(s, "outvq_full: %d\n", port->outvq_full);
if (!buf) seq_printf(s, "bytes_sent: %lu\n", port->stats.bytes_sent);
return -ENOMEM; seq_printf(s, "bytes_received: %lu\n", port->stats.bytes_received);
seq_printf(s, "bytes_discarded: %lu\n", port->stats.bytes_discarded);
port = filp->private_data; seq_printf(s, "is_console: %s\n",
out_offset = 0;
out_offset += snprintf(buf + out_offset, out_count,
"name: %s\n", port->name ? port->name : "");
out_offset += snprintf(buf + out_offset, out_count - out_offset,
"guest_connected: %d\n", port->guest_connected);
out_offset += snprintf(buf + out_offset, out_count - out_offset,
"host_connected: %d\n", port->host_connected);
out_offset += snprintf(buf + out_offset, out_count - out_offset,
"outvq_full: %d\n", port->outvq_full);
out_offset += snprintf(buf + out_offset, out_count - out_offset,
"bytes_sent: %lu\n", port->stats.bytes_sent);
out_offset += snprintf(buf + out_offset, out_count - out_offset,
"bytes_received: %lu\n",
port->stats.bytes_received);
out_offset += snprintf(buf + out_offset, out_count - out_offset,
"bytes_discarded: %lu\n",
port->stats.bytes_discarded);
out_offset += snprintf(buf + out_offset, out_count - out_offset,
"is_console: %s\n",
is_console_port(port) ? "yes" : "no"); is_console_port(port) ? "yes" : "no");
out_offset += snprintf(buf + out_offset, out_count - out_offset, seq_printf(s, "console_vtermno: %u\n", port->cons.vtermno);
"console_vtermno: %u\n", port->cons.vtermno);
ret = simple_read_from_buffer(ubuf, count, offp, buf, out_offset); return 0;
kfree(buf); }
return ret;
static int debugfs_open(struct inode *inode, struct file *file)
{
return single_open(file, debugfs_show, inode->i_private);
} }
static const struct file_operations port_debugfs_ops = { static const struct file_operations port_debugfs_ops = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.open = simple_open, .open = debugfs_open,
.read = debugfs_read, .read = seq_read,
.llseek = seq_lseek,
.release = single_release,
}; };
static void set_console_size(struct port *port, u16 rows, u16 cols) static void set_console_size(struct port *port, u16 rows, u16 cols)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment