From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: Eric Sandeen <sandeen@sandeen.net>
Cc: sandeen@redhat.com, linux-xfs@vger.kernel.org
Subject: Re: [PATCH 1/8] xfs_scrub_all: walk the lsblk device/fs hierarchy correctly
Date: Mon, 4 Feb 2019 10:16:49 -0800 [thread overview]
Message-ID: <20190204181649.GX5761@magnolia> (raw)
In-Reply-To: <d4cd6eba-2767-9fea-ea98-2416fe5c2ba4@sandeen.net>
On Mon, Feb 04, 2019 at 12:08:49PM -0600, Eric Sandeen wrote:
> On 12/19/18 1:29 PM, Darrick J. Wong wrote:
> > From: Darrick J. Wong <darrick.wong@oracle.com>
> >
> > Back when I was designing xfs_scrub_all, I naïvely assumed that the
> > emitted output would always list physical storage before the virtual
> > devices stacked atop it. However, this is not actually true when one
> > omits the "NAME" column, which is crucial to forcing the output (json or
> > otherwise) to capture the block device hierarchy. If the assumption is
> > violated, the program crashes with a python exception.
>
> Is this a quirk or a documented feature of lsblk?
Not a documented feature, but seems to be a fairly common behavioral
quirk?
> > To fix this, force the hierarchal json output and restructure the
> > discovery routines to walk the json object that we receive, from the top
> > (physical devices) downwards to wherever there are live xfs filesystems.
> >
> > Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> > ---
> > scrub/xfs_scrub_all.in | 28 +++++++++++++++++-----------
> > 1 file changed, 17 insertions(+), 11 deletions(-)
> >
> >
> > diff --git a/scrub/xfs_scrub_all.in b/scrub/xfs_scrub_all.in
> > index c4e9899d..5b76b49a 100644
> > --- a/scrub/xfs_scrub_all.in
> > +++ b/scrub/xfs_scrub_all.in
> > @@ -28,9 +28,21 @@ def DEVNULL():
> >
> > def find_mounts():
> > '''Map mountpoints to physical disks.'''
> > + def find_xfs_mounts(bdev, fs, lastdisk):
> > + '''Attach lastdisk to each fs found under bdev.'''
> > + if bdev['fstype'] == 'xfs' and bdev['mountpoint'] is not None:
> > + mnt = bdev['mountpoint']
> > + if mnt in fs:
> > + fs[mnt].add(lastdisk)
> > + else:
> > + fs[mnt] = set([lastdisk])
> > + if 'children' not in bdev:
> > + return
> > + for child in bdev['children']:
> > + find_xfs_mounts(child, fs, lastdisk)
> >
> > fs = {}
> > - cmd=['lsblk', '-o', 'KNAME,TYPE,FSTYPE,MOUNTPOINT', '-J']
> > + cmd=['lsblk', '-o', 'NAME,KNAME,TYPE,FSTYPE,MOUNTPOINT', '-J']
>
> sorry for the ridonculously late review, and although '-J" isn't added
> new in this patch, FYI at least RHEL7 does not allow it:
>
> # lsblk -o KNAME -J
> lsblk: invalid option -- 'J'
>
> ... thoughts? Probably should be handled gracefully at least?
lsblk returns 1 for unrecognized arguments, so xfs_scrub_all will bail
if lsblk barfs. Not sure if we want to divert lsblk's stderr to
/dev/null or just let it spray out sloppily like we do now?
(Practically speaking I suspect that distros will pick up the util-linux
release that has json support before they pick up XFS kernel scrub...
but I should at least make sure that's really true.)
--D
> -Eric
>
> > result = subprocess.Popen(cmd, stdout=subprocess.PIPE)
> > result.wait()
> > if result.returncode != 0:
> > @@ -38,18 +50,12 @@ def find_mounts():
> > sarray = [x.decode(sys.stdout.encoding) for x in result.stdout.readlines()]
> > output = ' '.join(sarray)
> > bdevdata = json.loads(output)
> > +
> > # The lsblk output had better be in disks-then-partitions order
> > for bdev in bdevdata['blockdevices']:
> > - if bdev['type'] in ('disk', 'loop'):
> > - lastdisk = bdev['kname']
> > - if bdev['fstype'] == 'xfs':
> > - mnt = bdev['mountpoint']
> > - if mnt is None:
> > - continue
> > - if mnt in fs:
> > - fs[mnt].add(lastdisk)
> > - else:
> > - fs[mnt] = set([lastdisk])
> > + lastdisk = bdev['kname']
> > + find_xfs_mounts(bdev, fs, lastdisk)
> > +
> > return fs
> >
> > def kill_systemd(unit, proc):
> >
next prev parent reply other threads:[~2019-02-04 18:16 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-19 19:29 [PATCH 0/8] xfsprogs: various fixes Darrick J. Wong
2018-12-19 19:29 ` [PATCH 1/8] xfs_scrub_all: walk the lsblk device/fs hierarchy correctly Darrick J. Wong
2019-02-04 18:08 ` Eric Sandeen
2019-02-04 18:16 ` Darrick J. Wong [this message]
2019-02-04 18:27 ` Eric Sandeen
2018-12-19 19:29 ` [PATCH 2/8] xfs_scrub_all.timer: activate after most of the system is up Darrick J. Wong
2019-02-04 18:12 ` Eric Sandeen
2018-12-19 19:29 ` [PATCH 3/8] xfs_scrub: rename the global nr_threads Darrick J. Wong
2019-02-04 18:20 ` Eric Sandeen
2018-12-19 19:29 ` [PATCH 4/8] xfs_scrub: use datadev parallelization estimates for thread count Darrick J. Wong
2019-02-04 18:31 ` Eric Sandeen
2019-02-04 18:34 ` Darrick J. Wong
2018-12-19 19:30 ` [PATCH 5/8] xfs_scrub: use data/rtdev parallelization estimates for the read-verify pool Darrick J. Wong
2019-02-04 18:35 ` Eric Sandeen
2019-02-04 18:38 ` Darrick J. Wong
2019-02-05 2:23 ` Darrick J. Wong
2018-12-19 19:30 ` [PATCH 6/8] xfs_repair: reinitialize the root directory nlink correctly Darrick J. Wong
2018-12-19 20:24 ` Bill O'Donnell
2019-02-04 19:19 ` Eric Sandeen
2018-12-19 19:30 ` [PATCH 7/8] xfs_repair: bump the irec on-disk nlink when adding lost+found Darrick J. Wong
2018-12-19 20:30 ` Bill O'Donnell
2018-12-19 19:30 ` [PATCH 8/8] xfs_repair: fix uninitialized variable warnings Darrick J. Wong
2018-12-19 20:25 ` Bill O'Donnell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190204181649.GX5761@magnolia \
--to=darrick.wong@oracle.com \
--cc=linux-xfs@vger.kernel.org \
--cc=sandeen@redhat.com \
--cc=sandeen@sandeen.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox