please help!! fsync() and fdatasync() big problems...

I’m using Qnx4.25. I’m trying to make sure the file is written to the disk
before the computer’s power is off. I tried using both fsync() and
fdatasync(), the help says these 2 functions doesnt return til the all the
data is written to the disk. From my debugging screen, i turn off the power
as soon as I see these 2 functions returns with 0 (meaing successful), but
after i turn back on the computer, the file is still showing the old data,
and few times, I got garbage in the file.

Ran Zhang <rzhang@vamcointernational.com> wrote:
RZ > I’m using Qnx4.25. I’m trying to make sure the file is written to the disk
RZ > before the computer’s power is off. I tried using both fsync() and
RZ > fdatasync(), the help says these 2 functions doesnt return til the all the
RZ > data is written to the disk. From my debugging screen, i turn off the power
RZ > as soon as I see these 2 functions returns with 0 (meaing successful), but
RZ > after i turn back on the computer, the file is still showing the old data,
RZ > and few times, I got garbage in the file.

The documentation is misleading. Everyone’s fought this battle before.

The functions return when the data is successfully written to Fsys Cache.
There is NO WAY to programaticly know when the data is written to the hard
drive, unless you wrote your own driver for the hard drive.

If you look at the documentation on Fsys there are a few command line
options that you might want to play with. They are:
Cache Size
Writback Delay
Asynchronous Writes

Basically you might want to tell Fsys never to return until data written to
cache is physically written to the hard drive. NOTE: This WILL slow down
all of your writes. But it will solve your problem.

Another thing you can try is to reduce the writeback delay. This says that
when data is X seconds old in cache, BEGIN writting it back to the hard
drive. There is no guarantee that the data will get written that quickly.
But it will close that window of opportunity for failure somewhat.

Good luck.

should I change the writeback delay for Fsys driver? I thought Fsys is only
been used for internal qnx file system, in order to speed up the
process writing to the hard drive? shouldn’t I modify the Fsys.eide? under
Fsys.eide, there is no anything related to writeback delay…


“Bill Caroselli” <qtps@earthlink.net> wrote in message
news:cpkeck$fol$2@inn.qnx.com

Ran Zhang <> rzhang@vamcointernational.com> > wrote:
RZ > I’m using Qnx4.25. I’m trying to make sure the file is written to
the disk
RZ > before the computer’s power is off. I tried using both fsync() and
RZ > fdatasync(), the help says these 2 functions doesnt return til the
all the
RZ > data is written to the disk. From my debugging screen, i turn off
the power
RZ > as soon as I see these 2 functions returns with 0 (meaing
successful), but
RZ > after i turn back on the computer, the file is still showing the old
data,
RZ > and few times, I got garbage in the file.

The documentation is misleading. Everyone’s fought this battle before.

The functions return when the data is successfully written to Fsys
Cache
.
There is NO WAY to programaticly know when the data is written to the hard
drive, unless you wrote your own driver for the hard drive.

If you look at the documentation on Fsys there are a few command line
options that you might want to play with. They are:
Cache Size
Writback Delay
Asynchronous Writes

Basically you might want to tell Fsys never to return until data written
to
cache is physically written to the hard drive. NOTE: This WILL slow down
all of your writes. But it will solve your problem.

Another thing you can try is to reduce the writeback delay. This says
that
when data is X seconds old in cache, BEGIN writting it back to the hard
drive. There is no guarantee that the data will get written that quickly.
But it will close that window of opportunity for failure somewhat.

Good luck.

As an idea…

You could still use the ‘sync’ function here and there to make sure the data
is flushed. Before you power off just do a ‘system(“shutdown -fb”);’ from
your code.

Augie


“Ran Zhang” <rzhang@vamcointernational.com> wrote in message
news:cpkbas$e8d$1@inn.qnx.com

I’m using Qnx4.25. I’m trying to make sure the file is written to the
disk
before the computer’s power is off. I tried using both fsync() and
fdatasync(), the help says these 2 functions doesnt return til the all the
data is written to the disk. From my debugging screen, i turn off the
power
as soon as I see these 2 functions returns with 0 (meaing successful),
but
after i turn back on the computer, the file is still showing the old data,
and few times, I got garbage in the file.

Ran Zhang <rzhang@vamcointernational.com> wrote:
RZ > should I change the writeback delay for Fsys driver? I thought Fsys is only
RZ > been used for internal qnx file system, in order to speed up the
RZ > process writing to the hard drive? shouldn’t I modify the Fsys.eide? under
RZ > Fsys.eide, there is no anything related to writeback delay…

This is an Fsys option, not a driver option. Therefore the same value
will apply for all drive types.

I would STRONGLY SUGGEST that you make sure you understand the consequences
of making the change. First, you will degrade system write performance.
Secondly, you will reduce the probibility but not eliminate the possibility
of the problem that you are experiencing from occuring again.

To be certain, you should do something like this:

  1. set the writeback delay to say 2 seconds
  2. when you want to shut down your system, shut down your application as
    gracefully as possible first.
  3. manually issue a ‘sync’ command. This can be done programmatically too.
  4. wait at least the number of seconds on your Fsys writeback delay, then
  5. wait until you see all hard drive activity stop on the hard drive LED.
  6. Now it is guaranteed to shutdown the power to your system.