From 5624ecc8dfc5ce811fd8abffc47269cf72bfb2ee Mon Sep 17 00:00:00 2001 From: Benguang Zhao Date: Tue, 18 Jul 2023 10:04:00 +0800 Subject: [PATCH] fix: prepare vnode dir recursively in vnodeCreate --- include/libs/tfs/tfs.h | 9 +++++++++ source/dnode/vnode/src/vnd/vnodeOpen.c | 12 ++++++++++-- source/libs/tfs/src/tfs.c | 16 +++++++++++++++- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/include/libs/tfs/tfs.h b/include/libs/tfs/tfs.h index 988294be4b..ef8a4cfe1f 100644 --- a/include/libs/tfs/tfs.h +++ b/include/libs/tfs/tfs.h @@ -130,6 +130,15 @@ int32_t tfsMkdir(STfs *pTfs, const char *rname); */ int32_t tfsMkdirAt(STfs *pTfs, const char *rname, SDiskID diskId); +/** + * @brief Recursive make directory at all levels in tfs. + * + * @param pTfs The fs object. + * @param rname The rel name of directory. + * @return int32_t 0 for success, -1 for failure. + */ +int32_t tfsMkdirRecur(STfs *pTfs, const char *rname); + /** * @brief Recursive create directories in tfs. * diff --git a/source/dnode/vnode/src/vnd/vnodeOpen.c b/source/dnode/vnode/src/vnd/vnodeOpen.c index 6aa9be7b8a..4c30011d89 100644 --- a/source/dnode/vnode/src/vnd/vnodeOpen.c +++ b/source/dnode/vnode/src/vnd/vnodeOpen.c @@ -27,6 +27,14 @@ int32_t vnodeGetPrimaryDir(const char *relPath, int32_t diskPrimary, STfs *pTfs, return 0; } +static int32_t vnodeMkDir(STfs *pTfs, const char *path) { + if (pTfs) { + return tfsMkdirRecur(pTfs, path); + } else { + return taosMkDir(path); + } +} + int32_t vnodeCreate(const char *path, SVnodeCfg *pCfg, int32_t diskPrimary, STfs *pTfs) { SVnodeInfo info = {0}; char dir[TSDB_FILENAME_LEN] = {0}; @@ -38,8 +46,8 @@ int32_t vnodeCreate(const char *path, SVnodeCfg *pCfg, int32_t diskPrimary, STfs } // create vnode env - if ((pTfs) ? tfsMkdir(pTfs, path) : taosMkDir(path)) { - vError("vgId:%d, failed to mkdir since %s, dir: %s", pCfg->vgId, strerror(errno), path); + if (vnodeMkDir(pTfs, path)) { + vError("vgId:%d, failed to prepare vnode dir since %s, path: %s", pCfg->vgId, strerror(errno), path); return TAOS_SYSTEM_ERROR(errno); } vnodeGetPrimaryDir(path, diskPrimary, pTfs, dir, TSDB_FILENAME_LEN); diff --git a/source/libs/tfs/src/tfs.c b/source/libs/tfs/src/tfs.c index 7747f158b1..a0a95114ae 100644 --- a/source/libs/tfs/src/tfs.c +++ b/source/libs/tfs/src/tfs.c @@ -281,7 +281,7 @@ int32_t tfsMkdirRecurAt(STfs *pTfs, const char *rname, SDiskID diskId) { return 0; } -int32_t tfsMkdir(STfs *pTfs, const char *rname) { +int32_t tfsMkdirRecur(STfs *pTfs, const char *rname) { for (int32_t level = 0; level < pTfs->nlevel; level++) { STfsTier *pTier = TFS_TIER_AT(pTfs, level); for (int32_t id = 0; id < pTier->ndisk; id++) { @@ -295,6 +295,20 @@ int32_t tfsMkdir(STfs *pTfs, const char *rname) { return 0; } +int32_t tfsMkdir(STfs *pTfs, const char *rname) { + for (int32_t level = 0; level < pTfs->nlevel; level++) { + STfsTier *pTier = TFS_TIER_AT(pTfs, level); + for (int32_t id = 0; id < pTier->ndisk; id++) { + SDiskID did = {.id = id, .level = level}; + if (tfsMkdirAt(pTfs, rname, did) < 0) { + return -1; + } + } + } + + return 0; +} + bool tfsDirExistAt(STfs *pTfs, const char *rname, SDiskID diskId) { STfsDisk *pDisk = TFS_DISK_AT(pTfs, diskId); char aname[TMPNAME_LEN];