aboutsummaryrefslogtreecommitdiff
path: root/block
diff options
context:
space:
mode:
Diffstat (limited to 'block')
-rw-r--r--block/nbd.c68
-rw-r--r--block/qcow2-cluster.c16
-rw-r--r--block/raw-posix.c13
-rw-r--r--block/sheepdog.c10
-rw-r--r--block/vvfat.c2
5 files changed, 70 insertions, 39 deletions
diff --git a/block/nbd.c b/block/nbd.c
index a1ec123..5e9d6cb 100644
--- a/block/nbd.c
+++ b/block/nbd.c
@@ -33,6 +33,8 @@
#include <sys/types.h>
#include <unistd.h>
+#define EN_OPTSTR ":exportname="
+
typedef struct BDRVNBDState {
int sock;
off_t size;
@@ -42,55 +44,83 @@ typedef struct BDRVNBDState {
static int nbd_open(BlockDriverState *bs, const char* filename, int flags)
{
BDRVNBDState *s = bs->opaque;
+ uint32_t nbdflags;
+
+ char *file;
+ char *name;
const char *host;
const char *unixpath;
int sock;
off_t size;
size_t blocksize;
int ret;
+ int err = -EINVAL;
+
+ file = qemu_strdup(filename);
- if (!strstart(filename, "nbd:", &host))
- return -EINVAL;
+ name = strstr(file, EN_OPTSTR);
+ if (name) {
+ if (name[strlen(EN_OPTSTR)] == 0) {
+ goto out;
+ }
+ name[0] = 0;
+ name += strlen(EN_OPTSTR);
+ }
+
+ if (!strstart(file, "nbd:", &host)) {
+ goto out;
+ }
if (strstart(host, "unix:", &unixpath)) {
- if (unixpath[0] != '/')
- return -EINVAL;
+ if (unixpath[0] != '/') {
+ goto out;
+ }
sock = unix_socket_outgoing(unixpath);
} else {
- uint16_t port;
+ uint16_t port = NBD_DEFAULT_PORT;
char *p, *r;
char hostname[128];
pstrcpy(hostname, 128, host);
p = strchr(hostname, ':');
- if (p == NULL)
- return -EINVAL;
+ if (p != NULL) {
+ *p = '\0';
+ p++;
+
+ port = strtol(p, &r, 0);
+ if (r == p) {
+ goto out;
+ }
+ } else if (name == NULL) {
+ goto out;
+ }
- *p = '\0';
- p++;
-
- port = strtol(p, &r, 0);
- if (r == p)
- return -EINVAL;
sock = tcp_socket_outgoing(hostname, port);
}
- if (sock == -1)
- return -errno;
+ if (sock == -1) {
+ err = -errno;
+ goto out;
+ }
- ret = nbd_receive_negotiate(sock, &size, &blocksize);
- if (ret == -1)
- return -errno;
+ ret = nbd_receive_negotiate(sock, name, &nbdflags, &size, &blocksize);
+ if (ret == -1) {
+ err = -errno;
+ goto out;
+ }
s->sock = sock;
s->size = size;
s->blocksize = blocksize;
+ err = 0;
- return 0;
+out:
+ qemu_free(file);
+ return err;
}
static int nbd_read(BlockDriverState *bs, int64_t sector_num,
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
index 166922f..f562b16 100644
--- a/block/qcow2-cluster.c
+++ b/block/qcow2-cluster.c
@@ -655,7 +655,7 @@ static int write_l2_entries(BlockDriverState *bs, uint64_t *l2_table,
int ret;
BLKDBG_EVENT(bs->file, BLKDBG_L2_UPDATE);
- ret = bdrv_pwrite_sync(bs->file, l2_offset + start_offset,
+ ret = bdrv_pwrite(bs->file, l2_offset + start_offset,
&l2_table[l2_start_index], len);
if (ret < 0) {
return ret;
@@ -718,9 +718,17 @@ int qcow2_alloc_cluster_link_l2(BlockDriverState *bs, QCowL2Meta *m)
goto err;
}
- for (i = 0; i < j; i++)
- qcow2_free_any_clusters(bs,
- be64_to_cpu(old_cluster[i]) & ~QCOW_OFLAG_COPIED, 1);
+ /*
+ * If this was a COW, we need to decrease the refcount of the old cluster.
+ * Also flush bs->file to get the right order for L2 and refcount update.
+ */
+ if (j != 0) {
+ bdrv_flush(bs->file);
+ for (i = 0; i < j; i++) {
+ qcow2_free_any_clusters(bs,
+ be64_to_cpu(old_cluster[i]) & ~QCOW_OFLAG_COPIED, 1);
+ }
+ }
ret = 0;
err:
diff --git a/block/raw-posix.c b/block/raw-posix.c
index 72fb8ce..813372a 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -48,6 +48,7 @@
#endif
#ifdef __linux__
#include <sys/ioctl.h>
+#include <sys/param.h>
#include <linux/cdrom.h>
#include <linux/fd.h>
#endif
@@ -868,8 +869,13 @@ static int hdev_open(BlockDriverState *bs, const char *filename, int flags)
s->type = FTYPE_FILE;
#if defined(__linux__)
- if (strstart(filename, "/dev/sg", NULL)) {
- bs->sg = 1;
+ {
+ char resolved_path[ MAXPATHLEN ], *temp;
+
+ temp = realpath(filename, resolved_path);
+ if (temp && strstart(temp, "/dev/sg", NULL)) {
+ bs->sg = 1;
+ }
}
#endif
@@ -1154,9 +1160,6 @@ static int cdrom_probe_device(const char *filename)
int fd, ret;
int prio = 0;
- if (strstart(filename, "/dev/cd", NULL))
- prio = 50;
-
fd = open(filename, O_RDONLY | O_NONBLOCK);
if (fd < 0) {
goto out;
diff --git a/block/sheepdog.c b/block/sheepdog.c
index 81aa564..e62820a 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -8,16 +8,6 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifdef _WIN32
-#include <windows.h>
-#include <winsock2.h>
-#include <ws2tcpip.h>
-#else
-#include <netdb.h>
-#include <netinet/tcp.h>
-
-#define closesocket(s) close(s)
-#endif
#include "qemu-common.h"
#include "qemu-error.h"
diff --git a/block/vvfat.c b/block/vvfat.c
index 6d61c2e..365332a 100644
--- a/block/vvfat.c
+++ b/block/vvfat.c
@@ -512,7 +512,7 @@ static inline uint8_t fat_chksum(const direntry_t* entry)
for(i=0;i<11;i++) {
unsigned char c;
- c = (i <= 8) ? entry->name[i] : entry->extension[i-8];
+ c = (i < 8) ? entry->name[i] : entry->extension[i-8];
chksum=(((chksum&0xfe)>>1)|((chksum&0x01)?0x80:0)) + c;
}