From patchwork Sun Apr 28 05:14:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Al Viro X-Patchwork-Id: 13645849 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 9E305321D; Sun, 28 Apr 2024 05:14:20 +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=1714281262; cv=none; b=N82d8qBnrkwqcSfXlAKo2nv4zv6+1GF3VELAm67vRDQz3uK4vv1bxtlHfnfJ2oW1pArfU6qqSvu07IqiH11vAEAVeHvgU2BJmIuYQBtBj680jHV7+/9UxKNaXWzF6BYGZV3tMF7EmGiu9L1IZ9nMi3uFqrkTfcX2yt6N/fK1FJs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714281262; c=relaxed/simple; bh=vQNaJRrJFrPBj/Dg76/OdGcf68/bXLwjvoY8PfjhDFg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=UU31HJE1KDwhfn3GFWRh3drqHDeJy0J5exNNPTutoEpXRpLjEB82HNHQIMNR3QiQuHJph9pkoXeoijhu4kAe9oi3+rs473BPqiXBGApCLzbOBsDMWmXK7xU4VWv+znTr9B5V9JN2X1kNyEVzPgbw5l9Qdvnq1eYf8FLEWeF5bgM= 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=cMW4/Res; 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="cMW4/Res" 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=PesFYtl58EzSLjZSdfcbgZBJojO53J2jqBqANYh4gVE=; b=cMW4/ResqEC6crdXAo3VeCvOTl d/GeVrede3okbTUwFk+7TGkmeZ8YKAtQWYOPRqcohgVkoISiFpsLouFMLSqsi7MKmjR2b3t70K4wl 5Xp/oaw3yc6BpywXX1O3v/Y2pw1+AK7nT46+jKeKe1NfMZmqUxF5jxZMkDvBWEhRGi0oGi8J/mhwZ KPOzxFkYCSoc0xHRivN2P4bSZwHefXXMiZoJC2kkmFQTgRZFw15BVncSpFDTQGf+gjkwfL6xqKDNo EFqyjS9FXTYYG3YJToDGO8/15+UVJfTeq7fLDS0Gq9I4afHtrV9n+BG1xC907XGOFfs8GQ+HdNNm4 MRxYrFMw==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.96 #2 (Red Hat Linux)) id 1s0wri-006VCo-1F; Sun, 28 Apr 2024 05:14:18 +0000 Date: Sun, 28 Apr 2024 06:14:18 +0100 From: Al Viro To: linux-fsdevel@vger.kernel.org Cc: Yu Kuai , linux-block@vger.kernel.org, Christian Brauner , Christoph Hellwig , Jens Axboe Subject: [PATCH 1/8] Use bdev_is_paritition() instead of open-coding it Message-ID: <20240428051418.GA1549798@ZenIV> References: <20240428051232.GU2118490@ZenIV> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20240428051232.GU2118490@ZenIV> Sender: Al Viro Signed-off-by: Al Viro Reviewed-by: Christoph Hellwig --- 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 Sun Apr 28 05:15: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: 13645850 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 80F07320C; Sun, 28 Apr 2024 05:15:23 +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=1714281325; cv=none; b=O5ne7aSVQXmhrfv8S/T1vnrCxCoJzwBJZIpeC1CCIS9oKPp3YoNgPRTdXBbPgNY79U5LaAcEOHXBzxTM66aPsmUDWO7G6xlnx9KDuebh4UJYyDUyo4x/jDfsw4WVoi9BRDa0hO5PbQqokpUMyLURZGktz3Hpd0XqOq25V+SX9ok= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714281325; 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=M34K70NghlGbVdX4zxI2IZhU+whiIuL8rVPFYrrQXamYHuZLcJa5j6xeyin/UuJfF0s+4duzlMObjidXP7GMU0D02B+U35GONedlYPrdFGSfbz9K8ZG7n/UPNoxZXACwtqRpVr/iYtr3k+qjiq142K1qP7ziEw6i4aWxgKQQApw= 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=fq888ksi; 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="fq888ksi" 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=fq888ksi5kylQAv/AsKVOZjZU+ khu1WYK8l37tQp+GncHkABmBK6OezQeYPJfdC26jlYv+/Lfgwj/67Gjdxitgg7X3O6j/1TylMnj4r TU7YrTFxlHLdBytKofJwgmbsdnAysXYlgn+V/67tSIc4wdz7CKiSzQy+yCDB9O6lqXD5+rTqpPAg+ ndqwqZoCdMEX1Fr7LcDJJevTtBQ3CNPsPnKlN/mnSlekL3uHith0KIvic+aVjw8vWzgD0xdVP0FYC KnHt9RRQi00P4Vzv/VIJPJSEez4kkdbeiLaacyCBjD8dob+Wdzx84uk1i/G1/eNRuKm5AXTgPpoT9 HZjJWm9Q==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.96 #2 (Red Hat Linux)) id 1s0wsk-006VFd-0H; Sun, 28 Apr 2024 05:15:22 +0000 Date: Sun, 28 Apr 2024 06:15:22 +0100 From: Al Viro To: linux-fsdevel@vger.kernel.org Cc: Yu Kuai , linux-block@vger.kernel.org, Christian Brauner , Christoph Hellwig , Jens Axboe Subject: [PATCH 2/8] wrapper for access to ->bd_partno Message-ID: <20240428051522.GB1549798@ZenIV> References: <20240428051232.GU2118490@ZenIV> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20240428051232.GU2118490@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 Sun Apr 28 05:16:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Al Viro X-Patchwork-Id: 13645853 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 BBC4A321D; Sun, 28 Apr 2024 05:16:22 +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=1714281384; cv=none; b=klBXkzAeAEdEdwLTVqq6VXnnfRrbMias+sD0BzdS07Ejo4V+g1BNN/GY9uNwEyOl/TOQCBGRhbwoTcvTdZ8EUXY6+bj3bzukG430Pj7zYKfTCgS+SMPkaji8enN/Ax9m01OL/7S3ySESap6EektLFAyDAYTsvBdLR8TrD2x9hOU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714281384; c=relaxed/simple; bh=q0RAssYWsvGYCQEhxffMOxjxrhMhIBZbvWOAYDWsB+c=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=YVafpBfNnOr7Cs/BRkm7/oMdKXC3mCkV49sTSVxoCD6j5aT2vQIKfHPVpZIANCxtpgfX19/ywpbi5e/3iFWs374GLd2tO2qT3InQuycqSFOKvSAfYrURv2LVz/D7q3TkSuEzORfuiFmkrQhwEDypgt47y2LrgrWWoPsvbn3WwLQ= 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=hMrBQnLU; 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="hMrBQnLU" 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=pa27QOZhgTYyjdTX6K9oFf7IjSK8d/+qozIJWisXWV0=; b=hMrBQnLU5MFUWkpUtzCSjw9U+F vze8lDtnckLgJuXdAWEj+ZJrABZ6L5a07rBHGDeVPE+ANvU6p5dVZ0ocO2iHShvVtI6ThIXtKUbgp ZzajvdfPtOxvuBC6wtIZ+Oe+LuswR3kgFB8ByIlZSSK2nR0FHauDA3jdqmNm1HEH1ol0GNnumRTWy zTVUFSj6ANLsvEKYiLGBxTM9GJqcL5S4GCnivwLjYFneSbf1Kh66TpQE8pCwk5dXVqKpIwVZVvIIY 3InOlQA8XdXX/eVPZwyuPXygPtGMHXnWQlqeG0coQO7oAnaU62ZouVCITs5PS0qQdOdHx9CCRZRAS NfkmFxCA==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.96 #2 (Red Hat Linux)) id 1s0wtg-006VIB-3B; Sun, 28 Apr 2024 05:16:21 +0000 Date: Sun, 28 Apr 2024 06:16:20 +0100 From: Al Viro To: linux-fsdevel@vger.kernel.org Cc: Yu Kuai , linux-block@vger.kernel.org, Christian Brauner , Christoph Hellwig , Jens Axboe Subject: [PATCH 3/8] bdev: infrastructure for flags Message-ID: <20240428051620.GC1549798@ZenIV> References: <20240428051232.GU2118490@ZenIV> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20240428051232.GU2118490@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), where flag numbers are zero-based. Use cmpxchg() to set/clear - all architectures support it for u32. NOTE: this commit does not actuall 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 | 2 +- include/linux/blkdev.h | 33 ++++++++++++++++++++++++++++++++- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/block/bdev.c b/block/bdev.c index 7a5f611c3d2e..0c55f7abaac3 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; + 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..274f7eb4138f 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -45,8 +45,8 @@ struct block_device { struct request_queue * bd_queue; struct disk_stats __percpu *bd_stats; unsigned long bd_stamp; + u32 __bd_flags; // partition number + flags 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..b9dbfb811533 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -722,7 +722,38 @@ 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 bdev->__bd_flags & 0xff; +} + +static inline bool bdev_test_flag(const struct block_device *bdev, int flag) +{ + return bdev->__bd_flags & (1 << (flag + 8)); +} + +static inline void bdev_set_flag(struct block_device *bdev, int flag) +{ + u32 v = bdev->__bd_flags; + + for (;;) { + u32 w = cmpxchg(&bdev->__bd_flags, v, v | (1 << (flag + 8))); + + if (v == w) + return; + v = w; + } +} + +static inline void bdev_clear_flag(struct block_device *bdev, int flag) +{ + u32 v = bdev->__bd_flags; + + for (;;) { + u32 w = cmpxchg(&bdev->__bd_flags, v, v & ~(1 << (flag + 8))); + + if (v == w) + return; + v = w; + } } static inline int get_disk_ro(struct gendisk *disk) From patchwork Sun Apr 28 05:17:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Al Viro X-Patchwork-Id: 13645854 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 62C7C320C; Sun, 28 Apr 2024 05:17: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=1714281449; cv=none; b=kc9rcLLgOWMdZvQH51/DAEYASA49fCcc2SFs0iBdzIhfpR0L1JtBuMbDswZ7MQYhhYrV5uNg23UQuH49AdPS3VgpbrWTu1JGI9OMPrjhJuI6tzX7OnGl/ZuSOI15WCpyWBEFberd4w8zaf6XNtFUGofEjmk4z4fmkO8JGiXBxRM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714281449; c=relaxed/simple; bh=+BLcWJoCEy6Lcy7oq8TS69eqNomO12mqU0xRquEsrYU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=qpAp4BL0DOpvn1Da/Gt0olBkYkZHgWQ73QyYFYp+9M4lfOaCinOXcU7AvsYc1ZS00gdd0vQliyOtw8FGzsxOhVyrgMiH68F/YsYzKyPHmblvm95FrvUJk35sldzl1UOKhc3kl9Xc4vBAXRt3F7RSNFT2+yKVyGKZb9r+uHl7Zi8= 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=dZX9cYZo; 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="dZX9cYZo" 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=S4nF/w/dYVCfQoFNcFEm8mUpsqd4FCdsG1qHmSeVg+s=; b=dZX9cYZo5ltwl6wfk1EwmZ+KHK chQ9A7R9oBQdhzaqhn9N7As5xwxdSD2CAa9oFbhCiWqxWH716NKsdYuKl64dWVlEVvRcrqK3gP+iw Nm6e4VSIU+tLcVu0iRkKPAhpkMKtMaS8T7ZMVHhouaxiY0CYmdcQfPNhiZL5qYPRcTAuB0jHQpZ8E 8Y5i5SVxwSa5SpF0sfAMM26jnS0pjLPNf+gbmEdxhO4nxxFlLqh7vYvSCoBAWy1fVv8KeiZqOodS/ pILSld896lWMAaFI1iON6MlVOfgNglZgrHqvnQuCTEtGMi3A97I/OOwd4gfySJV1pgZeyshNJavp1 hBKoijvQ==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.96 #2 (Red Hat Linux)) id 1s0wui-006VKS-1l; Sun, 28 Apr 2024 05:17:24 +0000 Date: Sun, 28 Apr 2024 06:17:24 +0100 From: Al Viro To: linux-fsdevel@vger.kernel.org Cc: Yu Kuai , linux-block@vger.kernel.org, Christian Brauner , Christoph Hellwig , Jens Axboe Subject: [PATCH 4/8] bdev: move ->bd_read_only to ->__bd_flags Message-ID: <20240428051724.GD1549798@ZenIV> References: <20240428051232.GU2118490@ZenIV> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20240428051232.GU2118490@ZenIV> Sender: Al Viro Signed-off-by: Al Viro --- block/ioctl.c | 5 ++++- include/linux/blk_types.h | 5 ++++- include/linux/blkdev.h | 4 ++-- 3 files changed, 10 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 274f7eb4138f..1aa41b651614 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -46,7 +46,6 @@ struct block_device { struct disk_stats __percpu *bd_stats; unsigned long bd_stamp; u32 __bd_flags; // partition number + flags - bool bd_read_only; /* read-only policy */ bool bd_write_holder; bool bd_has_submit_bio; dev_t bd_dev; @@ -86,6 +85,10 @@ struct block_device { #define bdev_kobj(_bdev) \ (&((_bdev)->bd_device.kobj)) +enum { + BD_READ_ONLY, // read-only policy +}; + /* * Block error status values. See block/blk-core:blk_errors for the details. * Alpha cannot write a byte atomically, so we need to use 32-bit value. diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index b9dbfb811533..d556cec9224b 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -758,13 +758,13 @@ static inline void bdev_clear_flag(struct block_device *bdev, int 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 Sun Apr 28 05:18: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: 13645855 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 15706320C; Sun, 28 Apr 2024 05:18: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=1714281496; cv=none; b=rYMNIg9849osUpEsWOR21svgykbrRoU6rQgUWsAjXkZ3hdF5cEeSPZ4i3heJjW9m/Ru+XN4GczWJQJkklVlqQW8JNGUoP1S/Kv/I0EO6vNxtmYT7F2MgfafakbcHZr9tV1G3OqfaI9sbUjg1qQZX/H3A2pzPvUC7aRq4PU1je0c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714281496; c=relaxed/simple; bh=7azFLDepGw3EjAQD9Jh6qJavhTc0jsWETc+eaETwr2E=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Rj/VNHSaStkBcb8xJnOpm/LUxHzN74nr9U3Fk252JFhhExZKAirKf2huR72C0R/sPOQa7p2h5x7JynXNoEOAdrrd1VOhhdydTEepPzWhJu+MGjGZFsf8zrOza94RYkhKXm6/e5P1uuQG0umakepvpAYH5vuCecmRJsyK2dp4n3Q= 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=HPwhaHMK; 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="HPwhaHMK" 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=uqvEx6sEC2MY3wKLQdNGpDvZ1tI9w1QriUWIELjqFzk=; b=HPwhaHMK2VIivTTbFP/1WgMOXL ijwZhUDe6bVj60efteSRpUbB1ruaU6S6ZxKTMQYHnn06rVHH2ltRosnGcNhVuo33ntkoZ1iYWq6JR u9WEbrw9ZBVXzzDrd5wfOdvKKMnMA/cPwm75hnIeWm34YoMOxy3mCDzVqpKe5PU1ypSNagOXU7Qwx 7+iUlgZkAgjLx3T2EMlvzKE6RUNO0dvQl5FwUTpC0tN9Mw5L+OHecVtP4wmzl6OmslRgctfwLf7Hv Ppg3EHFHgSecgbHhAx8cPvFqcR3VwTPZndlL3GkUiewkapqrPQiZrTk/BFshznWcWvZLkc94Y8iSX ehpALhow==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.96 #2 (Red Hat Linux)) id 1s0wvV-006VML-0F; Sun, 28 Apr 2024 05:18:13 +0000 Date: Sun, 28 Apr 2024 06:18:13 +0100 From: Al Viro To: linux-fsdevel@vger.kernel.org Cc: Yu Kuai , linux-block@vger.kernel.org, Christian Brauner , Christoph Hellwig , Jens Axboe Subject: [PATCH 5/8] bdev: move ->bd_write_holder into ->__bd_flags Message-ID: <20240428051813.GE1549798@ZenIV> References: <20240428051232.GU2118490@ZenIV> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20240428051232.GU2118490@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 0c55f7abaac3..24c1dd6de8a9 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 1aa41b651614..8a336053b5fa 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -46,7 +46,6 @@ struct block_device { struct disk_stats __percpu *bd_stats; unsigned long bd_stamp; u32 __bd_flags; // partition number + flags - bool bd_write_holder; bool bd_has_submit_bio; dev_t bd_dev; struct inode *bd_inode; /* will die */ @@ -87,6 +86,7 @@ struct block_device { enum { BD_READ_ONLY, // read-only policy + BD_WRITE_HOLDER, }; /* From patchwork Sun Apr 28 05:19:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Al Viro X-Patchwork-Id: 13645856 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 B81973C28; Sun, 28 Apr 2024 05:19:02 +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=1714281544; cv=none; b=JKqklUHTmekFhIh01tuY6SmEimUihMrxITlxfIcTdyAi8OTPW0c0vL2/a0ZFiCVsYf+QHZE+bmERw3y0IhkPTuo9Sfxbzw1qJNTHgXN+7oQwVsfG8ErTZZR510EAgefIVoHyFCSSyTg/oPQSCYmy0AIKxI8hWaN2FR9/1HmWAcQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714281544; c=relaxed/simple; bh=wM+0OgGZu8hO2Fn+GCnfnseFlCFqVn7dQHD0jDuyZaY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=oXHJJ7ZJKLQsa469QDHM9I8G0InBBZR4lfi+UDNR0k2sVyDOqHONrZW7HzCHtbM+c13P5OApuUSPxoopZXZyinJWYki3STP8Kg+bl5ZfsaqWUDP+ypYZ0bTX+zApGA/qlRbASZfryUQ3vWfbFN7SJicuVaOh9K4x7MUXzVJ3nWA= 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=jshJ5KR1; 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="jshJ5KR1" 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=MXOTJZGYGgFux0gWx+fGk+GxPTBkFmwMjosjPL6WUqE=; b=jshJ5KR18qEcPTGWXNFdPniy6t MQd5toYF32OwJEY3VvCyZtjhHl9n/ChAVXO5hrGzhZPABEXTPOjimbJlFUZQqk3be//Sney7bfUVY 8nK190XkeTCLIBYp+K6doYvq8uSooesSmD6fueFHVLJLwSipM7OiAq6uyoj+R3iHvMnrw+4Qig4uk UcDgUNmy/z36FI5u+N5YQPwWNXBXpY4kNW2bmei/rpjsB+36eM5idzdBUqAHwoEdoWXxqC+tXAGKx s05jhHkIxtrg2MaWF5SnHj9W7szjc9mvoSeekqKRP+dWNReVaiaGUMTv8P8tNI0MwPuVxCntwNYJF WwExfzQg==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.96 #2 (Red Hat Linux)) id 1s0wwG-006VOF-30; Sun, 28 Apr 2024 05:19:01 +0000 Date: Sun, 28 Apr 2024 06:19:00 +0100 From: Al Viro To: linux-fsdevel@vger.kernel.org Cc: Yu Kuai , linux-block@vger.kernel.org, Christian Brauner , Christoph Hellwig , Jens Axboe Subject: [PATCH 6/8] bdev: move ->bd_has_subit_bio to ->__bd_flags Message-ID: <20240428051900.GF1549798@ZenIV> References: <20240428051232.GU2118490@ZenIV> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20240428051232.GU2118490@ZenIV> Sender: Al Viro 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 24c1dd6de8a9..9aa23620fe92 100644 --- a/block/bdev.c +++ b/block/bdev.c @@ -414,10 +414,8 @@ struct block_device *bdev_alloc(struct gendisk *disk, u8 partno) 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 8a336053b5fa..c8f5364b24f1 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -46,7 +46,6 @@ struct block_device { struct disk_stats __percpu *bd_stats; unsigned long bd_stamp; u32 __bd_flags; // partition number + flags - bool bd_has_submit_bio; dev_t bd_dev; struct inode *bd_inode; /* will die */ @@ -87,6 +86,7 @@ struct block_device { enum { BD_READ_ONLY, // read-only policy BD_WRITE_HOLDER, + BD_HAS_SUBMIT_BIO, }; /* From patchwork Sun Apr 28 05:19:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Al Viro X-Patchwork-Id: 13645857 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 0D0BE320C; Sun, 28 Apr 2024 05:19:41 +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=1714281583; cv=none; b=H34i/ITRk/Ns9yZHAq5hytN4WMth+g97msy63eHEVVzE6dO2kcgUZ3egxN71o360fqbMHjzf6T8pSFRNbhizsm/5SjCw8+N4c3VcdcWO7+S/f3Hv7XyQQ7XS0ddbYJ7vChlV/Z9z9t+PS/59q6yzy+oQvq4bixACExiV9zNMqd4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714281583; c=relaxed/simple; bh=5aNW/JcDN2+X23Bke8nP2Qy4FDcNgexCJHLMUNXkqpg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=X4knXcJHZJ7WvVpVAeftpmqbNmISrat2p0WludT2M2UAkHmGRNnn6EQkiJPa2cpREoTHO3qucvQ5Wey7tQfvACFc5VBh7SOkNugdq8jjGuPgG1FffUCwvfcW0+xtMXDdC+e7s6lvmwhF0AKTERQNNyie9XfELNpDbsLxsMd1ZbY= 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=vHE07jo1; 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="vHE07jo1" 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=AjleHgbiW4gZwTUlHqCfArxk8aQfvqZ3X8uYfRsghBk=; b=vHE07jo16YpQU9BtXSstG2BEjE O4/NzT7wYkzwjYa76X+wvD3kZLjqgnpPX9UGy8BX3PSa+bRV2DdqZC6Lcf6cm4jnxBH76AKdrbXt0 yz3tYzwURdtQHowGYmu6nej58/gukHi8yU5F7QZPeqd3Q6UOZm+7wmV+evxOWiqoWjSnEY+lKndU9 kL4sXXoTdysnE8Th0o9jI2hNSc/eN1XECPjiFKXtMLrezXxCHi9nMBXvnb5CPEcFlEnkpgyQCuAGo Bg/YF2pIPmMSNMHrkiH8bZNs92I4vUQG8eBbh1iH0aG7I5S6HetYaSayDbcyfOBD3H/OOVm6irP1v DyamXTdw==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.96 #2 (Red Hat Linux)) id 1s0wwu-006VPg-0c; Sun, 28 Apr 2024 05:19:40 +0000 Date: Sun, 28 Apr 2024 06:19:40 +0100 From: Al Viro To: linux-fsdevel@vger.kernel.org Cc: Yu Kuai , linux-block@vger.kernel.org, Christian Brauner , Christoph Hellwig , Jens Axboe Subject: [PATCH 7/8] bdev: move ->bd_ro_warned to ->__bd_flags Message-ID: <20240428051940.GG1549798@ZenIV> References: <20240428051232.GU2118490@ZenIV> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20240428051232.GU2118490@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 c8f5364b24f1..59de93913cc4 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -65,7 +65,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 @@ -87,6 +86,7 @@ enum { BD_READ_ONLY, // read-only policy BD_WRITE_HOLDER, BD_HAS_SUBMIT_BIO, + BD_RO_WARNED, }; /* From patchwork Sun Apr 28 05:21:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Al Viro X-Patchwork-Id: 13645863 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 C692C320C; Sun, 28 Apr 2024 05:21:07 +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=1714281669; cv=none; b=Xb8qR4liojazXd15wvDEv2kSSqdj9vFtZbRQG645TP9IYF7PD5VWNupZ3vJY4ogomfX0amsPlx395qK7bkf8GQhovouEeHeWvMjKhs8YrSPerchDAIFZaBd44pFeOx6xXw7ZU6UDYSbc1h8NSer4DXw1NG44JH3Uec7JUhadInQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714281669; c=relaxed/simple; bh=8ZcnS8b0PNCfVGXzTKij4oQxakJ6aMqGuUG1wToqsrY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=VfosN0EBMChilFn1ZQUjXw/OdDyX44TQ6cCALm5nzVHipS6c2/vL+Ye0kjSGwe2g9+hvWprQOM45tc+R5HHgoJZ5xqB7sGStzMUSxlPGk2iT8Ygr7CsWkm8VqKVeOdpRbx2h8gpQ57qBV5X+RzLuZr4UahqtGjhee8DZo5CpTEI= 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=I+S0MGPk; 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="I+S0MGPk" 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=WJhjreZ4/O1HDJ0IIl3pZkSWylZry442LChV7Q1j9Qw=; b=I+S0MGPkV7JU2xQhB5RVq/zz53 QdkOy2mQV73hfCCA44UhZVbqqvFoHnxZMX+sR8OxFLI+2Mmac6sOgnzryxVznSqCoTytLKURa5IDi RBRDWN5/Wen8OAdetOfW4HObyXY0YIYaiJ3qUOuIQ623bij5hKgrR72XZ5SS1xw6/ZsfjVpk8Em3W By5gcWuXd+tqjQ4WOCQEy8FIgUCq4Is3zoD/iFjZp4fvWoCdD3CHbJWmsP9apZOWfz3Bky2k6hzPT eZodscQER1PHxpaCey6YG4IjjoWMnWbbUQTRaoMzo/uqBVkTYUMHbUS+phywAP894uIy9CQC6wWg5 np19HTwA==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.96 #2 (Red Hat Linux)) id 1s0wyI-006VT5-0U; Sun, 28 Apr 2024 05:21:06 +0000 Date: Sun, 28 Apr 2024 06:21:06 +0100 From: Al Viro To: linux-fsdevel@vger.kernel.org Cc: Yu Kuai , linux-block@vger.kernel.org, Christian Brauner , Christoph Hellwig , Jens Axboe Subject: [PATCH 8/8] bdev: move ->bd_make_it_fail to ->__bd_flags Message-ID: <20240428052106.GH1549798@ZenIV> References: <20240428051232.GU2118490@ZenIV> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20240428051232.GU2118490@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 59de93913cc4..98e1c2d28d60 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -62,9 +62,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 @@ -87,6 +84,9 @@ enum { BD_WRITE_HOLDER, BD_HAS_SUBMIT_BIO, BD_RO_WARNED, +#ifdef CONFIG_FAIL_MAKE_REQUEST + BD_MAKE_IT_FAIL, +#endif }; /*