Skip to content

Commit 581e260

Browse files
Christoph Hellwigaxboe
authored andcommitted
block: move block layer internals out of include/linux/genhd.h
None of this needs to be exposed to drivers. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 29125ed commit 581e260

5 files changed

Lines changed: 118 additions & 121 deletions

File tree

‎block/blk.h‎

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ static inline bool integrity_req_gap_front_merge(struct request *req,
149149
return bvec_gap_to_prev(req->q, &bip->bip_vec[bip->bip_vcnt - 1],
150150
bip_next->bip_vec[0].bv_offset);
151151
}
152+
153+
void blk_integrity_add(struct gendisk *);
154+
void blk_integrity_del(struct gendisk *);
152155
#else /* CONFIG_BLK_DEV_INTEGRITY */
153156
static inline bool integrity_req_gap_back_merge(struct request *req,
154157
struct bio *next)
@@ -171,6 +174,12 @@ static inline bool bio_integrity_endio(struct bio *bio)
171174
static inline void bio_integrity_free(struct bio *bio)
172175
{
173176
}
177+
static inline void blk_integrity_add(struct gendisk *disk)
178+
{
179+
}
180+
static inline void blk_integrity_del(struct gendisk *disk)
181+
{
182+
}
174183
#endif /* CONFIG_BLK_DEV_INTEGRITY */
175184

176185
unsigned long blk_rq_timeout(unsigned long timeout);
@@ -365,4 +374,111 @@ void blk_queue_free_zone_bitmaps(struct request_queue *q);
365374
static inline void blk_queue_free_zone_bitmaps(struct request_queue *q) {}
366375
#endif
367376

377+
void part_dec_in_flight(struct request_queue *q, struct hd_struct *part,
378+
int rw);
379+
void part_inc_in_flight(struct request_queue *q, struct hd_struct *part,
380+
int rw);
381+
void update_io_ticks(struct hd_struct *part, unsigned long now, bool end);
382+
struct hd_struct *disk_map_sector_rcu(struct gendisk *disk, sector_t sector);
383+
384+
int blk_alloc_devt(struct hd_struct *part, dev_t *devt);
385+
void blk_free_devt(dev_t devt);
386+
void blk_invalidate_devt(dev_t devt);
387+
char *disk_name(struct gendisk *hd, int partno, char *buf);
388+
#define ADDPART_FLAG_NONE 0
389+
#define ADDPART_FLAG_RAID 1
390+
#define ADDPART_FLAG_WHOLEDISK 2
391+
struct hd_struct *__must_check add_partition(struct gendisk *disk, int partno,
392+
sector_t start, sector_t len, int flags,
393+
struct partition_meta_info *info);
394+
void __delete_partition(struct percpu_ref *ref);
395+
void delete_partition(struct gendisk *disk, int partno);
396+
int disk_expand_part_tbl(struct gendisk *disk, int target);
397+
398+
static inline int hd_ref_init(struct hd_struct *part)
399+
{
400+
if (percpu_ref_init(&part->ref, __delete_partition, 0,
401+
GFP_KERNEL))
402+
return -ENOMEM;
403+
return 0;
404+
}
405+
406+
static inline void hd_struct_get(struct hd_struct *part)
407+
{
408+
percpu_ref_get(&part->ref);
409+
}
410+
411+
static inline int hd_struct_try_get(struct hd_struct *part)
412+
{
413+
return percpu_ref_tryget_live(&part->ref);
414+
}
415+
416+
static inline void hd_struct_put(struct hd_struct *part)
417+
{
418+
percpu_ref_put(&part->ref);
419+
}
420+
421+
static inline void hd_struct_kill(struct hd_struct *part)
422+
{
423+
percpu_ref_kill(&part->ref);
424+
}
425+
426+
static inline void hd_free_part(struct hd_struct *part)
427+
{
428+
free_part_stats(part);
429+
kfree(part->info);
430+
percpu_ref_exit(&part->ref);
431+
}
432+
433+
/*
434+
* Any access of part->nr_sects which is not protected by partition
435+
* bd_mutex or gendisk bdev bd_mutex, should be done using this
436+
* accessor function.
437+
*
438+
* Code written along the lines of i_size_read() and i_size_write().
439+
* CONFIG_PREEMPTION case optimizes the case of UP kernel with preemption
440+
* on.
441+
*/
442+
static inline sector_t part_nr_sects_read(struct hd_struct *part)
443+
{
444+
#if BITS_PER_LONG==32 && defined(CONFIG_SMP)
445+
sector_t nr_sects;
446+
unsigned seq;
447+
do {
448+
seq = read_seqcount_begin(&part->nr_sects_seq);
449+
nr_sects = part->nr_sects;
450+
} while (read_seqcount_retry(&part->nr_sects_seq, seq));
451+
return nr_sects;
452+
#elif BITS_PER_LONG==32 && defined(CONFIG_PREEMPTION)
453+
sector_t nr_sects;
454+
455+
preempt_disable();
456+
nr_sects = part->nr_sects;
457+
preempt_enable();
458+
return nr_sects;
459+
#else
460+
return part->nr_sects;
461+
#endif
462+
}
463+
464+
/*
465+
* Should be called with mutex lock held (typically bd_mutex) of partition
466+
* to provide mutual exlusion among writers otherwise seqcount might be
467+
* left in wrong state leaving the readers spinning infinitely.
468+
*/
469+
static inline void part_nr_sects_write(struct hd_struct *part, sector_t size)
470+
{
471+
#if BITS_PER_LONG==32 && defined(CONFIG_SMP)
472+
write_seqcount_begin(&part->nr_sects_seq);
473+
part->nr_sects = size;
474+
write_seqcount_end(&part->nr_sects_seq);
475+
#elif BITS_PER_LONG==32 && defined(CONFIG_PREEMPTION)
476+
preempt_disable();
477+
part->nr_sects = size;
478+
preempt_enable();
479+
#else
480+
part->nr_sects = size;
481+
#endif
482+
}
483+
368484
#endif /* BLK_INTERNAL_H */

‎block/ioctl.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <linux/blktrace_api.h>
1212
#include <linux/pr.h>
1313
#include <linux/uaccess.h>
14+
#include "blk.h"
1415

1516
static int blkpg_do_ioctl(struct block_device *bdev,
1617
struct blkpg_partition __user *upart, int op)

‎block/partitions/check.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <linux/pagemap.h>
33
#include <linux/blkdev.h>
44
#include <linux/genhd.h>
5+
#include "../blk.h"
56

67
/*
78
* add_gd_partition adds a partitions details to the devices partition

‎block/partitions/core.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include <linux/vmalloc.h>
1111
#include <linux/blktrace_api.h>
1212
#include <linux/raid/detect.h>
13-
#include "../blk.h"
1413
#include "check.h"
1514

1615
static int (*check_part[])(struct parsed_partitions *) = {

‎include/linux/genhd.h‎

Lines changed: 0 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -298,9 +298,6 @@ extern void disk_part_iter_init(struct disk_part_iter *piter,
298298
extern struct hd_struct *disk_part_iter_next(struct disk_part_iter *piter);
299299
extern void disk_part_iter_exit(struct disk_part_iter *piter);
300300

301-
extern struct hd_struct *disk_map_sector_rcu(struct gendisk *disk,
302-
sector_t sector);
303-
304301
/*
305302
* Macros to operate on percpu disk statistics:
306303
*
@@ -409,13 +406,6 @@ static inline void free_part_stats(struct hd_struct *part)
409406
#define part_stat_local_read_cpu(gendiskp, field, cpu) \
410407
local_read(&(part_stat_get_cpu(gendiskp, field, cpu)))
411408

412-
void part_dec_in_flight(struct request_queue *q, struct hd_struct *part,
413-
int rw);
414-
void part_inc_in_flight(struct request_queue *q, struct hd_struct *part,
415-
int rw);
416-
417-
void update_io_ticks(struct hd_struct *part, unsigned long now, bool end);
418-
419409
/* block/genhd.c */
420410
extern void device_add_disk(struct device *parent, struct gendisk *disk,
421411
const struct attribute_group **groups);
@@ -465,27 +455,11 @@ static inline void set_capacity(struct gendisk *disk, sector_t size)
465455
disk->part0.nr_sects = size;
466456
}
467457

468-
#define ADDPART_FLAG_NONE 0
469-
#define ADDPART_FLAG_RAID 1
470-
#define ADDPART_FLAG_WHOLEDISK 2
471-
472-
extern int blk_alloc_devt(struct hd_struct *part, dev_t *devt);
473-
extern void blk_free_devt(dev_t devt);
474-
extern void blk_invalidate_devt(dev_t devt);
475458
extern dev_t blk_lookup_devt(const char *name, int partno);
476-
extern char *disk_name (struct gendisk *hd, int partno, char *buf);
477459

478460
int bdev_disk_changed(struct block_device *bdev, bool invalidate);
479461
int blk_add_partitions(struct gendisk *disk, struct block_device *bdev);
480462
int blk_drop_partitions(struct gendisk *disk, struct block_device *bdev);
481-
extern int disk_expand_part_tbl(struct gendisk *disk, int target);
482-
extern struct hd_struct * __must_check add_partition(struct gendisk *disk,
483-
int partno, sector_t start,
484-
sector_t len, int flags,
485-
struct partition_meta_info
486-
*info);
487-
extern void __delete_partition(struct percpu_ref *);
488-
extern void delete_partition(struct gendisk *, int);
489463
extern void printk_all_partitions(void);
490464

491465
extern struct gendisk *__alloc_disk_node(int minors, int node_id);
@@ -517,100 +491,6 @@ extern void blk_unregister_region(dev_t devt, unsigned long range);
517491

518492
#define alloc_disk(minors) alloc_disk_node(minors, NUMA_NO_NODE)
519493

520-
static inline int hd_ref_init(struct hd_struct *part)
521-
{
522-
if (percpu_ref_init(&part->ref, __delete_partition, 0,
523-
GFP_KERNEL))
524-
return -ENOMEM;
525-
return 0;
526-
}
527-
528-
static inline void hd_struct_get(struct hd_struct *part)
529-
{
530-
percpu_ref_get(&part->ref);
531-
}
532-
533-
static inline int hd_struct_try_get(struct hd_struct *part)
534-
{
535-
return percpu_ref_tryget_live(&part->ref);
536-
}
537-
538-
static inline void hd_struct_put(struct hd_struct *part)
539-
{
540-
percpu_ref_put(&part->ref);
541-
}
542-
543-
static inline void hd_struct_kill(struct hd_struct *part)
544-
{
545-
percpu_ref_kill(&part->ref);
546-
}
547-
548-
static inline void hd_free_part(struct hd_struct *part)
549-
{
550-
free_part_stats(part);
551-
kfree(part->info);
552-
percpu_ref_exit(&part->ref);
553-
}
554-
555-
/*
556-
* Any access of part->nr_sects which is not protected by partition
557-
* bd_mutex or gendisk bdev bd_mutex, should be done using this
558-
* accessor function.
559-
*
560-
* Code written along the lines of i_size_read() and i_size_write().
561-
* CONFIG_PREEMPTION case optimizes the case of UP kernel with preemption
562-
* on.
563-
*/
564-
static inline sector_t part_nr_sects_read(struct hd_struct *part)
565-
{
566-
#if BITS_PER_LONG==32 && defined(CONFIG_SMP)
567-
sector_t nr_sects;
568-
unsigned seq;
569-
do {
570-
seq = read_seqcount_begin(&part->nr_sects_seq);
571-
nr_sects = part->nr_sects;
572-
} while (read_seqcount_retry(&part->nr_sects_seq, seq));
573-
return nr_sects;
574-
#elif BITS_PER_LONG==32 && defined(CONFIG_PREEMPTION)
575-
sector_t nr_sects;
576-
577-
preempt_disable();
578-
nr_sects = part->nr_sects;
579-
preempt_enable();
580-
return nr_sects;
581-
#else
582-
return part->nr_sects;
583-
#endif
584-
}
585-
586-
/*
587-
* Should be called with mutex lock held (typically bd_mutex) of partition
588-
* to provide mutual exlusion among writers otherwise seqcount might be
589-
* left in wrong state leaving the readers spinning infinitely.
590-
*/
591-
static inline void part_nr_sects_write(struct hd_struct *part, sector_t size)
592-
{
593-
#if BITS_PER_LONG==32 && defined(CONFIG_SMP)
594-
write_seqcount_begin(&part->nr_sects_seq);
595-
part->nr_sects = size;
596-
write_seqcount_end(&part->nr_sects_seq);
597-
#elif BITS_PER_LONG==32 && defined(CONFIG_PREEMPTION)
598-
preempt_disable();
599-
part->nr_sects = size;
600-
preempt_enable();
601-
#else
602-
part->nr_sects = size;
603-
#endif
604-
}
605-
606-
#if defined(CONFIG_BLK_DEV_INTEGRITY)
607-
extern void blk_integrity_add(struct gendisk *);
608-
extern void blk_integrity_del(struct gendisk *);
609-
#else /* CONFIG_BLK_DEV_INTEGRITY */
610-
static inline void blk_integrity_add(struct gendisk *disk) { }
611-
static inline void blk_integrity_del(struct gendisk *disk) { }
612-
#endif /* CONFIG_BLK_DEV_INTEGRITY */
613-
614494
#else /* CONFIG_BLOCK */
615495

616496
static inline void printk_all_partitions(void) { }

0 commit comments

Comments
 (0)