Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
openSUSE:Step:FrontRunner
targetcli-fb.15595
Split-out-blockdev-readonly-state-detection-hel...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File Split-out-blockdev-readonly-state-detection-helper.patch of Package targetcli-fb.15595
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
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor