Commit graph

399 commits

Author SHA1 Message Date
David van Moolenbroek 4f6b382c41 Retire ptrace(T_DUMPCORE), dumpcore(1), gcore(1)
The T_DUMPCORE implementation was not only broken - it would currently
produce a coredump of the tracer process rather than the traced
process - but also deeply flawed, and fixing it would require serious
alteration of PM's internal state machine. It should be possible to
implement the same functionality in userland, and that is now the
suggested way forward. For now, also remove the (identical) utilities
using T_DUMPCORE: dumpcore(1) and gcore(1).

Change-Id: I1d51be19c739362b8a5833de949b76382a1edbcc
2014-02-18 11:25:03 +01:00
David van Moolenbroek f707937192 VFS: process char driver replies from main thread
Previously, processing of some replies coming from character drivers
could block on locks, and therefore, such processing was done from
threads that were associated to the character driver process. The
hidden consequence of this was that if all threads were in use, VFS
could drop replies coming from the driver. This patch returns VFS to
a situation where the replies from character drivers are processed
instantly from the main thread, by removing the situations that may
cause VFS to block while handling those replies.

- change the locking model for select, so that it will never block
  on any processing that happens after the select call has been set
  up, in particular processing of character driver select replies;
- clearly mark all select routines that may never block;
- protect against race conditions in do_select as result of the
  locking that still does happen there (as is required for pipes);
- also handle select timers from the main thread;
- move processing of character driver replies into device.c.

Change-Id: I4dc8e69f265cbd178de0fbf321d35f58f067cc57
2014-02-18 11:25:03 +01:00
David van Moolenbroek 2e9f4d0198 VFS: properly cancel select queries on unpause
Change-Id: I16e71db3f5c1bcc7ba6045bc9f02b13d71dc31eb
2014-02-18 11:25:03 +01:00
David van Moolenbroek 87aefd7eb2 VFS: remove support for sync char driver protocol
Change-Id: I57cc870a053b813b3a3fc45da46606ea84fe4cb1
2014-02-18 11:25:03 +01:00
David van Moolenbroek c7fbafe1ad VFS: remove FP_BLOCKED_ON_DOPEN
These days, DEV_OPEN calls to character drivers block the calling
thread until completion or failure, and thus never return SUSPEND to
the caller. The same already applied to BDEV_OPEN calls to block
drivers. It has thus become impossible for a process to enter a state
of being blocked on a device open call.

There is currently no support for restarting device open calls to
restarted character drivers. This support was present in the _DOPEN
logic, but was already no longer triggering. In the future, this case
should be handled by the thread performing the open request.

Change-Id: I6cc1e7b4c9ed116c6ce160b315e6e060124dce00
2014-02-18 11:25:03 +01:00
David van Moolenbroek 6331e8f845 Retire the synchronous character driver protocol
- change all sync char drivers into async drivers;
- retire support for the sync protocol in libchardev;
- remove async dev style, as this is now the default;
- remove dev_status from VFS;
- clean up now-unused protocol messages.

Change-Id: I6aacff712292f6b29f2ccd51bc1e7d7003723e87
2014-02-18 11:25:02 +01:00
David van Moolenbroek 97172a1db0 Sync char protocol: add nonblocking transfer flag
The async char protocol already has this, so this patch closes the
gap between the two protocols a bit. Support for this flag has been
added to all sync char drivers that support CANCEL at all.

The LOG driver was already using the asynchronous protocol, but it
did not support the nonblocking transfer flag. This has been fixed
as well.

Change-Id: Ia55432c9f102765b59ad3feb45a8bd47a782c93f
2014-02-18 11:25:02 +01:00
David van Moolenbroek a75c47e5ac VFS: set w_drv_sendrec only when needed
As with w_task, this ensures that the field remains cleared if it is
not used. Without this, worker_stop could mistakenly identify a thread
as talking to a device driver rather than a (crashed) file server.

Change-Id: I7d3ebed3efc3cd4f5c891f61c67a6463109b6376
2014-02-18 11:25:02 +01:00
Thomas Veerman 7d02ecdbb4 VFS: set w_task only when needed
It was always set, but not always cleared, when talking to asynchronous
drivers. This could cause erratic behavior upon a driver crash.

Normally, a worker thread's w_task field is set when it's about to
communicate with a driver or FS. Then upon receiving a reply we can
do sanity checks (that the thread we want to wake up was actually
waiting for a reply). Also, when a driver/FS crashes, we can identify
which worker threads were talking to the crashed endpoint and handle
the error gracefully.

Asynchronous drivers are a bit special, though. In most cases, the
sender of the request is not interested in the reply (the sender was
suspended and only wants to know whether the request was successfully
caried out or not). However, the open request is special, as the reply
carries information needed by the sender. This is the only request
where a worker thread actually yields and waits for the result. This is
also the only case where we're interested in setting w_task for
asynchronous drivers.

Change-Id: Ia1ce2747937df376122b5e13b6a069de27fcc379
2014-02-18 11:25:02 +01:00
Lionel Sambuc cfd3379bb1 Removing CSU patches
* Removed startup code patches in lib/csu regarding kernel to userland
   ABI.

 * Aligned stack layout on NetBSD stack layout.

 * Generate valid stack pointers instead of offsets by taking into account
   _minix_kerninfo->kinfo->user_sp.

 * Refactored stack generation, by moving part of execve in two
   functions {minix_stack_params(), minix_stack_fill()} and using them
   in execve(), rs and vm.

 * Changed load offset of rtld (ld.so) to:
      execi.args.stack_high - execi.args.stack_size - 0xa00000
   which is 10MB below the main executable stack.

Change-Id: I839daf3de43321cded44105634102d419cb36cec
2014-02-18 11:25:02 +01:00
David van Moolenbroek 24ed4e38de Remove support for obsolete 3.2.1 ABI
Change-Id: I76b4960bda41f55d9c42f8c99c5beae3424ca851
2014-02-18 11:25:02 +01:00
David van Moolenbroek cc810ee4d9 VFS/FS: replace protocol version with flag field
The main motivation for this change is that only Loris supports
multithreading, and Loris supports dynamic thread allocation, so the
number of supported threads can be implemented as a bit flag (i.e.,
either 1 or "at least as many as VFS has"). The ABI break obviates the
need to support file system versioning at this time, and several
other aspects are better implemented as flags as well. Other changes:

- replace peek/bpeek test upon mount with FS flag as well;
- mark libsffs as 64-bit file size capable;
- remove old (3.2.1) getdents support.

Change-Id: I313eace9c50ed816656c31cd47d969033d952a03
2014-02-18 11:25:02 +01:00
David van Moolenbroek 8143b9bf1d Implement support for [f]statvfs1(2)
The [f]statvfs(3) calls now use [f]statvfs1(2).

Change-Id: I949c177fc14abf976e45165c342f897f4ec988ee
2014-02-18 11:25:02 +01:00
David van Moolenbroek 266239fe64 Implement support for getvfsstat(2)
Change-Id: I99b697919d411c57105de561105beefc7d1d309a
2014-02-18 11:25:02 +01:00
David van Moolenbroek 7113bcb896 Redo mount(2)/umount(2) ABI
- pass in file system type through mount(2), and return this type in
  statvfs structures as generated by [f]statvfs(2);
- align mount flags field with NetBSD's, splitting out service flags
  which are not to be passed to VFS;
- remove limitation of mount ABI to 16-byte labels, so that labels
  can be made larger in the future;
- introduce new m11 message union type for mount(2) as side effect.

Change-Id: I88b7710e297e00a5e4582ada5243d3d5c2801fd9
2014-02-18 11:25:01 +01:00
David van Moolenbroek 61ed526374 Align "struct statvfs" with NetBSD
This is a requirement for implementing calls such as getmntinfo(3).
VFS is now responsible for filling in some of the structure's fields.

Change-Id: I0c1fa78019587efefd2949b3be38cd9a7ddc2ced
2014-02-18 11:25:01 +01:00
David van Moolenbroek f10229eafb VFS/FS: remove fstatfs(2) and REQ_FSTATFS
The fstatfs(3) call now uses fstatvfs(2).

Change-Id: I3fa5d31f078457b4d80418c23060bb2c148cb460
2014-02-18 11:25:01 +01:00
Lionel Sambuc d44c3377db Bumping version to 3.3.0
Change-Id: I4c88bdd449daf6ad3fe4e93ee8fc35d4f38becc4
2014-02-18 11:25:01 +01:00
Thomas Veerman 32e916ad53 VFS: use 64-bit file offsets in all requests
Change-Id: I735c4068135474aff2c397f4bc9fb147a618b453
2014-02-18 11:25:01 +01:00
Thomas Veerman c1a31d53d9 stat.h: remove some big_ types
Change-Id: I84017db3d54edfb823cc52e02d0b07fccb003988
2014-02-18 11:25:01 +01:00
Thomas Veerman ab19ece134 Define protocol version of {mode,ino,uid,gid}_t
Change-Id: Ia2027749f2ce55a561d19eb895a5618505e9a2ac
2014-02-18 11:25:01 +01:00
Thomas Veerman c66fd312d4 VFS-FS protocol: add versioning
Change-Id: Ice6fbfd4b535b7435653fa08b27a3378d1cfdbf8
2014-02-18 11:25:00 +01:00
Ben Gras 740c1a7425 libminixfs: allow non-pagesize-multiple FSes
The memory-mapped files implementation (mmap() etc.) is implemented with
the help of the filesystems using the in-VM FS cache. Filesystems tell it
about all cached blocks and their metadata. Metadata is: device offset and,
if any (and known), inode number and in-inode offset. VM can then map in
requested memory-mapped file blocks, and request them if necessary.

A limitation of this system is that filesystem block sizes that are not
a multiple of the VM system (and VM hardware) page size are not possible;
we can't map blocks in partially. (We can copy, but then the benefits of
mapping and sharing the physical pages is gone.) So until before this
commit various pieces of caching code assumed page size multiple
blocksizes. This isn't strictly necessary as long as mmap() needn't be
supported on that FS.

This change allows the in-FS cache code (libminixfs) to allocate any-sized
blocks, and will not interact with the VM cache for non-pagesize-multiple
blocks. In that case it will also signal requestors, by failing 'peek'
requests, that mmap() should not be supported on this FS. VM and VFS
will then gracefully fail all file-mapping mmap() calls, and exec() will
fall back to copying executable blocks instead of mmap()ping executables.

As a result, 3 diagnostics that signal file-mapped mmap()s failing
(hitherto an unusual occurence) are disabled, as ld.so does file-mapped
mmap()s to map in objects it needs. On FSes not supporting it this situation
is legitimate and shouldn't cause so much noise. ld.so will revert to its own
minix-specific allocate+copy style of starting executables if mmap()s fail.

Change-Id: Iecb1c8090f5e0be28da8f5181bb35084eb18f67b
2013-11-21 10:03:06 +00:00
Gerard f1b0deacf3 Replaced add64, add64u and add64ul with operators.
Change-Id: Ia537f83e15cb686f1b81b34d73596f4298b0a924
2013-11-13 13:11:33 +00:00
Ben Gras c8f3b10909 fix a few more minix specific warnings
. also disable stack protection feature for gcc,
	  causes build errors for pkgsrc gcc on minix

Change-Id: I1c6e2bcb4d948098d642543d7b2711284ee55c72
2013-08-27 16:16:03 +00:00
David van Moolenbroek 78d707cd26 VM: support for shared call mask ACLs
The VM server now manages its call masks such that all user processes
share the same call mask. As a result, an update for the call mask of
any user process will apply to all user processes. This is similar to
the privilege infrastructure employed by the kernel, and may serve as
a template for similar fine-grained restrictions in other servers.

Concretely, this patch fixes the problem of "service edit init" not
applying the given VM call mask to user processes started from RC
scripts during system startup.

In addition, this patch makes RS set a proper VM call mask for each
recovery script it spawns.

Change-Id: I520a30d85a0d3f3502d2b158293a2258825358cf
2013-08-08 23:22:58 +02:00
Antoine Leca da82f9b2e8 <a.out.h>, MINIX style: remove as obsolete
Change-Id: Icc8b7210d60a93ac9cc4610d676dcba270756410
2013-08-06 11:43:35 +02:00
David van Moolenbroek c4f3c7d66f VFS: fix access bits in device reopen calls 2013-08-05 12:30:13 +02:00
Lionel Sambuc 0cdf705cc6 Enable optional GCC install and GCC improvements
-By adding MKGCC=yes and MKGCCCMDS=yes on the make commandline
   it is now possible to compile and install GCC on the system.

   Before doing this, if you are not using the build.sh script,
   you will need to call the fetch scripts in order to retrieve
   the sources of GCC and its dependencies.

 -Reduce difference with NetBSD share/mk

   Move Minix-specific parameters from bsd.gcc.mk to bsd.own.mk,
   which is anyway patched, so that bsd.gcc.mk is now aligned
   on the NetBSD version.

 -Clean libraries dependencies, compiles stdc++ only if gcc is
   also compiled (it is part of the gcc sources)

 -Correct minix.h header sequence, cleanup spec headers.

 -Fix cross-compilation from a 32bit host targeting MINIX/arm

Change-Id: I1b234af18eed4ab5675188244e931b2a2b7bd943
2013-07-12 14:22:03 +02:00
Xiaoguang Sun 64f10ee644 Implement getrusage
Implement getrusage.
These fields of struct rusage are not supported and always set to zero at this time
long ru_nswap;           /* swaps */
long ru_inblock;         /* block input operations */
long ru_oublock;         /* block output operations */
long ru_msgsnd;          /* messages sent */
long ru_msgrcv;          /* messages received */
long ru_nvcsw;           /* voluntary context switches */
long ru_nivcsw;          /* involuntary context switches */

test75.c is the unit test for this new function

Change-Id: I3f1eb69de1fce90d087d76773b09021fc6106539
2013-07-01 23:00:47 +02:00
Ben Gras cdf2f55a90 kernel, arm ucontext: ARM DBG=-g run fixes
kernel:
	. modules can be as big as the space (8MB) between them
	  instead of 4MB; memory is slightly bigger with DBG=-g

arm ucontext:
	. r4 is clobbered by the restore function, as it's
	  used as a scratch register, causing problems for the
	  DBG=-g build
	. r1-r3 are safe for scratch registers, as they are
	  caller-save, so use r3 instead; and don't bother
	  restoring r1-r3, but preserve r4

vfs:
	. improve TLL pointer sanity check a bit

Change-Id: I0e3cfc367fdc14477e40d04b5e044f288ca4cc7d
2013-06-24 16:57:30 +02:00
Ben Gras 456359aa72 retire 64-bit conversion functions
Change-Id: Ib6b81403f877c363a286c654e0524fa1cb781b80
2013-06-24 16:50:57 +02:00
Ben Gras 8f2749cca8 vfs: patch for unpause()/revive() race condition
. unpause() and revive() can race - revive() can run during
	  a device i/o unblock, causing two sendnb()s to occur, and the
	  2nd one to fail
	. this can easily happen when a process is blocking on tty and
	  is then killed by a signal - tty cancels the i/o and then
	  kills the process by a signal

Change-Id: Ia319acaedfa336b78c030a2c4af7246959bdcf87
2013-06-14 23:58:43 +02:00
Ben Gras 9e43052b21 inline sendnb should not call send vector
. also vfs has to reply to a vm call - so use asynsend for that

Change-Id: I30ac1e591191dea5c99e25b03151a4415d1151b0
2013-06-12 07:04:53 +00:00
Ben Gras 9178749e13 libc syslog, syslogd, logger, uds fixes
changes necessary for libc syslog() using a unix domain socket.

	. libc syslog: don't use send() connect() for unix
	  datagram sockets, minix wants write() and ioctl()
	. syslogd: listen on _PATH_LOG unix domain socket
	. logger: warnings fixes
	. pfs: make uds dgram socket type nonblocking so
	  syslog() doesn't block
	. vfs: add sanity check for empty fd in unpause()

Change-Id: Ied136c6fe0cc288f5a53478f1eebccc1ab1f39fb
2013-06-12 07:04:52 +00:00
Ben Gras f369157d95 pfs, vfs: increase various limits
. pipes in pfs
	. vnodes in vfs
	. thread stack sizes in vfs

Change-Id: Ib27dedd42f57a90821a5b950cd7ea25cb2b42f3f
2013-05-31 15:42:00 +00:00
Ben Gras 33a7ac7557 vfs: mmap support
. libc: add vfs_mmap, a way for vfs to initiate mmap()s.
	  This is a good special case to have as vfs is a slightly
	  different client from regular user processes. It doesn't do it
	  for itself, and has the dev & inode info already so the callback
	  to VFS for the lookup isn't necessary. So it has different info
	  to have to give to VM.
	. libc: also add minix_mmap64() that accepts a 64-bit offset, even
	  though our off_t is still 32 bit now.
	. On exec() time, try to mmap() in the executable if available.
	  (It is not yet available in this commit.)
	. To support mmap(), add do_vm_call that allows VM to lookup
	  (to ino+dev), do i/o from and close FD's on behalf of other
	  processes.

Change-Id: I831551e45a6781c74313c450eb9c967a68505932
2013-05-31 15:42:00 +00:00
Ben Gras 2d2a1a077d panic: declare as printf-style-checked
. and related fixes

Change-Id: I5131ac57dc53d8aec8d421a34c5ceea383404d7a
2013-05-31 13:35:25 +00:00
Ben Gras 5507a12d7c vfs: who_p fix
Change-Id: I0e04b6460907f5e67f6c90b2038d296d66b9a414
2013-05-31 09:28:38 +00:00
Ben Gras 4ebb889e7a libsys: panic hook feature
. vfs: use it to dump threads stacks

Change-Id: I7ae3521fc153a407505f11049629e6d4142cf7c7
2013-05-07 17:18:40 +00:00
Ben Gras 44f34e53d5 VFS: Implement REQ_BPEEK.
This commit introduces a new request type called REQ_BPEEK. It
requests minor device blocks from the FS.  Analogously to REQ_PEEK,
it requests the filesystem to get the requested blocks into its
cache, without actually copying the result anywhere.

Change-Id: If1d06645b0e17553a64b3167091e9d12efeb3d6f
2013-04-24 10:18:16 +00:00
Ben Gras 0cfff08e56 libexec: mmap support, prealloc variants
In libexec, split the memory allocation method into cleared and
non-cleared. Cleared gives zeroed memory, non-cleared gives 'junk'
memory (that will be overwritten anyway, and so needn't be cleared)
that is faster to get.

Also introduce the 'memmap' method that can be used, if available,
to map code and data from executables into a process using the
third-party mmap() mode.

Change-Id: I26694fd3c21deb8b97e01ed675dfc14719b0672b
2013-04-24 10:18:16 +00:00
Xiaoguang Sun 20e6c9329f Change function prototype to use endpoint_t instead of int 2013-04-23 17:15:15 +02:00
Ben Gras 072d916c1c vfs: fix null deref, pfs: add fchmod()
. vfs read_only() assumes vnode->v_vmnt is non-NULL, but it can
	  be NULL sometimes
	. e.g. fchmod() on UDS triggered NULL deref; add a check and
	  add REQ_CHMOD to pfs so unix domain sockets can be fchmod()ded
	. add to test56

Change-Id: I83c840f101b647516897cc99fcf472116d762012
2013-04-19 17:06:56 +02:00
Ben Gras cef94e096e vfs: make m_out non-global
m_out is shared between threads as the reply message, and it can happen
results get overwritten by another thread before the reply is sent. This
change

	. makes m_out local to the message handling function,
	  declared on the stack of the caller
	. forces callers of reply() to give it a message, or
	  declare the reply message has no significant fields except
	  for the return code by calling replycode()

Change-Id: Id06300083a63c72c00f34f86a5c7d96e4bbdf9f6
2013-04-12 23:40:38 +00:00
Antoine Leca 9131e98a7d utimens(2) system call
Variant of utime(2) with struct timespec (with ns precision)
instead of time_t values; also allows for tv_nsec members
the values UTIME_NOW (force update to current time) or
UTIME_OMIT (allow to set either atim or mtim independently.)

Provides a superset of utimes(2), futimes(2), lutimes(2),
and futimens(2).
Provides the same subset of utimensat(2) as does NetBSD 6.
Also import utimens() and lutimeNS() from NetBSD-current.
2013-04-12 18:55:39 +00:00
Antoine Leca 4069cef7f9 Subsecond timestamps support for FS
Expand REQ_UTIME to include tv_nsec members
(as in struct timespec) in addition to tv_sec==time_t

Designed with help from David van Moolenbroek
2013-04-12 11:11:59 +02:00
Thomas Cort 516fec97d9 libc: add clock_settime() system call.
This also adds the sys_settime() kernel call which allows for the adjusting
of the clock named realtime in the kernel. The existing sys_stime()
function is still needed for a separate job (setting the boottime). The
boottime is set in the readclock driver. The sys_settime() interface is
meant to be flexible and will support both clock_settime() and adjtime()
when adjtime() is implemented later.

settimeofday() was adjusted to use the clock_settime() interface.

One side note discovered during testing: uptime(1) (part of the last(1)),
uses wtmp to determine boottime (not Minix's times(2)). This leads `uptime`
to report odd results when you set the time to a time prior to boottime.
This isn't a new bug introduced by my changes. It's been there for a while.
2013-04-04 15:04:54 +02:00
Thomas Cort e67fc5771d libc: add clock_getres()/clock_gettime() system calls.
In order to make it more clear that ticks should be used for timers
and realtime should be used for timestamps / displaying the date/time,
getuptime() was renamed to getticks() and getuptime2() was renamed to
getuptime().

Servers, drivers, libraries, tests, etc that use getuptime()/getuptime2()
have been updated. In instances where a realtime was calculated, the
calculation was changed to use realtime.

System calls clock_getres() and clock_gettime() were added to PM/libc.
2013-04-04 15:04:53 +02:00
Thomas Veerman 6ee180f5f7 VFS: wikify README
Change-Id: I746f7c8ddabd1e047b8d536df14586c5b1594d55
2013-03-21 15:20:34 +00:00
Ben Gras 4f9139778d vfs: coredump fix: write zeroes for missing memory 2013-03-20 20:05:31 +00:00
Thomas Veerman 76ddef10da UDS: terminate canonical path string
When you provided a string with junk after the terminating nul to a
UNIX domain socket and used bind(2), the canonical path function would
not properly terminate the new string. This caused VFS to return
ENAMETOOLONG on an otherwise valid path name.

Test case is added to test56.

Change-Id: I883b6be23d9e4ea13c3cee28cbb3726343df037f
2013-03-08 15:42:32 +00:00
Ben Gras a9f55a2e46 VFS, FSes: add REQ_PEEK request type
REQ_PEEK behaves just like REQ_READ except that it does not copy
data anywhere, just obtains the blocks from the FS into the cache.

To be used by the future mmap implementation.

Change-Id: I1b56de304f0a7152b69a72c8962d04258adb44f9
2013-03-07 10:57:38 +00:00
Lionel Sambuc 8f3fbf7cc1 Cleanup: Remove minix.bootprog.mk
The build system distinction between "bootprog" and "service" is
meaningless as boot programs are standard services.

As minix.service.mk simply imports minix.bootprog.mk, reduce confusion
by removing minix.bootprog.mk and placing the rules in minix.service.mk.

Change-Id: I4056b1e574bed59a8c890239b41b1a7c7cad63e8
2013-03-06 11:56:56 +01:00
Thomas Veerman 49ad4e8888 Spring cleanup
Remove old versions of system calls and system calls that don't have
a libc api interface anymore (dup, dup2, creat).

VFS still contains support for old system call numbers for the new stat
system calls (i.e., 65, 66, 67) to keep supporting old binaries built for
MINIX 3.2.1 (prior to the release).

Change-Id: I721779b58a50c7eeae20669de24658d55d69b25b
2013-03-06 09:56:08 +00:00
Thomas Veerman 473547c777 VFS: implement pipe2
Change-Id: Iedc8042dd73a903456b25ba665d12577f5589ca2
2013-02-28 10:08:53 +00:00
Thomas Veerman fa78dc389f socket: implement SOCK_CLOEXEC and SOCK_NONBLOCK
Change-Id: I3fa36fa999c82a192d402cb4d913bd397e106e53
2013-02-28 10:08:53 +00:00
Thomas Veerman fd610ba1b0 VFS: add ability to open files O_CLOEXEC
.adjust libc to make use of it (undo __minix diff)

Change-Id: I90a1aa219fcd1b12b6bc60e72176f326eac8184a
2013-02-28 10:08:53 +00:00
Lionel Sambuc f640210005 Removing obsolete _NBSD_LIBC define
Change-Id: Ia6ce84ccdf36cf6f64540b990baaa7d85c53533d
2013-02-26 09:44:24 +00:00
Lionel Sambuc 8e4736f2df Removing obsolete _MINIX define
Change-Id: Id33ac7e973d1c0e249b690fe44a597474fac6076
2013-02-26 09:44:20 +00:00
Thomas Veerman 2b90964e33 VFS: don't garbage collect if file is already closed 2013-02-21 10:29:08 +00:00
Thomas Veerman cfcce207c1 VFS: prevent unmapping drivers that don't support reopening
libchardriver does not support DEV_REOPEN and will return ERESTART
when you do try it. This made VFS unhappy and concluded erroneously
that the driver was EDEADEPT.
2013-02-21 10:29:08 +00:00
Ben Gras 298b41b523 libexec: detect short files
if an exec() fails partway through reading in the sections, the target
process is already gone and a defunct process remains. sanity checking
the binary beforehand helps that.

test10 mutilates binaries and exec()s them on purpose; making an exec()
fail cleanly in such cases seems like acceptable behaviour.

fixes test10 on ARM.

Change-Id: I1ed9bb200ce469d4d349073cadccad5503b2fcb0
2013-02-04 12:04:35 +01:00
Thomas Veerman 06e2adbeaa VFS: fix select again
Change-Id: Ia5e26cdbfe38e3fb293dd57269a76b15c1fe236b
2013-01-25 17:42:36 +00:00
Thomas Veerman b180f32ab3 VFS/PFS: remove remnants of file position in pipes 2013-01-23 11:14:34 +00:00
Thomas Veerman 306f3ccd6f VFS: fix select bug on pipes 2013-01-23 11:14:34 +00:00
Lionel Sambuc f14fb60209 Libraries updates and cleanup
* Updating common/lib
 * Updating lib/csu
 * Updating lib/libc
 * Updating libexec/ld.elf_so
 * Corrected test on __minix in featuretest to actually follow the
   meaning of the comment.
 * Cleaned up _REENTRANT-related defintions.
 * Disabled -D_REENTRANT for libfetch
 * Removing some unneeded __NBSD_LIBC defines and tests

Change-Id: Ic1394baef74d11b9f86b312f5ff4bbc3cbf72ce2
2013-01-14 11:36:26 +01:00
Thomas Veerman bdfef53dbf VFS: initialize variables 2013-01-11 12:46:44 +00:00
Thomas Veerman aa521228a5 VFS: Coverity appeasements 2013-01-11 09:42:01 +00:00
Thomas Veerman ea8ff9284a Add stack trace dumps for VFS over serial 2013-01-11 09:18:36 +00:00
Thomas Veerman 625f4ae4a3 VFS: add documentation about internal working 2013-01-11 09:18:36 +00:00
Thomas Veerman 23c5f56e32 VFS: change locking to ease concurrent FSes
This patch uses stricter locking for REQ_LINK, REQ_MKDIR, REQ_MKNOD,
REQ_RENAME, REQ_RMDIR, REQ_SLINK and REQ_UNLINK. For all requests, VFS
locks the directory in which we add or remove an inode with VNODE_WRITE.
I.e., the operations have exclusive access to that directory.

Furthermore, REQ_CHOWN, REQ_CHMOD, and REQ_FTRUNC now lock the vmnt
VMNT_READ; VMNT_WRITE was unnecessary.
2013-01-11 09:18:35 +00:00
Thomas Veerman 3de8d1cf6e VFS/PFS: remove notion of position in pipes
Because pipes have no file position. VFS maintained (file) offsets into a
buffer internal to PFS and stored them in vnodes for simplicity, mixing
the responsibilities of filp and vnode objects.

With this patch PFS ignores the position field in REQ_READ and REQ_WRITE
requests making VFS' job a lot simpler.
2013-01-11 09:18:35 +00:00
Thomas Veerman 7c8b3ddfed VFS: fix locking bugs
.sync and fsync used unnecessarily restrictive locking type
.fsync violated locking order by obtaining a vmnt lock after a filp lock
.fsync contained a TOCTOU bug
.new_node violated locking rules (didn't upgrade lock upon file creation)
.do_pipe used unnecessarily restrictive locking type
.always lock pipes exclusively; even a read operation might require to do
 a write on a vnode object (update pipe size)
.when opening a file with O_TRUNC, upgrade vnode lock when truncating
.utime used unnecessarily restrictive locking type
.path parsing:
  .always acquire VMNT_WRITE or VMNT_EXCL on vmnt and downgrade to
   VMNT_READ if that was what was actually requested. This prevents the
   following deadlock scenario:
   thread A:
     lock_vmnt(vmp, TLL_READSER);
     lock_vnode(vp, TLL_READSER);
     upgrade_vmnt_lock(vmp, TLL_WRITE);

   thread B:
     lock_vmnt(vmp, TLL_READ);
     lock_vnode(vp, TLL_READSER);

   thread A will be stuck in upgrade_vmnt_lock and thread B is stuck in
   lock_vnode. This happens when, for example, thread A tries create a
   new node (open.c:new_node) and thread B tries to do eat_path to
   change dir (stadir.c:do_chdir). When the path is being resolved, a
   vnode is always locked with VNODE_OPCL (TLL_READSER) and then
   downgraded to VNODE_READ if read-only is actually requested. Thread
   A locks the vmnt with VMNT_WRITE (TLL_READSER) which still allows
   VMNT_READ locks. Thread B can't acquire a lock on the vnode because
   thread A has it; Thread A can't upgrade its vmnt lock to VMNT_WRITE
   (TLL_WRITE) because thread B has a VMNT_READ lock on it.

   By serializing vmnt locks during path parsing, thread B can only
   acquire a lock on vmp when thread A has completely finished its
   operation.
2013-01-11 09:18:35 +00:00
Kees Jongenburger c0c581a635 vfs:fix for variable 'rfp' set but not used.
mount.c: In function 'mount_pfs':
mount.c:395:17: error: variable 'rfp' set but not used [-Werror=unused-but-set-variable]

Change-Id: I2f22590ab4e3a4a1678e9096626ebca53d2660e6
2013-01-07 09:12:27 +01:00
Ben Gras 8aeac26999 vfs: fix clobbering fd_nr
dumpcore: fd_nr can be in use as blocking fd but will then be clobbered
by common_open, causing disaster for exiting unpause().
2012-12-11 12:00:57 +01:00
David van Moolenbroek 766047123a VFS: fix off-by-one in get_name() 2012-11-30 12:24:47 +00:00
Thomas Veerman 179261a9b6 mtab: support moving mount points
Also fix canonical_path function; it fails to parse some paths
2012-11-29 10:50:51 +00:00
Thomas Veerman d9f4f71916 Implement dynamic mtab support
With this patch /etc/mtab becomes obsolete.
2012-11-26 15:20:18 +00:00
Thomas Veerman de83b2a9d9 VFS: change 'last_dir' to match locking assumption
new_node makes the assumption that when it does last_dir on a path, a
successive advance would not yield a lock on a vmnt, because last_dir
already locked the vmnt. This is true except when last_dir resolves
to a directory on the parent vmnt of the file that was the result of
advance. For example,
 # cd /
 # echo foo > home
where home is on a different (sub) partition than / is (default
install). last_dir would resolve to / and advance would resolve to
/home.

With this change, last_dir resolves to the root node on the /home
partition, making the assumption valid again.
2012-11-26 15:20:18 +00:00
David van Moolenbroek 7dd286e6b8 VFS: do not save device node for new regular files
The VFS/FS protocol does not require the file server to supply a
special device node number in response to a REQ_CREATE request, as
this call creates only regular files. Therefore, VFS should not
erroneously save this piece of information from the REQ_CREATE reply
either.
2012-11-15 14:29:59 +00:00
Thomas Veerman 14e470be81 VFS: fix TOCTOU bug in sync 2012-11-14 13:24:53 +00:00
Thomas Veerman ed23a7a7d2 VFS: fix reboot panic with mounted FUSE FS
Upon reboot VFS semi-exits all processes and unmounts the file system.
However, upon unmount, exiting FUSE file systems might need service from
the file system (due to libc). As the FUSE process is halfway the exit
procedure, it doesn't have a valid root directory and working directory.
Trying to do system calls then triggers a sanity check in VFS.

This fix first exits normal processes which should then allow for
unmounting FUSE file systems. Then VFS exits all processes including
File Servers and unmounts the rest of the file system.
2012-11-14 13:18:16 +00:00
Thomas Veerman badec36b33 VFS: fix deadlock when out of worker threads
There is a deadlock vulnerability when there are no worker threads
available and all of them blocked on a worker thread that's waiting for a
reply from a driver or a reply from an FS that needs to make a back call. In
these cases the deadlock resolver thread should kick in, but didn't in all
cases. Moreover, POSIX calls from File Servers weren't handled properly
anymore, which also could lead to deadlocks.
2012-11-14 13:12:37 +00:00
Arne Welzel e35c4f78d2 VFS: fix check_bsf() locking
The check_bsf() macro uses assert(mutex_trylock(&bsf_lock)) and
assumes bsf_lock is locked afterwards. This breaks when compiling
with NOASSERTS="yes". Also: macro to function transition.
2012-09-28 14:57:34 +02:00
Arne Welzel 7e1074732b VFS: resolve unused parameter if NOASSERTS="yes"
If VFS is compiled with NOASSERTS="yes", ctty_opcl() does not
use the op parameter. Change to "non-assert()" sanity check.
2012-09-28 14:57:32 +02:00
Ben Gras 60014efb3e vfs: pm_dumpcore: always clean up process
. whenever this function is called, pm will expect
	  the process to be cleaned up
	. so don't abort the process entirely on error
	. fixes a later 'forking on top of in-use child' vfs panic
2012-09-19 17:13:17 +02:00
Thomas Veerman c087a60ed2 VFS: fix GCC compilation error 2012-09-17 15:29:38 +00:00
Thomas Veerman 3881e732a9 VFS: panic when unmount_all fails 2012-09-17 11:01:46 +00:00
Thomas Veerman 992799b91f VFS: make all IPC asynchronous
By decoupling synchronous drivers from VFS, we are a big step closer to
supporting driver crashes under all circumstances. That is, VFS can't
become stuck on IPC with a synchronous driver (e.g., INET) and can
recover from crashing block drivers during open/close/ioctl or during
communication with an FS.

In order to maintain serialized communication with a synchronous driver,
the communication is wrapped by a mutex on a per driver basis (not major
numbers as there can be multiple majors with identical endpoints). Majors
that share a driver endpoint point to a single mutex object.

In order to support crashes from block drivers, the file reopen tactic
had to be changed; first reopen files associated with the crashed
driver, then send the new driver endpoint to FSes. This solves a
deadlock between the FS and the block driver;
  - VFS would send REQ_NEW_DRIVER to an FS, but he FS only receives it
    after retrying the current request to the newly started driver.
  - The block driver would refuse the retried request until all files
    had been reopened.
  - VFS would reopen files only after getting a reply from the initial
    REQ_NEW_DRIVER.

When a character special driver crashes, all associated files have to
be marked invalid and closed (or reopened if flagged as such). However,
they can only be closed if a thread holds exclusive access to it. To
obtain exclusive access, the worker thread (which handles the new driver
endpoint event from DS) schedules a new job to garbage collect invalid
files. This way, we can signal the worker thread that was talking to the
crashed driver and will release exclusive access to a file associated
with the crashed driver and prevent the garbage collecting worker thread
from dead locking on that file.

Also, when a character special driver crashes, RS will unmap the driver
and remap it upon restart. During unmapping, associated files are marked
invalid instead of waiting for an endpoint up event from DS, as that
event might come later than new read/write/select requests and thus
cause confusion in the freshly started driver.

When locking a filp, the usage counters are no longer checked. The usage
counter can legally go down to zero during filp invalidation while there
are locks pending.

DS events are handled by a separate worker thread instead of the main
thread as reopening files could lead to another crash and a stuck thread.
An additional worker thread is then necessary to unlock it.

Finally, with everything asynchronous a race condition in do_select
surfaced. A select entry was only marked in use after succesfully sending
initial select requests to drivers and having to wait. When multiple
select() calls were handled there was opportunity that these entries
were overwritten. This had as effect that some select results were
ignored (and select() remained blocking instead if returning) or do_select
tried to access filps that were not present (because thrown away by
secondary select()). This bug manifested itself with sendrecs, but was
very hard to reproduce. However, it became awfully easy to trigger with
asynsends only.
2012-09-17 11:01:45 +00:00
Ben Gras e4ac80eb60 various warning/errorwarning fixes for gcc47
. warnings (sometimes promoted to errors) in servers/ and kernel/
 . -Os for ext2 boot module to make it small enough
2012-08-27 16:19:18 +02:00
Ben Gras 31d8526346 libexec: add load_offset feature, used for ld.so
. ld.so is linked at 0 but it can relocate itself; we
	  wish to load ld.so higher though to trap NULL dereferences.
	  if we know we have to execute ld.so, vfs tells libexec to put it
	  higher.
2012-08-12 23:22:54 +02:00
Thomas Veerman 66dbf73049 VFS: fix locking bug in clone_opcl
When VFS runs out of vnodes after closing a vnode in opcl, common_open
will try to unlock a vnode through unlock_filp that has already been
unlocked in clone_opcl. By first obtaining and locking a new vnode this
situation is prevented; if there are no free vnodes, common_open will
unlock a still locked vnode.
2012-07-30 10:01:16 +00:00
Thomas Veerman f6b0d662b5 VFS: check path components for NAME_MAX length 2012-07-30 09:44:58 +00:00
David van Moolenbroek 0b4c154160 VFS: call req_inhibread again 2012-07-19 14:36:51 +00:00
David van Moolenbroek e0742978f1 VFS: do not resolve symlinks in rename(2) 2012-07-18 14:59:45 +00:00
Thomas Veerman 0d3ccd8908 VFS: fix coverity defects 2012-07-17 10:29:22 +00:00
Thomas Veerman fd60f03129 VFS: remove support for sync FS communication 2012-07-17 10:12:53 +00:00
Thomas Veerman 06f49fe167 VFS: prevent buffer overflow
If an FS returns faulty struct dirent data, VFS could overflow
a buffer that holds this data.
2012-07-17 08:49:41 +00:00
Ben Gras cbcdb838f1 various coverity-inspired fixes
. some strncpy/strcpy to strlcpy conversions
	. new <minix/param.h> to avoid including other minix headers
	  that have colliding definitions with library and commands code,
	  causing parse warnings
	. removed some dead code / assignments
2012-07-16 14:00:56 +02:00