commit 820025dc64924ea3ad82dcf3f7c4a8f99f3f671b
parent 1645c1ef873c034c8cff4251350df524b789487d
Author: sin <sin@2f30.org>
Date: Sat, 2 Mar 2019 00:46:11 +0000
Move stats around
Diffstat:
M | dedup.c | | | 20 | ++++++++++---------- |
M | dedup.h | | | 21 | ++++++++++----------- |
M | types.c | | | 64 | ++++++++++++++++++++++++---------------------------------------- |
3 files changed, 44 insertions(+), 61 deletions(-)
diff --git a/dedup.c b/dedup.c
@@ -216,8 +216,8 @@ dedup_chunk(struct snapshot *snap, uint8_t *chunkp, size_t chunk_size)
n = comp(chunkp, comp_buf, chunk_size, comp_size(BLKSIZE_MAX));
hash_blk(comp_buf, n, md);
- blk_hdr.st.orig_size += chunk_size;
- blk_hdr.st.comp_size += n;
+ snap_hdr.st.orig_size += chunk_size;
+ snap_hdr.st.comp_size += n;
memcpy(cache_entry.md, md, sizeof(cache_entry.md));
if (lookup_cache_entry(cache, &cache_entry) < 0) {
@@ -236,13 +236,13 @@ dedup_chunk(struct snapshot *snap, uint8_t *chunkp, size_t chunk_size)
add_cache_entry(cache, &cache_entry);
cache_misses++;
- blk_hdr.st.dedup_size += blk_desc.size;
- blk_hdr.st.nr_blks++;
+ snap_hdr.st.dedup_size += blk_desc.size;
+ snap_hdr.st.nr_blks++;
- if (blk_desc.size > blk_hdr.st.max_blk_size)
- blk_hdr.st.max_blk_size = blk_desc.size;
- if (blk_desc.size < blk_hdr.st.min_blk_size)
- blk_hdr.st.min_blk_size = blk_desc.size;
+ if (blk_desc.size > snap_hdr.st.max_blk_size)
+ snap_hdr.st.max_blk_size = blk_desc.size;
+ if (blk_desc.size < snap_hdr.st.min_blk_size)
+ snap_hdr.st.min_blk_size = blk_desc.size;
} else {
struct blk_desc blk_desc;
@@ -494,7 +494,6 @@ load_blk_hdr(void)
if (sb.st_size == 0) {
blk_hdr.flags = (VER_MAJ << 8) | VER_MIN;
blk_hdr.size = BLK_HDR_LEN;
- blk_hdr.st.min_blk_size = comp_size(BLKSIZE_MAX);
write_blk_hdr(sfd, &blk_hdr);
return;
}
@@ -520,6 +519,7 @@ load_snap_hdr(void)
if (sb.st_size == 0) {
snap_hdr.flags = (VER_MAJ << 8) | VER_MIN;
snap_hdr.size = SNAP_HDR_LEN;
+ snap_hdr.st.min_blk_size = comp_size(BLKSIZE_MAX);
write_snap_hdr(ifd, &snap_hdr);
return;
}
@@ -566,7 +566,7 @@ static void
term(void)
{
if (verbose > 0)
- print_stats(&blk_hdr.st);
+ print_stats(&snap_hdr.st);
save_snap_hdr();
save_blk_hdr();
diff --git a/dedup.h b/dedup.h
@@ -6,8 +6,8 @@
* using the helpers from types.c. Any modification made to
* the structs below will need to be reflected here and in types.c.
*/
-#define SNAP_HDR_LEN 56
-#define BLK_HDR_LEN 112
+#define SNAP_HDR_LEN 104
+#define BLK_HDR_LEN 16
#define BLK_DESC_LEN 48
#define SNAPSHOT_LEN 304
#define CACHE_ENTRY_LEN 48
@@ -22,13 +22,6 @@
struct cache;
struct chunker;
-struct snapshot_hdr {
- uint64_t flags; /* bottom 16 bits are maj/min version */
- uint64_t size; /* size of snapshots file */
- uint64_t nr_snapshots;
- uint64_t reserved[4];
-};
-
struct stats {
uint64_t orig_size; /* original store size */
uint64_t comp_size; /* compressed store size */
@@ -36,13 +29,19 @@ struct stats {
uint64_t min_blk_size;
uint64_t max_blk_size;
uint64_t nr_blks; /* number of unique blocks */
- uint64_t reserved[6];
+ uint64_t reserved[4];
+};
+
+struct snapshot_hdr {
+ uint64_t flags; /* bottom 16 bits are maj/min version */
+ uint64_t size; /* size of snapshots file */
+ uint64_t nr_snapshots;
+ struct stats st;
};
struct blk_hdr {
uint64_t flags; /* bottom 16 bits are maj/min version */
uint64_t size; /* size of store file */
- struct stats st;
};
struct blk_desc {
diff --git a/types.c b/types.c
@@ -20,11 +20,19 @@ read_snap_hdr(int fd, struct snapshot_hdr *hdr)
&hdr->size,
&hdr->nr_snapshots);
+ n += unpack(&buf[n], "qqqqqq",
+ &hdr->st.orig_size,
+ &hdr->st.comp_size,
+ &hdr->st.dedup_size,
+ &hdr->st.min_blk_size,
+ &hdr->st.max_blk_size,
+ &hdr->st.nr_blks);
+
n += unpack(&buf[n], "qqqq",
- &hdr->reserved[0],
- &hdr->reserved[1],
- &hdr->reserved[2],
- &hdr->reserved[3]);
+ &hdr->st.reserved[0],
+ &hdr->st.reserved[1],
+ &hdr->st.reserved[2],
+ &hdr->st.reserved[3]);
assert(n == SNAP_HDR_LEN);
}
@@ -40,11 +48,19 @@ write_snap_hdr(int fd, struct snapshot_hdr *hdr)
hdr->size,
hdr->nr_snapshots);
+ n += pack(&buf[n], "qqqqqq",
+ hdr->st.orig_size,
+ hdr->st.comp_size,
+ hdr->st.dedup_size,
+ hdr->st.min_blk_size,
+ hdr->st.max_blk_size,
+ hdr->st.nr_blks);
+
n += pack(&buf[n], "qqqq",
- hdr->reserved[0],
- hdr->reserved[1],
- hdr->reserved[2],
- hdr->reserved[3]);
+ hdr->st.reserved[0],
+ hdr->st.reserved[1],
+ hdr->st.reserved[2],
+ hdr->st.reserved[3]);
assert(n == SNAP_HDR_LEN);
xwrite(fd, buf, n);
@@ -63,22 +79,6 @@ read_blk_hdr(int fd, struct blk_hdr *hdr)
&hdr->flags,
&hdr->size);
- n += unpack(&buf[n], "qqqqqq",
- &hdr->st.orig_size,
- &hdr->st.comp_size,
- &hdr->st.dedup_size,
- &hdr->st.min_blk_size,
- &hdr->st.max_blk_size,
- &hdr->st.nr_blks);
-
- n += unpack(&buf[n], "qqqqqq",
- &hdr->st.reserved[0],
- &hdr->st.reserved[1],
- &hdr->st.reserved[2],
- &hdr->st.reserved[3],
- &hdr->st.reserved[4],
- &hdr->st.reserved[5]);
-
assert(n == BLK_HDR_LEN);
}
@@ -92,22 +92,6 @@ write_blk_hdr(int fd, struct blk_hdr *hdr)
hdr->flags,
hdr->size);
- n += pack(&buf[n], "qqqqqq",
- hdr->st.orig_size,
- hdr->st.comp_size,
- hdr->st.dedup_size,
- hdr->st.min_blk_size,
- hdr->st.max_blk_size,
- hdr->st.nr_blks);
-
- n += pack(&buf[n], "qqqqqq",
- hdr->st.reserved[0],
- hdr->st.reserved[1],
- hdr->st.reserved[2],
- hdr->st.reserved[3],
- hdr->st.reserved[4],
- hdr->st.reserved[5]);
-
assert(n == BLK_HDR_LEN);
xwrite(fd, buf, n);
}