Skip to content
Navigation Menu
Toggle navigation
Sign in
In this repository
All GitHub Enterprise
↵
Jump to
↵
No suggested jump to results
In this repository
All GitHub Enterprise
↵
Jump to
↵
In this organization
All GitHub Enterprise
↵
Jump to
↵
In this repository
All GitHub Enterprise
↵
Jump to
↵
Sign in
Reseting focus
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
mariux64
/
linux
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
2
Pull requests
0
Actions
Projects
0
Wiki
Security
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security
Insights
Files
1eb80d6
Documentation
LICENSES
arch
block
certs
crypto
drivers
fs
9p
adfs
affs
afs
Kconfig
Makefile
addr_list.c
afs.h
afs_cm.h
afs_fs.h
afs_vl.h
cache.c
callback.c
cell.c
cmservice.c
dir.c
dir_edit.c
dir_silly.c
dynroot.c
file.c
flock.c
fs_probe.c
fsclient.c
inode.c
internal.h
main.c
misc.c
mntpt.c
proc.c
protocol_uae.h
protocol_yfs.h
rotate.c
rxrpc.c
security.c
server.c
server_list.c
super.c
vl_list.c
vl_probe.c
vl_rotate.c
vlclient.c
volume.c
write.c
xattr.c
xdr_fs.h
yfsclient.c
autofs
befs
bfs
btrfs
cachefiles
ceph
cifs
coda
configfs
cramfs
crypto
debugfs
devpts
dlm
ecryptfs
efivarfs
efs
erofs
exportfs
ext2
ext4
f2fs
fat
freevxfs
fscache
fuse
gfs2
hfs
hfsplus
hostfs
hpfs
hugetlbfs
iomap
isofs
jbd2
jffs2
jfs
kernfs
lockd
minix
nfs
nfs_common
nfsd
nilfs2
nls
notify
ntfs
ocfs2
omfs
openpromfs
orangefs
overlayfs
proc
pstore
qnx4
qnx6
quota
ramfs
reiserfs
romfs
squashfs
sysfs
sysv
tracefs
ubifs
udf
ufs
unicode
verity
xfs
Kconfig
Kconfig.binfmt
Makefile
aio.c
anon_inodes.c
attr.c
bad_inode.c
binfmt_aout.c
binfmt_elf.c
binfmt_elf_fdpic.c
binfmt_em86.c
binfmt_flat.c
binfmt_misc.c
binfmt_script.c
block_dev.c
buffer.c
char_dev.c
compat.c
compat_binfmt_elf.c
compat_ioctl.c
coredump.c
d_path.c
dax.c
dcache.c
dcookies.c
direct-io.c
drop_caches.c
eventfd.c
eventpoll.c
exec.c
fcntl.c
fhandle.c
file.c
file_table.c
filesystems.c
fs-writeback.c
fs_context.c
fs_parser.c
fs_pin.c
fs_struct.c
fs_types.c
fsopen.c
inode.c
internal.h
io_uring.c
ioctl.c
libfs.c
locks.c
mbcache.c
mount.h
mpage.c
namei.c
namespace.c
no-block.c
nsfs.c
open.c
pipe.c
pnode.c
pnode.h
posix_acl.c
proc_namespace.c
read_write.c
readdir.c
select.c
seq_file.c
signalfd.c
splice.c
stack.c
stat.c
statfs.c
super.c
sync.c
timerfd.c
userfaultfd.c
utimes.c
xattr.c
include
init
ipc
kernel
lib
mm
net
samples
scripts
security
sound
tools
usr
virt
.clang-format
.cocciconfig
.get_maintainer.ignore
.gitattributes
.gitignore
.mailmap
COPYING
CREDITS
Kbuild
Kconfig
MAINTAINERS
Makefile
README
Breadcrumbs
linux
/
fs
/
afs
/
dynroot.c
Blame
Blame
Latest commit
History
History
300 lines (251 loc) · 6.61 KB
Breadcrumbs
linux
/
fs
/
afs
/
dynroot.c
Top
File metadata and controls
Code
Blame
300 lines (251 loc) · 6.61 KB
Raw
// SPDX-License-Identifier: GPL-2.0-or-later /* AFS dynamic root handling * * Copyright (C) 2018 Red Hat, Inc. All Rights Reserved. * Written by David Howells (dhowells@redhat.com) */ #include <linux/fs.h> #include <linux/namei.h> #include <linux/dns_resolver.h> #include "internal.h" /* * Probe to see if a cell may exist. This prevents positive dentries from * being created unnecessarily. */ static int afs_probe_cell_name(struct dentry *dentry) { struct afs_cell *cell; struct afs_net *net = afs_d2net(dentry); const char *name = dentry->d_name.name; size_t len = dentry->d_name.len; int ret; /* Names prefixed with a dot are R/W mounts. */ if (name[0] == '.') { if (len == 1) return -EINVAL; name++; len--; } cell = afs_lookup_cell_rcu(net, name, len); if (!IS_ERR(cell)) { afs_put_cell(net, cell); return 0; } ret = dns_query(net->net, "afsdb", name, len, "srv=1", NULL, NULL, false); if (ret == -ENODATA) ret = -EDESTADDRREQ; return ret; } /* * Try to auto mount the mountpoint with pseudo directory, if the autocell * operation is setted. */ struct inode *afs_try_auto_mntpt(struct dentry *dentry, struct inode *dir) { struct afs_vnode *vnode = AFS_FS_I(dir); struct inode *inode; int ret = -ENOENT; _enter("%p{%pd}, {%llx:%llu}", dentry, dentry, vnode->fid.vid, vnode->fid.vnode); if (!test_bit(AFS_VNODE_AUTOCELL, &vnode->flags)) goto out; ret = afs_probe_cell_name(dentry); if (ret < 0) goto out; inode = afs_iget_pseudo_dir(dir->i_sb, false); if (IS_ERR(inode)) { ret = PTR_ERR(inode); goto out; } _leave("= %p", inode); return inode; out: _leave("= %d", ret); return ret == -ENOENT ? NULL : ERR_PTR(ret); } /* * Look up @cell in a dynroot directory. This is a substitution for the * local cell name for the net namespace. */ static struct dentry *afs_lookup_atcell(struct dentry *dentry) { struct afs_cell *cell; struct afs_net *net = afs_d2net(dentry); struct dentry *ret; unsigned int seq = 0; char *name; int len; if (!net->ws_cell) return ERR_PTR(-ENOENT); ret = ERR_PTR(-ENOMEM); name = kmalloc(AFS_MAXCELLNAME + 1, GFP_KERNEL); if (!name) goto out_p; rcu_read_lock(); do { read_seqbegin_or_lock(&net->cells_lock, &seq); cell = rcu_dereference_raw(net->ws_cell); if (cell) { len = cell->name_len; memcpy(name, cell->name, len + 1); } } while (need_seqretry(&net->cells_lock, seq)); done_seqretry(&net->cells_lock, seq); rcu_read_unlock(); ret = ERR_PTR(-ENOENT); if (!cell) goto out_n; ret = lookup_one_len(name, dentry->d_parent, len); /* We don't want to d_add() the @cell dentry here as we don't want to * the cached dentry to hide changes to the local cell name. */ out_n: kfree(name); out_p: return ret; } /* * Look up an entry in a dynroot directory. */ static struct dentry *afs_dynroot_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags) { _enter("%pd", dentry); ASSERTCMP(d_inode(dentry), ==, NULL); if (dentry->d_name.len >= AFSNAMEMAX) { _leave(" = -ENAMETOOLONG"); return ERR_PTR(-ENAMETOOLONG); } if (dentry->d_name.len == 5 && memcmp(dentry->d_name.name, "@cell", 5) == 0) return afs_lookup_atcell(dentry); return d_splice_alias(afs_try_auto_mntpt(dentry, dir), dentry); } const struct inode_operations afs_dynroot_inode_operations = { .lookup = afs_dynroot_lookup, }; /* * Dirs in the dynamic root don't need revalidation. */ static int afs_dynroot_d_revalidate(struct dentry *dentry, unsigned int flags) { return 1; } /* * Allow the VFS to enquire as to whether a dentry should be unhashed (mustn't * sleep) * - called from dput() when d_count is going to 0. * - return 1 to request dentry be unhashed, 0 otherwise */ static int afs_dynroot_d_delete(const struct dentry *dentry) { return d_really_is_positive(dentry); } const struct dentry_operations afs_dynroot_dentry_operations = { .d_revalidate = afs_dynroot_d_revalidate, .d_delete = afs_dynroot_d_delete, .d_release = afs_d_release, .d_automount = afs_d_automount, }; /* * Create a manually added cell mount directory. * - The caller must hold net->proc_cells_lock */ int afs_dynroot_mkdir(struct afs_net *net, struct afs_cell *cell) { struct super_block *sb = net->dynroot_sb; struct dentry *root, *subdir; int ret; if (!sb || atomic_read(&sb->s_active) == 0) return 0; /* Let the ->lookup op do the creation */ root = sb->s_root; inode_lock(root->d_inode); subdir = lookup_one_len(cell->name, root, cell->name_len); if (IS_ERR(subdir)) { ret = PTR_ERR(subdir); goto unlock; } /* Note that we're retaining an extra ref on the dentry */ subdir->d_fsdata = (void *)1UL; ret = 0; unlock: inode_unlock(root->d_inode); return ret; } /* * Remove a manually added cell mount directory. * - The caller must hold net->proc_cells_lock */ void afs_dynroot_rmdir(struct afs_net *net, struct afs_cell *cell) { struct super_block *sb = net->dynroot_sb; struct dentry *root, *subdir; if (!sb || atomic_read(&sb->s_active) == 0) return; root = sb->s_root; inode_lock(root->d_inode); /* Don't want to trigger a lookup call, which will re-add the cell */ subdir = try_lookup_one_len(cell->name, root, cell->name_len); if (IS_ERR_OR_NULL(subdir)) { _debug("lookup %ld", PTR_ERR(subdir)); goto no_dentry; } _debug("rmdir %pd %u", subdir, d_count(subdir)); if (subdir->d_fsdata) { _debug("unpin %u", d_count(subdir)); subdir->d_fsdata = NULL; dput(subdir); } dput(subdir); no_dentry: inode_unlock(root->d_inode); _leave(""); } /* * Populate a newly created dynamic root with cell names. */ int afs_dynroot_populate(struct super_block *sb) { struct afs_cell *cell; struct afs_net *net = afs_sb2net(sb); int ret; mutex_lock(&net->proc_cells_lock); net->dynroot_sb = sb; hlist_for_each_entry(cell, &net->proc_cells, proc_link) { ret = afs_dynroot_mkdir(net, cell); if (ret < 0) goto error; } ret = 0; out: mutex_unlock(&net->proc_cells_lock); return ret; error: net->dynroot_sb = NULL; goto out; } /* * When a dynamic root that's in the process of being destroyed, depopulate it * of pinned directories. */ void afs_dynroot_depopulate(struct super_block *sb) { struct afs_net *net = afs_sb2net(sb); struct dentry *root = sb->s_root, *subdir, *tmp; /* Prevent more subdirs from being created */ mutex_lock(&net->proc_cells_lock); if (net->dynroot_sb == sb) net->dynroot_sb = NULL; mutex_unlock(&net->proc_cells_lock); inode_lock(root->d_inode); /* Remove all the pins for dirs created for manually added cells */ list_for_each_entry_safe(subdir, tmp, &root->d_subdirs, d_child) { if (subdir->d_fsdata) { subdir->d_fsdata = NULL; dput(subdir); } } inode_unlock(root->d_inode); }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
You can’t perform that action at this time.