Commit 5a02dd31 authored by Mike Hibler's avatar Mike Hibler

Add -Z option to zero free space included in the image due to -F.

Previously, this "internal free space" was whatever garbage happened to
be on the disk we were imaging. By zeroing, we eliminate any leakage of
information from the source disk and also allow the image to compress just
a tad (1-4%) better.

Why isn't this the default? Eh...no good reason, other than that this whole
squish-out-small-free-ranges-to-allow-longer-writes optimization should be
done by the client and should not be encoded in the image.
parent cfc9612a
...@@ -65,6 +65,7 @@ int level = 4; ...@@ -65,6 +65,7 @@ int level = 4;
long dev_bsize = 1; long dev_bsize = 1;
uint32_t compat = 0; uint32_t compat = 0;
int frangesize= 64; /* 32k */ int frangesize= 64; /* 32k */
int zerofrange= 0;
int forcereads= 0; int forcereads= 0;
int badsectors= 0; int badsectors= 0;
int retrywrites= 1; int retrywrites= 1;
...@@ -403,7 +404,7 @@ main(int argc, char *argv[]) ...@@ -403,7 +404,7 @@ main(int argc, char *argv[])
memset(imageid, UUID_LENGTH, '\0'); memset(imageid, UUID_LENGTH, '\0');
gettimeofday(&sstamp, 0); gettimeofday(&sstamp, 0);
while ((ch = getopt(argc, argv, "vlbnNdihrs:c:z:ofI:13F:DR:S:XH:Me:k:u:a:")) != -1) while ((ch = getopt(argc, argv, "vlbnNdihrs:c:z:ofI:13F:DR:S:XH:Me:k:u:a:Z")) != -1)
switch(ch) { switch(ch) {
case 'v': case 'v':
version++; version++;
...@@ -471,6 +472,9 @@ main(int argc, char *argv[]) ...@@ -471,6 +472,9 @@ main(int argc, char *argv[])
if (frangesize < 0) if (frangesize < 0)
usage(); usage();
break; break;
case 'Z':
zerofrange = 1;
break;
case 'X': case 'X':
forcereads++; forcereads++;
break; break;
...@@ -1176,6 +1180,20 @@ dumpskips(int verbose) ...@@ -1176,6 +1180,20 @@ dumpskips(int verbose)
#undef DOHISTO #undef DOHISTO
/*
* Zero the data associated with a free range that is being included
* in the image because its size is less than frangesize.
*/
static void
zerofixup(void *bstart, off_t bsize, void *fdata)
{
if (debug > 1)
fprintf(stderr, "zerofixup: zeroing %llu@%p\n",
(unsigned long long)bsize, bstart);
memset(bstart, 0, bsize);
}
/* /*
* Sort and merge the list of skip blocks. * Sort and merge the list of skip blocks.
* This code also winnows out the free ranges smaller than frangesize. * This code also winnows out the free ranges smaller than frangesize.
...@@ -1209,6 +1227,12 @@ mergeskips(int verbose) ...@@ -1209,6 +1227,12 @@ mergeskips(int verbose)
"dropping range [%u-%u]\n", "dropping range [%u-%u]\n",
prange->start, prange->start,
prange->start+prange->size-1); prange->start+prange->size-1);
if (zerofrange)
addfixupfunc(zerofixup,
sectobytes(prange->start),
0,
sectobytes(prange->size),
NULL, 0, RELOC_NONE);
total += prange->size; total += prange->size;
#ifdef DOHISTO #ifdef DOHISTO
if (prange->size < 64) if (prange->size < 64)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment