summaryrefslogtreecommitdiffstats
path: root/src/kernel/xloop_file_fmt_qcow_main.c
diff options
context:
space:
mode:
authorManuel Bentele2020-11-20 07:35:13 +0100
committerManuel Bentele2020-11-20 07:35:13 +0100
commit4cdc802ea38be38edff2b72c9028d7a8af8f8938 (patch)
tree827466eeb6cc4e3c97568f9aeff2d59912b791c6 /src/kernel/xloop_file_fmt_qcow_main.c
parentAdd upstream and compatibility changes for Linux kernel 5.10 and 4.19 (diff)
downloadxloop-4cdc802ea38be38edff2b72c9028d7a8af8f8938.tar.gz
xloop-4cdc802ea38be38edff2b72c9028d7a8af8f8938.tar.xz
xloop-4cdc802ea38be38edff2b72c9028d7a8af8f8938.zip
Add Linux kernel module support for 32-bit architectures (eg. ARM)
This change replaces all 64-bit division and modulo operations with specific Linux kernel macros and functions to support 32-bit hardware architectures. Thus, the xloop kernel modules can also run on 32-bit ARM architectures, such as the Raspberry Pi 1 running Raspberry Pi OS.
Diffstat (limited to 'src/kernel/xloop_file_fmt_qcow_main.c')
-rw-r--r--src/kernel/xloop_file_fmt_qcow_main.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/kernel/xloop_file_fmt_qcow_main.c b/src/kernel/xloop_file_fmt_qcow_main.c
index dfde76d..376273d 100644
--- a/src/kernel/xloop_file_fmt_qcow_main.c
+++ b/src/kernel/xloop_file_fmt_qcow_main.c
@@ -26,6 +26,7 @@
#ifdef CONFIG_ZSTD_DECOMPRESS
#include <linux/zstd.h>
#endif
+#include <linux/math64.h>
#include <xloop/version.h>
@@ -119,7 +120,7 @@ static int __qcow_file_fmt_validate_table(struct xloop_file_fmt *xlo_fmt,
{
struct xloop_file_fmt_qcow_data *qcow_data = xlo_fmt->private_data;
- if (entries > max_size_bytes / entry_len) {
+ if (entries > div_s64(max_size_bytes, entry_len)) {
dev_err(xloop_file_fmt_to_dev(xlo_fmt), "%s too large\n", table_name);
return -EFBIG;
}
@@ -776,7 +777,7 @@ static int qcow_file_fmt_init(struct xloop_file_fmt *xlo_fmt)
/* create cache for L2 */
virtual_disk_size = qcow_data->size;
- max_l2_entries = DIV_ROUND_UP(virtual_disk_size, qcow_data->cluster_size);
+ max_l2_entries = DIV64_U64_ROUND_UP(virtual_disk_size, qcow_data->cluster_size);
max_l2_cache = round_up(
max_l2_entries * xloop_file_fmt_qcow_l2_entry_size(qcow_data),
qcow_data->cluster_size);
@@ -791,7 +792,7 @@ static int qcow_file_fmt_init(struct xloop_file_fmt *xlo_fmt)
l2_cache_entry_size = min(qcow_data->cluster_size, (int)PAGE_SIZE);
/* calculate the number of cache tables */
- l2_cache_size /= l2_cache_entry_size;
+ l2_cache_size = div_u64(l2_cache_size, l2_cache_entry_size);
if (l2_cache_size < QCOW_MIN_L2_CACHE_SIZE) {
l2_cache_size = QCOW_MIN_L2_CACHE_SIZE;
}
@@ -802,8 +803,8 @@ static int qcow_file_fmt_init(struct xloop_file_fmt *xlo_fmt)
goto free_l1_table;
}
- qcow_data->l2_slice_size =
- l2_cache_entry_size / xloop_file_fmt_qcow_l2_entry_size(qcow_data);
+ qcow_data->l2_slice_size = div_u64(l2_cache_entry_size,
+ xloop_file_fmt_qcow_l2_entry_size(qcow_data));
qcow_data->l2_table_cache = xloop_file_fmt_qcow_cache_create(xlo_fmt,
l2_cache_size, l2_cache_entry_size);