FreeBSD kernel kern code
vfs_mountroot.c File Reference
#include "opt_rootdevname.h"
#include <sys/cdefs.h>
#include <sys/param.h>
#include <sys/conf.h>
#include <sys/cons.h>
#include <sys/eventhandler.h>
#include <sys/fcntl.h>
#include <sys/jail.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
#include <sys/mdioctl.h>
#include <sys/mount.h>
#include <sys/mutex.h>
#include <sys/namei.h>
#include <sys/priv.h>
#include <sys/proc.h>
#include <sys/filedesc.h>
#include <sys/reboot.h>
#include <sys/sbuf.h>
#include <sys/stat.h>
#include <sys/syscallsubr.h>
#include <sys/sysproto.h>
#include <sys/sx.h>
#include <sys/sysctl.h>
#include <sys/sysent.h>
#include <sys/systm.h>
#include <sys/vnode.h>
#include <geom/geom.h>
Include dependency graph for vfs_mountroot.c:

Go to the source code of this file.

Macros

#define CC_WHITESPACE   -1
 
#define CC_NONWHITESPACE   -2
 
#define PE_EOF   -1
 
#define PE_EOL   -2
 
#define ERRMSGL   255
 

Enumerations

enum  rh_flags { RH_FREE , RH_ALLOC , RH_ARG }
 

Functions

 __FBSDID ("$FreeBSD$")
 
static int parse_mount (char **)
 
static struct mntargparse_mountroot_options (struct mntarg *, const char *)
 
static int sysctl_vfs_root_mount_hold (SYSCTL_HANDLER_ARGS)
 
static void vfs_mountroot_wait (void)
 
static int vfs_mountroot_wait_if_neccessary (const char *fs, const char *dev)
 
 MTX_SYSINIT (root_holds, &root_holds_mtx, "root_holds", MTX_DEF)
 
static TAILQ_HEAD (root_hold_token)
 
 TUNABLE_INT ("vfs.mountroot.timeout", &root_mount_timeout)
 
 SYSCTL_INT (_vfs, OID_AUTO, root_mount_always_wait, CTLFLAG_RDTUN, &root_mount_always_wait, 0, "Wait for root mount holds even if the root device already exists")
 
 SYSCTL_PROC (_vfs, OID_AUTO, root_mount_hold, CTLTYPE_STRING|CTLFLAG_RD|CTLFLAG_MPSAFE, NULL, 0, sysctl_vfs_root_mount_hold, "A", "List of root mount hold tokens")
 
struct root_hold_token * root_mount_hold (const char *identifier)
 
void root_mount_hold_token (const char *identifier, struct root_hold_token *h)
 
void root_mount_rel (struct root_hold_token *h)
 
int root_mounted (void)
 
static void set_rootvnode (void)
 
static int vfs_mountroot_devfs (struct thread *td, struct mount **mpp)
 
static void vfs_mountroot_shuffle (struct thread *td, struct mount *mpdevfs)
 
static __inline int parse_peek (char **conf)
 
static __inline void parse_poke (char **conf, int c)
 
static __inline void parse_advance (char **conf)
 
static int parse_skipto (char **conf, int mc)
 
static int parse_token (char **conf, char **tok)
 
static void parse_dir_ask_printenv (const char *var)
 
static int parse_dir_ask (char **conf)
 
static int parse_dir_md (char **conf)
 
static int parse_dir_onfail (char **conf)
 
static int parse_dir_timeout (char **conf)
 
static int parse_directive (char **conf)
 
static int parse_mount_dev_present (const char *dev)
 
static int vfs_mountroot_parse (struct sbuf *sb, struct mount *mpdevfs)
 
static void vfs_mountroot_conf0 (struct sbuf *sb)
 
static int vfs_mountroot_readconf (struct thread *td, struct sbuf *sb)
 
void vfs_mountroot (void)
 

Variables

struct vnode * rootvnode
 
struct mount * rootdevmp
 
char * rootdevnames [2] = {NULL, NULL}
 
struct mtx root_holds_mtx
 
static enum action root_mount_onfail = A_CONTINUE
 
static int root_mount_mddev
 
static int root_mount_complete
 
static int root_mount_timeout = 3
 
static int root_mount_always_wait = 0
 

Macro Definition Documentation

◆ CC_NONWHITESPACE

#define CC_NONWHITESPACE   -2

Definition at line 436 of file vfs_mountroot.c.

◆ CC_WHITESPACE

#define CC_WHITESPACE   -1

Definition at line 435 of file vfs_mountroot.c.

◆ ERRMSGL

#define ERRMSGL   255

Definition at line 736 of file vfs_mountroot.c.

◆ PE_EOF

#define PE_EOF   -1

Definition at line 439 of file vfs_mountroot.c.

◆ PE_EOL

#define PE_EOL   -2

Definition at line 440 of file vfs_mountroot.c.

Enumeration Type Documentation

◆ rh_flags

enum rh_flags
Enumerator
RH_FREE 
RH_ALLOC 
RH_ARG 

Definition at line 124 of file vfs_mountroot.c.

Function Documentation

◆ __FBSDID()

__FBSDID ( "$FreeBSD$"  )

◆ MTX_SYSINIT()

MTX_SYSINIT ( root_holds  ,
root_holds_mtx,
"root_holds"  ,
MTX_DEF   
)

◆ parse_advance()

static __inline void parse_advance ( char **  conf)
static

Definition at line 457 of file vfs_mountroot.c.

Referenced by parse_mount(), parse_skipto(), and vfs_mountroot_parse().

Here is the caller graph for this function:

◆ parse_dir_ask()

static int parse_dir_ask ( char **  conf)
static

Definition at line 524 of file vfs_mountroot.c.

References cngets(), hz, name, parse_dir_ask_printenv(), parse_mount(), printf(), and vfs_mountroot_wait().

Referenced by parse_directive().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parse_dir_ask_printenv()

static void parse_dir_ask_printenv ( const char *  var)
static

Definition at line 512 of file vfs_mountroot.c.

References freeenv(), kern_getenv(), and printf().

Referenced by parse_dir_ask().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parse_dir_md()

static int parse_dir_md ( char **  conf)
static

Definition at line 576 of file vfs_mountroot.c.

References fd, free(), kern_close(), kern_ioctl(), kern_openat(), kern_statat(), malloc(), parse_token(), path, printf(), and root_mount_mddev.

Referenced by parse_directive().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parse_dir_onfail()

static int parse_dir_onfail ( char **  conf)
static

Definition at line 649 of file vfs_mountroot.c.

References free(), parse_token(), printf(), and root_mount_onfail.

Referenced by parse_directive().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parse_dir_timeout()

static int parse_dir_timeout ( char **  conf)
static

Definition at line 676 of file vfs_mountroot.c.

References free(), parse_token(), and root_mount_timeout.

Referenced by parse_directive().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parse_directive()

static int parse_directive ( char **  conf)
static

Definition at line 695 of file vfs_mountroot.c.

References free(), parse_dir_ask(), parse_dir_md(), parse_dir_onfail(), parse_dir_timeout(), parse_skipto(), parse_token(), and printf().

Referenced by vfs_mountroot_parse().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parse_mount()

static int parse_mount ( char **  conf)
static

◆ parse_mount_dev_present()

static int parse_mount_dev_present ( const char *  dev)
static

Definition at line 723 of file vfs_mountroot.c.

References namei(), NDFREE(), and vput().

Referenced by vfs_mountroot_wait_if_neccessary().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parse_mountroot_options()

static struct mntarg * parse_mountroot_options ( struct mntarg ma,
const char *  options 
)
static

Definition at line 1125 of file vfs_mountroot.c.

References free(), mount_arg(), and name.

Referenced by parse_mount().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parse_peek()

static __inline int parse_peek ( char **  conf)
static

Definition at line 443 of file vfs_mountroot.c.

Referenced by parse_skipto(), and vfs_mountroot_parse().

Here is the caller graph for this function:

◆ parse_poke()

static __inline void parse_poke ( char **  conf,
int  c 
)
static

Definition at line 450 of file vfs_mountroot.c.

Referenced by parse_mount().

Here is the caller graph for this function:

◆ parse_skipto()

static int parse_skipto ( char **  conf,
int  mc 
)
static

Definition at line 464 of file vfs_mountroot.c.

References CC_NONWHITESPACE, CC_WHITESPACE, parse_advance(), parse_peek(), PE_EOF, and PE_EOL.

Referenced by parse_directive(), parse_mount(), parse_token(), and vfs_mountroot_parse().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parse_token()

static int parse_token ( char **  conf,
char **  tok 
)
static

Definition at line 493 of file vfs_mountroot.c.

References CC_NONWHITESPACE, CC_WHITESPACE, malloc(), and parse_skipto().

Referenced by parse_dir_md(), parse_dir_onfail(), parse_dir_timeout(), parse_directive(), parse_mount(), and vfs_mountroot_conf0().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ root_mount_hold()

struct root_hold_token * root_mount_hold ( const char *  identifier)

Definition at line 174 of file vfs_mountroot.c.

References malloc(), RH_ALLOC, and root_holds_mtx.

Here is the call graph for this function:

◆ root_mount_hold_token()

void root_mount_hold_token ( const char *  identifier,
struct root_hold_token *  h 
)

Definition at line 189 of file vfs_mountroot.c.

References panic(), RH_ARG, and root_holds_mtx.

Here is the call graph for this function:

◆ root_mount_rel()

void root_mount_rel ( struct root_hold_token *  h)

Definition at line 212 of file vfs_mountroot.c.

References free(), RH_ALLOC, RH_FREE, root_holds_mtx, and wakeup().

Here is the call graph for this function:

◆ root_mounted()

int root_mounted ( void  )

Definition at line 230 of file vfs_mountroot.c.

References root_mount_complete.

◆ set_rootvnode()

static void set_rootvnode ( void  )
static

Definition at line 238 of file vfs_mountroot.c.

References mountlist, panic(), pwd_set_rootvnode(), and rootvnode.

Referenced by vfs_mountroot_devfs(), and vfs_mountroot_shuffle().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SYSCTL_INT()

SYSCTL_INT ( _vfs  ,
OID_AUTO  ,
root_mount_always_wait  ,
CTLFLAG_RDTUN  ,
root_mount_always_wait,
,
"Wait for root mount holds even if the root device already exists"   
)

◆ SYSCTL_PROC()

SYSCTL_PROC ( _vfs  ,
OID_AUTO  ,
root_mount_hold  ,
CTLTYPE_STRING|CTLFLAG_RD|  CTLFLAG_MPSAFE,
NULL  ,
,
sysctl_vfs_root_mount_hold  ,
"A"  ,
"List of root mount hold tokens"   
)

◆ sysctl_vfs_root_mount_hold()

static int sysctl_vfs_root_mount_hold ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 150 of file vfs_mountroot.c.

References root_holds_mtx, sbuf_data(), sbuf_delete(), sbuf_finish(), sbuf_len(), sbuf_new(), sbuf_printf(), and sbuf_putc().

Here is the call graph for this function:

◆ TAILQ_HEAD()

static TAILQ_HEAD ( root_hold_token  )
static

Definition at line 114 of file vfs_mountroot.c.

◆ TUNABLE_INT()

TUNABLE_INT ( "vfs.mountroot.timeout"  ,
root_mount_timeout 
)

◆ vfs_mountroot()

void vfs_mountroot ( void  )

◆ vfs_mountroot_conf0()

static void vfs_mountroot_conf0 ( struct sbuf *  sb)
static

Definition at line 896 of file vfs_mountroot.c.

References boothowto, free(), freeenv(), kern_getenv(), parse_token(), root_mount_timeout, rootdevnames, and sbuf_printf().

Referenced by vfs_mountroot().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ vfs_mountroot_devfs()

static int vfs_mountroot_devfs ( struct thread *  td,
struct mount **  mpp 
)
static

Definition at line 250 of file vfs_mountroot.c.

References kern_symlinkat(), malloc(), mountlist, mountlist_mtx, printf(), rootdevmp, set_rootvnode(), vfs_busy(), vfs_byname(), vfs_mount_alloc(), vfs_op_exit(), and vfsconf.

Referenced by vfs_mountroot().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ vfs_mountroot_parse()

static int vfs_mountroot_parse ( struct sbuf *  sb,
struct mount *  mpdevfs 
)
static

Definition at line 827 of file vfs_mountroot.c.

References CC_NONWHITESPACE, kern_reboot(), panic(), parse_advance(), parse_directive(), parse_mount(), parse_peek(), parse_skipto(), PE_EOL, printf(), root_mount_mddev, root_mount_onfail, and sbuf_data().

Referenced by vfs_mountroot().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ vfs_mountroot_readconf()

static int vfs_mountroot_readconf ( struct thread *  td,
struct sbuf *  sb 
)
static

Definition at line 943 of file vfs_mountroot.c.

References buf, flags, NDFREE(), sbuf_printf(), vn_close(), vn_open(), and vn_rdwr().

Referenced by vfs_mountroot().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ vfs_mountroot_shuffle()

static void vfs_mountroot_shuffle ( struct thread *  td,
struct mount *  mpdevfs 
)
static

Definition at line 308 of file vfs_mountroot.c.

References cache_purge(), cache_purgevfs(), kern_funlinkat(), mountlist, mountlist_mtx, namei(), NDFREE(), panic(), printf(), rootvnode, set_rootvnode(), vfs_unbusy(), vinvalbuf(), vn_irflag_set_locked(), vn_irflag_unset_locked(), vput(), and vrele().

Referenced by vfs_mountroot().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ vfs_mountroot_wait()

static void vfs_mountroot_wait ( void  )
static

Definition at line 979 of file vfs_mountroot.c.

References hz, ppsratecheck(), printf(), and root_holds_mtx.

Referenced by parse_dir_ask(), and vfs_mountroot_wait_if_neccessary().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ vfs_mountroot_wait_if_neccessary()

static int vfs_mountroot_wait_if_neccessary ( const char *  fs,
const char *  dev 
)
static

Definition at line 1014 of file vfs_mountroot.c.

References hz, parse_mount_dev_present(), printf(), root_mount_always_wait, root_mount_timeout, and vfs_mountroot_wait().

Referenced by parse_mount().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ root_holds_mtx

◆ root_mount_always_wait

int root_mount_always_wait = 0
static

Definition at line 139 of file vfs_mountroot.c.

Referenced by vfs_mountroot_wait_if_neccessary().

◆ root_mount_complete

int root_mount_complete
static

Definition at line 133 of file vfs_mountroot.c.

Referenced by root_mounted(), and vfs_mountroot().

◆ root_mount_mddev

int root_mount_mddev
static

Definition at line 132 of file vfs_mountroot.c.

Referenced by parse_dir_md(), parse_mount(), and vfs_mountroot_parse().

◆ root_mount_onfail

enum action root_mount_onfail = A_CONTINUE
static

Definition at line 130 of file vfs_mountroot.c.

Referenced by parse_dir_onfail(), and vfs_mountroot_parse().

◆ root_mount_timeout

int root_mount_timeout = 3
static

◆ rootdevmp

struct mount* rootdevmp

Definition at line 107 of file vfs_mountroot.c.

Referenced by dounmount(), kern_reroot(), vfs_mountroot_devfs(), and vfs_unmountall().

◆ rootdevnames

char* rootdevnames[2] = {NULL, NULL}

Definition at line 109 of file vfs_mountroot.c.

Referenced by vfs_mountroot_conf0().

◆ rootvnode