package nbd

  1. Overview
  2. Docs

A Server allows you to expose an existing block device to remote clients over NBD.

type t

An open connection to an NBD client

type size = int64

The size of a remote disk

type name = string

The name of an export. In the 'new style' protocol as used in nbd >= 2.9.17 the client must select an export by name.

exception Client_requested_abort

The client terminated the option haggling phase by sending NBD_OPT_ABORT

val connect : Channel.cleartext_channel -> ?offer:name list -> unit -> (name * t) Lwt.t

connect cleartext_channel ?offer () performs the 'new style' initial handshake and options negotiation. Note that FORCEDTLS mode will be used in the negotiation unless cleartext_channel.make_tls_channel is None, signifying NOTLS mode. If ?offer is provided then these names will be returned if the client requests a list of exports, otherwise we will return EPERM. The client's choice of name is returned which must be looked up by the application. If the name is invalid, the only option is to close the connection. If the name is valid then use the serve function.

Raises Client_requested_abort if the client aborts the option haggilng phase instead of entering the transmission phase

val serve : t -> ?read_only:bool -> (module Mirage_block_lwt.S with type t = 'b) -> 'b -> unit Lwt.t

serve t read_only block b runs forever processing requests from t, using block device type b. If read_only is true, which is the default, the block device b is served in read-only mode: the server will set the NBD_FLAG_READ_ONLY transmission flag, and if the client issues a write command, the server will send an EPERM error to the client and will terminate the session.

val close : t -> unit Lwt.t

close t shuts down the connection t and frees any allocated resources

val with_connection : Channel.cleartext_channel -> ?offer:name list -> (string -> t -> unit Lwt.t) -> unit Lwt.t

with_connection clearchan ~offer f calls connect clearchan ~offer and attempts to apply f to the resulting t, with a guarantee to call close t afterwards.

OCaml

Innovation. Community. Security.