2 * Persistent reservation manager abstract class
4 * Copyright (c) 2017 Red Hat, Inc.
6 * Author: Paolo Bonzini <pbonzini@redhat.com>
8 * This code is licensed under the LGPL.
12 #include "qemu/osdep.h"
15 #include "qapi/error.h"
16 #include "block/aio.h"
17 #include "block/thread-pool.h"
18 #include "scsi/pr-manager.h"
21 typedef struct PRManagerData
{
23 struct sg_io_hdr
*hdr
;
27 static int pr_manager_worker(void *opaque
)
29 PRManagerData
*data
= opaque
;
30 PRManager
*pr_mgr
= data
->pr_mgr
;
31 PRManagerClass
*pr_mgr_class
=
32 PR_MANAGER_GET_CLASS(pr_mgr
);
33 struct sg_io_hdr
*hdr
= data
->hdr
;
38 trace_pr_manager_run(fd
, hdr
->cmdp
[0], hdr
->cmdp
[1]);
40 /* The reference was taken in pr_manager_execute. */
41 r
= pr_mgr_class
->run(pr_mgr
, fd
, hdr
);
42 object_unref(OBJECT(pr_mgr
));
47 BlockAIOCB
*pr_manager_execute(PRManager
*pr_mgr
,
48 AioContext
*ctx
, int fd
,
49 struct sg_io_hdr
*hdr
,
50 BlockCompletionFunc
*complete
,
53 PRManagerData
*data
= g_new(PRManagerData
, 1);
54 ThreadPool
*pool
= aio_get_thread_pool(ctx
);
56 trace_pr_manager_execute(fd
, hdr
->cmdp
[0], hdr
->cmdp
[1], opaque
);
57 data
->pr_mgr
= pr_mgr
;
61 /* The matching object_unref is in pr_manager_worker. */
62 object_ref(OBJECT(pr_mgr
));
63 return thread_pool_submit_aio(pool
, pr_manager_worker
,
64 data
, complete
, opaque
);
67 static const TypeInfo pr_manager_info
= {
68 .parent
= TYPE_OBJECT
,
69 .name
= TYPE_PR_MANAGER
,
70 .class_size
= sizeof(PRManagerClass
),
72 .interfaces
= (InterfaceInfo
[]) {
73 { TYPE_USER_CREATABLE
},
78 PRManager
*pr_manager_lookup(const char *id
, Error
**errp
)
83 obj
= object_resolve_path_component(object_get_objects_root(), id
);
85 error_setg(errp
, "No persistent reservation manager with id '%s'", id
);
89 pr_mgr
= (PRManager
*)
90 object_dynamic_cast(obj
,
94 "Object with id '%s' is not a persistent reservation manager",
103 pr_manager_register_types(void)
105 type_register_static(&pr_manager_info
);
109 type_init(pr_manager_register_types
);