migration queue
[PULL 1/6] virtiofsd: Silence gcc warning
In reply to Dr. David Alan Gilbert (git)From: "Dr. David Alan Gilbert" <[email protected]>
Gcc worries fd might be used unset, in reality it's always set if fi is set, and only used if fi is set so it's safe. Initialise it to -1 just to keep gcc happy for now.
Message-Id: <[email protected]>
--- tools/virtiofsd/passthrough_ll.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/virtiofsd/passthrough_ll.c +1 -1
@@ -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) {
Signature · 1 line
2.28.0
From: "Dr. David Alan Gilbert" <[email protected]>
The following changes since commit 2387df497b4b4bcf754eb7398edca82889e2ef54:
Merge remote-tracking branch 'remotes/armbru/tags/pull-qapi-2020-10-10' into staging (2020-10-12 11:29:42 +0100)
are available in the Git repository at:
git://github.com/dagrh/qemu.git tags/pull-migration-20201012a
for you to fetch changes up to b1a859cfb04db1d2b80dd9979ce6081cb9c00d75:
migration/dirtyrate: present dirty rate only when querying the rate has completed (2020-10-12 12:39:38 +0100)
----------------------------------------------------------------
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
----------------------------------------------------------------
Alex Bennée (1):
tools/virtiofsd: add support for --socket-group
Chuan Zheng (2):
migration/dirtyrate: record start_time and calc_time while at the measuring state migration/dirtyrate: present dirty rate only when querying the rate has completed
Dr. David Alan Gilbert (2):
virtiofsd: Silence gcc warning
virtiofsd: Call qemu_init_exec_dir
Stefan Hajnoczi (1):
virtiofsd: avoid /proc/self/fd tempdir
docs/tools/virtiofsd.rst | 4 ++++ migration/dirtyrate.c | 16 ++++++++++------ qapi/migration.json | 8 +++----- tools/virtiofsd/fuse_i.h | 1 + tools/virtiofsd/fuse_lowlevel.c | 6 ++++++ tools/virtiofsd/fuse_virtio.c | 21 +++++++++++++++++++-- tools/virtiofsd/passthrough_ll.c | 38 ++++++++++++++------------------------ 7 files changed, 57 insertions(+), 37 deletions(-)
[PULL 6/6] migration/dirtyrate: present dirty rate only when querying the rate has completed
From: Chuan Zheng <[email protected]>
Make dirty_rate field optional, present dirty rate only when querying
the rate has completed.
The qmp results is shown as follow:
@unstarted:
{"return":{"status":"unstarted","start-time":0,"calc-time":0},"id":"libvirt-12"} @measuring:
{"return":{"status":"measuring","start-time":102931,"calc-time":1},"id":"libvirt-85"} @measured:
{"return":{"status":"measured","dirty-rate":4,"start-time":150146,"calc-time":1},"id":"libvirt-15"}
Message-Id: <[email protected]>
--- migration/dirtyrate.c | 3 +-- qapi/migration.json | 8 +++----- 2 files changed, 4 insertions(+), 7 deletions(-)
migration/dirtyrate.c +1 -2
@@ -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;
qapi/migration.json +3 -5
@@ -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'} }
Signature · 1 line
2.28.0
[PULL 3/6] virtiofsd: Call qemu_init_exec_dir
In reply to Dr. David Alan Gilbert (git)From: "Dr. David Alan Gilbert" <[email protected]>
Since fcb4f59c879 qemu_get_local_state_pathname relies on the init_exec_dir, and virtiofsd asserts because we never set it. Set it.
Message-Id: <[email protected]>
--- tools/virtiofsd/passthrough_ll.c | 2 ++ 1 file changed, 2 insertions(+)
tools/virtiofsd/passthrough_ll.c +2 -0
@@ -2839,6 +2839,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 ;
Signature · 1 line
2.28.0
[PULL 5/6] migration/dirtyrate: record start_time and calc_time while at the measuring state
In reply to Dr. David Alan Gilbert (git)From: Chuan Zheng <[email protected]>
Querying could include both the start-time and the calc-time while at the measuring state, allowing a caller to determine when they should expect to come back looking for a result.
Message-Id: <[email protected]>
--- migration/dirtyrate.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
migration/dirtyrate.c +9 -4
@@ -83,14 +83,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 +335,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 +364,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 +374,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,
Signature · 1 line
2.28.0
[PULL 2/6] tools/virtiofsd: add support for --socket-group
In reply to Dr. David Alan Gilbert (git)From: Alex Bennée <[email protected]>
If you like running QEMU as a normal user (very common for TCG runs) but you have to run virtiofsd as a root user you run into connection problems. Adding support for an optional --socket-group allows the users to keep using the command line.
Message-Id: <[email protected]>
dgilbert: Split long line
--- docs/tools/virtiofsd.rst | 4 ++++ tools/virtiofsd/fuse_i.h | 1 + tools/virtiofsd/fuse_lowlevel.c | 6 ++++++ tools/virtiofsd/fuse_virtio.c | 21 +++++++++++++++++++-- 4 files changed, 30 insertions(+), 2 deletions(-)
docs/tools/virtiofsd.rst +4 -0
@@ -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.
tools/virtiofsd/fuse_i.h +1 -0
@@ -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;
tools/virtiofsd/fuse_lowlevel.c +6 -0
@@ -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 ;
tools/virtiofsd/fuse_virtio.c +19 -2
@@ -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 ) {
Signature · 1 line
2.28.0
[PULL 4/6] virtiofsd: avoid /proc/self/fd tempdir
In reply to Dr. David Alan Gilbert (git)From: Stefan Hajnoczi <[email protected]>
In order to prevent /proc/self/fd escapes a temporary directory is created where /proc/self/fd is bind-mounted. This doesn't work on read-only file systems.
Avoid the temporary directory by bind-mounting /proc/self/fd over /proc. This does not affect other processes since we remounted / with MS_REC | MS_SLAVE. /proc must exist and virtiofsd does not use it so it's safe to do this.
Path traversal can be tested with the following function:
static void test_proc_fd_escape(struct lo_data *lo)
{
int fd;
int level = 0;
ino_t last_ino = 0; fd = lo->proc_self_fd;
for (;;) {
struct stat st;
if (fstat(fd, &st) != 0) {
perror("fstat");
return;
}
if (last_ino && st.st_ino == last_ino) {
fprintf(stderr, "inode number unchanged, stopping\n");
return;
}
last_ino = st.st_ino;
fprintf(stderr, "Level %d dev %lu ino %lu\n", level,
(unsigned long)st.st_dev,
(unsigned long)last_ino);
fd = openat(fd, "..", O_PATH | O_DIRECTORY | O_NOFOLLOW);
level++;
}}
Before and after this patch only Level 0 is displayed. Without /proc/self/fd bind-mount protection it is possible to traverse parent directories.
Message-Id: <[email protected]>
--- tools/virtiofsd/passthrough_ll.c | 34 +++++++++++--------------------- 1 file changed, 11 insertions(+), 23 deletions(-)
tools/virtiofsd/passthrough_ll.c +11 -23
@@ -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); -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); +/* +* 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 ); } -/* 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); - } }/*
Signature · 1 line
2.28.0
Peter Maydell
AppliedQuoted 21 lines · Dr. David Alan Gilbert (git)
From: "Dr. David Alan Gilbert" <[email protected]>
The following changes since commit
2387df497b4b4bcf754eb7398edca82889e2ef54:Merge remote-tracking branch 'remotes/armbru/tags/pull-qapi-2020-10-10' into staging (2020-10-12 11:29:42 +0100)
are available in the Git repository at:
git://github.com/dagrh/qemu.gittags/pull-migration-20201012afor you to fetch changes up to
b1a859cfb04db1d2b80dd9979ce6081cb9c00d75:migration/dirtyrate: present dirty rate only when querying the rate has completed (2020-10-12 12:39:38 +0100)
----------------------------------------------------------------
v3 Migration+ virtiofsd pull 2020-10-12V3
Remove the postcopy recovery changes
Quoted 8 lines
Migration:
Dirtyrate measurement API cleanupVirtiofsd:
Missingqemu_init_exec_dircall
Support for setting the group on socket creation Stop a gcc warning
Avoid tempdir in sandboxing
Applied, thanks.
Please update the changelog at https://wiki.qemu.org/ChangeLog/5.2
for any user-visible changes.
-- PMM