On 2025/12/16 15:18, Gao Xiang wrote:
Hi Yifan,

On 2025/12/16 16:05, Yifan Zhao wrote:
If the main process of `erofsmount_nbd()` encounters an error after the
nbd device has been successfully set up, it fails to disconnect it
before exiting, resulting in the subprocess not being cleaned up and
blocked on `ioctl(nbdfd, NBD_DO_IT, 0)`.

Do you have a simple test case (IOWs, how do you test this?)
And is it possible to move the test case to erofs-utils tests?

How to reproduce the issue:


    mount.erofs -t erofs.nbd oci.layer=0 <some_non_erofs_image> /mnt/erofs


After the command fails, a leftover mount.erofs process (forked in erofsmount_nbd()) remains uncleaned.

In fact, I don't have a formal test case—I encountered this while trying out mount.erofs. Since this is an end-to-end scenario rather than unit test, would you recommend adding a regression test for it (and other discovered mount.erofs issues) in our GitHub CI? (I'm happy to implement it.)

This patch resolves the issue by invoking `erofs_nbd_disconnect()`
before exiting on error.

See below.


Signed-off-by: Yifan Zhao <[email protected]>
---
  lib/liberofs_nbd.h | 2 +-
  mount/main.c       | 8 ++++++++
  2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/lib/liberofs_nbd.h b/lib/liberofs_nbd.h
index 260605a..93daa24 100644
--- a/lib/liberofs_nbd.h
+++ b/lib/liberofs_nbd.h
@@ -28,7 +28,7 @@ struct erofs_nbd_request {
          char   handle[8];    /* older spelling of cookie */
      };
      u64 from;
-        u32 len;
+    u32 len;
  } __packed;
    /* 30-day timeout for NBD recovery */
diff --git a/mount/main.c b/mount/main.c
index 758e8f8..a093167 100644
--- a/mount/main.c
+++ b/mount/main.c
@@ -1206,6 +1206,14 @@ static int erofsmount_nbd(struct erofs_nbd_source *source,
                  free(id);
          }
      }
+
+    if (err < 0) {
+        nbdfd = open(nbdpath, O_RDWR);

I'm not sure if it's a best-practice (is it possible
nbdpath can be reused?)

Could we just kill the subprocess instead?

Also ioctl is discouraged and netlink is preferred now.

I will try to give a graceful solution later.

Thanks,

Yifan Zhao

Thanks,
Gao Xiang

+        if (nbdfd > 0) {
+            erofs_nbd_disconnect(nbdfd);
+            close(nbdfd);
+        }
+    }
      return err;
  }


Reply via email to