···12121313 (4) Filesystem context security.14141515- (5) VFS filesystem context operations.1515+ (5) VFS filesystem context API.16161717- (6) Parameter description.1717+ (6) Superblock creation helpers.18181919- (7) Parameter helper functions.1919+ (7) Parameter description.2020+2121+ (8) Parameter helper functions.202221232224========···43414442 (7) Destroy the context.45434646-To support this, the file_system_type struct gains a new field:4444+To support this, the file_system_type struct gains two new fields:47454846 int (*init_fs_context)(struct fs_context *fc);4747+ const struct fs_parameter_description *parameters;49485050-which is invoked to set up the filesystem-specific parts of a filesystem5151-context, including the additional space.4949+The first is invoked to set up the filesystem-specific parts of a filesystem5050+context, including the additional space, and the second points to the5151+parameter description for validation at registration time and querying by a5252+future system call.52535354Note that security initialisation is done *after* the filesystem is called so5455that the namespaces may be adjusted first.···7873 void *s_fs_info;7974 unsigned int sb_flags;8075 unsigned int sb_flags_mask;7676+ unsigned int s_iflags;7777+ unsigned int lsm_flags;8178 enum fs_context_purpose purpose:8;8282- bool sloppy:1;8383- bool silent:1;8479 ...8580 };8681···146141147142 Which bits SB_* flags are to be set/cleared in super_block::s_flags.148143144144+ (*) unsigned int s_iflags145145+146146+ These will be bitwise-OR'd with s->s_iflags when a superblock is created.147147+149148 (*) enum fs_context_purpose150149151150 This indicates the purpose for which the context is intended. The···158149 FS_CONTEXT_FOR_MOUNT, -- New superblock for explicit mount159150 FS_CONTEXT_FOR_SUBMOUNT -- New automatic submount of extant mount160151 FS_CONTEXT_FOR_RECONFIGURE -- Change an existing mount161161-162162- (*) bool sloppy163163- (*) bool silent164164-165165- These are set if the sloppy or silent mount options are given.166166-167167- [NOTE] sloppy is probably unnecessary when userspace passes over one168168- option at a time since the error can just be ignored if userspace deems it169169- to be unimportant.170170-171171- [NOTE] silent is probably redundant with sb_flags & SB_SILENT.172152173153The mount context is created by calling vfs_new_fs_context() or174154vfs_dup_fs_context() and is destroyed with put_fs_context(). Note that the···340342 It should return 0 on success or a negative error code on failure.341343342344343343-=================================344344-VFS FILESYSTEM CONTEXT OPERATIONS345345-=================================345345+==========================346346+VFS FILESYSTEM CONTEXT API347347+==========================346348347347-There are four operations for creating a filesystem context and348348-one for destroying a context:349349+There are four operations for creating a filesystem context and one for350350+destroying a context:349351350350- (*) struct fs_context *vfs_new_fs_context(struct file_system_type *fs_type,351351- struct dentry *reference,352352- unsigned int sb_flags,353353- unsigned int sb_flags_mask,354354- enum fs_context_purpose purpose);352352+ (*) struct fs_context *fs_context_for_mount(353353+ struct file_system_type *fs_type,354354+ unsigned int sb_flags);355355356356- Create a filesystem context for a given filesystem type and purpose. This357357- allocates the filesystem context, sets the superblock flags, initialises358358- the security and calls fs_type->init_fs_context() to initialise the359359- filesystem private data.356356+ Allocate a filesystem context for the purpose of setting up a new mount,357357+ whether that be with a new superblock or sharing an existing one. This358358+ sets the superblock flags, initialises the security and calls359359+ fs_type->init_fs_context() to initialise the filesystem private data.360360361361- reference can be NULL or it may indicate the root dentry of a superblock362362- that is going to be reconfigured (FS_CONTEXT_FOR_RECONFIGURE) or363363- the automount point that triggered a submount (FS_CONTEXT_FOR_SUBMOUNT).364364- This is provided as a source of namespace information.361361+ fs_type specifies the filesystem type that will manage the context and362362+ sb_flags presets the superblock flags stored therein.363363+364364+ (*) struct fs_context *fs_context_for_reconfigure(365365+ struct dentry *dentry,366366+ unsigned int sb_flags,367367+ unsigned int sb_flags_mask);368368+369369+ Allocate a filesystem context for the purpose of reconfiguring an370370+ existing superblock. dentry provides a reference to the superblock to be371371+ configured. sb_flags and sb_flags_mask indicate which superblock flags372372+ need changing and to what.373373+374374+ (*) struct fs_context *fs_context_for_submount(375375+ struct file_system_type *fs_type,376376+ struct dentry *reference);377377+378378+ Allocate a filesystem context for the purpose of creating a new mount for379379+ an automount point or other derived superblock. fs_type specifies the380380+ filesystem type that will manage the context and the reference dentry381381+ supplies the parameters. Namespaces are propagated from the reference382382+ dentry's superblock also.383383+384384+ Note that it's not a requirement that the reference dentry be of the same385385+ filesystem type as fs_type.365386366387 (*) struct fs_context *vfs_dup_fs_context(struct fs_context *src_fc);367388···406389407390For the remaining operations, if an error occurs, a negative error code will be408391returned.409409-410410- (*) int vfs_get_tree(struct fs_context *fc);411411-412412- Get or create the mountable root and superblock, using the parameters in413413- the filesystem context to select/configure the superblock. This invokes414414- the ->validate() op and then the ->get_tree() op.415415-416416- [NOTE] ->validate() could perhaps be rolled into ->get_tree() and417417- ->reconfigure().418418-419419- (*) struct vfsmount *vfs_create_mount(struct fs_context *fc);420420-421421- Create a mount given the parameters in the specified filesystem context.422422- Note that this does not attach the mount to anything.423392424393 (*) int vfs_parse_fs_param(struct fs_context *fc,425394 struct fs_parameter *param);···435432 clear the pointer, but then becomes responsible for disposing of the436433 object.437434438438- (*) int vfs_parse_fs_string(struct fs_context *fc, char *key,435435+ (*) int vfs_parse_fs_string(struct fs_context *fc, const char *key,439436 const char *value, size_t v_size);440437441441- A wrapper around vfs_parse_fs_param() that just passes a constant string.438438+ A wrapper around vfs_parse_fs_param() that copies the value string it is439439+ passed.442440443441 (*) int generic_parse_monolithic(struct fs_context *fc, void *data);444442445443 Parse a sys_mount() data page, assuming the form to be a text list446444 consisting of key[=val] options separated by commas. Each item in the447445 list is passed to vfs_mount_option(). This is the default when the448448- ->parse_monolithic() operation is NULL.446446+ ->parse_monolithic() method is NULL.447447+448448+ (*) int vfs_get_tree(struct fs_context *fc);449449+450450+ Get or create the mountable root and superblock, using the parameters in451451+ the filesystem context to select/configure the superblock. This invokes452452+ the ->get_tree() method.453453+454454+ (*) struct vfsmount *vfs_create_mount(struct fs_context *fc);455455+456456+ Create a mount given the parameters in the specified filesystem context.457457+ Note that this does not attach the mount to anything.458458+459459+460460+===========================461461+SUPERBLOCK CREATION HELPERS462462+===========================463463+464464+A number of VFS helpers are available for use by filesystems for the creation465465+or looking up of superblocks.466466+467467+ (*) struct super_block *468468+ sget_fc(struct fs_context *fc,469469+ int (*test)(struct super_block *sb, struct fs_context *fc),470470+ int (*set)(struct super_block *sb, struct fs_context *fc));471471+472472+ This is the core routine. If test is non-NULL, it searches for an473473+ existing superblock matching the criteria held in the fs_context, using474474+ the test function to match them. If no match is found, a new superblock475475+ is created and the set function is called to set it up.476476+477477+ Prior to the set function being called, fc->s_fs_info will be transferred478478+ to sb->s_fs_info - and fc->s_fs_info will be cleared if set returns479479+ success (ie. 0).480480+481481+The following helpers all wrap sget_fc():482482+483483+ (*) int vfs_get_super(struct fs_context *fc,484484+ enum vfs_get_super_keying keying,485485+ int (*fill_super)(struct super_block *sb,486486+ struct fs_context *fc))487487+488488+ This creates/looks up a deviceless superblock. The keying indicates how489489+ many superblocks of this type may exist and in what manner they may be490490+ shared:491491+492492+ (1) vfs_get_single_super493493+494494+ Only one such superblock may exist in the system. Any further495495+ attempt to get a new superblock gets this one (and any parameter496496+ differences are ignored).497497+498498+ (2) vfs_get_keyed_super499499+500500+ Multiple superblocks of this type may exist and they're keyed on501501+ their s_fs_info pointer (for example this may refer to a502502+ namespace).503503+504504+ (3) vfs_get_independent_super505505+506506+ Multiple independent superblocks of this type may exist. This507507+ function never matches an existing one and always creates a new508508+ one.449509450510451511=====================···520454521455 struct fs_parameter_description {522456 const char name[16];523523- u8 nr_params;524524- u8 nr_alt_keys;525525- u8 nr_enums;526526- bool ignore_unknown;527527- bool no_source;528528- const char *const *keys;529529- const struct constant_table *alt_keys;530457 const struct fs_parameter_spec *specs;531458 const struct fs_parameter_enum *enums;532459 };533460534461For example:535462536536- enum afs_param {463463+ enum {537464 Opt_autocell,538465 Opt_bar,539466 Opt_dyn,540467 Opt_foo,541468 Opt_source,542542- nr__afs_params543469 };544470545471 static const struct fs_parameter_description afs_fs_parameters = {546472 .name = "kAFS",547547- .nr_params = nr__afs_params,548548- .nr_alt_keys = ARRAY_SIZE(afs_param_alt_keys),549549- .nr_enums = ARRAY_SIZE(afs_param_enums),550550- .keys = afs_param_keys,551551- .alt_keys = afs_param_alt_keys,552473 .specs = afs_param_specs,553474 .enums = afs_param_enums,554475 };···547494 The name to be used in error messages generated by the parse helper548495 functions.549496550550- (2) u8 nr_params;497497+ (2) const struct fs_parameter_specification *specs;551498552552- The number of discrete parameter identifiers. This indicates the number553553- of elements in the ->types[] array and also limits the values that may be554554- used in the values that the ->keys[] array maps to.499499+ Table of parameter specifications, terminated with a null entry, where the500500+ entries are of type:555501556556- It is expected that, for example, two parameters that are related, say557557- "acl" and "noacl" with have the same ID, but will be flagged to indicate558558- that one is the inverse of the other. The value can then be picked out559559- from the parse result.560560-561561- (3) const struct fs_parameter_specification *specs;562562-563563- Table of parameter specifications, where the entries are of type:564564-565565- struct fs_parameter_type {566566- enum fs_parameter_spec type:8;567567- u8 flags;502502+ struct fs_parameter_spec {503503+ const char *name;504504+ u8 opt;505505+ enum fs_parameter_type type:8;506506+ unsigned short flags;568507 };569508570570- and the parameter identifier is the index to the array. 'type' indicates571571- the desired value type and must be one of:509509+ The 'name' field is a string to match exactly to the parameter key (no510510+ wildcards, patterns and no case-independence) and 'opt' is the value that511511+ will be returned by the fs_parser() function in the case of a successful512512+ match.513513+514514+ The 'type' field indicates the desired value type and must be one of:572515573516 TYPE NAME EXPECTED VALUE RESULT IN574517 ======================= ======================= =====================···574525 fs_param_is_u32_octal 32-bit octal int result->uint_32575526 fs_param_is_u32_hex 32-bit hex int result->uint_32576527 fs_param_is_s32 32-bit signed int result->int_32528528+ fs_param_is_u64 64-bit unsigned int result->uint_64577529 fs_param_is_enum Enum value name result->uint_32578530 fs_param_is_string Arbitrary string param->string579531 fs_param_is_blob Binary blob param->blob580532 fs_param_is_blockdev Blockdev path * Needs lookup581533 fs_param_is_path Path * Needs lookup582582- fs_param_is_fd File descriptor param->file583583-584584- And each parameter can be qualified with 'flags':585585-586586- fs_param_v_optional The value is optional587587- fs_param_neg_with_no If key name is prefixed with "no", it is false588588- fs_param_neg_with_empty If value is "", it is false589589- fs_param_deprecated The parameter is deprecated.590590-591591- For example:592592-593593- static const struct fs_parameter_spec afs_param_specs[nr__afs_params] = {594594- [Opt_autocell] = { fs_param_is flag },595595- [Opt_bar] = { fs_param_is_enum },596596- [Opt_dyn] = { fs_param_is flag },597597- [Opt_foo] = { fs_param_is_bool, fs_param_neg_with_no },598598- [Opt_source] = { fs_param_is_string },599599- };534534+ fs_param_is_fd File descriptor result->int_32600535601536 Note that if the value is of fs_param_is_bool type, fs_parse() will try602537 to match any string value against "0", "1", "no", "yes", "false", "true".603538604604- [!] NOTE that the table must be sorted according to primary key name so605605- that ->keys[] is also sorted.539539+ Each parameter can also be qualified with 'flags':606540607607- (4) const char *const *keys;541541+ fs_param_v_optional The value is optional542542+ fs_param_neg_with_no result->negated set if key is prefixed with "no"543543+ fs_param_neg_with_empty result->negated set if value is ""544544+ fs_param_deprecated The parameter is deprecated.608545609609- Table of primary key names for the parameters. There must be one entry610610- per defined parameter. The table is optional if ->nr_params is 0. The611611- table is just an array of names e.g.:546546+ These are wrapped with a number of convenience wrappers:612547613613- static const char *const afs_param_keys[nr__afs_params] = {614614- [Opt_autocell] = "autocell",615615- [Opt_bar] = "bar",616616- [Opt_dyn] = "dyn",617617- [Opt_foo] = "foo",618618- [Opt_source] = "source",548548+ MACRO SPECIFIES549549+ ======================= ===============================================550550+ fsparam_flag() fs_param_is_flag551551+ fsparam_flag_no() fs_param_is_flag, fs_param_neg_with_no552552+ fsparam_bool() fs_param_is_bool553553+ fsparam_u32() fs_param_is_u32554554+ fsparam_u32oct() fs_param_is_u32_octal555555+ fsparam_u32hex() fs_param_is_u32_hex556556+ fsparam_s32() fs_param_is_s32557557+ fsparam_u64() fs_param_is_u64558558+ fsparam_enum() fs_param_is_enum559559+ fsparam_string() fs_param_is_string560560+ fsparam_blob() fs_param_is_blob561561+ fsparam_bdev() fs_param_is_blockdev562562+ fsparam_path() fs_param_is_path563563+ fsparam_fd() fs_param_is_fd564564+565565+ all of which take two arguments, name string and option number - for566566+ example:567567+568568+ static const struct fs_parameter_spec afs_param_specs[] = {569569+ fsparam_flag ("autocell", Opt_autocell),570570+ fsparam_flag ("dyn", Opt_dyn),571571+ fsparam_string ("source", Opt_source),572572+ fsparam_flag_no ("foo", Opt_foo),573573+ {}619574 };620575621621- [!] NOTE that the table must be sorted such that the table can be searched622622- with bsearch() using strcmp(). This means that the Opt_* values must623623- correspond to the entries in this table.624624-625625- (5) const struct constant_table *alt_keys;626626- u8 nr_alt_keys;627627-628628- Table of additional key names and their mappings to parameter ID plus the629629- number of elements in the table. This is optional. The table is just an630630- array of { name, integer } pairs, e.g.:631631-632632- static const struct constant_table afs_param_keys[] = {633633- { "baz", Opt_bar },634634- { "dynamic", Opt_dyn },635635- };636636-637637- [!] NOTE that the table must be sorted such that strcmp() can be used with638638- bsearch() to search the entries.639639-640640- The parameter ID can also be fs_param_key_removed to indicate that a641641- deprecated parameter has been removed and that an error will be given.642642- This differs from fs_param_deprecated where the parameter may still have643643- an effect.644644-645645- Further, the behaviour of the parameter may differ when an alternate name646646- is used (for instance with NFS, "v3", "v4.2", etc. are alternate names).576576+ An addition macro, __fsparam() is provided that takes an additional pair577577+ of arguments to specify the type and the flags for anything that doesn't578578+ match one of the above macros.647579648580 (6) const struct fs_parameter_enum *enums;649649- u8 nr_enums;650581651651- Table of enum value names to integer mappings and the number of elements652652- stored therein. This is of type:582582+ Table of enum value names to integer mappings, terminated with a null583583+ entry. This is of type:653584654585 struct fs_parameter_enum {655655- u8 param_id;586586+ u8 opt;656587 char name[14];657588 u8 value;658589 };···649620 If a parameter of type fs_param_is_enum is encountered, fs_parse() will650621 try to look the value up in the enum table and the result will be stored651622 in the parse result.652652-653653- (7) bool no_source;654654-655655- If this is set, fs_parse() will ignore any "source" parameter and not656656- pass it to the filesystem.657623658624The parser should be pointed to by the parser pointer in the file_system_type659625struct as this will provide validation on registration (if···674650 int value;675651 };676652677677- and it must be sorted such that it can be searched using bsearch() using678678- strcmp(). If a match is found, the corresponding value is returned. If a679679- match isn't found, the not_found value is returned instead.653653+ If a match is found, the corresponding value is returned. If a match654654+ isn't found, the not_found value is returned instead.680655681656 (*) bool validate_constant_table(const struct constant_table *tbl,682657 size_t tbl_size,···688665 should just be set to lie inside the low-to-high range.689666690667 If all is good, true is returned. If the table is invalid, errors are691691- logged to dmesg, the stack is dumped and false is returned.668668+ logged to dmesg and false is returned.669669+670670+ (*) bool fs_validate_description(const struct fs_parameter_description *desc);671671+672672+ This performs some validation checks on a parameter description. It673673+ returns true if the description is good and false if it is not. It will674674+ log errors to dmesg if validation fails.692675693676 (*) int fs_parse(struct fs_context *fc,694694- const struct fs_param_parser *parser,677677+ const struct fs_parameter_description *desc,695678 struct fs_parameter *param,696696- struct fs_param_parse_result *result);679679+ struct fs_parse_result *result);697680698681 This is the main interpreter of parameters. It uses the parameter699699- description (parser) to look up the name of the parameter to use and to700700- convert that to a parameter ID (stored in result->key).682682+ description to look up a parameter by key name and to convert that to an683683+ option number (which it returns).701684702685 If successful, and if the parameter type indicates the result is a703686 boolean, integer or enum type, the value is converted by this function and704704- the result stored in result->{boolean,int_32,uint_32}.687687+ the result stored in result->{boolean,int_32,uint_32,uint_64}.705688706689 If a match isn't initially made, the key is prefixed with "no" and no707690 value is present then an attempt will be made to look up the key with the708691 prefix removed. If this matches a parameter for which the type has flag709709- fs_param_neg_with_no set, then a match will be made and the value will be710710- set to false/0/NULL.692692+ fs_param_neg_with_no set, then a match will be made and result->negated693693+ will be set to true.711694712712- If the parameter is successfully matched and, optionally, parsed713713- correctly, 1 is returned. If the parameter isn't matched and714714- parser->ignore_unknown is set, then 0 is returned. Otherwise -EINVAL is715715- returned.716716-717717- (*) bool fs_validate_description(const struct fs_parameter_description *desc);718718-719719- This is validates the parameter description. It returns true if the720720- description is good and false if it is not.695695+ If the parameter isn't matched, -ENOPARAM will be returned; if the696696+ parameter is matched, but the value is erroneous, -EINVAL will be697697+ returned; otherwise the parameter's option number will be returned.721698722699 (*) int fs_lookup_param(struct fs_context *fc,723700 struct fs_parameter *value,