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/uuid.h>
26 #include <linux/xarray.h>
27 #include <linux/file.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 const struct device_type part_type;
46 extern const struct class block_class;
49 * Maximum number of blkcg policies allowed to be registered concurrently.
50 * Defined here to simplify include dependency.
52 #define BLKCG_MAX_POLS 6
54 #define DISK_MAX_PARTS 256
55 #define DISK_NAME_LEN 32
57 #define PARTITION_META_INFO_VOLNAMELTH 64
59 * Enough for the string representation of any kind of UUID plus NULL.
60 * EFI UUID is 36 characters. MSDOS UUID is 11 characters.
62 #define PARTITION_META_INFO_UUIDLTH (UUID_STRING_LEN + 1)
64 struct partition_meta_info {
65 char uuid[PARTITION_META_INFO_UUIDLTH];
66 u8 volname[PARTITION_META_INFO_VOLNAMELTH];
70 * DOC: genhd capability flags
72 * ``GENHD_FL_REMOVABLE``: indicates that the block device gives access to
73 * removable media. When set, the device remains present even when media is not
74 * inserted. Shall not be set for devices which are removed entirely when the
77 * ``GENHD_FL_HIDDEN``: the block device is hidden; it doesn't produce events,
78 * doesn't appear in sysfs, and can't be opened from userspace or using
79 * blkdev_get*. Used for the underlying components of multipath devices.
81 * ``GENHD_FL_NO_PART``: partition support is disabled. The kernel will not
82 * scan for partitions from add_disk, and users can't add partitions manually.
86 GENHD_FL_REMOVABLE = 1 << 0,
87 GENHD_FL_HIDDEN = 1 << 1,
88 GENHD_FL_NO_PART = 1 << 2,
92 DISK_EVENT_MEDIA_CHANGE = 1 << 0, /* media changed */
93 DISK_EVENT_EJECT_REQUEST = 1 << 1, /* eject requested */
97 /* Poll even if events_poll_msecs is unset */
98 DISK_EVENT_FLAG_POLL = 1 << 0,
99 /* Forward events to udev */
100 DISK_EVENT_FLAG_UEVENT = 1 << 1,
101 /* Block event polling when open for exclusive write */
102 DISK_EVENT_FLAG_BLOCK_ON_EXCL_WRITE = 1 << 2,
108 struct blk_integrity {
109 const struct blk_integrity_profile *profile;
111 unsigned char tuple_size;
112 unsigned char pi_offset;
113 unsigned char interval_exp;
114 unsigned char tag_size;
117 typedef unsigned int __bitwise blk_mode_t;
119 /* open for reading */
120 #define BLK_OPEN_READ ((__force blk_mode_t)(1 << 0))
121 /* open for writing */
122 #define BLK_OPEN_WRITE ((__force blk_mode_t)(1 << 1))
123 /* open exclusively (vs other exclusive openers */
124 #define BLK_OPEN_EXCL ((__force blk_mode_t)(1 << 2))
125 /* opened with O_NDELAY */
126 #define BLK_OPEN_NDELAY ((__force blk_mode_t)(1 << 3))
127 /* open for "writes" only for ioctls (specialy hack for floppy.c) */
128 #define BLK_OPEN_WRITE_IOCTL ((__force blk_mode_t)(1 << 4))
129 /* open is exclusive wrt all other BLK_OPEN_WRITE opens to the device */
130 #define BLK_OPEN_RESTRICT_WRITES ((__force blk_mode_t)(1 << 5))
134 * major/first_minor/minors should not be set by any new driver, the
135 * block core will take care of allocating them automatically.
141 char disk_name[DISK_NAME_LEN]; /* name of major driver */
143 unsigned short events; /* supported events */
144 unsigned short event_flags; /* flags related to event processing */
146 struct xarray part_tbl;
147 struct block_device *part0;
149 const struct block_device_operations *fops;
150 struct request_queue *queue;
153 struct bio_set bio_split;
157 #define GD_NEED_PART_SCAN 0
158 #define GD_READ_ONLY 1
160 #define GD_NATIVE_CAPACITY 3
162 #define GD_SUPPRESS_PART_SCAN 5
163 #define GD_OWNS_QUEUE 6
165 struct mutex open_mutex; /* open/close mutex */
166 unsigned open_partitions; /* number of open partitions */
168 struct backing_dev_info *bdi;
169 struct kobject queue_kobj; /* the queue/ directory */
170 struct kobject *slave_dir;
171 #ifdef CONFIG_BLOCK_HOLDER_DEPRECATED
172 struct list_head slave_bdevs;
174 struct timer_rand_state *random;
175 atomic_t sync_io; /* RAID */
176 struct disk_events *ev;
178 #ifdef CONFIG_BLK_DEV_ZONED
180 * Zoned block device information for request dispatch control.
181 * nr_zones is the total number of zones of the device. This is always
182 * 0 for regular block devices. conv_zones_bitmap is a bitmap of nr_zones
183 * bits which indicates if a zone is conventional (bit set) or
184 * sequential (bit clear). seq_zones_wlock is a bitmap of nr_zones
185 * bits which indicates if a zone is write locked, that is, if a write
186 * request targeting the zone was dispatched.
188 * Reads of this information must be protected with blk_queue_enter() /
189 * blk_queue_exit(). Modifying this information is only allowed while
190 * no requests are being processed. See also blk_mq_freeze_queue() and
191 * blk_mq_unfreeze_queue().
193 unsigned int nr_zones;
194 unsigned int zone_capacity;
195 unsigned long *conv_zones_bitmap;
196 unsigned long *seq_zones_wlock;
197 unsigned int zone_wplugs_hash_bits;
198 spinlock_t zone_wplugs_lock;
199 struct mempool_s *zone_wplugs_pool;
200 struct hlist_head *zone_wplugs_hash;
201 struct list_head zone_wplugs_err_list;
202 struct work_struct zone_wplugs_work;
203 #endif /* CONFIG_BLK_DEV_ZONED */
205 #if IS_ENABLED(CONFIG_CDROM)
206 struct cdrom_device_info *cdi;
209 struct badblocks *bb;
210 struct lockdep_map lockdep_map;
212 blk_mode_t open_mode;
215 * Independent sector access ranges. This is always NULL for
216 * devices that do not have multiple independent access ranges.
218 struct blk_independent_access_ranges *ia_ranges;
221 static inline bool disk_live(struct gendisk *disk)
223 return !inode_unhashed(disk->part0->bd_inode);
227 * disk_openers - returns how many openers are there for a disk
228 * @disk: disk to check
230 * This returns the number of openers for a disk. Note that this value is only
231 * stable if disk->open_mutex is held.
233 * Note: Due to a quirk in the block layer open code, each open partition is
234 * only counted once even if there are multiple openers.
236 static inline unsigned int disk_openers(struct gendisk *disk)
238 return atomic_read(&disk->part0->bd_openers);
242 * The gendisk is refcounted by the part0 block_device, and the bd_device
243 * therein is also used for device model presentation in sysfs.
245 #define dev_to_disk(device) \
246 (dev_to_bdev(device)->bd_disk)
247 #define disk_to_dev(disk) \
248 (&((disk)->part0->bd_device))
250 #if IS_REACHABLE(CONFIG_CDROM)
251 #define disk_to_cdi(disk) ((disk)->cdi)
253 #define disk_to_cdi(disk) NULL
256 static inline dev_t disk_devt(struct gendisk *disk)
258 return MKDEV(disk->major, disk->first_minor);
261 static inline int blk_validate_block_size(unsigned long bsize)
263 if (bsize < 512 || bsize > PAGE_SIZE || !is_power_of_2(bsize))
269 static inline bool blk_op_is_passthrough(blk_opf_t op)
272 return op == REQ_OP_DRV_IN || op == REQ_OP_DRV_OUT;
276 * BLK_BOUNCE_NONE: never bounce (default)
277 * BLK_BOUNCE_HIGH: bounce all highmem pages
284 struct queue_limits {
285 enum blk_bounce bounce;
286 unsigned long seg_boundary_mask;
287 unsigned long virt_boundary_mask;
289 unsigned int max_hw_sectors;
290 unsigned int max_dev_sectors;
291 unsigned int chunk_sectors;
292 unsigned int max_sectors;
293 unsigned int max_user_sectors;
294 unsigned int max_segment_size;
295 unsigned int physical_block_size;
296 unsigned int logical_block_size;
297 unsigned int alignment_offset;
300 unsigned int max_discard_sectors;
301 unsigned int max_hw_discard_sectors;
302 unsigned int max_user_discard_sectors;
303 unsigned int max_secure_erase_sectors;
304 unsigned int max_write_zeroes_sectors;
305 unsigned int max_zone_append_sectors;
306 unsigned int discard_granularity;
307 unsigned int discard_alignment;
308 unsigned int zone_write_granularity;
310 unsigned short max_segments;
311 unsigned short max_integrity_segments;
312 unsigned short max_discard_segments;
314 unsigned char misaligned;
315 unsigned char discard_misaligned;
316 unsigned char raid_partial_stripes_expensive;
318 unsigned int max_open_zones;
319 unsigned int max_active_zones;
322 * Drivers that set dma_alignment to less than 511 must be prepared to
323 * handle individual bvec's that are not a multiple of a SECTOR_SIZE
324 * due to possible offsets.
326 unsigned int dma_alignment;
329 typedef int (*report_zones_cb)(struct blk_zone *zone, unsigned int idx,
332 void disk_set_zoned(struct gendisk *disk);
334 #define BLK_ALL_ZONES ((unsigned int)-1)
335 int blkdev_report_zones(struct block_device *bdev, sector_t sector,
336 unsigned int nr_zones, report_zones_cb cb, void *data);
337 int blkdev_zone_mgmt(struct block_device *bdev, enum req_op op,
338 sector_t sectors, sector_t nr_sectors);
339 int blk_revalidate_disk_zones(struct gendisk *disk);
342 * Independent access ranges: struct blk_independent_access_range describes
343 * a range of contiguous sectors that can be accessed using device command
344 * execution resources that are independent from the resources used for
345 * other access ranges. This is typically found with single-LUN multi-actuator
346 * HDDs where each access range is served by a different set of heads.
347 * The set of independent ranges supported by the device is defined using
348 * struct blk_independent_access_ranges. The independent ranges must not overlap
349 * and must include all sectors within the disk capacity (no sector holes
351 * For a device with multiple ranges, requests targeting sectors in different
352 * ranges can be executed in parallel. A request can straddle an access range
355 struct blk_independent_access_range {
361 struct blk_independent_access_ranges {
363 bool sysfs_registered;
364 unsigned int nr_ia_ranges;
365 struct blk_independent_access_range ia_range[];
368 struct request_queue {
370 * The queue owner gets to use this for whatever they like.
371 * ll_rw_blk doesn't touch it.
375 struct elevator_queue *elevator;
377 const struct blk_mq_ops *mq_ops;
380 struct blk_mq_ctx __percpu *queue_ctx;
383 * various queue flags, see QUEUE_* below
385 unsigned long queue_flags;
387 unsigned int rq_timeout;
389 unsigned int queue_depth;
393 /* hw dispatch queues */
394 unsigned int nr_hw_queues;
395 struct xarray hctx_table;
397 struct percpu_ref q_usage_counter;
399 struct request *last_merge;
401 spinlock_t queue_lock;
405 struct gendisk *disk;
410 struct kobject *mq_kobj;
412 struct queue_limits limits;
414 #ifdef CONFIG_BLK_DEV_INTEGRITY
415 struct blk_integrity integrity;
416 #endif /* CONFIG_BLK_DEV_INTEGRITY */
420 enum rpm_status rpm_status;
424 * Number of contexts that have called blk_set_pm_only(). If this
425 * counter is above zero then only RQF_PM requests are processed.
429 struct blk_queue_stats *stats;
430 struct rq_qos *rq_qos;
431 struct mutex rq_qos_mutex;
434 * ida allocated id for this queue. Used to index queues from
439 unsigned int dma_pad_mask;
444 unsigned long nr_requests; /* Max # of requests */
446 #ifdef CONFIG_BLK_INLINE_ENCRYPTION
447 struct blk_crypto_profile *crypto_profile;
448 struct kobject *crypto_kobject;
451 struct timer_list timeout;
452 struct work_struct timeout_work;
454 atomic_t nr_active_requests_shared_tags;
456 unsigned int required_elevator_features;
458 struct blk_mq_tags *sched_shared_tags;
460 struct list_head icq_list;
461 #ifdef CONFIG_BLK_CGROUP
462 DECLARE_BITMAP (blkcg_pols, BLKCG_MAX_POLS);
463 struct blkcg_gq *root_blkg;
464 struct list_head blkg_list;
465 struct mutex blkcg_mutex;
470 spinlock_t requeue_lock;
471 struct list_head requeue_list;
472 struct delayed_work requeue_work;
474 #ifdef CONFIG_BLK_DEV_IO_TRACE
475 struct blk_trace __rcu *blk_trace;
478 * for flush operations
480 struct blk_flush_queue *fq;
481 struct list_head flush_list;
483 struct mutex sysfs_lock;
484 struct mutex sysfs_dir_lock;
485 struct mutex limits_lock;
488 * for reusing dead hctx instance in case of updating
491 struct list_head unused_hctx_list;
492 spinlock_t unused_hctx_lock;
496 #ifdef CONFIG_BLK_DEV_THROTTLING
498 struct throtl_data *td;
500 struct rcu_head rcu_head;
501 wait_queue_head_t mq_freeze_wq;
503 * Protect concurrent access to q_usage_counter by
504 * percpu_ref_kill() and percpu_ref_reinit().
506 struct mutex mq_freeze_lock;
508 struct blk_mq_tag_set *tag_set;
509 struct list_head tag_set_list;
511 struct dentry *debugfs_dir;
512 struct dentry *sched_debugfs_dir;
513 struct dentry *rqos_debugfs_dir;
515 * Serializes all debugfs metadata operations using the above dentries.
517 struct mutex debugfs_mutex;
519 bool mq_sysfs_init_done;
522 /* Keep blk_queue_flag_name[] in sync with the definitions below */
523 #define QUEUE_FLAG_STOPPED 0 /* queue is stopped */
524 #define QUEUE_FLAG_DYING 1 /* queue being torn down */
525 #define QUEUE_FLAG_NOMERGES 3 /* disable merge attempts */
526 #define QUEUE_FLAG_SAME_COMP 4 /* complete on same CPU-group */
527 #define QUEUE_FLAG_FAIL_IO 5 /* fake timeout */
528 #define QUEUE_FLAG_NONROT 6 /* non-rotational device (SSD) */
529 #define QUEUE_FLAG_VIRT QUEUE_FLAG_NONROT /* paravirt device */
530 #define QUEUE_FLAG_IO_STAT 7 /* do disk/partitions IO accounting */
531 #define QUEUE_FLAG_NOXMERGES 9 /* No extended merges */
532 #define QUEUE_FLAG_ADD_RANDOM 10 /* Contributes to random pool */
533 #define QUEUE_FLAG_SYNCHRONOUS 11 /* always completes in submit context */
534 #define QUEUE_FLAG_SAME_FORCE 12 /* force complete on same CPU */
535 #define QUEUE_FLAG_HW_WC 13 /* Write back caching supported */
536 #define QUEUE_FLAG_INIT_DONE 14 /* queue is initialized */
537 #define QUEUE_FLAG_STABLE_WRITES 15 /* don't modify blks until WB is done */
538 #define QUEUE_FLAG_POLL 16 /* IO polling enabled if set */
539 #define QUEUE_FLAG_WC 17 /* Write back caching */
540 #define QUEUE_FLAG_FUA 18 /* device supports FUA writes */
541 #define QUEUE_FLAG_DAX 19 /* device supports DAX */
542 #define QUEUE_FLAG_STATS 20 /* track IO start and completion times */
543 #define QUEUE_FLAG_REGISTERED 22 /* queue has been registered to a disk */
544 #define QUEUE_FLAG_QUIESCED 24 /* queue has been quiesced */
545 #define QUEUE_FLAG_PCI_P2PDMA 25 /* device supports PCI p2p requests */
546 #define QUEUE_FLAG_ZONE_RESETALL 26 /* supports Zone Reset All */
547 #define QUEUE_FLAG_RQ_ALLOC_TIME 27 /* record rq->alloc_time_ns */
548 #define QUEUE_FLAG_HCTX_ACTIVE 28 /* at least one blk-mq hctx is active */
549 #define QUEUE_FLAG_NOWAIT 29 /* device supports NOWAIT */
550 #define QUEUE_FLAG_SQ_SCHED 30 /* single queue style io dispatch */
551 #define QUEUE_FLAG_SKIP_TAGSET_QUIESCE 31 /* quiesce_tagset skip the queue*/
553 #define QUEUE_FLAG_MQ_DEFAULT ((1UL << QUEUE_FLAG_IO_STAT) | \
554 (1UL << QUEUE_FLAG_SAME_COMP) | \
555 (1UL << QUEUE_FLAG_NOWAIT))
557 void blk_queue_flag_set(unsigned int flag, struct request_queue *q);
558 void blk_queue_flag_clear(unsigned int flag, struct request_queue *q);
559 bool blk_queue_flag_test_and_set(unsigned int flag, struct request_queue *q);
561 #define blk_queue_stopped(q) test_bit(QUEUE_FLAG_STOPPED, &(q)->queue_flags)
562 #define blk_queue_dying(q) test_bit(QUEUE_FLAG_DYING, &(q)->queue_flags)
563 #define blk_queue_init_done(q) test_bit(QUEUE_FLAG_INIT_DONE, &(q)->queue_flags)
564 #define blk_queue_nomerges(q) test_bit(QUEUE_FLAG_NOMERGES, &(q)->queue_flags)
565 #define blk_queue_noxmerges(q) \
566 test_bit(QUEUE_FLAG_NOXMERGES, &(q)->queue_flags)
567 #define blk_queue_nonrot(q) test_bit(QUEUE_FLAG_NONROT, &(q)->queue_flags)
568 #define blk_queue_stable_writes(q) \
569 test_bit(QUEUE_FLAG_STABLE_WRITES, &(q)->queue_flags)
570 #define blk_queue_io_stat(q) test_bit(QUEUE_FLAG_IO_STAT, &(q)->queue_flags)
571 #define blk_queue_add_random(q) test_bit(QUEUE_FLAG_ADD_RANDOM, &(q)->queue_flags)
572 #define blk_queue_zone_resetall(q) \
573 test_bit(QUEUE_FLAG_ZONE_RESETALL, &(q)->queue_flags)
574 #define blk_queue_dax(q) test_bit(QUEUE_FLAG_DAX, &(q)->queue_flags)
575 #define blk_queue_pci_p2pdma(q) \
576 test_bit(QUEUE_FLAG_PCI_P2PDMA, &(q)->queue_flags)
577 #ifdef CONFIG_BLK_RQ_ALLOC_TIME
578 #define blk_queue_rq_alloc_time(q) \
579 test_bit(QUEUE_FLAG_RQ_ALLOC_TIME, &(q)->queue_flags)
581 #define blk_queue_rq_alloc_time(q) false
584 #define blk_noretry_request(rq) \
585 ((rq)->cmd_flags & (REQ_FAILFAST_DEV|REQ_FAILFAST_TRANSPORT| \
586 REQ_FAILFAST_DRIVER))
587 #define blk_queue_quiesced(q) test_bit(QUEUE_FLAG_QUIESCED, &(q)->queue_flags)
588 #define blk_queue_pm_only(q) atomic_read(&(q)->pm_only)
589 #define blk_queue_registered(q) test_bit(QUEUE_FLAG_REGISTERED, &(q)->queue_flags)
590 #define blk_queue_sq_sched(q) test_bit(QUEUE_FLAG_SQ_SCHED, &(q)->queue_flags)
591 #define blk_queue_skip_tagset_quiesce(q) \
592 test_bit(QUEUE_FLAG_SKIP_TAGSET_QUIESCE, &(q)->queue_flags)
594 extern void blk_set_pm_only(struct request_queue *q);
595 extern void blk_clear_pm_only(struct request_queue *q);
597 #define list_entry_rq(ptr) list_entry((ptr), struct request, queuelist)
599 #define dma_map_bvec(dev, bv, dir, attrs) \
600 dma_map_page_attrs(dev, (bv)->bv_page, (bv)->bv_offset, (bv)->bv_len, \
603 static inline bool queue_is_mq(struct request_queue *q)
609 static inline enum rpm_status queue_rpm_status(struct request_queue *q)
611 return q->rpm_status;
614 static inline enum rpm_status queue_rpm_status(struct request_queue *q)
620 static inline bool blk_queue_is_zoned(struct request_queue *q)
622 return IS_ENABLED(CONFIG_BLK_DEV_ZONED) && q->limits.zoned;
625 #ifdef CONFIG_BLK_DEV_ZONED
626 unsigned int bdev_nr_zones(struct block_device *bdev);
628 static inline unsigned int disk_nr_zones(struct gendisk *disk)
630 return blk_queue_is_zoned(disk->queue) ? disk->nr_zones : 0;
633 static inline unsigned int disk_zone_no(struct gendisk *disk, sector_t sector)
635 if (!blk_queue_is_zoned(disk->queue))
637 return sector >> ilog2(disk->queue->limits.chunk_sectors);
640 static inline bool disk_zone_is_seq(struct gendisk *disk, sector_t sector)
642 if (!blk_queue_is_zoned(disk->queue))
644 if (!disk->conv_zones_bitmap)
646 return !test_bit(disk_zone_no(disk, sector), disk->conv_zones_bitmap);
649 static inline void disk_set_max_open_zones(struct gendisk *disk,
650 unsigned int max_open_zones)
652 disk->queue->limits.max_open_zones = max_open_zones;
655 static inline void disk_set_max_active_zones(struct gendisk *disk,
656 unsigned int max_active_zones)
658 disk->queue->limits.max_active_zones = max_active_zones;
661 static inline unsigned int bdev_max_open_zones(struct block_device *bdev)
663 return bdev->bd_disk->queue->limits.max_open_zones;
666 static inline unsigned int bdev_max_active_zones(struct block_device *bdev)
668 return bdev->bd_disk->queue->limits.max_active_zones;
671 bool blk_zone_plug_bio(struct bio *bio, unsigned int nr_segs);
672 #else /* CONFIG_BLK_DEV_ZONED */
673 static inline unsigned int bdev_nr_zones(struct block_device *bdev)
678 static inline unsigned int disk_nr_zones(struct gendisk *disk)
682 static inline bool disk_zone_is_seq(struct gendisk *disk, sector_t sector)
686 static inline unsigned int disk_zone_no(struct gendisk *disk, sector_t sector)
690 static inline unsigned int bdev_max_open_zones(struct block_device *bdev)
695 static inline unsigned int bdev_max_active_zones(struct block_device *bdev)
699 static inline bool blk_zone_plug_bio(struct bio *bio, unsigned int nr_segs)
703 #endif /* CONFIG_BLK_DEV_ZONED */
705 static inline unsigned int blk_queue_depth(struct request_queue *q)
708 return q->queue_depth;
710 return q->nr_requests;
714 * default timeout for SG_IO if none specified
716 #define BLK_DEFAULT_SG_TIMEOUT (60 * HZ)
717 #define BLK_MIN_SG_TIMEOUT (7 * HZ)
719 /* This should not be used directly - use rq_for_each_segment */
720 #define for_each_bio(_bio) \
721 for (; _bio; _bio = _bio->bi_next)
723 int __must_check device_add_disk(struct device *parent, struct gendisk *disk,
724 const struct attribute_group **groups);
725 static inline int __must_check add_disk(struct gendisk *disk)
727 return device_add_disk(NULL, disk, NULL);
729 void del_gendisk(struct gendisk *gp);
730 void invalidate_disk(struct gendisk *disk);
731 void set_disk_ro(struct gendisk *disk, bool read_only);
732 void disk_uevent(struct gendisk *disk, enum kobject_action action);
734 static inline int get_disk_ro(struct gendisk *disk)
736 return disk->part0->bd_read_only ||
737 test_bit(GD_READ_ONLY, &disk->state);
740 static inline int bdev_read_only(struct block_device *bdev)
742 return bdev->bd_read_only || get_disk_ro(bdev->bd_disk);
745 bool set_capacity_and_notify(struct gendisk *disk, sector_t size);
746 void disk_force_media_change(struct gendisk *disk);
747 void bdev_mark_dead(struct block_device *bdev, bool surprise);
749 void add_disk_randomness(struct gendisk *disk) __latent_entropy;
750 void rand_initialize_disk(struct gendisk *disk);
752 static inline sector_t get_start_sect(struct block_device *bdev)
754 return bdev->bd_start_sect;
757 static inline sector_t bdev_nr_sectors(struct block_device *bdev)
759 return bdev->bd_nr_sectors;
762 static inline loff_t bdev_nr_bytes(struct block_device *bdev)
764 return (loff_t)bdev_nr_sectors(bdev) << SECTOR_SHIFT;
767 static inline sector_t get_capacity(struct gendisk *disk)
769 return bdev_nr_sectors(disk->part0);
772 static inline u64 sb_bdev_nr_blocks(struct super_block *sb)
774 return bdev_nr_sectors(sb->s_bdev) >>
775 (sb->s_blocksize_bits - SECTOR_SHIFT);
778 int bdev_disk_changed(struct gendisk *disk, bool invalidate);
780 void put_disk(struct gendisk *disk);
781 struct gendisk *__blk_alloc_disk(struct queue_limits *lim, int node,
782 struct lock_class_key *lkclass);
785 * blk_alloc_disk - allocate a gendisk structure
786 * @lim: queue limits to be used for this disk.
787 * @node_id: numa node to allocate on
789 * Allocate and pre-initialize a gendisk structure for use with BIO based
792 * Returns an ERR_PTR on error, else the allocated disk.
796 #define blk_alloc_disk(lim, node_id) \
798 static struct lock_class_key __key; \
800 __blk_alloc_disk(lim, node_id, &__key); \
803 int __register_blkdev(unsigned int major, const char *name,
804 void (*probe)(dev_t devt));
805 #define register_blkdev(major, name) \
806 __register_blkdev(major, name, NULL)
807 void unregister_blkdev(unsigned int major, const char *name);
809 bool disk_check_media_change(struct gendisk *disk);
810 void set_capacity(struct gendisk *disk, sector_t size);
812 #ifdef CONFIG_BLOCK_HOLDER_DEPRECATED
813 int bd_link_disk_holder(struct block_device *bdev, struct gendisk *disk);
814 void bd_unlink_disk_holder(struct block_device *bdev, struct gendisk *disk);
816 static inline int bd_link_disk_holder(struct block_device *bdev,
817 struct gendisk *disk)
821 static inline void bd_unlink_disk_holder(struct block_device *bdev,
822 struct gendisk *disk)
825 #endif /* CONFIG_BLOCK_HOLDER_DEPRECATED */
827 dev_t part_devt(struct gendisk *disk, u8 partno);
828 void inc_diskseq(struct gendisk *disk);
829 void blk_request_module(dev_t devt);
831 extern int blk_register_queue(struct gendisk *disk);
832 extern void blk_unregister_queue(struct gendisk *disk);
833 void submit_bio_noacct(struct bio *bio);
834 struct bio *bio_split_to_limits(struct bio *bio);
836 extern int blk_lld_busy(struct request_queue *q);
837 extern int blk_queue_enter(struct request_queue *q, blk_mq_req_flags_t flags);
838 extern void blk_queue_exit(struct request_queue *q);
839 extern void blk_sync_queue(struct request_queue *q);
841 /* Helper to convert REQ_OP_XXX to its string format XXX */
842 extern const char *blk_op_str(enum req_op op);
844 int blk_status_to_errno(blk_status_t status);
845 blk_status_t errno_to_blk_status(int errno);
846 const char *blk_status_to_str(blk_status_t status);
848 /* only poll the hardware once, don't continue until a completion was found */
849 #define BLK_POLL_ONESHOT (1 << 0)
850 int bio_poll(struct bio *bio, struct io_comp_batch *iob, unsigned int flags);
851 int iocb_bio_iopoll(struct kiocb *kiocb, struct io_comp_batch *iob,
854 static inline struct request_queue *bdev_get_queue(struct block_device *bdev)
856 return bdev->bd_queue; /* this is never NULL */
859 /* Helper to convert BLK_ZONE_ZONE_XXX to its string format XXX */
860 const char *blk_zone_cond_str(enum blk_zone_cond zone_cond);
862 static inline unsigned int bio_zone_no(struct bio *bio)
864 return disk_zone_no(bio->bi_bdev->bd_disk, bio->bi_iter.bi_sector);
867 static inline bool bio_straddles_zones(struct bio *bio)
869 return bio_sectors(bio) &&
871 disk_zone_no(bio->bi_bdev->bd_disk, bio_end_sector(bio) - 1);
874 static inline unsigned int bio_zone_is_seq(struct bio *bio)
876 return disk_zone_is_seq(bio->bi_bdev->bd_disk, bio->bi_iter.bi_sector);
880 * Return how much of the chunk is left to be used for I/O at a given offset.
882 static inline unsigned int blk_chunk_sectors_left(sector_t offset,
883 unsigned int chunk_sectors)
885 if (unlikely(!is_power_of_2(chunk_sectors)))
886 return chunk_sectors - sector_div(offset, chunk_sectors);
887 return chunk_sectors - (offset & (chunk_sectors - 1));
891 * queue_limits_start_update - start an atomic update of queue limits
892 * @q: queue to update
894 * This functions starts an atomic update of the queue limits. It takes a lock
895 * to prevent other updates and returns a snapshot of the current limits that
896 * the caller can modify. The caller must call queue_limits_commit_update()
897 * to finish the update.
899 * Context: process context. The caller must have frozen the queue or ensured
900 * that there is outstanding I/O by other means.
902 static inline struct queue_limits
903 queue_limits_start_update(struct request_queue *q)
904 __acquires(q->limits_lock)
906 mutex_lock(&q->limits_lock);
909 int queue_limits_commit_update(struct request_queue *q,
910 struct queue_limits *lim);
911 int queue_limits_set(struct request_queue *q, struct queue_limits *lim);
914 * Access functions for manipulating queue properties
916 void blk_queue_bounce_limit(struct request_queue *q, enum blk_bounce limit);
917 extern void blk_queue_max_hw_sectors(struct request_queue *, unsigned int);
918 extern void blk_queue_chunk_sectors(struct request_queue *, unsigned int);
919 extern void blk_queue_max_segments(struct request_queue *, unsigned short);
920 extern void blk_queue_max_discard_segments(struct request_queue *,
922 void blk_queue_max_secure_erase_sectors(struct request_queue *q,
923 unsigned int max_sectors);
924 extern void blk_queue_max_segment_size(struct request_queue *, unsigned int);
925 extern void blk_queue_max_discard_sectors(struct request_queue *q,
926 unsigned int max_discard_sectors);
927 extern void blk_queue_max_write_zeroes_sectors(struct request_queue *q,
928 unsigned int max_write_same_sectors);
929 extern void blk_queue_logical_block_size(struct request_queue *, unsigned int);
930 extern void blk_queue_max_zone_append_sectors(struct request_queue *q,
931 unsigned int max_zone_append_sectors);
932 extern void blk_queue_physical_block_size(struct request_queue *, unsigned int);
933 void blk_queue_zone_write_granularity(struct request_queue *q,
935 extern void blk_queue_alignment_offset(struct request_queue *q,
936 unsigned int alignment);
937 void disk_update_readahead(struct gendisk *disk);
938 extern void blk_limits_io_min(struct queue_limits *limits, unsigned int min);
939 extern void blk_queue_io_min(struct request_queue *q, unsigned int min);
940 extern void blk_limits_io_opt(struct queue_limits *limits, unsigned int opt);
941 extern void blk_queue_io_opt(struct request_queue *q, unsigned int opt);
942 extern void blk_set_queue_depth(struct request_queue *q, unsigned int depth);
943 extern void blk_set_stacking_limits(struct queue_limits *lim);
944 extern int blk_stack_limits(struct queue_limits *t, struct queue_limits *b,
946 void queue_limits_stack_bdev(struct queue_limits *t, struct block_device *bdev,
947 sector_t offset, const char *pfx);
948 extern void blk_queue_update_dma_pad(struct request_queue *, unsigned int);
949 extern void blk_queue_segment_boundary(struct request_queue *, unsigned long);
950 extern void blk_queue_virt_boundary(struct request_queue *, unsigned long);
951 extern void blk_queue_dma_alignment(struct request_queue *, int);
952 extern void blk_queue_update_dma_alignment(struct request_queue *, int);
953 extern void blk_queue_rq_timeout(struct request_queue *, unsigned int);
954 extern void blk_queue_write_cache(struct request_queue *q, bool enabled, bool fua);
956 struct blk_independent_access_ranges *
957 disk_alloc_independent_access_ranges(struct gendisk *disk, int nr_ia_ranges);
958 void disk_set_independent_access_ranges(struct gendisk *disk,
959 struct blk_independent_access_ranges *iars);
962 * Elevator features for blk_queue_required_elevator_features:
964 /* Supports zoned block devices sequential write constraint */
965 #define ELEVATOR_F_ZBD_SEQ_WRITE (1U << 0)
967 extern void blk_queue_required_elevator_features(struct request_queue *q,
968 unsigned int features);
969 extern bool blk_queue_can_use_dma_map_merging(struct request_queue *q,
972 bool __must_check blk_get_queue(struct request_queue *);
973 extern void blk_put_queue(struct request_queue *);
975 void blk_mark_disk_dead(struct gendisk *disk);
979 * blk_plug permits building a queue of related requests by holding the I/O
980 * fragments for a short period. This allows merging of sequential requests
981 * into single larger request. As the requests are moved from a per-task list to
982 * the device's request_queue in a batch, this results in improved scalability
983 * as the lock contention for request_queue lock is reduced.
985 * It is ok not to disable preemption when adding the request to the plug list
986 * or when attempting a merge. For details, please see schedule() where
987 * blk_flush_plug() is called.
990 struct request *mq_list; /* blk-mq requests */
992 /* if ios_left is > 1, we can batch tag/rq allocations */
993 struct request *cached_rq;
995 unsigned short nr_ios;
997 unsigned short rq_count;
999 bool multiple_queues;
1002 struct list_head cb_list; /* md requires an unplug callback */
1006 typedef void (*blk_plug_cb_fn)(struct blk_plug_cb *, bool);
1007 struct blk_plug_cb {
1008 struct list_head list;
1009 blk_plug_cb_fn callback;
1012 extern struct blk_plug_cb *blk_check_plugged(blk_plug_cb_fn unplug,
1013 void *data, int size);
1014 extern void blk_start_plug(struct blk_plug *);
1015 extern void blk_start_plug_nr_ios(struct blk_plug *, unsigned short);
1016 extern void blk_finish_plug(struct blk_plug *);
1018 void __blk_flush_plug(struct blk_plug *plug, bool from_schedule);
1019 static inline void blk_flush_plug(struct blk_plug *plug, bool async)
1022 __blk_flush_plug(plug, async);
1026 * tsk == current here
1028 static inline void blk_plug_invalidate_ts(struct task_struct *tsk)
1030 struct blk_plug *plug = tsk->plug;
1033 plug->cur_ktime = 0;
1034 current->flags &= ~PF_BLOCK_TS;
1037 int blkdev_issue_flush(struct block_device *bdev);
1038 long nr_blockdev_pages(void);
1039 #else /* CONFIG_BLOCK */
1043 static inline void blk_start_plug_nr_ios(struct blk_plug *plug,
1044 unsigned short nr_ios)
1048 static inline void blk_start_plug(struct blk_plug *plug)
1052 static inline void blk_finish_plug(struct blk_plug *plug)
1056 static inline void blk_flush_plug(struct blk_plug *plug, bool async)
1060 static inline void blk_plug_invalidate_ts(struct task_struct *tsk)
1064 static inline int blkdev_issue_flush(struct block_device *bdev)
1069 static inline long nr_blockdev_pages(void)
1073 #endif /* CONFIG_BLOCK */
1075 extern void blk_io_schedule(void);
1077 int blkdev_issue_discard(struct block_device *bdev, sector_t sector,
1078 sector_t nr_sects, gfp_t gfp_mask);
1079 int __blkdev_issue_discard(struct block_device *bdev, sector_t sector,
1080 sector_t nr_sects, gfp_t gfp_mask, struct bio **biop);
1081 int blkdev_issue_secure_erase(struct block_device *bdev, sector_t sector,
1082 sector_t nr_sects, gfp_t gfp);
1084 #define BLKDEV_ZERO_NOUNMAP (1 << 0) /* do not free blocks */
1085 #define BLKDEV_ZERO_NOFALLBACK (1 << 1) /* don't write explicit zeroes */
1087 extern int __blkdev_issue_zeroout(struct block_device *bdev, sector_t sector,
1088 sector_t nr_sects, gfp_t gfp_mask, struct bio **biop,
1090 extern int blkdev_issue_zeroout(struct block_device *bdev, sector_t sector,
1091 sector_t nr_sects, gfp_t gfp_mask, unsigned flags);
1093 static inline int sb_issue_discard(struct super_block *sb, sector_t block,
1094 sector_t nr_blocks, gfp_t gfp_mask, unsigned long flags)
1096 return blkdev_issue_discard(sb->s_bdev,
1097 block << (sb->s_blocksize_bits -
1099 nr_blocks << (sb->s_blocksize_bits -
1103 static inline int sb_issue_zeroout(struct super_block *sb, sector_t block,
1104 sector_t nr_blocks, gfp_t gfp_mask)
1106 return blkdev_issue_zeroout(sb->s_bdev,
1107 block << (sb->s_blocksize_bits -
1109 nr_blocks << (sb->s_blocksize_bits -
1114 static inline bool bdev_is_partition(struct block_device *bdev)
1116 return bdev->bd_partno;
1119 enum blk_default_limits {
1120 BLK_MAX_SEGMENTS = 128,
1121 BLK_SAFE_MAX_SECTORS = 255,
1122 BLK_MAX_SEGMENT_SIZE = 65536,
1123 BLK_SEG_BOUNDARY_MASK = 0xFFFFFFFFUL,
1127 * Default upper limit for the software max_sectors limit used for
1128 * regular file system I/O. This can be increased through sysfs.
1130 * Not to be confused with the max_hw_sector limit that is entirely
1131 * controlled by the driver, usually based on hardware limits.
1133 #define BLK_DEF_MAX_SECTORS_CAP 2560u
1135 static inline unsigned long queue_segment_boundary(const struct request_queue *q)
1137 return q->limits.seg_boundary_mask;
1140 static inline unsigned long queue_virt_boundary(const struct request_queue *q)
1142 return q->limits.virt_boundary_mask;
1145 static inline unsigned int queue_max_sectors(const struct request_queue *q)
1147 return q->limits.max_sectors;
1150 static inline unsigned int queue_max_bytes(struct request_queue *q)
1152 return min_t(unsigned int, queue_max_sectors(q), INT_MAX >> 9) << 9;
1155 static inline unsigned int queue_max_hw_sectors(const struct request_queue *q)
1157 return q->limits.max_hw_sectors;
1160 static inline unsigned short queue_max_segments(const struct request_queue *q)
1162 return q->limits.max_segments;
1165 static inline unsigned short queue_max_discard_segments(const struct request_queue *q)
1167 return q->limits.max_discard_segments;
1170 static inline unsigned int queue_max_segment_size(const struct request_queue *q)
1172 return q->limits.max_segment_size;
1175 static inline unsigned int queue_limits_max_zone_append_sectors(struct queue_limits *l)
1177 unsigned int max_sectors = min(l->chunk_sectors, l->max_hw_sectors);
1179 return min_not_zero(l->max_zone_append_sectors, max_sectors);
1182 static inline unsigned int queue_max_zone_append_sectors(struct request_queue *q)
1184 if (!blk_queue_is_zoned(q))
1187 return queue_limits_max_zone_append_sectors(&q->limits);
1190 static inline bool queue_emulates_zone_append(struct request_queue *q)
1192 return blk_queue_is_zoned(q) && !q->limits.max_zone_append_sectors;
1195 static inline bool bdev_emulates_zone_append(struct block_device *bdev)
1197 return queue_emulates_zone_append(bdev_get_queue(bdev));
1200 static inline unsigned int
1201 bdev_max_zone_append_sectors(struct block_device *bdev)
1203 return queue_max_zone_append_sectors(bdev_get_queue(bdev));
1206 static inline unsigned int bdev_max_segments(struct block_device *bdev)
1208 return queue_max_segments(bdev_get_queue(bdev));
1211 static inline unsigned queue_logical_block_size(const struct request_queue *q)
1215 if (q && q->limits.logical_block_size)
1216 retval = q->limits.logical_block_size;
1221 static inline unsigned int bdev_logical_block_size(struct block_device *bdev)
1223 return queue_logical_block_size(bdev_get_queue(bdev));
1226 static inline unsigned int queue_physical_block_size(const struct request_queue *q)
1228 return q->limits.physical_block_size;
1231 static inline unsigned int bdev_physical_block_size(struct block_device *bdev)
1233 return queue_physical_block_size(bdev_get_queue(bdev));
1236 static inline unsigned int queue_io_min(const struct request_queue *q)
1238 return q->limits.io_min;
1241 static inline int bdev_io_min(struct block_device *bdev)
1243 return queue_io_min(bdev_get_queue(bdev));
1246 static inline unsigned int queue_io_opt(const struct request_queue *q)
1248 return q->limits.io_opt;
1251 static inline int bdev_io_opt(struct block_device *bdev)
1253 return queue_io_opt(bdev_get_queue(bdev));
1256 static inline unsigned int
1257 queue_zone_write_granularity(const struct request_queue *q)
1259 return q->limits.zone_write_granularity;
1262 static inline unsigned int
1263 bdev_zone_write_granularity(struct block_device *bdev)
1265 return queue_zone_write_granularity(bdev_get_queue(bdev));
1268 int bdev_alignment_offset(struct block_device *bdev);
1269 unsigned int bdev_discard_alignment(struct block_device *bdev);
1271 static inline unsigned int bdev_max_discard_sectors(struct block_device *bdev)
1273 return bdev_get_queue(bdev)->limits.max_discard_sectors;
1276 static inline unsigned int bdev_discard_granularity(struct block_device *bdev)
1278 return bdev_get_queue(bdev)->limits.discard_granularity;
1281 static inline unsigned int
1282 bdev_max_secure_erase_sectors(struct block_device *bdev)
1284 return bdev_get_queue(bdev)->limits.max_secure_erase_sectors;
1287 static inline unsigned int bdev_write_zeroes_sectors(struct block_device *bdev)
1289 struct request_queue *q = bdev_get_queue(bdev);
1292 return q->limits.max_write_zeroes_sectors;
1297 static inline bool bdev_nonrot(struct block_device *bdev)
1299 return blk_queue_nonrot(bdev_get_queue(bdev));
1302 static inline bool bdev_synchronous(struct block_device *bdev)
1304 return test_bit(QUEUE_FLAG_SYNCHRONOUS,
1305 &bdev_get_queue(bdev)->queue_flags);
1308 static inline bool bdev_stable_writes(struct block_device *bdev)
1310 return test_bit(QUEUE_FLAG_STABLE_WRITES,
1311 &bdev_get_queue(bdev)->queue_flags);
1314 static inline bool bdev_write_cache(struct block_device *bdev)
1316 return test_bit(QUEUE_FLAG_WC, &bdev_get_queue(bdev)->queue_flags);
1319 static inline bool bdev_fua(struct block_device *bdev)
1321 return test_bit(QUEUE_FLAG_FUA, &bdev_get_queue(bdev)->queue_flags);
1324 static inline bool bdev_nowait(struct block_device *bdev)
1326 return test_bit(QUEUE_FLAG_NOWAIT, &bdev_get_queue(bdev)->queue_flags);
1329 static inline bool bdev_is_zoned(struct block_device *bdev)
1331 return blk_queue_is_zoned(bdev_get_queue(bdev));
1334 static inline unsigned int bdev_zone_no(struct block_device *bdev, sector_t sec)
1336 return disk_zone_no(bdev->bd_disk, sec);
1339 /* Whether write serialization is required for @op on zoned devices. */
1340 static inline bool op_needs_zoned_write_locking(enum req_op op)
1342 return op == REQ_OP_WRITE || op == REQ_OP_WRITE_ZEROES;
1345 static inline bool bdev_op_is_zoned_write(struct block_device *bdev,
1348 return bdev_is_zoned(bdev) && op_needs_zoned_write_locking(op);
1351 static inline sector_t bdev_zone_sectors(struct block_device *bdev)
1353 struct request_queue *q = bdev_get_queue(bdev);
1355 if (!blk_queue_is_zoned(q))
1357 return q->limits.chunk_sectors;
1360 static inline sector_t bdev_offset_from_zone_start(struct block_device *bdev,
1363 return sector & (bdev_zone_sectors(bdev) - 1);
1366 static inline sector_t bio_offset_from_zone_start(struct bio *bio)
1368 return bdev_offset_from_zone_start(bio->bi_bdev,
1369 bio->bi_iter.bi_sector);
1372 static inline bool bdev_is_zone_start(struct block_device *bdev,
1375 return bdev_offset_from_zone_start(bdev, sector) == 0;
1378 static inline int queue_dma_alignment(const struct request_queue *q)
1380 return q ? q->limits.dma_alignment : 511;
1383 static inline unsigned int bdev_dma_alignment(struct block_device *bdev)
1385 return queue_dma_alignment(bdev_get_queue(bdev));
1388 static inline bool bdev_iter_is_aligned(struct block_device *bdev,
1389 struct iov_iter *iter)
1391 return iov_iter_is_aligned(iter, bdev_dma_alignment(bdev),
1392 bdev_logical_block_size(bdev) - 1);
1395 static inline int blk_rq_aligned(struct request_queue *q, unsigned long addr,
1398 unsigned int alignment = queue_dma_alignment(q) | q->dma_pad_mask;
1399 return !(addr & alignment) && !(len & alignment);
1402 /* assumes size > 256 */
1403 static inline unsigned int blksize_bits(unsigned int size)
1405 return order_base_2(size >> SECTOR_SHIFT) + SECTOR_SHIFT;
1408 static inline unsigned int block_size(struct block_device *bdev)
1410 return 1 << bdev->bd_inode->i_blkbits;
1413 int kblockd_schedule_work(struct work_struct *work);
1414 int kblockd_mod_delayed_work_on(int cpu, struct delayed_work *dwork, unsigned long delay);
1416 #define MODULE_ALIAS_BLOCKDEV(major,minor) \
1417 MODULE_ALIAS("block-major-" __stringify(major) "-" __stringify(minor))
1418 #define MODULE_ALIAS_BLOCKDEV_MAJOR(major) \
1419 MODULE_ALIAS("block-major-" __stringify(major) "-*")
1421 #ifdef CONFIG_BLK_INLINE_ENCRYPTION
1423 bool blk_crypto_register(struct blk_crypto_profile *profile,
1424 struct request_queue *q);
1426 #else /* CONFIG_BLK_INLINE_ENCRYPTION */
1428 static inline bool blk_crypto_register(struct blk_crypto_profile *profile,
1429 struct request_queue *q)
1434 #endif /* CONFIG_BLK_INLINE_ENCRYPTION */
1436 enum blk_unique_id {
1437 /* these match the Designator Types specified in SPC */
1443 struct block_device_operations {
1444 void (*submit_bio)(struct bio *bio);
1445 int (*poll_bio)(struct bio *bio, struct io_comp_batch *iob,
1446 unsigned int flags);
1447 int (*open)(struct gendisk *disk, blk_mode_t mode);
1448 void (*release)(struct gendisk *disk);
1449 int (*ioctl)(struct block_device *bdev, blk_mode_t mode,
1450 unsigned cmd, unsigned long arg);
1451 int (*compat_ioctl)(struct block_device *bdev, blk_mode_t mode,
1452 unsigned cmd, unsigned long arg);
1453 unsigned int (*check_events) (struct gendisk *disk,
1454 unsigned int clearing);
1455 void (*unlock_native_capacity) (struct gendisk *);
1456 int (*getgeo)(struct block_device *, struct hd_geometry *);
1457 int (*set_read_only)(struct block_device *bdev, bool ro);
1458 void (*free_disk)(struct gendisk *disk);
1459 /* this callback is with swap_lock and sometimes page table lock held */
1460 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
1461 int (*report_zones)(struct gendisk *, sector_t sector,
1462 unsigned int nr_zones, report_zones_cb cb, void *data);
1463 char *(*devnode)(struct gendisk *disk, umode_t *mode);
1464 /* returns the length of the identifier or a negative errno: */
1465 int (*get_unique_id)(struct gendisk *disk, u8 id[16],
1466 enum blk_unique_id id_type);
1467 struct module *owner;
1468 const struct pr_ops *pr_ops;
1471 * Special callback for probing GPT entry at a given sector.
1472 * Needed by Android devices, used by GPT scanner and MMC blk
1475 int (*alternative_gpt_sector)(struct gendisk *disk, sector_t *sector);
1478 #ifdef CONFIG_COMPAT
1479 extern int blkdev_compat_ptr_ioctl(struct block_device *, blk_mode_t,
1480 unsigned int, unsigned long);
1482 #define blkdev_compat_ptr_ioctl NULL
1485 static inline void blk_wake_io_task(struct task_struct *waiter)
1488 * If we're polling, the task itself is doing the completions. For
1489 * that case, we don't need to signal a wakeup, it's enough to just
1490 * mark us as RUNNING.
1492 if (waiter == current)
1493 __set_current_state(TASK_RUNNING);
1495 wake_up_process(waiter);
1498 unsigned long bdev_start_io_acct(struct block_device *bdev, enum req_op op,
1499 unsigned long start_time);
1500 void bdev_end_io_acct(struct block_device *bdev, enum req_op op,
1501 unsigned int sectors, 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 int lookup_bdev(const char *pathname, dev_t *dev);
1522 void blkdev_show(struct seq_file *seqf, off_t offset);
1524 #define BDEVNAME_SIZE 32 /* Largest string for a blockdev identifier */
1525 #define BDEVT_SIZE 10 /* Largest string for MAJ:MIN for blkdev */
1527 #define BLKDEV_MAJOR_MAX 512
1529 #define BLKDEV_MAJOR_MAX 0
1532 struct blk_holder_ops {
1533 void (*mark_dead)(struct block_device *bdev, bool surprise);
1536 * Sync the file system mounted on the block device.
1538 void (*sync)(struct block_device *bdev);
1541 * Freeze the file system mounted on the block device.
1543 int (*freeze)(struct block_device *bdev);
1546 * Thaw the file system mounted on the block device.
1548 int (*thaw)(struct block_device *bdev);
1551 * If needed, get a reference to the holder.
1553 void (*get_holder)(void *holder);
1556 * Release the holder.
1558 void (*put_holder)(void *holder);
1562 * For filesystems using @fs_holder_ops, the @holder argument passed to
1563 * helpers used to open and claim block devices via
1564 * bd_prepare_to_claim() must point to a superblock.
1566 extern const struct blk_holder_ops fs_holder_ops;
1569 * Return the correct open flags for blkdev_get_by_* for super block flags
1570 * as stored in sb->s_flags.
1572 #define sb_open_mode(flags) \
1573 (BLK_OPEN_READ | BLK_OPEN_RESTRICT_WRITES | \
1574 (((flags) & SB_RDONLY) ? 0 : BLK_OPEN_WRITE))
1576 struct file *bdev_file_open_by_dev(dev_t dev, blk_mode_t mode, void *holder,
1577 const struct blk_holder_ops *hops);
1578 struct file *bdev_file_open_by_path(const char *path, blk_mode_t mode,
1579 void *holder, const struct blk_holder_ops *hops);
1580 int bd_prepare_to_claim(struct block_device *bdev, void *holder,
1581 const struct blk_holder_ops *hops);
1582 void bd_abort_claiming(struct block_device *bdev, void *holder);
1584 /* just for blk-cgroup, don't use elsewhere */
1585 struct block_device *blkdev_get_no_open(dev_t dev);
1586 void blkdev_put_no_open(struct block_device *bdev);
1588 struct block_device *I_BDEV(struct inode *inode);
1589 struct block_device *file_bdev(struct file *bdev_file);
1592 void invalidate_bdev(struct block_device *bdev);
1593 int sync_blockdev(struct block_device *bdev);
1594 int sync_blockdev_range(struct block_device *bdev, loff_t lstart, loff_t lend);
1595 int sync_blockdev_nowait(struct block_device *bdev);
1596 void sync_bdevs(bool wait);
1597 void bdev_statx_dioalign(struct inode *inode, struct kstat *stat);
1598 void printk_all_partitions(void);
1599 int __init early_lookup_bdev(const char *pathname, dev_t *dev);
1601 static inline void invalidate_bdev(struct block_device *bdev)
1604 static inline int sync_blockdev(struct block_device *bdev)
1608 static inline int sync_blockdev_nowait(struct block_device *bdev)
1612 static inline void sync_bdevs(bool wait)
1615 static inline void bdev_statx_dioalign(struct inode *inode, struct kstat *stat)
1618 static inline void printk_all_partitions(void)
1621 static inline int early_lookup_bdev(const char *pathname, dev_t *dev)
1625 #endif /* CONFIG_BLOCK */
1627 int bdev_freeze(struct block_device *bdev);
1628 int bdev_thaw(struct block_device *bdev);
1630 struct io_comp_batch {
1631 struct request *req_list;
1633 void (*complete)(struct io_comp_batch *);
1636 #define DEFINE_IO_COMP_BATCH(name) struct io_comp_batch name = { }
1638 #endif /* _LINUX_BLKDEV_H */