aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/genhd.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/genhd.h')
-rw-r--r--include/linux/genhd.h25
1 files changed, 25 insertions, 0 deletions
diff --git a/include/linux/genhd.h b/include/linux/genhd.h
index 13893aa2ac9d..c0d5f6945c1e 100644
--- a/include/linux/genhd.h
+++ b/include/linux/genhd.h
@@ -115,6 +115,7 @@ struct hd_struct {
115#else 115#else
116 struct disk_stats dkstats; 116 struct disk_stats dkstats;
117#endif 117#endif
118 atomic_t ref;
118 struct rcu_head rcu_head; 119 struct rcu_head rcu_head;
119}; 120};
120 121
@@ -597,6 +598,7 @@ extern struct hd_struct * __must_check add_partition(struct gendisk *disk,
597 sector_t len, int flags, 598 sector_t len, int flags,
598 struct partition_meta_info 599 struct partition_meta_info
599 *info); 600 *info);
601extern void __delete_partition(struct hd_struct *);
600extern void delete_partition(struct gendisk *, int); 602extern void delete_partition(struct gendisk *, int);
601extern void printk_all_partitions(void); 603extern void printk_all_partitions(void);
602 604
@@ -625,6 +627,29 @@ extern ssize_t part_fail_store(struct device *dev,
625 const char *buf, size_t count); 627 const char *buf, size_t count);
626#endif /* CONFIG_FAIL_MAKE_REQUEST */ 628#endif /* CONFIG_FAIL_MAKE_REQUEST */
627 629
630static inline void hd_ref_init(struct hd_struct *part)
631{
632 atomic_set(&part->ref, 1);
633 smp_mb();
634}
635
636static inline void hd_struct_get(struct hd_struct *part)
637{
638 atomic_inc(&part->ref);
639 smp_mb__after_atomic_inc();
640}
641
642static inline int hd_struct_try_get(struct hd_struct *part)
643{
644 return atomic_inc_not_zero(&part->ref);
645}
646
647static inline void hd_struct_put(struct hd_struct *part)
648{
649 if (atomic_dec_and_test(&part->ref))
650 __delete_partition(part);
651}
652
628#else /* CONFIG_BLOCK */ 653#else /* CONFIG_BLOCK */
629 654
630static inline void printk_all_partitions(void) { } 655static inline void printk_all_partitions(void) { }