Skip to content

Commit 30672d3

Browse files
committed
libnvme/cmds: change copy desc format tags to big-endian
Change the elbt, elbat and albatm tag fields byte ordering. Signed-off-by: Tokunori Ikegami <[email protected]>
1 parent 67562fa commit 30672d3

4 files changed

Lines changed: 66 additions & 47 deletions

File tree

libnvme/src/nvme/cmds.h

Lines changed: 46 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5236,19 +5236,22 @@ nvme_init_dsm_range(struct nvme_dsm_range *dsm, __u32 *ctx_attrs,
52365236
}
52375237

52385238
/**
5239-
* nvme_init_copy_range_elbt() - Constructs a copy range elbt structure
5240-
* @elbt:
5241-
* @eilbrts: Expected initial logical block reference tag
5239+
* nvme_init_copy_range_tags() - Constructs a copy range tags structure
5240+
* @dest: Destination tag converted to big-endian
5241+
* @src: Source tag ELBT, ELBAT and ELBATM
5242+
* @size: Tag size
52425243
*/
52435244
static inline void
5244-
nvme_init_copy_range_elbt(__u8 *elbt, __u64 eilbrt)
5245+
nvme_init_copy_range_tags(__u8 *dest, __u8 *src, int size)
52455246
{
52465247
int i;
52475248

5248-
for (i = 0; i < 8; i++)
5249-
elbt[9 - i] = (eilbrt >> (8 * i)) & 0xff;
5250-
elbt[1] = 0;
5251-
elbt[0] = 0;
5249+
for (i = 0; i < size; i++)
5250+
#if __BYTE_ORDER == __LITTLE_ENDIAN
5251+
dest[size - 1 - i] = src[i];
5252+
#else /* __BYTE_ORDER == __LITTLE_ENDIAN */
5253+
dest[i] = src[i];
5254+
#endif /* __BYTE_ORDER == __LITTLE_ENDIAN */
52525255
}
52535256

52545257
/**
@@ -5263,17 +5266,20 @@ nvme_init_copy_range_elbt(__u8 *elbt, __u64 eilbrt)
52635266
*/
52645267
static inline void
52655268
nvme_init_copy_range_f0(struct nvme_copy_range_f0 *copy, __u16 *nlbs,
5266-
__u64 *slbas, __u32 *elbts, __u32 *elbatms,
5267-
__u32 *elbats, __u16 nr)
5269+
__u64 *slbas, __u32 *elbts, __u16 *elbatms,
5270+
__u16 *elbats, __u16 nr)
52685271
{
52695272
int i;
52705273

52715274
for (i = 0; i < nr; i++) {
52725275
copy[i].nlb = htole16(nlbs[i]);
52735276
copy[i].slba = htole64(slbas[i]);
5274-
copy[i].elbt = htole32(elbts[i]);
5275-
copy[i].elbatm = htole16(elbatms[i]);
5276-
copy[i].elbat = htole16(elbats[i]);
5277+
nvme_init_copy_range_tags(copy[i].elbt, (__u8 *)&elbts[i],
5278+
sizeof(elbts[i]));
5279+
nvme_init_copy_range_tags(copy[i].elbatm, (__u8 *)&elbatms[i],
5280+
sizeof(copy[i].elbatm));
5281+
nvme_init_copy_range_tags(copy[i].elbat, (__u8 *)&elbats[i],
5282+
sizeof(copy[i].elbat));
52775283
}
52785284
}
52795285

@@ -5289,17 +5295,22 @@ nvme_init_copy_range_f0(struct nvme_copy_range_f0 *copy, __u16 *nlbs,
52895295
*/
52905296
static inline void
52915297
nvme_init_copy_range_f1(struct nvme_copy_range_f1 *copy, __u16 *nlbs,
5292-
__u64 *slbas, __u64 *eilbrts, __u32 *elbatms,
5293-
__u32 *elbats, __u16 nr)
5298+
__u64 *slbas, __u64 *eilbrts, __u16 *elbatms,
5299+
__u16 *elbats, __u16 nr)
52945300
{
52955301
int i;
52965302

5303+
memset(copy, 0, sizeof(*copy) * nr);
5304+
52975305
for (i = 0; i < nr; i++) {
52985306
copy[i].nlb = htole16(nlbs[i]);
52995307
copy[i].slba = htole64(slbas[i]);
5300-
copy[i].elbatm = htole16(elbatms[i]);
5301-
copy[i].elbat = htole16(elbats[i]);
5302-
nvme_init_copy_range_elbt(copy[i].elbt, eilbrts[i]);
5308+
nvme_init_copy_range_tags(&copy[i].elbt[2], (__u8 *)&eilbrts[i],
5309+
sizeof(eilbrts[i]));
5310+
nvme_init_copy_range_tags(copy[i].elbatm, (__u8 *)&elbatms[i],
5311+
sizeof(copy[i].elbatm));
5312+
nvme_init_copy_range_tags(copy[i].elbat, (__u8 *)&elbats[i],
5313+
sizeof(copy[i].elbat));
53035314
}
53045315
}
53055316

@@ -5310,15 +5321,15 @@ nvme_init_copy_range_f1(struct nvme_copy_range_f1 *copy, __u16 *nlbs,
53105321
* @nlbs: Number of logical blocks
53115322
* @slbas: Starting LBA
53125323
* @sopts: Source options
5313-
* @eilbrts: Expected initial logical block reference tag
5324+
* @elbts: Expected initial logical block reference tag
53145325
* @elbatms: Expected logical block application tag mask
53155326
* @elbats: Expected logical block application tag
53165327
* @nr: Number of descriptors to construct
53175328
*/
53185329
static inline void
53195330
nvme_init_copy_range_f2(struct nvme_copy_range_f2 *copy,
53205331
__u32 *snsids, __u16 *nlbs, __u64 *slbas, __u16 *sopts,
5321-
__u32 *eilbrts, __u32 *elbatms, __u32 *elbats,
5332+
__u32 *elbts, __u16 *elbatms, __u16 *elbats,
53225333
__u16 nr)
53235334
{
53245335
int i;
@@ -5328,9 +5339,12 @@ nvme_init_copy_range_f2(struct nvme_copy_range_f2 *copy,
53285339
copy[i].nlb = htole16(nlbs[i]);
53295340
copy[i].slba = htole64(slbas[i]);
53305341
copy[i].sopt = htole16(sopts[i]);
5331-
copy[i].eilbrt = htole32(eilbrts[i]);
5332-
copy[i].elbatm = htole16(elbatms[i]);
5333-
copy[i].elbat = htole16(elbats[i]);
5342+
nvme_init_copy_range_tags(copy[i].elbt, (__u8 *)&elbts[i],
5343+
sizeof(elbts[i]));
5344+
nvme_init_copy_range_tags(copy[i].elbatm, (__u8 *)&elbatms[i],
5345+
sizeof(copy[i].elbatm));
5346+
nvme_init_copy_range_tags(copy[i].elbat, (__u8 *)&elbats[i],
5347+
sizeof(copy[i].elbat));
53345348
}
53355349
}
53365350

@@ -5349,19 +5363,24 @@ nvme_init_copy_range_f2(struct nvme_copy_range_f2 *copy,
53495363
static inline void
53505364
nvme_init_copy_range_f3(struct nvme_copy_range_f3 *copy, __u32 *snsids,
53515365
__u16 *nlbs, __u64 *slbas, __u16 *sopts,
5352-
__u64 *eilbrts, __u32 *elbatms, __u32 *elbats,
5366+
__u64 *eilbrts, __u16 *elbatms, __u16 *elbats,
53535367
__u16 nr)
53545368
{
53555369
int i;
53565370

5371+
memset(copy, 0, sizeof(*copy) * nr);
5372+
53575373
for (i = 0; i < nr; i++) {
53585374
copy[i].snsid = htole32(snsids[i]);
53595375
copy[i].nlb = htole16(nlbs[i]);
53605376
copy[i].slba = htole64(slbas[i]);
53615377
copy[i].sopt = htole16(sopts[i]);
5362-
copy[i].elbatm = htole16(elbatms[i]);
5363-
copy[i].elbat = htole16(elbats[i]);
5364-
nvme_init_copy_range_elbt(copy[i].elbt, eilbrts[i]);
5378+
nvme_init_copy_range_tags(&copy[i].elbt[2], (__u8 *)&eilbrts[i],
5379+
sizeof(eilbrts[i]));
5380+
nvme_init_copy_range_tags(copy[i].elbatm, (__u8 *)&elbatms[i],
5381+
sizeof(copy[i].elbatm));
5382+
nvme_init_copy_range_tags(copy[i].elbat, (__u8 *)&elbats[i],
5383+
sizeof(copy[i].elbat));
53655384
}
53665385
}
53675386

libnvme/src/nvme/types.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6457,9 +6457,9 @@ struct nvme_copy_range_f0 {
64576457
__u8 rsvd19;
64586458
__le16 cev;
64596459
__u8 rsvd22[2];
6460-
__le32 elbt;
6461-
__le16 elbat;
6462-
__le16 elbatm;
6460+
__u8 elbt[4];
6461+
__u8 elbat[2];
6462+
__u8 elbatm[2];
64636463
};
64646464

64656465
/**
@@ -6485,8 +6485,8 @@ struct nvme_copy_range_f1 {
64856485
__le16 cev;
64866486
__u8 rsvd22[4];
64876487
__u8 elbt[10];
6488-
__le16 elbat;
6489-
__le16 elbatm;
6488+
__u8 elbat[2];
6489+
__u8 elbatm[2];
64906490
};
64916491

64926492
/**
@@ -6507,7 +6507,7 @@ enum nvme_copy_range_sopt {
65076507
* @rsvd19: Reserved
65086508
* @cev: Command Extension Value
65096509
* @sopt: Source Options
6510-
* @eilbrt: Expected Initial Logical Block Reference Tag /
6510+
* @elbt: Expected Initial Logical Block Reference Tag /
65116511
* Expected Logical Block Storage Tag
65126512
* @elbatm: Expected Logical Block Application Tag Mask
65136513
* @elbat: Expected Logical Block Application Tag
@@ -6521,9 +6521,9 @@ struct nvme_copy_range_f2 {
65216521
__u8 rsvd19;
65226522
__le16 cev;
65236523
__le16 sopt;
6524-
__le32 eilbrt;
6525-
__le16 elbat;
6526-
__le16 elbatm;
6524+
__u8 elbt[4];
6525+
__u8 elbat[2];
6526+
__u8 elbatm[2];
65276527
};
65286528

65296529
/**
@@ -6553,8 +6553,8 @@ struct nvme_copy_range_f3 {
65536553
__le16 sopt;
65546554
__u8 rsvd24[2];
65556555
__u8 elbt[10];
6556-
__le16 elbat;
6557-
__le16 elbatm;
6556+
__u8 elbat[2];
6557+
__u8 elbatm[2];
65586558
};
65596559

65606560
/**

libnvme/test/ioctl/misc.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -991,15 +991,15 @@ static void test_copy(void)
991991
__u16 nlbs[TEST_COPY_NR] = { 0xa, 0xb, 0xc };
992992
__u64 slbas[TEST_COPY_NR] = { 0x1000, 0x20000000, 0x300040000000 };
993993
__u32 short_pi[TEST_COPY_NR] = { 0x1000, 0x20000000, 0x40000000 };
994-
__u32 elbatms[TEST_COPY_NR] = { 0x1ff, 0x3ff, 0x3ff };
995-
__u32 elbats[TEST_COPY_NR] = { 0x111, 0x222, 0x333 };
994+
__u16 elbatms[TEST_COPY_NR] = { 0x1ff, 0x3ff, 0x3ff };
995+
__u16 elbats[TEST_COPY_NR] = { 0x111, 0x222, 0x333 };
996996
__u8 expected_data[sizeof(struct nvme_copy_range_f0) * TEST_COPY_NR] = {
997997
0, 0, 0, 0, 0, 0, 0, 0, 0, 0x10, 0, 0, 0, 0, 0, 0,
998-
0xa, 0, 0, 0, 0, 0, 0, 0, 0, 0x10, 0, 0, 0x11, 1, 0xff, 1,
998+
0xa, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x10, 0, 1, 0x11, 1, 0xff,
999999
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x20, 0, 0, 0, 0,
1000-
0xb, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x20, 0x22, 2, 0xff, 3,
1000+
0xb, 0, 0, 0, 0, 0, 0, 0, 0x20, 0, 0, 0, 2, 0x22, 3, 0xff,
10011001
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x40, 0, 0x30, 0, 0,
1002-
0xc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x40, 0x33, 3, 0xff, 3
1002+
0xc, 0, 0, 0, 0, 0, 0, 0, 0x40, 0, 0, 0, 3, 0x33, 3, 0xff
10031003
};
10041004

10051005
_cleanup_free_ struct nvme_copy_range_f0 *copy = NULL;

nvme.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7766,8 +7766,8 @@ static int copy_cmd(int argc, char **argv, struct command *acmd, struct plugin *
77667766
__u64 long_pi[256];
77677767
} eilbrts;
77687768

7769-
__u32 elbatms[256] = { 0 };
7770-
__u32 elbats[256] = { 0 };
7769+
__u16 elbatms[256] = { 0 };
7770+
__u16 elbats[256] = { 0 };
77717771

77727772
_cleanup_free_ union {
77737773
struct nvme_copy_range_f0 f0[256];
@@ -7876,9 +7876,9 @@ static int copy_cmd(int argc, char **argv, struct command *acmd, struct plugin *
78767876
return -EINVAL;
78777877
}
78787878

7879-
natms = argconfig_parse_comma_sep_array_u32(cfg.elbatms, elbatms,
7879+
natms = argconfig_parse_comma_sep_array_u16(cfg.elbatms, elbatms,
78807880
ARRAY_SIZE(elbatms));
7881-
nats = argconfig_parse_comma_sep_array_u32(cfg.elbats, elbats,
7881+
nats = argconfig_parse_comma_sep_array_u16(cfg.elbats, elbats,
78827882
ARRAY_SIZE(elbats));
78837883

78847884
nr = max(nb, max(ns, max(nrts, max(natms, nats))));

0 commit comments

Comments
 (0)