static void vss_handle_request(struct work_struct *dummy) { switch (vss_transaction.msg->vss_hdr.operation) { /* * Initiate a "freeze/thaw" operation in the guest. * We respond to the host once the operation is complete. * * We send the message to the user space daemon and the operation is * performed in the daemon. */ case VSS_OP_THAW: case VSS_OP_FREEZE: case VSS_OP_HOT_BACKUP: if (vss_transaction.state < HVUTIL_READY) { /* Userspace is not registered yet */ pr_debug("VSS: Not ready for request.\n"); vss_respond_to_host(HV_E_FAIL); return; } pr_debug("VSS: Received request for op code: %d\n", vss_transaction.msg->vss_hdr.operation); vss_transaction.state = HVUTIL_HOSTMSG_RECEIVED; vss_send_op(); return; case VSS_OP_GET_DM_INFO: vss_transaction.msg->dm_info.flags = 0; break; default: break; } vss_respond_to_host(0); hv_poll_channel(vss_transaction.recv_channel, vss_poll_wrapper); }
static void vss_send_op(struct work_struct *dummy) { int op = vss_transaction.msg->vss_hdr.operation; int rc; struct cn_msg *msg; struct hv_vss_msg *vss_msg; msg = kzalloc(sizeof(*msg) + sizeof(*vss_msg), GFP_ATOMIC); if (!msg) return; vss_msg = (struct hv_vss_msg *)msg->data; msg->id.idx = CN_VSS_IDX; msg->id.val = CN_VSS_VAL; vss_msg->vss_hdr.operation = op; msg->len = sizeof(struct hv_vss_msg); rc = cn_netlink_send(msg, 0, 0, GFP_ATOMIC); if (rc) { pr_warn("VSS: failed to communicate to the daemon: %d\n", rc); if (cancel_delayed_work_sync(&vss_timeout_work)) vss_respond_to_host(HV_E_FAIL); } kfree(msg); return; }
static void vss_send_op(struct work_struct *dummy) { int op = vss_transaction.msg->vss_hdr.operation; int rc; struct hv_vss_msg *vss_msg; /* The transaction state is wrong. */ if (vss_transaction.state != HVUTIL_HOSTMSG_RECEIVED) return; vss_msg = kzalloc(sizeof(*vss_msg), GFP_KERNEL); if (!vss_msg) return; vss_msg->vss_hdr.operation = op; vss_transaction.state = HVUTIL_USERSPACE_REQ; rc = hvutil_transport_send(hvt, vss_msg, sizeof(*vss_msg)); if (rc) { pr_warn("VSS: failed to communicate to the daemon: %d\n", rc); if (cancel_delayed_work_sync(&vss_timeout_work)) { vss_respond_to_host(HV_E_FAIL); vss_transaction.state = HVUTIL_READY; } } kfree(vss_msg); return; }
static int vss_on_msg(void *msg, int len) { struct hv_vss_msg *vss_msg = (struct hv_vss_msg *)msg; if (len != sizeof(*vss_msg)) return -EINVAL; if (vss_msg->vss_hdr.operation == VSS_OP_REGISTER || vss_msg->vss_hdr.operation == VSS_OP_REGISTER1) { /* * Don't process registration messages if we're in the middle * of a transaction processing. */ if (vss_transaction.state > HVUTIL_READY) return -EINVAL; return vss_handle_handshake(vss_msg); } else if (vss_transaction.state == HVUTIL_USERSPACE_REQ) { vss_transaction.state = HVUTIL_USERSPACE_RECV; if (cancel_delayed_work_sync(&vss_timeout_work)) { vss_respond_to_host(vss_msg->error); /* Transaction is finished, reset the state. */ hv_poll_channel(vss_transaction.recv_channel, vss_poll_wrapper); } } else { /* This is a spurious call! */ pr_warn("VSS: Transaction not active\n"); return -EINVAL; } return 0; }
static void vss_send_op(void) { int op = vss_transaction.msg->vss_hdr.operation; int rc; struct hv_vss_msg *vss_msg; /* The transaction state is wrong. */ if (vss_transaction.state != HVUTIL_HOSTMSG_RECEIVED) { pr_debug("VSS: Unexpected attempt to send to daemon\n"); return; } vss_msg = kzalloc(sizeof(*vss_msg), GFP_KERNEL); if (!vss_msg) return; vss_msg->vss_hdr.operation = op; vss_transaction.state = HVUTIL_USERSPACE_REQ; schedule_delayed_work(&vss_timeout_work, op == VSS_OP_FREEZE ? VSS_FREEZE_TIMEOUT * HZ : HV_UTIL_TIMEOUT * HZ); rc = hvutil_transport_send(hvt, vss_msg, sizeof(*vss_msg), NULL); if (rc) { pr_warn("VSS: failed to communicate to the daemon: %d\n", rc); if (cancel_delayed_work_sync(&vss_timeout_work)) { vss_respond_to_host(HV_E_FAIL); vss_transaction.state = HVUTIL_READY; } } kfree(vss_msg); }
static void vss_on_reset(void) { if (cancel_delayed_work_sync(&vss_timeout_work)) vss_respond_to_host(HV_E_FAIL); vss_transaction.state = HVUTIL_DEVICE_INIT; complete(&release_event); }
static void vss_timeout_func(struct work_struct *dummy) { /* * Timeout waiting for userspace component to reply happened. */ pr_warn("VSS: timeout waiting for daemon to reply\n"); vss_respond_to_host(HV_E_FAIL); }
static void vss_timeout_func(struct work_struct *dummy) { /* * Timeout waiting for userspace component to reply happened. */ pr_warn("VSS: timeout waiting for daemon to reply\n"); vss_respond_to_host(HV_E_FAIL); hv_poll_channel(vss_transaction.recv_channel, vss_poll_wrapper); }
static void vss_timeout_func(struct work_struct *dummy) { /* * Timeout waiting for userspace component to reply happened. */ pr_warn("VSS: timeout waiting for daemon to reply\n"); vss_respond_to_host(HV_E_FAIL); /* Transaction is finished, reset the state. */ if (vss_transaction.state > HVUTIL_READY) vss_transaction.state = HVUTIL_READY; hv_poll_channel(vss_transaction.vss_context, hv_vss_onchannelcallback); }
static void vss_cn_callback(struct cn_msg *msg, struct netlink_skb_parms *nsp) { struct hv_vss_msg *vss_msg; vss_msg = (struct hv_vss_msg *)msg->data; if (vss_msg->vss_hdr.operation == VSS_OP_REGISTER) { pr_info("VSS daemon registered\n"); vss_transaction.active = false; if (vss_transaction.recv_channel != NULL) hv_vss_onchannelcallback(vss_transaction.recv_channel); return; } vss_respond_to_host(vss_msg->error); }
static int vss_on_msg(void *msg, int len) { struct hv_vss_msg *vss_msg = (struct hv_vss_msg *)msg; if (len != sizeof(*vss_msg)) { pr_debug("VSS: Message size does not match length\n"); return -EINVAL; } if (vss_msg->vss_hdr.operation == VSS_OP_REGISTER || vss_msg->vss_hdr.operation == VSS_OP_REGISTER1) { /* * Don't process registration messages if we're in the middle * of a transaction processing. */ if (vss_transaction.state > HVUTIL_READY) { pr_debug("VSS: Got unexpected registration request\n"); return -EINVAL; } return vss_handle_handshake(vss_msg); } else if (vss_transaction.state == HVUTIL_USERSPACE_REQ) { vss_transaction.state = HVUTIL_USERSPACE_RECV; if (vss_msg->vss_hdr.operation == VSS_OP_HOT_BACKUP) vss_transaction.msg->vss_cf.flags = VSS_HBU_NO_AUTO_RECOVERY; if (cancel_delayed_work_sync(&vss_timeout_work)) { vss_respond_to_host(vss_msg->error); /* Transaction is finished, reset the state. */ hv_poll_channel(vss_transaction.recv_channel, vss_poll_wrapper); } } else { /* This is a spurious call! */ pr_debug("VSS: Transaction not active\n"); return -EINVAL; } return 0; }
void hv_vss_onchannelcallback(void *context) { struct vmbus_channel *channel = context; u32 recvlen; u64 requestid; struct hv_vss_msg *vss_msg; struct icmsg_hdr *icmsghdrp; struct icmsg_negotiate *negop = NULL; if (vss_transaction.active) { /* * We will defer processing this callback once * the current transaction is complete. */ vss_transaction.recv_channel = channel; return; } vmbus_recvpacket(channel, recv_buffer, PAGE_SIZE * 2, &recvlen, &requestid); if (recvlen > 0) { icmsghdrp = (struct icmsg_hdr *)&recv_buffer[ sizeof(struct vmbuspipe_hdr)]; if (icmsghdrp->icmsgtype == ICMSGTYPE_NEGOTIATE) { vmbus_prep_negotiate_resp(icmsghdrp, negop, recv_buffer, UTIL_FW_VERSION, VSS_VERSION); } else { vss_msg = (struct hv_vss_msg *)&recv_buffer[ sizeof(struct vmbuspipe_hdr) + sizeof(struct icmsg_hdr)]; /* * Stash away this global state for completing the * transaction; note transactions are serialized. */ vss_transaction.recv_len = recvlen; vss_transaction.recv_channel = channel; vss_transaction.recv_req_id = requestid; vss_transaction.active = true; vss_transaction.msg = (struct hv_vss_msg *)vss_msg; switch (vss_msg->vss_hdr.operation) { /* * Initiate a "freeze/thaw" * operation in the guest. * We respond to the host once * the operation is complete. * * We send the message to the * user space daemon and the * operation is performed in * the daemon. */ case VSS_OP_FREEZE: case VSS_OP_THAW: schedule_work(&vss_send_op_work); schedule_delayed_work(&vss_timeout_work, VSS_USERSPACE_TIMEOUT); return; case VSS_OP_HOT_BACKUP: vss_msg->vss_cf.flags = VSS_HBU_NO_AUTO_RECOVERY; vss_respond_to_host(0); return; case VSS_OP_GET_DM_INFO: vss_msg->dm_info.flags = 0; vss_respond_to_host(0); return; default: vss_respond_to_host(0); return; } } icmsghdrp->icflags = ICMSGHDRFLAG_TRANSACTION | ICMSGHDRFLAG_RESPONSE; vmbus_sendpacket(channel, recv_buffer, recvlen, requestid, VM_PKT_DATA_INBAND, 0); } }