From e76852504e29d92f6998a1d46ac4e7cb45c2b329 Mon Sep 17 00:00:00 2001 From: wanghai01 Date: Thu, 30 Nov 2023 09:44:25 +0800 Subject: [PATCH] curvefs: fix list xattr miss someone Signed-off-by: wanghai01 --- curvefs/src/client/fuse_client.cpp | 17 +++++++++++++++++ curvefs/test/client/test_fuse_s3_client.cpp | 5 ++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/curvefs/src/client/fuse_client.cpp b/curvefs/src/client/fuse_client.cpp index 5feb64e94a..658f587351 100644 --- a/curvefs/src/client/fuse_client.cpp +++ b/curvefs/src/client/fuse_client.cpp @@ -1137,6 +1137,13 @@ CURVEFS_ERROR FuseClient::FuseOpListXattr(fuse_req_t req, fuse_ino_t ino, // +1 because, the format is key\0key\0 *realSize += it.first.length() + 1; } + // add summary xattr key + if (inodeAttr.type() == FsFileType::TYPE_DIRECTORY) { + *realSize += strlen(XATTR_DIR_RFILES) + 1; + *realSize += strlen(XATTR_DIR_RSUBDIRS) + 1; + *realSize += strlen(XATTR_DIR_RENTRIES) + 1; + *realSize += strlen(XATTR_DIR_RFBYTES) + 1; + } if (size == 0) { return CURVEFS_ERROR::OK; @@ -1150,6 +1157,16 @@ CURVEFS_ERROR FuseClient::FuseOpListXattr(fuse_req_t req, fuse_ino_t ino, memcpy(value, it.first.c_str(), tsize); value += tsize; } + if (inodeAttr.type() == FsFileType::TYPE_DIRECTORY) { + memcpy(value, XATTR_DIR_RFILES, strlen(XATTR_DIR_RFILES) + 1); + value += strlen(XATTR_DIR_RFILES) + 1; + memcpy(value, XATTR_DIR_RSUBDIRS, strlen(XATTR_DIR_RSUBDIRS) + 1); + value += strlen(XATTR_DIR_RSUBDIRS) + 1; + memcpy(value, XATTR_DIR_RENTRIES, strlen(XATTR_DIR_RENTRIES) + 1); + value += strlen(XATTR_DIR_RENTRIES) + 1; + memcpy(value, XATTR_DIR_RFBYTES, strlen(XATTR_DIR_RFBYTES) + 1); + value += strlen(XATTR_DIR_RFBYTES) + 1; + } return CURVEFS_ERROR::OK; } return CURVEFS_ERROR::OUT_OF_RANGE; diff --git a/curvefs/test/client/test_fuse_s3_client.cpp b/curvefs/test/client/test_fuse_s3_client.cpp index 3470c8dfcc..422c3c140f 100644 --- a/curvefs/test/client/test_fuse_s3_client.cpp +++ b/curvefs/test/client/test_fuse_s3_client.cpp @@ -4065,7 +4065,10 @@ TEST_F(TestFuseS3Client, FuseOpListXattr) { .WillOnce(DoAll(SetArgPointee<1>(inode), Return(CURVEFS_ERROR::OK))); ret = client_->FuseOpListXattr(req, ino, buf, size, &realSize); ASSERT_EQ(CURVEFS_ERROR::OK, ret); - auto expected = key.length() + 1; + auto expected = key.length() + 1 + strlen(XATTR_DIR_RFILES) + 1 + + strlen(XATTR_DIR_RSUBDIRS) + 1 + + strlen(XATTR_DIR_RENTRIES) + 1 + + strlen(XATTR_DIR_RFBYTES) + 1; ASSERT_EQ(realSize, expected); realSize = 0;