Revision 6583e3c7 block/qcow2-cluster.c

b/block/qcow2-cluster.c
171 171
}
172 172

  
173 173
/*
174
 * Writes one sector of the L1 table to the disk (can't update single entries
175
 * and we really don't want bdrv_pread to perform a read-modify-write)
176
 */
177
#define L1_ENTRIES_PER_SECTOR (512 / 8)
178
static int write_l1_entry(BDRVQcowState *s, int l1_index)
179
{
180
    uint64_t buf[L1_ENTRIES_PER_SECTOR];
181
    int l1_start_index;
182
    int i;
183

  
184
    l1_start_index = l1_index & ~(L1_ENTRIES_PER_SECTOR - 1);
185
    for (i = 0; i < L1_ENTRIES_PER_SECTOR; i++) {
186
        buf[i] = cpu_to_be64(s->l1_table[l1_start_index + i]);
187
    }
188

  
189
    if (bdrv_pwrite(s->hd, s->l1_table_offset + 8 * l1_start_index,
190
        buf, sizeof(buf)) != sizeof(buf))
191
    {
192
        return -1;
193
    }
194

  
195
    return 0;
196
}
197

  
198
/*
174 199
 * l2_allocate
175 200
 *
176 201
 * Allocate a new l2 entry in the file. If l1_index points to an already
......
184 209
{
185 210
    BDRVQcowState *s = bs->opaque;
186 211
    int min_index;
187
    uint64_t old_l2_offset, tmp;
212
    uint64_t old_l2_offset;
188 213
    uint64_t *l2_table, l2_offset;
189 214

  
190 215
    old_l2_offset = s->l1_table[l1_index];
......
196 221
    /* update the L1 entry */
197 222

  
198 223
    s->l1_table[l1_index] = l2_offset | QCOW_OFLAG_COPIED;
199

  
200
    tmp = cpu_to_be64(l2_offset | QCOW_OFLAG_COPIED);
201
    if (bdrv_pwrite(s->hd, s->l1_table_offset + l1_index * sizeof(tmp),
202
                    &tmp, sizeof(tmp)) != sizeof(tmp))
224
    if (write_l1_entry(s, l1_index) < 0) {
203 225
        return NULL;
226
    }
204 227

  
205 228
    /* allocate a new entry in the l2 cache */
206 229

  

Also available in: Unified diff