From: Liu Yuan <tailai.ly at taobao.com> Remove useless code for recovery handling. Signed-off-by: Liu Yuan <tailai.ly at taobao.com> --- sheep/farm/farm.c | 12 ++++++------ sheep/farm/farm.h | 8 ++++---- sheep/farm/snap.c | 40 +++++----------------------------------- 3 files changed, 15 insertions(+), 45 deletions(-) diff --git a/sheep/farm/farm.c b/sheep/farm/farm.c index 4ccd629..f5b26b1 100644 --- a/sheep/farm/farm.c +++ b/sheep/farm/farm.c @@ -112,14 +112,14 @@ int prealloc(int fd, uint32_t size) return ret; } -static int get_trunk_sha1(uint32_t epoch, unsigned char *outsha1, int user) +static int get_trunk_sha1(uint32_t epoch, unsigned char *outsha1) { int i, nr_logs = -1, ret = -1; struct snap_log *log_buf, *log_free = NULL; void *snap_buf = NULL; struct sha1_file_hdr hdr; - log_free = log_buf = snap_log_read(&nr_logs, user); + log_free = log_buf = snap_log_read(&nr_logs); dprintf("%d\n", nr_logs); if (nr_logs < 0) goto out; @@ -180,7 +180,7 @@ static int farm_snapshot(struct siocb *iocb) void *buffer; int log_nr, ret = SD_RES_EIO, epoch; - buffer = snap_log_read(&log_nr, 1); + buffer = snap_log_read(&log_nr); if (!buffer) goto out; @@ -198,7 +198,7 @@ static int farm_snapshot(struct siocb *iocb) trunk_sha1, snap_sha1) < 0) goto out; - if (snap_log_write(epoch, snap_sha1, 1) < 0) + if (snap_log_write(epoch, snap_sha1) < 0) goto out; ret = SD_RES_SUCCESS; @@ -240,7 +240,7 @@ static int restore_objects_from_snap(uint32_t epoch) uint64_t nr_trunks, i; int ret = SD_RES_EIO; - if (get_trunk_sha1(epoch, trunk_sha1, 1) < 0) + if (get_trunk_sha1(epoch, trunk_sha1) < 0) goto out; trunk_free = trunk_buf = trunk_file_read(trunk_sha1, &hdr); @@ -303,7 +303,7 @@ static int farm_get_snap_file(struct siocb *iocb) int nr; dprintf("try get snap file\n"); - buffer = snap_log_read(&nr, 1); + buffer = snap_log_read(&nr); if (!buffer) goto out; size = nr * sizeof(struct snap_log); diff --git a/sheep/farm/farm.h b/sheep/farm/farm.h index af803b6..1a0081e 100644 --- a/sheep/farm/farm.h +++ b/sheep/farm/farm.h @@ -44,8 +44,8 @@ extern char farm_dir[PATH_MAX]; extern char farm_obj_dir[PATH_MAX]; /* sha1_file.c */ extern char *sha1_to_path(const unsigned char *sha1); -extern int sha1_file_write(unsigned char *buf, unsigned len, unsigned char *outsha1); -extern void *sha1_file_read(const unsigned char *sha1, struct sha1_file_hdr *hdr); +extern int sha1_file_write(unsigned char *buf, unsigned len, unsigned char *); +extern void *sha1_file_read(const unsigned char *sha1, struct sha1_file_hdr *); extern char *sha1_to_hex(const unsigned char *sha1); extern int get_sha1_hex(const char *hex, unsigned char *sha1); extern int sha1_file_try_delete(const unsigned char *sha1); @@ -61,7 +61,7 @@ extern void *snap_file_read(unsigned char *sha1, struct sha1_file_hdr *outhdr); extern int snap_file_write(uint32_t epoch, struct sd_node *nodes, int nr_nodes, unsigned char *trunksha1, unsigned char *outsha1); extern int snap_log_truncate(void); -extern void *snap_log_read(int *, int user); -extern int snap_log_write(uint32_t epoch, unsigned char *sha1, int user); +extern void *snap_log_read(int *); +extern int snap_log_write(uint32_t epoch, unsigned char *sha1); #endif diff --git a/sheep/farm/snap.c b/sheep/farm/snap.c index d819ebb..88294cc 100644 --- a/sheep/farm/snap.c +++ b/sheep/farm/snap.c @@ -28,19 +28,6 @@ int snap_init(void) struct strbuf buf = STRBUF_INIT; strbuf_addstr(&buf, farm_dir); - strbuf_addf(&buf, "/%s", "sys_snap"); - - fd = open(buf.buf, O_CREAT | O_EXCL, 0666); - if (fd < 0) { - if (errno != EEXIST) { - ret = -1; - goto out; - } - } - close(fd); - - strbuf_reset(&buf); - strbuf_addstr(&buf, farm_dir); strbuf_addf(&buf, "/%s", "user_snap"); fd = open(buf.buf, O_CREAT | O_EXCL, 0666); @@ -57,24 +44,7 @@ out: return ret; } -int snap_log_truncate(void) -{ - int ret = 0; - struct strbuf buf = STRBUF_INIT; - - strbuf_addstr(&buf, farm_dir); - strbuf_addf(&buf, "/%s", "sys_snap"); - - if (truncate(buf.buf, 0) < 0) { - dprintf("truncate snapshot log file fail:%m.\n"); - ret = -1; - } - - strbuf_release(&buf); - return ret; -} - -int snap_log_write(uint32_t epoch, unsigned char *sha1, int user) +int snap_log_write(uint32_t epoch, unsigned char *sha1) { int fd, ret = -1; struct strbuf buf = STRBUF_INIT; @@ -83,7 +53,7 @@ int snap_log_write(uint32_t epoch, unsigned char *sha1, int user) memcpy(log.sha1, sha1, SHA1_LEN); strbuf_addstr(&buf, farm_dir); - strbuf_addf(&buf, "/%s", user ? "user_snap" : "sys_snap"); + strbuf_addf(&buf, "/%s", "user_snap"); fd = open(buf.buf, O_WRONLY | O_APPEND); if (fd < 0) { @@ -103,7 +73,7 @@ out: return ret; } -void *snap_log_read(int *out_nr, int user) +void *snap_log_read(int *out_nr) { struct strbuf buf = STRBUF_INIT; struct stat st; @@ -111,7 +81,7 @@ void *snap_log_read(int *out_nr, int user) int len, fd; strbuf_addstr(&buf, farm_dir); - strbuf_addf(&buf, "/%s", user ? "user_snap" : "sys_snap"); + strbuf_addf(&buf, "/%s", "user_snap"); fd = open(buf.buf, O_RDONLY); if (fd < 0) { @@ -156,7 +126,7 @@ void *snap_file_read(unsigned char *sha1, struct sha1_file_hdr *outhdr) } int snap_file_write(uint32_t epoch, struct sd_node *nodes, int nr_nodes, - unsigned char *trunksha1, unsigned char *outsha1) + unsigned char *trunksha1, unsigned char *outsha1) { int ret = 0; struct strbuf buf = STRBUF_INIT; -- 1.7.1 |