This commit is contained in:
comatose 2012-12-03 08:25:06 +09:00
parent a1219f920f
commit ce8145de67
3 changed files with 38 additions and 14 deletions

5
buse.c
View File

@ -74,8 +74,8 @@ int buse_main(int argc, char *argv[], const struct buse_operations *aop, void *u
(void) userdata;
assert(argc == 3);
dev_file = argv[2];
assert(argc == 2);
dev_file = argv[1];
assert(!socketpair(AF_UNIX, SOCK_STREAM, 0, sp));
@ -91,6 +91,7 @@ int buse_main(int argc, char *argv[], const struct buse_operations *aop, void *u
sk = sp[1];
assert(ioctl(nbd, NBD_SET_SOCK, sk) != -1);
assert(ioctl(nbd, NBD_SET_FLAGS, NBD_FLAG_SEND_TRIM) != -1);
err = ioctl(nbd, NBD_DO_IT);
fprintf(stderr, "nbd device terminated with code %d\n", err);
if (err == -1)

8
buse.h
View File

@ -26,6 +26,14 @@ enum {
NBD_CMD_TRIM = 4
};
/* values for flags field */
#define NBD_FLAG_HAS_FLAGS (1 << 0) /* Flags are there */
#define NBD_FLAG_READ_ONLY (1 << 1) /* Device is read-only */
#define NBD_FLAG_SEND_FLUSH (1 << 2) /* Send FLUSH */
#define NBD_FLAG_SEND_FUA (1 << 3) /* Send FUA (Force Unit Access) */
#define NBD_FLAG_ROTATIONAL (1 << 4) /* Use elevator algorithm - rotational media */
#define NBD_FLAG_SEND_TRIM (1 << 5) /* send trim/discard */
/* Magic numbers */
#define NBD_REQUEST_MAGIC 0x25609513
#define NBD_REPLY_MAGIC 0x67446698

View File

@ -8,32 +8,47 @@ static void *data;
static int xmp_read(void *buf, u_int32_t len, u_int64_t offset)
{
memcpy(buf, (char *)data + offset, len);
return 0;
fprintf(stderr, "R - %lu, %u\n", offset, len);
memcpy(buf, (char *)data + offset, len);
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;
fprintf(stderr, "W - %lu, %u\n", offset, len);
memcpy((char *)data + offset, buf, len);
return 0;
}
static int xmp_disc()
{
fprintf(stderr, "Received a disconnect request.\n");
return 0;
fprintf(stderr, "Received a disconnect request.\n");
return 0;
}
static int xmp_flush(){
fprintf(stderr, "F\n");
return 0;
}
static int xmp_trim(u_int64_t from, u_int32_t len){
fprintf(stderr, "T - %lu, %u\n", from, len);
return 0;
}
static struct buse_operations aop = {
.read = xmp_read,
.write = xmp_write,
.disc = xmp_disc,
.size = 128 * 1024 * 1024,
.read = xmp_read,
.write = xmp_write,
.disc = xmp_disc,
.trim = xmp_trim,
.flush = xmp_flush,
.size = 128 * 1024 * 1024,
};
int main(int argc, char *argv[])
{
data = malloc(aop.size);
data = malloc(aop.size);
return buse_main(argc, argv, &aop, NULL);
return buse_main(argc, argv, &aop, NULL);
}