Skip to content

Commit

Permalink
vzstorage-pd: revoke lease before deleting an image file
Browse files Browse the repository at this point in the history
If a file is used by someone, it can't be deleted without
revoking its lease.

Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
  • Loading branch information
avagin committed Feb 9, 2018
1 parent 528511d commit 2759ea8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
2 changes: 1 addition & 1 deletion vzstorage-pd/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ GITID ?= $(shell git describe --always HEAD || true)
TARNAME := $(NAME)-$(GITID)

all:
go build .
go build -i .
.PHONY: all

tar: $(TARNAME).tar.bz2
Expand Down
31 changes: 28 additions & 3 deletions vzstorage-pd/virtuozzo-provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,38 @@ func (p *vzFSProvisioner) patchSecret(oldSecret, newSecret *v1.Secret) error {
}

func removePloop(mount string, options map[string]string) error {
volumePath := options["volumePath"]
volumeID := options["volumeID"]
deltasPath, ok := options["deltasPath"]
if !ok {
deltasPath = volumePath
}
imageDir := path.Join(mount, deltasPath, volumeID+".image")
ploopPath := path.Join(mount, options["volumePath"], options["volumeID"])
vol, err := ploop.PloopVolumeOpen(ploopPath)
ploopPathTmp := path.Join(mount, options["volumePath"], options["volumeID"]+".deleted")
err := os.Rename(ploopPath, ploopPathTmp)
if err != nil {
return err
}

cmd := "vstorage"
args := []string{"revoke", "-R", imageDir}
err = exec.Command(cmd, args...).Run()
if err != nil {
glog.Errorf("Unable to revoke a lease for %s", imageDir)
}

vol, err := ploop.PloopVolumeOpen(ploopPathTmp)
if err != nil {
return err
}
glog.Infof("Delete: %s", ploopPath)
return vol.Delete()
glog.Infof("Delete: %s", ploopPathTmp)
err = vol.Delete()
if err != nil {
return err
}
os.RemoveAll(imageDir)
return nil
}

// Provision creates a storage asset and returns a PV object representing it.
Expand Down

0 comments on commit 2759ea8

Please sign in to comment.