@@ -1910,40 +1910,15 @@ static blk_qc_t blk_queue_bio(struct request_queue *q, struct bio *bio)
19101910 return BLK_QC_T_NONE ;
19111911}
19121912
1913- /*
1914- * If bio->bi_dev is a partition, remap the location
1915- */
1916- static inline void blk_partition_remap (struct bio * bio )
1917- {
1918- struct block_device * bdev = bio -> bi_bdev ;
1919-
1920- /*
1921- * Zone reset does not include bi_size so bio_sectors() is always 0.
1922- * Include a test for the reset op code and perform the remap if needed.
1923- */
1924- if (bdev != bdev -> bd_contains &&
1925- (bio_sectors (bio ) || bio_op (bio ) == REQ_OP_ZONE_RESET )) {
1926- struct hd_struct * p = bdev -> bd_part ;
1927-
1928- bio -> bi_iter .bi_sector += p -> start_sect ;
1929- bio -> bi_bdev = bdev -> bd_contains ;
1930-
1931- trace_block_bio_remap (bdev_get_queue (bio -> bi_bdev ), bio ,
1932- bdev -> bd_dev ,
1933- bio -> bi_iter .bi_sector - p -> start_sect );
1934- }
1935- }
1936-
19371913static void handle_bad_sector (struct bio * bio )
19381914{
19391915 char b [BDEVNAME_SIZE ];
19401916
19411917 printk (KERN_INFO "attempt to access beyond end of device\n" );
19421918 printk (KERN_INFO "%s: rw=%d, want=%Lu, limit=%Lu\n" ,
1943- bdevname (bio -> bi_bdev , b ),
1944- bio -> bi_opf ,
1919+ bio_devname (bio , b ), bio -> bi_opf ,
19451920 (unsigned long long )bio_end_sector (bio ),
1946- (long long )( i_size_read ( bio -> bi_bdev -> bd_inode ) >> 9 ));
1921+ (long long )get_capacity ( bio -> bi_disk ));
19471922}
19481923
19491924#ifdef CONFIG_FAIL_MAKE_REQUEST
@@ -1981,6 +1956,38 @@ static inline bool should_fail_request(struct hd_struct *part,
19811956
19821957#endif /* CONFIG_FAIL_MAKE_REQUEST */
19831958
1959+ /*
1960+ * Remap block n of partition p to block n+start(p) of the disk.
1961+ */
1962+ static inline int blk_partition_remap (struct bio * bio )
1963+ {
1964+ struct hd_struct * p ;
1965+ int ret = 0 ;
1966+
1967+ /*
1968+ * Zone reset does not include bi_size so bio_sectors() is always 0.
1969+ * Include a test for the reset op code and perform the remap if needed.
1970+ */
1971+ if (!bio -> bi_partno ||
1972+ (!bio_sectors (bio ) && bio_op (bio ) != REQ_OP_ZONE_RESET ))
1973+ return 0 ;
1974+
1975+ rcu_read_lock ();
1976+ p = __disk_get_part (bio -> bi_disk , bio -> bi_partno );
1977+ if (likely (p && !should_fail_request (p , bio -> bi_iter .bi_size ))) {
1978+ bio -> bi_iter .bi_sector += p -> start_sect ;
1979+ bio -> bi_partno = 0 ;
1980+ trace_block_bio_remap (bio -> bi_disk -> queue , bio , part_devt (p ),
1981+ bio -> bi_iter .bi_sector - p -> start_sect );
1982+ } else {
1983+ printk ("%s: fail for partition %d\n" , __func__ , bio -> bi_partno );
1984+ ret = - EIO ;
1985+ }
1986+ rcu_read_unlock ();
1987+
1988+ return ret ;
1989+ }
1990+
19841991/*
19851992 * Check whether this bio extends beyond the end of the device.
19861993 */
@@ -1992,7 +1999,7 @@ static inline int bio_check_eod(struct bio *bio, unsigned int nr_sectors)
19921999 return 0 ;
19932000
19942001 /* Test device or partition size, when known. */
1995- maxsector = i_size_read (bio -> bi_bdev -> bd_inode ) >> 9 ;
2002+ maxsector = get_capacity (bio -> bi_disk ) ;
19962003 if (maxsector ) {
19972004 sector_t sector = bio -> bi_iter .bi_sector ;
19982005
@@ -2017,20 +2024,18 @@ generic_make_request_checks(struct bio *bio)
20172024 int nr_sectors = bio_sectors (bio );
20182025 blk_status_t status = BLK_STS_IOERR ;
20192026 char b [BDEVNAME_SIZE ];
2020- struct hd_struct * part ;
20212027
20222028 might_sleep ();
20232029
20242030 if (bio_check_eod (bio , nr_sectors ))
20252031 goto end_io ;
20262032
2027- q = bdev_get_queue ( bio -> bi_bdev ) ;
2033+ q = bio -> bi_disk -> queue ;
20282034 if (unlikely (!q )) {
20292035 printk (KERN_ERR
20302036 "generic_make_request: Trying to access "
20312037 "nonexistent block-device %s (%Lu)\n" ,
2032- bdevname (bio -> bi_bdev , b ),
2033- (long long ) bio -> bi_iter .bi_sector );
2038+ bio_devname (bio , b ), (long long )bio -> bi_iter .bi_sector );
20342039 goto end_io ;
20352040 }
20362041
@@ -2042,17 +2047,11 @@ generic_make_request_checks(struct bio *bio)
20422047 if ((bio -> bi_opf & REQ_NOWAIT ) && !queue_is_rq_based (q ))
20432048 goto not_supported ;
20442049
2045- part = bio -> bi_bdev -> bd_part ;
2046- if (should_fail_request (part , bio -> bi_iter .bi_size ) ||
2047- should_fail_request (& part_to_disk (part )-> part0 ,
2048- bio -> bi_iter .bi_size ))
2050+ if (should_fail_request (& bio -> bi_disk -> part0 , bio -> bi_iter .bi_size ))
20492051 goto end_io ;
20502052
2051- /*
2052- * If this device has partitions, remap block n
2053- * of partition p to block n+start(p) of the disk.
2054- */
2055- blk_partition_remap (bio );
2053+ if (blk_partition_remap (bio ))
2054+ goto end_io ;
20562055
20572056 if (bio_check_eod (bio , nr_sectors ))
20582057 goto end_io ;
@@ -2081,16 +2080,16 @@ generic_make_request_checks(struct bio *bio)
20812080 goto not_supported ;
20822081 break ;
20832082 case REQ_OP_WRITE_SAME :
2084- if (!bdev_write_same ( bio -> bi_bdev ) )
2083+ if (!q -> limits . max_write_same_sectors )
20852084 goto not_supported ;
20862085 break ;
20872086 case REQ_OP_ZONE_REPORT :
20882087 case REQ_OP_ZONE_RESET :
2089- if (!bdev_is_zoned ( bio -> bi_bdev ))
2088+ if (!blk_queue_is_zoned ( q ))
20902089 goto not_supported ;
20912090 break ;
20922091 case REQ_OP_WRITE_ZEROES :
2093- if (!bdev_write_zeroes_sectors ( bio -> bi_bdev ) )
2092+ if (!q -> limits . max_write_zeroes_sectors )
20942093 goto not_supported ;
20952094 break ;
20962095 default :
@@ -2197,7 +2196,7 @@ blk_qc_t generic_make_request(struct bio *bio)
21972196 bio_list_init (& bio_list_on_stack [0 ]);
21982197 current -> bio_list = bio_list_on_stack ;
21992198 do {
2200- struct request_queue * q = bdev_get_queue ( bio -> bi_bdev ) ;
2199+ struct request_queue * q = bio -> bi_disk -> queue ;
22012200
22022201 if (likely (blk_queue_enter (q , bio -> bi_opf & REQ_NOWAIT ) == 0 )) {
22032202 struct bio_list lower , same ;
@@ -2215,7 +2214,7 @@ blk_qc_t generic_make_request(struct bio *bio)
22152214 bio_list_init (& lower );
22162215 bio_list_init (& same );
22172216 while ((bio = bio_list_pop (& bio_list_on_stack [0 ])) != NULL )
2218- if (q == bdev_get_queue ( bio -> bi_bdev ) )
2217+ if (q == bio -> bi_disk -> queue )
22192218 bio_list_add (& same , bio );
22202219 else
22212220 bio_list_add (& lower , bio );
@@ -2258,7 +2257,7 @@ blk_qc_t submit_bio(struct bio *bio)
22582257 unsigned int count ;
22592258
22602259 if (unlikely (bio_op (bio ) == REQ_OP_WRITE_SAME ))
2261- count = bdev_logical_block_size (bio -> bi_bdev ) >> 9 ;
2260+ count = queue_logical_block_size (bio -> bi_disk -> queue ) ;
22622261 else
22632262 count = bio_sectors (bio );
22642263
@@ -2275,8 +2274,7 @@ blk_qc_t submit_bio(struct bio *bio)
22752274 current -> comm , task_pid_nr (current ),
22762275 op_is_write (bio_op (bio )) ? "WRITE" : "READ" ,
22772276 (unsigned long long )bio -> bi_iter .bi_sector ,
2278- bdevname (bio -> bi_bdev , b ),
2279- count );
2277+ bio_devname (bio , b ), count );
22802278 }
22812279 }
22822280
@@ -3049,8 +3047,8 @@ void blk_rq_bio_prep(struct request_queue *q, struct request *rq,
30493047 rq -> __data_len = bio -> bi_iter .bi_size ;
30503048 rq -> bio = rq -> biotail = bio ;
30513049
3052- if (bio -> bi_bdev )
3053- rq -> rq_disk = bio -> bi_bdev -> bd_disk ;
3050+ if (bio -> bi_disk )
3051+ rq -> rq_disk = bio -> bi_disk ;
30543052}
30553053
30563054#if ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE
0 commit comments