From patchwork Mon Oct 7 10:42:57 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Dryomov X-Patchwork-Id: 2996101 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.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 591A39F245 for ; Mon, 7 Oct 2013 10:43:43 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4D4D82012F for ; Mon, 7 Oct 2013 10:43:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C2692200EC for ; Mon, 7 Oct 2013 10:43:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755751Ab3JGKnb (ORCPT ); Mon, 7 Oct 2013 06:43:31 -0400 Received: from mail-ea0-f180.google.com ([209.85.215.180]:33780 "EHLO mail-ea0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755359Ab3JGKn2 (ORCPT ); Mon, 7 Oct 2013 06:43:28 -0400 Received: by mail-ea0-f180.google.com with SMTP id h10so3079910eaj.25 for ; Mon, 07 Oct 2013 03:43:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=DskaQ4y1J/K1foc9q2wMPZeeLaz7W4inPwUE6cMOEOA=; b=MNtTy3ZlEHGPQuNbrKZlffpQ+aS2WGDQsfPbJ7e5JegKgTn1yiIk53xhRVcXFaKGDx Ht8276uIDG+mGaCTv6anFIZhpnbFvb7Mx4ZwNeSn4Sf1x0aVTmtfp1PsFUn8X9KOZ4wH D6n4PMMSvubUv70kjncq1laLVJNx1g0cFSo6b+M436A3cM4hJBAk1H2lv+FpefQEhOB7 jk7IVklNoruDo9eYQ2WbeAXshztnJhXiFtTjvA0tGn42PjJoeQmlj3qsxGmUOhpJBYew ueKTI8vMFZpDo/X79AYnVMqGcZ7mgKUXBpVU15EFhRShFO7TJQyA1hrNFwmvfb7g68Q1 eCFw== X-Received: by 10.15.61.137 with SMTP id i9mr3307864eex.50.1381142606597; Mon, 07 Oct 2013 03:43:26 -0700 (PDT) Received: from localhost ([109.110.75.198]) by mx.google.com with ESMTPSA id a1sm61853589eem.1.1969.12.31.16.00.00 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 07 Oct 2013 03:43:26 -0700 (PDT) From: Ilya Dryomov To: linux-btrfs@vger.kernel.org Cc: Chris Mason , Stefan Behrens , idryomov@gmail.com Subject: [PATCH] Btrfs: fix the dev-replace suspend sequence Date: Mon, 7 Oct 2013 13:42:57 +0300 Message-Id: <1381142577-7957-1-git-send-email-idryomov@gmail.com> X-Mailer: git-send-email 1.7.10.4 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-7.0 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, 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 Replace progresses strictly from lower to higher offsets, and the progress is tracked in chunks, by storing the physical offset of the dev_extent which is being copied in the cursor_left field of btrfs_dev_replace_item. When we are done copying the chunk, left_cursor is updated to point one byte past the dev_extent, so that on resume we can skip the dev_extents that have already been copied. There is a major bug (which goes all the way back to the inception of dev-replace in 3.8) in the way left_cursor is bumped: the bump is done unconditionally, without any regard to the scrub_chunk return value. On suspend (and also on any kind of error) scrub_chunk returns early, i.e. without completing the copy. This leads to us skipping the chunk that hasn't been fully copied yet when resuming. Fix this by doing the cursor_left update only if scrub_chunk ret is 0. (On suspend scrub_chunk returns with -ECANCELED, so this fix covers both suspend and error cases.) Cc: Stefan Behrens Signed-off-by: Ilya Dryomov --- fs/btrfs/scrub.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c index a18e0e2..f21e2df 100644 --- a/fs/btrfs/scrub.c +++ b/fs/btrfs/scrub.c @@ -2717,8 +2717,6 @@ int scrub_enumerate_chunks(struct scrub_ctx *sctx, mutex_unlock(&fs_info->scrub_lock); wake_up(&fs_info->scrub_pause_wait); - dev_replace->cursor_left = dev_replace->cursor_right; - dev_replace->item_needs_writeback = 1; btrfs_put_block_group(cache); if (ret) break; @@ -2732,6 +2730,9 @@ int scrub_enumerate_chunks(struct scrub_ctx *sctx, break; } + dev_replace->cursor_left = dev_replace->cursor_right; + dev_replace->item_needs_writeback = 1; + key.offset = found_key.offset + length; btrfs_release_path(path); }