Explorar o código

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 %!s(int64=10) %!d(string=hai) anos
pai
achega
09c033ff87

+ 29 - 14
daemon/graphdriver/devmapper/deviceset.go

@@ -89,8 +89,10 @@ type DeviceSet struct {
 	filesystem           string
 	filesystem           string
 	mountOptions         string
 	mountOptions         string
 	mkfsArgs             []string
 	mkfsArgs             []string
-	dataDevice           string
-	metadataDevice       string
+	dataDevice           string // block or loop dev
+	dataLoopFile         string // loopback file, if used
+	metadataDevice       string // block or loop dev
+	metadataLoopFile     string // loopback file, if used
 	doBlkDiscard         bool
 	doBlkDiscard         bool
 	thinpBlockSize       uint32
 	thinpBlockSize       uint32
 	thinPoolDevice       string
 	thinPoolDevice       string
@@ -104,8 +106,10 @@ type DiskUsage struct {
 
 
 type Status struct {
 type Status struct {
 	PoolName         string
 	PoolName         string
-	DataLoopback     string
-	MetadataLoopback string
+	DataFile         string // actual block device for data
+	DataLoopback     string // loopback file, if used
+	MetadataFile     string // actual block device for metadata
+	MetadataLoopback string // loopback file, if used
 	Data             DiskUsage
 	Data             DiskUsage
 	Metadata         DiskUsage
 	Metadata         DiskUsage
 	SectorSize       uint64
 	SectorSize       uint64
@@ -1013,6 +1017,8 @@ func (devices *DeviceSet) initDevmapper(doInit bool) error {
 			if err != nil {
 			if err != nil {
 				return err
 				return err
 			}
 			}
+			devices.dataLoopFile = data
+			devices.dataDevice = dataFile.Name()
 		} else {
 		} else {
 			dataFile, err = os.OpenFile(devices.dataDevice, os.O_RDWR, 0600)
 			dataFile, err = os.OpenFile(devices.dataDevice, os.O_RDWR, 0600)
 			if err != nil {
 			if err != nil {
@@ -1044,6 +1050,8 @@ func (devices *DeviceSet) initDevmapper(doInit bool) error {
 			if err != nil {
 			if err != nil {
 				return err
 				return err
 			}
 			}
+			devices.metadataLoopFile = metadata
+			devices.metadataDevice = metadataFile.Name()
 		} else {
 		} else {
 			metadataFile, err = os.OpenFile(devices.metadataDevice, os.O_RDWR, 0600)
 			metadataFile, err = os.OpenFile(devices.metadataDevice, os.O_RDWR, 0600)
 			if err != nil {
 			if err != nil {
@@ -1540,6 +1548,19 @@ func (devices *DeviceSet) poolStatus() (totalSizeInSectors, transactionId, dataU
 	return
 	return
 }
 }
 
 
+// MetadataDevicePath returns the path to the metadata storage for this deviceset,
+// regardless of loopback or block device
+func (devices DeviceSet) DataDevicePath() string {
+	return devices.dataDevice
+}
+
+// MetadataDevicePath returns the path to the metadata storage for this deviceset,
+// regardless of loopback or block device
+func (devices DeviceSet) MetadataDevicePath() string {
+	return devices.metadataDevice
+}
+
+// Status returns the current status of this deviceset
 func (devices *DeviceSet) Status() *Status {
 func (devices *DeviceSet) Status() *Status {
 	devices.Lock()
 	devices.Lock()
 	defer devices.Unlock()
 	defer devices.Unlock()
@@ -1547,16 +1568,10 @@ func (devices *DeviceSet) Status() *Status {
 	status := &Status{}
 	status := &Status{}
 
 
 	status.PoolName = devices.getPoolName()
 	status.PoolName = devices.getPoolName()
-	if len(devices.dataDevice) > 0 {
-		status.DataLoopback = devices.dataDevice
-	} else {
-		status.DataLoopback = path.Join(devices.loopbackDir(), "data")
-	}
-	if len(devices.metadataDevice) > 0 {
-		status.MetadataLoopback = devices.metadataDevice
-	} else {
-		status.MetadataLoopback = path.Join(devices.loopbackDir(), "metadata")
-	}
+	status.DataFile = devices.DataDevicePath()
+	status.DataLoopback = devices.dataLoopFile
+	status.MetadataFile = devices.MetadataDevicePath()
+	status.MetadataLoopback = devices.metadataLoopFile
 
 
 	totalSizeInSectors, _, dataUsed, dataTotal, metadataUsed, metadataTotal, err := devices.poolStatus()
 	totalSizeInSectors, _, dataUsed, dataTotal, metadataUsed, metadataTotal, err := devices.poolStatus()
 	if err == nil {
 	if err == nil {

+ 8 - 2
daemon/graphdriver/devmapper/driver.go

@@ -57,13 +57,19 @@ func (d *Driver) Status() [][2]string {
 	status := [][2]string{
 	status := [][2]string{
 		{"Pool Name", s.PoolName},
 		{"Pool Name", s.PoolName},
 		{"Pool Blocksize", fmt.Sprintf("%s", units.HumanSize(float64(s.SectorSize)))},
 		{"Pool Blocksize", fmt.Sprintf("%s", units.HumanSize(float64(s.SectorSize)))},
-		{"Data file", s.DataLoopback},
-		{"Metadata file", s.MetadataLoopback},
+		{"Data file", s.DataFile},
+		{"Metadata file", s.MetadataFile},
 		{"Data Space Used", fmt.Sprintf("%s", units.HumanSize(float64(s.Data.Used)))},
 		{"Data Space Used", fmt.Sprintf("%s", units.HumanSize(float64(s.Data.Used)))},
 		{"Data Space Total", fmt.Sprintf("%s", units.HumanSize(float64(s.Data.Total)))},
 		{"Data Space Total", fmt.Sprintf("%s", units.HumanSize(float64(s.Data.Total)))},
 		{"Metadata Space Used", fmt.Sprintf("%s", units.HumanSize(float64(s.Metadata.Used)))},
 		{"Metadata Space Used", fmt.Sprintf("%s", units.HumanSize(float64(s.Metadata.Used)))},
 		{"Metadata Space Total", fmt.Sprintf("%s", units.HumanSize(float64(s.Metadata.Total)))},
 		{"Metadata Space Total", fmt.Sprintf("%s", units.HumanSize(float64(s.Metadata.Total)))},
 	}
 	}
+	if len(s.DataLoopback) > 0 {
+		status = append(status, [2]string{"Data loop file", s.DataLoopback})
+	}
+	if len(s.MetadataLoopback) > 0 {
+		status = append(status, [2]string{"Metadata loop file", s.MetadataLoopback})
+	}
 	if vStr, err := devicemapper.GetLibraryVersion(); err == nil {
 	if vStr, err := devicemapper.GetLibraryVersion(); err == nil {
 		status = append(status, [2]string{"Library Version", vStr})
 		status = append(status, [2]string{"Library Version", vStr})
 	}
 	}