spdk read,write complete

This commit is contained in:
king
2024-08-08 13:43:08 +00:00
parent 2871adf324
commit cbb3e62137
2 changed files with 204 additions and 5 deletions

View File

@@ -6,12 +6,159 @@
#include <spdk/blob.h>
#include <spdk/bdev.h>
#include <spdk/blob_bdev.h>
#include <spdk/env.h>
void zv2404_spdk_bdev_event_cb(enum spdk_bdev_event_type type, struct spdk_bdev *bdev,
#define BUFFER_SIZE 512
struct spdk_blob_store *blobstore;
spdk_blob_id blob_id;
struct spdk_blob *blob;
uint64_t free_cluster_count;
uint64_t num_cluster;
uint8_t *write_buffer;
uint8_t *read_buffer;
struct spdk_io_channel *channel;
static void zv2404fs_spdk_bs_unload_cb(void *arg, int bserrno) {
spdk_app_stop(0);
}
static void zv2404fs_spdk_blob_delete_cb(void *arg, int bserrno) {
if (blobstore) {
if (channel) {
spdk_bs_free_io_channel(channel);
}
spdk_bs_unload(blobstore, zv2404fs_spdk_bs_unload_cb, NULL);
}
}
static void zv2404fs_spdk_blob_close_cb(void *arg, int bserrno) {
spdk_bs_delete_blob(blobstore, blob_id, zv2404fs_spdk_blob_delete_cb, NULL);
}
static void zv2404fs_spdk_blob_read_cb(void *arg, int bserrno) {
SPDK_NOTICELOG("READ BUFFER : %s\n", read_buffer);
spdk_blob_close(blob, zv2404fs_spdk_blob_close_cb, NULL);
}
static void zv2404fs_spdk_blob_write_cb(void *arg, int bserrno) {
SPDK_NOTICELOG("WRITE COMPLETE\n");
uint8_t *rbuffer = spdk_malloc(512, 0x1000, NULL, SPDK_ENV_LCORE_ID_ANY, SPDK_MALLOC_DMA);
if (rbuffer == NULL) {
spdk_app_stop(0);
return ;
}
memset(rbuffer, 0x0, BUFFER_SIZE);
read_buffer = rbuffer;
spdk_blob_io_read(blob, channel, rbuffer, 0, 1, zv2404fs_spdk_blob_read_cb, NULL);
}
static void zv2404fs_spdk_blob_sync_cb(void *arg, int bserrno) {
uint8_t *wbuffer = spdk_malloc(512, 0x1000, NULL, SPDK_ENV_LCORE_ID_ANY, SPDK_MALLOC_DMA);
if (wbuffer == NULL) {
spdk_app_stop(0);
return ;
}
memset(wbuffer, 'A', BUFFER_SIZE);
*(wbuffer+BUFFER_SIZE-1) = '\0';
write_buffer = wbuffer;
struct spdk_io_channel *chan = spdk_bs_alloc_io_channel(blobstore);
if (chan == NULL) {
spdk_app_stop(0);
return ;
}
channel = chan;
spdk_blob_io_write(blob, channel, wbuffer, 0, 1, zv2404fs_spdk_blob_write_cb, NULL);
}
static void zv2404fs_spdk_blob_resize_cb(void *arg, int bserrno) {
struct spdk_blob *blb = (struct spdk_blob *)arg;
uint64_t total = spdk_blob_get_num_clusters(blb);
num_cluster = total;
SPDK_NOTICELOG("resize blob :%"PRIu64"\n", total);
spdk_blob_sync_md(blb, zv2404fs_spdk_blob_sync_cb, blb);
}
static void zv2404fs_spdk_bs_open_blob_cb(void *arg, struct spdk_blob *blb, int bserrno) {
struct spdk_blob_store *bs = (struct spdk_blob_store*)arg;
blob = blb;
uint64_t free_cluster = spdk_bs_free_cluster_count(bs); //
SPDK_NOTICELOG("free_cluster : %"PRIu64"\n", free_cluster);
free_cluster_count = free_cluster;
spdk_blob_resize(blb, free_cluster, zv2404fs_spdk_blob_resize_cb, blb);
}
static void zv2404fs_spdk_bs_create_blob_cb(void *arg, spdk_blob_id blobid, int bserrno) {
struct spdk_blob_store *bs = (struct spdk_blob_store*)arg;
blob_id = blobid;
SPDK_NOTICELOG("blobid : %"PRIu64"\n", blobid);
spdk_bs_open_blob(bs, blobid, zv2404fs_spdk_bs_open_blob_cb, bs);
}
static void zv2404fs_spdk_bs_init_cb(void *arg, struct spdk_blob_store *bs,
int bserrno) {
uint64_t io_unit_size = spdk_bs_get_io_unit_size(bs);
SPDK_NOTICELOG("io_unit_size : %"PRIu64"\n", io_unit_size);
blobstore = bs;
spdk_bs_create_blob(bs, zv2404fs_spdk_bs_create_blob_cb, bs);
}
static void zv2404_spdk_bdev_event_cb(enum spdk_bdev_event_type type, struct spdk_bdev *bdev,
void *event_ctx) {
printf("zv2404_spdk_bdev_event_cb\n");
SPDK_NOTICELOG("zv2404_spdk_bdev_event_cb\n");
}
@@ -28,12 +175,26 @@ static void zv2404fs_entry(void *ctx) {
spdk_app_stop(0);
}
//int *count = malloc(sizeof(int));
//*count = 2404;
spdk_bs_init(bs_dev, NULL, zv2404fs_spdk_bs_init_cb, NULL);
printf("zv2404fs_entry\n");
//sleep(10);
SPDK_NOTICELOG("zv2404fs_entry\n");
}
// open
// read
// write
// close
#if 1
int main(int argc, char *argv[]) {
@@ -47,8 +208,29 @@ int main(int argc, char *argv[]) {
spdk_app_start(&opts, zv2404fs_entry, NULL);
printf("hello spdk\n");
SPDK_NOTICELOG("hello spdk\n");
}
#else
// posix
int main() {
int fd = open("a.txt", O_CREAT | O_READ);
char *buffer = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
write(fd, buffer, strlen(buffer));
char rbuffer[128] = {0};
read(fd, buffer, 128);
close();
}
#endif

17
zvfs.json Normal file
View File

@@ -0,0 +1,17 @@
{
"subsystems": [
{
"subsystem": "bdev",
"config": [
{
"method": "bdev_malloc_create",
"params": {
"name": "Malloc0",
"num_blocks": 32768,
"block_size": 512
}
}
]
}
]
}