Esempio n. 1
0
/*
 * write out a page to a file
 */
static void write_page(struct bitmap *bitmap, struct page *page, int wait)
{
    struct buffer_head *bh;

    if (bitmap->file == NULL) {
        switch (write_sb_page(bitmap, page, wait)) {
        case -EINVAL:
            bitmap->flags |= BITMAP_WRITE_ERROR;
        }
    } else {

        bh = page_buffers(page);

        while (bh && bh->b_blocknr) {
            atomic_inc(&bitmap->pending_writes);
            set_buffer_locked(bh);
            set_buffer_mapped(bh);
            submit_bh(WRITE, bh);
            bh = bh->b_this_page;
        }

        if (wait) {
            wait_event(bitmap->write_wait,
                       atomic_read(&bitmap->pending_writes)==0);
        }
    }
    if (bitmap->flags & BITMAP_WRITE_ERROR)
        bitmap_file_kick(bitmap);
}
Esempio n. 2
0
/*
 * write out a page to a file
 */
static int write_page(struct bitmap *bitmap, struct page *page, int wait)
{
    int ret = -ENOMEM;

    if (bitmap->file == NULL)
        return write_sb_page(bitmap->mddev, bitmap->offset, page, wait);

    flush_dcache_page(page); /* make sure visible to anyone reading the file */

    if (wait)
        lock_page(page);
    else {
        if (TestSetPageLocked(page))
            return -EAGAIN; /* already locked */
        if (PageWriteback(page)) {
            unlock_page(page);
            return -EAGAIN;
        }
    }

    ret = page->mapping->a_ops->prepare_write(bitmap->file, page, 0, PAGE_SIZE);
    if (!ret)
        ret = page->mapping->a_ops->commit_write(bitmap->file, page, 0,
                PAGE_SIZE);
    if (ret) {
        unlock_page(page);
        return ret;
    }

    set_page_dirty(page); /* force it to be written out */

    if (!wait) {
        /* add to list to be waited for by daemon */
        struct page_list *item = mempool_alloc(bitmap->write_pool, GFP_NOIO);
        item->page = page;
        get_page(page);
        spin_lock(&bitmap->write_lock);
        list_add(&item->list, &bitmap->complete_pages);
        spin_unlock(&bitmap->write_lock);
        md_wakeup_thread(bitmap->writeback_daemon);
    }
    return write_one_page(page, wait);
}
Esempio n. 3
0
/*
 * write out a page to a file
 */
static int write_page(struct bitmap *bitmap, struct page *page, int wait)
{
	struct buffer_head *bh;

	if (bitmap->file == NULL)
		return write_sb_page(bitmap, page, wait);

	bh = page_buffers(page);

	while (bh && bh->b_blocknr) {
		atomic_inc(&bitmap->pending_writes);
		set_buffer_locked(bh);
		set_buffer_mapped(bh);
		submit_bh(WRITE, bh);
		bh = bh->b_this_page;
	}

	if (wait) {
		wait_event(bitmap->write_wait,
			   atomic_read(&bitmap->pending_writes)==0);
		return (bitmap->flags & BITMAP_WRITE_ERROR) ? -EIO : 0;
	}
	return 0;
}