From 13fc8f758d75e1d712f19c5309c4ba0f6acd934e Mon Sep 17 00:00:00 2001 From: Vincent Batts Date: Mon, 19 Jan 2015 15:10:37 -0500 Subject: [PATCH] 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 --- devicemapper/devmapper.go | 20 ++++++++++++++++++++ devicemapper/devmapper_wrapper.go | 10 ++++++++++ 2 files changed, 30 insertions(+) diff --git a/devicemapper/devmapper.go b/devicemapper/devmapper.go index c23a362..486ec15 100644 --- a/devicemapper/devmapper.go +++ b/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") diff --git a/devicemapper/devmapper_wrapper.go b/devicemapper/devmapper_wrapper.go index 499405a..aff8446 100644 --- a/devicemapper/devmapper_wrapper.go +++ b/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))) }