Commit Graph

264 Commits

Author SHA1 Message Date
chs fd34ea77eb remove checks for failure after memory allocation calls that cannot fail:
kmem_alloc() with KM_SLEEP
  kmem_zalloc() with KM_SLEEP
  percpu_alloc()
  pserialize_create()
  psref_class_create()

all of these paths include an assertion that the allocation has not failed,
so callers should not assert that again.
2017-06-01 02:45:05 +00:00
riastradh 7f7aad09bd Make VOP_RECLAIM do the last unlock of the vnode.
VOP_RECLAIM naturally has exclusive access to the vnode, so having it
locked on entry is not strictly necessary -- but it means if there
are any final operations that must be done on the vnode, such as
ffs_update, requiring exclusive access to it, we can now kassert that
the vnode is locked in those operations.

We can't just have the caller release the last lock because some file
systems don't use genfs_lock, and require the vnode to remain valid
for VOP_UNLOCK to work, notably unionfs.
2017-05-26 14:20:59 +00:00
riastradh 6fa7b15833 Change VOP_REMOVE and VOP_RMDIR to preserve lock/ref on dvp.
No change to vp -- the plan is to replace the node by the
componentname in the vop parameters, and let all directory vops do
lookups internally.

Proposed on tech-kern with no objections:
https://mail-index.netbsd.org/tech-kern/2017/04/17/msg021825.html
2017-04-26 03:02:47 +00:00
riastradh 87fb32292e Make VOP_INACTIVE preserve vnode lock on return.
Discussed on tech-kern:
https://mail-index.netbsd.org/tech-kern/2017/04/01/msg021751.html

Ride 7.99.68, a bumpy bus of incremental vfs improvements!
2017-04-11 14:24:59 +00:00
hannken 3c404d2c80 Protect tmpfs_getpages() against reclaiming vnodes. 2017-03-30 09:09:26 +00:00
hannken 90ead62d2f Change the protocol to update a mounted file system from read-write
to read-only and vice versa:

- Add an internal flag IMNT_WANTRDONLY.
- Set either IMNT_WANTRDWR or IMNT_WANTRDONLY if going from or to read-only.
- After successfull call to VFS_MOUNT() set or clear MNT_RDONLY.

Adapt tmpfs and rumpfs to the new protocol.  Other file systems will be
updated when they get the IMNT_CAN_RWTORO property.

Welcome to 7.99.64
2017-03-01 10:44:47 +00:00
hannken 326db3aaf6 Add generic genfs_suspendctl() and use it for all file systems.
Layered file systems need work.
2017-02-17 08:31:23 +00:00
hannken ac23b49f6d Run vflush() when going from read/write to read only. 2017-01-27 10:47:54 +00:00
joerg a88ba739cb Remove RO check in tmpfs_putpages for now, the syncer doesn't like the
error code.
2017-01-11 12:12:32 +00:00
hannken bd6e0af46f Change tmpfs_chsize() to update mtime etc. even if "length == node->tn_size".
Adresses PR kern/51762 "mtime not updated by open(O_TRUNC)"
2017-01-04 10:06:43 +00:00
dholland b5981bcf46 In the event that loading the root vnode fails, bail out of
tmpfs_mount instead of crashing.

Came up in PR 51436, where kmem issues caused internal allocations to
wrongly fail. However, that could happen for real sometime (e.g.
probably if you tried to mount a new tmpfs when the system was very
low on memory, or possibly for other reasons entirely) and crashing
isn't the ticket.

(This is not a fix for PR 51436)
2016-08-26 21:44:24 +00:00
skrll a321adb539 Two fixes from rmind
- tmpfs_node_get: restore (decrement) the node count on the error path.
- tmpfs_bytes_max: save the value of uvmexp.freetarg (since it is
  unlocked/racy).
2016-08-22 23:07:36 +00:00
hannken 7139aab724 Remove now obsolete operation vcache_remove().
Welcome to 7.99.36
2016-08-20 12:37:06 +00:00
martin 9dbda5ea54 Backout previous - need coffee first 2016-03-12 12:21:37 +00:00
martin 1ad22223be Mark a variable as __diagused. 2016-03-12 11:45:59 +00:00
kardel 641d22c5f7 do no access uninitialized variables in KASSERTs - fixes build 2016-03-12 10:51:00 +00:00
joerg b2f469507c Implement most of mount -ur functionality for tmpfs. Remaining issue is
the question who is responsible for syncing pending writes, but the
functionality is good enough for serving as read-only chroot base in
bulk builds.
2016-03-12 08:51:13 +00:00
joerg d547094d79 Only recheck size/node limits on update mounts, if there actually have
been specified.
2016-03-12 08:45:23 +00:00
leot 9df9aefc02 Make sure that nde->td_node is NULL for asserts.
Thanks and from Mindaugas Rasiukevicius.

Fixes PR kern/50381.
2015-10-29 16:19:44 +00:00
justin eec608f983 This enum is likely to be made unsigned by the compiler, so the assertion
will not work and clang objects with -Wtautological-constant-out-of-range-compare
2015-07-07 09:30:24 +00:00
wiz 90eb2b6e7b Fix typo in comment. 2015-07-06 10:24:59 +00:00
hannken 8c80da52ef Change tmpfs to vcache.
- Use tmpfs node address as key.
- Remove tn_vlock, field tn_vnode now protected by vcache.
- Add a hold count to tmpfs node to prevent nodes from disappearing
  while tmpfs_fhtovp() trys to vcache_get() them.  Last holder
  destroys reclaimed nodes.
- Remove the now unneeded parent unlock/lock for lookup of '..'.
2015-07-06 10:07:12 +00:00
hannken 12475e0224 Use VFS_PROTOS() for tmpfs. 2015-07-06 10:05:50 +00:00
riastradh 46e71c7d57 Make VOP_LINK return directory still locked and referenced.
Ride 7.99.10 bump.
2015-04-20 22:59:19 +00:00
riastradh f6139440c5 Make vget always return vnode unlocked.
Convert callers who want locks to use vn_lock afterward.

Add extra argument so the compiler will report stragglers.
2015-04-20 13:44:16 +00:00
uebayasi fe9a32c84e Define filesystem attributes with vfs dependency. 2014-10-11 06:42:18 +00:00
gson 1b265e6701 Store symlinks without a NUL terminator so that lstat(2) returns the
correct length.  Fixes the tmpfs part of PR kern/48864.
2014-09-08 14:49:46 +00:00
dholland 05d075b3ae Add VOP_FALLOCATE and VOP_FDISCARD to every vnode ops table I can
find.

The filesystem ones all call genfs_eopnotsupp - right now I am only
implementing the plumbing and we can implement fallocate and/or
fdiscard for files later.

The device ones call spec_fallocate (which is also genfs_eopnotsupp)
and spec_fdiscard, which dispatches to the device-level op.

The fifo ones all call vn_fifo_bypass, which also ends up being
EOPNOTSUPP.
2014-07-25 08:20:51 +00:00
pooka a98adcf8d6 use psize_t for physical memory calculation 2014-06-13 11:57:48 +00:00
martin b7650b1af5 Check for invalid mount arguments early and gracefully fail the mount.
Spotted by pooka@
2014-06-10 16:10:59 +00:00
martin 269c704651 Make sure to expand "freepages" to 64bit before shifting to byte values -
on rump we may have all our virtual address space "free".
Pointed out by pooka@.
2014-06-10 15:44:27 +00:00
martin c7dd06b6bb Remove the hardcoded 4 MB free kernel memory limit and replace it
by uvmexp.freetarg, as discussed on tech-kern.
Main purpose is to make tmpfs usable (as far as possible) on small memory
machines.
This is a bit experimental, but we need to give it some real world exposure
to see how well it works.
2014-06-07 09:54:34 +00:00
rmind ce079fc9c0 tmpfs_mknod: it is not our responsibility to call vput() on the directory
vnode, so remove it (and ensure *vpp is NULL while here).
2014-05-26 19:12:07 +00:00
christos 71fd41685f fix typo 2014-04-30 01:59:30 +00:00
christos 0172bc970f handle MNT_UPDATE 2014-04-30 01:33:51 +00:00
maxv 23f76b6d00 An (un)privileged user can easily make the kernel dereference a NULL
pointer.

The kernel allows 'data' to be NULL; it's the fs's responsibility to
ensure that it isn't NULL (if the fs actually needs data).

ok christos@
2014-04-16 18:55:17 +00:00
hannken 6d285189fb Change all vfsops to use C99 designated initializers.
No functional changes intended.
2014-03-23 15:21:15 +00:00
hannken 2b6ec89863 The current implementation of vn_lock() is racy. Modification of
the vnode operations vector for active vnodes is unsafe because it
is not known whether deadfs or the original file system will be
called.

- Pass down LK_RETRY to the lock operation (hint for deadfs only).

- Change deadfs lock operation to return ENOENT if LK_RETRY is unset.

- Change all other lock operations to check for dead vnode once
  the vnode is locked and unlock and return ENOENT in this case.

With these changes in place vnode lock operations will never succeed
after vclean() has marked the vnode as VI_XLOCK and before vclean()
has changed the operations vector.

Adresses PR kern/37706 (Forced unmount of file systems is unsafe)

Discussed on tech-kern.

Welcome to 6.99.33
2014-02-27 16:51:37 +00:00
maxv 1036f1d9fc Adapt my previous patch differently. read(2) wants EISDIR when the
object is a directory. Which also means that tmpfs_read() was returning
a wrong error code when dealing with non-regular vnodes.
2014-02-17 20:16:52 +00:00
maxv 6b47753f22 Fix tmpfs_read()'s return value; it should return EINVAL. Now consistent with
tmpfs_write().

ok christos@
2014-02-16 12:54:07 +00:00
hannken 97834f7ba0 Change vnode operation lookup to return the resulting vnode *vpp unlocked.
Change cache_lookup() to return an unlocked vnode.

Discussed on tech-kern@

Welcome to 6.99.31
2014-02-07 15:29:20 +00:00
hannken b9c5e8c0f7 Remove an annoying printf. And to answer the question: VFS_VGET() gets
used by NFS V3 server for readdirplus.
2014-02-06 16:18:38 +00:00
hannken 04c776e5c8 Change vnode operations create, mknod, mkdir and symlink to return
the resulting vnode *vpp unlocked.

Discussed on tech-kern@

Welcome to 6.99.30
2014-01-23 10:13:55 +00:00
hannken 1139274440 Change vnode operations create, mknod, mkdir and symlink to keep the
directory node dvp locked on return.

Discussed on tech-kern@

Welcome to 6.99.29
2014-01-17 10:55:01 +00:00
pedro 65d0f0003c Prevent a diagnostic assertion in tmpfs_rmdir() from being triggered
through an rmdir on ".." by moving it so it happens after the check for
empty directories; OK rmind@.
2014-01-10 16:42:38 +00:00
pedro 0cc071bd88 Allocate direntp on the stack in tmpfs_dir_getdents(), thus saving
calls to kmem_zalloc() and kmem_free(); OK rmind@. From OpenBSD.
2014-01-08 16:11:04 +00:00
hannken b04f8aa83f Fix a race where thread1 runs VOP_REMOVE() and gets preempted in
tmpfs_reclaim() before the call to tmpfs_free_node().  Thread2
runs VFS_FHTOVP() and gets a new vnode attached to the node thread1
is about to destroy.

Change tmpfs_fhtovp() to check the generation number after
tmpfs_vnode_get() succeeded.
2014-01-04 12:36:49 +00:00
hannken 8ea5485de5 Fix a race where thread1 runs VOP_REMOVE() and gets preempted in
tmpfs_reclaim() before the call to tmpfs_free_node().  Thread2
runs VFS_FHTOVP() and gets a new vnode attached to the node thread1
is about to destroy.

Change tmpfs_alloc_node() to always assign non-zero generation number
and tmpfs_inactive() to set the generation number of unlinked nodes
to zero.
2014-01-03 09:53:12 +00:00
hannken 905b6b7730 It is not the task of tmpfs_open() to check for unlinked nodes.
Fix tmpfs_lookup() to always return ENOENT when looking up from
an unlinked directory.
2013-12-24 09:23:33 +00:00
rmind ccc45228d5 - tmpfs_construct_node: prevent from the new node construction if the
directory was removed.  Fixes the crash reported by Nicolas Joly.
- tmpfs_reclaim: avoid race by checking tn_links with the vnode locked.
2013-11-24 17:16:29 +00:00