Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dop251/nbd
Linux NBD Go library
https://github.com/dop251/nbd
Last synced: 3 months ago
JSON representation
Linux NBD Go library
- Host: GitHub
- URL: https://github.com/dop251/nbd
- Owner: dop251
- License: mit
- Created: 2017-09-16T12:59:15.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-01-18T18:24:45.000Z (almost 2 years ago)
- Last Synced: 2024-06-21T20:01:44.726Z (6 months ago)
- Language: Go
- Size: 8.79 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Go library for Linux NBD support.
It includes an implementation of a server connection handler and a client side connector.
Note that negotiation is out of the scope, the connection needs to be fully configured by the time
the handler starts.It is currently used for a [BUSE](https://github.com/dop251/buse), but can be also used as a foundation for a
full-fledged server and client implementation.## Usage
### Server
```go
package mainimport (
"net"
"os""github.com/dop251/nbd"
)func SimpleServer(listener net.Listener, filepath string) error {
f, err := os.OpenFile(filepath, os.O_RDWR, 0600)
if err != nil {
return err
}// We want to use a shared process pool for all connections. This ensures no
// more than 4 requests are being served at any given time.
pool := nbd.NewProcPool(4)for {
conn, err := listener.Accept()
if err != nil {
return err
}
go func() {
dev := nbd.NewServerConn(conn, f)
dev.SetPool(pool)
dev.Serve()
}()
}}
```### Client
```go
package mainimport (
"github.com/dop251/nbd"
)client := nbd.NewClient("/dev/nbd0", fd, devsize)
client.SetSendFlush(true)
client.SetSendTrim(true)client.Run()
```