[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Standard NBD URL syntax (again)



On Wed, May 22, 2019 at 9:42 AM Wouter Verhelst <w@uter.be> wrote:
On Tue, May 21, 2019 at 10:27:01PM +0100, Richard W.M. Jones wrote:
> On Tue, May 21, 2019 at 10:30:36PM +0200, Wouter Verhelst wrote:
> > On Mon, May 20, 2019 at 10:20:56AM +0100, Richard W.M. Jones wrote:
> > > The leading problem with the "obvious" NBD URL format seems to be that
> > > it's impossible to specify empty export names or export names which
> > > don't start with a '/' character.
> >
> > Not sure? We can just define the / as a separator character, rather than
> > as part of the name. That would then result in:
> >
> > nbd://nbd-server.example.com:12345/foo
> >
> > for "the export called 'foo' at nbd-server.example.com on port 12345"
> >
> > nbd://nbd-server.example.com//foo
> >
> > for "the export called '/foo' at nbd-server.example.com on the default
> > port"
>
> This is what qemu uses, but it does seem a little awkward?  It would
> be easy to make the naive assumption that given an export called
> "/foo" you'd write the URL "nbd://server/foo".

That really depends on how you interpret the / character, but yeah,
that's possible. We'll just have to make sure to document that well,
then.

The value of using a URL is user being able to use existing URL parsers.

>>> from urllib.parse import urlparse
>>> urlparse("nbd://nbd-server.example.com:12345/foo")
ParseResult(scheme='nbd', netloc='nbd-server.example.com:12345', path='/foo', params='', query='', fragment='')
>>> urlparse("nbd://nbd-server.example.com:12345//foo")
ParseResult(scheme='nbd', netloc='nbd-server.example.com:12345', path='//foo', params='', query='', fragment='')

So users will mostly likely use //path when accessing the server with the second URL.

Multiple separator are typically normalized to single one, both in web applications
and when accessing the file system:

    >>> os.path.samefile("/tmp/file", "/tmp///file")
    True

Same behavior with:

    ls /tmp/file
    ls /tmp//file

I think that the way to think about it is that export names are always
relative to the server root, so


maps to the export name "foo" and "/foo".

And both:

mapped to the empty export name.
Nir

Reply to: