Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/kevin/tags/for-upstream' into s…
Browse files Browse the repository at this point in the history
…taging

Block patches

# gpg: Signature made Wed 30 Apr 2014 19:19:32 BST using RSA key ID C88F2FD6
# gpg: Good signature from "Kevin Wolf <kwolf@redhat.com>"

* remotes/kevin/tags/for-upstream: (31 commits)
  curl: Fix hang reading from slow connections
  curl: Ensure all informationals are checked for completion
  curl: Eliminate unnecessary use of curl_multi_socket_all
  curl: Remove unnecessary explicit calls to internal event handler
  curl: Remove erroneous sleep waiting for curl completion
  curl: Fix return from curl_read_cb with invalid state
  curl: Remove unnecessary use of goto
  curl: Fix long line
  block/vdi: Error out immediately in vdi_create()
  block/bochs: Fix error handling for seek_to_sector()
  qcow2: Check min_size in qcow2_grow_l1_table()
  qcow2: Catch bdrv_getlength() error
  block: Use correct width in format strings
  qcow2: Avoid overflow in alloc_clusters_noref()
  block: Use error_abort in bdrv_image_info_specific_dump()
  block: Fix open_flags in bdrv_reopen()
  Revert "block: another bdrv_append fix"
  block: Unlink temporary files in raw-posix/win32
  block: Remove BDRV_O_COPY_ON_READ for bs->file
  block: Create bdrv_backing_flags()
  ...

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
  • Loading branch information
pm215 committed May 2, 2014
2 parents c090c10 + b7079df commit e50bf23
Show file tree
Hide file tree
Showing 24 changed files with 355 additions and 171 deletions.
108 changes: 72 additions & 36 deletions block.c
Expand Up @@ -774,6 +774,45 @@ void bdrv_disable_copy_on_read(BlockDriverState *bs)
bs->copy_on_read--;
}

/*
* Returns the flags that bs->file should get, based on the given flags for
* the parent BDS
*/
static int bdrv_inherited_flags(int flags)
{
/* Enable protocol handling, disable format probing for bs->file */
flags |= BDRV_O_PROTOCOL;

/* Our block drivers take care to send flushes and respect unmap policy,
* so we can enable both unconditionally on lower layers. */
flags |= BDRV_O_CACHE_WB | BDRV_O_UNMAP;

/* The backing file of a temporary snapshot is read-only */
if (flags & BDRV_O_SNAPSHOT) {
flags &= ~BDRV_O_RDWR;
}

/* Clear flags that only apply to the top layer */
flags &= ~(BDRV_O_SNAPSHOT | BDRV_O_NO_BACKING | BDRV_O_COPY_ON_READ);

return flags;
}

/*
* Returns the flags that bs->backing_hd should get, based on the given flags
* for the parent BDS
*/
static int bdrv_backing_flags(int flags)
{
/* backing files always opened read-only */
flags &= ~(BDRV_O_RDWR | BDRV_O_COPY_ON_READ);

/* snapshot=on is handled on the top layer */
flags &= ~(BDRV_O_SNAPSHOT | BDRV_O_TEMPORARY);

return flags;
}

static int bdrv_open_flags(BlockDriverState *bs, int flags)
{
int open_flags = flags | BDRV_O_CACHE_WB;
Expand All @@ -792,7 +831,7 @@ static int bdrv_open_flags(BlockDriverState *bs, int flags)
/*
* Snapshots should be writable.
*/
if (bs->is_temporary) {
if (flags & BDRV_O_TEMPORARY) {
open_flags |= BDRV_O_RDWR;
}

Expand Down Expand Up @@ -951,13 +990,6 @@ static int bdrv_open_common(BlockDriverState *bs, BlockDriverState *file,
bdrv_refresh_limits(bs);
assert(bdrv_opt_mem_align(bs) != 0);
assert((bs->request_alignment != 0) || bs->sg);

#ifndef _WIN32
if (bs->is_temporary) {
assert(bs->filename[0] != '\0');
unlink(bs->filename);
}
#endif
return 0;

free_and_fail:
Expand Down Expand Up @@ -1069,7 +1101,7 @@ static int bdrv_file_open(BlockDriverState *bs, const char *filename,
int bdrv_open_backing_file(BlockDriverState *bs, QDict *options, Error **errp)
{
char *backing_filename = g_malloc0(PATH_MAX);
int back_flags, ret = 0;
int ret = 0;
BlockDriver *back_drv = NULL;
Error *local_err = NULL;

Expand Down Expand Up @@ -1097,14 +1129,10 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict *options, Error **errp)
back_drv = bdrv_find_format(bs->backing_format);
}

/* backing files always opened read-only */
back_flags = bs->open_flags & ~(BDRV_O_RDWR | BDRV_O_SNAPSHOT |
BDRV_O_COPY_ON_READ);

assert(bs->backing_hd == NULL);
ret = bdrv_open(&bs->backing_hd,
*backing_filename ? backing_filename : NULL, NULL, options,
back_flags, back_drv, &local_err);
bdrv_backing_flags(bs->open_flags), back_drv, &local_err);
if (ret < 0) {
bs->backing_hd = NULL;
bs->open_flags |= BDRV_O_NO_BACKING;
Expand Down Expand Up @@ -1232,10 +1260,10 @@ void bdrv_append_temp_snapshot(BlockDriverState *bs, Error **errp)
qstring_from_str(tmp_filename));

bs_snapshot = bdrv_new("", &error_abort);
bs_snapshot->is_temporary = 1;

ret = bdrv_open(&bs_snapshot, NULL, NULL, snapshot_options,
bs->open_flags & ~BDRV_O_SNAPSHOT, bdrv_qcow2, &local_err);
(bs->open_flags & ~BDRV_O_SNAPSHOT) | BDRV_O_TEMPORARY,
bdrv_qcow2, &local_err);
if (ret < 0) {
error_propagate(errp, local_err);
goto out;
Expand Down Expand Up @@ -1333,10 +1361,10 @@ int bdrv_open(BlockDriverState **pbs, const char *filename,

assert(file == NULL);
ret = bdrv_open_image(&file, filename, options, "file",
bdrv_open_flags(bs, flags | BDRV_O_UNMAP) |
BDRV_O_PROTOCOL, true, &local_err);
bdrv_inherited_flags(flags),
true, &local_err);
if (ret < 0) {
goto unlink_and_fail;
goto fail;
}

/* Find the right image format driver */
Expand All @@ -1347,7 +1375,7 @@ int bdrv_open(BlockDriverState **pbs, const char *filename,
if (!drv) {
error_setg(errp, "Invalid driver: '%s'", drvname);
ret = -EINVAL;
goto unlink_and_fail;
goto fail;
}
}

Expand All @@ -1357,18 +1385,18 @@ int bdrv_open(BlockDriverState **pbs, const char *filename,
} else {
error_setg(errp, "Must specify either driver or file");
ret = -EINVAL;
goto unlink_and_fail;
goto fail;
}
}

if (!drv) {
goto unlink_and_fail;
goto fail;
}

/* Open the image */
ret = bdrv_open_common(bs, file, options, flags, drv, &local_err);
if (ret < 0) {
goto unlink_and_fail;
goto fail;
}

if (file && (bs->file != file)) {
Expand Down Expand Up @@ -1430,14 +1458,10 @@ int bdrv_open(BlockDriverState **pbs, const char *filename,
*pbs = bs;
return 0;

unlink_and_fail:
fail:
if (file != NULL) {
bdrv_unref(file);
}
if (bs->is_temporary) {
unlink(filename);
}
fail:
QDECREF(bs->options);
QDECREF(options);
bs->options = NULL;
Expand Down Expand Up @@ -1501,8 +1525,11 @@ BlockReopenQueue *bdrv_reopen_queue(BlockReopenQueue *bs_queue,
QSIMPLEQ_INIT(bs_queue);
}

/* bdrv_open() masks this flag out */
flags &= ~BDRV_O_PROTOCOL;

if (bs->file) {
bdrv_reopen_queue(bs_queue, bs->file, flags);
bdrv_reopen_queue(bs_queue, bs->file, bdrv_inherited_flags(flags));
}

bs_entry = g_new0(BlockReopenQueueEntry, 1);
Expand Down Expand Up @@ -1717,11 +1744,6 @@ void bdrv_close(BlockDriverState *bs)
}
bs->drv->bdrv_close(bs);
g_free(bs->opaque);
#ifdef _WIN32
if (bs->is_temporary) {
unlink(bs->filename);
}
#endif
bs->opaque = NULL;
bs->drv = NULL;
bs->copy_on_read = 0;
Expand Down Expand Up @@ -1845,7 +1867,6 @@ static void bdrv_move_feature_fields(BlockDriverState *bs_dest,
BlockDriverState *bs_src)
{
/* move some fields that need to stay attached to the device */
bs_dest->open_flags = bs_src->open_flags;

/* dev info */
bs_dest->dev_ops = bs_src->dev_ops;
Expand Down Expand Up @@ -3601,10 +3622,25 @@ void bdrv_iterate_format(void (*it)(void *opaque, const char *name),
void *opaque)
{
BlockDriver *drv;
int count = 0;
const char **formats = NULL;

QLIST_FOREACH(drv, &bdrv_drivers, list) {
it(opaque, drv->format_name);
if (drv->format_name) {
bool found = false;
int i = count;
while (formats && i && !found) {
found = !strcmp(formats[--i], drv->format_name);
}

if (!found) {
formats = g_realloc(formats, (count + 1) * sizeof(char *));
formats[count++] = drv->format_name;
it(opaque, drv->format_name);
}
}
}
g_free(formats);
}

/* This function is to find block backend bs */
Expand Down
23 changes: 14 additions & 9 deletions block/bochs.c
Expand Up @@ -187,27 +187,29 @@ static int64_t seek_to_sector(BlockDriverState *bs, int64_t sector_num)
uint64_t offset = sector_num * 512;
uint64_t extent_index, extent_offset, bitmap_offset;
char bitmap_entry;
int ret;

// seek to sector
extent_index = offset / s->extent_size;
extent_offset = (offset % s->extent_size) / 512;

if (s->catalog_bitmap[extent_index] == 0xffffffff) {
return -1; /* not allocated */
return 0; /* not allocated */
}

bitmap_offset = s->data_offset +
(512 * (uint64_t) s->catalog_bitmap[extent_index] *
(s->extent_blocks + s->bitmap_blocks));

/* read in bitmap for current extent */
if (bdrv_pread(bs->file, bitmap_offset + (extent_offset / 8),
&bitmap_entry, 1) != 1) {
return -1;
ret = bdrv_pread(bs->file, bitmap_offset + (extent_offset / 8),
&bitmap_entry, 1);
if (ret < 0) {
return ret;
}

if (!((bitmap_entry >> (extent_offset % 8)) & 1)) {
return -1; /* not allocated */
return 0; /* not allocated */
}

return bitmap_offset + (512 * (s->bitmap_blocks + extent_offset));
Expand All @@ -220,13 +222,16 @@ static int bochs_read(BlockDriverState *bs, int64_t sector_num,

while (nb_sectors > 0) {
int64_t block_offset = seek_to_sector(bs, sector_num);
if (block_offset >= 0) {
if (block_offset < 0) {
return block_offset;
} else if (block_offset > 0) {
ret = bdrv_pread(bs->file, block_offset, buf, 512);
if (ret != 512) {
return -1;
if (ret < 0) {
return ret;
}
} else
} else {
memset(buf, 0, 512);
}
nb_sectors--;
sector_num++;
buf += 512;
Expand Down
2 changes: 1 addition & 1 deletion block/cow.c
Expand Up @@ -82,7 +82,7 @@ static int cow_open(BlockDriverState *bs, QDict *options, int flags,
if (be32_to_cpu(cow_header.version) != COW_VERSION) {
char version[64];
snprintf(version, sizeof(version),
"COW version %d", cow_header.version);
"COW version %" PRIu32, cow_header.version);
error_set(errp, QERR_UNKNOWN_BLOCK_FORMAT_FEATURE,
bs->device_name, "cow", version);
ret = -ENOTSUP;
Expand Down

0 comments on commit e50bf23

Please sign in to comment.