[sheepdog] [PATCH 1/4] dog/farm: kill snap file
Liu Yuan
namei.unix at gmail.com
Fri Mar 14 13:04:37 CET 2014
snap file is used to store [idx, trunk_sha1] pairs, but since we already have
sha1 information in struct snap_log, we don't need it at all and we can directly
store trunk sha1 in snap_log.
Signed-off-by: Liu Yuan <namei.unix at gmail.com>
---
dog/farm/farm.c | 13 ++-----------
dog/farm/farm.h | 10 +---------
dog/farm/snap.c | 19 +------------------
3 files changed, 4 insertions(+), 38 deletions(-)
diff --git a/dog/farm/farm.c b/dog/farm/farm.c
index 7d93406..c5af9ed 100644
--- a/dog/farm/farm.c
+++ b/dog/farm/farm.c
@@ -176,7 +176,6 @@ static int get_trunk_sha1(uint32_t idx, const char *tag, unsigned char *outsha1)
{
int nr_logs = -1, ret = -1;
struct snap_log *log_buf, *log_free = NULL;
- struct snap_file *snap_buf = NULL;
log_free = log_buf = snap_log_read(&nr_logs);
if (nr_logs < 0)
@@ -185,16 +184,12 @@ static int get_trunk_sha1(uint32_t idx, const char *tag, unsigned char *outsha1)
for (int i = 0; i < nr_logs; i++, log_buf++) {
if (log_buf->idx != idx && strcmp(log_buf->tag, tag))
continue;
- snap_buf = snap_file_read(log_buf->sha1);
- if (!snap_buf)
- goto out;
- memcpy(outsha1, snap_buf->trunk_sha1, SHA1_DIGEST_SIZE);
+ memcpy(outsha1, log_buf->trunk_sha1, SHA1_DIGEST_SIZE);
ret = 0;
goto out;
}
out:
free(log_free);
- free(snap_buf);
return ret;
}
@@ -314,7 +309,6 @@ static int queue_save_snapshot_work(uint64_t oid, uint32_t nr_copies,
int farm_save_snapshot(const char *tag)
{
- unsigned char snap_sha1[SHA1_DIGEST_SIZE];
unsigned char trunk_sha1[SHA1_DIGEST_SIZE];
struct strbuf trunk_buf;
void *snap_log = NULL;
@@ -342,10 +336,7 @@ int farm_save_snapshot(const char *tag)
trunk_sha1) < 0)
goto out;
- if (snap_file_write(idx, trunk_sha1, snap_sha1) < 0)
- goto out;
-
- if (snap_log_write(idx, tag, snap_sha1) < 0)
+ if (snap_log_write(idx, tag, trunk_sha1) < 0)
goto out;
ret = 0;
diff --git a/dog/farm/farm.h b/dog/farm/farm.h
index c045845..e838a58 100644
--- a/dog/farm/farm.h
+++ b/dog/farm/farm.h
@@ -31,16 +31,11 @@ struct trunk_file {
struct trunk_entry *entries;
};
-struct snap_file {
- int idx;
- unsigned char trunk_sha1[SHA1_DIGEST_SIZE];
-};
-
struct snap_log {
uint32_t idx;
char tag[SD_MAX_SNAPSHOT_TAG_LEN];
uint64_t time;
- unsigned char sha1[SHA1_DIGEST_SIZE];
+ unsigned char trunk_sha1[SHA1_DIGEST_SIZE];
};
/* farm.c */
@@ -61,9 +56,6 @@ uint64_t trunk_get_count(void);
/* snap.c */
int snap_init(const char *path);
-struct snap_file *snap_file_read(unsigned char *sha1);
-int snap_file_write(uint32_t idx, unsigned char *trunk_sha1,
- unsigned char *outsha1);
void *snap_log_read(int *out_nr);
int snap_log_write(uint32_t idx, const char *tag, unsigned char *sha1);
diff --git a/dog/farm/snap.c b/dog/farm/snap.c
index 8c46484..5e889d7 100644
--- a/dog/farm/snap.c
+++ b/dog/farm/snap.c
@@ -56,7 +56,7 @@ int snap_log_write(uint32_t idx, const char *tag, unsigned char *sha1)
struct snap_log log = { .idx = idx,
.time = time(NULL) };
pstrcpy(log.tag, SD_MAX_SNAPSHOT_TAG_LEN, tag);
- memcpy(log.sha1, sha1, SHA1_DIGEST_SIZE);
+ memcpy(log.trunk_sha1, sha1, SHA1_DIGEST_SIZE);
fd = open(snap_log_path, O_WRONLY | O_APPEND);
if (fd < 0) {
@@ -108,20 +108,3 @@ out_close:
out:
return buffer;
}
-
-struct snap_file *snap_file_read(unsigned char *sha1)
-{
- size_t size;
- return sha1_file_read(sha1, &size);
-}
-
-int snap_file_write(uint32_t idx, unsigned char *trunk_sha1,
- unsigned char *outsha1)
-{
- struct snap_file snap;
- snap.idx = idx;
- memcpy(snap.trunk_sha1, trunk_sha1, SHA1_DIGEST_SIZE);
-
- return sha1_file_write(&snap, sizeof(struct snap_file),
- outsha1);
-}
--
1.8.1.2
More information about the sheepdog
mailing list