[pve-devel] [PATCH 2/2] Add patch to use /dev/loop-control
Wolfgang Bumiller
w.bumiller at proxmox.com
Fri Jul 3 15:02:50 CEST 2015
LXC iterates through the /dev directory trying to attach to
existing loop devices, meaning it only uses nodes that
already exist. This patch makes it /dev/loop-control to find
and allocate new ones on the fly.
Fixes #651
---
.../0001-Use-dev-loop-control-if-it-exists.patch | 59 ++++++++++++++++++++++
debian/patches/series | 1 +
2 files changed, 60 insertions(+)
create mode 100644 debian/patches/0001-Use-dev-loop-control-if-it-exists.patch
diff --git a/debian/patches/0001-Use-dev-loop-control-if-it-exists.patch b/debian/patches/0001-Use-dev-loop-control-if-it-exists.patch
new file mode 100644
index 0000000..23732d8
--- /dev/null
+++ b/debian/patches/0001-Use-dev-loop-control-if-it-exists.patch
@@ -0,0 +1,59 @@
+From edd7414a642a52005ebcdd92d5d643b105bbe041 Mon Sep 17 00:00:00 2001
+From: Wolfgang Bumiller <w.bumiller at proxmox.com>
+Date: Fri, 3 Jul 2015 14:10:17 +0200
+Subject: [PATCH] Use /dev/loop-control if it exists
+
+Loop devices can be added on the fly when needed, they're
+not always created beforehand. The loop-control device can
+be used to find and allocate the next available number
+instead of going through the /dev directory contents (which
+is now only a fallback mechanism).
+
+Signed-off-by: Wolfgang Bumiller <w.bumiller at proxmox.com>
+---
+ src/lxc/bdev.c | 22 +++++++++++++++++++++-
+ 1 file changed, 21 insertions(+), 1 deletion(-)
+
+diff --git a/src/lxc/bdev.c b/src/lxc/bdev.c
+index 520652c..5540b49 100644
+--- a/src/lxc/bdev.c
++++ b/src/lxc/bdev.c
+@@ -1868,7 +1868,7 @@ static int loop_detect(const char *path)
+ return 0;
+ }
+
+-static int find_free_loopdev(int *retfd, char *namep)
++static int find_free_loopdev_no_control(int *retfd, char *namep)
+ {
+ struct dirent dirent, *direntp;
+ struct loop_info64 lo;
+@@ -1908,6 +1908,26 @@ static int find_free_loopdev(int *retfd, char *namep)
+ return 0;
+ }
+
++static int find_free_loopdev(int *retfd, char *namep)
++{
++ int rc, fd = -1;
++ int ctl = open("/dev/loop-control", O_RDWR);
++ if (ctl < 0)
++ return find_free_loopdev_no_control(retfd, namep);
++ rc = ioctl(ctl, LOOP_CTL_GET_FREE);
++ if (rc >= 0) {
++ snprintf(namep, 100, "/dev/loop%d", rc);
++ fd = open(namep, O_RDWR);
++ }
++ close(ctl);
++ if (fd == -1) {
++ ERROR("No loop device found");
++ return -1;
++ }
++ *retfd = fd;
++ return 0;
++}
++
+ static int loop_mount(struct bdev *bdev)
+ {
+ int lfd, ffd = -1, ret = -1;
+--
+2.1.4
+
diff --git a/debian/patches/series b/debian/patches/series
index 5c40332..d4cae20 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -6,3 +6,4 @@ do-dot-call-chown_mapped_root-on-etc-pve.patch
use-var-lib-vz-as-default-dir.patch
do-not-use-config-path-for-rootfs.patch
run-lxcnetaddbr.patch
+0001-Use-dev-loop-control-if-it-exists.patch
--
2.1.4
More information about the pve-devel
mailing list