decruft genhd.h v2
Subsystems (9)
Christoph Hellwig
maintainerHi Jens,
this series tries to move as much out of genhd.h that doesn't really belong there.
Changes since v1:
- rebased to the latest block tree
Christoph Hellwig
maintainerPATCH 1/9 block: mark block_depr static
--- block/genhd.c | 2 +- include/linux/genhd.h | 1 - 2 files changed, 1 insertion(+), 2 deletions(-)
block/genhd.c +1 -1
@@ -27,7 +27,7 @@#include "blk.h" static DEFINE_MUTEX (block_class_lock); -struct kobject *block_depr; +static struct kobject *block_depr;/* for extended dynamic devt allocation, currently only one major is used */ #define NR_EXT_DEVT (1 << MINORBITS)
include/linux/genhd.h +0 -1
@@ -27,7 +27,6 @@#define part_to_dev (part) (&((part)->__dev))extern struct device_type part_type; -extern struct kobject *block_depr;extern struct class block_class;#define DISK_MAX_PARTS 256
Signature · 1 line
2.25.1
Christoph Hellwig
maintainerPATCH 2/9 block: mark part_in_flight and part_in_flight_rw static
In reply to Christoph Hellwig--- block/genhd.c | 7 ++++--- include/linux/genhd.h | 3 --- 2 files changed, 4 insertions(+), 6 deletions(-)
block/genhd.c +4 -3
@@ -139,7 +139,8 @@ void part_dec_in_flight(struct request_queue *q, struct hd_struct *part, int rw)part_stat_local_dec (&part_to_disk (part)->part0, in_flight[rw]); } -unsigned int part_in_flight (struct request_queue *q,struct hd_struct *part) +static unsigned int part_in_flight (struct request_queue *q, +struct hd_struct *part) {int cpu;unsigned int inflight;
@@ -159,8 +160,8 @@ unsigned int part_in_flight(struct request_queue *q, struct hd_struct *part)return inflight; } -void part_in_flight_rw (struct request_queue *q,struct hd_struct *part, -unsigned int inflight[2 ]) +static void part_in_flight_rw (struct request_queue *q,struct hd_struct *part, +unsigned int inflight[2 ]) {int cpu;
include/linux/genhd.h +0 -3
@@ -409,9 +409,6 @@ static inline void free_part_stats(struct hd_struct *part)#define part_stat_local_read_cpu (gendiskp, field, cpu) \ local_read(&(part_stat_get_cpu(gendiskp, field, cpu))) -unsigned int part_in_flight (struct request_queue *q,struct hd_struct *part); -void part_in_flight_rw (struct request_queue *q,struct hd_struct *part, -unsigned int inflight[2 ]);void part_dec_in_flight (struct request_queue *q,struct hd_struct *part,int rw); void part_inc_in_flight(struct request_queue *q, struct hd_struct *part,
Signature · 1 line
2.25.1
Re: [PATCH 2/9] block: mark part_in_flight and part_in_flight_rw static
Quoted 1 line · Christoph Hellwig
Signed-off-by Christoph Hellwig <[email protected]>
Some people still ask for some commit description, not just a sign-off line.
I do think that's unnecessary though when, as here, the patch subject is descriptive and complete.
block/genhd.c
Quoted 1 line
block/genhd.c +0
-0
[]
block/genhd.c void part_dec_in_flight(struct request_queue *q, struct hd_struct *part, int rw) · line 143
Quoted 7 lines
block/genhd.c +2
-1@@ -139,7 +139,8 @@ void part_dec_in_flight(struct request_queue *q, struct hd_struct *part, int rw)part_stat_local_dec (&part_to_disk (part)->part0, in_flight[rw]); } -unsigned int part_in_flight (struct request_queue *q,struct hd_struct *part) +static unsigned int part_in_flight (struct request_queue *q, +struct hd_struct *part)
genhd.c aligns multi-line arguments to open parenthesis, it'd be nicer to maintain that style.
block/genhd.c unsigned int part_in_flight(struct request_queue *q, struct hd_struct *part) · line 164
Quoted 11 lines
block/genhd.c +2
-2{int cpu;unsigned int inflight;@@ -159,8 +160,8 @@ unsigned int part_in_flight(struct request_queue *q, struct hd_struct *part)return inflight; } -void part_in_flight_rw (struct request_queue *q,struct hd_struct *part, -unsigned int inflight[2 ]) +static void part_in_flight_rw (struct request_queue *q,struct hd_struct *part, +unsigned int inflight[2 ])
etc.
Christoph Hellwig
maintainerPATCH 3/9 block: unexport disk_get_part
In reply to Christoph Hellwigdisk_get_part is not used by any modular code.
--- block/genhd.c | 1 - 1 file changed, 1 deletion(-)
block/genhd.c +0 -1
@@ -217,7 +217,6 @@ struct hd_struct *disk_get_part(struct gendisk *disk, int partno)return part; } -EXPORT_SYMBOL_GPL (disk_get_part);/** * disk_part_iter_init - initialize partition iterator
Signature · 1 line
2.25.1
Christoph Hellwig
maintainerPATCH 4/9 block: unexport disk_map_sector_rcu
In reply to Christoph Hellwigdisk_map_sector_rcu is not used by any modular code.
--- block/genhd.c | 1 - 1 file changed, 1 deletion(-)
block/genhd.c +0 -1
@@ -372,7 +372,6 @@ struct hd_struct *disk_map_sector_rcu(struct gendisk *disk, sector_t sector) }return &disk->part0; } -EXPORT_SYMBOL_GPL (disk_map_sector_rcu);/* * Can be deleted altogether. Later.
Signature · 1 line
2.25.1
Christoph Hellwig
maintainerPATCH 5/9 block: unexport get_gendisk
In reply to Christoph Hellwigget_gendisk is not used by any modular code.
--- block/genhd.c | 1 - 1 file changed, 1 deletion(-)
block/genhd.c +0 -1
@@ -980,7 +980,6 @@ struct gendisk *get_gendisk(dev_t devt, int *partno) }return disk; } -EXPORT_SYMBOL (get_gendisk);/** * bdget_disk - do bdget() by gendisk and partition number
Signature · 1 line
2.25.1
Christoph Hellwig
maintainerPATCH 6/9 block: move guard_bio_eod to bio.c
In reply to Christoph HellwigThis is bio layer functionality and not related to buffer heads.
--- block/bio.c | 43 +++++++++++++++++++++++++++++++++++++++++++ fs/buffer.c | 43 ------------------------------------------- fs/internal.h | 1 - include/linux/bio.h | 1 + 4 files changed, 44 insertions(+), 44 deletions(-)
block/bio.c +43 -0
@@ -588,6 +588,49 @@ void bio_truncate(struct bio *bio, unsigned new_size) bio->bi_iter.bi_size = new_size; } +/** +* guard_bio_eod - truncate a BIO to fit the block device +* @bio: bio to truncate +* +* This allows us to do IO even on the odd last sectors of a device, even if the +* block size is some multiple of the physical sector size. +* +* We'll just truncate the bio to the size of the device, and clear the end of +* the buffer head manually. Truly out-of-range accesses will turn into actual +* I/O errors, this only handles the "we need to be able to do I/O at the final +* sector" case. +*/ +void guard_bio_eod (struct bio *bio) +{ +sector_t maxsector; +struct hd_struct *part; + +rcu_read_lock (); + part =__disk_get_part (bio->bi_disk, bio->bi_partno); +if (part) + maxsector =part_nr_sects_read (part); +else + maxsector =get_capacity (bio->bi_disk); +rcu_read_unlock (); + +if (!maxsector) +return ; + +/* +* If the *whole* IO is past the end of the device, +* let it through, and the IO layer will turn it into +* an EIO. +*/ +if (unlikely (bio->bi_iter.bi_sector >= maxsector)) +return ; + + maxsector -= bio->bi_iter.bi_sector; +if (likely ((bio->bi_iter.bi_size >>9 ) <= maxsector)) +return ; + +bio_truncate (bio, maxsector <<9 ); +} +/** * bio_put - release a reference to a bio * @bio: bio to release reference to
fs/buffer.c +0 -43
49 lines not on this page · raw message
fs/internal.h +0 -1
@@ -38,7 +38,6 @@ static inline int __sync_blockdev(struct block_device *bdev, int wait)/* * buffer.c */ -extern void guard_bio_eod (struct bio *bio);extern int __block_write_begin_int (struct page *page,loff_t pos,unsigned len,get_block_t *get_block,struct iomap *iomap);
include/linux/bio.h +1 -0
@@ -471,6 +471,7 @@ extern struct bio *bio_copy_user_iov(struct request_queue *,extern int bio_uncopy_user (struct bio *);void zero_fill_bio_iter (struct bio *bio,struct bvec_iter iter);void bio_truncate (struct bio *bio,unsigned new_size); +void guard_bio_eod (struct bio *bio);static inline void zero_fill_bio (struct bio *bio) {
Signature · 1 line
2.25.1
Christoph Hellwig
maintainerPATCH 7/9 block: move block layer internals out of include/linux/genhd.h
In reply to Christoph HellwigNone of this needs to be exposed to drivers.
--- block/blk.h | 116 +++++++++++++++++++++++++++++++++++++ block/ioctl.c | 1 + block/partitions/check.h | 1 + block/partitions/core.c | 1 - include/linux/genhd.h | 120 --------------------------------------- 5 files changed, 118 insertions(+), 121 deletions(-)
block/blk.h +116 -0
@@ -149,6 +149,9 @@ static inline bool integrity_req_gap_front_merge(struct request *req,return bvec_gap_to_prev (req->q, &bip->bip_vec[bip->bip_vcnt -1 ], bip_next->bip_vec[0].bv_offset); } + +void blk_integrity_add (struct gendisk *); +void blk_integrity_del (struct gendisk *);#else /* CONFIG_BLK_DEV_INTEGRITY */ static inline bool integrity_req_gap_back_merge (struct request *req,struct bio *next)
@@ -171,6 +174,12 @@ static inline bool bio_integrity_endio(struct bio *bio)static inline void bio_integrity_free (struct bio *bio) { } +static inline void blk_integrity_add (struct gendisk *disk) +{ +} +static inline void blk_integrity_del (struct gendisk *disk) +{ +}#endif /* CONFIG_BLK_DEV_INTEGRITY */ unsigned long blk_rq_timeout (unsigned long timeout);
@@ -365,4 +374,111 @@ void blk_queue_free_zone_bitmaps(struct request_queue *q);static inline void blk_queue_free_zone_bitmaps (struct request_queue *q) {}#endif +void part_dec_in_flight (struct request_queue *q,struct hd_struct *part, +int rw); +void part_inc_in_flight (struct request_queue *q,struct hd_struct *part, +int rw); +void update_io_ticks (struct hd_struct *part,unsigned long now,bool end); +struct hd_struct *disk_map_sector_rcu (struct gendisk *disk,sector_t sector); + +int blk_alloc_devt (struct hd_struct *part,dev_t *devt); +void blk_free_devt (dev_t devt); +void blk_invalidate_devt (dev_t devt); +char *disk_name (struct gendisk *hd,int partno,char *buf); +#define ADDPART_FLAG_NONE 0 +#define ADDPART_FLAG_RAID 1 +#define ADDPART_FLAG_WHOLEDISK 2 +struct hd_struct *__must_check add_partition (struct gendisk *disk,int partno, +sector_t start,sector_t len,int flags, +struct partition_meta_info *info); +void __delete_partition (struct percpu_ref *ref); +void delete_partition (struct gendisk *disk,int partno); +int disk_expand_part_tbl (struct gendisk *disk,int target); + +static inline int hd_ref_init (struct hd_struct *part) +{ +if (percpu_ref_init (&part->ref, __delete_partition,0 , +GFP_KERNEL )) +return -ENOMEM ; +return 0 ; +} + +static inline void hd_struct_get (struct hd_struct *part) +{ +percpu_ref_get (&part->ref); +} + +static inline int hd_struct_try_get (struct hd_struct *part) +{ +return percpu_ref_tryget_live (&part->ref); +} + +static inline void hd_struct_put (struct hd_struct *part) +{ +percpu_ref_put (&part->ref); +} + +static inline void hd_struct_kill (struct hd_struct *part) +{ +percpu_ref_kill (&part->ref); +} + +static inline void hd_free_part (struct hd_struct *part) +{ +free_part_stats (part); +kfree (part->info); +percpu_ref_exit (&part->ref); +} + +/* +* Any access of part->nr_sects which is not protected by partition +* bd_mutex or gendisk bdev bd_mutex, should be done using this +* accessor function. +* +* Code written along the lines of i_size_read() and i_size_write(). +* CONFIG_PREEMPTION case optimizes the case of UP kernel with preemption +* on. +*/ +static inline sector_t part_nr_sects_read (struct hd_struct *part) +{ +#if BITS_PER_LONG ==32 && defined(CONFIG_SMP ) +sector_t nr_sects; +unsigned seq; +do { + seq =read_seqcount_begin (&part->nr_sects_seq); + nr_sects = part->nr_sects; + }while (read_seqcount_retry (&part->nr_sects_seq, seq)); +return nr_sects; +#elif BITS_PER_LONG ==32 && defined(CONFIG_PREEMPTION ) +sector_t nr_sects; + +preempt_disable (); + nr_sects = part->nr_sects; +preempt_enable (); +return nr_sects; +#else +return part->nr_sects; +#endif +} + +/* +* Should be called with mutex lock held (typically bd_mutex) of partition +* to provide mutual exlusion among writers otherwise seqcount might be +* left in wrong state leaving the readers spinning infinitely. +*/ +static inline void part_nr_sects_write (struct hd_struct *part,sector_t size) +{ +#if BITS_PER_LONG ==32 && defined(CONFIG_SMP ) +write_seqcount_begin (&part->nr_sects_seq); + part->nr_sects = size; +write_seqcount_end (&part->nr_sects_seq); +#elif BITS_PER_LONG ==32 && defined(CONFIG_PREEMPTION ) +preempt_disable (); + part->nr_sects = size; +preempt_enable (); +#else + part->nr_sects = size; +#endif +} +#endif /* BLK_INTERNAL_H */
block/ioctl.c +1 -0
@@ -11,6 +11,7 @@#include <linux/blktrace_api.h> #include <linux/pr.h> #include <linux/uaccess.h> +#include "blk.h" static int blkpg_do_ioctl (struct block_device *bdev,struct blkpg_partition __user *upart,int op)
block/partitions/check.h +1 -0
@@ -2,6 +2,7 @@#include <linux/pagemap.h> #include <linux/blkdev.h> #include <linux/genhd.h> +#include "../blk.h" /* * add_gd_partition adds a partitions details to the devices partition
block/partitions/core.c +0 -1
@@ -10,7 +10,6 @@#include <linux/vmalloc.h> #include <linux/blktrace_api.h> #include <linux/raid/detect.h> -#include "../blk.h" #include "check.h" static int (*check_part[])(struct parsed_partitions *) = {
include/linux/genhd.h +0 -120
149 lines not on this page · raw message
Signature · 1 line
2.25.1
Christoph Hellwig
maintainerPATCH 8/9 block: move the part_stat* helpers from genhd.h to a new header
In reply to Christoph HellwigThese macros are just used by a few files. Move them out of genhd.h, which is included everywhere into a new standalone header.
--- block/blk.h | 1 + drivers/block/drbd/drbd_receiver.c | 1 + drivers/block/drbd/drbd_worker.c | 1 + drivers/block/zram/zram_drv.c | 1 + drivers/md/dm.c | 1 + drivers/md/md.c | 1 + drivers/nvme/target/admin-cmd.c | 1 + fs/ext4/super.c | 2 +- fs/ext4/sysfs.c | 1 + fs/f2fs/f2fs.h | 1 + fs/f2fs/super.c | 1 + include/linux/genhd.h | 108 --------------------------- include/linux/part_stat.h | 115 +++++++++++++++++++++++++++++ 13 files changed, 126 insertions(+), 109 deletions(-) create mode 100644 include/linux/part_stat.h
block/blk.h +1 -0
@@ -4,6 +4,7 @@#include <linux/idr.h> #include <linux/blk-mq.h> +#include <linux/part_stat.h> #include <xen/xen.h> #include "blk-mq.h" #include "blk-mq-sched.h"
drivers/block/drbd/drbd_receiver.c +1 -0
@@ -33,6 +33,7 @@#include <linux/random.h> #include <linux/string.h> #include <linux/scatterlist.h> +#include <linux/part_stat.h> #include "drbd_int.h" #include "drbd_protocol.h" #include "drbd_req.h"
drivers/block/drbd/drbd_worker.c +1 -0
@@ -22,6 +22,7 @@#include <linux/random.h> #include <linux/string.h> #include <linux/scatterlist.h> +#include <linux/part_stat.h> #include "drbd_int.h" #include "drbd_protocol.h"
drivers/block/zram/zram_drv.c +1 -0
@@ -33,6 +33,7 @@#include <linux/sysfs.h> #include <linux/debugfs.h> #include <linux/cpuhotplug.h> +#include <linux/part_stat.h> #include "zram_drv.h"
drivers/md/dm.c +1 -0
@@ -25,6 +25,7 @@#include <linux/wait.h> #include <linux/pr.h> #include <linux/refcount.h> +#include <linux/part_stat.h> #define DM_MSG_PREFIX "core"
drivers/md/md.c +1 -0
@@ -61,6 +61,7 @@#include <linux/raid/detect.h> #include <linux/slab.h> #include <linux/percpu-refcount.h> +#include <linux/part_stat.h> #include <trace/events/block.h> #include "md.h"
drivers/nvme/target/admin-cmd.c +1 -0
@@ -6,6 +6,7 @@#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt#include <linux/module.h> #include <linux/rculist.h> +#include <linux/part_stat.h> #include <generated/utsrelease.h> #include <asm/unaligned.h>
fs/ext4/super.c +1 -1
@@ -43,7 +43,7 @@#include <linux/uaccess.h> #include <linux/iversion.h> #include <linux/unicode.h> - +#include <linux/part_stat.h> #include <linux/kthread.h> #include <linux/freezer.h>
fs/ext4/sysfs.c +1 -0
@@ -13,6 +13,7 @@#include <linux/seq_file.h> #include <linux/slab.h> #include <linux/proc_fs.h> +#include <linux/part_stat.h> #include "ext4.h" #include "ext4_jbd2.h"
fs/f2fs/f2fs.h +1 -0
@@ -22,6 +22,7 @@#include <linux/bio.h> #include <linux/blkdev.h> #include <linux/quotaops.h> +#include <linux/part_stat.h> #include <crypto/hash.h> #include <linux/fscrypt.h>
fs/f2fs/super.c +1 -0
@@ -24,6 +24,7 @@#include <linux/sysfs.h> #include <linux/quota.h> #include <linux/unicode.h> +#include <linux/part_stat.h> #include "f2fs.h" #include "node.h"
include/linux/genhd.h +0 -108
114 lines not on this page · raw message
include/linux/part_stat.h new file +115 -0
115 lines not on this page · raw message
Signature · 1 line
2.25.1
Christoph Hellwig
maintainerPATCH 9/9 block: make the init_part_stats return value more logical
In reply to Christoph HellwigReturn 0 / -ENOMEM instead of a boolean dressed up as int.
--- block/genhd.c | 2 +- block/partitions/core.c | 2 +- include/linux/part_stat.h | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-)
block/genhd.c +1 -1
@@ -1644,7 +1644,7 @@ struct gendisk *__alloc_disk_node(int minors, int node_id) disk =kzalloc_node (sizeof (struct gendisk ),GFP_KERNEL , node_id);if (disk) { -if (!init_part_stats (&disk->part0)) { +if (init_part_stats (&disk->part0)) {kfree (disk);return NULL ; }
block/partitions/core.c +1 -1
@@ -377,7 +377,7 @@ struct hd_struct *add_partition(struct gendisk *disk, int partno,if (!p)return ERR_PTR (-EBUSY ); -if (!init_part_stats (p)) { +if (init_part_stats (p)) { err = -ENOMEM ; goto out_free; }
include/linux/part_stat.h +3 -3
@@ -48,8 +48,8 @@ static inline int init_part_stats(struct hd_struct *part) { part->dkstats = alloc_percpu(struct disk_stats);if (!part->dkstats) -return 0 ; -return 1 ; +return -ENOMEM ; +return 0 ; }static inline void free_part_stats (struct hd_struct *part)
@@ -72,7 +72,7 @@ static inline void part_stat_set_all(struct hd_struct *part, int value)static inline int init_part_stats (struct hd_struct *part) { -return 1 ; +return 0 ; }static inline void free_part_stats (struct hd_struct *part)
Signature · 1 line
2.25.1
Quoted 7 lines · Christoph Hellwig
Hi Jens,
this series tries to move as much out of
genhd.hthat doesn't really belong there.Changes since v1:
- rebased to the latest block tree
Applied, thanks.
Signature · 1 line
Jens Axboe