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
|
|
|
#ifndef MARS_H
|
|
|
|
#define MARS_H
|
|
|
|
|
2015-07-01 05:19:21 +00:00
|
|
|
/* TRANSITIONAL compatibility to BOTH the old prepatch
|
|
|
|
* and the new wrapper around vfs_*(). Both will be replaced
|
|
|
|
* for kernel upstream.
|
|
|
|
*/
|
|
|
|
#include "compat.h"
|
|
|
|
|
2011-02-23 20:48:06 +00:00
|
|
|
#include <linux/semaphore.h>
|
2011-06-10 13:57:52 +00:00
|
|
|
#include <linux/rwsem.h>
|
2015-07-01 05:19:21 +00:00
|
|
|
#include <linux/major.h>
|
2010-06-14 14:27:40 +00:00
|
|
|
|
2011-03-30 12:02:50 +00:00
|
|
|
//#define MARS_TRACING // write runtime trace data to /mars/trace.csv
|
2011-03-24 16:05:46 +00:00
|
|
|
|
2013-07-10 06:30:35 +00:00
|
|
|
// check the Kconfig environment
|
|
|
|
|
|
|
|
#ifndef CONFIG_MARS_MODULE
|
|
|
|
// when unsure, include faked config file
|
2013-04-09 13:35:00 +00:00
|
|
|
#include "mars_config.h"
|
2014-06-17 06:24:31 +00:00
|
|
|
#ifndef CONFIG_SMP
|
|
|
|
#warning CONFIG_SMP is not set -- are you SURE???
|
|
|
|
#endif
|
2013-07-10 06:30:35 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CONFIG_64BIT
|
|
|
|
#error MARS is only tested under 64bit
|
|
|
|
#endif
|
|
|
|
#ifndef CONFIG_BLOCK
|
|
|
|
#error CONFIG_BLOCK must be set
|
|
|
|
#endif
|
|
|
|
#ifndef CONFIG_PROC_SYSCTL
|
|
|
|
#error CONFIG_PROC_SYSCTL must be set
|
|
|
|
#endif
|
|
|
|
#ifndef CONFIG_HIGH_RES_TIMERS
|
|
|
|
#error CONFIG_HIGH_RES_TIMERS must be set
|
|
|
|
#endif
|
2014-06-14 06:47:54 +00:00
|
|
|
|
2011-03-22 14:36:26 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2011-03-27 15:18:38 +00:00
|
|
|
// include the generic brick infrastructure
|
2011-03-23 17:58:02 +00:00
|
|
|
|
2011-10-17 12:31:48 +00:00
|
|
|
#define OBJ_TYPE_MREF 0
|
|
|
|
#define OBJ_TYPE_MAX 1
|
2011-03-22 14:36:26 +00:00
|
|
|
|
|
|
|
#include "brick.h"
|
2011-08-12 11:09:48 +00:00
|
|
|
#include "brick_mem.h"
|
2012-12-10 09:31:28 +00:00
|
|
|
#include "brick_atomic.h"
|
2013-07-18 10:45:34 +00:00
|
|
|
#include "lamport.h"
|
2012-10-15 14:35:36 +00:00
|
|
|
#include "lib_timing.h"
|
2011-03-22 14:36:26 +00:00
|
|
|
|
2011-08-12 11:09:48 +00:00
|
|
|
#define GFP_MARS GFP_BRICK
|
2011-03-24 16:05:46 +00:00
|
|
|
|
2011-03-22 14:36:26 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2011-03-23 17:58:02 +00:00
|
|
|
// MARS-specific debugging helpers
|
2011-03-22 14:36:26 +00:00
|
|
|
|
2012-10-11 06:25:41 +00:00
|
|
|
#define _MARS_MSG(_class, _dump, _fmt, _args...) \
|
|
|
|
brick_say(_class, _dump, "MARS", __BASE_FILE__, __LINE__, __FUNCTION__, _fmt, ##_args)
|
2011-03-22 14:36:26 +00:00
|
|
|
|
2012-10-11 06:25:41 +00:00
|
|
|
#define MARS_FAT(_fmt, _args...) _MARS_MSG(SAY_FATAL, true, _fmt, ##_args)
|
2014-03-13 08:33:12 +00:00
|
|
|
#define MARS_ERR(_fmt, _args...) _MARS_MSG(SAY_ERROR, false, _fmt, ##_args)
|
2012-10-11 06:25:41 +00:00
|
|
|
#define MARS_WRN(_fmt, _args...) _MARS_MSG(SAY_WARN, false, _fmt, ##_args)
|
|
|
|
#define MARS_INF(_fmt, _args...) _MARS_MSG(SAY_INFO, false, _fmt, ##_args)
|
2011-03-18 13:15:40 +00:00
|
|
|
|
2010-07-23 11:55:18 +00:00
|
|
|
#ifdef MARS_DEBUGGING
|
2012-10-11 06:25:41 +00:00
|
|
|
#define MARS_DBG(_fmt, _args...) _MARS_MSG(SAY_DEBUG, false, _fmt, ##_args)
|
2010-07-23 11:55:18 +00:00
|
|
|
#else
|
2011-07-20 13:11:44 +00:00
|
|
|
#define MARS_DBG(_args...) /**/
|
2010-07-23 11:55:18 +00:00
|
|
|
#endif
|
2011-03-18 13:15:40 +00:00
|
|
|
|
2011-02-23 20:48:06 +00:00
|
|
|
#ifdef IO_DEBUGGING
|
2012-10-11 06:25:41 +00:00
|
|
|
#define MARS_IO(_fmt, _args...) _MARS_MSG(SAY_DEBUG, false, _fmt, ##_args)
|
2011-02-23 20:48:06 +00:00
|
|
|
#else
|
2011-07-20 13:11:44 +00:00
|
|
|
#define MARS_IO(_args...) /*empty*/
|
2011-02-23 20:48:06 +00:00
|
|
|
#endif
|
2011-03-18 13:15:40 +00:00
|
|
|
|
2011-03-02 09:30:56 +00:00
|
|
|
#ifdef STAT_DEBUGGING
|
2013-01-22 10:30:52 +00:00
|
|
|
#ifdef MARS_DEBUGGING
|
|
|
|
# define MARS_STAT MARS_DBG
|
|
|
|
#else
|
|
|
|
# define MARS_STAT MARS_INF
|
|
|
|
#endif
|
2011-03-02 09:30:56 +00:00
|
|
|
#else
|
2011-07-20 13:11:44 +00:00
|
|
|
#define MARS_STAT(_args...) /*empty*/
|
2011-03-02 09:30:56 +00:00
|
|
|
#endif
|
2010-06-14 14:27:40 +00:00
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// MARS-specific definitions
|
|
|
|
|
2019-07-19 06:07:37 +00:00
|
|
|
/* This _should_ be updated when _compatible_ features
|
|
|
|
* are added. When somebody may _rely_ on the new feature,
|
|
|
|
* then this _must_ be updated.
|
|
|
|
*/
|
2020-03-25 10:17:58 +00:00
|
|
|
#define OPTIONAL_FEATURES_VERSION 4
|
2019-07-19 06:07:37 +00:00
|
|
|
|
|
|
|
/* for stringification */
|
|
|
|
#define _stringify(s) #s
|
|
|
|
#define stringify(s) _stringify(s)
|
|
|
|
|
2019-07-30 11:46:14 +00:00
|
|
|
extern int usable_features_version;
|
|
|
|
|
2019-07-24 07:28:17 +00:00
|
|
|
#define OLD_MARS_DIGEST_SIZE 16
|
|
|
|
#define MARS_DIGEST_SIZE 32
|
2019-03-26 09:57:33 +00:00
|
|
|
|
2011-05-19 11:36:00 +00:00
|
|
|
#define MARS_PRIO_HIGH -1
|
|
|
|
#define MARS_PRIO_NORMAL 0 // this is automatically used by memset()
|
|
|
|
#define MARS_PRIO_LOW 1
|
|
|
|
#define MARS_PRIO_NR 3
|
2011-03-10 11:40:06 +00:00
|
|
|
|
2010-06-20 18:55:34 +00:00
|
|
|
// object stuff
|
|
|
|
|
2010-12-15 12:13:18 +00:00
|
|
|
/* mref */
|
2010-07-23 11:55:18 +00:00
|
|
|
|
2010-12-15 12:13:18 +00:00
|
|
|
extern const struct generic_object_type mref_type;
|
2010-07-05 15:56:58 +00:00
|
|
|
|
2011-03-27 15:18:38 +00:00
|
|
|
#ifdef MARS_TRACING
|
|
|
|
|
2011-03-29 14:40:40 +00:00
|
|
|
extern unsigned long long start_trace_clock;
|
|
|
|
|
2011-03-27 15:18:38 +00:00
|
|
|
#define MAX_TRACES 16
|
|
|
|
|
|
|
|
#define TRACING_INFO \
|
|
|
|
int ref_traces; \
|
2011-03-29 14:40:40 +00:00
|
|
|
unsigned long long ref_trace_stamp[MAX_TRACES]; \
|
|
|
|
const char *ref_trace_info[MAX_TRACES];
|
2011-03-27 15:18:38 +00:00
|
|
|
|
|
|
|
extern void _mars_log(char *buf, int len);
|
|
|
|
extern void mars_log(const char *fmt, ...);
|
|
|
|
extern void mars_trace(struct mref_object *mref, const char *info);
|
|
|
|
extern void mars_log_trace(struct mref_object *mref);
|
|
|
|
|
|
|
|
#else
|
|
|
|
#define TRACING_INFO /*empty*/
|
|
|
|
#define _mars_log(buf,len) /*empty*/
|
|
|
|
#define mars_log(fmt...) /*empty*/
|
|
|
|
#define mars_trace(mref,info) /*empty*/
|
|
|
|
#define mars_log_trace(mref) /*empty*/
|
|
|
|
#endif
|
|
|
|
|
2019-03-14 12:44:16 +00:00
|
|
|
enum _MREF_FLAGS {
|
|
|
|
/* New flags must always be appended */
|
|
|
|
/* Never change the position of an existing flag */
|
|
|
|
_MREF_UPTODATE,
|
|
|
|
_MREF_READING,
|
|
|
|
_MREF_WRITING,
|
2019-03-14 20:11:51 +00:00
|
|
|
_MREF_WRITE,
|
|
|
|
_MREF_MAY_WRITE,
|
2019-03-25 08:00:45 +00:00
|
|
|
_MREF_SKIP_SYNC,
|
2019-03-25 08:12:45 +00:00
|
|
|
_MREF_NODATA, /* only useful for chksum reading */
|
|
|
|
/* Checksum bits, starting at the upper half */
|
|
|
|
_MREF_CHKSUM_MD5_OLD = 16,
|
2019-08-07 07:15:21 +00:00
|
|
|
_MREF_CHKSUM_MD5,
|
2020-04-09 05:45:35 +00:00
|
|
|
_MREF_CHKSUM_CRC32C,
|
|
|
|
_MREF_CHKSUM_CRC32,
|
2019-03-26 13:22:08 +00:00
|
|
|
_MREF_CHKSUM_SHA1,
|
2019-03-26 09:57:33 +00:00
|
|
|
_MREF_CHKSUM_LAST,
|
2019-07-25 06:55:17 +00:00
|
|
|
_MREF_COMPRESS_LZO = 24,
|
2019-07-31 12:40:52 +00:00
|
|
|
_MREF_COMPRESS_LZ4,
|
2020-03-29 16:17:48 +00:00
|
|
|
_MREF_COMPRESS_ZLIB,
|
2019-07-25 06:55:17 +00:00
|
|
|
_MREF_COMPRESS_LAST,
|
2022-03-28 14:18:41 +00:00
|
|
|
} __packed;
|
2019-03-14 12:44:16 +00:00
|
|
|
|
|
|
|
#define MREF_UPTODATE (1UL << _MREF_UPTODATE)
|
|
|
|
#define MREF_READING (1UL << _MREF_READING)
|
|
|
|
#define MREF_WRITING (1UL << _MREF_WRITING)
|
2019-03-14 20:11:51 +00:00
|
|
|
#define MREF_WRITE (1UL << _MREF_WRITE)
|
|
|
|
#define MREF_MAY_WRITE (1UL << _MREF_MAY_WRITE)
|
2019-03-25 08:00:45 +00:00
|
|
|
#define MREF_SKIP_SYNC (1UL << _MREF_SKIP_SYNC)
|
2019-03-25 08:12:45 +00:00
|
|
|
#define MREF_NODATA (1UL << _MREF_NODATA)
|
|
|
|
#define MREF_CHKSUM_MD5_OLD (1UL << _MREF_CHKSUM_MD5_OLD)
|
2019-08-07 07:15:21 +00:00
|
|
|
#define MREF_CHKSUM_MD5 (1UL << _MREF_CHKSUM_MD5)
|
2020-04-09 05:45:35 +00:00
|
|
|
#define MREF_CHKSUM_CRC32C (1UL << _MREF_CHKSUM_CRC32C)
|
|
|
|
#define MREF_CHKSUM_CRC32 (1UL << _MREF_CHKSUM_CRC32)
|
2019-03-26 13:22:08 +00:00
|
|
|
#define MREF_CHKSUM_SHA1 (1UL << _MREF_CHKSUM_SHA1)
|
2019-03-26 09:57:33 +00:00
|
|
|
#define MREF_CHKSUM_LAST (1UL << _MREF_CHKSUM_LAST)
|
2019-07-25 06:55:17 +00:00
|
|
|
#define MREF_COMPRESS_LZO (1UL << _MREF_COMPRESS_LZO)
|
2019-07-31 12:40:52 +00:00
|
|
|
#define MREF_COMPRESS_LZ4 (1UL << _MREF_COMPRESS_LZ4)
|
2020-03-29 16:17:48 +00:00
|
|
|
#define MREF_COMPRESS_ZLIB (1UL << _MREF_COMPRESS_ZLIB)
|
2019-03-26 09:57:33 +00:00
|
|
|
#define MREF_CHKSUM_ANY (MREF_CHKSUM_MD5_OLD | \
|
2019-08-07 07:15:21 +00:00
|
|
|
MREF_CHKSUM_MD5 | \
|
2020-04-09 05:45:35 +00:00
|
|
|
MREF_CHKSUM_CRC32C | \
|
|
|
|
MREF_CHKSUM_CRC32 | \
|
2019-03-26 13:22:08 +00:00
|
|
|
MREF_CHKSUM_SHA1 | \
|
2019-03-26 09:57:33 +00:00
|
|
|
MREF_CHKSUM_LAST)
|
2019-07-31 12:40:52 +00:00
|
|
|
#define MREF_COMPRESS_ANY (MREF_COMPRESS_LZO | \
|
2020-03-29 16:17:48 +00:00
|
|
|
MREF_COMPRESS_LZ4 | \
|
|
|
|
MREF_COMPRESS_ZLIB)
|
2019-03-14 12:44:16 +00:00
|
|
|
|
2012-01-30 11:54:27 +00:00
|
|
|
#define MREF_OBJECT(OBJTYPE) \
|
|
|
|
CALLBACK_OBJECT(OBJTYPE); \
|
2010-08-02 16:31:10 +00:00
|
|
|
/* supplied by caller */ \
|
2011-03-10 11:40:06 +00:00
|
|
|
void *ref_data; /* preset to NULL for buffered IO */ \
|
2010-08-05 15:54:48 +00:00
|
|
|
loff_t ref_pos; \
|
|
|
|
int ref_len; \
|
2011-03-10 11:40:06 +00:00
|
|
|
int ref_prio; \
|
2011-03-07 10:27:38 +00:00
|
|
|
int ref_timeout; \
|
2019-03-14 12:44:16 +00:00
|
|
|
/* shared */ \
|
|
|
|
__u32 ref_flags; \
|
2010-08-05 15:54:48 +00:00
|
|
|
/* maintained by the ref implementation, readable for callers */ \
|
2011-03-18 13:15:40 +00:00
|
|
|
loff_t ref_total_size; /* just for info, need not be implemented */ \
|
2019-03-26 09:57:33 +00:00
|
|
|
unsigned char ref_checksum[MARS_DIGEST_SIZE]; \
|
2011-02-23 20:48:06 +00:00
|
|
|
int ref_id; /* not mandatory; may be used for identification */ \
|
2010-08-05 15:54:48 +00:00
|
|
|
/* maintained by the ref implementation, incrementable for \
|
|
|
|
* callers (but not decrementable! use ref_put()) */ \
|
2012-12-10 09:31:28 +00:00
|
|
|
tatomic_t ref_count; \
|
2019-03-14 20:11:51 +00:00
|
|
|
/* deprecated, to be removed in future */ \
|
|
|
|
int ref_rw; \
|
|
|
|
int ref_may_write; \
|
2019-03-25 08:00:45 +00:00
|
|
|
bool ref_skip_sync; /* skip sync for this particular mref */ \
|
2019-03-25 08:12:45 +00:00
|
|
|
int ref_cs_mode; /* 0 = off, 1 = checksum + data, 2 = checksum only */ \
|
2011-10-04 11:34:18 +00:00
|
|
|
/* internal */ \
|
2012-12-10 09:31:28 +00:00
|
|
|
atomic_trace_t ref_at; \
|
2019-03-14 21:13:09 +00:00
|
|
|
bool ref_initialized; /* internally used for checking */ \
|
2011-03-27 15:18:38 +00:00
|
|
|
TRACING_INFO;
|
2010-07-23 11:55:18 +00:00
|
|
|
|
2010-12-15 12:13:18 +00:00
|
|
|
struct mref_object {
|
|
|
|
MREF_OBJECT(mref);
|
2010-07-23 11:55:18 +00:00
|
|
|
};
|
2010-06-20 18:55:34 +00:00
|
|
|
|
2012-12-10 09:31:28 +00:00
|
|
|
#define _mref_check(mref) \
|
|
|
|
({ \
|
|
|
|
if (unlikely(BRICK_CHECKING && !(mref)->ref_initialized)) { \
|
|
|
|
MARS_ERR("mref %p is not initialized\n", (mref)); \
|
|
|
|
} \
|
|
|
|
CHECK_TATOMIC(&(mref)->ref_at, &(mref)->ref_count, 1); \
|
|
|
|
})
|
|
|
|
|
|
|
|
#define _mref_get_first(mref) \
|
|
|
|
({ \
|
|
|
|
if (unlikely(BRICK_CHECKING && (mref)->ref_initialized)) { \
|
|
|
|
MARS_ERR("mref %p is already initialized\n", (mref)); \
|
|
|
|
} \
|
2013-04-12 08:55:51 +00:00
|
|
|
_CHECK_TATOMIC(&(mref)->ref_at, &(mref)->ref_count, !=, 0, 0); \
|
2012-12-10 09:31:28 +00:00
|
|
|
(mref)->ref_initialized = true; \
|
|
|
|
tatomic_inc(&(mref)->ref_at, &(mref)->ref_count); \
|
|
|
|
})
|
|
|
|
|
|
|
|
#define _mref_get(mref) \
|
|
|
|
({ \
|
|
|
|
_mref_check(mref); \
|
|
|
|
tatomic_inc(&(mref)->ref_at, &(mref)->ref_count); \
|
|
|
|
})
|
|
|
|
|
|
|
|
#define _mref_put(mref) \
|
|
|
|
({ \
|
|
|
|
_mref_check(mref); \
|
|
|
|
tatomic_dec_and_test(&(mref)->ref_at, &(mref)->ref_count); \
|
|
|
|
})
|
|
|
|
|
2010-07-07 14:09:16 +00:00
|
|
|
// internal helper structs
|
|
|
|
|
|
|
|
struct mars_info {
|
|
|
|
loff_t current_size;
|
2013-04-16 08:01:45 +00:00
|
|
|
int tf_align; // transfer alignment constraint
|
|
|
|
int tf_min_size; // transfer is only possible in multiples of this
|
2010-07-07 14:09:16 +00:00
|
|
|
};
|
|
|
|
|
2010-06-20 18:55:34 +00:00
|
|
|
// brick stuff
|
|
|
|
|
2012-01-30 11:54:27 +00:00
|
|
|
#define MARS_BRICK(BRITYPE) \
|
|
|
|
GENERIC_BRICK(BRITYPE); \
|
2012-02-02 15:25:43 +00:00
|
|
|
struct generic_object_layout mref_object_layout; \
|
2011-03-01 09:34:36 +00:00
|
|
|
struct list_head global_brick_link; \
|
|
|
|
struct list_head dent_brick_link; \
|
2011-02-23 20:48:06 +00:00
|
|
|
const char *brick_path; \
|
|
|
|
struct mars_global *global; \
|
2019-02-19 09:18:29 +00:00
|
|
|
struct lamport_time create_stamp; \
|
2020-01-27 11:03:03 +00:00
|
|
|
struct lamport_time kill_stamp; \
|
2014-02-03 08:19:14 +00:00
|
|
|
void **kill_ptr; \
|
2015-02-10 09:45:40 +00:00
|
|
|
int *mode_ptr; \
|
2013-05-09 19:55:23 +00:00
|
|
|
int kill_round; \
|
2013-01-22 11:10:12 +00:00
|
|
|
bool killme; \
|
2010-06-14 14:27:40 +00:00
|
|
|
|
|
|
|
struct mars_brick {
|
|
|
|
MARS_BRICK(mars);
|
|
|
|
};
|
|
|
|
|
2012-01-30 11:54:27 +00:00
|
|
|
#define MARS_INPUT(BRITYPE) \
|
|
|
|
GENERIC_INPUT(BRITYPE); \
|
2010-06-14 14:27:40 +00:00
|
|
|
|
|
|
|
struct mars_input {
|
|
|
|
MARS_INPUT(mars);
|
|
|
|
};
|
|
|
|
|
2012-01-30 11:54:27 +00:00
|
|
|
#define MARS_OUTPUT(BRITYPE) \
|
|
|
|
GENERIC_OUTPUT(BRITYPE); \
|
2010-06-14 14:27:40 +00:00
|
|
|
|
|
|
|
struct mars_output {
|
|
|
|
MARS_OUTPUT(mars);
|
|
|
|
};
|
|
|
|
|
2012-01-30 11:54:27 +00:00
|
|
|
#define MARS_BRICK_OPS(BRITYPE) \
|
|
|
|
GENERIC_BRICK_OPS(BRITYPE); \
|
|
|
|
char *(*brick_statistics)(struct BRITYPE##_brick *brick, int verbose); \
|
|
|
|
void (*reset_statistics)(struct BRITYPE##_brick *brick); \
|
2010-06-28 05:53:46 +00:00
|
|
|
|
2012-01-30 11:54:27 +00:00
|
|
|
#define MARS_OUTPUT_OPS(BRITYPE) \
|
|
|
|
GENERIC_OUTPUT_OPS(BRITYPE); \
|
|
|
|
int (*mars_get_info)(struct BRITYPE##_output *output, struct mars_info *info); \
|
2010-12-15 12:13:18 +00:00
|
|
|
/* mref */ \
|
2012-01-30 11:54:27 +00:00
|
|
|
int (*mref_get)(struct BRITYPE##_output *output, struct mref_object *mref); \
|
|
|
|
void (*mref_io)(struct BRITYPE##_output *output, struct mref_object *mref); \
|
|
|
|
void (*mref_put)(struct BRITYPE##_output *output, struct mref_object *mref); \
|
2010-06-14 14:27:40 +00:00
|
|
|
|
|
|
|
// all non-extendable types
|
2010-07-30 11:50:20 +00:00
|
|
|
|
2012-01-30 11:54:27 +00:00
|
|
|
#define _MARS_TYPES(BRITYPE) \
|
2010-07-30 11:50:20 +00:00
|
|
|
\
|
2012-01-30 11:54:27 +00:00
|
|
|
struct BRITYPE##_brick_ops { \
|
|
|
|
MARS_BRICK_OPS(BRITYPE); \
|
2010-08-04 22:38:48 +00:00
|
|
|
}; \
|
|
|
|
\
|
2012-01-30 11:54:27 +00:00
|
|
|
struct BRITYPE##_output_ops { \
|
|
|
|
MARS_OUTPUT_OPS(BRITYPE); \
|
2010-08-04 22:38:48 +00:00
|
|
|
}; \
|
2010-06-28 05:53:46 +00:00
|
|
|
\
|
2012-01-30 11:54:27 +00:00
|
|
|
struct BRITYPE##_brick_type { \
|
|
|
|
GENERIC_BRICK_TYPE(BRITYPE); \
|
2010-06-28 05:53:46 +00:00
|
|
|
}; \
|
|
|
|
\
|
2012-01-30 11:54:27 +00:00
|
|
|
struct BRITYPE##_input_type { \
|
|
|
|
GENERIC_INPUT_TYPE(BRITYPE); \
|
2010-06-28 05:53:46 +00:00
|
|
|
}; \
|
|
|
|
\
|
2012-01-30 11:54:27 +00:00
|
|
|
struct BRITYPE##_output_type { \
|
|
|
|
GENERIC_OUTPUT_TYPE(BRITYPE); \
|
2010-06-28 05:53:46 +00:00
|
|
|
}; \
|
2010-08-04 22:38:48 +00:00
|
|
|
\
|
2012-01-30 11:54:27 +00:00
|
|
|
struct BRITYPE##_callback { \
|
|
|
|
GENERIC_CALLBACK(BRITYPE); \
|
2010-08-08 14:02:54 +00:00
|
|
|
}; \
|
|
|
|
\
|
2012-01-30 11:54:27 +00:00
|
|
|
DECLARE_BRICK_FUNCTIONS(BRITYPE); \
|
2010-06-28 05:53:46 +00:00
|
|
|
|
2010-07-23 11:55:18 +00:00
|
|
|
|
2012-01-30 11:54:27 +00:00
|
|
|
#define MARS_TYPES(BRITYPE) \
|
2010-07-30 11:50:20 +00:00
|
|
|
\
|
2012-01-30 11:54:27 +00:00
|
|
|
_MARS_TYPES(BRITYPE) \
|
2010-07-30 11:50:20 +00:00
|
|
|
\
|
2012-01-30 11:54:27 +00:00
|
|
|
DECLARE_ASPECT_FUNCTIONS(BRITYPE,mref); \
|
|
|
|
extern int init_mars_##BRITYPE(void); \
|
|
|
|
extern void exit_mars_##BRITYPE(void);
|
2010-07-23 11:55:18 +00:00
|
|
|
|
|
|
|
|
2010-12-15 11:58:22 +00:00
|
|
|
// instantiate a pseudo base-class "mars"
|
|
|
|
|
|
|
|
_MARS_TYPES(mars);
|
2012-01-30 11:54:27 +00:00
|
|
|
DECLARE_ASPECT_FUNCTIONS(mars,mref);
|
2010-12-15 11:58:22 +00:00
|
|
|
|
2010-06-14 14:27:40 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2010-12-15 11:58:22 +00:00
|
|
|
// MARS-specific helpers
|
2010-06-14 14:27:40 +00:00
|
|
|
|
2012-01-30 11:54:27 +00:00
|
|
|
#define MARS_MAKE_STATICS(BRITYPE) \
|
2010-07-23 11:55:18 +00:00
|
|
|
\
|
2012-01-30 11:54:27 +00:00
|
|
|
int BRITYPE##_brick_nr = -EEXIST; \
|
|
|
|
EXPORT_SYMBOL_GPL(BRITYPE##_brick_nr); \
|
2010-07-23 11:55:18 +00:00
|
|
|
\
|
2012-01-30 11:54:27 +00:00
|
|
|
static const struct generic_aspect_type BRITYPE##_mref_aspect_type = { \
|
|
|
|
.aspect_type_name = #BRITYPE "_mref_aspect_type", \
|
2010-12-15 12:13:18 +00:00
|
|
|
.object_type = &mref_type, \
|
2012-01-30 11:54:27 +00:00
|
|
|
.aspect_size = sizeof(struct BRITYPE##_mref_aspect), \
|
|
|
|
.init_fn = BRITYPE##_mref_aspect_init_fn, \
|
|
|
|
.exit_fn = BRITYPE##_mref_aspect_exit_fn, \
|
2010-07-23 11:55:18 +00:00
|
|
|
}; \
|
|
|
|
\
|
2012-01-30 11:54:27 +00:00
|
|
|
static const struct generic_aspect_type *BRITYPE##_aspect_types[OBJ_TYPE_MAX] = { \
|
|
|
|
[OBJ_TYPE_MREF] = &BRITYPE##_mref_aspect_type, \
|
2010-07-23 11:55:18 +00:00
|
|
|
}; \
|
2010-07-30 11:50:20 +00:00
|
|
|
|
2011-08-25 10:16:32 +00:00
|
|
|
extern const struct meta mars_info_meta[];
|
|
|
|
extern const struct meta mars_mref_meta[];
|
2019-02-19 09:18:29 +00:00
|
|
|
extern const struct meta mars_lamport_time_meta[];
|
2011-08-25 10:16:32 +00:00
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2011-07-22 10:43:40 +00:00
|
|
|
#ifdef _STRATEGY
|
|
|
|
#include "sy_old/strategy.h"
|
|
|
|
#endif
|
2011-02-23 20:48:06 +00:00
|
|
|
|
2011-11-04 15:43:23 +00:00
|
|
|
extern void mars_power_led_on(struct mars_brick *brick, bool val);
|
|
|
|
extern void mars_power_led_off(struct mars_brick *brick, bool val);
|
2020-06-14 10:42:22 +00:00
|
|
|
|
2011-07-22 10:43:40 +00:00
|
|
|
/* this should disappear!
|
|
|
|
*/
|
2020-06-14 10:42:22 +00:00
|
|
|
enum mars_trigger_mode {
|
|
|
|
_MARS_TRIGGER_LOCAL,
|
|
|
|
_MARS_TRIGGER_FROM_REMOTE,
|
|
|
|
_MARS_TRIGGER_TO_REMOTE,
|
|
|
|
_MARS_TRIGGER_TO_REMOTE_ALL,
|
|
|
|
_MARS_TRIGGER_FULL,
|
2022-03-28 14:18:41 +00:00
|
|
|
} __packed;
|
2020-06-14 10:42:22 +00:00
|
|
|
|
|
|
|
#define MARS_TRIGGER_LOCAL (1 << _MARS_TRIGGER_LOCAL)
|
|
|
|
#define MARS_TRIGGER_FROM_REMOTE (1 << _MARS_TRIGGER_FROM_REMOTE)
|
|
|
|
#define MARS_TRIGGER_TO_REMOTE (1 << _MARS_TRIGGER_TO_REMOTE)
|
|
|
|
#define MARS_TRIGGER_TO_REMOTE_ALL (1 << _MARS_TRIGGER_TO_REMOTE_ALL)
|
|
|
|
#define MARS_TRIGGER_FULL (1 << _MARS_TRIGGER_FULL)
|
|
|
|
|
|
|
|
void mars_remote_trigger(int code);
|
|
|
|
|
|
|
|
void __mars_trigger(int code);
|
2020-02-26 10:24:37 +00:00
|
|
|
#define mars_trigger() \
|
2020-06-14 10:42:22 +00:00
|
|
|
__mars_trigger(MARS_TRIGGER_LOCAL)
|
2011-02-27 14:17:58 +00:00
|
|
|
|
2011-02-23 20:48:06 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-10-15 14:35:36 +00:00
|
|
|
/* Some global stuff.
|
|
|
|
*/
|
|
|
|
|
|
|
|
extern struct banning mars_global_ban;
|
|
|
|
|
2012-11-16 11:43:10 +00:00
|
|
|
extern atomic_t mars_global_io_flying;
|
|
|
|
|
2013-09-26 09:09:35 +00:00
|
|
|
extern int mars_throttle_start;
|
|
|
|
extern int mars_throttle_end;
|
|
|
|
|
2012-10-15 14:35:36 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2011-03-01 18:00:14 +00:00
|
|
|
/* Some special brick types for avoidance of cyclic references.
|
|
|
|
*
|
|
|
|
* The client/server network bricks use this for independent instantiation
|
|
|
|
* from the main instantiation logic (separate modprobe for mars_server
|
|
|
|
* is possible).
|
|
|
|
*/
|
2011-03-03 09:02:10 +00:00
|
|
|
extern const struct generic_brick_type *_client_brick_type;
|
2011-03-18 13:15:40 +00:00
|
|
|
extern const struct generic_brick_type *_bio_brick_type;
|
2011-03-03 09:02:10 +00:00
|
|
|
extern const struct generic_brick_type *_aio_brick_type;
|
2011-11-14 13:12:33 +00:00
|
|
|
extern const struct generic_brick_type *_sio_brick_type;
|
2011-03-01 18:00:14 +00:00
|
|
|
|
2021-01-25 14:44:33 +00:00
|
|
|
#if !defined(CONFIG_MARS_PREFER_SIO) && (defined(MARS_HAS_PREPATCH) || defined(MARS_HAS_PREPATCH_V2))
|
2016-08-26 07:04:02 +00:00
|
|
|
#define ENABLE_MARS_AIO
|
|
|
|
#endif
|
2011-11-14 17:24:47 +00:00
|
|
|
|
2016-08-26 07:04:02 +00:00
|
|
|
#ifdef ENABLE_MARS_AIO
|
2011-03-02 09:30:56 +00:00
|
|
|
/* Kludge: our kernel threads will have no mm context, but need one
|
|
|
|
* for stuff like ioctx_alloc() / aio_setup_ring() etc
|
|
|
|
* which expect userspace resources.
|
|
|
|
* We fake one.
|
|
|
|
* TODO: factor out the userspace stuff from AIO such that
|
|
|
|
* this fake is no longer necessary.
|
|
|
|
* Even better: replace do_mmap() in AIO stuff by something
|
|
|
|
* more friendly to kernelspace apps.
|
|
|
|
*/
|
|
|
|
#include <linux/mmu_context.h>
|
|
|
|
|
|
|
|
extern struct mm_struct *mm_fake;
|
2013-01-14 20:02:24 +00:00
|
|
|
extern struct task_struct *mm_fake_task;
|
|
|
|
extern atomic_t mm_fake_count;
|
2011-03-02 09:30:56 +00:00
|
|
|
|
2011-08-25 10:16:32 +00:00
|
|
|
static inline void set_fake(void)
|
2011-03-02 09:30:56 +00:00
|
|
|
{
|
2011-08-25 10:16:32 +00:00
|
|
|
mm_fake = current->mm;
|
|
|
|
if (mm_fake) {
|
2013-01-14 20:02:24 +00:00
|
|
|
MARS_DBG("initialized fake\n");
|
|
|
|
mm_fake_task = current;
|
|
|
|
get_task_struct(current); // paired with put_task_struct()
|
|
|
|
atomic_inc(&mm_fake->mm_count); // paired with mmdrop()
|
|
|
|
atomic_inc(&mm_fake->mm_users); // paired with mmput()
|
2011-08-25 10:16:32 +00:00
|
|
|
}
|
2011-03-02 09:30:56 +00:00
|
|
|
}
|
|
|
|
|
2011-08-25 10:16:32 +00:00
|
|
|
static inline void put_fake(void)
|
2011-03-02 09:30:56 +00:00
|
|
|
{
|
2013-01-14 20:02:24 +00:00
|
|
|
if (mm_fake && mm_fake_task) {
|
|
|
|
int remain = atomic_read(&mm_fake_count);
|
|
|
|
if (unlikely(remain != 0)) {
|
|
|
|
MARS_ERR("cannot cleanup fake, remain = %d\n", remain);
|
|
|
|
} else {
|
|
|
|
MARS_DBG("cleaning up fake\n");
|
|
|
|
mmput(mm_fake);
|
|
|
|
mmdrop(mm_fake);
|
|
|
|
mm_fake = NULL;
|
|
|
|
put_task_struct(mm_fake_task);
|
|
|
|
mm_fake_task = NULL;
|
|
|
|
}
|
2011-08-25 10:16:32 +00:00
|
|
|
}
|
2011-03-02 09:30:56 +00:00
|
|
|
}
|
|
|
|
|
2011-08-25 10:16:32 +00:00
|
|
|
static inline void use_fake_mm(void)
|
2011-03-02 09:30:56 +00:00
|
|
|
{
|
2011-08-25 10:16:32 +00:00
|
|
|
if (!current->mm && mm_fake) {
|
2013-01-14 20:02:24 +00:00
|
|
|
atomic_inc(&mm_fake_count);
|
|
|
|
MARS_DBG("using fake, count=%d\n", atomic_read(&mm_fake_count));
|
2011-08-25 10:16:32 +00:00
|
|
|
use_mm(mm_fake);
|
2011-03-02 09:30:56 +00:00
|
|
|
}
|
|
|
|
}
|
2011-08-25 10:16:32 +00:00
|
|
|
|
2011-03-02 09:30:56 +00:00
|
|
|
/* Cleanup faked mm, otherwise do_exit() will crash
|
|
|
|
*/
|
2011-08-25 10:16:32 +00:00
|
|
|
static inline void unuse_fake_mm(void)
|
2011-03-02 09:30:56 +00:00
|
|
|
{
|
2011-08-25 10:16:32 +00:00
|
|
|
if (current->mm == mm_fake && mm_fake) {
|
2013-01-14 20:02:24 +00:00
|
|
|
MARS_DBG("unusing fake, count=%d\n", atomic_read(&mm_fake_count));
|
|
|
|
atomic_dec(&mm_fake_count);
|
2011-08-25 10:16:32 +00:00
|
|
|
unuse_mm(mm_fake);
|
2013-01-14 20:02:24 +00:00
|
|
|
current->mm = NULL;
|
2011-03-02 09:30:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-14 17:24:47 +00:00
|
|
|
#else
|
|
|
|
static inline void set_fake(void) {}
|
|
|
|
static inline void put_fake(void) {}
|
|
|
|
static inline void use_fake_mm(void) {}
|
|
|
|
static inline void unuse_fake_mm(void) {}
|
|
|
|
#endif
|
|
|
|
|
2011-08-25 10:16:32 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2019-03-26 09:57:33 +00:00
|
|
|
/* Crypto / digest stuff
|
2012-08-01 10:01:13 +00:00
|
|
|
*/
|
|
|
|
|
2019-07-25 08:27:43 +00:00
|
|
|
#define MARS_MAX_COMPR_SIZE (PAGE_SIZE * 8)
|
|
|
|
|
2019-03-26 09:57:33 +00:00
|
|
|
extern __u32 available_digest_mask;
|
|
|
|
extern __u32 usable_digest_mask;
|
|
|
|
extern __u32 used_log_digest;
|
|
|
|
extern __u32 used_net_digest;
|
|
|
|
|
|
|
|
extern __u32 disabled_log_digests;
|
|
|
|
extern __u32 disabled_net_digests;
|
|
|
|
|
2022-02-24 10:07:53 +00:00
|
|
|
extern long mars_digest(__u32 digest_flags,
|
2019-03-26 09:57:33 +00:00
|
|
|
__u32 *used_flags,
|
|
|
|
void *digest,
|
2020-04-30 06:16:53 +00:00
|
|
|
const void *data, int len);
|
2019-03-26 09:57:33 +00:00
|
|
|
|
2012-08-01 10:09:49 +00:00
|
|
|
extern void mref_checksum(struct mref_object *mref);
|
2012-08-01 10:01:13 +00:00
|
|
|
|
2019-07-25 06:55:17 +00:00
|
|
|
/*******************************************************************/
|
|
|
|
|
|
|
|
/* compression stuff */
|
|
|
|
|
|
|
|
#define MARS_MAX_COMPR_SIZE (PAGE_SIZE * 8)
|
|
|
|
|
|
|
|
extern int compress_overhead;
|
|
|
|
|
|
|
|
extern __u32 available_compression_mask;
|
|
|
|
extern __u32 usable_compression_mask;
|
|
|
|
|
2020-03-29 16:17:48 +00:00
|
|
|
extern int mars_zlib_compression_level;
|
|
|
|
|
2019-07-25 06:55:17 +00:00
|
|
|
extern int mars_compress(void *src_data,
|
|
|
|
int src_len,
|
|
|
|
void *dst_data,
|
|
|
|
int dst_len,
|
|
|
|
__u32 check_flags,
|
|
|
|
__u32 *result_flags);
|
|
|
|
|
|
|
|
void *mars_decompress(void *src_data,
|
|
|
|
int src_len,
|
|
|
|
void *dst_data,
|
|
|
|
int dst_len,
|
|
|
|
__u32 check_flags);
|
|
|
|
|
2012-08-01 10:01:13 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-02-06 22:35:04 +00:00
|
|
|
/* Crash-testing instrumentation.
|
|
|
|
* Only for debugging. Never use this for production.
|
|
|
|
* Simulate a crash at the "wrong moment".
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef CONFIG_MARS_DEBUG
|
|
|
|
extern int mars_crash_mode;
|
2016-08-08 11:47:25 +00:00
|
|
|
extern int mars_hang_mode;
|
2016-02-06 22:35:04 +00:00
|
|
|
extern void _crashme(int mode, bool do_sync);
|
|
|
|
#else
|
|
|
|
extern inline void _crashme(int mode, bool do_sync) {}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2011-08-25 10:16:32 +00:00
|
|
|
// init
|
|
|
|
|
|
|
|
extern int init_mars(void);
|
|
|
|
extern void exit_mars(void);
|
|
|
|
|
2011-02-23 20:48:06 +00:00
|
|
|
#endif
|