[PATCH] md/bitmap: cleaner separation of page attribute handlers in md/bitmap
md/bitmap has some attributes per-page. Handling of these attributes in largely abstracted in set_page_attr and clear_page_attr. However get_page_attr exposes the format used to store them. So prior to changing that format, introduce test_page_attr instead of get_page_attr, and make appropriate usage changes. Signed-off-by: Neil Brown <neilb@suse.de> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
This commit is contained in:
parent
0b79ccf0cd
commit
ec7a3197f4
@ -717,9 +717,10 @@ static inline void clear_page_attr(struct bitmap *bitmap, struct page *page,
|
|||||||
bitmap->filemap_attr[page->index] &= ~attr;
|
bitmap->filemap_attr[page->index] &= ~attr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline unsigned long get_page_attr(struct bitmap *bitmap, struct page *page)
|
static inline unsigned long test_page_attr(struct bitmap *bitmap, struct page *page,
|
||||||
|
enum bitmap_page_attr attr)
|
||||||
{
|
{
|
||||||
return bitmap->filemap_attr[page->index];
|
return bitmap->filemap_attr[page->index] & attr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -745,7 +746,7 @@ static void bitmap_file_set_bit(struct bitmap *bitmap, sector_t block)
|
|||||||
|
|
||||||
|
|
||||||
/* make sure the page stays cached until it gets written out */
|
/* make sure the page stays cached until it gets written out */
|
||||||
if (! (get_page_attr(bitmap, page) & BITMAP_PAGE_DIRTY))
|
if (! test_page_attr(bitmap, page, BITMAP_PAGE_DIRTY))
|
||||||
get_page(page);
|
get_page(page);
|
||||||
|
|
||||||
/* set the bit */
|
/* set the bit */
|
||||||
@ -769,7 +770,8 @@ static void bitmap_writeback(struct bitmap *bitmap);
|
|||||||
* sync the dirty pages of the bitmap file to disk */
|
* sync the dirty pages of the bitmap file to disk */
|
||||||
int bitmap_unplug(struct bitmap *bitmap)
|
int bitmap_unplug(struct bitmap *bitmap)
|
||||||
{
|
{
|
||||||
unsigned long i, attr, flags;
|
unsigned long i, flags;
|
||||||
|
int dirty, need_write;
|
||||||
struct page *page;
|
struct page *page;
|
||||||
int wait = 0;
|
int wait = 0;
|
||||||
int err;
|
int err;
|
||||||
@ -786,17 +788,18 @@ int bitmap_unplug(struct bitmap *bitmap)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
page = bitmap->filemap[i];
|
page = bitmap->filemap[i];
|
||||||
attr = get_page_attr(bitmap, page);
|
dirty = test_page_attr(bitmap, page, BITMAP_PAGE_DIRTY);
|
||||||
|
need_write = test_page_attr(bitmap, page, BITMAP_PAGE_NEEDWRITE);
|
||||||
clear_page_attr(bitmap, page, BITMAP_PAGE_DIRTY);
|
clear_page_attr(bitmap, page, BITMAP_PAGE_DIRTY);
|
||||||
clear_page_attr(bitmap, page, BITMAP_PAGE_NEEDWRITE);
|
clear_page_attr(bitmap, page, BITMAP_PAGE_NEEDWRITE);
|
||||||
if ((attr & BITMAP_PAGE_DIRTY))
|
if (dirty)
|
||||||
wait = 1;
|
wait = 1;
|
||||||
spin_unlock_irqrestore(&bitmap->lock, flags);
|
spin_unlock_irqrestore(&bitmap->lock, flags);
|
||||||
|
|
||||||
if (attr & (BITMAP_PAGE_DIRTY | BITMAP_PAGE_NEEDWRITE)) {
|
if (dirty | need_write) {
|
||||||
err = write_page(bitmap, page, 0);
|
err = write_page(bitmap, page, 0);
|
||||||
if (err == -EAGAIN) {
|
if (err == -EAGAIN) {
|
||||||
if (attr & BITMAP_PAGE_DIRTY)
|
if (dirty)
|
||||||
err = write_page(bitmap, page, 1);
|
err = write_page(bitmap, page, 1);
|
||||||
else
|
else
|
||||||
err = 0;
|
err = 0;
|
||||||
@ -961,12 +964,11 @@ void bitmap_write_all(struct bitmap *bitmap)
|
|||||||
/* We don't actually write all bitmap blocks here,
|
/* We don't actually write all bitmap blocks here,
|
||||||
* just flag them as needing to be written
|
* just flag them as needing to be written
|
||||||
*/
|
*/
|
||||||
|
int i;
|
||||||
|
|
||||||
unsigned long chunks = bitmap->chunks;
|
for (i=0; i < bitmap->file_pages; i++)
|
||||||
unsigned long bytes = (chunks+7)/8 + sizeof(bitmap_super_t);
|
set_page_attr(bitmap, bitmap->filemap[i],
|
||||||
unsigned long num_pages = (bytes + PAGE_SIZE-1) / PAGE_SIZE;
|
BITMAP_PAGE_NEEDWRITE);
|
||||||
while (num_pages--)
|
|
||||||
bitmap->filemap_attr[num_pages] |= BITMAP_PAGE_NEEDWRITE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -997,7 +999,6 @@ int bitmap_daemon_work(struct bitmap *bitmap)
|
|||||||
struct page *page = NULL, *lastpage = NULL;
|
struct page *page = NULL, *lastpage = NULL;
|
||||||
int err = 0;
|
int err = 0;
|
||||||
int blocks;
|
int blocks;
|
||||||
int attr;
|
|
||||||
void *paddr;
|
void *paddr;
|
||||||
|
|
||||||
if (bitmap == NULL)
|
if (bitmap == NULL)
|
||||||
@ -1019,13 +1020,15 @@ int bitmap_daemon_work(struct bitmap *bitmap)
|
|||||||
|
|
||||||
if (page != lastpage) {
|
if (page != lastpage) {
|
||||||
/* skip this page unless it's marked as needing cleaning */
|
/* skip this page unless it's marked as needing cleaning */
|
||||||
if (!((attr=get_page_attr(bitmap, page)) & BITMAP_PAGE_CLEAN)) {
|
if (!test_page_attr(bitmap, page, BITMAP_PAGE_CLEAN)) {
|
||||||
if (attr & BITMAP_PAGE_NEEDWRITE) {
|
int need_write = test_page_attr(bitmap, page,
|
||||||
|
BITMAP_PAGE_NEEDWRITE);
|
||||||
|
if (need_write) {
|
||||||
get_page(page);
|
get_page(page);
|
||||||
clear_page_attr(bitmap, page, BITMAP_PAGE_NEEDWRITE);
|
clear_page_attr(bitmap, page, BITMAP_PAGE_NEEDWRITE);
|
||||||
}
|
}
|
||||||
spin_unlock_irqrestore(&bitmap->lock, flags);
|
spin_unlock_irqrestore(&bitmap->lock, flags);
|
||||||
if (attr & BITMAP_PAGE_NEEDWRITE) {
|
if (need_write) {
|
||||||
switch (write_page(bitmap, page, 0)) {
|
switch (write_page(bitmap, page, 0)) {
|
||||||
case -EAGAIN:
|
case -EAGAIN:
|
||||||
set_page_attr(bitmap, page, BITMAP_PAGE_NEEDWRITE);
|
set_page_attr(bitmap, page, BITMAP_PAGE_NEEDWRITE);
|
||||||
@ -1043,7 +1046,7 @@ int bitmap_daemon_work(struct bitmap *bitmap)
|
|||||||
/* grab the new page, sync and release the old */
|
/* grab the new page, sync and release the old */
|
||||||
get_page(page);
|
get_page(page);
|
||||||
if (lastpage != NULL) {
|
if (lastpage != NULL) {
|
||||||
if (get_page_attr(bitmap, lastpage) & BITMAP_PAGE_NEEDWRITE) {
|
if (test_page_attr(bitmap, lastpage, BITMAP_PAGE_NEEDWRITE)) {
|
||||||
clear_page_attr(bitmap, lastpage, BITMAP_PAGE_NEEDWRITE);
|
clear_page_attr(bitmap, lastpage, BITMAP_PAGE_NEEDWRITE);
|
||||||
spin_unlock_irqrestore(&bitmap->lock, flags);
|
spin_unlock_irqrestore(&bitmap->lock, flags);
|
||||||
err = write_page(bitmap, lastpage, 0);
|
err = write_page(bitmap, lastpage, 0);
|
||||||
@ -1097,7 +1100,7 @@ int bitmap_daemon_work(struct bitmap *bitmap)
|
|||||||
/* now sync the final page */
|
/* now sync the final page */
|
||||||
if (lastpage != NULL) {
|
if (lastpage != NULL) {
|
||||||
spin_lock_irqsave(&bitmap->lock, flags);
|
spin_lock_irqsave(&bitmap->lock, flags);
|
||||||
if (get_page_attr(bitmap, lastpage) &BITMAP_PAGE_NEEDWRITE) {
|
if (test_page_attr(bitmap, lastpage, BITMAP_PAGE_NEEDWRITE)) {
|
||||||
clear_page_attr(bitmap, lastpage, BITMAP_PAGE_NEEDWRITE);
|
clear_page_attr(bitmap, lastpage, BITMAP_PAGE_NEEDWRITE);
|
||||||
spin_unlock_irqrestore(&bitmap->lock, flags);
|
spin_unlock_irqrestore(&bitmap->lock, flags);
|
||||||
err = write_page(bitmap, lastpage, 0);
|
err = write_page(bitmap, lastpage, 0);
|
||||||
|
Loading…
Reference in New Issue
Block a user