2010-06-14 14:27:40 +00:00
|
|
|
// (c) 2010 Thomas Schoebel-Theuer / 1&1 Internet AG
|
|
|
|
#ifndef MARS_H
|
|
|
|
#define MARS_H
|
|
|
|
|
|
|
|
#include <linux/list.h>
|
2010-07-30 11:50:20 +00:00
|
|
|
#include <asm/spinlock.h>
|
2010-07-23 11:55:18 +00:00
|
|
|
#include <asm/atomic.h>
|
2010-06-14 14:27:40 +00:00
|
|
|
|
2010-08-03 09:38:12 +00:00
|
|
|
#define MARS_FATAL "MARS_FATAL " __BASE_FILE__ ": "
|
2010-07-30 05:46:22 +00:00
|
|
|
#define MARS_ERROR "MARS_ERROR " __BASE_FILE__ ": "
|
|
|
|
#define MARS_INFO "MARS_INFO " __BASE_FILE__ ": "
|
|
|
|
#define MARS_DEBUG "MARS_DEBUG " __BASE_FILE__ ": "
|
2010-06-14 14:27:40 +00:00
|
|
|
|
2010-08-03 09:38:12 +00:00
|
|
|
#define MARS_FAT(fmt, args...) printk(MARS_FATAL "%s(): " fmt, __FUNCTION__, ##args)
|
2010-07-30 05:46:22 +00:00
|
|
|
#define MARS_ERR(fmt, args...) printk(MARS_ERROR "%s(): " fmt, __FUNCTION__, ##args)
|
|
|
|
#define MARS_INF(fmt, args...) printk(MARS_INFO "%s(): " fmt, __FUNCTION__, ##args)
|
2010-07-23 11:55:18 +00:00
|
|
|
#ifdef MARS_DEBUGGING
|
2010-07-30 05:46:22 +00:00
|
|
|
#define MARS_DBG(fmt, args...) printk(MARS_DEBUG "%s(): " fmt, __FUNCTION__, ##args)
|
2010-07-23 11:55:18 +00:00
|
|
|
#else
|
2010-06-16 13:21:30 +00:00
|
|
|
#define MARS_DBG(args...) /**/
|
2010-07-23 11:55:18 +00:00
|
|
|
#endif
|
2010-06-14 14:27:40 +00:00
|
|
|
|
2010-08-05 15:54:48 +00:00
|
|
|
#define BRICK_OBJ_MARS_REF 0
|
2010-08-04 22:38:48 +00:00
|
|
|
#define BRICK_OBJ_NR 1
|
2010-06-14 14:27:40 +00:00
|
|
|
|
2010-08-05 15:54:48 +00:00
|
|
|
#define GFP_MARS GFP_NOIO
|
2010-08-04 17:32:04 +00:00
|
|
|
|
2010-07-23 11:55:18 +00:00
|
|
|
#include "brick.h"
|
2010-06-14 14:27:40 +00:00
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// MARS-specific definitions
|
|
|
|
|
2010-06-20 18:55:34 +00:00
|
|
|
// object stuff
|
|
|
|
|
2010-08-05 15:54:48 +00:00
|
|
|
/* mars_ref */
|
2010-07-23 11:55:18 +00:00
|
|
|
|
2010-08-05 15:54:48 +00:00
|
|
|
#define MARS_REF_UPTODATE 1
|
|
|
|
#define MARS_REF_READING 2
|
|
|
|
#define MARS_REF_WRITING 4
|
2010-07-05 15:56:58 +00:00
|
|
|
|
2010-08-05 15:54:48 +00:00
|
|
|
extern const struct generic_object_type mars_ref_type;
|
2010-07-05 15:56:58 +00:00
|
|
|
|
2010-08-05 15:54:48 +00:00
|
|
|
struct mars_ref_aspect {
|
|
|
|
GENERIC_ASPECT(mars_ref);
|
2010-07-05 15:56:58 +00:00
|
|
|
};
|
|
|
|
|
2010-08-05 15:54:48 +00:00
|
|
|
struct mars_ref_aspect_layout {
|
|
|
|
GENERIC_ASPECT_LAYOUT(mars_ref);
|
2010-07-05 15:56:58 +00:00
|
|
|
};
|
|
|
|
|
2010-08-05 15:54:48 +00:00
|
|
|
struct mars_ref_object_layout {
|
|
|
|
GENERIC_OBJECT_LAYOUT(mars_ref);
|
2010-07-05 15:56:58 +00:00
|
|
|
};
|
|
|
|
|
2010-08-05 15:54:48 +00:00
|
|
|
#define MARS_REF_OBJECT(PREFIX) \
|
2010-07-23 11:55:18 +00:00
|
|
|
GENERIC_OBJECT(PREFIX); \
|
2010-08-02 16:31:10 +00:00
|
|
|
/* supplied by caller */ \
|
2010-08-05 15:54:48 +00:00
|
|
|
loff_t ref_pos; \
|
|
|
|
int ref_len; \
|
|
|
|
int ref_may_write; \
|
|
|
|
/* maintained by the ref implementation, readable for callers */ \
|
2010-08-04 17:32:04 +00:00
|
|
|
struct bio *orig_bio; \
|
2010-08-05 15:54:48 +00:00
|
|
|
void *ref_data; \
|
|
|
|
int ref_flags; \
|
|
|
|
int ref_rw; \
|
|
|
|
/* maintained by the ref implementation, incrementable for \
|
|
|
|
* callers (but not decrementable! use ref_put()) */ \
|
|
|
|
atomic_t ref_count; \
|
2010-07-30 11:50:20 +00:00
|
|
|
/* callback part */ \
|
2010-08-08 14:02:54 +00:00
|
|
|
struct generic_callback *ref_cb; \
|
2010-07-23 11:55:18 +00:00
|
|
|
|
2010-08-05 15:54:48 +00:00
|
|
|
struct mars_ref_object {
|
|
|
|
MARS_REF_OBJECT(mars_ref);
|
2010-07-23 11:55:18 +00:00
|
|
|
};
|
2010-06-20 18:55:34 +00:00
|
|
|
|
2010-07-07 14:09:16 +00:00
|
|
|
// internal helper structs
|
|
|
|
|
|
|
|
struct mars_info {
|
|
|
|
loff_t current_size;
|
|
|
|
struct file *backing_file;
|
|
|
|
};
|
|
|
|
|
2010-06-20 18:55:34 +00:00
|
|
|
// brick stuff
|
|
|
|
|
2010-06-28 05:53:46 +00:00
|
|
|
#define MARS_BRICK(PREFIX) \
|
|
|
|
GENERIC_BRICK(PREFIX); \
|
2010-06-14 14:27:40 +00:00
|
|
|
|
|
|
|
struct mars_brick {
|
|
|
|
MARS_BRICK(mars);
|
|
|
|
};
|
|
|
|
|
2010-06-28 05:53:46 +00:00
|
|
|
#define MARS_INPUT(PREFIX) \
|
|
|
|
GENERIC_INPUT(PREFIX); \
|
2010-06-14 14:27:40 +00:00
|
|
|
|
|
|
|
struct mars_input {
|
|
|
|
MARS_INPUT(mars);
|
|
|
|
};
|
|
|
|
|
2010-06-28 05:53:46 +00:00
|
|
|
#define MARS_OUTPUT(PREFIX) \
|
|
|
|
GENERIC_OUTPUT(PREFIX); \
|
2010-06-14 14:27:40 +00:00
|
|
|
|
|
|
|
struct mars_output {
|
|
|
|
MARS_OUTPUT(mars);
|
|
|
|
};
|
|
|
|
|
2010-06-28 05:53:46 +00:00
|
|
|
#define MARS_BRICK_OPS(PREFIX) \
|
|
|
|
GENERIC_BRICK_OPS(PREFIX); \
|
|
|
|
int (*mars_dummy_op)(int); \
|
|
|
|
|
|
|
|
#define MARS_OUTPUT_OPS(PREFIX) \
|
|
|
|
GENERIC_OUTPUT_OPS(PREFIX); \
|
2010-08-03 09:38:12 +00:00
|
|
|
int (*mars_get_info)(struct PREFIX##_output *output, struct mars_info *info); \
|
2010-08-05 15:54:48 +00:00
|
|
|
/* mars_ref */ \
|
|
|
|
int (*mars_ref_get)(struct PREFIX##_output *output, struct mars_ref_object *mref); \
|
|
|
|
void (*mars_ref_io)(struct PREFIX##_output *output, struct mars_ref_object *mref, int rw); \
|
|
|
|
void (*mars_ref_put)(struct PREFIX##_output *output, struct mars_ref_object *mref); \
|
2010-06-14 14:27:40 +00:00
|
|
|
|
|
|
|
// all non-extendable types
|
2010-07-30 11:50:20 +00:00
|
|
|
|
|
|
|
#define _MARS_TYPES(BRICK) \
|
|
|
|
\
|
2010-08-04 22:38:48 +00:00
|
|
|
struct BRICK##_brick_ops { \
|
|
|
|
MARS_BRICK_OPS(BRICK); \
|
|
|
|
}; \
|
|
|
|
\
|
2010-07-30 11:50:20 +00:00
|
|
|
struct BRICK##_output_ops { \
|
2010-08-04 22:38:48 +00:00
|
|
|
MARS_OUTPUT_OPS(BRICK); \
|
|
|
|
}; \
|
2010-06-28 05:53:46 +00:00
|
|
|
\
|
2010-08-04 22:38:48 +00:00
|
|
|
struct BRICK##_brick_type { \
|
|
|
|
GENERIC_BRICK_TYPE(BRICK); \
|
2010-06-28 05:53:46 +00:00
|
|
|
}; \
|
|
|
|
\
|
2010-07-30 11:50:20 +00:00
|
|
|
struct BRICK##_input_type { \
|
2010-08-04 22:38:48 +00:00
|
|
|
GENERIC_INPUT_TYPE(BRICK); \
|
2010-06-28 05:53:46 +00:00
|
|
|
}; \
|
|
|
|
\
|
2010-07-30 11:50:20 +00:00
|
|
|
struct BRICK##_output_type { \
|
2010-08-04 22:38:48 +00:00
|
|
|
GENERIC_OUTPUT_TYPE(BRICK); \
|
2010-06-28 05:53:46 +00:00
|
|
|
}; \
|
2010-08-04 22:38:48 +00:00
|
|
|
\
|
2010-08-08 14:02:54 +00:00
|
|
|
struct BRICK##_callback { \
|
|
|
|
GENERIC_CALLBACK(BRICK); \
|
|
|
|
}; \
|
|
|
|
\
|
2010-07-30 11:50:20 +00:00
|
|
|
GENERIC_MAKE_FUNCTIONS(BRICK); \
|
|
|
|
GENERIC_MAKE_CONNECT(BRICK,BRICK); \
|
2010-06-28 05:53:46 +00:00
|
|
|
|
2010-07-23 11:55:18 +00:00
|
|
|
|
2010-07-30 11:50:20 +00:00
|
|
|
#define MARS_TYPES(BRICK) \
|
|
|
|
\
|
|
|
|
_MARS_TYPES(BRICK) \
|
|
|
|
\
|
2010-08-01 20:21:18 +00:00
|
|
|
struct BRICK##_object_layout; \
|
|
|
|
\
|
2010-07-30 11:50:20 +00:00
|
|
|
GENERIC_MAKE_CONNECT(generic,BRICK); \
|
2010-08-01 20:21:18 +00:00
|
|
|
GENERIC_OBJECT_LAYOUT_FUNCTIONS(BRICK); \
|
2010-08-05 15:54:48 +00:00
|
|
|
GENERIC_ASPECT_LAYOUT_FUNCTIONS(BRICK,mars_ref); \
|
|
|
|
GENERIC_ASPECT_FUNCTIONS(BRICK,mars_ref); \
|
2010-07-23 11:55:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
// instantiate all mars-specific functions
|
|
|
|
|
2010-08-05 15:54:48 +00:00
|
|
|
GENERIC_OBJECT_FUNCTIONS(mars_ref);
|
2010-07-23 11:55:18 +00:00
|
|
|
|
2010-06-14 14:27:40 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// MARS-specific helper functions
|
|
|
|
|
2010-07-30 11:50:20 +00:00
|
|
|
#define MARS_MAKE_STATICS(BRICK) \
|
2010-07-23 11:55:18 +00:00
|
|
|
\
|
2010-07-30 11:50:20 +00:00
|
|
|
int BRICK##_brick_nr = -EEXIST; \
|
|
|
|
EXPORT_SYMBOL_GPL(BRICK##_brick_nr); \
|
2010-07-23 11:55:18 +00:00
|
|
|
\
|
2010-08-05 15:54:48 +00:00
|
|
|
static const struct generic_aspect_type BRICK##_mars_ref_aspect_type = { \
|
|
|
|
.aspect_type_name = #BRICK "_mars_ref_aspect_type", \
|
|
|
|
.object_type = &mars_ref_type, \
|
|
|
|
.aspect_size = sizeof(struct BRICK##_mars_ref_aspect), \
|
|
|
|
.init_fn = BRICK##_mars_ref_aspect_init_fn, \
|
2010-08-08 09:03:42 +00:00
|
|
|
.exit_fn = BRICK##_mars_ref_aspect_exit_fn, \
|
2010-07-23 11:55:18 +00:00
|
|
|
}; \
|
|
|
|
\
|
2010-07-30 11:50:20 +00:00
|
|
|
static const struct generic_aspect_type *BRICK##_aspect_types[BRICK_OBJ_NR] = { \
|
2010-08-05 15:54:48 +00:00
|
|
|
[BRICK_OBJ_MARS_REF] = &BRICK##_mars_ref_aspect_type, \
|
2010-07-23 11:55:18 +00:00
|
|
|
}; \
|
2010-07-30 11:50:20 +00:00
|
|
|
|
2010-08-08 09:03:42 +00:00
|
|
|
#define _CHECK_ATOMIC(atom,OP,minval) \
|
2010-08-05 15:54:48 +00:00
|
|
|
do { \
|
2010-08-08 09:03:42 +00:00
|
|
|
int test = atomic_read(atom); \
|
2010-08-05 15:54:48 +00:00
|
|
|
if (test OP (minval)) { \
|
2010-08-08 09:03:42 +00:00
|
|
|
atomic_set(atom, minval); \
|
|
|
|
MARS_ERR("line %d atom " #atom " " #OP " " #minval "\n", __LINE__); \
|
2010-08-05 15:54:48 +00:00
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
2010-08-08 09:03:42 +00:00
|
|
|
#define CHECK_ATOMIC(atom,minval) \
|
|
|
|
_CHECK_ATOMIC(atom, <, minval)
|
2010-08-05 15:54:48 +00:00
|
|
|
|
|
|
|
static inline void mars_ref_attach_bio(struct mars_ref_object *mref, struct bio *bio)
|
2010-08-04 17:32:04 +00:00
|
|
|
{
|
|
|
|
int test;
|
2010-08-05 15:54:48 +00:00
|
|
|
if (unlikely(mref->orig_bio)) {
|
2010-08-04 17:32:04 +00:00
|
|
|
MARS_ERR("attaching a bio twice!\n");
|
|
|
|
}
|
2010-08-05 15:54:48 +00:00
|
|
|
test = atomic_read(&mref->ref_count);
|
2010-08-04 17:32:04 +00:00
|
|
|
if (unlikely(test != 0)) {
|
2010-08-05 15:54:48 +00:00
|
|
|
MARS_ERR("bad ref_count %d\n", test);
|
2010-08-04 17:32:04 +00:00
|
|
|
}
|
2010-08-05 15:54:48 +00:00
|
|
|
mref->orig_bio = bio;
|
|
|
|
mref->ref_pos = -1;
|
|
|
|
atomic_set(&mref->ref_count, 1);
|
2010-08-04 17:32:04 +00:00
|
|
|
}
|
|
|
|
|
2010-08-08 09:03:42 +00:00
|
|
|
#define CHECK_HEAD_EMPTY(head) \
|
|
|
|
if (!list_empty(head)) { \
|
|
|
|
INIT_LIST_HEAD(head); \
|
|
|
|
MARS_ERR("list_head " #head " (%p) not empty\n", head); \
|
|
|
|
} \
|
|
|
|
|
2010-06-14 14:27:40 +00:00
|
|
|
#endif
|