Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.167.179 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796306234; b=sZXNQTRS4D22p5EskDp0L5/0LRw+mctMClho1SHM2/ThB8F5hoqURuiC3k1vVjn3lX1w x4G9jHN/9VasvK7hGVu8Z62bRJ6KaZnDmFytaHcRbNKQwYGNDDKSfpLDMt+sKzbdHXeN1 tnfhO6J5+DaeVKW2syoh1btFkwtdqupLk1sFydqslm4Pnqin1QTl3exkQLmIUPHiag9zM UOdz7Y4Hnh6Jex+FwGbRxxAectHqJ7Dv89h7YJ/7wOQjRFDAUkfkMv7ZwNZ7L/n/G2v3P VTaWUovEMnUjBCXtRoeAdjlEk4jBmy8+JIqurTRR06gFCHtdit1lLvYJapdhEDFvHkw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796306234; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=rz0aJF39awF7JLlKjSsK4vGAtoBVn2+PxpNZkQUwdBo=; b=DM9pglVgkZruItcLqU3VHjz5AMee4w/+s7qUawObmbcyKpuDwAS3pdP4IJN8fQpUWffV POUBazkZWBU6qfwerC3jsMOjWk5m6iLVPMsbLijV10tGWJSzPm9EapXoVfKmh6rW1Or3i UwhuHZLsF31Plgd6NCcUjgEZri1kzEbwrAkblniuoAXVaNXqLbfrvXgZgGPVONtWjUMEc uv+cQj96BQzPK/K5x0/RxVqX61iuX1Om7XHYCAAofjoWIWFZW9c90Y8gcJIlc7dtXTSjG nJ/buMwlAoGS9kVo0ZqbUG930czYsE3InI6uNJU2ni6gDR/X4iHSFjWVWUi2CCew+FA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=hammerspace.com; spf=pass smtp.mailfrom=hammerspace.com; dkim=pass header.d=hammerspace.com header.i=@hammerspace.com header.a=rsa-sha256 header.s=google header.b=TmtDFP1s; arc=none smtp.remote-ip=209.85.167.179 Received: from mail-oi1-f179.google.com (mail-oi1-f179.google.com [209.85.167.179]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9F946606A337 for ; Thu, 3 Dec 2026 13:57:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9F946606A337 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=hammerspace.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=hammerspace.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=hammerspace.com header.i=@hammerspace.com header.a=rsa-sha256 header.s=google header.b=TmtDFP1s Received: by mail-oi1-f179.google.com with SMTP id 5614622812f47-4ab8cb2a6e4so9056744b6e.0 for ; Thu, 03 Dec 2026 05:57:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hammerspace.com; s=google; t=1796306233; x=1796911033; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=rz0aJF39awF7JLlKjSsK4vGAtoBVn2+PxpNZkQUwdBo=; b=TmtDFP1sWxh8kKw84vL5e53lWHWPTg9EzuomXuas7gsp2do4134t7dVlYO55OOKUCi vDCBQicQlPbaA/ecA4STtzmCJvphsx4uJL+fFpiPt6RR1kDygGWKtfDBOsM6Tk96XCf7 6QJA8EwsBl2tCG9oNGRK1GTKup8hZwyUB1hkoGbXD73CH+LvrvhLHDiz+EZvPRXEJ1U4 16jEadjN6MU18mWlMwhy6PfcSckz6UzgwY77SUKyJxi0qW/2NQaLpgkb0OvYEYxMKABV xbh8IA7xEPuyO1NzXV6UHst8AdgKU6uDRSTUJw1yzqnEBO+YmHfoE7VxWwalw1vrsu24 4ZqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796306233; x=1796911033; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=rz0aJF39awF7JLlKjSsK4vGAtoBVn2+PxpNZkQUwdBo=; b=sx+MuOW5HizPoGGh25MYEtTU9gmO/i/2rLKoTupkcKK2mRlVt23vlXGWHk/0KnMi+b 3zL4UoUxzpkYtPSZi82GGCl1komfb6ZtWRMJ1dWNI3IMOXXpsY5Glg+eyFxdHc4QcC/K RBvu7fGBrYgrUEOk8uzRcndVr+YPMaSryoY8boqjEQI9rsT08k/7CgFjc/5jLNoim9d+ jAUUMFS4uwxNE1GawHKJ+/J5S3RAyWWFiYdYDaTa2j40xnuaM8lwnyVR+3Iir0SoU+iO Assz1bdUlj/w5g80Y04xfUxZnp5dTeUk9Q8VVklT7jm9k4OMpuT2BCURV8yHfnCHtQbi OkiQ== X-Forwarded-Encrypted: i=1; AL+hErGJRCChqTSWsCRI7dt4d58/dyIDvGN1XDxmI1xgz2wGjV+IONt+FKoTd5cJnJtxryeeQl/W1IaLUCA=@vger.kernel.org X-Gm-Message-State: APuU4Z+m9Bt+VOfnLwL9mr1WorVPEfC+rBpeGG+zT8TOL7H4gXTB3eAE R11Mn9s9llaBiTt38824Q4mNG37mK3+neVIFCtdXZqshKC9MJo+1w8jXm8E+Z8i9N9E= X-Gm-Gg: AZFdTZeR/n+otZ4lFVakCAQ4MNmuVKXiz7vlShKam6pa8bZ0psEZIHVfM4t2F0fRVuW C2wPlaV0FbCmZ35GYiMRR6aAI2wbTcKwTmF8Oue+8G/u+/jSY+EYr9XV/pnUgETFoqUiEUvDPFk 8/LM1w0YgiqBDr2EVeWHTRnaDbSXHks3kVhLjL3DzleW4LFAqQecdnyLxcSpM83Oj4ELCQaocdn uy8PM5PZd5+ccd6L3g8PuW2K/1bEH9/cyje/oDVSVI3MVIFu6ouBVuwYr3iL9qmzr6d4XWoo9LL NFxOnA5GZI/watRK0ImCerwmA0vDT7j47ojxl/eHAIH4vIQENWfQvsn9CSIDJZitCC+px0lDhd6 ALTwi0O1iraazVIqkqPhbKR5KE/lrDLCnxIILVTBQ8fa74Wgms0UYDTvlxNAiyVnJiDBCRCuiQP FoAr+7pzORXn4+XLn/e1j5ImuFjixh0vDtykWogauzc/ST9CazCNhWTU+V5/6udNDZHwfYI/3T8 8rdNfb5rQ7NplryaygqeX5PiiF+Qau0lwt3aJO5kHUj0eB7jQIQVlQdjP24oFEaZB4YUZjSKcOo Z/qAOvLbgpiKDgahj9/TIAMf+2wdC+2BpTQYX7aOA73gdzXLuznlT++ePzGsHQk3hBnBHm8E X-Received: by 2002:a05:6808:c236:b0:573:a2a3:b747 with SMTP id 5614622812f47-57a0bc9d295mr50173797b6e.41.1796306232534; Thu, 03 Dec 2026 05:57:12 -0800 (PST) Received: from bcodding.csb.hammerspace.com ([66.97.168.37]) by smtp.gmail.com with ESMTPSA id 5614622812f47-57a350548ffsm30973955b6e.11.2026.12.03.05.57.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 05:57:12 -0800 (PST) From: Benjamin Coddington To: Trond Myklebust , Anna Schumaker , Mike Snitzer Cc: Olga Kornievskaia , linux-nfs@vger.kernel.org Subject: [PATCH v4 04/11] pNFS/flexfiles: don't switch a busy mirrored write descriptor to the MDS Date: Thu, 3 Dec 2026 08:56:59 -0500 Message-ID: <4ce0f4838fd597275d8a1211287651f55d5b2e7f.1796306148.git.bcodding@hammerspace.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: References: X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Benjamin Coddington nfs_pageio_reset_write_mds() replaces pg_ops before it completes the descriptor, so the completion sees only mirror 0. Requests queued on the other mirrors are never sent or cleaned up, the mirror array they are linked on is freed, and their folios never leave writeback. ff_layout_pg_init_write() falls back to the MDS from a later pg_init while other mirrors still hold requests: when the layout segment is gone, or when a mirror's DS cannot be prepared. After the previous patch the mirrors are sent together, so this happens when one mirror's request is retried during completion while the others still hold theirs, or when pg_init fails partway through the mirror copies of a request. In that case return -EAGAIN as for a mirror count change, so error cleanup redirties the queued requests, or requeues them for an O_DIRECT write, with the flexfiles ops still in place; the next pg_init starts from an empty descriptor and can switch safely. ff_layout_write_pagelist() returning PNFS_NOT_ATTEMPTED has the same problem through pnfs_write_through_mds(). For a mirrored layout, handle the failure the way FF_FLAGS_NO_IO_THRU_MDS already does: mark the layout for return with the failing device and return PNFS_TRY_AGAIN. RFC 8435 section 7 asks the client to retry with a new layout before falling back to the MDS, and section 8.2.3 leaves it to the server to decide, in that layout, whether the errant mirror stays. The retry's pg_init then uses the new layout, or goes to the MDS if the server has none to give. A fatal error preparing the DS, such as -ENOMEM or a signal, is no evidence against the device, so retry that one without returning the layout: pg_init prepares the DS again and falls back to the MDS if that fails too. A failure to create the DS RPC client is treated the same way; pg_init has nothing to prepare then, and the write is tried again. With FF_FLAGS_NO_IO_THRU_MDS such an error no longer returns the layout either; pg_init waits and prepares the DS again. A single-mirror descriptor keeps using PNFS_NOT_ATTEMPTED, now also when the RPC client can't be created: pnfs_write_through_mds() switches it safely, since its only mirror is not freed. Fixes: d67ae825a59d ("pnfs/flexfiles: Add the FlexFile Layout Driver") Cc: stable@vger.kernel.org # v4.0+ Signed-off-by: Benjamin Coddington --- fs/nfs/flexfilelayout/flexfilelayout.c | 48 +++++++++++++++++++------- 1 file changed, 36 insertions(+), 12 deletions(-) diff --git a/fs/nfs/flexfilelayout/flexfilelayout.c b/fs/nfs/flexfilelayout/flexfilelayout.c index a03ef583c391..309f50b29ccd 100644 --- a/fs/nfs/flexfilelayout/flexfilelayout.c +++ b/fs/nfs/flexfilelayout/flexfilelayout.c @@ -1150,6 +1150,22 @@ ff_layout_pg_init_read(struct nfs_pageio_descriptor *pgio, nfs_pageio_reset_read_mds(pgio); } +/* + * Switching to the MDS discards the mirror array, so it must not happen while + * any mirror still holds requests. + */ +static bool ff_layout_pg_mirrors_busy(struct nfs_pageio_descriptor *pgio) +{ + u32 i; + + if (pgio->pg_mirror_count == 1) + return false; + for (i = 0; i < pgio->pg_mirror_count; i++) + if (!list_empty(&pgio->pg_mirrors[i].pg_list)) + return true; + return false; +} + static void ff_layout_pg_init_write(struct nfs_pageio_descriptor *pgio, struct nfs_page *req) @@ -1215,6 +1231,8 @@ ff_layout_pg_init_write(struct nfs_pageio_descriptor *pgio, pgio->pg_error = -EAGAIN; return; out_mds: + if (ff_layout_pg_mirrors_busy(pgio)) + goto out_eagain; trace_pnfs_mds_fallback_pg_init_write(pgio->pg_inode, 0, NFS4_MAX_UINT64, IOMODE_RW, NFS_I(pgio->pg_inode)->layout, @@ -2437,8 +2455,10 @@ ff_layout_write_pagelist(struct nfs_pgio_header *hdr, int sync) ds_clnt = nfs4_ff_find_or_create_ds_client(mirror_ds, ds->ds_clp, hdr->inode); - if (IS_ERR(ds_clnt)) + if (IS_ERR(ds_clnt)) { + ds_fatal_error = true; goto out_failed; + } ds_cred = ff_layout_get_ds_cred(mirror, &lseg->pls_range, hdr->cred, mirror_ds, dss_id); @@ -2493,19 +2513,23 @@ ff_layout_write_pagelist(struct nfs_pgio_header *hdr, int sync) nfs4_ff_layout_put_deviceid(mirror_ds); if (ff_layout_avoid_mds_available_ds(lseg) && !ds_fatal_error) return PNFS_TRY_AGAIN; - if (ff_layout_no_fallback_to_mds(lseg)) { - /* - * FF_FLAGS_NO_IO_THRU_MDS: force fresh LAYOUTGET, - * never fall through to MDS I/O. - */ + if (!ff_layout_no_fallback_to_mds(lseg) && + FF_LAYOUT_MIRROR_COUNT(lseg) == 1) { + trace_pnfs_mds_fallback_write_pagelist(hdr->inode, + hdr->args.offset, hdr->args.count, + IOMODE_RW, NFS_I(hdr->inode)->layout, lseg); + return PNFS_NOT_ATTEMPTED; + } + /* + * FF_FLAGS_NO_IO_THRU_MDS forbids MDS I/O, and + * pnfs_write_through_mds() cannot switch a mirrored descriptor, so + * retry. A fatal error is no evidence against the DS: keep the + * layout then, and let pg_init of the retry prepare the DS again. + */ + if (!ds_fatal_error) pnfs_error_mark_layout_for_return(hdr->inode, lseg, &mirror->dss[dss_id].devid); - return PNFS_TRY_AGAIN; - } - trace_pnfs_mds_fallback_write_pagelist(hdr->inode, - hdr->args.offset, hdr->args.count, - IOMODE_RW, NFS_I(hdr->inode)->layout, lseg); - return PNFS_NOT_ATTEMPTED; + return PNFS_TRY_AGAIN; } static struct nfs_fh * -- 2.53.0