Skip to content

NAS-135892 / 25.10 / Allow addr_trsvcid to be None for FC transport #16506

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

Merged
merged 2 commits into from
May 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""NVMe target does not require trsvcid for FC

Revision ID: dae46dda9606
Revises: c227e49be4d8
Create Date: 2025-05-16 15:58:38.849619+00:00

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = 'dae46dda9606'
down_revision = 'c227e49be4d8'
branch_labels = None
depends_on = None


def upgrade():
with op.batch_alter_table('services_nvmet_port', schema=None) as batch_op:
batch_op.alter_column('nvmet_port_addr_trsvcid',
existing_type=sa.VARCHAR(length=255),
nullable=True)


def downgrade():
with op.batch_alter_table('services_nvmet_port', schema=None) as batch_op:
batch_op.alter_column('nvmet_port_addr_trsvcid',
existing_type=sa.VARCHAR(length=255),
nullable=False)
4 changes: 2 additions & 2 deletions src/middlewared/middlewared/api/v25_10_0/nvmet_port.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class NVMetPortEntry(BaseModel):
""" Index of the port, for internal use. """
addr_trtype: FabricTransportType
""" Fabric transport technology name. """
addr_trsvcid: int | NonEmptyString
addr_trsvcid: int | NonEmptyString | None
""" Transport-specific TRSVCID field. When configured for TCP/IP or RDMA this will be the port number. """
addr_traddr: str
"""
Expand Down Expand Up @@ -71,8 +71,8 @@ def normalize_addr_traddr(cls, value: str) -> str:

class NVMetPortCreateFC(NVMetPortCreateTemplate):
addr_trtype: Literal['FC']
addr_trsvcid: NonEmptyString
addr_traddr: NonEmptyString
addr_trsvcid: Excluded = excluded_field()


class NVMetPortCreateArgs(BaseModel):
Expand Down
19 changes: 9 additions & 10 deletions src/middlewared/middlewared/plugins/nvmet/port.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class NVMetPortModel(sa.Model):
id = sa.Column(sa.Integer(), primary_key=True)
nvmet_port_index = sa.Column(sa.Integer(), unique=True)
nvmet_port_addr_trtype = sa.Column(sa.Integer())
# addr_trsvcid port number for IPv4 | IPv6, but string for AF_IB
nvmet_port_addr_trsvcid = sa.Column(sa.String(255))
# addr_trsvcid port number for IPv4 | IPv6, but string for AF_IB, None for FC
nvmet_port_addr_trsvcid = sa.Column(sa.String(255), nullable=True, default=None)
nvmet_port_addr_traddr = sa.Column(sa.String(255))
nvmet_port_addr_adrfam = sa.Column(sa.Integer())
nvmet_port_inline_data_size = sa.Column(sa.Integer(), nullable=True, default=None)
Expand Down Expand Up @@ -265,15 +265,14 @@ async def usage(self) -> dict:
}

async def __validate(self, verrors, data, schema_name, old=None):
filters = [
['addr_trtype', '=', data['addr_trtype']],
['addr_traddr', '=', data['addr_traddr']],
]
if data['addr_trtype'] != PORT_TRTYPE.FC.api:
filters.append(['addr_trsvcid', '=', data['addr_trsvcid']])
try:
existing = await self.middleware.call('nvmet.port.query',
[
['addr_trtype', '=', data['addr_trtype']],
['addr_traddr', '=', data['addr_traddr']],
['addr_trsvcid', '=', data['addr_trsvcid']]
],
{'get': True}
)
existing = await self.middleware.call('nvmet.port.query', filters, {'get': True})
except MatchNotFound:
existing = None

Expand Down