static int init_vdi_state(uint64_t oid, const char *wd, uint32_t epoch) { int ret; struct sd_inode *inode = xzalloc(SD_INODE_HEADER_SIZE); struct siocb iocb = { .epoch = epoch, .buf = inode, .length = SD_INODE_HEADER_SIZE, }; char path[PATH_MAX]; if (epoch == 0) get_store_path(oid, iocb.ec_index, path); else get_store_stale_path(oid, iocb.epoch, iocb.ec_index, path); ret = default_read_from_path(oid, path, &iocb); if (ret != SD_RES_SUCCESS) { sd_err("failed to read inode header %" PRIx64 " %" PRId32 "at %s", oid, epoch, path); goto out; } atomic_set_bit(oid_to_vid(oid), sys->vdi_inuse); out: free(inode); return ret; }
int default_read(uint64_t oid, struct siocb *iocb) { int ret; char path[PATH_MAX]; uint32_t epoch = sys_epoch(); get_obj_path(oid, path); ret = default_read_from_path(oid, path, iocb); /* If the request is againt the older epoch, try to read from * the stale directory */ while (ret == SD_RES_NO_OBJ && iocb->epoch < epoch) { epoch--; get_stale_obj_path(oid, epoch, path); ret = default_read_from_path(oid, path, iocb); } return ret; }
int default_read(uint64_t oid, const struct siocb *iocb) { int ret; char path[PATH_MAX]; get_store_path(oid, iocb->ec_index, path); ret = default_read_from_path(oid, path, iocb); /* * If the request is againt the older epoch, try to read from * the stale directory */ if (ret == SD_RES_NO_OBJ && iocb->epoch > 0 && iocb->epoch < sys_epoch()) { get_store_stale_path(oid, iocb->epoch, iocb->ec_index, path); ret = default_read_from_path(oid, path, iocb); } return ret; }
int default_get_hash(uint64_t oid, uint32_t epoch, uint8_t *sha1) { int ret; void *buf; struct siocb iocb = {}; uint32_t length; bool is_readonly_obj = oid_is_readonly(oid); char path[PATH_MAX]; ret = get_object_path(oid, epoch, path, sizeof(path)); if (ret != SD_RES_SUCCESS) return ret; if (is_readonly_obj) { if (get_object_sha1(path, sha1) == 0) { sd_debug("use cached sha1 digest %s", sha1_to_hex(sha1)); return SD_RES_SUCCESS; } } length = get_store_objsize(oid); buf = valloc(length); if (buf == NULL) return SD_RES_NO_MEM; iocb.epoch = epoch; iocb.buf = buf; iocb.length = length; ret = default_read_from_path(oid, path, &iocb); if (ret != SD_RES_SUCCESS) { free(buf); return ret; } get_buffer_sha1(buf, length, sha1); free(buf); sd_debug("the message digest of %"PRIx64" at epoch %d is %s", oid, epoch, sha1_to_hex(sha1)); if (is_readonly_obj) set_object_sha1(path, sha1); return ret; }