Skip to content

Commit 4202e4c

Browse files
authored
NAS-135892 / 25.10 / Allow addr_trsvcid to be None for FC transport (#16506)
1 parent adb961a commit 4202e4c

File tree

3 files changed

+41
-12
lines changed

3 files changed

+41
-12
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""NVMe target does not require trsvcid for FC
2+
3+
Revision ID: dae46dda9606
4+
Revises: c227e49be4d8
5+
Create Date: 2025-05-16 15:58:38.849619+00:00
6+
7+
"""
8+
from alembic import op
9+
import sqlalchemy as sa
10+
11+
12+
# revision identifiers, used by Alembic.
13+
revision = 'dae46dda9606'
14+
down_revision = 'c227e49be4d8'
15+
branch_labels = None
16+
depends_on = None
17+
18+
19+
def upgrade():
20+
with op.batch_alter_table('services_nvmet_port', schema=None) as batch_op:
21+
batch_op.alter_column('nvmet_port_addr_trsvcid',
22+
existing_type=sa.VARCHAR(length=255),
23+
nullable=True)
24+
25+
26+
def downgrade():
27+
with op.batch_alter_table('services_nvmet_port', schema=None) as batch_op:
28+
batch_op.alter_column('nvmet_port_addr_trsvcid',
29+
existing_type=sa.VARCHAR(length=255),
30+
nullable=False)

src/middlewared/middlewared/api/v25_10_0/nvmet_port.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class NVMetPortEntry(BaseModel):
2828
""" Index of the port, for internal use. """
2929
addr_trtype: FabricTransportType
3030
""" Fabric transport technology name. """
31-
addr_trsvcid: int | NonEmptyString
31+
addr_trsvcid: int | NonEmptyString | None
3232
""" Transport-specific TRSVCID field. When configured for TCP/IP or RDMA this will be the port number. """
3333
addr_traddr: str
3434
"""
@@ -71,8 +71,8 @@ def normalize_addr_traddr(cls, value: str) -> str:
7171

7272
class NVMetPortCreateFC(NVMetPortCreateTemplate):
7373
addr_trtype: Literal['FC']
74-
addr_trsvcid: NonEmptyString
7574
addr_traddr: NonEmptyString
75+
addr_trsvcid: Excluded = excluded_field()
7676

7777

7878
class NVMetPortCreateArgs(BaseModel):

src/middlewared/middlewared/plugins/nvmet/port.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ class NVMetPortModel(sa.Model):
2828
id = sa.Column(sa.Integer(), primary_key=True)
2929
nvmet_port_index = sa.Column(sa.Integer(), unique=True)
3030
nvmet_port_addr_trtype = sa.Column(sa.Integer())
31-
# addr_trsvcid port number for IPv4 | IPv6, but string for AF_IB
32-
nvmet_port_addr_trsvcid = sa.Column(sa.String(255))
31+
# addr_trsvcid port number for IPv4 | IPv6, but string for AF_IB, None for FC
32+
nvmet_port_addr_trsvcid = sa.Column(sa.String(255), nullable=True, default=None)
3333
nvmet_port_addr_traddr = sa.Column(sa.String(255))
3434
nvmet_port_addr_adrfam = sa.Column(sa.Integer())
3535
nvmet_port_inline_data_size = sa.Column(sa.Integer(), nullable=True, default=None)
@@ -265,15 +265,14 @@ async def usage(self) -> dict:
265265
}
266266

267267
async def __validate(self, verrors, data, schema_name, old=None):
268+
filters = [
269+
['addr_trtype', '=', data['addr_trtype']],
270+
['addr_traddr', '=', data['addr_traddr']],
271+
]
272+
if data['addr_trtype'] != PORT_TRTYPE.FC.api:
273+
filters.append(['addr_trsvcid', '=', data['addr_trsvcid']])
268274
try:
269-
existing = await self.middleware.call('nvmet.port.query',
270-
[
271-
['addr_trtype', '=', data['addr_trtype']],
272-
['addr_traddr', '=', data['addr_traddr']],
273-
['addr_trsvcid', '=', data['addr_trsvcid']]
274-
],
275-
{'get': True}
276-
)
275+
existing = await self.middleware.call('nvmet.port.query', filters, {'get': True})
277276
except MatchNotFound:
278277
existing = None
279278

0 commit comments

Comments
 (0)