nbd: put get-bdev and register-poller to lib/nbd
nbd poller is put into spdk_nbd_disk. nbd test app no longer needs to process spdk_bdev. This enables upcomming patches to move nbd test app functionality to SPDK library. Change-Id: I1b563a49dc9488e8dcc20706be82b17fdbd07ff1 Signed-off-by: Xiaodong Liu <xiaodong.liu@intel.com> Reviewed-on: https://review.gerrithub.io/390093 Tested-by: SPDK Automated Test System <sys_sgsw@intel.com> Reviewed-by: Changpeng Liu <changpeng.liu@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
This commit is contained in:
parent
1dcaee4c46
commit
3b9c5e9c6a
@ -37,14 +37,7 @@
|
|||||||
struct spdk_bdev;
|
struct spdk_bdev;
|
||||||
struct spdk_nbd_disk;
|
struct spdk_nbd_disk;
|
||||||
|
|
||||||
struct spdk_nbd_disk *spdk_nbd_start(struct spdk_bdev *bdev, const char *nbd_path);
|
struct spdk_nbd_disk *spdk_nbd_start(const char *bdev_name, const char *nbd_path);
|
||||||
|
|
||||||
/**
|
|
||||||
* Poll an NBD instance.
|
|
||||||
*
|
|
||||||
* \return 0 on success or negated errno values on error (e.g. connection closed).
|
|
||||||
*/
|
|
||||||
int spdk_nbd_poll(struct spdk_nbd_disk *nbd);
|
|
||||||
|
|
||||||
void spdk_nbd_stop(struct spdk_nbd_disk *nbd);
|
void spdk_nbd_stop(struct spdk_nbd_disk *nbd);
|
||||||
|
|
||||||
|
|||||||
@ -75,6 +75,7 @@ struct spdk_nbd_disk {
|
|||||||
int kernel_sp_fd;
|
int kernel_sp_fd;
|
||||||
int spdk_sp_fd;
|
int spdk_sp_fd;
|
||||||
struct nbd_io io;
|
struct nbd_io io;
|
||||||
|
struct spdk_poller *nbd_poller;
|
||||||
uint32_t buf_align;
|
uint32_t buf_align;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -123,6 +124,10 @@ _nbd_stop(struct spdk_nbd_disk *nbd)
|
|||||||
close(nbd->kernel_sp_fd);
|
close(nbd->kernel_sp_fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (nbd->nbd_poller) {
|
||||||
|
spdk_poller_unregister(&nbd->nbd_poller);
|
||||||
|
}
|
||||||
|
|
||||||
free(nbd);
|
free(nbd);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -286,8 +291,13 @@ process_request(struct spdk_nbd_disk *nbd)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
/**
|
||||||
spdk_nbd_poll(struct spdk_nbd_disk *nbd)
|
* Poll an NBD instance.
|
||||||
|
*
|
||||||
|
* \return 0 on success or negated errno values on error (e.g. connection closed).
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
_spdk_nbd_poll(struct spdk_nbd_disk *nbd)
|
||||||
{
|
{
|
||||||
struct nbd_io *io = &nbd->io;
|
struct nbd_io *io = &nbd->io;
|
||||||
int fd = nbd->spdk_sp_fd;
|
int fd = nbd->spdk_sp_fd;
|
||||||
@ -355,6 +365,19 @@ spdk_nbd_poll(struct spdk_nbd_disk *nbd)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
spdk_nbd_poll(void *arg)
|
||||||
|
{
|
||||||
|
struct spdk_nbd_disk *nbd = arg;
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
rc = _spdk_nbd_poll(nbd);
|
||||||
|
if (rc < 0) {
|
||||||
|
SPDK_NOTICELOG("spdk_nbd_poll got error %d; close it", rc);
|
||||||
|
spdk_nbd_stop(nbd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void *
|
static void *
|
||||||
nbd_start_kernel(void *arg)
|
nbd_start_kernel(void *arg)
|
||||||
{
|
{
|
||||||
@ -388,15 +411,22 @@ nbd_start_kernel(void *arg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct spdk_nbd_disk *
|
struct spdk_nbd_disk *
|
||||||
spdk_nbd_start(struct spdk_bdev *bdev, const char *nbd_path)
|
spdk_nbd_start(const char *bdev_name, const char *nbd_path)
|
||||||
{
|
{
|
||||||
struct spdk_nbd_disk *nbd;
|
struct spdk_nbd_disk *nbd;
|
||||||
|
struct spdk_bdev *bdev;
|
||||||
pthread_t tid;
|
pthread_t tid;
|
||||||
int rc;
|
int rc;
|
||||||
int sp[2];
|
int sp[2];
|
||||||
char buf[64];
|
char buf[64];
|
||||||
int flag;
|
int flag;
|
||||||
|
|
||||||
|
bdev = spdk_bdev_get_by_name(bdev_name);
|
||||||
|
if (bdev == NULL) {
|
||||||
|
SPDK_ERRLOG("no bdev %s exists\n", bdev_name);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
nbd = calloc(1, sizeof(*nbd));
|
nbd = calloc(1, sizeof(*nbd));
|
||||||
if (nbd == NULL) {
|
if (nbd == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -478,6 +508,8 @@ spdk_nbd_start(struct spdk_bdev *bdev, const char *nbd_path)
|
|||||||
to_be32(&nbd->io.resp.magic, NBD_REPLY_MAGIC);
|
to_be32(&nbd->io.resp.magic, NBD_REPLY_MAGIC);
|
||||||
nbd->io.req_in_progress = true;
|
nbd->io.req_in_progress = true;
|
||||||
|
|
||||||
|
nbd->nbd_poller = spdk_poller_register(spdk_nbd_poll, nbd, 0);
|
||||||
|
|
||||||
return nbd;
|
return nbd;
|
||||||
|
|
||||||
err:
|
err:
|
||||||
|
|||||||
@ -43,7 +43,6 @@
|
|||||||
#include "spdk/log.h"
|
#include "spdk/log.h"
|
||||||
#include "spdk/util.h"
|
#include "spdk/util.h"
|
||||||
|
|
||||||
static struct spdk_poller *g_nbd_poller;
|
|
||||||
static struct spdk_nbd_disk *g_nbd_disk;
|
static struct spdk_nbd_disk *g_nbd_disk;
|
||||||
static char *g_bdev_name;
|
static char *g_bdev_name;
|
||||||
static char *g_nbd_name = "/dev/nbd0";
|
static char *g_nbd_name = "/dev/nbd0";
|
||||||
@ -53,43 +52,18 @@ static char *g_nbd_name = "/dev/nbd0";
|
|||||||
static void
|
static void
|
||||||
nbd_shutdown(void)
|
nbd_shutdown(void)
|
||||||
{
|
{
|
||||||
spdk_poller_unregister(&g_nbd_poller);
|
|
||||||
|
|
||||||
spdk_nbd_stop(g_nbd_disk);
|
spdk_nbd_stop(g_nbd_disk);
|
||||||
spdk_app_stop(0);
|
spdk_app_stop(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
nbd_poll(void *arg)
|
|
||||||
{
|
|
||||||
int rc;
|
|
||||||
|
|
||||||
rc = spdk_nbd_poll(g_nbd_disk);
|
|
||||||
if (rc < 0) {
|
|
||||||
SPDK_NOTICELOG("spdk_nbd_poll() returned %d; shutting down", rc);
|
|
||||||
nbd_shutdown();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
nbd_start(void *arg1, void *arg2)
|
nbd_start(void *arg1, void *arg2)
|
||||||
{
|
{
|
||||||
struct spdk_bdev *bdev;
|
g_nbd_disk = spdk_nbd_start(g_bdev_name, g_nbd_name);
|
||||||
|
|
||||||
bdev = spdk_bdev_get_by_name(g_bdev_name);
|
|
||||||
if (bdev == NULL) {
|
|
||||||
SPDK_ERRLOG("no bdev %s exists\n", g_bdev_name);
|
|
||||||
spdk_app_stop(-1);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
g_nbd_disk = spdk_nbd_start(bdev, g_nbd_name);
|
|
||||||
if (g_nbd_disk == NULL) {
|
if (g_nbd_disk == NULL) {
|
||||||
spdk_app_stop(-1);
|
spdk_app_stop(-1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_nbd_poller = spdk_poller_register(nbd_poll, NULL, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void usage(char *program_name)
|
static void usage(char *program_name)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user