@@ -37,37 +37,67 @@ func freeString(s *C.char) {
3737 C .free (unsafe .Pointer (s ))
3838}
3939
40+ type DdbApi interface {
41+ Init (log * logging.LeveledLogger ) (func (), error )
42+ PoolIsOpen () bool
43+ Ls (path string , recursive bool , details bool ) error
44+ Open (path string , db_path string , write_mode bool ) error
45+ Version () error
46+ Close () error
47+ SuperblockDump () error
48+ ValueDump (path string , dst string ) error
49+ Rm (path string ) error
50+ ValueLoad (src string , dst string ) error
51+ IlogDump (path string ) error
52+ IlogCommit (path string ) error
53+ IlogClear (path string ) error
54+ DtxDump (path string , active bool , committed bool ) error
55+ DtxCmtClear (path string ) error
56+ SmdSync (nvme_conf string , db_path string ) error
57+ VeaDump () error
58+ VeaUpdate (offset string , blk_cnt string ) error
59+ DtxActCommit (path string , dtx_id string ) error
60+ DtxActAbort (path string , dtx_id string ) error
61+ Feature (path , db_path , enable , disable string , show bool ) error
62+ RmPool (path string , db_path string ) error
63+ DtxActDiscardInvalid (path string , dtx_id string ) error
64+ DevList (db_path string ) error
65+ DevReplace (db_path string , old_devid string , new_devid string ) error
66+ DtxStat (path string , details bool ) error
67+ ProvMem (db_path string , tmpfs_mount string , tmpfs_mount_size uint ) error
68+ DtxAggr (path string , cmt_time uint64 , cmt_date string ) error
69+ }
70+
71+ // DdbContext structure for wrapping the C code context structure
72+ type DdbContext struct {
73+ ctx C.struct_ddb_ctx
74+ log * logging.LeveledLogger
75+ }
76+
4077// InitDdb initializes the ddb context and returns a closure to finalize it.
41- func InitDdb ( log * logging.LeveledLogger ) (* DdbContext , func (), error ) {
78+ func ( ctx * DdbContext ) Init ( log * logging.LeveledLogger ) (func (), error ) {
4279 // Must lock to OS thread because vos init/fini uses ABT init and finalize which must be called on the same thread
4380 runtime .LockOSThread ()
4481
4582 if err := daosError (C .ddb_init ()); err != nil {
4683 runtime .UnlockOSThread ()
47- return nil , nil , err
84+ return nil , err
4885 }
4986
50- ctx := & DdbContext {}
5187 C .ddb_ctx_init (& ctx .ctx ) // Initialize with ctx default values
5288 ctx .log = log
5389
54- return ctx , func () {
90+ return func () {
5591 C .ddb_fini ()
5692 runtime .UnlockOSThread ()
5793 }, nil
5894}
5995
60- // DdbContext structure for wrapping the C code context structure
61- type DdbContext struct {
62- ctx C.struct_ddb_ctx
63- log * logging.LeveledLogger
64- }
65-
66- func ddbPoolIsOpen (ctx * DdbContext ) bool {
96+ func (ctx * DdbContext ) PoolIsOpen () bool {
6797 return bool (C .ddb_pool_is_open (& ctx .ctx ))
6898}
6999
70- func ddbLs (ctx * DdbContext , path string , recursive bool , details bool ) error {
100+ func (ctx * DdbContext ) Ls ( path string , recursive bool , details bool ) error {
71101 /* Set up the options */
72102 options := C.struct_ls_options {}
73103 options .path = C .CString (path )
@@ -78,33 +108,34 @@ func ddbLs(ctx *DdbContext, path string, recursive bool, details bool) error {
78108 return daosError (C .ddb_run_ls (& ctx .ctx , & options ))
79109}
80110
81- func ddbOpen (ctx * DdbContext , path string , write_mode bool ) error {
111+ func (ctx * DdbContext ) Open ( path string , db_path string , write_mode bool ) error {
82112 /* Set up the options */
83113 options := C.struct_open_options {}
84114 options .path = C .CString (path )
85115 defer freeString (options .path )
86- options .db_path = ctx .ctx .dc_db_path
116+ options .db_path = C .CString (db_path )
117+ defer freeString (options .db_path )
87118 options .write_mode = C .bool (write_mode )
88119 /* Run the c code command */
89120 return daosError (C .ddb_run_open (& ctx .ctx , & options ))
90121}
91122
92- func ddbVersion (ctx * DdbContext ) error {
123+ func (ctx * DdbContext ) Version ( ) error {
93124 /* Run the c code command */
94125 return daosError (C .ddb_run_version (& ctx .ctx ))
95126}
96127
97- func ddbClose (ctx * DdbContext ) error {
128+ func (ctx * DdbContext ) Close ( ) error {
98129 /* Run the c code command */
99130 return daosError (C .ddb_run_close (& ctx .ctx ))
100131}
101132
102- func ddbSuperblockDump (ctx * DdbContext ) error {
133+ func (ctx * DdbContext ) SuperblockDump ( ) error {
103134 /* Run the c code command */
104135 return daosError (C .ddb_run_superblock_dump (& ctx .ctx ))
105136}
106137
107- func ddbValueDump (ctx * DdbContext , path string , dst string ) error {
138+ func (ctx * DdbContext ) ValueDump ( path string , dst string ) error {
108139 /* Set up the options */
109140 options := C.struct_value_dump_options {}
110141 options .path = C .CString (path )
@@ -115,7 +146,7 @@ func ddbValueDump(ctx *DdbContext, path string, dst string) error {
115146 return daosError (C .ddb_run_value_dump (& ctx .ctx , & options ))
116147}
117148
118- func ddbRm (ctx * DdbContext , path string ) error {
149+ func (ctx * DdbContext ) Rm ( path string ) error {
119150 /* Set up the options */
120151 options := C.struct_rm_options {}
121152 options .path = C .CString (path )
@@ -124,7 +155,7 @@ func ddbRm(ctx *DdbContext, path string) error {
124155 return daosError (C .ddb_run_rm (& ctx .ctx , & options ))
125156}
126157
127- func ddbValueLoad (ctx * DdbContext , src string , dst string ) error {
158+ func (ctx * DdbContext ) ValueLoad ( src string , dst string ) error {
128159 /* Set up the options */
129160 options := C.struct_value_load_options {}
130161 options .src = C .CString (src )
@@ -135,7 +166,7 @@ func ddbValueLoad(ctx *DdbContext, src string, dst string) error {
135166 return daosError (C .ddb_run_value_load (& ctx .ctx , & options ))
136167}
137168
138- func ddbIlogDump (ctx * DdbContext , path string ) error {
169+ func (ctx * DdbContext ) IlogDump ( path string ) error {
139170 /* Set up the options */
140171 options := C.struct_ilog_dump_options {}
141172 options .path = C .CString (path )
@@ -144,7 +175,7 @@ func ddbIlogDump(ctx *DdbContext, path string) error {
144175 return daosError (C .ddb_run_ilog_dump (& ctx .ctx , & options ))
145176}
146177
147- func ddbIlogCommit (ctx * DdbContext , path string ) error {
178+ func (ctx * DdbContext ) IlogCommit ( path string ) error {
148179 /* Set up the options */
149180 options := C.struct_ilog_commit_options {}
150181 options .path = C .CString (path )
@@ -153,7 +184,7 @@ func ddbIlogCommit(ctx *DdbContext, path string) error {
153184 return daosError (C .ddb_run_ilog_commit (& ctx .ctx , & options ))
154185}
155186
156- func ddbIlogClear (ctx * DdbContext , path string ) error {
187+ func (ctx * DdbContext ) IlogClear ( path string ) error {
157188 /* Set up the options */
158189 options := C.struct_ilog_clear_options {}
159190 options .path = C .CString (path )
@@ -162,7 +193,7 @@ func ddbIlogClear(ctx *DdbContext, path string) error {
162193 return daosError (C .ddb_run_ilog_clear (& ctx .ctx , & options ))
163194}
164195
165- func ddbDtxDump (ctx * DdbContext , path string , active bool , committed bool ) error {
196+ func (ctx * DdbContext ) DtxDump ( path string , active bool , committed bool ) error {
166197 /* Set up the options */
167198 options := C.struct_dtx_dump_options {}
168199 options .path = C .CString (path )
@@ -173,7 +204,7 @@ func ddbDtxDump(ctx *DdbContext, path string, active bool, committed bool) error
173204 return daosError (C .ddb_run_dtx_dump (& ctx .ctx , & options ))
174205}
175206
176- func ddbDtxCmtClear (ctx * DdbContext , path string ) error {
207+ func (ctx * DdbContext ) DtxCmtClear ( path string ) error {
177208 /* Set up the options */
178209 options := C.struct_dtx_cmt_clear_options {}
179210 options .path = C .CString (path )
@@ -182,7 +213,7 @@ func ddbDtxCmtClear(ctx *DdbContext, path string) error {
182213 return daosError (C .ddb_run_dtx_cmt_clear (& ctx .ctx , & options ))
183214}
184215
185- func ddbSmdSync (ctx * DdbContext , nvme_conf string , db_path string ) error {
216+ func (ctx * DdbContext ) SmdSync ( nvme_conf string , db_path string ) error {
186217 /* Set up the options */
187218 options := C.struct_smd_sync_options {}
188219 options .nvme_conf = C .CString (nvme_conf )
@@ -193,12 +224,12 @@ func ddbSmdSync(ctx *DdbContext, nvme_conf string, db_path string) error {
193224 return daosError (C .ddb_run_smd_sync (& ctx .ctx , & options ))
194225}
195226
196- func ddbVeaDump (ctx * DdbContext ) error {
227+ func (ctx * DdbContext ) VeaDump ( ) error {
197228 /* Run the c code command */
198229 return daosError (C .ddb_run_vea_dump (& ctx .ctx ))
199230}
200231
201- func ddbVeaUpdate (ctx * DdbContext , offset string , blk_cnt string ) error {
232+ func (ctx * DdbContext ) VeaUpdate ( offset string , blk_cnt string ) error {
202233 /* Set up the options */
203234 options := C.struct_vea_update_options {}
204235 options .offset = C .CString (offset )
@@ -209,7 +240,7 @@ func ddbVeaUpdate(ctx *DdbContext, offset string, blk_cnt string) error {
209240 return daosError (C .ddb_run_vea_update (& ctx .ctx , & options ))
210241}
211242
212- func ddbDtxActCommit (ctx * DdbContext , path string , dtx_id string ) error {
243+ func (ctx * DdbContext ) DtxActCommit ( path string , dtx_id string ) error {
213244 /* Set up the options */
214245 options := C.struct_dtx_act_options {}
215246 options .path = C .CString (path )
@@ -220,7 +251,7 @@ func ddbDtxActCommit(ctx *DdbContext, path string, dtx_id string) error {
220251 return daosError (C .ddb_run_dtx_act_commit (& ctx .ctx , & options ))
221252}
222253
223- func ddbDtxActAbort (ctx * DdbContext , path string , dtx_id string ) error {
254+ func (ctx * DdbContext ) DtxActAbort ( path string , dtx_id string ) error {
224255 /* Set up the options */
225256 options := C.struct_dtx_act_options {}
226257 options .path = C .CString (path )
@@ -231,12 +262,13 @@ func ddbDtxActAbort(ctx *DdbContext, path string, dtx_id string) error {
231262 return daosError (C .ddb_run_dtx_act_abort (& ctx .ctx , & options ))
232263}
233264
234- func ddbFeature (ctx * DdbContext , path , enable , disable string , show bool ) error {
265+ func (ctx * DdbContext ) Feature ( path , db_path , enable , disable string , show bool ) error {
235266 /* Set up the options */
236267 options := C.struct_feature_options {}
237268 options .path = C .CString (path )
238269 defer freeString (options .path )
239- options .db_path = ctx .ctx .dc_db_path
270+ options .db_path = C .CString (db_path )
271+ defer freeString (options .db_path )
240272 if enable != "" {
241273 err := daosError (C .ddb_feature_string2flags (& ctx .ctx , C .CString (enable ),
242274 & options .set_compat_flags , & options .set_incompat_flags ))
@@ -256,17 +288,18 @@ func ddbFeature(ctx *DdbContext, path, enable, disable string, show bool) error
256288 return daosError (C .ddb_run_feature (& ctx .ctx , & options ))
257289}
258290
259- func ddbRmPool (ctx * DdbContext , path string ) error {
291+ func (ctx * DdbContext ) RmPool ( path string , db_path string ) error {
260292 /* Set up the options */
261293 options := C.struct_rm_pool_options {}
262294 options .path = C .CString (path )
263295 defer freeString (options .path )
264- options .db_path = ctx .ctx .dc_db_path
296+ options .db_path = C .CString (db_path )
297+ defer freeString (options .db_path )
265298 /* Run the c code command */
266299 return daosError (C .ddb_run_rm_pool (& ctx .ctx , & options ))
267300}
268301
269- func ddbDtxActDiscardInvalid (ctx * DdbContext , path string , dtx_id string ) error {
302+ func (ctx * DdbContext ) DtxActDiscardInvalid ( path string , dtx_id string ) error {
270303 /* Set up the options */
271304 options := C.struct_dtx_act_options {}
272305 options .path = C .CString (path )
@@ -277,7 +310,7 @@ func ddbDtxActDiscardInvalid(ctx *DdbContext, path string, dtx_id string) error
277310 return daosError (C .ddb_run_dtx_act_discard_invalid (& ctx .ctx , & options ))
278311}
279312
280- func ddbDevList (ctx * DdbContext , db_path string ) error {
313+ func (ctx * DdbContext ) DevList ( db_path string ) error {
281314 /* Set up the options */
282315 options := C.struct_dev_list_options {}
283316 options .db_path = C .CString (db_path )
@@ -286,7 +319,7 @@ func ddbDevList(ctx *DdbContext, db_path string) error {
286319 return daosError (C .ddb_run_dev_list (& ctx .ctx , & options ))
287320}
288321
289- func ddbDevReplace (ctx * DdbContext , db_path string , old_devid string , new_devid string ) error {
322+ func (ctx * DdbContext ) DevReplace ( db_path string , old_devid string , new_devid string ) error {
290323 /* Set up the options */
291324 options := C.struct_dev_replace_options {}
292325 options .db_path = C .CString (db_path )
@@ -299,7 +332,7 @@ func ddbDevReplace(ctx *DdbContext, db_path string, old_devid string, new_devid
299332 return daosError (C .ddb_run_dev_replace (& ctx .ctx , & options ))
300333}
301334
302- func ddbDtxStat (ctx * DdbContext , path string , details bool ) error {
335+ func (ctx * DdbContext ) DtxStat ( path string , details bool ) error {
303336 /* Set up the options */
304337 options := C.struct_dtx_stat_options {}
305338 options .path = C .CString (path )
@@ -309,7 +342,7 @@ func ddbDtxStat(ctx *DdbContext, path string, details bool) error {
309342 return daosError (C .ddb_run_dtx_stat (& ctx .ctx , & options ))
310343}
311344
312- func ddbProvMem (ctx * DdbContext , db_path string , tmpfs_mount string , tmpfs_mount_size uint ) error {
345+ func (ctx * DdbContext ) ProvMem ( db_path string , tmpfs_mount string , tmpfs_mount_size uint ) error {
313346 /* Set up the options */
314347 options := C.struct_prov_mem_options {}
315348 options .db_path = C .CString (db_path )
@@ -322,7 +355,7 @@ func ddbProvMem(ctx *DdbContext, db_path string, tmpfs_mount string, tmpfs_mount
322355 return daosError (C .ddb_run_prov_mem (& ctx .ctx , & options ))
323356}
324357
325- func ddbDtxAggr (ctx * DdbContext , path string , cmt_time uint64 , cmt_date string ) error {
358+ func (ctx * DdbContext ) DtxAggr ( path string , cmt_time uint64 , cmt_date string ) error {
326359 if cmt_time != math .MaxUint64 && cmt_date != "" {
327360 ctx .log .Error ("'--cmt_time' and '--cmt_date' options are mutually exclusive" )
328361 return daosError (- C .DER_INVAL )
0 commit comments