Skip to content
This repository was archived by the owner on May 12, 2021. It is now read-only.

Commit c01d69d

Browse files
committed
block: Get rid of device prediction for Storage as well
Similar to Device, use PCI information for determining device name for BlkStorage handler as well. Fixes #198 Signed-off-by: Archana Shinde <archana.m.shinde@intel.com>
1 parent 95c4ccc commit c01d69d

File tree

3 files changed

+19
-22
lines changed

3 files changed

+19
-22
lines changed

grpc.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ func (a *agentGRPC) CreateContainer(ctx context.Context, req *pb.CreateContainer
439439
// After all those storages have been processed, no matter the order
440440
// here, the agent will rely on libcontainer (using the oci.Mounts
441441
// list) to bind mount all of them inside the container.
442-
mountList, err := addStorages(req.Storages)
442+
mountList, err := addStorages(req.Storages, a.sandbox)
443443
if err != nil {
444444
return emptyResp, err
445445
}
@@ -862,7 +862,7 @@ func (a *agentGRPC) CreateSandbox(ctx context.Context, req *pb.CreateSandboxRequ
862862
}
863863
}
864864

865-
mountList, err := addStorages(req.Storages)
865+
mountList, err := addStorages(req.Storages, a.sandbox)
866866
if err != nil {
867867
return emptyResp, err
868868
}

mount.go

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"strings"
1414
"syscall"
1515

16-
"github.com/kata-containers/agent/pkg/uevent"
1716
pb "github.com/kata-containers/agent/protocols/grpc"
1817
"github.com/sirupsen/logrus"
1918
"golang.org/x/sys/unix"
@@ -184,7 +183,7 @@ func removeMounts(mounts []string) error {
184183

185184
// storageHandler is the type of callback to be defined to handle every
186185
// type of storage driver.
187-
type storageHandler func(storage pb.Storage) (string, error)
186+
type storageHandler func(storage pb.Storage, s *sandbox) (string, error)
188187

189188
// storageHandlerList lists the supported drivers.
190189
var storageHandlerList = map[string]storageHandler{
@@ -194,27 +193,25 @@ var storageHandlerList = map[string]storageHandler{
194193
}
195194

196195
// virtio9pStorageHandler handles the storage for 9p driver.
197-
func virtio9pStorageHandler(storage pb.Storage) (string, error) {
196+
func virtio9pStorageHandler(storage pb.Storage, s *sandbox) (string, error) {
198197
return commonStorageHandler(storage)
199198
}
200199

201200
// virtioBlkStorageHandler handles the storage for blk driver.
202-
func virtioBlkStorageHandler(storage pb.Storage) (string, error) {
203-
// First need to make sure the expected device shows up properly.
204-
devName := strings.TrimPrefix(storage.Source, devPrefix)
205-
checkUevent := func(uEv *uevent.Uevent) bool {
206-
return (uEv.Action == "add" &&
207-
filepath.Base(uEv.DevPath) == devName)
208-
}
209-
if err := waitForDevice(storage.Source, devName, checkUevent); err != nil {
201+
func virtioBlkStorageHandler(storage pb.Storage, s *sandbox) (string, error) {
202+
// Get the device node path based on the PCI address provided
203+
// in Storage Source
204+
devPath, err := getBlockDeviceNodeName(s, storage.Source)
205+
if err != nil {
210206
return "", err
211207
}
208+
storage.Source = devPath
212209

213210
return commonStorageHandler(storage)
214211
}
215212

216213
// virtioSCSIStorageHandler handles the storage for scsi driver.
217-
func virtioSCSIStorageHandler(storage pb.Storage) (string, error) {
214+
func virtioSCSIStorageHandler(storage pb.Storage, s *sandbox) (string, error) {
218215
// Retrieve the device path from SCSI address.
219216
devPath, err := getSCSIDevPath(storage.Source)
220217
if err != nil {
@@ -248,7 +245,7 @@ func mountStorage(storage pb.Storage) error {
248245
// associated operations such as waiting for the device to show up, and mount
249246
// it to a specific location, according to the type of handler chosen, and for
250247
// each storage.
251-
func addStorages(storages []*pb.Storage) ([]string, error) {
248+
func addStorages(storages []*pb.Storage, s *sandbox) ([]string, error) {
252249
var mountList []string
253250

254251
for _, storage := range storages {
@@ -262,7 +259,7 @@ func addStorages(storages []*pb.Storage) ([]string, error) {
262259
"Unknown storage driver %q", storage.Driver)
263260
}
264261

265-
mountPoint, err := devHandler(*storage)
262+
mountPoint, err := devHandler(*storage, s)
266263
if err != nil {
267264
return nil, err
268265
}

mount_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func TestVirtio9pStorageHandlerSuccessful(t *testing.T) {
4343
storage.Fstype = "bind"
4444
storage.Options = []string{"rbind"}
4545

46-
_, err = virtio9pStorageHandler(storage)
46+
_, err = virtio9pStorageHandler(storage, &sandbox{})
4747
assert.Nil(t, err, "storage9pDriverHandler() failed: %v", err)
4848
}
4949

@@ -66,12 +66,12 @@ func TestVirtioBlkStorageHandlerSuccessful(t *testing.T) {
6666
storage.Fstype = "bind"
6767
storage.Options = []string{"rbind"}
6868

69-
_, err = virtioBlkStorageHandler(storage)
69+
_, err = virtioBlkStorageHandler(storage, &sandbox{})
7070
assert.Nil(t, err, "storageBlockStorageDriverHandler() failed: %v", err)
7171
}
7272

7373
func testAddStoragesSuccessful(t *testing.T, storages []*pb.Storage) {
74-
_, err := addStorages(storages)
74+
_, err := addStorages(storages, &sandbox{})
7575
assert.Nil(t, err, "addStorages() failed: %v", err)
7676
}
7777

@@ -89,11 +89,11 @@ func TestAddStoragesNilStoragesSuccessful(t *testing.T) {
8989
testAddStoragesSuccessful(t, storages)
9090
}
9191

92-
func noopStorageHandlerReturnNil(storage pb.Storage) (string, error) {
92+
func noopStorageHandlerReturnNil(storage pb.Storage, s *sandbox) (string, error) {
9393
return "", nil
9494
}
9595

96-
func noopStorageHandlerReturnError(storage pb.Storage) (string, error) {
96+
func noopStorageHandlerReturnError(storage pb.Storage, s *sandbox) (string, error) {
9797
return "", fmt.Errorf("Noop handler failure")
9898
}
9999

@@ -113,7 +113,7 @@ func TestAddStoragesNoopHandlerSuccessful(t *testing.T) {
113113
}
114114

115115
func testAddStoragesFailure(t *testing.T, storages []*pb.Storage) {
116-
_, err := addStorages(storages)
116+
_, err := addStorages(storages, &sandbox{})
117117
assert.NotNil(t, err, "addStorages() should have failed")
118118
}
119119

0 commit comments

Comments
 (0)