Add parameter for progress update without in separate lines.

Useful for reencryption or integrity format.
This commit is contained in:
Milan Broz
2017-10-04 15:22:32 +02:00
parent 59e6b33c6f
commit 7e53c87f5c
8 changed files with 33 additions and 7 deletions

View File

@@ -40,7 +40,7 @@ To start (or continue) re-encryption for <device> use:
\-\-device-size, \-\-hash, \-\-iter-time, \-\-use-random | \-\-use-urandom, \-\-device-size, \-\-hash, \-\-iter-time, \-\-use-random | \-\-use-urandom,
\-\-keep-key, \-\-key-size, \-\-key-file, \-\-key-slot, \-\-keyfile-offset, \-\-keep-key, \-\-key-size, \-\-key-file, \-\-key-slot, \-\-keyfile-offset,
\-\-keyfile-size, \-\-tries, \-\-use-directio, \-\-use-fsync, \-\-verbose, \-\-write-log, \-\-keyfile-size, \-\-tries, \-\-use-directio, \-\-use-fsync, \-\-verbose, \-\-write-log,
\-\-uuid] \-\-uuid, \-\-progress-frequency]
To encrypt data on (not yet encrypted) device, use \fI\-\-new\fR with combination To encrypt data on (not yet encrypted) device, use \fI\-\-new\fR with combination
with \fI\-\-reduce-device-size\fR. with \fI\-\-reduce-device-size\fR.
@@ -192,6 +192,9 @@ of the interrupted decryption process.
.B "\-\-batch-mode, \-q" .B "\-\-batch-mode, \-q"
Suppresses all warnings and reencryption progress output. Suppresses all warnings and reencryption progress output.
.TP .TP
.B "\-\-progress-frequency <seconds>"
Print separate line every <seconds> with reencryption progress.
.TP
.B "\-\-version" .B "\-\-version"
Show the program version. Show the program version.
.SH RETURN CODES .SH RETURN CODES

View File

@@ -924,6 +924,9 @@ Suppresses all confirmation questions. Use with care!
If the \-y option is not specified, this option also switches off If the \-y option is not specified, this option also switches off
the passphrase verification for \fIluksFormat\fR. the passphrase verification for \fIluksFormat\fR.
.TP .TP
.B "\-\-progress-frequency <seconds>"
Print separate line every <seconds> with wipe progress.
.TP
.B "\-\-timeout, \-t <number of seconds>" .B "\-\-timeout, \-t <number of seconds>"
The number of seconds to wait before timeout on passphrase input The number of seconds to wait before timeout on passphrase input
via terminal. It is relevant every time a passphrase is asked, via terminal. It is relevant every time a passphrase is asked,

View File

@@ -20,7 +20,8 @@ Integritysetup supports these operations:
Formats <device> (calculates space and dm-integrity superblock and wipes the device). Formats <device> (calculates space and dm-integrity superblock and wipes the device).
\fB<options>\fR can be [\-\-batch\-mode, \-\-no\-wipe, \-\-journal\-size, \-\-interleave\-sectors, \fB<options>\fR can be [\-\-batch\-mode, \-\-no\-wipe, \-\-journal\-size, \-\-interleave\-sectors,
\-\-tag\-size, \-\-integrity, \-\-integrity\-key\-size, \-\-integrity\-key\-file, \-\-sector\-size] \-\-tag\-size, \-\-integrity, \-\-integrity\-key\-size, \-\-integrity\-key\-file, \-\-sector\-size,
\-\-progress-frequency]
.PP .PP
\fIopen\fR <device> <name> \fIopen\fR <device> <name>
@@ -64,6 +65,9 @@ Show the program version.
.B "\-\-batch\-mode" .B "\-\-batch\-mode"
Do not ask for confirmation. Do not ask for confirmation.
.TP .TP
.B "\-\-progress-frequency <seconds>"
Print separate line every <seconds> with wipe progress.
.TP
.B "\-\-no\-wipe" .B "\-\-no\-wipe"
Do not wipe the device after format. A device that is not initially wiped will contain invalid checksums. Do not wipe the device after format. A device that is not initially wiped will contain invalid checksums.
.TP .TP

View File

@@ -2020,6 +2020,7 @@ int main(int argc, const char **argv)
{ "readonly", 'r', POPT_ARG_NONE, &opt_readonly, 0, N_("Create a readonly mapping"), NULL }, { "readonly", 'r', POPT_ARG_NONE, &opt_readonly, 0, N_("Create a readonly mapping"), NULL },
{ "batch-mode", 'q', POPT_ARG_NONE, &opt_batch_mode, 0, N_("Do not ask for confirmation"), NULL }, { "batch-mode", 'q', POPT_ARG_NONE, &opt_batch_mode, 0, N_("Do not ask for confirmation"), NULL },
{ "timeout", 't', POPT_ARG_INT, &opt_timeout, 0, N_("Timeout for interactive passphrase prompt (in seconds)"), N_("secs") }, { "timeout", 't', POPT_ARG_INT, &opt_timeout, 0, N_("Timeout for interactive passphrase prompt (in seconds)"), N_("secs") },
{ "progress-frequency",'\0', POPT_ARG_INT, &opt_progress_frequency, 0, N_("Progress line update (in seconds)"), N_("secs") },
{ "tries", 'T', POPT_ARG_INT, &opt_tries, 0, N_("How often the input of the passphrase can be retried"), NULL }, { "tries", 'T', POPT_ARG_INT, &opt_tries, 0, N_("How often the input of the passphrase can be retried"), NULL },
{ "align-payload", '\0', POPT_ARG_INT, &opt_align_payload, 0, N_("Align payload at <n> sector boundaries - for luksFormat"), N_("SECTORS") }, { "align-payload", '\0', POPT_ARG_INT, &opt_align_payload, 0, N_("Align payload at <n> sector boundaries - for luksFormat"), N_("SECTORS") },
{ "header-backup-file",'\0', POPT_ARG_STRING, &opt_header_backup_file, 0, N_("File with LUKS header and keyslots backup."), NULL }, { "header-backup-file",'\0', POPT_ARG_STRING, &opt_header_backup_file, 0, N_("File with LUKS header and keyslots backup."), NULL },

View File

@@ -58,6 +58,8 @@ extern int opt_debug;
extern int opt_verbose; extern int opt_verbose;
extern int opt_batch_mode; extern int opt_batch_mode;
extern int opt_force_password; extern int opt_force_password;
extern int opt_progress_frequency;
/* Common tools */ /* Common tools */
void clogger(struct crypt_device *cd, int level, const char *file, int line, void clogger(struct crypt_device *cd, int level, const char *file, int line,

View File

@@ -1267,6 +1267,7 @@ int main(int argc, const char **argv)
{ "key-file", 'd', POPT_ARG_STRING, &opt_key_file, 0, N_("Read the key from a file."), NULL }, { "key-file", 'd', POPT_ARG_STRING, &opt_key_file, 0, N_("Read the key from a file."), NULL },
{ "iter-time", 'i', POPT_ARG_INT, &opt_iteration_time, 0, N_("PBKDF2 iteration time for LUKS (in ms)"), N_("msecs") }, { "iter-time", 'i', POPT_ARG_INT, &opt_iteration_time, 0, N_("PBKDF2 iteration time for LUKS (in ms)"), N_("msecs") },
{ "batch-mode", 'q', POPT_ARG_NONE, &opt_batch_mode, 0, N_("Do not ask for confirmation"), NULL }, { "batch-mode", 'q', POPT_ARG_NONE, &opt_batch_mode, 0, N_("Do not ask for confirmation"), NULL },
{ "progress-frequency",'\0', POPT_ARG_INT, &opt_progress_frequency, 0, N_("Progress line update (in seconds)"), N_("secs") },
{ "tries", 'T', POPT_ARG_INT, &opt_tries, 0, N_("How often the input of the passphrase can be retried"), NULL }, { "tries", 'T', POPT_ARG_INT, &opt_tries, 0, N_("How often the input of the passphrase can be retried"), NULL },
{ "use-random", '\0', POPT_ARG_NONE, &opt_random, 0, N_("Use /dev/random for generating volume key."), NULL }, { "use-random", '\0', POPT_ARG_NONE, &opt_random, 0, N_("Use /dev/random for generating volume key."), NULL },
{ "use-urandom", '\0', POPT_ARG_NONE, &opt_urandom, 0, N_("Use /dev/urandom for generating volume key."), NULL }, { "use-urandom", '\0', POPT_ARG_NONE, &opt_urandom, 0, N_("Use /dev/urandom for generating volume key."), NULL },

View File

@@ -483,6 +483,7 @@ int main(int argc, const char **argv)
{ "verbose", 'v', POPT_ARG_NONE, &opt_verbose, 0, N_("Shows more detailed error messages"), NULL }, { "verbose", 'v', POPT_ARG_NONE, &opt_verbose, 0, N_("Shows more detailed error messages"), NULL },
{ "debug", '\0', POPT_ARG_NONE, &opt_debug, 0, N_("Show debug messages"), NULL }, { "debug", '\0', POPT_ARG_NONE, &opt_debug, 0, N_("Show debug messages"), NULL },
{ "batch-mode", 'q', POPT_ARG_NONE, &opt_batch_mode, 0, N_("Do not ask for confirmation"), NULL }, { "batch-mode", 'q', POPT_ARG_NONE, &opt_batch_mode, 0, N_("Do not ask for confirmation"), NULL },
{ "progress-frequency", '\0', POPT_ARG_INT, &opt_progress_frequency, 0, N_("Progress line update (in seconds)"), N_("secs") },
{ "no-wipe", '\0', POPT_ARG_NONE, &opt_no_wipe, 0, N_("Do not wipe device after format"), NULL }, { "no-wipe", '\0', POPT_ARG_NONE, &opt_no_wipe, 0, N_("Do not wipe device after format"), NULL },
{ "journal-size", 'j', POPT_ARG_STRING,&opt_journal_size_str, 0, N_("Journal size"), N_("bytes") }, { "journal-size", 'j', POPT_ARG_STRING,&opt_journal_size_str, 0, N_("Journal size"), N_("bytes") },

View File

@@ -28,6 +28,7 @@
int opt_verbose = 0; int opt_verbose = 0;
int opt_debug = 0; int opt_debug = 0;
int opt_batch_mode = 0; int opt_batch_mode = 0;
int opt_progress_frequency = 0;
/* interrupt handling */ /* interrupt handling */
volatile int quit = 0; volatile int quit = 0;
@@ -336,9 +337,10 @@ static double time_diff(struct timeval *start, struct timeval *end)
+ (end->tv_usec - start->tv_usec) / 1E6; + (end->tv_usec - start->tv_usec) / 1E6;
} }
// FIXME: detect terminal type
void tools_clear_line(void) void tools_clear_line(void)
{ {
if (opt_progress_frequency)
return;
/* vt100 code clear line */ /* vt100 code clear line */
log_std("\33[2K\r"); log_std("\33[2K\r");
} }
@@ -348,8 +350,9 @@ void tools_time_progress(uint64_t device_size, uint64_t bytes,
{ {
struct timeval now_time; struct timeval now_time;
unsigned long long mbytes, eta; unsigned long long mbytes, eta;
double tdiff, mib; double tdiff, mib, frequency;
int final = (bytes == device_size); int final = (bytes == device_size);
char *eol;
if (opt_batch_mode) if (opt_batch_mode)
return; return;
@@ -361,7 +364,15 @@ void tools_time_progress(uint64_t device_size, uint64_t bytes,
return; return;
} }
if (!final && time_diff(end_time, &now_time) < 0.5) if (opt_progress_frequency) {
frequency = (double)opt_progress_frequency;
eol = "\n";
} else {
frequency = 0.5;
eol = "";
}
if (!final && time_diff(end_time, &now_time) < frequency)
return; return;
*end_time = now_time; *end_time = now_time;
@@ -388,9 +399,9 @@ void tools_time_progress(uint64_t device_size, uint64_t bytes,
mbytes, mib); mbytes, mib);
else else
log_std("Progress: %5.1f%%, ETA %02llu:%02llu, " log_std("Progress: %5.1f%%, ETA %02llu:%02llu, "
"%4llu MiB written, speed %5.1f MiB/s", "%4llu MiB written, speed %5.1f MiB/s%s",
(double)bytes / device_size * 100, (double)bytes / device_size * 100,
eta / 60, eta % 60, mbytes, mib); eta / 60, eta % 60, mbytes, mib, eol);
fflush(stdout); fflush(stdout);
} }