From patchwork Fri Apr 8 07:53:16 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kazuya Mio X-Patchwork-Id: 90294 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 1E45DB6F84 for ; Fri, 8 Apr 2011 18:14:12 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756426Ab1DHIOK (ORCPT ); Fri, 8 Apr 2011 04:14:10 -0400 Received: from TYO202.gate.nec.co.jp ([202.32.8.206]:58535 "EHLO tyo202.gate.nec.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756089Ab1DHIOI (ORCPT ); Fri, 8 Apr 2011 04:14:08 -0400 Received: from mailgate3.nec.co.jp ([10.7.69.192]) by tyo202.gate.nec.co.jp (8.13.8/8.13.4) with ESMTP id p388E6wn026524; Fri, 8 Apr 2011 17:14:06 +0900 (JST) Received: (from root@localhost) by mailgate3.nec.co.jp (8.11.7/3.7W-MAILGATE-NEC) id p388E5612827; Fri, 8 Apr 2011 17:14:06 +0900 (JST) Received: from mail01b.kamome.nec.co.jp (mail01b.kamome.nec.co.jp [10.25.43.2]) by mailsv4.nec.co.jp (8.13.8/8.13.4) with ESMTP id p388E5ee008502; Fri, 8 Apr 2011 17:14:05 +0900 (JST) Received: from shikibu.jp.nec.com ([10.26.220.2] [10.26.220.2]) by mail03.kamome.nec.co.jp with ESMTP id BT-MMP-327638; Fri, 8 Apr 2011 16:53:26 +0900 Received: from [10.64.168.30] ([10.64.168.30] [10.64.168.30]) by mail.jp.nec.com with ESMTP; Fri, 8 Apr 2011 16:53:22 +0900 Message-ID: <4D9EBEEC.3030609@sx.jp.nec.com> Date: Fri, 08 Apr 2011 16:53:16 +0900 From: Kazuya Mio User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; ja; rv:1.9.2.15) Gecko/20110303 Thunderbird/3.1.9 MIME-Version: 1.0 To: ext4 , Theodore Tso Subject: [PATCH 10/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, 21 insertions(+), 18 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 b87aae9..76e84a2 100644 --- a/misc/e4defrag.c +++ b/misc/e4defrag.c @@ -316,6 +316,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; } @@ -726,11 +727,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 ? -1 : 0; } /* @@ -889,7 +888,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"); } @@ -987,15 +986,6 @@ static int file_defrag(const char *file, const struct stat64 *buf, return 0; } - /* Has no blocks */ - if (buf->st_blocks == 0) { - if (mode_flag & DETAIL) { - PRINT_FILE_NAME(file); - IN_FTW_PRINT_ERR_MSG("File has no blocks"); - } - return 0; - } - fd = open64(file, O_RDWR); if (fd < 0) { if (mode_flag & DETAIL) { @@ -1013,6 +1003,12 @@ 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 */ @@ -1112,6 +1108,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 = get_fragment_score(donor_fd, threshold); @@ -1156,7 +1158,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; } @@ -1296,10 +1298,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); @@ -1327,6 +1326,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,