Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/control/cmd/ddb/commands_wrapper.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// (C) Copyright 2022-2024 Intel Corporation.
// (C) Copyright 2025 Hewlett Packard Enterprise Development LP.

Check failure on line 3 in src/control/cmd/ddb/commands_wrapper.go

View workflow job for this annotation

GitHub Actions / Copyright check

Copyright out of date
// (C) Copyright 2025 Vdura Inc.
//
// SPDX-License-Identifier: BSD-2-Clause-Patent
Expand Down Expand Up @@ -258,11 +258,13 @@
return daosError(C.ddb_run_feature(&ctx.ctx, &options))
}

func ddbRmPool(ctx *DdbContext, path string) error {
func ddbRmPool(ctx *DdbContext, path string, db_path string) error {
/* Set up the options */
options := C.struct_rm_pool_options{}
options.path = C.CString(path)
defer freeString(options.path)
options.db_path = C.CString(db_path)
defer freeString(options.db_path)
/* Run the c code command */
return daosError(C.ddb_run_rm_pool(&ctx.ctx, &options))
}
Expand Down
5 changes: 4 additions & 1 deletion src/control/cmd/ddb/ddb_commands.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// (C) Copyright 2022-2024 Intel Corporation.
// (C) Copyright 2025 Vdura Inc.
// (C) Copyright 2025 Hewlett Packard Enterprise Development LP.

Check failure on line 4 in src/control/cmd/ddb/ddb_commands.go

View workflow job for this annotation

GitHub Actions / Copyright check

Copyright out of date
//
// SPDX-License-Identifier: BSD-2-Clause-Patent
//
Expand Down Expand Up @@ -330,11 +330,14 @@
Help: "Remove a vos pool.",
LongHelp: "",
HelpGroup: "vos",
Flags: func(f *grumble.Flags) {
f.String("p", "db_path", "", "Path to the sys db")
},
Args: func(a *grumble.Args) {
a.String("path", "Optional, Path to the vos file", grumble.Default(""))
},
Run: func(c *grumble.Context) error {
return ddbRmPool(ctx, c.Args.String("path"))
return ddbRmPool(ctx, c.Args.String("path"), c.Flags.String("db_path"))
},
Completer: rmPoolCompleter,
})
Expand Down
32 changes: 25 additions & 7 deletions src/control/cmd/ddb/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// (C) Copyright 2022-2024 Intel Corporation.
// (C) Copyright 2025 Hewlett Packard Enterprise Development LP

Check failure on line 3 in src/control/cmd/ddb/main.go

View workflow job for this annotation

GitHub Actions / Copyright check

Copyright out of date
//
// SPDX-License-Identifier: BSD-2-Clause-Patent
//
Expand Down Expand Up @@ -179,6 +179,10 @@
return nil
}

if opts.Args.RunCmd != "" && opts.CmdFile != "" {
return errors.New("Cannot use both command file and a command string")
}

if opts.Debug {
log.WithLogLevel(logging.LogLevelDebug)
log.Debug("debug output enabled")
Expand All @@ -193,6 +197,10 @@

if opts.Args.VosPath != "" {
if !strings.HasPrefix(string(opts.Args.RunCmd), "feature") &&
!strings.HasPrefix(string(opts.Args.RunCmd), "open") &&
!strings.HasPrefix(string(opts.Args.RunCmd), "close") &&
!strings.HasPrefix(string(opts.Args.RunCmd), "prov_mem") &&
!strings.HasPrefix(string(opts.Args.RunCmd), "smd_sync") &&
!strings.HasPrefix(string(opts.Args.RunCmd), "rm_pool") &&
!strings.HasPrefix(string(opts.Args.RunCmd), "dev_list") &&
!strings.HasPrefix(string(opts.Args.RunCmd), "dev_replace") {
Expand All @@ -201,20 +209,30 @@
return errors.Wrapf(err, "Error opening path: %s", opts.Args.VosPath)
}
}
}

if opts.Args.RunCmd != "" && opts.CmdFile != "" {
return errors.New("Cannot use both command file and a command string")
}

if opts.Args.VosPath != "" {
ctx.ctx.dc_pool_path = C.CString(string(opts.Args.VosPath))
defer C.free(unsafe.Pointer(ctx.ctx.dc_pool_path))
}

if opts.Args.RunCmd != "" || opts.CmdFile != "" {
// Non-interactive mode
if opts.Args.RunCmd != "" {
err := runCmdStr(app, string(opts.Args.RunCmd), opts.Args.RunCmdArgs...)
if ddbPoolIsOpen(ctx) {
err = runCmdStr(app, string(opts.Args.RunCmd), opts.Args.RunCmdArgs...)
} else {
param := []string{}
skip := true

for _, v := range args {
if v == string(opts.Args.VosPath) && skip {
skip = false
} else if v != string(opts.Args.RunCmd) {
param = append(param, v)
}
}

err = runCmdStr(app, string(opts.Args.RunCmd), param...)
}
if err != nil {
log.Errorf("Error running command %q %s\n", string(opts.Args.RunCmd), err)
}
Expand Down
1 change: 1 addition & 0 deletions src/utils/ddb/ddb.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* (C) Copyright 2022-2024 Intel Corporation.
* (C) Copyright 2025 Hewlett Packard Enterprise Development LP.

Check failure on line 3 in src/utils/ddb/ddb.h

View workflow job for this annotation

GitHub Actions / Copyright check

Copyright out of date
* (C) Copyright 2025 Vdura Inc.
*
* SPDX-License-Identifier: BSD-2-Clause-Patent
Expand Down Expand Up @@ -204,6 +204,7 @@

struct rm_pool_options {
const char *path;
const char *db_path;
};

struct dev_list_options {
Expand Down
100 changes: 59 additions & 41 deletions src/utils/ddb/ddb_commands.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* (C) Copyright 2022-2024 Intel Corporation.
* (C) Copyright 2025 Vdura Inc.
* (C) Copyright 2025 Hewlett Packard Enterprise Development LP.

Check failure on line 4 in src/utils/ddb/ddb_commands.c

View workflow job for this annotation

GitHub Actions / Copyright check

Copyright out of date
*
* SPDX-License-Identifier: BSD-2-Clause-Patent
*/
Expand All @@ -27,6 +27,24 @@
#define ilog_path_required_error_message "Path to object, dkey, or akey required\n"
#define error_msg_write_mode_only "Can only modify the VOS tree in 'write mode'\n"

/* clang-format off */
#define DDB_POOL_SHOULD_OPEN(ctx) \
do { \
if (daos_handle_is_inval((ctx)->dc_poh)) { \
ddb_error(ctx, "Cannot operate on a closed pool. Open it firstly.\n"); \
return -DER_NO_HDL; \
} \
} while (0)

#define DDB_POOL_SHOULD_CLOSE(ctx) \
do { \
if (daos_handle_is_valid((ctx)->dc_poh)) { \
ddb_error(ctx, "Cannot operate on an opened pool. Close it firstly.\n"); \
return -DER_BUSY; \
} \
} while (0)
/* clang-format on */

int
ddb_run_version(struct ddb_ctx *ctx)
{
Expand Down Expand Up @@ -62,10 +80,8 @@
int
ddb_run_open(struct ddb_ctx *ctx, struct open_options *opt)
{
if (ddb_pool_is_open(ctx)) {
ddb_error(ctx, "Must close pool before can open another\n");
return -DER_EXIST;
}
DDB_POOL_SHOULD_CLOSE(ctx);

ctx->dc_write_mode = opt->write_mode;
return dv_pool_open(opt->path, opt->db_path, &ctx->dc_poh, 0);
}
Expand All @@ -75,10 +91,8 @@
{
int rc;

if (!ddb_pool_is_open(ctx)) {
ddb_error(ctx, "No pool open to close\n");
if (!ddb_pool_is_open(ctx))
return 0;
}

rc = dv_pool_close(ctx->dc_poh);
ctx->dc_poh = DAOS_HDL_INVAL;
Expand Down Expand Up @@ -217,12 +231,9 @@
struct dv_tree_path vtp;
struct ls_ctx lsctx = {0};

if (daos_handle_is_inval(ctx->dc_poh)) {
ddb_error(ctx, "Not connected to a pool. Use 'open' to connect to a pool.\n");
return -DER_NONEXIST;
}
rc = init_path(ctx, opt->path, &itp);
DDB_POOL_SHOULD_OPEN(ctx);

rc = init_path(ctx, opt->path, &itp);
if (!SUCCESS(rc))
return rc;

Expand Down Expand Up @@ -266,8 +277,9 @@
{
int rc;

rc = dv_superblock(ctx->dc_poh, print_superblock_cb, ctx);
DDB_POOL_SHOULD_OPEN(ctx);

rc = dv_superblock(ctx->dc_poh, print_superblock_cb, ctx);
if (rc == -DER_DF_INVAL)
ddb_error(ctx, "Error with pool superblock");

Expand Down Expand Up @@ -331,6 +343,8 @@
dv_dump_value_cb cb = NULL;
int rc;

DDB_POOL_SHOULD_OPEN(ctx);

if (!opt->path) {
ddb_error(ctx, "A VOS path to dump is required.\n");
return -DER_INVAL;
Expand Down Expand Up @@ -383,6 +397,8 @@
daos_handle_t coh;
int rc;

DDB_POOL_SHOULD_OPEN(ctx);

if (!opt->path) {
ddb_error(ctx, ilog_path_required_error_message);
return -DER_INVAL;
Expand Down Expand Up @@ -460,6 +476,8 @@
bool both = !(opt->committed ^ opt->active);
struct dtx_cb_args args = {.ctx = ctx, .entry_count = 0};

DDB_POOL_SHOULD_OPEN(ctx);

rc = init_path(ctx, opt->path, &itp);
if (!SUCCESS(rc))
return rc;
Expand Down Expand Up @@ -512,6 +530,8 @@
struct dv_tree_path vtp;
int rc;

DDB_POOL_SHOULD_OPEN(ctx);

if (!ctx->dc_write_mode) {
ddb_error(ctx, error_msg_write_mode_only);
return -DER_INVAL;
Expand Down Expand Up @@ -549,6 +569,8 @@
size_t file_size;
int rc;

DDB_POOL_SHOULD_OPEN(ctx);

if (!ctx->dc_write_mode) {
ddb_error(ctx, error_msg_write_mode_only);
return -DER_INVAL;
Expand Down Expand Up @@ -616,6 +638,8 @@
daos_handle_t coh = {0};
int rc;

DDB_POOL_SHOULD_OPEN(ctx);

if (!ctx->dc_write_mode) {
ddb_error(ctx, error_msg_write_mode_only);
return -DER_INVAL;
Expand Down Expand Up @@ -686,6 +710,8 @@
daos_handle_t coh = {0};
int rc;

DDB_POOL_SHOULD_OPEN(ctx);

if (!ctx->dc_write_mode) {
ddb_error(ctx, error_msg_write_mode_only);
return -DER_INVAL;
Expand Down Expand Up @@ -764,10 +790,7 @@
char db_path[DDB_PATH_MAX] = DEFAULT_DB_PATH;
int rc;

if (daos_handle_is_valid(ctx->dc_poh)) {
ddb_print(ctx, "Close pool connection before attempting to sync smd\n");
return -DER_INVAL;
}
DDB_POOL_SHOULD_CLOSE(ctx);

if (opt->nvme_conf != NULL) {
if (strlen(opt->nvme_conf) == 0 || strlen(opt->nvme_conf) >= DDB_PATH_MAX) {
Expand Down Expand Up @@ -816,6 +839,8 @@
struct dump_vea_cb_args args = {.dva_ctx = ctx, .dva_count = 0};
int rc;

DDB_POOL_SHOULD_OPEN(ctx);

rc = dv_enumerate_vea(ctx->dc_poh, dump_vea_cb, &args);

ddb_printf(ctx, "Total Free Regions: %d\n", args.dva_count);
Expand Down Expand Up @@ -894,6 +919,8 @@
uint32_t blk_cnt;
int rc;

DDB_POOL_SHOULD_OPEN(ctx);

if (!ctx->dc_write_mode) {
ddb_error(ctx, error_msg_write_mode_only);
return -DER_INVAL;
Expand Down Expand Up @@ -983,6 +1010,8 @@
struct dtx_modify_args args = {0};
int rc;

DDB_POOL_SHOULD_OPEN(ctx);

if (!ctx->dc_write_mode) {
ddb_error(ctx, error_msg_write_mode_only);
return -DER_INVAL;
Expand Down Expand Up @@ -1013,6 +1042,8 @@
struct dtx_modify_args args = {0};
int rc;

DDB_POOL_SHOULD_OPEN(ctx);

if (!ctx->dc_write_mode) {
ddb_error(ctx, error_msg_write_mode_only);
return -DER_INVAL;
Expand Down Expand Up @@ -1115,12 +1146,9 @@
int
ddb_run_rm_pool(struct ddb_ctx *ctx, struct rm_pool_options *opt)
{
if (ddb_pool_is_open(ctx)) {
ddb_error(ctx, "Must close pool before can open another\n");
return -DER_BUSY;
}
DDB_POOL_SHOULD_CLOSE(ctx);

return dv_pool_destroy(opt->path);
return dv_pool_destroy(opt->path, opt->db_path);
}

#define DTI_ALL "all"
Expand Down Expand Up @@ -1161,6 +1189,8 @@
struct dtx_active_entry_discard_invalid_cb_arg bundle = {.ctx = ctx, .args = &args};
int rc;

DDB_POOL_SHOULD_OPEN(ctx);

if (!ctx->dc_write_mode) {
ddb_error(ctx, error_msg_write_mode_only);
return -DER_INVAL;
Expand Down Expand Up @@ -1197,10 +1227,7 @@
d_list_t dev_list;
int rc, dev_cnt = 0;

if (daos_handle_is_valid(ctx->dc_poh)) {
ddb_print(ctx, "Close pool connection before attempting to list devices\n");
return -DER_INVAL;
}
DDB_POOL_SHOULD_CLOSE(ctx);

if (opt->db_path != NULL) {
if (strlen(opt->db_path) == 0 || strlen(opt->db_path) >= DDB_PATH_MAX) {
Expand Down Expand Up @@ -1240,10 +1267,7 @@
uuid_t old_devid, new_devid;
int rc;

if (daos_handle_is_valid(ctx->dc_poh)) {
ddb_print(ctx, "Close pool connection before attempting to replace device\n");
return -DER_INVAL;
}
DDB_POOL_SHOULD_CLOSE(ctx);

if (opt->db_path != NULL) {
if (strlen(opt->db_path) == 0 || strlen(opt->db_path) >= DDB_PATH_MAX) {
Expand Down Expand Up @@ -1591,11 +1615,7 @@
struct vos_iter_anchors anchors = {0};
int rc;

if (daos_handle_is_inval(ctx->dc_poh)) {
ddb_error(ctx, "Not connected to a pool. Use 'open' to connect to a pool.\n");
rc = -DER_NONEXIST;
goto done;
}
DDB_POOL_SHOULD_OPEN(ctx);

args.ctx = ctx;
args.opt = opt;
Expand Down Expand Up @@ -1723,18 +1743,14 @@
struct vos_iter_anchors anchors = {0};
int rc;

DDB_POOL_SHOULD_OPEN(ctx);

if (!ctx->dc_write_mode) {
ddb_error(ctx, error_msg_write_mode_only);
rc = -DER_INVAL;
goto done;
}

if (daos_handle_is_inval(ctx->dc_poh)) {
ddb_error(ctx, "Not connected to a pool. Use 'open' to connect to a pool.\n");
rc = -DER_NONEXIST;
goto done;
}

switch (opt->format) {
case DDB_DTX_AGGR_NOW:
args.cmt_time = NULL;
Expand Down Expand Up @@ -1774,6 +1790,8 @@
{
int rc = 0;

DDB_POOL_SHOULD_CLOSE(ctx);

if (opt->db_path == NULL || strlen(opt->db_path) == 0 ||
strlen(opt->db_path) >= DDB_PATH_MAX) {
ddb_errorf(ctx, "db_path '%s' either too short (==0) or too long (>=%d).\n",
Expand Down
2 changes: 1 addition & 1 deletion src/utils/ddb/ddb_parse.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* (C) Copyright 2019-2024 Intel Corporation.
* (C) Copyright 2025 Hewlett Packard Enterprise Development LP

Check failure on line 3 in src/utils/ddb/ddb_parse.h

View workflow job for this annotation

GitHub Actions / Copyright check

Copyright out of date
*
* SPDX-License-Identifier: BSD-2-Clause-Patent
*/
Expand All @@ -23,7 +23,7 @@
bool pa_write_mode;
bool pa_get_help;
};
#define DB_PATH_LEN 64
#define DB_PATH_LEN 256
struct vos_file_parts {
char vf_db_path[DB_PATH_LEN];
uuid_t vf_pool_uuid;
Expand Down
Loading
Loading