static int get_object_path(uint64_t oid, uint32_t epoch, char *path) { if (default_exist(oid)) { get_obj_path(oid, path); } else { get_stale_obj_path(oid, epoch, path); if (access(path, F_OK) < 0) { if (errno == ENOENT) return SD_RES_NO_OBJ; return SD_RES_EIO; } } return SD_RES_SUCCESS; }
static int move_object_to_stale_dir(uint64_t oid, void *arg) { char path[PATH_MAX], stale_path[PATH_MAX]; uint32_t tgt_epoch = *(int *)arg; get_obj_path(oid, path); get_stale_obj_path(oid, tgt_epoch, stale_path); if (rename(path, stale_path) < 0) { eprintf("failed to move stale object %"PRIX64" to %s, %m\n", oid, path); return SD_RES_EIO; } dprintf("moved object %"PRIx64"\n", oid); return SD_RES_SUCCESS; }
int default_link(uint64_t oid, struct siocb *iocb, uint32_t tgt_epoch) { char path[PATH_MAX], stale_path[PATH_MAX]; dprintf("try link %"PRIx64" from snapshot with epoch %d\n", oid, tgt_epoch); get_obj_path(oid, path); get_stale_obj_path(oid, tgt_epoch, stale_path); if (link(stale_path, path) < 0) { eprintf("failed to link from %s to %s, %m\n", stale_path, path); return err_to_sderr(oid, errno); } return SD_RES_SUCCESS; }
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_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 */ if (ret == SD_RES_NO_OBJ && iocb->epoch > 0 && iocb->epoch < sys_epoch()) { get_stale_obj_path(oid, iocb->epoch, path); ret = default_read_from_path(oid, path, iocb); } return ret; }
int default_link(uint64_t oid, uint32_t tgt_epoch) { char path[PATH_MAX], stale_path[PATH_MAX]; sd_debug("try link %"PRIx64" from snapshot with epoch %d", oid, tgt_epoch); get_obj_path(oid, path); get_stale_obj_path(oid, tgt_epoch, stale_path); if (link(stale_path, path) < 0) { /* * Recovery thread and main thread might try to recover the * same object and we might get EEXIST in such case. */ if (errno == EEXIST) goto out; sd_debug("failed to link from %s to %s, %m", stale_path, path); return err_to_sderr(path, oid, errno); } out: return SD_RES_SUCCESS; }