2014-11-21 10:51:34 +00:00
|
|
|
/*
|
|
|
|
* MARS Long Distance Replication Software
|
|
|
|
*
|
|
|
|
* This file is part of MARS project: http://schoebel.github.io/mars/
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010-2014 Thomas Schoebel-Theuer
|
|
|
|
* Copyright (C) 2011-2014 1&1 Internet AG
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
2010-06-14 14:27:40 +00:00
|
|
|
|
|
|
|
/* Interface to a Linux device.
|
|
|
|
* 1 Input, 0 Outputs.
|
|
|
|
*/
|
|
|
|
|
2010-07-30 05:46:22 +00:00
|
|
|
//#define BRICK_DEBUGGING
|
|
|
|
//#define MARS_DEBUGGING
|
2011-03-18 13:15:40 +00:00
|
|
|
//#define IO_DEBUGGING
|
|
|
|
|
2011-04-21 16:03:04 +00:00
|
|
|
#define REQUEST_MERGING
|
2012-01-13 11:01:23 +00:00
|
|
|
//#define ALWAYS_UNPLUG false // FIXME: does not work! single requests left over!
|
|
|
|
#define ALWAYS_UNPLUG true
|
2011-12-08 15:38:04 +00:00
|
|
|
#define ALWAYS_UNPLUG_FROM_EXTERNAL true
|
2011-04-21 16:03:04 +00:00
|
|
|
#define PREFETCH_LEN PAGE_SIZE
|
|
|
|
//#define FRONT_MERGE // FIXME: this does not work.
|
2011-12-08 15:38:04 +00:00
|
|
|
//#define MODIFY_READAHEAD // don't use it, otherwise sequential IO will suffer
|
2010-07-30 05:46:22 +00:00
|
|
|
|
2011-03-18 13:15:40 +00:00
|
|
|
// low-level device parameters
|
2011-12-08 15:38:04 +00:00
|
|
|
#define USE_MAX_SECTORS (MARS_MAX_SEGMENT_SIZE >> 9)
|
|
|
|
#define USE_MAX_PHYS_SEGMENTS (MARS_MAX_SEGMENT_SIZE >> 9)
|
|
|
|
#define USE_MAX_SEGMENT_SIZE MARS_MAX_SEGMENT_SIZE
|
|
|
|
#define USE_LOGICAL_BLOCK_SIZE 512
|
2019-01-10 06:25:27 +00:00
|
|
|
#define USE_MAX_HW_SECTORS 1
|
2011-12-08 15:38:04 +00:00
|
|
|
#define USE_SEGMENT_BOUNDARY (PAGE_SIZE-1)
|
|
|
|
|
|
|
|
#define USE_CONGESTED_FN
|
2011-10-12 14:57:53 +00:00
|
|
|
//#define DENY_READA
|
2011-03-18 13:15:40 +00:00
|
|
|
|
2010-06-14 14:27:40 +00:00
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
|
2012-11-28 11:42:05 +00:00
|
|
|
#include <linux/bio.h>
|
2010-06-14 14:27:40 +00:00
|
|
|
#include <linux/major.h>
|
|
|
|
#include <linux/genhd.h>
|
|
|
|
#include <linux/blkdev.h>
|
|
|
|
|
|
|
|
#include "mars.h"
|
2016-01-19 09:21:10 +00:00
|
|
|
#include "mars_if.h"
|
2013-09-26 09:09:35 +00:00
|
|
|
|
2014-06-04 07:10:50 +00:00
|
|
|
// remove_this
|
|
|
|
|
2019-02-20 10:34:53 +00:00
|
|
|
/* TBD: improve this */
|
|
|
|
#ifdef NEED_BIO_SPLIT
|
2019-01-10 12:36:45 +00:00
|
|
|
#undef USE_MAX_PHYS_SEGMENTS
|
|
|
|
#define USE_MAX_PHYS_SEGMENTS 1
|
2019-01-08 15:48:50 +00:00
|
|
|
#endif
|
|
|
|
|
2014-06-04 07:10:50 +00:00
|
|
|
// end_remove_this
|
2013-09-26 09:09:35 +00:00
|
|
|
///////////////////////// global tuning ////////////////////////
|
|
|
|
|
2017-04-07 06:24:20 +00:00
|
|
|
int if_nr_requests = 1024;
|
|
|
|
|
2013-09-26 09:09:35 +00:00
|
|
|
int if_throttle_start_size = 0; // in kb
|
|
|
|
EXPORT_SYMBOL_GPL(if_throttle_start_size);
|
|
|
|
|
|
|
|
struct mars_limiter if_throttle = {
|
2016-01-19 08:15:44 +00:00
|
|
|
.lim_max_amount_rate = 10000,
|
2013-09-26 09:09:35 +00:00
|
|
|
};
|
2010-06-14 14:27:40 +00:00
|
|
|
|
|
|
|
///////////////////////// own type definitions ////////////////////////
|
|
|
|
|
2013-04-12 11:43:43 +00:00
|
|
|
#define IF_HASH_MAX (PAGE_SIZE / sizeof(struct if_hash_anchor))
|
|
|
|
#define IF_HASH_CHUNK (PAGE_SIZE * 32)
|
|
|
|
|
|
|
|
struct if_hash_anchor {
|
|
|
|
spinlock_t hash_lock;
|
|
|
|
struct list_head hash_anchor;
|
|
|
|
};
|
|
|
|
|
2010-06-14 14:27:40 +00:00
|
|
|
///////////////////////// own static definitions ////////////////////////
|
|
|
|
|
2011-03-31 16:16:00 +00:00
|
|
|
// TODO: check bounds, ensure that free minor numbers are recycled
|
2010-06-14 14:27:40 +00:00
|
|
|
static int device_minor = 0;
|
|
|
|
|
2010-06-22 13:21:42 +00:00
|
|
|
//////////////// object / aspect constructors / destructors ///////////////
|
|
|
|
|
2010-06-14 14:27:40 +00:00
|
|
|
///////////////////////// linux operations ////////////////////////
|
|
|
|
|
2019-02-21 10:02:14 +00:00
|
|
|
#ifdef MARS_HAS_GENERIC_BLK_ACCOUNTING
|
|
|
|
|
|
|
|
/* Disbaled by default, for saving overhead */
|
|
|
|
int mars_io_acct = 0;
|
|
|
|
|
|
|
|
static
|
|
|
|
void _if_start_io_acct(struct if_input *input, struct bio_wrapper *biow)
|
|
|
|
{
|
|
|
|
struct bio *bio;
|
|
|
|
|
|
|
|
if (!mars_io_acct)
|
|
|
|
return;
|
|
|
|
|
|
|
|
bio = biow->bio;
|
|
|
|
biow->start_time = jiffies;
|
|
|
|
generic_start_io_acct(
|
|
|
|
#ifdef MARS_HAS_NEW_GENERIC_BLK_ACCOUNTING
|
|
|
|
input->q,
|
|
|
|
#endif
|
|
|
|
bio_data_dir(bio),
|
|
|
|
bio->bi_iter.bi_size >> 9,
|
|
|
|
&input->disk->part0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
void _if_end_io_acct(struct if_input *input, struct bio_wrapper *biow)
|
|
|
|
{
|
|
|
|
struct bio *bio;
|
|
|
|
|
|
|
|
if (!biow->start_time)
|
|
|
|
return;
|
|
|
|
|
|
|
|
bio = biow->bio;
|
|
|
|
generic_end_io_acct(
|
|
|
|
#ifdef MARS_HAS_NEW_GENERIC_BLK_ACCOUNTING
|
|
|
|
input->q,
|
|
|
|
#endif
|
|
|
|
bio_data_dir(bio),
|
|
|
|
&input->disk->part0,
|
|
|
|
biow->start_time);
|
|
|
|
}
|
|
|
|
|
|
|
|
#elif defined(MARS_HAS_OLD_BLK_ACCOUNTING)
|
|
|
|
|
2013-10-28 11:19:01 +00:00
|
|
|
static
|
|
|
|
void _if_start_io_acct(struct if_input *input, struct bio_wrapper *biow)
|
|
|
|
{
|
|
|
|
struct bio *bio = biow->bio;
|
|
|
|
const int rw = bio_data_dir(bio);
|
|
|
|
const int cpu = part_stat_lock();
|
2019-02-21 10:02:14 +00:00
|
|
|
|
2013-10-28 11:19:01 +00:00
|
|
|
(void)cpu;
|
|
|
|
part_round_stats(cpu, &input->disk->part0);
|
|
|
|
part_stat_inc(cpu, &input->disk->part0, ios[rw]);
|
2014-06-04 07:10:50 +00:00
|
|
|
// remove_this
|
2019-08-06 06:53:28 +00:00
|
|
|
#ifdef MARS_HAS_BVEC_ITER
|
2014-06-04 07:10:50 +00:00
|
|
|
// end_remove_this
|
|
|
|
part_stat_add(cpu, &input->disk->part0, sectors[rw], bio->bi_iter.bi_size >> 9);
|
|
|
|
// remove_this
|
|
|
|
#else
|
2013-10-28 11:19:01 +00:00
|
|
|
part_stat_add(cpu, &input->disk->part0, sectors[rw], bio->bi_size >> 9);
|
2014-06-04 07:10:50 +00:00
|
|
|
#endif
|
|
|
|
// end_remove_this
|
2013-10-28 11:19:01 +00:00
|
|
|
part_inc_in_flight(&input->disk->part0, rw);
|
|
|
|
part_stat_unlock();
|
|
|
|
biow->start_time = jiffies;
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
void _if_end_io_acct(struct if_input *input, struct bio_wrapper *biow)
|
|
|
|
{
|
|
|
|
unsigned long duration = jiffies - biow->start_time;
|
|
|
|
struct bio *bio = biow->bio;
|
|
|
|
const int rw = bio_data_dir(bio);
|
|
|
|
const int cpu = part_stat_lock();
|
|
|
|
(void)cpu;
|
|
|
|
part_stat_add(cpu, &input->disk->part0, ticks[rw], duration);
|
|
|
|
part_round_stats(cpu, &input->disk->part0);
|
|
|
|
part_dec_in_flight(&input->disk->part0, rw);
|
|
|
|
part_stat_unlock();
|
|
|
|
}
|
|
|
|
|
2019-02-21 10:02:14 +00:00
|
|
|
#else // MARS_HAS_OLD_BLK_ACCOUNTING
|
|
|
|
|
2013-10-28 11:19:01 +00:00
|
|
|
#define _if_start_io_acct(...) do {} while (0)
|
|
|
|
#define _if_end_io_acct(...) do {} while (0)
|
2019-02-21 10:02:14 +00:00
|
|
|
|
2013-10-28 11:19:01 +00:00
|
|
|
#endif
|
|
|
|
|
2019-08-19 08:56:47 +00:00
|
|
|
/* Abstract from interface changes
|
|
|
|
*/
|
|
|
|
static
|
2020-07-30 09:00:01 +00:00
|
|
|
void _call_bio_endio(struct if_brick *brick, struct bio *bio, int error)
|
2019-08-19 08:56:47 +00:00
|
|
|
{
|
|
|
|
#ifdef MARS_HAS_BI_STATUS
|
|
|
|
bio->bi_status = errno_to_blk_status(error);
|
|
|
|
bio_endio(bio);
|
|
|
|
#else
|
|
|
|
#ifdef MARS_HAS_BI_ERROR
|
|
|
|
bio->bi_error = error;
|
|
|
|
bio_endio(bio);
|
|
|
|
#else
|
|
|
|
bio_endio(bio, error);
|
|
|
|
#endif
|
|
|
|
#endif
|
2020-07-30 09:00:01 +00:00
|
|
|
/* Just a hint for userspace, no strictness needed */
|
2021-01-29 13:03:17 +00:00
|
|
|
get_real_lamport(&brick->completion_stamp);
|
2019-08-19 08:56:47 +00:00
|
|
|
}
|
|
|
|
|
2010-06-14 14:27:40 +00:00
|
|
|
/* callback
|
|
|
|
*/
|
2011-03-11 13:57:54 +00:00
|
|
|
static
|
|
|
|
void if_endio(struct generic_callback *cb)
|
2010-06-14 14:27:40 +00:00
|
|
|
{
|
2011-03-07 10:27:38 +00:00
|
|
|
struct if_mref_aspect *mref_a = cb->cb_private;
|
2011-03-11 13:57:54 +00:00
|
|
|
struct if_input *input;
|
2020-05-08 16:41:22 +00:00
|
|
|
struct if_brick *brick;
|
2011-03-31 16:16:00 +00:00
|
|
|
int k;
|
2010-08-04 17:32:04 +00:00
|
|
|
int error;
|
2010-11-26 13:45:10 +00:00
|
|
|
|
2014-03-23 09:57:56 +00:00
|
|
|
LAST_CALLBACK(cb);
|
2012-01-13 11:01:23 +00:00
|
|
|
if (unlikely(!mref_a || !mref_a->object)) {
|
|
|
|
MARS_FAT("mref_a = %p mref = %p, something is very wrong here!\n", mref_a, mref_a->object);
|
2010-11-26 13:45:10 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-10-28 11:19:01 +00:00
|
|
|
input = mref_a->input;
|
|
|
|
CHECK_PTR(input, err);
|
2010-11-26 13:45:10 +00:00
|
|
|
|
2011-03-27 15:18:38 +00:00
|
|
|
mars_trace(mref_a->object, "if_endio");
|
|
|
|
mars_log_trace(mref_a->object);
|
|
|
|
|
2019-03-14 20:11:51 +00:00
|
|
|
MARS_IO("flags = %ux bio_count = %d\n", mref->ref_flags, mref_a->bio_count);
|
2011-10-12 14:57:53 +00:00
|
|
|
|
2010-12-10 17:40:20 +00:00
|
|
|
for (k = 0; k < mref_a->bio_count; k++) {
|
2011-11-30 14:23:44 +00:00
|
|
|
struct bio_wrapper *biow;
|
|
|
|
struct bio *bio;
|
|
|
|
|
|
|
|
biow = mref_a->orig_biow[k];
|
|
|
|
mref_a->orig_biow[k] = NULL;
|
|
|
|
CHECK_PTR(biow, err);
|
|
|
|
|
|
|
|
CHECK_ATOMIC(&biow->bi_comp_cnt, 1);
|
|
|
|
if (!atomic_dec_and_test(&biow->bi_comp_cnt)) {
|
2010-12-10 17:40:20 +00:00
|
|
|
continue;
|
|
|
|
}
|
2010-11-26 13:45:10 +00:00
|
|
|
|
2011-11-30 14:23:44 +00:00
|
|
|
bio = biow->bio;
|
|
|
|
CHECK_PTR_NULL(bio, err);
|
|
|
|
|
2013-10-28 11:19:01 +00:00
|
|
|
_if_end_io_acct(input, biow);
|
|
|
|
|
2011-10-04 11:34:18 +00:00
|
|
|
error = CALLBACK_ERROR(mref_a->object);
|
2010-12-10 17:40:20 +00:00
|
|
|
if (unlikely(error < 0)) {
|
2016-02-01 08:05:30 +00:00
|
|
|
if (likely(input->brick))
|
|
|
|
input->brick->error_code = error;
|
2010-12-10 17:40:20 +00:00
|
|
|
} else { // bio conventions are slightly different...
|
|
|
|
error = 0;
|
2014-06-04 07:10:50 +00:00
|
|
|
// remove_this
|
2019-08-06 06:53:28 +00:00
|
|
|
#ifdef MARS_HAS_BVEC_ITER
|
2014-06-04 07:10:50 +00:00
|
|
|
// end_remove_this
|
|
|
|
bio->bi_iter.bi_size = 0;
|
|
|
|
// remove_this
|
|
|
|
#else
|
2010-12-10 17:40:20 +00:00
|
|
|
bio->bi_size = 0;
|
2014-06-04 07:10:50 +00:00
|
|
|
#endif
|
|
|
|
// end_remove_this
|
2010-12-10 17:40:20 +00:00
|
|
|
}
|
2019-03-14 20:11:51 +00:00
|
|
|
MARS_IO("calling end_io() flags = %ux error = %d\n",
|
|
|
|
mref->ref_flags, error);
|
2020-07-30 09:00:01 +00:00
|
|
|
_call_bio_endio(input->brick, bio, error);
|
2011-11-30 14:23:44 +00:00
|
|
|
brick_mem_free(biow);
|
2010-11-26 13:45:10 +00:00
|
|
|
}
|
2020-05-08 16:41:22 +00:00
|
|
|
brick = input->brick;
|
2019-03-14 20:11:51 +00:00
|
|
|
if (mref_a->object->ref_flags & MREF_WRITE) {
|
2020-05-08 16:41:22 +00:00
|
|
|
atomic_dec(&brick->write_flying_count);
|
2013-10-28 11:19:01 +00:00
|
|
|
} else {
|
2020-05-08 16:41:22 +00:00
|
|
|
atomic_dec(&brick->read_flying_count);
|
2013-10-28 11:19:01 +00:00
|
|
|
}
|
2011-10-12 14:57:53 +00:00
|
|
|
#ifdef IO_DEBUGGING
|
|
|
|
{
|
|
|
|
char *txt = brick->ops->brick_statistics(brick, false);
|
|
|
|
MARS_IO("%s", txt);
|
|
|
|
brick_string_free(txt);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
MARS_IO("finished.\n");
|
2011-11-30 14:23:44 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
err:
|
|
|
|
MARS_FAT("error in callback, giving up\n");
|
2010-12-10 17:40:20 +00:00
|
|
|
}
|
2010-11-26 13:45:10 +00:00
|
|
|
|
2010-12-10 17:40:20 +00:00
|
|
|
/* Kick off plugged mrefs
|
|
|
|
*/
|
2011-07-15 10:12:06 +00:00
|
|
|
static
|
|
|
|
void _if_unplug(struct if_input *input)
|
2010-12-10 17:40:20 +00:00
|
|
|
{
|
2020-05-08 16:41:22 +00:00
|
|
|
struct if_brick *brick = input->brick;
|
2010-12-10 17:40:20 +00:00
|
|
|
LIST_HEAD(tmp_list);
|
|
|
|
unsigned long flags;
|
|
|
|
|
2012-02-08 11:44:42 +00:00
|
|
|
#ifdef CONFIG_MARS_DEBUG
|
2010-12-10 17:40:20 +00:00
|
|
|
might_sleep();
|
2011-10-12 14:57:53 +00:00
|
|
|
#endif
|
2010-12-10 17:40:20 +00:00
|
|
|
|
2011-12-08 15:38:04 +00:00
|
|
|
MARS_IO("plugged_count = %d\n", atomic_read(&input->plugged_count));
|
|
|
|
|
2010-12-10 17:40:20 +00:00
|
|
|
down(&input->kick_sem);
|
2021-01-29 19:59:08 +00:00
|
|
|
#ifdef MARS_HAS_OLD_QUEUE_LOCK
|
2010-12-10 17:40:20 +00:00
|
|
|
traced_lock(&input->req_lock, flags);
|
2021-01-29 19:59:08 +00:00
|
|
|
#else
|
|
|
|
traced_lock(&input->q->queue_lock, flags);
|
|
|
|
#endif
|
2011-07-15 10:12:06 +00:00
|
|
|
#ifdef USE_TIMER
|
|
|
|
del_timer(&input->timer);
|
|
|
|
#endif
|
2010-12-10 17:40:20 +00:00
|
|
|
if (!list_empty(&input->plug_anchor)) {
|
|
|
|
// move over the whole list
|
|
|
|
list_replace_init(&input->plug_anchor, &tmp_list);
|
2011-03-30 12:02:50 +00:00
|
|
|
atomic_set(&input->plugged_count, 0);
|
2010-08-04 17:32:04 +00:00
|
|
|
}
|
2021-01-29 19:59:08 +00:00
|
|
|
#ifdef MARS_HAS_OLD_QUEUE_LOCK
|
|
|
|
traced_unlock(&input->req_lock, flags);
|
|
|
|
#else
|
|
|
|
traced_unlock(&input->q->queue_lock, flags);
|
|
|
|
#endif
|
2010-12-10 17:40:20 +00:00
|
|
|
up(&input->kick_sem);
|
2010-11-26 13:45:10 +00:00
|
|
|
|
2010-12-10 17:40:20 +00:00
|
|
|
while (!list_empty(&tmp_list)) {
|
2011-03-07 10:27:38 +00:00
|
|
|
struct if_mref_aspect *mref_a;
|
2010-12-15 12:13:18 +00:00
|
|
|
struct mref_object *mref;
|
2021-03-01 10:56:09 +00:00
|
|
|
unsigned int hash_index;
|
2011-03-30 12:02:50 +00:00
|
|
|
unsigned long flags;
|
|
|
|
|
2011-03-07 10:27:38 +00:00
|
|
|
mref_a = container_of(tmp_list.next, struct if_mref_aspect, plug_head);
|
2010-12-10 17:40:20 +00:00
|
|
|
list_del_init(&mref_a->plug_head);
|
2011-04-21 16:03:04 +00:00
|
|
|
|
2011-03-30 12:02:50 +00:00
|
|
|
hash_index = mref_a->hash_index;
|
2013-04-12 11:43:43 +00:00
|
|
|
traced_lock(&input->hash_table[hash_index].hash_lock, flags);
|
2011-03-30 12:02:50 +00:00
|
|
|
list_del_init(&mref_a->hash_head);
|
2013-04-12 11:43:43 +00:00
|
|
|
traced_unlock(&input->hash_table[hash_index].hash_lock, flags);
|
2011-03-30 12:02:50 +00:00
|
|
|
|
2010-12-10 17:40:20 +00:00
|
|
|
mref = mref_a->object;
|
2010-11-26 13:45:10 +00:00
|
|
|
|
2011-04-21 16:03:04 +00:00
|
|
|
if (unlikely(mref_a->current_len > mref_a->max_len)) {
|
|
|
|
MARS_ERR("request len %d > %d\n", mref_a->current_len, mref_a->max_len);
|
|
|
|
}
|
|
|
|
mref->ref_len = mref_a->current_len;
|
|
|
|
|
2011-03-27 15:18:38 +00:00
|
|
|
mars_trace(mref, "if_unplug");
|
2011-03-24 16:05:46 +00:00
|
|
|
|
2020-07-30 18:48:38 +00:00
|
|
|
#ifdef CONFIG_MARS_DEBUG
|
2013-01-03 08:49:52 +00:00
|
|
|
atomic_inc(&input->total_fire_count);
|
2020-07-30 18:48:38 +00:00
|
|
|
#endif
|
2020-05-08 16:41:22 +00:00
|
|
|
brick = input->brick;
|
2019-03-14 20:11:51 +00:00
|
|
|
if (mref->ref_flags & MREF_WRITE) {
|
2020-05-08 16:41:22 +00:00
|
|
|
atomic_inc(&brick->write_flying_count);
|
2011-05-19 11:36:00 +00:00
|
|
|
} else {
|
2020-05-08 16:41:22 +00:00
|
|
|
atomic_inc(&brick->read_flying_count);
|
2011-05-19 11:36:00 +00:00
|
|
|
}
|
2020-07-30 18:48:38 +00:00
|
|
|
#ifdef CONFIG_MARS_DEBUG
|
2019-03-25 08:00:45 +00:00
|
|
|
if (mref->ref_flags & MREF_SKIP_SYNC)
|
2013-01-03 08:49:52 +00:00
|
|
|
atomic_inc(&input->total_skip_sync_count);
|
2020-07-30 18:48:38 +00:00
|
|
|
#endif
|
2011-05-19 11:36:00 +00:00
|
|
|
|
2021-06-29 08:52:11 +00:00
|
|
|
GENERIC_INPUT_CALL_VOID(input, mref_io, mref);
|
|
|
|
GENERIC_INPUT_CALL_VOID(input, mref_put, mref);
|
2010-12-10 17:40:20 +00:00
|
|
|
}
|
2011-10-12 14:57:53 +00:00
|
|
|
#ifdef IO_DEBUGGING
|
|
|
|
{
|
|
|
|
struct if_brick *brick = input->brick;
|
|
|
|
char *txt = brick->ops->brick_statistics(brick, false);
|
|
|
|
MARS_IO("%s", txt);
|
|
|
|
brick_string_free(txt);
|
|
|
|
}
|
|
|
|
#endif
|
2010-06-14 14:27:40 +00:00
|
|
|
}
|
|
|
|
|
2012-09-18 06:13:33 +00:00
|
|
|
#ifndef BLK_MAX_REQUEST_COUNT
|
2011-07-15 10:12:06 +00:00
|
|
|
#ifdef USE_TIMER
|
|
|
|
static
|
|
|
|
void if_timer(unsigned long data)
|
|
|
|
{
|
2011-12-08 15:38:04 +00:00
|
|
|
MARS_IO("\n");
|
2011-07-15 10:12:06 +00:00
|
|
|
_if_unplug((void*)data);
|
|
|
|
}
|
|
|
|
#endif
|
2012-09-18 06:13:33 +00:00
|
|
|
#endif // BLK_MAX_REQUEST_COUNT
|
2011-07-15 10:12:06 +00:00
|
|
|
|
2010-11-26 13:45:10 +00:00
|
|
|
/* accept a linux bio, convert to mref and call buf_io() on it.
|
2010-06-14 14:27:40 +00:00
|
|
|
*/
|
2012-09-18 06:13:33 +00:00
|
|
|
static
|
2015-11-18 14:16:07 +00:00
|
|
|
/* see dece16353ef47d8d33f5302bc158072a9d65e26f */
|
|
|
|
#ifdef BLK_QC_T_NONE
|
2019-01-08 15:48:50 +00:00
|
|
|
#ifdef NEED_BIO_SPLIT
|
2015-11-18 14:16:07 +00:00
|
|
|
// end_remove_this
|
2019-01-08 15:48:50 +00:00
|
|
|
blk_qc_t _if_make_request(struct request_queue *q, struct bio *bio)
|
2015-11-18 14:16:07 +00:00
|
|
|
// remove_this
|
2019-01-08 15:48:50 +00:00
|
|
|
#else
|
|
|
|
blk_qc_t if_make_request(struct request_queue *q, struct bio *bio)
|
|
|
|
#endif
|
2015-11-18 14:16:07 +00:00
|
|
|
#elif defined(BIO_CPU_AFFINE)
|
|
|
|
int if_make_request(struct request_queue *q, struct bio *bio)
|
2012-09-18 06:13:33 +00:00
|
|
|
#else
|
2019-01-08 15:48:50 +00:00
|
|
|
#ifdef NEED_BIO_SPLIT
|
|
|
|
void _if_make_request(struct request_queue *q, struct bio *bio)
|
|
|
|
#else
|
2015-11-18 14:16:07 +00:00
|
|
|
void if_make_request(struct request_queue *q, struct bio *bio)
|
2012-09-18 06:13:33 +00:00
|
|
|
#endif
|
2019-01-08 15:48:50 +00:00
|
|
|
#endif
|
2010-06-14 14:27:40 +00:00
|
|
|
{
|
2012-02-26 15:23:57 +00:00
|
|
|
struct if_input *input = q->queuedata;
|
|
|
|
struct if_brick *brick = input->brick;
|
|
|
|
|
|
|
|
/* Original flags of the source bio
|
|
|
|
*/
|
|
|
|
const int rw = bio_data_dir(bio);
|
|
|
|
const int sectors = bio_sectors(bio);
|
2016-08-24 12:50:57 +00:00
|
|
|
// remove_this
|
|
|
|
/* Adapt to different kernel versions.
|
|
|
|
* This is a maintainance nightmare.
|
|
|
|
* Most is provisionary.
|
|
|
|
*/
|
2012-11-28 11:42:05 +00:00
|
|
|
#if defined(BIO_RW_RQ_MASK) || defined(BIO_FLUSH)
|
2012-02-26 15:23:57 +00:00
|
|
|
const bool ahead = bio_rw_flagged(bio, BIO_RW_AHEAD) && rw == READ;
|
|
|
|
const bool barrier = bio_rw_flagged(bio, BIO_RW_BARRIER);
|
|
|
|
const bool syncio = bio_rw_flagged(bio, BIO_RW_SYNCIO);
|
|
|
|
const bool unplug = bio_rw_flagged(bio, BIO_RW_UNPLUG);
|
|
|
|
const bool meta = bio_rw_flagged(bio, BIO_RW_META);
|
|
|
|
const bool discard = bio_rw_flagged(bio, BIO_RW_DISCARD);
|
|
|
|
const bool noidle = bio_rw_flagged(bio, BIO_RW_NOIDLE);
|
2013-04-19 07:07:32 +00:00
|
|
|
#elif defined(REQ_FLUSH) && defined(REQ_SYNC)
|
|
|
|
#define _flagged(x) (bio->bi_rw & (x))
|
|
|
|
const bool ahead = _flagged(REQ_RAHEAD) && rw == READ;
|
|
|
|
const bool barrier = _flagged(REQ_FLUSH);
|
|
|
|
const bool syncio = _flagged(REQ_SYNC);
|
2012-09-18 06:13:33 +00:00
|
|
|
const bool unplug = false;
|
2013-04-19 07:07:32 +00:00
|
|
|
const bool meta = _flagged(REQ_META);
|
|
|
|
const bool discard = _flagged(REQ_DISCARD);
|
|
|
|
const bool noidle = _flagged(REQ_THROTTLED);
|
2019-08-06 06:53:28 +00:00
|
|
|
#elif defined(MARS_HAS_NEW_BIO_OP)
|
2016-08-24 12:50:57 +00:00
|
|
|
// end_remove_this
|
|
|
|
#define _flagged(x) (bio->bi_opf & (x))
|
|
|
|
const bool ahead = _flagged(REQ_RAHEAD) && rw == READ;
|
|
|
|
const bool barrier = false;
|
|
|
|
const bool syncio = _flagged(REQ_SYNC);
|
|
|
|
const bool unplug = false;
|
|
|
|
const bool meta = _flagged(REQ_META);
|
|
|
|
const bool discard = bio_op(bio) == REQ_OP_DISCARD;
|
2019-02-21 11:27:20 +00:00
|
|
|
#ifdef MARS_HAS_BIO_THROTTLED
|
2019-02-21 11:30:02 +00:00
|
|
|
const bool noidle = !bio_flagged(bio, BIO_THROTTLED);
|
2019-02-21 11:27:20 +00:00
|
|
|
#else
|
2016-08-24 12:50:57 +00:00
|
|
|
const bool noidle = _flagged(REQ_THROTTLED);
|
2019-02-21 11:27:20 +00:00
|
|
|
#endif
|
2016-08-24 12:50:57 +00:00
|
|
|
// remove_this
|
2013-04-19 07:07:32 +00:00
|
|
|
#else
|
|
|
|
#error Cannot decode the bio flags
|
2012-09-18 06:13:33 +00:00
|
|
|
#endif
|
2016-08-24 12:50:57 +00:00
|
|
|
// end_remove_this
|
2012-02-26 15:23:57 +00:00
|
|
|
const int prio = bio_prio(bio);
|
|
|
|
|
|
|
|
/* Transform into MARS flags
|
|
|
|
*/
|
|
|
|
const int ref_prio =
|
|
|
|
(prio == IOPRIO_CLASS_RT || (meta | syncio)) ?
|
|
|
|
MARS_PRIO_HIGH :
|
|
|
|
(prio == IOPRIO_CLASS_IDLE) ?
|
|
|
|
MARS_PRIO_LOW :
|
|
|
|
MARS_PRIO_NORMAL;
|
|
|
|
const bool do_unplug = ALWAYS_UNPLUG | unplug | noidle;
|
|
|
|
const bool do_skip_sync = brick->skip_sync && !(barrier | syncio);
|
|
|
|
|
2011-11-30 14:23:44 +00:00
|
|
|
struct bio_wrapper *biow;
|
2010-12-15 12:13:18 +00:00
|
|
|
struct mref_object *mref = NULL;
|
2011-03-07 10:27:38 +00:00
|
|
|
struct if_mref_aspect *mref_a;
|
2014-06-04 07:10:50 +00:00
|
|
|
// remove_this
|
2019-08-06 06:53:28 +00:00
|
|
|
#ifdef MARS_HAS_BVEC_ITER
|
2014-06-04 07:10:50 +00:00
|
|
|
// end_remove_this
|
|
|
|
struct bio_vec bvec;
|
|
|
|
struct bvec_iter i;
|
|
|
|
loff_t pos = ((loff_t)bio->bi_iter.bi_sector) << 9; // TODO: make dynamic
|
|
|
|
int total_len = bio->bi_iter.bi_size;
|
|
|
|
// remove_this
|
|
|
|
#else
|
2010-11-26 13:45:10 +00:00
|
|
|
struct bio_vec *bvec;
|
|
|
|
int i;
|
|
|
|
loff_t pos = ((loff_t)bio->bi_sector) << 9; // TODO: make dynamic
|
2011-04-08 09:52:46 +00:00
|
|
|
int total_len = bio->bi_size;
|
2014-06-04 07:10:50 +00:00
|
|
|
#endif
|
|
|
|
// end_remove_this
|
2020-08-17 15:04:43 +00:00
|
|
|
int kb = (total_len + 512) / 1024;
|
2014-06-04 07:10:50 +00:00
|
|
|
bool assigned = false;
|
2015-09-30 10:42:16 +00:00
|
|
|
int error = -EINVAL;
|
2010-06-14 14:27:40 +00:00
|
|
|
|
2012-11-15 12:53:26 +00:00
|
|
|
bind_to_channel(brick->say_channel, current);
|
|
|
|
|
2012-02-26 15:23:57 +00:00
|
|
|
MARS_IO("bio %p "
|
|
|
|
"size = %d "
|
|
|
|
"rw = %d "
|
|
|
|
"sectors = %d "
|
|
|
|
"ahead = %d "
|
|
|
|
"barrier = %d "
|
|
|
|
"syncio = %d "
|
|
|
|
"unplug = %d "
|
|
|
|
"meta = %d "
|
|
|
|
"discard = %d "
|
|
|
|
"noidle = %d "
|
|
|
|
"prio = %d "
|
|
|
|
"pos = %lldd "
|
|
|
|
"total_len = %d\n",
|
|
|
|
bio,
|
|
|
|
bio->bi_size,
|
|
|
|
rw,
|
|
|
|
sectors,
|
|
|
|
ahead,
|
|
|
|
barrier,
|
|
|
|
syncio,
|
|
|
|
unplug,
|
|
|
|
meta,
|
|
|
|
discard,
|
|
|
|
noidle,
|
|
|
|
prio,
|
|
|
|
pos,
|
|
|
|
total_len);
|
2010-06-16 13:21:30 +00:00
|
|
|
|
2010-12-10 17:40:20 +00:00
|
|
|
might_sleep();
|
|
|
|
|
2012-02-26 15:23:57 +00:00
|
|
|
if (unlikely(!sectors)) {
|
2011-07-15 10:12:06 +00:00
|
|
|
_if_unplug(input);
|
|
|
|
/* THINK: usually this happens only at write barriers.
|
|
|
|
* We have no "barrier" operation in MARS, since
|
|
|
|
* callback semantics should always denote
|
|
|
|
* "writethrough accomplished".
|
|
|
|
* In case of exceptional semantics, we need to do
|
|
|
|
* something here. For now, we do just nothing.
|
|
|
|
*/
|
2012-09-18 06:13:33 +00:00
|
|
|
error = 0;
|
2020-07-30 09:00:01 +00:00
|
|
|
_call_bio_endio(brick, bio, 0);
|
2012-09-18 06:13:33 +00:00
|
|
|
goto done;
|
2011-07-15 10:12:06 +00:00
|
|
|
}
|
2010-06-14 14:27:40 +00:00
|
|
|
|
2013-09-26 09:09:35 +00:00
|
|
|
// throttling of too big write requests
|
2013-11-20 10:53:06 +00:00
|
|
|
if (rw && if_throttle_start_size > 0) {
|
|
|
|
if (kb >= if_throttle_start_size)
|
|
|
|
mars_limit_sleep(&if_throttle, kb);
|
2013-09-26 09:09:35 +00:00
|
|
|
}
|
|
|
|
|
2020-08-17 15:04:43 +00:00
|
|
|
/* gather statistics on IOPS etc */
|
|
|
|
mars_limit(&brick->io_limiter, kb);
|
|
|
|
|
2011-10-12 14:57:53 +00:00
|
|
|
#ifdef DENY_READA // provisinary -- we should introduce an equivalent of READA also to the MARS infrastructure
|
2012-02-26 15:23:57 +00:00
|
|
|
if (ahead) {
|
2020-07-30 18:48:38 +00:00
|
|
|
#ifdef CONFIG_MARS_DEBUG
|
2011-08-05 09:26:24 +00:00
|
|
|
atomic_inc(&input->total_reada_count);
|
2020-07-30 18:48:38 +00:00
|
|
|
#endif
|
2020-07-30 09:00:01 +00:00
|
|
|
_call_bio_endio(brick, bio, -EWOULDBLOCK);
|
2012-09-18 06:13:33 +00:00
|
|
|
error = 0;
|
|
|
|
goto done;
|
2011-08-05 09:26:24 +00:00
|
|
|
}
|
2012-02-26 15:23:57 +00:00
|
|
|
#else
|
|
|
|
(void)ahead; // shut up gcc
|
2011-08-05 09:26:24 +00:00
|
|
|
#endif
|
2012-02-26 15:23:57 +00:00
|
|
|
if (unlikely(discard)) { // NYI
|
2012-09-18 06:13:33 +00:00
|
|
|
error = 0;
|
2020-07-30 09:00:01 +00:00
|
|
|
_call_bio_endio(brick, bio, 0);
|
2012-09-18 06:13:33 +00:00
|
|
|
goto done;
|
2012-02-26 15:23:57 +00:00
|
|
|
}
|
2011-11-30 14:23:44 +00:00
|
|
|
|
|
|
|
biow = brick_mem_alloc(sizeof(struct bio_wrapper));
|
|
|
|
CHECK_PTR(biow, err);
|
|
|
|
biow->bio = bio;
|
|
|
|
atomic_set(&biow->bi_comp_cnt, 0);
|
|
|
|
|
2020-07-30 18:48:38 +00:00
|
|
|
#ifdef CONFIG_MARS_DEBUG
|
2011-03-31 16:16:00 +00:00
|
|
|
if (rw) {
|
2011-05-19 11:36:00 +00:00
|
|
|
atomic_inc(&input->total_write_count);
|
2011-03-31 16:16:00 +00:00
|
|
|
} else {
|
2011-05-19 11:36:00 +00:00
|
|
|
atomic_inc(&input->total_read_count);
|
2011-03-31 16:16:00 +00:00
|
|
|
}
|
2020-07-30 18:48:38 +00:00
|
|
|
#endif
|
2011-03-31 16:16:00 +00:00
|
|
|
|
2013-10-28 11:19:01 +00:00
|
|
|
_if_start_io_acct(input, biow);
|
|
|
|
|
2011-02-23 20:48:06 +00:00
|
|
|
/* FIXME: THIS IS PROVISIONARY (use event instead)
|
2010-08-10 17:39:30 +00:00
|
|
|
*/
|
2011-02-23 20:48:06 +00:00
|
|
|
while (unlikely(!brick->power.led_on)) {
|
2012-09-17 10:11:25 +00:00
|
|
|
brick_msleep(100);
|
2010-08-10 17:39:30 +00:00
|
|
|
}
|
|
|
|
|
2010-12-10 17:40:20 +00:00
|
|
|
down(&input->kick_sem);
|
|
|
|
|
2010-11-26 13:45:10 +00:00
|
|
|
bio_for_each_segment(bvec, bio, i) {
|
2014-06-04 07:10:50 +00:00
|
|
|
// remove_this
|
2019-08-06 06:53:28 +00:00
|
|
|
#ifdef MARS_HAS_BVEC_ITER
|
2014-06-04 07:10:50 +00:00
|
|
|
// end_remove_this
|
|
|
|
struct page *page = bvec.bv_page;
|
|
|
|
int bv_len = bvec.bv_len;
|
|
|
|
int offset = bvec.bv_offset;
|
|
|
|
// remove_this
|
|
|
|
#else
|
2011-03-18 13:15:40 +00:00
|
|
|
struct page *page = bvec->bv_page;
|
2011-03-31 04:41:42 +00:00
|
|
|
int bv_len = bvec->bv_len;
|
2011-03-18 13:15:40 +00:00
|
|
|
int offset = bvec->bv_offset;
|
2014-06-04 07:10:50 +00:00
|
|
|
#endif
|
|
|
|
// end_remove_this
|
2011-03-31 04:41:42 +00:00
|
|
|
void *data;
|
|
|
|
|
2013-10-14 20:26:24 +00:00
|
|
|
#ifdef ARCH_HAS_KMAP
|
|
|
|
#error FIXME: the current infrastructure cannot deal with HIGHMEM / kmap()
|
|
|
|
#endif
|
|
|
|
data = page_address(page);
|
2011-03-18 13:15:40 +00:00
|
|
|
MARS_IO("page = %p data = %p\n", page, data);
|
2011-04-08 09:52:46 +00:00
|
|
|
error = -EINVAL;
|
|
|
|
if (unlikely(!data))
|
|
|
|
break;
|
|
|
|
|
2011-03-18 13:15:40 +00:00
|
|
|
data += offset;
|
2010-11-26 13:45:10 +00:00
|
|
|
|
|
|
|
while (bv_len > 0) {
|
2010-12-10 17:40:20 +00:00
|
|
|
struct list_head *tmp;
|
2021-03-01 10:56:09 +00:00
|
|
|
unsigned int hash_index;
|
2011-03-31 04:41:42 +00:00
|
|
|
int this_len = 0;
|
2010-12-10 17:40:20 +00:00
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
mref = NULL;
|
|
|
|
mref_a = NULL;
|
2011-03-18 13:15:40 +00:00
|
|
|
|
|
|
|
MARS_IO("rw = %d i = %d pos = %lld bv_page = %p bv_offset = %d data = %p bv_len = %d\n", rw, i, pos, bvec->bv_page, bvec->bv_offset, data, bv_len);
|
2010-12-10 17:40:20 +00:00
|
|
|
|
2021-03-01 10:56:09 +00:00
|
|
|
hash_index = ((unsigned long)pos / IF_HASH_CHUNK) % IF_HASH_MAX;
|
2011-03-31 04:41:42 +00:00
|
|
|
|
|
|
|
#ifdef REQUEST_MERGING
|
2013-04-12 11:43:43 +00:00
|
|
|
traced_lock(&input->hash_table[hash_index].hash_lock, flags);
|
|
|
|
for (tmp = input->hash_table[hash_index].hash_anchor.next; tmp != &input->hash_table[hash_index].hash_anchor; tmp = tmp->next) {
|
2011-03-07 10:27:38 +00:00
|
|
|
struct if_mref_aspect *tmp_a;
|
2011-03-31 04:41:42 +00:00
|
|
|
struct mref_object *tmp_mref;
|
|
|
|
int i;
|
2011-03-18 13:15:40 +00:00
|
|
|
|
2011-03-31 04:41:42 +00:00
|
|
|
tmp_a = container_of(tmp, struct if_mref_aspect, hash_head);
|
|
|
|
tmp_mref = tmp_a->object;
|
2019-03-14 20:11:51 +00:00
|
|
|
if (tmp_a->orig_page != page ||
|
|
|
|
(tmp_mref->ref_flags & MREF_WRITE) != (rw ? MREF_WRITE : 0) ||
|
|
|
|
tmp_a->bio_count >= MAX_BIO ||
|
|
|
|
tmp_a->current_len + bv_len > tmp_a->max_len) {
|
2010-12-10 17:40:20 +00:00
|
|
|
continue;
|
2011-03-31 04:41:42 +00:00
|
|
|
}
|
2010-12-10 17:40:20 +00:00
|
|
|
|
2011-04-21 16:03:04 +00:00
|
|
|
if (tmp_mref->ref_data + tmp_a->current_len == data) {
|
2011-03-31 04:41:42 +00:00
|
|
|
goto merge_end;
|
2011-04-21 16:03:04 +00:00
|
|
|
#ifdef FRONT_MERGE // FIXME: this cannot work. ref_data must never be changed. pre-allocate from offset 0 instead.
|
2011-03-31 04:41:42 +00:00
|
|
|
} else if (data + bv_len == tmp_mref->ref_data) {
|
|
|
|
goto merge_front;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
|
2011-04-21 16:03:04 +00:00
|
|
|
#ifdef FRONT_MERGE // FIXME: this cannot work. ref_data must never be changed. pre-allocate from offset 0 instead.
|
2011-03-31 04:41:42 +00:00
|
|
|
merge_front:
|
|
|
|
tmp_mref->ref_data = data;
|
2011-04-21 16:03:04 +00:00
|
|
|
#endif
|
2011-03-31 04:41:42 +00:00
|
|
|
merge_end:
|
2011-04-21 16:03:04 +00:00
|
|
|
tmp_a->current_len += bv_len;
|
2011-03-31 04:41:42 +00:00
|
|
|
mref = tmp_mref;
|
|
|
|
mref_a = tmp_a;
|
|
|
|
this_len = bv_len;
|
2012-02-26 15:23:57 +00:00
|
|
|
if (!do_skip_sync) {
|
2019-03-25 08:00:45 +00:00
|
|
|
mref->ref_flags &= ~MREF_SKIP_SYNC;
|
2011-04-08 09:52:46 +00:00
|
|
|
}
|
2011-03-31 04:41:42 +00:00
|
|
|
|
|
|
|
for (i = 0; i < mref_a->bio_count; i++) {
|
2011-11-30 14:23:44 +00:00
|
|
|
if (mref_a->orig_biow[i]->bio == bio) {
|
2011-03-31 04:41:42 +00:00
|
|
|
goto unlock;
|
2011-03-24 16:05:46 +00:00
|
|
|
}
|
2011-03-31 04:41:42 +00:00
|
|
|
}
|
2010-12-10 17:40:20 +00:00
|
|
|
|
2011-11-30 14:23:44 +00:00
|
|
|
CHECK_ATOMIC(&biow->bi_comp_cnt, 0);
|
|
|
|
atomic_inc(&biow->bi_comp_cnt);
|
|
|
|
mref_a->orig_biow[mref_a->bio_count++] = biow;
|
2011-03-31 04:41:42 +00:00
|
|
|
assigned = true;
|
|
|
|
goto unlock;
|
|
|
|
} // foreach hash collision list member
|
|
|
|
|
|
|
|
unlock:
|
2013-04-12 11:43:43 +00:00
|
|
|
traced_unlock(&input->hash_table[hash_index].hash_lock, flags);
|
2010-11-26 13:45:10 +00:00
|
|
|
#endif
|
|
|
|
if (!mref) {
|
2011-04-08 09:52:46 +00:00
|
|
|
int prefetch_len;
|
2010-11-26 13:45:10 +00:00
|
|
|
error = -ENOMEM;
|
2012-02-02 15:25:43 +00:00
|
|
|
mref = if_alloc_mref(brick);
|
2010-12-10 17:40:20 +00:00
|
|
|
if (unlikely(!mref)) {
|
|
|
|
up(&input->kick_sem);
|
2010-11-26 13:45:10 +00:00
|
|
|
goto err;
|
2010-12-10 17:40:20 +00:00
|
|
|
}
|
2011-10-03 17:31:02 +00:00
|
|
|
mref_a = if_mref_get_aspect(brick, mref);
|
2010-12-10 17:40:20 +00:00
|
|
|
if (unlikely(!mref_a)) {
|
|
|
|
up(&input->kick_sem);
|
2010-11-26 13:45:10 +00:00
|
|
|
goto err;
|
2010-12-10 17:40:20 +00:00
|
|
|
}
|
2011-04-08 09:52:46 +00:00
|
|
|
|
|
|
|
#ifdef PREFETCH_LEN
|
|
|
|
prefetch_len = PREFETCH_LEN - offset;
|
2011-04-21 16:03:04 +00:00
|
|
|
#if 1
|
|
|
|
// TODO: this restriction is too strong to be useful for performance boosts. Do better.
|
|
|
|
if (prefetch_len > total_len) {
|
|
|
|
prefetch_len = total_len;
|
|
|
|
}
|
|
|
|
#endif
|
2012-08-08 13:50:41 +00:00
|
|
|
if (pos + prefetch_len > brick->dev_size) {
|
|
|
|
prefetch_len = brick->dev_size - pos;
|
2011-04-21 16:03:04 +00:00
|
|
|
}
|
|
|
|
if (prefetch_len < bv_len) {
|
2011-04-08 09:52:46 +00:00
|
|
|
prefetch_len = bv_len;
|
2011-04-21 16:03:04 +00:00
|
|
|
}
|
2011-04-08 09:52:46 +00:00
|
|
|
#else
|
|
|
|
prefetch_len = bv_len;
|
|
|
|
#endif
|
|
|
|
|
2011-10-04 11:34:18 +00:00
|
|
|
SETUP_CALLBACK(mref, if_endio, mref_a);
|
|
|
|
|
2010-11-26 13:45:10 +00:00
|
|
|
mref_a->input = input;
|
2019-03-14 20:11:51 +00:00
|
|
|
mref->ref_flags = rw ? MREF_WRITE | MREF_MAY_WRITE : 0;
|
2010-11-26 13:45:10 +00:00
|
|
|
mref->ref_pos = pos;
|
2011-04-08 09:52:46 +00:00
|
|
|
mref->ref_len = prefetch_len;
|
2010-12-10 17:40:20 +00:00
|
|
|
mref->ref_data = data; // direct IO
|
2012-02-26 15:23:57 +00:00
|
|
|
mref->ref_prio = ref_prio;
|
2011-04-21 16:03:04 +00:00
|
|
|
mref_a->orig_page = page;
|
2010-12-10 17:40:20 +00:00
|
|
|
|
2010-12-15 12:13:18 +00:00
|
|
|
error = GENERIC_INPUT_CALL(input, mref_get, mref);
|
2010-12-10 17:40:20 +00:00
|
|
|
if (unlikely(error < 0)) {
|
|
|
|
up(&input->kick_sem);
|
2010-11-26 13:45:10 +00:00
|
|
|
goto err;
|
2010-12-10 17:40:20 +00:00
|
|
|
}
|
2010-11-26 13:45:10 +00:00
|
|
|
|
2011-03-27 15:18:38 +00:00
|
|
|
mars_trace(mref, "if_start");
|
2011-04-08 09:52:46 +00:00
|
|
|
|
2011-04-21 16:03:04 +00:00
|
|
|
this_len = mref->ref_len; // now may be shorter than originally requested.
|
|
|
|
mref_a->max_len = this_len;
|
2011-04-08 09:52:46 +00:00
|
|
|
if (this_len > bv_len) {
|
2011-04-21 16:03:04 +00:00
|
|
|
this_len = bv_len;
|
2011-04-08 09:52:46 +00:00
|
|
|
}
|
2011-04-21 16:03:04 +00:00
|
|
|
mref_a->current_len = this_len;
|
2020-07-30 18:48:38 +00:00
|
|
|
#ifdef CONFIG_MARS_DEBUG
|
2011-03-31 16:16:00 +00:00
|
|
|
if (rw) {
|
2011-05-19 11:36:00 +00:00
|
|
|
atomic_inc(&input->total_mref_write_count);
|
2011-03-31 16:16:00 +00:00
|
|
|
} else {
|
2011-05-19 11:36:00 +00:00
|
|
|
atomic_inc(&input->total_mref_read_count);
|
2011-03-31 16:16:00 +00:00
|
|
|
}
|
2020-07-30 18:48:38 +00:00
|
|
|
#endif
|
2011-03-27 15:18:38 +00:00
|
|
|
|
2011-11-30 14:23:44 +00:00
|
|
|
CHECK_ATOMIC(&biow->bi_comp_cnt, 0);
|
|
|
|
atomic_inc(&biow->bi_comp_cnt);
|
|
|
|
mref_a->orig_biow[0] = biow;
|
2010-12-10 17:40:20 +00:00
|
|
|
mref_a->bio_count = 1;
|
|
|
|
assigned = true;
|
2013-04-18 16:38:03 +00:00
|
|
|
|
|
|
|
/* When a bio with multiple biovecs is split into
|
|
|
|
* multiple mrefs, only the last one should be
|
|
|
|
* working in synchronous writethrough mode.
|
|
|
|
*/
|
2019-03-25 08:00:45 +00:00
|
|
|
mref->ref_flags |= MREF_SKIP_SYNC;
|
2014-06-04 07:10:50 +00:00
|
|
|
// remove_this
|
2019-08-06 06:53:28 +00:00
|
|
|
#ifdef MARS_HAS_BVEC_ITER
|
2014-06-04 07:10:50 +00:00
|
|
|
// end_remove_this
|
|
|
|
if (!do_skip_sync && i.bi_idx + 1 >= bio->bi_iter.bi_idx) {
|
2019-03-25 08:00:45 +00:00
|
|
|
mref->ref_flags &= ~MREF_SKIP_SYNC;
|
2014-06-04 07:10:50 +00:00
|
|
|
}
|
|
|
|
// remove_this
|
|
|
|
#else
|
2013-04-18 16:38:03 +00:00
|
|
|
if (!do_skip_sync && i + 1 >= bio->bi_vcnt) {
|
2019-03-25 08:00:45 +00:00
|
|
|
mref->ref_flags &= ~MREF_SKIP_SYNC;
|
2011-03-24 16:05:46 +00:00
|
|
|
}
|
2014-06-04 07:10:50 +00:00
|
|
|
#endif
|
|
|
|
// end_remove_this
|
2011-03-24 16:05:46 +00:00
|
|
|
|
2011-03-30 12:02:50 +00:00
|
|
|
atomic_inc(&input->plugged_count);
|
|
|
|
|
|
|
|
mref_a->hash_index = hash_index;
|
2013-04-12 11:43:43 +00:00
|
|
|
traced_lock(&input->hash_table[hash_index].hash_lock, flags);
|
|
|
|
list_add_tail(&mref_a->hash_head, &input->hash_table[hash_index].hash_anchor);
|
|
|
|
traced_unlock(&input->hash_table[hash_index].hash_lock, flags);
|
2011-03-24 16:05:46 +00:00
|
|
|
|
2021-01-29 19:59:08 +00:00
|
|
|
#ifdef MARS_HAS_OLD_QUEUE_LOCK
|
2010-12-10 17:40:20 +00:00
|
|
|
traced_lock(&input->req_lock, flags);
|
2021-01-29 19:59:08 +00:00
|
|
|
#else
|
|
|
|
traced_lock(&input->q->queue_lock, flags);
|
|
|
|
#endif
|
2010-12-10 17:40:20 +00:00
|
|
|
list_add_tail(&mref_a->plug_head, &input->plug_anchor);
|
2021-01-29 19:59:08 +00:00
|
|
|
#ifdef MARS_HAS_OLD_QUEUE_LOCK
|
2010-12-10 17:40:20 +00:00
|
|
|
traced_unlock(&input->req_lock, flags);
|
2021-01-29 19:59:08 +00:00
|
|
|
#else
|
|
|
|
traced_unlock(&input->q->queue_lock, flags);
|
|
|
|
#endif
|
2011-03-31 04:41:42 +00:00
|
|
|
} // !mref
|
|
|
|
|
|
|
|
pos += this_len;
|
|
|
|
data += this_len;
|
|
|
|
bv_len -= this_len;
|
2011-04-08 09:52:46 +00:00
|
|
|
total_len -= this_len;
|
2010-11-26 13:45:10 +00:00
|
|
|
} // while bv_len > 0
|
|
|
|
} // foreach bvec
|
|
|
|
|
2010-12-10 17:40:20 +00:00
|
|
|
up(&input->kick_sem);
|
|
|
|
|
2011-04-08 09:52:46 +00:00
|
|
|
if (likely(!total_len)) {
|
|
|
|
error = 0;
|
|
|
|
} else {
|
|
|
|
MARS_ERR("bad rest len = %d\n", total_len);
|
|
|
|
}
|
2010-06-14 14:27:40 +00:00
|
|
|
|
|
|
|
err:
|
2010-12-10 17:40:20 +00:00
|
|
|
|
2011-10-12 14:57:53 +00:00
|
|
|
#ifdef IO_DEBUGGING
|
|
|
|
{
|
|
|
|
char *txt = brick->ops->brick_statistics(brick, false);
|
|
|
|
MARS_IO("%s", txt);
|
|
|
|
brick_string_free(txt);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-11-26 13:45:10 +00:00
|
|
|
if (error < 0) {
|
2011-03-31 04:41:42 +00:00
|
|
|
MARS_ERR("cannot submit request from bio, status=%d\n", error);
|
2015-09-29 05:35:59 +00:00
|
|
|
if (!assigned) {
|
2016-02-01 08:05:30 +00:00
|
|
|
brick->error_code = error;
|
2020-07-30 09:00:01 +00:00
|
|
|
_call_bio_endio(brick, bio, error);
|
2010-12-10 17:40:20 +00:00
|
|
|
}
|
2010-11-26 13:45:10 +00:00
|
|
|
}
|
|
|
|
|
2012-02-26 15:23:57 +00:00
|
|
|
if (do_unplug ||
|
2011-03-30 12:02:50 +00:00
|
|
|
(brick && brick->max_plugged > 0 && atomic_read(&input->plugged_count) > brick->max_plugged)) {
|
2011-03-07 10:27:38 +00:00
|
|
|
_if_unplug(input);
|
2010-11-26 13:45:10 +00:00
|
|
|
}
|
2011-07-15 10:12:06 +00:00
|
|
|
#ifdef USE_TIMER
|
|
|
|
else {
|
|
|
|
unsigned long flags;
|
2021-01-29 19:59:08 +00:00
|
|
|
#ifdef MARS_HAS_OLD_QUEUE_LOCK
|
2011-07-15 10:12:06 +00:00
|
|
|
traced_lock(&input->req_lock, flags);
|
2021-01-29 19:59:08 +00:00
|
|
|
#else
|
|
|
|
traced_lock(&input->q->queue_lock, flags);
|
|
|
|
#endif
|
2011-07-15 10:12:06 +00:00
|
|
|
if (timer_pending(&input->timer)) {
|
|
|
|
del_timer(&input->timer);
|
|
|
|
}
|
|
|
|
input->timer.function = if_timer;
|
|
|
|
input->timer.data = (unsigned long)input;
|
2011-12-08 15:38:04 +00:00
|
|
|
input->timer.expires = jiffies + USE_TIMER;
|
2011-07-15 10:12:06 +00:00
|
|
|
add_timer(&input->timer);
|
2021-01-29 19:59:08 +00:00
|
|
|
#ifdef MARS_HAS_OLD_QUEUE_LOCK
|
2011-07-15 10:12:06 +00:00
|
|
|
traced_unlock(&input->req_lock, flags);
|
2021-01-29 19:59:08 +00:00
|
|
|
#else
|
|
|
|
traced_unlock(&input->q->queue_lock, flags);
|
|
|
|
#endif
|
2011-07-15 10:12:06 +00:00
|
|
|
}
|
|
|
|
#endif
|
2010-12-10 17:40:20 +00:00
|
|
|
|
2012-09-18 06:13:33 +00:00
|
|
|
done:
|
2012-11-15 12:53:26 +00:00
|
|
|
remove_binding_from(brick->say_channel, current);
|
|
|
|
|
2015-11-18 14:16:07 +00:00
|
|
|
// remove_this
|
|
|
|
/* see dece16353ef47d8d33f5302bc158072a9d65e26f */
|
|
|
|
#ifdef BLK_QC_T_NONE
|
|
|
|
// end_remove_this
|
|
|
|
return BLK_QC_T_NONE;
|
|
|
|
// remove_this
|
|
|
|
#elif defined(BIO_CPU_AFFINE)
|
2010-08-04 17:32:04 +00:00
|
|
|
return error;
|
2012-09-18 06:13:33 +00:00
|
|
|
#else
|
|
|
|
return;
|
|
|
|
#endif
|
2010-06-14 14:27:40 +00:00
|
|
|
}
|
|
|
|
|
2019-01-08 15:48:50 +00:00
|
|
|
#ifdef NEED_BIO_SPLIT
|
|
|
|
static
|
|
|
|
#ifdef BLK_QC_T_NONE
|
|
|
|
blk_qc_t if_make_request(struct request_queue *q, struct bio *bio)
|
|
|
|
#else
|
|
|
|
void if_make_request(struct request_queue *q, struct bio *bio)
|
|
|
|
#endif
|
|
|
|
{
|
2019-02-21 11:45:57 +00:00
|
|
|
#ifdef MARS_HAS_BIO_SPLIT2
|
|
|
|
blk_queue_split(q, &bio);
|
|
|
|
#else
|
2019-01-08 15:48:50 +00:00
|
|
|
blk_queue_split(q, &bio, q->bio_split);
|
2019-02-21 11:45:57 +00:00
|
|
|
#endif
|
2019-01-08 15:48:50 +00:00
|
|
|
#ifdef BLK_QC_T_NONE
|
|
|
|
return _if_make_request(q, bio);
|
|
|
|
#else
|
|
|
|
_if_make_request(q, bio);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2012-09-18 06:13:33 +00:00
|
|
|
#ifndef BLK_MAX_REQUEST_COUNT
|
2011-03-18 13:15:40 +00:00
|
|
|
//static
|
|
|
|
void if_unplug(struct request_queue *q)
|
2010-06-17 16:57:10 +00:00
|
|
|
{
|
2011-12-08 15:38:04 +00:00
|
|
|
struct if_input *input = q->queuedata;
|
2011-05-06 10:25:52 +00:00
|
|
|
int was_plugged = 1;
|
|
|
|
#if 1
|
|
|
|
spin_lock_irq(q->queue_lock);
|
|
|
|
was_plugged = blk_remove_plug(q);
|
|
|
|
spin_unlock_irq(q->queue_lock);
|
|
|
|
#else
|
2010-06-17 16:57:10 +00:00
|
|
|
queue_flag_clear_unlocked(QUEUE_FLAG_PLUGGED, q);
|
2011-05-06 10:25:52 +00:00
|
|
|
#endif
|
2011-12-08 15:38:04 +00:00
|
|
|
|
|
|
|
was_plugged += atomic_read(&input->plugged_count);
|
|
|
|
|
2011-10-12 14:57:53 +00:00
|
|
|
MARS_IO("block layer called UNPLUG was_plugged = %d\n", was_plugged);
|
2011-12-08 15:38:04 +00:00
|
|
|
if (ALWAYS_UNPLUG_FROM_EXTERNAL || was_plugged) {
|
2011-05-06 10:25:52 +00:00
|
|
|
_if_unplug(input);
|
|
|
|
}
|
2010-06-17 16:57:10 +00:00
|
|
|
}
|
2012-09-18 06:13:33 +00:00
|
|
|
#endif
|
2010-06-17 16:57:10 +00:00
|
|
|
|
2011-03-18 13:15:40 +00:00
|
|
|
//static
|
|
|
|
int mars_congested(void *data, int bdi_bits)
|
|
|
|
{
|
|
|
|
struct if_input *input = data;
|
2022-06-27 16:41:04 +00:00
|
|
|
struct if_brick *brick;
|
2011-03-18 13:15:40 +00:00
|
|
|
int ret = 0;
|
2015-08-19 10:50:59 +00:00
|
|
|
|
2022-06-27 16:41:04 +00:00
|
|
|
if (!data)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
CHECK_PTR(input, done);
|
|
|
|
brick = input->brick;
|
|
|
|
if (!brick)
|
|
|
|
goto done;
|
|
|
|
CHECK_PTR(brick, done);
|
|
|
|
|
2015-08-19 10:50:59 +00:00
|
|
|
#ifdef WB_STAT_BATCH /* changed by 4452226ea276e74fc3e252c88d9bb7e8f8e44bf0 */
|
|
|
|
if (bdi_bits & (1 << WB_sync_congested) &&
|
2020-05-08 16:41:22 +00:00
|
|
|
atomic_read(&brick->read_flying_count) > 0) {
|
2015-08-19 10:50:59 +00:00
|
|
|
ret |= (1 << WB_sync_congested);
|
|
|
|
}
|
|
|
|
if (bdi_bits & (1 << WB_async_congested) &&
|
2020-05-08 16:41:22 +00:00
|
|
|
atomic_read(&brick->write_flying_count) > 0) {
|
2015-08-19 10:50:59 +00:00
|
|
|
ret |= (1 << WB_async_congested);
|
|
|
|
}
|
|
|
|
#else /* old code */
|
2011-03-18 13:15:40 +00:00
|
|
|
if (bdi_bits & (1 << BDI_sync_congested) &&
|
2020-05-08 16:41:22 +00:00
|
|
|
atomic_read(&brick->read_flying_count) > 0) {
|
2011-03-18 13:15:40 +00:00
|
|
|
ret |= (1 << BDI_sync_congested);
|
2012-12-29 21:45:00 +00:00
|
|
|
}
|
|
|
|
if (bdi_bits & (1 << BDI_async_congested) &&
|
2020-05-08 16:41:22 +00:00
|
|
|
atomic_read(&brick->write_flying_count) > 0) {
|
2012-12-29 21:45:00 +00:00
|
|
|
ret |= (1 << BDI_async_congested);
|
2011-03-18 13:15:40 +00:00
|
|
|
}
|
2015-08-19 10:50:59 +00:00
|
|
|
#endif
|
2022-06-27 16:41:04 +00:00
|
|
|
done:
|
2011-03-18 13:15:40 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-10-23 10:04:22 +00:00
|
|
|
// remove_this
|
2019-08-06 06:53:28 +00:00
|
|
|
#ifdef MARS_HAS_MERGE_BVEC
|
2016-10-23 09:54:01 +00:00
|
|
|
static
|
|
|
|
int mars_merge_bvec(struct request_queue *q, struct bvec_merge_data *bvm, struct bio_vec *bvec)
|
|
|
|
{
|
|
|
|
unsigned int bio_size = bvm->bi_size;
|
|
|
|
if (!bio_size) {
|
|
|
|
return bvec->bv_len;
|
|
|
|
}
|
|
|
|
return 128;
|
|
|
|
}
|
2016-10-23 10:04:22 +00:00
|
|
|
#endif
|
2016-10-23 09:54:01 +00:00
|
|
|
|
2016-10-23 10:04:22 +00:00
|
|
|
// end_remove_this
|
2012-08-08 13:50:41 +00:00
|
|
|
static
|
2013-09-25 13:21:50 +00:00
|
|
|
loff_t if_get_capacity(struct if_brick *brick)
|
2012-08-08 13:50:41 +00:00
|
|
|
{
|
2013-09-25 13:21:50 +00:00
|
|
|
/* Don't read always, read only when unknown.
|
|
|
|
* brick->dev_size may be different from underlying sizes,
|
|
|
|
* e.g. when the size symlink indicates a logically smaller
|
|
|
|
* device than physically.
|
|
|
|
*/
|
2012-08-08 13:50:41 +00:00
|
|
|
if (brick->dev_size <= 0) {
|
|
|
|
struct if_input *input = brick->inputs[0];
|
|
|
|
int status;
|
2013-09-25 13:21:50 +00:00
|
|
|
|
2019-02-06 09:08:44 +00:00
|
|
|
status = GENERIC_INPUT_CALL(input, mars_get_info, &brick->info);
|
2013-09-25 13:21:50 +00:00
|
|
|
if (unlikely(status < 0)) {
|
2012-08-08 13:50:41 +00:00
|
|
|
MARS_ERR("cannot get device info, status=%d\n", status);
|
|
|
|
return 0;
|
|
|
|
}
|
2019-02-06 09:08:44 +00:00
|
|
|
MARS_INF("determined default capacity: %lld bytes\n", brick->info.current_size);
|
|
|
|
brick->dev_size = brick->info.current_size;
|
2012-08-08 13:50:41 +00:00
|
|
|
}
|
2013-09-25 13:21:50 +00:00
|
|
|
return brick->dev_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
void if_set_capacity(struct if_input *input, loff_t capacity)
|
|
|
|
{
|
|
|
|
CHECK_PTR(input->disk, done);
|
|
|
|
CHECK_PTR(input->disk->disk_name, done);
|
|
|
|
MARS_INF("new capacity of '%s': %lld bytes\n", input->disk->disk_name, capacity);
|
|
|
|
input->capacity = capacity;
|
|
|
|
set_capacity(input->disk, capacity >> 9);
|
|
|
|
if (likely(input->bdev && input->bdev->bd_inode)) {
|
|
|
|
i_size_write(input->bdev->bd_inode, capacity);
|
|
|
|
}
|
|
|
|
done:;
|
2012-08-08 13:50:41 +00:00
|
|
|
}
|
|
|
|
|
2011-11-08 12:33:13 +00:00
|
|
|
static const struct block_device_operations if_blkdev_ops;
|
2010-06-14 14:27:40 +00:00
|
|
|
|
2020-05-08 16:41:22 +00:00
|
|
|
static
|
|
|
|
int check_io_done(struct if_brick *brick, bool do_wait)
|
|
|
|
{
|
|
|
|
for (;;) {
|
|
|
|
int nr = atomic_read(&brick->read_flying_count) +
|
|
|
|
atomic_read(&brick->write_flying_count);
|
|
|
|
|
|
|
|
if (nr <= 0 || !do_wait)
|
|
|
|
return nr;
|
|
|
|
MARS_INF("%d IO requests not yet completed\n", nr);
|
|
|
|
brick_msleep(1000 / HZ + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-07 10:27:38 +00:00
|
|
|
static int if_switch(struct if_brick *brick)
|
2010-06-14 14:27:40 +00:00
|
|
|
{
|
2011-03-07 10:27:38 +00:00
|
|
|
struct if_input *input = brick->inputs[0];
|
2010-06-14 14:27:40 +00:00
|
|
|
struct request_queue *q;
|
|
|
|
struct gendisk *disk;
|
|
|
|
int minor;
|
2011-11-08 12:33:13 +00:00
|
|
|
int status = 0;
|
2010-06-14 14:27:40 +00:00
|
|
|
|
2011-11-08 12:33:13 +00:00
|
|
|
down(&brick->switch_sem);
|
|
|
|
|
2013-09-24 07:53:54 +00:00
|
|
|
// brick is in operation
|
|
|
|
if (brick->power.button && brick->power.led_on) {
|
2013-09-25 13:21:50 +00:00
|
|
|
loff_t capacity;
|
|
|
|
capacity = if_get_capacity(brick);
|
2013-09-24 07:53:54 +00:00
|
|
|
if (capacity > 0 && capacity != input->capacity) {
|
2013-09-25 13:21:50 +00:00
|
|
|
MARS_INF("changing capacity from %lld to %lld\n", (long long)input->capacity, (long long)capacity);
|
|
|
|
if_set_capacity(input, capacity);
|
2013-09-24 07:53:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// brick should be switched on
|
2011-11-08 12:33:13 +00:00
|
|
|
if (brick->power.button && brick->power.led_off) {
|
2013-09-25 13:21:50 +00:00
|
|
|
loff_t capacity;
|
2019-02-21 10:31:59 +00:00
|
|
|
#ifdef MARS_HAS_BDI_GET
|
|
|
|
struct backing_dev_info *bdi;
|
|
|
|
#endif
|
2013-09-25 13:21:50 +00:00
|
|
|
|
2011-02-23 20:48:06 +00:00
|
|
|
mars_power_led_off((void*)brick, false);
|
2012-11-15 12:53:26 +00:00
|
|
|
brick->say_channel = get_binding(current);
|
|
|
|
|
2011-11-08 12:33:13 +00:00
|
|
|
status = -ENOMEM;
|
2011-02-23 20:48:06 +00:00
|
|
|
q = blk_alloc_queue(GFP_MARS);
|
|
|
|
if (!q) {
|
|
|
|
MARS_ERR("cannot allocate device request queue\n");
|
2011-11-08 12:33:13 +00:00
|
|
|
goto is_down;
|
2011-02-23 20:48:06 +00:00
|
|
|
}
|
|
|
|
q->queuedata = input;
|
|
|
|
input->q = q;
|
|
|
|
|
|
|
|
disk = alloc_disk(1);
|
|
|
|
if (!disk) {
|
|
|
|
MARS_ERR("cannot allocate gendisk\n");
|
2011-11-08 12:33:13 +00:00
|
|
|
goto is_down;
|
2011-02-23 20:48:06 +00:00
|
|
|
}
|
2010-06-14 14:27:40 +00:00
|
|
|
|
2011-02-23 20:48:06 +00:00
|
|
|
minor = device_minor++; //TODO: protect against races (e.g. atomic_t)
|
2012-09-18 06:13:33 +00:00
|
|
|
set_disk_ro(disk, true);
|
|
|
|
|
2011-02-23 20:48:06 +00:00
|
|
|
disk->queue = q;
|
|
|
|
disk->major = MARS_MAJOR; //TODO: make this dynamic for >256 devices
|
|
|
|
disk->first_minor = minor;
|
2011-03-07 10:27:38 +00:00
|
|
|
disk->fops = &if_blkdev_ops;
|
2011-02-23 20:48:06 +00:00
|
|
|
snprintf(disk->disk_name, sizeof(disk->disk_name), "mars/%s", brick->brick_name);
|
|
|
|
disk->private_data = input;
|
2013-09-25 13:21:50 +00:00
|
|
|
input->disk = disk;
|
|
|
|
capacity = if_get_capacity(brick);
|
|
|
|
MARS_DBG("created device name %s, capacity=%lld\n", disk->disk_name, capacity);
|
|
|
|
if_set_capacity(input, capacity);
|
2011-02-23 20:48:06 +00:00
|
|
|
|
2011-03-07 10:27:38 +00:00
|
|
|
blk_queue_make_request(q, if_make_request);
|
2011-03-18 13:15:40 +00:00
|
|
|
#ifdef USE_MAX_SECTORS
|
2012-09-18 06:13:33 +00:00
|
|
|
#ifdef MAX_SEGMENT_SIZE
|
|
|
|
MARS_DBG("blk_queue_max_sectors()\n");
|
2011-03-18 13:15:40 +00:00
|
|
|
blk_queue_max_sectors(q, USE_MAX_SECTORS);
|
2012-09-18 06:13:33 +00:00
|
|
|
#else
|
|
|
|
MARS_DBG("blk_queue_max_hw_sectors()\n");
|
|
|
|
blk_queue_max_hw_sectors(q, USE_MAX_SECTORS);
|
|
|
|
#endif
|
2011-03-18 13:15:40 +00:00
|
|
|
#endif
|
|
|
|
#ifdef USE_MAX_PHYS_SEGMENTS
|
2012-09-18 06:13:33 +00:00
|
|
|
#ifdef MAX_SEGMENT_SIZE
|
|
|
|
MARS_DBG("blk_queue_max_phys_segments()\n");
|
2011-03-18 13:15:40 +00:00
|
|
|
blk_queue_max_phys_segments(q, USE_MAX_PHYS_SEGMENTS);
|
2012-09-18 06:13:33 +00:00
|
|
|
#else
|
|
|
|
MARS_DBG("blk_queue_max_segments()\n");
|
|
|
|
blk_queue_max_segments(q, USE_MAX_PHYS_SEGMENTS);
|
|
|
|
#endif
|
2011-03-18 13:15:40 +00:00
|
|
|
#endif
|
|
|
|
#ifdef USE_MAX_HW_SEGMENTS
|
2012-09-18 06:13:33 +00:00
|
|
|
MARS_DBG("blk_queue_max_hw_segments()\n");
|
2011-03-18 13:15:40 +00:00
|
|
|
blk_queue_max_hw_segments(q, USE_MAX_HW_SEGMENTS);
|
|
|
|
#endif
|
2019-01-10 06:25:27 +00:00
|
|
|
#ifdef USE_MAX_HW_SECTORS
|
|
|
|
MARS_DBG("blk_queue_max_hw_sectors()\n");
|
|
|
|
blk_queue_max_hw_sectors(q, USE_MAX_HW_SECTORS);
|
|
|
|
#endif
|
2011-03-18 13:15:40 +00:00
|
|
|
#ifdef USE_MAX_SEGMENT_SIZE
|
2012-09-18 06:13:33 +00:00
|
|
|
MARS_DBG("blk_queue_max_segment_size()\n");
|
2011-03-18 13:15:40 +00:00
|
|
|
blk_queue_max_segment_size(q, USE_MAX_SEGMENT_SIZE);
|
|
|
|
#endif
|
|
|
|
#ifdef USE_LOGICAL_BLOCK_SIZE
|
2019-02-06 09:14:12 +00:00
|
|
|
if (brick->info.tf_align >= 512) {
|
|
|
|
MARS_DBG("blk_queue_physical_block_size(%d)\n", brick->info.tf_align);
|
|
|
|
blk_queue_physical_block_size(q, brick->info.tf_align);
|
|
|
|
}
|
|
|
|
if (brick->info.tf_min_size >= 512) {
|
|
|
|
MARS_DBG("blk_queue_logical_block_size(%d)\n", brick->info.tf_min_size);
|
|
|
|
blk_queue_logical_block_size(q, brick->info.tf_min_size);
|
|
|
|
} else {
|
|
|
|
MARS_DBG("blk_queue_logical_block_size()\n");
|
|
|
|
blk_queue_logical_block_size(q, USE_LOGICAL_BLOCK_SIZE);
|
|
|
|
}
|
2011-03-18 13:15:40 +00:00
|
|
|
#endif
|
|
|
|
#ifdef USE_SEGMENT_BOUNDARY
|
2012-09-18 06:13:33 +00:00
|
|
|
MARS_DBG("blk_queue_segment_boundary()\n");
|
2011-03-18 13:15:40 +00:00
|
|
|
blk_queue_segment_boundary(q, USE_SEGMENT_BOUNDARY);
|
|
|
|
#endif
|
2012-09-18 06:13:33 +00:00
|
|
|
#ifdef QUEUE_ORDERED_DRAIN
|
|
|
|
MARS_DBG("blk_queue_ordered()\n");
|
|
|
|
blk_queue_ordered(q, QUEUE_ORDERED_DRAIN, NULL);
|
2011-03-18 13:15:40 +00:00
|
|
|
#endif
|
2012-09-18 06:13:33 +00:00
|
|
|
MARS_DBG("blk_queue_bounce_limit()\n");
|
2011-02-23 20:48:06 +00:00
|
|
|
blk_queue_bounce_limit(q, BLK_BOUNCE_ANY);
|
2012-09-18 06:13:33 +00:00
|
|
|
#ifndef BLK_MAX_REQUEST_COUNT
|
|
|
|
MARS_DBG("unplug_fn\n");
|
2011-03-07 10:27:38 +00:00
|
|
|
q->unplug_fn = if_unplug;
|
2012-09-18 06:13:33 +00:00
|
|
|
#endif
|
2021-01-29 19:59:08 +00:00
|
|
|
#ifdef MARS_HAS_OLD_QUEUE_LOCK
|
2012-09-18 06:13:33 +00:00
|
|
|
MARS_DBG("queue_lock\n");
|
2011-02-23 20:48:06 +00:00
|
|
|
q->queue_lock = &input->req_lock; // needed!
|
2021-01-29 19:59:08 +00:00
|
|
|
#endif
|
2011-02-23 20:48:06 +00:00
|
|
|
|
|
|
|
input->bdev = bdget(MKDEV(disk->major, minor));
|
|
|
|
/* we have no partitions. we contain only ourselves. */
|
|
|
|
input->bdev->bd_contains = input->bdev;
|
2010-06-14 14:27:40 +00:00
|
|
|
|
2019-02-21 10:31:59 +00:00
|
|
|
#ifdef MARS_HAS_BDI_GET
|
|
|
|
bdi = input->bdev->bd_bdi;
|
|
|
|
#ifdef MODIFY_READAHEAD
|
|
|
|
MARS_INF("ra_pages OLD = %lu NEW = %d\n",
|
|
|
|
bdi->ra_pages, brick->readahead);
|
|
|
|
bdi->ra_pages = brick->readahead;
|
|
|
|
#endif
|
|
|
|
#ifdef USE_CONGESTED_FN
|
|
|
|
MARS_DBG("congested_fn\n");
|
|
|
|
bdi->congested_fn = mars_congested;
|
|
|
|
bdi->congested_data = input;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2011-12-08 15:38:04 +00:00
|
|
|
#ifdef MODIFY_READAHEAD
|
2011-03-11 13:57:54 +00:00
|
|
|
MARS_INF("ra_pages OLD = %lu NEW = %d\n", q->backing_dev_info.ra_pages, brick->readahead);
|
|
|
|
q->backing_dev_info.ra_pages = brick->readahead;
|
2011-08-05 09:26:24 +00:00
|
|
|
#endif
|
2011-03-18 13:15:40 +00:00
|
|
|
#ifdef USE_CONGESTED_FN
|
2012-09-18 06:13:33 +00:00
|
|
|
MARS_DBG("congested_fn\n");
|
2011-02-23 20:48:06 +00:00
|
|
|
q->backing_dev_info.congested_fn = mars_congested;
|
|
|
|
q->backing_dev_info.congested_data = input;
|
2010-06-14 14:27:40 +00:00
|
|
|
#endif
|
2019-02-21 10:31:59 +00:00
|
|
|
#endif
|
2016-10-23 10:04:22 +00:00
|
|
|
// remove_this
|
2019-08-06 06:53:28 +00:00
|
|
|
#ifdef MARS_HAS_MERGE_BVEC
|
2016-10-23 09:54:01 +00:00
|
|
|
MARS_DBG("blk_queue_merge_bvec()\n");
|
|
|
|
blk_queue_merge_bvec(q, mars_merge_bvec);
|
|
|
|
#endif
|
2011-02-23 20:48:06 +00:00
|
|
|
|
2016-10-23 10:04:22 +00:00
|
|
|
// end_remove_this
|
2017-04-07 06:24:20 +00:00
|
|
|
q->nr_requests = if_nr_requests;
|
2011-02-23 20:48:06 +00:00
|
|
|
// point of no return
|
2012-09-18 06:13:33 +00:00
|
|
|
MARS_DBG("add_disk()\n");
|
2011-02-23 20:48:06 +00:00
|
|
|
add_disk(disk);
|
2012-09-18 06:13:33 +00:00
|
|
|
#if 1
|
|
|
|
set_disk_ro(disk, false);
|
|
|
|
#else
|
|
|
|
set_device_ro(input->bdev, 0); // TODO: implement modes
|
|
|
|
#endif
|
2013-09-24 07:53:54 +00:00
|
|
|
|
|
|
|
// report success
|
2011-02-23 20:48:06 +00:00
|
|
|
mars_power_led_on((void*)brick, true);
|
2011-11-08 12:33:13 +00:00
|
|
|
status = 0;
|
2013-09-24 07:53:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// brick should be switched off
|
|
|
|
if (!brick->power.button && !brick->power.led_off) {
|
2015-03-23 11:34:12 +00:00
|
|
|
int opened;
|
|
|
|
int plugged;
|
2013-08-30 13:28:09 +00:00
|
|
|
int flying;
|
|
|
|
|
2011-02-23 20:48:06 +00:00
|
|
|
mars_power_led_on((void*)brick, false);
|
2011-03-08 16:45:52 +00:00
|
|
|
disk = input->disk;
|
|
|
|
if (!disk)
|
2011-03-23 17:58:02 +00:00
|
|
|
goto is_down;
|
|
|
|
|
2015-03-23 11:34:12 +00:00
|
|
|
opened = atomic_read(&brick->open_count);
|
|
|
|
if (unlikely(opened > 0)) {
|
|
|
|
MARS_INF("device '%s' is open %d times, cannot shutdown\n", disk->disk_name, opened);
|
|
|
|
status = -EBUSY;
|
|
|
|
goto done; // don't indicate "off" status
|
|
|
|
}
|
|
|
|
plugged = atomic_read(&input->plugged_count);
|
|
|
|
if (unlikely(plugged > 0)) {
|
|
|
|
MARS_INF("device '%s' has %d plugged requests, cannot shutdown\n", disk->disk_name, plugged);
|
2011-11-08 12:33:13 +00:00
|
|
|
status = -EBUSY;
|
|
|
|
goto done; // don't indicate "off" status
|
2011-03-08 16:45:52 +00:00
|
|
|
}
|
2020-05-08 16:41:22 +00:00
|
|
|
flying = check_io_done(brick, false);
|
2015-03-23 11:34:12 +00:00
|
|
|
if (unlikely(flying > 0)) {
|
2013-08-30 13:28:09 +00:00
|
|
|
MARS_INF("device '%s' has %d flying requests, cannot shutdown\n", disk->disk_name, flying);
|
|
|
|
status = -EBUSY;
|
|
|
|
goto done; // don't indicate "off" status
|
|
|
|
}
|
2014-12-01 09:19:58 +00:00
|
|
|
MARS_DBG("calling del_gendisk()\n");
|
|
|
|
del_gendisk(input->disk);
|
|
|
|
/* There might be subtle races */
|
2020-05-08 16:41:22 +00:00
|
|
|
check_io_done(brick, true);
|
2011-02-23 20:48:06 +00:00
|
|
|
if (input->bdev) {
|
2021-01-24 10:27:24 +00:00
|
|
|
#if defined(USE_CONGESTED_FN) && defined(MARS_HAS_BDI_GET)
|
|
|
|
struct backing_dev_info *bdi;
|
|
|
|
|
|
|
|
/* ensure that callbacks will stop */
|
|
|
|
MARS_DBG("unregister congested_fn\n");
|
|
|
|
bdi = input->bdev->bd_bdi;
|
2022-06-27 16:41:04 +00:00
|
|
|
if (bdi) {
|
2021-01-24 10:27:24 +00:00
|
|
|
bdi->congested_fn = NULL;
|
2022-06-27 16:41:04 +00:00
|
|
|
bdi->congested_data = NULL;
|
|
|
|
}
|
2021-01-24 10:27:24 +00:00
|
|
|
#endif
|
2012-12-04 08:26:19 +00:00
|
|
|
MARS_DBG("calling bdput()\n");
|
2011-02-23 20:48:06 +00:00
|
|
|
bdput(input->bdev);
|
|
|
|
input->bdev = NULL;
|
|
|
|
}
|
2012-12-04 08:26:19 +00:00
|
|
|
MARS_DBG("calling put_disk()\n");
|
2011-03-23 17:58:02 +00:00
|
|
|
put_disk(input->disk);
|
|
|
|
input->disk = NULL;
|
2015-07-06 15:36:01 +00:00
|
|
|
q = input->q;
|
|
|
|
if (q) {
|
2021-01-24 10:27:24 +00:00
|
|
|
#if defined(USE_CONGESTED_FN) && !defined(MARS_HAS_BDI_GET)
|
|
|
|
/* ensure that callbacks will stop */
|
|
|
|
MARS_DBG("unregister congested_fn\n");
|
|
|
|
q->backing_dev_info.congested_fn = NULL;
|
2022-06-27 16:41:04 +00:00
|
|
|
q->backing_dev_info.congested_data = NULL;
|
2021-01-24 10:27:24 +00:00
|
|
|
#endif
|
2015-07-06 15:36:01 +00:00
|
|
|
blk_cleanup_queue(q);
|
|
|
|
input->q = NULL;
|
|
|
|
}
|
2011-11-08 12:33:13 +00:00
|
|
|
status = 0;
|
2011-03-23 17:58:02 +00:00
|
|
|
is_down:
|
2011-02-23 20:48:06 +00:00
|
|
|
mars_power_led_off((void*)brick, true);
|
|
|
|
}
|
2011-11-08 12:33:13 +00:00
|
|
|
|
|
|
|
done:
|
|
|
|
up(&brick->switch_sem);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////// interface to the outer world (kernel) ///////////////
|
|
|
|
|
|
|
|
static int if_open(struct block_device *bdev, fmode_t mode)
|
|
|
|
{
|
2012-12-04 08:26:19 +00:00
|
|
|
struct if_input *input;
|
|
|
|
struct if_brick *brick;
|
|
|
|
|
|
|
|
if (unlikely(!bdev || !bdev->bd_disk)) {
|
|
|
|
MARS_ERR("----------------------- INVAL ------------------------------\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
input = bdev->bd_disk->private_data;
|
|
|
|
|
|
|
|
if (unlikely(!input || !input->brick)) {
|
|
|
|
MARS_ERR("----------------------- BAD IF SETUP ------------------------------\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
brick = input->brick;
|
|
|
|
|
|
|
|
down(&brick->switch_sem);
|
|
|
|
|
|
|
|
if (unlikely(!brick->power.led_on)) {
|
2013-05-04 19:54:12 +00:00
|
|
|
MARS_INF("----------------------- BUSY %d ------------------------------\n", atomic_read(&brick->open_count));
|
2012-12-04 08:26:19 +00:00
|
|
|
up(&brick->switch_sem);
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
2013-05-04 19:54:12 +00:00
|
|
|
atomic_inc(&brick->open_count);
|
2012-12-04 08:26:19 +00:00
|
|
|
|
2013-05-04 19:54:12 +00:00
|
|
|
MARS_INF("----------------------- OPEN %d ------------------------------\n", atomic_read(&brick->open_count));
|
2020-06-14 10:42:22 +00:00
|
|
|
mars_remote_trigger(MARS_TRIGGER_LOCAL | MARS_TRIGGER_TO_REMOTE);
|
2012-12-04 08:26:19 +00:00
|
|
|
|
|
|
|
up(&brick->switch_sem);
|
2010-08-26 17:12:30 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-06-04 07:10:50 +00:00
|
|
|
static
|
|
|
|
// remove_this
|
2019-08-06 06:53:28 +00:00
|
|
|
#ifdef MARS_HAS_VOID_RELEASE
|
2014-06-04 07:10:50 +00:00
|
|
|
// end_remove_this
|
|
|
|
void
|
|
|
|
// remove_this
|
|
|
|
#else
|
|
|
|
int
|
|
|
|
#endif
|
|
|
|
// end_remove_this
|
|
|
|
if_release(struct gendisk *gd, fmode_t mode)
|
2011-11-08 12:33:13 +00:00
|
|
|
{
|
|
|
|
struct if_input *input = gd->private_data;
|
2013-05-04 19:54:12 +00:00
|
|
|
struct if_brick *brick = input->brick;
|
2011-11-08 12:33:13 +00:00
|
|
|
int nr;
|
|
|
|
|
2019-11-20 18:49:00 +00:00
|
|
|
nr = atomic_read(&brick->open_count);
|
|
|
|
MARS_INF("----------------------- CLOSE %d ------------------------------\n",
|
|
|
|
nr);
|
|
|
|
if (nr <= 1)
|
2020-05-08 16:41:22 +00:00
|
|
|
check_io_done(brick, true);
|
2012-12-04 08:26:19 +00:00
|
|
|
|
2013-05-04 19:54:12 +00:00
|
|
|
if (atomic_dec_and_test(&brick->open_count)) {
|
2020-05-08 16:41:22 +00:00
|
|
|
check_io_done(brick, true);
|
2012-12-04 08:26:19 +00:00
|
|
|
|
|
|
|
MARS_DBG("status button=%d led_on=%d led_off=%d\n", brick->power.button, brick->power.led_on, brick->power.led_off);
|
2016-02-01 08:05:30 +00:00
|
|
|
brick->error_code = 0;
|
2020-06-14 10:42:22 +00:00
|
|
|
mars_remote_trigger(MARS_TRIGGER_LOCAL | MARS_TRIGGER_TO_REMOTE);
|
2011-11-08 12:33:13 +00:00
|
|
|
}
|
2014-06-04 07:10:50 +00:00
|
|
|
// remove_this
|
2019-08-06 06:53:28 +00:00
|
|
|
#ifndef MARS_HAS_VOID_RELEASE
|
2011-11-08 12:33:13 +00:00
|
|
|
return 0;
|
2014-06-04 07:10:50 +00:00
|
|
|
#endif
|
|
|
|
// end_remove_this
|
2011-11-08 12:33:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct block_device_operations if_blkdev_ops = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.open = if_open,
|
|
|
|
.release = if_release,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2011-03-31 16:16:00 +00:00
|
|
|
//////////////// informational / statistics ///////////////
|
|
|
|
|
|
|
|
static
|
|
|
|
char *if_statistics(struct if_brick *brick, int verbose)
|
|
|
|
{
|
|
|
|
struct if_input *input = brick->inputs[0];
|
2012-02-12 11:19:57 +00:00
|
|
|
char *res = brick_string_alloc(512);
|
2020-07-30 18:48:38 +00:00
|
|
|
#ifdef CONFIG_MARS_DEBUG
|
2011-08-05 09:26:24 +00:00
|
|
|
int tmp0 = atomic_read(&input->total_reada_count);
|
2011-05-19 11:36:00 +00:00
|
|
|
int tmp1 = atomic_read(&input->total_read_count);
|
|
|
|
int tmp2 = atomic_read(&input->total_mref_read_count);
|
|
|
|
int tmp3 = atomic_read(&input->total_write_count);
|
|
|
|
int tmp4 = atomic_read(&input->total_mref_write_count);
|
2020-07-30 18:48:38 +00:00
|
|
|
#endif
|
2011-03-31 16:16:00 +00:00
|
|
|
if (!res)
|
|
|
|
return NULL;
|
2012-02-12 11:19:57 +00:00
|
|
|
snprintf(res, 512,
|
2020-05-16 17:29:04 +00:00
|
|
|
"disk = %p "
|
2020-07-30 18:48:38 +00:00
|
|
|
#ifdef CONFIG_MARS_DEBUG
|
2012-02-12 11:19:57 +00:00
|
|
|
"total reada = %d "
|
|
|
|
"reads = %d "
|
|
|
|
"mref_reads = %d (%d%%) "
|
|
|
|
"writes = %d "
|
|
|
|
"mref_writes = %d (%d%%) "
|
2013-01-03 08:49:52 +00:00
|
|
|
"empty = %d "
|
|
|
|
"fired = %d "
|
|
|
|
"skip_sync = %d "
|
2020-07-30 18:48:38 +00:00
|
|
|
#endif
|
2013-01-03 08:49:52 +00:00
|
|
|
"| "
|
2016-01-27 06:58:35 +00:00
|
|
|
"opened = %d "
|
2012-02-12 11:19:57 +00:00
|
|
|
"plugged = %d "
|
2020-05-08 16:41:22 +00:00
|
|
|
"flying reads = %d "
|
|
|
|
"flying writes = %d\n",
|
2020-05-16 17:29:04 +00:00
|
|
|
input->disk,
|
2020-07-30 18:48:38 +00:00
|
|
|
#ifdef CONFIG_MARS_DEBUG
|
2012-02-12 11:19:57 +00:00
|
|
|
tmp0,
|
|
|
|
tmp1,
|
|
|
|
tmp2,
|
|
|
|
tmp1 ? tmp2 * 100 / tmp1 : 0,
|
|
|
|
tmp3,
|
|
|
|
tmp4,
|
|
|
|
tmp3 ? tmp4 * 100 / tmp3 : 0,
|
|
|
|
atomic_read(&input->total_empty_count),
|
2013-01-03 08:49:52 +00:00
|
|
|
atomic_read(&input->total_fire_count),
|
|
|
|
atomic_read(&input->total_skip_sync_count),
|
2020-07-30 18:48:38 +00:00
|
|
|
#endif
|
2016-01-27 06:58:35 +00:00
|
|
|
atomic_read(&brick->open_count),
|
2012-02-12 11:19:57 +00:00
|
|
|
atomic_read(&input->plugged_count),
|
2020-05-08 16:41:22 +00:00
|
|
|
atomic_read(&brick->read_flying_count),
|
|
|
|
atomic_read(&brick->write_flying_count));
|
2011-03-31 16:16:00 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2011-05-19 11:36:00 +00:00
|
|
|
static
|
|
|
|
void if_reset_statistics(struct if_brick *brick)
|
|
|
|
{
|
2020-07-30 18:48:38 +00:00
|
|
|
#ifdef CONFIG_MARS_DEBUG
|
2011-05-19 11:36:00 +00:00
|
|
|
struct if_input *input = brick->inputs[0];
|
2020-07-30 18:48:38 +00:00
|
|
|
|
2011-05-19 11:36:00 +00:00
|
|
|
atomic_set(&input->total_read_count, 0);
|
|
|
|
atomic_set(&input->total_write_count, 0);
|
2011-07-15 10:12:06 +00:00
|
|
|
atomic_set(&input->total_empty_count, 0);
|
2013-01-03 08:49:52 +00:00
|
|
|
atomic_set(&input->total_fire_count, 0);
|
|
|
|
atomic_set(&input->total_skip_sync_count, 0);
|
2011-05-19 11:36:00 +00:00
|
|
|
atomic_set(&input->total_mref_read_count, 0);
|
|
|
|
atomic_set(&input->total_mref_write_count, 0);
|
2020-07-30 18:48:38 +00:00
|
|
|
#endif
|
2011-05-19 11:36:00 +00:00
|
|
|
}
|
|
|
|
|
2011-03-08 16:45:52 +00:00
|
|
|
////////////////// own brick / input / output operations //////////////////
|
|
|
|
|
|
|
|
// none
|
|
|
|
|
|
|
|
//////////////// object / aspect constructors / destructors ///////////////
|
|
|
|
|
2011-10-03 17:31:02 +00:00
|
|
|
static int if_mref_aspect_init_fn(struct generic_aspect *_ini)
|
2011-03-08 16:45:52 +00:00
|
|
|
{
|
|
|
|
struct if_mref_aspect *ini = (void*)_ini;
|
|
|
|
INIT_LIST_HEAD(&ini->plug_head);
|
2011-03-30 12:02:50 +00:00
|
|
|
INIT_LIST_HEAD(&ini->hash_head);
|
2011-03-08 16:45:52 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-10-03 17:31:02 +00:00
|
|
|
static void if_mref_aspect_exit_fn(struct generic_aspect *_ini)
|
2011-03-08 16:45:52 +00:00
|
|
|
{
|
|
|
|
struct if_mref_aspect *ini = (void*)_ini;
|
|
|
|
CHECK_HEAD_EMPTY(&ini->plug_head);
|
2011-03-30 12:02:50 +00:00
|
|
|
CHECK_HEAD_EMPTY(&ini->hash_head);
|
2011-03-08 16:45:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MARS_MAKE_STATICS(if);
|
|
|
|
|
2011-07-15 10:12:06 +00:00
|
|
|
//////////////////////// constructors / destructors ////////////////////////
|
2011-03-08 16:45:52 +00:00
|
|
|
|
|
|
|
static int if_brick_construct(struct if_brick *brick)
|
|
|
|
{
|
2011-11-08 12:33:13 +00:00
|
|
|
sema_init(&brick->switch_sem, 1);
|
2013-05-04 19:54:12 +00:00
|
|
|
atomic_set(&brick->open_count, 0);
|
2020-05-08 16:41:22 +00:00
|
|
|
atomic_set(&brick->read_flying_count, 0);
|
|
|
|
atomic_set(&brick->write_flying_count, 0);
|
2011-03-08 16:45:52 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int if_brick_destruct(struct if_brick *brick)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-03-07 10:27:38 +00:00
|
|
|
static int if_input_construct(struct if_input *input)
|
2010-08-26 17:12:30 +00:00
|
|
|
{
|
2011-03-30 12:02:50 +00:00
|
|
|
int i;
|
2013-04-12 11:43:43 +00:00
|
|
|
|
|
|
|
input->hash_table = brick_block_alloc(0, PAGE_SIZE);
|
2011-03-30 12:02:50 +00:00
|
|
|
for (i = 0; i < IF_HASH_MAX; i++) {
|
2013-04-12 11:43:43 +00:00
|
|
|
spin_lock_init(&input->hash_table[i].hash_lock);
|
|
|
|
INIT_LIST_HEAD(&input->hash_table[i].hash_anchor);
|
2011-03-30 12:02:50 +00:00
|
|
|
}
|
2011-03-08 16:45:52 +00:00
|
|
|
INIT_LIST_HEAD(&input->plug_anchor);
|
|
|
|
sema_init(&input->kick_sem, 1);
|
2021-01-29 19:59:08 +00:00
|
|
|
#ifdef MARS_HAS_OLD_QUEUE_LOCK
|
2011-03-08 16:45:52 +00:00
|
|
|
spin_lock_init(&input->req_lock);
|
2021-01-29 19:59:08 +00:00
|
|
|
#endif
|
2011-03-30 12:02:50 +00:00
|
|
|
atomic_set(&input->plugged_count, 0);
|
2011-07-15 10:12:06 +00:00
|
|
|
#ifdef USE_TIMER
|
|
|
|
init_timer(&input->timer);
|
|
|
|
#endif
|
2010-06-14 14:27:40 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-03-07 10:27:38 +00:00
|
|
|
static int if_input_destruct(struct if_input *input)
|
2010-06-14 14:27:40 +00:00
|
|
|
{
|
2013-04-12 11:43:43 +00:00
|
|
|
int i;
|
2021-01-24 10:27:24 +00:00
|
|
|
|
2013-04-12 11:43:43 +00:00
|
|
|
for (i = 0; i < IF_HASH_MAX; i++) {
|
|
|
|
CHECK_HEAD_EMPTY(&input->hash_table[i].hash_anchor);
|
|
|
|
}
|
|
|
|
CHECK_HEAD_EMPTY(&input->plug_anchor);
|
|
|
|
brick_block_free(input->hash_table, PAGE_SIZE);
|
2010-06-14 14:27:40 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-03-07 10:27:38 +00:00
|
|
|
static int if_output_construct(struct if_output *output)
|
2010-08-10 17:39:30 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-06-14 14:27:40 +00:00
|
|
|
///////////////////////// static structs ////////////////////////
|
|
|
|
|
2011-03-07 10:27:38 +00:00
|
|
|
static struct if_brick_ops if_brick_ops = {
|
|
|
|
.brick_switch = if_switch,
|
2011-03-31 16:16:00 +00:00
|
|
|
.brick_statistics = if_statistics,
|
2011-05-19 11:36:00 +00:00
|
|
|
.reset_statistics = if_reset_statistics,
|
2010-06-14 14:27:40 +00:00
|
|
|
};
|
|
|
|
|
2011-03-07 10:27:38 +00:00
|
|
|
static struct if_output_ops if_output_ops = {
|
2010-08-10 17:39:30 +00:00
|
|
|
};
|
|
|
|
|
2011-03-07 10:27:38 +00:00
|
|
|
const struct if_input_type if_input_type = {
|
|
|
|
.type_name = "if_input",
|
|
|
|
.input_size = sizeof(struct if_input),
|
|
|
|
.input_construct = &if_input_construct,
|
|
|
|
.input_destruct = &if_input_destruct,
|
2010-06-14 14:27:40 +00:00
|
|
|
};
|
|
|
|
|
2011-03-07 10:27:38 +00:00
|
|
|
static const struct if_input_type *if_input_types[] = {
|
|
|
|
&if_input_type,
|
2010-06-14 14:27:40 +00:00
|
|
|
};
|
|
|
|
|
2011-03-07 10:27:38 +00:00
|
|
|
const struct if_output_type if_output_type = {
|
|
|
|
.type_name = "if_output",
|
|
|
|
.output_size = sizeof(struct if_output),
|
|
|
|
.master_ops = &if_output_ops,
|
|
|
|
.output_construct = &if_output_construct,
|
2010-08-10 17:39:30 +00:00
|
|
|
};
|
2011-03-23 17:58:02 +00:00
|
|
|
|
|
|
|
static const struct if_output_type *if_output_types[] = {
|
|
|
|
&if_output_type,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-03-07 10:27:38 +00:00
|
|
|
const struct if_brick_type if_brick_type = {
|
|
|
|
.type_name = "if_brick",
|
|
|
|
.brick_size = sizeof(struct if_brick),
|
2010-06-14 14:27:40 +00:00
|
|
|
.max_inputs = 1,
|
|
|
|
.max_outputs = 0,
|
2011-03-07 10:27:38 +00:00
|
|
|
.master_ops = &if_brick_ops,
|
2011-10-03 17:31:02 +00:00
|
|
|
.aspect_types = if_aspect_types,
|
2011-03-07 10:27:38 +00:00
|
|
|
.default_input_types = if_input_types,
|
2011-03-23 17:58:02 +00:00
|
|
|
.default_output_types = if_output_types,
|
2011-03-07 10:27:38 +00:00
|
|
|
.brick_construct = &if_brick_construct,
|
|
|
|
.brick_destruct = &if_brick_destruct,
|
2010-06-14 14:27:40 +00:00
|
|
|
};
|
2011-03-07 10:27:38 +00:00
|
|
|
EXPORT_SYMBOL_GPL(if_brick_type);
|
2010-06-14 14:27:40 +00:00
|
|
|
|
|
|
|
////////////////// module init stuff /////////////////////////
|
|
|
|
|
2014-04-23 11:16:26 +00:00
|
|
|
void exit_mars_if(void)
|
2010-06-14 14:27:40 +00:00
|
|
|
{
|
|
|
|
int status;
|
2011-03-07 10:27:38 +00:00
|
|
|
MARS_INF("exit_if()\n");
|
|
|
|
status = if_unregister_brick_type();
|
2011-03-03 18:23:34 +00:00
|
|
|
unregister_blkdev(MARS_MAJOR, "mars");
|
2010-06-14 14:27:40 +00:00
|
|
|
}
|
|
|
|
|
2011-08-25 10:16:32 +00:00
|
|
|
int __init init_mars_if(void)
|
2010-06-14 14:27:40 +00:00
|
|
|
{
|
|
|
|
int status;
|
2010-08-04 17:32:04 +00:00
|
|
|
|
2011-03-07 10:27:38 +00:00
|
|
|
(void)if_aspect_types; // not used, shut up gcc
|
2010-08-04 17:32:04 +00:00
|
|
|
|
2011-03-07 10:27:38 +00:00
|
|
|
MARS_INF("init_if()\n");
|
2011-03-03 18:23:34 +00:00
|
|
|
status = register_blkdev(MARS_MAJOR, "mars");
|
2010-06-14 14:27:40 +00:00
|
|
|
if (status)
|
|
|
|
return status;
|
2011-03-07 10:27:38 +00:00
|
|
|
status = if_register_brick_type();
|
2010-06-14 14:27:40 +00:00
|
|
|
if (status)
|
|
|
|
goto err_device;
|
|
|
|
return status;
|
|
|
|
err_device:
|
2011-03-07 10:27:38 +00:00
|
|
|
MARS_ERR("init_if() status=%d\n", status);
|
2011-08-25 10:16:32 +00:00
|
|
|
exit_mars_if();
|
2010-06-14 14:27:40 +00:00
|
|
|
return status;
|
|
|
|
}
|