qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v4 2/2] migration: check magic value for deciding the mapping


From: manish.mishra
Subject: Re: [PATCH v4 2/2] migration: check magic value for deciding the mapping of channels
Date: Wed, 23 Nov 2022 22:03:10 +0530
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.5.0


On 23/11/22 9:57 pm, Peter Xu wrote:
On Wed, Nov 23, 2022 at 09:28:14PM +0530, manish.mishra wrote:
On 23/11/22 9:22 pm, Peter Xu wrote:
On Wed, Nov 23, 2022 at 03:05:27PM +0000, manish.mishra wrote:
+int migration_channel_read_peek(QIOChannel *ioc,
+                                const char *buf,
+                                const size_t buflen,
+                                Error **errp)
+{
+   ssize_t len = 0;
+   struct iovec iov = { .iov_base = (char *)buf, .iov_len = buflen };
+
+   while (len < buflen) {
+       len = qio_channel_readv_full(ioc, &iov, 1, NULL,
+                                    NULL, QIO_CHANNEL_READ_FLAG_MSG_PEEK, 
errp);
+
+       if (len == QIO_CHANNEL_ERR_BLOCK) {
This needs to take care of partial len too?

sorry Peter, I did not quite understand it. Can you please give some more 
details.
As Daniel pointed out, I think if we peek partially it'll go into a loop.
Since we shouldn't read 0 anyway here, maybe you can directly write it as:

while (true) {
   len = read();
   if (len <= 0 && len != QIO_CHANNEL_ERR_BLOCK) {
       error_setg(...);
       return -1;
   }
   if (len == buflen) {
       break;
   }
   /* For either partial peek or QIO_CHANNEL_ERR_BLOCK, retry with timeout */
   sleep();
}


Yes, got it, sorry, will update it.

Thanks

Manish Mishra

+            if (qemu_in_coroutine()) {
+                /* 1ms sleep. */
+                qemu_co_sleep_ns(QEMU_CLOCK_REALTIME, 1000000);
+            } else {
+                qio_channel_wait(ioc, G_IO_IN);
+            }
+            continue;
+       }
+       if (len == 0) {
+           error_setg(errp,
+                      "Unexpected end-of-file on channel");
+           return -1;
+       }
+       if (len < 0) {
+           return -1;
+       }
+   }
+
+   return 0;
+}
Thanks

Manish Mishra




reply via email to

[Prev in Thread] Current Thread [Next in Thread]