4308
4308
spin_lock(&sinfo->lock);
4309
4309
spin_lock(&block_rsv->lock);
4311
block_rsv->size = num_bytes;
4311
block_rsv->size = min_t(u64, num_bytes, 512 * 1024 * 1024);
4313
4313
num_bytes = sinfo->bytes_used + sinfo->bytes_pinned +
4314
4314
sinfo->bytes_reserved + sinfo->bytes_readonly +
4601
4601
* If the inodes csum_bytes is the same as the original
4602
4602
* csum_bytes then we know we haven't raced with any free()ers
4603
4603
* so we can just reduce our inodes csum bytes and carry on.
4604
* Otherwise we have to do the normal free thing to account for
4605
* the case that the free side didn't free up its reserve
4606
* because of this outstanding reservation.
4608
if (BTRFS_I(inode)->csum_bytes == csum_bytes)
4605
if (BTRFS_I(inode)->csum_bytes == csum_bytes) {
4609
4606
calc_csum_metadata_size(inode, num_bytes, 0);
4611
to_free = calc_csum_metadata_size(inode, num_bytes, 0);
4608
u64 orig_csum_bytes = BTRFS_I(inode)->csum_bytes;
4612
* This is tricky, but first we need to figure out how much we
4613
* free'd from any free-ers that occured during this
4614
* reservation, so we reset ->csum_bytes to the csum_bytes
4615
* before we dropped our lock, and then call the free for the
4616
* number of bytes that were freed while we were trying our
4619
bytes = csum_bytes - BTRFS_I(inode)->csum_bytes;
4620
BTRFS_I(inode)->csum_bytes = csum_bytes;
4621
to_free = calc_csum_metadata_size(inode, bytes, 0);
4625
* Now we need to see how much we would have freed had we not
4626
* been making this reservation and our ->csum_bytes were not
4627
* artificially inflated.
4629
BTRFS_I(inode)->csum_bytes = csum_bytes - num_bytes;
4630
bytes = csum_bytes - orig_csum_bytes;
4631
bytes = calc_csum_metadata_size(inode, bytes, 0);
4634
* Now reset ->csum_bytes to what it should be. If bytes is
4635
* more than to_free then we would have free'd more space had we
4636
* not had an artificially high ->csum_bytes, so we need to free
4637
* the remainder. If bytes is the same or less then we don't
4638
* need to do anything, the other free-ers did the correct
4641
BTRFS_I(inode)->csum_bytes = orig_csum_bytes - num_bytes;
4642
if (bytes > to_free)
4643
to_free = bytes - to_free;
4612
4647
spin_unlock(&BTRFS_I(inode)->lock);
4614
4649
to_free += btrfs_calc_trans_metadata_size(root, dropped);