Use monotonic clock for cryptfs progress
Otherwise we get strange results when the time changes. Worst effect is that the encryption takes a lot longer since we are calling the logging code far more frequently. Bug: 17625981 Change-Id: Ice29f28b3720e9e4a1ea28e45eeab574d1959ec1
This commit is contained in:
parent
3574b085f4
commit
9c58a871f9
1 changed files with 27 additions and 15 deletions
16
cryptfs.c
16
cryptfs.c
|
@ -40,6 +40,7 @@
|
||||||
#include <ext4.h>
|
#include <ext4.h>
|
||||||
#include <linux/kdev_t.h>
|
#include <linux/kdev_t.h>
|
||||||
#include <fs_mgr.h>
|
#include <fs_mgr.h>
|
||||||
|
#include <time.h>
|
||||||
#include "cryptfs.h"
|
#include "cryptfs.h"
|
||||||
#define LOG_TAG "Cryptfs"
|
#define LOG_TAG "Cryptfs"
|
||||||
#include "cutils/log.h"
|
#include "cutils/log.h"
|
||||||
|
@ -2127,7 +2128,11 @@ static void update_progress(struct encryptGroupsData* data, int is_used)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data->cur_pct >= 5) {
|
if (data->cur_pct >= 5) {
|
||||||
double elapsed_time = difftime(time(NULL), data->time_started);
|
struct timespec time_now;
|
||||||
|
if (clock_gettime(CLOCK_MONOTONIC, &time_now)) {
|
||||||
|
SLOGW("Error getting time");
|
||||||
|
} else {
|
||||||
|
double elapsed_time = difftime(time_now.tv_sec, data->time_started);
|
||||||
off64_t remaining_blocks = data->tot_used_blocks
|
off64_t remaining_blocks = data->tot_used_blocks
|
||||||
- data->used_blocks_already_done;
|
- data->used_blocks_already_done;
|
||||||
int remaining_time = (int)(elapsed_time * remaining_blocks
|
int remaining_time = (int)(elapsed_time * remaining_blocks
|
||||||
|
@ -2145,6 +2150,7 @@ static void update_progress(struct encryptGroupsData* data, int is_used)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void log_progress(struct encryptGroupsData const* data, bool completed)
|
static void log_progress(struct encryptGroupsData const* data, bool completed)
|
||||||
{
|
{
|
||||||
|
@ -2349,7 +2355,13 @@ static int cryptfs_enable_inplace_ext4(char *crypto_blkdev,
|
||||||
|
|
||||||
data.one_pct = data.tot_used_blocks / 100;
|
data.one_pct = data.tot_used_blocks / 100;
|
||||||
data.cur_pct = 0;
|
data.cur_pct = 0;
|
||||||
data.time_started = time(NULL);
|
|
||||||
|
struct timespec time_started = {0};
|
||||||
|
if (clock_gettime(CLOCK_MONOTONIC, &time_started)) {
|
||||||
|
SLOGW("Error getting time at start");
|
||||||
|
// Note - continue anyway - we'll run with 0
|
||||||
|
}
|
||||||
|
data.time_started = time_started.tv_sec;
|
||||||
data.remaining_time = -1;
|
data.remaining_time = -1;
|
||||||
|
|
||||||
rc = encrypt_groups(&data);
|
rc = encrypt_groups(&data);
|
||||||
|
|
Loading…
Reference in a new issue