From patchwork Thu Feb 29 14:38:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13577212 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 38FBE137757 for ; Thu, 29 Feb 2024 14:39:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709217552; cv=none; b=Flu260eSFybJ6nyK4/7tEKxBIzLeeAmpZzjjCunzvlSGKckPWnMValcB4/CjCLoTZgJLb3STOk/udMzt3XLPhgl5azk8Vzw9zlRn53OTNysOzLJK7zcXOU7GOLN3RGc5IRAF9hJtRflMnOei2mee2nWz085S0IQPr1LovgsPlCU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709217552; c=relaxed/simple; bh=wrUO6NjJ5EO0fL9Kr6s3bBM49H1kgVhnwqvJSzc9s2Y=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=TSg1M7QjuKO9r4Eo1Ov+DM0yOjc+6iMJM31cSbLDLyipe2gqESUU8Mbb9pGNZbH0Acg20BTnLH8xfVOEkMJh/FX1ZPfejwqFt1xH+s4QtZf+iR4n0VFQ1NPaYm0Til3UMOUiPgZmHG6Fa8kYTxlYK+jb8qQ46r7QSxA576kBIpk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=xr5lFHR7; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="xr5lFHR7" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; 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; bh=3d3wiWZ4gh1IydUuJ2k1At36hB0TiDUfLbBdK9F+NZ0=; b=xr5lFHR7tOU5dhc+DH1jc7FFGW iS0cp+D2T6m7l980piwU3CBetRvNnlpAc01/GGPRf7/eni+OLG4Rp2ydjY7kVa8nPaFHC5gamdR6Z YpJ8kYboKda0jJgPnnXrtJEfLcz/l7SYKAHQ2AdoTzih/OcwAv5mKTrMn2epFW1F1ne3iO83zE4Me 3LO/jk1m4l5GoP/TYRkdGFohbiSl6Co+gbdm2jwX6BPfy1IyT6RnsuqrBXg/DDC2nN2VaoRNn6JJn gI37V0F1JolwUzIaH685+ZPMutCaq824EsWJsIkbcWkBOYOoTSoTOtzeEzw0vHABM0W2TTgRMCytK 0yGBrGBA==; Received: from [216.9.110.7] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rfhYy-0000000Dtkt-2EQU; Thu, 29 Feb 2024 14:39:08 +0000 From: Christoph Hellwig To: Josef Bacik , Jens Axboe Cc: linux-block@vger.kernel.org, nbd@other.debian.org Subject: [PATCH 1/3] nbd: don't clear discard_sectors in nbd_config_put Date: Thu, 29 Feb 2024 06:38:44 -0800 Message-Id: <20240229143846.1047223-2-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240229143846.1047223-1-hch@lst.de> References: <20240229143846.1047223-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html nbd_config_put currently clears discard_sectors when unusing a device. This is pretty odd behavior and different from the sector size configuration which is simply left in places and then reconfigured when nbd_set_size is as part of configuring the device. Change nbd_set_size to clear discard_sectors if discard is not supported so that all the queue limits changes are handled in one place. Signed-off-by: Christoph Hellwig --- drivers/block/nbd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c index 9ee9587375fac3..384750d5259fb8 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -336,6 +336,8 @@ static int nbd_set_size(struct nbd_device *nbd, loff_t bytesize, if (nbd->config->flags & NBD_FLAG_SEND_TRIM) blk_queue_max_discard_sectors(nbd->disk->queue, UINT_MAX); + else + blk_queue_max_discard_sectors(nbd->disk->queue, 0); blk_queue_logical_block_size(nbd->disk->queue, blksize); blk_queue_physical_block_size(nbd->disk->queue, blksize); @@ -1351,7 +1353,6 @@ static void nbd_config_put(struct nbd_device *nbd) nbd->config = NULL; nbd->tag_set.timeout = 0; - blk_queue_max_discard_sectors(nbd->disk->queue, 0); mutex_unlock(&nbd->config_lock); nbd_put(nbd); From patchwork Thu Feb 29 14:38:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13577211 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 19BCA12F58C for ; Thu, 29 Feb 2024 14:39:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709217551; cv=none; b=LX1FSCN9SN69NQi4QYStUIqeBcqtqSSqRHo+St2IWZ9VWQ7ttpL60wfXBgfe8FNL6aH6C/9KeDqzn2jh6ZEVEVdDTRT8FMppwy1lXlJZoUaIDmfZWMNHuIyQaDcOIU25ibms8IZ/8Q/2Q6rcuAPdbjvqSj7rKkGhGZqYfXjsXoE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709217551; c=relaxed/simple; bh=I9L4J92cSF5Fll/q8oAuU+969JtLRTHzwO050h4DyBM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=AftvCkEsxCDOVPGXgQZ7LqXx2Em0uMmdncnPVgnfwKgA7zWvadNMAn0hcWOuWX/hz3UTLJDhBfP65WUFrWZc/Tobhs7xpjjg85ka+AlZPjc0/vZWcVGtb8FDpFG75ApIWqPtjExPJDFlL2Djznsv439+0NzWwXPFdLO9/BnZaTY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=obrk09l8; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="obrk09l8" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; 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; bh=QJzXdMVMj/zE5xp/XtEAbR9lvP5zyixzjCOJuZCm9tw=; b=obrk09l8xvSV6j+flbBYIB7XlT i4xB9MHcbN8j4lLUXt1LR/34QC3KaQJsLTrLTI1DivYjtouc+mKFNNh5qXvmCGt/d+nnXRNs8wJCr 9R+V0D8RluGAbT5JY0vgA8LgTnJ62orH4N+xjqbYWXiiMyQtuUar47pS7QTD4vg3DaWMMlQbBHarO 4b8lzctbvqz8LVUFeBVpFgAYvFp2e61Q9Wk8tUkJ3BUrz/hXCoadNsgqlI7xp/M2cKezGaw9poJ33 fqka59rEGKAZuyC298Elw64k2zBzM+wbBPa+QN9aOBM1bj0uGrlZoV8mAgK1cMkpFZivY59anmwFT 1LlORHPw==; Received: from [216.9.110.7] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rfhYz-0000000Dtl9-1IUO; Thu, 29 Feb 2024 14:39:09 +0000 From: Christoph Hellwig To: Josef Bacik , Jens Axboe Cc: linux-block@vger.kernel.org, nbd@other.debian.org Subject: [PATCH 2/3] nbd: freeze the queue for queue limits updates Date: Thu, 29 Feb 2024 06:38:45 -0800 Message-Id: <20240229143846.1047223-3-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240229143846.1047223-1-hch@lst.de> References: <20240229143846.1047223-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html nbd currently updates the logical and physical block sizes as well as the discard_sectors on a live queue. Freeze the queue first to make sure there are not commands in flight that can see torn or inconsistent limits. Signed-off-by: Christoph Hellwig --- drivers/block/nbd.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c index 384750d5259fb8..22ee0ed9aa6db0 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -316,7 +316,7 @@ static void nbd_mark_nsock_dead(struct nbd_device *nbd, struct nbd_sock *nsock, nsock->sent = 0; } -static int nbd_set_size(struct nbd_device *nbd, loff_t bytesize, +static int __nbd_set_size(struct nbd_device *nbd, loff_t bytesize, loff_t blksize) { if (!blksize) @@ -348,6 +348,18 @@ static int nbd_set_size(struct nbd_device *nbd, loff_t bytesize, return 0; } +static int nbd_set_size(struct nbd_device *nbd, loff_t bytesize, + loff_t blksize) +{ + int error; + + blk_mq_freeze_queue(nbd->disk->queue); + error = __nbd_set_size(nbd, bytesize, blksize); + blk_mq_unfreeze_queue(nbd->disk->queue); + + return error; +} + static void nbd_complete_rq(struct request *req) { struct nbd_cmd *cmd = blk_mq_rq_to_pdu(req); From patchwork Thu Feb 29 14:38:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13577213 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 D4679137777 for ; Thu, 29 Feb 2024 14:39:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709217552; cv=none; b=uupi/2BHTb+JkD0okLBnT9GYaUn2Vvwax2qrKo/9QxCAYxvkWQWEc2Cm9zVfYLARzLw6YNt7nHOoirrJRV5ePQ/HKLjegWvQ6U9XQ8hx5Dq3VZgkaWDakreDjHKb7jZpVOld22Miffua/a9NEX5EkJjgZhl/KjynIpjLckH1oCI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709217552; c=relaxed/simple; bh=DkT0j0H2VmgzgLbTRvsMmGG+ouZTICRX2K7NfTnL5dY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=XYWnPcjWTzE+sKjueU0tPQmHU2/7RY8Hwil/WmElGqoiYImQGFi/bO3W2GZmQB7eUixa5sGi2zqGUf6CCVwNqtEKjRcP2Do8YSp77uO1byEtVwO1PxzLaXebVz5CCF+X6fPOaoWDQXEt6ZTs/jxsJXYuK7XcYl6OeMlcKZeS5iM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=Hz0RKqmH; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="Hz0RKqmH" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; 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; bh=eB65jZCI4DOhsIeR75tX3uMn80Bbo9GI/LSxj/PB/hc=; b=Hz0RKqmHaQcPC1bWJZrMZ0IH9L jGz9W3302SATyFWmY9zDUymlrGRx2pjU+veA0ikAa4OeFRb3pw91WrEzaTr/XdXXApYOifmRcIxqH iadVD2ZiKk2xOvzLSj+JTTG/O/osBkPKWRCNRj5MK4ehWoYeFfbqj1AcvkPM3K5jhq5nQJ222kr5r BbQPpLuLD4/9wNBS4O4J41+wRkkLBrIV3YAoT12dwRnORB54LUJH/V7yP2cuN9XX8B0YG07MqFuA7 kiC+UajH28x91CDk7+/Qrl2kczCBpQETGyapGOmFx8CKEXSV46tZSuEK7+sYTqeiU3cRWJOeC0d/z 7Q985ZUQ==; Received: from [216.9.110.7] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rfhZ0-0000000DtlP-1JXi; Thu, 29 Feb 2024 14:39:10 +0000 From: Christoph Hellwig To: Josef Bacik , Jens Axboe Cc: linux-block@vger.kernel.org, nbd@other.debian.org Subject: [PATCH 3/3] nbd: use the atomic queue limits API in nbd_set_size Date: Thu, 29 Feb 2024 06:38:46 -0800 Message-Id: <20240229143846.1047223-4-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240229143846.1047223-1-hch@lst.de> References: <20240229143846.1047223-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Use queue_limits_start_update / queue_limits_commit_update to update all the limits in one go and with proper sanity checking. Signed-off-by: Christoph Hellwig --- drivers/block/nbd.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c index 22ee0ed9aa6db0..9d4ec9273bf954 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -319,6 +319,9 @@ static void nbd_mark_nsock_dead(struct nbd_device *nbd, struct nbd_sock *nsock, static int __nbd_set_size(struct nbd_device *nbd, loff_t bytesize, loff_t blksize) { + struct queue_limits lim; + int error; + if (!blksize) blksize = 1u << NBD_DEF_BLKSIZE_BITS; @@ -334,12 +337,16 @@ static int __nbd_set_size(struct nbd_device *nbd, loff_t bytesize, if (!nbd->pid) return 0; + lim = queue_limits_start_update(nbd->disk->queue); if (nbd->config->flags & NBD_FLAG_SEND_TRIM) - blk_queue_max_discard_sectors(nbd->disk->queue, UINT_MAX); + lim.max_hw_discard_sectors = UINT_MAX; else - blk_queue_max_discard_sectors(nbd->disk->queue, 0); - blk_queue_logical_block_size(nbd->disk->queue, blksize); - blk_queue_physical_block_size(nbd->disk->queue, blksize); + lim.max_hw_discard_sectors = 0; + lim.logical_block_size = blksize; + lim.physical_block_size = blksize; + error = queue_limits_commit_update(nbd->disk->queue, &lim); + if (error) + return error; if (max_part) set_bit(GD_NEED_PART_SCAN, &nbd->disk->state);