import mars-05.tgz

This commit is contained in:
Thomas Schoebel-Theuer 2010-06-17 17:57:10 +01:00
parent 7552314757
commit 7f9d7f8568
5 changed files with 227 additions and 10 deletions

View File

@ -29,7 +29,7 @@ config MARS_DEVICE_SIO
Experimental storage System.
config MARS_TEST
tristate "provisionary"
tristate "provisionary TEST"
depends on MARS
default m
---help---

6
mars.h
View File

@ -12,10 +12,12 @@
#define _NORMAL_CODE(X) X
#endif
#define MARS_INFO "MARS_INFO: "
#define MARS_ERROR "MARS_ERROR: "
#define MARS_INFO "MARS_INFO: "
#define MARS_DEBUG "MARS_DEBUG: "
#define MARS_ERR(args...) printk(MARS_ERROR args)
#define MARS_INF(args...) printk(MARS_INFO args)
//#define MARS_DBG(args...) printk("MARS_DEBUG: " args)
#define MARS_DBG(args...) /**/
@ -454,11 +456,11 @@ extern inline int INPUT_PREFIX##_##OUTPUT_PREFIX####_disconnect( \
#define MARS_IO(PREFIX) \
GENERIC_OBJECT(PREFIX); \
struct bio *orig_bio; \
struct bio *mars_bio; \
int (*mars_endio)(struct mars_io *mio); \
struct mars_io {
MARS_IO(mars);
struct list_head io_head; //TODO: move to aspect
};
#define MARS_BRICK(PREFIX) \

View File

@ -3,9 +3,13 @@
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/string.h>
#include <linux/list.h>
#include <linux/types.h>
#include <linux/blkdev.h>
#include <linux/highmem.h>
#include <linux/kthread.h>
#include <linux/spinlock.h>
#include <linux/wait.h>
#include "mars.h"
@ -15,19 +19,124 @@
////////////////// own brick / input / output operations //////////////////
static int transfer_none(int cmd,
struct page *raw_page, unsigned raw_off,
struct page *loop_page, unsigned loop_off,
int size)
{
char *raw_buf = kmap_atomic(raw_page, KM_USER0) + raw_off;
char *loop_buf = kmap_atomic(loop_page, KM_USER1) + loop_off;
if (cmd == READ)
memcpy(loop_buf, raw_buf, size);
else
memcpy(raw_buf, loop_buf, size);
kunmap_atomic(raw_buf, KM_USER0);
kunmap_atomic(loop_buf, KM_USER1);
cond_resched();
return 0;
}
static int device_sio_write_aops(struct device_sio_output *output, struct mars_io *mio)
{
struct bio *bio = mio->orig_bio;
loff_t pos = ((loff_t)bio->bi_sector << 9);
struct file *file = output->filp;
struct address_space *mapping = file->f_mapping;
struct bio_vec *bvec;
int i;
int ret = -EIO;
mutex_lock(&mapping->host->i_mutex);
bio_for_each_segment(bvec, bio, i) {
//pgoff_t index;
unsigned offset, bv_offs;
int len;
//index = pos >> PAGE_CACHE_SHIFT;
offset = pos & ((pgoff_t)PAGE_CACHE_SIZE - 1);
bv_offs = bvec->bv_offset;
len = bvec->bv_len;
while (len > 0) {
int transfer_result;
unsigned size, copied;
struct page *page;
void *fsdata;
size = PAGE_CACHE_SIZE - offset;
if (size > len)
size = len;
ret = pagecache_write_begin(file, mapping, pos, size, 0,
&page, &fsdata);
if (ret)
goto fail;
//file_update_time(file);
transfer_result = transfer_none(WRITE, page, offset, bvec->bv_page, bv_offs, size);
copied = size;
if (transfer_result)
copied = 0;
ret = pagecache_write_end(file, mapping, pos, size, copied,
page, fsdata);
if (ret < 0 || ret != copied)
goto fail;
if (unlikely(transfer_result))
goto fail;
bv_offs += copied;
len -= copied;
offset = 0;
//index++;
pos += copied;
}
ret = 0;
continue;
fail:
ret = -EIO;
}
mutex_unlock(&mapping->host->i_mutex);
if (!ret)
bio->bi_size = 0;
mio->mars_endio(mio);
blk_run_address_space(mapping);
return ret;
}
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
bool barrier = (direction != READ && bio_rw_flagged(bio, BIO_RW_BARRIER));
struct bio_vec *bvec;
int i;
int ret = -EIO;
if (barrier) {
MARS_INF("got barrier request\n");
}
if (!output->filp)
goto done;
#if 1
if (direction == WRITE) {
return device_sio_write_aops(output, mio);
}
#endif
bio_for_each_segment(bvec, bio, i) {
mm_segment_t oldfs;
@ -40,10 +149,11 @@ static int device_sio_mars_io(struct device_sio_output *output, struct mars_io *
oldfs = get_fs();
set_fs(get_ds());
if (direction == READ)
if (direction == READ) {
ret = do_sync_read(output->filp, addr, len, &ppos);
else
} else {
ret = do_sync_write(output->filp, addr, len, &ppos);
}
set_fs(oldfs);
kunmap(bvec->bv_page);
@ -57,7 +167,20 @@ static int device_sio_mars_io(struct device_sio_output *output, struct mars_io *
MARS_ERR("IO error pos=%llu, len=%u, status=%d\n", pos, len, ret);
goto done;
}
#if 0
if (direction == WRITE) {
struct inode *inode = output->filp->f_dentry->d_inode;
struct address_space *mapping = inode->i_mapping;
int res;
res = sync_page_range(inode, mapping, pos, len);
if (res) {
MARS_ERR("syncing pages failed: %d\n", res);
}
}
#endif
pos += len;
bio->bi_size -= len;
ret = 0;
@ -68,6 +191,49 @@ done:
return ret;
}
#ifdef WITH_THREAD
static int device_sio_mars_queue(struct device_sio_output *output, struct mars_io *mio)
{
MARS_DBG("queue %p\n", mio);
spin_lock_irq(&output->lock);
list_add_tail(&mio->io_head, &output->mio_list);
spin_unlock_irq(&output->lock);
wake_up(&output->event);
return 0;
}
static int device_sio_thread(void *data)
{
struct device_sio_output *output = data;
MARS_INF("kthread has started.\n");
//set_user_nice(current, -20);
while (!kthread_should_stop()) {
struct mars_io *mio;
wait_event_interruptible(output->event,
!list_empty(&output->mio_list) ||
kthread_should_stop());
if (list_empty(&output->mio_list))
continue;
spin_lock_irq(&output->lock);
mio = container_of(output->mio_list.next, struct mars_io, io_head);
spin_unlock_irq(&output->lock);
MARS_DBG("got %p\n", mio);
device_sio_mars_io(output, mio);
}
MARS_INF("kthread has stopped.\n");
return 0;
}
#endif
//////////////////////// constructors / destructors //////////////////////
static int device_sio_brick_construct(struct device_sio_brick *brick)
@ -94,13 +260,40 @@ static int device_sio_output_construct(struct device_sio_output *output)
return err;
}
#if 0
{
struct address_space *mapping = output->filp->f_mapping;
int old_gfp_mask = mapping_gfp_mask(mapping);
mapping_set_gfp_mask(mapping, old_gfp_mask & ~(__GFP_IO|__GFP_FS));
}
#endif
#ifdef WITH_THREAD
spin_lock_init(&output->lock);
init_waitqueue_head(&output->event);
INIT_LIST_HEAD(&output->mio_list);
output->thread = kthread_create(device_sio_thread, output, "mars_sio%d", 0);
if (IS_ERR(output->thread)) {
int error = PTR_ERR(output->thread);
MARS_ERR("cannot create thread, status=%d\n", error);
filp_close(output->filp, NULL);
return error;
}
wake_up_process(output->thread);
#endif
return 0;
}
static int device_sio_output_destruct(struct device_sio_output *output)
{
#ifdef WITH_THREAD
kthread_stop(output->thread);
output->thread = NULL;
#endif
if (output->filp) {
filp_close(output->filp, NULL);
output->filp = NULL;
}
return 0;
@ -112,7 +305,11 @@ static struct device_sio_brick_ops device_sio_brick_ops = {
};
static struct device_sio_output_ops device_sio_output_ops = {
#ifdef WITH_THREAD
.mars_io = device_sio_mars_queue,
#else
.mars_io = device_sio_mars_io,
#endif
};
static struct device_sio_output_type device_sio_output_type = {

View File

@ -1,4 +1,6 @@
// (c) 2010 Thomas Schoebel-Theuer / 1&1 Internet AG
//#define WITH_THREAD
struct device_sio_brick {
MARS_BRICK(device_sio);
};
@ -10,6 +12,12 @@ struct device_sio_input {
struct device_sio_output {
MARS_OUTPUT(device_sio);
struct file *filp;
#ifdef WITH_THREAD
struct list_head mio_list;
struct task_struct *thread;
wait_queue_head_t event;
spinlock_t lock;
#endif
};
MARS_TYPES(device_sio);

View File

@ -38,6 +38,7 @@ static int if_device_endio(struct mars_io *mio)
}
} // else lower layers have already signalled the orig_bio
kfree(mio);
return 0;
}
@ -65,7 +66,6 @@ static int if_device_make_request(struct request_queue *q, struct bio *bio)
goto err;
mio->orig_bio = bio;
mio->mars_bio = NULL;
mio->mars_endio = if_device_endio;
error = output->ops->mars_io(output, mio);
@ -107,6 +107,15 @@ static const struct block_device_operations if_device_blkdev_ops = {
////////////////// own brick / input / output operations //////////////////
static void if_device_unplug(struct request_queue *q)
{
//struct if_device_input *input = q->queuedata;
MARS_DBG("UNPLUG\n");
queue_flag_clear_unlocked(QUEUE_FLAG_PLUGGED, q);
//blk_run_address_space(lo->lo_backing_file->f_mapping);
}
//////////////////////// contructors / destructors ////////////////////////
static int if_device_brick_construct(struct if_device_brick *brick)
@ -132,7 +141,7 @@ static int if_device_input_construct(struct if_device_input *input)
MARS_ERR("cannot allocate device request queue\n");
return -ENOMEM;
}
q->queuedata = input;
q->queuedata = input;
input->q = q;
MARS_DBG("2\n");
@ -156,6 +165,8 @@ static int if_device_input_construct(struct if_device_input *input)
blk_queue_make_request(q, if_device_make_request);
blk_queue_max_segment_size(q, MARS_MAX_SEGMENT_SIZE);
blk_queue_bounce_limit(q, BLK_BOUNCE_ANY);
q->unplug_fn = if_device_unplug;
blk_queue_ordered(q, QUEUE_ORDERED_DRAIN, NULL);//???
MARS_DBG("4\n");
input->bdev = bdget(MKDEV(disk->major, minor));
@ -171,7 +182,6 @@ static int if_device_input_construct(struct if_device_input *input)
blk_queue_merge_bvec(q, mars_merge_bvec);
q->queue_lock = &input->req_lock; /* needed since we use */
/* plugging on a queue, that actually has no requests! */
q->unplug_fn = mars_unplug_fn;
#endif
MARS_DBG("99999\n");