Skip to content

nfsd load

Donald Buczek edited this page Jul 20, 2020 · 8 revisions
    MODULE_ALIAS_FS("nfsd");

will make alias fs-nfsd nfsd appear in /lib/modules/$(uname -r)/modules.aliases, so when mount -t nfsd nfsd /proc/fs/nfsd is executed by proc-fs-nfsd.mount, the module is requested by https://elixir.bootlin.com/linux/v5.7/source/fs/filesystems.c#L273

    struct file_system_type *get_fs_type(const char *name)
    {
        /* ... */
	fs = __get_fs_type(name, len);
	if (!fs && (request_module("fs-%.*s", len, name) == 0)) {
		fs = __get_fs_type(name, len);
        /* ... */

https://elixir.bootlin.com/linux/v5.7/source/fs/nfsd/nfsctl.c#L1577

module_init(init_nfsd)

https://elixir.bootlin.com/linux/v5.7/source/fs/nfsd/nfsctl.c#L1517

unsigned int nfsd_net_id;
/* ... */
static struct pernet_operations nfsd_net_ops = {
	.init = nfsd_init_net,
	.exit = nfsd_exit_net,
	.id   = &nfsd_net_id,
	.size = sizeof(struct nfsd_net),
};

static int __init init_nfsd(void)
{
	int retval;
	printk(KERN_INFO "Installing knfsd (copyright (C) 1996 okir@monad.swb.de).\n");

	retval = register_pernet_subsys(&nfsd_net_ops);

A zero filled struct nfsd_net is allocated and nfsd_init_net is called for each existing network namespace and will be done for each future network namespace.

https://elixir.bootlin.com/linux/v5.7/source/fs/nfsd/nfsctl.c#L1451

static __net_init int nfsd_init_net(struct net *net)
{
	int retval;
	struct vfsmount *mnt;
	struct nfsd_net *nn = net_generic(net, nfsd_net_id);

	retval = nfsd_export_init(net);
	if (retval)
		goto out_export_error;

init nfsd.export und nfsd.export caches and their /proc/net/rpc/NAME..

	retval = nfsd_idmap_init(net);
	if (retval)
		goto out_idmap_error;

init "nfs4.nametoid" and "nfs4.idtoname" cachees (nfs4 UID/GID mappings to names)

	nn->nfsd_versions = NULL;
	nn->nfsd4_minorversions = NULL;
	retval = nfsd_reply_cache_init(nn);
	if (retval)
		goto out_drc_error;

init reply cache (SLAB "nfsd_drc" but probably merged with another compatible type, so not visible in /proc/slabinfo).

	nn->nfsd_versions = NULL;
	nn->nfsd4_minorversions = NULL;
	retval = nfsd_reply_cache_init(nn);
	if (retval)
		goto out_drc_error;
	nn->nfsd4_lease = 90;	/* default lease time */
	nn->nfsd4_grace = 90;
	nn->somebody_reclaimed = false;
	nn->track_reclaim_completes = false;
	nn->clverifier_counter = prandom_u32();
	nn->clientid_base = prandom_u32();
	nn->clientid_counter = nn->clientid_base + 1;
	nn->s2s_cp_cl_id = nn->clientid_counter++;

	atomic_set(&nn->ntf_refcnt, 0);
	init_waitqueue_head(&nn->ntf_wq);
	seqlock_init(&nn->boot_lock);

	mnt =  vfs_kern_mount(&nfsd_fs_type, SB_KERNMOUNT, "nfsd", NULL);
	if (IS_ERR(mnt)) {
		retval = PTR_ERR(mnt);
		goto out_mount_err;
	}

the mount is not (yet) attached to anything.