mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-30 13:31:52 -06:00
Update ioctl order in nbd_init() to detect EBUSY
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> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
7a706633e9
commit
3e05c78551
1 changed files with 9 additions and 18 deletions
27
nbd.c
27
nbd.c
|
@ -358,6 +358,15 @@ int nbd_receive_negotiate(int csock, const char *name, uint32_t *flags,
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
int nbd_init(int fd, int csock, uint32_t flags, off_t size, size_t blocksize)
|
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);
|
TRACE("Setting block size to %lu", (unsigned long)blocksize);
|
||||||
|
|
||||||
if (ioctl(fd, NBD_SET_BLKSIZE, blocksize) == -1) {
|
if (ioctl(fd, NBD_SET_BLKSIZE, blocksize) == -1) {
|
||||||
|
@ -396,24 +405,6 @@ int nbd_init(int fd, int csock, uint32_t flags, off_t size, size_t blocksize)
|
||||||
return -1;
|
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");
|
TRACE("Negotiation ended");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue