Skip to content

Commit 30df2e1

Browse files
committed
ioctl: Rearrange members in nvme_ns_attach_args
Avoid any holes in the struct by rearranging the members. Also add the attribute packed to struct definition to reduce ABI breakage. struct nvme_ns_attach_args { int args_size; /* 0 4 */ int fd; /* 4 4 */ __u32 * result; /* 8 8 */ __u32 timeout; /* 16 4 */ __u32 nsid; /* 20 4 */ struct nvme_ctrl_list * ctrlist; /* 24 8 */ enum nvme_ns_attach_sel sel; /* 32 4 */ /* size: 40, cachelines: 1, members: 7 */ /* padding: 4 */ /* last cacheline: 40 bytes */ } __attribute__((__aligned__(8))); While at it also introduce the result member. Signed-off-by: Daniel Wagner <[email protected]>
1 parent fe068c6 commit 30df2e1

2 files changed

Lines changed: 14 additions & 10 deletions

File tree

src/nvme/ioctl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1203,7 +1203,7 @@ int nvme_ns_attach(struct nvme_ns_attach_args *args)
12031203

12041204
if (args->args_size < sizeof(*args))
12051205
return -EINVAL;
1206-
return nvme_submit_admin_passthru(args->fd, &cmd, NULL);
1206+
return nvme_submit_admin_passthru(args->fd, &cmd, args->result);
12071207
}
12081208

12091209
int nvme_fw_download(struct nvme_fw_download_args *args)

src/nvme/ioctl.h

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2781,19 +2781,21 @@ static inline int nvme_ns_mgmt_delete(int fd, __u32 nsid)
27812781
/**
27822782
* nvme_ns_attach_args - Arguments for Nvme Namespace Management command
27832783
* @fd: File descriptor of nvme device
2784+
* @result: NVMe command result
2785+
* @timeout: Timeout in ms
27842786
* @nsid: Namespace ID to execute attach selection
2785-
* @sel: Attachment selection, see &enum nvme_ns_attach_sel
27862787
* @ctrlist: Controller list to modify attachment state of nsid
2787-
* @timeout: Timeout in ms
2788+
* @sel: Attachment selection, see &enum nvme_ns_attach_sel
27882789
*/
27892790
struct nvme_ns_attach_args {
27902791
int args_size;
27912792
int fd;
2793+
__u32 *result;
2794+
__u32 timeout;
27922795
__u32 nsid;
2793-
enum nvme_ns_attach_sel sel;
27942796
struct nvme_ctrl_list *ctrlist;
2795-
__u32 timeout;
2796-
};
2797+
enum nvme_ns_attach_sel sel;
2798+
} __attribute__((packed, aligned(__alignof__(__u32*))));
27972799

27982800
/**
27992801
* nvme_ns_attach_args - Attach or detach namespace to controller(s)
@@ -2813,10 +2815,11 @@ static inline int nvme_ns_attach_ctrls(int fd, __u32 nsid,
28132815
struct nvme_ns_attach_args args = {
28142816
.args_size = sizeof(args),
28152817
.fd = fd,
2818+
.result = NULL,
2819+
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
28162820
.nsid = nsid,
2817-
.sel = NVME_NS_ATTACH_SEL_CTRL_ATTACH,
28182821
.ctrlist = ctrlist,
2819-
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
2822+
.sel = NVME_NS_ATTACH_SEL_CTRL_ATTACH,
28202823
};
28212824

28222825
return nvme_ns_attach(&args);
@@ -2834,10 +2837,11 @@ static inline int nvme_ns_detach_ctrls(int fd, __u32 nsid,
28342837
struct nvme_ns_attach_args args = {
28352838
.args_size = sizeof(args),
28362839
.fd = fd,
2840+
.result = NULL,
2841+
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
28372842
.nsid = nsid,
2838-
.sel = NVME_NS_ATTACH_SEL_CTRL_DEATTACH,
28392843
.ctrlist = ctrlist,
2840-
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
2844+
.sel = NVME_NS_ATTACH_SEL_CTRL_DEATTACH,
28412845
};
28422846

28432847
return nvme_ns_attach(&args);

0 commit comments

Comments
 (0)