Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 22 additions & 13 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@ go_import_path: github.com/codedellemc/libstorage

language: go
go:
- 1.6.3
- 1.7.5
- 1.8
- tip
# - 1.6.3
# - 1.7.5
- 1.8.3
# - tip

os:
- linux

env:
- TRAVIS_GOARCH=amd64 BUILD_TAGS="gofig pflag libstorage_integration_driver_linux libstorage_storage_driver libstorage_storage_driver_vfs libstorage_storage_executor libstorage_storage_executor_vfs"
- TRAVIS_GOARCH=arm BUILD_TAGS="gofig pflag libstorage_integration_driver_linux libstorage_storage_driver libstorage_storage_driver_vfs libstorage_storage_executor libstorage_storage_executor_vfs"
- TRAVIS_GOARCH=arm64 BUILD_TAGS="gofig pflag libstorage_integration_driver_linux libstorage_storage_driver libstorage_storage_driver_vfs libstorage_storage_executor libstorage_storage_executor_vfs"
- VFS_INSTANCEID_USE_FIELDS=true BUILD_TAGS="gofig pflag libstorage_integration_driver_linux libstorage_storage_driver libstorage_storage_driver_vfs libstorage_storage_executor libstorage_storage_executor_vfs"
- LIBSTORAGE_TEST_TCP=false LIBSTORAGE_TEST_TCP_TLS=true BUILD_TAGS="gofig pflag libstorage_integration_driver_linux libstorage_storage_driver libstorage_storage_driver_vfs libstorage_storage_executor libstorage_storage_executor_vfs"
- LIBSTORAGE_TEST_TCP=false LIBSTORAGE_TEST_TCP_TLS_PEERS=true BUILD_TAGS="gofig pflag libstorage_integration_driver_linux libstorage_storage_driver libstorage_storage_driver_vfs libstorage_storage_executor libstorage_storage_executor_vfs"
- BUILD_TAGS="gofig pflag libstorage_integration_driver_linux"
- BUILD_TAGS=""
# - TRAVIS_GOARCH=arm BUILD_TAGS="gofig pflag libstorage_integration_driver_linux libstorage_storage_driver libstorage_storage_driver_vfs libstorage_storage_executor libstorage_storage_executor_vfs"
# - TRAVIS_GOARCH=arm64 BUILD_TAGS="gofig pflag libstorage_integration_driver_linux libstorage_storage_driver libstorage_storage_driver_vfs libstorage_storage_executor libstorage_storage_executor_vfs"
# - VFS_INSTANCEID_USE_FIELDS=true BUILD_TAGS="gofig pflag libstorage_integration_driver_linux libstorage_storage_driver libstorage_storage_driver_vfs libstorage_storage_executor libstorage_storage_executor_vfs"
# - LIBSTORAGE_TEST_TCP=false LIBSTORAGE_TEST_TCP_TLS=true BUILD_TAGS="gofig pflag libstorage_integration_driver_linux libstorage_storage_driver libstorage_storage_driver_vfs libstorage_storage_executor libstorage_storage_executor_vfs"
# - LIBSTORAGE_TEST_TCP=false LIBSTORAGE_TEST_TCP_TLS_PEERS=true BUILD_TAGS="gofig pflag libstorage_integration_driver_linux libstorage_storage_driver libstorage_storage_driver_vfs libstorage_storage_executor libstorage_storage_executor_vfs"
# - BUILD_TAGS="gofig pflag libstorage_integration_driver_linux"
# - BUILD_TAGS=""

matrix:
fast_finish: true
Expand Down Expand Up @@ -55,9 +55,18 @@ before_install:
- git config --global 'url.https://gopkg.in/fsnotify.v1.insteadof' 'https://gopkg.in/fsnotify.v1/'
- git config --global 'url.https://github.com/.insteadof' 'git://github.com/'
- git config --global 'url.https://github.com/.insteadof' '[email protected]:'
- make version
- make info
- make deps
- export PROJECT_NAME="libstorage"
- export GOPATH_OLD="$GOPATH"
- export GOPATH="/tmp/go"
- mkdir -p "$GOPATH"/{bin,pkg,src}
- mv "$GOPATH_OLD"/bin/* "$GOPATH"/bin/
- export PATH="${GOPATH}/bin:${PATH}"
- mkdir -p "$GOPATH"/src/github.com/codedellemc
- rsync -ax vendor/ "$GOPATH"/src/ && rm -fr vendor
- cd .. && mv "$PROJECT_NAME" "$GOPATH"/src/github.com/codedellemc/
- cd "$GOPATH"/src/github.com/codedellemc/"$PROJECT_NAME"
- make info

script:
- make gometalinter-all
Expand Down
15 changes: 13 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ GO_STDLIB := archive archive/tar archive/zip bufio builtin bytes compress \
runtime/trace sort strconv strings sync sync/atomic syscall \
testing testing/iotest testing/quick text text/scanner \
text/tabwriter text/template text/template/parse time unicode \
unicode/utf16 unicode/utf8 unsafe
unicode/utf16 unicode/utf8 unsafe context plugin


################################################################################
Expand Down Expand Up @@ -554,6 +554,7 @@ TEST_EXT_DEPS_SRCS := $(sort $(TEST_EXT_DEPS_SRCS))
ALL_EXT_DEPS := $(sort $(EXT_DEPS) $(TEST_EXT_DEPS))
ALL_EXT_DEPS_SRCS := $(sort $(EXT_DEPS_SRCS) $(TEST_EXT_DEPS_SRCS))

ifneq (1,$(NODEPS))
ifneq (1,$(VENDORED))

$(GLIDE):
Expand Down Expand Up @@ -595,14 +596,16 @@ GO_PHONY += $(GLIDE_LOCK)-clean
GO_CLOBBER += $(GLIDE_LOCK)-clean

endif #ifneq (1,$(VENDORED))

endif #ifneq (1,$(NODEPS))

################################################################################
## GOBINDATA ##
################################################################################
GO_BINDATA := $(GOPATH)/bin/go-bindata
go-bindata: $(GO_BINDATA)

ifneq (1,$(NODEPS))

GO_BINDATA_IMPORT_PATH := vendor/github.com/jteeuwen/go-bindata/go-bindata
ifneq (1,$(VENDORED))
GO_BINDATA_IMPORT_PATH := $(ROOT_IMPORT_PATH)/$(GO_BINDATA_IMPORT_PATH)
Expand All @@ -618,6 +621,7 @@ $(GO_BINDATA):
@touch $@
GO_DEPS += $(GO_BINDATA)

endif #ifneq (1,$(NODEPS))

################################################################################
## GOMETALINTER ##
Expand All @@ -629,10 +633,12 @@ endif
ifneq (1,$(GOMETALINTER_DISABLED))
GOMETALINTER := $(GOPATH)/bin/gometalinter

ifneq (1,$(NODEPS))
$(GOMETALINTER): | $(GOMETALINTER_TOOLS)
GOOS="" GOARCH="" go get -u github.com/alecthomas/gometalinter
gometalinter: $(GOMETALINTER)
GO_DEPS += $(GOMETALINTER)
endif # ifneq (1,$(NODEPS))

GOMETALINTER_TOOLS_D := .gometalinter.tools.d
$(GOMETALINTER_TOOLS_D): $(GOMETALINTER)
Expand Down Expand Up @@ -1377,7 +1383,12 @@ cover-debug:
################################################################################
## TARGETS ##
################################################################################
ifeq (1,$(NODEPS))
deps:
@echo nodeps
else
deps: $(GO_DEPS)
endif

build-tests: $(GO_BUILD_TESTS)

Expand Down
74 changes: 74 additions & 0 deletions api/mods/mods.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// +build go1.8,linux

package mods

import (
"io/ioutil"
"os"
"path"
"plugin"
"strconv"
"strings"
"sync"

"github.com/akutz/gotil"

"github.com/codedellemc/libstorage/api/types"
)

var (
loadedMods = map[string]bool{}
loadedModsLock = sync.Mutex{}
)

// LoadModules loads the shared objects present on the file system
// as libStorage plug-ins.
func LoadModules(
ctx types.Context,
pathConfig *types.PathConfig) {

disabled, _ := strconv.ParseBool(
os.Getenv("LIBSTORAGE_PLUGINS_DISABLED"))
if disabled {
ctx.Debug("plugin support disabled")
return
}

loadedModsLock.Lock()
defer loadedModsLock.Unlock()

if !gotil.FileExists(pathConfig.Mod) {
return
}
modFiles, err := ioutil.ReadDir(pathConfig.Mod)
if err != nil {
ctx.WithField("path", pathConfig.Mod).Warn(
"failed to list module files")
return
}
for _, f := range modFiles {
modFilePath := f.Name()
modFilePath = path.Join(pathConfig.Mod, modFilePath)
ctx.WithField(
"path", modFilePath).Debug(
"loading module")
lcModFilePath := strings.ToLower(modFilePath)
if loaded, ok := loadedMods[lcModFilePath]; ok && loaded {
ctx.WithField(
"path", modFilePath).Debug(
"already loaded")
continue
}
_, err := plugin.Open(modFilePath)
if err != nil {
ctx.WithError(err).WithField(
"path", modFilePath).Error(
"error opening module")
continue
}
loadedMods[lcModFilePath] = true
ctx.WithField(
"path", modFilePath).Info(
"loaded module")
}
}
16 changes: 16 additions & 0 deletions api/mods/nomods.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// +build !go1.8 !linux

package mods

import (
"github.com/codedellemc/libstorage/api/types"
)

// LoadModules loads the shared objects present on the file system
// as libStorage plug-ins.
func LoadModules(
ctx types.Context,
pathConfig *types.PathConfig) {

// NOOP
}
3 changes: 3 additions & 0 deletions api/types/types_paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ type PathConfig struct {
// Log is the path to the log directory.
Log string

// Mod is the path to the mod directory.
Mod string

// Run is the path to the run directory.
Run string

Expand Down
4 changes: 4 additions & 0 deletions api/utils/utils_paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func NewPathConfig(ctx types.Context, home, token string) *types.PathConfig {
envVarHomeEtc = fmt.Sprintf("%s_HOME_ETC", ucTok)
envVarHomeEtcTLS = fmt.Sprintf("%s_HOME_ETC_TLS", ucTok)
envVarHomeLib = fmt.Sprintf("%s_HOME_LIB", ucTok)
envVarHomeLibMod = fmt.Sprintf("%s_HOME_LIB_MOD", ucTok)
envVarHomeLog = fmt.Sprintf("%s_HOME_LOG", ucTok)
envVarHomeRun = fmt.Sprintf("%s_HOME_RUN", ucTok)
envVarHomeLSX = fmt.Sprintf("%s_HOME_LSX", ucTok)
Expand All @@ -57,6 +58,7 @@ func NewPathConfig(ctx types.Context, home, token string) *types.PathConfig {
initPathConfigFieldWithEnvVar(ctx, envVarHomeEtc, &pathConfig.Etc)
initPathConfigFieldWithEnvVar(ctx, envVarHomeEtcTLS, &pathConfig.TLS)
initPathConfigFieldWithEnvVar(ctx, envVarHomeLib, &pathConfig.Lib)
initPathConfigFieldWithEnvVar(ctx, envVarHomeLibMod, &pathConfig.Mod)
initPathConfigFieldWithEnvVar(ctx, envVarHomeLog, &pathConfig.Log)
initPathConfigFieldWithEnvVar(ctx, envVarHomeRun, &pathConfig.Run)
initPathConfigFieldWithEnvVar(ctx, envVarHomeLSX, &pathConfig.LSX)
Expand Down Expand Up @@ -84,6 +86,8 @@ func NewPathConfig(ctx types.Context, home, token string) *types.PathConfig {
ctx, false, true, token, pathConfig.Etc, "tls", &pathConfig.TLS)
initPathConfigFieldWithPath(
ctx, root, true, token, pathConfig.Home, "var/lib", &pathConfig.Lib)
initPathConfigFieldWithPath(
ctx, false, true, token, pathConfig.Lib, "mod", &pathConfig.Mod)
initPathConfigFieldWithPath(
ctx, root, true, token, pathConfig.Home, "var/log", &pathConfig.Log)
initPathConfigFieldWithPath(
Expand Down
8 changes: 7 additions & 1 deletion cli/lsx/lsx.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/akutz/goof"

"github.com/codedellemc/libstorage/api/context"
apimods "github.com/codedellemc/libstorage/api/mods"
"github.com/codedellemc/libstorage/api/registry"
apitypes "github.com/codedellemc/libstorage/api/types"
"github.com/codedellemc/libstorage/api/utils"
Expand All @@ -31,7 +32,12 @@ var cmdRx = regexp.MustCompile(
func Run() {

ctx := context.Background()
ctx = ctx.WithValue(context.PathConfigKey, utils.NewPathConfig(ctx, "", ""))
pathConfig := utils.NewPathConfig(ctx, "", "")
ctx = ctx.WithValue(context.PathConfigKey, pathConfig)

// load shared objects
apimods.LoadModules(ctx, pathConfig)

registry.ProcessRegisteredConfigs(ctx)

args := os.Args
Expand Down