ext4, fsync(2), and perl

Josef Wolf jw at raven.inka.de
Fri Mar 5 08:13:14 UTC 2010


On Fri, Mar 05, 2010 at 10:37:04AM +0800, Christopher Chan wrote:
> On Friday, March 05, 2010 03:19 AM, Josef Wolf wrote:

Thanks for your response, Christopher!

[ ... ]
> >     # but for the directory, I have to comment the sync operations to
> >     # avoid an "illegal filehandle" error
> >     #
> >     my $hd = new IO::Handle;
> >     opendir ($hd, $histdir) or die "open $histdir: $!";
> >     link ($history, "$history-$ymd_hms") unless -e "$history-$ymd_hms";
> > #   $hd->sync or die "sync $histdir: $!";
> >     rename "$history.$$", $history or die "Cant rename: $!";
> > #   $hd->sync&&  $hd->closedir or die "closedir $histdir: $!";
> >
> > Any ideas how to properly fsync the directory in perl?
> 
>    my $hd;
>    open($hd, $histdir);
>    link ($history, "$history-$ymd_hms") unless -e "$history-$ymd_hms";
>    rename "$history.$$", $history or die "Cant rename: $!";
>    unless (fsync($hd)) {
>      print STDERR "error: problem fsync-ing directory '$histdir': $!\n";
>      close($dh);
>      return 0;
>    }
> 
> Try this?

This tells me I have to use IO::Handle::sync() instead. The POSIX manpage
states that fsync is deprecated. This is why I used IO::Handle in my original
example.

And when I try to use IO::Handle::sync on a directory opened with open()
like this

  my $hd = new IO::Handle;
  open ($hd, $dir) or die "open $dir: $!";
  $hd->sync or die "sync $dir: $!";
  $hd->close or die "close $dir: $!";

I get this error:

  sync /home/jw: Invalid argument at ./t.pl line 12.

I guess the problem is that the directory is opened in read-only mode. But
OTOH, the kernel will (hopefully) not let me open it in any other mode.

> > PS: http://thunk.org/tytso/blog/2009/03/15/dont-fear-the-fsync/
> 
> UFS and soft-updates anyone?

Do we have them in linux?




More information about the ubuntu-users mailing list