virtiofsd+migration pull 2020-07-03

A couple of small migration fixes, and some capability
 rework for virtiofsd.
 
 Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
 -----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCAAdFiEERfXHG0oMt/uXep+pBRYzHrxb/ecFAl7/TisACgkQBRYzHrxb
 /efm3xAAoahip+4tZSLhUTx2wPv5XNlKDmxxc5lXKlW1ezZijVE7AB1lPOi1PUwF
 3om7RUXjvygAnvcxYV1PXw/AKATp0p/s2RbELF1Q9QNTGN+6gPKNr0tP0QW4/hOP
 UJE0ce7uSHKXJGNhSre233/kIWyqlEeRT95BBs9qxamg057t1tos4ghsYuCJAHGj
 GhllZ9f7pVaBsS23JrweNIO+WpZyygVhff5o4AkUKKsgOLeYV9vDJuk15FBTzgf4
 qsxLYiTPT0HRzSKM5ep/HY09nvTR8wRD49kh7Efo9kwEL6TyJ5nGjOtNkYMmGY2W
 WWje/Nw7HJeOkXkJrX+T7Sy98bmE/X5t14SAQ3teRWGv34p+rgLKYByPMRGvwf82
 eBRvaSh/DfX0zhGYbs0iEJgkQV0R+B27XqsmCdVLX0Pd5yf+q9oQTUdk9vgBBJcN
 f7oE4A9FagwhEc8dg9bSJ5ayERYHXlnd3rg4sY+VZbIf6kZXhHxfpfhZpCJJcH0j
 DEzQO17mRM12Ztbm/O9ol5H/0xVcxW52kw3dOl39ojrLNZqli1AkT+x73E3Vf3s8
 aLtRE4Ir0Zma8RzNSmC1uokfHUI55fdpAJ9jVkWTGYyArJiazqvMipyfJAIHiuMm
 cyl6sH44G8eaRqxmxNLOdSQJCUDIRdTrqAgdDintorQrvItMCAk=
 =+0cQ
 -----END PGP SIGNATURE-----

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

virtiofsd+migration pull 2020-07-03

A couple of small migration fixes, and some capability
rework for virtiofsd.

Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>

# gpg: Signature made Fri 03 Jul 2020 16:26:35 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-20200703a:
  migration: Count new_dirty instead of real_dirty
  migration: postcopy take proper error return
  virtiofsd: Allow addition or removal of capabilities
  virtiofsd: Check capability calls
  virtiofsd: Terminate capability list

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
Peter Maydell 2020-07-04 15:05:43 +01:00
commit 0b100c8e72
6 changed files with 80 additions and 13 deletions

View File

@ -54,6 +54,11 @@ Options
* flock|no_flock -
Enable/disable flock. The default is ``no_flock``.
* modcaps=CAPLIST
Modify the list of capabilities allowed; CAPLIST is a colon separated
list of capabilities, each preceded by either + or -, e.g.
''+sys_admin:-chown''.
* log_level=LEVEL -
Print only log messages matching LEVEL or more severe. LEVEL is one of
``err``, ``warn``, ``info``, or ``debug``. The default is ``info``.

View File

@ -442,8 +442,7 @@ static inline void cpu_physical_memory_clear_dirty_range(ram_addr_t start,
static inline
uint64_t cpu_physical_memory_sync_dirty_bitmap(RAMBlock *rb,
ram_addr_t start,
ram_addr_t length,
uint64_t *real_dirty_pages)
ram_addr_t length)
{
ram_addr_t addr;
unsigned long word = BIT_WORD((start + rb->offset) >> TARGET_PAGE_BITS);
@ -469,7 +468,6 @@ uint64_t cpu_physical_memory_sync_dirty_bitmap(RAMBlock *rb,
if (src[idx][offset]) {
unsigned long bits = atomic_xchg(&src[idx][offset], 0);
unsigned long new_dirty;
*real_dirty_pages += ctpopl(bits);
new_dirty = ~dest[k];
dest[k] |= bits;
new_dirty &= bits;
@ -502,7 +500,6 @@ uint64_t cpu_physical_memory_sync_dirty_bitmap(RAMBlock *rb,
start + addr + offset,
TARGET_PAGE_SIZE,
DIRTY_MEMORY_MIGRATION)) {
*real_dirty_pages += 1;
long k = (start + addr) >> TARGET_PAGE_BITS;
if (!test_and_set_bit(k, dest)) {
num_dirty++;

View File

@ -389,7 +389,7 @@ bool postcopy_ram_supported_by_host(MigrationIncomingState *mis)
*/
if (munlockall()) {
error_report("%s: munlockall: %s", __func__, strerror(errno));
return -1;
goto out;
}
/*

View File

@ -859,9 +859,11 @@ static inline bool migration_bitmap_clear_dirty(RAMState *rs,
/* Called with RCU critical section */
static void ramblock_sync_dirty_bitmap(RAMState *rs, RAMBlock *rb)
{
rs->migration_dirty_pages +=
cpu_physical_memory_sync_dirty_bitmap(rb, 0, rb->used_length,
&rs->num_dirty_pages_period);
uint64_t new_dirty_pages =
cpu_physical_memory_sync_dirty_bitmap(rb, 0, rb->used_length);
rs->migration_dirty_pages += new_dirty_pages;
rs->num_dirty_pages_period += new_dirty_pages;
}
/**

View File

@ -174,6 +174,8 @@ void fuse_cmdline_help(void)
" default: no_writeback\n"
" -o xattr|no_xattr enable/disable xattr\n"
" default: no_xattr\n"
" -o modcaps=CAPLIST Modify the list of capabilities\n"
" e.g. -o modcaps=+sys_admin:-chown\n"
" --rlimit-nofile=<num> set maximum number of file descriptors\n"
" (0 leaves rlimit unchanged)\n"
" default: min(1000000, fs.file-max - 16384)\n"

View File

@ -145,6 +145,7 @@ struct lo_data {
int posix_lock;
int xattr;
char *source;
char *modcaps;
double timeout;
int cache;
int timeout_set;
@ -170,6 +171,7 @@ static const struct fuse_opt lo_opts[] = {
{ "no_posix_lock", offsetof(struct lo_data, posix_lock), 0 },
{ "xattr", offsetof(struct lo_data, xattr), 1 },
{ "no_xattr", offsetof(struct lo_data, xattr), 0 },
{ "modcaps=%s", offsetof(struct lo_data, modcaps), 0 },
{ "timeout=%lf", offsetof(struct lo_data, timeout), 0 },
{ "timeout=", offsetof(struct lo_data, timeout_set), 1 },
{ "cache=none", offsetof(struct lo_data, cache), CACHE_NONE },
@ -2570,9 +2572,11 @@ static void setup_mounts(const char *source)
/*
* Only keep whitelisted capabilities that are needed for file system operation
* The (possibly NULL) modcaps_in string passed in is free'd before exit.
*/
static void setup_capabilities(void)
static void setup_capabilities(char *modcaps_in)
{
char *modcaps = modcaps_in;
pthread_mutex_lock(&cap.mutex);
capng_restore_state(&cap.saved);
@ -2589,7 +2593,7 @@ static void setup_capabilities(void)
*/
capng_setpid(syscall(SYS_gettid));
capng_clear(CAPNG_SELECT_BOTH);
capng_updatev(CAPNG_ADD, CAPNG_PERMITTED | CAPNG_EFFECTIVE,
if (capng_updatev(CAPNG_ADD, CAPNG_PERMITTED | CAPNG_EFFECTIVE,
CAP_CHOWN,
CAP_DAC_OVERRIDE,
CAP_DAC_READ_SEARCH,
@ -2598,10 +2602,67 @@ static void setup_capabilities(void)
CAP_SETGID,
CAP_SETUID,
CAP_MKNOD,
CAP_SETFCAP);
capng_apply(CAPNG_SELECT_BOTH);
CAP_SETFCAP,
-1)) {
fuse_log(FUSE_LOG_ERR, "%s: capng_updatev failed\n", __func__);
exit(1);
}
/*
* The modcaps option is a colon separated list of caps,
* each preceded by either + or -.
*/
while (modcaps) {
capng_act_t action;
int cap;
char *next = strchr(modcaps, ':');
if (next) {
*next = '\0';
next++;
}
switch (modcaps[0]) {
case '+':
action = CAPNG_ADD;
break;
case '-':
action = CAPNG_DROP;
break;
default:
fuse_log(FUSE_LOG_ERR,
"%s: Expecting '+'/'-' in modcaps but found '%c'\n",
__func__, modcaps[0]);
exit(1);
}
cap = capng_name_to_capability(modcaps + 1);
if (cap < 0) {
fuse_log(FUSE_LOG_ERR, "%s: Unknown capability '%s'\n", __func__,
modcaps);
exit(1);
}
if (capng_update(action, CAPNG_PERMITTED | CAPNG_EFFECTIVE, cap)) {
fuse_log(FUSE_LOG_ERR, "%s: capng_update failed for '%s'\n",
__func__, modcaps);
exit(1);
}
modcaps = next;
}
g_free(modcaps_in);
if (capng_apply(CAPNG_SELECT_BOTH)) {
fuse_log(FUSE_LOG_ERR, "%s: capng_apply failed\n", __func__);
exit(1);
}
cap.saved = capng_save_state();
if (!cap.saved) {
fuse_log(FUSE_LOG_ERR, "%s: capng_save_state failed\n", __func__);
exit(1);
}
pthread_mutex_unlock(&cap.mutex);
}
@ -2615,7 +2676,7 @@ static void setup_sandbox(struct lo_data *lo, struct fuse_session *se,
setup_namespaces(lo, se);
setup_mounts(lo->source);
setup_seccomp(enable_syslog);
setup_capabilities();
setup_capabilities(g_strdup(lo->modcaps));
}
/* Set the maximum number of open file descriptors */