From 220df537d2db926984937e3f4874a4d659cee527 Mon Sep 17 00:00:00 2001 From: Jan Michalski Date: Mon, 23 Feb 2026 13:12:47 +0000 Subject: [PATCH 1/3] DAOS-18608 ddb: md-on-ssd interactive open fix Signed-off-by: Jan Michalski --- src/control/cmd/ddb/ddb_commands.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/control/cmd/ddb/ddb_commands.go b/src/control/cmd/ddb/ddb_commands.go index 7273ac94b52..12fa1c6301b 100644 --- a/src/control/cmd/ddb/ddb_commands.go +++ b/src/control/cmd/ddb/ddb_commands.go @@ -10,10 +10,16 @@ package main import ( "math" + "unsafe" "github.com/desertbit/grumble" ) +/* + #include +*/ +import "C" + func addAppCommands(app *grumble.App, ctx *DdbContext) { // Command: ls app.AddCommand(&grumble.Command{ @@ -51,6 +57,10 @@ pool shard. Part of the path is used to determine what the pool uuid is.`, a.String("path", "Path to the vos file to open.") }, Run: func(c *grumble.Context) error { + if c.Flags.String("db_path") != "" { + ctx.ctx.dc_db_path = C.CString(string(c.Flags.String("db_path"))) + defer C.free(unsafe.Pointer(ctx.ctx.dc_db_path)) + } return ddbOpen(ctx, c.Args.String("path"), c.Flags.Bool("write_mode")) }, Completer: openCompleter, From a635c1b5fa85d2d9b19857ff06f67b2e63071972 Mon Sep 17 00:00:00 2001 From: Jan Michalski Date: Thu, 26 Feb 2026 17:36:28 +0000 Subject: [PATCH 2/3] DAOS-18608 ddb: confine CGo calls to commands_wrapper.go Signed-off-by: Jan Michalski --- src/control/cmd/ddb/commands_wrapper.go | 9 +++++++++ src/control/cmd/ddb/ddb_commands.go | 10 ++-------- src/control/cmd/ddb/main.go | 14 ++++---------- 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/control/cmd/ddb/commands_wrapper.go b/src/control/cmd/ddb/commands_wrapper.go index 1ba453d082d..d9751dbd8e5 100644 --- a/src/control/cmd/ddb/commands_wrapper.go +++ b/src/control/cmd/ddb/commands_wrapper.go @@ -37,6 +37,15 @@ func freeString(s *C.char) { C.free(unsafe.Pointer(s)) } +func SetCString(out **C.char, s string) func() { + cstr := C.CString(s) + *out = cstr + + return func() { + C.free(unsafe.Pointer(cstr)) + } +} + // InitDdb initializes the ddb context and returns a closure to finalize it. func InitDdb(log *logging.LeveledLogger) (*DdbContext, func(), error) { // Must lock to OS thread because vos init/fini uses ABT init and finalize which must be called on the same thread diff --git a/src/control/cmd/ddb/ddb_commands.go b/src/control/cmd/ddb/ddb_commands.go index 12fa1c6301b..d515499264c 100644 --- a/src/control/cmd/ddb/ddb_commands.go +++ b/src/control/cmd/ddb/ddb_commands.go @@ -10,16 +10,10 @@ package main import ( "math" - "unsafe" "github.com/desertbit/grumble" ) -/* - #include -*/ -import "C" - func addAppCommands(app *grumble.App, ctx *DdbContext) { // Command: ls app.AddCommand(&grumble.Command{ @@ -58,8 +52,8 @@ pool shard. Part of the path is used to determine what the pool uuid is.`, }, Run: func(c *grumble.Context) error { if c.Flags.String("db_path") != "" { - ctx.ctx.dc_db_path = C.CString(string(c.Flags.String("db_path"))) - defer C.free(unsafe.Pointer(ctx.ctx.dc_db_path)) + cleanup := SetCString(&ctx.ctx.dc_db_path, c.Flags.String("db_path")) + defer cleanup() } return ddbOpen(ctx, c.Args.String("path"), c.Flags.Bool("write_mode")) }, diff --git a/src/control/cmd/ddb/main.go b/src/control/cmd/ddb/main.go index f61903827b8..e3f64940d64 100644 --- a/src/control/cmd/ddb/main.go +++ b/src/control/cmd/ddb/main.go @@ -16,7 +16,6 @@ import ( "path/filepath" "runtime/debug" "strings" - "unsafe" "github.com/desertbit/columnize" "github.com/desertbit/go-shlex" @@ -31,11 +30,6 @@ import ( "github.com/daos-stack/daos/src/control/server/engine" ) -/* - #include -*/ -import "C" - func exitWithError(err error) { cmdName := path.Base(os.Args[0]) fmt.Fprintf(os.Stderr, "ERROR: %s: %v\n", cmdName, err) @@ -307,13 +301,13 @@ func parseOpts(args []string, opts *cliOptions) error { app := createGrumbleApp(ctx) if opts.SysdbPath != "" { - ctx.ctx.dc_db_path = C.CString(string(opts.SysdbPath)) - defer C.free(unsafe.Pointer(ctx.ctx.dc_db_path)) + cleanup := SetCString(&ctx.ctx.dc_db_path, string(opts.SysdbPath)) + defer cleanup() } if opts.VosPath != "" { - ctx.ctx.dc_pool_path = C.CString(string(opts.VosPath)) - defer C.free(unsafe.Pointer(ctx.ctx.dc_pool_path)) + cleanup := SetCString(&ctx.ctx.dc_pool_path, string(opts.SysdbPath)) + defer cleanup() if !strings.HasPrefix(string(opts.Args.RunCmd), "feature") && !strings.HasPrefix(string(opts.Args.RunCmd), "open") && From 2602883b53eeda0f9c154a606e2227e81b46fd2c Mon Sep 17 00:00:00 2001 From: Jan Michalski Date: Mon, 2 Mar 2026 11:58:36 +0000 Subject: [PATCH 3/3] DAOS-18608 ddb: confine CGo calls to commands_wrapper.go (fix) Signed-off-by: Jan Michalski --- src/control/cmd/ddb/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/control/cmd/ddb/main.go b/src/control/cmd/ddb/main.go index e3f64940d64..9cf5bb2089d 100644 --- a/src/control/cmd/ddb/main.go +++ b/src/control/cmd/ddb/main.go @@ -306,7 +306,7 @@ func parseOpts(args []string, opts *cliOptions) error { } if opts.VosPath != "" { - cleanup := SetCString(&ctx.ctx.dc_pool_path, string(opts.SysdbPath)) + cleanup := SetCString(&ctx.ctx.dc_pool_path, string(opts.VosPath)) defer cleanup() if !strings.HasPrefix(string(opts.Args.RunCmd), "feature") &&