This is a wrapper to the write syscall in order to retry on short writes * or if the syscall gets interrupted. It could look strange that we retry * on short writes given that we are writing to a block device: normally if * the first call is short, there is a end-of-space condition, so the next * is likely to fail. However apparently in modern systems this is no longer * true, and in general
| 320 | * true, and in general it looks just more resilient to retry the write. If |
| 321 | * there is an actual error condition we'll get it at the next try. */ |
| 322 | ssize_t aofWrite(int fd, const char *buf, size_t len) { |
| 323 | ssize_t nwritten = 0, totwritten = 0; |
| 324 | |
| 325 | while(len) { |
| 326 | nwritten = write(fd, buf, len); |
| 327 | |
| 328 | if (nwritten < 0) { |
| 329 | if (errno == EINTR) continue; |
| 330 | return totwritten ? totwritten : -1; |
| 331 | } |
| 332 | |
| 333 | len -= nwritten; |
| 334 | buf += nwritten; |
| 335 | totwritten += nwritten; |
| 336 | } |
| 337 | |
| 338 | return totwritten; |
| 339 | } |
| 340 | |
| 341 | /* Write the append only file buffer on disk. |
| 342 | * |
no test coverage detected