fellow_storage: Improve error handling for _getattr()

parent 98d05582
...@@ -6118,56 +6118,67 @@ fellow_cache_obj_delete(struct fellow_cache *fc, ...@@ -6118,56 +6118,67 @@ fellow_cache_obj_delete(struct fellow_cache *fc,
buddy_return(rets); buddy_return(rets);
} }
// XXX status struct fellow_cache_res
void *
fellow_cache_obj_getattr(struct fellow_cache *fc, fellow_cache_obj_getattr(struct fellow_cache *fc,
struct fellow_cache_obj *fco, struct fellow_cache_obj *fco,
enum obj_attr attr, size_t *len) enum obj_attr attr, size_t *len)
{ {
struct fellow_cache_res fcr;
struct fellow_disk_obj *fdo; struct fellow_disk_obj *fdo;
const char *err;
CHECK_OBJ_NOTNULL(fco, FELLOW_CACHE_OBJ_MAGIC); CHECK_OBJ_NOTNULL(fco, FELLOW_CACHE_OBJ_MAGIC);
fdo = FCO_FDO(fco); fdo = FCO_FDO(fco);
CHECK_OBJ_NOTNULL(fdo, FELLOW_DISK_OBJ_MAGIC); CHECK_OBJ_NOTNULL(fdo, FELLOW_DISK_OBJ_MAGIC);
AN(len); AN(len);
fcr = fco->fcr;
if (fcr.status != fcr_ok)
return (fcr);
/* Auxiliary attributes:
*
* ref is never returned and just ignored by
* fellow_cache_seg_auxattr_free()
*/
switch (attr) { switch (attr) {
/* Fixed size attributes */
#define FDO_FIXATTR(U, l, s, vs) \ #define FDO_FIXATTR(U, l, s, vs) \
case OA_##U: \ case OA_##U: \
*len = vs; \ *len = vs; \
return (fdo->fa_##l); fcr = FCR_OK(fdo->fa_##l); \
#include "tbl/fellow_obj_attr.h" break;
/* Variable size attributes */
#define FDO_VARATTR(U, l) \ #define FDO_VARATTR(U, l) \
case OA_##U: \ case OA_##U: \
if (fdo->va_##l.aoff == 0) \ if (fdo->va_##l.aoff == 0) { \
return (NULL); \ fcr = FCR_OK(NULL); \
break; \
} \
*len = fdo->va_##l.alen; \ *len = fdo->va_##l.alen; \
return ((uint8_t *)fdo + fdo->va_##l.aoff); fcr = FCR_OK((uint8_t *)fdo + fdo->va_##l.aoff); \
#include "tbl/fellow_obj_attr.h" break;
/* Auxiliary attributes
* ref is never returned and just ignored by
* fellow_cache_seg_auxattr_free()
*/
#define FDO_AUXATTR(U, l) \ #define FDO_AUXATTR(U, l) \
case OA_##U: { \ case OA_##U: { \
struct fellow_cache_seg *fcs = &fco->aa_##l##_seg; \ struct fellow_cache_seg *fcs = &fco->aa_##l##_seg; \
if (fcs->disk_seg->seg.size == 0) \ if (fcs->disk_seg->seg.size == 0) { \
return (NULL); \ fcr = FCR_OK(NULL); \
break; \
} \
fellow_cache_seg_auxattr_ref_in(fc, fcs); \ fellow_cache_seg_auxattr_ref_in(fc, fcs); \
XXXAZ(fellow_cache_seg_check(fcs)); \ err = fellow_cache_seg_check(fcs); \
if (err != NULL) { \
fcr = FCR_IOFAIL(err); \
break; \
} \
*len = fcs->u.fcs_len; \ *len = fcs->u.fcs_len; \
return (fcs->alloc.ptr); \ fcr = FCR_OK(fcs->alloc.ptr); \
break; \
} }
#include "tbl/fellow_obj_attr.h" #include "tbl/fellow_obj_attr.h"
default: default:
break; WRONG("Unsupported OBJ_ATTR");
} }
WRONG("Unsupported OBJ_ATTR"); return (fellow_cache_obj_res(fc, fco, fcr));
} }
void * void *
...@@ -6435,15 +6446,16 @@ static const char * const oatest[OA__MAX] = { ...@@ -6435,15 +6446,16 @@ static const char * const oatest[OA__MAX] = {
void t_getattr(struct fellow_cache *fc, struct fellow_cache_obj *fco) void t_getattr(struct fellow_cache *fc, struct fellow_cache_obj *fco)
{ {
struct fellow_cache_res fcr;
unsigned u; unsigned u;
size_t sz; size_t sz;
const char *v;
for (u = 0; u < OA__MAX; u++) { for (u = 0; u < OA__MAX; u++) {
v = fellow_cache_obj_getattr(fc, fco, u, &sz); fcr = fellow_cache_obj_getattr(fc, fco, u, &sz);
AN(v); assert(fcr.status == fcr_ok);
AN(fcr.r.ptr);
assert(sz == strlen(oatest[u])); assert(sz == strlen(oatest[u]));
AZ(strncmp(v, oatest[u], sz)); AZ(strncmp(fcr.r.ptr, oatest[u], sz));
} }
} }
...@@ -7004,7 +7016,7 @@ t_busyobj(unsigned chksum, struct fellow_cache *fc) ...@@ -7004,7 +7016,7 @@ t_busyobj(unsigned chksum, struct fellow_cache *fc)
AN(fco->fcsl->next); AN(fco->fcsl->next);
// fixattr always return a pointer // fixattr always return a pointer
for (u = OA_VARY; u < OA__MAX; u++) for (u = OA_VARY; u < OA__MAX; u++)
AZ(fellow_cache_obj_getattr(fc, fco, u, &sz)); AZ(fellow_cache_obj_getattr(fc, fco, u, &sz).r.ptr);
for (u = 0; u < OA__MAX; u++) for (u = 0; u < OA__MAX; u++)
AN(fellow_busy_setattr(fbo, u, strlen(oatest[u]), oatest[u])); AN(fellow_busy_setattr(fbo, u, strlen(oatest[u]), oatest[u]));
t_getattr(fc, fco); t_getattr(fc, fco);
...@@ -7313,7 +7325,7 @@ t_cache(const char *fn, unsigned chksum) ...@@ -7313,7 +7325,7 @@ t_cache(const char *fn, unsigned chksum)
AN(fco->fcsl->next); AN(fco->fcsl->next);
// fixattr always return a pointer // fixattr always return a pointer
for (u = OA_VARY; u < OA__MAX; u++) for (u = OA_VARY; u < OA__MAX; u++)
AZ(fellow_cache_obj_getattr(fc, fco, u, &sz)); AZ(fellow_cache_obj_getattr(fc, fco, u, &sz).r.ptr);
for (u = 0; u < OA__MAX; u++) for (u = 0; u < OA__MAX; u++)
AN(fellow_busy_setattr(fbo, u, strlen(oatest[u]), oatest[u])); AN(fellow_busy_setattr(fbo, u, strlen(oatest[u]), oatest[u]));
t_getattr(fc, fco); t_getattr(fc, fco);
......
...@@ -64,7 +64,8 @@ struct fellow_cache_res fellow_cache_obj_get(struct fellow_cache *fc, ...@@ -64,7 +64,8 @@ struct fellow_cache_res fellow_cache_obj_get(struct fellow_cache *fc,
struct fellow_cache_res struct fellow_cache_res
fellow_cache_obj_iter(struct fellow_cache *fc, struct fellow_cache_obj *fco, fellow_cache_obj_iter(struct fellow_cache *fc, struct fellow_cache_obj *fco,
void *priv, objiterate_f func, int final); void *priv, objiterate_f func, int final);
void *fellow_cache_obj_getattr(struct fellow_cache *fc, struct fellow_cache_res
fellow_cache_obj_getattr(struct fellow_cache *fc,
struct fellow_cache_obj *fco, struct fellow_cache_obj *fco,
enum obj_attr attr, size_t *len); enum obj_attr attr, size_t *len);
int fellow_cache_obj_lru_touch(struct fellow_cache_obj *fco); int fellow_cache_obj_lru_touch(struct fellow_cache_obj *fco);
......
...@@ -503,6 +503,7 @@ stvfe_fcr_handle(struct worker *wrk, struct objcore *oc, ...@@ -503,6 +503,7 @@ stvfe_fcr_handle(struct worker *wrk, struct objcore *oc,
const struct stevedore *stv, const struct stvfe *stvfe, const struct stevedore *stv, const struct stvfe *stvfe,
struct fellow_cache_res fcr) struct fellow_cache_res fcr)
{ {
if (fcr.status == fcr_ok) if (fcr.status == fcr_ok)
return; return;
...@@ -523,6 +524,7 @@ stvfe_fcr_handle_iter(struct worker *wrk, struct objcore *oc, ...@@ -523,6 +524,7 @@ stvfe_fcr_handle_iter(struct worker *wrk, struct objcore *oc,
const struct stevedore *stv, const struct stvfe *stvfe, const struct stevedore *stv, const struct stvfe *stvfe,
struct fellow_cache_res fcr) struct fellow_cache_res fcr)
{ {
if (fcr.status == fcr_ok) if (fcr.status == fcr_ok)
return (fcr.r.integer); return (fcr.r.integer);
...@@ -1107,12 +1109,13 @@ sfemem_getattr(struct worker *wrk, struct objcore *memoc, enum obj_attr attr, ...@@ -1107,12 +1109,13 @@ sfemem_getattr(struct worker *wrk, struct objcore *memoc, enum obj_attr attr,
const struct stevedore *stv = oc_stv(wrk, memoc); const struct stevedore *stv = oc_stv(wrk, memoc);
const struct stvfe *stvfe = stv_stvfe(stv); const struct stvfe *stvfe = stv_stvfe(stv);
struct fellow_cache_obj *fco = stvfe_memoc_fco(stv, stvfe, memoc); struct fellow_cache_obj *fco = stvfe_memoc_fco(stv, stvfe, memoc);
struct fellow_cache_res fcr;
size_t len; size_t len;
void *r;
assert_memstv(stvfe, stv); assert_memstv(stvfe, stv);
r = fellow_cache_obj_getattr(stvfe->fc, fco, attr, &len); fcr = fellow_cache_obj_getattr(stvfe->fc, fco, attr, &len);
stvfe_fcr_handle(wrk, memoc, stv, stvfe, fcr);
if (slen) if (slen)
*slen = (ssize_t)len; *slen = (ssize_t)len;
...@@ -1120,7 +1123,7 @@ sfemem_getattr(struct worker *wrk, struct objcore *memoc, enum obj_attr attr, ...@@ -1120,7 +1123,7 @@ sfemem_getattr(struct worker *wrk, struct objcore *memoc, enum obj_attr attr,
if (attr == OA_VARY) if (attr == OA_VARY)
(void) fellow_cache_obj_lru_touch(fco); (void) fellow_cache_obj_lru_touch(fco);
return (r); return (fcr.status == fcr_ok ? fcr.r.ptr : NULL);
} }
static const void * v_matchproto_(objgetattr_f) static const void * v_matchproto_(objgetattr_f)
...@@ -1131,17 +1134,18 @@ sfedsk_getattr_tomem(struct worker *wrk, struct objcore *dskoc, ...@@ -1131,17 +1134,18 @@ sfedsk_getattr_tomem(struct worker *wrk, struct objcore *dskoc,
const struct stvfe *stvfe = stv_stvfe(stv); const struct stvfe *stvfe = stv_stvfe(stv);
struct fcoc fcoc = stvfe_dskoc_fco(wrk, stv, stvfe, dskoc, struct fcoc fcoc = stvfe_dskoc_fco(wrk, stv, stvfe, dskoc,
attr == OA_VARY ? 1 : 0); attr == OA_VARY ? 1 : 0);
struct fellow_cache_res fcr;
size_t len; size_t len;
void *r;
if (fcoc.fco == NULL) if (fcoc.fco == NULL)
return (NULL); return (NULL);
r = fellow_cache_obj_getattr(stvfe->fc, fcoc.fco, attr, &len); fcr = fellow_cache_obj_getattr(stvfe->fc, fcoc.fco, attr, &len);
stvfe_fcr_handle(wrk, dskoc, stv, stvfe, fcr);
fcoc_fini(stvfe->fc, &fcoc); fcoc_fini(stvfe->fc, &fcoc);
if (slen) if (slen)
*slen = (ssize_t)len; *slen = (ssize_t)len;
return (r); return (fcr.status == fcr_ok ? fcr.r.ptr : NULL);
} }
/* we do not want to pull in the fco just to get the xid, just return 0 */ /* we do not want to pull in the fco just to get the xid, just return 0 */
......
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