//! VM integration examples for virtiofsd
//!
//! This example shows how to integrate virtiofsd with virtual machines,
//! including QEMU command generation and setup scenarios.

// Check if virtiofsd is available
if !virtiofsd_available() {
    print("Error: virtiofsd is not installed");
    throw "virtiofsd not available";
}

print("=== Virtiofsd VM Integration Examples ===");

// Helper function to generate QEMU virtiofs device arguments
fn generate_qemu_virtiofs_args(socket_path, mount_tag) {
    return [
        "-device", "vhost-user-fs-pci,chardev=char0,tag=" + mount_tag,
        "-chardev", "socket,id=char0,path=" + socket_path
    ];
}

// Example 1: Single VM with shared /tmp directory
print("\n1. Single VM with shared directory");

let socket_path = "/tmp/vm_share.sock";
let mount_tag = "tmpshare";

// Start virtiofsd daemon using share_directory
let daemon = share_directory("/tmp", socket_path);
print("Share daemon started");
print("  PID: " + daemon.pid());
print("  Socket: " + daemon.socket_path());
print("  Host dir: " + daemon.shared_dir());

// Generate QEMU arguments
let virtiofs_args = generate_qemu_virtiofs_args(socket_path, mount_tag);
print("\nQEMU virtiofs arguments:");
for arg in virtiofs_args {
    print("  " + arg);
}

print("\nGuest mount command:");
print("  sudo mount -t virtiofs " + mount_tag + " /mnt/shared");

// Stop daemon
daemon.stop();
print("Share daemon stopped");

print("\n=== VM Integration Examples Complete ===");
print("\nKey integration points:");
print("- Use unique socket paths for each share");
print("- Mount tags should be descriptive and unique");
print("- Use read-only shares for system directories");
