From patchwork Mon Mar 22 03:25:45 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: jim owens X-Patchwork-Id: 87340 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o2M3Pn1R018493 for ; Mon, 22 Mar 2010 03:25:49 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754001Ab0CVDZr (ORCPT ); Sun, 21 Mar 2010 23:25:47 -0400 Received: from mail-iw0-f182.google.com ([209.85.223.182]:49739 "EHLO mail-iw0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753726Ab0CVDZr (ORCPT ); Sun, 21 Mar 2010 23:25:47 -0400 Received: by iwn12 with SMTP id 12so3984979iwn.21 for ; Sun, 21 Mar 2010 20:25:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:subject:content-type :content-transfer-encoding; bh=p9WnhXYFE65DLOf5t03ZeM1OlROD4GmHQ7F8PK+h4Wk=; b=MC37RLZlaW6px00NM8nKoG8G/naH/wu2oMSrZYjHN7LqKTi10TCpI6G+3IEICYsfEq 7VTPFaBc0bY1m2WQspxLA0NUOilVEZ6de+Fpn1AUbDeNJis+8U3VvE+fX+oJoBJ1XkIW DKm8eCvP7ZAuymcN7NsRu3GSEHLwXuZQCRijg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject :content-type:content-transfer-encoding; b=FMRv9tCPzphWPhzTSOXw74TF94KTZyOAR9UAjQhRlZY7p5P10TjDdZU3HnVsD7XtJ9 CpAgTeOOzCDThkvgeyhsFAW8/DToEpAtIM754KAQHOGOgBXtYEQw/v+D5SdCvDFicFYp JnLCFJ9uKcRO5d50TBE18MK7lHpQIYMg+v25E= Received: by 10.231.159.134 with SMTP id j6mr1328478ibx.29.1269228346650; Sun, 21 Mar 2010 20:25:46 -0700 (PDT) Received: from [192.168.0.97] (c-24-147-40-65.hsd1.nh.comcast.net [24.147.40.65]) by mx.google.com with ESMTPS id c21sm1402931ibr.22.2010.03.21.20.25.45 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sun, 21 Mar 2010 20:25:46 -0700 (PDT) Message-ID: <4BA6E339.2060305@gmail.com> Date: Sun, 21 Mar 2010 23:25:45 -0400 From: jim owens User-Agent: Thunderbird 2.0.0.24 (X11/20100317) MIME-Version: 1.0 To: linux-btrfs Subject: [PATCH V3 08/18] Btrfs: split btrfs_map_block into two parts for direct I/O. Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Mon, 22 Mar 2010 03:25:49 +0000 (UTC) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index ebdd10f..8346e88 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -2626,33 +2626,16 @@ static int find_live_mirror(struct map_lookup *map, int first, int num, return optimal; } -int btrfs_map_block(struct btrfs_mapping_tree *map_tree, int rw, - u64 logical, u64 *length, - struct btrfs_multi_bio **multi_ret, - int mirror_num) +void btrfs_map_to_stripe(struct extent_map *em, int rw, int mirror_num, + u64 logical, u64 *length, + struct btrfs_stripe_info *stripe_info) { - struct extent_map *em; struct map_lookup *map; - struct extent_map_tree *em_tree = &map_tree->map_tree; u64 offset; u64 stripe_offset; u64 stripe_nr; int stripe_index; - int i; int num_stripes; - int max_errors; - struct btrfs_multi_bio *multi; - - read_lock(&em_tree->lock); - em = lookup_extent_mapping(em_tree, logical, *length); - read_unlock(&em_tree->lock); - - if (!em) { - printk(KERN_CRIT "unable to find logical %llu len %llu\n", - (unsigned long long)logical, - (unsigned long long)*length); - BUG(); - } BUG_ON(em->start > logical || em->start + em->len < logical); map = (struct map_lookup *)em->bdev; @@ -2682,19 +2665,19 @@ int btrfs_map_block(struct btrfs_mapping_tree *map_tree, int rw, *length = min(*length, em->len - offset); } - if (!multi_ret) - goto out; + if (!stripe_info) + return; if (mirror_num > map->num_stripes) mirror_num = 0; - max_errors = 0; + stripe_info->max_errors = 0; if (rw & (1 << BIO_RW)) { if (map->type & (BTRFS_BLOCK_GROUP_RAID1 | BTRFS_BLOCK_GROUP_DUP)) - max_errors = 1; + stripe_info->max_errors = 1; else if (map->type & BTRFS_BLOCK_GROUP_RAID10) - max_errors = 1; + stripe_info->max_errors = 1; } num_stripes = 1; @@ -2741,22 +2724,58 @@ int btrfs_map_block(struct btrfs_mapping_tree *map_tree, int rw, } BUG_ON(stripe_index >= map->num_stripes); - multi = kzalloc(btrfs_multi_bio_size(num_stripes), GFP_NOFS); + stripe_info->num_stripes = num_stripes; + stripe_info->stripe_index = stripe_index; + stripe_info->phys_offset = stripe_offset + stripe_nr * map->stripe_len; +} + +int btrfs_map_block(struct btrfs_mapping_tree *map_tree, int rw, + u64 logical, u64 *length, + struct btrfs_multi_bio **multi_ret, int mirror_num) +{ + struct extent_map *em; + struct map_lookup *map; + struct extent_map_tree *em_tree = &map_tree->map_tree; + struct btrfs_multi_bio *multi; + struct btrfs_stripe_info stripe_info; + int i; + + read_lock(&em_tree->lock); + em = lookup_extent_mapping(em_tree, logical, *length); + read_unlock(&em_tree->lock); + + if (!em) { + printk(KERN_CRIT "unable to find logical %llu len %llu\n", + (unsigned long long)logical, + (unsigned long long)*length); + BUG(); + } + + btrfs_map_to_stripe(em, rw, mirror_num, logical, length, + multi_ret ? &stripe_info : NULL); + if (!multi_ret) + goto out; + + multi = kzalloc(btrfs_multi_bio_size(stripe_info.num_stripes), + GFP_NOFS); if (!multi) return -ENOMEM; *multi_ret = multi; atomic_set(&multi->error, 0); - multi->num_stripes = num_stripes; - multi->max_errors = max_errors; + multi->num_stripes = stripe_info.num_stripes; + multi->max_errors = stripe_info.max_errors; - for (i = 0; i < num_stripes; i++) { + map = (struct map_lookup *)em->bdev; + for (i = 0; i < stripe_info.num_stripes; i++) { multi->stripes[i].physical = - map->stripes[stripe_index].physical + - stripe_offset + stripe_nr * map->stripe_len; - multi->stripes[i].dev = map->stripes[stripe_index].dev; - stripe_index++; + map->stripes[stripe_info.stripe_index].physical + + stripe_info.phys_offset; + multi->stripes[i].dev = + map->stripes[stripe_info.stripe_index].dev; + stripe_info.stripe_index++; } + out: free_extent_map(em); return 0; diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h index d5aab74..76c4394 100644 --- a/fs/btrfs/volumes.h +++ b/fs/btrfs/volumes.h @@ -135,6 +135,13 @@ struct btrfs_multi_bio { struct btrfs_bio_stripe stripes[]; }; +struct btrfs_stripe_info { + int num_stripes; + int max_errors; + int stripe_index; + u64 phys_offset; +}; + #define btrfs_multi_bio_size(n) (sizeof(struct btrfs_multi_bio) + \ (sizeof(struct btrfs_bio_stripe) * (n))) @@ -142,6 +149,9 @@ int btrfs_alloc_dev_extent(struct btrfs_trans_handle *trans, struct btrfs_device *device, u64 chunk_tree, u64 chunk_objectid, u64 chunk_offset, u64 start, u64 num_bytes); +void btrfs_map_to_stripe(struct extent_map *em, int rw, int mirror_num, + u64 logical, u64 *length, + struct btrfs_stripe_info *stripe_info); int btrfs_map_block(struct btrfs_mapping_tree *map_tree, int rw, u64 logical, u64 *length, struct btrfs_multi_bio **multi_ret, int mirror_num);