1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
// -*- Mode: Go; indent-tabs-mode: t -*-
/*
* Copyright (C) Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package builtin
import (
"math"
"github.com/snapcore/snapd/interfaces"
"github.com/snapcore/snapd/interfaces/compatibility"
"github.com/snapcore/snapd/interfaces/ldconfig"
"github.com/snapcore/snapd/snap"
)
const cudaDriverLibsSummary = `allows exposing CUDA driver libraries to the system`
// Plugs only supported for the system on classic for the moment (note this is
// checked on "system" snap installation even though this is an implicit plug
// in that case) - in the future we will allow snaps having this as plug and
// this declaration will have to change.
const cudaDriverLibsBaseDeclarationPlugs = `
cuda-driver-libs:
allow-installation:
plug-snap-type:
- core
allow-connection:
slots-per-plug: *
deny-auto-connection: true
`
// Installation only allowed if permitted by the snap declaration (for asserted snaps)
const cudaDriverLibsBaseDeclarationSlots = `
cuda-driver-libs:
allow-installation: false
deny-auto-connection: true
`
// cudaDriverLibsInterface allows exposing CUDA driver libraries to the system or snaps.
type cudaDriverLibsInterface struct {
commonInterface
}
func (iface *cudaDriverLibsInterface) BeforePrepareSlot(slot *snap.SlotInfo) error {
var compatField string
if err := slot.Attr("compatibility", &compatField); err != nil {
return err
}
// Validate format of compatibility field - we don't actually need to do
// anything else with it until we start to support regular snaps.
_, err := compatibility.DecodeCompatField(compatField,
&compatibility.CompatSpec{Dimensions: []compatibility.CompatDimension{
{Tag: "cuda", Values: []compatibility.CompatRange{{Min: 0, Max: math.MaxUint}}},
{Tag: "ubuntu", Values: []compatibility.CompatRange{{Min: 2404, Max: math.MaxUint}}},
}})
if err != nil {
return err
}
// Validate directories
return validateLdconfigLibDirs(slot)
}
func (iface *cudaDriverLibsInterface) LdconfigConnectedPlug(spec *ldconfig.Specification, plug *interfaces.ConnectedPlug, slot *interfaces.ConnectedSlot) error {
// The plug can only be the system plug for the time being
return addLdconfigLibDirs(spec, slot)
}
func (iface *cudaDriverLibsInterface) AutoConnect(*snap.PlugInfo, *snap.SlotInfo) bool {
// TODO This might need changes when we support plugs in non-system
// snaps for this interface.
return true
}
func init() {
registerIface(&cudaDriverLibsInterface{
commonInterface: commonInterface{
name: "cuda-driver-libs",
summary: cudaDriverLibsSummary,
baseDeclarationPlugs: cudaDriverLibsBaseDeclarationPlugs,
baseDeclarationSlots: cudaDriverLibsBaseDeclarationSlots,
// Not supported on core yet
implicitPlugOnCore: false,
implicitPlugOnClassic: true,
},
})
}
|