Skip to content

Commit f9765b1

Browse files
authored
zdb: Dump encrypted write and clone ZIL records
Block pointers are not encrypted in TX_WRITE and TX_CLONE_RANGE records, so we can dump them, that may be useful for debugging. Related to #15543. Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Alexander Motin <[email protected]> Sponsored by: iXsystems, Inc. Closes #15629
1 parent 86239a5 commit f9765b1

File tree

1 file changed

+58
-2
lines changed

1 file changed

+58
-2
lines changed

cmd/zdb/zdb_il.c

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ zil_prt_rec_write(zilog_t *zilog, int txtype, const void *arg)
168168
(u_longlong_t)lr->lr_foid, (u_longlong_t)lr->lr_offset,
169169
(u_longlong_t)lr->lr_length);
170170

171-
if (txtype == TX_WRITE2 || verbose < 5)
171+
if (txtype == TX_WRITE2 || verbose < 4)
172172
return;
173173

174174
if (lr->lr_common.lrc_reclen == sizeof (lr_write_t)) {
@@ -178,6 +178,8 @@ zil_prt_rec_write(zilog_t *zilog, int txtype, const void *arg)
178178
"will claim" : "won't claim");
179179
print_log_bp(bp, tab_prefix);
180180

181+
if (verbose < 5)
182+
return;
181183
if (BP_IS_HOLE(bp)) {
182184
(void) printf("\t\t\tLSIZE 0x%llx\n",
183185
(u_longlong_t)BP_GET_LSIZE(bp));
@@ -202,6 +204,9 @@ zil_prt_rec_write(zilog_t *zilog, int txtype, const void *arg)
202204
if (error)
203205
goto out;
204206
} else {
207+
if (verbose < 5)
208+
return;
209+
205210
/* data is stored after the end of the lr_write record */
206211
data = abd_alloc(lr->lr_length, B_FALSE);
207212
abd_copy_from_buf(data, lr + 1, lr->lr_length);
@@ -217,6 +222,28 @@ zil_prt_rec_write(zilog_t *zilog, int txtype, const void *arg)
217222
abd_free(data);
218223
}
219224

225+
static void
226+
zil_prt_rec_write_enc(zilog_t *zilog, int txtype, const void *arg)
227+
{
228+
(void) txtype;
229+
const lr_write_t *lr = arg;
230+
const blkptr_t *bp = &lr->lr_blkptr;
231+
int verbose = MAX(dump_opt['d'], dump_opt['i']);
232+
233+
(void) printf("%s(encrypted)\n", tab_prefix);
234+
235+
if (verbose < 4)
236+
return;
237+
238+
if (lr->lr_common.lrc_reclen == sizeof (lr_write_t)) {
239+
(void) printf("%shas blkptr, %s\n", tab_prefix,
240+
!BP_IS_HOLE(bp) &&
241+
bp->blk_birth >= spa_min_claim_txg(zilog->zl_spa) ?
242+
"will claim" : "won't claim");
243+
print_log_bp(bp, tab_prefix);
244+
}
245+
}
246+
220247
static void
221248
zil_prt_rec_truncate(zilog_t *zilog, int txtype, const void *arg)
222249
{
@@ -312,11 +339,34 @@ zil_prt_rec_clone_range(zilog_t *zilog, int txtype, const void *arg)
312339
{
313340
(void) zilog, (void) txtype;
314341
const lr_clone_range_t *lr = arg;
342+
int verbose = MAX(dump_opt['d'], dump_opt['i']);
315343

316344
(void) printf("%sfoid %llu, offset %llx, length %llx, blksize %llx\n",
317345
tab_prefix, (u_longlong_t)lr->lr_foid, (u_longlong_t)lr->lr_offset,
318346
(u_longlong_t)lr->lr_length, (u_longlong_t)lr->lr_blksz);
319347

348+
if (verbose < 4)
349+
return;
350+
351+
for (unsigned int i = 0; i < lr->lr_nbps; i++) {
352+
(void) printf("%s[%u/%llu] ", tab_prefix, i + 1,
353+
(u_longlong_t)lr->lr_nbps);
354+
print_log_bp(&lr->lr_bps[i], "");
355+
}
356+
}
357+
358+
static void
359+
zil_prt_rec_clone_range_enc(zilog_t *zilog, int txtype, const void *arg)
360+
{
361+
(void) zilog, (void) txtype;
362+
const lr_clone_range_t *lr = arg;
363+
int verbose = MAX(dump_opt['d'], dump_opt['i']);
364+
365+
(void) printf("%s(encrypted)\n", tab_prefix);
366+
367+
if (verbose < 4)
368+
return;
369+
320370
for (unsigned int i = 0; i < lr->lr_nbps; i++) {
321371
(void) printf("%s[%u/%llu] ", tab_prefix, i + 1,
322372
(u_longlong_t)lr->lr_nbps);
@@ -327,6 +377,7 @@ zil_prt_rec_clone_range(zilog_t *zilog, int txtype, const void *arg)
327377
typedef void (*zil_prt_rec_func_t)(zilog_t *, int, const void *);
328378
typedef struct zil_rec_info {
329379
zil_prt_rec_func_t zri_print;
380+
zil_prt_rec_func_t zri_print_enc;
330381
const char *zri_name;
331382
uint64_t zri_count;
332383
} zil_rec_info_t;
@@ -341,7 +392,9 @@ static zil_rec_info_t zil_rec_info[TX_MAX_TYPE] = {
341392
{.zri_print = zil_prt_rec_remove, .zri_name = "TX_RMDIR "},
342393
{.zri_print = zil_prt_rec_link, .zri_name = "TX_LINK "},
343394
{.zri_print = zil_prt_rec_rename, .zri_name = "TX_RENAME "},
344-
{.zri_print = zil_prt_rec_write, .zri_name = "TX_WRITE "},
395+
{.zri_print = zil_prt_rec_write,
396+
.zri_print_enc = zil_prt_rec_write_enc,
397+
.zri_name = "TX_WRITE "},
345398
{.zri_print = zil_prt_rec_truncate, .zri_name = "TX_TRUNCATE "},
346399
{.zri_print = zil_prt_rec_setattr, .zri_name = "TX_SETATTR "},
347400
{.zri_print = zil_prt_rec_acl, .zri_name = "TX_ACL_V0 "},
@@ -358,6 +411,7 @@ static zil_rec_info_t zil_rec_info[TX_MAX_TYPE] = {
358411
{.zri_print = zil_prt_rec_rename, .zri_name = "TX_RENAME_EXCHANGE "},
359412
{.zri_print = zil_prt_rec_rename, .zri_name = "TX_RENAME_WHITEOUT "},
360413
{.zri_print = zil_prt_rec_clone_range,
414+
.zri_print_enc = zil_prt_rec_clone_range_enc,
361415
.zri_name = "TX_CLONE_RANGE "},
362416
};
363417

@@ -384,6 +438,8 @@ print_log_record(zilog_t *zilog, const lr_t *lr, void *arg, uint64_t claim_txg)
384438
if (txtype && verbose >= 3) {
385439
if (!zilog->zl_os->os_encrypted) {
386440
zil_rec_info[txtype].zri_print(zilog, txtype, lr);
441+
} else if (zil_rec_info[txtype].zri_print_enc) {
442+
zil_rec_info[txtype].zri_print_enc(zilog, txtype, lr);
387443
} else {
388444
(void) printf("%s(encrypted)\n", tab_prefix);
389445
}

0 commit comments

Comments
 (0)