From patchwork Fri Jul 5 15:13:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13725271 Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8420414A60C; Fri, 5 Jul 2024 15:13:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720192440; cv=none; b=pNPgQmSTB6zG3SAXKx14eznG7kGf6phBnw6Wm3YxkT/uagpGlF7NDhg4xDycnt9P5j2eKl8sSRLwO5OfqeAty4ZXTU4bGMq79uTZDHSe0l9kASBgL3FakcSjU13IQjJEbbY62YOndrY6ghIdzjDM6IawsCg1nXGPLDaE6iiDmNU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720192440; c=relaxed/simple; bh=2sRJOr8yNCoBqCRZKtS0aHunaDitsRUFOHAd4BSzZUU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=kunkyu5TUSFWos2XVuwsLzGaO8x2XhliC3VbytuiczVYa0zStt1Jl4vGELKJKvmJrtKvQk5nRSY2Py8QyAfsV6FBMoRToTtwH6NaR86e5M1MffmPS05xebWyXuIEGdwD2GnH79rc5XM63FkgbW0DSuwoClTXTXfSqQMYCEuygRo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.218.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f43.google.com with SMTP id a640c23a62f3a-a77c9c5d68bso99701966b.2; Fri, 05 Jul 2024 08:13:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720192437; x=1720797237; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ui/evj4sZznHtsxKnMwIDYhzqdeAFRSy+YGy9CYAhdA=; b=YjcGASCbotnkxgEZmoZ2f9D4U4rQSsj3D+IUp17tVpbjGMzSfK4oX39663+II0MSR/ +UWcTY5z/D949VPYAuKwpmzKWrog8Hn5kXk84cLL1M4ulYsn9KpaVikbCE8V5N1Ttkiv pcolKgLAuWNkaA41YvPKwNEvSUq3IE91N5opCYcR/Mm+l0YQmw88gFXMQcRgR5F6cidc YXXAVqdeQbXW0UU4Ui1n4VxKg67QUD/i+/dISjluxBv0rKG4BHa/piSDBClBEc0qVy03 HYdT0Bk00O8MILKZlQmAAMPOWBj0mbXbi2Nu5nOtyGAKWahVIaSW+mHCHQP/dRhRDAsq BuMQ== X-Forwarded-Encrypted: i=1; AJvYcCXUqIxm++lWirtHEYUFIx194u7jGBw7a9XTDv1jvI2wMqH7gQypcVUUxtFbsAgF1ESUbpv3iLHIkPBkt6RaNKFYLkEWYwdEkXn55pX2 X-Gm-Message-State: AOJu0Yz6mOwPV/KF4qaN0Pa/AH4HWES4m0vkVQxeFDNabceh6KIXMSYG Ihel0JnOgkt+5wLYV4gE6z5avoM8nr/gluoyE5TwGJSsXgykP78Rl42iPw== X-Google-Smtp-Source: AGHT+IGg34UcA7/267iQUiqbnGgF9FjuGiH/0pkC+7IkZZzs+TOJ6qrgoxAqW8F+Q7VkoMQdsFMwPg== X-Received: by 2002:a17:906:3c49:b0:a77:c199:9d01 with SMTP id a640c23a62f3a-a77c1999e66mr244215966b.22.1720192436759; Fri, 05 Jul 2024 08:13:56 -0700 (PDT) Received: from [127.0.0.1] (p200300f6f72f3200fa633ffffe02074c.dip0.t-ipconnect.de. [2003:f6:f72f:3200:fa63:3fff:fe02:74c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a72aaf6336csm686226566b.70.2024.07.05.08.13.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jul 2024 08:13:56 -0700 (PDT) From: Johannes Thumshirn Date: Fri, 05 Jul 2024 17:13:47 +0200 Subject: [PATCH v4 1/7] btrfs: replace stripe extents Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240705-b4-rst-updates-v4-1-f3eed3f2cfad@kernel.org> References: <20240705-b4-rst-updates-v4-0-f3eed3f2cfad@kernel.org> In-Reply-To: <20240705-b4-rst-updates-v4-0-f3eed3f2cfad@kernel.org> To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Johannes Thumshirn X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=openpgp-sha256; l=2072; i=jth@kernel.org; h=from:subject:message-id; bh=hWXRtvyntafCT4XnKrcTYAkQgbW5dNOrGqpu/T/gXtA=; b=owGbwMvMwCV2ad4npfVdsu8YT6slMaR18G4MXuwty/94mlGv2wsV7xKRrDkCt4WfCHU9M2Y6P O9J1/rAjlIWBjEuBlkxRZbjobb7JUyPsE859NoMZg4rE8gQBi5OAZjINyOG/3nzb8lGRz22evXu xLOc1NLatX4LAw6+uPnH4vfWG5zJd+sYGbbt+tXX51KbxXV047q+Wbd5M7/bztvRp/OaQ65gn/L VMC4A X-Developer-Key: i=jth@kernel.org; a=openpgp; fpr=EC389CABC2C4F25D8600D0D00393969D2D760850 From: Johannes Thumshirn If we can't insert a stripe extent in the RAID stripe tree, because the key that points to the specific position in the stripe tree is already existing, we have to remove the item and then replace it by a new item. This can happen for example on device replace operations. Signed-off-by: Johannes Thumshirn --- fs/btrfs/raid-stripe-tree.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/fs/btrfs/raid-stripe-tree.c b/fs/btrfs/raid-stripe-tree.c index e6f7a234b8f6..3b32e96c33fc 100644 --- a/fs/btrfs/raid-stripe-tree.c +++ b/fs/btrfs/raid-stripe-tree.c @@ -73,6 +73,39 @@ int btrfs_delete_raid_extent(struct btrfs_trans_handle *trans, u64 start, u64 le return ret; } +static int replace_raid_extent_item(struct btrfs_trans_handle *trans, + struct btrfs_key *key, + struct btrfs_stripe_extent *stripe_extent, + const size_t item_size) +{ + struct btrfs_fs_info *fs_info = trans->fs_info; + struct btrfs_root *stripe_root = fs_info->stripe_root; + struct btrfs_path *path; + int ret; + + path = btrfs_alloc_path(); + if (!path) + return -ENOMEM; + + ret = btrfs_search_slot(trans, stripe_root, key, path, -1, 1); + if (ret) + goto err; + + ret = btrfs_del_item(trans, stripe_root, path); + if (ret) { + ret = (ret == 1) ? -ENOENT : ret; + goto err; + } + + btrfs_free_path(path); + + return btrfs_insert_item(trans, stripe_root, key, stripe_extent, + item_size); + err: + btrfs_free_path(path); + return ret; +} + static int btrfs_insert_one_raid_extent(struct btrfs_trans_handle *trans, struct btrfs_io_context *bioc) { @@ -112,6 +145,9 @@ static int btrfs_insert_one_raid_extent(struct btrfs_trans_handle *trans, ret = btrfs_insert_item(trans, stripe_root, &stripe_key, stripe_extent, item_size); + if (ret == -EEXIST) + ret = replace_raid_extent_item(trans, &stripe_key, + stripe_extent, item_size); if (ret) btrfs_abort_transaction(trans, ret); From patchwork Fri Jul 5 15:13:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13725272 Received: from mail-ej1-f48.google.com (mail-ej1-f48.google.com [209.85.218.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8599516B741; Fri, 5 Jul 2024 15:13:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720192441; cv=none; b=rZu5Daj8mdXGnGYSLXrbQbyY8DRbDJMapbO4Ggd/Hcj7U2GMXUZaNcJczWUyC1AqwdCdZA2E54Q0XSMOTwJ1SYULZXSIrVnRk/Tc3hS6nxMkkvW3xWwQ2hhmwzNqwJUAiLW58B4blNPonUzi2Za/eGxXQT+psoWZz55haenEoMA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720192441; c=relaxed/simple; bh=w4UY0qaNXatI2G4viGXg8MjSywm4bZkH/4/87SoqBg4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=nOYZKnrD+BMOEfsobHwjPsozvvrDOzjaj8h+KWAyVI5Psoq1lUylv0+o9nVB3+0FbmFnIQUlsG90OeufVa1ZoIJNo134eJjHxMuZek/ZBuAWJYE8EeGIdKF0mOEw3wKIMNhXkS0G3K3hU2ycNUsloFBCHllLfiuti/637A+U2dM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.218.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f48.google.com with SMTP id a640c23a62f3a-a77cb7c106dso99357266b.1; Fri, 05 Jul 2024 08:13:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720192438; x=1720797238; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=w72yAYQGgwZTCvkC7UicckI1wvtaU1tCLlsJ9npFA88=; b=fWsM48oFvvS0Qqv6dHqp5MI4ceOLahOlkZQZd1WUVqq6owBWIpe+mVawKLr4Eiyedb kPImDvDSQfQNB61OJ5n4cw6IkGKlqyb7cTPhFt4vLca4ux4HWDlWI+ywDwkDqFIzstaJ mc1KAaXGU6xBXv2h4VeifKedJkGUftveApkPygr4XsG7uPWP1f/uoXQFKDp/l7EBcEoc +AP0/xJR/UYK0BZ+LhzQoPHXxthGhFXEqzI0+6aN101SWC9NGhNXXYFedmDTW9w4r8mn 82YkbAiHKoCtRQ27jozqkdbrQRooQi1ilkS86sv3XcZcNuD8gO5XFZ7v7Oe8UAZgB7EL RFfg== X-Forwarded-Encrypted: i=1; AJvYcCUKJvzLqJnV85PKpJraxCT0bVP7o2J3Hi4gtqJPaXPhlpE9u+ku/++64/HB6YcymDGp/8mE4waqxpIGsU3WWJV+KeMz+4seOgT9UdEr X-Gm-Message-State: AOJu0YwYr/ME41IHnr2bGPM0dGy22X3dsQcUjK/vxM1BXJdSIKV9iCub RovCqBKofR4wUn7J/uA6AR+GdU6gq2P8ed5emmNrSr65buz9IwYfthwS9Q== X-Google-Smtp-Source: AGHT+IH2cT61O23REW96KTq6RlJBvRtvqItIVrLumpDTfZsGclikFhH5PlbsMvaIkKhpOGMNB+lWlg== X-Received: by 2002:a17:907:d25:b0:a77:c4a7:c421 with SMTP id a640c23a62f3a-a77c4a7c4efmr269677466b.30.1720192437732; Fri, 05 Jul 2024 08:13:57 -0700 (PDT) Received: from [127.0.0.1] (p200300f6f72f3200fa633ffffe02074c.dip0.t-ipconnect.de. [2003:f6:f72f:3200:fa63:3fff:fe02:74c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a72aaf6336csm686226566b.70.2024.07.05.08.13.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jul 2024 08:13:57 -0700 (PDT) From: Johannes Thumshirn Date: Fri, 05 Jul 2024 17:13:48 +0200 Subject: [PATCH v4 2/7] btrfs: rst: don't print tree dump in case lookup fails Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240705-b4-rst-updates-v4-2-f3eed3f2cfad@kernel.org> References: <20240705-b4-rst-updates-v4-0-f3eed3f2cfad@kernel.org> In-Reply-To: <20240705-b4-rst-updates-v4-0-f3eed3f2cfad@kernel.org> To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Johannes Thumshirn X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=openpgp-sha256; l=1099; i=jth@kernel.org; h=from:subject:message-id; bh=oU0E8uyvg8QMXoew6S4xY7nRBEk9shMhOdx0hjavAik=; b=owGbwMvMwCV2ad4npfVdsu8YT6slMaR18G4Uf856Obz5uWglu8ySK3LbW/L125j/qjelM9bEr 2+ZpvO4o5SFQYyLQVZMkeV4qO1+CdMj7FMOvTaDmcPKBDKEgYtTACayyIvhr2Cn5xOxuze12xzP LDdlZbQrrV3zto73wj6x1dkbZh/rfc/w3/fy842HFL6f3y301657bsgbnuxvx0I8T3MtzksQWaV eyQUA X-Developer-Key: i=jth@kernel.org; a=openpgp; fpr=EC389CABC2C4F25D8600D0D00393969D2D760850 From: Johannes Thumshirn Don't print tree dump in case a raid-stripe-tree lookup fails. Dumping the stripe tree in case of a lookup failure was originally intended to be a debug feature, but it turned out to be a problem, in case of i.e. readahead. Signed-off-by: Johannes Thumshirn --- fs/btrfs/raid-stripe-tree.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/raid-stripe-tree.c b/fs/btrfs/raid-stripe-tree.c index 3b32e96c33fc..84746c8886be 100644 --- a/fs/btrfs/raid-stripe-tree.c +++ b/fs/btrfs/raid-stripe-tree.c @@ -281,10 +281,8 @@ int btrfs_get_raid_extent_offset(struct btrfs_fs_info *fs_info, out: if (ret > 0) ret = -ENOENT; - if (ret && ret != -EIO && !stripe->is_scrub) { - if (IS_ENABLED(CONFIG_BTRFS_DEBUG)) - btrfs_print_tree(leaf, 1); - btrfs_err(fs_info, + if (ret && ret != -EIO) { + btrfs_debug(fs_info, "cannot find raid-stripe for logical [%llu, %llu] devid %llu, profile %s", logical, logical + *length, stripe->dev->devid, btrfs_bg_type_to_raid_name(map_type)); From patchwork Fri Jul 5 15:13:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13725273 Received: from mail-ej1-f53.google.com (mail-ej1-f53.google.com [209.85.218.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 945E916CD0F; Fri, 5 Jul 2024 15:14:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720192442; cv=none; b=VzTzyml0yhk1yW+HUWsa751UsFN7xQNfRJppc4s+T1qtMTbi2zt46FpMvexTKxBKpFIc9e5emZQt+IwN+AihVqPzdc/QY+HNVQ7VvI21ziNFkY/AnQ6I6FDakrdOGOiiTT370NIqhr7Ct32hgQN1q+lt0pftDkePv7l/LgQHIEA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720192442; c=relaxed/simple; bh=is+g/UmLn3VnD5JZNWK/X0ZjNyP++WSe0zIuSqaWhNk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=WWVYebGfycPN5br3I1/6TLvgsESk9sUwatXU9sgRwpS6sl6uH+ULcUBrmMSr3NNznmEGYi5f1s2uMYbIjakLxGDz2t2QKb4Nk8C7uy6WNYP0EStDqSoXfC9YhiUIyTIUIEzSVkhIFpD3jeHOOt0rwkXh4WzkbnOMhYXV00UuUtg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.218.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f53.google.com with SMTP id a640c23a62f3a-a689ad8d1f6so190537066b.2; Fri, 05 Jul 2024 08:14:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720192439; x=1720797239; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=z4yJib9/yu31KzhE/Fvb9I0Ph5ips0oIhml2mycHtDs=; b=lvr0lfn3WYPGEjH9FFazuTD7MPCtJoCYRAXsr0V4K1mDA3wuButvHuSdh50Jwxdfx2 IfIf9uW4zPMgmW2Dj7/QRW2Fr9WhF5hTsHHLvjGljNyLEAAXflhp4qpG1lZtK9zV6gHW Xpem3yWU/XtqH+U6WBDfheohmE70PaDDuJDC02C8MrMjSeDftlbPsdnIwhz19XOrN9/A dkAv5raoJxfPzRRF3NjzeEvcC8qARv5FWXnAkmAOwFgeCKPXoSaZNqbVqfZlT2GFCEUJ KaXo99ilTgv/djevPh+VuIHXdT4GJCEbsgihR6LAOSxhKnYiH0mzNK2zKIsJBSgA+1M2 kx5w== X-Forwarded-Encrypted: i=1; AJvYcCVlRwAjQyk66SvQuE9EU5AGnIcgbiqzKmq5IqAL8MU0Xp0zpRFCK/6uKynmwLLtcK9HsABxAaxgUJ7YvsR0lA1UTdgpeoc1g43v60Uc X-Gm-Message-State: AOJu0Yw+F52Pd31K2Yw6MHDQETVxnokQuGWQFs3e5epHsO0GwDclLzw1 3XRjImxg6wkvzuR+BulDlh7wGeFX2iy52fCGneRS2Fq7XqSGTbtwQYvlKQ== X-Google-Smtp-Source: AGHT+IHXwiDHUoN0WHlTQXRP9FZ9KNOwF/QDhAiLG/kx6iL92RdcCk4TouZWtFe6dVwHRNf3ihJ49A== X-Received: by 2002:a17:907:608c:b0:a77:bfca:da54 with SMTP id a640c23a62f3a-a77bfcadb9emr344657166b.29.1720192438928; Fri, 05 Jul 2024 08:13:58 -0700 (PDT) Received: from [127.0.0.1] (p200300f6f72f3200fa633ffffe02074c.dip0.t-ipconnect.de. [2003:f6:f72f:3200:fa63:3fff:fe02:74c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a72aaf6336csm686226566b.70.2024.07.05.08.13.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jul 2024 08:13:58 -0700 (PDT) From: Johannes Thumshirn Date: Fri, 05 Jul 2024 17:13:49 +0200 Subject: [PATCH v4 3/7] btrfs: split RAID stripes on deletion Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240705-b4-rst-updates-v4-3-f3eed3f2cfad@kernel.org> References: <20240705-b4-rst-updates-v4-0-f3eed3f2cfad@kernel.org> In-Reply-To: <20240705-b4-rst-updates-v4-0-f3eed3f2cfad@kernel.org> To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Johannes Thumshirn X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=openpgp-sha256; l=4263; i=jth@kernel.org; h=from:subject:message-id; bh=rknHPBJsb/MFqKgvZKmBibYNWi+sACspr+DYxYi9A/U=; b=owGbwMvMwCV2ad4npfVdsu8YT6slMaR18G5a3mqQznA+Wp9H6YH0bLu2v711XwqnKV142vJ7n fXT1DnHOkpZGMS4GGTFFFmOh9rulzA9wj7l0GszmDmsTCBDGLg4BWAi6zoZGdp0fi1KU+1+c3nW t0en8w6f3O0ezV7S8F/54kbtHSs8xV4w/HeRMl1tJMq4KvDW9Yl6FQ9unAhcb6b3b/q3d58t/++ rLOYFAA== X-Developer-Key: i=jth@kernel.org; a=openpgp; fpr=EC389CABC2C4F25D8600D0D00393969D2D760850 From: Johannes Thumshirn The current RAID stripe code assumes, that we will always remove a whole stripe entry. But if we're only removing a part of a RAID stripe we're hitting the ASSERT()ion checking for this condition. Instead of assuming the complete deletion of a RAID stripe, split the stripe if we need to. Signed-off-by: Johannes Thumshirn --- fs/btrfs/ctree.c | 1 + fs/btrfs/raid-stripe-tree.c | 98 ++++++++++++++++++++++++++++++++++----------- 2 files changed, 75 insertions(+), 24 deletions(-) diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c index 451203055bbf..82278e54969e 100644 --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c @@ -3863,6 +3863,7 @@ static noinline int setup_leaf_for_split(struct btrfs_trans_handle *trans, btrfs_item_key_to_cpu(leaf, &key, path->slots[0]); BUG_ON(key.type != BTRFS_EXTENT_DATA_KEY && + key.type != BTRFS_RAID_STRIPE_KEY && key.type != BTRFS_EXTENT_CSUM_KEY); if (btrfs_leaf_free_space(leaf) >= ins_len) diff --git a/fs/btrfs/raid-stripe-tree.c b/fs/btrfs/raid-stripe-tree.c index 84746c8886be..d2a6e409b3e8 100644 --- a/fs/btrfs/raid-stripe-tree.c +++ b/fs/btrfs/raid-stripe-tree.c @@ -33,42 +33,92 @@ int btrfs_delete_raid_extent(struct btrfs_trans_handle *trans, u64 start, u64 le if (!path) return -ENOMEM; - while (1) { - key.objectid = start; - key.type = BTRFS_RAID_STRIPE_KEY; - key.offset = length; +again: + key.objectid = start; + key.type = BTRFS_RAID_STRIPE_KEY; + key.offset = length; - ret = btrfs_search_slot(trans, stripe_root, &key, path, -1, 1); - if (ret < 0) - break; - if (ret > 0) { - ret = 0; - if (path->slots[0] == 0) - break; - path->slots[0]--; - } + ret = btrfs_search_slot(trans, stripe_root, &key, path, -1, 1); + if (ret < 0) + goto out; + if (ret > 0) { + ret = 0; + if (path->slots[0] == 0) + goto out; + path->slots[0]--; + } + + leaf = path->nodes[0]; + slot = path->slots[0]; + btrfs_item_key_to_cpu(leaf, &key, slot); + found_start = key.objectid; + found_end = found_start + key.offset; + + /* That stripe ends before we start, we're done. */ + if (found_end <= start) + goto out; + + trace_btrfs_raid_extent_delete(fs_info, start, end, + found_start, found_end); + + if (found_start < start) { + u64 diff = start - found_start; + struct btrfs_key new_key; + int num_stripes; + struct btrfs_stripe_extent *stripe_extent; + + new_key.objectid = start; + new_key.type = BTRFS_RAID_STRIPE_KEY; + new_key.offset = length - diff; + + ret = btrfs_duplicate_item(trans, stripe_root, path, + &new_key); + if (ret) + goto out; leaf = path->nodes[0]; slot = path->slots[0]; - btrfs_item_key_to_cpu(leaf, &key, slot); - found_start = key.objectid; - found_end = found_start + key.offset; - /* That stripe ends before we start, we're done. */ - if (found_end <= start) - break; + num_stripes = + btrfs_num_raid_stripes(btrfs_item_size(leaf, slot)); + stripe_extent = + btrfs_item_ptr(leaf, slot, struct btrfs_stripe_extent); + + for (int i = 0; i < num_stripes; i++) { + struct btrfs_raid_stride *raid_stride = + &stripe_extent->strides[i]; + u64 physical = + btrfs_raid_stride_physical(leaf, raid_stride); + + btrfs_set_raid_stride_physical(leaf, raid_stride, + physical + diff); + } + + btrfs_mark_buffer_dirty(trans, leaf); + btrfs_release_path(path); + goto again; + } - trace_btrfs_raid_extent_delete(fs_info, start, end, - found_start, found_end); + if (found_end > end) { + u64 diff = found_end - end; + struct btrfs_key new_key; - ASSERT(found_start >= start && found_end <= end); - ret = btrfs_del_item(trans, stripe_root, path); + new_key.objectid = found_start; + new_key.type = BTRFS_RAID_STRIPE_KEY; + new_key.offset = length - diff; + + ret = btrfs_duplicate_item(trans, stripe_root, path, + &new_key); if (ret) - break; + goto out; + btrfs_mark_buffer_dirty(trans, leaf); btrfs_release_path(path); } + ret = btrfs_del_item(trans, stripe_root, path); + + out: btrfs_free_path(path); return ret; } From patchwork Fri Jul 5 15:13:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13725274 Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BFD7116D4F7; Fri, 5 Jul 2024 15:14:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720192443; cv=none; b=bUjwnOLUaqn6FelKfF6Aul6qg5+LRwcoGIeFwztZBu+r8135i/3y/65MKicsshXFeKYyKEoW4pcYJafNV1e2Gud0zYGofpRiZfIGT7P9/kA9f1PLlqA9E10iT0WRvuZZEmjn29xMlPJpIoxAMq6SbQCQqTONBtL69tWPY8Pc8TU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720192443; c=relaxed/simple; bh=/3l1jXBu0VpItMhctO55F8Gr7ik+tgM/KNLoI2d0PZA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=L7NQZuJ7k9lOiKx8mxUvub199Og/IH81gqVT/j8+SWWznkwDw43ZnxSjEwYuZCEo6mN/mjBJfRxi5leHONn45QtIKetG95yVt9R0IkjHChAwbjpa48hbV5nKl7nvHNeIpNj/0c8dVNKG8HCS8lkMx00/ATqgWwjSkY2sW5yWfjg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.218.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-a72988749f0so239721466b.0; Fri, 05 Jul 2024 08:14:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720192440; x=1720797240; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aZNMpxbYZfZkGHpatVbKT88mSuPlBT+CABFw4C25AbE=; b=w2jK4JCL0Nv+NN+lhG8EGsOojm3WFopHdVlj1HgIPaF+Izwia4xYNDOnOvdTgRGe8X 0y9HoE088R6ML67PK/FYKEJfNtNyM9iJFHckQYnUy0A0kmJo6PEO/xyYnE7eBEqos/fM 2+vLKjU4p4LIdO/hs4Q6bvFtZqhpXLB8ZvycM22BU5rIm8qteeTayx8YNvyiomP9A4xO due8yWF2B4oeWYOI+ZO1zHtSFaTm/ojQbMdWBLLjyWY7B8glHM55mWMNqZFqfP+aiSWS Xw9vH3YHAGL73XM6ZEqMZK7GdEuDNA2dn4ntAk/eEg+1FhYFAllmAKMXxZYbmuZ5nYT0 0Q5g== X-Forwarded-Encrypted: i=1; AJvYcCXCUhv+xhJ8FsioUljDGd1sjIE2hnJySGlpT3x1p5QKL1VQpZSGw+r0NCoEA78VgUK3+wPsQttm6CwqCdQU82YLeD1AcUO8CaYra4Ye X-Gm-Message-State: AOJu0Yx1OtDnfAo1qn7b0ixtLF4Na3oBPT6IYZ/F38+WOs4VKMpbU8zk QWK5QGYKHYs1n7debbCr6IxXMhuC8ovhGcdvi7nQxbmw1flWL62OU+NIBA== X-Google-Smtp-Source: AGHT+IFZYebBd7ET2GyP0gUoP/PU5eToH1JLr7N88xojaervcPl+0o2BweeiZIsT7eTYOUjVzv5GrQ== X-Received: by 2002:a17:907:60d3:b0:a72:b4c9:2be8 with SMTP id a640c23a62f3a-a77ba7279a7mr425387366b.72.1720192439975; Fri, 05 Jul 2024 08:13:59 -0700 (PDT) Received: from [127.0.0.1] (p200300f6f72f3200fa633ffffe02074c.dip0.t-ipconnect.de. [2003:f6:f72f:3200:fa63:3fff:fe02:74c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a72aaf6336csm686226566b.70.2024.07.05.08.13.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jul 2024 08:13:59 -0700 (PDT) From: Johannes Thumshirn Date: Fri, 05 Jul 2024 17:13:50 +0200 Subject: [PATCH v4 4/7] btrfs: stripe-tree: add selftests Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240705-b4-rst-updates-v4-4-f3eed3f2cfad@kernel.org> References: <20240705-b4-rst-updates-v4-0-f3eed3f2cfad@kernel.org> In-Reply-To: <20240705-b4-rst-updates-v4-0-f3eed3f2cfad@kernel.org> To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Johannes Thumshirn X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=openpgp-sha256; l=11628; i=jth@kernel.org; h=from:subject:message-id; bh=fenVcePD9xkTySZuXQQD75LcFDttc4Aqso8ZFozVdB4=; b=owGbwMvMwCV2ad4npfVdsu8YT6slMaR18G7ifLR6VUTfRwNVnqS3do8iV1hIbGnL3yI/ndvyh K39dNmfHaUsDGJcDLJiiizHQ233S5geYZ9y6LUZzBxWJpAhDFycAjCR52cZGQ4cLI3nz+tq/+Ca cXSaksm950slXzIW5J98WZLI8auh3ofhv59Zl53DOtfDb//89OWeEdH32LnX2jabJUX5UmHqJ/8 vrAA= X-Developer-Key: i=jth@kernel.org; a=openpgp; fpr=EC389CABC2C4F25D8600D0D00393969D2D760850 From: Johannes Thumshirn Add self-tests for the RAID stripe tree code. Signed-off-by: Johannes Thumshirn --- fs/btrfs/Makefile | 3 +- fs/btrfs/raid-stripe-tree.c | 3 +- fs/btrfs/raid-stripe-tree.h | 5 + fs/btrfs/tests/btrfs-tests.c | 3 + fs/btrfs/tests/btrfs-tests.h | 1 + fs/btrfs/tests/raid-stripe-tree-tests.c | 322 ++++++++++++++++++++++++++++++++ 6 files changed, 335 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/Makefile b/fs/btrfs/Makefile index 87617f2968bc..3cfc440c636c 100644 --- a/fs/btrfs/Makefile +++ b/fs/btrfs/Makefile @@ -43,4 +43,5 @@ btrfs-$(CONFIG_FS_VERITY) += verity.o btrfs-$(CONFIG_BTRFS_FS_RUN_SANITY_TESTS) += tests/free-space-tests.o \ tests/extent-buffer-tests.o tests/btrfs-tests.o \ tests/extent-io-tests.o tests/inode-tests.o tests/qgroup-tests.o \ - tests/free-space-tree-tests.o tests/extent-map-tests.o + tests/free-space-tree-tests.o tests/extent-map-tests.o \ + tests/raid-stripe-tree-tests.o diff --git a/fs/btrfs/raid-stripe-tree.c b/fs/btrfs/raid-stripe-tree.c index d2a6e409b3e8..ba0733c6be76 100644 --- a/fs/btrfs/raid-stripe-tree.c +++ b/fs/btrfs/raid-stripe-tree.c @@ -156,7 +156,8 @@ static int replace_raid_extent_item(struct btrfs_trans_handle *trans, return ret; } -static int btrfs_insert_one_raid_extent(struct btrfs_trans_handle *trans, +EXPORT_FOR_TESTS +int btrfs_insert_one_raid_extent(struct btrfs_trans_handle *trans, struct btrfs_io_context *bioc) { struct btrfs_fs_info *fs_info = trans->fs_info; diff --git a/fs/btrfs/raid-stripe-tree.h b/fs/btrfs/raid-stripe-tree.h index 1ac1c21aac2f..541836421778 100644 --- a/fs/btrfs/raid-stripe-tree.h +++ b/fs/btrfs/raid-stripe-tree.h @@ -28,6 +28,11 @@ int btrfs_get_raid_extent_offset(struct btrfs_fs_info *fs_info, int btrfs_insert_raid_extent(struct btrfs_trans_handle *trans, struct btrfs_ordered_extent *ordered_extent); +#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS +int btrfs_insert_one_raid_extent(struct btrfs_trans_handle *trans, + struct btrfs_io_context *bioc); +#endif + static inline bool btrfs_need_stripe_tree_update(struct btrfs_fs_info *fs_info, u64 map_type) { diff --git a/fs/btrfs/tests/btrfs-tests.c b/fs/btrfs/tests/btrfs-tests.c index ce50847e1e01..18e1ab4a0914 100644 --- a/fs/btrfs/tests/btrfs-tests.c +++ b/fs/btrfs/tests/btrfs-tests.c @@ -291,6 +291,9 @@ int btrfs_run_sanity_tests(void) ret = btrfs_test_free_space_tree(sectorsize, nodesize); if (ret) goto out; + ret = btrfs_test_raid_stripe_tree(sectorsize, nodesize); + if (ret) + goto out; } } ret = btrfs_test_extent_map(); diff --git a/fs/btrfs/tests/btrfs-tests.h b/fs/btrfs/tests/btrfs-tests.h index dc2f2ab15fa5..61bcadaf2036 100644 --- a/fs/btrfs/tests/btrfs-tests.h +++ b/fs/btrfs/tests/btrfs-tests.h @@ -37,6 +37,7 @@ int btrfs_test_extent_io(u32 sectorsize, u32 nodesize); int btrfs_test_inodes(u32 sectorsize, u32 nodesize); int btrfs_test_qgroups(u32 sectorsize, u32 nodesize); int btrfs_test_free_space_tree(u32 sectorsize, u32 nodesize); +int btrfs_test_raid_stripe_tree(u32 sectorsize, u32 nodesize); int btrfs_test_extent_map(void); struct inode *btrfs_new_test_inode(void); struct btrfs_fs_info *btrfs_alloc_dummy_fs_info(u32 nodesize, u32 sectorsize); diff --git a/fs/btrfs/tests/raid-stripe-tree-tests.c b/fs/btrfs/tests/raid-stripe-tree-tests.c new file mode 100644 index 000000000000..bec7c210c14c --- /dev/null +++ b/fs/btrfs/tests/raid-stripe-tree-tests.c @@ -0,0 +1,322 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2024 Western Digital Corporation. All rights reserved. + */ +#include +#include +#include +#include +#include +#include +#include +#include "btrfs-tests.h" +#include "../disk-io.h" +#include "../transaction.h" +#include "../volumes.h" +#include "../raid-stripe-tree.h" +#include "../block-group.h" + +static struct btrfs_io_context *alloc_dummy_bioc(struct btrfs_fs_info *fs_info, + u64 logical, u16 total_stripes) +{ + struct btrfs_io_context *bioc; + + bioc = kzalloc(sizeof(struct btrfs_io_context) + + sizeof(struct btrfs_io_stripe) * total_stripes, + GFP_KERNEL); + + if (!bioc) + return NULL; + + refcount_set(&bioc->refs, 1); + + bioc->fs_info = fs_info; + bioc->replace_stripe_src = -1; + bioc->full_stripe_logical = (u64)-1; + bioc->logical = logical; + + return bioc; +} + +typedef int (*test_func_t)(struct btrfs_fs_info *); + +static int test_stripe_tree_delete_tail(struct btrfs_fs_info *fs_info) +{ + struct btrfs_trans_handle trans; + struct btrfs_io_context *bioc; + struct btrfs_io_stripe stripe = { }; + const u64 map_type = BTRFS_BLOCK_GROUP_DATA | BTRFS_BLOCK_GROUP_RAID1; + const int total_stripes = btrfs_bg_type_to_factor(map_type); + u64 logical = SZ_8K; + u64 length = SZ_64K; + u64 read_length; + int i; + int last = 0; + int ret; + + btrfs_init_dummy_trans(&trans, fs_info); + + bioc = alloc_dummy_bioc(fs_info, logical, total_stripes); + if (!bioc) + return -ENOMEM; + + bioc->size = length; + bioc->map_type = map_type; + for (i = 0; i < total_stripes; ++i) { + struct btrfs_device *dev; + + dev = kzalloc(sizeof(struct btrfs_device), GFP_KERNEL); + if (!dev) { + ret = -ENOMEM; + goto out; + } + dev->devid = i; + bioc->stripes[i].dev = dev; + bioc->stripes[i].length = length; + bioc->stripes[i].physical = i * SZ_8K; + last = i; + } + + ret = btrfs_insert_one_raid_extent(&trans, bioc); + if (ret) + goto out; + + ret = btrfs_delete_raid_extent(&trans, logical, SZ_16K); + if (ret) + goto out; + + stripe.dev = bioc->stripes[last].dev; + read_length = length - SZ_16K; + ret = btrfs_get_raid_extent_offset(fs_info, logical, + &read_length, map_type, 0, &stripe); + if (ret) + goto out; + + if (read_length != length - SZ_16K) { + test_err("invalid length %llu vs %llu", read_length, + length - SZ_16K); + ret = -EINVAL; + goto out; + } + + if (stripe.physical != bioc->stripes[last].physical) { + test_err("invalid physical %llu vs %llu", stripe.physical, + bioc->stripes[last].physical); + ret = -EINVAL; + } + +out: + for (i = 0; i < total_stripes; i++) + kfree(bioc->stripes[i].dev); + + kfree(bioc); + return ret; +} + +static int test_stripe_tree_delete_front(struct btrfs_fs_info *fs_info) +{ + struct btrfs_trans_handle trans; + struct btrfs_io_context *bioc; + const u64 map_type = BTRFS_BLOCK_GROUP_DATA | BTRFS_BLOCK_GROUP_RAID1; + const int total_stripes = btrfs_bg_type_to_factor(map_type); + u64 logical = SZ_8K; + u64 length = SZ_64K; + u64 read_length; + struct btrfs_io_stripe stripe = { }; + int i; + int last = 0; + int ret; + + btrfs_init_dummy_trans(&trans, fs_info); + + bioc = alloc_dummy_bioc(fs_info, logical, total_stripes); + if (!bioc) + return -ENOMEM; + + bioc->size = length; + bioc->map_type = map_type; + for (i = 0; i < total_stripes; i++) { + struct btrfs_device *dev; + + dev = kzalloc(sizeof(struct btrfs_device), GFP_KERNEL); + if (!dev) { + ret = -ENOMEM; + goto out; + } + dev->devid = i; + bioc->stripes[i].dev = dev; + bioc->stripes[i].length = length; + bioc->stripes[i].physical = i * SZ_8K; + last = i; + } + + ret = btrfs_insert_one_raid_extent(&trans, bioc); + if (ret) + goto out; + + ret = btrfs_delete_raid_extent(&trans, logical, SZ_8K); + if (ret) + goto out; + + stripe.dev = bioc->stripes[last].dev; + read_length = length - SZ_8K; + ret = btrfs_get_raid_extent_offset(fs_info, logical + SZ_8K, + &read_length, map_type, 0, &stripe); + if (ret) + goto out; + + if (read_length != length - SZ_8K) { + test_err("invalid length %llu vs %llu", read_length, + length - SZ_8K); + ret = -EINVAL; + goto out; + } + + if (stripe.physical != bioc->stripes[last].physical + SZ_8K) { + test_err("invalid physical %llu vs %llu", stripe.physical, + bioc->stripes[last].physical); + ret = -EINVAL; + } + +out: + for (i = 0; i < total_stripes; i++) + kfree(bioc->stripes[i].dev); + + kfree(bioc); + return ret; + +} + +static int test_stripe_tree_delete_whole(struct btrfs_fs_info *fs_info) +{ + struct btrfs_trans_handle trans; + struct btrfs_io_context *bioc; + const u64 map_type = BTRFS_BLOCK_GROUP_DATA | BTRFS_BLOCK_GROUP_RAID1; + const int total_stripes = btrfs_bg_type_to_factor(map_type); + u64 logical = SZ_8K; + u64 length = SZ_64K; + int i; + int ret; + + btrfs_init_dummy_trans(&trans, fs_info); + + bioc = alloc_dummy_bioc(fs_info, logical, total_stripes); + if (!bioc) + return -ENOMEM; + + bioc->size = length; + bioc->map_type = map_type; + for (i = 0; i < total_stripes; ++i) { + struct btrfs_device *dev; + + dev = kzalloc(sizeof(struct btrfs_device), GFP_KERNEL); + if (!dev) { + ret = -ENOMEM; + goto out; + } + dev->devid = i; + bioc->stripes[i].dev = dev; + bioc->stripes[i].length = length; + bioc->stripes[i].physical = i * SZ_8K; + } + + ret = btrfs_insert_one_raid_extent(&trans, bioc); + if (ret) + goto out; + + ret = btrfs_delete_raid_extent(&trans, logical, length); + if (ret) + goto out; + + ret = btrfs_header_nritems(fs_info->stripe_root->node); + if (ret != 0) { + test_err("test failed"); + ret = -EINVAL; + } + +out: + for (i = 0; i < total_stripes; i++) + kfree(bioc->stripes[i].dev); + + kfree(bioc); + return ret; +} + +static int test_stripe_tree_delete(struct btrfs_fs_info *fs_info) +{ + test_func_t delete_tests[] = { + test_stripe_tree_delete_whole, + test_stripe_tree_delete_front, + test_stripe_tree_delete_tail, + }; + int ret; + + for (int i = 0; i < ARRAY_SIZE(delete_tests); i++) { + test_func_t test = delete_tests[i]; + + ret = test(fs_info); + if (ret) + goto out; + } + +out: + return ret; +} + +int btrfs_test_raid_stripe_tree(u32 sectorsize, u32 nodesize) +{ + test_func_t tests[] = { + test_stripe_tree_delete, + }; + struct btrfs_fs_info *fs_info; + struct btrfs_root *root = NULL; + int ret = 0; + + test_msg("running raid stripe tree tests"); + + fs_info = btrfs_alloc_dummy_fs_info(nodesize, sectorsize); + if (!fs_info) { + test_std_err(TEST_ALLOC_FS_INFO); + ret = -ENOMEM; + goto out; + } + + root = btrfs_alloc_dummy_root(fs_info); + if (IS_ERR(root)) { + test_std_err(TEST_ALLOC_ROOT); + ret = PTR_ERR(root); + goto out; + } + + root->root_key.objectid = BTRFS_RAID_STRIPE_TREE_OBJECTID; + root->root_key.type = BTRFS_ROOT_ITEM_KEY; + root->root_key.offset = 0; + btrfs_global_root_insert(root); + root->fs_info->stripe_root = root; + root->fs_info->tree_root = root; + btrfs_set_super_incompat_flags(fs_info->super_copy, + BTRFS_FEATURE_INCOMPAT_RAID_STRIPE_TREE); + + + root->node = alloc_test_extent_buffer(fs_info, nodesize); + if (IS_ERR(root->node)) { + test_std_err(TEST_ALLOC_EXTENT_BUFFER); + ret = PTR_ERR(root->node); + goto out; + } + btrfs_set_header_level(root->node, 0); + btrfs_set_header_nritems(root->node, 0); + root->alloc_bytenr += 2 * nodesize; + + for (int i = 0; i < ARRAY_SIZE(tests); i++) { + test_func_t test = tests[i]; + + ret = test(fs_info); + if (ret) + goto out; + } +out: + btrfs_free_dummy_root(root); + btrfs_free_dummy_fs_info(fs_info); + return ret; +} From patchwork Fri Jul 5 15:13:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13725275 Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1A3EA16E863; Fri, 5 Jul 2024 15:14:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720192444; cv=none; b=HJfwSAXYaX3cazGwK+ddy/XfYVjjmBV58DbXiQlOAeO1Ou1ESQt91XcnuSaGTTXPHmJGH4DuN41uCpNEovcHkgACssTNGGf7V8mHx3abVnlG5GQJhG02BKYXTIv2Thcn36/bp5jdN10uvOLGfR/4IaPcZtYSAgFqsGP9CmwHrYI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720192444; c=relaxed/simple; bh=3ENqzb97joBmtCY5X5PZSKhZQlDsXq21Lx8PuDDcIc4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=u9mUaLLXoKiHEJ65mIbzFZ73TWepLdrRkiDrxAFVd7iN1Sf/DLgnrcKAy46VhEg/pIrfdO5264iKXzx8QcmPLgB5R+/cm3SBvcbEzgpct0I6Ym+tYQCWMHon7jU0j4ew9cxTx8LdlJ8nQ+vXSzijQ3x1nozxA3++uxplkzFabRE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.218.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f54.google.com with SMTP id a640c23a62f3a-a77bf336171so255796266b.1; Fri, 05 Jul 2024 08:14:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720192441; x=1720797241; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=T4fJBqRhN/ALwL+ec4EbLWnLhrO++xB8AGJ6zLwkd/8=; b=ucRNPQ7oXfWPiYnLkea0+eiAU70soKhTaZ/OfO4CK2ZtcQ9jSuGjFNltKFduR6VAdw mvdIi4YKzjvqrdXlLl7GhMl/VLCuSpya34XWWOeiJ/EJOGGOtbErw4CgA4ipKZgK1mkh 2VEkQ/r4LXuq6P7/feH3XFiKQw0gDWKTxO4EAQnvqdB9L/hfXX0qw9lrtUmPcK6EXX50 mu8xgiaNrxsgli/dVFHp7NcRRm5eFmkinOOQ0XXDKbMF+qt3JY1hng6+6K16Qcw9eo5T BT5n33AzlxkRu2zSZlkAD6CQrOANGAiikWmJAHXSaimughrI77heh6lytvGv/JErgacJ ScrA== X-Forwarded-Encrypted: i=1; AJvYcCXcOcotLP88Ag8kVHRAOkONARw7XrveVo+WRHZFNhRWpJXWSRK/+5d9IKKn2ZoFBj52iYwa7SjW5yPEFzhQzUwvv/cVd6brNbP5T2St X-Gm-Message-State: AOJu0YwbvTABi8is1QPQoAh7NSV1KdyQO5eINhORbqSfF6yzMgxCmwHQ q2jdMO2o9yoTWej7AxzSj0LtB40InD5QUtcVi/z6E412D7MBbvO5Pu1GIQ== X-Google-Smtp-Source: AGHT+IERhMPGGhZZrLR1D1u7uiSii05k0mKMva35MIAJ7UCZLA/ge1PpSS9I612ZRZCQJPvhlqqRPQ== X-Received: by 2002:a17:906:4685:b0:a6f:20e0:1d1a with SMTP id a640c23a62f3a-a77bdadffb9mr397468366b.33.1720192441083; Fri, 05 Jul 2024 08:14:01 -0700 (PDT) Received: from [127.0.0.1] (p200300f6f72f3200fa633ffffe02074c.dip0.t-ipconnect.de. [2003:f6:f72f:3200:fa63:3fff:fe02:74c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a72aaf6336csm686226566b.70.2024.07.05.08.14.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jul 2024 08:14:00 -0700 (PDT) From: Johannes Thumshirn Date: Fri, 05 Jul 2024 17:13:51 +0200 Subject: [PATCH v4 5/7] btrfs: don't hold dev_replace rwsem over whole of btrfs_map_block Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240705-b4-rst-updates-v4-5-f3eed3f2cfad@kernel.org> References: <20240705-b4-rst-updates-v4-0-f3eed3f2cfad@kernel.org> In-Reply-To: <20240705-b4-rst-updates-v4-0-f3eed3f2cfad@kernel.org> To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Johannes Thumshirn X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=openpgp-sha256; l=3501; i=jth@kernel.org; h=from:subject:message-id; bh=FSQfegSNF0R+Xzt230/PK3KBm1geIM/wZFBq+IyvNp8=; b=owGbwMvMwCV2ad4npfVdsu8YT6slMaR18G4Sjk8zeXlu4fvys18n7Nt7sczMZ17I9hlMgcHTT kvd8vk2s6OUhUGMi0FWTJHleKjtfgnTI+xTDr02g5nDygQyhIGLUwAm8mcOI8PSz83i9zomT6rO N//6e374vU8cK/d/0zg949a5uVHWHd8CGf7pbL+fFbvjUmGIzEk9bf0bM6z3/LjJ3dmf39EZkR/ lwcYLAA== X-Developer-Key: i=jth@kernel.org; a=openpgp; fpr=EC389CABC2C4F25D8600D0D00393969D2D760850 From: Johannes Thumshirn Don't hold the dev_replace rwsem for the entirety of btrfs_map_block(). It is only needed to protect a) calls to find_live_mirror() and b) calling into handle_ops_on_dev_replace(). But there is no need to hold the rwsem for any kind of set_io_stripe() calls. So relax taking the dev_replace rwsem to only protect both cases and check if the device replace status has changed in the meantime, for which we have to re-do the find_live_mirror() calls. This fixes a deadlock on raid-stripe-tree where device replace performs a scrub operation, which in turn calls into btrfs_map_block() to find the physical location of the block. Signed-off-by: Johannes Thumshirn Reviewed-by: Josef Bacik Reviewed-by: Qu Wenruo --- fs/btrfs/volumes.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index fcedc43ef291..4209419244a1 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -6650,14 +6650,9 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, max_len = btrfs_max_io_len(map, map_offset, &io_geom); *length = min_t(u64, map->chunk_len - map_offset, max_len); +again: down_read(&dev_replace->rwsem); dev_replace_is_ongoing = btrfs_dev_replace_is_ongoing(dev_replace); - /* - * Hold the semaphore for read during the whole operation, write is - * requested at commit time but must wait. - */ - if (!dev_replace_is_ongoing) - up_read(&dev_replace->rwsem); switch (map->type & BTRFS_BLOCK_GROUP_PROFILE_MASK) { case BTRFS_BLOCK_GROUP_RAID0: @@ -6695,6 +6690,7 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, "stripe index math went horribly wrong, got stripe_index=%u, num_stripes=%u", io_geom.stripe_index, map->num_stripes); ret = -EINVAL; + up_read(&dev_replace->rwsem); goto out; } @@ -6710,6 +6706,8 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, */ num_alloc_stripes += 2; + up_read(&dev_replace->rwsem); + /* * If this I/O maps to a single device, try to return the device and * physical block information on the stack instead of allocating an @@ -6782,6 +6780,18 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, goto out; } + /* + * Check if something changed the dev_replace state since + * we've checked it for the last time and if redo the whole + * mapping operation. + */ + down_read(&dev_replace->rwsem); + if (dev_replace_is_ongoing != + btrfs_dev_replace_is_ongoing(dev_replace)) { + up_read(&dev_replace->rwsem); + goto again; + } + if (op != BTRFS_MAP_READ) io_geom.max_errors = btrfs_chunk_max_errors(map); @@ -6789,6 +6799,7 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, op != BTRFS_MAP_READ) { handle_ops_on_dev_replace(bioc, dev_replace, logical, &io_geom); } + up_read(&dev_replace->rwsem); *bioc_ret = bioc; bioc->num_stripes = io_geom.num_stripes; @@ -6796,11 +6807,6 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, bioc->mirror_num = io_geom.mirror_num; out: - if (dev_replace_is_ongoing) { - lockdep_assert_held(&dev_replace->rwsem); - /* Unlock and let waiting writers proceed */ - up_read(&dev_replace->rwsem); - } btrfs_free_chunk_map(map); return ret; } From patchwork Fri Jul 5 15:13:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13725276 Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 12AEE16EB74; Fri, 5 Jul 2024 15:14:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720192445; cv=none; b=HNr+HnLV5rZutCltvu+00g89Kg2ls01yo3aAj5GRXmHp82cfj7VP5otWC0zURuVY5tf2RsRUFwUdmJzaSBVCsrjk8Fj95GMOzgeeOPj/dlE/l3x0IGLInMHdraGEsNCmhPDmGJV+X17YsQznka337E0Ha31JBKVqub6QES1iwvI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720192445; c=relaxed/simple; bh=QMnTCTtJiJrPH2JIySIPFKT86DVHKnbXKEgtE+He4bc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=R/9Sacz/djI2Ivcg1FUY5ZreHqLsh7mfV3d2nGiojOLGNhFNt5/7/AQOksD03daTVP9XZRS7qyjQ6RVnTRQsoMagEvwtZoUMWkaEJwuFqy5GM/swkQoF/Jtegz3kQfE7s/qQaAWFE178Fq7JnaMjEetwLLcXMyEWwWCarN+idk4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.218.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-a77cb7c106dso99364766b.1; Fri, 05 Jul 2024 08:14:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720192442; x=1720797242; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=h7ntbhccgXALWpWLNHUmzWoIXG74udOWs1KUfAeRQqk=; b=HTDZv8E7FioHlmJMnZuveOZbJPzEGglAu4VwtkeGjkIfZZLpCFgqXBSdA0D7S3y1lp WRMRQa4hhL/+t6cPZDzUrK/srQEAAx1Rz4veDZwEJen3msPWVgQXEkrC4dGSea1IU167 N/T8qU6o2qXWH31XT0TedkxZywYWnbWgfXtQvinBqWTIS290jLmrTVtuOpvb0XwzjZh4 QGYRtWJgG5ZVpcHSEZxHOlT2v17QKLoaPV5bjFEPyPJqGWNxzcuRPXmXq+6U3BeNcAg6 0fV1hEiIeiOlGjwCmezpNbdgpYDcsph2ayUlvF0u2qoIcPv7+6kpnsNS5pGVgHT4aadV NT7w== X-Forwarded-Encrypted: i=1; AJvYcCWr6h5xXhkNsVQRiQFm/rSeyJTu74boIOLJJjgCVsiKCb06ONnc2fDN6XHCL4HmKNc1Ul775+DNnGOnqB2uIbocZUXxpl4fQDn0WEJx X-Gm-Message-State: AOJu0YzJUZRTPve8WKAPV+/uevA8KFembCEiNeCSFz+DNuo6OwswSYL4 YA/pxYCCmDQ57FJGl/IphNwzoOEtRLaM3JbTKn1+4H2rjVWpQjYK5o/LJQ== X-Google-Smtp-Source: AGHT+IHgG+iQF5DSzz32+NK65g5H7nR0U1CRekw5L64vzqWqFJRL1PUd1roZp9OHvKKy92DK1dTnMw== X-Received: by 2002:a17:907:6e8d:b0:a72:8d40:52b8 with SMTP id a640c23a62f3a-a77ba44cf6dmr367219966b.3.1720192442400; Fri, 05 Jul 2024 08:14:02 -0700 (PDT) Received: from [127.0.0.1] (p200300f6f72f3200fa633ffffe02074c.dip0.t-ipconnect.de. [2003:f6:f72f:3200:fa63:3fff:fe02:74c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a72aaf6336csm686226566b.70.2024.07.05.08.14.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jul 2024 08:14:01 -0700 (PDT) From: Johannes Thumshirn Date: Fri, 05 Jul 2024 17:13:52 +0200 Subject: [PATCH v4 6/7] btrfs: rename brtfs_io_stripe::is_scrub to commit_root Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240705-b4-rst-updates-v4-6-f3eed3f2cfad@kernel.org> References: <20240705-b4-rst-updates-v4-0-f3eed3f2cfad@kernel.org> In-Reply-To: <20240705-b4-rst-updates-v4-0-f3eed3f2cfad@kernel.org> To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Johannes Thumshirn X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=openpgp-sha256; l=2170; i=jth@kernel.org; h=from:subject:message-id; bh=Fok4bTdJnN9CEf4tAvRVtqyQ7FJSvMwR/2K0tVu4Mso=; b=owGbwMvMwCV2ad4npfVdsu8YT6slMaR18G4yVp3StJ9h4+M69Z75c6wn7PWbc+meIVeyss6WR j891SVnO0pZGMS4GGTFFFmOh9rulzA9wj7l0GszmDmsTCBDGLg4BWAiywQYGQ7mSn86f+2CWH71 3SjrY/t7vEU2uzdpdE1WFQ3YuSXTPoDhn+EeuTUn/554bVaqVbiU6++7xa5Gs+rCTiXVth0KT0t cygwA X-Developer-Key: i=jth@kernel.org; a=openpgp; fpr=EC389CABC2C4F25D8600D0D00393969D2D760850 From: Johannes Thumshirn Rename brtfs_io_stripe's is_scrub to commit_root, as this is what it actually does, instruct btrfs_get_raid_extent_offset() to look at the commit root. Signed-off-by: Johannes Thumshirn --- fs/btrfs/bio.c | 2 +- fs/btrfs/raid-stripe-tree.c | 2 +- fs/btrfs/scrub.c | 2 +- fs/btrfs/volumes.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/bio.c b/fs/btrfs/bio.c index f04d93109960..5f36c75a2457 100644 --- a/fs/btrfs/bio.c +++ b/fs/btrfs/bio.c @@ -679,7 +679,7 @@ static bool btrfs_submit_chunk(struct btrfs_bio *bbio, int mirror_num) blk_status_t ret; int error; - smap.is_scrub = !bbio->inode; + smap.commit_root = !bbio->inode; btrfs_bio_counter_inc_blocked(fs_info); error = btrfs_map_block(fs_info, btrfs_op(bio), logical, &map_length, diff --git a/fs/btrfs/raid-stripe-tree.c b/fs/btrfs/raid-stripe-tree.c index ba0733c6be76..39085ff971c9 100644 --- a/fs/btrfs/raid-stripe-tree.c +++ b/fs/btrfs/raid-stripe-tree.c @@ -259,7 +259,7 @@ int btrfs_get_raid_extent_offset(struct btrfs_fs_info *fs_info, if (!path) return -ENOMEM; - if (stripe->is_scrub) { + if (stripe->commit_root) { path->skip_locking = 1; path->search_commit_root = 1; } diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c index 14a8d7100018..9c483b799cf1 100644 --- a/fs/btrfs/scrub.c +++ b/fs/btrfs/scrub.c @@ -1688,7 +1688,7 @@ static void scrub_submit_extent_sector_read(struct scrub_ctx *sctx, (i << fs_info->sectorsize_bits); int err; - io_stripe.is_scrub = true; + io_stripe.commit_root = true; stripe_len = (nr_sectors - i) << fs_info->sectorsize_bits; /* * For RST cases, we need to manually split the bbio to diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h index 37a09ebb34dd..25bc68af0df8 100644 --- a/fs/btrfs/volumes.h +++ b/fs/btrfs/volumes.h @@ -444,7 +444,7 @@ struct btrfs_io_stripe { /* Block mapping. */ u64 physical; u64 length; - bool is_scrub; + bool commit_root; /* For the endio handler. */ struct btrfs_io_context *bioc; }; From patchwork Fri Jul 5 15:13:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13725277 Received: from mail-ej1-f42.google.com (mail-ej1-f42.google.com [209.85.218.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1C2EF16F0DB; Fri, 5 Jul 2024 15:14:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720192446; cv=none; b=S+OmoUisQfjQ2459SW+VoauE4GH6VmRaL28lRlF8hZlA0cfP8VeFsTeitv3i2AW2HR+7bxsXDXwc4XiP7S+LkkR/euz9gGqlCHAyEqizmNMe/fqSA0LQr0pmqb6zC7LmJ9WelNYzj2wtW6D9KjTH3AqIdrLBgrAo2jhK2PfbdiY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720192446; c=relaxed/simple; bh=ekFx6/UsvaA/3yvaH2RA9a1JPfgBUUsMZ08ssWsFV38=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=JSiBpwJtqzMZVRtFs5pJMow4DoDkhFk/2nJ62pR57dMMQ6JLElbCwvU8grBOi2yIt/2jCNJLDItG8gEBryI6Jf0kFsDgISo1X8MDzrdhF5TeP/d4MqGTgc/0XgTPbUr6MkTAv5O2/Av/BqKIQJH22JO4miOpOV8vSYLU31CY/Sw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.218.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f42.google.com with SMTP id a640c23a62f3a-a77bf336171so255800866b.1; Fri, 05 Jul 2024 08:14:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720192443; x=1720797243; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=f892GFCIKQxBKmRhb+6kTPzjH25qhEZtsnNdHLdYsBk=; b=hNPQLW6bfc6Meovcbaisy7lKiaJsyl43iNqr1hEs364LV0o0gAyXnJEhSmyVsLj7Qq BVujgty32WfRCPzr75k7hOZC3BadoMYByXY4tM+Xg/TM6n/w4JUMIStXE3Yj9WTkxQM9 Eidm3G552mQYjUM6dv5ShwKV9Z63Pp5B6XNXxNExP88KNeNnDM+r9MBUqrQlc/x4dsul lLK/7Et0WcEf/ISo6pDGmxyF/55sEZJET6Ai9cjJQlnS6uCFT91QahaCOxUi2Dlf+kaO qfHD1wyKOrmN3NO/gZWHFxiwvVw+ZmbOEabxAqOGBytZsH4fcn31RJdvTC60ZrlaZxAX WyVA== X-Forwarded-Encrypted: i=1; AJvYcCW4ct/XBNDckBLJx07p6bDzgQ2nQCOoxwhPHqxVZ7tUShF0AgPB2PobosVhXjyZScsvqtx1JRT1pUqaShmKE0UY692hML3Hr8lGyja+ X-Gm-Message-State: AOJu0YwX6SMhieEdTxzKNJ0DKI+0A+Kq0KUf+CVMbtOH5CsTN+B3GLnc 4O8LjLi2E7QpFqRcYcGGTUCX59vWE/vvgo853DMSaXwMFem9QxbCVwuq9w== X-Google-Smtp-Source: AGHT+IFVxUY4sS9mTMtIhBvzUNkhz102rbCJKUOBFxcXi3a7FVoUIs9kA/GosIGgRyTTCvjRWOTCfw== X-Received: by 2002:a17:906:32c2:b0:a73:9037:fdf5 with SMTP id a640c23a62f3a-a77bd99ec77mr405247566b.6.1720192443334; Fri, 05 Jul 2024 08:14:03 -0700 (PDT) Received: from [127.0.0.1] (p200300f6f72f3200fa633ffffe02074c.dip0.t-ipconnect.de. [2003:f6:f72f:3200:fa63:3fff:fe02:74c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a72aaf6336csm686226566b.70.2024.07.05.08.14.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jul 2024 08:14:02 -0700 (PDT) From: Johannes Thumshirn Date: Fri, 05 Jul 2024 17:13:53 +0200 Subject: [PATCH v4 7/7] btrfs: stripe-tree: also look at commit root on relocation Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240705-b4-rst-updates-v4-7-f3eed3f2cfad@kernel.org> References: <20240705-b4-rst-updates-v4-0-f3eed3f2cfad@kernel.org> In-Reply-To: <20240705-b4-rst-updates-v4-0-f3eed3f2cfad@kernel.org> To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Johannes Thumshirn X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=openpgp-sha256; l=880; i=jth@kernel.org; h=from:subject:message-id; bh=8UH5N1FhZ+1tzlRwIIfBMRwnha9ThVa7PaBu24T5R78=; b=owGbwMvMwCV2ad4npfVdsu8YT6slMaR18G6aaVT5qmB3rMWtWr71v6d6vzI5fvzh11/zc+duP Sso+W99X0cpC4MYF4OsmCLL8VDb/RKmR9inHHptBjOHlQlkCAMXpwBMRP8zI8MJt1MrUhbx91Uk RkxjWZdcGv1eK+OFwfkjX3Yfk/K2FLJgZNgybWXVX05LZf2Qm68evWLX1J333vf4nqJVLLdrz69 ivsgDAA== X-Developer-Key: i=jth@kernel.org; a=openpgp; fpr=EC389CABC2C4F25D8600D0D00393969D2D760850 From: Johannes Thumshirn When doing reads on a raid stripe tree enabled system while relocation is ongoinig, also look at the commit root. The data we're interested in could've just been relocated to another place in the current transaction. Signed-off-by: Johannes Thumshirn --- fs/btrfs/bio.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/bio.c b/fs/btrfs/bio.c index 5f36c75a2457..948509ac343e 100644 --- a/fs/btrfs/bio.c +++ b/fs/btrfs/bio.c @@ -679,7 +679,8 @@ static bool btrfs_submit_chunk(struct btrfs_bio *bbio, int mirror_num) blk_status_t ret; int error; - smap.commit_root = !bbio->inode; + smap.commit_root = !bbio->inode || + btrfs_is_data_reloc_root(inode->root); btrfs_bio_counter_inc_blocked(fs_info); error = btrfs_map_block(fs_info, btrfs_op(bio), logical, &map_length,