From patchwork Tue Jun 7 17:28:47 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jim Rees X-Patchwork-Id: 858162 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p57HShV6019126 for ; Tue, 7 Jun 2011 17:28:59 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755067Ab1FGR2u (ORCPT ); Tue, 7 Jun 2011 13:28:50 -0400 Received: from int-mailstore01.merit.edu ([207.75.116.232]:53510 "EHLO int-mailstore01.merit.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754086Ab1FGR2t (ORCPT ); Tue, 7 Jun 2011 13:28:49 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by int-mailstore01.merit.edu (Postfix) with ESMTP id 54B8A3055B74; Tue, 7 Jun 2011 13:28:49 -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 DQ2SViBSvi4b; Tue, 7 Jun 2011 13:28:48 -0400 (EDT) Received: from merit.edu (host-17.subnet-17.med.umich.edu [141.214.17.17]) by int-mailstore01.merit.edu (Postfix) with ESMTPSA id B65593083A6D; Tue, 7 Jun 2011 13:28:48 -0400 (EDT) Date: Tue, 7 Jun 2011 13:28:47 -0400 From: Jim Rees To: Benny Halevy Cc: linux-nfs@vger.kernel.org, peter honeyman Subject: [PATCH 24/88] pnfsblock: find_get_extent Message-ID: <41ad52dc1c5519c25062cc42f021c97486783c1a.1307464382.git.rees@umich.edu> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: 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]); Tue, 07 Jun 2011 17:28:59 +0000 (UTC) From: Fred Implement find_get_extent(), one of the core extent manipulation routines. Signed-off-by: Fred Isaman Signed-off-by: Benny Halevy pnfsblock: fix print format warnings for sector_t and size_t gcc spews warnings about these on x86_64, e.g.: fs/nfs/blocklayout/blocklayout.c:74: warning: format ‘%Lu’ expects type ‘long long unsigned int’, but argument 2 has type ‘sector_t’ fs/nfs/blocklayout/blocklayout.c:388: warning: format ‘%d’ expects type ‘int’, but argument 5 has type ‘size_t’ Signed-off-by: Benny Halevy --- fs/nfs/blocklayout/blocklayout.h | 3 ++ fs/nfs/blocklayout/extents.c | 47 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 0 deletions(-) diff --git a/fs/nfs/blocklayout/blocklayout.h b/fs/nfs/blocklayout/blocklayout.h index 13fc0e2..e992b94 100644 --- a/fs/nfs/blocklayout/blocklayout.h +++ b/fs/nfs/blocklayout/blocklayout.h @@ -203,6 +203,9 @@ struct pnfs_block_dev *nfs4_blk_init_metadev(struct super_block *sb, int nfs4_blk_flatten(struct pnfs_blk_volume *, int, struct pnfs_block_dev *); void free_block_dev(struct pnfs_block_dev *bdev); /* extents.c */ +struct pnfs_block_extent * +find_get_extent(struct pnfs_block_layout *bl, sector_t isect, + struct pnfs_block_extent **cow_read); void put_extent(struct pnfs_block_extent *be); struct pnfs_block_extent *alloc_extent(void); int add_and_merge_extent(struct pnfs_block_layout *bl, diff --git a/fs/nfs/blocklayout/extents.c b/fs/nfs/blocklayout/extents.c index ce7b6f7..944f824 100644 --- a/fs/nfs/blocklayout/extents.c +++ b/fs/nfs/blocklayout/extents.c @@ -193,3 +193,50 @@ add_and_merge_extent(struct pnfs_block_layout *bl, put_extent(new); return -EIO; } + +/* Returns extent, or NULL. If a second READ extent exists, it is returned + * in cow_read, if given. + * + * The extents are kept in two seperate ordered lists, one for READ and NONE, + * one for READWRITE and INVALID. Within each list, we assume: + * 1. Extents are ordered by file offset. + * 2. For any given isect, there is at most one extents that matches. + */ +struct pnfs_block_extent * +find_get_extent(struct pnfs_block_layout *bl, sector_t isect, + struct pnfs_block_extent **cow_read) +{ + struct pnfs_block_extent *be, *cow, *ret; + int i; + + dprintk("%s enter with isect %llu\n", __func__, (u64)isect); + cow = ret = NULL; + spin_lock(&bl->bl_ext_lock); + for (i = 0; i < EXTENT_LISTS; i++) { + if (ret && + (!cow_read || ret->be_state != PNFS_BLOCK_INVALID_DATA)) + break; + list_for_each_entry(be, &bl->bl_extents[i], be_node) { + if (isect < be->be_f_offset) + break; + if (isect < be->be_f_offset + be->be_length) { + /* We have found an extent */ + dprintk("%s Get %p (%i)\n", __func__, be, + atomic_read(&be->be_refcnt.refcount)); + kref_get(&be->be_refcnt); + if (!ret) + ret = be; + else if (be->be_state != PNFS_BLOCK_READ_DATA) + put_extent(be); + else + cow = be; + break; + } + } + } + spin_unlock(&bl->bl_ext_lock); + if (cow_read) + *cow_read = cow; + print_bl_extent(ret); + return ret; +}