Browse code

daemon/graphdriver/devmapper/ fix lint errors/warnings Addresses #14756 Signed-off-by: Srini Brahmaroutu <srbrahma@us.ibm.com>

Srini Brahmaroutu authored on 2015/07/23 09:42:28
Showing 5 changed files
... ...
@@ -27,35 +27,35 @@ import (
27 27
 )
28 28
 
29 29
 var (
30
-	DefaultDataLoopbackSize     int64  = 100 * 1024 * 1024 * 1024
31
-	DefaultMetaDataLoopbackSize int64  = 2 * 1024 * 1024 * 1024
32
-	DefaultBaseFsSize           uint64 = 100 * 1024 * 1024 * 1024
33
-	DefaultThinpBlockSize       uint32 = 128 // 64K = 128 512b sectors
34
-	DefaultUdevSyncOverride     bool   = false
35
-	MaxDeviceId                 int    = 0xffffff // 24 bit, pool limit
36
-	DeviceIdMapSz               int    = (MaxDeviceId + 1) / 8
30
+	defaultDataLoopbackSize     int64  = 100 * 1024 * 1024 * 1024
31
+	defaultMetaDataLoopbackSize int64  = 2 * 1024 * 1024 * 1024
32
+	defaultBaseFsSize           uint64 = 100 * 1024 * 1024 * 1024
33
+	defaultThinpBlockSize       uint32 = 128 // 64K = 128 512b sectors
34
+	defaultUdevSyncOverride            = false
35
+	maxDeviceID                        = 0xffffff // 24 bit, pool limit
36
+	deviceIDMapSz                      = (maxDeviceID + 1) / 8
37 37
 	// We retry device removal so many a times that even error messages
38 38
 	// will fill up console during normal operation. So only log Fatal
39 39
 	// messages by default.
40
-	DMLogLevel                   int  = devicemapper.LogLevelFatal
41
-	DriverDeferredRemovalSupport bool = false
42
-	EnableDeferredRemoval        bool = false
40
+	logLevel                     = devicemapper.LogLevelFatal
41
+	driverDeferredRemovalSupport = false
42
+	enableDeferredRemoval        = false
43 43
 )
44 44
 
45 45
 const deviceSetMetaFile string = "deviceset-metadata"
46 46
 const transactionMetaFile string = "transaction-metadata"
47 47
 
48
-type Transaction struct {
49
-	OpenTransactionId uint64 `json:"open_transaction_id"`
50
-	DeviceIdHash      string `json:"device_hash"`
51
-	DeviceId          int    `json:"device_id"`
48
+type transaction struct {
49
+	OpenTransactionID uint64 `json:"open_transaction_id"`
50
+	DeviceIDHash      string `json:"device_hash"`
51
+	DeviceID          int    `json:"device_id"`
52 52
 }
53 53
 
54
-type DevInfo struct {
54
+type devInfo struct {
55 55
 	Hash          string `json:"-"`
56
-	DeviceId      int    `json:"device_id"`
56
+	DeviceID      int    `json:"device_id"`
57 57
 	Size          uint64 `json:"size"`
58
-	TransactionId uint64 `json:"transaction_id"`
58
+	TransactionID uint64 `json:"transaction_id"`
59 59
 	Initialized   bool   `json:"initialized"`
60 60
 	devices       *DeviceSet
61 61
 
... ...
@@ -75,19 +75,20 @@ type DevInfo struct {
75 75
 	lock sync.Mutex
76 76
 }
77 77
 
78
-type MetaData struct {
79
-	Devices     map[string]*DevInfo `json:"Devices"`
78
+type metaData struct {
79
+	Devices     map[string]*devInfo `json:"Devices"`
80 80
 	devicesLock sync.Mutex          // Protects all read/writes to Devices map
81 81
 }
82 82
 
83
+// DeviceSet holds information about list of devices
83 84
 type DeviceSet struct {
84
-	MetaData      `json:"-"`
85
+	metaData      `json:"-"`
85 86
 	sync.Mutex    `json:"-"` // Protects Devices map and serializes calls into libdevmapper
86 87
 	root          string
87 88
 	devicePrefix  string
88
-	TransactionId uint64 `json:"-"`
89
-	NextDeviceId  int    `json:"next_device_id"`
90
-	deviceIdMap   []byte
89
+	TransactionID uint64 `json:"-"`
90
+	NextDeviceID  int    `json:"next_device_id"`
91
+	deviceIDMap   []byte
91 92
 
92 93
 	// Options
93 94
 	dataLoopbackSize      int64
... ...
@@ -103,44 +104,66 @@ type DeviceSet struct {
103 103
 	doBlkDiscard          bool
104 104
 	thinpBlockSize        uint32
105 105
 	thinPoolDevice        string
106
-	Transaction           `json:"-"`
106
+	transaction           `json:"-"`
107 107
 	overrideUdevSyncCheck bool
108 108
 	deferredRemove        bool   // use deferred removal
109 109
 	BaseDeviceUUID        string //save UUID of base device
110 110
 }
111 111
 
112
+// DiskUsage contains information about disk usage and is used when reporting Status of a device.
112 113
 type DiskUsage struct {
113
-	Used      uint64
114
-	Total     uint64
114
+	// Used bytes on the disk.
115
+	Used uint64
116
+	// Total bytes on the disk.
117
+	Total uint64
118
+	// Available bytes on the disk.
115 119
 	Available uint64
116 120
 }
117 121
 
122
+// Status returns the information about the device.
118 123
 type Status struct {
119
-	PoolName              string
120
-	DataFile              string // actual block device for data
121
-	DataLoopback          string // loopback file, if used
122
-	MetadataFile          string // actual block device for metadata
123
-	MetadataLoopback      string // loopback file, if used
124
-	Data                  DiskUsage
125
-	Metadata              DiskUsage
126
-	SectorSize            uint64
127
-	UdevSyncSupported     bool
124
+	// PoolName is the name of the data pool.
125
+	PoolName string
126
+	// DataFile is the actual block device for data.
127
+	DataFile string
128
+	// DataLoopback loopback file, if used.
129
+	DataLoopback string
130
+	// MetadataFile is the actual block device for metadata.
131
+	MetadataFile string
132
+	// MetadataLoopback is the loopback file, if used.
133
+	MetadataLoopback string
134
+	// Data is the disk used for data.
135
+	Data DiskUsage
136
+	// Metadata is the disk used for meta data.
137
+	Metadata DiskUsage
138
+	// SectorSize size of the vector.
139
+	SectorSize uint64
140
+	// UdevSyncSupported is true if sync is supported.
141
+	UdevSyncSupported bool
142
+	// DeferredRemoveEnabled is true then the device is not unmounted.
128 143
 	DeferredRemoveEnabled bool
129 144
 }
130 145
 
131 146
 // Structure used to export image/container metadata in docker inspect.
132
-type DeviceMetadata struct {
133
-	deviceId   int
147
+type deviceMetadata struct {
148
+	deviceID   int
134 149
 	deviceSize uint64 // size in bytes
135 150
 	deviceName string // Device name as used during activation
136 151
 }
137 152
 
153
+// DevStatus returns information about device mounted containing its id, size and sector information.
138 154
 type DevStatus struct {
139
-	DeviceId            int
140
-	Size                uint64
141
-	TransactionId       uint64
142
-	SizeInSectors       uint64
143
-	MappedSectors       uint64
155
+	// DeviceID is the id of the device.
156
+	DeviceID int
157
+	// Size is the size of the filesystem.
158
+	Size uint64
159
+	// TransactionID is a unique integer per device set used to identify an operation on the file system, this number is incremental.
160
+	TransactionID uint64
161
+	// SizeInSectors indicates the size of the sectors allocated.
162
+	SizeInSectors uint64
163
+	// MappedSectors indicates number of mapped sectors.
164
+	MappedSectors uint64
165
+	// HighestMappedSector is the pointer to the highest mapped sector.
144 166
 	HighestMappedSector uint64
145 167
 }
146 168
 
... ...
@@ -148,7 +171,7 @@ func getDevName(name string) string {
148 148
 	return "/dev/mapper/" + name
149 149
 }
150 150
 
151
-func (info *DevInfo) Name() string {
151
+func (info *devInfo) Name() string {
152 152
 	hash := info.Hash
153 153
 	if hash == "" {
154 154
 		hash = "base"
... ...
@@ -156,7 +179,7 @@ func (info *DevInfo) Name() string {
156 156
 	return fmt.Sprintf("%s-%s", info.devices.devicePrefix, hash)
157 157
 }
158 158
 
159
-func (info *DevInfo) DevName() string {
159
+func (info *devInfo) DevName() string {
160 160
 	return getDevName(info.Name())
161 161
 }
162 162
 
... ...
@@ -168,7 +191,7 @@ func (devices *DeviceSet) metadataDir() string {
168 168
 	return path.Join(devices.root, "metadata")
169 169
 }
170 170
 
171
-func (devices *DeviceSet) metadataFile(info *DevInfo) string {
171
+func (devices *DeviceSet) metadataFile(info *devInfo) string {
172 172
 	file := info.Hash
173 173
 	if file == "" {
174 174
 		file = "base"
... ...
@@ -237,20 +260,20 @@ func (devices *DeviceSet) ensureImage(name string, size int64) (string, error) {
237 237
 	return filename, nil
238 238
 }
239 239
 
240
-func (devices *DeviceSet) allocateTransactionId() uint64 {
241
-	devices.OpenTransactionId = devices.TransactionId + 1
242
-	return devices.OpenTransactionId
240
+func (devices *DeviceSet) allocateTransactionID() uint64 {
241
+	devices.OpenTransactionID = devices.TransactionID + 1
242
+	return devices.OpenTransactionID
243 243
 }
244 244
 
245
-func (devices *DeviceSet) updatePoolTransactionId() error {
246
-	if err := devicemapper.SetTransactionId(devices.getPoolDevName(), devices.TransactionId, devices.OpenTransactionId); err != nil {
245
+func (devices *DeviceSet) updatePoolTransactionID() error {
246
+	if err := devicemapper.SetTransactionId(devices.getPoolDevName(), devices.TransactionID, devices.OpenTransactionID); err != nil {
247 247
 		return fmt.Errorf("Error setting devmapper transaction ID: %s", err)
248 248
 	}
249
-	devices.TransactionId = devices.OpenTransactionId
249
+	devices.TransactionID = devices.OpenTransactionID
250 250
 	return nil
251 251
 }
252 252
 
253
-func (devices *DeviceSet) removeMetadata(info *DevInfo) error {
253
+func (devices *DeviceSet) removeMetadata(info *devInfo) error {
254 254
 	if err := os.RemoveAll(devices.metadataFile(info)); err != nil {
255 255
 		return fmt.Errorf("Error removing metadata file %s: %s", devices.metadataFile(info), err)
256 256
 	}
... ...
@@ -284,7 +307,7 @@ func (devices *DeviceSet) writeMetaFile(jsonData []byte, filePath string) error
284 284
 	return nil
285 285
 }
286 286
 
287
-func (devices *DeviceSet) saveMetadata(info *DevInfo) error {
287
+func (devices *DeviceSet) saveMetadata(info *devInfo) error {
288 288
 	jsonData, err := json.Marshal(info)
289 289
 	if err != nil {
290 290
 		return fmt.Errorf("Error encoding metadata to json: %s", err)
... ...
@@ -295,31 +318,31 @@ func (devices *DeviceSet) saveMetadata(info *DevInfo) error {
295 295
 	return nil
296 296
 }
297 297
 
298
-func (devices *DeviceSet) markDeviceIdUsed(deviceId int) {
298
+func (devices *DeviceSet) markDeviceIDUsed(deviceID int) {
299 299
 	var mask byte
300
-	i := deviceId % 8
300
+	i := deviceID % 8
301 301
 	mask = 1 << uint(i)
302
-	devices.deviceIdMap[deviceId/8] = devices.deviceIdMap[deviceId/8] | mask
302
+	devices.deviceIDMap[deviceID/8] = devices.deviceIDMap[deviceID/8] | mask
303 303
 }
304 304
 
305
-func (devices *DeviceSet) markDeviceIdFree(deviceId int) {
305
+func (devices *DeviceSet) markDeviceIDFree(deviceID int) {
306 306
 	var mask byte
307
-	i := deviceId % 8
307
+	i := deviceID % 8
308 308
 	mask = ^(1 << uint(i))
309
-	devices.deviceIdMap[deviceId/8] = devices.deviceIdMap[deviceId/8] & mask
309
+	devices.deviceIDMap[deviceID/8] = devices.deviceIDMap[deviceID/8] & mask
310 310
 }
311 311
 
312
-func (devices *DeviceSet) isDeviceIdFree(deviceId int) bool {
312
+func (devices *DeviceSet) isDeviceIDFree(deviceID int) bool {
313 313
 	var mask byte
314
-	i := deviceId % 8
314
+	i := deviceID % 8
315 315
 	mask = (1 << uint(i))
316
-	if (devices.deviceIdMap[deviceId/8] & mask) != 0 {
316
+	if (devices.deviceIDMap[deviceID/8] & mask) != 0 {
317 317
 		return false
318 318
 	}
319 319
 	return true
320 320
 }
321 321
 
322
-func (devices *DeviceSet) lookupDevice(hash string) (*DevInfo, error) {
322
+func (devices *DeviceSet) lookupDevice(hash string) (*devInfo, error) {
323 323
 	devices.devicesLock.Lock()
324 324
 	defer devices.devicesLock.Unlock()
325 325
 	info := devices.Devices[hash]
... ...
@@ -364,22 +387,22 @@ func (devices *DeviceSet) deviceFileWalkFunction(path string, finfo os.FileInfo)
364 364
 		return fmt.Errorf("Error loading device metadata file %s", hash)
365 365
 	}
366 366
 
367
-	if dinfo.DeviceId > MaxDeviceId {
368
-		logrus.Errorf("Ignoring Invalid DeviceId=%d", dinfo.DeviceId)
367
+	if dinfo.DeviceID > maxDeviceID {
368
+		logrus.Errorf("Ignoring Invalid DeviceID=%d", dinfo.DeviceID)
369 369
 		return nil
370 370
 	}
371 371
 
372 372
 	devices.Lock()
373
-	devices.markDeviceIdUsed(dinfo.DeviceId)
373
+	devices.markDeviceIDUsed(dinfo.DeviceID)
374 374
 	devices.Unlock()
375 375
 
376
-	logrus.Debugf("Added deviceId=%d to DeviceIdMap", dinfo.DeviceId)
376
+	logrus.Debugf("Added deviceID=%d to DeviceIDMap", dinfo.DeviceID)
377 377
 	return nil
378 378
 }
379 379
 
380
-func (devices *DeviceSet) constructDeviceIdMap() error {
381
-	logrus.Debugf("[deviceset] constructDeviceIdMap()")
382
-	defer logrus.Debugf("[deviceset] constructDeviceIdMap() END")
380
+func (devices *DeviceSet) constructDeviceIDMap() error {
381
+	logrus.Debugf("[deviceset] constructDeviceIDMap()")
382
+	defer logrus.Debugf("[deviceset] constructDeviceIDMap() END")
383 383
 
384 384
 	var scan = func(path string, info os.FileInfo, err error) error {
385 385
 		if err != nil {
... ...
@@ -400,9 +423,9 @@ func (devices *DeviceSet) constructDeviceIdMap() error {
400 400
 
401 401
 func (devices *DeviceSet) unregisterDevice(id int, hash string) error {
402 402
 	logrus.Debugf("unregisterDevice(%v, %v)", id, hash)
403
-	info := &DevInfo{
403
+	info := &devInfo{
404 404
 		Hash:     hash,
405
-		DeviceId: id,
405
+		DeviceID: id,
406 406
 	}
407 407
 
408 408
 	devices.devicesLock.Lock()
... ...
@@ -417,13 +440,13 @@ func (devices *DeviceSet) unregisterDevice(id int, hash string) error {
417 417
 	return nil
418 418
 }
419 419
 
420
-func (devices *DeviceSet) registerDevice(id int, hash string, size uint64, transactionId uint64) (*DevInfo, error) {
420
+func (devices *DeviceSet) registerDevice(id int, hash string, size uint64, transactionID uint64) (*devInfo, error) {
421 421
 	logrus.Debugf("registerDevice(%v, %v)", id, hash)
422
-	info := &DevInfo{
422
+	info := &devInfo{
423 423
 		Hash:          hash,
424
-		DeviceId:      id,
424
+		DeviceID:      id,
425 425
 		Size:          size,
426
-		TransactionId: transactionId,
426
+		TransactionID: transactionID,
427 427
 		Initialized:   false,
428 428
 		devices:       devices,
429 429
 	}
... ...
@@ -443,7 +466,7 @@ func (devices *DeviceSet) registerDevice(id int, hash string, size uint64, trans
443 443
 	return info, nil
444 444
 }
445 445
 
446
-func (devices *DeviceSet) activateDeviceIfNeeded(info *DevInfo) error {
446
+func (devices *DeviceSet) activateDeviceIfNeeded(info *devInfo) error {
447 447
 	logrus.Debugf("activateDeviceIfNeeded(%v)", info.Hash)
448 448
 
449 449
 	// Make sure deferred removal on device is canceled, if one was
... ...
@@ -456,10 +479,10 @@ func (devices *DeviceSet) activateDeviceIfNeeded(info *DevInfo) error {
456 456
 		return nil
457 457
 	}
458 458
 
459
-	return devicemapper.ActivateDevice(devices.getPoolDevName(), info.Name(), info.DeviceId, info.Size)
459
+	return devicemapper.ActivateDevice(devices.getPoolDevName(), info.Name(), info.DeviceID, info.Size)
460 460
 }
461 461
 
462
-func (devices *DeviceSet) createFilesystem(info *DevInfo) error {
462
+func (devices *DeviceSet) createFilesystem(info *devInfo) error {
463 463
 	devname := info.DevName()
464 464
 
465 465
 	args := []string{}
... ...
@@ -500,7 +523,7 @@ func (devices *DeviceSet) migrateOldMetaData() error {
500 500
 	}
501 501
 
502 502
 	if jsonData != nil {
503
-		m := MetaData{Devices: make(map[string]*DevInfo)}
503
+		m := metaData{Devices: make(map[string]*devInfo)}
504 504
 
505 505
 		if err := json.Unmarshal(jsonData, &m); err != nil {
506 506
 			return err
... ...
@@ -524,14 +547,14 @@ func (devices *DeviceSet) initMetaData() error {
524 524
 		return err
525 525
 	}
526 526
 
527
-	_, transactionId, _, _, _, _, err := devices.poolStatus()
527
+	_, transactionID, _, _, _, _, err := devices.poolStatus()
528 528
 	if err != nil {
529 529
 		return err
530 530
 	}
531 531
 
532
-	devices.TransactionId = transactionId
532
+	devices.TransactionID = transactionID
533 533
 
534
-	if err := devices.constructDeviceIdMap(); err != nil {
534
+	if err := devices.constructDeviceIDMap(); err != nil {
535 535
 		return err
536 536
 	}
537 537
 
... ...
@@ -541,129 +564,129 @@ func (devices *DeviceSet) initMetaData() error {
541 541
 	return nil
542 542
 }
543 543
 
544
-func (devices *DeviceSet) incNextDeviceId() {
545
-	// Ids are 24bit, so wrap around
546
-	devices.NextDeviceId = (devices.NextDeviceId + 1) & MaxDeviceId
544
+func (devices *DeviceSet) incNextDeviceID() {
545
+	// IDs are 24bit, so wrap around
546
+	devices.NextDeviceID = (devices.NextDeviceID + 1) & maxDeviceID
547 547
 }
548 548
 
549
-func (devices *DeviceSet) getNextFreeDeviceId() (int, error) {
550
-	devices.incNextDeviceId()
551
-	for i := 0; i <= MaxDeviceId; i++ {
552
-		if devices.isDeviceIdFree(devices.NextDeviceId) {
553
-			devices.markDeviceIdUsed(devices.NextDeviceId)
554
-			return devices.NextDeviceId, nil
549
+func (devices *DeviceSet) getNextFreeDeviceID() (int, error) {
550
+	devices.incNextDeviceID()
551
+	for i := 0; i <= maxDeviceID; i++ {
552
+		if devices.isDeviceIDFree(devices.NextDeviceID) {
553
+			devices.markDeviceIDUsed(devices.NextDeviceID)
554
+			return devices.NextDeviceID, nil
555 555
 		}
556
-		devices.incNextDeviceId()
556
+		devices.incNextDeviceID()
557 557
 	}
558 558
 
559
-	return 0, fmt.Errorf("Unable to find a free device Id")
559
+	return 0, fmt.Errorf("Unable to find a free device ID")
560 560
 }
561 561
 
562
-func (devices *DeviceSet) createRegisterDevice(hash string) (*DevInfo, error) {
563
-	deviceId, err := devices.getNextFreeDeviceId()
562
+func (devices *DeviceSet) createRegisterDevice(hash string) (*devInfo, error) {
563
+	deviceID, err := devices.getNextFreeDeviceID()
564 564
 	if err != nil {
565 565
 		return nil, err
566 566
 	}
567 567
 
568
-	if err := devices.openTransaction(hash, deviceId); err != nil {
569
-		logrus.Debugf("Error opening transaction hash = %s deviceId = %d", hash, deviceId)
570
-		devices.markDeviceIdFree(deviceId)
568
+	if err := devices.openTransaction(hash, deviceID); err != nil {
569
+		logrus.Debugf("Error opening transaction hash = %s deviceID = %d", hash, deviceID)
570
+		devices.markDeviceIDFree(deviceID)
571 571
 		return nil, err
572 572
 	}
573 573
 
574 574
 	for {
575
-		if err := devicemapper.CreateDevice(devices.getPoolDevName(), deviceId); err != nil {
575
+		if err := devicemapper.CreateDevice(devices.getPoolDevName(), deviceID); err != nil {
576 576
 			if devicemapper.DeviceIdExists(err) {
577
-				// Device Id already exists. This should not
577
+				// Device ID already exists. This should not
578 578
 				// happen. Now we have a mechianism to find
579
-				// a free device Id. So something is not right.
579
+				// a free device ID. So something is not right.
580 580
 				// Give a warning and continue.
581
-				logrus.Errorf("Device Id %d exists in pool but it is supposed to be unused", deviceId)
582
-				deviceId, err = devices.getNextFreeDeviceId()
581
+				logrus.Errorf("Device ID %d exists in pool but it is supposed to be unused", deviceID)
582
+				deviceID, err = devices.getNextFreeDeviceID()
583 583
 				if err != nil {
584 584
 					return nil, err
585 585
 				}
586 586
 				// Save new device id into transaction
587
-				devices.refreshTransaction(deviceId)
587
+				devices.refreshTransaction(deviceID)
588 588
 				continue
589 589
 			}
590 590
 			logrus.Debugf("Error creating device: %s", err)
591
-			devices.markDeviceIdFree(deviceId)
591
+			devices.markDeviceIDFree(deviceID)
592 592
 			return nil, err
593 593
 		}
594 594
 		break
595 595
 	}
596 596
 
597
-	logrus.Debugf("Registering device (id %v) with FS size %v", deviceId, devices.baseFsSize)
598
-	info, err := devices.registerDevice(deviceId, hash, devices.baseFsSize, devices.OpenTransactionId)
597
+	logrus.Debugf("Registering device (id %v) with FS size %v", deviceID, devices.baseFsSize)
598
+	info, err := devices.registerDevice(deviceID, hash, devices.baseFsSize, devices.OpenTransactionID)
599 599
 	if err != nil {
600
-		_ = devicemapper.DeleteDevice(devices.getPoolDevName(), deviceId)
601
-		devices.markDeviceIdFree(deviceId)
600
+		_ = devicemapper.DeleteDevice(devices.getPoolDevName(), deviceID)
601
+		devices.markDeviceIDFree(deviceID)
602 602
 		return nil, err
603 603
 	}
604 604
 
605 605
 	if err := devices.closeTransaction(); err != nil {
606
-		devices.unregisterDevice(deviceId, hash)
607
-		devicemapper.DeleteDevice(devices.getPoolDevName(), deviceId)
608
-		devices.markDeviceIdFree(deviceId)
606
+		devices.unregisterDevice(deviceID, hash)
607
+		devicemapper.DeleteDevice(devices.getPoolDevName(), deviceID)
608
+		devices.markDeviceIDFree(deviceID)
609 609
 		return nil, err
610 610
 	}
611 611
 	return info, nil
612 612
 }
613 613
 
614
-func (devices *DeviceSet) createRegisterSnapDevice(hash string, baseInfo *DevInfo) error {
615
-	deviceId, err := devices.getNextFreeDeviceId()
614
+func (devices *DeviceSet) createRegisterSnapDevice(hash string, baseInfo *devInfo) error {
615
+	deviceID, err := devices.getNextFreeDeviceID()
616 616
 	if err != nil {
617 617
 		return err
618 618
 	}
619 619
 
620
-	if err := devices.openTransaction(hash, deviceId); err != nil {
621
-		logrus.Debugf("Error opening transaction hash = %s deviceId = %d", hash, deviceId)
622
-		devices.markDeviceIdFree(deviceId)
620
+	if err := devices.openTransaction(hash, deviceID); err != nil {
621
+		logrus.Debugf("Error opening transaction hash = %s deviceID = %d", hash, deviceID)
622
+		devices.markDeviceIDFree(deviceID)
623 623
 		return err
624 624
 	}
625 625
 
626 626
 	for {
627
-		if err := devicemapper.CreateSnapDevice(devices.getPoolDevName(), deviceId, baseInfo.Name(), baseInfo.DeviceId); err != nil {
627
+		if err := devicemapper.CreateSnapDevice(devices.getPoolDevName(), deviceID, baseInfo.Name(), baseInfo.DeviceID); err != nil {
628 628
 			if devicemapper.DeviceIdExists(err) {
629
-				// Device Id already exists. This should not
629
+				// Device ID already exists. This should not
630 630
 				// happen. Now we have a mechianism to find
631
-				// a free device Id. So something is not right.
631
+				// a free device ID. So something is not right.
632 632
 				// Give a warning and continue.
633
-				logrus.Errorf("Device Id %d exists in pool but it is supposed to be unused", deviceId)
634
-				deviceId, err = devices.getNextFreeDeviceId()
633
+				logrus.Errorf("Device ID %d exists in pool but it is supposed to be unused", deviceID)
634
+				deviceID, err = devices.getNextFreeDeviceID()
635 635
 				if err != nil {
636 636
 					return err
637 637
 				}
638 638
 				// Save new device id into transaction
639
-				devices.refreshTransaction(deviceId)
639
+				devices.refreshTransaction(deviceID)
640 640
 				continue
641 641
 			}
642 642
 			logrus.Debugf("Error creating snap device: %s", err)
643
-			devices.markDeviceIdFree(deviceId)
643
+			devices.markDeviceIDFree(deviceID)
644 644
 			return err
645 645
 		}
646 646
 		break
647 647
 	}
648 648
 
649
-	if _, err := devices.registerDevice(deviceId, hash, baseInfo.Size, devices.OpenTransactionId); err != nil {
650
-		devicemapper.DeleteDevice(devices.getPoolDevName(), deviceId)
651
-		devices.markDeviceIdFree(deviceId)
649
+	if _, err := devices.registerDevice(deviceID, hash, baseInfo.Size, devices.OpenTransactionID); err != nil {
650
+		devicemapper.DeleteDevice(devices.getPoolDevName(), deviceID)
651
+		devices.markDeviceIDFree(deviceID)
652 652
 		logrus.Debugf("Error registering device: %s", err)
653 653
 		return err
654 654
 	}
655 655
 
656 656
 	if err := devices.closeTransaction(); err != nil {
657
-		devices.unregisterDevice(deviceId, hash)
658
-		devicemapper.DeleteDevice(devices.getPoolDevName(), deviceId)
659
-		devices.markDeviceIdFree(deviceId)
657
+		devices.unregisterDevice(deviceID, hash)
658
+		devicemapper.DeleteDevice(devices.getPoolDevName(), deviceID)
659
+		devices.markDeviceIDFree(deviceID)
660 660
 		return err
661 661
 	}
662 662
 	return nil
663 663
 }
664 664
 
665
-func (devices *DeviceSet) loadMetadata(hash string) *DevInfo {
666
-	info := &DevInfo{Hash: hash, devices: devices}
665
+func (devices *DeviceSet) loadMetadata(hash string) *devInfo {
666
+	info := &devInfo{Hash: hash, devices: devices}
667 667
 
668 668
 	jsonData, err := ioutil.ReadFile(devices.metadataFile(info))
669 669
 	if err != nil {
... ...
@@ -690,7 +713,7 @@ func getDeviceUUID(device string) (string, error) {
690 690
 	return uuid, nil
691 691
 }
692 692
 
693
-func (devices *DeviceSet) verifyBaseDeviceUUID(baseInfo *DevInfo) error {
693
+func (devices *DeviceSet) verifyBaseDeviceUUID(baseInfo *devInfo) error {
694 694
 	devices.Lock()
695 695
 	defer devices.Unlock()
696 696
 
... ...
@@ -712,7 +735,7 @@ func (devices *DeviceSet) verifyBaseDeviceUUID(baseInfo *DevInfo) error {
712 712
 	return nil
713 713
 }
714 714
 
715
-func (devices *DeviceSet) saveBaseDeviceUUID(baseInfo *DevInfo) error {
715
+func (devices *DeviceSet) saveBaseDeviceUUID(baseInfo *devInfo) error {
716 716
 	devices.Lock()
717 717
 	defer devices.Unlock()
718 718
 
... ...
@@ -758,7 +781,7 @@ func (devices *DeviceSet) setupBaseImage() error {
758 758
 	}
759 759
 
760 760
 	if devices.thinPoolDevice != "" && oldInfo == nil {
761
-		_, transactionId, dataUsed, _, _, _, err := devices.poolStatus()
761
+		_, transactionID, dataUsed, _, _, _, err := devices.poolStatus()
762 762
 		if err != nil {
763 763
 			return err
764 764
 		}
... ...
@@ -766,8 +789,8 @@ func (devices *DeviceSet) setupBaseImage() error {
766 766
 			return fmt.Errorf("Unable to take ownership of thin-pool (%s) that already has used data blocks",
767 767
 				devices.thinPoolDevice)
768 768
 		}
769
-		if transactionId != 0 {
770
-			return fmt.Errorf("Unable to take ownership of thin-pool (%s) with non-zero transaction Id",
769
+		if transactionID != 0 {
770
+			return fmt.Errorf("Unable to take ownership of thin-pool (%s) with non-zero transaction ID",
771 771
 				devices.thinPoolDevice)
772 772
 		}
773 773
 	}
... ...
@@ -817,11 +840,12 @@ func setCloseOnExec(name string) {
817 817
 	}
818 818
 }
819 819
 
820
+// DMLog implements logging using DevMapperLogger interface.
820 821
 func (devices *DeviceSet) DMLog(level int, file string, line int, dmError int, message string) {
821 822
 	// By default libdm sends us all the messages including debug ones.
822 823
 	// We need to filter out messages here and figure out which one
823 824
 	// should be printed.
824
-	if level > DMLogLevel {
825
+	if level > logLevel {
825 826
 		return
826 827
 	}
827 828
 
... ...
@@ -844,6 +868,7 @@ func minor(device uint64) uint64 {
844 844
 	return (device & 0xff) | ((device >> 12) & 0xfff00)
845 845
 }
846 846
 
847
+// ResizePool increases the size of the pool.
847 848
 func (devices *DeviceSet) ResizePool(size int64) error {
848 849
 	dirname := devices.loopbackDir()
849 850
 	datafilename := path.Join(dirname, "data")
... ...
@@ -922,18 +947,18 @@ func (devices *DeviceSet) loadTransactionMetaData() error {
922 922
 		// There is no active transaction. This will be the case
923 923
 		// during upgrade.
924 924
 		if os.IsNotExist(err) {
925
-			devices.OpenTransactionId = devices.TransactionId
925
+			devices.OpenTransactionID = devices.TransactionID
926 926
 			return nil
927 927
 		}
928 928
 		return err
929 929
 	}
930 930
 
931
-	json.Unmarshal(jsonData, &devices.Transaction)
931
+	json.Unmarshal(jsonData, &devices.transaction)
932 932
 	return nil
933 933
 }
934 934
 
935 935
 func (devices *DeviceSet) saveTransactionMetaData() error {
936
-	jsonData, err := json.Marshal(&devices.Transaction)
936
+	jsonData, err := json.Marshal(&devices.transaction)
937 937
 	if err != nil {
938 938
 		return fmt.Errorf("Error encoding metadata to json: %s", err)
939 939
 	}
... ...
@@ -949,20 +974,20 @@ func (devices *DeviceSet) removeTransactionMetaData() error {
949 949
 }
950 950
 
951 951
 func (devices *DeviceSet) rollbackTransaction() error {
952
-	logrus.Debugf("Rolling back open transaction: TransactionId=%d hash=%s device_id=%d", devices.OpenTransactionId, devices.DeviceIdHash, devices.DeviceId)
952
+	logrus.Debugf("Rolling back open transaction: TransactionID=%d hash=%s device_id=%d", devices.OpenTransactionID, devices.DeviceIDHash, devices.DeviceID)
953 953
 
954 954
 	// A device id might have already been deleted before transaction
955 955
 	// closed. In that case this call will fail. Just leave a message
956 956
 	// in case of failure.
957
-	if err := devicemapper.DeleteDevice(devices.getPoolDevName(), devices.DeviceId); err != nil {
957
+	if err := devicemapper.DeleteDevice(devices.getPoolDevName(), devices.DeviceID); err != nil {
958 958
 		logrus.Errorf("Unable to delete device: %s", err)
959 959
 	}
960 960
 
961
-	dinfo := &DevInfo{Hash: devices.DeviceIdHash}
961
+	dinfo := &devInfo{Hash: devices.DeviceIDHash}
962 962
 	if err := devices.removeMetadata(dinfo); err != nil {
963 963
 		logrus.Errorf("Unable to remove metadata: %s", err)
964 964
 	} else {
965
-		devices.markDeviceIdFree(devices.DeviceId)
965
+		devices.markDeviceIDFree(devices.DeviceID)
966 966
 	}
967 967
 
968 968
 	if err := devices.removeTransactionMetaData(); err != nil {
... ...
@@ -977,26 +1002,26 @@ func (devices *DeviceSet) processPendingTransaction() error {
977 977
 		return err
978 978
 	}
979 979
 
980
-	// If there was open transaction but pool transaction Id is same
981
-	// as open transaction Id, nothing to roll back.
982
-	if devices.TransactionId == devices.OpenTransactionId {
980
+	// If there was open transaction but pool transaction ID is same
981
+	// as open transaction ID, nothing to roll back.
982
+	if devices.TransactionID == devices.OpenTransactionID {
983 983
 		return nil
984 984
 	}
985 985
 
986
-	// If open transaction Id is less than pool transaction Id, something
986
+	// If open transaction ID is less than pool transaction ID, something
987 987
 	// is wrong. Bail out.
988
-	if devices.OpenTransactionId < devices.TransactionId {
989
-		logrus.Errorf("Open Transaction id %d is less than pool transaction id %d", devices.OpenTransactionId, devices.TransactionId)
988
+	if devices.OpenTransactionID < devices.TransactionID {
989
+		logrus.Errorf("Open Transaction id %d is less than pool transaction id %d", devices.OpenTransactionID, devices.TransactionID)
990 990
 		return nil
991 991
 	}
992 992
 
993
-	// Pool transaction Id is not same as open transaction. There is
993
+	// Pool transaction ID is not same as open transaction. There is
994 994
 	// a transaction which was not completed.
995 995
 	if err := devices.rollbackTransaction(); err != nil {
996 996
 		return fmt.Errorf("Rolling back open transaction failed: %s", err)
997 997
 	}
998 998
 
999
-	devices.OpenTransactionId = devices.TransactionId
999
+	devices.OpenTransactionID = devices.TransactionID
1000 1000
 	return nil
1001 1001
 }
1002 1002
 
... ...
@@ -1023,18 +1048,18 @@ func (devices *DeviceSet) saveDeviceSetMetaData() error {
1023 1023
 	return devices.writeMetaFile(jsonData, devices.deviceSetMetaFile())
1024 1024
 }
1025 1025
 
1026
-func (devices *DeviceSet) openTransaction(hash string, DeviceId int) error {
1027
-	devices.allocateTransactionId()
1028
-	devices.DeviceIdHash = hash
1029
-	devices.DeviceId = DeviceId
1026
+func (devices *DeviceSet) openTransaction(hash string, DeviceID int) error {
1027
+	devices.allocateTransactionID()
1028
+	devices.DeviceIDHash = hash
1029
+	devices.DeviceID = DeviceID
1030 1030
 	if err := devices.saveTransactionMetaData(); err != nil {
1031 1031
 		return fmt.Errorf("Error saving transaction metadata: %s", err)
1032 1032
 	}
1033 1033
 	return nil
1034 1034
 }
1035 1035
 
1036
-func (devices *DeviceSet) refreshTransaction(DeviceId int) error {
1037
-	devices.DeviceId = DeviceId
1036
+func (devices *DeviceSet) refreshTransaction(DeviceID int) error {
1037
+	devices.DeviceID = DeviceID
1038 1038
 	if err := devices.saveTransactionMetaData(); err != nil {
1039 1039
 		return fmt.Errorf("Error saving transaction metadata: %s", err)
1040 1040
 	}
... ...
@@ -1042,7 +1067,7 @@ func (devices *DeviceSet) refreshTransaction(DeviceId int) error {
1042 1042
 }
1043 1043
 
1044 1044
 func (devices *DeviceSet) closeTransaction() error {
1045
-	if err := devices.updatePoolTransactionId(); err != nil {
1045
+	if err := devices.updatePoolTransactionID(); err != nil {
1046 1046
 		logrus.Debugf("Failed to close Transaction")
1047 1047
 		return err
1048 1048
 	}
... ...
@@ -1064,7 +1089,7 @@ func determineDriverCapabilities(version string) error {
1064 1064
 	}
1065 1065
 
1066 1066
 	if major > 4 {
1067
-		DriverDeferredRemovalSupport = true
1067
+		driverDeferredRemovalSupport = true
1068 1068
 		return nil
1069 1069
 	}
1070 1070
 
... ...
@@ -1082,7 +1107,7 @@ func determineDriverCapabilities(version string) error {
1082 1082
 	 * check for patch level as it can not be less than 0.
1083 1083
 	 */
1084 1084
 	if minor >= 27 {
1085
-		DriverDeferredRemovalSupport = true
1085
+		driverDeferredRemovalSupport = true
1086 1086
 		return nil
1087 1087
 	}
1088 1088
 
... ...
@@ -1225,7 +1250,7 @@ func (devices *DeviceSet) initDevmapper(doInit bool) error {
1225 1225
 
1226 1226
 	// If user asked for deferred removal and both library and driver
1227 1227
 	// supports deferred removal use it.
1228
-	if EnableDeferredRemoval && DriverDeferredRemovalSupport && devicemapper.LibraryDeferredRemovalSupport == true {
1228
+	if enableDeferredRemoval && driverDeferredRemovalSupport && devicemapper.LibraryDeferredRemovalSupport == true {
1229 1229
 		logrus.Debugf("devmapper: Deferred removal support enabled.")
1230 1230
 		devices.deferredRemove = true
1231 1231
 	}
... ...
@@ -1372,7 +1397,7 @@ func (devices *DeviceSet) initDevmapper(doInit bool) error {
1372 1372
 		}
1373 1373
 	}
1374 1374
 
1375
-	// Right now this loads only NextDeviceId. If there is more metadata
1375
+	// Right now this loads only NextDeviceID. If there is more metadata
1376 1376
 	// down the line, we might have to move it earlier.
1377 1377
 	if err := devices.loadDeviceSetMetaData(); err != nil {
1378 1378
 		return err
... ...
@@ -1389,6 +1414,7 @@ func (devices *DeviceSet) initDevmapper(doInit bool) error {
1389 1389
 	return nil
1390 1390
 }
1391 1391
 
1392
+// AddDevice adds a device and registers in the hash.
1392 1393
 func (devices *DeviceSet) AddDevice(hash, baseHash string) error {
1393 1394
 	logrus.Debugf("[deviceset] AddDevice(hash=%s basehash=%s)", hash, baseHash)
1394 1395
 	defer logrus.Debugf("[deviceset] AddDevice(hash=%s basehash=%s) END", hash, baseHash)
... ...
@@ -1415,7 +1441,7 @@ func (devices *DeviceSet) AddDevice(hash, baseHash string) error {
1415 1415
 	return nil
1416 1416
 }
1417 1417
 
1418
-func (devices *DeviceSet) deleteDevice(info *DevInfo) error {
1418
+func (devices *DeviceSet) deleteDevice(info *devInfo) error {
1419 1419
 	if devices.doBlkDiscard {
1420 1420
 		// This is a workaround for the kernel not discarding block so
1421 1421
 		// on the thin pool when we remove a thinp device, so we do it
... ...
@@ -1435,17 +1461,17 @@ func (devices *DeviceSet) deleteDevice(info *DevInfo) error {
1435 1435
 		}
1436 1436
 	}
1437 1437
 
1438
-	if err := devices.openTransaction(info.Hash, info.DeviceId); err != nil {
1439
-		logrus.Debugf("Error opening transaction hash = %s deviceId = %d", "", info.DeviceId)
1438
+	if err := devices.openTransaction(info.Hash, info.DeviceID); err != nil {
1439
+		logrus.Debugf("Error opening transaction hash = %s deviceID = %d", "", info.DeviceID)
1440 1440
 		return err
1441 1441
 	}
1442 1442
 
1443
-	if err := devicemapper.DeleteDevice(devices.getPoolDevName(), info.DeviceId); err != nil {
1443
+	if err := devicemapper.DeleteDevice(devices.getPoolDevName(), info.DeviceID); err != nil {
1444 1444
 		logrus.Debugf("Error deleting device: %s", err)
1445 1445
 		return err
1446 1446
 	}
1447 1447
 
1448
-	if err := devices.unregisterDevice(info.DeviceId, info.Hash); err != nil {
1448
+	if err := devices.unregisterDevice(info.DeviceID, info.Hash); err != nil {
1449 1449
 		return err
1450 1450
 	}
1451 1451
 
... ...
@@ -1453,11 +1479,12 @@ func (devices *DeviceSet) deleteDevice(info *DevInfo) error {
1453 1453
 		return err
1454 1454
 	}
1455 1455
 
1456
-	devices.markDeviceIdFree(info.DeviceId)
1456
+	devices.markDeviceIDFree(info.DeviceID)
1457 1457
 
1458 1458
 	return nil
1459 1459
 }
1460 1460
 
1461
+// DeleteDevice deletes a device from the hash.
1461 1462
 func (devices *DeviceSet) DeleteDevice(hash string) error {
1462 1463
 	info, err := devices.lookupDevice(hash)
1463 1464
 	if err != nil {
... ...
@@ -1493,7 +1520,7 @@ func (devices *DeviceSet) deactivatePool() error {
1493 1493
 	return nil
1494 1494
 }
1495 1495
 
1496
-func (devices *DeviceSet) deactivateDevice(info *DevInfo) error {
1496
+func (devices *DeviceSet) deactivateDevice(info *devInfo) error {
1497 1497
 	logrus.Debugf("[devmapper] deactivateDevice(%s)", info.Hash)
1498 1498
 	defer logrus.Debugf("[devmapper] deactivateDevice END(%s)", info.Hash)
1499 1499
 
... ...
@@ -1544,7 +1571,7 @@ func (devices *DeviceSet) removeDevice(devname string) error {
1544 1544
 	return err
1545 1545
 }
1546 1546
 
1547
-func (devices *DeviceSet) cancelDeferredRemoval(info *DevInfo) error {
1547
+func (devices *DeviceSet) cancelDeferredRemoval(info *devInfo) error {
1548 1548
 	if !devices.deferredRemove {
1549 1549
 		return nil
1550 1550
 	}
... ...
@@ -1583,12 +1610,13 @@ func (devices *DeviceSet) cancelDeferredRemoval(info *DevInfo) error {
1583 1583
 	return err
1584 1584
 }
1585 1585
 
1586
+// Shutdown shuts down the device by unmounting the root.
1586 1587
 func (devices *DeviceSet) Shutdown() error {
1587 1588
 	logrus.Debugf("[deviceset %s] Shutdown()", devices.devicePrefix)
1588 1589
 	logrus.Debugf("[devmapper] Shutting down DeviceSet: %s", devices.root)
1589 1590
 	defer logrus.Debugf("[deviceset %s] Shutdown() END", devices.devicePrefix)
1590 1591
 
1591
-	var devs []*DevInfo
1592
+	var devs []*devInfo
1592 1593
 
1593 1594
 	devices.devicesLock.Lock()
1594 1595
 	for _, info := range devices.Devices {
... ...
@@ -1639,6 +1667,7 @@ func (devices *DeviceSet) Shutdown() error {
1639 1639
 	return nil
1640 1640
 }
1641 1641
 
1642
+// MountDevice mounts the device if not already mounted.
1642 1643
 func (devices *DeviceSet) MountDevice(hash, path, mountLabel string) error {
1643 1644
 	info, err := devices.lookupDevice(hash)
1644 1645
 	if err != nil {
... ...
@@ -1664,8 +1693,6 @@ func (devices *DeviceSet) MountDevice(hash, path, mountLabel string) error {
1664 1664
 		return fmt.Errorf("Error activating devmapper device for '%s': %s", hash, err)
1665 1665
 	}
1666 1666
 
1667
-	var flags uintptr = syscall.MS_MGC_VAL
1668
-
1669 1667
 	fstype, err := ProbeFsType(info.DevName())
1670 1668
 	if err != nil {
1671 1669
 		return err
... ...
@@ -1681,7 +1708,7 @@ func (devices *DeviceSet) MountDevice(hash, path, mountLabel string) error {
1681 1681
 	options = joinMountOptions(options, devices.mountOptions)
1682 1682
 	options = joinMountOptions(options, label.FormatMountLabel("", mountLabel))
1683 1683
 
1684
-	if err := syscall.Mount(info.DevName(), path, fstype, flags, options); err != nil {
1684
+	if err := syscall.Mount(info.DevName(), path, fstype, syscall.MS_MGC_VAL, options); err != nil {
1685 1685
 		return fmt.Errorf("Error mounting '%s' on '%s': %s", info.DevName(), path, err)
1686 1686
 	}
1687 1687
 
... ...
@@ -1691,6 +1718,7 @@ func (devices *DeviceSet) MountDevice(hash, path, mountLabel string) error {
1691 1691
 	return nil
1692 1692
 }
1693 1693
 
1694
+// UnmountDevice unmounts the device and removes it from hash.
1694 1695
 func (devices *DeviceSet) UnmountDevice(hash string) error {
1695 1696
 	logrus.Debugf("[devmapper] UnmountDevice(hash=%s)", hash)
1696 1697
 	defer logrus.Debugf("[devmapper] UnmountDevice(hash=%s) END", hash)
... ...
@@ -1730,6 +1758,7 @@ func (devices *DeviceSet) UnmountDevice(hash string) error {
1730 1730
 	return nil
1731 1731
 }
1732 1732
 
1733
+// HasDevice returns true if the device is in the hash and mounted.
1733 1734
 func (devices *DeviceSet) HasDevice(hash string) bool {
1734 1735
 	devices.Lock()
1735 1736
 	defer devices.Unlock()
... ...
@@ -1738,6 +1767,7 @@ func (devices *DeviceSet) HasDevice(hash string) bool {
1738 1738
 	return info != nil
1739 1739
 }
1740 1740
 
1741
+// HasActivatedDevice return true if the device exists.
1741 1742
 func (devices *DeviceSet) HasActivatedDevice(hash string) bool {
1742 1743
 	info, _ := devices.lookupDevice(hash)
1743 1744
 	if info == nil {
... ...
@@ -1754,6 +1784,7 @@ func (devices *DeviceSet) HasActivatedDevice(hash string) bool {
1754 1754
 	return devinfo != nil && devinfo.Exists != 0
1755 1755
 }
1756 1756
 
1757
+// List returns a list of device ids.
1757 1758
 func (devices *DeviceSet) List() []string {
1758 1759
 	devices.Lock()
1759 1760
 	defer devices.Unlock()
... ...
@@ -1782,6 +1813,7 @@ func (devices *DeviceSet) deviceStatus(devName string) (sizeInSectors, mappedSec
1782 1782
 	return
1783 1783
 }
1784 1784
 
1785
+// GetDeviceStatus provides size, mapped sectors
1785 1786
 func (devices *DeviceSet) GetDeviceStatus(hash string) (*DevStatus, error) {
1786 1787
 	info, err := devices.lookupDevice(hash)
1787 1788
 	if err != nil {
... ...
@@ -1795,9 +1827,9 @@ func (devices *DeviceSet) GetDeviceStatus(hash string) (*DevStatus, error) {
1795 1795
 	defer devices.Unlock()
1796 1796
 
1797 1797
 	status := &DevStatus{
1798
-		DeviceId:      info.DeviceId,
1798
+		DeviceID:      info.DeviceID,
1799 1799
 		Size:          info.Size,
1800
-		TransactionId: info.TransactionId,
1800
+		TransactionID: info.TransactionID,
1801 1801
 	}
1802 1802
 
1803 1803
 	if err := devices.activateDeviceIfNeeded(info); err != nil {
... ...
@@ -1817,10 +1849,10 @@ func (devices *DeviceSet) GetDeviceStatus(hash string) (*DevStatus, error) {
1817 1817
 	return status, nil
1818 1818
 }
1819 1819
 
1820
-func (devices *DeviceSet) poolStatus() (totalSizeInSectors, transactionId, dataUsed, dataTotal, metadataUsed, metadataTotal uint64, err error) {
1820
+func (devices *DeviceSet) poolStatus() (totalSizeInSectors, transactionID, dataUsed, dataTotal, metadataUsed, metadataTotal uint64, err error) {
1821 1821
 	var params string
1822 1822
 	if _, totalSizeInSectors, _, params, err = devicemapper.GetStatus(devices.getPoolName()); err == nil {
1823
-		_, err = fmt.Sscanf(params, "%d %d/%d %d/%d", &transactionId, &metadataUsed, &metadataTotal, &dataUsed, &dataTotal)
1823
+		_, err = fmt.Sscanf(params, "%d %d/%d %d/%d", &transactionID, &metadataUsed, &metadataTotal, &dataUsed, &dataTotal)
1824 1824
 	}
1825 1825
 	return
1826 1826
 }
... ...
@@ -1908,7 +1940,7 @@ func (devices *DeviceSet) Status() *Status {
1908 1908
 }
1909 1909
 
1910 1910
 // Status returns the current status of this deviceset
1911
-func (devices *DeviceSet) ExportDeviceMetadata(hash string) (*DeviceMetadata, error) {
1911
+func (devices *DeviceSet) exportDeviceMetadata(hash string) (*deviceMetadata, error) {
1912 1912
 	info, err := devices.lookupDevice(hash)
1913 1913
 	if err != nil {
1914 1914
 		return nil, err
... ...
@@ -1917,24 +1949,25 @@ func (devices *DeviceSet) ExportDeviceMetadata(hash string) (*DeviceMetadata, er
1917 1917
 	info.lock.Lock()
1918 1918
 	defer info.lock.Unlock()
1919 1919
 
1920
-	metadata := &DeviceMetadata{info.DeviceId, info.Size, info.Name()}
1920
+	metadata := &deviceMetadata{info.DeviceID, info.Size, info.Name()}
1921 1921
 	return metadata, nil
1922 1922
 }
1923 1923
 
1924
+// NewDeviceSet creates the device set based on the options provided.
1924 1925
 func NewDeviceSet(root string, doInit bool, options []string) (*DeviceSet, error) {
1925 1926
 	devicemapper.SetDevDir("/dev")
1926 1927
 
1927 1928
 	devices := &DeviceSet{
1928 1929
 		root:                  root,
1929
-		MetaData:              MetaData{Devices: make(map[string]*DevInfo)},
1930
-		dataLoopbackSize:      DefaultDataLoopbackSize,
1931
-		metaDataLoopbackSize:  DefaultMetaDataLoopbackSize,
1932
-		baseFsSize:            DefaultBaseFsSize,
1933
-		overrideUdevSyncCheck: DefaultUdevSyncOverride,
1930
+		metaData:              metaData{Devices: make(map[string]*devInfo)},
1931
+		dataLoopbackSize:      defaultDataLoopbackSize,
1932
+		metaDataLoopbackSize:  defaultMetaDataLoopbackSize,
1933
+		baseFsSize:            defaultBaseFsSize,
1934
+		overrideUdevSyncCheck: defaultUdevSyncOverride,
1934 1935
 		filesystem:            "ext4",
1935 1936
 		doBlkDiscard:          true,
1936
-		thinpBlockSize:        DefaultThinpBlockSize,
1937
-		deviceIdMap:           make([]byte, DeviceIdMapSz),
1937
+		thinpBlockSize:        defaultThinpBlockSize,
1938
+		deviceIDMap:           make([]byte, deviceIDMapSz),
1938 1939
 	}
1939 1940
 
1940 1941
 	foundBlkDiscard := false
... ...
@@ -1998,7 +2031,7 @@ func NewDeviceSet(root string, doInit bool, options []string) (*DeviceSet, error
1998 1998
 			}
1999 1999
 
2000 2000
 		case "dm.use_deferred_removal":
2001
-			EnableDeferredRemoval, err = strconv.ParseBool(val)
2001
+			enableDeferredRemoval, err = strconv.ParseBool(val)
2002 2002
 			if err != nil {
2003 2003
 				return nil, err
2004 2004
 			}
... ...
@@ -10,10 +10,10 @@ import (
10 10
 
11 11
 func init() {
12 12
 	// Reduce the size the the base fs and loopback for the tests
13
-	DefaultDataLoopbackSize = 300 * 1024 * 1024
14
-	DefaultMetaDataLoopbackSize = 200 * 1024 * 1024
15
-	DefaultBaseFsSize = 300 * 1024 * 1024
16
-	DefaultUdevSyncOverride = true
13
+	defaultDataLoopbackSize = 300 * 1024 * 1024
14
+	defaultMetaDataLoopbackSize = 200 * 1024 * 1024
15
+	defaultBaseFsSize = 300 * 1024 * 1024
16
+	defaultUdevSyncOverride = true
17 17
 	if err := graphtest.InitLoopbacks(); err != nil {
18 18
 		panic(err)
19 19
 	}
... ...
@@ -25,6 +25,7 @@ func init() {
25 25
 
26 26
 // End of placeholder interfaces.
27 27
 
28
+// Driver contains the device set mounted and the home directory
28 29
 type Driver struct {
29 30
 	*DeviceSet
30 31
 	home string
... ...
@@ -32,6 +33,7 @@ type Driver struct {
32 32
 
33 33
 var backingFs = "<unknown>"
34 34
 
35
+// Init creates a driver with the given home and the set of options.
35 36
 func Init(home string, options []string) (graphdriver.Driver, error) {
36 37
 	fsMagic, err := graphdriver.GetFSMagic(home)
37 38
 	if err != nil {
... ...
@@ -62,6 +64,9 @@ func (d *Driver) String() string {
62 62
 	return "devicemapper"
63 63
 }
64 64
 
65
+// Status returns the status about the driver in a printable format.
66
+// Information returned contains Pool Name, Data File, Metadata file, disk usage by
67
+// the data and metadata, etc.
65 68
 func (d *Driver) Status() [][2]string {
66 69
 	s := d.DeviceSet.Status()
67 70
 
... ...
@@ -92,20 +97,22 @@ func (d *Driver) Status() [][2]string {
92 92
 	return status
93 93
 }
94 94
 
95
+// GetMetadata returns a map of information about the device.
95 96
 func (d *Driver) GetMetadata(id string) (map[string]string, error) {
96
-	m, err := d.DeviceSet.ExportDeviceMetadata(id)
97
+	m, err := d.DeviceSet.exportDeviceMetadata(id)
97 98
 
98 99
 	if err != nil {
99 100
 		return nil, err
100 101
 	}
101 102
 
102 103
 	metadata := make(map[string]string)
103
-	metadata["DeviceId"] = strconv.Itoa(m.deviceId)
104
+	metadata["DeviceId"] = strconv.Itoa(m.deviceID)
104 105
 	metadata["DeviceSize"] = strconv.FormatUint(m.deviceSize, 10)
105 106
 	metadata["DeviceName"] = m.deviceName
106 107
 	return metadata, nil
107 108
 }
108 109
 
110
+// Cleanup unmounts a device.
109 111
 func (d *Driver) Cleanup() error {
110 112
 	err := d.DeviceSet.Shutdown()
111 113
 
... ...
@@ -116,6 +123,7 @@ func (d *Driver) Cleanup() error {
116 116
 	return err
117 117
 }
118 118
 
119
+// Create adds a device with a given id and the parent.
119 120
 func (d *Driver) Create(id, parent string) error {
120 121
 	if err := d.DeviceSet.AddDevice(id, parent); err != nil {
121 122
 		return err
... ...
@@ -124,6 +132,7 @@ func (d *Driver) Create(id, parent string) error {
124 124
 	return nil
125 125
 }
126 126
 
127
+// Remove removes a device with a given id, unmounts the filesystem.
127 128
 func (d *Driver) Remove(id string) error {
128 129
 	if !d.DeviceSet.HasDevice(id) {
129 130
 		// Consider removing a non-existing device a no-op
... ...
@@ -145,6 +154,7 @@ func (d *Driver) Remove(id string) error {
145 145
 	return nil
146 146
 }
147 147
 
148
+// Get mounts a device with given id into the root filesystem
148 149
 func (d *Driver) Get(id, mountLabel string) (string, error) {
149 150
 	mp := path.Join(d.home, "mnt", id)
150 151
 
... ...
@@ -177,6 +187,7 @@ func (d *Driver) Get(id, mountLabel string) (string, error) {
177 177
 	return rootFs, nil
178 178
 }
179 179
 
180
+// Put unmounts a device and removes it.
180 181
 func (d *Driver) Put(id string) error {
181 182
 	err := d.DeviceSet.UnmountDevice(id)
182 183
 	if err != nil {
... ...
@@ -185,6 +196,7 @@ func (d *Driver) Put(id string) error {
185 185
 	return err
186 186
 }
187 187
 
188
+// Exists checks to see if the device is mounted.
188 189
 func (d *Driver) Exists(id string) bool {
189 190
 	return d.DeviceSet.HasDevice(id)
190 191
 }
... ...
@@ -13,6 +13,7 @@ import (
13 13
 // FIXME: this is copy-pasted from the aufs driver.
14 14
 // It should be moved into the core.
15 15
 
16
+// Mounted returns true if a mount point exists.
16 17
 func Mounted(mountpoint string) (bool, error) {
17 18
 	mntpoint, err := os.Stat(mountpoint)
18 19
 	if err != nil {
... ...
@@ -36,6 +37,7 @@ type probeData struct {
36 36
 	offset uint64
37 37
 }
38 38
 
39
+// ProbeFsType returns the filesystem name for the given device id.
39 40
 func ProbeFsType(device string) (string, error) {
40 41
 	probes := []probeData{
41 42
 		{"btrfs", "_BHRfS_M", 0x10040},
... ...
@@ -19,6 +19,7 @@ packages=(
19 19
 	daemon/execdriver/native
20 20
 	daemon/execdriver/native/template
21 21
 	daemon/graphdriver/aufs
22
+	daemon/graphdriver/devmapper
22 23
 	daemon/network
23 24
 	docker
24 25
 	dockerinit