Skip to content
This repository has been archived by the owner on Mar 26, 2020. It is now read-only.

Commit

Permalink
Refactor Device management
Browse files Browse the repository at this point in the history
Signed-off-by: Aravinda VK <avishwan@redhat.com>
  • Loading branch information
aravindavk authored and Madhu-1 committed Dec 5, 2018
1 parent 3d9707a commit 931b7a2
Show file tree
Hide file tree
Showing 17 changed files with 201 additions and 203 deletions.
5 changes: 3 additions & 2 deletions doc/endpoints.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 19 additions & 10 deletions e2e/smartvol_ops_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func checkZeroLvs(r *require.Assertions) {

func checkZeroLvsWithRange(r *require.Assertions, start, end int) {
for i := start; i <= end; i++ {
nlv, err := numberOfLvs(fmt.Sprintf("vg-dev-gluster_loop%d", i))
nlv, err := numberOfLvs(fmt.Sprintf("gluster-dev-gluster_loop%d", i))
r.Nil(err)
if err == nil {
r.Equal(0, nlv)
Expand Down Expand Up @@ -325,7 +325,7 @@ func editDevice(t *testing.T) {
var deviceList []deviceapi.Info
var peerID string
for _, peer := range peerList {
deviceList, err = client.DeviceList(peer.ID.String())
deviceList, err = client.DeviceList(peer.ID.String(), "")
if len(deviceList) > 0 {
peerID = peer.ID.String()
break
Expand All @@ -334,26 +334,26 @@ func editDevice(t *testing.T) {

device := deviceList[0]
if device.State == "enabled" {
err = client.DeviceEdit(peerID, device.Name, "disabled")
err = client.DeviceEdit(peerID, device.Device, "disabled")
r.Nil(err)
} else if device.State == "disabled" {
err = client.DeviceEdit(peerID, device.Name, "enabled")
err = client.DeviceEdit(peerID, device.Device, "enabled")
r.Nil(err)
}
newDeviceList, err := client.DeviceList(peerID)
newDeviceList, err := client.DeviceList(peerID, "")
r.Nil(err)
for _, newDevice := range newDeviceList {
if newDevice.Name == device.Name {
if newDevice.Device == device.Device {
r.NotEqual(newDevice.State, device.State)
}
}

for _, peer := range peerList {
deviceList, err := client.DeviceList(peer.ID.String())
deviceList, err := client.DeviceList(peer.ID.String(), "")
r.Nil(err)
for _, device := range deviceList {
if device.State == "enabled" {
err = client.DeviceEdit(peer.ID.String(), device.Name, "disabled")
err = client.DeviceEdit(peer.ID.String(), device.Device, "disabled")
r.Nil(err)
}
}
Expand All @@ -372,11 +372,11 @@ func editDevice(t *testing.T) {
r.NotNil(err)

for _, peer := range peerList {
deviceList, err := client.DeviceList(peer.ID.String())
deviceList, err := client.DeviceList(peer.ID.String(), "")
r.Nil(err)
for _, device := range deviceList {
if device.State == "disabled" {
err = client.DeviceEdit(peer.ID.String(), device.Name, "enabled")
err = client.DeviceEdit(peer.ID.String(), device.Device, "enabled")
r.Nil(err)
}
}
Expand Down Expand Up @@ -413,12 +413,21 @@ func TestSmartVolume(t *testing.T) {

_, err = client.DeviceAdd(tc.gds[0].PeerID(), "/dev/gluster_loop1")
r.Nil(err)
dev, err := client.DeviceList(tc.gds[0].PeerID(), "/dev/gluster_loop1")
r.Nil(err)
r.Equal(dev[0].Device, "/dev/gluster_loop1")

_, err = client.DeviceAdd(tc.gds[1].PeerID(), "/dev/gluster_loop2")
r.Nil(err)
dev, err = client.DeviceList(tc.gds[1].PeerID(), "/dev/gluster_loop2")
r.Nil(err)
r.Equal(dev[0].Device, "/dev/gluster_loop2")

_, err = client.DeviceAdd(tc.gds[2].PeerID(), "/dev/gluster_loop3")
r.Nil(err)
dev, err = client.DeviceList(tc.gds[2].PeerID(), "/dev/gluster_loop3")
r.Nil(err)
r.Equal(dev[0].Device, "/dev/gluster_loop3")

t.Run("Smartvol Distributed Volume", testSmartVolumeDistribute)
t.Run("Smartvol Replicate 2 Volume", testSmartVolumeReplicate2)
Expand Down
2 changes: 2 additions & 0 deletions glusterd2/brick/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ type Brickinfo struct {
Type Type
Decommissioned bool
PType ProvisionType
VgName string
RootDevice string
MountInfo
}

Expand Down
2 changes: 2 additions & 0 deletions glusterd2/bricksplanner/planner.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ func PlanBricks(req *api.VolCreateReq) error {
if vg.AvailableSize >= totalsize && !zoneUsed && !vg.Used {
subvols[idx].Bricks[bidx].PeerID = vg.PeerID
subvols[idx].Bricks[bidx].VgName = vg.Name
subvols[idx].Bricks[bidx].RootDevice = vg.Device
subvols[idx].Bricks[bidx].DevicePath = "/dev/" + vg.Name + "/" + b.LvName

zones[vg.Zone] = struct{}{}
Expand Down Expand Up @@ -211,6 +212,7 @@ func PlanBricks(req *api.VolCreateReq) error {
if vg.AvailableSize >= totalsize && !zoneUsed {
subvols[idx].Bricks[bidx].PeerID = vg.PeerID
subvols[idx].Bricks[bidx].VgName = vg.Name
subvols[idx].Bricks[bidx].RootDevice = vg.Device
subvols[idx].Bricks[bidx].DevicePath = "/dev/" + vg.Name + "/" + b.LvName

zones[vg.Zone] = struct{}{}
Expand Down
21 changes: 10 additions & 11 deletions glusterd2/bricksplanner/utils.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package bricksplanner

import (
"encoding/json"
"sort"
"strings"

Expand All @@ -10,6 +9,7 @@ import (
"github.com/gluster/glusterd2/pkg/api"
"github.com/gluster/glusterd2/pkg/utils"
deviceapi "github.com/gluster/glusterd2/plugins/device/api"
"github.com/gluster/glusterd2/plugins/device/deviceutils"
)

var subvolPlanners = make(map[string]SubvolPlanner)
Expand All @@ -25,7 +25,7 @@ type SubvolPlanner interface {
// Vg represents Virtual Volume Group
type Vg struct {
Name string
DeviceName string
Device string
PeerID string
Zone string
State string
Expand Down Expand Up @@ -71,15 +71,14 @@ func getAvailableVgs(req *api.VolCreateReq) ([]Vg, error) {
continue
}

devicesRaw, exists := p.Metadata["_devices"]
if !exists {
// No device registered for this peer
continue
deviceInfo, err := deviceutils.GetDevices(p.ID.String())
if err != nil {
return nil, err
}

var deviceInfo []deviceapi.Info
if err := json.Unmarshal([]byte(devicesRaw), &deviceInfo); err != nil {
return nil, err
if len(deviceInfo) == 0 {
// No device registered for this peer
continue
}

for _, d := range deviceInfo {
Expand All @@ -89,8 +88,8 @@ func getAvailableVgs(req *api.VolCreateReq) ([]Vg, error) {
}

vgs = append(vgs, Vg{
DeviceName: d.Name,
Name: d.VgName,
Device: d.Device,
Name: d.VgName(),
PeerID: p.ID.String(),
Zone: peerzone,
State: d.State,
Expand Down
9 changes: 4 additions & 5 deletions glusterd2/commands/volumes/volume-expand-txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,28 +307,27 @@ func expandLocalBricks(volinfo *volume.Volinfo, expansionTpSizePerBrick uint64,
if uuid.Equal(b.PeerID, gdctx.MyUUID) {
tpName := fmt.Sprintf("tp_%s_s%d_b%d", volinfo.Name, i+1, j+1)
lvName := fmt.Sprintf("brick_%s_s%d_b%d", volinfo.Name, i+1, j+1)
vgName := brickVgMapping[b.Path]
totalExpansionSizePerBrick := expansionTpSizePerBrick + expansionMetadataSizePerBrick

// extend thinpool
err := lvmutils.ExtendThinpool(expansionTpSizePerBrick, vgName, tpName)
err := lvmutils.ExtendThinpool(expansionTpSizePerBrick, b.VgName, tpName)
if err != nil {
return err
}
// extend metadata pool
err = lvmutils.ExtendMetadataPool(expansionMetadataSizePerBrick, vgName, tpName)
err = lvmutils.ExtendMetadataPool(expansionMetadataSizePerBrick, b.VgName, tpName)
if err != nil {
return err
}

// extend lv
err = lvmutils.ExtendLV(totalExpansionSizePerBrick, vgName, lvName)
err = lvmutils.ExtendLV(totalExpansionSizePerBrick, b.VgName, lvName)
if err != nil {
return err
}

// Update current Vg free size
err = deviceutils.UpdateDeviceFreeSize(gdctx.MyUUID.String(), vgName)
err = deviceutils.UpdateDeviceFreeSize(gdctx.MyUUID.String(), b.RootDevice)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions glusterd2/commands/volumes/volume-smartvol-txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func txnPrepareBricks(c transaction.TxnCtx) error {
}

// Update current Vg free size
err = deviceutils.UpdateDeviceFreeSize(gdctx.MyUUID.String(), b.VgName)
err = deviceutils.UpdateDeviceFreeSize(gdctx.MyUUID.String(), b.RootDevice)
if err != nil {
c.Logger().WithError(err).WithField("vg-name", b.VgName).
Error("failed to update available size of a device")
Expand Down Expand Up @@ -144,7 +144,7 @@ func txnUndoPrepareBricks(c transaction.TxnCtx) error {
}

// Update current Vg free size
deviceutils.UpdateDeviceFreeSize(gdctx.MyUUID.String(), b.VgName)
deviceutils.UpdateDeviceFreeSize(gdctx.MyUUID.String(), b.RootDevice)
}
}

Expand Down
2 changes: 2 additions & 0 deletions glusterd2/volume/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ func NewBrickEntries(bricks []api.BrickReq, volName, volfileID string, volID uui
binfo.VolfileID = volfileID
binfo.VolumeID = volID
binfo.ID = uuid.NewRandom()
binfo.VgName = b.VgName
binfo.RootDevice = b.RootDevice

binfo.PType = ptype
if ptype.IsAutoProvisioned() || ptype.IsSnapshotProvisioned() {
Expand Down
2 changes: 1 addition & 1 deletion glusterd2/volume/volume-utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ func CleanBricks(volinfo *Volinfo) error {
}

// Update current Vg free size
err = deviceutils.UpdateDeviceFreeSize(gdctx.MyUUID.String(), vgname)
err = deviceutils.UpdateDeviceFreeSizeByVg(gdctx.MyUUID.String(), vgname)
if err != nil {
log.WithError(err).WithField("vg-name", vgname).
Error("failed to update available size of a device")
Expand Down
1 change: 1 addition & 0 deletions pkg/api/volume_req.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type BrickReq struct {
TpMetadataSize uint64 `json:"metadata-size,omitempty"`
TpSize uint64 `json:"thinpool-size,omitempty"`
VgName string `json:"vg-name,omitempty"`
RootDevice string `json:"root-device,omitempty"`
TpName string `json:"thinpool-name,omitempty"`
LvName string `json:"logical-volume,omitempty"`
Size uint64 `json:"size,omitempty"`
Expand Down
1 change: 1 addition & 0 deletions pkg/errors/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,5 @@ var (
ErrInvalidFilenameFormat = errors.New("filename should be an absolute path in volume, should start with / notation")
ErrHostOrBrickNotFound = errors.New("please specify hostname and brick path to resolve split-brain")
ErrVolTypeNotInReplicateOrDisperse = errors.New("invalid operation: the volume is not a replicate or disperse volume")
ErrDeviceNotFound = errors.New("device does not exist in the given peer")
)
17 changes: 12 additions & 5 deletions pkg/restclient/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,25 @@ import (

// DeviceAdd registers device
func (c *Client) DeviceAdd(peerid, device string) (deviceapi.AddDeviceResp, error) {
var peerinfo deviceapi.AddDeviceResp
var deviceinfo deviceapi.AddDeviceResp
req := deviceapi.AddDeviceReq{
Device: device,
}
err := c.post("/v1/devices/"+peerid, req, http.StatusOK, &peerinfo)
return peerinfo, err
err := c.post("/v1/devices/"+peerid, req, http.StatusCreated, &deviceinfo)
return deviceinfo, err
}

// DeviceList lists the devices
func (c *Client) DeviceList(peerid string) ([]deviceapi.Info, error) {
func (c *Client) DeviceList(peerid, device string) ([]deviceapi.Info, error) {
var deviceList deviceapi.ListDeviceResp
url := fmt.Sprintf("/v1/devices/%s", peerid)
url := "/v1/devices"
if peerid != "" {
url = fmt.Sprintf("%s/%s", url, peerid)
if device != "" {
url = fmt.Sprintf("%s/%s", url, strings.TrimPrefix(device, "/"))
}
}

err := c.get(url, nil, http.StatusOK, &deviceList)
return deviceList, err
}
Expand Down
24 changes: 15 additions & 9 deletions plugins/device/api/resp.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
package api

import (
"github.com/gluster/glusterd2/pkg/api"
"strings"

"github.com/pborman/uuid"
)

// Info represents structure in which devices are to be store in Peer Metadata
type Info struct {
Name string `json:"name"`
State string `json:"state"`
VgName string `json:"vg-name"`
AvailableSize uint64 `json:"available-size"`
ExtentSize uint64 `json:"extent-size"`
Used bool `json:"device-used"`
PeerID string `json:"peer-id"`
Device string `json:"device"`
State string `json:"state"`
AvailableSize uint64 `json:"available-size"`
ExtentSize uint64 `json:"extent-size"`
Used bool `json:"device-used"`
PeerID uuid.UUID `json:"peer-id"`
}

// VgName returns name for LVM Vg
func (info *Info) VgName() string {
return "gluster" + strings.Replace(info.Device, "/", "-", -1)
}

// AddDeviceResp is the success response sent to a AddDeviceReq request
type AddDeviceResp api.Peer
type AddDeviceResp Info

// ListDeviceResp is the success response sent to a ListDevice request
type ListDeviceResp []Info
Loading

0 comments on commit 931b7a2

Please sign in to comment.