1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Portions Copyright (C) 1992 Drew Eckhardt
5 #ifndef _LINUX_BLKDEV_H
6 #define _LINUX_BLKDEV_H
8 #include <linux/types.h>
9 #include <linux/blk_types.h>
10 #include <linux/device.h>
11 #include <linux/list.h>
12 #include <linux/llist.h>
13 #include <linux/minmax.h>
14 #include <linux/timer.h>
15 #include <linux/workqueue.h>
16 #include <linux/wait.h>
17 #include <linux/bio.h>
18 #include <linux/gfp.h>
19 #include <linux/kdev_t.h>
20 #include <linux/rcupdate.h>
21 #include <linux/percpu-refcount.h>
22 #include <linux/blkzoned.h>
23 #include <linux/sched.h>
24 #include <linux/sbitmap.h>
25 #include <linux/srcu.h>
26 #include <linux/uuid.h>
27 #include <linux/xarray.h>
31 struct elevator_queue;
36 struct blk_flush_queue;
40 struct blk_queue_stats;
41 struct blk_stat_callback;
42 struct blk_crypto_profile;
44 extern const struct device_type disk_type;
45 extern struct device_type part_type;
46 extern struct class block_class;
48 /* Must be consistent with blk_mq_poll_stats_bkt() */
49 #define BLK_MQ_POLL_STATS_BKTS 16
51 /* Doing classic polling */
52 #define BLK_MQ_POLL_CLASSIC -1
55 * Maximum number of blkcg policies allowed to be registered concurrently.
56 * Defined here to simplify include dependency.
58 #define BLKCG_MAX_POLS 6
60 #define DISK_MAX_PARTS 256
61 #define DISK_NAME_LEN 32
63 #define PARTITION_META_INFO_VOLNAMELTH 64
65 * Enough for the string representation of any kind of UUID plus NULL.
66 * EFI UUID is 36 characters. MSDOS UUID is 11 characters.
68 #define PARTITION_META_INFO_UUIDLTH (UUID_STRING_LEN + 1)
70 struct partition_meta_info {
71 char uuid[PARTITION_META_INFO_UUIDLTH];
72 u8 volname[PARTITION_META_INFO_VOLNAMELTH];
76 * DOC: genhd capability flags
78 * ``GENHD_FL_REMOVABLE``: indicates that the block device gives access to
79 * removable media. When set, the device remains present even when media is not
80 * inserted. Shall not be set for devices which are removed entirely when the
83 * ``GENHD_FL_HIDDEN``: the block device is hidden; it doesn't produce events,
84 * doesn't appear in sysfs, and can't be opened from userspace or using
85 * blkdev_get*. Used for the underlying components of multipath devices.
87 * ``GENHD_FL_NO_PART``: partition support is disabled. The kernel will not
88 * scan for partitions from add_disk, and users can't add partitions manually.
92 GENHD_FL_REMOVABLE = 1 << 0,
93 GENHD_FL_HIDDEN = 1 << 1,
94 GENHD_FL_NO_PART = 1 << 2,
98 DISK_EVENT_MEDIA_CHANGE = 1 << 0, /* media changed */
99 DISK_EVENT_EJECT_REQUEST = 1 << 1, /* eject requested */
103 /* Poll even if events_poll_msecs is unset */
104 DISK_EVENT_FLAG_POLL = 1 << 0,
105 /* Forward events to udev */
106 DISK_EVENT_FLAG_UEVENT = 1 << 1,
107 /* Block event polling when open for exclusive write */
108 DISK_EVENT_FLAG_BLOCK_ON_EXCL_WRITE = 1 << 2,
114 struct blk_integrity {
115 const struct blk_integrity_profile *profile;
117 unsigned char tuple_size;
118 unsigned char interval_exp;
119 unsigned char tag_size;
124 * major/first_minor/minors should not be set by any new driver, the
125 * block core will take care of allocating them automatically.
131 char disk_name[DISK_NAME_LEN]; /* name of major driver */
133 unsigned short events; /* supported events */
134 unsigned short event_flags; /* flags related to event processing */
136 struct xarray part_tbl;
137 struct block_device *part0;
139 const struct block_device_operations *fops;
140 struct request_queue *queue;
145 #define GD_NEED_PART_SCAN 0
146 #define GD_READ_ONLY 1
148 #define GD_NATIVE_CAPACITY 3
151 struct mutex open_mutex; /* open/close mutex */
152 unsigned open_partitions; /* number of open partitions */
154 struct backing_dev_info *bdi;
155 struct kobject *slave_dir;
156 #ifdef CONFIG_BLOCK_HOLDER_DEPRECATED
157 struct list_head slave_bdevs;
159 struct timer_rand_state *random;
160 atomic_t sync_io; /* RAID */
161 struct disk_events *ev;
162 #ifdef CONFIG_BLK_DEV_INTEGRITY
163 struct kobject integrity_kobj;
164 #endif /* CONFIG_BLK_DEV_INTEGRITY */
165 #if IS_ENABLED(CONFIG_CDROM)
166 struct cdrom_device_info *cdi;
169 struct badblocks *bb;
170 struct lockdep_map lockdep_map;
174 static inline bool disk_live(struct gendisk *disk)
176 return !inode_unhashed(disk->part0->bd_inode);
180 * The gendisk is refcounted by the part0 block_device, and the bd_device
181 * therein is also used for device model presentation in sysfs.
183 #define dev_to_disk(device) \
184 (dev_to_bdev(device)->bd_disk)
185 #define disk_to_dev(disk) \
186 (&((disk)->part0->bd_device))
188 #if IS_REACHABLE(CONFIG_CDROM)
189 #define disk_to_cdi(disk) ((disk)->cdi)
191 #define disk_to_cdi(disk) NULL
194 static inline dev_t disk_devt(struct gendisk *disk)
196 return MKDEV(disk->major, disk->first_minor);
199 static inline int blk_validate_block_size(unsigned long bsize)
201 if (bsize < 512 || bsize > PAGE_SIZE || !is_power_of_2(bsize))
207 static inline bool blk_op_is_passthrough(unsigned int op)
210 return op == REQ_OP_DRV_IN || op == REQ_OP_DRV_OUT;
214 * Zoned block device models (zoned limit).
216 * Note: This needs to be ordered from the least to the most severe
217 * restrictions for the inheritance in blk_stack_limits() to work.
219 enum blk_zoned_model {
220 BLK_ZONED_NONE = 0, /* Regular block device */
221 BLK_ZONED_HA, /* Host-aware zoned block device */
222 BLK_ZONED_HM, /* Host-managed zoned block device */
226 * BLK_BOUNCE_NONE: never bounce (default)
227 * BLK_BOUNCE_HIGH: bounce all highmem pages
234 struct queue_limits {
235 enum blk_bounce bounce;
236 unsigned long seg_boundary_mask;
237 unsigned long virt_boundary_mask;
239 unsigned int max_hw_sectors;
240 unsigned int max_dev_sectors;
241 unsigned int chunk_sectors;
242 unsigned int max_sectors;
243 unsigned int max_segment_size;
244 unsigned int physical_block_size;
245 unsigned int logical_block_size;
246 unsigned int alignment_offset;
249 unsigned int max_discard_sectors;
250 unsigned int max_hw_discard_sectors;
251 unsigned int max_write_zeroes_sectors;
252 unsigned int max_zone_append_sectors;
253 unsigned int discard_granularity;
254 unsigned int discard_alignment;
255 unsigned int zone_write_granularity;
257 unsigned short max_segments;
258 unsigned short max_integrity_segments;
259 unsigned short max_discard_segments;
261 unsigned char misaligned;
262 unsigned char discard_misaligned;
263 unsigned char raid_partial_stripes_expensive;
264 enum blk_zoned_model zoned;
267 typedef int (*report_zones_cb)(struct blk_zone *zone, unsigned int idx,
270 void blk_queue_set_zoned(struct gendisk *disk, enum blk_zoned_model model);
272 #ifdef CONFIG_BLK_DEV_ZONED
274 #define BLK_ALL_ZONES ((unsigned int)-1)
275 int blkdev_report_zones(struct block_device *bdev, sector_t sector,
276 unsigned int nr_zones, report_zones_cb cb, void *data);
277 unsigned int blkdev_nr_zones(struct gendisk *disk);
278 extern int blkdev_zone_mgmt(struct block_device *bdev, enum req_opf op,
279 sector_t sectors, sector_t nr_sectors,
281 int blk_revalidate_disk_zones(struct gendisk *disk,
282 void (*update_driver_data)(struct gendisk *disk));
284 extern int blkdev_report_zones_ioctl(struct block_device *bdev, fmode_t mode,
285 unsigned int cmd, unsigned long arg);
286 extern int blkdev_zone_mgmt_ioctl(struct block_device *bdev, fmode_t mode,
287 unsigned int cmd, unsigned long arg);
289 #else /* CONFIG_BLK_DEV_ZONED */
291 static inline unsigned int blkdev_nr_zones(struct gendisk *disk)
296 static inline int blkdev_report_zones_ioctl(struct block_device *bdev,
297 fmode_t mode, unsigned int cmd,
303 static inline int blkdev_zone_mgmt_ioctl(struct block_device *bdev,
304 fmode_t mode, unsigned int cmd,
310 #endif /* CONFIG_BLK_DEV_ZONED */
313 * Independent access ranges: struct blk_independent_access_range describes
314 * a range of contiguous sectors that can be accessed using device command
315 * execution resources that are independent from the resources used for
316 * other access ranges. This is typically found with single-LUN multi-actuator
317 * HDDs where each access range is served by a different set of heads.
318 * The set of independent ranges supported by the device is defined using
319 * struct blk_independent_access_ranges. The independent ranges must not overlap
320 * and must include all sectors within the disk capacity (no sector holes
322 * For a device with multiple ranges, requests targeting sectors in different
323 * ranges can be executed in parallel. A request can straddle an access range
326 struct blk_independent_access_range {
328 struct request_queue *queue;
333 struct blk_independent_access_ranges {
335 bool sysfs_registered;
336 unsigned int nr_ia_ranges;
337 struct blk_independent_access_range ia_range[];
340 struct request_queue {
341 struct request *last_merge;
342 struct elevator_queue *elevator;
344 struct percpu_ref q_usage_counter;
346 struct blk_queue_stats *stats;
347 struct rq_qos *rq_qos;
349 const struct blk_mq_ops *mq_ops;
352 struct blk_mq_ctx __percpu *queue_ctx;
354 unsigned int queue_depth;
356 /* hw dispatch queues */
357 struct xarray hctx_table;
358 unsigned int nr_hw_queues;
361 * The queue owner gets to use this for whatever they like.
362 * ll_rw_blk doesn't touch it.
367 * various queue flags, see QUEUE_* below
369 unsigned long queue_flags;
371 * Number of contexts that have called blk_set_pm_only(). If this
372 * counter is above zero then only RQF_PM requests are processed.
377 * ida allocated id for this queue. Used to index queues from
382 spinlock_t queue_lock;
384 struct gendisk *disk;
394 struct kobject *mq_kobj;
396 #ifdef CONFIG_BLK_DEV_INTEGRITY
397 struct blk_integrity integrity;
398 #endif /* CONFIG_BLK_DEV_INTEGRITY */
402 enum rpm_status rpm_status;
408 unsigned long nr_requests; /* Max # of requests */
410 unsigned int dma_pad_mask;
411 unsigned int dma_alignment;
413 #ifdef CONFIG_BLK_INLINE_ENCRYPTION
414 struct blk_crypto_profile *crypto_profile;
415 struct kobject *crypto_kobject;
418 unsigned int rq_timeout;
421 struct blk_stat_callback *poll_cb;
422 struct blk_rq_stat *poll_stat;
424 struct timer_list timeout;
425 struct work_struct timeout_work;
427 atomic_t nr_active_requests_shared_tags;
429 struct blk_mq_tags *sched_shared_tags;
431 struct list_head icq_list;
432 #ifdef CONFIG_BLK_CGROUP
433 DECLARE_BITMAP (blkcg_pols, BLKCG_MAX_POLS);
434 struct blkcg_gq *root_blkg;
435 struct list_head blkg_list;
438 struct queue_limits limits;
440 unsigned int required_elevator_features;
442 #ifdef CONFIG_BLK_DEV_ZONED
444 * Zoned block device information for request dispatch control.
445 * nr_zones is the total number of zones of the device. This is always
446 * 0 for regular block devices. conv_zones_bitmap is a bitmap of nr_zones
447 * bits which indicates if a zone is conventional (bit set) or
448 * sequential (bit clear). seq_zones_wlock is a bitmap of nr_zones
449 * bits which indicates if a zone is write locked, that is, if a write
450 * request targeting the zone was dispatched. All three fields are
451 * initialized by the low level device driver (e.g. scsi/sd.c).
452 * Stacking drivers (device mappers) may or may not initialize
455 * Reads of this information must be protected with blk_queue_enter() /
456 * blk_queue_exit(). Modifying this information is only allowed while
457 * no requests are being processed. See also blk_mq_freeze_queue() and
458 * blk_mq_unfreeze_queue().
460 unsigned int nr_zones;
461 unsigned long *conv_zones_bitmap;
462 unsigned long *seq_zones_wlock;
463 unsigned int max_open_zones;
464 unsigned int max_active_zones;
465 #endif /* CONFIG_BLK_DEV_ZONED */
468 struct mutex debugfs_mutex;
469 #ifdef CONFIG_BLK_DEV_IO_TRACE
470 struct blk_trace __rcu *blk_trace;
473 * for flush operations
475 struct blk_flush_queue *fq;
477 struct list_head requeue_list;
478 spinlock_t requeue_lock;
479 struct delayed_work requeue_work;
481 struct mutex sysfs_lock;
482 struct mutex sysfs_dir_lock;
485 * for reusing dead hctx instance in case of updating
488 struct list_head unused_hctx_list;
489 spinlock_t unused_hctx_lock;
493 #ifdef CONFIG_BLK_DEV_THROTTLING
495 struct throtl_data *td;
497 struct rcu_head rcu_head;
498 wait_queue_head_t mq_freeze_wq;
500 * Protect concurrent access to q_usage_counter by
501 * percpu_ref_kill() and percpu_ref_reinit().
503 struct mutex mq_freeze_lock;
507 struct blk_mq_tag_set *tag_set;
508 struct list_head tag_set_list;
509 struct bio_set bio_split;
511 struct dentry *debugfs_dir;
513 #ifdef CONFIG_BLK_DEBUG_FS
514 struct dentry *sched_debugfs_dir;
515 struct dentry *rqos_debugfs_dir;
518 bool mq_sysfs_init_done;
520 #define BLK_MAX_WRITE_HINTS 5
521 u64 write_hints[BLK_MAX_WRITE_HINTS];
524 * Independent sector access ranges. This is always NULL for
525 * devices that do not have multiple independent access ranges.
527 struct blk_independent_access_ranges *ia_ranges;
530 * @srcu: Sleepable RCU. Use as lock when type of the request queue
531 * is blocking (BLK_MQ_F_BLOCKING). Must be the last member
533 struct srcu_struct srcu[];
536 /* Keep blk_queue_flag_name[] in sync with the definitions below */
537 #define QUEUE_FLAG_STOPPED 0 /* queue is stopped */
538 #define QUEUE_FLAG_DYING 1 /* queue being torn down */
539 #define QUEUE_FLAG_HAS_SRCU 2 /* SRCU is allocated */
540 #define QUEUE_FLAG_NOMERGES 3 /* disable merge attempts */
541 #define QUEUE_FLAG_SAME_COMP 4 /* complete on same CPU-group */
542 #define QUEUE_FLAG_FAIL_IO 5 /* fake timeout */
543 #define QUEUE_FLAG_NONROT 6 /* non-rotational device (SSD) */
544 #define QUEUE_FLAG_VIRT QUEUE_FLAG_NONROT /* paravirt device */
545 #define QUEUE_FLAG_IO_STAT 7 /* do disk/partitions IO accounting */
546 #define QUEUE_FLAG_DISCARD 8 /* supports DISCARD */
547 #define QUEUE_FLAG_NOXMERGES 9 /* No extended merges */
548 #define QUEUE_FLAG_ADD_RANDOM 10 /* Contributes to random pool */
549 #define QUEUE_FLAG_SECERASE 11 /* supports secure erase */
550 #define QUEUE_FLAG_SAME_FORCE 12 /* force complete on same CPU */
551 #define QUEUE_FLAG_DEAD 13 /* queue tear-down finished */
552 #define QUEUE_FLAG_INIT_DONE 14 /* queue is initialized */
553 #define QUEUE_FLAG_STABLE_WRITES 15 /* don't modify blks until WB is done */
554 #define QUEUE_FLAG_POLL 16 /* IO polling enabled if set */
555 #define QUEUE_FLAG_WC 17 /* Write back caching */
556 #define QUEUE_FLAG_FUA 18 /* device supports FUA writes */
557 #define QUEUE_FLAG_DAX 19 /* device supports DAX */
558 #define QUEUE_FLAG_STATS 20 /* track IO start and completion times */
559 #define QUEUE_FLAG_REGISTERED 22 /* queue has been registered to a disk */
560 #define QUEUE_FLAG_QUIESCED 24 /* queue has been quiesced */
561 #define QUEUE_FLAG_PCI_P2PDMA 25 /* device supports PCI p2p requests */
562 #define QUEUE_FLAG_ZONE_RESETALL 26 /* supports Zone Reset All */
563 #define QUEUE_FLAG_RQ_ALLOC_TIME 27 /* record rq->alloc_time_ns */
564 #define QUEUE_FLAG_HCTX_ACTIVE 28 /* at least one blk-mq hctx is active */
565 #define QUEUE_FLAG_NOWAIT 29 /* device supports NOWAIT */
567 #define QUEUE_FLAG_MQ_DEFAULT ((1 << QUEUE_FLAG_IO_STAT) | \
568 (1 << QUEUE_FLAG_SAME_COMP) | \
569 (1 << QUEUE_FLAG_NOWAIT))
571 void blk_queue_flag_set(unsigned int flag, struct request_queue *q);
572 void blk_queue_flag_clear(unsigned int flag, struct request_queue *q);
573 bool blk_queue_flag_test_and_set(unsigned int flag, struct request_queue *q);
575 #define blk_queue_stopped(q) test_bit(QUEUE_FLAG_STOPPED, &(q)->queue_flags)
576 #define blk_queue_dying(q) test_bit(QUEUE_FLAG_DYING, &(q)->queue_flags)
577 #define blk_queue_has_srcu(q) test_bit(QUEUE_FLAG_HAS_SRCU, &(q)->queue_flags)
578 #define blk_queue_dead(q) test_bit(QUEUE_FLAG_DEAD, &(q)->queue_flags)
579 #define blk_queue_init_done(q) test_bit(QUEUE_FLAG_INIT_DONE, &(q)->queue_flags)
580 #define blk_queue_nomerges(q) test_bit(QUEUE_FLAG_NOMERGES, &(q)->queue_flags)
581 #define blk_queue_noxmerges(q) \
582 test_bit(QUEUE_FLAG_NOXMERGES, &(q)->queue_flags)
583 #define blk_queue_nonrot(q) test_bit(QUEUE_FLAG_NONROT, &(q)->queue_flags)
584 #define blk_queue_stable_writes(q) \
585 test_bit(QUEUE_FLAG_STABLE_WRITES, &(q)->queue_flags)
586 #define blk_queue_io_stat(q) test_bit(QUEUE_FLAG_IO_STAT, &(q)->queue_flags)
587 #define blk_queue_add_random(q) test_bit(QUEUE_FLAG_ADD_RANDOM, &(q)->queue_flags)
588 #define blk_queue_discard(q) test_bit(QUEUE_FLAG_DISCARD, &(q)->queue_flags)
589 #define blk_queue_zone_resetall(q) \
590 test_bit(QUEUE_FLAG_ZONE_RESETALL, &(q)->queue_flags)
591 #define blk_queue_secure_erase(q) \
592 (test_bit(QUEUE_FLAG_SECERASE, &(q)->queue_flags))
593 #define blk_queue_dax(q) test_bit(QUEUE_FLAG_DAX, &(q)->queue_flags)
594 #define blk_queue_pci_p2pdma(q) \
595 test_bit(QUEUE_FLAG_PCI_P2PDMA, &(q)->queue_flags)
596 #ifdef CONFIG_BLK_RQ_ALLOC_TIME
597 #define blk_queue_rq_alloc_time(q) \
598 test_bit(QUEUE_FLAG_RQ_ALLOC_TIME, &(q)->queue_flags)
600 #define blk_queue_rq_alloc_time(q) false
603 #define blk_noretry_request(rq) \
604 ((rq)->cmd_flags & (REQ_FAILFAST_DEV|REQ_FAILFAST_TRANSPORT| \
605 REQ_FAILFAST_DRIVER))
606 #define blk_queue_quiesced(q) test_bit(QUEUE_FLAG_QUIESCED, &(q)->queue_flags)
607 #define blk_queue_pm_only(q) atomic_read(&(q)->pm_only)
608 #define blk_queue_fua(q) test_bit(QUEUE_FLAG_FUA, &(q)->queue_flags)
609 #define blk_queue_registered(q) test_bit(QUEUE_FLAG_REGISTERED, &(q)->queue_flags)
610 #define blk_queue_nowait(q) test_bit(QUEUE_FLAG_NOWAIT, &(q)->queue_flags)
612 extern void blk_set_pm_only(struct request_queue *q);
613 extern void blk_clear_pm_only(struct request_queue *q);
615 #define list_entry_rq(ptr) list_entry((ptr), struct request, queuelist)
617 #define dma_map_bvec(dev, bv, dir, attrs) \
618 dma_map_page_attrs(dev, (bv)->bv_page, (bv)->bv_offset, (bv)->bv_len, \
621 static inline bool queue_is_mq(struct request_queue *q)
627 static inline enum rpm_status queue_rpm_status(struct request_queue *q)
629 return q->rpm_status;
632 static inline enum rpm_status queue_rpm_status(struct request_queue *q)
638 static inline enum blk_zoned_model
639 blk_queue_zoned_model(struct request_queue *q)
641 if (IS_ENABLED(CONFIG_BLK_DEV_ZONED))
642 return q->limits.zoned;
643 return BLK_ZONED_NONE;
646 static inline bool blk_queue_is_zoned(struct request_queue *q)
648 switch (blk_queue_zoned_model(q)) {
657 static inline sector_t blk_queue_zone_sectors(struct request_queue *q)
659 return blk_queue_is_zoned(q) ? q->limits.chunk_sectors : 0;
662 #ifdef CONFIG_BLK_DEV_ZONED
663 static inline unsigned int blk_queue_nr_zones(struct request_queue *q)
665 return blk_queue_is_zoned(q) ? q->nr_zones : 0;
668 static inline unsigned int blk_queue_zone_no(struct request_queue *q,
671 if (!blk_queue_is_zoned(q))
673 return sector >> ilog2(q->limits.chunk_sectors);
676 static inline bool blk_queue_zone_is_seq(struct request_queue *q,
679 if (!blk_queue_is_zoned(q))
681 if (!q->conv_zones_bitmap)
683 return !test_bit(blk_queue_zone_no(q, sector), q->conv_zones_bitmap);
686 static inline void blk_queue_max_open_zones(struct request_queue *q,
687 unsigned int max_open_zones)
689 q->max_open_zones = max_open_zones;
692 static inline unsigned int queue_max_open_zones(const struct request_queue *q)
694 return q->max_open_zones;
697 static inline void blk_queue_max_active_zones(struct request_queue *q,
698 unsigned int max_active_zones)
700 q->max_active_zones = max_active_zones;
703 static inline unsigned int queue_max_active_zones(const struct request_queue *q)
705 return q->max_active_zones;
707 #else /* CONFIG_BLK_DEV_ZONED */
708 static inline unsigned int blk_queue_nr_zones(struct request_queue *q)
712 static inline bool blk_queue_zone_is_seq(struct request_queue *q,
717 static inline unsigned int blk_queue_zone_no(struct request_queue *q,
722 static inline unsigned int queue_max_open_zones(const struct request_queue *q)
726 static inline unsigned int queue_max_active_zones(const struct request_queue *q)
730 #endif /* CONFIG_BLK_DEV_ZONED */
732 static inline unsigned int blk_queue_depth(struct request_queue *q)
735 return q->queue_depth;
737 return q->nr_requests;
741 * default timeout for SG_IO if none specified
743 #define BLK_DEFAULT_SG_TIMEOUT (60 * HZ)
744 #define BLK_MIN_SG_TIMEOUT (7 * HZ)
746 /* This should not be used directly - use rq_for_each_segment */
747 #define for_each_bio(_bio) \
748 for (; _bio; _bio = _bio->bi_next)
750 int __must_check device_add_disk(struct device *parent, struct gendisk *disk,
751 const struct attribute_group **groups);
752 static inline int __must_check add_disk(struct gendisk *disk)
754 return device_add_disk(NULL, disk, NULL);
756 void del_gendisk(struct gendisk *gp);
757 void invalidate_disk(struct gendisk *disk);
758 void set_disk_ro(struct gendisk *disk, bool read_only);
759 void disk_uevent(struct gendisk *disk, enum kobject_action action);
761 static inline int get_disk_ro(struct gendisk *disk)
763 return disk->part0->bd_read_only ||
764 test_bit(GD_READ_ONLY, &disk->state);
767 static inline int bdev_read_only(struct block_device *bdev)
769 return bdev->bd_read_only || get_disk_ro(bdev->bd_disk);
772 bool set_capacity_and_notify(struct gendisk *disk, sector_t size);
773 bool disk_force_media_change(struct gendisk *disk, unsigned int events);
775 void add_disk_randomness(struct gendisk *disk) __latent_entropy;
776 void rand_initialize_disk(struct gendisk *disk);
778 static inline sector_t get_start_sect(struct block_device *bdev)
780 return bdev->bd_start_sect;
783 static inline sector_t bdev_nr_sectors(struct block_device *bdev)
785 return bdev->bd_nr_sectors;
788 static inline loff_t bdev_nr_bytes(struct block_device *bdev)
790 return (loff_t)bdev_nr_sectors(bdev) << SECTOR_SHIFT;
793 static inline sector_t get_capacity(struct gendisk *disk)
795 return bdev_nr_sectors(disk->part0);
798 static inline u64 sb_bdev_nr_blocks(struct super_block *sb)
800 return bdev_nr_sectors(sb->s_bdev) >>
801 (sb->s_blocksize_bits - SECTOR_SHIFT);
804 int bdev_disk_changed(struct gendisk *disk, bool invalidate);
806 struct gendisk *__alloc_disk_node(struct request_queue *q, int node_id,
807 struct lock_class_key *lkclass);
808 void put_disk(struct gendisk *disk);
809 struct gendisk *__blk_alloc_disk(int node, struct lock_class_key *lkclass);
812 * blk_alloc_disk - allocate a gendisk structure
813 * @node_id: numa node to allocate on
815 * Allocate and pre-initialize a gendisk structure for use with BIO based
820 #define blk_alloc_disk(node_id) \
822 static struct lock_class_key __key; \
824 __blk_alloc_disk(node_id, &__key); \
826 void blk_cleanup_disk(struct gendisk *disk);
828 int __register_blkdev(unsigned int major, const char *name,
829 void (*probe)(dev_t devt));
830 #define register_blkdev(major, name) \
831 __register_blkdev(major, name, NULL)
832 void unregister_blkdev(unsigned int major, const char *name);
834 bool bdev_check_media_change(struct block_device *bdev);
835 int __invalidate_device(struct block_device *bdev, bool kill_dirty);
836 void set_capacity(struct gendisk *disk, sector_t size);
838 #ifdef CONFIG_BLOCK_HOLDER_DEPRECATED
839 int bd_link_disk_holder(struct block_device *bdev, struct gendisk *disk);
840 void bd_unlink_disk_holder(struct block_device *bdev, struct gendisk *disk);
841 int bd_register_pending_holders(struct gendisk *disk);
843 static inline int bd_link_disk_holder(struct block_device *bdev,
844 struct gendisk *disk)
848 static inline void bd_unlink_disk_holder(struct block_device *bdev,
849 struct gendisk *disk)
852 static inline int bd_register_pending_holders(struct gendisk *disk)
856 #endif /* CONFIG_BLOCK_HOLDER_DEPRECATED */
858 dev_t part_devt(struct gendisk *disk, u8 partno);
859 void inc_diskseq(struct gendisk *disk);
860 dev_t blk_lookup_devt(const char *name, int partno);
861 void blk_request_module(dev_t devt);
863 extern int blk_register_queue(struct gendisk *disk);
864 extern void blk_unregister_queue(struct gendisk *disk);
865 void submit_bio_noacct(struct bio *bio);
867 extern int blk_lld_busy(struct request_queue *q);
868 extern void blk_queue_split(struct bio **);
869 extern int blk_queue_enter(struct request_queue *q, blk_mq_req_flags_t flags);
870 extern void blk_queue_exit(struct request_queue *q);
871 extern void blk_sync_queue(struct request_queue *q);
873 /* Helper to convert REQ_OP_XXX to its string format XXX */
874 extern const char *blk_op_str(unsigned int op);
876 int blk_status_to_errno(blk_status_t status);
877 blk_status_t errno_to_blk_status(int errno);
879 /* only poll the hardware once, don't continue until a completion was found */
880 #define BLK_POLL_ONESHOT (1 << 0)
881 /* do not sleep to wait for the expected completion time */
882 #define BLK_POLL_NOSLEEP (1 << 1)
883 int bio_poll(struct bio *bio, struct io_comp_batch *iob, unsigned int flags);
884 int iocb_bio_iopoll(struct kiocb *kiocb, struct io_comp_batch *iob,
887 static inline struct request_queue *bdev_get_queue(struct block_device *bdev)
889 return bdev->bd_queue; /* this is never NULL */
892 #ifdef CONFIG_BLK_DEV_ZONED
894 /* Helper to convert BLK_ZONE_ZONE_XXX to its string format XXX */
895 const char *blk_zone_cond_str(enum blk_zone_cond zone_cond);
897 static inline unsigned int bio_zone_no(struct bio *bio)
899 return blk_queue_zone_no(bdev_get_queue(bio->bi_bdev),
900 bio->bi_iter.bi_sector);
903 static inline unsigned int bio_zone_is_seq(struct bio *bio)
905 return blk_queue_zone_is_seq(bdev_get_queue(bio->bi_bdev),
906 bio->bi_iter.bi_sector);
908 #endif /* CONFIG_BLK_DEV_ZONED */
910 static inline unsigned int blk_queue_get_max_sectors(struct request_queue *q,
913 if (unlikely(op == REQ_OP_DISCARD || op == REQ_OP_SECURE_ERASE))
914 return min(q->limits.max_discard_sectors,
915 UINT_MAX >> SECTOR_SHIFT);
917 if (unlikely(op == REQ_OP_WRITE_ZEROES))
918 return q->limits.max_write_zeroes_sectors;
920 return q->limits.max_sectors;
924 * Return maximum size of a request at given offset. Only valid for
925 * file system requests.
927 static inline unsigned int blk_max_size_offset(struct request_queue *q,
929 unsigned int chunk_sectors)
931 if (!chunk_sectors) {
932 if (q->limits.chunk_sectors)
933 chunk_sectors = q->limits.chunk_sectors;
935 return q->limits.max_sectors;
938 if (likely(is_power_of_2(chunk_sectors)))
939 chunk_sectors -= offset & (chunk_sectors - 1);
941 chunk_sectors -= sector_div(offset, chunk_sectors);
943 return min(q->limits.max_sectors, chunk_sectors);
947 * Access functions for manipulating queue properties
949 extern void blk_cleanup_queue(struct request_queue *);
950 void blk_queue_bounce_limit(struct request_queue *q, enum blk_bounce limit);
951 extern void blk_queue_max_hw_sectors(struct request_queue *, unsigned int);
952 extern void blk_queue_chunk_sectors(struct request_queue *, unsigned int);
953 extern void blk_queue_max_segments(struct request_queue *, unsigned short);
954 extern void blk_queue_max_discard_segments(struct request_queue *,
956 extern void blk_queue_max_segment_size(struct request_queue *, unsigned int);
957 extern void blk_queue_max_discard_sectors(struct request_queue *q,
958 unsigned int max_discard_sectors);
959 extern void blk_queue_max_write_zeroes_sectors(struct request_queue *q,
960 unsigned int max_write_same_sectors);
961 extern void blk_queue_logical_block_size(struct request_queue *, unsigned int);
962 extern void blk_queue_max_zone_append_sectors(struct request_queue *q,
963 unsigned int max_zone_append_sectors);
964 extern void blk_queue_physical_block_size(struct request_queue *, unsigned int);
965 void blk_queue_zone_write_granularity(struct request_queue *q,
967 extern void blk_queue_alignment_offset(struct request_queue *q,
968 unsigned int alignment);
969 void disk_update_readahead(struct gendisk *disk);
970 extern void blk_limits_io_min(struct queue_limits *limits, unsigned int min);
971 extern void blk_queue_io_min(struct request_queue *q, unsigned int min);
972 extern void blk_limits_io_opt(struct queue_limits *limits, unsigned int opt);
973 extern void blk_queue_io_opt(struct request_queue *q, unsigned int opt);
974 extern void blk_set_queue_depth(struct request_queue *q, unsigned int depth);
975 extern void blk_set_default_limits(struct queue_limits *lim);
976 extern void blk_set_stacking_limits(struct queue_limits *lim);
977 extern int blk_stack_limits(struct queue_limits *t, struct queue_limits *b,
979 extern void disk_stack_limits(struct gendisk *disk, struct block_device *bdev,
981 extern void blk_queue_update_dma_pad(struct request_queue *, unsigned int);
982 extern void blk_queue_segment_boundary(struct request_queue *, unsigned long);
983 extern void blk_queue_virt_boundary(struct request_queue *, unsigned long);
984 extern void blk_queue_dma_alignment(struct request_queue *, int);
985 extern void blk_queue_update_dma_alignment(struct request_queue *, int);
986 extern void blk_queue_rq_timeout(struct request_queue *, unsigned int);
987 extern void blk_queue_write_cache(struct request_queue *q, bool enabled, bool fua);
989 struct blk_independent_access_ranges *
990 disk_alloc_independent_access_ranges(struct gendisk *disk, int nr_ia_ranges);
991 void disk_set_independent_access_ranges(struct gendisk *disk,
992 struct blk_independent_access_ranges *iars);
995 * Elevator features for blk_queue_required_elevator_features:
997 /* Supports zoned block devices sequential write constraint */
998 #define ELEVATOR_F_ZBD_SEQ_WRITE (1U << 0)
999 /* Supports scheduling on multiple hardware queues */
1000 #define ELEVATOR_F_MQ_AWARE (1U << 1)
1002 extern void blk_queue_required_elevator_features(struct request_queue *q,
1003 unsigned int features);
1004 extern bool blk_queue_can_use_dma_map_merging(struct request_queue *q,
1005 struct device *dev);
1007 bool __must_check blk_get_queue(struct request_queue *);
1008 extern void blk_put_queue(struct request_queue *);
1010 void blk_mark_disk_dead(struct gendisk *disk);
1014 * blk_plug permits building a queue of related requests by holding the I/O
1015 * fragments for a short period. This allows merging of sequential requests
1016 * into single larger request. As the requests are moved from a per-task list to
1017 * the device's request_queue in a batch, this results in improved scalability
1018 * as the lock contention for request_queue lock is reduced.
1020 * It is ok not to disable preemption when adding the request to the plug list
1021 * or when attempting a merge. For details, please see schedule() where
1022 * blk_flush_plug() is called.
1025 struct request *mq_list; /* blk-mq requests */
1027 /* if ios_left is > 1, we can batch tag/rq allocations */
1028 struct request *cached_rq;
1029 unsigned short nr_ios;
1031 unsigned short rq_count;
1033 bool multiple_queues;
1037 struct list_head cb_list; /* md requires an unplug callback */
1041 typedef void (*blk_plug_cb_fn)(struct blk_plug_cb *, bool);
1042 struct blk_plug_cb {
1043 struct list_head list;
1044 blk_plug_cb_fn callback;
1047 extern struct blk_plug_cb *blk_check_plugged(blk_plug_cb_fn unplug,
1048 void *data, int size);
1049 extern void blk_start_plug(struct blk_plug *);
1050 extern void blk_start_plug_nr_ios(struct blk_plug *, unsigned short);
1051 extern void blk_finish_plug(struct blk_plug *);
1053 void __blk_flush_plug(struct blk_plug *plug, bool from_schedule);
1054 static inline void blk_flush_plug(struct blk_plug *plug, bool async)
1057 __blk_flush_plug(plug, async);
1060 int blkdev_issue_flush(struct block_device *bdev);
1061 long nr_blockdev_pages(void);
1062 #else /* CONFIG_BLOCK */
1066 static inline void blk_start_plug_nr_ios(struct blk_plug *plug,
1067 unsigned short nr_ios)
1071 static inline void blk_start_plug(struct blk_plug *plug)
1075 static inline void blk_finish_plug(struct blk_plug *plug)
1079 static inline void blk_flush_plug(struct blk_plug *plug, bool async)
1083 static inline int blkdev_issue_flush(struct block_device *bdev)
1088 static inline long nr_blockdev_pages(void)
1092 #endif /* CONFIG_BLOCK */
1094 extern void blk_io_schedule(void);
1096 #define BLKDEV_DISCARD_SECURE (1 << 0) /* issue a secure erase */
1098 extern int blkdev_issue_discard(struct block_device *bdev, sector_t sector,
1099 sector_t nr_sects, gfp_t gfp_mask, unsigned long flags);
1100 extern int __blkdev_issue_discard(struct block_device *bdev, sector_t sector,
1101 sector_t nr_sects, gfp_t gfp_mask, int flags,
1104 #define BLKDEV_ZERO_NOUNMAP (1 << 0) /* do not free blocks */
1105 #define BLKDEV_ZERO_NOFALLBACK (1 << 1) /* don't write explicit zeroes */
1107 extern int __blkdev_issue_zeroout(struct block_device *bdev, sector_t sector,
1108 sector_t nr_sects, gfp_t gfp_mask, struct bio **biop,
1110 extern int blkdev_issue_zeroout(struct block_device *bdev, sector_t sector,
1111 sector_t nr_sects, gfp_t gfp_mask, unsigned flags);
1113 static inline int sb_issue_discard(struct super_block *sb, sector_t block,
1114 sector_t nr_blocks, gfp_t gfp_mask, unsigned long flags)
1116 return blkdev_issue_discard(sb->s_bdev,
1117 block << (sb->s_blocksize_bits -
1119 nr_blocks << (sb->s_blocksize_bits -
1123 static inline int sb_issue_zeroout(struct super_block *sb, sector_t block,
1124 sector_t nr_blocks, gfp_t gfp_mask)
1126 return blkdev_issue_zeroout(sb->s_bdev,
1127 block << (sb->s_blocksize_bits -
1129 nr_blocks << (sb->s_blocksize_bits -
1134 static inline bool bdev_is_partition(struct block_device *bdev)
1136 return bdev->bd_partno;
1139 enum blk_default_limits {
1140 BLK_MAX_SEGMENTS = 128,
1141 BLK_SAFE_MAX_SECTORS = 255,
1142 BLK_DEF_MAX_SECTORS = 2560,
1143 BLK_MAX_SEGMENT_SIZE = 65536,
1144 BLK_SEG_BOUNDARY_MASK = 0xFFFFFFFFUL,
1147 static inline unsigned long queue_segment_boundary(const struct request_queue *q)
1149 return q->limits.seg_boundary_mask;
1152 static inline unsigned long queue_virt_boundary(const struct request_queue *q)
1154 return q->limits.virt_boundary_mask;
1157 static inline unsigned int queue_max_sectors(const struct request_queue *q)
1159 return q->limits.max_sectors;
1162 static inline unsigned int queue_max_bytes(struct request_queue *q)
1164 return min_t(unsigned int, queue_max_sectors(q), INT_MAX >> 9) << 9;
1167 static inline unsigned int queue_max_hw_sectors(const struct request_queue *q)
1169 return q->limits.max_hw_sectors;
1172 static inline unsigned short queue_max_segments(const struct request_queue *q)
1174 return q->limits.max_segments;
1177 static inline unsigned short queue_max_discard_segments(const struct request_queue *q)
1179 return q->limits.max_discard_segments;
1182 static inline unsigned int queue_max_segment_size(const struct request_queue *q)
1184 return q->limits.max_segment_size;
1187 static inline unsigned int queue_max_zone_append_sectors(const struct request_queue *q)
1190 const struct queue_limits *l = &q->limits;
1192 return min(l->max_zone_append_sectors, l->max_sectors);
1195 static inline unsigned queue_logical_block_size(const struct request_queue *q)
1199 if (q && q->limits.logical_block_size)
1200 retval = q->limits.logical_block_size;
1205 static inline unsigned int bdev_logical_block_size(struct block_device *bdev)
1207 return queue_logical_block_size(bdev_get_queue(bdev));
1210 static inline unsigned int queue_physical_block_size(const struct request_queue *q)
1212 return q->limits.physical_block_size;
1215 static inline unsigned int bdev_physical_block_size(struct block_device *bdev)
1217 return queue_physical_block_size(bdev_get_queue(bdev));
1220 static inline unsigned int queue_io_min(const struct request_queue *q)
1222 return q->limits.io_min;
1225 static inline int bdev_io_min(struct block_device *bdev)
1227 return queue_io_min(bdev_get_queue(bdev));
1230 static inline unsigned int queue_io_opt(const struct request_queue *q)
1232 return q->limits.io_opt;
1235 static inline int bdev_io_opt(struct block_device *bdev)
1237 return queue_io_opt(bdev_get_queue(bdev));
1240 static inline unsigned int
1241 queue_zone_write_granularity(const struct request_queue *q)
1243 return q->limits.zone_write_granularity;
1246 static inline unsigned int
1247 bdev_zone_write_granularity(struct block_device *bdev)
1249 return queue_zone_write_granularity(bdev_get_queue(bdev));
1252 static inline int queue_alignment_offset(const struct request_queue *q)
1254 if (q->limits.misaligned)
1257 return q->limits.alignment_offset;
1260 static inline int queue_limit_alignment_offset(struct queue_limits *lim, sector_t sector)
1262 unsigned int granularity = max(lim->physical_block_size, lim->io_min);
1263 unsigned int alignment = sector_div(sector, granularity >> SECTOR_SHIFT)
1266 return (granularity + lim->alignment_offset - alignment) % granularity;
1269 static inline int bdev_alignment_offset(struct block_device *bdev)
1271 struct request_queue *q = bdev_get_queue(bdev);
1273 if (q->limits.misaligned)
1275 if (bdev_is_partition(bdev))
1276 return queue_limit_alignment_offset(&q->limits,
1277 bdev->bd_start_sect);
1278 return q->limits.alignment_offset;
1281 static inline int queue_discard_alignment(const struct request_queue *q)
1283 if (q->limits.discard_misaligned)
1286 return q->limits.discard_alignment;
1289 static inline int queue_limit_discard_alignment(struct queue_limits *lim, sector_t sector)
1291 unsigned int alignment, granularity, offset;
1293 if (!lim->max_discard_sectors)
1296 /* Why are these in bytes, not sectors? */
1297 alignment = lim->discard_alignment >> SECTOR_SHIFT;
1298 granularity = lim->discard_granularity >> SECTOR_SHIFT;
1302 /* Offset of the partition start in 'granularity' sectors */
1303 offset = sector_div(sector, granularity);
1305 /* And why do we do this modulus *again* in blkdev_issue_discard()? */
1306 offset = (granularity + alignment - offset) % granularity;
1308 /* Turn it back into bytes, gaah */
1309 return offset << SECTOR_SHIFT;
1312 static inline int bdev_discard_alignment(struct block_device *bdev)
1314 struct request_queue *q = bdev_get_queue(bdev);
1316 if (bdev_is_partition(bdev))
1317 return queue_limit_discard_alignment(&q->limits,
1318 bdev->bd_start_sect);
1319 return q->limits.discard_alignment;
1322 static inline unsigned int bdev_write_zeroes_sectors(struct block_device *bdev)
1324 struct request_queue *q = bdev_get_queue(bdev);
1327 return q->limits.max_write_zeroes_sectors;
1332 static inline enum blk_zoned_model bdev_zoned_model(struct block_device *bdev)
1334 struct request_queue *q = bdev_get_queue(bdev);
1337 return blk_queue_zoned_model(q);
1339 return BLK_ZONED_NONE;
1342 static inline bool bdev_is_zoned(struct block_device *bdev)
1344 struct request_queue *q = bdev_get_queue(bdev);
1347 return blk_queue_is_zoned(q);
1352 static inline sector_t bdev_zone_sectors(struct block_device *bdev)
1354 struct request_queue *q = bdev_get_queue(bdev);
1357 return blk_queue_zone_sectors(q);
1361 static inline unsigned int bdev_max_open_zones(struct block_device *bdev)
1363 struct request_queue *q = bdev_get_queue(bdev);
1366 return queue_max_open_zones(q);
1370 static inline unsigned int bdev_max_active_zones(struct block_device *bdev)
1372 struct request_queue *q = bdev_get_queue(bdev);
1375 return queue_max_active_zones(q);
1379 static inline int queue_dma_alignment(const struct request_queue *q)
1381 return q ? q->dma_alignment : 511;
1384 static inline int blk_rq_aligned(struct request_queue *q, unsigned long addr,
1387 unsigned int alignment = queue_dma_alignment(q) | q->dma_pad_mask;
1388 return !(addr & alignment) && !(len & alignment);
1391 /* assumes size > 256 */
1392 static inline unsigned int blksize_bits(unsigned int size)
1394 unsigned int bits = 8;
1398 } while (size > 256);
1402 static inline unsigned int block_size(struct block_device *bdev)
1404 return 1 << bdev->bd_inode->i_blkbits;
1407 int kblockd_schedule_work(struct work_struct *work);
1408 int kblockd_mod_delayed_work_on(int cpu, struct delayed_work *dwork, unsigned long delay);
1410 #define MODULE_ALIAS_BLOCKDEV(major,minor) \
1411 MODULE_ALIAS("block-major-" __stringify(major) "-" __stringify(minor))
1412 #define MODULE_ALIAS_BLOCKDEV_MAJOR(major) \
1413 MODULE_ALIAS("block-major-" __stringify(major) "-*")
1415 #ifdef CONFIG_BLK_INLINE_ENCRYPTION
1417 bool blk_crypto_register(struct blk_crypto_profile *profile,
1418 struct request_queue *q);
1420 #else /* CONFIG_BLK_INLINE_ENCRYPTION */
1422 static inline bool blk_crypto_register(struct blk_crypto_profile *profile,
1423 struct request_queue *q)
1428 #endif /* CONFIG_BLK_INLINE_ENCRYPTION */
1430 enum blk_unique_id {
1431 /* these match the Designator Types specified in SPC */
1437 #define NFL4_UFLG_MASK 0x0000003F
1439 struct block_device_operations {
1440 void (*submit_bio)(struct bio *bio);
1441 int (*poll_bio)(struct bio *bio, struct io_comp_batch *iob,
1442 unsigned int flags);
1443 int (*open) (struct block_device *, fmode_t);
1444 void (*release) (struct gendisk *, fmode_t);
1445 int (*rw_page)(struct block_device *, sector_t, struct page *, unsigned int);
1446 int (*ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
1447 int (*compat_ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
1448 unsigned int (*check_events) (struct gendisk *disk,
1449 unsigned int clearing);
1450 void (*unlock_native_capacity) (struct gendisk *);
1451 int (*getgeo)(struct block_device *, struct hd_geometry *);
1452 int (*set_read_only)(struct block_device *bdev, bool ro);
1453 void (*free_disk)(struct gendisk *disk);
1454 /* this callback is with swap_lock and sometimes page table lock held */
1455 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
1456 int (*report_zones)(struct gendisk *, sector_t sector,
1457 unsigned int nr_zones, report_zones_cb cb, void *data);
1458 char *(*devnode)(struct gendisk *disk, umode_t *mode);
1459 /* returns the length of the identifier or a negative errno: */
1460 int (*get_unique_id)(struct gendisk *disk, u8 id[16],
1461 enum blk_unique_id id_type);
1462 struct module *owner;
1463 const struct pr_ops *pr_ops;
1466 * Special callback for probing GPT entry at a given sector.
1467 * Needed by Android devices, used by GPT scanner and MMC blk
1470 int (*alternative_gpt_sector)(struct gendisk *disk, sector_t *sector);
1473 #ifdef CONFIG_COMPAT
1474 extern int blkdev_compat_ptr_ioctl(struct block_device *, fmode_t,
1475 unsigned int, unsigned long);
1477 #define blkdev_compat_ptr_ioctl NULL
1480 extern int bdev_read_page(struct block_device *, sector_t, struct page *);
1481 extern int bdev_write_page(struct block_device *, sector_t, struct page *,
1482 struct writeback_control *);
1484 static inline void blk_wake_io_task(struct task_struct *waiter)
1487 * If we're polling, the task itself is doing the completions. For
1488 * that case, we don't need to signal a wakeup, it's enough to just
1489 * mark us as RUNNING.
1491 if (waiter == current)
1492 __set_current_state(TASK_RUNNING);
1494 wake_up_process(waiter);
1497 unsigned long disk_start_io_acct(struct gendisk *disk, unsigned int sectors,
1499 void disk_end_io_acct(struct gendisk *disk, unsigned int op,
1500 unsigned long start_time);
1502 void bio_start_io_acct_time(struct bio *bio, unsigned long start_time);
1503 unsigned long bio_start_io_acct(struct bio *bio);
1504 void bio_end_io_acct_remapped(struct bio *bio, unsigned long start_time,
1505 struct block_device *orig_bdev);
1508 * bio_end_io_acct - end I/O accounting for bio based drivers
1509 * @bio: bio to end account for
1510 * @start_time: start time returned by bio_start_io_acct()
1512 static inline void bio_end_io_acct(struct bio *bio, unsigned long start_time)
1514 return bio_end_io_acct_remapped(bio, start_time, bio->bi_bdev);
1517 int bdev_read_only(struct block_device *bdev);
1518 int set_blocksize(struct block_device *bdev, int size);
1520 const char *bdevname(struct block_device *bdev, char *buffer);
1521 int lookup_bdev(const char *pathname, dev_t *dev);
1523 void blkdev_show(struct seq_file *seqf, off_t offset);
1525 #define BDEVNAME_SIZE 32 /* Largest string for a blockdev identifier */
1526 #define BDEVT_SIZE 10 /* Largest string for MAJ:MIN for blkdev */
1528 #define BLKDEV_MAJOR_MAX 512
1530 #define BLKDEV_MAJOR_MAX 0
1533 struct block_device *blkdev_get_by_path(const char *path, fmode_t mode,
1535 struct block_device *blkdev_get_by_dev(dev_t dev, fmode_t mode, void *holder);
1536 int bd_prepare_to_claim(struct block_device *bdev, void *holder);
1537 void bd_abort_claiming(struct block_device *bdev, void *holder);
1538 void blkdev_put(struct block_device *bdev, fmode_t mode);
1540 /* just for blk-cgroup, don't use elsewhere */
1541 struct block_device *blkdev_get_no_open(dev_t dev);
1542 void blkdev_put_no_open(struct block_device *bdev);
1544 struct block_device *bdev_alloc(struct gendisk *disk, u8 partno);
1545 void bdev_add(struct block_device *bdev, dev_t dev);
1546 struct block_device *I_BDEV(struct inode *inode);
1547 int truncate_bdev_range(struct block_device *bdev, fmode_t mode, loff_t lstart,
1551 void invalidate_bdev(struct block_device *bdev);
1552 int sync_blockdev(struct block_device *bdev);
1553 int sync_blockdev_nowait(struct block_device *bdev);
1554 void sync_bdevs(bool wait);
1555 void printk_all_partitions(void);
1557 static inline void invalidate_bdev(struct block_device *bdev)
1560 static inline int sync_blockdev(struct block_device *bdev)
1564 static inline int sync_blockdev_nowait(struct block_device *bdev)
1568 static inline void sync_bdevs(bool wait)
1571 static inline void printk_all_partitions(void)
1574 #endif /* CONFIG_BLOCK */
1576 int fsync_bdev(struct block_device *bdev);
1578 int freeze_bdev(struct block_device *bdev);
1579 int thaw_bdev(struct block_device *bdev);
1581 struct io_comp_batch {
1582 struct request *req_list;
1584 void (*complete)(struct io_comp_batch *);
1587 #define DEFINE_IO_COMP_BATCH(name) struct io_comp_batch name = { }
1589 #endif /* _LINUX_BLKDEV_H */