Lines Matching refs:refcount
57 /* refcount handling */
114 * Returns the refcount of the cluster given by its index. Any non-negative
115 * return value is the refcount of the cluster, negative values are -errno
144 * Rounds the refcount table size up to avoid growing the table for each single
145 * refcount block that is allocated.
162 /* Checks if two offsets are described by the same refcount block */
173 * Loads a refcount block. If it doesn't exist yet, it is allocated first
174 * (including growing the refcount table if needed).
176 * Returns the offset of the refcount block on success or -errno in error case
186 /* Find the refcount block for the given cluster */
208 * a cluster for the new refcount block. It may also include a new refcount
209 * table if the old refcount table is too small.
214 * increase the refcount and very likely we would end up with an endless
215 * recursion. Instead we must place the refcount blocks in a way that
219 * and doing the initial refcount increase. This means that some clusters
220 * have already been allocated by the caller, but their refcount isn't
225 * refcount block into the cache
235 /* Allocate the refcount block itself and mark it as used */
242 fprintf(stderr, "qcow2: Allocate refcount block %d for %" PRIx64
248 /* Zero the new refcount block before updating it */
264 /* Initialize the new refcount block only after updating its refcount,
265 * update_refcount uses the refcount cache itself */
270 /* Now the new refcount block needs to be written to disk */
278 /* If the refcount table is big enough, just hook the block up there */
294 * If we come here, we need to grow the refcount table. Again, a new
295 * refcount table needs some space and we can't simply allocate to avoid
298 * Therefore let's grab new refcount blocks at the end of the image, which
299 * will describe themselves and the new refcount table. This way we can
301 * refcount table at once without producing an inconsistent state in
306 /* Calculate the number of refcount blocks needed so far */
330 fprintf(stderr, "qcow2: Grow refcount table %" PRId32 " => %" PRId64 "\n",
334 /* Create the new refcount table and blocks */
343 /* Fill the new refcount table */
353 /* Fill the refcount blocks */
360 /* Write refcount blocks to disk */
369 /* Write refcount table to disk */
385 /* Hook up the new refcount table in the qcow2 header */
457 /* XXX: cache several refcount block clusters ? */
483 int block_index, refcount;
487 /* Only write refcount block to disk when we are done with it */
502 /* Load the refcount block and allocate it if needed */
520 refcount = be16_to_cpu(s->refcount_block_cache[block_index]);
521 refcount += addend;
522 if (refcount < 0 || refcount > 0xffff) {
526 if (refcount == 0 && cluster_index < s->free_cluster_index) {
529 s->refcount_block_cache[block_index] = cpu_to_be16(refcount);
547 * some cases like ENOSPC for allocating a new refcount block)
558 * Increases or decreases the refcount of a given cluster by one.
561 * If the return value is non-negative, it is the new refcount of the cluster.
590 int i, nb_clusters, refcount;
596 refcount = get_refcount(bs, next_cluster_index);
598 if (refcount < 0) {
599 return refcount;
600 } else if (refcount != 0) {
729 int refcount;
738 refcount = be16_to_cpu(*p);
739 refcount++;
740 *p = cpu_to_be16(refcount);
751 int l2_size, i, j, l1_modified, l2_modified, nb_csectors, refcount;
806 refcount = 2;
809 refcount = update_cluster_refcount(bs, offset >> s->cluster_bits, addend);
811 refcount = get_refcount(bs, offset >> s->cluster_bits);
814 if (refcount < 0) {
819 if (refcount == 1) {
835 refcount = update_cluster_refcount(bs, l2_offset >> s->cluster_bits, addend);
837 refcount = get_refcount(bs, l2_offset >> s->cluster_bits);
839 if (refcount < 0) {
841 } else if (refcount == 1) {
878 /* refcount checking functions */
883 * Increases the refcount for a range of clusters in a given refcount table.
884 * This is used to construct a temporary refcount table out of L1 and L2 tables
885 * which can be compared the the refcount table saved in the image.
927 * Increases the refcount in the given refcount table for the all clusters
940 int i, l2_size, nb_csectors, refcount;
970 /* QCOW_OFLAG_COPIED must be set iff refcount == 1 */
974 refcount = get_refcount(bs, offset >> s->cluster_bits);
975 if (refcount < 0) {
976 fprintf(stderr, "Can't get refcount for offset %"
977 PRIx64 ": %s\n", entry, strerror(-refcount));
980 if ((refcount == 1) != ((entry & QCOW_OFLAG_COPIED) != 0)) {
982 PRIx64 " refcount=%d\n", entry, refcount);
1012 * Increases the refcount for the L1 table, its L2 tables and all referenced
1013 * clusters in the given refcount table. While doing so, performs some checks
1028 int i, refcount, ret;
1052 /* QCOW_OFLAG_COPIED must be set iff refcount == 1 */
1054 refcount = get_refcount(bs, (l2_offset & ~QCOW_OFLAG_COPIED)
1056 if (refcount < 0) {
1057 fprintf(stderr, "Can't get refcount for l2_offset %"
1058 PRIx64 ": %s\n", l2_offset, strerror(-refcount));
1061 if ((refcount == 1) != ((l2_offset & QCOW_OFLAG_COPIED) != 0)) {
1063 " refcount=%d\n", l2_offset, refcount);
1099 * Checks an image for refcount consistency.
1140 /* refcount data */
1150 /* Refcount blocks are cluster aligned */
1152 fprintf(stderr, "ERROR refcount block %d is not "
1153 "cluster aligned; refcount table entry corrupted\n", i);
1159 fprintf(stderr, "ERROR refcount block %d is outside image\n", i);
1168 fprintf(stderr, "ERROR refcount block %d refcount=%d\n",
1179 fprintf(stderr, "Can't get refcount for cluster %d: %s\n",
1187 fprintf(stderr, "%s cluster %d refcount=%d reference=%d\n",