From 8ffd210632418138abb4eeb13b4e5196bc1f7848 Mon Sep 17 00:00:00 2001 From: Lixia Chen Date: Tue, 20 Apr 2021 18:22:53 -0400 Subject: [PATCH] Change cache server default dir --- .../dataset/engine/cache/cache_admin.cc | 9 ++++++- .../dataset/engine/cache/cache_common.h | 15 +++++++---- .../dataset/engine/cache/cache_main.cc | 9 ++++++- mindspore/ccsrc/minddata/dataset/util/path.cc | 25 ++++++++++++------- mindspore/ccsrc/minddata/dataset/util/path.h | 6 +++-- 5 files changed, 46 insertions(+), 18 deletions(-) diff --git a/mindspore/ccsrc/minddata/dataset/engine/cache/cache_admin.cc b/mindspore/ccsrc/minddata/dataset/engine/cache/cache_admin.cc index e10619a63b6..449efbe3155 100644 --- a/mindspore/ccsrc/minddata/dataset/engine/cache/cache_admin.cc +++ b/mindspore/ccsrc/minddata/dataset/engine/cache/cache_admin.cc @@ -26,6 +26,13 @@ int main(int argc, char **argv) { ms::Status rc; ds::CacheAdminArgHandler args; std::stringstream arg_stream; + // Create the common path for all users + ds::Path common_dir = ds::Path(ds::kDefaultCommonPath); + rc = common_dir.CreateCommonDirectories(); + if (rc.IsError()) { + std::cerr << rc.ToString() << std::endl; + return 1; + } #ifdef USE_GLOG #define google mindspore_private @@ -34,7 +41,7 @@ int main(int argc, char **argv) { // Create default log dir ds::Path log_dir = ds::Path(FLAGS_log_dir); rc = log_dir.CreateDirectories(); - if (!rc.IsOk()) { + if (rc.IsError()) { std::cerr << rc.ToString() << std::endl; return 1; } diff --git a/mindspore/ccsrc/minddata/dataset/engine/cache/cache_common.h b/mindspore/ccsrc/minddata/dataset/engine/cache/cache_common.h index 40922fea23a..03cdf1daf97 100644 --- a/mindspore/ccsrc/minddata/dataset/engine/cache/cache_common.h +++ b/mindspore/ccsrc/minddata/dataset/engine/cache/cache_common.h @@ -48,8 +48,8 @@ constexpr static uint32_t kLocalClientSupport = 1; constexpr static uint32_t kDataIsInSharedMemory = 2; /// \brief Size of each message used in message queue. constexpr static int32_t kSharedMessageSize = 2048; -/// \brief Prefix for default cache spilling path and log path -const char kDefaultPathPrefix[] = "/tmp/mindspore/cache"; +/// \brief The default common path for all users +const char kDefaultCommonPath[] = "/tmp/mindspore/"; /// \brief State of CacheService at the server. enum class CacheServiceState : int8_t { @@ -73,7 +73,7 @@ inline void Status2CacheReply(const Status &rc, CacheReply *reply) { /// \param port /// \return unix socket url inline std::string PortToUnixSocketPath(int port) { - return kDefaultPathPrefix + std::string("/cache_server_p") + std::to_string(port); + return kDefaultCommonPath + std::string("/cache_server_p") + std::to_string(port); } /// \brief Round up to the next 4k @@ -92,8 +92,13 @@ using numa_id_t = int32_t; using cpu_id_t = int32_t; /// Return the default log dir for cache -inline std::string DefaultLogDir() { return kDefaultPathPrefix + std::string("/log"); } - +inline std::string DefaultLogDir() { +#if !defined(_WIN32) && !defined(_WIN64) && !defined(__ANDROID__) && !defined(ANDROID) && !defined(__APPLE__) + return kDefaultCommonPath + Services::GetUserName() + std::string("/cache/log"); +#else + return kDefaultCommonPath; +#endif +} } // namespace dataset } // namespace mindspore #endif // MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_CACHE_COMMON_H_ diff --git a/mindspore/ccsrc/minddata/dataset/engine/cache/cache_main.cc b/mindspore/ccsrc/minddata/dataset/engine/cache/cache_main.cc index c839cd601b5..aa68880a377 100644 --- a/mindspore/ccsrc/minddata/dataset/engine/cache/cache_main.cc +++ b/mindspore/ccsrc/minddata/dataset/engine/cache/cache_main.cc @@ -145,8 +145,15 @@ ms::Status StartServer(int argc, char **argv) { } int main(int argc, char **argv) { + // Create the common path for all users + ds::Path common_dir = ds::Path(ds::kDefaultCommonPath); + ms::Status rc = common_dir.CreateCommonDirectories(); + if (rc.IsError()) { + std::cerr << rc.ToString() << std::endl; + return 1; + } // This executable is not to be called directly, and should be invoked by cache_admin executable. - ms::Status rc = StartServer(argc, argv); + rc = StartServer(argc, argv); // Check result if (rc.IsError()) { auto errCode = rc.StatusCode(); diff --git a/mindspore/ccsrc/minddata/dataset/util/path.cc b/mindspore/ccsrc/minddata/dataset/util/path.cc index df61ccda279..bde43f2aaed 100644 --- a/mindspore/ccsrc/minddata/dataset/util/path.cc +++ b/mindspore/ccsrc/minddata/dataset/util/path.cc @@ -129,12 +129,15 @@ bool Path::IsDirectory() { } } -Status Path::CreateDirectory() { +Status Path::CreateDirectory(bool is_common_dir) { if (!Exists()) { #if defined(_WIN32) || defined(_WIN64) int rc = mkdir(common::SafeCStr(path_)); #else int rc = mkdir(common::SafeCStr(path_), S_IRUSR | S_IWUSR | S_IXUSR); + if (rc == 0 && is_common_dir) { + rc = chmod(common::SafeCStr(path_), S_IRWXU | S_IRWXG | S_IRWXO); + } #endif if (rc) { std::ostringstream oss; @@ -166,7 +169,7 @@ std::string Path::ParentPath() { return r; } -Status Path::CreateDirectories() { +Status Path::CreateDirectories(bool is_common_dir) { if (IsDirectory()) { MS_LOG(DEBUG) << "Directory " << toString() << " already exists."; return Status::OK(); @@ -174,16 +177,18 @@ Status Path::CreateDirectories() { MS_LOG(DEBUG) << "Creating directory " << toString() << "."; std::string parent = ParentPath(); if (!parent.empty()) { - if (Path(parent).CreateDirectories()) { - return CreateDirectory(); + if (Path(parent).CreateDirectories(is_common_dir)) { + return CreateDirectory(is_common_dir); } } else { - return CreateDirectory(); + return CreateDirectory(is_common_dir); } } return Status::OK(); } +Status Path::CreateCommonDirectories() { return CreateDirectories(true); } + Status Path::Remove() { if (Exists()) { if (IsDirectory()) { @@ -223,19 +228,21 @@ Status Path::OpenFile(int *file_descriptor, bool create) { } char canonical_path[PATH_MAX + 1] = {0x00}; #if defined(_WIN32) || defined(_WIN64) - if (_fullpath(canonical_path, common::SafeCStr(path_), PATH_MAX) == nullptr) { + auto err = _fullpath(canonical_path, common::SafeCStr(path_), PATH_MAX); #else - if (realpath(common::SafeCStr(path_), canonical_path) == nullptr) { + auto err = realpath(common::SafeCStr(path_), canonical_path); #endif + if (err == nullptr) { if (errno == ENOENT && create) { // File doesn't exist and we are to create it. Let's break it down. auto file_part = Basename(); auto parent_part = ParentPath(); #if defined(_WIN32) || defined(_WIN64) - if (_fullpath(canonical_path, common::SafeCStr(parent_part), PATH_MAX) == nullptr) { + auto parent_err = _fullpath(canonical_path, common::SafeCStr(parent_part), PATH_MAX); #else - if (realpath(common::SafeCStr(parent_part), canonical_path) == nullptr) { + auto parent_err = realpath(common::SafeCStr(parent_part), canonical_path); #endif + if (parent_err == nullptr) { RETURN_STATUS_UNEXPECTED(strerror(errno)); } auto cur_inx = strlen(canonical_path); diff --git a/mindspore/ccsrc/minddata/dataset/util/path.h b/mindspore/ccsrc/minddata/dataset/util/path.h index 5e7f9cd7b16..cb131ad5ae0 100644 --- a/mindspore/ccsrc/minddata/dataset/util/path.h +++ b/mindspore/ccsrc/minddata/dataset/util/path.h @@ -94,9 +94,11 @@ class Path { bool IsDirectory(); - Status CreateDirectory(); + Status CreateDirectory(bool is_common_dir = false); - Status CreateDirectories(); + Status CreateDirectories(bool is_common_dir = false); + + Status CreateCommonDirectories(); std::string Extension() const;