Revision 16d2fc00 block/cow.c

b/block/cow.c
64 64
    struct cow_header_v2 cow_header;
65 65
    int bitmap_size;
66 66
    int64_t size;
67
    int ret;
67 68

  
68 69
    /* see if it is a cow image */
69
    if (bdrv_pread(bs->file, 0, &cow_header, sizeof(cow_header)) !=
70
            sizeof(cow_header)) {
70
    ret = bdrv_pread(bs->file, 0, &cow_header, sizeof(cow_header));
71
    if (ret < 0) {
72
        goto fail;
73
    }
74

  
75
    if (be32_to_cpu(cow_header.magic) != COW_MAGIC) {
76
        ret = -EINVAL;
71 77
        goto fail;
72 78
    }
73 79

  
74
    if (be32_to_cpu(cow_header.magic) != COW_MAGIC ||
75
        be32_to_cpu(cow_header.version) != COW_VERSION) {
80
    if (be32_to_cpu(cow_header.version) != COW_VERSION) {
81
        char version[64];
82
        snprintf(version, sizeof(version),
83
               "COW version %d", cow_header.version);
84
        qerror_report(QERR_UNKNOWN_BLOCK_FORMAT_FEATURE,
85
            bs->device_name, "cow", version);
86
        ret = -ENOTSUP;
76 87
        goto fail;
77 88
    }
78 89

  
......
88 99
    qemu_co_mutex_init(&s->lock);
89 100
    return 0;
90 101
 fail:
91
    return -1;
102
    return ret;
92 103
}
93 104

  
94 105
/*
......
182 193
            ret = bdrv_pread(bs->file,
183 194
                        s->cow_sectors_offset + sector_num * 512,
184 195
                        buf, n * 512);
185
            if (ret != n * 512)
186
                return -1;
196
            if (ret < 0) {
197
                return ret;
198
            }
187 199
        } else {
188 200
            if (bs->backing_hd) {
189 201
                /* read from the base image */
190 202
                ret = bdrv_read(bs->backing_hd, sector_num, buf, n);
191
                if (ret < 0)
192
                    return -1;
203
                if (ret < 0) {
204
                    return ret;
205
                }
193 206
            } else {
194
            memset(buf, 0, n * 512);
195
        }
207
                memset(buf, 0, n * 512);
208
            }
196 209
        }
197 210
        nb_sectors -= n;
198 211
        sector_num += n;
......
220 233

  
221 234
    ret = bdrv_pwrite(bs->file, s->cow_sectors_offset + sector_num * 512,
222 235
                      buf, nb_sectors * 512);
223
    if (ret != nb_sectors * 512)
224
        return -1;
236
    if (ret < 0) {
237
        return ret;
238
    }
225 239

  
226 240
    return cow_update_bitmap(bs, sector_num, nb_sectors);
227 241
}
......
288 302
    cow_header.sectorsize = cpu_to_be32(512);
289 303
    cow_header.size = cpu_to_be64(image_sectors * 512);
290 304
    ret = bdrv_pwrite(cow_bs, 0, &cow_header, sizeof(cow_header));
291
    if (ret != sizeof(cow_header)) {
305
    if (ret < 0) {
292 306
        goto exit;
293 307
    }
294 308

  
295 309
    /* resize to include at least all the bitmap */
296 310
    ret = bdrv_truncate(cow_bs,
297 311
        sizeof(cow_header) + ((image_sectors + 7) >> 3));
298
    if (ret) {
312
    if (ret < 0) {
299 313
        goto exit;
300 314
    }
301 315

  

Also available in: Unified diff