1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef _BCACHEFS_OPTS_H 3 #define _BCACHEFS_OPTS_H 4 5 #include <linux/bug.h> 6 #include <linux/log2.h> 7 #include <linux/string.h> 8 #include <linux/sysfs.h> 9 #include "bcachefs_format.h" 10 11 struct bch_fs; 12 13 extern const char * const bch2_error_actions[]; 14 extern const char * const bch2_fsck_fix_opts[]; 15 extern const char * const bch2_version_upgrade_opts[]; 16 extern const char * const bch2_sb_features[]; 17 extern const char * const bch2_sb_compat[]; 18 extern const char * const __bch2_btree_ids[]; 19 extern const char * const __bch2_csum_types[]; 20 extern const char * const __bch2_csum_opts[]; 21 extern const char * const __bch2_compression_types[]; 22 extern const char * const bch2_compression_opts[]; 23 extern const char * const __bch2_str_hash_types[]; 24 extern const char * const bch2_str_hash_opts[]; 25 extern const char * const __bch2_data_types[]; 26 extern const char * const bch2_member_states[]; 27 extern const char * const bch2_d_types[]; 28 29 void bch2_prt_jset_entry_type(struct printbuf *, enum bch_jset_entry_type); 30 void bch2_prt_fs_usage_type(struct printbuf *, enum bch_fs_usage_type); 31 void bch2_prt_data_type(struct printbuf *, enum bch_data_type); 32 void bch2_prt_csum_opt(struct printbuf *, enum bch_csum_opt); 33 void bch2_prt_csum_type(struct printbuf *, enum bch_csum_type); 34 void bch2_prt_compression_type(struct printbuf *, enum bch_compression_type); 35 void bch2_prt_str_hash_type(struct printbuf *, enum bch_str_hash_type); 36 37 static inline const char *bch2_d_type_str(unsigned d_type) 38 { 39 return (d_type < BCH_DT_MAX ? bch2_d_types[d_type] : NULL) ?: "(bad d_type)"; 40 } 41 42 /* 43 * Mount options; we also store defaults in the superblock. 44 * 45 * Also exposed via sysfs: if an option is writeable, and it's also stored in 46 * the superblock, changing it via sysfs (currently? might change this) also 47 * updates the superblock. 48 * 49 * We store options as signed integers, where -1 means undefined. This means we 50 * can pass the mount options to bch2_fs_alloc() as a whole struct, and then only 51 * apply the options from that struct that are defined. 52 */ 53 54 /* When can be set: */ 55 enum opt_flags { 56 OPT_FS = BIT(0), /* Filesystem option */ 57 OPT_DEVICE = BIT(1), /* Device option */ 58 OPT_INODE = BIT(2), /* Inode option */ 59 OPT_FORMAT = BIT(3), /* May be specified at format time */ 60 OPT_MOUNT = BIT(4), /* May be specified at mount time */ 61 OPT_RUNTIME = BIT(5), /* May be specified at runtime */ 62 OPT_HUMAN_READABLE = BIT(6), 63 OPT_MUST_BE_POW_2 = BIT(7), /* Must be power of 2 */ 64 OPT_SB_FIELD_SECTORS = BIT(8), /* Superblock field is >> 9 of actual value */ 65 OPT_SB_FIELD_ILOG2 = BIT(9), /* Superblock field is ilog2 of actual value */ 66 OPT_SB_FIELD_ONE_BIAS = BIT(10), /* 0 means default value */ 67 OPT_HIDDEN = BIT(11), 68 }; 69 70 enum opt_type { 71 BCH_OPT_BOOL, 72 BCH_OPT_UINT, 73 BCH_OPT_STR, 74 BCH_OPT_BITFIELD, 75 BCH_OPT_FN, 76 }; 77 78 struct bch_opt_fn { 79 int (*parse)(struct bch_fs *, const char *, u64 *, struct printbuf *); 80 void (*to_text)(struct printbuf *, struct bch_fs *, struct bch_sb *, u64); 81 int (*validate)(u64, struct printbuf *); 82 }; 83 84 /** 85 * x(name, shortopt, type, in mem type, mode, sb_opt) 86 * 87 * @name - name of mount option, sysfs attribute, and struct bch_opts 88 * member 89 * 90 * @mode - when opt may be set 91 * 92 * @sb_option - name of corresponding superblock option 93 * 94 * @type - one of OPT_BOOL, OPT_UINT, OPT_STR 95 */ 96 97 /* 98 * XXX: add fields for 99 * - default value 100 * - helptext 101 */ 102 103 #ifdef __KERNEL__ 104 #define RATELIMIT_ERRORS_DEFAULT true 105 #else 106 #define RATELIMIT_ERRORS_DEFAULT false 107 #endif 108 109 #ifdef CONFIG_BCACHEFS_DEBUG 110 #define BCACHEFS_VERBOSE_DEFAULT true 111 #else 112 #define BCACHEFS_VERBOSE_DEFAULT false 113 #endif 114 115 #define BCH_FIX_ERRORS_OPTS() \ 116 x(exit, 0) \ 117 x(yes, 1) \ 118 x(no, 2) \ 119 x(ask, 3) 120 121 enum fsck_err_opts { 122 #define x(t, n) FSCK_FIX_##t, 123 BCH_FIX_ERRORS_OPTS() 124 #undef x 125 }; 126 127 #define BCH_OPTS() \ 128 x(block_size, u16, \ 129 OPT_FS|OPT_FORMAT| \ 130 OPT_HUMAN_READABLE|OPT_MUST_BE_POW_2|OPT_SB_FIELD_SECTORS, \ 131 OPT_UINT(512, 1U << 16), \ 132 BCH_SB_BLOCK_SIZE, 4 << 10, \ 133 "size", NULL) \ 134 x(btree_node_size, u32, \ 135 OPT_FS|OPT_FORMAT| \ 136 OPT_HUMAN_READABLE|OPT_MUST_BE_POW_2|OPT_SB_FIELD_SECTORS, \ 137 OPT_UINT(512, 1U << 20), \ 138 BCH_SB_BTREE_NODE_SIZE, 256 << 10, \ 139 "size", "Btree node size, default 256k") \ 140 x(errors, u8, \ 141 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \ 142 OPT_STR(bch2_error_actions), \ 143 BCH_SB_ERROR_ACTION, BCH_ON_ERROR_fix_safe, \ 144 NULL, "Action to take on filesystem error") \ 145 x(write_error_timeout, u16, \ 146 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \ 147 OPT_UINT(1, 300), \ 148 BCH_SB_WRITE_ERROR_TIMEOUT, 30, \ 149 NULL, "Number of consecutive write errors allowed before kicking out a device")\ 150 x(metadata_replicas, u8, \ 151 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \ 152 OPT_UINT(1, BCH_REPLICAS_MAX), \ 153 BCH_SB_META_REPLICAS_WANT, 1, \ 154 "#", "Number of metadata replicas") \ 155 x(data_replicas, u8, \ 156 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \ 157 OPT_UINT(1, BCH_REPLICAS_MAX), \ 158 BCH_SB_DATA_REPLICAS_WANT, 1, \ 159 "#", "Number of data replicas") \ 160 x(metadata_replicas_required, u8, \ 161 OPT_FS|OPT_FORMAT|OPT_MOUNT, \ 162 OPT_UINT(1, BCH_REPLICAS_MAX), \ 163 BCH_SB_META_REPLICAS_REQ, 1, \ 164 "#", NULL) \ 165 x(data_replicas_required, u8, \ 166 OPT_FS|OPT_FORMAT|OPT_MOUNT, \ 167 OPT_UINT(1, BCH_REPLICAS_MAX), \ 168 BCH_SB_DATA_REPLICAS_REQ, 1, \ 169 "#", NULL) \ 170 x(encoded_extent_max, u32, \ 171 OPT_FS|OPT_FORMAT| \ 172 OPT_HUMAN_READABLE|OPT_MUST_BE_POW_2|OPT_SB_FIELD_SECTORS|OPT_SB_FIELD_ILOG2,\ 173 OPT_UINT(4096, 2U << 20), \ 174 BCH_SB_ENCODED_EXTENT_MAX_BITS, 64 << 10, \ 175 "size", "Maximum size of checksummed/compressed extents")\ 176 x(metadata_checksum, u8, \ 177 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \ 178 OPT_STR(__bch2_csum_opts), \ 179 BCH_SB_META_CSUM_TYPE, BCH_CSUM_OPT_crc32c, \ 180 NULL, NULL) \ 181 x(data_checksum, u8, \ 182 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \ 183 OPT_STR(__bch2_csum_opts), \ 184 BCH_SB_DATA_CSUM_TYPE, BCH_CSUM_OPT_crc32c, \ 185 NULL, NULL) \ 186 x(checksum_err_retry_nr, u8, \ 187 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \ 188 OPT_UINT(0, 32), \ 189 BCH_SB_CSUM_ERR_RETRY_NR, 3, \ 190 NULL, NULL) \ 191 x(compression, u8, \ 192 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \ 193 OPT_FN(bch2_opt_compression), \ 194 BCH_SB_COMPRESSION_TYPE, BCH_COMPRESSION_OPT_none, \ 195 NULL, NULL) \ 196 x(background_compression, u8, \ 197 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \ 198 OPT_FN(bch2_opt_compression), \ 199 BCH_SB_BACKGROUND_COMPRESSION_TYPE,BCH_COMPRESSION_OPT_none, \ 200 NULL, NULL) \ 201 x(str_hash, u8, \ 202 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \ 203 OPT_STR(bch2_str_hash_opts), \ 204 BCH_SB_STR_HASH_TYPE, BCH_STR_HASH_OPT_siphash, \ 205 NULL, "Hash function for directory entries and xattrs")\ 206 x(metadata_target, u16, \ 207 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \ 208 OPT_FN(bch2_opt_target), \ 209 BCH_SB_METADATA_TARGET, 0, \ 210 "(target)", "Device or label for metadata writes") \ 211 x(foreground_target, u16, \ 212 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \ 213 OPT_FN(bch2_opt_target), \ 214 BCH_SB_FOREGROUND_TARGET, 0, \ 215 "(target)", "Device or label for foreground writes") \ 216 x(background_target, u16, \ 217 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \ 218 OPT_FN(bch2_opt_target), \ 219 BCH_SB_BACKGROUND_TARGET, 0, \ 220 "(target)", "Device or label to move data to in the background")\ 221 x(promote_target, u16, \ 222 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \ 223 OPT_FN(bch2_opt_target), \ 224 BCH_SB_PROMOTE_TARGET, 0, \ 225 "(target)", "Device or label to promote data to on read") \ 226 x(erasure_code, u16, \ 227 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \ 228 OPT_BOOL(), \ 229 BCH_SB_ERASURE_CODE, false, \ 230 NULL, "Enable erasure coding (DO NOT USE YET)") \ 231 x(casefold, u8, \ 232 OPT_FS|OPT_INODE|OPT_FORMAT, \ 233 OPT_BOOL(), \ 234 BCH_SB_CASEFOLD, false, \ 235 NULL, "Dirent lookups are casefolded") \ 236 x(inodes_32bit, u8, \ 237 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \ 238 OPT_BOOL(), \ 239 BCH_SB_INODE_32BIT, true, \ 240 NULL, "Constrain inode numbers to 32 bits") \ 241 x(shard_inode_numbers_bits, u8, \ 242 OPT_FS|OPT_FORMAT, \ 243 OPT_UINT(0, 8), \ 244 BCH_SB_SHARD_INUMS_NBITS, 0, \ 245 NULL, "Shard new inode numbers by CPU id") \ 246 x(inodes_use_key_cache, u8, \ 247 OPT_FS|OPT_FORMAT|OPT_MOUNT, \ 248 OPT_BOOL(), \ 249 BCH_SB_INODES_USE_KEY_CACHE, true, \ 250 NULL, "Use the btree key cache for the inodes btree") \ 251 x(btree_node_mem_ptr_optimization, u8, \ 252 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \ 253 OPT_BOOL(), \ 254 BCH2_NO_SB_OPT, true, \ 255 NULL, "Stash pointer to in memory btree node in btree ptr")\ 256 x(gc_reserve_percent, u8, \ 257 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \ 258 OPT_UINT(5, 21), \ 259 BCH_SB_GC_RESERVE, 8, \ 260 "%", "Percentage of disk space to reserve for copygc")\ 261 x(gc_reserve_bytes, u64, \ 262 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME| \ 263 OPT_HUMAN_READABLE|OPT_SB_FIELD_SECTORS, \ 264 OPT_UINT(0, U64_MAX), \ 265 BCH_SB_GC_RESERVE_BYTES, 0, \ 266 "%", "Amount of disk space to reserve for copygc\n" \ 267 "Takes precedence over gc_reserve_percent if set")\ 268 x(root_reserve_percent, u8, \ 269 OPT_FS|OPT_FORMAT|OPT_MOUNT, \ 270 OPT_UINT(0, 100), \ 271 BCH_SB_ROOT_RESERVE, 0, \ 272 "%", "Percentage of disk space to reserve for superuser")\ 273 x(wide_macs, u8, \ 274 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \ 275 OPT_BOOL(), \ 276 BCH_SB_128_BIT_MACS, false, \ 277 NULL, "Store full 128 bits of cryptographic MACs, instead of 80")\ 278 x(inline_data, u8, \ 279 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \ 280 OPT_BOOL(), \ 281 BCH2_NO_SB_OPT, true, \ 282 NULL, "Enable inline data extents") \ 283 x(promote_whole_extents, u8, \ 284 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \ 285 OPT_BOOL(), \ 286 BCH_SB_PROMOTE_WHOLE_EXTENTS, true, \ 287 NULL, "Promote whole extents, instead of just part being read")\ 288 x(acl, u8, \ 289 OPT_FS|OPT_FORMAT|OPT_MOUNT, \ 290 OPT_BOOL(), \ 291 BCH_SB_POSIX_ACL, true, \ 292 NULL, "Enable POSIX acls") \ 293 x(usrquota, u8, \ 294 OPT_FS|OPT_FORMAT|OPT_MOUNT, \ 295 OPT_BOOL(), \ 296 BCH_SB_USRQUOTA, false, \ 297 NULL, "Enable user quotas") \ 298 x(grpquota, u8, \ 299 OPT_FS|OPT_FORMAT|OPT_MOUNT, \ 300 OPT_BOOL(), \ 301 BCH_SB_GRPQUOTA, false, \ 302 NULL, "Enable group quotas") \ 303 x(prjquota, u8, \ 304 OPT_FS|OPT_FORMAT|OPT_MOUNT, \ 305 OPT_BOOL(), \ 306 BCH_SB_PRJQUOTA, false, \ 307 NULL, "Enable project quotas") \ 308 x(degraded, u8, \ 309 OPT_FS|OPT_MOUNT, \ 310 OPT_BOOL(), \ 311 BCH2_NO_SB_OPT, false, \ 312 NULL, "Allow mounting in degraded mode") \ 313 x(very_degraded, u8, \ 314 OPT_FS|OPT_MOUNT, \ 315 OPT_BOOL(), \ 316 BCH2_NO_SB_OPT, false, \ 317 NULL, "Allow mounting in when data will be missing") \ 318 x(no_splitbrain_check, u8, \ 319 OPT_FS|OPT_MOUNT, \ 320 OPT_BOOL(), \ 321 BCH2_NO_SB_OPT, false, \ 322 NULL, "Don't kick drives out when splitbrain detected")\ 323 x(verbose, u8, \ 324 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \ 325 OPT_BOOL(), \ 326 BCH2_NO_SB_OPT, BCACHEFS_VERBOSE_DEFAULT, \ 327 NULL, "Extra debugging information during mount/recovery")\ 328 x(journal_flush_delay, u32, \ 329 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \ 330 OPT_UINT(1, U32_MAX), \ 331 BCH_SB_JOURNAL_FLUSH_DELAY, 1000, \ 332 NULL, "Delay in milliseconds before automatic journal commits")\ 333 x(journal_flush_disabled, u8, \ 334 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \ 335 OPT_BOOL(), \ 336 BCH_SB_JOURNAL_FLUSH_DISABLED,false, \ 337 NULL, "Disable journal flush on sync/fsync\n" \ 338 "If enabled, writes can be lost, but only since the\n"\ 339 "last journal write (default 1 second)") \ 340 x(journal_reclaim_delay, u32, \ 341 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \ 342 OPT_UINT(0, U32_MAX), \ 343 BCH_SB_JOURNAL_RECLAIM_DELAY, 100, \ 344 NULL, "Delay in milliseconds before automatic journal reclaim")\ 345 x(move_bytes_in_flight, u32, \ 346 OPT_HUMAN_READABLE|OPT_FS|OPT_MOUNT|OPT_RUNTIME, \ 347 OPT_UINT(1024, U32_MAX), \ 348 BCH2_NO_SB_OPT, 1U << 20, \ 349 NULL, "Maximum Amount of IO to keep in flight by the move path")\ 350 x(move_ios_in_flight, u32, \ 351 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \ 352 OPT_UINT(1, 1024), \ 353 BCH2_NO_SB_OPT, 32, \ 354 NULL, "Maximum number of IOs to keep in flight by the move path")\ 355 x(fsck, u8, \ 356 OPT_FS|OPT_MOUNT, \ 357 OPT_BOOL(), \ 358 BCH2_NO_SB_OPT, false, \ 359 NULL, "Run fsck on mount") \ 360 x(fsck_memory_usage_percent, u8, \ 361 OPT_FS|OPT_MOUNT, \ 362 OPT_UINT(20, 70), \ 363 BCH2_NO_SB_OPT, 50, \ 364 NULL, "Maximum percentage of system ram fsck is allowed to pin")\ 365 x(fix_errors, u8, \ 366 OPT_FS|OPT_MOUNT, \ 367 OPT_FN(bch2_opt_fix_errors), \ 368 BCH2_NO_SB_OPT, FSCK_FIX_exit, \ 369 NULL, "Fix errors during fsck without asking") \ 370 x(ratelimit_errors, u8, \ 371 OPT_FS|OPT_MOUNT, \ 372 OPT_BOOL(), \ 373 BCH2_NO_SB_OPT, RATELIMIT_ERRORS_DEFAULT, \ 374 NULL, "Ratelimit error messages during fsck") \ 375 x(nochanges, u8, \ 376 OPT_FS|OPT_MOUNT, \ 377 OPT_BOOL(), \ 378 BCH2_NO_SB_OPT, false, \ 379 NULL, "Super read only mode - no writes at all will be issued,\n"\ 380 "even if we have to replay the journal") \ 381 x(norecovery, u8, \ 382 OPT_FS|OPT_MOUNT, \ 383 OPT_BOOL(), \ 384 BCH2_NO_SB_OPT, false, \ 385 NULL, "Exit recovery immediately prior to journal replay")\ 386 x(recovery_passes, u64, \ 387 OPT_FS|OPT_MOUNT, \ 388 OPT_BITFIELD(bch2_recovery_passes), \ 389 BCH2_NO_SB_OPT, 0, \ 390 NULL, "Recovery passes to run explicitly") \ 391 x(recovery_passes_exclude, u64, \ 392 OPT_FS|OPT_MOUNT, \ 393 OPT_BITFIELD(bch2_recovery_passes), \ 394 BCH2_NO_SB_OPT, 0, \ 395 NULL, "Recovery passes to exclude") \ 396 x(recovery_pass_last, u8, \ 397 OPT_FS|OPT_MOUNT, \ 398 OPT_STR_NOLIMIT(bch2_recovery_passes), \ 399 BCH2_NO_SB_OPT, 0, \ 400 NULL, "Exit recovery after specified pass") \ 401 x(retain_recovery_info, u8, \ 402 0, \ 403 OPT_BOOL(), \ 404 BCH2_NO_SB_OPT, false, \ 405 NULL, "Don't free journal entries/keys, scanned btree nodes after startup")\ 406 x(read_entire_journal, u8, \ 407 0, \ 408 OPT_BOOL(), \ 409 BCH2_NO_SB_OPT, false, \ 410 NULL, "Read all journal entries, not just dirty ones")\ 411 x(read_journal_only, u8, \ 412 0, \ 413 OPT_BOOL(), \ 414 BCH2_NO_SB_OPT, false, \ 415 NULL, "Only read the journal, skip the rest of recovery")\ 416 x(journal_transaction_names, u8, \ 417 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \ 418 OPT_BOOL(), \ 419 BCH_SB_JOURNAL_TRANSACTION_NAMES, true, \ 420 NULL, "Log transaction function names in journal") \ 421 x(allocator_stuck_timeout, u16, \ 422 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \ 423 OPT_UINT(0, U16_MAX), \ 424 BCH_SB_ALLOCATOR_STUCK_TIMEOUT, 30, \ 425 NULL, "Default timeout in seconds for stuck allocator messages")\ 426 x(noexcl, u8, \ 427 OPT_FS|OPT_MOUNT, \ 428 OPT_BOOL(), \ 429 BCH2_NO_SB_OPT, false, \ 430 NULL, "Don't open device in exclusive mode") \ 431 x(direct_io, u8, \ 432 OPT_FS|OPT_MOUNT, \ 433 OPT_BOOL(), \ 434 BCH2_NO_SB_OPT, true, \ 435 NULL, "Use O_DIRECT (userspace only)") \ 436 x(sb, u64, \ 437 OPT_MOUNT, \ 438 OPT_UINT(0, S64_MAX), \ 439 BCH2_NO_SB_OPT, BCH_SB_SECTOR, \ 440 "offset", "Sector offset of superblock") \ 441 x(read_only, u8, \ 442 OPT_FS|OPT_MOUNT|OPT_HIDDEN, \ 443 OPT_BOOL(), \ 444 BCH2_NO_SB_OPT, false, \ 445 NULL, NULL) \ 446 x(nostart, u8, \ 447 0, \ 448 OPT_BOOL(), \ 449 BCH2_NO_SB_OPT, false, \ 450 NULL, "Don\'t start filesystem, only open devices") \ 451 x(reconstruct_alloc, u8, \ 452 OPT_FS|OPT_MOUNT, \ 453 OPT_BOOL(), \ 454 BCH2_NO_SB_OPT, false, \ 455 NULL, "Reconstruct alloc btree") \ 456 x(version_upgrade, u8, \ 457 OPT_FS|OPT_MOUNT, \ 458 OPT_STR(bch2_version_upgrade_opts), \ 459 BCH_SB_VERSION_UPGRADE, BCH_VERSION_UPGRADE_compatible, \ 460 NULL, "Set superblock to latest version,\n" \ 461 "allowing any new features to be used") \ 462 x(stdio, u64, \ 463 0, \ 464 OPT_UINT(0, S64_MAX), \ 465 BCH2_NO_SB_OPT, false, \ 466 NULL, "Pointer to a struct stdio_redirect") \ 467 x(project, u8, \ 468 OPT_INODE, \ 469 OPT_BOOL(), \ 470 BCH2_NO_SB_OPT, false, \ 471 NULL, NULL) \ 472 x(nocow, u8, \ 473 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \ 474 OPT_BOOL(), \ 475 BCH_SB_NOCOW, false, \ 476 NULL, "Nocow mode: Writes will be done in place when possible.\n"\ 477 "Snapshots and reflink will still caused writes to be COW\n"\ 478 "Implicitly disables data checksumming, compression and encryption")\ 479 x(nocow_enabled, u8, \ 480 OPT_FS|OPT_MOUNT, \ 481 OPT_BOOL(), \ 482 BCH2_NO_SB_OPT, true, \ 483 NULL, "Enable nocow mode: enables runtime locking in\n"\ 484 "data move path needed if nocow will ever be in use\n")\ 485 x(copygc_enabled, u8, \ 486 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \ 487 OPT_BOOL(), \ 488 BCH2_NO_SB_OPT, true, \ 489 NULL, "Enable copygc: disable for debugging, or to\n"\ 490 "quiet the system when doing performance testing\n")\ 491 x(rebalance_enabled, u8, \ 492 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \ 493 OPT_BOOL(), \ 494 BCH2_NO_SB_OPT, true, \ 495 NULL, "Enable rebalance: disable for debugging, or to\n"\ 496 "quiet the system when doing performance testing\n")\ 497 x(no_data_io, u8, \ 498 OPT_MOUNT, \ 499 OPT_BOOL(), \ 500 BCH2_NO_SB_OPT, false, \ 501 NULL, "Skip submit_bio() for data reads and writes, " \ 502 "for performance testing purposes") \ 503 x(state, u64, \ 504 OPT_DEVICE|OPT_RUNTIME, \ 505 OPT_STR(bch2_member_states), \ 506 BCH_MEMBER_STATE, BCH_MEMBER_STATE_rw, \ 507 "state", "rw,ro,failed,spare") \ 508 x(bucket_size, u32, \ 509 OPT_DEVICE|OPT_HUMAN_READABLE|OPT_SB_FIELD_SECTORS, \ 510 OPT_UINT(0, S64_MAX), \ 511 BCH_MEMBER_BUCKET_SIZE, 0, \ 512 "size", "Specifies the bucket size; must be greater than the btree node size")\ 513 x(durability, u8, \ 514 OPT_DEVICE|OPT_RUNTIME|OPT_SB_FIELD_ONE_BIAS, \ 515 OPT_UINT(0, BCH_REPLICAS_MAX), \ 516 BCH_MEMBER_DURABILITY, 1, \ 517 "n", "Data written to this device will be considered\n"\ 518 "to have already been replicated n times") \ 519 x(data_allowed, u8, \ 520 OPT_DEVICE, \ 521 OPT_BITFIELD(__bch2_data_types), \ 522 BCH_MEMBER_DATA_ALLOWED, BIT(BCH_DATA_journal)|BIT(BCH_DATA_btree)|BIT(BCH_DATA_user),\ 523 "types", "Allowed data types for this device: journal, btree, and/or user")\ 524 x(discard, u8, \ 525 OPT_MOUNT|OPT_DEVICE|OPT_RUNTIME, \ 526 OPT_BOOL(), \ 527 BCH_MEMBER_DISCARD, true, \ 528 NULL, "Enable discard/TRIM support") \ 529 x(btree_node_prefetch, u8, \ 530 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \ 531 OPT_BOOL(), \ 532 BCH2_NO_SB_OPT, true, \ 533 NULL, "BTREE_ITER_prefetch casuse btree nodes to be\n"\ 534 " prefetched sequentially") 535 536 struct bch_opts { 537 #define x(_name, _bits, ...) unsigned _name##_defined:1; 538 BCH_OPTS() 539 #undef x 540 541 #define x(_name, _bits, ...) _bits _name; 542 BCH_OPTS() 543 #undef x 544 }; 545 546 struct bch2_opts_parse { 547 struct bch_opts opts; 548 549 /* to save opts that can't be parsed before the FS is opened: */ 550 struct printbuf parse_later; 551 }; 552 553 static const __maybe_unused struct bch_opts bch2_opts_default = { 554 #define x(_name, _bits, _mode, _type, _sb_opt, _default, ...) \ 555 ._name##_defined = true, \ 556 ._name = _default, \ 557 558 BCH_OPTS() 559 #undef x 560 }; 561 562 #define opt_defined(_opts, _name) ((_opts)._name##_defined) 563 564 #define opt_get(_opts, _name) \ 565 (opt_defined(_opts, _name) ? (_opts)._name : bch2_opts_default._name) 566 567 #define opt_set(_opts, _name, _v) \ 568 do { \ 569 (_opts)._name##_defined = true; \ 570 (_opts)._name = _v; \ 571 } while (0) 572 573 static inline struct bch_opts bch2_opts_empty(void) 574 { 575 return (struct bch_opts) { 0 }; 576 } 577 578 void bch2_opts_apply(struct bch_opts *, struct bch_opts); 579 580 enum bch_opt_id { 581 #define x(_name, ...) Opt_##_name, 582 BCH_OPTS() 583 #undef x 584 bch2_opts_nr 585 }; 586 587 struct bch_fs; 588 struct printbuf; 589 590 struct bch_option { 591 struct attribute attr; 592 enum opt_type type; 593 enum opt_flags flags; 594 u64 min, max; 595 596 const char * const *choices; 597 598 struct bch_opt_fn fn; 599 600 const char *hint; 601 const char *help; 602 603 u64 (*get_sb)(const struct bch_sb *); 604 void (*set_sb)(struct bch_sb *, u64); 605 606 u64 (*get_member)(const struct bch_member *); 607 void (*set_member)(struct bch_member *, u64); 608 609 }; 610 611 extern const struct bch_option bch2_opt_table[]; 612 613 bool bch2_opt_defined_by_id(const struct bch_opts *, enum bch_opt_id); 614 u64 bch2_opt_get_by_id(const struct bch_opts *, enum bch_opt_id); 615 void bch2_opt_set_by_id(struct bch_opts *, enum bch_opt_id, u64); 616 617 u64 bch2_opt_from_sb(struct bch_sb *, enum bch_opt_id, int); 618 int bch2_opts_from_sb(struct bch_opts *, struct bch_sb *); 619 void __bch2_opt_set_sb(struct bch_sb *, int, const struct bch_option *, u64); 620 621 struct bch_dev; 622 void bch2_opt_set_sb(struct bch_fs *, struct bch_dev *, const struct bch_option *, u64); 623 624 int bch2_opt_lookup(const char *); 625 int bch2_opt_validate(const struct bch_option *, u64, struct printbuf *); 626 int bch2_opt_parse(struct bch_fs *, const struct bch_option *, 627 const char *, u64 *, struct printbuf *); 628 629 #define OPT_SHOW_FULL_LIST (1 << 0) 630 #define OPT_SHOW_MOUNT_STYLE (1 << 1) 631 632 void bch2_opt_to_text(struct printbuf *, struct bch_fs *, struct bch_sb *, 633 const struct bch_option *, u64, unsigned); 634 void bch2_opts_to_text(struct printbuf *, 635 struct bch_opts, 636 struct bch_fs *, struct bch_sb *, 637 unsigned, unsigned, unsigned); 638 639 int bch2_opt_check_may_set(struct bch_fs *, struct bch_dev *, int, u64); 640 int bch2_opts_check_may_set(struct bch_fs *); 641 int bch2_parse_one_mount_opt(struct bch_fs *, struct bch_opts *, 642 struct printbuf *, const char *, const char *); 643 int bch2_parse_mount_opts(struct bch_fs *, struct bch_opts *, struct printbuf *, 644 char *, bool); 645 646 /* inode opts: */ 647 648 struct bch_io_opts { 649 #define x(_name, _bits) u##_bits _name; 650 BCH_INODE_OPTS() 651 #undef x 652 #define x(_name, _bits) u64 _name##_from_inode:1; 653 BCH_INODE_OPTS() 654 #undef x 655 }; 656 657 static inline void bch2_io_opts_fixups(struct bch_io_opts *opts) 658 { 659 if (!opts->background_target) 660 opts->background_target = opts->foreground_target; 661 if (!opts->background_compression) 662 opts->background_compression = opts->compression; 663 if (opts->nocow) { 664 opts->compression = opts->background_compression = 0; 665 opts->data_checksum = 0; 666 opts->erasure_code = 0; 667 } 668 } 669 670 struct bch_io_opts bch2_opts_to_inode_opts(struct bch_opts); 671 bool bch2_opt_is_inode_opt(enum bch_opt_id); 672 673 #endif /* _BCACHEFS_OPTS_H */ 674