Example #1
0
//export devClose
func devClose(dev Device) {
	cfgString := C.GoString(C.tcmu_get_dev_cfgstring(dev))
	if cfgString == "" {
		log.Errorln("Cannot find configuration string")
		return
	}

	id := strings.TrimPrefix(cfgString, "longhorn//")
	if id != volume {
		//Ignore close other devs
		return
	}
	log.Infof("Device %s removed", volume)
}
Example #2
0
//export devOpen
func devOpen(dev Device) int {
	state := &State{
		backend: backend,
	}
	blockSizeStr := C.CString("hw_block_size")
	defer C.free(unsafe.Pointer(blockSizeStr))
	blockSize := int(C.tcmu_get_attribute(dev, blockSizeStr))
	if blockSize == -1 {
		log.Errorln("Cannot find valid hw_block_size")
		return -C.EINVAL
	}
	state.blockSize = blockSize

	size := int64(C.tcmu_get_device_size(dev))
	if size == -1 {
		log.Errorln("Cannot find valid disk size")
		return -C.EINVAL
	}
	state.lbas = size / int64(state.blockSize)

	cfgString := C.GoString(C.tcmu_get_dev_cfgstring(dev))
	if cfgString == "" {
		log.Errorln("Cannot find configuration string")
		return -C.EINVAL
	}

	id := strings.TrimPrefix(cfgString, "longhorn//")
	if id != volume {
		log.Debugf("Ignore volume %s, which is not mine", id)
		return -C.EINVAL
	}
	state.volume = id
	devFd = int32(C.tcmu_get_dev_fd(dev))

	go state.HandleRequest(dev)

	log.Infof("Device %s added", state.volume)
	return 0
}