Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'pull-bd_flags-2' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs

Pull bdev flags update from Al Viro:
"Compactifying bdev flags.

We can easily have up to 24 flags with sane atomicity, _without_
pushing anything out of the first cacheline of struct block_device"

* tag 'pull-bd_flags-2' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs:
bdev: move ->bd_make_it_fail to ->__bd_flags
bdev: move ->bd_ro_warned to ->__bd_flags
bdev: move ->bd_has_subit_bio to ->__bd_flags
bdev: move ->bd_write_holder into ->__bd_flags
bdev: move ->bd_read_only to ->__bd_flags
bdev: infrastructure for flags
wrapper for access to ->bd_partno
Use bdev_is_paritition() instead of open-coding it

+77 -46
+8 -9
block/bdev.c
··· 422 422 mutex_init(&bdev->bd_fsfreeze_mutex); 423 423 spin_lock_init(&bdev->bd_size_lock); 424 424 mutex_init(&bdev->bd_holder_lock); 425 - bdev->bd_partno = partno; 425 + atomic_set(&bdev->__bd_flags, partno); 426 426 bdev->bd_mapping = &inode->i_data; 427 427 bdev->bd_queue = disk->queue; 428 - if (partno) 429 - bdev->bd_has_submit_bio = disk->part0->bd_has_submit_bio; 430 - else 431 - bdev->bd_has_submit_bio = false; 428 + if (partno && bdev_test_flag(disk->part0, BD_HAS_SUBMIT_BIO)) 429 + bdev_set_flag(bdev, BD_HAS_SUBMIT_BIO); 432 430 bdev->bd_stats = alloc_percpu(struct disk_stats); 433 431 if (!bdev->bd_stats) { 434 432 iput(inode); ··· 640 642 bdev->bd_holder = NULL; 641 643 bdev->bd_holder_ops = NULL; 642 644 mutex_unlock(&bdev->bd_holder_lock); 643 - if (bdev->bd_write_holder) 645 + if (bdev_test_flag(bdev, BD_WRITE_HOLDER)) 644 646 unblock = true; 645 647 } 646 648 if (!whole->bd_holders) ··· 653 655 */ 654 656 if (unblock) { 655 657 disk_unblock_events(bdev->bd_disk); 656 - bdev->bd_write_holder = false; 658 + bdev_clear_flag(bdev, BD_WRITE_HOLDER); 657 659 } 658 660 } 659 661 ··· 920 922 * writeable reference is too fragile given the way @mode is 921 923 * used in blkdev_get/put(). 922 924 */ 923 - if ((mode & BLK_OPEN_WRITE) && !bdev->bd_write_holder && 925 + if ((mode & BLK_OPEN_WRITE) && 926 + !bdev_test_flag(bdev, BD_WRITE_HOLDER) && 924 927 (disk->event_flags & DISK_EVENT_FLAG_BLOCK_ON_EXCL_WRITE)) { 925 - bdev->bd_write_holder = true; 928 + bdev_set_flag(bdev, BD_WRITE_HOLDER); 926 929 unblock_events = false; 927 930 } 928 931 }
+10 -7
block/blk-core.c
··· 496 496 497 497 bool should_fail_request(struct block_device *part, unsigned int bytes) 498 498 { 499 - return part->bd_make_it_fail && should_fail(&fail_make_request, bytes); 499 + return bdev_test_flag(part, BD_MAKE_IT_FAIL) && 500 + should_fail(&fail_make_request, bytes); 500 501 } 501 502 502 503 static int __init fail_make_request_debugfs(void) ··· 517 516 if (op_is_flush(bio->bi_opf) && !bio_sectors(bio)) 518 517 return; 519 518 520 - if (bio->bi_bdev->bd_ro_warned) 519 + if (bdev_test_flag(bio->bi_bdev, BD_RO_WARNED)) 521 520 return; 522 521 523 - bio->bi_bdev->bd_ro_warned = true; 522 + bdev_set_flag(bio->bi_bdev, BD_RO_WARNED); 523 + 524 524 /* 525 525 * Use ioctl to set underlying disk of raid/dm to read-only 526 526 * will trigger this. ··· 618 616 if (unlikely(!blk_crypto_bio_prep(&bio))) 619 617 return; 620 618 621 - if (!bio->bi_bdev->bd_has_submit_bio) { 619 + if (!bdev_test_flag(bio->bi_bdev, BD_HAS_SUBMIT_BIO)) { 622 620 blk_mq_submit_bio(bio); 623 621 } else if (likely(bio_queue_enter(bio) == 0)) { 624 622 struct gendisk *disk = bio->bi_bdev->bd_disk; ··· 732 730 */ 733 731 if (current->bio_list) 734 732 bio_list_add(&current->bio_list[0], bio); 735 - else if (!bio->bi_bdev->bd_has_submit_bio) 733 + else if (!bdev_test_flag(bio->bi_bdev, BD_HAS_SUBMIT_BIO)) 736 734 __submit_bio_noacct_mq(bio); 737 735 else 738 736 __submit_bio_noacct(bio); ··· 768 766 if (!bio_flagged(bio, BIO_REMAPPED)) { 769 767 if (unlikely(bio_check_eod(bio))) 770 768 goto end_io; 771 - if (bdev->bd_partno && unlikely(blk_partition_remap(bio))) 769 + if (bdev_is_partition(bdev) && 770 + unlikely(blk_partition_remap(bio))) 772 771 goto end_io; 773 772 } 774 773 ··· 994 991 (end || part_in_flight(part))) 995 992 __part_stat_add(part, io_ticks, now - stamp); 996 993 997 - if (part->bd_partno) { 994 + if (bdev_is_partition(part)) { 998 995 part = bdev_whole(part); 999 996 goto again; 1000 997 }
+1 -1
block/blk-mq.c
··· 93 93 struct mq_inflight *mi = priv; 94 94 95 95 if (rq->part && blk_do_io_stat(rq) && 96 - (!mi->part->bd_partno || rq->part == mi->part) && 96 + (!bdev_is_partition(mi->part) || rq->part == mi->part) && 97 97 blk_mq_rq_state(rq) == MQ_RQ_IN_FLIGHT) 98 98 mi->inflight[rq_data_dir(rq)]++; 99 99
+2 -2
block/blk-zoned.c
··· 1257 1257 * is not called. So we need to schedule execution of the next 1258 1258 * plugged BIO here. 1259 1259 */ 1260 - if (bio->bi_bdev->bd_has_submit_bio) 1260 + if (bdev_test_flag(bio->bi_bdev, BD_HAS_SUBMIT_BIO)) 1261 1261 disk_zone_wplug_unplug_bio(disk, zwplug); 1262 1262 1263 1263 /* Drop the reference we took when entering this function. */ ··· 1326 1326 * path for BIO-based devices will not do that. So drop this extra 1327 1327 * reference here. 1328 1328 */ 1329 - if (bdev->bd_has_submit_bio) 1329 + if (bdev_test_flag(bdev, BD_HAS_SUBMIT_BIO)) 1330 1330 blk_queue_exit(bdev->bd_disk->queue); 1331 1331 1332 1332 put_zwplug:
+1 -1
block/early-lookup.c
··· 78 78 * to the partition number found by UUID. 79 79 */ 80 80 *devt = part_devt(dev_to_disk(dev), 81 - dev_to_bdev(dev)->bd_partno + offset); 81 + bdev_partno(dev_to_bdev(dev)) + offset); 82 82 } else { 83 83 *devt = dev->devt; 84 84 }
+10 -5
block/genhd.c
··· 411 411 elevator_init_mq(disk->queue); 412 412 413 413 /* Mark bdev as having a submit_bio, if needed */ 414 - disk->part0->bd_has_submit_bio = disk->fops->submit_bio != NULL; 414 + if (disk->fops->submit_bio) 415 + bdev_set_flag(disk->part0, BD_HAS_SUBMIT_BIO); 415 416 416 417 /* 417 418 * If the driver provides an explicit major number it also must provide ··· 1065 1064 ssize_t part_fail_show(struct device *dev, 1066 1065 struct device_attribute *attr, char *buf) 1067 1066 { 1068 - return sprintf(buf, "%d\n", dev_to_bdev(dev)->bd_make_it_fail); 1067 + return sprintf(buf, "%d\n", 1068 + bdev_test_flag(dev_to_bdev(dev), BD_MAKE_IT_FAIL)); 1069 1069 } 1070 1070 1071 1071 ssize_t part_fail_store(struct device *dev, ··· 1075 1073 { 1076 1074 int i; 1077 1075 1078 - if (count > 0 && sscanf(buf, "%d", &i) > 0) 1079 - dev_to_bdev(dev)->bd_make_it_fail = i; 1080 - 1076 + if (count > 0 && sscanf(buf, "%d", &i) > 0) { 1077 + if (i) 1078 + bdev_set_flag(dev_to_bdev(dev), BD_MAKE_IT_FAIL); 1079 + else 1080 + bdev_clear_flag(dev_to_bdev(dev), BD_MAKE_IT_FAIL); 1081 + } 1081 1082 return count; 1082 1083 } 1083 1084
+4 -1
block/ioctl.c
··· 431 431 if (ret) 432 432 return ret; 433 433 } 434 - bdev->bd_read_only = n; 434 + if (n) 435 + bdev_set_flag(bdev, BD_READ_ONLY); 436 + else 437 + bdev_clear_flag(bdev, BD_READ_ONLY); 435 438 return 0; 436 439 } 437 440
+6 -6
block/partitions/core.c
··· 173 173 static ssize_t part_partition_show(struct device *dev, 174 174 struct device_attribute *attr, char *buf) 175 175 { 176 - return sprintf(buf, "%d\n", dev_to_bdev(dev)->bd_partno); 176 + return sprintf(buf, "%d\n", bdev_partno(dev_to_bdev(dev))); 177 177 } 178 178 179 179 static ssize_t part_start_show(struct device *dev, ··· 250 250 { 251 251 const struct block_device *part = dev_to_bdev(dev); 252 252 253 - add_uevent_var(env, "PARTN=%u", part->bd_partno); 253 + add_uevent_var(env, "PARTN=%u", bdev_partno(part)); 254 254 if (part->bd_meta_info && part->bd_meta_info->volname[0]) 255 255 add_uevent_var(env, "PARTNAME=%s", part->bd_meta_info->volname); 256 256 return 0; ··· 267 267 { 268 268 lockdep_assert_held(&part->bd_disk->open_mutex); 269 269 270 - xa_erase(&part->bd_disk->part_tbl, part->bd_partno); 270 + xa_erase(&part->bd_disk->part_tbl, bdev_partno(part)); 271 271 kobject_put(part->bd_holder_dir); 272 272 273 273 device_del(&part->bd_device); ··· 338 338 pdev->parent = ddev; 339 339 340 340 /* in consecutive minor range? */ 341 - if (bdev->bd_partno < disk->minors) { 342 - devt = MKDEV(disk->major, disk->first_minor + bdev->bd_partno); 341 + if (bdev_partno(bdev) < disk->minors) { 342 + devt = MKDEV(disk->major, disk->first_minor + bdev_partno(bdev)); 343 343 } else { 344 344 err = blk_alloc_ext_minor(); 345 345 if (err < 0) ··· 404 404 405 405 rcu_read_lock(); 406 406 xa_for_each_start(&disk->part_tbl, idx, part, 1) { 407 - if (part->bd_partno != skip_partno && 407 + if (bdev_partno(part) != skip_partno && 408 408 start < part->bd_start_sect + bdev_nr_sectors(part) && 409 409 start + length > part->bd_start_sect) { 410 410 overlap = true;
+9 -8
include/linux/blk_types.h
··· 45 45 struct request_queue * bd_queue; 46 46 struct disk_stats __percpu *bd_stats; 47 47 unsigned long bd_stamp; 48 - bool bd_read_only; /* read-only policy */ 49 - u8 bd_partno; 50 - bool bd_write_holder; 51 - bool bd_has_submit_bio; 48 + atomic_t __bd_flags; // partition number + flags 49 + #define BD_PARTNO 255 // lower 8 bits; assign-once 50 + #define BD_READ_ONLY (1u<<8) // read-only policy 51 + #define BD_WRITE_HOLDER (1u<<9) 52 + #define BD_HAS_SUBMIT_BIO (1u<<10) 53 + #define BD_RO_WARNED (1u<<11) 54 + #ifdef CONFIG_FAIL_MAKE_REQUEST 55 + #define BD_MAKE_IT_FAIL (1u<<12) 56 + #endif 52 57 dev_t bd_dev; 53 58 struct address_space *bd_mapping; /* page cache */ 54 59 ··· 70 65 struct mutex bd_fsfreeze_mutex; /* serialize freeze/thaw */ 71 66 72 67 struct partition_meta_info *bd_meta_info; 73 - #ifdef CONFIG_FAIL_MAKE_REQUEST 74 - bool bd_make_it_fail; 75 - #endif 76 - bool bd_ro_warned; 77 68 int bd_writers; 78 69 /* 79 70 * keep this out-of-line as it's both big and not needed in the fast
+23 -3
include/linux/blkdev.h
··· 718 718 void set_disk_ro(struct gendisk *disk, bool read_only); 719 719 void disk_uevent(struct gendisk *disk, enum kobject_action action); 720 720 721 + static inline u8 bdev_partno(const struct block_device *bdev) 722 + { 723 + return atomic_read(&bdev->__bd_flags) & BD_PARTNO; 724 + } 725 + 726 + static inline bool bdev_test_flag(const struct block_device *bdev, unsigned flag) 727 + { 728 + return atomic_read(&bdev->__bd_flags) & flag; 729 + } 730 + 731 + static inline void bdev_set_flag(struct block_device *bdev, unsigned flag) 732 + { 733 + atomic_or(flag, &bdev->__bd_flags); 734 + } 735 + 736 + static inline void bdev_clear_flag(struct block_device *bdev, unsigned flag) 737 + { 738 + atomic_andnot(flag, &bdev->__bd_flags); 739 + } 740 + 721 741 static inline int get_disk_ro(struct gendisk *disk) 722 742 { 723 - return disk->part0->bd_read_only || 743 + return bdev_test_flag(disk->part0, BD_READ_ONLY) || 724 744 test_bit(GD_READ_ONLY, &disk->state); 725 745 } 726 746 727 747 static inline int bdev_read_only(struct block_device *bdev) 728 748 { 729 - return bdev->bd_read_only || get_disk_ro(bdev->bd_disk); 749 + return bdev_test_flag(bdev, BD_READ_ONLY) || get_disk_ro(bdev->bd_disk); 730 750 } 731 751 732 752 bool set_capacity_and_notify(struct gendisk *disk, sector_t size); ··· 1106 1086 1107 1087 static inline bool bdev_is_partition(struct block_device *bdev) 1108 1088 { 1109 - return bdev->bd_partno; 1089 + return bdev_partno(bdev) != 0; 1110 1090 } 1111 1091 1112 1092 enum blk_default_limits {
+1 -1
include/linux/part_stat.h
··· 59 59 60 60 #define part_stat_add(part, field, addnd) do { \ 61 61 __part_stat_add((part), field, addnd); \ 62 - if ((part)->bd_partno) \ 62 + if (bdev_is_partition(part)) \ 63 63 __part_stat_add(bdev_whole(part), field, addnd); \ 64 64 } while (0) 65 65
+2 -2
lib/vsprintf.c
··· 966 966 967 967 hd = bdev->bd_disk; 968 968 buf = string(buf, end, hd->disk_name, spec); 969 - if (bdev->bd_partno) { 969 + if (bdev_is_partition(bdev)) { 970 970 if (isdigit(hd->disk_name[strlen(hd->disk_name)-1])) { 971 971 if (buf < end) 972 972 *buf = 'p'; 973 973 buf++; 974 974 } 975 - buf = number(buf, end, bdev->bd_partno, spec); 975 + buf = number(buf, end, bdev_partno(bdev), spec); 976 976 } 977 977 return buf; 978 978 }