From: @lixiachen Reviewed-by: @mikef,@robingrosman Signed-off-by: @robingrosmanpull/15547/MERGE
| @@ -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; | |||
| } | |||
| @@ -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_ | |||
| @@ -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(); | |||
| @@ -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); | |||
| @@ -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; | |||