Personal tools
You are here: Home Issue tracker stat to unlinked file failes

#45 — stat to unlinked file failes

State Resolved
Version: 0.6.9
Area Functionality
Issue type Bug
Severity Medium
Submitted by Valentin Hilbig
Submitted on May 24, 2010
Responsible Seth Heeren
Target release: 0.6.9
Return to tracker
Last modified on May 10, 2011
fstat() call to unlinked file fails

I observed this because HERE-documents fail /tmp is a ZFS like in

cat <<EOF
Hello World
EOF

Verified on Debian Lenny and Squeeze.

Note that I think that this could be a FUSE limitation. In that case this is a FUSE bug, not a ZFS bug.

In this case sorry by reporting it here, but I have no other FUSE testbed except ZFS-FUSE.

-Tino
Steps to reproduce:
Compile unlinkcheck.c to unlinkcheck.



Then run on a NON-ZFS-directory:

./unlinkcheck testfile1
all ok: No such file or directory

Now repeat this on a ZFS directory:

./unlinkcheck /tank/testfile1
cannot stat deleted file: No such file or directory

Behavior should be the same, as using an unlinked file is a common way to work with tmpfiles, hence fstat() shall work.

File unlinkcheck.c (also attached):

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>

void die(const char *s) { perror(s); exit(1); abort(); }

int main(int argc, char **argv)
{
  struct stat st; const char *file; int fd;
  if (argc!=2 || (file=argv[1])==0) die("Usage: unlinkcheck file");
  if (!lstat(file,&st)) die("File must not exist");
  if ((fd = open(file, O_RDWR|O_CREAT|O_EXCL,0700))<0) die("cannot create file");
  if (unlink(file)) die("cannot unlink");
  if (fstat(fd,&st)) die("cannot stat deleted file");
  die("all ok");
  return 0;
}
Attached:
unlinkcheck.c — C source code, 0Kb
Added by Seth Heeren on May 27, 2010 02:32 PM
Issue state: unconfirmedopen
Responsible manager: (UNASSIGNED)sgheeren
Confirmed on Lucid

0.5.0 worked ok

0.6.0 (and later) didn't

Will bisect
Added by Seth Heeren on May 27, 2010 03:53 PM
oops, after correcting my script a bit:

cat <<"SOURCE" | gcc -xc -o /root/unlinkcheck
#include <stdlib.h>
#include <sys/stat.h>
#include <fcntl.h>

void die(const char *s, int code) { perror(s); exit(code); abort(); }

int main(int argc, char **argv)
{
  struct stat st; const char *file; int fd;
  if (argc!=2 || (file=argv[1])==0) die("Usage: unlinkcheck file", 125);
  if (!lstat(file,&st)) die("File must not exist", 125);
  if ((fd = open(file, O_RDWR|O_CREAT|O_EXCL,0700))<0) die("cannot create file", 125);
  if (unlink(file)) die("cannot unlink", 125);
  if (fstat(fd,&st)) die("cannot stat deleted file", 1);
  die("all ok", 0);
  return 0;
}
HERE

cat > /root/run.sh <<"RUN"
#!/bin/bash

(cd src && sed -i 's/-Werror//' SConstruct && scons -j5 debug=2 install >/dev/null) || exit 125
/root/dorky.sh || exit 125
find /tmp/mypool -delete
/root/unlinkcheck /tmp/mypool/test$RANDOM
RUN

git bisect start release_0.6.0 0.5.0
git bisect run /root/run.sh
...

There are only 'skip'ped commits left to test.
The first bad commit could be any of:
b0450a72169eb580dad4e94e5f618f1b021a3c4d
594cf26048660d3d2b7ce6d7d9612e66eff31a29
e02989dac9df05647e0e4d4d88f84211324e325a
81d8811f8f9b81ba326c13a6a4ca4422e87564a6
fab8bc751deb1afa6f0fdc4148c3c6614fe853af
72c8e68f63cadc2703bc1915fe9e6a6fe335ef0c
We cannot bisect more!
bisect run cannot continue any more
Added by Seth Heeren on May 27, 2010 05:51 PM
Target release: None0.6.9
I found that revision onnv_62-193-gea95fdf (May 2007) had this problem as well, which was subsequently fixed.

'git log --grep=zget' gives me a suspicion that in the pursuit of a compilation fix, 0.5.0-166-gfab8bc7 broke this.

Although this commit is exceptionally unclear, I've tried to remerge the changes

    git diff --color be06509e5fef5daa23^^..be06509e5fef5daa23

Lo and behold, this fixes the problem.
<strike>It also fixes the problem reported in issue #43... </strike> I had poopood on my test :(

Tino, thanks again for the report and, I might say, EXCELLENT steps to reproduce. That's a big help.
Added by Seth Heeren on Jun 04, 2010 11:53 AM
Issue state: openresolved
Closing (fix delivered 0.6.9)