targetcli-fb/Split-out-blockdev-readonly-state-detection-helper.patch
Lee Duncan f8c3097b3b Accepting request 596386 from home:dmdiss:bsc1079329_krbd
- Merge RBD support from non-fb version (bsc#1079329)
  + Split-out-blockdev-readonly-state-detection-helper.patch
  + rbd-support.patch (SLE/Leap only, due to LIO kernel dependency)
  + Add explicit Provides for "python-rtslib-rbd"
- Detect write-protected block devices (bsc#1070815)
  + Auto-detect-readonly-state-for-iblock-devices.patch
  + Use-signed-char-instead-of-char.patch

- Automatically generate version string from upstream tag
  + Retain current fb-removed version format used
  + Rename targetcli-fb-2.1.fb47.tar.xz to targetcli-fb-2.1.47.tar.xzar.xz
    and cleanup hardcoded duplicate name/version values in spec

OBS-URL: https://build.opensuse.org/request/show/596386
OBS-URL: https://build.opensuse.org/package/show/Base:System/targetcli-fb?expand=0&rev=18
2018-04-16 20:19:01 +00:00

81 lines
2.6 KiB
Diff

From 7374ba0e53d8e6af4abbb02bd60f35ed541b94f5 Mon Sep 17 00:00:00 2001
From: David Disseldorp <ddiss@suse.de>
Date: Tue, 10 Apr 2018 16:22:54 +0200
Subject: [PATCH 3/4] Split out blockdev readonly state detection helper
So that it can be reused for RBD backstores.
Signed-off-by: David Disseldorp <ddiss@suse.de>
---
targetcli/ui_backstore.py | 40 ++++++++++++++++++++--------------------
1 file changed, 20 insertions(+), 20 deletions(-)
diff --git a/targetcli/ui_backstore.py b/targetcli/ui_backstore.py
index 546d9d2..57dedb1 100644
--- a/targetcli/ui_backstore.py
+++ b/targetcli/ui_backstore.py
@@ -117,6 +117,25 @@ def complete_path(path, stat_fn):
return sorted(filtered,
key=lambda s: '~'+s if s.endswith('/') else s)
+def blk_dev_ro_check(dev):
+ BLKROGET=0x0000125E
+ try:
+ f = os.open(dev, os.O_RDONLY)
+ except (OSError, IOError):
+ raise ExecutionError("Could not open %s" % dev)
+ # ioctl returns an int. Provision a buffer for it
+ buf = array.array('b', [0] * 4)
+ try:
+ fcntl.ioctl(f, BLKROGET, buf)
+ except (OSError, IOError):
+ os.close(f)
+ return False
+
+ os.close(f)
+ if struct.unpack('I', buf)[0] == 0:
+ return False
+ return True
+
class UIALUATargetPortGroup(UIRTSLibNode):
'''
@@ -519,25 +538,6 @@ class UIBlockBackstore(UIBackstore):
self.so_cls = UIBlockStorageObject
UIBackstore.__init__(self, 'block', parent)
- def _ui_block_ro_check(self, dev):
- BLKROGET=0x0000125E
- try:
- f = os.open(dev, os.O_RDONLY)
- except (OSError, IOError):
- raise ExecutionError("Could not open %s" % dev)
- # ioctl returns an int. Provision a buffer for it
- buf = array.array('b', [0] * 4)
- try:
- fcntl.ioctl(f, BLKROGET, buf)
- except (OSError, IOError):
- os.close(f)
- return False
-
- os.close(f)
- if struct.unpack('I', buf)[0] == 0:
- return False
- return True
-
def ui_command_create(self, name, dev, readonly=None, wwn=None):
'''
Creates an Block Storage object. I{dev} is the path to the TYPE_DISK
@@ -548,7 +548,7 @@ class UIBlockBackstore(UIBackstore):
ro_string = self.ui_eval_param(readonly, 'string', None)
if ro_string == None:
# attempt to detect block device readonly state via ioctl
- readonly = self._ui_block_ro_check(dev)
+ readonly = blk_dev_ro_check(dev)
else:
readonly = self.ui_eval_param(readonly, 'bool', False)
--
2.13.6