Fixes to hugetlbfs_read() support
Subsystems (2)
PATCH 1/1 Fixes to hugetlbfs_read() support
In reply to a message not in the archiveHi Ken,
Here is the latest against 2.6.23-rc8-mm2. If you are happy with this, I will ask Andrew to pick it up. I did test this version :)
Thanks,
Badari
Various fixes to hugetlbfs_read() support
- handle HOLES correcty
- clean up weird looking loop condition reported by Ken Chen
- integrated "not updating file offset after read" fix by Ken Chen
- holding i_mutex to prevent any unwanted interactions with truncate
fs/hugetlbfs/inode.c | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-)
fs/hugetlbfs/inode.c +23 -13
@@ -228,11 +228,13 @@ static ssize_t hugetlbfs_read(struct filstruct address_space *mapping = filp->f_mapping;struct inode *inode = mapping->host;unsigned long index = *ppos >>HPAGE_SHIFT ; +unsigned long offset = *ppos & ~HPAGE_MASK ;unsigned long end_index;loff_t isize; -unsigned long offset;ssize_t retval =0 ; +mutex_lock (&inode->i_mutex); +/* validate length */ if (len ==0 ) goto out;
@@ -241,7 +243,6 @@ static ssize_t hugetlbfs_read(struct filif (!isize) goto out; - offset = *ppos & ~HPAGE_MASK ; end_index = (isize -1 ) >>HPAGE_SHIFT ;for (;;) {struct page *page;
@@ -263,18 +264,23 @@ static ssize_t hugetlbfs_read(struct fil page =find_get_page (mapping, index);if (unlikely (page ==NULL )) {/* -* We can't find the page in the cache - bail out ? +* We have a HOLE, zero out the user-buffer for the +* length of the hole or request. */ - goto out; + ret = len < nr ? len : nr; +if (clear_user (buf, ret)) + ret = -EFAULT ; + }else { +/* +* We have the page, copy it to user space buffer. +*/ + ret =hugetlbfs_read_actor (page, offset, buf, len, nr); } -/* -* Ok, we have the page, copy it to user space buffer. -*/ - ret =hugetlbfs_read_actor (page, offset, buf, len, nr);if (ret <0 ) {if (retval ==0 ) retval = ret; -page_cache_release (page); +if (page) +page_cache_release (page); goto out; }
@@ -284,12 +290,16 @@ static ssize_t hugetlbfs_read(struct fil index += offset >>HPAGE_SHIFT ; offset &= ~HPAGE_MASK ; -page_cache_release (page); -if (ret == nr && len) -continue ; - goto out; +if (page) +page_cache_release (page); + +/* short read or no more work */ +if ((ret != nr) || (len ==0 )) +break ; } out: + *ppos = ((loff_t ) index <<HPAGE_SHIFT ) + offset; +mutex_unlock (&inode->i_mutex);return retval; }
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 4 lines · Badari Pulavarty
Hi Ken,
Here is the latest against 2.6.23-rc8-mm2. If you are happy with this, I will ask Andrew to pick it up. I did test this version :)
Looks good. I also tested and verified that it works.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>