Bug 108811

Summary: overlayfs over xfs cannot delete file
Product: File System Reporter: LiLinZhe (reg)
Component: OtherAssignee: fs_other
Status: RESOLVED WILL_FIX_LATER    
Severity: normal CC: reg
Priority: P1    
Hardware: All   
OS: Linux   
Kernel Version: 4.3.0 Subsystem:
Regression: No Bisected commit-id:
Bug Depends on: 109001    
Bug Blocks:    
Attachments: quick dirty fix
do not use dir2 ftypes even in v2 dir.

Description LiLinZhe 2015-12-03 10:04:49 UTC
1 - Description
When mount overlayfs over xfs. Delete file will remain stub.(Works fine on ext4)

2 - What Expect
Overlayfs should works well on xfs. 

3 - How to reproduce
```
# dd if=/dev/zero of=./xfs.img bs=1M count=30
# mkfs.xfs ./xfs.img ;
# mkdir -p /xfs-test/
# mount -o loop xfs.img /xfs-test/
# cd /xfs-test; mkdir lower work upper mp;
# mkdir lower/a;touch lower/a/b
# mount -t overlay overlay -o lowerdir=./lower,upperdir=./upper,workdir=./work ./mp
# rm -rf a/b
# cd a
# ls -lah
[root@localhost a]# ls -lah
ls: cannot access b: No such file or directory
total 0
drwxr-xr-x 1 root root 14 Dec  3 17:57 .
drwxr-xr-x 1 root root 14 Dec  3 17:56 ..
?????????? ? ?    ?     ?            ? b

# ls b
ls: cannot access b: No such file or directory

# cd ..;rm -rf a
rm: cannot remove ‘a’: Directory not empty

```

4- Frequency of reproduction
Always
Comment 1 LiLinZhe 2015-12-03 10:32:09 UTC
Created attachment 196361 [details]
quick dirty fix

A quick look of source code points out

   function ovl_dir_read in  /linux-4.3/fs/overlayfs/readdir.c

   L259: if (!err && rdd->first_maybe_whiteout) {

rdd->first_maybe_whiteout will remains zero in xfs. but works fine in ext4. remove it  works for me. still digging why it not work.
Comment 2 LiLinZhe 2015-12-07 13:24:12 UTC
attachment 196361 [details] won't work. don't use it.
====

i use xfs v2 dirs. 

[root@localhost xfs]# file /home/x
/home/x: SGI XFS filesystem data (blksz 4096, inosz 512, v2 dirs)


when track code to xfs.  dir_emit always return filetype as 0.

when examine xfs_dir2_sf_getdents / xfs_dir2_block_getdents / xfs_dir2_leaf_getdents. I found dp->d_ops->data_get_ftype / dp->d_ops->sf_get_ftype will always points to xfs_dir2_sfe_get_ftype / xfs_dir2_data_get_ftype. which return XFS_DIR3_FT_UNKNOWN forever.

change to xfs_dir3_sfe_get_ftype /  xfs_dir3_data_get_ftype should fix this fine.

I'll submit a patch soon but not expect xfs accept it.(changed libxfs)
Comment 3 LiLinZhe 2015-12-07 13:31:12 UTC
Created attachment 196531 [details]
do not use dir2 ftypes even in v2 dir.
Comment 4 LiLinZhe 2015-12-08 02:00:05 UTC
thanks dave. to solve this:

mkfs.xfs -n ftype=1

still need process dents return d_type == DT_UNKNOWN.