You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

storage_container.h 2.2 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /**
  2. * Copyright 2019 Huawei Technologies Co., Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef DATASET_UTIL_STORAGE_CONTAINER_H_
  17. #define DATASET_UTIL_STORAGE_CONTAINER_H_
  18. #include <limits.h>
  19. #include <unistd.h>
  20. #include <memory>
  21. #include <mutex>
  22. #include <string>
  23. #include <vector>
  24. #include "dataset/util/system_pool.h"
  25. #include "dataset/util/buddy.h"
  26. #include "dataset/util/path.h"
  27. #include "dataset/util/slice.h"
  28. #include "dataset/util/status.h"
  29. namespace mindspore {
  30. namespace dataset {
  31. class StorageManager;
  32. class StorageContainer {
  33. public:
  34. friend class StorageManager;
  35. ~StorageContainer() noexcept;
  36. StorageContainer(const StorageContainer &) = delete;
  37. StorageContainer &operator=(const StorageContainer &) = delete;
  38. friend std::ostream &operator<<(std::ostream &os, const StorageContainer &s);
  39. Status Open() noexcept;
  40. Status Close() noexcept;
  41. Status Insert(const std::vector<ReadableSlice> &buf, off64_t *offset) noexcept;
  42. Status Write(const ReadableSlice &dest, off64_t offset) const noexcept;
  43. Status Read(WritableSlice *dest, off64_t offset) const noexcept;
  44. Status Truncate() const noexcept;
  45. bool IsOpen() const { return is_open_; }
  46. static Status CreateStorageContainer(std::shared_ptr<StorageContainer> *out_sc, const std::string &path);
  47. private:
  48. mutable std::mutex mutex_;
  49. Path cont_;
  50. int fd_;
  51. bool is_open_;
  52. std::unique_ptr<BuddySpace> bs_;
  53. // Use the default value of BuddySpace
  54. // which can map upto 4G of space.
  55. explicit StorageContainer(const std::string &path) : cont_(path), fd_(-1), is_open_(false), bs_(nullptr) {}
  56. Status Create();
  57. };
  58. } // namespace dataset
  59. } // namespace mindspore
  60. #endif // DATASET_UTIL_STORAGE_CONTAINER_H_