linux/drivers/md/md.c

// SPDX-License-Identifier: GPL-2.0-or-later
/*
   md.c : Multiple Devices driver for Linux
     Copyright (C) 1998, 1999, 2000 Ingo Molnar

     completely rewritten, based on the MD driver code from Marc Zyngier

   Changes:

   - RAID-1/RAID-5 extensions by Miguel de Icaza, Gadi Oxman, Ingo Molnar
   - RAID-6 extensions by H. Peter Anvin <[email protected]>
   - boot support for linear and striped mode by Harald Hoyer <[email protected]>
   - kerneld support by Boris Tobotras <[email protected]>
   - kmod support by: Cyrus Durgin
   - RAID0 bugfixes: Mark Anthony Lisher <[email protected]>
   - Devfs support by Richard Gooch <[email protected]>

   - lots of fixes and improvements to the RAID1/RAID5 and generic
     RAID code (such as request based resynchronization):

     Neil Brown <[email protected]>.

   - persistent bitmap code
     Copyright (C) 2003-2004, Paul Clements, SteelEye Technology, Inc.


   Errors, Warnings, etc.
   Please use:
     pr_crit() for error conditions that risk data loss
     pr_err() for error conditions that are unexpected, like an IO error
         or internal inconsistency
     pr_warn() for error conditions that could have been predicated, like
         adding a device to an array when it has incompatible metadata
     pr_info() for every interesting, very rare events, like an array starting
         or stopping, or resync starting or stopping
     pr_debug() for everything else.

*/

#include <linux/sched/mm.h>
#include <linux/sched/signal.h>
#include <linux/kthread.h>
#include <linux/blkdev.h>
#include <linux/blk-integrity.h>
#include <linux/badblocks.h>
#include <linux/sysctl.h>
#include <linux/seq_file.h>
#include <linux/fs.h>
#include <linux/poll.h>
#include <linux/ctype.h>
#include <linux/string.h>
#include <linux/hdreg.h>
#include <linux/proc_fs.h>
#include <linux/random.h>
#include <linux/major.h>
#include <linux/module.h>
#include <linux/reboot.h>
#include <linux/file.h>
#include <linux/compat.h>
#include <linux/delay.h>
#include <linux/raid/md_p.h>
#include <linux/raid/md_u.h>
#include <linux/raid/detect.h>
#include <linux/slab.h>
#include <linux/percpu-refcount.h>
#include <linux/part_stat.h>

#include "md.h"
#include "md-bitmap.h"
#include "md-cluster.h"

static const char *action_name[NR_SYNC_ACTIONS] =;

/* pers_list is a list of registered personalities protected by pers_lock. */
static LIST_HEAD(pers_list);
static DEFINE_SPINLOCK(pers_lock);

static const struct kobj_type md_ktype;

const struct md_cluster_operations *md_cluster_ops;
EXPORT_SYMBOL();
static struct module *md_cluster_mod;

static DECLARE_WAIT_QUEUE_HEAD(resync_wait);
static struct workqueue_struct *md_wq;

/*
 * This workqueue is used for sync_work to register new sync_thread, and for
 * del_work to remove rdev, and for event_work that is only set by dm-raid.
 *
 * Noted that sync_work will grab reconfig_mutex, hence never flush this
 * workqueue whith reconfig_mutex grabbed.
 */
static struct workqueue_struct *md_misc_wq;
struct workqueue_struct *md_bitmap_wq;

static int remove_and_add_spares(struct mddev *mddev,
				 struct md_rdev *this);
static void mddev_detach(struct mddev *mddev);
static void export_rdev(struct md_rdev *rdev, struct mddev *mddev);
static void md_wakeup_thread_directly(struct md_thread __rcu *thread);

/*
 * Default number of read corrections we'll attempt on an rdev
 * before ejecting it from the array. We divide the read error
 * count by 2 for every hour elapsed between read errors.
 */
#define MD_DEFAULT_MAX_CORRECTED_READ_ERRORS
/* Default safemode delay: 200 msec */
#define DEFAULT_SAFEMODE_DELAY
/*
 * Current RAID-1,4,5 parallel reconstruction 'guaranteed speed limit'
 * is 1000 KB/sec, so the extra system load does not show up that much.
 * Increase it if you want to have more _guaranteed_ speed. Note that
 * the RAID driver will use the maximum available bandwidth if the IO
 * subsystem is idle. There is also an 'absolute maximum' reconstruction
 * speed limit - in case reconstruction slows down your system despite
 * idle IO detection.
 *
 * you can change it via /proc/sys/dev/raid/speed_limit_min and _max.
 * or /sys/block/mdX/md/sync_speed_{min,max}
 */

static int sysctl_speed_limit_min =;
static int sysctl_speed_limit_max =;
static inline int speed_min(struct mddev *mddev)
{}

static inline int speed_max(struct mddev *mddev)
{}

static void rdev_uninit_serial(struct md_rdev *rdev)
{}

static void rdevs_uninit_serial(struct mddev *mddev)
{}

static int rdev_init_serial(struct md_rdev *rdev)
{}

static int rdevs_init_serial(struct mddev *mddev)
{}

/*
 * rdev needs to enable serial stuffs if it meets the conditions:
 * 1. it is multi-queue device flaged with writemostly.
 * 2. the write-behind mode is enabled.
 */
static int rdev_need_serial(struct md_rdev *rdev)
{}

/*
 * Init resource for rdev(s), then create serial_info_pool if:
 * 1. rdev is the first device which return true from rdev_enable_serial.
 * 2. rdev is NULL, means we want to enable serialization for all rdevs.
 */
void mddev_create_serial_pool(struct mddev *mddev, struct md_rdev *rdev)
{}

/*
 * Free resource from rdev(s), and destroy serial_info_pool under conditions:
 * 1. rdev is the last device flaged with CollisionCheck.
 * 2. when bitmap is destroyed while policy is not enabled.
 * 3. for disable policy, the pool is destroyed only when no rdev needs it.
 */
void mddev_destroy_serial_pool(struct mddev *mddev, struct md_rdev *rdev)
{}

static struct ctl_table_header *raid_table_header;

static struct ctl_table raid_table[] =;

static int start_readonly;

/*
 * The original mechanism for creating an md device is to create
 * a device node in /dev and to open it.  This causes races with device-close.
 * The preferred method is to write to the "new_array" module parameter.
 * This can avoid races.
 * Setting create_on_open to false disables the original mechanism
 * so all the races disappear.
 */
static bool create_on_open =;

/*
 * We have a system wide 'event count' that is incremented
 * on any 'interesting' event, and readers of /proc/mdstat
 * can use 'poll' or 'select' to find out when the event
 * count increases.
 *
 * Events are:
 *  start array, stop array, error, add device, remove device,
 *  start build, activate spare
 */
static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
static atomic_t md_event_count;
void md_new_event(void)
{}
EXPORT_SYMBOL_GPL();

/*
 * Enables to iterate over all existing md arrays
 * all_mddevs_lock protects this list.
 */
static LIST_HEAD(all_mddevs);
static DEFINE_SPINLOCK(all_mddevs_lock);

static bool is_md_suspended(struct mddev *mddev)
{}
/* Rather than calling directly into the personality make_request function,
 * IO requests come here first so that we can check if the device is
 * being suspended pending a reconfiguration.
 * We hold a refcount over the call to ->make_request.  By the time that
 * call has finished, the bio has been linked into some internal structure
 * and so is visible to ->quiesce(), so we don't need the refcount any more.
 */
static bool is_suspended(struct mddev *mddev, struct bio *bio)
{}

bool md_handle_request(struct mddev *mddev, struct bio *bio)
{}
EXPORT_SYMBOL();

static void md_submit_bio(struct bio *bio)
{}

/*
 * Make sure no new requests are submitted to the device, and any requests that
 * have been submitted are completely handled.
 */
int mddev_suspend(struct mddev *mddev, bool interruptible)
{}
EXPORT_SYMBOL_GPL();

static void __mddev_resume(struct mddev *mddev, bool recovery_needed)
{}

void mddev_resume(struct mddev *mddev)
{}
EXPORT_SYMBOL_GPL();

/* sync bdev before setting device to readonly or stopping raid*/
static int mddev_set_closing_and_sync_blockdev(struct mddev *mddev, int opener_num)
{}

/*
 * Generic flush handling for md
 */

static void md_end_flush(struct bio *bio)
{}

static void md_submit_flush_data(struct work_struct *ws);

static void submit_flushes(struct work_struct *ws)
{}

static void md_submit_flush_data(struct work_struct *ws)
{}

/*
 * Manages consolidation of flushes and submitting any flushes needed for
 * a bio with REQ_PREFLUSH.  Returns true if the bio is finished or is
 * being finished in another context.  Returns false if the flushing is
 * complete but still needs the I/O portion of the bio to be processed.
 */
bool md_flush_request(struct mddev *mddev, struct bio *bio)
{}
EXPORT_SYMBOL();

static inline struct mddev *mddev_get(struct mddev *mddev)
{}

static void mddev_delayed_delete(struct work_struct *ws);

static void __mddev_put(struct mddev *mddev)
{}

void mddev_put(struct mddev *mddev)
{}

static void md_safemode_timeout(struct timer_list *t);
static void md_start_sync(struct work_struct *ws);

static void active_io_release(struct percpu_ref *ref)
{}

static void no_op(struct percpu_ref *r) {}

int mddev_init(struct mddev *mddev)
{}
EXPORT_SYMBOL_GPL();

void mddev_destroy(struct mddev *mddev)
{}
EXPORT_SYMBOL_GPL();

static struct mddev *mddev_find_locked(dev_t unit)
{}

/* find an unused unit number */
static dev_t mddev_alloc_unit(void)
{}

static struct mddev *mddev_alloc(dev_t unit)
{}

static void mddev_free(struct mddev *mddev)
{}

static const struct attribute_group md_redundancy_group;

void mddev_unlock(struct mddev *mddev)
{}
EXPORT_SYMBOL_GPL();

struct md_rdev *md_find_rdev_nr_rcu(struct mddev *mddev, int nr)
{}
EXPORT_SYMBOL_GPL();

static struct md_rdev *find_rdev(struct mddev *mddev, dev_t dev)
{}

struct md_rdev *md_find_rdev_rcu(struct mddev *mddev, dev_t dev)
{}
EXPORT_SYMBOL_GPL();

static struct md_personality *find_pers(int level, char *clevel)
{}

/* return the offset of the super block in 512byte sectors */
static inline sector_t calc_dev_sboffset(struct md_rdev *rdev)
{}

static int alloc_disk_sb(struct md_rdev *rdev)
{}

void md_rdev_clear(struct md_rdev *rdev)
{}
EXPORT_SYMBOL_GPL();

static void super_written(struct bio *bio)
{}

void md_super_write(struct mddev *mddev, struct md_rdev *rdev,
		   sector_t sector, int size, struct page *page)
{}

int md_super_wait(struct mddev *mddev)
{}

int sync_page_io(struct md_rdev *rdev, sector_t sector, int size,
		 struct page *page, blk_opf_t opf, bool metadata_op)
{}
EXPORT_SYMBOL_GPL();

static int read_disk_sb(struct md_rdev *rdev, int size)
{}

static int md_uuid_equal(mdp_super_t *sb1, mdp_super_t *sb2)
{}

static int md_sb_equal(mdp_super_t *sb1, mdp_super_t *sb2)
{}

static u32 md_csum_fold(u32 csum)
{}

static unsigned int calc_sb_csum(mdp_super_t *sb)
{}

/*
 * Handle superblock details.
 * We want to be able to handle multiple superblock formats
 * so we have a common interface to them all, and an array of
 * different handlers.
 * We rely on user-space to write the initial superblock, and support
 * reading and updating of superblocks.
 * Interface methods are:
 *   int load_super(struct md_rdev *dev, struct md_rdev *refdev, int minor_version)
 *      loads and validates a superblock on dev.
 *      if refdev != NULL, compare superblocks on both devices
 *    Return:
 *      0 - dev has a superblock that is compatible with refdev
 *      1 - dev has a superblock that is compatible and newer than refdev
 *          so dev should be used as the refdev in future
 *     -EINVAL superblock incompatible or invalid
 *     -othererror e.g. -EIO
 *
 *   int validate_super(struct mddev *mddev, struct md_rdev *dev)
 *      Verify that dev is acceptable into mddev.
 *       The first time, mddev->raid_disks will be 0, and data from
 *       dev should be merged in.  Subsequent calls check that dev
 *       is new enough.  Return 0 or -EINVAL
 *
 *   void sync_super(struct mddev *mddev, struct md_rdev *dev)
 *     Update the superblock for rdev with data in mddev
 *     This does not write to disc.
 *
 */

struct super_type  {};

/*
 * Check that the given mddev has no bitmap.
 *
 * This function is called from the run method of all personalities that do not
 * support bitmaps. It prints an error message and returns non-zero if mddev
 * has a bitmap. Otherwise, it returns 0.
 *
 */
int md_check_no_bitmap(struct mddev *mddev)
{}
EXPORT_SYMBOL();

/*
 * load_super for 0.90.0
 */
static int super_90_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_version)
{}

/*
 * validate_super for 0.90.0
 * note: we are not using "freshest" for 0.9 superblock
 */
static int super_90_validate(struct mddev *mddev, struct md_rdev *freshest, struct md_rdev *rdev)
{}

/*
 * sync_super for 0.90.0
 */
static void super_90_sync(struct mddev *mddev, struct md_rdev *rdev)
{}

/*
 * rdev_size_change for 0.90.0
 */
static unsigned long long
super_90_rdev_size_change(struct md_rdev *rdev, sector_t num_sectors)
{}

static int
super_90_allow_new_offset(struct md_rdev *rdev, unsigned long long new_offset)
{}

/*
 * version 1 superblock
 */

static __le32 calc_sb_1_csum(struct mdp_superblock_1 *sb)
{}

static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_version)
{}

static int super_1_validate(struct mddev *mddev, struct md_rdev *freshest, struct md_rdev *rdev)
{}

static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
{}

static sector_t super_1_choose_bm_space(sector_t dev_size)
{}

static unsigned long long
super_1_rdev_size_change(struct md_rdev *rdev, sector_t num_sectors)
{}

static int
super_1_allow_new_offset(struct md_rdev *rdev,
			 unsigned long long new_offset)
{}

static struct super_type super_types[] =;

static void sync_super(struct mddev *mddev, struct md_rdev *rdev)
{}

static int match_mddev_units(struct mddev *mddev1, struct mddev *mddev2)
{}

static LIST_HEAD(pending_raid_disks);

/*
 * Try to register data integrity profile for an mddev
 *
 * This is called when an array is started and after a disk has been kicked
 * from the array. It only succeeds if all working and active component devices
 * are integrity capable with matching profiles.
 */
int md_integrity_register(struct mddev *mddev)
{}
EXPORT_SYMBOL();

static bool rdev_read_only(struct md_rdev *rdev)
{}

static int bind_rdev_to_array(struct md_rdev *rdev, struct mddev *mddev)
{}

void md_autodetect_dev(dev_t dev);

/* just for claiming the bdev */
static struct md_rdev claim_rdev;

static void export_rdev(struct md_rdev *rdev, struct mddev *mddev)
{}

static void md_kick_rdev_from_array(struct md_rdev *rdev)
{}

static void export_array(struct mddev *mddev)
{}

static bool set_in_sync(struct mddev *mddev)
{}

static void sync_sbs(struct mddev *mddev, int nospares)
{}

static bool does_sb_need_changing(struct mddev *mddev)
{}

void md_update_sb(struct mddev *mddev, int force_change)
{}
EXPORT_SYMBOL();

static int add_bound_rdev(struct md_rdev *rdev)
{}

/* words written to sysfs files may, or may not, be \n terminated.
 * We want to accept with case. For this we use cmd_match.
 */
static int cmd_match(const char *cmd, const char *str)
{}

struct rdev_sysfs_entry {};

static ssize_t
state_show(struct md_rdev *rdev, char *page)
{}

static ssize_t
state_store(struct md_rdev *rdev, const char *buf, size_t len)
{}
static struct rdev_sysfs_entry rdev_state =;

static ssize_t
errors_show(struct md_rdev *rdev, char *page)
{}

static ssize_t
errors_store(struct md_rdev *rdev, const char *buf, size_t len)
{}
static struct rdev_sysfs_entry rdev_errors =;

static ssize_t
slot_show(struct md_rdev *rdev, char *page)
{}

static ssize_t
slot_store(struct md_rdev *rdev, const char *buf, size_t len)
{}

static struct rdev_sysfs_entry rdev_slot =;

static ssize_t
offset_show(struct md_rdev *rdev, char *page)
{}

static ssize_t
offset_store(struct md_rdev *rdev, const char *buf, size_t len)
{}

static struct rdev_sysfs_entry rdev_offset =;

static ssize_t new_offset_show(struct md_rdev *rdev, char *page)
{}

static ssize_t new_offset_store(struct md_rdev *rdev,
				const char *buf, size_t len)
{}
static struct rdev_sysfs_entry rdev_new_offset =;

static ssize_t
rdev_size_show(struct md_rdev *rdev, char *page)
{}

static int md_rdevs_overlap(struct md_rdev *a, struct md_rdev *b)
{}

static bool md_rdev_overlaps(struct md_rdev *rdev)
{}

static int strict_blocks_to_sectors(const char *buf, sector_t *sectors)
{}

static ssize_t
rdev_size_store(struct md_rdev *rdev, const char *buf, size_t len)
{}

static struct rdev_sysfs_entry rdev_size =;

static ssize_t recovery_start_show(struct md_rdev *rdev, char *page)
{}

static ssize_t recovery_start_store(struct md_rdev *rdev, const char *buf, size_t len)
{}

static struct rdev_sysfs_entry rdev_recovery_start =;

/* sysfs access to bad-blocks list.
 * We present two files.
 * 'bad-blocks' lists sector numbers and lengths of ranges that
 *    are recorded as bad.  The list is truncated to fit within
 *    the one-page limit of sysfs.
 *    Writing "sector length" to this file adds an acknowledged
 *    bad block list.
 * 'unacknowledged-bad-blocks' lists bad blocks that have not yet
 *    been acknowledged.  Writing to this file adds bad blocks
 *    without acknowledging them.  This is largely for testing.
 */
static ssize_t bb_show(struct md_rdev *rdev, char *page)
{}
static ssize_t bb_store(struct md_rdev *rdev, const char *page, size_t len)
{}
static struct rdev_sysfs_entry rdev_bad_blocks =;

static ssize_t ubb_show(struct md_rdev *rdev, char *page)
{}
static ssize_t ubb_store(struct md_rdev *rdev, const char *page, size_t len)
{}
static struct rdev_sysfs_entry rdev_unack_bad_blocks =;

static ssize_t
ppl_sector_show(struct md_rdev *rdev, char *page)
{}

static ssize_t
ppl_sector_store(struct md_rdev *rdev, const char *buf, size_t len)
{}

static struct rdev_sysfs_entry rdev_ppl_sector =;

static ssize_t
ppl_size_show(struct md_rdev *rdev, char *page)
{}

static ssize_t
ppl_size_store(struct md_rdev *rdev, const char *buf, size_t len)
{}

static struct rdev_sysfs_entry rdev_ppl_size =;

static struct attribute *rdev_default_attrs[] =;
ATTRIBUTE_GROUPS();
static ssize_t
rdev_attr_show(struct kobject *kobj, struct attribute *attr, char *page)
{}

static ssize_t
rdev_attr_store(struct kobject *kobj, struct attribute *attr,
	      const char *page, size_t length)
{}

static void rdev_free(struct kobject *ko)
{}
static const struct sysfs_ops rdev_sysfs_ops =;
static const struct kobj_type rdev_ktype =;

int md_rdev_init(struct md_rdev *rdev)
{}
EXPORT_SYMBOL_GPL();

/*
 * Import a device. If 'super_format' >= 0, then sanity check the superblock
 *
 * mark the device faulty if:
 *
 *   - the device is nonexistent (zero size)
 *   - the device has no valid superblock
 *
 * a faulty rdev _never_ has rdev->sb set.
 */
static struct md_rdev *md_import_device(dev_t newdev, int super_format, int super_minor)
{}

/*
 * Check a full RAID array for plausibility
 */

static int analyze_sbs(struct mddev *mddev)
{}

/* Read a fixed-point number.
 * Numbers in sysfs attributes should be in "standard" units where
 * possible, so time should be in seconds.
 * However we internally use a a much smaller unit such as
 * milliseconds or jiffies.
 * This function takes a decimal number with a possible fractional
 * component, and produces an integer which is the result of
 * multiplying that number by 10^'scale'.
 * all without any floating-point arithmetic.
 */
int strict_strtoul_scaled(const char *cp, unsigned long *res, int scale)
{}

static ssize_t
safe_delay_show(struct mddev *mddev, char *page)
{}
static ssize_t
safe_delay_store(struct mddev *mddev, const char *cbuf, size_t len)
{}
static struct md_sysfs_entry md_safe_delay =;

static ssize_t
level_show(struct mddev *mddev, char *page)
{}

static ssize_t
level_store(struct mddev *mddev, const char *buf, size_t len)
{}

static struct md_sysfs_entry md_level =;

static ssize_t
layout_show(struct mddev *mddev, char *page)
{}

static ssize_t
layout_store(struct mddev *mddev, const char *buf, size_t len)
{}
static struct md_sysfs_entry md_layout =;

static ssize_t
raid_disks_show(struct mddev *mddev, char *page)
{}

static int update_raid_disks(struct mddev *mddev, int raid_disks);

static ssize_t
raid_disks_store(struct mddev *mddev, const char *buf, size_t len)
{}
static struct md_sysfs_entry md_raid_disks =;

static ssize_t
uuid_show(struct mddev *mddev, char *page)
{}
static struct md_sysfs_entry md_uuid =;

static ssize_t
chunk_size_show(struct mddev *mddev, char *page)
{}

static ssize_t
chunk_size_store(struct mddev *mddev, const char *buf, size_t len)
{}
static struct md_sysfs_entry md_chunk_size =;

static ssize_t
resync_start_show(struct mddev *mddev, char *page)
{}

static ssize_t
resync_start_store(struct mddev *mddev, const char *buf, size_t len)
{}
static struct md_sysfs_entry md_resync_start =;

/*
 * The array state can be:
 *
 * clear
 *     No devices, no size, no level
 *     Equivalent to STOP_ARRAY ioctl
 * inactive
 *     May have some settings, but array is not active
 *        all IO results in error
 *     When written, doesn't tear down array, but just stops it
 * suspended (not supported yet)
 *     All IO requests will block. The array can be reconfigured.
 *     Writing this, if accepted, will block until array is quiescent
 * readonly
 *     no resync can happen.  no superblocks get written.
 *     write requests fail
 * read-auto
 *     like readonly, but behaves like 'clean' on a write request.
 *
 * clean - no pending writes, but otherwise active.
 *     When written to inactive array, starts without resync
 *     If a write request arrives then
 *       if metadata is known, mark 'dirty' and switch to 'active'.
 *       if not known, block and switch to write-pending
 *     If written to an active array that has pending writes, then fails.
 * active
 *     fully active: IO and resync can be happening.
 *     When written to inactive array, starts with resync
 *
 * write-pending
 *     clean, but writes are blocked waiting for 'active' to be written.
 *
 * active-idle
 *     like active, but no writes have been seen for a while (100msec).
 *
 * broken
*     Array is failed. It's useful because mounted-arrays aren't stopped
*     when array is failed, so this state will at least alert the user that
*     something is wrong.
 */
enum array_state {};
static char *array_states[] =;

static int match_word(const char *word, char **list)
{}

static ssize_t
array_state_show(struct mddev *mddev, char *page)
{}

static int do_md_stop(struct mddev *mddev, int ro);
static int md_set_readonly(struct mddev *mddev);
static int restart_array(struct mddev *mddev);

static ssize_t
array_state_store(struct mddev *mddev, const char *buf, size_t len)
{}
static struct md_sysfs_entry md_array_state =;

static ssize_t
max_corrected_read_errors_show(struct mddev *mddev, char *page) {}

static ssize_t
max_corrected_read_errors_store(struct mddev *mddev, const char *buf, size_t len)
{}

static struct md_sysfs_entry max_corr_read_errors =;

static ssize_t
null_show(struct mddev *mddev, char *page)
{}

static ssize_t
new_dev_store(struct mddev *mddev, const char *buf, size_t len)
{}

static struct md_sysfs_entry md_new_device =;

static ssize_t
bitmap_store(struct mddev *mddev, const char *buf, size_t len)
{}

static struct md_sysfs_entry md_bitmap =;

static ssize_t
size_show(struct mddev *mddev, char *page)
{}

static int update_size(struct mddev *mddev, sector_t num_sectors);

static ssize_t
size_store(struct mddev *mddev, const char *buf, size_t len)
{}

static struct md_sysfs_entry md_size =;

/* Metadata version.
 * This is one of
 *   'none' for arrays with no metadata (good luck...)
 *   'external' for arrays with externally managed metadata,
 * or N.M for internally known formats
 */
static ssize_t
metadata_show(struct mddev *mddev, char *page)
{}

static ssize_t
metadata_store(struct mddev *mddev, const char *buf, size_t len)
{}

static struct md_sysfs_entry md_metadata =;

enum sync_action md_sync_action(struct mddev *mddev)
{}

enum sync_action md_sync_action_by_name(const char *page)
{}

const char *md_sync_action_name(enum sync_action action)
{}

static ssize_t
action_show(struct mddev *mddev, char *page)
{}

/**
 * stop_sync_thread() - wait for sync_thread to stop if it's running.
 * @mddev:	the array.
 * @locked:	if set, reconfig_mutex will still be held after this function
 *		return; if not set, reconfig_mutex will be released after this
 *		function return.
 */
static void stop_sync_thread(struct mddev *mddev, bool locked)
{}

void md_idle_sync_thread(struct mddev *mddev)
{}
EXPORT_SYMBOL_GPL();

void md_frozen_sync_thread(struct mddev *mddev)
{}
EXPORT_SYMBOL_GPL();

void md_unfrozen_sync_thread(struct mddev *mddev)
{}
EXPORT_SYMBOL_GPL();

static int mddev_start_reshape(struct mddev *mddev)
{}

static ssize_t
action_store(struct mddev *mddev, const char *page, size_t len)
{}

static struct md_sysfs_entry md_scan_mode =;

static ssize_t
last_sync_action_show(struct mddev *mddev, char *page)
{}

static struct md_sysfs_entry md_last_scan_mode =;

static ssize_t
mismatch_cnt_show(struct mddev *mddev, char *page)
{}

static struct md_sysfs_entry md_mismatches =;

static ssize_t
sync_min_show(struct mddev *mddev, char *page)
{}

static ssize_t
sync_min_store(struct mddev *mddev, const char *buf, size_t len)
{}

static struct md_sysfs_entry md_sync_min =;

static ssize_t
sync_max_show(struct mddev *mddev, char *page)
{}

static ssize_t
sync_max_store(struct mddev *mddev, const char *buf, size_t len)
{}

static struct md_sysfs_entry md_sync_max =;

static ssize_t
degraded_show(struct mddev *mddev, char *page)
{}
static struct md_sysfs_entry md_degraded =;

static ssize_t
sync_force_parallel_show(struct mddev *mddev, char *page)
{}

static ssize_t
sync_force_parallel_store(struct mddev *mddev, const char *buf, size_t len)
{}

/* force parallel resync, even with shared block devices */
static struct md_sysfs_entry md_sync_force_parallel =;

static ssize_t
sync_speed_show(struct mddev *mddev, char *page)
{}

static struct md_sysfs_entry md_sync_speed =;

static ssize_t
sync_completed_show(struct mddev *mddev, char *page)
{}

static struct md_sysfs_entry md_sync_completed =;

static ssize_t
min_sync_show(struct mddev *mddev, char *page)
{}
static ssize_t
min_sync_store(struct mddev *mddev, const char *buf, size_t len)
{}

static struct md_sysfs_entry md_min_sync =;

static ssize_t
max_sync_show(struct mddev *mddev, char *page)
{}
static ssize_t
max_sync_store(struct mddev *mddev, const char *buf, size_t len)
{}

static struct md_sysfs_entry md_max_sync =;

static ssize_t
suspend_lo_show(struct mddev *mddev, char *page)
{}

static ssize_t
suspend_lo_store(struct mddev *mddev, const char *buf, size_t len)
{}
static struct md_sysfs_entry md_suspend_lo =;

static ssize_t
suspend_hi_show(struct mddev *mddev, char *page)
{}

static ssize_t
suspend_hi_store(struct mddev *mddev, const char *buf, size_t len)
{}
static struct md_sysfs_entry md_suspend_hi =;

static ssize_t
reshape_position_show(struct mddev *mddev, char *page)
{}

static ssize_t
reshape_position_store(struct mddev *mddev, const char *buf, size_t len)
{}

static struct md_sysfs_entry md_reshape_position =;

static ssize_t
reshape_direction_show(struct mddev *mddev, char *page)
{}

static ssize_t
reshape_direction_store(struct mddev *mddev, const char *buf, size_t len)
{}

static struct md_sysfs_entry md_reshape_direction =;

static ssize_t
array_size_show(struct mddev *mddev, char *page)
{}

static ssize_t
array_size_store(struct mddev *mddev, const char *buf, size_t len)
{}

static struct md_sysfs_entry md_array_size =;

static ssize_t
consistency_policy_show(struct mddev *mddev, char *page)
{}

static ssize_t
consistency_policy_store(struct mddev *mddev, const char *buf, size_t len)
{}

static struct md_sysfs_entry md_consistency_policy =;

static ssize_t fail_last_dev_show(struct mddev *mddev, char *page)
{}

/*
 * Setting fail_last_dev to true to allow last device to be forcibly removed
 * from RAID1/RAID10.
 */
static ssize_t
fail_last_dev_store(struct mddev *mddev, const char *buf, size_t len)
{}
static struct md_sysfs_entry md_fail_last_dev =;

static ssize_t serialize_policy_show(struct mddev *mddev, char *page)
{}

/*
 * Setting serialize_policy to true to enforce write IO is not reordered
 * for raid1.
 */
static ssize_t
serialize_policy_store(struct mddev *mddev, const char *buf, size_t len)
{}

static struct md_sysfs_entry md_serialize_policy =;


static struct attribute *md_default_attrs[] =;

static const struct attribute_group md_default_group =;

static struct attribute *md_redundancy_attrs[] =;
static const struct attribute_group md_redundancy_group =;

static const struct attribute_group *md_attr_groups[] =;

static ssize_t
md_attr_show(struct kobject *kobj, struct attribute *attr, char *page)
{}

static ssize_t
md_attr_store(struct kobject *kobj, struct attribute *attr,
	      const char *page, size_t length)
{}

static void md_kobj_release(struct kobject *ko)
{}

static const struct sysfs_ops md_sysfs_ops =;
static const struct kobj_type md_ktype =;

int mdp_major =;

/* stack the limit for all rdevs into lim */
int mddev_stack_rdev_limits(struct mddev *mddev, struct queue_limits *lim,
		unsigned int flags)
{}
EXPORT_SYMBOL_GPL();

/* apply the extra stacking limits from a new rdev into mddev */
int mddev_stack_new_rdev(struct mddev *mddev, struct md_rdev *rdev)
{}
EXPORT_SYMBOL_GPL();

/* update the optimal I/O size after a reshape */
void mddev_update_io_opt(struct mddev *mddev, unsigned int nr_stripes)
{}
EXPORT_SYMBOL_GPL();

static void mddev_delayed_delete(struct work_struct *ws)
{}

void md_init_stacking_limits(struct queue_limits *lim)
{}
EXPORT_SYMBOL_GPL();

struct mddev *md_alloc(dev_t dev, char *name)
{}

static int md_alloc_and_put(dev_t dev, char *name)
{}

static void md_probe(dev_t dev)
{}

static int add_named_array(const char *val, const struct kernel_param *kp)
{}

static void md_safemode_timeout(struct timer_list *t)
{}

static int start_dirty_degraded;

int md_run(struct mddev *mddev)
{}
EXPORT_SYMBOL_GPL();

int do_md_run(struct mddev *mddev)
{}

int md_start(struct mddev *mddev)
{}
EXPORT_SYMBOL_GPL();

static int restart_array(struct mddev *mddev)
{}

static void md_clean(struct mddev *mddev)
{}

static void __md_stop_writes(struct mddev *mddev)
{}

void md_stop_writes(struct mddev *mddev)
{}
EXPORT_SYMBOL_GPL();

static void mddev_detach(struct mddev *mddev)
{}

static void __md_stop(struct mddev *mddev)
{}

void md_stop(struct mddev *mddev)
{}

EXPORT_SYMBOL_GPL();

/* ensure 'mddev->pers' exist before calling md_set_readonly() */
static int md_set_readonly(struct mddev *mddev)
{}

/* mode:
 *   0 - completely stop and dis-assemble array
 *   2 - stop but do not disassemble array
 */
static int do_md_stop(struct mddev *mddev, int mode)
{}

#ifndef MODULE
static void autorun_array(struct mddev *mddev)
{}

/*
 * lets try to run arrays based on all disks that have arrived
 * until now. (those are in pending_raid_disks)
 *
 * the method: pick the first pending disk, collect all disks with
 * the same UUID, remove all from the pending list and put them into
 * the 'same_array' list. Then order this list based on superblock
 * update time (freshest comes first), kick out 'old' disks and
 * compare superblocks. If everything's fine then run it.
 *
 * If "unit" is allocated, then bump its reference count
 */
static void autorun_devices(int part)
{}
#endif /* !MODULE */

static int get_version(void __user *arg)
{}

static int get_array_info(struct mddev *mddev, void __user *arg)
{}

static int get_bitmap_file(struct mddev *mddev, void __user * arg)
{}

static int get_disk_info(struct mddev *mddev, void __user * arg)
{}

int md_add_new_disk(struct mddev *mddev, struct mdu_disk_info_s *info)
{}

static int hot_remove_disk(struct mddev *mddev, dev_t dev)
{}

static int hot_add_disk(struct mddev *mddev, dev_t dev)
{}

static int set_bitmap_file(struct mddev *mddev, int fd)
{}

/*
 * md_set_array_info is used two different ways
 * The original usage is when creating a new array.
 * In this usage, raid_disks is > 0 and it together with
 *  level, size, not_persistent,layout,chunksize determine the
 *  shape of the array.
 *  This will always create an array with a type-0.90.0 superblock.
 * The newer usage is when assembling an array.
 *  In this case raid_disks will be 0, and the major_version field is
 *  use to determine which style super-blocks are to be found on the devices.
 *  The minor and patch _version numbers are also kept incase the
 *  super_block handler wishes to interpret them.
 */
int md_set_array_info(struct mddev *mddev, struct mdu_array_info_s *info)
{}

void md_set_array_sectors(struct mddev *mddev, sector_t array_sectors)
{}
EXPORT_SYMBOL();

static int update_size(struct mddev *mddev, sector_t num_sectors)
{}

static int update_raid_disks(struct mddev *mddev, int raid_disks)
{}

/*
 * update_array_info is used to change the configuration of an
 * on-line array.
 * The version, ctime,level,size,raid_disks,not_persistent, layout,chunk_size
 * fields in the info are checked against the array.
 * Any differences that cannot be handled will cause an error.
 * Normally, only one change can be managed at a time.
 */
static int update_array_info(struct mddev *mddev, mdu_array_info_t *info)
{}

static int set_disk_faulty(struct mddev *mddev, dev_t dev)
{}

/*
 * We have a problem here : there is no easy way to give a CHS
 * virtual geometry. We currently pretend that we have a 2 heads
 * 4 sectors (with a BIG number of cylinders...). This drives
 * dosfs just mad... ;-)
 */
static int md_getgeo(struct block_device *bdev, struct hd_geometry *geo)
{}

static inline int md_ioctl_valid(unsigned int cmd)
{}

static bool md_ioctl_need_suspend(unsigned int cmd)
{}

static int __md_set_array_info(struct mddev *mddev, void __user *argp)
{}

static int md_ioctl(struct block_device *bdev, blk_mode_t mode,
			unsigned int cmd, unsigned long arg)
{}
#ifdef CONFIG_COMPAT
static int md_compat_ioctl(struct block_device *bdev, blk_mode_t mode,
		    unsigned int cmd, unsigned long arg)
{}
#endif /* CONFIG_COMPAT */

static int md_set_read_only(struct block_device *bdev, bool ro)
{}

static int md_open(struct gendisk *disk, blk_mode_t mode)
{}

static void md_release(struct gendisk *disk)
{}

static unsigned int md_check_events(struct gendisk *disk, unsigned int clearing)
{}

static void md_free_disk(struct gendisk *disk)
{}

const struct block_device_operations md_fops =;

static int md_thread(void *arg)
{}

static void md_wakeup_thread_directly(struct md_thread __rcu *thread)
{}

void md_wakeup_thread(struct md_thread __rcu *thread)
{}
EXPORT_SYMBOL();

struct md_thread *md_register_thread(void (*run) (struct md_thread *),
		struct mddev *mddev, const char *name)
{}
EXPORT_SYMBOL();

void md_unregister_thread(struct mddev *mddev, struct md_thread __rcu **threadp)
{}
EXPORT_SYMBOL();

void md_error(struct mddev *mddev, struct md_rdev *rdev)
{}
EXPORT_SYMBOL();

/* seq_file implementation /proc/mdstat */

static void status_unused(struct seq_file *seq)
{}

static void status_personalities(struct seq_file *seq)
{}

static int status_resync(struct seq_file *seq, struct mddev *mddev)
{}

static void *md_seq_start(struct seq_file *seq, loff_t *pos)
	__acquires(&all_mddevs_lock)
{}

static void *md_seq_next(struct seq_file *seq, void *v, loff_t *pos)
{}

static void md_seq_stop(struct seq_file *seq, void *v)
	__releases(&all_mddevs_lock)
{}

static int md_seq_show(struct seq_file *seq, void *v)
{}

static const struct seq_operations md_seq_ops =;

static int md_seq_open(struct inode *inode, struct file *file)
{}

static int md_unloading;
static __poll_t mdstat_poll(struct file *filp, poll_table *wait)
{}

static const struct proc_ops mdstat_proc_ops =;

int register_md_personality(struct md_personality *p)
{}
EXPORT_SYMBOL();

int unregister_md_personality(struct md_personality *p)
{}
EXPORT_SYMBOL();

int register_md_cluster_operations(const struct md_cluster_operations *ops,
				   struct module *module)
{}
EXPORT_SYMBOL();

int unregister_md_cluster_operations(void)
{}
EXPORT_SYMBOL();

int md_setup_cluster(struct mddev *mddev, int nodes)
{}

void md_cluster_stop(struct mddev *mddev)
{}

static int is_mddev_idle(struct mddev *mddev, int init)
{}

void md_done_sync(struct mddev *mddev, int blocks, int ok)
{}
EXPORT_SYMBOL();

/* md_write_start(mddev, bi)
 * If we need to update some array metadata (e.g. 'active' flag
 * in superblock) before writing, schedule a superblock update
 * and wait for it to complete.
 * A return value of 'false' means that the write wasn't recorded
 * and cannot proceed as the array is being suspend.
 */
void md_write_start(struct mddev *mddev, struct bio *bi)
{}
EXPORT_SYMBOL();

/* md_write_inc can only be called when md_write_start() has
 * already been called at least once of the current request.
 * It increments the counter and is useful when a single request
 * is split into several parts.  Each part causes an increment and
 * so needs a matching md_write_end().
 * Unlike md_write_start(), it is safe to call md_write_inc() inside
 * a spinlocked region.
 */
void md_write_inc(struct mddev *mddev, struct bio *bi)
{}
EXPORT_SYMBOL();

void md_write_end(struct mddev *mddev)
{}

EXPORT_SYMBOL();

/* This is used by raid0 and raid10 */
void md_submit_discard_bio(struct mddev *mddev, struct md_rdev *rdev,
			struct bio *bio, sector_t start, sector_t size)
{}
EXPORT_SYMBOL_GPL();

static void md_end_clone_io(struct bio *bio)
{}

static void md_clone_bio(struct mddev *mddev, struct bio **bio)
{}

void md_account_bio(struct mddev *mddev, struct bio **bio)
{}
EXPORT_SYMBOL_GPL();

void md_free_cloned_bio(struct bio *bio)
{}
EXPORT_SYMBOL_GPL();

/* md_allow_write(mddev)
 * Calling this ensures that the array is marked 'active' so that writes
 * may proceed without blocking.  It is important to call this before
 * attempting a GFP_KERNEL allocation while holding the mddev lock.
 * Must be called with mddev_lock held.
 */
void md_allow_write(struct mddev *mddev)
{}
EXPORT_SYMBOL_GPL();

static sector_t md_sync_max_sectors(struct mddev *mddev,
				    enum sync_action action)
{}

static sector_t md_sync_position(struct mddev *mddev, enum sync_action action)
{}

#define SYNC_MARKS
#define SYNC_MARK_STEP
#define UPDATE_FREQUENCY
void md_do_sync(struct md_thread *thread)
{}
EXPORT_SYMBOL_GPL();

static bool rdev_removeable(struct md_rdev *rdev)
{}

static bool rdev_is_spare(struct md_rdev *rdev)
{}

static bool rdev_addable(struct md_rdev *rdev)
{}

static bool md_spares_need_change(struct mddev *mddev)
{}

static int remove_and_add_spares(struct mddev *mddev,
				 struct md_rdev *this)
{}

static bool md_choose_sync_action(struct mddev *mddev, int *spares)
{}

static void md_start_sync(struct work_struct *ws)
{}

static void unregister_sync_thread(struct mddev *mddev)
{}

/*
 * This routine is regularly called by all per-raid-array threads to
 * deal with generic issues like resync and super-block update.
 * Raid personalities that don't have a thread (linear/raid0) do not
 * need this as they never do any recovery or update the superblock.
 *
 * It does not do any resync itself, but rather "forks" off other threads
 * to do that as needed.
 * When it is determined that resync is needed, we set MD_RECOVERY_RUNNING in
 * "->recovery" and create a thread at ->sync_thread.
 * When the thread finishes it sets MD_RECOVERY_DONE
 * and wakeups up this thread which will reap the thread and finish up.
 * This thread also removes any faulty devices (with nr_pending == 0).
 *
 * The overall approach is:
 *  1/ if the superblock needs updating, update it.
 *  2/ If a recovery thread is running, don't do anything else.
 *  3/ If recovery has finished, clean up, possibly marking spares active.
 *  4/ If there are any faulty devices, remove them.
 *  5/ If array is degraded, try to add spares devices
 *  6/ If array has spares or is not in-sync, start a resync thread.
 */
void md_check_recovery(struct mddev *mddev)
{}
EXPORT_SYMBOL();

void md_reap_sync_thread(struct mddev *mddev)
{}
EXPORT_SYMBOL();

void md_wait_for_blocked_rdev(struct md_rdev *rdev, struct mddev *mddev)
{}
EXPORT_SYMBOL();

void md_finish_reshape(struct mddev *mddev)
{}
EXPORT_SYMBOL();

/* Bad block management */

/* Returns 1 on success, 0 on failure */
int rdev_set_badblocks(struct md_rdev *rdev, sector_t s, int sectors,
		       int is_new)
{}
EXPORT_SYMBOL_GPL();

int rdev_clear_badblocks(struct md_rdev *rdev, sector_t s, int sectors,
			 int is_new)
{}
EXPORT_SYMBOL_GPL();

static int md_notify_reboot(struct notifier_block *this,
			    unsigned long code, void *x)
{}

static struct notifier_block md_notifier =;

static void md_geninit(void)
{}

static int __init md_init(void)
{}

static void check_sb_changes(struct mddev *mddev, struct md_rdev *rdev)
{}

static int read_rdev(struct mddev *mddev, struct md_rdev *rdev)
{}

void md_reload_sb(struct mddev *mddev, int nr)
{}
EXPORT_SYMBOL();

#ifndef MODULE

/*
 * Searches all registered partitions for autorun RAID arrays
 * at boot time.
 */

static DEFINE_MUTEX(detected_devices_mutex);
static LIST_HEAD(all_detected_devices);
struct detected_devices_node {};

void md_autodetect_dev(dev_t dev)
{}

void md_autostart_arrays(int part)
{}

#endif /* !MODULE */

static __exit void md_exit(void)
{}

subsys_initcall(md_init);
module_exit()

static int get_ro(char *buffer, const struct kernel_param *kp)
{}
static int set_ro(const char *val, const struct kernel_param *kp)
{}

module_param_call();
module_param(start_dirty_degraded, int, S_IRUGO|S_IWUSR);
module_param_call();
module_param(create_on_open, bool, S_IRUSR|S_IWUSR);

MODULE_LICENSE();
MODULE_DESCRIPTION();
MODULE_ALIAS();
MODULE_ALIAS_BLOCKDEV_MAJOR();