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

224 lines
5.1 KiB

  1. /*
  2. Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
  3. Permission to use, copy, modify, and/or distribute this software for any
  4. purpose with or without fee is hereby granted, provided that the above
  5. copyright notice and this permission notice appear in all copies.
  6. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  7. WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  8. MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  9. ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  10. WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  11. ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  12. OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  13. */
  14. #pragma once
  15. #include "branches.hpp"
  16. #include "category.hpp"
  17. #include "config_cachefiles.hpp"
  18. #include "config_flushonclose.hpp"
  19. #include "config_follow_symlinks.hpp"
  20. #include "config_pid.hpp"
  21. #include "config_inodecalc.hpp"
  22. #include "config_link_exdev.hpp"
  23. #include "config_log_metrics.hpp"
  24. #include "config_moveonenospc.hpp"
  25. #include "config_nfsopenhack.hpp"
  26. #include "config_rename_exdev.hpp"
  27. #include "config_set.hpp"
  28. #include "config_statfs.hpp"
  29. #include "config_statfsignore.hpp"
  30. #include "config_xattr.hpp"
  31. #include "enum.hpp"
  32. #include "errno.hpp"
  33. #include "funcs.hpp"
  34. #include "fuse_readdir.hpp"
  35. #include "policy.hpp"
  36. #include "rwlock.hpp"
  37. #include "tofrom_wrapper.hpp"
  38. #include "fuse.h"
  39. #include <cstdint>
  40. #include <map>
  41. #include <memory>
  42. #include <string>
  43. #include <vector>
  44. #include <sys/stat.h>
  45. typedef ToFromWrapper<bool> ConfigBOOL;
  46. typedef ToFromWrapper<uint64_t> ConfigUINT64;
  47. typedef ToFromWrapper<int> ConfigINT;
  48. typedef ToFromWrapper<std::string> ConfigSTR;
  49. typedef std::map<std::string,ToFromString*> Str2TFStrMap;
  50. extern const std::string CONTROLFILE;
  51. class Config
  52. {
  53. public:
  54. struct Err
  55. {
  56. int err;
  57. std::string str;
  58. };
  59. typedef std::vector<Err> ErrVec;
  60. public:
  61. class Read
  62. {
  63. public:
  64. Read();
  65. public:
  66. inline const Config* operator->() const;
  67. private:
  68. const Config &_cfg;
  69. };
  70. public:
  71. class Write
  72. {
  73. public:
  74. Write();
  75. public:
  76. Config* operator->();
  77. private:
  78. Config &_cfg;
  79. };
  80. public:
  81. Config();
  82. public:
  83. Config& operator=(const Config&);
  84. public:
  85. ConfigBOOL async_read;
  86. ConfigBOOL auto_cache;
  87. ConfigUINT64 minfreespace;
  88. Branches branches;
  89. ConfigUINT64 branches_mount_timeout;
  90. ConfigUINT64 cache_attr;
  91. ConfigUINT64 cache_entry;
  92. CacheFiles cache_files;
  93. ConfigSet cache_files_process_names;
  94. ConfigUINT64 cache_negative_entry;
  95. ConfigBOOL cache_readdir;
  96. ConfigUINT64 cache_statfs;
  97. ConfigBOOL cache_symlinks;
  98. Categories category;
  99. ConfigBOOL direct_io;
  100. ConfigBOOL dropcacheonclose;
  101. FlushOnClose flushonclose;
  102. FollowSymlinks follow_symlinks;
  103. ConfigSTR fsname;
  104. Funcs func;
  105. ConfigUINT64 fuse_msg_size;
  106. ConfigBOOL ignorepponrename;
  107. InodeCalc inodecalc;
  108. ConfigBOOL kernel_cache;
  109. ConfigBOOL lazy_umount_mountpoint;
  110. ConfigBOOL link_cow;
  111. LinkEXDEV link_exdev;
  112. LogMetrics log_metrics;
  113. ConfigSTR mountpoint;
  114. MoveOnENOSPC moveonenospc;
  115. NFSOpenHack nfsopenhack;
  116. ConfigBOOL nullrw;
  117. ConfigBOOL parallel_direct_writes;
  118. ConfigGetPid pid;
  119. ConfigBOOL posix_acl;
  120. ConfigUINT64 readahead;
  121. FUSE::ReadDir readdir;
  122. ConfigBOOL readdirplus;
  123. RenameEXDEV rename_exdev;
  124. ConfigINT scheduling_priority;
  125. ConfigBOOL security_capability;
  126. SrcMounts srcmounts;
  127. StatFS statfs;
  128. StatFSIgnore statfs_ignore;
  129. ConfigBOOL symlinkify;
  130. ConfigUINT64 symlinkify_timeout;
  131. ConfigINT fuse_read_thread_count;
  132. ConfigINT fuse_process_thread_count;
  133. ConfigINT fuse_process_thread_queue_depth;
  134. ConfigSTR fuse_pin_threads;
  135. ConfigSTR version;
  136. ConfigBOOL writeback_cache;
  137. XAttr xattr;
  138. private:
  139. bool _initialized;
  140. public:
  141. void finish_initializing();
  142. public:
  143. friend std::ostream& operator<<(std::ostream &s,
  144. const Config &c);
  145. public:
  146. bool has_key(const std::string &key) const;
  147. void keys(std::string &s) const;
  148. void keys_xattr(std::string &s) const;
  149. public:
  150. int get(const std::string &key, std::string *val) const;
  151. int set_raw(const std::string &key, const std::string &val);
  152. int set(const std::string &key, const std::string &val);
  153. int set(const std::string &kv);
  154. public:
  155. int from_stream(std::istream &istrm, ErrVec *errs);
  156. int from_file(const std::string &filepath, ErrVec *errs);
  157. private:
  158. Str2TFStrMap _map;
  159. private:
  160. static Config _singleton;
  161. public:
  162. friend class Read;
  163. friend class Write;
  164. };
  165. std::ostream& operator<<(std::ostream &s,const Config::ErrVec &ev);
  166. inline
  167. Config::Read::Read()
  168. : _cfg(Config::_singleton)
  169. {
  170. }
  171. inline
  172. const
  173. Config*
  174. Config::Read::operator->() const
  175. {
  176. return &_cfg;
  177. }
  178. inline
  179. Config::Write::Write()
  180. : _cfg(Config::_singleton)
  181. {
  182. }
  183. inline
  184. Config*
  185. Config::Write::operator->()
  186. {
  187. return &_cfg;
  188. }