Re: [PATCH 2/2] mkfs: Show progress during block discard

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Nov 22, 2019 at 05:27:42PM +0100, Pavel Reichl wrote:
> On Thu, Nov 21, 2019 at 10:59 PM Darrick J. Wong
> <darrick.wong@xxxxxxxxxx> wrote:
> >
> > On Thu, Nov 21, 2019 at 10:44:45PM +0100, Pavel Reichl wrote:
> > > Signed-off-by: Pavel Reichl <preichl@xxxxxxxxxx>
> > > ---
> > >  mkfs/xfs_mkfs.c | 8 ++++++++
> > >  1 file changed, 8 insertions(+)
> > >
> > > diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
> > > index a02d6f66..07b8bd78 100644
> > > --- a/mkfs/xfs_mkfs.c
> > > +++ b/mkfs/xfs_mkfs.c
> > > @@ -1248,6 +1248,7 @@ discard_blocks(dev_t dev, uint64_t nsectors)
> > >       const uint64_t  step            = (uint64_t)2<<30;
> > >       /* Sector size is 512 bytes */
> > >       const uint64_t  count           = nsectors << 9;
> > > +     uint64_t        prev_done       = (uint64_t) ~0;
> > >
> > >       fd = libxfs_device_to_fd(dev);
> > >       if (fd <= 0)
> > > @@ -1255,6 +1256,7 @@ discard_blocks(dev_t dev, uint64_t nsectors)
> > >
> > >       while (offset < count) {
> > >               uint64_t        tmp_step = step;
> > > +             uint64_t        done = offset * 100 / count;
> > >
> > >               if ((offset + step) > count)
> > >                       tmp_step = count - offset;
> > > @@ -1268,7 +1270,13 @@ discard_blocks(dev_t dev, uint64_t nsectors)
> > >                       return;
> > >
> > >               offset += tmp_step;
> > > +
> > > +             if (prev_done != done) {
> >
> > Hmm... so this prints the status message every increase percentage
> > point, right?
> 
> Not at all, the 'least change' it prints is one percent but that's the
> maximum granularity i.e. I tested with 10 GB file and the output was:
> 
> Discarding:  0% done
> Discarding: 20% done
> Discarding: 40% done
> Discarding: 60% done
> Discarding: 80% done
> Discarding is done.
> 
> So ATM there could be up to 102 lines - please propose a different idea.

if (device supports discard) {
	if (!quiet)
		printf(_("Discarding blocks, this may take some time..."));
	<discard loop>
}
<the rest of mkfs>

> 
> >
> > > +                     prev_done = done;
> > > +                     fprintf(stderr, _("Discarding: %2lu%% done\n"), done);
> >
> > This isn't an error, so why output to stderr?
> My bad, sorry.
> 
> >
> > FWIW if it's a tty you might consider ending that string with \r so the
> > status messages don't scroll off the screen.  Or possibly only reporting
> > status if stdout is a tty?
> 
> Do I get it right that you propose to not flow the terminal with
> dozens of lines which just update the percentage but instead keep
> updating the same line? If so, I do like that.

Correct.

--D

> >
> > --D
> >
> > > +             }
> > >       }
> > > +     fprintf(stderr, _("Discarding is done.\n"));
> > >  }
> > >
> > >  static __attribute__((noreturn)) void
> > > --
> > > 2.23.0
> > >
> >
> 



[Index of Archives]     [XFS Filesystem Development (older mail)]     [Linux Filesystem Development]     [Linux Audio Users]     [Yosemite Trails]     [Linux Kernel]     [Linux RAID]     [Linux SCSI]


  Powered by Linux