From patchwork Mon Aug 12 13:20:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wouter Verhelst X-Patchwork-Id: 13760630 Received: from lounge.grep.be (lounge.grep.be [144.76.219.42]) (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 CFC6817B51B; Mon, 12 Aug 2024 13:52:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=144.76.219.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723470733; cv=none; b=MqmEbqTqbbN2MzjUF2p7Pswflo26Ds4ob2EyqF0iYSb8SPnzBFssOA8M7edAoPsqJ+WVkHmYoYaJedes82Giwb8/Rigw3uviaN3Cre8U4KuQxkuVYMTeKMVEns2vO8HtAPIRYLhJwrj95XRLt05tNUfCCg7Dts/EDKv7rJHYFKA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723470733; c=relaxed/simple; bh=cAwbV8ZC5p+BD1zrpaL4RfTaUIEHIZ/3hYRfMPKIN40=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QA5BZbtglIz+0Bbjt1zqDqlpQrOJ/mPp1zww1N7OSCuvru4U/LWLD6ItnEgcyaRKfIHCO23GPa2AP8sCEFWodNprr7SzlGBGNEd6+0Og1Woel9VH3DgIU0FRE0fUEfMcMfUl4cGFbWPRBV2RAfi+LLH1OIeUgeYLhKyAtbcdPSA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=uter.be; spf=pass smtp.mailfrom=grep.be; dkim=fail (0-bit key) header.d=grep.be header.i=@grep.be header.b=lejhTNoi reason="key not found in DNS"; arc=none smtp.client-ip=144.76.219.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=uter.be Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=grep.be Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="key not found in DNS" (0-bit key) header.d=grep.be header.i=@grep.be header.b="lejhTNoi" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=grep.be; s=2017.latin; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To :Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=CPlFTzWYOxO8KdoJEO4L163n14ZVh0BcaBrQIuR5/Qw=; b=lejhTNoiOkuHrQYDnylirgBRaU vhDHsj3iX9yX2EYHJ+7bKVH5m+YF/iOP+kpKZcd/NGnUiSiosnbxo+l7ugraxtMERGOqVmhFy9WrV wrbEYwqsk2q/2+UWEqStSibq4MNhIl0XKDZYIDmf4ed6QUI7LBPqRUEOYFV5Fu701MxPHQI2Lh5T9 sj5pel2QK4VQLjjhcqp7dBGjl6+T9BfGgdV99j1ANOA2LnOHzendaBjiFzKh4m9iZSWMXrdC0aI9/ kWCSs/Cnpu2CoJQOBxN2G21aXu9wU5kD3T0+8TV3FscwJwGbSPspOEHFXPVwNGMdrFjZwm+uxQgkA cW2sFlSQ==; Received: from vc-gp-n-105-245-229-160.umts.vodacom.co.za ([105.245.229.160] helo=pc220518) by lounge.grep.be with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1sdVSl-009Xjz-0O; Mon, 12 Aug 2024 15:51:55 +0200 Received: from wouter by pc220518 with local (Exim 4.98) (envelope-from ) id 1sdVAp-00000000V90-3y1J; Mon, 12 Aug 2024 15:33:23 +0200 From: Wouter Verhelst To: Josef Bacik , Jens Axboe Cc: Wouter Verhelst , Eric Blake , Damien Le Moal , linux-block@vger.kernel.org, nbd@other.debian.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 1/3] nbd: implement the WRITE_ZEROES command Date: Mon, 12 Aug 2024 15:20:37 +0200 Message-ID: <20240812133032.115134-3-w@uter.be> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240812133032.115134-1-w@uter.be> References: <20240812133032.115134-1-w@uter.be> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The NBD protocol defines a message for zeroing out a region of an export Add support to the kernel driver for that message. Signed-off-by: Wouter Verhelst Cc: Eric Blake Reviewed-by: Damien Le Moal --- drivers/block/nbd.c | 8 ++++++++ include/uapi/linux/nbd.h | 5 ++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c index 5b1811b1ba5f..b2b69cc5ca23 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -352,6 +352,8 @@ static int __nbd_set_size(struct nbd_device *nbd, loff_t bytesize, } if (nbd->config->flags & NBD_FLAG_ROTATIONAL) lim.features |= BLK_FEAT_ROTATIONAL; + if (nbd->config->flags & NBD_FLAG_SEND_WRITE_ZEROES) + lim.max_write_zeroes_sectors = UINT_MAX >> SECTOR_SHIFT; lim.logical_block_size = blksize; lim.physical_block_size = blksize; @@ -421,6 +423,8 @@ static u32 req_to_nbd_cmd_type(struct request *req) return NBD_CMD_WRITE; case REQ_OP_READ: return NBD_CMD_READ; + case REQ_OP_WRITE_ZEROES: + return NBD_CMD_WRITE_ZEROES; default: return U32_MAX; } @@ -637,6 +641,8 @@ static blk_status_t nbd_send_cmd(struct nbd_device *nbd, struct nbd_cmd *cmd, if (req->cmd_flags & REQ_FUA) nbd_cmd_flags |= NBD_CMD_FLAG_FUA; + if ((req->cmd_flags & REQ_NOUNMAP) && (type == NBD_CMD_WRITE_ZEROES)) + nbd_cmd_flags |= NBD_CMD_FLAG_NO_HOLE; /* We did a partial send previously, and we at least sent the whole * request struct, so just go and send the rest of the pages in the @@ -1706,6 +1712,8 @@ static int nbd_dbg_flags_show(struct seq_file *s, void *unused) seq_puts(s, "NBD_FLAG_SEND_FUA\n"); if (flags & NBD_FLAG_SEND_TRIM) seq_puts(s, "NBD_FLAG_SEND_TRIM\n"); + if (flags & NBD_FLAG_SEND_WRITE_ZEROES) + seq_puts(s, "NBD_FLAG_SEND_WRITE_ZEROES\n"); return 0; } diff --git a/include/uapi/linux/nbd.h b/include/uapi/linux/nbd.h index d75215f2c675..f1d468acfb25 100644 --- a/include/uapi/linux/nbd.h +++ b/include/uapi/linux/nbd.h @@ -42,8 +42,9 @@ enum { NBD_CMD_WRITE = 1, NBD_CMD_DISC = 2, NBD_CMD_FLUSH = 3, - NBD_CMD_TRIM = 4 + NBD_CMD_TRIM = 4, /* userspace defines additional extension commands */ + NBD_CMD_WRITE_ZEROES = 6, }; /* values for flags field, these are server interaction specific. */ @@ -53,11 +54,13 @@ enum { #define NBD_FLAG_SEND_FUA (1 << 3) /* send FUA (forced unit access) */ #define NBD_FLAG_ROTATIONAL (1 << 4) /* device is rotational */ #define NBD_FLAG_SEND_TRIM (1 << 5) /* send trim/discard */ +#define NBD_FLAG_SEND_WRITE_ZEROES (1 << 6) /* supports WRITE_ZEROES */ /* there is a gap here to match userspace */ #define NBD_FLAG_CAN_MULTI_CONN (1 << 8) /* Server supports multiple connections per export. */ /* values for cmd flags in the upper 16 bits of request type */ #define NBD_CMD_FLAG_FUA (1 << 16) /* FUA (forced unit access) op */ +#define NBD_CMD_FLAG_NO_HOLE (1 << 17) /* Do not punch a hole for WRITE_ZEROES */ /* These are client behavior specific flags. */ #define NBD_CFLAG_DESTROY_ON_DISCONNECT (1 << 0) /* delete the nbd device on From patchwork Mon Aug 12 13:20:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wouter Verhelst X-Patchwork-Id: 13760632 Received: from lounge.grep.be (lounge.grep.be [144.76.219.42]) (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 44BA817D34D; Mon, 12 Aug 2024 13:52:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=144.76.219.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723470744; cv=none; b=Ju4IifJQBLx6QbH7Mojti/5nGMh/IKKsfryW7npSg7A0VU9MBJW/OMV2qMwzlZp1W0Qg0mzGMvYJHrnWbUqrNL/gRKEe9vh9wLS9BYbLzx06UE7fuuPPT2DIsQIKkWDSwxVpF3vm2w4WytArIEQivNoc7RLQK26T5ejQSN+JjdY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723470744; c=relaxed/simple; bh=1nykpV20XzUyh1xghYDzTzIRKc3dX90aa7aq40fZ6iI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tYvCdaXzwbxDlQcVmWRJGkfjr/bNqaS/nXKpwjo1XY0LIyEzvgWYeK3TLeC8XyohTJ3KWHUvwpI/XRDBEQUn7F/0p3slMEeHd7ZT1xrhcIgJPJCM6Zssc6hd79t4VCTOnzkV6JgwgtdS780WAVeUAkrcpKV/UrDyZtjKxkYiDVY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=uter.be; spf=pass smtp.mailfrom=grep.be; dkim=fail (0-bit key) header.d=grep.be header.i=@grep.be header.b=rdvzS5oT reason="key not found in DNS"; arc=none smtp.client-ip=144.76.219.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=uter.be Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=grep.be Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="key not found in DNS" (0-bit key) header.d=grep.be header.i=@grep.be header.b="rdvzS5oT" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=grep.be; s=2017.latin; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To :Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=ExUwhfh9phkCbbYOnXzCUwr8Bo5hwWP+odZj9PhevEY=; b=rdvzS5oT+ybPlKqsblXfZflCUc yL8cJELY5LfnVLjER++4v8mfqpFeoFCkInWE/NH1Pbjf4JfIBu0fQlJpzVaYiJQE5FyVdulRqOsJJ GvUjvI8bCPp7WTPVJsggz0INvLbd3BQ6IrSUgWvFU/Xhmxn7hcnEVrY4he+jmECksIbjByiOJiq1j 19V72j1hAVGLdnsTT/CO+boe2HmqHXuuMLT3GAXAGg99+ROMYryy9YDknYkR2cpTnB34wSlm+GICl 9AfTQZu+dI7lEY5UTuhbfDhHeL6lvVfurf5iCnjUdj83+K3Z+XiQGyQJcLYpWaWAy4Uf0bvkfouEc xS+QY3Fg==; Received: from vc-gp-n-105-245-229-160.umts.vodacom.co.za ([105.245.229.160] helo=pc220518) by lounge.grep.be with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1sdVT6-009Xv2-1r; Mon, 12 Aug 2024 15:52:16 +0200 Received: from wouter by pc220518 with local (Exim 4.98) (envelope-from ) id 1sdVBW-00000000VEg-3N10; Mon, 12 Aug 2024 15:34:06 +0200 From: Wouter Verhelst To: Josef Bacik , Jens Axboe Cc: Wouter Verhelst , Eric Blake , Damien Le Moal , linux-block@vger.kernel.org, nbd@other.debian.org, linux-kernel@vger.kernel.org, Eric Blake Subject: [PATCH v4 2/3] nbd: nbd_bg_flags_show: add NBD_FLAG_ROTATIONAL Date: Mon, 12 Aug 2024 15:20:40 +0200 Message-ID: <20240812133032.115134-6-w@uter.be> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240812133032.115134-1-w@uter.be> References: <20240812133032.115134-1-w@uter.be> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Also handle NBD_FLAG_ROTATIONAL in our debug helper function Signed-off-by: Wouter Verhelst Cc: Eric Blake --- drivers/block/nbd.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c index b2b69cc5ca23..fdcf0bbedf3b 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -1714,6 +1714,8 @@ static int nbd_dbg_flags_show(struct seq_file *s, void *unused) seq_puts(s, "NBD_FLAG_SEND_TRIM\n"); if (flags & NBD_FLAG_SEND_WRITE_ZEROES) seq_puts(s, "NBD_FLAG_SEND_WRITE_ZEROES\n"); + if (flags & NBD_FLAG_ROTATIONAL) + seq_puts(s, "NBD_FLAG_ROTATIONAL\n"); return 0; } From patchwork Mon Aug 12 13:20:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wouter Verhelst X-Patchwork-Id: 13760679 Received: from lounge.grep.be (lounge.grep.be [144.76.219.42]) (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 8673B174EEB; Mon, 12 Aug 2024 14:21:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=144.76.219.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723472500; cv=none; b=GpNSuIkCn/28R27p4bZfcTJ2k7qVjJNouRE4J0Xy/6/oF8nWPGJ/c4DHXi9oHRuwoAI/fCDIe3NQlECXFBJ2Gy7mLLl0VSeEYrGoG7suqtJZyv4Tjfm6gYSYP6OP0CiH1No1OLhzDO79ubrtv9ZJvg84t/LBxSGYg9WDAhNiX5g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723472500; c=relaxed/simple; bh=JeY1TPFy1DrkJKqz6R7Y3R7apZx4kYrch19xGM9uAVg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fgzAHV7OgI8pmsSrgNpJnys6+7nljDLpcj9F9PGbvubDTB8qr0xntlxbrug1dOYN08N0JRWSU17xRgYpSMiRxBRQhMlJbPIFZeTRbGrN1TUHjeRLK/lIbTJHDbcvKk5rryA801ksyINFvGVtnCzjjvflUb1JyIM0vGGMNYl8cIM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=uter.be; spf=pass smtp.mailfrom=grep.be; dkim=fail (0-bit key) header.d=grep.be header.i=@grep.be header.b=ozuxj6QP reason="key not found in DNS"; arc=none smtp.client-ip=144.76.219.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=uter.be Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=grep.be Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="key not found in DNS" (0-bit key) header.d=grep.be header.i=@grep.be header.b="ozuxj6QP" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=grep.be; s=2017.latin; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To :Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=UfNjOcnK0rNibgV49Da6IoKbw+3WWkpzfO/rH4LGQ2U=; b=ozuxj6QP1tspTE3TBAu18U913q AIntpY3wB0RxJJ6TK2UHI8gWC+TiWayDwqRmi6o9x0e7ZLtRIRM6EckASCCezzKJt1usuB7H9Hpml x3gAkojbdIE6xK28Z7Dyn5kfdqkFIl2AFjnZStooQjDW2HIi5V80ShWXqDknbKxTbHL9s572i4pRU UbvNdlX3b129LyaaBRtGurYTUcf1LtJ53oriiM1NoPrjyJ76HEVRZc+lXKu3VXCNoSOnNUhwRAx68 f1LnqJiNXDPkJPrhrO+dQeEn9T+3qu4q/mjHp3RYufcEs0Mwuz0WK2DdsSoizVfjowgKiA/QrUUhQ zpTe/vkA==; Received: from [196.210.96.185] (helo=pc220518) by lounge.grep.be with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1sdVvS-009n08-13; Mon, 12 Aug 2024 16:21:34 +0200 Received: from wouter by pc220518 with local (Exim 4.98) (envelope-from ) id 1sdVBo-00000000VH7-1PHN; Mon, 12 Aug 2024 15:34:24 +0200 From: Wouter Verhelst To: Josef Bacik , Jens Axboe Cc: Wouter Verhelst , Eric Blake , Damien Le Moal , linux-block@vger.kernel.org, nbd@other.debian.org, linux-kernel@vger.kernel.org, Eric Blake Subject: [PATCH v4 3/3] nbd: correct the maximum value for discard sectors Date: Mon, 12 Aug 2024 15:20:42 +0200 Message-ID: <20240812133032.115134-8-w@uter.be> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240812133032.115134-1-w@uter.be> References: <20240812133032.115134-1-w@uter.be> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The version of the NBD protocol implemented by the kernel driver currently has a 32 bit field for length values. As the NBD protocol uses bytes as a unit of length, length values larger than 2^32 bytes cannot be expressed. Update the max_hw_discard_sectors field to match that. Signed-off-by: Wouter Verhelst Fixes: 268283244c0f ("nbd: use the atomic queue limits API in nbd_set_size") Reviewed-by: Damien Le Moal Cc: Eric Blake --- drivers/block/nbd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c index fdcf0bbedf3b..235ab5f59608 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -339,7 +339,7 @@ static int __nbd_set_size(struct nbd_device *nbd, loff_t bytesize, lim = queue_limits_start_update(nbd->disk->queue); if (nbd->config->flags & NBD_FLAG_SEND_TRIM) - lim.max_hw_discard_sectors = UINT_MAX; + lim.max_hw_discard_sectors = UINT_MAX >> SECTOR_SHIFT; else lim.max_hw_discard_sectors = 0; if (!(nbd->config->flags & NBD_FLAG_SEND_FLUSH)) {