Restore the kernel v5.13 text attribute write behavior
v2 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 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 v2 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 v2 2/3 kunit: Add support for suite initialization and cleanup
In reply to Bart Van Assche--- 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 ;
Re: [PATCH v2 2/3] kunit: Add support for suite initialization and cleanup
Quoted 10 lines · Bart Van Assche
Reviewed-by Brendan Higgins <[email protected]>Cc David Gow <[email protected]>Cc Shuah Khan <[email protected]>Cc Bodo Stroesser <[email protected]>Cc Martin K. Petersen <[email protected]>Cc Yanko Kaneti <[email protected]>Signed-off-by Bart Van Assche <[email protected]>---
I know I do not take patches without any changelog text. Maybe other maintainers are more lax :(
Re: [PATCH v2 2/3] kunit: Add support for suite initialization and cleanup
Quoted 12 lines · Greg KH
Quoted 10 lines · Bart Van Assche
Reviewed-by Brendan Higgins <[email protected]>Cc David Gow <[email protected]>Cc Shuah Khan <[email protected]>Cc Bodo Stroesser <[email protected]>Cc Martin K. Petersen <[email protected]>Cc Yanko Kaneti <[email protected]>Signed-off-by Bart Van Assche <[email protected]>---
Quoted 2 lines
I know I do not take patches without any changelog text. Maybe other maintainers are more lax :(
Almost every patch from me has an elaborate changelog. For this patch I chose not to add a changelog since I think that the subject is self-explanatory?
Thanks,
Bart.
Shuah Khan
maintainerRe: [PATCH v2 2/3] kunit: Add support for suite initialization and cleanup
Quoted 13 lines · Bart Van Assche
Quoted 12 lines · Greg KH
Quoted 10 lines · Bart Van Assche
Reviewed-by Brendan Higgins <[email protected]>Cc David Gow <[email protected]>Cc Shuah Khan <[email protected]>Cc Bodo Stroesser <[email protected]>Cc Martin K. Petersen <[email protected]>Cc Yanko Kaneti <[email protected]>Signed-off-by Bart Van Assche <[email protected]>---
Quoted 5 lines
Quoted 2 lines
I know I do not take patches without any changelog text. Maybe other maintainers are more lax :(
Almost every patch from me has an elaborate changelog. For this patch I chose not to add a changelog since I think that the subject is self-explanatory?
I don't take patches without change logs either. I can't say the subject tells me what you are doing.
Please add a change log.
thanks,
-- Shuah
Re: [PATCH v2 2/3] kunit: Add support for suite initialization and cleanup
Quoted 17 lines · Shuah Khan
Quoted 16 lines · Bart Van Assche
Quoted 14 lines · Greg KH
Quoted 10 lines · Bart Van Assche
Reviewed-by Brendan Higgins <[email protected]>Cc David Gow <[email protected]>Cc Shuah Khan <[email protected]>Cc Bodo Stroesser <[email protected]>Cc Martin K. Petersen <[email protected]>Cc Yanko Kaneti <[email protected]>Signed-off-by Bart Van Assche <[email protected]>---
I know I do not take patches without any changelog text. Maybe other maintainers are more lax :(
Quoted 6 lines
Quoted 1 line
Almost every patch from me has an elaborate changelog. For this patch I chose not to add a changelog since I think that the subject is self-explanatory?
I don't take patches without change logs either. I can't say the subject tells me what you are doing.
Please add a change log.
I will add a changelog. But please note that this patch has been sent to Christoph as configfs maintainer.
Bart.
Shuah Khan
maintainerRe: [PATCH v2 2/3] kunit: Add support for suite initialization and cleanup
Quoted 18 lines · Bart Van Assche
Quoted 17 lines · Shuah Khan
Quoted 16 lines · Bart Van Assche
Quoted 14 lines · Greg KH
Quoted 10 lines · Bart Van Assche
Reviewed-by Brendan Higgins <[email protected]>Cc David Gow <[email protected]>Cc Shuah Khan <[email protected]>Cc Bodo Stroesser <[email protected]>Cc Martin K. Petersen <[email protected]>Cc Yanko Kaneti <[email protected]>Signed-off-by Bart Van Assche <[email protected]>---
I know I do not take patches without any changelog text. Maybe other maintainers are more lax :(
Quoted 9 lines
Quoted 6 lines
Quoted 1 line
Almost every patch from me has an elaborate changelog. For this patch I chose not to add a changelog since I think that the subject is self-explanatory?
I don't take patches without change logs either. I can't say the subject tells me what you are doing.
Please add a change log.
I will add a changelog. But please note that this patch has been sent to Christoph as configfs maintainer.
Sure. This is a kunit patch - hence Kunit maintainers can comment on it. Besides the comment is about missing change log which is rather basic kernel dev 101.
Please take a look at Documentation/process/submitting-patches.rst for information on commit logs.
thanks,
-- Shuah
Re: [PATCH v2 2/3] kunit: Add support for suite initialization and cleanup
Quoted 2 lines · Shuah Khan
Please take a look at
Documentation/process/submitting-patches.rstfor information on commit logs.
As one can see below, I'm already familiar with the kernel development process:
$ git log --author="Bart Van Assche" | grep -c ^commit 1664
Bart.
Shuah Khan
maintainerRe: [PATCH v2 2/3] kunit: Add support for suite initialization and cleanup
Quoted 9 lines · Bart Van Assche
Quoted 2 lines · Shuah Khan
Please take a look at
Documentation/process/submitting-patches.rstfor information on commit logs.As one can see below, I'm already familiar with the kernel development process:
$ git log --author="Bart Van Assche" | grep -c ^commit 1664
Terrific. I am glad you know the process.
thanks,
-- Shuah
PATCH v2 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