Introduction
PATCH 1/1 Introduction
Herewith, a group of patches for md/raid in 2.6.13-mm.
They (together with the md patches already in -mm) are all appropriate for the flood which will be pouring in to Linus now that 2.6.13 is out.
There are a few bug fixes (it's SO good having a test suite to help find these), a couple of code cleanups, and the write-intent-logging stuff is now supported on raid4/5/6 as well as raid1.
Thanks,
NeilBrown
[PATCH md 001 of 7] Remove old cruft from md_k.h header file. [PATCH md 002 of 7] Limit size of sb read/written to appropriate amount. [PATCH md 003 of 7] Add write-intent-bitmap support to raid5 [PATCH md 004 of 7] write-intent bitmap support for raid6
[PATCH md 005 of 7] Use kthread infrastructure in md
[PATCH md 006 of 7] Ensure bitmap_writeback_daemon handles shutdown properly. [PATCH md 007 of 7] Tidy up daemon stop/start code in md/bitmap.c
PATCH 1/1 Remove old cruft from md_k.h header file.
These inlines haven't been used for ages, they should go.
### Diffstat output
./include/linux/raid/md_k.h | 64 -------------------------------------------- 1 file changed, 64 deletions(-)
include/linux/raid/md_k.h renamed from include/linux/raid/md_k.h~current~ +0 -64
@@ -86,70 +86,6 @@ typedef struct mdk_rdev_s mdk_rdev_t;#define MAX_CHUNK_SIZE (4096*1024)/* -* default readahead -*/ - -static inline int disk_faulty (mdp_disk_t * d) -{ -return d->state & (1 <<MD_DISK_FAULTY ); -} - -static inline int disk_active (mdp_disk_t * d) -{ -return d->state & (1 <<MD_DISK_ACTIVE ); -} - -static inline int disk_sync (mdp_disk_t * d) -{ -return d->state & (1 <<MD_DISK_SYNC ); -} - -static inline int disk_spare (mdp_disk_t * d) -{ -return !disk_sync (d) && !disk_active (d) && !disk_faulty (d); -} - -static inline int disk_removed (mdp_disk_t * d) -{ -return d->state & (1 <<MD_DISK_REMOVED ); -} - -static inline void mark_disk_faulty (mdp_disk_t * d) -{ - d->state |= (1 <<MD_DISK_FAULTY ); -} - -static inline void mark_disk_active (mdp_disk_t * d) -{ - d->state |= (1 <<MD_DISK_ACTIVE ); -} - -static inline void mark_disk_sync (mdp_disk_t * d) -{ - d->state |= (1 <<MD_DISK_SYNC ); -} - -static inline void mark_disk_spare (mdp_disk_t * d) -{ - d->state =0 ; -} - -static inline void mark_disk_removed (mdp_disk_t * d) -{ - d->state = (1 <<MD_DISK_FAULTY ) | (1 <<MD_DISK_REMOVED ); -} - -static inline void mark_disk_inactive (mdp_disk_t * d) -{ - d->state &= ~(1 <<MD_DISK_ACTIVE ); -} - -static inline void mark_disk_nonsync (mdp_disk_t * d) -{ - d->state &= ~(1 <<MD_DISK_SYNC ); -} - -/* * MD's 'extended' device */ struct mdk_rdev_s
PATCH 1/1 Limit size of sb read/written to appropriate amount.
In reply to NeilBrownversion-1 superblocks are not (normally) 4K long, and can be of variable size. Writing the full 4K can cause corruption (but only in non-default configurations).
With this patch the super-block-flavour can choose a size to read, and set a size to write based on what it finds.
### Diffstat output
./drivers/md/md.c | 20 +++++++++++++++----- ./include/linux/raid/md_k.h | 1 + 2 files changed, 16 insertions(+), 5 deletions(-)
drivers/md/md.c renamed from drivers/md/md.c~current~ +15 -5
@@ -393,7 +393,7 @@ int sync_page_io(struct block_device *bdreturn ret; } -static int read_disk_sb (mdk_rdev_t * rdev) +static int read_disk_sb (mdk_rdev_t * rdev,int size) {char b[BDEVNAME_SIZE ];if (!rdev->sb_page) {
@@ -404,7 +404,7 @@ static int read_disk_sb(mdk_rdev_t * rdereturn 0 ; -if (!sync_page_io (rdev->bdev, rdev->sb_offset<<1 ,MD_SB_BYTES , rdev->sb_page,READ )) +if (!sync_page_io (rdev->bdev, rdev->sb_offset<<1 , size, rdev->sb_page,READ )) goto fail; rdev->sb_loaded =1 ;return 0 ;
@@ -531,7 +531,7 @@ static int super_90_load(mdk_rdev_t *rde sb_offset =calc_dev_sboffset (rdev->bdev); rdev->sb_offset = sb_offset; - ret =read_disk_sb (rdev); + ret =read_disk_sb (rdev,MD_SB_BYTES );if (ret)return ret; ret = -EINVAL ;
@@ -564,6 +564,7 @@ static int super_90_load(mdk_rdev_t *rde rdev->preferred_minor = sb->md_minor; rdev->data_offset =0 ; + rdev->sb_size =MD_SB_BYTES ;if (sb->level ==LEVEL_MULTIPATH ) rdev->desc_nr =-1 ;
@@ -837,6 +838,7 @@ static int super_1_load(mdk_rdev_t *rdevint ret;sector_t sb_offset;char b[BDEVNAME_SIZE ], b2[BDEVNAME_SIZE ]; +int bmask;/* * Calculate the position of the superblock.
@@ -865,7 +867,10 @@ static int super_1_load(mdk_rdev_t *rdev } rdev->sb_offset = sb_offset; - ret =read_disk_sb (rdev); +/* superblock is rarely larger than 1K, but it can be larger, +* and it is safe to read 4k, so we do that +*/ + ret =read_disk_sb (rdev,4096 );if (ret)return ret;
@@ -891,6 +896,11 @@ static int super_1_load(mdk_rdev_t *rdev rdev->preferred_minor =0xffff ; rdev->data_offset =le64_to_cpu (sb->data_offset); + rdev->sb_size =le32_to_cpu (sb->max_dev) *2 +256 ; + bmask =block_size (rdev->bdev)-1 ; +if (rdev->sb_size & bmask) + rdev-> sb_size = (rdev->sb_size | bmask)+1 ; +if (refdev ==0 )return 1 ;else {
@@ -1375,7 +1385,7 @@ repeat:dprintk ("%s " ,bdevname (rdev->bdev,b));if (!rdev->faulty) {md_super_write (mddev,rdev, - rdev->sb_offset<<1 ,MD_SB_BYTES , + rdev->sb_offset<<1 , rdev->sb_size, rdev->sb_page); dprintk(KERN_INFO "(write) %s's sb offset: %llu\n", bdevname(rdev->bdev,b),
include/linux/raid/md_k.h renamed from include/linux/raid/md_k.h~current~ +1 -0
@@ -102,6 +102,7 @@ struct mdk_rdev_sint sb_loaded;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 */ /* A device can be in one of three states based on two flags:
PATCH 1/1 Add write-intent-bitmap support to raid5
In reply to NeilBrownMost awkward part of this is delaying write requests until bitmap updates have been flushed.
To achieve this, we have a sequence number (seq_flush) which is incremented each time the raid5 is unplugged.
If the raid thread notices that this has changed, it flushes bitmap changes, and assigned the value of seq_flush to seq_write. When a write request arrives, it is given the number from seq_write, and that write request may not complete until seq_flush is larger than the saved seq number.
We have a new queue for storing stripes which are waiting for a bitmap flush and an extra flag for stripes to record if the write was 'degraded' and so should not clear the a bit in the bitmap.
### Diffstat output
./drivers/md/md.c | 3 ./drivers/md/raid5.c | 133 +++++++++++++++++++++++++++++++++++++++---- ./include/linux/raid/raid5.h | 14 ++++ 3 files changed, 137 insertions(+), 13 deletions(-)
drivers/md/md.c renamed from drivers/md/md.c~current~ +1 -2
@@ -645,7 +645,7 @@ static int super_90_validate(mddev_t *mdif (sb->state & (1 <<MD_SB_BITMAP_PRESENT ) && mddev->bitmap_file ==NULL ) { -if (mddev->level !=1 ) { +if (mddev->level !=1 && mddev->level !=5 ) {/* FIXME use a better test */ printk (KERN_WARNING "md: bitmaps only support for raid1\n" );return -EINVAL ;
@@ -3517,7 +3517,6 @@ void md_done_sync(mddev_t *mddev, int bl*/ void md_write_start (mddev_t *mddev,struct bio *bi) { -DEFINE_WAIT (w);if (bio_data_dir (bi) !=WRITE )return ;
drivers/md/raid5.c renamed from drivers/md/raid5.c~current~ +123 -10
301 lines not on this page · raw message
include/linux/raid/raid5.h renamed from include/linux/raid/raid5.h~current~ +13 -1
@@ -134,6 +134,7 @@ struct stripe_head {unsigned long state;/* state flags */ atomic_t count;/* nr of active thread/requests */ spinlock_t lock; +int bm_seq;/* sequence number for bitmap flushes */ struct r5dev {struct bio req;struct bio_vec vec;
@@ -165,12 +166,13 @@ struct stripe_head {/* * Stripe state */ -#define STRIPE_ERROR 1#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/* * Plugging:
@@ -210,10 +212,20 @@ struct raid5_private_data {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 */ atomic_t preread_active_stripes;/* stripes with scheduled io */ char cache_name[20 ];kmem_cache_t *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. +*/ +/* * Free stripes pool */
PATCH 1/1 write-intent bitmap support for raid6
In reply to NeilBrownThis is a direct port of the raid5 patch.
### Diffstat output
./drivers/md/md.c | 2 ./drivers/md/raid6main.c | 133 +++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 124 insertions(+), 11 deletions(-)
drivers/md/md.c renamed from drivers/md/md.c~current~ +1 -1
@@ -645,7 +645,7 @@ static int super_90_validate(mddev_t *mdif (sb->state & (1 <<MD_SB_BITMAP_PRESENT ) && mddev->bitmap_file ==NULL ) { -if (mddev->level !=1 && mddev->level !=5 ) { +if (mddev->level !=1 && mddev->level !=5 && mddev->level !=6 ) {/* FIXME use a better test */ printk (KERN_WARNING "md: bitmaps only support for raid1\n" );return -EINVAL ;
drivers/md/raid6main.c renamed from drivers/md/raid6main.c~current~ +123 -10
301 lines not on this page · raw message
PATCH 1/1 Use kthread infrastructure in md
In reply to NeilBrownSwitch MD to use the kthread infrastructure, to simplify the code and get rid of tasklist_lock abuse in md_unregister_thread.
Also don't flush signals in md_thread, as the called thread will always do that.
### Diffstat output
./drivers/md/md.c | 48 ++++++++++-------------------------------------- 1 file changed, 10 insertions(+), 38 deletions(-)
drivers/md/md.c renamed from drivers/md/md.c~current~ +10 -38
@@ -34,6 +34,7 @@#include <linux/module.h> #include <linux/config.h> +#include <linux/kthread.h> #include <linux/linkage.h> #include <linux/raid/md.h> #include <linux/raid/bitmap.h>
@@ -3049,18 +3050,6 @@ static int md_thread(void * arg) {mdk_thread_t *thread = arg; -lock_kernel (); - -/* -* Detach thread -*/ - -daemonize (thread->name,mdname (thread->mddev)); - - current->exit_signal =SIGCHLD ; -allow_signal (SIGKILL ); - thread->tsk = current; -/* * md_thread is a 'system-thread', it's priority should be very * high. We avoid resource deadlocks individually in each
@@ -3072,14 +3061,14 @@ static int md_thread(void * arg)* bdflush, otherwise bdflush will deadlock if there are too * many dirty RAID5 blocks. */ -unlock_kernel ();complete (thread->event); -while (thread->run) { +while (!kthread_should_stop ()) {void (*run)(mddev_t *);wait_event_interruptible_timeout (thread->wqueue, -test_bit (THREAD_WAKEUP , &thread->flags), +test_bit (THREAD_WAKEUP , &thread->flags) + ||kthread_should_stop (), thread->timeout);try_to_freeze ();
@@ -3088,11 +3077,8 @@ static int md_thread(void * arg) run = thread->run;if (run)run (thread->mddev); - -if (signal_pending (current)) -flush_signals (current); } -complete (thread->event); +return 0 ; }
@@ -3109,11 +3095,9 @@ mdk_thread_t *md_register_thread(void (* const char *name) {mdk_thread_t *thread; -int ret;struct completion event; - thread = (mdk_thread_t *)kmalloc - (sizeof (mdk_thread_t),GFP_KERNEL ); + thread =kmalloc (sizeof (mdk_thread_t),GFP_KERNEL );if (!thread)return NULL ;
@@ -3126,8 +3110,8 @@ mdk_thread_t *md_register_thread(void (* thread->mddev = mddev; thread->name = name; thread->timeout =MAX_SCHEDULE_TIMEOUT ; - ret =kernel_thread (md_thread, thread,0 ); -if (ret <0 ) { + thread->tsk =kthread_run (md_thread, thread,mdname (thread->mddev)); +if (IS_ERR (thread->tsk)) {kfree (thread);return NULL ; }
@@ -3137,21 +3121,9 @@ mdk_thread_t *md_register_thread(void (*void md_unregister_thread (mdk_thread_t *thread) { -struct completion event; - -init_completion (&event); - - thread->event = &event; - -/* As soon as ->run is set to NULL, the task could disappear, -* so we need to hold tasklist_lock until we have sent the signal -*/ dprintk ("interrupting MD-thread pid %d\n" , thread->tsk->pid); -read_lock (&tasklist_lock); - thread->run =NULL ; -send_sig (SIGKILL , thread->tsk,1 ); -read_unlock (&tasklist_lock); -wait_for_completion (&event); + +kthread_stop (thread->tsk);kfree (thread); }
PATCH 1/1 Ensure bitmap_writeback_daemon handles shutdown properly.
In reply to NeilBrownmddev->bitmap gets clearred before the writeback daemon is stopped. So the write_back daemon needs to be careful not to dereference the 'bitmap' if it is NULL.
### Diffstat output
./drivers/md/bitmap.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/md/bitmap.c renamed from drivers/md/bitmap.c~current~ +3 -0
@@ -1156,6 +1156,9 @@ static void bitmap_writeback_daemon(mdde err = -EINTR ; goto out; } +if (bitmap ==NULL ) +/* about to be stopped. */ +return ;PRINTK ("%s: bitmap writeback daemon woke up...\n" ,bmname (bitmap));/* wait on bitmap page writebacks */
PATCH 1/1 Tidy up daemon stop/start code in md/bitmap.c
In reply to NeilBrownThe bitmap code used to have two daemons, so there is some 'common' start/stop code. But now there is only one, so the common code is just noise.
This patch tidies this up somewhat.
### Diffstat output
./drivers/md/bitmap.c | 73 ++++++++++++++++++-------------------------------- 1 file changed, 27 insertions(+), 46 deletions(-)
drivers/md/bitmap.c renamed from drivers/md/bitmap.c~current~ +27 -46
@@ -626,7 +626,7 @@ static void bitmap_file_unmap(struct bitpage_cache_release (sb_page); } -static void bitmap_stop_daemons (struct bitmap *bitmap); +static void bitmap_stop_daemon (struct bitmap *bitmap);/* dequeue the next item in a page list -- don't call from irq context */ static struct page_list *dequeue_page (struct bitmap *bitmap)
@@ -668,7 +668,7 @@ static void bitmap_file_put(struct bitma bitmap->file =NULL ;spin_unlock_irqrestore (&bitmap->lock, flags); -bitmap_stop_daemons (bitmap); +bitmap_stop_daemon (bitmap);drain_write_queues (bitmap);
@@ -1188,21 +1188,12 @@ static void bitmap_writeback_daemon(mdde } } -static int bitmap_start_daemon (struct bitmap *bitmap,mdk_thread_t **ptr, +static mdk_thread_t *bitmap_start_daemon (struct bitmap *bitmap,void (*func)(mddev_t *),char *name) {mdk_thread_t *daemon; -unsigned long flags;char namebuf[32 ]; -spin_lock_irqsave (&bitmap->lock, flags); - *ptr =NULL ; - -if (!bitmap->file)/* no need for daemon if there's no backing file */ - goto out_unlock; - -spin_unlock_irqrestore (&bitmap->lock, flags); -#ifdef INJECT_FATAL_FAULT_2 daemon =NULL ;#else
@@ -1212,47 +1203,32 @@ static int bitmap_start_daemon(struct biif (!daemon) {printk (KERN_ERR "%s: failed to start bitmap daemon\n" ,bmname (bitmap)); -return -ECHILD ; +return ERR_PTR (-ECHILD ); } -spin_lock_irqsave (&bitmap->lock, flags); - *ptr = daemon; -md_wakeup_thread (daemon);/* start it running */ PRINTK ("%s: %s daemon (pid %d) started...\n" ,bmname (bitmap), name, daemon->tsk->pid); -out_unlock: -spin_unlock_irqrestore (&bitmap->lock, flags); -return 0 ; -} -static int bitmap_start_daemons (struct bitmap *bitmap) -{ -int err =bitmap_start_daemon (bitmap, &bitmap->writeback_daemon, - bitmap_writeback_daemon,"bitmap_wb" ); -return err; +return daemon; } -static void bitmap_stop_daemon (struct bitmap *bitmap,mdk_thread_t **ptr) +static void bitmap_stop_daemon (struct bitmap *bitmap) { -mdk_thread_t *daemon; -unsigned long flags; - -spin_lock_irqsave (&bitmap->lock, flags); - daemon = *ptr; - *ptr =NULL ; -spin_unlock_irqrestore (&bitmap->lock, flags); -if (daemon) -md_unregister_thread (daemon);/* destroy the thread */ -} +/* the daemon can't stop itself... it'll just exit instead... */ +if (bitmap->writeback_daemon && !IS_ERR (bitmap->writeback_daemon) && + current->pid != bitmap->writeback_daemon->tsk->pid) { +mdk_thread_t *daemon; +unsigned long flags; -static void bitmap_stop_daemons (struct bitmap *bitmap) -{ -/* the daemons can't stop themselves... they'll just exit instead... */ -if (bitmap->writeback_daemon && - current->pid != bitmap->writeback_daemon->tsk->pid) -bitmap_stop_daemon (bitmap, &bitmap->writeback_daemon); +spin_lock_irqsave (&bitmap->lock, flags); + daemon = bitmap->writeback_daemon; + bitmap->writeback_daemon =NULL ; +spin_unlock_irqrestore (&bitmap->lock, flags); +if (daemon && !IS_ERR (daemon)) +md_unregister_thread (daemon);/* destroy the thread */ + } } static bitmap_counter_t *bitmap_get_counter(struct bitmap *bitmap,
@@ -1637,10 +1613,15 @@ int bitmap_create(mddev_t *mddev) mddev->bitmap = bitmap; -/* kick off the bitmap daemons */ - err =bitmap_start_daemons (bitmap); -if (err) -return err; +if (file) +/* kick off the bitmap writeback daemon */ + bitmap->writeback_daemon = +bitmap_start_daemon (bitmap, + bitmap_writeback_daemon, +"bitmap_wb" ); + +if (IS_ERR (bitmap->writeback_daemon)) +return PTR_ERR (bitmap->writeback_daemon);return bitmap_update_sb (bitmap); error: