[sheepdog] [PATCH 1/2] sheep: fix error handling in epoch_log_remote

Christoph Hellwig hch at infradead.org
Tue Jun 5 13:53:15 CEST 2012


Make sure we exit if any operations fails, operations that can fail are:

 - get_latest_epoch - because local_stat_cluster is a a force operation
   we might not have any epoch log yet.  In that case there is no point
   to continue.
 - epoch_log_read - can fail in any number of ways, although once we
   have a valid epoch it generally shouldn't.
 - if we didn't manage to read the epoch log from any node we should
   return -1 as there is no valid data returned.  If we have a valid
   node list of size 0 one of the nodes will return that to us.

Also adjust get_vnodes_from_epoch to deal with the negative return value,
local_stat_cluster currently doesn't have any error handling and will
be fixed in the next patch.

Signed-off-by: Christoph Hellwig <hch at lst.de>

Index: sheepdog/sheep/store.c
===================================================================
--- sheepdog.orig/sheep/store.c	2012-06-05 07:40:55.336111143 -0400
+++ sheepdog/sheep/store.c	2012-06-05 07:41:00.272111270 -0400
@@ -102,10 +102,17 @@ void do_io_request(struct work *work)
 int epoch_log_read_remote(uint32_t epoch, char *buf, int len)
 {
 	int i, ret;
-	unsigned int nr, le = get_latest_epoch();
+	unsigned int nr, le;
 	struct sd_node nodes[SD_MAX_NODES];
 
+	le = get_latest_epoch();
+	if (!le)
+		return 0;
+
 	nr = epoch_log_read(le, (char *)nodes, sizeof(nodes));
+	if (nr < 0)
+		return -1;
+
 	nr /= sizeof(nodes[0]);
 
 	for (i = 0; i < nr; i++) {
@@ -135,16 +142,11 @@ int epoch_log_read_remote(uint32_t epoch
 		ret = exec_req(fd, &hdr, buf, &wlen, &rlen);
 		close(fd);
 
-		if (ret)
-			continue;
-		if (rsp->result == SD_RES_SUCCESS) {
-			ret = rsp->data_length;
-			goto out;
-		}
+		if (!ret && rsp->result == SD_RES_SUCCESS)
+			return rsp->data_length;
 	}
-	ret = 0; /* If no one has targeted epoch file, we can safely return 0 */
-out:
-	return ret;
+
+	return -1;
 }
 
 int epoch_log_read_nr(uint32_t epoch, char *buf, int len)
Index: sheepdog/sheep/recovery.c
===================================================================
--- sheepdog.orig/sheep/recovery.c	2012-06-05 07:32:25.608098136 -0400
+++ sheepdog/sheep/recovery.c	2012-06-05 07:41:15.808111665 -0400
@@ -63,7 +63,7 @@ static struct vnode_info *get_vnodes_fro
 	if (nr_nodes < 0) {
 		nr_nodes = epoch_log_read_remote(epoch, (void *)nodes,
 						 sizeof(nodes));
-		if (nr_nodes == 0)
+		if (nr_nodes <= 0)
 			return NULL;
 		nr_nodes /= sizeof(nodes[0]);
 	}



More information about the sheepdog mailing list