Browse Source

devicemapper: dm_udev_get_sync_support

expose an api to call dm_udev_get_sync_support/dm_udev_set_sync_support

Signed-off-by: Vincent Batts <vbatts@redhat.com>
Vincent Batts 10 years ago
parent
commit
9c3380039e
2 changed files with 30 additions and 0 deletions
  1. 20 0
      pkg/devicemapper/devmapper.go
  2. 10 0
      pkg/devicemapper/devmapper_wrapper.go

+ 20 - 0
pkg/devicemapper/devmapper.go

@@ -319,6 +319,26 @@ func GetLibraryVersion() (string, error) {
 	return version, nil
 }
 
+// UdevSyncSupported returns whether device-mapper is able to sync with udev
+//
+// This is essential otherwise race conditions can arise where both udev and
+// device-mapper attempt to create and destroy devices.
+func UdevSyncSupported() bool {
+	return DmUdevGetSyncSupport() != 0
+}
+
+// UdevSetSyncSupport allows setting whether the udev sync should be enabled.
+// The return bool indicates the state of whether the sync is enabled.
+func UdevSetSyncSupport(enable bool) bool {
+	if enable {
+		DmUdevSetSyncSupport(1)
+	} else {
+		DmUdevSetSyncSupport(0)
+	}
+
+	return UdevSyncSupported()
+}
+
 // Useful helper for cleanup
 func RemoveDevice(name string) error {
 	log.Debugf("[devmapper] RemoveDevice START")

+ 10 - 0
pkg/devicemapper/devmapper_wrapper.go

@@ -107,6 +107,8 @@ var (
 	DmTaskSetRo            = dmTaskSetRoFct
 	DmTaskSetSector        = dmTaskSetSectorFct
 	DmUdevWait             = dmUdevWaitFct
+	DmUdevSetSyncSupport   = dmUdevSetSyncSupportFct
+	DmUdevGetSyncSupport   = dmUdevGetSyncSupportFct
 	LogWithErrnoInit       = logWithErrnoInitFct
 )
 
@@ -231,6 +233,14 @@ func dmGetNextTargetFct(task *CDmTask, next uintptr, start, length *uint64, targ
 	return uintptr(nextp)
 }
 
+func dmUdevSetSyncSupportFct(syncWithUdev int) {
+	(C.dm_udev_set_sync_support(C.int(syncWithUdev)))
+}
+
+func dmUdevGetSyncSupportFct() int {
+	return int(C.dm_udev_get_sync_support())
+}
+
 func dmUdevWaitFct(cookie uint) int {
 	return int(C.dm_udev_wait(C.uint32_t(cookie)))
 }