diff mbox

[1/2] ext4: Return proper offset for '..' if inline_data enabled.

Message ID 1364466899-5599-1-git-send-email-tm@tao.ma
State Superseded, archived
Headers show

Commit Message

Tao Ma March 28, 2013, 10:34 a.m. UTC
From: Tao Ma <boyu.mt@taobao.com>

Zach reported a problem that if inline data is enabled, we don't
tell the difference between the offset of '.' and '..'. And a
getdents will fail if the user only want to get '.'.

This patch adds a new offset EXT4_INLINE_DOTDOT_OFFSET which
indicates the offset of inline "..", and now 0 is for the "."
and EXT4_INLINE_DOTDOT_OFFSET is for "..".

Reported-by: Zach Brown <zab@redhat.com>
Signed-off-by: Tao Ma <boyu.mt@taobao.com>
---
 fs/ext4/inline.c |   18 +++++++++++++++---
 1 files changed, 15 insertions(+), 3 deletions(-)

Comments

Zach Brown March 28, 2013, 6:33 p.m. UTC | #1
On Thu, Mar 28, 2013 at 06:34:58PM +0800, Tao Ma wrote:
> From: Tao Ma <boyu.mt@taobao.com>
> 
> Zach reported a problem that if inline data is enabled, we don't
> tell the difference between the offset of '.' and '..'. And a
> getdents will fail if the user only want to get '.'.
> 
> This patch adds a new offset EXT4_INLINE_DOTDOT_OFFSET which
> indicates the offset of inline "..", and now 0 is for the "."
> and EXT4_INLINE_DOTDOT_OFFSET is for "..".

Yeah, this fixes the problem.  I confirmed that my little test that got
a single dirent from getdents() now properly sees . and .. and exits
rather than spinning.

Tested-by: Zach Brown <zab@redhat.com>

>  
> +			if (filp->f_pos == EXT4_INLINE_DOTDOT_OFFSET) {
>  				error = filldir(dirent, "..", 2, 0, parent_ino,
>  						DT_DIR);
>  				if (error)
> -- 
> 1.7.0.4

Though I think you should change the fourth argument (offset) of the
second flildir() from 0 to EXT4_INLINE_DOTDOT_OFFSET.

- z
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Tao Ma March 29, 2013, 1:34 a.m. UTC | #2
On 03/29/2013 02:33 AM, Zach Brown wrote:
> On Thu, Mar 28, 2013 at 06:34:58PM +0800, Tao Ma wrote:
>> From: Tao Ma <boyu.mt@taobao.com>
>>
>> Zach reported a problem that if inline data is enabled, we don't
>> tell the difference between the offset of '.' and '..'. And a
>> getdents will fail if the user only want to get '.'.
>>
>> This patch adds a new offset EXT4_INLINE_DOTDOT_OFFSET which
>> indicates the offset of inline "..", and now 0 is for the "."
>> and EXT4_INLINE_DOTDOT_OFFSET is for "..".
> 
> Yeah, this fixes the problem.  I confirmed that my little test that got
> a single dirent from getdents() now properly sees . and .. and exits
> rather than spinning.
> 
> Tested-by: Zach Brown <zab@redhat.com>
> 
>>  
>> +			if (filp->f_pos == EXT4_INLINE_DOTDOT_OFFSET) {
>>  				error = filldir(dirent, "..", 2, 0, parent_ino,
>>  						DT_DIR);
>>  				if (error)
>> -- 
>> 1.7.0.4
> 
> Though I think you should change the fourth argument (offset) of the
> second flildir() from 0 to EXT4_INLINE_DOTDOT_OFFSET.
My fault, will change it in the next version.

Thanks,
Tao
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Theodore Ts'o April 8, 2013, 5:11 p.m. UTC | #3
On Fri, Mar 29, 2013 at 09:34:58AM +0800, Tao Ma wrote:
> My fault, will change it in the next version.

Hi Tao,

Will you be able to send out a new version of this patch series in the
next few days?  The next merge window will be coming fairly quickly.

Thanks,

					- Ted
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/fs/ext4/inline.c b/fs/ext4/inline.c
index c0fd1a1..9c09dd5 100644
--- a/fs/ext4/inline.c
+++ b/fs/ext4/inline.c
@@ -19,7 +19,8 @@ 
 
 #define EXT4_XATTR_SYSTEM_DATA	"data"
 #define EXT4_MIN_INLINE_DATA_SIZE	((sizeof(__le32) * EXT4_N_BLOCKS))
-#define EXT4_INLINE_DOTDOT_SIZE	4
+#define EXT4_INLINE_DOTDOT_SIZE		4
+#define EXT4_INLINE_DOTDOT_OFFSET	2
 
 int ext4_get_inline_size(struct inode *inode)
 {
@@ -1330,6 +1331,7 @@  int ext4_read_inline_dir(struct file *filp,
 	sb = inode->i_sb;
 	stored = 0;
 	parent_ino = le32_to_cpu(((struct ext4_dir_entry_2 *)dir_buf)->inode);
+	offset = filp->f_pos;
 
 	while (!error && !stored && filp->f_pos < inode->i_size) {
 revalidate:
@@ -1342,9 +1344,15 @@  revalidate:
 		if (filp->f_version != inode->i_version) {
 			for (i = 0;
 			     i < inode->i_size && i < offset;) {
+				/*
+				 * "." is with offset 0 and
+				 * ".." is EXT4_INLINE_DOTDOT_OFFSET.
+				 */
 				if (!i) {
-					/* skip "." and ".." if needed. */
-					i += EXT4_INLINE_DOTDOT_SIZE;
+					i = EXT4_INLINE_DOTDOT_OFFSET;
+					continue;
+				} else if (i == EXT4_INLINE_DOTDOT_OFFSET) {
+					i = EXT4_INLINE_DOTDOT_SIZE;
 					continue;
 				}
 				de = (struct ext4_dir_entry_2 *)
@@ -1373,7 +1381,11 @@  revalidate:
 				if (error)
 					break;
 				stored++;
+				filp->f_pos = EXT4_INLINE_DOTDOT_OFFSET;
+				continue;
+			}
 
+			if (filp->f_pos == EXT4_INLINE_DOTDOT_OFFSET) {
 				error = filldir(dirent, "..", 2, 0, parent_ino,
 						DT_DIR);
 				if (error)