ext4, fsync(2), and perl
Christopher Chan
christopher.chan at bradbury.edu.hk
Fri Mar 5 09:38:19 UTC 2010
On Friday, March 05, 2010 04:13 PM, Josef Wolf wrote:
> 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.
IO::Handle is for files only? I doubt that it will work with directories.
POSIX manpage says fsync is deprecated? That is highly impossible...not
if they want just about every program rewritten.
>
> 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.
>
IO::Handle is for files only I believe...
More information about the ubuntu-users
mailing list