Skip to content

Commit

Permalink
Merge pull request #106 from joseivanlopez/allow-lun-scan
Browse files Browse the repository at this point in the history
Provide allow_lun_scan info
  • Loading branch information
joseivanlopez committed Jun 16, 2023
2 parents cb55645 + 8ce5c4c commit 54d7d5f
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 1 deletion.
7 changes: 7 additions & 0 deletions package/yast2-s390.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Wed Jun 14 14:38:18 UTC 2023 - José Iván López González <jlopez@suse.com>

- Add info about allow_lun_scan option (related to
gh#openSUSE/agama#626).
- 4.6.3

-------------------------------------------------------------------
Mon Jun 5 10:09:02 UTC 2023 - José Iván López González <jlopez@suse.com>

Expand Down
2 changes: 1 addition & 1 deletion package/yast2-s390.spec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


Name: yast2-s390
Version: 4.6.2
Version: 4.6.3
Release: 0
Group: System/YaST
License: GPL-2.0-only
Expand Down
37 changes: 37 additions & 0 deletions src/lib/y2s390/zfcp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,19 @@

module Y2S390
# Manager for zFCP devices
#
# About allow_lun_scan option:
# * It is enabled by default since SLE 12.
# * It can be disabled by means of a kernel parameter (zfcp.allow_lun_scan=0).
# * Configuring it once the system boots is discouraged, see
# https://bugzilla.suse.com/show_bug.cgi?id=1210597#c20
class ZFCP
include Yast
include Yast::Logger

ALLOW_LUN_SCAN_FILE = "/sys/module/zfcp/parameters/allow_lun_scan".freeze
private_constant :ALLOW_LUN_SCAN_FILE

# Detected controllers
#
# @return [Array<Hash>] keys for each hash:
Expand All @@ -43,6 +52,20 @@ def initialize
@disks = []
end

# Whether the allow_lun_scan option is active
#
# Having allow_lun_scan active has some implications:
# * All LUNs are automatically activated when the controller is activated.
# * LUNs cannot be deactivated.
#
# @return [Boolean]
def allow_lun_scan?
return false unless File.exist?(ALLOW_LUN_SCAN_FILE)

allow = Yast::SCR.Read(path(".target.string"), ALLOW_LUN_SCAN_FILE).chomp
allow == "Y"
end

# Probes the zFCP controllers
def probe_controllers
make_all_devices_visible
Expand Down Expand Up @@ -90,6 +113,20 @@ def activated_controller?(channel)
io.any? { |i| i["active"] }
end

# Whether the controller is performing auto LUN scan
#
# For that, allow_lun_scan must be active and the controller must be running in NPIV mode.
#
# @param channel [String] E.g., "0.0.fa00"
# @return [Boolean]
def lun_scan_controller?(channel)
file = "/sys/bus/ccw/drivers/zfcp/#{channel}/host0/fc_host/host0/port_type"
return false unless allow_lun_scan? && File.exist?(file)

mode = Yast::SCR.Read(path(".target.string"), file).chomp
mode == "NPIV VPORT"
end

# Runs the command for activating a zFCP disk
#
# @param channel [String] E.g., "0.0.fa00"
Expand Down
92 changes: 92 additions & 0 deletions test/y2s390/zfcp_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,34 @@
require "y2s390/zfcp"

describe Y2S390::ZFCP do
describe "#allow_lun_scan?" do
before do
allow(File).to receive(:exist?)
.with("/sys/module/zfcp/parameters/allow_lun_scan")
.and_return(true)

allow(Yast::SCR).to receive(:Read)
.with(anything, "/sys/module/zfcp/parameters/allow_lun_scan")
.and_return(allow_lun_scan)
end

context "if allow_lun_scan is active" do
let(:allow_lun_scan) { "Y" }

it "returns true" do
expect(subject.allow_lun_scan?).to eq(true)
end
end

context "if allow_lun_scan is not active" do
let(:allow_lun_scan) { "N" }

it "returns false" do
expect(subject.allow_lun_scan?).to eq(false)
end
end
end

describe "#probe_controllers" do
before do
allow(Yast::SCR).to receive(:Read).with(Yast.path(".probe.storage"))
Expand Down Expand Up @@ -144,6 +172,70 @@
end
end

describe "#lun_scan_controller?" do
before do
allow(subject).to receive(:allow_lun_scan?).and_return(allow_lun_scan)

allow(Yast::SCR).to receive(:Read)
.with(anything, "/sys/module/zfcp/parameters/allow_lun_scan")
.and_return(allow_lun_scan)

allow(File).to receive(:exist?)
.with("/sys/bus/ccw/drivers/zfcp/0.0.fa00/host0/fc_host/host0/port_type")
.and_return(controller_active)

allow(Yast::SCR).to receive(:Read)
.with(anything, "/sys/bus/ccw/drivers/zfcp/0.0.fa00/host0/fc_host/host0/port_type")
.and_return(controller_mode)
end

let(:allow_lun_scan) { nil }

let(:controller_active) { nil }

let(:controller_mode) { nil }

context "if allow_lun_scan is not active" do
let(:allow_lun_scan) { false }

it "returns false" do
expect(subject.lun_scan_controller?("0.0.fa00")).to eq(false)
end
end

context "if allow_lun_scan is active and the controller is not active" do
let(:allow_lun_scan) { true }

let(:controller_active) { false }

it "returns false" do
expect(subject.lun_scan_controller?("0.0.fa00")).to eq(false)
end
end

context "if allow_lun_scan is active and the controller is active" do
let(:allow_lun_scan) { true }

let(:controller_active) { true }

context "and the controller is not running in NPIV mode" do
let(:controller_mode) { "" }

it "returns false" do
expect(subject.lun_scan_controller?("0.0.fa00")).to eq(false)
end
end

context "and the controller is running in NPIV mode" do
let(:controller_mode) { "NPIV VPORT" }

it "returns true" do
expect(subject.lun_scan_controller?("0.0.fa00")).to eq(true)
end
end
end
end

describe "#activate_disk" do
before do
allow(Yast::SCR).to receive(:Execute).with(anything, command).and_return(output)
Expand Down

0 comments on commit 54d7d5f

Please sign in to comment.