allow dump levels 0-254
cover allow dump levels 0-254
xfsdump limits dump levels to 0-9. Nothing on media or in the inventory imposes that: the media file header stores the level as an int32_t and the inventory session header as a byte. The limit is the LEVEL_MAX policy constant in dump/content.c, plus an assert in xfsrestore's label display that the level is a single digit. Linux dump(8) has accepted any integer level for years.
This can be very useful in environments for which frequent incrementals are desirable, but the current ten levels (0-9) are simply too narrow.
1/2 makes xfsrestore print levels of any size
2/2 raises xfsdump's limit to 254, the most the inventory byte can
hold with 255 kept as the -I level= "any level" marker. The level written into the media header is capped at 9 so that released xfsrestore, whose assert would otherwise abort, can still restore these dumps (reporting them as level 9); the real level goes into the adjacent 4 bytes of alignment padding, which xfsdump always zeroed.
No on-disk layout changes and no inventory format change. Dumps at levels 0-9 are byte-for-byte what xfsdump writes today, and existing dumps and inventories decode unchanged.
Testing: built with gcc 13.3 against xfsprogs 6.6 headers, with no new warnings. On a 6.8 kernel, fstests -g dump gives the same results with and without this series (29 pass; 14 not run: the tape tests and xfs/287). A new fstests test, xfs/842 (sent separately), passes with the series and is skipped with xfsdump 3.3.0.
An end-to-end script also checked compatibility with 3.3.0. A chain of incrementals at levels 0-12, 100, 253 and 254 restores correctly with the new xfsrestore and with 3.3.0 xfsrestore, which reports every level above 9 as 9. Dumps from 3.3.0 xfsdump restore correctly with the new xfsrestore. 3.3.0 xfsdump sharing the inventory lists the real levels and still bases its incrementals on levels below its own. For comparison, a dump carrying the raw level 10 in cih_level makes 3.3.0 xfsrestore (assertions enabled) abort in display_dump_label().
Tool use: this series was developed with an AI coding assistant (Claude Opus 5.5, Anthropic). It traced the level limit through xfsdump, xfsrestore, xfsinvutil and the inventory code, and drafted the code, man page change and changelogs from a request to lift the 0-9 limit without changing on-disk formats or breaking older xfsrestore. I reviewed all of it and found no need to change any of it. The changes center on the self-imposed enforcement of the 0-9 level limit itself and on displaying levels of any size safely. The coding tool ran all the tests in a QEMU VM, and I reviewed both the code and the test results.
Diego Rivera (2):
xfsrestore: don't assume single-digit dump levels in dump labels
xfsdump: allow dump levels up to 254
common/arch_xlate.c | 2 +- common/content_inode.h | 60 +++++++++++++++++++++++++++++++++++++++--- dump/content.c | 23 +++++++++++++--- inventory/inventory.h | 7 ++++- man/man8/xfsdump.8 | 10 +++++-- restore/content.c | 11 ++++---- 6 files changed, 96 insertions(+), 17 deletions(-)
base-commit: 04051066b6c66218717cb6cbfd51e96df393d183
Signature · 1 line
2.43.0
PATCH 1/2 xfsrestore: don't assume single-digit dump levels in dump labels
display_dump_label() renders the dump level by adding it to '0' and asserts that the level is below 10. The media header carries the level as an int32_t, so the assert is the only thing tying xfsrestore to single-digit levels: on a build without NDEBUG it aborts on any dump whose level is 10 or more, and with NDEBUG it prints a punctuation character instead of the level.
Format the level as a decimal number instead. The translatable message is left untouched so existing translations keep working.
Drafted with an AI coding assistant (Claude); details in the cover letter of the posting.
--- restore/content.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
restore/content.c +3 -4
@@ -9425,15 +9425,14 @@ display_dump_label(bool_t lockpr, content_inode_hdr_t *scrhdrp) {char dateline[28 ]; -char level_string[2 ]; +char level_string[12 ];char dump_string_uuid[UUID_STR_LEN +1 ];char media_string_uuid[UUID_STR_LEN +1 ];char fs_string_uuid[UUID_STR_LEN +1 ];assert (scrhdrp->cih_level >=0 ); -assert (scrhdrp->cih_level <10 ); - level_string[0 ] = (char )('0' + (u_char_t )scrhdrp->cih_level); - level_string[1 ] =0 ; +snprintf (level_string,sizeof (level_string),"%u" , + (uint )scrhdrp->cih_level);uuid_unparse (grhdrp->gh_dumpid, dump_string_uuid);uuid_unparse (mrhdrp->mh_mediaid, media_string_uuid);
Signature · 1 line
2.43.0
PATCH 2/2 xfsdump: allow dump levels up to 254
In reply to Diego RiveraThe 0-9 range of dump levels is not imposed by any on-media or inventory structure. The media file header stores the level as an int32_t (cih_level) and the inventory as a byte (sh_level). The range is a policy constant, LEVEL_MAX in dump/content.c, inherited from the traditional dump(8) convention of single-digit levels; Linux dump(8) itself has accepted any integer level for years. The only code that actually depends on it is xfsrestore's display of the level, which asserted the level was a single digit (fixed earlier in this series).
Raise LEVEL_MAX to INV_LEVEL_MAX, 254: the most sh_level can hold, keeping 255 (PR_MAXLEVEL) as the "any level" marker of the -I level= print filter. The inventory format and code are otherwise unchanged, so older xfsdump, xfsrestore and xfsinvutil sharing the inventory see the real levels, and older xfsdump never picks a session above its own maximum of 9 as the base of an incremental.
Released xfsrestore still carries that assert, and aborts on any dump whose level is 10 or more when built without NDEBUG. To let it restore the new dumps anyway, cap the level xfsdump writes into cih_level at 9, and record the real level in the 4 bytes of alignment padding that follow it (pad1, renamed cih_level_ext): two tag bytes plus a big-endian 16-bit level. Older xfsrestore only compares cih_level with 0, so it restores such a dump correctly and just reports it as level
9. New xfsrestore decodes the real level with cih_get_level(). The padding was always zeroed (the header template is calloc()ed), and the tag is only honoured together with cih_level == 9, so dumps from older xfsdump decode unchanged. Dumps at levels 0-9 are byte-for-byte the same as before.
Restore's cumulative-restore checks work on base dump ids, not on levels, so they need no change.
Also reject a non-numeric -l argument instead of letting atoi() turn it silently into level 0.
Drafted with an AI coding assistant (Claude); details in the cover letter of the posting.
--- common/arch_xlate.c | 2 +- common/content_inode.h | 60 +++++++++++++++++++++++++++++++++++++++--- dump/content.c | 23 +++++++++++++--- inventory/inventory.h | 7 ++++- man/man8/xfsdump.8 | 10 +++++-- restore/content.c | 6 ++--- 6 files changed, 94 insertions(+), 14 deletions(-)
common/arch_xlate.c +1 -1
@@ -253,7 +253,7 @@ xlate_content_inode_hdr(content_inode_hdr_t *cih1, content_inode_hdr_t *cih2, in ptr2 = cih1; } -BXLATE (pad1); +BXLATE (cih_level_ext);BXLATE (cih_last_id);BXLATE (cih_resume_id);BXLATE (cih_pad2);
common/content_inode.h +57 -3
72 lines not on this page · raw message
dump/content.c +19 -4
@@ -75,10 +75,14 @@*/ #define ULONGLONG_MAX 18446744073709551615LLU -/* legal range of dump levels +/* legal range of dump levels: bounded by what the inventory can record +* and by what the media file header can carry (see content_inode.h) */ #define LEVEL_DEFAULT 0 -#define LEVEL_MAX 9 +#define LEVEL_MAX INV_LEVEL_MAX +#if LEVEL_MAX >CIH_LEVEL_EXT_MAX +#error "LEVEL_MAX does not fit in the media file header" +#endif /* ordinary files as big or bigger than this many pages will be * preceeded in the dump by enough padding to align the first byte
@@ -660,7 +664,18 @@ content_init(int argc,usage ();return BOOL_FALSE ; } - sc_level = (ix_t )atoi (optarg); + { +char *endp; +unsigned long lvl; + + errno =0 ; + lvl =strtoul (optarg, &endp,10 ); +if (!*optarg || *endp || errno || + lvl >LEVEL_MAX ) { + lvl = (unsigned long )LEVEL_MAX +1 ; + } + sc_level = (ix_t )lvl; + }if (sc_level >LEVEL_MAX ) { mlog(MLOG_NORMAL | MLOG_ERROR, _( "-%c argument must be "
@@ -1538,7 +1553,7 @@ _("%s is not the root of the filesystem (bind mount?) - use primary mountpoint\n*/ assert (sizeof (cwhdrtemplatep->ch_specific) >=sizeof (*scwhdrtemplatep)); scwhdrtemplatep->cih_mediafiletype =CIH_MEDIAFILETYPE_DATA ; - scwhdrtemplatep->cih_level = (int32_t )sc_level; +cih_set_level (scwhdrtemplatep, (uint32_t )sc_level); scwhdrtemplatep->cih_dumpattr =CIH_DUMPATTR_INOMAP ;if (subtreecnt) { scwhdrtemplatep->cih_dumpattr |=CIH_DUMPATTR_SUBTREE ;
inventory/inventory.h +6 -1
@@ -64,7 +64,12 @@ typedef uint32_t inv_version_t;#define PR_STRMSONLY 3#define PR_ALL 4#define PR_MAXDEPTH 5 -#define PR_MAXLEVEL 255 +#define PR_MAXLEVEL 255/* -I level= value meaning "any level" */ + +/* highest dump level a session can be recorded at: sh_level is a byte, +* and PR_MAXLEVEL is reserved as the "any level" marker +*/ +#define INV_LEVEL_MAX (PR_MAXLEVEL - 1)/*----------------------------------------------------------------------*/ /* Inventory */
man/man8/xfsdump.8 +8 -2
@@ -125,13 +125,19 @@ preceding the source filesystem specification) is specified. .TP 5 \f3\-l\f1 \f2level\f1 -Specifies a dump level of 0 to 9. +Specifies a dump level of 0 to 254. The dump level determines the base dump to which this dump is relative. The base dump is the most recent dump at a lesser level. A level 0 dump is absolute \- all files are dumped. -A dump level where 1 <= \f2level\f1 <= 9 is referred to as an incremental dump. +A dump level where 1 <= \f2level\f1 <= 254 is referred to as an incremental dump. Only files that have been changed since the base dump are dumped. +Older versions of +.B xfsdump +only accept levels 0 to 9. +Older versions of +.BR xfsrestore (8) +can restore dumps made at higher levels, but report them as level 9. Subtree dumps (see the .B \-s
restore/content.c +3 -3
@@ -2083,7 +2083,7 @@ content_stream_restore(ix_t thrdix) matchpr =BOOL_FALSE ; resumepr = (scrhdrp->cih_dumpattr &CIH_DUMPATTR_RESUME );assert (scrhdrp->cih_level >=0 ); - level = (ix_t )scrhdrp->cih_level; + level = (ix_t )cih_get_level (scrhdrp); baseidp = resumepr ? &scrhdrp->cih_resume_id
@@ -2339,7 +2339,7 @@ content_stream_restore(ix_t thrdix)if (!tranp->t_treeinitdonepr) {bool_t fullpr; - fullpr = (scrhdrp->cih_level + fullpr = (cih_get_level (scrhdrp) ==0 ) &&
@@ -9432,7 +9432,7 @@ display_dump_label(bool_t lockpr,assert (scrhdrp->cih_level >=0 );snprintf (level_string,sizeof (level_string),"%u" , - (uint )scrhdrp->cih_level); + (uint )cih_get_level (scrhdrp));uuid_unparse (grhdrp->gh_dumpid, dump_string_uuid);uuid_unparse (mrhdrp->mh_mediaid, media_string_uuid);
Signature · 1 line
2.43.0