#!/bin/bash
# sys/tool/qemu-nbd.sh - Network Block Device image mounting support

set -e


######
# Native dependencies

sys_tool_qemu_nbd_client_packages=( qemu-utils )


######
# settings interface

sys_tool_qemu_nbd_config_init() {
	lib_setting_vars -ro qemu_nbd_device_count

	# total number of NBD device files
	qemu_nbd_device_count=16
}


######
# lib interface

sys_tool_qemu_nbd_lib_init() {
	debug "nbd: loading nbd module"
	if lsmod | grep '^nbd ' >/dev/null; then
		debug "nbd: kernel module loaded"
	else
		info "nbd: loading kernel module"
		run_sudo modprobe nbd
	fi
}

######
# nbd interface

qemu_nbd_image_dev() { has_args 1 "$@"; echo "/dev/nbd$1"; }

qemu_nbd_image_mount() {
	has_args 2 "$@"
	run_sudo qemu-nbd -c "$(qemu_nbd_image_dev "$1")" "$2"
}
qemu_nbd_image_umount() {
	has_args 1 "$@"
	run_sudo qemu-nbd -d "$(qemu_nbd_image_dev "$1")" > /dev/null
}

qemu_nbd_partition_dev() { has_args 2 "$@"; echo "/dev/nbd${1}p${2}"; }

qemu_nbd_partition_mount() {
	has_args 3 "$@"
	[ -d "$3" ] || run_mkdir "$3"
	run_sudo mount "$(qemu_nbd_partition_dev "$1" "$2")" "$3"
}
qemu_nbd_partition_umount() {
	has_args 1 "$@"
	run_sudo umount "$1"
}

View the Developer Guide Index

View the Reference Manual Index


Generated on Fri Jul 28 14:36:11 PDT 2017 by mcsh d14 v0.23.0.