49{
51
53
54#define PG_GET_AIOS_COLS 15
55
57 {
69
70
71 /*
72 * There is no lock that could prevent the state of the IO to advance
73 * concurrently - and we don't want to introduce one, as that would
74 * introduce atomics into a very common path. Instead we
75 *
76 * 1) Determine the state + generation of the IO.
77 *
78 * 2) Copy the IO to local memory.
79 *
80 * 3) Check if state or generation of the IO changed. If the state
81 * changed, retry, if the generation changed don't display the IO.
82 */
83
84 /* 1) from above */
86
87 /*
88 * Retry at this point, so we can accept changing states, but not
89 * changing generations.
90 */
91retry:
93 start_state = live_ioh->
state;
94
96 continue;
97
98 /* 2) from above */
100
101 /*
102 * Safe to copy even if no iovec is used - we always reserve the
103 * required space.
104 */
107
108 /*
109 * Copy information about owner before 3) below, if the process exited
110 * it'd have to wait for the IO to finish first, which we would detect
111 * in 3).
112 */
115 owner_pid = owner_proc->
pid;
116
117 /* 3) from above */
119
120 /*
121 * The IO completed and a new one was started with the same ID. Don't
122 * display it - it really started after this function was called.
123 * There be a risk of a livelock if we just retried endlessly, if IOs
124 * complete very quickly.
125 */
127 continue;
128
129 /*
130 * The IO's state changed while we were "rendering" it. Just start
131 * from scratch. There's no risk of a livelock here, as an IO has a
132 * limited sets of states it can be in, and state changes go only in a
133 * single direction.
134 */
135 if (live_ioh->
state != start_state)
136 goto retry;
137
138 /*
139 * Now that we have copied the IO into local memory and checked that
140 * it's still in the same state, we are not allowed to access "live"
141 * memory anymore. To make it slightly easier to catch such cases, set
142 * the "live" pointers to NULL.
143 */
144 live_ioh = NULL;
145 owner_proc = NULL;
146
147
148 /* column: owning pid */
149 if (owner_pid != 0)
151 else
152 nulls[0] = false;
153
154 /* column: IO's id */
156
157 /* column: IO's generation */
159
160 /* column: IO's state */
162
163 /*
164 * If the IO is in PGAIO_HS_HANDED_OUT state, none of the following
165 * fields are valid yet (or are in the process of being set).
166 * Therefore we don't want to display any other columns.
167 */
169 {
170 memset(nulls + 4, 1, (
lengthof(nulls) - 4) *
sizeof(
bool));
171 goto display;
172 }
173
174 /* column: IO's operation */
176
177 /* columns: details about the IO's operation (offset, length) */
179 {
181 nulls[5] = true;
182 nulls[6] = true;
183 break;
188 break;
193 break;
194 }
195
196 /* column: IO's target */
198
199 /* column: length of IO's data array */
201
202 /* column: raw result (i.e. some form of syscall return value) */
207 else
208 nulls[9] = true;
209
210 /*
211 * column: result in the higher level representation (unknown if not
212 * finished)
213 */
216
217 /* column: target description */
219
220 /* columns: one for each flag */
224
225display:
227 }
228
230}
int pgaio_io_get_id(PgAioHandle *ioh)
const char * pgaio_result_status_string(PgAioResultStatus rs)
const char * pgaio_io_get_state_name(PgAioHandle *ioh)
@ PGAIO_HF_REFERENCES_LOCAL
static size_t iov_byte_length(const struct iovec *iov, int cnt)
@ PGAIO_HS_COMPLETED_SHARED
@ PGAIO_HS_COMPLETED_LOCAL
const char * pgaio_io_get_op_name(PgAioHandle *ioh)
const char * pgaio_io_get_target_name(PgAioHandle *ioh)
char * pgaio_io_get_target_description(PgAioHandle *ioh)
#define pg_read_barrier()
static Datum values[MAXATTR]
#define CStringGetTextDatum(s)
void InitMaterializedSRF(FunctionCallInfo fcinfo, bits32 flags)
static Datum Int64GetDatum(int64 X)
static Datum Int16GetDatum(int16 X)
static Datum BoolGetDatum(bool X)
static Datum Int32GetDatum(int32 X)
#define GetPGProcByNumber(n)
PgAioResult distilled_result
Tuplestorestate * setResult
void tuplestore_putvalues(Tuplestorestate *state, TupleDesc tdesc, const Datum *values, const bool *isnull)
struct PgAioOpData::@126 read
struct PgAioOpData::@127 write