[PATCH 1/2] erofs-utils: mount: gracefully exit when `erofsmount_nbd()` encounts an error

Yifan Zhao zhaoyifan28 at huawei.com
Tue Dec 16 18:05:56 AEDT 2025


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)`.

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

Signed-off-by: Yifan Zhao <zhaoyifan28 at huawei.com>
---
 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);
+		if (nbdfd > 0) {
+			erofs_nbd_disconnect(nbdfd);
+			close(nbdfd);
+		}
+	}
 	return err;
 }
 
-- 
2.43.0



More information about the Linux-erofs mailing list