closefd,ifitfails to readdevice,fixunboundlocalerror

(cherry picked from commit 13bfec47c5573dc3fa1f6cc17d4acf0526e773c4)
This commit is contained in:
liuyumeng 2021-07-24 17:44:48 +08:00 committed by openeuler-sync-bot
parent b053e20273
commit 99ea09e2d7
3 changed files with 81 additions and 1 deletions

View File

@ -0,0 +1,33 @@
From 1383e61211aaeee106b29f2e408fdda8f92370df Mon Sep 17 00:00:00 2001
From: Nijin Ashok <nashok@redhat.com>
Date: Tue, 15 Sep 2020 18:15:32 +0530
Subject: [PATCH] Close fd if it fails to read the device
If the device is unmapped from the storage side, the os.read will
fail with i/o error. However, it's not closing the fd and any
process using the blivet module will hold the device indefeniely. This
prevents administrator from removing the device from multipath
layer.
Conflict:NA
Reference:https://github.com/storaged-project/blivet/commit/1383e61211aaeee106b29f2e408fdda8f92370df
---
blivet/devicelibs/edd.py | 2 ++
1 file changed, 2 insertions(+)
diff --git a/blivet/devicelibs/edd.py b/blivet/devicelibs/edd.py
index a661f73..f64c4e5 100644
--- a/blivet/devicelibs/edd.py
+++ b/blivet/devicelibs/edd.py
@@ -679,6 +679,8 @@ def collect_mbrs(devices, root=None):
testdata_log.debug("device %s data[440:443] raised %s", path, e)
log.error("edd: could not read mbrsig from disk %s: %s",
dev.name, str(e))
+ if fd:
+ os.close(fd)
continue
mbrsig_str = "0x%08x" % mbrsig
--
2.23.0

View File

@ -0,0 +1,39 @@
From 7709298a2b5ab0eb3a2990bb2fd4ead7d1b29674 Mon Sep 17 00:00:00 2001
From: Vojtech Trefny <vtrefny@redhat.com>
Date: Fri, 18 Sep 2020 13:18:06 +0200
Subject: [PATCH] edd: Fix UnboundLocalError when trying to close fd in
collect_mbrs
The "fd" variable is not defined when the "os.open" fails (e.g.
when the device we try to open doesn't exist).
Conflict:NA
Reference:https://github.com/storaged-project/blivet/commit/7709298a2b5ab0eb3a2990bb2fd4ead7d1b29674
---
blivet/devicelibs/edd.py | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/blivet/devicelibs/edd.py b/blivet/devicelibs/edd.py
index f64c4e5..67b7186 100644
--- a/blivet/devicelibs/edd.py
+++ b/blivet/devicelibs/edd.py
@@ -664,6 +664,7 @@ def collect_mbrs(devices, root=None):
"""
mbr_dict = {}
for dev in devices:
+ fd = -1
try:
path = util.Path("/dev", root=root) + dev.name
fd = os.open(path.ondisk, os.O_RDONLY)
@@ -679,7 +680,7 @@ def collect_mbrs(devices, root=None):
testdata_log.debug("device %s data[440:443] raised %s", path, e)
log.error("edd: could not read mbrsig from disk %s: %s",
dev.name, str(e))
- if fd:
+ if fd > 0:
os.close(fd)
continue
--
2.23.0

View File

@ -3,7 +3,7 @@
Name: python-blivet
Version: 3.2.2
Release: 5
Release: 6
Epoch: 1
Summary: A python module for system storage configuration
License: LGPLv2+
@ -21,6 +21,8 @@ Patch0: 0001-force-lvm-plugin.patch
Patch1: Fix-name-resolution-for-MD-devices-and-partitions-on.patch
Patch9000: fix-the-long-hostname.patch
Patch6000: backport-Account-for-pmspare-grow-when-adjusting-thinpool-metadata.patch
Patch6001: backport-Close-fd-if-it-fails-to-read-the-device.patch
Patch6002: backport-Fix-UnboundLocalError.patch
Patch9001: huawei-fix-allocate-partitions-threw-exception-when-raid.patch
%description
@ -122,6 +124,12 @@ make PYTHON=%{__python2} DESTDIR=%{buildroot} install
%doc README
%changelog
* Sat Jul 24 2021 liuyumeng <liuyumeng5@huawei.com> - 3.2.2-6
- Type:bugfix
- ID:NA
- SUG:NA
- DESC:close fd,if it fails to read device,fix unboundlocalerror
* Thu Jun 10 2021 liuxin <liuxin264@huawei.com> - 3.2.2-5
- Type:bugfix
- ID:NA