Received: by 10.223.164.202 with SMTP id h10csp1377811wrb; Mon, 27 Nov 2017 01:49:26 -0800 (PST) X-Google-Smtp-Source: AGs4zMYMzESX8BrpJMjg3xr32+JO0JhuGxBCfzMq5xhYW7sb88KwSuynS33ZbVrAyBcayQpYdWoj X-Received: by 10.84.245.22 with SMTP id i22mr10417650pll.123.1511776166510; Mon, 27 Nov 2017 01:49:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511776166; cv=none; d=google.com; s=arc-20160816; b=tTltR+kdM7uDu7glw4b7DAKVE1R7A0JUQUIIrnAZQbdvq9XW1wrt5/ZKBYx1bcNfs7 PsTlv29VMIqsyhz1XHq3pqZSBGwIUmsMJwXKbhWSzVGQF6YBofgxj/UYd8RioULiX8ln wmXMnpSwEaf+azSJzAQX4gMaBvlumrf1qQYIoNAVdcUp+Alrx/J+/o/MGc3b7Y2ynU3+ ME7YvjXnRRVelJtpz5kH5DT+z/BkHOkaDfVsZtB7jwP0R3cgAL+uTQkv+IbkhCI0SgpE SatHm+6P03UVK4RvP5/fgKruQZi8phNg389IzGJ9HHE99GVIPqULIrs46atMRhG7J8mA +JgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=wHobJIMPehylZmdWgX08DefQ+f5GUCht35IbzSdEmVE=; b=FQR2k8BHTv3rcdQMRjFq21pN/eBy3kfYUZAOuit6NAM7DvImYRRUAwMBOIySblbWau PMw88uab+dhrz9oPoEZJTPUC8DQ0KUCvEVJzVpTP1fwDhiDtx78zT6e27Xe3oP2PNNFz XjnvDQpmf4c/ALmr9mV84P7SsNLQ1irM4Xml7ylr6aMM8fJJB2cWoW1UH/Wx957Uljcd YwZwWJAeLmLJGJxQ/XV/8GA+G4WXjP+yXRUWFdZB4cfkRWS+cXQi7eG8Hb+J0MV2OjHl fIPyUfTTK2sUKnCEv9Da/sEumCdXSG+2W9LuyyJ2t4FrJxBuLC9H0JSmXf7XRElNspt9 ZtPw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x7si22643477plw.158.2017.11.27.01.49.15; Mon, 27 Nov 2017 01:49:26 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751833AbdK0JrQ (ORCPT + 78 others); Mon, 27 Nov 2017 04:47:16 -0500 Received: from prv3-mh.provo.novell.com ([137.65.250.26]:49462 "EHLO prv3-mh.provo.novell.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751785AbdK0JrO (ORCPT ); Mon, 27 Nov 2017 04:47:14 -0500 Received: from ghe-pc.suse.asia (prv-ext-foundry1int.gns.novell.com [137.65.251.240]) by prv3-mh.provo.novell.com with ESMTP (TLS encrypted); Mon, 27 Nov 2017 02:47:04 -0700 From: Gang He To: mfasheh@versity.com, jlbec@evilplan.org, rgoldwyn@suse.com, hch@lst.de Cc: Gang He , linux-kernel@vger.kernel.org, ocfs2-devel@oss.oracle.com, akpm@linux-foundation.org Subject: [PATCH 2/3] ocfs2: add ocfs2_overwrite_io function Date: Mon, 27 Nov 2017 17:46:26 +0800 Message-Id: <1511775987-841-3-git-send-email-ghe@suse.com> X-Mailer: git-send-email 1.8.5.6 In-Reply-To: <1511775987-841-1-git-send-email-ghe@suse.com> References: <1511775987-841-1-git-send-email-ghe@suse.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add ocfs2_overwrite_io function, which is used to judge if overwrite allocated blocks, otherwise, the write will bring extra block allocation overhead. Signed-off-by: Gang He --- fs/ocfs2/extent_map.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++ fs/ocfs2/extent_map.h | 3 +++ 2 files changed, 70 insertions(+) diff --git a/fs/ocfs2/extent_map.c b/fs/ocfs2/extent_map.c index e4719e0..98bf325 100644 --- a/fs/ocfs2/extent_map.c +++ b/fs/ocfs2/extent_map.c @@ -832,6 +832,73 @@ int ocfs2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, return ret; } +/* Is IO overwriting allocated blocks? */ +int ocfs2_overwrite_io(struct inode *inode, u64 map_start, u64 map_len, + int wait) +{ + int ret = 0, is_last; + u32 mapping_end, cpos; + struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); + struct buffer_head *di_bh = NULL; + struct ocfs2_extent_rec rec; + + if (wait) + ret = ocfs2_inode_lock(inode, &di_bh, 0); + else + ret = ocfs2_try_inode_lock(inode, &di_bh, 0); + if (ret) + goto out; + + if (wait) + down_read(&OCFS2_I(inode)->ip_alloc_sem); + else { + if (!down_read_trylock(&OCFS2_I(inode)->ip_alloc_sem)) { + ret = -EAGAIN; + goto out_unlock1; + } + } + + if ((OCFS2_I(inode)->ip_dyn_features & OCFS2_INLINE_DATA_FL) && + ((map_start + map_len) <= i_size_read(inode))) + goto out_unlock2; + + cpos = map_start >> osb->s_clustersize_bits; + mapping_end = ocfs2_clusters_for_bytes(inode->i_sb, + map_start + map_len); + is_last = 0; + while (cpos < mapping_end && !is_last) { + ret = ocfs2_get_clusters_nocache(inode, di_bh, cpos, + NULL, &rec, &is_last); + if (ret) { + mlog_errno(ret); + goto out_unlock2; + } + + if (rec.e_blkno == 0ULL) + break; + + if (rec.e_flags & OCFS2_EXT_REFCOUNTED) + break; + + cpos = le32_to_cpu(rec.e_cpos) + + le16_to_cpu(rec.e_leaf_clusters); + } + + if (cpos < mapping_end) + ret = 1; + +out_unlock2: + brelse(di_bh); + + up_read(&OCFS2_I(inode)->ip_alloc_sem); + +out_unlock1: + ocfs2_inode_unlock(inode, 0); + +out: + return (ret ? 0 : 1); +} + int ocfs2_seek_data_hole_offset(struct file *file, loff_t *offset, int whence) { struct inode *inode = file->f_mapping->host; diff --git a/fs/ocfs2/extent_map.h b/fs/ocfs2/extent_map.h index 67ea57d..fd9e86a 100644 --- a/fs/ocfs2/extent_map.h +++ b/fs/ocfs2/extent_map.h @@ -53,6 +53,9 @@ int ocfs2_extent_map_get_blocks(struct inode *inode, u64 v_blkno, u64 *p_blkno, int ocfs2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, u64 map_start, u64 map_len); +int ocfs2_overwrite_io(struct inode *inode, u64 map_start, u64 map_len, + int wait); + int ocfs2_seek_data_hole_offset(struct file *file, loff_t *offset, int origin); int ocfs2_xattr_get_clusters(struct inode *inode, u32 v_cluster, -- 1.8.5.6 From 1585307214901685806@xxx Tue Nov 28 10:59:34 +0000 2017 X-GM-THRID: 1585307214901685806 X-Gmail-Labels: Inbox,Category Promotions,HistoricalUnread