/* * Maximum number of blkcg policies allowed to be registered concurrently. * Defined here to simplify include dependency.
*/ #define BLKCG_MAX_POLS 6
#define PARTITION_META_INFO_VOLNAMELTH 64 /* * Enough for the string representation of any kind of UUID plus NULL. * EFI UUID is 36 characters. MSDOS UUID is 11 characters.
*/ #define PARTITION_META_INFO_UUIDLTH (UUID_STRING_LEN + 1)
/** * DOC: genhd capability flags * * ``GENHD_FL_REMOVABLE``: indicates that the block device gives access to * removable media. When set, the device remains present even when media is not * inserted. Shall not be set for devices which are removed entirely when the * media is removed. * * ``GENHD_FL_HIDDEN``: the block device is hidden; it doesn't produce events, * doesn't appear in sysfs, and can't be opened from userspace or using * blkdev_get*. Used for the underlying components of multipath devices. * * ``GENHD_FL_NO_PART``: partition support is disabled. The kernel will not * scan for partitions from add_disk, and users can't add partitions manually. *
*/ enum {
GENHD_FL_REMOVABLE = 1 << 0,
GENHD_FL_HIDDEN = 1 << 1,
GENHD_FL_NO_PART = 1 << 2,
};
/* open for reading */ #define BLK_OPEN_READ ((__force blk_mode_t)(1 << 0)) /* open for writing */ #define BLK_OPEN_WRITE ((__force blk_mode_t)(1 << 1)) /* open exclusively (vs other exclusive openers */ #define BLK_OPEN_EXCL ((__force blk_mode_t)(1 << 2)) /* opened with O_NDELAY */ #define BLK_OPEN_NDELAY ((__force blk_mode_t)(1 << 3)) /* open for "writes" only for ioctls (specialy hack for floppy.c) */ #define BLK_OPEN_WRITE_IOCTL ((__force blk_mode_t)(1 << 4)) /* open is exclusive wrt all other BLK_OPEN_WRITE opens to the device */ #define BLK_OPEN_RESTRICT_WRITES ((__force blk_mode_t)(1 << 5)) /* return partition scanning errors */ #define BLK_OPEN_STRICT_SCAN ((__force blk_mode_t)(1 << 6))
struct gendisk { /* * major/first_minor/minors should not be set by any new driver, the * block core will take care of allocating them automatically.
*/ int major; int first_minor; int minors;
char disk_name[DISK_NAME_LEN]; /* name of major driver */
unsignedshort events; /* supported events */ unsignedshort event_flags; /* flags related to event processing */
#ifdef CONFIG_BLK_DEV_ZONED /* * Zoned block device information. Reads of this information must be * protected with blk_queue_enter() / blk_queue_exit(). Modifying this * information is only allowed while no requests are being processed. * See also blk_mq_freeze_queue() and blk_mq_unfreeze_queue().
*/ unsignedint nr_zones; unsignedint zone_capacity; unsignedint last_zone_capacity; unsignedlong __rcu *conv_zones_bitmap; unsignedint zone_wplugs_hash_bits;
atomic_t nr_zone_wplugs;
spinlock_t zone_wplugs_lock; struct mempool_s *zone_wplugs_pool; struct hlist_head *zone_wplugs_hash; struct workqueue_struct *zone_wplugs_wq; #endif/* CONFIG_BLK_DEV_ZONED */
/* * Independent sector access ranges. This is always NULL for * devices that do not have multiple independent access ranges.
*/ struct blk_independent_access_ranges *ia_ranges;
struct mutex rqos_state_mutex; /* rqos state change mutex */
};
/** * disk_openers - returns how many openers are there for a disk * @disk: disk to check * * This returns the number of openers for a disk. Note that this value is only * stable if disk->open_mutex is held. * * Note: Due to a quirk in the block layer open code, each open partition is * only counted once even if there are multiple openers.
*/ staticinlineunsignedint disk_openers(struct gendisk *disk)
{ return atomic_read(&disk->part0->bd_openers);
}
/** * disk_has_partscan - return %true if partition scanning is enabled on a disk * @disk: disk to check * * Returns %true if partitions scanning is enabled for @disk, or %false if * partition scanning is disabled either permanently or temporarily.
*/ staticinlinebool disk_has_partscan(struct gendisk *disk)
{ return !(disk->flags & (GENHD_FL_NO_PART | GENHD_FL_HIDDEN)) &&
!test_bit(GD_SUPPRESS_PART_SCAN, &disk->state);
}
/* * The gendisk is refcounted by the part0 block_device, and the bd_device * therein is also used for device model presentation in sysfs.
*/ #define dev_to_disk(device) \
(dev_to_bdev(device)->bd_disk) #define disk_to_dev(disk) \
(&((disk)->part0->bd_device))
#ifdef CONFIG_TRANSPARENT_HUGEPAGE /* * We should strive for 1 << (PAGE_SHIFT + MAX_PAGECACHE_ORDER) * however we constrain this to what we can validate and test.
*/ #define BLK_MAX_BLOCK_SIZE SZ_64K #else #define BLK_MAX_BLOCK_SIZE PAGE_SIZE #endif
/* blk_validate_limits() validates bsize, so drivers don't usually need to */ staticinlineint blk_validate_block_size(unsignedlong bsize)
{ if (bsize < 512 || bsize > BLK_MAX_BLOCK_SIZE || !is_power_of_2(bsize)) return -EINVAL;
return 0;
}
staticinlinebool blk_op_is_passthrough(blk_opf_t op)
{
op &= REQ_OP_MASK; return op == REQ_OP_DRV_IN || op == REQ_OP_DRV_OUT;
}
/* flags set by the driver in queue_limits.features */ typedefunsignedint __bitwise blk_features_t;
/* * Drivers that set dma_alignment to less than 511 must be prepared to * handle individual bvec's that are not a multiple of a SECTOR_SIZE * due to possible offsets.
*/ unsignedint dma_alignment; unsignedint dma_pad_mask;
#define BLK_ALL_ZONES ((unsignedint)-1) int blkdev_report_zones(struct block_device *bdev, sector_t sector, unsignedint nr_zones, report_zones_cb cb, void *data); int blkdev_zone_mgmt(struct block_device *bdev, enum req_op op,
sector_t sectors, sector_t nr_sectors); int blk_revalidate_disk_zones(struct gendisk *disk);
/* * Independent access ranges: struct blk_independent_access_range describes * a range of contiguous sectors that can be accessed using device command * execution resources that are independent from the resources used for * other access ranges. This is typically found with single-LUN multi-actuator * HDDs where each access range is served by a different set of heads. * The set of independent ranges supported by the device is defined using * struct blk_independent_access_ranges. The independent ranges must not overlap * and must include all sectors within the disk capacity (no sector holes * allowed). * For a device with multiple ranges, requests targeting sectors in different * ranges can be executed in parallel. A request can straddle an access range * boundary.
*/ struct blk_independent_access_range { struct kobject kobj;
sector_t sector;
sector_t nr_sectors;
};
/* * Number of contexts that have called blk_set_pm_only(). If this * counter is above zero then only RQF_PM requests are processed.
*/
atomic_t pm_only;
/* * Protects against I/O scheduler switching, particularly when updating * q->elevator. Since the elevator update code path may also modify q-> * nr_requests and wbt latency, this lock also protects the sysfs attrs * nr_requests and wbt_lat_usec. Additionally the nr_hw_queues update * may modify hctx tags, reserved-tags and cpumask, so this lock also * helps protect the hctx sysfs/debugfs attrs. To ensure proper locking * order during an elevator or nr_hw_queue update, first freeze the * queue, then acquire ->elevator_lock.
*/ struct mutex elevator_lock;
struct mutex sysfs_lock; /* * Protects queue limits and also sysfs attribute read_ahead_kb.
*/ struct mutex limits_lock;
/* * for reusing dead hctx instance in case of updating * nr_hw_queues
*/ struct list_head unused_hctx_list;
spinlock_t unused_hctx_lock;
int mq_freeze_depth;
#ifdef CONFIG_BLK_DEV_THROTTLING /* Throttle data */ struct throtl_data *td; #endif struct rcu_head rcu_head; #ifdef CONFIG_LOCKDEP struct task_struct *mq_freeze_owner; int mq_freeze_owner_depth; /* * Records disk & queue state in current context, used in unfreeze * queue
*/ bool mq_freeze_disk_dead; bool mq_freeze_queue_dying; #endif
wait_queue_head_t mq_freeze_wq; /* * Protect concurrent access to q_usage_counter by * percpu_ref_kill() and percpu_ref_reinit().
*/ struct mutex mq_freeze_lock;
struct dentry *debugfs_dir; struct dentry *sched_debugfs_dir; struct dentry *rqos_debugfs_dir; /* * Serializes all debugfs metadata operations using the above dentries.
*/ struct mutex debugfs_mutex;
};
/* Keep blk_queue_flag_name[] in sync with the definitions below */ enum {
QUEUE_FLAG_DYING, /* queue being torn down */
QUEUE_FLAG_NOMERGES, /* disable merge attempts */
QUEUE_FLAG_SAME_COMP, /* complete on same CPU-group */
QUEUE_FLAG_FAIL_IO, /* fake timeout */
QUEUE_FLAG_NOXMERGES, /* No extended merges */
QUEUE_FLAG_SAME_FORCE, /* force complete on same CPU */
QUEUE_FLAG_INIT_DONE, /* queue is initialized */
QUEUE_FLAG_STATS, /* track IO start and completion times */
QUEUE_FLAG_REGISTERED, /* queue has been registered to a disk */
QUEUE_FLAG_QUIESCED, /* queue has been quiesced */
QUEUE_FLAG_RQ_ALLOC_TIME, /* record rq->alloc_time_ns */
QUEUE_FLAG_HCTX_ACTIVE, /* at least one blk-mq hctx is active */
QUEUE_FLAG_SQ_SCHED, /* single queue style io dispatch */
QUEUE_FLAG_DISABLE_WBT_DEF, /* for sched to disable/enable wbt */
QUEUE_FLAG_NO_ELV_SWITCH, /* can't switch elevator any more */
QUEUE_FLAG_QOS_ENABLED, /* qos is enabled */
QUEUE_FLAG_MAX
};
/** * bio_needs_zone_write_plugging - Check if a BIO needs to be handled with zone * write plugging * @bio: The BIO being submitted * * Return true whenever @bio execution needs to be handled through zone * write plugging (using blk_zone_plug_bio()). Return false otherwise.
*/ staticinlinebool bio_needs_zone_write_plugging(struct bio *bio)
{ enum req_op op = bio_op(bio);
/* * Only zoned block devices have a zone write plug hash table. But not * all of them have one (e.g. DM devices may not need one).
*/ if (!bio->bi_bdev->bd_disk->zone_wplugs_hash) returnfalse;
/* Only write operations need zone write plugging. */ if (!op_is_write(op)) returnfalse;
/* Ignore empty flush */ if (op_is_flush(bio->bi_opf) && !bio_sectors(bio)) returnfalse;
/* Ignore BIOs that already have been handled by zone write plugging. */ if (bio_flagged(bio, BIO_ZONE_WRITE_PLUGGING)) returnfalse;
/* * All zone write operations must be handled through zone write plugging * using blk_zone_plug_bio().
*/ switch (op) { case REQ_OP_ZONE_APPEND: case REQ_OP_WRITE: case REQ_OP_WRITE_ZEROES: case REQ_OP_ZONE_FINISH: case REQ_OP_ZONE_RESET: case REQ_OP_ZONE_RESET_ALL: returntrue; default: returnfalse;
}
}
bool blk_zone_plug_bio(struct bio *bio, unsignedint nr_segs);
/** * disk_zone_capacity - returns the zone capacity of zone containing @sector * @disk: disk to work with * @sector: sector number within the querying zone * * Returns the zone capacity of a zone containing @sector. @sector can be any * sector in the zone.
*/ staticinlineunsignedint disk_zone_capacity(struct gendisk *disk,
sector_t sector)
{
sector_t zone_sectors = disk->queue->limits.chunk_sectors;
/** * blk_alloc_disk - allocate a gendisk structure * @lim: queue limits to be used for this disk. * @node_id: numa node to allocate on * * Allocate and pre-initialize a gendisk structure for use with BIO based * drivers. * * Returns an ERR_PTR on error, else the allocated disk. * * Context: can sleep
*/ #define blk_alloc_disk(lim, node_id) \
({ \ staticstruct lock_class_key __key; \
\
__blk_alloc_disk(lim, node_id, &__key); \
})
/* Helper to convert REQ_OP_XXX to its string format XXX */ externconstchar *blk_op_str(enum req_op op);
int blk_status_to_errno(blk_status_t status);
blk_status_t errno_to_blk_status(int errno); constchar *blk_status_to_str(blk_status_t status);
/* only poll the hardware once, don't continue until a completion was found */ #define BLK_POLL_ONESHOT (1 << 0) int bio_poll(struct bio *bio, struct io_comp_batch *iob, unsignedint flags); int iocb_bio_iopoll(struct kiocb *kiocb, struct io_comp_batch *iob, unsignedint flags);
staticinlinestruct request_queue *bdev_get_queue(struct block_device *bdev)
{ return bdev->bd_queue; /* this is never NULL */
}
/* Helper to convert BLK_ZONE_ZONE_XXX to its string format XXX */ constchar *blk_zone_cond_str(enum blk_zone_cond zone_cond);
staticinlineunsignedint bio_zone_no(struct bio *bio)
{ return disk_zone_no(bio->bi_bdev->bd_disk, bio->bi_iter.bi_sector);
}
/* * Return how much within the boundary is left to be used for I/O at a given * offset.
*/ staticinlineunsignedint blk_boundary_sectors_left(sector_t offset, unsignedint boundary_sectors)
{ if (unlikely(!is_power_of_2(boundary_sectors))) return boundary_sectors - sector_div(offset, boundary_sectors); return boundary_sectors - (offset & (boundary_sectors - 1));
}
/** * queue_limits_start_update - start an atomic update of queue limits * @q: queue to update * * This functions starts an atomic update of the queue limits. It takes a lock * to prevent other updates and returns a snapshot of the current limits that * the caller can modify. The caller must call queue_limits_commit_update() * to finish the update. * * Context: process context.
*/ staticinlinestruct queue_limits
queue_limits_start_update(struct request_queue *q)
{
mutex_lock(&q->limits_lock); return q->limits;
} int queue_limits_commit_update_frozen(struct request_queue *q, struct queue_limits *lim); int queue_limits_commit_update(struct request_queue *q, struct queue_limits *lim); int queue_limits_set(struct request_queue *q, struct queue_limits *lim); int blk_validate_limits(struct queue_limits *lim);
/** * queue_limits_cancel_update - cancel an atomic update of queue limits * @q: queue to update * * This functions cancels an atomic update of the queue limits started by * queue_limits_start_update() and should be used when an error occurs after * starting update.
*/ staticinlinevoid queue_limits_cancel_update(struct request_queue *q)
{
mutex_unlock(&q->limits_lock);
}
/* * These helpers are for drivers that have sloppy feature negotiation and might * have to disable DISCARD, WRITE_ZEROES or SECURE_DISCARD from the I/O * completion handler when the device returned an indicator that the respective * feature is not actually supported. They are racy and the driver needs to * cope with that. Try to avoid this scheme if you can.
*/ staticinlinevoid blk_queue_disable_discard(struct request_queue *q)
{
q->limits.max_discard_sectors = 0;
}
#ifdef CONFIG_BLOCK /* * blk_plug permits building a queue of related requests by holding the I/O * fragments for a short period. This allows merging of sequential requests * into single larger request. As the requests are moved from a per-task list to * the device's request_queue in a batch, this results in improved scalability * as the lock contention for request_queue lock is reduced. * * It is ok not to disable preemption when adding the request to the plug list * or when attempting a merge. For details, please see schedule() where * blk_flush_plug() is called.
*/ struct blk_plug { struct rq_list mq_list; /* blk-mq requests */
/* if ios_left is > 1, we can batch tag/rq allocations */ struct rq_list cached_rqs;
u64 cur_ktime; unsignedshort nr_ios;
/* Check whether @sector is a multiple of the zone size. */ staticinlinebool bdev_is_zone_aligned(struct block_device *bdev,
sector_t sector)
{ return bdev_is_zone_start(bdev, sector);
}
/** * bdev_zone_is_seq - check if a sector belongs to a sequential write zone * @bdev: block device to check * @sector: sector number * * Check if @sector on @bdev is contained in a sequential write required zone.
*/ staticinlinebool bdev_zone_is_seq(struct block_device *bdev, sector_t sector)
{ bool is_seq = false;
enum blk_unique_id { /* these match the Designator Types specified in SPC */
BLK_UID_T10 = 1,
BLK_UID_EUI64 = 2,
BLK_UID_NAA = 3,
};
struct block_device_operations { void (*submit_bio)(struct bio *bio); int (*poll_bio)(struct bio *bio, struct io_comp_batch *iob, unsignedint flags); int (*open)(struct gendisk *disk, blk_mode_t mode); void (*release)(struct gendisk *disk); int (*ioctl)(struct block_device *bdev, blk_mode_t mode, unsigned cmd, unsignedlong arg); int (*compat_ioctl)(struct block_device *bdev, blk_mode_t mode, unsigned cmd, unsignedlong arg); unsignedint (*check_events) (struct gendisk *disk, unsignedint clearing); void (*unlock_native_capacity) (struct gendisk *); int (*getgeo)(struct block_device *, struct hd_geometry *); int (*set_read_only)(struct block_device *bdev, bool ro); void (*free_disk)(struct gendisk *disk); /* this callback is with swap_lock and sometimes page table lock held */ void (*swap_slot_free_notify) (struct block_device *, unsignedlong); int (*report_zones)(struct gendisk *, sector_t sector, unsignedint nr_zones, report_zones_cb cb, void *data); char *(*devnode)(struct gendisk *disk, umode_t *mode); /* returns the length of the identifier or a negative errno: */ int (*get_unique_id)(struct gendisk *disk, u8 id[16], enum blk_unique_id id_type); struct module *owner; conststruct pr_ops *pr_ops;
/* * Special callback for probing GPT entry at a given sector. * Needed by Android devices, used by GPT scanner and MMC blk * driver.
*/ int (*alternative_gpt_sector)(struct gendisk *disk, sector_t *sector);
};
staticinlinevoid blk_wake_io_task(struct task_struct *waiter)
{ /* * If we're polling, the task itself is doing the completions. For * that case, we don't need to signal a wakeup, it's enough to just * mark us as RUNNING.
*/ if (waiter == current)
__set_current_state(TASK_RUNNING); else
wake_up_process(waiter);
}
unsignedlong bio_start_io_acct(struct bio *bio); void bio_end_io_acct_remapped(struct bio *bio, unsignedlong start_time, struct block_device *orig_bdev);
/** * bio_end_io_acct - end I/O accounting for bio based drivers * @bio: bio to end account for * @start_time: start time returned by bio_start_io_acct()
*/ staticinlinevoid bio_end_io_acct(struct bio *bio, unsignedlong start_time)
{ return bio_end_io_acct_remapped(bio, start_time, bio->bi_bdev);
}
int bdev_validate_blocksize(struct block_device *bdev, int block_size); int set_blocksize(struct file *file, int size);
/* * Sync the file system mounted on the block device.
*/ void (*sync)(struct block_device *bdev);
/* * Freeze the file system mounted on the block device.
*/ int (*freeze)(struct block_device *bdev);
/* * Thaw the file system mounted on the block device.
*/ int (*thaw)(struct block_device *bdev);
};
/* * For filesystems using @fs_holder_ops, the @holder argument passed to * helpers used to open and claim block devices via * bd_prepare_to_claim() must point to a superblock.
*/ externconststruct blk_holder_ops fs_holder_ops;
/* * Return the correct open flags for blkdev_get_by_* for super block flags * as stored in sb->s_flags.
*/ #define sb_open_mode(flags) \
(BLK_OPEN_READ | BLK_OPEN_RESTRICT_WRITES | \
(((flags) & SB_RDONLY) ? 0 : BLK_OPEN_WRITE))
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.