glusterfs
99 строк · 2.0 Кб
1/*
2Copyright (c) 2021 Red Hat, Inc. <https://www.redhat.com>
3This file is part of GlusterFS.
4
5This file is licensed to you under your choice of the GNU Lesser
6General Public License, version 3 or any later version (LGPLv3 or
7later), or the GNU General Public License, version 2 (GPLv2), in all
8cases as published by the Free Software Foundation.
9*/
10
11#include <glusterfs/gf-io-legacy.h>
12
13#include <glusterfs/globals.h>
14#include <glusterfs/gf-event.h>
15#include <glusterfs/timer.h>
16
17static uint64_t gf_io_legacy_seq;
18
19static int32_t
20gf_io_legacy_setup(void)
21{
22gf_io_legacy_seq = 0;
23
24return 0;
25}
26
27static void
28gf_io_legacy_cleanup(void)
29{
30}
31
32static int32_t
33gf_io_legacy_wait(void)
34{
35return gf_event_dispatch(global_ctx->event_pool);
36}
37
38static void
39gf_io_legacy_flush(void)
40{
41}
42
43static void
44gf_io_legacy_cbk(uint64_t id, int32_t res)
45{
46uint64_t seq;
47
48seq = uatomic_add_return(&gf_io_legacy_seq, 1) - 1;
49
50gf_io_cbk(NULL, seq, id, res);
51}
52
53static uint64_t
54gf_io_legacy_cancel(uint64_t seq, uint64_t id, gf_io_op_t *op, uint32_t count)
55{
56gf_timer_t *timer;
57
58timer = (gf_timer_t *)(uintptr_t)op->cancel.id;
59if (timer == NULL) {
60gf_io_legacy_cbk(id, -ENOENT);
61} else {
62op = timer->data;
63if (gf_timer_call_cancel(global_ctx, timer) < 0) {
64gf_io_legacy_cbk(id, -EALREADY);
65} else {
66gf_io_legacy_cbk(op->cancel.id, -ECANCELED);
67gf_io_legacy_cbk(id, 0);
68}
69}
70
71return 0;
72}
73
74static uint64_t
75gf_io_legacy_callback(uint64_t seq, uint64_t id, gf_io_op_t *op, uint32_t count)
76{
77gf_io_legacy_cbk(id, 0);
78
79return 0;
80}
81
82const gf_io_engine_t gf_io_engine_legacy = {
83.name = "legacy",
84.mode = GF_IO_MODE_LEGACY,
85
86.setup = gf_io_legacy_setup,
87.cleanup = gf_io_legacy_cleanup,
88.wait = gf_io_legacy_wait,
89
90.worker_setup = NULL,
91.worker_cleanup = NULL,
92.worker_stop = NULL,
93.worker = NULL,
94
95.flush = gf_io_legacy_flush,
96
97.cancel = gf_io_legacy_cancel,
98.callback = gf_io_legacy_callback
99};
100