* [LTP] [PATCH v3] fcntl/fcntl32.c: add F_SETLEASE and F_WRLCK argument test
[not found] <55EFA462.5010608@cn.fujitsu.com>
@ 2015-09-15 8:55 ` Guangwen Feng
2015-09-17 8:03 ` Jan Stancek
2015-09-30 16:41 ` Cyril Hrubis
0 siblings, 2 replies; 8+ messages in thread
From: Guangwen Feng @ 2015-09-15 8:55 UTC (permalink / raw)
To: ltp
Add new testcase to verify that a write lease may be placed
on a file only if there are no other open file descriptors
for the file.
Signed-off-by: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
---
runtest/ltplite | 1 +
runtest/stress.part3 | 1 +
runtest/syscalls | 2 +
testcases/kernel/syscalls/.gitignore | 2 +
testcases/kernel/syscalls/fcntl/fcntl32.c | 137 ++++++++++++++++++++++++++++++
5 files changed, 143 insertions(+)
create mode 100644 testcases/kernel/syscalls/fcntl/fcntl32.c
diff --git a/runtest/ltplite b/runtest/ltplite
index ab6424c..e3ae8cf 100644
--- a/runtest/ltplite
+++ b/runtest/ltplite
@@ -225,6 +225,7 @@ fcntl26 fcntl26
fcntl29 fcntl29
fcntl30 fcntl30
fcntl31 fcntl31
+fcntl32 fcntl32
fdatasync01 fdatasync01
fdatasync02 fdatasync02
diff --git a/runtest/stress.part3 b/runtest/stress.part3
index ab9af3c..ca8b70c 100644
--- a/runtest/stress.part3
+++ b/runtest/stress.part3
@@ -164,6 +164,7 @@ fcntl26 fcntl26
fcntl29 fcntl29
fcntl30 fcntl30
fcntl31 fcntl31
+fcntl32 fcntl32
fdatasync01 fdatasync01
fdatasync02 fdatasync02
diff --git a/runtest/syscalls b/runtest/syscalls
index ee2627f..a641bcd 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -258,6 +258,8 @@ fcntl30 fcntl30
fcntl30_64 fcntl30_64
fcntl31 fcntl31
fcntl31_64 fcntl31_64
+fcntl32 fcntl32
+fcntl32_64 fcntl32_64
fdatasync01 fdatasync01
fdatasync02 fdatasync02
diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore
index 18c0ad6..2b288e0 100644
--- a/testcases/kernel/syscalls/.gitignore
+++ b/testcases/kernel/syscalls/.gitignore
@@ -221,6 +221,8 @@
/fcntl/fcntl30_64
/fcntl/fcntl31
/fcntl/fcntl31_64
+/fcntl/fcntl32
+/fcntl/fcntl32_64
/fdatasync/fdatasync01
/fdatasync/fdatasync02
/flock/flock01
diff --git a/testcases/kernel/syscalls/fcntl/fcntl32.c b/testcases/kernel/syscalls/fcntl/fcntl32.c
new file mode 100644
index 0000000..05d963e
--- /dev/null
+++ b/testcases/kernel/syscalls/fcntl/fcntl32.c
@@ -0,0 +1,137 @@
+/*
+ * Copyright (c) 2015 Fujitsu Ltd.
+ * Author: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * You should have received a copy of the GNU General Public License
+ * alone with this program.
+ */
+
+/*
+ * DESCRIPTION
+ * Basic test for fcntl(2) using F_SETLEASE & F_WRLCK argument.
+ * "A write lease may be placed on a file only if there are
+ * no other open file descriptors for the file."
+ */
+
+#include <errno.h>
+
+#include "test.h"
+#include "safe_macros.h"
+#include "tst_fs_type.h"
+
+static void setup(void);
+static void verify_fcntl(int);
+static void cleanup(void);
+
+#define FILE_MODE (S_IRWXU | S_IRWXG | S_IRWXO | S_ISUID | S_ISGID)
+
+static int fd1;
+static int fd2;
+
+static struct test_case_t {
+ int fd1_flag;
+ int fd2_flag;
+} test_cases[] = {
+ {O_RDONLY, O_RDONLY},
+ {O_RDONLY, O_WRONLY},
+ {O_RDONLY, O_RDWR},
+ {O_WRONLY, O_RDONLY},
+ {O_WRONLY, O_WRONLY},
+ {O_WRONLY, O_RDWR},
+ {O_RDWR, O_RDONLY},
+ {O_RDWR, O_WRONLY},
+ {O_RDWR, O_RDWR},
+};
+
+char *TCID = "fcntl32";
+int TST_TOTAL = ARRAY_SIZE(test_cases);
+
+int main(int ac, char **av)
+{
+ int lc;
+ int tc;
+ long type;
+
+ tst_parse_opts(ac, av, NULL, NULL);
+
+ setup();
+
+ switch ((type = tst_fs_type(cleanup, "."))) {
+ case TST_NFS_MAGIC:
+ case TST_RAMFS_MAGIC:
+ case TST_TMPFS_MAGIC:
+ tst_brkm(TCONF, cleanup, "%s filesystem does not support "
+ "fcntl(2)'s F_SETLEASE operation",
+ tst_fs_type_name(type));
+ default:
+ break;
+ }
+
+ for (lc = 0; TEST_LOOPING(lc); lc++) {
+ tst_count = 0;
+
+ for (tc = 0; tc < TST_TOTAL; tc++)
+ verify_fcntl(tc);
+ }
+
+ cleanup();
+ tst_exit();
+}
+
+static void setup(void)
+{
+ tst_sig(NOFORK, DEF_HANDLER, cleanup);
+ TEST_PAUSE;
+
+ tst_tmpdir();
+
+ SAFE_TOUCH(cleanup, "file", FILE_MODE, NULL);
+}
+
+static void verify_fcntl(int i)
+{
+ fd1 = SAFE_OPEN(cleanup, "file", test_cases[i].fd1_flag);
+ fd2 = SAFE_OPEN(cleanup, "file", test_cases[i].fd2_flag);
+
+ TEST(fcntl(fd1, F_SETLEASE, F_WRLCK));
+
+ if (TEST_RETURN == 0) {
+ tst_resm(TFAIL, "fcntl(F_SETLEASE, F_WRLCK) "
+ "succeeded unexpectedly");
+ } else {
+ if (TEST_ERRNO == EBUSY || TEST_ERRNO == EAGAIN) {
+ tst_resm(TPASS | TTERRNO,
+ "fcntl(F_SETLEASE, F_WRLCK) "
+ "failed as expected");
+ } else {
+ tst_resm(TFAIL | TTERRNO,
+ "fcntl(F_SETLEASE, F_WRLCK) "
+ "failed unexpectedly, "
+ "expected errno is EBUSY or EAGAIN");
+ }
+ }
+
+ SAFE_CLOSE(cleanup, fd1);
+ fd1 = 0;
+ SAFE_CLOSE(cleanup, fd2);
+ fd2 = 0;
+}
+
+static void cleanup(void)
+{
+ if (fd1 > 0 && close(fd1))
+ tst_resm(TWARN | TERRNO, "Failed to close file");
+
+ if (fd2 > 0 && close(fd2))
+ tst_resm(TWARN | TERRNO, "Failed to close file");
+
+ tst_rmdir();
+}
--
1.8.4.2
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [LTP] [PATCH v3] fcntl/fcntl32.c: add F_SETLEASE and F_WRLCK argument test
2015-09-15 8:55 ` [LTP] [PATCH v3] fcntl/fcntl32.c: add F_SETLEASE and F_WRLCK argument test Guangwen Feng
@ 2015-09-17 8:03 ` Jan Stancek
2015-09-30 16:41 ` Cyril Hrubis
1 sibling, 0 replies; 8+ messages in thread
From: Jan Stancek @ 2015-09-17 8:03 UTC (permalink / raw)
To: ltp
----- Original Message -----
> From: "Guangwen Feng" <fenggw-fnst@cn.fujitsu.com>
> To: ltp@lists.linux.it
> Sent: Tuesday, 15 September, 2015 10:55:39 AM
> Subject: [LTP] [PATCH v3] fcntl/fcntl32.c: add F_SETLEASE and F_WRLCK argument test
>
> Add new testcase to verify that a write lease may be placed
> on a file only if there are no other open file descriptors
> for the file.
>
> Signed-off-by: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
Looks good to me.
Reviewed-by: Jan Stancek <jstancek@redhat.com>
> ---
> runtest/ltplite | 1 +
> runtest/stress.part3 | 1 +
> runtest/syscalls | 2 +
> testcases/kernel/syscalls/.gitignore | 2 +
> testcases/kernel/syscalls/fcntl/fcntl32.c | 137
> ++++++++++++++++++++++++++++++
> 5 files changed, 143 insertions(+)
> create mode 100644 testcases/kernel/syscalls/fcntl/fcntl32.c
>
> diff --git a/runtest/ltplite b/runtest/ltplite
> index ab6424c..e3ae8cf 100644
> --- a/runtest/ltplite
> +++ b/runtest/ltplite
> @@ -225,6 +225,7 @@ fcntl26 fcntl26
> fcntl29 fcntl29
> fcntl30 fcntl30
> fcntl31 fcntl31
> +fcntl32 fcntl32
>
> fdatasync01 fdatasync01
> fdatasync02 fdatasync02
> diff --git a/runtest/stress.part3 b/runtest/stress.part3
> index ab9af3c..ca8b70c 100644
> --- a/runtest/stress.part3
> +++ b/runtest/stress.part3
> @@ -164,6 +164,7 @@ fcntl26 fcntl26
> fcntl29 fcntl29
> fcntl30 fcntl30
> fcntl31 fcntl31
> +fcntl32 fcntl32
>
> fdatasync01 fdatasync01
> fdatasync02 fdatasync02
> diff --git a/runtest/syscalls b/runtest/syscalls
> index ee2627f..a641bcd 100644
> --- a/runtest/syscalls
> +++ b/runtest/syscalls
> @@ -258,6 +258,8 @@ fcntl30 fcntl30
> fcntl30_64 fcntl30_64
> fcntl31 fcntl31
> fcntl31_64 fcntl31_64
> +fcntl32 fcntl32
> +fcntl32_64 fcntl32_64
>
> fdatasync01 fdatasync01
> fdatasync02 fdatasync02
> diff --git a/testcases/kernel/syscalls/.gitignore
> b/testcases/kernel/syscalls/.gitignore
> index 18c0ad6..2b288e0 100644
> --- a/testcases/kernel/syscalls/.gitignore
> +++ b/testcases/kernel/syscalls/.gitignore
> @@ -221,6 +221,8 @@
> /fcntl/fcntl30_64
> /fcntl/fcntl31
> /fcntl/fcntl31_64
> +/fcntl/fcntl32
> +/fcntl/fcntl32_64
> /fdatasync/fdatasync01
> /fdatasync/fdatasync02
> /flock/flock01
> diff --git a/testcases/kernel/syscalls/fcntl/fcntl32.c
> b/testcases/kernel/syscalls/fcntl/fcntl32.c
> new file mode 100644
> index 0000000..05d963e
> --- /dev/null
> +++ b/testcases/kernel/syscalls/fcntl/fcntl32.c
> @@ -0,0 +1,137 @@
> +/*
> + * Copyright (c) 2015 Fujitsu Ltd.
> + * Author: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
> + *
> + * This program is free software; you can redistribute it and/or modify it
> + * under the terms of version 2 of the GNU General Public License as
> + * published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it would be useful, but
> + * WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
> + *
> + * You should have received a copy of the GNU General Public License
> + * alone with this program.
> + */
> +
> +/*
> + * DESCRIPTION
> + * Basic test for fcntl(2) using F_SETLEASE & F_WRLCK argument.
> + * "A write lease may be placed on a file only if there are
> + * no other open file descriptors for the file."
> + */
> +
> +#include <errno.h>
> +
> +#include "test.h"
> +#include "safe_macros.h"
> +#include "tst_fs_type.h"
> +
> +static void setup(void);
> +static void verify_fcntl(int);
> +static void cleanup(void);
> +
> +#define FILE_MODE (S_IRWXU | S_IRWXG | S_IRWXO | S_ISUID | S_ISGID)
> +
> +static int fd1;
> +static int fd2;
> +
> +static struct test_case_t {
> + int fd1_flag;
> + int fd2_flag;
> +} test_cases[] = {
> + {O_RDONLY, O_RDONLY},
> + {O_RDONLY, O_WRONLY},
> + {O_RDONLY, O_RDWR},
> + {O_WRONLY, O_RDONLY},
> + {O_WRONLY, O_WRONLY},
> + {O_WRONLY, O_RDWR},
> + {O_RDWR, O_RDONLY},
> + {O_RDWR, O_WRONLY},
> + {O_RDWR, O_RDWR},
> +};
> +
> +char *TCID = "fcntl32";
> +int TST_TOTAL = ARRAY_SIZE(test_cases);
> +
> +int main(int ac, char **av)
> +{
> + int lc;
> + int tc;
> + long type;
> +
> + tst_parse_opts(ac, av, NULL, NULL);
> +
> + setup();
> +
> + switch ((type = tst_fs_type(cleanup, "."))) {
> + case TST_NFS_MAGIC:
> + case TST_RAMFS_MAGIC:
> + case TST_TMPFS_MAGIC:
> + tst_brkm(TCONF, cleanup, "%s filesystem does not support "
> + "fcntl(2)'s F_SETLEASE operation",
> + tst_fs_type_name(type));
> + default:
> + break;
> + }
> +
> + for (lc = 0; TEST_LOOPING(lc); lc++) {
> + tst_count = 0;
> +
> + for (tc = 0; tc < TST_TOTAL; tc++)
> + verify_fcntl(tc);
> + }
> +
> + cleanup();
> + tst_exit();
> +}
> +
> +static void setup(void)
> +{
> + tst_sig(NOFORK, DEF_HANDLER, cleanup);
> + TEST_PAUSE;
> +
> + tst_tmpdir();
> +
> + SAFE_TOUCH(cleanup, "file", FILE_MODE, NULL);
> +}
> +
> +static void verify_fcntl(int i)
> +{
> + fd1 = SAFE_OPEN(cleanup, "file", test_cases[i].fd1_flag);
> + fd2 = SAFE_OPEN(cleanup, "file", test_cases[i].fd2_flag);
> +
> + TEST(fcntl(fd1, F_SETLEASE, F_WRLCK));
> +
> + if (TEST_RETURN == 0) {
> + tst_resm(TFAIL, "fcntl(F_SETLEASE, F_WRLCK) "
> + "succeeded unexpectedly");
> + } else {
> + if (TEST_ERRNO == EBUSY || TEST_ERRNO == EAGAIN) {
> + tst_resm(TPASS | TTERRNO,
> + "fcntl(F_SETLEASE, F_WRLCK) "
> + "failed as expected");
> + } else {
> + tst_resm(TFAIL | TTERRNO,
> + "fcntl(F_SETLEASE, F_WRLCK) "
> + "failed unexpectedly, "
> + "expected errno is EBUSY or EAGAIN");
> + }
> + }
> +
> + SAFE_CLOSE(cleanup, fd1);
> + fd1 = 0;
> + SAFE_CLOSE(cleanup, fd2);
> + fd2 = 0;
> +}
> +
> +static void cleanup(void)
> +{
> + if (fd1 > 0 && close(fd1))
> + tst_resm(TWARN | TERRNO, "Failed to close file");
> +
> + if (fd2 > 0 && close(fd2))
> + tst_resm(TWARN | TERRNO, "Failed to close file");
> +
> + tst_rmdir();
> +}
> --
> 1.8.4.2
>
>
> --
> Mailing list info: http://lists.linux.it/listinfo/ltp
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* [LTP] [PATCH v3] fcntl/fcntl32.c: add F_SETLEASE and F_WRLCK argument test
2015-09-15 8:55 ` [LTP] [PATCH v3] fcntl/fcntl32.c: add F_SETLEASE and F_WRLCK argument test Guangwen Feng
2015-09-17 8:03 ` Jan Stancek
@ 2015-09-30 16:41 ` Cyril Hrubis
2015-10-07 10:00 ` Guangwen Feng
1 sibling, 1 reply; 8+ messages in thread
From: Cyril Hrubis @ 2015-09-30 16:41 UTC (permalink / raw)
To: ltp
Hi!
> +int main(int ac, char **av)
> +{
> + int lc;
> + int tc;
> + long type;
> +
> + tst_parse_opts(ac, av, NULL, NULL);
> +
> + setup();
> +
> + switch ((type = tst_fs_type(cleanup, "."))) {
> + case TST_NFS_MAGIC:
> + case TST_RAMFS_MAGIC:
> + case TST_TMPFS_MAGIC:
> + tst_brkm(TCONF, cleanup, "%s filesystem does not support "
> + "fcntl(2)'s F_SETLEASE operation",
> + tst_fs_type_name(type));
> + default:
> + break;
> + }
Same as the second one. I would preffer figuring out that the fcntl() is
unsupported by actually trying to use it.
Otherwise it looks fine.
--
Cyril Hrubis
chrubis@suse.cz
^ permalink raw reply [flat|nested] 8+ messages in thread
* [LTP] [PATCH v3] fcntl/fcntl32.c: add F_SETLEASE and F_WRLCK argument test
2015-09-30 16:41 ` Cyril Hrubis
@ 2015-10-07 10:00 ` Guangwen Feng
2015-10-12 11:14 ` [LTP] [PATCH v4] " Guangwen Feng
2015-10-12 17:43 ` [LTP] [PATCH v3] " Cyril Hrubis
0 siblings, 2 replies; 8+ messages in thread
From: Guangwen Feng @ 2015-10-07 10:00 UTC (permalink / raw)
To: ltp
Hi!
Thanks for your reply.
On 2015/10/01 00:41, Cyril Hrubis wrote:
> Hi!
>> +int main(int ac, char **av)
>> +{
>> + int lc;
>> + int tc;
>> + long type;
>> +
>> + tst_parse_opts(ac, av, NULL, NULL);
>> +
>> + setup();
>> +
>> + switch ((type = tst_fs_type(cleanup, "."))) {
>> + case TST_NFS_MAGIC:
>> + case TST_RAMFS_MAGIC:
>> + case TST_TMPFS_MAGIC:
>> + tst_brkm(TCONF, cleanup, "%s filesystem does not support "
>> + "fcntl(2)'s F_SETLEASE operation",
>> + tst_fs_type_name(type));
>> + default:
>> + break;
>> + }
>
> Same as the second one. I would preffer figuring out that the fcntl() is
> unsupported by actually trying to use it.
>
It will return EAGAIN when we actually use it, I don't think it's a reasonable errno,
since on ramfs or tmpfs, when opening or creating a new file, the dentry->d_count
will get an extra count to be 2 but not 1. Please have a look at the following link:
http://www.gossamer-threads.com/lists/linux/kernel/913113
I feel the expression is not clear, it should be "cannot do fcntl()'s F_SETLEASE operation
on %s filesystem"
>
> Otherwise it looks fine.
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* [LTP] [PATCH v4] fcntl/fcntl32.c: add F_SETLEASE and F_WRLCK argument test
2015-10-07 10:00 ` Guangwen Feng
@ 2015-10-12 11:14 ` Guangwen Feng
2015-10-12 17:43 ` [LTP] [PATCH v3] " Cyril Hrubis
1 sibling, 0 replies; 8+ messages in thread
From: Guangwen Feng @ 2015-10-12 11:14 UTC (permalink / raw)
To: ltp
Add new testcase to verify that a write lease may be placed
on a file only if there are no other open file descriptors
for the file.
Signed-off-by: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
---
runtest/ltplite | 1 +
runtest/stress.part3 | 1 +
runtest/syscalls | 2 +
testcases/kernel/syscalls/.gitignore | 2 +
testcases/kernel/syscalls/fcntl/fcntl32.c | 135 ++++++++++++++++++++++++++++++
5 files changed, 141 insertions(+)
create mode 100644 testcases/kernel/syscalls/fcntl/fcntl32.c
diff --git a/runtest/ltplite b/runtest/ltplite
index 7f3efdc..63a1583 100644
--- a/runtest/ltplite
+++ b/runtest/ltplite
@@ -225,6 +225,7 @@ fcntl26 fcntl26
fcntl29 fcntl29
fcntl30 fcntl30
fcntl31 fcntl31
+fcntl32 fcntl32
fdatasync01 fdatasync01
fdatasync02 fdatasync02
diff --git a/runtest/stress.part3 b/runtest/stress.part3
index ab9af3c..ca8b70c 100644
--- a/runtest/stress.part3
+++ b/runtest/stress.part3
@@ -164,6 +164,7 @@ fcntl26 fcntl26
fcntl29 fcntl29
fcntl30 fcntl30
fcntl31 fcntl31
+fcntl32 fcntl32
fdatasync01 fdatasync01
fdatasync02 fdatasync02
diff --git a/runtest/syscalls b/runtest/syscalls
index c54a637..db03ccc 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -258,6 +258,8 @@ fcntl30 fcntl30
fcntl30_64 fcntl30_64
fcntl31 fcntl31
fcntl31_64 fcntl31_64
+fcntl32 fcntl32
+fcntl32_64 fcntl32_64
fdatasync01 fdatasync01
fdatasync02 fdatasync02
diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore
index 9f659c5..3bba587 100644
--- a/testcases/kernel/syscalls/.gitignore
+++ b/testcases/kernel/syscalls/.gitignore
@@ -221,6 +221,8 @@
/fcntl/fcntl30_64
/fcntl/fcntl31
/fcntl/fcntl31_64
+/fcntl/fcntl32
+/fcntl/fcntl32_64
/fdatasync/fdatasync01
/fdatasync/fdatasync02
/flock/flock01
diff --git a/testcases/kernel/syscalls/fcntl/fcntl32.c b/testcases/kernel/syscalls/fcntl/fcntl32.c
new file mode 100644
index 0000000..f87f7f4
--- /dev/null
+++ b/testcases/kernel/syscalls/fcntl/fcntl32.c
@@ -0,0 +1,135 @@
+/*
+ * Copyright (c) 2015 Fujitsu Ltd.
+ * Author: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * You should have received a copy of the GNU General Public License
+ * alone with this program.
+ */
+
+/*
+ * DESCRIPTION
+ * Basic test for fcntl(2) using F_SETLEASE & F_WRLCK argument.
+ * "A write lease may be placed on a file only if there are
+ * no other open file descriptors for the file."
+ */
+
+#include <errno.h>
+
+#include "test.h"
+#include "safe_macros.h"
+#include "tst_fs_type.h"
+
+static void setup(void);
+static void verify_fcntl(int);
+static void cleanup(void);
+
+#define FILE_MODE (S_IRWXU | S_IRWXG | S_IRWXO | S_ISUID | S_ISGID)
+
+static int fd1;
+static int fd2;
+
+static struct test_case_t {
+ int fd1_flag;
+ int fd2_flag;
+} test_cases[] = {
+ {O_RDONLY, O_RDONLY},
+ {O_RDONLY, O_WRONLY},
+ {O_RDONLY, O_RDWR},
+ {O_WRONLY, O_RDONLY},
+ {O_WRONLY, O_WRONLY},
+ {O_WRONLY, O_RDWR},
+ {O_RDWR, O_RDONLY},
+ {O_RDWR, O_WRONLY},
+ {O_RDWR, O_RDWR},
+};
+
+char *TCID = "fcntl32";
+int TST_TOTAL = ARRAY_SIZE(test_cases);
+
+int main(int ac, char **av)
+{
+ int lc;
+ int tc;
+ long type;
+
+ tst_parse_opts(ac, av, NULL, NULL);
+
+ setup();
+
+ for (lc = 0; TEST_LOOPING(lc); lc++) {
+ tst_count = 0;
+
+ for (tc = 0; tc < TST_TOTAL; tc++)
+ verify_fcntl(tc);
+ }
+
+ cleanup();
+ tst_exit();
+}
+
+static void setup(void)
+{
+ tst_sig(NOFORK, DEF_HANDLER, cleanup);
+ TEST_PAUSE;
+
+ tst_tmpdir();
+
+ fd1 = SAFE_CREAT(cleanup, "file", FILE_MODE);
+ TEST(fcntl(fd1, F_SETLEASE, F_WRLCK));
+ if (TEST_RETURN == -1 && TEST_ERRNO == EAGAIN) {
+ tst_brkm(TCONF, cleanup,
+ "Cannot do fcntl(F_SETLEASE, F_WRLCK) "
+ "on %s filesystem",
+ tst_fs_type_name(tst_fs_type(cleanup, ".")));
+ }
+ SAFE_CLOSE(cleanup, fd1);
+ fd1 = 0;
+}
+
+static void verify_fcntl(int i)
+{
+ fd1 = SAFE_OPEN(cleanup, "file", test_cases[i].fd1_flag);
+ fd2 = SAFE_OPEN(cleanup, "file", test_cases[i].fd2_flag);
+
+ TEST(fcntl(fd1, F_SETLEASE, F_WRLCK));
+
+ if (TEST_RETURN == 0) {
+ tst_resm(TFAIL, "fcntl(F_SETLEASE, F_WRLCK) "
+ "succeeded unexpectedly");
+ } else {
+ if (TEST_ERRNO == EBUSY || TEST_ERRNO == EAGAIN) {
+ tst_resm(TPASS | TTERRNO,
+ "fcntl(F_SETLEASE, F_WRLCK) "
+ "failed as expected");
+ } else {
+ tst_resm(TFAIL | TTERRNO,
+ "fcntl(F_SETLEASE, F_WRLCK) "
+ "failed unexpectedly, "
+ "expected errno is EBUSY or EAGAIN");
+ }
+ }
+
+ SAFE_CLOSE(cleanup, fd1);
+ fd1 = 0;
+ SAFE_CLOSE(cleanup, fd2);
+ fd2 = 0;
+}
+
+static void cleanup(void)
+{
+ if (fd1 > 0 && close(fd1))
+ tst_resm(TWARN | TERRNO, "Failed to close file");
+
+ if (fd2 > 0 && close(fd2))
+ tst_resm(TWARN | TERRNO, "Failed to close file");
+
+ tst_rmdir();
+}
--
1.8.4.2
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [LTP] [PATCH v3] fcntl/fcntl32.c: add F_SETLEASE and F_WRLCK argument test
2015-10-07 10:00 ` Guangwen Feng
2015-10-12 11:14 ` [LTP] [PATCH v4] " Guangwen Feng
@ 2015-10-12 17:43 ` Cyril Hrubis
2015-10-13 3:56 ` [LTP] [PATCH v5] " Guangwen Feng
1 sibling, 1 reply; 8+ messages in thread
From: Cyril Hrubis @ 2015-10-12 17:43 UTC (permalink / raw)
To: ltp
Hi!
> > Same as the second one. I would preffer figuring out that the fcntl() is
> > unsupported by actually trying to use it.
> >
>
> It will return EAGAIN when we actually use it, I don't think it's a reasonable errno,
> since on ramfs or tmpfs, when opening or creating a new file, the dentry->d_count
> will get an extra count to be 2 but not 1. Please have a look at the following link:
> http://www.gossamer-threads.com/lists/linux/kernel/913113
Hmm, so the kernel thinks that the file has been opened two times
allready and returns EAGAIN when we try the lock. It may be better to
just to skip these filesystems as you did then, since it's unlikely that
somebody will fix this in kernel.
--
Cyril Hrubis
chrubis@suse.cz
^ permalink raw reply [flat|nested] 8+ messages in thread
* [LTP] [PATCH v5] fcntl/fcntl32.c: add F_SETLEASE and F_WRLCK argument test
2015-10-12 17:43 ` [LTP] [PATCH v3] " Cyril Hrubis
@ 2015-10-13 3:56 ` Guangwen Feng
2015-10-13 18:23 ` Cyril Hrubis
0 siblings, 1 reply; 8+ messages in thread
From: Guangwen Feng @ 2015-10-13 3:56 UTC (permalink / raw)
To: ltp
Add new testcase to verify that a write lease may be placed
on a file only if there are no other open file descriptors
for the file.
Signed-off-by: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
---
runtest/ltplite | 1 +
runtest/stress.part3 | 1 +
runtest/syscalls | 2 +
testcases/kernel/syscalls/.gitignore | 2 +
testcases/kernel/syscalls/fcntl/fcntl32.c | 138 ++++++++++++++++++++++++++++++
5 files changed, 144 insertions(+)
create mode 100644 testcases/kernel/syscalls/fcntl/fcntl32.c
diff --git a/runtest/ltplite b/runtest/ltplite
index 7f3efdc..63a1583 100644
--- a/runtest/ltplite
+++ b/runtest/ltplite
@@ -225,6 +225,7 @@ fcntl26 fcntl26
fcntl29 fcntl29
fcntl30 fcntl30
fcntl31 fcntl31
+fcntl32 fcntl32
fdatasync01 fdatasync01
fdatasync02 fdatasync02
diff --git a/runtest/stress.part3 b/runtest/stress.part3
index ab9af3c..ca8b70c 100644
--- a/runtest/stress.part3
+++ b/runtest/stress.part3
@@ -164,6 +164,7 @@ fcntl26 fcntl26
fcntl29 fcntl29
fcntl30 fcntl30
fcntl31 fcntl31
+fcntl32 fcntl32
fdatasync01 fdatasync01
fdatasync02 fdatasync02
diff --git a/runtest/syscalls b/runtest/syscalls
index 1b53fb0..bce4865 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -258,6 +258,8 @@ fcntl30 fcntl30
fcntl30_64 fcntl30_64
fcntl31 fcntl31
fcntl31_64 fcntl31_64
+fcntl32 fcntl32
+fcntl32_64 fcntl32_64
fdatasync01 fdatasync01
fdatasync02 fdatasync02
diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore
index 7822b2e..d085ed6 100644
--- a/testcases/kernel/syscalls/.gitignore
+++ b/testcases/kernel/syscalls/.gitignore
@@ -221,6 +221,8 @@
/fcntl/fcntl30_64
/fcntl/fcntl31
/fcntl/fcntl31_64
+/fcntl/fcntl32
+/fcntl/fcntl32_64
/fdatasync/fdatasync01
/fdatasync/fdatasync02
/flock/flock01
diff --git a/testcases/kernel/syscalls/fcntl/fcntl32.c b/testcases/kernel/syscalls/fcntl/fcntl32.c
new file mode 100644
index 0000000..7c77f6f
--- /dev/null
+++ b/testcases/kernel/syscalls/fcntl/fcntl32.c
@@ -0,0 +1,138 @@
+/*
+ * Copyright (c) 2015 Fujitsu Ltd.
+ * Author: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * You should have received a copy of the GNU General Public License
+ * alone with this program.
+ */
+
+/*
+ * DESCRIPTION
+ * Basic test for fcntl(2) using F_SETLEASE & F_WRLCK argument.
+ * "A write lease may be placed on a file only if there are
+ * no other open file descriptors for the file."
+ */
+
+#include <errno.h>
+
+#include "test.h"
+#include "safe_macros.h"
+#include "tst_fs_type.h"
+
+static void setup(void);
+static void verify_fcntl(int);
+static void cleanup(void);
+
+#define FILE_MODE (S_IRWXU | S_IRWXG | S_IRWXO | S_ISUID | S_ISGID)
+
+static int fd1;
+static int fd2;
+static long type;
+
+static struct test_case_t {
+ int fd1_flag;
+ int fd2_flag;
+} test_cases[] = {
+ {O_RDONLY, O_RDONLY},
+ {O_RDONLY, O_WRONLY},
+ {O_RDONLY, O_RDWR},
+ {O_WRONLY, O_RDONLY},
+ {O_WRONLY, O_WRONLY},
+ {O_WRONLY, O_RDWR},
+ {O_RDWR, O_RDONLY},
+ {O_RDWR, O_WRONLY},
+ {O_RDWR, O_RDWR},
+};
+
+char *TCID = "fcntl32";
+int TST_TOTAL = ARRAY_SIZE(test_cases);
+
+int main(int ac, char **av)
+{
+ int lc;
+ int tc;
+
+ tst_parse_opts(ac, av, NULL, NULL);
+
+ setup();
+
+ for (lc = 0; TEST_LOOPING(lc); lc++) {
+ tst_count = 0;
+
+ for (tc = 0; tc < TST_TOTAL; tc++)
+ verify_fcntl(tc);
+ }
+
+ cleanup();
+ tst_exit();
+}
+
+static void setup(void)
+{
+ tst_sig(NOFORK, DEF_HANDLER, cleanup);
+ TEST_PAUSE;
+
+ tst_tmpdir();
+
+ switch ((type = tst_fs_type(cleanup, "."))) {
+ case TST_NFS_MAGIC:
+ case TST_RAMFS_MAGIC:
+ case TST_TMPFS_MAGIC:
+ tst_brkm(TCONF, cleanup,
+ "Cannot do fcntl(F_SETLEASE, F_WRLCK) "
+ "on %s filesystem",
+ tst_fs_type_name(type));
+ default:
+ break;
+ }
+
+ SAFE_TOUCH(cleanup, "file", FILE_MODE, NULL);
+}
+
+static void verify_fcntl(int i)
+{
+ fd1 = SAFE_OPEN(cleanup, "file", test_cases[i].fd1_flag);
+ fd2 = SAFE_OPEN(cleanup, "file", test_cases[i].fd2_flag);
+
+ TEST(fcntl(fd1, F_SETLEASE, F_WRLCK));
+
+ if (TEST_RETURN == 0) {
+ tst_resm(TFAIL, "fcntl(F_SETLEASE, F_WRLCK) "
+ "succeeded unexpectedly");
+ } else {
+ if (TEST_ERRNO == EBUSY || TEST_ERRNO == EAGAIN) {
+ tst_resm(TPASS | TTERRNO,
+ "fcntl(F_SETLEASE, F_WRLCK) "
+ "failed as expected");
+ } else {
+ tst_resm(TFAIL | TTERRNO,
+ "fcntl(F_SETLEASE, F_WRLCK) "
+ "failed unexpectedly, "
+ "expected errno is EBUSY or EAGAIN");
+ }
+ }
+
+ SAFE_CLOSE(cleanup, fd1);
+ fd1 = 0;
+ SAFE_CLOSE(cleanup, fd2);
+ fd2 = 0;
+}
+
+static void cleanup(void)
+{
+ if (fd1 > 0 && close(fd1))
+ tst_resm(TWARN | TERRNO, "Failed to close file");
+
+ if (fd2 > 0 && close(fd2))
+ tst_resm(TWARN | TERRNO, "Failed to close file");
+
+ tst_rmdir();
+}
--
1.8.4.2
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [LTP] [PATCH v5] fcntl/fcntl32.c: add F_SETLEASE and F_WRLCK argument test
2015-10-13 3:56 ` [LTP] [PATCH v5] " Guangwen Feng
@ 2015-10-13 18:23 ` Cyril Hrubis
0 siblings, 0 replies; 8+ messages in thread
From: Cyril Hrubis @ 2015-10-13 18:23 UTC (permalink / raw)
To: ltp
Hi!
Pushed, thanks.
--
Cyril Hrubis
chrubis@suse.cz
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2015-10-13 18:23 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <55EFA462.5010608@cn.fujitsu.com>
2015-09-15 8:55 ` [LTP] [PATCH v3] fcntl/fcntl32.c: add F_SETLEASE and F_WRLCK argument test Guangwen Feng
2015-09-17 8:03 ` Jan Stancek
2015-09-30 16:41 ` Cyril Hrubis
2015-10-07 10:00 ` Guangwen Feng
2015-10-12 11:14 ` [LTP] [PATCH v4] " Guangwen Feng
2015-10-12 17:43 ` [LTP] [PATCH v3] " Cyril Hrubis
2015-10-13 3:56 ` [LTP] [PATCH v5] " Guangwen Feng
2015-10-13 18:23 ` Cyril Hrubis
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox