|
|
8042be |
From f20c2a3298ceae7536c06bd08a5c571ebfa8cce4 Mon Sep 17 00:00:00 2001
|
|
|
8042be |
From: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
8042be |
Date: Thu, 6 May 2021 12:50:43 +0200
|
|
|
8042be |
Subject: Update C files and scripts to kernel version 5.7-rc1
|
|
|
8042be |
|
|
|
8042be |
(cherry-picked from RHEL 8.4.0 commit b0a20fac0e74b0b3eecc20ffe74006e7877da352)
|
|
|
8042be |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
8042be |
---
|
|
|
8042be |
hv_fcopy_daemon.c | 37 +++++++++++++++++++++++++++++++-----
|
|
|
8042be |
hv_get_dhcp_info.sh | 2 +-
|
|
|
8042be |
hv_kvp_daemon.c | 35 ++++++++++++++++++++--------------
|
|
|
8042be |
hv_set_ifconfig.sh | 2 +-
|
|
|
8042be |
hv_vss_daemon.c | 46 ++++++++++++++++++++++++++++++++++-----------
|
|
|
8042be |
5 files changed, 90 insertions(+), 32 deletions(-)
|
|
|
8042be |
|
|
|
8042be |
diff --git a/hv_fcopy_daemon.c b/hv_fcopy_daemon.c
|
|
|
8042be |
index aea2d91..16d629b 100644
|
|
|
8042be |
--- a/hv_fcopy_daemon.c
|
|
|
8042be |
+++ b/hv_fcopy_daemon.c
|
|
|
8042be |
@@ -80,6 +80,8 @@ static int hv_start_fcopy(struct hv_start_fcopy *smsg)
|
|
|
8042be |
|
|
|
8042be |
error = 0;
|
|
|
8042be |
done:
|
|
|
8042be |
+ if (error)
|
|
|
8042be |
+ target_fname[0] = '\0';
|
|
|
8042be |
return error;
|
|
|
8042be |
}
|
|
|
8042be |
|
|
|
8042be |
@@ -108,15 +110,29 @@ static int hv_copy_data(struct hv_do_fcopy *cpmsg)
|
|
|
8042be |
return ret;
|
|
|
8042be |
}
|
|
|
8042be |
|
|
|
8042be |
+/*
|
|
|
8042be |
+ * Reset target_fname to "" in the two below functions for hibernation: if
|
|
|
8042be |
+ * the fcopy operation is aborted by hibernation, the daemon should remove the
|
|
|
8042be |
+ * partially-copied file; to achieve this, the hv_utils driver always fakes a
|
|
|
8042be |
+ * CANCEL_FCOPY message upon suspend, and later when the VM resumes back,
|
|
|
8042be |
+ * the daemon calls hv_copy_cancel() to remove the file; if a file is copied
|
|
|
8042be |
+ * successfully before suspend, hv_copy_finished() must reset target_fname to
|
|
|
8042be |
+ * avoid that the file can be incorrectly removed upon resume, since the faked
|
|
|
8042be |
+ * CANCEL_FCOPY message is spurious in this case.
|
|
|
8042be |
+ */
|
|
|
8042be |
static int hv_copy_finished(void)
|
|
|
8042be |
{
|
|
|
8042be |
close(target_fd);
|
|
|
8042be |
+ target_fname[0] = '\0';
|
|
|
8042be |
return 0;
|
|
|
8042be |
}
|
|
|
8042be |
static int hv_copy_cancel(void)
|
|
|
8042be |
{
|
|
|
8042be |
close(target_fd);
|
|
|
8042be |
- unlink(target_fname);
|
|
|
8042be |
+ if (strlen(target_fname) > 0) {
|
|
|
8042be |
+ unlink(target_fname);
|
|
|
8042be |
+ target_fname[0] = '\0';
|
|
|
8042be |
+ }
|
|
|
8042be |
return 0;
|
|
|
8042be |
|
|
|
8042be |
}
|
|
|
8042be |
@@ -131,7 +147,7 @@ void print_usage(char *argv[])
|
|
|
8042be |
|
|
|
8042be |
int main(int argc, char *argv[])
|
|
|
8042be |
{
|
|
|
8042be |
- int fcopy_fd;
|
|
|
8042be |
+ int fcopy_fd = -1;
|
|
|
8042be |
int error;
|
|
|
8042be |
int daemonize = 1, long_index = 0, opt;
|
|
|
8042be |
int version = FCOPY_CURRENT_VERSION;
|
|
|
8042be |
@@ -141,7 +157,7 @@ int main(int argc, char *argv[])
|
|
|
8042be |
struct hv_do_fcopy copy;
|
|
|
8042be |
__u32 kernel_modver;
|
|
|
8042be |
} buffer = { };
|
|
|
8042be |
- int in_handshake = 1;
|
|
|
8042be |
+ int in_handshake;
|
|
|
8042be |
|
|
|
8042be |
static struct option long_options[] = {
|
|
|
8042be |
{"help", no_argument, 0, 'h' },
|
|
|
8042be |
@@ -170,6 +186,12 @@ int main(int argc, char *argv[])
|
|
|
8042be |
openlog("HV_FCOPY", 0, LOG_USER);
|
|
|
8042be |
syslog(LOG_INFO, "starting; pid is:%d", getpid());
|
|
|
8042be |
|
|
|
8042be |
+reopen_fcopy_fd:
|
|
|
8042be |
+ if (fcopy_fd != -1)
|
|
|
8042be |
+ close(fcopy_fd);
|
|
|
8042be |
+ /* Remove any possible partially-copied file on error */
|
|
|
8042be |
+ hv_copy_cancel();
|
|
|
8042be |
+ in_handshake = 1;
|
|
|
8042be |
fcopy_fd = open("/dev/vmbus/hv_fcopy", O_RDWR);
|
|
|
8042be |
|
|
|
8042be |
if (fcopy_fd < 0) {
|
|
|
8042be |
@@ -196,7 +218,7 @@ int main(int argc, char *argv[])
|
|
|
8042be |
len = pread(fcopy_fd, &buffer, sizeof(buffer), 0);
|
|
|
8042be |
if (len < 0) {
|
|
|
8042be |
syslog(LOG_ERR, "pread failed: %s", strerror(errno));
|
|
|
8042be |
- exit(EXIT_FAILURE);
|
|
|
8042be |
+ goto reopen_fcopy_fd;
|
|
|
8042be |
}
|
|
|
8042be |
|
|
|
8042be |
if (in_handshake) {
|
|
|
8042be |
@@ -231,9 +253,14 @@ int main(int argc, char *argv[])
|
|
|
8042be |
|
|
|
8042be |
}
|
|
|
8042be |
|
|
|
8042be |
+ /*
|
|
|
8042be |
+ * pwrite() may return an error due to the faked CANCEL_FCOPY
|
|
|
8042be |
+ * message upon hibernation. Ignore the error by resetting the
|
|
|
8042be |
+ * dev file, i.e. closing and re-opening it.
|
|
|
8042be |
+ */
|
|
|
8042be |
if (pwrite(fcopy_fd, &error, sizeof(int), 0) != sizeof(int)) {
|
|
|
8042be |
syslog(LOG_ERR, "pwrite failed: %s", strerror(errno));
|
|
|
8042be |
- exit(EXIT_FAILURE);
|
|
|
8042be |
+ goto reopen_fcopy_fd;
|
|
|
8042be |
}
|
|
|
8042be |
}
|
|
|
8042be |
}
|
|
|
8042be |
diff --git a/hv_get_dhcp_info.sh b/hv_get_dhcp_info.sh
|
|
|
8042be |
index c38686c..2f2a3c7 100644
|
|
|
8042be |
--- a/hv_get_dhcp_info.sh
|
|
|
8042be |
+++ b/hv_get_dhcp_info.sh
|
|
|
8042be |
@@ -13,7 +13,7 @@
|
|
|
8042be |
# the script prints the string "Disabled" to stdout.
|
|
|
8042be |
#
|
|
|
8042be |
# Each Distro is expected to implement this script in a distro specific
|
|
|
8042be |
-# fashion. For instance on Distros that ship with Network Manager enabled,
|
|
|
8042be |
+# fashion. For instance, on Distros that ship with Network Manager enabled,
|
|
|
8042be |
# this script can be based on the Network Manager APIs for retrieving DHCP
|
|
|
8042be |
# information.
|
|
|
8042be |
|
|
|
8042be |
diff --git a/hv_kvp_daemon.c b/hv_kvp_daemon.c
|
|
|
8042be |
index e9ef4ca..0e5f14a 100644
|
|
|
8042be |
--- a/hv_kvp_daemon.c
|
|
|
8042be |
+++ b/hv_kvp_daemon.c
|
|
|
8042be |
@@ -76,7 +76,7 @@ enum {
|
|
|
8042be |
DNS
|
|
|
8042be |
};
|
|
|
8042be |
|
|
|
8042be |
-static int in_hand_shake = 1;
|
|
|
8042be |
+static int in_hand_shake;
|
|
|
8042be |
|
|
|
8042be |
static char *os_name = "";
|
|
|
8042be |
static char *os_major = "";
|
|
|
8042be |
@@ -1360,7 +1360,7 @@ void print_usage(char *argv[])
|
|
|
8042be |
|
|
|
8042be |
int main(int argc, char *argv[])
|
|
|
8042be |
{
|
|
|
8042be |
- int kvp_fd, len;
|
|
|
8042be |
+ int kvp_fd = -1, len;
|
|
|
8042be |
int error;
|
|
|
8042be |
struct pollfd pfd;
|
|
|
8042be |
char *p;
|
|
|
8042be |
@@ -1400,14 +1400,6 @@ int main(int argc, char *argv[])
|
|
|
8042be |
openlog("KVP", 0, LOG_USER);
|
|
|
8042be |
syslog(LOG_INFO, "KVP starting; pid is:%d", getpid());
|
|
|
8042be |
|
|
|
8042be |
- kvp_fd = open("/dev/vmbus/hv_kvp", O_RDWR | O_CLOEXEC);
|
|
|
8042be |
-
|
|
|
8042be |
- if (kvp_fd < 0) {
|
|
|
8042be |
- syslog(LOG_ERR, "open /dev/vmbus/hv_kvp failed; error: %d %s",
|
|
|
8042be |
- errno, strerror(errno));
|
|
|
8042be |
- exit(EXIT_FAILURE);
|
|
|
8042be |
- }
|
|
|
8042be |
-
|
|
|
8042be |
/*
|
|
|
8042be |
* Retrieve OS release information.
|
|
|
8042be |
*/
|
|
|
8042be |
@@ -1423,6 +1415,18 @@ int main(int argc, char *argv[])
|
|
|
8042be |
exit(EXIT_FAILURE);
|
|
|
8042be |
}
|
|
|
8042be |
|
|
|
8042be |
+reopen_kvp_fd:
|
|
|
8042be |
+ if (kvp_fd != -1)
|
|
|
8042be |
+ close(kvp_fd);
|
|
|
8042be |
+ in_hand_shake = 1;
|
|
|
8042be |
+ kvp_fd = open("/dev/vmbus/hv_kvp", O_RDWR | O_CLOEXEC);
|
|
|
8042be |
+
|
|
|
8042be |
+ if (kvp_fd < 0) {
|
|
|
8042be |
+ syslog(LOG_ERR, "open /dev/vmbus/hv_kvp failed; error: %d %s",
|
|
|
8042be |
+ errno, strerror(errno));
|
|
|
8042be |
+ exit(EXIT_FAILURE);
|
|
|
8042be |
+ }
|
|
|
8042be |
+
|
|
|
8042be |
/*
|
|
|
8042be |
* Register ourselves with the kernel.
|
|
|
8042be |
*/
|
|
|
8042be |
@@ -1457,8 +1461,7 @@ int main(int argc, char *argv[])
|
|
|
8042be |
syslog(LOG_ERR, "read failed; error:%d %s",
|
|
|
8042be |
errno, strerror(errno));
|
|
|
8042be |
|
|
|
8042be |
- close(kvp_fd);
|
|
|
8042be |
- return EXIT_FAILURE;
|
|
|
8042be |
+ goto reopen_kvp_fd;
|
|
|
8042be |
}
|
|
|
8042be |
|
|
|
8042be |
/*
|
|
|
8042be |
@@ -1617,13 +1620,17 @@ int main(int argc, char *argv[])
|
|
|
8042be |
break;
|
|
|
8042be |
}
|
|
|
8042be |
|
|
|
8042be |
- /* Send the value back to the kernel. */
|
|
|
8042be |
+ /*
|
|
|
8042be |
+ * Send the value back to the kernel. Note: the write() may
|
|
|
8042be |
+ * return an error due to hibernation; we can ignore the error
|
|
|
8042be |
+ * by resetting the dev file, i.e. closing and re-opening it.
|
|
|
8042be |
+ */
|
|
|
8042be |
kvp_done:
|
|
|
8042be |
len = write(kvp_fd, hv_msg, sizeof(struct hv_kvp_msg));
|
|
|
8042be |
if (len != sizeof(struct hv_kvp_msg)) {
|
|
|
8042be |
syslog(LOG_ERR, "write failed; error: %d %s", errno,
|
|
|
8042be |
strerror(errno));
|
|
|
8042be |
- exit(EXIT_FAILURE);
|
|
|
8042be |
+ goto reopen_kvp_fd;
|
|
|
8042be |
}
|
|
|
8042be |
}
|
|
|
8042be |
|
|
|
8042be |
diff --git a/hv_set_ifconfig.sh b/hv_set_ifconfig.sh
|
|
|
8042be |
index 18b27cc..3dd064c 100644
|
|
|
8042be |
--- a/hv_set_ifconfig.sh
|
|
|
8042be |
+++ b/hv_set_ifconfig.sh
|
|
|
8042be |
@@ -12,7 +12,7 @@
|
|
|
8042be |
# be used to configure the interface.
|
|
|
8042be |
#
|
|
|
8042be |
# Each Distro is expected to implement this script in a distro specific
|
|
|
8042be |
-# fashion. For instance on Distros that ship with Network Manager enabled,
|
|
|
8042be |
+# fashion. For instance, on Distros that ship with Network Manager enabled,
|
|
|
8042be |
# this script can be based on the Network Manager APIs for configuring the
|
|
|
8042be |
# interface.
|
|
|
8042be |
#
|
|
|
8042be |
diff --git a/hv_vss_daemon.c b/hv_vss_daemon.c
|
|
|
8042be |
index 92902a8..29a1e48 100644
|
|
|
8042be |
--- a/hv_vss_daemon.c
|
|
|
8042be |
+++ b/hv_vss_daemon.c
|
|
|
8042be |
@@ -28,6 +28,8 @@
|
|
|
8042be |
#include <stdbool.h>
|
|
|
8042be |
#include <dirent.h>
|
|
|
8042be |
|
|
|
8042be |
+static bool fs_frozen;
|
|
|
8042be |
+
|
|
|
8042be |
/* Don't use syslog() in the function since that can cause write to disk */
|
|
|
8042be |
static int vss_do_freeze(char *dir, unsigned int cmd)
|
|
|
8042be |
{
|
|
|
8042be |
@@ -155,16 +157,22 @@ static int vss_operate(int operation)
|
|
|
8042be |
continue;
|
|
|
8042be |
}
|
|
|
8042be |
error |= vss_do_freeze(ent->mnt_dir, cmd);
|
|
|
8042be |
- if (error && operation == VSS_OP_FREEZE)
|
|
|
8042be |
- goto err;
|
|
|
8042be |
+ if (operation == VSS_OP_FREEZE) {
|
|
|
8042be |
+ if (error)
|
|
|
8042be |
+ goto err;
|
|
|
8042be |
+ fs_frozen = true;
|
|
|
8042be |
+ }
|
|
|
8042be |
}
|
|
|
8042be |
|
|
|
8042be |
endmntent(mounts);
|
|
|
8042be |
|
|
|
8042be |
if (root_seen) {
|
|
|
8042be |
error |= vss_do_freeze("/", cmd);
|
|
|
8042be |
- if (error && operation == VSS_OP_FREEZE)
|
|
|
8042be |
- goto err;
|
|
|
8042be |
+ if (operation == VSS_OP_FREEZE) {
|
|
|
8042be |
+ if (error)
|
|
|
8042be |
+ goto err;
|
|
|
8042be |
+ fs_frozen = true;
|
|
|
8042be |
+ }
|
|
|
8042be |
}
|
|
|
8042be |
|
|
|
8042be |
goto out;
|
|
|
8042be |
@@ -175,6 +183,7 @@ err:
|
|
|
8042be |
endmntent(mounts);
|
|
|
8042be |
}
|
|
|
8042be |
vss_operate(VSS_OP_THAW);
|
|
|
8042be |
+ fs_frozen = false;
|
|
|
8042be |
/* Call syslog after we thaw all filesystems */
|
|
|
8042be |
if (ent)
|
|
|
8042be |
syslog(LOG_ERR, "FREEZE of %s failed; error:%d %s",
|
|
|
8042be |
@@ -196,13 +205,13 @@ void print_usage(char *argv[])
|
|
|
8042be |
|
|
|
8042be |
int main(int argc, char *argv[])
|
|
|
8042be |
{
|
|
|
8042be |
- int vss_fd, len;
|
|
|
8042be |
+ int vss_fd = -1, len;
|
|
|
8042be |
int error;
|
|
|
8042be |
struct pollfd pfd;
|
|
|
8042be |
int op;
|
|
|
8042be |
struct hv_vss_msg vss_msg[1];
|
|
|
8042be |
int daemonize = 1, long_index = 0, opt;
|
|
|
8042be |
- int in_handshake = 1;
|
|
|
8042be |
+ int in_handshake;
|
|
|
8042be |
__u32 kernel_modver;
|
|
|
8042be |
|
|
|
8042be |
static struct option long_options[] = {
|
|
|
8042be |
@@ -232,6 +241,18 @@ int main(int argc, char *argv[])
|
|
|
8042be |
openlog("Hyper-V VSS", 0, LOG_USER);
|
|
|
8042be |
syslog(LOG_INFO, "VSS starting; pid is:%d", getpid());
|
|
|
8042be |
|
|
|
8042be |
+reopen_vss_fd:
|
|
|
8042be |
+ if (vss_fd != -1)
|
|
|
8042be |
+ close(vss_fd);
|
|
|
8042be |
+ if (fs_frozen) {
|
|
|
8042be |
+ if (vss_operate(VSS_OP_THAW) || fs_frozen) {
|
|
|
8042be |
+ syslog(LOG_ERR, "failed to thaw file system: err=%d",
|
|
|
8042be |
+ errno);
|
|
|
8042be |
+ exit(EXIT_FAILURE);
|
|
|
8042be |
+ }
|
|
|
8042be |
+ }
|
|
|
8042be |
+
|
|
|
8042be |
+ in_handshake = 1;
|
|
|
8042be |
vss_fd = open("/dev/vmbus/hv_vss", O_RDWR);
|
|
|
8042be |
if (vss_fd < 0) {
|
|
|
8042be |
syslog(LOG_ERR, "open /dev/vmbus/hv_vss failed; error: %d %s",
|
|
|
8042be |
@@ -247,8 +268,7 @@ int main(int argc, char *argv[])
|
|
|
8042be |
if (len < 0) {
|
|
|
8042be |
syslog(LOG_ERR, "registration to kernel failed; error: %d %s",
|
|
|
8042be |
errno, strerror(errno));
|
|
|
8042be |
- close(vss_fd);
|
|
|
8042be |
- exit(EXIT_FAILURE);
|
|
|
8042be |
+ goto reopen_vss_fd;
|
|
|
8042be |
}
|
|
|
8042be |
|
|
|
8042be |
pfd.fd = vss_fd;
|
|
|
8042be |
@@ -312,14 +332,18 @@ int main(int argc, char *argv[])
|
|
|
8042be |
default:
|
|
|
8042be |
syslog(LOG_ERR, "Illegal op:%d\n", op);
|
|
|
8042be |
}
|
|
|
8042be |
+
|
|
|
8042be |
+ /*
|
|
|
8042be |
+ * The write() may return an error due to the faked VSS_OP_THAW
|
|
|
8042be |
+ * message upon hibernation. Ignore the error by resetting the
|
|
|
8042be |
+ * dev file, i.e. closing and re-opening it.
|
|
|
8042be |
+ */
|
|
|
8042be |
vss_msg->error = error;
|
|
|
8042be |
len = write(vss_fd, vss_msg, sizeof(struct hv_vss_msg));
|
|
|
8042be |
if (len != sizeof(struct hv_vss_msg)) {
|
|
|
8042be |
syslog(LOG_ERR, "write failed; error: %d %s", errno,
|
|
|
8042be |
strerror(errno));
|
|
|
8042be |
-
|
|
|
8042be |
- if (op == VSS_OP_FREEZE)
|
|
|
8042be |
- vss_operate(VSS_OP_THAW);
|
|
|
8042be |
+ goto reopen_vss_fd;
|
|
|
8042be |
}
|
|
|
8042be |
}
|
|
|
8042be |
|
|
|
8042be |
--
|
|
|
8042be |
2.27.0
|
|
|
8042be |
|