123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679 |
- #ifndef _MD_MD_H
- #define _MD_MD_H
- #include <linux/blkdev.h>
- #include <linux/backing-dev.h>
- #include <linux/badblocks.h>
- #include <linux/kobject.h>
- #include <linux/list.h>
- #include <linux/mm.h>
- #include <linux/mutex.h>
- #include <linux/timer.h>
- #include <linux/wait.h>
- #include <linux/workqueue.h>
- #include "md-cluster.h"
- #define MaxSector (~(sector_t)0)
- struct md_rdev {
- struct list_head same_set;
- sector_t sectors;
- struct mddev *mddev;
- int last_events;
-
- struct block_device *meta_bdev;
- struct block_device *bdev;
- struct page *sb_page, *bb_page;
- int sb_loaded;
- __u64 sb_events;
- sector_t data_offset;
- sector_t new_data_offset;
- sector_t sb_start;
- int sb_size;
- int preferred_minor;
- struct kobject kobj;
-
- unsigned long flags;
- wait_queue_head_t blocked_wait;
- int desc_nr;
- int raid_disk;
- int new_raid_disk;
- int saved_raid_disk;
- union {
- sector_t recovery_offset;
- sector_t journal_tail;
- };
- atomic_t nr_pending;
- atomic_t read_errors;
- time64_t last_read_error;
- atomic_t corrected_errors;
- struct work_struct del_work;
- struct kernfs_node *sysfs_state;
- struct badblocks badblocks;
- };
- enum flag_bits {
- Faulty,
- In_sync,
- Bitmap_sync,
- WriteMostly,
- AutoDetected,
- Blocked,
- WriteErrorSeen,
- FaultRecorded,
- BlockedBadBlocks,
- WantReplacement,
- Replacement,
- Candidate,
- Journal,
- ClusterRemove,
- RemoveSynchronized,
- };
- static inline int is_badblock(struct md_rdev *rdev, sector_t s, int sectors,
- sector_t *first_bad, int *bad_sectors)
- {
- if (unlikely(rdev->badblocks.count)) {
- int rv = badblocks_check(&rdev->badblocks, rdev->data_offset + s,
- sectors,
- first_bad, bad_sectors);
- if (rv)
- *first_bad -= rdev->data_offset;
- return rv;
- }
- return 0;
- }
- extern int rdev_set_badblocks(struct md_rdev *rdev, sector_t s, int sectors,
- int is_new);
- extern int rdev_clear_badblocks(struct md_rdev *rdev, sector_t s, int sectors,
- int is_new);
- struct md_cluster_info;
- struct mddev {
- void *private;
- struct md_personality *pers;
- dev_t unit;
- int md_minor;
- struct list_head disks;
- unsigned long flags;
- #define MD_CHANGE_DEVS 0
- #define MD_CHANGE_CLEAN 1
- #define MD_CHANGE_PENDING 2
- #define MD_UPDATE_SB_FLAGS (1 | 2 | 4)
- #define MD_ARRAY_FIRST_USE 3
- #define MD_CLOSING 4
- #define MD_JOURNAL_CLEAN 5
- #define MD_HAS_JOURNAL 6
- #define MD_RELOAD_SB 7
- #define MD_CLUSTER_RESYNC_LOCKED 8
- int suspended;
- atomic_t active_io;
- int ro;
- int sysfs_active;
- struct gendisk *gendisk;
- struct kobject kobj;
- int hold_active;
- #define UNTIL_IOCTL 1
- #define UNTIL_STOP 2
-
- int major_version,
- minor_version,
- patch_version;
- int persistent;
- int external;
- char metadata_type[17];
- int chunk_sectors;
- time64_t ctime, utime;
- int level, layout;
- char clevel[16];
- int raid_disks;
- int max_disks;
- sector_t dev_sectors;
- sector_t array_sectors;
- int external_size;
- __u64 events;
-
- int can_decrease_events;
- char uuid[16];
-
- sector_t reshape_position;
- int delta_disks, new_level, new_layout;
- int new_chunk_sectors;
- int reshape_backwards;
- struct md_thread *thread;
- struct md_thread *sync_thread;
-
- char *last_sync_action;
- sector_t curr_resync;
-
- sector_t curr_resync_completed;
- unsigned long resync_mark;
- sector_t resync_mark_cnt;
- sector_t curr_mark_cnt;
- sector_t resync_max_sectors;
- atomic64_t resync_mismatches;
-
- sector_t suspend_lo;
- sector_t suspend_hi;
-
- int sync_speed_min;
- int sync_speed_max;
-
- int parallel_resync;
- int ok_start_degraded;
-
- #define MD_RECOVERY_RUNNING 0
- #define MD_RECOVERY_SYNC 1
- #define MD_RECOVERY_RECOVER 2
- #define MD_RECOVERY_INTR 3
- #define MD_RECOVERY_DONE 4
- #define MD_RECOVERY_NEEDED 5
- #define MD_RECOVERY_REQUESTED 6
- #define MD_RECOVERY_CHECK 7
- #define MD_RECOVERY_RESHAPE 8
- #define MD_RECOVERY_FROZEN 9
- #define MD_RECOVERY_ERROR 10
- unsigned long recovery;
-
- int recovery_disabled;
- int in_sync;
-
- struct mutex open_mutex;
- struct mutex reconfig_mutex;
- atomic_t active;
- atomic_t openers;
- int changed;
- int degraded;
- atomic_t recovery_active;
- wait_queue_head_t recovery_wait;
- sector_t recovery_cp;
- sector_t resync_min;
- sector_t resync_max;
- struct kernfs_node *sysfs_state;
- struct kernfs_node *sysfs_action;
- struct work_struct del_work;
-
- spinlock_t lock;
- wait_queue_head_t sb_wait;
- atomic_t pending_writes;
- unsigned int safemode;
- unsigned int safemode_delay;
- struct timer_list safemode_timer;
- atomic_t writes_pending;
- struct request_queue *queue;
- struct bitmap *bitmap;
- struct {
- struct file *file;
- loff_t offset;
- unsigned long space;
- loff_t default_offset;
- unsigned long default_space;
- struct mutex mutex;
- unsigned long chunksize;
- unsigned long daemon_sleep;
- unsigned long max_write_behind;
- int external;
- int nodes;
- char cluster_name[64];
- } bitmap_info;
- atomic_t max_corr_read_errors;
- struct list_head all_mddevs;
- struct attribute_group *to_remove;
- struct bio_set *bio_set;
-
- struct bio *flush_bio;
- atomic_t flush_pending;
- struct work_struct flush_work;
- struct work_struct event_work;
- void (*sync_super)(struct mddev *mddev, struct md_rdev *rdev);
- struct md_cluster_info *cluster_info;
- unsigned int good_device_nr;
- };
- static inline int __must_check mddev_lock(struct mddev *mddev)
- {
- return mutex_lock_interruptible(&mddev->reconfig_mutex);
- }
- static inline void mddev_lock_nointr(struct mddev *mddev)
- {
- mutex_lock(&mddev->reconfig_mutex);
- }
- static inline int mddev_is_locked(struct mddev *mddev)
- {
- return mutex_is_locked(&mddev->reconfig_mutex);
- }
- static inline int mddev_trylock(struct mddev *mddev)
- {
- return mutex_trylock(&mddev->reconfig_mutex);
- }
- extern void mddev_unlock(struct mddev *mddev);
- static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
- {
- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
- }
- struct md_personality
- {
- char *name;
- int level;
- struct list_head list;
- struct module *owner;
- void (*make_request)(struct mddev *mddev, struct bio *bio);
- int (*run)(struct mddev *mddev);
- void (*free)(struct mddev *mddev, void *priv);
- void (*status)(struct seq_file *seq, struct mddev *mddev);
-
- void (*error_handler)(struct mddev *mddev, struct md_rdev *rdev);
- int (*hot_add_disk) (struct mddev *mddev, struct md_rdev *rdev);
- int (*hot_remove_disk) (struct mddev *mddev, struct md_rdev *rdev);
- int (*spare_active) (struct mddev *mddev);
- sector_t (*sync_request)(struct mddev *mddev, sector_t sector_nr, int *skipped);
- int (*resize) (struct mddev *mddev, sector_t sectors);
- sector_t (*size) (struct mddev *mddev, sector_t sectors, int raid_disks);
- int (*check_reshape) (struct mddev *mddev);
- int (*start_reshape) (struct mddev *mddev);
- void (*finish_reshape) (struct mddev *mddev);
-
- void (*quiesce) (struct mddev *mddev, int state);
-
- void *(*takeover) (struct mddev *mddev);
-
- int (*congested)(struct mddev *mddev, int bits);
- };
- struct md_sysfs_entry {
- struct attribute attr;
- ssize_t (*show)(struct mddev *, char *);
- ssize_t (*store)(struct mddev *, const char *, size_t);
- };
- extern struct attribute_group md_bitmap_group;
- static inline struct kernfs_node *sysfs_get_dirent_safe(struct kernfs_node *sd, char *name)
- {
- if (sd)
- return sysfs_get_dirent(sd, name);
- return sd;
- }
- static inline void sysfs_notify_dirent_safe(struct kernfs_node *sd)
- {
- if (sd)
- sysfs_notify_dirent(sd);
- }
- static inline char * mdname (struct mddev * mddev)
- {
- return mddev->gendisk ? mddev->gendisk->disk_name : "mdX";
- }
- static inline int sysfs_link_rdev(struct mddev *mddev, struct md_rdev *rdev)
- {
- char nm[20];
- if (!test_bit(Replacement, &rdev->flags) &&
- !test_bit(Journal, &rdev->flags) &&
- mddev->kobj.sd) {
- sprintf(nm, "rd%d", rdev->raid_disk);
- return sysfs_create_link(&mddev->kobj, &rdev->kobj, nm);
- } else
- return 0;
- }
- static inline void sysfs_unlink_rdev(struct mddev *mddev, struct md_rdev *rdev)
- {
- char nm[20];
- if (!test_bit(Replacement, &rdev->flags) &&
- !test_bit(Journal, &rdev->flags) &&
- mddev->kobj.sd) {
- sprintf(nm, "rd%d", rdev->raid_disk);
- sysfs_remove_link(&mddev->kobj, nm);
- }
- }
- #define rdev_for_each_list(rdev, tmp, head) \
- list_for_each_entry_safe(rdev, tmp, head, same_set)
- #define rdev_for_each(rdev, mddev) \
- list_for_each_entry(rdev, &((mddev)->disks), same_set)
- #define rdev_for_each_safe(rdev, tmp, mddev) \
- list_for_each_entry_safe(rdev, tmp, &((mddev)->disks), same_set)
- #define rdev_for_each_rcu(rdev, mddev) \
- list_for_each_entry_rcu(rdev, &((mddev)->disks), same_set)
- struct md_thread {
- void (*run) (struct md_thread *thread);
- struct mddev *mddev;
- wait_queue_head_t wqueue;
- unsigned long flags;
- struct task_struct *tsk;
- unsigned long timeout;
- void *private;
- };
- #define THREAD_WAKEUP 0
- static inline void safe_put_page(struct page *p)
- {
- if (p) put_page(p);
- }
- extern int register_md_personality(struct md_personality *p);
- extern int unregister_md_personality(struct md_personality *p);
- extern int register_md_cluster_operations(struct md_cluster_operations *ops,
- struct module *module);
- extern int unregister_md_cluster_operations(void);
- extern int md_setup_cluster(struct mddev *mddev, int nodes);
- extern void md_cluster_stop(struct mddev *mddev);
- extern struct md_thread *md_register_thread(
- void (*run)(struct md_thread *thread),
- struct mddev *mddev,
- const char *name);
- extern void md_unregister_thread(struct md_thread **threadp);
- extern void md_wakeup_thread(struct md_thread *thread);
- extern void md_check_recovery(struct mddev *mddev);
- extern void md_reap_sync_thread(struct mddev *mddev);
- extern void md_write_start(struct mddev *mddev, struct bio *bi);
- extern void md_write_end(struct mddev *mddev);
- extern void md_done_sync(struct mddev *mddev, int blocks, int ok);
- extern void md_error(struct mddev *mddev, struct md_rdev *rdev);
- extern void md_finish_reshape(struct mddev *mddev);
- extern int mddev_congested(struct mddev *mddev, int bits);
- extern void md_flush_request(struct mddev *mddev, struct bio *bio);
- extern void md_super_write(struct mddev *mddev, struct md_rdev *rdev,
- sector_t sector, int size, struct page *page);
- extern void md_super_wait(struct mddev *mddev);
- extern int sync_page_io(struct md_rdev *rdev, sector_t sector, int size,
- struct page *page, int op, int op_flags,
- bool metadata_op);
- extern void md_do_sync(struct md_thread *thread);
- extern void md_new_event(struct mddev *mddev);
- extern int md_allow_write(struct mddev *mddev);
- extern void md_wait_for_blocked_rdev(struct md_rdev *rdev, struct mddev *mddev);
- extern void md_set_array_sectors(struct mddev *mddev, sector_t array_sectors);
- extern int md_check_no_bitmap(struct mddev *mddev);
- extern int md_integrity_register(struct mddev *mddev);
- extern int md_integrity_add_rdev(struct md_rdev *rdev, struct mddev *mddev);
- extern int strict_strtoul_scaled(const char *cp, unsigned long *res, int scale);
- extern void mddev_init(struct mddev *mddev);
- extern int md_run(struct mddev *mddev);
- extern void md_stop(struct mddev *mddev);
- extern void md_stop_writes(struct mddev *mddev);
- extern int md_rdev_init(struct md_rdev *rdev);
- extern void md_rdev_clear(struct md_rdev *rdev);
- extern void mddev_suspend(struct mddev *mddev);
- extern void mddev_resume(struct mddev *mddev);
- extern struct bio *bio_clone_mddev(struct bio *bio, gfp_t gfp_mask,
- struct mddev *mddev);
- extern struct bio *bio_alloc_mddev(gfp_t gfp_mask, int nr_iovecs,
- struct mddev *mddev);
- extern void md_unplug(struct blk_plug_cb *cb, bool from_schedule);
- extern void md_reload_sb(struct mddev *mddev, int raid_disk);
- extern void md_update_sb(struct mddev *mddev, int force);
- extern void md_kick_rdev_from_array(struct md_rdev * rdev);
- struct md_rdev *md_find_rdev_nr_rcu(struct mddev *mddev, int nr);
- static inline int mddev_check_plugged(struct mddev *mddev)
- {
- return !!blk_check_plugged(md_unplug, mddev,
- sizeof(struct blk_plug_cb));
- }
- static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
- {
- int faulty = test_bit(Faulty, &rdev->flags);
- if (atomic_dec_and_test(&rdev->nr_pending) && faulty) {
- set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
- md_wakeup_thread(mddev->thread);
- }
- }
- extern struct md_cluster_operations *md_cluster_ops;
- static inline int mddev_is_clustered(struct mddev *mddev)
- {
- return mddev->cluster_info && mddev->bitmap_info.nodes > 1;
- }
- #endif
|