From: Chris Mason <chris.mason@oracle.com>
To: CSights <csights@fastmail.fm>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: metadata copied/data not copied?
Date: Tue, 17 Mar 2009 13:24:45 -0400 [thread overview]
Message-ID: <1237310685.31273.31.camel@think.oraclecorp.com> (raw)
In-Reply-To: <200903171308.05848.csights@fastmail.fm>
On Tue, 2009-03-17 at 13:08 -0400, CSights wrote:
> Hi everyone,
>
> > > Here is an expanded example which is how I imagined COW would handle
> > > changes to the file's data ("file contents"). One can pretend it is an
> > > attempt to inject malicious code into /bin/sh (e.g. file1 is /bin/sh).
> > >
> > > [METADATA] --> DATA
> > > [file1 perms olduser:oldgroup] --> file contents
> > >
> > >
> > > # cp file1 file2
> > > [file1 perms olduser:oldgroup "COW"] \
> > > --> file contents
> > > [file1 perms olduser:oldgroup "COW"] /
> > > (A "COW" flag is set in btrfs's (hidden) metadata.)
> > >
> > >
> > > # chown newuser:newgroup file2
> > > [file1 perms olduser:oldgroup "COW"] \
> > > --> file contents
> > > [file1 perms newuser:newgroup "COW"] /
> > > (chown, chmod, others? are not "writes" to file contents, so file
> > > contents don't need to be copied-on-write yet.)
> > >
> > >
> > > # cat newcontent >> file2
> > > [file1 perms olduser:oldgroup] --> file contents
> > > [file2 perms newuser:newgroup] --> file contents + newcontent
> > > (File contents are modified. This is a "write" that triggers COW. The
> > > file contents are copied and then modified. Metadata for file2 are hooked
> > > up to copied then modified file contents. "COW" flag is cleared.)
> >
> > It would work, but it is slightly different from how btrfs works. There
> > are two ways to read COW (copy on write):
> >
> > 1) Before changing something, make a copy of the old data and put it
> > somewhere else. Then overwrite the original location.
> >
> > 2) Don't ever overwrite the original location, write somewhere new
> > instead. The old copy stays in the original location.
> >
> > Btrfs does #2.
>
> Does the choice #1 or #2 change whether the extended example works or not?
> It seems as though either way makes sense for the example given...?
>
Yes, either way works. #1 is what lvm snapshotting uses, which avoids
fragmentation of the original, but it doesn't scale well to lots of
snapshots.
> > The bcp command creates a second inode that points to the same data
> > extents as the first inode. So, modifications to the inodes themselves
> > (such as chown, chmod, touch etc) don't touch the data extents.
> >
> > Modifications to the data extents go through the COW mechanism to make
> > sure we don't overwrite the originals.
>
> To me it sounds like if cp were replaced with bcp, then btrfs would behave as
> I imagined in my example...
The long term goal is to get cp to use a new system call to cow link
files.
> Why is a "bcp" separate from cp needed? Is it because with cp btrfs
> doesn't "know" a simple copy is being made, but just gets a stream of data to
> write to disk?
> Is it possible to update cp to do the btrfs ioctl automatically, or must the
> commands always remain separate because there are situations where it would
> be a problem for the file contents to be COW? (It seems to me the fact that
> the data contents are COW would be transparent to userland apps, so the bcp
> ioctl could be built in to cp.)
>
> Looking forward to (a stable) btrfs!
> Eager User. :)
;)
-chris
next prev parent reply other threads:[~2009-03-17 17:24 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-16 14:35 metadata copied/data not copied? CSights
2009-03-16 15:28 ` jim owens
2009-03-17 0:25 ` Chris Mason
2009-03-17 15:34 ` CSights
2009-03-17 15:56 ` Chris Mason
2009-03-17 17:08 ` CSights
2009-03-17 17:24 ` Chris Mason [this message]
2009-03-16 21:14 ` Dmitri Nikulin
2009-03-16 21:18 ` Dmitri Nikulin
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=1237310685.31273.31.camel@think.oraclecorp.com \
--to=chris.mason@oracle.com \
--cc=csights@fastmail.fm \
--cc=linux-btrfs@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.