Skip to contentSkip to conversation

nobh_truncate_page question

DISCUSSION Dmitriy Monakhov 2 participants 2 messages Feb 7, 2007 – Feb 8, 2007

lore
Share & tools
lore
#0 lore raw

Could some one please explain me what's happens with nobh_truncate_page?

int nobh_truncate_page(struct address_space *mapping, loff_t from) {
........
if ((offset & (blocksize - 1)) == 0)

                goto out;

        ret = -ENOMEM;
        page = grab_cache_page(mapping, index);
        if (!page)
                goto out;

        to = (offset + blocksize) & ~(blocksize - 1);
        ret = a_ops->prepare_write(NULL, page, offset, to);

<<<<< This prepare_write() not balanced by appropriate commit_write() <<<<< Currently this not is fatal because this function used only <<<<< by ext2 and jfs witch unbalanced prepare/commit operations <<<<< not painful.

        if (ret == 0) {
                kaddr = kmap_atomic(page, KM_USER0);
                memset(kaddr + offset, 0, PAGE_CACHE_SIZE - offset);
                flush_dcache_page(page);
                kunmap_atomic(kaddr, KM_USER0);
                set_page_dirty(page);
        }
        unlock_page(page);
        page_cache_release(page);
out:
        return ret;
}

But we can't just call commit_write after all job done because this result in i_size increasing till block end. Where are two possible solutions:
a) Call ->commit_write() and then restore i_size to old value.
b) Leave code as it is now, but add warning comment about prepare/commit balance violation.

#1 lore raw
Quoted 15 lines · On Thu, 08 Feb 2007 01:45:10 +0300 Dmitriy Monakhov <[email protected]>…

Could some one please explain me what's happens with nobh_truncate_page?

int nobh_truncate_page(struct address_space *mapping, loff_t from) {
........
if ((offset & (blocksize - 1)) == 0)

                goto out;

        ret = -ENOMEM;
        page = grab_cache_page(mapping, index);
        if (!page)
                goto out;

        to = (offset + blocksize) & ~(blocksize - 1);
        ret = a_ops->prepare_write(NULL, page, offset, to);
Quoted 4 lines

<<<<< This prepare_write() not balanced by appropriate commit_write() <<<<< Currently this not is fatal because this function used only <<<<< by ext2 and jfs witch unbalanced prepare/commit operations <<<<< not painful.

See that comment at the top of nobh_truncate_page()?

Quoted 13 lines
        if (ret == 0) {
                kaddr = kmap_atomic(page, KM_USER0);
                memset(kaddr + offset, 0, PAGE_CACHE_SIZE - offset);
                flush_dcache_page(page);
                kunmap_atomic(kaddr, KM_USER0);
                set_page_dirty(page);
        }
        unlock_page(page);
        page_cache_release(page);
out:
        return ret;
}
Quoted 5 lines

But we can't just call commit_write after all job done because this result in i_size increasing till block end. Where are two possible solutions:
a) Call ->commit_write() and then restore i_size to old value.
b) Leave code as it is now, but add warning comment about prepare/commit balance violation.

It just happens that nobh_prepare_write() does all the things which nobh_truncate_page() wants done.

If you need to change nobh_prepare_write(), you'll need to change nobh_truncate_page().

Or something. You haven't told us what you're trying to do.