[sheepdog] [PATCH 1/3] farm: add defensive debug info

Liu Yuan namei.unix at gmail.com
Tue Jun 12 17:16:09 CEST 2012


From: Liu Yuan <tailai.ly at taobao.com>

We observed a bug emitting the line "write sha1 object fail", which doesn't
give why it fails, so add more debug info to assist analysis

Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
---
 sheep/farm/sha1_file.c |    6 +++++-
 sheep/farm/trunk.c     |    2 +-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/sheep/farm/sha1_file.c b/sheep/farm/sha1_file.c
index 135546f..ead1a00 100644
--- a/sheep/farm/sha1_file.c
+++ b/sheep/farm/sha1_file.c
@@ -124,6 +124,7 @@ static int sha1_buffer_write(const unsigned char *sha1, void *buf, unsigned int
 	}
 	len = xwrite(fd, buf, size);
 	if (len != size) {
+		dprintf("%m\n");
 		close(fd);
 		return -1;
 	}
@@ -162,13 +163,16 @@ static void *map_sha1_file(const unsigned char *sha1, unsigned long *size)
 		return NULL;
 	}
 	if (fstat(fd, &st) < 0) {
+		dprintf("%m\n");
 		close(fd);
 		return NULL;
 	}
 	map = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
 	close(fd);
-	if (map == MAP_FAILED)
+	if (map == MAP_FAILED) {
+		dprintf("%m\n");
 		return NULL;
+	}
 	*size = st.st_size;
 	return map;
 }
diff --git a/sheep/farm/trunk.c b/sheep/farm/trunk.c
index b573460..c9d11f2 100644
--- a/sheep/farm/trunk.c
+++ b/sheep/farm/trunk.c
@@ -277,7 +277,7 @@ int trunk_file_write_recovery(unsigned char *outsha1)
 			dprintf("stale oid %"PRIx64"\n", oid);
 			if (trunk_entry_no_sha1(entry) || trunk_entry_is_dirty(entry)) {
 				if (fill_entry_new_sha1(entry) < 0) {
-					eprintf("write sha1 object fail.\n");
+					eprintf("fill sha1 fail\n");
 					goto out;
 				}
 			}
-- 
1.7.10.2




More information about the sheepdog mailing list