1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::ffi::*;
use core::ptr::NonNull;
use objc2::__framework_prelude::*;
use objc2_foundation::*;
use crate::*;
extern_class!(
/// Storage device attachment backed by a Network Block Device (NBD) client.
///
/// This storage device attachment provides an NBD client implementation. The NBD client is connected
/// to an NBD server referred to by an NBD Uniform Resource Indicator (URI), represented as an URL in
/// this API. The NBD server runs outside of Virtualization framework and is not controlled by
/// Virtualization framework. The NBD client forwards the guest's I/O operations to the NBD server,
/// where the I/O operations are handled.
///
/// The NBD client will attempt to connect to the NBD server referred to by the URL when you start the virtual
/// machine (e.g. when `[VZVirtualMachine startWithCompletionHandler:]` is called). A connection attempt is NOT
/// made when the attachment object is initialized. Reconnection attempts will take place throughout the life
/// cycle of the virtual machine when the NBD client encounters a recoverable error such as connection timeout
/// and unexpected connection errors. The NBD client will disconnect from the server when the virtual machine
/// shuts down.
///
/// Using this attachment requires the app to have the "com.apple.security.network.client" entitlement as this attachment opens an outgoing
/// network connection.
///
/// For more information about NBD, see https://github.com/NetworkBlockDevice/nbd/blob/master/doc/proto.md.
/// For more information about the NBD URL format, see https://github.com/NetworkBlockDevice/nbd/blob/master/doc/uri.md.
///
/// An example use of this API is:
/// ```text
/// NSURL *url = [[NSURL alloc] initWithString:
/// "
/// nbd://localhost:10809/myDisk"]
/// NSError *error = nil;
/// VZNetworkBlockDeviceStorageDeviceAttachment *attachment =
/// [[VZNetworkBlockDeviceStorageDeviceAttachment alloc] initWithURL:url
/// timeout:5.0
/// forcedReadOnly:NO
/// synchronizationMode:VZDiskSynchronizationModeFull
/// error:
/// &error
/// ];
///
/// if (!attachment) {
/// // Handle the `error`.
/// }
///
/// VZVirtioBlockDeviceConfiguration *blockDevice = [[VZVirtioBlockDeviceConfiguration alloc] initWithAttachment:attachment];
/// ```
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/virtualization/vznetworkblockdevicestoragedeviceattachment?language=objc)
#[unsafe(super(VZStorageDeviceAttachment, NSObject))]
#[derive(Debug, PartialEq, Eq, Hash)]
#[cfg(feature = "VZStorageDeviceAttachment")]
pub struct VZNetworkBlockDeviceStorageDeviceAttachment;
);
#[cfg(feature = "VZStorageDeviceAttachment")]
extern_conformance!(
unsafe impl NSObjectProtocol for VZNetworkBlockDeviceStorageDeviceAttachment {}
);
#[cfg(feature = "VZStorageDeviceAttachment")]
impl VZNetworkBlockDeviceStorageDeviceAttachment {
extern_methods!(
#[cfg(feature = "VZDiskSynchronizationMode")]
/// Initialize the attachment from an NBD Uniform Resource Indicator (URI) represented as an URL.
///
/// Parameter `URL`: The URL referring to the NBD server to which the NBD client is to be connected.
///
/// Parameter `timeout`: The timeout value in seconds for the connection between the client and server. When the timeout expires, an attempt to reconnect with the server will take place.
///
/// Parameter `forcedReadOnly`: If YES, the disk attachment is forced to be read-only, regardless of whether or not the NBD server supports write requests.
///
/// Parameter `error`: If not nil, assigned with the error if the initialization failed.
///
/// Returns: An initialized `VZNetworkBlockDeviceStorageDeviceAttachment` or nil if there was an error.
///
/// The `forcedReadOnly` parameter affects how the NBD client is exposed to the guest operating system
/// by the storage controller. As part of the NBD protocol, whether or not the disk exposed by the NBD client is
/// read-only is advertised by the NBD server during the handshake phase of the protocol. Setting `forcedReadOnly`
/// to YES will force the NBD client to show up as read-only to the guest regardless of whether or not the NBD
/// server advertises itself as read-only.
#[unsafe(method(initWithURL:timeout:forcedReadOnly:synchronizationMode:error:_))]
#[unsafe(method_family = init)]
pub unsafe fn initWithURL_timeout_forcedReadOnly_synchronizationMode_error(
this: Allocated<Self>,
url: &NSURL,
timeout: NSTimeInterval,
forced_read_only: bool,
synchronization_mode: VZDiskSynchronizationMode,
) -> Result<Retained<Self>, Retained<NSError>>;
/// Convenience initializer to create the attachment from an NBD URL.
///
/// Parameter `URL`: The URL referring to the NBD server to which the NBD client is to be connected.
///
/// Parameter `error`: If not nil, assigned with the error if the initialization failed.
///
/// Returns: An initialized `VZNetworkBlockDeviceStorageDeviceAttachment` or nil if there was an error.
///
/// This initializer automatically assigns optimized default values for the `timeout`,
/// `forcedReadOnly`, and `synchronizationMode` properties.
#[unsafe(method(initWithURL:error:_))]
#[unsafe(method_family = init)]
pub unsafe fn initWithURL_error(
this: Allocated<Self>,
url: &NSURL,
) -> Result<Retained<Self>, Retained<NSError>>;
/// Check if URL is a valid NBD URL.
///
/// Parameter `URL`: The NBD URL to validate.
///
/// Parameter `error`: If not nil, assigned with an error describing why the URL is not valid.
///
/// See https://github.com/NetworkBlockDevice/nbd/blob/master/doc/uri.md for more detailed descriptions
/// of valid URIs.
///
/// This method checks that the URL is well-formed, it does not attempt to access the URL.
#[unsafe(method(validateURL:error:_))]
#[unsafe(method_family = none)]
pub unsafe fn validateURL_error(url: &NSURL) -> Result<(), Retained<NSError>>;
/// URL referring to the NBD server to which the NBD client is to be connected.
#[unsafe(method(URL))]
#[unsafe(method_family = none)]
pub unsafe fn URL(&self) -> Retained<NSURL>;
/// The timeout value in seconds for the connection between the client and server. When the timeout expires, an attempt to reconnect with the server will take place.
#[unsafe(method(timeout))]
#[unsafe(method_family = none)]
pub unsafe fn timeout(&self) -> NSTimeInterval;
/// Whether the underlying disk attachment is forced to be read-only.
///
/// The `forcedReadOnly` parameter affects how the NBD client is exposed to the guest operating system
/// by the storage controller. As part of the NBD protocol, whether or not the disk exposed by the NBD client
/// is read-only is advertised by the NBD server during the handshake phase of the protocol. Setting
/// `forcedReadOnly` to YES will force the NBD client to show up as read-only to the
/// guest regardless of whether or not the NBD server advertises itself as read-only.
#[unsafe(method(isForcedReadOnly))]
#[unsafe(method_family = none)]
pub unsafe fn isForcedReadOnly(&self) -> bool;
#[cfg(feature = "VZDiskSynchronizationMode")]
/// The mode in which the NBD client synchronizes data with the NBD server.
#[unsafe(method(synchronizationMode))]
#[unsafe(method_family = none)]
pub unsafe fn synchronizationMode(&self) -> VZDiskSynchronizationMode;
/// The attachment's delegate.
#[unsafe(method(delegate))]
#[unsafe(method_family = none)]
pub unsafe fn delegate(
&self,
) -> Option<Retained<ProtocolObject<dyn VZNetworkBlockDeviceStorageDeviceAttachmentDelegate>>>;
/// Setter for [`delegate`][Self::delegate].
///
/// This is a [weak property][objc2::topics::weak_property].
#[unsafe(method(setDelegate:))]
#[unsafe(method_family = none)]
pub unsafe fn setDelegate(
&self,
delegate: Option<
&ProtocolObject<dyn VZNetworkBlockDeviceStorageDeviceAttachmentDelegate>,
>,
);
);
}
/// Methods declared on superclass `VZStorageDeviceAttachment`.
#[cfg(feature = "VZStorageDeviceAttachment")]
impl VZNetworkBlockDeviceStorageDeviceAttachment {
extern_methods!(
#[unsafe(method(new))]
#[unsafe(method_family = new)]
pub unsafe fn new() -> Retained<Self>;
#[unsafe(method(init))]
#[unsafe(method_family = init)]
pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
);
}
extern_protocol!(
/// A class conforming to VZNetworkBlockDeviceStorageDeviceAttachmentDelegate can provide
/// methods for tracking the attachment's state.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/virtualization/vznetworkblockdevicestoragedeviceattachmentdelegate?language=objc)
pub unsafe trait VZNetworkBlockDeviceStorageDeviceAttachmentDelegate:
NSObjectProtocol
{
#[cfg(feature = "VZStorageDeviceAttachment")]
/// Invoked when the NBD client has successfully connected/reconnected with the server.
///
/// Parameter `attachment`: The attachment object invoking the delegate method.
///
/// Connection with the server will take place when the virtual machine is first started, and reconnection
/// attempts will take place when the connection times out or when the NBD client has encountered a recoverable
/// error, such as an I/O error from the server. The method may be invoked multiple times during a virtual
/// machine's life cycle. Reconnections are transparent to the guest.
#[optional]
#[unsafe(method(attachmentWasConnected:))]
#[unsafe(method_family = none)]
unsafe fn attachmentWasConnected(
&self,
attachment: &VZNetworkBlockDeviceStorageDeviceAttachment,
);
#[cfg(feature = "VZStorageDeviceAttachment")]
/// Invoked when the NBD client has encountered a non-recoverable error.
///
/// Parameter `attachment`: The attachment object invoking the delegate method.
///
/// Parameter `error`: The error.
///
/// The NBD client will be in a non-functional state after this method is invoked.
#[optional]
#[unsafe(method(attachment:didEncounterError:))]
#[unsafe(method_family = none)]
unsafe fn attachment_didEncounterError(
&self,
attachment: &VZNetworkBlockDeviceStorageDeviceAttachment,
error: &NSError,
);
}
);