Revision 6b837bc4 qemu-img.c

b/qemu-img.c
77 77
           "       match exactly. The image doesn't need a working backing file before\n"
78 78
           "       rebasing in this case (useful for renaming the backing file)\n"
79 79
           "  '-h' with or without a command shows this help and lists the supported formats\n"
80
           "  '-p' show progress of command (only certain commands)\n"
80 81
           "\n"
81 82
           "Parameters to snapshot subcommand:\n"
82 83
           "  'snapshot' is the name of the snapshot to create, apply or delete\n"
......
567 568
static int img_convert(int argc, char **argv)
568 569
{
569 570
    int c, ret = 0, n, n1, bs_n, bs_i, compress, cluster_size, cluster_sectors;
571
    int progress = 0;
570 572
    const char *fmt, *out_fmt, *out_baseimg, *out_filename;
571 573
    BlockDriver *drv, *proto_drv;
572 574
    BlockDriverState **bs = NULL, *out_bs = NULL;
......
579 581
    QEMUOptionParameter *out_baseimg_param;
580 582
    char *options = NULL;
581 583
    const char *snapshot_name = NULL;
584
    float local_progress;
582 585

  
583 586
    fmt = NULL;
584 587
    out_fmt = "raw";
585 588
    out_baseimg = NULL;
586 589
    compress = 0;
587 590
    for(;;) {
588
        c = getopt(argc, argv, "f:O:B:s:hce6o:");
591
        c = getopt(argc, argv, "f:O:B:s:hce6o:p");
589 592
        if (c == -1) {
590 593
            break;
591 594
        }
......
620 623
        case 's':
621 624
            snapshot_name = optarg;
622 625
            break;
626
        case 'p':
627
            progress = 1;
628
            break;
623 629
        }
624 630
    }
625 631

  
......
642 648
        goto out;
643 649
    }
644 650
        
651
    qemu_progress_init(progress, 2.0);
652
    qemu_progress_print(0, 100);
653

  
645 654
    bs = qemu_mallocz(bs_n * sizeof(BlockDriverState *));
646 655

  
647 656
    total_sectors = 0;
......
773 782
        }
774 783
        cluster_sectors = cluster_size >> 9;
775 784
        sector_num = 0;
785

  
786
        nb_sectors = total_sectors;
787
        local_progress = (float)100 /
788
            (nb_sectors / MIN(nb_sectors, (cluster_sectors)));
789

  
776 790
        for(;;) {
777 791
            int64_t bs_num;
778 792
            int remainder;
......
832 846
                }
833 847
            }
834 848
            sector_num += n;
849
            qemu_progress_print(local_progress, 100);
835 850
        }
836 851
        /* signal EOF to align */
837 852
        bdrv_write_compressed(out_bs, 0, NULL, 0);
......
839 854
        int has_zero_init = bdrv_has_zero_init(out_bs);
840 855

  
841 856
        sector_num = 0; // total number of sectors converted so far
857
        nb_sectors = total_sectors - sector_num;
858
        local_progress = (float)100 /
859
            (nb_sectors / MIN(nb_sectors, (IO_BUF_SIZE / 512)));
860

  
842 861
        for(;;) {
843 862
            nb_sectors = total_sectors - sector_num;
844 863
            if (nb_sectors <= 0) {
......
912 931
                n -= n1;
913 932
                buf1 += n1 * 512;
914 933
            }
934
            qemu_progress_print(local_progress, 100);
915 935
        }
916 936
    }
917 937
out:
938
    qemu_progress_end();
918 939
    free_option_parameters(create_options);
919 940
    free_option_parameters(param);
920 941
    qemu_free(buf);
......
1184 1205
    const char *fmt, *out_basefmt, *out_baseimg;
1185 1206
    int c, flags, ret;
1186 1207
    int unsafe = 0;
1208
    int progress = 0;
1187 1209

  
1188 1210
    /* Parse commandline parameters */
1189 1211
    fmt = NULL;
......
1191 1213
    out_basefmt = NULL;
1192 1214

  
1193 1215
    for(;;) {
1194
        c = getopt(argc, argv, "uhf:F:b:");
1216
        c = getopt(argc, argv, "uhf:F:b:p");
1195 1217
        if (c == -1) {
1196 1218
            break;
1197 1219
        }
......
1212 1234
        case 'u':
1213 1235
            unsafe = 1;
1214 1236
            break;
1237
        case 'p':
1238
            progress = 1;
1239
            break;
1215 1240
        }
1216 1241
    }
1217 1242

  
......
1220 1245
    }
1221 1246
    filename = argv[optind++];
1222 1247

  
1248
    qemu_progress_init(progress, 2.0);
1249
    qemu_progress_print(0, 100);
1250

  
1223 1251
    /*
1224 1252
     * Open the images.
1225 1253
     *
......
1295 1323
        int n;
1296 1324
        uint8_t * buf_old;
1297 1325
        uint8_t * buf_new;
1326
        float local_progress;
1298 1327

  
1299 1328
        buf_old = qemu_malloc(IO_BUF_SIZE);
1300 1329
        buf_new = qemu_malloc(IO_BUF_SIZE);
1301 1330

  
1302 1331
        bdrv_get_geometry(bs, &num_sectors);
1303 1332

  
1333
        local_progress = (float)100 /
1334
            (num_sectors / MIN(num_sectors, (IO_BUF_SIZE / 512)));
1304 1335
        for (sector = 0; sector < num_sectors; sector += n) {
1305 1336

  
1306 1337
            /* How many sectors can we handle with the next read? */
......
1348 1379

  
1349 1380
                written += pnum;
1350 1381
            }
1382
            qemu_progress_print(local_progress, 100);
1351 1383
        }
1352 1384

  
1353 1385
        qemu_free(buf_old);
......
1368 1400
            out_baseimg, strerror(-ret));
1369 1401
    }
1370 1402

  
1403
    qemu_progress_print(100, 0);
1371 1404
    /*
1372 1405
     * TODO At this point it is possible to check if any clusters that are
1373 1406
     * allocated in the COW file are the same in the backing file. If so, they
......
1375 1408
     * backing file, in case of a crash this would lead to corruption.
1376 1409
     */
1377 1410
out:
1411
    qemu_progress_end();
1378 1412
    /* Cleanup */
1379 1413
    if (!unsafe) {
1380 1414
        bdrv_delete(bs_old_backing);

Also available in: Unified diff