From 685b1ffb691988a7a7ade5e6ca65f0610352a226 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 6f1c0b4771..a5b367c9f3 100644 --- a/curvefs/src/client/fuse_client.cpp +++ b/curvefs/src/client/fuse_client.cpp @@ -1175,6 +1175,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; @@ -1188,6 +1195,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 7e55d6df77..d84e3afa29 100644 --- a/curvefs/test/client/test_fuse_s3_client.cpp +++ b/curvefs/test/client/test_fuse_s3_client.cpp @@ -4069,7 +4069,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;