2009-12-02 11:08:58 +01:00
|
|
|
/* Filter driver - general include file */
|
|
|
|
#define _MINIX 1
|
|
|
|
#define _SYSTEM 1
|
|
|
|
#include <minix/config.h>
|
|
|
|
#include <minix/const.h>
|
|
|
|
#include <minix/type.h>
|
|
|
|
#include <minix/com.h>
|
|
|
|
#include <minix/ipc.h>
|
|
|
|
#include <sys/ioc_disk.h>
|
|
|
|
#include <minix/sysutil.h>
|
|
|
|
#include <minix/syslib.h>
|
|
|
|
#include <minix/partition.h>
|
|
|
|
#include <minix/ds.h>
|
|
|
|
#include <minix/callnr.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 <minix/blockdriver.h>
|
2011-11-07 16:16:08 +01:00
|
|
|
#include <minix/optset.h>
|
2009-12-02 11:08:58 +01:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#define SECTOR_SIZE 512
|
|
|
|
|
2010-01-27 11:19:13 +01:00
|
|
|
typedef enum {
|
2009-12-22 00:30:01 +01:00
|
|
|
ST_NIL, /* Zero checksums */
|
2009-12-02 11:08:58 +01:00
|
|
|
ST_XOR, /* XOR-based checksums */
|
|
|
|
ST_CRC, /* CRC32-based checksums */
|
|
|
|
ST_MD5 /* MD5-based checksums */
|
2010-01-27 11:19:13 +01:00
|
|
|
} checksum_type;
|
2009-12-02 11:08:58 +01:00
|
|
|
|
2010-01-27 11:19:13 +01:00
|
|
|
typedef enum {
|
2009-12-02 11:08:58 +01:00
|
|
|
FLT_WRITE, /* write to up to two disks */
|
|
|
|
FLT_READ, /* read from one disk */
|
|
|
|
FLT_READ2 /* read from both disks */
|
2010-01-27 11:19:13 +01:00
|
|
|
} disk_operation;
|
2009-12-02 11:08:58 +01:00
|
|
|
|
2010-04-08 15:41:35 +02:00
|
|
|
struct driverinfo {
|
|
|
|
char *label;
|
|
|
|
int minor;
|
|
|
|
endpoint_t endpt;
|
|
|
|
int up_event;
|
|
|
|
|
|
|
|
int problem; /* one of BD_* */
|
|
|
|
int error; /* one of E*, only relevant if problem>0 */
|
|
|
|
int retries;
|
|
|
|
int kills;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* UP event characterization. */
|
|
|
|
#define UP_EXPECTED 0
|
|
|
|
#define UP_NONE 1
|
|
|
|
#define UP_PENDING 2
|
|
|
|
|
2009-12-02 11:08:58 +01:00
|
|
|
/* Something was wrong and the disk driver has been restarted/refreshed,
|
|
|
|
* so the request needs to be redone.
|
|
|
|
*/
|
|
|
|
#define RET_REDO 1
|
|
|
|
|
|
|
|
/* The cases where the disk driver need to be restarted/refreshed by RS.
|
|
|
|
* BD_DEAD: the disk driver has died. Restart it.
|
|
|
|
* BD_PROTO: a protocol error has occurred. Refresh it.
|
|
|
|
* BD_DATA: a data error has occurred. Refresh it.
|
|
|
|
*/
|
2010-01-27 11:19:13 +01:00
|
|
|
typedef enum {
|
2009-12-02 11:08:58 +01:00
|
|
|
BD_NONE,
|
|
|
|
BD_DEAD,
|
|
|
|
BD_PROTO,
|
|
|
|
BD_DATA,
|
|
|
|
BD_LAST
|
2010-01-27 11:19:13 +01:00
|
|
|
} driver_state;
|
2009-12-02 11:08:58 +01:00
|
|
|
|
|
|
|
#define DRIVER_MAIN 0
|
|
|
|
#define DRIVER_BACKUP 1
|
|
|
|
|
2009-12-22 00:30:01 +01:00
|
|
|
/* Requests for more than this many bytes will be allocated dynamically. */
|
|
|
|
#define BUF_SIZE (256 * 1024)
|
2009-12-02 11:08:58 +01:00
|
|
|
#define SBUF_SIZE (BUF_SIZE * 2)
|
|
|
|
|
|
|
|
#define LABEL_SIZE 32
|
|
|
|
|
|
|
|
typedef unsigned long sector_t;
|
|
|
|
|
|
|
|
/* main.c */
|
|
|
|
extern int USE_CHECKSUM;
|
|
|
|
extern int USE_MIRROR;
|
|
|
|
extern int BAD_SUM_ERROR;
|
|
|
|
extern int USE_SUM_LAYOUT;
|
|
|
|
extern int SUM_TYPE;
|
|
|
|
extern int SUM_SIZE;
|
|
|
|
extern int NR_SUM_SEC;
|
|
|
|
extern int NR_RETRIES;
|
|
|
|
extern int NR_RESTARTS;
|
|
|
|
extern int DRIVER_TIMEOUT;
|
2009-12-22 00:30:01 +01:00
|
|
|
extern int CHUNK_SIZE;
|
2009-12-02 11:08:58 +01:00
|
|
|
|
|
|
|
extern char MAIN_LABEL[LABEL_SIZE];
|
|
|
|
extern char BACKUP_LABEL[LABEL_SIZE];
|
|
|
|
extern int MAIN_MINOR;
|
|
|
|
extern int BACKUP_MINOR;
|
|
|
|
|
|
|
|
/* sum.c */
|
|
|
|
extern void sum_init(void);
|
|
|
|
extern int transfer(u64_t pos, char *buffer, size_t *sizep, int flag_rw);
|
|
|
|
extern u64_t convert(u64_t size);
|
|
|
|
|
|
|
|
/* driver.c */
|
|
|
|
extern void driver_init(void);
|
|
|
|
extern void driver_shutdown(void);
|
|
|
|
extern u64_t get_raw_size(void);
|
|
|
|
extern void reset_kills(void);
|
|
|
|
extern int check_driver(int which);
|
|
|
|
extern int bad_driver(int which, int type, int error);
|
|
|
|
extern int read_write(u64_t pos, char *bufa, char *bufb, size_t *sizep,
|
|
|
|
int flag_rw);
|
2010-04-08 15:41:35 +02:00
|
|
|
extern void ds_event(void);
|
2009-12-02 11:08:58 +01:00
|
|
|
|
|
|
|
/* util.c */
|
|
|
|
extern char *flt_malloc(size_t size, char *sbuf, size_t ssize);
|
2010-04-07 13:25:51 +02:00
|
|
|
extern void flt_free(char *buf, size_t size, const char *sbuf);
|
2009-12-02 11:08:58 +01:00
|
|
|
extern char *print64(u64_t p);
|
|
|
|
extern clock_t flt_alarm(clock_t dt);
|
2010-04-08 15:41:35 +02:00
|
|
|
|