From patchwork Tue Aug 6 13:30:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wouter Verhelst X-Patchwork-Id: 13754885 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 717B51D1F70; Tue, 6 Aug 2024 13:31:18 +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=1722951081; cv=none; b=DrvP4MCd2okCvy4mKyQjfzjlMqnzKGWmXY0X/aFY9xh5VOfqjRgrH9gtXXWt8GTdTYcfYYwHFK3WTgkEtU0+gAYs05T+vAXhI75EmmfD+5N0HwNzKk3m0tV6kGeqYVOnc4ZHdUtB/gQrOm14Rdy0CnNBGLi0mmQSm48QTsQPdWw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722951081; c=relaxed/simple; bh=zWSCz73at9uv5gGCQxikHF05yR+6+jFaqGCgvUE8fvs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=L+2az8Cwtb3wY3kFefc3CqnIPkFskMuVZHUitRN6nesDazS5WLewZ8eSAKK5m4YvERo7WHV9zB0HgG9rLB76+NJwE8c8ZD5gnSawn+b+fr89A3PQu/M51v3AP8OTQNlpidwzjCGEAEnS2rlagtNjI10AnUfh6eISeNx8/9B2WJk= 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=Qio/YNTK 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="Qio/YNTK" 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=4ezqpc2sp8gD3/2IUsk5Z3eEd9Ks2MQHDdk337O8ScE=; b=Qio/YNTKl3rtT6yh1SL1SIEv5x 412DlnJ8MEiGHSnVs88ygGJknbhqqTfC6IUSlM95ZwfdvV0S8DA79Qtq3ARBlF4A2PzmWrm+dPZ7s thGp0Q4mYuRVeUTpgKdGyA3c65KT/1B3BZ4vYeep+rEWVZZRCPVK4ayAsnRNY689vGp+s+BhtVoE3 mhQg5kpZOZo9HC2ovqtmoSLJZECk+CDP0jP9lCUmpDvOpyp3URMSl8KhBuCwtj/+rKXTIGaHpBvwR OsbAU+B5uYKeO3bV0wKDiDBuizd5SKf4YsblY5aKHPHqQePoioK9LLy0FUzb9jhsQY453ZzHm+Un0 WL0L5/Eg==; Received: from [196.251.239.242] (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 1sbKHT-00HZHT-2F; Tue, 06 Aug 2024 15:31:15 +0200 Received: from wouter by pc220518 with local (Exim 4.98) (envelope-from ) id 1sbKHP-000000017kU-2DJf; Tue, 06 Aug 2024 15:31:11 +0200 From: Wouter Verhelst To: Josef Bacik , Jens Axboe Cc: Wouter Verhelst , linux-block@vger.kernel.org, nbd@other.debian.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/3] nbd: implement the WRITE_ZEROES command Date: Tue, 6 Aug 2024 15:30:54 +0200 Message-ID: <20240806133058.268058-1-w@uter.be> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240803130432.5952-1-w@uter.be> References: <20240803130432.5952-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 --- 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..58221b89965d 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 / blksize; 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 Tue Aug 6 13:30:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wouter Verhelst X-Patchwork-Id: 13754884 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 7174F1D1F47; Tue, 6 Aug 2024 13:31:18 +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=1722951081; cv=none; b=d2FPXbOGGTyXO47UPu2KKUco2LgVhZixMaImgs4pAqdZDEOftLwp+JZTuD+TkmjqHu17S8dSYFMuAw05+Ew72UQ/CnWlYha4Agx9xWhXUk9yHt+ug5blujxpv5crUwwsHlnQPhGuIP2FXZ783oJiOHsUx1wfNWQnTOsVYjsyPyU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722951081; c=relaxed/simple; bh=41vzVAVmQoE/b4vTs5dty2x2d2LfL9KAQdxFyLdt8qI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YDNfPOwXDtvJ6aVIsbS/glgZAEejdk+x41TZDJRS6Y9hqBMZ2IWJVPafOn3vddiGrY4uVAXeBVWVmzhZWyVLdbwFaSB0SbZhR6GLBDvxsoQ7kG/IPqU/CR1P0fxSDfH6lZOcPTikk4PeUFE03R6qi+qENvqtsr+NyL1K7Huw/nw= 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=hSFpjyeS 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="hSFpjyeS" 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=3rHWsnZQI00onpRkU1ccFvqkYqofNkevl1X51tyBwPQ=; b=hSFpjyeSfnk+ZH3lxfFkFu0for 3sF52lRNjW3fliXat9Ook9xhpayt5iRp3kH0v8nyHRtN2n8syn0C0IAGoYQ8fVLDBNgc/bdYonbYH 0WEBsouGDYGuFVYPgsvCez/BMhZA6q5Kl5+ZCzagK1Z5I4aP/3VMyV/ySy2n1zkX4qsELnjRoTL/x K9SJpB40bQW8j9ltKHamgvwjg+WXii965qkaaMWEX7MIPkha9RZxUL1kweq4zHLCvbQdzp3Mwh5uY Ff1Pl75NnjScsG09NKvAdR0Z0njWLN7HAykDOZ1IftByYD9gFCXkNT9yTdK4qxL00y6xj2++xK7/h f21thkQA==; Received: from [196.251.239.242] (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 1sbKHT-00HZHU-39; Tue, 06 Aug 2024 15:31:15 +0200 Received: from wouter by pc220518 with local (Exim 4.98) (envelope-from ) id 1sbKHP-000000017kg-3K8h; Tue, 06 Aug 2024 15:31:11 +0200 From: Wouter Verhelst To: Josef Bacik , Jens Axboe Cc: Wouter Verhelst , linux-block@vger.kernel.org, nbd@other.debian.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/3] nbd: nbd_bg_flags_show: add NBD_FLAG_ROTATIONAL Date: Tue, 6 Aug 2024 15:30:55 +0200 Message-ID: <20240806133058.268058-2-w@uter.be> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240806133058.268058-1-w@uter.be> References: <20240803130432.5952-1-w@uter.be> <20240806133058.268058-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 --- drivers/block/nbd.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c index 58221b89965d..20e9f9fdeaae 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 Tue Aug 6 13:30:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wouter Verhelst X-Patchwork-Id: 13754886 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 718061D1F73; Tue, 6 Aug 2024 13:31:18 +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=1722951082; cv=none; b=cNwp1nn8pyor0RT3UKoohv+t6yadKAORLqxiB/kDs3NFnRXhfNn1frkIJZhks0cPUtuHjbF3+Z2M4FVRoQBSm0eSZLmA7Yw8/eYbbGg8esigby6wXoShftPeHCGEMbqVZArG43XvfjA/PcoZRxSGTyQeX8FVZy8QaBEZx/aGnOI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722951082; c=relaxed/simple; bh=TD20eceQmDWe+GB0izd/3j2w6czmpj6fF7AlDhyNu/c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rmdntl+EtFhcY+6WR1weT+3We1H2bv1yO+zTebh+JmIb0aYBqojcq3CUCkJ37WAGu453MsAwFZcVWCz7hFXQi4UirL2REje0mGNh6AJOqBviEUwvO0sVgF1jWbsfdhzLbm1t+0l6mvClcJBrGJiIHwC/df1bktPTeek0filWZ78= 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=d9IxhPod 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="d9IxhPod" 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=Xcgcw/iQnRD6/Ii1rjeE6TECmbYw3NwUK+7/q09vO38=; b=d9IxhPodRH3LMsYIATXCjfU3CT DT8SPwh3xivwMv+k4bKHDIGVXBtpV+wSS/tJ1wvGBRhJjBXr3hOOHhVFKq8t5khsSaJsq1p3JUuch YLp8DLvA/k9fzq0rdRnQ2DrqSutWhF3aVPWl1fAzQ2OjOoBZYoZZT5kLg/6FOrYQq1ev9kerk4HeL WJ/6zP5yKx50qIvJcR9EkhoZs4ZXdUInxK0XZ55Z2auXdwfMfIOegOROEH6B7qc5jSXozIgWyDqs2 d3t8gu21vq65+muvZziOTJd2toUC7MEzbNK62WFi0xHTA6uXDaxTCxF/X3PVr3rkjJKEsKbWFONPb HvsUYWhA==; Received: from [196.251.239.242] (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 1sbKHT-00HZHV-2C; Tue, 06 Aug 2024 15:31:15 +0200 Received: from wouter by pc220518 with local (Exim 4.98) (envelope-from ) id 1sbKHQ-000000017kw-0HfU; Tue, 06 Aug 2024 15:31:12 +0200 From: Wouter Verhelst To: Josef Bacik , Jens Axboe Cc: Wouter Verhelst , linux-block@vger.kernel.org, nbd@other.debian.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/3] nbd: correct the maximum value for discard sectors Date: Tue, 6 Aug 2024 15:30:56 +0200 Message-ID: <20240806133058.268058-3-w@uter.be> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240806133058.268058-1-w@uter.be> References: <20240803130432.5952-1-w@uter.be> <20240806133058.268058-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: 268283244c0f018dec8bf4a9c69ce50684561f46 --- 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 20e9f9fdeaae..1457f0c8a4a4 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 / blksize; else lim.max_hw_discard_sectors = 0; if (!(nbd->config->flags & NBD_FLAG_SEND_FLUSH)) {