Restore the kernel v5.13 text attribute write behavior
v3 cover Restore the kernel v5.13 text attribute write behavior
Hi Christoph,
This patch series restores the v5.13 text attribute write behavior and also adds unit tests for configfs. Please consider these patches for inclusion in the Linux kernel.
Thanks,
Bart.
Changes compared to v2:
- Modified description of patch 2/3.
Changes compared to v1:
- Instead of making the text attribute write behavior POSIX compliant, restore the v5.13 behavior.
- Added more unit tests.
Bart Van Assche (3):
configfs: Restore the kernel v5.13 text attribute write behavior
kunit: Add support for suite initialization and cleanup
configfs: Add unit tests
fs/configfs/Kconfig | 8 + fs/configfs/Makefile | 2 + fs/configfs/configfs-test.c | 427 ++++++++++++++++++++++++++++++++++++ fs/configfs/file.c | 18 +- include/kunit/test.h | 4 + lib/kunit/test.c | 14 ++ 6 files changed, 461 insertions(+), 12 deletions(-) create mode 100644 fs/configfs/configfs-test.c
PATCH v3 1/3 configfs: Restore the kernel v5.13 text attribute write behavior
Instead of appending new text attribute data at the offset specified by the write() system call, only pass the newly written data to the .store() callback.
--- fs/configfs/file.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-)
fs/configfs/file.c +6 -12
@@ -177,28 +177,22 @@ static ssize_t configfs_bin_read_iter(struct kiocb *iocb, struct iov_iter *to)return retval; } -/* Fill [buffer, buffer + pos) with data coming from @from. */ -static int fill_write_buffer (struct configfs_buffer *buffer,loff_t pos, +/* Fill @buffer with data coming from @from. */ +static int fill_write_buffer (struct configfs_buffer *buffer,struct iov_iter *from) { -loff_t to_copy;int copied; -u8 *to;if (!buffer->page) buffer->page = (char *)__get_free_pages (GFP_KERNEL ,0 );if (!buffer->page)return -ENOMEM ; - to_copy =SIMPLE_ATTR_SIZE -1 - pos; -if (to_copy <=0 ) -return 0 ; - to = buffer->page + pos; - copied =copy_from_iter (to, to_copy, from); + copied =copy_from_iter (buffer->page,SIMPLE_ATTR_SIZE -1 , from); buffer->needs_read_fill =1 ;/* if buf is assumed to contain a string, terminate it by \0, * so e.g. sscanf() can scan the string easily */ - to[copied] =0 ; + buffer->page[copied] =0 ;return copied ? : -EFAULT ; }
@@ -227,10 +221,10 @@ static ssize_t configfs_write_iter(struct kiocb *iocb, struct iov_iter *from) {struct file *file = iocb->ki_filp;struct configfs_buffer *buffer = file->private_data; -ssize_t len; +int len;mutex_lock (&buffer->mutex); - len =fill_write_buffer (buffer, iocb->ki_pos, from); + len =fill_write_buffer (buffer, from);if (len >0 ) len =flush_write_buffer (file, buffer, len);if (len >0 )
PATCH v3 2/3 kunit: Add support for suite initialization and cleanup
In reply to Bart Van AsscheA common feature of unit testing frameworks is support for sharing a test configuration across multiple unit tests. Add this functionality to the KUnit framework. This functionality will be used in the next patch in this series.
--- include/kunit/test.h | 4 ++++ lib/kunit/test.c | 14 ++++++++++++++ 2 files changed, 18 insertions(+)
include/kunit/test.h +4 -0
@@ -215,6 +215,8 @@ static inline char *kunit_status_to_ok_not_ok(enum kunit_status status)* struct kunit_suite - describes a related collection of &struct kunit_case * * @name: the name of the test. Purely informational. +* @init_suite: called once per test suite before the test cases. +* @exit_suite: called once per test suite after all test cases. * @init: called before every test case. * @exit: called after every test case. * @test_cases: a null terminated array of test cases.
@@ -229,6 +231,8 @@ static inline char *kunit_status_to_ok_not_ok(enum kunit_status status)*/ struct kunit_suite {const char name[256 ]; +int (*init_suite)(void ); +void (*exit_suite)(void );int (*init)(struct kunit *test);void (*exit)(struct kunit *test);struct kunit_case *test_cases;
lib/kunit/test.c +14 -0
@@ -397,9 +397,19 @@ int kunit_run_tests(struct kunit_suite *suite) {char param_desc[KUNIT_PARAM_DESC_SIZE ];struct kunit_case *test_case; +int res =0 ;kunit_print_subtest_start (suite); +if (suite->init_suite) + res = suite->init_suite (); + +if (res <0 ) { +kunit_log (KERN_INFO , suite,KUNIT_SUBTEST_INDENT +"# Suite initialization failed (%d)\n" , res); + goto end; + } +kunit_suite_for_each_test_case (suite, test_case) {struct kunit test = { .param_value =NULL , .param_index =0 }; test_case->status =KUNIT_SKIPPED ;
@@ -439,6 +449,10 @@ int kunit_run_tests(struct kunit_suite *suite) test.status_comment); } +if (suite->exit_suite) + suite->exit_suite (); + +end:kunit_print_subtest_end (suite);return 0 ;
PATCH v3 3/3 configfs: Add unit tests
In reply to Bart Van AsscheTesting configfs read and write behavior is non-trivial and tedious. Hence these configfs kunit tests that make it easier to test configfs text and binary attribute support. This is how I run these tests:
set -e
if [ -e .config ]; then
make ARCH=um mrproper
fi
if [ ! -e .kunit/.kunitconfig ]; then
cat <<EOF >.kunit/.kunitconfigCONFIG_CONFIGFS_FS=yCONFIG_CONFIGFS_KUNIT_TEST=yCONFIG_KUNIT=yCONFIG_PROVE_LOCKING=yCONFIG_SYSFS=yCONFIG_UBSAN=y
EOF
cp .kunit/.kunitconfig .kunit/.config
fi./tools/testing/kunit/kunit.py run
--- fs/configfs/Kconfig | 8 + fs/configfs/Makefile | 2 + fs/configfs/configfs-test.c | 427 ++++++++++++++++++++++++++++++++++++ 3 files changed, 437 insertions(+) create mode 100644 fs/configfs/configfs-test.c
fs/configfs/Kconfig +8 -0
@@ -10,3 +10,11 @@ config CONFIGFS_FS Both sysfs and configfs can and should exist together on the same system. One is not a replacement for the other. + +config CONFIGFS_KUNIT_TEST + tristate "Configfs Kunit test" if !KUNIT_ALL_TESTS + depends on CONFIGFS_FS && KUNIT + default KUNIT_ALL_TESTS + help + Run the configfs unit tests at boot time. For more information, see + also the Kunit documentation in Documentation/dev-tools/kunit/.
fs/configfs/Makefile +2 -0
@@ -6,3 +6,5 @@ obj-$(CONFIG_CONFIGFS_FS) += configfs.o configfs-objs := inode.o file.o dir.o symlink.o mount.o item.o + +obj-$(CONFIG_CONFIGFS_KUNIT_TEST) += configfs-test.o
fs/configfs/configfs-test.c new file +427 -0
427 lines not on this page · raw message
kernel test robot
build botRe: [PATCH v3 3/3] configfs: Add unit tests
I love your patch! Yet something to improve:
Hi Bart,
I love your patch! Yet something to improve:
[auto build test ERROR on hch-configfs/for-next]
[also build test ERROR on linus/master v5.14-rc3 next-20210729] [cannot apply to linux/master]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Bart-Van-Assche/Restore-the-kernel-v5-13-text-attribute-write-behavior/20210730-113708 base: git://git.infradead.org/users/hch/configfs.git for-next config: microblaze-randconfig-r036-20210730 (attached as .config) compiler: microblaze-linux-gcc (GCC) 10.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/808490b67fe8580bcfca28bc36abb79d6ec13bd4
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Bart-Van-Assche/Restore-the-kernel-v5-13-text-attribute-write-behavior/20210730-113708 git checkout 808490b67fe8580bcfca28bc36abb79d6ec13bd4
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-10.3.0 make.cross ARCH=microblaze
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>, old ones prefixed by <<):
ERROR: modpost: missing MODULE_LICENSE() in fs/configfs/configfs-test.o
>> ERROR: modpost: "do_mount" [fs/configfs/configfs-test.ko] undefined!
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Quoted 3 lines · Bart Van Assche
This patch series restores the v5.13 text attribute write behavior and also adds unit tests for configfs. Please consider these patches for inclusion in the Linux kernel.
(replying to my own email)
The build bot reported the following for this patch series:
All errors (new ones prefixed by >>, old ones prefixed by <<):
ERROR: modpost: missing MODULE_LICENSE() in fs/configfs/configfs-test.o
Quoted 1 line
Quoted 1 line
ERROR: modpost: "
do_mount" [fs/configfs/configfs-test.ko] undefined!
I will fix these issues and repost this patch series.
Bart.