X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fcryptsetup_reencrypt.c;h=5505431613b2f757cbfdcbb7f05197ad9df2d3da;hb=d67548adfe4b98dc3202646a4239abb9469b7891;hp=16ab1003dff881bb3c9435a2a48e7839460ef85b;hpb=32c578729c2b369ff92a4a2d0df47f57aec7ab45;p=platform%2Fupstream%2Fcryptsetup.git diff --git a/src/cryptsetup_reencrypt.c b/src/cryptsetup_reencrypt.c index 16ab100..5505431 100644 --- a/src/cryptsetup_reencrypt.c +++ b/src/cryptsetup_reencrypt.c @@ -1,12 +1,13 @@ /* * cryptsetup-reencrypt - crypt utility for offline re-encryption * - * Copyright (C) 2012, Milan Broz All rights reserved. * Copyright (C) 2012, Red Hat, Inc. All rights reserved. + * Copyright (C) 2012-2013, Milan Broz All rights reserved. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License - * version 2 as published by the Free Software Foundation. + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -348,38 +349,27 @@ static void close_log(struct reenc_ctx *rc) static int open_log(struct reenc_ctx *rc) { - int flags, create_new; - struct stat st; + int flags = opt_directio ? O_DIRECT : 0; - if (!stat(rc->log_file, &st)) - create_new = 0; - else if (errno == ENOENT) - create_new = 1; - else - return -EINVAL; - - if (create_new) { - log_dbg("Creating LUKS reencryption log file %s.", rc->log_file); - flags = opt_directio ? O_RDWR|O_CREAT|O_DIRECT : O_RDWR|O_CREAT; - rc->log_fd = open(rc->log_file, flags, S_IRUSR|S_IWUSR); - if (rc->log_fd == -1) - return -EINVAL; - } else { + rc->log_fd = open(rc->log_file, O_RDWR|O_EXCL|O_CREAT|flags, S_IRUSR|S_IWUSR); + if (rc->log_fd != -1) { + log_dbg("Created LUKS reencryption log file %s.", rc->log_file); + } else if (errno == EEXIST) { log_std(_("Log file %s exists, resuming reencryption.\n"), rc->log_file); - flags = opt_directio ? O_RDWR|O_DIRECT : O_RDWR; - rc->log_fd = open(rc->log_file, flags); - if (rc->log_fd == -1) - return -EINVAL; + rc->log_fd = open(rc->log_file, O_RDWR|flags); rc->in_progress = 1; } + if (rc->log_fd == -1) + return -EINVAL; + if (posix_memalign((void *)&rc->log_buf, alignment(rc->log_fd), SECTOR_SIZE)) { log_err(_("Allocation of aligned memory failed.\n")); close_log(rc); return -ENOMEM; } - if (create_new && write_log(rc) < 0) { + if (!rc->in_progress && write_log(rc) < 0) { close_log(rc); return -EIO; } @@ -400,6 +390,7 @@ static int activate_luks_headers(struct reenc_ctx *rc) (r = crypt_set_data_device(cd, rc->device))) goto out; + log_verbose(_("Activating temporary device using old LUKS header.\n")); if ((r = crypt_activate_by_passphrase(cd, rc->header_file_org, opt_key_slot, rc->p[rc->keyslot].password, rc->p[rc->keyslot].passwordLen, CRYPT_ACTIVATE_READONLY|CRYPT_ACTIVATE_PRIVATE)) < 0) @@ -410,6 +401,7 @@ static int activate_luks_headers(struct reenc_ctx *rc) (r = crypt_set_data_device(cd_new, rc->device))) goto out; + log_verbose(_("Activating temporary device using new LUKS header.\n")); if ((r = crypt_activate_by_passphrase(cd_new, rc->header_file_new, opt_key_slot, rc->p[rc->keyslot].password, rc->p[rc->keyslot].passwordLen, CRYPT_ACTIVATE_SHARED|CRYPT_ACTIVATE_PRIVATE)) < 0) @@ -629,6 +621,7 @@ static void print_progress(struct reenc_ctx *rc, uint64_t bytes, int final) if (!mib) return; + /* FIXME: calculate this from last minute only and remaining space */ eta = (unsigned long long)(rc->device_size / 1024 / 1024 / mib - tdiff); /* vt100 code clear line */ @@ -938,7 +931,7 @@ static int initialize_passphrase(struct reenc_ctx *rc, const char *device) log_dbg("Passhrases initialization."); if (opt_new && !rc->in_progress) { - r = init_passphrase1(rc, cd, _("Enter new LUKS passphrase: "), 0, 0); + r = init_passphrase1(rc, cd, _("Enter new passphrase: "), 0, 0); return r > 0 ? 0 : r; } @@ -952,14 +945,14 @@ static int initialize_passphrase(struct reenc_ctx *rc, const char *device) if (opt_key_file) { r = init_keyfile(rc, cd, opt_key_slot); } else if (rc->in_progress) { - r = init_passphrase1(rc, cd, _("Enter any LUKS passphrase: "), + r = init_passphrase1(rc, cd, _("Enter any existing passphrase: "), CRYPT_ANY_SLOT, 1); } else for (i = 0; i < MAX_SLOT; i++) { ki = crypt_keyslot_status(cd, i); if (ki != CRYPT_SLOT_ACTIVE && ki != CRYPT_SLOT_ACTIVE_LAST) continue; - snprintf(msg, sizeof(msg), _("Enter LUKS passphrase for key slot %u: "), i); + snprintf(msg, sizeof(msg), _("Enter passphrase for key slot %u: "), i); r = init_passphrase1(rc, cd, msg, i, 1); if (r < 0) break;