Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Solaris - Synchronous Disk Flush/Synchronous Sync?

What is the best way to do synchronous disk flush on Solaris? I want to flush all disk, not a single file.

Sync() on Solaris (opposite to Linux) works ASYNCHRONOUSLY, I'm looking for SYNCHRONOUS sync() (it returns when it's done)

Consequent question: how to check sync is done properly? How can I write test showing it's done?

Thanks!

like image 533
Michal Avatar asked Dec 01 '25 18:12

Michal


1 Answers

You can run:

/usr/sbin/lockfs -af

Quoting lockfs manual page:

-f

     Force a synchronous flush of all data that is  dirty  at
     the  time  fsflush  is  run to its backing store for the
     named file system (or for all file systems.)

     It is a more reliable method than using sync(1M) because
     it  does  not  return  until  all possible data has been
     pushed.

If you want to do it purely in C, you might use

  #include <sys/filio.h>
  ...    
  ioctl(fd, _FIOFFS, NULL);

with fd being a file descriptor to the file system mount point (from /etc/mtab).

Beware though that _FIOFFS is a private interface so might disappear at any time without notice. A fully supported and more robust way would be to simply add the line system("/usr/sbin/lockfs -af"); to your code.

like image 97
jlliagre Avatar answered Dec 03 '25 13:12

jlliagre



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!