pojntfx / go-nbd

Pure Go NBD server and client library.
Apache License 2.0
353 stars 18 forks source link

Map empty string export name to default #9

Open rwmjones opened 7 months ago

rwmjones commented 7 months ago

The NBD protocol says ...

A special, "empty", name (i.e., the length field is zero and no name is specified), is reserved for a "default" export, to be used in cases where explicitly specifying an export name makes no sense.

I notice that this server doesn't seem to do this:

$ nbdinfo nbd://localhost/
nbdinfo: nbd_opt_go: server replied with error to opt_go request: No such file or directory for the default export
nbdinfo: suggestion: to list all exports on the server, use --list
protocol: newstyle-fixed without TLS, using simple packets

Using --list shows that there is one export literally called default:

$ nbdinfo --list nbd://localhost
protocol: newstyle-fixed without TLS, using simple packets
export="default":
    export-size: 1073741824 (1G)
    uri: nbd://localhost:10809/default
    is_rotational: false
    is_read_only: false
    can_block_status_payload: false
    can_cache: false
    can_df: false
    can_fast_zero: false
    can_flush: false
    can_fua: false
    can_multi_conn: true
    can_trim: false
    can_zero: false
    block_size_minimum: 1
    block_size_preferred: 4096 (4K)
    block_size_maximum: 4294967295

I would suggest mapping the empty string to default export as per the specification.

rwmjones commented 7 months ago

Actually the server supports multiple exports: https://github.com/pojntfx/go-nbd/blob/b9d19c256a0369ed074eaa18121bdf2eea9534d0/pkg/server/nbd.go#L41

Maybe provide a way for one of them to be flagged as the default export; or choose the first in the list as the default?

(Adding @ebblake)

pojntfx commented 3 months ago

Interesting; would simply using an empty string as the export name effectively make that export the default as per the specification?