This is an automated email from the git hooks/post-receive script.
nsoffer pushed a commit to branch master
in repository sanlock.
commit 1c8f054606a24988fdf6417b4d7b578fb482bc9a
Author: Nir Soffer <nsoffer(a)redhat.com>
AuthorDate: Tue May 7 01:05:27 2019 +0300
sanlock: Fail read_resource_owners() with wrong sector size
If sanlock_read_resource_owners() is called with wrong sector size, fail
instead of falling back to actual sector size. This is more consistent
with sanlock_read_resource() and other other functions.
Signed-off-by: Nir Soffer <nsoffer(a)redhat.com>
---
src/resource.c | 22 ++++++++++++++++------
tests/python_test.py | 1 -
2 files changed, 16 insertions(+), 7 deletions(-)
diff --git a/src/resource.c b/src/resource.c
index a783106..21dbe84 100644
--- a/src/resource.c
+++ b/src/resource.c
@@ -169,18 +169,16 @@ int read_resource_owners(struct task *task, struct token *token,
char *lease_buf_dblock;
char *lease_buf = NULL;
char *hosts_buf = NULL;
+ const int sector_size_set = token->sector_size != 0;
int align_size;
int host_count = 0;
int i, rv;
disk = &token->disks[0];
- /*
- * We don't know the sector_size of the resource until the leader
- * record has been read, start with the smaller size.
- */
+ /* If sector size not set, start with the smaller one. */
- if (!token->sector_size) {
+ if (!sector_size_set) {
token->sector_size = 512;
token->align_size = sector_size_to_align_size_old(512);
}
@@ -206,9 +204,21 @@ int read_resource_owners(struct task *task, struct token *token,
if (!align_size)
align_size = sector_size_to_align_size_old(leader.sector_size);
+ /* If caller specified values are incorrect, fail. */
+
+ if (sector_size_set && token->sector_size != leader.sector_size) {
+ log_errot(token, "read_resource_owners invalid sector_size: %d actual: %d",
+ token->sector_size, leader.sector_size);
+ rv = -EINVAL;
+ goto out;
+ }
+
+ /*
+ * If the caller did not specify sector size and our guess was wrong,
+ * retry with the actual value
+ */
if ((token->sector_size != leader.sector_size) ||
(token->align_size != align_size)) {
- /* initial sizes were wrong */
log_debug("read_resource_owners rereading with correct sizses");
token->sector_size = leader.sector_size;
token->align_size = align_size;
diff --git a/tests/python_test.py b/tests/python_test.py
index edb6de7..d70187c 100644
--- a/tests/python_test.py
+++ b/tests/python_test.py
@@ -219,7 +219,6 @@ def test_read_resource_4k_invalid_sector_size(sanlock_daemon,
user_4k_path):
assert e.value.errno == errno.EINVAL
-(a)pytest.mark.xfail(reason="fallback hides wrong value from caller")
def test_read_resource_owners_4k_invalid_sector_size(
sanlock_daemon, user_4k_path):
disks = [(user_4k_path, 0)]
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
Show replies by date