qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: Marcel Apfelbaum <marcel.apfelbaum@gmail.com>,
	Eduardo Habkost <ehabkost@redhat.com>,
	Gerd Hoffmann <kraxel@redhat.com>, Bandan Das <bsd@redhat.com>
Subject: [Qemu-devel] [PULL 8/8] usb-mtp: replace the homebrew write with qemu_write_full
Date: Wed, 30 Jan 2019 08:34:26 +0100	[thread overview]
Message-ID: <20190130073426.11525-9-kraxel@redhat.com> (raw)
In-Reply-To: <20190130073426.11525-1-kraxel@redhat.com>

From: Bandan Das <bsd@redhat.com>

qemu_write_full takes care of partial blocking writes,
as in cases of larger file sizes

Suggested-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Bandan Das <bsd@redhat.com>
Message-id: 20190129131908.27924-4-bsd@redhat.com
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/usb/dev-mtp.c | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)

diff --git a/hw/usb/dev-mtp.c b/hw/usb/dev-mtp.c
index 2ca25c9da5..f1d20fa1b9 100644
--- a/hw/usb/dev-mtp.c
+++ b/hw/usb/dev-mtp.c
@@ -1632,24 +1632,16 @@ static char *utf16_to_str(uint8_t len, uint16_t *arr)
 /* Wrapper around write, returns 0 on failure */
 static uint64_t write_retry(int fd, void *buf, uint64_t size, off_t offset)
 {
-        uint64_t bytes_left = size, ret;
+        uint64_t ret = 0;
 
         if (lseek(fd, offset, SEEK_SET) < 0) {
             goto done;
         }
 
-        while (bytes_left > 0) {
-                ret = write(fd, buf, bytes_left);
-                if ((ret == -1) && (errno != EINTR || errno != EAGAIN ||
-                                    errno != EWOULDBLOCK)) {
-                        break;
-                }
-                bytes_left -= ret;
-                buf += ret;
-        }
+        ret = qemu_write_full(fd, buf, size);
 
 done:
-        return size - bytes_left;
+        return ret;
 }
 
 static void usb_mtp_update_object(MTPObject *parent, char *name)
-- 
2.9.3

  parent reply	other threads:[~2019-01-30  7:34 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-30  7:34 [Qemu-devel] [PULL 0/8] Usb 20190130 patches Gerd Hoffmann
2019-01-30  7:34 ` [Qemu-devel] [PULL 1/8] usb: assign unique serial numbers to hid devices Gerd Hoffmann
2019-05-17 16:54   ` Dr. David Alan Gilbert
2019-01-30  7:34 ` [Qemu-devel] [PULL 2/8] usb: dev-mtp: close fd in usb_mtp_object_readdir() Gerd Hoffmann
2019-01-30  7:34 ` [Qemu-devel] [PULL 3/8] hw/usb: Fix LGPL information in the file headers Gerd Hoffmann
2019-01-30  7:34 ` [Qemu-devel] [PULL 4/8] usb: XHCI shall not halt isochronous endpoints Gerd Hoffmann
2019-01-30  7:34 ` [Qemu-devel] [PULL 5/8] usb: implement XHCI underrun/overrun events Gerd Hoffmann
2019-01-30  7:34 ` [Qemu-devel] [PULL 6/8] usb-mtp: Reallocate buffer in multiples of MTP_WRITE_BUF_SZ Gerd Hoffmann
2019-01-30  7:34 ` [Qemu-devel] [PULL 7/8] usb-mtp: breakup MTP write into smaller chunks Gerd Hoffmann
2019-02-14 18:52   ` Peter Maydell
2019-02-15 18:45     ` Bandan Das
2019-02-15 18:55       ` Peter Maydell
2019-02-15 19:22         ` Bandan Das
2019-01-30  7:34 ` Gerd Hoffmann [this message]
2019-01-31 15:40 ` [Qemu-devel] [PULL 0/8] Usb 20190130 patches Peter Maydell
2019-01-31 18:10 ` no-reply
2019-02-02 21:26 ` no-reply

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=20190130073426.11525-9-kraxel@redhat.com \
    --to=kraxel@redhat.com \
    --cc=bsd@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=marcel.apfelbaum@gmail.com \
    --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).