fellow_cache: Prepare for an fdo pointer

parent b44682ec
...@@ -345,6 +345,7 @@ static inline uint16_t \ ...@@ -345,6 +345,7 @@ static inline uint16_t \
SEGLIST_FIT_FUNC(disk) SEGLIST_FIT_FUNC(disk)
//struct fellow_disk_obj;
struct fellow_cache_obj; struct fellow_cache_obj;
struct fellow_cache_seg { struct fellow_cache_seg {
uint16_t magic; uint16_t magic;
...@@ -372,7 +373,10 @@ struct fellow_cache_seg { ...@@ -372,7 +373,10 @@ struct fellow_cache_seg {
struct fellow_cache_obj *fco; struct fellow_cache_obj *fco;
struct fellow_disk_seg *disk_seg; struct fellow_disk_seg *disk_seg;
struct buddy_ptr_extent alloc; struct buddy_ptr_extent alloc;
size_t len; // used size union {
size_t fcs_len; // FCS_* used size
struct fellow_disk_obj *fco_fdo; // FCO_* ptr to fdo
} u;
}; };
struct fellow_cache_seglist { struct fellow_cache_seglist {
...@@ -1392,7 +1396,7 @@ assert_cache_seg_consistency(const struct fellow_cache_seg *fcs) ...@@ -1392,7 +1396,7 @@ assert_cache_seg_consistency(const struct fellow_cache_seg *fcs)
#define FCOSA_NOMEM do { \ #define FCOSA_NOMEM do { \
AZ(fcs->alloc.ptr); \ AZ(fcs->alloc.ptr); \
AZ(fcs->alloc.size); \ AZ(fcs->alloc.size); \
AZ(fcs->len); \ AZ(fcs->u.fcs_len); \
} while(0) } while(0)
#define FCSA_MEM do { \ #define FCSA_MEM do { \
AN(fcs->alloc.ptr); \ AN(fcs->alloc.ptr); \
...@@ -1496,7 +1500,7 @@ fellow_cache_seg_free(struct buddy_returns *memret, ...@@ -1496,7 +1500,7 @@ fellow_cache_seg_free(struct buddy_returns *memret,
AZ(fcs->fcs_onlru); AZ(fcs->fcs_onlru);
assert(fcs->refcnt == deref); assert(fcs->refcnt == deref);
fcs->refcnt = 0; fcs->refcnt = 0;
fcs->len = 0; fcs->u.fcs_len = 0;
/* /*
* at this point, the fcs is not consistent in all cases, e.g. FCS_EVICT * at this point, the fcs is not consistent in all cases, e.g. FCS_EVICT
* has no memory - but this is the point where it does no longer exist * has no memory - but this is the point where it does no longer exist
...@@ -2805,10 +2809,10 @@ fellow_cache_seg_fini(const struct fellow_cache_seg *fcs) ...@@ -2805,10 +2809,10 @@ fellow_cache_seg_fini(const struct fellow_cache_seg *fcs)
CHECK_OBJ_NOTNULL(fds, FELLOW_DISK_SEG_MAGIC); CHECK_OBJ_NOTNULL(fds, FELLOW_DISK_SEG_MAGIC);
AN(fcs->alloc.ptr); AN(fcs->alloc.ptr);
AN(fcs->len); AN(fcs->u.fcs_len);
assert(fcs->len <= fds->seg.size); assert(fcs->u.fcs_len <= fds->seg.size);
fds->seg.size = fcs->len; fds->seg.size = fcs->u.fcs_len;
fh(fds->fht, fds->fh, fcs->alloc.ptr, fcs->len); fh(fds->fht, fds->fh, fcs->alloc.ptr, fcs->u.fcs_len);
} }
static inline void static inline void
...@@ -2923,7 +2927,7 @@ fellow_cache_seg_unbusy(struct fellow_busy *fbo, struct fellow_cache_seg *fcs){ ...@@ -2923,7 +2927,7 @@ fellow_cache_seg_unbusy(struct fellow_busy *fbo, struct fellow_cache_seg *fcs){
CHECK_OBJ_NOTNULL(fco, FELLOW_CACHE_OBJ_MAGIC); CHECK_OBJ_NOTNULL(fco, FELLOW_CACHE_OBJ_MAGIC);
assert(fco == fbo->fco); assert(fco == fbo->fco);
AN(fcs->refcnt); AN(fcs->refcnt);
AN(fcs->len); AN(fcs->u.fcs_len);
assert_fcos_transition(from, to); assert_fcos_transition(from, to);
struct fellow_lru_chgbatch lcb[1] = struct fellow_lru_chgbatch lcb[1] =
...@@ -3316,9 +3320,9 @@ fellow_cache_seg_io_check(const struct fellow_cache *fc, ...@@ -3316,9 +3320,9 @@ fellow_cache_seg_io_check(const struct fellow_cache *fc,
assert(fcs->alloc.size == asz); assert(fcs->alloc.size == asz);
AN(fds->seg.off); AN(fds->seg.off);
AN(fds->seg.size); AN(fds->seg.size);
assert(fds->seg.size >= fcs->len); assert(fds->seg.size >= fcs->u.fcs_len);
assert(fds->seg.size <= asz); assert(fds->seg.size <= asz);
fcs->len = fds->seg.size; fcs->u.fcs_len = fds->seg.size;
// O_DIRECT alignment on 4K // O_DIRECT alignment on 4K
AZ((uintptr_t) fcs->alloc.ptr & FELLOW_BLOCK_ALIGN); AZ((uintptr_t) fcs->alloc.ptr & FELLOW_BLOCK_ALIGN);
...@@ -3425,7 +3429,7 @@ fellow_cache_seg_evict_locked( ...@@ -3425,7 +3429,7 @@ fellow_cache_seg_evict_locked(
assert(fcs->state == FCS_INCORE); assert(fcs->state == FCS_INCORE);
*alloc = fcs->alloc; *alloc = fcs->alloc;
fcs->alloc = buddy_ptr_extent_nil; fcs->alloc = buddy_ptr_extent_nil;
fcs->len = 0; fcs->u.fcs_len = 0;
fcs->state = FCS_DISK; fcs->state = FCS_DISK;
} }
...@@ -4060,7 +4064,7 @@ fellow_cache_seg_check(struct fellow_cache_seg *fcs) ...@@ -4060,7 +4064,7 @@ fellow_cache_seg_check(struct fellow_cache_seg *fcs)
CHECK_OBJ_NOTNULL(fds, FELLOW_DISK_SEG_MAGIC); CHECK_OBJ_NOTNULL(fds, FELLOW_DISK_SEG_MAGIC);
#ifdef TODO_READ_ERR #ifdef TODO_READ_ERR
if ((fds->segnum % 16 == 0 && FC_INJ) || if ((fds->segnum % 16 == 0 && FC_INJ) ||
fhcmp(fds->fht, fds->fh, fcs->alloc.ptr, fcs->len)) { fhcmp(fds->fht, fds->fh, fcs->alloc.ptr, fcs->u.fcs_len)) {
err = "segment checksum error"; err = "segment checksum error";
to = FCS_READFAIL; to = FCS_READFAIL;
} }
...@@ -4754,16 +4758,16 @@ fellow_busy_obj_getspace(struct fellow_busy *fbo, size_t *sz, uint8_t **ptr) ...@@ -4754,16 +4758,16 @@ fellow_busy_obj_getspace(struct fellow_busy *fbo, size_t *sz, uint8_t **ptr)
fcs = fbo->body_seg; fcs = fbo->body_seg;
if (fcs != NULL && fcs->state == FCS_BUSY) { if (fcs != NULL && fcs->state == FCS_BUSY) {
AN(fcs->alloc.size); AN(fcs->alloc.size);
if (fcs->len < fcs->alloc.size) { if (fcs->u.fcs_len < fcs->alloc.size) {
spc = fcs->alloc.size - fcs->len; spc = fcs->alloc.size - fcs->u.fcs_len;
assert(spc > 0); assert(spc > 0);
if (spc < *sz) if (spc < *sz)
*sz = spc; *sz = spc;
*ptr = (uint8_t *)fcs->alloc.ptr + fcs->len; *ptr = (uint8_t *)fcs->alloc.ptr + fcs->u.fcs_len;
return (FCR_OK(fbo)); return (FCR_OK(fbo));
} }
assert(fcs->len == fcs->alloc.size); assert(fcs->u.fcs_len == fcs->alloc.size);
unbusy = fcs; unbusy = fcs;
fcs = NULL; fcs = NULL;
} }
...@@ -4831,9 +4835,9 @@ fellow_busy_obj_extend(struct fellow_busy *fbo, size_t l) ...@@ -4831,9 +4835,9 @@ fellow_busy_obj_extend(struct fellow_busy *fbo, size_t l)
fcs = fbo->body_seg; fcs = fbo->body_seg;
CHECK_OBJ_NOTNULL(fcs, FELLOW_CACHE_SEG_MAGIC); CHECK_OBJ_NOTNULL(fcs, FELLOW_CACHE_SEG_MAGIC);
assert(fcs->state == FCS_BUSY); assert(fcs->state == FCS_BUSY);
fcs->len += l; fcs->u.fcs_len += l;
fbo->sz_returned += l; fbo->sz_returned += l;
assert(fcs->len <= fcs->alloc.size); assert(fcs->u.fcs_len <= fcs->alloc.size);
} }
static void static void
...@@ -4932,7 +4936,7 @@ fellow_busy_obj_trimstore(struct fellow_busy *fbo) ...@@ -4932,7 +4936,7 @@ fellow_busy_obj_trimstore(struct fellow_busy *fbo)
assert_cache_seg_consistency(fcs); assert_cache_seg_consistency(fcs);
if (fcs->state == FCS_BUSY) { if (fcs->state == FCS_BUSY) {
assert(fcs->len <= fcs->alloc.size); assert(fcs->u.fcs_len <= fcs->alloc.size);
AN(fdr); AN(fdr);
/* /*
...@@ -4946,7 +4950,7 @@ fellow_busy_obj_trimstore(struct fellow_busy *fbo) ...@@ -4946,7 +4950,7 @@ fellow_busy_obj_trimstore(struct fellow_busy *fbo)
} else { } else {
assert(fcs->state == FCS_USABLE); assert(fcs->state == FCS_USABLE);
AZ(fcs->alloc.size); AZ(fcs->alloc.size);
AZ(fcs->len); AZ(fcs->u.fcs_len);
} }
if (fdr) { if (fdr) {
...@@ -4954,7 +4958,7 @@ fellow_busy_obj_trimstore(struct fellow_busy *fbo) ...@@ -4954,7 +4958,7 @@ fellow_busy_obj_trimstore(struct fellow_busy *fbo)
// fbr offset where fcs starts // fbr offset where fcs starts
base = fbr->len - fcs->alloc.size; base = fbr->len - fcs->alloc.size;
nsz = base + fcs->len; nsz = base + fcs->u.fcs_len;
if (nsz == 0) if (nsz == 0)
fellow_busy_region_free(fbo, fdr); fellow_busy_region_free(fbo, fdr);
...@@ -4981,8 +4985,8 @@ fellow_busy_obj_trimstore(struct fellow_busy *fbo) ...@@ -4981,8 +4985,8 @@ fellow_busy_obj_trimstore(struct fellow_busy *fbo)
// dsk/membuddy aligment must match // dsk/membuddy aligment must match
assert(nsz == fcs->alloc.size); assert(nsz == fcs->alloc.size);
fcs->disk_seg->seg.size = fcs->alloc.size; fcs->disk_seg->seg.size = fcs->alloc.size;
assert(fcs->len <= fcs->alloc.size); assert(fcs->u.fcs_len <= fcs->alloc.size);
if (fcs->len == 0) { if (fcs->u.fcs_len == 0) {
fcs->alloc.ptr = NULL; fcs->alloc.ptr = NULL;
AZ(fcs->disk_seg->seg.size); AZ(fcs->disk_seg->seg.size);
fcs->disk_seg->seg.off = 0; fcs->disk_seg->seg.off = 0;
...@@ -5758,7 +5762,7 @@ fellow_cache_obj_getattr(struct fellow_cache *fc, ...@@ -5758,7 +5762,7 @@ fellow_cache_obj_getattr(struct fellow_cache *fc,
return (NULL); \ return (NULL); \
fellow_cache_seg_auxattr_ref_in(fc, fcs); \ fellow_cache_seg_auxattr_ref_in(fc, fcs); \
XXXAZ(fellow_cache_seg_check(fcs)); \ XXXAZ(fellow_cache_seg_check(fcs)); \
*len = fcs->len; \ *len = fcs->u.fcs_len; \
return (fcs->alloc.ptr); \ return (fcs->alloc.ptr); \
} }
#include "tbl/fellow_obj_attr.h" #include "tbl/fellow_obj_attr.h"
...@@ -5839,8 +5843,8 @@ fellow_busy_setattr(struct fellow_busy *fbo, enum obj_attr attr, ...@@ -5839,8 +5843,8 @@ fellow_busy_setattr(struct fellow_busy *fbo, enum obj_attr attr,
if (! fellow_busy_seg_alloc(fbo, fcs, len)) \ if (! fellow_busy_seg_alloc(fbo, fcs, len)) \
break; \ break; \
assert(fcs->alloc.size >= len); \ assert(fcs->alloc.size >= len); \
AZ(fcs->len); \ AZ(fcs->u.fcs_len); \
fcs->len = len; \ fcs->u.fcs_len = len; \
retval = fcs->alloc.ptr; \ retval = fcs->alloc.ptr; \
memcpy(retval, ptr, len); \ memcpy(retval, ptr, len); \
fellow_cache_seg_unbusy(fbo, fcs); \ fellow_cache_seg_unbusy(fbo, fcs); \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment