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>
30 struct elevator_queue;
35 struct blk_flush_queue;
39 struct blk_queue_stats;
40 struct blk_stat_callback;
41 struct blk_crypto_profile;
43 extern const struct device_type disk_type;
44 extern const struct device_type part_type;
45 extern struct class block_class;
48 * Maximum number of blkcg policies allowed to be registered concurrently.
49 * Defined here to simplify include dependency.
51 #define BLKCG_MAX_POLS 6
53 #define DISK_MAX_PARTS 256
54 #define DISK_NAME_LEN 32
56 #define PARTITION_META_INFO_VOLNAMELTH 64
58 * Enough for the string representation of any kind of UUID plus NULL.
59 * EFI UUID is 36 characters. MSDOS UUID is 11 characters.
61 #define PARTITION_META_INFO_UUIDLTH (UUID_STRING_LEN + 1)
63 struct partition_meta_info {
64 char uuid[PARTITION_META_INFO_UUIDLTH];
65 u8 volname[PARTITION_META_INFO_VOLNAMELTH];
69 * DOC: genhd capability flags
71 * ``GENHD_FL_REMOVABLE``: indicates that the block device gives access to
72 * removable media. When set, the device remains present even when media is not
73 * inserted. Shall not be set for devices which are removed entirely when the
76 * ``GENHD_FL_HIDDEN``: the block device is hidden; it doesn't produce events,
77 * doesn't appear in sysfs, and can't be opened from userspace or using
78 * blkdev_get*. Used for the underlying components of multipath devices.
80 * ``GENHD_FL_NO_PART``: partition support is disabled. The kernel will not
81 * scan for partitions from add_disk, and users can't add partitions manually.
85 GENHD_FL_REMOVABLE = 1 << 0,
86 GENHD_FL_HIDDEN = 1 << 1,
87 GENHD_FL_NO_PART = 1 << 2,
91 DISK_EVENT_MEDIA_CHANGE = 1 << 0, /* media changed */
92 DISK_EVENT_EJECT_REQUEST = 1 << 1, /* eject requested */
96 /* Poll even if events_poll_msecs is unset */
97 DISK_EVENT_FLAG_POLL = 1 << 0,
98 /* Forward events to udev */
99 DISK_EVENT_FLAG_UEVENT = 1 << 1,
100 /* Block event polling when open for exclusive write */
101 DISK_EVENT_FLAG_BLOCK_ON_EXCL_WRITE = 1 << 2,
107 struct blk_integrity {
108 const struct blk_integrity_profile *profile;
110 unsigned char tuple_size;
111 unsigned char interval_exp;
112 unsigned char tag_size;
117 * major/first_minor/minors should not be set by any new driver, the
118 * block core will take care of allocating them automatically.
124 char disk_name[DISK_NAME_LEN]; /* name of major driver */
126 unsigned short events; /* supported events */
127 unsigned short event_flags; /* flags related to event processing */
129 struct xarray part_tbl;
130 struct block_device *part0;
132 const struct block_device_operations *fops;
133 struct request_queue *queue;
136 struct bio_set bio_split;
140 #define GD_NEED_PART_SCAN 0
141 #define GD_READ_ONLY 1
143 #define GD_NATIVE_CAPACITY 3
145 #define GD_SUPPRESS_PART_SCAN 5
146 #define GD_OWNS_QUEUE 6
148 struct mutex open_mutex; /* open/close mutex */
149 unsigned open_partitions; /* number of open partitions */
151 struct backing_dev_info *bdi;
152 struct kobject queue_kobj; /* the queue/ directory */
153 struct kobject *slave_dir;
154 #ifdef CONFIG_BLOCK_HOLDER_DEPRECATED
155 struct list_head slave_bdevs;
157 struct timer_rand_state *random;
158 atomic_t sync_io; /* RAID */
159 struct disk_events *ev;
161 #ifdef CONFIG_BLK_DEV_ZONED
163 * Zoned block device information for request dispatch control.
164 * nr_zones is the total number of zones of the device. This is always
165 * 0 for regular block devices. conv_zones_bitmap is a bitmap of nr_zones
166 * bits which indicates if a zone is conventional (bit set) or
167 * sequential (bit clear). seq_zones_wlock is a bitmap of nr_zones
168 * bits which indicates if a zone is write locked, that is, if a write
169 * request targeting the zone was dispatched.
171 * Reads of this information must be protected with blk_queue_enter() /
172 * blk_queue_exit(). Modifying this information is only allowed while
173 * no requests are being processed. See also blk_mq_freeze_queue() and
174 * blk_mq_unfreeze_queue().
176 unsigned int nr_zones;
177 unsigned int max_open_zones;
178 unsigned int max_active_zones;
179 unsigned long *conv_zones_bitmap;
180 unsigned long *seq_zones_wlock;
181 #endif /* CONFIG_BLK_DEV_ZONED */
183 #if IS_ENABLED(CONFIG_CDROM)
184 struct cdrom_device_info *cdi;
187 struct badblocks *bb;
188 struct lockdep_map lockdep_map;
192 * Independent sector access ranges. This is always NULL for
193 * devices that do not have multiple independent access ranges.
195 struct blk_independent_access_ranges *ia_ranges;
198 static inline bool disk_live(struct gendisk *disk)
200 return !inode_unhashed(disk->part0->bd_inode);
204 * disk_openers - returns how many openers are there for a disk
205 * @disk: disk to check
207 * This returns the number of openers for a disk. Note that this value is only
208 * stable if disk->open_mutex is held.
210 * Note: Due to a quirk in the block layer open code, each open partition is
211 * only counted once even if there are multiple openers.
213 static inline unsigned int disk_openers(struct gendisk *disk)
215 return atomic_read(&disk->part0->bd_openers);
219 * The gendisk is refcounted by the part0 block_device, and the bd_device
220 * therein is also used for device model presentation in sysfs.
222 #define dev_to_disk(device) \
223 (dev_to_bdev(device)->bd_disk)
224 #define disk_to_dev(disk) \
225 (&((disk)->part0->bd_device))
227 #if IS_REACHABLE(CONFIG_CDROM)
228 #define disk_to_cdi(disk) ((disk)->cdi)
230 #define disk_to_cdi(disk) NULL
233 static inline dev_t disk_devt(struct gendisk *disk)
235 return MKDEV(disk->major, disk->first_minor);
238 static inline int blk_validate_block_size(unsigned long bsize)
240 if (bsize < 512 || bsize > PAGE_SIZE || !is_power_of_2(bsize))
246 static inline bool blk_op_is_passthrough(blk_opf_t op)
249 return op == REQ_OP_DRV_IN || op == REQ_OP_DRV_OUT;
253 * Zoned block device models (zoned limit).
255 * Note: This needs to be ordered from the least to the most severe
256 * restrictions for the inheritance in blk_stack_limits() to work.
258 enum blk_zoned_model {
259 BLK_ZONED_NONE = 0, /* Regular block device */
260 BLK_ZONED_HA, /* Host-aware zoned block device */
261 BLK_ZONED_HM, /* Host-managed zoned block device */
265 * BLK_BOUNCE_NONE: never bounce (default)
266 * BLK_BOUNCE_HIGH: bounce all highmem pages
273 struct queue_limits {
274 enum blk_bounce bounce;
275 unsigned long seg_boundary_mask;
276 unsigned long virt_boundary_mask;
278 unsigned int max_hw_sectors;
279 unsigned int max_dev_sectors;
280 unsigned int chunk_sectors;
281 unsigned int max_sectors;
282 unsigned int max_user_sectors;
283 unsigned int max_segment_size;
284 unsigned int physical_block_size;
285 unsigned int logical_block_size;
286 unsigned int alignment_offset;
289 unsigned int max_discard_sectors;
290 unsigned int max_hw_discard_sectors;
291 unsigned int max_secure_erase_sectors;
292 unsigned int max_write_zeroes_sectors;
293 unsigned int max_zone_append_sectors;
294 unsigned int discard_granularity;
295 unsigned int discard_alignment;
296 unsigned int zone_write_granularity;
298 unsigned short max_segments;
299 unsigned short max_integrity_segments;
300 unsigned short max_discard_segments;
302 unsigned char misaligned;
303 unsigned char discard_misaligned;
304 unsigned char raid_partial_stripes_expensive;
305 enum blk_zoned_model zoned;
308 * Drivers that set dma_alignment to less than 511 must be prepared to
309 * handle individual bvec's that are not a multiple of a SECTOR_SIZE
310 * due to possible offsets.
312 unsigned int dma_alignment;
315 typedef int (*report_zones_cb)(struct blk_zone *zone, unsigned int idx,
318 void disk_set_zoned(struct gendisk *disk, enum blk_zoned_model model);
320 #ifdef CONFIG_BLK_DEV_ZONED
322 #define BLK_ALL_ZONES ((unsigned int)-1)
323 int blkdev_report_zones(struct block_device *bdev, sector_t sector,
324 unsigned int nr_zones, report_zones_cb cb, void *data);
325 unsigned int bdev_nr_zones(struct block_device *bdev);
326 extern int blkdev_zone_mgmt(struct block_device *bdev, enum req_op op,
327 sector_t sectors, sector_t nr_sectors,
329 int blk_revalidate_disk_zones(struct gendisk *disk,
330 void (*update_driver_data)(struct gendisk *disk));
332 extern int blkdev_report_zones_ioctl(struct block_device *bdev, fmode_t mode,
333 unsigned int cmd, unsigned long arg);
334 extern int blkdev_zone_mgmt_ioctl(struct block_device *bdev, fmode_t mode,
335 unsigned int cmd, unsigned long arg);
337 #else /* CONFIG_BLK_DEV_ZONED */
339 static inline unsigned int bdev_nr_zones(struct block_device *bdev)
344 static inline int blkdev_report_zones_ioctl(struct block_device *bdev,
345 fmode_t mode, unsigned int cmd,
351 static inline int blkdev_zone_mgmt_ioctl(struct block_device *bdev,
352 fmode_t mode, unsigned int cmd,
358 #endif /* CONFIG_BLK_DEV_ZONED */
361 * Independent access ranges: struct blk_independent_access_range describes
362 * a range of contiguous sectors that can be accessed using device command
363 * execution resources that are independent from the resources used for
364 * other access ranges. This is typically found with single-LUN multi-actuator
365 * HDDs where each access range is served by a different set of heads.
366 * The set of independent ranges supported by the device is defined using
367 * struct blk_independent_access_ranges. The independent ranges must not overlap
368 * and must include all sectors within the disk capacity (no sector holes
370 * For a device with multiple ranges, requests targeting sectors in different
371 * ranges can be executed in parallel. A request can straddle an access range
374 struct blk_independent_access_range {
380 struct blk_independent_access_ranges {
382 bool sysfs_registered;
383 unsigned int nr_ia_ranges;
384 struct blk_independent_access_range ia_range[];
387 struct request_queue {
388 struct request *last_merge;
389 struct elevator_queue *elevator;
391 struct percpu_ref q_usage_counter;
393 struct blk_queue_stats *stats;
394 struct rq_qos *rq_qos;
395 struct mutex rq_qos_mutex;
397 const struct blk_mq_ops *mq_ops;
400 struct blk_mq_ctx __percpu *queue_ctx;
402 unsigned int queue_depth;
404 /* hw dispatch queues */
405 struct xarray hctx_table;
406 unsigned int nr_hw_queues;
409 * The queue owner gets to use this for whatever they like.
410 * ll_rw_blk doesn't touch it.
415 * various queue flags, see QUEUE_* below
417 unsigned long queue_flags;
419 * Number of contexts that have called blk_set_pm_only(). If this
420 * counter is above zero then only RQF_PM requests are processed.
425 * ida allocated id for this queue. Used to index queues from
430 spinlock_t queue_lock;
432 struct gendisk *disk;
439 struct kobject *mq_kobj;
441 #ifdef CONFIG_BLK_DEV_INTEGRITY
442 struct blk_integrity integrity;
443 #endif /* CONFIG_BLK_DEV_INTEGRITY */
447 enum rpm_status rpm_status;
453 unsigned long nr_requests; /* Max # of requests */
455 unsigned int dma_pad_mask;
457 #ifdef CONFIG_BLK_INLINE_ENCRYPTION
458 struct blk_crypto_profile *crypto_profile;
459 struct kobject *crypto_kobject;
462 unsigned int rq_timeout;
464 struct timer_list timeout;
465 struct work_struct timeout_work;
467 atomic_t nr_active_requests_shared_tags;
469 struct blk_mq_tags *sched_shared_tags;
471 struct list_head icq_list;
472 #ifdef CONFIG_BLK_CGROUP
473 DECLARE_BITMAP (blkcg_pols, BLKCG_MAX_POLS);
474 struct blkcg_gq *root_blkg;
475 struct list_head blkg_list;
476 struct mutex blkcg_mutex;
479 struct queue_limits limits;
481 unsigned int required_elevator_features;
484 #ifdef CONFIG_BLK_DEV_IO_TRACE
485 struct blk_trace __rcu *blk_trace;
488 * for flush operations
490 struct blk_flush_queue *fq;
491 struct list_head flush_list;
493 struct list_head requeue_list;
494 spinlock_t requeue_lock;
495 struct delayed_work requeue_work;
497 struct mutex sysfs_lock;
498 struct mutex sysfs_dir_lock;
501 * for reusing dead hctx instance in case of updating
504 struct list_head unused_hctx_list;
505 spinlock_t unused_hctx_lock;
509 #ifdef CONFIG_BLK_DEV_THROTTLING
511 struct throtl_data *td;
513 struct rcu_head rcu_head;
514 wait_queue_head_t mq_freeze_wq;
516 * Protect concurrent access to q_usage_counter by
517 * percpu_ref_kill() and percpu_ref_reinit().
519 struct mutex mq_freeze_lock;
523 struct blk_mq_tag_set *tag_set;
524 struct list_head tag_set_list;
526 struct dentry *debugfs_dir;
527 struct dentry *sched_debugfs_dir;
528 struct dentry *rqos_debugfs_dir;
530 * Serializes all debugfs metadata operations using the above dentries.
532 struct mutex debugfs_mutex;
534 bool mq_sysfs_init_done;
537 /* Keep blk_queue_flag_name[] in sync with the definitions below */
538 #define QUEUE_FLAG_STOPPED 0 /* queue is stopped */
539 #define QUEUE_FLAG_DYING 1 /* queue being torn down */
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_NOXMERGES 9 /* No extended merges */
547 #define QUEUE_FLAG_ADD_RANDOM 10 /* Contributes to random pool */
548 #define QUEUE_FLAG_SYNCHRONOUS 11 /* always completes in submit context */
549 #define QUEUE_FLAG_SAME_FORCE 12 /* force complete on same CPU */
550 #define QUEUE_FLAG_INIT_DONE 14 /* queue is initialized */
551 #define QUEUE_FLAG_STABLE_WRITES 15 /* don't modify blks until WB is done */
552 #define QUEUE_FLAG_POLL 16 /* IO polling enabled if set */
553 #define QUEUE_FLAG_WC 17 /* Write back caching */
554 #define QUEUE_FLAG_FUA 18 /* device supports FUA writes */
555 #define QUEUE_FLAG_DAX 19 /* device supports DAX */
556 #define QUEUE_FLAG_STATS 20 /* track IO start and completion times */
557 #define QUEUE_FLAG_REGISTERED 22 /* queue has been registered to a disk */
558 #define QUEUE_FLAG_QUIESCED 24 /* queue has been quiesced */
559 #define QUEUE_FLAG_PCI_P2PDMA 25 /* device supports PCI p2p requests */
560 #define QUEUE_FLAG_ZONE_RESETALL 26 /* supports Zone Reset All */
561 #define QUEUE_FLAG_RQ_ALLOC_TIME 27 /* record rq->alloc_time_ns */
562 #define QUEUE_FLAG_HCTX_ACTIVE 28 /* at least one blk-mq hctx is active */
563 #define QUEUE_FLAG_NOWAIT 29 /* device supports NOWAIT */
564 #define QUEUE_FLAG_SQ_SCHED 30 /* single queue style io dispatch */
565 #define QUEUE_FLAG_SKIP_TAGSET_QUIESCE 31 /* quiesce_tagset skip the queue*/
567 #define QUEUE_FLAG_MQ_DEFAULT ((1UL << QUEUE_FLAG_IO_STAT) | \
568 (1UL << QUEUE_FLAG_SAME_COMP) | \
569 (1UL << 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_init_done(q) test_bit(QUEUE_FLAG_INIT_DONE, &(q)->queue_flags)
578 #define blk_queue_nomerges(q) test_bit(QUEUE_FLAG_NOMERGES, &(q)->queue_flags)
579 #define blk_queue_noxmerges(q) \
580 test_bit(QUEUE_FLAG_NOXMERGES, &(q)->queue_flags)
581 #define blk_queue_nonrot(q) test_bit(QUEUE_FLAG_NONROT, &(q)->queue_flags)
582 #define blk_queue_stable_writes(q) \
583 test_bit(QUEUE_FLAG_STABLE_WRITES, &(q)->queue_flags)
584 #define blk_queue_io_stat(q) test_bit(QUEUE_FLAG_IO_STAT, &(q)->queue_flags)
585 #define blk_queue_add_random(q) test_bit(QUEUE_FLAG_ADD_RANDOM, &(q)->queue_flags)
586 #define blk_queue_zone_resetall(q) \
587 test_bit(QUEUE_FLAG_ZONE_RESETALL, &(q)->queue_flags)
588 #define blk_queue_dax(q) test_bit(QUEUE_FLAG_DAX, &(q)->queue_flags)
589 #define blk_queue_pci_p2pdma(q) \
590 test_bit(QUEUE_FLAG_PCI_P2PDMA, &(q)->queue_flags)
591 #ifdef CONFIG_BLK_RQ_ALLOC_TIME
592 #define blk_queue_rq_alloc_time(q) \
593 test_bit(QUEUE_FLAG_RQ_ALLOC_TIME, &(q)->queue_flags)
595 #define blk_queue_rq_alloc_time(q) false
598 #define blk_noretry_request(rq) \
599 ((rq)->cmd_flags & (REQ_FAILFAST_DEV|REQ_FAILFAST_TRANSPORT| \
600 REQ_FAILFAST_DRIVER))
601 #define blk_queue_quiesced(q) test_bit(QUEUE_FLAG_QUIESCED, &(q)->queue_flags)
602 #define blk_queue_pm_only(q) atomic_read(&(q)->pm_only)
603 #define blk_queue_registered(q) test_bit(QUEUE_FLAG_REGISTERED, &(q)->queue_flags)
604 #define blk_queue_sq_sched(q) test_bit(QUEUE_FLAG_SQ_SCHED, &(q)->queue_flags)
605 #define blk_queue_skip_tagset_quiesce(q) \
606 test_bit(QUEUE_FLAG_SKIP_TAGSET_QUIESCE, &(q)->queue_flags)
608 extern void blk_set_pm_only(struct request_queue *q);
609 extern void blk_clear_pm_only(struct request_queue *q);
611 #define list_entry_rq(ptr) list_entry((ptr), struct request, queuelist)
613 #define dma_map_bvec(dev, bv, dir, attrs) \
614 dma_map_page_attrs(dev, (bv)->bv_page, (bv)->bv_offset, (bv)->bv_len, \
617 static inline bool queue_is_mq(struct request_queue *q)
623 static inline enum rpm_status queue_rpm_status(struct request_queue *q)
625 return q->rpm_status;
628 static inline enum rpm_status queue_rpm_status(struct request_queue *q)
634 static inline enum blk_zoned_model
635 blk_queue_zoned_model(struct request_queue *q)
637 if (IS_ENABLED(CONFIG_BLK_DEV_ZONED))
638 return q->limits.zoned;
639 return BLK_ZONED_NONE;
642 static inline bool blk_queue_is_zoned(struct request_queue *q)
644 switch (blk_queue_zoned_model(q)) {
653 #ifdef CONFIG_BLK_DEV_ZONED
654 static inline unsigned int disk_nr_zones(struct gendisk *disk)
656 return blk_queue_is_zoned(disk->queue) ? disk->nr_zones : 0;
659 static inline unsigned int disk_zone_no(struct gendisk *disk, sector_t sector)
661 if (!blk_queue_is_zoned(disk->queue))
663 return sector >> ilog2(disk->queue->limits.chunk_sectors);
666 static inline bool disk_zone_is_seq(struct gendisk *disk, sector_t sector)
668 if (!blk_queue_is_zoned(disk->queue))
670 if (!disk->conv_zones_bitmap)
672 return !test_bit(disk_zone_no(disk, sector), disk->conv_zones_bitmap);
675 static inline void disk_set_max_open_zones(struct gendisk *disk,
676 unsigned int max_open_zones)
678 disk->max_open_zones = max_open_zones;
681 static inline void disk_set_max_active_zones(struct gendisk *disk,
682 unsigned int max_active_zones)
684 disk->max_active_zones = max_active_zones;
687 static inline unsigned int bdev_max_open_zones(struct block_device *bdev)
689 return bdev->bd_disk->max_open_zones;
692 static inline unsigned int bdev_max_active_zones(struct block_device *bdev)
694 return bdev->bd_disk->max_active_zones;
697 #else /* CONFIG_BLK_DEV_ZONED */
698 static inline unsigned int disk_nr_zones(struct gendisk *disk)
702 static inline bool disk_zone_is_seq(struct gendisk *disk, sector_t sector)
706 static inline unsigned int disk_zone_no(struct gendisk *disk, sector_t sector)
710 static inline unsigned int bdev_max_open_zones(struct block_device *bdev)
715 static inline unsigned int bdev_max_active_zones(struct block_device *bdev)
719 #endif /* CONFIG_BLK_DEV_ZONED */
721 static inline unsigned int blk_queue_depth(struct request_queue *q)
724 return q->queue_depth;
726 return q->nr_requests;
730 * default timeout for SG_IO if none specified
732 #define BLK_DEFAULT_SG_TIMEOUT (60 * HZ)
733 #define BLK_MIN_SG_TIMEOUT (7 * HZ)
735 /* This should not be used directly - use rq_for_each_segment */
736 #define for_each_bio(_bio) \
737 for (; _bio; _bio = _bio->bi_next)
739 int __must_check device_add_disk(struct device *parent, struct gendisk *disk,
740 const struct attribute_group **groups);
741 static inline int __must_check add_disk(struct gendisk *disk)
743 return device_add_disk(NULL, disk, NULL);
745 void del_gendisk(struct gendisk *gp);
746 void invalidate_disk(struct gendisk *disk);
747 void set_disk_ro(struct gendisk *disk, bool read_only);
748 void disk_uevent(struct gendisk *disk, enum kobject_action action);
750 static inline int get_disk_ro(struct gendisk *disk)
752 return disk->part0->bd_read_only ||
753 test_bit(GD_READ_ONLY, &disk->state);
756 static inline int bdev_read_only(struct block_device *bdev)
758 return bdev->bd_read_only || get_disk_ro(bdev->bd_disk);
761 bool set_capacity_and_notify(struct gendisk *disk, sector_t size);
762 bool disk_force_media_change(struct gendisk *disk, unsigned int events);
764 void add_disk_randomness(struct gendisk *disk) __latent_entropy;
765 void rand_initialize_disk(struct gendisk *disk);
767 static inline sector_t get_start_sect(struct block_device *bdev)
769 return bdev->bd_start_sect;
772 static inline sector_t bdev_nr_sectors(struct block_device *bdev)
774 return bdev->bd_nr_sectors;
777 static inline loff_t bdev_nr_bytes(struct block_device *bdev)
779 return (loff_t)bdev_nr_sectors(bdev) << SECTOR_SHIFT;
782 static inline sector_t get_capacity(struct gendisk *disk)
784 return bdev_nr_sectors(disk->part0);
787 static inline u64 sb_bdev_nr_blocks(struct super_block *sb)
789 return bdev_nr_sectors(sb->s_bdev) >>
790 (sb->s_blocksize_bits - SECTOR_SHIFT);
793 int bdev_disk_changed(struct gendisk *disk, bool invalidate);
795 void put_disk(struct gendisk *disk);
796 struct gendisk *__blk_alloc_disk(int node, struct lock_class_key *lkclass);
799 * blk_alloc_disk - allocate a gendisk structure
800 * @node_id: numa node to allocate on
802 * Allocate and pre-initialize a gendisk structure for use with BIO based
807 #define blk_alloc_disk(node_id) \
809 static struct lock_class_key __key; \
811 __blk_alloc_disk(node_id, &__key); \
814 int __register_blkdev(unsigned int major, const char *name,
815 void (*probe)(dev_t devt));
816 #define register_blkdev(major, name) \
817 __register_blkdev(major, name, NULL)
818 void unregister_blkdev(unsigned int major, const char *name);
820 bool disk_check_media_change(struct gendisk *disk);
821 int __invalidate_device(struct block_device *bdev, bool kill_dirty);
822 void set_capacity(struct gendisk *disk, sector_t size);
824 #ifdef CONFIG_BLOCK_HOLDER_DEPRECATED
825 int bd_link_disk_holder(struct block_device *bdev, struct gendisk *disk);
826 void bd_unlink_disk_holder(struct block_device *bdev, struct gendisk *disk);
828 static inline int bd_link_disk_holder(struct block_device *bdev,
829 struct gendisk *disk)
833 static inline void bd_unlink_disk_holder(struct block_device *bdev,
834 struct gendisk *disk)
837 #endif /* CONFIG_BLOCK_HOLDER_DEPRECATED */
839 dev_t part_devt(struct gendisk *disk, u8 partno);
840 void inc_diskseq(struct gendisk *disk);
841 void blk_request_module(dev_t devt);
843 extern int blk_register_queue(struct gendisk *disk);
844 extern void blk_unregister_queue(struct gendisk *disk);
845 void submit_bio_noacct(struct bio *bio);
846 struct bio *bio_split_to_limits(struct bio *bio);
848 extern int blk_lld_busy(struct request_queue *q);
849 extern int blk_queue_enter(struct request_queue *q, blk_mq_req_flags_t flags);
850 extern void blk_queue_exit(struct request_queue *q);
851 extern void blk_sync_queue(struct request_queue *q);
853 /* Helper to convert REQ_OP_XXX to its string format XXX */
854 extern const char *blk_op_str(enum req_op op);
856 int blk_status_to_errno(blk_status_t status);
857 blk_status_t errno_to_blk_status(int errno);
859 /* only poll the hardware once, don't continue until a completion was found */
860 #define BLK_POLL_ONESHOT (1 << 0)
861 int bio_poll(struct bio *bio, struct io_comp_batch *iob, unsigned int flags);
862 int iocb_bio_iopoll(struct kiocb *kiocb, struct io_comp_batch *iob,
865 static inline struct request_queue *bdev_get_queue(struct block_device *bdev)
867 return bdev->bd_queue; /* this is never NULL */
870 /* Helper to convert BLK_ZONE_ZONE_XXX to its string format XXX */
871 const char *blk_zone_cond_str(enum blk_zone_cond zone_cond);
873 static inline unsigned int bio_zone_no(struct bio *bio)
875 return disk_zone_no(bio->bi_bdev->bd_disk, bio->bi_iter.bi_sector);
878 static inline unsigned int bio_zone_is_seq(struct bio *bio)
880 return disk_zone_is_seq(bio->bi_bdev->bd_disk, bio->bi_iter.bi_sector);
884 * Return how much of the chunk is left to be used for I/O at a given offset.
886 static inline unsigned int blk_chunk_sectors_left(sector_t offset,
887 unsigned int chunk_sectors)
889 if (unlikely(!is_power_of_2(chunk_sectors)))
890 return chunk_sectors - sector_div(offset, chunk_sectors);
891 return chunk_sectors - (offset & (chunk_sectors - 1));
895 * Access functions for manipulating queue properties
897 void blk_queue_bounce_limit(struct request_queue *q, enum blk_bounce limit);
898 extern void blk_queue_max_hw_sectors(struct request_queue *, unsigned int);
899 extern void blk_queue_chunk_sectors(struct request_queue *, unsigned int);
900 extern void blk_queue_max_segments(struct request_queue *, unsigned short);
901 extern void blk_queue_max_discard_segments(struct request_queue *,
903 void blk_queue_max_secure_erase_sectors(struct request_queue *q,
904 unsigned int max_sectors);
905 extern void blk_queue_max_segment_size(struct request_queue *, unsigned int);
906 extern void blk_queue_max_discard_sectors(struct request_queue *q,
907 unsigned int max_discard_sectors);
908 extern void blk_queue_max_write_zeroes_sectors(struct request_queue *q,
909 unsigned int max_write_same_sectors);
910 extern void blk_queue_logical_block_size(struct request_queue *, unsigned int);
911 extern void blk_queue_max_zone_append_sectors(struct request_queue *q,
912 unsigned int max_zone_append_sectors);
913 extern void blk_queue_physical_block_size(struct request_queue *, unsigned int);
914 void blk_queue_zone_write_granularity(struct request_queue *q,
916 extern void blk_queue_alignment_offset(struct request_queue *q,
917 unsigned int alignment);
918 void disk_update_readahead(struct gendisk *disk);
919 extern void blk_limits_io_min(struct queue_limits *limits, unsigned int min);
920 extern void blk_queue_io_min(struct request_queue *q, unsigned int min);
921 extern void blk_limits_io_opt(struct queue_limits *limits, unsigned int opt);
922 extern void blk_queue_io_opt(struct request_queue *q, unsigned int opt);
923 extern void blk_set_queue_depth(struct request_queue *q, unsigned int depth);
924 extern void blk_set_stacking_limits(struct queue_limits *lim);
925 extern int blk_stack_limits(struct queue_limits *t, struct queue_limits *b,
927 extern void disk_stack_limits(struct gendisk *disk, struct block_device *bdev,
929 extern void blk_queue_update_dma_pad(struct request_queue *, unsigned int);
930 extern void blk_queue_segment_boundary(struct request_queue *, unsigned long);
931 extern void blk_queue_virt_boundary(struct request_queue *, unsigned long);
932 extern void blk_queue_dma_alignment(struct request_queue *, int);
933 extern void blk_queue_update_dma_alignment(struct request_queue *, int);
934 extern void blk_queue_rq_timeout(struct request_queue *, unsigned int);
935 extern void blk_queue_write_cache(struct request_queue *q, bool enabled, bool fua);
937 struct blk_independent_access_ranges *
938 disk_alloc_independent_access_ranges(struct gendisk *disk, int nr_ia_ranges);
939 void disk_set_independent_access_ranges(struct gendisk *disk,
940 struct blk_independent_access_ranges *iars);
943 * Elevator features for blk_queue_required_elevator_features:
945 /* Supports zoned block devices sequential write constraint */
946 #define ELEVATOR_F_ZBD_SEQ_WRITE (1U << 0)
948 extern void blk_queue_required_elevator_features(struct request_queue *q,
949 unsigned int features);
950 extern bool blk_queue_can_use_dma_map_merging(struct request_queue *q,
953 bool __must_check blk_get_queue(struct request_queue *);
954 extern void blk_put_queue(struct request_queue *);
956 void blk_mark_disk_dead(struct gendisk *disk);
960 * blk_plug permits building a queue of related requests by holding the I/O
961 * fragments for a short period. This allows merging of sequential requests
962 * into single larger request. As the requests are moved from a per-task list to
963 * the device's request_queue in a batch, this results in improved scalability
964 * as the lock contention for request_queue lock is reduced.
966 * It is ok not to disable preemption when adding the request to the plug list
967 * or when attempting a merge. For details, please see schedule() where
968 * blk_flush_plug() is called.
971 struct request *mq_list; /* blk-mq requests */
973 /* if ios_left is > 1, we can batch tag/rq allocations */
974 struct request *cached_rq;
975 unsigned short nr_ios;
977 unsigned short rq_count;
979 bool multiple_queues;
983 struct list_head cb_list; /* md requires an unplug callback */
987 typedef void (*blk_plug_cb_fn)(struct blk_plug_cb *, bool);
989 struct list_head list;
990 blk_plug_cb_fn callback;
993 extern struct blk_plug_cb *blk_check_plugged(blk_plug_cb_fn unplug,
994 void *data, int size);
995 extern void blk_start_plug(struct blk_plug *);
996 extern void blk_start_plug_nr_ios(struct blk_plug *, unsigned short);
997 extern void blk_finish_plug(struct blk_plug *);
999 void __blk_flush_plug(struct blk_plug *plug, bool from_schedule);
1000 static inline void blk_flush_plug(struct blk_plug *plug, bool async)
1003 __blk_flush_plug(plug, async);
1006 int blkdev_issue_flush(struct block_device *bdev);
1007 long nr_blockdev_pages(void);
1008 #else /* CONFIG_BLOCK */
1012 static inline void blk_start_plug_nr_ios(struct blk_plug *plug,
1013 unsigned short nr_ios)
1017 static inline void blk_start_plug(struct blk_plug *plug)
1021 static inline void blk_finish_plug(struct blk_plug *plug)
1025 static inline void blk_flush_plug(struct blk_plug *plug, bool async)
1029 static inline int blkdev_issue_flush(struct block_device *bdev)
1034 static inline long nr_blockdev_pages(void)
1038 #endif /* CONFIG_BLOCK */
1040 extern void blk_io_schedule(void);
1042 int blkdev_issue_discard(struct block_device *bdev, sector_t sector,
1043 sector_t nr_sects, gfp_t gfp_mask);
1044 int __blkdev_issue_discard(struct block_device *bdev, sector_t sector,
1045 sector_t nr_sects, gfp_t gfp_mask, struct bio **biop);
1046 int blkdev_issue_secure_erase(struct block_device *bdev, sector_t sector,
1047 sector_t nr_sects, gfp_t gfp);
1049 #define BLKDEV_ZERO_NOUNMAP (1 << 0) /* do not free blocks */
1050 #define BLKDEV_ZERO_NOFALLBACK (1 << 1) /* don't write explicit zeroes */
1052 extern int __blkdev_issue_zeroout(struct block_device *bdev, sector_t sector,
1053 sector_t nr_sects, gfp_t gfp_mask, struct bio **biop,
1055 extern int blkdev_issue_zeroout(struct block_device *bdev, sector_t sector,
1056 sector_t nr_sects, gfp_t gfp_mask, unsigned flags);
1058 static inline int sb_issue_discard(struct super_block *sb, sector_t block,
1059 sector_t nr_blocks, gfp_t gfp_mask, unsigned long flags)
1061 return blkdev_issue_discard(sb->s_bdev,
1062 block << (sb->s_blocksize_bits -
1064 nr_blocks << (sb->s_blocksize_bits -
1068 static inline int sb_issue_zeroout(struct super_block *sb, sector_t block,
1069 sector_t nr_blocks, gfp_t gfp_mask)
1071 return blkdev_issue_zeroout(sb->s_bdev,
1072 block << (sb->s_blocksize_bits -
1074 nr_blocks << (sb->s_blocksize_bits -
1079 static inline bool bdev_is_partition(struct block_device *bdev)
1081 return bdev->bd_partno;
1084 enum blk_default_limits {
1085 BLK_MAX_SEGMENTS = 128,
1086 BLK_SAFE_MAX_SECTORS = 255,
1087 BLK_MAX_SEGMENT_SIZE = 65536,
1088 BLK_SEG_BOUNDARY_MASK = 0xFFFFFFFFUL,
1091 #define BLK_DEF_MAX_SECTORS 2560u
1093 static inline unsigned long queue_segment_boundary(const struct request_queue *q)
1095 return q->limits.seg_boundary_mask;
1098 static inline unsigned long queue_virt_boundary(const struct request_queue *q)
1100 return q->limits.virt_boundary_mask;
1103 static inline unsigned int queue_max_sectors(const struct request_queue *q)
1105 return q->limits.max_sectors;
1108 static inline unsigned int queue_max_bytes(struct request_queue *q)
1110 return min_t(unsigned int, queue_max_sectors(q), INT_MAX >> 9) << 9;
1113 static inline unsigned int queue_max_hw_sectors(const struct request_queue *q)
1115 return q->limits.max_hw_sectors;
1118 static inline unsigned short queue_max_segments(const struct request_queue *q)
1120 return q->limits.max_segments;
1123 static inline unsigned short queue_max_discard_segments(const struct request_queue *q)
1125 return q->limits.max_discard_segments;
1128 static inline unsigned int queue_max_segment_size(const struct request_queue *q)
1130 return q->limits.max_segment_size;
1133 static inline unsigned int queue_max_zone_append_sectors(const struct request_queue *q)
1136 const struct queue_limits *l = &q->limits;
1138 return min(l->max_zone_append_sectors, l->max_sectors);
1141 static inline unsigned int
1142 bdev_max_zone_append_sectors(struct block_device *bdev)
1144 return queue_max_zone_append_sectors(bdev_get_queue(bdev));
1147 static inline unsigned int bdev_max_segments(struct block_device *bdev)
1149 return queue_max_segments(bdev_get_queue(bdev));
1152 static inline unsigned queue_logical_block_size(const struct request_queue *q)
1156 if (q && q->limits.logical_block_size)
1157 retval = q->limits.logical_block_size;
1162 static inline unsigned int bdev_logical_block_size(struct block_device *bdev)
1164 return queue_logical_block_size(bdev_get_queue(bdev));
1167 static inline unsigned int queue_physical_block_size(const struct request_queue *q)
1169 return q->limits.physical_block_size;
1172 static inline unsigned int bdev_physical_block_size(struct block_device *bdev)
1174 return queue_physical_block_size(bdev_get_queue(bdev));
1177 static inline unsigned int queue_io_min(const struct request_queue *q)
1179 return q->limits.io_min;
1182 static inline int bdev_io_min(struct block_device *bdev)
1184 return queue_io_min(bdev_get_queue(bdev));
1187 static inline unsigned int queue_io_opt(const struct request_queue *q)
1189 return q->limits.io_opt;
1192 static inline int bdev_io_opt(struct block_device *bdev)
1194 return queue_io_opt(bdev_get_queue(bdev));
1197 static inline unsigned int
1198 queue_zone_write_granularity(const struct request_queue *q)
1200 return q->limits.zone_write_granularity;
1203 static inline unsigned int
1204 bdev_zone_write_granularity(struct block_device *bdev)
1206 return queue_zone_write_granularity(bdev_get_queue(bdev));
1209 int bdev_alignment_offset(struct block_device *bdev);
1210 unsigned int bdev_discard_alignment(struct block_device *bdev);
1212 static inline unsigned int bdev_max_discard_sectors(struct block_device *bdev)
1214 return bdev_get_queue(bdev)->limits.max_discard_sectors;
1217 static inline unsigned int bdev_discard_granularity(struct block_device *bdev)
1219 return bdev_get_queue(bdev)->limits.discard_granularity;
1222 static inline unsigned int
1223 bdev_max_secure_erase_sectors(struct block_device *bdev)
1225 return bdev_get_queue(bdev)->limits.max_secure_erase_sectors;
1228 static inline unsigned int bdev_write_zeroes_sectors(struct block_device *bdev)
1230 struct request_queue *q = bdev_get_queue(bdev);
1233 return q->limits.max_write_zeroes_sectors;
1238 static inline bool bdev_nonrot(struct block_device *bdev)
1240 return blk_queue_nonrot(bdev_get_queue(bdev));
1243 static inline bool bdev_synchronous(struct block_device *bdev)
1245 return test_bit(QUEUE_FLAG_SYNCHRONOUS,
1246 &bdev_get_queue(bdev)->queue_flags);
1249 static inline bool bdev_stable_writes(struct block_device *bdev)
1251 return test_bit(QUEUE_FLAG_STABLE_WRITES,
1252 &bdev_get_queue(bdev)->queue_flags);
1255 static inline bool bdev_write_cache(struct block_device *bdev)
1257 return test_bit(QUEUE_FLAG_WC, &bdev_get_queue(bdev)->queue_flags);
1260 static inline bool bdev_fua(struct block_device *bdev)
1262 return test_bit(QUEUE_FLAG_FUA, &bdev_get_queue(bdev)->queue_flags);
1265 static inline bool bdev_nowait(struct block_device *bdev)
1267 return test_bit(QUEUE_FLAG_NOWAIT, &bdev_get_queue(bdev)->queue_flags);
1270 static inline enum blk_zoned_model bdev_zoned_model(struct block_device *bdev)
1272 return blk_queue_zoned_model(bdev_get_queue(bdev));
1275 static inline bool bdev_is_zoned(struct block_device *bdev)
1277 return blk_queue_is_zoned(bdev_get_queue(bdev));
1280 static inline unsigned int bdev_zone_no(struct block_device *bdev, sector_t sec)
1282 return disk_zone_no(bdev->bd_disk, sec);
1285 /* Whether write serialization is required for @op on zoned devices. */
1286 static inline bool op_needs_zoned_write_locking(enum req_op op)
1288 return op == REQ_OP_WRITE || op == REQ_OP_WRITE_ZEROES;
1291 static inline bool bdev_op_is_zoned_write(struct block_device *bdev,
1294 return bdev_is_zoned(bdev) && op_needs_zoned_write_locking(op);
1297 static inline sector_t bdev_zone_sectors(struct block_device *bdev)
1299 struct request_queue *q = bdev_get_queue(bdev);
1301 if (!blk_queue_is_zoned(q))
1303 return q->limits.chunk_sectors;
1306 static inline sector_t bdev_offset_from_zone_start(struct block_device *bdev,
1309 return sector & (bdev_zone_sectors(bdev) - 1);
1312 static inline bool bdev_is_zone_start(struct block_device *bdev,
1315 return bdev_offset_from_zone_start(bdev, sector) == 0;
1318 static inline int queue_dma_alignment(const struct request_queue *q)
1320 return q ? q->limits.dma_alignment : 511;
1323 static inline unsigned int bdev_dma_alignment(struct block_device *bdev)
1325 return queue_dma_alignment(bdev_get_queue(bdev));
1328 static inline bool bdev_iter_is_aligned(struct block_device *bdev,
1329 struct iov_iter *iter)
1331 return iov_iter_is_aligned(iter, bdev_dma_alignment(bdev),
1332 bdev_logical_block_size(bdev) - 1);
1335 static inline int blk_rq_aligned(struct request_queue *q, unsigned long addr,
1338 unsigned int alignment = queue_dma_alignment(q) | q->dma_pad_mask;
1339 return !(addr & alignment) && !(len & alignment);
1342 /* assumes size > 256 */
1343 static inline unsigned int blksize_bits(unsigned int size)
1345 return order_base_2(size >> SECTOR_SHIFT) + SECTOR_SHIFT;
1348 static inline unsigned int block_size(struct block_device *bdev)
1350 return 1 << bdev->bd_inode->i_blkbits;
1353 int kblockd_schedule_work(struct work_struct *work);
1354 int kblockd_mod_delayed_work_on(int cpu, struct delayed_work *dwork, unsigned long delay);
1356 #define MODULE_ALIAS_BLOCKDEV(major,minor) \
1357 MODULE_ALIAS("block-major-" __stringify(major) "-" __stringify(minor))
1358 #define MODULE_ALIAS_BLOCKDEV_MAJOR(major) \
1359 MODULE_ALIAS("block-major-" __stringify(major) "-*")
1361 #ifdef CONFIG_BLK_INLINE_ENCRYPTION
1363 bool blk_crypto_register(struct blk_crypto_profile *profile,
1364 struct request_queue *q);
1366 #else /* CONFIG_BLK_INLINE_ENCRYPTION */
1368 static inline bool blk_crypto_register(struct blk_crypto_profile *profile,
1369 struct request_queue *q)
1374 #endif /* CONFIG_BLK_INLINE_ENCRYPTION */
1376 enum blk_unique_id {
1377 /* these match the Designator Types specified in SPC */
1383 #define NFL4_UFLG_MASK 0x0000003F
1385 struct block_device_operations {
1386 void (*submit_bio)(struct bio *bio);
1387 int (*poll_bio)(struct bio *bio, struct io_comp_batch *iob,
1388 unsigned int flags);
1389 int (*open) (struct block_device *, fmode_t);
1390 void (*release) (struct gendisk *, fmode_t);
1391 int (*ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
1392 int (*compat_ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
1393 unsigned int (*check_events) (struct gendisk *disk,
1394 unsigned int clearing);
1395 void (*unlock_native_capacity) (struct gendisk *);
1396 int (*getgeo)(struct block_device *, struct hd_geometry *);
1397 int (*set_read_only)(struct block_device *bdev, bool ro);
1398 void (*free_disk)(struct gendisk *disk);
1399 /* this callback is with swap_lock and sometimes page table lock held */
1400 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
1401 int (*report_zones)(struct gendisk *, sector_t sector,
1402 unsigned int nr_zones, report_zones_cb cb, void *data);
1403 char *(*devnode)(struct gendisk *disk, umode_t *mode);
1404 /* returns the length of the identifier or a negative errno: */
1405 int (*get_unique_id)(struct gendisk *disk, u8 id[16],
1406 enum blk_unique_id id_type);
1407 struct module *owner;
1408 const struct pr_ops *pr_ops;
1411 * Special callback for probing GPT entry at a given sector.
1412 * Needed by Android devices, used by GPT scanner and MMC blk
1415 int (*alternative_gpt_sector)(struct gendisk *disk, sector_t *sector);
1418 #ifdef CONFIG_COMPAT
1419 extern int blkdev_compat_ptr_ioctl(struct block_device *, fmode_t,
1420 unsigned int, unsigned long);
1422 #define blkdev_compat_ptr_ioctl NULL
1425 static inline void blk_wake_io_task(struct task_struct *waiter)
1428 * If we're polling, the task itself is doing the completions. For
1429 * that case, we don't need to signal a wakeup, it's enough to just
1430 * mark us as RUNNING.
1432 if (waiter == current)
1433 __set_current_state(TASK_RUNNING);
1435 wake_up_process(waiter);
1438 unsigned long bdev_start_io_acct(struct block_device *bdev, enum req_op op,
1439 unsigned long start_time);
1440 void bdev_end_io_acct(struct block_device *bdev, enum req_op op,
1441 unsigned int sectors, unsigned long start_time);
1443 unsigned long bio_start_io_acct(struct bio *bio);
1444 void bio_end_io_acct_remapped(struct bio *bio, unsigned long start_time,
1445 struct block_device *orig_bdev);
1448 * bio_end_io_acct - end I/O accounting for bio based drivers
1449 * @bio: bio to end account for
1450 * @start_time: start time returned by bio_start_io_acct()
1452 static inline void bio_end_io_acct(struct bio *bio, unsigned long start_time)
1454 return bio_end_io_acct_remapped(bio, start_time, bio->bi_bdev);
1457 int bdev_read_only(struct block_device *bdev);
1458 int set_blocksize(struct block_device *bdev, int size);
1460 int lookup_bdev(const char *pathname, dev_t *dev);
1462 void blkdev_show(struct seq_file *seqf, off_t offset);
1464 #define BDEVNAME_SIZE 32 /* Largest string for a blockdev identifier */
1465 #define BDEVT_SIZE 10 /* Largest string for MAJ:MIN for blkdev */
1467 #define BLKDEV_MAJOR_MAX 512
1469 #define BLKDEV_MAJOR_MAX 0
1472 struct blk_holder_ops {
1473 void (*mark_dead)(struct block_device *bdev);
1476 struct block_device *blkdev_get_by_dev(dev_t dev, fmode_t mode, void *holder,
1477 const struct blk_holder_ops *hops);
1478 struct block_device *blkdev_get_by_path(const char *path, fmode_t mode,
1479 void *holder, const struct blk_holder_ops *hops);
1480 int bd_prepare_to_claim(struct block_device *bdev, void *holder,
1481 const struct blk_holder_ops *hops);
1482 void bd_abort_claiming(struct block_device *bdev, void *holder);
1483 void blkdev_put(struct block_device *bdev, fmode_t mode);
1485 /* just for blk-cgroup, don't use elsewhere */
1486 struct block_device *blkdev_get_no_open(dev_t dev);
1487 void blkdev_put_no_open(struct block_device *bdev);
1489 struct block_device *bdev_alloc(struct gendisk *disk, u8 partno);
1490 void bdev_add(struct block_device *bdev, dev_t dev);
1491 struct block_device *I_BDEV(struct inode *inode);
1492 int truncate_bdev_range(struct block_device *bdev, fmode_t mode, loff_t lstart,
1496 void invalidate_bdev(struct block_device *bdev);
1497 int sync_blockdev(struct block_device *bdev);
1498 int sync_blockdev_range(struct block_device *bdev, loff_t lstart, loff_t lend);
1499 int sync_blockdev_nowait(struct block_device *bdev);
1500 void sync_bdevs(bool wait);
1501 void bdev_statx_dioalign(struct inode *inode, struct kstat *stat);
1502 void printk_all_partitions(void);
1503 int __init early_lookup_bdev(const char *pathname, dev_t *dev);
1505 static inline void invalidate_bdev(struct block_device *bdev)
1508 static inline int sync_blockdev(struct block_device *bdev)
1512 static inline int sync_blockdev_nowait(struct block_device *bdev)
1516 static inline void sync_bdevs(bool wait)
1519 static inline void bdev_statx_dioalign(struct inode *inode, struct kstat *stat)
1522 static inline void printk_all_partitions(void)
1525 static inline int early_lookup_bdev(const char *pathname, dev_t *dev)
1529 #endif /* CONFIG_BLOCK */
1531 int fsync_bdev(struct block_device *bdev);
1533 int freeze_bdev(struct block_device *bdev);
1534 int thaw_bdev(struct block_device *bdev);
1536 struct io_comp_batch {
1537 struct request *req_list;
1539 void (*complete)(struct io_comp_batch *);
1542 #define DEFINE_IO_COMP_BATCH(name) struct io_comp_batch name = { }
1544 #endif /* _LINUX_BLKDEV_H */