/* * nfs_path - reconstruct the path given an arbitrary dentry * @base - used to return pointer to the end of devname part of path * @dentry_in - pointer to dentry * @buffer - result buffer * @buflen_in - 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_in, char *buffer,
ssize_t buflen_in, unsigned flags)
{ char *end; int namelen; unsigned seq; constchar *base; struct dentry *dentry;
ssize_t 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);
}
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 nfs_fs_context *ctx; struct fs_context *fc; struct vfsmount *mnt = ERR_PTR(-ENOMEM); struct nfs_server *server = NFS_SB(path->dentry->d_sb); struct nfs_client *client = server->nfs_client; int timeout = READ_ONCE(nfs_mountpoint_expiry_timeout); int ret;
if (IS_ROOT(path->dentry)) return ERR_PTR(-ESTALE);
/* Open a new filesystem context, transferring parameters from the * parent superblock, including the network namespace.
*/
fc = fs_context_for_submount(path->mnt->mnt_sb->s_type, path->dentry); if (IS_ERR(fc)) return ERR_CAST(fc);
if (fc->net_ns != client->cl_net) {
put_net(fc->net_ns);
fc->net_ns = get_net(client->cl_net);
}
/* for submounts we want the same server; referrals will reassign */
memcpy(&ctx->nfs_server._address, &client->cl_addr, client->cl_addrlen);
ctx->nfs_server.addrlen = client->cl_addrlen;
ctx->nfs_server.port = server->port;
mark_mounts_for_expiry(list); if (!list_empty(list) && timeout > 0)
schedule_delayed_work(&nfs_automount_task, timeout);
}
void nfs_release_automount_timer(void)
{ if (list_empty(&nfs_automount_list))
cancel_delayed_work(&nfs_automount_task);
}
/** * nfs_do_submount - set up mountpoint when crossing a filesystem boundary * @fc: pointer to struct nfs_fs_context *
*/ int nfs_do_submount(struct fs_context *fc)
{ struct nfs_fs_context *ctx = nfs_fc2context(fc); struct dentry *dentry = ctx->clone_data.dentry; struct nfs_server *server; char *buffer, *p; int ret;
/* create a new volume representation */
server = ctx->nfs_mod->rpc_ops->clone_server(NFS_SB(ctx->clone_data.sb),
ctx->mntfh,
ctx->clone_data.fattr,
ctx->selected_flavor);
if (IS_ERR(server)) return PTR_ERR(server);
ctx->server = server;
buffer = kmalloc(4096, GFP_USER); if (!buffer) return -ENOMEM;
/* Look it up again to get its attributes */
err = server->nfs_client->rpc_ops->lookup(d_inode(parent), dentry, &dentry->d_name,
ctx->mntfh, ctx->clone_data.fattr);
dput(parent); if (err != 0) return err;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.