public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] xfs: fix unaligned access in readdir
@ 2007-12-26 15:48 Christoph Hellwig
  2007-12-26 22:19 ` Dustin Marquess
  2008-01-07 22:53 ` Christoph Hellwig
  0 siblings, 2 replies; 3+ messages in thread
From: Christoph Hellwig @ 2007-12-26 15:48 UTC (permalink / raw)
  To: jailbird; +Cc: xfs

This patch should fix the issue seen on Alpha with unaligned accesses
in the new readdir code.   By aligning each dirent to sizeof(u64) we'll
avoid unaligned accesses.  To make doubly sure we're not hitting
problems also rearrange struct hack_dirent to avoid holes.


Signed-off-by: Christoph Hellwig <hch@lst.de>

Index: linux-2.6-xfs/fs/xfs/linux-2.6/xfs_file.c
===================================================================
--- linux-2.6-xfs.orig/fs/xfs/linux-2.6/xfs_file.c	2007-12-26 15:35:33.000000000 +0100
+++ linux-2.6-xfs/fs/xfs/linux-2.6/xfs_file.c	2007-12-26 15:40:14.000000000 +0100
@@ -262,9 +262,9 @@ xfs_file_readdir(
 #else
 
 struct hack_dirent {
-	int		namlen;
-	loff_t		offset;
 	u64		ino;
+	loff_t		offset;
+	int		namlen;
 	unsigned int	d_type;
 	char		name[];
 };
@@ -286,8 +286,10 @@ xfs_hack_filldir(
 {
 	struct hack_callback *buf = __buf;
 	struct hack_dirent *de = (struct hack_dirent *)(buf->dirent + buf->used);
+	unsigned int reclen;
 
-	if (buf->used + sizeof(struct hack_dirent) + namlen > buf->len)
+	reclen = ALIGN(sizeof(struct hack_dirent) + namlen, sizeof(u64));
+	if (buf->used + reclen > buf->len)
 		return -EINVAL;
 
 	de->namlen = namlen;
@@ -295,7 +297,7 @@ xfs_hack_filldir(
 	de->ino = ino;
 	de->d_type = d_type;
 	memcpy(de->name, name, namlen);
-	buf->used += sizeof(struct hack_dirent) + namlen;
+	buf->used += reclen;
 	return 0;
 }
 
@@ -335,7 +337,8 @@ xfs_file_readdir(
 		offset = filp->f_pos;
 
 	while (!eof) {
-		int reclen;
+		unsigned int reclen;
+
 		start_offset = offset;
 
 		buf.used = 0;
@@ -356,7 +359,8 @@ xfs_file_readdir(
 				goto done;
 			}
 
-			reclen = sizeof(struct hack_dirent) + de->namlen;
+			reclen = ALIGN(sizeof(struct hack_dirent) + de->namlen,
+				       sizeof(u64));
 			size -= reclen;
 			de = (struct hack_dirent *)((char *)de + reclen);
 			curr_offset = de->offset /* & 0x7fffffff */;

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

* Re: [PATCH] xfs: fix unaligned access in readdir
  2007-12-26 15:48 [PATCH] xfs: fix unaligned access in readdir Christoph Hellwig
@ 2007-12-26 22:19 ` Dustin Marquess
  2008-01-07 22:53 ` Christoph Hellwig
  1 sibling, 0 replies; 3+ messages in thread
From: Dustin Marquess @ 2007-12-26 22:19 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: xfs

This patch does indeed fix the problem.

Thanks!

-Dustin

Christoph Hellwig wrote:
> This patch should fix the issue seen on Alpha with unaligned accesses
> in the new readdir code.   By aligning each dirent to sizeof(u64) we'll
> avoid unaligned accesses.  To make doubly sure we're not hitting
> problems also rearrange struct hack_dirent to avoid holes.
> 
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> 
> Index: linux-2.6-xfs/fs/xfs/linux-2.6/xfs_file.c
> ===================================================================
> --- linux-2.6-xfs.orig/fs/xfs/linux-2.6/xfs_file.c	2007-12-26 15:35:33.000000000 +0100
> +++ linux-2.6-xfs/fs/xfs/linux-2.6/xfs_file.c	2007-12-26 15:40:14.000000000 +0100
> @@ -262,9 +262,9 @@ xfs_file_readdir(
>  #else
>  
>  struct hack_dirent {
> -	int		namlen;
> -	loff_t		offset;
>  	u64		ino;
> +	loff_t		offset;
> +	int		namlen;
>  	unsigned int	d_type;
>  	char		name[];
>  };
> @@ -286,8 +286,10 @@ xfs_hack_filldir(
>  {
>  	struct hack_callback *buf = __buf;
>  	struct hack_dirent *de = (struct hack_dirent *)(buf->dirent + buf->used);
> +	unsigned int reclen;
>  
> -	if (buf->used + sizeof(struct hack_dirent) + namlen > buf->len)
> +	reclen = ALIGN(sizeof(struct hack_dirent) + namlen, sizeof(u64));
> +	if (buf->used + reclen > buf->len)
>  		return -EINVAL;
>  
>  	de->namlen = namlen;
> @@ -295,7 +297,7 @@ xfs_hack_filldir(
>  	de->ino = ino;
>  	de->d_type = d_type;
>  	memcpy(de->name, name, namlen);
> -	buf->used += sizeof(struct hack_dirent) + namlen;
> +	buf->used += reclen;
>  	return 0;
>  }
>  
> @@ -335,7 +337,8 @@ xfs_file_readdir(
>  		offset = filp->f_pos;
>  
>  	while (!eof) {
> -		int reclen;
> +		unsigned int reclen;
> +
>  		start_offset = offset;
>  
>  		buf.used = 0;
> @@ -356,7 +359,8 @@ xfs_file_readdir(
>  				goto done;
>  			}
>  
> -			reclen = sizeof(struct hack_dirent) + de->namlen;
> +			reclen = ALIGN(sizeof(struct hack_dirent) + de->namlen,
> +				       sizeof(u64));
>  			size -= reclen;
>  			de = (struct hack_dirent *)((char *)de + reclen);
>  			curr_offset = de->offset /* & 0x7fffffff */;
> 

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

* Re: [PATCH] xfs: fix unaligned access in readdir
  2007-12-26 15:48 [PATCH] xfs: fix unaligned access in readdir Christoph Hellwig
  2007-12-26 22:19 ` Dustin Marquess
@ 2008-01-07 22:53 ` Christoph Hellwig
  1 sibling, 0 replies; 3+ messages in thread
From: Christoph Hellwig @ 2008-01-07 22:53 UTC (permalink / raw)
  To: xfs

On Wed, Dec 26, 2007 at 04:48:57PM +0100, Christoph Hellwig wrote:
> This patch should fix the issue seen on Alpha with unaligned accesses
> in the new readdir code.   By aligning each dirent to sizeof(u64) we'll
> avoid unaligned accesses.  To make doubly sure we're not hitting
> problems also rearrange struct hack_dirent to avoid holes.

If anyone in Melbourne is getting back from Holidays it would be nice
if we could get this patch into 2.6.24-final still..

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

end of thread, other threads:[~2008-01-07 22:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-12-26 15:48 [PATCH] xfs: fix unaligned access in readdir Christoph Hellwig
2007-12-26 22:19 ` Dustin Marquess
2008-01-07 22:53 ` Christoph Hellwig

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