From patchwork Thu Dec 2 20:34:10 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 375811 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 oB2KZb5j023382 for ; Thu, 2 Dec 2010 20:35:38 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757228Ab0LBUfe (ORCPT ); Thu, 2 Dec 2010 15:35:34 -0500 Received: from mx1.redhat.com ([209.132.183.28]:12944 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752829Ab0LBUfe (ORCPT ); Thu, 2 Dec 2010 15:35:34 -0500 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id oB2KZUgN007015 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 2 Dec 2010 15:35:30 -0500 Received: from dhcp231-156.rdu.redhat.com (dhcp231-156.rdu.redhat.com [10.11.231.156]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id oB2KZTKq016359; Thu, 2 Dec 2010 15:35:30 -0500 Date: Thu, 2 Dec 2010 15:34:10 -0500 From: Josef Bacik To: Johannes Hirte Cc: Josef Bacik , linux-btrfs@vger.kernel.org Subject: Re: disk space caching generation missmatch Message-ID: <20101202203410.GC8805@dhcp231-156.rdu.redhat.com> References: <201012011746.14458.johannes.hirte@fem.tu-ilmenau.de> <20101201200312.GF7021@localhost.localdomain> <201012012222.45471.johannes.hirte@fem.tu-ilmenau.de> <201012012240.29525.johannes.hirte@fem.tu-ilmenau.de> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <201012012240.29525.johannes.hirte@fem.tu-ilmenau.de> User-Agent: Mutt/1.5.19 (2009-01-05) X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 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 (demeter1.kernel.org [140.211.167.41]); Thu, 02 Dec 2010 20:35:38 +0000 (UTC) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 87aae66..5ee883b 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -2794,13 +2794,19 @@ again: if (i_size_read(inode) > 0) { ret = btrfs_truncate_free_space_cache(root, trans, path, inode); - if (ret) + if (ret) { + printk(KERN_ERR "truncate free space cache failed for %llu, %d\n", + block_group->key.objectid, ret); goto out_put; + } } spin_lock(&block_group->lock); if (block_group->cached != BTRFS_CACHE_FINISHED) { + /* Not cached, don't bother trying to write something out */ + block_group->disk_cache_state = BTRFS_DC_WRITTEN; spin_unlock(&block_group->lock); + printk(KERN_ERR "block group %llu not cached\n", block_group->key.objectid); goto out_put; } spin_unlock(&block_group->lock); @@ -2820,13 +2826,20 @@ again: num_pages *= PAGE_CACHE_SIZE; ret = btrfs_check_data_free_space(inode, num_pages); - if (ret) + if (ret) { + printk(KERN_ERR "not enough free space for cache %llu\n", block_group->key.objectid); goto out_put; + } ret = btrfs_prealloc_file_range_trans(inode, trans, 0, 0, num_pages, num_pages, num_pages, &alloc_hint); btrfs_free_reserved_data_space(inode, num_pages); + if (!ret) { + spin_lock(&block_gruop->lock); + block_group->disk_cache_state = BTRFS_DC_SETUP; + spin_unlock(&block_group->lock); + } out_put: iput(inode); out_free: @@ -2835,8 +2848,6 @@ out: spin_lock(&block_group->lock); if (ret) block_group->disk_cache_state = BTRFS_DC_ERROR; - else - block_group->disk_cache_state = BTRFS_DC_SETUP; spin_unlock(&block_group->lock); return ret; diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c index 22ee0dc..029cc42 100644 --- a/fs/btrfs/free-space-cache.c +++ b/fs/btrfs/free-space-cache.c @@ -290,7 +290,7 @@ int load_free_space_cache(struct btrfs_fs_info *fs_info, (unsigned long long)BTRFS_I(inode)->generation, (unsigned long long)generation, (unsigned long long)block_group->key.objectid); - goto out; + goto free_cache; } if (!num_entries) @@ -511,6 +511,8 @@ int btrfs_write_out_cache(struct btrfs_root *root, spin_lock(&block_group->lock); if (block_group->disk_cache_state < BTRFS_DC_SETUP) { spin_unlock(&block_group->lock); + printk(KERN_ERR "block group %llu, wrong dcs %d\n", block_group->key.objectid, + block_group->disk_cache_state); return 0; } spin_unlock(&block_group->lock); @@ -520,6 +522,13 @@ int btrfs_write_out_cache(struct btrfs_root *root, return 0; if (!i_size_read(inode)) { + printk(KERN_ERR "no allocated space for block group %llu\n", block_group->key.objectid); + iput(inode); + return 0; + } + + node = rb_first(&block_group->free_space_offset); + if (!node) { iput(inode); return 0; } @@ -543,10 +552,6 @@ int btrfs_write_out_cache(struct btrfs_root *root, */ first_page_offset = (sizeof(u32) * num_checksums) + sizeof(u64); - node = rb_first(&block_group->free_space_offset); - if (!node) - goto out_free; - /* * Lock all pages first so we can lock the extent safely. * @@ -771,6 +776,7 @@ out_free: block_group->disk_cache_state = BTRFS_DC_ERROR; spin_unlock(&block_group->lock); BTRFS_I(inode)->generation = 0; + printk(KERN_ERR "problem writing out block group cache for %llu\n", block_group->key.objectid); } kfree(checksums); btrfs_update_inode(trans, root, inode);