]>
Commit | Line | Data |
---|---|---|
33e9e9bd KW |
1 | /* |
2 | * Declarations for background jobs | |
3 | * | |
4 | * Copyright (c) 2011 IBM Corp. | |
5 | * Copyright (c) 2012, 2018 Red Hat, Inc. | |
6 | * | |
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
8 | * of this software and associated documentation files (the "Software"), to deal | |
9 | * in the Software without restriction, including without limitation the rights | |
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
11 | * copies of the Software, and to permit persons to whom the Software is | |
12 | * furnished to do so, subject to the following conditions: | |
13 | * | |
14 | * The above copyright notice and this permission notice shall be included in | |
15 | * all copies or substantial portions of the Software. | |
16 | * | |
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
20 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
23 | * THE SOFTWARE. | |
24 | */ | |
25 | ||
26 | #ifndef JOB_H | |
27 | #define JOB_H | |
28 | ||
252291ea | 29 | #include "qapi/qapi-types-block-core.h" |
e7c1d78b | 30 | #include "qemu/queue.h" |
252291ea | 31 | |
33e9e9bd KW |
32 | typedef struct JobDriver JobDriver; |
33 | ||
34 | /** | |
35 | * Long-running operation. | |
36 | */ | |
37 | typedef struct Job { | |
38 | /** The ID of the job. May be NULL for internal jobs. */ | |
39 | char *id; | |
40 | ||
41 | /** The type of this job. */ | |
42 | const JobDriver *driver; | |
e7c1d78b | 43 | |
a50c2ab8 KW |
44 | /** Current state; See @JobStatus for details. */ |
45 | JobStatus status; | |
46 | ||
e7c1d78b KW |
47 | /** Element of the list of jobs */ |
48 | QLIST_ENTRY(Job) job_list; | |
33e9e9bd KW |
49 | } Job; |
50 | ||
51 | /** | |
52 | * Callbacks and other information about a Job driver. | |
53 | */ | |
54 | struct JobDriver { | |
55 | /** Derived Job struct size */ | |
56 | size_t instance_size; | |
252291ea KW |
57 | |
58 | /** Enum describing the operation */ | |
59 | JobType job_type; | |
33e9e9bd KW |
60 | }; |
61 | ||
62 | ||
63 | /** | |
64 | * Create a new long-running job and return it. | |
65 | * | |
66 | * @job_id: The id of the newly-created job, or %NULL for internal jobs | |
67 | * @driver: The class object for the newly-created job. | |
68 | * @errp: Error object. | |
69 | */ | |
70 | void *job_create(const char *job_id, const JobDriver *driver, Error **errp); | |
71 | ||
fd61a701 KW |
72 | /** Frees the @job object. */ |
73 | void job_delete(Job *job); | |
74 | ||
252291ea KW |
75 | /** Returns the JobType of a given Job. */ |
76 | JobType job_type(const Job *job); | |
77 | ||
78 | /** Returns the enum string for the JobType of a given Job. */ | |
79 | const char *job_type_str(const Job *job); | |
80 | ||
e7c1d78b KW |
81 | /** |
82 | * Get the next element from the list of block jobs after @job, or the | |
83 | * first one if @job is %NULL. | |
84 | * | |
85 | * Returns the requested job, or %NULL if there are no more jobs left. | |
86 | */ | |
87 | Job *job_next(Job *job); | |
88 | ||
89 | /** | |
90 | * Get the job identified by @id (which must not be %NULL). | |
91 | * | |
92 | * Returns the requested job, or %NULL if it doesn't exist. | |
93 | */ | |
94 | Job *job_get(const char *id); | |
95 | ||
a50c2ab8 KW |
96 | /** |
97 | * Check whether the verb @verb can be applied to @job in its current state. | |
98 | * Returns 0 if the verb can be applied; otherwise errp is set and -EPERM | |
99 | * returned. | |
100 | */ | |
101 | int job_apply_verb(Job *job, JobVerb verb, Error **errp); | |
102 | ||
103 | /* TODO To be removed from the public interface */ | |
104 | void job_state_transition(Job *job, JobStatus s1); | |
105 | ||
33e9e9bd | 106 | #endif |