@@ -37,46 +37,67 @@ func freeString(s *C.char) {
3737 C .free (unsafe .Pointer (s ))
3838}
3939
40- func SetCString (out * * C.char , s string ) func () {
41- cstr := C .CString (s )
42- * out = cstr
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+ }
4370
44- return func () {
45- C .free (unsafe .Pointer (cstr ))
46- }
71+ // DdbContext structure for wrapping the C code context structure
72+ type DdbContext struct {
73+ ctx C.struct_ddb_ctx
74+ log * logging.LeveledLogger
4775}
4876
49- // InitDdb initializes the ddb context and returns a closure to finalize it.
50- func InitDdb ( log * logging.LeveledLogger ) (* DdbContext , func (), error ) {
77+ // Init initializes the ddb context and returns a closure to finalize it.
78+ func ( ctx * DdbContext ) Init ( log * logging.LeveledLogger ) (func (), error ) {
5179 // Must lock to OS thread because vos init/fini uses ABT init and finalize which must be called on the same thread
5280 runtime .LockOSThread ()
5381
5482 if err := daosError (C .ddb_init ()); err != nil {
5583 runtime .UnlockOSThread ()
56- return nil , nil , err
84+ return nil , err
5785 }
5886
59- ctx := & DdbContext {}
6087 C .ddb_ctx_init (& ctx .ctx ) // Initialize with ctx default values
6188 ctx .log = log
6289
63- return ctx , func () {
90+ return func () {
6491 C .ddb_fini ()
6592 runtime .UnlockOSThread ()
6693 }, nil
6794}
6895
69- // DdbContext structure for wrapping the C code context structure
70- type DdbContext struct {
71- ctx C.struct_ddb_ctx
72- log * logging.LeveledLogger
73- }
74-
75- func ddbPoolIsOpen (ctx * DdbContext ) bool {
96+ func (ctx * DdbContext ) PoolIsOpen () bool {
7697 return bool (C .ddb_pool_is_open (& ctx .ctx ))
7798}
7899
79- func ddbLs (ctx * DdbContext , path string , recursive bool , details bool ) error {
100+ func (ctx * DdbContext ) Ls ( path string , recursive bool , details bool ) error {
80101 /* Set up the options */
81102 options := C.struct_ls_options {}
82103 options .path = C .CString (path )
@@ -87,33 +108,34 @@ func ddbLs(ctx *DdbContext, path string, recursive bool, details bool) error {
87108 return daosError (C .ddb_run_ls (& ctx .ctx , & options ))
88109}
89110
90- func ddbOpen (ctx * DdbContext , path string , write_mode bool ) error {
111+ func (ctx * DdbContext ) Open ( path string , db_path string , write_mode bool ) error {
91112 /* Set up the options */
92113 options := C.struct_open_options {}
93114 options .path = C .CString (path )
94115 defer freeString (options .path )
95- options .db_path = ctx .ctx .dc_db_path
116+ options .db_path = C .CString (db_path )
117+ defer freeString (options .db_path )
96118 options .write_mode = C .bool (write_mode )
97119 /* Run the c code command */
98120 return daosError (C .ddb_run_open (& ctx .ctx , & options ))
99121}
100122
101- func ddbVersion (ctx * DdbContext ) error {
123+ func (ctx * DdbContext ) Version ( ) error {
102124 /* Run the c code command */
103125 return daosError (C .ddb_run_version (& ctx .ctx ))
104126}
105127
106- func ddbClose (ctx * DdbContext ) error {
128+ func (ctx * DdbContext ) Close ( ) error {
107129 /* Run the c code command */
108130 return daosError (C .ddb_run_close (& ctx .ctx ))
109131}
110132
111- func ddbSuperblockDump (ctx * DdbContext ) error {
133+ func (ctx * DdbContext ) SuperblockDump ( ) error {
112134 /* Run the c code command */
113135 return daosError (C .ddb_run_superblock_dump (& ctx .ctx ))
114136}
115137
116- func ddbValueDump (ctx * DdbContext , path string , dst string ) error {
138+ func (ctx * DdbContext ) ValueDump ( path string , dst string ) error {
117139 /* Set up the options */
118140 options := C.struct_value_dump_options {}
119141 options .path = C .CString (path )
@@ -124,7 +146,7 @@ func ddbValueDump(ctx *DdbContext, path string, dst string) error {
124146 return daosError (C .ddb_run_value_dump (& ctx .ctx , & options ))
125147}
126148
127- func ddbRm (ctx * DdbContext , path string ) error {
149+ func (ctx * DdbContext ) Rm ( path string ) error {
128150 /* Set up the options */
129151 options := C.struct_rm_options {}
130152 options .path = C .CString (path )
@@ -133,7 +155,7 @@ func ddbRm(ctx *DdbContext, path string) error {
133155 return daosError (C .ddb_run_rm (& ctx .ctx , & options ))
134156}
135157
136- func ddbValueLoad (ctx * DdbContext , src string , dst string ) error {
158+ func (ctx * DdbContext ) ValueLoad ( src string , dst string ) error {
137159 /* Set up the options */
138160 options := C.struct_value_load_options {}
139161 options .src = C .CString (src )
@@ -144,7 +166,7 @@ func ddbValueLoad(ctx *DdbContext, src string, dst string) error {
144166 return daosError (C .ddb_run_value_load (& ctx .ctx , & options ))
145167}
146168
147- func ddbIlogDump (ctx * DdbContext , path string ) error {
169+ func (ctx * DdbContext ) IlogDump ( path string ) error {
148170 /* Set up the options */
149171 options := C.struct_ilog_dump_options {}
150172 options .path = C .CString (path )
@@ -153,7 +175,7 @@ func ddbIlogDump(ctx *DdbContext, path string) error {
153175 return daosError (C .ddb_run_ilog_dump (& ctx .ctx , & options ))
154176}
155177
156- func ddbIlogCommit (ctx * DdbContext , path string ) error {
178+ func (ctx * DdbContext ) IlogCommit ( path string ) error {
157179 /* Set up the options */
158180 options := C.struct_ilog_commit_options {}
159181 options .path = C .CString (path )
@@ -162,7 +184,7 @@ func ddbIlogCommit(ctx *DdbContext, path string) error {
162184 return daosError (C .ddb_run_ilog_commit (& ctx .ctx , & options ))
163185}
164186
165- func ddbIlogClear (ctx * DdbContext , path string ) error {
187+ func (ctx * DdbContext ) IlogClear ( path string ) error {
166188 /* Set up the options */
167189 options := C.struct_ilog_clear_options {}
168190 options .path = C .CString (path )
@@ -171,7 +193,7 @@ func ddbIlogClear(ctx *DdbContext, path string) error {
171193 return daosError (C .ddb_run_ilog_clear (& ctx .ctx , & options ))
172194}
173195
174- func ddbDtxDump (ctx * DdbContext , path string , active bool , committed bool ) error {
196+ func (ctx * DdbContext ) DtxDump ( path string , active bool , committed bool ) error {
175197 /* Set up the options */
176198 options := C.struct_dtx_dump_options {}
177199 options .path = C .CString (path )
@@ -182,7 +204,7 @@ func ddbDtxDump(ctx *DdbContext, path string, active bool, committed bool) error
182204 return daosError (C .ddb_run_dtx_dump (& ctx .ctx , & options ))
183205}
184206
185- func ddbDtxCmtClear (ctx * DdbContext , path string ) error {
207+ func (ctx * DdbContext ) DtxCmtClear ( path string ) error {
186208 /* Set up the options */
187209 options := C.struct_dtx_cmt_clear_options {}
188210 options .path = C .CString (path )
@@ -191,7 +213,7 @@ func ddbDtxCmtClear(ctx *DdbContext, path string) error {
191213 return daosError (C .ddb_run_dtx_cmt_clear (& ctx .ctx , & options ))
192214}
193215
194- func ddbSmdSync (ctx * DdbContext , nvme_conf string , db_path string ) error {
216+ func (ctx * DdbContext ) SmdSync ( nvme_conf string , db_path string ) error {
195217 /* Set up the options */
196218 options := C.struct_smd_sync_options {}
197219 options .nvme_conf = C .CString (nvme_conf )
@@ -202,12 +224,12 @@ func ddbSmdSync(ctx *DdbContext, nvme_conf string, db_path string) error {
202224 return daosError (C .ddb_run_smd_sync (& ctx .ctx , & options ))
203225}
204226
205- func ddbVeaDump (ctx * DdbContext ) error {
227+ func (ctx * DdbContext ) VeaDump ( ) error {
206228 /* Run the c code command */
207229 return daosError (C .ddb_run_vea_dump (& ctx .ctx ))
208230}
209231
210- func ddbVeaUpdate (ctx * DdbContext , offset string , blk_cnt string ) error {
232+ func (ctx * DdbContext ) VeaUpdate ( offset string , blk_cnt string ) error {
211233 /* Set up the options */
212234 options := C.struct_vea_update_options {}
213235 options .offset = C .CString (offset )
@@ -218,7 +240,7 @@ func ddbVeaUpdate(ctx *DdbContext, offset string, blk_cnt string) error {
218240 return daosError (C .ddb_run_vea_update (& ctx .ctx , & options ))
219241}
220242
221- func ddbDtxActCommit (ctx * DdbContext , path string , dtx_id string ) error {
243+ func (ctx * DdbContext ) DtxActCommit ( path string , dtx_id string ) error {
222244 /* Set up the options */
223245 options := C.struct_dtx_act_options {}
224246 options .path = C .CString (path )
@@ -229,7 +251,7 @@ func ddbDtxActCommit(ctx *DdbContext, path string, dtx_id string) error {
229251 return daosError (C .ddb_run_dtx_act_commit (& ctx .ctx , & options ))
230252}
231253
232- func ddbDtxActAbort (ctx * DdbContext , path string , dtx_id string ) error {
254+ func (ctx * DdbContext ) DtxActAbort ( path string , dtx_id string ) error {
233255 /* Set up the options */
234256 options := C.struct_dtx_act_options {}
235257 options .path = C .CString (path )
@@ -240,12 +262,13 @@ func ddbDtxActAbort(ctx *DdbContext, path string, dtx_id string) error {
240262 return daosError (C .ddb_run_dtx_act_abort (& ctx .ctx , & options ))
241263}
242264
243- 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 {
244266 /* Set up the options */
245267 options := C.struct_feature_options {}
246268 options .path = C .CString (path )
247269 defer freeString (options .path )
248- options .db_path = ctx .ctx .dc_db_path
270+ options .db_path = C .CString (db_path )
271+ defer freeString (options .db_path )
249272 if enable != "" {
250273 err := daosError (C .ddb_feature_string2flags (& ctx .ctx , C .CString (enable ),
251274 & options .set_compat_flags , & options .set_incompat_flags ))
@@ -265,17 +288,18 @@ func ddbFeature(ctx *DdbContext, path, enable, disable string, show bool) error
265288 return daosError (C .ddb_run_feature (& ctx .ctx , & options ))
266289}
267290
268- func ddbRmPool (ctx * DdbContext , path string ) error {
291+ func (ctx * DdbContext ) RmPool ( path string , db_path string ) error {
269292 /* Set up the options */
270293 options := C.struct_rm_pool_options {}
271294 options .path = C .CString (path )
272295 defer freeString (options .path )
273- options .db_path = ctx .ctx .dc_db_path
296+ options .db_path = C .CString (db_path )
297+ defer freeString (options .db_path )
274298 /* Run the c code command */
275299 return daosError (C .ddb_run_rm_pool (& ctx .ctx , & options ))
276300}
277301
278- func ddbDtxActDiscardInvalid (ctx * DdbContext , path string , dtx_id string ) error {
302+ func (ctx * DdbContext ) DtxActDiscardInvalid ( path string , dtx_id string ) error {
279303 /* Set up the options */
280304 options := C.struct_dtx_act_options {}
281305 options .path = C .CString (path )
@@ -286,7 +310,7 @@ func ddbDtxActDiscardInvalid(ctx *DdbContext, path string, dtx_id string) error
286310 return daosError (C .ddb_run_dtx_act_discard_invalid (& ctx .ctx , & options ))
287311}
288312
289- func ddbDevList (ctx * DdbContext , db_path string ) error {
313+ func (ctx * DdbContext ) DevList ( db_path string ) error {
290314 /* Set up the options */
291315 options := C.struct_dev_list_options {}
292316 options .db_path = C .CString (db_path )
@@ -295,7 +319,7 @@ func ddbDevList(ctx *DdbContext, db_path string) error {
295319 return daosError (C .ddb_run_dev_list (& ctx .ctx , & options ))
296320}
297321
298- 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 {
299323 /* Set up the options */
300324 options := C.struct_dev_replace_options {}
301325 options .db_path = C .CString (db_path )
@@ -308,7 +332,7 @@ func ddbDevReplace(ctx *DdbContext, db_path string, old_devid string, new_devid
308332 return daosError (C .ddb_run_dev_replace (& ctx .ctx , & options ))
309333}
310334
311- func ddbDtxStat (ctx * DdbContext , path string , details bool ) error {
335+ func (ctx * DdbContext ) DtxStat ( path string , details bool ) error {
312336 /* Set up the options */
313337 options := C.struct_dtx_stat_options {}
314338 options .path = C .CString (path )
@@ -318,7 +342,7 @@ func ddbDtxStat(ctx *DdbContext, path string, details bool) error {
318342 return daosError (C .ddb_run_dtx_stat (& ctx .ctx , & options ))
319343}
320344
321- 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 {
322346 /* Set up the options */
323347 options := C.struct_prov_mem_options {}
324348 options .db_path = C .CString (db_path )
@@ -331,7 +355,7 @@ func ddbProvMem(ctx *DdbContext, db_path string, tmpfs_mount string, tmpfs_mount
331355 return daosError (C .ddb_run_prov_mem (& ctx .ctx , & options ))
332356}
333357
334- 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 {
335359 if cmt_time != math .MaxUint64 && cmt_date != "" {
336360 ctx .log .Error ("'--cmt_time' and '--cmt_date' options are mutually exclusive" )
337361 return daosError (- C .DER_INVAL )
0 commit comments