Commit d5d03eec authored by Alexey Dobriyan's avatar Alexey Dobriyan Committed by Jens Axboe

dac960: switch to seq_file

Signed-off-by: default avatarAlexey Dobriyan <adobriyan@gmail.com>
Cc: Yang Hongyang <yanghy@cn.fujitsu.com>
Cc: Tejun Heo <tj@kernel.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarJens Axboe <jens.axboe@oracle.com>
parent ff2c3de3
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/smp_lock.h> #include <linux/smp_lock.h>
#include <linux/proc_fs.h> #include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include <linux/reboot.h> #include <linux/reboot.h>
#include <linux/spinlock.h> #include <linux/spinlock.h>
#include <linux/timer.h> #include <linux/timer.h>
...@@ -6422,16 +6423,10 @@ static bool DAC960_V2_ExecuteUserCommand(DAC960_Controller_T *Controller, ...@@ -6422,16 +6423,10 @@ static bool DAC960_V2_ExecuteUserCommand(DAC960_Controller_T *Controller,
return true; return true;
} }
static int dac960_proc_show(struct seq_file *m, void *v)
/*
DAC960_ProcReadStatus implements reading /proc/rd/status.
*/
static int DAC960_ProcReadStatus(char *Page, char **Start, off_t Offset,
int Count, int *EOF, void *Data)
{ {
unsigned char *StatusMessage = "OK\n"; unsigned char *StatusMessage = "OK\n";
int ControllerNumber, BytesAvailable; int ControllerNumber;
for (ControllerNumber = 0; for (ControllerNumber = 0;
ControllerNumber < DAC960_ControllerCount; ControllerNumber < DAC960_ControllerCount;
ControllerNumber++) ControllerNumber++)
...@@ -6444,52 +6439,49 @@ static int DAC960_ProcReadStatus(char *Page, char **Start, off_t Offset, ...@@ -6444,52 +6439,49 @@ static int DAC960_ProcReadStatus(char *Page, char **Start, off_t Offset,
break; break;
} }
} }
BytesAvailable = strlen(StatusMessage) - Offset; seq_puts(m, StatusMessage);
if (Count >= BytesAvailable) return 0;
{
Count = BytesAvailable;
*EOF = true;
}
if (Count <= 0) return 0;
*Start = Page;
memcpy(Page, &StatusMessage[Offset], Count);
return Count;
} }
static int dac960_proc_open(struct inode *inode, struct file *file)
{
return single_open(file, dac960_proc_show, NULL);
}
/* static const struct file_operations dac960_proc_fops = {
DAC960_ProcReadInitialStatus implements reading /proc/rd/cN/initial_status. .owner = THIS_MODULE,
*/ .open = dac960_proc_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};
static int DAC960_ProcReadInitialStatus(char *Page, char **Start, off_t Offset, static int dac960_initial_status_proc_show(struct seq_file *m, void *v)
int Count, int *EOF, void *Data)
{ {
DAC960_Controller_T *Controller = (DAC960_Controller_T *) Data; DAC960_Controller_T *Controller = (DAC960_Controller_T *)m->private;
int BytesAvailable = Controller->InitialStatusLength - Offset; seq_printf(m, "%.*s", Controller->InitialStatusLength, Controller->CombinedStatusBuffer);
if (Count >= BytesAvailable) return 0;
{
Count = BytesAvailable;
*EOF = true;
}
if (Count <= 0) return 0;
*Start = Page;
memcpy(Page, &Controller->CombinedStatusBuffer[Offset], Count);
return Count;
} }
static int dac960_initial_status_proc_open(struct inode *inode, struct file *file)
{
return single_open(file, dac960_initial_status_proc_show, PDE(inode)->data);
}
/* static const struct file_operations dac960_initial_status_proc_fops = {
DAC960_ProcReadCurrentStatus implements reading /proc/rd/cN/current_status. .owner = THIS_MODULE,
*/ .open = dac960_initial_status_proc_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};
static int DAC960_ProcReadCurrentStatus(char *Page, char **Start, off_t Offset, static int dac960_current_status_proc_show(struct seq_file *m, void *v)
int Count, int *EOF, void *Data)
{ {
DAC960_Controller_T *Controller = (DAC960_Controller_T *) Data; DAC960_Controller_T *Controller = (DAC960_Controller_T *) m->private;
unsigned char *StatusMessage = unsigned char *StatusMessage =
"No Rebuild or Consistency Check in Progress\n"; "No Rebuild or Consistency Check in Progress\n";
int ProgressMessageLength = strlen(StatusMessage); int ProgressMessageLength = strlen(StatusMessage);
int BytesAvailable;
if (jiffies != Controller->LastCurrentStatusTime) if (jiffies != Controller->LastCurrentStatusTime)
{ {
Controller->CurrentStatusLength = 0; Controller->CurrentStatusLength = 0;
...@@ -6513,49 +6505,41 @@ static int DAC960_ProcReadCurrentStatus(char *Page, char **Start, off_t Offset, ...@@ -6513,49 +6505,41 @@ static int DAC960_ProcReadCurrentStatus(char *Page, char **Start, off_t Offset,
} }
Controller->LastCurrentStatusTime = jiffies; Controller->LastCurrentStatusTime = jiffies;
} }
BytesAvailable = Controller->CurrentStatusLength - Offset; seq_printf(m, "%.*s", Controller->CurrentStatusLength, Controller->CurrentStatusBuffer);
if (Count >= BytesAvailable) return 0;
{
Count = BytesAvailable;
*EOF = true;
}
if (Count <= 0) return 0;
*Start = Page;
memcpy(Page, &Controller->CurrentStatusBuffer[Offset], Count);
return Count;
} }
static int dac960_current_status_proc_open(struct inode *inode, struct file *file)
{
return single_open(file, dac960_current_status_proc_show, PDE(inode)->data);
}
/* static const struct file_operations dac960_current_status_proc_fops = {
DAC960_ProcReadUserCommand implements reading /proc/rd/cN/user_command. .owner = THIS_MODULE,
*/ .open = dac960_current_status_proc_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};
static int DAC960_ProcReadUserCommand(char *Page, char **Start, off_t Offset, static int dac960_user_command_proc_show(struct seq_file *m, void *v)
int Count, int *EOF, void *Data)
{ {
DAC960_Controller_T *Controller = (DAC960_Controller_T *) Data; DAC960_Controller_T *Controller = (DAC960_Controller_T *)m->private;
int BytesAvailable = Controller->UserStatusLength - Offset;
if (Count >= BytesAvailable)
{
Count = BytesAvailable;
*EOF = true;
}
if (Count <= 0) return 0;
*Start = Page;
memcpy(Page, &Controller->UserStatusBuffer[Offset], Count);
return Count;
}
seq_printf(m, "%.*s", Controller->UserStatusLength, Controller->UserStatusBuffer);
return 0;
}
/* static int dac960_user_command_proc_open(struct inode *inode, struct file *file)
DAC960_ProcWriteUserCommand implements writing /proc/rd/cN/user_command. {
*/ return single_open(file, dac960_user_command_proc_show, PDE(inode)->data);
}
static int DAC960_ProcWriteUserCommand(struct file *file, static ssize_t dac960_user_command_proc_write(struct file *file,
const char __user *Buffer, const char __user *Buffer,
unsigned long Count, void *Data) size_t Count, loff_t *pos)
{ {
DAC960_Controller_T *Controller = (DAC960_Controller_T *) Data; DAC960_Controller_T *Controller = (DAC960_Controller_T *) PDE(file->f_path.dentry->d_inode)->data;
unsigned char CommandBuffer[80]; unsigned char CommandBuffer[80];
int Length; int Length;
if (Count > sizeof(CommandBuffer)-1) return -EINVAL; if (Count > sizeof(CommandBuffer)-1) return -EINVAL;
...@@ -6572,6 +6556,14 @@ static int DAC960_ProcWriteUserCommand(struct file *file, ...@@ -6572,6 +6556,14 @@ static int DAC960_ProcWriteUserCommand(struct file *file,
? Count : -EBUSY); ? Count : -EBUSY);
} }
static const struct file_operations dac960_user_command_proc_fops = {
.owner = THIS_MODULE,
.open = dac960_user_command_proc_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
.write = dac960_user_command_proc_write,
};
/* /*
DAC960_CreateProcEntries creates the /proc/rd/... entries for the DAC960_CreateProcEntries creates the /proc/rd/... entries for the
...@@ -6586,23 +6578,17 @@ static void DAC960_CreateProcEntries(DAC960_Controller_T *Controller) ...@@ -6586,23 +6578,17 @@ static void DAC960_CreateProcEntries(DAC960_Controller_T *Controller)
if (DAC960_ProcDirectoryEntry == NULL) { if (DAC960_ProcDirectoryEntry == NULL) {
DAC960_ProcDirectoryEntry = proc_mkdir("rd", NULL); DAC960_ProcDirectoryEntry = proc_mkdir("rd", NULL);
StatusProcEntry = create_proc_read_entry("status", 0, StatusProcEntry = proc_create("status", 0,
DAC960_ProcDirectoryEntry, DAC960_ProcDirectoryEntry,
DAC960_ProcReadStatus, NULL); &dac960_proc_fops);
} }
sprintf(Controller->ControllerName, "c%d", Controller->ControllerNumber); sprintf(Controller->ControllerName, "c%d", Controller->ControllerNumber);
ControllerProcEntry = proc_mkdir(Controller->ControllerName, ControllerProcEntry = proc_mkdir(Controller->ControllerName,
DAC960_ProcDirectoryEntry); DAC960_ProcDirectoryEntry);
create_proc_read_entry("initial_status", 0, ControllerProcEntry, proc_create_data("initial_status", 0, ControllerProcEntry, &dac960_initial_status_proc_fops, Controller);
DAC960_ProcReadInitialStatus, Controller); proc_create_data("current_status", 0, ControllerProcEntry, &dac960_current_status_proc_fops, Controller);
create_proc_read_entry("current_status", 0, ControllerProcEntry, UserCommandProcEntry = proc_create_data("user_command", S_IWUSR | S_IRUSR, ControllerProcEntry, &dac960_user_command_proc_fops, Controller);
DAC960_ProcReadCurrentStatus, Controller);
UserCommandProcEntry =
create_proc_read_entry("user_command", S_IWUSR | S_IRUSR,
ControllerProcEntry, DAC960_ProcReadUserCommand,
Controller);
UserCommandProcEntry->write_proc = DAC960_ProcWriteUserCommand;
Controller->ControllerProcEntry = ControllerProcEntry; Controller->ControllerProcEntry = ControllerProcEntry;
} }
......
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