Merge remote-tracking branch 'kwolf/for-anthony' into staging

* kwolf/for-anthony:
  ahci: SATA FIS is 20 bytes, not 0x20
  virtio-blk: Fix geometry sector calculation
  block: prevent snapshot mode $TMPDIR symlink attack
  sheepdog: fix return value of do_load_save_vm_state
  virtio: Fix compiler warning for non Linux hosts
This commit is contained in:
Anthony Liguori 2012-06-03 07:54:05 +08:00
commit 2eb02f2826
3 changed files with 26 additions and 9 deletions

View File

@ -1957,7 +1957,7 @@ static int do_load_save_vmstate(BDRVSheepdogState *s, uint8_t *data,
int64_t pos, int size, int load)
{
int fd, create;
int ret = 0;
int ret = 0, remaining = size;
unsigned int data_len;
uint64_t vmstate_oid;
uint32_t vdi_index;
@ -1968,11 +1968,11 @@ static int do_load_save_vmstate(BDRVSheepdogState *s, uint8_t *data,
return fd;
}
while (size) {
while (remaining) {
vdi_index = pos / SD_DATA_OBJ_SIZE;
offset = pos % SD_DATA_OBJ_SIZE;
data_len = MIN(size, SD_DATA_OBJ_SIZE);
data_len = MIN(remaining, SD_DATA_OBJ_SIZE);
vmstate_oid = vid_to_vmstate_oid(s->inode.vdi_id, vdi_index);
@ -1993,9 +1993,9 @@ static int do_load_save_vmstate(BDRVSheepdogState *s, uint8_t *data,
}
pos += data_len;
size -= data_len;
ret += data_len;
remaining -= data_len;
}
ret = size;
cleanup:
closesocket(fd);
return ret;

View File

@ -462,7 +462,7 @@ static void ahci_check_cmd_bh(void *opaque)
static void ahci_init_d2h(AHCIDevice *ad)
{
uint8_t init_fis[0x20];
uint8_t init_fis[20];
IDEState *ide_state = &ad->port.ifs[0];
memset(init_fis, 0, sizeof(init_fis));
@ -619,7 +619,7 @@ static void ahci_write_fis_d2h(AHCIDevice *ad, uint8_t *cmd_fis)
d2h_fis[11] = cmd_fis[11];
d2h_fis[12] = cmd_fis[12];
d2h_fis[13] = cmd_fis[13];
for (i = 14; i < 0x20; i++) {
for (i = 14; i < 20; i++) {
d2h_fis[i] = 0;
}

View File

@ -147,9 +147,11 @@ static VirtIOBlockReq *virtio_blk_get_request(VirtIOBlock *s)
static void virtio_blk_handle_scsi(VirtIOBlockReq *req)
{
#ifdef __linux__
int ret;
int status = VIRTIO_BLK_S_OK;
int i;
#endif
int status = VIRTIO_BLK_S_OK;
/*
* We require at least one output segment each for the virtio_blk_outhdr
@ -489,7 +491,22 @@ static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config)
stw_raw(&blkcfg.min_io_size, s->conf->min_io_size / blk_size);
stw_raw(&blkcfg.opt_io_size, s->conf->opt_io_size / blk_size);
blkcfg.heads = heads;
blkcfg.sectors = secs & ~s->sector_mask;
/*
* We must ensure that the block device capacity is a multiple of
* the logical block size. If that is not the case, lets use
* sector_mask to adopt the geometry to have a correct picture.
* For those devices where the capacity is ok for the given geometry
* we dont touch the sector value of the geometry, since some devices
* (like s390 dasd) need a specific value. Here the capacity is already
* cyls*heads*secs*blk_size and the sector value is not block size
* divided by 512 - instead it is the amount of blk_size blocks
* per track (cylinder).
*/
if (bdrv_getlength(s->bs) / heads / secs % blk_size) {
blkcfg.sectors = secs & ~s->sector_mask;
} else {
blkcfg.sectors = secs;
}
blkcfg.size_max = 0;
blkcfg.physical_block_exp = get_physical_block_exp(s->conf);
blkcfg.alignment_offset = 0;