Signed-off-by: Fiona Ebner <f.eb...@proxmox.com> --- New in v7.
pve-backup.c | 86 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 49 insertions(+), 37 deletions(-) diff --git a/pve-backup.c b/pve-backup.c index 091b5bd231..04583f2b89 100644 --- a/pve-backup.c +++ b/pve-backup.c @@ -760,6 +760,53 @@ static bool fleecing_all(const char *device_id) return true; } +static PVEBackupDevInfo coroutine_fn GRAPH_RDLOCK *get_single_device_info( + const char *device, + bool (*device_uses_fleecing)(const char*), + Error **errp) +{ + BlockBackend *blk = blk_by_name(device); + if (!blk) { + error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, + "Device '%s' not found", device); + return NULL; + } + BlockDriverState *bs = blk_bs(blk); + if (!bdrv_co_is_inserted(bs)) { + error_setg(errp, "Device '%s' has no medium", device); + return NULL; + } + PVEBackupDevInfo *di = g_new0(PVEBackupDevInfo, 1); + di->bs = bs; + di->device_name = g_strdup(bdrv_get_device_name(bs)); + + if (device_uses_fleecing && device_uses_fleecing(device)) { + g_autofree gchar *fleecing_devid = g_strconcat(device, "-fleecing", NULL); + BlockBackend *fleecing_blk = blk_by_name(fleecing_devid); + if (!fleecing_blk) { + error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, + "Device '%s' not found", fleecing_devid); + return NULL; + } + BlockDriverState *fleecing_bs = blk_bs(fleecing_blk); + if (!bdrv_co_is_inserted(fleecing_bs)) { + error_setg(errp, "Device '%s' has no medium", fleecing_devid); + return NULL; + } + /* + * Fleecing image needs to be the same size to act as a cbw target. + */ + if (bs->total_sectors != fleecing_bs->total_sectors) { + error_setg(errp, "Size mismatch for '%s' - sector count %ld != %ld", + fleecing_devid, fleecing_bs->total_sectors, bs->total_sectors); + return NULL; + } + di->fleecing.bs = fleecing_bs; + } + + return di; +} + /* * Returns a list of device infos, which needs to be freed by the caller. In * case of an error, errp will be set, but the returned value might still be a @@ -778,45 +825,10 @@ static GList coroutine_fn GRAPH_RDLOCK *get_device_info( gchar **d = devs; while (d && *d) { - BlockBackend *blk = blk_by_name(*d); - if (!blk) { - error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, - "Device '%s' not found", *d); + PVEBackupDevInfo *di = get_single_device_info(*d, device_uses_fleecing, errp); + if (!di) { goto err; } - BlockDriverState *bs = blk_bs(blk); - if (!bdrv_co_is_inserted(bs)) { - error_setg(errp, "Device '%s' has no medium", *d); - goto err; - } - PVEBackupDevInfo *di = g_new0(PVEBackupDevInfo, 1); - di->bs = bs; - di->device_name = g_strdup(bdrv_get_device_name(bs)); - - if (device_uses_fleecing && device_uses_fleecing(*d)) { - g_autofree gchar *fleecing_devid = g_strconcat(*d, "-fleecing", NULL); - BlockBackend *fleecing_blk = blk_by_name(fleecing_devid); - if (!fleecing_blk) { - error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, - "Device '%s' not found", fleecing_devid); - goto err; - } - BlockDriverState *fleecing_bs = blk_bs(fleecing_blk); - if (!bdrv_co_is_inserted(fleecing_bs)) { - error_setg(errp, "Device '%s' has no medium", fleecing_devid); - goto err; - } - /* - * Fleecing image needs to be the same size to act as a cbw target. - */ - if (bs->total_sectors != fleecing_bs->total_sectors) { - error_setg(errp, "Size mismatch for '%s' - sector count %ld != %ld", - fleecing_devid, fleecing_bs->total_sectors, bs->total_sectors); - goto err; - } - di->fleecing.bs = fleecing_bs; - } - di_list = g_list_append(di_list, di); d++; } -- 2.39.5 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel