Creation of Cybook 2416 (actually Gen4) repository
This commit is contained in:
2
include/linux/raid/Kbuild
Normal file
2
include/linux/raid/Kbuild
Normal file
@@ -0,0 +1,2 @@
|
||||
header-y += md_p.h
|
||||
header-y += md_u.h
|
||||
285
include/linux/raid/bitmap.h
Normal file
285
include/linux/raid/bitmap.h
Normal file
@@ -0,0 +1,285 @@
|
||||
/*
|
||||
* bitmap.h: Copyright (C) Peter T. Breuer (ptb@ot.uc3m.es) 2003
|
||||
*
|
||||
* additions: Copyright (C) 2003-2004, Paul Clements, SteelEye Technology, Inc.
|
||||
*/
|
||||
#ifndef BITMAP_H
|
||||
#define BITMAP_H 1
|
||||
|
||||
#define BITMAP_MAJOR_LO 3
|
||||
/* version 4 insists the bitmap is in little-endian order
|
||||
* with version 3, it is host-endian which is non-portable
|
||||
*/
|
||||
#define BITMAP_MAJOR_HI 4
|
||||
#define BITMAP_MAJOR_HOSTENDIAN 3
|
||||
|
||||
#define BITMAP_MINOR 39
|
||||
|
||||
/*
|
||||
* in-memory bitmap:
|
||||
*
|
||||
* Use 16 bit block counters to track pending writes to each "chunk".
|
||||
* The 2 high order bits are special-purpose, the first is a flag indicating
|
||||
* whether a resync is needed. The second is a flag indicating whether a
|
||||
* resync is active.
|
||||
* This means that the counter is actually 14 bits:
|
||||
*
|
||||
* +--------+--------+------------------------------------------------+
|
||||
* | resync | resync | counter |
|
||||
* | needed | active | |
|
||||
* | (0-1) | (0-1) | (0-16383) |
|
||||
* +--------+--------+------------------------------------------------+
|
||||
*
|
||||
* The "resync needed" bit is set when:
|
||||
* a '1' bit is read from storage at startup.
|
||||
* a write request fails on some drives
|
||||
* a resync is aborted on a chunk with 'resync active' set
|
||||
* It is cleared (and resync-active set) when a resync starts across all drives
|
||||
* of the chunk.
|
||||
*
|
||||
*
|
||||
* The "resync active" bit is set when:
|
||||
* a resync is started on all drives, and resync_needed is set.
|
||||
* resync_needed will be cleared (as long as resync_active wasn't already set).
|
||||
* It is cleared when a resync completes.
|
||||
*
|
||||
* The counter counts pending write requests, plus the on-disk bit.
|
||||
* When the counter is '1' and the resync bits are clear, the on-disk
|
||||
* bit can be cleared aswell, thus setting the counter to 0.
|
||||
* When we set a bit, or in the counter (to start a write), if the fields is
|
||||
* 0, we first set the disk bit and set the counter to 1.
|
||||
*
|
||||
* If the counter is 0, the on-disk bit is clear and the stipe is clean
|
||||
* Anything that dirties the stipe pushes the counter to 2 (at least)
|
||||
* and sets the on-disk bit (lazily).
|
||||
* If a periodic sweep find the counter at 2, it is decremented to 1.
|
||||
* If the sweep find the counter at 1, the on-disk bit is cleared and the
|
||||
* counter goes to zero.
|
||||
*
|
||||
* Also, we'll hijack the "map" pointer itself and use it as two 16 bit block
|
||||
* counters as a fallback when "page" memory cannot be allocated:
|
||||
*
|
||||
* Normal case (page memory allocated):
|
||||
*
|
||||
* page pointer (32-bit)
|
||||
*
|
||||
* [ ] ------+
|
||||
* |
|
||||
* +-------> [ ][ ]..[ ] (4096 byte page == 2048 counters)
|
||||
* c1 c2 c2048
|
||||
*
|
||||
* Hijacked case (page memory allocation failed):
|
||||
*
|
||||
* hijacked page pointer (32-bit)
|
||||
*
|
||||
* [ ][ ] (no page memory allocated)
|
||||
* counter #1 (16-bit) counter #2 (16-bit)
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef __KERNEL__
|
||||
|
||||
#define PAGE_BITS (PAGE_SIZE << 3)
|
||||
#define PAGE_BIT_SHIFT (PAGE_SHIFT + 3)
|
||||
|
||||
typedef __u16 bitmap_counter_t;
|
||||
#define COUNTER_BITS 16
|
||||
#define COUNTER_BIT_SHIFT 4
|
||||
#define COUNTER_BYTE_RATIO (COUNTER_BITS / 8)
|
||||
#define COUNTER_BYTE_SHIFT (COUNTER_BIT_SHIFT - 3)
|
||||
|
||||
#define NEEDED_MASK ((bitmap_counter_t) (1 << (COUNTER_BITS - 1)))
|
||||
#define RESYNC_MASK ((bitmap_counter_t) (1 << (COUNTER_BITS - 2)))
|
||||
#define COUNTER_MAX ((bitmap_counter_t) RESYNC_MASK - 1)
|
||||
#define NEEDED(x) (((bitmap_counter_t) x) & NEEDED_MASK)
|
||||
#define RESYNC(x) (((bitmap_counter_t) x) & RESYNC_MASK)
|
||||
#define COUNTER(x) (((bitmap_counter_t) x) & COUNTER_MAX)
|
||||
|
||||
/* how many counters per page? */
|
||||
#define PAGE_COUNTER_RATIO (PAGE_BITS / COUNTER_BITS)
|
||||
/* same, except a shift value for more efficient bitops */
|
||||
#define PAGE_COUNTER_SHIFT (PAGE_BIT_SHIFT - COUNTER_BIT_SHIFT)
|
||||
/* same, except a mask value for more efficient bitops */
|
||||
#define PAGE_COUNTER_MASK (PAGE_COUNTER_RATIO - 1)
|
||||
|
||||
#define BITMAP_BLOCK_SIZE 512
|
||||
#define BITMAP_BLOCK_SHIFT 9
|
||||
|
||||
/* how many blocks per chunk? (this is variable) */
|
||||
#define CHUNK_BLOCK_RATIO(bitmap) ((bitmap)->chunksize >> BITMAP_BLOCK_SHIFT)
|
||||
#define CHUNK_BLOCK_SHIFT(bitmap) ((bitmap)->chunkshift - BITMAP_BLOCK_SHIFT)
|
||||
#define CHUNK_BLOCK_MASK(bitmap) (CHUNK_BLOCK_RATIO(bitmap) - 1)
|
||||
|
||||
/* when hijacked, the counters and bits represent even larger "chunks" */
|
||||
/* there will be 1024 chunks represented by each counter in the page pointers */
|
||||
#define PAGEPTR_BLOCK_RATIO(bitmap) \
|
||||
(CHUNK_BLOCK_RATIO(bitmap) << PAGE_COUNTER_SHIFT >> 1)
|
||||
#define PAGEPTR_BLOCK_SHIFT(bitmap) \
|
||||
(CHUNK_BLOCK_SHIFT(bitmap) + PAGE_COUNTER_SHIFT - 1)
|
||||
#define PAGEPTR_BLOCK_MASK(bitmap) (PAGEPTR_BLOCK_RATIO(bitmap) - 1)
|
||||
|
||||
/*
|
||||
* on-disk bitmap:
|
||||
*
|
||||
* Use one bit per "chunk" (block set). We do the disk I/O on the bitmap
|
||||
* file a page at a time. There's a superblock at the start of the file.
|
||||
*/
|
||||
|
||||
/* map chunks (bits) to file pages - offset by the size of the superblock */
|
||||
#define CHUNK_BIT_OFFSET(chunk) ((chunk) + (sizeof(bitmap_super_t) << 3))
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* bitmap structures:
|
||||
*/
|
||||
|
||||
#define BITMAP_MAGIC 0x6d746962
|
||||
|
||||
/* use these for bitmap->flags and bitmap->sb->state bit-fields */
|
||||
enum bitmap_state {
|
||||
BITMAP_ACTIVE = 0x001, /* the bitmap is in use */
|
||||
BITMAP_STALE = 0x002, /* the bitmap file is out of date or had -EIO */
|
||||
BITMAP_WRITE_ERROR = 0x004, /* A write error has occurred */
|
||||
BITMAP_HOSTENDIAN = 0x8000,
|
||||
};
|
||||
|
||||
/* the superblock at the front of the bitmap file -- little endian */
|
||||
typedef struct bitmap_super_s {
|
||||
__le32 magic; /* 0 BITMAP_MAGIC */
|
||||
__le32 version; /* 4 the bitmap major for now, could change... */
|
||||
__u8 uuid[16]; /* 8 128 bit uuid - must match md device uuid */
|
||||
__le64 events; /* 24 event counter for the bitmap (1)*/
|
||||
__le64 events_cleared;/*32 event counter when last bit cleared (2) */
|
||||
__le64 sync_size; /* 40 the size of the md device's sync range(3) */
|
||||
__le32 state; /* 48 bitmap state information */
|
||||
__le32 chunksize; /* 52 the bitmap chunk size in bytes */
|
||||
__le32 daemon_sleep; /* 56 seconds between disk flushes */
|
||||
__le32 write_behind; /* 60 number of outstanding write-behind writes */
|
||||
|
||||
__u8 pad[256 - 64]; /* set to zero */
|
||||
} bitmap_super_t;
|
||||
|
||||
/* notes:
|
||||
* (1) This event counter is updated before the eventcounter in the md superblock
|
||||
* When a bitmap is loaded, it is only accepted if this event counter is equal
|
||||
* to, or one greater than, the event counter in the superblock.
|
||||
* (2) This event counter is updated when the other one is *if*and*only*if* the
|
||||
* array is not degraded. As bits are not cleared when the array is degraded,
|
||||
* this represents the last time that any bits were cleared.
|
||||
* If a device is being added that has an event count with this value or
|
||||
* higher, it is accepted as conforming to the bitmap.
|
||||
* (3)This is the number of sectors represented by the bitmap, and is the range that
|
||||
* resync happens across. For raid1 and raid5/6 it is the size of individual
|
||||
* devices. For raid10 it is the size of the array.
|
||||
*/
|
||||
|
||||
#ifdef __KERNEL__
|
||||
|
||||
/* the in-memory bitmap is represented by bitmap_pages */
|
||||
struct bitmap_page {
|
||||
/*
|
||||
* map points to the actual memory page
|
||||
*/
|
||||
char *map;
|
||||
/*
|
||||
* in emergencies (when map cannot be alloced), hijack the map
|
||||
* pointer and use it as two counters itself
|
||||
*/
|
||||
unsigned int hijacked:1;
|
||||
/*
|
||||
* count of dirty bits on the page
|
||||
*/
|
||||
unsigned int count:31;
|
||||
};
|
||||
|
||||
/* keep track of bitmap file pages that have pending writes on them */
|
||||
struct page_list {
|
||||
struct list_head list;
|
||||
struct page *page;
|
||||
};
|
||||
|
||||
/* the main bitmap structure - one per mddev */
|
||||
struct bitmap {
|
||||
struct bitmap_page *bp;
|
||||
unsigned long pages; /* total number of pages in the bitmap */
|
||||
unsigned long missing_pages; /* number of pages not yet allocated */
|
||||
|
||||
mddev_t *mddev; /* the md device that the bitmap is for */
|
||||
|
||||
int counter_bits; /* how many bits per block counter */
|
||||
|
||||
/* bitmap chunksize -- how much data does each bit represent? */
|
||||
unsigned long chunksize;
|
||||
unsigned long chunkshift; /* chunksize = 2^chunkshift (for bitops) */
|
||||
unsigned long chunks; /* total number of data chunks for the array */
|
||||
|
||||
/* We hold a count on the chunk currently being synced, and drop
|
||||
* it when the last block is started. If the resync is aborted
|
||||
* midway, we need to be able to drop that count, so we remember
|
||||
* the counted chunk..
|
||||
*/
|
||||
unsigned long syncchunk;
|
||||
|
||||
__u64 events_cleared;
|
||||
|
||||
/* bitmap spinlock */
|
||||
spinlock_t lock;
|
||||
|
||||
long offset; /* offset from superblock if file is NULL */
|
||||
struct file *file; /* backing disk file */
|
||||
struct page *sb_page; /* cached copy of the bitmap file superblock */
|
||||
struct page **filemap; /* list of cache pages for the file */
|
||||
unsigned long *filemap_attr; /* attributes associated w/ filemap pages */
|
||||
unsigned long file_pages; /* number of pages in the file */
|
||||
int last_page_size; /* bytes in the last page */
|
||||
|
||||
unsigned long flags;
|
||||
|
||||
unsigned long max_write_behind; /* write-behind mode */
|
||||
atomic_t behind_writes;
|
||||
|
||||
/*
|
||||
* the bitmap daemon - periodically wakes up and sweeps the bitmap
|
||||
* file, cleaning up bits and flushing out pages to disk as necessary
|
||||
*/
|
||||
unsigned long daemon_lastrun; /* jiffies of last run */
|
||||
unsigned long daemon_sleep; /* how many seconds between updates? */
|
||||
|
||||
atomic_t pending_writes; /* pending writes to the bitmap file */
|
||||
wait_queue_head_t write_wait;
|
||||
wait_queue_head_t overflow_wait;
|
||||
|
||||
};
|
||||
|
||||
/* the bitmap API */
|
||||
|
||||
/* these are used only by md/bitmap */
|
||||
int bitmap_create(mddev_t *mddev);
|
||||
void bitmap_flush(mddev_t *mddev);
|
||||
void bitmap_destroy(mddev_t *mddev);
|
||||
int bitmap_active(struct bitmap *bitmap);
|
||||
|
||||
char *file_path(struct file *file, char *buf, int count);
|
||||
void bitmap_print_sb(struct bitmap *bitmap);
|
||||
int bitmap_update_sb(struct bitmap *bitmap);
|
||||
|
||||
int bitmap_setallbits(struct bitmap *bitmap);
|
||||
void bitmap_write_all(struct bitmap *bitmap);
|
||||
|
||||
void bitmap_dirty_bits(struct bitmap *bitmap, unsigned long s, unsigned long e);
|
||||
|
||||
/* these are exported */
|
||||
int bitmap_startwrite(struct bitmap *bitmap, sector_t offset,
|
||||
unsigned long sectors, int behind);
|
||||
void bitmap_endwrite(struct bitmap *bitmap, sector_t offset,
|
||||
unsigned long sectors, int success, int behind);
|
||||
int bitmap_start_sync(struct bitmap *bitmap, sector_t offset, int *blocks, int degraded);
|
||||
void bitmap_end_sync(struct bitmap *bitmap, sector_t offset, int *blocks, int aborted);
|
||||
void bitmap_close_sync(struct bitmap *bitmap);
|
||||
|
||||
int bitmap_unplug(struct bitmap *bitmap);
|
||||
int bitmap_daemon_work(struct bitmap *bitmap);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
29
include/linux/raid/linear.h
Normal file
29
include/linux/raid/linear.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#ifndef _LINEAR_H
|
||||
#define _LINEAR_H
|
||||
|
||||
#include <linux/raid/md.h>
|
||||
|
||||
struct dev_info {
|
||||
mdk_rdev_t *rdev;
|
||||
sector_t size;
|
||||
sector_t offset;
|
||||
};
|
||||
|
||||
typedef struct dev_info dev_info_t;
|
||||
|
||||
struct linear_private_data
|
||||
{
|
||||
struct linear_private_data *prev; /* earlier version */
|
||||
dev_info_t **hash_table;
|
||||
sector_t hash_spacing;
|
||||
sector_t array_size;
|
||||
int preshift; /* shift before dividing by hash_spacing */
|
||||
dev_info_t disks[0];
|
||||
};
|
||||
|
||||
|
||||
typedef struct linear_private_data linear_conf_t;
|
||||
|
||||
#define mddev_to_conf(mddev) ((linear_conf_t *) mddev->private)
|
||||
|
||||
#endif
|
||||
101
include/linux/raid/md.h
Normal file
101
include/linux/raid/md.h
Normal file
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
md.h : Multiple Devices driver for Linux
|
||||
Copyright (C) 1996-98 Ingo Molnar, Gadi Oxman
|
||||
Copyright (C) 1994-96 Marc ZYNGIER
|
||||
<zyngier@ufr-info-p7.ibp.fr> or
|
||||
<maz@gloups.fdn.fr>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
(for example /usr/src/linux/COPYING); if not, write to the Free
|
||||
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#ifndef _MD_H
|
||||
#define _MD_H
|
||||
|
||||
#include <linux/blkdev.h>
|
||||
#include <asm/semaphore.h>
|
||||
#include <linux/major.h>
|
||||
#include <linux/ioctl.h>
|
||||
#include <linux/types.h>
|
||||
#include <linux/bitops.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/hdreg.h>
|
||||
#include <linux/proc_fs.h>
|
||||
#include <linux/seq_file.h>
|
||||
#include <linux/smp_lock.h>
|
||||
#include <linux/delay.h>
|
||||
#include <net/checksum.h>
|
||||
#include <linux/random.h>
|
||||
#include <linux/kernel_stat.h>
|
||||
#include <asm/io.h>
|
||||
#include <linux/completion.h>
|
||||
#include <linux/mempool.h>
|
||||
#include <linux/list.h>
|
||||
#include <linux/reboot.h>
|
||||
#include <linux/vmalloc.h>
|
||||
#include <linux/blkpg.h>
|
||||
#include <linux/bio.h>
|
||||
|
||||
/*
|
||||
* 'md_p.h' holds the 'physical' layout of RAID devices
|
||||
* 'md_u.h' holds the user <=> kernel API
|
||||
*
|
||||
* 'md_k.h' holds kernel internal definitions
|
||||
*/
|
||||
|
||||
#include <linux/raid/md_p.h>
|
||||
#include <linux/raid/md_u.h>
|
||||
#include <linux/raid/md_k.h>
|
||||
|
||||
#ifdef CONFIG_MD
|
||||
|
||||
/*
|
||||
* Different major versions are not compatible.
|
||||
* Different minor versions are only downward compatible.
|
||||
* Different patchlevel versions are downward and upward compatible.
|
||||
*/
|
||||
#define MD_MAJOR_VERSION 0
|
||||
#define MD_MINOR_VERSION 90
|
||||
/*
|
||||
* MD_PATCHLEVEL_VERSION indicates kernel functionality.
|
||||
* >=1 means different superblock formats are selectable using SET_ARRAY_INFO
|
||||
* and major_version/minor_version accordingly
|
||||
* >=2 means that Internal bitmaps are supported by setting MD_SB_BITMAP_PRESENT
|
||||
* in the super status byte
|
||||
* >=3 means that bitmap superblock version 4 is supported, which uses
|
||||
* little-ending representation rather than host-endian
|
||||
*/
|
||||
#define MD_PATCHLEVEL_VERSION 3
|
||||
|
||||
extern int register_md_personality (struct mdk_personality *p);
|
||||
extern int unregister_md_personality (struct mdk_personality *p);
|
||||
extern mdk_thread_t * md_register_thread (void (*run) (mddev_t *mddev),
|
||||
mddev_t *mddev, const char *name);
|
||||
extern void md_unregister_thread (mdk_thread_t *thread);
|
||||
extern void md_wakeup_thread(mdk_thread_t *thread);
|
||||
extern void md_check_recovery(mddev_t *mddev);
|
||||
extern void md_write_start(mddev_t *mddev, struct bio *bi);
|
||||
extern void md_write_end(mddev_t *mddev);
|
||||
extern void md_handle_safemode(mddev_t *mddev);
|
||||
extern void md_done_sync(mddev_t *mddev, int blocks, int ok);
|
||||
extern void md_error (mddev_t *mddev, mdk_rdev_t *rdev);
|
||||
extern void md_unplug_mddev(mddev_t *mddev);
|
||||
|
||||
extern void md_super_write(mddev_t *mddev, mdk_rdev_t *rdev,
|
||||
sector_t sector, int size, struct page *page);
|
||||
extern void md_super_wait(mddev_t *mddev);
|
||||
extern int sync_page_io(struct block_device *bdev, sector_t sector, int size,
|
||||
struct page *page, int rw);
|
||||
extern void md_do_sync(mddev_t *mddev);
|
||||
extern void md_new_event(mddev_t *mddev);
|
||||
extern void md_allow_write(mddev_t *mddev);
|
||||
|
||||
#endif /* CONFIG_MD */
|
||||
#endif
|
||||
|
||||
371
include/linux/raid/md_k.h
Normal file
371
include/linux/raid/md_k.h
Normal file
@@ -0,0 +1,371 @@
|
||||
/*
|
||||
md_k.h : kernel internal structure of the Linux MD driver
|
||||
Copyright (C) 1996-98 Ingo Molnar, Gadi Oxman
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
(for example /usr/src/linux/COPYING); if not, write to the Free
|
||||
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#ifndef _MD_K_H
|
||||
#define _MD_K_H
|
||||
|
||||
/* and dm-bio-list.h is not under include/linux because.... ??? */
|
||||
#include "../../../drivers/md/dm-bio-list.h"
|
||||
|
||||
#ifdef CONFIG_BLOCK
|
||||
|
||||
#define LEVEL_MULTIPATH (-4)
|
||||
#define LEVEL_LINEAR (-1)
|
||||
#define LEVEL_FAULTY (-5)
|
||||
|
||||
/* we need a value for 'no level specified' and 0
|
||||
* means 'raid0', so we need something else. This is
|
||||
* for internal use only
|
||||
*/
|
||||
#define LEVEL_NONE (-1000000)
|
||||
|
||||
#define MaxSector (~(sector_t)0)
|
||||
|
||||
typedef struct mddev_s mddev_t;
|
||||
typedef struct mdk_rdev_s mdk_rdev_t;
|
||||
|
||||
/*
|
||||
* options passed in raidrun:
|
||||
*/
|
||||
|
||||
/* Currently this must fit in an 'int' */
|
||||
#define MAX_CHUNK_SIZE (1<<30)
|
||||
|
||||
/*
|
||||
* MD's 'extended' device
|
||||
*/
|
||||
struct mdk_rdev_s
|
||||
{
|
||||
struct list_head same_set; /* RAID devices within the same set */
|
||||
|
||||
sector_t size; /* Device size (in blocks) */
|
||||
mddev_t *mddev; /* RAID array if running */
|
||||
unsigned long last_events; /* IO event timestamp */
|
||||
|
||||
struct block_device *bdev; /* block device handle */
|
||||
|
||||
struct page *sb_page;
|
||||
int sb_loaded;
|
||||
__u64 sb_events;
|
||||
sector_t data_offset; /* start of data in array */
|
||||
sector_t sb_offset;
|
||||
int sb_size; /* bytes in the superblock */
|
||||
int preferred_minor; /* autorun support */
|
||||
|
||||
struct kobject kobj;
|
||||
|
||||
/* A device can be in one of three states based on two flags:
|
||||
* Not working: faulty==1 in_sync==0
|
||||
* Fully working: faulty==0 in_sync==1
|
||||
* Working, but not
|
||||
* in sync with array
|
||||
* faulty==0 in_sync==0
|
||||
*
|
||||
* It can never have faulty==1, in_sync==1
|
||||
* This reduces the burden of testing multiple flags in many cases
|
||||
*/
|
||||
|
||||
unsigned long flags;
|
||||
#define Faulty 1 /* device is known to have a fault */
|
||||
#define In_sync 2 /* device is in_sync with rest of array */
|
||||
#define WriteMostly 4 /* Avoid reading if at all possible */
|
||||
#define BarriersNotsupp 5 /* BIO_RW_BARRIER is not supported */
|
||||
|
||||
int desc_nr; /* descriptor index in the superblock */
|
||||
int raid_disk; /* role of device in array */
|
||||
int saved_raid_disk; /* role that device used to have in the
|
||||
* array and could again if we did a partial
|
||||
* resync from the bitmap
|
||||
*/
|
||||
sector_t recovery_offset;/* If this device has been partially
|
||||
* recovered, this is where we were
|
||||
* up to.
|
||||
*/
|
||||
|
||||
atomic_t nr_pending; /* number of pending requests.
|
||||
* only maintained for arrays that
|
||||
* support hot removal
|
||||
*/
|
||||
atomic_t read_errors; /* number of consecutive read errors that
|
||||
* we have tried to ignore.
|
||||
*/
|
||||
atomic_t corrected_errors; /* number of corrected read errors,
|
||||
* for reporting to userspace and storing
|
||||
* in superblock.
|
||||
*/
|
||||
struct work_struct del_work; /* used for delayed sysfs removal */
|
||||
};
|
||||
|
||||
struct mddev_s
|
||||
{
|
||||
void *private;
|
||||
struct mdk_personality *pers;
|
||||
dev_t unit;
|
||||
int md_minor;
|
||||
struct list_head disks;
|
||||
unsigned long flags;
|
||||
#define MD_CHANGE_DEVS 0 /* Some device status has changed */
|
||||
#define MD_CHANGE_CLEAN 1 /* transition to or from 'clean' */
|
||||
#define MD_CHANGE_PENDING 2 /* superblock update in progress */
|
||||
|
||||
int ro;
|
||||
|
||||
struct gendisk *gendisk;
|
||||
|
||||
struct kobject kobj;
|
||||
|
||||
/* Superblock information */
|
||||
int major_version,
|
||||
minor_version,
|
||||
patch_version;
|
||||
int persistent;
|
||||
int chunk_size;
|
||||
time_t ctime, utime;
|
||||
int level, layout;
|
||||
char clevel[16];
|
||||
int raid_disks;
|
||||
int max_disks;
|
||||
sector_t size; /* used size of component devices */
|
||||
sector_t array_size; /* exported array size */
|
||||
__u64 events;
|
||||
|
||||
char uuid[16];
|
||||
|
||||
/* If the array is being reshaped, we need to record the
|
||||
* new shape and an indication of where we are up to.
|
||||
* This is written to the superblock.
|
||||
* If reshape_position is MaxSector, then no reshape is happening (yet).
|
||||
*/
|
||||
sector_t reshape_position;
|
||||
int delta_disks, new_level, new_layout, new_chunk;
|
||||
|
||||
struct mdk_thread_s *thread; /* management thread */
|
||||
struct mdk_thread_s *sync_thread; /* doing resync or reconstruct */
|
||||
sector_t curr_resync; /* last block scheduled */
|
||||
unsigned long resync_mark; /* a recent timestamp */
|
||||
sector_t resync_mark_cnt;/* blocks written at resync_mark */
|
||||
sector_t curr_mark_cnt; /* blocks scheduled now */
|
||||
|
||||
sector_t resync_max_sectors; /* may be set by personality */
|
||||
|
||||
sector_t resync_mismatches; /* count of sectors where
|
||||
* parity/replica mismatch found
|
||||
*/
|
||||
|
||||
/* allow user-space to request suspension of IO to regions of the array */
|
||||
sector_t suspend_lo;
|
||||
sector_t suspend_hi;
|
||||
/* if zero, use the system-wide default */
|
||||
int sync_speed_min;
|
||||
int sync_speed_max;
|
||||
|
||||
int ok_start_degraded;
|
||||
/* recovery/resync flags
|
||||
* NEEDED: we might need to start a resync/recover
|
||||
* RUNNING: a thread is running, or about to be started
|
||||
* SYNC: actually doing a resync, not a recovery
|
||||
* ERR: and IO error was detected - abort the resync/recovery
|
||||
* INTR: someone requested a (clean) early abort.
|
||||
* DONE: thread is done and is waiting to be reaped
|
||||
* REQUEST: user-space has requested a sync (used with SYNC)
|
||||
* CHECK: user-space request for for check-only, no repair
|
||||
* RESHAPE: A reshape is happening
|
||||
*
|
||||
* If neither SYNC or RESHAPE are set, then it is a recovery.
|
||||
*/
|
||||
#define MD_RECOVERY_RUNNING 0
|
||||
#define MD_RECOVERY_SYNC 1
|
||||
#define MD_RECOVERY_ERR 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
|
||||
|
||||
unsigned long recovery;
|
||||
|
||||
int in_sync; /* know to not need resync */
|
||||
struct mutex reconfig_mutex;
|
||||
atomic_t active;
|
||||
|
||||
int changed; /* true if we might need to reread partition info */
|
||||
int degraded; /* whether md should consider
|
||||
* adding a spare
|
||||
*/
|
||||
int barriers_work; /* initialised to true, cleared as soon
|
||||
* as a barrier request to slave
|
||||
* fails. Only supported
|
||||
*/
|
||||
struct bio *biolist; /* bios that need to be retried
|
||||
* because BIO_RW_BARRIER is not supported
|
||||
*/
|
||||
|
||||
atomic_t recovery_active; /* blocks scheduled, but not written */
|
||||
wait_queue_head_t recovery_wait;
|
||||
sector_t recovery_cp;
|
||||
|
||||
spinlock_t write_lock;
|
||||
wait_queue_head_t sb_wait; /* for waiting on superblock updates */
|
||||
atomic_t pending_writes; /* number of active superblock writes */
|
||||
|
||||
unsigned int safemode; /* if set, update "clean" superblock
|
||||
* when no writes pending.
|
||||
*/
|
||||
unsigned int safemode_delay;
|
||||
struct timer_list safemode_timer;
|
||||
atomic_t writes_pending;
|
||||
request_queue_t *queue; /* for plugging ... */
|
||||
|
||||
atomic_t write_behind; /* outstanding async IO */
|
||||
unsigned int max_write_behind; /* 0 = sync */
|
||||
|
||||
struct bitmap *bitmap; /* the bitmap for the device */
|
||||
struct file *bitmap_file; /* the bitmap file */
|
||||
long bitmap_offset; /* offset from superblock of
|
||||
* start of bitmap. May be
|
||||
* negative, but not '0'
|
||||
*/
|
||||
long default_bitmap_offset; /* this is the offset to use when
|
||||
* hot-adding a bitmap. It should
|
||||
* eventually be settable by sysfs.
|
||||
*/
|
||||
|
||||
struct list_head all_mddevs;
|
||||
};
|
||||
|
||||
|
||||
static inline void rdev_dec_pending(mdk_rdev_t *rdev, mddev_t *mddev)
|
||||
{
|
||||
int faulty = test_bit(Faulty, &rdev->flags);
|
||||
if (atomic_dec_and_test(&rdev->nr_pending) && faulty)
|
||||
set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
|
||||
}
|
||||
|
||||
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 mdk_personality
|
||||
{
|
||||
char *name;
|
||||
int level;
|
||||
struct list_head list;
|
||||
struct module *owner;
|
||||
int (*make_request)(request_queue_t *q, struct bio *bio);
|
||||
int (*run)(mddev_t *mddev);
|
||||
int (*stop)(mddev_t *mddev);
|
||||
void (*status)(struct seq_file *seq, mddev_t *mddev);
|
||||
/* error_handler must set ->faulty and clear ->in_sync
|
||||
* if appropriate, and should abort recovery if needed
|
||||
*/
|
||||
void (*error_handler)(mddev_t *mddev, mdk_rdev_t *rdev);
|
||||
int (*hot_add_disk) (mddev_t *mddev, mdk_rdev_t *rdev);
|
||||
int (*hot_remove_disk) (mddev_t *mddev, int number);
|
||||
int (*spare_active) (mddev_t *mddev);
|
||||
sector_t (*sync_request)(mddev_t *mddev, sector_t sector_nr, int *skipped, int go_faster);
|
||||
int (*resize) (mddev_t *mddev, sector_t sectors);
|
||||
int (*check_reshape) (mddev_t *mddev);
|
||||
int (*start_reshape) (mddev_t *mddev);
|
||||
int (*reconfig) (mddev_t *mddev, int layout, int chunk_size);
|
||||
/* quiesce moves between quiescence states
|
||||
* 0 - fully active
|
||||
* 1 - no new requests allowed
|
||||
* others - reserved
|
||||
*/
|
||||
void (*quiesce) (mddev_t *mddev, int state);
|
||||
};
|
||||
|
||||
|
||||
struct md_sysfs_entry {
|
||||
struct attribute attr;
|
||||
ssize_t (*show)(mddev_t *, char *);
|
||||
ssize_t (*store)(mddev_t *, const char *, size_t);
|
||||
};
|
||||
|
||||
|
||||
static inline char * mdname (mddev_t * mddev)
|
||||
{
|
||||
return mddev->gendisk ? mddev->gendisk->disk_name : "mdX";
|
||||
}
|
||||
|
||||
/*
|
||||
* iterates through some rdev ringlist. It's safe to remove the
|
||||
* current 'rdev'. Dont touch 'tmp' though.
|
||||
*/
|
||||
#define ITERATE_RDEV_GENERIC(head,rdev,tmp) \
|
||||
\
|
||||
for ((tmp) = (head).next; \
|
||||
(rdev) = (list_entry((tmp), mdk_rdev_t, same_set)), \
|
||||
(tmp) = (tmp)->next, (tmp)->prev != &(head) \
|
||||
; )
|
||||
/*
|
||||
* iterates through the 'same array disks' ringlist
|
||||
*/
|
||||
#define ITERATE_RDEV(mddev,rdev,tmp) \
|
||||
ITERATE_RDEV_GENERIC((mddev)->disks,rdev,tmp)
|
||||
|
||||
/*
|
||||
* Iterates through 'pending RAID disks'
|
||||
*/
|
||||
#define ITERATE_RDEV_PENDING(rdev,tmp) \
|
||||
ITERATE_RDEV_GENERIC(pending_raid_disks,rdev,tmp)
|
||||
|
||||
typedef struct mdk_thread_s {
|
||||
void (*run) (mddev_t *mddev);
|
||||
mddev_t *mddev;
|
||||
wait_queue_head_t wqueue;
|
||||
unsigned long flags;
|
||||
struct task_struct *tsk;
|
||||
unsigned long timeout;
|
||||
} mdk_thread_t;
|
||||
|
||||
#define THREAD_WAKEUP 0
|
||||
|
||||
#define __wait_event_lock_irq(wq, condition, lock, cmd) \
|
||||
do { \
|
||||
wait_queue_t __wait; \
|
||||
init_waitqueue_entry(&__wait, current); \
|
||||
\
|
||||
add_wait_queue(&wq, &__wait); \
|
||||
for (;;) { \
|
||||
set_current_state(TASK_UNINTERRUPTIBLE); \
|
||||
if (condition) \
|
||||
break; \
|
||||
spin_unlock_irq(&lock); \
|
||||
cmd; \
|
||||
schedule(); \
|
||||
spin_lock_irq(&lock); \
|
||||
} \
|
||||
current->state = TASK_RUNNING; \
|
||||
remove_wait_queue(&wq, &__wait); \
|
||||
} while (0)
|
||||
|
||||
#define wait_event_lock_irq(wq, condition, lock, cmd) \
|
||||
do { \
|
||||
if (condition) \
|
||||
break; \
|
||||
__wait_event_lock_irq(wq, condition, lock, cmd); \
|
||||
} while (0)
|
||||
|
||||
static inline void safe_put_page(struct page *p)
|
||||
{
|
||||
if (p) put_page(p);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_BLOCK */
|
||||
#endif
|
||||
|
||||
276
include/linux/raid/md_p.h
Normal file
276
include/linux/raid/md_p.h
Normal file
@@ -0,0 +1,276 @@
|
||||
/*
|
||||
md_p.h : physical layout of Linux RAID devices
|
||||
Copyright (C) 1996-98 Ingo Molnar, Gadi Oxman
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
(for example /usr/src/linux/COPYING); if not, write to the Free
|
||||
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#ifndef _MD_P_H
|
||||
#define _MD_P_H
|
||||
|
||||
/*
|
||||
* RAID superblock.
|
||||
*
|
||||
* The RAID superblock maintains some statistics on each RAID configuration.
|
||||
* Each real device in the RAID set contains it near the end of the device.
|
||||
* Some of the ideas are copied from the ext2fs implementation.
|
||||
*
|
||||
* We currently use 4096 bytes as follows:
|
||||
*
|
||||
* word offset function
|
||||
*
|
||||
* 0 - 31 Constant generic RAID device information.
|
||||
* 32 - 63 Generic state information.
|
||||
* 64 - 127 Personality specific information.
|
||||
* 128 - 511 12 32-words descriptors of the disks in the raid set.
|
||||
* 512 - 911 Reserved.
|
||||
* 912 - 1023 Disk specific descriptor.
|
||||
*/
|
||||
|
||||
/*
|
||||
* If x is the real device size in bytes, we return an apparent size of:
|
||||
*
|
||||
* y = (x & ~(MD_RESERVED_BYTES - 1)) - MD_RESERVED_BYTES
|
||||
*
|
||||
* and place the 4kB superblock at offset y.
|
||||
*/
|
||||
#define MD_RESERVED_BYTES (64 * 1024)
|
||||
#define MD_RESERVED_SECTORS (MD_RESERVED_BYTES / 512)
|
||||
#define MD_RESERVED_BLOCKS (MD_RESERVED_BYTES / BLOCK_SIZE)
|
||||
|
||||
#define MD_NEW_SIZE_SECTORS(x) ((x & ~(MD_RESERVED_SECTORS - 1)) - MD_RESERVED_SECTORS)
|
||||
#define MD_NEW_SIZE_BLOCKS(x) ((x & ~(MD_RESERVED_BLOCKS - 1)) - MD_RESERVED_BLOCKS)
|
||||
|
||||
#define MD_SB_BYTES 4096
|
||||
#define MD_SB_WORDS (MD_SB_BYTES / 4)
|
||||
#define MD_SB_BLOCKS (MD_SB_BYTES / BLOCK_SIZE)
|
||||
#define MD_SB_SECTORS (MD_SB_BYTES / 512)
|
||||
|
||||
/*
|
||||
* The following are counted in 32-bit words
|
||||
*/
|
||||
#define MD_SB_GENERIC_OFFSET 0
|
||||
#define MD_SB_PERSONALITY_OFFSET 64
|
||||
#define MD_SB_DISKS_OFFSET 128
|
||||
#define MD_SB_DESCRIPTOR_OFFSET 992
|
||||
|
||||
#define MD_SB_GENERIC_CONSTANT_WORDS 32
|
||||
#define MD_SB_GENERIC_STATE_WORDS 32
|
||||
#define MD_SB_GENERIC_WORDS (MD_SB_GENERIC_CONSTANT_WORDS + MD_SB_GENERIC_STATE_WORDS)
|
||||
#define MD_SB_PERSONALITY_WORDS 64
|
||||
#define MD_SB_DESCRIPTOR_WORDS 32
|
||||
#define MD_SB_DISKS 27
|
||||
#define MD_SB_DISKS_WORDS (MD_SB_DISKS*MD_SB_DESCRIPTOR_WORDS)
|
||||
#define MD_SB_RESERVED_WORDS (1024 - MD_SB_GENERIC_WORDS - MD_SB_PERSONALITY_WORDS - MD_SB_DISKS_WORDS - MD_SB_DESCRIPTOR_WORDS)
|
||||
#define MD_SB_EQUAL_WORDS (MD_SB_GENERIC_WORDS + MD_SB_PERSONALITY_WORDS + MD_SB_DISKS_WORDS)
|
||||
|
||||
/*
|
||||
* Device "operational" state bits
|
||||
*/
|
||||
#define MD_DISK_FAULTY 0 /* disk is faulty / operational */
|
||||
#define MD_DISK_ACTIVE 1 /* disk is running or spare disk */
|
||||
#define MD_DISK_SYNC 2 /* disk is in sync with the raid set */
|
||||
#define MD_DISK_REMOVED 3 /* disk is in sync with the raid set */
|
||||
|
||||
#define MD_DISK_WRITEMOSTLY 9 /* disk is "write-mostly" is RAID1 config.
|
||||
* read requests will only be sent here in
|
||||
* dire need
|
||||
*/
|
||||
|
||||
typedef struct mdp_device_descriptor_s {
|
||||
__u32 number; /* 0 Device number in the entire set */
|
||||
__u32 major; /* 1 Device major number */
|
||||
__u32 minor; /* 2 Device minor number */
|
||||
__u32 raid_disk; /* 3 The role of the device in the raid set */
|
||||
__u32 state; /* 4 Operational state */
|
||||
__u32 reserved[MD_SB_DESCRIPTOR_WORDS - 5];
|
||||
} mdp_disk_t;
|
||||
|
||||
#define MD_SB_MAGIC 0xa92b4efc
|
||||
|
||||
/*
|
||||
* Superblock state bits
|
||||
*/
|
||||
#define MD_SB_CLEAN 0
|
||||
#define MD_SB_ERRORS 1
|
||||
|
||||
#define MD_SB_BITMAP_PRESENT 8 /* bitmap may be present nearby */
|
||||
|
||||
/*
|
||||
* Notes:
|
||||
* - if an array is being reshaped (restriped) in order to change the
|
||||
* the number of active devices in the array, 'raid_disks' will be
|
||||
* the larger of the old and new numbers. 'delta_disks' will
|
||||
* be the "new - old". So if +ve, raid_disks is the new value, and
|
||||
* "raid_disks-delta_disks" is the old. If -ve, raid_disks is the
|
||||
* old value and "raid_disks+delta_disks" is the new (smaller) value.
|
||||
*/
|
||||
|
||||
|
||||
typedef struct mdp_superblock_s {
|
||||
/*
|
||||
* Constant generic information
|
||||
*/
|
||||
__u32 md_magic; /* 0 MD identifier */
|
||||
__u32 major_version; /* 1 major version to which the set conforms */
|
||||
__u32 minor_version; /* 2 minor version ... */
|
||||
__u32 patch_version; /* 3 patchlevel version ... */
|
||||
__u32 gvalid_words; /* 4 Number of used words in this section */
|
||||
__u32 set_uuid0; /* 5 Raid set identifier */
|
||||
__u32 ctime; /* 6 Creation time */
|
||||
__u32 level; /* 7 Raid personality */
|
||||
__u32 size; /* 8 Apparent size of each individual disk */
|
||||
__u32 nr_disks; /* 9 total disks in the raid set */
|
||||
__u32 raid_disks; /* 10 disks in a fully functional raid set */
|
||||
__u32 md_minor; /* 11 preferred MD minor device number */
|
||||
__u32 not_persistent; /* 12 does it have a persistent superblock */
|
||||
__u32 set_uuid1; /* 13 Raid set identifier #2 */
|
||||
__u32 set_uuid2; /* 14 Raid set identifier #3 */
|
||||
__u32 set_uuid3; /* 15 Raid set identifier #4 */
|
||||
__u32 gstate_creserved[MD_SB_GENERIC_CONSTANT_WORDS - 16];
|
||||
|
||||
/*
|
||||
* Generic state information
|
||||
*/
|
||||
__u32 utime; /* 0 Superblock update time */
|
||||
__u32 state; /* 1 State bits (clean, ...) */
|
||||
__u32 active_disks; /* 2 Number of currently active disks */
|
||||
__u32 working_disks; /* 3 Number of working disks */
|
||||
__u32 failed_disks; /* 4 Number of failed disks */
|
||||
__u32 spare_disks; /* 5 Number of spare disks */
|
||||
__u32 sb_csum; /* 6 checksum of the whole superblock */
|
||||
#ifdef __BIG_ENDIAN
|
||||
__u32 events_hi; /* 7 high-order of superblock update count */
|
||||
__u32 events_lo; /* 8 low-order of superblock update count */
|
||||
__u32 cp_events_hi; /* 9 high-order of checkpoint update count */
|
||||
__u32 cp_events_lo; /* 10 low-order of checkpoint update count */
|
||||
#else
|
||||
__u32 events_lo; /* 7 low-order of superblock update count */
|
||||
__u32 events_hi; /* 8 high-order of superblock update count */
|
||||
__u32 cp_events_lo; /* 9 low-order of checkpoint update count */
|
||||
__u32 cp_events_hi; /* 10 high-order of checkpoint update count */
|
||||
#endif
|
||||
__u32 recovery_cp; /* 11 recovery checkpoint sector count */
|
||||
/* There are only valid for minor_version > 90 */
|
||||
__u64 reshape_position; /* 12,13 next address in array-space for reshape */
|
||||
__u32 new_level; /* 14 new level we are reshaping to */
|
||||
__u32 delta_disks; /* 15 change in number of raid_disks */
|
||||
__u32 new_layout; /* 16 new layout */
|
||||
__u32 new_chunk; /* 17 new chunk size (bytes) */
|
||||
__u32 gstate_sreserved[MD_SB_GENERIC_STATE_WORDS - 18];
|
||||
|
||||
/*
|
||||
* Personality information
|
||||
*/
|
||||
__u32 layout; /* 0 the array's physical layout */
|
||||
__u32 chunk_size; /* 1 chunk size in bytes */
|
||||
__u32 root_pv; /* 2 LV root PV */
|
||||
__u32 root_block; /* 3 LV root block */
|
||||
__u32 pstate_reserved[MD_SB_PERSONALITY_WORDS - 4];
|
||||
|
||||
/*
|
||||
* Disks information
|
||||
*/
|
||||
mdp_disk_t disks[MD_SB_DISKS];
|
||||
|
||||
/*
|
||||
* Reserved
|
||||
*/
|
||||
__u32 reserved[MD_SB_RESERVED_WORDS];
|
||||
|
||||
/*
|
||||
* Active descriptor
|
||||
*/
|
||||
mdp_disk_t this_disk;
|
||||
|
||||
} mdp_super_t;
|
||||
|
||||
static inline __u64 md_event(mdp_super_t *sb) {
|
||||
__u64 ev = sb->events_hi;
|
||||
return (ev<<32)| sb->events_lo;
|
||||
}
|
||||
|
||||
/*
|
||||
* The version-1 superblock :
|
||||
* All numeric fields are little-endian.
|
||||
*
|
||||
* total size: 256 bytes plus 2 per device.
|
||||
* 1K allows 384 devices.
|
||||
*/
|
||||
struct mdp_superblock_1 {
|
||||
/* constant array information - 128 bytes */
|
||||
__le32 magic; /* MD_SB_MAGIC: 0xa92b4efc - little endian */
|
||||
__le32 major_version; /* 1 */
|
||||
__le32 feature_map; /* bit 0 set if 'bitmap_offset' is meaningful */
|
||||
__le32 pad0; /* always set to 0 when writing */
|
||||
|
||||
__u8 set_uuid[16]; /* user-space generated. */
|
||||
char set_name[32]; /* set and interpreted by user-space */
|
||||
|
||||
__le64 ctime; /* lo 40 bits are seconds, top 24 are microseconds or 0*/
|
||||
__le32 level; /* -4 (multipath), -1 (linear), 0,1,4,5 */
|
||||
__le32 layout; /* only for raid5 and raid10 currently */
|
||||
__le64 size; /* used size of component devices, in 512byte sectors */
|
||||
|
||||
__le32 chunksize; /* in 512byte sectors */
|
||||
__le32 raid_disks;
|
||||
__le32 bitmap_offset; /* sectors after start of superblock that bitmap starts
|
||||
* NOTE: signed, so bitmap can be before superblock
|
||||
* only meaningful of feature_map[0] is set.
|
||||
*/
|
||||
|
||||
/* These are only valid with feature bit '4' */
|
||||
__le32 new_level; /* new level we are reshaping to */
|
||||
__le64 reshape_position; /* next address in array-space for reshape */
|
||||
__le32 delta_disks; /* change in number of raid_disks */
|
||||
__le32 new_layout; /* new layout */
|
||||
__le32 new_chunk; /* new chunk size (bytes) */
|
||||
__u8 pad1[128-124]; /* set to 0 when written */
|
||||
|
||||
/* constant this-device information - 64 bytes */
|
||||
__le64 data_offset; /* sector start of data, often 0 */
|
||||
__le64 data_size; /* sectors in this device that can be used for data */
|
||||
__le64 super_offset; /* sector start of this superblock */
|
||||
__le64 recovery_offset;/* sectors before this offset (from data_offset) have been recovered */
|
||||
__le32 dev_number; /* permanent identifier of this device - not role in raid */
|
||||
__le32 cnt_corrected_read; /* number of read errors that were corrected by re-writing */
|
||||
__u8 device_uuid[16]; /* user-space setable, ignored by kernel */
|
||||
__u8 devflags; /* per-device flags. Only one defined...*/
|
||||
#define WriteMostly1 1 /* mask for writemostly flag in above */
|
||||
__u8 pad2[64-57]; /* set to 0 when writing */
|
||||
|
||||
/* array state information - 64 bytes */
|
||||
__le64 utime; /* 40 bits second, 24 btes microseconds */
|
||||
__le64 events; /* incremented when superblock updated */
|
||||
__le64 resync_offset; /* data before this offset (from data_offset) known to be in sync */
|
||||
__le32 sb_csum; /* checksum upto devs[max_dev] */
|
||||
__le32 max_dev; /* size of devs[] array to consider */
|
||||
__u8 pad3[64-32]; /* set to 0 when writing */
|
||||
|
||||
/* device state information. Indexed by dev_number.
|
||||
* 2 bytes per device
|
||||
* Note there are no per-device state flags. State information is rolled
|
||||
* into the 'roles' value. If a device is spare or faulty, then it doesn't
|
||||
* have a meaningful role.
|
||||
*/
|
||||
__le16 dev_roles[0]; /* role in array, or 0xffff for a spare, or 0xfffe for faulty */
|
||||
};
|
||||
|
||||
/* feature_map bits */
|
||||
#define MD_FEATURE_BITMAP_OFFSET 1
|
||||
#define MD_FEATURE_RECOVERY_OFFSET 2 /* recovery_offset is present and
|
||||
* must be honoured
|
||||
*/
|
||||
#define MD_FEATURE_RESHAPE_ACTIVE 4
|
||||
|
||||
#define MD_FEATURE_ALL (1|2|4)
|
||||
|
||||
#endif
|
||||
|
||||
124
include/linux/raid/md_u.h
Normal file
124
include/linux/raid/md_u.h
Normal file
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
md_u.h : user <=> kernel API between Linux raidtools and RAID drivers
|
||||
Copyright (C) 1998 Ingo Molnar
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
(for example /usr/src/linux/COPYING); if not, write to the Free
|
||||
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#ifndef _MD_U_H
|
||||
#define _MD_U_H
|
||||
|
||||
/* ioctls */
|
||||
|
||||
/* status */
|
||||
#define RAID_VERSION _IOR (MD_MAJOR, 0x10, mdu_version_t)
|
||||
#define GET_ARRAY_INFO _IOR (MD_MAJOR, 0x11, mdu_array_info_t)
|
||||
#define GET_DISK_INFO _IOR (MD_MAJOR, 0x12, mdu_disk_info_t)
|
||||
#define PRINT_RAID_DEBUG _IO (MD_MAJOR, 0x13)
|
||||
#define RAID_AUTORUN _IO (MD_MAJOR, 0x14)
|
||||
#define GET_BITMAP_FILE _IOR (MD_MAJOR, 0x15, mdu_bitmap_file_t)
|
||||
|
||||
/* configuration */
|
||||
#define CLEAR_ARRAY _IO (MD_MAJOR, 0x20)
|
||||
#define ADD_NEW_DISK _IOW (MD_MAJOR, 0x21, mdu_disk_info_t)
|
||||
#define HOT_REMOVE_DISK _IO (MD_MAJOR, 0x22)
|
||||
#define SET_ARRAY_INFO _IOW (MD_MAJOR, 0x23, mdu_array_info_t)
|
||||
#define SET_DISK_INFO _IO (MD_MAJOR, 0x24)
|
||||
#define WRITE_RAID_INFO _IO (MD_MAJOR, 0x25)
|
||||
#define UNPROTECT_ARRAY _IO (MD_MAJOR, 0x26)
|
||||
#define PROTECT_ARRAY _IO (MD_MAJOR, 0x27)
|
||||
#define HOT_ADD_DISK _IO (MD_MAJOR, 0x28)
|
||||
#define SET_DISK_FAULTY _IO (MD_MAJOR, 0x29)
|
||||
#define HOT_GENERATE_ERROR _IO (MD_MAJOR, 0x2a)
|
||||
#define SET_BITMAP_FILE _IOW (MD_MAJOR, 0x2b, int)
|
||||
|
||||
/* usage */
|
||||
#define RUN_ARRAY _IOW (MD_MAJOR, 0x30, mdu_param_t)
|
||||
/* 0x31 was START_ARRAY */
|
||||
#define STOP_ARRAY _IO (MD_MAJOR, 0x32)
|
||||
#define STOP_ARRAY_RO _IO (MD_MAJOR, 0x33)
|
||||
#define RESTART_ARRAY_RW _IO (MD_MAJOR, 0x34)
|
||||
|
||||
typedef struct mdu_version_s {
|
||||
int major;
|
||||
int minor;
|
||||
int patchlevel;
|
||||
} mdu_version_t;
|
||||
|
||||
typedef struct mdu_array_info_s {
|
||||
/*
|
||||
* Generic constant information
|
||||
*/
|
||||
int major_version;
|
||||
int minor_version;
|
||||
int patch_version;
|
||||
int ctime;
|
||||
int level;
|
||||
int size;
|
||||
int nr_disks;
|
||||
int raid_disks;
|
||||
int md_minor;
|
||||
int not_persistent;
|
||||
|
||||
/*
|
||||
* Generic state information
|
||||
*/
|
||||
int utime; /* 0 Superblock update time */
|
||||
int state; /* 1 State bits (clean, ...) */
|
||||
int active_disks; /* 2 Number of currently active disks */
|
||||
int working_disks; /* 3 Number of working disks */
|
||||
int failed_disks; /* 4 Number of failed disks */
|
||||
int spare_disks; /* 5 Number of spare disks */
|
||||
|
||||
/*
|
||||
* Personality information
|
||||
*/
|
||||
int layout; /* 0 the array's physical layout */
|
||||
int chunk_size; /* 1 chunk size in bytes */
|
||||
|
||||
} mdu_array_info_t;
|
||||
|
||||
typedef struct mdu_disk_info_s {
|
||||
/*
|
||||
* configuration/status of one particular disk
|
||||
*/
|
||||
int number;
|
||||
int major;
|
||||
int minor;
|
||||
int raid_disk;
|
||||
int state;
|
||||
|
||||
} mdu_disk_info_t;
|
||||
|
||||
typedef struct mdu_start_info_s {
|
||||
/*
|
||||
* configuration/status of one particular disk
|
||||
*/
|
||||
int major;
|
||||
int minor;
|
||||
int raid_disk;
|
||||
int state;
|
||||
|
||||
} mdu_start_info_t;
|
||||
|
||||
typedef struct mdu_bitmap_file_s
|
||||
{
|
||||
char pathname[4096];
|
||||
} mdu_bitmap_file_t;
|
||||
|
||||
typedef struct mdu_param_s
|
||||
{
|
||||
int personality; /* 1,2,3,4 */
|
||||
int chunk_size; /* in bytes */
|
||||
int max_fault; /* unused for now */
|
||||
} mdu_param_t;
|
||||
|
||||
#endif
|
||||
|
||||
42
include/linux/raid/multipath.h
Normal file
42
include/linux/raid/multipath.h
Normal file
@@ -0,0 +1,42 @@
|
||||
#ifndef _MULTIPATH_H
|
||||
#define _MULTIPATH_H
|
||||
|
||||
#include <linux/raid/md.h>
|
||||
|
||||
struct multipath_info {
|
||||
mdk_rdev_t *rdev;
|
||||
};
|
||||
|
||||
struct multipath_private_data {
|
||||
mddev_t *mddev;
|
||||
struct multipath_info *multipaths;
|
||||
int raid_disks;
|
||||
int working_disks;
|
||||
spinlock_t device_lock;
|
||||
struct list_head retry_list;
|
||||
|
||||
mempool_t *pool;
|
||||
};
|
||||
|
||||
typedef struct multipath_private_data multipath_conf_t;
|
||||
|
||||
/*
|
||||
* this is the only point in the RAID code where we violate
|
||||
* C type safety. mddev->private is an 'opaque' pointer.
|
||||
*/
|
||||
#define mddev_to_conf(mddev) ((multipath_conf_t *) mddev->private)
|
||||
|
||||
/*
|
||||
* this is our 'private' 'collective' MULTIPATH buffer head.
|
||||
* it contains information about what kind of IO operations were started
|
||||
* for this MULTIPATH operation, and about their status:
|
||||
*/
|
||||
|
||||
struct multipath_bh {
|
||||
mddev_t *mddev;
|
||||
struct bio *master_bio;
|
||||
struct bio bio;
|
||||
int path;
|
||||
struct list_head retry_list;
|
||||
};
|
||||
#endif
|
||||
30
include/linux/raid/raid0.h
Normal file
30
include/linux/raid/raid0.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#ifndef _RAID0_H
|
||||
#define _RAID0_H
|
||||
|
||||
#include <linux/raid/md.h>
|
||||
|
||||
struct strip_zone
|
||||
{
|
||||
sector_t zone_offset; /* Zone offset in md_dev */
|
||||
sector_t dev_offset; /* Zone offset in real dev */
|
||||
sector_t size; /* Zone size */
|
||||
int nb_dev; /* # of devices attached to the zone */
|
||||
mdk_rdev_t **dev; /* Devices attached to the zone */
|
||||
};
|
||||
|
||||
struct raid0_private_data
|
||||
{
|
||||
struct strip_zone **hash_table; /* Table of indexes into strip_zone */
|
||||
struct strip_zone *strip_zone;
|
||||
mdk_rdev_t **devlist; /* lists of rdevs, pointed to by strip_zone->dev */
|
||||
int nr_strip_zones;
|
||||
|
||||
sector_t hash_spacing;
|
||||
int preshift; /* shift this before divide by hash_spacing */
|
||||
};
|
||||
|
||||
typedef struct raid0_private_data raid0_conf_t;
|
||||
|
||||
#define mddev_to_conf(mddev) ((raid0_conf_t *) mddev->private)
|
||||
|
||||
#endif
|
||||
134
include/linux/raid/raid1.h
Normal file
134
include/linux/raid/raid1.h
Normal file
@@ -0,0 +1,134 @@
|
||||
#ifndef _RAID1_H
|
||||
#define _RAID1_H
|
||||
|
||||
#include <linux/raid/md.h>
|
||||
|
||||
typedef struct mirror_info mirror_info_t;
|
||||
|
||||
struct mirror_info {
|
||||
mdk_rdev_t *rdev;
|
||||
sector_t head_position;
|
||||
};
|
||||
|
||||
/*
|
||||
* memory pools need a pointer to the mddev, so they can force an unplug
|
||||
* when memory is tight, and a count of the number of drives that the
|
||||
* pool was allocated for, so they know how much to allocate and free.
|
||||
* mddev->raid_disks cannot be used, as it can change while a pool is active
|
||||
* These two datums are stored in a kmalloced struct.
|
||||
*/
|
||||
|
||||
struct pool_info {
|
||||
mddev_t *mddev;
|
||||
int raid_disks;
|
||||
};
|
||||
|
||||
|
||||
typedef struct r1bio_s r1bio_t;
|
||||
|
||||
struct r1_private_data_s {
|
||||
mddev_t *mddev;
|
||||
mirror_info_t *mirrors;
|
||||
int raid_disks;
|
||||
int last_used;
|
||||
sector_t next_seq_sect;
|
||||
spinlock_t device_lock;
|
||||
|
||||
struct list_head retry_list;
|
||||
/* queue pending writes and submit them on unplug */
|
||||
struct bio_list pending_bio_list;
|
||||
/* queue of writes that have been unplugged */
|
||||
struct bio_list flushing_bio_list;
|
||||
|
||||
/* for use when syncing mirrors: */
|
||||
|
||||
spinlock_t resync_lock;
|
||||
int nr_pending;
|
||||
int nr_waiting;
|
||||
int nr_queued;
|
||||
int barrier;
|
||||
sector_t next_resync;
|
||||
int fullsync; /* set to 1 if a full sync is needed,
|
||||
* (fresh device added).
|
||||
* Cleared when a sync completes.
|
||||
*/
|
||||
|
||||
wait_queue_head_t wait_barrier;
|
||||
|
||||
struct pool_info *poolinfo;
|
||||
|
||||
struct page *tmppage;
|
||||
|
||||
mempool_t *r1bio_pool;
|
||||
mempool_t *r1buf_pool;
|
||||
};
|
||||
|
||||
typedef struct r1_private_data_s conf_t;
|
||||
|
||||
/*
|
||||
* this is the only point in the RAID code where we violate
|
||||
* C type safety. mddev->private is an 'opaque' pointer.
|
||||
*/
|
||||
#define mddev_to_conf(mddev) ((conf_t *) mddev->private)
|
||||
|
||||
/*
|
||||
* this is our 'private' RAID1 bio.
|
||||
*
|
||||
* it contains information about what kind of IO operations were started
|
||||
* for this RAID1 operation, and about their status:
|
||||
*/
|
||||
|
||||
struct r1bio_s {
|
||||
atomic_t remaining; /* 'have we finished' count,
|
||||
* used from IRQ handlers
|
||||
*/
|
||||
atomic_t behind_remaining; /* number of write-behind ios remaining
|
||||
* in this BehindIO request
|
||||
*/
|
||||
sector_t sector;
|
||||
int sectors;
|
||||
unsigned long state;
|
||||
mddev_t *mddev;
|
||||
/*
|
||||
* original bio going to /dev/mdx
|
||||
*/
|
||||
struct bio *master_bio;
|
||||
/*
|
||||
* if the IO is in READ direction, then this is where we read
|
||||
*/
|
||||
int read_disk;
|
||||
|
||||
struct list_head retry_list;
|
||||
struct bitmap_update *bitmap_update;
|
||||
/*
|
||||
* if the IO is in WRITE direction, then multiple bios are used.
|
||||
* We choose the number when they are allocated.
|
||||
*/
|
||||
struct bio *bios[0];
|
||||
/* DO NOT PUT ANY NEW FIELDS HERE - bios array is contiguously alloced*/
|
||||
};
|
||||
|
||||
/* when we get a read error on a read-only array, we redirect to another
|
||||
* device without failing the first device, or trying to over-write to
|
||||
* correct the read error. To keep track of bad blocks on a per-bio
|
||||
* level, we store IO_BLOCKED in the appropriate 'bios' pointer
|
||||
*/
|
||||
#define IO_BLOCKED ((struct bio*)1)
|
||||
|
||||
/* bits for r1bio.state */
|
||||
#define R1BIO_Uptodate 0
|
||||
#define R1BIO_IsSync 1
|
||||
#define R1BIO_Degraded 2
|
||||
#define R1BIO_BehindIO 3
|
||||
#define R1BIO_Barrier 4
|
||||
#define R1BIO_BarrierRetry 5
|
||||
/* For write-behind requests, we call bi_end_io when
|
||||
* the last non-write-behind device completes, providing
|
||||
* any write was successful. Otherwise we call when
|
||||
* any write-behind write succeeds, otherwise we call
|
||||
* with failure when last write completes (and all failed).
|
||||
* Record that bi_end_io was called with this flag...
|
||||
*/
|
||||
#define R1BIO_Returned 6
|
||||
|
||||
#endif
|
||||
123
include/linux/raid/raid10.h
Normal file
123
include/linux/raid/raid10.h
Normal file
@@ -0,0 +1,123 @@
|
||||
#ifndef _RAID10_H
|
||||
#define _RAID10_H
|
||||
|
||||
#include <linux/raid/md.h>
|
||||
|
||||
typedef struct mirror_info mirror_info_t;
|
||||
|
||||
struct mirror_info {
|
||||
mdk_rdev_t *rdev;
|
||||
sector_t head_position;
|
||||
};
|
||||
|
||||
typedef struct r10bio_s r10bio_t;
|
||||
|
||||
struct r10_private_data_s {
|
||||
mddev_t *mddev;
|
||||
mirror_info_t *mirrors;
|
||||
int raid_disks;
|
||||
spinlock_t device_lock;
|
||||
|
||||
/* geometry */
|
||||
int near_copies; /* number of copies layed out raid0 style */
|
||||
int far_copies; /* number of copies layed out
|
||||
* at large strides across drives
|
||||
*/
|
||||
int far_offset; /* far_copies are offset by 1 stripe
|
||||
* instead of many
|
||||
*/
|
||||
int copies; /* near_copies * far_copies.
|
||||
* must be <= raid_disks
|
||||
*/
|
||||
sector_t stride; /* distance between far copies.
|
||||
* This is size / far_copies unless
|
||||
* far_offset, in which case it is
|
||||
* 1 stripe.
|
||||
*/
|
||||
|
||||
int chunk_shift; /* shift from chunks to sectors */
|
||||
sector_t chunk_mask;
|
||||
|
||||
struct list_head retry_list;
|
||||
/* queue pending writes and submit them on unplug */
|
||||
struct bio_list pending_bio_list;
|
||||
|
||||
|
||||
spinlock_t resync_lock;
|
||||
int nr_pending;
|
||||
int nr_waiting;
|
||||
int nr_queued;
|
||||
int barrier;
|
||||
sector_t next_resync;
|
||||
int fullsync; /* set to 1 if a full sync is needed,
|
||||
* (fresh device added).
|
||||
* Cleared when a sync completes.
|
||||
*/
|
||||
|
||||
wait_queue_head_t wait_barrier;
|
||||
|
||||
mempool_t *r10bio_pool;
|
||||
mempool_t *r10buf_pool;
|
||||
struct page *tmppage;
|
||||
};
|
||||
|
||||
typedef struct r10_private_data_s conf_t;
|
||||
|
||||
/*
|
||||
* this is the only point in the RAID code where we violate
|
||||
* C type safety. mddev->private is an 'opaque' pointer.
|
||||
*/
|
||||
#define mddev_to_conf(mddev) ((conf_t *) mddev->private)
|
||||
|
||||
/*
|
||||
* this is our 'private' RAID10 bio.
|
||||
*
|
||||
* it contains information about what kind of IO operations were started
|
||||
* for this RAID10 operation, and about their status:
|
||||
*/
|
||||
|
||||
struct r10bio_s {
|
||||
atomic_t remaining; /* 'have we finished' count,
|
||||
* used from IRQ handlers
|
||||
*/
|
||||
sector_t sector; /* virtual sector number */
|
||||
int sectors;
|
||||
unsigned long state;
|
||||
mddev_t *mddev;
|
||||
/*
|
||||
* original bio going to /dev/mdx
|
||||
*/
|
||||
struct bio *master_bio;
|
||||
/*
|
||||
* if the IO is in READ direction, then this is where we read
|
||||
*/
|
||||
int read_slot;
|
||||
|
||||
struct list_head retry_list;
|
||||
/*
|
||||
* if the IO is in WRITE direction, then multiple bios are used,
|
||||
* one for each copy.
|
||||
* When resyncing we also use one for each copy.
|
||||
* When reconstructing, we use 2 bios, one for read, one for write.
|
||||
* We choose the number when they are allocated.
|
||||
*/
|
||||
struct {
|
||||
struct bio *bio;
|
||||
sector_t addr;
|
||||
int devnum;
|
||||
} devs[0];
|
||||
};
|
||||
|
||||
/* when we get a read error on a read-only array, we redirect to another
|
||||
* device without failing the first device, or trying to over-write to
|
||||
* correct the read error. To keep track of bad blocks on a per-bio
|
||||
* level, we store IO_BLOCKED in the appropriate 'bios' pointer
|
||||
*/
|
||||
#define IO_BLOCKED ((struct bio*)1)
|
||||
|
||||
/* bits for r10bio.state */
|
||||
#define R10BIO_Uptodate 0
|
||||
#define R10BIO_IsSync 1
|
||||
#define R10BIO_IsRecover 2
|
||||
#define R10BIO_Degraded 3
|
||||
#endif
|
||||
280
include/linux/raid/raid5.h
Normal file
280
include/linux/raid/raid5.h
Normal file
@@ -0,0 +1,280 @@
|
||||
#ifndef _RAID5_H
|
||||
#define _RAID5_H
|
||||
|
||||
#include <linux/raid/md.h>
|
||||
#include <linux/raid/xor.h>
|
||||
|
||||
/*
|
||||
*
|
||||
* Each stripe contains one buffer per disc. Each buffer can be in
|
||||
* one of a number of states stored in "flags". Changes between
|
||||
* these states happen *almost* exclusively under a per-stripe
|
||||
* spinlock. Some very specific changes can happen in bi_end_io, and
|
||||
* these are not protected by the spin lock.
|
||||
*
|
||||
* The flag bits that are used to represent these states are:
|
||||
* R5_UPTODATE and R5_LOCKED
|
||||
*
|
||||
* State Empty == !UPTODATE, !LOCK
|
||||
* We have no data, and there is no active request
|
||||
* State Want == !UPTODATE, LOCK
|
||||
* A read request is being submitted for this block
|
||||
* State Dirty == UPTODATE, LOCK
|
||||
* Some new data is in this buffer, and it is being written out
|
||||
* State Clean == UPTODATE, !LOCK
|
||||
* We have valid data which is the same as on disc
|
||||
*
|
||||
* The possible state transitions are:
|
||||
*
|
||||
* Empty -> Want - on read or write to get old data for parity calc
|
||||
* Empty -> Dirty - on compute_parity to satisfy write/sync request.(RECONSTRUCT_WRITE)
|
||||
* Empty -> Clean - on compute_block when computing a block for failed drive
|
||||
* Want -> Empty - on failed read
|
||||
* Want -> Clean - on successful completion of read request
|
||||
* Dirty -> Clean - on successful completion of write request
|
||||
* Dirty -> Clean - on failed write
|
||||
* Clean -> Dirty - on compute_parity to satisfy write/sync (RECONSTRUCT or RMW)
|
||||
*
|
||||
* The Want->Empty, Want->Clean, Dirty->Clean, transitions
|
||||
* all happen in b_end_io at interrupt time.
|
||||
* Each sets the Uptodate bit before releasing the Lock bit.
|
||||
* This leaves one multi-stage transition:
|
||||
* Want->Dirty->Clean
|
||||
* This is safe because thinking that a Clean buffer is actually dirty
|
||||
* will at worst delay some action, and the stripe will be scheduled
|
||||
* for attention after the transition is complete.
|
||||
*
|
||||
* There is one possibility that is not covered by these states. That
|
||||
* is if one drive has failed and there is a spare being rebuilt. We
|
||||
* can't distinguish between a clean block that has been generated
|
||||
* from parity calculations, and a clean block that has been
|
||||
* successfully written to the spare ( or to parity when resyncing).
|
||||
* To distingush these states we have a stripe bit STRIPE_INSYNC that
|
||||
* is set whenever a write is scheduled to the spare, or to the parity
|
||||
* disc if there is no spare. A sync request clears this bit, and
|
||||
* when we find it set with no buffers locked, we know the sync is
|
||||
* complete.
|
||||
*
|
||||
* Buffers for the md device that arrive via make_request are attached
|
||||
* to the appropriate stripe in one of two lists linked on b_reqnext.
|
||||
* One list (bh_read) for read requests, one (bh_write) for write.
|
||||
* There should never be more than one buffer on the two lists
|
||||
* together, but we are not guaranteed of that so we allow for more.
|
||||
*
|
||||
* If a buffer is on the read list when the associated cache buffer is
|
||||
* Uptodate, the data is copied into the read buffer and it's b_end_io
|
||||
* routine is called. This may happen in the end_request routine only
|
||||
* if the buffer has just successfully been read. end_request should
|
||||
* remove the buffers from the list and then set the Uptodate bit on
|
||||
* the buffer. Other threads may do this only if they first check
|
||||
* that the Uptodate bit is set. Once they have checked that they may
|
||||
* take buffers off the read queue.
|
||||
*
|
||||
* When a buffer on the write list is committed for write it is copied
|
||||
* into the cache buffer, which is then marked dirty, and moved onto a
|
||||
* third list, the written list (bh_written). Once both the parity
|
||||
* block and the cached buffer are successfully written, any buffer on
|
||||
* a written list can be returned with b_end_io.
|
||||
*
|
||||
* The write list and read list both act as fifos. The read list is
|
||||
* protected by the device_lock. The write and written lists are
|
||||
* protected by the stripe lock. The device_lock, which can be
|
||||
* claimed while the stipe lock is held, is only for list
|
||||
* manipulations and will only be held for a very short time. It can
|
||||
* be claimed from interrupts.
|
||||
*
|
||||
*
|
||||
* Stripes in the stripe cache can be on one of two lists (or on
|
||||
* neither). The "inactive_list" contains stripes which are not
|
||||
* currently being used for any request. They can freely be reused
|
||||
* for another stripe. The "handle_list" contains stripes that need
|
||||
* to be handled in some way. Both of these are fifo queues. Each
|
||||
* stripe is also (potentially) linked to a hash bucket in the hash
|
||||
* table so that it can be found by sector number. Stripes that are
|
||||
* not hashed must be on the inactive_list, and will normally be at
|
||||
* the front. All stripes start life this way.
|
||||
*
|
||||
* The inactive_list, handle_list and hash bucket lists are all protected by the
|
||||
* device_lock.
|
||||
* - stripes on the inactive_list never have their stripe_lock held.
|
||||
* - stripes have a reference counter. If count==0, they are on a list.
|
||||
* - If a stripe might need handling, STRIPE_HANDLE is set.
|
||||
* - When refcount reaches zero, then if STRIPE_HANDLE it is put on
|
||||
* handle_list else inactive_list
|
||||
*
|
||||
* This, combined with the fact that STRIPE_HANDLE is only ever
|
||||
* cleared while a stripe has a non-zero count means that if the
|
||||
* refcount is 0 and STRIPE_HANDLE is set, then it is on the
|
||||
* handle_list and if recount is 0 and STRIPE_HANDLE is not set, then
|
||||
* the stripe is on inactive_list.
|
||||
*
|
||||
* The possible transitions are:
|
||||
* activate an unhashed/inactive stripe (get_active_stripe())
|
||||
* lockdev check-hash unlink-stripe cnt++ clean-stripe hash-stripe unlockdev
|
||||
* activate a hashed, possibly active stripe (get_active_stripe())
|
||||
* lockdev check-hash if(!cnt++)unlink-stripe unlockdev
|
||||
* attach a request to an active stripe (add_stripe_bh())
|
||||
* lockdev attach-buffer unlockdev
|
||||
* handle a stripe (handle_stripe())
|
||||
* lockstripe clrSTRIPE_HANDLE ... (lockdev check-buffers unlockdev) .. change-state .. record io needed unlockstripe schedule io
|
||||
* release an active stripe (release_stripe())
|
||||
* lockdev if (!--cnt) { if STRIPE_HANDLE, add to handle_list else add to inactive-list } unlockdev
|
||||
*
|
||||
* The refcount counts each thread that have activated the stripe,
|
||||
* plus raid5d if it is handling it, plus one for each active request
|
||||
* on a cached buffer.
|
||||
*/
|
||||
|
||||
struct stripe_head {
|
||||
struct hlist_node hash;
|
||||
struct list_head lru; /* inactive_list or handle_list */
|
||||
struct raid5_private_data *raid_conf;
|
||||
sector_t sector; /* sector of this row */
|
||||
int pd_idx; /* parity disk index */
|
||||
unsigned long state; /* state flags */
|
||||
atomic_t count; /* nr of active thread/requests */
|
||||
spinlock_t lock;
|
||||
int bm_seq; /* sequence number for bitmap flushes */
|
||||
int disks; /* disks in stripe */
|
||||
struct r5dev {
|
||||
struct bio req;
|
||||
struct bio_vec vec;
|
||||
struct page *page;
|
||||
struct bio *toread, *towrite, *written;
|
||||
sector_t sector; /* sector of this page */
|
||||
unsigned long flags;
|
||||
} dev[1]; /* allocated with extra space depending of RAID geometry */
|
||||
};
|
||||
/* Flags */
|
||||
#define R5_UPTODATE 0 /* page contains current data */
|
||||
#define R5_LOCKED 1 /* IO has been submitted on "req" */
|
||||
#define R5_OVERWRITE 2 /* towrite covers whole page */
|
||||
/* and some that are internal to handle_stripe */
|
||||
#define R5_Insync 3 /* rdev && rdev->in_sync at start */
|
||||
#define R5_Wantread 4 /* want to schedule a read */
|
||||
#define R5_Wantwrite 5
|
||||
#define R5_Overlap 7 /* There is a pending overlapping request on this block */
|
||||
#define R5_ReadError 8 /* seen a read error here recently */
|
||||
#define R5_ReWrite 9 /* have tried to over-write the readerror */
|
||||
|
||||
#define R5_Expanded 10 /* This block now has post-expand data */
|
||||
/*
|
||||
* Write method
|
||||
*/
|
||||
#define RECONSTRUCT_WRITE 1
|
||||
#define READ_MODIFY_WRITE 2
|
||||
/* not a write method, but a compute_parity mode */
|
||||
#define CHECK_PARITY 3
|
||||
|
||||
/*
|
||||
* Stripe state
|
||||
*/
|
||||
#define STRIPE_HANDLE 2
|
||||
#define STRIPE_SYNCING 3
|
||||
#define STRIPE_INSYNC 4
|
||||
#define STRIPE_PREREAD_ACTIVE 5
|
||||
#define STRIPE_DELAYED 6
|
||||
#define STRIPE_DEGRADED 7
|
||||
#define STRIPE_BIT_DELAY 8
|
||||
#define STRIPE_EXPANDING 9
|
||||
#define STRIPE_EXPAND_SOURCE 10
|
||||
#define STRIPE_EXPAND_READY 11
|
||||
/*
|
||||
* Plugging:
|
||||
*
|
||||
* To improve write throughput, we need to delay the handling of some
|
||||
* stripes until there has been a chance that several write requests
|
||||
* for the one stripe have all been collected.
|
||||
* In particular, any write request that would require pre-reading
|
||||
* is put on a "delayed" queue until there are no stripes currently
|
||||
* in a pre-read phase. Further, if the "delayed" queue is empty when
|
||||
* a stripe is put on it then we "plug" the queue and do not process it
|
||||
* until an unplug call is made. (the unplug_io_fn() is called).
|
||||
*
|
||||
* When preread is initiated on a stripe, we set PREREAD_ACTIVE and add
|
||||
* it to the count of prereading stripes.
|
||||
* When write is initiated, or the stripe refcnt == 0 (just in case) we
|
||||
* clear the PREREAD_ACTIVE flag and decrement the count
|
||||
* Whenever the 'handle' queue is empty and the device is not plugged, we
|
||||
* move any strips from delayed to handle and clear the DELAYED flag and set
|
||||
* PREREAD_ACTIVE.
|
||||
* In stripe_handle, if we find pre-reading is necessary, we do it if
|
||||
* PREREAD_ACTIVE is set, else we set DELAYED which will send it to the delayed queue.
|
||||
* HANDLE gets cleared if stripe_handle leave nothing locked.
|
||||
*/
|
||||
|
||||
|
||||
struct disk_info {
|
||||
mdk_rdev_t *rdev;
|
||||
};
|
||||
|
||||
struct raid5_private_data {
|
||||
struct hlist_head *stripe_hashtbl;
|
||||
mddev_t *mddev;
|
||||
struct disk_info *spare;
|
||||
int chunk_size, level, algorithm;
|
||||
int max_degraded;
|
||||
int raid_disks;
|
||||
int max_nr_stripes;
|
||||
|
||||
/* used during an expand */
|
||||
sector_t expand_progress; /* MaxSector when no expand happening */
|
||||
sector_t expand_lo; /* from here up to expand_progress it out-of-bounds
|
||||
* as we haven't flushed the metadata yet
|
||||
*/
|
||||
int previous_raid_disks;
|
||||
|
||||
struct list_head handle_list; /* stripes needing handling */
|
||||
struct list_head delayed_list; /* stripes that have plugged requests */
|
||||
struct list_head bitmap_list; /* stripes delaying awaiting bitmap update */
|
||||
struct bio *retry_read_aligned; /* currently retrying aligned bios */
|
||||
struct bio *retry_read_aligned_list; /* aligned bios retry list */
|
||||
atomic_t preread_active_stripes; /* stripes with scheduled io */
|
||||
atomic_t active_aligned_reads;
|
||||
|
||||
atomic_t reshape_stripes; /* stripes with pending writes for reshape */
|
||||
/* unfortunately we need two cache names as we temporarily have
|
||||
* two caches.
|
||||
*/
|
||||
int active_name;
|
||||
char cache_name[2][20];
|
||||
struct kmem_cache *slab_cache; /* for allocating stripes */
|
||||
|
||||
int seq_flush, seq_write;
|
||||
int quiesce;
|
||||
|
||||
int fullsync; /* set to 1 if a full sync is needed,
|
||||
* (fresh device added).
|
||||
* Cleared when a sync completes.
|
||||
*/
|
||||
|
||||
struct page *spare_page; /* Used when checking P/Q in raid6 */
|
||||
|
||||
/*
|
||||
* Free stripes pool
|
||||
*/
|
||||
atomic_t active_stripes;
|
||||
struct list_head inactive_list;
|
||||
wait_queue_head_t wait_for_stripe;
|
||||
wait_queue_head_t wait_for_overlap;
|
||||
int inactive_blocked; /* release of inactive stripes blocked,
|
||||
* waiting for 25% to be free
|
||||
*/
|
||||
int pool_size; /* number of disks in stripeheads in pool */
|
||||
spinlock_t device_lock;
|
||||
struct disk_info *disks;
|
||||
};
|
||||
|
||||
typedef struct raid5_private_data raid5_conf_t;
|
||||
|
||||
#define mddev_to_conf(mddev) ((raid5_conf_t *) mddev->private)
|
||||
|
||||
/*
|
||||
* Our supported algorithms
|
||||
*/
|
||||
#define ALGORITHM_LEFT_ASYMMETRIC 0
|
||||
#define ALGORITHM_RIGHT_ASYMMETRIC 1
|
||||
#define ALGORITHM_LEFT_SYMMETRIC 2
|
||||
#define ALGORITHM_RIGHT_SYMMETRIC 3
|
||||
|
||||
#endif
|
||||
23
include/linux/raid/xor.h
Normal file
23
include/linux/raid/xor.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#ifndef _XOR_H
|
||||
#define _XOR_H
|
||||
|
||||
#include <linux/raid/md.h>
|
||||
|
||||
#define MAX_XOR_BLOCKS 5
|
||||
|
||||
extern void xor_block(unsigned int count, unsigned int bytes, void **ptr);
|
||||
|
||||
struct xor_block_template {
|
||||
struct xor_block_template *next;
|
||||
const char *name;
|
||||
int speed;
|
||||
void (*do_2)(unsigned long, unsigned long *, unsigned long *);
|
||||
void (*do_3)(unsigned long, unsigned long *, unsigned long *,
|
||||
unsigned long *);
|
||||
void (*do_4)(unsigned long, unsigned long *, unsigned long *,
|
||||
unsigned long *, unsigned long *);
|
||||
void (*do_5)(unsigned long, unsigned long *, unsigned long *,
|
||||
unsigned long *, unsigned long *, unsigned long *);
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user