Пример #1
0
static void *retrieve_object_from_snap(uint64_t oid, int epoch)
{
    struct sha1_file_hdr hdr;
    struct trunk_entry *trunk_buf, *trunk_free = NULL;
    unsigned char trunk_sha1[SHA1_LEN];
    uint64_t nr_trunks, i;
    void *buffer = NULL;

    if (get_trunk_sha1(epoch, trunk_sha1, 0) < 0)
        goto out;

    trunk_free = trunk_buf = trunk_file_read(trunk_sha1, &hdr);
    if (!trunk_buf)
        goto out;

    nr_trunks = hdr.priv;
    for (i = 0; i < nr_trunks; i++, trunk_buf++) {
        struct sha1_file_hdr h;
        if (trunk_buf->oid != oid)
            continue;

        buffer = sha1_file_read(trunk_buf->sha1, &h);
        break;
    }

out:
    dprintf("oid %"PRIx64", epoch %d, %s\n", oid, epoch, buffer ? "succeed" : "fail");
    free(trunk_free);
    return buffer;
}
Пример #2
0
static int cleanup_trunk(int epoch)
{
    struct sha1_file_hdr hdr;
    struct trunk_entry *trunk_buf, *trunk_free = NULL;
    unsigned char trunk_sha1[SHA1_LEN];
    uint64_t nr_trunks, i;
    int ret = SD_RES_EIO;

    if (get_trunk_sha1(epoch, trunk_sha1, 0) < 0)
        goto out;

    trunk_free = trunk_buf = trunk_file_read(trunk_sha1, &hdr);
    if (!trunk_buf)
        goto out;

    nr_trunks = hdr.priv;
    for (i = 0; i < nr_trunks; i++, trunk_buf++)
        sha1_file_try_delete(trunk_buf->sha1);

    if (sha1_file_try_delete(trunk_sha1) < 0)
        goto out;

    ret = SD_RES_SUCCESS;

out:
    free(trunk_free);
    return ret;
}
Пример #3
0
static int restore_objects_from_snap(uint32_t epoch)
{
	struct sha1_file_hdr hdr;
	struct trunk_entry *trunk_buf, *trunk_free = NULL;
	unsigned char trunk_sha1[SHA1_LEN];
	uint64_t nr_trunks, i;
	int ret = SD_RES_EIO;

	if (get_trunk_sha1(epoch, trunk_sha1) < 0)
		goto out;

	trunk_free = trunk_buf = trunk_file_read(trunk_sha1, &hdr);
	if (!trunk_buf)
		goto out;

	nr_trunks = hdr.priv;
	ret = SD_RES_SUCCESS;
	for (i = 0; i < nr_trunks; i++, trunk_buf++) {
		struct sha1_file_hdr h;
		struct siocb io = { 0 };
		uint64_t oid;
		void *buffer = NULL;

		oid = trunk_buf->oid;
		buffer = sha1_file_read(trunk_buf->sha1, &h);
		if (!buffer) {
			sd_eprintf("oid %"PRIx64" not restored", oid);
			goto out;
		}
		io.length = h.size;
		io.buf = buffer;
		ret = default_create_and_write(oid, &io);
		if (ret != SD_RES_SUCCESS) {
			sd_eprintf("oid %"PRIx64" not restored", oid);
			goto out;
		} else
			sd_dprintf("oid %"PRIx64" restored", oid);

		free(buffer);
	}
out:
	free(trunk_free);
	return ret;
}