Compare commits

1 Commits
main ... 1.1

13 changed files with 371 additions and 272 deletions

View File

@@ -1,85 +0,0 @@
From e70542fec8f78d156cee101bc8680ddabbbbd7f6 Mon Sep 17 00:00:00 2001
From: Lee Duncan <lduncan@suse.com>
Date: Mon, 24 Mar 2025 11:21:59 -0700
Subject: [PATCH] Fix issue with Path(...).open: needs parenthesis
There are places where the code does this pattern:
with Path(some_path).open as f:
... (do stuff)
But that generates an error message like:
/> restoreconfig temp.json
Traceback (most recent call last):
File "/usr/bin/targetcli", line 8, in <module>
sys.exit(main())
~~~~^^
File "/usr/lib/python3.13/site-packages/targetcli/targetcli_shell.py", line 313, in main
shell.run_interactive()
~~~~~~~~~~~~~~~~~~~~~^^
File "/usr/lib/python3.13/site-packages/configshell/shell.py", line 899, in run_interactive
self._cli_loop()
~~~~~~~~~~~~~~^^
File "/usr/lib/python3.13/site-packages/configshell/shell.py", line 728, in _cli_loop
self.run_cmdline(cmdline)
~~~~~~~~~~~~~~~~^^^^^^^^^
File "/usr/lib/python3.13/site-packages/configshell/shell.py", line 842, in run_cmdline
self._execute_command(path, command, pparams, kparams)
~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.13/site-packages/configshell/shell.py", line 817, in _execute_command
result = target.execute_command(command, pparams, kparams)
File "/usr/lib/python3.13/site-packages/configshell/node.py", line 1405, in execute_command
return method(*pparams, **kparams)
File "/usr/lib/python3.13/site-packages/targetcli/ui_root.py", line 207, in ui_command_restoreconfig
errors = self.rtsroot.restore_from_file(savefile, clear_existing,
target, storage_object)
File "/usr/lib/python3.13/site-packages/rtslib/root.py", line 490, in restore_from_file
with Path(restore_file).open as f:
^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'method' object does not support the context manager protocol
Adding empty parenthesis after the "open" fixes the issue.
---
rtslib/root.py | 4 ++--
scripts/convert-to-json | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/rtslib/root.py b/rtslib/root.py
index 749a80620e65..b05d380a6c50 100644
--- a/rtslib/root.py
+++ b/rtslib/root.py
@@ -190,7 +190,7 @@ class RTSRoot(CFSNode):
current = self.dump()
try:
- with Path(save_file).open as f:
+ with Path(save_file).open() as f:
saveconf = json.loads(f.read())
except OSError as e:
if e.errno == errno.ENOENT:
@@ -487,7 +487,7 @@ class RTSRoot(CFSNode):
if not restore_file:
restore_file = default_save_file
- with Path(restore_file).open as f:
+ with Path(restore_file).open() as f:
config = json.loads(f.read())
return self.restore(config, target, storage_object,
clear_existing=clear_existing,
diff --git a/scripts/convert-to-json b/scripts/convert-to-json
index daa82daf705b..7677350f3040 100755
--- a/scripts/convert-to-json
+++ b/scripts/convert-to-json
@@ -318,7 +318,7 @@ def parse(txt, cur):
elif txt[cur] == "fabric":
cur = parse_fabric(txt, cur)
-with Path("/etc/target/scsi_target.lio").open as f:
+with Path("/etc/target/scsi_target.lio").open() as f:
txt = f.read()
txt = split(txt)
cur = parse(txt, 0)
--
2.43.0

View File

@@ -1,44 +0,0 @@
From 4677e05cf54eab01bde48dcf3ae1488b6a8241b4 Mon Sep 17 00:00:00 2001
From: Alfred Wingate <parona@protonmail.com>
Date: Mon, 10 Mar 2025 09:50:53 +0200
Subject: [PATCH] Install targetctl as an entrypoint
scripts = ['scripts/targetctl'] didn't survive the transition to hatch,
readd it with required modifications.
Bug: https://bugs.gentoo.org/950964
Fixes: 9eea9a306f83b039629350dace0983f65fa9c64f
Signed-off-by: Alfred Wingate <parona@protonmail.com>
---
pyproject.toml | 5 ++++-
scripts/targetctl => rtslib/targetctl.py | 0
2 files changed, 4 insertions(+), 1 deletion(-)
rename scripts/targetctl => rtslib/targetctl.py (100%)
diff --git a/pyproject.toml b/pyproject.toml
index c07186aa007c..adebb9f104ea 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -31,6 +31,9 @@ paths = ["COPYING"]
[project.urls]
Homepage = "http://github.com/open-iscsi/rtslib-fb"
+[project.scripts]
+targetctl = "rtslib.targetctl:main"
+
[tool.hatch.version]
source = "vcs"
@@ -90,4 +93,4 @@ ignore = [
]
[tool.ruff.lint.per-file-ignores]
# Magic value used in comparison
-"scripts/targetctl" = ["PLR2004"]
+"rtslib/targetctl.py" = ["PLR2004"]
diff --git a/scripts/targetctl b/rtslib/targetctl.py
similarity index 100%
rename from scripts/targetctl
rename to rtslib/targetctl.py
--
2.43.0

View File

@@ -1,26 +0,0 @@
From 631685f400d3bd170a449503ce062a82c58d823a Mon Sep 17 00:00:00 2001
From: Lee Duncan <lduncan@suse.com>
Date: Mon, 24 Mar 2025 10:00:21 -0700
Subject: [PATCH] Remove use of /usr/bin/python
The targetctl.py script was using /usr/bin/python, even
though this package has been ported to python3.
This makes installing it on modern systems fail.
---
rtslib/targetctl.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/rtslib/targetctl.py b/rtslib/targetctl.py
index e304be0d2f38..124d03f3c1fb 100755
--- a/rtslib/targetctl.py
+++ b/rtslib/targetctl.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/python3
'''
targetctl
--
2.43.0

View File

@@ -3,12 +3,11 @@
<param name="scm">git</param> <param name="scm">git</param>
<param name="url">https://github.com/open-iscsi/rtslib-fb.git</param> <param name="url">https://github.com/open-iscsi/rtslib-fb.git</param>
<param name="subdir"></param> <param name="subdir"></param>
<param name="package-meta">yes</param>
<param name="filename">python-rtslib-fb</param> <param name="filename">python-rtslib-fb</param>
<param name="versionformat">@PARENT_TAG@</param> <param name="versionformat">@PARENT_TAG@</param>
<param name="versionrewrite-pattern">v(\d*\.\d*\.)fb(\d*)</param> <param name="versionrewrite-pattern">v(\d*\.\d*\.)fb(\d*)</param>
<param name="versionrewrite-replacement">\1\2</param> <param name="versionrewrite-replacement">\1\2</param>
<param name="revision">v2.2.2</param> <param name="revision">v2.1.75</param>
<param name="changesgenerate">enable</param> <param name="changesgenerate">enable</param>
</service> </service>
<service name="recompress" mode="disabled"> <service name="recompress" mode="disabled">

View File

@@ -1,4 +1,4 @@
<servicedata> <servicedata>
<service name="tar_scm"> <service name="tar_scm">
<param name="url">https://github.com/open-iscsi/rtslib-fb.git</param> <param name="url">https://github.com/open-iscsi/rtslib-fb.git</param>
<param name="changesrevision">139c7770600cd7e367ebc7504b991551c7e67bc4</param></service></servicedata> <param name="changesrevision">5469e71cfc47a5a869dae6bc7c1e0b2db7ae4c6a</param></service></servicedata>

BIN
python-rtslib-fb-v2.1.75.tar.xz (Stored with Git LFS) Normal file

Binary file not shown.

BIN
python-rtslib-fb-v2.2.2.tar.xz (Stored with Git LFS)

Binary file not shown.

View File

@@ -1,74 +1,3 @@
-------------------------------------------------------------------
Sat Mar 22 15:35:05 UTC 2025 - lduncan@suse.com
- Update to version v2.2.2:
* Explicitly set build target wheel packages
* Fix the program name in pyproject.toml
* Fix and update pre-commit ruf check
* Add PyPA publish and pre-commit check workflows
* Add rtslib_fb import compability
* Silently ignore OSError on close
* fixup! Fix various issues found by ruff linter rules
* Add ruff rules, pre-commit config
* Convert codebase to pathlib
* Fix various issues found by ruff linter rules
* Refactor code to Python>=3.9 to pass pyupgrade
* Fix issues found by ruff pep8-naming rules
* Fix issues found by ruff pycodestyle rules
* Use f-strings
* Fixing issues found by ruff Pyflakes rules
* Move to PEP-621; Drop -fb from module name
* rtslib: explicitely import "kmod.error" and "kmod.Kmod"
* rtslib/LUN: add some ALUA property
Also, updated the SPEC file, and removed patch no longer needed,
since the problem is no longer present:
* rtslib-Fix-handling-of-sysfs-RW-attrs-that-are-actually-RO.patch
Added three commits, one from upstream, the others submitted there:
* Install-targetctl-as-an-entrypoint.patch (added from upstream)
* Remove-use-of-usr-bin-python.patch (submitted upstream)
* Fix-issue-with-Path-open-needs-parenthesis.patch (submitted upstream)
-------------------------------------------------------------------
Mon Jun 17 16:09:09 UTC 2024 - Lee Duncan <lduncan@suse.com>
- Revert rtslib-refactor-to-python3.patch, which breaks targetcli
(bsc#1226388)
-------------------------------------------------------------------
Fri Jun 7 13:12:41 UTC 2024 - Markéta Machová <mmachova@suse.com>
- Add rtslib-refactor-to-python3.patch to get rid of six
-------------------------------------------------------------------
Thu May 16 15:10:26 UTC 2024 - Dominique Leuenberger <dimstar@opensuse.org>
- Use %autosetup macro: allows us to eliminate usage of deprecated
%patchN syntax.
-------------------------------------------------------------------
Tue Jan 9 21:43:21 UTC 2024 - Matej Cepl <mcepl@cepl.eu>
- Clean up the SPEC file
-------------------------------------------------------------------
Tue Jan 9 11:49:34 UTC 2024 - David Disseldorp <ddiss@suse.com>
- Drop downstream-only LIO target_core_rbd support (bsc#1218634)
* rbd-support-disable_emulate_legacy_capacity.patch
* rbd-support.patch
-------------------------------------------------------------------
Thu Oct 05 09:08:31 UTC 2023 - dmueller@suse.com
- Update to version v2.1.76:
* version 2.1.76
* rtslib: remove the limit of 255 max mapped LUNs
* setup.py: match __version__ with optional trailing ".g<hash>".
* rtslib: Don't create /var/run on import
* Fix inability to create ACLs for some FC cards
------------------------------------------------------------------- -------------------------------------------------------------------
Fri Apr 21 12:33:32 UTC 2023 - Dirk Müller <dmueller@suse.com> Fri Apr 21 12:33:32 UTC 2023 - Dirk Müller <dmueller@suse.com>

View File

@@ -1,7 +1,7 @@
# #
# spec file for package python-rtslib-fb # spec file for package python-rtslib-fb
# #
# Copyright (c) 2025 SUSE LLC # Copyright (c) 2023 SUSE LLC
# #
# All modifications and additions to the file contributed by third parties # All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed # remain the property of their copyright owners, unless otherwise agreed
@@ -16,42 +16,51 @@
# #
%if 0%{?suse_version} > 1500
%bcond_without libalternatives
%else
%bcond_with libalternatives
%endif
%define dbdir %{_sysconfdir}/target %define dbdir %{_sysconfdir}/target
%define oldpython python %{?!python_module:%define python_module() python-%{**} python3-%{**}}
%define cpkg %{oldpython}-rtslib-fb-common
%{?sle15_python_module_pythons} %{?sle15_python_module_pythons}
Name: python-rtslib-fb Name: python-rtslib-fb
Version: 2.2.2 Version: 2.1.75
Release: 0%{?dist} Release: 0%{?dist}
Summary: API for Linux kernel SCSI target (aka LIO) Summary: API for Linux kernel SCSI target (aka LIO)
License: Apache-2.0 License: Apache-2.0
Group: Development/Languages/Python Group: Development/Languages/Python
URL: https://github.com/open-iscsi/rtslib-fb.git URL: https://github.com/open-iscsi/rtslib-fb.git
Source: python-rtslib-fb-v%{version}.tar.xz Source: python-rtslib-fb-v%{version}.tar.xz
Patch1: rtslib-target-service-for-suse.patch Patch1: rbd-support.patch
Patch2: Install-targetctl-as-an-entrypoint.patch Patch2: rtslib-Fix-handling-of-sysfs-RW-attrs-that-are-actually-RO.patch
Patch3: Remove-use-of-usr-bin-python.patch Patch3: rtslib-target-service-for-suse.patch
Patch4: Fix-issue-with-Path-open-needs-parenthesis.patch Patch4: rbd-support-disable_emulate_legacy_capacity.patch
BuildRequires: %{python_module devel}
BuildRequires: %{python_module hatch_vcs}
BuildRequires: %{python_module hatchling}
BuildRequires: %{python_module pip}
BuildRequires: %{python_module pyudev} BuildRequires: %{python_module pyudev}
BuildRequires: %{python_module setuptools} BuildRequires: %{python_module setuptools}
BuildRequires: %{python_module wheel} BuildRequires: %{python_module six}
BuildRequires: fdupes BuildRequires: fdupes
BuildRequires: git
BuildRequires: python-rpm-macros >= 20210929 BuildRequires: python-rpm-macros >= 20210929
BuildRequires: pkgconfig(systemd)
Requires: %{cpkg}
Requires: python-pyudev Requires: python-pyudev
%define oldpython python
%define cpkg %{oldpython}-rtslib-fb-common
Requires: %{cpkg}
%if %{with libalternatives}
Requires: alts
BuildRequires: alts
%else
Requires(post): update-alternatives
Requires(postun):update-alternatives
%endif
Provides: python-rtslib = %{version}-%{release} Provides: python-rtslib = %{version}-%{release}
Obsoletes: python-rtslib < %{version} Obsoletes: python-rtslib < %{version}
%if 0%{?sle_version} >= 150000
# explicit Provides advertising RBD support
Provides: python-rtslib-rbd = %{version}
Obsoletes: python-rtslib-rbd < %{version}
%endif
BuildArch: noarch BuildArch: noarch
Requires(post): update-alternatives
Requires(postun): update-alternatives
%python_subpackages %python_subpackages
@@ -61,23 +70,31 @@ SCSI target, present in 3.x Linux kernel versions. rtslib-fb is licensed under
the Apache 2.0 license. Contributions are welcome the Apache 2.0 license. Contributions are welcome
%package -n %{cpkg} %package -n %{cpkg}
Summary: Common python-rtslib-fb subpackage for all Python 3 versions Summary: Common python-rtslib-fb subpackage for Python 2 or 3
Group: Development/Languages/Python Group: Development/Languages/Python
Obsoletes: %{name} < %{version}-%{release} Obsoletes: %{name} < %{version}-%{release}
%description -n %{cpkg} %description -n %{cpkg}
python-rtslib-fb-common is the invariant base package needed by all python-rtslib-fb-common is the invariant base package needed by both
version of python3*-rtslib-fb. python2-rtslib-fb and python3-rtslib-fb.
%prep %prep
%autosetup -p1 -n python-rtslib-fb-v%{version} %setup -q -n python-rtslib-fb-v%{version}
%if 0%{?sle_version} >= 150000
# RBD support is dependent on LIO changes present in the SLE/Leap kernel
%patch1 -p1
%patch4 -p1
%endif
%patch2 -p1
%patch3 -p1
%build %build
%pyproject_wheel %python_build
%install %install
%pyproject_install %python_install
%python_clone -a %{buildroot}/%{_bindir}/targetctl %python_clone -a %{buildroot}/%{_bindir}/targetctl
%fdupes %{buildroot}
install -d -m755 %{buildroot}%{_mandir}/man5 install -d -m755 %{buildroot}%{_mandir}/man5
install -m644 doc/saveconfig.json.5 %{buildroot}%{_mandir}/man5 install -m644 doc/saveconfig.json.5 %{buildroot}%{_mandir}/man5
install -d -m755 %{buildroot}%{_mandir}/man8 install -d -m755 %{buildroot}%{_mandir}/man8
@@ -88,7 +105,6 @@ install -d -m755 %{buildroot}/%{dbdir}/alua
mkdir -p %{buildroot}/%{_unitdir}/ mkdir -p %{buildroot}/%{_unitdir}/
install -m644 systemd/target.service %{buildroot}/%{_unitdir} install -m644 systemd/target.service %{buildroot}/%{_unitdir}
install -d -m755 %{buildroot}%{_sbindir} install -d -m755 %{buildroot}%{_sbindir}
%fdupes %{buildroot}
ln -s %{_sbindir}/service %{buildroot}/%{_sbindir}/rctarget ln -s %{_sbindir}/service %{buildroot}/%{_sbindir}/rctarget
%post %post
@@ -101,6 +117,8 @@ ln -s %{_sbindir}/service %{buildroot}/%{_sbindir}/rctarget
%pre %pre
%{service_add_pre target.service} %{service_add_pre target.service}
# If libalternatives is used: Removing old update-alternatives entries.
%python_libalternatives_reset_alternative targetctl
%preun %preun
%{stop_on_removal target} %{stop_on_removal target}
@@ -120,8 +138,7 @@ ln -s %{_sbindir}/service %{buildroot}/%{_sbindir}/rctarget
%files %{python_files} %files %{python_files}
%python_alternative %{_bindir}/targetctl %python_alternative %{_bindir}/targetctl
%{python_sitelib}/rtslib* %{python_sitelib}/*
%pycache_only %{python_sitelib}/__pycache__
%files -n %{cpkg} %files -n %{cpkg}
%license COPYING %license COPYING
@@ -131,7 +148,7 @@ ln -s %{_sbindir}/service %{buildroot}/%{_sbindir}/rctarget
%dir %{dbdir}/alua %dir %{dbdir}/alua
%{_unitdir}/target.service %{_unitdir}/target.service
%{_sbindir}/rctarget %{_sbindir}/rctarget
%{_mandir}/man5/saveconfig.json.5%{?ext_man} %doc %{_mandir}/man5/saveconfig.json.5.gz
%{_mandir}/man8/targetctl.8%{?ext_man} %doc %{_mandir}/man8/targetctl.8.gz
%changelog %changelog

View File

@@ -0,0 +1,96 @@
From 4e633572ef8a9b07d1ae1252cf4c2b2daf673998 Mon Sep 17 00:00:00 2001
From: Mykola Golub <mgolub@suse.com>
Date: Thu, 3 Feb 2022 18:40:47 +0000
Subject: [PATCH] disable emulate_legacy_capacity on creating RBD backstore
When rbd image has object-map feature set, `enable` will fail
unless emulate_legacy_capacity (default is 1) is set to 0.
Provide a possibility to disable emulate_legacy_capacity when
creating backstore (before enabling it) via additional
disable_emulate_legacy_capacity parameter.
We might eventually want to merge the rbd support patches into one,
but right now keeping them separate looks useful for tracking the
change (feature) added here.
This patch is for the changes added by "rbd support" patch
(rbd-support.patch) and thus it is not needed upstream until
the rbd support is added upstream.
Eventualy we might want to merge this and "rbd support" patches
into one. For now it looks useful to keep it separate to track
the change (feature) added by this patch.
ceph-iscsi needs this change to support rbd images with
object-map feature enabled.
Reviewed-by: David Disseldorp <ddiss@suse.de>
Signed-off-by: Mykola Golub <mgolub@suse.com>
---
rtslib/tcm.py | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/rtslib/tcm.py b/rtslib/tcm.py
index d42a78f..3bf599d 100644
--- a/rtslib/tcm.py
+++ b/rtslib/tcm.py
@@ -809,7 +809,8 @@ class RBDStorageObject(StorageObject):
# RBDStorageObject private stuff
def __init__(self, name, dev=None, wwn=None, readonly=False,
- write_back=False, index=None):
+ write_back=False, index=None,
+ disable_emulate_legacy_capacity=False):
'''
A RBDIOStorageObject can be instantiated in two ways:
- B{Creation mode}: If I{dev} is specified, the underlying configFS
@@ -822,6 +823,10 @@ class RBDStorageObject(StorageObject):
I{name}. The underlying configFS object must already exist in
that mode, or instantiation will fail.
+ Note, setting disable_emulate_legacy_capacity to True is dangerous
+ for any image that has previously been iSCSI exported with
+ emulate_legacy_capacity enabled.
+
@param name: The name of the RBDIOStorageObject.
@type name: string
@param dev: The path to the backend rbd device to be used.
@@ -835,20 +840,23 @@ class RBDStorageObject(StorageObject):
@type readonly: boolean
@param write_back: Enable write back cache.
@type write_back: boolean
+ @param disable_emulate_legacy_capacity: Disable emulate_legacy_capacity mode.
+ @type disable_emulate_legacy_capacity: boolean
@return: A RBDIOStorageObject object.
'''
if dev is not None:
super(RBDStorageObject, self).__init__(name, 'create', index)
try:
- self._configure(dev, wwn, readonly)
+ self._configure(dev, wwn, readonly,
+ disable_emulate_legacy_capacity)
except:
self.delete()
raise
else:
super(RBDStorageObject, self).__init__(name, 'lookup', index)
- def _configure(self, dev, wwn, readonly):
+ def _configure(self, dev, wwn, readonly, disable_emulate_legacy_capacity):
self._check_self()
if get_blockdev_type(dev) != 0:
raise RTSLibError("Device %s is not a TYPE_DISK rbd device" % dev)
@@ -858,6 +866,8 @@ class RBDStorageObject(StorageObject):
self._set_udev_path(dev)
self._control("udev_path=%s" % dev)
self._control("readonly=%d" % readonly)
+ if disable_emulate_legacy_capacity:
+ self.set_attribute("emulate_legacy_capacity", 0)
self._enable()
super(RBDStorageObject, self)._configure(wwn)
--
2.33.1

154
rbd-support.patch Normal file
View File

@@ -0,0 +1,154 @@
From 9496352d515b9f440b68c8534e41899cf1a9570e Mon Sep 17 00:00:00 2001
From: Mike Christie <mchristi@redhat.com>
Date: Wed, 29 Jul 2015 04:28:02 -0500
Subject: [PATCH] rbd support
rtslib-fb-rbd-support.patch obtained from:
https://marc.info/?l=ceph-devel&m=143816209010058
Reviewed-by: David Disseldorp <ddiss@suse.de>
---
rtslib/__init__.py | 1
rtslib/tcm.py | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 104 insertions(+)
--- a/rtslib/__init__.py
+++ b/rtslib/__init__.py
@@ -32,6 +32,7 @@ from .fabric import FabricModule
from .tcm import FileIOStorageObject, BlockStorageObject
from .tcm import PSCSIStorageObject, RDMCPStorageObject, UserBackedStorageObject
+from .tcm import RBDStorageObject
from .tcm import StorageObjectFactory
from .alua import ALUATargetPortGroup
--- a/rtslib/tcm.py
+++ b/rtslib/tcm.py
@@ -801,6 +801,111 @@ class BlockStorageObject(StorageObject):
d['dev'] = self.udev_path
return d
+class RBDStorageObject(StorageObject):
+ '''
+ An interface to configFS storage objects for RBD backstore.
+ '''
+
+ # RBDStorageObject private stuff
+
+ def __init__(self, name, dev=None, wwn=None, readonly=False,
+ write_back=False, index=None):
+ '''
+ A RBDIOStorageObject can be instantiated in two ways:
+ - B{Creation mode}: If I{dev} is specified, the underlying configFS
+ object will be created with that parameter.
+ No RBDIOStorageObject with the same I{name} can pre-exist in
+ the parent Backstore in that mode.
+ - B{Lookup mode}: If I{dev} is not set, then the
+ RBDIOStorageObject will be bound to the existing configFS
+ object in the parent Backstore having the specified
+ I{name}. The underlying configFS object must already exist in
+ that mode, or instantiation will fail.
+
+ @param name: The name of the RBDIOStorageObject.
+ @type name: string
+ @param dev: The path to the backend rbd device to be used.
+ - Example: I{dev="/dev/sda"}.
+ - The only device type that is accepted I{TYPE_DISK}.
+ For other device types, use pscsi.
+ @type dev: string
+ @param wwn: T10 WWN Unit Serial, will generate if None
+ @type wwn: string
+ @param readonly: Use to read only.
+ @type readonly: boolean
+ @param write_back: Enable write back cache.
+ @type write_back: boolean
+ @return: A RBDIOStorageObject object.
+ '''
+
+ if dev is not None:
+ super(RBDStorageObject, self).__init__(name, 'create', index)
+ try:
+ self._configure(dev, wwn, readonly)
+ except:
+ self.delete()
+ raise
+ else:
+ super(RBDStorageObject, self).__init__(name, 'lookup', index)
+
+ def _configure(self, dev, wwn, readonly):
+ self._check_self()
+ if get_blockdev_type(dev) != 0:
+ raise RTSLibError("Device %s is not a TYPE_DISK rbd device" % dev)
+ if is_dev_in_use(dev):
+ raise RTSLibError("Cannot configure StorageObject because "
+ + "device %s is already in use" % dev)
+ self._set_udev_path(dev)
+ self._control("udev_path=%s" % dev)
+ self._control("readonly=%d" % readonly)
+ self._enable()
+
+ super(RBDStorageObject, self)._configure(wwn)
+
+ def _get_major(self):
+ self._check_self()
+ return int(self._parse_info('Major'))
+
+ def _get_minor(self):
+ self._check_self()
+ return int(self._parse_info('Minor'))
+
+ def _get_size(self):
+ # udev_path doesn't work here, what if LV gets renamed?
+ return get_size_for_disk_name(self._parse_info('device')) * int(self._parse_info('SectorSize'))
+
+ def _get_wb_enabled(self):
+ self._check_self()
+ return bool(int(self.get_attribute("emulate_write_cache")))
+
+ def _get_readonly(self):
+ self._check_self()
+ # 'readonly' not present before kernel 3.6
+ try:
+ return bool(int(self._parse_info('readonly')))
+ except AttributeError:
+ return False
+
+ # RBDStorageObject public stuff
+
+ major = property(_get_major,
+ doc="Get the block device major number")
+ minor = property(_get_minor,
+ doc="Get the block device minor number")
+ size = property(_get_size,
+ doc="Get the block device size")
+ write_back = property(_get_wb_enabled,
+ doc="True if write-back, False if write-through (write cache disabled)")
+ readonly = property(_get_readonly,
+ doc="True if the device is read-only, False if read/write")
+
+ def dump(self):
+ d = super(RBDStorageObject, self).dump()
+ d['write_back'] = self.write_back
+ d['readonly'] = self.readonly
+ d['wwn'] = self.wwn
+ d['dev'] = self.udev_path
+ return d
class UserBackedStorageObject(StorageObject):
'''
@@ -940,6 +1041,7 @@ so_mapping = {
"fileio": FileIOStorageObject,
"iblock": BlockStorageObject,
"block": BlockStorageObject,
+ "rbd": RBDStorageObject,
"user": UserBackedStorageObject,
}
@@ -950,6 +1052,7 @@ bs_params = {
FileIOStorageObject: dict(name='fileio'),
BlockStorageObject: dict(name='block', alt_dirprefix='iblock'),
UserBackedStorageObject: dict(name='user'),
+ RBDStorageObject: dict(name='rbd'),
}
bs_cache = {}

View File

@@ -0,0 +1,65 @@
From 10f23379b2d3e2226782e2d6185bee22cc586170 Mon Sep 17 00:00:00 2001
From: Lee Duncan <lduncan@suse.com>
Date: Thu, 15 Oct 2020 14:21:20 -0700
Subject: [PATCH] Fix handling of sysfs RW attrs that are actually RO
Kernel commit 356ba2a8bc8d ("scsi: target: tcmu: Make
gr_support and alua_support attributes writable"), made the
alua_support and pgr_support sysfs attributes writable
so that individual target drivers could change them.
This means that the filesystem attributes might saw
read-write, but the attributes can in fact be read-only.
When a user tries to write to them, in this case,
they EINVAL.
This causes rtslib to throw error messages when one does
a "targetctl restore" like these:
> Storage Object fileio/file01: Cannot set attribute alua_support: [Errno 22] Invalid argument, skipped
> Storage Object fileio/file01: Cannot set attribute pgr_support: [Errno 22] Invalid argument, skipped
While these messages are benign, they will cause confusion, since
(1) there's nothing wrong, and (2) they didn't occur before above-
mentioned kernel commit.
This fix tells rtslib to ignore errno 22 for these two attributes.
---
rtslib/node.py | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/rtslib/node.py b/rtslib/node.py
index 415f45d675f9..ed08030002bb 100644
--- a/rtslib/node.py
+++ b/rtslib/node.py
@@ -20,6 +20,7 @@ under the License.
import os
import stat
+import errno
from .utils import fread, fwrite, RTSLibError, RTSLibNotInCFS
@@ -28,6 +29,10 @@ class CFSNode(object):
# Where is the configfs base LIO directory ?
configfs_dir = '/sys/kernel/config/target'
+ # these two attributes can have file permissions of
+ # read-write but be read-only
+ may_be_ro_attrs = ['alua_support', 'pgr_support']
+
# CFSNode private stuff
def __init__(self):
@@ -172,7 +177,8 @@ class CFSNode(object):
try:
fwrite(path, "%s" % str(value))
except Exception as e:
- raise RTSLibError("Cannot set attribute %s: %s" % (attribute, e))
+ if attribute not in self.may_be_ro_attrs or e.errno != errno.EINVAL:
+ raise RTSLibError("Cannot set attribute %s: %s" % (attribute, e))
def get_attribute(self, attribute):
'''
--
2.26.2

View File

@@ -1,24 +1,18 @@
From: Lee Duncan <lduncan@suse.com>
Date: Sat Mar 22 10:52:22 AM PDT 2025
Subject: [PATCH] blah
Blah
---
--- a/systemd/target.service 2019-01-31 11:11:28.517558290 -0800 --- a/systemd/target.service 2019-01-31 11:11:28.517558290 -0800
+++ b/systemd/target.service 2020-10-16 09:34:28.888091013 -0700 +++ b/systemd/target.service 2020-10-16 09:34:28.888091013 -0700
@@ -6,9 +6,12 @@ After=sys-kernel-config.mount network.ta @@ -6,10 +6,13 @@ After=sys-kernel-config.mount network.ta
[Service] [Service]
Type=oneshot Type=oneshot
RemainAfterExit=yes RemainAfterExit=yes
-ExecStart=/usr/bin/targetctl restore -ExecStart=/usr/bin/targetctl restore
-ExecStop=/usr/bin/targetctl clear
+Environment=CONFIG_FILE=/etc/target/saveconfig.json +Environment=CONFIG_FILE=/etc/target/saveconfig.json
+EnvironmentFile=-/etc/sysconfig/target +EnvironmentFile=-/etc/sysconfig/target
+ExecStart=/usr/bin/targetctl restore $CONFIG_FILE +ExecStart=/usr/bin/targetctl restore $CONFIG_FILE
+ExecStop=/usr/bin/targetctl save $CONFIG_FILE +ExecStop=/usr/bin/targetctl save $CONFIG_FILE
ExecStop=/usr/bin/targetctl clear
SyslogIdentifier=target SyslogIdentifier=target
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target
-
+Alias=targetcli.service +Alias=targetcli.service