1
0
mirror of https://github.com/gluster/glusterd2.git synced 2026-02-05 12:45:38 +01:00
Files
glusterd2/plugins/blockvolume/routes.go
Poornima G 54ce5f6f7a blockvolume: Code re-org to fix race condition and cleanup bhv
The block host volume will still exist even when the blocks are all
deleted. Manually deleting block host volume will need another step
of unmounting. With this patch we auto-delete the block host volume
if there are no blocks.

The availablility check of bhv free space is not done within lock, hence
there is a possiblity that the available space has changed by the
time we decide to create the volume. This patch also fixes the race
condition.

Signed-off-by: Poornima G <pgurusid@redhat.com>
2019-03-29 20:30:50 +05:30

74 lines
1.9 KiB
Go

package blockvolume
import (
"net/http"
"sync"
"github.com/gluster/glusterd2/glusterd2/servers/rest/route"
"github.com/gluster/glusterd2/pkg/utils"
"github.com/gluster/glusterd2/plugins/blockvolume/api"
"github.com/gluster/glusterd2/plugins/blockvolume/hostvol"
)
// BlockVolume represents BlockVolume plugin
type BlockVolume struct {
hostVolManager hostvol.HostingVolumeManager
initOnce sync.Once
}
// Name returns plugin name
func (b *BlockVolume) Name() string {
b.Init()
return "block-volume"
}
// RestRoutes returns list of REST API routes of BlockVolume to register with Glusterd.
func (b *BlockVolume) RestRoutes() route.Routes {
b.Init()
return route.Routes{
{
Name: "BlockCreate",
Method: http.MethodPost,
Pattern: "/blockvolumes/{provider}",
Version: 1,
RequestType: utils.GetTypeString((*api.BlockVolumeCreateRequest)(nil)),
ResponseType: utils.GetTypeString((*api.BlockVolumeCreateResp)(nil)),
HandlerFunc: b.CreateVolume,
},
{
Name: "BlockDelete",
Method: http.MethodDelete,
Pattern: "/blockvolumes/{provider}/{name}",
Version: 1,
HandlerFunc: b.DeleteVolume,
},
{
Name: "BlockList",
Method: http.MethodGet,
Pattern: "/blockvolumes/{provider}",
Version: 1,
HandlerFunc: b.ListBlockVolumes,
},
{
Name: "BlockGet",
Method: http.MethodGet,
Pattern: "/blockvolumes/{provider}/{name}",
Version: 1,
HandlerFunc: b.GetBlockVolume,
},
}
}
// RegisterStepFuncs registers all step functions
func (*BlockVolume) RegisterStepFuncs() {
hostvol.RegisterBHVstepFunctions()
}
// Init will initialize the underlying HostVolume manager only once.
// calling it multiple times will do nothing
func (b *BlockVolume) Init() {
b.initOnce.Do(func() {
b.hostVolManager = hostvol.NewGlusterVolManager()
})
}