Why is there read SCSI command during a sys_write()
-
19-06-2021 - |
문제
I want to understand how a sys_write
on a scsi device works. Therefore I wrote a simple test program, and added in the issue
function of the device driver some debug printk()
to print the ata_queued_cmd->scsicmd->cmnd
.
int main() {
int w;
char buffer[512] = "test string with 512 byte";
// OPEN
int fd = open("/dev/sdd", O_WRONLY | O_SYNC);
// WRITE
w = write(fd,buffer,sizeof(buffer));
return 0;
}
In /var/log/messages
I can see the following issued commands:
scsicmd->cmnd
------------------------------
0x28 | READ(10)
0x2A | WRITE(10)
0x35 | SYNCHRONIZE CACHE (10)
The 512 Byte I want to write should be the blocksize. This is how I get this value:
root$ blockdev --getsize /dev/sdd # returns size in sectors
488397168
root$ blockdev --getsize64 /dev/sdd # returns size in sectors
250059350016
root$ python -c "print 250059350016.0/488397168"
512.0
It's very important for me, that the data is power-failure safe written. That's the reason why I want to wait for the reuturn with O_SYNC
. Now I have some questions:
- Why is there a
READ
before theWRITE
? - Does the
SYNCHRONIZE CACHE
guarantee me, if the data is in the internal cache of the drive? Or is there more I could do to have a secure write?
Thank you very much :)
해결책
OK I figured it out now. They read it to load the data into an internal Kernel buffer, so when you have multiple writes/reads, the data is already buffered.
제휴하지 않습니다 StackOverflow