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?


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.

Thanks,
Gao Xiang

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


Reply via email to