Skip to content
Snippets Groups Projects
Commit a472a64b authored by Alessandro Rubini's avatar Alessandro Rubini
Browse files

core: add v_op to buffer type/instance and add mmap to generic fops


Signed-off-by: default avatarAlessandro Rubini <rubini@gnudd.com>
Acked-by: default avatarFederico Vaga <federico.vaga@gmail.com>
parent 107c42f1
Branches
Tags
No related merge requests found
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <linux/zio.h> #include <linux/zio.h>
#include <linux/gfp.h> #include <linux/gfp.h>
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/mm.h>
#include <linux/list.h> #include <linux/list.h>
#include <linux/spinlock.h> #include <linux/spinlock.h>
#include <linux/wait.h> #include <linux/wait.h>
...@@ -36,7 +37,7 @@ struct zio_buffer_type { ...@@ -36,7 +37,7 @@ struct zio_buffer_type {
* If the field is NULL, you'll get ENODEV when opening the cdev. * If the field is NULL, you'll get ENODEV when opening the cdev.
*/ */
const struct file_operations *f_op; const struct file_operations *f_op;
const struct vm_operations *v_op; const struct vm_operations_struct *v_op;
/* default attributes for instance */ /* default attributes for instance */
struct zio_attribute_set zattr_set; struct zio_attribute_set zattr_set;
...@@ -75,6 +76,7 @@ struct zio_bi { ...@@ -75,6 +76,7 @@ struct zio_bi {
const struct zio_buffer_operations *b_op; const struct zio_buffer_operations *b_op;
const struct file_operations *f_op; const struct file_operations *f_op;
const struct vm_operations_struct *v_op;
}; };
#define to_zio_bi(_kobj) container_of(_kobj, struct zio_bi, head.kobj) #define to_zio_bi(_kobj) container_of(_kobj, struct zio_bi, head.kobj)
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/types.h> #include <linux/types.h>
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/mm.h>
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/poll.h> #include <linux/poll.h>
#include <linux/sched.h> #include <linux/sched.h>
...@@ -481,6 +482,22 @@ static ssize_t zio_generic_write(struct file *f, const char __user *ubuf, ...@@ -481,6 +482,22 @@ static ssize_t zio_generic_write(struct file *f, const char __user *ubuf,
return count; return count;
} }
static int zio_generic_mmap(struct file *f, struct vm_area_struct *vma)
{
struct zio_f_priv *priv = f->private_data;
struct zio_bi *bi = priv->chan->bi;
const struct vm_operations_struct *v_op = bi->v_op;
if (!v_op)
return -ENODEV; /* according to man page */
/* The buffer instance may usecount, so notifiy it and allow
it to fail */
vma->vm_ops = v_op;
if (v_op->open)
v_op->open(vma); /* returns void */
return 0;
}
static unsigned int zio_generic_poll(struct file *f, static unsigned int zio_generic_poll(struct file *f,
struct poll_table_struct *w) struct poll_table_struct *w)
{ {
...@@ -506,6 +523,7 @@ const struct file_operations zio_generic_file_operations = { ...@@ -506,6 +523,7 @@ const struct file_operations zio_generic_file_operations = {
.read = zio_generic_read, .read = zio_generic_read,
.write = zio_generic_write, .write = zio_generic_write,
.poll = zio_generic_poll, .poll = zio_generic_poll,
.mmap = zio_generic_mmap,
.release = zio_generic_release, .release = zio_generic_release,
}; };
/* Export, so buffers can use it or internal function */ /* Export, so buffers can use it or internal function */
......
...@@ -1041,6 +1041,7 @@ static struct zio_bi *__bi_create_and_init(struct zio_buffer_type *zbuf, ...@@ -1041,6 +1041,7 @@ static struct zio_bi *__bi_create_and_init(struct zio_buffer_type *zbuf,
/* Initialize buffer */ /* Initialize buffer */
bi->b_op = zbuf->b_op; bi->b_op = zbuf->b_op;
bi->f_op = zbuf->f_op; bi->f_op = zbuf->f_op;
bi->v_op = zbuf->v_op;
bi->flags |= (chan->flags & ZIO_DIR); bi->flags |= (chan->flags & ZIO_DIR);
bi->head.zobj_type = ZBI; bi->head.zobj_type = ZBI;
snprintf(bi->head.name, ZIO_NAME_LEN, "%s-%s-%d-%d", snprintf(bi->head.name, ZIO_NAME_LEN, "%s-%s-%d-%d",
......
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