v3 Migration+ virtiofsd pull 2020-10-12

V3
   Remove the postcopy recovery changes
 
 Migration:
   Dirtyrate measurement API cleanup
 
 Virtiofsd:
   Missing qemu_init_exec_dir call
   Support for setting the group on socket creation
   Stop a gcc warning
   Avoid tempdir in sandboxing
 -----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCAAdFiEERfXHG0oMt/uXep+pBRYzHrxb/ecFAl+EQWIACgkQBRYzHrxb
 /edFdQ/+Mv2A3gHGWDeVkVmotTEBppRa22WjipSiUzdJhn25q/T6twyM7FXwZPQn
 1j8A0nmY3mogx/Z0lB1jMOEUbI7x5WedF82gdZQXVskbOtaW4bp9IktkzfNo6xUU
 A6lcG2hZeCOwnqtOkibxf1EHznO0/d3BMIGwBV773hkji0MFmyj/ekxmJIS3y6rn
 m/TEOGQeDdRp9BZcMaGEbW3IJ8+Zz6aWTOwm7/AKMkf3MZJ0ltyIhb3WUi+qsSR4
 8+bq7ayPn9sxyCReLU4AmktZ33bqkU7JLXgGahNP4ySLbKIJSMzloWroFnl6Oynx
 oWOv7PzBwA+pwOCeihoDIOthl7MIpZZg6Q8YfE6vG/7phqtOB1UW3DOWaWdTbYjE
 d3o5S1T7kjK10dLqZ5iuNnQ0iH0qwDDSHQQL8IefnyXDweUZU1JuNwHP5VT30ia5
 B4lUTYGQJ60JXnpJJKE1bUioxDzlsPKCgoFfTS9e/ULUt6RW4m6Ctmmu8aJy7mm5
 NUEWyk39oionJBZ42jBPD/w/DaZorirqIGPeZxE99shasuWazpZ2LZj0ksYV1x5f
 yGEhvXjdcKt6YwRADzno8cCisZcWhVnJhXUDBPTiBKYmFNlY2aVrB84Lixpysnp8
 Dsis6XvHb9jLceAUl0Qut6JlGzZ0NRq6bBk+YsknRJeGBdmWz8w=
 =0yqB
 -----END PGP SIGNATURE-----

Merge remote-tracking branch 'remotes/dgilbert/tags/pull-migration-20201012a' into staging

v3 Migration+ virtiofsd pull 2020-10-12

V3
  Remove the postcopy recovery changes

Migration:
  Dirtyrate measurement API cleanup

Virtiofsd:
  Missing qemu_init_exec_dir call
  Support for setting the group on socket creation
  Stop a gcc warning
  Avoid tempdir in sandboxing

# gpg: Signature made Mon 12 Oct 2020 12:43:30 BST
# gpg:                using RSA key 45F5C71B4A0CB7FB977A9FA90516331EBC5BFDE7
# gpg: Good signature from "Dr. David Alan Gilbert (RH2) <dgilbert@redhat.com>" [full]
# Primary key fingerprint: 45F5 C71B 4A0C B7FB 977A  9FA9 0516 331E BC5B FDE7

* remotes/dgilbert/tags/pull-migration-20201012a:
  migration/dirtyrate: present dirty rate only when querying the rate has completed
  migration/dirtyrate: record start_time and calc_time while at the measuring state
  virtiofsd: avoid /proc/self/fd tempdir
  virtiofsd: Call qemu_init_exec_dir
  tools/virtiofsd: add support for --socket-group
  virtiofsd: Silence gcc warning

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
Peter Maydell 2020-10-12 13:12:04 +01:00
commit a0bdf86687
7 changed files with 57 additions and 37 deletions

View file

@ -87,6 +87,10 @@ Options
Listen on vhost-user UNIX domain socket at PATH.
.. option:: --socket-group=GROUP
Set the vhost-user UNIX domain socket gid to GROUP.
.. option:: --fd=FDNUM
Accept connections from vhost-user UNIX domain socket file descriptor FDNUM.

View file

@ -69,9 +69,8 @@ static struct DirtyRateInfo *query_dirty_rate_info(void)
struct DirtyRateInfo *info = g_malloc0(sizeof(DirtyRateInfo));
if (qatomic_read(&CalculatingState) == DIRTY_RATE_STATUS_MEASURED) {
info->has_dirty_rate = true;
info->dirty_rate = dirty_rate;
} else {
info->dirty_rate = -1;
}
info->status = CalculatingState;
@ -83,14 +82,14 @@ static struct DirtyRateInfo *query_dirty_rate_info(void)
return info;
}
static void reset_dirtyrate_stat(void)
static void init_dirtyrate_stat(int64_t start_time, int64_t calc_time)
{
DirtyStat.total_dirty_samples = 0;
DirtyStat.total_sample_count = 0;
DirtyStat.total_block_mem_MB = 0;
DirtyStat.dirty_rate = -1;
DirtyStat.start_time = 0;
DirtyStat.calc_time = 0;
DirtyStat.start_time = start_time;
DirtyStat.calc_time = calc_time;
}
static void update_dirtyrate_stat(struct RamblockDirtyInfo *info)
@ -335,7 +334,6 @@ static void calculate_dirtyrate(struct DirtyRateConfig config)
int64_t initial_time;
rcu_register_thread();
reset_dirtyrate_stat();
rcu_read_lock();
initial_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
if (!record_ramblock_hash_info(&block_dinfo, config, &block_count)) {
@ -365,6 +363,8 @@ void *get_dirtyrate_thread(void *arg)
{
struct DirtyRateConfig config = *(struct DirtyRateConfig *)arg;
int ret;
int64_t start_time;
int64_t calc_time;
ret = dirtyrate_set_state(&CalculatingState, DIRTY_RATE_STATUS_UNSTARTED,
DIRTY_RATE_STATUS_MEASURING);
@ -373,6 +373,10 @@ void *get_dirtyrate_thread(void *arg)
return NULL;
}
start_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME) / 1000;
calc_time = config.sample_period_seconds;
init_dirtyrate_stat(start_time, calc_time);
calculate_dirtyrate(config);
ret = dirtyrate_set_state(&CalculatingState, DIRTY_RATE_STATUS_MEASURING,

View file

@ -1743,10 +1743,8 @@
#
# Information about current dirty page rate of vm.
#
# @dirty-rate: @dirtyrate describing the dirty page rate of vm
# in units of MB/s.
# If this field returns '-1', it means querying has not
# yet started or completed.
# @dirty-rate: an estimate of the dirty page rate of the VM in units of
# MB/s, present only when estimating the rate has completed.
#
# @status: status containing dirtyrate query status includes
# 'unstarted' or 'measuring' or 'measured'
@ -1759,7 +1757,7 @@
#
##
{ 'struct': 'DirtyRateInfo',
'data': {'dirty-rate': 'int64',
'data': {'*dirty-rate': 'int64',
'status': 'DirtyRateStatus',
'start-time': 'int64',
'calc-time': 'int64'} }

View file

@ -68,6 +68,7 @@ struct fuse_session {
size_t bufsize;
int error;
char *vu_socket_path;
char *vu_socket_group;
int vu_listen_fd;
int vu_socketfd;
struct fv_VuDev *virtio_dev;

View file

@ -2523,6 +2523,7 @@ static const struct fuse_opt fuse_ll_opts[] = {
LL_OPTION("--debug", debug, 1),
LL_OPTION("allow_root", deny_others, 1),
LL_OPTION("--socket-path=%s", vu_socket_path, 0),
LL_OPTION("--socket-group=%s", vu_socket_group, 0),
LL_OPTION("--fd=%d", vu_listen_fd, 0),
LL_OPTION("--thread-pool-size=%d", thread_pool_size, 0),
FUSE_OPT_END
@ -2630,6 +2631,11 @@ struct fuse_session *fuse_session_new(struct fuse_args *args,
"fuse: --socket-path and --fd cannot be given together\n");
goto out4;
}
if (se->vu_socket_group && !se->vu_socket_path) {
fuse_log(FUSE_LOG_ERR,
"fuse: --socket-group can only be used with --socket-path\n");
goto out4;
}
se->bufsize = FUSE_MAX_MAX_PAGES * getpagesize() + FUSE_BUFFER_HEADER_SIZE;

View file

@ -31,6 +31,8 @@
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/un.h>
#include <sys/types.h>
#include <grp.h>
#include <unistd.h>
#include "contrib/libvhost-user/libvhost-user.h"
@ -924,15 +926,30 @@ static int fv_create_listen_socket(struct fuse_session *se)
/*
* Unfortunately bind doesn't let you set the mask on the socket,
* so set umask to 077 and restore it later.
* so set umask appropriately and restore it later.
*/
old_umask = umask(0077);
if (se->vu_socket_group) {
old_umask = umask(S_IROTH | S_IWOTH | S_IXOTH);
} else {
old_umask = umask(S_IRGRP | S_IWGRP | S_IXGRP |
S_IROTH | S_IWOTH | S_IXOTH);
}
if (bind(listen_sock, (struct sockaddr *)&un, addr_len) == -1) {
fuse_log(FUSE_LOG_ERR, "vhost socket bind: %m\n");
close(listen_sock);
umask(old_umask);
return -1;
}
if (se->vu_socket_group) {
struct group *g = getgrnam(se->vu_socket_group);
if (g) {
if (!chown(se->vu_socket_path, -1, g->gr_gid)) {
fuse_log(FUSE_LOG_WARNING,
"vhost socket failed to set group to %s (%d)\n",
se->vu_socket_group, g->gr_gid);
}
}
}
umask(old_umask);
if (listen(listen_sock, 1) == -1) {

View file

@ -620,7 +620,7 @@ static void lo_setattr(fuse_req_t req, fuse_ino_t ino, struct stat *attr,
struct lo_inode *inode;
int ifd;
int res;
int fd;
int fd = -1;
inode = lo_inode(req, ino);
if (!inode) {
@ -2393,8 +2393,6 @@ static void setup_wait_parent_capabilities(void)
static void setup_namespaces(struct lo_data *lo, struct fuse_session *se)
{
pid_t child;
char template[] = "virtiofsd-XXXXXX";
char *tmpdir;
/*
* Create a new pid namespace for *child* processes. We'll have to
@ -2458,33 +2456,23 @@ static void setup_namespaces(struct lo_data *lo, struct fuse_session *se)
exit(1);
}
tmpdir = mkdtemp(template);
if (!tmpdir) {
fuse_log(FUSE_LOG_ERR, "tmpdir(%s): %m\n", template);
/*
* We only need /proc/self/fd. Prevent ".." from accessing parent
* directories of /proc/self/fd by bind-mounting it over /proc. Since / was
* previously remounted with MS_REC | MS_SLAVE this mount change only
* affects our process.
*/
if (mount("/proc/self/fd", "/proc", NULL, MS_BIND, NULL) < 0) {
fuse_log(FUSE_LOG_ERR, "mount(/proc/self/fd, MS_BIND): %m\n");
exit(1);
}
if (mount("/proc/self/fd", tmpdir, NULL, MS_BIND, NULL) < 0) {
fuse_log(FUSE_LOG_ERR, "mount(/proc/self/fd, %s, MS_BIND): %m\n",
tmpdir);
exit(1);
}
/* Now we can get our /proc/self/fd directory file descriptor */
lo->proc_self_fd = open(tmpdir, O_PATH);
/* Get the /proc (actually /proc/self/fd, see above) file descriptor */
lo->proc_self_fd = open("/proc", O_PATH);
if (lo->proc_self_fd == -1) {
fuse_log(FUSE_LOG_ERR, "open(%s, O_PATH): %m\n", tmpdir);
fuse_log(FUSE_LOG_ERR, "open(/proc, O_PATH): %m\n");
exit(1);
}
if (umount2(tmpdir, MNT_DETACH) < 0) {
fuse_log(FUSE_LOG_ERR, "umount2(%s, MNT_DETACH): %m\n", tmpdir);
exit(1);
}
if (rmdir(tmpdir) < 0) {
fuse_log(FUSE_LOG_ERR, "rmdir(%s): %m\n", tmpdir);
}
}
/*
@ -2839,6 +2827,8 @@ int main(int argc, char *argv[])
/* Don't mask creation mode, kernel already did that */
umask(0);
qemu_init_exec_dir(argv[0]);
pthread_mutex_init(&lo.mutex, NULL);
lo.inodes = g_hash_table_new(lo_key_hash, lo_key_equal);
lo.root.fd = -1;