block: report errno when flock fcntl fails
v2 cover block: report errno when flock fcntl fails
As Kevin pointed out, adding the error reported by fcntl to the reported error required updates to the tests.
When running the tests there were lots of failures due to output comparison problems, such as:
@@ -6,7 +6,9 @@
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=SIZE
{ 'execute': 'qmp_capabilities' }
{"return": {}}
-{'execute':'drive-mirror', 'arguments':{ 'device': 'src', 'target': 'TEST_DIR/t.IMGFMT', 'mode': 'existing', 'sync': 'full'}} +{'execute':'drive-mirror', 'arguments':{
+ 'device': 'src', 'target': 'TEST_DIR/t.IMGFMT',
+ 'mode': 'existing', 'sync': 'full'}}
WARNING: Image format was not specified for 'TEST_DIR/t.raw' and probing guessed raw.
Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted. Specify the 'raw' format explicitly to remove the restrictions.
To avoid this, the second patch flattens the input command that will be sent to the tool before it is echoed back for later comparison.
v2:
- Update the tests appropriately (Kevin).
- Removed qemu-trivial given that there was debate.
- Filter the input echoed before sending to qemu* during testing such that comparisons succeed.
David Edmondson (2):
block: report errno when flock fcntl fails
tests: Collapse echoed JSON input to a single line
block/file-posix.c | 20 ++++----- tests/qemu-iotests/153.out | 76 ++++++++++++++++---------------- tests/qemu-iotests/182.out | 2 +- tests/qemu-iotests/common.filter | 6 +++ tests/qemu-iotests/common.qemu | 2 +- 5 files changed, 56 insertions(+), 50 deletions(-)
Signature · 1 line
2.29.2
PATCH v2 1/2 block: report errno when flock fcntl fails
When a call to fcntl(2) for the purpose of manipulating file locks fails, report the error returned by fcntl.
--- block/file-posix.c | 20 +++++----- tests/qemu-iotests/153.out | 76 +++++++++++++++++++------------------- tests/qemu-iotests/182.out | 2 +- 3 files changed, 49 insertions(+), 49 deletions(-)
block/file-posix.c +10 -10
@@ -836,7 +836,7 @@ static int raw_apply_lock_bytes(BDRVRawState *s, int fd,if ((perm_lock_bits & bit) && !(locked_perm & bit)) { ret =qemu_lock_fd (fd, off,1 , false);if (ret) { -error_setg (errp,"Failed to lock byte %d" , off); +error_setg_errno (errp, -ret,"Failed to lock byte %d" , off);return ret; }else if (s) { s->locked_perm |= bit;
@@ -844,7 +844,7 @@ static int raw_apply_lock_bytes(BDRVRawState *s, int fd, }else if (unlock && (locked_perm & bit) && !(perm_lock_bits & bit)) { ret =qemu_unlock_fd (fd, off,1 );if (ret) { -error_setg (errp,"Failed to unlock byte %d" , off); +error_setg_errno (errp, -ret,"Failed to unlock byte %d" , off);return ret; }else if (s) { s->locked_perm &= ~bit;
@@ -857,7 +857,7 @@ static int raw_apply_lock_bytes(BDRVRawState *s, int fd,if ((shared_perm_lock_bits & bit) && !(locked_shared_perm & bit)) { ret =qemu_lock_fd (fd, off,1 , false);if (ret) { -error_setg (errp,"Failed to lock byte %d" , off); +error_setg_errno (errp, -ret,"Failed to lock byte %d" , off);return ret; }else if (s) { s->locked_shared_perm |= bit;
@@ -866,7 +866,7 @@ static int raw_apply_lock_bytes(BDRVRawState *s, int fd, !(shared_perm_lock_bits & bit)) { ret =qemu_unlock_fd (fd, off,1 );if (ret) { -error_setg (errp,"Failed to unlock byte %d" , off); +error_setg_errno (errp, -ret,"Failed to unlock byte %d" , off);return ret; }else if (s) { s->locked_shared_perm &= ~bit;
@@ -890,9 +890,9 @@ static int raw_check_lock_bytes(int fd, uint64_t perm, uint64_t shared_perm, ret =qemu_lock_fd_test (fd, off,1 , true);if (ret) {char *perm_name =bdrv_perm_names (p); -error_setg (errp, -"Failed to get \"%s\" lock" , - perm_name); +error_setg_errno (errp, -ret, +"Failed to get \"%s\" lock" , + perm_name);g_free (perm_name);return ret; }
@@ -905,9 +905,9 @@ static int raw_check_lock_bytes(int fd, uint64_t perm, uint64_t shared_perm, ret =qemu_lock_fd_test (fd, off,1 , true);if (ret) {char *perm_name =bdrv_perm_names (p); -error_setg (errp, -"Failed to get shared \"%s\" lock" , - perm_name); +error_setg_errno (errp, -ret, +"Failed to get shared \"%s\" lock" , + perm_name);g_free (perm_name);return ret; }
tests/qemu-iotests/153.out +38 -38
234 lines not on this page · raw message
tests/qemu-iotests/182.out +1 -1
@@ -3,7 +3,7 @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=33554432 Starting QEMU Starting a second QEMU using the same image should fail -QEMU_PROG: -drive file=TEST_DIR/t.qcow2,if=none,id=drive0,file.locking=on: Failed to get "write" lock +QEMU_PROG: -drive file=TEST_DIR/t.qcow2,if=none,id=drive0,file.locking=on: Failed to get "write" lock: Resource temporarily unavailable Is another process using the image [TEST_DIR/t.qcow2]? === Testing reopen ===
Signature · 1 line
2.29.2
Quoted 9 lines · David Edmondson
When a call to fcntl(2) for the purpose of manipulating file locks fails, report the error returned by fcntl.
Signed-off-by David Edmondson <[email protected]>--- block/file-posix.c | 20 +++++----- tests/qemu-iotests/153.out | 76 +++++++++++++++++++------------------- tests/qemu-iotests/182.out | 2 +- 3 files changed, 49 insertions(+), 49 deletions(-)
Quoted 9 lines · David Edmondson
When a call to fcntl(2) for the purpose of manipulating file locks fails, report the error returned by fcntl.
Signed-off-by David Edmondson <[email protected]>--- block/file-posix.c | 20 +++++----- tests/qemu-iotests/153.out | 76 +++++++++++++++++++------------------- tests/qemu-iotests/182.out | 2 +- 3 files changed, 49 insertions(+), 49 deletions(-)
tests/qemu-iotests/296.out also needs to be adjusted (found by grepping for 'Failed to get').
And now I might as well add this idea: EAGAIN is the most common errno when flock fcntl fails, so would it make sense to generate a custom error message then? I’d like to think we could do better than “Resource temporarily unavailable”, e.g. perhaps “Lock is already taken”.
OTOH, “Resource temporarily unavailable” isn’t *that* bad, so if you don’t want to, I won’t push for it.
Max
Quoted 10 lines · Max Reitz
Quoted 8 lines · David Edmondson
When a call to fcntl(2) for the purpose of manipulating file locks fails, report the error returned by fcntl.
Signed-off-by David Edmondson <[email protected]>--- block/file-posix.c | 20 +++++----- tests/qemu-iotests/153.out | 76 +++++++++++++++++++------------------- tests/qemu-iotests/182.out | 2 +- 3 files changed, 49 insertions(+), 49 deletions(-)
Quoted 2 lines
tests/qemu-iotests/296.out also needs to be adjusted (found by grepping for 'Failed to get').
I will check and add it.
Quoted 5 lines
And now I might as well add this idea: EAGAIN is the most common errno when flock fcntl fails, so would it make sense to generate a custom error message then? I’d like to think we could do better than “Resource temporarily unavailable”, e.g. perhaps “Lock is already taken”.
Kevin previously suggested that we should elide the detail in this common case (please correct me if that's a misrepresentation), but there didn't seem to be any consensus for that.
Quoted 2 lines
OTOH, “Resource temporarily unavailable” isn’t *that* bad, so if you don’t want to, I won’t push for it.
Other than that it's just more code (which in general is not good), I don't have a strong opinion.
dme.
Signature · 1 line
Facts don't do what I want them to.
PATCH v2 2/2 tests: Collapse echoed JSON input to a single line
In reply to David EdmondsonWhen sending JSON to running qemu, qemu-io, etc. instances, flatten the echoed input to a single line to ensure that comparisons with the expected input (which is always a single line) are successful.
--- tests/qemu-iotests/common.filter | 6 ++++++ tests/qemu-iotests/common.qemu | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-)
tests/qemu-iotests/common.filter +6 -0
@@ -332,5 +332,11 @@ for fname in fnames: sys.stdout.write(result)' } +# Convert multi-line input to a single line. +_filter_collapse_lines() +{ + (tr -d '\n'; echo) +} + # make sure this script returns success true
tests/qemu-iotests/common.qemu +1 -1
@@ -159,7 +159,7 @@ _send_qemu_cmd() # input back to output); decide based on leading '{' if [ -z "$silent" ] && [ -z "$mismatch_only" ] && [ "$cmd" != "${cmd#\{}" ]; then - echo "${cmd}" | _filter_testdir | _filter_imgfmt + echo "${cmd}" | _filter_testdir | _filter_imgfmt | _filter_collapse_lines fi while [ ${count} -gt 0 ] do
Signature · 1 line
2.29.2
Re: [PATCH v2 2/2] tests: Collapse echoed JSON input to a single line
Quoted 9 lines · David Edmondson
When sending JSON to running qemu, qemu-io, etc. instances, flatten the echoed input to a single line to ensure that comparisons with the expected input (which is always a single line) are successful.
Signed-off-by David Edmondson <[email protected]>--- tests/qemu-iotests/common.filter | 6 ++++++ tests/qemu-iotests/common.qemu | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-)
I think this is superseded now by commit 0e72078128229bf9efb54.
Max
Re: [PATCH v2 2/2] tests: Collapse echoed JSON input to a single line
Quoted 11 lines · Max Reitz
Quoted 8 lines · David Edmondson
When sending JSON to running qemu, qemu-io, etc. instances, flatten the echoed input to a single line to ensure that comparisons with the expected input (which is always a single line) are successful.
Signed-off-by David Edmondson <[email protected]>--- tests/qemu-iotests/common.filter | 6 ++++++ tests/qemu-iotests/common.qemu | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-)I think this is superseded now by commit
0e72078128229bf9efb54.
Yes, agreed.
dme.
Signature · 1 line
Here I am, a rabbit-hearted girl.