summaryrefslogtreecommitdiffstats
path: root/sys/fs/tmpfs/tmpfs_subr.c
Commit message (Collapse)AuthorAgeFilesLines
* MFC r312432:kib2017-02-021-1/+2
| | | | Add a mount option for tmpfs(5) to not use namecache.
* MFC r312429:kib2017-02-021-5/+0
| | | | VNON nodes cannot exist.
* MFC r312428:kib2017-02-021-18/+71
| | | | Refcount tmpfs nodes and mount structures.
* MFC r312425:kib2017-01-261-7/+2
| | | | Make tmpfs directory cursor available outside tmpfs_subr.c.
* MFC r312410:kib2017-01-261-1/+1
| | | | | | | Rework some tmpfs lock assertions. MFC r312412: Protect macro argument.
* MFC r312409:kib2017-01-261-24/+11
| | | | | | | Style fixes and comment updates. MFC r312435: Remove mistakenly merged field.
* MFC r312124 (by mjg):kib2017-01-261-7/+3
| | | | tmpfs: manage tm_pages_used with atomics.
* MFC r311531 (by mjg):kib2017-01-261-16/+6
| | | | Perform a lockless check in tmpfs_itimes.
* MFC r311525:kib2017-01-131-16/+39
| | | | Lock tmpfs node tn_status updates done under the shared vnode lock.
* MFC r311524:kib2017-01-131-15/+15
| | | | Use vnode lock assertion expression, assert exclusive ownership.
* MFC r303916:kib2016-08-171-4/+7
| | | | Convert another tmpfs assert into runtime check.
* MFC r284594:kib2015-06-261-0/+1
| | | | Restore the td_cookie value upon detach.
* MFC r277828:kib2015-02-111-0/+25
| | | | | | | | | | | | | Update mtime for tmpfs files modified through memory mapping. MFC r277969: Update both ctime and mtime for writes to tmpfs files. MFC r277972: Remove single-use boolean. MFC r278151: Remove duplicated assignment.
* MFC r278000:kib2015-02-071-0/+2
| | | | | Update directory times immediately after an entry is created or removed.
* MFC r268617:kib2014-07-281-2/+23
| | | | Rework the tmpfs unmount.
* MFC r268615:kib2014-07-281-1/+1
| | | | | | | | | | | Add OBJ_TMPFS_NODE flag. MFC r268616: Set the OBJ_TMPFS_NODE flag for vm_object of VREG tmpfs node. MFC r269053: Correct assertion. tmpfs vm object is always at the bottom of the shadow chain.
* MFC r268613:kib2014-07-281-0/+1
| | | | Style. Add comment about lock mode.
* MFC r268611:kib2014-07-281-9/+5
| | | | Replace goto's with the return.
* MFC r268610:kib2014-07-281-1/+1
| | | | Add convenience macro to assert tmpfs node lock.
* MFC r268609:kib2014-07-281-0/+1
| | | | Add some assertions for the code handling vm_object for tmpfs vnode.
* MFC r268605:kib2014-07-281-41/+0
| | | | Remove code separator lines which do not conform to style(9).
* MFC r267564:kib2014-06-241-16/+12
| | | | | In msdosfs_setattr(), add a check for result of the utimes(2) permissions test. Refactor the permission checks for utimes(2).
* MFC r267060:kib2014-06-111-0/+2
| | | | Allow shared locking for the tmpfs vnode.
* MFC r263131,r263174,r263175:bdrewery2014-03-301-21/+26
| | | | | | | | | | | | | | | | Tmpfs readdir() redundant logic and code readability cleanup. r263131: Cleanup redundant logic and add some comments to help explain how it works in lieu of potentially less clear code. r263174: Rename cnt to maxcookies and change its use as the condition for when to lookup cookies to be less obscure. r263175: Add missing FALLTHROUGH comment in tmpfs_dir_getdents for looking up '.' and '..'.
* Support storing 7 additional file flags in tmpfs:ken2013-08-281-3/+4
| | | | | | | | | | | UF_SYSTEM, UF_SPARSE, UF_OFFLINE, UF_REPARSE, UF_ARCHIVE, UF_READONLY, and UF_HIDDEN. Sort the file flags tmpfs supports alphabetically. tmpfs now supports the same flags as UFS, with the exception of SF_SNAPSHOT. Reported by: bdrewery, antoine Sponsored by: Spectra Logic
* The soft and hard busy mechanism rely on the vm object lock to work.attilio2013-08-091-5/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Unify the 2 concept into a real, minimal, sxlock where the shared acquisition represent the soft busy and the exclusive acquisition represent the hard busy. The old VPO_WANTED mechanism becames the hard-path for this new lock and it becomes per-page rather than per-object. The vm_object lock becames an interlock for this functionality: it can be held in both read or write mode. However, if the vm_object lock is held in read mode while acquiring or releasing the busy state, the thread owner cannot make any assumption on the busy state unless it is also busying it. Also: - Add a new flag to directly shared busy pages while vm_page_alloc and vm_page_grab are being executed. This will be very helpful once these functions happen under a read object lock. - Move the swapping sleep into its own per-object flag The KPI is heavilly changed this is why the version is bumped. It is very likely that some VM ports users will need to change their own code. Sponsored by: EMC / Isilon storage division Discussed with: alc Reviewed by: jeff, kib Tested by: gavin, bapt (older version) Tested by: pho, scottl
* The tmpfs_alloc_vp() is used to instantiate vnode for the tmpfs node,kib2013-08-051-0/+24
| | | | | | | | | | | | | | | | | | | | | | in particular, from the tmpfs_lookup VOP method. If LK_NOWAIT is not specified in the lkflags, the lookup is supposed to return an alive vnode whenever the underlying node is valid. Currently, the tmpfs_alloc_vp() returns ENOENT if the vnode attached to node exists and is being reclaimed. This causes spurious ENOENT errors from lookup on tmpfs and corresponding random 'No such file' failures from syscalls working with tmpfs files. Fix this by waiting for the doomed vnode to be detached from the tmpfs node if sleepable allocation is requested. Note that filesystems which use vfs_hash.c, correctly handle the case due to vfs_hash_get() looping when vget() returns ENOENT for sleepable requests. Reported and tested by: pho Sponsored by: The FreeBSD Foundation MFC after: 2 weeks
* Assert that OBJ_TMPFS flag on the vm object for the tmpfs node iskib2013-05-301-0/+2
| | | | | | cleared when the tmpfs node is going away. Tested by: bdrewery, pho
* For the new regular tmpfs vnode, v_object is initialized beforekib2013-05-021-1/+31
| | | | | | | | | | | | | | insmntque() is called. The standard insmntque destructor resets the vop vector to deadfs one, and calls vgone() on the vnode. As result, v_object is kept unchanged, which triggers an assertion in the reclaim code, on instmntque() failure. Also, in this case, OBJ_TMPFS flag on the backed vm object is not cleared. Provide the tmpfs insmntque() destructor which properly clears OBJ_TMPFS flag and resets v_object. Reported and tested by: pho Sponsored by: The FreeBSD Foundation
* Rework the handling of the tmpfs node backing swap object and tmpfskib2013-04-281-6/+21
| | | | | | | | | | | | | | | | | | vnode v_object to avoid double-buffering. Use the same object both as the backing store for tmpfs node and as the v_object. Besides reducing memory use up to 2x times for situation of mapping files from tmpfs, it also makes tmpfs read and write operations copy twice bytes less. VM subsystem was already slightly adapted to tolerate OBJT_SWAP object as v_object. Now the vm_object_deallocate() is modified to not reinstantiate OBJ_ONEMAPPING flag and help the VFS to correctly handle VV_TEXT flag on the last dereference of the tmpfs backing object. Reviewed by: alc Tested by: pho, bf MFC after: 1 month
* - Make 'flags' argument to chflags(2), fchflags(2) and lchflags(2) of typepjd2013-03-211-1/+2
| | | | | | | | | | | u_long. Before this change it was of type int for syscalls, but prototypes in sys/stat.h and documentation for chflags(2) and fchflags(2) (but not for lchflags(2)) stated that it was u_long. Now some related functions use u_long type for flags (strtofflags(3), fflagstostr(3)). - Make path argument of type 'const char *' for consistency. Discussed on: arch Sponsored by: The FreeBSD Foundation
* Rename VM_OBJECT_LOCK(), VM_OBJECT_UNLOCK() and VM_OBJECT_TRYLOCK() toattilio2013-02-201-5/+5
| | | | | | their "write" versions. Sponsored by: EMC / Isilon storage division
* Switch vm_object lock to be a rwlock.attilio2013-02-201-0/+2
| | | | | | | | * VM_OBJECT_LOCK and VM_OBJECT_UNLOCK are mapped to write operations * VM_OBJECT_SLEEP() is introduced as a general purpose primitve to get a sleep operation using a VM_OBJECT_LOCK() as protection * The approach must bear with vm_pager.h namespace pollution so many files require including directly rwlock.h
* tmpfs: Replace directory entry linked list with RB-Tree.gleb2013-01-061-131/+426
| | | | | | | | | | | | | | | | | | | | | Use file name hash as a tree key, handle duplicate keys. Both VOP_LOOKUP and VOP_READDIR operations utilize same tree for search. Directory entry offset (cookie) is either file name hash or incremental id in case of hash collisions (duplicate-cookies). Keep sorted per directory list of duplicate-cookie entries to facilitate cookie number allocation. Don't fail if previous VOP_READDIR() offset is no longer valid, start with next dirent instead. Other file system handle it similarly. Workaround race prone tn_readdir_last[pn] fields update. Add tmpfs_dir_destroy() to free all dirents. Set NFS cookies in tmpfs_dir_getdents(). Return EJUSTRETURN from tmpfs_dir_getdents() instead of hard coded -1. Mark directory traversal routines static as they are no longer used outside of tmpfs_subr.c
* After the PHYS_TO_VM_PAGE() function was de-inlined, the main reasonkib2012-08-051-0/+1
| | | | | | | | | | | | | to pull vm_param.h was removed. Other big dependency of vm_page.h on vm_param.h are PA_LOCK* definitions, which are only needed for in-kernel code, because modules use KBI-safe functions to lock the pages. Stop including vm_param.h into vm_page.h. Include vm_param.h explicitely for the kernel code which needs it. Suggested and reviewed by: alc MFC after: 2 weeks
* Return EOPNOTSUPP rather than EPERM for the SF_SNAPSHOT flag becausejh2012-04-181-4/+1
| | | | | | tmpfs doesn't support snapshots. Suggested by: bde
* Sync tmpfs_chflags() with the recent changes to UFS:jh2012-04-161-13/+13
| | | | | | - Add a check for unsupported file flags. - Return EPERM when an user without PRIV_VFS_SYSFLAGS privilege attempts to toggle SF_SETTABLE flags.
* Provide better description for vfs.tmpfs.memory_reserved sysctl.gleb2012-04-151-1/+2
| | | | Suggested by: Anton Yuzhaninov <citrin@citrin.ru>
* Add reserved memory limit sysctl to tmpfs.gleb2012-04-071-1/+66
| | | | | | | Cleanup availble and used memory functions. Check if free pages available before allocating new node. Discussed with: delphij
* Prevent tmpfs_rename() deadlock in a way similar to UFSgleb2012-03-141-0/+3
| | | | | | Unlock vnodes and try to lock them one by one. Relookup fvp and tvp. Approved by: mdf (mentor)
* Don't enforce LK_RETRY to get existing vnode in tmpfs_alloc_vp()gleb2012-03-141-7/+11
| | | | | | | | | Doomed vnode is hardly of any use here, besides all callers handle error case. vfs_hash_get() does the same. Don't mess with vnode holdcount, vget() takes care of it already. Approved by: mdf (mentor)
* When tmpfs_write() resets an extended file to its original size after analc2012-01-161-4/+8
| | | | | | | | error, we want tmpfs_reg_resize() to ignore I/O errors and unconditionally update the file's size. Reviewed by: kib MFC after: 3 weeks
* Neither tmpfs_nocacheread() nor tmpfs_mappedwrite() needs to callalc2012-01-141-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | vm_object_pip_{add,subtract}() on the swap object because the swap object can't be destroyed while the vnode is exclusively locked. Moreover, even if the swap object could have been destroyed during tmpfs_nocacheread() and tmpfs_mappedwrite() this code is broken because vm_object_pip_subtract() does not wake up the sleeping thread that is trying to destroy the swap object. Free invalid pages after an I/O error. There is no virtue in keeping them around in the swap object creating more work for the page daemon. (I believe that any non-busy page in the swap object will now always be valid.) vm_pager_get_pages() does not return a standard errno, so its return value should not be returned by tmpfs without translation to an errno value. There is no reason for the wakeup on vpg in tmpfs_mappedwrite() to occur with the swap object locked. Eliminate printf()s from tmpfs_nocacheread() and tmpfs_mappedwrite(). (The swap pager already spam your console if data corruption is imminent.) Reviewed by: kib MFC after: 3 weeks
* Correct an error of omission in the implementation of the truncationalc2012-01-081-19/+59
| | | | | | | | | | | | | | | | | | | | | | | operation on POSIX shared memory objects and tmpfs. Previously, neither of these modules correctly handled the case in which the new size of the object or file was not a multiple of the page size. Specifically, they did not handle partial page truncation of data stored on swap. As a result, stale data might later be returned to an application. Interestingly, a data inconsistency was less likely to occur under tmpfs than POSIX shared memory objects. The reason being that a different mistake by the tmpfs truncation operation helped avoid a data inconsistency. If the data was still resident in memory in a PG_CACHED page, then the tmpfs truncation operation would reactivate that page, zero the truncated portion, and leave the page pinned in memory. More precisely, the benevolent error was that the truncation operation didn't add the reactivated page to any of the paging queues, effectively pinning the page. This page would remain pinned until the file was destroyed or the page was read or written. With this change, the page is now added to the inactive queue. Discussed with: jhb Reviewed by: kib (an earlier version) MFC after: 3 weeks
* Add a new option, OBJPR_NOTMAPPED, to vm_object_page_remove(). Passing thisalc2011-06-291-1/+1
| | | | | | | | | | | | | | | | | | option to vm_object_page_remove() asserts that the specified range of pages is not mapped, or more precisely that none of these pages have any managed mappings. Thus, vm_object_page_remove() need not call pmap_remove_all() on the pages. This change not only saves time by eliminating pointless calls to pmap_remove_all(), but it also eliminates an inconsistency in the use of pmap_remove_all() versus related functions, like pmap_remove_write(). It eliminates harmless but pointless calls to pmap_remove_all() that were being performed on PG_UNMANAGED pages. Update all of the existing assertions on pmap_remove_all() to reflect this change. Reviewed by: kib
* Further simplify tmpfs_reg_resize(). Also, update its comments, includingalc2011-02-141-17/+12
| | | | style fixes.
* Eliminate tn_reg.tn_aobj_pages. Instead, correctly maintain the vmalc2011-02-131-32/+26
| | | | | | | | | object's size field. Previously, that field was always zero, even when the object tn_reg.tn_aobj contained numerous pages. Apply style fixes to tmpfs_reg_resize(). In collaboration with: kib
* In tmpfs_readdir(), normalize handling of the directory entries thatkib2011-01-201-3/+4
| | | | | | | | | | either overflow the supplied buffer, or cause uiomove fail. Do not advance cached de when directory entry was not copied out. Do not return EOF when no entries could be copied due to first entry too large for supplied buffer, signal EINVAL instead. Reported by: Beat G?tzi <beat chruetertee ch> MFC after: 1 week
* Add support for whiteouts on tmpfs.ed2010-08-221-37/+71
| | | | | | | | | | | | | | Right now unionfs only allows filesystems to be mounted on top of another if it supports whiteouts. Even though I have sent a patch to daichi@ to let unionfs work without it, we'd better also add support for whiteouts to tmpfs. This patch implements .vop_whiteout and makes necessary changes to lookup() and readdir() to take them into account. We must also make sure that when adding or removing a file, we honour the componentname's DOWHITEOUT and ISWHITEOUT, to prevent duplicate filenames. MFC after: 1 month
* - Change the type of nodes_max to u_int and use "%u" format string tojh2010-01-201-1/+1
| | | | | | | | | | | | | convert its value. [1] - Set default tm_nodes_max to min(pages + 3, UINT32_MAX). It's more reasonable than the old four nodes per page (with page size 4096) because non-empty regular files always use at least one page. This fixes possible overflow in the calculation. [2] - Don't allow more than tm_nodes_max nodes allocated in tmpfs_alloc_node(). PR: kern/138367 Suggested by: bde [1], Gleb Kurtsou [2] Approved by: trasz (mentor)
OpenPOWER on IntegriCloud