Skip to contentSkip to conversation

cp --reflink and qgroup limit

DISCUSSION Antoine Belvire 2 participants 3 messages Sep 17, 2017 – Sep 18, 2017 Btrfs file system

lore
Share & tools
lore
#0 lore raw

Hello,

The behavior of 'cp --reflink' puzzles me from the quota point of view.

It looks like it's possible to easily exceeds a qgroup's max_rfer limit like this:

~# # Create '/test' and '/test/a' subvolumes
~# btrfs subvolume create /test
~# btrfs subvolume create /test/a
~#
~# # Set limits
~# btrfs qgroup limit 10m (qgroupid) /
~# btrfs qgroup limit -e 5m (qgroupid) /
~#
~# # Limits are set
~# btrfs qgroup show -erF /test/a/

qgroupid         rfer         excl     max_rfer     max_excl
--------         ----         ----     --------     --------
(the id)     16.00KiB     16.00KiB     10.00MiB      5.00MiB

~#
~# # Write a big file in '/test'
~# dd if=/dev/urandom of=/test/bigfile bs=1M count=50 ~#
~# # Copy it to '/test/a' using cp --reflink ~# cp --reflink /test/bigfile /test/a
~#
~# # No EDQUOT error, quota limit is exceeded ~# btrfs qgroup show --sync -erF /test/a/

qgroupid         rfer         excl     max_rfer     max_excl
--------         ----         ----     --------     --------
(the id)     50.02MiB     16.00KiB     10.00MiB      5.00MiB

~#

However, now the limit is exceeded, EDQUOT is raised upon a new 'cp --reflink':

~# touch /test/nothing
~# cp --reflink /test/nothing /test/a
cp: cannot create regular file 'a/nothing': Disk quota exceeded ~#

As far as I understand the code, btrfs_clone doesn't try to reserve data it clones. It only reserves metadata through btrfs_start_transaction.

Is it an expected behavior?

Regards,

--
Antoine

#1 lore raw
Quoted 36 lines · Antoine Belvire

Hello,

The behavior of 'cp --reflink' puzzles me from the quota point of view.

It looks like it's possible to easily exceeds a qgroup's max_rfer limit like this:

~# # Create '/test' and '/test/a' subvolumes
~# btrfs subvolume create /test
~# btrfs subvolume create /test/a
~#
~# # Set limits
~# btrfs qgroup limit 10m (qgroupid) /
~# btrfs qgroup limit -e 5m (qgroupid) /
~#
~# # Limits are set
~# btrfs qgroup show -erF /test/a/
qgroupid         rfer         excl     max_rfer     max_excl --------         ----         ----     --------     -------- (the id)     16.00KiB     16.00KiB     10.00MiB      5.00MiB ~#
~# # Write a big file in '/test'
~# dd if=/dev/urandom of=/test/bigfile bs=1M count=50 ~#
~# # Copy it to '/test/a' using cp --reflink
~# cp --reflink /test/bigfile /test/a
~#
~# # No EDQUOT error, quota limit is exceeded
~# btrfs qgroup show --sync -erF /test/a/
qgroupid         rfer         excl     max_rfer     max_excl --------         ----         ----     --------     -------- (the id)     50.02MiB     16.00KiB     10.00MiB      5.00MiB ~#

However, now the limit is exceeded, EDQUOT is raised upon a new 'cp --reflink':

Quoted 6 lines

~# touch /test/nothing
~# cp --reflink /test/nothing /test/a
cp: cannot create regular file 'a/nothing': Disk quota exceeded ~#

As far as I understand the code, btrfs_clone doesn't try to reserve data it clones. It only reserves metadata through btrfs_start_transaction.

That's a bug, and should be fixed.

But it's a little complicated to fix.
The biggest problem is, until reflink is done and we commit a transaction, we don't know if the the reflink operation will increase "rfer" or not. (Considering a case where both reflink source and destination is inside the same subvolume)

Yes, we can always try to reserve the size of the data, and cause false alert, but the handling of reserved data range will be another problem.

I'll check if we can solve it.

Thanks,
Qu

Quoted 11 lines

Is it an expected behavior?

Regards,

Signature · 5 lines
Antoine
-- 
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#2 lore raw

Hello Qu,

Le 18/09/2017 à 01:33, Qu Wenruo a écrit :

Quoted 1 line

That's a bug, and should be fixed.

OK.

Quoted 7 lines

But it's a little complicated to fix.
The biggest problem is, until reflink is done and we commit a transaction, we don't know if the the reflink operation will increase "rfer" or not. (Considering a case where both reflink source and destination is inside the same subvolume)

Yes, we can always try to reserve the size of the data, and cause false alert, but the handling of reserved data range will be another problem.

I'll check if we can solve it.

Thanks for your explanation. I'm looking forward to hearing good news about this then :)

Regards,

--
Antoine