Return EREMOTE when reading Glacier objects (#1705)

Previously s3fs returned EIO which was not helpful to the caller.
Returning a more specific error code allows automatically restoring
the object via RestoreObject in a subsequent commit.
References #1466.
This commit is contained in:
Andrew Gaul 2021-06-30 09:25:36 +09:00 committed by GitHub
parent 1965916f7a
commit 487df27008
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -47,6 +47,7 @@ static const std::string empty_md5_base64_hash = "1B2M2Y8AsgTpgAmY7PhCfg=="
// Class S3fsCurl // Class S3fsCurl
//------------------------------------------------------------------- //-------------------------------------------------------------------
static const int MULTIPART_SIZE = 10 * 1024 * 1024; static const int MULTIPART_SIZE = 10 * 1024 * 1024;
static const int GET_OBJECT_RESPONSE_LIMIT = 1024;
static const int IAM_EXPIRE_MERGIN = 20 * 60; // update timing static const int IAM_EXPIRE_MERGIN = 20 * 60; // update timing
static const std::string ECS_IAM_ENV_VAR = "AWS_CONTAINER_CREDENTIALS_RELATIVE_URI"; static const std::string ECS_IAM_ENV_VAR = "AWS_CONTAINER_CREDENTIALS_RELATIVE_URI";
@ -681,6 +682,11 @@ size_t S3fsCurl::DownloadWriteCallback(void* ptr, size_t size, size_t nmemb, voi
return 0; return 0;
} }
// Buffer initial bytes in case it is an XML error response.
if(pCurl->bodydata.size() < GET_OBJECT_RESPONSE_LIMIT){
pCurl->bodydata.Append(ptr, std::min(size * nmemb, GET_OBJECT_RESPONSE_LIMIT - pCurl->bodydata.size()));
}
// write size // write size
ssize_t copysize = (size * nmemb) < (size_t)pCurl->partdata.size ? (size * nmemb) : (size_t)pCurl->partdata.size; ssize_t copysize = (size * nmemb) < (size_t)pCurl->partdata.size ? (size * nmemb) : (size_t)pCurl->partdata.size;
ssize_t writebytes; ssize_t writebytes;
@ -2320,6 +2326,9 @@ int S3fsCurl::RequestPerform(bool dontAddAuthHeaders /*=false*/)
if(value == "EntityTooLarge"){ if(value == "EntityTooLarge"){
result = -EFBIG; result = -EFBIG;
break; break;
}else if(value == "InvalidObjectState"){
result = -EREMOTE;
break;
}else if(value == "KeyTooLongError"){ }else if(value == "KeyTooLongError"){
result = -ENAMETOOLONG; result = -ENAMETOOLONG;
break; break;