2011-03-18 13:15:40 +00:00
|
|
|
// (c) 2010 Thomas Schoebel-Theuer / 1&1 Internet AG
|
|
|
|
|
2012-02-12 11:19:57 +00:00
|
|
|
// (c) 2010 Thomas Schoebel-Theuer / 1&1 Internet AG
|
|
|
|
|
2011-03-18 13:15:40 +00:00
|
|
|
// Bio brick (interface to blkdev IO via kernel bios)
|
|
|
|
|
|
|
|
//#define BRICK_DEBUGGING
|
|
|
|
//#define MARS_DEBUGGING
|
|
|
|
//#define IO_DEBUGGING
|
|
|
|
|
|
|
|
//#define FAKE_IO
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/bio.h>
|
|
|
|
|
|
|
|
#include "mars.h"
|
2012-10-12 12:17:34 +00:00
|
|
|
#include "lib_timing.h"
|
|
|
|
|
2012-10-15 14:35:36 +00:00
|
|
|
#include "mars_bio.h"
|
|
|
|
|
2012-10-12 12:17:34 +00:00
|
|
|
static struct timing_stats timings[2] = {};
|
2011-03-18 13:15:40 +00:00
|
|
|
|
2012-10-15 14:35:36 +00:00
|
|
|
struct threshold bio_submit_threshold = {
|
|
|
|
.thr_ban = &mars_global_ban,
|
|
|
|
.thr_limit = BIO_SUBMIT_MAX_LATENCY,
|
|
|
|
.thr_factor = 100,
|
|
|
|
.thr_plus = 0,
|
|
|
|
};
|
|
|
|
EXPORT_SYMBOL_GPL(bio_submit_threshold);
|
|
|
|
|
|
|
|
struct threshold bio_io_threshold[2] = {
|
|
|
|
[0] = {
|
|
|
|
.thr_ban = &mars_global_ban,
|
|
|
|
.thr_limit = BIO_IO_R_MAX_LATENCY,
|
|
|
|
.thr_factor = 10,
|
|
|
|
.thr_plus = 10000,
|
|
|
|
},
|
|
|
|
[1] = {
|
|
|
|
.thr_ban = &mars_global_ban,
|
|
|
|
.thr_limit = BIO_IO_W_MAX_LATENCY,
|
|
|
|
.thr_factor = 10,
|
|
|
|
.thr_plus = 10000,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
EXPORT_SYMBOL_GPL(bio_io_threshold);
|
2011-03-18 13:15:40 +00:00
|
|
|
|
2012-10-15 14:35:36 +00:00
|
|
|
///////////////////////// own type definitions ////////////////////////
|
2011-03-18 13:15:40 +00:00
|
|
|
|
|
|
|
static void bio_ref_put(struct bio_output *output, struct mref_object *mref);
|
|
|
|
|
|
|
|
///////////////////////// own helper functions ////////////////////////
|
|
|
|
|
|
|
|
/* This is called from the kernel bio layer.
|
|
|
|
*/
|
|
|
|
static
|
|
|
|
void bio_callback(struct bio *bio, int code)
|
|
|
|
{
|
|
|
|
struct bio_mref_aspect *mref_a = bio->bi_private;
|
|
|
|
struct bio_brick *brick;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
CHECK_PTR(mref_a, err);
|
|
|
|
CHECK_PTR(mref_a->output, err);
|
|
|
|
brick = mref_a->output->brick;
|
|
|
|
CHECK_PTR(brick, err);
|
|
|
|
|
|
|
|
mref_a->status_code = code;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&brick->lock, flags);
|
2012-10-15 14:35:36 +00:00
|
|
|
list_del(&mref_a->io_head);
|
|
|
|
list_add_tail(&mref_a->io_head, &brick->completed_list);
|
|
|
|
atomic_inc(&brick->completed_count);
|
2011-03-18 13:15:40 +00:00
|
|
|
spin_unlock_irqrestore(&brick->lock, flags);
|
|
|
|
|
2012-10-12 07:50:37 +00:00
|
|
|
wake_up_interruptible(&brick->response_event);
|
2011-03-18 13:15:40 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
err:
|
|
|
|
MARS_FAT("cannot handle bio callback\n");
|
|
|
|
}
|
|
|
|
|
2011-03-31 16:16:00 +00:00
|
|
|
/* Map from kernel address/length to struct page (if not already known),
|
|
|
|
* check alignment constraints, create bio from it.
|
|
|
|
* Return the length (may be smaller than requested).
|
2011-03-18 13:15:40 +00:00
|
|
|
*/
|
|
|
|
static
|
2011-04-21 16:03:04 +00:00
|
|
|
int make_bio(struct bio_brick *brick, void *data, int len, loff_t pos, struct bio_mref_aspect *private, struct bio **_bio)
|
2011-03-18 13:15:40 +00:00
|
|
|
{
|
|
|
|
unsigned long long sector;
|
|
|
|
int sector_offset;
|
|
|
|
int data_offset;
|
|
|
|
int page_offset;
|
|
|
|
int page_len;
|
|
|
|
int bvec_count;
|
2011-03-31 16:16:00 +00:00
|
|
|
int rest_len = len;
|
|
|
|
int result_len = 0;
|
2011-03-18 13:15:40 +00:00
|
|
|
int status;
|
|
|
|
int i;
|
|
|
|
struct bio *bio = NULL;
|
|
|
|
struct block_device *bdev;
|
|
|
|
|
|
|
|
status = -EINVAL;
|
|
|
|
CHECK_PTR(brick, out);
|
|
|
|
bdev = brick->bdev;
|
|
|
|
CHECK_PTR(bdev, out);
|
|
|
|
|
2011-03-31 16:16:00 +00:00
|
|
|
if (unlikely(rest_len <= 0)) {
|
|
|
|
MARS_ERR("bad bio len %d\n", rest_len);
|
2011-03-18 13:15:40 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
sector = pos >> 9; // TODO: make dynamic
|
|
|
|
sector_offset = pos & ((1 << 9) - 1); // TODO: make dynamic
|
|
|
|
data_offset = ((unsigned long)data) & ((1 << 9) - 1); // TODO: make dynamic
|
|
|
|
|
|
|
|
if (unlikely(sector_offset > 0)) {
|
|
|
|
MARS_ERR("odd sector offset %d\n", sector_offset);
|
|
|
|
goto out;
|
|
|
|
}
|
2011-03-30 12:02:50 +00:00
|
|
|
if (unlikely(sector_offset != data_offset)) {
|
|
|
|
MARS_ERR("bad alignment: sector_offset %d != data_offet %d\n", sector_offset, data_offset);
|
|
|
|
goto out;
|
|
|
|
}
|
2011-03-31 16:16:00 +00:00
|
|
|
if (unlikely(rest_len & ((1 << 9) - 1))) {
|
|
|
|
MARS_ERR("odd length %d\n", rest_len);
|
2011-03-18 13:15:40 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2011-04-21 16:03:04 +00:00
|
|
|
page_offset = ((unsigned long)data) & (PAGE_SIZE-1);
|
2011-03-31 16:16:00 +00:00
|
|
|
page_len = rest_len + page_offset;
|
2011-03-18 13:15:40 +00:00
|
|
|
bvec_count = (page_len - 1) / PAGE_SIZE + 1;
|
2011-03-30 12:02:50 +00:00
|
|
|
if (bvec_count > brick->bvec_max) {
|
2011-03-18 13:15:40 +00:00
|
|
|
bvec_count = brick->bvec_max;
|
2011-03-30 12:02:50 +00:00
|
|
|
}
|
2011-03-18 13:15:40 +00:00
|
|
|
|
2011-03-31 16:16:00 +00:00
|
|
|
MARS_IO("sector_offset = %d data = %p pos = %lld rest_len = %d page_offset = %d page_len = %d bvec_count = %d\n", sector_offset, data, pos, rest_len, page_offset, page_len, bvec_count);
|
2011-03-18 13:15:40 +00:00
|
|
|
|
|
|
|
bio = bio_alloc(GFP_MARS, bvec_count);
|
|
|
|
status = -ENOMEM;
|
2011-03-31 16:16:00 +00:00
|
|
|
if (unlikely(!bio)) {
|
2011-03-18 13:15:40 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2011-03-31 16:16:00 +00:00
|
|
|
for (i = 0; i < bvec_count && rest_len > 0; i++) {
|
2011-04-21 16:03:04 +00:00
|
|
|
struct page *page;
|
2011-03-31 16:16:00 +00:00
|
|
|
int this_rest = PAGE_SIZE - page_offset;
|
|
|
|
int this_len = rest_len;
|
2011-03-18 13:15:40 +00:00
|
|
|
|
2011-03-31 16:16:00 +00:00
|
|
|
if (this_len > this_rest) {
|
|
|
|
this_len = this_rest;
|
|
|
|
}
|
|
|
|
#ifdef MARS_DEBUGGING
|
2011-03-18 13:15:40 +00:00
|
|
|
if (unlikely(!virt_addr_valid(data))) {
|
|
|
|
MARS_ERR("invalid virtual kernel address %p\n", data);
|
|
|
|
status = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
2011-03-31 16:16:00 +00:00
|
|
|
#endif
|
2011-03-18 13:15:40 +00:00
|
|
|
|
2011-08-12 11:09:48 +00:00
|
|
|
page = brick_iomap(data, &page_offset, &this_len);
|
2011-04-21 16:03:04 +00:00
|
|
|
if (unlikely(!page)) {
|
|
|
|
MARS_ERR("cannot iomap() kernel address %p\n", data);
|
|
|
|
status = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2011-03-31 16:16:00 +00:00
|
|
|
MARS_IO(" i = %d page = %p bv_len = %d bv_offset = %d\n", i, page, this_len, page_offset);
|
2011-03-18 13:15:40 +00:00
|
|
|
|
|
|
|
bio->bi_io_vec[i].bv_page = page;
|
2011-03-31 16:16:00 +00:00
|
|
|
bio->bi_io_vec[i].bv_len = this_len;
|
2011-03-18 13:15:40 +00:00
|
|
|
bio->bi_io_vec[i].bv_offset = page_offset;
|
|
|
|
|
2011-03-31 16:16:00 +00:00
|
|
|
data += this_len;
|
|
|
|
rest_len -= this_len;
|
|
|
|
result_len += this_len;
|
2011-03-18 13:15:40 +00:00
|
|
|
page_offset = 0;
|
2011-03-31 16:16:00 +00:00
|
|
|
//MARS_IO("page_offset=%d this_len=%d (new len=%d, new status=%d)\n", page_offset, this_len, rest_len, status);
|
2011-03-18 13:15:40 +00:00
|
|
|
}
|
|
|
|
|
2011-03-31 16:16:00 +00:00
|
|
|
if (unlikely(rest_len != 0)) {
|
|
|
|
MARS_ERR("computation of bvec_count %d was wrong, diff=%d\n", bvec_count, rest_len);
|
2011-03-18 13:15:40 +00:00
|
|
|
status = -EIO;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
bio->bi_vcnt = i;
|
|
|
|
bio->bi_idx = 0;
|
2011-03-31 16:16:00 +00:00
|
|
|
bio->bi_size = result_len;
|
2011-03-18 13:15:40 +00:00
|
|
|
bio->bi_sector = sector;
|
|
|
|
bio->bi_bdev = bdev;
|
|
|
|
bio->bi_private = private;
|
|
|
|
bio->bi_end_io = bio_callback;
|
|
|
|
bio->bi_rw = 0; // must be filled in later
|
2011-03-31 16:16:00 +00:00
|
|
|
status = result_len;
|
2011-03-18 13:15:40 +00:00
|
|
|
|
|
|
|
out:
|
|
|
|
if (unlikely(status < 0)) {
|
|
|
|
MARS_ERR("error %d\n", status);
|
|
|
|
if (bio) {
|
|
|
|
bio_put(bio);
|
|
|
|
bio = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*_bio = bio;
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
////////////////// own brick / input / output operations //////////////////
|
|
|
|
|
2012-02-25 21:22:52 +00:00
|
|
|
#define PRIO_INDEX(mref) ((mref)->ref_prio + 1)
|
|
|
|
|
2011-03-18 13:15:40 +00:00
|
|
|
static int bio_get_info(struct bio_output *output, struct mars_info *info)
|
|
|
|
{
|
|
|
|
struct bio_brick *brick = output->brick;
|
2012-08-16 12:42:54 +00:00
|
|
|
struct inode *inode;
|
2011-03-18 13:15:40 +00:00
|
|
|
int status = 0;
|
2012-08-16 12:42:54 +00:00
|
|
|
|
|
|
|
if (unlikely(!brick->filp ||
|
|
|
|
!brick->filp->f_mapping ||
|
|
|
|
!(inode = brick->filp->f_mapping->host))) {
|
|
|
|
status = -ENOENT;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
brick->total_size = inode->i_size;
|
2011-03-18 13:15:40 +00:00
|
|
|
info->current_size = brick->total_size;
|
|
|
|
MARS_DBG("determined device size = %lld\n", info->current_size);
|
|
|
|
info->backing_file = brick->filp;
|
2012-08-16 12:42:54 +00:00
|
|
|
done:
|
2011-03-18 13:15:40 +00:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int bio_ref_get(struct bio_output *output, struct mref_object *mref)
|
|
|
|
{
|
2011-10-03 17:31:02 +00:00
|
|
|
struct bio_mref_aspect *mref_a = bio_mref_get_aspect(output->brick, mref);
|
2011-03-18 13:15:40 +00:00
|
|
|
int status = -EINVAL;
|
|
|
|
|
|
|
|
CHECK_PTR(mref_a, done);
|
|
|
|
CHECK_PTR(output->brick, done);
|
|
|
|
_CHECK_ATOMIC(&mref->ref_count, !=, 0);
|
|
|
|
|
|
|
|
if (mref_a->output)
|
|
|
|
goto ok;
|
2012-02-25 21:22:52 +00:00
|
|
|
|
2011-03-18 13:15:40 +00:00
|
|
|
mref_a->output = output;
|
|
|
|
mref_a->bio = NULL;
|
|
|
|
|
2011-03-31 16:16:00 +00:00
|
|
|
if (!mref->ref_data) { // buffered IO.
|
2011-03-18 13:15:40 +00:00
|
|
|
status = -ENOMEM;
|
2011-08-12 11:09:48 +00:00
|
|
|
mref->ref_data = brick_block_alloc(mref->ref_pos, (mref_a->alloc_len = mref->ref_len));
|
2011-03-31 16:16:00 +00:00
|
|
|
if (unlikely(!mref->ref_data)) {
|
2011-03-18 13:15:40 +00:00
|
|
|
goto done;
|
2011-03-31 16:16:00 +00:00
|
|
|
}
|
|
|
|
mref_a->do_dealloc = true;
|
2011-03-18 13:15:40 +00:00
|
|
|
}
|
|
|
|
|
2011-04-21 16:03:04 +00:00
|
|
|
status = make_bio(output->brick, mref->ref_data, mref->ref_len, mref->ref_pos, mref_a, &mref_a->bio);
|
2011-03-18 13:15:40 +00:00
|
|
|
if (unlikely(status < 0 || !mref_a->bio)) {
|
|
|
|
MARS_ERR("could not create bio, status = %d\n", status);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2012-02-25 21:22:52 +00:00
|
|
|
if (unlikely(mref->ref_prio < MARS_PRIO_HIGH))
|
|
|
|
mref->ref_prio = MARS_PRIO_HIGH;
|
|
|
|
else if (unlikely(mref->ref_prio > MARS_PRIO_LOW))
|
|
|
|
mref->ref_prio = MARS_PRIO_LOW;
|
|
|
|
|
|
|
|
MARS_IO("len = %d status = %d prio = %d fly = %d\n", mref->ref_len, status, mref->ref_prio, atomic_read(&output->brick->fly_count[PRIO_INDEX(mref)]));
|
2011-03-18 13:15:40 +00:00
|
|
|
|
|
|
|
mref->ref_len = status;
|
|
|
|
ok:
|
|
|
|
atomic_inc(&mref->ref_count);
|
|
|
|
status = 0;
|
|
|
|
|
|
|
|
done:
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
void bio_ref_put(struct bio_output *output, struct mref_object *mref)
|
|
|
|
{
|
|
|
|
struct bio_mref_aspect *mref_a;
|
|
|
|
|
|
|
|
CHECK_ATOMIC(&mref->ref_count, 1);
|
|
|
|
if (!atomic_dec_and_test(&mref->ref_count)) {
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
MARS_IO("deallocating\n");
|
|
|
|
|
|
|
|
mref->ref_total_size = output->brick->total_size;
|
|
|
|
|
2011-10-03 17:31:02 +00:00
|
|
|
mref_a = bio_mref_get_aspect(output->brick, mref);
|
2011-03-18 13:15:40 +00:00
|
|
|
CHECK_PTR(mref_a, err);
|
|
|
|
|
|
|
|
if (likely(mref_a->bio)) {
|
2011-05-26 14:32:32 +00:00
|
|
|
#ifdef MARS_DEBUGGING
|
|
|
|
int bi_cnt = atomic_read(&mref_a->bio->bi_cnt);
|
|
|
|
if (bi_cnt > 1) {
|
|
|
|
MARS_DBG("bi_cnt = %d\n", bi_cnt);
|
|
|
|
}
|
|
|
|
#endif
|
2011-03-18 13:15:40 +00:00
|
|
|
bio_put(mref_a->bio);
|
|
|
|
mref_a->bio = NULL;
|
|
|
|
}
|
|
|
|
if (mref_a->do_dealloc) {
|
|
|
|
MARS_IO("free page\n");
|
2011-08-12 11:09:48 +00:00
|
|
|
brick_block_free(mref->ref_data, mref_a->alloc_len);
|
2011-03-31 16:16:00 +00:00
|
|
|
mref->ref_data = NULL;
|
2011-03-18 13:15:40 +00:00
|
|
|
}
|
|
|
|
bio_free_mref(mref);
|
|
|
|
|
|
|
|
done:
|
|
|
|
return;
|
|
|
|
|
|
|
|
err:
|
|
|
|
MARS_FAT("cannot work\n");
|
|
|
|
}
|
|
|
|
|
2011-05-26 14:32:32 +00:00
|
|
|
static
|
2012-02-25 21:22:52 +00:00
|
|
|
void _bio_ref_io(struct bio_output *output, struct mref_object *mref, bool cork)
|
2011-03-18 13:15:40 +00:00
|
|
|
{
|
2011-04-29 09:36:10 +00:00
|
|
|
struct bio_brick *brick = output->brick;
|
2011-10-03 17:31:02 +00:00
|
|
|
struct bio_mref_aspect *mref_a = bio_mref_get_aspect(output->brick, mref);
|
2011-03-18 13:15:40 +00:00
|
|
|
struct bio *bio;
|
2012-10-15 14:35:36 +00:00
|
|
|
unsigned long long latency;
|
|
|
|
unsigned long flags;
|
2011-03-18 13:15:40 +00:00
|
|
|
int rw;
|
|
|
|
int status = -EINVAL;
|
|
|
|
|
|
|
|
CHECK_PTR(mref_a, err);
|
|
|
|
bio = mref_a->bio;
|
|
|
|
CHECK_PTR(bio, err);
|
|
|
|
|
|
|
|
CHECK_ATOMIC(&mref->ref_count, 1);
|
|
|
|
atomic_inc(&mref->ref_count);
|
2012-02-25 21:22:52 +00:00
|
|
|
atomic_inc(&brick->fly_count[PRIO_INDEX(mref)]);
|
2011-03-18 13:15:40 +00:00
|
|
|
|
|
|
|
bio_get(bio);
|
|
|
|
|
|
|
|
rw = mref->ref_rw & 1;
|
2012-09-18 06:13:33 +00:00
|
|
|
#ifdef BIO_RW_NOIDLE
|
2012-02-25 21:22:52 +00:00
|
|
|
if (brick->do_noidle && !cork) {
|
2011-05-06 10:25:52 +00:00
|
|
|
rw |= (1 << BIO_RW_NOIDLE);
|
|
|
|
}
|
2012-09-18 06:13:33 +00:00
|
|
|
#endif
|
2011-05-06 10:25:52 +00:00
|
|
|
if (!mref->ref_skip_sync) {
|
2012-09-18 06:13:33 +00:00
|
|
|
#ifdef BIO_RW_SYNCIO
|
2011-05-06 10:25:52 +00:00
|
|
|
if (brick->do_sync) {
|
|
|
|
rw |= (1 << BIO_RW_SYNCIO);
|
|
|
|
}
|
2012-09-18 06:13:33 +00:00
|
|
|
#endif
|
|
|
|
#ifdef BIO_RW_UNPLUG
|
2012-02-25 21:22:52 +00:00
|
|
|
if (brick->do_unplug && !cork) {
|
2011-05-06 10:25:52 +00:00
|
|
|
rw |= (1 << BIO_RW_UNPLUG);
|
|
|
|
}
|
2012-09-18 06:13:33 +00:00
|
|
|
#endif
|
2011-05-06 10:25:52 +00:00
|
|
|
}
|
|
|
|
|
2012-02-25 21:22:52 +00:00
|
|
|
MARS_IO("starting IO rw = %d prio 0 %d fly = %d\n", rw, mref->ref_prio, atomic_read(&brick->fly_count[PRIO_INDEX(mref)]));
|
2011-03-27 15:18:38 +00:00
|
|
|
mars_trace(mref, "bio_submit");
|
2011-03-18 13:15:40 +00:00
|
|
|
|
2012-10-15 14:35:36 +00:00
|
|
|
mref_a->start_stamp = cpu_clock(raw_smp_processor_id());
|
|
|
|
spin_lock_irqsave(&brick->lock, flags);
|
|
|
|
list_add_tail(&mref_a->io_head, &brick->submitted_list[rw & 1]);
|
|
|
|
spin_unlock_irqrestore(&brick->lock, flags);
|
|
|
|
|
2011-03-18 13:15:40 +00:00
|
|
|
#ifdef FAKE_IO
|
|
|
|
bio->bi_end_io(bio, 0);
|
|
|
|
#else
|
2011-05-06 10:25:52 +00:00
|
|
|
bio->bi_rw = rw;
|
2012-10-15 14:35:36 +00:00
|
|
|
latency = TIME_STATS(
|
|
|
|
&timings[rw & 1],
|
|
|
|
submit_bio(rw, bio)
|
|
|
|
);
|
2011-03-18 13:15:40 +00:00
|
|
|
#endif
|
|
|
|
|
2012-10-15 14:35:36 +00:00
|
|
|
threshold_check(&bio_submit_threshold, latency);
|
|
|
|
|
2011-03-18 13:15:40 +00:00
|
|
|
status = 0;
|
|
|
|
if (unlikely(bio_flagged(bio, BIO_EOPNOTSUPP)))
|
|
|
|
status = -EOPNOTSUPP;
|
|
|
|
|
|
|
|
MARS_IO("submitted\n");
|
|
|
|
|
|
|
|
if (likely(status >= 0))
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
bio_put(bio);
|
2012-02-25 21:22:52 +00:00
|
|
|
atomic_dec(&brick->fly_count[PRIO_INDEX(mref)]);
|
2011-05-26 14:32:32 +00:00
|
|
|
|
2011-03-18 13:15:40 +00:00
|
|
|
err:
|
|
|
|
MARS_ERR("IO error %d\n", status);
|
2011-10-04 11:34:18 +00:00
|
|
|
CHECKED_CALLBACK(mref, status, done);
|
2012-11-16 11:43:10 +00:00
|
|
|
atomic_dec(&mars_global_io_flying);
|
2011-10-04 11:34:18 +00:00
|
|
|
|
2011-04-29 09:36:10 +00:00
|
|
|
done: ;
|
2011-03-18 13:15:40 +00:00
|
|
|
}
|
|
|
|
|
2011-05-26 14:32:32 +00:00
|
|
|
static
|
|
|
|
void bio_ref_io(struct bio_output *output, struct mref_object *mref)
|
|
|
|
{
|
2012-11-16 11:43:10 +00:00
|
|
|
atomic_inc(&mars_global_io_flying);
|
2012-10-12 07:50:37 +00:00
|
|
|
if (mref->ref_prio == MARS_PRIO_LOW ||
|
|
|
|
(mref->ref_prio == MARS_PRIO_NORMAL && mref->ref_rw)) {
|
2011-10-03 17:31:02 +00:00
|
|
|
struct bio_mref_aspect *mref_a = bio_mref_get_aspect(output->brick, mref);
|
2011-05-26 14:32:32 +00:00
|
|
|
struct bio_brick *brick = output->brick;
|
|
|
|
unsigned long flags;
|
2012-10-12 07:50:37 +00:00
|
|
|
|
|
|
|
atomic_inc(&mref->ref_count);
|
|
|
|
|
2011-05-26 14:32:32 +00:00
|
|
|
spin_lock_irqsave(&brick->lock, flags);
|
2012-10-12 07:50:37 +00:00
|
|
|
list_add_tail(&mref_a->io_head, &brick->queue_list[PRIO_INDEX(mref)]);
|
|
|
|
atomic_inc(&brick->queue_count[PRIO_INDEX(mref)]);
|
2011-05-26 14:32:32 +00:00
|
|
|
spin_unlock_irqrestore(&brick->lock, flags);
|
2012-10-12 07:50:37 +00:00
|
|
|
brick->submitted = true;
|
|
|
|
|
|
|
|
wake_up_interruptible(&brick->submit_event);
|
2011-05-26 14:32:32 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-10-12 07:50:37 +00:00
|
|
|
// realtime IO: start immediately
|
2012-02-25 21:22:52 +00:00
|
|
|
_bio_ref_io(output, mref, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
2012-10-12 07:50:37 +00:00
|
|
|
int bio_response_thread(void *data)
|
2011-03-18 13:15:40 +00:00
|
|
|
{
|
|
|
|
struct bio_brick *brick = data;
|
2011-10-12 14:57:53 +00:00
|
|
|
#ifdef IO_DEBUGGING
|
|
|
|
int round = 0;
|
|
|
|
#endif
|
2011-03-18 13:15:40 +00:00
|
|
|
|
2012-10-12 07:50:37 +00:00
|
|
|
MARS_INF("bio response thread has started on '%s'.\n", brick->brick_path);
|
2011-03-18 13:15:40 +00:00
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
LIST_HEAD(tmp_list);
|
|
|
|
unsigned long flags;
|
2012-10-15 14:35:36 +00:00
|
|
|
int thr_limit;
|
|
|
|
int sleeptime;
|
2012-10-12 07:50:37 +00:00
|
|
|
int count;
|
2012-10-15 14:35:36 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
thr_limit = bio_io_threshold[0].thr_limit;
|
|
|
|
if (bio_io_threshold[1].thr_limit < thr_limit)
|
|
|
|
thr_limit = bio_io_threshold[1].thr_limit;
|
|
|
|
|
|
|
|
sleeptime = HZ / 10;
|
|
|
|
if (thr_limit > 0) {
|
|
|
|
sleeptime = thr_limit / (1000000 * 2 / HZ);
|
|
|
|
if (unlikely(sleeptime < 2))
|
|
|
|
sleeptime = 2;
|
|
|
|
}
|
2011-03-18 13:15:40 +00:00
|
|
|
|
2011-10-12 14:57:53 +00:00
|
|
|
#ifdef IO_DEBUGGING
|
|
|
|
round++;
|
2012-10-15 14:35:36 +00:00
|
|
|
MARS_IO("%d sleeping %d...\n", round, sleeptime);
|
2011-10-12 14:57:53 +00:00
|
|
|
#endif
|
2011-05-26 14:32:32 +00:00
|
|
|
wait_event_interruptible_timeout(
|
2012-10-12 07:50:37 +00:00
|
|
|
brick->response_event,
|
|
|
|
atomic_read(&brick->completed_count) > 0,
|
2012-10-15 14:35:36 +00:00
|
|
|
sleeptime);
|
2012-02-25 21:22:52 +00:00
|
|
|
|
2012-10-12 07:50:37 +00:00
|
|
|
MARS_IO("%d woken up, completed_count = %d fly_count[0] = %d fly_count[1] = %d fly_count[2] = %d\n",
|
2012-02-25 21:22:52 +00:00
|
|
|
round,
|
|
|
|
atomic_read(&brick->completed_count),
|
|
|
|
atomic_read(&brick->fly_count[0]),
|
|
|
|
atomic_read(&brick->fly_count[1]),
|
|
|
|
atomic_read(&brick->fly_count[2]));
|
2011-03-18 13:15:40 +00:00
|
|
|
|
|
|
|
spin_lock_irqsave(&brick->lock, flags);
|
|
|
|
list_replace_init(&brick->completed_list, &tmp_list);
|
|
|
|
spin_unlock_irqrestore(&brick->lock, flags);
|
|
|
|
|
2012-10-12 07:50:37 +00:00
|
|
|
count = 0;
|
2011-03-18 13:15:40 +00:00
|
|
|
for (;;) {
|
|
|
|
struct list_head *tmp;
|
|
|
|
struct bio_mref_aspect *mref_a;
|
|
|
|
struct mref_object *mref;
|
2012-10-15 14:35:36 +00:00
|
|
|
unsigned long long latency;
|
2011-03-18 13:15:40 +00:00
|
|
|
int code;
|
|
|
|
|
|
|
|
if (list_empty(&tmp_list)) {
|
2012-11-13 16:01:37 +00:00
|
|
|
if (brick_thread_should_stop())
|
2011-03-18 13:15:40 +00:00
|
|
|
goto done;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp = tmp_list.next;
|
|
|
|
list_del_init(tmp);
|
2011-04-29 09:36:10 +00:00
|
|
|
atomic_dec(&brick->completed_count);
|
2012-10-15 14:35:36 +00:00
|
|
|
|
2011-03-18 13:15:40 +00:00
|
|
|
mref_a = container_of(tmp, struct bio_mref_aspect, io_head);
|
2012-10-15 14:35:36 +00:00
|
|
|
mref = mref_a->object;
|
|
|
|
|
2011-03-18 13:15:40 +00:00
|
|
|
|
2012-10-15 14:35:36 +00:00
|
|
|
latency = cpu_clock(raw_smp_processor_id()) - mref_a->start_stamp;
|
|
|
|
threshold_check(&bio_io_threshold[mref->ref_rw & 1], latency);
|
|
|
|
|
2011-03-18 13:15:40 +00:00
|
|
|
code = mref_a->status_code;
|
2011-10-12 14:57:53 +00:00
|
|
|
#ifdef IO_DEBUGGING
|
|
|
|
round++;
|
|
|
|
MARS_IO("%d completed , status = %d\n", round, code);
|
|
|
|
#endif
|
2011-03-18 13:15:40 +00:00
|
|
|
|
2011-03-27 15:18:38 +00:00
|
|
|
mars_trace(mref, "bio_endio");
|
|
|
|
|
2011-03-18 13:15:40 +00:00
|
|
|
if (code < 0) {
|
|
|
|
MARS_ERR("IO error %d\n", code);
|
|
|
|
} else {
|
2012-08-01 10:09:49 +00:00
|
|
|
mref_checksum(mref);
|
2011-03-18 13:15:40 +00:00
|
|
|
mref->ref_flags |= MREF_UPTODATE;
|
|
|
|
}
|
2011-10-04 11:34:18 +00:00
|
|
|
|
|
|
|
SIMPLE_CALLBACK(mref, code);
|
2011-10-12 14:57:53 +00:00
|
|
|
|
|
|
|
MARS_IO("%d callback done.\n", round);
|
2011-03-18 13:15:40 +00:00
|
|
|
|
2012-02-25 21:22:52 +00:00
|
|
|
atomic_dec(&brick->fly_count[PRIO_INDEX(mref)]);
|
|
|
|
atomic_inc(&brick->total_completed_count[PRIO_INDEX(mref)]);
|
2012-10-12 07:50:37 +00:00
|
|
|
count++;
|
2012-02-25 21:22:52 +00:00
|
|
|
|
2012-10-12 07:50:37 +00:00
|
|
|
MARS_IO("%d completed_count = %d fly_count = %d\n", round, atomic_read(&brick->completed_count), atomic_read(&brick->fly_count[PRIO_INDEX(mref)]));
|
2012-02-25 21:22:52 +00:00
|
|
|
|
2011-05-26 14:32:32 +00:00
|
|
|
if (likely(mref_a->bio)) {
|
|
|
|
bio_put(mref_a->bio);
|
|
|
|
}
|
2011-03-18 13:15:40 +00:00
|
|
|
bio_ref_put(mref_a->output, mref);
|
2012-11-16 11:43:10 +00:00
|
|
|
|
|
|
|
atomic_dec(&mars_global_io_flying);
|
2011-03-18 13:15:40 +00:00
|
|
|
}
|
2012-10-15 14:35:36 +00:00
|
|
|
|
|
|
|
/* Try to detect slow requests as early as possible,
|
|
|
|
* even before they have completed.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
unsigned long long eldest = 0;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&brick->lock, flags);
|
|
|
|
if (!list_empty(&brick->submitted_list[i])) {
|
|
|
|
struct bio_mref_aspect *mref_a;
|
|
|
|
mref_a = container_of(brick->submitted_list[i].next, struct bio_mref_aspect, io_head);
|
|
|
|
eldest = mref_a->start_stamp;
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&brick->lock, flags);
|
|
|
|
|
|
|
|
if (eldest) {
|
|
|
|
threshold_check(&bio_io_threshold[i], cpu_clock(raw_smp_processor_id()) - eldest);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-12 07:50:37 +00:00
|
|
|
if (count) {
|
|
|
|
brick->submitted = true;
|
|
|
|
wake_up_interruptible(&brick->submit_event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
done:
|
|
|
|
MARS_INF("bio response thread has stopped.\n");
|
|
|
|
return 0;
|
|
|
|
}
|
2011-05-26 14:32:32 +00:00
|
|
|
|
2012-10-12 07:50:37 +00:00
|
|
|
static
|
|
|
|
bool _bg_should_run(struct bio_brick *brick)
|
|
|
|
{
|
|
|
|
return (atomic_read(&brick->queue_count[2]) > 0 &&
|
|
|
|
atomic_read(&brick->fly_count[0]) + atomic_read(&brick->fly_count[1]) <= brick->bg_threshold &&
|
|
|
|
(brick->bg_maxfly <= 0 || atomic_read(&brick->fly_count[2]) < brick->bg_maxfly));
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
int bio_submit_thread(void *data)
|
|
|
|
{
|
|
|
|
struct bio_brick *brick = data;
|
|
|
|
#ifdef IO_DEBUGGING
|
|
|
|
int round = 0;
|
|
|
|
#endif
|
2011-05-26 14:32:32 +00:00
|
|
|
|
2012-10-12 07:50:37 +00:00
|
|
|
MARS_INF("bio submit thread has started on '%s'.\n", brick->brick_path);
|
|
|
|
|
2012-11-13 16:01:37 +00:00
|
|
|
while (!brick_thread_should_stop()) {
|
2012-10-12 07:50:37 +00:00
|
|
|
int prio;
|
|
|
|
#ifdef IO_DEBUGGING
|
|
|
|
round++;
|
|
|
|
MARS_IO("%d sleeping...\n", round);
|
|
|
|
#endif
|
|
|
|
wait_event_interruptible_timeout(
|
|
|
|
brick->submit_event,
|
|
|
|
brick->submitted,
|
2012-10-15 14:35:36 +00:00
|
|
|
HZ / 2);
|
2012-10-12 07:50:37 +00:00
|
|
|
|
|
|
|
brick->submitted = false;
|
|
|
|
|
|
|
|
MARS_IO("%d woken up, completed_count = %d fly_count[0] = %d fly_count[1] = %d fly_count[2] = %d\n",
|
|
|
|
round,
|
|
|
|
atomic_read(&brick->completed_count),
|
|
|
|
atomic_read(&brick->fly_count[0]),
|
|
|
|
atomic_read(&brick->fly_count[1]),
|
|
|
|
atomic_read(&brick->fly_count[2]));
|
|
|
|
|
|
|
|
for (prio = 0; prio < MARS_PRIO_NR; prio++) {
|
|
|
|
LIST_HEAD(tmp_list);
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
if (prio == MARS_PRIO_NR-1 && !_bg_should_run(brick)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
MARS_IO("%d pushing prio %d to foreground, completed_count = %d\n", round, prio, atomic_read(&brick->completed_count));
|
2011-10-12 14:57:53 +00:00
|
|
|
|
2011-05-26 14:32:32 +00:00
|
|
|
spin_lock_irqsave(&brick->lock, flags);
|
2012-10-12 07:50:37 +00:00
|
|
|
list_replace_init(&brick->queue_list[prio], &tmp_list);
|
2011-05-26 14:32:32 +00:00
|
|
|
spin_unlock_irqrestore(&brick->lock, flags);
|
|
|
|
|
2012-10-12 07:50:37 +00:00
|
|
|
while (!list_empty(&tmp_list)) {
|
|
|
|
struct list_head *tmp = tmp_list.next;
|
|
|
|
struct bio_mref_aspect *mref_a;
|
|
|
|
struct mref_object *mref;
|
|
|
|
bool cork;
|
|
|
|
|
|
|
|
list_del_init(tmp);
|
|
|
|
|
|
|
|
mref_a = container_of(tmp, struct bio_mref_aspect, io_head);
|
|
|
|
mref = mref_a->object;
|
|
|
|
if (unlikely(!mref)) {
|
|
|
|
MARS_ERR("invalid mref\n");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
atomic_dec(&brick->queue_count[PRIO_INDEX(mref)]);
|
|
|
|
cork = atomic_read(&brick->queue_count[PRIO_INDEX(mref)]) > 0;
|
|
|
|
|
|
|
|
_bio_ref_io(mref_a->output, mref, cork);
|
|
|
|
|
|
|
|
bio_ref_put(mref_a->output, mref);
|
2011-05-26 14:32:32 +00:00
|
|
|
}
|
|
|
|
}
|
2011-03-18 13:15:40 +00:00
|
|
|
}
|
2012-10-12 07:50:37 +00:00
|
|
|
|
|
|
|
MARS_INF("bio submit thread has stopped.\n");
|
2011-03-18 13:15:40 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int bio_switch(struct bio_brick *brick)
|
|
|
|
{
|
|
|
|
int status = 0;
|
|
|
|
if (brick->power.button) {
|
|
|
|
mars_power_led_off((void*)brick, false);
|
|
|
|
|
|
|
|
if (!brick->bdev) {
|
|
|
|
static int index = 0;
|
2011-10-07 09:13:46 +00:00
|
|
|
const char *path = brick->brick_path;
|
2011-03-18 13:15:40 +00:00
|
|
|
int flags = O_RDWR | O_LARGEFILE;
|
|
|
|
int prot = 0600;
|
|
|
|
struct inode *inode;
|
|
|
|
struct request_queue *q;
|
|
|
|
mm_segment_t oldfs;
|
|
|
|
|
|
|
|
oldfs = get_fs();
|
|
|
|
set_fs(get_ds());
|
|
|
|
brick->filp = filp_open(path, flags, prot);
|
|
|
|
set_fs(oldfs);
|
|
|
|
|
|
|
|
if (!brick->filp) {
|
|
|
|
MARS_ERR("cannot open '%s'\n", path);
|
|
|
|
status = -ENOENT;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = -EINVAL;
|
|
|
|
CHECK_PTR(brick->filp->f_mapping, done);
|
|
|
|
inode = brick->filp->f_mapping->host;
|
|
|
|
CHECK_PTR(inode, done);
|
|
|
|
if (!S_ISBLK(inode->i_mode)) {
|
|
|
|
MARS_ERR("sorry, '%s' is not a block device\n", path);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
q = bdev_get_queue(inode->i_bdev);
|
|
|
|
CHECK_PTR(q, done);
|
|
|
|
|
2011-08-05 09:26:24 +00:00
|
|
|
#if 1
|
2011-03-18 13:15:40 +00:00
|
|
|
MARS_INF("ra_pages OLD=%lu NEW=%d\n", q->backing_dev_info.ra_pages, brick->ra_pages);
|
|
|
|
q->backing_dev_info.ra_pages = brick->ra_pages;
|
2011-08-05 09:26:24 +00:00
|
|
|
#endif
|
2011-03-18 13:15:40 +00:00
|
|
|
brick->bvec_max = queue_max_hw_sectors(q) >> (PAGE_SHIFT - 9);
|
|
|
|
brick->total_size = inode->i_size;
|
2012-10-12 07:50:37 +00:00
|
|
|
|
|
|
|
brick->response_thread = brick_thread_create(bio_response_thread, brick, "mars_bio_r%d", index);
|
|
|
|
brick->submit_thread = brick_thread_create(bio_submit_thread, brick, "mars_bio_s%d", index);
|
|
|
|
index++;
|
|
|
|
if (likely(brick->submit_thread && brick->response_thread)) {
|
2011-03-18 13:15:40 +00:00
|
|
|
brick->bdev = inode->i_bdev;
|
|
|
|
status = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (brick->bdev) {
|
|
|
|
mars_power_led_on((void*)brick, true);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
mars_power_led_on((void*)brick, false);
|
|
|
|
|
|
|
|
// TODO: wait for IO completion
|
|
|
|
|
|
|
|
if (brick->filp) {
|
|
|
|
filp_close(brick->filp, NULL);
|
|
|
|
brick->filp = NULL;
|
|
|
|
}
|
2012-10-12 07:50:37 +00:00
|
|
|
brick_thread_stop(brick->submit_thread);
|
|
|
|
brick_thread_stop(brick->response_thread);
|
2011-03-18 13:15:40 +00:00
|
|
|
brick->bdev = NULL;
|
|
|
|
brick->total_size = 0;
|
|
|
|
|
|
|
|
mars_power_led_off((void*)brick, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
if (status < 0 && brick->filp) {
|
|
|
|
filp_close(brick->filp, NULL);
|
|
|
|
brick->filp = NULL;
|
|
|
|
}
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-29 09:36:10 +00:00
|
|
|
//////////////// informational / statistics ///////////////
|
|
|
|
|
|
|
|
static noinline
|
|
|
|
char *bio_statistics(struct bio_brick *brick, int verbose)
|
|
|
|
{
|
2012-10-12 12:17:34 +00:00
|
|
|
char *res = brick_string_alloc(4096);
|
|
|
|
int pos = 0;
|
2011-04-29 09:36:10 +00:00
|
|
|
if (!res)
|
|
|
|
return NULL;
|
|
|
|
|
2012-10-12 12:17:34 +00:00
|
|
|
pos += report_timing(&timings[0], res + pos, 4096 - pos);
|
|
|
|
pos += report_timing(&timings[1], res + pos, 4096 - pos);
|
2011-04-29 09:36:10 +00:00
|
|
|
|
2012-10-12 12:17:34 +00:00
|
|
|
snprintf(res + pos, 4096 - pos,
|
2012-02-25 21:22:52 +00:00
|
|
|
"total "
|
|
|
|
"completed[0] = %d "
|
|
|
|
"completed[1] = %d "
|
2012-10-12 07:50:37 +00:00
|
|
|
"completed[2] = %d | "
|
|
|
|
"queued[0] = %d "
|
|
|
|
"queued[1] = %d "
|
|
|
|
"queued[2] = %d "
|
2012-02-25 21:22:52 +00:00
|
|
|
"flying[0] = %d "
|
|
|
|
"flying[1] = %d "
|
|
|
|
"flying[2] = %d "
|
2012-10-12 07:50:37 +00:00
|
|
|
"completing = %d\n",
|
2012-02-25 21:22:52 +00:00
|
|
|
atomic_read(&brick->total_completed_count[0]),
|
|
|
|
atomic_read(&brick->total_completed_count[1]),
|
|
|
|
atomic_read(&brick->total_completed_count[2]),
|
|
|
|
atomic_read(&brick->fly_count[0]),
|
2012-10-12 07:50:37 +00:00
|
|
|
atomic_read(&brick->queue_count[0]),
|
|
|
|
atomic_read(&brick->queue_count[1]),
|
|
|
|
atomic_read(&brick->queue_count[2]),
|
2012-02-25 21:22:52 +00:00
|
|
|
atomic_read(&brick->fly_count[1]),
|
|
|
|
atomic_read(&brick->fly_count[2]),
|
2012-10-12 07:50:37 +00:00
|
|
|
atomic_read(&brick->completed_count));
|
2011-04-29 09:36:10 +00:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static noinline
|
|
|
|
void bio_reset_statistics(struct bio_brick *brick)
|
|
|
|
{
|
2012-02-25 21:22:52 +00:00
|
|
|
atomic_set(&brick->total_completed_count[0], 0);
|
|
|
|
atomic_set(&brick->total_completed_count[1], 0);
|
|
|
|
atomic_set(&brick->total_completed_count[2], 0);
|
2011-04-29 09:36:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-18 13:15:40 +00:00
|
|
|
//////////////// object / aspect constructors / destructors ///////////////
|
|
|
|
|
2011-10-03 17:31:02 +00:00
|
|
|
static int bio_mref_aspect_init_fn(struct generic_aspect *_ini)
|
2011-03-18 13:15:40 +00:00
|
|
|
{
|
|
|
|
struct bio_mref_aspect *ini = (void*)_ini;
|
|
|
|
INIT_LIST_HEAD(&ini->io_head);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-10-03 17:31:02 +00:00
|
|
|
static void bio_mref_aspect_exit_fn(struct generic_aspect *_ini)
|
2011-03-18 13:15:40 +00:00
|
|
|
{
|
|
|
|
struct bio_mref_aspect *ini = (void*)_ini;
|
|
|
|
(void)ini;
|
|
|
|
}
|
|
|
|
|
|
|
|
MARS_MAKE_STATICS(bio);
|
|
|
|
|
|
|
|
////////////////////// brick constructors / destructors ////////////////////
|
|
|
|
|
|
|
|
static int bio_brick_construct(struct bio_brick *brick)
|
|
|
|
{
|
|
|
|
spin_lock_init(&brick->lock);
|
2012-10-12 07:50:37 +00:00
|
|
|
INIT_LIST_HEAD(&brick->queue_list[0]);
|
|
|
|
INIT_LIST_HEAD(&brick->queue_list[1]);
|
|
|
|
INIT_LIST_HEAD(&brick->queue_list[2]);
|
2012-10-15 14:35:36 +00:00
|
|
|
INIT_LIST_HEAD(&brick->submitted_list[0]);
|
|
|
|
INIT_LIST_HEAD(&brick->submitted_list[1]);
|
2011-03-18 13:15:40 +00:00
|
|
|
INIT_LIST_HEAD(&brick->completed_list);
|
2012-10-12 07:50:37 +00:00
|
|
|
init_waitqueue_head(&brick->submit_event);
|
|
|
|
init_waitqueue_head(&brick->response_event);
|
2011-03-18 13:15:40 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int bio_brick_destruct(struct bio_brick *brick)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int bio_output_construct(struct bio_output *output)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int bio_output_destruct(struct bio_output *output)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////// static structs ////////////////////////
|
|
|
|
|
|
|
|
static struct bio_brick_ops bio_brick_ops = {
|
|
|
|
.brick_switch = bio_switch,
|
2011-04-29 09:36:10 +00:00
|
|
|
.brick_statistics = bio_statistics,
|
|
|
|
.reset_statistics = bio_reset_statistics,
|
2011-03-18 13:15:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct bio_output_ops bio_output_ops = {
|
|
|
|
.mars_get_info = bio_get_info,
|
|
|
|
.mref_get = bio_ref_get,
|
|
|
|
.mref_put = bio_ref_put,
|
|
|
|
.mref_io = bio_ref_io,
|
|
|
|
};
|
|
|
|
|
|
|
|
const struct bio_input_type bio_input_type = {
|
|
|
|
.type_name = "bio_input",
|
|
|
|
.input_size = sizeof(struct bio_input),
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct bio_input_type *bio_input_types[] = {
|
|
|
|
&bio_input_type,
|
|
|
|
};
|
|
|
|
|
|
|
|
const struct bio_output_type bio_output_type = {
|
|
|
|
.type_name = "bio_output",
|
|
|
|
.output_size = sizeof(struct bio_output),
|
|
|
|
.master_ops = &bio_output_ops,
|
|
|
|
.output_construct = &bio_output_construct,
|
|
|
|
.output_destruct = &bio_output_destruct,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct bio_output_type *bio_output_types[] = {
|
|
|
|
&bio_output_type,
|
|
|
|
};
|
|
|
|
|
|
|
|
const struct bio_brick_type bio_brick_type = {
|
|
|
|
.type_name = "bio_brick",
|
|
|
|
.brick_size = sizeof(struct bio_brick),
|
|
|
|
.max_inputs = 0,
|
|
|
|
.max_outputs = 1,
|
|
|
|
.master_ops = &bio_brick_ops,
|
2011-10-03 17:31:02 +00:00
|
|
|
.aspect_types = bio_aspect_types,
|
2011-03-18 13:15:40 +00:00
|
|
|
.default_input_types = bio_input_types,
|
|
|
|
.default_output_types = bio_output_types,
|
|
|
|
.brick_construct = &bio_brick_construct,
|
|
|
|
.brick_destruct = &bio_brick_destruct,
|
|
|
|
};
|
|
|
|
EXPORT_SYMBOL_GPL(bio_brick_type);
|
|
|
|
|
|
|
|
////////////////// module init stuff /////////////////////////
|
|
|
|
|
2011-08-25 10:16:32 +00:00
|
|
|
int __init init_mars_bio(void)
|
2011-03-18 13:15:40 +00:00
|
|
|
{
|
|
|
|
MARS_INF("init_bio()\n");
|
|
|
|
_bio_brick_type = (void*)&bio_brick_type;
|
|
|
|
return bio_register_brick_type();
|
|
|
|
}
|
|
|
|
|
2011-08-25 10:16:32 +00:00
|
|
|
void __exit exit_mars_bio(void)
|
2011-03-18 13:15:40 +00:00
|
|
|
{
|
|
|
|
MARS_INF("exit_bio()\n");
|
|
|
|
bio_unregister_brick_type();
|
|
|
|
}
|
|
|
|
|
2011-08-25 10:16:32 +00:00
|
|
|
#ifndef CONFIG_MARS_HAVE_BIGMODULE
|
2011-03-18 13:15:40 +00:00
|
|
|
MODULE_DESCRIPTION("MARS bio brick");
|
|
|
|
MODULE_AUTHOR("Thomas Schoebel-Theuer <tst@1und1.de>");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
2011-08-25 10:16:32 +00:00
|
|
|
module_init(init_mars_bio);
|
|
|
|
module_exit(exit_mars_bio);
|
|
|
|
#endif
|