infra: prepare simplification of flags

This commit is contained in:
Thomas Schoebel-Theuer 2019-03-14 13:44:16 +01:00 committed by Thomas Schoebel-Theuer
parent 00834a2370
commit af89dba044
5 changed files with 24 additions and 17 deletions

View File

@ -121,10 +121,6 @@
/* mref */
#define MREF_UPTODATE 1
#define MREF_READING 2
#define MREF_WRITING 4
extern const struct generic_object_type mref_type;
#ifdef MARS_TRACING
@ -151,6 +147,18 @@ extern void mars_log_trace(struct mref_object *mref);
#define mars_log_trace(mref) /*empty*/
#endif
enum _MREF_FLAGS {
/* New flags must always be appended */
/* Never change the position of an existing flag */
_MREF_UPTODATE,
_MREF_READING,
_MREF_WRITING,
};
#define MREF_UPTODATE (1UL << _MREF_UPTODATE)
#define MREF_READING (1UL << _MREF_READING)
#define MREF_WRITING (1UL << _MREF_WRITING)
#define MREF_OBJECT(OBJTYPE) \
CALLBACK_OBJECT(OBJTYPE); \
/* supplied by caller */ \
@ -161,10 +169,11 @@ extern void mars_log_trace(struct mref_object *mref);
int ref_prio; \
int ref_timeout; \
int ref_cs_mode; /* 0 = off, 1 = checksum + data, 2 = checksum only */ \
/* shared */ \
__u32 ref_flags; \
/* maintained by the ref implementation, readable for callers */ \
loff_t ref_total_size; /* just for info, need not be implemented */ \
unsigned char ref_checksum[16]; \
int ref_flags; \
int ref_rw; \
int ref_id; /* not mandatory; may be used for identification */ \
bool ref_skip_sync; /* skip sync for this particular mref */ \

View File

@ -551,7 +551,7 @@ again:
_mref_assign(bf, mref_a);
MARS_DBG("bf=%p index = %lld flags = %d\n", bf, bf->bf_base_index, bf->bf_flags);
MARS_DBG("bf=%p index = %lld flags = %x\n", bf, bf->bf_base_index, bf->bf_flags);
mref->ref_flags = bf->bf_flags;
mref->ref_data = bf->bf_data + base_offset;
@ -583,7 +583,7 @@ static void _buf_ref_put(struct buf_output *output, struct buf_mref_aspect *mref
if (!_mref_put(mref))
return;
MARS_DBG("buf_ref_put() mref=%p mref_a=%p bf=%p flags=%d\n", mref, mref_a, bf, bf->bf_flags);
MARS_DBG("buf_ref_put() mref=%p mref_a=%p bf=%p flags=%x\n", mref, mref_a, bf, bf->bf_flags);
_mref_remove(bf, mref_a);
buf_free_mref(mref);
@ -629,7 +629,7 @@ static int _buf_make_io(struct buf_brick *brick, struct buf_head *bf, void *star
}
#endif
MARS_DBG("bf = %p rw = %d start = %lld len = %d flags = %d\n", bf, rw, start_pos, start_len, bf->bf_flags);
MARS_DBG("bf = %p rw = %d start = %lld len = %d flags = %x\n", bf, rw, start_pos, start_len, bf->bf_flags);
atomic_set(&bf->bf_io_count, 0);
status = -ENOMEM;
@ -700,7 +700,7 @@ static void _buf_endio(struct generic_callback *cb)
struct buf_head *bf;
struct buf_brick *brick;
LIST_HEAD(tmp);
int old_flags;
__u32 old_flags;
unsigned long flags;
void *start_data = NULL;
loff_t start_pos = 0;
@ -719,7 +719,7 @@ static void _buf_endio(struct generic_callback *cb)
brick = bf->bf_brick;
CHECK_PTR(brick, err);
MARS_DBG("_buf_endio() bf_mref_a=%p bf_mref=%p bf=%p flags=%d\n", bf_mref_a, bf_mref, bf, bf->bf_flags);
MARS_DBG("_buf_endio() bf_mref_a=%p bf_mref=%p bf=%p flags=%x\n", bf_mref_a, bf_mref, bf, bf->bf_flags);
if (error < 0)
bf->bf_error = error;
@ -886,7 +886,7 @@ static void buf_ref_io(struct buf_output *output, struct mref_object *mref)
_mref_get(mref);
CHECK_ATOMIC(&bf->bf_hash_count, 1);
MARS_DBG("IO mref=%p rw=%d bf=%p flags=%d\n", mref, mref->ref_rw, bf, bf->bf_flags);
MARS_DBG("IO mref=%p rw=%d bf=%p flags=%x\n", mref, mref->ref_rw, bf, bf->bf_flags);
if (mref->ref_rw != READ) {
loff_t end;
@ -926,7 +926,7 @@ static void buf_ref_io(struct buf_output *output, struct mref_object *mref)
goto already_done;
#endif
if (bf->bf_flags & MREF_READING) {
MARS_ERR("bad bf_flags %d\n", bf->bf_flags);
MARS_ERR("bad bf_flags %x\n", bf->bf_flags);
}
if (!(bf->bf_flags & MREF_WRITING)) {
#if 0

View File

@ -98,7 +98,7 @@ struct buf_head {
struct buf_brick *bf_brick;
loff_t bf_pos;
loff_t bf_base_index;
int bf_flags;
__u32 bf_flags;
int bf_error;
atomic_t bf_hash_count; // # references pinning the hash
atomic_t bf_mref_count; // # mrefs (only used for checking, no real semantics)

View File

@ -106,7 +106,7 @@ const struct meta mars_mref_meta[] = {
META_INI(ref_timeout, struct mref_object, FIELD_INT),
META_INI(ref_total_size, struct mref_object, FIELD_INT),
META_INI(ref_checksum, struct mref_object, FIELD_INT),
META_INI(ref_flags, struct mref_object, FIELD_INT),
META_INI(ref_flags, struct mref_object, FIELD_UINT),
META_INI(ref_rw, struct mref_object, FIELD_INT),
META_INI(ref_id, struct mref_object, FIELD_INT),
META_INI(ref_skip_sync, struct mref_object, FIELD_INT),

View File

@ -88,8 +88,6 @@ static void _usebuf_endio(struct generic_callback *cb)
sub_mref = sub_mref_a->object;
CHECK_PTR(sub_mref, done);
//MARS_INF("HALLO %p %p len = %d may_write = %d rw = %d flags = %d\n", mref, sub_mref, sub_mref->ref_len, sub_mref->ref_may_write, sub_mref->ref_rw, sub_mref->ref_flags);
if (mref->ref_data != sub_mref->ref_data && cb->cb_error >= 0) {
if (sub_mref->ref_may_write == 0) {
if (sub_mref->ref_flags & MREF_UPTODATE) {
@ -183,7 +181,7 @@ static int usebuf_ref_get(struct usebuf_output *output, struct mref_object *mref
}
mref->ref_len = sub_mref->ref_len;
//MARS_INF("GOT %p %p flags = %d\n", mref, sub_mref, sub_mref->ref_flags);
//MARS_INF("GOT %p %p flags = %x\n", mref, sub_mref, sub_mref->ref_flags);
if (!mref->ref_data) {
MARS_INF("uiiiiiiiiiii\n");
mref->ref_data = sub_mref->ref_data;