[Sheepdog] Fix to put_sha1_file

huxinwei huxinwei at huawei.com
Fri Mar 2 10:11:21 CET 2012


Hi list:

  I found an panic in sheep today.

Mar 02 23:57:28 fill_entry_new_sha1(178) data sha1:5e630c602d8e18e3ee6643670ddd4a671e5ee922, 8071d67a00000000
Mar 02 23:57:28 omap_file_insert(265) nr is 488
Mar 02 23:57:28 trunk_file_write(315) try delete stale snapshot object 8071d67a00000000, with data sha1: 5d5d171fca6bf63a0b6a0f4db2c7367b8b48bf9b
Mar 02 23:57:28 put_sha1_file(92) No such file or directory 

  It happens when the sheep is killed after omap_file_init but before omap_file_final, and some of the staled snapshot have been unlinked.
Then sheep will always panic every time afterward.
  
  The patch is a proposal to make put_sha1_file tolerant not-exist-file.

  FYI.

diff --git a/sheep/farm/sha1_file.c b/sheep/farm/sha1_file.c
index 3296e12..347c0b5 100644
--- a/sheep/farm/sha1_file.c
+++ b/sheep/farm/sha1_file.c
@@ -88,8 +88,15 @@ static int put_sha1_file(char *name)
 {
 	uint32_t count;
 
-	if (getxattr(name, CNAME, &count, CSIZE) < 0)
+	if (getxattr(name, CNAME, &count, CSIZE) < 0) {
+		if (errno == ENOENT) {
+			dprintf("sha1 file doesn't exist\n");
+			return -1;
+		} else {
 			panic("%m\n");
+		}
+	}
+
 	count--;
 	if (count == 0) {
 		if (unlink(name) < 0) {



More information about the sheepdog mailing list