-
Notifications
You must be signed in to change notification settings - Fork 0
/
libstor-s_exported.go
85 lines (70 loc) · 2.08 KB
/
libstor-s_exported.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
package main
import "C"
import (
"os"
"unsafe"
log "github.com/sirupsen/logrus"
"github.com/rexray/rexray/libstorage/api/context"
"github.com/rexray/rexray/libstorage/api/registry"
"github.com/rexray/rexray/libstorage/api/server"
"github.com/rexray/rexray/libstorage/api/utils"
apicfg "github.com/rexray/rexray/libstorage/api/utils/config"
)
// closeOnAbort is a helper function that can be called by programs, such as
// tests or a command line or service application.
//
//export closeOnAbort
func closeOnAbort() {
server.CloseOnAbort()
}
// serve starts the libStorage server, blocking the current thread until the
// server is shutdown.
//
// char* host the golang network-style address. if no value is provided
// then a random TCP port bound to localhost is used
//
// short argc the length of the argv array
//
// void* argv a pointer to an array of char* strings that represent the
// drivers and corresponding service names to load. if the
// array is odd-numbered then the service for the trailing
// driver takes the name of the driver
//
// char* serve(char* host, int argc, void* argv);
//export serve
func serve(
host *C.char, argc C.int, argv unsafe.Pointer) *C.char {
iargc := int(argc)
args := make([]string, iargc)
pargv := argv
for x := 0; x < iargc; x++ {
gostr := C.GoString((*C.char)(pargv))
log.WithFields(log.Fields{
"x": x,
"gostr": gostr,
}).Info("parsed gostr")
args[x] = gostr
pargv = unsafe.Pointer(uintptr(pargv) + unsafe.Sizeof(gostr))
}
szHost := C.GoString(host)
log.WithFields(log.Fields{
"host": szHost,
"args": args,
}).Info("serving")
ctx := context.Background()
ctx = ctx.WithValue(context.PathConfigKey, utils.NewPathConfig(ctx, "", ""))
registry.ProcessRegisteredConfigs(ctx)
config, err := apicfg.NewConfig(ctx)
if err != nil {
return C.CString(err.Error())
}
if len(szHost) > 0 {
os.Setenv("LIBSTORAGE_HOST", szHost)
}
_, errs, err := server.Serve(ctx, config)
if err != nil {
return C.CString(err.Error())
}
<-errs
return nil
}