Browse code

devmapper: show device and loop file , if used

Presenly the "Data file:" shows either the loopback _file_ or the block device.
With this, the "Data file:" will always show the device, and if it is a
loopback, then there will additionally be a "Data loop file:".
(Same for "Metadata file:")

Signed-off-by: Vincent Batts <vbatts@redhat.com>

Vincent Batts authored on 2015/01/10 01:20:07
Showing 2 changed files
... ...
@@ -89,8 +89,10 @@ type DeviceSet struct {
89 89
 	filesystem           string
90 90
 	mountOptions         string
91 91
 	mkfsArgs             []string
92
-	dataDevice           string
93
-	metadataDevice       string
92
+	dataDevice           string // block or loop dev
93
+	dataLoopFile         string // loopback file, if used
94
+	metadataDevice       string // block or loop dev
95
+	metadataLoopFile     string // loopback file, if used
94 96
 	doBlkDiscard         bool
95 97
 	thinpBlockSize       uint32
96 98
 	thinPoolDevice       string
... ...
@@ -104,8 +106,10 @@ type DiskUsage struct {
104 104
 
105 105
 type Status struct {
106 106
 	PoolName         string
107
-	DataLoopback     string
108
-	MetadataLoopback string
107
+	DataFile         string // actual block device for data
108
+	DataLoopback     string // loopback file, if used
109
+	MetadataFile     string // actual block device for metadata
110
+	MetadataLoopback string // loopback file, if used
109 111
 	Data             DiskUsage
110 112
 	Metadata         DiskUsage
111 113
 	SectorSize       uint64
... ...
@@ -1013,6 +1017,8 @@ func (devices *DeviceSet) initDevmapper(doInit bool) error {
1013 1013
 			if err != nil {
1014 1014
 				return err
1015 1015
 			}
1016
+			devices.dataLoopFile = data
1017
+			devices.dataDevice = dataFile.Name()
1016 1018
 		} else {
1017 1019
 			dataFile, err = os.OpenFile(devices.dataDevice, os.O_RDWR, 0600)
1018 1020
 			if err != nil {
... ...
@@ -1044,6 +1050,8 @@ func (devices *DeviceSet) initDevmapper(doInit bool) error {
1044 1044
 			if err != nil {
1045 1045
 				return err
1046 1046
 			}
1047
+			devices.metadataLoopFile = metadata
1048
+			devices.metadataDevice = metadataFile.Name()
1047 1049
 		} else {
1048 1050
 			metadataFile, err = os.OpenFile(devices.metadataDevice, os.O_RDWR, 0600)
1049 1051
 			if err != nil {
... ...
@@ -1540,6 +1548,19 @@ func (devices *DeviceSet) poolStatus() (totalSizeInSectors, transactionId, dataU
1540 1540
 	return
1541 1541
 }
1542 1542
 
1543
+// MetadataDevicePath returns the path to the metadata storage for this deviceset,
1544
+// regardless of loopback or block device
1545
+func (devices DeviceSet) DataDevicePath() string {
1546
+	return devices.dataDevice
1547
+}
1548
+
1549
+// MetadataDevicePath returns the path to the metadata storage for this deviceset,
1550
+// regardless of loopback or block device
1551
+func (devices DeviceSet) MetadataDevicePath() string {
1552
+	return devices.metadataDevice
1553
+}
1554
+
1555
+// Status returns the current status of this deviceset
1543 1556
 func (devices *DeviceSet) Status() *Status {
1544 1557
 	devices.Lock()
1545 1558
 	defer devices.Unlock()
... ...
@@ -1547,16 +1568,10 @@ func (devices *DeviceSet) Status() *Status {
1547 1547
 	status := &Status{}
1548 1548
 
1549 1549
 	status.PoolName = devices.getPoolName()
1550
-	if len(devices.dataDevice) > 0 {
1551
-		status.DataLoopback = devices.dataDevice
1552
-	} else {
1553
-		status.DataLoopback = path.Join(devices.loopbackDir(), "data")
1554
-	}
1555
-	if len(devices.metadataDevice) > 0 {
1556
-		status.MetadataLoopback = devices.metadataDevice
1557
-	} else {
1558
-		status.MetadataLoopback = path.Join(devices.loopbackDir(), "metadata")
1559
-	}
1550
+	status.DataFile = devices.DataDevicePath()
1551
+	status.DataLoopback = devices.dataLoopFile
1552
+	status.MetadataFile = devices.MetadataDevicePath()
1553
+	status.MetadataLoopback = devices.metadataLoopFile
1560 1554
 
1561 1555
 	totalSizeInSectors, _, dataUsed, dataTotal, metadataUsed, metadataTotal, err := devices.poolStatus()
1562 1556
 	if err == nil {
... ...
@@ -57,13 +57,19 @@ func (d *Driver) Status() [][2]string {
57 57
 	status := [][2]string{
58 58
 		{"Pool Name", s.PoolName},
59 59
 		{"Pool Blocksize", fmt.Sprintf("%s", units.HumanSize(float64(s.SectorSize)))},
60
-		{"Data file", s.DataLoopback},
61
-		{"Metadata file", s.MetadataLoopback},
60
+		{"Data file", s.DataFile},
61
+		{"Metadata file", s.MetadataFile},
62 62
 		{"Data Space Used", fmt.Sprintf("%s", units.HumanSize(float64(s.Data.Used)))},
63 63
 		{"Data Space Total", fmt.Sprintf("%s", units.HumanSize(float64(s.Data.Total)))},
64 64
 		{"Metadata Space Used", fmt.Sprintf("%s", units.HumanSize(float64(s.Metadata.Used)))},
65 65
 		{"Metadata Space Total", fmt.Sprintf("%s", units.HumanSize(float64(s.Metadata.Total)))},
66 66
 	}
67
+	if len(s.DataLoopback) > 0 {
68
+		status = append(status, [2]string{"Data loop file", s.DataLoopback})
69
+	}
70
+	if len(s.MetadataLoopback) > 0 {
71
+		status = append(status, [2]string{"Metadata loop file", s.MetadataLoopback})
72
+	}
67 73
 	if vStr, err := devicemapper.GetLibraryVersion(); err == nil {
68 74
 		status = append(status, [2]string{"Library Version", vStr})
69 75
 	}