From patchwork Sun Jun 12 23:44:42 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Rees X-Patchwork-Id: 873482 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.4) with ESMTP id p5CNhqA8007930 for ; Sun, 12 Jun 2011 23:45:10 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754684Ab1FLXoo (ORCPT ); Sun, 12 Jun 2011 19:44:44 -0400 Received: from int-mailstore01.merit.edu ([207.75.116.232]:60794 "EHLO int-mailstore01.merit.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754543Ab1FLXoo (ORCPT ); Sun, 12 Jun 2011 19:44:44 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by int-mailstore01.merit.edu (Postfix) with ESMTP id 39AA2308EFBD; Sun, 12 Jun 2011 19:44:44 -0400 (EDT) X-Virus-Scanned: amavisd-new at int-mailstore01.merit.edu Received: from int-mailstore01.merit.edu ([127.0.0.1]) by localhost (int-mailstore01.merit.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 0tlWybb0PvQ7; Sun, 12 Jun 2011 19:44:43 -0400 (EDT) Received: from merit.edu (74-126-0-171.static.123.net [74.126.0.171]) by int-mailstore01.merit.edu (Postfix) with ESMTPSA id 9F93630852E8; Sun, 12 Jun 2011 19:44:43 -0400 (EDT) X-Mailbox-Line: From 497dbd6147e55dd3a57f9b11be61637d128fbac3 Mon Sep 17 00:00:00 2001 Message-Id: <497dbd6147e55dd3a57f9b11be61637d128fbac3.1307921138.git.rees@umich.edu> In-Reply-To: References: Date: Sun, 12 Jun 2011 19:44:42 -0400 Subject: [PATCH 22/34] pnfsblock: merge rw extents From: Jim Rees To: linux-nfs@vger.kernel.org Cc: peter honeyman Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Sun, 12 Jun 2011 23:45:10 +0000 (UTC) From: Fred Isaman Signed-off-by: Fred Isaman Signed-off-by: Benny Halevy --- fs/nfs/blocklayout/extents.c | 47 ++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 47 insertions(+), 0 deletions(-) diff --git a/fs/nfs/blocklayout/extents.c b/fs/nfs/blocklayout/extents.c index 3d36f66..43a3601 100644 --- a/fs/nfs/blocklayout/extents.c +++ b/fs/nfs/blocklayout/extents.c @@ -501,3 +501,50 @@ find_get_extent(struct pnfs_block_layout *bl, sector_t isect, print_bl_extent(ret); return ret; } + +/* Helper function to set_to_rw that initialize a new extent */ +static void +_prep_new_extent(struct pnfs_block_extent *new, + struct pnfs_block_extent *orig, + sector_t offset, sector_t length, int state) +{ + kref_init(&new->be_refcnt); + /* don't need to INIT_LIST_HEAD(&new->be_node) */ + memcpy(&new->be_devid, &orig->be_devid, sizeof(struct nfs4_deviceid)); + new->be_mdev = orig->be_mdev; + new->be_f_offset = offset; + new->be_length = length; + new->be_v_offset = orig->be_v_offset - orig->be_f_offset + offset; + new->be_state = state; + new->be_inval = orig->be_inval; +} + +/* Tries to merge be with extent in front of it in list. + * Frees storage if not used. + */ +static struct pnfs_block_extent * +_front_merge(struct pnfs_block_extent *be, struct list_head *head, + struct pnfs_block_extent *storage) +{ + struct pnfs_block_extent *prev; + + if (!storage) + goto no_merge; + if (&be->be_node == head || be->be_node.prev == head) + goto no_merge; + prev = list_entry(be->be_node.prev, struct pnfs_block_extent, be_node); + if ((prev->be_f_offset + prev->be_length != be->be_f_offset) || + !extents_consistent(prev, be)) + goto no_merge; + _prep_new_extent(storage, prev, prev->be_f_offset, + prev->be_length + be->be_length, prev->be_state); + list_replace(&prev->be_node, &storage->be_node); + put_extent(prev); + list_del(&be->be_node); + put_extent(be); + return storage; + + no_merge: + kfree(storage); + return be; +}