Bug 895910

Summary: guestmount: rename() incorrectly follows symbolic links
Product: [Community] Virtualization Tools Reporter: Richard W.M. Jones <rjones>
Component: libguestfsAssignee: Richard W.M. Jones <rjones>
Status: CLOSED UPSTREAM QA Contact:
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: unspecifiedCC: bfan, dyasny, leiwang, mbooth, moli, qguan, walters, wshi
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: 892834 Environment:
Last Closed: 2013-01-21 17:00:47 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:
Bug Depends On:    
Bug Blocks: 892834    
Attachments:
Description Flags
rename.sh none

Description Richard W.M. Jones 2013-01-16 09:19:42 UTC
+++ This bug was initially created as a clone of Bug #892834 +++

Description of problem:

My project ostree implements atomic upgrades by swapping symbolic links.  However, rename() incorrectly follows the symbolic link, instead of overwriting the target.

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

libguestfs-1.16.34-2.el6.x86_64
fuse-2.8.3-4.el6.x86_64
kernel-2.6.32-350.el6.x86_64

How reproducible:

Always.

Expected results (ext4):

$ mkdir adir
$ mkdir bdir
$ ln -s adir current
$ ln -s bdir new
$ mv -T -f new current
$ ls -al
total 16
drwxrwxr-x. 4 walters walters 4096 Jan  7 18:44 .
drwxrwxr-x. 4 walters walters 4096 Jan  7 18:42 ..
drwxrwxr-x. 2 walters walters 4096 Jan  7 18:42 adir
drwxrwxr-x. 2 walters walters 4096 Jan  7 18:42 bdir
lrwxrwxrwx. 1 walters walters    4 Jan  7 18:44 current -> bdir
$ 

Actual results (guestfs):

$ ls -al
total 16
drwxr-xr-x.  2 root root 4096 Jan  7 17:45 .
drwxr-xr-x. 12 root root 4096 Jan  7 17:45 ..
drwxrwxr-x.  2 root root 4096 Jan  7 18:47 adir
drwxrwxr-x.  2 root root 4096 Jan  7 18:46 bdir
lrwxrwxrwx.  1 root root    4 Jan  7 18:46 current -> adir
$ ls -al adir
total 8
drwxrwxr-x. 2 root root 4096 Jan  7 18:47 .
drwxr-xr-x. 4 root root 4096 Jan  7 18:47 ..
lrwxrwxrwx. 1 root root    4 Jan  7 18:46 new -> bdir

(where "new" is a broken symbolic link).

Note to testers: the -T argument to "mv" is important, it will ensure we just use the kernel rename() call instead of following the target.

--- Additional comment from RHEL Product and Program Management on 2013-01-07 19:04:32 EST ---

Since this bug report was entered in bugzilla, the release flag has been
set to ? to ensure that it is properly evaluated for this release.

--- Additional comment from Mohua Li on 2013-01-11 01:20:10 EST ---

 could reproduce in a guestmount mountpoint compare to the host filesystem,

--- Additional comment from RHEL Product and Program Management on 2013-01-14 01:47:53 EST ---

This request was not resolved in time for the current release.
Red Hat invites you to ask your support representative to
propose this request, if still desired, for consideration in
the next release of Red Hat Enterprise Linux.

Comment 1 Richard W.M. Jones 2013-01-21 15:41:46 UTC
Created attachment 684374 [details]
rename.sh

A self-contained script that demonstrates the bug.

Compare the output to the 'actual' and 'expected' cases above.

Comment 2 Richard W.M. Jones 2013-01-21 15:47:39 UTC
Running guestmount with the --trace option shows the following
API calls are made (I omitted some non-essential calls):

+ mkdir adir
libguestfs: trace: mkdir_mode "/adir" 509
libguestfs: trace: mkdir_mode = 0
+ mkdir bdir
libguestfs: trace: mkdir_mode "/bdir" 509
libguestfs: trace: mkdir_mode = 0
+ ln -s adir current
libguestfs: trace: ln_s "adir" "/current"
libguestfs: trace: ln_s = 0
+ ln -s bdir new
libguestfs: trace: ln_s "bdir" "/new"
libguestfs: trace: ln_s = 0
+ mv -T -f new current
libguestfs: trace: mv "/new" "/current"
libguestfs: trace: mv = 0