Example #1
0
func (p *VirStoragePool) StorageVolCreateXML(xmlConfig string, flags uint32) (VirStorageVol, error) {
	cXml := C.CString(string(xmlConfig))
	defer C.free(unsafe.Pointer(cXml))
	ptr := C.virStorageVolCreateXML(p.ptr, cXml, C.uint(flags))
	if ptr == nil {
		return VirStorageVol{}, errors.New(GetLastError())
	}
	return VirStorageVol{ptr: ptr}, nil
}
Example #2
0
// CreateStorageVolume creates a storage volume within a pool based on an XML
// description. Not all pools support creation of volumes.
// Since 1.0.1 VolCreatePreallocMetadata in "flags" can be used to get higher
// performance with qcow2 image files which don't support full preallocation, by
// creating a sparse image file with metadata.
// "Free" should be used to free the resources after the storage volume object
// is no longer needed.
func (pool StoragePool) CreateStorageVolume(xml string, flags StorageVolumeCreateFlag) (StorageVolume, error) {
	cXML := C.CString(xml)
	defer C.free(unsafe.Pointer(cXML))

	pool.log.Printf("creating storage volume (flags = %v)...\n", flags)
	cVol := C.virStorageVolCreateXML(pool.virStoragePool, cXML, C.uint(flags))

	if cVol == nil {
		err := LastError()
		pool.log.Printf("an error occurred: %v\n", err)
		return StorageVolume{}, err
	}

	pool.log.Println("volume created")

	storageVolume := StorageVolume{
		log:           pool.log,
		virStorageVol: cVol,
	}

	return storageVolume, nil
}