This requires the user to be in the libvirt group to perform privileged file write. If the target directory doesn't exist, pool-create-as must be run with the --build option. The destination file ownership and permissions can be set in the XML.
LFILE_DIR=/root
LFILE_NAME=要写入的文件
echo 'data' > data_to_write
TF=$(mktemp)
cat > $TF <y$LFILE_DIR/$LFILE_NAME540965$LFILE_DIR/$LFILE_NAME060000
EOF
virsh -c qemu:///system pool-create-as x dir --target $LFILE_DIR
virsh -c qemu:///system vol-create --pool x --file $TF
virsh -c qemu:///system vol-upload --pool x $LFILE_DIR/$LFILE_NAME data_to_write
virsh -c qemu:///system pool-destroy x
file-read
从文件中读取数据。
This requires the user to be in the libvirt group to perform privileged file read.
LFILE_DIR=/root
LFILE_NAME=要读取的文件路径
SPATH=file_to_save
virsh -c qemu:///system pool-create-as x dir --target $LFILE_DIR
virsh -c qemu:///system vol-download --pool x $LFILE_NAME $SPATH
virsh -c qemu:///system pool-destroy x