Skip to content

Commit bb35a6e

Browse files
borkmanndavem330
authored andcommitted
bpf, inode: allow for rename and link ops
Add support for renaming and hard links to the fs. Most of this can be implemented by using simple library operations under the same constraints that we don't use a reserved name like elsewhere. Linking can be useful to share/manage things like maps across subsystem users. It works within the file system boundary, but is not allowed for directories. Symbolic links are explicitly not implemented here, as it can be better done already by doing bind mounts inside bpf fs to set up shared directories f.e. useful when using volumes in docker containers that map a private working directory into /sys/fs/bpf/ which contains itself a bind mounted path from the host's /sys/fs/bpf/ mount that is shared among multiple containers. For single maps instead of whole directory, hard links can be easily used to do the same. Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent b626f2c commit bb35a6e

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

kernel/bpf/inode.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,31 @@ static int bpf_mkobj(struct inode *dir, struct dentry *dentry, umode_t mode,
187187
}
188188
}
189189

190+
static int bpf_link(struct dentry *old_dentry, struct inode *dir,
191+
struct dentry *new_dentry)
192+
{
193+
if (bpf_dname_reserved(new_dentry))
194+
return -EPERM;
195+
196+
return simple_link(old_dentry, dir, new_dentry);
197+
}
198+
199+
static int bpf_rename(struct inode *old_dir, struct dentry *old_dentry,
200+
struct inode *new_dir, struct dentry *new_dentry)
201+
{
202+
if (bpf_dname_reserved(new_dentry))
203+
return -EPERM;
204+
205+
return simple_rename(old_dir, old_dentry, new_dir, new_dentry);
206+
}
207+
190208
static const struct inode_operations bpf_dir_iops = {
191209
.lookup = simple_lookup,
192210
.mknod = bpf_mkobj,
193211
.mkdir = bpf_mkdir,
194212
.rmdir = simple_rmdir,
213+
.rename = bpf_rename,
214+
.link = bpf_link,
195215
.unlink = simple_unlink,
196216
};
197217

0 commit comments

Comments
 (0)