From patchwork Fri Jan 10 07:37:31 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13933886 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 126252066F2 for ; Fri, 10 Jan 2025 07:37:58 +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=1736494680; cv=none; b=nJS1Xg9IUMHTa87CC8mW4dr0rRPpBuZ2oc3X7+QPsF85iLWpOEEXORfAdBdbDviwKueisGDGRlL9F8/On7dT6DAYWFDjczSxqPMwEptUMmWU7+JJDOv9KI4eNgmbgq/VD+XiI1+wxymFK9oGlLzmHm9JQ8Ng49j5qTYW+jeKxZ4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736494680; c=relaxed/simple; bh=48cEQwW1/AGHm12XJMHZEt6cXBbpFq/S1T2KgiTEjgs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Je+ckbKw7dl+AgvZWgsMh7rnYrIRQf/M1Iu3Lts5xMQG1OEnuiJfEHUjDn6uAiyGrCpZAZfmYolQkWgaZgovptAzGmPDI/UBuzaS0NCsJZPtOhMl2I1z0ip5WDp3hFlsjajffMGGQ3zG93xh5hzvFFF4NsKoB3oU9V/g7lCDX4k= 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=wEktJjJX; 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="wEktJjJX" 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=QVSgywGjeyHzIkGH0Hz4WNzrp+6FU5u/jaR6AJJSjVU=; b=wEktJjJXwLp7mAPr3GXKZKTQ52 OPkYSDpR9Q3pfg22FUdnC6nCoEY/rhn7w1+qnEPbHeihHbsyYqfQ2ptrhg0d9kCz0lcWTThfzhK3b iw76nTHxaFUk0SOyrN4u+4NqQvPeFAblQwqoikq+L7kSc9e+YMOQE4FTH4DEfN1b3QBYEEr5VnRmP /GU9sZ+v6FHRO+eTeOD3SFOOcrR/i0sc4gHhf6QQ2asK6nXDL4x/OxLNLrCBDANaiUj7kFrXPKWA1 wNjARvHk8KCiYh4tOZvbF6OQ3ied+KjC1mcO/+i7EjRFElL7AlpfJ7YFfLGFBdtgtGpkdHp4dVAg6 oxMoWxOA==; Received: from 2a02-8389-2341-5b80-76c3-a3dc-14f6-94e8.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:76c3:a3dc:14f6:94e8] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1tW9ag-0000000EOPh-0noN; Fri, 10 Jan 2025 07:37:58 +0000 From: Christoph Hellwig To: Jens Axboe Cc: linux-block@vger.kernel.org Subject: [PATCH 1/8] loop: move updating lo_flags out of loop_set_status_from_info Date: Fri, 10 Jan 2025 08:37:31 +0100 Message-ID: <20250110073750.1582447-2-hch@lst.de> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250110073750.1582447-1-hch@lst.de> References: <20250110073750.1582447-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 While loop_configure simplify assigns the flags passed in by userspace, loop_set_status only looks at the two changeable flags, and currently has to do a complicate dance to implement that. Move assign lo->lo_flags out of loop_set_status_from_info into the callers and thus drastically simplify the lo_flags handling in loop_set_status. Signed-off-by: Christoph Hellwig --- drivers/block/loop.c | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/drivers/block/loop.c b/drivers/block/loop.c index 15e486baa223..6ea729cdce71 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -971,7 +971,6 @@ loop_set_status_from_info(struct loop_device *lo, memcpy(lo->lo_file_name, info->lo_file_name, LO_NAME_SIZE); lo->lo_file_name[LO_NAME_SIZE-1] = 0; - lo->lo_flags = info->lo_flags; return 0; } @@ -1069,6 +1068,7 @@ static int loop_configure(struct loop_device *lo, blk_mode_t mode, error = loop_set_status_from_info(lo, &config->info); if (error) goto out_unlock; + lo->lo_flags = config->info.lo_flags; if (!(file->f_mode & FMODE_WRITE) || !(mode & BLK_OPEN_WRITE) || !file->f_op->write_iter) @@ -1258,7 +1258,6 @@ static int loop_set_status(struct loop_device *lo, const struct loop_info64 *info) { int err; - int prev_lo_flags; bool partscan = false; bool size_changed = false; @@ -1280,18 +1279,16 @@ loop_set_status(struct loop_device *lo, const struct loop_info64 *info) /* I/O need to be drained during transfer transition */ blk_mq_freeze_queue(lo->lo_queue); - prev_lo_flags = lo->lo_flags; - err = loop_set_status_from_info(lo, info); if (err) goto out_unfreeze; - /* Mask out flags that can't be set using LOOP_SET_STATUS. */ - lo->lo_flags &= LOOP_SET_STATUS_SETTABLE_FLAGS; - /* For those flags, use the previous values instead */ - lo->lo_flags |= prev_lo_flags & ~LOOP_SET_STATUS_SETTABLE_FLAGS; - /* For flags that can't be cleared, use previous values too */ - lo->lo_flags |= prev_lo_flags & ~LOOP_SET_STATUS_CLEARABLE_FLAGS; + partscan = !(lo->lo_flags & LO_FLAGS_PARTSCAN) && + (info->lo_flags & LO_FLAGS_PARTSCAN); + + lo->lo_flags &= ~(LOOP_SET_STATUS_SETTABLE_FLAGS | + LOOP_SET_STATUS_CLEARABLE_FLAGS); + lo->lo_flags |= (info->lo_flags & LOOP_SET_STATUS_SETTABLE_FLAGS); if (size_changed) { loff_t new_size = get_size(lo->lo_offset, lo->lo_sizelimit, @@ -1304,12 +1301,8 @@ loop_set_status(struct loop_device *lo, const struct loop_info64 *info) out_unfreeze: blk_mq_unfreeze_queue(lo->lo_queue); - - if (!err && (lo->lo_flags & LO_FLAGS_PARTSCAN) && - !(prev_lo_flags & LO_FLAGS_PARTSCAN)) { + if (partscan) clear_bit(GD_SUPPRESS_PART_SCAN, &lo->lo_disk->state); - partscan = true; - } out_unlock: mutex_unlock(&lo->lo_mutex); if (partscan) From patchwork Fri Jan 10 07:37:32 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13933887 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 5914B207A1D for ; Fri, 10 Jan 2025 07:38:02 +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=1736494684; cv=none; b=lqTs2IqW9vR2Bf/R7L8CAqlLuJPGvdWrombwGS9LhGGEd3/irsAhZ2dnID7HqBMLzQzfK4iECwS+gTjB/NwOh1X6j64+ewH2xAVrUjBBeeTEihTJIJICXrAMQebh7kgZDkZIoQoYRa/+Hul/3ApafQLdnRkPOW8bqQxDhHFCG7A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736494684; c=relaxed/simple; bh=7ddtTOLcuxhXKPG8q+8NNYdNCMSZoIs1KP+qDEHYynA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=phLa+Sp5sii+kGPpNDUYouOjUHIyH1SpcluOefO4gkauNKkbyzsxPe+o1au7RsJA9vmq09qZWfxRyTShpszgUZjNxTLGS23IW/qq0fUJdtSWEh24yc/bPr4KwNFYnZsGBWkxzenQWL1gGE6ruX9UwgYVN8aA4NHlUG3DYF3I45s= 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=E6RDTSv+; 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="E6RDTSv+" 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=HJ48E+HRyUvOykPui4TJ51s5rpa3tBNMVaIdNRccCps=; b=E6RDTSv+jtMdXrzrJTQDdKhaoa MMs1K92lP5ZKeWayEPqKsKjdVrsocs2PxcRXSMye1FwUZAxQh4U2UZUSltvD/+RmKriNgbAYAkiV0 jTcxuqLqGnG8385x6F+4rNCc2EPDhsrK21pob4g7asOL33NMj0q8HxPvxLB+wJ+PMm4TnRfOcoBU7 s7/htOV5dP15naKB0DTzcVm6bFoLV6XJ7t2SuGsbjIwNT/LFqGbhI5iLgszzvYq6mX4FFTtu8Unuy h0wJ/7t8VW2lDjrvChN6kwHuCDskAdyrK2pSbZOc5rwHfA2D1pbEKXw2sIy63a3JL+ijy1hjWqPcw +UbTtB8g==; Received: from 2a02-8389-2341-5b80-76c3-a3dc-14f6-94e8.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:76c3:a3dc:14f6:94e8] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1tW9aj-0000000EOQH-2Rzq; Fri, 10 Jan 2025 07:38:02 +0000 From: Christoph Hellwig To: Jens Axboe Cc: linux-block@vger.kernel.org Subject: [PATCH 2/8] loop: update commands in loop_set_status still referring to transfers Date: Fri, 10 Jan 2025 08:37:32 +0100 Message-ID: <20250110073750.1582447-3-hch@lst.de> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250110073750.1582447-1-hch@lst.de> References: <20250110073750.1582447-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 The concept of transfers is gone since commit 47e9624616c8 ("block: remove support for cryptoloop and the xor transfer"). Signed-off-by: Christoph Hellwig --- drivers/block/loop.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/block/loop.c b/drivers/block/loop.c index 6ea729cdce71..0c7dfc6eee12 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -1276,7 +1276,7 @@ loop_set_status(struct loop_device *lo, const struct loop_info64 *info) invalidate_bdev(lo->lo_device); } - /* I/O need to be drained during transfer transition */ + /* I/O needs to be drained before changing lo_offset or lo_sizelimit */ blk_mq_freeze_queue(lo->lo_queue); err = loop_set_status_from_info(lo, info); @@ -1296,7 +1296,7 @@ loop_set_status(struct loop_device *lo, const struct loop_info64 *info) loop_set_size(lo, new_size); } - /* update dio if lo_offset or transfer is changed */ + /* update the direct I/O flag if lo_offset changed */ __loop_update_dio(lo, lo->use_dio); out_unfreeze: From patchwork Fri Jan 10 07:37:33 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13933888 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 507F4207E04 for ; Fri, 10 Jan 2025 07:38:05 +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=1736494686; cv=none; b=ub7DPsPVRJ8JHvRZRBD1hek19DdVcq+ZhLNu6Mhd+cohR2pJkWXn7zMVGSBUpqrXIVTYy0ySauRDqNUooyd4hRfXmahEKja1tGKdfG7HAL4CSBdmow3K1eE8j6Vl0ZoYOUsEO0R+hLxUkxe4Uk0kmB5m2yMREnS3OauJ0X34AUM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736494686; c=relaxed/simple; bh=fwUiEUotSYYxZVBcBMctwTNQgs88VkGKfNj3lTd6jk8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RFkQv2PgjPQe5AlRbWOM2uA2+fzPRGVj3tT8CdtPdMlaSonqLNnebC+MLJ1aJOe/FkRxZw0N4woOw29kTqMtidm0zyYXVI4iCEu0DNQSCNAnAoo/r4kXCLRFIBMgsoNsKxOIrT4NSfyeCwHtUshQx550ENvMXaNvOyfY3zC7Jq0= 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=IhUWewzQ; 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="IhUWewzQ" 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=fBFw0G03it4OiNiy6X+kXPRWCZfiX1LeXRK/O8w7x3w=; b=IhUWewzQ20Ang1bE7vHz2yaKP4 6XNYswC5TrL/J68qL/y54uWvMpmS2rO5EBrZLEOMaCq+UK6ZkXqAxf6HtL+RU+wq8Wv08yfq8u2jW kKt4SsAIzBJXyoUZDcQMqSwF9DORBv5973sedcfKuPhS5YhOoDyPW4Kri3wJlrdHVzgMPrAVI6V8G N9o6whccmxsUIa+Uqps92gQigKDmmtRVL6uYIQgyVEVqEObwxB/+xC5/JHtwsNHfoq24yEgVFr1a4 VohiJGt/xyMTqTXfGsHy08+f3/QCNrojWhAkQ8l5Y1yJcxKWrfBcFHVEcWg4Nhlq3aLOChbniTaRm Laow9Bag==; Received: from 2a02-8389-2341-5b80-76c3-a3dc-14f6-94e8.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:76c3:a3dc:14f6:94e8] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1tW9am-0000000EOR4-2GSz; Fri, 10 Jan 2025 07:38:05 +0000 From: Christoph Hellwig To: Jens Axboe Cc: linux-block@vger.kernel.org Subject: [PATCH 3/8] loop: create a lo_can_use_dio helper Date: Fri, 10 Jan 2025 08:37:33 +0100 Message-ID: <20250110073750.1582447-4-hch@lst.de> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250110073750.1582447-1-hch@lst.de> References: <20250110073750.1582447-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 Factor out a part of __loop_update_dio in preparation for further refactoring. Signed-off-by: Christoph Hellwig --- drivers/block/loop.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/drivers/block/loop.c b/drivers/block/loop.c index 0c7dfc6eee12..55bea9c95b45 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -182,26 +182,29 @@ static bool lo_bdev_can_use_dio(struct loop_device *lo, return true; } -static void __loop_update_dio(struct loop_device *lo, bool dio) +static bool lo_can_use_dio(struct loop_device *lo) { - struct file *file = lo->lo_backing_file; - struct inode *inode = file->f_mapping->host; - struct block_device *backing_bdev = NULL; - bool use_dio; + struct inode *inode = lo->lo_backing_file->f_mapping->host; + + if (!(lo->lo_backing_file->f_mode & FMODE_CAN_ODIRECT)) + return false; if (S_ISBLK(inode->i_mode)) - backing_bdev = I_BDEV(inode); - else if (inode->i_sb->s_bdev) - backing_bdev = inode->i_sb->s_bdev; + return lo_bdev_can_use_dio(lo, I_BDEV(inode)); + if (inode->i_sb->s_bdev) + return lo_bdev_can_use_dio(lo, inode->i_sb->s_bdev); + return true; +} - use_dio = dio && (file->f_mode & FMODE_CAN_ODIRECT) && - (!backing_bdev || lo_bdev_can_use_dio(lo, backing_bdev)); +static void __loop_update_dio(struct loop_device *lo, bool dio) +{ + bool use_dio = dio && lo_can_use_dio(lo); if (lo->use_dio == use_dio) return; /* flush dirty pages before changing direct IO */ - vfs_fsync(file, 0); + vfs_fsync(lo->lo_backing_file, 0); /* * The flag of LO_FLAGS_DIRECT_IO is handled similarly with From patchwork Fri Jan 10 07:37:34 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13933889 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 467AA2080E1 for ; Fri, 10 Jan 2025 07:38: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=1736494690; cv=none; b=cPQnYTjFrWfdN225WE837+2RR5i6XSYPSfVBGzZ441Lzq2ICYIb+Wh4T8a2L7cGFzyxo4Ds6lK4f0oYtOc6zraakIKELAn37gkocKVYXSKxXy1lw7jMauePaHFVCXqU3jIS8fTxXaVqxAKeoZ7IC7YDIIOcdTS2Po5x4f6E+sVg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736494690; c=relaxed/simple; bh=QtAsjwGcMr/cl8FB/1WvCspVxDh08/JBTZi1wckbVQY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Uy4KT2F7bMhaQHI+L7oJO80+uKx5T6hhHzV7zKO+Kx4n/zigXL1nxbUpb8gLIj9ERaZMG+/qTtYA3DBiU4O4wlqG3l3Wst7A5y+rcTsyQpRtaQxAXK0nwGZ0mPalZ9qya5vHdtz0I578n7DxO4KZ8Ha3breN4OBOf7AeS1p4/WI= 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=pj+meaqa; 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="pj+meaqa" 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=3Jtcm6CMpcaO8P1Y7V8sqa3C2at6TAs1buK5yy5RA5s=; b=pj+meaqa74fiolEk4xzP+zCEKq zTz0pRDSJqtp4o2q6zP/IXjy2LJ3kW5ugKIZSdJl3yGKa3afUnB5j7xnKXsTM6ncA4KPLKIbpniV7 DGYC5m2G2qXMmak1Piv2XINhwd+S4xDOK/WDijsu32sLv43CFCj2BTJH0D+mFaVX8b+L6IITw/9Su wT2cFLKLSNrHyPRv6YtEA5jVwF36WC/uNX45U9MwCEGCWmAKtEnlIu40MXDNgUbAcbeQC4oHYH883 yhzTo8IVA8LqU90nqsAQqvD37WvtAeEk7c5frIef8rxYD6z97GP4SeuySwcGMpyt829Fe70ddTopZ Wha6P66w==; Received: from 2a02-8389-2341-5b80-76c3-a3dc-14f6-94e8.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:76c3:a3dc:14f6:94e8] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1tW9aq-0000000EOSB-1GJY; Fri, 10 Jan 2025 07:38:08 +0000 From: Christoph Hellwig To: Jens Axboe Cc: linux-block@vger.kernel.org Subject: [PATCH 4/8] loop: only write back pagecache when starting to to use direct I/O Date: Fri, 10 Jan 2025 08:37:34 +0100 Message-ID: <20250110073750.1582447-5-hch@lst.de> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250110073750.1582447-1-hch@lst.de> References: <20250110073750.1582447-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 There is no point in doing an fdatasync to write out pages when switching away from direct I/O, as there won't be any. The writeback is only needed when switching to direct I/O, which would have to invalidate the pagecache less efficiently from the I/O path. Signed-off-by: Christoph Hellwig --- drivers/block/loop.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/block/loop.c b/drivers/block/loop.c index 55bea9c95b45..cf80cdf5e440 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -203,8 +203,9 @@ static void __loop_update_dio(struct loop_device *lo, bool dio) if (lo->use_dio == use_dio) return; - /* flush dirty pages before changing direct IO */ - vfs_fsync(lo->lo_backing_file, 0); + /* flush dirty pages before starting to use direct I/O */ + if (use_dio) + vfs_fsync(lo->lo_backing_file, 0); /* * The flag of LO_FLAGS_DIRECT_IO is handled similarly with From patchwork Fri Jan 10 07:37:35 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13933890 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 A9A85207DE5 for ; Fri, 10 Jan 2025 07:38:12 +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=1736494694; cv=none; b=bnSmLImPp3KTA0UfZjSNWt49dDEsmHlIbkrAQeAvf8CzPV59Hjm0q5XDAi36I8J3RBWIdT1+3RGRG1rMWoa4pisfGLCTsYOrUDujmzEuHKi6hxYUKCi11FXe2niH/m/jzQyjgjDdkEsjmyUrOkIrOUiCgFFqZT5Eb/M0Ll1T+Mc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736494694; c=relaxed/simple; bh=B/CqjXNIn+4NPKDzVoJKydDehoEWa2uGacNRUZ8+R+M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QFYyY5XHNRWFBEwOtQQnlWaAIlFVayz7IqVr9wb4xjqmQ8iIIDg6Ciw/piu2CuxxWj5bYvk/06u20NNp+rRKRPh4Gl77p34Ep9NlOtBMSmKa36psJpabytOsR0YSqVJl7Euo1jYZ6JPHmgJcy47IBJZutu9i4mFqmx/+uui5Mbo= 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=0sSTghqq; 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="0sSTghqq" 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=sHe7CdWpC98PmbFIcWxI15Gbkx5EugCyXfHuarJeyOo=; b=0sSTghqqttRP4aBtfM474o96aX 0PNT/j8gNBNOtax1pU+NAvkjh3cdzOQOgqi/kE5zULnbs+MnRfipFw8BEuAX/RqRBiVw2CLYDL9JZ 3HklD1z4i5H8eN0PeGT2rZdkSzhCtO9UAV5Jm5kLnE2LX/KZfAMMw3qi4jb/JuELzuAsUEmys4Zc0 wv4KgNPvcAgjTkTzcIrBSIvfIcuPGU/x3yr59+sgb0iX9Qyu7L7aMIAfr28Elezv4cOd7j2EnmNbK 5eQMAKAroIMqGEUPFIjt1Hhvrkqg6NmsrG5igcG+QVFSLMJ93E6mxBYU7+MZIY/WmpsgqdL2j1Wyb maFOvdQA==; Received: from 2a02-8389-2341-5b80-76c3-a3dc-14f6-94e8.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:76c3:a3dc:14f6:94e8] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1tW9at-0000000EOTI-3Prr; Fri, 10 Jan 2025 07:38:12 +0000 From: Christoph Hellwig To: Jens Axboe Cc: linux-block@vger.kernel.org Subject: [PATCH 5/8] loop: open code the direct I/O flag update in loop_set_dio Date: Fri, 10 Jan 2025 08:37:35 +0100 Message-ID: <20250110073750.1582447-6-hch@lst.de> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250110073750.1582447-1-hch@lst.de> References: <20250110073750.1582447-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 loop_set_dio is different from the other (__)loop_update_dio callers in that it doesn't take any implicit conditions into account and wants to update the direct I/O flag to the user passed in value and fail if that can't be done. Open code the logic here to prepare for simplifying the other direct I/O flag updates and to make the error handling less convoluted. Signed-off-by: Christoph Hellwig --- drivers/block/loop.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/drivers/block/loop.c b/drivers/block/loop.c index cf80cdf5e440..6eb6d901151c 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -1455,16 +1455,28 @@ static int loop_set_capacity(struct loop_device *lo) static int loop_set_dio(struct loop_device *lo, unsigned long arg) { - int error = -ENXIO; - if (lo->lo_state != Lo_bound) - goto out; + bool use_dio = !!arg; - __loop_update_dio(lo, !!arg); - if (lo->use_dio == !!arg) + if (lo->lo_state != Lo_bound) + return -ENXIO; + if (use_dio == lo->use_dio) return 0; - error = -EINVAL; - out: - return error; + + if (use_dio) { + if (!lo_can_use_dio(lo)) + return -EINVAL; + /* flush dirty pages before starting to use direct I/O */ + vfs_fsync(lo->lo_backing_file, 0); + } + + blk_mq_freeze_queue(lo->lo_queue); + lo->use_dio = use_dio; + if (use_dio) + lo->lo_flags |= LO_FLAGS_DIRECT_IO; + else + lo->lo_flags &= ~LO_FLAGS_DIRECT_IO; + blk_mq_unfreeze_queue(lo->lo_queue); + return 0; } static int loop_set_block_size(struct loop_device *lo, unsigned long arg) From patchwork Fri Jan 10 07:37:36 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13933891 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 9619620896A for ; Fri, 10 Jan 2025 07:38:16 +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=1736494697; cv=none; b=AcopwYnFAK1qp1Qi09iwkO0BcTR+pdHXRmeYHdwXBSkDTLTnjkbiXEgIMIz10zUVIyg25864KcXPPZhS7/l+3ISlnXCxhmjzWIvwKwOak9tsCPuG+WwwFicdqLIPOFeVOh6929+fq1Tma/u+Dl+DBZjNSH9l5iGDkcXrE2nM5sY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736494697; c=relaxed/simple; bh=CIp4/pGngL2eeI7L7SlkTIp1aEoV4GKhiRytdBbJ0L4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=C8wNfxbCdSnYlihjL5CGdb4tuSnvnTqtGDQV9jncp9OCrkeMh6enTxdD1uPwICaOUZiezOJT+brUhOAjR9x9JgMSTrKE2RIqSm3A1umCJYfKzAdx9atjtFCMO+1IJHWguKlR/ttaHmy7BJi3tNPwfldk2yYU64+MHrU6Y+8j8Tk= 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=rKb741zp; 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="rKb741zp" 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=GleDJqF1Ska9OhiZxaP8JYwFeW87TAxXN7QGenaOOGA=; b=rKb741zp975Dd9Z6WztLVDd/Ao R6ZPHnitXdcgFgrHNvJMDjXjhgXXn8UACqMrTYHpU4R7gktN9ULnd0ZCRLEf6ke7EzDJJQXTjAbm/ 7c5p5GeNcpDze/MEE8GJb1y2iE3Fk9fY3kDgdi6mMs9jQMNw9LLHSwxvrPBYiP8EFFuOyoumh1T9Z 7b2VmRK2VaBazJ0BNktTvs8G4ropZZC0hBhUWJkZF0vkgembxXdkNGUJzmd5L5dKZqfSJ7PbHVT8L uaqWqoNCax0uHMnLfHlEsQJOJ9Cn7kB1MNacjMHCITmZn2eOOZwhksmNvUCKKyfxSQ4H448cVB0Un WLWOKgsg==; Received: from 2a02-8389-2341-5b80-76c3-a3dc-14f6-94e8.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:76c3:a3dc:14f6:94e8] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1tW9ax-0000000EOUs-2XZ9; Fri, 10 Jan 2025 07:38:16 +0000 From: Christoph Hellwig To: Jens Axboe Cc: linux-block@vger.kernel.org Subject: [PATCH 6/8] loop: allow loop_set_status to re-enable direct I/O Date: Fri, 10 Jan 2025 08:37:36 +0100 Message-ID: <20250110073750.1582447-7-hch@lst.de> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250110073750.1582447-1-hch@lst.de> References: <20250110073750.1582447-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 Unlike all other calls of (__)loop_update_dio, loop_set_status never looks at the O_DIRECT flag of the backing file, and thus doesn't re-enable direct I/O on an O_DIRECT backing file if e.g. the new block size would allow it. Fix that and remove the need for the separate __loop_update_dio flag. Signed-off-by: Christoph Hellwig --- drivers/block/loop.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/drivers/block/loop.c b/drivers/block/loop.c index 6eb6d901151c..2e1f8aa045a9 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -196,8 +196,9 @@ static bool lo_can_use_dio(struct loop_device *lo) return true; } -static void __loop_update_dio(struct loop_device *lo, bool dio) +static inline void loop_update_dio(struct loop_device *lo) { + bool dio = lo->use_dio || (lo->lo_backing_file->f_flags & O_DIRECT); bool use_dio = dio && lo_can_use_dio(lo); if (lo->use_dio == use_dio) @@ -531,12 +532,6 @@ static int do_req_filebacked(struct loop_device *lo, struct request *rq) } } -static inline void loop_update_dio(struct loop_device *lo) -{ - __loop_update_dio(lo, (lo->lo_backing_file->f_flags & O_DIRECT) | - lo->use_dio); -} - static void loop_reread_partitions(struct loop_device *lo) { int rc; @@ -1301,7 +1296,7 @@ loop_set_status(struct loop_device *lo, const struct loop_info64 *info) } /* update the direct I/O flag if lo_offset changed */ - __loop_update_dio(lo, lo->use_dio); + loop_update_dio(lo); out_unfreeze: blk_mq_unfreeze_queue(lo->lo_queue); From patchwork Fri Jan 10 07:37:37 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13933892 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 6B92B207A11 for ; Fri, 10 Jan 2025 07:38:20 +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=1736494701; cv=none; b=XT4z8f7icgCZ3MEcAJi8WVnivu1wqIfM64in9ayGvT/NnUppX+DoGqbcZxETUGoGGCvrlYehPxx7/xr0hgLRwBnrRDVruUoPgMFN/aXsSfHgBs+7Si6CBZKdhs53a7nYwGxAufuQcOcksqB0TTxu0W1OaL3PNJXyG4YDo0V4jOc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736494701; c=relaxed/simple; bh=OsbCom6Fg/UasFWKuW0xQQvWLbq4I7yjnmf7yIRjVPM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eM5iUYdgQjTYemRH54Av+/VJmtCBPYez5mv1HJ2vyf4l/oDEiIJ/WKuN96X69a2c32BrHv456amd1txnJNFb5+syv6pHv7LcCdK0qcOVpM4Zg/Z+VimojytO0oi6Z2fv6aGjQRrEeJ3ltcVw0ZnVqwLGKV/Zh5PA5ypwHQasQM8= 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=X49AdG/2; 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="X49AdG/2" 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=wSEfXYhlhmvAtNThGIhg3iNUE9ObFa3rkgFmAgRQsvU=; b=X49AdG/2e5qpXfsO/nUoizn2sW cwUr/mcIRBAEelO5kblBD5A9pWS0Lr+bqbn5VQkdRjAahQYPS0XVohwCIkU49kP6ATxX2SrWyRwM/ Uv9MbnrqzwCp8sgzFijovaBUNmATrjbjXEQBrsBePqKHQa9CJenrxVi1716XWhLo6R1Vhbl/iPfDN 4twMJysXS0Q2Pm99FqGjxlmmssAXbnz0so2I9pJdwSZbAgrJxRWmCzUiixXUN9x+XAO3WYeHsuyPz eypGx41BEMNF/iyZFOznkmXAwqBjR+oIanWXsnBUnRtfRuURe0emxT1rb+B1pIsdxU4CWhq0Oj+9a SKzzhaZA==; Received: from 2a02-8389-2341-5b80-76c3-a3dc-14f6-94e8.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:76c3:a3dc:14f6:94e8] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1tW9b1-0000000EOXi-23s1; Fri, 10 Jan 2025 07:38:20 +0000 From: Christoph Hellwig To: Jens Axboe Cc: linux-block@vger.kernel.org Subject: [PATCH 7/8] loop: don't freeze the queue in loop_update_dio Date: Fri, 10 Jan 2025 08:37:37 +0100 Message-ID: <20250110073750.1582447-8-hch@lst.de> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250110073750.1582447-1-hch@lst.de> References: <20250110073750.1582447-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 All callers of loop_update_dio except for loop_configure already have the queue frozen, and loop_configure works on an unbound device. Remove the superfluous recursive freezing in loop_update_dio and add asserts for the locking and freezing state instead. Signed-off-by: Christoph Hellwig --- drivers/block/loop.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/block/loop.c b/drivers/block/loop.c index 2e1f8aa045a9..acb1a0cdfb27 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -201,6 +201,10 @@ static inline void loop_update_dio(struct loop_device *lo) bool dio = lo->use_dio || (lo->lo_backing_file->f_flags & O_DIRECT); bool use_dio = dio && lo_can_use_dio(lo); + lockdep_assert_held(&lo->lo_mutex); + WARN_ON_ONCE(lo->lo_state == Lo_bound && + lo->lo_queue->mq_freeze_depth == 0); + if (lo->use_dio == use_dio) return; @@ -213,15 +217,11 @@ static inline void loop_update_dio(struct loop_device *lo) * LO_FLAGS_READ_ONLY, both are set from kernel, and losetup * will get updated by ioctl(LOOP_GET_STATUS) */ - if (lo->lo_state == Lo_bound) - blk_mq_freeze_queue(lo->lo_queue); lo->use_dio = use_dio; if (use_dio) lo->lo_flags |= LO_FLAGS_DIRECT_IO; else lo->lo_flags &= ~LO_FLAGS_DIRECT_IO; - if (lo->lo_state == Lo_bound) - blk_mq_unfreeze_queue(lo->lo_queue); } /** From patchwork Fri Jan 10 07:37:38 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13933893 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 48493207A25 for ; Fri, 10 Jan 2025 07:38:23 +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=1736494704; cv=none; b=J3TYy2D/EWbTi7VYxkQP16RL3YB/sUVkx4LvOUTnLGEPtLE4tX9da0YqZY8RgSAng8wsIjw+JbWYlhl2RJelf2vDR7YpMWg8+9dLM1WvjMbu2EZo5YRzZ2aavkZxSOFjYhmOym1fJocQV9xwCK8aleB2Qj8+rj3c0lRMHLcNOLA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736494704; c=relaxed/simple; bh=1nidxe83YlOVFnlUAhC/TWTuQm/ksSKIUHo5sDKV4X0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=H3GU7rohikm9LbPSqp1jJwBfCXX4AktTlFp8DHpr3QdfbWX39e67PUcHZ2u2i/I6BV4bxvRqszuYCAzsi8T1uk6gojLoW/LStefLbeqJc+AOSIV6NRm0FQQ3NGS4gv/hazGB5UVsJ7kdHaP5MTnRAAI2yJ1LZcAotW3Nixfm0gA= 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=YFwtpApL; 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="YFwtpApL" 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=mypScqCIyLbbV6jVQFhblmb33CqlnwMmBfpnCB8FigQ=; b=YFwtpApLGwGfBt9W2qPFEAhP9q U8nXlGRv4G7N29yk3Nt5IpEpfAvQAQtd/nMfnb6ZtYAGsLEYyqOqCdwQYBjLu27nHFsXunLtkuNuH MyNPQHMCmae7bss0McZ1OuCJJ/0jTM2mSzTXHhUSXrGar7pH1sktDalqPfy+W2srKHk7OcsTXwE53 CzCxDBmxZ3lfpTMZUqx90P3BmJaNWHIwasdxr+hzpv0P88GB1YmgWggmDBeYUe1xGLwcjNWE3WxwD KcvCqL7aAwGl8G0HhceB1S7WuNeT/3Nbq6UQOc8dtHOpphyUN13npQ1PhHA0Iog00gwW3ciLLqrOy 6POnrqIg==; Received: from 2a02-8389-2341-5b80-76c3-a3dc-14f6-94e8.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:76c3:a3dc:14f6:94e8] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1tW9b4-0000000EOZS-29ZG; Fri, 10 Jan 2025 07:38:23 +0000 From: Christoph Hellwig To: Jens Axboe Cc: linux-block@vger.kernel.org Subject: [PATCH 8/8] loop: remove the use_dio field in struct loop_device Date: Fri, 10 Jan 2025 08:37:38 +0100 Message-ID: <20250110073750.1582447-9-hch@lst.de> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250110073750.1582447-1-hch@lst.de> References: <20250110073750.1582447-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 This field duplicate the LO_FLAGS_DIRECT_IO flag in lo_flags. Remove it to have a single source of truth about using direct I/O. Signed-off-by: Christoph Hellwig --- drivers/block/loop.c | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/drivers/block/loop.c b/drivers/block/loop.c index acb1a0cdfb27..1ec7417c7f00 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -68,7 +68,6 @@ struct loop_device { struct list_head idle_worker_list; struct rb_root worker_tree; struct timer_list timer; - bool use_dio; bool sysfs_inited; struct request_queue *lo_queue; @@ -196,32 +195,30 @@ static bool lo_can_use_dio(struct loop_device *lo) return true; } +/* + * Direct I/O can be enabled either by using an O_DIRECT file descriptor, or by + * passing in the LO_FLAGS_DIRECT_IO flag from userspace. It will be silently + * disabled when the device block size is too small or the offset is unaligned. + * + * loop_get_status will always report the effective LO_FLAGS_DIRECT_IO flag and + * not the originally passed in one. + */ static inline void loop_update_dio(struct loop_device *lo) { - bool dio = lo->use_dio || (lo->lo_backing_file->f_flags & O_DIRECT); - bool use_dio = dio && lo_can_use_dio(lo); + bool dio_in_use = lo->lo_flags & LO_FLAGS_DIRECT_IO; lockdep_assert_held(&lo->lo_mutex); WARN_ON_ONCE(lo->lo_state == Lo_bound && lo->lo_queue->mq_freeze_depth == 0); - if (lo->use_dio == use_dio) - return; - - /* flush dirty pages before starting to use direct I/O */ - if (use_dio) - vfs_fsync(lo->lo_backing_file, 0); - - /* - * The flag of LO_FLAGS_DIRECT_IO is handled similarly with - * LO_FLAGS_READ_ONLY, both are set from kernel, and losetup - * will get updated by ioctl(LOOP_GET_STATUS) - */ - lo->use_dio = use_dio; - if (use_dio) + if (lo->lo_backing_file->f_flags & O_DIRECT) lo->lo_flags |= LO_FLAGS_DIRECT_IO; - else + if ((lo->lo_flags & LO_FLAGS_DIRECT_IO) && !lo_can_use_dio(lo)) lo->lo_flags &= ~LO_FLAGS_DIRECT_IO; + + /* flush dirty pages before starting to issue direct I/O */ + if ((lo->lo_flags & LO_FLAGS_DIRECT_IO) && !dio_in_use) + vfs_fsync(lo->lo_backing_file, 0); } /** @@ -1089,7 +1086,6 @@ static int loop_configure(struct loop_device *lo, blk_mode_t mode, disk_force_media_change(lo->lo_disk); set_disk_ro(lo->lo_disk, (lo->lo_flags & LO_FLAGS_READ_ONLY) != 0); - lo->use_dio = lo->lo_flags & LO_FLAGS_DIRECT_IO; lo->lo_device = bdev; lo->lo_backing_file = file; lo->old_gfp_mask = mapping_gfp_mask(mapping); @@ -1454,7 +1450,7 @@ static int loop_set_dio(struct loop_device *lo, unsigned long arg) if (lo->lo_state != Lo_bound) return -ENXIO; - if (use_dio == lo->use_dio) + if (use_dio == !!(lo->lo_flags & LO_FLAGS_DIRECT_IO)) return 0; if (use_dio) { @@ -1465,7 +1461,6 @@ static int loop_set_dio(struct loop_device *lo, unsigned long arg) } blk_mq_freeze_queue(lo->lo_queue); - lo->use_dio = use_dio; if (use_dio) lo->lo_flags |= LO_FLAGS_DIRECT_IO; else @@ -1876,7 +1871,7 @@ static blk_status_t loop_queue_rq(struct blk_mq_hw_ctx *hctx, cmd->use_aio = false; break; default: - cmd->use_aio = lo->use_dio; + cmd->use_aio = lo->lo_flags & LO_FLAGS_DIRECT_IO; break; }