tokio_nbd/
lib.rs

1//! Network Block Device (NBD) driver implementation and server functionality.
2//!
3//! This module provides core components for implementing an NBD server:
4//!
5//! - [`crate::device::NbdDriver`]: A trait for defining NBD devices
6//! - [`crate::server::NbdServer`]: A struct for handling the NBD protocol
7//!
8//! # Protocol Compliance
9//!
10//! This implementation follows the NBD protocol specification as defined at
11//! [NetworkBlockDevice/nbd](https://github.com/NetworkBlockDevice/nbd/blob/master/doc/proto.md).
12//!
13//! # Security Considerations
14//!
15//! NBD does not provide built-in authentication or encryption. For secure deployments:
16//!
17//! - Use on trusted networks only
18//! - Consider implementing TLS support (with the `START_TLS` option)
19//! - Use firewall rules to restrict access
20//!
21//! # Logging
22//!
23//! This crate uses the `tracing` crate for logging. To enable logging, you need to install
24//! a tracing subscriber. For simple usage, you can use the `init_default_tracing` function
25//! provided by this crate.
26//!
27//! ```rust,no_run
28//! tokio_nbd::init_default_tracing();
29//! ```
30//!
31//! For more advanced usage, you can use the tracing crate directly to configure logging.
32
33mod command_request;
34pub mod device;
35pub mod errors;
36pub mod flags;
37mod info;
38mod io;
39mod magic;
40mod option_reply;
41mod option_request;
42pub mod server;
43
44/// Initializes a default tracing subscriber suitable for use with tokio-nbd.
45///
46/// This sets up basic console logging with RUST_LOG environment variable support.
47/// If you want more advanced tracing configuration, you should set up your own
48/// subscriber instead.
49///
50/// # Example
51///
52/// ```rust,no_run
53/// // Initialize the default tracing subscriber at the beginning of your program
54/// tokio_nbd::init_default_tracing();
55///
56/// // Now logs from tokio-nbd will be visible
57/// ```
58pub fn init_default_tracing() {
59    let env_filter = tracing_subscriber::EnvFilter::try_from_default_env()
60        .unwrap_or_else(|_| tracing_subscriber::EnvFilter::new("tokio_nbd=info"));
61
62    tracing_subscriber::fmt()
63        .with_env_filter(env_filter)
64        .with_target(true)
65        .init();
66}