diff --git a/.travis.yml b/.travis.yml index d6d4b360626..e8f71f26484 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,6 +16,9 @@ env: - TEST_NO_FUSE=1 TEST_VERBOSE=1 TEST_SUITE=test_go_expensive - TEST_NO_FUSE=1 TEST_VERBOSE=1 TEST_SUITE=test_sharness_expensive +before_install: + - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get install -y librados-dev; fi + install: - make install diff --git a/package.json b/package.json index 19462633b2a..f2a0d56dcec 100644 --- a/package.json +++ b/package.json @@ -592,6 +592,12 @@ "hash": "QmTzWwfHZr9N6Tnk4iDTtKMWY57D3wik73qNCVo21Bu1UP", "name": "iptb-plugins", "version": "1.0.3" + }, + { + "author": "bjzhang", + "hash": "QmYyMML9pPAFqQAtHW56YHzUXK7CBnubB1g7kK123eo98G", + "name": "go-ds-rados", + "version": "0.0.4" } ], "gxVersion": "0.10.0", diff --git a/plugin/plugins/Rules.mk b/plugin/plugins/Rules.mk index 80924bad202..e7840008f2e 100644 --- a/plugin/plugins/Rules.mk +++ b/plugin/plugins/Rules.mk @@ -1,6 +1,6 @@ include mk/header.mk -$(d)_plugins:=$(d)/git $(d)/badgerds $(d)/flatfs $(d)/levelds +$(d)_plugins:=$(d)/git $(d)/badgerds $(d)/flatfs $(d)/levelds $(d)/rados $(d)_plugins_so:=$(addsuffix .so,$($(d)_plugins)) $(d)_plugins_main:=$(addsuffix /main/main.go,$($(d)_plugins)) diff --git a/plugin/plugins/rados/rados.go b/plugin/plugins/rados/rados.go new file mode 100644 index 00000000000..fd0000daa21 --- /dev/null +++ b/plugin/plugins/rados/rados.go @@ -0,0 +1,80 @@ +// +build linux + +package radosds + +import ( + "fmt" + "os" + + "github.com/ipfs/go-ipfs/plugin" + "github.com/ipfs/go-ipfs/repo" + "github.com/ipfs/go-ipfs/repo/fsrepo" + + rados "gx/ipfs/QmYyMML9pPAFqQAtHW56YHzUXK7CBnubB1g7kK123eo98G/go-ds-rados" +) + +// Plugins is exported list of plugins that will be loaded +var Plugins = []plugin.Plugin{ + &radosPlugin{}, +} + +type radosPlugin struct{} + +var _ plugin.PluginDatastore = (*radosPlugin)(nil) + +func (*radosPlugin) Name() string { + return "ds-rados" +} + +func (*radosPlugin) Version() string { + return "0.1.0" +} + +func (*radosPlugin) Init() error { + return nil +} + +func (*radosPlugin) DatastoreTypeName() string { + return "rados" +} + +type radosDatastoreConfig struct { + confPath string + pool string +} + +func (*radosPlugin) DatastoreConfigParser() fsrepo.ConfigFromMap { + return func(params map[string]interface{}) (fsrepo.DatastoreConfig, error) { + var c radosDatastoreConfig + var ok bool + c.confPath, ok = params["confpath"].(string) + if !ok { + return nil, fmt.Errorf("confpath filed is missing or not string") + } + c.pool, ok = params["pool"].(string) + if !ok { + return nil, fmt.Errorf("'pool' filed is missing or not string") + } + return &c, nil + } +} + +func (c *radosDatastoreConfig) DiskSpec() fsrepo.DiskSpec { + return map[string]interface{}{ + "type": "rados", + "confpath": c.confPath, + "pool": c.pool, + } +} + +func (c *radosDatastoreConfig) Create(string) (repo.Datastore, error) { + _, err := os.Open(c.confPath) + if os.IsNotExist(err) { + return nil, fmt.Errorf("Config file for rados doesn't exist:%s", c.confPath) + } + if os.IsPermission(err) { + return nil, fmt.Errorf("Permission deny for file:%s", c.confPath) + } + + return rados.NewDatastore(c.confPath, c.pool) +}