如何在同步/ fsync / syncfs到便携式设备后确保数据完整性 [英] How to make sure data integrity after sync/fsync/syncfs to portable device

查看:456
本文介绍了如何在同步/ fsync / syncfs到便携式设备后确保数据完整性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基于同步手册页,无法保证在调用同步后光盘将刷新其缓存:
根据标准规范(例如,POSIX.1-2001),sync()会调度写入,但是在实际写入完成之前可能会返回。但是,由于版本1.3.20 Linux确实在等待。(这仍然不能保证数据完整性:现代磁盘有大量缓存。)



并且,在fsync手册中,没有提到这一点。



有没有办法确保所有写入光盘特别是便携式设备(USB)的写入调用同步后完成?我遇到过调用sync / fsync后数据和元数据信息没有完全写入光盘的情况。
我很好奇Windows / linux中的安全删除设备如何知道所有数据都已由设备本身完全写入。

解决方案


我很好奇Windows / linux中的安全删除设备是如何知道所有数据都已由设备本身完全写入。


对于IXish系统:



使用 umount 命令 umount()系统调用






  blockdev --flushbufs 

可能会刷新设备的缓冲区,但不会让任何人再次访问设备和补充缓冲区。






此外, / proc 文件系统:

  / proc / sys / vm / drop_caches 

可用于冲洗不同的缓冲区:



https://www.kernel.org/doc/Documentation/sysctl/vm.txt


[...]



要释放dentries和inode:

  echo 2> / proc / sys / vm / drop_caches 

[...]



Based on sync manual page, there is no guarantee the disc will flush its cache after calling sync: "According to the standard specification (e.g., POSIX.1-2001), sync() schedules the writes, but may return before the actual writing is done. However, since version 1.3.20 Linux does actually wait. (This still does not guarantee data integrity: modern disks have large caches.) "

And, in fsync manual, there is no mention about this.

Is there ways to makes sure all writes to disc especially portable device (USB) has been finished after calling sync? I have encountered cases that data and metadata information has not fully written to disc after calling sync/fsync. I am curious how "Safely remove device" in windows/linux knows that all data has been fully written by the device itself.

解决方案

I am curious how "Safely remove device" in windows/linux knows that all data has been fully written by the device itself.

For IXish systems:

Unmount the USB-device's partitions using the umount command or the umount() system call.


Doing

blockdev --flushbufs

might flush the device's buffer, but does not keep anybody from accessing the devices again and refill buffers.


Also there is this kernel interface in the /proc file system:

/proc/sys/vm/drop_caches

which can be used to flush different buffers:

Verbatim from https://www.kernel.org/doc/Documentation/sysctl/vm.txt

[...]

To free dentries and inodes:

  echo 2 > /proc/sys/vm/drop_caches

[...]

这篇关于如何在同步/ fsync / syncfs到便携式设备后确保数据完整性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆