cregit-Linux how code gets into the kernel

Release 4.11 fs/nfs/namespace.c

Directory: fs/nfs
/*
 * linux/fs/nfs/namespace.c
 *
 * Copyright (C) 2005 Trond Myklebust <Trond.Myklebust@netapp.com>
 * - Modified by David Howells <dhowells@redhat.com>
 *
 * NFS namespace
 */

#include <linux/module.h>
#include <linux/dcache.h>
#include <linux/gfp.h>
#include <linux/mount.h>
#include <linux/namei.h>
#include <linux/nfs_fs.h>
#include <linux/string.h>
#include <linux/sunrpc/clnt.h>
#include <linux/vfs.h>
#include <linux/sunrpc/gss_api.h>
#include "internal.h"


#define NFSDBG_FACILITY		NFSDBG_VFS

static void nfs_expire_automounts(struct work_struct *work);

static LIST_HEAD(nfs_automount_list);
static DECLARE_DELAYED_WORK(nfs_automount_task, nfs_expire_automounts);

int nfs_mountpoint_expiry_timeout = 500 * HZ;

/*
 * nfs_path - reconstruct the path given an arbitrary dentry
 * @base - used to return pointer to the end of devname part of path
 * @dentry - pointer to dentry
 * @buffer - result buffer
 * @buflen - length of buffer
 * @flags - options (see below)
 *
 * Helper function for constructing the server pathname
 * by arbitrary hashed dentry.
 *
 * This is mainly for use in figuring out the path on the
 * server side when automounting on top of an existing partition
 * and in generating /proc/mounts and friends.
 *
 * Supported flags:
 * NFS_PATH_CANONICAL: ensure there is exactly one slash after
 *                     the original device (export) name
 *                     (if unset, the original name is returned verbatim)
 */

char *nfs_path(char **p, struct dentry *dentry, char *buffer, ssize_t buflen, unsigned flags) { char *end; int namelen; unsigned seq; const char *base; rename_retry: end = buffer+buflen; *--end = '\0'; buflen--; seq = read_seqbegin(&rename_lock); rcu_read_lock(); while (1) { spin_lock(&dentry->d_lock); if (IS_ROOT(dentry)) break; namelen = dentry->d_name.len; buflen -= namelen + 1; if (buflen < 0) goto Elong_unlock; end -= namelen; memcpy(end, dentry->d_name.name, namelen); *--end = '/'; spin_unlock(&dentry->d_lock); dentry = dentry->d_parent; } if (read_seqretry(&rename_lock, seq)) { spin_unlock(&dentry->d_lock); rcu_read_unlock(); goto rename_retry; } if ((flags & NFS_PATH_CANONICAL) && *end != '/') { if (--buflen < 0) { spin_unlock(&dentry->d_lock); rcu_read_unlock(); goto Elong; } *--end = '/'; } *p = end; base = dentry->d_fsdata; if (!base) { spin_unlock(&dentry->d_lock); rcu_read_unlock(); WARN_ON(1); return end; } namelen = strlen(base); if (*end == '/') { /* Strip off excess slashes in base string */ while (namelen > 0 && base[namelen - 1] == '/') namelen--; } buflen -= namelen; if (buflen < 0) { spin_unlock(&dentry->d_lock); rcu_read_unlock(); goto Elong; } end -= namelen; memcpy(end, base, namelen); spin_unlock(&dentry->d_lock); rcu_read_unlock(); return end; Elong_unlock: spin_unlock(&dentry->d_lock); rcu_read_unlock(); if (read_seqretry(&rename_lock, seq)) goto rename_retry; Elong: return ERR_PTR(-ENAMETOOLONG); }

Contributors

PersonTokensPropCommitsCommitProp
David Howells16142.26%222.22%
Al Viro12131.76%111.11%
Nicholas Piggin5113.39%111.11%
Trond Myklebust256.56%111.11%
Ben Hutchings143.67%111.11%
Benjamin Coddington41.05%111.11%
Josh Triplett30.79%111.11%
Dan Carpenter20.52%111.11%
Total381100.00%9100.00%

EXPORT_SYMBOL_GPL(nfs_path); /* * nfs_d_automount - Handle crossing a mountpoint on the server * @path - The mountpoint * * When we encounter a mountpoint on the server, we want to set up * a mountpoint on the client too, to prevent inode numbers from * colliding, and to allow "df" to work properly. * On NFSv4, we also want to allow for the fact that different * filesystems may be migrated to different servers in a failover * situation, and that different filesystems may want to use * different security flavours. */
struct vfsmount *nfs_d_automount(struct path *path) { struct vfsmount *mnt; struct nfs_server *server = NFS_SERVER(d_inode(path->dentry)); struct nfs_fh *fh = NULL; struct nfs_fattr *fattr = NULL; dprintk("--> nfs_d_automount()\n"); mnt = ERR_PTR(-ESTALE); if (IS_ROOT(path->dentry)) goto out_nofree; mnt = ERR_PTR(-ENOMEM); fh = nfs_alloc_fhandle(); fattr = nfs_alloc_fattr(); if (fh == NULL || fattr == NULL) goto out; dprintk("%s: enter\n", __func__); mnt = server->nfs_client->rpc_ops->submount(server, path->dentry, fh, fattr); if (IS_ERR(mnt)) goto out; dprintk("%s: done, success\n", __func__); mntget(mnt); /* prevent immediate expiration */ mnt_set_expiry(mnt, &nfs_automount_list); schedule_delayed_work(&nfs_automount_task, nfs_mountpoint_expiry_timeout); out: nfs_free_fattr(fattr); nfs_free_fhandle(fh); out_nofree: if (IS_ERR(mnt)) dprintk("<-- %s(): error %ld\n", __func__, PTR_ERR(mnt)); else dprintk("<-- %s() = %p\n", __func__, mnt); return mnt; }

Contributors

PersonTokensPropCommitsCommitProp
Trond Myklebust10548.84%318.75%
David Howells5525.58%531.25%
Chuck Lever2310.70%16.25%
Bryan Schumaker188.37%212.50%
Denis V. Lunev94.19%16.25%
Jan Blunck20.93%212.50%
Manoj Naik20.93%16.25%
Harvey Harrison10.47%16.25%
Total215100.00%16100.00%


static int nfs_namespace_getattr(const struct path *path, struct kstat *stat, u32 request_mask, unsigned int query_flags) { if (NFS_FH(d_inode(path->dentry))->size != 0) return nfs_getattr(path, stat, request_mask, query_flags); generic_fillattr(d_inode(path->dentry), stat); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Trond Myklebust4262.69%133.33%
David Howells2537.31%266.67%
Total67100.00%3100.00%


static int nfs_namespace_setattr(struct dentry *dentry, struct iattr *attr) { if (NFS_FH(d_inode(dentry))->size != 0) return nfs_setattr(dentry, attr); return -EACCES; }

Contributors

PersonTokensPropCommitsCommitProp
Trond Myklebust3992.86%150.00%
David Howells37.14%150.00%
Total42100.00%2100.00%

const struct inode_operations nfs_mountpoint_inode_operations = { .getattr = nfs_getattr, .setattr = nfs_setattr, }; const struct inode_operations nfs_referral_inode_operations = { .getattr = nfs_namespace_getattr, .setattr = nfs_namespace_setattr, };
static void nfs_expire_automounts(struct work_struct *work) { struct list_head *list = &nfs_automount_list; mark_mounts_for_expiry(list); if (!list_empty(list)) schedule_delayed_work(&nfs_automount_task, nfs_mountpoint_expiry_timeout); }

Contributors

PersonTokensPropCommitsCommitProp
Trond Myklebust3587.50%150.00%
David Howells512.50%150.00%
Total40100.00%2100.00%


void nfs_release_automount_timer(void) { if (list_empty(&nfs_automount_list)) cancel_delayed_work(&nfs_automount_task); }

Contributors

PersonTokensPropCommitsCommitProp
Trond Myklebust21100.00%2100.00%
Total21100.00%2100.00%

/* * Clone a mountpoint of the appropriate type */
static struct vfsmount *nfs_do_clone_mount(struct nfs_server *server, const char *devname, struct nfs_clone_mount *mountdata) { return vfs_submount(mountdata->dentry, &nfs_xdev_fs_type, devname, mountdata); }

Contributors

PersonTokensPropCommitsCommitProp
David Howells3386.84%375.00%
Eric W. Biedermann513.16%125.00%
Total38100.00%4100.00%

/** * nfs_do_submount - set up mountpoint when crossing a filesystem boundary * @dentry - parent directory * @fh - filehandle for new root dentry * @fattr - attributes for new root inode * @authflavor - security flavor to use when performing the mount * */
struct vfsmount *nfs_do_submount(struct dentry *dentry, struct nfs_fh *fh, struct nfs_fattr *fattr, rpc_authflavor_t authflavor) { struct nfs_clone_mount mountdata = { .sb = dentry->d_sb, .dentry = dentry, .fh = fh, .fattr = fattr, .authflavor = authflavor, }; struct vfsmount *mnt = ERR_PTR(-ENOMEM); char *page = (char *) __get_free_page(GFP_USER); char *devname; dprintk("--> nfs_do_submount()\n"); dprintk("%s: submounting on %pd2\n", __func__, dentry); if (page == NULL) goto out; devname = nfs_devname(dentry, page, PAGE_SIZE); mnt = (struct vfsmount *)devname; if (IS_ERR(devname)) goto free_page; mnt = nfs_do_clone_mount(NFS_SB(dentry->d_sb), devname, &mountdata); free_page: free_page((unsigned long)page); out: dprintk("%s: done\n", __func__); dprintk("<-- nfs_do_submount() = %p\n", mnt); return mnt; }

Contributors

PersonTokensPropCommitsCommitProp
David Howells16990.86%233.33%
Bryan Schumaker84.30%116.67%
Al Viro73.76%233.33%
Harvey Harrison21.08%116.67%
Total186100.00%6100.00%

EXPORT_SYMBOL_GPL(nfs_do_submount);
struct vfsmount *nfs_submount(struct nfs_server *server, struct dentry *dentry, struct nfs_fh *fh, struct nfs_fattr *fattr) { int err; struct dentry *parent = dget_parent(dentry); /* Look it up again to get its attributes */ err = server->nfs_client->rpc_ops->lookup(d_inode(parent), &dentry->d_name, fh, fattr, NULL); dput(parent); if (err != 0) return ERR_PTR(err); return nfs_do_submount(dentry, fh, fattr, server->client->cl_auth->au_flavor); }

Contributors

PersonTokensPropCommitsCommitProp
Bryan Schumaker9895.15%133.33%
David Howells32.91%133.33%
David Quigley21.94%133.33%
Total103100.00%3100.00%

EXPORT_SYMBOL_GPL(nfs_submount);

Overall Contributors

PersonTokensPropCommitsCommitProp
David Howells46938.60%1025.00%
Trond Myklebust34027.98%615.00%
Bryan Schumaker14612.02%512.50%
Al Viro12810.53%37.50%
Nicholas Piggin514.20%12.50%
Chuck Lever231.89%12.50%
Ben Hutchings151.23%12.50%
Denis V. Lunev90.74%12.50%
Manoj Naik70.58%12.50%
Eric W. Biedermann50.41%12.50%
Benjamin Coddington40.33%12.50%
Josh Triplett30.25%12.50%
Tejun Heo30.25%12.50%
Harvey Harrison30.25%12.50%
Jan Blunck20.16%25.00%
Arjan van de Ven20.16%12.50%
Dan Carpenter20.16%12.50%
David Quigley20.16%12.50%
Adrian Bunk10.08%12.50%
Total1215100.00%40100.00%
Directory: fs/nfs
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
Created with cregit.