Skip to content

Commit f58348c

Browse files
committed
nvme-cmds: move nvme_ns_detach/attach_ctrl to nvme-cli
Move these trivial functions to nvme-cli. Since they had to be modified recently due to the I/O Submission Handling (ISH) bit, it is better to move them out of the library to simplify maintaining a stable API. Signed-off-by: Daniel Wagner <[email protected]>
1 parent e949369 commit f58348c

5 files changed

Lines changed: 78 additions & 63 deletions

File tree

libnvme/src/nvme/cmds.c

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -303,36 +303,6 @@ int nvme_get_lba_status_log(struct nvme_transport_handle *hdl, bool rae,
303303
return 0;
304304
}
305305

306-
static int nvme_ns_attachment(struct nvme_transport_handle *hdl, bool ish,
307-
__u32 nsid, __u16 num_ctrls, __u16 *ctrlist, bool attach)
308-
{
309-
struct nvme_ctrl_list cntlist = { 0 };
310-
struct nvme_passthru_cmd cmd;
311-
312-
nvme_init_ctrl_list(&cntlist, num_ctrls, ctrlist);
313-
if (ish && nvme_transport_handle_is_mi(hdl))
314-
nvme_init_mi_cmd_flags(&cmd, ish);
315-
316-
if (attach)
317-
nvme_init_ns_attach_ctrls(&cmd, nsid, &cntlist);
318-
else
319-
nvme_init_ns_detach_ctrls(&cmd, nsid, &cntlist);
320-
321-
return nvme_submit_admin_passthru(hdl, &cmd);
322-
}
323-
324-
int nvme_namespace_attach_ctrls(struct nvme_transport_handle *hdl, bool ish,
325-
__u32 nsid, __u16 num_ctrls, __u16 *ctrlist)
326-
{
327-
return nvme_ns_attachment(hdl, ish, nsid, num_ctrls, ctrlist, true);
328-
}
329-
330-
int nvme_namespace_detach_ctrls(struct nvme_transport_handle *hdl, bool ish,
331-
__u32 nsid, __u16 num_ctrls, __u16 *ctrlist)
332-
{
333-
return nvme_ns_attachment(hdl, ish, nsid, num_ctrls, ctrlist, false);
334-
}
335-
336306
size_t nvme_get_ana_log_len_from_id_ctrl(const struct nvme_id_ctrl *id_ctrl,
337307
bool rgo)
338308
{

libnvme/src/nvme/cmds.h

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5568,34 +5568,6 @@ int nvme_get_logical_block_size(struct nvme_transport_handle *hdl, __u32 nsid,
55685568
int nvme_get_lba_status_log(struct nvme_transport_handle *hdl, bool rae,
55695569
struct nvme_lba_status_log **log);
55705570

5571-
/**
5572-
* nvme_namespace_attach_ctrls() - Attach namespace to controller(s)
5573-
* @hdl: Transport handle
5574-
* @ish: Ignore Shutdown (for NVMe-MI command)
5575-
* @nsid: Namespace ID to attach
5576-
* @num_ctrls: Number of controllers in ctrlist
5577-
* @ctrlist: List of controller IDs to perform the attach action
5578-
*
5579-
* Return: 0 on success, the nvme command status if a response was
5580-
* received (see &enum nvme_status_field) or a negative error otherwise.
5581-
*/
5582-
int nvme_namespace_attach_ctrls(struct nvme_transport_handle *hdl, bool ish,
5583-
__u32 nsid, __u16 num_ctrls, __u16 *ctrlist);
5584-
5585-
/**
5586-
* nvme_namespace_detach_ctrls() - Detach namespace from controller(s)
5587-
* @hdl: Transport handle
5588-
* @ish: Ignore Shutdown (for NVMe-MI command)
5589-
* @nsid: Namespace ID to detach
5590-
* @num_ctrls: Number of controllers in ctrlist
5591-
* @ctrlist: List of controller IDs to perform the detach action
5592-
*
5593-
* Return: 0 on success, the nvme command status if a response was
5594-
* received (see &enum nvme_status_field) or a negative error otherwise.
5595-
*/
5596-
int nvme_namespace_detach_ctrls(struct nvme_transport_handle *hdl, bool ish,
5597-
__u32 nsid, __u16 num_ctrls, __u16 *ctrlist);
5598-
55995571
/**
56005572
* nvme_get_feature_length() - Retrieve the command payload length for a
56015573
* specific feature identifier

meson.build

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -472,15 +472,16 @@ if want_nvme
472472
subdir('util') # declares: util_sources
473473

474474
sources = [
475-
'nvme.c',
475+
'libnvme-wrap.c',
476+
'logging.c',
477+
'nvme-cmds.c',
476478
'nvme-models.c',
477-
'nvme-print.c',
478-
'nvme-print-stdout.c',
479479
'nvme-print-binary.c',
480+
'nvme-print-stdout.c',
481+
'nvme-print.c',
480482
'nvme-rpmb.c',
483+
'nvme.c',
481484
'plugin.c',
482-
'libnvme-wrap.c',
483-
'logging.c',
484485
]
485486
if want_fabrics
486487
sources += 'fabrics.c'

nvme-cmds.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// SPDX-License-Identifier: LGPL-2.1-or-later
2+
/*
3+
* This file is part of libnvme.
4+
* Copyright (c) 2020 Western Digital Corporation or its affiliates.
5+
*
6+
* Authors: Keith Busch <[email protected]>
7+
* Chaitanya Kulkarni <[email protected]>
8+
*/
9+
10+
#include <libnvme.h>
11+
12+
#include "nvme-cmds.h"
13+
14+
static int nvme_ns_attachment(struct nvme_transport_handle *hdl, bool ish,
15+
__u32 nsid, __u16 num_ctrls, __u16 *ctrlist, bool attach)
16+
{
17+
struct nvme_ctrl_list cntlist = { 0 };
18+
struct nvme_passthru_cmd cmd;
19+
20+
nvme_init_ctrl_list(&cntlist, num_ctrls, ctrlist);
21+
if (ish && nvme_transport_handle_is_mi(hdl))
22+
nvme_init_mi_cmd_flags(&cmd, ish);
23+
24+
if (attach)
25+
nvme_init_ns_attach_ctrls(&cmd, nsid, &cntlist);
26+
else
27+
nvme_init_ns_detach_ctrls(&cmd, nsid, &cntlist);
28+
29+
return nvme_submit_admin_passthru(hdl, &cmd);
30+
}
31+
32+
int nvme_namespace_attach_ctrls(struct nvme_transport_handle *hdl, bool ish,
33+
__u32 nsid, __u16 num_ctrls, __u16 *ctrlist)
34+
{
35+
return nvme_ns_attachment(hdl, ish, nsid, num_ctrls, ctrlist, true);
36+
}
37+
38+
int nvme_namespace_detach_ctrls(struct nvme_transport_handle *hdl, bool ish,
39+
__u32 nsid, __u16 num_ctrls, __u16 *ctrlist)
40+
{
41+
return nvme_ns_attachment(hdl, ish, nsid, num_ctrls, ctrlist, false);
42+
}
43+
44+

nvme-cmds.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1717,5 +1717,33 @@ nvme_get_features_simple(struct nvme_transport_handle *hdl, __u8 fid,
17171717
return err;
17181718
}
17191719

1720+
/**
1721+
* nvme_namespace_attach_ctrls() - Attach namespace to controller(s)
1722+
* @hdl: Transport handle
1723+
* @ish: Ignore Shutdown (for NVMe-MI command)
1724+
* @nsid: Namespace ID to attach
1725+
* @num_ctrls: Number of controllers in ctrlist
1726+
* @ctrlist: List of controller IDs to perform the attach action
1727+
*
1728+
* Return: 0 on success, the nvme command status if a response was
1729+
* received (see &enum nvme_status_field) or a negative error otherwise.
1730+
*/
1731+
int nvme_namespace_attach_ctrls(struct nvme_transport_handle *hdl, bool ish,
1732+
__u32 nsid, __u16 num_ctrls, __u16 *ctrlist);
1733+
1734+
/**
1735+
* nvme_namespace_detach_ctrls() - Detach namespace from controller(s)
1736+
* @hdl: Transport handle
1737+
* @ish: Ignore Shutdown (for NVMe-MI command)
1738+
* @nsid: Namespace ID to detach
1739+
* @num_ctrls: Number of controllers in ctrlist
1740+
* @ctrlist: List of controller IDs to perform the detach action
1741+
*
1742+
* Return: 0 on success, the nvme command status if a response was
1743+
* received (see &enum nvme_status_field) or a negative error otherwise.
1744+
*/
1745+
int nvme_namespace_detach_ctrls(struct nvme_transport_handle *hdl, bool ish,
1746+
__u32 nsid, __u16 num_ctrls, __u16 *ctrlist);
1747+
17201748

17211749
#endif /* NVME_CMDS */

0 commit comments

Comments
 (0)