Skip to content

Commit 3a6072f

Browse files
author
Keith Busch
authored
Merge pull request #531 from jeffreyalien/master
[NVMe-CLI] Add support for larger data sizes needed to get DUI data.
2 parents 24eed48 + 9419b3d commit 3a6072f

1 file changed

Lines changed: 63 additions & 25 deletions

File tree

plugins/wdc/wdc-nvme.c

Lines changed: 63 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
#define WDC_DRIVE_CAP_CRASH_DUMP 0x0000000000000800
9191
#define WDC_DRIVE_CAP_PFAIL_DUMP 0x0000000000001000
9292

93+
9394
#define WDC_DRIVE_CAP_DRIVE_ESSENTIALS 0x0000000100000000
9495
#define WDC_DRIVE_CAP_DUI_DATA 0x0000000200000000
9596
#define WDC_SN730B_CAP_VUC_LOG 0x0000000400000000
@@ -1312,6 +1313,7 @@ static int wdc_do_cap_dui(int fd, char *file, __u32 xfer_size, int data_area, in
13121313
__s64 total_size = 0;
13131314
int i;
13141315
bool last_xfer = false;
1316+
int err = 0, output = 0;
13151317

13161318
log_hdr = (struct wdc_dui_log_hdr *) malloc(dui_log_hdr_size);
13171319
if (log_hdr == NULL) {
@@ -1366,30 +1368,41 @@ static int wdc_do_cap_dui(int fd, char *file, __u32 xfer_size, int data_area, in
13661368

13671369
total_size = log_size;
13681370

1369-
dump_data = (__u8 *) malloc(sizeof (__u8) * total_size);
1371+
dump_data = (__u8 *) malloc(sizeof (__u8) * xfer_size_long);
13701372
if (dump_data == NULL) {
13711373
fprintf(stderr, "%s: ERROR : dump data V2 malloc failed : status %s, size = 0x%lx\n",
1372-
__func__, strerror(errno), (long unsigned int)total_size);
1374+
__func__, strerror(errno), (long unsigned int)xfer_size_long);
13731375
ret = -1;
13741376
goto out;
13751377
}
1376-
memset(dump_data, 0, sizeof (__u8) * total_size);
1378+
memset(dump_data, 0, sizeof (__u8) * xfer_size_long);
1379+
1380+
output = open(file, O_WRONLY | O_CREAT | O_TRUNC, 0666);
1381+
if (output < 0) {
1382+
fprintf(stderr, "%s: Failed to open output file %s: %s!\n",
1383+
__func__, file, strerror(errno));
1384+
ret = output;
1385+
goto out;
1386+
}
13771387

1378-
/* copy the telemetry and log headers into the dump_data buffer */
1379-
memcpy(dump_data, log_hdr_v2, WDC_NVME_CAP_DUI_HEADER_SIZE);
1388+
/* write the telemetry and log headers into the dump_file */
1389+
err = write(output, (void *)log_hdr, WDC_NVME_CAP_DUI_HEADER_SIZE);
1390+
if (err != WDC_NVME_CAP_DUI_HEADER_SIZE) {
1391+
fprintf(stderr, "%s: Failed to flush header data to file!\n", __func__);
1392+
goto free_mem;
1393+
}
13801394

13811395
log_size -= WDC_NVME_CAP_DUI_HEADER_SIZE;
13821396
curr_data_offset = WDC_NVME_CAP_DUI_HEADER_SIZE;
13831397
i = 0;
1398+
buffer_addr = (__u64)(uintptr_t)dump_data;
13841399

13851400
for(; log_size > 0; log_size -= xfer_size_long) {
13861401
xfer_size_long = min(xfer_size_long, log_size);
13871402

13881403
if (log_size <= xfer_size_long)
13891404
last_xfer = true;
13901405

1391-
buffer_addr = (__u64)(uintptr_t)dump_data + (__u64)curr_data_offset;
1392-
13931406
ret = wdc_dump_dui_data_v2(fd, (__u32)xfer_size_long, curr_data_offset, (__u8 *)buffer_addr, last_xfer);
13941407
if (ret != 0) {
13951408
fprintf(stderr, "%s: ERROR : WDC : Get chunk %d, size = 0x%lx, offset = 0x%lx, addr = 0x%lx\n",
@@ -1398,6 +1411,14 @@ static int wdc_do_cap_dui(int fd, char *file, __u32 xfer_size, int data_area, in
13981411
break;
13991412
}
14001413

1414+
/* write the dump data into the file */
1415+
err = write(output, (void *)buffer_addr, xfer_size_long);
1416+
if (err != xfer_size_long) {
1417+
fprintf(stderr, "%s: ERROR : WDC : Failed to flush DUI data to file! chunk %d, err = 0x%x, xfer_size = 0x%lx\n",
1418+
__func__, i, err, (long unsigned int)xfer_size_long);
1419+
goto free_mem;
1420+
}
1421+
14011422
curr_data_offset += xfer_size_long;
14021423
i++;
14031424
}
@@ -1436,56 +1457,72 @@ static int wdc_do_cap_dui(int fd, char *file, __u32 xfer_size, int data_area, in
14361457

14371458
total_size = log_size;
14381459

1439-
dump_data = (__u8 *) malloc(sizeof (__u8) * total_size);
1460+
dump_data = (__u8 *) malloc(sizeof (__u8) * xfer_size);
14401461
if (dump_data == NULL) {
1441-
fprintf(stderr, "%s: ERROR : dump data V1 malloc failed : status %s, size = 0x%lx\n",
1442-
__func__, strerror(errno), (long unsigned int)total_size);
1462+
fprintf(stderr, "%s: ERROR : dump data V1 malloc failed : status %s, size = 0x%x\n",
1463+
__func__, strerror(errno), (unsigned int)xfer_size);
14431464
ret = -1;
14441465
goto out;
14451466
}
1446-
memset(dump_data, 0, sizeof (__u8) * total_size);
1467+
memset(dump_data, 0, sizeof (__u8) * xfer_size);
1468+
1469+
output = open(file, O_WRONLY | O_CREAT | O_TRUNC, 0666);
1470+
if (output < 0) {
1471+
fprintf(stderr, "%s: Failed to open output file %s: %s!\n",
1472+
__func__, file, strerror(errno));
1473+
ret = output;
1474+
goto out;
1475+
}
14471476

1448-
/* copy the telemetry and log headers into the dump_data buffer */
1449-
memcpy(dump_data, log_hdr, WDC_NVME_CAP_DUI_HEADER_SIZE);
1477+
/* write the telemetry and log headers into the dump_file */
1478+
err = write(output, (void *)log_hdr, WDC_NVME_CAP_DUI_HEADER_SIZE);
1479+
if (err != WDC_NVME_CAP_DUI_HEADER_SIZE) {
1480+
fprintf(stderr, "%s: Failed to flush header data to file!\n", __func__);
1481+
goto free_mem;
1482+
}
14501483

14511484
log_size -= WDC_NVME_CAP_DUI_HEADER_SIZE;
14521485
curr_data_offset = WDC_NVME_CAP_DUI_HEADER_SIZE;
14531486
i = 0;
1487+
buffer_addr = (__u64)(uintptr_t)dump_data;
14541488

14551489
for(; log_size > 0; log_size -= xfer_size) {
14561490
xfer_size = min(xfer_size, log_size);
14571491

14581492
if (log_size <= xfer_size)
14591493
last_xfer = true;
14601494

1461-
buffer_addr = (__u64)(uintptr_t)dump_data + (__u64)curr_data_offset;
1462-
14631495
ret = wdc_dump_dui_data(fd, xfer_size, curr_data_offset, (__u8 *)buffer_addr, last_xfer);
14641496
if (ret != 0) {
14651497
fprintf(stderr, "%s: ERROR : WDC : Get chunk %d, size = 0x%lx, offset = 0x%x, addr = 0x%lx\n",
1466-
__func__, i, (long unsigned int)total_size, curr_data_offset, (long unsigned int)buffer_addr);
1498+
__func__, i, (long unsigned int)log_size, curr_data_offset, (long unsigned int)buffer_addr);
14671499
fprintf(stderr, "%s: ERROR : WDC : NVMe Status:%s(%x)\n", __func__, nvme_status_to_string(ret), ret);
14681500
break;
14691501
}
14701502

1503+
/* write the dump data into the file */
1504+
err = write(output, (void *)buffer_addr, xfer_size);
1505+
if (err != xfer_size) {
1506+
fprintf(stderr, "%s: ERROR : WDC : Failed to flush DUI data to file! chunk %d, err = 0x%x, xfer_size = 0x%x\n",
1507+
__func__, i, err, xfer_size);
1508+
goto free_mem;
1509+
}
1510+
14711511
curr_data_offset += xfer_size;
14721512
i++;
14731513
}
1474-
14751514
}
14761515
}
14771516

1478-
if (ret == 0) {
1479-
fprintf(stderr, "%s: NVMe Status:%s(%x)\n", __func__, nvme_status_to_string(ret), ret);
1480-
if (verbose)
1481-
fprintf(stderr, "INFO : WDC : Capture Device Unit Info log, length = 0x%lx\n", (long unsigned int)total_size);
1482-
1483-
ret = wdc_create_log_file(file, dump_data, total_size);
1484-
}
1517+
fprintf(stderr, "%s: NVMe Status:%s(%x)\n", __func__, nvme_status_to_string(ret), ret);
1518+
if (verbose)
1519+
fprintf(stderr, "INFO : WDC : Capture Device Unit Info log, length = 0x%lx\n", (long unsigned int)total_size);
14851520

1521+
free_mem:
1522+
close(output);
14861523
free(dump_data);
14871524

1488-
out:
1525+
out:
14891526
free(log_hdr);
14901527
return ret;
14911528
}
@@ -3859,6 +3896,7 @@ static int wdc_drive_resize(int argc, char **argv,
38593896
return ret;
38603897
}
38613898

3899+
38623900
static void wdc_print_nand_stats_normal(struct wdc_nand_stats *data)
38633901
{
38643902
printf(" NAND Statistics :- \n");

0 commit comments

Comments
 (0)