1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
From f83d05c3be3c3bcc84f6fa229504848ee8078321 Mon Sep 17 00:00:00 2001
From: Vincent Batts <vbatts@redhat.com>
Date: Fri, 7 Aug 2015 10:18:20 -0400
Subject: [PATCH] devicemapper: fix zero-sized field access
Fixes: #15279
Due to
https://github.com/golang/go/commit/7904946eeb35faece61bbf6f5b3cc8be2f519c17
the devices field is dropped.
This solution works on go1.4 and go1.5
Signed-off-by: Vincent Batts <vbatts@redhat.com>
---
daemon/graphdriver/devmapper/deviceset.go | 14 +++++++++-----
pkg/devicemapper/devmapper_wrapper.go | 18 +++++++++++++++---
2 files changed, 24 insertions(+), 8 deletions(-)
diff --git a/daemon/graphdriver/devmapper/deviceset.go b/daemon/graphdriver/devmapper/deviceset.go
index 6dddeb1..97e2032 100644
--- a/daemon/graphdriver/devmapper/deviceset.go
+++ b/daemon/graphdriver/devmapper/deviceset.go
@@ -1509,12 +1509,16 @@ func (devices *DeviceSet) deactivatePool() error {
if err != nil {
return err
}
- if d, err := devicemapper.GetDeps(devname); err == nil {
- // Access to more Debug output
- logrus.Debugf("[devmapper] devicemapper.GetDeps() %s: %#v", devname, d)
+
+ if devinfo.Exists == 0 {
+ return nil
}
- if devinfo.Exists != 0 {
- return devicemapper.RemoveDevice(devname)
+ if err := devicemapper.RemoveDevice(devname); err != nil {
+ return err
+ }
+
+ if d, err := devicemapper.GetDeps(devname); err == nil {
+ logrus.Warnf("[devmapper] device %s still has %d active dependents", devname, d.Count)
}
return nil
diff --git a/pkg/devicemapper/devmapper_wrapper.go b/pkg/devicemapper/devmapper_wrapper.go
index 87c2003..44ca772 100644
--- a/pkg/devicemapper/devmapper_wrapper.go
+++ b/pkg/devicemapper/devmapper_wrapper.go
@@ -38,7 +38,10 @@ static void log_with_errno_init()
*/
import "C"
-import "unsafe"
+import (
+ "reflect"
+ "unsafe"
+)
type (
CDmTask C.struct_dm_task
@@ -184,12 +187,21 @@ func dmTaskGetDepsFct(task *CDmTask) *Deps {
if Cdeps == nil {
return nil
}
+
+ // golang issue: https://github.com/golang/go/issues/11925
+ hdr := reflect.SliceHeader{
+ Data: uintptr(unsafe.Pointer(uintptr(unsafe.Pointer(Cdeps)) + unsafe.Sizeof(*Cdeps))),
+ Len: int(Cdeps.count),
+ Cap: int(Cdeps.count),
+ }
+ devices := *(*[]C.uint64_t)(unsafe.Pointer(&hdr))
+
deps := &Deps{
Count: uint32(Cdeps.count),
Filler: uint32(Cdeps.filler),
}
- for _, device := range Cdeps.device {
- deps.Device = append(deps.Device, (uint64)(device))
+ for _, device := range devices {
+ deps.Device = append(deps.Device, uint64(device))
}
return deps
}
|