public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Eryu Guan <eguan@redhat.com>
To: "Darrick J. Wong" <darrick.wong@oracle.com>
Cc: xfs <linux-xfs@vger.kernel.org>, Eric Sandeen <sandeen@redhat.com>
Subject: Re: [PATCH] xfsdump: fix race condition between lseek() and read()/write()
Date: Tue, 28 Mar 2017 11:41:30 +0800	[thread overview]
Message-ID: <20170328034130.GT14226@eguan.usersys.redhat.com> (raw)
In-Reply-To: <20170327202030.GK5722@birch.djwong.org>

On Mon, Mar 27, 2017 at 01:20:30PM -0700, Darrick J. Wong wrote:
> [move to new list]
> 
> On Thu, Apr 21, 2016 at 09:06:56PM +0800, Eryu Guan wrote:
> > There's a race condition in the [get|put]_invtrecord() routines, because
> > a lseek() followed by a read()/write() is not atmoic, the file offset
> > might be changed before read()/write().
> > 
> > xfs/302 catches this failure as:
> > xfsdump: drive 1: INV : Unknown version 0 - Expected version 1
> > xfsdump: inv_core.c:66: get_counters: Assertion `((invt_counter_t *)(*cntpp))->ic_vernum == (inv_version_t) 1' failed.
> > 
> > And it can be reproduced by running multi-stream dump in a tight loop
> >   mount /dev/<dev> /mnt/xfs
> >   mkdir /mnt/xfs/dumpdir
> >   # populate dumpdir here
> >   while xfsdump -M l1 -M l2 -f d1 -f d2 -L ses /mnt/xfs -s dumpdir; do
> >   	:
> >   done
> > 
> > Fix it by replacing the "lseek(); read()/write()" sequence by
> > pread()/pwrite(), which make the seek and I/O an atomic operation.
> > 
> > Also convert and remove all *_SEEKCUR routines to "SEEK_SET" variants,
> > because they depend on the maintenance of current file offset, but
> > pread()/pwrite() don't change file offset.
> > 
> > Signed-off-by: Eryu Guan <eguan@redhat.com>
> > ---
> > 
> > Tested via the reproducer and xfstests "-g dump" run, with both v4 and v5 XFS.
> > 
> > I'm not sure if this is the right fix, perhaps what should be fixed is the
> > "INVLOCK()", which is now implemented by flock(2), and doesn't work in
> > multi-thread env, if what it's meant to protect is concurrent accesses from
> > different threads, not processes.
> > 
> > If so, it seems to me that making INVLOCK() a pthread rw lock could fix the
> > race condition as well. But the INVLOCK calls are almost everywhere, I didn't
> > find a simple way to try it.
> 
> I wonder, did this ever make any progress?  Offhand it looks ok, but then
> I'm no xfsdump expert.

No, you're the first one to comment on this patch :)

> 
> (Yes, our QA is bugging me about xfs/302 failures too...)

JFYI, xfs/059 and xfs/301 also fail due to this bug, just that xfs/059
failure rarely happens.

Thanks,
Eryu

  reply	other threads:[~2017-03-28  3:41 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-21 13:06 [PATCH] xfsdump: fix race condition between lseek() and read()/write() Eryu Guan
2017-03-27 20:20 ` Darrick J. Wong
2017-03-28  3:41   ` Eryu Guan [this message]
2017-07-12 18:26     ` Darrick J. Wong
2017-07-12 18:46 ` Eric Sandeen
2017-07-12 19:33   ` Eric Sandeen
2017-07-12 20:56 ` Eric Sandeen
2017-07-13  7:28   ` Eryu Guan
2017-07-13  8:41   ` [PATCH v2] " Eryu Guan
2017-07-13 20:10     ` Eric Sandeen

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=20170328034130.GT14226@eguan.usersys.redhat.com \
    --to=eguan@redhat.com \
    --cc=darrick.wong@oracle.com \
    --cc=linux-xfs@vger.kernel.org \
    --cc=sandeen@redhat.com \
    /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