Skip to contentSkip to conversation

fix file position for hugetlbfs-read-support

PATCH In review Ken Chen 2 participants 2 messages Oct 2, 2007

Subsystems (2)
lore
Share & tools
lore

Ken Chen

author
#0 lore raw

PATCH 1/1 fix file position for hugetlbfs-read-support

While working on a related area, I ran into a bug in hugetlbfs file read support that is currently in -mm tree (hugetlbfs-read-support.patch).

The problem is that hugetlb file position wasn't updated in hugetlbfs_read(), so sys_read() will always read from same file location. A simple "cp" command that reads file until EOF will never terminate. Fix it by updating the ppos at the end of hugetlbfs_read().

fs/hugetlbfs/inode.c +2 -2
index 6dde2c3..8d9a631 100644
@@ -228,9 +228,9 @@ hugetlbfs_read(struct file *filp
 	struct 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;
 
 	/* validate length */
@@ -241,7 +241,6 @@ hugetlbfs_read(struct file *filp
 	if (!isize)
 		goto out;
 
-	offset = *ppos & ~HPAGE_MASK;
 	end_index = (isize - 1) >> HPAGE_SHIFT;
 	for (;;) {
 		struct page *page;
@@ -290,6 +289,7 @@ hugetlbfs_read(struct file *filp
 		goto out;
 	}
 out:
+	*ppos = ((loff_t) index << HPAGE_SHIFT) + offset;
 	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>

Acked-by on v1 1/1
#1 lore raw
Quoted 4 lines · Ken Chen

While working on a related area, I ran into a bug in hugetlbfs file read support that is currently in -mm tree (hugetlbfs-read-support.patch).

Quoted 8 lines

The problem is that hugetlb file position wasn't updated in hugetlbfs_read(), so sys_read() will always read from same file location. A simple "cp" command that reads file until EOF will never terminate. Fix it by updating the ppos at the end of hugetlbfs_read().

Thank you.

Thanks,
Badari

--
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>