qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, mreitz@redhat.com, eblake@redhat.com,
	pkrempa@redhat.com, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 6/8] file-posix: Lock new fd in raw_reopen_prepare()
Date: Fri,  8 Mar 2019 16:37:55 +0100	[thread overview]
Message-ID: <20190308153757.25794-7-kwolf@redhat.com> (raw)
In-Reply-To: <20190308153757.25794-1-kwolf@redhat.com>

There is no reason why we can take locks on the new file descriptor only
in raw_reopen_commit() where error handling isn't possible any more.
Instead, we can already do this in raw_reopen_prepare().

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 block/file-posix.c | 27 ++++++++++++++++-----------
 1 file changed, 16 insertions(+), 11 deletions(-)

diff --git a/block/file-posix.c b/block/file-posix.c
index 6aaee1df16..932cc8e58c 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -906,7 +906,7 @@ static int raw_reopen_prepare(BDRVReopenState *state,
     BDRVRawState *s;
     BDRVRawReopenState *rs;
     QemuOpts *opts;
-    int ret = 0;
+    int ret;
     Error *local_err = NULL;
 
     assert(state != NULL);
@@ -947,14 +947,27 @@ static int raw_reopen_prepare(BDRVReopenState *state,
     if (rs->fd != -1) {
         raw_probe_alignment(state->bs, rs->fd, &local_err);
         if (local_err) {
-            qemu_close(rs->fd);
-            rs->fd = -1;
             error_propagate(errp, local_err);
             ret = -EINVAL;
+            goto out_fd;
+        }
+
+        /* Copy locks to the new fd */
+        ret = raw_apply_lock_bytes(NULL, rs->fd, s->locked_perm,
+                                   s->locked_shared_perm, false, errp);
+        if (ret < 0) {
+            ret = -EINVAL;
+            goto out_fd;
         }
     }
 
     s->reopen_state = state;
+    ret = 0;
+out_fd:
+    if (ret < 0) {
+        qemu_close(rs->fd);
+        rs->fd = -1;
+    }
 out:
     qemu_opts_del(opts);
     return ret;
@@ -964,18 +977,10 @@ static void raw_reopen_commit(BDRVReopenState *state)
 {
     BDRVRawReopenState *rs = state->opaque;
     BDRVRawState *s = state->bs->opaque;
-    Error *local_err = NULL;
 
     s->check_cache_dropped = rs->check_cache_dropped;
     s->open_flags = rs->open_flags;
 
-    /* Copy locks to the new fd before closing the old one. */
-    raw_apply_lock_bytes(NULL, rs->fd, s->locked_perm,
-                         s->locked_shared_perm, false, &local_err);
-    if (local_err) {
-        /* shouldn't fail in a sane host, but report it just in case. */
-        error_report_err(local_err);
-    }
     qemu_close(s->fd);
     s->fd = rs->fd;
 
-- 
2.20.1

  parent reply	other threads:[~2019-03-08 15:38 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-08 15:37 [Qemu-devel] [PATCH 0/8] file-posix: Make auto-read-only dynamic Kevin Wolf
2019-03-08 15:37 ` [Qemu-devel] [PATCH 1/8] tests/virtio-blk-test: Disable auto-read-only Kevin Wolf
2019-03-12  2:46   ` Eric Blake
2019-03-08 15:37 ` [Qemu-devel] [PATCH 2/8] block: Avoid useless local_err Kevin Wolf
2019-03-11 10:16   ` [Qemu-devel] [Qemu-block] " Alberto Garcia
2019-03-08 15:37 ` [Qemu-devel] [PATCH 3/8] block: Make permission changes in reopen less wrong Kevin Wolf
2019-03-08 15:37 ` [Qemu-devel] [PATCH 4/8] file-posix: Factor out raw_reconfigure_getfd() Kevin Wolf
2019-03-08 15:37 ` [Qemu-devel] [PATCH 5/8] file-posix: Store BDRVRawState.reopen_state during reopen Kevin Wolf
2019-03-08 15:37 ` Kevin Wolf [this message]
2019-03-08 15:37 ` [Qemu-devel] [PATCH 7/8] file-posix: Prepare permission code for fd switching Kevin Wolf
2019-03-08 15:37 ` [Qemu-devel] [PATCH 8/8] file-posix: Make auto-read-only dynamic Kevin Wolf
2019-03-11 13:09 ` [Qemu-devel] [PATCH 0/8] " Peter Krempa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190308153757.25794-7-kwolf@redhat.com \
    --to=kwolf@redhat.com \
    --cc=eblake@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=pkrempa@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).