Skip to contentSkip to conversation

migration queue

GIT PULL Applied Dr. David Alan Gilbert (git) 2 participants 17 messages Dec 18, 2020 – Dec 31, 2020 Arm/actions semi architecture

lore
Share & tools
lore
#1 lore raw

[PULL 02/15] monitor:braces {} are necessary for all arms of this statement

In reply to Dr. David Alan Gilbert (git)

From: Yutao Ai <[email protected]>

Fix the errors by add {}

Message-Id: <[email protected]>

---
 monitor/misc.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
monitor/misc.c +9 -5
index fde6e36a0b..09f9a74d78 100644
@@ -492,8 +492,10 @@ static void hmp_singlestep(Monitor *mon, const QDict *qdict)
 static void hmp_gdbserver(Monitor *mon, const QDict *qdict)
 {
     const char *device = qdict_get_try_str(qdict, "device");
-    if (!device)
+    if (!device) {
         device = "tcp::" DEFAULT_GDBSTUB_PORT;
+    }
+
     if (gdbserver_start(device) < 0) {
         monitor_printf(mon, "Could not open gdbserver on device '%s'\n",
                        device);
@@ -559,10 +561,11 @@ static void memory_dump(Monitor *mon, int count, int format, int wsize,
     }
 
     len = wsize * count;
-    if (wsize == 1)
+    if (wsize == 1) {
         line_size = 8;
-    else
+    } else {
         line_size = 16;
+    }
     max_digits = 0;
 
     switch(format) {
@@ -583,10 +586,11 @@ static void memory_dump(Monitor *mon, int count, int format, int wsize,
     }
 
     while (len > 0) {
-        if (is_physical)
+        if (is_physical) {
             monitor_printf(mon, TARGET_FMT_plx ":", addr);
-        else
+        } else {
             monitor_printf(mon, TARGET_FMT_lx ":", (target_ulong)addr);
+        }
         l = len;
         if (l > line_size)
             l = line_size;
Signature · 1 line
2.29.2
#2 lore raw

[PULL 07/15] virtiofsd: Set up posix_lock hash table for root inode

In reply to Dr. David Alan Gilbert (git)

From: Vivek Goyal <[email protected]>

We setup per inode hash table ->posix_lock to support remote posix locks. But we forgot to initialize this table for root inode.

Laszlo managed to trigger an issue where he sent a FUSE_FLUSH request for root inode and lo_flush() found inode with inode->posix_lock NULL and accessing this table crashed virtiofsd.

May be we can get rid of initializing this hash table for directory objects completely. But that optimization is for another day.

Message-Id: <[email protected]>

---
 tools/virtiofsd/passthrough_ll.c | 7 +++++++
 1 file changed, 7 insertions(+)
tools/virtiofsd/passthrough_ll.c +7 -0
index e61cc56530..80e62b1610 100644
@@ -3380,6 +3380,9 @@ static void setup_root(struct lo_data *lo, struct lo_inode *root)
     root->key.mnt_id = mnt_id;
     root->nlookup = 2;
     g_atomic_int_set(&root->refcount, 2);
+    pthread_mutex_init(&root->plock_mutex, NULL);
+    root->posix_locks = g_hash_table_new_full(
+        g_direct_hash, g_direct_equal, NULL, posix_locks_value_destroy);
 }
 
 static guint lo_key_hash(gconstpointer key)
@@ -3402,6 +3405,10 @@ static void fuse_lo_data_cleanup(struct lo_data *lo)
     if (lo->inodes) {
         g_hash_table_destroy(lo->inodes);
     }
+
+    if (lo->root.posix_locks) {
+        g_hash_table_destroy(lo->root.posix_locks);
+    }
     lo_map_destroy(&lo->fd_map);
     lo_map_destroy(&lo->dirp_map);
     lo_map_destroy(&lo->ino_map);
Signature · 1 line
2.29.2
#0 lore raw

From: "Dr. David Alan Gilbert" <[email protected]>

The following changes since commit 75ee62ac606bfc9eb59310b9446df3434bf6e8c2:

Merge remote-tracking branch 'remotes/ehabkost-gl/tags/x86-next-pull-request' into staging (2020-12-17 18:53:36 +0000)

are available in the Git repository at:

git://github.com/dagrh/qemu.git tags/pull-migration-20201218a

for you to fetch changes up to 36d0fe65160d83cb065de9b6fe60114ee127d9f0:

migration: Don't allow migration if vm is in POSTMIGRATE (2020-12-18 10:08:25 +0000)

----------------------------------------------------------------
Monitor, virtiofsd and migration pull

HMP cleanups
Migration fixes
Note the change in behaviour of not allowing a postmigrate migrtion rather than crashing

Virtiofsd cleanups and fixes
--thread-pool-size=0 for no thread pool (faster for some workloads)

----------------------------------------------------------------
Alex Chen (1):
virtiofsd: Remove useless code about send_notify_iov

Laszlo Ersek (2):
virtiofsd: make the debug log timestamp on stderr more human-readable
virtiofsd: update FUSE_FORGET comment on "lo_inode.nlookup"

Markus Armbruster (1):
docs/devel/migration: Improve debugging section a bit

Peter Maydell (1):
hmp-commands.hx: List abbreviation after command for cont, quit, print

Tuguoyi (3):
savevm: Remove dead code in save_snapshot()
savevm: Delete snapshots just created in case of error
migration: Don't allow migration if vm is in POSTMIGRATE

Vivek Goyal (4):
virtiofsd: Use --thread-pool-size=0 to mean no thread pool
virtiofsd: Set up posix_lock hash table for root inode
virtiofsd: Disable posix_lock hash table if remote locks are not enabled
virtiofsd: Check file type in lo_flush()

Yutao Ai (3):
monitor:open brace '{' following struct go on the same line monitor:braces {} are necessary for all arms of this statement monitor:Don't use '#' flag of printf format ('%#') in format strings

 docs/devel/migration.rst         | 11 +++--
 hmp-commands.hx                  | 12 ++---
 migration/migration.c            |  6 +++
 migration/savevm.c               | 11 ++---
 monitor/hmp-cmds.c               |  3 +-
 monitor/misc.c                   | 16 ++++---
 tools/virtiofsd/fuse_lowlevel.c  | 98 ----------------------------------------
 tools/virtiofsd/fuse_virtio.c    | 36 +++++++++++----
 tools/virtiofsd/passthrough_ll.c | 91 +++++++++++++++++++++++++++++--------
 9 files changed, 131 insertions(+), 153 deletions(-)
#3 lore raw

[PULL 01/15] monitor:open brace '{' following struct go on the same line

From: Yutao Ai <[email protected]>

Move the open brace '{' following struct go on the same line

Message-Id: <[email protected]>

---
 monitor/hmp-cmds.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
monitor/hmp-cmds.c +1 -2
index 65d8ff4849..79c84322b3 100644
@@ -1549,8 +1549,7 @@ end:
     hmp_handle_error(mon, err);
 }
 
-typedef struct HMPMigrationStatus
-{
+typedef struct HMPMigrationStatus {
     QEMUTimer *timer;
     Monitor *mon;
     bool is_block_migration;
Signature · 1 line
2.29.2
#4 lore raw

[PULL 03/15] monitor:Don't use '#' flag of printf format ('%#') in format strings

In reply to Dr. David Alan Gilbert (git)

From: Yutao Ai <[email protected]>

Delete '#' and use '0x' prefix instead

Message-Id: <[email protected]>

---
 monitor/misc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
monitor/misc.c +1 -1
index 09f9a74d78..6f5ae096dc 100644
@@ -919,7 +919,7 @@ static void hmp_ioport_read(Monitor *mon, const QDict *qdict)
         suffix = 'l';
         break;
     }
-    monitor_printf(mon, "port%c[0x%04x] = %#0*x\n",
+    monitor_printf(mon, "port%c[0x%04x] = 0x%0*x\n",
                    suffix, addr, size * 2, val);
 }
 
Signature · 1 line
2.29.2
#5 lore raw

[PULL 05/15] virtiofsd: Use --thread-pool-size=0 to mean no thread pool

In reply to Dr. David Alan Gilbert (git)

From: Vivek Goyal <[email protected]>

Right now we create a thread pool and main thread hands over the request to thread in thread pool to process. Number of threads in thread pool can be managed by option --thread-pool-size.

In tests we have noted that many of the workloads are getting better performance if we don't use a thread pool at all and process all the requests in the context of a thread receiving the request.

Hence give user an option to be able to run virtiofsd without using a thread pool.

To implement this, I have used existing option --thread-pool-size. This option defines how many maximum threads can be in the thread pool. Thread pool size zero freezes thead pool. I can't see why will one start virtiofsd with a frozen thread pool (hence frozen file system). So I am redefining --thread-pool-size=0 to mean, don't use a thread pool. Instead process the request in the context of thread receiving request from the queue.

Message-Id: <[email protected]>

---
 tools/virtiofsd/fuse_virtio.c | 36 ++++++++++++++++++++++++++---------
 1 file changed, 27 insertions(+), 9 deletions(-)
tools/virtiofsd/fuse_virtio.c +27 -9
index b264dcbd18..ddcefee427 100644
@@ -578,13 +578,18 @@ static void *fv_queue_thread(void *opaque)
     struct VuDev *dev = &qi->virtio_dev->dev;
     struct VuVirtq *q = vu_get_queue(dev, qi->qidx);
     struct fuse_session *se = qi->virtio_dev->se;
-    GThreadPool *pool;
-
-    pool = g_thread_pool_new(fv_queue_worker, qi, se->thread_pool_size, FALSE,
-                             NULL);
-    if (!pool) {
-        fuse_log(FUSE_LOG_ERR, "%s: g_thread_pool_new failed\n", __func__);
-        return NULL;
+    GThreadPool *pool = NULL;
+    GList *req_list = NULL;
+
+    if (se->thread_pool_size) {
+        fuse_log(FUSE_LOG_DEBUG, "%s: Creating thread pool for Queue %d\n",
+                 __func__, qi->qidx);
+        pool = g_thread_pool_new(fv_queue_worker, qi, se->thread_pool_size,
+                                 FALSE, NULL);
+        if (!pool) {
+            fuse_log(FUSE_LOG_ERR, "%s: g_thread_pool_new failed\n", __func__);
+            return NULL;
+        }
     }
 
     fuse_log(FUSE_LOG_INFO, "%s: Start for queue %d kick_fd %d\n", __func__,
@@ -659,14 +664,27 @@ static void *fv_queue_thread(void *opaque)
 
             req->reply_sent = false;
 
-            g_thread_pool_push(pool, req, NULL);
+            if (!se->thread_pool_size) {
+                req_list = g_list_prepend(req_list, req);
+            } else {
+                g_thread_pool_push(pool, req, NULL);
+            }
         }
 
         pthread_mutex_unlock(&qi->vq_lock);
         pthread_rwlock_unlock(&qi->virtio_dev->vu_dispatch_rwlock);
+
+        /* Process all the requests. */
+        if (!se->thread_pool_size && req_list != NULL) {
+            g_list_foreach(req_list, fv_queue_worker, qi);
+            g_list_free(req_list);
+            req_list = NULL;
+        }
     }
 
-    g_thread_pool_free(pool, FALSE, TRUE);
+    if (pool) {
+        g_thread_pool_free(pool, FALSE, TRUE);
+    }
 
     return NULL;
 }
Signature · 1 line
2.29.2
#6 lore raw

[PULL 06/15] virtiofsd: make the debug log timestamp on stderr more human-readable

In reply to Dr. David Alan Gilbert (git)

From: Laszlo Ersek <[email protected]>

The current timestamp format doesn't help me visually notice small jumps in time ("small" as defined on human scale, such as a few seconds or a few ten seconds). Replace it with a local time format where such differences stand out.

Before:

Quoted 6 lines

[13316826770337] [ID: 00000004] unique: 62, opcode: RELEASEDIR (29), nodeid: 1, insize: 64, pid: 1
[13316826778175] [ID: 00000004] unique: 62, success, outsize: 16
[13316826781156] [ID: 00000004] virtio_send_msg: elem 0: with 1 in desc of length 16 [15138279317927] [ID: 00000001] virtio_loop: Got VU event
[15138279504884] [ID: 00000001] fv_queue_set_started: qidx=1 started=0 [15138279519034] [ID: 00000003] fv_queue_thread: kill event on queue 1 - quitting

Quoted 8 lines

[15138280876463] [ID: 00000001] fv_remove_watch: TODO! fd=9 [15138280897381] [ID: 00000001] virtio_loop: Waiting for VU event [15138280946834] [ID: 00000001] virtio_loop: Got VU event [15138281175421] [ID: 00000001] virtio_loop: Waiting for VU event [15138281182387] [ID: 00000001] virtio_loop: Got VU event [15138281189474] [ID: 00000001] virtio_loop: Waiting for VU event [15138309321936] [ID: 00000001] virtio_loop: Unexpected poll revents 11 [15138309434150] [ID: 00000001] virtio_loop: Exit

(Notice how you don't (easily) notice the gap in time after "virtio_send_msg", and especially the amount of time passed is hard to estimate.)

After:

Quoted 6 lines

[2020-12-08 06:43:22.58+0100] [ID: 00000004] unique: 51, opcode: RELEASEDIR (29), nodeid: 1, insize: 64, pid: 1
[2020-12-08 06:43:22.58+0100] [ID: 00000004] unique: 51, success, outsize: 16
[2020-12-08 06:43:22.58+0100] [ID: 00000004] virtio_send_msg: elem 0: with 1 in desc of length 16 [2020-12-08 06:43:29.34+0100] [ID: 00000001] virtio_loop: Got VU event
[2020-12-08 06:43:29.34+0100] [ID: 00000001] fv_queue_set_started: qidx=1 started=0 [2020-12-08 06:43:29.34+0100] [ID: 00000003] fv_queue_thread: kill event on queue 1 - quitting

Quoted 8 lines

[2020-12-08 06:43:29.34+0100] [ID: 00000001] fv_remove_watch: TODO! fd=9 [2020-12-08 06:43:29.34+0100] [ID: 00000001] virtio_loop: Waiting for VU event [2020-12-08 06:43:29.34+0100] [ID: 00000001] virtio_loop: Got VU event [2020-12-08 06:43:29.34+0100] [ID: 00000001] virtio_loop: Waiting for VU event [2020-12-08 06:43:29.34+0100] [ID: 00000001] virtio_loop: Got VU event [2020-12-08 06:43:29.34+0100] [ID: 00000001] virtio_loop: Waiting for VU event [2020-12-08 06:43:29.37+0100] [ID: 00000001] virtio_loop: Unexpected poll revents 11 [2020-12-08 06:43:29.37+0100] [ID: 00000001] virtio_loop: Exit

Cc "Dr. David Alan Gilbert" <[email protected]>
Cc Stefan Hajnoczi <[email protected]>

Message-Id: <[email protected]>

---
 tools/virtiofsd/passthrough_ll.c | 31 +++++++++++++++++++++++++++----
 1 file changed, 27 insertions(+), 4 deletions(-)
tools/virtiofsd/passthrough_ll.c +27 -4
index 12de321745..e61cc56530 100644
@@ -3284,18 +3284,38 @@ static void setup_nofile_rlimit(unsigned long rlimit_nofile)
 static void log_func(enum fuse_log_level level, const char *fmt, va_list ap)
 {
     g_autofree char *localfmt = NULL;
+    struct timespec ts;
+    struct tm tm;
+    char sec_fmt[sizeof "2020-12-07 18:17:54"];
+    char zone_fmt[sizeof "+0100"];
 
     if (current_log_level < level) {
         return;
     }
 
     if (current_log_level == FUSE_LOG_DEBUG) {
-        if (!use_syslog) {
-            localfmt = g_strdup_printf("[%" PRId64 "] [ID: %08ld] %s",
-                                       get_clock(), syscall(__NR_gettid), fmt);
-        } else {
+        if (use_syslog) {
+            /* no timestamp needed */
             localfmt = g_strdup_printf("[ID: %08ld] %s", syscall(__NR_gettid),
                                        fmt);
+        } else {
+            /* try formatting a broken-down timestamp */
+            if (clock_gettime(CLOCK_REALTIME, &ts) != -1 &&
+                localtime_r(&ts.tv_sec, &tm) != NULL &&
+                strftime(sec_fmt, sizeof sec_fmt, "%Y-%m-%d %H:%M:%S",
+                         &tm) != 0 &&
+                strftime(zone_fmt, sizeof zone_fmt, "%z", &tm) != 0) {
+                localfmt = g_strdup_printf("[%s.%02ld%s] [ID: %08ld] %s",
+                                           sec_fmt,
+                                           ts.tv_nsec / (10L * 1000 * 1000),
+                                           zone_fmt, syscall(__NR_gettid),
+                                           fmt);
+            } else {
+                /* fall back to a flat timestamp */
+                localfmt = g_strdup_printf("[%" PRId64 "] [ID: %08ld] %s",
+                                           get_clock(), syscall(__NR_gettid),
+                                           fmt);
+            }
         }
         fmt = localfmt;
     }
@@ -3416,6 +3436,9 @@ int main(int argc, char *argv[])
     struct lo_map_elem *reserve_elem;
     int ret = -1;
 
+    /* Initialize time conversion information for localtime_r(). */
+    tzset();
+
     /* Don't mask creation mode, kernel already did that */
     umask(0);
 
Signature · 1 line
2.29.2
#7 lore raw

[PULL 09/15] virtiofsd: Check file type in lo_flush()

In reply to Dr. David Alan Gilbert (git)

From: Vivek Goyal <[email protected]>

Currently lo_flush() is written in such a way that it expects to receive a FLUSH requests on a regular file (and not directories). For example, we call lo_fi_fd() which searches lo->fd_map. If we open directories using opendir(), we keep don't keep track of these in lo->fd_map instead we keep them in lo->dir_map. So we expect lo_flush() to be called on regular files only.

Even linux fuse client calls FLUSH only for regular files and not directories. So put a check for filetype and return EBADF if lo_flush() is called on a non-regular file.

Message-Id: <[email protected]>

---
 tools/virtiofsd/passthrough_ll.c | 6 ++++++
 1 file changed, 6 insertions(+)
tools/virtiofsd/passthrough_ll.c +6 -0
index 4f805cbb82..b00be648d3 100644
@@ -1961,6 +1961,12 @@ static void lo_flush(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi)
         return;
     }
 
+    if (!S_ISREG(inode->filetype)) {
+        lo_inode_put(lo, &inode);
+        fuse_reply_err(req, EBADF);
+        return;
+    }
+
     /* An fd is going away. Cleanup associated posix locks */
     if (lo->posix_lock) {
         pthread_mutex_lock(&inode->plock_mutex);
Signature · 1 line
2.29.2
#8 lore raw

[PULL 04/15] hmp-commands.hx: List abbreviation after command for cont, quit, print

In reply to Dr. David Alan Gilbert (git)

From: Peter Maydell <[email protected]>

We have four HMP commands which have a single-character abbreviated
version: cont ('c'), quit ('q'), print ('p') and help ('h'). For cont, quit and print, we list the abbreviation first in the help documentation and the command name. This has the odd effect that in the full 'help' command list these commands end up sorted out of alphabetical order (they end up after all the other commands that start with the same letter). As it happens, the only place this currently changes the order is for 'cont'.

Abbreviation first is also not a very logical order, and it doesn't match what we use for 'help' (which is 'help|?'). Put the full command name first in both the help text and the .name field for cont, quit and print.

Message-Id: <[email protected]>

---
 hmp-commands.hx | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
hmp-commands.hx +6 -6
index 470a420c2d..73e0832ea1 100644
@@ -40,7 +40,7 @@ SRST
 ERST
 
     {
-        .name       = "q|quit",
+        .name       = "quit|q",
         .args_type  = "",
         .params     = "",
         .help       = "quit the emulator",
@@ -49,7 +49,7 @@ ERST
     },
 
 SRST
-``q`` or ``quit``
+``quit`` or ``q``
   Quit the emulator.
 ERST
 
@@ -401,7 +401,7 @@ SRST
 ERST
 
     {
-        .name       = "c|cont",
+        .name       = "cont|c",
         .args_type  = "",
         .params     = "",
         .help       = "resume emulation",
@@ -409,7 +409,7 @@ ERST
     },
 
 SRST
-``c`` or ``cont``
+``cont`` or ``c``
   Resume emulation.
 ERST
 
@@ -554,7 +554,7 @@ SRST
 ERST
 
     {
-        .name       = "p|print",
+        .name       = "print|p",
         .args_type  = "fmt:/,val:l",
         .params     = "/fmt expr",
         .help       = "print expression value (use $reg for CPU register access)",
@@ -562,7 +562,7 @@ ERST
     },
 
 SRST
-``p`` or ``print/``\ *fmt* *expr*
+``print`` or ``p/``\ *fmt* *expr*
   Print expression value. Only the *format* part of *fmt* is
   used.
 ERST
Signature · 1 line
2.29.2
#9 lore raw

[PULL 11/15] virtiofsd: Remove useless code about send_notify_iov

In reply to Dr. David Alan Gilbert (git)

From: Alex Chen <[email protected]>

The 'ch' will be NULL in the following stack:
send_notify_iov()->fuse_send_msg()->virtio_send_msg(), and this may lead to NULL pointer dereferenced in virtio_send_msg(). But send_notify_iov() was never called, so remove the useless code about send_notify_iov() to fix this problem.

Message-Id: <[email protected]>

---
 tools/virtiofsd/fuse_lowlevel.c | 98 ---------------------------------
 1 file changed, 98 deletions(-)
tools/virtiofsd/fuse_lowlevel.c +0 -98
index d4119e92ab..e94b71110b 100644
@@ -2143,104 +2143,6 @@ static void do_destroy(fuse_req_t req, fuse_ino_t nodeid,
     send_reply_ok(req, NULL, 0);
 }
 
-static int send_notify_iov(struct fuse_session *se, int notify_code,
-                           struct iovec *iov, int count)
-{
-    struct fuse_out_header out = {
-        .error = notify_code,
-    };
-
-    if (!se->got_init) {
-        return -ENOTCONN;
-    }
-
-    iov[0].iov_base = &out;
-    iov[0].iov_len = sizeof(struct fuse_out_header);
-
-    return fuse_send_msg(se, NULL, iov, count);
-}
-
-int fuse_lowlevel_notify_poll(struct fuse_pollhandle *ph)
-{
-    if (ph != NULL) {
-        struct fuse_notify_poll_wakeup_out outarg = {
-            .kh = ph->kh,
-        };
-        struct iovec iov[2];
-
-        iov[1].iov_base = &outarg;
-        iov[1].iov_len = sizeof(outarg);
-
-        return send_notify_iov(ph->se, FUSE_NOTIFY_POLL, iov, 2);
-    } else {
-        return 0;
-    }
-}
-
-int fuse_lowlevel_notify_inval_inode(struct fuse_session *se, fuse_ino_t ino,
-                                     off_t off, off_t len)
-{
-    struct fuse_notify_inval_inode_out outarg = {
-        .ino = ino,
-        .off = off,
-        .len = len,
-    };
-    struct iovec iov[2];
-
-    if (!se) {
-        return -EINVAL;
-    }
-
-    iov[1].iov_base = &outarg;
-    iov[1].iov_len = sizeof(outarg);
-
-    return send_notify_iov(se, FUSE_NOTIFY_INVAL_INODE, iov, 2);
-}
-
-int fuse_lowlevel_notify_inval_entry(struct fuse_session *se, fuse_ino_t parent,
-                                     const char *name, size_t namelen)
-{
-    struct fuse_notify_inval_entry_out outarg = {
-        .parent = parent,
-        .namelen = namelen,
-    };
-    struct iovec iov[3];
-
-    if (!se) {
-        return -EINVAL;
-    }
-
-    iov[1].iov_base = &outarg;
-    iov[1].iov_len = sizeof(outarg);
-    iov[2].iov_base = (void *)name;
-    iov[2].iov_len = namelen + 1;
-
-    return send_notify_iov(se, FUSE_NOTIFY_INVAL_ENTRY, iov, 3);
-}
-
-int fuse_lowlevel_notify_delete(struct fuse_session *se, fuse_ino_t parent,
-                                fuse_ino_t child, const char *name,
-                                size_t namelen)
-{
-    struct fuse_notify_delete_out outarg = {
-        .parent = parent,
-        .child = child,
-        .namelen = namelen,
-    };
-    struct iovec iov[3];
-
-    if (!se) {
-        return -EINVAL;
-    }
-
-    iov[1].iov_base = &outarg;
-    iov[1].iov_len = sizeof(outarg);
-    iov[2].iov_base = (void *)name;
-    iov[2].iov_len = namelen + 1;
-
-    return send_notify_iov(se, FUSE_NOTIFY_DELETE, iov, 3);
-}
-
 int fuse_lowlevel_notify_store(struct fuse_session *se, fuse_ino_t ino,
                                off_t offset, struct fuse_bufvec *bufv)
 {
Signature · 1 line
2.29.2
#10 lore raw

[PULL 10/15] virtiofsd: update FUSE_FORGET comment on "lo_inode.nlookup"

In reply to Dr. David Alan Gilbert (git)

From: Laszlo Ersek <[email protected]>

Miklos confirms it's *only* the FUSE_FORGET request that the client can use for decrementing "lo_inode.nlookup".

Cc "Dr. David Alan Gilbert" <[email protected]>
Cc Miklos Szeredi <[email protected]>
Cc Stefan Hajnoczi <[email protected]>
Fixes 1222f015558fc34cea02aa3a5a92de608c82cec8

Message-Id: <[email protected]>

---
 tools/virtiofsd/passthrough_ll.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/virtiofsd/passthrough_ll.c +1 -1
index b00be648d3..5fb36d9407 100644
@@ -101,7 +101,7 @@ struct lo_inode {
      * This counter keeps the inode alive during the FUSE session.
      * Incremented when the FUSE inode number is sent in a reply
      * (FUSE_LOOKUP, FUSE_READDIRPLUS, etc).  Decremented when an inode is
-     * released by requests like FUSE_FORGET, FUSE_RMDIR, FUSE_RENAME, etc.
+     * released by a FUSE_FORGET request.
      *
      * Note that this value is untrusted because the client can manipulate
      * it arbitrarily using FUSE_FORGET requests.
Signature · 1 line
2.29.2
#11 lore raw

[PULL 08/15] virtiofsd: Disable posix_lock hash table if remote locks are not enabled

In reply to Dr. David Alan Gilbert (git)

From: Vivek Goyal <[email protected]>

If remote posix locks are not enabled (lo->posix_lock == false), then disable code paths taken to initialize inode->posix_lock hash table and corresponding destruction and search etc.

lo_getlk() and lo_setlk() have been modified to return ENOSYS if daemon does not support posix lock but client still sends a lock/unlock request.

Message-Id: <[email protected]>

---
 tools/virtiofsd/passthrough_ll.c | 51 +++++++++++++++++++++-----------
 1 file changed, 34 insertions(+), 17 deletions(-)
tools/virtiofsd/passthrough_ll.c +34 -17
index 80e62b1610..4f805cbb82 100644
@@ -902,10 +902,11 @@ static int lo_do_lookup(fuse_req_t req, fuse_ino_t parent, const char *name,
         inode->key.ino = e->attr.st_ino;
         inode->key.dev = e->attr.st_dev;
         inode->key.mnt_id = mnt_id;
-        pthread_mutex_init(&inode->plock_mutex, NULL);
-        inode->posix_locks = g_hash_table_new_full(
-            g_direct_hash, g_direct_equal, NULL, posix_locks_value_destroy);
-
+        if (lo->posix_lock) {
+            pthread_mutex_init(&inode->plock_mutex, NULL);
+            inode->posix_locks = g_hash_table_new_full(
+                g_direct_hash, g_direct_equal, NULL, posix_locks_value_destroy);
+        }
         pthread_mutex_lock(&lo->mutex);
         inode->fuse_ino = lo_add_inode_mapping(req, inode);
         g_hash_table_insert(lo->inodes, &inode->key, inode);
@@ -1291,12 +1292,13 @@ static void unref_inode(struct lo_data *lo, struct lo_inode *inode, uint64_t n)
     if (!inode->nlookup) {
         lo_map_remove(&lo->ino_map, inode->fuse_ino);
         g_hash_table_remove(lo->inodes, &inode->key);
-        if (g_hash_table_size(inode->posix_locks)) {
-            fuse_log(FUSE_LOG_WARNING, "Hash table is not empty\n");
+        if (lo->posix_lock) {
+            if (g_hash_table_size(inode->posix_locks)) {
+                fuse_log(FUSE_LOG_WARNING, "Hash table is not empty\n");
+            }
+            g_hash_table_destroy(inode->posix_locks);
+            pthread_mutex_destroy(&inode->plock_mutex);
         }
-        g_hash_table_destroy(inode->posix_locks);
-        pthread_mutex_destroy(&inode->plock_mutex);
-
         /* Drop our refcount from lo_do_lookup() */
         lo_inode_put(lo, &inode);
     }
@@ -1772,6 +1774,11 @@ static void lo_getlk(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi,
              ino, fi->flags, fi->lock_owner, lock->l_type, lock->l_start,
              lock->l_len);
 
+    if (!lo->posix_lock) {
+        fuse_reply_err(req, ENOSYS);
+        return;
+    }
+
     inode = lo_inode(req, ino);
     if (!inode) {
         fuse_reply_err(req, EBADF);
@@ -1817,6 +1824,11 @@ static void lo_setlk(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi,
              ino, fi->flags, lock->l_type, lock->l_pid, fi->lock_owner, sleep,
              lock->l_whence, lock->l_start, lock->l_len);
 
+    if (!lo->posix_lock) {
+        fuse_reply_err(req, ENOSYS);
+        return;
+    }
+
     if (sleep) {
         fuse_reply_err(req, EOPNOTSUPP);
         return;
@@ -1941,6 +1953,7 @@ static void lo_flush(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi)
     int res;
     (void)ino;
     struct lo_inode *inode;
+    struct lo_data *lo = lo_data(req);
 
     inode = lo_inode(req, ino);
     if (!inode) {
@@ -1949,12 +1962,14 @@ static void lo_flush(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi)
     }
 
     /* An fd is going away. Cleanup associated posix locks */
-    pthread_mutex_lock(&inode->plock_mutex);
-    g_hash_table_remove(inode->posix_locks, GUINT_TO_POINTER(fi->lock_owner));
-    pthread_mutex_unlock(&inode->plock_mutex);
-
+    if (lo->posix_lock) {
+        pthread_mutex_lock(&inode->plock_mutex);
+        g_hash_table_remove(inode->posix_locks,
+            GUINT_TO_POINTER(fi->lock_owner));
+        pthread_mutex_unlock(&inode->plock_mutex);
+    }
     res = close(dup(lo_fi_fd(req, fi)));
-    lo_inode_put(lo_data(req), &inode);
+    lo_inode_put(lo, &inode);
     fuse_reply_err(req, res == -1 ? errno : 0);
 }
 
@@ -3380,9 +3395,11 @@ static void setup_root(struct lo_data *lo, struct lo_inode *root)
     root->key.mnt_id = mnt_id;
     root->nlookup = 2;
     g_atomic_int_set(&root->refcount, 2);
-    pthread_mutex_init(&root->plock_mutex, NULL);
-    root->posix_locks = g_hash_table_new_full(
-        g_direct_hash, g_direct_equal, NULL, posix_locks_value_destroy);
+    if (lo->posix_lock) {
+        pthread_mutex_init(&root->plock_mutex, NULL);
+        root->posix_locks = g_hash_table_new_full(
+            g_direct_hash, g_direct_equal, NULL, posix_locks_value_destroy);
+    }
 }
 
 static guint lo_key_hash(gconstpointer key)
Signature · 1 line
2.29.2
#12 lore raw

[PULL 13/15] savevm: Remove dead code in save_snapshot()

In reply to Dr. David Alan Gilbert (git)

From: Tuguoyi <[email protected]>

The snapshot in each bs is deleted at the beginning, so there is no need to find the snapshot again.

Message-Id: <[email protected]>

---
 migration/savevm.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)
migration/savevm.c +2 -8
index 5f937a2762..601b5144b8 100644
@@ -2728,7 +2728,7 @@ int qemu_load_device_state(QEMUFile *f)
 int save_snapshot(const char *name, Error **errp)
 {
     BlockDriverState *bs, *bs1;
-    QEMUSnapshotInfo sn1, *sn = &sn1, old_sn1, *old_sn = &old_sn1;
+    QEMUSnapshotInfo sn1, *sn = &sn1;
     int ret = -1, ret2;
     QEMUFile *f;
     int saved_vm_running;
@@ -2797,13 +2797,7 @@ int save_snapshot(const char *name, Error **errp)
     }
 
     if (name) {
-        ret = bdrv_snapshot_find(bs, old_sn, name);
-        if (ret >= 0) {
-            pstrcpy(sn->name, sizeof(sn->name), old_sn->name);
-            pstrcpy(sn->id_str, sizeof(sn->id_str), old_sn->id_str);
-        } else {
-            pstrcpy(sn->name, sizeof(sn->name), name);
-        }
+        pstrcpy(sn->name, sizeof(sn->name), name);
     } else {
         /* cast below needed for OpenBSD where tv_sec is still 'long' */
         localtime_r((const time_t *)&tv.tv_sec, &tm);
Signature · 1 line
2.29.2
#13 lore raw

[PULL 12/15] docs/devel/migration: Improve debugging section a bit

In reply to Dr. David Alan Gilbert (git)

From: Markus Armbruster <[email protected]>

Fix typos, and make the example work out of the box.

Message-Id: <[email protected]>

---
 docs/devel/migration.rst | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
docs/devel/migration.rst +6 -5
index 49112bb27a..ad381b89b2 100644
@@ -53,22 +53,23 @@ savevm/loadvm functionality.
 Debugging
 =========
 
-The migration stream can be analyzed thanks to `scripts/analyze_migration.py`.
+The migration stream can be analyzed thanks to `scripts/analyze-migration.py`.
 
 Example usage:
 
 .. code-block:: shell
 
-  $ qemu-system-x86_64
-   (qemu) migrate "exec:cat > mig"
-  $ ./scripts/analyze_migration.py -f mig
+  $ qemu-system-x86_64 -display none -monitor stdio
+  (qemu) migrate "exec:cat > mig"
+  (qemu) q
+  $ ./scripts/analyze-migration.py -f mig
   {
     "ram (3)": {
         "section sizes": {
             "pc.ram": "0x0000000008000000",
   ...
 
-See also ``analyze_migration.py -h`` help for more options.
+See also ``analyze-migration.py -h`` help for more options.
 
 Common infrastructure
 =====================
Signature · 1 line
2.29.2
#14 lore raw

[PULL 15/15] migration: Don't allow migration if vm is in POSTMIGRATE

In reply to Dr. David Alan Gilbert (git)

From: Tuguoyi <[email protected]>

The following steps will cause qemu assertion failure:
- pause vm by executing 'virsh suspend'
- create external snapshot of memory and disk using 'virsh snapshot-create-as'
- doing the above operation again will cause qemu crash

The backtrace looks like:

    at /build/qemu-5.0/migration/savevm.c:1401
    at /build/qemu-5.0/migration/savevm.c:1453

When the first migration completes, bs->open_flags will set BDRV_O_INACTIVE flag by bdrv_inactivate_all(), and during the second migration the bdrv_inactivate_recurse assert that the bs->open_flags is already BDRV_O_INACTIVE enabled which cause crash.

As Vladimir suggested, this patch makes migrate_prepare check the state of vm and return error if it is in RUN_STATE_POSTMIGRATE state.

Message-Id: <[email protected]>

---
 migration/migration.c | 6 ++++++
 1 file changed, 6 insertions(+)
migration/migration.c +6 -0
index e0dbde4091..f5d4a52c95 100644
@@ -2102,6 +2102,12 @@ static bool migrate_prepare(MigrationState *s, bool blk, bool blk_inc,
         return false;
     }
 
+    if (runstate_check(RUN_STATE_POSTMIGRATE)) {
+        error_setg(errp, "Can't migrate the vm that was paused due to "
+                   "previous migration");
+        return false;
+    }
+
     if (migration_is_blocked(errp)) {
         return false;
     }
Signature · 1 line
2.29.2
#15 lore raw

[PULL 14/15] savevm: Delete snapshots just created in case of error

In reply to Dr. David Alan Gilbert (git)

From: Tuguoyi <[email protected]>

bdrv_all_create_snapshot() can fails with some snapshots created, so it's better to delete those snapshots before returns to the caller

Message-Id: <[email protected]>

---
 migration/savevm.c | 1 +
 1 file changed, 1 insertion(+)
migration/savevm.c +1 -0
index 601b5144b8..4a18c9d897 100644
@@ -2833,6 +2833,7 @@ int save_snapshot(const char *name, Error **errp)
     if (ret < 0) {
         error_setg(errp, "Error while creating snapshot on '%s'",
                    bdrv_get_device_or_node_name(bs));
+        bdrv_all_delete_snapshot(sn->name, &bs, NULL);
         goto the_end;
     }
 
Signature · 1 line
2.29.2
#16 lore raw
In reply to Dr. David Alan Gilbert (git)
Quoted 23 lines · Dr. David Alan Gilbert (git)

From: "Dr. David Alan Gilbert" <[email protected]>

The following changes since commit 75ee62ac606bfc9eb59310b9446df3434bf6e8c2:

Merge remote-tracking branch 'remotes/ehabkost-gl/tags/x86-next-pull-request' into staging (2020-12-17 18:53:36 +0000)

are available in the Git repository at:

git://github.com/dagrh/qemu.git tags/pull-migration-20201218a

for you to fetch changes up to 36d0fe65160d83cb065de9b6fe60114ee127d9f0:

migration: Don't allow migration if vm is in POSTMIGRATE (2020-12-18 10:08:25 +0000)

----------------------------------------------------------------
Monitor, virtiofsd and migration pull

HMP cleanups
Migration fixes
Note the change in behaviour of not allowing a postmigrate migrtion rather than crashing

Quoted 5 lines

Virtiofsd cleanups and fixes
--thread-pool-size=0 for no thread pool (faster for some workloads)

Applied, thanks.

Please update the changelog at https://wiki.qemu.org/ChangeLog/6.0
for any user-visible changes.

-- PMM