Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1174 from ancorgs/tmpfs_wrapper
Initial wrapper for Storage::Tmpfs
- Loading branch information
Showing
8 changed files
with
174 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# Copyright (c) [2020] SUSE LLC | ||
# | ||
# All Rights Reserved. | ||
# | ||
# This program is free software; you can redistribute it and/or modify it | ||
# under the terms of version 2 of the GNU General Public License as published | ||
# by the Free Software Foundation. | ||
# | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
# more details. | ||
# | ||
# You should have received a copy of the GNU General Public License along | ||
# with this program; if not, contact SUSE LLC. | ||
# | ||
# To contact SUSE LLC about this file by physical or electronic mail, you may | ||
# find current contact information at www.suse.com. | ||
|
||
require "y2storage/storage_class_wrapper" | ||
require "y2storage/filesystems/base" | ||
|
||
module Y2Storage | ||
module Filesystems | ||
# Class to represent a tmpfs. | ||
# | ||
# The Tmpfs object should always have MountPoint as child. So the Tmpfs | ||
# must be deleted whenever the MountPoint is removed. | ||
# | ||
# This is a wrapper for Storage::Tmpfs | ||
class Tmpfs < Base | ||
wrap_class Storage::Tmpfs | ||
|
||
# @!method self.create(devicegraph) | ||
# @param devicegraph [Devicegraph] | ||
# @return [Tmpfs] | ||
storage_class_forward :create, as: "Filesystems::Tmpfs" | ||
|
||
# @!method self.all(devicegraph) | ||
# @param devicegraph [Devicegraph] | ||
# @return [Array<Tmpfs>] all the tmp filesystems in the given devicegraph | ||
storage_class_forward :all, as: "Filesystems::Tmpfs" | ||
|
||
# Size of the filesystem, given by the corresponding mount option | ||
# | ||
# @return [DiskSize] zero if the size couldn't be determined | ||
def size | ||
DiskSize.parse(size_from_mount_options, legacy_units: true) | ||
rescue StandardError | ||
DiskSize.zero | ||
end | ||
|
||
protected | ||
|
||
# Name of the mount option used to determine the size of the tmpfs | ||
# @return [String] | ||
SIZE_OPT = "size".freeze | ||
private_constant :SIZE_OPT | ||
|
||
# @see Device#is? | ||
def types_for_is | ||
super << :tmpfs | ||
end | ||
|
||
# Mount options used to define the size of the temporary filesystem | ||
# | ||
# For a sane tmpfs, this should be an array with just one element. But it could be empty | ||
# if the size is not defined or could contain several entries if the "size=" argument is | ||
# specified more than once. | ||
# | ||
# @return [Array<String>] | ||
def size_mount_options | ||
return [] unless mount_point | ||
|
||
mount_point.mount_options.select { |opt| opt =~ /#{SIZE_OPT}=/i } | ||
end | ||
|
||
# String representation of the filesystem size, as specified in the mount options | ||
# | ||
# @return [String, nil] nil if no size is given in the mount options | ||
def size_from_mount_options | ||
option = size_mount_options.last | ||
return nil unless option | ||
|
||
option.split("=").last | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!/usr/bin/env rspec | ||
# Copyright (c) [2020] SUSE LLC | ||
# | ||
# All Rights Reserved. | ||
# | ||
# This program is free software; you can redistribute it and/or modify it | ||
# under the terms of version 2 of the GNU General Public License as published | ||
# by the Free Software Foundation. | ||
# | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
# more details. | ||
# | ||
# You should have received a copy of the GNU General Public License along | ||
# with this program; if not, contact SUSE LLC. | ||
# | ||
# To contact SUSE LLC about this file by physical or electronic mail, you may | ||
# find current contact information at www.suse.com. | ||
|
||
require_relative "../spec_helper" | ||
require "y2storage" | ||
|
||
describe Y2Storage::Filesystems::Tmpfs do | ||
before do | ||
Y2Storage::StorageManager.create_test_instance | ||
end | ||
subject(:filesystem) { described_class.create(fake_devicegraph) } | ||
|
||
describe "#size" do | ||
it "returns the size specified as mount option" do | ||
filesystem.mount_path = "/tmp" | ||
filesystem.mount_point.mount_options = ["rw", "size=128M", "noatime"] | ||
|
||
expect(filesystem.size).to eq Y2Storage::DiskSize.MiB(128) | ||
end | ||
|
||
it "returns zero if there is no mount point" do | ||
expect(filesystem.size).to eq Y2Storage::DiskSize.zero | ||
end | ||
|
||
it "returns zero if there are no mount options" do | ||
filesystem.mount_path = "/tmp" | ||
expect(filesystem.size).to eq Y2Storage::DiskSize.zero | ||
end | ||
end | ||
end |