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-07-23 11:55:18 +00:00
|
|
|
#define BRICK_OBJ_MARS_IO 0
|
|
|
|
#define BRICK_OBJ_MARS_BUF 1
|
2010-07-30 11:50:20 +00:00
|
|
|
#define BRICK_OBJ_NR 2
|
2010-06-14 14:27:40 +00:00
|
|
|
|
2010-08-04 17:32:04 +00:00
|
|
|
#define GFP_MARS GFP_ATOMIC
|
|
|
|
|
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-07-05 15:56:58 +00:00
|
|
|
/* mars_io */
|
2010-07-23 11:55:18 +00:00
|
|
|
|
2010-06-20 18:55:34 +00:00
|
|
|
extern const struct generic_object_type mars_io_type;
|
|
|
|
|
|
|
|
struct mars_io_aspect {
|
|
|
|
GENERIC_ASPECT(mars_io);
|
|
|
|
};
|
|
|
|
|
2010-06-22 13:21:42 +00:00
|
|
|
struct mars_io_aspect_layout {
|
|
|
|
GENERIC_ASPECT_LAYOUT(mars_io);
|
|
|
|
};
|
|
|
|
|
2010-06-20 18:55:34 +00:00
|
|
|
struct mars_io_object_layout {
|
|
|
|
GENERIC_OBJECT_LAYOUT(mars_io);
|
|
|
|
};
|
|
|
|
|
2010-06-28 05:53:46 +00:00
|
|
|
#define MARS_IO_OBJECT(PREFIX) \
|
|
|
|
GENERIC_OBJECT(PREFIX); \
|
|
|
|
struct bio *orig_bio; \
|
2010-07-30 05:46:22 +00:00
|
|
|
int (*mars_endio)(struct mars_io_object *mio, int error); \
|
2010-08-03 16:03:32 +00:00
|
|
|
void *cb_private; \
|
2010-06-14 14:27:40 +00:00
|
|
|
|
2010-06-20 18:55:34 +00:00
|
|
|
struct mars_io_object {
|
|
|
|
MARS_IO_OBJECT(mars_io);
|
2010-06-14 14:27:40 +00:00
|
|
|
};
|
|
|
|
|
2010-07-05 15:56:58 +00:00
|
|
|
/* mars_buf */
|
2010-07-23 11:55:18 +00:00
|
|
|
|
2010-07-07 14:09:16 +00:00
|
|
|
#define MARS_BUF_UPTODATE 1
|
|
|
|
#define MARS_BUF_READING 2
|
|
|
|
#define MARS_BUF_WRITING 4
|
2010-07-05 15:56:58 +00:00
|
|
|
|
2010-07-23 11:55:18 +00:00
|
|
|
extern const struct generic_object_type mars_buf_type;
|
2010-07-05 15:56:58 +00:00
|
|
|
|
|
|
|
struct mars_buf_aspect {
|
|
|
|
GENERIC_ASPECT(mars_buf);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct mars_buf_aspect_layout {
|
|
|
|
GENERIC_ASPECT_LAYOUT(mars_buf);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct mars_buf_object_layout {
|
|
|
|
GENERIC_OBJECT_LAYOUT(mars_buf);
|
|
|
|
};
|
|
|
|
|
|
|
|
#define MARS_BUF_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-07-05 15:56:58 +00:00
|
|
|
loff_t buf_pos; \
|
2010-08-02 16:31:10 +00:00
|
|
|
int buf_len; \
|
|
|
|
int buf_may_write; \
|
|
|
|
/* maintained by the buf implementation, readable for callers */ \
|
2010-08-04 17:32:04 +00:00
|
|
|
struct bio *orig_bio; \
|
2010-08-02 16:31:10 +00:00
|
|
|
void *buf_data; \
|
|
|
|
int buf_flags; \
|
|
|
|
int buf_rw; \
|
|
|
|
/* maintained by the buf implementation, incrementable for \
|
|
|
|
* callers (but not decrementable! use buf_put()) */ \
|
|
|
|
atomic_t buf_count; \
|
2010-07-30 11:50:20 +00:00
|
|
|
/* callback part */ \
|
2010-08-02 16:31:10 +00:00
|
|
|
int cb_error; \
|
|
|
|
void *cb_private; \
|
2010-08-03 09:38:12 +00:00
|
|
|
void (*cb_buf_endio)(struct mars_buf_object *mbuf); \
|
2010-07-23 11:55:18 +00:00
|
|
|
|
2010-07-30 11:50:20 +00:00
|
|
|
struct mars_buf_object {
|
|
|
|
MARS_BUF_OBJECT(mars_buf);
|
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-07-05 15:56:58 +00:00
|
|
|
/* mars_io */ \
|
2010-08-03 09:38:12 +00:00
|
|
|
int (*mars_io)(struct PREFIX##_output *output, struct mars_io_object *mio); \
|
|
|
|
int (*mars_get_info)(struct PREFIX##_output *output, struct mars_info *info); \
|
2010-07-05 15:56:58 +00:00
|
|
|
/* mars_buf */ \
|
2010-08-03 09:38:12 +00:00
|
|
|
int (*mars_buf_get)(struct PREFIX##_output *output, struct mars_buf_object *mbuf); \
|
|
|
|
void (*mars_buf_io)(struct PREFIX##_output *output, struct mars_buf_object *mbuf, int rw); \
|
|
|
|
void (*mars_buf_put)(struct PREFIX##_output *output, struct mars_buf_object *mbuf); \
|
2010-06-14 14:27:40 +00:00
|
|
|
|
|
|
|
// all non-extendable types
|
2010-07-30 11:50:20 +00:00
|
|
|
|
|
|
|
#define _MARS_TYPES(BRICK) \
|
|
|
|
\
|
|
|
|
struct BRICK##_brick_ops { \
|
|
|
|
MARS_BRICK_OPS(BRICK); \
|
2010-06-28 05:53:46 +00:00
|
|
|
}; \
|
|
|
|
\
|
2010-07-30 11:50:20 +00:00
|
|
|
struct BRICK##_output_ops { \
|
|
|
|
MARS_OUTPUT_OPS(BRICK); \
|
2010-06-28 05:53:46 +00:00
|
|
|
}; \
|
|
|
|
\
|
2010-07-30 11:50:20 +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 { \
|
|
|
|
GENERIC_INPUT_TYPE(BRICK); \
|
2010-06-28 05:53:46 +00:00
|
|
|
}; \
|
|
|
|
\
|
2010-07-30 11:50:20 +00:00
|
|
|
struct BRICK##_output_type { \
|
|
|
|
GENERIC_OUTPUT_TYPE(BRICK); \
|
2010-06-28 05:53:46 +00:00
|
|
|
}; \
|
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); \
|
|
|
|
GENERIC_MAKE_CONNECT(mars,BRICK); \
|
2010-08-01 20:21:18 +00:00
|
|
|
GENERIC_OBJECT_LAYOUT_FUNCTIONS(BRICK); \
|
2010-07-30 11:50:20 +00:00
|
|
|
GENERIC_ASPECT_LAYOUT_FUNCTIONS(BRICK,mars_io); \
|
|
|
|
GENERIC_ASPECT_LAYOUT_FUNCTIONS(BRICK,mars_buf); \
|
|
|
|
GENERIC_ASPECT_FUNCTIONS(BRICK,mars_io); \
|
|
|
|
GENERIC_ASPECT_FUNCTIONS(BRICK,mars_buf); \
|
2010-07-23 11:55:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
// instantiate all mars-specific functions
|
|
|
|
|
2010-07-30 05:46:22 +00:00
|
|
|
//GENERIC_ASPECT_LAYOUT_FUNCTIONS(mars,mars_io);
|
|
|
|
//GENERIC_ASPECT_LAYOUT_FUNCTIONS(mars,mars_buf);
|
2010-07-23 11:55:18 +00:00
|
|
|
|
|
|
|
GENERIC_OBJECT_FUNCTIONS(mars_io);
|
|
|
|
GENERIC_OBJECT_FUNCTIONS(mars_buf);
|
|
|
|
|
2010-08-01 20:21:18 +00:00
|
|
|
//GENERIC_ASPECT_FUNCTIONS(mars,mars_io);
|
|
|
|
//GENERIC_ASPECT_FUNCTIONS(mars,mars_buf);
|
2010-06-14 14:27:40 +00:00
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// MARS-specific helper functions
|
|
|
|
|
|
|
|
_MARS_TYPES(mars);
|
|
|
|
GENERIC_MAKE_CONNECT(generic,mars);
|
|
|
|
|
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-07-30 11:50:20 +00:00
|
|
|
static const struct generic_aspect_type BRICK##_mars_io_aspect_type = { \
|
|
|
|
.aspect_type_name = #BRICK "_mars_io_aspect_type", \
|
2010-07-30 05:46:22 +00:00
|
|
|
.object_type = &mars_io_type, \
|
2010-07-30 11:50:20 +00:00
|
|
|
.aspect_size = sizeof(struct BRICK##_mars_io_aspect), \
|
|
|
|
.init_fn = BRICK##_mars_io_aspect_init_fn, \
|
2010-07-23 11:55:18 +00:00
|
|
|
}; \
|
|
|
|
\
|
2010-07-30 11:50:20 +00:00
|
|
|
static const struct generic_aspect_type BRICK##_mars_buf_aspect_type = { \
|
|
|
|
.aspect_type_name = #BRICK "_mars_buf_aspect_type", \
|
2010-07-30 05:46:22 +00:00
|
|
|
.object_type = &mars_buf_type, \
|
2010-07-30 11:50:20 +00:00
|
|
|
.aspect_size = sizeof(struct BRICK##_mars_buf_aspect), \
|
|
|
|
.init_fn = BRICK##_mars_buf_aspect_init_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] = { \
|
|
|
|
[BRICK_OBJ_MARS_IO] = &BRICK##_mars_io_aspect_type, \
|
|
|
|
[BRICK_OBJ_MARS_BUF] = &BRICK##_mars_buf_aspect_type, \
|
2010-07-23 11:55:18 +00:00
|
|
|
}; \
|
2010-07-30 11:50:20 +00:00
|
|
|
|
2010-08-04 17:32:04 +00:00
|
|
|
static inline void mars_buf_attach_bio(struct mars_buf_object *mbuf, struct bio *bio)
|
|
|
|
{
|
|
|
|
int test;
|
|
|
|
if (unlikely(mbuf->orig_bio)) {
|
|
|
|
MARS_ERR("attaching a bio twice!\n");
|
|
|
|
}
|
|
|
|
test = atomic_read(&mbuf->buf_count);
|
|
|
|
if (unlikely(test != 0)) {
|
|
|
|
MARS_ERR("bad buf_count %d\n", test);
|
|
|
|
}
|
|
|
|
mbuf->orig_bio = bio;
|
|
|
|
mbuf->buf_pos = -1;
|
|
|
|
atomic_set(&mbuf->buf_count, 1);
|
|
|
|
}
|
|
|
|
|
2010-06-14 14:27:40 +00:00
|
|
|
#endif
|