Project

General

Profile

Actions

Bug #69315

closed
DP DP

client: async paths without OC fails for non-contiguous I/O

Bug #69315: client: async paths without OC fails for non-contiguous I/O

Added by Dhairya Parmar almost 2 years ago. Updated almost 2 years ago.

Status:
Rejected
Priority:
Urgent
Category:
Correctness/Safety
Target version:
Due date:
% Done:

0%

Source:
Development
Backport:
squid,reef
Regression:
No
Severity:
2 - major
Reviewed:
Affected Versions:
ceph-qa-suite:
Component(FS):
Client, libcephfs
Labels (FS):
Pull request ID:
Tags (freeform):
Merge Commit:
Fixed In:
Released In:
Upkeep Timestamp:

Description

Test case:

TEST_F(TestClient, LlreadvLlwritevNonContiguous) {
  /* Test writing at non-contiguous memory locations, and make sure read at
  the exact locations where the buffers are written and the bytes read should
  be equal to the bytes written.  */

  int mypid = getpid();
  char filename[256];

  sprintf(filename, "test_llreadvllwritevnoncontiguousfile%u", mypid);

  Inode *root, *file;
  root = client->get_root();
  ASSERT_NE(root, (Inode *)NULL);

  Fh *fh;
  struct ceph_statx stx;

  ASSERT_EQ(0, client->ll_createx(root, filename, 0666,
                  O_RDWR | O_CREAT | O_TRUNC,
                  &file, &fh, &stx, 0, 0, myperm));

  const int NUM_BUF = 5;
  char out_buf_0[] = "hello ";
  char out_buf_1[] = "world\n";
  char out_buf_2[] = "Ceph - ";
  char out_buf_3[] = "a scalable distributed ";
  char out_buf_4[] = "storage system\n";

  struct iovec iov_out_non_contiguous[NUM_BUF] = {
    {out_buf_0, sizeof(out_buf_0)},
    {out_buf_1, sizeof(out_buf_1)},
    {out_buf_2, sizeof(out_buf_2)},
    {out_buf_3, sizeof(out_buf_3)},
    {out_buf_4, sizeof(out_buf_4)}
  };

  char in_buf_0[sizeof(out_buf_0)];
  char in_buf_1[sizeof(out_buf_1)];
  char in_buf_2[sizeof(out_buf_2)];
  char in_buf_3[sizeof(out_buf_3)];
  char in_buf_4[sizeof(out_buf_4)];

  struct iovec iov_in_non_contiguous[NUM_BUF] = {
    {in_buf_0, sizeof(in_buf_0)},
    {in_buf_1, sizeof(in_buf_1)},
    {in_buf_2, sizeof(in_buf_2)},
    {in_buf_3, sizeof(in_buf_3)},
    {in_buf_4, sizeof(in_buf_4)}
  };

  ssize_t bytes_to_write = 0, total_bytes_written = 0, total_bytes_read = 0;
  for(int i = 0; i < NUM_BUF; ++i) {
    bytes_to_write += iov_out_non_contiguous[i].iov_len;
  }

  std::unique_ptr<C_SaferCond> writefinish = nullptr;
  std::unique_ptr<C_SaferCond> readfinish = nullptr;

  int64_t rc;
  bufferlist bl, tmpbl;

  struct iovec *current_iov = iov_out_non_contiguous;

  for(int i = 0; i < NUM_BUF; ++i) {
    writefinish.reset(new C_SaferCond("test-nonblocking-writefinish-non-contiguous"));
    rc = client->ll_preadv_pwritev(fh, current_iov++, 1, i * NUM_BUF * 10,
                                   true, writefinish.get(), nullptr);
    ASSERT_EQ(rc, 0);
    rc = writefinish->wait();
    ASSERT_EQ(rc, iov_out_non_contiguous[i].iov_len);
    total_bytes_written += rc;
  }
  ASSERT_EQ(total_bytes_written, bytes_to_write);

  current_iov = iov_in_non_contiguous;

  for(int i = 0; i < NUM_BUF; ++i) {
    readfinish.reset(new C_SaferCond("test-nonblocking-readfinish-non-contiguous"));
    ssize_t bytes_read = 0;
    rc = client->ll_preadv_pwritev(fh, current_iov++, 1, i * NUM_BUF * 10,
                                   false, readfinish.get(), &tmpbl);
    // std::cout << "##### [" << i << "]" << "temp bl ptr: " << tmpbl << std::endl;
    std::cout << "##### [" << i << "]" << "temp bl data: " << tmpbl.to_str() << std::endl;
    bl.append(tmpbl);
    ASSERT_EQ(rc, 0);
    bytes_read = readfinish->wait();
    ASSERT_EQ(bytes_read, iov_out_non_contiguous[i].iov_len);
    total_bytes_read += bytes_read; 
  }
  ASSERT_EQ(total_bytes_read, bytes_to_write);

  // std::cout << "$$$$$ bufferlist ptr: " << bl << std::endl;
  std::cout << "$$$$$ bufferlist data: " << bl.to_str() << std::endl;
  copy_bufferlist_to_iovec(iov_in_non_contiguous, NUM_BUF, &bl, total_bytes_read);
  for(int i = 0; i < NUM_BUF; ++i) {
    ASSERT_EQ(0, strncmp((const char*)iov_in_non_contiguous[i].iov_base,
                         (const char*)iov_out_non_contiguous[i].iov_base,
                         iov_out_non_contiguous[i].iov_len));
  }

  client->ll_release(fh);
  ASSERT_EQ(0, client->ll_unlink(root, filename, myperm));        
}

When ran with ObjectCacher enabled i.e. client_oc=true (which is true by default), the test case passes:

[       OK ] TestClient.LlreadvLlwritevNonContiguous (170 ms)

but when ran without ObjectCacher (--client_oc=false):

[  FAILED  ] TestClient.LlreadvLlwritevNonContiguous (2654 ms)

It fails.

(A bit off-topic - not only it failed but test cases in general take 2X time to execute with Filer is what my general observation is, I have some faint memory of Filer being used because ObjectCacher eats up memory, unsure if it's Ganesha or Ceph side but we should advocate for ObjectCacher and fix any leaks on our side, anyway this is a separate topic for some other day.)

It fails with:

Expected equality of these values:
  0
  strncmp((const char*)iov_in_non_contiguous[i].iov_base, (const char*)iov_out_non_contiguous[i].iov_base, iov_out_non_contiguous[i].iov_len)
    Which is: -15

I.e. the str1 is < str2 meaning the data in iov_in_non_contiguous which is the read data is less than write data (iov_out_non_contiguous).

When I added some debug std::cout lines for the buffers which store data for read iovec structs, I see this:

1. With ObjectCacher:

##### [0]temp bl data: hello

##### [1]temp bl data: world

##### [2]temp bl data: Ceph -

##### [3]temp bl data: a scalable distributed

##### [4]temp bl data: storage system

$$$$$ bufferlist data: hello world
Ceph - a scalable distributed storage system

2. Without ObjectCacher (i.e. Filer):

##### [0]temp bl data:

##### [1]temp bl data: hello

##### [2]temp bl data: hello world

##### [3]temp bl data: hello world

##### [4]temp bl data: hello world

$$$$$ bufferlist data: hello hello world
hello world
Ceph - hello world
Ceph - a scalable distributed

buffers in the case without ObjectCacher are distorted.

If it was the test case, then it should've failed in both the cases and on top of that I've checked the code twice and it looks fine. If anyone finds anything that I might've overlooked then do let me know. I'm not sure what's going on since I'm not that well versed with Filer code. There might also be something with async I/O passing the context and it getting mishandled somewhere - need to check.


Files

client.admin.199534.log (74.3 KB) client.admin.199534.log Dhairya Parmar, 12/23/2024 02:47 PM
client.admin.216311.oc.enabled.log (90.9 KB) client.admin.216311.oc.enabled.log Dhairya Parmar, 12/23/2024 04:36 PM

Related issues 1 (1 open — 0 closed)

Related to CephFS - Bug #69347: Test failure: test_async_io_fio (tasks.cephfs.test_nfs.TestNFS)Triaged

Actions

DP Updated by Dhairya Parmar almost 2 years ago Actions #1

  • Category set to Correctness/Safety
  • Source set to Development
  • Component(FS) Client, libcephfs added

DP Updated by Dhairya Parmar almost 2 years ago Actions #2

  • Description updated (diff)

DP Updated by Dhairya Parmar almost 2 years ago ยท Edited Actions #3

I checked the logs for write and they look processed as it should be:

2024-12-23T18:37:02.355+0530 7f20e895b6c0 19 client.4279 C_Write_Finisher::try_complete this 0x5611ad7c10e0 onuninlinefinished 1 iofinished 1 iofinished_r 7 fsync_finished 1
2024-12-23T18:37:02.355+0530 7f20e895b6c0 19 client.4279  complete with iofinished_r 7
2024-12-23T18:37:02.368+0530 7f20e895b6c0 19 client.4279 C_Write_Finisher::try_complete this 0x5611ad71e7d0 onuninlinefinished 1 iofinished 1 iofinished_r 7 fsync_finished 1
2024-12-23T18:37:02.368+0530 7f20e895b6c0 19 client.4279  complete with iofinished_r 7
2024-12-23T18:37:02.381+0530 7f20e895b6c0 19 client.4279 C_Write_Finisher::try_complete this 0x5611ad72e830 onuninlinefinished 1 iofinished 1 iofinished_r 8 fsync_finished 1
2024-12-23T18:37:02.381+0530 7f20e895b6c0 19 client.4279  complete with iofinished_r 8
2024-12-23T18:37:02.394+0530 7f20e895b6c0 19 client.4279 C_Write_Finisher::try_complete this 0x5611ad729450 onuninlinefinished 1 iofinished 1 iofinished_r 24 fsync_finished 1
2024-12-23T18:37:02.394+0530 7f20e895b6c0 19 client.4279  complete with iofinished_r 24
2024-12-23T18:37:02.407+0530 7f20e895b6c0 19 client.4279 C_Write_Finisher::try_complete this 0x5611ad6aaa70 onuninlinefinished 1 iofinished 1 iofinished_r 16 fsync_finished 1
2024-12-23T18:37:02.407+0530 7f20e895b6c0 19 client.4279  complete with iofinished_r 16

i suspect read path going haywire somewhere.

VS Updated by Venky Shankar almost 2 years ago Actions #4

  • Assignee set to Dhairya Parmar
  • Priority changed from Normal to Urgent
  • Target version set to v20.0.0

VS Updated by Venky Shankar almost 2 years ago Actions #6

Dhairya, do you also have the logs with oc enabled? It might get a bit easier to debug the issue.

VS Updated by Venky Shankar almost 2 years ago Actions #7

  • Backport set to squid,reef
  • Severity changed from 3 - minor to 2 - major

DP Updated by Dhairya Parmar almost 2 years ago Actions #8

@Venky Shankar attaching client log for the same test case with OC enabled.

VS Updated by Venky Shankar almost 2 years ago Actions #9

  • Related to Bug #69347: Test failure: test_async_io_fio (tasks.cephfs.test_nfs.TestNFS) added

DP Updated by Dhairya Parmar almost 2 years ago Actions #10

So there's more to this:

If I tweak the test case a bit by clearing the tmpbl (tmpbl.clear();) after each iteration (just to be sure it doesn't mess up the bl), I have this:

##### [0]temp bl data:

##### [1]temp bl data: hello 

##### [2]temp bl data: world

##### [3]temp bl data: Ceph - 

##### [4]temp bl data: a scalable distributed 

$$$$$ bufferlist data: hello world
Ceph - a scalable distributed 
unknown file: Failure
C++ exception with description "End of buffer [buffer:2]" thrown in the test body.

VS Updated by Venky Shankar almost 2 years ago Actions #11

I think it will help a bit to first rule out any unsafe (lockless!) access to the bufferlist (in the client) that could be causing mangled data.

DP Updated by Dhairya Parmar almost 2 years ago Actions #12

Looks like it is how the way bufflist is updated in the test case. bl.append(tmpbl) occurs right after the ll_preadv_pwritev call. So, for OC enabled, the tmpbl has the correct info and so is the bl but for Filer, the tmpbl goes haywire. if that line (bl.append(tmpbl)) is shifted down after the context is completed (along with adding a tmpbl.clear()), it works fine and the test case passes. Do long story short, it's being noticed that OC and Filer are behaving differently with bufferlist. Maybe because OC caches the data because there is also the readahead while Filer is just a direct osdc call. I'm not sure if this is what the behaviour should be but tweaking the test case with what I mentioned, does solve the issue. it's added in [0].

[0] https://github.com/ceph/ceph/pull/54435/commits/d6143a4e2b7a4595a69d71aa63d0d57681948ee6#diff-67a20aae67cffa6ae8fad5bdad208d9a73c1868bf52c353002288ea015be65b3R798

DP Updated by Dhairya Parmar almost 2 years ago Actions #13

  • Status changed from New to Rejected

The test case in description used to append buffer before the context completion takes place. This never caught attention with OC enabled because the buffers are cached (readahead) and usually the test case passes but not with Filer (OC disabled). With correctly placing the bl.append(tmpbl) line, the test case works fine.

Actions

Also available in: PDF Atom