From patchwork Tue Dec 3 12:11:43 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zheng Liu X-Patchwork-Id: 296170 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 E35382C009F for ; Tue, 3 Dec 2013 23:09:43 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753837Ab3LCMJn (ORCPT ); Tue, 3 Dec 2013 07:09:43 -0500 Received: from mail-pa0-f51.google.com ([209.85.220.51]:59049 "EHLO mail-pa0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753768Ab3LCMJm (ORCPT ); Tue, 3 Dec 2013 07:09:42 -0500 Received: by mail-pa0-f51.google.com with SMTP id fa1so2895528pad.10 for ; Tue, 03 Dec 2013 04:09:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=n2emr9KExaZqzYrUE1wc9ZDSpIu5owWxmEDx6RNq0CM=; b=Wxrde6bBwPdkD2a3f8fTT7RV4oCZs4CKSN1Jc5PoVeosmrT7PaXggluxpfAxe8cvWw 1CrP/Ck3+sqIEDsUr6oa4bysU6JrYnmghh6pMAXbu5ju20MPzub04JDRZGik+PjR99C3 9N5ZzRil59/GJczLJOtQtVxXD+G2ixTR79E/KzCAXtJVLybjiE1Lz8Z1INeuc16sRwPX iDESZJWVYbuzO+hUwF3SIsvgWXbu9fj7sSjmuLXXchYlxcG/FLTMMLoQIomq0fY2nXXZ uB1KD5b8m3Sx1USfb9XfYc2maWnxz+/Hc60QcgVvZsM8w1L7U7SDEtEYJShsR8q8CUNN tFGQ== X-Received: by 10.66.8.66 with SMTP id p2mr49343582paa.129.1386072582466; Tue, 03 Dec 2013 04:09:42 -0800 (PST) Received: from alpha.taobao.ali.com ([182.92.247.2]) by mx.google.com with ESMTPSA id xv2sm129628866pbb.39.2013.12.03.04.09.40 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 03 Dec 2013 04:09:41 -0800 (PST) From: Zheng Liu To: linux-ext4@vger.kernel.org Cc: Theodore Ts'o , "Darrick J. Wong" , Zheng Liu Subject: [PATCH v2 16/28] debugfs: handle inline data feature in punch command Date: Tue, 3 Dec 2013 20:11:43 +0800 Message-Id: <1386072715-9869-17-git-send-email-wenqing.lz@taobao.com> X-Mailer: git-send-email 1.7.9.7 In-Reply-To: <1386072715-9869-1-git-send-email-wenqing.lz@taobao.com> References: <1386072715-9869-1-git-send-email-wenqing.lz@taobao.com> Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: Zheng Liu Now punch command only can remove all inline data because now punch command is based on block unit and the size of inline data is never beyond a block size. Signed-off-by: Zheng Liu --- lib/ext2fs/ext2fsP.h | 1 + lib/ext2fs/inline_data.c | 2 +- lib/ext2fs/punch.c | 28 +++++++++++++++++++++++++++- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/lib/ext2fs/ext2fsP.h b/lib/ext2fs/ext2fsP.h index b2da21a..bfc321c 100644 --- a/lib/ext2fs/ext2fsP.h +++ b/lib/ext2fs/ext2fsP.h @@ -91,6 +91,7 @@ extern int ext2fs_process_dir_block(ext2_filsys fs, extern errcode_t ext2fs_inline_data_init(ext2_filsys fs, ext2_ino_t ino); extern errcode_t ext2fs_inline_data_size(ext2_filsys fs, ext2_ino_t ino, size_t *size); +extern errcode_t ext2fs_inline_data_ea_remove(ext2_filsys fs, ext2_ino_t ino); extern errcode_t ext2fs_inline_data_expand(ext2_filsys fs, ext2_ino_t ino); extern errcode_t ext2fs_inline_data_dir_iterate(ext2_filsys fs, ext2_ino_t ino, diff --git a/lib/ext2fs/inline_data.c b/lib/ext2fs/inline_data.c index 527a52d..16af814 100644 --- a/lib/ext2fs/inline_data.c +++ b/lib/ext2fs/inline_data.c @@ -207,7 +207,7 @@ out: return retval & BLOCK_ERROR ? ctx->errcode : 0; } -static errcode_t ext2fs_inline_data_ea_remove(ext2_filsys fs, ext2_ino_t ino) +errcode_t ext2fs_inline_data_ea_remove(ext2_filsys fs, ext2_ino_t ino) { struct ext2_xattr_handle *handle; errcode_t retval; diff --git a/lib/ext2fs/punch.c b/lib/ext2fs/punch.c index 4471f46..d6c9004 100644 --- a/lib/ext2fs/punch.c +++ b/lib/ext2fs/punch.c @@ -300,6 +300,30 @@ errout: return retval; } +static errcode_t ext2fs_punch_inline_data(ext2_filsys fs, ext2_ino_t ino, + struct ext2_inode *inode, + blk64_t start, blk64_t end) +{ + errcode_t retval; + + /* + * In libext2fs ext2fs_punch is based on block unit. So that + * means that if start > 0 we don't need to do nothing. Due + * to this we will remove all inline data in ext2fs_punch() + * now. + */ + if (start > 0) + return 0; + + memset((char *)inode->i_block, 0, EXT4_MIN_INLINE_DATA_SIZE); + inode->i_size = 0; + retval = ext2fs_write_inode(fs, ino, inode); + if (retval) + return retval; + + return ext2fs_inline_data_ea_remove(fs, ino); +} + /* * Deallocate all logical blocks starting at start to end, inclusive. * If end is ~0, then this is effectively truncate. @@ -322,7 +346,9 @@ extern errcode_t ext2fs_punch(ext2_filsys fs, ext2_ino_t ino, return retval; inode = &inode_buf; } - if (inode->i_flags & EXT4_EXTENTS_FL) + if (inode->i_flags & EXT4_INLINE_DATA_FL) + return ext2fs_punch_inline_data(fs, ino, inode, start, end); + else if (inode->i_flags & EXT4_EXTENTS_FL) retval = ext2fs_punch_extent(fs, ino, inode, start, end); else { blk_t count;