문제

I've got an application that at a high level performs SCSI READ10 and WRITE10 operations simultaneously. When they reach the lower-levels of my code they call write() followed by read() on /dev/sgXX. I'm getting very strange results on devices receiving my application's commands though, and they happen sporadically. Is having this low-level simultaneous write() / read() safe? Or could I possibly be thrashing data going to the HBA?

도움이 되었습니까?

해결책

Read and write should be by definition safe but:

1) Reading and writing, does it happen on the same file descriptor. If not, the open file table in your system can have multiple offsets, resulting in data read and write in an inconsistent way.

2) If you have a block of data that has to be written to your disk, do you use write in a for loop? This is not safe, because other read or write operations can be started between two write calls. Have a look at readv and writev to atomically write big data blocks.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top