MCPcopy Index your code
hub / github.com/containerd/containerd / UpdateDevice

Method UpdateDevice

plugins/snapshots/devmapper/metadata.go:227–256  ·  view source on GitHub ↗

UpdateDevice updates device info in metadata store. The callback should be used to indicate whether device info update was successful or not. An error returned from the callback will rollback the update transaction in the database. Name and Device ID are not allowed to change.

(ctx context.Context, name string, fn DeviceInfoCallback)

Source from the content-addressed store, hash-verified

225// An error returned from the callback will rollback the update transaction in the database.
226// Name and Device ID are not allowed to change.
227func (m *PoolMetadata) UpdateDevice(ctx context.Context, name string, fn DeviceInfoCallback) error {
228 return m.db.Update(func(tx *bolt.Tx) error {
229 var (
230 device = &DeviceInfo{}
231 bucket = tx.Bucket(devicesBucketName)
232 )
233
234 if err := getObject(bucket, name, device); err != nil {
235 return err
236 }
237
238 // Don't allow changing these values, keep things in sync with devmapper
239 name := device.Name
240 devID := device.DeviceID
241
242 if err := fn(device); err != nil {
243 return err
244 }
245
246 if name != device.Name {
247 return fmt.Errorf("failed to update device info, name didn't match: %q %q", name, device.Name)
248 }
249
250 if devID != device.DeviceID {
251 return fmt.Errorf("failed to update device info, device id didn't match: %d %d", devID, device.DeviceID)
252 }
253
254 return putObject(bucket, name, device, true)
255 })
256}
257
258// GetDevice retrieves device info by name from database
259func (m *PoolMetadata) GetDevice(ctx context.Context, name string) (*DeviceInfo, error) {

Callers 3

ChangeDeviceStateMethod · 0.95
transitionMethod · 0.80

Calls 3

getObjectFunction · 0.85
putObjectFunction · 0.85
UpdateMethod · 0.65

Tested by 1