migrate libvirt back to other repo

This commit is contained in:
Jeeves 2024-06-26 12:12:29 -06:00
parent 739bcb016a
commit 43333bd6b2
15 changed files with 220 additions and 1651 deletions

6
.gitignore vendored
View file

@ -1,5 +1,5 @@
random/
server/libvirt
server/.zig-cache
server/zig-out
server/zig-libvirt
server/.zig-cache/
server/zig-out/
web/

148
flake.lock generated
View file

@ -36,13 +36,49 @@
"type": "github"
}
},
"flake-utils_3": {
"inputs": {
"systems": "systems_3"
},
"locked": {
"lastModified": 1710146030,
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"flake-utils_4": {
"inputs": {
"systems": "systems_4"
},
"locked": {
"lastModified": 1710146030,
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1719075281,
"narHash": "sha256-CyyxvOwFf12I91PBWz43iGT1kjsf5oi6ax7CrvaMyAo=",
"lastModified": 1719254875,
"narHash": "sha256-ECni+IkwXjusHsm9Sexdtq8weAq/yUyt1TWIemXt3Ko=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "a71e967ef3694799d0c418c98332f7ff4cc5f6af",
"rev": "2893f56de08021cffd9b6b6dfc70fd9ccd51eb60",
"type": "github"
},
"original": {
@ -85,6 +121,36 @@
}
},
"nixpkgs_3": {
"locked": {
"lastModified": 1719231935,
"narHash": "sha256-jvgDRtw1+w9u5L2oo/2J7pJhPuJ0HL53NMq5ssxvonA=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "4cc2ade958e237ed32f5d67a25377084ac8f108b",
"type": "github"
},
"original": {
"owner": "nixos",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_4": {
"locked": {
"lastModified": 1718622336,
"narHash": "sha256-lywfxWRBn+lwdKaBy5x5uTkbCcEPUonCn6bK8OQPsw4=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "d0fc4188d246ab953653f00e9ce0cf51d10d5eda",
"type": "github"
},
"original": {
"owner": "nixos",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_5": {
"locked": {
"lastModified": 1718622336,
"narHash": "sha256-lywfxWRBn+lwdKaBy5x5uTkbCcEPUonCn6bK8OQPsw4=",
@ -123,7 +189,8 @@
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs",
"nixvirt": "nixvirt",
"zig2nix": "zig2nix"
"zig-libvirt": "zig-libvirt",
"zig2nix": "zig2nix_2"
}
},
"systems": {
@ -156,10 +223,60 @@
"type": "github"
}
},
"zig2nix": {
"systems_3": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"systems_4": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"zig-libvirt": {
"inputs": {
"flake-utils": "flake-utils_2",
"nixpkgs": "nixpkgs_3"
"nixpkgs": "nixpkgs_3",
"zig2nix": "zig2nix"
},
"locked": {
"lastModified": 1719425163,
"narHash": "sha256-XP6oDHvaJUtItVlOT8ELI/9GkCsCu3rG0SlR5qwFuhg=",
"owner": "Nomkid",
"repo": "zig-libvirt",
"rev": "8eabdba79f72a46916a2e835643a802ab29bf682",
"type": "github"
},
"original": {
"owner": "Nomkid",
"repo": "zig-libvirt",
"type": "github"
}
},
"zig2nix": {
"inputs": {
"flake-utils": "flake-utils_3",
"nixpkgs": "nixpkgs_4"
},
"locked": {
"lastModified": 1719192015,
@ -174,6 +291,25 @@
"repo": "zig2nix",
"type": "github"
}
},
"zig2nix_2": {
"inputs": {
"flake-utils": "flake-utils_4",
"nixpkgs": "nixpkgs_5"
},
"locked": {
"lastModified": 1719364424,
"narHash": "sha256-EGpIcuGfpx+NQJGUho8vK5Q3TFHdaHtTLoqV/V+n4oY=",
"owner": "Cloudef",
"repo": "zig2nix",
"rev": "67d44febbeb1fad4c861a5c4d67a8f6719f7f763",
"type": "github"
},
"original": {
"owner": "Cloudef",
"repo": "zig2nix",
"type": "github"
}
}
},
"root": "root",

View file

@ -10,11 +10,10 @@
# };
nixvirt.url = "github:Nomkid/NixVirt";
zig2nix.url = "github:Cloudef/zig2nix";
# symlink.url = "github:schuelermine/nix-symlink";
# zig-libvirt.url = "github:Nomkid/zig-libvirt";
zig-libvirt.url = "github:Nomkid/zig-libvirt";
};
outputs = { self, nixpkgs, flake-utils, nixvirt, zig2nix }:
outputs = { self, nixpkgs, flake-utils, nixvirt, zig2nix, zig-libvirt }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
@ -46,6 +45,8 @@
default = zig-env.app-no-root [] "zig build run -- \"$@\"";
};
packages.zig-libvirt = zig-libvirt.packages.${system}.default;
devShells.default = zig-env.mkShell {
nativeBuildInputs = [ pkgs.libvirt.outPath ];
};

View file

@ -1,19 +1,10 @@
const std = @import("std");
const Build = std.Build;
const Step = Build.Step;
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const translate_c = b.addTranslateC(.{
.root_source_file = b.path("libvirt/include/libvirt/libvirt.h"),
.target = target,
.optimize = optimize,
});
translate_c.addIncludeDir("libvirt/include");
const output = b.addInstallFile(translate_c.getOutput(), "libvirt.zig");
const libvirt = b.dependency("libvirt", .{});
const exe = b.addExecutable(.{
.name = "server",
@ -21,14 +12,7 @@ pub fn build(b: *std.Build) !void {
.target = target,
.optimize = optimize,
});
exe.step.dependOn(&output.step);
exe.linkLibC();
exe.root_module.addIncludePath(b.path("libvirt/include"));
// exe.linkSystemLibrary("libvirt");
exe.addLibraryPath(b.path("libvirt/lib"));
exe.addObjectFile(b.path("libvirt/lib/libvirt.so.0.10000.0"));
exe.addObjectFile(b.path("libvirt/lib/libvirt-admin.so.0.10000.0"));
exe.addObjectFile(b.path("libvirt/lib/libvirt-qemu.so.0.10000.0"));
exe.root_module.addImport("libvirt", libvirt.module("libvirt"));
b.installArtifact(exe);
const run_cmd = b.addRunArtifact(exe);
@ -39,36 +23,4 @@ pub fn build(b: *std.Build) !void {
const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step);
const libvirt_test = b.addTest(.{
.root_source_file = b.path("src/libvirt.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
});
const libvirt_connection_test = b.addTest(.{
.root_source_file = b.path("src/libvirt-connection.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
});
const libvirt_unit_tests = [_]*Step.Compile{
libvirt_test,
libvirt_connection_test,
};
for (libvirt_unit_tests) |tests| {
tests.root_module.addIncludePath(b.path("libvirt/include"));
tests.addLibraryPath(b.path("libvirt/lib"));
tests.addObjectFile(b.path("libvirt/lib/libvirt.so.0.10000.0"));
tests.addObjectFile(b.path("libvirt/lib/libvirt-admin.so.0.10000.0"));
tests.addObjectFile(b.path("libvirt/lib/libvirt-qemu.so.0.10000.0"));
}
const run_libvirt_tests = [_]*Step.Run{
b.addRunArtifact(libvirt_test),
b.addRunArtifact(libvirt_connection_test),
};
const test_step = b.step("test", "Run unit tests");
for (run_libvirt_tests) |tests| test_step.dependOn(&tests.step);
}

View file

@ -31,6 +31,9 @@
// // actually used.
// .lazy = false,
//},
.libvirt = .{
.path = "zig-libvirt",
},
},
.paths = .{

View file

@ -1,7 +0,0 @@
pub const c = @cImport({
@cInclude("libvirt/libvirt.h");
@cInclude("libvirt/libvirt-admin.h");
@cInclude("libvirt/libvirt-lxc.h");
@cInclude("libvirt/libvirt-qemu.h");
@cInclude("libvirt/virterror.h");
});

View file

@ -1,241 +0,0 @@
const std = @import("std");
const mem = std.mem;
const heap = std.heap;
const h = @import("libvirt-helper.zig");
const c = @import("libvirt-c.zig").c;
const err = @import("libvirt-error.zig");
const Domain = @import("libvirt-domain.zig");
const Pool = @import("libvirt-pool.zig");
const VirError = err.VirError;
const Connection = @This();
ptr: c.virConnectPtr,
allocator: mem.Allocator,
pub fn init(uri: []const u8, allocator: mem.Allocator) VirError!Connection {
const connection = c.virConnectOpenAuth(@ptrCast(uri), c.virConnectAuthPtrDefault, 0);
if (connection) |conn| return .{
.ptr = conn,
.allocator = allocator,
} else return err.handleError();
}
pub fn deinit(self: *const Connection) void {
_ = c.virConnectClose(self.ptr);
}
pub fn getURI(self: *const Connection) Error![]u8 {
const uri = c.virConnectGetURI(self.ptr);
defer std.c.free(uri);
const str = h.string(uri);
return if (str.len == 0) err.handleError() else try self.allocator.dupe(u8, str);
}
pub fn freeURI(self: *const Connection, uri: []u8) void {
self.allocator.free(uri);
}
test "connection" {
const conn = try Connection.init("qemu:///system", std.testing.allocator);
defer conn.deinit();
const uri = try conn.getURI();
defer conn.freeURI(uri);
}
// pub fn createPool(self: *const Connection, xml: String, flags: []const Pool.CreateFlags) !Pool {
// const pool = c.virStoragePoolCreateXML(self.ptr, @ptrCast(xml.str), intFromFlags(Pool.CreateFlags, flags));
// return if (pool) |p| Pool.init(p, self.allocator) else handleError();
// }
// pub fn definePoolFlags(self: *const Connection, xml: String, flags: []const Pool.DefineFlags) !Pool {
// const pool = c.virStoragePoolCreateXML(self.ptr, @ptrCast(xml.str), intFromFlags(Pool.DefineFlags, flags));
// return if (pool) |p| Pool.init(p, self.allocator) else handleError();
// }
pub const Error = mem.Allocator.Error || VirError;
pub fn pools(self: *const Connection) Error![]Pool {
const list = try Pool.listAllStoragePools(self, &[_]Pool.ListFlags{});
var l = try self.allocator.alloc(Pool, list.len);
for (list, 0..) |p, i| l[i] = Pool.init(p, self.allocator);
return l;
}
pub fn freePools(self: *const Connection, slice: []Pool) void {
// for (slice) |pool| pool.deinit();
self.allocator.free(slice);
}
pub fn iteratePools(self: *const Connection) Error!PoolIterator {
return .{
.allocator = self.allocator,
.values = try self.pools(),
};
}
pub const PoolIterator = struct {
allocator: mem.Allocator,
values: []Pool,
index: usize = 0,
pub fn deinit(it: *PoolIterator) void {
for (it.values) |v| v.free() catch @panic("pool free error");
it.allocator.free(it.values);
}
pub fn next(it: *PoolIterator) ?Pool {
if (it.index >= it.values.len) return null;
const v = it.values[it.index];
it.index += 1;
return v;
}
pub fn reset(it: *PoolIterator) void {
it.index = 0;
}
};
pub fn numOfDomains(self: *const Connection) VirError!u32 {
return Domain.numOfDomains(self);
}
pub fn numOfDefinedDomains(self: *const Connection) VirError!u32 {
return Domain.numOfDefinedDomains(self);
}
// pub fn createDomain(self: *const Connection, xml: String, flags: []const Domain.CreateFlags) !Domain {
// const domain = c.virDomainCreateXML(self.ptr, @ptrCast(xml.str), intFromFlags(Domain.CreateFlags, flags));
// return if (domain) |d| Domain.init(d, self.allocator) else handleError();
// }
// pub fn defineDomain(self: *const Connection, xml: String) !Domain {
// const domain = c.virDomainDefineXML(self.ptr, @ptrCast(xml.str));
// return if (domain) |d| Domain.init(d, self.allocator) else handleError();
// }
// pub fn defineDomainFlags(self: *const Connection, xml: String, flags: []const Domain.DefineFlags) !Domain {
// const domain = c.virDomainDefineXMLFlags(self.ptr, @ptrCast(xml.str), intFromFlags(Domain.DefineFlags, flags));
// return if (domain) |d| Domain.init(d, self.allocator) else handleError();
// }
pub fn createDomain(self: *const Connection, xml: h.String, flags: []const Domain.CreateFlags) VirError!Domain {
const ptr = try Domain.createXML(self, xml, flags);
return Domain.init(ptr, self.allocator);
}
pub fn domains(self: *const Connection) Error![]Domain {
const list = try Domain.listAllDomains(self, &[_]Domain.ListFlags{});
var l = try self.allocator.alloc(Domain, list.len);
for (list, 0..) |p, i| l[i] = Domain.init(p, self.allocator);
return l;
}
pub fn freeDomains(self: *const Connection, slice: []Domain) void {
// for (slice) |domain| domain.deinit();
self.allocator.free(slice);
}
pub fn iterateDomains(self: *const Connection) Error!DomainIterator {
return .{
.allocator = self.allocator,
.values = try self.domains(),
};
}
pub const DomainIterator = struct {
allocator: mem.Allocator,
values: []Domain,
index: usize = 0,
pub fn deinit(it: *DomainIterator) void {
for (it.values) |v| v.free() catch @panic("domain free error");
it.allocator.free(it.values);
}
pub fn next(it: *DomainIterator) ?Domain {
if (it.index >= it.values.len) return null;
const v = it.values[it.index];
it.index += 1;
return v;
}
pub fn reset(it: *DomainIterator) void {
it.index = 0;
}
};
test "domains" {
const conn = try Connection.init("qemu:///system", std.testing.allocator);
defer conn.deinit();
// Enumerate domains
const num_active = try conn.numOfDomains();
const num_inactive = try conn.numOfDefinedDomains();
_ = .{ num_active, num_inactive };
// Iterate domains
var domain_it = try conn.iterateDomains();
defer domain_it.deinit();
while (domain_it.next()) |domain| {
const active = try domain.isActive();
const name = try domain.getName();
_ = .{ active, name };
}
// Create and destory domain
const xml = try h.String.init(std.testing.allocator,
\\<domain type="kvm">
\\ <name>vm1</name>
\\ <uuid>48dd0909-6346-4028-b922-1b3a13571360</uuid>
\\ <memory unit="KiB">1048576</memory>
\\ <currentMemory unit="KiB">1048576</currentMemory>
\\ <vcpu placement="static">1</vcpu>
\\ <os>
\\ <type arch="x86_64" machine="pc-i440fx-8.2">hvm</type>
\\ <boot dev="hd"/>
\\ </os>
\\ <features>
\\ <acpi/>
\\ <apic/>
\\ <vmport state="off"/>
\\ </features>
\\ <cpu mode="host-passthrough" check="none" migratable="on"/>
\\ <clock offset="utc">
\\ <timer name="rtc" tickpolicy="catchup"/>
\\ <timer name="pit" tickpolicy="delay"/>
\\ <timer name="hpet" present="no"/>
\\ </clock>
\\ <on_poweroff>destroy</on_poweroff>
\\ <on_reboot>restart</on_reboot>
\\ <on_crash>destroy</on_crash>
\\ <pm>
\\ <suspend-to-mem enabled="no"/>
\\ <suspend-to-disk enabled="no"/>
\\ </pm>
\\ <devices>
\\ <emulator>/run/libvirt/nix-emulators/qemu-system-x86_64</emulator>
\\ <controller type="usb" index="0" model="ich9-ehci1">
\\ <address type="pci" domain="0x0000" bus="0x00" slot="0x02" function="0x7"/>
\\ </controller>
\\ <controller type="usb" index="0" model="ich9-uhci1">
\\ <master startport="0"/>
\\ <address type="pci" domain="0x0000" bus="0x00" slot="0x02" function="0x0" multifunction="on"/>
\\ </controller>
\\ <controller type="usb" index="0" model="ich9-uhci2">
\\ <master startport="2"/>
\\ <address type="pci" domain="0x0000" bus="0x00" slot="0x02" function="0x1"/>
\\ </controller>
\\ <controller type="usb" index="0" model="ich9-uhci3">
\\ <master startport="4"/>
\\ <address type="pci" domain="0x0000" bus="0x00" slot="0x02" function="0x2"/>
\\ </controller>
\\ <controller type="pci" index="0" model="pci-root"/>
\\ <serial type="pty">
\\ <target type="isa-serial" port="0">
\\ <model name="isa-serial"/>
\\ </target>
\\ </serial>
\\ <console type="pty">
\\ <target type="serial" port="0"/>
\\ </console>
\\ <input type="mouse" bus="ps2"/>
\\ <input type="keyboard" bus="ps2"/>
\\ <audio id="1" type="none"/>
\\ <memballoon model="virtio">
\\ <address type="pci" domain="0x0000" bus="0x00" slot="0x03" function="0x0"/>
\\ </memballoon>
\\ </devices>
\\</domain>
);
defer xml.deinit();
const domain = try conn.createDomain(xml, &.{});
try domain.destroy();
// TODO with flags
}

View file

@ -1,387 +0,0 @@
const std = @import("std");
const mem = std.mem;
const heap = std.heap;
const h = @import("libvirt-helper.zig");
const c = @import("libvirt-c.zig").c;
const err = @import("libvirt-error.zig");
const Connection = @import("libvirt-connection.zig");
const VirError = err.VirError;
const Domain = @This();
ptr: c.virDomainPtr,
arena: *heap.ArenaAllocator,
pub fn init(ptr: c.virDomainPtr, allocator: mem.Allocator) Domain {
var arena = heap.ArenaAllocator.init(allocator);
return .{
.ptr = ptr,
.arena = &arena,
};
}
pub fn deinit(self: *const Domain) void {
self.arena.deinit();
}
// TODO event handling callbacks
pub fn xmlFromNative() void {}
pub fn xmlToNative() void {}
pub fn getAllDomainStats() void {}
pub fn getDomainCapabilities() void {}
pub fn listAllDomains(conn: *const Connection, flags: []const ListFlags) VirError![]c.virDomainPtr {
var list: [*]c.virDomainPtr = undefined;
const num = c.virConnectListAllDomains(conn.ptr, @ptrCast(&list), h.intFromFlags(ListFlags, flags));
return if (num < 0) err.handleError() else list[0..@intCast(num)];
}
pub fn listDefinedDomains() void {}
pub fn listDomains() void {}
pub fn numOfDefinedDomains(conn: *const Connection) VirError!u32 {
const n = c.virConnectNumOfDomains(conn.ptr);
return if (n < 0) err.handleError() else @intCast(n);
}
pub fn numOfDomains(conn: *const Connection) VirError!u32 {
const n = c.virConnectNumOfDomains(conn.ptr);
return if (n < 0) err.handleError() else @intCast(n);
}
pub fn abortJob() void {}
pub fn abortJobFlags() void {}
pub fn addIOThread() void {}
pub fn agentSetResponseTimeout() void {}
pub fn attachDevice() void {}
pub fn attachDeviceFlags() void {}
pub fn authorizedSSHKeysSet() void {}
pub fn backupBegin() void {}
pub fn backupGetXMLDesc() void {}
pub fn blockCommit() void {}
pub fn blockCopy() void {}
pub fn blockJobAbort() void {}
pub fn blockJobSetSpeed() void {}
pub fn blockPeek() void {}
pub fn blockPull() void {}
pub fn blockRebase() void {}
pub fn blockResize() void {}
pub fn blockStats() void {}
pub fn blockStatsFlags() void {}
pub fn coreDump() void {}
pub fn coreDumpWithFormat() void {}
pub fn create() void {}
pub fn createLinux() void {}
pub fn createWithFiles() void {}
pub fn createWithFlags() void {}
pub fn createXML(conn: *const Connection, xml: h.String, flags: []const CreateFlags) VirError!c.virDomainPtr {
return if (c.virDomainCreateXML(
conn.ptr,
@ptrCast(xml.str),
h.intFromFlags(CreateFlags, flags),
)) |p| p else err.handleError();
}
pub fn createXMLWithFiles() void {}
pub fn defineXML() void {}
pub fn defineXMLFlags() void {}
pub fn delIOThread() void {}
pub fn destroy(self: *const Domain) VirError!void {
if (c.virDomainDestroy(self.ptr) < 0) return err.handleError();
}
pub fn destroyFlags(self: *const Domain, flags: []const DestroyFlags) VirError!void {
if (c.virDomainDestroyFlags(self.ptr, h.intFromFlags(DestroyFlags, flags)) < 0) return err.handleError();
}
pub fn detachDevice() void {}
pub fn detachDeviceAlias() void {}
pub fn detachDeviceFlags() void {}
pub fn fdAssociate() void {}
pub fn fsFreeze() void {}
pub fn fsInfoFree() void {}
pub fn fsThaw() void {}
pub fn fsTrim() void {}
pub fn free(self: *const Domain) VirError!void {
if (c.virDomainFree(self.ptr) < 0) return err.handleError();
}
pub fn getAutostart() void {}
pub fn getBlkioParameters() void {}
pub fn getBlockInfo() void {}
pub fn getBlockIoTune() void {}
pub fn getBlockJobInfo() void {}
pub fn getCPUStats() void {}
pub fn getConnect() void {}
pub fn getControlInfo() void {}
pub fn getDiskErrors() void {}
pub fn getEmulatorPinInfo() void {}
pub fn getFSInfo() void {}
pub fn getGuestInfo() void {}
pub fn getGuestVcpus() void {}
pub fn getHostname() void {}
pub fn getID() void {}
pub fn getIOThreadInfo() void {}
pub fn getInfo() void {}
pub fn getInterfaceParameters() void {}
pub fn getJobInfo() void {}
pub fn getJobStats() void {}
pub fn getLaunchSecurityInfo() void {}
pub fn getMaxMemory() void {}
pub fn getMaxVcpus() void {}
pub fn getMemoryParameters() void {}
pub fn getMessages() void {}
pub fn getMetadata() void {}
pub fn getName(self: *const Domain) VirError![]const u8 {
const name = c.virDomainGetName(self.ptr);
const str = h.string(name);
return if (str.len == 0) err.handleError() else str;
}
pub fn getNumaParameters() void {}
pub fn getOSType() void {}
pub fn getPerfEvents() void {}
pub fn getSchedulerParameters() void {}
pub fn getSchedulerParametersFlags() void {}
pub fn getSchedulerType() void {}
pub fn getSecurityLabel() void {}
pub fn getSecurityLabelList() void {}
pub fn getState() void {}
pub fn getTime() void {}
pub fn getUUID() void {}
pub fn getUUIDString() void {}
pub fn getVcpuPinInfo() void {}
pub fn getVcpus() void {}
pub fn getVpusFlags() void {}
pub fn getXMLDesc() void {}
pub fn graphicsReload() void {}
pub fn hasManagedSaveImage() void {}
pub fn ioThreadInfoFree() void {}
pub fn injectNMI() void {}
pub fn interfaceAddresses() void {}
pub fn interfaceFree() void {}
pub fn interfaceStats() void {}
pub fn isActive(self: *const Domain) VirError!bool {
return switch (c.virDomainIsActive(self.ptr)) {
0 => false,
1 => true,
else => err.handleError(),
};
}
pub fn isPersistent() void {}
pub fn isUpdated() void {}
pub fn listGetStats() void {}
pub fn lookupByID() void {}
pub fn lookupByUUID() void {}
pub fn lookupByUUIDString() void {}
pub fn managedSave() void {}
pub fn managedSaveDefineXML() void {}
pub fn managedSaveGetXMLDesc() void {}
pub fn managedSaveRemove() void {}
pub fn memoryPeek() void {}
pub fn memoryStats() void {}
// TODO virDomainMigrate*
pub fn openChannel() void {}
pub fn openConsole() void {}
pub fn openGraphics() void {}
pub fn openGraphicsFD() void {}
pub fn pmSuspendForDuration() void {}
pub fn pmWakeup() void {}
pub fn pinEmulator() void {}
pub fn pinIOThread() void {}
pub fn pinVcpu() void {}
pub fn pinVcpuFlags() void {}
pub fn reboot() void {}
pub fn ref(self: *const Domain) VirError!void {
if (c.virDomainRef(self.ptr) < 0) return err.handleError();
}
pub fn rename() void {}
pub fn reset() void {}
pub fn restore() void {}
pub fn restoreFlags() void {}
pub fn restoreParams() void {}
pub fn @"resume"() void {}
pub fn save() void {}
pub fn saveFlags() void {}
pub fn saveImageDefineXML() void {}
pub fn saveImageGetXMLDesc() void {}
pub fn saveParams() void {}
pub fn screenshot() void {}
pub fn sendKey() void {}
pub fn sendProcessSignal() void {}
pub fn setAutostart() void {}
pub fn setBlkioParameters() void {}
pub fn setBlockIoTune() void {}
pub fn setBlockThreshold() void {}
pub fn setGuestVcpus() void {}
pub fn setIOThreadParams() void {}
pub fn setInterfaceParameters() void {}
pub fn setLaunchSecurityState() void {}
pub fn setLifecycleAction() void {}
pub fn setMaxMemory() void {}
pub fn setMemory() void {}
pub fn setMemoryFlags() void {}
pub fn setMemoryParameters() void {}
pub fn setMemoryStatsPeriod() void {}
pub fn setMetadata() void {}
pub fn setNumaParameters() void {}
pub fn setPerfEvents() void {}
pub fn setSchedulerParameters() void {}
pub fn setSchedulerParametersFlags() void {}
pub fn setTime() void {}
pub fn setUserPassword() void {}
pub fn setVcpu() void {}
pub fn setVcpus() void {}
pub fn setVpusFlags() void {}
pub fn shutdown() void {}
pub fn @"suspend"() void {}
pub fn undefine() void {}
pub fn undefineFlags() void {}
pub fn updateDeviceFlags() void {}
pub const ListFlags = enum(c_uint) {
Active = c.VIR_CONNECT_LIST_DOMAINS_ACTIVE,
Inactive = c.VIR_CONNECT_LIST_DOMAINS_INACTIVE,
Persistent = c.VIR_CONNECT_LIST_DOMAINS_PERSISTENT,
Transient = c.VIR_CONNECT_LIST_DOMAINS_TRANSIENT,
Running = c.VIR_CONNECT_LIST_DOMAINS_RUNNING,
Paused = c.VIR_CONNECT_LIST_DOMAINS_PAUSED,
Shutoff = c.VIR_CONNECT_LIST_DOMAINS_SHUTOFF,
Other = c.VIR_CONNECT_LIST_DOMAINS_OTHER,
ManagedSave = c.VIR_CONNECT_LIST_DOMAINS_MANAGEDSAVE,
NoManagedSave = c.VIR_CONNECT_LIST_DOMAINS_NO_MANAGEDSAVE,
Autostart = c.VIR_CONNECT_LIST_DOMAINS_AUTOSTART,
NoAutostart = c.VIR_CONNECT_LIST_DOMAINS_NO_AUTOSTART,
HasSnapshot = c.VIR_CONNECT_LIST_DOMAINS_HAS_SNAPSHOT,
NoSnapshot = c.VIR_CONNECT_LIST_DOMAINS_NO_SNAPSHOT,
HasCheckpoint = c.VIR_CONNECT_LIST_DOMAINS_HAS_CHECKPOINT,
NoCheckpoint = c.VIR_CONNECT_LIST_DOMAINS_NO_CHECKPOINT,
};
pub const AbortJobFlagsValues = enum(c_uint) {};
pub const AgentResponseTimeoutValues = enum(c_uint) {};
pub const AuthorizedSSHKeysSetFlags = enum(c_uint) {};
pub const BackupBeginFlags = enum(c_uint) {};
pub const BlockCommitFlags = enum(c_uint) {};
pub const BlockCopyFlags = enum(c_uint) {};
pub const BlockJobAbortFlags = enum(c_uint) {};
pub const BlockJobInfoFlags = enum(c_uint) {};
pub const BlockJobSetSpeedFlags = enum(c_uint) {};
pub const BlockPullFlags = enum(c_uint) {};
pub const BlockRebaseFlags = enum(c_uint) {};
pub const BlockResizeFlags = enum(c_uint) {};
pub const ChannelFlags = enum(c_uint) {};
pub const ConsoleFlags = enum(c_uint) {};
pub const CoreDumpFlags = enum(c_uint) {};
pub const CreateFlags = enum(c_uint) {
None = c.VIR_DOMAIN_NONE,
StartPaused = c.VIR_DOMAIN_START_PAUSED,
StartAutodestroy = c.VIR_DOMAIN_START_AUTODESTROY,
StartBypassCache = c.VIR_DOMAIN_START_BYPASS_CACHE,
StartForceBoot = c.VIR_DOMAIN_START_FORCE_BOOT,
StartValidate = c.VIR_DOMAIN_START_VALIDATE,
StartResetNvram = c.VIR_DOMAIN_START_RESET_NVRAM,
};
pub const DefineFlags = enum(c_uint) {
Validate = c.VIR_DOMAIN_DEFINE_VALIDATE,
};
pub const DestroyFlags = enum(c_uint) {
Default = c.VIR_DOMAIN_DESTROY_DEFAULT,
Graceful = c.VIR_DOMAIN_DESTROY_GRACEFUL,
RemoveLogs = c.VIR_DOMAIN_DESTROY_REMOVE_LOGS,
};
pub const DeviceModifyFlags = enum(c_uint) {};
pub const DirtyRateCalcFlags = enum(c_uint) {};
pub const FDAssociateFlags = enum(c_uint) {};
pub const GetHostnameFlags = enum(c_uint) {};
pub const GetJobStatsFlags = enum(c_uint) {};
pub const GuestInfoTypes = enum(c_uint) {};
pub const MemoryFailureFlags = enum(c_uint) {};
pub const MemoryFlags = enum(c_uint) {};
pub const MemoryModFlags = enum(c_uint) {};
pub const MigrateFlags = enum(c_uint) {};
pub const MigrateMaxSpeedFlags = enum(c_uint) {};
pub const OpenGraphicsFlags = enum(c_uint) {};
pub const RebootFlagValues = enum(c_uint) {};
pub const SaveImageXMLFlags = enum(c_uint) {};
pub const SaveRestoreFlags = enum(c_uint) {};
pub const SetTimeFlags = enum(c_uint) {};
pub const SetUserPasswordFlags = enum(c_uint) {};
pub const ShutdownFlagValues = enum(c_uint) {};
pub const StatsTypes = enum(c_uint) {};
pub const UndefineFlagsValues = enum(c_uint) {};
pub const VcpuFlags = enum(c_uint) {};
pub const XMLFlags = enum(c_uint) {
Secure = c.VIR_DOMAIN_XML_SECURE,
Inactive = c.VIR_DOMAIN_XML_INACTIVE,
UpdateCPU = c.VIR_DOMAIN_XML_UPDATE_CPU,
Migratable = c.VIR_DOMAIN_XML_MIGRATABLE,
};
pub const BlockInfo = struct {};
pub const BlockJobCursor = u64;
pub const BlockJobInfo = struct {};
pub const BlockStats = struct {};
pub const ControlInfo = struct {};
pub const DiskError = struct {};
pub const EventGraphicsAddress = struct {};
pub const EventGraphicsSubject = struct {};
pub const EventGraphicsSubjectIdentity = struct {};
pub const FSInfo = struct {};
pub const IOThreadInfo = struct {};
pub const IPAddress = struct {};
pub const Info = struct {};
pub const Interface = struct {};
pub const InterfaceStats = struct {};
pub const JobInfo = struct {};
pub const MemoryStat = struct {};
pub const StatsRecord = struct {};
pub const BlockJobType = enum(c_uint) {};
pub const BlockedReason = enum(c_uint) {};
pub const ControlErrorReason = enum(c_uint) {};
pub const ControlState = enum(c_uint) {};
pub const CoreDumpFormat = enum(c_uint) {};
pub const CrashedReason = enum(c_uint) {};
pub const DirtyRateStatus = enum(c_uint) {};
pub const DiskErrorCode = enum(c_uint) {};
pub const EventCrashedDetailType = enum(c_uint) {};
pub const EventDefinedDetailType = enum(c_uint) {};
pub const EventGraphicsAddressType = enum(c_uint) {};
pub const EventGraphicsPhase = enum(c_uint) {};
pub const EventID = enum(c_uint) {};
pub const EventIOErrorAction = enum(c_uint) {};
pub const EventPMSuspendedDetailType = enum(c_uint) {};
pub const EventResumedDetailType = enum(c_uint) {};
pub const EventShutdownDetailType = enum(c_uint) {};
pub const EventStartedDetailType = enum(c_uint) {};
pub const EventStoppedDetailType = enum(c_uint) {};
pub const EventSuspendedDetailType = enum(c_uint) {};
pub const EventTrayChangeReason = enum(c_uint) {};
pub const EventType = enum(c_uint) {};
pub const EventUndefinedDetailType = enum(c_uint) {};
pub const EventWatchdogAction = enum(c_uint) {};
pub const GraphicsReloadType = enum(c_uint) {};
pub const InterfaceAddressesSource = enum(c_uint) {};
pub const JobOperation = enum(c_uint) {};
pub const JobType = enum(c_uint) {};
pub const Lifecycle = enum(c_uint) {};
pub const LifecycleAction = enum(c_uint) {};
pub const MemoryFailureActionType = enum(c_uint) {};
pub const MemoryFailureRecipientType = enum(c_uint) {};
pub const MemoryStatTags = enum(c_uint) {};
pub const MessageType = enum(c_uint) {};
pub const MetadataType = enum(c_uint) {};
pub const ModificationImpact = enum(c_uint) {};
pub const NostateReason = enum(c_uint) {};
pub const NumatuneMemNode = enum(c_uint) {};
pub const PMSuspendedDiskReason = enum(c_uint) {};
pub const PMSuspendedReason = enum(c_uint) {};
pub const PausedReason = enum(c_uint) {};
pub const ProcessSignal = enum(c_uint) {};
pub const RunningReason = enum(c_uint) {};
pub const ShutdownReason = enum(c_uint) {};
pub const ShutoffReason = enum(c_uint) {};
pub const State = enum(c_uint) {};
// pub const DomainIterator = Iterator(Domain, c.virDomainPtr, c.virDomainFree);

View file

@ -1,232 +0,0 @@
const std = @import("std");
const c = @import("libvirt-c.zig").c;
pub fn handleError() VirError {
const err = c.virGetLastError();
// std.debug.print("err: {any}\n", .{err});
return switch (err.*.code) {
c.VIR_ERR_OK => VirError.OK,
c.VIR_ERR_INTERNAL_ERROR => VirError.InternalError,
c.VIR_ERR_NO_MEMORY => VirError.NoMemory,
c.VIR_ERR_NO_SUPPORT => VirError.NoSupport,
c.VIR_ERR_UNKNOWN_HOST => VirError.UnknownHost,
c.VIR_ERR_NO_CONNECT => VirError.NoConnect,
c.VIR_ERR_INVALID_CONN => VirError.InvalidConn,
c.VIR_ERR_INVALID_DOMAIN => VirError.InvalidDomain,
c.VIR_ERR_INVALID_ARG => VirError.InvalidArg,
c.VIR_ERR_OPERATION_FAILED => VirError.OperationFailed,
c.VIR_ERR_GET_FAILED => VirError.GetFailed,
c.VIR_ERR_POST_FAILED => VirError.PostFailed,
c.VIR_ERR_HTTP_ERROR => VirError.HttpError,
c.VIR_ERR_SEXPR_SERIAL => VirError.SexprSerial,
c.VIR_ERR_NO_XEN => VirError.NoXen,
c.VIR_ERR_XEN_CALL => VirError.XenCall,
c.VIR_ERR_OS_TYPE => VirError.OsType,
c.VIR_ERR_NO_KERNEL => VirError.NoKernel,
c.VIR_ERR_NO_ROOT => VirError.NoRoot,
c.VIR_ERR_NO_TARGET => VirError.NoTarget,
c.VIR_ERR_NO_NAME => VirError.NoName,
c.VIR_ERR_NO_OS => VirError.NoOs,
c.VIR_ERR_NO_DEVICE => VirError.NoDevice,
c.VIR_ERR_DRIVER_FULL => VirError.DriverFull,
c.VIR_ERR_CALL_FAILED => VirError.CallFailed,
c.VIR_ERR_XML_ERROR => VirError.XmlError,
c.VIR_ERR_DOM_EXIST => VirError.DomExist,
c.VIR_ERR_OPERATION_DENIED => VirError.OperationDenied,
c.VIR_ERR_OPEN_FAILED => VirError.OpenFailed,
c.VIR_ERR_READ_FAILED => VirError.ReadFailed,
c.VIR_ERR_PARSE_FAILED => VirError.ParseFailed,
c.VIR_ERR_CONF_SYNTAX => VirError.ConfSyntax,
c.VIR_ERR_WRITE_FAILED => VirError.WriteFailed,
c.VIR_ERR_XML_DETAIL => VirError.XmlDetail,
c.VIR_ERR_INVALID_NETWORK => VirError.InvalidNetwork,
c.VIR_ERR_NETWORK_EXIST => VirError.NetworkExist,
c.VIR_ERR_SYSTEM_ERROR => VirError.SystemError,
c.VIR_ERR_RPC => VirError.Rpc,
c.VIR_ERR_GNUTLS_ERROR => VirError.GnutlsError,
c.VIR_WAR_NO_NETWORK => VirError.WarNoNetwork, // ???
c.VIR_ERR_NO_DOMAIN => VirError.NoDomain,
c.VIR_ERR_NO_NETWORK => VirError.NoNetwork,
c.VIR_ERR_INVALID_MAC => VirError.InvalidMac,
c.VIR_ERR_AUTH_FAILED => VirError.AuthFailed,
c.VIR_ERR_INVALID_STORAGE_POOL => VirError.InvalidStoragePool,
c.VIR_ERR_INVALID_STORAGE_VOL => VirError.InvalidStorageVol,
c.VIR_WAR_NO_STORAGE => VirError.WarNoStorage, // ???
c.VIR_ERR_NO_STORAGE_POOL => VirError.NoStoragePool,
c.VIR_ERR_NO_STORAGE_VOL => VirError.NoStorageVol,
c.VIR_WAR_NO_NODE => VirError.WarNoNode, // ???
c.VIR_ERR_INVALID_NODE_DEVICE => VirError.InvalidNodeDevice,
c.VIR_ERR_NO_NODE_DEVICE => VirError.NoNodeDevice,
c.VIR_ERR_NO_SECURITY_MODEL => VirError.NoSecurityModel,
c.VIR_ERR_OPERATION_INVALID => VirError.OperationInvalid,
c.VIR_WAR_NO_INTERFACE => VirError.WarNoInterface, // ???
c.VIR_ERR_NO_INTERFACE => VirError.NoInterface,
c.VIR_ERR_INVALID_INTERFACE => VirError.InvalidInterface,
c.VIR_ERR_MULTIPLE_INTERFACES => VirError.MultipleInterfaces,
c.VIR_WAR_NO_NWFILTER => VirError.WarNoNwfilter, // ???
c.VIR_ERR_INVALID_NWFILTER => VirError.InvalidNwfilter,
c.VIR_ERR_BUILD_FIREWALL => VirError.BuildFirewall,
c.VIR_WAR_NO_SECRET => VirError.WarNoSecret, // ???
c.VIR_ERR_INVALID_SECRET => VirError.InvalidSecret,
c.VIR_ERR_CONFIG_UNSUPPORTED => VirError.ConfigUnsupported,
c.VIR_ERR_OPERATION_TIMEOUT => VirError.OperationTimeout,
c.VIR_ERR_MIGRATE_PERSIST_FAILED => VirError.MigratePersistFailed,
c.VIR_ERR_HOOK_SCRIPT_FAILED => VirError.HookScriptFailed,
c.VIR_ERR_INVALID_DOMAIN_SNAPSHOT => VirError.InvalidDomainSnapshot,
c.VIR_ERR_NO_DOMAIN_SNAPSHOT => VirError.NoDomainSnapshot,
c.VIR_ERR_INVALID_STREAM => VirError.InvalidStream,
c.VIR_ERR_ARGUMENT_UNSUPPORTED => VirError.ArgumentUnsupported,
c.VIR_ERR_STORAGE_PROBE_FAILED => VirError.StorageProbeFailed,
c.VIR_ERR_STORAGE_POOL_BUILT => VirError.StoragePoolBuilt,
c.VIR_ERR_SNAPSHOT_REVERT_RISKY => VirError.SnapshotReverRisky,
c.VIR_ERR_OPERATION_ABORTED => VirError.OperationAborted,
c.VIR_ERR_AUTH_CANCELLED => VirError.AuthCancelled,
c.VIR_ERR_NO_DOMAIN_METADATA => VirError.NoDomainMetadata,
c.VIR_ERR_MIGRATE_UNSAFE => VirError.MigrateUnsafe,
c.VIR_ERR_OVERFLOW => VirError.Overflow,
c.VIR_ERR_BLOCK_COPY_ACTIVE => VirError.BlockCopyActive,
c.VIR_ERR_OPERATION_UNSUPPORTED => VirError.OperationUnsupported,
c.VIR_ERR_SSH => VirError.Ssh,
c.VIR_ERR_AGENT_UNRESPONSIVE => VirError.AgentUnresponsive,
c.VIR_ERR_RESOURCE_BUSY => VirError.ResourceBusy,
c.VIR_ERR_ACCESS_DENIED => VirError.AccessDenied,
c.VIR_ERR_DBUS_SERVICE => VirError.DbusService,
c.VIR_ERR_STORAGE_VOL_EXIST => VirError.StorageVolExist,
c.VIR_ERR_CPU_INCOMPATIBLE => VirError.CpuIncompatible,
c.VIR_ERR_XML_INVALID_SCHEMA => VirError.XmlInvalidSchema,
c.VIR_ERR_MIGRATE_FINISH_OK => VirError.MigrateFinishOk,
c.VIR_ERR_AUTH_UNAVAILABLE => VirError.AuthUnavailable,
c.VIR_ERR_NO_SERVER => VirError.NoServer,
c.VIR_ERR_NO_CLIENT => VirError.NoClient,
c.VIR_ERR_AGENT_UNSYNCED => VirError.AgentUnsynced,
c.VIR_ERR_LIBSSH => VirError.Libssh,
c.VIR_ERR_DEVICE_MISSING => VirError.DeviceMissing,
c.VIR_ERR_INVALID_NWFILTER_BINDING => VirError.InvalidNwfilterBinding,
c.VIR_ERR_NO_NWFILTER_BINDING => VirError.NoNwfilterBinding,
c.VIR_ERR_INVALID_DOMAIN_CHECKPOINT => VirError.InvalidDomainCheckpoint,
c.VIR_ERR_NO_DOMAIN_CHECKPOINT => VirError.NoDomainCheckpoint,
c.VIR_ERR_NO_DOMAIN_BACKUP => VirError.NoDomainBackup,
c.VIR_ERR_INVALID_NETWORK_PORT => VirError.InvalidNetworkPort,
c.VIR_ERR_NETWORK_PORT_EXIST => VirError.NetworkPortExist,
c.VIR_ERR_NO_NETWORK_PORT => VirError.NoNetworkPort,
c.VIR_ERR_NO_HOSTNAME => VirError.NoHostname,
c.VIR_ERR_CHECKPOINT_INCONSISTENT => VirError.CheckpointInconsistent,
c.VIR_ERR_MULTIPLE_DOMAINS => VirError.MultipleDomains,
c.VIR_ERR_NO_NETWORK_METADATA => VirError.NoNetworkMetadata,
else => VirError.OK,
};
}
pub const VirError = error{
OK,
InternalError,
NoMemory,
NoSupport,
UnknownHost,
NoConnect,
InvalidConn,
InvalidDomain,
InvalidArg,
OperationFailed,
GetFailed,
PostFailed,
HttpError,
SexprSerial,
NoXen,
XenCall,
OsType,
NoKernel,
NoRoot,
NoSource,
NoTarget,
NoName,
NoOs,
NoDevice,
NoXenstore,
DriverFull,
CallFailed,
XmlError,
DomExist,
OperationDenied,
OpenFailed,
ReadFailed,
ParseFailed,
ConfSyntax,
WriteFailed,
XmlDetail,
InvalidNetwork,
NetworkExist,
SystemError,
Rpc,
GnutlsError,
WarNoNetwork, // ???
NoDomain,
NoNetwork,
InvalidMac,
AuthFailed,
InvalidStoragePool,
InvalidStorageVol,
WarNoStorage, // ???
NoStoragePool,
NoStorageVol,
WarNoNode, // ???
InvalidNodeDevice,
NoNodeDevice,
NoSecurityModel,
OperationInvalid,
WarNoInterface, // ???
NoInterface,
InvalidInterface,
MultipleInterfaces,
WarNoNwfilter, // ???
InvalidNwfilter,
BuildFirewall,
WarNoSecret, // ???
InvalidSecret,
ConfigUnsupported,
OperationTimeout,
MigratePersistFailed,
HookScriptFailed,
InvalidDomainSnapshot,
NoDomainSnapshot,
InvalidStream,
ArgumentUnsupported,
StorageProbeFailed,
StoragePoolBuilt,
SnapshotReverRisky,
OperationAborted,
AuthCancelled,
NoDomainMetadata,
MigrateUnsafe,
Overflow,
BlockCopyActive,
OperationUnsupported,
Ssh,
AgentUnresponsive,
ResourceBusy,
AccessDenied,
DbusService,
StorageVolExist,
CpuIncompatible,
XmlInvalidSchema,
MigrateFinishOk,
AuthUnavailable,
NoServer,
NoClient,
AgentUnsynced,
Libssh,
DeviceMissing,
InvalidNwfilterBinding,
NoNwfilterBinding,
InvalidDomainCheckpoint,
NoDomainCheckpoint,
NoDomainBackup,
InvalidNetworkPort,
NetworkPortExist,
NoNetworkPort,
NoHostname,
CheckpointInconsistent,
MultipleDomains,
NoNetworkMetadata,
};

View file

@ -1,89 +0,0 @@
const std = @import("std");
const mem = std.mem;
const err = @import("libvirt-error.zig");
// Helper struct for allocating null-terminated strings
pub const String = struct {
allocator: mem.Allocator,
slice: []u8,
str: [:0]const u8,
pub fn init(allocator: mem.Allocator, in_str: []const u8) !String {
const str = try allocator.alloc(u8, in_str.len + 1);
@memcpy(str[0..in_str.len], in_str);
str[str.len - 1] = 0;
return .{
.allocator = allocator,
.slice = str,
.str = @ptrCast(str),
};
}
pub fn deinit(self: *const String) void {
self.allocator.free(self.slice);
}
};
pub fn string(str: [*c]const u8) []const u8 {
return mem.span(str);
}
pub fn intFromFlags(comptime T: type, flags: []const T) c_uint {
var flags_int: c_uint = 0;
for (flags) |f| flags_int |= @intFromEnum(f);
return flags_int;
}
fn Iterator(comptime T: type, comptime Ptr: type, comptime freeFn: *const fn (Ptr) callconv(.C) c_int) type {
return struct {
allocator: mem.Allocator,
list: [*]Ptr,
num: c_int,
curr: usize,
pub fn init(
comptime PP: type, // Parent Pointer
comptime P: type, // Parent
comptime F: type, // Flags
parent: *const P,
flags: []const F,
allocator: mem.Allocator,
initFn: *const fn (?*PP, [*c][*c]Ptr, c_uint) callconv(.C) c_int,
) !Self {
var list: [*]Ptr = undefined;
const num = initFn(parent.ptr, @ptrCast(&list), intFromFlags(F, flags));
return if (num < 0) err.handleError() else .{
.allocator = allocator,
.list = list,
.num = num,
.curr = 0,
};
}
pub fn deinit(self: *Self) void {
var i: usize = 0;
while (i < self.num) : (i += 1) _ = freeFn(self.list[i]);
}
pub fn first(self: *Self) T {
self.curr = 0;
// return .{ .ptr = self.list[self.curr], .arena = heap.ArenaAllocator.init(self.allocator) };
return T.init(self.list[self.curr], self.allocator);
}
pub fn next(self: *Self) ?T {
if (self.curr >= self.num) return null;
const ptr = self.list[self.curr];
self.curr += 1;
// return .{ .ptr = ptr, .arena = heap.ArenaAllocator.init(self.allocator) };
return T.init(ptr, self.allocator);
}
const Self = @This();
};
}
fn numOf(
comptime P: type,
ptr: P,
fnPtr: *const fn (P) callconv(.C) c_int,
) !u32 {
const num = fnPtr(ptr);
return if (num < 0) err.handleError() else @intCast(num);
}

View file

@ -1,265 +0,0 @@
const std = @import("std");
const mem = std.mem;
const heap = std.heap;
const c = @import("libvirt-c.zig").c;
const h = @import("libvirt-helper.zig");
const err = @import("libvirt-error.zig");
const Connection = @import("libvirt-connection.zig");
const Volume = @import("libvirt-volume.zig");
const VirError = err.VirError;
const Pool = @This();
ptr: c.virStoragePoolPtr,
arena: *heap.ArenaAllocator,
pub fn init(ptr: c.virStoragePoolPtr, allocator: mem.Allocator) Pool {
var arena = heap.ArenaAllocator.init(allocator);
return .{
.ptr = ptr,
.arena = &arena,
};
}
pub fn deinit(self: *const Pool) void {
self.arena.deinit();
}
// pub fn findStoragePoolSources(
// conn: *const Connection,
// type: []const u8,
// srcSpec: []const u8,
// flags: []const Flags,
// ) VirError![]u8 {} // TODO
// pub fn getStoragePoolCapabilities(
// conn: *const Connection,
// flags: []const Flags,
// ) VirError![]u8 {} // TODO
pub fn listAllStoragePools(
conn: *const Connection,
// pools: [*]c.virStoragePoolPtr,
flags: []const ListFlags,
) VirError![]c.virStoragePoolPtr {
var list: [*]c.virStoragePoolPtr = undefined;
const num = c.virConnectListAllStoragePools(
conn.ptr,
@ptrCast(&list),
h.intFromFlags(ListFlags, flags),
);
return if (num < 0) err.handleError() else list[0..@intCast(num)];
}
// pub fn listDefinedStoragePools(
// conn: *const Connection,
// names: [*]const []const u8,
// maxnames: u32,
// ) VirError!u32 {} // TODO
// pub fn listStoragePools(
// conn: *const Connection,
// names: [*]const []const u8,
// maxnames: u32,
// ) VirError!u32 {} // TODO
// pub fn numOfDefinedStoragePools(conn: *const Connection) VirError!u32 {}
// pub fn numOfStoragePools(conn: *const Connection) VirError!u32 {}
// TODO event handling callbacks
pub fn build(self: *const Pool, flags: []const BuildFlags) VirError!void {
if (c.virStoragePoolBuild(self.ptr, h.intFromFlags(BuildFlags, flags)) < 0) return err.handleError();
}
// pub fn create(conn: *const Connection) VirError!void {} // TODO
// pub fn createXML(conn: *const Connection) VirError!void {} // TODO
// pub fn defineXML(conn: *const Connection) VirError!void {} // TODO
pub fn delete(self: *const Pool, flags: []const DeleteFlags) VirError!void {
if (c.virStoragePoolDelete(self.ptr, h.intFromFlags(DeleteFlags, flags)) < 0) return err.handleError();
}
pub fn destroy(self: *const Pool) VirError!void {
if (c.virStoragePoolDestroy(self.ptr) < 0) return err.handleError();
}
pub fn free(self: *const Pool) VirError!void {
if (c.virStoragePoolFree(self.ptr) < 0) return err.handleError();
}
pub fn getAutostart(self: *const Pool, autostart: *c_int) VirError!void {
if (c.virStoragePoolGetAutostart(self.ptr, autostart) < 0) return err.handleError();
}
pub fn getConnect(self: *const Pool) VirError!c.virConnectPtr {
return if (c.virStoragePoolGetConnect(self.ptr)) |ptr| ptr else err.handleError();
}
pub fn getInfo(self: *const Pool, info: c.virStoragePoolInfoPtr) VirError!void {
if (c.virStoragePoolGetInfo(self.ptr, info) < 0) return err.handleError();
}
pub fn getName(self: *const Pool) VirError![]const u8 {
const name = c.virStoragePoolGetName(self.ptr);
const str = h.string(name);
return if (str.len == 0) err.handleError() else str;
}
// pub fn getUUID(self: *const Pool) VirError!void {} // TODO
// pub fn getUUIDString(self: *const Pool) VirError!void {} // TODO
pub fn getXMLDesc(self: *const Pool, flags: []const XMLFlags) VirError![]const u8 {
const desc = c.virStoragePoolGetXMLDesc(self.ptr, h.intFromFlags(XMLFlags, flags));
const str = h.string(desc);
return if (str.len == 0) err.handleError() else str;
}
pub fn isActive(self: *const Pool) VirError!bool {
return switch (c.virStoragePoolIsActive(self.ptr)) {
0 => false,
1 => true,
else => err.handleError(),
};
}
pub fn isPersistent(self: *const Pool) VirError!bool {
return switch (c.virStoragePoolIsPersistent(self.ptr)) {
0 => false,
1 => true,
else => err.handleError(),
};
}
// pub fn listAllVolumes(self: *const Pool) void {} // TODO
// pub fn listVolumes(self: *const Pool) void {} // TODO
pub fn lookupByName(conn: *const Connection, name: []const u8) VirError!Pool {
if (c.vir(conn.ptr, name)) |p| p else err.handleError();
}
pub fn lookupByTargetPath(conn: *const Connection, path: []const u8) VirError!Pool {
if (c.vir(conn.ptr, path)) |p| p else err.handleError();
}
pub fn lookupByUUID(conn: *const Connection, uuid: []const u8) VirError!Pool {
if (c.vir(conn.ptr, uuid)) |p| p else err.handleError();
}
pub fn lookupByUUIDString(conn: *const Connection, uuid: []const u8) VirError!Pool {
if (c.vir(conn.ptr, uuid)) |p| p else err.handleError();
}
pub fn lookupByVolume(vol: *const Volume) VirError!Pool {
if (c.vir(vol.ptr)) |p| p else err.handleError();
}
pub fn numOfVolumes(self: *const Pool) VirError!u32 {
const num = c.virStoragePoolNumOfVolumes(self.ptr);
return if (num < 0) err.handleError() else num;
}
pub fn ref(self: *const Pool) VirError!void {
if (c.virStoragePoolRef(self.ptr) < 0) return err.handleError();
}
pub fn refresh(self: *const Pool, flags: []const RefreshFlags) VirError!void {
if (c.virStoragePoolRefresh(self.ptr, h.intFromFlags(RefreshFlags, flags)) < 0) return err.handleError();
}
pub fn setAutostart(self: *const Pool, autostart: bool) VirError!void {
const i = if (autostart) 1 else 0;
if (c.virStoragePoolSetAutostart(self.ptr, i) < 0) return err.handleError();
}
pub fn undefine(self: *const Pool) VirError!void {
if (c.virStoragePoolUndefine(self.ptr) < 0) return err.handleError();
}
// pub fn createVolume(self: *const Pool, xml: String, flags: []const Volume.CreateFlags) !Volume {
// const volume = c.virStorageVolCreateXML(self.ptr, @ptrCast(xml.str), intFromFlags(Volume.CreateFlags, flags));
// return if (volume) |v| Volume.init(v, self.arena.allocator()) else err.handleError();
// }
// pub fn lookupVolumeByName(self: *const Pool, name: []const u8) !Volume {
// const volume = c.virStorageVolLookupByName(self.ptr, @ptrCast(name));
// return if (volume) |v| Volume.init(v, self.arena.allocator()) else err.handleError();
// }
// pub fn iterateVolumes(self: *const Pool, flags: []const ListFlags) Volume.VolumeIterator {
// return Volume.VolumeIterator.init(
// c.virStorageVolumePtr,
// Pool,
// Volume.ListFlags,
// self,
// flags,
// self.arena.allocator(),
// c.virStoragePoolListAllVolumes,
// );
// }
pub fn lookupVolumeByKey(self: *const Pool, key: []const u8) VirError!Volume {
const volume = Volume.lookupByKey(self, key);
return if (volume) |v| v else err.handleError();
}
pub fn lookupVolumeByName(self: *const Pool, name: []const u8) VirError!Volume {
const volume = Volume.lookupByName(self, name);
return if (volume) |v| v else err.handleError();
}
pub fn lookupVolumeByPath(self: *const Pool, path: []const u8) VirError!Volume {
const volume = Volume.lookupByPath(self, path);
return if (volume) |v| v else err.handleError();
}
pub const ListFlags = enum(c_uint) {
Inactive = c.VIR_CONNECT_LIST_STORAGE_POOLS_INACTIVE,
Active = c.VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE,
Persistent = c.VIR_CONNECT_LIST_STORAGE_POOLS_PERSISTENT,
Transient = c.VIR_CONNECT_LIST_STORAGE_POOLS_TRANSIENT,
Autostart = c.VIR_CONNECT_LIST_STORAGE_POOLS_AUTOSTART,
NoAutostart = c.VIR_CONNECT_LIST_STORAGE_POOLS_NO_AUTOSTART,
Dir = c.VIR_CONNECT_LIST_STORAGE_POOLS_DIR,
Fs = c.VIR_CONNECT_LIST_STORAGE_POOLS_FS,
NetFs = c.VIR_CONNECT_LIST_STORAGE_POOLS_NETFS,
Logical = c.VIR_CONNECT_LIST_STORAGE_POOLS_LOGICAL,
Disk = c.VIR_CONNECT_LIST_STORAGE_POOLS_DISK,
Iscsi = c.VIR_CONNECT_LIST_STORAGE_POOLS_ISCSI,
Scsi = c.VIR_CONNECT_LIST_STORAGE_POOLS_SCSI,
Mpath = c.VIR_CONNECT_LIST_STORAGE_POOLS_MPATH,
Rbd = c.VIR_CONNECT_LIST_STORAGE_POOLS_RBD,
Sheepdog = c.VIR_CONNECT_LIST_STORAGE_POOLS_SHEEPDOG,
Gluster = c.VIR_CONNECT_LIST_STORAGE_POOLS_GLUSTER,
Zfs = c.VIR_CONNECT_LIST_STORAGE_POOLS_ZFS,
Vstorage = c.VIR_CONNECT_LIST_STORAGE_POOLS_VSTORAGE,
IscsiDirect = c.VIR_CONNECT_LIST_STORAGE_POOLS_ISCSI_DIRECT,
};
pub const BuildFlags = enum(c_uint) {
New = c.VIR_STORAGE_POOL_BUILD_NEW,
Repair = c.VIR_STORAGE_POOL_BUILD_REPAIR,
Resize = c.VIR_STORAGE_POOL_BUILD_RESIZE,
NoOverwrite = c.VIR_STORAGE_POOL_BUILD_NO_OVERWRITE,
Overwrite = c.VIR_STORAGE_POOL_BUILD_OVERWRITE,
};
pub const CreateFlags = enum(c_uint) {
Normal = c.VIR_STORAGE_POOL_CREATE_NORMAL,
WithBuild = c.VIR_STORAGE_POOL_CREATEWITH_BUILD_,
WithBuildOverwrite = c.VIR_STORAGE_POOL_CREATE_WITH_BUILD_OVERWRITE,
WithBuildNoOverwrite = c.VIR_STORAGE_POOL_CREATE_WITH_BUILD_NO_OVERWRITE,
};
pub const DefineFlags = enum(c_uint) {
Validate = c.VIR_STORAGE_POOL_DEFINE_VALIDATE,
};
pub const DeleteFlags = enum(c_uint) {
Normal = c.VIR_STORAGE_POOL_DELETE_NORMAL,
Zeroed = c.VIR_STORAGE_POOL_DELETE_ZEROED,
};
pub const RefreshFlags = enum(c_uint) {};
pub const XMLFlags = enum(c_uint) {
Inactive = c.VIR_STORAGE_XML_INACTIVE,
};
pub const Info = struct {
state: State,
capacity: u64,
allocation: u64,
available: u64,
};
pub const State = enum(c_uint) {
Inactive = c.VIR_STORAGE_POOL_INACTIVE,
Building = c.VIR_STORAGE_POOL_BUILDING,
Running = c.VIR_STORAGE_POOL_RUNNING,
Degraded = c.VIR_STORAGE_POOL_DEGRADED,
Inaccessible = c.VIR_STORAGE_POOL_INACCESSIBLE,
Last = c.VIR_STORAGE_POOL_STATE_LAST,
};
pub const EventID = enum(c_uint) {
Lifecycle = c.VIR_STORAGE_POOL_EVENT_ID_LIFECYCLE,
Refresh = c.VIR_STORAGE_POOL_EVENT_ID_REFRESH,
Last = c.VIR_STORAGE_POOL_EVENT_ID_LAST,
};
pub const EventLifecycleType = enum(c_uint) {
Defined = c.VIR_STORAGE_POOL_EVENT_DEFINED,
Undefined = c.VIR_STORAGE_POOL_EVENT_UNDEFINED,
Started = c.VIR_STORAGE_POOL_EVENT_STARTED,
Stopped = c.VIR_STORAGE_POOL_EVENT_STOPPED,
Created = c.VIR_STORAGE_POOL_EVENT_CREATED,
Deleted = c.VIR_STORAGE_POOL_EVENT_DELETED,
Last = c.VIR_STORAGE_POOL_EVENT_LAST,
};
// pub const PoolIterator = Iterator(Pool, c.virStoragePoolPtr, c.virStoragePoolFree);

View file

@ -1,135 +0,0 @@
const std = @import("std");
const mem = std.mem;
const heap = std.heap;
const h = @import("libvirt-helper.zig");
const c = @import("libvirt-c.zig").c;
const err = @import("libvirt-error.zig");
const Connection = @import("libvirt-connection.zig");
const Domain = @import("libvirt-domain.zig");
const VirError = err.VirError;
const Snapshot = @This();
ptr: c.virDomainSnapshotPtr,
arena: *heap.ArenaAllocator,
pub fn init(ptr: c.virDomainSnapshotPtr, allocator: mem.Allocator) Snapshot {
var arena = heap.ArenaAllocator.init(allocator);
return .{
.ptr = ptr,
.arena = &arena,
};
}
pub fn deinit(self: *const Snapshot) void {
self.arena.deinit();
}
pub fn hasCurrentSnapshot(domain: *const Domain) VirError!bool {
return switch (c.virDomainHasCurrentSnapshot(domain.ptr, 0)) {
0 => false,
1 => true,
else => err.handleError(),
};
}
// pub fn listAllSnapshots(domain: *const Domain) VirError!void {} // TODO
pub fn revertToSnapshot() void {}
pub fn createXML(domain: *const Domain, xml: []const u8, flags: []const CreateFlags) VirError!Snapshot {
return if (c.virDomainSnapshotCreateXML(domain.ptr, @ptrCast(xml), h.intFromFlags(CreateFlags, flags))) |s| s else err.handleError();
}
pub fn current(domain: *const Domain) VirError!Snapshot {
return if (c.virDomainSnapshotCurrent(domain.ptr, 0)) |s| s else err.handleError();
}
pub fn delete(self: *const Snapshot, flags: []const DeleteFlags) VirError!void {
if (c.virDomainSnapshotDelete(self.ptr, h.intFromFlags(DeleteFlags, flags)) < 0) return err.handleError();
}
pub fn free(self: *const Snapshot) VirError!void {
if (c.virDomainSnapshotFree(self.ptr) < 0) return err.handleError();
}
pub fn getConnect(self: *const Snapshot) VirError!Connection {
return if (c.virDomainSnapshotGetConnect(self.ptr)) |v| v else err.handleError();
}
pub fn getDomain(self: *const Snapshot) VirError!Domain {
return if (c.virDomainSnapshotGetDomain(self.ptr)) |v| v else err.handleError();
}
pub fn getName(self: *const Snapshot) VirError![]const u8 {
return if (c.virDomainSnapshotGetName(self.ptr)) |v| v else err.handleError();
}
pub fn getParent(self: *const Snapshot) VirError!Snapshot {
return if (c.virDomainSnapshotGetParent(self.ptr, 0)) |v| v else err.handleError();
}
// pub fn getXMLDesc(self: *const Snapshot) VirError!void {} // TODO
pub fn hasMetadata(self: *const Snapshot) VirError!bool {
return switch (c.virDomainSnapshotHasMetadata(self.ptr, 0)) {
0 => false,
1 => true,
else => err.handleError(),
};
}
pub fn isCurrent(self: *const Snapshot) VirError!bool {
return switch (c.virDomainSnapshotIsCurrent(self.ptr, 0)) {
0 => false,
1 => true,
else => err.handleError(),
};
}
pub fn listAllChildren() void {} // TODO
pub fn listChildrenNames() void {} // TODO
// pub fn listNames(domain: *const Domain) VirError!void {} // TODO
pub fn lookupByName(domain: *const Domain, name: []const u8) VirError!Snapshot {
return if (c.virDomainSnapshotLookupByName(domain.ptr, @ptrCast(name), 0)) |s| s else err.handleError();
}
pub fn num(domain: *const Domain, flags: []const ListFlags) VirError!u32 {
const n = c.virDomainSnapshotNum(domain.ptr, h.intFromFlags(ListFlags, flags));
return if (n < 0) err.handleError() else @intCast(n);
}
pub fn numChildren(self: *const Snapshot, flags: []const ListFlags) VirError!u32 {
const n = c.virDomainSnapshotNumChildred(self.ptr, h.intFromFlags(ListFlags, flags));
return if (n < 0) err.handleError() else @intCast(n);
}
pub fn ref(self: *const Snapshot) VirError!void {
if (c.virDomainSnapshotRef(self.ptr) < 0) return err.handleError();
}
pub const ListFlags = enum(c_uint) {
Descendants = c.VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS,
Roots = c.VIR_DOMAIN_SNAPSHOT_LIST_ROOTS,
Metadata = c.VIR_DOMAIN_SNAPSHOT_LIST_METADATA,
Leaves = c.VIR_DOMAIN_SNAPSHOT_LIST_LEAVES,
NoLeaves = c.VIR_DOMAIN_SNAPSHOT_LIST_NO_LEAVES,
NoMetadata = c.VIR_DOMAIN_SNAPSHOT_LIST_NO_METADATA,
Inactive = c.VIR_DOMAIN_SNAPSHOT_LIST_INACTIVE,
Active = c.VIR_DOMAIN_SNAPSHOT_LIST_ACTIVE,
DiskOnly = c.VIR_DOMAIN_SNAPSHOT_LIST_DISK_ONLY,
Internal = c.VIR_DOMAIN_SNAPSHOT_LIST_INTERNAL,
External = c.VIR_DOMAIN_SNAPSHOT_LIST_EXTERNAL,
Topological = c.VIR_DOMAIN_SNAPSHOT_LIST_TOPOLOGICAL,
};
pub const CreateFlags = enum(c_uint) {
Redefine = c.VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE,
Current = c.VIR_DOMAIN_SNAPSHOT_CREATE_CURRENT,
NoMetadata = c.VIR_DOMAIN_SNAPSHOT_CREATE_NO_METADATA,
Halt = c.VIR_DOMAIN_SNAPSHOT_CREATE_HALT,
DiskOnly = c.VIR_DOMAIN_SNAPSHOT_CREATE_DISK_ONLY,
ReuseExt = c.VIR_DOMAIN_SNAPSHOT_CREATE_REUSE_EXT,
Quiesce = c.VIR_DOMAIN_SNAPSHOT_CREATE_QUIESCE,
Atomic = c.VIR_DOMAIN_SNAPSHOT_CREATE_ATOMIC,
Live = c.VIR_DOMAIN_SNAPSHOT_CREATE_LIVE,
Validate = c.VIR_DOMAIN_SNAPSHOT_CREATE_VALIDATE,
};
pub const DeleteFlags = enum(c_uint) {
Children = c.VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN,
MetadataOnly = c.VIR_DOMAIN_SNAPSHOT_DELETE_METADATA_ONLY,
ChildrenOnly = c.VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY,
};
pub const RevertFlags = enum(c_uint) {
Running = c.VIR_DOMAIN_SNAPSHOT_REVERT_RUNNING,
Paused = c.VIR_DOMAIN_SNAPSHOT_REVERT_PAUSED,
Force = c.VIR_DOMAIN_SNAPSHOT_REVERT_FORCE,
ResetNvram = c.VIR_DOMAIN_SNAPSHOT_REVERT_RESET_NVRAM,
};
pub const XMLFlags = enum(c_uint) {
Secure = c.VIR_DOMAIN_XML_SECURE,
};

View file

@ -1,154 +0,0 @@
const std = @import("std");
const mem = std.mem;
const heap = std.heap;
const h = @import("libvirt-helper.zig");
const c = @import("libvirt-c.zig").c;
const err = @import("libvirt-error.zig");
const Connection = @import("libvirt-connection.zig");
const Pool = @import("libvirt-pool.zig");
const VirError = err.VirError;
const Volume = @This();
ptr: c.virStorageVolPtr,
arena: *heap.ArenaAllocator,
pub fn init(ptr: c.virStorageVolPtr, allocator: mem.Allocator) Volume {
var arena = heap.ArenaAllocator.init(allocator);
return .{
.ptr = ptr,
.arena = &arena,
};
}
pub fn deinit(self: *const Volume) void {
self.arena.deinit();
}
// pub fn createXML(
// pool: *const Pool,
// xml: h.String,
// flags: []const CreateFlags,
// ) void {} // TODO
// pub fn createXMLFrom(
// pool: *const Pool,
// xml: h.String,
// flags: []const CreateFlags,
// ) void {} // TODO
pub fn delete(self: *const Volume, flags: []const DeleteFlags) VirError!void {
if (c.virStorageVolDelete(self.ptr, h.intFromFlags(DeleteFlags, flags)) < 0)
return err.handleError();
}
// pub fn download(self: *const Volume) VirError!void {} // TODO
pub fn free(self: *const Volume) VirError!void {
if (c.virStorageVolFree(self.ptr) < 0) return err.handleError();
}
pub fn getConnect(self: *const Volume) VirError!c.virConnectPtr {
return if (c.virStorageVolGetConnect(self.ptr)) |conn| conn else err.handleError();
}
pub const GetInfoError = mem.Allocator.Error || VirError;
pub fn getInfo(self: *const Volume) GetInfoError!*Info {
var info = try self.arena.allocator().create(Info);
errdefer self.arena.allocator().destroy(info);
const p: c.virStorageVolInfoPtr = undefined;
if (c.virStorageVolGetInfo(self.ptr, p) < 0) return err.handleError();
info.type = p.*.type;
info.capacity = p.*.capacity;
info.allocation = p.*.allocation;
return info;
} // TODO
// pub fn getInfoFlags(self: *const Volume, flags: []const InfoFlags) GetInfoError!void {} // TODO
pub fn getKey(self: *const Volume) VirError![]const u8 {
return if (c.virStorageVolGetKey(self.ptr)) |v| v else err.handleError();
}
pub fn getName(self: *const Volume) VirError![]const u8 {
return if (c.virStorageVolGetName(self.ptr)) |v| v else err.handleError();
}
pub fn getPath(self: *const Volume) VirError![]const u8 {
// TODO use h.String?
return if (c.virStorageVolGetPath(self.ptr)) |v| v else err.handleError();
}
// pub fn getXMLDesc(self: *const Volume) void {} // TODO
pub fn lookupByKey(conn: *const Connection, key: []const u8) VirError!Volume {
return if (c.virStorageVolLookupByKey(conn.ptr, key)) |v| v else err.handleError();
}
pub fn lookupByName(conn: *const Connection, name: []const u8) VirError!Volume {
return if (c.virStorageVolLookupByName(conn.ptr, name)) |v| v else err.handleError();
}
pub fn lookupByPath(conn: *const Connection, path: []const u8) VirError!Volume {
return if (c.virStorageVolLookupByPath(conn.ptr, path)) |v| v else err.handleError();
}
pub fn ref(self: *const Volume) VirError!void {
if (c.virStorageVolRef(self.ptr) < 0) return err.handleError();
}
pub fn resize(self: *const Volume, capacity: u64, flags: []const ResizeFlags) VirError!void {
if (c.virStorageVolResize(self.ptr, capacity, h.intFromFlags(ResizeFlags, flags)) < 0) return err.handleError();
}
// pub fn upload(self: *const Volume) void {} // TODO
pub fn wipe(self: *const Volume, flags: []const WipeFlags) VirError!void {
if (c.virStorageVolWipe(self.ptr, h.intFromFlags(WipeFlags, flags)) < 0) return err.handleError();
}
pub fn wipePattern(self: *const Volume, algorithm: WipeAlgorithm, flags: []const WipeFlags) VirError!void {
if (c.virStorageVolWipePattern(
self.ptr,
@intFromEnum(algorithm),
h.intFromFlags(WipeFlags, flags),
) < 0) return err.handleError();
}
pub const ListFlags = enum(c_uint) {};
pub const CreateFlags = enum(c_uint) {
PreallocMetadata = c.VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA,
Reflink = c.VIR_STORAGE_VOL_CREATE_REFLINK,
Validate = c.VIR_STORAGE_VOL_CREATE_VALIDATE,
};
pub const DeleteFlags = enum(c_uint) {
Normal = c.VIR_STORAGE_VOL_DELETE_NORMAL,
Zeroed = c.VIR_STORAGE_VOL_DELETE_ZEROED,
WithSnapshots = c.VIR_STORAGE_VOL_DELETE_WITH_SNAPSHOTS,
};
pub const DownloadFlags = enum(c_uint) {
SparseStream = c.VIR_STORAGE_VOL_DOWNLOAD_SPARSE_STREAM,
};
pub const InfoFlags = enum(c_uint) {
UseAllocation = c.VIR_STORAGE_VOL_USE_ALLOCATION,
GetPhysical = c.VIR_STORAGE_VOL_GET_PHYSICAL,
};
pub const ResizeFlags = enum(c_uint) {
Allocate = c.VIR_STORAGE_VOL_RESIZE_ALLOCATE,
Delta = c.VIR_STORAGE_VOL_RESIZE_DELTA,
Shrink = c.VIR_STORAGE_VOL_RESIZE_SHRINK,
};
pub const UploadFlags = enum(c_uint) {};
pub const WipeFlags = enum(c_uint) {};
pub const Info = struct {
type: Type,
capacity: u64,
allocation: u64,
};
pub const Type = enum(c_uint) {
File = c.VIR_STORAGE_VOL_FILE,
Block = c.VIR_STORAGE_VOL_BLOCK,
Dir = c.VIR_STORAGE_VOL_DIR,
Network = c.VIR_STORAGE_VOL_NETWORK,
Netdir = c.VIR_STORAGE_VOL_NETDIR,
Ploop = c.VIR_STORAGE_VOL_PLOOP,
Last = c.VIR_STORAGE_VOL_LAST,
};
pub const WipeAlgorithm = enum(c_uint) {
Zero = c.VIR_STORAGE_VOL_WIPE_ALG_ZERO,
Nnsa = c.VIR_STORAGE_VOL_WIPE_ALG_NNSA,
Dod = c.VIR_STORAGE_VOL_WIPE_ALG_DOD,
Bsi = c.VIR_STORAGE_VOL_WIPE_ALG_BSI,
Gutmann = c.VIR_STORAGE_VOL_WIPE_ALG_GUTMANN,
Schneier = c.VIR_STORAGE_VOL_WIPE_ALG_SHNEIER,
Pfitzner7 = c.VIR_STORAGE_VOL_WIPE_ALG_PFITZNER7,
Pfitzner33 = c.VIR_STORAGE_VOL_WIPE_ALG_PFITZNER33,
Random = c.VIR_STORAGE_VOL_WIPE_ALG_RANDOM,
Trim = c.VIR_STORAGE_VOL_WIPE_ALG_TRIM,
Last = c.VIR_STORAGE_VOL_WIPE_ALG_LAST,
};
// pub const VolumeIterator = Iterator(Volume, c.virStorageVolPtr, c.virStorageVolFree);

View file

@ -1,13 +0,0 @@
const std = @import("std");
const mem = std.mem;
const heap = std.heap;
const h = @import("libvirt-helper.zig");
const err = @import("libvirt-error.zig");
pub const String = h.String;
pub const Error = err.VirError;
pub const Connection = @import("libvirt-connection.zig");
pub const Pool = @import("libvirt-pool.zig");
pub const Domain = @import("libvirt-domain.zig");

View file

@ -3,7 +3,7 @@ const process = std.process;
const heap = std.heap;
const mem = std.mem;
const fs = std.fs;
const libvirt = @import("libvirt.zig");
const libvirt = @import("libvirt");
pub fn main() !void {
var arena = heap.ArenaAllocator.init(heap.raw_c_allocator);
@ -13,30 +13,30 @@ pub fn main() !void {
const connection = try libvirt.Connection.init("qemu:///system", allocator);
defer connection.deinit();
var flake_dir = try fs.cwd().openDir("flakes/windows/test", .{});
defer flake_dir.close();
// var flake_dir = try fs.cwd().openDir("flakes/windows/test", .{});
// defer flake_dir.close();
var nix = process.Child.init(&[_][]const u8{ "nix", "build", ".#volume", "-o", "volume" }, allocator);
nix.cwd_dir = flake_dir;
// _ = try nix.spawnAndWait();
nix.argv = &[_][]const u8{ "nix", "build", ".#beforeInstall", "-o", "beforeInstall" };
// _ = try nix.spawnAndWait();
nix.argv = &[_][]const u8{ "nix", "build", ".#afterInstall", "-o", "afterInstall" };
// _ = try nix.spawnAndWait();
nix.argv = &[_][]const u8{ "nix", "build", ".#beforeBoot", "-o", "beforeBoot" };
// _ = try nix.spawnAndWait();
nix.argv = &[_][]const u8{ "nix", "build", ".#afterBoot", "-o", "afterBoot" };
// _ = try nix.spawnAndWait();
// var nix = process.Child.init(&[_][]const u8{ "nix", "build", ".#volume", "-o", "volume" }, allocator);
// nix.cwd_dir = flake_dir;
// // _ = try nix.spawnAndWait();
// nix.argv = &[_][]const u8{ "nix", "build", ".#beforeInstall", "-o", "beforeInstall" };
// // _ = try nix.spawnAndWait();
// nix.argv = &[_][]const u8{ "nix", "build", ".#afterInstall", "-o", "afterInstall" };
// // _ = try nix.spawnAndWait();
// nix.argv = &[_][]const u8{ "nix", "build", ".#beforeBoot", "-o", "beforeBoot" };
// // _ = try nix.spawnAndWait();
// nix.argv = &[_][]const u8{ "nix", "build", ".#afterBoot", "-o", "afterBoot" };
// // _ = try nix.spawnAndWait();
const volume_def = try flake_dir.openFile("volume", .{});
defer volume_def.close();
const volume_xml = try volume_def.readToEndAlloc(allocator, 1024 * 1024);
defer allocator.free(volume_xml);
// const volume_def = try flake_dir.openFile("volume", .{});
// defer volume_def.close();
// const volume_xml = try volume_def.readToEndAlloc(allocator, 1024 * 1024);
// defer allocator.free(volume_xml);
const domain_beforeinstall_def = try flake_dir.openFile("beforeInstall", .{});
defer domain_beforeinstall_def.close();
const domain_beforeinstall_xml = try domain_beforeinstall_def.readToEndAlloc(allocator, 1024 * 1024 * 1024);
defer allocator.free(domain_beforeinstall_xml);
// const domain_beforeinstall_def = try flake_dir.openFile("beforeInstall", .{});
// defer domain_beforeinstall_def.close();
// const domain_beforeinstall_xml = try domain_beforeinstall_def.readToEndAlloc(allocator, 1024 * 1024 * 1024);
// defer allocator.free(domain_beforeinstall_xml);
// --------------
@ -44,54 +44,54 @@ pub fn main() !void {
defer connection.freeURI(uri);
std.debug.print("uri: {s}\n", .{uri});
const num_active = try connection.numOfDomains();
const num_inactive = try connection.numOfDefinedDomains();
std.debug.print("active: {d}, inactive: {d}\n", .{ num_active, num_inactive });
_ = .{ num_active, num_inactive };
// const num_active = try connection.numOfDomains();
// const num_inactive = try connection.numOfDefinedDomains();
// std.debug.print("active: {d}, inactive: {d}\n", .{ num_active, num_inactive });
// _ = .{ num_active, num_inactive };
const domains = try connection.domains();
defer connection.freeDomains(domains);
for (domains) |domain| {
defer domain.free() catch @panic("domain free fail");
const active = try domain.isActive();
const name = try domain.getName();
std.debug.print("domain name: {s}, active: {any}\n", .{ name, active });
}
var domain_it = try connection.iterateDomains();
defer domain_it.deinit();
while (domain_it.next()) |domain| {
const active = try domain.isActive();
const name = try domain.getName();
std.debug.print("domain name: {s}, active: {any}\n", .{ name, active });
}
// var domain_iter = try connection.iterateDomains(&[_]libvirt.Domain.ListFlags{
// libvirt.Domain.ListFlags.Active,
// libvirt.Domain.ListFlags.Inactive,
// });
// defer domain_iter.deinit();
// while (domain_iter.next()) |domain| {
// const active = domain.isActive();
// const name = domain.getName();
// // std.debug.print("name: {s}, active: {any}\n", .{ name, active });
// _ = .{ name, active };
// const domains = try connection.domains();
// defer connection.freeDomains(domains);
// for (domains) |domain| {
// defer domain.free() catch @panic("domain free fail");
// const active = try domain.isActive();
// const name = try domain.getName();
// std.debug.print("domain name: {s}, active: {any}\n", .{ name, active });
// }
const pools = try connection.pools();
defer connection.freePools(pools);
for (pools) |pool| {
defer pool.free() catch @panic("pool free fail");
const name = try pool.getName();
std.debug.print("pool name {s}\n", .{name});
// var domain_it = try connection.iterateDomains();
// defer domain_it.deinit();
// while (domain_it.next()) |domain| {
// const active = try domain.isActive();
// const name = try domain.getName();
// std.debug.print("domain name: {s}, active: {any}\n", .{ name, active });
// }
// if (mem.eql(u8, name, "default")) {
// const vol = try pool.createVolumeXML(xml, &[_]libvirt.Volume.CreateFlags{});
// _ = vol;
// break;
// }
}
// // var domain_iter = try connection.iterateDomains(&[_]libvirt.Domain.ListFlags{
// // libvirt.Domain.ListFlags.Active,
// // libvirt.Domain.ListFlags.Inactive,
// // });
// // defer domain_iter.deinit();
// // while (domain_iter.next()) |domain| {
// // const active = domain.isActive();
// // const name = domain.getName();
// // // std.debug.print("name: {s}, active: {any}\n", .{ name, active });
// // _ = .{ name, active };
// // }
// const pools = try connection.pools();
// defer connection.freePools(pools);
// for (pools) |pool| {
// defer pool.free() catch @panic("pool free fail");
// const name = try pool.getName();
// std.debug.print("pool name {s}\n", .{name});
// if (mem.eql(u8, name, "default")) {
// const vol = try pool.createVolumeXML(xml, &[_]libvirt.Volume.CreateFlags{});
// _ = vol;
// break;
// }
// }
// var pool_iter = try connection.iteratePools(&[_]libvirt.Pool.ListFlags{
// libvirt.Pool.ListFlags.Active,