Skip to content

Commit d94f15a

Browse files
committed
VMware vSphere Driver
This patch introduces the new VMware vSphere Driver - "vmw". The driver uses VMCI Sockets (https://www.vmware.com/support/developer/vmci-sdk/) to communicate directly with a vSphere host, removing the need for the sizeable VMware SDK for Go library dependency.
1 parent 8570256 commit d94f15a

File tree

18 files changed

+2206
-21
lines changed

18 files changed

+2206
-21
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*.d
88
*.out
99
got
10+
gob
1011
libstorage.paw
1112
.site/
1213
site/
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// +build linux
2+
// +build !libstorage_storage_executor libstorage_storage_executor_vmw
3+
4+
package executor
5+
6+
import (
7+
gofig "github.com/akutz/gofig/types"
8+
9+
"github.com/codedellemc/libstorage/api/registry"
10+
"github.com/codedellemc/libstorage/api/types"
11+
"github.com/codedellemc/libstorage/drivers/storage/vmw"
12+
)
13+
14+
type driver struct {
15+
config gofig.Config
16+
}
17+
18+
func init() {
19+
registry.RegisterStorageExecutor(vmw.Name, newDriver)
20+
}
21+
22+
func newDriver() types.StorageExecutor {
23+
return &driver{}
24+
}
25+
26+
func (d *driver) Name() string {
27+
return vmw.Name
28+
}
29+
30+
func (d *driver) Supported(
31+
ctx types.Context,
32+
opts types.Store) (bool, error) {
33+
34+
return true, nil
35+
}
36+
37+
func (d *driver) Init(ctx types.Context, config gofig.Config) error {
38+
d.config = config
39+
return nil
40+
}
41+
42+
// InstanceID returns the local system's InstanceID.
43+
func (d *driver) InstanceID(
44+
ctx types.Context,
45+
opts types.Store) (*types.InstanceID, error) {
46+
47+
iid := &types.InstanceID{Driver: vmw.Name}
48+
iid.ID = vmw.Name
49+
return iid, nil
50+
}
51+
52+
// NextDevice returns the next available device.
53+
func (d *driver) NextDevice(
54+
ctx types.Context,
55+
opts types.Store) (string, error) {
56+
57+
return "", nil
58+
}
59+
60+
// LocalDevices returns a map of the system's local devices.
61+
func (d *driver) LocalDevices(
62+
ctx types.Context,
63+
opts *types.LocalDevicesOpts) (*types.LocalDevices, error) {
64+
65+
return &types.LocalDevices{DeviceMap: map[string]string{}}, nil
66+
}
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
// +build linux
2+
// +build !libstorage_storage_driver libstorage_storage_driver_vmw
3+
4+
package storage
5+
6+
import (
7+
gofig "github.com/akutz/gofig/types"
8+
9+
"github.com/codedellemc/libstorage/api/registry"
10+
"github.com/codedellemc/libstorage/api/types"
11+
12+
"github.com/codedellemc/libstorage/drivers/storage/vmw"
13+
14+
// load the vmci pkg
15+
_ "github.com/codedellemc/libstorage/drivers/storage/vmw/vmci"
16+
//_ "github.com/vmware/docker-volume-vsphere/vmdk_plugin/drivers/vmdk/vmdkops"
17+
)
18+
19+
const (
20+
minSizeGiB = 1
21+
)
22+
23+
type driver struct {
24+
ctx types.Context
25+
config gofig.Config
26+
}
27+
28+
func init() {
29+
registry.RegisterStorageDriver(vmw.Name, newDriver)
30+
}
31+
32+
func newDriver() types.StorageDriver {
33+
return &driver{}
34+
}
35+
36+
func (d *driver) Name() string {
37+
return vmw.Name
38+
}
39+
40+
func (d *driver) Type(ctx types.Context) (types.StorageType, error) {
41+
return types.Block, nil
42+
}
43+
44+
func (d *driver) Init(ctx types.Context, config gofig.Config) error {
45+
d.ctx = ctx
46+
d.config = config
47+
return nil
48+
}
49+
50+
func (d *driver) NextDeviceInfo(
51+
ctx types.Context) (*types.NextDeviceInfo, error) {
52+
return &types.NextDeviceInfo{
53+
Ignore: true,
54+
}, nil
55+
}
56+
57+
func (d *driver) InstanceInspect(
58+
ctx types.Context,
59+
opts types.Store) (*types.Instance, error) {
60+
61+
return nil, nil
62+
}
63+
64+
func (d *driver) Volumes(
65+
ctx types.Context,
66+
opts *types.VolumesOpts) ([]*types.Volume, error) {
67+
68+
return nil, nil
69+
}
70+
71+
func (d *driver) VolumeInspect(
72+
ctx types.Context,
73+
volumeID string,
74+
opts *types.VolumeInspectOpts) (*types.Volume, error) {
75+
76+
return nil, nil
77+
}
78+
79+
func (d *driver) VolumeCreate(
80+
ctx types.Context,
81+
name string,
82+
opts *types.VolumeCreateOpts) (*types.Volume, error) {
83+
84+
return nil, nil
85+
}
86+
87+
func (d *driver) VolumeCreateFromSnapshot(
88+
ctx types.Context,
89+
snapshotID, volumeName string,
90+
opts *types.VolumeCreateOpts) (*types.Volume, error) {
91+
92+
return nil, nil
93+
}
94+
95+
func (d *driver) VolumeCopy(
96+
ctx types.Context,
97+
volumeID, volumeName string,
98+
opts types.Store) (*types.Volume, error) {
99+
100+
return nil, nil
101+
}
102+
103+
func (d *driver) VolumeSnapshot(
104+
ctx types.Context,
105+
volumeID, snapshotName string,
106+
opts types.Store) (*types.Snapshot, error) {
107+
108+
return nil, nil
109+
}
110+
111+
func (d *driver) VolumeRemove(
112+
ctx types.Context,
113+
volumeID string,
114+
opts *types.VolumeRemoveOpts) error {
115+
116+
return nil
117+
}
118+
119+
func (d *driver) VolumeAttach(
120+
ctx types.Context,
121+
volumeID string,
122+
opts *types.VolumeAttachOpts) (*types.Volume, string, error) {
123+
124+
return nil, "", nil
125+
}
126+
127+
func (d *driver) VolumeDetach(
128+
ctx types.Context,
129+
volumeID string,
130+
opts *types.VolumeDetachOpts) (*types.Volume, error) {
131+
132+
return nil, nil
133+
}
134+
135+
func (d *driver) Snapshots(
136+
ctx types.Context,
137+
opts types.Store) ([]*types.Snapshot, error) {
138+
139+
return nil, nil
140+
}
141+
142+
func (d *driver) SnapshotInspect(
143+
ctx types.Context,
144+
snapshotID string,
145+
opts types.Store) (*types.Snapshot, error) {
146+
147+
return nil, nil
148+
}
149+
150+
func (d *driver) SnapshotCopy(
151+
ctx types.Context,
152+
snapshotID, snapshotName, destinationID string,
153+
opts types.Store) (*types.Snapshot, error) {
154+
155+
return nil, nil
156+
}
157+
158+
func (d *driver) SnapshotRemove(
159+
ctx types.Context,
160+
snapshotID string,
161+
opts types.Store) error {
162+
163+
return nil
164+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
VMW_COVERPKG := $(ROOT_IMPORT_PATH)/drivers/storage/vmw
2+
TEST_COVERPKG_./drivers/storage/vmw/tests := $(VMW_COVERPKG),$(VMW_COVERPKG)/executor
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// +build linux
2+
// +build !libstorage_storage_driver libstorage_storage_driver_vmw
3+
4+
package tests
5+
6+
import (
7+
"os"
8+
"testing"
9+
10+
_ "github.com/codedellemc/libstorage/api/tests"
11+
_ "github.com/codedellemc/libstorage/drivers/storage/vmw/storage"
12+
)
13+
14+
func TestMain(m *testing.M) {
15+
os.Exit(m.Run())
16+
}
17+
18+
func TestHello(t *testing.T) {
19+
t.Log("hello")
20+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Copyright 2016 VMware, Inc. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// Shared info (magic, err. codes, etc) on vSocket command channel
16+
17+
#ifndef _CONNECTION_TYPES_H_
18+
#define _CONNECTION_TYPES_H_
19+
20+
#define MAGIC 0xbadbeef
21+
22+
// -1 always indicates failure
23+
#define CONN_FAILURE (-1)
24+
25+
// 0 is usually success. Note: sometimes we return socket FD on success
26+
#define CONN_SUCCESS (0)
27+
28+
// First non privileged port
29+
#define START_NON_PRIVILEGED_PORT 1024
30+
31+
/*
32+
* Check and set errno helper
33+
* Useful when send/recv gets us less than we wanted, and we want to set errno
34+
* for the caller to know about the protocol Issue
35+
*/
36+
#define CHECK_ERRNO(_ret) {if (_ret >= 0 && errno == 0) { errno = EBADMSG; }}
37+
38+
/*
39+
* This function acquires and returns address family for vSockets.
40+
* On failure returns -1 an sets errno (if not set by VMCISock_GetAFValue ())
41+
*
42+
* The address family for vSockets must be acquired, it is not static.
43+
* The code opens and keeps FD to /dev/vsock to indicate to the kernel
44+
* that VMCI driver is used by this process.
45+
* Needs to be called once per process.
46+
* <af> is expected to be closed by process completion
47+
*/
48+
static inline int
49+
vsock_get_family(void)
50+
{
51+
static int af = -1;
52+
53+
errno = 0;
54+
if (af == -1) { // TODO: for multi-thread will need a lock. Issue #35
55+
af = VMCISock_GetAFValue();
56+
}
57+
if (af == -1 && errno == 0) {
58+
errno = EAFNOSUPPORT; // report "family not supported" upstairs
59+
}
60+
return af;
61+
}
62+
63+
#endif // _CONNECTION_TYPES_H_

0 commit comments

Comments
 (0)