[sheepdog] [PATCH 1/2] farm: remove xattr code in sha1.c

Liu Yuan namei.unix at gmail.com
Wed Jul 24 07:36:41 CEST 2013


refcount of sha1 file for deletion makes use of xattr, but currently we don't
support snapshot deletion yet.

This patch remove xattr code completely because:
- deletion snapshots can be exercised by
  1. export the snapshots you want to keep to another snapshot storage
  2. delete the old snapshot storage.

- Assume storage for storing snapshots to support xattr is very lame, e.g., we
  we can't rely on Amazon's S3 storage to support kind of xattr.

Signed-off-by: Liu Yuan <namei.unix at gmail.com>
---
 collie/farm/farm.h      |    1 -
 collie/farm/sha1_file.c |   54 -----------------------------------------------
 2 files changed, 55 deletions(-)

diff --git a/collie/farm/farm.h b/collie/farm/farm.h
index aa82b0f..246f493 100644
--- a/collie/farm/farm.h
+++ b/collie/farm/farm.h
@@ -69,7 +69,6 @@ int snap_log_write(uint32_t idx, const char *tag, unsigned char *sha1);
 int sha1_file_write(void *buf, size_t len, unsigned char *sha1);
 void *sha1_file_read(const unsigned char *sha1, size_t *size);
 int get_sha1_hex(const char *hex, unsigned char *sha1);
-int sha1_file_try_delete(const unsigned char *sha1);
 
 /* object_tree.c */
 int object_tree_size(void);
diff --git a/collie/farm/sha1_file.c b/collie/farm/sha1_file.c
index 251243d..2ec1c37 100644
--- a/collie/farm/sha1_file.c
+++ b/collie/farm/sha1_file.c
@@ -23,7 +23,6 @@
  *     by verifying that their hashes match the content of the file.
  */
 #include <sys/types.h>
-#include <sys/xattr.h>
 
 #include "farm.h"
 #include "util.h"
@@ -58,51 +57,6 @@ static char *sha1_to_path(const unsigned char *sha1)
 	return buf;
 }
 
-#define CNAME	"user.farm.count"
-#define CSIZE	sizeof(uint32_t)
-
-static void get_sha1_file(char *name)
-{
-	uint32_t count;
-	if (getxattr(name, CNAME, &count, CSIZE) < 0) {
-		if (errno == ENODATA) {
-			count = 1;
-			if (setxattr(name, CNAME, &count, CSIZE, 0) < 0)
-				panic("%m");
-			return;
-		} else
-			panic("%m");
-	}
-	count++;
-	if (setxattr(name, CNAME, &count, CSIZE, 0) < 0)
-		panic("%m");
-}
-
-static int put_sha1_file(char *name)
-{
-	uint32_t count;
-
-	if (getxattr(name, CNAME, &count, CSIZE) < 0) {
-		if (errno == ENOENT) {
-			fprintf(stderr, "sha1 file doesn't exist.\n");
-			return -1;
-		} else
-			panic("%m");
-	}
-
-	count--;
-	if (count == 0) {
-		if (unlink(name) < 0) {
-			fprintf(stderr, "%m\n");
-			return -1;
-		}
-	} else {
-		if (setxattr(name, CNAME, &count, CSIZE, 0) < 0)
-			panic("%m");
-	}
-	return 0;
-}
-
 static int sha1_buffer_write(const unsigned char *sha1,
 			     void *buf, unsigned int size)
 {
@@ -127,7 +81,6 @@ static int sha1_buffer_write(const unsigned char *sha1,
 	}
 
 	close(fd);
-	get_sha1_file(filename);
 err_open:
 	return ret;
 }
@@ -196,13 +149,6 @@ out:
 	return buf;
 }
 
-int sha1_file_try_delete(const unsigned char *sha1)
-{
-	char *filename = sha1_to_path(sha1);
-
-	return put_sha1_file(filename);
-}
-
 static unsigned hexval(char c)
 {
 	if (c >= '0' && c <= '9')
-- 
1.7.9.5




More information about the sheepdog mailing list