Classes | |
struct | buffer |
Defines | |
#define | QUERY(fmt, args...) printk(KERN_DEBUG "FSC: " fmt, ## args) |
#define | CHAR_DEVICE_NAME "fsc_dev" |
#define | MAX_BUFFER_LENGTH 5192 |
Functions | |
module_param (fsc_major, int, S_IRUSR) | |
ssize_t | fsc_read (struct file *filp, char *buf, size_t count, loff_t *f_pos) |
Char Device read function. Allways called from user space by FS Deamon. The deamon reads content of output_buffer and sends it as commands and data to database. On empty output buffer (zero declared length) the caller will be blocked - added into wait queue. The caller will be woken up after writing any data into output buffer from kernel FS. This function don't support reading larger ammount of data then output buffer size. Greater number of char to be read can be specified, but the maximum ouput buffer length is returned. If count is less than output_buffer length, count characters will be read, but the kernel FS remains blocked until whole output_buffer is read. | |
ssize_t | fsc_write (struct file *filp, const char *buf, size_t count, loff_t *f_pos) |
Char Device write function. | |
int | fsc_release (struct inode *inode, struct file *filp) |
Release (close) the char device. | |
int | fsc_open (struct inode *inode, struct file *filp) |
Open the char device. | |
void | fsc_init (void) |
FS Character Device initialization. | |
void | fsc_fini (void) |
FS Character Device fini. | |
int | fsc_read_procmem (char *buf, char **start, off_t offset, int count, int *eof, void *data) |
Prints information about the fsc device. | |
int | fsc_waitforempty_output (void) |
Wait for empty output buffer. | |
int | fsc_waitforfull_input (void) |
Wait for full input buffer. | |
int | __fsc_query__ (const char *out_buf, const int out_count, char *in_buf, int in_count) |
File System Char Device communication channel. | |
int | fsc_query (const char *out_buf, const int out_count, char *in_buf, int in_count) |
Variables | |
buffer | fsc_output_buffer |
buffer | fsc_input_buffer |
atomic_t | fsc_available = ATOMIC_INIT(1) |
semaphore | fsc_sem |
mutex | query_mutex |
int | fsc_major = 0 |
file_operations | fsc_fops |
int | fsc_major |
file_operations | fsc_fops |
#define CHAR_DEVICE_NAME "fsc_dev" |
Character device name, identifies it in /dev/
Definition at line 23 of file fsc_device.h.
#define MAX_BUFFER_LENGTH 5192 |
Maximum length of each char device buffer. Length defined in MYSQLFS protocol: 300 bytes for command part + 4096 bytes for data part. See protocol.txt for more info.
Definition at line 31 of file fsc_device.h.
Referenced by __fsc_query__(), and fsc_write().
#define QUERY | ( | fmt, | |||
args... | ) | printk(KERN_DEBUG "FSC: " fmt, ## args) |
Macro for print query
Definition at line 19 of file fsc_device.h.
int __fsc_query__ | ( | const char * | out_buf, | |
const int | out_count, | |||
char * | in_buf, | |||
int | in_count | |||
) |
File System Char Device communication channel.
This function writes FS query into output buffer, waits until FS Deamon read it, waits until FS Deamon writes the answer via write function. This function can will block in few situations: 1) the FS sends query but output_buffer is still full (hasn't been read) 2) the FS Char Dev waits until input_buffer contains some data (answer) fsc_query function is always called by kernel filesystem, the return value should be carefully checked and the query should be repeated if error occurs.
out_buf | Command or data from FS to FS Deamon. Note: | |
out_count | Length of out_buf content (number of chars). | |
in_buf | Buffer for storing the answer or returning data. | |
in_count | Maximum length of the buffer, max number of char that could be written into. |
Definition at line 298 of file fsc_device.c.
References buffer::data, buffer::deamon_queue, fsc_input_buffer, fsc_output_buffer, fsc_sem, fsc_waitforempty_output(), fsc_waitforfull_input(), buffer::length, MAX_BUFFER_LENGTH, PDEBUG, and result.
Referenced by fsc_query().
void fsc_fini | ( | void | ) |
FS Character Device fini.
Destroy mutex.
Definition at line 116 of file fsc_device.c.
References query_mutex.
void fsc_init | ( | void | ) |
FS Character Device initialization.
Initializes wait queues for both input and output buffer, declares buffer contents as empty and initializes semaphore for mutual exclusive access to char device internals.
Definition at line 98 of file fsc_device.c.
References buffer::deamon_queue, fsc_input_buffer, fsc_output_buffer, fsc_sem, buffer::kernel_queue, buffer::length, and query_mutex.
int fsc_open | ( | struct inode * | inode, | |
struct file * | filp | |||
) |
Open the char device.
Char device is open exclusively, only one open instance in the time.
inode | Ignored. | |
filp | Ignored. |
Definition at line 159 of file fsc_device.c.
References fsc_available, and PDEBUG.
int fsc_query | ( | const char * | out_buf, | |
const int | out_count, | |||
char * | in_buf, | |||
int | in_count | |||
) |
Wraper for __fsc_query__()
Definition at line 270 of file fsc_device.c.
References __fsc_query__(), query_mutex, and result.
Referenced by query().
ssize_t fsc_read | ( | struct file * | filp, | |
char * | buf, | |||
size_t | count, | |||
loff_t * | f_pos | |||
) |
Char Device read function. Allways called from user space by FS Deamon. The deamon reads content of output_buffer and sends it as commands and data to database. On empty output buffer (zero declared length) the caller will be blocked - added into wait queue. The caller will be woken up after writing any data into output buffer from kernel FS. This function don't support reading larger ammount of data then output buffer size. Greater number of char to be read can be specified, but the maximum ouput buffer length is returned. If count is less than output_buffer length, count characters will be read, but the kernel FS remains blocked until whole output_buffer is read.
filp | Ignored. | |
buf | Buffer for storing output_buffer data. | |
count | Number of chars to be read. | |
f_pos | Ignored. |
Definition at line 460 of file fsc_device.c.
References buffer::data, buffer::deamon_queue, fsc_output_buffer, fsc_sem, buffer::kernel_queue, buffer::length, and PDEBUG.
int fsc_read_procmem | ( | char * | buf, | |
char ** | start, | |||
off_t | offset, | |||
int | count, | |||
int * | eof, | |||
void * | data | |||
) |
Prints information about the fsc device.
Not necessary for running, but useful for checking the char device buffer content. Only way to see what is stored inside the buffers withnout reading or writing into them. Params usually not needed, call "cat /proc/fsc_dev".
buf | Buffer will contain char device info. | |
start | Ignored. | |
offset | Ignored. | |
count | Ignored. | |
eof | End Of File parameter. | |
data | Ignored. |
Definition at line 137 of file fsc_device.c.
References buffer::data, fsc_input_buffer, fsc_output_buffer, and buffer::length.
int fsc_release | ( | struct inode * | inode, | |
struct file * | filp | |||
) |
Release (close) the char device.
inode | Ignored. | |
filp | Ignored. |
Definition at line 180 of file fsc_device.c.
References fsc_available, and PDEBUG.
int fsc_waitforempty_output | ( | void | ) |
Wait for empty output buffer.
Output buffer is used for storing FS commands and data until FS Deamon reads it. When new attempt from kernel to write into ouput buffer is processed and old data are present, this function blocks current running kernel thread using wait queue. The queue is defined in the output buffer sturcture, kernel always sleeps in the kernel_queue. Caller of this function has to hold the semaphore. After return from waiting with success, the semaphore is set down again.
Definition at line 203 of file fsc_device.c.
References fsc_output_buffer, fsc_sem, buffer::kernel_queue, buffer::length, and PDEBUG.
Referenced by __fsc_query__().
int fsc_waitforfull_input | ( | void | ) |
Wait for full input buffer.
Input buffer is used for storing response from database or command response written by FS Deamon. When new attempt from kernel to read from input buffer is processed and no data are present, this function blocks current running kernel thread using wait queue. The queue is defined in the input buffer structure, kernel alwazs sleeps in the kernel_queue. Calle of this function has to hold the semaphore. After return from waitin with success, the semaphore is set down again.
Definition at line 241 of file fsc_device.c.
References fsc_input_buffer, fsc_sem, buffer::kernel_queue, buffer::length, and PDEBUG.
Referenced by __fsc_query__().
ssize_t fsc_write | ( | struct file * | filp, | |
const char * | buf, | |||
size_t | count, | |||
loff_t * | f_pos | |||
) |
Char Device write function.
Allways called from user space by FS Deamon. The deamon writes command answers and data from database. On full input_buffer (non-zero declared length) the caller will be blocked - added into wait queue. The caller will be woken up after reading full content of input buffer from kernel FS. This function don't support writing larger ammount of data then input buffer size.
filp | Ignored. | |
buf | Buffer with written data. | |
count | Number of chars in the buf buffer. | |
f_pos | Ignored. |
Definition at line 385 of file fsc_device.c.
References buffer::data, buffer::deamon_queue, fsc_input_buffer, fsc_sem, buffer::kernel_queue, buffer::length, MAX_BUFFER_LENGTH, and PDEBUG.
module_param | ( | fsc_major | , | |
int | , | |||
S_IRUSR | ||||
) |
Expose fsc device major number.
atomic_t fsc_available = ATOMIC_INIT(1) |
Atomic variable for determinig usage of fsc device by exactly one user at the moment.
Definition at line 53 of file fsc_device.c.
Referenced by fsc_open(), and fsc_release().
struct file_operations fsc_fops |
This kernel structure contains informations about operations supported by fsc device.
Definition at line 82 of file fsc_device.c.
struct file_operations fsc_fops |
Initial value:
{ .read = fsc_read, .write = fsc_write, .open = fsc_open, .release = fsc_release }
Definition at line 82 of file fsc_device.c.
struct buffer fsc_input_buffer |
Input buffer stores data to be written to char device by the deamon.
Definition at line 49 of file fsc_device.c.
Referenced by __fsc_query__(), fsc_init(), fsc_read_procmem(), fsc_waitforfull_input(), and fsc_write().
int fsc_major |
FSC Device module major number.
Definition at line 65 of file fsc_device.c.
int fsc_major = 0 |
FSC Device module major number.
Definition at line 65 of file fsc_device.c.
struct buffer fsc_output_buffer |
Output buffer stores data to be read from char device by the deamon.
Definition at line 45 of file fsc_device.c.
Referenced by __fsc_query__(), fsc_init(), fsc_read(), fsc_read_procmem(), and fsc_waitforempty_output().
struct semaphore fsc_sem |
Semaphore for mutual exclusive access to fsc device buffers.
Definition at line 57 of file fsc_device.c.
Referenced by __fsc_query__(), fsc_init(), fsc_read(), fsc_waitforempty_output(), fsc_waitforfull_input(), and fsc_write().
struct mutex query_mutex |
Structure for mutex
Definition at line 61 of file fsc_device.c.
Referenced by fsc_fini(), fsc_init(), and fsc_query().