Skip to content

Commit f07b697

Browse files
kanard38knard38
authored andcommitted
DAOS-17321 ddb: Checksum management with ddb
First commit. Signed-off-by: Cedric Koch-Hofer <[email protected]>
1 parent b51a31c commit f07b697

File tree

9 files changed

+310
-29
lines changed

9 files changed

+310
-29
lines changed

src/control/cmd/ddb/commands_wrapper.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,3 +349,14 @@ func ddbDtxAggr(ctx *DdbContext, path string, cmt_time uint64, cmt_date string)
349349
/* Run the c code command */
350350
return daosError(C.ddb_run_dtx_aggr(&ctx.ctx, &options))
351351
}
352+
353+
func ddbCsumDump(ctx *DdbContext, path string, dst string) error {
354+
/* Set up the options */
355+
options := C.struct_csum_dump_options{}
356+
options.path = C.CString(path)
357+
defer freeString(options.path)
358+
options.dst = C.CString(dst)
359+
defer freeString(options.dst)
360+
/* Run the c code command */
361+
return daosError(C.ddb_run_csum_dump(&ctx.ctx, &options))
362+
}

src/control/cmd/ddb/ddb_commands.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,4 +442,23 @@ the path must include the extent, otherwise, it must not.`,
442442
},
443443
Completer: nil,
444444
})
445+
// Command dtx_aggr
446+
app.AddCommand(&grumble.Command{
447+
Name: "csum_dump",
448+
Aliases: nil,
449+
Help: "Dump checksum information",
450+
LongHelp: `Dump a checksum to the screen or file. The vos path should be a complete path,
451+
including the akey and if the value is an array value it should include the
452+
extent. If a path to a file was provided then the value will be written to the
453+
file, else it will be printed to the screen.`,
454+
HelpGroup: "vos",
455+
Args: func(a *grumble.Args) {
456+
a.String("path", "VOS tree path to dump.")
457+
a.String("dst", "Optional, destination vos tree path to a value.", grumble.Default(""))
458+
},
459+
Run: func(c *grumble.Context) error {
460+
return ddbCsumDump(ctx, c.Args.String("path"), c.Args.String("dst"))
461+
},
462+
Completer: nil,
463+
})
445464
}

src/include/daos_srv/vos.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,13 @@ vos_obj_fetch_ex(daos_handle_t coh, daos_unit_oid_t oid, daos_epoch_t epoch,
723723
uint64_t flags, daos_key_t *dkey, unsigned int iod_nr,
724724
daos_iod_t *iods, d_sg_list_t *sgls, struct dtx_handle *dth);
725725

726+
/**
727+
* TODO DAOS-17321
728+
*/
729+
int
730+
vos_csum_fetch(daos_handle_t coh, daos_key_t *dkey, daos_unit_oid_t oid, daos_iod_t *iod,
731+
struct dcs_ci_list *cil);
732+
726733
/**
727734
* Update records for the specified object.
728735
* If input buffer is not provided in \a sgl, then this function returns

src/include/daos_srv/vos_types.h

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -258,49 +258,51 @@ typedef enum {
258258

259259
enum {
260260
/** Conditional Op: Punch key if it exists, fail otherwise */
261-
VOS_OF_COND_PUNCH = DAOS_COND_PUNCH,
261+
VOS_OF_COND_PUNCH = DAOS_COND_PUNCH,
262262
/** Conditional Op: Insert dkey if it doesn't exist, fail otherwise */
263-
VOS_OF_COND_DKEY_INSERT = DAOS_COND_DKEY_INSERT,
263+
VOS_OF_COND_DKEY_INSERT = DAOS_COND_DKEY_INSERT,
264264
/** Conditional Op: Update dkey if it exists, fail otherwise */
265-
VOS_OF_COND_DKEY_UPDATE = DAOS_COND_DKEY_UPDATE,
265+
VOS_OF_COND_DKEY_UPDATE = DAOS_COND_DKEY_UPDATE,
266266
/** Conditional Op: Fetch dkey if it exists, fail otherwise */
267-
VOS_OF_COND_DKEY_FETCH = DAOS_COND_DKEY_FETCH,
267+
VOS_OF_COND_DKEY_FETCH = DAOS_COND_DKEY_FETCH,
268268
/** Conditional Op: Insert akey if it doesn't exist, fail otherwise */
269-
VOS_OF_COND_AKEY_INSERT = DAOS_COND_AKEY_INSERT,
269+
VOS_OF_COND_AKEY_INSERT = DAOS_COND_AKEY_INSERT,
270270
/** Conditional Op: Update akey if it exists, fail otherwise */
271-
VOS_OF_COND_AKEY_UPDATE = DAOS_COND_AKEY_UPDATE,
271+
VOS_OF_COND_AKEY_UPDATE = DAOS_COND_AKEY_UPDATE,
272272
/** Conditional Op: Fetch akey if it exists, fail otherwise */
273-
VOS_OF_COND_AKEY_FETCH = DAOS_COND_AKEY_FETCH,
273+
VOS_OF_COND_AKEY_FETCH = DAOS_COND_AKEY_FETCH,
274274
/** Indicates akey conditions are specified in iod_flags */
275-
VOS_OF_COND_PER_AKEY = DAOS_COND_PER_AKEY,
275+
VOS_OF_COND_PER_AKEY = DAOS_COND_PER_AKEY,
276276
/* critical update - skip checks on SCM system/held space */
277-
VOS_OF_CRIT = (1 << 8),
277+
VOS_OF_CRIT = (1 << 8),
278278
/** Instead of update or punch of extents, remove all extents
279279
* under the specified range. Intended for internal use only.
280280
*/
281-
VOS_OF_REMOVE = (1 << 9),
281+
VOS_OF_REMOVE = (1 << 9),
282282
/* only query iod_size */
283-
VOS_OF_FETCH_SIZE_ONLY = (1 << 10),
283+
VOS_OF_FETCH_SIZE_ONLY = (1 << 10),
284284
/* query recx list */
285-
VOS_OF_FETCH_RECX_LIST = (1 << 11),
285+
VOS_OF_FETCH_RECX_LIST = (1 << 11),
286286
/* only set read TS */
287-
VOS_OF_FETCH_SET_TS_ONLY = (1 << 12),
287+
VOS_OF_FETCH_SET_TS_ONLY = (1 << 12),
288288
/* check the target (obj/dkey/akey) existence */
289-
VOS_OF_FETCH_CHECK_EXISTENCE = (1 << 13),
289+
VOS_OF_FETCH_CHECK_EXISTENCE = (1 << 13),
290290
/** Set when propagating a punch that results in empty subtree */
291-
VOS_OF_PUNCH_PROPAGATE = (1 << 14),
291+
VOS_OF_PUNCH_PROPAGATE = (1 << 14),
292292
/** replay punch (underwrite) */
293-
VOS_OF_REPLAY_PC = (1 << 15),
293+
VOS_OF_REPLAY_PC = (1 << 15),
294294
/** Dedup update mode */
295-
VOS_OF_DEDUP = (1 << 16),
295+
VOS_OF_DEDUP = (1 << 16),
296296
/** Dedup update with memcmp verify mode */
297-
VOS_OF_DEDUP_VERIFY = (1 << 17),
297+
VOS_OF_DEDUP_VERIFY = (1 << 17),
298298
/** Ignore fetch only used by shadow fetch to ignore the evt fetch */
299-
VOS_OF_SKIP_FETCH = (1 << 18),
299+
VOS_OF_SKIP_FETCH = (1 << 18),
300300
/** Operation on EC object (currently only applies to update) */
301-
VOS_OF_EC = (1 << 19),
301+
VOS_OF_EC = (1 << 19),
302302
/** Update from rebuild */
303-
VOS_OF_REBUILD = (1 << 20),
303+
VOS_OF_REBUILD = (1 << 20),
304+
/* only query iod_size */
305+
VOS_OF_FETCH_CSUM_ONLY = (1 << 21),
304306
};
305307

306308
enum {

src/utils/ddb/ddb.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,11 @@ struct dtx_aggr_options {
236236
char *cmt_date;
237237
};
238238

239+
struct csum_dump_options {
240+
char *path;
241+
char *dst;
242+
};
243+
239244
struct ddb_cmd_info {
240245
enum ddb_cmd dci_cmd;
241246
union {
@@ -330,6 +335,8 @@ int
330335
ddb_run_prov_mem(struct ddb_ctx *ctx, struct prov_mem_options *opt);
331336
int
332337
ddb_run_dtx_aggr(struct ddb_ctx *ctx, struct dtx_aggr_options *opt);
338+
int
339+
ddb_run_csum_dump(struct ddb_ctx *ctx, struct csum_dump_options *opt);
333340

334341
void
335342
ddb_program_help(struct ddb_ctx *ctx);

src/utils/ddb/ddb_commands.c

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,150 @@ ddb_run_value_dump(struct ddb_ctx *ctx, struct value_dump_options *opt)
366366
return rc;
367367
}
368368

369+
struct dump_csum_args {
370+
struct ddb_ctx *dca_ctx;
371+
struct dv_indexed_tree_path *dca_vtp;
372+
char *dca_dst_path;
373+
};
374+
375+
struct dump_csum_value {
376+
char *dcv_type;
377+
uint16_t dcv_length;
378+
uint8_t *dcv_buf;
379+
};
380+
381+
static int
382+
dump_csum_wrap(struct dump_csum_args *args, struct dcs_ci_list *cil, struct dump_csum_value *dcv)
383+
{
384+
struct dcs_csum_info *ci;
385+
struct hash_ft *hf;
386+
387+
if (cil->dcl_csum_infos_nr == 0)
388+
return -DER_NONEXIST;
389+
D_ASSERT(cil->dcl_csum_infos_nr == 1);
390+
391+
ci = dcs_csum_info_get(cil, 0);
392+
D_ASSERT(ci_is_valid(ci));
393+
D_ASSERT(ci->cs_nr == 1);
394+
hf = daos_mhash_type2algo(ci->cs_type);
395+
396+
dcv->dcv_type = hf->cf_name;
397+
dcv->dcv_length = ci->cs_len;
398+
dcv->dcv_buf = ci_idx2csum(ci, 0);
399+
400+
return 0;
401+
}
402+
403+
static int
404+
print_csum_cb(void *cb_args, struct dcs_ci_list *cil)
405+
{
406+
struct dump_csum_args *args;
407+
struct ddb_ctx *ctx;
408+
struct dump_csum_value dcv;
409+
int i;
410+
int rc;
411+
412+
args = cb_args;
413+
ctx = args->dca_ctx;
414+
415+
rc = dump_csum_wrap(cb_args, cil, &dcv);
416+
if (!SUCCESS(rc)) {
417+
D_ASSERT(-DER_NONEXIST);
418+
419+
ddb_print(ctx, "No check-sum at: ");
420+
itp_print_full(ctx, args->dca_vtp);
421+
ddb_print(ctx, "\n");
422+
return 0;
423+
}
424+
425+
itp_print_full(ctx, args->dca_vtp);
426+
ddb_print(ctx, "\n");
427+
ddb_printf(ctx, "Type: %s, Length: %" PRIu16 ", Value: 0x", dcv.dcv_type, dcv.dcv_length);
428+
for (i = 0; i < dcv.dcv_length; i++)
429+
ddb_printf(ctx, "%02" PRIx8, dcv.dcv_buf[i]);
430+
ddb_print(ctx, "\n");
431+
432+
return 0;
433+
}
434+
435+
static int
436+
write_file_csum_cb(void *cb_args, struct dcs_ci_list *cil)
437+
{
438+
struct dump_csum_args *args;
439+
struct ddb_ctx *ctx;
440+
struct dump_csum_value dcv;
441+
d_iov_t value;
442+
int rc;
443+
444+
args = cb_args;
445+
ctx = args->dca_ctx;
446+
447+
D_ASSERT(ctx->dc_io_ft.ddb_write_file);
448+
449+
rc = dump_csum_wrap(cb_args, cil, &dcv);
450+
if (!SUCCESS(rc)) {
451+
D_ASSERT(-DER_NONEXIST);
452+
453+
ddb_print(ctx, "No check-sum at: ");
454+
itp_print_full(ctx, args->dca_vtp);
455+
ddb_print(ctx, "\n");
456+
return 0;
457+
}
458+
value.iov_buf = dcv.dcv_buf;
459+
value.iov_len = dcv.dcv_length;
460+
value.iov_buf_len = dcv.dcv_length;
461+
462+
ddb_printf(ctx, "Dumping chekck-sum (type: %s, length: %" PRIu16 ") to %s\n", dcv.dcv_type,
463+
dcv.dcv_length, args->dca_dst_path);
464+
rc = ctx->dc_io_ft.ddb_write_file(args->dca_dst_path, &value);
465+
return rc;
466+
}
467+
468+
int
469+
ddb_run_csum_dump(struct ddb_ctx *ctx, struct csum_dump_options *opt)
470+
{
471+
struct dv_indexed_tree_path itp = {0};
472+
struct dv_tree_path vtp;
473+
struct dump_csum_args dca = {0};
474+
dv_dump_csum_cb cb = NULL;
475+
int rc;
476+
477+
if (!opt->path) {
478+
ddb_error(ctx, "A VOS path to dump is required.\n");
479+
rc = -DER_INVAL;
480+
goto out;
481+
}
482+
483+
rc = init_path(ctx, opt->path, &itp);
484+
if (!SUCCESS(rc))
485+
goto out;
486+
487+
if (!itp_has_value(&itp)) {
488+
ddb_errorf(ctx, "Path [%s] is incomplete.\n", opt->path);
489+
rc = -DDBER_INCOMPLETE_PATH_VALUE;
490+
goto out_itp;
491+
}
492+
493+
if (opt->dst && opt->dst[0] != '\0')
494+
cb = write_file_csum_cb;
495+
else
496+
cb = print_csum_cb;
497+
498+
dca.dca_dst_path = opt->dst;
499+
dca.dca_ctx = ctx;
500+
dca.dca_vtp = &itp;
501+
502+
itp_to_vos_path(&itp, &vtp);
503+
504+
rc = dv_dump_csum(ctx->dc_poh, &vtp, cb, &dca);
505+
506+
out_itp:
507+
itp_free(&itp);
508+
509+
out:
510+
return rc;
511+
}
512+
369513
static int
370514
dump_ilog_entry_cb(void *cb_arg, struct ddb_ilog_entry *entry)
371515
{

src/utils/ddb/ddb_vos.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,55 @@ dv_dump_value(daos_handle_t poh, struct dv_tree_path *path, dv_dump_value_cb dum
10271027
return rc;
10281028
}
10291029

1030+
int
1031+
dv_dump_csum(daos_handle_t poh, struct dv_tree_path *path, dv_dump_csum_cb dump_cb, void *cb_arg)
1032+
{
1033+
daos_iod_t iod = {0};
1034+
daos_handle_t coh;
1035+
struct dcs_ci_list cil;
1036+
int rc;
1037+
1038+
rc = vos_cont_open(poh, path->vtp_cont, &coh);
1039+
if (!SUCCESS(rc)) {
1040+
D_ERROR("Unable to fetch object: " DF_RC "\n", DP_RC(rc));
1041+
goto out;
1042+
}
1043+
1044+
iod.iod_name = path->vtp_akey;
1045+
iod.iod_recxs = &path->vtp_recx;
1046+
iod.iod_nr = 1;
1047+
iod.iod_size = 0;
1048+
iod.iod_type = path->vtp_recx.rx_nr == 0 ? DAOS_IOD_SINGLE : DAOS_IOD_ARRAY;
1049+
1050+
rc = dcs_csum_info_list_init(&cil, 0);
1051+
if (!SUCCESS(rc)) {
1052+
D_ERROR("Unable to init csum list: " DF_RC "\n", DP_RC(rc));
1053+
goto out_cont;
1054+
}
1055+
1056+
rc = vos_csum_fetch(coh, &path->vtp_dkey, path->vtp_oid, &iod, &cil);
1057+
if (!SUCCESS(rc)) {
1058+
D_ERROR("Unable to fetch csum: " DF_RC "\n", DP_RC(rc));
1059+
goto out_cil;
1060+
}
1061+
1062+
if (!dump_cb)
1063+
goto out_cil;
1064+
rc = dump_cb(cb_arg, &cil);
1065+
if (!SUCCESS(rc)) {
1066+
D_ERROR("Unable to dump csum: " DF_RC "\n", DP_RC(rc));
1067+
}
1068+
1069+
out_cil:
1070+
dcs_csum_info_list_fini(&cil);
1071+
1072+
out_cont:
1073+
vos_cont_close(coh);
1074+
1075+
out:
1076+
return rc;
1077+
}
1078+
10301079
static void
10311080
ilog_entry_status(enum ilog_status status, char *status_str, uint32_t status_str_len)
10321081
{

src/utils/ddb/ddb_vos.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ typedef int (*dv_dump_value_cb)(void *cb_arg, d_iov_t *value);
139139
int dv_dump_value(daos_handle_t poh, struct dv_tree_path *path, dv_dump_value_cb dump_cb,
140140
void *cb_arg);
141141

142+
typedef int (*dv_dump_csum_cb)(void *cb_arg, struct dcs_ci_list *cil);
143+
144+
int
145+
dv_dump_csum(daos_handle_t poh, struct dv_tree_path *path, dv_dump_csum_cb dump_cb, void *cb_arg);
146+
142147
struct ddb_ilog_entry {
143148
uint32_t die_idx;
144149
int32_t die_status;

0 commit comments

Comments
 (0)