-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Vladimir Popov <[email protected]>
- Loading branch information
Vladimir Popov
committed
Oct 28, 2020
1 parent
68f46a3
commit 0cfd526
Showing
8 changed files
with
232 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright (c) 2020 Doc.ai and/or its affiliates. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at: | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package pci | ||
|
||
import "github.com/networkservicemesh/sdk-sriov/pkg/sriov/storage" | ||
|
||
type pciStorage struct { | ||
storage storage.Storage | ||
} | ||
|
||
func (s *pciStorage) store(kernelDrivers map[string]string) { | ||
s.storage.Store(kernelDrivers) | ||
} | ||
|
||
func (s *pciStorage) load() map[string]string { | ||
return s.storage.Load() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,4 +33,3 @@ physicalFunctions: | |
iommuGroup: 1 | ||
- address: 0000:03:00.3 | ||
iommuGroup: 1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright (c) 2020 Doc.ai and/or its affiliates. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at: | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// Package storage provides interface for key-value storage | ||
package storage | ||
|
||
// Storage is a state storage interface | ||
type Storage interface { | ||
Store(state map[string]string) | ||
Load() map[string]string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright (c) 2020 Doc.ai and/or its affiliates. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at: | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package storage | ||
|
||
// TestStorage is a simple map-based Storage for testing | ||
type TestStorage struct { | ||
state map[string]string | ||
} | ||
|
||
// NewTestStorage returns a new TestStorage | ||
func NewTestStorage() *TestStorage { | ||
return &TestStorage{ | ||
state: map[string]string{}, | ||
} | ||
} | ||
|
||
// Store stores state | ||
func (s *TestStorage) Store(state map[string]string) { | ||
s.state = state | ||
} | ||
|
||
// Load loads state | ||
func (s *TestStorage) Load() map[string]string { | ||
return s.state | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright (c) 2020 Doc.ai and/or its affiliates. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at: | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package token | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"github.com/networkservicemesh/sdk-sriov/pkg/sriov/storage" | ||
) | ||
|
||
type tokenStorage struct { | ||
storage storage.Storage | ||
} | ||
|
||
type storedToken struct { | ||
ID string `json:"id"` | ||
Name string `json:"name"` | ||
} | ||
|
||
func (s *tokenStorage) store(tokens map[string]*token) { | ||
state := map[string]string{} | ||
for id, tok := range tokens { | ||
state[id] = marshallToken(tok) | ||
} | ||
s.storage.Store(state) | ||
} | ||
|
||
func marshallToken(tok *token) string { | ||
data, _ := json.Marshal(&storedToken{ | ||
ID: tok.id, | ||
Name: tok.name, | ||
}) | ||
return string(data) | ||
} | ||
|
||
func (s *tokenStorage) load() map[string]*token { | ||
tokens := map[string]*token{} | ||
state := s.storage.Load() | ||
for id, s := range state { | ||
tokens[id] = unmarshallToken(s) | ||
} | ||
return tokens | ||
} | ||
|
||
func unmarshallToken(s string) (tok *token) { | ||
storedTok := storedToken{} | ||
_ = json.Unmarshal([]byte(s), &storedTok) | ||
|
||
return &token{ | ||
id: storedTok.ID, | ||
name: storedTok.Name, | ||
state: free, | ||
} | ||
} |