blobfs: add blobfs_detect RPC
Add module blobfs_bdev as a general module to simplify the operations of blobfs on bdev. Then its functions can be utilized by other libraries or apps. blobfs_detect can be used to detect whether there is one blobfs on given bdev. Change-Id: Ib425574816061dc945fb652b539f791a44097a43 Signed-off-by: Xiaodong Liu <xiaodong.liu@intel.com> Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/466486 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Paul Luse <paul.e.luse@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
This commit is contained in:
parent
e4e6c256b9
commit
3ce759a1d5
@ -73,6 +73,12 @@ function has been deprecated.
|
||||
The new create function can cowork with spdk_bdev_open_ext function, which provides callback
|
||||
function that will be called by asynchronous event such as bdev removal.
|
||||
|
||||
### blobfs_bdev
|
||||
|
||||
A new blobfs module `bdev` has been added to simplify the operations of blobfs on bdev.
|
||||
|
||||
Function spdk_blobfs_bdev_detect is added to detect whether blobfs exists on the given block device.
|
||||
|
||||
### nvme
|
||||
|
||||
Added `no_shn_notification` to NVMe controller initialization options, users can enable
|
||||
@ -129,6 +135,8 @@ Added optional parameter '--md-size' to 'construct_null_bdev' RPC method.
|
||||
Added optional parameters '--dif-type' and '--dif-is-head-of-md' to 'construct_null_bdev'
|
||||
RPC method.
|
||||
|
||||
Added `blobfs_detect` RPC method to detect whether a blobfs exists on given bdev.
|
||||
|
||||
## v19.07:
|
||||
|
||||
### ftl
|
||||
|
@ -203,6 +203,7 @@ if [ $SPDK_RUN_FUNCTIONAL_TEST -eq 1 ]; then
|
||||
if [ $SPDK_TEST_BLOBFS -eq 1 ]; then
|
||||
run_test suite ./test/blobfs/rocksdb/rocksdb.sh
|
||||
run_test suite ./test/blobstore/blobstore.sh
|
||||
run_test suite ./test/blobfs/blobfs.sh
|
||||
fi
|
||||
|
||||
if [ $SPDK_TEST_NVMF -eq 1 ]; then
|
||||
|
@ -5693,6 +5693,47 @@ Example response:
|
||||
}
|
||||
~~~
|
||||
|
||||
# Blobfs {#jsonrpc_components_blobfs}
|
||||
|
||||
## blobfs_detect {#rpc_blobfs_detect}
|
||||
|
||||
Detect whether a blobfs exists on bdev.
|
||||
|
||||
### Parameters
|
||||
|
||||
Name | Optional | Type | Description
|
||||
----------------------- | -------- | ----------- | -----------
|
||||
bdev_name | Required | string | Block device name to detect blobfs
|
||||
|
||||
### Response
|
||||
|
||||
True if a blobfs exists on the bdev; False otherwise.
|
||||
|
||||
### Example
|
||||
|
||||
Example request:
|
||||
|
||||
~~~
|
||||
{
|
||||
"jsonrpc": "2.0",
|
||||
"id": 1,
|
||||
"method": "blobfs_detect",
|
||||
"params": {
|
||||
"bdev_name": "Malloc0"
|
||||
}
|
||||
}
|
||||
~~~
|
||||
|
||||
Example response:
|
||||
|
||||
~~~
|
||||
{
|
||||
"jsonrpc": "2.0",
|
||||
"id": 1,
|
||||
"result": "true"
|
||||
}
|
||||
~~~
|
||||
|
||||
# Miscellaneous RPC commands
|
||||
|
||||
## bdev_nvme_send_cmd {#rpc_bdev_nvme_send_cmd}
|
||||
|
70
include/spdk/blobfs_bdev.h
Normal file
70
include/spdk/blobfs_bdev.h
Normal file
@ -0,0 +1,70 @@
|
||||
/*-
|
||||
* BSD LICENSE
|
||||
*
|
||||
* Copyright (c) Intel Corporation.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Intel Corporation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* Operations on blobfs whose backing device is spdk_bdev
|
||||
*/
|
||||
|
||||
#ifndef SPDK_BLOBFS_BDEV_H
|
||||
#define SPDK_BLOBFS_BDEV_H
|
||||
|
||||
#include "spdk/stdinc.h"
|
||||
#include "spdk/bdev.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* blobfs on bdev operation completion callback.
|
||||
*
|
||||
* \param cb_arg Callback argument.
|
||||
* \param fserrno 0 if it completed successfully, or negative errno if it failed.
|
||||
*/
|
||||
typedef void (*spdk_blobfs_bdev_op_complete)(void *cb_arg, int fserrno);
|
||||
|
||||
/**
|
||||
* Detect whether blobfs exists on the given device.
|
||||
*
|
||||
* \param bdev_name Name of block device.
|
||||
* \param cb_fn Called when the detecting is complete. fserrno is -EILSEQ if no blobfs exists.
|
||||
* \param cb_arg Argument passed to function cb_fn.
|
||||
*/
|
||||
void spdk_blobfs_bdev_detect(const char *bdev_name,
|
||||
spdk_blobfs_bdev_op_complete cb_fn, void *cb_arg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* SPDK_BLOBFS_BDEV_H */
|
@ -97,6 +97,9 @@ BDEV_DEPS_CONF_THREAD = $(BDEV_DEPS) conf thread
|
||||
# module/blob
|
||||
DEPDIRS-blob_bdev := log thread bdev
|
||||
|
||||
# module/blobfs
|
||||
DEPDIRS-blobfs_bdev := $(BDEV_DEPS_THREAD) blob_bdev blobfs
|
||||
|
||||
# module/copy
|
||||
DEPDIRS-copy_ioat := log ioat conf thread $(JSON_LIBS) copy
|
||||
|
||||
|
@ -34,7 +34,7 @@
|
||||
SPDK_ROOT_DIR := $(abspath $(CURDIR)/..)
|
||||
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
|
||||
|
||||
DIRS-y = bdev blob copy event sock
|
||||
DIRS-y = bdev blob blobfs copy event sock
|
||||
|
||||
DEPDIRS-blob :=
|
||||
DEPDIRS-copy :=
|
||||
|
44
module/blobfs/Makefile
Normal file
44
module/blobfs/Makefile
Normal file
@ -0,0 +1,44 @@
|
||||
#
|
||||
# BSD LICENSE
|
||||
#
|
||||
# Copyright (c) Intel Corporation.
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# * Neither the name of Intel Corporation nor the names of its
|
||||
# contributors may be used to endorse or promote products derived
|
||||
# from this software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
|
||||
SPDK_ROOT_DIR := $(abspath $(CURDIR)/../..)
|
||||
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
|
||||
|
||||
DIRS-y = bdev
|
||||
|
||||
.PHONY: all clean $(DIRS-y)
|
||||
|
||||
all: $(DIRS-y)
|
||||
clean: $(DIRS-y)
|
||||
|
||||
include $(SPDK_ROOT_DIR)/mk/spdk.subdirs.mk
|
40
module/blobfs/bdev/Makefile
Normal file
40
module/blobfs/bdev/Makefile
Normal file
@ -0,0 +1,40 @@
|
||||
#
|
||||
# BSD LICENSE
|
||||
#
|
||||
# Copyright (c) Intel Corporation.
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# * Neither the name of Intel Corporation nor the names of its
|
||||
# contributors may be used to endorse or promote products derived
|
||||
# from this software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
|
||||
SPDK_ROOT_DIR := $(abspath $(CURDIR)/../../..)
|
||||
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
|
||||
|
||||
C_SRCS = blobfs_bdev.c blobfs_bdev_rpc.c
|
||||
LIBNAME = blobfs_bdev
|
||||
|
||||
include $(SPDK_ROOT_DIR)/mk/spdk.lib.mk
|
143
module/blobfs/bdev/blobfs_bdev.c
Normal file
143
module/blobfs/bdev/blobfs_bdev.c
Normal file
@ -0,0 +1,143 @@
|
||||
/*-
|
||||
* BSD LICENSE
|
||||
*
|
||||
* Copyright (c) Intel Corporation.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Intel Corporation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "spdk/stdinc.h"
|
||||
#include "spdk/blobfs.h"
|
||||
#include "spdk/bdev.h"
|
||||
#include "spdk/event.h"
|
||||
#include "spdk/blob_bdev.h"
|
||||
#include "spdk/blobfs_bdev.h"
|
||||
#include "spdk/log.h"
|
||||
#include "spdk/string.h"
|
||||
#include "spdk/rpc.h"
|
||||
#include "spdk/util.h"
|
||||
|
||||
#include "spdk_internal/log.h"
|
||||
|
||||
static void
|
||||
blobfs_bdev_event_cb(enum spdk_bdev_event_type type, struct spdk_bdev *bdev,
|
||||
void *event_ctx)
|
||||
{
|
||||
SPDK_WARNLOG("Async event(%d) is triggered in bdev %s\n", type, spdk_bdev_get_name(bdev));
|
||||
}
|
||||
|
||||
struct blobfs_bdev_operation_ctx {
|
||||
const char *bdev_name;
|
||||
struct spdk_filesystem *fs;
|
||||
|
||||
spdk_blobfs_bdev_op_complete cb_fn;
|
||||
void *cb_arg;
|
||||
};
|
||||
|
||||
static void
|
||||
_blobfs_bdev_unload_cb(void *_ctx, int fserrno)
|
||||
{
|
||||
struct blobfs_bdev_operation_ctx *ctx = _ctx;
|
||||
|
||||
if (fserrno) {
|
||||
SPDK_ERRLOG("Failed to unload blobfs on bdev %s: errno %d\n", ctx->bdev_name, fserrno);
|
||||
}
|
||||
|
||||
ctx->cb_fn(ctx->cb_arg, fserrno);
|
||||
free(ctx);
|
||||
}
|
||||
|
||||
static void
|
||||
blobfs_bdev_unload(void *_ctx)
|
||||
{
|
||||
struct blobfs_bdev_operation_ctx *ctx = _ctx;
|
||||
|
||||
spdk_fs_unload(ctx->fs, _blobfs_bdev_unload_cb, ctx);
|
||||
}
|
||||
|
||||
static void
|
||||
blobfs_bdev_load_cb_to_unload(void *_ctx, struct spdk_filesystem *fs, int fserrno)
|
||||
{
|
||||
struct blobfs_bdev_operation_ctx *ctx = _ctx;
|
||||
|
||||
if (fserrno) {
|
||||
ctx->cb_fn(ctx->cb_arg, fserrno);
|
||||
free(ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
ctx->fs = fs;
|
||||
spdk_thread_send_msg(spdk_get_thread(), blobfs_bdev_unload, ctx);
|
||||
}
|
||||
|
||||
void
|
||||
spdk_blobfs_bdev_detect(const char *bdev_name,
|
||||
spdk_blobfs_bdev_op_complete cb_fn, void *cb_arg)
|
||||
{
|
||||
struct blobfs_bdev_operation_ctx *ctx;
|
||||
struct spdk_bs_dev *bs_dev;
|
||||
struct spdk_bdev_desc *desc;
|
||||
int rc;
|
||||
|
||||
ctx = calloc(1, sizeof(*ctx));
|
||||
if (ctx == NULL) {
|
||||
SPDK_ERRLOG("Failed to allocate ctx.\n");
|
||||
cb_fn(cb_arg, -ENOMEM);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
ctx->bdev_name = bdev_name;
|
||||
ctx->cb_fn = cb_fn;
|
||||
ctx->cb_arg = cb_arg;
|
||||
|
||||
rc = spdk_bdev_open_ext(bdev_name, true, blobfs_bdev_event_cb, NULL, &desc);
|
||||
if (rc != 0) {
|
||||
SPDK_INFOLOG(SPDK_LOG_BLOBFS, "Failed to open bdev(%s): %s\n", ctx->bdev_name, spdk_strerror(rc));
|
||||
|
||||
goto invalid;
|
||||
}
|
||||
|
||||
bs_dev = spdk_bdev_create_bs_dev_from_desc(desc);
|
||||
if (bs_dev == NULL) {
|
||||
SPDK_INFOLOG(SPDK_LOG_BLOBFS, "Failed to create a blobstore block device from bdev desc");
|
||||
rc = -ENOMEM;
|
||||
spdk_bdev_close(desc);
|
||||
|
||||
goto invalid;
|
||||
}
|
||||
|
||||
spdk_fs_load(bs_dev, NULL, blobfs_bdev_load_cb_to_unload, ctx);
|
||||
|
||||
return;
|
||||
|
||||
invalid:
|
||||
free(ctx);
|
||||
|
||||
cb_fn(cb_arg, rc);
|
||||
}
|
117
module/blobfs/bdev/blobfs_bdev_rpc.c
Normal file
117
module/blobfs/bdev/blobfs_bdev_rpc.c
Normal file
@ -0,0 +1,117 @@
|
||||
/*-
|
||||
* BSD LICENSE
|
||||
*
|
||||
* Copyright (c) Intel Corporation.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Intel Corporation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "spdk/stdinc.h"
|
||||
#include "spdk/blobfs.h"
|
||||
#include "spdk/bdev.h"
|
||||
#include "spdk/event.h"
|
||||
#include "spdk/blob_bdev.h"
|
||||
#include "spdk/blobfs_bdev.h"
|
||||
#include "spdk/log.h"
|
||||
#include "spdk/string.h"
|
||||
#include "spdk/rpc.h"
|
||||
#include "spdk/util.h"
|
||||
|
||||
#include "spdk_internal/log.h"
|
||||
|
||||
struct rpc_blobfs_detect {
|
||||
char *bdev_name;
|
||||
|
||||
struct spdk_jsonrpc_request *request;
|
||||
};
|
||||
|
||||
static void
|
||||
free_rpc_blobfs_detect(struct rpc_blobfs_detect *req)
|
||||
{
|
||||
free(req->bdev_name);
|
||||
free(req);
|
||||
}
|
||||
|
||||
static const struct spdk_json_object_decoder rpc_blobfs_detect_decoders[] = {
|
||||
{"bdev_name", offsetof(struct rpc_blobfs_detect, bdev_name), spdk_json_decode_string},
|
||||
};
|
||||
|
||||
static void
|
||||
_rpc_blobfs_detect_done(void *cb_arg, int fserrno)
|
||||
{
|
||||
struct rpc_blobfs_detect *req = cb_arg;
|
||||
struct spdk_json_write_ctx *w;
|
||||
bool existed = true;
|
||||
|
||||
if (fserrno == -EILSEQ) {
|
||||
/* There is no blobfs existing on bdev */
|
||||
existed = false;
|
||||
} else if (fserrno != 0) {
|
||||
spdk_jsonrpc_send_error_response(req->request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
|
||||
spdk_strerror(-fserrno));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
w = spdk_jsonrpc_begin_result(req->request);
|
||||
spdk_json_write_bool(w, existed);
|
||||
spdk_jsonrpc_end_result(req->request, w);
|
||||
|
||||
free_rpc_blobfs_detect(req);
|
||||
}
|
||||
|
||||
static void
|
||||
spdk_rpc_blobfs_detect(struct spdk_jsonrpc_request *request,
|
||||
const struct spdk_json_val *params)
|
||||
{
|
||||
struct rpc_blobfs_detect *req;
|
||||
|
||||
req = calloc(1, sizeof(*req));
|
||||
if (req == NULL) {
|
||||
SPDK_ERRLOG("could not allocate rpc_blobfs_detect request.\n");
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR, "Out of memory");
|
||||
return;
|
||||
}
|
||||
|
||||
if (spdk_json_decode_object(params, rpc_blobfs_detect_decoders,
|
||||
SPDK_COUNTOF(rpc_blobfs_detect_decoders),
|
||||
req)) {
|
||||
SPDK_ERRLOG("spdk_json_decode_object failed\n");
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
||||
"spdk_json_decode_object failed");
|
||||
|
||||
free_rpc_blobfs_detect(req);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
req->request = request;
|
||||
spdk_blobfs_bdev_detect(req->bdev_name, _rpc_blobfs_detect_done, req);
|
||||
}
|
||||
|
||||
SPDK_RPC_REGISTER("blobfs_detect", spdk_rpc_blobfs_detect, SPDK_RPC_RUNTIME)
|
@ -2064,6 +2064,15 @@ Format: 'user:u1 secret:s1 muser:mu1 msecret:ms1,user:u2 secret:s2 muser:mu2 mse
|
||||
'thread_get_stats', help='Display current statistics of all the threads')
|
||||
p.set_defaults(func=thread_get_stats)
|
||||
|
||||
# blobfs
|
||||
def blobfs_detect(args):
|
||||
print(rpc.blobfs.blobfs_detect(args.client,
|
||||
bdev_name=args.bdev_name))
|
||||
|
||||
p = subparsers.add_parser('blobfs_detect', help='Detect whether a blobfs exists on bdev')
|
||||
p.add_argument('bdev_name', help='Blockdev name to detect blobfs. Example: Malloc0.')
|
||||
p.set_defaults(func=blobfs_detect)
|
||||
|
||||
def check_called_name(name):
|
||||
if name in deprecated_aliases:
|
||||
print("{} is deprecated, use {} instead.".format(name, deprecated_aliases[name]), file=sys.stderr)
|
||||
|
@ -3,6 +3,7 @@ import sys
|
||||
|
||||
from . import app
|
||||
from . import bdev
|
||||
from . import blobfs
|
||||
from . import ioat
|
||||
from . import iscsi
|
||||
from . import log
|
||||
|
13
scripts/rpc/blobfs.py
Normal file
13
scripts/rpc/blobfs.py
Normal file
@ -0,0 +1,13 @@
|
||||
def blobfs_detect(client, bdev_name):
|
||||
"""Detect whether a blobfs exists on bdev.
|
||||
|
||||
Args:
|
||||
bdev_name: block device name to detect blobfs
|
||||
|
||||
Returns:
|
||||
True if a blobfs exists on the bdev; False otherwise.
|
||||
"""
|
||||
params = {
|
||||
'bdev_name': bdev_name
|
||||
}
|
||||
return client.call('blobfs_detect', params)
|
@ -41,7 +41,7 @@ C_SRCS := bdev_svc.c
|
||||
|
||||
SPDK_LIB_LIST = $(ALL_MODULES_LIST)
|
||||
SPDK_LIB_LIST += event_bdev event_copy event_vmd
|
||||
SPDK_LIB_LIST += nvmf event log trace conf thread util bdev copy rpc jsonrpc json sock
|
||||
SPDK_LIB_LIST += nvmf event log trace conf thread util bdev copy rpc jsonrpc json sock blobfs_bdev
|
||||
SPDK_LIB_LIST += app_rpc log_rpc bdev_rpc notify
|
||||
|
||||
ifeq ($(OS),Linux)
|
||||
|
75
test/blobfs/blobfs.sh
Executable file
75
test/blobfs/blobfs.sh
Executable file
@ -0,0 +1,75 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
SYSTEM=$(uname -s)
|
||||
if [ $SYSTEM = "FreeBSD" ] ; then
|
||||
echo "blobfs.sh cannot run on FreeBSD currently."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
testdir=$(readlink -f $(dirname $0))
|
||||
rootdir=$(readlink -f $testdir/../..)
|
||||
rpc_server=/var/tmp/spdk-blobfs.sock
|
||||
rpc_py="$rootdir/scripts/rpc.py -s $rpc_server"
|
||||
tmp_file=/tmp/blobfs_file
|
||||
conf_file=/tmp/blobfs.conf
|
||||
bdevname=BlobfsBdev
|
||||
|
||||
source $rootdir/test/common/autotest_common.sh
|
||||
|
||||
function on_error_exit() {
|
||||
if [ -n "$blobfs_pid" ]; then
|
||||
killprocess $blobfs_pid
|
||||
fi
|
||||
|
||||
rm -f $tmp_file
|
||||
rm -f $conf_file
|
||||
print_backtrace
|
||||
exit 1
|
||||
}
|
||||
|
||||
function blobfs_start_app {
|
||||
$rootdir/test/app/bdev_svc/bdev_svc -r $rpc_server -c ${conf_file} &
|
||||
blobfs_pid=$!
|
||||
|
||||
echo "Process blobfs pid: $blobfs_pid"
|
||||
waitforlisten $blobfs_pid $rpc_server
|
||||
}
|
||||
|
||||
function blobfs_detect_test() {
|
||||
# Detect out there is no blobfs on test bdev
|
||||
blobfs_start_app
|
||||
result=$($rpc_py blobfs_detect ${bdevname})
|
||||
if [ "${result}" != "False" ]; then
|
||||
false
|
||||
fi
|
||||
|
||||
killprocess $blobfs_pid
|
||||
|
||||
# Create blobfs on test bdev
|
||||
$rootdir/test/blobfs/mkfs/mkfs ${conf_file} ${bdevname}
|
||||
|
||||
# Detect out there is a blobfs on test bdev
|
||||
blobfs_start_app
|
||||
result=$($rpc_py blobfs_detect ${bdevname})
|
||||
if [ "${result}" != "True" ]; then
|
||||
false
|
||||
fi
|
||||
|
||||
killprocess $blobfs_pid
|
||||
}
|
||||
|
||||
timing_enter blobfs
|
||||
|
||||
trap 'on_error_exit;' ERR
|
||||
|
||||
# Create one temp file as test bdev
|
||||
dd if=/dev/zero of=${tmp_file} bs=4k count=1M
|
||||
echo "[AIO]" > ${conf_file}
|
||||
echo "AIO ${tmp_file} ${bdevname} 4096" >> ${conf_file}
|
||||
|
||||
blobfs_detect_test
|
||||
|
||||
rm -f $tmp_file
|
||||
report_test_completion "blobfs"
|
||||
|
||||
timing_exit blobfs
|
@ -34,7 +34,7 @@
|
||||
SPDK_ROOT_DIR := $(abspath $(CURDIR)/../../../..)
|
||||
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
|
||||
|
||||
DIRS-y = tree.c blobfs_async_ut blobfs_sync_ut
|
||||
DIRS-y = tree.c blobfs_async_ut blobfs_sync_ut blobfs_bdev.c
|
||||
|
||||
.PHONY: all clean $(DIRS-y)
|
||||
|
||||
|
1
test/unit/lib/blobfs/blobfs_bdev.c/.gitignore
vendored
Normal file
1
test/unit/lib/blobfs/blobfs_bdev.c/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
blobfs_bdev_ut
|
38
test/unit/lib/blobfs/blobfs_bdev.c/Makefile
Normal file
38
test/unit/lib/blobfs/blobfs_bdev.c/Makefile
Normal file
@ -0,0 +1,38 @@
|
||||
#
|
||||
# BSD LICENSE
|
||||
#
|
||||
# Copyright (c) Intel Corporation.
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# * Neither the name of Intel Corporation nor the names of its
|
||||
# contributors may be used to endorse or promote products derived
|
||||
# from this software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
|
||||
SPDK_ROOT_DIR := $(abspath $(CURDIR)/../../../../..)
|
||||
|
||||
TEST_FILE = blobfs_bdev_ut.c
|
||||
|
||||
include $(SPDK_ROOT_DIR)/mk/spdk.unittest.mk
|
194
test/unit/lib/blobfs/blobfs_bdev.c/blobfs_bdev_ut.c
Normal file
194
test/unit/lib/blobfs/blobfs_bdev.c/blobfs_bdev_ut.c
Normal file
@ -0,0 +1,194 @@
|
||||
/*-
|
||||
* BSD LICENSE
|
||||
*
|
||||
* Copyright (c) Intel Corporation.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Intel Corporation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "spdk_cunit.h"
|
||||
#include "spdk/string.h"
|
||||
#include "spdk/stdinc.h"
|
||||
|
||||
#include "blobfs/bdev/blobfs_bdev.c"
|
||||
|
||||
int g_fserrno;
|
||||
|
||||
bool g_bdev_open_ext_fail = false;
|
||||
bool g_bdev_create_bs_dev_from_desc_fail = false;
|
||||
bool g_fs_load_fail = false;
|
||||
bool g_fs_unload_fail = false;
|
||||
|
||||
const char *g_bdev_name = "ut_bdev";
|
||||
|
||||
int
|
||||
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)
|
||||
{
|
||||
if (g_bdev_open_ext_fail) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct spdk_bs_dev *
|
||||
spdk_bdev_create_bs_dev_from_desc(struct spdk_bdev_desc *desc)
|
||||
{
|
||||
static struct spdk_bs_dev bs_dev;
|
||||
|
||||
if (g_bdev_create_bs_dev_from_desc_fail) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return &bs_dev;
|
||||
}
|
||||
|
||||
void
|
||||
spdk_fs_load(struct spdk_bs_dev *dev, fs_send_request_fn send_request_fn,
|
||||
spdk_fs_op_with_handle_complete cb_fn, void *cb_arg)
|
||||
{
|
||||
int rc = 0;
|
||||
|
||||
if (g_fs_load_fail) {
|
||||
rc = -1;
|
||||
}
|
||||
|
||||
cb_fn(cb_arg, NULL, rc);
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
spdk_fs_unload(struct spdk_filesystem *fs, spdk_fs_op_complete cb_fn, void *cb_arg)
|
||||
{
|
||||
int rc = 0;
|
||||
|
||||
if (g_fs_unload_fail) {
|
||||
rc = -1;
|
||||
}
|
||||
|
||||
cb_fn(cb_arg, rc);
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
spdk_bdev_close(struct spdk_bdev_desc *desc)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
spdk_thread_send_msg(const struct spdk_thread *thread, spdk_msg_fn fn, void *ctx)
|
||||
{
|
||||
fn(ctx);
|
||||
}
|
||||
|
||||
struct spdk_thread *
|
||||
spdk_get_thread(void)
|
||||
{
|
||||
struct spdk_thread *thd = (struct spdk_thread *)0x1;
|
||||
|
||||
return thd;
|
||||
}
|
||||
|
||||
const char *
|
||||
spdk_bdev_get_name(const struct spdk_bdev *bdev)
|
||||
{
|
||||
return g_bdev_name;
|
||||
}
|
||||
|
||||
static void
|
||||
blobfs_bdev_op_complete(void *cb_arg, int fserrno)
|
||||
{
|
||||
g_fserrno = fserrno;
|
||||
}
|
||||
|
||||
static void
|
||||
spdk_blobfs_bdev_detect_test(void)
|
||||
{
|
||||
/* spdk_bdev_open_ext() fails */
|
||||
g_bdev_open_ext_fail = true;
|
||||
spdk_blobfs_bdev_detect(g_bdev_name, blobfs_bdev_op_complete, NULL);
|
||||
CU_ASSERT(g_fserrno != 0);
|
||||
|
||||
g_bdev_open_ext_fail = false;
|
||||
|
||||
/* spdk_bdev_create_bs_dev_from_desc() fails */
|
||||
g_bdev_create_bs_dev_from_desc_fail = true;
|
||||
spdk_blobfs_bdev_detect(g_bdev_name, blobfs_bdev_op_complete, NULL);
|
||||
CU_ASSERT(g_fserrno != 0);
|
||||
|
||||
g_bdev_create_bs_dev_from_desc_fail = false;
|
||||
|
||||
/* spdk_fs_load() fails */
|
||||
g_fs_load_fail = true;
|
||||
spdk_blobfs_bdev_detect(g_bdev_name, blobfs_bdev_op_complete, NULL);
|
||||
CU_ASSERT(g_fserrno != 0);
|
||||
|
||||
g_fs_load_fail = false;
|
||||
|
||||
/* spdk_fs_unload() fails */
|
||||
g_fs_unload_fail = true;
|
||||
spdk_blobfs_bdev_detect(g_bdev_name, blobfs_bdev_op_complete, NULL);
|
||||
CU_ASSERT(g_fserrno != 0);
|
||||
|
||||
g_fs_unload_fail = false;
|
||||
|
||||
/* no fail */
|
||||
spdk_blobfs_bdev_detect(g_bdev_name, blobfs_bdev_op_complete, NULL);
|
||||
CU_ASSERT(g_fserrno == 0);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
CU_pSuite suite = NULL;
|
||||
unsigned int num_failures;
|
||||
|
||||
if (CU_initialize_registry() != CUE_SUCCESS) {
|
||||
return CU_get_error();
|
||||
}
|
||||
|
||||
suite = CU_add_suite("blobfs_bdev_ut", NULL, NULL);
|
||||
if (suite == NULL) {
|
||||
CU_cleanup_registry();
|
||||
return CU_get_error();
|
||||
}
|
||||
|
||||
if (CU_add_test(suite, "spdk_blobfs_bdev_detect_test", spdk_blobfs_bdev_detect_test) == NULL) {
|
||||
CU_cleanup_registry();
|
||||
return CU_get_error();
|
||||
}
|
||||
|
||||
CU_basic_set_mode(CU_BRM_VERBOSE);
|
||||
CU_basic_run_tests();
|
||||
num_failures = CU_get_number_of_failures();
|
||||
CU_cleanup_registry();
|
||||
|
||||
return num_failures;
|
||||
}
|
||||
|
||||
SPDK_LOG_REGISTER_COMPONENT("blobfs", SPDK_LOG_BLOBFS)
|
@ -81,6 +81,7 @@ $valgrind $testdir/lib/blobfs/tree.c/tree_ut
|
||||
$valgrind $testdir/lib/blobfs/blobfs_async_ut/blobfs_async_ut
|
||||
# blobfs_sync_ut hangs when run under valgrind, so don't use $valgrind
|
||||
$testdir/lib/blobfs/blobfs_sync_ut/blobfs_sync_ut
|
||||
$valgrind $testdir/lib/blobfs/blobfs_bdev.c/blobfs_bdev_ut
|
||||
|
||||
$valgrind $testdir/lib/event/subsystem.c/subsystem_ut
|
||||
$valgrind $testdir/lib/event/app.c/app_ut
|
||||
|
Loading…
Reference in New Issue
Block a user