From patchwork Thu Jan 16 21:38:46 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13942336 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DE7691D5AA8 for ; Thu, 16 Jan 2025 21:38:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737063528; cv=none; b=UL9duoazUfz1xywqjDu2xFc+8o6iAqr8nF/kZ9gDyJW81tFSaLEjtQpkm83aMFBHiHohfnVzSMHN56VSQg0IpuDhDXIRopdz0ascbbktSJYUHOrjhhZv+rQDN33/Yh2SnqMM4sReLC1I9HqyWVwWmfEC6XhCaYVdL7c1rDne0zE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737063528; c=relaxed/simple; bh=Q8PKJt5gyx6h6/8FjkYbbDi8qxgzKHJi55ZBo6yNwKk=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hK6hCp5U7T5s2ClfMmL3wh2sqLgiFfGIKm4aJlRDnOe89WTTeXRo87v2CKB0o5F+mgmVSFz/nl9f16opzQw8ebeptocpbz28gn9Hn+f1MrPFpBQDzQtVDD1rdSTtqus64r8xgxcXFM+CEfTsnCpRmrbZYHFkIiohNwhknUJVl2U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CzJz2N/T; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="CzJz2N/T" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5A87BC4CED6; Thu, 16 Jan 2025 21:38:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1737063527; bh=Q8PKJt5gyx6h6/8FjkYbbDi8qxgzKHJi55ZBo6yNwKk=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=CzJz2N/Tt1tXQlaID08v7ECxNa6HDGMsAmbImXXbT61tH7srT6ZhAOBr76Hz5kTxW 6+1D2C6yy3BqZkG/KE7omIs0flvkaWohh5FrUm6mhxkFBaNb3WpHQ2AeHsdEF1gZV1 6qqnh8PrK2p9nfDsDAS7A3kZfInbhOgxW0xfaTaXALFBdpyR555GQZK2NzofJx18Ys VKL5D5hie/CddAYtictt1hxjkstiDXxb+VXp1KuX5QHXceXzTbeFb6FHuJvRS1HY0u vI3zPlaHffInsbC/6BWiB2L1P+nBiqJ1F8Pdpral4xvkrYeAwUmRM3jEmr1l9U3HFZ 6dk7LOz1d5Grw== Date: Thu, 16 Jan 2025 13:38:46 -0800 Subject: [PATCH 1/8] xfs_db: fix multiple dblock commands From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: tom.samstag@netrise.io, tom.samstag@netrise.io, hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173706332222.1823674.15603891144443245230.stgit@frogsfrogsfrogs> In-Reply-To: <173706332198.1823674.17512820639050359555.stgit@frogsfrogsfrogs> References: <173706332198.1823674.17512820639050359555.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Tom Samstag reported that running the following sequence of commands no longer works quite right: > inode [inodenum] > dblock 0 > p > dblock 1 > p > dblock 2 > p > [etc] Mr. Samstag looked into the source code and discovered that the dblock_f is incorrectly accessing iocur_top->data outside of the push_cur -> set_cur_inode -> pop_cur sequence that this function uses to compute the type of the file data. In other words, it's using whatever's on top of the stack at the start of the function. For the "dblock 0" case above this is the inode, but for the "dblock 1" case this is the contents of file data block 0, not an inode. Fix this by relocating the check to the correct place. Reported-by: tom.samstag@netrise.io Tested-by: Tom Samstag Cc: # v6.12.0 Fixes: b05a31722f5d4c ("xfs_db: access realtime file blocks") Signed-off-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- db/block.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/db/block.c b/db/block.c index 00830a3d57e1df..2f1978c41f3094 100644 --- a/db/block.c +++ b/db/block.c @@ -246,6 +246,7 @@ dblock_f( int nb; xfs_extnum_t nex; char *p; + bool isrt; typnm_t type; bno = (xfs_fileoff_t)strtoull(argv[1], &p, 0); @@ -255,6 +256,7 @@ dblock_f( } push_cur(); set_cur_inode(iocur_top->ino); + isrt = is_rtfile(iocur_top->data); type = inode_next_type(); pop_cur(); if (type == TYP_NONE) { @@ -273,7 +275,7 @@ dblock_f( ASSERT(typtab[type].typnm == type); if (nex > 1) make_bbmap(&bbmap, nex, bmp); - if (is_rtfile(iocur_top->data)) + if (isrt) set_rt_cur(&typtab[type], xfs_rtb_to_daddr(mp, dfsbno), nb * blkbb, DB_RING_ADD, nex > 1 ? &bbmap : NULL); From patchwork Thu Jan 16 21:39:02 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13942337 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B70A81B0F30 for ; Thu, 16 Jan 2025 21:39:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737063543; cv=none; b=OYBtmVNjl4+ytJ1xRc5Q5X+y06VXu5UvtXF2fDiAiuSgpixKgK0p/WWEpz7yKR2WCJTSqeCIuIiYTpprhuYekB36UEn6ILYX06GkahntpGKOZhL/sWX4yGnctX7TubWsaVFcyStN/nMzPkoIC6NbT3S3dei4PAG6/jj+4VyirFE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737063543; c=relaxed/simple; bh=mz61MqxE1RzwA/m4v8O8qX8H3KKZ0Y6kvkaCxAoAY/A=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=GH6a4Z3Gsdp3lPwFyn14//FPnzSBW5thNH/wWdLvqQhcyP33UtDcxk/7CuSvnOQ/wyYcjDmcftb+J72EXASUkUw7PPs2KZIC4UKsoQdplnQQBNlcjzw6VlMODo1ICh5MzlKD2JhrlY4yvRVpObxdk6tr54EX6QaIQHM7KoRwZVA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YwDGR9Ey; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="YwDGR9Ey" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3A088C4CED6; Thu, 16 Jan 2025 21:39:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1737063543; bh=mz61MqxE1RzwA/m4v8O8qX8H3KKZ0Y6kvkaCxAoAY/A=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=YwDGR9EyKHCfbCTNsjhPUBuCXUu5JGTzIGLQSgyrIVdbIn8IwGfxs5qaOiCNGJsaF 9SIwaQoc3qydKc4eMT8CZD51vNZ9sShY3kDTLuqBcd3EpmZZ5+yzbwYReFPuI6WQUN WJDyppbrc8cGfqfqVGnjrQAZevVb1nWVqxvV7kMJPdorOG3YGYCewDgBl/ozA8DmzV TIEgEp7AUylShDTVbJ4/8xbYmTV/zQ37RWRZaeJKTJ2seT4oDoli5dMmaFDtuo0sQA jiV6h1Px/A19xnJWYmG3zEVuojlqMy0ZiUfVsV1E/QQRN2zMtuJcfzyXZox+/4410k rMEcKc4Cr3jCg== Date: Thu, 16 Jan 2025 13:39:02 -0800 Subject: [PATCH 2/8] xfs_repair: don't obliterate return codes From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173706332237.1823674.4750925735232214007.stgit@frogsfrogsfrogs> In-Reply-To: <173706332198.1823674.17512820639050359555.stgit@frogsfrogsfrogs> References: <173706332198.1823674.17512820639050359555.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Don't clobber error here, it's err2 that's the temporary variable. Coverity-id: 1637363 Fixes: b790ab2a303d58 ("xfs_repair: support quota inodes in the metadata directory") Signed-off-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- repair/quotacheck.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/repair/quotacheck.c b/repair/quotacheck.c index 8c7339b267d8e6..7953144c3f416b 100644 --- a/repair/quotacheck.c +++ b/repair/quotacheck.c @@ -691,7 +691,7 @@ discover_quota_inodes( err2 = mark_quota_inode(tp, dp, XFS_DQTYPE_GROUP); if (err2 && !error) error = err2; - error = mark_quota_inode(tp, dp, XFS_DQTYPE_PROJ); + err2 = mark_quota_inode(tp, dp, XFS_DQTYPE_PROJ); if (err2 && !error) error = err2; From patchwork Thu Jan 16 21:39:18 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13942338 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 583361862 for ; Thu, 16 Jan 2025 21:39:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737063560; cv=none; b=jkjRkoCFrmcoIjspYxjnRaRU3XkDSrfzobG0SDh4L0nUET8HOPmodNytbNBZq5C/xRIdVB6kMZMRYkJC2asvY0PPXHNiIrxa9sWirI5gxF5vpAyfMkHrL+wZB4QzHZH8fK5fvBFdIqhQ4jgRBb8gWSsE9rhpdusKnuSih+OF7j4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737063560; c=relaxed/simple; bh=wogcHI5ryNCdDtXslixyus7GN4/FJsJSkqKpiEHZCfo=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=QZW6an8yfdLpb1DVCqbP2M6NsmrxeEJCY5TJAzr++DZY4rU4N4lxeTgRyx3rFtgu1Wr2LJMfSJfO0loeifyvmMrr798k7Vga4Yny4GDG8/fNIcxfr9iOU/smNpZfvowgs5UNDaz3U/CmWVZ9wPWgI8oygsue1hRENh0SJOfPJDo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JDmO1tyV; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="JDmO1tyV" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D7066C4CED6; Thu, 16 Jan 2025 21:39:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1737063558; bh=wogcHI5ryNCdDtXslixyus7GN4/FJsJSkqKpiEHZCfo=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=JDmO1tyV/UgeIP66Qumcdk8QzUywQ6tL6+j/ELWUX0yX11qhUUeMlrliXEylfQQTF zmE3R0/GG+lZS7cwnXTtsEuaYwxqLIv//a4QGSXKdP5aByntQ9TGWhpETqu1CM6jrN MxZUFSEtR9gNgIfMBI2f6W8qoWh8W73VveZ+bApFX2AnrIDF9lbcA9++MO8P8O7q6a abuv9YY28t538gf2Xx8hmW1ZSuzFytPsefB+t/r/r0XhUilNSLEIIGhDJNENiZtwid rGgAd1eCZ7g4BZeJQY3ZVT42SPufHXoHw5ct+VBx5X6++pd/mbdu5cboJFbbL2g3AQ 0HamWRu2b56Mg== Date: Thu, 16 Jan 2025 13:39:18 -0800 Subject: [PATCH 3/8] libxfs: fix uninit variable in libxfs_alloc_file_space From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173706332252.1823674.14773579267642290396.stgit@frogsfrogsfrogs> In-Reply-To: <173706332198.1823674.17512820639050359555.stgit@frogsfrogsfrogs> References: <173706332198.1823674.17512820639050359555.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Fix this uninitialized variable. Coverity-id: 1637359 Fixes: b48164b8cd7618 ("libxfs: resync libxfs_alloc_file_space interface with the kernel") Signed-off-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- libxfs/util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libxfs/util.c b/libxfs/util.c index 4a9dd254083a63..3597850ddccb9a 100644 --- a/libxfs/util.c +++ b/libxfs/util.c @@ -193,7 +193,7 @@ libxfs_alloc_file_space( int rt; xfs_trans_t *tp; xfs_bmbt_irec_t imaps[1], *imapp; - int error; + int error = 0; if (len <= 0) return -EINVAL; From patchwork Thu Jan 16 21:39:34 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13942339 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F18BC1862 for ; Thu, 16 Jan 2025 21:39:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737063576; cv=none; b=NCIbcmjcM1LGJxB1gEqIvB1NlrngG1jHnaecBV7yG/tYz2LvG3lyuPWf6BA0xMcFblOdCgZSrbyg6GqnuT14BH8c7TTdh1ekGw4BdHmNYqLqIO9cCuI9nQ9MYylQbjYIKgZJi6LDkDPmv3W/471GPftUeBDZ9Bnxplk9YkNSegk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737063576; c=relaxed/simple; bh=0Tq1dBj50r8t0p4f/GbpiltLenVOdsnTIhMegwpiIrk=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=iT73FxrXORbcI3hX8T1j4maQSuy3oIz09D9Hieq2u0tifdlCe+qJq2tIBgYM8O+U4pNSv0WEnkIURayk6kXi1mVSR1hlma/R2z0fBRfuUdZxB6p4JkRe180Kp+cJgAILZUJB2MAmKlI9Oq4kc4lTtaAZNjhW3EL1eyKN5jTPGyE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mUDU9YAE; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="mUDU9YAE" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 74ED0C4CED6; Thu, 16 Jan 2025 21:39:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1737063574; bh=0Tq1dBj50r8t0p4f/GbpiltLenVOdsnTIhMegwpiIrk=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=mUDU9YAEJWmmr4q03876BLNI+fcrucmb1rqIp6g2ca8Xe9VY6eFnrWBpzJZTuvMsu ljRoqSiRgAvokwYX6UV9jd8GcRUS2rb8dfOQ7VjVULN16W79boaT/z+i59NRPzWTEu KwbBxOBwBa6++7SlcS2yS3MkJ4Q+WV1oFhNaIxMQEFvdP8aIUu9URKwx33IzsYBRfO iIC+eJ287+S0Zw15Q6gVYhf3LftgEcnVFRmTrJrsEAgnglVH94N04JQIaH2uU9PPBy mT6g8TQq/nYaZn5y/D+CfRLkR0zVBDGlXmcGfhueVZ/K9tjf6JSFuI0xIHLiLj8Dbu IA/iFisHT8pWw== Date: Thu, 16 Jan 2025 13:39:34 -0800 Subject: [PATCH 4/8] xfs_db: improve error message when unknown btree type given to btheight From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173706332266.1823674.6627837665243659732.stgit@frogsfrogsfrogs> In-Reply-To: <173706332198.1823674.17512820639050359555.stgit@frogsfrogsfrogs> References: <173706332198.1823674.17512820639050359555.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong I found accidentally that if you do this (note 'rmap', not 'rmapbt'): xfs_db /dev/sda -c 'btheight -n 100 rmap' The program spits back "Numerical result out of range". That's the result of it failing to match "rmap" against a known btree type, and falling back to parsing the string as if it were a btree geometry description. Improve this a little by checking that there's at least one semicolon in the string so that the error message improves to: "rmap: expected a btree geometry specification" Fixes: cb1e69c564c1e0 ("xfs_db: add a function to compute btree geometry") Signed-off-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- db/btheight.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/db/btheight.c b/db/btheight.c index 6643489c82c4c9..98165b522e4f6f 100644 --- a/db/btheight.c +++ b/db/btheight.c @@ -145,6 +145,12 @@ construct_records_per_block( } } + p = strchr(tag, ':'); + if (!p) { + fprintf(stderr, _("%s: expected a btree geometry specification.\n"), tag); + return -1; + } + toktag = strdup(tag); ret = -1; From patchwork Thu Jan 16 21:39:49 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13942340 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AB5541862 for ; Thu, 16 Jan 2025 21:39:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737063591; cv=none; b=nELeh9yJ3bWQgq9fTXhe4qH53QBeyPWhuHYerlcnQM6OZ+kOn7GaXAV3uGjOp/iLmMoHU/SPmuPKKzHzuUTdM6brA5+Xe2P7OC7mm2h9aKNbXCKsYoF12pE5gayX+E3fC+VD2HeIYow39qdxlkMp5gcn/lTBLEWmBv0o5ytf2Hs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737063591; c=relaxed/simple; bh=Qd4zBf5Eb6KRQOJGSLE6Pno9kaM38ZPUoyqVSIV0XlQ=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=kDUyntxWMCnscBvIZNbbssylX85ZYJzRGPX7nTXEbFsgCULBalxMP5Qf/gTi9si2M1hPjBIJXAfYMT/LLqBlPNW//vneLGXNahSJopsvA+9C6T3tuXY2pl2OHE7xXGBbgGe7j8O2i9WSIAr9O9/hNEzK2HH6bZT9y5kgAtAfos8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=V5lHKvyh; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="V5lHKvyh" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 22DCBC4CED6; Thu, 16 Jan 2025 21:39:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1737063590; bh=Qd4zBf5Eb6KRQOJGSLE6Pno9kaM38ZPUoyqVSIV0XlQ=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=V5lHKvyhRUqXz/yj9U+/TNL0wW6rsUN6u+z4OnfzFEehInG1ru70Td7Fq6ifMMoRW kkgfQsr2gDJgen80rYEGD+lx1eA4/vkAlG6VvuGPs4AAXtqopO+C0lZm554kwICvXy /rOT/4rzxChyZ7PizJlz5NtsCIXMmzziagm5VL9AMrk5zJQir56S4nlUy0UNLOBCfs NFvzscKfzLbBYfC9RlHH0aaAC2/9ZBirm39G2iRCsDOdvuvOfa55VrHJa+WgyfcwNV gd/yr4iZA4kXXsugnlLbMsbc3TWcdx4jm9R1bjPyJW/UHGLyzlTYr9R+gOz7m+sBWJ /TZ9GLvH7yohg== Date: Thu, 16 Jan 2025 13:39:49 -0800 Subject: [PATCH 5/8] mkfs: fix parsing of value-less -d/-l concurrency cli option From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173706332281.1823674.7436201439160217375.stgit@frogsfrogsfrogs> In-Reply-To: <173706332198.1823674.17512820639050359555.stgit@frogsfrogsfrogs> References: <173706332198.1823674.17512820639050359555.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong It's supposed to be possible to specify the -d concurrency option with no value in order to get mkfs calculate the agcount from the number of CPUs. Unfortunately I forgot to handle that case (optarg is null) so mkfs crashes instead. Fix that. Fixes: 9338bc8b1bf073 ("mkfs: allow sizing allocation groups for concurrency") Signed-off-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- mkfs/xfs_mkfs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c index 956cc295489342..deaac2044b94dd 100644 --- a/mkfs/xfs_mkfs.c +++ b/mkfs/xfs_mkfs.c @@ -1722,7 +1722,7 @@ set_data_concurrency( * "nr_cpus" or "1" means set the concurrency level to the CPU count. * If this cannot be determined, fall back to the default AG geometry. */ - if (!strcmp(value, "nr_cpus")) + if (!value || !strcmp(value, "nr_cpus")) optnum = 1; else optnum = getnum(value, opts, subopt); @@ -1867,7 +1867,7 @@ set_log_concurrency( * "nr_cpus" or 1 means set the concurrency level to the CPU count. If * this cannot be determined, fall back to the default computation. */ - if (!strcmp(value, "nr_cpus")) + if (!value || !strcmp(value, "nr_cpus")) optnum = 1; else optnum = getnum(value, opts, subopt); From patchwork Thu Jan 16 21:40:05 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13942341 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 53CD5198A0D for ; Thu, 16 Jan 2025 21:40:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737063607; cv=none; b=BzAiZFPl97F+gYgSO5pc0YB6symqcDm70gxzIINAbm7cuEOphLSc6hTBhxBfTA5OwvEAJElgkNwDDl8XwlWuvIVCeDWjYdDNhWbP90ZJya/cw2wPc1n+2HfroKYKmdC+n+8Z6xxOsdXyo5ZQW11Xb57JGEsZhLMLq9VRXe7wSvw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737063607; c=relaxed/simple; bh=Nc0wLvhUAW6K2K1O1XAU2PmRPIopkK3RTegodvlnFfs=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=G8WIAsAEpFHVPtdjwX+fglNzRTbMnSyKGPJ2k/SPQOv9+z/1LFXKM5yd0tmRmuB6f5Y7bg6M1HBmvNn7ZnTvham1JtikpuamExy3Sr9+XhnvIDHbwRunTH2JohgCYyyppde7ojlxbiqlfKl+ePNcUjkvKIbEVPkBqYyhdWUfCmo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=k8N3YXEe; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="k8N3YXEe" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B7585C4CEDD; Thu, 16 Jan 2025 21:40:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1737063605; bh=Nc0wLvhUAW6K2K1O1XAU2PmRPIopkK3RTegodvlnFfs=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=k8N3YXEeMrgIgvXBbqMNET0GWtGi1wHPZI/EAZHqvCYevIf3Lm3fQZC/vC71kPoxC sFFtVkHXZJ5IbLFiHAjMCd3WiiA1S2zIvNhC31Gf4uifTvd3Jaf/c148QQ0FuUk8hi zRG4GenD2D1NhjABi3nfgBqmBma9qOwxvZ2id1uCTATXzPzeRifEe4bYMN50Y+9yoy cTaqIWoUme8VUIFYGkj58dRgP/CZvLah0Ts0gkifR9uwNkvR1uptgOQFKyBKPlrg5E 5UNIefGncL+OQDpakOE8YG9zVcRiDktiBBjFELWhaFwKWaI6CKUMU7ui7hB4WLppz4 w3q8oRfywL+og== Date: Thu, 16 Jan 2025 13:40:05 -0800 Subject: [PATCH 6/8] m4: fix statx override selection if /usr/include doesn't define it From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173706332296.1823674.4865518424967775302.stgit@frogsfrogsfrogs> In-Reply-To: <173706332198.1823674.17512820639050359555.stgit@frogsfrogsfrogs> References: <173706332198.1823674.17512820639050359555.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong If the system headers (aka the ones in /usr/include) do not define struct statx at all, we need to use our internal override. The m4 code doesn't handle this admittedly corner case, but let's fix it for anyone trying to build new xfsprogs on a decade-old distribution. Fixes: 409477af604f46 ("xfs_io: add support for atomic write statx fields") Signed-off-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- m4/package_libcdev.m4 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/m4/package_libcdev.m4 b/m4/package_libcdev.m4 index 6db1177350b643..4ef7e8f67a3ba6 100644 --- a/m4/package_libcdev.m4 +++ b/m4/package_libcdev.m4 @@ -112,7 +112,7 @@ AC_DEFUN([AC_NEED_INTERNAL_STATX], need_internal_statx=yes, [#include ] ) - ],, + ],need_internal_statx=yes, [#include ] ) AC_SUBST(need_internal_statx) From patchwork Thu Jan 16 21:40:20 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13942342 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C6EF5198A0D for ; Thu, 16 Jan 2025 21:40:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737063621; cv=none; b=O232uo1R4d4il/13/7ZSS84SMnH4y4ZbBLdAJ8Or/7ZRtVhAhlyvYezcCbBLOKNmXThv7H9uWJxS3n6FgEG7VDJoZYs0YTG1CUMfOqWulgaWDv6TYFcbE7A2T4ghMC+a32k1h1w1FtyaQKPmsLdimVjDLe+7KfDmZ5oh3cUGCpU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737063621; c=relaxed/simple; bh=WQD3ZXK/TDCd9m+hmZEwoLoSaDB2ApXMz34y5eLV3nU=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=DRFdq2/XztU8PDwNbZjFOMGrKllGOaTpOpjBsRZ9tzCjcG5Tofrg7f2qoauOrCMNo38lXO49ECyrN9nnPck26nmazOdbO6SbSxNt85bPOspV8gloBBf6rMTqGx9vQOwF393Q5FjZItz66HYRWc0ifQpg3dTUNxITV9R/Oz3LcPU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KYDu6tf/; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="KYDu6tf/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5E429C4CED6; Thu, 16 Jan 2025 21:40:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1737063621; bh=WQD3ZXK/TDCd9m+hmZEwoLoSaDB2ApXMz34y5eLV3nU=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=KYDu6tf/LFvjISHaxpF2RE09kguqr1+0+nSCYCrbhCLS9bKr1Y5IJ69clOtVHNSKB HciMa+wjFw1S2Rx5rykjzP1qqjITl/PHalxAr26RPOXjimN3S7IUShTDHTE7zpMzOF TswRFxAp7l5+1jEcYJGEH885CiliOk/Zvz8xnRJX4il+3zFLFoR5cGgLzhhD0i7MTX WuKv0SK9n3NesDkeNYy4IptR2dLMnesrOAWuTx9vtjuxEfQEPMTFP5M2Ckrz7APc+z i7/8gagWICpghetE+Hf64wwQIQMPV8jUlHUvvdd03oCIjts5G272ZxBd058NhUmA0W 7HHn8Ou2eotBw== Date: Thu, 16 Jan 2025 13:40:20 -0800 Subject: [PATCH 7/8] build: initialize stack variables to zero by default From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <173706332310.1823674.14707219486092901346.stgit@frogsfrogsfrogs> In-Reply-To: <173706332198.1823674.17512820639050359555.stgit@frogsfrogsfrogs> References: <173706332198.1823674.17512820639050359555.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Newer versions of gcc and clang can include the ability to zero stack variables by default. Let's enable it so that we (a) reduce the risk of writing stack contents to disk somewhere and (b) try to reduce unpredictable program behavior based on random stack contents. The kernel added this 6 years ago, so I think it's mature enough for xfsprogs. Signed-off-by: "Darrick J. Wong" Reluctantly-Reviewed-by: Christoph Hellwig --- configure.ac | 1 + include/builddefs.in | 2 +- m4/package_sanitizer.m4 | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 224d1d3930bf2f..90ef7925a925d0 100644 --- a/configure.ac +++ b/configure.ac @@ -177,6 +177,7 @@ AC_CONFIG_SYSTEMD_SYSTEM_UNIT_DIR AC_CONFIG_CROND_DIR AC_CONFIG_UDEV_RULE_DIR AC_HAVE_BLKID_TOPO +AC_HAVE_TRIVIAL_AUTO_VAR_INIT if test "$enable_ubsan" = "yes" || test "$enable_ubsan" = "probe"; then AC_PACKAGE_CHECK_UBSAN diff --git a/include/builddefs.in b/include/builddefs.in index ac43b6412c8cbb..82840ec7fd3adb 100644 --- a/include/builddefs.in +++ b/include/builddefs.in @@ -146,7 +146,7 @@ ifeq ($(HAVE_LIBURCU_ATOMIC64),yes) PCFLAGS += -DHAVE_LIBURCU_ATOMIC64 endif -SANITIZER_CFLAGS += @addrsan_cflags@ @threadsan_cflags@ @ubsan_cflags@ +SANITIZER_CFLAGS += @addrsan_cflags@ @threadsan_cflags@ @ubsan_cflags@ @autovar_init_cflags@ SANITIZER_LDFLAGS += @addrsan_ldflags@ @threadsan_ldflags@ @ubsan_ldflags@ # Use special ar/ranlib wrappers if we have lto diff --git a/m4/package_sanitizer.m4 b/m4/package_sanitizer.m4 index 41b729906a27ba..6488f7ebce2f50 100644 --- a/m4/package_sanitizer.m4 +++ b/m4/package_sanitizer.m4 @@ -57,3 +57,17 @@ AC_DEFUN([AC_PACKAGE_CHECK_THREADSAN], AC_SUBST(threadsan_cflags) AC_SUBST(threadsan_ldflags) ]) + +# Check if we have -ftrivial-auto-var-init=zero +AC_DEFUN([AC_HAVE_TRIVIAL_AUTO_VAR_INIT], + [ AC_MSG_CHECKING([if C compiler supports zeroing automatic vars]) + OLD_CFLAGS="$CFLAGS" + TEST_CFLAGS="-ftrivial-auto-var-init=zero" + CFLAGS="$CFLAGS $TEST_CFLAGS" + AC_LINK_IFELSE([AC_LANG_PROGRAM([])], + [AC_MSG_RESULT([yes])] + [autovar_init_cflags=$TEST_CFLAGS], + [AC_MSG_RESULT([no])]) + CFLAGS="${OLD_CFLAGS}" + AC_SUBST(autovar_init_cflags) + ]) From patchwork Thu Jan 16 21:40:36 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13942343 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6A2D319343E for ; Thu, 16 Jan 2025 21:40:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737063637; cv=none; b=mDF39nV3bRXvspqTJJ6gMZwvhBbYB/heLvbKTqE4bXZIh+aAdTFHm9NEdMGBYlWi0E9nlotoWCzcBU+AS60WCxIUhOmRRHKsKWJJiIzEgHfcr2PIhY/h3gNJH5WZLNZCqldgmKLdV11sDisazh2udpF7WHd8Pp6NvgbvldWh7po= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737063637; c=relaxed/simple; bh=U3EC5xpx9yTBUKmvtKw+IMVzfbgPTBCNlcsoCsKlu0c=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=YI/ek/R4RdTxR0PuOAYV+qELqmPE/TkLxEAJU/r34gkZgrjUjgD+pZL0H79xKj9SkieI3Wce3JR8TeIIVeqxAnemgQ/IIYQTRgi1agKTI0DttMmhknH/H/WsniYj0B8X+SJXHD4HnH+ZyRMzgvNkGY+jRzJec4QRkQWulntmdD0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=E+DcTkCg; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="E+DcTkCg" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F18F8C4CED6; Thu, 16 Jan 2025 21:40:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1737063637; bh=U3EC5xpx9yTBUKmvtKw+IMVzfbgPTBCNlcsoCsKlu0c=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=E+DcTkCgp94dNwqi48rjRfJSRwC7OQWnAWszE2+yyrlDNGgtAv5qnQiw+ukw9Vo19 IdBrMbHXCQb1THrpCSgziF23sX4PMt3shY5nouriux4FxRtKdP76DVOYRYTFB15JCm DpdgO4t7RYJRsfKp6heWj7TVlPAsWy6Pml59ZrTmMvTVzoXmECPzmox2nWUgcCNFGM pk0/HE085QqMzhDp7rOyoFEOxHHtqFDcEk6VhxRFZWPKZs3VPYLVKJzFw5HgOvtT8S gUE7tv7kLoM177t/J8nRAb2I2WGHfhVo/YEvTgyt4EGJYnlQYvnqvtsQq44Q6PZd7W OiEk6G0J5J5Pg== Date: Thu, 16 Jan 2025 13:40:36 -0800 Subject: [PATCH 8/8] mkfs: allow sizing realtime allocation groups for concurrency From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173706332326.1823674.12394486107801229381.stgit@frogsfrogsfrogs> In-Reply-To: <173706332198.1823674.17512820639050359555.stgit@frogsfrogsfrogs> References: <173706332198.1823674.17512820639050359555.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Add a -r concurrency= option to mkfs so that sysadmins can configure the filesystem so that there are enough rtgroups that the specified number of threads can (in theory) can find an uncontended rtgroup from which to allocate space. This has the exact same purpose as the -d concurrency switch that was added for the data device. Signed-off-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- man/man8/mkfs.xfs.8.in | 28 ++++++++++ mkfs/xfs_mkfs.c | 140 +++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 165 insertions(+), 3 deletions(-) diff --git a/man/man8/mkfs.xfs.8.in b/man/man8/mkfs.xfs.8.in index 32361cf973fcf8..37e3a88e7ac777 100644 --- a/man/man8/mkfs.xfs.8.in +++ b/man/man8/mkfs.xfs.8.in @@ -1220,6 +1220,34 @@ .SH OPTIONS and .B rgsize suboptions are mutually exclusive. +.TP +.BI concurrency= value +Create enough realtime allocation groups to handle the desired level of +concurrency. +The goal of this calculation scheme is to set the number of rtgroups to an +integer multiple of the number of writer threads desired, to minimize +contention of rtgroup locks. +This scheme will neither create fewer rtgroups than would be created by the +default configuration, nor will it create rtgroups smaller than 4GB. +This option is not compatible with the +.B rgcount +or +.B rgsize +options. +The magic value +.I nr_cpus +or +.I 1 +or no value at all will set this parameter to the number of active processors +in the system. +If the kernel advertises that the realtime device is a non-mechanical storage +device, +.B mkfs.xfs +will use this new geometry calculation scheme. +The magic value of +.I 0 +forces use of the older rtgroups geometry calculations that is used for +mechanical storage. .RE .PP .PD 0 diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c index deaac2044b94dd..073e79ac58303c 100644 --- a/mkfs/xfs_mkfs.c +++ b/mkfs/xfs_mkfs.c @@ -134,6 +134,7 @@ enum { R_NOALIGN, R_RGCOUNT, R_RGSIZE, + R_CONCURRENCY, R_MAX_OPTS, }; @@ -737,6 +738,7 @@ static struct opt_params ropts = { [R_NOALIGN] = "noalign", [R_RGCOUNT] = "rgcount", [R_RGSIZE] = "rgsize", + [R_CONCURRENCY] = "concurrency", [R_MAX_OPTS] = NULL, }, .subopt_params = { @@ -778,6 +780,7 @@ static struct opt_params ropts = { }, { .index = R_RGCOUNT, .conflicts = { { &ropts, R_RGSIZE }, + { &ropts, R_CONCURRENCY }, { NULL, LAST_CONFLICT } }, .minval = 1, .maxval = XFS_MAX_RGNUMBER, @@ -785,12 +788,22 @@ static struct opt_params ropts = { }, { .index = R_RGSIZE, .conflicts = { { &ropts, R_RGCOUNT }, + { &ropts, R_CONCURRENCY }, { NULL, LAST_CONFLICT } }, .convert = true, .minval = 0, .maxval = (unsigned long long)XFS_MAX_RGBLOCKS << XFS_MAX_BLOCKSIZE_LOG, .defaultval = SUBOPT_NEEDS_VAL, }, + { .index = R_CONCURRENCY, + .conflicts = { { &ropts, R_RGCOUNT }, + { &ropts, R_RGSIZE }, + { NULL, LAST_CONFLICT } }, + .convert = true, + .minval = 0, + .maxval = INT_MAX, + .defaultval = 1, + }, }, }; @@ -1034,6 +1047,7 @@ struct cli_params { int proto_slashes_are_spaces; int data_concurrency; int log_concurrency; + int rtvol_concurrency; /* parameters where 0 is not a valid value */ int64_t agcount; @@ -1157,7 +1171,8 @@ usage( void ) /* no-op info only */ [-N]\n\ /* prototype file */ [-p fname]\n\ /* quiet */ [-q]\n\ -/* realtime subvol */ [-r extsize=num,size=num,rtdev=xxx,rgcount=n,rgsize=n]\n\ +/* realtime subvol */ [-r extsize=num,size=num,rtdev=xxx,rgcount=n,rgsize=n,\n\ + concurrency=num]\n\ /* sectorsize */ [-s size=num]\n\ /* version */ [-V]\n\ devicename\n\ @@ -2071,6 +2086,31 @@ proto_opts_parser( return 0; } +static void +set_rtvol_concurrency( + struct opt_params *opts, + int subopt, + struct cli_params *cli, + const char *value) +{ + long long optnum; + + /* + * "nr_cpus" or "1" means set the concurrency level to the CPU count. + * If this cannot be determined, fall back to the default rtgroup + * geometry. + */ + if (!value || !strcmp(value, "nr_cpus")) + optnum = 1; + else + optnum = getnum(value, opts, subopt); + + if (optnum == 1) + cli->rtvol_concurrency = nr_cpus(); + else + cli->rtvol_concurrency = optnum; +} + static int rtdev_opts_parser( struct opt_params *opts, @@ -2101,6 +2141,9 @@ rtdev_opts_parser( case R_RGSIZE: cli->rgsize = getstr(value, opts, subopt); break; + case R_CONCURRENCY: + set_rtvol_concurrency(opts, subopt, cli, value); + break; default: return -EINVAL; } @@ -3740,10 +3783,97 @@ _("realtime group size (%llu) not at all congruent with extent size (%llu)\n"), return 0; } +static bool +rtdev_is_solidstate( + struct libxfs_init *xi) +{ + unsigned short rotational = 1; + int error; + + error = ioctl(xi->rt.fd, BLKROTATIONAL, &rotational); + if (error) + return false; + + return rotational == 0; +} + +static void +calc_concurrency_rtgroup_geometry( + struct mkfs_params *cfg, + struct cli_params *cli, + struct libxfs_init *xi) +{ + uint64_t try_rgsize; + uint64_t def_rgsize; + uint64_t def_rgcount; + int nr_threads = cli->rtvol_concurrency; + int try_threads; + + if (is_power_of_2(cfg->rtextblocks)) + def_rgsize = calc_rgsize_extsize_power(cfg); + else + def_rgsize = calc_rgsize_extsize_nonpower(cfg); + def_rgcount = howmany(cfg->rtblocks, def_rgsize); + try_rgsize = def_rgsize; + + /* + * If the caller doesn't have a particular concurrency level in mind, + * set it to the number of CPUs in the system. + */ + if (nr_threads < 0) + nr_threads = nr_cpus(); + + /* + * Don't create fewer rtgroups than what we would create with the + * default geometry calculation. + */ + if (!nr_threads || nr_threads < def_rgcount) + goto out; + + /* + * Let's try matching the number of rtgroups to the number of CPUs. If + * the proposed geometry results in rtgroups smaller than 4GB, reduce + * the rtgroup count until we have 4GB rtgroups. Don't let the thread + * count go below the default geometry calculation. + */ + try_threads = nr_threads; + try_rgsize = cfg->rtblocks / try_threads; + if (try_rgsize < GIGABYTES(4, cfg->blocklog)) { + do { + try_threads--; + if (try_threads <= def_rgcount) { + try_rgsize = def_rgsize; + goto out; + } + + try_rgsize = cfg->rtblocks / try_threads; + } while (try_rgsize < GIGABYTES(4, cfg->blocklog)); + goto out; + } + + /* + * For large filesystems we try to ensure that the rtgroup count is a + * multiple of the desired thread count. Specifically, if the proposed + * rtgroup size is larger than both the maximum rtgroup size and the + * rtgroup size we would have gotten with the defaults, add the thread + * count to the rtgroup count until we get an rtgroup size below both + * of those factors. + */ + while (try_rgsize > XFS_MAX_RGBLOCKS && try_rgsize > def_rgsize) { + try_threads += nr_threads; + try_rgsize = cfg->dblocks / try_threads; + } + +out: + cfg->rgsize = try_rgsize; + cfg->rgcount = howmany(cfg->rtblocks, cfg->rgsize); +} + static void calculate_rtgroup_geometry( struct mkfs_params *cfg, - struct cli_params *cli) + struct cli_params *cli, + struct libxfs_init *xi) { if (!cli->sb_feat.metadir) { cfg->rgcount = 0; @@ -3783,6 +3913,9 @@ _("rgsize (%s) not a multiple of fs blk size (%d)\n"), /* too small even for a single group */ cfg->rgsize = cfg->rtblocks; cfg->rgcount = 0; + } else if (cli->rtvol_concurrency > 0 || + (cli->data_concurrency == -1 && rtdev_is_solidstate(xi))) { + calc_concurrency_rtgroup_geometry(cfg, cli, xi); } else if (is_power_of_2(cfg->rtextblocks)) { cfg->rgsize = calc_rgsize_extsize_power(cfg); cfg->rgcount = cfg->rtblocks / cfg->rgsize + @@ -4890,6 +5023,7 @@ main( .is_supported = 1, .data_concurrency = -1, /* auto detect non-mechanical storage */ .log_concurrency = -1, /* auto detect non-mechanical ddev */ + .rtvol_concurrency = -1, /* auto detect non-mechanical rtdev */ .autofsck = FSPROP_AUTOFSCK_UNSET, }; struct mkfs_params cfg = {}; @@ -5077,7 +5211,7 @@ main( */ calculate_initial_ag_geometry(&cfg, &cli, &xi); align_ag_geometry(&cfg); - calculate_rtgroup_geometry(&cfg, &cli); + calculate_rtgroup_geometry(&cfg, &cli, &xi); calculate_imaxpct(&cfg, &cli);