mirror of
https://github.com/gluster/glusterd2.git
synced 2026-02-05 12:45:38 +01:00
snapshot:update options during snap create using default value
This also address review comments in PR 846. Signed-off-by: Mohammed Rafi KC <rkavunga@redhat.com>
This commit is contained in:
committed by
Kaushal M
parent
4d75627bc3
commit
d284f086d0
@@ -38,8 +38,7 @@ func createBrickPath(num int) ([]string, error) {
|
||||
for i := 1; i <= num; i++ {
|
||||
prefix := fmt.Sprintf("%s%d/%s", brickPrefix, i, lvmPrefix)
|
||||
path := fmt.Sprintf("%s_mnt", prefix)
|
||||
err := os.MkdirAll(path, os.ModeDir|os.ModePerm)
|
||||
if err != nil {
|
||||
if err := os.MkdirAll(path, os.ModeDir|os.ModePerm); err != nil {
|
||||
return brickPath, err
|
||||
}
|
||||
brickPath = append(brickPath, path)
|
||||
@@ -137,18 +136,16 @@ func createVHD(num int, size string) error {
|
||||
vhdPath := fmt.Sprintf("%s_vhd", prefix)
|
||||
devicePath := fmt.Sprintf("%s_loop", prefix)
|
||||
//TODO replace exec command with syscall.Fallocate
|
||||
_, err := exec.Command(fallocateBin, "-l", size, vhdPath).Output()
|
||||
if err != nil {
|
||||
if _, err := exec.Command(fallocateBin, "-l", size, vhdPath).Output(); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := exec.Command(mknodBin, "-m", "660", devicePath, "b", "7", strconv.Itoa(i+8)).Output(); err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = exec.Command(mknodBin, "-m", "660", devicePath, "b", "7", strconv.Itoa(i+8)).Output()
|
||||
loosetupCmd := exec.Command("losetup", devicePath, vhdPath)
|
||||
_, err = loosetupCmd.Output()
|
||||
if err != nil {
|
||||
if _, err := loosetupCmd.Output(); err != nil {
|
||||
return err
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -166,13 +163,11 @@ func CreateLvmBricks(prefix string, num int) ([]string, error) {
|
||||
if err != nil {
|
||||
return brickPath, err
|
||||
}
|
||||
err = createVHD(num, "300M")
|
||||
if err != nil {
|
||||
if err = createVHD(num, "300M"); err != nil {
|
||||
return brickPath, err
|
||||
}
|
||||
|
||||
err = createLV(num, "200M", "150M")
|
||||
if err != nil {
|
||||
if err = createLV(num, "200M", "150M"); err != nil {
|
||||
return brickPath, err
|
||||
}
|
||||
return brickPath, nil
|
||||
@@ -219,13 +214,11 @@ func CleanupLvmBricks(prefix string, num int) error {
|
||||
if !verifyLVM() {
|
||||
return errors.New("lvm or thinlv is not available on the machine")
|
||||
}
|
||||
err = deleteVHD(num, false)
|
||||
if err != nil {
|
||||
if err = deleteVHD(num, false); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = deleteLV(num, false)
|
||||
if err != nil {
|
||||
if err = deleteLV(num, false); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -36,8 +36,7 @@ func snapshotActivateCmdRun(cmd *cobra.Command, args []string) {
|
||||
req := api.SnapActivateReq{
|
||||
Force: flagSnapshotActivateCmdForce,
|
||||
}
|
||||
err := client.SnapshotActivate(req, snapname)
|
||||
if err != nil {
|
||||
if err := client.SnapshotActivate(req, snapname); err != nil {
|
||||
if GlobalFlag.Verbose {
|
||||
log.WithError(err).WithField("snapshot", snapname).Error("snapshot activation failed")
|
||||
}
|
||||
|
||||
@@ -26,8 +26,7 @@ func init() {
|
||||
|
||||
func snapshotDeactivateCmdRun(cmd *cobra.Command, args []string) {
|
||||
snapname := cmd.Flags().Args()[0]
|
||||
err := client.SnapshotDeactivate(snapname)
|
||||
if err != nil {
|
||||
if err := client.SnapshotDeactivate(snapname); err != nil {
|
||||
if GlobalFlag.Verbose {
|
||||
log.WithError(err).WithField("snapshot", snapname).Error("snapshot deactivation failed")
|
||||
}
|
||||
|
||||
@@ -29,8 +29,7 @@ func init() {
|
||||
func snapshotDeleteCmdRun(cmd *cobra.Command, args []string) {
|
||||
snapname := args[0]
|
||||
|
||||
err := client.SnapshotDelete(snapname)
|
||||
if err != nil {
|
||||
if err := client.SnapshotDelete(snapname); err != nil {
|
||||
if GlobalFlag.Verbose {
|
||||
log.WithError(err).WithField(
|
||||
"snapshot", snapname).Error("snapshot delete failed")
|
||||
|
||||
@@ -47,7 +47,7 @@ func snapshotInfoDisplay(snap api.SnapGetResp) {
|
||||
fmt.Println("Snapshot Volume ID:", vol.ID)
|
||||
fmt.Println("State:", vol.State)
|
||||
fmt.Println("Origin Volume name:", snap.ParentVolName)
|
||||
fmt.Println("Snap Creation Time:", "To Be Added")
|
||||
fmt.Println("Snap Creation Time:", snap.SnapTime)
|
||||
fmt.Println("Labels:", "To Be Added")
|
||||
fmt.Println()
|
||||
|
||||
@@ -69,8 +69,7 @@ func snapshotInfoHandler(cmd *cobra.Command) error {
|
||||
}
|
||||
|
||||
func snapshotInfoCmdRun(cmd *cobra.Command, args []string) {
|
||||
err := snapshotInfoHandler(cmd)
|
||||
if err != nil {
|
||||
if err := snapshotInfoHandler(cmd); err != nil {
|
||||
if GlobalFlag.Verbose {
|
||||
log.WithError(err).Error("error getting snapshot info")
|
||||
}
|
||||
|
||||
@@ -61,8 +61,7 @@ var snapshotListCmd = &cobra.Command{
|
||||
}
|
||||
|
||||
func snapshotListCmdRun(cmd *cobra.Command, args []string) {
|
||||
err := snapshotListHandler(cmd)
|
||||
if err != nil {
|
||||
if err := snapshotListHandler(cmd); err != nil {
|
||||
if GlobalFlag.Verbose {
|
||||
log.WithError(err).Error("error getting snapshot list")
|
||||
}
|
||||
|
||||
@@ -70,8 +70,7 @@ var snapshotStatusCmd = &cobra.Command{
|
||||
}
|
||||
|
||||
func snapshotStatusCmdRun(cmd *cobra.Command, args []string) {
|
||||
err := snapshotStatusHandler(cmd)
|
||||
if err != nil {
|
||||
if err := snapshotStatusHandler(cmd); err != nil {
|
||||
if GlobalFlag.Verbose {
|
||||
log.WithError(err).Error("error getting snapshot status")
|
||||
}
|
||||
|
||||
@@ -75,12 +75,7 @@ func activateSnapshot(c transaction.TxnCtx) error {
|
||||
}
|
||||
|
||||
err = snapshot.ActivateDeactivateFunc(snapinfo, brickinfos, activate, c.Logger())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
return err
|
||||
}
|
||||
func storeSnapshotActivate(c transaction.TxnCtx) error {
|
||||
var snapname string
|
||||
@@ -172,8 +167,13 @@ func snapshotActivateHandler(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
err = txn.Ctx.Set("snapname", &snapname)
|
||||
if err != nil {
|
||||
if vol.State == volume.VolStarted && req.Force == false {
|
||||
err := errors.New("snapshot already activated. Use force to override the behaviour")
|
||||
restutils.SendHTTPError(ctx, w, http.StatusBadRequest, err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = txn.Ctx.Set("snapname", &snapname); err != nil {
|
||||
log.WithError(err).Error("failed to set snap name in transaction context")
|
||||
restutils.SendHTTPError(ctx, w, http.StatusInternalServerError, err)
|
||||
return
|
||||
@@ -197,14 +197,12 @@ func snapshotActivateHandler(w http.ResponseWriter, r *http.Request) {
|
||||
Nodes: []uuid.UUID{gdctx.MyUUID},
|
||||
},
|
||||
}
|
||||
err = txn.Ctx.Set("req", &req)
|
||||
if err != nil {
|
||||
if err = txn.Ctx.Set("req", &req); err != nil {
|
||||
log.WithError(err).Error("failed to set request in transaction context")
|
||||
restutils.SendHTTPError(ctx, w, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
err = txn.Do()
|
||||
if err != nil {
|
||||
if err = txn.Do(); err != nil {
|
||||
log.WithError(err).WithField(
|
||||
"snapshot", snapname).Error("failed to start snapshot")
|
||||
restutils.SendHTTPError(ctx, w, http.StatusInternalServerError, err)
|
||||
|
||||
@@ -221,8 +221,7 @@ func createCloneVolinfo(c transaction.TxnCtx) error {
|
||||
|
||||
for _, node := range volinfo.Nodes() {
|
||||
tmp := make(map[string]snapshot.BrickMountData)
|
||||
err := c.GetNodeResult(node, snapshot.NodeDataTxnKey, &tmp)
|
||||
if err != nil {
|
||||
if err := c.GetNodeResult(node, snapshot.NodeDataTxnKey, &tmp); err != nil {
|
||||
return err
|
||||
}
|
||||
for k, v := range tmp {
|
||||
@@ -243,8 +242,7 @@ func createCloneVolinfo(c transaction.TxnCtx) error {
|
||||
newVol.Name = clonename
|
||||
newVol.VolfileID = clonename
|
||||
|
||||
err = createSnapSubvols(newVol, volinfo, nodeData)
|
||||
if err != nil {
|
||||
if err = createSnapSubvols(newVol, volinfo, nodeData); err != nil {
|
||||
log.WithError(err).WithFields(log.Fields{
|
||||
"snapshot": snapname,
|
||||
"volume name": clonename,
|
||||
@@ -349,14 +347,12 @@ func snapshotCloneHandler(w http.ResponseWriter, r *http.Request) {
|
||||
Nodes: []uuid.UUID{gdctx.MyUUID},
|
||||
},
|
||||
}
|
||||
err = txn.Ctx.Set("snapname", &snapname)
|
||||
if err != nil {
|
||||
if err = txn.Ctx.Set("snapname", &snapname); err != nil {
|
||||
logger.WithError(err).Error("failed to set request in transaction context")
|
||||
restutils.SendHTTPError(ctx, w, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
err = txn.Ctx.Set("clonename", &req.CloneName)
|
||||
if err != nil {
|
||||
if err = txn.Ctx.Set("clonename", &req.CloneName); err != nil {
|
||||
logger.WithError(err).Error("failed to set request in transaction context")
|
||||
restutils.SendHTTPError(ctx, w, http.StatusInternalServerError, err)
|
||||
return
|
||||
|
||||
@@ -28,6 +28,7 @@ import (
|
||||
"github.com/gluster/glusterd2/glusterd2/transaction"
|
||||
"github.com/gluster/glusterd2/glusterd2/volgen"
|
||||
"github.com/gluster/glusterd2/glusterd2/volume"
|
||||
"github.com/gluster/glusterd2/glusterd2/xlator"
|
||||
"github.com/gluster/glusterd2/pkg/api"
|
||||
gderrors "github.com/gluster/glusterd2/pkg/errors"
|
||||
|
||||
@@ -36,6 +37,11 @@ import (
|
||||
config "github.com/spf13/viper"
|
||||
)
|
||||
|
||||
type txnData struct {
|
||||
Req api.SnapCreateReq
|
||||
SnapTime time.Time
|
||||
}
|
||||
|
||||
func barrierActivateDeactivateFunc(volinfo *volume.Volinfo, option string, originUUID uuid.UUID) error {
|
||||
var req brick.GfBrickOpReq
|
||||
var err error
|
||||
@@ -103,9 +109,6 @@ func deactivateBarrier(c transaction.TxnCtx) error {
|
||||
*/
|
||||
return nil
|
||||
}
|
||||
/*
|
||||
Do we need to do this ?
|
||||
*/
|
||||
var originatorUUID uuid.UUID
|
||||
if err := c.Get("originator-uuid", &originatorUUID); err != nil {
|
||||
return err
|
||||
@@ -122,11 +125,8 @@ func deactivateBarrier(c transaction.TxnCtx) error {
|
||||
c.Logger().WithFields(log.Fields{"volume": volinfo.Name}).Info("Sending Barrier request to bricks")
|
||||
|
||||
err = barrierActivateDeactivateFunc(volinfo, "disable", originatorUUID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return err
|
||||
|
||||
}
|
||||
|
||||
@@ -162,11 +162,7 @@ func activateBarrier(c transaction.TxnCtx) error {
|
||||
c.Logger().WithFields(log.Fields{"volume": volinfo.Name}).Info("Sending Barrier request to bricks")
|
||||
|
||||
err = barrierActivateDeactivateFunc(volinfo, "enable", originatorUUID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return err
|
||||
|
||||
}
|
||||
func undoBrickSnapshots(c transaction.TxnCtx) error {
|
||||
@@ -328,14 +324,18 @@ func populateSnapBrickMountData(volinfo *volume.Volinfo, snapName string) (map[s
|
||||
}
|
||||
|
||||
func validateSnapCreate(c transaction.TxnCtx) error {
|
||||
var req api.SnapCreateReq
|
||||
var statusStr []string
|
||||
var err error
|
||||
var nodeData map[string]snapshot.BrickMountData
|
||||
var volinfo *volume.Volinfo
|
||||
if err = c.Get("req", &req); err != nil {
|
||||
var (
|
||||
statusStr []string
|
||||
err error
|
||||
nodeData map[string]snapshot.BrickMountData
|
||||
volinfo *volume.Volinfo
|
||||
data txnData
|
||||
)
|
||||
|
||||
if err := c.Get("data", &data); err != nil {
|
||||
return err
|
||||
}
|
||||
req := &data.Req
|
||||
|
||||
volinfo, err = volume.GetVolume(req.VolName)
|
||||
if err != nil {
|
||||
@@ -374,7 +374,6 @@ func validateSnapCreate(c transaction.TxnCtx) error {
|
||||
return errors.New("one or more brick is not compatable")
|
||||
}
|
||||
if nodeData, err = populateSnapBrickMountData(volinfo, req.SnapName); err != nil {
|
||||
|
||||
return err
|
||||
}
|
||||
c.SetNodeResult(gdctx.MyUUID, snapshot.NodeDataTxnKey, &nodeData)
|
||||
@@ -523,7 +522,7 @@ func createSnapSubvols(newVolinfo, origVolinfo *volume.Volinfo, nodeData map[str
|
||||
}
|
||||
|
||||
func createSnapinfo(c transaction.TxnCtx) error {
|
||||
var req api.SnapCreateReq
|
||||
var data txnData
|
||||
ignoreOps := map[string]string{
|
||||
"features.quota": "off",
|
||||
"features.inode-quota": "off",
|
||||
@@ -536,9 +535,10 @@ func createSnapinfo(c transaction.TxnCtx) error {
|
||||
}
|
||||
|
||||
nodeData := make(map[string]snapshot.BrickMountData)
|
||||
if err := c.Get("req", &req); err != nil {
|
||||
if err := c.Get("data", &data); err != nil {
|
||||
return err
|
||||
}
|
||||
req := &data.Req
|
||||
|
||||
volinfo, err := volume.GetVolume(req.VolName)
|
||||
if err != nil {
|
||||
@@ -547,8 +547,7 @@ func createSnapinfo(c transaction.TxnCtx) error {
|
||||
|
||||
for _, node := range volinfo.Nodes() {
|
||||
tmp := make(map[string]snapshot.BrickMountData)
|
||||
err := c.GetNodeResult(node, snapshot.NodeDataTxnKey, &tmp)
|
||||
if err != nil {
|
||||
if err := c.GetNodeResult(node, snapshot.NodeDataTxnKey, &tmp); err != nil {
|
||||
return err
|
||||
}
|
||||
for k, v := range tmp {
|
||||
@@ -561,9 +560,21 @@ func createSnapinfo(c transaction.TxnCtx) error {
|
||||
duplicateVolinfo(volinfo, snapVolinfo)
|
||||
|
||||
snapInfo.OptionChange = make(map[string]string)
|
||||
snapInfo.SnapTime = data.SnapTime
|
||||
|
||||
for key, value := range ignoreOps {
|
||||
snapInfo.OptionChange[key] = snapVolinfo.Options[key]
|
||||
currentValue, ok := snapVolinfo.Options[key]
|
||||
if !ok {
|
||||
//Option is not reconfigured, Storing default value
|
||||
option, err := xlator.FindOption(key)
|
||||
if err != nil {
|
||||
//On failure return from here when all the xlator options are ported
|
||||
} else {
|
||||
currentValue = option.DefaultValue
|
||||
}
|
||||
}
|
||||
|
||||
snapInfo.OptionChange[key] = currentValue
|
||||
snapVolinfo.Options[key] = value
|
||||
}
|
||||
|
||||
@@ -580,8 +591,7 @@ func createSnapinfo(c transaction.TxnCtx) error {
|
||||
For now disabling heal
|
||||
*/
|
||||
|
||||
err = createSnapSubvols(snapVolinfo, volinfo, nodeData)
|
||||
if err != nil {
|
||||
if err = createSnapSubvols(snapVolinfo, volinfo, nodeData); err != nil {
|
||||
log.WithError(err).WithFields(log.Fields{
|
||||
"snapshot": snapVolinfo.Name,
|
||||
"volumeName": volinfo.Name,
|
||||
@@ -597,10 +607,7 @@ func createSnapinfo(c transaction.TxnCtx) error {
|
||||
*/
|
||||
|
||||
err = c.Set("snapinfo", snapInfo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return err
|
||||
}
|
||||
|
||||
func duplicateVolinfo(vol, v *volume.Volinfo) {
|
||||
@@ -640,10 +647,13 @@ func snapshotBrickCreate(snapName, volName, mountDir string, subvolNumber, brick
|
||||
}
|
||||
|
||||
func validateOriginNodeSnapCreate(c transaction.TxnCtx) error {
|
||||
var req api.SnapCreateReq
|
||||
if err := c.Get("req", &req); err != nil {
|
||||
var data txnData
|
||||
|
||||
if err := c.Get("data", &data); err != nil {
|
||||
return err
|
||||
}
|
||||
req := &data.Req
|
||||
|
||||
if snapshot.ExistsFunc(req.SnapName) {
|
||||
return gderrors.ErrSnapExists
|
||||
}
|
||||
@@ -654,7 +664,6 @@ func validateOriginNodeSnapCreate(c transaction.TxnCtx) error {
|
||||
}
|
||||
|
||||
if volinfo.State != volume.VolStarted {
|
||||
|
||||
return errors.New("volume has not started")
|
||||
}
|
||||
barrierOp := volinfo.Options["features.barrier"]
|
||||
@@ -699,9 +708,10 @@ func registerSnapCreateStepFuncs() {
|
||||
|
||||
func snapshotCreateHandler(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
req := new(api.SnapCreateReq)
|
||||
logger := gdctx.GetReqLogger(ctx)
|
||||
var snapInfo snapshot.Snapinfo
|
||||
var data txnData
|
||||
req := &data.Req
|
||||
|
||||
err := unmarshalSnapCreateRequest(req, r)
|
||||
if err != nil {
|
||||
@@ -710,8 +720,8 @@ func snapshotCreateHandler(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
if req.TimeStamp == true {
|
||||
t := time.Now().UTC()
|
||||
req.SnapName = req.SnapName + t.Format("_GMT_2006_01_02_15_04_05")
|
||||
data.SnapTime = time.Now().UTC()
|
||||
req.SnapName = req.SnapName + data.SnapTime.Format("_GMT_2006_01_02_15_04_05")
|
||||
}
|
||||
|
||||
if !volume.IsValidName(req.SnapName) {
|
||||
@@ -770,14 +780,13 @@ func snapshotCreateHandler(w http.ResponseWriter, r *http.Request) {
|
||||
Nodes: []uuid.UUID{gdctx.MyUUID},
|
||||
},
|
||||
}
|
||||
err = txn.Ctx.Set("req", req)
|
||||
if err != nil {
|
||||
if err = txn.Ctx.Set("data", data); err != nil {
|
||||
logger.WithError(err).Error("failed to set request in transaction context")
|
||||
restutils.SendHTTPError(ctx, w, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
err = txn.Do()
|
||||
if err != nil {
|
||||
|
||||
if err = txn.Do(); err != nil {
|
||||
logger.WithError(err).Error("snapshot create transaction failed")
|
||||
status, err := restutils.ErrToStatusCode(err)
|
||||
restutils.SendHTTPError(ctx, w, status, err)
|
||||
@@ -785,8 +794,8 @@ func snapshotCreateHandler(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
txn.Ctx.Logger().WithField("SnapName", req.SnapName).Info("new snapshot created")
|
||||
err = txn.Ctx.Get("snapinfo", &snapInfo)
|
||||
if err != nil {
|
||||
|
||||
if err = txn.Ctx.Get("snapinfo", &snapInfo); err != nil {
|
||||
logger.WithError(err).Error("failed to get snap volinfo in transaction context")
|
||||
restutils.SendHTTPError(ctx, w, http.StatusInternalServerError, err)
|
||||
return
|
||||
@@ -809,5 +818,6 @@ func createSnapInfoResp(snap *snapshot.Snapinfo) *api.SnapInfo {
|
||||
VolInfo: *vinfo,
|
||||
ParentVolName: snap.ParentVolume,
|
||||
Description: snap.Description,
|
||||
SnapTime: (snap.SnapTime).Format("Mon Jan _2 2006 15:04:05 GMT"),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package snapshotcommands
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/gluster/glusterd2/glusterd2/brick"
|
||||
@@ -29,15 +28,12 @@ func validateSnapDeactivate(c transaction.TxnCtx) error {
|
||||
}
|
||||
|
||||
vol := &snapinfo.SnapVolinfo
|
||||
switch vol.State == volume.VolStarted {
|
||||
case true:
|
||||
if vol.State == volume.VolStarted {
|
||||
brickinfos, err = snapshot.GetOnlineBricks(vol)
|
||||
if err != nil {
|
||||
log.WithError(err).Error("failed to get online Bricks")
|
||||
return err
|
||||
}
|
||||
case false:
|
||||
return errors.New("snapshot is already stopped")
|
||||
|
||||
}
|
||||
if err := c.SetNodeResult(gdctx.MyUUID, "brickListToOperate", &brickinfos); err != nil {
|
||||
@@ -69,8 +65,7 @@ func deactivateSnapshot(c transaction.TxnCtx) error {
|
||||
//TODO Stop other process of snapshot volume
|
||||
//Yet to implement a generic way in glusterd2
|
||||
|
||||
err = snapshot.ActivateDeactivateFunc(snapinfo, brickinfos, activate, c.Logger())
|
||||
if err != nil {
|
||||
if err = snapshot.ActivateDeactivateFunc(snapinfo, brickinfos, activate, c.Logger()); err != nil {
|
||||
return err
|
||||
}
|
||||
vol := &snapinfo.SnapVolinfo
|
||||
@@ -164,6 +159,11 @@ func snapshotDeactivateHandler(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
vol = &snapinfo.SnapVolinfo
|
||||
if vol.State != volume.VolStarted {
|
||||
errMsg := "snapshot is already deactivated"
|
||||
restutils.SendHTTPError(ctx, w, http.StatusBadRequest, errMsg)
|
||||
return
|
||||
}
|
||||
|
||||
txn.Nodes = vol.Nodes()
|
||||
txn.Steps = []*transaction.Step{
|
||||
@@ -182,15 +182,13 @@ func snapshotDeactivateHandler(w http.ResponseWriter, r *http.Request) {
|
||||
Nodes: []uuid.UUID{gdctx.MyUUID},
|
||||
},
|
||||
}
|
||||
err = txn.Ctx.Set("snapname", &snapname)
|
||||
if err != nil {
|
||||
if err = txn.Ctx.Set("snapname", &snapname); err != nil {
|
||||
log.WithError(err).Error("failed to set snap name in transaction context")
|
||||
restutils.SendHTTPError(ctx, w, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
|
||||
err = txn.Do()
|
||||
if err != nil {
|
||||
if err = txn.Do(); err != nil {
|
||||
log.WithError(err).WithField("snapshot", snapname).Error("failed to de-activate snap")
|
||||
restutils.SendHTTPError(ctx, w, http.StatusInternalServerError, err)
|
||||
return
|
||||
|
||||
@@ -331,28 +331,24 @@ func snapshotRestoreHandler(w http.ResponseWriter, r *http.Request) {
|
||||
Nodes: []uuid.UUID{gdctx.MyUUID},
|
||||
},
|
||||
}
|
||||
err = txn.Ctx.Set("snapname", snapname)
|
||||
if err != nil {
|
||||
if err = txn.Ctx.Set("snapname", snapname); err != nil {
|
||||
logger.WithError(err).Error("failed to set request in transaction context")
|
||||
restutils.SendHTTPError(ctx, w, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
err = txn.Ctx.Set("snapinfo", snapinfo)
|
||||
if err != nil {
|
||||
if err = txn.Ctx.Set("snapinfo", snapinfo); err != nil {
|
||||
logger.WithError(err).Error("failed to set request in transaction context")
|
||||
restutils.SendHTTPError(ctx, w, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
|
||||
err = txn.Ctx.Set("volinfo", vol)
|
||||
if err != nil {
|
||||
if err = txn.Ctx.Set("volinfo", vol); err != nil {
|
||||
logger.WithError(err).Error("failed to set request in transaction context")
|
||||
restutils.SendHTTPError(ctx, w, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
|
||||
err = txn.Do()
|
||||
if err != nil {
|
||||
if err = txn.Do(); err != nil {
|
||||
logger.WithError(err).Error("snapshot restore transaction failed")
|
||||
restutils.SendHTTPError(ctx, w, http.StatusInternalServerError, err)
|
||||
return
|
||||
|
||||
@@ -118,8 +118,7 @@ func snapshotStatusHandler(w http.ResponseWriter, r *http.Request) {
|
||||
txn.DontCheckAlive = true
|
||||
txn.DisableRollback = true
|
||||
|
||||
err = txn.Do()
|
||||
if err != nil {
|
||||
if err = txn.Do(); err != nil {
|
||||
logger.WithError(err).WithField("snapname", snapname).Error("Failed to get snapshot status")
|
||||
restutils.SendHTTPError(ctx, w, http.StatusInternalServerError, err)
|
||||
return
|
||||
|
||||
@@ -88,11 +88,7 @@ func IsThinLV(brickPath string) bool {
|
||||
func MountSnapshotDirectory(mountPath string, mountData brick.MountInfo) error {
|
||||
err := utils.ExecuteCommandRun("mount", "-o", mountData.MntOpts, mountData.DevicePath, mountPath)
|
||||
// Use syscall.Mount command to mount the bricks
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return err
|
||||
}
|
||||
|
||||
//GetVgName creates the device path for lvm snapshot
|
||||
@@ -116,8 +112,7 @@ func RemoveBrickSnapshot(devicePath string) error {
|
||||
func LVSnapshot(originDevice, DevicePath string) error {
|
||||
|
||||
cmd := exec.Command(CreateCommand, "-s", originDevice, "--setactivationskip", "n", "--name", DevicePath)
|
||||
err := cmd.Start()
|
||||
if err != nil {
|
||||
if err := cmd.Start(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -133,8 +128,7 @@ func UpdateFsLabel(DevicePath, FsType string) error {
|
||||
switch FsType {
|
||||
case "xfs":
|
||||
label := uuid[:12]
|
||||
err := utils.ExecuteCommandRun("xfs_admin", "-L", label, DevicePath)
|
||||
if err != nil {
|
||||
if err := utils.ExecuteCommandRun("xfs_admin", "-L", label, DevicePath); err != nil {
|
||||
return err
|
||||
}
|
||||
case "ext4":
|
||||
@@ -143,8 +137,7 @@ func UpdateFsLabel(DevicePath, FsType string) error {
|
||||
fallthrough
|
||||
case "ext2":
|
||||
label := uuid[:16]
|
||||
err := utils.ExecuteCommandRun("tune2fs", "-L", label, DevicePath)
|
||||
if err != nil {
|
||||
if err := utils.ExecuteCommandRun("tune2fs", "-L", label, DevicePath); err != nil {
|
||||
return err
|
||||
}
|
||||
default:
|
||||
|
||||
@@ -95,8 +95,7 @@ func MountSnapBrickDirectory(vol *volume.Volinfo, brickinfo *brick.Brickinfo) er
|
||||
return err
|
||||
}
|
||||
|
||||
err := unix.Setxattr(brickinfo.Path, volumeIDXattrKey, vol.ID, 0)
|
||||
if err != nil {
|
||||
if err := unix.Setxattr(brickinfo.Path, volumeIDXattrKey, vol.ID, 0); err != nil {
|
||||
log.WithError(err).WithFields(log.Fields{
|
||||
"brickPath": brickinfo.Path,
|
||||
"xattr": volumeIDXattrKey}).Error("setxattr failed")
|
||||
@@ -173,11 +172,9 @@ func ActivateDeactivateFunc(snapinfo *Snapinfo, b []brick.Brickinfo, activate bo
|
||||
func CheckBricksCompatability(volinfo *volume.Volinfo) []string {
|
||||
|
||||
var paths []string
|
||||
for _, subvol := range volinfo.Subvols {
|
||||
for _, brick := range subvol.Bricks {
|
||||
if lvm.IsThinLV(brick.Path) != true {
|
||||
paths = append(paths, brick.String())
|
||||
}
|
||||
for _, brick := range volinfo.GetLocalBricks() {
|
||||
if lvm.IsThinLV(brick.Path) != true {
|
||||
paths = append(paths, brick.String())
|
||||
}
|
||||
}
|
||||
return paths
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
//Package snapshot that contains struct for snapshot
|
||||
package snapshot
|
||||
|
||||
import "github.com/gluster/glusterd2/glusterd2/volume"
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/gluster/glusterd2/glusterd2/volume"
|
||||
)
|
||||
|
||||
//Snapinfo is used to represent a snapshot
|
||||
type Snapinfo struct {
|
||||
@@ -9,4 +13,5 @@ type Snapinfo struct {
|
||||
ParentVolume string
|
||||
Description string
|
||||
OptionChange map[string]string
|
||||
SnapTime time.Time
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ type SnapInfo struct {
|
||||
VolInfo VolumeInfo `json:"snapinfo"`
|
||||
ParentVolName string `json:"parentname"`
|
||||
Description string `json:"description"`
|
||||
SnapTime string `json:"snaptime"`
|
||||
}
|
||||
|
||||
//SnapList contains snapshot name of a volume
|
||||
|
||||
@@ -48,7 +48,7 @@ var (
|
||||
ErrEmptySnapName = errors.New("snapshot name is empty")
|
||||
ErrSnapExists = errors.New("snapshot already exists")
|
||||
ErrSnapNotFound = errors.New("snapshot not found")
|
||||
ErrSnapNotActivated = errors.New("Snapshot not activated")
|
||||
ErrSnapNotActivated = errors.New("snapshot not activated")
|
||||
ErrInvalidVolFlags = errors.New("invalid volume flags")
|
||||
ErrMetadataSizeOutOfBounds = errors.New("metadata size exceeds max allowed size of 4KB")
|
||||
ErrFetchingVolfileContent = errors.New("unable to fetch volfile content")
|
||||
|
||||
Reference in New Issue
Block a user