create.c (d7e2fe4aac8b74bbfe82b2309536528b4dbe0d34) | create.c (4ec8df0183d0906ae6704d65ef6d8082c970ecdf) |
---|---|
1/* 2 * Block layer code related to image creation 3 * 4 * Copyright (c) 2018 Kevin Wolf <kwolf@redhat.com> 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a copy 7 * of this software and associated documentation files (the "Software"), to deal 8 * in the Software without restriction, including without limitation the rights --- 29 unchanged lines hidden (view full) --- 38} BlockdevCreateJob; 39 40static int coroutine_fn blockdev_create_run(Job *job, Error **errp) 41{ 42 BlockdevCreateJob *s = container_of(job, BlockdevCreateJob, common); 43 int ret; 44 45 GLOBAL_STATE_CODE(); | 1/* 2 * Block layer code related to image creation 3 * 4 * Copyright (c) 2018 Kevin Wolf <kwolf@redhat.com> 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a copy 7 * of this software and associated documentation files (the "Software"), to deal 8 * in the Software without restriction, including without limitation the rights --- 29 unchanged lines hidden (view full) --- 38} BlockdevCreateJob; 39 40static int coroutine_fn blockdev_create_run(Job *job, Error **errp) 41{ 42 BlockdevCreateJob *s = container_of(job, BlockdevCreateJob, common); 43 int ret; 44 45 GLOBAL_STATE_CODE(); |
46 GRAPH_RDLOCK_GUARD(); |
|
46 47 job_progress_set_remaining(&s->common, 1); 48 ret = s->drv->bdrv_co_create(s->opts, errp); 49 job_progress_update(&s->common, 1); 50 51 qapi_free_BlockdevCreateOptions(s->opts); 52 53 return ret; 54} 55 56static const JobDriver blockdev_create_job_driver = { 57 .instance_size = sizeof(BlockdevCreateJob), 58 .job_type = JOB_TYPE_CREATE, 59 .run = blockdev_create_run, 60}; 61 | 47 48 job_progress_set_remaining(&s->common, 1); 49 ret = s->drv->bdrv_co_create(s->opts, errp); 50 job_progress_update(&s->common, 1); 51 52 qapi_free_BlockdevCreateOptions(s->opts); 53 54 return ret; 55} 56 57static const JobDriver blockdev_create_job_driver = { 58 .instance_size = sizeof(BlockdevCreateJob), 59 .job_type = JOB_TYPE_CREATE, 60 .run = blockdev_create_run, 61}; 62 |
63/* Checking whether the function is present doesn't require the graph lock */ 64static inline bool TSA_NO_TSA has_bdrv_co_create(BlockDriver *drv) 65{ 66 return drv->bdrv_co_create; 67} 68 |
|
62void qmp_blockdev_create(const char *job_id, BlockdevCreateOptions *options, 63 Error **errp) 64{ 65 BlockdevCreateJob *s; 66 const char *fmt = BlockdevDriver_str(options->driver); 67 BlockDriver *drv = bdrv_find_format(fmt); 68 69 if (!drv) { --- 4 unchanged lines hidden (view full) --- 74 /* If the driver is in the schema, we know that it exists. But it may not 75 * be whitelisted. */ 76 if (bdrv_uses_whitelist() && !bdrv_is_whitelisted(drv, false)) { 77 error_setg(errp, "Driver is not whitelisted"); 78 return; 79 } 80 81 /* Error out if the driver doesn't support .bdrv_co_create */ | 69void qmp_blockdev_create(const char *job_id, BlockdevCreateOptions *options, 70 Error **errp) 71{ 72 BlockdevCreateJob *s; 73 const char *fmt = BlockdevDriver_str(options->driver); 74 BlockDriver *drv = bdrv_find_format(fmt); 75 76 if (!drv) { --- 4 unchanged lines hidden (view full) --- 81 /* If the driver is in the schema, we know that it exists. But it may not 82 * be whitelisted. */ 83 if (bdrv_uses_whitelist() && !bdrv_is_whitelisted(drv, false)) { 84 error_setg(errp, "Driver is not whitelisted"); 85 return; 86 } 87 88 /* Error out if the driver doesn't support .bdrv_co_create */ |
82 if (!drv->bdrv_co_create) { | 89 if (!has_bdrv_co_create(drv)) { |
83 error_setg(errp, "Driver does not support blockdev-create"); 84 return; 85 } 86 87 /* Create the block job */ 88 /* TODO Running in the main context. Block drivers need to error out or add 89 * locking when they use a BDS in a different AioContext. */ 90 s = job_create(job_id, &blockdev_create_job_driver, NULL, 91 qemu_get_aio_context(), JOB_DEFAULT | JOB_MANUAL_DISMISS, 92 NULL, NULL, errp); 93 if (!s) { 94 return; 95 } 96 97 s->drv = drv, 98 s->opts = QAPI_CLONE(BlockdevCreateOptions, options), 99 100 job_start(&s->common); 101} | 90 error_setg(errp, "Driver does not support blockdev-create"); 91 return; 92 } 93 94 /* Create the block job */ 95 /* TODO Running in the main context. Block drivers need to error out or add 96 * locking when they use a BDS in a different AioContext. */ 97 s = job_create(job_id, &blockdev_create_job_driver, NULL, 98 qemu_get_aio_context(), JOB_DEFAULT | JOB_MANUAL_DISMISS, 99 NULL, NULL, errp); 100 if (!s) { 101 return; 102 } 103 104 s->drv = drv, 105 s->opts = QAPI_CLONE(BlockdevCreateOptions, options), 106 107 job_start(&s->common); 108} |