[sheepdog] [PATCH] sheep: cleanup recover_object_from_replica
Christoph Hellwig
hch at infradead.org
Tue Jun 5 14:16:15 CEST 2012
Use the out and done labels more consistently and flatten the control flow.
Also return actual error values instead of -1 to the caller in all cases
to allow for more fine grained error handling in the future.
diff --git a/sheep/recovery.c b/sheep/recovery.c
index 591c5d1..2597126 100644
--- a/sheep/recovery.c
+++ b/sheep/recovery.c
@@ -79,7 +79,7 @@ static int recover_object_from_replica(uint64_t oid,
struct sd_rsp *rsp = (struct sd_rsp *)&hdr;
char name[128];
unsigned wlen = 0, rlen;
- int fd, ret = -1;
+ int fd, ret;
void *buf;
struct siocb iocb = { 0 };
@@ -93,6 +93,7 @@ static int recover_object_from_replica(uint64_t oid,
buf = valloc(rlen);
if (!buf) {
eprintf("%m\n");
+ ret = SD_RES_EIO;
goto out;
}
@@ -100,13 +101,9 @@ static int recover_object_from_replica(uint64_t oid,
iocb.epoch = epoch;
iocb.length = rlen;
ret = sd_store->link(oid, &iocb, tgt_epoch);
- if (ret == SD_RES_SUCCESS) {
- ret = 0;
- goto done;
- } else {
- ret = -1;
+ if (ret != SD_RES_SUCCESS)
goto out;
- }
+ goto done;
}
addr_to_str(name, sizeof(name), entry->addr, 0);
@@ -114,7 +111,7 @@ static int recover_object_from_replica(uint64_t oid,
dprintf("%s, %d\n", name, entry->port);
if (fd < 0) {
eprintf("failed to connect to %s:%"PRIu32"\n", name, entry->port);
- ret = -1;
+ ret = SD_RES_EIO;
goto out;
}
@@ -133,31 +130,29 @@ static int recover_object_from_replica(uint64_t oid,
if (ret != 0) {
eprintf("res: %"PRIx32"\n", rsp->result);
- ret = -1;
goto out;
}
rsp = (struct sd_rsp *)&hdr;
- if (rsp->result == SD_RES_SUCCESS) {
- iocb.epoch = epoch;
- iocb.length = rlen;
- iocb.buf = buf;
- ret = sd_store->atomic_put(oid, &iocb);
- if (ret != SD_RES_SUCCESS) {
- ret = -1;
- goto out;
- }
- } else {
+ if (rsp->result != SD_RES_SUCCESS) {
eprintf("failed, res: %"PRIx32"\n", rsp->result);
ret = rsp->result;
goto out;
}
+
+ iocb.epoch = epoch;
+ iocb.length = rlen;
+ iocb.buf = buf;
+ ret = sd_store->atomic_put(oid, &iocb);
+ if (ret != SD_RES_SUCCESS)
+ goto out;
+
done:
- dprintf("recovered oid %"PRIx64" from %d to epoch %d\n", oid, tgt_epoch, epoch);
+ dprintf("recovered oid %"PRIx64" from %d to epoch %d\n", oid,
+ tgt_epoch, epoch);
+ objlist_cache_insert(oid);
out:
- if (ret == SD_RES_SUCCESS)
- objlist_cache_insert(oid);
free(buf);
return ret;
}
More information about the sheepdog
mailing list