dlbeer/dhara

prepare_write behavior

Opened this issue · 3 comments

Hi,

Why inside the prepare_write() function the auto_gc() check returns 0 in case of error? Look at code section:

static int prepare_write(struct dhara_map *m, dhara_sector_t dst, uint8_t *meta, dhara_error_t *err)
{
    dhara_error_t my_err;

    if (auto_gc(m, err) < 0)
        return 0; <<< Why this is zero and not -1? 

    if (m->count >= dhara_map_capacity(m))
    {
        dhara_set_error(err, DHARA_E_MAP_FULL);
        return -1;
    }

    if (trace_path(m, dst, NULL, meta, &my_err) < 0) 
    {
        if (my_err != DHARA_E_NOT_FOUND) 
        {
            dhara_set_error(err, my_err);
            return -1;
        }        

        m->count++;
    }

    ck_set_count(dhara_journal_cookie(&m->journal), m->count);
    return 0;
}

If you want "soft" error handling in that case then you need to remove that check for auto_gc. Code returns with 0, but trace_path and ck_set_count would not be called. I prefer to return error in case of failure, earlier occurs - earlier fixed. If nand interface or memory is broken that leads to auto_gc failure then saving writes make no sense (for me).