Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=01ef2f2525e8733f01443…
Commit: 01ef2f2525e8733f01443987b2c6f99882e04f3d
Parent: 0d957dcacc3118e9f2d4e83830d6c93b8955fd5f
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Tue Jun 7 08:21:03 2022 -0500
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Thu Jun 30 10:55:16 2022 -0500
lvmdbusd: Remove try/except for mkfifo
We should never run into this error condition when using tempfile.mkdtemp.
---
daemons/lvmdbusd/lvm_shell_proxy.py.in | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/daemons/lvmdbusd/lvm_shell_proxy.py.in b/daemons/lvmdbusd/lvm_shell_proxy.py.in
index fa2415fcf..5802d2d70 100644
--- a/daemons/lvmdbusd/lvm_shell_proxy.py.in
+++ b/daemons/lvmdbusd/lvm_shell_proxy.py.in
@@ -122,11 +122,8 @@ class LVMShellProxy(object):
tmp_dir = tempfile.mkdtemp(prefix="lvmdbus_")
tmp_file = "%s/lvmdbus_report" % (tmp_dir)
- try:
- # Let's create a fifo for the report output
- os.mkfifo(tmp_file, 0o600)
- except FileExistsError:
- pass
+ # Create a fifo for the report output
+ os.mkfifo(tmp_file, 0o600)
# Open the fifo for use to read and for lvm child process to write to.
self.report_fd = os.open(tmp_file, os.O_NONBLOCK)
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=73121e3f0712d228e713b…
Commit: 73121e3f0712d228e713b71468484ca55d62d93b
Parent: 8fa8dfdb8c3b5310a5b43c99fd088f4f076b5903
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Mon Jun 6 10:01:18 2022 -0500
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Thu Jun 30 10:55:16 2022 -0500
lvmdbustest: Increase number of LVs
As storage is getting faster, we need to create more LVs to pass this test.
---
test/dbus/lvmdbustest.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/test/dbus/lvmdbustest.py b/test/dbus/lvmdbustest.py
index ae02c5fef..12f1741b1 100755
--- a/test/dbus/lvmdbustest.py
+++ b/test/dbus/lvmdbustest.py
@@ -1170,7 +1170,7 @@ class TestDbusService(unittest.TestCase):
return
# This may not pass
- for i in [64, 128]:
+ for i in [128, 256]:
yes = self._test_expired_timer(i)
if yes:
break
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=8fa8dfdb8c3b5310a5b43…
Commit: 8fa8dfdb8c3b5310a5b43c99fd088f4f076b5903
Parent: 55059e002abb3d858e4c53ac0da078ca853ff1f4
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Mon Jun 6 09:59:59 2022 -0500
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Thu Jun 30 10:55:16 2022 -0500
lvmdbustest: Correct comment spelling/grammar
---
test/dbus/lvmdbustest.py | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/test/dbus/lvmdbustest.py b/test/dbus/lvmdbustest.py
index e16a484b7..ae02c5fef 100755
--- a/test/dbus/lvmdbustest.py
+++ b/test/dbus/lvmdbustest.py
@@ -153,7 +153,7 @@ def get_objects():
rc[interface].append(proxy)
# At this point we have a full population of everything, we now need to
- # prune the the objects if we are filtering PVs with a sub selection.
+ # prune the objects if we are filtering PVs with a sub selection.
return _prune(rc, pv_device_list), bus
@@ -1111,7 +1111,7 @@ class TestDbusService(unittest.TestCase):
def _test_expired_timer(self, num_lvs):
rc = False
- # In small configurations lvm is pretty snappy, so lets create a VG
+ # In small configurations lvm is pretty snappy, so let's create a VG
# add a number of LVs and then remove the VG and all the contained
# LVs which appears to consistently run a little slow.
@@ -1781,7 +1781,7 @@ class TestDbusService(unittest.TestCase):
self.assertTrue(ec == 0, "%s exit code = %d" % (operation, ec))
def test_external_vg_create(self):
- # We need to ensure that if a user creates something outside of lvm
+ # We need to ensure that if a user creates something outside lvm
# dbus service that things are sequenced correctly so that if a dbus
# user calls into the service they will find the same information.
vg_name = vg_n()
@@ -1794,8 +1794,8 @@ class TestDbusService(unittest.TestCase):
self._verify_existence(cmd, cmd[0], vg_name)
def test_external_lv_create(self):
- # Lets create a LV outside of service and see if we correctly handle
- # it's inclusion
+ # Let's create a LV outside of service and see if we correctly handle
+ # its inclusion
vg = self._vg_create().Vg
lv_name = lv_n()
full_name = "%s/%s" % (vg.Name, lv_name)
@@ -1804,8 +1804,8 @@ class TestDbusService(unittest.TestCase):
self._verify_existence(cmd, cmd[0], full_name)
def test_external_pv_create(self):
- # Lets create a PV outside of service and see if we correctly handle
- # it's inclusion
+ # Let's create a PV outside of service and see if we correctly handle
+ # its inclusion
target = self.objs[PV_INT][0]
# Remove the PV
@@ -1851,7 +1851,7 @@ class TestDbusService(unittest.TestCase):
#
# NOTE: This needs an equivalent of aux extend_filter_LVMTEST
# when run from lvm2 testsuite. See dbustest.sh.
- # Also if developing locally with actual devices one can achieve this
+ # Also, if developing locally with actual devices one can achieve this
# by editing lvm.conf with "devices/scan_lvs = 1" As testing
# typically utilizes loopback, this test is skipped in
# those environments.
@@ -1866,7 +1866,7 @@ class TestDbusService(unittest.TestCase):
pv_object_path = self._create_nested(pv_object_path)
def test_pv_symlinks(self):
- # Lets take one of our test PVs, pvremove it, find a symlink to it
+ # Let's take one of our test PVs, pvremove it, find a symlink to it
# and re-create using the symlink to ensure we return an object
# path to it. Additionally, we will take the symlink and do a lookup
# (Manager.LookUpByLvmId) using it and the original device path to
@@ -1888,7 +1888,7 @@ class TestDbusService(unittest.TestCase):
rc = self._lookup(pv_device_path)
self.assertEqual(rc, '/')
- # Lets locate a symlink for it
+ # Let's locate a symlink for it
devices = glob('/dev/disk/*/*')
rp_pv_device_path = os.path.realpath(pv_device_path)
for d in devices:
@@ -1953,7 +1953,7 @@ class TestDbusService(unittest.TestCase):
raise unittest.SkipTest('vdo not supported')
# Do this twice to ensure we are providing the correct flags to force
- # the operation when if finds an existing vdo signature, which likely
+ # the operation when it finds an existing vdo signature, which likely
# shouldn't exist.
for _ in range(0, 2):
vg, _, _ = self._create_vdo_pool_and_lv()
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=55059e002abb3d858e4c5…
Commit: 55059e002abb3d858e4c53ac0da078ca853ff1f4
Parent: d393436727014b9eddf71009065f65a59ff3837c
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Mon Jun 6 09:58:39 2022 -0500
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Thu Jun 30 10:55:16 2022 -0500
lvmdbustest: Test job remove path when job not complete
---
test/dbus/lvmdbustest.py | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/test/dbus/lvmdbustest.py b/test/dbus/lvmdbustest.py
index d876a1748..e16a484b7 100755
--- a/test/dbus/lvmdbustest.py
+++ b/test/dbus/lvmdbustest.py
@@ -886,8 +886,19 @@ class TestDbusService(unittest.TestCase):
j.Remove()
break
+ else:
+ # Most of the time we will get this exception as expected, but there is
+ # a race condition between checking if it's complete and removing it (we want to try to remove while
+ # it's not complete to raise the exception)
+ # Thus, we can't reliably use self.assertRaises.
+ # We have included it here to test this path in the daemon.
+ try:
+ j.Remove()
+ except dbus.exceptions.DBusException:
+ pass
if j.Wait(1):
+ self.assertTrue(j.Wait(0))
j.update()
self.assertTrue(j.Complete)
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=d393436727014b9eddf71…
Commit: d393436727014b9eddf71009065f65a59ff3837c
Parent: 691494268502ddb20da2a14568984c0fa4f29f50
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Mon Jun 6 09:57:20 2022 -0500
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Thu Jun 30 10:55:16 2022 -0500
lvmdbusd: Correct grammar in lvm shell proxy comments
---
daemons/lvmdbusd/lvm_shell_proxy.py.in | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/daemons/lvmdbusd/lvm_shell_proxy.py.in b/daemons/lvmdbusd/lvm_shell_proxy.py.in
index e106ca36f..fa2415fcf 100644
--- a/daemons/lvmdbusd/lvm_shell_proxy.py.in
+++ b/daemons/lvmdbusd/lvm_shell_proxy.py.in
@@ -123,7 +123,7 @@ class LVMShellProxy(object):
tmp_file = "%s/lvmdbus_report" % (tmp_dir)
try:
- # Lets create fifo for the report output
+ # Let's create a fifo for the report output
os.mkfifo(tmp_file, 0o600)
except FileExistsError:
pass
@@ -162,7 +162,7 @@ class LVMShellProxy(object):
except:
raise
finally:
- # These will get deleted when the FD count goes to zero so we
+ # These will get deleted when the FD count goes to zero, so we
# can be sure to clean up correctly no matter how we finish
os.unlink(tmp_file)
os.rmdir(tmp_dir)
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=691494268502ddb20da2a…
Commit: 691494268502ddb20da2a14568984c0fa4f29f50
Parent: eee89a941eb4e63865356cfe9e513c24cfa8e0f9
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Mon Jun 6 09:56:32 2022 -0500
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Thu Jun 30 10:55:16 2022 -0500
lvmdbusd: Don't require "lvm> " prompt for shell
Depending on how lvm is compiled, it may not present the "lvm> " prompt
when using the lvm shell. Don't require it to be present.
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=2090391
---
daemons/lvmdbusd/lvm_shell_proxy.py.in | 83 ++++++++++++++++++----------------
1 file changed, 43 insertions(+), 40 deletions(-)
diff --git a/daemons/lvmdbusd/lvm_shell_proxy.py.in b/daemons/lvmdbusd/lvm_shell_proxy.py.in
index 1a5051a92..e106ca36f 100644
--- a/daemons/lvmdbusd/lvm_shell_proxy.py.in
+++ b/daemons/lvmdbusd/lvm_shell_proxy.py.in
@@ -19,7 +19,6 @@ import sys
import tempfile
import time
import select
-import copy
try:
import simplejson as json
@@ -31,8 +30,6 @@ from lvmdbusd.cfg import LVM_CMD
from lvmdbusd.utils import log_debug, log_error, add_no_notify, make_non_block,\
read_decoded
-SHELL_PROMPT = "lvm> "
-
def _quote_arg(arg):
if len(shlex.split(arg)) > 1:
@@ -43,10 +40,11 @@ def _quote_arg(arg):
class LVMShellProxy(object):
- # Read until we get prompt back and a result
- # @param: no_output Caller expects no output to report FD
- # Returns stdout, report, stderr (report is JSON!)
- def _read_until_prompt(self, no_output=False):
+ # Read REPORT FD until we have a complete and valid JSON record or give
+ # up trying to get one.
+ #
+ # Returns stdout, report (JSON), stderr
+ def _read_response(self):
stdout = ""
report = ""
stderr = ""
@@ -58,6 +56,7 @@ class LVMShellProxy(object):
# Try reading from all FDs to prevent one from filling up and causing
# a hang. Keep reading until we get the prompt back and the report
# FD does not contain valid JSON
+
while keep_reading:
try:
rd_fd = [
@@ -78,32 +77,33 @@ class LVMShellProxy(object):
if self.lvm_shell.poll() is not None:
raise Exception(self.lvm_shell.returncode, "%s" % stderr)
- if stdout.endswith(SHELL_PROMPT):
- if no_output:
- keep_reading = False
- else:
- cur_report_len = len(report)
- if cur_report_len != 0:
- # Only bother to parse if we have more data
- if prev_report_len != cur_report_len:
- prev_report_len = cur_report_len
- # Parse the JSON if it's good we are done,
- # if not we will try to read some more.
- try:
- report_json = json.loads(report)
- keep_reading = False
- except ValueError:
- pass
-
- if keep_reading:
- extra_passes -= 1
- if extra_passes <= 0:
- if len(report):
- raise ValueError("Invalid json: %s" %
- report)
- else:
- raise ValueError(
- "lvm returned no JSON output!")
+ cur_report_len = len(report)
+ if cur_report_len != 0:
+ # Only bother to parse if we have more data and the last 2 characters match expected
+ # complete JSON, prevents excessive JSON parsing attempts
+ if prev_report_len != cur_report_len and report[-2:] == "}\n":
+ prev_report_len = cur_report_len
+
+ # Parse the JSON if it's good we are done,
+ # if not we will try to read some more.
+ try:
+ report_json = json.loads(report)
+ keep_reading = False
+ except ValueError:
+ pass
+
+ # As long as lvm is spewing something on one of the FDs we will
+ # keep trying. If we get a few timeouts with no activity, and
+ # we don't have valid JSON, we will raise an error.
+ if len(ready) == 0 and keep_reading:
+ extra_passes -= 1
+ if extra_passes <= 0:
+ if len(report):
+ raise ValueError("Invalid json: %s" %
+ report)
+ else:
+ raise ValueError(
+ "lvm returned no JSON output!")
except IOError as ioe:
log_debug(str(ioe))
@@ -118,7 +118,6 @@ class LVMShellProxy(object):
self.lvm_shell.stdin.flush()
def __init__(self):
-
# Create a temp directory
tmp_dir = tempfile.mkdtemp(prefix="lvmdbus_")
tmp_file = "%s/lvmdbus_report" % (tmp_dir)
@@ -139,6 +138,11 @@ class LVMShellProxy(object):
local_env = {"LC_ALL": "C", "LVM_REPORT_FD": "%s" % lvm_fd, "LVM_COMMAND_PROFILE": "lvmdbusd",
"LVM_LOG_FILE_MAX_LINES": "0"}
+ # If any env variables contain LVM we will propagate them too
+ for k, v in os.environ.items():
+ if "LVM" in k:
+ local_env[k] = v
+
# run the lvm shell
self.lvm_shell = subprocess.Popen(
[LVM_CMD],
@@ -152,10 +156,9 @@ class LVMShellProxy(object):
# Close our copy of the lvm_fd, child process is open in its process space
os.close(lvm_fd)
- # wait for the first prompt
- errors = self._read_until_prompt(no_output=True)[2]
- if errors and len(errors):
- raise RuntimeError(errors)
+ # Assume we are ready as we may not get the lvm prompt message depending on
+ # if we are using readline or editline.
+
except:
raise
finally:
@@ -169,7 +172,7 @@ class LVMShellProxy(object):
self._write_cmd('lastlog\n')
# read everything from the STDOUT to the next prompt
- stdout, report_json, stderr = self._read_until_prompt()
+ stdout, report_json, stderr = self._read_response()
if 'log' in report_json:
error_msg = ""
# Walk the entire log array and build an error string
@@ -203,7 +206,7 @@ class LVMShellProxy(object):
self._write_cmd(cmd)
# read everything from the STDOUT to the next prompt
- stdout, report_json, stderr = self._read_until_prompt()
+ stdout, report_json, stderr = self._read_response()
# Parse the report to see what happened
if 'log' in report_json:
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=eee89a941eb4e63865356…
Commit: eee89a941eb4e63865356cfe9e513c24cfa8e0f9
Parent: 7a2090655d3ab5abde83b981594ed527e2a7f1f7
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Mon Jun 6 09:51:54 2022 -0500
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Thu Jun 30 10:55:16 2022 -0500
lvmdbusd: Job prop. Get/GetAll exec. immediately
This allows API user the ability to check on the status of a long running
job without blocking in the request queue.
---
daemons/lvmdbusd/job.py | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/daemons/lvmdbusd/job.py b/daemons/lvmdbusd/job.py
index 988b1147a..7629cafc7 100644
--- a/daemons/lvmdbusd/job.py
+++ b/daemons/lvmdbusd/job.py
@@ -226,3 +226,21 @@ class Job(AutomatedProperties):
def Uuid(self):
import uuid
return uuid.uuid1()
+
+ # Override the property "getters" implementation for the job interface, so a user can query a job while the queue
+ # is processing items. Originally all the property get methods were this way, but we changed this in
+ # e53454d6de07de56736303dd2157c3859f6fa848
+
+ # Properties
+ # noinspection PyUnusedLocal
+ @dbus.service.method(dbus_interface=dbus.PROPERTIES_IFACE,
+ in_signature='ss', out_signature='v')
+ def Get(self, interface_name, property_name):
+ # Note: If we get an exception in this handler we won't know about it,
+ # only the side effect of no returned value!
+ return AutomatedProperties._get_prop(self, interface_name, property_name)
+
+ @dbus.service.method(dbus_interface=dbus.PROPERTIES_IFACE,
+ in_signature='s', out_signature='a{sv}')
+ def GetAll(self, interface_name):
+ return AutomatedProperties._get_all_prop(self, interface_name)
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=7a2090655d3ab5abde83b…
Commit: 7a2090655d3ab5abde83b981594ed527e2a7f1f7
Parent: b3d7aff6a3a8fd55790f61b9b0b33d599841030b
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Thu May 26 10:44:02 2022 -0500
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Thu Jun 30 10:55:16 2022 -0500
lvmdbusd: Remove the use of sub shell for lvm shell
This reduces the number of processes and improves security.
---
daemons/lvmdbusd/lvm_shell_proxy.py.in | 24 +++++++++++-------------
1 file changed, 11 insertions(+), 13 deletions(-)
diff --git a/daemons/lvmdbusd/lvm_shell_proxy.py.in b/daemons/lvmdbusd/lvm_shell_proxy.py.in
index 40639442c..1a5051a92 100644
--- a/daemons/lvmdbusd/lvm_shell_proxy.py.in
+++ b/daemons/lvmdbusd/lvm_shell_proxy.py.in
@@ -129,31 +129,29 @@ class LVMShellProxy(object):
except FileExistsError:
pass
- # We have to open non-blocking as the other side isn't open until
- # we actually fork the process.
+ # Open the fifo for use to read and for lvm child process to write to.
self.report_fd = os.open(tmp_file, os.O_NONBLOCK)
self.report_stream = os.fdopen(self.report_fd, 'rb', 0)
+ lvm_fd = os.open(tmp_file, os.O_WRONLY)
- # Setup the environment for using our own socket for reporting
- local_env = {}
- local_env["LC_ALL"] = "C"
- local_env["LVM_REPORT_FD"] = "32"
- local_env["LVM_COMMAND_PROFILE"] = "lvmdbusd"
-
- # Disable the abort logic if lvm logs too much, which easily happens
- # when utilizing the lvm shell.
- local_env["LVM_LOG_FILE_MAX_LINES"] = "0"
+ # Set up the environment for using our own socket for reporting and disable the abort
+ # logic if lvm logs too much, which easily happens when utilizing the lvm shell.
+ local_env = {"LC_ALL": "C", "LVM_REPORT_FD": "%s" % lvm_fd, "LVM_COMMAND_PROFILE": "lvmdbusd",
+ "LVM_LOG_FILE_MAX_LINES": "0"}
# run the lvm shell
self.lvm_shell = subprocess.Popen(
- [LVM_CMD + " 32>%s" % tmp_file],
+ [LVM_CMD],
stdin=subprocess.PIPE, stdout=subprocess.PIPE, env=local_env,
- stderr=subprocess.PIPE, close_fds=True, shell=True)
+ stderr=subprocess.PIPE, close_fds=True, pass_fds=(lvm_fd,), shell=False)
try:
make_non_block(self.lvm_shell.stdout)
make_non_block(self.lvm_shell.stderr)
+ # Close our copy of the lvm_fd, child process is open in its process space
+ os.close(lvm_fd)
+
# wait for the first prompt
errors = self._read_until_prompt(no_output=True)[2]
if errors and len(errors):