From patchwork Mon Nov 14 06:25:13 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kazuya Mio X-Patchwork-Id: 125486 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 9A118B7134 for ; Mon, 14 Nov 2011 17:32:15 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752097Ab1KNGcO (ORCPT ); Mon, 14 Nov 2011 01:32:14 -0500 Received: from TYO201.gate.nec.co.jp ([202.32.8.193]:57380 "EHLO tyo201.gate.nec.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751855Ab1KNGcO (ORCPT ); Mon, 14 Nov 2011 01:32:14 -0500 Received: from mailgate3.nec.co.jp ([10.7.69.197]) by tyo201.gate.nec.co.jp (8.13.8/8.13.4) with ESMTP id pAE6W9Op017414; Mon, 14 Nov 2011 15:32:09 +0900 (JST) Received: (from root@localhost) by mailgate3.nec.co.jp (8.11.7/3.7W-MAILGATE-NEC) id pAE6W9I02927; Mon, 14 Nov 2011 15:32:09 +0900 (JST) Received: from mail03.kamome.nec.co.jp (mail03.kamome.nec.co.jp [10.25.43.7]) by mailsv.nec.co.jp (8.13.8/8.13.4) with ESMTP id pAE6W8nC005990; Mon, 14 Nov 2011 15:32:08 +0900 (JST) Received: from yonosuke.jp.nec.com ([10.26.220.15] [10.26.220.15]) by mail03.kamome.nec.co.jp with ESMTP id BT-MMP-2013779; Mon, 14 Nov 2011 15:25:13 +0900 Received: from [10.64.168.30] ([10.64.168.30] [10.64.168.30]) by mail.jp.nec.com with ESMTP; Mon, 14 Nov 2011 15:25:13 +0900 Message-ID: <4EC0B449.4010409@sx.jp.nec.com> Date: Mon, 14 Nov 2011 15:25:13 +0900 From: Kazuya Mio User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; ja; rv:1.9.2.18) Gecko/20110613 Thunderbird/3.1.11 MIME-Version: 1.0 To: ext4 CC: Theodore Tso , Andreas Dilger Subject: [PATCH v3 09/11] e4defrag: Fix error messages more clearly Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org There are some error messages we don't really understand what happens. This patch fixes those messages. Signed-off-by: Kazuya Mio --- misc/e4defrag.c | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/misc/e4defrag.c b/misc/e4defrag.c index 7cf0cf0..9938c12 100644 --- a/misc/e4defrag.c +++ b/misc/e4defrag.c @@ -324,6 +324,7 @@ static int is_ext4(const char *file) mnt_type = realloc(mnt_type, strlen(mnt->mnt_type) + 1); if (mnt_type == NULL) { + perror("Failed to allocate memory"); endmntent(fp); return -1; } @@ -518,10 +519,9 @@ static int file_frag_count(int fd) * * @fd: defrag target file's descriptor. * @file: file name. - * @extents: file extents. * @blk_count: file blocks. */ -static int file_check(int fd, const char *file, int extents, blk64_t blk_count) +static int file_check(int fd, const char *file, blk64_t blk_count) { int ret; struct flock lock; @@ -536,9 +536,7 @@ static int file_check(int fd, const char *file, int extents, blk64_t blk_count) ret = check_free_size(fd, file, blk_count); if (ret < 0) { if ((mode_flag & DETAIL) && ret == -ENOSPC) { - printf("\033[79;0H\033[K[%u/%u] \"%s\"\t\t" - " extents: %d -> %d\n", defraged_file_count, - total_count, file, extents, extents); + PRINT_FILE_NAME(file); IN_FTW_PRINT_ERR_MSG( "Defrag size is larger than filesystem's free space"); } @@ -731,11 +729,9 @@ static int get_file_extents(int fd, struct fiemap_extent_list **ext_list_head) !(ext_buf[EXTENT_MAX_COUNT-1].fe_flags & FIEMAP_EXTENT_LAST)); - FREE(fiemap_buf); - return 0; out: FREE(fiemap_buf); - return -1; + return (errno == 0) ? 0 : -1; } /* @@ -877,7 +873,7 @@ static int call_defrag(int fd, int donor_fd, const char *file, if (mode_flag & DETAIL) { printf("\n"); PRINT_ERR_MSG_WITH_ERRNO( - "Failed to free page"); + "Failed to synchronize the file"); } else { printf("\t[ NG ]\n"); } @@ -1001,13 +997,19 @@ static int file_defrag(const char *file, const struct stat64 *buf, PRINT_ERR_MSG_WITH_ERRNO(NGMSG_FILE_EXTENT); } goto out; + } else if (orig_list == NULL) { + if (mode_flag & DETAIL) { + PRINT_FILE_NAME(file); + IN_FTW_PRINT_ERR_MSG("File has no blocks"); + } + goto out; } /* Count file fragments before defrag */ file_frags_start = get_exts_count(orig_list); blk_count = buf->st_blocks / (block_size / 512); - if (file_check(fd, file, file_frags_start, blk_count) < 0) + if (file_check(fd, file, blk_count) < 0) goto out; if (fsync(fd) < 0) { @@ -1093,6 +1095,12 @@ static int file_defrag(const char *file, const struct stat64 *buf, PRINT_ERR_MSG_WITH_ERRNO(NGMSG_FILE_EXTENT); } goto out; + } else if (donor_list == NULL) { + if (mode_flag & DETAIL) { + PRINT_FILE_NAME(file); + IN_FTW_PRINT_ERR_MSG("Temporary file was removed"); + } + goto out; } donor_score = e2p_get_fragscore(donor_fd, threshold, @@ -1140,7 +1148,7 @@ check_improvement: file_frags_end = file_frag_count(fd); if (file_frags_end < 0) { printf("\n"); - PRINT_ERR_MSG_WITH_ERRNO(NGMSG_FILE_INFO); + PRINT_ERR_MSG_WITH_ERRNO(NGMSG_FILE_EXTENT); goto out; } @@ -1286,10 +1294,7 @@ int main(int argc, char *argv[]) } switch (arg_type) { - case DIRNAME: - printf("ext4 defragmentation for directory(%s)\n", - argv[i]); - + case DIRNAME: { int mount_dir_len = 0; mount_dir_len = strnlen(lost_found_dir, PATH_MAX); @@ -1317,6 +1322,10 @@ int main(int argc, char *argv[]) /* "e4defrag mount_piont_dir/else_dir" */ memset(lost_found_dir, 0, PATH_MAX + 1); } + + printf("ext4 defragmentation for directory(%s)\n", + argv[i]); + } case DEVNAME: if (arg_type == DEVNAME) { strncpy(lost_found_dir, dir_name,