token

package
v1.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 6, 2022 License: Apache-2.0 Imports: 5 Imported by: 3

Documentation

Overview

Package token provides a token pool for SR-IOV resources

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Pool

type Pool struct {
	// contains filtered or unexported fields
}

Pool manages forwarder SR-IOV resource tokens

func NewPool

func NewPool(cfg *config.Config) *Pool

NewPool returns a new Pool

func (*Pool) AddListener

func (p *Pool) AddListener(listener func())

AddListener adds a new listener that fires on tokens state change to/from "closed"

func (*Pool) Allocate

func (p *Pool) Allocate(id string) error

Allocate marks a token selected by the given ID as "allocated": * `free` -> `allocated` (common case) * `allocated` -> `allocated` (we have not called Free, but Device Plugin is already using the token) * `inUse` -stopUsing-> `allocated` (we have not called StopUsing, Free, but Device Plugin is already using the token) * `closed` -XXX-> `error`

func (*Pool) Find

func (p *Pool) Find(id string) (string, error)

Find returns a token name selected by the given ID

func (*Pool) Free

func (p *Pool) Free(id string) error

Free marks a token selected by the given ID as "free": * `free` -> `free` (nothing to do here) * `allocated` -> `free` (common case) * `inUse` -stopUsing-> `allocated` -> `free` (we have not called StopUsing, but the client have died) * `closed` -> `closed` (we should not fail, but we cannot free closed token)

func (*Pool) Restore

func (p *Pool) Restore(tokens map[string][]string) error

Restore replaces part of existing tokens with given tokens and set them into the allocated state NOTE: it can be called only on untouched Pool, any actions will disable Restore

func (*Pool) StopUsing

func (p *Pool) StopUsing(id string) error

StopUsing marks an "inUse" token selected by ID as "allocated" and frees all related closed tokens: * `free` -XXX-> `error` * `allocated` -XXX-> `error` * `inUse` -> `allocated` (common case) * `closed` -XXX-> `error`

func (*Pool) ToEnv added in v1.1.0

func (p *Pool) ToEnv(tokenName string, tokenIDs []string) (name, value string)

ToEnv returns a (name, value) pair to store given tokens into the environment variable

func (*Pool) Tokens

func (p *Pool) Tokens() map[string]map[string]bool

Tokens returns a map of tokens by names marked as available/not available

func (*Pool) Use

func (p *Pool) Use(id string, names []string) error

Use marks a token selected by the given ID as "inUse" and closes 1 token for any of names: * `free` -> `inUse` (allocated token has been closed and freed, but the client have not died) * `allocated` -> `inUse` (common case) * `inUse` -XXX-> `error` * `closed` -XXX-> `error`

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL