[sheepdog] [PATCH v2 5/6] collie: add sd_read_object_sha1() to common.c

Kai Zhang kyle at zelin.io
Sat Jun 8 04:02:32 CEST 2013


Signed-off-by: Kai Zhang <kyle at zelin.io>
---
 collie/collie.h |    2 ++
 collie/common.c |   27 +++++++++++++++++++++++++++
 2 files changed, 29 insertions(+), 0 deletions(-)

diff --git a/collie/collie.h b/collie/collie.h
index 1d89558..18b9c08 100644
--- a/collie/collie.h
+++ b/collie/collie.h
@@ -65,6 +65,8 @@ typedef void (*vdi_parser_func_t)(uint32_t vid, const char *name,
 				  uint32_t flags,
 				  const struct sd_inode *i, void *data);
 int parse_vdi(vdi_parser_func_t func, size_t size, void *data);
+int sd_read_object_sha1(uint64_t oid, uint32_t epoch, int nr_copies,
+			unsigned char *sha1);
 int sd_read_object(uint64_t oid, void *data, unsigned int datalen,
 		   uint64_t offset, bool direct);
 int sd_write_object(uint64_t oid, uint64_t cow_oid, void *data,
diff --git a/collie/common.c b/collie/common.c
index 2b08db1..bb8dd2e 100644
--- a/collie/common.c
+++ b/collie/common.c
@@ -37,6 +37,33 @@ char *size_to_str(uint64_t _size, char *str, int str_size)
 	return str;
 }
 
+int sd_read_object_sha1(uint64_t oid, uint32_t epoch, int nr_copies,
+			unsigned char *sha1)
+{
+	struct sd_req req;
+	struct sd_rsp *rsp = (struct sd_rsp *)&req;
+	const struct sd_vnode *vnode = NULL;
+	char host[HOST_NAME_MAX];
+	int port, ret = -1;
+
+	sd_init_req(&req, SD_OP_GET_HASH);
+	req.obj.oid = oid;
+	req.obj.tgt_epoch = epoch;
+
+	for (int i = 0; i < nr_copies; i++) {
+		vnode = oid_to_vnode(sd_vnodes, sd_vnodes_nr, oid, i);
+		addr_to_str(host, sizeof(host), vnode->nid.addr, 0);
+		port = vnode->nid.port;
+		if (collie_exec_req(host, port, &req, NULL) == 0) {
+			memcpy(sha1, rsp->hash.digest, SHA1_LEN);
+			ret = 0;
+			goto out;
+		}
+	}
+out:
+	return ret;
+}
+
 int sd_read_object(uint64_t oid, void *data, unsigned int datalen,
 		   uint64_t offset, bool direct)
 {
-- 
1.7.1




More information about the sheepdog mailing list