linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [patch] fix file position for hugetlbfs-read-support
@ 2007-10-02 22:30 Ken Chen
  2007-10-02 22:37 ` Badari Pulavarty
  0 siblings, 1 reply; 2+ messages in thread
From: Ken Chen @ 2007-10-02 22:30 UTC (permalink / raw)
  To: Andrew Morton, Badari Pulavarty; +Cc: linux-mm

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().

Signed-off-by: Ken Chen <kenchen@google.com>


diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
index 6dde2c3..8d9a631 100644
--- a/fs/hugetlbfs/inode.c
+++ b/fs/hugetlbfs/inode.c
@@ -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 majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-10-02 22:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-10-02 22:30 [patch] fix file position for hugetlbfs-read-support Ken Chen
2007-10-02 22:37 ` Badari Pulavarty

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox