0022-harness-Add-fallback-code-for-filesystems-not-suppor.patch 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. From ac60a850d5ce22ae21e3746f72a9ebb2623d17f8 Mon Sep 17 00:00:00 2001
  2. From: Guillem Jover <guillem@hadrons.org>
  3. Date: Sat, 20 Jul 2019 21:21:01 +0200
  4. Subject: [PATCH libaio 22/28] harness: Add fallback code for filesystems not
  5. supporting O_DIRECT
  6. When running the harness on a filesystem such as a tmpfs, which do not
  7. support O_DIRECT, fallback to calls without the flag.
  8. Signed-off-by: Guillem Jover <guillem@hadrons.org>
  9. [JEM: change from duplicating the open call to using F_SETFL]
  10. [JEM: 18 and 21 require O_DIRECT-skip if not present]
  11. Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
  12. ---
  13. harness/cases/17.t | 11 +++++++++--
  14. harness/cases/18.t | 2 ++
  15. harness/cases/19.t | 10 ++++++++--
  16. harness/cases/21.t | 5 ++++-
  17. 4 files changed, 23 insertions(+), 5 deletions(-)
  18. diff --git a/harness/cases/17.t b/harness/cases/17.t
  19. index 38ada4d..b4b6660 100644
  20. --- a/harness/cases/17.t
  21. +++ b/harness/cases/17.t
  22. @@ -119,7 +119,7 @@ void prune(io_context_t io_ctx, int max_ios, int getevents_type)
  23. void run_test(int max_ios, int getevents_type)
  24. {
  25. - int fd, ret;
  26. + int fd, ret, flags;
  27. long i, to_submit;
  28. struct iocb **iocb_sub;
  29. io_context_t io_ctx;
  30. @@ -137,9 +137,16 @@ void run_test(int max_ios, int getevents_type)
  31. events = calloc(max_ios, sizeof(*events));
  32. unlink(filename);
  33. - fd = open(filename, O_CREAT | O_RDWR | O_DIRECT, 0644);
  34. + fd = open(filename, O_CREAT | O_RDWR, 0644);
  35. assert(fd >= 0);
  36. + /*
  37. + * Use O_DIRECT if it's available. If it's not, the test code
  38. + * will still operate correctly, just potentially slower.
  39. + */
  40. + flags = fcntl(fd, F_GETFL, 0);
  41. + fcntl(fd, F_SETFL, flags | O_DIRECT);
  42. +
  43. ret = ftruncate(fd, max_ios * io_size);
  44. assert(!ret);
  45. diff --git a/harness/cases/18.t b/harness/cases/18.t
  46. index daa1d26..e8dbcd1 100644
  47. --- a/harness/cases/18.t
  48. +++ b/harness/cases/18.t
  49. @@ -53,6 +53,8 @@ aio_worker(void *ptr)
  50. assert(buffer != NULL);
  51. fd = open(FILENAME, O_DIRECT|O_RDONLY);
  52. + if (fd < 0 && errno == EINVAL)
  53. + exit(3); /* skip this test, O_DIRECT is unavailable */
  54. assert(fd >= 0);
  55. for (i = 0; i < 1000; i++) {
  56. diff --git a/harness/cases/19.t b/harness/cases/19.t
  57. index 5c3e0d6..ba1c620 100644
  58. --- a/harness/cases/19.t
  59. +++ b/harness/cases/19.t
  60. @@ -38,15 +38,21 @@ struct aio_ring {
  61. int
  62. open_temp_file(void)
  63. {
  64. - int fd;
  65. + int fd, flags;
  66. char template[sizeof(TEMPLATE)];
  67. strncpy(template, TEMPLATE, sizeof(template));
  68. - fd = mkostemp(template, O_DIRECT);
  69. + fd = mkstemp(template);
  70. if (fd < 0) {
  71. perror("mkstemp");
  72. exit(1);
  73. }
  74. + /*
  75. + * O_DIRECT is desirable, but not required for this test.
  76. + */
  77. + flags = fcntl(F_GETFL, 0);
  78. + fcntl(F_SETFL, flags | O_DIRECT);
  79. +
  80. unlink(template);
  81. return fd;
  82. }
  83. diff --git a/harness/cases/21.t b/harness/cases/21.t
  84. index fe33a9d..ba988ed 100644
  85. --- a/harness/cases/21.t
  86. +++ b/harness/cases/21.t
  87. @@ -92,7 +92,10 @@ test_main()
  88. */
  89. flags = fcntl(fd, F_GETFL);
  90. ret = fcntl(fd, F_SETFL, flags | O_DIRECT);
  91. - if (ret != 0) {
  92. + if (ret < 0) {
  93. + /* SKIP this test if O_DIRECT is not available on this fs */
  94. + if (errno == EINVAL)
  95. + return 3;
  96. perror("fcntl");
  97. return 1;
  98. }
  99. --
  100. 2.26.0.292.g33ef6b2f38