'struct ubi_mkvol_request req' is one parameter of the function 'ubi_mkvol'
, this parameter will be passed to kernel and then be checked. It acts as a
local variable in many ubi tests, such as io_basic, io_read, mkvol_bad,
mkvol_basic, etc.
After commit
c355aa465fce ("ubi: expose the volume CRC check skip flag") in
linux-stable, 'struct ubi_mkvol_request' supports a new configuration named
'flags', and req.flags will be checked in kernel function
'verify_mkvol_req'. Currently, there is no initialization for req.flags
before 'ubi_mkvol' invoked. So, req.flags can be an arbitrary number passed
to kernel. When we run ubi tests in qemu (x86_64, kernel image: 5.2.0-rc4),
the following errors may occur:
======================================================================
======================================================================
======================================================================
Test on mtdram, fastmap enabled, VID header offset factor 1
======================================================================
======================================================================
======================================================================
mtdram: 16MiB, PEB size 16KiB, fastmap enabled
Running mkvol_basic /dev/ubi0
Running mkvol_bad /dev/ubi0
[mkvol_bad] test_mkvol():105: ubi_mkvol failed with error 22
(Invalid argument), expected 28 (No space left on device)
[mkvol_bad] test_mkvol():105: bytes =
16060929
Error: mkvol_bad failed
FAILURE
This patch fully initializes every 'struct ubi_mkvol_request req' passed to
'ubi_mkvol', which can fix the bug that the ubi test failed caused by that
req.flags was not initialized. And it is still compatible with old kernel
before kernel commit
c355aa465fce ("ubi: expose the volume CRC check skip
flag").
----------------------------------------
Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
req.vol_id = UBI_VOL_NUM_AUTO;
req.alignment = 1; /* TODO: What is this? */
req.bytes = ubi_device->info.leb_size * max_ebs_per_vol;
+ req.flags = 0;
if (req.bytes == 0 || req.bytes > ubi_device->info.avail_bytes)
req.bytes = ubi_device->info.avail_bytes;
req.vol_type = UBI_DYNAMIC_VOLUME;
req.bytes = dev_info.avail_bytes;
req.vol_type = type;
req.name = name;
+ req.flags = 0;
if (ubi_mkvol(libubi, node, &req)) {
failed("ubi_mkvol");
req.vol_type = type;
req.name = name;
+ req.flags = 0;
for (i = 0; i < sizeof(alignments)/sizeof(int); i++) {
req.vol_id = UBI_VOL_NUM_AUTO;
sprintf(vol_name[i], PROGRAM_NAME":%d", i);
reqests[i].name = vol_name[i];
reqests[i].vol_type = UBI_DYNAMIC_VOLUME;
+ reqests[i].flags = 0;
if (i == THREADS_NUM)
reqests[i].vol_type = UBI_STATIC_VOLUME;
sprintf(vol_nodes[i], UBI_VOLUME_PATTERN, dev_info.dev_num, i);
req.bytes = dev_info.avail_bytes;
req.vol_type = UBI_STATIC_VOLUME;
req.name = name;
+ req.flags = 0;
if (ubi_mkvol(libubi, node, &req)) {
failed("ubi_mkvol");
req.vol_id = UBI_VOL_NUM_AUTO;
req.vol_type = type;
req.name = name;
+ req.flags = 0;
req.alignment = alignments[i];
req.alignment -= req.alignment % dev_info.min_io_size;
req.vol_id = UBI_VOL_NUM_AUTO;
req.vol_type = type;
req.name = name;
+ req.flags = 0;
req.alignment = alignments[i];
req.alignment -= req.alignment % dev_info.min_io_size;
req.bytes = dev_info.avail_bytes;
req.vol_type = UBI_DYNAMIC_VOLUME;
req.name = name;
+ req.flags = 0;
/* Bad volume ID */
req.vol_id = -2;
req.bytes = dev_info.avail_bytes;
req.vol_type = UBI_DYNAMIC_VOLUME;
req.name = name;
+ req.flags = 0;
if (ubi_mkvol(libubi, node, &req)) {
failed("ubi_mkvol");
return -1;
req.vol_type = UBI_DYNAMIC_VOLUME;
req.name = name;
+ req.flags = 0;
if (ubi_mkvol(libubi, node, &req)) {
failed("ubi_mkvol");
req.bytes = dev_info.avail_bytes;
req.vol_type = UBI_DYNAMIC_VOLUME;
req.name = name;
+ req.flags = 0;
if (ubi_mkvol(libubi, node, &req)) {
failed("ubi_mkvol");
req.alignment = 1;
req.bytes = 1;
req.vol_type = UBI_STATIC_VOLUME;
+ req.flags = 0;
sprintf(nm, "%s:%d", name, i);
req.name = nm;
req.vol_type = UBI_DYNAMIC_VOLUME;
sprintf(nm, "%s:%d", name, n);
req.name = nm;
+ req.flags = 0;
while (iter--) {
req.vol_id = UBI_VOL_NUM_AUTO;
req.bytes = MIN_AVAIL_EBS * dev_info.leb_size;
req.vol_type = type;
req.name = name;
+ req.flags = 0;
if (ubi_mkvol(libubi, node, &req)) {
failed("ubi_mkvol");
req.vol_id = UBI_VOL_NUM_AUTO;
req.vol_type = type;
req.name = name;
+ req.flags = 0;
req.alignment = alignments[i];
req.alignment -= req.alignment % dev_info.min_io_size;
req.bytes = dev_info.leb_size;
req.vol_type = UBI_DYNAMIC_VOLUME;
req.name = "rmvol";
+ req.flags = 0;
if (ubi_mkvol(libubi, node, &req)) {
failed("ubi_mkvol");