mirror of https://github.com/schoebel/mars
import mars-04.tgz
This commit is contained in:
parent
feafb2a4c4
commit
7552314757
19
mars.h
19
mars.h
|
@ -16,7 +16,8 @@
|
|||
#define MARS_ERROR "MARS_ERROR: "
|
||||
|
||||
#define MARS_ERR(args...) printk(MARS_ERROR args)
|
||||
#define MARS_DBG(args...) printk("MARS_DEBUG: " args)
|
||||
//#define MARS_DBG(args...) printk("MARS_DEBUG: " args)
|
||||
#define MARS_DBG(args...) /**/
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
@ -24,14 +25,14 @@
|
|||
|
||||
#define MAX_DEFAULT_ASPECTS 8
|
||||
|
||||
#define GENERIC_OBJECT_LAYOUT(PREFIX) \
|
||||
int max_size; \
|
||||
int rest_size; \
|
||||
int max_aspects; \
|
||||
int nr_aspects; \
|
||||
int *aspect_sizes; \
|
||||
int *aspect_offsets; \
|
||||
void *alloc_ptr; \
|
||||
#define GENERIC_OBJECT_LAYOUT(PREFIX) \
|
||||
int max_size; \
|
||||
int rest_size; \
|
||||
int max_aspects; \
|
||||
int nr_aspects; \
|
||||
int *aspect_sizes; \
|
||||
int *aspect_offsets; \
|
||||
void *alloc_ptr; \
|
||||
|
||||
struct generic_object_layout {
|
||||
GENERIC_OBJECT_LAYOUT(generic);
|
||||
|
|
|
@ -3,6 +3,9 @@
|
|||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/string.h>
|
||||
#include <linux/types.h>
|
||||
#include <linux/blkdev.h>
|
||||
#include <linux/highmem.h>
|
||||
|
||||
#include "mars.h"
|
||||
|
||||
|
@ -15,11 +18,57 @@
|
|||
static int device_sio_mars_io(struct device_sio_output *output, struct mars_io *mio)
|
||||
{
|
||||
struct bio *bio = mio->orig_bio;
|
||||
int direction = bio->bi_rw & 1;
|
||||
//unsigned int nr_sectors = bio_sectors(bio);
|
||||
unsigned long sector = bio->bi_sector;
|
||||
unsigned long long pos = sector << 9; //TODO: allow different sector sizes
|
||||
struct bio_vec *bvec;
|
||||
int i;
|
||||
int ret = -EIO;
|
||||
|
||||
if (!output->filp)
|
||||
goto done;
|
||||
|
||||
bio_for_each_segment(bvec, bio, i) {
|
||||
mm_segment_t oldfs;
|
||||
unsigned long long ppos = pos;
|
||||
void *addr = kmap(bvec->bv_page) + bvec->bv_offset;
|
||||
unsigned int len = bvec->bv_len;
|
||||
|
||||
MARS_DBG("IO dir=%d sector=%lu size=%d | pos=%llu len=%u addr=%p\n", direction, sector, bio->bi_size, pos, len, addr);
|
||||
|
||||
oldfs = get_fs();
|
||||
set_fs(get_ds());
|
||||
|
||||
if (direction == READ)
|
||||
ret = do_sync_read(output->filp, addr, len, &ppos);
|
||||
else
|
||||
ret = do_sync_write(output->filp, addr, len, &ppos);
|
||||
|
||||
set_fs(oldfs);
|
||||
kunmap(bvec->bv_page);
|
||||
|
||||
if (!ret) { // EOF
|
||||
MARS_DBG("EOF\n");
|
||||
addr = kmap(bvec->bv_page) + bvec->bv_offset;
|
||||
memset(addr, 0, len);
|
||||
kunmap(bvec->bv_page);
|
||||
} else if (ret != len) {
|
||||
MARS_ERR("IO error pos=%llu, len=%u, status=%d\n", pos, len, ret);
|
||||
goto done;
|
||||
}
|
||||
|
||||
pos += len;
|
||||
bio->bi_size -= len;
|
||||
ret = 0;
|
||||
}
|
||||
|
||||
done:
|
||||
mio->mars_endio(mio);
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
///////////////////////// contructors / destructors ////////////////////////
|
||||
//////////////////////// constructors / destructors //////////////////////
|
||||
|
||||
static int device_sio_brick_construct(struct device_sio_brick *brick)
|
||||
{
|
||||
|
@ -28,6 +77,32 @@ static int device_sio_brick_construct(struct device_sio_brick *brick)
|
|||
|
||||
static int device_sio_output_construct(struct device_sio_output *output)
|
||||
{
|
||||
mm_segment_t oldfs;
|
||||
int flags = O_CREAT | O_RDWR | O_LARGEFILE;
|
||||
int prot = 0600;
|
||||
char *path = "/tmp/testfile.img";
|
||||
|
||||
oldfs = get_fs();
|
||||
set_fs(get_ds());
|
||||
output->filp = filp_open(path, flags, prot);
|
||||
set_fs(oldfs);
|
||||
|
||||
if (IS_ERR(output->filp)) {
|
||||
int err = PTR_ERR(output->filp);
|
||||
MARS_ERR("can't open file '%s' status=%d\n", path, err);
|
||||
output->filp = NULL;
|
||||
return err;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int device_sio_output_destruct(struct device_sio_output *output)
|
||||
{
|
||||
if (output->filp) {
|
||||
filp_close(output->filp, NULL);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -45,6 +120,7 @@ static struct device_sio_output_type device_sio_output_type = {
|
|||
.output_size = sizeof(struct device_sio_output),
|
||||
.master_ops = &device_sio_output_ops,
|
||||
.output_construct = &device_sio_output_construct,
|
||||
.output_destruct = &device_sio_output_destruct,
|
||||
};
|
||||
|
||||
static struct device_sio_output_type *device_sio_output_types[] = {
|
||||
|
|
|
@ -9,6 +9,7 @@ struct device_sio_input {
|
|||
|
||||
struct device_sio_output {
|
||||
MARS_OUTPUT(device_sio);
|
||||
struct file *filp;
|
||||
};
|
||||
|
||||
MARS_TYPES(device_sio);
|
||||
|
|
|
@ -47,14 +47,11 @@ static int if_device_make_request(struct request_queue *q, struct bio *bio)
|
|||
{
|
||||
struct if_device_input *input = q->queuedata;
|
||||
struct if_device_output *output;
|
||||
struct mars_io *mio;
|
||||
struct mars_io *mio = NULL;
|
||||
int error = -ENOSYS;
|
||||
|
||||
MARS_DBG("make_request(%d)\n", bio->bi_size);
|
||||
#if 0
|
||||
bio->bi_size = 0;
|
||||
bio_endio(bio, 0);
|
||||
#else
|
||||
|
||||
if (!input || !input->connect)
|
||||
goto err;
|
||||
|
||||
|
@ -74,13 +71,16 @@ static int if_device_make_request(struct request_queue *q, struct bio *bio)
|
|||
error = output->ops->mars_io(output, mio);
|
||||
if (error)
|
||||
goto err_free;
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
|
||||
err_free:
|
||||
kfree(mio);
|
||||
err:
|
||||
bio_endio(bio, error);
|
||||
MARS_ERR("cannot submit request, status=%d\n", error);
|
||||
if (!mio)
|
||||
bio_endio(bio, error);
|
||||
//else mars_endio() callback must have been called, which is responsible for cleanup
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -124,6 +124,7 @@ static int if_device_input_construct(struct if_device_input *input)
|
|||
struct request_queue *q;
|
||||
struct gendisk *disk;
|
||||
int minor;
|
||||
int capacity = 2 * 1024 * 1024 * 4; //TODO: make this dynamic
|
||||
|
||||
MARS_DBG("1\n");
|
||||
q = blk_alloc_queue(GFP_KERNEL);
|
||||
|
@ -150,7 +151,7 @@ static int if_device_input_construct(struct if_device_input *input)
|
|||
sprintf(disk->disk_name, "mars%d", minor);
|
||||
MARS_DBG("created device name %s\n", disk->disk_name);
|
||||
disk->private_data = input;
|
||||
set_capacity(disk, 1024); //XXX
|
||||
set_capacity(disk, capacity);
|
||||
|
||||
blk_queue_make_request(q, if_device_make_request);
|
||||
blk_queue_max_segment_size(q, MARS_MAX_SEGMENT_SIZE);
|
||||
|
|
Loading…
Reference in New Issue