Util-Linux package development
 help / color / mirror / Atom feed
From: Stanislav Brabec <sbrabec@suse.cz>
To: Karel Zak <kzak@redhat.com>
Cc: Ruediger Meier <sweet_f_a@gmx.de>,
	util-linux@vger.kernel.org, David Sterba <dsterba@suse.cz>
Subject: Re: [PATCH] tests: add test for loop option in fstab (my mistake, and two new bugs, one in kernel)
Date: Tue, 1 Mar 2016 16:26:33 +0100	[thread overview]
Message-ID: <56D5B4A9.4020805@suse.cz> (raw)
In-Reply-To: <56CF5691.5010006@suse.cz>

On Feb 25, 2016 at 20:31 Stanislav Brabec wrote:
> On Feb 24, 2016 at 22:33 Stanislav Brabec wrote:
> 
>> => It looks like a kernel bug.
>> Kernel is openSUSE Tumbleweed linux-4.4.1-1.
> 
> Analyzed and sent to LKML.
> http://marc.info/?l=linux-kernel&m=145642818824430&w=2
> 
> It seems that problem reported here is triggered by multiple mounts 
> using multiple loop devices pointing to the same file.
> 
And not only that it breaks structures.

Even if structures will be kept in order, it will cause data
corruption: kernel does not have an information, that both loop devices
point to the same device:

Here is an analysis of Al Viro[1]:

Sigh...  sys_mount() (mount_bdev(), actually) has no way to tell if two
loop devices refer to the same underlying object.  As far as it's
concerned, you are asking to mount a completely unrelated block device.
Which just happens to see the data (living in separate pagecache, even)
modified behind its back (with some delay) after it gets written to another
device.  Filesystem drivers generally don't like when something is screwing
the underlying data, to put it mildly...

When you ask to mount the _same_ device, mount_bdev(), as well as btrfs
counterpart, makes sure that you get a reference to the same struct
super_block, which avoids all coherency problems - all mounted instances
refer to the same in-core objects (dentries, inodes, page cache, etc.).
They get separate struct vfsmount instances, but that only matters for
mountpoint crossing.

As soon as you've set the second /dev/loop alias for the same underlying
file, you are asking for all kinds of trouble.  If you use the same one
consistently, you are OK.  BTW, even
losetup /dev/loop0 /dev/sda1
mount -t ext2 /dev/sda1 /mnt/1
mount -t ext2 /dev/loop0 /mnt/2
is enough for trouble - you get (as far as ext2 knows) unrelated devices
screwing each other, with no good way to predict that.  And you need to
check propagation through more than one layer - loop over loop over block
is also possible.

IMO on-demand losetup a-la -o loop is simply a bad idea...

References:
[1] https://lkml.org/lkml/2016/2/26/897

-- 
Best Regards / S pozdravem,

Stanislav Brabec
software developer
---------------------------------------------------------------------
SUSE LINUX, s. r. o.                         e-mail: sbrabec@suse.com
Lihovarská 1060/12                            tel: +49 911 7405384547
190 00 Praha 9                                 fax:  +420 284 084 001
Czech Republic                                    http://www.suse.cz/
PGP: 830B 40D5 9E05 35D8 5E27 6FA3 717C 209F A04F CD76

      reply	other threads:[~2016-03-01 15:26 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-11 19:45 [PATCH] tests: add test for loop option in fstab Stanislav Brabec
2016-02-12 10:10 ` Karel Zak
2016-02-12 15:28 ` Ruediger Meier
2016-02-12 15:55   ` Stanislav Brabec
2016-02-15 11:42 ` Ruediger Meier
2016-02-16 14:49   ` Karel Zak
2016-02-19 18:27     ` Stanislav Brabec
2016-02-22 10:12       ` Karel Zak
2016-02-22 10:29         ` Ruediger Meier
2016-02-22 10:53           ` Karel Zak
2016-02-22 16:36         ` Stanislav Brabec
2016-02-24 18:58           ` Stanislav Brabec
2016-02-24 21:33             ` [PATCH] tests: add test for loop option in fstab (my mistake, and two new bugs, one in kernel) Stanislav Brabec
2016-02-25 19:31               ` Stanislav Brabec
2016-03-01 15:26                 ` Stanislav Brabec [this message]

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=56D5B4A9.4020805@suse.cz \
    --to=sbrabec@suse.cz \
    --cc=dsterba@suse.cz \
    --cc=kzak@redhat.com \
    --cc=sweet_f_a@gmx.de \
    --cc=util-linux@vger.kernel.org \
    /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