aboutsummaryrefslogtreecommitdiff
path: root/sys/fs/fdescfs
Commit message (Collapse)AuthorAgeFilesLines
* file: Add a fd flag with O_RESOLVE_BENEATH semanticsMark Johnston2026-02-091-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | The O_RESOLVE_BENEATH openat(2) flag restricts name lookups such that they remain under the directory referenced by the dirfd. This commit introduces an implicit version of the flag, FD_RESOLVE_BENEATH, stored in the file descriptor entry. When the flag is set, any lookup relative to that fd automatically has O_RESOLVE_BENEATH semantics. Furthermore, the flag is sticky, meaning that it cannot be cleared, and it is copied by dup() and openat(). File descriptors with FD_RESOLVE_BENEATH set may not be passed to fchdir(2) or fchroot(2). Various fd lookup routines are modified to return fd flags to the caller. This flag will be used to address a case where jails with different root directories and the ability to pass SCM_RIGHTS messages across the jail boundary can transfer directory fds in such as way as to allow a filesystem escape. PR: 262180 Reviewed by: kib MFC after: 3 weeks Differential Revision: https://reviews.freebsd.org/D50371 (cherry picked from commit f35525ff2053e026a423e852136d73ed93c95803)
* Fix MNT_IGNORE for devfs, fdescfs and nullfsDoug Rabson2024-04-271-1/+1
| | | | | | | | | | | | | | | | | | The MNT_IGNORE flag can be used to mark certain filesystem mounts so that utilities such as df(1) and mount(8) can filter out those mounts by default. This can be used, for instance, to reduce the noise from running container workloads inside jails which often have at least three and sometimes as many as ten mounts per container. The flag is supplied by the nmount(2) system call and is recorded so that it can be reported by statfs(2). Unfortunately several filesystems override the default behaviour and mask out the flag, defeating its purpose. This change preserves the MNT_IGNORE flag for those filesystems so that it can be reported correctly. MFC after: 1 week (cherry picked from commit b5c4616582cebdcf4dee909a3c2f5b113c4ae59e)
* sys: Remove $FreeBSD$: two-line .h patternWarner Losh2023-08-233-6/+0
| | | | | | | Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/ Similar commit in current: (cherry picked from commit 95ee2897e98f)
* fdescfs: add a mount option rdlnkKonstantin Belousov2023-07-203-6/+13
| | | | | | PR: 272127 (cherry picked from commit 3905309dfeeb89f03b09c347f7ac0a863faa3975)
* Revert "VFS: Remove VV_READLINK flag" and "fdescfs: improve linrdlnk mount ↵Konstantin Belousov2023-07-201-2/+1
| | | | | | option" (cherry picked from commit 9c3bfe2ad07170cd7d3645a7c24f4d80a509c2b7)
* fdescfs: improve linrdlnk mount optionKonstantin Belousov2023-07-041-3/+5
| | | | | | PR: 272127 (cherry picked from commit 3bffa2262328e4ff1737516f176107f607e7bc76)
* sys/fs: do not report blocks allocated for synthetic file systemsStefan Eßer2023-05-011-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | The pseudo file systems (devfs, fdescfs, procfs, etc.) report total and available blocks and inodes despite being synthetic with no underlying storage device to which those values could be applied. The current code of these file systems tends to report a fixed number of total blocks but no free blocks, and in the case of procfs, libprocfs, linsysfs also no free inodes. This can be irritating in e.g. the "df" output, since 100% of the resources seem to be in use, but it can also create warnings in monitoring tools used for capacity management. This patch makes these file systems return the same value for the total and free parameters, leading to 0% in use being displayed by "df". Since there is no resource that can be exhausted, this appears to be a sensible result. Reviewed by: mckusick Differential Revision: https://reviews.freebsd.org/D39442 (cherry picked from commit 88a795e80c03ff1d960d830ee273589664ab06cc)
* fdesc_lookup(): drop fdroppedKonstantin Belousov2023-04-061-6/+2
| | | | (cherry picked from commit 13262b07a06910edd5e58e6bb2e1d4786a7b7d8e)
* fdesc_lookup(): the condition to use vn_vget_ino() is always trueKonstantin Belousov2023-04-061-20/+18
| | | | (cherry picked from commit 7dca8fd1cb3f91e7a3c07b7f57af6d9d43d0c71c)
* fdesc_lookup(): no need to vhold the dvp vnodeKonstantin Belousov2023-04-061-2/+0
| | | | (cherry picked from commit 8d97282a394278d29883e7afa98ed6294efab35e)
* fdescfs: Fix a file ref leakMark Johnston2023-04-051-17/+25
| | | | | | | | | | | | | | | | | | | | In fdesc_lookup(), vn_vget_ino_gen() may fail without invoking the callback, in which case the ref on fp is leaked. This happens if the fdescfs mount is being concurrently unmounted. Moreover, we cannot safely drop the ref while the dvp is locked. So: - Use a flag variable to indicate whether the ref is dropped. - Reorganize things to handle the leak. Reported by: C Turt <ecturt@gmail.com> Reviewed by: mjg, kib Tested by: pho MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D39189 (cherry picked from commit 0f5b6f9a041e9cca3b376f6ec909374938887a3b)
* fdesc_allocvp(): fix potential use after freeKonstantin Belousov2023-03-311-4/+5
| | | | (cherry picked from commit 51b8ffb95c4fe45f6825d551bd093889820a8115)
* fdescfs: remove useless XXX comment, unwrap lineKonstantin Belousov2023-03-311-2/+1
| | | | (cherry picked from commit fa3ea81b77e41e3f33a611e51fd8bcbb2f4c8a95)
* fdescfs: allow chown/utime etc on fdescfs fd for underlying files opened ↵Konstantin Belousov2022-06-131-2/+8
| | | | | | with O_PATH (cherry picked from commit 156745b42d9e6dfa3d9c6dc480db7836683850cf)
* fdescfs: add an option to return underlying file vnode on lookupKonstantin Belousov2021-06-113-1/+14
| | | | (cherry picked from commit f9b1e711f0d8c27f2d29e7a8e6276947d37a6a22)
* fdescfs: allow shared locking of root vnodeMateusz Guzik2021-05-221-1/+12
| | | | | | Eliminates fdescfs from lock profile when running poudriere. (cherry picked from commit 4fe925b81e75b5885ec6d504c6217f848439164a)
* Convert remaining cap_rights_init users to cap_rights_init_oneMateusz Guzik2021-01-121-1/+1
| | | | | | | | | | | | | semantic patch: @@ expression rights, r; @@ - cap_rights_init(&rights, r) + cap_rights_init_one(&rights, r)
* fs: clean up empty lines in .c and .h filesMateusz Guzik2020-09-011-1/+0
| | | | Notes: svn path=/head/; revision=365070
* cache: drop the always curthread argument from reverse lookup routinesMateusz Guzik2020-08-241-1/+1
| | | | | | | | | Note VOP_VPTOCNP keeps getting it as temporary compatibility for zfs. Tested by: pho Notes: svn path=/head/; revision=364633
* vfs: remove the thread argument from vgetMateusz Guzik2020-08-162-3/+3
| | | | | | | | | | | | | | | | | | It was already asserted to be curthread. Semantic patch: @@ expression arg1, arg2, arg3; @@ - vget(arg1, arg2, arg3) + vget(arg1, arg2) Notes: svn path=/head/; revision=364271
* vfs: drop the mostly unused flags argument from VOP_UNLOCKMateusz Guzik2020-01-032-5/+5
| | | | | | | | | | | Filesystems which want to use it in limited capacity can employ the VOP_UNLOCK_FLAGS macro. Reviewed by: kib (previous version) Differential Revision: https://reviews.freebsd.org/D21427 Notes: svn path=/head/; revision=356337
* vfs: flatten vop vectorsMateusz Guzik2019-12-161-0/+1
| | | | | | | | | | | | | | | This eliminates the following loop from all VOP calls: while(vop != NULL && \ vop->vop_spare2 == NULL && vop->vop_bypass == NULL) vop = vop->vop_default; Reviewed by: jeff Tesetd by: pho Differential Revision: https://reviews.freebsd.org/D22738 Notes: svn path=/head/; revision=355790
* vfs: introduce v_irflag and make v_type smallerMateusz Guzik2019-12-081-1/+1
| | | | | | | | | | | | | | | | | | The current vnode layout is not smp-friendly by having frequently read data avoidably sharing cachelines with very frequently modified fields. In particular v_iflag inspected for VI_DOOMED can be found in the same line with v_usecount. Instead make it available in the same cacheline as the v_op, v_data and v_type which all get read all the time. v_type is avoidably 4 bytes while the necessary data will easily fit in 1. Shrinking it frees up 3 bytes, 2 of which get used here to introduce a new flag field with a new value: VIRF_DOOMED. Reviewed by: kib, jeff Differential Revision: https://reviews.freebsd.org/D22715 Notes: svn path=/head/; revision=355537
* Ensure that directory entry padding bytes are zeroed.Mark Johnston2018-11-231-1/+2
| | | | | | | | | | | | | | | | | Directory entries must be padded to maintain alignment; in many filesystems the padding was not initialized, resulting in stack memory being copied out to userspace. With the ino64 work there are also some explicit pad fields in struct dirent. Add a subroutine to clear these bytes and use it in the in-tree filesystems. The NFS client is omitted for now as it was fixed separately in r340787. Reported by: Thomas Barabosch, Fraunhofer FKIE Reviewed by: kib MFC after: 3 days Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=340856
* Add d_off support for multiple filesystems.Konstantin Belousov2018-11-141-0/+2
| | | | | | | | | | | | | | | | | | | | | | | The d_off field has been added to the dirent structure recently. Currently filesystems don't support this feature. Support has been added and tested for zfs, ufs, ext2fs, fdescfs, msdosfs and unionfs. A stub implementation is available for cd9660, nandfs, udf and pseudofs but hasn't been tested. Motivation for this feature: our usecase is for a userspace nfs server (nfs-ganesha) with zfs. At the moment we cache direntry offsets by calling lseek once per entry, with this patch we can get the offset directly from getdirentries(2) calls which provides a significant speedup. Submitted by: Jack Halford <jack@gandi.net> Reviewed by: mckusick, pfg, rmacklem (previous versions) Sponsored by: Gandi.net MFC after: 1 week Differential revision: https://reviews.freebsd.org/D17917 Notes: svn path=/head/; revision=340431
* Eliminate the overhead of gratuitous repeated reinitialization of cap_rightsMatt Macy2018-05-091-4/+2
| | | | | | | | | | | | | | | - Add macros to allow preinitialization of cap_rights_t. - Convert most commonly used code paths to use preinitialized cap_rights_t. A 3.6% speedup in fstat was measured with this change. Reported by: mjg Reviewed by: oshogbo Approved by: sbruno MFC after: 1 month Notes: svn path=/head/; revision=333425
* Make it easier for filesystems to count themselves as jail-enabled,Jamie Gritton2018-05-041-4/+0
| | | | | | | | | | | | | | | by doing most of the work in a new function prison_add_vfs in kern_jail.c Now a jail-enabled filesystem need only mark itself with VFCF_JAIL, and the rest is taken care of. This includes adding a jail parameter like allow.mount.foofs, and a sysctl like security.jail.mount_foofs_allowed. Both of these used to be a static list of known filesystems, with predefined permission bits. Reviewed by: kib Differential Revision: D14681 Notes: svn path=/head/; revision=333263
* Fix Bad file descriptor error.Hajimu UMEMOTO2018-03-091-0/+2
| | | | | | | MFC after: 1 week Notes: svn path=/head/; revision=330681
* Use long for the last argument to VOP_PATHCONF rather than a register_t.John Baldwin2018-01-171-1/+1
| | | | | | | | | | | | | | pathconf(2) and fpathconf(2) both return a long. The kern_[f]pathconf() functions now accept a pointer to a long value rather than modifying td_retval directly. Instead, the system calls explicitly store the returned long value in td_retval[0]. Requested by: bde Reviewed by: kib Sponsored by: Chelsio Communications Notes: svn path=/head/; revision=328099
* Add a custom VOP_PATHCONF method for fdescfs.John Baldwin2017-12-191-1/+31
| | | | | | | | | | | | | | | The method handles NAME_MAX and LINK_MAX explicitly. For all other pathconf variables, the method passes the request down to the underlying file descriptor. This requires splitting a kern_fpathconf() syscallsubr routine out of sys_fpathconf(). Also, to avoid lock order reversals with vnode locks, the fdescfs vnode is unlocked around the call to kern_fpathconf(), but with the usecount of the vnode bumped. MFC after: 1 month Sponsored by: Chelsio Communications Notes: svn path=/head/; revision=326986
* sys: further adoption of SPDX licensing ID tags.Pedro F. Giffuni2017-11-203-0/+6
| | | | | | | | | | | | | | | | | Mainly focus on files that use BSD 3-Clause license. The Software Package Data Exchange (SPDX) group provides a specification to make it easier for automated tools to detect and summarize well known opensource licenses. We are gradually adopting the specification, noting that the tags are considered only advisory and do not, in any way, superceed or replace the license texts. Special thanks to Wind River for providing access to "The Duke of Highlander" tool: an older (2014) run over FreeBSD tree was useful as a starting point. Notes: svn path=/head/; revision=326023
* Implement proper Linux /dev/fd and /proc/self/fd behavior by addingDmitry Chagin2017-08-013-3/+63
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Linux specific things to the native fdescfs file system. Unlike FreeBSD, the Linux fdescfs is a directory containing a symbolic links to the actual files, which the process has open. A readlink(2) call on this file returns a full path in case of regular file or a string in a special format (type:[inode], anon_inode:<file-type>, etc..). As well as in a FreeBSD, opening the file in the Linux fdescfs directory is equivalent to duplicating the corresponding file descriptor. Here we have mutually exclusive requirements: - in case of readlink(2) call fdescfs lookup() method should return VLNK vnode otherwise our kern_readlink() fail with EINVAL error; - in the other calls fdescfs lookup() method should return non VLNK vnode. For what new vnode v_flag VV_READLINK was added, which is set if fdescfs has beed mounted with linrdlnk option an modified kern_readlinkat() to properly handle it. For now For Linux ABI compatibility mount fdescfs volume with linrdlnk option: mount -t fdescfs -o linrdlnk null /compat/linux/dev/fd Reviewed by: kib@ MFC after: 1 week Relnotes: yes Notes: svn path=/head/; revision=321839
* Replace unnecessary _KERNEL by double-include protection.Dmitry Chagin2017-07-251-2/+4
| | | | | | | MFC after: 2 week Notes: svn path=/head/; revision=321460
* Style(9). Whitespace.Dmitry Chagin2017-07-091-1/+1
| | | | | | | MFC after: 3 weeks Notes: svn path=/head/; revision=320837
* Eliminate the bogus casts.Dmitry Chagin2017-07-091-2/+2
| | | | | | | MFC after: 3 weeks Notes: svn path=/head/; revision=320836
* Don't initialize error in declaration.Dmitry Chagin2017-07-081-1/+1
| | | | | | | MFC after: 3 weeks Notes: svn path=/head/; revision=320820
* Eliminate the bogus cast.Dmitry Chagin2017-07-081-1/+1
| | | | | | | MFC after: 3 weeks Notes: svn path=/head/; revision=320819
* Eliminate the bogus cast.Dmitry Chagin2017-07-081-1/+1
| | | | | | | MFC after: 3 weeks Notes: svn path=/head/; revision=320818
* Don't take a lock around atomic operation.Dmitry Chagin2017-07-081-8/+2
| | | | | | | MFC after: 3 weeks Notes: svn path=/head/; revision=320817
* Remove init from declaration, collapse two int vars declarations into single.Dmitry Chagin2017-07-081-2/+2
| | | | | | | MFC after: 3 weeks Notes: svn path=/head/; revision=320816
* Remove init from declaration.Dmitry Chagin2017-07-081-1/+1
| | | | | | | MFC after: 3 weeks Notes: svn path=/head/; revision=320815
* Style(9). Add blank line aftr {.Dmitry Chagin2017-07-081-0/+1
| | | | | | | MFC after: 3 weeks Notes: svn path=/head/; revision=320814
* Commit the 64-bit inode project.Konstantin Belousov2017-05-231-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Extend the ino_t, dev_t, nlink_t types to 64-bit ints. Modify struct dirent layout to add d_off, increase the size of d_fileno to 64-bits, increase the size of d_namlen to 16-bits, and change the required alignment. Increase struct statfs f_mntfromname[] and f_mntonname[] array length MNAMELEN to 1024. ABI breakage is mitigated by providing compatibility using versioned symbols, ingenious use of the existing padding in structures, and by employing other tricks. Unfortunately, not everything can be fixed, especially outside the base system. For instance, third-party APIs which pass struct stat around are broken in backward and forward incompatible ways. Kinfo sysctl MIBs ABI is changed in backward-compatible way, but there is no general mechanism to handle other sysctl MIBS which return structures where the layout has changed. It was considered that the breakage is either in the management interfaces, where we usually allow ABI slip, or is not important. Struct xvnode changed layout, no compat shims are provided. For struct xtty, dev_t tty device member was reduced to uint32_t. It was decided that keeping ABI compat in this case is more useful than reporting 64-bit dev_t, for the sake of pstat. Update note: strictly follow the instructions in UPDATING. Build and install the new kernel with COMPAT_FREEBSD11 option enabled, then reboot, and only then install new world. Credits: The 64-bit inode project, also known as ino64, started life many years ago as a project by Gleb Kurtsou (gleb). Kirk McKusick (mckusick) then picked up and updated the patch, and acted as a flag-waver. Feedback, suggestions, and discussions were carried by Ed Maste (emaste), John Baldwin (jhb), Jilles Tjoelker (jilles), and Rick Macklem (rmacklem). Kris Moore (kris) performed an initial ports investigation followed by an exp-run by Antoine Brodin (antoine). Essential and all-embracing testing was done by Peter Holm (pho). The heavy lifting of coordinating all these efforts and bringing the project to completion were done by Konstantin Belousov (kib). Sponsored by: The FreeBSD Foundation (emaste, kib) Differential revision: https://reviews.freebsd.org/D10439 Notes: svn path=/head/; revision=318736
* Hide the boottime and bootimebin globals, provide the getboottime(9)Konstantin Belousov2016-07-271-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | and getboottimebin(9) KPI. Change consumers of boottime to use the KPI. The variables were renamed to avoid shadowing issues with local variables of the same name. Issue is that boottime* should be adjusted from tc_windup(), which requires them to be members of the timehands structure. As a preparation, this commit only introduces the interface. Some uses of boottime were found doubtful, e.g. NLM uses boottime to identify the system boot instance. Arguably the identity should not change on the leap second adjustment, but the commit is about the timekeeping code and the consumers were kept bug-to-bug compatible. Tested by: pho (as part of the bigger patch) Reviewed by: jhb (same) Discussed with: bde Sponsored by: The FreeBSD Foundation MFC after: 1 month X-Differential revision: https://reviews.freebsd.org/D7302 Notes: svn path=/head/; revision=303382
* Rationalize license numbering in fdescfs(5)Ed Maste2016-04-303-3/+3
| | | | Notes: svn path=/head/; revision=298853
* ANSIfy fdescfs(5)Ed Maste2016-04-302-58/+13
| | | | Notes: svn path=/head/; revision=298846
* Revert r295359:Pedro F. Giffuni2016-02-071-1/+1
| | | | | | | | | | | | | CID 1018688 is a false positive. The initialization is done by calling vn_start_write(... &mp, flags). mp is only an output parameter unless (flags & V_MNTREF), and fdesc doesn't put V_MNTREF in flags. Pointed out by: bde Notes: svn path=/head/; revision=295371
* fdesc_setattr: unitialized pointer readPedro F. Giffuni2016-02-071-1/+1
| | | | | | | CID: 1018688 Notes: svn path=/head/; revision=295359
* fd: make 'rights' a manadatory argument to fget* functionsMateusz Guzik2015-07-051-1/+2
| | | | Notes: svn path=/head/; revision=285172
* Replace struct filedesc argument in getvnode with struct threadMateusz Guzik2015-06-161-1/+1
| | | | | | | This is is a step towards removal of spurious arguments. Notes: svn path=/head/; revision=284446