From patchwork Sun Dec 2 14:34:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Su Yue X-Patchwork-Id: 10707875 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C5BEC109C for ; Sun, 2 Dec 2018 06:37:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ACA7E2AE06 for ; Sun, 2 Dec 2018 06:37:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9CD652AE2A; Sun, 2 Dec 2018 06:37:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.1 required=2.0 tests=BAYES_00,DATE_IN_FUTURE_06_12, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1429B2AE06 for ; Sun, 2 Dec 2018 06:37:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725440AbeLBGep (ORCPT ); Sun, 2 Dec 2018 01:34:45 -0500 Received: from mail-pf1-f194.google.com ([209.85.210.194]:39145 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725355AbeLBGep (ORCPT ); Sun, 2 Dec 2018 01:34:45 -0500 Received: by mail-pf1-f194.google.com with SMTP id c72so4789689pfc.6 for ; Sat, 01 Dec 2018 22:34:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=eq4KoD6Ck+oeskhsEk6urmY2LnKdR2Mlb/yY0GvEgNI=; b=BUxmIDgSPAUGraUBmZqwtUmEQWgnDOR5M0IByAdftDJDBoPOQzf+5TDcrVNJiZUfZG cYM8PsTntFIQwJr2UUFH9hc+WWeAr0zBAs8gXFpquqs0Xh8yolnyum/eBLRv3kSbFAcp WQCVTg1yUz8z33L1JKc8llw00kkRTz17x2KqQSSRyGs7XwcNSySWDrNsmnsLeIYWoEJH uKYsQXtVbFeSeblz2AXkuc4Y5+zCyqftL5OqJBum45Gi+5PKNJ+AmMRbj04ytoJFyQ3r qAAtoYXmnH41NjLBmBnSA/ouPlX1JYXIhn5nNb5SCg9LEDmO4Mizv/trOf64wVel+f+S X56Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=eq4KoD6Ck+oeskhsEk6urmY2LnKdR2Mlb/yY0GvEgNI=; b=idoj7JTNPdir6FI/19ezPY1CPriXIr0MTEJK7ZBv5f4An0aLhVfroR73gZTkjJgJGZ Hi01H1AG6sr70B/Ujog+1T00RRAEzM3S+UAD4ksDeKy9SF3fv8aiaeH+jJQom1TcFlSM 1BUfrhG3hQWKH48x2n6sKDq8GwLywj3/uo/jH6/qxhDMpQT9NVkkfDPZVOhA7MWsC2ME GuCjk3XA+c40ktxc1Usvz7wU06/UdWy5p21tifwWCEq0KWTOJYVru0VtzIKOA3CpFe/3 vNzv/a0jHImITyVlD4zLc5v1k3IPNDO7Vy0ZbUs4dsHSu7ruBdQ01BAhsC6z30idIOx6 khgg== X-Gm-Message-State: AA+aEWZBjxbpOVVa/mbnTco7HB+r6I0mzECOwkQGAff7eeUlXC1gW+Y3 b4S74j2TTTlgUxfqcPOg8TCOepO/ X-Google-Smtp-Source: AFSGD/Xg1Tb6jUGRrzd1YBBKByTalmaIlNfVnO1PZp8F/bImAw4fndIf/R6KQbfTdd3WHUrmSoHXjg== X-Received: by 2002:a63:902:: with SMTP id 2mr8984701pgj.219.1543732481387; Sat, 01 Dec 2018 22:34:41 -0800 (PST) Received: from cat-arch.lan ([173.82.208.113]) by smtp.gmail.com with ESMTPSA id m9sm10316555pgd.32.2018.12.01.22.34.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 01 Dec 2018 22:34:40 -0800 (PST) From: damenly.su@gmail.com X-Google-Original-From: suy.fnst@cn.fujitsu.com To: linux-btrfs@vger.kernel.org Cc: suy.fnst@cn.fujitsu.com Subject: [PATCH v2 01/13] btrfs-progs: lowmem: add argument path to punch_extent_hole() Date: Sun, 2 Dec 2018 14:34:24 +0000 Message-Id: <20181202143424.14892-1-suy.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181023094147.7906-2-suy.fnst@cn.fujitsu.com> References: <20181023094147.7906-2-suy.fnst@cn.fujitsu.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Su Yue Since repair will do CoW, the outer path may be invalid, add an argument path to punch_extent_hole(). When punch_extent_hole() returns, path will still point to the item before calling punch_extent_hole(); Signed-off-by: Su Yue --- Changelog: v2: Remove varaiable @ret2. Call btrfs_abort_transaction() if failed. --- check/mode-lowmem.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/check/mode-lowmem.c b/check/mode-lowmem.c index 1bce44f5658a..3dce4d3b5fc1 100644 --- a/check/mode-lowmem.c +++ b/check/mode-lowmem.c @@ -1710,28 +1710,37 @@ out: /* * Wrapper function of btrfs_punch_hole. * + * @path: will point to the item while calling the function. + * * Returns 0 means success. * Returns not 0 means error. */ -static int punch_extent_hole(struct btrfs_root *root, u64 ino, u64 start, - u64 len) +static int punch_extent_hole(struct btrfs_root *root, struct btrfs_path *path, + u64 ino, u64 start, u64 len) { struct btrfs_trans_handle *trans; - int ret = 0; + struct btrfs_key key; + int ret; + btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0]); trans = btrfs_start_transaction(root, 1); if (IS_ERR(trans)) return PTR_ERR(trans); ret = btrfs_punch_hole(trans, root, ino, start, len); - if (ret) + if (ret) { error("failed to add hole [%llu, %llu] in inode [%llu]", start, len, ino); - else - printf("Add a hole [%llu, %llu] in inode [%llu]\n", start, len, - ino); - + btrfs_abort_transaction(trans, ret); + return ret; + } + printf("Add a hole [%llu, %llu] in inode [%llu]\n", start, len, ino); btrfs_commit_transaction(trans, root); + + btrfs_release_path(path); + ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); + if (ret > 0) + ret = -ENOENT; return ret; } @@ -1963,7 +1972,7 @@ static int check_file_extent(struct btrfs_root *root, struct btrfs_path *path, /* Check EXTENT_DATA hole */ if (!no_holes && *end != fkey.offset) { if (repair) - ret = punch_extent_hole(root, fkey.objectid, + ret = punch_extent_hole(root, path, fkey.objectid, *end, fkey.offset - *end); if (!repair || ret) { err |= FILE_EXTENT_ERROR; @@ -2534,7 +2543,7 @@ out: if (!nbytes && !no_holes && extent_end < isize) { if (repair) - ret = punch_extent_hole(root, inode_id, + ret = punch_extent_hole(root, path, inode_id, extent_end, isize - extent_end); if (!repair || ret) { err |= NBYTES_ERROR; From patchwork Sun Dec 2 14:38:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Su Yue X-Patchwork-Id: 10707877 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1F4751057 for ; Sun, 2 Dec 2018 06:39:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 075102B3C3 for ; Sun, 2 Dec 2018 06:39:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ECF892B3D6; Sun, 2 Dec 2018 06:39:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.1 required=2.0 tests=BAYES_00,DATE_IN_FUTURE_06_12, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 794382B3C3 for ; Sun, 2 Dec 2018 06:39:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725535AbeLBGjO (ORCPT ); Sun, 2 Dec 2018 01:39:14 -0500 Received: from mail-pf1-f196.google.com ([209.85.210.196]:44061 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725355AbeLBGjO (ORCPT ); Sun, 2 Dec 2018 01:39:14 -0500 Received: by mail-pf1-f196.google.com with SMTP id u6so4784380pfh.11 for ; Sat, 01 Dec 2018 22:39:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9Ob9CUzmD8sAzSSAwjo4IWvZOovBlakf1kDH8eNSei8=; b=FqZt5kQ4IVN0+yROM5STYs0GDZ6rK4xr5ktSk7JnJGDLuVU6xnA9b2srmdW6F16sJx Q9kTWwYowVSE4PbFxNCIHXzJlQaHA6U/6DY+Od7y+Cde2kLIz16SErvIhg8pBGencaMV WynofQbHlp0tbPT05vInvw7kb+dS035KhfWzrTu5c+ibkdE2x0aQlI5lGT6tEBDJWIkD HAqfdYzfclivIZw/8lXSJ/aBmOBkQvi3zahNbURc+yNg4hk7iTYbO6EO3I1b1O8Vq9Y2 rLDEglPbWkq4lH6kTnV5EBNk59/S4ekByxhfQmKrKLT09c2D3g7zgSPN2kXyIAFNntrj fu/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9Ob9CUzmD8sAzSSAwjo4IWvZOovBlakf1kDH8eNSei8=; b=jSd4a26aw4VK/cKE51JWg37xGwOmDjBv8VEejkFB0ij18pvvftPoVogtNJOdyiB/pR TfXP4TjY2reQABYKi+9GtRxIrLSQOaUS9/DzsbEiE7tRat5c/MJ6BtIXJsjIsE7M8Reg dF4thN2WofScefv19pltKIaZ6bIevMxrdg9RJ5owxGmwljKgQp/nm0AEUDuvzV0vVGgR 46EBCF76UwRcrh+OMKBDPf6Lkc7dl1xHZ8FUHa1O5BVFGjDmRcY+Ypd8kr7NTqx91wcY wR2r4b8WPvJrZzCsCxiIk5wWjSnpYo1WEirjDNC5W3c1duEcc+YN/IcvIvc6Yzs8c98g E5yg== X-Gm-Message-State: AA+aEWYAzQmU6+MuOYbdalLrADoSVJ+fezE0de4mCuyzJ8BQ3cGNP4jL 7ubz+CHlFDr3SWsq3DzV/49njWRs X-Google-Smtp-Source: AFSGD/XcGgS5bkQwDGFCVgCmmgz+hWRBhVOpaGhgRfnSn3pqJrBzPjEZV+2/oSNv4y2L3Vb2ea6ilw== X-Received: by 2002:a63:d846:: with SMTP id k6mr8634464pgj.251.1543732752336; Sat, 01 Dec 2018 22:39:12 -0800 (PST) Received: from cat-arch.lan ([173.82.208.113]) by smtp.gmail.com with ESMTPSA id v191sm11584264pgb.77.2018.12.01.22.39.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 01 Dec 2018 22:39:11 -0800 (PST) From: damenly.su@gmail.com X-Google-Original-From: suy.fnst@cn.fujitsu.com To: linux-btrfs@vger.kernel.org Cc: suy.fnst@cn.fujitsu.com Subject: [PATCH v2 02/13] btrfs-progs: lowmem: move nbytes check before isize check Date: Sun, 2 Dec 2018 14:38:55 +0000 Message-Id: <20181202143855.15533-1-suy.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181023094147.7906-3-suy.fnst@cn.fujitsu.com> References: <20181023094147.7906-3-suy.fnst@cn.fujitsu.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Su Yue For files, lowmem repair will try to check nbytes and isize, but isize check depends nbytes. Once bytes has been repaired, then isize should be checked and repaired. So move nbytes check before isize check. Also set nbytes to extent_size once repaired successfully. Signed-off-by: Su Yue --- Changelog: v2 Remove one unrelated change. --- check/mode-lowmem.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/check/mode-lowmem.c b/check/mode-lowmem.c index 3dce4d3b5fc1..58f8f6fabed7 100644 --- a/check/mode-lowmem.c +++ b/check/mode-lowmem.c @@ -2541,28 +2541,31 @@ out: } } - if (!nbytes && !no_holes && extent_end < isize) { - if (repair) - ret = punch_extent_hole(root, path, inode_id, - extent_end, isize - extent_end); + if (nbytes != extent_size) { + if (repair) { + ret = repair_inode_nbytes_lowmem(root, path, + inode_id, extent_size); + if (!ret) + nbytes = extent_size; + } if (!repair || ret) { err |= NBYTES_ERROR; error( - "root %llu INODE[%llu] size %llu should have a file extent hole", - root->objectid, inode_id, isize); + "root %llu INODE[%llu] nbytes %llu not equal to extent_size %llu", + root->objectid, inode_id, nbytes, + extent_size); } } - if (nbytes != extent_size) { + if (!nbytes && !no_holes && extent_end < isize) { if (repair) - ret = repair_inode_nbytes_lowmem(root, path, - inode_id, extent_size); + ret = punch_extent_hole(root, path, inode_id, + extent_end, isize - extent_end); if (!repair || ret) { err |= NBYTES_ERROR; error( - "root %llu INODE[%llu] nbytes %llu not equal to extent_size %llu", - root->objectid, inode_id, nbytes, - extent_size); + "root %llu INODE[%llu] size %llu should have a file extent hole", + root->objectid, inode_id, isize); } } }