mirror of
https://github.com/vgough/encfs.git
synced 2024-11-22 07:53:31 +01:00
Make write() write all its data even if it takes time
This commit is contained in:
parent
8e13120b18
commit
acbeb64765
@ -203,10 +203,10 @@ ssize_t RawFileIO::read(const IORequest &req) const {
|
|||||||
rAssert(fd >= 0);
|
rAssert(fd >= 0);
|
||||||
|
|
||||||
ssize_t readSize = pread(fd, req.data, req.dataLen, req.offset);
|
ssize_t readSize = pread(fd, req.data, req.dataLen, req.offset);
|
||||||
int eno = errno;
|
|
||||||
errno = 0; //just to be sure error seen in integration tests really comes from the function rc.
|
|
||||||
|
|
||||||
if (readSize < 0) {
|
if (readSize < 0) {
|
||||||
|
int eno = errno;
|
||||||
|
errno = 0; //just to be sure error seen in integration tests really comes from the function rc.
|
||||||
RLOG(WARNING) << "read failed at offset " << req.offset << " for "
|
RLOG(WARNING) << "read failed at offset " << req.offset << " for "
|
||||||
<< req.dataLen << " bytes: " << strerror(eno);
|
<< req.dataLen << " bytes: " << strerror(eno);
|
||||||
return -eno;
|
return -eno;
|
||||||
@ -219,37 +219,43 @@ ssize_t RawFileIO::write(const IORequest &req) {
|
|||||||
rAssert(fd >= 0);
|
rAssert(fd >= 0);
|
||||||
rAssert(canWrite);
|
rAssert(canWrite);
|
||||||
|
|
||||||
int retrys = 10;
|
// int retrys = 10;
|
||||||
void *buf = req.data;
|
void *buf = req.data;
|
||||||
ssize_t bytes = req.dataLen;
|
ssize_t bytes = req.dataLen;
|
||||||
off_t offset = req.offset;
|
off_t offset = req.offset;
|
||||||
|
|
||||||
int eno = 0;
|
/*
|
||||||
while ((bytes != 0) && retrys > 0) {
|
* Let's write while pwrite() writes, to avoid writing only a part of the request,
|
||||||
errno = 0;
|
* whereas it could have been fully written. This to avoid inconsistencies / corruption.
|
||||||
|
*/
|
||||||
|
// while ((bytes != 0) && retrys > 0) {
|
||||||
|
while (bytes != 0) {
|
||||||
ssize_t writeSize = ::pwrite(fd, buf, bytes, offset);
|
ssize_t writeSize = ::pwrite(fd, buf, bytes, offset);
|
||||||
eno = errno;
|
|
||||||
errno = 0; //just to be sure error seen in integration tests really comes from the function rc.
|
|
||||||
|
|
||||||
if (writeSize < 0) {
|
if (writeSize <= 0) {
|
||||||
|
int eno = errno;
|
||||||
|
errno = 0; //just to be sure error seen in integration tests really comes from the function rc.
|
||||||
knownSize = false;
|
knownSize = false;
|
||||||
RLOG(WARNING) << "write failed at offset " << offset << " for " << bytes
|
RLOG(WARNING) << "write failed at offset " << offset << " for " << bytes
|
||||||
<< " bytes: " << strerror(eno);
|
<< " bytes: " << strerror(eno);
|
||||||
|
// pwrite is not expected to return 0, so eno should always be set, but we never know...
|
||||||
|
if (eno) {
|
||||||
return -eno;
|
return -eno;
|
||||||
}
|
}
|
||||||
|
return -EIO;
|
||||||
|
}
|
||||||
|
|
||||||
bytes -= writeSize;
|
bytes -= writeSize;
|
||||||
offset += writeSize;
|
offset += writeSize;
|
||||||
buf = (void *)((char *)buf + writeSize);
|
buf = (void *)((char *)buf + writeSize);
|
||||||
--retrys;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bytes != 0) {
|
// if (bytes != 0) {
|
||||||
RLOG(ERROR) << "Write error: wrote " << req.dataLen - bytes << " bytes of "
|
// RLOG(ERROR) << "Write error: wrote " << req.dataLen - bytes << " bytes of "
|
||||||
<< req.dataLen << ", max retries reached";
|
// << req.dataLen << ", max retries reached";
|
||||||
knownSize = false;
|
// knownSize = false;
|
||||||
return (eno) ? -eno : -EIO;
|
// return (eno) ? -eno : -EIO;
|
||||||
}
|
// }
|
||||||
if (knownSize) {
|
if (knownSize) {
|
||||||
off_t last = req.offset + req.dataLen;
|
off_t last = req.offset + req.dataLen;
|
||||||
if (last > fileSize) {
|
if (last > fileSize) {
|
||||||
|
Loading…
Reference in New Issue
Block a user