Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.53 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796406132; b=Mr3kxgGmei/q7TnijlQlD6wnlUVw9tIfPplLIG+NRlG1ddp9jU76zQz3xCuPzrCmf1oj c8AEXXqAPnxEpjaaAnMQZPRg0dXNzJFJmjwLesBWVjWUU4Ry9TQ8lhpRCddsxUW/lRBRI 8QRZWIE54/od+XOPU7uVCQvJdHP4dcvBLq/DfMUr0kpD5zVuYxsCGf8hY3g6X+d1Bk73G 0N8u4l/ux/Sn3m2eNoPnePvaSA0bgvlqYA/7wU/vz44pGW0MH+mf2o6JCPa+F6kudAZ5g ZISqTWuXYqs4r1Sw3EZjDKK47/P8duuQqZ4zalTfGLnD4Qsjfi/gnLBs37TYItHNuRg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796406132; 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=uciMBRCg9YmbkqLxs1ykAOBEC8RP7vfHX/ANJO0mKW0=; b=0qrYAKiztwk9yKgezTqYJ+fEBLCSEEchMZ7Uh3KyTFglGQSUTBGKDzRVUnzuq0jrBrWx nTJmlxZhJFXB+DD8rmPLgsaIuTbdVVD64UGswKC4HBlZG2pz4GkQiFuDxlsX1mN0mZULS HlnBFjjpaTF9jlUqB9v2ksSqtAaO8e0Pyu/40WM+zUIxmRVMTGHS0al+5kdrvkRkjhBjO xHgTiLDEU5XxcNXqsJAFe8mtqKTcey4/BokI6mEGyOc2CpmG/pVaGaf9PLF86tEUMriUc 2k7IDo10vXbgVZq4wgVAaO1/rFbRHe5qtnkrlDsAQv8wVKGXg1nktS3pXs7mfSV2FiQ== 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=PxSnwkL8; arc=none smtp.remote-ip=209.85.161.53 Received: from mail-oo1-f53.google.com (mail-oo1-f53.google.com [209.85.161.53]) (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 CED7B606A32C for ; Fri, 4 Dec 2026 17:42:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org CED7B606A32C 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=PxSnwkL8 Received: by mail-oo1-f53.google.com with SMTP id 006d021491bc7-6d68de53053so683642eaf.0 for ; Fri, 04 Dec 2026 09:42:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hammerspace.com; s=google; t=1796406131; x=1797010931; 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=uciMBRCg9YmbkqLxs1ykAOBEC8RP7vfHX/ANJO0mKW0=; b=PxSnwkL8LcGKjdMhfK1LSybHnyVeQ42Sa3iRpv7HAtnTCdo+Jm+4uYnHkXPMTYPNZC 1OoXKTMdcd3iqZmDK76wTZ4H1fd6kW5jZebJX4x4EQG/qAe3RVep9X9n70W9gAFaDkso lq3htKjWWlUOe9cN1OQWxvo5X6Iunfq6eS83cpoK/x5xRyEkE4MMuPCmQJjvS4EHyL4L Qm3jrnxoI4tvKkdIyYKTs+QKCxoJyW9Ji49QUQPbxCvXBLdy/+mAQ8vMSrR+hTCfYzRX h/7F4CBmBmrew/1sYmLxyYJql4UetyujVtWAMEywQ59Klhccm+SYDF1qULM3Wx67n6bX 7lzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796406131; x=1797010931; 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=uciMBRCg9YmbkqLxs1ykAOBEC8RP7vfHX/ANJO0mKW0=; b=UJBAJIS5is4FS5xX1t/GWC8zi/y12amppDucvBkkkBAMexRzE5oxsntz3TWHy+eqFr Ae+XLA3BKBqPLVuH6I+aBwoWkYURmMQ24FvC/Xt8mRI75DxecsMsyl09+k4YVyrPJIm/ WZu5cvUYeMpIhYn2hsujJod0I/jgj1vLRmMR9xuNy08wxRy86BkTR6ZxRBa/hdutX0P4 Nwg9AKBfVhie83AG/WRD91euMmEg3r7aHXaAfISN39eTt6InQOk323c76F7O7qP3D3N1 xYLbvYokIJUhHeK/fNEicfvUQiYOfVRTOboUjGeo57Mj363wI9mLxMrNetjxnd4ysNVB ijjQ== X-Forwarded-Encrypted: i=1; AL+hErFO6CwJ5SMkLJ3jtM0ZUE3JKJvCNkuGmVtBVES8TVPos1z8pa9C6+880NVK2HzRXCa1HWNkIDQbcZ4=@vger.kernel.org X-Gm-Message-State: APuU4Z8sEVDTSHUVFrTlWDF2uDs5Rmo2a61nwMfLg7PjDSJz/uiAT4ql c1fhQCsWzo/rkTiOffMAoaSArpqi5WZaBD1XgJ4k7wDaSKSq7ozacBbcx5GUrrplWIE= X-Gm-Gg: AZFdTZc4RYtW7/2xX31xcIOui29GS9AOmMpfoPhkeVZd+s12/GEwuJKr7m86zAI/5tx EilNj+a88i/NjR98gUehAra6f7we/eZcZi/2DgIpMj/FiLQJOC8c6ZT4lLxupzBFm0Vg8RZfAgP 9SOVkltlzXO9plWKRlPsEUvVUMMwwf9EGFBgUsqFecn+rs42HF3wIzS6RICurPqlTqFELZr2okh OF8aVjCGPwCnIXr87S5hQaCX35ZjCOaHRBTkyhcspEywkqcuGFEXRW1rQqn2aPS7RXqAWhwINTO 0TCDpb3rW2Bz2tyFHpWKDNaLupekA0TgEnMp7IC9zV3Ic/BQYmRUxWKuGcauoeQUZ33kMhBZyU2 uyMOAPYdf5tyU51AHaoH18WGS9p/iK4VRwaQf9qme8p2zxtw1df4hND+U/JNGLfSSf+zbuvtIvJ JLTXnRRykkROu0iGkuIOmCGgNJeJqhg9CYFFdDUuAgS7N71uV41Dl0M9f5/Bz5DCAgoZM3CofhF wtD8DN+GPjSwXQmm6HbcWdjRvfAHrH+Rzq4V8N18+hDk/zQELeiJWAD2bOxxQynuJPhnyAunjg5 vIVAa7krSp97r5lDHM/sh72dyB3Gi6LOVaHEcdi1/dJFOBhv4yqK1RtDy+8TVf6iau+CcOY5 X-Received: by 2002:a05:6820:1394:b0:71a:f5b7:e0c6 with SMTP id 006d021491bc7-71bf21ac504mr2653792eaf.51.1796406130635; Fri, 04 Dec 2026 09:42:10 -0800 (PST) Received: from bcodding.csb.hammerspace.com ([66.97.168.37]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-71bef0cd34asm3035398eaf.3.2026.12.04.09.42.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 09:42:10 -0800 (PST) From: Benjamin Coddington To: Trond Myklebust , Anna Schumaker , Mike Snitzer Cc: Olga Kornievskaia , linux-nfs@vger.kernel.org Subject: [PATCH v5 04/12] pNFS/flexfiles: don't switch a busy mirrored write descriptor to the MDS Date: Fri, 4 Dec 2026 12:41:55 -0500 Message-ID: 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. 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 failure to create the DS RPC client comes after the DS is prepared, so pg_init has nothing to wait for and the write would be refused again at once. Return the layout for that failure whenever the write doesn't go to the MDS, including when another DS is available, so that the retry waits for a new layout. 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 # v6.6+ Signed-off-by: Benjamin Coddington --- fs/nfs/flexfilelayout/flexfilelayout.c | 56 ++++++++++++++++++++------ 1 file changed, 43 insertions(+), 13 deletions(-) diff --git a/fs/nfs/flexfilelayout/flexfilelayout.c b/fs/nfs/flexfilelayout/flexfilelayout.c index a03ef583c391..7af1d0a94e64 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, @@ -2421,6 +2439,7 @@ ff_layout_write_pagelist(struct nfs_pgio_header *hdr, int sync) u32 idx = hdr->pgio_mirror_idx; u32 dss_id; bool ds_fatal_error = false; + bool ds_clnt_error = false; mirror = FF_LAYOUT_COMP(lseg, idx); dss_id = nfs4_ff_layout_calc_dss_id( @@ -2437,8 +2456,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_clnt_error = true; goto out_failed; + } ds_cred = ff_layout_get_ds_cred(mirror, &lseg->pls_range, hdr->cred, mirror_ds, dss_id); @@ -2491,21 +2512,30 @@ ff_layout_write_pagelist(struct nfs_pgio_header *hdr, int sync) out_failed: nfs4_ff_layout_put_deviceid(mirror_ds); - if (ff_layout_avoid_mds_available_ds(lseg) && !ds_fatal_error) + /* + * The DS is already prepared when its RPC client can't be created, + * so a retry on this layout would fail the same way at once. + */ + if (ff_layout_avoid_mds_available_ds(lseg) && !ds_fatal_error && + !ds_clnt_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