summaryrefslogtreecommitdiffstats
path: root/sys/fs/devfs
Commit message (Collapse)AuthorAgeFilesLines
...
* Handle the special ruleset 0 in devfs_ruleset_use(). An attempt set thejh2010-12-121-0/+5
| | | | | | | | current ruleset to 0 with command "devfs ruleset 0" triggered a KASSERT in devfs_ruleset_create(). PR: kern/125030 Submitted by: Mateusz Guzik
* Format prototypes to follow style(9) more closely.jh2010-10-122-22/+25
| | | | Discussed with: kib, phk
* Add a new function devfs_dev_exists() to be able to find out if ajh2010-09-272-0/+22
| | | | | | | | | specific devfs path already exists. The function will be used from kern_conf.c to detect duplicate device registrations. Callers must hold the devmtx mutex. Reviewed by: kib
* Add reference counting for devfs paths containing user created symbolicjh2010-09-275-2/+199
| | | | | | | | | | | | | | | | links. The reference counting is needed to be able to determine if a specific devfs path exists. For true device file paths we can traverse the cdevp_list but a separate directory list is needed for user created symbolic links. Add a new directory entry flag DE_USER to mark entries which should unreference their parent directory on deletion. A new function to traverse cdevp_list and the directory list will be introduced in a separate commit. Idea from: kib Reviewed by: kib
* Modify devfs_fqpn() for future use in devfs path reference countingjh2010-09-212-14/+23
| | | | | | | | | | | | | code: - Accept devfs_mount and devfs_dirent as the arguments instead of a vnode. This generalizes the function so that it can be used from contexts where vnode references are not available. - Accept NULL cnp argument. No '/' will be appended, if a NULL cnp is provided. - Make the function global and add its prototype to devfs.h. Reviewed by: kib
* - For consistency, remove "." and ".." entries from de_dlist beforejh2010-09-181-0/+4
| | | | | | | | | calling devfs_delete() (and thus possibly dropping dm_lock) in devfs_rmdir_empty(). - Assert that we don't return doomed entries from devfs_find(). [1] Suggested by: kib [1] Reviewed by: kib
* Remove empty devfs directories automatically.jh2010-09-153-17/+106
| | | | | | | | | | | | | | | | | | | | devfs_delete() now recursively removes empty parent directories unless the DEVFS_DEL_NORECURSE flag is specified. devfs_delete() can't be called anymore with a parent directory vnode lock held because the possible parent directory deletion needs to lock the vnode. Thus we unlock the parent directory vnode in devfs_remove() before calling devfs_delete(). Call devfs_populate_vp() from devfs_symlink() and devfs_vptocnp() as now directories can get removed. Add a check for DE_DOOMED flag to devfs_populate_vp() because devfs_delete() drops dm_lock before the VI_DOOMED vnode flag gets set. This ensures that devfs_populate_vp() returns an error for directories which are in progress of deletion. Reviewed by: kib Discussed on: freebsd-current (mostly silence)
* Set de_dir for user created symbolic links. This will be needed to bejh2010-08-261-0/+1
| | | | able to resolve their parent directories.
* Call devfs_populate_vp() from devfs_getattr(). It was possible thatjh2010-08-251-1/+9
| | | | fstat(2) returned stale information through an open file descriptor.
* Introduce and use devfs_populate_vp() to unlock a vnode before callingjh2010-08-221-26/+56
| | | | | | | devfs_populate(). This is a prerequisite for the automatic removal of empty directories which will be committed in the future. Reviewed by: kib (previous version)
* Add dedicated routines to toggle lockmgr flags such as LK_NOSHARE andjhb2010-08-201-1/+1
| | | | | | | | | | | | LK_CANRECURSE after a lock is created. Use them to implement macros that otherwise manipulated the flags directly. Assert that the associated lockmgr lock is exclusively locked by the current thread when manipulating these flags to ensure the flag updates are safe. This last change required some minor shuffling in a few filesystems to exclusively lock a brand new vnode slightly earlier. Reviewed by: kib MFC after: 3 days
* Call dev_rel() in error paths.jh2010-08-191-0/+3
| | | | | | Reported by: kib Reviewed by: kib MFC after: 2 weeks
* Allow user created symbolic links to cover device files and directoriesjh2010-08-123-15/+56
| | | | | | | | | | | | | | if the device file appears during or after the link creation. User created symbolic links are now inserted at the head of the directory entry list after the "." and ".." entries. A new directory entry flag DE_COVERED indicates that an entry is covered by a symbolic link. PR: kern/114057 Reviewed by: kib Idea from: kib Discussed on: freebsd-current (mostly silence)
* Enable shared lookups and externed shared ops for devfs.kib2010-08-061-1/+2
| | | | | In collaboration with: pho MFC after: 1 month
* Add new make_dev_p(9) flag MAKEDEV_ETERNAL to inform devfs that createdkib2010-08-062-30/+34
| | | | | | | | | cdev will never be destroyed. Propagate the flag to devfs vnodes as VV_ETERNVALDEV. Use the flags to avoid acquiring devmtx and taking a thread reference on such nodes. In collaboration with: pho MFC after: 1 month
* Enable shared locks for the devfs vnodes. Honor the locking modekib2010-08-063-17/+20
| | | | | | | requested by lookup(). This should be a nop at the moment. In collaboration with: pho MFC after: 1 month
* Initialize VV_ISTTY vnode flag on the devfs vnode creation instead ofkib2010-08-061-4/+5
| | | | | | | doing it on each open. In collaboration with: pho MFC after: 1 month
* Add a new function devfs_parent_dirent() for resolving devfs parentjh2010-06-093-9/+32
| | | | | | | directory entry. Use the new function in devfs_fqpn(), devfs_lookupx() and devfs_vptocnp() instead of manually resolving the parent entry. Reviewed by: kib
* Don't try to call cdevsw d_close() method when devfs_close() is calledjh2010-06-011-0/+7
| | | | | | | because of insmntque1() failure. Found with: stress2 Suggested and reviewed by: kib
* Add MAKEDEV_NOWAIT flag to make_dev_credf(9), to create a device nodekib2010-05-062-3/+8
| | | | | | | | in a no-sleep context. If resource allocation cannot be done without sleep, make_dev_credf() fails and returns NULL. Reviewed by: jh MFC after: 2 weeks
* Revert r206560. The change doesn't work correctly in all cases withjh2010-04-162-24/+0
| | | | multiple devfs mounts.
* - Ignore and report duplicate and empty device names in devfs_populate_loop()jh2010-04-132-0/+24
| | | | | | | | | | instead of causing erratic behavior. Currently make_dev(9) can't fail, so there is no way to report an error to make_dev(9) callers. - Disallow using "." and ".." in device path names. It didn't work previously but now it is reported rather than panicing. - Treat multiple sequential slashes as single in device path names. Discussed with: pjd
* Properly use dev_refl()/dev_rel() in kern.devname.ed2010-01-311-10/+13
| | | | | | | | While there, perform some clean-up fixes. Update some stale comments on struct cdev * instead of dev_t and devfs_random(). Also add some missing whitespace. MFC after: 1 week
* Let access overriding to TTYs depend on the cdev_priv, not the vnode.ed2009-12-191-7/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Basically this commit changes two things, which improves access to TTYs in exceptional conditions. Basically the problem was that when you ran jexec(8) to attach to a jail, you couldn't use /dev/tty (well, also the node of the actual TTY, e.g. /dev/pts/X). This is very inconvenient if you want to attach to screens quickly, use ssh(1), etc. The fixes: - Cache the cdev_priv of the controlling TTY in struct session. Change devfs_access() to compare against the cdev_priv instead of the vnode. This allows you to bypass UNIX permissions, even across different mounts of devfs. - Extend devfs_prison_check() to unconditionally expose the device node of the controlling TTY, even if normal prison nesting rules normally don't allow this. This actually allows you to interact with this device node. To be honest, I'm not really happy with this solution. We now have to store three pointers to a controlling TTY (s_ttyp, s_ttyvp, s_ttydp). In an ideal world, we should just get rid of the latter two and only use s_ttyp, but this makes certian pieces of code very impractical (e.g. devfs, kern_exit.c). Reported by: Many people
* Improve nested jail awareness of devfs by handling credentials.ed2009-06-201-0/+22
| | | | | | | | | | | | | | | | | | Now that we start to use credentials on character devices more often (because of MPSAFE TTY), move the prison-checks that are in place in the TTY code into devfs. Instead of strictly comparing the prisons, use the more common prison_check() function to compare credentials. This means that pseudo-terminals are only visible in devfs by processes within the same jail and parent jails. Even though regular users in parent jails can now interact with pseudo-terminals from child jails, this seems to be the right approach. These processes are also capable of interacting with the jailed processes anyway, through signals for example. Reviewed by: kib, rwatson (older version)
* VOP_IOCTL takes unlocked vnode as an argument. Due to this, v_data maykib2009-06-101-2/+10
| | | | | | | | | | | | be NULL or derefenced memory may become free at arbitrary moment. Lock the vnode in cd9660, devfs and pseudofs implementation of VOP_IOCTL to prevent reclaim; check whether the vnode was already reclaimed after the lock is granted. Reported by: georg at dts su Reviewed by: des (pseudofs) MFC after: 2 weeks
* Move "options MAC" from opt_mac.h to opt_global.h, as it's now in GENERICrwatson2009-06-053-6/+0
| | | | | | | | and used in a large number of files, but also because an increasing number of incorrect uses of MAC calls were sneaking in due to copy-and-paste of MAC-aware code without the associated opt_mac.h include. Discussed with: pjd
* Re-add opt_mac.h include, which is required in order for MNT_MULTILABELrwatson2009-06-041-0/+2
| | | | | | | | to be set properly on devfs. Otherwise, it isn't possible to set labels on /dev nodes. Reported by: Sergio Rodriguez <sergiorr at yahoo.com> MFC after: 3 days
* Devfs replaces file ops vector with devfs-specific one in devfs_open(),kib2009-05-151-1/+3
| | | | | | | | | | | | | before the struct file is fully initialized in vn_open(), in particular, fp->f_vnode is NULL. Other thread calling file operation before f_vnode is set results in NULL pointer dereference in devvn_refthread(). Initialize f_vnode before calling d_fdopen() cdevsw method, that might set file ops too. Reported and tested by: Chris Timmons <cwt networks cwu edu> (RELENG_7 version) MFC after: 3 days
* Remove the thread argument from the FSD (File-System Dependent) parts ofattilio2009-05-113-22/+16
| | | | | | | | | | | | | | | | | the VFS. Now all the VFS_* functions and relating parts don't want the context as long as it always refers to curthread. In some points, in particular when dealing with VOPs and functions living in the same namespace (eg. vflush) which still need to be converted, pass curthread explicitly in order to retain the old behaviour. Such loose ends will be fixed ASAP. While here fix a bug: now, UFS_EXTATTR can be compiled alone without the UFS_EXTATTR_AUTOSTART option. VFS KPI is heavilly changed by this commit so thirdy parts modules needs to be recompiled. Bump __FreeBSD_version in order to signal such situation.
* Remove VOP_LEASE and supporting functions. This hasn't been used sincerwatson2009-04-101-1/+0
| | | | | | | | | | | | | | the removal of NQNFS, but was left in in case it was required for NFSv4. Since our new NFSv4 client and server can't use it for their requirements, GC the old mechanism, as well as other unused lease- related code and interfaces. Due to its impact on kernel programming and binary interfaces, this change should not be MFC'd. Proposed by: jeff Reviewed by: jeff Discussed with: rmacklem, zach loafman @ isilon
* Enable advisory file locking for devfs vnodes.kib2009-03-111-9/+0
| | | | | Reported by: Timothy Redaelli <timothy redaelli eu> MFC after: 1 week
* Extract the no_poll() and vop_nopoll() code into the common routinekib2009-03-061-1/+1
| | | | | | | | | poll_no_poll(). Return a poll_no_poll() result from devfs_poll_f() when filedescriptor does not reference the live cdev, instead of ENXIO. Noted and tested by: hps MFC after: 1 week
* Remove unused local variables.bz2009-01-311-2/+1
| | | | | | Submitted by: Christoph Mallon christoph.mallon@gmx.de Reviewed by: kib MFC after: 2 weeks
* Mark most often used sysctl's as MPSAFE.ed2009-01-281-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | After running a `make buildkernel', I noticed most of the Giant locks in sysctl are only caused by a very small amount of sysctl's: - sysctl.name2oid. This one is locked by SYSCTL_LOCK, just like sysctl.oidfmt. - kern.ident, kern.osrelease, kern.version, etc. These are just constant strings. - kern.arandom, used by the stack protector. It is already protected by arc4_mtx. I also saw the following sysctl's show up. Not as often as the ones above, but still quite often: - security.jail.jailed. Also mark security.jail.list as MPSAFE. They don't need locking or already use allprison_lock. - kern.devname, used by devname(3), ttyname(3), etc. This seems to reduce Giant locking inside sysctl by ~75% in my primitive test setup.
* Don't panic with "vinvalbuf: dirty bufs" when the mounted device that wastrasz2009-01-081-2/+18
| | | | | | | | being written to goes away. Reviewed by: kib, scottl Approved by: rwatson (mentor) Sponsored by: FreeBSD Foundation
* Do not leak defs_de_interlock on error.kib2008-12-121-1/+3
| | | | Another pointy hat for my collection.
* Implement VOP_VPTOCNP for devfs. Directory and character device vnodes aremarcus2008-12-121-0/+65
| | | | | | | properly translated to their component names. Reviewed by: arch Approved by: kib
* Introduce accmode_t. This is required for NFSv4 ACLs - it will be neccessarytrasz2008-10-281-1/+1
| | | | | | | to add more V* constants, and the variables changed by this patch were often being assigned to mode_t variables, which is 16 bit. Approved by: rwatson (mentor)
* Save previous content of the td_fpop before storing the currentkib2008-09-261-12/+27
| | | | | | | | | | | | | | | filedescriptor into it. Make sure that td_fpop is NULL when calling d_mmap from dev_pager_getpages(). Change guards against td_fpop field being non-NULL with private state for another device, and against sudden clearing the td_fpop. This could occur when either a driver method calls another driver through the filedescriptor operation, or a page fault happen while driver is writing to a memory backed by another driver. Noted by: rwatson Tested by: rnoland MFC after: 3 days
* Already initialize the vfs timestamps inside the cdev upon allocation.ed2008-09-211-0/+4
| | | | | | | | | | | | | In the MPSAFE TTY branch I noticed the vfs timestamps inside devfs were allocated with 0, where the getattr() routine bumps the timestamps to boottime if the value is below 3600. The reason why it has been designed like this, is because timestamps during boot are likely to be invalid. This means that device nodes that are created on demand (posix_openpt()) have timestamps with a value of boottime, which is not what we want. Solve this by calling vfs_timestamp() inside devfs_alloc(). Discussed with: kib
* fdescfs, devfs, mqueuefs, nfs, portalfs, pseudofs, tmpfs and xfskib2008-09-201-2/+1
| | | | | | | | | | | initialize the vattr structure in VOP_GETATTR() with VATTR_NULL(), vattr_null() or by zeroing it. Remove these to allow preinitialization of fields work in vn_stat(). This is needed to get birthtime initialized correctly. Submitted by: Jaakko Heinonen <jh saunalahti fi> Discussed on: freebsd-fs MFC after: 1 month
* Decontextualize the couplet VOP_GETATTR / VOP_SETATTR as the passed threadattilio2008-08-281-4/+6
| | | | | | was always curthread and totally unuseful. Tested by: Giovanni Trematerra <giovanni dot trematerra at gmail dot com>
* Integrate the new MPSAFE TTY layer to the FreeBSD operating system.ed2008-08-201-3/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The last half year I've been working on a replacement TTY layer for the FreeBSD kernel. The new TTY layer was designed to improve the following: - Improved driver model: The old TTY layer has a driver model that is not abstract enough to make it friendly to use. A good example is the output path, where the device drivers directly access the output buffers. This means that an in-kernel PPP implementation must always convert network buffers into TTY buffers. If a PPP implementation would be built on top of the new TTY layer (still needs a hooks layer, though), it would allow the PPP implementation to directly hand the data to the TTY driver. - Improved hotplugging: With the old TTY layer, it isn't entirely safe to destroy TTY's from the system. This implementation has a two-step destructing design, where the driver first abandons the TTY. After all threads have left the TTY, the TTY layer calls a routine in the driver, which can be used to free resources (unit numbers, etc). The pts(4) driver also implements this feature, which means posix_openpt() will now return PTY's that are created on the fly. - Improved performance: One of the major improvements is the per-TTY mutex, which is expected to improve scalability when compared to the old Giant locking. Another change is the unbuffered copying to userspace, which is both used on TTY device nodes and PTY masters. Upgrading should be quite straightforward. Unlike previous versions, existing kernel configuration files do not need to be changed, except when they reference device drivers that are listed in UPDATING. Obtained from: //depot/projects/mpsafetty/... Approved by: philip (ex-mentor) Discussed: on the lists, at BSDCan, at the DevSummit Sponsored by: Snow B.V., the Netherlands dcons(4) fixed by: kan
* Remove unnecessary locking around pointer fetch.kib2008-08-121-2/+0
| | | | Requested by: jhb
* Get pointer to devfs_ruleset struct after garbage collection has beengonzo2008-06-221-3/+3
| | | | | | | | performed. Otherwise if ruleset is used by given mountpoint and is empty it's freed by devfs_ruleset_reap and pointer becomes bogus. Submitted by: Mateusz Guzik <mjguzik@gmail.com> PR: kern/124853
* Struct cdev is always the member of the struct cdev_priv. When devfskib2008-06-163-9/+10
| | | | | | | | | | | needed to promote cdev to cdev_priv, the si_priv pointer was followed. Use member2struct() to calculate address of the wrapping cdev_priv. Rename si_priv to __si_reserved. Tested by: pho Reviewed by: ed MFC after: 2 weeks
* When devfs_allocv() committed to create new vnode, since de_vnode is NULL,kib2008-06-051-1/+1
| | | | | | | | | | | the dm_lock is held while the newly allocated vnode is locked. Since no other threads may try to lock the new vnode yet, the LOR there cannot result in the deadlock. Shut down the witness warning to note this fact. Tested by: pho Prodded by: attilio
* Revert the changes I made to devfs_setattr() in r179457.ed2008-06-011-4/+3
| | | | | | | | | | | As discussed with Robert Watson and John Baldwin, it would be better if PTY's are created with proper permissions, turning grantpt() into a no-op. Bypassing security frameworks like MAC by passing NOCRED to VOP_SETATTR() will only make things more complex. Approved by: philip (mentor)
* Merge back devfs changes from the mpsafetty branch.ed2008-05-311-6/+6
| | | | | | | | | | | | | | | | | | | | | | | In the mpsafetty branch, PTY's are allocated through the posix_openpt() system call. The controller side of a PTY now uses its own file descriptor type (just like sockets, vnodes, pipes, etc). To remain compatible with existing FreeBSD and Linux C libraries, we can still create PTY's by opening /dev/ptmx or /dev/ptyXX. These nodes implement d_fdopen(). Devfs has been slightly changed here, to allow finit() to be called from d_fdopen(). The routine grantpt() has also been moved into the kernel. This routine is a little odd, because it needs to bypass standard UNIX permissions. It needs to change the owner/group/mode of the slave device node, which may often not be possible. The old implementation solved this by spawning a setuid utility. When VOP_SETATTR() is called with NOCRED, devfs_setattr() dereferences ap->a_cred, causing a kernel panic. Change the de_{uid,gid,mode} code to allow changes when a->a_cred is set to NOCRED. Approved by: philip (mentor)
OpenPOWER on IntegriCloud