Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

vfs: Update mount API docs

Update the mount API docs to reflect recent changes to the code.

Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

David Howells and committed by
Linus Torvalds
7d6ab823 bfed6d0f

+194 -171
+194 -171
Documentation/filesystems/mount_api.txt
··· 12 12 13 13 (4) Filesystem context security. 14 14 15 - (5) VFS filesystem context operations. 15 + (5) VFS filesystem context API. 16 16 17 - (6) Parameter description. 17 + (6) Superblock creation helpers. 18 18 19 - (7) Parameter helper functions. 19 + (7) Parameter description. 20 + 21 + (8) Parameter helper functions. 20 22 21 23 22 24 ======== ··· 43 41 44 42 (7) Destroy the context. 45 43 46 - To support this, the file_system_type struct gains a new field: 44 + To support this, the file_system_type struct gains two new fields: 47 45 48 46 int (*init_fs_context)(struct fs_context *fc); 47 + const struct fs_parameter_description *parameters; 49 48 50 - which is invoked to set up the filesystem-specific parts of a filesystem 51 - context, including the additional space. 49 + The first is invoked to set up the filesystem-specific parts of a filesystem 50 + context, including the additional space, and the second points to the 51 + parameter description for validation at registration time and querying by a 52 + future system call. 52 53 53 54 Note that security initialisation is done *after* the filesystem is called so 54 55 that the namespaces may be adjusted first. ··· 78 73 void *s_fs_info; 79 74 unsigned int sb_flags; 80 75 unsigned int sb_flags_mask; 76 + unsigned int s_iflags; 77 + unsigned int lsm_flags; 81 78 enum fs_context_purpose purpose:8; 82 - bool sloppy:1; 83 - bool silent:1; 84 79 ... 85 80 }; 86 81 ··· 146 141 147 142 Which bits SB_* flags are to be set/cleared in super_block::s_flags. 148 143 144 + (*) unsigned int s_iflags 145 + 146 + These will be bitwise-OR'd with s->s_iflags when a superblock is created. 147 + 149 148 (*) enum fs_context_purpose 150 149 151 150 This indicates the purpose for which the context is intended. The ··· 158 149 FS_CONTEXT_FOR_MOUNT, -- New superblock for explicit mount 159 150 FS_CONTEXT_FOR_SUBMOUNT -- New automatic submount of extant mount 160 151 FS_CONTEXT_FOR_RECONFIGURE -- Change an existing mount 161 - 162 - (*) bool sloppy 163 - (*) bool silent 164 - 165 - These are set if the sloppy or silent mount options are given. 166 - 167 - [NOTE] sloppy is probably unnecessary when userspace passes over one 168 - option at a time since the error can just be ignored if userspace deems it 169 - to be unimportant. 170 - 171 - [NOTE] silent is probably redundant with sb_flags & SB_SILENT. 172 152 173 153 The mount context is created by calling vfs_new_fs_context() or 174 154 vfs_dup_fs_context() and is destroyed with put_fs_context(). Note that the ··· 340 342 It should return 0 on success or a negative error code on failure. 341 343 342 344 343 - ================================= 344 - VFS FILESYSTEM CONTEXT OPERATIONS 345 - ================================= 345 + ========================== 346 + VFS FILESYSTEM CONTEXT API 347 + ========================== 346 348 347 - There are four operations for creating a filesystem context and 348 - one for destroying a context: 349 + There are four operations for creating a filesystem context and one for 350 + destroying a context: 349 351 350 - (*) struct fs_context *vfs_new_fs_context(struct file_system_type *fs_type, 351 - struct dentry *reference, 352 - unsigned int sb_flags, 353 - unsigned int sb_flags_mask, 354 - enum fs_context_purpose purpose); 352 + (*) struct fs_context *fs_context_for_mount( 353 + struct file_system_type *fs_type, 354 + unsigned int sb_flags); 355 355 356 - Create a filesystem context for a given filesystem type and purpose. This 357 - allocates the filesystem context, sets the superblock flags, initialises 358 - the security and calls fs_type->init_fs_context() to initialise the 359 - filesystem private data. 356 + Allocate a filesystem context for the purpose of setting up a new mount, 357 + whether that be with a new superblock or sharing an existing one. This 358 + sets the superblock flags, initialises the security and calls 359 + fs_type->init_fs_context() to initialise the filesystem private data. 360 360 361 - reference can be NULL or it may indicate the root dentry of a superblock 362 - that is going to be reconfigured (FS_CONTEXT_FOR_RECONFIGURE) or 363 - the automount point that triggered a submount (FS_CONTEXT_FOR_SUBMOUNT). 364 - This is provided as a source of namespace information. 361 + fs_type specifies the filesystem type that will manage the context and 362 + sb_flags presets the superblock flags stored therein. 363 + 364 + (*) struct fs_context *fs_context_for_reconfigure( 365 + struct dentry *dentry, 366 + unsigned int sb_flags, 367 + unsigned int sb_flags_mask); 368 + 369 + Allocate a filesystem context for the purpose of reconfiguring an 370 + existing superblock. dentry provides a reference to the superblock to be 371 + configured. sb_flags and sb_flags_mask indicate which superblock flags 372 + need changing and to what. 373 + 374 + (*) struct fs_context *fs_context_for_submount( 375 + struct file_system_type *fs_type, 376 + struct dentry *reference); 377 + 378 + Allocate a filesystem context for the purpose of creating a new mount for 379 + an automount point or other derived superblock. fs_type specifies the 380 + filesystem type that will manage the context and the reference dentry 381 + supplies the parameters. Namespaces are propagated from the reference 382 + dentry's superblock also. 383 + 384 + Note that it's not a requirement that the reference dentry be of the same 385 + filesystem type as fs_type. 365 386 366 387 (*) struct fs_context *vfs_dup_fs_context(struct fs_context *src_fc); 367 388 ··· 406 389 407 390 For the remaining operations, if an error occurs, a negative error code will be 408 391 returned. 409 - 410 - (*) int vfs_get_tree(struct fs_context *fc); 411 - 412 - Get or create the mountable root and superblock, using the parameters in 413 - the filesystem context to select/configure the superblock. This invokes 414 - the ->validate() op and then the ->get_tree() op. 415 - 416 - [NOTE] ->validate() could perhaps be rolled into ->get_tree() and 417 - ->reconfigure(). 418 - 419 - (*) struct vfsmount *vfs_create_mount(struct fs_context *fc); 420 - 421 - Create a mount given the parameters in the specified filesystem context. 422 - Note that this does not attach the mount to anything. 423 392 424 393 (*) int vfs_parse_fs_param(struct fs_context *fc, 425 394 struct fs_parameter *param); ··· 435 432 clear the pointer, but then becomes responsible for disposing of the 436 433 object. 437 434 438 - (*) int vfs_parse_fs_string(struct fs_context *fc, char *key, 435 + (*) int vfs_parse_fs_string(struct fs_context *fc, const char *key, 439 436 const char *value, size_t v_size); 440 437 441 - A wrapper around vfs_parse_fs_param() that just passes a constant string. 438 + A wrapper around vfs_parse_fs_param() that copies the value string it is 439 + passed. 442 440 443 441 (*) int generic_parse_monolithic(struct fs_context *fc, void *data); 444 442 445 443 Parse a sys_mount() data page, assuming the form to be a text list 446 444 consisting of key[=val] options separated by commas. Each item in the 447 445 list is passed to vfs_mount_option(). This is the default when the 448 - ->parse_monolithic() operation is NULL. 446 + ->parse_monolithic() method is NULL. 447 + 448 + (*) int vfs_get_tree(struct fs_context *fc); 449 + 450 + Get or create the mountable root and superblock, using the parameters in 451 + the filesystem context to select/configure the superblock. This invokes 452 + the ->get_tree() method. 453 + 454 + (*) struct vfsmount *vfs_create_mount(struct fs_context *fc); 455 + 456 + Create a mount given the parameters in the specified filesystem context. 457 + Note that this does not attach the mount to anything. 458 + 459 + 460 + =========================== 461 + SUPERBLOCK CREATION HELPERS 462 + =========================== 463 + 464 + A number of VFS helpers are available for use by filesystems for the creation 465 + or looking up of superblocks. 466 + 467 + (*) struct super_block * 468 + sget_fc(struct fs_context *fc, 469 + int (*test)(struct super_block *sb, struct fs_context *fc), 470 + int (*set)(struct super_block *sb, struct fs_context *fc)); 471 + 472 + This is the core routine. If test is non-NULL, it searches for an 473 + existing superblock matching the criteria held in the fs_context, using 474 + the test function to match them. If no match is found, a new superblock 475 + is created and the set function is called to set it up. 476 + 477 + Prior to the set function being called, fc->s_fs_info will be transferred 478 + to sb->s_fs_info - and fc->s_fs_info will be cleared if set returns 479 + success (ie. 0). 480 + 481 + The following helpers all wrap sget_fc(): 482 + 483 + (*) int vfs_get_super(struct fs_context *fc, 484 + enum vfs_get_super_keying keying, 485 + int (*fill_super)(struct super_block *sb, 486 + struct fs_context *fc)) 487 + 488 + This creates/looks up a deviceless superblock. The keying indicates how 489 + many superblocks of this type may exist and in what manner they may be 490 + shared: 491 + 492 + (1) vfs_get_single_super 493 + 494 + Only one such superblock may exist in the system. Any further 495 + attempt to get a new superblock gets this one (and any parameter 496 + differences are ignored). 497 + 498 + (2) vfs_get_keyed_super 499 + 500 + Multiple superblocks of this type may exist and they're keyed on 501 + their s_fs_info pointer (for example this may refer to a 502 + namespace). 503 + 504 + (3) vfs_get_independent_super 505 + 506 + Multiple independent superblocks of this type may exist. This 507 + function never matches an existing one and always creates a new 508 + one. 449 509 450 510 451 511 ===================== ··· 520 454 521 455 struct fs_parameter_description { 522 456 const char name[16]; 523 - u8 nr_params; 524 - u8 nr_alt_keys; 525 - u8 nr_enums; 526 - bool ignore_unknown; 527 - bool no_source; 528 - const char *const *keys; 529 - const struct constant_table *alt_keys; 530 457 const struct fs_parameter_spec *specs; 531 458 const struct fs_parameter_enum *enums; 532 459 }; 533 460 534 461 For example: 535 462 536 - enum afs_param { 463 + enum { 537 464 Opt_autocell, 538 465 Opt_bar, 539 466 Opt_dyn, 540 467 Opt_foo, 541 468 Opt_source, 542 - nr__afs_params 543 469 }; 544 470 545 471 static const struct fs_parameter_description afs_fs_parameters = { 546 472 .name = "kAFS", 547 - .nr_params = nr__afs_params, 548 - .nr_alt_keys = ARRAY_SIZE(afs_param_alt_keys), 549 - .nr_enums = ARRAY_SIZE(afs_param_enums), 550 - .keys = afs_param_keys, 551 - .alt_keys = afs_param_alt_keys, 552 473 .specs = afs_param_specs, 553 474 .enums = afs_param_enums, 554 475 }; ··· 547 494 The name to be used in error messages generated by the parse helper 548 495 functions. 549 496 550 - (2) u8 nr_params; 497 + (2) const struct fs_parameter_specification *specs; 551 498 552 - The number of discrete parameter identifiers. This indicates the number 553 - of elements in the ->types[] array and also limits the values that may be 554 - used in the values that the ->keys[] array maps to. 499 + Table of parameter specifications, terminated with a null entry, where the 500 + entries are of type: 555 501 556 - It is expected that, for example, two parameters that are related, say 557 - "acl" and "noacl" with have the same ID, but will be flagged to indicate 558 - that one is the inverse of the other. The value can then be picked out 559 - from the parse result. 560 - 561 - (3) const struct fs_parameter_specification *specs; 562 - 563 - Table of parameter specifications, where the entries are of type: 564 - 565 - struct fs_parameter_type { 566 - enum fs_parameter_spec type:8; 567 - u8 flags; 502 + struct fs_parameter_spec { 503 + const char *name; 504 + u8 opt; 505 + enum fs_parameter_type type:8; 506 + unsigned short flags; 568 507 }; 569 508 570 - and the parameter identifier is the index to the array. 'type' indicates 571 - the desired value type and must be one of: 509 + The 'name' field is a string to match exactly to the parameter key (no 510 + wildcards, patterns and no case-independence) and 'opt' is the value that 511 + will be returned by the fs_parser() function in the case of a successful 512 + match. 513 + 514 + The 'type' field indicates the desired value type and must be one of: 572 515 573 516 TYPE NAME EXPECTED VALUE RESULT IN 574 517 ======================= ======================= ===================== ··· 574 525 fs_param_is_u32_octal 32-bit octal int result->uint_32 575 526 fs_param_is_u32_hex 32-bit hex int result->uint_32 576 527 fs_param_is_s32 32-bit signed int result->int_32 528 + fs_param_is_u64 64-bit unsigned int result->uint_64 577 529 fs_param_is_enum Enum value name result->uint_32 578 530 fs_param_is_string Arbitrary string param->string 579 531 fs_param_is_blob Binary blob param->blob 580 532 fs_param_is_blockdev Blockdev path * Needs lookup 581 533 fs_param_is_path Path * Needs lookup 582 - fs_param_is_fd File descriptor param->file 583 - 584 - And each parameter can be qualified with 'flags': 585 - 586 - fs_param_v_optional The value is optional 587 - fs_param_neg_with_no If key name is prefixed with "no", it is false 588 - fs_param_neg_with_empty If value is "", it is false 589 - fs_param_deprecated The parameter is deprecated. 590 - 591 - For example: 592 - 593 - static const struct fs_parameter_spec afs_param_specs[nr__afs_params] = { 594 - [Opt_autocell] = { fs_param_is flag }, 595 - [Opt_bar] = { fs_param_is_enum }, 596 - [Opt_dyn] = { fs_param_is flag }, 597 - [Opt_foo] = { fs_param_is_bool, fs_param_neg_with_no }, 598 - [Opt_source] = { fs_param_is_string }, 599 - }; 534 + fs_param_is_fd File descriptor result->int_32 600 535 601 536 Note that if the value is of fs_param_is_bool type, fs_parse() will try 602 537 to match any string value against "0", "1", "no", "yes", "false", "true". 603 538 604 - [!] NOTE that the table must be sorted according to primary key name so 605 - that ->keys[] is also sorted. 539 + Each parameter can also be qualified with 'flags': 606 540 607 - (4) const char *const *keys; 541 + fs_param_v_optional The value is optional 542 + fs_param_neg_with_no result->negated set if key is prefixed with "no" 543 + fs_param_neg_with_empty result->negated set if value is "" 544 + fs_param_deprecated The parameter is deprecated. 608 545 609 - Table of primary key names for the parameters. There must be one entry 610 - per defined parameter. The table is optional if ->nr_params is 0. The 611 - table is just an array of names e.g.: 546 + These are wrapped with a number of convenience wrappers: 612 547 613 - static const char *const afs_param_keys[nr__afs_params] = { 614 - [Opt_autocell] = "autocell", 615 - [Opt_bar] = "bar", 616 - [Opt_dyn] = "dyn", 617 - [Opt_foo] = "foo", 618 - [Opt_source] = "source", 548 + MACRO SPECIFIES 549 + ======================= =============================================== 550 + fsparam_flag() fs_param_is_flag 551 + fsparam_flag_no() fs_param_is_flag, fs_param_neg_with_no 552 + fsparam_bool() fs_param_is_bool 553 + fsparam_u32() fs_param_is_u32 554 + fsparam_u32oct() fs_param_is_u32_octal 555 + fsparam_u32hex() fs_param_is_u32_hex 556 + fsparam_s32() fs_param_is_s32 557 + fsparam_u64() fs_param_is_u64 558 + fsparam_enum() fs_param_is_enum 559 + fsparam_string() fs_param_is_string 560 + fsparam_blob() fs_param_is_blob 561 + fsparam_bdev() fs_param_is_blockdev 562 + fsparam_path() fs_param_is_path 563 + fsparam_fd() fs_param_is_fd 564 + 565 + all of which take two arguments, name string and option number - for 566 + example: 567 + 568 + static const struct fs_parameter_spec afs_param_specs[] = { 569 + fsparam_flag ("autocell", Opt_autocell), 570 + fsparam_flag ("dyn", Opt_dyn), 571 + fsparam_string ("source", Opt_source), 572 + fsparam_flag_no ("foo", Opt_foo), 573 + {} 619 574 }; 620 575 621 - [!] NOTE that the table must be sorted such that the table can be searched 622 - with bsearch() using strcmp(). This means that the Opt_* values must 623 - correspond to the entries in this table. 624 - 625 - (5) const struct constant_table *alt_keys; 626 - u8 nr_alt_keys; 627 - 628 - Table of additional key names and their mappings to parameter ID plus the 629 - number of elements in the table. This is optional. The table is just an 630 - array of { name, integer } pairs, e.g.: 631 - 632 - static const struct constant_table afs_param_keys[] = { 633 - { "baz", Opt_bar }, 634 - { "dynamic", Opt_dyn }, 635 - }; 636 - 637 - [!] NOTE that the table must be sorted such that strcmp() can be used with 638 - bsearch() to search the entries. 639 - 640 - The parameter ID can also be fs_param_key_removed to indicate that a 641 - deprecated parameter has been removed and that an error will be given. 642 - This differs from fs_param_deprecated where the parameter may still have 643 - an effect. 644 - 645 - Further, the behaviour of the parameter may differ when an alternate name 646 - is used (for instance with NFS, "v3", "v4.2", etc. are alternate names). 576 + An addition macro, __fsparam() is provided that takes an additional pair 577 + of arguments to specify the type and the flags for anything that doesn't 578 + match one of the above macros. 647 579 648 580 (6) const struct fs_parameter_enum *enums; 649 - u8 nr_enums; 650 581 651 - Table of enum value names to integer mappings and the number of elements 652 - stored therein. This is of type: 582 + Table of enum value names to integer mappings, terminated with a null 583 + entry. This is of type: 653 584 654 585 struct fs_parameter_enum { 655 - u8 param_id; 586 + u8 opt; 656 587 char name[14]; 657 588 u8 value; 658 589 }; ··· 649 620 If a parameter of type fs_param_is_enum is encountered, fs_parse() will 650 621 try to look the value up in the enum table and the result will be stored 651 622 in the parse result. 652 - 653 - (7) bool no_source; 654 - 655 - If this is set, fs_parse() will ignore any "source" parameter and not 656 - pass it to the filesystem. 657 623 658 624 The parser should be pointed to by the parser pointer in the file_system_type 659 625 struct as this will provide validation on registration (if ··· 674 650 int value; 675 651 }; 676 652 677 - and it must be sorted such that it can be searched using bsearch() using 678 - strcmp(). If a match is found, the corresponding value is returned. If a 679 - match isn't found, the not_found value is returned instead. 653 + If a match is found, the corresponding value is returned. If a match 654 + isn't found, the not_found value is returned instead. 680 655 681 656 (*) bool validate_constant_table(const struct constant_table *tbl, 682 657 size_t tbl_size, ··· 688 665 should just be set to lie inside the low-to-high range. 689 666 690 667 If all is good, true is returned. If the table is invalid, errors are 691 - logged to dmesg, the stack is dumped and false is returned. 668 + logged to dmesg and false is returned. 669 + 670 + (*) bool fs_validate_description(const struct fs_parameter_description *desc); 671 + 672 + This performs some validation checks on a parameter description. It 673 + returns true if the description is good and false if it is not. It will 674 + log errors to dmesg if validation fails. 692 675 693 676 (*) int fs_parse(struct fs_context *fc, 694 - const struct fs_param_parser *parser, 677 + const struct fs_parameter_description *desc, 695 678 struct fs_parameter *param, 696 - struct fs_param_parse_result *result); 679 + struct fs_parse_result *result); 697 680 698 681 This is the main interpreter of parameters. It uses the parameter 699 - description (parser) to look up the name of the parameter to use and to 700 - convert that to a parameter ID (stored in result->key). 682 + description to look up a parameter by key name and to convert that to an 683 + option number (which it returns). 701 684 702 685 If successful, and if the parameter type indicates the result is a 703 686 boolean, integer or enum type, the value is converted by this function and 704 - the result stored in result->{boolean,int_32,uint_32}. 687 + the result stored in result->{boolean,int_32,uint_32,uint_64}. 705 688 706 689 If a match isn't initially made, the key is prefixed with "no" and no 707 690 value is present then an attempt will be made to look up the key with the 708 691 prefix removed. If this matches a parameter for which the type has flag 709 - fs_param_neg_with_no set, then a match will be made and the value will be 710 - set to false/0/NULL. 692 + fs_param_neg_with_no set, then a match will be made and result->negated 693 + will be set to true. 711 694 712 - If the parameter is successfully matched and, optionally, parsed 713 - correctly, 1 is returned. If the parameter isn't matched and 714 - parser->ignore_unknown is set, then 0 is returned. Otherwise -EINVAL is 715 - returned. 716 - 717 - (*) bool fs_validate_description(const struct fs_parameter_description *desc); 718 - 719 - This is validates the parameter description. It returns true if the 720 - description is good and false if it is not. 695 + If the parameter isn't matched, -ENOPARAM will be returned; if the 696 + parameter is matched, but the value is erroneous, -EINVAL will be 697 + returned; otherwise the parameter's option number will be returned. 721 698 722 699 (*) int fs_lookup_param(struct fs_context *fc, 723 700 struct fs_parameter *value,