Committing various changes.
This commit is contained in:
parent
552256907e
commit
fa6dc0152c
23
abuse.c
23
abuse.c
|
@ -36,8 +36,7 @@ int abuse_main(int argc, char *argv[], const struct abuse_operations *aop, void
|
||||||
int sp[2];
|
int sp[2];
|
||||||
int nbd, sk, err, tmp_fd;
|
int nbd, sk, err, tmp_fd;
|
||||||
u_int64_t from;
|
u_int64_t from;
|
||||||
u_int32_t len;
|
u_int32_t len, bytes_read, bytes_written;
|
||||||
int bytes_written, bytes_read;
|
|
||||||
char *dev_file;
|
char *dev_file;
|
||||||
struct nbd_request request;
|
struct nbd_request request;
|
||||||
struct nbd_reply reply;
|
struct nbd_reply reply;
|
||||||
|
@ -92,27 +91,43 @@ int abuse_main(int argc, char *argv[], const struct abuse_operations *aop, void
|
||||||
|
|
||||||
len = ntohl(request.len);
|
len = ntohl(request.len);
|
||||||
from = ntohll(request.from);
|
from = ntohll(request.from);
|
||||||
(void) from;
|
|
||||||
assert(request.magic == htonl(NBD_REQUEST_MAGIC));
|
assert(request.magic == htonl(NBD_REQUEST_MAGIC));
|
||||||
|
|
||||||
switch(ntohl(request.type)) {
|
switch(ntohl(request.type)) {
|
||||||
|
/* I may at some point need to deal with the the fact that the
|
||||||
|
* official nbd server has a maximum buffer size, and divides up
|
||||||
|
* oversized requests into multiple pieces. This applies to reads
|
||||||
|
* and writes.
|
||||||
|
*/
|
||||||
case NBD_CMD_READ:
|
case NBD_CMD_READ:
|
||||||
chunk = malloc(len + sizeof(struct nbd_reply));
|
chunk = malloc(len + sizeof(struct nbd_reply));
|
||||||
aop->read((char *)chunk + sizeof(struct nbd_reply), len, from);
|
aop->read((char *)chunk + sizeof(struct nbd_reply), len, from);
|
||||||
memcpy(chunk, &reply, sizeof(struct nbd_reply));
|
memcpy(chunk, &reply, sizeof(struct nbd_reply));
|
||||||
bytes_written = write(sk, chunk, len + sizeof(struct nbd_reply));
|
bytes_written = write(sk, chunk, len + sizeof(struct nbd_reply));
|
||||||
|
assert(bytes_written == len + sizeof(struct nbd_reply));
|
||||||
fprintf(stderr, "Wrote %d bytes.\n", bytes_written);
|
fprintf(stderr, "Wrote %d bytes.\n", bytes_written);
|
||||||
/* assert(bytes_written == len + sizeof(struct nbd_reply)); */
|
|
||||||
free(chunk);
|
free(chunk);
|
||||||
break;
|
break;
|
||||||
case NBD_CMD_WRITE:
|
case NBD_CMD_WRITE:
|
||||||
|
chunk = malloc(len);
|
||||||
|
bytes_read = read(sk, &chunk, len);
|
||||||
|
assert(bytes_read == len);
|
||||||
|
aop->write(chunk, len, from);
|
||||||
|
free(chunk);
|
||||||
|
bytes_written = write(sk, &reply, sizeof(struct nbd_reply));
|
||||||
|
assert(bytes_written == sizeof(struct nbd_reply));
|
||||||
break;
|
break;
|
||||||
case NBD_CMD_DISC:
|
case NBD_CMD_DISC:
|
||||||
|
aop->disc();
|
||||||
break;
|
break;
|
||||||
case NBD_CMD_FLUSH:
|
case NBD_CMD_FLUSH:
|
||||||
|
aop->flush();
|
||||||
break;
|
break;
|
||||||
case NBD_CMD_TRIM:
|
case NBD_CMD_TRIM:
|
||||||
|
aop->trim();
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
assert(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
6
abuse.h
6
abuse.h
|
@ -6,9 +6,9 @@
|
||||||
struct abuse_operations {
|
struct abuse_operations {
|
||||||
int (*read)(void *buf, u_int32_t len, u_int64_t offset);
|
int (*read)(void *buf, u_int32_t len, u_int64_t offset);
|
||||||
int (*write)(const void *buf, u_int32_t len, u_int64_t offset);
|
int (*write)(const void *buf, u_int32_t len, u_int64_t offset);
|
||||||
void (*disc)();
|
int (*disc)();
|
||||||
void (*flush)();
|
int (*flush)();
|
||||||
void (*trim)();
|
int (*trim)();
|
||||||
|
|
||||||
u_int64_t size;
|
u_int64_t size;
|
||||||
};
|
};
|
||||||
|
|
16
abusexmp.c
16
abusexmp.c
|
@ -3,21 +3,31 @@
|
||||||
|
|
||||||
#include "abuse.h"
|
#include "abuse.h"
|
||||||
|
|
||||||
|
static void *data;
|
||||||
|
|
||||||
static int xmp_read(void *buf, u_int32_t len, u_int64_t offset)
|
static int xmp_read(void *buf, u_int32_t len, u_int64_t offset)
|
||||||
{
|
{
|
||||||
(void) offset;
|
/* memcpy(buf, (char *)data + offset, len); */
|
||||||
|
|
||||||
memset(buf, 0, len);
|
memset(buf, 0, len);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int xmp_write(const void *buf, u_int32_t len, u_int64_t offset)
|
||||||
|
{
|
||||||
|
memcpy((char *)data + offset, buf, len);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static struct abuse_operations aop = {
|
static struct abuse_operations aop = {
|
||||||
.read = xmp_read,
|
.read = xmp_read,
|
||||||
.size = 1024,
|
.write = xmp_write,
|
||||||
|
.size = 128 * 1024 * 1024,
|
||||||
};
|
};
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
data = malloc(aop.size);
|
||||||
|
|
||||||
return abuse_main(argc, argv, &aop, NULL);
|
return abuse_main(argc, argv, &aop, NULL);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue