From patchwork Mon Nov 18 22:40:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Coddington X-Patchwork-Id: 13879138 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 A3CD31E9060 for ; Mon, 18 Nov 2024 22:40:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731969653; cv=none; b=HL3mogrOABKL+ONBdZCxrCmv/l7n2eyS6EgcAB1ROqYfSchZCyBlfiumUMyQ0B2UWFMKtwZipPlqOrC4G54NL6w6/PGk/hyX0wfaIHtesdfMr4Zg4W9Q322BjLEva/EOuPwWc+pitLU70uKU9cEGDxYHZNCfdGRjmT8jbgCDIFQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731969653; c=relaxed/simple; bh=OZpi5m0VvYR7a432BKb/ytZedlbv1XMZi/Rq7CZphiQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZeS6CZxt3A6hi6btZeYiaZb+Ge/95WYXZiXRtWXYx5e3pXY+hhDv5BUvm9qOEwD44iL939eCF6l4GDRgG/cyFv7fFdrhDMLqExeetd5j9wijTedlrSwDkPwJvxJZLr1VlAdu/ImCiNBiYX/I+JRw8zrQ6JE6zeEl71SIjehPL8I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=TdCvfO87; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="TdCvfO87" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1731969650; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Oq9D3YuPWdAFaJGMJXmXZX1ELQaSyVylt8P6iK1TrM8=; b=TdCvfO87aroNoMZKBp2RDhk9iBjbiRbQBJMh1ruP4YYc82brIuZYlyBGfFw+PswJiBk3Pm FNkF6ZVeFY/LvyNS+e03XtvCk8FDG8/XhfIbM78ZfIstAXAir8Lt9bXtQLkItkA41x1lXo Uwv6meTcDfS3DKKkaZXqOPOGoaLTHyU= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-116-RJ_T4mIKN_Otdu3UblSYPQ-1; Mon, 18 Nov 2024 17:40:46 -0500 X-MC-Unique: RJ_T4mIKN_Otdu3UblSYPQ-1 X-Mimecast-MFC-AGG-ID: RJ_T4mIKN_Otdu3UblSYPQ Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 5B15B1977331; Mon, 18 Nov 2024 22:40:45 +0000 (UTC) Received: from bcodding.csb.redhat.com (unknown [10.22.74.7]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 3B8AB1955F43; Mon, 18 Nov 2024 22:40:44 +0000 (UTC) From: Benjamin Coddington To: Trond Myklebust , Anna Schumaker , Chuck Lever Cc: linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] nfs/blocklayout: Don't attempt unregister for invalid block device Date: Mon, 18 Nov 2024 17:40:40 -0500 Message-ID: In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Since commit d869da91cccb, an unmount of a pNFS SCSI layout-enabled NFS will dereference a NULL block_device in: bl_unregister_scsi+0x16/0xe0 [blocklayoutdriver] bl_free_device+0x70/0x80 [blocklayoutdriver] bl_free_deviceid_node+0x12/0x30 [blocklayoutdriver] nfs4_put_deviceid_node+0x60/0xc0 [nfsv4] nfs4_deviceid_purge_client+0x132/0x190 [nfsv4] unset_pnfs_layoutdriver+0x59/0x60 [nfsv4] nfs4_destroy_server+0x36/0x70 [nfsv4] nfs_free_server+0x23/0xe0 [nfs] deactivate_locked_super+0x30/0xb0 cleanup_mnt+0xba/0x150 task_work_run+0x59/0x90 syscall_exit_to_user_mode+0x217/0x220 do_syscall_64+0x8e/0x160 This happens because even though we were able to create the nfs4_deviceid_node, the lookup for the device was unable to attach the block device to the pnfs_block_dev. If we never found a block device to register, we can avoid this case with the PNFS_BDEV_REGISTERED flag. Move the deref behind the test for the flag. Fixes: d869da91cccb ("nfs/blocklayout: Fix premature PR key unregistration") Signed-off-by: Benjamin Coddington Reviewed-by: Christoph Hellwig --- fs/nfs/blocklayout/dev.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/fs/nfs/blocklayout/dev.c b/fs/nfs/blocklayout/dev.c index 6252f4447945..7ae79814f4ff 100644 --- a/fs/nfs/blocklayout/dev.c +++ b/fs/nfs/blocklayout/dev.c @@ -16,13 +16,16 @@ static void bl_unregister_scsi(struct pnfs_block_dev *dev) { - struct block_device *bdev = file_bdev(dev->bdev_file); - const struct pr_ops *ops = bdev->bd_disk->fops->pr_ops; + struct block_device *bdev; + const struct pr_ops *ops; int status; if (!test_and_clear_bit(PNFS_BDEV_REGISTERED, &dev->flags)) return; + bdev = file_bdev(dev->bdev_file); + ops = bdev->bd_disk->fops->pr_ops; + status = ops->pr_register(bdev, dev->pr_key, 0, false); if (status) trace_bl_pr_key_unreg_err(bdev, dev->pr_key, status); From patchwork Mon Nov 18 22:40:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Coddington X-Patchwork-Id: 13879139 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 1B3C71EABA6 for ; Mon, 18 Nov 2024 22:40:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731969655; cv=none; b=faAUC4ZdLEKrJDonBxPcTSqsnRvm6XDaCB0AINUVEGKMJW6ih1lmfcainf6WacAlt79PkIQmUx4UnelGwUqjXN6Pbt0l4yVl+4BkznNWx1i6JS2CIWnnK+1Y7BTagaKToCjOiyJkZ4sY9nW6PX6s0sTwhqDxaCA74GidlLeS+JU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731969655; c=relaxed/simple; bh=8I8cTzqmQIe8Mqr4QUvYjsVEy8nHn6IOzVkAEZwLuXc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qim8QUWPkrSWnXR5+SKfkVDazfqDqL8XvneXGoe1Xp3j+8UksweXSJ5ce7cxurZjohwu/eU+QMdaYqxnL051P88RZpAzgpp0yCl2kHlFu54AM2NtO/CKCHKLQNixBB/DU3e9Dz21U/VuY3GVSkg3LbTxPCM2sCVdP3zmGZ5WmP8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=h6aVnVll; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="h6aVnVll" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1731969653; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZI9kWRXGJcDQLwvjKncH58hpps9J9CvzzMy7vY4uSr4=; b=h6aVnVlli93ip4CZeZtZxf4vNbaawDJazhz4ybeEONjKIVVrgPggKvL8JVSeJ59Tsrp6au CkgsW5P9usJkPrQJGs5G/e1lgB1GTFOdOfn5+GHt2xxYBRI6iqL5wuYawMih1/Rf8jCok2 0N25f8u8ZRKakoe/4iHYevAttXTuVDY= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-138-28HYdbiYMiOF_0TF7n8kXQ-1; Mon, 18 Nov 2024 17:40:47 -0500 X-MC-Unique: 28HYdbiYMiOF_0TF7n8kXQ-1 X-Mimecast-MFC-AGG-ID: 28HYdbiYMiOF_0TF7n8kXQ Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id BC3A61944A8D; Mon, 18 Nov 2024 22:40:46 +0000 (UTC) Received: from bcodding.csb.redhat.com (unknown [10.22.74.7]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 9C58C1955F43; Mon, 18 Nov 2024 22:40:45 +0000 (UTC) From: Benjamin Coddington To: Trond Myklebust , Anna Schumaker , Chuck Lever Cc: linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] nfs/blocklayout: Limit repeat device registration on failure Date: Mon, 18 Nov 2024 17:40:41 -0500 Message-ID: In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 If we're unable to register a SCSI device, ensure we mark the device as unavailable so that it will timeout and be re-added via GETDEVINFO. This avoids repeated doomed attempts to register a device in the IO path. Add some clarifying comments as well. Fixes: d869da91cccb ("nfs/blocklayout: Fix premature PR key unregistration") Signed-off-by: Benjamin Coddington Reviewed-by: Christoph Hellwig --- fs/nfs/blocklayout/blocklayout.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/fs/nfs/blocklayout/blocklayout.c b/fs/nfs/blocklayout/blocklayout.c index 0becdec12970..b36bc2f4f7e2 100644 --- a/fs/nfs/blocklayout/blocklayout.c +++ b/fs/nfs/blocklayout/blocklayout.c @@ -571,19 +571,29 @@ bl_find_get_deviceid(struct nfs_server *server, if (!node) return ERR_PTR(-ENODEV); + /* + * Devices that are marked unavailable are left in the cache with a + * timeout to avoid sending GETDEVINFO after every LAYOUTGET, or + * constantly attempting to register the device. Once marked as + * unavailable they must be deleted and never reused. + */ if (test_bit(NFS_DEVICEID_UNAVAILABLE, &node->flags)) { unsigned long end = jiffies; unsigned long start = end - PNFS_DEVICE_RETRY_TIMEOUT; if (!time_in_range(node->timestamp_unavailable, start, end)) { + /* Force a new GETDEVINFO for this LAYOUT */ nfs4_delete_deviceid(node->ld, node->nfs_client, id); goto retry; } goto out_put; } - if (!bl_register_dev(container_of(node, struct pnfs_block_dev, node))) + /* If we cannot register, treat this device as transient */ + if (!bl_register_dev(container_of(node, struct pnfs_block_dev, node))) { + nfs4_mark_deviceid_unavailable(node); goto out_put; + } return node;