Skip to content

Delete vmdk first before delete directory for vc 6.5 or newer#2652

Merged
emlin merged 6 commits intovmware:masterfrom
emlin:2014
Oct 18, 2016
Merged

Delete vmdk first before delete directory for vc 6.5 or newer#2652
emlin merged 6 commits intovmware:masterfrom
emlin:2014

Conversation

@emlin
Copy link
Contributor

@emlin emlin commented Oct 11, 2016

Fixes #2014
In VC 6.5, if we delete datastore file directories, with linked vmdk files inside, delete will fail, even we don't have any delta vmdks rely on them.
Delete from UI does not work as well.

The only workaround for this issue, is to delete in vSAN model, delete vmdk files first, and then file directory.


m := object.NewFileManager(ds.Client())
if d.isVSAN(ds) {
if d.geVC65() || d.isVSAN(ds) {
Copy link
Contributor

@fdawg4l fdawg4l Oct 11, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we do this (call deleteFiles...) all the time? Do we need to only do it for 65 or vsan?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, this will make the delete slower, especially while there are many images downloaded.


m := object.NewFileManager(ds.Client())
if d.isVSAN(ds) {
if d.geVC65() || d.isVSAN(ds) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Why is the caller responsible for knowing the exact model by which you have to delete files?
  2. Why even bother with separate paths (this is purely an optimization)

Can we have d.deleteFiles(m, ds, dsPath) - if we really have to have the optimization, the check should be inside that function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, the top level method to delete should be method
func (d *Dispatcher) deleteDatastoreFiles(ds *object.Datastore, path string, force bool) (bool, error)
So caller doesn't need to care about the internal impl, I think.

The last comment is same to @fdawg4l mentioned above. But I think delete interactively is not an optimization. It will slow down the delete.
But if vsphere is going this way, and we don't care too much about 6.0, it's also fine to remove this branch.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't care too much about moving to a consolidated branch, but having this logic here instead of in the pkg/vsphere/datastore code means that every single caller who wants to delete a tree has to do this same version detection or know the specifics of how to do a recursive deletion.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the pkg/vsphere/datastore is meant to be a common pkg could be used by both vic-machine and storage portlayer, but there is some assumption not exists in vic-machine.
I could refactor code to merge them two, but probably not at this time.

func (d *Dispatcher) geVC65() bool {
vcVersion := d.session.Client.ServiceContent.About.Version
// vsphere only has versions 5.5.x, 6.0.x, 6.5.x, not likely to have 6.10.x, so compare string directly here
return strings.Compare(vcVersion, "6.5.0") >= 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think https://golang.org/pkg/strings/#HasPrefix could be more suitable here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so you mean anything without "6.0." prefix? In case, vsphere does not provide any patch like 6.1.x.
anyway, not likely...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only reason for this method is to select a difference in a specific behaviour. If this is being broken out into a separate method then it should be something like deleteRequiresEmptyDirectory() that actually describes the use. Otherwise we'll end up with geVC70 as well once 6.5 is released and we start testing against vmkernel main.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not quite sure about this point.
Current method name just shows the function itself, and the caller decides how to use it. That is same to the definition of isVSAN() method.

For the method in the future of geVC70, that must be other function difference between VC 6.5 and VC 7.0.
We could limit such kind of difference, and I don't prefer to have this detection, just if without this branch, there will have side effect, and that's not necessary for VC 6.0 as I said above.
So if we agree for this impact, I can remove the detection, and keep them consistent in VMFS file system and vSAN, for both VC versions.


m := object.NewFileManager(ds.Client())
if d.isVSAN(ds) {
if d.geVC65() || d.isVSAN(ds) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't care too much about moving to a consolidated branch, but having this logic here instead of in the pkg/vsphere/datastore code means that every single caller who wants to delete a tree has to do this same version detection or know the specifics of how to do a recursive deletion.

func (d *Dispatcher) geVC65() bool {
vcVersion := d.session.Client.ServiceContent.About.Version
// vsphere only has versions 5.5.x, 6.0.x, 6.5.x, not likely to have 6.10.x, so compare string directly here
return strings.Compare(vcVersion, "6.5.0") >= 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only reason for this method is to select a difference in a specific behaviour. If this is being broken out into a separate method then it should be something like deleteRequiresEmptyDirectory() that actually describes the use. Otherwise we'll end up with geVC70 as well once 6.5 is released and we start testing against vmkernel main.

@dougm
Copy link
Member

dougm commented Oct 12, 2016

What is the error with 6.5? And vSAN?

"Folder deletes are always recursive" http://pubs.vmware.com/vsphere-60/index.jsp#com.vmware.wssdk.apiref.doc/vim.FileManager.html#deleteFile

@emlin
Copy link
Contributor Author

emlin commented Oct 12, 2016

@dougm Well the problem in vSAN and 6.5 is slightly different.

vSAN: to delete a folder, the folder must be empty.
But it is a semi-random issue. Delete folder usually works well, but if there is any error happens, clear all files, and then delete folder will be the only solution.

6.5: delete folder works well, if there is no linked disk chain.
In our case, image pull will create vmdk files, as well as metadata file. If clear the vmdk files, delete folder works well, even with metadata files and folders exists.
So in this case, clear all files first, and then delete folder can be the workaround.

For the recursive delete, thanks for the reference. I didn't know that.
But even that's the case, if we have thousands of images, and even more layers, it will still be much better to call vsphere once and recursively delete inside of vc, than to call vsphere API thousands of times.

  Do not differentiate vc6.0 and 6.5, vmfs and vsan datastore
  to reduce difference based on env.
@hickeng
Copy link
Contributor

hickeng commented Oct 14, 2016

LGTM

@andrewtchin
Copy link
Contributor

lgtm

1 similar comment
@mdubya66
Copy link
Contributor

lgtm

@emlin
Copy link
Contributor Author

emlin commented Oct 18, 2016

♻️

@emlin emlin merged commit 0be8891 into vmware:master Oct 18, 2016
@emlin
Copy link
Contributor Author

emlin commented Oct 18, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants