expose an api to call dm_udev_get_sync_support/dm_udev_set_sync_support
Signed-off-by: Vincent Batts <vbatts@redhat.com>
... | ... |
@@ -319,6 +319,26 @@ func GetLibraryVersion() (string, error) { |
319 | 319 |
return version, nil |
320 | 320 |
} |
321 | 321 |
|
322 |
+// UdevSyncSupported returns whether device-mapper is able to sync with udev |
|
323 |
+// |
|
324 |
+// This is essential otherwise race conditions can arise where both udev and |
|
325 |
+// device-mapper attempt to create and destroy devices. |
|
326 |
+func UdevSyncSupported() bool { |
|
327 |
+ return DmUdevGetSyncSupport() != 0 |
|
328 |
+} |
|
329 |
+ |
|
330 |
+// UdevSetSyncSupport allows setting whether the udev sync should be enabled. |
|
331 |
+// The return bool indicates the state of whether the sync is enabled. |
|
332 |
+func UdevSetSyncSupport(enable bool) bool { |
|
333 |
+ if enable { |
|
334 |
+ DmUdevSetSyncSupport(1) |
|
335 |
+ } else { |
|
336 |
+ DmUdevSetSyncSupport(0) |
|
337 |
+ } |
|
338 |
+ |
|
339 |
+ return UdevSyncSupported() |
|
340 |
+} |
|
341 |
+ |
|
322 | 342 |
// Useful helper for cleanup |
323 | 343 |
func RemoveDevice(name string) error { |
324 | 344 |
log.Debugf("[devmapper] RemoveDevice START") |
... | ... |
@@ -107,6 +107,8 @@ var ( |
107 | 107 |
DmTaskSetRo = dmTaskSetRoFct |
108 | 108 |
DmTaskSetSector = dmTaskSetSectorFct |
109 | 109 |
DmUdevWait = dmUdevWaitFct |
110 |
+ DmUdevSetSyncSupport = dmUdevSetSyncSupportFct |
|
111 |
+ DmUdevGetSyncSupport = dmUdevGetSyncSupportFct |
|
110 | 112 |
LogWithErrnoInit = logWithErrnoInitFct |
111 | 113 |
) |
112 | 114 |
|
... | ... |
@@ -231,6 +233,14 @@ func dmGetNextTargetFct(task *CDmTask, next uintptr, start, length *uint64, targ |
231 | 231 |
return uintptr(nextp) |
232 | 232 |
} |
233 | 233 |
|
234 |
+func dmUdevSetSyncSupportFct(syncWithUdev int) { |
|
235 |
+ (C.dm_udev_set_sync_support(C.int(syncWithUdev))) |
|
236 |
+} |
|
237 |
+ |
|
238 |
+func dmUdevGetSyncSupportFct() int { |
|
239 |
+ return int(C.dm_udev_get_sync_support()) |
|
240 |
+} |
|
241 |
+ |
|
234 | 242 |
func dmUdevWaitFct(cookie uint) int { |
235 | 243 |
return int(C.dm_udev_wait(C.uint32_t(cookie))) |
236 | 244 |
} |