Bug 1293276

Summary: guestfish can not ll a symbolic link dir or edit a file in it
Product: Red Hat Enterprise Linux 6 Reporter: Xianghua Chen <xchen>
Component: libguestfsAssignee: Pino Toscano <ptoscano>
Status: CLOSED ERRATA QA Contact: Virtualization Bugs <virt-bugs>
Severity: medium Docs Contact:
Priority: medium    
Version: 6.8CC: huzhan, linl, ptoscano, wshi, xchen
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: libguestfs-1.20.11-17.el6 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2016-05-10 19:56:23 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: 1301844    

Description Xianghua Chen 2015-12-21 09:41:27 UTC
Description of problem:
guestfish can not ll a symbolic link  dir  or edit a file in it

Version-Release number of selected component (if applicable):
libguestfs-1.20.11-16.el6.x86_64

How reproducible:
100%

Steps to Reproduce:
1. Prepare a image: RHEL-Server-6.7-32-hvm.raw
2. # guestfish -a RHEL-Server-6.7-32-hvm.raw -i
><fs> mkdir /home/testdir
><fs> ln-s /home/testdir/ /home/testdir_link
><fs> touch /home/testdir_link/file1
><fs> vi /home/testdir_link/file1
libguestfs: error: mv: mv: cannot stat `/sysroot/home/testdir_link/suaRydJi': No such file or directory
><fs> ll /home/testdir_link/
libguestfs: error: ll: ls: cannot access /sysroot/home/testdir_link/: No such file or directory
><fs> ll /home/testdir/
total 12
drwxr-xr-x  2 root root 4096 Dec 18 13:24 .
drwxr-xr-x. 3 root root 4096 Dec 18 13:23 ..
-rw-r--r--  1 root root   10 Dec 18 13:24 suaRydJi
-rw-r--r--  1 root root    0 Dec 18 13:23 file1



Actual results:
At step 2,
When vi the file1 , type something and save, it can not save successfully. But it will create a new file for you with the content you typed.
When ll the /home/testdir_link/, It can not list the content.

Expected results:
It can ll the symbolic link  dir and edit file1 in it.

Additional info:
1. In RHEL7.2(libguestfs-1.28.1-55.el7.x86_64) , it can edit file1 successfully, but can not ll the /home/testdir_link/ either.
2. Here is the trace log for the two command:
><fs> vi /home/testdir_link/file1
libguestfs: trace: get_tmpdir
libguestfs: trace: get_tmpdir = "/tmp"
libguestfs: trace: download "/home/testdir_link/file1" "/dev/fd/8"
libguestfs: send_to_daemon: 72 bytes: 00 00 00 44 | 20 00 f5 f5 | 00 00 00 04 | 00 00 00 43 | 00 00 00 00 | ...
libguestfs: recv_from_daemon: 40 bytes: 20 00 f5 f5 | 00 00 00 04 | 00 00 00 43 | 00 00 00 01 | 00 12 34 58 | ...
libguestfs: recv_from_daemon: 8 bytes: 00 00 00 00 | 00 00 00 00 |
libguestfs: trace: download = 0
libguestfs: trace: upload "/tmp/guestfishzuyAWL" "/home/testdir_link/suaRydJi"
libguestfs: send_to_daemon: 76 bytes: 00 00 00 48 | 20 00 f5 f5 | 00 00 00 04 | 00 00 00 42 | 00 00 00 00 | ...
libguestfs: send_to_daemon: 24 bytes: 00 00 00 14 | 00 00 00 00 | 00 00 00 0c | 6c 73 61 6a | 64 67 6c 6a | ...
libguestfs: send_to_daemon: 12 bytes: 00 00 00 08 | 00 00 00 00 | 00 00 00 00 |
libguestfs: recv_from_daemon: 40 bytes: 20 00 f5 f5 | 00 00 00 04 | 00 00 00 42 | 00 00 00 01 | 00 12 34 59 | ...
libguestfs: trace: upload = 0
libguestfs: trace: available "linuxxattrs"
libguestfs: send_to_daemon: 64 bytes: 00 00 00 3c | 20 00 f5 f5 | 00 00 00 04 | 00 00 00 d8 | 00 00 00 00 | ...
libguestfs: recv_from_daemon: 40 bytes: 20 00 f5 f5 | 00 00 00 04 | 00 00 00 d8 | 00 00 00 01 | 00 12 34 5a | ...
libguestfs: trace: available = 0
libguestfs: trace: stat "/home/testdir_link/file1"
libguestfs: send_to_daemon: 72 bytes: 00 00 00 44 | 20 00 f5 f5 | 00 00 00 04 | 00 00 00 34 | 00 00 00 00 | ...
libguestfs: recv_from_daemon: 144 bytes: 20 00 f5 f5 | 00 00 00 04 | 00 00 00 34 | 00 00 00 01 | 00 12 34 5b | ...
libguestfs: trace: stat = <struct guestfs_stat *>
libguestfs: trace: getxattr "/home/testdir_link/file1" "security.selinux"
libguestfs: send_to_daemon: 92 bytes: 00 00 00 58 | 20 00 f5 f5 | 00 00 00 04 | 00 00 01 17 | 00 00 00 00 | ...
guestfsd: error: getxattr: No data available
libguestfs: recv_from_daemon: 84 bytes: 20 00 f5 f5 | 00 00 00 04 | 00 00 01 17 | 00 00 00 01 | 00 12 34 5c | ...
libguestfs: trace: getxattr = NULL (error)
libguestfs: trace: chmod 420 "/home/testdir_link/suaRydJi"
libguestfs: send_to_daemon: 80 bytes: 00 00 00 4c | 20 00 f5 f5 | 00 00 00 04 | 00 00 00 22 | 00 00 00 00 | ...
libguestfs: recv_from_daemon: 40 bytes: 20 00 f5 f5 | 00 00 00 04 | 00 00 00 22 | 00 00 00 01 | 00 12 34 5d | ...
libguestfs: trace: chmod = 0
libguestfs: trace: chown 0 0 "/home/testdir_link/suaRydJi"
libguestfs: send_to_daemon: 84 bytes: 00 00 00 50 | 20 00 f5 f5 | 00 00 00 04 | 00 00 00 23 | 00 00 00 00 | ...
libguestfs: recv_from_daemon: 40 bytes: 20 00 f5 f5 | 00 00 00 04 | 00 00 00 23 | 00 00 00 01 | 00 12 34 5e | ...
libguestfs: trace: chown = 0
libguestfs: trace: mv "/home/testdir_link/suaRydJi" "/home/testdir_link/file1"
libguestfs: send_to_daemon: 104 bytes: 00 00 00 64 | 20 00 f5 f5 | 00 00 00 04 | 00 00 00 59 | 00 00 00 00 | ...
guestfsd: error: mv: cannot stat `/sysroot/home/testdir_link/suaRydJi': No such file or directory
libguestfs: recv_from_daemon: 128 bytes: 20 00 f5 f5 | 00 00 00 04 | 00 00 00 59 | 00 00 00 01 | 00 12 34 5f | ...
libguestfs: trace: mv = -1 (error)
libguestfs: error: mv: mv: cannot stat `/sysroot/home/testdir_link/suaRydJi': No such file or directory

><fs> ll /home/testdir_link/
libguestfs: trace: ll "/home/testdir_link/"
libguestfs: send_to_daemon: 68 bytes: 00 00 00 40 | 20 00 f5 f5 | 00 00 00 04 | 00 00 00 05 | 00 00 00 00 | ...
guestfsd: error: ls: cannot access /sysroot/home/testdir_link/: No such file or directory
libguestfs: recv_from_daemon: 120 bytes: 20 00 f5 f5 | 00 00 00 04 | 00 00 00 05 | 00 00 00 01 | 00 12 34 60 | ...
libguestfs: trace: ll = NULL (error)
libguestfs: error: ll: ls: cannot access /sysroot/home/testdir_link/: No such file or directory

Comment 1 Richard W.M. Jones 2016-01-04 13:13:33 UTC
The one line reproducers for both of these (different) problems are:

guestfish -N fs -m /dev/sda1 mkdir /dir : ln-s /dir/ /link : touch /link/file1 : vi /link/file1

guestfish -N fs -m /dev/sda1 mkdir /dir : ln-s /dir/ /link : touch /link/file1 : ll /link/

On RHEL 6.7, both commands give me errors.

Upstream, the 'vi' test is OK, but the 'll' test fails.

Comment 2 Pino Toscano 2016-01-14 16:47:52 UTC
(In reply to Richard W.M. Jones from comment #1)
> guestfish -N fs -m /dev/sda1 mkdir /dir : ln-s /dir/ /link : touch
> /link/file1 : vi /link/file1

I think this has been fixed with 431cdfd983bc9864d6a44a456a97b72455bb17cd, though that applies on the refactoring of the "edit" code (meaning this will need to be duplicated in fish/edit.c and edit/virt-edit.c).

Comment 3 Pino Toscano 2016-01-14 16:51:48 UTC
(In reply to Richard W.M. Jones from comment #1)
> guestfish -N fs -m /dev/sda1 mkdir /dir : ln-s /dir/ /link : touch
> /link/file1 : ll /link/

ll is special, as it is executed from the appliance and not from the guest -- that means absolute symlinks won't work. A fix for that could be to just resolve the path in advance, and execute ls on that instead.

Comment 6 Pino Toscano 2016-01-15 10:35:15 UTC
(In reply to Pino Toscano from comment #3)
> (In reply to Richard W.M. Jones from comment #1)
> > guestfish -N fs -m /dev/sda1 mkdir /dir : ln-s /dir/ /link : touch
> > /link/file1 : ll /link/
> 
> ll is special, as it is executed from the appliance and not from the guest
> -- that means absolute symlinks won't work. A fix for that could be to just
> resolve the path in advance, and execute ls on that instead.

Patch posted for this:
  https://www.redhat.com/archives/libguestfs/2016-January/msg00063.html

Comment 11 errata-xmlrpc 2016-05-10 19:56:23 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://rhn.redhat.com/errata/RHBA-2016-0762.html