diff --git a/src/nvme/api-types.h b/src/nvme/api-types.h index 0de41a65..80ac8d23 100644 --- a/src/nvme/api-types.h +++ b/src/nvme/api-types.h @@ -666,8 +666,6 @@ struct nvme_dsm_args { * @prinfow: Protection information field for write * @dtype: Directive type * @format: Descriptor format - * @ilbrt_u64: Initial logical block reference tag - 8 byte - * version required for enhanced protection info */ struct nvme_copy_args { __u64 sdlba; @@ -677,7 +675,7 @@ struct nvme_copy_args { int fd; __u32 timeout; __u32 nsid; - __u32 ilbrt; + __u64 ilbrt; int lr; int fua; __u16 nr; @@ -688,7 +686,6 @@ struct nvme_copy_args { __u8 prinfow; __u8 dtype; __u8 format; - __u64 ilbrt_u64; }; /** diff --git a/src/nvme/ioctl.c b/src/nvme/ioctl.c index 33339939..974168e2 100644 --- a/src/nvme/ioctl.c +++ b/src/nvme/ioctl.c @@ -1718,11 +1718,9 @@ int nvme_dsm(struct nvme_dsm_args *args) int nvme_copy(struct nvme_copy_args *args) { - const size_t size_v1 = sizeof_args(struct nvme_copy_args, format, __u64); - const size_t size_v2 = sizeof_args(struct nvme_copy_args, ilbrt_u64, __u64); __u32 cdw3, cdw12, cdw14, data_len; - if (args->args_size < size_v1 || args->args_size > size_v2) { + if (args->args_size < sizeof(*args)) { errno = EINVAL; return -1; } @@ -1732,19 +1730,19 @@ int nvme_copy(struct nvme_copy_args *args) ((args->prinfow & 0xf) << 26) | ((args->fua & 0x1) << 30) | ((args->lr & 0x1) << 31); - if (args->args_size == size_v1) { + if (args->format == 0) { cdw3 = 0; cdw14 = args->ilbrt; + data_len = args->nr * sizeof(struct nvme_copy_range); + } else if (args->format == 1) { + cdw3 = (args->ilbrt >> 32) & 0xffffffff; + cdw14 = args->ilbrt & 0xffffffff; + data_len = args->nr * sizeof(struct nvme_copy_range_f1); } else { - cdw3 = (args->ilbrt_u64 >> 32) & 0xffffffff; - cdw14 = args->ilbrt_u64 & 0xffffffff; + errno = EINVAL; + return -1; } - if (args->format == 1) - data_len = args->nr * sizeof(struct nvme_copy_range_f1); - else - data_len = args->nr * sizeof(struct nvme_copy_range); - struct nvme_passthru_cmd cmd = { .opcode = nvme_cmd_copy, .nsid = args->nsid, diff --git a/src/nvme/util.c b/src/nvme/util.c index 4363d5e4..db68a40c 100644 --- a/src/nvme/util.c +++ b/src/nvme/util.c @@ -401,14 +401,16 @@ void nvme_init_copy_range_f1(struct nvme_copy_range_f1 *copy, __u16 *nlbs, __u64 *slbas, __u64 *eilbrts, __u32 *elbatms, __u32 *elbats, __u16 nr) { - int i; + int i, j; for (i = 0; i < nr; i++) { copy[i].nlb = cpu_to_le16(nlbs[i]); copy[i].slba = cpu_to_le64(slbas[i]); - copy[i].elbt[2] = cpu_to_le64(eilbrts[i]); copy[i].elbatm = cpu_to_le16(elbatms[i]); copy[i].elbat = cpu_to_le16(elbats[i]); + + for (j = 0; j < 8; j++) + copy[i].elbt[9 - j] = (eilbrts[i] >> (8 * j)) & 0xff; } }