1 /* 2 Copyright The containerd Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package cgroups 18 19 import ( 20 "errors" 21 ) 22 23 var ( 24 // ErrIgnoreSubsystem allows the specific subsystem to be skipped 25 ErrIgnoreSubsystem = errors.New("skip subsystem") 26 // ErrDevicesRequired is returned when the devices subsystem is required but 27 // does not exist or is not active 28 ErrDevicesRequired = errors.New("devices subsystem is required") 29 ) 30 31 // InitOpts allows configuration for the creation or loading of a cgroup 32 type InitOpts func(*InitConfig) error 33 34 // InitConfig provides configuration options for the creation 35 // or loading of a cgroup and its subsystems 36 type InitConfig struct { 37 // InitCheck can be used to check initialization errors from the subsystem 38 InitCheck InitCheck 39 } 40 41 func newInitConfig() *InitConfig { 42 return &InitConfig{ 43 InitCheck: RequireDevices, 44 } 45 } 46 47 // InitCheck allows subsystems errors to be checked when initialized or loaded 48 type InitCheck func(Subsystem, Path, error) error 49 50 // AllowAny allows any subsystem errors to be skipped 51 func AllowAny(_ Subsystem, _ Path, _ error) error { 52 return ErrIgnoreSubsystem 53 } 54 55 // RequireDevices requires the device subsystem but no others 56 func RequireDevices(s Subsystem, _ Path, _ error) error { 57 if s.Name() == Devices { 58 return ErrDevicesRequired 59 } 60 return ErrIgnoreSubsystem 61 } 62