2005-04-21 16:53:53 +02:00
|
|
|
/* When a needed block is not in the cache, it must be fetched from the disk.
|
|
|
|
* Special character files also require I/O. The routines for these are here.
|
|
|
|
*
|
|
|
|
* The entry points in this file are:
|
2013-09-10 20:25:01 +02:00
|
|
|
* cdev_open: open a character device
|
|
|
|
* cdev_close: close a character device
|
|
|
|
* cdev_io: initiate a read, write, or ioctl to a character device
|
|
|
|
* cdev_select: initiate a select call on a device
|
|
|
|
* cdev_cancel: cancel an I/O request, blocking until it has been cancelled
|
|
|
|
* cdev_reply: process the result of a character driver request
|
|
|
|
* bdev_open: open a block device
|
|
|
|
* bdev_close: close a block device
|
|
|
|
* bdev_reply: process the result of a block driver request
|
|
|
|
* bdev_up: a block driver has been mapped in
|
|
|
|
* do_ioctl: perform the IOCTL system call
|
2005-04-21 16:53:53 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "fs.h"
|
Split block/character protocols and libdriver
This patch separates the character and block driver communication
protocols. The old character protocol remains the same, but a new
block protocol is introduced. The libdriver library is replaced by
two new libraries: libchardriver and libblockdriver. Their exposed
API, and drivers that use them, have been updated accordingly.
Together, libbdev and libblockdriver now completely abstract away
the message format used by the block protocol. As the memory driver
is both a character and a block device driver, it now implements its
own message loop.
The most important semantic change made to the block protocol is that
it is no longer possible to return both partial results and an error
for a single transfer. This simplifies the interaction between the
caller and the driver, as the I/O vector no longer needs to be copied
back. Also, drivers are now no longer supposed to decide based on the
layout of the I/O vector when a transfer should be cut short. Put
simply, transfers are now supposed to either succeed completely, or
result in an error.
After this patch, the state of the various pieces is as follows:
- block protocol: stable
- libbdev API: stable for synchronous communication
- libblockdriver API: needs slight revision (the drvlib/partition API
in particular; the threading API will also change shortly)
- character protocol: needs cleanup
- libchardriver API: needs cleanup accordingly
- driver restarts: largely unsupported until endpoint changes are
reintroduced
As a side effect, this patch eliminates several bugs, hacks, and gcc
-Wall and -W warnings all over the place. It probably introduces a
few new ones, too.
Update warning: this patch changes the protocol between MFS and disk
drivers, so in order to use old/new images, the MFS from the ramdisk
must be used to mount all file systems.
2011-11-22 13:27:53 +01:00
|
|
|
#include <string.h>
|
2005-04-21 16:53:53 +02:00
|
|
|
#include <fcntl.h>
|
2006-06-20 12:12:09 +02:00
|
|
|
#include <assert.h>
|
2011-03-25 11:56:43 +01:00
|
|
|
#include <sys/stat.h>
|
2005-04-21 16:53:53 +02:00
|
|
|
#include <minix/callnr.h>
|
|
|
|
#include <minix/com.h>
|
endpoint-aware conversion of servers.
'who', indicating caller number in pm and fs and some other servers, has
been removed in favour of 'who_e' (endpoint) and 'who_p' (proc nr.).
In both PM and FS, isokendpt() convert endpoints to process slot
numbers, returning OK if it was a valid and consistent endpoint number.
okendpt() does the same but panic()s if it doesn't succeed. (In PM,
this is pm_isok..)
pm and fs keep their own records of process endpoints in their proc tables,
which are needed to make kernel calls about those processes.
message field names have changed.
fs drivers are endpoints.
fs now doesn't try to get out of driver deadlock, as the protocol isn't
supposed to let that happen any more. (A warning is printed if ELOCKED
is detected though.)
fproc[].fp_task (indicating which driver the process is suspended on)
became an int.
PM and FS now get endpoint numbers of initial boot processes from the
kernel. These happen to be the same as the old proc numbers, to let
user processes reach them with the old numbers, but FS and PM don't know
that. All new processes after INIT, even after the generation number
wraps around, get endpoint numbers with generation 1 and higher, so
the first instances of the boot processes are the only processes ever
to have endpoint numbers in the old proc number range.
More return code checks of sys_* functions have been added.
IS has become endpoint-aware. Ditched the 'text' and 'data' fields
in the kernel dump (which show locations, not sizes, so aren't terribly
useful) in favour of the endpoint number. Proc number is still visible.
Some other dumps (e.g. dmap, rs) show endpoint numbers now too which got
the formatting changed.
PM reading segments using rw_seg() has changed - it uses other fields
in the message now instead of encoding the segment and process number and
fd in the fd field. For that it uses _read_pm() and _write_pm() which to
_taskcall()s directly in pm/misc.c.
PM now sys_exit()s itself on panic(), instead of sys_abort().
RS also talks in endpoints instead of process numbers.
2006-03-03 11:20:58 +01:00
|
|
|
#include <minix/endpoint.h>
|
2006-06-20 12:12:09 +02:00
|
|
|
#include <minix/ioctl.h>
|
2006-11-27 15:21:43 +01:00
|
|
|
#include <minix/u64.h>
|
2005-04-21 16:53:53 +02:00
|
|
|
#include "file.h"
|
2012-02-13 16:28:04 +01:00
|
|
|
#include "scratchpad.h"
|
|
|
|
#include "dmap.h"
|
2006-10-25 15:40:36 +02:00
|
|
|
#include <minix/vfsif.h>
|
|
|
|
#include "vnode.h"
|
|
|
|
#include "vmnt.h"
|
2005-04-21 16:53:53 +02:00
|
|
|
#include "param.h"
|
|
|
|
|
2013-10-06 15:58:54 +02:00
|
|
|
static int cdev_opcl(int op, dev_t dev, int flags);
|
2013-08-30 13:33:56 +02:00
|
|
|
static int block_io(endpoint_t driver_e, message *mess_ptr);
|
|
|
|
static cp_grant_id_t make_grant(endpoint_t driver_e, endpoint_t user_e, int op,
|
2013-09-10 12:19:08 +02:00
|
|
|
void *buf, unsigned long size);
|
2012-02-13 16:28:04 +01:00
|
|
|
|
Split block/character protocols and libdriver
This patch separates the character and block driver communication
protocols. The old character protocol remains the same, but a new
block protocol is introduced. The libdriver library is replaced by
two new libraries: libchardriver and libblockdriver. Their exposed
API, and drivers that use them, have been updated accordingly.
Together, libbdev and libblockdriver now completely abstract away
the message format used by the block protocol. As the memory driver
is both a character and a block device driver, it now implements its
own message loop.
The most important semantic change made to the block protocol is that
it is no longer possible to return both partial results and an error
for a single transfer. This simplifies the interaction between the
caller and the driver, as the I/O vector no longer needs to be copied
back. Also, drivers are now no longer supposed to decide based on the
layout of the I/O vector when a transfer should be cut short. Put
simply, transfers are now supposed to either succeed completely, or
result in an error.
After this patch, the state of the various pieces is as follows:
- block protocol: stable
- libbdev API: stable for synchronous communication
- libblockdriver API: needs slight revision (the drvlib/partition API
in particular; the threading API will also change shortly)
- character protocol: needs cleanup
- libchardriver API: needs cleanup accordingly
- driver restarts: largely unsupported until endpoint changes are
reintroduced
As a side effect, this patch eliminates several bugs, hacks, and gcc
-Wall and -W warnings all over the place. It probably introduces a
few new ones, too.
Update warning: this patch changes the protocol between MFS and disk
drivers, so in order to use old/new images, the MFS from the ramdisk
must be used to mount all file systems.
2011-11-22 13:27:53 +01:00
|
|
|
/*===========================================================================*
|
2013-09-10 12:19:08 +02:00
|
|
|
* bdev_open *
|
Split block/character protocols and libdriver
This patch separates the character and block driver communication
protocols. The old character protocol remains the same, but a new
block protocol is introduced. The libdriver library is replaced by
two new libraries: libchardriver and libblockdriver. Their exposed
API, and drivers that use them, have been updated accordingly.
Together, libbdev and libblockdriver now completely abstract away
the message format used by the block protocol. As the memory driver
is both a character and a block device driver, it now implements its
own message loop.
The most important semantic change made to the block protocol is that
it is no longer possible to return both partial results and an error
for a single transfer. This simplifies the interaction between the
caller and the driver, as the I/O vector no longer needs to be copied
back. Also, drivers are now no longer supposed to decide based on the
layout of the I/O vector when a transfer should be cut short. Put
simply, transfers are now supposed to either succeed completely, or
result in an error.
After this patch, the state of the various pieces is as follows:
- block protocol: stable
- libbdev API: stable for synchronous communication
- libblockdriver API: needs slight revision (the drvlib/partition API
in particular; the threading API will also change shortly)
- character protocol: needs cleanup
- libchardriver API: needs cleanup accordingly
- driver restarts: largely unsupported until endpoint changes are
reintroduced
As a side effect, this patch eliminates several bugs, hacks, and gcc
-Wall and -W warnings all over the place. It probably introduces a
few new ones, too.
Update warning: this patch changes the protocol between MFS and disk
drivers, so in order to use old/new images, the MFS from the ramdisk
must be used to mount all file systems.
2011-11-22 13:27:53 +01:00
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
int bdev_open(dev_t dev, int access)
|
Split block/character protocols and libdriver
This patch separates the character and block driver communication
protocols. The old character protocol remains the same, but a new
block protocol is introduced. The libdriver library is replaced by
two new libraries: libchardriver and libblockdriver. Their exposed
API, and drivers that use them, have been updated accordingly.
Together, libbdev and libblockdriver now completely abstract away
the message format used by the block protocol. As the memory driver
is both a character and a block device driver, it now implements its
own message loop.
The most important semantic change made to the block protocol is that
it is no longer possible to return both partial results and an error
for a single transfer. This simplifies the interaction between the
caller and the driver, as the I/O vector no longer needs to be copied
back. Also, drivers are now no longer supposed to decide based on the
layout of the I/O vector when a transfer should be cut short. Put
simply, transfers are now supposed to either succeed completely, or
result in an error.
After this patch, the state of the various pieces is as follows:
- block protocol: stable
- libbdev API: stable for synchronous communication
- libblockdriver API: needs slight revision (the drvlib/partition API
in particular; the threading API will also change shortly)
- character protocol: needs cleanup
- libchardriver API: needs cleanup accordingly
- driver restarts: largely unsupported until endpoint changes are
reintroduced
As a side effect, this patch eliminates several bugs, hacks, and gcc
-Wall and -W warnings all over the place. It probably introduces a
few new ones, too.
Update warning: this patch changes the protocol between MFS and disk
drivers, so in order to use old/new images, the MFS from the ramdisk
must be used to mount all file systems.
2011-11-22 13:27:53 +01:00
|
|
|
{
|
|
|
|
/* Open a block device. */
|
2013-09-10 12:19:08 +02:00
|
|
|
devmajor_t major_dev;
|
|
|
|
devminor_t minor_dev;
|
|
|
|
message dev_mess;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
major_dev = major(dev);
|
|
|
|
minor_dev = minor(dev);
|
|
|
|
if (major_dev < 0 || major_dev >= NR_DEVICES) return ENXIO;
|
|
|
|
if (dmap[major_dev].dmap_driver == NONE) return ENXIO;
|
|
|
|
|
|
|
|
memset(&dev_mess, 0, sizeof(dev_mess));
|
|
|
|
dev_mess.m_type = BDEV_OPEN;
|
|
|
|
dev_mess.BDEV_MINOR = minor_dev;
|
|
|
|
dev_mess.BDEV_ACCESS = 0;
|
|
|
|
if (access & R_BIT) dev_mess.BDEV_ACCESS |= BDEV_R_BIT;
|
|
|
|
if (access & W_BIT) dev_mess.BDEV_ACCESS |= BDEV_W_BIT;
|
|
|
|
dev_mess.BDEV_ID = 0;
|
Split block/character protocols and libdriver
This patch separates the character and block driver communication
protocols. The old character protocol remains the same, but a new
block protocol is introduced. The libdriver library is replaced by
two new libraries: libchardriver and libblockdriver. Their exposed
API, and drivers that use them, have been updated accordingly.
Together, libbdev and libblockdriver now completely abstract away
the message format used by the block protocol. As the memory driver
is both a character and a block device driver, it now implements its
own message loop.
The most important semantic change made to the block protocol is that
it is no longer possible to return both partial results and an error
for a single transfer. This simplifies the interaction between the
caller and the driver, as the I/O vector no longer needs to be copied
back. Also, drivers are now no longer supposed to decide based on the
layout of the I/O vector when a transfer should be cut short. Put
simply, transfers are now supposed to either succeed completely, or
result in an error.
After this patch, the state of the various pieces is as follows:
- block protocol: stable
- libbdev API: stable for synchronous communication
- libblockdriver API: needs slight revision (the drvlib/partition API
in particular; the threading API will also change shortly)
- character protocol: needs cleanup
- libchardriver API: needs cleanup accordingly
- driver restarts: largely unsupported until endpoint changes are
reintroduced
As a side effect, this patch eliminates several bugs, hacks, and gcc
-Wall and -W warnings all over the place. It probably introduces a
few new ones, too.
Update warning: this patch changes the protocol between MFS and disk
drivers, so in order to use old/new images, the MFS from the ramdisk
must be used to mount all file systems.
2011-11-22 13:27:53 +01:00
|
|
|
|
2013-09-10 12:19:08 +02:00
|
|
|
/* Call the task. */
|
|
|
|
r = block_io(dmap[major_dev].dmap_driver, &dev_mess);
|
|
|
|
if (r != OK)
|
|
|
|
return r;
|
Split block/character protocols and libdriver
This patch separates the character and block driver communication
protocols. The old character protocol remains the same, but a new
block protocol is introduced. The libdriver library is replaced by
two new libraries: libchardriver and libblockdriver. Their exposed
API, and drivers that use them, have been updated accordingly.
Together, libbdev and libblockdriver now completely abstract away
the message format used by the block protocol. As the memory driver
is both a character and a block device driver, it now implements its
own message loop.
The most important semantic change made to the block protocol is that
it is no longer possible to return both partial results and an error
for a single transfer. This simplifies the interaction between the
caller and the driver, as the I/O vector no longer needs to be copied
back. Also, drivers are now no longer supposed to decide based on the
layout of the I/O vector when a transfer should be cut short. Put
simply, transfers are now supposed to either succeed completely, or
result in an error.
After this patch, the state of the various pieces is as follows:
- block protocol: stable
- libbdev API: stable for synchronous communication
- libblockdriver API: needs slight revision (the drvlib/partition API
in particular; the threading API will also change shortly)
- character protocol: needs cleanup
- libchardriver API: needs cleanup accordingly
- driver restarts: largely unsupported until endpoint changes are
reintroduced
As a side effect, this patch eliminates several bugs, hacks, and gcc
-Wall and -W warnings all over the place. It probably introduces a
few new ones, too.
Update warning: this patch changes the protocol between MFS and disk
drivers, so in order to use old/new images, the MFS from the ramdisk
must be used to mount all file systems.
2011-11-22 13:27:53 +01:00
|
|
|
|
2013-09-10 12:19:08 +02:00
|
|
|
return dev_mess.BDEV_STATUS;
|
Split block/character protocols and libdriver
This patch separates the character and block driver communication
protocols. The old character protocol remains the same, but a new
block protocol is introduced. The libdriver library is replaced by
two new libraries: libchardriver and libblockdriver. Their exposed
API, and drivers that use them, have been updated accordingly.
Together, libbdev and libblockdriver now completely abstract away
the message format used by the block protocol. As the memory driver
is both a character and a block device driver, it now implements its
own message loop.
The most important semantic change made to the block protocol is that
it is no longer possible to return both partial results and an error
for a single transfer. This simplifies the interaction between the
caller and the driver, as the I/O vector no longer needs to be copied
back. Also, drivers are now no longer supposed to decide based on the
layout of the I/O vector when a transfer should be cut short. Put
simply, transfers are now supposed to either succeed completely, or
result in an error.
After this patch, the state of the various pieces is as follows:
- block protocol: stable
- libbdev API: stable for synchronous communication
- libblockdriver API: needs slight revision (the drvlib/partition API
in particular; the threading API will also change shortly)
- character protocol: needs cleanup
- libchardriver API: needs cleanup accordingly
- driver restarts: largely unsupported until endpoint changes are
reintroduced
As a side effect, this patch eliminates several bugs, hacks, and gcc
-Wall and -W warnings all over the place. It probably introduces a
few new ones, too.
Update warning: this patch changes the protocol between MFS and disk
drivers, so in order to use old/new images, the MFS from the ramdisk
must be used to mount all file systems.
2011-11-22 13:27:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* bdev_close *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
int bdev_close(dev_t dev)
|
Split block/character protocols and libdriver
This patch separates the character and block driver communication
protocols. The old character protocol remains the same, but a new
block protocol is introduced. The libdriver library is replaced by
two new libraries: libchardriver and libblockdriver. Their exposed
API, and drivers that use them, have been updated accordingly.
Together, libbdev and libblockdriver now completely abstract away
the message format used by the block protocol. As the memory driver
is both a character and a block device driver, it now implements its
own message loop.
The most important semantic change made to the block protocol is that
it is no longer possible to return both partial results and an error
for a single transfer. This simplifies the interaction between the
caller and the driver, as the I/O vector no longer needs to be copied
back. Also, drivers are now no longer supposed to decide based on the
layout of the I/O vector when a transfer should be cut short. Put
simply, transfers are now supposed to either succeed completely, or
result in an error.
After this patch, the state of the various pieces is as follows:
- block protocol: stable
- libbdev API: stable for synchronous communication
- libblockdriver API: needs slight revision (the drvlib/partition API
in particular; the threading API will also change shortly)
- character protocol: needs cleanup
- libchardriver API: needs cleanup accordingly
- driver restarts: largely unsupported until endpoint changes are
reintroduced
As a side effect, this patch eliminates several bugs, hacks, and gcc
-Wall and -W warnings all over the place. It probably introduces a
few new ones, too.
Update warning: this patch changes the protocol between MFS and disk
drivers, so in order to use old/new images, the MFS from the ramdisk
must be used to mount all file systems.
2011-11-22 13:27:53 +01:00
|
|
|
{
|
|
|
|
/* Close a block device. */
|
2013-09-10 12:19:08 +02:00
|
|
|
devmajor_t major_dev;
|
|
|
|
devminor_t minor_dev;
|
|
|
|
message dev_mess;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
major_dev = major(dev);
|
|
|
|
minor_dev = minor(dev);
|
|
|
|
if (major_dev < 0 || major_dev >= NR_DEVICES) return ENXIO;
|
|
|
|
if (dmap[major_dev].dmap_driver == NONE) return ENXIO;
|
|
|
|
|
|
|
|
memset(&dev_mess, 0, sizeof(dev_mess));
|
|
|
|
dev_mess.m_type = BDEV_CLOSE;
|
|
|
|
dev_mess.BDEV_MINOR = minor_dev;
|
|
|
|
dev_mess.BDEV_ID = 0;
|
Split block/character protocols and libdriver
This patch separates the character and block driver communication
protocols. The old character protocol remains the same, but a new
block protocol is introduced. The libdriver library is replaced by
two new libraries: libchardriver and libblockdriver. Their exposed
API, and drivers that use them, have been updated accordingly.
Together, libbdev and libblockdriver now completely abstract away
the message format used by the block protocol. As the memory driver
is both a character and a block device driver, it now implements its
own message loop.
The most important semantic change made to the block protocol is that
it is no longer possible to return both partial results and an error
for a single transfer. This simplifies the interaction between the
caller and the driver, as the I/O vector no longer needs to be copied
back. Also, drivers are now no longer supposed to decide based on the
layout of the I/O vector when a transfer should be cut short. Put
simply, transfers are now supposed to either succeed completely, or
result in an error.
After this patch, the state of the various pieces is as follows:
- block protocol: stable
- libbdev API: stable for synchronous communication
- libblockdriver API: needs slight revision (the drvlib/partition API
in particular; the threading API will also change shortly)
- character protocol: needs cleanup
- libchardriver API: needs cleanup accordingly
- driver restarts: largely unsupported until endpoint changes are
reintroduced
As a side effect, this patch eliminates several bugs, hacks, and gcc
-Wall and -W warnings all over the place. It probably introduces a
few new ones, too.
Update warning: this patch changes the protocol between MFS and disk
drivers, so in order to use old/new images, the MFS from the ramdisk
must be used to mount all file systems.
2011-11-22 13:27:53 +01:00
|
|
|
|
2013-09-10 12:19:08 +02:00
|
|
|
r = block_io(dmap[major_dev].dmap_driver, &dev_mess);
|
|
|
|
if (r != OK)
|
|
|
|
return r;
|
Split block/character protocols and libdriver
This patch separates the character and block driver communication
protocols. The old character protocol remains the same, but a new
block protocol is introduced. The libdriver library is replaced by
two new libraries: libchardriver and libblockdriver. Their exposed
API, and drivers that use them, have been updated accordingly.
Together, libbdev and libblockdriver now completely abstract away
the message format used by the block protocol. As the memory driver
is both a character and a block device driver, it now implements its
own message loop.
The most important semantic change made to the block protocol is that
it is no longer possible to return both partial results and an error
for a single transfer. This simplifies the interaction between the
caller and the driver, as the I/O vector no longer needs to be copied
back. Also, drivers are now no longer supposed to decide based on the
layout of the I/O vector when a transfer should be cut short. Put
simply, transfers are now supposed to either succeed completely, or
result in an error.
After this patch, the state of the various pieces is as follows:
- block protocol: stable
- libbdev API: stable for synchronous communication
- libblockdriver API: needs slight revision (the drvlib/partition API
in particular; the threading API will also change shortly)
- character protocol: needs cleanup
- libchardriver API: needs cleanup accordingly
- driver restarts: largely unsupported until endpoint changes are
reintroduced
As a side effect, this patch eliminates several bugs, hacks, and gcc
-Wall and -W warnings all over the place. It probably introduces a
few new ones, too.
Update warning: this patch changes the protocol between MFS and disk
drivers, so in order to use old/new images, the MFS from the ramdisk
must be used to mount all file systems.
2011-11-22 13:27:53 +01:00
|
|
|
|
2013-09-10 12:19:08 +02:00
|
|
|
return dev_mess.BDEV_STATUS;
|
Split block/character protocols and libdriver
This patch separates the character and block driver communication
protocols. The old character protocol remains the same, but a new
block protocol is introduced. The libdriver library is replaced by
two new libraries: libchardriver and libblockdriver. Their exposed
API, and drivers that use them, have been updated accordingly.
Together, libbdev and libblockdriver now completely abstract away
the message format used by the block protocol. As the memory driver
is both a character and a block device driver, it now implements its
own message loop.
The most important semantic change made to the block protocol is that
it is no longer possible to return both partial results and an error
for a single transfer. This simplifies the interaction between the
caller and the driver, as the I/O vector no longer needs to be copied
back. Also, drivers are now no longer supposed to decide based on the
layout of the I/O vector when a transfer should be cut short. Put
simply, transfers are now supposed to either succeed completely, or
result in an error.
After this patch, the state of the various pieces is as follows:
- block protocol: stable
- libbdev API: stable for synchronous communication
- libblockdriver API: needs slight revision (the drvlib/partition API
in particular; the threading API will also change shortly)
- character protocol: needs cleanup
- libchardriver API: needs cleanup accordingly
- driver restarts: largely unsupported until endpoint changes are
reintroduced
As a side effect, this patch eliminates several bugs, hacks, and gcc
-Wall and -W warnings all over the place. It probably introduces a
few new ones, too.
Update warning: this patch changes the protocol between MFS and disk
drivers, so in order to use old/new images, the MFS from the ramdisk
must be used to mount all file systems.
2011-11-22 13:27:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* bdev_ioctl *
|
|
|
|
*===========================================================================*/
|
2013-09-10 12:19:08 +02:00
|
|
|
static int bdev_ioctl(dev_t dev, endpoint_t proc_e, unsigned long req,
|
|
|
|
void *buf)
|
Split block/character protocols and libdriver
This patch separates the character and block driver communication
protocols. The old character protocol remains the same, but a new
block protocol is introduced. The libdriver library is replaced by
two new libraries: libchardriver and libblockdriver. Their exposed
API, and drivers that use them, have been updated accordingly.
Together, libbdev and libblockdriver now completely abstract away
the message format used by the block protocol. As the memory driver
is both a character and a block device driver, it now implements its
own message loop.
The most important semantic change made to the block protocol is that
it is no longer possible to return both partial results and an error
for a single transfer. This simplifies the interaction between the
caller and the driver, as the I/O vector no longer needs to be copied
back. Also, drivers are now no longer supposed to decide based on the
layout of the I/O vector when a transfer should be cut short. Put
simply, transfers are now supposed to either succeed completely, or
result in an error.
After this patch, the state of the various pieces is as follows:
- block protocol: stable
- libbdev API: stable for synchronous communication
- libblockdriver API: needs slight revision (the drvlib/partition API
in particular; the threading API will also change shortly)
- character protocol: needs cleanup
- libchardriver API: needs cleanup accordingly
- driver restarts: largely unsupported until endpoint changes are
reintroduced
As a side effect, this patch eliminates several bugs, hacks, and gcc
-Wall and -W warnings all over the place. It probably introduces a
few new ones, too.
Update warning: this patch changes the protocol between MFS and disk
drivers, so in order to use old/new images, the MFS from the ramdisk
must be used to mount all file systems.
2011-11-22 13:27:53 +01:00
|
|
|
{
|
|
|
|
/* Perform an I/O control operation on a block device. */
|
|
|
|
struct dmap *dp;
|
|
|
|
cp_grant_id_t gid;
|
|
|
|
message dev_mess;
|
2013-09-10 12:19:08 +02:00
|
|
|
devmajor_t major_dev;
|
|
|
|
devminor_t minor_dev;
|
2013-10-06 15:58:54 +02:00
|
|
|
int r;
|
Split block/character protocols and libdriver
This patch separates the character and block driver communication
protocols. The old character protocol remains the same, but a new
block protocol is introduced. The libdriver library is replaced by
two new libraries: libchardriver and libblockdriver. Their exposed
API, and drivers that use them, have been updated accordingly.
Together, libbdev and libblockdriver now completely abstract away
the message format used by the block protocol. As the memory driver
is both a character and a block device driver, it now implements its
own message loop.
The most important semantic change made to the block protocol is that
it is no longer possible to return both partial results and an error
for a single transfer. This simplifies the interaction between the
caller and the driver, as the I/O vector no longer needs to be copied
back. Also, drivers are now no longer supposed to decide based on the
layout of the I/O vector when a transfer should be cut short. Put
simply, transfers are now supposed to either succeed completely, or
result in an error.
After this patch, the state of the various pieces is as follows:
- block protocol: stable
- libbdev API: stable for synchronous communication
- libblockdriver API: needs slight revision (the drvlib/partition API
in particular; the threading API will also change shortly)
- character protocol: needs cleanup
- libchardriver API: needs cleanup accordingly
- driver restarts: largely unsupported until endpoint changes are
reintroduced
As a side effect, this patch eliminates several bugs, hacks, and gcc
-Wall and -W warnings all over the place. It probably introduces a
few new ones, too.
Update warning: this patch changes the protocol between MFS and disk
drivers, so in order to use old/new images, the MFS from the ramdisk
must be used to mount all file systems.
2011-11-22 13:27:53 +01:00
|
|
|
|
|
|
|
major_dev = major(dev);
|
|
|
|
minor_dev = minor(dev);
|
|
|
|
|
|
|
|
/* Determine task dmap. */
|
|
|
|
dp = &dmap[major_dev];
|
|
|
|
if (dp->dmap_driver == NONE) {
|
2013-08-30 11:14:03 +02:00
|
|
|
printf("VFS: bdev_ioctl: no driver for major %d\n", major_dev);
|
Split block/character protocols and libdriver
This patch separates the character and block driver communication
protocols. The old character protocol remains the same, but a new
block protocol is introduced. The libdriver library is replaced by
two new libraries: libchardriver and libblockdriver. Their exposed
API, and drivers that use them, have been updated accordingly.
Together, libbdev and libblockdriver now completely abstract away
the message format used by the block protocol. As the memory driver
is both a character and a block device driver, it now implements its
own message loop.
The most important semantic change made to the block protocol is that
it is no longer possible to return both partial results and an error
for a single transfer. This simplifies the interaction between the
caller and the driver, as the I/O vector no longer needs to be copied
back. Also, drivers are now no longer supposed to decide based on the
layout of the I/O vector when a transfer should be cut short. Put
simply, transfers are now supposed to either succeed completely, or
result in an error.
After this patch, the state of the various pieces is as follows:
- block protocol: stable
- libbdev API: stable for synchronous communication
- libblockdriver API: needs slight revision (the drvlib/partition API
in particular; the threading API will also change shortly)
- character protocol: needs cleanup
- libchardriver API: needs cleanup accordingly
- driver restarts: largely unsupported until endpoint changes are
reintroduced
As a side effect, this patch eliminates several bugs, hacks, and gcc
-Wall and -W warnings all over the place. It probably introduces a
few new ones, too.
Update warning: this patch changes the protocol between MFS and disk
drivers, so in order to use old/new images, the MFS from the ramdisk
must be used to mount all file systems.
2011-11-22 13:27:53 +01:00
|
|
|
return(ENXIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set up a grant if necessary. */
|
2013-08-30 13:33:56 +02:00
|
|
|
gid = make_grant(dp->dmap_driver, proc_e, BDEV_IOCTL, buf, req);
|
Split block/character protocols and libdriver
This patch separates the character and block driver communication
protocols. The old character protocol remains the same, but a new
block protocol is introduced. The libdriver library is replaced by
two new libraries: libchardriver and libblockdriver. Their exposed
API, and drivers that use them, have been updated accordingly.
Together, libbdev and libblockdriver now completely abstract away
the message format used by the block protocol. As the memory driver
is both a character and a block device driver, it now implements its
own message loop.
The most important semantic change made to the block protocol is that
it is no longer possible to return both partial results and an error
for a single transfer. This simplifies the interaction between the
caller and the driver, as the I/O vector no longer needs to be copied
back. Also, drivers are now no longer supposed to decide based on the
layout of the I/O vector when a transfer should be cut short. Put
simply, transfers are now supposed to either succeed completely, or
result in an error.
After this patch, the state of the various pieces is as follows:
- block protocol: stable
- libbdev API: stable for synchronous communication
- libblockdriver API: needs slight revision (the drvlib/partition API
in particular; the threading API will also change shortly)
- character protocol: needs cleanup
- libchardriver API: needs cleanup accordingly
- driver restarts: largely unsupported until endpoint changes are
reintroduced
As a side effect, this patch eliminates several bugs, hacks, and gcc
-Wall and -W warnings all over the place. It probably introduces a
few new ones, too.
Update warning: this patch changes the protocol between MFS and disk
drivers, so in order to use old/new images, the MFS from the ramdisk
must be used to mount all file systems.
2011-11-22 13:27:53 +01:00
|
|
|
|
|
|
|
/* Set up the message passed to the task. */
|
|
|
|
memset(&dev_mess, 0, sizeof(dev_mess));
|
|
|
|
|
|
|
|
dev_mess.m_type = BDEV_IOCTL;
|
|
|
|
dev_mess.BDEV_MINOR = minor_dev;
|
|
|
|
dev_mess.BDEV_REQUEST = req;
|
|
|
|
dev_mess.BDEV_GRANT = gid;
|
2013-07-27 00:49:49 +02:00
|
|
|
dev_mess.BDEV_USER = proc_e;
|
Split block/character protocols and libdriver
This patch separates the character and block driver communication
protocols. The old character protocol remains the same, but a new
block protocol is introduced. The libdriver library is replaced by
two new libraries: libchardriver and libblockdriver. Their exposed
API, and drivers that use them, have been updated accordingly.
Together, libbdev and libblockdriver now completely abstract away
the message format used by the block protocol. As the memory driver
is both a character and a block device driver, it now implements its
own message loop.
The most important semantic change made to the block protocol is that
it is no longer possible to return both partial results and an error
for a single transfer. This simplifies the interaction between the
caller and the driver, as the I/O vector no longer needs to be copied
back. Also, drivers are now no longer supposed to decide based on the
layout of the I/O vector when a transfer should be cut short. Put
simply, transfers are now supposed to either succeed completely, or
result in an error.
After this patch, the state of the various pieces is as follows:
- block protocol: stable
- libbdev API: stable for synchronous communication
- libblockdriver API: needs slight revision (the drvlib/partition API
in particular; the threading API will also change shortly)
- character protocol: needs cleanup
- libchardriver API: needs cleanup accordingly
- driver restarts: largely unsupported until endpoint changes are
reintroduced
As a side effect, this patch eliminates several bugs, hacks, and gcc
-Wall and -W warnings all over the place. It probably introduces a
few new ones, too.
Update warning: this patch changes the protocol between MFS and disk
drivers, so in order to use old/new images, the MFS from the ramdisk
must be used to mount all file systems.
2011-11-22 13:27:53 +01:00
|
|
|
dev_mess.BDEV_ID = 0;
|
|
|
|
|
|
|
|
/* Call the task. */
|
2013-10-06 15:58:54 +02:00
|
|
|
r = block_io(dp->dmap_driver, &dev_mess);
|
Split block/character protocols and libdriver
This patch separates the character and block driver communication
protocols. The old character protocol remains the same, but a new
block protocol is introduced. The libdriver library is replaced by
two new libraries: libchardriver and libblockdriver. Their exposed
API, and drivers that use them, have been updated accordingly.
Together, libbdev and libblockdriver now completely abstract away
the message format used by the block protocol. As the memory driver
is both a character and a block device driver, it now implements its
own message loop.
The most important semantic change made to the block protocol is that
it is no longer possible to return both partial results and an error
for a single transfer. This simplifies the interaction between the
caller and the driver, as the I/O vector no longer needs to be copied
back. Also, drivers are now no longer supposed to decide based on the
layout of the I/O vector when a transfer should be cut short. Put
simply, transfers are now supposed to either succeed completely, or
result in an error.
After this patch, the state of the various pieces is as follows:
- block protocol: stable
- libbdev API: stable for synchronous communication
- libblockdriver API: needs slight revision (the drvlib/partition API
in particular; the threading API will also change shortly)
- character protocol: needs cleanup
- libchardriver API: needs cleanup accordingly
- driver restarts: largely unsupported until endpoint changes are
reintroduced
As a side effect, this patch eliminates several bugs, hacks, and gcc
-Wall and -W warnings all over the place. It probably introduces a
few new ones, too.
Update warning: this patch changes the protocol between MFS and disk
drivers, so in order to use old/new images, the MFS from the ramdisk
must be used to mount all file systems.
2011-11-22 13:27:53 +01:00
|
|
|
|
|
|
|
/* Clean up. */
|
2012-02-13 16:28:04 +01:00
|
|
|
if (GRANT_VALID(gid)) cpf_revoke(gid);
|
Split block/character protocols and libdriver
This patch separates the character and block driver communication
protocols. The old character protocol remains the same, but a new
block protocol is introduced. The libdriver library is replaced by
two new libraries: libchardriver and libblockdriver. Their exposed
API, and drivers that use them, have been updated accordingly.
Together, libbdev and libblockdriver now completely abstract away
the message format used by the block protocol. As the memory driver
is both a character and a block device driver, it now implements its
own message loop.
The most important semantic change made to the block protocol is that
it is no longer possible to return both partial results and an error
for a single transfer. This simplifies the interaction between the
caller and the driver, as the I/O vector no longer needs to be copied
back. Also, drivers are now no longer supposed to decide based on the
layout of the I/O vector when a transfer should be cut short. Put
simply, transfers are now supposed to either succeed completely, or
result in an error.
After this patch, the state of the various pieces is as follows:
- block protocol: stable
- libbdev API: stable for synchronous communication
- libblockdriver API: needs slight revision (the drvlib/partition API
in particular; the threading API will also change shortly)
- character protocol: needs cleanup
- libchardriver API: needs cleanup accordingly
- driver restarts: largely unsupported until endpoint changes are
reintroduced
As a side effect, this patch eliminates several bugs, hacks, and gcc
-Wall and -W warnings all over the place. It probably introduces a
few new ones, too.
Update warning: this patch changes the protocol between MFS and disk
drivers, so in order to use old/new images, the MFS from the ramdisk
must be used to mount all file systems.
2011-11-22 13:27:53 +01:00
|
|
|
|
|
|
|
/* Return the result. */
|
2013-10-06 15:58:54 +02:00
|
|
|
if (r != OK)
|
|
|
|
return(r);
|
|
|
|
|
2012-02-13 16:28:04 +01:00
|
|
|
return(dev_mess.BDEV_STATUS);
|
Split block/character protocols and libdriver
This patch separates the character and block driver communication
protocols. The old character protocol remains the same, but a new
block protocol is introduced. The libdriver library is replaced by
two new libraries: libchardriver and libblockdriver. Their exposed
API, and drivers that use them, have been updated accordingly.
Together, libbdev and libblockdriver now completely abstract away
the message format used by the block protocol. As the memory driver
is both a character and a block device driver, it now implements its
own message loop.
The most important semantic change made to the block protocol is that
it is no longer possible to return both partial results and an error
for a single transfer. This simplifies the interaction between the
caller and the driver, as the I/O vector no longer needs to be copied
back. Also, drivers are now no longer supposed to decide based on the
layout of the I/O vector when a transfer should be cut short. Put
simply, transfers are now supposed to either succeed completely, or
result in an error.
After this patch, the state of the various pieces is as follows:
- block protocol: stable
- libbdev API: stable for synchronous communication
- libblockdriver API: needs slight revision (the drvlib/partition API
in particular; the threading API will also change shortly)
- character protocol: needs cleanup
- libchardriver API: needs cleanup accordingly
- driver restarts: largely unsupported until endpoint changes are
reintroduced
As a side effect, this patch eliminates several bugs, hacks, and gcc
-Wall and -W warnings all over the place. It probably introduces a
few new ones, too.
Update warning: this patch changes the protocol between MFS and disk
drivers, so in order to use old/new images, the MFS from the ramdisk
must be used to mount all file systems.
2011-11-22 13:27:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-20 12:12:09 +02:00
|
|
|
/*===========================================================================*
|
2013-08-30 13:33:56 +02:00
|
|
|
* make_grant *
|
2006-06-20 12:12:09 +02:00
|
|
|
*===========================================================================*/
|
2013-08-30 13:33:56 +02:00
|
|
|
static cp_grant_id_t make_grant(endpoint_t driver_e, endpoint_t user_e, int op,
|
2013-09-10 12:19:08 +02:00
|
|
|
void *buf, unsigned long bytes)
|
2006-06-20 12:12:09 +02:00
|
|
|
{
|
2013-08-30 13:33:56 +02:00
|
|
|
/* Create a magic grant for the given operation and buffer. */
|
|
|
|
cp_grant_id_t gid;
|
|
|
|
int access;
|
2012-02-13 16:28:04 +01:00
|
|
|
size_t size;
|
- Introduce support for sticky bit.
- Revise VFS-FS protocol and update VFS/MFS/ISOFS accordingly.
- Clean up MFS by removing old, dead code (backwards compatibility is broken by
the new VFS-FS protocol, anyway) and rewrite other parts. Also, make sure all
functions have proper banners and prototypes.
- VFS should always provide a (syntactically) valid path to the FS; no need for
the FS to do sanity checks when leaving/entering mount points.
- Fix several bugs in MFS:
- Several path lookup bugs in MFS.
- A link can be too big for the path buffer.
- A mountpoint can become inaccessible when the creation of a new inode
fails, because the inode already exists and is a mountpoint.
- Introduce support for supplemental groups.
- Add test 46 to test supplemental group functionality (and removed obsolete
suppl. tests from test 2).
- Clean up VFS (not everything is done yet).
- ISOFS now opens device read-only. This makes the -r flag in the mount command
unnecessary (but will still report to be mounted read-write).
- Introduce PipeFS. PipeFS is a new FS that handles all anonymous and
named pipes. However, named pipes still reside on the (M)FS, as they are part
of the file system on disk. To make this work VFS now has a concept of
'mapped' inodes, which causes read, write, truncate and stat requests to be
redirected to the mapped FS, and all other requests to the original FS.
2009-12-20 21:27:14 +01:00
|
|
|
|
2013-08-30 13:33:56 +02:00
|
|
|
switch (op) {
|
2013-09-10 20:25:01 +02:00
|
|
|
case CDEV_READ:
|
|
|
|
case CDEV_WRITE:
|
2013-09-10 12:19:08 +02:00
|
|
|
gid = cpf_grant_magic(driver_e, user_e, (vir_bytes) buf,
|
2013-09-10 20:25:01 +02:00
|
|
|
(size_t) bytes, op == CDEV_READ ? CPF_WRITE : CPF_READ);
|
2012-02-13 16:28:04 +01:00
|
|
|
break;
|
2013-08-30 13:33:56 +02:00
|
|
|
|
2013-09-10 20:25:01 +02:00
|
|
|
case CDEV_IOCTL:
|
2013-08-30 13:33:56 +02:00
|
|
|
case BDEV_IOCTL:
|
2013-09-10 12:19:08 +02:00
|
|
|
/* For IOCTLs, the bytes parameter contains the IOCTL request.
|
|
|
|
* This request encodes the requested access method and buffer size.
|
2013-08-30 13:33:56 +02:00
|
|
|
*/
|
|
|
|
access = 0;
|
2012-04-13 14:50:38 +02:00
|
|
|
if(_MINIX_IOCTL_IOR(bytes)) access |= CPF_WRITE;
|
|
|
|
if(_MINIX_IOCTL_IOW(bytes)) access |= CPF_READ;
|
|
|
|
if(_MINIX_IOCTL_BIG(bytes))
|
|
|
|
size = _MINIX_IOCTL_SIZE_BIG(bytes);
|
2012-02-13 16:28:04 +01:00
|
|
|
else
|
2012-04-13 14:50:38 +02:00
|
|
|
size = _MINIX_IOCTL_SIZE(bytes);
|
- Introduce support for sticky bit.
- Revise VFS-FS protocol and update VFS/MFS/ISOFS accordingly.
- Clean up MFS by removing old, dead code (backwards compatibility is broken by
the new VFS-FS protocol, anyway) and rewrite other parts. Also, make sure all
functions have proper banners and prototypes.
- VFS should always provide a (syntactically) valid path to the FS; no need for
the FS to do sanity checks when leaving/entering mount points.
- Fix several bugs in MFS:
- Several path lookup bugs in MFS.
- A link can be too big for the path buffer.
- A mountpoint can become inaccessible when the creation of a new inode
fails, because the inode already exists and is a mountpoint.
- Introduce support for supplemental groups.
- Add test 46 to test supplemental group functionality (and removed obsolete
suppl. tests from test 2).
- Clean up VFS (not everything is done yet).
- ISOFS now opens device read-only. This makes the -r flag in the mount command
unnecessary (but will still report to be mounted read-write).
- Introduce PipeFS. PipeFS is a new FS that handles all anonymous and
named pipes. However, named pipes still reside on the (M)FS, as they are part
of the file system on disk. To make this work VFS now has a concept of
'mapped' inodes, which causes read, write, truncate and stat requests to be
redirected to the mapped FS, and all other requests to the original FS.
2009-12-20 21:27:14 +01:00
|
|
|
|
2013-09-10 20:25:01 +02:00
|
|
|
/* Grant access to the buffer even if no I/O happens with the ioctl,
|
|
|
|
* although now that we no longer identify responses based on grants,
|
|
|
|
* this is not strictly necessary.
|
2012-02-13 16:28:04 +01:00
|
|
|
*/
|
2013-08-30 13:33:56 +02:00
|
|
|
gid = cpf_grant_magic(driver_e, user_e, (vir_bytes) buf, size, access);
|
2012-02-13 16:28:04 +01:00
|
|
|
break;
|
2006-06-20 12:12:09 +02:00
|
|
|
|
2013-08-30 13:33:56 +02:00
|
|
|
default:
|
|
|
|
panic("VFS: unknown operation %d", op);
|
2012-02-13 16:28:04 +01:00
|
|
|
}
|
2006-06-20 12:12:09 +02:00
|
|
|
|
2013-08-30 13:33:56 +02:00
|
|
|
if (!GRANT_VALID(gid))
|
|
|
|
panic("VFS: cpf_grant_magic failed");
|
|
|
|
|
|
|
|
return gid;
|
2006-06-20 12:12:09 +02:00
|
|
|
}
|
|
|
|
|
2013-10-06 15:58:54 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* cdev_get *
|
|
|
|
*===========================================================================*/
|
|
|
|
static struct dmap *cdev_get(dev_t dev, devminor_t *minor_dev)
|
|
|
|
{
|
|
|
|
/* Obtain the dmap structure for the given device, if a valid driver exists for
|
|
|
|
* the major device. Perform redirection for CTTY_MAJOR.
|
|
|
|
*/
|
|
|
|
devmajor_t major_dev;
|
|
|
|
struct dmap *dp;
|
|
|
|
int slot;
|
|
|
|
|
|
|
|
/* First cover one special case: /dev/tty, the magic device that translates
|
|
|
|
* to the controlling tty.
|
|
|
|
*/
|
|
|
|
if (major(dev) == CTTY_MAJOR) {
|
|
|
|
/* No controlling terminal? Fail the request. */
|
|
|
|
if (fp->fp_tty == 0) return(NULL);
|
|
|
|
|
|
|
|
/* Substitute the controlling terminal device. */
|
|
|
|
dev = fp->fp_tty;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Determine task dmap. */
|
|
|
|
major_dev = major(dev);
|
|
|
|
if (major_dev < 0 || major_dev >= NR_DEVICES) return(NULL);
|
|
|
|
|
|
|
|
dp = &dmap[major_dev];
|
|
|
|
|
|
|
|
/* See if driver is roughly valid. */
|
|
|
|
if (dp->dmap_driver == NONE) return(NULL);
|
|
|
|
|
|
|
|
if (isokendpt(dp->dmap_driver, &slot) != OK) {
|
|
|
|
printf("VFS: cdev_get: old driver for major %x (%d)\n", major_dev,
|
|
|
|
dp->dmap_driver);
|
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Also return the (possibly redirected) minor number. */
|
|
|
|
*minor_dev = minor(dev);
|
|
|
|
return dp;
|
|
|
|
}
|
2013-08-30 13:33:56 +02:00
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
/*===========================================================================*
|
2013-09-10 20:25:01 +02:00
|
|
|
* cdev_io *
|
2005-04-21 16:53:53 +02:00
|
|
|
*===========================================================================*/
|
2013-09-10 20:25:01 +02:00
|
|
|
int cdev_io(
|
|
|
|
int op, /* CDEV_READ, CDEV_WRITE, or CDEV_IOCTL */
|
2010-04-13 12:58:41 +02:00
|
|
|
dev_t dev, /* major-minor device number */
|
2013-08-30 13:33:56 +02:00
|
|
|
endpoint_t proc_e, /* in whose address space is buf? */
|
2010-04-13 12:58:41 +02:00
|
|
|
void *buf, /* virtual address of the buffer */
|
2013-03-25 17:08:04 +01:00
|
|
|
off_t pos, /* byte position */
|
2013-09-10 20:25:01 +02:00
|
|
|
unsigned long bytes, /* how many bytes to transfer, or request */
|
2013-09-10 16:06:37 +02:00
|
|
|
int flags /* special flags, like O_NONBLOCK */
|
2010-04-13 12:58:41 +02:00
|
|
|
)
|
2005-04-21 16:53:53 +02:00
|
|
|
{
|
2013-09-10 20:25:01 +02:00
|
|
|
/* Initiate a read, write, or ioctl to a character device. */
|
2013-10-06 15:58:54 +02:00
|
|
|
devminor_t minor_dev;
|
2005-04-21 16:53:53 +02:00
|
|
|
struct dmap *dp;
|
|
|
|
message dev_mess;
|
2013-08-30 13:33:56 +02:00
|
|
|
cp_grant_id_t gid;
|
2013-10-06 15:58:54 +02:00
|
|
|
int r;
|
2013-08-30 13:33:56 +02:00
|
|
|
|
2013-09-10 20:25:01 +02:00
|
|
|
assert(op == CDEV_READ || op == CDEV_WRITE || op == CDEV_IOCTL);
|
2006-11-27 15:21:43 +01:00
|
|
|
|
2013-10-06 15:58:54 +02:00
|
|
|
/* Determine task map. */
|
|
|
|
if ((dp = cdev_get(dev, &minor_dev)) == NULL)
|
|
|
|
return(EIO);
|
2005-10-05 17:38:15 +02:00
|
|
|
|
2013-08-30 13:33:56 +02:00
|
|
|
/* Create a grant for the buffer provided by the user process. */
|
|
|
|
gid = make_grant(dp->dmap_driver, proc_e, op, buf, bytes);
|
2012-02-20 14:19:29 +01:00
|
|
|
|
2013-08-30 13:33:56 +02:00
|
|
|
/* Set up the rest of the message that will be sent to the driver. */
|
2013-09-10 12:19:08 +02:00
|
|
|
memset(&dev_mess, 0, sizeof(dev_mess));
|
2013-09-10 20:25:01 +02:00
|
|
|
dev_mess.m_type = op;
|
|
|
|
dev_mess.CDEV_MINOR = minor_dev;
|
|
|
|
if (op == CDEV_IOCTL) {
|
|
|
|
dev_mess.CDEV_REQUEST = bytes;
|
|
|
|
dev_mess.CDEV_USER = proc_e;
|
2013-08-30 13:33:56 +02:00
|
|
|
} else {
|
2013-09-10 20:25:01 +02:00
|
|
|
dev_mess.CDEV_POS_LO = ex64lo(pos);
|
|
|
|
dev_mess.CDEV_POS_HI = ex64hi(pos);
|
|
|
|
dev_mess.CDEV_COUNT = (size_t) bytes;
|
2013-08-30 13:33:56 +02:00
|
|
|
}
|
2013-09-10 20:25:01 +02:00
|
|
|
dev_mess.CDEV_ID = proc_e;
|
|
|
|
dev_mess.CDEV_GRANT = gid;
|
|
|
|
dev_mess.CDEV_FLAGS = 0;
|
2012-02-20 14:19:29 +01:00
|
|
|
if (flags & O_NONBLOCK)
|
2013-09-10 20:25:01 +02:00
|
|
|
dev_mess.CDEV_FLAGS |= CDEV_NONBLOCK;
|
2006-06-20 12:12:09 +02:00
|
|
|
|
2013-08-30 13:33:56 +02:00
|
|
|
/* Send the request to the driver. */
|
2013-10-06 15:58:54 +02:00
|
|
|
if ((r = asynsend3(dp->dmap_driver, &dev_mess, AMF_NOREPLY)) != OK)
|
|
|
|
panic("VFS: asynsend in cdev_io failed: %d", r);
|
2006-06-20 12:12:09 +02:00
|
|
|
|
2013-08-30 13:33:56 +02:00
|
|
|
/* Suspend the calling process until a reply arrives. */
|
|
|
|
wait_for(dp->dmap_driver);
|
|
|
|
assert(!GRANT_VALID(fp->fp_grant));
|
|
|
|
fp->fp_grant = gid; /* revoke this when unsuspended. */
|
2006-06-20 12:12:09 +02:00
|
|
|
|
2013-08-30 13:33:56 +02:00
|
|
|
return SUSPEND;
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
|
2013-09-10 12:19:08 +02:00
|
|
|
|
|
|
|
/*===========================================================================*
|
2013-10-06 15:58:54 +02:00
|
|
|
* cdev_clone *
|
2013-09-10 12:19:08 +02:00
|
|
|
*===========================================================================*/
|
2013-10-06 15:58:54 +02:00
|
|
|
static int cdev_clone(dev_t dev, devminor_t new_minor)
|
2013-09-10 12:19:08 +02:00
|
|
|
{
|
|
|
|
/* A new minor device number has been returned. Request PFS to create a
|
|
|
|
* temporary device file to hold it.
|
|
|
|
*/
|
|
|
|
struct vnode *vp;
|
|
|
|
struct node_details res;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
/* Device number of the new device. */
|
|
|
|
dev = makedev(major(dev), new_minor);
|
|
|
|
|
|
|
|
/* Issue request */
|
|
|
|
r = req_newnode(PFS_PROC_NR, fp->fp_effuid, fp->fp_effgid,
|
|
|
|
ALL_MODES | I_CHAR_SPECIAL, dev, &res);
|
|
|
|
if (r != OK) {
|
2013-10-06 15:58:54 +02:00
|
|
|
(void) cdev_opcl(CDEV_CLOSE, dev, 0);
|
2013-09-10 12:19:08 +02:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Drop old node and use the new values */
|
|
|
|
if ((vp = get_free_vnode()) == NULL) {
|
|
|
|
req_putnode(PFS_PROC_NR, res.inode_nr, 1); /* is this right? */
|
2013-10-06 15:58:54 +02:00
|
|
|
(void) cdev_opcl(CDEV_CLOSE, dev, 0);
|
2013-09-10 12:19:08 +02:00
|
|
|
return(err_code);
|
|
|
|
}
|
|
|
|
lock_vnode(vp, VNODE_OPCL);
|
|
|
|
|
2013-09-10 16:06:37 +02:00
|
|
|
assert(fp->fp_filp[scratch(fp).file.fd_nr] != NULL);
|
2013-09-10 12:19:08 +02:00
|
|
|
unlock_vnode(fp->fp_filp[scratch(fp).file.fd_nr]->filp_vno);
|
|
|
|
put_vnode(fp->fp_filp[scratch(fp).file.fd_nr]->filp_vno);
|
|
|
|
|
|
|
|
vp->v_fs_e = res.fs_e;
|
|
|
|
vp->v_vmnt = NULL;
|
|
|
|
vp->v_dev = NO_DEV;
|
|
|
|
vp->v_fs_e = res.fs_e;
|
|
|
|
vp->v_inode_nr = res.inode_nr;
|
|
|
|
vp->v_mode = res.fmode;
|
|
|
|
vp->v_sdev = dev;
|
|
|
|
vp->v_fs_count = 1;
|
|
|
|
vp->v_ref_count = 1;
|
|
|
|
fp->fp_filp[scratch(fp).file.fd_nr]->filp_vno = vp;
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
/*===========================================================================*
|
2013-10-06 15:58:54 +02:00
|
|
|
* cdev_opcl *
|
2005-04-21 16:53:53 +02:00
|
|
|
*===========================================================================*/
|
2013-10-06 15:58:54 +02:00
|
|
|
static int cdev_opcl(
|
2013-09-10 20:25:01 +02:00
|
|
|
int op, /* operation, CDEV_OPEN or CDEV_CLOSE */
|
2010-04-13 12:58:41 +02:00
|
|
|
dev_t dev, /* device to open or close */
|
|
|
|
int flags /* mode bits and flags */
|
|
|
|
)
|
2005-04-21 16:53:53 +02:00
|
|
|
{
|
2013-10-06 15:58:54 +02:00
|
|
|
/* Open or close a character device. */
|
2013-09-10 20:25:01 +02:00
|
|
|
devminor_t minor_dev, new_minor;
|
2005-04-21 16:53:53 +02:00
|
|
|
struct dmap *dp;
|
2013-10-06 15:58:54 +02:00
|
|
|
struct fproc *rfp;
|
2005-04-21 16:53:53 +02:00
|
|
|
message dev_mess;
|
2013-09-10 20:25:01 +02:00
|
|
|
int r, r2;
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2013-10-06 15:58:54 +02:00
|
|
|
assert(op == CDEV_OPEN || op == CDEV_CLOSE);
|
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
/* Determine task dmap. */
|
2013-10-06 15:58:54 +02:00
|
|
|
if ((dp = cdev_get(dev, &minor_dev)) == NULL)
|
|
|
|
return(ENXIO);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2013-10-06 15:58:54 +02:00
|
|
|
/* CTTY exception: do not actually send the open/close request for /dev/tty
|
|
|
|
* to the driver. This avoids the case that the actual device will remain
|
|
|
|
* open forever if the process calls setsid() after opening /dev/tty.
|
|
|
|
*/
|
|
|
|
if (major(dev) == CTTY_MAJOR) return(OK);
|
|
|
|
|
|
|
|
/* Add O_NOCTTY to the access flags if this process is not a session leader,
|
|
|
|
* or if it already has a controlling tty, or if it is someone else's
|
|
|
|
* controlling tty. For performance reasons, only search the full process
|
|
|
|
* table if this driver has set controlling ttys before.
|
|
|
|
*/
|
|
|
|
if (!(fp->fp_flags & FP_SESLDR) || fp->fp_tty != 0) {
|
|
|
|
flags |= O_NOCTTY;
|
|
|
|
} else if (!(flags & O_NOCTTY) && dp->dmap_seen_tty) {
|
|
|
|
for (rfp = &fproc[0]; rfp < &fproc[NR_PROCS]; rfp++)
|
|
|
|
if (rfp->fp_pid != PID_FREE && rfp->fp_tty == dev)
|
|
|
|
flags |= O_NOCTTY;
|
|
|
|
}
|
Split block/character protocols and libdriver
This patch separates the character and block driver communication
protocols. The old character protocol remains the same, but a new
block protocol is introduced. The libdriver library is replaced by
two new libraries: libchardriver and libblockdriver. Their exposed
API, and drivers that use them, have been updated accordingly.
Together, libbdev and libblockdriver now completely abstract away
the message format used by the block protocol. As the memory driver
is both a character and a block device driver, it now implements its
own message loop.
The most important semantic change made to the block protocol is that
it is no longer possible to return both partial results and an error
for a single transfer. This simplifies the interaction between the
caller and the driver, as the I/O vector no longer needs to be copied
back. Also, drivers are now no longer supposed to decide based on the
layout of the I/O vector when a transfer should be cut short. Put
simply, transfers are now supposed to either succeed completely, or
result in an error.
After this patch, the state of the various pieces is as follows:
- block protocol: stable
- libbdev API: stable for synchronous communication
- libblockdriver API: needs slight revision (the drvlib/partition API
in particular; the threading API will also change shortly)
- character protocol: needs cleanup
- libchardriver API: needs cleanup accordingly
- driver restarts: largely unsupported until endpoint changes are
reintroduced
As a side effect, this patch eliminates several bugs, hacks, and gcc
-Wall and -W warnings all over the place. It probably introduces a
few new ones, too.
Update warning: this patch changes the protocol between MFS and disk
drivers, so in order to use old/new images, the MFS from the ramdisk
must be used to mount all file systems.
2011-11-22 13:27:53 +01:00
|
|
|
|
2013-09-10 12:19:08 +02:00
|
|
|
/* Prepare the request message. */
|
|
|
|
memset(&dev_mess, 0, sizeof(dev_mess));
|
2013-08-30 11:14:03 +02:00
|
|
|
|
2013-09-10 12:19:08 +02:00
|
|
|
dev_mess.m_type = op;
|
2013-09-10 20:25:01 +02:00
|
|
|
dev_mess.CDEV_MINOR = minor_dev;
|
2013-10-06 15:58:54 +02:00
|
|
|
dev_mess.CDEV_ID = who_e;
|
2013-09-10 20:25:01 +02:00
|
|
|
if (op == CDEV_OPEN) {
|
2013-10-06 15:58:54 +02:00
|
|
|
dev_mess.CDEV_USER = who_e;
|
2013-09-10 20:25:01 +02:00
|
|
|
dev_mess.CDEV_ACCESS = 0;
|
|
|
|
if (flags & R_BIT) dev_mess.CDEV_ACCESS |= CDEV_R_BIT;
|
|
|
|
if (flags & W_BIT) dev_mess.CDEV_ACCESS |= CDEV_W_BIT;
|
|
|
|
if (flags & O_NOCTTY) dev_mess.CDEV_ACCESS |= CDEV_NOCTTY;
|
|
|
|
}
|
2013-08-30 11:14:03 +02:00
|
|
|
|
2013-10-06 15:58:54 +02:00
|
|
|
/* Send the request to the driver. */
|
|
|
|
if ((r = asynsend3(dp->dmap_driver, &dev_mess, AMF_NOREPLY)) != OK)
|
|
|
|
panic("VFS: asynsend in cdev_opcl failed: %d", r);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2013-09-10 16:06:37 +02:00
|
|
|
/* Block the thread waiting for a reply. */
|
|
|
|
fp->fp_task = dp->dmap_driver;
|
|
|
|
self->w_task = dp->dmap_driver;
|
|
|
|
self->w_drv_sendrec = &dev_mess;
|
2013-08-24 12:29:39 +02:00
|
|
|
|
2013-09-10 16:06:37 +02:00
|
|
|
worker_wait();
|
2013-08-24 12:29:39 +02:00
|
|
|
|
2013-09-10 16:06:37 +02:00
|
|
|
self->w_task = NONE;
|
|
|
|
self->w_drv_sendrec = NULL;
|
2012-02-13 16:28:04 +01:00
|
|
|
|
2013-10-06 15:58:54 +02:00
|
|
|
/* Process the reply. */
|
2013-09-10 20:25:01 +02:00
|
|
|
r = dev_mess.CDEV_STATUS;
|
|
|
|
|
|
|
|
if (op == CDEV_OPEN && r >= 0) {
|
2013-10-06 15:58:54 +02:00
|
|
|
/* Some devices need special processing upon open. Such a device is
|
|
|
|
* "cloned", i.e. on a succesful open it is replaced by a new device
|
|
|
|
* with a new unique minor device number. This new device number
|
|
|
|
* identifies a new object (such as a new network connection) that has
|
|
|
|
* been allocated within a driver.
|
|
|
|
*/
|
2013-09-10 20:25:01 +02:00
|
|
|
if (r & CDEV_CLONED) {
|
|
|
|
new_minor = r & ~(CDEV_CLONED | CDEV_CTTY);
|
2013-10-06 15:58:54 +02:00
|
|
|
if ((r2 = cdev_clone(dev, new_minor)) < 0)
|
|
|
|
return(r2);
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
|
2013-10-06 15:58:54 +02:00
|
|
|
/* Did this call make the tty the controlling tty? */
|
|
|
|
if (r & CDEV_CTTY) {
|
|
|
|
fp->fp_tty = dev;
|
|
|
|
dp->dmap_seen_tty = TRUE;
|
|
|
|
}
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
r = OK;
|
|
|
|
}
|
2012-02-13 16:28:04 +01:00
|
|
|
|
2013-10-06 15:58:54 +02:00
|
|
|
/* Return the result from the driver. */
|
2005-04-21 16:53:53 +02:00
|
|
|
return(r);
|
|
|
|
}
|
|
|
|
|
- Introduce support for sticky bit.
- Revise VFS-FS protocol and update VFS/MFS/ISOFS accordingly.
- Clean up MFS by removing old, dead code (backwards compatibility is broken by
the new VFS-FS protocol, anyway) and rewrite other parts. Also, make sure all
functions have proper banners and prototypes.
- VFS should always provide a (syntactically) valid path to the FS; no need for
the FS to do sanity checks when leaving/entering mount points.
- Fix several bugs in MFS:
- Several path lookup bugs in MFS.
- A link can be too big for the path buffer.
- A mountpoint can become inaccessible when the creation of a new inode
fails, because the inode already exists and is a mountpoint.
- Introduce support for supplemental groups.
- Add test 46 to test supplemental group functionality (and removed obsolete
suppl. tests from test 2).
- Clean up VFS (not everything is done yet).
- ISOFS now opens device read-only. This makes the -r flag in the mount command
unnecessary (but will still report to be mounted read-write).
- Introduce PipeFS. PipeFS is a new FS that handles all anonymous and
named pipes. However, named pipes still reside on the (M)FS, as they are part
of the file system on disk. To make this work VFS now has a concept of
'mapped' inodes, which causes read, write, truncate and stat requests to be
redirected to the mapped FS, and all other requests to the original FS.
2009-12-20 21:27:14 +01:00
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
/*===========================================================================*
|
2013-10-06 15:58:54 +02:00
|
|
|
* cdev_open *
|
2005-04-21 16:53:53 +02:00
|
|
|
*===========================================================================*/
|
2013-10-06 15:58:54 +02:00
|
|
|
int cdev_open(dev_t dev, int flags)
|
2005-04-21 16:53:53 +02:00
|
|
|
{
|
2013-10-06 15:58:54 +02:00
|
|
|
/* Open a character device. */
|
Split block/character protocols and libdriver
This patch separates the character and block driver communication
protocols. The old character protocol remains the same, but a new
block protocol is introduced. The libdriver library is replaced by
two new libraries: libchardriver and libblockdriver. Their exposed
API, and drivers that use them, have been updated accordingly.
Together, libbdev and libblockdriver now completely abstract away
the message format used by the block protocol. As the memory driver
is both a character and a block device driver, it now implements its
own message loop.
The most important semantic change made to the block protocol is that
it is no longer possible to return both partial results and an error
for a single transfer. This simplifies the interaction between the
caller and the driver, as the I/O vector no longer needs to be copied
back. Also, drivers are now no longer supposed to decide based on the
layout of the I/O vector when a transfer should be cut short. Put
simply, transfers are now supposed to either succeed completely, or
result in an error.
After this patch, the state of the various pieces is as follows:
- block protocol: stable
- libbdev API: stable for synchronous communication
- libblockdriver API: needs slight revision (the drvlib/partition API
in particular; the threading API will also change shortly)
- character protocol: needs cleanup
- libchardriver API: needs cleanup accordingly
- driver restarts: largely unsupported until endpoint changes are
reintroduced
As a side effect, this patch eliminates several bugs, hacks, and gcc
-Wall and -W warnings all over the place. It probably introduces a
few new ones, too.
Update warning: this patch changes the protocol between MFS and disk
drivers, so in order to use old/new images, the MFS from the ramdisk
must be used to mount all file systems.
2011-11-22 13:27:53 +01:00
|
|
|
|
2013-10-06 15:58:54 +02:00
|
|
|
return cdev_opcl(CDEV_OPEN, dev, flags);
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
|
- Introduce support for sticky bit.
- Revise VFS-FS protocol and update VFS/MFS/ISOFS accordingly.
- Clean up MFS by removing old, dead code (backwards compatibility is broken by
the new VFS-FS protocol, anyway) and rewrite other parts. Also, make sure all
functions have proper banners and prototypes.
- VFS should always provide a (syntactically) valid path to the FS; no need for
the FS to do sanity checks when leaving/entering mount points.
- Fix several bugs in MFS:
- Several path lookup bugs in MFS.
- A link can be too big for the path buffer.
- A mountpoint can become inaccessible when the creation of a new inode
fails, because the inode already exists and is a mountpoint.
- Introduce support for supplemental groups.
- Add test 46 to test supplemental group functionality (and removed obsolete
suppl. tests from test 2).
- Clean up VFS (not everything is done yet).
- ISOFS now opens device read-only. This makes the -r flag in the mount command
unnecessary (but will still report to be mounted read-write).
- Introduce PipeFS. PipeFS is a new FS that handles all anonymous and
named pipes. However, named pipes still reside on the (M)FS, as they are part
of the file system on disk. To make this work VFS now has a concept of
'mapped' inodes, which causes read, write, truncate and stat requests to be
redirected to the mapped FS, and all other requests to the original FS.
2009-12-20 21:27:14 +01:00
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
/*===========================================================================*
|
2013-10-06 15:58:54 +02:00
|
|
|
* cdev_close *
|
2005-04-21 16:53:53 +02:00
|
|
|
*===========================================================================*/
|
2013-10-06 15:58:54 +02:00
|
|
|
int cdev_close(dev_t dev)
|
2005-04-21 16:53:53 +02:00
|
|
|
{
|
2013-10-06 15:58:54 +02:00
|
|
|
/* Close a character device. */
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2013-10-06 15:58:54 +02:00
|
|
|
return cdev_opcl(CDEV_CLOSE, dev, 0);
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
|
- Introduce support for sticky bit.
- Revise VFS-FS protocol and update VFS/MFS/ISOFS accordingly.
- Clean up MFS by removing old, dead code (backwards compatibility is broken by
the new VFS-FS protocol, anyway) and rewrite other parts. Also, make sure all
functions have proper banners and prototypes.
- VFS should always provide a (syntactically) valid path to the FS; no need for
the FS to do sanity checks when leaving/entering mount points.
- Fix several bugs in MFS:
- Several path lookup bugs in MFS.
- A link can be too big for the path buffer.
- A mountpoint can become inaccessible when the creation of a new inode
fails, because the inode already exists and is a mountpoint.
- Introduce support for supplemental groups.
- Add test 46 to test supplemental group functionality (and removed obsolete
suppl. tests from test 2).
- Clean up VFS (not everything is done yet).
- ISOFS now opens device read-only. This makes the -r flag in the mount command
unnecessary (but will still report to be mounted read-write).
- Introduce PipeFS. PipeFS is a new FS that handles all anonymous and
named pipes. However, named pipes still reside on the (M)FS, as they are part
of the file system on disk. To make this work VFS now has a concept of
'mapped' inodes, which causes read, write, truncate and stat requests to be
redirected to the mapped FS, and all other requests to the original FS.
2009-12-20 21:27:14 +01:00
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* do_ioctl *
|
|
|
|
*===========================================================================*/
|
2013-04-12 18:41:23 +02:00
|
|
|
int do_ioctl(message *UNUSED(m_out))
|
2005-04-21 16:53:53 +02:00
|
|
|
{
|
2012-04-13 14:50:38 +02:00
|
|
|
/* Perform the ioctl(ls_fd, request, argx) system call */
|
2013-09-10 12:19:08 +02:00
|
|
|
unsigned long ioctlrequest;
|
2013-09-10 16:06:37 +02:00
|
|
|
int r = OK;
|
2005-04-21 16:53:53 +02:00
|
|
|
struct filp *f;
|
2006-10-25 15:40:36 +02:00
|
|
|
register struct vnode *vp;
|
2005-04-21 16:53:53 +02:00
|
|
|
dev_t dev;
|
2012-04-13 14:50:38 +02:00
|
|
|
void *argx;
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2013-08-30 11:14:03 +02:00
|
|
|
scratch(fp).file.fd_nr = job_m_in.VFS_IOCTL_FD;
|
|
|
|
ioctlrequest = job_m_in.VFS_IOCTL_REQ;
|
|
|
|
argx = job_m_in.VFS_IOCTL_ARG;
|
2012-02-13 16:28:04 +01:00
|
|
|
|
|
|
|
if ((f = get_filp(scratch(fp).file.fd_nr, VNODE_READ)) == NULL)
|
|
|
|
return(err_code);
|
2006-10-25 15:40:36 +02:00
|
|
|
vp = f->filp_vno; /* get vnode pointer */
|
2012-04-25 14:44:42 +02:00
|
|
|
if (!S_ISCHR(vp->v_mode) && !S_ISBLK(vp->v_mode)) {
|
2012-02-13 16:28:04 +01:00
|
|
|
r = ENOTTY;
|
|
|
|
}
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2012-02-13 16:28:04 +01:00
|
|
|
if (r == OK) {
|
|
|
|
dev = (dev_t) vp->v_sdev;
|
Split block/character protocols and libdriver
This patch separates the character and block driver communication
protocols. The old character protocol remains the same, but a new
block protocol is introduced. The libdriver library is replaced by
two new libraries: libchardriver and libblockdriver. Their exposed
API, and drivers that use them, have been updated accordingly.
Together, libbdev and libblockdriver now completely abstract away
the message format used by the block protocol. As the memory driver
is both a character and a block device driver, it now implements its
own message loop.
The most important semantic change made to the block protocol is that
it is no longer possible to return both partial results and an error
for a single transfer. This simplifies the interaction between the
caller and the driver, as the I/O vector no longer needs to be copied
back. Also, drivers are now no longer supposed to decide based on the
layout of the I/O vector when a transfer should be cut short. Put
simply, transfers are now supposed to either succeed completely, or
result in an error.
After this patch, the state of the various pieces is as follows:
- block protocol: stable
- libbdev API: stable for synchronous communication
- libblockdriver API: needs slight revision (the drvlib/partition API
in particular; the threading API will also change shortly)
- character protocol: needs cleanup
- libchardriver API: needs cleanup accordingly
- driver restarts: largely unsupported until endpoint changes are
reintroduced
As a side effect, this patch eliminates several bugs, hacks, and gcc
-Wall and -W warnings all over the place. It probably introduces a
few new ones, too.
Update warning: this patch changes the protocol between MFS and disk
drivers, so in order to use old/new images, the MFS from the ramdisk
must be used to mount all file systems.
2011-11-22 13:27:53 +01:00
|
|
|
|
2013-10-05 12:50:44 +02:00
|
|
|
if (S_ISBLK(vp->v_mode)) {
|
|
|
|
f->filp_ioctl_fp = fp;
|
|
|
|
|
2012-04-13 14:50:38 +02:00
|
|
|
r = bdev_ioctl(dev, who_e, ioctlrequest, argx);
|
2013-10-05 12:50:44 +02:00
|
|
|
|
|
|
|
f->filp_ioctl_fp = NULL;
|
|
|
|
} else
|
2013-09-10 20:25:01 +02:00
|
|
|
r = cdev_io(CDEV_IOCTL, dev, who_e, argx, 0, ioctlrequest,
|
|
|
|
f->filp_flags);
|
2012-02-13 16:28:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
unlock_filp(f);
|
|
|
|
|
|
|
|
return(r);
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
|
- Introduce support for sticky bit.
- Revise VFS-FS protocol and update VFS/MFS/ISOFS accordingly.
- Clean up MFS by removing old, dead code (backwards compatibility is broken by
the new VFS-FS protocol, anyway) and rewrite other parts. Also, make sure all
functions have proper banners and prototypes.
- VFS should always provide a (syntactically) valid path to the FS; no need for
the FS to do sanity checks when leaving/entering mount points.
- Fix several bugs in MFS:
- Several path lookup bugs in MFS.
- A link can be too big for the path buffer.
- A mountpoint can become inaccessible when the creation of a new inode
fails, because the inode already exists and is a mountpoint.
- Introduce support for supplemental groups.
- Add test 46 to test supplemental group functionality (and removed obsolete
suppl. tests from test 2).
- Clean up VFS (not everything is done yet).
- ISOFS now opens device read-only. This makes the -r flag in the mount command
unnecessary (but will still report to be mounted read-write).
- Introduce PipeFS. PipeFS is a new FS that handles all anonymous and
named pipes. However, named pipes still reside on the (M)FS, as they are part
of the file system on disk. To make this work VFS now has a concept of
'mapped' inodes, which causes read, write, truncate and stat requests to be
redirected to the mapped FS, and all other requests to the original FS.
2009-12-20 21:27:14 +01:00
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
/*===========================================================================*
|
2013-09-10 20:25:01 +02:00
|
|
|
* cdev_select *
|
2005-04-21 16:53:53 +02:00
|
|
|
*===========================================================================*/
|
2013-09-10 20:25:01 +02:00
|
|
|
int cdev_select(dev_t dev, int ops)
|
2005-04-21 16:53:53 +02:00
|
|
|
{
|
2013-08-30 13:33:56 +02:00
|
|
|
/* Initiate a select call on a device. Return OK iff the request was sent. */
|
2013-09-10 12:19:08 +02:00
|
|
|
devminor_t minor_dev;
|
2013-08-30 13:33:56 +02:00
|
|
|
message dev_mess;
|
|
|
|
struct dmap *dp;
|
2013-10-06 15:58:54 +02:00
|
|
|
int r;
|
2013-08-30 13:33:56 +02:00
|
|
|
|
2013-10-06 15:58:54 +02:00
|
|
|
/* Determine task dmap. */
|
|
|
|
if ((dp = cdev_get(dev, &minor_dev)) == NULL)
|
|
|
|
return(EIO);
|
2013-08-30 13:33:56 +02:00
|
|
|
|
2013-10-06 15:58:54 +02:00
|
|
|
/* Prepare the request message. */
|
2013-08-30 13:33:56 +02:00
|
|
|
memset(&dev_mess, 0, sizeof(dev_mess));
|
|
|
|
|
2013-09-10 20:25:01 +02:00
|
|
|
dev_mess.m_type = CDEV_SELECT;
|
|
|
|
dev_mess.CDEV_MINOR = minor_dev;
|
|
|
|
dev_mess.CDEV_OPS = ops;
|
2013-08-30 13:33:56 +02:00
|
|
|
|
2013-10-06 15:58:54 +02:00
|
|
|
/* Send the request to the driver. */
|
|
|
|
if ((r = asynsend3(dp->dmap_driver, &dev_mess, AMF_NOREPLY)) != OK)
|
|
|
|
panic("VFS: asynsend in cdev_select failed: %d", r);
|
|
|
|
|
|
|
|
return(OK);
|
2013-08-30 13:33:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*===========================================================================*
|
2013-09-10 20:25:01 +02:00
|
|
|
* cdev_cancel *
|
2013-08-30 13:33:56 +02:00
|
|
|
*===========================================================================*/
|
2013-09-10 20:25:01 +02:00
|
|
|
int cdev_cancel(dev_t dev)
|
2013-08-30 13:33:56 +02:00
|
|
|
{
|
|
|
|
/* Cancel an I/O request, blocking until it has been cancelled. */
|
2013-09-10 12:19:08 +02:00
|
|
|
devminor_t minor_dev;
|
2013-08-30 13:33:56 +02:00
|
|
|
message dev_mess;
|
|
|
|
struct dmap *dp;
|
2013-09-10 12:19:08 +02:00
|
|
|
int r;
|
2013-08-30 13:33:56 +02:00
|
|
|
|
2013-10-06 15:58:54 +02:00
|
|
|
/* Determine task dmap. */
|
|
|
|
if ((dp = cdev_get(dev, &minor_dev)) == NULL)
|
|
|
|
return(EIO);
|
2013-08-30 13:33:56 +02:00
|
|
|
|
2013-10-06 15:58:54 +02:00
|
|
|
/* Prepare the request message. */
|
2013-08-30 13:33:56 +02:00
|
|
|
memset(&dev_mess, 0, sizeof(dev_mess));
|
|
|
|
|
2013-09-10 20:25:01 +02:00
|
|
|
dev_mess.m_type = CDEV_CANCEL;
|
|
|
|
dev_mess.CDEV_MINOR = minor_dev;
|
|
|
|
dev_mess.CDEV_ID = fp->fp_endpoint;
|
2013-08-30 13:33:56 +02:00
|
|
|
|
2013-10-06 15:58:54 +02:00
|
|
|
/* Send the request to the driver. */
|
|
|
|
if ((r = asynsend3(dp->dmap_driver, &dev_mess, AMF_NOREPLY)) != OK)
|
|
|
|
panic("VFS: asynsend in cdev_cancel failed: %d", r);
|
2013-08-30 13:33:56 +02:00
|
|
|
|
|
|
|
/* Suspend this thread until we have received the response. */
|
|
|
|
fp->fp_task = dp->dmap_driver;
|
|
|
|
self->w_task = dp->dmap_driver;
|
|
|
|
self->w_drv_sendrec = &dev_mess;
|
|
|
|
|
|
|
|
worker_wait();
|
|
|
|
|
|
|
|
self->w_task = NONE;
|
|
|
|
self->w_drv_sendrec = NULL;
|
|
|
|
|
|
|
|
/* Clean up and return the result (note: the request may have completed). */
|
|
|
|
if (GRANT_VALID(fp->fp_grant)) {
|
|
|
|
(void) cpf_revoke(fp->fp_grant);
|
|
|
|
fp->fp_grant = GRANT_INVALID;
|
|
|
|
}
|
|
|
|
|
2013-09-10 20:25:01 +02:00
|
|
|
r = dev_mess.CDEV_STATUS;
|
2013-08-30 13:33:56 +02:00
|
|
|
return (r == EAGAIN) ? EINTR : r;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* block_io *
|
|
|
|
*===========================================================================*/
|
|
|
|
static int block_io(endpoint_t driver_e, message *mess_ptr)
|
|
|
|
{
|
|
|
|
/* Perform I/O on a block device. The current thread is suspended until a reply
|
|
|
|
* comes in from the driver.
|
2005-04-21 16:53:53 +02:00
|
|
|
*/
|
2013-08-30 13:33:56 +02:00
|
|
|
int r, status, retry_count;
|
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-08-28 16:06:51 +02:00
|
|
|
message mess_retry;
|
2008-11-19 13:26:10 +01:00
|
|
|
|
2013-08-30 13:33:56 +02:00
|
|
|
assert(IS_BDEV_RQ(mess_ptr->m_type));
|
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-08-28 16:06:51 +02:00
|
|
|
mess_retry = *mess_ptr;
|
|
|
|
retry_count = 0;
|
Split block/character protocols and libdriver
This patch separates the character and block driver communication
protocols. The old character protocol remains the same, but a new
block protocol is introduced. The libdriver library is replaced by
two new libraries: libchardriver and libblockdriver. Their exposed
API, and drivers that use them, have been updated accordingly.
Together, libbdev and libblockdriver now completely abstract away
the message format used by the block protocol. As the memory driver
is both a character and a block device driver, it now implements its
own message loop.
The most important semantic change made to the block protocol is that
it is no longer possible to return both partial results and an error
for a single transfer. This simplifies the interaction between the
caller and the driver, as the I/O vector no longer needs to be copied
back. Also, drivers are now no longer supposed to decide based on the
layout of the I/O vector when a transfer should be cut short. Put
simply, transfers are now supposed to either succeed completely, or
result in an error.
After this patch, the state of the various pieces is as follows:
- block protocol: stable
- libbdev API: stable for synchronous communication
- libblockdriver API: needs slight revision (the drvlib/partition API
in particular; the threading API will also change shortly)
- character protocol: needs cleanup
- libchardriver API: needs cleanup accordingly
- driver restarts: largely unsupported until endpoint changes are
reintroduced
As a side effect, this patch eliminates several bugs, hacks, and gcc
-Wall and -W warnings all over the place. It probably introduces a
few new ones, too.
Update warning: this patch changes the protocol between MFS and disk
drivers, so in order to use old/new images, the MFS from the ramdisk
must be used to mount all file systems.
2011-11-22 13:27:53 +01:00
|
|
|
|
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-08-28 16:06:51 +02:00
|
|
|
do {
|
|
|
|
r = drv_sendrec(driver_e, mess_ptr);
|
2013-10-06 15:58:54 +02:00
|
|
|
if (r != OK)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
status = mess_ptr->BDEV_STATUS;
|
|
|
|
if (status == ERESTART) {
|
|
|
|
r = EDEADEPT;
|
|
|
|
*mess_ptr = mess_retry;
|
|
|
|
retry_count++;
|
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-08-28 16:06:51 +02:00
|
|
|
}
|
2013-02-15 16:00:21 +01:00
|
|
|
} while (status == ERESTART && retry_count < 5);
|
|
|
|
|
|
|
|
/* If we failed to restart the request, return EIO */
|
2013-10-06 15:58:54 +02:00
|
|
|
if (status == ERESTART && retry_count >= 5)
|
|
|
|
return EIO;
|
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-08-28 16:06:51 +02:00
|
|
|
|
2012-02-13 16:28:04 +01:00
|
|
|
if (r != OK) {
|
|
|
|
if (r == EDEADSRCDST || r == EDEADEPT) {
|
|
|
|
printf("VFS: dead driver %d\n", driver_e);
|
|
|
|
dmap_unmap_by_endpt(driver_e);
|
2013-10-06 15:58:54 +02:00
|
|
|
return(EIO);
|
2012-02-13 16:28:04 +01:00
|
|
|
} else if (r == ELOCKED) {
|
|
|
|
printf("VFS: ELOCKED talking to %d\n", driver_e);
|
2013-10-06 15:58:54 +02:00
|
|
|
return(EIO);
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
2013-08-30 13:33:56 +02:00
|
|
|
panic("block_io: can't send/receive: %d", r);
|
2012-02-13 16:28:04 +01:00
|
|
|
}
|
2010-08-30 15:44:07 +02:00
|
|
|
|
- Introduce support for sticky bit.
- Revise VFS-FS protocol and update VFS/MFS/ISOFS accordingly.
- Clean up MFS by removing old, dead code (backwards compatibility is broken by
the new VFS-FS protocol, anyway) and rewrite other parts. Also, make sure all
functions have proper banners and prototypes.
- VFS should always provide a (syntactically) valid path to the FS; no need for
the FS to do sanity checks when leaving/entering mount points.
- Fix several bugs in MFS:
- Several path lookup bugs in MFS.
- A link can be too big for the path buffer.
- A mountpoint can become inaccessible when the creation of a new inode
fails, because the inode already exists and is a mountpoint.
- Introduce support for supplemental groups.
- Add test 46 to test supplemental group functionality (and removed obsolete
suppl. tests from test 2).
- Clean up VFS (not everything is done yet).
- ISOFS now opens device read-only. This makes the -r flag in the mount command
unnecessary (but will still report to be mounted read-write).
- Introduce PipeFS. PipeFS is a new FS that handles all anonymous and
named pipes. However, named pipes still reside on the (M)FS, as they are part
of the file system on disk. To make this work VFS now has a concept of
'mapped' inodes, which causes read, write, truncate and stat requests to be
redirected to the mapped FS, and all other requests to the original FS.
2009-12-20 21:27:14 +01:00
|
|
|
return(OK);
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
|
- Introduce support for sticky bit.
- Revise VFS-FS protocol and update VFS/MFS/ISOFS accordingly.
- Clean up MFS by removing old, dead code (backwards compatibility is broken by
the new VFS-FS protocol, anyway) and rewrite other parts. Also, make sure all
functions have proper banners and prototypes.
- VFS should always provide a (syntactically) valid path to the FS; no need for
the FS to do sanity checks when leaving/entering mount points.
- Fix several bugs in MFS:
- Several path lookup bugs in MFS.
- A link can be too big for the path buffer.
- A mountpoint can become inaccessible when the creation of a new inode
fails, because the inode already exists and is a mountpoint.
- Introduce support for supplemental groups.
- Add test 46 to test supplemental group functionality (and removed obsolete
suppl. tests from test 2).
- Clean up VFS (not everything is done yet).
- ISOFS now opens device read-only. This makes the -r flag in the mount command
unnecessary (but will still report to be mounted read-write).
- Introduce PipeFS. PipeFS is a new FS that handles all anonymous and
named pipes. However, named pipes still reside on the (M)FS, as they are part
of the file system on disk. To make this work VFS now has a concept of
'mapped' inodes, which causes read, write, truncate and stat requests to be
redirected to the mapped FS, and all other requests to the original FS.
2009-12-20 21:27:14 +01:00
|
|
|
|
2005-10-20 21:39:32 +02:00
|
|
|
/*===========================================================================*
|
Split block/character protocols and libdriver
This patch separates the character and block driver communication
protocols. The old character protocol remains the same, but a new
block protocol is introduced. The libdriver library is replaced by
two new libraries: libchardriver and libblockdriver. Their exposed
API, and drivers that use them, have been updated accordingly.
Together, libbdev and libblockdriver now completely abstract away
the message format used by the block protocol. As the memory driver
is both a character and a block device driver, it now implements its
own message loop.
The most important semantic change made to the block protocol is that
it is no longer possible to return both partial results and an error
for a single transfer. This simplifies the interaction between the
caller and the driver, as the I/O vector no longer needs to be copied
back. Also, drivers are now no longer supposed to decide based on the
layout of the I/O vector when a transfer should be cut short. Put
simply, transfers are now supposed to either succeed completely, or
result in an error.
After this patch, the state of the various pieces is as follows:
- block protocol: stable
- libbdev API: stable for synchronous communication
- libblockdriver API: needs slight revision (the drvlib/partition API
in particular; the threading API will also change shortly)
- character protocol: needs cleanup
- libchardriver API: needs cleanup accordingly
- driver restarts: largely unsupported until endpoint changes are
reintroduced
As a side effect, this patch eliminates several bugs, hacks, and gcc
-Wall and -W warnings all over the place. It probably introduces a
few new ones, too.
Update warning: this patch changes the protocol between MFS and disk
drivers, so in order to use old/new images, the MFS from the ramdisk
must be used to mount all file systems.
2011-11-22 13:27:53 +01:00
|
|
|
* bdev_up *
|
2005-10-20 21:39:32 +02:00
|
|
|
*===========================================================================*/
|
2013-09-10 12:19:08 +02:00
|
|
|
void bdev_up(devmajor_t maj)
|
2005-10-20 21:39:32 +02:00
|
|
|
{
|
Split block/character protocols and libdriver
This patch separates the character and block driver communication
protocols. The old character protocol remains the same, but a new
block protocol is introduced. The libdriver library is replaced by
two new libraries: libchardriver and libblockdriver. Their exposed
API, and drivers that use them, have been updated accordingly.
Together, libbdev and libblockdriver now completely abstract away
the message format used by the block protocol. As the memory driver
is both a character and a block device driver, it now implements its
own message loop.
The most important semantic change made to the block protocol is that
it is no longer possible to return both partial results and an error
for a single transfer. This simplifies the interaction between the
caller and the driver, as the I/O vector no longer needs to be copied
back. Also, drivers are now no longer supposed to decide based on the
layout of the I/O vector when a transfer should be cut short. Put
simply, transfers are now supposed to either succeed completely, or
result in an error.
After this patch, the state of the various pieces is as follows:
- block protocol: stable
- libbdev API: stable for synchronous communication
- libblockdriver API: needs slight revision (the drvlib/partition API
in particular; the threading API will also change shortly)
- character protocol: needs cleanup
- libchardriver API: needs cleanup accordingly
- driver restarts: largely unsupported until endpoint changes are
reintroduced
As a side effect, this patch eliminates several bugs, hacks, and gcc
-Wall and -W warnings all over the place. It probably introduces a
few new ones, too.
Update warning: this patch changes the protocol between MFS and disk
drivers, so in order to use old/new images, the MFS from the ramdisk
must be used to mount all file systems.
2011-11-22 13:27:53 +01:00
|
|
|
/* A new block device driver has been mapped in. This may affect both mounted
|
|
|
|
* file systems and open block-special files.
|
|
|
|
*/
|
2011-11-30 19:05:26 +01:00
|
|
|
int r, found, bits;
|
2012-02-13 16:28:04 +01:00
|
|
|
struct filp *rfilp;
|
2008-02-22 16:41:07 +01:00
|
|
|
struct vmnt *vmp;
|
|
|
|
struct vnode *vp;
|
2011-11-30 19:05:26 +01:00
|
|
|
char *label;
|
2008-02-22 16:41:07 +01:00
|
|
|
|
2012-02-13 16:28:04 +01:00
|
|
|
if (maj < 0 || maj >= NR_DEVICES) panic("VFS: out-of-bound major");
|
2011-11-30 19:05:26 +01:00
|
|
|
label = dmap[maj].dmap_label;
|
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-08-28 16:06:51 +02:00
|
|
|
found = 0;
|
2006-10-25 15:40:36 +02:00
|
|
|
|
2011-03-25 11:56:43 +01:00
|
|
|
/* For each block-special file that was previously opened on the affected
|
|
|
|
* device, we need to reopen it on the new driver.
|
|
|
|
*/
|
2012-02-13 16:28:04 +01:00
|
|
|
for (rfilp = filp; rfilp < &filp[NR_FILPS]; rfilp++) {
|
|
|
|
if (rfilp->filp_count < 1 || !(vp = rfilp->filp_vno)) continue;
|
|
|
|
if (major(vp->v_sdev) != maj) continue;
|
|
|
|
if (!S_ISBLK(vp->v_mode)) continue;
|
2011-03-25 11:56:43 +01:00
|
|
|
|
|
|
|
/* Reopen the device on the driver, once per filp. */
|
2013-08-04 14:39:02 +02:00
|
|
|
bits = rfilp->filp_mode & (R_BIT|W_BIT);
|
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-08-28 16:06:51 +02:00
|
|
|
if ((r = bdev_open(vp->v_sdev, bits)) != OK) {
|
2011-03-25 11:56:43 +01:00
|
|
|
printf("VFS: mounted dev %d/%d re-open failed: %d.\n",
|
|
|
|
maj, minor(vp->v_sdev), r);
|
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-08-28 16:06:51 +02:00
|
|
|
dmap[maj].dmap_recovering = 0;
|
|
|
|
return; /* Give up entirely */
|
|
|
|
}
|
2011-03-25 11:56:43 +01:00
|
|
|
|
|
|
|
found = 1;
|
|
|
|
}
|
|
|
|
|
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-08-28 16:06:51 +02:00
|
|
|
/* Tell each affected mounted file system about the new endpoint.
|
|
|
|
*/
|
|
|
|
for (vmp = &vmnt[0]; vmp < &vmnt[NR_MNTS]; ++vmp) {
|
|
|
|
if (major(vmp->m_dev) != maj) continue;
|
|
|
|
|
|
|
|
/* Send the driver label to the mounted file system. */
|
|
|
|
if (OK != req_newdriver(vmp->m_fs_e, vmp->m_dev, label))
|
|
|
|
printf("VFS dev_up: error sending new driver label to %d\n",
|
|
|
|
vmp->m_fs_e);
|
|
|
|
}
|
|
|
|
|
2011-03-25 11:56:43 +01:00
|
|
|
/* If any block-special file was open for this major at all, also inform the
|
2012-02-13 16:28:04 +01:00
|
|
|
* root file system about the new driver. We do this even if the
|
|
|
|
* block-special file is linked to another mounted file system, merely
|
2011-03-25 11:56:43 +01:00
|
|
|
* because it is more work to check for that case.
|
|
|
|
*/
|
|
|
|
if (found) {
|
2011-11-30 19:05:26 +01:00
|
|
|
if (OK != req_newdriver(ROOT_FS_E, makedev(maj, 0), label))
|
|
|
|
printf("VFSdev_up: error sending new driver label to %d\n",
|
2012-02-13 16:28:04 +01:00
|
|
|
ROOT_FS_E);
|
2011-03-25 11:56:43 +01:00
|
|
|
}
|
Split block/character protocols and libdriver
This patch separates the character and block driver communication
protocols. The old character protocol remains the same, but a new
block protocol is introduced. The libdriver library is replaced by
two new libraries: libchardriver and libblockdriver. Their exposed
API, and drivers that use them, have been updated accordingly.
Together, libbdev and libblockdriver now completely abstract away
the message format used by the block protocol. As the memory driver
is both a character and a block device driver, it now implements its
own message loop.
The most important semantic change made to the block protocol is that
it is no longer possible to return both partial results and an error
for a single transfer. This simplifies the interaction between the
caller and the driver, as the I/O vector no longer needs to be copied
back. Also, drivers are now no longer supposed to decide based on the
layout of the I/O vector when a transfer should be cut short. Put
simply, transfers are now supposed to either succeed completely, or
result in an error.
After this patch, the state of the various pieces is as follows:
- block protocol: stable
- libbdev API: stable for synchronous communication
- libblockdriver API: needs slight revision (the drvlib/partition API
in particular; the threading API will also change shortly)
- character protocol: needs cleanup
- libchardriver API: needs cleanup accordingly
- driver restarts: largely unsupported until endpoint changes are
reintroduced
As a side effect, this patch eliminates several bugs, hacks, and gcc
-Wall and -W warnings all over the place. It probably introduces a
few new ones, too.
Update warning: this patch changes the protocol between MFS and disk
drivers, so in order to use old/new images, the MFS from the ramdisk
must be used to mount all file systems.
2011-11-22 13:27:53 +01:00
|
|
|
}
|
|
|
|
|
2011-03-25 11:56:43 +01:00
|
|
|
|
2012-02-13 16:28:04 +01:00
|
|
|
/*===========================================================================*
|
2013-09-10 20:25:01 +02:00
|
|
|
* cdev_generic_reply *
|
2012-02-13 16:28:04 +01:00
|
|
|
*===========================================================================*/
|
2013-09-10 20:25:01 +02:00
|
|
|
static void cdev_generic_reply(message *m_ptr)
|
2012-02-13 16:28:04 +01:00
|
|
|
{
|
2013-09-10 20:25:01 +02:00
|
|
|
/* A character driver has results for an open, close, read, write, or ioctl
|
|
|
|
* call (i.e., everything except select). There may be a thread waiting for
|
|
|
|
* these results as part of an ongoing open, close, or (for read/write/ioctl)
|
|
|
|
* cancel call. If so, wake up that thread; if not, send a reply to the
|
|
|
|
* requesting process. This function MUST NOT block its calling thread.
|
2013-08-30 13:42:51 +02:00
|
|
|
*/
|
2012-02-13 16:28:04 +01:00
|
|
|
struct fproc *rfp;
|
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-08-28 16:06:51 +02:00
|
|
|
struct worker_thread *wp;
|
2012-02-13 16:28:04 +01:00
|
|
|
endpoint_t proc_e;
|
|
|
|
int slot;
|
|
|
|
|
2013-09-10 20:25:01 +02:00
|
|
|
proc_e = m_ptr->CDEV_ID;
|
|
|
|
|
|
|
|
if (m_ptr->CDEV_STATUS == SUSPEND) {
|
|
|
|
printf("VFS: got SUSPEND from %d, not reviving\n", m_ptr->m_source);
|
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-08-28 16:06:51 +02:00
|
|
|
return;
|
|
|
|
}
|
2013-08-30 13:33:56 +02:00
|
|
|
|
2013-09-10 20:25:01 +02:00
|
|
|
if (isokendpt(proc_e, &slot) != OK) {
|
|
|
|
printf("VFS: proc %d from %d not found\n", proc_e, m_ptr->m_source);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
rfp = &fproc[slot];
|
|
|
|
wp = rfp->fp_worker;
|
|
|
|
if (wp != NULL && wp->w_task == who_e) {
|
|
|
|
assert(!fp_is_blocked(rfp));
|
|
|
|
*wp->w_drv_sendrec = *m_ptr;
|
|
|
|
worker_signal(wp); /* Continue open/close/cancel */
|
|
|
|
} else if (rfp->fp_blocked_on != FP_BLOCKED_ON_OTHER ||
|
|
|
|
rfp->fp_task != m_ptr->m_source) {
|
|
|
|
/* This would typically be caused by a protocol error, i.e. a driver
|
|
|
|
* not properly following the character driver protocol rules.
|
2013-08-30 13:33:56 +02:00
|
|
|
*/
|
2013-09-10 20:25:01 +02:00
|
|
|
printf("VFS: proc %d not blocked on %d\n", proc_e, m_ptr->m_source);
|
|
|
|
} else {
|
|
|
|
revive(proc_e, m_ptr->CDEV_STATUS);
|
2013-08-30 13:33:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-30 13:42:51 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* cdev_reply *
|
|
|
|
*===========================================================================*/
|
|
|
|
void cdev_reply(void)
|
|
|
|
{
|
|
|
|
/* A character driver has results for us. */
|
|
|
|
|
2013-09-10 20:25:01 +02:00
|
|
|
if (get_dmap(who_e) == NULL) {
|
|
|
|
printf("VFS: ignoring char dev reply from unknown driver %d\n", who_e);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-08-30 13:42:51 +02:00
|
|
|
switch (call_nr) {
|
2013-09-10 20:25:01 +02:00
|
|
|
case CDEV_REPLY:
|
|
|
|
cdev_generic_reply(&m_in);
|
|
|
|
break;
|
|
|
|
case CDEV_SEL1_REPLY:
|
|
|
|
select_reply1(m_in.m_source, m_in.CDEV_MINOR, m_in.CDEV_STATUS);
|
2013-08-30 13:42:51 +02:00
|
|
|
break;
|
2013-09-10 20:25:01 +02:00
|
|
|
case CDEV_SEL2_REPLY:
|
|
|
|
select_reply2(m_in.m_source, m_in.CDEV_MINOR, m_in.CDEV_STATUS);
|
2013-08-30 13:42:51 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("VFS: char driver %u sent unknown reply %x\n", who_e, call_nr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* bdev_reply *
|
|
|
|
*===========================================================================*/
|
2013-09-10 20:25:01 +02:00
|
|
|
void bdev_reply(void)
|
2013-08-30 13:42:51 +02:00
|
|
|
{
|
|
|
|
/* A block driver has results for a call. There must be a thread waiting for
|
|
|
|
* these results - wake it up. This function MUST NOT block its calling thread.
|
|
|
|
*/
|
2013-09-10 12:19:08 +02:00
|
|
|
struct worker_thread *wp;
|
2013-09-10 20:25:01 +02:00
|
|
|
struct dmap *dp;
|
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-08-28 16:06:51 +02:00
|
|
|
|
2013-09-10 20:25:01 +02:00
|
|
|
if ((dp = get_dmap(who_e)) == NULL) {
|
|
|
|
printf("VFS: ignoring block dev reply from unknown driver %d\n",
|
|
|
|
who_e);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dp->dmap_servicing == INVALID_THREAD) {
|
|
|
|
printf("VFS: ignoring spurious block dev reply from %d\n", who_e);
|
|
|
|
return;
|
|
|
|
}
|
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-08-28 16:06:51 +02:00
|
|
|
|
2013-09-10 12:19:08 +02:00
|
|
|
wp = worker_get(dp->dmap_servicing);
|
|
|
|
if (wp == NULL || wp->w_task != who_e) {
|
|
|
|
printf("VFS: no worker thread waiting for a reply from %d\n", who_e);
|
|
|
|
return;
|
|
|
|
}
|
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-08-28 16:06:51 +02:00
|
|
|
|
2013-09-10 12:19:08 +02:00
|
|
|
assert(wp->w_drv_sendrec != NULL);
|
|
|
|
*wp->w_drv_sendrec = m_in;
|
|
|
|
wp->w_drv_sendrec = NULL;
|
|
|
|
worker_signal(wp);
|
2012-02-13 16:28:04 +01:00
|
|
|
}
|