]> www.infradead.org Git - mtd-utils.git/commitdiff
ubi-tests: ubi_mkvol_request: Fully initialize 'struct ubi_mkvol_request req'
authorZhihao Cheng <chengzhihao1@huawei.com>
Fri, 14 Jun 2019 12:14:38 +0000 (20:14 +0800)
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>
Sun, 16 Jun 2019 10:27:10 +0000 (12:27 +0200)
'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>
tests/ubi-tests/integ.c
tests/ubi-tests/io_basic.c
tests/ubi-tests/io_paral.c
tests/ubi-tests/io_read.c
tests/ubi-tests/io_update.c
tests/ubi-tests/mkvol_bad.c
tests/ubi-tests/mkvol_basic.c
tests/ubi-tests/mkvol_paral.c
tests/ubi-tests/rsvol.c
tests/ubi-tests/volrefcnt.c

index 1cd064964abfbbd83619e83e669491d22d0461e5..fd38ef5bb6507cb95ac1ab2a7a570f283c6cdadc 100644 (file)
@@ -467,6 +467,7 @@ static void operate_on_ubi_device(struct ubi_device_info *ubi_device)
                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;
index 3a296b4831b2dafec5c7926139cb56d552b3357a..288a351a857cfad4e1115c9fff5f7cd1c6df5f88 100644 (file)
@@ -55,6 +55,7 @@ static int test_basic(int type)
        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");
@@ -102,6 +103,7 @@ static int test_aligned(int type)
 
        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;
index 6c77ec1d110f26049960d52da42773f0c0e06f12..4040b3eca2553da3fef99d326f130fd66166c7a5 100644 (file)
@@ -266,6 +266,7 @@ int main(int argc, char * const argv[])
                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);
index f48db677f655cacfedc34fa443d1297a45260dde..3100ef1350abb9dc77064db0654ae3236df1cd73 100644 (file)
@@ -74,6 +74,7 @@ static int test_static(void)
        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");
@@ -329,6 +330,7 @@ static int test_read(int type)
                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;
index fe3ad7b2da168ee4d3bd38077638e64da9364806..f48df1dbe719c7de3da3b550c06434822c8ec607 100644 (file)
@@ -233,6 +233,7 @@ static int test_update(int type)
                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;
index 486fbab218a3aaebeef40731143d17f1c7f4fe40..7e46726abd30a0974f94c2475cc32b553947afd3 100644 (file)
@@ -48,6 +48,7 @@ static int test_mkvol(void)
        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;
@@ -251,6 +252,7 @@ static int test_rmvol(void)
        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;
index 88d115ad95205d346e776672354b1e7040bcc4ba..c7c6984d89d45d3421b79d025d85c100e0c9434a 100644 (file)
@@ -59,6 +59,7 @@ static int mkvol_alignment(void)
 
                req.vol_type = UBI_DYNAMIC_VOLUME;
                req.name = name;
+               req.flags = 0;
 
                if (ubi_mkvol(libubi, node, &req)) {
                        failed("ubi_mkvol");
@@ -101,6 +102,7 @@ static int mkvol_basic(void)
        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");
@@ -170,6 +172,7 @@ static int mkvol_multiple(void)
                req.alignment = 1;
                req.bytes = 1;
                req.vol_type = UBI_STATIC_VOLUME;
+               req.flags = 0;
 
                sprintf(nm, "%s:%d", name, i);
                req.name = nm;
index 95b5e104ee1598b967543f3e69d7db5f96a52f54..41d5ae09968e9ba3f64153ee8be755663184cb74 100644 (file)
@@ -54,6 +54,7 @@ static void * the_thread(void *ptr)
        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;
index 6bfade9fc16c4a008b04959e9e277a6acaa7297e..921b36f7154ac56a070eee0df42bb4bf6a52c4cb 100644 (file)
@@ -54,6 +54,7 @@ static int test_basic(int type)
        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");
@@ -237,6 +238,7 @@ static int test_rsvol(int type)
                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;
index 591a55a9092fd778ea6821f205a6b36f2dab27c6..328a8ad8604adeb310e99d41b0f4cc9eb1bcc2fe 100644 (file)
@@ -67,6 +67,7 @@ int main(int argc, char * const argv[])
        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");