Lines Matching refs:client

29 static inline bool has_pending_request(struct acrn_ioreq_client *client)
31 return !bitmap_empty(client->ioreqs_map, ACRN_IO_REQUEST_MAX);
34 static inline bool is_destroying(struct acrn_ioreq_client *client)
36 return test_bit(ACRN_IOREQ_CLIENT_DESTROYING, &client->flags);
73 static int acrn_ioreq_complete_request(struct acrn_ioreq_client *client,
79 if (vcpu >= client->vm->vcpu_num)
82 clear_bit(vcpu, client->ioreqs_map);
84 acrn_req = (struct acrn_io_request *)client->vm->ioreq_buf;
88 ret = ioreq_complete_request(client->vm, vcpu, acrn_req);
107 * acrn_ioreq_range_add() - Add an iorange monitored by an ioreq client
108 * @client: The ioreq client
115 int acrn_ioreq_range_add(struct acrn_ioreq_client *client,
134 write_lock_bh(&client->range_lock);
135 list_add(&range->list, &client->range_list);
136 write_unlock_bh(&client->range_lock);
142 * acrn_ioreq_range_del() - Del an iorange monitored by an ioreq client
143 * @client: The ioreq client
148 void acrn_ioreq_range_del(struct acrn_ioreq_client *client,
153 write_lock_bh(&client->range_lock);
154 list_for_each_entry(range, &client->range_list, list) {
163 write_unlock_bh(&client->range_lock);
167 * ioreq_task() is the execution entity of handler thread of an I/O client.
168 * The handler callback of the I/O client is called within the handler thread.
172 struct acrn_ioreq_client *client = data;
187 ioreqs_map = client->ioreqs_map;
189 acrn_ioreq_client_wait(client);
190 while (has_pending_request(client)) {
191 vcpu = find_first_bit(ioreqs_map, client->vm->vcpu_num);
192 req = client->vm->ioreq_buf->req_slot + vcpu;
193 ret = client->handler(client, req);
199 acrn_ioreq_complete_request(client, vcpu, req);
208 * I/O requests if there are any. For the default I/O client, it is safe to
214 struct acrn_ioreq_client *client;
231 list_for_each_entry(client, &vm->ioreq_clients, list) {
232 has_pending = has_pending_request(client);
243 "%s cannot flush pending request!\n", client->name);
245 /* Clear all ioreqs belonging to the default client */
247 client = vm->default_client;
248 if (client) {
249 for_each_set_bit(vcpu, client->ioreqs_map, ACRN_IO_REQUEST_MAX)
250 acrn_ioreq_complete_request(client, vcpu, NULL);
258 int acrn_ioreq_client_wait(struct acrn_ioreq_client *client)
260 if (client->is_default) {
262 * In the default client, a user space thread waits on the
264 * space the client is going to be destroyed.
266 wait_event_interruptible(client->wq,
267 has_pending_request(client) ||
268 is_destroying(client));
269 if (is_destroying(client))
272 wait_event_interruptible(client->wq,
273 has_pending_request(client) ||
384 struct acrn_ioreq_client *client, *found = NULL;
389 list_for_each_entry(client, &vm->ioreq_clients, list) {
390 read_lock_bh(&client->range_lock);
391 list_for_each_entry(range, &client->range_list, list) {
393 found = client;
397 read_unlock_bh(&client->range_lock);
405 * acrn_ioreq_client_create() - Create an ioreq client
406 * @vm: The VM that this client belongs to
407 * @handler: The ioreq_handler of ioreq client acrn_hsm will create a kernel
410 * @is_default: If it is the default client
411 * @name: The name of ioreq client
420 struct acrn_ioreq_client *client;
424 "Cannot create non-default client w/o handler!\n");
427 client = kzalloc(sizeof(*client), GFP_KERNEL);
428 if (!client)
431 client->handler = handler;
432 client->vm = vm;
433 client->priv = priv;
434 client->is_default = is_default;
436 strscpy(client->name, name);
437 rwlock_init(&client->range_lock);
438 INIT_LIST_HEAD(&client->range_list);
439 init_waitqueue_head(&client->wq);
441 if (client->handler) {
442 client->thread = kthread_run(ioreq_task, client, "VM%u-%s",
443 client->vm->vmid, client->name);
444 if (IS_ERR(client->thread)) {
445 kfree(client);
452 vm->default_client = client;
454 list_add(&client->list, &vm->ioreq_clients);
457 dev_dbg(acrn_dev.this_device, "Created ioreq client %s.\n", name);
458 return client;
462 * acrn_ioreq_client_destroy() - Destroy an ioreq client
463 * @client: The ioreq client
465 void acrn_ioreq_client_destroy(struct acrn_ioreq_client *client)
468 struct acrn_vm *vm = client->vm;
471 "Destroy ioreq client %s.\n", client->name);
473 set_bit(ACRN_IOREQ_CLIENT_DESTROYING, &client->flags);
474 if (client->is_default)
475 wake_up_interruptible(&client->wq);
477 kthread_stop(client->thread);
480 if (client->is_default)
483 list_del(&client->list);
486 write_lock_bh(&client->range_lock);
487 list_for_each_entry_safe(range, next, &client->range_list, list) {
491 write_unlock_bh(&client->range_lock);
492 kfree(client);
499 struct acrn_ioreq_client *client;
518 client = find_ioreq_client(vm, req);
519 if (!client) {
521 "Failed to find ioreq client!\n");
525 if (!client->is_default)
535 set_bit(i, client->ioreqs_map);
536 wake_up_interruptible(&client->wq);
638 struct acrn_ioreq_client *client, *next;
643 list_for_each_entry_safe(client, next, &vm->ioreq_clients, list)
644 acrn_ioreq_client_destroy(client);