xfsprogs: Fix uninitialized cfg->lsunit
PATCH v2 1/1 xfsprogs: Fix uninitialized cfg->lsunit
From: Allison Henderson <[email protected]>
While investigating another mkfs bug, noticed that cfg->lsunit is sometimes left uninitialized when it should not. This is because calc_stripe_factors in some cases needs cfg->loginternal to be set first. This is done in validate_logdev. So move calc_stripe_factors below validate_logdev while parsing configs.
--- mkfs/xfs_mkfs.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
mkfs/xfs_mkfs.c +4 -4
@@ -3861,15 +3861,15 @@ main( .isdirect = LIBXFS_DIRECT, .isreadonly = LIBXFS_EXCLUSIVELY, }; -struct xfs_mount mbuf = {}; +struct xfs_mount mbuf = {0 };struct xfs_mount *mp = &mbuf;struct xfs_sb *sbp = &mp->m_sb; -struct fs_topology ft = {}; +struct fs_topology ft = {0 };struct cli_params cli = { .xi = &xi, .loginternal =1 , }; -struct mkfs_params cfg = {}; +struct mkfs_params cfg = {0 };/* build time defaults */ struct mkfs_default_params dft = {
@@ -4008,7 +4008,6 @@ main( cfg.rtblocks =calc_dev_size (cli.rtsize, &cfg, &ropts,R_SIZE ,"rt" );validate_rtextsize (&cfg, &cli, &ft); -calc_stripe_factors (&cfg, &cli, &ft);/* * Open and validate the device configurations
@@ -4018,6 +4017,7 @@ main(validate_datadev (&cfg, &cli);validate_logdev (&cfg, &cli, &logfile);validate_rtdev (&cfg, &cli, &rtfile); +calc_stripe_factors (&cfg, &cli, &ft);/* * At this point when know exactly what size all the devices are,
Signature · 1 line
2.7.4
Quoted 11 lines · Allison Collins
From: Allison Henderson <[email protected]>
While investigating another mkfs bug, noticed that
cfg->lsunitis sometimes left uninitialized when it should not. This is becausecalc_stripe_factorsin some cases needscfg->loginternalto be set first. This is done invalidate_logdev. So movecalc_stripe_factorsbelowvalidate_logdevwhile parsing configs.Signed-off-by Allison Collins <[email protected]>Reviewed-by Darrick J. Wong <[email protected]>Reviewed-by Carlos Maiolino <[email protected]>
Ok, while I appreciate you taking Carlos's input, the patch now does far more than the commit log says, with no explanation of why it's doing so. (and there's no indication of what actually changed in V2: - putting that info below the "---" line is helpful)
I'd prefer to take the original patch and if we really want to change how we initialize empty structures, that should be a separate patch, and should hit everywhere we do it, not just mkfs.
But to Carlos's point, cfg->lsunit isn't exactly "uninitialized" (to me, uninitialized means that it was never set, when in fact it was initialized, to zero, right?)
So it's not quite clear to me what's happening here; I guess this test:
/*
* check that log sunit is modulo fsblksize or default it to dsunit.
*/
if (lsunit) {
/* convert from 512 byte blocks to fs blocks */
cfg->lsunit = DTOBT(lsunit, cfg->blocklog);
} else if (cfg->sb_feat.log_version == 2 &&
cfg->loginternal && cfg->dsunit) {
/* lsunit and dsunit now in fs blocks */
cfg->lsunit = cfg->dsunit;
}is doing the wrong thing because cfg->loginternal hasn't actually been evaluated yet? Is there a mkfs command that demonstrates the problem which could be included in the changelog? Does it only happen with external logs? If you can provide a bit more information about when and how this actually fails, that would improve the changelog for future generations.
(also agreeing w/ darrick that these seem like little time bombs...)
Thanks,
-Eric
Quoted 44 lines
--- mkfs/xfs_mkfs.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)mkfs/xfs_mkfs.c +4
-4@@ -3861,15 +3861,15 @@ main( .isdirect = LIBXFS_DIRECT, .isreadonly = LIBXFS_EXCLUSIVELY, }; -struct xfs_mount mbuf = {}; +struct xfs_mount mbuf = {0 };struct xfs_mount *mp = &mbuf;struct xfs_sb *sbp = &mp->m_sb; -struct fs_topology ft = {}; +struct fs_topology ft = {0 };struct cli_params cli = { .xi = &xi, .loginternal =1 , }; -struct mkfs_params cfg = {}; +struct mkfs_params cfg = {0 };/* build time defaults */ struct mkfs_default_params dft = {@@ -4008,7 +4008,6 @@ main( cfg.rtblocks =calc_dev_size (cli.rtsize, &cfg, &ropts,R_SIZE ,"rt" );validate_rtextsize (&cfg, &cli, &ft); -calc_stripe_factors (&cfg, &cli, &ft);/* * Open and validate the device configurations @@ -4018,6 +4017,7 @@ main(validate_datadev (&cfg, &cli);validate_logdev (&cfg, &cli, &logfile);validate_rtdev (&cfg, &cli, &rtfile); +calc_stripe_factors (&cfg, &cli, &ft);/* * At this point when know exactly what size all the devices are,
Quoted 13 lines · Eric Sandeen
Quoted 11 lines · Allison Collins
From: Allison Henderson <[email protected]>
While investigating another mkfs bug, noticed that
cfg->lsunitis sometimes left uninitialized when it should not. This is becausecalc_stripe_factorsin some cases needscfg->loginternalto be set first. This is done invalidate_logdev. So movecalc_stripe_factorsbelowvalidate_logdevwhile parsing configs.Signed-off-by Allison Collins <[email protected]>Reviewed-by Darrick J. Wong <[email protected]>Reviewed-by Carlos Maiolino <[email protected]>
Quoted 8 lines
Ok, while I appreciate you taking Carlos's input, the patch now does far more than the commit log says, with no explanation of why it's doing so. (and there's no indication of what actually changed in V2: - putting that info below the "---" line is helpful)
I'd prefer to take the original patch and if we really want to change how we initialize empty structures, that should be a separate patch, and should hit everywhere we do it, not just mkfs.
Ok so I was on track up to here
Quoted 3 lines
But to Carlos's point,
cfg->lsunitisn't exactly "uninitialized" (to me, uninitialized means that it was never set, when in fact it was initialized, to zero, right?)
and I guess this is just semantics...
Quoted 14 lines
So it's not quite clear to me what's happening here; I guess this test:
/* * check that log sunit is modulo fsblksize or default it to dsunit. */ if (lsunit) { /* convert from 512 byte blocks to fs blocks */ cfg->lsunit = DTOBT(lsunit, cfg->blocklog); } else if (cfg->sb_feat.log_version == 2 && cfg->loginternal && cfg->dsunit) { /* lsunit and dsunit now in fs blocks */ cfg->lsunit = cfg->dsunit; }
Quoted 6 lines
is doing the wrong thing because
cfg->loginternalhasn't actually been evaluated yet? Is there a mkfs command that demonstrates the problem which could be included in the changelog? Does it only happen with external logs? If you can provide a bit more information about when and how this actually fails, that would improve the changelog for future generations.
OK, TBH I had confused cfg-> with cli-> (derp) and I see that as you said, validate_logdev() sets up cfg->loginternal, sorry. So I'm ok with V1 and its changelog as it stands, I think.
Sorry for my confusion and the noise,
-Eric
Quoted 50 lines
(also agreeing w/ darrick that these seem like little time bombs...)
Thanks,
-EricQuoted 44 lines
--- mkfs/xfs_mkfs.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)mkfs/xfs_mkfs.c +4
-4@@ -3861,15 +3861,15 @@ main( .isdirect = LIBXFS_DIRECT, .isreadonly = LIBXFS_EXCLUSIVELY, }; -struct xfs_mount mbuf = {}; +struct xfs_mount mbuf = {0 };struct xfs_mount *mp = &mbuf;struct xfs_sb *sbp = &mp->m_sb; -struct fs_topology ft = {}; +struct fs_topology ft = {0 };struct cli_params cli = { .xi = &xi, .loginternal =1 , }; -struct mkfs_params cfg = {}; +struct mkfs_params cfg = {0 };/* build time defaults */ struct mkfs_default_params dft = {@@ -4008,7 +4008,6 @@ main( cfg.rtblocks =calc_dev_size (cli.rtsize, &cfg, &ropts,R_SIZE ,"rt" );validate_rtextsize (&cfg, &cli, &ft); -calc_stripe_factors (&cfg, &cli, &ft);/* * Open and validate the device configurations @@ -4018,6 +4017,7 @@ main(validate_datadev (&cfg, &cli);validate_logdev (&cfg, &cli, &logfile);validate_rtdev (&cfg, &cli, &rtfile); +calc_stripe_factors (&cfg, &cli, &ft);/* * At this point when know exactly what size all the devices are,
Quoted 52 lines · Eric Sandeen
Quoted 13 lines · Eric Sandeen
Quoted 11 lines · Allison Collins
From: Allison Henderson <[email protected]>
While investigating another mkfs bug, noticed that
cfg->lsunitis sometimes left uninitialized when it should not. This is becausecalc_stripe_factorsin some cases needscfg->loginternalto be set first. This is done invalidate_logdev. So movecalc_stripe_factorsbelowvalidate_logdevwhile parsing configs.Signed-off-by Allison Collins <[email protected]>Reviewed-by Darrick J. Wong <[email protected]>Reviewed-by Carlos Maiolino <[email protected]>Quoted 8 lines
Ok, while I appreciate you taking Carlos's input, the patch now does far more than the commit log says, with no explanation of why it's doing so. (and there's no indication of what actually changed in V2: - putting that info below the "---" line is helpful)
I'd prefer to take the original patch and if we really want to change how we initialize empty structures, that should be a separate patch, and should hit everywhere we do it, not just mkfs.
Ok so I was on track up to here
Quoted 3 lines
But to Carlos's point,
cfg->lsunitisn't exactly "uninitialized" (to me, uninitialized means that it was never set, when in fact it was initialized, to zero, right?)and I guess this is just semantics...
Quoted 14 lines
So it's not quite clear to me what's happening here; I guess this test:
/* * check that log sunit is modulo fsblksize or default it to dsunit. */ if (lsunit) { /* convert from 512 byte blocks to fs blocks */ cfg->lsunit = DTOBT(lsunit, cfg->blocklog); } else if (cfg->sb_feat.log_version == 2 && cfg->loginternal && cfg->dsunit) { /* lsunit and dsunit now in fs blocks */ cfg->lsunit = cfg->dsunit; }Quoted 6 lines
is doing the wrong thing because
cfg->loginternalhasn't actually been evaluated yet? Is there a mkfs command that demonstrates the problem which could be included in the changelog? Does it only happen with external logs? If you can provide a bit more information about when and how this actually fails, that would improve the changelog for future generations.
Quoted 7 lines
OK, TBH I had confused cfg-> with cli-> (derp) and I see that as you said,
validate_logdev()sets upcfg->loginternal, sorry. So I'm ok with V1 and its changelog as it stands, I think.Sorry for my confusion and the noise,
-Eric
Alrighty then, I think I answered all your other questions in the IRC chat. Thank you!!
Allison
Quoted 51 lines
Quoted 51 lines
(also agreeing w/ darrick that these seem like little time bombs...)
Thanks,
-EricQuoted 44 lines
--- mkfs/xfs_mkfs.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)mkfs/xfs_mkfs.c +4
-4@@ -3861,15 +3861,15 @@ main( .isdirect = LIBXFS_DIRECT, .isreadonly = LIBXFS_EXCLUSIVELY, }; -struct xfs_mount mbuf = {}; +struct xfs_mount mbuf = {0 };struct xfs_mount *mp = &mbuf;struct xfs_sb *sbp = &mp->m_sb; -struct fs_topology ft = {}; +struct fs_topology ft = {0 };struct cli_params cli = { .xi = &xi, .loginternal =1 , }; -struct mkfs_params cfg = {}; +struct mkfs_params cfg = {0 };/* build time defaults */ struct mkfs_default_params dft = {@@ -4008,7 +4008,6 @@ main( cfg.rtblocks =calc_dev_size (cli.rtsize, &cfg, &ropts,R_SIZE ,"rt" );validate_rtextsize (&cfg, &cli, &ft); -calc_stripe_factors (&cfg, &cli, &ft);/* * Open and validate the device configurations @@ -4018,6 +4017,7 @@ main(validate_datadev (&cfg, &cli);validate_logdev (&cfg, &cli, &logfile);validate_rtdev (&cfg, &cli, &rtfile); +calc_stripe_factors (&cfg, &cli, &ft);/* * At this point when know exactly what size all the devices are,