Message ID | 20180910120513.14069-1-kewal@zilogic.com |
---|---|
State | Changes Requested |
Headers | show |
Series | [v1] Test statx syscall for SYNC_FLAGS | expand |
Hello, kewal <kewal@zilogic.com> writes: > * statx06.c :- > > Testcase 1: AT_STATX_DONT_SYNC > With AT_STATX_DONT_SYNC server changes should not get sync with client. > > Testcase 2: AT_STATX_FORCE_SYNC > With AT_STATX_FORCE_SYNC server changes should get sync with client. > > Signed-off-by: Kewal Ukunde <kewal@zilogic.com> > Signed-off-by: Vaishnavi.d <vaishnavi.d@zilogic.com> > Signed-off-by: Tarun.T.U <tarun@zilogic.com> > --- > runtest/syscalls | 1 + > testcases/kernel/syscalls/statx/.gitignore | 1 + > testcases/kernel/syscalls/statx/statx06.c | 183 +++++++++++++++++++++++++++++ > 3 files changed, 185 insertions(+) > create mode 100644 testcases/kernel/syscalls/statx/statx06.c > > diff --git a/runtest/syscalls b/runtest/syscalls > index 0d0be7713..71b83b25c 100644 > --- a/runtest/syscalls > +++ b/runtest/syscalls > @@ -1504,3 +1504,4 @@ statx02 statx02 > statx03 statx03 > statx04 statx04 > statx05 statx05 > +statx06 statx06 > diff --git a/testcases/kernel/syscalls/statx/.gitignore b/testcases/kernel/syscalls/statx/.gitignore > index 209fc3a33..c1ceddabf 100644 > --- a/testcases/kernel/syscalls/statx/.gitignore > +++ b/testcases/kernel/syscalls/statx/.gitignore > @@ -3,3 +3,4 @@ > /statx03 > /statx04 > /statx05 > +/statx06 > diff --git a/testcases/kernel/syscalls/statx/statx06.c b/testcases/kernel/syscalls/statx/statx06.c > new file mode 100644 > index 000000000..8b66bf832 > --- /dev/null > +++ b/testcases/kernel/syscalls/statx/statx06.c > @@ -0,0 +1,183 @@ > +// SPDX-License-Identifier: GPL-2.0-or-later > +/* > + * Copyright (c) Zilogic Systems Pvt. Ltd., 2018 > + * Email : code@zilogic.com > + */ > + > +/* > + * Test statx > + * > + * This code tests the following flags: > + * 1) AT_STATX_FORCE_SYNC > + * 2) AT_STATX_DONT_SYNC > + * > + * By exportfs cmd creating NFS setup. > + * > + * A test file is created in server folder and statx is being > + * done in client folder. > + * > + * TESTCASE 1: > + * BY AT_STATX_SYNC_AS_STAT getting predefined mode value. > + * Then, by using AT_STATX_FORCE_SYNC getting new updated vaue > + * from server file changes. > + * > + * TESTCASE 2: > + * BY AT_STATX_SYNC_AS_STAT getting predefined mode value. > + * AT_STATX_FORCE_SYNC is called to create cache data of the file. > + * Then, by using DONT_SYNC_FILE getting old cached data in client folder, > + * but mode has been chaged in server file. > + * > + * Minimum kernel version required is 4.11. > + */ > + > +#include <netdb.h> > +#include <stdio.h> > +#include <stdlib.h> > +#include "tst_test.h" > +#include "lapi/stat.h" > + > +#define MODE(X) (X & (~S_IFMT)) > +#define BUFF_SIZE 512 > +#define DEFAULT_MODE 0644 > +#define CURRENT_MODE 0777 > + > +#define CLIENT_PATH "client" > +#define SERVER_PATH "server" > +#define FORCE_SYNC_FILE "force_sync_file" > +#define DONT_SYNC_FILE "dont_sync_file" > + > +static char cwd[BUFF_SIZE]; > +static char cmd[BUFF_SIZE]; > + > +static int get_mode(char *file_name, int flag_type, char *flag_name) > +{ > + char client_path[BUFF_SIZE]; > + struct statx buff; > + > + sprintf(client_path, "%s/%s/%s", cwd, CLIENT_PATH, file_name); > + > + TEST(statx(AT_FDCWD, client_path, flag_type, STATX_ALL, &buff)); > + > + if (TST_RET == -1) > + tst_brk(TFAIL | TST_ERR, > + "statx(AT_FDCWD, %s, %s, STATX_ALL, &buff)", > + file_name, flag_name); > + else > + tst_res(TINFO, "statx(AT_FDCWD, %s, %s, STATX_ALL, &buff)", > + file_name, flag_name); Seems like something strange is happening with the whitespace. > + > + return buff.stx_mode; > +} > + > +static void test_for_dont_sync(void) > +{ > + unsigned int cur_mode; > + char server_path[BUFF_SIZE]; > + > + sprintf(server_path, "%s/%s/%s", cwd, SERVER_PATH, DONT_SYNC_FILE); > + > + get_mode(DONT_SYNC_FILE, AT_STATX_FORCE_SYNC, > + "AT_STATX_FORCE_SYNC"); > + > + SAFE_CHMOD(server_path, CURRENT_MODE); > + cur_mode = get_mode(DONT_SYNC_FILE, AT_STATX_DONT_SYNC, > + "AT_STATX_DONT_SYNC"); > + > + if (DEFAULT_MODE == MODE(cur_mode)) Try running check_patch from the kernel on this: WARNING: Comparisons should place the constant on the right side of the test #86: FILE: statx06.c:86: + if (DEFAULT_MODE == MODE(cur_mode)) > + tst_res(TPASS, > + "statx() with AT_STATX_DONT_SYNC for mode %o %o", > + DEFAULT_MODE, (cur_mode & ~S_IFMT)); > + else > + tst_res(TFAIL, > + "statx() with AT_STATX_DONT_SYNC for mode %o %o", > + DEFAULT_MODE, (cur_mode & ~S_IFMT)); > +} > + > +static void test_for_force_sync(void) > +{ > + unsigned int cur_mode; > + char server_path[BUFF_SIZE]; > + > + sprintf(server_path, "%s/%s/%s", cwd, SERVER_PATH, FORCE_SYNC_FILE); > + > + SAFE_CHMOD(server_path, CURRENT_MODE); > + cur_mode = get_mode(FORCE_SYNC_FILE, AT_STATX_FORCE_SYNC, > + "AT_STATX_FORCE_SYNC"); > + > + if (CURRENT_MODE == MODE(cur_mode)) > + tst_res(TPASS, > + "statx() with AT_STATX_FORCE_SYNC for mode %o %o", > + CURRENT_MODE, (cur_mode & ~S_IFMT)); > + else > + tst_res(TFAIL, > + "statx() with AT_STATX_FORCE_SYNC for mode %o %o", > + CURRENT_MODE, (cur_mode & ~S_IFMT)); > +} > + > +struct test_cases { > + void (*func)(void); > +} tcases[] = { > + {test_for_dont_sync}, > + {test_for_force_sync} > +}; > + > +static void test_statx(unsigned int nr) > +{ > + struct test_cases *tc = &tcases[nr]; > + > + tc->func(); > +} > + > +static void setup(void) > +{ > + char force_sync_file[BUFF_SIZE]; > + char dont_sync_file[BUFF_SIZE]; > + char server_path[BUFF_SIZE]; > + char client_path[BUFF_SIZE]; > + char mount_data[BUFF_SIZE]; > + char *ip = "127.0.0.1"; > + > + TESTPTR(getcwd(cwd, BUFF_SIZE)); > + if (TST_RET_PTR == NULL) > + tst_brk(TBROK | TST_ERR, "Failed to get PWD"); > + > + sprintf(force_sync_file, "%s/%s", SERVER_PATH, FORCE_SYNC_FILE); > + sprintf(dont_sync_file, "%s/%s", SERVER_PATH, DONT_SYNC_FILE); > + > + SAFE_MKDIR(SERVER_PATH, DEFAULT_MODE); > + SAFE_MKDIR(CLIENT_PATH, DEFAULT_MODE); > + SAFE_CREAT(force_sync_file, DEFAULT_MODE); > + SAFE_CREAT(dont_sync_file, DEFAULT_MODE); > + > + sprintf(server_path, ":%s/%s", cwd, SERVER_PATH); > + sprintf(client_path, "%s/%s", cwd, CLIENT_PATH); > + sprintf(mount_data, "addr=%s", ip); I get a lot of warnings when compiling with gcc8 like statx06.c:152:27: warning: ‘/’ directive writing 1 byte into a region of size between 0 and 511 [-Wformat-overflow=] sprintf(server_path, ":%s/%s", cwd, SERVER_PATH); > + > + sprintf(cmd, > + "exportfs -i -o no_root_squash,rw,sync,no_subtree_check *%s", > + server_path); Must we use an absolute path here and when mounting? > + > + if (WEXITSTATUS(tst_system(cmd)) == 127) > + tst_brk(TBROK | TST_ERR, "%s not found", cmd); This should probably be just TCONF as we shouldn't expect all systems to support running an NFS server. Also you should check for other errors. > + > + SAFE_MOUNT(server_path, client_path, "nfs", 0, mount_data); > +} > + > +static void cleanup(void) > +{ > + if (WEXITSTATUS(tst_system("exportfs -ua")) == 127) > + tst_brk(TBROK | TST_ERR, "%s", cmd); > + > + SAFE_UMOUNT(CLIENT_PATH); > +} > + > +static struct tst_test test = { > + .tcnt = ARRAY_SIZE(tcases), > + .test = test_statx, > + .setup = setup, > + .cleanup = cleanup, > + .min_kver = "4.11", > + .needs_tmpdir = 1, > + .dev_fs_type = "nfs", > + .needs_root = 1, > +}; > -- > 2.11.0 -- Thank you, Richard.
Hi Richard, On Monday 10 September 2018 07:30 PM, Richard Palethorpe wrote: > Hello, > > kewal <kewal@zilogic.com> writes: > >> * statx06.c :- >> >> Testcase 1: AT_STATX_DONT_SYNC >> With AT_STATX_DONT_SYNC server changes should not get sync with >> client. >> >> Testcase 2: AT_STATX_FORCE_SYNC >> With AT_STATX_FORCE_SYNC server changes should get sync with client. >> >> Signed-off-by: Kewal Ukunde <kewal@zilogic.com> >> Signed-off-by: Vaishnavi.d <vaishnavi.d@zilogic.com> >> Signed-off-by: Tarun.T.U <tarun@zilogic.com> >> --- >> runtest/syscalls | 1 + >> testcases/kernel/syscalls/statx/.gitignore | 1 + >> testcases/kernel/syscalls/statx/statx06.c | 183 >> +++++++++++++++++++++++++++++ >> 3 files changed, 185 insertions(+) >> create mode 100644 testcases/kernel/syscalls/statx/statx06.c >> >> diff --git a/runtest/syscalls b/runtest/syscalls >> index 0d0be7713..71b83b25c 100644 >> --- a/runtest/syscalls >> +++ b/runtest/syscalls >> @@ -1504,3 +1504,4 @@ statx02 statx02 >> statx03 statx03 >> statx04 statx04 >> statx05 statx05 >> +statx06 statx06 >> diff --git a/testcases/kernel/syscalls/statx/.gitignore >> b/testcases/kernel/syscalls/statx/.gitignore >> index 209fc3a33..c1ceddabf 100644 >> --- a/testcases/kernel/syscalls/statx/.gitignore >> +++ b/testcases/kernel/syscalls/statx/.gitignore >> @@ -3,3 +3,4 @@ >> /statx03 >> /statx04 >> /statx05 >> +/statx06 >> diff --git a/testcases/kernel/syscalls/statx/statx06.c >> b/testcases/kernel/syscalls/statx/statx06.c >> new file mode 100644 >> index 000000000..8b66bf832 >> --- /dev/null >> +++ b/testcases/kernel/syscalls/statx/statx06.c >> @@ -0,0 +1,183 @@ >> +// SPDX-License-Identifier: GPL-2.0-or-later >> +/* >> + * Copyright (c) Zilogic Systems Pvt. Ltd., 2018 >> + * Email : code@zilogic.com >> + */ >> + >> +/* >> + * Test statx >> + * >> + * This code tests the following flags: >> + * 1) AT_STATX_FORCE_SYNC >> + * 2) AT_STATX_DONT_SYNC >> + * >> + * By exportfs cmd creating NFS setup. >> + * >> + * A test file is created in server folder and statx is being >> + * done in client folder. >> + * >> + * TESTCASE 1: >> + * BY AT_STATX_SYNC_AS_STAT getting predefined mode value. >> + * Then, by using AT_STATX_FORCE_SYNC getting new updated vaue >> + * from server file changes. >> + * >> + * TESTCASE 2: >> + * BY AT_STATX_SYNC_AS_STAT getting predefined mode value. >> + * AT_STATX_FORCE_SYNC is called to create cache data of the file. >> + * Then, by using DONT_SYNC_FILE getting old cached data in client >> folder, >> + * but mode has been chaged in server file. >> + * >> + * Minimum kernel version required is 4.11. >> + */ >> + >> +#include <netdb.h> >> +#include <stdio.h> >> +#include <stdlib.h> >> +#include "tst_test.h" >> +#include "lapi/stat.h" >> + >> +#define MODE(X) (X & (~S_IFMT)) >> +#define BUFF_SIZE 512 >> +#define DEFAULT_MODE 0644 >> +#define CURRENT_MODE 0777 >> + >> +#define CLIENT_PATH "client" >> +#define SERVER_PATH "server" >> +#define FORCE_SYNC_FILE "force_sync_file" >> +#define DONT_SYNC_FILE "dont_sync_file" >> + >> +static char cwd[BUFF_SIZE]; >> +static char cmd[BUFF_SIZE]; >> + >> +static int get_mode(char *file_name, int flag_type, char *flag_name) >> +{ >> + char client_path[BUFF_SIZE]; >> + struct statx buff; >> + >> + sprintf(client_path, "%s/%s/%s", cwd, CLIENT_PATH, file_name); >> + >> + TEST(statx(AT_FDCWD, client_path, flag_type, STATX_ALL, &buff)); >> + >> + if (TST_RET == -1) >> + tst_brk(TFAIL | TST_ERR, >> + "statx(AT_FDCWD, %s, %s, STATX_ALL, &buff)", >> + file_name, flag_name); >> + else >> + tst_res(TINFO, "statx(AT_FDCWD, %s, %s, STATX_ALL, &buff)", >> + file_name, flag_name); > Seems like something strange is happening with the whitespace. > >> + >> + return buff.stx_mode; >> +} >> + >> +static void test_for_dont_sync(void) >> +{ >> + unsigned int cur_mode; >> + char server_path[BUFF_SIZE]; >> + >> + sprintf(server_path, "%s/%s/%s", cwd, SERVER_PATH, DONT_SYNC_FILE); >> + >> + get_mode(DONT_SYNC_FILE, AT_STATX_FORCE_SYNC, >> + "AT_STATX_FORCE_SYNC"); >> + >> + SAFE_CHMOD(server_path, CURRENT_MODE); >> + cur_mode = get_mode(DONT_SYNC_FILE, AT_STATX_DONT_SYNC, >> + "AT_STATX_DONT_SYNC"); >> + >> + if (DEFAULT_MODE == MODE(cur_mode)) > Try running check_patch from the kernel on this: > > WARNING: Comparisons should place the constant on the right side of > the test > #86: FILE: statx06.c:86: > + if (DEFAULT_MODE == MODE(cur_mode)) > >> + tst_res(TPASS, >> + "statx() with AT_STATX_DONT_SYNC for mode %o %o", >> + DEFAULT_MODE, (cur_mode & ~S_IFMT)); >> + else >> + tst_res(TFAIL, >> + "statx() with AT_STATX_DONT_SYNC for mode %o %o", >> + DEFAULT_MODE, (cur_mode & ~S_IFMT)); >> +} >> + >> +static void test_for_force_sync(void) >> +{ >> + unsigned int cur_mode; >> + char server_path[BUFF_SIZE]; >> + >> + sprintf(server_path, "%s/%s/%s", cwd, SERVER_PATH, >> FORCE_SYNC_FILE); >> + >> + SAFE_CHMOD(server_path, CURRENT_MODE); >> + cur_mode = get_mode(FORCE_SYNC_FILE, AT_STATX_FORCE_SYNC, >> + "AT_STATX_FORCE_SYNC"); >> + >> + if (CURRENT_MODE == MODE(cur_mode)) >> + tst_res(TPASS, >> + "statx() with AT_STATX_FORCE_SYNC for mode %o %o", >> + CURRENT_MODE, (cur_mode & ~S_IFMT)); >> + else >> + tst_res(TFAIL, >> + "statx() with AT_STATX_FORCE_SYNC for mode %o %o", >> + CURRENT_MODE, (cur_mode & ~S_IFMT)); >> +} >> + >> +struct test_cases { >> + void (*func)(void); >> +} tcases[] = { >> + {test_for_dont_sync}, >> + {test_for_force_sync} >> +}; >> + >> +static void test_statx(unsigned int nr) >> +{ >> + struct test_cases *tc = &tcases[nr]; >> + >> + tc->func(); >> +} >> + >> +static void setup(void) >> +{ >> + char force_sync_file[BUFF_SIZE]; >> + char dont_sync_file[BUFF_SIZE]; >> + char server_path[BUFF_SIZE]; >> + char client_path[BUFF_SIZE]; >> + char mount_data[BUFF_SIZE]; >> + char *ip = "127.0.0.1"; >> + >> + TESTPTR(getcwd(cwd, BUFF_SIZE)); >> + if (TST_RET_PTR == NULL) >> + tst_brk(TBROK | TST_ERR, "Failed to get PWD"); >> + >> + sprintf(force_sync_file, "%s/%s", SERVER_PATH, FORCE_SYNC_FILE); >> + sprintf(dont_sync_file, "%s/%s", SERVER_PATH, DONT_SYNC_FILE); >> + >> + SAFE_MKDIR(SERVER_PATH, DEFAULT_MODE); >> + SAFE_MKDIR(CLIENT_PATH, DEFAULT_MODE); >> + SAFE_CREAT(force_sync_file, DEFAULT_MODE); >> + SAFE_CREAT(dont_sync_file, DEFAULT_MODE); >> + >> + sprintf(server_path, ":%s/%s", cwd, SERVER_PATH); >> + sprintf(client_path, "%s/%s", cwd, CLIENT_PATH); >> + sprintf(mount_data, "addr=%s", ip); > I get a lot of warnings when compiling with gcc8 like > > statx06.c:152:27: warning: ‘/’ directive writing 1 byte into a region > of size between 0 and 511 [-Wformat-overflow=] > sprintf(server_path, ":%s/%s", cwd, SERVER_PATH); > > >> + >> + sprintf(cmd, >> + "exportfs -i -o no_root_squash,rw,sync,no_subtree_check >> *%s", >> + server_path); > Must we use an absolute path here and when mounting? Yes, The problem with using relative path is exportfs writes the exact relative path to /var/lib/nfs/stab from where mount refers from. Because of this, ultimately mount fails. So, we are using absolute path in both cases. >> + >> + if (WEXITSTATUS(tst_system(cmd)) == 127) >> + tst_brk(TBROK | TST_ERR, "%s not found", cmd); > This should probably be just TCONF as we shouldn't expect all systems to > support running an NFS server. Also you should check for other errors. > >> + >> + SAFE_MOUNT(server_path, client_path, "nfs", 0, mount_data); >> +} >> + >> +static void cleanup(void) >> +{ >> + if (WEXITSTATUS(tst_system("exportfs -ua")) == 127) >> + tst_brk(TBROK | TST_ERR, "%s", cmd); >> + >> + SAFE_UMOUNT(CLIENT_PATH); >> +} >> + >> +static struct tst_test test = { >> + .tcnt = ARRAY_SIZE(tcases), >> + .test = test_statx, >> + .setup = setup, >> + .cleanup = cleanup, >> + .min_kver = "4.11", >> + .needs_tmpdir = 1, >> + .dev_fs_type = "nfs", >> + .needs_root = 1, >> +}; >> -- >> 2.11.0 > > -- > Thank you, > Richard. Regards, Kewal <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> </head> <body text="#000000" bgcolor="#FFFFFF"> <div class="moz-text-flowed" style="font-family: -moz-fixed; font-size: 12px;" lang="x-unicode">Hi Richard, <br> <br> <br> On Monday 10 September 2018 07:30 PM, Richard Palethorpe wrote: <br> <blockquote type="cite" style="color: #000000;">Hello, <br> <br> kewal <a class="moz-txt-link-rfc2396E" href="mailto:kewal@zilogic.com"><kewal@zilogic.com></a> writes: <br> <br> <blockquote type="cite" style="color: #000000;">* statx06.c :- <br> <br> Testcase 1: AT_STATX_DONT_SYNC <br> With AT_STATX_DONT_SYNC server changes should not get sync with client. <br> <br> Testcase 2: AT_STATX_FORCE_SYNC <br> With AT_STATX_FORCE_SYNC server changes should get sync with client. <br> <br> Signed-off-by: Kewal Ukunde <a class="moz-txt-link-rfc2396E" href="mailto:kewal@zilogic.com"><kewal@zilogic.com></a> <br> Signed-off-by: Vaishnavi.d <a class="moz-txt-link-rfc2396E" href="mailto:vaishnavi.d@zilogic.com"><vaishnavi.d@zilogic.com></a> <br> Signed-off-by: Tarun.T.U <a class="moz-txt-link-rfc2396E" href="mailto:tarun@zilogic.com"><tarun@zilogic.com></a> <br> --- <br> runtest/syscalls | 1 + <br> testcases/kernel/syscalls/statx/.gitignore | 1 + <br> testcases/kernel/syscalls/statx/statx06.c | 183 +++++++++++++++++++++++++++++ <br> 3 files changed, 185 insertions(+) <br> create mode 100644 testcases/kernel/syscalls/statx/statx06.c <br> <br> diff --git a/runtest/syscalls b/runtest/syscalls <br> index 0d0be7713..71b83b25c 100644 <br> --- a/runtest/syscalls <br> +++ b/runtest/syscalls <br> @@ -1504,3 +1504,4 @@ statx02 statx02 <br> statx03 statx03 <br> statx04 statx04 <br> statx05 statx05 <br> +statx06 statx06 <br> diff --git a/testcases/kernel/syscalls/statx/.gitignore b/testcases/kernel/syscalls/statx/.gitignore <br> index 209fc3a33..c1ceddabf 100644 <br> --- a/testcases/kernel/syscalls/statx/.gitignore <br> +++ b/testcases/kernel/syscalls/statx/.gitignore <br> @@ -3,3 +3,4 @@ <br> /statx03 <br> /statx04 <br> /statx05 <br> +/statx06 <br> diff --git a/testcases/kernel/syscalls/statx/statx06.c b/testcases/kernel/syscalls/statx/statx06.c <br> new file mode 100644 <br> index 000000000..8b66bf832 <br> --- /dev/null <br> +++ b/testcases/kernel/syscalls/statx/statx06.c <br> @@ -0,0 +1,183 @@ <br> +// SPDX-License-Identifier: GPL-2.0-or-later <br> +/* <br> + * Copyright (c) Zilogic Systems Pvt. Ltd., 2018 <br> + * Email : <a class="moz-txt-link-abbreviated" href="mailto:code@zilogic.com">code@zilogic.com</a> <br> + */ <br> + <br> +/* <br> + * Test statx <br> + * <br> + * This code tests the following flags: <br> + * 1) AT_STATX_FORCE_SYNC <br> + * 2) AT_STATX_DONT_SYNC <br> + * <br> + * By exportfs cmd creating NFS setup. <br> + * <br> + * A test file is created in server folder and statx is being <br> + * done in client folder. <br> + * <br> + * TESTCASE 1: <br> + * BY AT_STATX_SYNC_AS_STAT getting predefined mode value. <br> + * Then, by using AT_STATX_FORCE_SYNC getting new updated vaue <br> + * from server file changes. <br> + * <br> + * TESTCASE 2: <br> + * BY AT_STATX_SYNC_AS_STAT getting predefined mode value. <br> + * AT_STATX_FORCE_SYNC is called to create cache data of the file. <br> + * Then, by using DONT_SYNC_FILE getting old cached data in client folder, <br> + * but mode has been chaged in server file. <br> + * <br> + * Minimum kernel version required is 4.11. <br> + */ <br> + <br> +#include <netdb.h> <br> +#include <stdio.h> <br> +#include <stdlib.h> <br> +#include "tst_test.h" <br> +#include "lapi/stat.h" <br> + <br> +#define MODE(X) (X & (~S_IFMT)) <br> +#define BUFF_SIZE 512 <br> +#define DEFAULT_MODE 0644 <br> +#define CURRENT_MODE 0777 <br> + <br> +#define CLIENT_PATH "client" <br> +#define SERVER_PATH "server" <br> +#define FORCE_SYNC_FILE "force_sync_file" <br> +#define DONT_SYNC_FILE "dont_sync_file" <br> + <br> +static char cwd[BUFF_SIZE]; <br> +static char cmd[BUFF_SIZE]; <br> + <br> +static int get_mode(char *file_name, int flag_type, char *flag_name) <br> +{ <br> + char client_path[BUFF_SIZE]; <br> + struct statx buff; <br> + <br> + sprintf(client_path, "%s/%s/%s", cwd, CLIENT_PATH, file_name); <br> + <br> + TEST(statx(AT_FDCWD, client_path, flag_type, STATX_ALL, &buff)); <br> + <br> + if (TST_RET == -1) <br> + tst_brk(TFAIL | TST_ERR, <br> + "statx(AT_FDCWD, %s, %s, STATX_ALL, &buff)", <br> + file_name, flag_name); <br> + else <br> + tst_res(TINFO, "statx(AT_FDCWD, %s, %s, STATX_ALL, &buff)", <br> + file_name, flag_name); <br> </blockquote> Seems like something strange is happening with the whitespace. <br> <br> <blockquote type="cite" style="color: #000000;">+ <br> + return buff.stx_mode; <br> +} <br> + <br> +static void test_for_dont_sync(void) <br> +{ <br> + unsigned int cur_mode; <br> + char server_path[BUFF_SIZE]; <br> + <br> + sprintf(server_path, "%s/%s/%s", cwd, SERVER_PATH, DONT_SYNC_FILE); <br> + <br> + get_mode(DONT_SYNC_FILE, AT_STATX_FORCE_SYNC, <br> + "AT_STATX_FORCE_SYNC"); <br> + <br> + SAFE_CHMOD(server_path, CURRENT_MODE); <br> + cur_mode = get_mode(DONT_SYNC_FILE, AT_STATX_DONT_SYNC, <br> + "AT_STATX_DONT_SYNC"); <br> + <br> + if (DEFAULT_MODE == MODE(cur_mode)) <br> </blockquote> Try running check_patch from the kernel on this: <br> <br> WARNING: Comparisons should place the constant on the right side of the test <br> #86: FILE: statx06.c:86: <br> + if (DEFAULT_MODE == MODE(cur_mode)) <br> <br> <blockquote type="cite" style="color: #000000;">+ tst_res(TPASS, <br> + "statx() with AT_STATX_DONT_SYNC for mode %o %o", <br> + DEFAULT_MODE, (cur_mode & ~S_IFMT)); <br> + else <br> + tst_res(TFAIL, <br> + "statx() with AT_STATX_DONT_SYNC for mode %o %o", <br> + DEFAULT_MODE, (cur_mode & ~S_IFMT)); <br> +} <br> + <br> +static void test_for_force_sync(void) <br> +{ <br> + unsigned int cur_mode; <br> + char server_path[BUFF_SIZE]; <br> + <br> + sprintf(server_path, "%s/%s/%s", cwd, SERVER_PATH, FORCE_SYNC_FILE); <br> + <br> + SAFE_CHMOD(server_path, CURRENT_MODE); <br> + cur_mode = get_mode(FORCE_SYNC_FILE, AT_STATX_FORCE_SYNC, <br> + "AT_STATX_FORCE_SYNC"); <br> + <br> + if (CURRENT_MODE == MODE(cur_mode)) <br> + tst_res(TPASS, <br> + "statx() with AT_STATX_FORCE_SYNC for mode %o %o", <br> + CURRENT_MODE, (cur_mode & ~S_IFMT)); <br> + else <br> + tst_res(TFAIL, <br> + "statx() with AT_STATX_FORCE_SYNC for mode %o %o", <br> + CURRENT_MODE, (cur_mode & ~S_IFMT)); <br> +} <br> + <br> +struct test_cases { <br> + void (*func)(void); <br> +} tcases[] = { <br> + {test_for_dont_sync}, <br> + {test_for_force_sync} <br> +}; <br> + <br> +static void test_statx(unsigned int nr) <br> +{ <br> + struct test_cases *tc = &tcases[nr]; <br> + <br> + tc->func(); <br> +} <br> + <br> +static void setup(void) <br> +{ <br> + char force_sync_file[BUFF_SIZE]; <br> + char dont_sync_file[BUFF_SIZE]; <br> + char server_path[BUFF_SIZE]; <br> + char client_path[BUFF_SIZE]; <br> + char mount_data[BUFF_SIZE]; <br> + char *ip = "127.0.0.1"; <br> + <br> + TESTPTR(getcwd(cwd, BUFF_SIZE)); <br> + if (TST_RET_PTR == NULL) <br> + tst_brk(TBROK | TST_ERR, "Failed to get PWD"); <br> + <br> + sprintf(force_sync_file, "%s/%s", SERVER_PATH, FORCE_SYNC_FILE); <br> + sprintf(dont_sync_file, "%s/%s", SERVER_PATH, DONT_SYNC_FILE); <br> + <br> + SAFE_MKDIR(SERVER_PATH, DEFAULT_MODE); <br> + SAFE_MKDIR(CLIENT_PATH, DEFAULT_MODE); <br> + SAFE_CREAT(force_sync_file, DEFAULT_MODE); <br> + SAFE_CREAT(dont_sync_file, DEFAULT_MODE); <br> + <br> + sprintf(server_path, ":%s/%s", cwd, SERVER_PATH); <br> + sprintf(client_path, "%s/%s", cwd, CLIENT_PATH); <br> + sprintf(mount_data, "addr=%s", ip); <br> </blockquote> I get a lot of warnings when compiling with gcc8 like <br> <br> statx06.c:152:27: warning: ‘/’ directive writing 1 byte into a region of size between 0 and 511 [-Wformat-overflow=] <br> sprintf(server_path, ":%s/%s", cwd, SERVER_PATH); <br> <br> <br> <blockquote type="cite" style="color: #000000;">+ <br> + sprintf(cmd, <br> + "exportfs -i -o no_root_squash,rw,sync,no_subtree_check *%s", <br> + server_path); <br> </blockquote> Must we use an absolute path here and when mounting? <br> </blockquote> Yes, The problem with using relative path is exportfs writes the exact relative path to /var/lib/nfs/stab from where mount refers from. Because of this, ultimately mount fails. So, we are using absolute path in both cases. <br> <blockquote type="cite" style="color: #000000;"> <blockquote type="cite" style="color: #000000;">+ <br> + if (WEXITSTATUS(tst_system(cmd)) == 127) <br> + tst_brk(TBROK | TST_ERR, "%s not found", cmd); <br> </blockquote> This should probably be just TCONF as we shouldn't expect all systems to <br> support running an NFS server. Also you should check for other errors. <br> <br> <blockquote type="cite" style="color: #000000;">+ <br> + SAFE_MOUNT(server_path, client_path, "nfs", 0, mount_data); <br> +} <br> + <br> +static void cleanup(void) <br> +{ <br> + if (WEXITSTATUS(tst_system("exportfs -ua")) == 127) <br> + tst_brk(TBROK | TST_ERR, "%s", cmd); <br> + <br> + SAFE_UMOUNT(CLIENT_PATH); <br> +} <br> + <br> +static struct tst_test test = { <br> + .tcnt = ARRAY_SIZE(tcases), <br> + .test = test_statx, <br> + .setup = setup, <br> + .cleanup = cleanup, <br> + .min_kver = "4.11", <br> + .needs_tmpdir = 1, <br> + .dev_fs_type = "nfs", <br> + .needs_root = 1, <br> +}; <br> -- <br> 2.11.0 <br> </blockquote> <br> -- <br> Thank you, <br> Richard. <br> </blockquote> <br> Regards, <br> Kewal <br> </div> </body> </html>
diff --git a/runtest/syscalls b/runtest/syscalls index 0d0be7713..71b83b25c 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -1504,3 +1504,4 @@ statx02 statx02 statx03 statx03 statx04 statx04 statx05 statx05 +statx06 statx06 diff --git a/testcases/kernel/syscalls/statx/.gitignore b/testcases/kernel/syscalls/statx/.gitignore index 209fc3a33..c1ceddabf 100644 --- a/testcases/kernel/syscalls/statx/.gitignore +++ b/testcases/kernel/syscalls/statx/.gitignore @@ -3,3 +3,4 @@ /statx03 /statx04 /statx05 +/statx06 diff --git a/testcases/kernel/syscalls/statx/statx06.c b/testcases/kernel/syscalls/statx/statx06.c new file mode 100644 index 000000000..8b66bf832 --- /dev/null +++ b/testcases/kernel/syscalls/statx/statx06.c @@ -0,0 +1,183 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) Zilogic Systems Pvt. Ltd., 2018 + * Email : code@zilogic.com + */ + +/* + * Test statx + * + * This code tests the following flags: + * 1) AT_STATX_FORCE_SYNC + * 2) AT_STATX_DONT_SYNC + * + * By exportfs cmd creating NFS setup. + * + * A test file is created in server folder and statx is being + * done in client folder. + * + * TESTCASE 1: + * BY AT_STATX_SYNC_AS_STAT getting predefined mode value. + * Then, by using AT_STATX_FORCE_SYNC getting new updated vaue + * from server file changes. + * + * TESTCASE 2: + * BY AT_STATX_SYNC_AS_STAT getting predefined mode value. + * AT_STATX_FORCE_SYNC is called to create cache data of the file. + * Then, by using DONT_SYNC_FILE getting old cached data in client folder, + * but mode has been chaged in server file. + * + * Minimum kernel version required is 4.11. + */ + +#include <netdb.h> +#include <stdio.h> +#include <stdlib.h> +#include "tst_test.h" +#include "lapi/stat.h" + +#define MODE(X) (X & (~S_IFMT)) +#define BUFF_SIZE 512 +#define DEFAULT_MODE 0644 +#define CURRENT_MODE 0777 + +#define CLIENT_PATH "client" +#define SERVER_PATH "server" +#define FORCE_SYNC_FILE "force_sync_file" +#define DONT_SYNC_FILE "dont_sync_file" + +static char cwd[BUFF_SIZE]; +static char cmd[BUFF_SIZE]; + +static int get_mode(char *file_name, int flag_type, char *flag_name) +{ + char client_path[BUFF_SIZE]; + struct statx buff; + + sprintf(client_path, "%s/%s/%s", cwd, CLIENT_PATH, file_name); + + TEST(statx(AT_FDCWD, client_path, flag_type, STATX_ALL, &buff)); + + if (TST_RET == -1) + tst_brk(TFAIL | TST_ERR, + "statx(AT_FDCWD, %s, %s, STATX_ALL, &buff)", + file_name, flag_name); + else + tst_res(TINFO, "statx(AT_FDCWD, %s, %s, STATX_ALL, &buff)", + file_name, flag_name); + + return buff.stx_mode; +} + +static void test_for_dont_sync(void) +{ + unsigned int cur_mode; + char server_path[BUFF_SIZE]; + + sprintf(server_path, "%s/%s/%s", cwd, SERVER_PATH, DONT_SYNC_FILE); + + get_mode(DONT_SYNC_FILE, AT_STATX_FORCE_SYNC, + "AT_STATX_FORCE_SYNC"); + + SAFE_CHMOD(server_path, CURRENT_MODE); + cur_mode = get_mode(DONT_SYNC_FILE, AT_STATX_DONT_SYNC, + "AT_STATX_DONT_SYNC"); + + if (DEFAULT_MODE == MODE(cur_mode)) + tst_res(TPASS, + "statx() with AT_STATX_DONT_SYNC for mode %o %o", + DEFAULT_MODE, (cur_mode & ~S_IFMT)); + else + tst_res(TFAIL, + "statx() with AT_STATX_DONT_SYNC for mode %o %o", + DEFAULT_MODE, (cur_mode & ~S_IFMT)); +} + +static void test_for_force_sync(void) +{ + unsigned int cur_mode; + char server_path[BUFF_SIZE]; + + sprintf(server_path, "%s/%s/%s", cwd, SERVER_PATH, FORCE_SYNC_FILE); + + SAFE_CHMOD(server_path, CURRENT_MODE); + cur_mode = get_mode(FORCE_SYNC_FILE, AT_STATX_FORCE_SYNC, + "AT_STATX_FORCE_SYNC"); + + if (CURRENT_MODE == MODE(cur_mode)) + tst_res(TPASS, + "statx() with AT_STATX_FORCE_SYNC for mode %o %o", + CURRENT_MODE, (cur_mode & ~S_IFMT)); + else + tst_res(TFAIL, + "statx() with AT_STATX_FORCE_SYNC for mode %o %o", + CURRENT_MODE, (cur_mode & ~S_IFMT)); +} + +struct test_cases { + void (*func)(void); +} tcases[] = { + {test_for_dont_sync}, + {test_for_force_sync} +}; + +static void test_statx(unsigned int nr) +{ + struct test_cases *tc = &tcases[nr]; + + tc->func(); +} + +static void setup(void) +{ + char force_sync_file[BUFF_SIZE]; + char dont_sync_file[BUFF_SIZE]; + char server_path[BUFF_SIZE]; + char client_path[BUFF_SIZE]; + char mount_data[BUFF_SIZE]; + char *ip = "127.0.0.1"; + + TESTPTR(getcwd(cwd, BUFF_SIZE)); + if (TST_RET_PTR == NULL) + tst_brk(TBROK | TST_ERR, "Failed to get PWD"); + + sprintf(force_sync_file, "%s/%s", SERVER_PATH, FORCE_SYNC_FILE); + sprintf(dont_sync_file, "%s/%s", SERVER_PATH, DONT_SYNC_FILE); + + SAFE_MKDIR(SERVER_PATH, DEFAULT_MODE); + SAFE_MKDIR(CLIENT_PATH, DEFAULT_MODE); + SAFE_CREAT(force_sync_file, DEFAULT_MODE); + SAFE_CREAT(dont_sync_file, DEFAULT_MODE); + + sprintf(server_path, ":%s/%s", cwd, SERVER_PATH); + sprintf(client_path, "%s/%s", cwd, CLIENT_PATH); + sprintf(mount_data, "addr=%s", ip); + + sprintf(cmd, + "exportfs -i -o no_root_squash,rw,sync,no_subtree_check *%s", + server_path); + + if (WEXITSTATUS(tst_system(cmd)) == 127) + tst_brk(TBROK | TST_ERR, "%s not found", cmd); + + SAFE_MOUNT(server_path, client_path, "nfs", 0, mount_data); +} + +static void cleanup(void) +{ + if (WEXITSTATUS(tst_system("exportfs -ua")) == 127) + tst_brk(TBROK | TST_ERR, "%s", cmd); + + SAFE_UMOUNT(CLIENT_PATH); +} + +static struct tst_test test = { + .tcnt = ARRAY_SIZE(tcases), + .test = test_statx, + .setup = setup, + .cleanup = cleanup, + .min_kver = "4.11", + .needs_tmpdir = 1, + .dev_fs_type = "nfs", + .needs_root = 1, +};