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