From patchwork Fri May 3 00:07:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Al Viro X-Patchwork-Id: 13652222 Received: from zeniv.linux.org.uk (zeniv.linux.org.uk [62.89.141.173]) (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 E200D363; Fri, 3 May 2024 00:07:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=62.89.141.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714694849; cv=none; b=YbsNf0+o8+gO3vvIz41jjT5r14znTwh8KJif9weunBhstvP98zY+QDc8rJQKfnjpRdc0tV8bU6vxSNDXZyjQdi4wjOgjvMQ2Ok3qi7ofLCnR40TkSsy1ZKfszn0iZ0MCmPBO0emy0UBcDezMTWYtDyRhlKNmx6f7mtIC683VKlY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714694849; c=relaxed/simple; bh=LFrJDxmKj9w6ynN8mcUGqPilpYVqB1/3O06eZI980b4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Yra6OrFCC+H2eQHYK69jpqVLr2e7kpRAtwbdySb5Bg70agCogabpGU4jSzfaxiTOVXz9yvlJu6khlxymnadXQ6UU03AGrD2jyT4ZClXZeoDH4bDbV9QkGxJmXLMG7JQtwx7Bi7jVAzjvQdGaWqEEufzl/UcHxZpQj9cK9DYWq0M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zeniv.linux.org.uk; spf=none smtp.mailfrom=ftp.linux.org.uk; dkim=pass (2048-bit key) header.d=linux.org.uk header.i=@linux.org.uk header.b=Hn0LB+0C; arc=none smtp.client-ip=62.89.141.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zeniv.linux.org.uk Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=ftp.linux.org.uk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linux.org.uk header.i=@linux.org.uk header.b="Hn0LB+0C" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=linux.org.uk; s=zeniv-20220401; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=ys4a7CLJtVETbT20zG171QwSQa3BYsZmIsfgyhTcRXw=; b=Hn0LB+0CPYMxaSnDHwmrqWfZfu 7l4BeWkE/UokBL3hFDDWCXZMJh25TCm1VpC0yhjDbcapcHyoURiH/kJW3K8vGKvIzUS8gFQ5yjY9A oXPkfinF3xwDRk/4mVKK+vXLB5yKDPZ+JM1hVpe3xSL2bATgw4gOGcOQ1NvHUvLFdEMznP0gq2gWz NstQgVcpytj4f2JuPMD/zynf3/d3uzquIJVHRsmpIRwb4Tpd5W7yojHjupWJSiZmUvTys1LuFj3MY drSp9Si7mmMSgTOKJpvsSFbNNZB26ytqRNlOxhb3o6P4zDNDV/SvlaPX5RnFLedmoQgJitm4Pf2Zf HgfZshvw==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.96 #2 (Red Hat Linux)) id 1s2gST-009tG1-0W; Fri, 03 May 2024 00:07:25 +0000 Date: Fri, 3 May 2024 01:07:25 +0100 From: Al Viro To: Christoph Hellwig Cc: linux-fsdevel@vger.kernel.org, Yu Kuai , linux-block@vger.kernel.org, Christian Brauner , Jens Axboe Subject: [PATCH 1/8] Use bdev_is_paritition() instead of open-coding it Message-ID: <20240503000725.GA2357260@ZenIV> References: <20240428051232.GU2118490@ZenIV> <20240429052315.GB32688@lst.de> <20240429073107.GZ2118490@ZenIV> <20240429170209.GA2118490@ZenIV> <20240429181300.GB2118490@ZenIV> <20240429183041.GC2118490@ZenIV> <20240503000647.GQ2118490@ZenIV> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20240503000647.GQ2118490@ZenIV> Sender: Al Viro Reviewed-by: Christoph Hellwig Signed-off-by: Al Viro --- block/blk-core.c | 5 +++-- block/blk-mq.c | 2 +- include/linux/part_stat.h | 2 +- lib/vsprintf.c | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/block/blk-core.c b/block/blk-core.c index a16b5abdbbf5..20322abc6082 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -759,7 +759,8 @@ void submit_bio_noacct(struct bio *bio) if (!bio_flagged(bio, BIO_REMAPPED)) { if (unlikely(bio_check_eod(bio))) goto end_io; - if (bdev->bd_partno && unlikely(blk_partition_remap(bio))) + if (bdev_is_partition(bdev) && + unlikely(blk_partition_remap(bio))) goto end_io; } @@ -989,7 +990,7 @@ void update_io_ticks(struct block_device *part, unsigned long now, bool end) if (likely(try_cmpxchg(&part->bd_stamp, &stamp, now))) __part_stat_add(part, io_ticks, end ? now - stamp : 1); } - if (part->bd_partno) { + if (bdev_is_partition(part)) { part = bdev_whole(part); goto again; } diff --git a/block/blk-mq.c b/block/blk-mq.c index 32afb87efbd0..43bb8f50a07c 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -92,7 +92,7 @@ static bool blk_mq_check_inflight(struct request *rq, void *priv) struct mq_inflight *mi = priv; if (rq->part && blk_do_io_stat(rq) && - (!mi->part->bd_partno || rq->part == mi->part) && + (!bdev_is_partition(mi->part) || rq->part == mi->part) && blk_mq_rq_state(rq) == MQ_RQ_IN_FLIGHT) mi->inflight[rq_data_dir(rq)]++; diff --git a/include/linux/part_stat.h b/include/linux/part_stat.h index abeba356bc3f..ac8c44dd8237 100644 --- a/include/linux/part_stat.h +++ b/include/linux/part_stat.h @@ -59,7 +59,7 @@ static inline void part_stat_set_all(struct block_device *part, int value) #define part_stat_add(part, field, addnd) do { \ __part_stat_add((part), field, addnd); \ - if ((part)->bd_partno) \ + if (bdev_is_partition(part)) \ __part_stat_add(bdev_whole(part), field, addnd); \ } while (0) diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 552738f14275..3f9f1b959ef0 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -966,7 +966,7 @@ char *bdev_name(char *buf, char *end, struct block_device *bdev, hd = bdev->bd_disk; buf = string(buf, end, hd->disk_name, spec); - if (bdev->bd_partno) { + if (bdev_is_partition(bdev)) { if (isdigit(hd->disk_name[strlen(hd->disk_name)-1])) { if (buf < end) *buf = 'p'; From patchwork Fri May 3 00:07:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Al Viro X-Patchwork-Id: 13652223 Received: from zeniv.linux.org.uk (zeniv.linux.org.uk [62.89.141.173]) (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 091BD360; Fri, 3 May 2024 00:07:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=62.89.141.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714694874; cv=none; b=FKxCGgJvEOmW48K96MbM/7E2MeU1RSERigmwAfli/BEKc/Md35KmbzY55+W7loAd5UZVuM3uLNPNnyWDZc0wO1qdQzYhoIOk07glTA8rRpNXcI/4nOLaeQmIkkP3QXJnYGVID31V00X6crq314CtwJ+zVU7VGP3ZROneRg/7a0Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714694874; c=relaxed/simple; bh=m2aZ1DeTWeEYs4Hfg2zynhEj7mEerAUtys8ZINR/T5s=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=CWWcFaZbLKoh77xhDKjty6mboVaqEIeEpx8OqPOQvXSxC5U9W4esp6hCXuuXaIeGs+4c7YQSEV3xNjvn+7DuJcjMdGEnNPX1zYEFV9CXk1q4VSJwuNZW6FUHhuoaIhxG4ffrCG9x785M8a65bLnWHwWeXmIeMa+acMNoJkedegc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zeniv.linux.org.uk; spf=none smtp.mailfrom=ftp.linux.org.uk; dkim=pass (2048-bit key) header.d=linux.org.uk header.i=@linux.org.uk header.b=gIsfy8Gp; arc=none smtp.client-ip=62.89.141.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zeniv.linux.org.uk Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=ftp.linux.org.uk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linux.org.uk header.i=@linux.org.uk header.b="gIsfy8Gp" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=linux.org.uk; s=zeniv-20220401; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=9Dp0BIALSGxgiIBh3V0yvPHXGeHmC+LFW7q/zZU4J9c=; b=gIsfy8Gpio0FFLsJWp6E/p1dvV u0CiXqtQ02hmaCjyQRYw5eOh+qb+hW42DgnnUzhyjVcvBX2QzZ7lY5Hy9RBWaPBcVWDWhRCCVhzLA 0a4rURyEZntY2CB15nxawGPc/no6p7c2Wlu1MCgmch3XSPsPF0Zf97txzGO709vGRNbHD5wirZwVP pew3StXDVILVIqtGLG13ipVmQ+RvP7iOenD/pySNH1tJfgp0JlFn2NyvklAHn7aagkwykm4NARxeX txK3OOoFw2fZfHZ/0AU1P0zD2RKhF2GgY1ckZttsbkVTmgzecBdQoCP663UVc2yabIDoRqvclDMh0 zBJR8a4w==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.96 #2 (Red Hat Linux)) id 1s2gSt-009tHH-0H; Fri, 03 May 2024 00:07:51 +0000 Date: Fri, 3 May 2024 01:07:51 +0100 From: Al Viro To: Christoph Hellwig Cc: linux-fsdevel@vger.kernel.org, Yu Kuai , linux-block@vger.kernel.org, Christian Brauner , Jens Axboe Subject: [PATCH 2/8] wrapper for access to ->bd_partno Message-ID: <20240503000751.GB2357260@ZenIV> References: <20240428051232.GU2118490@ZenIV> <20240429052315.GB32688@lst.de> <20240429073107.GZ2118490@ZenIV> <20240429170209.GA2118490@ZenIV> <20240429181300.GB2118490@ZenIV> <20240429183041.GC2118490@ZenIV> <20240503000647.GQ2118490@ZenIV> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20240503000647.GQ2118490@ZenIV> Sender: Al Viro On the next step it's going to get folded into a field where flags will go. Signed-off-by: Al Viro --- block/early-lookup.c | 2 +- block/partitions/core.c | 12 ++++++------ include/linux/blkdev.h | 7 ++++++- lib/vsprintf.c | 2 +- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/block/early-lookup.c b/block/early-lookup.c index 3effbd0d35e9..3fb57f7d2b12 100644 --- a/block/early-lookup.c +++ b/block/early-lookup.c @@ -78,7 +78,7 @@ static int __init devt_from_partuuid(const char *uuid_str, dev_t *devt) * to the partition number found by UUID. */ *devt = part_devt(dev_to_disk(dev), - dev_to_bdev(dev)->bd_partno + offset); + bdev_partno(dev_to_bdev(dev)) + offset); } else { *devt = dev->devt; } diff --git a/block/partitions/core.c b/block/partitions/core.c index b11e88c82c8c..edd5309dc4ba 100644 --- a/block/partitions/core.c +++ b/block/partitions/core.c @@ -173,7 +173,7 @@ static struct parsed_partitions *check_partition(struct gendisk *hd) static ssize_t part_partition_show(struct device *dev, struct device_attribute *attr, char *buf) { - return sprintf(buf, "%d\n", dev_to_bdev(dev)->bd_partno); + return sprintf(buf, "%d\n", bdev_partno(dev_to_bdev(dev))); } static ssize_t part_start_show(struct device *dev, @@ -250,7 +250,7 @@ static int part_uevent(const struct device *dev, struct kobj_uevent_env *env) { const struct block_device *part = dev_to_bdev(dev); - add_uevent_var(env, "PARTN=%u", part->bd_partno); + add_uevent_var(env, "PARTN=%u", bdev_partno(part)); if (part->bd_meta_info && part->bd_meta_info->volname[0]) add_uevent_var(env, "PARTNAME=%s", part->bd_meta_info->volname); return 0; @@ -267,7 +267,7 @@ void drop_partition(struct block_device *part) { lockdep_assert_held(&part->bd_disk->open_mutex); - xa_erase(&part->bd_disk->part_tbl, part->bd_partno); + xa_erase(&part->bd_disk->part_tbl, bdev_partno(part)); kobject_put(part->bd_holder_dir); device_del(&part->bd_device); @@ -338,8 +338,8 @@ static struct block_device *add_partition(struct gendisk *disk, int partno, pdev->parent = ddev; /* in consecutive minor range? */ - if (bdev->bd_partno < disk->minors) { - devt = MKDEV(disk->major, disk->first_minor + bdev->bd_partno); + if (bdev_partno(bdev) < disk->minors) { + devt = MKDEV(disk->major, disk->first_minor + bdev_partno(bdev)); } else { err = blk_alloc_ext_minor(); if (err < 0) @@ -404,7 +404,7 @@ static bool partition_overlaps(struct gendisk *disk, sector_t start, rcu_read_lock(); xa_for_each_start(&disk->part_tbl, idx, part, 1) { - if (part->bd_partno != skip_partno && + if (bdev_partno(part) != skip_partno && start < part->bd_start_sect + bdev_nr_sectors(part) && start + length > part->bd_start_sect) { overlap = true; diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index c3e8f7cf96be..32549d675955 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -720,6 +720,11 @@ void invalidate_disk(struct gendisk *disk); void set_disk_ro(struct gendisk *disk, bool read_only); void disk_uevent(struct gendisk *disk, enum kobject_action action); +static inline u8 bdev_partno(const struct block_device *bdev) +{ + return bdev->bd_partno; +} + static inline int get_disk_ro(struct gendisk *disk) { return disk->part0->bd_read_only || @@ -1095,7 +1100,7 @@ static inline int sb_issue_zeroout(struct super_block *sb, sector_t block, static inline bool bdev_is_partition(struct block_device *bdev) { - return bdev->bd_partno; + return bdev_partno(bdev) != 0; } enum blk_default_limits { diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 3f9f1b959ef0..cdd4e2314bfc 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -972,7 +972,7 @@ char *bdev_name(char *buf, char *end, struct block_device *bdev, *buf = 'p'; buf++; } - buf = number(buf, end, bdev->bd_partno, spec); + buf = number(buf, end, bdev_partno(bdev), spec); } return buf; } From patchwork Fri May 3 00:08:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Al Viro X-Patchwork-Id: 13652224 Received: from zeniv.linux.org.uk (zeniv.linux.org.uk [62.89.141.173]) (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 5C13B360; Fri, 3 May 2024 00:08:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=62.89.141.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714694916; cv=none; b=YGkO2goBSah6P2rHtjJsiZNcyWKdHraym2+ut2oquEY6zk8ePEJ6EJNKyfJn0bgjIszsywJdl053P0vKDxWnLVeq6AR+OmCXb33ENmG0gwphJ1xY+SbEizHA5P4hRChFFzzy6/bFxZR/WICmebmwBwIGpIIOvcQryIm/0J2O8Dg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714694916; c=relaxed/simple; bh=Nthh7ICbE2s/qv+DPz+C5N5NUF9cThrABfTelH21nwE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=p3LlkfEUlUxXeGr3nGGEkv2sq22PaKk9Td7KbJELByOYUTFqChcZfBe4E548aFOvLWCDVHQ3qs411GWinCv5rjqchGaYUItyKcfjUemGV0+0A1BziwsyPVCHDVAit8VnU9JvlFCQnyVI4FwHjPvmLrvtfHQRnHwGv7m6QO5kvqE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zeniv.linux.org.uk; spf=none smtp.mailfrom=ftp.linux.org.uk; dkim=pass (2048-bit key) header.d=linux.org.uk header.i=@linux.org.uk header.b=VL3UFXMc; arc=none smtp.client-ip=62.89.141.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zeniv.linux.org.uk Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=ftp.linux.org.uk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linux.org.uk header.i=@linux.org.uk header.b="VL3UFXMc" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=linux.org.uk; s=zeniv-20220401; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=MwJ+QCQAAQMykWTxtpk8i97fNwYcavR7sdQTgeYOgN8=; b=VL3UFXMc7rBbgCMqAP3CSMLC81 p1cfhmTa5CgkrIw62G6tMW2kunIF6kKGDxRJ2Ai6wibH1mvwYBArReOE+KWGoOJKUuIh+v0g9St1Z H0PTsxd/I8qsLJord/reBHlg2QKCjnN+O9dPrM3FkVoi8Bxw3+9yvH+Aok6Qd0FDXRfifHWjfjosQ jNWU3vJm9LFhOc3VHzdAcpb1MpmXVs19hT/cFGLO0ejINM3VRN/a1TFJyPMPRJQEQSWwCJb39ZtCb QR+fDe9njm3yzLOyDEdLlo5SRGOUSfD79XpjSDv+LHt3vOn5EPmXjhhP6pBlZs7l/aZkoOYjKWbio w4ztAQ4w==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.96 #2 (Red Hat Linux)) id 1s2gTY-009tJc-0M; Fri, 03 May 2024 00:08:32 +0000 Date: Fri, 3 May 2024 01:08:32 +0100 From: Al Viro To: Christoph Hellwig Cc: linux-fsdevel@vger.kernel.org, Yu Kuai , linux-block@vger.kernel.org, Christian Brauner , Jens Axboe Subject: [PATCH v2 3/8] bdev: infrastructure for flags Message-ID: <20240503000832.GC2357260@ZenIV> References: <20240428051232.GU2118490@ZenIV> <20240429052315.GB32688@lst.de> <20240429073107.GZ2118490@ZenIV> <20240429170209.GA2118490@ZenIV> <20240429181300.GB2118490@ZenIV> <20240429183041.GC2118490@ZenIV> <20240503000647.GQ2118490@ZenIV> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20240503000647.GQ2118490@ZenIV> Sender: Al Viro Replace bd_partno with a 32bit field (__bd_flags). The lower 8 bits contain the partition number, the upper 24 are for flags. Helpers: bdev_{test,set,clear}_flag(bdev, flag), with atomic_or() and atomic_andnot() used to set/clear. NOTE: this commit does not actually move any flags over there - they are still bool fields. As the result, it shifts the fields wrt cacheline boundaries; that's going to be restored once the first 3 flags are dealt with. Signed-off-by: Al Viro --- block/bdev.c | 2 +- include/linux/blk_types.h | 3 ++- include/linux/blkdev.h | 17 ++++++++++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/block/bdev.c b/block/bdev.c index 7a5f611c3d2e..2ec223315500 100644 --- a/block/bdev.c +++ b/block/bdev.c @@ -411,7 +411,7 @@ struct block_device *bdev_alloc(struct gendisk *disk, u8 partno) mutex_init(&bdev->bd_fsfreeze_mutex); spin_lock_init(&bdev->bd_size_lock); mutex_init(&bdev->bd_holder_lock); - bdev->bd_partno = partno; + atomic_set(&bdev->__bd_flags, partno); bdev->bd_inode = inode; bdev->bd_queue = disk->queue; if (partno) diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h index cb1526ec44b5..04f92737ab08 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -45,8 +45,9 @@ struct block_device { struct request_queue * bd_queue; struct disk_stats __percpu *bd_stats; unsigned long bd_stamp; + atomic_t __bd_flags; // partition number + flags +#define BD_PARTNO 255 // lower 8 bits; assign-once bool bd_read_only; /* read-only policy */ - u8 bd_partno; bool bd_write_holder; bool bd_has_submit_bio; dev_t bd_dev; diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 32549d675955..99917e5860fd 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -722,7 +722,22 @@ void disk_uevent(struct gendisk *disk, enum kobject_action action); static inline u8 bdev_partno(const struct block_device *bdev) { - return bdev->bd_partno; + return atomic_read(&bdev->__bd_flags) & BD_PARTNO; +} + +static inline bool bdev_test_flag(const struct block_device *bdev, unsigned flag) +{ + return atomic_read(&bdev->__bd_flags) & flag; +} + +static inline void bdev_set_flag(struct block_device *bdev, unsigned flag) +{ + atomic_or(flag, &bdev->__bd_flags); +} + +static inline void bdev_clear_flag(struct block_device *bdev, unsigned flag) +{ + atomic_andnot(flag, &bdev->__bd_flags); } static inline int get_disk_ro(struct gendisk *disk) From patchwork Fri May 3 00:09:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Al Viro X-Patchwork-Id: 13652225 Received: from zeniv.linux.org.uk (zeniv.linux.org.uk [62.89.141.173]) (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 885F3363; Fri, 3 May 2024 00:09:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=62.89.141.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714694956; cv=none; b=mU/Zolp2KNg3L9nH6J9J7lJbbDC7lgDoh73t63a5NB9clFTpIUyN96nHivlOHhYC1V50B1SDM4qXdpea4ba5GSaukxEdOqBVwKiL5+7GJk2PhjbgHTRnnSIeD9MmDoJPF5z1+12jQS1lxZeLjYSU7OpplfQQtTCCmj7mrLJ0aPQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714694956; c=relaxed/simple; bh=cojsWIeyfGiLhxm2tPqb2vAQ5hT5Z34uEOctYj0O3Pg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=G4T/Env5mTZ3zR4yhUB5j9K2AA+h+/nlJFVGo5kNCTlptIS26ocywZLCrgjTgutvw3VOPFBEgNAnPenZj69LYyjK/vIyFOSzMlMT8o8raS98lCdDrbr2e+kY0leBWvNmrp+w13vhba/4kWOemWEdA6f7C7Am1tit36CrQdoc44k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zeniv.linux.org.uk; spf=none smtp.mailfrom=ftp.linux.org.uk; dkim=pass (2048-bit key) header.d=linux.org.uk header.i=@linux.org.uk header.b=hIn4o+Kx; arc=none smtp.client-ip=62.89.141.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zeniv.linux.org.uk Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=ftp.linux.org.uk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linux.org.uk header.i=@linux.org.uk header.b="hIn4o+Kx" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=linux.org.uk; s=zeniv-20220401; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=n4Ft2/FYJcfjKPznnQzW16Cvd+WdR+TnW1ctICzNXeo=; b=hIn4o+KxMIZn2p0bbE3P3ZyKlk 2LueSK00h43Ip/TxrOesHyPlJhNDsfwNcjjxe1vMbwQmim3qjpYCQ80Q9AZbYNd64cl49HG2pXqR6 Zcb/EZc4Lmcsxy/EOB5psfgELw4hhwsYIOl+iHV5p8AsMws0AmevVozytJ9OyHH9IxvKVLtuy0z93 UsluT5mKCKTbhgFCxCKHohGn2Kg9EXNkVAc9qKY4N6XWvvJz06MSfS8627uuD0ngnA3l7f8/0QTVC v1NWKc2TeugSR0YLitn/IJRoBrKrFufMJBEpA97BbNfD/LJ5/FGfJWtlbD0LnVAvZiBkRBuB4Dn8b xuTzSOFA==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.96 #2 (Red Hat Linux)) id 1s2gUD-009tLf-0M; Fri, 03 May 2024 00:09:13 +0000 Date: Fri, 3 May 2024 01:09:13 +0100 From: Al Viro To: Christoph Hellwig Cc: linux-fsdevel@vger.kernel.org, Yu Kuai , linux-block@vger.kernel.org, Christian Brauner , Jens Axboe Subject: [PATCH v2 4/8] bdev: move ->bd_read_only to ->__bd_flags Message-ID: <20240503000913.GD2357260@ZenIV> References: <20240428051232.GU2118490@ZenIV> <20240429052315.GB32688@lst.de> <20240429073107.GZ2118490@ZenIV> <20240429170209.GA2118490@ZenIV> <20240429181300.GB2118490@ZenIV> <20240429183041.GC2118490@ZenIV> <20240503000647.GQ2118490@ZenIV> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20240503000647.GQ2118490@ZenIV> Sender: Al Viro Signed-off-by: Al Viro --- block/ioctl.c | 5 ++++- include/linux/blk_types.h | 2 +- include/linux/blkdev.h | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/block/ioctl.c b/block/ioctl.c index 0c76137adcaa..be173e4ff43d 100644 --- a/block/ioctl.c +++ b/block/ioctl.c @@ -402,7 +402,10 @@ static int blkdev_roset(struct block_device *bdev, unsigned cmd, if (ret) return ret; } - bdev->bd_read_only = n; + if (n) + bdev_set_flag(bdev, BD_READ_ONLY); + else + bdev_clear_flag(bdev, BD_READ_ONLY); return 0; } diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h index 04f92737ab08..f70dd31cbcd1 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -47,7 +47,7 @@ struct block_device { unsigned long bd_stamp; atomic_t __bd_flags; // partition number + flags #define BD_PARTNO 255 // lower 8 bits; assign-once - bool bd_read_only; /* read-only policy */ +#define BD_READ_ONLY (1u<<8) // read-only policy bool bd_write_holder; bool bd_has_submit_bio; dev_t bd_dev; diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 99917e5860fd..1fe91231f85b 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -742,13 +742,13 @@ static inline void bdev_clear_flag(struct block_device *bdev, unsigned flag) static inline int get_disk_ro(struct gendisk *disk) { - return disk->part0->bd_read_only || + return bdev_test_flag(disk->part0, BD_READ_ONLY) || test_bit(GD_READ_ONLY, &disk->state); } static inline int bdev_read_only(struct block_device *bdev) { - return bdev->bd_read_only || get_disk_ro(bdev->bd_disk); + return bdev_test_flag(bdev, BD_READ_ONLY) || get_disk_ro(bdev->bd_disk); } bool set_capacity_and_notify(struct gendisk *disk, sector_t size); From patchwork Fri May 3 00:09:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Al Viro X-Patchwork-Id: 13652226 Received: from zeniv.linux.org.uk (zeniv.linux.org.uk [62.89.141.173]) (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 37A4B23BE; Fri, 3 May 2024 00:09:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=62.89.141.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714694992; cv=none; b=O4QUemcMV9MFydO7SIlEPWvVyxT3Bw20vD80qc1rlXAcA24xIvOjf+KgilRxkJ7mt2XYKBNiKOdDAeex4hBd9XHD9ULTvhhojR+1xihF9mXxQGS5xv+h6+TOnMMrj+IBQVlQqnTaP2zQMrRt0RasvOpyK60Vuz9PT2Ud27MrJz8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714694992; c=relaxed/simple; bh=D8AkZRzETStIuPLnD7JFVBUqMyBCxWhPezAy7TndIH4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=qG76cSeDBGlr3h1aK2iSOOG4a5HHFaySv0xTJYk1/+ix/jxdyqDSyTYjgnKDzdV/+8oVkhnc+yKH+CrFVGKG4lununrOKnGZKxhSRjQym4qzSxNx19feW8iEaE9ksREBnO9MFPZWVUTXPYcPg3RjM78fImkRyMQsqZdY683ddxk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zeniv.linux.org.uk; spf=none smtp.mailfrom=ftp.linux.org.uk; dkim=pass (2048-bit key) header.d=linux.org.uk header.i=@linux.org.uk header.b=RRlonU6a; arc=none smtp.client-ip=62.89.141.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zeniv.linux.org.uk Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=ftp.linux.org.uk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linux.org.uk header.i=@linux.org.uk header.b="RRlonU6a" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=linux.org.uk; s=zeniv-20220401; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=+zX/QCk99sTeJ4dtEAX8EjuXv+zzqKzaQmfxxlcg1Wg=; b=RRlonU6arumTzmeRtFIaoB0c0q pHXGy60vz+AZhJjGnZmk3qyMfs1yI04zAghogCQFVmjQ/U0PjYGmO5inwRPciUiwPE+vxnPdlVtMX zLdspbaBK18uz2V+ysZ/0YfuaacrfJuTbpmpgiuhp8CZCuRLVbiOOUPF1PiquQQHGAFPNEYLwHHyZ yzQb2gT5md4iFTS0iwjOwLoNLM52/2j8FHEhA6jFaiLJaMGTfgfWMSayLzJ3BeF3QdXNCLyHZNJUZ 6gGiZHxc1tGfwn6smsaBHMz6OD3GOUeoXoKHfsqJCJCaoPB5IEVrmGTmu9stqlNxWszoR/LZZUGFS Q0NrncQw==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.96 #2 (Red Hat Linux)) id 1s2gUn-009tNd-1D; Fri, 03 May 2024 00:09:49 +0000 Date: Fri, 3 May 2024 01:09:49 +0100 From: Al Viro To: Christoph Hellwig Cc: linux-fsdevel@vger.kernel.org, Yu Kuai , linux-block@vger.kernel.org, Christian Brauner , Jens Axboe Subject: [PATCH v2 5/8] bdev: move ->bd_write_holder into ->__bd_flags Message-ID: <20240503000949.GE2357260@ZenIV> References: <20240428051232.GU2118490@ZenIV> <20240429052315.GB32688@lst.de> <20240429073107.GZ2118490@ZenIV> <20240429170209.GA2118490@ZenIV> <20240429181300.GB2118490@ZenIV> <20240429183041.GC2118490@ZenIV> <20240503000647.GQ2118490@ZenIV> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20240503000647.GQ2118490@ZenIV> Sender: Al Viro Signed-off-by: Al Viro --- block/bdev.c | 9 +++++---- include/linux/blk_types.h | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/block/bdev.c b/block/bdev.c index 2ec223315500..9df9a59f0900 100644 --- a/block/bdev.c +++ b/block/bdev.c @@ -624,7 +624,7 @@ static void bd_end_claim(struct block_device *bdev, void *holder) bdev->bd_holder = NULL; bdev->bd_holder_ops = NULL; mutex_unlock(&bdev->bd_holder_lock); - if (bdev->bd_write_holder) + if (bdev_test_flag(bdev, BD_WRITE_HOLDER)) unblock = true; } if (!whole->bd_holders) @@ -640,7 +640,7 @@ static void bd_end_claim(struct block_device *bdev, void *holder) */ if (unblock) { disk_unblock_events(bdev->bd_disk); - bdev->bd_write_holder = false; + bdev_clear_flag(bdev, BD_WRITE_HOLDER); } } @@ -892,9 +892,10 @@ int bdev_open(struct block_device *bdev, blk_mode_t mode, void *holder, * writeable reference is too fragile given the way @mode is * used in blkdev_get/put(). */ - if ((mode & BLK_OPEN_WRITE) && !bdev->bd_write_holder && + if ((mode & BLK_OPEN_WRITE) && + !bdev_test_flag(bdev, BD_WRITE_HOLDER) && (disk->event_flags & DISK_EVENT_FLAG_BLOCK_ON_EXCL_WRITE)) { - bdev->bd_write_holder = true; + bdev_set_flag(bdev, BD_WRITE_HOLDER); unblock_events = false; } } diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h index f70dd31cbcd1..e45a490d488e 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -48,7 +48,7 @@ struct block_device { atomic_t __bd_flags; // partition number + flags #define BD_PARTNO 255 // lower 8 bits; assign-once #define BD_READ_ONLY (1u<<8) // read-only policy - bool bd_write_holder; +#define BD_WRITE_HOLDER (1u<<9) bool bd_has_submit_bio; dev_t bd_dev; struct inode *bd_inode; /* will die */ From patchwork Fri May 3 00:10:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Al Viro X-Patchwork-Id: 13652227 Received: from zeniv.linux.org.uk (zeniv.linux.org.uk [62.89.141.173]) (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 D2B87AD23; Fri, 3 May 2024 00:10:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=62.89.141.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714695026; cv=none; b=LC9bsIHDzZpq7umHugMjVwpNuTzHKI3XVn6KUOBOrxVTlpDxCok2CuAeNq/iue7+EZ2MYGIQs319uB98HAA4wUpmTvgYI16k/NG9Ulw0E6zZN5goqqhoFjd2Obwv/YdhzlDg6kp0fzM76q6ZHDmTrq1hq+0SU0GPgRELjtzp2dE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714695026; c=relaxed/simple; bh=a0/gi46X7y3jTzuYMVtk8CxDU9bN3SH73R3EnPynBN4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=b//7xzbqwDxPlfFumFHMGDLySUXlkxroB6ckjthrp/3+5glFcz/zy2nhKiXWNRiizu3mGasMQ7AgjXnoWey/aGqEGLyCEPJecbq9fNTpqf46RCuaNWDBTQ6Esw1ZVr/L4/Ya+8kxd8VO/AK7QQMki5Wehpp4R+eFx2hbb2y4/ZQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zeniv.linux.org.uk; spf=none smtp.mailfrom=ftp.linux.org.uk; dkim=pass (2048-bit key) header.d=linux.org.uk header.i=@linux.org.uk header.b=FLyhRQk0; arc=none smtp.client-ip=62.89.141.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zeniv.linux.org.uk Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=ftp.linux.org.uk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linux.org.uk header.i=@linux.org.uk header.b="FLyhRQk0" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=linux.org.uk; s=zeniv-20220401; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=hnUHDwXj43ZP3pn4nhfhUHKbkW/EIaViouUuR/zUvvQ=; b=FLyhRQk0SuesAp8ZfuH1ZS40GK ma+/xNeWkgwx1cJ82Hva7VMrXA30rkaz5Z5h59jC+n5hkiMlfXxOyM1QfhWa0aVza7evHEQZsevk7 mDKN3XV5kaELurrGp/+nodG96liN14HAxNxRc9WpDLfewWmKSdH/yRRZdps0ou5qCsaUcf3UquaDw s44M+WR6pzw6bFdlnop9vsIf6eRcSskHXoxgGtlnx80KpxZkY2oNIRJXBiXJGt9FgQ4hlHeRtnKnB /T7wdo8Nji0SQmgXkENdRQYxRdHL3nS/2X/u2wt35RCz8e3WkVbAjdPLk7sK5CNyk79k5HUELdV7u ZyWO7bEA==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.96 #2 (Red Hat Linux)) id 1s2gVK-009tPa-2V; Fri, 03 May 2024 00:10:23 +0000 Date: Fri, 3 May 2024 01:10:22 +0100 From: Al Viro To: Christoph Hellwig Cc: linux-fsdevel@vger.kernel.org, Yu Kuai , linux-block@vger.kernel.org, Christian Brauner , Jens Axboe Subject: [PATCH v2 6/8] bdev: move ->bd_has_subit_bio to ->__bd_flags Message-ID: <20240503001022.GF2357260@ZenIV> References: <20240428051232.GU2118490@ZenIV> <20240429052315.GB32688@lst.de> <20240429073107.GZ2118490@ZenIV> <20240429170209.GA2118490@ZenIV> <20240429181300.GB2118490@ZenIV> <20240429183041.GC2118490@ZenIV> <20240503000647.GQ2118490@ZenIV> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20240503000647.GQ2118490@ZenIV> Sender: Al Viro In bdev_alloc() we have all flags initialized to false, so assignment to ->bh_has_submit_bio n there is a no-op unless we have partno != 0 and flag already set on entire device. In device_add_disk() we have just allocated the block_device in question and it had been a full-device one, so the flag is guaranteed to be still clear when we get to assignment. Signed-off-by: Al Viro --- block/bdev.c | 6 ++---- block/blk-core.c | 4 ++-- block/genhd.c | 3 ++- include/linux/blk_types.h | 2 +- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/block/bdev.c b/block/bdev.c index 9df9a59f0900..fae30eae7741 100644 --- a/block/bdev.c +++ b/block/bdev.c @@ -414,10 +414,8 @@ struct block_device *bdev_alloc(struct gendisk *disk, u8 partno) atomic_set(&bdev->__bd_flags, partno); bdev->bd_inode = inode; bdev->bd_queue = disk->queue; - if (partno) - bdev->bd_has_submit_bio = disk->part0->bd_has_submit_bio; - else - bdev->bd_has_submit_bio = false; + if (partno && bdev_test_flag(disk->part0, BD_HAS_SUBMIT_BIO)) + bdev_set_flag(bdev, BD_HAS_SUBMIT_BIO); bdev->bd_stats = alloc_percpu(struct disk_stats); if (!bdev->bd_stats) { iput(inode); diff --git a/block/blk-core.c b/block/blk-core.c index 20322abc6082..f61460b65408 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -615,7 +615,7 @@ static void __submit_bio(struct bio *bio) if (unlikely(!blk_crypto_bio_prep(&bio))) return; - if (!bio->bi_bdev->bd_has_submit_bio) { + if (!bdev_test_flag(bio->bi_bdev, BD_HAS_SUBMIT_BIO)) { blk_mq_submit_bio(bio); } else if (likely(bio_queue_enter(bio) == 0)) { struct gendisk *disk = bio->bi_bdev->bd_disk; @@ -723,7 +723,7 @@ void submit_bio_noacct_nocheck(struct bio *bio) */ if (current->bio_list) bio_list_add(¤t->bio_list[0], bio); - else if (!bio->bi_bdev->bd_has_submit_bio) + else if (!bdev_test_flag(bio->bi_bdev, BD_HAS_SUBMIT_BIO)) __submit_bio_noacct_mq(bio); else __submit_bio_noacct(bio); diff --git a/block/genhd.c b/block/genhd.c index bb29a68e1d67..19cd1a31fa80 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -413,7 +413,8 @@ int __must_check device_add_disk(struct device *parent, struct gendisk *disk, elevator_init_mq(disk->queue); /* Mark bdev as having a submit_bio, if needed */ - disk->part0->bd_has_submit_bio = disk->fops->submit_bio != NULL; + if (disk->fops->submit_bio) + bdev_set_flag(disk->part0, BD_HAS_SUBMIT_BIO); /* * If the driver provides an explicit major number it also must provide diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h index e45a490d488e..11b9e8eeb79f 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -49,7 +49,7 @@ struct block_device { #define BD_PARTNO 255 // lower 8 bits; assign-once #define BD_READ_ONLY (1u<<8) // read-only policy #define BD_WRITE_HOLDER (1u<<9) - bool bd_has_submit_bio; +#define BD_HAS_SUBMIT_BIO (1u<<10) dev_t bd_dev; struct inode *bd_inode; /* will die */ From patchwork Fri May 3 00:10:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Al Viro X-Patchwork-Id: 13652228 Received: from zeniv.linux.org.uk (zeniv.linux.org.uk [62.89.141.173]) (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 CED3928E2; Fri, 3 May 2024 00:10:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=62.89.141.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714695057; cv=none; b=MUzIV6fEmmjfVUVQt+Fw7AZabw7I+XIoYCjcUE3YtIZB8Aw4J6X35yx6rckj0tW/TXRIQzULgWt1lj5kH/m9ZDGzYIxHelCEvnnWRVu6z2u8WF9/Z5ISViZqRZ9ECDHYiUR+9s9f6tE6wvpuEEgKo0iphF1TFR9fgTMHrOTnnp0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714695057; c=relaxed/simple; bh=keoWL2m8Qea8xblO7xycny8fY7XElzF3E63FokViYeE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=I5LPK8v/8O/McQLN4Dqz5W1zqtSZgYt82oSc4NTs3LD6isJ7kt7C6E6q8GG6jMcWpgxxnf2Ed4wcPMHoZ8Sx6RTA/SGUkhFdzIxmF6NQuH5A5fygTmh69gYTTRlbCC/sCBMEhkVYcIlaGl0A4hz0fGLMN56pvHFuJ+rzBR9OqKs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zeniv.linux.org.uk; spf=none smtp.mailfrom=ftp.linux.org.uk; dkim=pass (2048-bit key) header.d=linux.org.uk header.i=@linux.org.uk header.b=s4i+XSN/; arc=none smtp.client-ip=62.89.141.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zeniv.linux.org.uk Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=ftp.linux.org.uk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linux.org.uk header.i=@linux.org.uk header.b="s4i+XSN/" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=linux.org.uk; s=zeniv-20220401; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=ZxijnfJaPifRRMZKYO9oyk4tZfBPhRrsYWEdO2vC2g0=; b=s4i+XSN/1hUTbQpBQF2WmJeJSd tPY/1EbmoSJMEAzvzSccj0eP9Xd8g03OS3TmOVVhuTlCy9kgISl8DGhEiEgp4+xZfvOeVVhIxKtHV HyJ8KJpMkMA+J3c27quy+Q7WWD3NuskuKEWhItdziT9wCtXjUySFLbtJogIFHa3nrmihK9cCv7irE 0oWa8r0o7TtpGR480r7ymgYPg11AB0P95W+zz6LmhQqrSsl5D4ME3MDd1/ucaXeK10zbBpA6h4O0p N/H7etWoJLT6yvD8oCVnzdt7MRTtZ0f7FQqT7igQBvvFG4GHSlAfJACH9uphSpE/qH4x6diZAIPMw Ax9FXQWg==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.96 #2 (Red Hat Linux)) id 1s2gVp-009tRc-1f; Fri, 03 May 2024 00:10:53 +0000 Date: Fri, 3 May 2024 01:10:53 +0100 From: Al Viro To: Christoph Hellwig Cc: linux-fsdevel@vger.kernel.org, Yu Kuai , linux-block@vger.kernel.org, Christian Brauner , Jens Axboe Subject: [PATCH v2 7/8] bdev: move ->bd_ro_warned to ->__bd_flags Message-ID: <20240503001053.GG2357260@ZenIV> References: <20240428051232.GU2118490@ZenIV> <20240429052315.GB32688@lst.de> <20240429073107.GZ2118490@ZenIV> <20240429170209.GA2118490@ZenIV> <20240429181300.GB2118490@ZenIV> <20240429183041.GC2118490@ZenIV> <20240503000647.GQ2118490@ZenIV> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20240503000647.GQ2118490@ZenIV> Sender: Al Viro Signed-off-by: Al Viro --- block/blk-core.c | 5 +++-- include/linux/blk_types.h | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/block/blk-core.c b/block/blk-core.c index f61460b65408..1be49be9fac4 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -514,10 +514,11 @@ static inline void bio_check_ro(struct bio *bio) if (op_is_flush(bio->bi_opf) && !bio_sectors(bio)) return; - if (bio->bi_bdev->bd_ro_warned) + if (bdev_test_flag(bio->bi_bdev, BD_RO_WARNED)) return; - bio->bi_bdev->bd_ro_warned = true; + bdev_set_flag(bio->bi_bdev, BD_RO_WARNED); + /* * Use ioctl to set underlying disk of raid/dm to read-only * will trigger this. diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h index 11b9e8eeb79f..4e0c8785090c 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -50,6 +50,7 @@ struct block_device { #define BD_READ_ONLY (1u<<8) // read-only policy #define BD_WRITE_HOLDER (1u<<9) #define BD_HAS_SUBMIT_BIO (1u<<10) +#define BD_RO_WARNED (1u<<11) dev_t bd_dev; struct inode *bd_inode; /* will die */ @@ -69,7 +70,6 @@ struct block_device { #ifdef CONFIG_FAIL_MAKE_REQUEST bool bd_make_it_fail; #endif - bool bd_ro_warned; int bd_writers; /* * keep this out-of-line as it's both big and not needed in the fast From patchwork Fri May 3 00:11:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Al Viro X-Patchwork-Id: 13652231 Received: from zeniv.linux.org.uk (zeniv.linux.org.uk [62.89.141.173]) (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 900791FDA; Fri, 3 May 2024 00:11:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=62.89.141.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714695085; cv=none; b=I8bELIMmPv3NXq531fupUvdaCNdlIJUF5eazlCpDgEbBqI1BYpUe/x7kJrqn+ijdK870GLYACsmYnYuAKjS7a9EV4a5GR24o0pQ25Jp+JOKW/sVfAY2msGBHUGt2Xcp8YoMKPQZa2/N0/iHe3KJINtooX2vULiz924m2LdJb7qE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714695085; c=relaxed/simple; bh=ZY1QxZtFxBjgqUQAN0MaQZuTJkkcwvtB7mVOVYYdnFs=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=n8PxZSTee4R76CvRn6wfEb7aN0i3MXzEYV7drbyYoHHAUc0jCK2Ck1sY6XUI3tELal2Yg9/egBi8K2kVlUYNQfxNaecDZO0ccR5c5iU75wheDghTu60O1W6clrvRljAMWrRkdaNNBaf02wD1l+lXmm1UhYTDzLQAI4iZrO0cZhk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zeniv.linux.org.uk; spf=none smtp.mailfrom=ftp.linux.org.uk; dkim=pass (2048-bit key) header.d=linux.org.uk header.i=@linux.org.uk header.b=cxaZe8Cr; arc=none smtp.client-ip=62.89.141.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zeniv.linux.org.uk Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=ftp.linux.org.uk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linux.org.uk header.i=@linux.org.uk header.b="cxaZe8Cr" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=linux.org.uk; s=zeniv-20220401; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=0SS3sTlKK63HL5RcSUatqvwGfSVEL8pnEtH16W529JQ=; b=cxaZe8Cr4qs2myGPzGFUFUVWqZ BRKydz0L060gD+SyJY4gBg2ynwI8EFO5wFzksmb0XwG+zsOZfBul/GGp7QANFuJyTX0q9TS8ueU92 wY3Qf/bdaOcR4CYtxUuEA2zw1Orun3m66ZpWY6rRcc6Q1RzVMRg+qWaBRkuW1thXSq+cQX8S2RNdu e7u4o5T7mDff48NBhzSp2M4yUsV/9E/2zm+w9RcMoSAZsaTcjPSpTOvRa8MxjHlI6YdFwZ8tQ4Kvt U3iItwQdcfDLKEg9B2Vaab0SFVWdp65bi1PYSr0dBuJ5mvi+g2DwnmTE3DJhEkxHOjEbe8GHJrb+E Wv2NDKVQ==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.96 #2 (Red Hat Linux)) id 1s2gWI-009tTS-39; Fri, 03 May 2024 00:11:23 +0000 Date: Fri, 3 May 2024 01:11:22 +0100 From: Al Viro To: Christoph Hellwig Cc: linux-fsdevel@vger.kernel.org, Yu Kuai , linux-block@vger.kernel.org, Christian Brauner , Jens Axboe Subject: [PATCH v2 8/8] bdev: move ->bd_make_it_fail to ->__bd_flags Message-ID: <20240503001122.GH2357260@ZenIV> References: <20240428051232.GU2118490@ZenIV> <20240429052315.GB32688@lst.de> <20240429073107.GZ2118490@ZenIV> <20240429170209.GA2118490@ZenIV> <20240429181300.GB2118490@ZenIV> <20240429183041.GC2118490@ZenIV> <20240503000647.GQ2118490@ZenIV> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20240503000647.GQ2118490@ZenIV> Sender: Al Viro Signed-off-by: Al Viro --- block/blk-core.c | 3 ++- block/genhd.c | 12 ++++++++---- include/linux/blk_types.h | 6 +++--- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/block/blk-core.c b/block/blk-core.c index 1be49be9fac4..1076336dd620 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -494,7 +494,8 @@ __setup("fail_make_request=", setup_fail_make_request); bool should_fail_request(struct block_device *part, unsigned int bytes) { - return part->bd_make_it_fail && should_fail(&fail_make_request, bytes); + return bdev_test_flag(part, BD_MAKE_IT_FAIL) && + should_fail(&fail_make_request, bytes); } static int __init fail_make_request_debugfs(void) diff --git a/block/genhd.c b/block/genhd.c index 19cd1a31fa80..0cce461952f6 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -1066,7 +1066,8 @@ static DEVICE_ATTR(diskseq, 0444, diskseq_show, NULL); ssize_t part_fail_show(struct device *dev, struct device_attribute *attr, char *buf) { - return sprintf(buf, "%d\n", dev_to_bdev(dev)->bd_make_it_fail); + return sprintf(buf, "%d\n", + bdev_test_flag(dev_to_bdev(dev), BD_MAKE_IT_FAIL)); } ssize_t part_fail_store(struct device *dev, @@ -1075,9 +1076,12 @@ ssize_t part_fail_store(struct device *dev, { int i; - if (count > 0 && sscanf(buf, "%d", &i) > 0) - dev_to_bdev(dev)->bd_make_it_fail = i; - + if (count > 0 && sscanf(buf, "%d", &i) > 0) { + if (i) + bdev_set_flag(dev_to_bdev(dev), BD_MAKE_IT_FAIL); + else + bdev_clear_flag(dev_to_bdev(dev), BD_MAKE_IT_FAIL); + } return count; } diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h index 4e0c8785090c..5bb7805927ac 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -51,6 +51,9 @@ struct block_device { #define BD_WRITE_HOLDER (1u<<9) #define BD_HAS_SUBMIT_BIO (1u<<10) #define BD_RO_WARNED (1u<<11) +#ifdef CONFIG_FAIL_MAKE_REQUEST +#define BD_MAKE_IT_FAIL (1u<<12) +#endif dev_t bd_dev; struct inode *bd_inode; /* will die */ @@ -67,9 +70,6 @@ struct block_device { struct mutex bd_fsfreeze_mutex; /* serialize freeze/thaw */ struct partition_meta_info *bd_meta_info; -#ifdef CONFIG_FAIL_MAKE_REQUEST - bool bd_make_it_fail; -#endif int bd_writers; /* * keep this out-of-line as it's both big and not needed in the fast