xref: /qemu/job.c (revision 33e9e9bd)
1*33e9e9bdSKevin Wolf /*
2*33e9e9bdSKevin Wolf  * Background jobs (long-running operations)
3*33e9e9bdSKevin Wolf  *
4*33e9e9bdSKevin Wolf  * Copyright (c) 2011 IBM Corp.
5*33e9e9bdSKevin Wolf  * Copyright (c) 2012, 2018 Red Hat, Inc.
6*33e9e9bdSKevin Wolf  *
7*33e9e9bdSKevin Wolf  * Permission is hereby granted, free of charge, to any person obtaining a copy
8*33e9e9bdSKevin Wolf  * of this software and associated documentation files (the "Software"), to deal
9*33e9e9bdSKevin Wolf  * in the Software without restriction, including without limitation the rights
10*33e9e9bdSKevin Wolf  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11*33e9e9bdSKevin Wolf  * copies of the Software, and to permit persons to whom the Software is
12*33e9e9bdSKevin Wolf  * furnished to do so, subject to the following conditions:
13*33e9e9bdSKevin Wolf  *
14*33e9e9bdSKevin Wolf  * The above copyright notice and this permission notice shall be included in
15*33e9e9bdSKevin Wolf  * all copies or substantial portions of the Software.
16*33e9e9bdSKevin Wolf  *
17*33e9e9bdSKevin Wolf  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18*33e9e9bdSKevin Wolf  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19*33e9e9bdSKevin Wolf  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20*33e9e9bdSKevin Wolf  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21*33e9e9bdSKevin Wolf  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22*33e9e9bdSKevin Wolf  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23*33e9e9bdSKevin Wolf  * THE SOFTWARE.
24*33e9e9bdSKevin Wolf  */
25*33e9e9bdSKevin Wolf 
26*33e9e9bdSKevin Wolf #include "qemu/osdep.h"
27*33e9e9bdSKevin Wolf #include "qemu-common.h"
28*33e9e9bdSKevin Wolf #include "qapi/error.h"
29*33e9e9bdSKevin Wolf #include "qemu/job.h"
30*33e9e9bdSKevin Wolf #include "qemu/id.h"
31*33e9e9bdSKevin Wolf 
32*33e9e9bdSKevin Wolf void *job_create(const char *job_id, const JobDriver *driver, Error **errp)
33*33e9e9bdSKevin Wolf {
34*33e9e9bdSKevin Wolf     Job *job;
35*33e9e9bdSKevin Wolf 
36*33e9e9bdSKevin Wolf     if (job_id) {
37*33e9e9bdSKevin Wolf         if (!id_wellformed(job_id)) {
38*33e9e9bdSKevin Wolf             error_setg(errp, "Invalid job ID '%s'", job_id);
39*33e9e9bdSKevin Wolf             return NULL;
40*33e9e9bdSKevin Wolf         }
41*33e9e9bdSKevin Wolf     }
42*33e9e9bdSKevin Wolf 
43*33e9e9bdSKevin Wolf     job = g_malloc0(driver->instance_size);
44*33e9e9bdSKevin Wolf     job->driver        = driver;
45*33e9e9bdSKevin Wolf     job->id            = g_strdup(job_id);
46*33e9e9bdSKevin Wolf 
47*33e9e9bdSKevin Wolf     return job;
48*33e9e9bdSKevin Wolf }
49