From patchwork Fri Dec 6 09:58:05 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zheng Liu X-Patchwork-Id: 297680 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 3E5622C00A9 for ; Fri, 6 Dec 2013 20:56:20 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757625Ab3LFJ4T (ORCPT ); Fri, 6 Dec 2013 04:56:19 -0500 Received: from mail-pd0-f175.google.com ([209.85.192.175]:58361 "EHLO mail-pd0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757598Ab3LFJ4H (ORCPT ); Fri, 6 Dec 2013 04:56:07 -0500 Received: by mail-pd0-f175.google.com with SMTP id w10so746139pde.6 for ; Fri, 06 Dec 2013 01:56:07 -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=LEfiYGzcjnx036Nfb5YipFFEWDf9svhrZf29LiO+S2s=; b=AbASi4dwesqlcfiyfiB1JJ4ok472ObpIs96YuVPhyS8Yw5aOjgjgVCxs8Etu0YmcIG FX46d0SuSLlUS66iN2Q3QIhveOsFfAvey+/FZhXoK/KZlsPMhT474iWc4bnTw81vFz/r TGCNcLk/jQhpIxVBLbzTSj73045bAN3kuzSNLz8prhSKSIq7qzTwA/VjWI3wH7TqX9BL WCBp6o2F255jaHcNPh4tBRKf7z0X9BNsJRcoY5QG1ZhYRS1Sn/EKW1bKuh7jvF7qLnG4 nBkr4JRIFDbS+APV288Cq5zlOSWe4fZbovRtyYyC93zk6cAIPcJNVR/cNf73TWuYP6MB /yyw== X-Received: by 10.68.136.34 with SMTP id px2mr3058515pbb.113.1386323767152; Fri, 06 Dec 2013 01:56:07 -0800 (PST) Received: from alpha.taobao.ali.com ([182.92.247.2]) by mx.google.com with ESMTPSA id m2sm56582620pbn.19.2013.12.06.01.56.03 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 06 Dec 2013 01:56:06 -0800 (PST) From: Zheng Liu To: linux-ext4@vger.kernel.org Cc: Theodore Ts'o , "Darrick J. Wong" , Zheng Liu Subject: [PATCH v3 18/30] debugfs: handle inline data feature in punch command Date: Fri, 6 Dec 2013 17:58:05 +0800 Message-Id: <1386323897-2354-19-git-send-email-wenqing.lz@taobao.com> X-Mailer: git-send-email 1.7.9.7 In-Reply-To: <1386323897-2354-1-git-send-email-wenqing.lz@taobao.com> References: <1386323897-2354-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 3144427..a25c5bd 100644 --- a/lib/ext2fs/inline_data.c +++ b/lib/ext2fs/inline_data.c @@ -238,7 +238,7 @@ out: return retval & BLOCK_ERROR ? ctx->errcode : retval; } -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;