From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 2FC7E92462 for ; Tue, 4 Oct 2022 15:48:51 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 030C1447E for ; Tue, 4 Oct 2022 15:48:21 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Tue, 4 Oct 2022 15:48:18 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 668D3447AA for ; Tue, 4 Oct 2022 15:48:18 +0200 (CEST) From: Stoiko Ivanov To: pve-devel@lists.proxmox.com Date: Tue, 4 Oct 2022 15:47:59 +0200 Message-Id: <20221004134803.3605742-3-s.ivanov@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221004134803.3605742-1-s.ivanov@proxmox.com> References: <20221004134803.3605742-1-s.ivanov@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.179 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pve-devel] [PATCH zfsonlinux 2/6] trim: determine if a device uses nvme transport with lsblk (Closes: #990745) X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Oct 2022 13:48:51 -0000 Thanks to Miao Wang for get_transp() function (cherry picked from debian-upstream[0] commit 1f5433b15e4f7c823983bb90390c4b023f3d1948) [0] https://salsa.debian.org/zfsonlinux-team/zfs Signed-off-by: Stoiko Ivanov --- .../zfsutils-linux/usr/lib/zfs-linux/trim | 29 +++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/debian/tree/zfsutils-linux/usr/lib/zfs-linux/trim b/debian/tree/zfsutils-linux/usr/lib/zfs-linux/trim index 5b6305b0..91d00bb0 100755 --- a/debian/tree/zfsutils-linux/usr/lib/zfs-linux/trim +++ b/debian/tree/zfsutils-linux/usr/lib/zfs-linux/trim @@ -26,14 +26,33 @@ trim_if_not_already_trimming () { fi } +get_transp () { + local dev="$1" + local par_dev="$dev" + local pd + while true; do + pd=$(lsblk -dnr -o PKNAME "$par_dev") + if [ "$?" -ne 0 ]; then + return $? + fi + if [ -z "$pd" ]; then + break + else + par_dev="/dev/$pd" + fi + done + lsblk -dnr -o TRAN "$par_dev" +} + zpool_is_nvme_only () { zpool=$1 # get a list of devices attached to the specified zpool - zpool list -vHPL "${zpool}" | - awk -F'\t' '$2 ~ /^\/dev\// { - if($2 !~ /^\/dev\/nvme/) - exit 1 - }' + for x in $(zpool list -vHPL "${zpool}" |\ + awk -F'\t' '{if($2 ~ /^\/dev\//) print $2}'); do + if [ "$(get_transp $x)" != "nvme" ]; then + return 1 + fi + done } # TRIM all healthy pools that are not already trimming as per their configs. -- 2.30.2