-
Notifications
You must be signed in to change notification settings - Fork 291
/
commands_wrapper.go
225 lines (194 loc) · 6.23 KB
/
commands_wrapper.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
//
// (C) Copyright 2022-2023 Intel Corporation.
//
// SPDX-License-Identifier: BSD-2-Clause-Patent
//
package main
import (
"runtime"
"unsafe"
"github.com/daos-stack/daos/src/control/lib/daos"
)
/*
#cgo CFLAGS: -I${SRCDIR}/../../../utils/ddb/
#cgo LDFLAGS: -lddb -lgurt
#include <ddb.h>
#include <daos_errno.h>
*/
import "C"
func daosError(rc C.int) error {
if rc != 0 {
return daos.Status(rc)
}
return nil
}
func freeString(s *C.char) {
C.free(unsafe.Pointer(s))
}
// InitDdb initializes the ddb context and returns a closure to finalize it.
func InitDdb() (*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
runtime.LockOSThread()
if err := daosError(C.ddb_init()); err != nil {
runtime.UnlockOSThread()
return nil, nil, err
}
ctx := &DdbContext{}
C.ddb_ctx_init(&ctx.ctx) // Initialize with ctx default values
return ctx, func() {
C.ddb_fini()
runtime.UnlockOSThread()
}, nil
}
// DdbContext structure for wrapping the C code context structure
type DdbContext struct {
ctx C.struct_ddb_ctx
}
func ddbPoolIsOpen(ctx *DdbContext) bool {
return bool(C.ddb_pool_is_open(&ctx.ctx))
}
func ddbLs(ctx *DdbContext, path string, recursive bool, details bool) error {
/* Set up the options */
options := C.struct_ls_options{}
options.path = C.CString(path)
defer freeString(options.path)
options.recursive = C.bool(recursive)
options.details = C.bool(details)
/* Run the c code command */
return daosError(C.ddb_run_ls(&ctx.ctx, &options))
}
func ddbOpen(ctx *DdbContext, path string, write_mode bool) error {
/* Set up the options */
options := C.struct_open_options{}
options.path = C.CString(path)
defer freeString(options.path)
options.write_mode = C.bool(write_mode)
/* Run the c code command */
return daosError(C.ddb_run_open(&ctx.ctx, &options))
}
func ddbVersion(ctx *DdbContext) error {
/* Run the c code command */
return daosError(C.ddb_run_version(&ctx.ctx))
}
func ddbClose(ctx *DdbContext) error {
/* Run the c code command */
return daosError(C.ddb_run_close(&ctx.ctx))
}
func ddbSuperblockDump(ctx *DdbContext) error {
/* Run the c code command */
return daosError(C.ddb_run_superblock_dump(&ctx.ctx))
}
func ddbValueDump(ctx *DdbContext, path string, dst string) error {
/* Set up the options */
options := C.struct_value_dump_options{}
options.path = C.CString(path)
defer freeString(options.path)
options.dst = C.CString(dst)
defer freeString(options.dst)
/* Run the c code command */
return daosError(C.ddb_run_value_dump(&ctx.ctx, &options))
}
func ddbRm(ctx *DdbContext, path string) error {
/* Set up the options */
options := C.struct_rm_options{}
options.path = C.CString(path)
defer freeString(options.path)
/* Run the c code command */
return daosError(C.ddb_run_rm(&ctx.ctx, &options))
}
func ddbValueLoad(ctx *DdbContext, src string, dst string) error {
/* Set up the options */
options := C.struct_value_load_options{}
options.src = C.CString(src)
defer freeString(options.src)
options.dst = C.CString(dst)
defer freeString(options.dst)
/* Run the c code command */
return daosError(C.ddb_run_value_load(&ctx.ctx, &options))
}
func ddbIlogDump(ctx *DdbContext, path string) error {
/* Set up the options */
options := C.struct_ilog_dump_options{}
options.path = C.CString(path)
defer freeString(options.path)
/* Run the c code command */
return daosError(C.ddb_run_ilog_dump(&ctx.ctx, &options))
}
func ddbIlogCommit(ctx *DdbContext, path string) error {
/* Set up the options */
options := C.struct_ilog_commit_options{}
options.path = C.CString(path)
defer freeString(options.path)
/* Run the c code command */
return daosError(C.ddb_run_ilog_commit(&ctx.ctx, &options))
}
func ddbIlogClear(ctx *DdbContext, path string) error {
/* Set up the options */
options := C.struct_ilog_clear_options{}
options.path = C.CString(path)
defer freeString(options.path)
/* Run the c code command */
return daosError(C.ddb_run_ilog_clear(&ctx.ctx, &options))
}
func ddbDtxDump(ctx *DdbContext, path string, active bool, committed bool) error {
/* Set up the options */
options := C.struct_dtx_dump_options{}
options.path = C.CString(path)
defer freeString(options.path)
options.active = C.bool(active)
options.committed = C.bool(committed)
/* Run the c code command */
return daosError(C.ddb_run_dtx_dump(&ctx.ctx, &options))
}
func ddbDtxCmtClear(ctx *DdbContext, path string) error {
/* Set up the options */
options := C.struct_dtx_cmt_clear_options{}
options.path = C.CString(path)
defer freeString(options.path)
/* Run the c code command */
return daosError(C.ddb_run_dtx_cmt_clear(&ctx.ctx, &options))
}
func ddbSmdSync(ctx *DdbContext, nvme_conf string, db_path string) error {
/* Set up the options */
options := C.struct_smd_sync_options{}
options.nvme_conf = C.CString(nvme_conf)
defer freeString(options.nvme_conf)
options.db_path = C.CString(db_path)
defer freeString(options.db_path)
/* Run the c code command */
return daosError(C.ddb_run_smd_sync(&ctx.ctx, &options))
}
func ddbVeaDump(ctx *DdbContext) error {
/* Run the c code command */
return daosError(C.ddb_run_vea_dump(&ctx.ctx))
}
func ddbVeaUpdate(ctx *DdbContext, offset string, blk_cnt string) error {
/* Set up the options */
options := C.struct_vea_update_options{}
options.offset = C.CString(offset)
defer freeString(options.offset)
options.blk_cnt = C.CString(blk_cnt)
defer freeString(options.blk_cnt)
/* Run the c code command */
return daosError(C.ddb_run_vea_update(&ctx.ctx, &options))
}
func ddbDtxActCommit(ctx *DdbContext, path string, dtx_id string) error {
/* Set up the options */
options := C.struct_dtx_act_commit_options{}
options.path = C.CString(path)
defer freeString(options.path)
options.dtx_id = C.CString(dtx_id)
defer freeString(options.dtx_id)
/* Run the c code command */
return daosError(C.ddb_run_dtx_act_commit(&ctx.ctx, &options))
}
func ddbDtxActAbort(ctx *DdbContext, path string, dtx_id string) error {
/* Set up the options */
options := C.struct_dtx_act_abort_options{}
options.path = C.CString(path)
defer freeString(options.path)
options.dtx_id = C.CString(dtx_id)
defer freeString(options.dtx_id)
/* Run the c code command */
return daosError(C.ddb_run_dtx_act_abort(&ctx.ctx, &options))
}