Skip to content

Commit

Permalink
fix getxattr return wrong length
Browse files Browse the repository at this point in the history
Signed-off-by: wanghai01 <[email protected]>
  • Loading branch information
SeanHai committed Jan 16, 2023
1 parent 796195d commit 47e86ad
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 74 deletions.
8 changes: 4 additions & 4 deletions curvefs/proto/metaserver.proto
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ message Inode {
map<uint64, S3ChunkInfoList> s3ChunkInfoMap = 18; // TYPE_S3 only, first is chunk index
optional uint32 dtime = 19;
optional uint32 openmpcount = 20; // openmpcount mount points had the file open
map<string, string> xattr = 21;
map<string, bytes> xattr = 21;
repeated uint64 parent = 22;
}

Expand Down Expand Up @@ -314,7 +314,7 @@ message UpdateInodeRequest {
map<uint64, S3ChunkInfoList> s3ChunkInfoMap = 17;
optional uint32 nlink = 18;
// field 19 is left for compatibility
map<string, string> xattr = 20;
map<string, bytes> xattr = 20;
repeated uint64 parent = 21;
map<uint64, S3ChunkInfoList> s3ChunkInfoAdd = 22;
optional VolumeExtentList volumeExtents = 23;
Expand Down Expand Up @@ -407,7 +407,7 @@ message InodeAttr {
optional uint64 rdev = 16;
optional uint32 dtime = 17;
optional uint32 openmpcount = 18;
map<string, string> xattr = 19;
map<string, bytes> xattr = 19;
repeated uint64 parent = 20;
}

Expand Down Expand Up @@ -438,7 +438,7 @@ message BatchGetXAttrRequest {
message XAttr {
required uint64 inodeId = 1;
required uint32 fsId = 2;
map<string, string> xAttrInfos = 3;
map<string, bytes> xAttrInfos = 3;
}

message BatchGetXAttrResponse {
Expand Down
3 changes: 2 additions & 1 deletion curvefs/src/client/common/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ enum class MetaServerOpType {

std::ostream &operator<<(std::ostream &os, MetaServerOpType optype);

const uint32_t MAXXATTRLENGTH = 256;
const uint32_t MAX_XATTR_NAME_LENGTH = 255;
const uint32_t MAX_XATTR_VALUE_LENGTH = 64 * 1024;

const char kCurveFsWarmupXAttr[] = "curvefs.warmup.op";

Expand Down
9 changes: 4 additions & 5 deletions curvefs/src/client/curve_fuse_op.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ using ::curvefs::client::FuseClient;
using ::curvefs::client::FuseS3Client;
using ::curvefs::client::FuseVolumeClient;
using ::curvefs::client::common::FuseClientOption;
using ::curvefs::client::common::MAXXATTRLENGTH;
using ::curvefs::client::rpcclient::MdsClientImpl;
using ::curvefs::client::rpcclient::MDSBaseClient;
using ::curvefs::client::metric::ClientOpMetric;
Expand Down Expand Up @@ -344,19 +343,19 @@ void FuseOpGetXattr(fuse_req_t req, fuse_ino_t ino, const char *name,
size_t size) {
InflightGuard guard(&g_clientOpMetric->opGetXattr.inflightOpNum);
LatencyUpdater updater(&g_clientOpMetric->opGetXattr.latency);
char buf[MAXXATTRLENGTH] = {0};
std::string buf;
CURVEFS_ERROR ret = g_ClientInstance->FuseOpGetXattr(req, ino, name,
buf, size);
&buf, size);
if (ret != CURVEFS_ERROR::OK) {
g_clientOpMetric->opGetXattr.ecount << 1;
FuseReplyErrByErrCode(req, ret);
return;
}

if (size == 0) {
fuse_reply_xattr(req, strlen(buf));
fuse_reply_xattr(req, buf.length());
} else {
fuse_reply_buf(req, buf, strlen(buf));
fuse_reply_buf(req, buf.data(), buf.length());
}
}

Expand Down
27 changes: 16 additions & 11 deletions curvefs/src/client/fuse_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ using ::curvefs::common::S3Info;
using ::curvefs::common::Volume;
using ::curvefs::mds::topology::PartitionTxId;
using ::curvefs::mds::FSStatusCode_Name;
using ::curvefs::client::common::MAXXATTRLENGTH;
using ::curvefs::client::common::MAX_XATTR_NAME_LENGTH;
using ::curvefs::client::common::MAX_XATTR_VALUE_LENGTH;
using ::curvefs::client::common::FileHandle;

#define RETURN_IF_UNSUCCESS(action) \
Expand Down Expand Up @@ -1325,15 +1326,14 @@ CURVEFS_ERROR FuseClient::FuseOpSetAttr(fuse_req_t req, fuse_ino_t ino,
}

CURVEFS_ERROR FuseClient::FuseOpGetXattr(fuse_req_t req, fuse_ino_t ino,
const char* name, void* value,
const char* name, std::string* value,
size_t size) {
VLOG(9) << "FuseOpGetXattr, ino: " << ino
<< ", name: " << name << ", size = " << size;
if (option_.disableXattr) {
return CURVEFS_ERROR::NOTSUPPORT;
}

std::string xValue;
InodeAttr inodeAttr;
CURVEFS_ERROR ret = inodeManager_->GetInodeAttr(ino, &inodeAttr);
if (ret != CURVEFS_ERROR::OK) {
Expand All @@ -1342,17 +1342,20 @@ CURVEFS_ERROR FuseClient::FuseOpGetXattr(fuse_req_t req, fuse_ino_t ino,
return ret;
}

ret = xattrManager_->GetXattr(name, &xValue, &inodeAttr, enableSumInDir_);
ret = xattrManager_->GetXattr(name, value, &inodeAttr, enableSumInDir_);
if (CURVEFS_ERROR::OK != ret) {
LOG(ERROR) << "xattrManager get xattr failed, name = " << name;
return ret;
}

ret = CURVEFS_ERROR::NODATA;
if (xValue.length() > 0) {
if ((size == 0 && xValue.length() <= MAXXATTRLENGTH) ||
(size >= xValue.length() && xValue.length() <= MAXXATTRLENGTH)) {
memcpy(value, xValue.c_str(), xValue.length());
if (value->length() > 0) {
if ((size == 0 && value->length() <= MAX_XATTR_VALUE_LENGTH) ||
(size >= value->length() &&
value->length() <= MAX_XATTR_VALUE_LENGTH)) {
VLOG(1) << "FuseOpGetXattr name = " << name
<< ", length = " << value->length()
<< ", value = " << *value;
ret = CURVEFS_ERROR::OK;
} else {
ret = CURVEFS_ERROR::OUT_OF_RANGE;
Expand All @@ -1364,15 +1367,17 @@ CURVEFS_ERROR FuseClient::FuseOpGetXattr(fuse_req_t req, fuse_ino_t ino,
CURVEFS_ERROR FuseClient::FuseOpSetXattr(fuse_req_t req, fuse_ino_t ino,
const char* name, const char* value,
size_t size, int flags) {
VLOG(1) << "FuseOpSetXattr ino: " << ino << ", name: " << name
<< ", value: " << value;
if (option_.disableXattr) {
return CURVEFS_ERROR::NOTSUPPORT;
}

std::string strname(name);
std::string strvalue(value, size);
if (strname.length() > MAXXATTRLENGTH || size > MAXXATTRLENGTH) {
VLOG(1) << "FuseOpSetXattr ino: " << ino << ", name: " << name
<< ", size = " << size
<< ", strvalue: " << strvalue;
if (strname.length() > MAX_XATTR_NAME_LENGTH ||
size > MAX_XATTR_VALUE_LENGTH) {
LOG(ERROR) << "xattr length is too long, name = " << name
<< ", name length = " << strname.length()
<< ", value length = " << size;
Expand Down
2 changes: 1 addition & 1 deletion curvefs/src/client/fuse_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class FuseClient {
struct stat* attrOut);

virtual CURVEFS_ERROR FuseOpGetXattr(fuse_req_t req, fuse_ino_t ino,
const char* name, void* value,
const char* name, std::string* value,
size_t size);

virtual CURVEFS_ERROR FuseOpSetXattr(fuse_req_t req, fuse_ino_t ino,
Expand Down
Loading

0 comments on commit 47e86ad

Please sign in to comment.