From patchwork Mon Feb 9 20:03:06 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 5803251 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 4D3A89F336 for ; Mon, 9 Feb 2015 20:04:32 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 57B562011D for ; Mon, 9 Feb 2015 20:04:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 51C502011B for ; Mon, 9 Feb 2015 20:04:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932379AbbBIUEW (ORCPT ); Mon, 9 Feb 2015 15:04:22 -0500 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:17775 "EHLO mx0b-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1760902AbbBIUDy (ORCPT ); Mon, 9 Feb 2015 15:03:54 -0500 Received: from pps.filterd (m0004077 [127.0.0.1]) by mx0b-00082601.pphosted.com (8.14.5/8.14.5) with SMTP id t19K3kEL022512; Mon, 9 Feb 2015 12:03:51 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=wit.ai; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=mx2; bh=MJ1ELy4HWV5cS1tQWKxqkCyo9lvHeAIdwLMUsfv1MYs=; b=OvcDR+th60NZBHYxOVuw1YuqHKaxA57WBEB6jgukcdHTjQ1KuFc1xHBbWN6mXsCwQ++x ztwg7ecsk9pWc3WzUqHO/I2QFjrYf391wzi/R6+mTrkghkNMXD8ahuNPGj+xPySBLrCP Ocvpa8leF5CSe7okh+y0hWnOnITFbq3p0Xt7s/Xn9gdLpPCDv/nLda7Mc5Xs5YgwkACw GWH0l+B0mXnxHV7FaDOybfctqgvN+s0rM58i4aTOZkEOtXUs7ZYqwHbuu5XNSWs61nVX ThSwG6Q+iscAzeG3Nieltl35NXDziNwoe9tsx4Bv7ivDXws9JR58q+WNQIiEWxZ3W8Rc ig== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fb.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=facebook; bh=MJ1ELy4HWV5cS1tQWKxqkCyo9lvHeAIdwLMUsfv1MYs=; b=SoecSSmnB25A4uD/OIlQWEjuWsA4cobEICu3aaKMBFuRf3kMgp3TDRcoAQk8Ngk5qTkT HrmLVa/cYhmVbzmn0a1CUm8cvwl0fE6M96SFa4rF0V+pQigI14e4VPo23Q9rSE0J7VLz QNu6Mcemg6dsDFDVgT+wXFzzZXgGS+I3U8I= Received: from mail.thefacebook.com ([199.201.64.23]) by mx0b-00082601.pphosted.com with ESMTP id 1sf2yv04ax-3 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NOT); Mon, 09 Feb 2015 12:03:51 -0800 Received: from localhost (192.168.57.29) by mail.thefacebook.com (192.168.16.11) with Microsoft SMTP Server (TLS) id 14.3.195.1; Mon, 9 Feb 2015 12:03:28 -0800 From: Josef Bacik To: , Subject: [PATCH 03/16] Btrfs-progs: handle -eagain properly Date: Mon, 9 Feb 2015 15:03:06 -0500 Message-ID: <1423512199-16552-4-git-send-email-jbacik@fb.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1423512199-16552-1-git-send-email-jbacik@fb.com> References: <1423512199-16552-1-git-send-email-jbacik@fb.com> MIME-Version: 1.0 X-Originating-IP: [192.168.57.29] X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.13.68, 1.0.33, 0.0.0000 definitions=2015-02-09_02:2015-02-09, 2015-02-08, 1970-01-01 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 kscore.is_bulkscore=0 kscore.compositescore=0 circleOfTrustscore=2.87009407511322 compositescore=0.980601274849849 urlsuspect_oldscore=0.980601274849849 suspectscore=2 recipient_domain_to_sender_totalscore=0 phishscore=0 bulkscore=0 kscore.is_spamscore=0 recipient_to_sender_totalscore=0 recipient_domain_to_sender_domain_totalscore=64355 rbsscore=0.980601274849849 spamscore=0 recipient_to_sender_domain_totalscore=0 urlsuspectscore=0.9 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=7.0.1-1402240000 definitions=main-1502090197 X-FB-Internal: deliver Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID,T_RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If we fix bad blocks during run_next_block we will return -EAGAIN to loop around and start again. The deal_with_roots work messed up this handling, this patch fixes it. With this patch we can properly deal with broken tree blocks. Thanks, Signed-off-by: Josef Bacik --- cmds-check.c | 93 +++++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 64 insertions(+), 29 deletions(-) diff --git a/cmds-check.c b/cmds-check.c index ca40e35..e74fa0f 100644 --- a/cmds-check.c +++ b/cmds-check.c @@ -7649,6 +7649,18 @@ static int add_root_item_to_list(struct list_head *head, return 0; } +static void free_root_item_list(struct list_head *list) +{ + struct root_item_record *ri_rec; + + while (!list_empty(list)) { + ri_rec = list_first_entry(list, struct root_item_record, + list); + list_del_init(&ri_rec->list); + free(ri_rec); + } +} + static int deal_root_from_list(struct list_head *list, struct btrfs_trans_handle *trans, struct btrfs_root *root, @@ -7846,50 +7858,49 @@ again: path.slots[0]++; } btrfs_release_path(&path); + + /* + * check_block can return -EAGAIN if it fixes something, please keep + * this in mind when dealing with return values from these functions, if + * we get -EAGAIN we want to fall through and restart the loop. + */ ret = deal_root_from_list(&normal_trees, trans, root, bits, bits_nr, &pending, &seen, &reada, &nodes, &extent_cache, &chunk_cache, &dev_cache, &block_group_cache, &dev_extent_cache); - if (ret < 0) + if (ret < 0) { + if (ret == -EAGAIN) + goto loop; goto out; + } ret = deal_root_from_list(&dropping_trees, trans, root, bits, bits_nr, &pending, &seen, &reada, &nodes, &extent_cache, - &chunk_cache, &dev_cache, &block_group_cache, + &chunk_cache, &dev_cache, + &block_group_cache, &dev_extent_cache); - if (ret < 0) + if (ret < 0) { + if (ret == -EAGAIN) + goto loop; goto out; - if (ret >= 0) - ret = check_extent_refs(trans, root, &extent_cache); - if (ret == -EAGAIN) { - ret = btrfs_commit_transaction(trans, root); - if (ret) - goto out; - - trans = btrfs_start_transaction(root, 1); - if (IS_ERR(trans)) { - ret = PTR_ERR(trans); - goto out; - } - - free_corrupt_blocks_tree(root->fs_info->corrupt_blocks); - free_extent_cache_tree(&seen); - free_extent_cache_tree(&pending); - free_extent_cache_tree(&reada); - free_extent_cache_tree(&nodes); - free_chunk_cache_tree(&chunk_cache); - free_block_group_tree(&block_group_cache); - free_device_cache_tree(&dev_cache); - free_device_extent_tree(&dev_extent_cache); - free_extent_record_cache(root->fs_info, &extent_cache); - goto again; } err = check_chunks(&chunk_cache, &block_group_cache, &dev_extent_cache, NULL, NULL, NULL, 0); - if (err && !ret) - ret = err; + if (err) { + if (err == -EAGAIN) + goto loop; + if (!ret) + ret = err; + } + + ret = check_extent_refs(trans, root, &extent_cache); + if (ret < 0) { + if (ret == -EAGAIN) + goto loop; + goto out; + } err = check_devices(&dev_cache, &dev_extent_cache); if (err && !ret) @@ -7917,6 +7928,30 @@ out: free_extent_cache_tree(&reada); free_extent_cache_tree(&nodes); return ret; +loop: + ret = btrfs_commit_transaction(trans, root); + if (ret) + goto out; + + trans = btrfs_start_transaction(root, 1); + if (IS_ERR(trans)) { + ret = PTR_ERR(trans); + goto out; + } + + free_corrupt_blocks_tree(root->fs_info->corrupt_blocks); + free_extent_cache_tree(&seen); + free_extent_cache_tree(&pending); + free_extent_cache_tree(&reada); + free_extent_cache_tree(&nodes); + free_chunk_cache_tree(&chunk_cache); + free_block_group_tree(&block_group_cache); + free_device_cache_tree(&dev_cache); + free_device_extent_tree(&dev_extent_cache); + free_extent_record_cache(root->fs_info, &extent_cache); + free_root_item_list(&normal_trees); + free_root_item_list(&dropping_trees); + goto again; } static int btrfs_fsck_reinit_root(struct btrfs_trans_handle *trans,