From patchwork Fri Jan 11 10:53:45 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zheng Liu X-Patchwork-Id: 211299 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 B2A5A2C0233 for ; Fri, 11 Jan 2013 21:40:39 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753545Ab3AKKkj (ORCPT ); Fri, 11 Jan 2013 05:40:39 -0500 Received: from mail-pa0-f43.google.com ([209.85.220.43]:62778 "EHLO mail-pa0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753137Ab3AKKki (ORCPT ); Fri, 11 Jan 2013 05:40:38 -0500 Received: by mail-pa0-f43.google.com with SMTP id fb10so951196pad.16 for ; Fri, 11 Jan 2013 02:40:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=LNZq5SBYrJUzxEpmog4Q59l6hP3jfPSVLMvGhotWOOs=; b=nsWF5xKlDYHeR0QAufJGPdUHXmUfrYMUnqgYW+PD8WU2oZZC7X2h9IJ+WjQAXDW+ur U3mEgF+h++0HXx0If9eg9F1PeiEKS99IfKD16Le7TNRyP0QvCJQJCx22ujjmbPCbXVVK dQYj2QAeKfX0o3e1Wmgv5V1tEQy5/rjjYz8MKLZb+8HoHmDAXI0euaJ/MXIUivSRCOWV J8Yr/a2sNGwNS0Ag5lOjJZ+Hlq34yUSZLHnVWuO9VpSraZRBUnBuPrLkDLXL0oqvZXk3 ucjeMVPLCXaMvRFMHk13pfgEZ8FwcaYD7f2s962MFcGDjsJ9/5KPn27umf9O0zxvsswd afxw== X-Received: by 10.68.241.65 with SMTP id wg1mr230717327pbc.141.1357900838598; Fri, 11 Jan 2013 02:40:38 -0800 (PST) Received: from lz-desktop.taobao.ali.com ([182.92.247.2]) by mx.google.com with ESMTPS id uk9sm2576791pbc.63.2013.01.11.02.40.33 (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 11 Jan 2013 02:40:37 -0800 (PST) From: Zheng Liu To: linux-ext4@vger.kernel.org Cc: Jan kara , "Theodore Ts'o" , Zheng Liu Subject: [PATCH 5/7 v2] ext4: track all extent status in extent status tree Date: Fri, 11 Jan 2013 18:53:45 +0800 Message-Id: <1357901627-3068-6-git-send-email-wenqing.lz@taobao.com> X-Mailer: git-send-email 1.7.12.rc2.18.g61b472e In-Reply-To: <1357901627-3068-1-git-send-email-wenqing.lz@taobao.com> References: <1357901627-3068-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 After record phycisal block and status, extent status tree is able to track the status of every extents. When we call _map_blocks functions to lookup an extent or create a new written/unwritten/delayed extent, this extent will be inserted into extent status tree. We don't load all extents from disk in alloc_inode() because it costs too much memory, and, when open/close a file very frequently, it will takes too much time to load all extent information. So currently when we create/lookup an extent, this extent will be inserted into extent status tree. Hence, the status in extent status tree might be not completely. CC: Jan kara CC: "Theodore Ts'o" Signed-off-by: Zheng Liu --- fs/ext4/extents.c | 5 +++- fs/ext4/file.c | 6 +++-- fs/ext4/inode.c | 73 ++++++++++++++++++++++++++++++++++++------------------- 3 files changed, 56 insertions(+), 28 deletions(-) diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index aa9a6d2..d23a654 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -2074,7 +2074,7 @@ static int ext4_fill_fiemap_extents(struct inode *inode, } /* This is possible iff next == next_del == EXT_MAX_BLOCKS */ - if (next == next_del) { + if (next == next_del && next_del == EXT_MAX_BLOCKS) { flags |= FIEMAP_EXTENT_LAST; if (unlikely(next_del != EXT_MAX_BLOCKS || next != EXT_MAX_BLOCKS)) { @@ -4570,6 +4570,9 @@ static int ext4_find_delayed_extent(struct inode *inode, /* A hole found. */ return 0; + if (!ext4_es_is_delayed(&es)) + return 0; + if (es.es_lblk > newex->ec_block) { /* A hole found. */ newex->ec_len = min(es.es_lblk - newex->ec_block, diff --git a/fs/ext4/file.c b/fs/ext4/file.c index 718c49f..afaf9f15 100644 --- a/fs/ext4/file.c +++ b/fs/ext4/file.c @@ -466,7 +466,8 @@ static loff_t ext4_seek_data(struct file *file, loff_t offset, loff_t maxsize) */ es.es_lblk = last; (void)ext4_es_find_extent(inode, &es); - if (last >= es.es_lblk && last < es.es_lblk + es.es_len) { + if (ext4_es_is_delayed(&es) && + last >= es.es_lblk && last < es.es_lblk + es.es_len) { if (last != start) dataoff = last << blkbits; break; @@ -550,7 +551,8 @@ static loff_t ext4_seek_hole(struct file *file, loff_t offset, loff_t maxsize) */ es.es_lblk = last; (void)ext4_es_find_extent(inode, &es); - if (last >= es.es_lblk && last < es.es_lblk + es.es_len) { + if (ext4_es_is_delayed(&es) && + last >= es.es_lblk && last < es.es_lblk + es.es_len) { last = es.es_lblk + es.es_len; holeoff = last << blkbits; continue; diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index e09c7cf..f0dda2a 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -527,20 +527,20 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode, retval = ext4_ind_map_blocks(handle, inode, map, flags & EXT4_GET_BLOCKS_KEEP_SIZE); } + if (retval > 0) { + int ret, status; + status = map->m_flags & EXT4_MAP_UNWRITTEN ? + EXTENT_STATUS_UNWRITTEN : EXTENT_STATUS_WRITTEN; + ret = ext4_es_insert_extent(inode, map->m_lblk, + map->m_len, map->m_pblk, status); + if (ret < 0) + retval = ret; + } if (!(flags & EXT4_GET_BLOCKS_NO_LOCK)) up_read((&EXT4_I(inode)->i_data_sem)); if (retval > 0 && map->m_flags & EXT4_MAP_MAPPED) { - int ret; - if (flags & EXT4_GET_BLOCKS_DELALLOC_RESERVE) { - /* delayed alloc may be allocated by fallocate and - * coverted to initialized by directIO. - * we need to handle delayed extent here. - */ - down_write((&EXT4_I(inode)->i_data_sem)); - goto delayed_mapped; - } - ret = check_block_validity(inode, map); + int ret = check_block_validity(inode, map); if (ret != 0) return ret; } @@ -615,18 +615,27 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode, (flags & EXT4_GET_BLOCKS_DELALLOC_RESERVE)) ext4_da_update_reserve_space(inode, retval, 1); } - if (flags & EXT4_GET_BLOCKS_DELALLOC_RESERVE) { + if (flags & EXT4_GET_BLOCKS_DELALLOC_RESERVE) ext4_clear_inode_state(inode, EXT4_STATE_DELALLOC_RESERVED); - if (retval > 0 && map->m_flags & EXT4_MAP_MAPPED) { - int ret; -delayed_mapped: - /* delayed allocation blocks has been allocated */ - ret = ext4_es_remove_extent(inode, map->m_lblk, - map->m_len); - if (ret < 0) - retval = ret; - } + if (retval > 0) { + int ret, status; + + if (flags & EXT4_GET_BLOCKS_PRE_IO) + status = EXTENT_STATUS_UNWRITTEN; + else if (flags & EXT4_GET_BLOCKS_CONVERT) + status = EXTENT_STATUS_WRITTEN; + else if (flags & EXT4_GET_BLOCKS_UNINIT_EXT) + status = EXTENT_STATUS_UNWRITTEN; + else if (flags & EXT4_GET_BLOCKS_CREATE) + status = EXTENT_STATUS_WRITTEN; + else + BUG_ON(1); + + ret = ext4_es_insert_extent(inode, map->m_lblk, map->m_len, + map->m_pblk, status); + if (ret < 0) + retval = ret; } up_write((&EXT4_I(inode)->i_data_sem)); @@ -1805,6 +1814,7 @@ static int ext4_da_map_blocks(struct inode *inode, sector_t iblock, retval = ext4_ind_map_blocks(NULL, inode, map, 0); if (retval == 0) { + int ret; /* * XXX: __block_prepare_write() unmaps passed block, * is it OK? @@ -1813,20 +1823,33 @@ static int ext4_da_map_blocks(struct inode *inode, sector_t iblock, * then we dont need to reserve it again. */ if ((EXT4_SB(inode->i_sb)->s_cluster_ratio == 1) || !ext4_find_delalloc_cluster(inode, map->m_lblk)) { - retval = ext4_da_reserve_space(inode, iblock); - if (retval) + ret = ext4_da_reserve_space(inode, iblock); + if (ret) { /* not enough space to reserve */ + retval = ret; goto out_unlock; + } } - retval = ext4_es_insert_extent(inode, map->m_lblk, map->m_len, - ~0, EXTENT_STATUS_DELAYED); - if (retval) + ret = ext4_es_insert_extent(inode, map->m_lblk, map->m_len, + ~0, EXTENT_STATUS_DELAYED); + if (ret) { + retval = ret; goto out_unlock; + } map_bh(bh, inode->i_sb, invalid_block); set_buffer_new(bh); set_buffer_delay(bh); + } else if (retval > 0) { + int ret, status; + + status = map->m_flags & EXT4_MAP_UNWRITTEN ? + EXTENT_STATUS_UNWRITTEN : EXTENT_STATUS_WRITTEN; + ret = ext4_es_insert_extent(inode, map->m_lblk, map->m_len, + map->m_pblk, status); + if (ret != 0) + retval = ret; } out_unlock: