This commit is contained in:
parent
a1219f920f
commit
ce8145de67
5
buse.c
5
buse.c
|
@ -74,8 +74,8 @@ int buse_main(int argc, char *argv[], const struct buse_operations *aop, void *u
|
||||||
|
|
||||||
(void) userdata;
|
(void) userdata;
|
||||||
|
|
||||||
assert(argc == 3);
|
assert(argc == 2);
|
||||||
dev_file = argv[2];
|
dev_file = argv[1];
|
||||||
|
|
||||||
assert(!socketpair(AF_UNIX, SOCK_STREAM, 0, sp));
|
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];
|
sk = sp[1];
|
||||||
|
|
||||||
assert(ioctl(nbd, NBD_SET_SOCK, sk) != -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);
|
err = ioctl(nbd, NBD_DO_IT);
|
||||||
fprintf(stderr, "nbd device terminated with code %d\n", err);
|
fprintf(stderr, "nbd device terminated with code %d\n", err);
|
||||||
if (err == -1)
|
if (err == -1)
|
||||||
|
|
8
buse.h
8
buse.h
|
@ -26,6 +26,14 @@ enum {
|
||||||
NBD_CMD_TRIM = 4
|
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 */
|
/* Magic numbers */
|
||||||
#define NBD_REQUEST_MAGIC 0x25609513
|
#define NBD_REQUEST_MAGIC 0x25609513
|
||||||
#define NBD_REPLY_MAGIC 0x67446698
|
#define NBD_REPLY_MAGIC 0x67446698
|
||||||
|
|
39
busexmp.c
39
busexmp.c
|
@ -8,32 +8,47 @@ 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)
|
||||||
{
|
{
|
||||||
memcpy(buf, (char *)data + offset, len);
|
fprintf(stderr, "R - %lu, %u\n", offset, len);
|
||||||
return 0;
|
memcpy(buf, (char *)data + offset, len);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int xmp_write(const void *buf, u_int32_t len, u_int64_t offset)
|
static int xmp_write(const void *buf, u_int32_t len, u_int64_t offset)
|
||||||
{
|
{
|
||||||
memcpy((char *)data + offset, buf, len);
|
fprintf(stderr, "W - %lu, %u\n", offset, len);
|
||||||
return 0;
|
memcpy((char *)data + offset, buf, len);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int xmp_disc()
|
static int xmp_disc()
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Received a disconnect request.\n");
|
fprintf(stderr, "Received a disconnect request.\n");
|
||||||
return 0;
|
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 = {
|
static struct buse_operations aop = {
|
||||||
.read = xmp_read,
|
.read = xmp_read,
|
||||||
.write = xmp_write,
|
.write = xmp_write,
|
||||||
.disc = xmp_disc,
|
.disc = xmp_disc,
|
||||||
.size = 128 * 1024 * 1024,
|
.trim = xmp_trim,
|
||||||
|
.flush = xmp_flush,
|
||||||
|
.size = 128 * 1024 * 1024,
|
||||||
};
|
};
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
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);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue