Skip to content

Commit

Permalink
Rename *_limit methods to set quotas
Browse files Browse the repository at this point in the history
* Rename {rfer,excl}_limit to max_{referenced,exlusive}
  • Loading branch information
imobachgs committed Oct 7, 2020
1 parent b95c030 commit f220a15
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 33 deletions.
18 changes: 9 additions & 9 deletions src/lib/y2storage/btrfs_qgroup.rb
Expand Up @@ -29,23 +29,23 @@ module Y2Storage
class BtrfsQgroup
attr_reader :subvol_id

# @attr :rfer_limit
# @attr :max_referenced
# @return [DiskSize,nil] Referenced extents quota (shared quota). `nil` if not set.
attr_reader :rfer_limit
attr_reader :max_referenced

# @attr :excl_limit
# @attr :max_exclusive
# @return [DiskSize,nil] Exclusive extents quota. `nil` if not set.
attr_reader :excl_limit
attr_reader :max_exclusive

# Constructor
#
# @param subvol_id [Integer] Subvolume ID
# @param rfer_limit [DiskSize,nil] Referenced extents limit
# @param excl_limit [DiskSize,nil] Exclusive extents limit
def initialize(subvol_id, rfer_limit = nil, excl_limit = nil)
# @param max_referenced [DiskSize,nil] Referenced extents limit
# @param max_exclusive [DiskSize,nil] Exclusive extents limit
def initialize(subvol_id, max_referenced = nil, max_exclusive = nil)
@subvol_id = subvol_id
@rfer_limit = rfer_limit
@excl_limit = excl_limit
@max_referenced = max_referenced
@max_exclusive = max_exclusive
end
end
end
22 changes: 12 additions & 10 deletions src/lib/y2storage/btrfs_subvolume.rb
Expand Up @@ -177,35 +177,37 @@ def qgroup
# Assigns the referenced extents quota
#
# @param value [DiskSize] Limit for referenced extents; DiskSize.unlimited to remove the limit
def rfer_limit=(value)
save_userdata(:rfer_limit, value)
def max_referenced=(value)
save_userdata(:max_referenced, value)
end

# Assigns the exclusive extents quota
#
# @param value [DiskSize] Limit for exclusive extents; DiskSize.unlimited to remove the limit
def excl_limit=(value)
save_userdata(:excl_limit, value)
def max_exclusive=(value)
save_userdata(:max_exclusive, value)
end

# Returns the referenced extents quota
#
# @param value [DiskSize] Limit for referenced extents; DiskSize.unlimited if no limit
# @return [DiskSize]
def rfer_limit
user_limit = userdata_value(:rfer_limit)
def max_referenced
user_limit = userdata_value(:max_referenced)
return user_limit if user_limit
return qgroup.rfer_limit if qgroup
return qgroup.max_referenced if qgroup

DiskSize.unlimited
end

# Returns the exclusive extents quota
#
# @param value [DiskSize] Limit for exclusive extents; DiskSize.unlimited if no limit
def excl_limit
user_limit = userdata_value(:excl_limit)
def max_exclusive
user_limit = userdata_value(:max_exclusive)
return user_limit if user_limit
return qgroup.excl_limit if qgroup
return qgroup.max_exclusive if qgroup

DiskSize.unlimited
end

Expand Down
4 changes: 2 additions & 2 deletions test/y2storage/btrfs_reader_test.rb
Expand Up @@ -95,8 +95,8 @@
describe "#qgroups" do
it "returns the qgroups" do
qgroups = reader.qgroups
expect(qgroups.first.rfer_limit).to eq(3.GiB)
expect(qgroups.first.excl_limit).to eq(2.GiB)
expect(qgroups.first.max_referenced).to eq(3.GiB)
expect(qgroups.first.max_exclusive).to eq(2.GiB)
end
end
end
24 changes: 12 additions & 12 deletions test/y2storage/btrfs_subvolume_test.rb
Expand Up @@ -158,43 +158,43 @@
allow(btrfs_filesystem).to receive(:qgroup_for).with(subject.id).and_return(qgroup)
end

describe "#rfer_limit" do
it "returns the rfer_limit from the qgroup" do
expect(subject.rfer_limit).to eq(2.GiB)
describe "#max_referenced" do
it "returns the max_referenced from the qgroup" do
expect(subject.max_referenced).to eq(2.GiB)
end

context "when it does not have an assigned qgroup" do
let(:qgroup) { nil }

it "returns unlimited" do
expect(subject.rfer_limit).to eq(Y2Storage::DiskSize.unlimited)
expect(subject.max_referenced).to eq(Y2Storage::DiskSize.unlimited)
end
end
end

describe "#excl_limit" do
it "returns the rfer_limit from the qgroup" do
expect(subject.excl_limit).to eq(3.GiB)
describe "#max_exclusive" do
it "returns the max_referenced from the qgroup" do
expect(subject.max_exclusive).to eq(3.GiB)
end

context "when it does not have an assigned qgroup" do
let(:qgroup) { nil }

it "returns unlimited" do
expect(subject.excl_limit).to eq(Y2Storage::DiskSize.unlimited)
expect(subject.max_exclusive).to eq(Y2Storage::DiskSize.unlimited)
end
end
end

describe "#rfer_limit=" do
describe "#max_referenced=" do
it "sets the referenced extents limit" do
expect { subject.rfer_limit = 1.GiB }.to change { subject.rfer_limit }.to(1.GiB)
expect { subject.max_referenced = 1.GiB }.to change { subject.max_referenced }.to(1.GiB)
end
end

describe "#excl_limit=" do
describe "#max_exclusive=" do
it "sets the referenced extents limit" do
expect { subject.excl_limit = 1.GiB }.to change { subject.excl_limit }.to(1.GiB)
expect { subject.max_exclusive = 1.GiB }.to change { subject.max_exclusive }.to(1.GiB)
end
end
end
Expand Down

0 comments on commit f220a15

Please sign in to comment.