qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v4 1/3] Update ioctl order in nbd_init() to detect EBUSY
@ 2011-12-02 15:27 Chunyan Liu
  2011-12-02 15:27 ` [Qemu-devel] [PATCH v4 2/3] Extract code to nbd_setup function to be used for many purposes Chunyan Liu
  2011-12-02 15:27 ` [Qemu-devel] [PATCH v4 3/3] Add -f option to qemu-nbd Chunyan Liu
  0 siblings, 2 replies; 16+ messages in thread
From: Chunyan Liu @ 2011-12-02 15:27 UTC (permalink / raw)
  To: stefanha; +Cc: qemu-devel

Update ioctl(s) in nbd_init() to detect device busy early.

Current nbd_init() issues NBD_CLEAR_SOCKET before NBD_SET_SOCKET, if issuing
"qemu-nbd -c /dev/nbd0 disk.img" twice, the second time won't detect EBUSY in
nbd_init(), but in nbd_client will report EBUSY and do clear socket (the 1st
time command will be affacted too because of no socket any more.)

No change to previous version.

Signed-off-by: Chunyan Liu <cyliu@suse.com>
---
 nbd.c |   27 +++++++++------------------
 1 files changed, 9 insertions(+), 18 deletions(-)

diff --git a/nbd.c b/nbd.c
index e6c931c..4184614 100644
--- a/nbd.c
+++ b/nbd.c
@@ -348,6 +348,15 @@ int nbd_receive_negotiate(int csock, const char *name, uint32_t *flags,
 #ifdef __linux__
 int nbd_init(int fd, int csock, uint32_t flags, off_t size, size_t blocksize)
 {
+    TRACE("Setting NBD socket");
+
+    if (ioctl(fd, NBD_SET_SOCK, csock) == -1) {
+        int serrno = errno;
+        LOG("Failed to set NBD socket");
+        errno = serrno;
+        return -1;
+    }
+
     TRACE("Setting block size to %lu", (unsigned long)blocksize);
 
     if (ioctl(fd, NBD_SET_BLKSIZE, blocksize) == -1) {
@@ -386,24 +395,6 @@ int nbd_init(int fd, int csock, uint32_t flags, off_t size, size_t blocksize)
         return -1;
     }
 
-    TRACE("Clearing NBD socket");
-
-    if (ioctl(fd, NBD_CLEAR_SOCK) == -1) {
-        int serrno = errno;
-        LOG("Failed clearing NBD socket");
-        errno = serrno;
-        return -1;
-    }
-
-    TRACE("Setting NBD socket");
-
-    if (ioctl(fd, NBD_SET_SOCK, csock) == -1) {
-        int serrno = errno;
-        LOG("Failed to set NBD socket");
-        errno = serrno;
-        return -1;
-    }
-
     TRACE("Negotiation ended");
 
     return 0;
-- 
1.7.3.4

^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2011-12-09  9:36 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-12-02 15:27 [Qemu-devel] [PATCH v4 1/3] Update ioctl order in nbd_init() to detect EBUSY Chunyan Liu
2011-12-02 15:27 ` [Qemu-devel] [PATCH v4 2/3] Extract code to nbd_setup function to be used for many purposes Chunyan Liu
2011-12-02 16:32   ` Paolo Bonzini
2011-12-05  5:46     ` Chunyan Liu
2011-12-05 13:16       ` Stefan Hajnoczi
2011-12-06  6:56         ` Chunyan Liu
2011-12-06  7:59           ` Paolo Bonzini
2011-12-06  8:42             ` Chunyan Liu
2011-12-06  8:44               ` Paolo Bonzini
2011-12-06  9:01                 ` Chunyan Liu
2011-12-07  4:23                   ` Chunyan Liu
2011-12-07  9:44                     ` Paolo Bonzini
2011-12-08 11:55                     ` Stefan Hajnoczi
2011-12-09  8:31                       ` Chunyan Liu
2011-12-09  9:36                         ` Stefan Hajnoczi
2011-12-02 15:27 ` [Qemu-devel] [PATCH v4 3/3] Add -f option to qemu-nbd Chunyan Liu

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).