Bug 1785094

Summary: rename dir1 to another existing dir2 cause dir1 glusterfa link file deleted
Product: [Community] GlusterFS Reporter: zhou lin <zz.sh.cynthia>
Component: posixAssignee: bugs <bugs>
Status: CLOSED UPSTREAM QA Contact:
Severity: high Docs Contact:
Priority: unspecified    
Version: mainlineCC: bugs, pasik, ravishankar
Target Milestone: ---   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2020-03-12 13:25:24 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
patch for ls dir return empty after rename dir to another existing dir none

Description zhou lin 2019-12-19 06:28:20 UTC
Description of problem:
rename a dir1 to another existing dir2 cause dir1 glusterfs link file in .glusterfs/xx/xx/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx disappear

Version-Release number of selected component (if applicable):

glusterfs7.0
How reproducible:


Steps to Reproduce:
1>	Mkdir dir1 dir2
2>	Touch some files in both dir1 and dir2
3>	Rename dir1 dir2 *  //this will fail with “rename: dir1: rename to dir2 failed: Directory not empty”
4>	Check the glusterfs link file in .glusterfs/xx/xx/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx this file will disappear



Actual results:


Expected results:
glusterfs link file should not disappear.

Additional info:
this issue is permanent in glusterfs7.0, very easy to reproduce.

Comment 1 zhou lin 2019-12-20 07:52:25 UTC
This problem is permanent. From my investigation, for both glusterfs3.12.15 and glusterfs7.0 the root cause seems to be the posix_rename of glusterfsd side firstly unlink the glusterfs link (in posix_handle_unset) and then it fails in 
 sys_rename(since the target already exists), then it does not restore the glusterfs link( file link 1d6febd3-875c-4879-a370-c4828e0052c3 in .glusterfs/1d/6f directory). I think the correct practice should be either restore the deleted  glusterfs link file after sys_rename fail or change to firstly call sys_rename then delete the glusterfs link( I test this and seems with my code change this problem is gone). 
   I would like your opinion on this issue, this issue is permanent, you can try in your own env. Thanks!

following is the reproduce steps:
1>	Mkdir dir1 dir2
2>	Touch some files in both dir1 and dir2
3>	Rename dir1 dir2 *  //this will fail with “rename: dir1: rename to dir2 failed: Directory not empty”
4>	Check the glusterfs link file in .glusterfs/xx/xx/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx this file will disappear
5>	Ls dir1 when dht is enabled in glusterfs3.12 ls command fails to show  dir1 contents


enclosed is my test patch, with my patch there is no such issue.

Comment 2 zhou lin 2019-12-20 07:54:28 UTC
Created attachment 1646749 [details]
patch for ls dir return empty after rename dir to another existing dir

firstly sys_rename, only remove glusterfs metadata( glusterfs gfid link file) when sys_rename has been successfully executed.

Comment 3 Ravishankar N 2019-12-23 12:38:35 UTC
Could you send the patch for review on gerrit please?

Comment 4 Ravishankar N 2019-12-23 12:41:01 UTC
The patch workflow is @ https://docs.gluster.org/en/latest/Developer-guide/Simplified-Development-Workflow/ but I think you already have sent patches before. :-)

Comment 5 zhou lin 2019-12-24 05:37:09 UTC
https://review.gluster.org/#/c/glusterfs/+/23918/
please help to check

Comment 6 Worker Ant 2019-12-24 09:56:25 UTC
REVIEW: https://review.gluster.org/23918 (put sys_rename ahead of deleting gfid link) posted (#8) for review on master by None

Comment 7 Worker Ant 2020-03-12 13:25:24 UTC
This bug is moved to https://github.com/gluster/glusterfs/issues/1014, and will be tracked there from now on. Visit GitHub issues URL for further details

Comment 8 Red Hat Bugzilla 2023-09-14 05:48:58 UTC
The needinfo request[s] on this closed bug have been removed as they have been unresolved for 1000 days