Lines Matching +full:post +full:- +full:processing

11  * See the COPYING file in the top-level directory.
21 #include "qemu/help-texts.h"
22 #include "qobject/json-parser.h"
25 #include "guest-agent-core.h"
26 #include "qga-qapi-init-commands.h"
33 #include "qemu-version.h"
37 #include "qga/service-win32.h"
38 #include "qga/vss-win32.h"
40 #include "commands-common.h"
46 #define QGA_VIRTIO_PATH_DEFAULT "/dev/virtio-ports/org.qemu.guest_agent.0"
52 #define QGA_STATE_RELATIVE_DIR "qemu-ga"
56 #define QGA_FSFREEZE_HOOK_DEFAULT CONFIG_QEMU_CONFDIR "/fsfreeze-hook"
59 #define QGA_CONF_DEFAULT CONFIG_QEMU_CONFDIR G_DIR_SEPARATOR_S "qemu-ga.conf"
137 "guest-ping",
138 "guest-info",
139 "guest-sync",
140 "guest-sync-delimited",
141 "guest-fsfreeze-status",
142 "guest-fsfreeze-thaw",
163 dfl_pathnames.pidfile = g_build_filename(state, QGA_STATE_RELATIVE_DIR, "qemu-ga.pid", NULL); in init_dfl_pathnames()
215 if (ret == -1) { in register_signal_handlers()
219 if (ret == -1) { in register_signal_handlers()
232 /* TODO: use this in place of all post-fork() fclose(std*) callers */
258 "Usage: %s [-m <method> -p <path>] [<options>]\n" in usage()
262 " -c, --config=PATH configuration file path (default is\n" in usage()
263 " %s/qemu-ga.conf\n" in usage()
265 " -m, --method transport method: one of unix-listen, virtio-serial,\n" in usage()
266 " isa-serial, or vsock-listen (virtio-serial is the default)\n" in usage()
267 " -p, --path device/socket path (the default for virtio-serial is:\n" in usage()
269 " the default for isa-serial is:\n" in usage()
271 " Socket addresses for vsock-listen are written as\n" in usage()
273 " -l, --logfile set logfile path, logs to stderr by default\n" in usage()
274 " -f, --pidfile specify pidfile (default is %s)\n" in usage()
276 " -F, --fsfreeze-hook\n" in usage()
281 " If using -F with an argument, do not follow -F with a\n" in usage()
283 " (for example: -F/var/run/fsfreezehook.sh)\n" in usage()
285 " -t, --statedir specify dir to store state information (absolute paths\n" in usage()
287 " -v, --verbose log extra debugging information\n" in usage()
288 " -V, --version print version information and exit\n" in usage()
289 " -d, --daemonize become a daemon\n" in usage()
291 " -s, --service service commands: install, uninstall, vss-install, vss-uninstall\n" in usage()
293 " -b, --block-rpcs comma-separated list of RPCs to disable (no spaces,\n" in usage()
294 " use \"--block-rpcs=help\" to list available RPCs)\n" in usage()
295 " -a, --allow-rpcs comma-separated list of RPCs to enable (no spaces,\n" in usage()
296 " use \"--allow-rpcs=help\" to list available RPCs)\n" in usage()
297 " -D, --dump-conf dump a qemu-ga config file based on current config\n" in usage()
298 " options / command-line parameters to stdout\n" in usage()
299 " -r, --retry-path attempt re-opening path if it's unavailable or closed\n" in usage()
301 " (virtio-serial driver re-install, serial device hot\n" in usage()
303 " -h, --help display this help and exit\n" in usage()
336 return s->logging_enabled; in ga_logging_enabled()
341 s->logging_enabled = false; in ga_disable_logging()
346 s->logging_enabled = true; in ga_enable_logging()
396 ReportEvent(s->event_log, glib_log_level_to_system(level), in ga_log()
399 } else if (level & s->log_level) { in ga_log()
402 fprintf(s->log_file, "%s: %s: %s\n", nowstr, level_str, msg); in ga_log()
403 fflush(s->log_file); in ga_log()
409 s->delimit_response = true; in ga_set_response_delimited()
433 GAConfig *config = state->config; in ga_command_is_allowed()
438 if (config->allowedrpcs) { in ga_command_is_allowed()
440 * If an allow-list is given, this changes the fallback in ga_command_is_allowed()
445 if (g_list_find_custom(config->allowedrpcs, name, ga_strcmp) != NULL) { in ga_command_is_allowed()
454 if (config->blockedrpcs) { in ga_command_is_allowed()
455 if (g_list_find_custom(config->blockedrpcs, name, ga_strcmp) != NULL) { in ga_command_is_allowed()
464 if (state->frozen) { in ga_command_is_allowed()
506 if (fd == -1) { in ga_create_file()
517 if (ret == -1) { in ga_delete_file()
527 return s->frozen; in ga_is_frozen()
536 s->frozen = true; in ga_set_frozen()
537 if (!ga_create_file(s->state_filepath_isfrozen)) { in ga_set_frozen()
539 s->state_filepath_isfrozen); in ga_set_frozen()
554 if (s->deferred_options.log_filepath) { in ga_unset_frozen()
555 s->log_file = ga_open_logfile(s->deferred_options.log_filepath); in ga_unset_frozen()
556 if (!s->log_file) { in ga_unset_frozen()
557 s->log_file = stderr; in ga_unset_frozen()
559 s->deferred_options.log_filepath = NULL; in ga_unset_frozen()
562 g_warning("logging re-enabled due to filesystem unfreeze"); in ga_unset_frozen()
563 if (s->deferred_options.pid_filepath) { in ga_unset_frozen()
566 if (!qemu_write_pidfile(s->deferred_options.pid_filepath, &err)) { in ga_unset_frozen()
570 s->deferred_options.pid_filepath = NULL; in ga_unset_frozen()
573 /* enable all disabled, non-blocked and allowed commands */ in ga_unset_frozen()
574 s->frozen = false; in ga_unset_frozen()
575 if (!ga_delete_file(s->state_filepath_isfrozen)) { in ga_unset_frozen()
577 s->state_filepath_isfrozen); in ga_unset_frozen()
585 return s->fsfreeze_hook; in ga_fsfreeze_hook()
592 s->load_avg_wait_handle = wait_handle; in ga_set_load_avg_wait_handle()
596 s->load_avg_event = event; in ga_set_load_avg_event()
600 s->load_avg_pdh_query = query; in ga_set_load_avg_pdh_query()
604 return s->load_avg_pdh_query; in ga_get_load_avg_pdh_query()
659 g_assert(s->channel); in send_response()
667 return -EINVAL; in send_response()
670 if (s->delimit_response) { in send_response()
671 s->delimit_response = false; in send_response()
676 status = ga_channel_write_all(s->channel, response->str, response->len); in send_response()
679 return -EIO; in send_response()
699 g_debug("processing command"); in process_event()
705 g_warning("error sending error response: %s", strerror(-ret)); in process_event()
717 GIOStatus status = ga_channel_read(s->channel, buf, QGA_READ_COUNT_DEFAULT, &count); in channel_event_cb()
726 json_message_parser_feed(&s->parser, (char *)buf, (int)count); in channel_event_cb()
730 if (!s->virtio) { in channel_event_cb()
736 * host-side chardev. sleep a bit to mitigate this in channel_event_cb()
738 if (s->virtio) { in channel_event_cb()
754 if (strcmp(method, "virtio-serial") == 0) { in channel_init()
755 s->virtio = true; /* virtio requires special handling in some cases */ in channel_init()
757 } else if (strcmp(method, "isa-serial") == 0) { in channel_init()
759 } else if (strcmp(method, "unix-listen") == 0) { in channel_init()
761 } else if (strcmp(method, "vsock-listen") == 0) { in channel_init()
768 s->channel = ga_channel_new(channel_method, path, listen_fd, in channel_init()
770 if (!s->channel) { in channel_init()
784 if (broadcast_header->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE) { in handle_serial_device_events()
788 /* Start QEMU-ga's service */ in handle_serial_device_events()
789 if (!SetEvent(ga_state->wakeup_event)) { in handle_serial_device_events()
797 /* Stop QEMU-ga's service */ in handle_serial_device_events()
798 if (!ResetEvent(ga_state->wakeup_event)) { in handle_serial_device_events()
813 GAService *service = &ga_state->service; in service_ctrl_handler()
819 SetEvent(ga_state->wakeup_event); in service_ctrl_handler()
820 service->status.dwCurrentState = SERVICE_STOP_PENDING; in service_ctrl_handler()
821 SetServiceStatus(service->status_handle, &service->status); in service_ctrl_handler()
835 GAService *service = &ga_state->service; in service_main()
837 service->status_handle = RegisterServiceCtrlHandlerEx(QGA_SERVICE_NAME, in service_main()
840 if (service->status_handle == 0) { in service_main()
845 service->status.dwServiceType = SERVICE_WIN32; in service_main()
846 service->status.dwCurrentState = SERVICE_RUNNING; in service_main()
847 service->status.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN; in service_main()
848 service->status.dwWin32ExitCode = NO_ERROR; in service_main()
849 service->status.dwServiceSpecificExitCode = NO_ERROR; in service_main()
850 service->status.dwCheckPoint = 0; in service_main()
851 service->status.dwWaitHint = 0; in service_main()
858 service->device_notification_handle = in service_main()
859 RegisterDeviceNotification(service->status_handle, in service_main()
861 if (!service->device_notification_handle) { in service_main()
865 SetServiceStatus(service->status_handle, &service->status); in service_main()
869 UnregisterDeviceNotification(service->device_notification_handle); in service_main()
870 service->status.dwCurrentState = SERVICE_STOPPED; in service_main()
871 SetServiceStatus(service->status_handle, &service->status); in service_main()
878 pstate->fd_counter = QGA_PSTATE_DEFAULT_FD_COUNTER; in set_persistent_state_defaults()
889 * values. so load them now, and ignore any errors in accessing key-value in persistent_state_from_keyfile()
895 pstate->fd_counter = in persistent_state_from_keyfile()
906 g_key_file_set_integer(keyfile, "global", "fd_counter", pstate->fd_counter); in persistent_state_to_keyfile()
924 gerr->message); in write_persistent_state()
932 path, gerr->message); in write_persistent_state()
958 if (stat(path, &st) == -1) { in read_persistent_state()
977 * while qemu-ga thought the filesystem was frozen, or in read_persistent_state()
1000 path, gerr->message); in read_persistent_state()
1022 g_assert(s->pstate_filepath); in ga_get_fd_handle()
1030 handle = s->pstate.fd_counter++; in ga_get_fd_handle()
1032 /* This should never happen on a reasonable timeframe, as guest-file-open in ga_get_fd_handle()
1034 if (s->pstate.fd_counter == INT64_MAX) { in ga_get_fd_handle()
1038 if (!write_persistent_state(&s->pstate, s->pstate_filepath)) { in ga_get_fd_handle()
1040 return -1; in ga_get_fd_handle()
1057 strv = g_strsplit(str, delim, -1); in split_list()
1077 config->daemonize = in config_load()
1081 config->method = in config_load()
1085 config->channel_path = in config_load()
1089 config->log_filepath = in config_load()
1093 config->pid_filepath = in config_load()
1097 if (g_key_file_has_key(keyfile, "general", "fsfreeze-hook", NULL)) { in config_load()
1098 config->fsfreeze_hook = in config_load()
1100 "general", "fsfreeze-hook", &gerr); in config_load()
1104 config->state_dir = in config_load()
1110 config->log_level = G_LOG_LEVEL_MASK; in config_load()
1112 if (g_key_file_has_key(keyfile, "general", "retry-path", NULL)) { in config_load()
1113 config->retry_path = in config_load()
1114 g_key_file_get_boolean(keyfile, "general", "retry-path", &gerr); in config_load()
1117 if (g_key_file_has_key(keyfile, "general", "block-rpcs", NULL)) { in config_load()
1118 config->bliststr = in config_load()
1119 g_key_file_get_string(keyfile, "general", "block-rpcs", &gerr); in config_load()
1120 config->blockedrpcs = g_list_concat(config->blockedrpcs, in config_load()
1121 split_list(config->bliststr, ",")); in config_load()
1123 if (g_key_file_has_key(keyfile, "general", "allow-rpcs", NULL)) { in config_load()
1124 config->aliststr = in config_load()
1125 g_key_file_get_string(keyfile, "general", "allow-rpcs", &gerr); in config_load()
1126 config->allowedrpcs = g_list_concat(config->allowedrpcs, in config_load()
1127 split_list(config->aliststr, ",")); in config_load()
1133 !(gerr->domain == G_FILE_ERROR && gerr->code == G_FILE_ERROR_NOENT))) { in config_load()
1135 confpath, gerr->message); in config_load()
1146 str = g_string_append(str, (gchar *)list->data); in list_join()
1165 g_key_file_set_boolean(keyfile, "general", "daemon", config->daemonize); in config_dump()
1166 g_key_file_set_string(keyfile, "general", "method", config->method); in config_dump()
1167 if (config->channel_path) { in config_dump()
1168 g_key_file_set_string(keyfile, "general", "path", config->channel_path); in config_dump()
1170 if (config->log_filepath) { in config_dump()
1172 config->log_filepath); in config_dump()
1174 g_key_file_set_string(keyfile, "general", "pidfile", config->pid_filepath); in config_dump()
1176 if (config->fsfreeze_hook) { in config_dump()
1177 g_key_file_set_string(keyfile, "general", "fsfreeze-hook", in config_dump()
1178 config->fsfreeze_hook); in config_dump()
1181 g_key_file_set_string(keyfile, "general", "statedir", config->state_dir); in config_dump()
1183 config->log_level == G_LOG_LEVEL_MASK); in config_dump()
1184 g_key_file_set_boolean(keyfile, "general", "retry-path", in config_dump()
1185 config->retry_path); in config_dump()
1186 tmp = list_join(config->blockedrpcs, ','); in config_dump()
1187 g_key_file_set_string(keyfile, "general", "block-rpcs", tmp); in config_dump()
1189 tmp = list_join(config->allowedrpcs, ','); in config_dump()
1190 g_key_file_set_string(keyfile, "general", "allow-rpcs", tmp); in config_dump()
1195 g_critical("Failed to dump keyfile: %s", error->message); in config_dump()
1213 { "dump-conf", 0, NULL, 'D' }, in config_parse()
1217 { "fsfreeze-hook", 2, NULL, 'F' }, in config_parse()
1223 { "block-rpcs", 1, NULL, 'b' }, in config_parse()
1224 { "allow-rpcs", 1, NULL, 'a' }, in config_parse()
1229 { "retry-path", 0, NULL, 'r' }, in config_parse()
1236 while ((ch = getopt_long(argc, argv, sopt, lopt, NULL)) != -1) { in config_parse()
1253 while ((ch = getopt_long(argc, argv, sopt, lopt, &opt_ind)) != -1) { in config_parse()
1256 g_free(config->method); in config_parse()
1257 config->method = g_strdup(optarg); in config_parse()
1260 g_free(config->channel_path); in config_parse()
1261 config->channel_path = g_strdup(optarg); in config_parse()
1264 g_free(config->log_filepath); in config_parse()
1265 config->log_filepath = g_strdup(optarg); in config_parse()
1268 g_free(config->pid_filepath); in config_parse()
1269 config->pid_filepath = g_strdup(optarg); in config_parse()
1273 g_free(config->fsfreeze_hook); in config_parse()
1274 … config->fsfreeze_hook = optarg ? g_strdup(optarg) : get_relocated_path(QGA_FSFREEZE_HOOK_DEFAULT); in config_parse()
1278 g_free(config->state_dir); in config_parse()
1279 config->state_dir = g_strdup(optarg); in config_parse()
1283 config->log_level = G_LOG_LEVEL_MASK; in config_parse()
1289 config->daemonize = 1; in config_parse()
1292 config->dumpconf = 1; in config_parse()
1295 config->retry_path = true; in config_parse()
1302 config->blockedrpcs = g_list_concat(config->blockedrpcs, in config_parse()
1311 config->allowedrpcs = g_list_concat(config->allowedrpcs, in config_parse()
1317 config->service = optarg; in config_parse()
1318 if (strcmp(config->service, "install") == 0) { in config_parse()
1322 if (ga_install_service(config->channel_path, in config_parse()
1323 config->log_filepath, config->state_dir)) { in config_parse()
1327 } else if (strcmp(config->service, "uninstall") == 0) { in config_parse()
1330 } else if (strcmp(config->service, "vss-install") == 0) { in config_parse()
1335 } else if (strcmp(config->service, "vss-uninstall") == 0) { in config_parse()
1348 g_print("Unknown option, try '%s --help' for more information.\n", in config_parse()
1357 g_free(config->method); in config_free()
1358 g_free(config->log_filepath); in config_free()
1359 g_free(config->pid_filepath); in config_free()
1360 g_free(config->state_dir); in config_free()
1361 g_free(config->channel_path); in config_free()
1362 g_free(config->bliststr); in config_free()
1363 g_free(config->aliststr); in config_free()
1365 g_free(config->fsfreeze_hook); in config_free()
1367 g_list_free_full(config->blockedrpcs, g_free); in config_free()
1368 g_list_free_full(config->allowedrpcs, g_free); in config_free()
1375 /* check if a previous instance of qemu-ga exited with filesystems' state in check_is_frozen()
1376 * marked as frozen. this could be a stale value (a non-qemu-ga process in check_is_frozen()
1378 * unneeded unfreeze than to risk hanging on start-up in check_is_frozen()
1381 if (stat(s->state_filepath_isfrozen, &st) == -1) { in check_is_frozen()
1389 s->state_filepath_isfrozen, strerror(errno)); in check_is_frozen()
1395 " disabling non-fsfreeze-safe commands until" in check_is_frozen()
1396 " guest-fsfreeze-thaw is issued, or filesystems are" in check_is_frozen()
1398 s->state_filepath_isfrozen); in check_is_frozen()
1411 s->log_level = config->log_level; in initialize_agent()
1412 s->log_file = stderr; in initialize_agent()
1414 s->fsfreeze_hook = config->fsfreeze_hook; in initialize_agent()
1416 s->pstate_filepath = g_strdup_printf("%s/qga.state", config->state_dir); in initialize_agent()
1417 s->state_filepath_isfrozen = g_strdup_printf("%s/qga.state.isfrozen", in initialize_agent()
1418 config->state_dir); in initialize_agent()
1419 s->frozen = check_is_frozen(s); in initialize_agent()
1428 s->load_avg_wait_handle = INVALID_HANDLE_VALUE; in initialize_agent()
1429 s->load_avg_event = INVALID_HANDLE_VALUE; in initialize_agent()
1430 s->load_avg_pdh_query = NULL; in initialize_agent()
1432 s->event_log = RegisterEventSource(NULL, "qemu-ga"); in initialize_agent()
1433 if (!s->event_log) { in initialize_agent()
1445 if (g_mkdir_with_parents(config->state_dir, S_IRWXU) == -1) { in initialize_agent()
1447 " '%s': %s", config->state_dir, strerror(errno)); in initialize_agent()
1457 if (config->daemonize) { in initialize_agent()
1459 s->deferred_options.pid_filepath = config->pid_filepath; in initialize_agent()
1461 if (config->log_filepath) { in initialize_agent()
1463 s->deferred_options.log_filepath = config->log_filepath; in initialize_agent()
1467 if (config->log_filepath) { in initialize_agent()
1468 FILE *log_file = ga_open_logfile(config->log_filepath); in initialize_agent()
1474 s->log_file = log_file; in initialize_agent()
1479 if (!read_persistent_state(&s->pstate, in initialize_agent()
1480 s->pstate_filepath, in initialize_agent()
1486 s->command_state = ga_command_state_new(); in initialize_agent()
1487 ga_command_state_init(s, s->command_state); in initialize_agent()
1488 ga_command_state_init_all(s->command_state); in initialize_agent()
1489 json_message_parser_init(&s->parser, process_event, s, NULL); in initialize_agent()
1498 s->main_loop = g_main_loop_new(NULL, false); in initialize_agent()
1500 s->config = config; in initialize_agent()
1501 s->socket_activation = socket_activation; in initialize_agent()
1504 s->wakeup_event = CreateEvent(NULL, TRUE, FALSE, TEXT("WakeUp")); in initialize_agent()
1505 if (s->wakeup_event == NULL) { in initialize_agent()
1513 if (!channel_init(s, s->config->method, s->config->channel_path, in initialize_agent()
1514 s->socket_activation ? FIRST_SOCKET_ACTIVATION_FD : -1)) { in initialize_agent()
1519 if (config->daemonize) { in initialize_agent()
1523 become_daemon(config->pid_filepath); in initialize_agent()
1534 CloseHandle(s->wakeup_event); in cleanup_agent()
1535 CloseHandle(s->event_log); in cleanup_agent()
1537 if (s->load_avg_wait_handle != INVALID_HANDLE_VALUE) { in cleanup_agent()
1538 UnregisterWait(s->load_avg_wait_handle); in cleanup_agent()
1541 if (s->load_avg_event != INVALID_HANDLE_VALUE) { in cleanup_agent()
1542 CloseHandle(s->load_avg_event); in cleanup_agent()
1545 if (s->load_avg_pdh_query) { in cleanup_agent()
1546 PdhCloseQuery(s->load_avg_pdh_query); in cleanup_agent()
1549 if (s->command_state) { in cleanup_agent()
1550 ga_command_state_cleanup_all(s->command_state); in cleanup_agent()
1551 ga_command_state_free(s->command_state); in cleanup_agent()
1552 json_message_parser_destroy(&s->parser); in cleanup_agent()
1554 g_free(s->pstate_filepath); in cleanup_agent()
1555 g_free(s->state_filepath_isfrozen); in cleanup_agent()
1556 if (s->main_loop) { in cleanup_agent()
1557 g_main_loop_unref(s->main_loop); in cleanup_agent()
1565 if (!s->channel && in run_agent_once()
1566 channel_init(s, s->config->method, s->config->channel_path, in run_agent_once()
1567 s->socket_activation ? FIRST_SOCKET_ACTIVATION_FD : -1)) { in run_agent_once()
1572 g_main_loop_run(s->main_loop); in run_agent_once()
1574 if (s->channel) { in run_agent_once()
1575 ga_channel_free(s->channel); in run_agent_once()
1576 s->channel = NULL; in run_agent_once()
1590 dwWaitResult = WaitForSingleObject(s->wakeup_event, INFINITE); in wait_for_channel_availability()
1607 s->force_exit = false; in run_agent()
1611 if (s->config->retry_path && !s->force_exit) { in run_agent()
1615 } while (s->config->retry_path && !s->force_exit); in run_agent()
1622 if (!s->force_exit) { in stop_agent()
1623 s->force_exit = requested; in stop_agent()
1626 if (g_main_loop_is_running(s->main_loop)) { in stop_agent()
1627 g_main_loop_quit(s->main_loop); in stop_agent()
1638 config->log_level = G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL; in main()
1646 if (config->pid_filepath == NULL) { in main()
1647 config->pid_filepath = g_strdup(dfl_pathnames.pidfile); in main()
1650 if (config->state_dir == NULL) { in main()
1651 config->state_dir = g_strdup(dfl_pathnames.state_dir); in main()
1654 if (config->method == NULL) { in main()
1655 config->method = g_strdup("virtio-serial"); in main()
1660 g_critical("qemu-ga only supports listening on one socket"); in main()
1666 g_free(config->method); in main()
1667 g_free(config->channel_path); in main()
1668 config->method = NULL; in main()
1669 config->channel_path = NULL; in main()
1673 if (addr->type == SOCKET_ADDRESS_TYPE_UNIX) { in main()
1674 config->method = g_strdup("unix-listen"); in main()
1675 } else if (addr->type == SOCKET_ADDRESS_TYPE_VSOCK) { in main()
1676 config->method = g_strdup("vsock-listen"); in main()
1682 if (!config->method) { in main()
1686 } else if (config->channel_path == NULL) { in main()
1687 if (strcmp(config->method, "virtio-serial") == 0) { in main()
1688 /* try the default path for the virtio-serial port */ in main()
1689 config->channel_path = g_strdup(QGA_VIRTIO_PATH_DEFAULT); in main()
1690 } else if (strcmp(config->method, "isa-serial") == 0) { in main()
1691 /* try the default path for the serial port - COM1 */ in main()
1692 config->channel_path = g_strdup(QGA_SERIAL_PATH_DEFAULT); in main()
1699 if (config->dumpconf) { in main()
1712 if (config->daemonize) { in main()
1727 if (config->daemonize) { in main()
1728 unlink(config->pid_filepath); in main()