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 branch 'block-6.19' into for-7.0/block

Merge in fixes that went to 6.19 after for-7.0/block was branched.
Pending ublk changes depend on particularly the async scan work.

* block-6.19:
block: zero non-PI portion of auto integrity buffer
ublk: fix use-after-free in ublk_partition_scan_work
blk-mq: avoid stall during boot due to synchronize_rcu_expedited
loop: add missing bd_abort_claiming in loop_set_status
block: don't merge bios with different app_tags
blk-rq-qos: Remove unlikely() hints from QoS checks
loop: don't change loop device under exclusive opener in loop_set_status
block, bfq: update outdated comment
blk-mq: skip CPU offline notify on unmapped hctx
selftests/ublk: fix Makefile to rebuild on header changes
selftests/ublk: add test for async partition scan
ublk: scan partition in async way
block,bfq: fix aux stat accumulation destination
md: Fix forward incompatibility from configurable logical block size
md: Fix logical_block_size configuration being overwritten
md: suspend array while updating raid_disks via sysfs
md/raid5: fix possible null-pointer dereferences in raid5_store_group_thread_cnt()
md: Fix static checker warning in analyze_sbs

+243 -63
+1 -1
block/bfq-cgroup.c
··· 380 380 blkg_rwstat_add_aux(&to->merged, &from->merged); 381 381 blkg_rwstat_add_aux(&to->service_time, &from->service_time); 382 382 blkg_rwstat_add_aux(&to->wait_time, &from->wait_time); 383 - bfq_stat_add_aux(&from->time, &from->time); 383 + bfq_stat_add_aux(&to->time, &from->time); 384 384 bfq_stat_add_aux(&to->avg_queue_size_sum, &from->avg_queue_size_sum); 385 385 bfq_stat_add_aux(&to->avg_queue_size_samples, 386 386 &from->avg_queue_size_samples);
+1 -1
block/bfq-iosched.h
··· 984 984 * unused for the root group. Used to know whether there 985 985 * are groups with more than one active @bfq_entity 986 986 * (see the comments to the function 987 - * bfq_bfqq_may_idle()). 987 + * bfq_better_to_idle()). 988 988 * @rq_pos_tree: rbtree sorted by next_request position, used when 989 989 * determining if two or more queues have interleaving 990 990 * requests (see bfq_find_close_cooperator()).
+1 -1
block/bio-integrity-auto.c
··· 128 128 return true; 129 129 set_flags = false; 130 130 gfp |= __GFP_ZERO; 131 - } else if (bi->csum_type == BLK_INTEGRITY_CSUM_NONE) 131 + } else if (bi->metadata_size > bi->pi_tuple_size) 132 132 gfp |= __GFP_ZERO; 133 133 break; 134 134 default:
+18 -5
block/blk-integrity.c
··· 140 140 bool blk_integrity_merge_rq(struct request_queue *q, struct request *req, 141 141 struct request *next) 142 142 { 143 + struct bio_integrity_payload *bip, *bip_next; 144 + 143 145 if (blk_integrity_rq(req) == 0 && blk_integrity_rq(next) == 0) 144 146 return true; 145 147 146 148 if (blk_integrity_rq(req) == 0 || blk_integrity_rq(next) == 0) 147 149 return false; 148 150 149 - if (bio_integrity(req->bio)->bip_flags != 150 - bio_integrity(next->bio)->bip_flags) 151 + bip = bio_integrity(req->bio); 152 + bip_next = bio_integrity(next->bio); 153 + if (bip->bip_flags != bip_next->bip_flags) 154 + return false; 155 + 156 + if (bip->bip_flags & BIP_CHECK_APPTAG && 157 + bip->app_tag != bip_next->app_tag) 151 158 return false; 152 159 153 160 if (req->nr_integrity_segments + next->nr_integrity_segments > ··· 170 163 bool blk_integrity_merge_bio(struct request_queue *q, struct request *req, 171 164 struct bio *bio) 172 165 { 166 + struct bio_integrity_payload *bip, *bip_bio = bio_integrity(bio); 173 167 int nr_integrity_segs; 174 168 175 - if (blk_integrity_rq(req) == 0 && bio_integrity(bio) == NULL) 169 + if (blk_integrity_rq(req) == 0 && bip_bio == NULL) 176 170 return true; 177 171 178 - if (blk_integrity_rq(req) == 0 || bio_integrity(bio) == NULL) 172 + if (blk_integrity_rq(req) == 0 || bip_bio == NULL) 179 173 return false; 180 174 181 - if (bio_integrity(req->bio)->bip_flags != bio_integrity(bio)->bip_flags) 175 + bip = bio_integrity(req->bio); 176 + if (bip->bip_flags != bip_bio->bip_flags) 177 + return false; 178 + 179 + if (bip->bip_flags & BIP_CHECK_APPTAG && 180 + bip->app_tag != bip_bio->app_tag) 182 181 return false; 183 182 184 183 nr_integrity_segs = blk_rq_count_integrity_sg(q, bio);
+2 -3
block/blk-mq.c
··· 3721 3721 struct blk_mq_hw_ctx, cpuhp_online); 3722 3722 int ret = 0; 3723 3723 3724 - if (blk_mq_hctx_has_online_cpu(hctx, cpu)) 3724 + if (!hctx->nr_ctx || blk_mq_hctx_has_online_cpu(hctx, cpu)) 3725 3725 return 0; 3726 3726 3727 3727 /* ··· 4553 4553 * Make sure reading the old queue_hw_ctx from other 4554 4554 * context concurrently won't trigger uaf. 4555 4555 */ 4556 - synchronize_rcu_expedited(); 4557 - kfree(hctxs); 4556 + kfree_rcu_mightsleep(hctxs); 4558 4557 hctxs = new_hctxs; 4559 4558 } 4560 4559
+9 -16
block/blk-rq-qos.h
··· 112 112 113 113 static inline void rq_qos_cleanup(struct request_queue *q, struct bio *bio) 114 114 { 115 - if (unlikely(test_bit(QUEUE_FLAG_QOS_ENABLED, &q->queue_flags)) && 116 - q->rq_qos) 115 + if (test_bit(QUEUE_FLAG_QOS_ENABLED, &q->queue_flags) && q->rq_qos) 117 116 __rq_qos_cleanup(q->rq_qos, bio); 118 117 } 119 118 120 119 static inline void rq_qos_done(struct request_queue *q, struct request *rq) 121 120 { 122 - if (unlikely(test_bit(QUEUE_FLAG_QOS_ENABLED, &q->queue_flags)) && 123 - q->rq_qos && !blk_rq_is_passthrough(rq)) 121 + if (test_bit(QUEUE_FLAG_QOS_ENABLED, &q->queue_flags) && 122 + q->rq_qos && !blk_rq_is_passthrough(rq)) 124 123 __rq_qos_done(q->rq_qos, rq); 125 124 } 126 125 127 126 static inline void rq_qos_issue(struct request_queue *q, struct request *rq) 128 127 { 129 - if (unlikely(test_bit(QUEUE_FLAG_QOS_ENABLED, &q->queue_flags)) && 130 - q->rq_qos) 128 + if (test_bit(QUEUE_FLAG_QOS_ENABLED, &q->queue_flags) && q->rq_qos) 131 129 __rq_qos_issue(q->rq_qos, rq); 132 130 } 133 131 134 132 static inline void rq_qos_requeue(struct request_queue *q, struct request *rq) 135 133 { 136 - if (unlikely(test_bit(QUEUE_FLAG_QOS_ENABLED, &q->queue_flags)) && 137 - q->rq_qos) 134 + if (test_bit(QUEUE_FLAG_QOS_ENABLED, &q->queue_flags) && q->rq_qos) 138 135 __rq_qos_requeue(q->rq_qos, rq); 139 136 } 140 137 ··· 159 162 160 163 static inline void rq_qos_throttle(struct request_queue *q, struct bio *bio) 161 164 { 162 - if (unlikely(test_bit(QUEUE_FLAG_QOS_ENABLED, &q->queue_flags)) && 163 - q->rq_qos) { 165 + if (test_bit(QUEUE_FLAG_QOS_ENABLED, &q->queue_flags) && q->rq_qos) { 164 166 bio_set_flag(bio, BIO_QOS_THROTTLED); 165 167 __rq_qos_throttle(q->rq_qos, bio); 166 168 } ··· 168 172 static inline void rq_qos_track(struct request_queue *q, struct request *rq, 169 173 struct bio *bio) 170 174 { 171 - if (unlikely(test_bit(QUEUE_FLAG_QOS_ENABLED, &q->queue_flags)) && 172 - q->rq_qos) 175 + if (test_bit(QUEUE_FLAG_QOS_ENABLED, &q->queue_flags) && q->rq_qos) 173 176 __rq_qos_track(q->rq_qos, rq, bio); 174 177 } 175 178 176 179 static inline void rq_qos_merge(struct request_queue *q, struct request *rq, 177 180 struct bio *bio) 178 181 { 179 - if (unlikely(test_bit(QUEUE_FLAG_QOS_ENABLED, &q->queue_flags)) && 180 - q->rq_qos) { 182 + if (test_bit(QUEUE_FLAG_QOS_ENABLED, &q->queue_flags) && q->rq_qos) { 181 183 bio_set_flag(bio, BIO_QOS_MERGED); 182 184 __rq_qos_merge(q->rq_qos, rq, bio); 183 185 } ··· 183 189 184 190 static inline void rq_qos_queue_depth_changed(struct request_queue *q) 185 191 { 186 - if (unlikely(test_bit(QUEUE_FLAG_QOS_ENABLED, &q->queue_flags)) && 187 - q->rq_qos) 192 + if (test_bit(QUEUE_FLAG_QOS_ENABLED, &q->queue_flags) && q->rq_qos) 188 193 __rq_qos_queue_depth_changed(q->rq_qos); 189 194 } 190 195
+33 -12
drivers/block/loop.c
··· 1225 1225 } 1226 1226 1227 1227 static int 1228 - loop_set_status(struct loop_device *lo, const struct loop_info64 *info) 1228 + loop_set_status(struct loop_device *lo, blk_mode_t mode, 1229 + struct block_device *bdev, const struct loop_info64 *info) 1229 1230 { 1230 1231 int err; 1231 1232 bool partscan = false; 1232 1233 bool size_changed = false; 1233 1234 unsigned int memflags; 1234 1235 1236 + /* 1237 + * If we don't hold exclusive handle for the device, upgrade to it 1238 + * here to avoid changing device under exclusive owner. 1239 + */ 1240 + if (!(mode & BLK_OPEN_EXCL)) { 1241 + err = bd_prepare_to_claim(bdev, loop_set_status, NULL); 1242 + if (err) 1243 + goto out_reread_partitions; 1244 + } 1245 + 1235 1246 err = mutex_lock_killable(&lo->lo_mutex); 1236 1247 if (err) 1237 - return err; 1248 + goto out_abort_claiming; 1249 + 1238 1250 if (lo->lo_state != Lo_bound) { 1239 1251 err = -ENXIO; 1240 1252 goto out_unlock; ··· 1285 1273 } 1286 1274 out_unlock: 1287 1275 mutex_unlock(&lo->lo_mutex); 1276 + out_abort_claiming: 1277 + if (!(mode & BLK_OPEN_EXCL)) 1278 + bd_abort_claiming(bdev, loop_set_status); 1279 + out_reread_partitions: 1288 1280 if (partscan) 1289 1281 loop_reread_partitions(lo); 1290 1282 ··· 1368 1352 } 1369 1353 1370 1354 static int 1371 - loop_set_status_old(struct loop_device *lo, const struct loop_info __user *arg) 1355 + loop_set_status_old(struct loop_device *lo, blk_mode_t mode, 1356 + struct block_device *bdev, 1357 + const struct loop_info __user *arg) 1372 1358 { 1373 1359 struct loop_info info; 1374 1360 struct loop_info64 info64; ··· 1378 1360 if (copy_from_user(&info, arg, sizeof (struct loop_info))) 1379 1361 return -EFAULT; 1380 1362 loop_info64_from_old(&info, &info64); 1381 - return loop_set_status(lo, &info64); 1363 + return loop_set_status(lo, mode, bdev, &info64); 1382 1364 } 1383 1365 1384 1366 static int 1385 - loop_set_status64(struct loop_device *lo, const struct loop_info64 __user *arg) 1367 + loop_set_status64(struct loop_device *lo, blk_mode_t mode, 1368 + struct block_device *bdev, 1369 + const struct loop_info64 __user *arg) 1386 1370 { 1387 1371 struct loop_info64 info64; 1388 1372 1389 1373 if (copy_from_user(&info64, arg, sizeof (struct loop_info64))) 1390 1374 return -EFAULT; 1391 - return loop_set_status(lo, &info64); 1375 + return loop_set_status(lo, mode, bdev, &info64); 1392 1376 } 1393 1377 1394 1378 static int ··· 1569 1549 case LOOP_SET_STATUS: 1570 1550 err = -EPERM; 1571 1551 if ((mode & BLK_OPEN_WRITE) || capable(CAP_SYS_ADMIN)) 1572 - err = loop_set_status_old(lo, argp); 1552 + err = loop_set_status_old(lo, mode, bdev, argp); 1573 1553 break; 1574 1554 case LOOP_GET_STATUS: 1575 1555 return loop_get_status_old(lo, argp); 1576 1556 case LOOP_SET_STATUS64: 1577 1557 err = -EPERM; 1578 1558 if ((mode & BLK_OPEN_WRITE) || capable(CAP_SYS_ADMIN)) 1579 - err = loop_set_status64(lo, argp); 1559 + err = loop_set_status64(lo, mode, bdev, argp); 1580 1560 break; 1581 1561 case LOOP_GET_STATUS64: 1582 1562 return loop_get_status64(lo, argp); ··· 1670 1650 } 1671 1651 1672 1652 static int 1673 - loop_set_status_compat(struct loop_device *lo, 1674 - const struct compat_loop_info __user *arg) 1653 + loop_set_status_compat(struct loop_device *lo, blk_mode_t mode, 1654 + struct block_device *bdev, 1655 + const struct compat_loop_info __user *arg) 1675 1656 { 1676 1657 struct loop_info64 info64; 1677 1658 int ret; ··· 1680 1659 ret = loop_info64_from_compat(arg, &info64); 1681 1660 if (ret < 0) 1682 1661 return ret; 1683 - return loop_set_status(lo, &info64); 1662 + return loop_set_status(lo, mode, bdev, &info64); 1684 1663 } 1685 1664 1686 1665 static int ··· 1706 1685 1707 1686 switch(cmd) { 1708 1687 case LOOP_SET_STATUS: 1709 - err = loop_set_status_compat(lo, 1688 + err = loop_set_status_compat(lo, mode, bdev, 1710 1689 (const struct compat_loop_info __user *)arg); 1711 1690 break; 1712 1691 case LOOP_GET_STATUS:
+39 -3
drivers/block/ublk_drv.c
··· 237 237 bool canceling; 238 238 pid_t ublksrv_tgid; 239 239 struct delayed_work exit_work; 240 + struct work_struct partition_scan_work; 240 241 241 242 struct ublk_queue *queues[]; 242 243 }; ··· 1583 1582 put_device(disk_to_dev(disk)); 1584 1583 } 1585 1584 1585 + static void ublk_partition_scan_work(struct work_struct *work) 1586 + { 1587 + struct ublk_device *ub = 1588 + container_of(work, struct ublk_device, partition_scan_work); 1589 + /* Hold disk reference to prevent UAF during concurrent teardown */ 1590 + struct gendisk *disk = ublk_get_disk(ub); 1591 + 1592 + if (!disk) 1593 + return; 1594 + 1595 + if (WARN_ON_ONCE(!test_and_clear_bit(GD_SUPPRESS_PART_SCAN, 1596 + &disk->state))) 1597 + goto out; 1598 + 1599 + mutex_lock(&disk->open_mutex); 1600 + bdev_disk_changed(disk, false); 1601 + mutex_unlock(&disk->open_mutex); 1602 + out: 1603 + ublk_put_disk(disk); 1604 + } 1605 + 1586 1606 /* 1587 1607 * Use this function to ensure that ->canceling is consistently set for 1588 1608 * the device and all queues. Do not set these flags directly. ··· 2048 2026 mutex_lock(&ub->mutex); 2049 2027 ublk_stop_dev_unlocked(ub); 2050 2028 mutex_unlock(&ub->mutex); 2029 + cancel_work_sync(&ub->partition_scan_work); 2051 2030 ublk_cancel_dev(ub); 2052 2031 } 2053 2032 ··· 2977 2954 2978 2955 ublk_apply_params(ub); 2979 2956 2980 - /* don't probe partitions if any daemon task is un-trusted */ 2981 - if (ub->unprivileged_daemons) 2982 - set_bit(GD_SUPPRESS_PART_SCAN, &disk->state); 2957 + /* 2958 + * Suppress partition scan to avoid potential IO hang. 2959 + * 2960 + * If ublk server error occurs during partition scan, the IO may 2961 + * wait while holding ub->mutex, which can deadlock with other 2962 + * operations that need the mutex. Defer partition scan to async 2963 + * work. 2964 + * For unprivileged daemons, keep GD_SUPPRESS_PART_SCAN set 2965 + * permanently. 2966 + */ 2967 + set_bit(GD_SUPPRESS_PART_SCAN, &disk->state); 2983 2968 2984 2969 ublk_get_device(ub); 2985 2970 ub->dev_info.state = UBLK_S_DEV_LIVE; ··· 3003 2972 goto out_put_cdev; 3004 2973 3005 2974 set_bit(UB_STATE_USED, &ub->state); 2975 + 2976 + /* Schedule async partition scan for trusted daemons */ 2977 + if (!ub->unprivileged_daemons) 2978 + schedule_work(&ub->partition_scan_work); 3006 2979 3007 2980 out_put_cdev: 3008 2981 if (ret) { ··· 3173 3138 mutex_init(&ub->mutex); 3174 3139 spin_lock_init(&ub->lock); 3175 3140 mutex_init(&ub->cancel_mutex); 3141 + INIT_WORK(&ub->partition_scan_work, ublk_partition_scan_work); 3176 3142 3177 3143 ret = ublk_alloc_dev_number(ub, header->dev_id); 3178 3144 if (ret < 0)
+50 -11
drivers/md/md.c
··· 1999 1999 mddev->layout = le32_to_cpu(sb->layout); 2000 2000 mddev->raid_disks = le32_to_cpu(sb->raid_disks); 2001 2001 mddev->dev_sectors = le64_to_cpu(sb->size); 2002 - mddev->logical_block_size = le32_to_cpu(sb->logical_block_size); 2003 2002 mddev->events = ev1; 2004 2003 mddev->bitmap_info.offset = 0; 2005 2004 mddev->bitmap_info.space = 0; ··· 2013 2014 memcpy(mddev->uuid, sb->set_uuid, 16); 2014 2015 2015 2016 mddev->max_disks = (4096-256)/2; 2017 + 2018 + if (!mddev->logical_block_size) 2019 + mddev->logical_block_size = le32_to_cpu(sb->logical_block_size); 2016 2020 2017 2021 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_BITMAP_OFFSET) && 2018 2022 mddev->bitmap_info.file == NULL) { ··· 3884 3882 3885 3883 static int analyze_sbs(struct mddev *mddev) 3886 3884 { 3887 - int i; 3888 3885 struct md_rdev *rdev, *freshest, *tmp; 3889 3886 3890 3887 freshest = NULL; ··· 3910 3909 super_types[mddev->major_version]. 3911 3910 validate_super(mddev, NULL/*freshest*/, freshest); 3912 3911 3913 - i = 0; 3914 3912 rdev_for_each_safe(rdev, tmp, mddev) { 3915 3913 if (mddev->max_disks && 3916 - (rdev->desc_nr >= mddev->max_disks || 3917 - i > mddev->max_disks)) { 3914 + rdev->desc_nr >= mddev->max_disks) { 3918 3915 pr_warn("md: %s: %pg: only %d devices permitted\n", 3919 3916 mdname(mddev), rdev->bdev, 3920 3917 mddev->max_disks); ··· 4406 4407 if (err < 0) 4407 4408 return err; 4408 4409 4409 - err = mddev_lock(mddev); 4410 + err = mddev_suspend_and_lock(mddev); 4410 4411 if (err) 4411 4412 return err; 4412 4413 if (mddev->pers) ··· 4431 4432 } else 4432 4433 mddev->raid_disks = n; 4433 4434 out_unlock: 4434 - mddev_unlock(mddev); 4435 + mddev_unlock_and_resume(mddev); 4435 4436 return err ? err : len; 4436 4437 } 4437 4438 static struct md_sysfs_entry md_raid_disks = ··· 5980 5981 if (mddev->major_version == 0) 5981 5982 return -EINVAL; 5982 5983 5983 - if (mddev->pers) 5984 - return -EBUSY; 5985 - 5986 5984 err = kstrtouint(buf, 10, &lbs); 5987 5985 if (err < 0) 5988 5986 return -EINVAL; 5987 + 5988 + if (mddev->pers) { 5989 + unsigned int curr_lbs; 5990 + 5991 + if (mddev->logical_block_size) 5992 + return -EBUSY; 5993 + /* 5994 + * To fix forward compatibility issues, LBS is not 5995 + * configured for arrays from old kernels (<=6.18) by default. 5996 + * If the user confirms no rollback to old kernels, 5997 + * enable LBS by writing current LBS — to prevent data 5998 + * loss from LBS changes. 5999 + */ 6000 + curr_lbs = queue_logical_block_size(mddev->gendisk->queue); 6001 + if (lbs != curr_lbs) 6002 + return -EINVAL; 6003 + 6004 + mddev->logical_block_size = curr_lbs; 6005 + set_bit(MD_SB_CHANGE_DEVS, &mddev->sb_flags); 6006 + pr_info("%s: logical block size configured successfully, array will not be assembled in old kernels (<= 6.18)\n", 6007 + mdname(mddev)); 6008 + return len; 6009 + } 5989 6010 5990 6011 err = mddev_lock(mddev); 5991 6012 if (err) ··· 6182 6163 mdname(mddev)); 6183 6164 return -EINVAL; 6184 6165 } 6185 - mddev->logical_block_size = lim->logical_block_size; 6166 + 6167 + /* Only 1.x meta needs to set logical block size */ 6168 + if (mddev->major_version == 0) 6169 + return 0; 6170 + 6171 + /* 6172 + * Fix forward compatibility issue. Only set LBS by default for 6173 + * new arrays, mddev->events == 0 indicates the array was just 6174 + * created. When assembling an array, read LBS from the superblock 6175 + * instead — LBS is 0 in superblocks created by old kernels. 6176 + */ 6177 + if (!mddev->events) { 6178 + pr_info("%s: array will not be assembled in old kernels that lack configurable LBS support (<= 6.18)\n", 6179 + mdname(mddev)); 6180 + mddev->logical_block_size = lim->logical_block_size; 6181 + } 6182 + 6183 + if (!mddev->logical_block_size) 6184 + pr_warn("%s: echo current LBS to md/logical_block_size to prevent data loss issues from LBS changes.\n" 6185 + "\tNote: After setting, array will not be assembled in old kernels (<= 6.18)\n", 6186 + mdname(mddev)); 6186 6187 6187 6188 return 0; 6188 6189 }
+6 -4
drivers/md/raid5.c
··· 7187 7187 err = mddev_suspend_and_lock(mddev); 7188 7188 if (err) 7189 7189 return err; 7190 + conf = mddev->private; 7191 + if (!conf) { 7192 + mddev_unlock_and_resume(mddev); 7193 + return -ENODEV; 7194 + } 7190 7195 raid5_quiesce(mddev, true); 7191 7196 7192 - conf = mddev->private; 7193 - if (!conf) 7194 - err = -ENODEV; 7195 - else if (new != conf->worker_cnt_per_group) { 7197 + if (new != conf->worker_cnt_per_group) { 7196 7198 old_groups = conf->worker_groups; 7197 7199 if (old_groups) 7198 7200 flush_workqueue(raid5_wq);
+3 -2
tools/testing/selftests/ublk/Makefile
··· 22 22 TEST_PROGS += test_generic_12.sh 23 23 TEST_PROGS += test_generic_13.sh 24 24 TEST_PROGS += test_generic_14.sh 25 + TEST_PROGS += test_generic_15.sh 25 26 26 27 TEST_PROGS += test_null_01.sh 27 28 TEST_PROGS += test_null_02.sh ··· 51 50 52 51 TEST_GEN_PROGS_EXTENDED = kublk 53 52 53 + LOCAL_HDRS += $(wildcard *.h) 54 54 include ../lib.mk 55 55 56 - $(TEST_GEN_PROGS_EXTENDED): kublk.c null.c file_backed.c common.c stripe.c \ 57 - fault_inject.c 56 + $(TEST_GEN_PROGS_EXTENDED): $(wildcard *.c) 58 57 59 58 check: 60 59 shellcheck -x -f gcc *.sh
+12 -4
tools/testing/selftests/ublk/test_common.sh
··· 178 178 _create_ublk_dev() { 179 179 local dev_id; 180 180 local cmd=$1 181 + local settle=$2 181 182 182 - shift 1 183 + shift 2 183 184 184 185 if [ ! -c /dev/ublk-control ]; then 185 186 return ${UBLK_SKIP_CODE} ··· 195 194 echo "fail to add ublk dev $*" 196 195 return 255 197 196 fi 198 - udevadm settle 197 + 198 + if [ "$settle" = "yes" ]; then 199 + udevadm settle 200 + fi 199 201 200 202 if [[ "$dev_id" =~ ^[0-9]+$ ]]; then 201 203 echo "${dev_id}" ··· 208 204 } 209 205 210 206 _add_ublk_dev() { 211 - _create_ublk_dev "add" "$@" 207 + _create_ublk_dev "add" "yes" "$@" 208 + } 209 + 210 + _add_ublk_dev_no_settle() { 211 + _create_ublk_dev "add" "no" "$@" 212 212 } 213 213 214 214 _recover_ublk_dev() { 215 215 local dev_id 216 216 local state 217 217 218 - dev_id=$(_create_ublk_dev "recover" "$@") 218 + dev_id=$(_create_ublk_dev "recover" "yes" "$@") 219 219 for ((j=0;j<20;j++)); do 220 220 state=$(_get_ublk_dev_state "${dev_id}") 221 221 [ "$state" == "LIVE" ] && break
+68
tools/testing/selftests/ublk/test_generic_15.sh
··· 1 + #!/bin/bash 2 + # SPDX-License-Identifier: GPL-2.0 3 + 4 + . "$(cd "$(dirname "$0")" && pwd)"/test_common.sh 5 + 6 + TID="generic_15" 7 + ERR_CODE=0 8 + 9 + _test_partition_scan_no_hang() 10 + { 11 + local recovery_flag=$1 12 + local expected_state=$2 13 + local dev_id 14 + local state 15 + local daemon_pid 16 + local start_time 17 + local elapsed 18 + 19 + # Create ublk device with fault_inject target and very large delay 20 + # to simulate hang during partition table read 21 + # --delay_us 60000000 = 60 seconds delay 22 + # Use _add_ublk_dev_no_settle to avoid udevadm settle hang waiting 23 + # for partition scan events to complete 24 + if [ "$recovery_flag" = "yes" ]; then 25 + echo "Testing partition scan with recovery support..." 26 + dev_id=$(_add_ublk_dev_no_settle -t fault_inject -q 1 -d 1 --delay_us 60000000 -r 1) 27 + else 28 + echo "Testing partition scan without recovery..." 29 + dev_id=$(_add_ublk_dev_no_settle -t fault_inject -q 1 -d 1 --delay_us 60000000) 30 + fi 31 + 32 + _check_add_dev "$TID" $? 33 + 34 + # The add command should return quickly because partition scan is async. 35 + # Now sleep briefly to let the async partition scan work start and hit 36 + # the delay in the fault_inject handler. 37 + sleep 1 38 + 39 + # Kill the ublk daemon while partition scan is potentially blocked 40 + # And check state transitions properly 41 + start_time=${SECONDS} 42 + daemon_pid=$(_get_ublk_daemon_pid "${dev_id}") 43 + state=$(__ublk_kill_daemon "${dev_id}" "${expected_state}") 44 + elapsed=$((SECONDS - start_time)) 45 + 46 + # Verify the device transitioned to expected state 47 + if [ "$state" != "${expected_state}" ]; then 48 + echo "FAIL: Device state is $state, expected ${expected_state}" 49 + ERR_CODE=255 50 + ${UBLK_PROG} del -n "${dev_id}" > /dev/null 2>&1 51 + return 52 + fi 53 + echo "PASS: Device transitioned to ${expected_state} in ${elapsed}s without hanging" 54 + 55 + # Clean up the device 56 + ${UBLK_PROG} del -n "${dev_id}" > /dev/null 2>&1 57 + } 58 + 59 + _prep_test "partition_scan" "verify async partition scan prevents IO hang" 60 + 61 + # Test 1: Without recovery support - should transition to DEAD 62 + _test_partition_scan_no_hang "no" "DEAD" 63 + 64 + # Test 2: With recovery support - should transition to QUIESCED 65 + _test_partition_scan_no_hang "yes" "QUIESCED" 66 + 67 + _cleanup_test "partition_scan" 68 + _show_result $TID $ERR_CODE