From 657575210d1719e092640514b3e86f7aae84072f Mon Sep 17 00:00:00 2001 From: Evgeniy Kochetov Date: Wed, 11 Sep 2019 14:04:56 +0000 Subject: [PATCH] nvmf/subsystem: Open block device with extended API Signed-off-by: Evgeniy Kochetov Signed-off-by: Sasha Kotchubievsky Signed-off-by: Alexey Marchuk Change-Id: I471cceefd58ad4c4c64c140fcc66dc25dde43254 Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/468541 Tested-by: SPDK CI Jenkins Reviewed-by: Jim Harris Reviewed-by: Shuhei Matsumoto Reviewed-by: Ben Walker --- lib/nvmf/subsystem.c | 27 ++++++++++++++++--- test/unit/lib/nvmf/subsystem.c/subsystem_ut.c | 8 +++--- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/lib/nvmf/subsystem.c b/lib/nvmf/subsystem.c index e1e5658ce..f6f87592e 100644 --- a/lib/nvmf/subsystem.c +++ b/lib/nvmf/subsystem.c @@ -1,8 +1,8 @@ /*- * BSD LICENSE * - * Copyright (c) Intel Corporation. - * All rights reserved. + * Copyright (c) Intel Corporation. All rights reserved. + * Copyright (c) 2019 Mellanox Technologies LTD. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -959,6 +959,27 @@ spdk_nvmf_ns_hot_remove(void *remove_ctx) } } +static void +spdk_nvmf_ns_event(enum spdk_bdev_event_type type, + struct spdk_bdev *bdev, + void *event_ctx) +{ + SPDK_DEBUGLOG(SPDK_LOG_NVMF, "Bdev event: type %d, name %s, subsystem_id %d, ns_id %d\n", + type, + bdev->name, + ((struct spdk_nvmf_ns *)event_ctx)->subsystem->id, + ((struct spdk_nvmf_ns *)event_ctx)->nsid); + + switch (type) { + case SPDK_BDEV_EVENT_REMOVE: + spdk_nvmf_ns_hot_remove(event_ctx); + break; + default: + SPDK_NOTICELOG("Unsupported bdev event: type %d\n", type); + break; + } +} + void spdk_nvmf_ns_opts_get_defaults(struct spdk_nvmf_ns_opts *opts, size_t opts_size) { @@ -1065,7 +1086,7 @@ spdk_nvmf_subsystem_add_ns(struct spdk_nvmf_subsystem *subsystem, struct spdk_bd ns->bdev = bdev; ns->opts = opts; ns->subsystem = subsystem; - rc = spdk_bdev_open(bdev, true, spdk_nvmf_ns_hot_remove, ns, &ns->desc); + rc = spdk_bdev_open_ext(bdev->name, true, spdk_nvmf_ns_event, ns, &ns->desc); if (rc != 0) { SPDK_ERRLOG("Subsystem %s: bdev %s cannot be opened, error=%d\n", subsystem->subnqn, spdk_bdev_get_name(bdev), rc); diff --git a/test/unit/lib/nvmf/subsystem.c/subsystem_ut.c b/test/unit/lib/nvmf/subsystem.c/subsystem_ut.c index e2294f619..e6199bde9 100644 --- a/test/unit/lib/nvmf/subsystem.c/subsystem_ut.c +++ b/test/unit/lib/nvmf/subsystem.c/subsystem_ut.c @@ -1,8 +1,8 @@ /*- * BSD LICENSE * - * Copyright (c) Intel Corporation. - * All rights reserved. + * Copyright (c) Intel Corporation. All rights reserved. + * Copyright (c) 2019 Mellanox Technologies LTD. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -197,8 +197,8 @@ spdk_nvmf_ctrlr_ns_changed(struct spdk_nvmf_ctrlr *ctrlr, uint32_t nsid) } int -spdk_bdev_open(struct spdk_bdev *bdev, bool write, spdk_bdev_remove_cb_t remove_cb, - void *remove_ctx, struct spdk_bdev_desc **desc) +spdk_bdev_open_ext(const char *bdev_name, bool write, spdk_bdev_event_cb_t event_cb, + void *event_ctx, struct spdk_bdev_desc **_desc) { return 0; }