-
- page_cache_release(lastpage);
- }
-
- return err;
-}
-
-static void daemon_exit(struct bitmap *bitmap, mdk_thread_t **daemon)
-{
- mdk_thread_t *dmn;
- unsigned long flags;
-
- /* if no one is waiting on us, we'll free the md thread struct
- * and exit, otherwise we let the waiter clean things up */
- spin_lock_irqsave(&bitmap->lock, flags);
- if ((dmn = *daemon)) { /* no one is waiting, cleanup and exit */
- *daemon = NULL;
- spin_unlock_irqrestore(&bitmap->lock, flags);
- kfree(dmn);
- complete_and_exit(NULL, 0); /* do_exit not exported */
- }
- spin_unlock_irqrestore(&bitmap->lock, flags);
-}
-
-static void bitmap_writeback_daemon(mddev_t *mddev)
-{
- struct bitmap *bitmap = mddev->bitmap;
- struct page *page;
- struct page_list *item;
- int err = 0;
-
- while (1) {
- PRINTK("%s: bitmap writeback daemon waiting...\n", bmname(bitmap));
- down_interruptible(&bitmap->write_done);
- if (signal_pending(current)) {
- printk(KERN_INFO
- "%s: bitmap writeback daemon got signal, exiting...\n",
- bmname(bitmap));
- break;
- }
-
- PRINTK("%s: bitmap writeback daemon woke up...\n", bmname(bitmap));
- /* wait on bitmap page writebacks */
- while ((item = dequeue_page(bitmap, &bitmap->complete_pages))) {
- page = item->page;
- mempool_free(item, bitmap->write_pool);
- PRINTK("wait on page writeback: %p %lu\n", page, bitmap->writes_pending);
- wait_on_page_writeback(page);
- PRINTK("finished page writeback: %p %lu\n", page, bitmap->writes_pending);
- spin_lock(&bitmap->write_lock);
- if (!--bitmap->writes_pending)
- wake_up(&bitmap->write_wait);
- spin_unlock(&bitmap->write_lock);
- err = PageError(page);
- page_cache_release(page);
- if (err) {
- printk(KERN_WARNING "%s: bitmap file writeback "
- "failed (page %lu): %d\n",
- bmname(bitmap), page->index, err);
- bitmap_file_kick(bitmap);
- goto out;
- }
- }
- }
-out:
- if (err) {
- printk(KERN_INFO "%s: bitmap writeback daemon exiting (%d)\n",
- bmname(bitmap), err);
- daemon_exit(bitmap, &bitmap->writeback_daemon);
- }
- return;
-}
-
-static int bitmap_start_daemon(struct bitmap *bitmap, mdk_thread_t **ptr,
- 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);
-
-#if INJECT_FATAL_FAULT_2
- daemon = NULL;
-#else
- sprintf(namebuf, "%%s_%s", name);
- daemon = md_register_thread(func, bitmap->mddev, namebuf);
-#endif
- if (!daemon) {
- printk(KERN_ERR "%s: failed to start bitmap daemon\n",
- bmname(bitmap));
- return -ECHILD;