]> www.infradead.org Git - users/jedix/linux-maple.git/log
users/jedix/linux-maple.git
13 years agoBtrfs: check unused against how much space we actually want
Josef Bacik [Thu, 22 Sep 2011 18:30:02 +0000 (14:30 -0400)]
Btrfs: check unused against how much space we actually want

There is a bug that may lead to early ENOSPC in our reservation code.  We've
been checking against num_bytes which may be above and beyond what we want to
actually reserve, which could give us a false ENOSPC.  Fix this by making sure
the unused space is above how much we want to reserve and not how much we're
trying to flush.  Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
(cherry picked from commit ef3be45722317f8c2fb0e861065df0c3830ff9ac)

13 years agoBtrfs: fix orphan cleanup regression
Josef Bacik [Wed, 21 Sep 2011 20:55:59 +0000 (16:55 -0400)]
Btrfs: fix orphan cleanup regression

In fixing how we deal with bad inodes, we had a regression in the orphan cleanup
code, since it expects to get a bad inode back.  So fix it to deal with getting
-ESTALE back by deleting the orphan item manually and moving on.  Thanks,

Reported-by: Simon Kirby <sim@hostway.ca>
Signed-off-by: Josef Bacik <josef@redhat.com>
(cherry picked from commit a8c9e5769718d47e87cce40c9b84cab421804797)

13 years agoBtrfs: use the inode's mapping mask for allocating pages
Josef Bacik [Wed, 21 Sep 2011 19:05:58 +0000 (15:05 -0400)]
Btrfs: use the inode's mapping mask for allocating pages

Johannes pointed out we were allocating only kernel pages for doing writes,
which is kind of a big deal if you are on 32bit and have more than a gig of ram.
So fix our allocations to use the mapping's gfp but still clear __GFP_FS so we
don't re-enter.  Thanks,

Reported-by: Johannes Weiner <jweiner@redhat.com>
Signed-off-by: Josef Bacik <josef@redhat.com>
(cherry picked from commit 3b16a4e3c355ee3c790473decfcf83d4faeb8ce0)

13 years agoBtrfs: delay iput when deleting a block group
Josef Bacik [Mon, 19 Sep 2011 16:26:24 +0000 (12:26 -0400)]
Btrfs: delay iput when deleting a block group

I kept getting warnings from evict because we were calling
btrfs_start_transaction() with a transaction already started when doing a
balance.  This is because we remove a block group which requires a transaction,
and the put the last reference on the cache inode.  Instead of doing this we
need to delay the iput so it is done not within a transaction having started.
This gets rid of our warnings.  Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
(cherry picked from commit 455757c322cc0a0f2a692c5625dd88aaf6a7b889)

13 years agoBtrfs: make sure to unset trans->block_rsv before running delayed refs
Josef Bacik [Mon, 19 Sep 2011 15:58:54 +0000 (11:58 -0400)]
Btrfs: make sure to unset trans->block_rsv before running delayed refs

Checksums are charged in 2 different ways.  The first case is when we're writing
to the disk, we account for the new checksums with the delalloc block rsv.  In
order for this to work we check if we're allocating a block for the csum root
and if trans->block_rsv == the delalloc block rsv.  But when we're deleting the
csums because of cow, this is charged to the global block rsv, and is done when
we run the delayed refs.  So we need to make sure that trans->block_rsv == NULL
when running the delayed refs.  So set it to NULL and reset it in
should_end_transaction, and set it to NULL in commit_transaction.  This got rid
of the ridiculous amount of warnings I was seeing when trying to do a balance.
Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
(cherry picked from commit 9c8d86db9aee6f85866d480e0f9b37817264814c)

13 years agoBtrfs: stop passing a trans handle all around the reservation code
Josef Bacik [Tue, 30 Aug 2011 16:34:28 +0000 (12:34 -0400)]
Btrfs: stop passing a trans handle all around the reservation code

The only thing that we need to have a trans handle for is in
reserve_metadata_bytes and thats to know how much flushing we can do.  So
instead of passing it around, just check current->journal_info for a
trans_handle so we know if we can commit a transaction to try and free up space
or not.  Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
(cherry picked from commit 4a92b1b8d2810db4ea0c34616b94c0b3810fa027)

13 years agoBtrfs: don't get the block_rsv in btrfs_free_tree_block
Josef Bacik [Tue, 30 Aug 2011 15:40:48 +0000 (11:40 -0400)]
Btrfs: don't get the block_rsv in btrfs_free_tree_block

Since the durable block rsv stuff has been killed there is no need to get the
block_rsv in btrfs_free_tree_block anymore.

Signed-off-by: Josef Bacik <josef@redhat.com>
(cherry picked from commit d02c9955ded7fc56dd1edc987558b084ccb03eb4)

13 years agoBtrfs: use the transactions block_rsv for the csum root
Josef Bacik [Tue, 30 Aug 2011 15:31:29 +0000 (11:31 -0400)]
Btrfs: use the transactions block_rsv for the csum root

The alloc warnings everybody has been seeing is because we have been reserving
space for csums, but we weren't actually using that space.  So make
get_block_rsv() return the trans->block_rsv if we're modifying the csum root.
Also set the trans->block_rsv to NULL so that if we modify the csum root when
running delayed ref's that comes out of the global reserve like it's supposed
to.  With this patch I'm not seeing those alloc warnings anymore.  Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
(cherry picked from commit 4c13d758b7e79c14a0026c1f783f0c79e339b7bb)

13 years agoBtrfs: handle enospc accounting for free space inodes
Josef Bacik [Tue, 30 Aug 2011 14:19:10 +0000 (10:19 -0400)]
Btrfs: handle enospc accounting for free space inodes

Since free space inodes now use normal checksumming we need to make sure to
account for their metadata use.  So reserve metadata space, and then if we fail
to write out the metadata we can just release it, otherwise it will be freed up
when the io completes.  Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
(cherry picked from commit c09544e07f8cdc455ed8615d4c067d694c33bd18)

13 years agoBtrfs: put the block group cache after we commit the super
Josef Bacik [Mon, 29 Aug 2011 18:06:00 +0000 (14:06 -0400)]
Btrfs: put the block group cache after we commit the super

In moving some enospc stuff around I noticed that when we unmount we are often
evicting the free space cache inodes before we do our last commit.  This isn't
bad, but it makes us constantly have to re-read the inodes back.  So instead
don't evict the cache until after we do our last commit, this will make things a
little less crappy and makes a future enospc change work properly.  Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
(cherry picked from commit 300e4f8a56f263797568c95b71c949f9f02e4534)

13 years agoBtrfs: set truncate block rsv's size
Josef Bacik [Mon, 29 Aug 2011 15:01:31 +0000 (11:01 -0400)]
Btrfs: set truncate block rsv's size

While debugging a different issue I noticed that we were always reserving space
when we tried to use our truncate block rsv's.  This is because they didn't have
a ->size value, so use_block_rsv just assumes there is nothing reserved and it
does a reserve_metadata_bytes.  This is because btrfs_check_block_rsv() doesn't
actually add to the size of the block rsv.  That seems to be the right thing to
do so set ->size to the minimum truncate size we need, since we will always only
refill to that size anyway, and this way everything works out correctly.

Signed-off-by: Josef Bacik <josef@redhat.com>
(cherry picked from commit 4a33854257764c2ec6337ee0c8ecafb64f8e29e1)

13 years agoBtrfs: don't increase the block_rsv's size when emergency allocating space
Josef Bacik [Mon, 22 Aug 2011 19:23:19 +0000 (15:23 -0400)]
Btrfs: don't increase the block_rsv's size when emergency allocating space

If we have to emergency reserve space we need to not increase the block_rsv
size, otherwise we'll leak space.  Take for instance delalloc, say we reserve
4k, and we use that 4k, and then we have to emergency allocate another 4k, we
bump the size up to 8k, however we've only accounted for 4k in reservations in
all of our supporting logic, so we'll go to free the 4k and end up having a size
of 4k, which will cause us to later not free as much space.  I saw this doing
testing where I wasn't reserving enough space for something but was still
leaking space, very frustrating.  Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
(cherry picked from commit 7f70150896ebd1169d9c43484c8c424f755353c4)

13 years agoBtrfs: fix space leak when we fail to make an allocation
Josef Bacik [Fri, 19 Aug 2011 19:45:52 +0000 (15:45 -0400)]
Btrfs: fix space leak when we fail to make an allocation

When changing back to using a spin_lock to protect the extent counters I decided
that since we would only be dropping our original extent, it was ok to just drop
the extent and return.  However since somebody else could have come in and done
a reservation, we need to do the normal song and dance to clear the reservation
out properly.  So calculate how much space we need to free, and then subtract
what we just attempted to reserve.  If it's more then we know we need to drop
those bytes from the delalloc block rsv.  Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
(cherry picked from commit 7ed49f187c82821e35f8869399bcf90822a74a23)

13 years agoBtrfs: fix call to btrfs_search_slot in free space cache
Josef Bacik [Fri, 19 Aug 2011 16:06:12 +0000 (12:06 -0400)]
Btrfs: fix call to btrfs_search_slot in free space cache

We are setting ins_len to 1 even tho we are just modifying an item that should
be there already.  This may cause the search stuff to split nodes on the way
down needelessly.  Set this to 0 since we aren't inserting anything.  Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
(cherry picked from commit a9b5fcddce594a408a48d523087b5bb64ce82469)

13 years agoBtrfs: allow callers to specify if flushing can occur for btrfs_block_rsv_check
Josef Bacik [Fri, 19 Aug 2011 14:31:56 +0000 (10:31 -0400)]
Btrfs: allow callers to specify if flushing can occur for btrfs_block_rsv_check

If you run xfstest 224 it you will get lots of messages about not being able to
delete inodes and that they will be cleaned up next mount.  This is because
btrfs_block_rsv_check was not calling reserve_metadata_bytes with the ability to
flush, so if there was not enough space, it simply failed.  But in truncate and
evict case we could easily flush space to try and get enough space to do our
work, so make btrfs_block_rsv_check take a flush argument to pass down to
reserve_metadata_bytes.  Now xfstests 224 runs fine without all those
complaints.  Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
(cherry picked from commit 482e6dc5261406fdb921946e70b51467b0305bad)

13 years agoBtrfs: reduce the amount of space needed for truncates
Josef Bacik [Fri, 19 Aug 2011 14:29:59 +0000 (10:29 -0400)]
Btrfs: reduce the amount of space needed for truncates

With btrfs_truncate_inode_items we always return if we have to go to another
leaf, which makes us do our reservation again.  This means we will only ever
modify one leaf at a time, so we only need 1 items worth of slack space.  Also,
since we are deleting we will not be creating nodes as we go down, if anything
we'll be free'ing them as we merge them together, so make a different
calculation for truncate which will only have the worst case useage of COW'ing
the entire path down to the leaf.  Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
(cherry picked from commit 07127184efb629f1336c0592bfdacec258cab731)

13 years agoBtrfs: only reserve space in fallocate if we have to do a preallocate
Josef Bacik [Wed, 17 Aug 2011 14:19:52 +0000 (10:19 -0400)]
Btrfs: only reserve space in fallocate if we have to do a preallocate

Lukas found a problem where if he tries to fallocate over the same region twice
and the first fallocate took up all the space we would fail with ENOSPC.  This
is because we reserve the total space we want to use for fallocate, regardless
of wether or not we will have to actually preallocate.  So instead move the
check into the loop where we actually have to do the preallocate.  Thanks,

Tested-by: Lukas Czerner <lczerner@redhat.com>
Signed-off-by: Josef Bacik <josef@redhat.com>
(cherry picked from commit 1b9c332b6c92e992b1971a08412c6f460a54b514)

13 years agoBtrfs: kill btrfs_truncate_reserve_metadata
Josef Bacik [Mon, 8 Aug 2011 18:03:37 +0000 (14:03 -0400)]
Btrfs: kill btrfs_truncate_reserve_metadata

Since we've optimized the truncate path, we no longer require this function.

Signed-off-by: Josef Bacik <josef@redhat.com>
(cherry picked from commit 5e962c7850c273b483acc747b41bd5cddf631049)

13 years agoBtrfs: optimize how we account for space in truncate
Josef Bacik [Mon, 8 Aug 2011 17:46:15 +0000 (13:46 -0400)]
Btrfs: optimize how we account for space in truncate

Currently we're starting and stopping a transaction for no real reason, so kill
that and just reserve enough space as if we can truncate all in one transaction.
Also use btrfs_block_rsv_check() for our reserve to minimize the amount of space
we may have to allocate for our slack space.  Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
(cherry picked from commit 907cbcebd4e5f641faf08601f216b1ceb6cb3bdf)

13 years agoBtrfs: don't try to commit in btrfs_block_rsv_check
Josef Bacik [Mon, 8 Aug 2011 17:33:21 +0000 (13:33 -0400)]
Btrfs: don't try to commit in btrfs_block_rsv_check

We will try and reserve metadata bytes in btrfs_block_rsv_check and if we cannot
because we have a transaction open it will return EAGAIN, so we do not need to
try and commit the transaction again.

Signed-off-by: Josef Bacik <josef@redhat.com>
(cherry picked from commit 13553e5221d6901a33b3f2157a389de085c161fe)

13 years agoBtrfs: kill unused parts of block_rsv
Josef Bacik [Mon, 8 Aug 2011 16:50:18 +0000 (12:50 -0400)]
Btrfs: kill unused parts of block_rsv

The priority and refill_used flags are not used anymore, and neither is the
usage counter, so just remove them from btrfs_block_rsv.

Signed-off-by: Josef Bacik <josef@redhat.com>
(cherry picked from commit dabdb6408cb801644fa613c7432da012640b348c)

13 years agoBtrfs: ratelimit the generation printk for the free space cache
Josef Bacik [Mon, 8 Aug 2011 12:24:46 +0000 (08:24 -0400)]
Btrfs: ratelimit the generation printk for the free space cache

A user reported getting spammed when moving to 3.0 by this message.  Since we
switched to the normal checksumming infrastructure all old free space caches
will be wrong and need to be regenerated so people are likely to see this
message a lot, so ratelimit it so it doesn't fill up their logs and freak them
out.  Thanks,

Reported-by: Andrew Lutomirski <luto@mit.edu>
Signed-off-by: Josef Bacik <josef@redhat.com>
(cherry picked from commit 6ab60601d518d563ca1a47eaa399096e69d3b64a)

13 years agoBtrfs: fix how we reserve space for deleting inodes
Josef Bacik [Fri, 5 Aug 2011 17:22:24 +0000 (13:22 -0400)]
Btrfs: fix how we reserve space for deleting inodes

I converted btrfs_truncate to do sane reservations for truncate, but didn't
convert btrfs_evict_inode.  Basically we need to save the orphan_rsv for
deleting the orphan item, and do normal reservations for our truncate.  Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
(cherry picked from commit 4289a667a0d7c6b134898cac7bfbe950267c305c)

13 years agoBtrfs: kill the durable block rsv stuff
Josef Bacik [Fri, 5 Aug 2011 14:25:38 +0000 (10:25 -0400)]
Btrfs: kill the durable block rsv stuff

This is confusing code and isn't used by anything anymore, so delete it.

Signed-off-by: Josef Bacik <josef@redhat.com>
(cherry picked from commit 37be25bcb6d731914e126f8de59c4367f0d66b80)

13 years agoBtrfs: kill the orphan space calculation for snapshots
Josef Bacik [Thu, 4 Aug 2011 19:34:57 +0000 (15:34 -0400)]
Btrfs: kill the orphan space calculation for snapshots

This patch kills off the calculation for the amount of space needed for the
orphan operations during a snapshot.  The thing is we only do snapshots on
commit, so any space that is in the block_rsv->freed[] isn't going to be in the
new snapshot anyway, so there isn't any reason to require that space to be
reserved for the snapshot to occur.  Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
(cherry picked from commit dba68306f3fae681b1005137f130f5bcfdfed34a)

13 years agoBtrfs: calculate checksum space correctly
Josef Bacik [Thu, 4 Aug 2011 14:25:02 +0000 (10:25 -0400)]
Btrfs: calculate checksum space correctly

We have not been reserving enough space for checksums.  We were just reserving
bytes for the checksum items themselves, we were not taking into account having
to cow the tree and such.  This patch adds a csum_bytes counter to the inode for
keeping track of the number of bytes outstanding we have for checksums.  Then we
calculate how many leaves would be required for the checksums we are given and
use that to reserve space.  This adds a significant amount of bytes to our
reservations, but we will handle this later.  Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
(cherry picked from commit 7709cde33f12db71efb377fae4ae7aab6c94ebc6)

13 years agoBtrfs: skip looking for delalloc if we don't have ->fill_delalloc
Josef Bacik [Mon, 1 Aug 2011 16:08:18 +0000 (12:08 -0400)]
Btrfs: skip looking for delalloc if we don't have ->fill_delalloc

We always look for delalloc bytes in our io_tree so we can fill in delalloc.
This is fine in most cases, but if we're writing out the btree_inode this is
just a superfluous tree search on the io_tree, and if we have a lot of metadata
dirty this could be an expensive check.  So instead check to see if our io_tree
has a ->fill_delalloc op, and if not don't even bother doing the lookup.
Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
(cherry picked from commit 9e4871070b5f070cacf26525389d56e0345ba156)

13 years agoBtrfs: use bytes_may_use for all ENOSPC reservations
Josef Bacik [Tue, 26 Jul 2011 21:00:46 +0000 (17:00 -0400)]
Btrfs: use bytes_may_use for all ENOSPC reservations

We have been using bytes_reserved for metadata reservations, which is wrong
since we use that to keep track of outstanding reservations from the allocator.
This resulted in us doing a lot of silly things to make sure we don't allocate a
bunch of metadata chunks since we never had a real view of how much space was
actually in use by metadata.

This passes Arne's enospc test and xfstests as well as my own enospc tests.
Hopefully this will get us moving in the right direction.  Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
(cherry picked from commit fb25e9141ab843794d5cdef3936ccb58435e2371)

13 years agoBtrfs: fix how we mount subvol=<whatever>
Josef Bacik [Mon, 25 Jul 2011 19:55:42 +0000 (15:55 -0400)]
Btrfs: fix how we mount subvol=<whatever>

We've only been able to mount with subvol=<whatever> where whatever was a subvol
within whatever root we had as the default.  This allows us to mount -o
subvol=path/to/subvol/you/want relative from the normal fs_tree root.  Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
(cherry picked from commit 830c4adbd04a79f806d4fa579546f36a71b727c1)

13 years agoBtrfs: use d_obtain_alias when mounting subvol/subvolid
Josef Bacik [Mon, 25 Jul 2011 19:40:35 +0000 (15:40 -0400)]
Btrfs: use d_obtain_alias when mounting subvol/subvolid

Currently what we do is just wrong.  We either

1) Alloc a new "root" dentry with sb->s_root as it's parent which is just wrong
as we could walk into this subvol later on via another path and hilarity could
ensue.  Also we don't check the return value of d_splice_alias which isn't good
either.

or

2) Do a d_find_alias() which we could have lost our dentry from cache at this
point and found nothing.

So use d_obtain_alias().  In the case that we already have the inode/dentry in
cache we will get the correct dentry.  If not we will get a disconnected dentry
tree so if we walk into it later on everything will be connected up properly.
Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
(cherry picked from commit ba5b8958dabbd7890a6929af1ffc0d87187765dc)

13 years agoBtrfs: kill reserved_bytes in inode
Josef Bacik [Thu, 14 Jul 2011 20:02:04 +0000 (16:02 -0400)]
Btrfs: kill reserved_bytes in inode

reserved_bytes is not used for anything in the inode, remove it.

Signed-off-by: Josef Bacik <josef@redhat.com>
(cherry picked from commit 0cbbdf7c9c46467bfb7129c30236f36a679ab244)

13 years agoBtrfs: move stuff around in btrfs_inode to get better packing
Josef Bacik [Thu, 14 Jul 2011 18:28:08 +0000 (14:28 -0400)]
Btrfs: move stuff around in btrfs_inode to get better packing

Moving things around to give us better packing in the btrfs_inode.  This reduces
the size of our inode by 8 bytes.  Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
(cherry picked from commit f1bdcc0a8278aa42cb77331275890aac85a4e7cd)

13 years agoBtrfs: make sure not to defrag extents past i_size
Chris Mason [Tue, 11 Oct 2011 15:41:40 +0000 (11:41 -0400)]
Btrfs: make sure not to defrag extents past i_size

The btrfs file defrag code will loop through the extents and
force COW on them.  But there is a concurrent truncate in the middle of
the defrag, it might end up defragging the same range over and over
again.

The problem is that writepage won't go through and do anything on pages
past i_size, so the cow won't happen, so the file will appear to still
be fragmented.  defrag will end up hitting the same extents again and
again.

In the worst case, the truncate can actually live lock with the defrag
because the defrag keeps creating new ordered extents which the truncate
code keeps waiting on.

The fix here is to make defrag check for i_size inside the main loop,
instead of just once before the looping starts.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
(cherry picked from commit f7f43cc84152e53b5687cd0eb8823310ba065524)

13 years agoBtrfs: fix recursive auto-defrag
Li Zefan [Mon, 10 Oct 2011 19:43:34 +0000 (15:43 -0400)]
Btrfs: fix recursive auto-defrag

Follow those steps:

  # mount -o autodefrag /dev/sda7 /mnt
  # dd if=/dev/urandom of=/mnt/tmp bs=200K count=1
  # sync
  # dd if=/dev/urandom of=/mnt/tmp bs=8K count=1 conv=notrunc

and then it'll go into a loop: writeback -> defrag -> writeback ...

It's because writeback writes [8K, 200K] and then writes [0, 8K].

I tried to make writeback know if the pages are dirtied by defrag,
but the patch was a bit intrusive. Here I simply set writeback_index
when we defrag a file.

Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
(cherry picked from commit 2a0f7f5769992bae5b3f97157fd80b2b943be485)

13 years agoBtrfs: stop the readahead threads on failed mount
Chris Mason [Thu, 3 Nov 2011 19:21:39 +0000 (15:21 -0400)]
Btrfs: stop the readahead threads on failed mount

If we don't stop them, they linger around corrupting
memory by using pointers to freed things.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
(cherry picked from commit 306c8b68c82dfe6b7c9e5b61985760ad5d089205)

13 years agoBtrfs: fix extent_buffer leak in the metadata IO error handling
Chris Mason [Fri, 4 Nov 2011 02:23:13 +0000 (22:23 -0400)]
Btrfs: fix extent_buffer leak in the metadata IO error handling

The scrub readahead branch brought in a new error handling hook,
but it was leaking extent_buffer references.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
(cherry picked from commit c674e04e1cd6049715e7b9446790f4b441e547c0)

13 years agobtrfs: use readahead API for scrub
Arne Jansen [Fri, 10 Jun 2011 10:39:23 +0000 (12:39 +0200)]
btrfs: use readahead API for scrub

Scrub uses a simple tree-enumeration to bring the relevant portions
of the extent- and csum-tree into the page cache before starting the
scrub-I/O. This is now replaced by using the new readahead-API.
During readahead the scrub is being accounted as paused, so it won't
hold off transaction commits.

This change raises the average disk bandwith utilisation on my test
volume from 70% to 90%. On another volume, the time for a test run
went down from 89s to 43s.

Changes v5:
 - reada1/2 are now of type struct reada_control *

Signed-off-by: Arne Jansen <sensille@gmx.net>
(cherry picked from commit 7a26285eea8eb92e0088db011571d887d4551b0f with conflicts)

13 years agobtrfs: hooks for readahead
Arne Jansen [Fri, 10 Jun 2011 11:55:54 +0000 (13:55 +0200)]
btrfs: hooks for readahead

This adds the hooks needed for readahead. In the readpage_end_io_hook,
the extent state is checked for the EXTENT_READAHEAD flag. Only in this
case the readahead hook is called, to keep the impact on non-ra as low
as possible.
Additionally, a hook for a failed IO is added, otherwise readahead would
wait indefinitely for the extent to finish.

Changes for v2:
 - eliminate race condition

Signed-off-by: Arne Jansen <sensille@gmx.net>
(cherry picked from commit 4bb31e928d1a47f5bd046ecb176b8eff7c589fc0 with conflicts)

13 years agobtrfs: initial readahead code and prototypes
Arne Jansen [Mon, 23 May 2011 12:33:49 +0000 (14:33 +0200)]
btrfs: initial readahead code and prototypes

This is the implementation for the generic read ahead framework.

To trigger a readahead, btrfs_reada_add must be called. It will start
a read ahead for the given range [start, end) on tree root. The returned
handle can either be used to wait on the readahead to finish
(btrfs_reada_wait), or to send it to the background (btrfs_reada_detach).

The read ahead works as follows:
On btrfs_reada_add, the root of the tree is inserted into a radix_tree.
reada_start_machine will then search for extents to prefetch and trigger
some reads. When a read finishes for a node, all contained node/leaf
pointers that lie in the given range will also be enqueued. The reads will
be triggered in sequential order, thus giving a big win over a naive
enumeration. It will also make use of multi-device layouts. Each disk
will have its on read pointer and all disks will by utilized in parallel.
Also will no two disks read both sides of a mirror simultaneously, as this
would waste seeking capacity. Instead both disks will read different parts
of the filesystem.
Any number of readaheads can be started in parallel. The read order will be
determined globally, i.e. 2 parallel readaheads will normally finish faster
than the 2 started one after another.

Changes v2:
 - protect root->node by transaction instead of node_lock
 - fix missed branches:
    The readahead had a too simple check to determine if a branch from
    a node should be checked or not. It now also records the upper bound
    of each node to see if the requested RA range lies within.
 - use KERN_CONT to debug output, to avoid line breaks
 - defer reada_start_machine to worker to avoid deadlock

Changes v3:
 - protect root->node by rcu

Changes v5:
 - changed EIO-semantics of reada_tree_block_flagged
 - remove spin_lock from reada_control and make elems an atomic_t
 - remove unused read_total from reada_control
 - kill reada_key_cmp, use btrfs_comp_cpu_keys instead
 - use kref-style release functions where possible
 - return struct reada_control * instead of void * from btrfs_reada_add

Signed-off-by: Arne Jansen <sensille@gmx.net>
(cherry picked from commit 7414a03fbf9e75fbbf2a3c16828cd862e572aa44 with conflicts)

13 years agobtrfs: state information for readahead
Arne Jansen [Mon, 23 May 2011 12:30:00 +0000 (14:30 +0200)]
btrfs: state information for readahead

Add state information for readahead to btrfs_fs_info and btrfs_device

Changes v2:
 - don't wait in radix_trees
 - add own set of workers for readahead

Reviewed-by: Josef Bacik <josef@redhat.com>
Signed-off-by: Arne Jansen <sensille@gmx.net>
(cherry picked from commit 90519d66abbccc251d14719ac76f191f70826e40)

13 years agobtrfs: add READAHEAD extent buffer flag
Arne Jansen [Mon, 23 May 2011 12:25:41 +0000 (14:25 +0200)]
btrfs: add READAHEAD extent buffer flag

Add a READAHEAD extent buffer flag.
Add a function to trigger a read with this flag set.

Changes v2:
 - use extent buffer flags instead of extent state flags

Changes v5:
 - adapt to changed read_extent_buffer_pages interface
 - don't return eb from reada_tree_block_flagged if it has CORRUPT flag set

Signed-off-by: Arne Jansen <sensille@gmx.net>
(cherry picked from commit ab0fff03055d2d1b01a7581badeba18db9c4f55c)

13 years agobtrfs: add an extra wait mode to read_extent_buffer_pages
Arne Jansen [Fri, 10 Jun 2011 12:06:53 +0000 (14:06 +0200)]
btrfs: add an extra wait mode to read_extent_buffer_pages

read_extent_buffer_pages currently has two modes, either trigger a read
without waiting for anything, or wait for the I/O to finish. The former
also bails when it's unable to lock the page. This patch now adds an
additional parameter to allow it to block on page lock, but don't wait
for completion.

Changes v5:
 - merge the 2 wait parameters into one and define WAIT_NONE, WAIT_COMPLETE and
   WAIT_PAGE_LOCK

Change v6:
 - fix bug introduced in v5

Signed-off-by: Arne Jansen <sensille@gmx.net>
(cherry picked from commit bb82ab88dfdb12948af58989c75bfe904bc1b09d)

13 years agoBtrfs: force a page fault if we have a shorty copy on a page boundary
Josef Bacik [Fri, 30 Sep 2011 19:23:54 +0000 (15:23 -0400)]
Btrfs: force a page fault if we have a shorty copy on a page boundary

A user reported a problem where ceph was getting into 100% cpu usage while doing
some writing.  It turns out it's because we were doing a short write on a not
uptodate page, which means we'd fall back at one page at a time and fault the
page in.  The problem is our position is on the page boundary, so our fault in
logic wasn't actually reading the page, so we'd just spin forever or until the
page got read in by somebody else.  This will force a readpage if we end up
doing a short copy.  Alexandre could reproduce this easily with ceph and reports
it fixes his problem.  I also wrote a reproducer that no longer hangs my box
with this patch.  Thanks,

Reported-and-tested-by: Alexandre Oliva <aoliva@redhat.com>
Signed-off-by: Josef Bacik <josef@redhat.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
(cherry picked from commit b6316429af7f365f307dfd2b6a7a42f2563aef19)

13 years agoBtrfs: fix the new inspection ioctls for 32 bit compat
Chris Mason [Wed, 2 Nov 2011 19:48:34 +0000 (15:48 -0400)]
Btrfs: fix the new inspection ioctls for 32 bit compat

The new ioctls to follow backrefs are not clean for 32/64 bit
compat.  This reworks them for u64s everywhere.  They are brand new, so
there are no problems with changing the interface now.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
(cherry picked from commit 740c3d226cbba6cd6a32adfb66809c94938f3e57)

13 years agobtrfs: integrating raid-repair and scrub-fixup-nodatasum
Jan Schmidt [Thu, 4 Aug 2011 16:11:04 +0000 (18:11 +0200)]
btrfs: integrating raid-repair and scrub-fixup-nodatasum

This ties nodatasum fixup in scrub together with raid repair patches. While
both series are working fine alone, scrub will report uncorrectable errors
if they occur in a nodatasum extent *and* the page is in the page cache.

Previously, we would have triggered readpage to find good data and do the
repair. However, readpage wouldn't read anything in the case where the page
is up to date in the cache. So, we simply take that good data we have and
call repair_io_failure directly (unless the page in the cache is dirty).

Signed-off-by: Jan Schmidt <list.btrfs@jan-o-sch.net>
(cherry picked from commit 5da6fcbc4eb50c0f55d520750332f5a6ab13508c)

13 years agobtrfs: Moved repair code from inode.c to extent_io.c
Jan Schmidt [Fri, 22 Jul 2011 13:41:52 +0000 (15:41 +0200)]
btrfs: Moved repair code from inode.c to extent_io.c

The raid-retry code in inode.c can be generalized so that it works for
metadata as well. Thus, this patch moves it to extent_io.c and makes the
raid-retry code a raid-repair code.

Repair works that way: Whenever a read error occurs and we have more
mirrors to try, note the failed mirror, and retry another. If we find a
good one, check if we did note a failure earlier and if so, do not allow
the read to complete until after the bad sector was written with the good
data we just fetched. As we have the extent locked while reading, no one
can change the data in between.

Signed-off-by: Jan Schmidt <list.btrfs@jan-o-sch.net>
(cherry picked from commit 4a54c8c165b66300830a67349fc7595e3fc442f7)

13 years agobtrfs: Put mirror_num in bi_bdev
Jan Schmidt [Thu, 16 Jun 2011 10:05:19 +0000 (12:05 +0200)]
btrfs: Put mirror_num in bi_bdev

The error correction code wants to make sure that only the bad mirror is
rewritten. Thus, we need to know which mirror is the bad one. I did not
find a more apropriate field than bi_bdev. But I think using this is fine,
because it is modified by the block layer, anyway, and should not be read
after the bio returned.

Signed-off-by: Jan Schmidt <list.btrfs@jan-o-sch.net>
(cherry picked from commit 2774b2ca3d49124bf1ae89e8d575b3dab4221266)

13 years agobtrfs: Do not use bio->bi_bdev after submission
Jan Schmidt [Thu, 16 Jun 2011 12:37:03 +0000 (14:37 +0200)]
btrfs: Do not use bio->bi_bdev after submission

The block layer modifies bio->bi_bdev and bio->bi_sector while working on
the bio, they do _not_ come back unmodified in the completion callback.

To call add_page, we need at least some bi_bdev set, which is why the code
was working, previously. With this patch, we use the latest_bdev from
fsinfo instead of the leftover in the bio. This gives us the possibility to
use the bi_bdev field for another purpose.

Signed-off-by: Jan Schmidt <list.btrfs@jan-o-sch.net>
(cherry picked from commit 1503140d3ec2be9b917d2f8f7c64cb77b79a215b)

13 years agobtrfs: btrfs_multi_bio replaced with btrfs_bio
Jan Schmidt [Thu, 4 Aug 2011 15:15:33 +0000 (17:15 +0200)]
btrfs: btrfs_multi_bio replaced with btrfs_bio

btrfs_bio is a bio abstraction able to split and not complete after the last
bio has returned (like the old btrfs_multi_bio). Additionally, btrfs_bio
tracks the mirror_num used to read data which can be used for error
correction purposes.

Signed-off-by: Jan Schmidt <list.btrfs@jan-o-sch.net>
(cherry picked from commit a1d3c4786a4b9c71c0767aa656a759968f7554b6)

13 years agobtrfs: new ioctls to do logical->inode and inode->path resolving
Jan Schmidt [Thu, 7 Jul 2011 14:48:38 +0000 (16:48 +0200)]
btrfs: new ioctls to do logical->inode and inode->path resolving

these ioctls make use of the new functions initially added for scrub. they
return all inodes belonging to a logical address (BTRFS_IOC_LOGICAL_INO) and
all paths belonging to an inode (BTRFS_IOC_INO_PATHS).

Signed-off-by: Jan Schmidt <list.btrfs@jan-o-sch.net>
(cherry picked from commit d7728c960dccf775b92f2c4139f1216275a45c44)

13 years agobtrfs scrub: add fixup code for errors on nodatasum files
Jan Schmidt [Mon, 13 Jun 2011 18:04:15 +0000 (20:04 +0200)]
btrfs scrub: add fixup code for errors on nodatasum files

This removes a FIXME comment and introduces the first part of nodatasum
fixup: It gets the corresponding inode for a logical address and triggers a
regular readpage for the corrupted sector.

Once we have on-the-fly error correction our error will be automatically
corrected. The correction code is expected to clear the newly introduced
EXTENT_DAMAGED flag, making scrub report that error as "corrected" instead
of "uncorrectable" eventually.

Signed-off-by: Jan Schmidt <list.btrfs@jan-o-sch.net>
(cherry picked from commit 0ef8e45158f97dde4801b535e25f70f7caf01a27)

13 years agobtrfs scrub: use int for mirror_num, not u64
Jan Schmidt [Fri, 17 Jun 2011 13:55:21 +0000 (15:55 +0200)]
btrfs scrub: use int for mirror_num, not u64

the rest of the code uses int mirror_num, and so should scrub

Signed-off-by: Jan Schmidt <list.btrfs@jan-o-sch.net>
(cherry picked from commit e12fa9cd390f8e93a9144bd99bd6f6ed316fbc1e)

13 years agobtrfs: add mirror_num to extent_read_full_page
Jan Schmidt [Mon, 13 Jun 2011 18:02:58 +0000 (20:02 +0200)]
btrfs: add mirror_num to extent_read_full_page

Currently, extent_read_full_page always assumes we are trying to read mirror
0, which generally is the best we can do. To add flexibility, pass it as a
parameter. This will be needed by scrub fixup code.

Signed-off-by: Jan Schmidt <list.btrfs@jan-o-sch.net>
(cherry picked from commit 8ddc7d9cd0a00062247c732b96386ec2462bdbc7)

13 years agobtrfs scrub: bugfix: mirror_num off by one
Jan Schmidt [Mon, 13 Jun 2011 17:56:54 +0000 (19:56 +0200)]
btrfs scrub: bugfix: mirror_num off by one

Fix the mirror_num determination in scrub_stripe. The rest of the scrub code
did not use mirror_num for anything important and that error went unnoticed.
The nodatasum fixup patch of this set depends on a correct mirror_num.

Signed-off-by: Jan Schmidt <list.btrfs@jan-o-sch.net>
(cherry picked from commit 193ea74b2729e6ddc08fb6bde6e15a3bd4d94071)

13 years agobtrfs scrub: print paths of corrupted files
Jan Schmidt [Mon, 13 Jun 2011 17:59:12 +0000 (19:59 +0200)]
btrfs scrub: print paths of corrupted files

While scrubbing, we may encounter various errors. Previously, a logical
address was printed to the log only. Now, all paths belonging to that
address are resolved and printed separately. That should work for hardlinks
as well as reflinks.

Signed-off-by: Jan Schmidt <list.btrfs@jan-o-sch.net>
(cherry picked from commit 558540c17771eaf89b1a3be39aa2c8bc837da1a6)

13 years agobtrfs scrub: added unverified_errors
Jan Schmidt [Mon, 13 Jun 2011 17:56:13 +0000 (19:56 +0200)]
btrfs scrub: added unverified_errors

In normal operation, scrub is reading data sequentially in large portions.
In case of an i/o error, we try to find the corrupted area(s) by issuing
page sized read requests. With this commit we increment the
unverified_errors counter if all of the small size requests succeed.

Userland patches carrying such conspicous events to the administrator should
already be around.

Signed-off-by: Jan Schmidt <list.btrfs@jan-o-sch.net>
(cherry picked from commit 13db62b7a1e8c64763a93c155091620f85ff8920)

13 years agobtrfs: added helper functions to iterate backrefs
Jan Schmidt [Mon, 13 Jun 2011 17:52:59 +0000 (19:52 +0200)]
btrfs: added helper functions to iterate backrefs

These helper functions iterate back references and call a function for each
backref. There is also a function to resolve an inode to a path in the
file system.

Signed-off-by: Jan Schmidt <list.btrfs@jan-o-sch.net>
(cherry picked from commit a542ad1bafc7df9fc16de8a6894b350a4df75572)

13 years agobtrfs: btrfs_permission's RO check shouldn't apply to device nodes
Jeff Mahoney [Mon, 15 Aug 2011 17:27:21 +0000 (17:27 +0000)]
btrfs: btrfs_permission's RO check shouldn't apply to device nodes

This patch tightens the read-only access checks in btrfs_permission to
 match the constraints in inode_permission. Currently, even though the
 device node itself will be unmodified, read-write access to device nodes
 is denied to when the device node resides on a read-only subvolume or a
 is a file that has been marked read-only by the btrfs conversion utility.

 With this patch applied, the check only affects regular files,
 directories, and symlinks. It also restructures the code a bit so that
 we don't duplicate the MAY_WRITE check for both tests.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
(cherry picked from commit cb6db4e57632ba8589cc2f9fe1d0aa9116b87ab8 with conflicts)

13 years agobtrfs: S_ISREG(mode) is not mode & S_IFREG...
Al Viro [Sun, 24 Jul 2011 21:08:40 +0000 (17:08 -0400)]
btrfs: S_ISREG(mode) is not mode & S_IFREG...

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
(cherry picked from commit 569254b0cc4e125ffde48780b215ecaf5f72bbf4)

13 years agobtrfs: kill magical embedded struct superblock
Al Viro [Thu, 7 Jul 2011 19:44:25 +0000 (15:44 -0400)]
btrfs: kill magical embedded struct superblock

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
(cherry picked from commit 0ee5dc676a5f8fadede608c7281dfedb1ae714ea)

13 years agoxen: Remove hanging references to CONFIG_XEN_PLATFORM_PCI
Konrad Rzeszutek Wilk [Mon, 14 Nov 2011 22:45:26 +0000 (17:45 -0500)]
xen: Remove hanging references to CONFIG_XEN_PLATFORM_PCI

In 5fbdc10395cd500d6ff844825a918c4e6f38de37 the XEN_PLATFORM_PCI config
option was removed, but references in header files remained. Clean up
those references.

Signed-off-by: Daniel De Graaf <dgdegra@tycho.nsa.gov>
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
13 years agoSPEC: v2.6.39-100.0.16
Maxim Uvarov [Fri, 11 Nov 2011 19:05:56 +0000 (11:05 -0800)]
SPEC: v2.6.39-100.0.16

Signed-off-by: Maxim Uvarov <maxim.uvarov@oracle.com>
13 years agoSPEC: fixes for spec file
Guru Anbalagane [Thu, 10 Nov 2011 15:34:35 +0000 (07:34 -0800)]
SPEC: fixes for spec file

This fixes bug 133599851333970013348381

Signed-off-by: Guru Anbalagane <guru.anbalagane@oracle.com>
13 years agoconfig: enable IP_PNP
Guru Anbalagane [Fri, 21 Oct 2011 07:05:40 +0000 (00:05 -0700)]
config: enable IP_PNP

Signed-off-by: Guru Anbalagane <guru.anbalagane@oracle.com>
13 years agoMerge branch 'uek2-merge' of git://oss.oracle.com/git/kwilk/xen into uek2-stable
Guru Anbalagane [Fri, 21 Oct 2011 06:46:11 +0000 (23:46 -0700)]
Merge branch 'uek2-merge' of git://oss.oracle.com/git/kwilk/xen into uek2-stable

13 years agoocfs2: Fix cleancache initialization call to correctly pass uuid
Dan Magenheimer [Fri, 21 Oct 2011 06:35:53 +0000 (23:35 -0700)]
ocfs2: Fix cleancache initialization call to correctly pass uuid

As reported by Steven Whitehouse in https://lkml.org/lkml/2011/5/27/221
the ocfs2 volume UUID is incorrectly passed to cleancache.
As a result, shared-ephemeral tmem pools will not actually
be created; instead they will be private (unshared) which
misses out on a major benefit of tmem.

Reported-by: Steven Whitehouse <swhiteho@redhat.com>
Signed-off-by: Dan Magenheimer <dan.magenheimer@oracle.com>
13 years agoMerge branch 'stable/xen-block.rebase' into uek2-merge
Konrad Rzeszutek Wilk [Wed, 19 Oct 2011 20:31:58 +0000 (16:31 -0400)]
Merge branch 'stable/xen-block.rebase' into uek2-merge

* stable/xen-block.rebase:
  xen/blkback: Fix two races in the handling of barrier requests.
  xen/blkback: Check for proper operation.
  xen/blkback: Fix the inhibition to map pages when discarding sector ranges.
  xen/blkback: Report VBD_WSECT (wr_sect) properly.
  xen/blkback: Support 'feature-barrier' aka old-style BARRIER requests.
  xen-blkfront: plug device number leak in xlblk_init() error path
  xen-blkfront: If no barrier or flush is supported, use invalid operation.
  xen-blkback: use kzalloc() in favor of kmalloc()+memset()
  xen-blkback: fixed indentation and comments
  xen-blkfront: fix a deadlock while handling discard response
  xen-blkfront: Handle discard requests.
  xen-blkback: Implement discard requests ('feature-discard')
  xen-blkfront: add BLKIF_OP_DISCARD and discard request struct
  xen/blkback: Add module alias for autoloading
  xen/blkback: Don't let in-flight requests defer pending ones.

Conflicts:
drivers/block/xen-blkback/blkback.c

13 years agoxen/blkback: Fix two races in the handling of barrier requests.
Konrad Rzeszutek Wilk [Mon, 17 Oct 2011 18:27:48 +0000 (14:27 -0400)]
xen/blkback: Fix two races in the handling of barrier requests.

There are two windows of opportunity to cause a race when
processing a barrier request. This patch fixes this.

Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
13 years agoxen/blkback: Check for proper operation.
Konrad Rzeszutek Wilk [Fri, 14 Oct 2011 16:13:05 +0000 (12:13 -0400)]
xen/blkback: Check for proper operation.

The patch titled: "xen/blkback: Fix the inhibition to map pages
when discarding sector ranges." had the right idea except that
it used the wrong comparison operator. It had == instead of !=.

This fixes the bug where all (except discard) operations would
have been ignored.

Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
13 years agoxen/blkback: Fix the inhibition to map pages when discarding sector ranges.
Konrad Rzeszutek Wilk [Mon, 10 Oct 2011 04:47:49 +0000 (00:47 -0400)]
xen/blkback: Fix the inhibition to map pages when discarding sector ranges.

The 'operation' parameters are the ones provided to the bio layer while
the req->operation are the ones passed in between the backend and
frontend. We used the wrong 'operation' value to squash the
call to map pages when processing the discard operation resulting
in an hypercall that did nothing. Lets guard against going in the
mapping function by checking for the proper operation type.

CC: Li Dongyang <lidongyang@novell.com>
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
13 years agoxen/blkback: Report VBD_WSECT (wr_sect) properly.
Konrad Rzeszutek Wilk [Mon, 10 Oct 2011 16:33:21 +0000 (12:33 -0400)]
xen/blkback: Report VBD_WSECT (wr_sect) properly.

We did not increment the amount of sectors written to disk
b/c we tested for the == WRITE which is incorrect - as the
operations are more of WRITE_FLUSH, WRITE_ODIRECT. This patch
fixes it by doing a & WRITE check.

CC: stable@kernel.org
Reported-by: Andy Burns <xen.lists@burns.me.uk>
Suggested-by: Ian Campbell <Ian.Campbell@citrix.com>
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
13 years agoxen/blkback: Support 'feature-barrier' aka old-style BARRIER requests.
Konrad Rzeszutek Wilk [Mon, 10 Oct 2011 04:42:22 +0000 (00:42 -0400)]
xen/blkback: Support 'feature-barrier' aka old-style BARRIER requests.

We emulate the barrier requests by draining the outstanding bio's
and then sending the WRITE_FLUSH command. To drain the I/Os
we use the refcnt that is used during disconnect to wait for all
the I/Os before disconnecting from the frontend. We latch on its
value and if it reaches either the threshold for disconnect or when
there are no more outstanding I/Os, then we have drained all I/Os.

Suggested-by: Christopher Hellwig <hch@infradead.org>
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
13 years agoxen-blkfront: plug device number leak in xlblk_init() error path
Laszlo Ersek [Fri, 7 Oct 2011 19:34:38 +0000 (21:34 +0200)]
xen-blkfront: plug device number leak in xlblk_init() error path

... though after a failed xenbus_register_frontend() all may be lost.

Acked-by: Ian Campbell <ian.campbell@citrix.com>
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
13 years agoxen-blkfront: If no barrier or flush is supported, use invalid operation.
Konrad Rzeszutek Wilk [Fri, 16 Sep 2011 19:15:14 +0000 (15:15 -0400)]
xen-blkfront: If no barrier or flush is supported, use invalid operation.

Guard against issuing BLKIF_OP_WRITE_BARRIER or BLKIF_OP_FLUSH_CACHE
by checking whether we successfully negotiated with the backend.
The negotiation with the backend also sets the q->flush_flags which
fortunately for us is also used when submitting an bio to us. If
we don't support barriers or flushes it would be set to zero so
we should never end up having to deal with REQ_FLUSH | REQ_FUA.

However, other third party implementations of __make_request that
might be stacked on top of us might not be so smart, so lets fix this up.

Acked-by: Jan Beulich <jbeulich@suse.com>
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
13 years agoxen-blkback: use kzalloc() in favor of kmalloc()+memset()
Jan Beulich [Fri, 16 Sep 2011 07:38:09 +0000 (08:38 +0100)]
xen-blkback: use kzalloc() in favor of kmalloc()+memset()

This fixes the problem of three of those four memset()-s having
improper size arguments passed: Sizeof a pointer-typed expression
returns the size of the pointer, not that of the pointed to data.

It also reverts using kmalloc() instead of kzalloc() for the allocation
of the pending grant handles array, as that array gets fully
initialized in a subsequent loop.

Reported-by: Julia Lawall <julia@diku.dk>
Signed-off-by: Jan Beulich <jbeulich@novell.com>
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
13 years agoxen-blkback: fixed indentation and comments
Joe Jin [Mon, 15 Aug 2011 04:57:07 +0000 (12:57 +0800)]
xen-blkback: fixed indentation and comments

This patch fixes belows:

1. Fix code style issue.
2. Fix incorrect functions name in comments.

Signed-off-by: Joe Jin <joe.jin@oracle.com>
Cc: Jens Axboe <jaxboe@fusionio.com>
Cc: Ian Campbell <Ian.Campbell@eu.citrix.com>
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
13 years agoxen-blkfront: fix a deadlock while handling discard response
Li Dongyang [Wed, 14 Sep 2011 06:02:40 +0000 (14:02 +0800)]
xen-blkfront: fix a deadlock while handling discard response

When we get -EOPNOTSUPP response for a discard request, we will clear
the discard flag on the request queue so we won't attempt to send discard
requests to backend again, and this should be protected under rq->queue_lock.
However, when we setup the request queue, we pass blkif_io_lock to
blk_init_queue so rq->queue_lock is blkif_io_lock indeed, and this lock
is already taken when we are in blkif_interrpt, so remove the
spin_lock/spin_unlock when we clear the discard flag or we will end up
with deadlock here

Signed-off-by: Li Dongyang <lidongyang@novell.com>
[v1: Updated description a bit and removed comment from source]
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
13 years agoxen-blkfront: Handle discard requests.
Li Dongyang [Thu, 1 Sep 2011 10:39:09 +0000 (18:39 +0800)]
xen-blkfront: Handle discard requests.

If the backend advertises 'feature-discard', then interrogate
the backend for alignment and granularity. Setup the request
queue with the appropiate values and send the discard operation
as required.

Signed-off-by: Li Dongyang <lidongyang@novell.com>
[v1: Amended commit description]
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
13 years agoxen-blkback: Implement discard requests ('feature-discard')
Li Dongyang [Thu, 1 Sep 2011 10:39:10 +0000 (18:39 +0800)]
xen-blkback: Implement discard requests ('feature-discard')

..aka ATA TRIM/SCSI UNMAP command to be passed through the frontend
and used as appropiately by the backend. We also advertise
certain granulity parameters to the frontend so it can plug them in.
If the backend is a realy device - we just end up using
'blkdev_issue_discard' while for loopback devices - we just punch
a hole in the image file.

Signed-off-by: Li Dongyang <lidongyang@novell.com>
[v1: Fixed up pr_debug and commit description]
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
13 years agoxen-blkfront: add BLKIF_OP_DISCARD and discard request struct
Li Dongyang [Thu, 1 Sep 2011 10:39:08 +0000 (18:39 +0800)]
xen-blkfront: add BLKIF_OP_DISCARD and discard request struct

Now we use BLKIF_OP_DISCARD and add blkif_request_discard to blkif_request union,
the patch is taken from Owen Smith and Konrad, Thanks

Signed-off-by: Owen Smith <owen.smith@citrix.com>
Signed-off-by: Li Dongyang <lidongyang@novell.com>
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
13 years agoxen/blkback: Add module alias for autoloading
Bastian Blank [Wed, 29 Jun 2011 12:40:50 +0000 (14:40 +0200)]
xen/blkback: Add module alias for autoloading

Add xen-backend:vbd module alias to the xen-blkback module. This allows
automatic loading of the module.

Signed-off-by: Bastian Blank <waldi@debian.org>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
13 years agoxen/blkback: Don't let in-flight requests defer pending ones.
Daniel Stodden [Sat, 28 May 2011 20:21:10 +0000 (13:21 -0700)]
xen/blkback: Don't let in-flight requests defer pending ones.

Running RING_FINAL_CHECK_FOR_REQUESTS from make_response is a bad
idea. It means that in-flight I/O is essentially blocking continued
batches. This essentially kills throughput on frontends which unplug
(or even just notify) early and rightfully assume addtional requests
will be picked up on time, not synchronously.

Signed-off-by: Daniel Stodden <daniel.stodden@citrix.com>
[v1: Rebased and fixed compile problems]
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
13 years agoMerge branch 'stable/xen-settime' into uek2-merge
Konrad Rzeszutek Wilk [Wed, 19 Oct 2011 20:13:38 +0000 (16:13 -0400)]
Merge branch 'stable/xen-settime' into uek2-merge

* stable/xen-settime:
  xen/dom0: set wallclock time in Xen
  xen: add dom0_op hypercall
  xen/acpi: Domain0 acpi parser related platform hypercall

13 years agoMerge branch 'stable/e820-3.2.rebased' into uek2-merge
Konrad Rzeszutek Wilk [Wed, 19 Oct 2011 20:12:04 +0000 (16:12 -0400)]
Merge branch 'stable/e820-3.2.rebased' into uek2-merge

* stable/e820-3.2.rebased:
  xen: release all pages within 1-1 p2m mappings
  xen: allow extra memory to be in multiple regions
  xen: allow balloon driver to use more than one memory region
  xen/balloon: simplify test for the end of usable RAM
  xen/balloon: account for pages released during memory setup
  xen/e820: if there is no dom0_mem=, don't tweak extra_pages.
  Revert "xen/e820: if there is no dom0_mem=, don't tweak extra_pages."
  xen/e820: if there is no dom0_mem=, don't tweak extra_pages.
  xen: use maximum reservation to limit amount of usable RAM
  xen: Fix misleading WARN message at xen_release_chunk
  xen: Fix printk() format in xen/setup.c

Conflicts:
arch/x86/xen/setup.c

13 years agoMerge branch 'stable/mmu.fixes.rebased' into uek2-merge
Konrad Rzeszutek Wilk [Wed, 19 Oct 2011 20:05:45 +0000 (16:05 -0400)]
Merge branch 'stable/mmu.fixes.rebased' into uek2-merge

* stable/mmu.fixes.rebased:
  xen/gntdev: Fix sleep-inside-spinlock
  xen: modify kernel mappings corresponding to granted pages
  xen: add an "highmem" parameter to alloc_xenballooned_pages
  xen/p2m: Use SetPagePrivate and its friends for M2P overrides.
  xen/p2m: Make debug/xen/mmu/p2m visible again.
  Revert "xen/debug: WARN_ON when identity PFN has no _PAGE_IOMAP flag set."

Conflicts:
drivers/xen/balloon.c
include/xen/balloon.h

13 years agoMerge branch 'stable/drivers-3.2.rebased' into uek2-merge
Konrad Rzeszutek Wilk [Wed, 19 Oct 2011 19:54:47 +0000 (15:54 -0400)]
Merge branch 'stable/drivers-3.2.rebased' into uek2-merge

* stable/drivers-3.2.rebased:
  xen: use static initializers in xen-balloon.c
  xenbus: don't rely on xen_initial_domain to detect local xenstore
  xenbus: Fix loopback event channel assuming domain 0
  xen/pv-on-hvm:kexec: Fix implicit declaration of function 'xen_hvm_domain'
  xen/pv-on-hvm kexec: add xs_reset_watches to shutdown watches from old kernel
  xen/pv-on-hvm kexec: update xs_wire.h:xsd_sockmsg_type from xen-unstable
  xen/pv-on-hvm kexec+kdump: reset PV devices in kexec or crash kernel
  xen/pv-on-hvm kexec: rebind virqs to existing eventchannel ports
  xen/pv-on-hvm kexec: prevent crash in xenwatch_thread() when stale watch events arrive

Conflicts:
drivers/xen/xen-balloon.c
drivers/xen/xenbus/xenbus_probe.c

13 years agoMerge branch 'stable/cleanups-3.2.rebased' into uek2-merge
Konrad Rzeszutek Wilk [Wed, 19 Oct 2011 19:49:59 +0000 (15:49 -0400)]
Merge branch 'stable/cleanups-3.2.rebased' into uek2-merge

* stable/cleanups-3.2.rebased:
  Xen: fix braces and tabs coding style issue in xenbus_probe.c
  Xen: fix braces coding style issue in xenbus_probe.h
  Xen: fix whitespaces,tabs coding style issue in drivers/xen/pci.c
  Xen: fix braces coding style issue in gntdev.c and grant-table.c
  Xen: fix whitespaces,tabs coding style issue in drivers/xen/events.c
  Xen: fix whitespaces,tabs coding style issue in drivers/xen/balloon.c

Conflicts:
drivers/xen/pci.c

13 years agoMerge branch 'stable/pci.fixes-3.2' of git://oss.oracle.com/git/kwilk/xen into uek2...
Konrad Rzeszutek Wilk [Wed, 19 Oct 2011 19:44:10 +0000 (15:44 -0400)]
Merge branch 'stable/pci.fixes-3.2' of git://oss.oracle.com/git/kwilk/xen into uek2-merge

* 'stable/pci.fixes-3.2' of git://oss.oracle.com/git/kwilk/xen:
  xen/pci: support multi-segment systems
  xen-swiotlb: When doing coherent alloc/dealloc check before swizzling the MFNs.
  xen/pci: make bus notifier handler return sane values
  xen-swiotlb: fix printk and panic args
  xen-swiotlb: Fix wrong panic.
  xen-swiotlb: Retry up three times to allocate Xen-SWIOTLB
  xen-pcifront: Update warning comment to use 'e820_host' option.

13 years agoMerge branch 'stable/bug.fixes-3.2.rebased' of git://oss.oracle.com/git/kwilk/xen...
Konrad Rzeszutek Wilk [Wed, 19 Oct 2011 19:43:13 +0000 (15:43 -0400)]
Merge branch 'stable/bug.fixes-3.2.rebased' of git://oss.oracle.com/git/kwilk/xen into uek2-merge

* 'stable/bug.fixes-3.2.rebased' of git://oss.oracle.com/git/kwilk/xen:
  xen/irq: If we fail during msi_capability_init return proper error code.
  xen: remove XEN_PLATFORM_PCI config option
  xen: XEN_PVHVM depends on PCI
  xen/p2m/debugfs: Make type_name more obvious.
  xen/p2m/debugfs: Fix potential pointer exception.
  xen/enlighten: Fix compile warnings and set cx to known value.
  xen/xenbus: Remove the unnecessary check.
  xen/events: Don't check the info for NULL as it is already done.
  xen/pci: Use 'acpi_gsi_to_irq' value unconditionally.
  xen/pci: Remove 'xen_allocate_pirq_gsi'.
  xen/pci: Retire unnecessary #ifdef CONFIG_ACPI
  xen/pci: Move the allocation of IRQs when there are no IOAPIC's to the end
  xen/pci: Squash pci_xen_initial_domain and xen_setup_pirqs together.
  xen/pci: Use the xen_register_pirq for HVM and initial domain users
  xen/pci: In xen_register_pirq bind the GSI to the IRQ after the hypercall.
  xen/pci: Provide #ifdef CONFIG_ACPI to easy code squashing.
  xen/pci: Update comments and fix empty spaces.
  xen/pci: Shuffle code around.

Conflicts:
arch/x86/pci/xen.c
drivers/xen/Makefile

13 years agoMerge branch 'stable/xen-pciback-0.6.3.bugfixes' of git://oss.oracle.com/git/kwilk...
Konrad Rzeszutek Wilk [Wed, 19 Oct 2011 19:42:45 +0000 (15:42 -0400)]
Merge branch 'stable/xen-pciback-0.6.3.bugfixes' of git://oss.oracle.com/git/kwilk/xen into uek2-merge

* 'stable/xen-pciback-0.6.3.bugfixes' of git://oss.oracle.com/git/kwilk/xen:
  xen/pciback: Check if the device is found instead of blindly assuming so.
  xen/pciback: Do not dereference psdev during printk when it is NULL.
  xen/pciback: double lock typo
  xen/pciback: use mutex rather than spinlock in vpci backend
  xen/pciback: Use mutexes when working with Xenbus state transitions.
  xen/pciback: miscellaneous adjustments
  xen/pciback: use mutex rather than spinlock in passthrough backend
  xen/pciback: use resource_size()

13 years agoxen/irq: If we fail during msi_capability_init return proper error code.
Konrad Rzeszutek Wilk [Thu, 29 Sep 2011 17:26:45 +0000 (13:26 -0400)]
xen/irq: If we fail during msi_capability_init return proper error code.

There are three different modes: PV, HVM, and initial domain 0. In all
the cases we would return -1 for failure instead of a proper error code.
Fix this by propagating the error code from the generic IRQ code.

Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
13 years agoxen: remove XEN_PLATFORM_PCI config option
Konrad Rzeszutek Wilk [Wed, 19 Oct 2011 17:34:39 +0000 (13:34 -0400)]
xen: remove XEN_PLATFORM_PCI config option

Xen PVHVM needs xen-platform-pci, on the other hand xen-platform-pci is
useless in any other cases.
Therefore remove the XEN_PLATFORM_PCI config option and compile
xen-platform-pci built-in if XEN_PVHVM is selected.

Changes to v1:

- remove xen-platform-pci.o and just use platform-pci.o since it is not
externally visible anymore.

Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Conflicts:

drivers/xen/Makefile

13 years agoxen: XEN_PVHVM depends on PCI
Stefano Stabellini [Thu, 29 Sep 2011 11:05:57 +0000 (12:05 +0100)]
xen: XEN_PVHVM depends on PCI

Xen PV on HVM guests require PCI support because they need the
xen-platform-pci driver in order to initialize xenbus.

Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
13 years agoxen/p2m/debugfs: Make type_name more obvious.
Konrad Rzeszutek Wilk [Mon, 3 Oct 2011 16:35:26 +0000 (12:35 -0400)]
xen/p2m/debugfs: Make type_name more obvious.

Per Ian Campbell suggestion to defend against future breakage
in case we expand the P2M values, incorporate the defines
in the string array.

Suggested-by: Ian Campbell <Ian.Campbell@citrix.com>
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
13 years agoxen/p2m/debugfs: Fix potential pointer exception.
Konrad Rzeszutek Wilk [Thu, 29 Sep 2011 17:09:34 +0000 (13:09 -0400)]
xen/p2m/debugfs: Fix potential pointer exception.

We could be referencing the last + 1 element of level_name[]
array which would cause a pointer exception, because of the
initial setup of lvl=4.

[v1: No need to do this for type_name, pointed out by Ian Campbell]
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
13 years agoxen/enlighten: Fix compile warnings and set cx to known value.
Konrad Rzeszutek Wilk [Thu, 29 Sep 2011 17:06:42 +0000 (13:06 -0400)]
xen/enlighten: Fix compile warnings and set cx to known value.

We get:
linux/arch/x86/xen/enlighten.c: In function ‘xen_start_kernel’:
linux/arch/x86/xen/enlighten.c:226: warning: ‘cx’ may be used uninitialized in this function
linux/arch/x86/xen/enlighten.c:240: note: ‘cx’ was declared here

and the cx is really not set but passed in the xen_cpuid instruction
which masks the value with returned masked_ecx from cpuid. This
can potentially lead to invalid data being stored in cx.

Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
13 years agoxen/xenbus: Remove the unnecessary check.
Konrad Rzeszutek Wilk [Thu, 29 Sep 2011 17:16:17 +0000 (13:16 -0400)]
xen/xenbus: Remove the unnecessary check.

.. we check whether 'xdev' is NULL - but there is no need for
it as the 'dev' check is done before. The 'dev' is embedded in
the 'xdev' so having xdev != NULL with dev being being checked
is not going to happen.

Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
13 years agoxen/events: Don't check the info for NULL as it is already done.
Konrad Rzeszutek Wilk [Thu, 29 Sep 2011 17:13:30 +0000 (13:13 -0400)]
xen/events: Don't check the info for NULL as it is already done.

The list operation checks whether the 'info' structure that is
retrieved from the list is NULL (otherwise it would not been able
to retrieve it). This check is not neccessary.

Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
13 years agoxen/pci: Use 'acpi_gsi_to_irq' value unconditionally.
Konrad Rzeszutek Wilk [Wed, 6 Jul 2011 17:03:35 +0000 (13:03 -0400)]
xen/pci: Use 'acpi_gsi_to_irq' value unconditionally.

In the past we would only use the function's value if the
returned value was not equal to 'acpi_sci_override_gsi'. Meaning
that the INT_SRV_OVR values for global and source irq were different.
But it is OK to use the function's value even when the global
and source irq are the same.

Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
13 years agoxen/pci: Remove 'xen_allocate_pirq_gsi'.
Konrad Rzeszutek Wilk [Wed, 6 Jul 2011 19:15:23 +0000 (15:15 -0400)]
xen/pci: Remove 'xen_allocate_pirq_gsi'.

In the past (2.6.38) the 'xen_allocate_pirq_gsi' would allocate
an entry in a Linux IRQ -> {XEN_IRQ, type, event, ..} array. All
of that has been removed in 2.6.39 and the Xen IRQ subsystem uses
an linked list that is populated when the call to
'xen_allocate_irq_gsi' (universally done from any of the xen_bind_*
calls) is done. The 'xen_allocate_pirq_gsi' is a NOP and there is
no need for it anymore so lets remove it.

Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>