Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fabrics: Simple URI parser #820

Merged
merged 3 commits into from
May 15, 2024
Merged

fabrics: Simple URI parser #820

merged 3 commits into from
May 15, 2024

Conversation

tbzatek
Copy link
Contributor

@tbzatek tbzatek commented Apr 24, 2024

This is an initial implementation for a simple URI parser. Described in NVM Express Boot Specification (TP8012), used in struct nbft_info_discovery as a composite connection string, as opposed e.g. to separate struct fields in struct nbft_info_subsystem_ns.

Open questions/TODO:

  • handle escaped ("percent-encoded") sequences
  • any UTF-8 related tasks? (can't think of any right now)
  • handle query
  • handle fragment
  • handle username + password

i.e. as defined in RFC 3986:

      URI         = scheme ":" hier-part [ "?" query ] [ "#" fragment ]

         foo://example.com:8042/over/there?name=ferret#nose
         \_/   \______________/\_________/ \_________/ \__/
          |           |            |            |        |
       scheme     authority       path        query   fragment

Applied to NVMe:

nvme+tcp://user:pass@host:port/subsys_nqn/nid?name=ferret#nose

Since the above tasks may involve struct nvme_fabrics_uri element changes, marking as WIP, seeking initial feedback. Any other possible elements to extract that I missed?

@tbzatek tbzatek force-pushed the uriparser-1 branch 2 times, most recently from 1028d7b to 4055d3a Compare May 6, 2024 16:14
tbzatek added 2 commits May 13, 2024 17:41
A very simple URI parser implementing URI syntax described
in the Boot Specification, rev. 1.0.

Signed-off-by: Tomas Bzatek <tbzatek@redhat.com>
Simple testcase both for valid and malformed URI strings.

Signed-off-by: Tomas Bzatek <tbzatek@redhat.com>
@tbzatek tbzatek marked this pull request as ready for review May 13, 2024 15:41
This adds support for unescaping percent-encoded URI parts.

Signed-off-by: Tomas Bzatek <tbzatek@redhat.com>
@tbzatek tbzatek changed the title [WIP] fabrics: Simple URI parser fabrics: Simple URI parser May 13, 2024
@tbzatek
Copy link
Contributor Author

tbzatek commented May 13, 2024

I think this is ready for review.

@tbzatek
Copy link
Contributor Author

tbzatek commented May 15, 2024

As a side note - while this work was initiated by the need from the NVM Express Boot Specification, I believe this libnvme URI parser could serve more general needs. There's simply so much potential in using URI as an alternative to the usual set of parameters. Perhaps more attractive to high-level/end-user-facing tools than low-level tools like nvme-cli. What about nvme-stas, any plans for using URIs, @martin-belanger ?

I haven't noticed any other mention elsewhere than in the Boot Specification. My primary concern is whether this API is universal enough before it's released and frozen. Alternatively, this might be moved into nvme-cli as a private API for nbft.c before it's mature enough.

@martin-belanger
Copy link
Contributor

What about nvme-stas, any plans for using URIs, @martin-belanger ?

Hi @tbzatek - nvme-stas currently supports URIs read from NBFT records. We convert URIs into the familiar transport, traddr, and trsvcid parameters needed by libnvme. Since nvme-stas is written in Python, I was able to simply use the function urllib.parse.urlparse() without having to write my own URI parser.

Ref: https://github.com/linux-nvme/nvme-stas/blob/main/staslib/conf.py#L804

@tbzatek
Copy link
Contributor Author

tbzatek commented May 15, 2024

I was able to simply use the function urllib.parse.urlparse() without having to write my own URI parser.

I see, fair enough :-) I was originally considering using the uriparser C library but since it would be pulled in as dependency and we need to pack nvme-cli in initramfs, it was a no-go. Not to mention supporting old distros where we do regular rebases (RHEL 9).

@igaw
Copy link
Collaborator

igaw commented May 15, 2024

My primary concern is whether this API is universal enough before it's released and frozen

I think we start with what you came up and see how it works out. In the worst case we introduce nvme_parse_uri2

@igaw igaw merged commit 1ec2432 into linux-nvme:master May 15, 2024
13 of 14 checks passed
@igaw
Copy link
Collaborator

igaw commented May 15, 2024

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants