.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * An implementation of file copy service. |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright (C) 2014, Microsoft, Inc. |
---|
5 | 6 | * |
---|
6 | 7 | * Author : K. Y. Srinivasan <ksrinivasan@novell.com> |
---|
7 | | - * |
---|
8 | | - * This program is free software; you can redistribute it and/or modify it |
---|
9 | | - * under the terms of the GNU General Public License version 2 as published |
---|
10 | | - * by the Free Software Foundation. |
---|
11 | | - * |
---|
12 | | - * This program is distributed in the hope that it will be useful, but |
---|
13 | | - * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
14 | | - * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or |
---|
15 | | - * NON INFRINGEMENT. See the GNU General Public License for more |
---|
16 | | - * details. |
---|
17 | | - * |
---|
18 | 8 | */ |
---|
19 | 9 | |
---|
20 | 10 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
---|
.. | .. |
---|
23 | 13 | #include <linux/workqueue.h> |
---|
24 | 14 | #include <linux/hyperv.h> |
---|
25 | 15 | #include <linux/sched.h> |
---|
| 16 | +#include <asm/hyperv-tlfs.h> |
---|
26 | 17 | |
---|
27 | 18 | #include "hyperv_vmbus.h" |
---|
28 | 19 | #include "hv_utils_transport.h" |
---|
.. | .. |
---|
80 | 71 | { |
---|
81 | 72 | /* Transaction is finished, reset the state here to avoid races. */ |
---|
82 | 73 | fcopy_transaction.state = HVUTIL_READY; |
---|
83 | | - hv_fcopy_onchannelcallback(channel); |
---|
| 74 | + tasklet_schedule(&((struct vmbus_channel *)channel)->callback_event); |
---|
84 | 75 | } |
---|
85 | 76 | |
---|
86 | 77 | static void fcopy_timeout_func(struct work_struct *dummy) |
---|
.. | .. |
---|
244 | 235 | if (fcopy_transaction.state > HVUTIL_READY) |
---|
245 | 236 | return; |
---|
246 | 237 | |
---|
247 | | - vmbus_recvpacket(channel, recv_buffer, PAGE_SIZE * 2, &recvlen, |
---|
| 238 | + vmbus_recvpacket(channel, recv_buffer, HV_HYP_PAGE_SIZE * 2, &recvlen, |
---|
248 | 239 | &requestid); |
---|
249 | 240 | if (recvlen <= 0) |
---|
250 | 241 | return; |
---|
.. | .. |
---|
355 | 346 | return 0; |
---|
356 | 347 | } |
---|
357 | 348 | |
---|
| 349 | +static void hv_fcopy_cancel_work(void) |
---|
| 350 | +{ |
---|
| 351 | + cancel_delayed_work_sync(&fcopy_timeout_work); |
---|
| 352 | + cancel_work_sync(&fcopy_send_work); |
---|
| 353 | +} |
---|
| 354 | + |
---|
| 355 | +int hv_fcopy_pre_suspend(void) |
---|
| 356 | +{ |
---|
| 357 | + struct vmbus_channel *channel = fcopy_transaction.recv_channel; |
---|
| 358 | + struct hv_fcopy_hdr *fcopy_msg; |
---|
| 359 | + |
---|
| 360 | + /* |
---|
| 361 | + * Fake a CANCEL_FCOPY message for the user space daemon in case the |
---|
| 362 | + * daemon is in the middle of copying some file. It doesn't matter if |
---|
| 363 | + * there is already a message pending to be delivered to the user |
---|
| 364 | + * space since we force fcopy_transaction.state to be HVUTIL_READY, so |
---|
| 365 | + * the user space daemon's write() will fail with EINVAL (see |
---|
| 366 | + * fcopy_on_msg()), and the daemon will reset the device by closing |
---|
| 367 | + * and re-opening it. |
---|
| 368 | + */ |
---|
| 369 | + fcopy_msg = kzalloc(sizeof(*fcopy_msg), GFP_KERNEL); |
---|
| 370 | + if (!fcopy_msg) |
---|
| 371 | + return -ENOMEM; |
---|
| 372 | + |
---|
| 373 | + tasklet_disable(&channel->callback_event); |
---|
| 374 | + |
---|
| 375 | + fcopy_msg->operation = CANCEL_FCOPY; |
---|
| 376 | + |
---|
| 377 | + hv_fcopy_cancel_work(); |
---|
| 378 | + |
---|
| 379 | + /* We don't care about the return value. */ |
---|
| 380 | + hvutil_transport_send(hvt, fcopy_msg, sizeof(*fcopy_msg), NULL); |
---|
| 381 | + |
---|
| 382 | + kfree(fcopy_msg); |
---|
| 383 | + |
---|
| 384 | + fcopy_transaction.state = HVUTIL_READY; |
---|
| 385 | + |
---|
| 386 | + /* tasklet_enable() will be called in hv_fcopy_pre_resume(). */ |
---|
| 387 | + return 0; |
---|
| 388 | +} |
---|
| 389 | + |
---|
| 390 | +int hv_fcopy_pre_resume(void) |
---|
| 391 | +{ |
---|
| 392 | + struct vmbus_channel *channel = fcopy_transaction.recv_channel; |
---|
| 393 | + |
---|
| 394 | + tasklet_enable(&channel->callback_event); |
---|
| 395 | + |
---|
| 396 | + return 0; |
---|
| 397 | +} |
---|
| 398 | + |
---|
358 | 399 | void hv_fcopy_deinit(void) |
---|
359 | 400 | { |
---|
360 | 401 | fcopy_transaction.state = HVUTIL_DEVICE_DYING; |
---|
361 | | - cancel_delayed_work_sync(&fcopy_timeout_work); |
---|
| 402 | + |
---|
| 403 | + hv_fcopy_cancel_work(); |
---|
| 404 | + |
---|
362 | 405 | hvutil_transport_destroy(hvt); |
---|
363 | 406 | } |
---|