Project

General

Profile

0001-tests-add-a-test-for-doing-a-getattr-while-caps-are-.patch

Jeff Layton, 02/20/2018 06:02 PM

Download (3.86 KB)

View differences:

src/test/libcephfs/deleg.cc
59 59
  struct ceph_statx stx;
60 60
  UserPerm *perms = ceph_mount_perms(cmount);
61 61

  
62
  ASSERT_EQ(ceph_ll_lookup(cmount, root, filename, &file, &stx, 0, 0, perms), 0);
62
  ASSERT_EQ(ceph_ll_lookup(cmount, root, filename, &file, &stx, CEPH_STATX_ALL_STATS, 0, perms), 0);
63 63
  int ret;
64 64
  for (;;) {
65
    ASSERT_EQ(ceph_ll_getattr(cmount, file, &stx, CEPH_STATX_ALL_STATS, 0, perms), 0);
65 66
    ret = ceph_ll_open(cmount, file, flags, &fh, perms);
66 67
    if (ret != -EAGAIN)
67 68
      break;
......
302 303
  ASSERT_EQ(ceph_ll_getattr(cmount, root, &stx, 0, 0, perms), -ENOTCONN);
303 304
  ceph_release(cmount);
304 305
}
306

  
307
TEST(LibCephFS, RecalledGetattr) {
308
  struct ceph_mount_info *cmount1;
309
  ASSERT_EQ(ceph_create(&cmount1, NULL), 0);
310
  ASSERT_EQ(ceph_conf_read_file(cmount1, NULL), 0);
311
  ASSERT_EQ(0, ceph_conf_parse_env(cmount1, NULL));
312
  ASSERT_EQ(ceph_mount(cmount1, "/"), 0);
313
  ASSERT_EQ(set_default_deleg_timeout(cmount1), 0);
314

  
315
  Inode *root, *file;
316
  ASSERT_EQ(ceph_ll_lookup_root(cmount1, &root), 0);
317

  
318
  char filename[32];
319
  sprintf(filename, "recalledgetattr%x", getpid());
320

  
321
  Fh *fh;
322
  struct ceph_statx stx;
323
  UserPerm *perms = ceph_mount_perms(cmount1);
324

  
325
  ASSERT_EQ(ceph_ll_create(cmount1, root, filename, 0666,
326
		    O_RDWR|O_CREAT|O_EXCL, &file, &fh, &stx, 0, 0, perms), 0);
327
  ASSERT_EQ(ceph_ll_write(cmount1, fh, 0, sizeof(filename), filename), sizeof(filename));
328
  ASSERT_EQ(ceph_ll_close(cmount1, fh), 0);
329

  
330
  /* New mount for read delegation */
331
  struct ceph_mount_info *cmount2;
332
  ASSERT_EQ(ceph_create(&cmount2, NULL), 0);
333
  ASSERT_EQ(ceph_conf_read_file(cmount2, NULL), 0);
334
  ASSERT_EQ(0, ceph_conf_parse_env(cmount2, NULL));
335
  ASSERT_EQ(ceph_mount(cmount2, "/"), 0);
336
  ASSERT_EQ(set_default_deleg_timeout(cmount2), 0);
337

  
338
  ASSERT_EQ(ceph_ll_lookup_root(cmount2, &root), 0);
339
  perms = ceph_mount_perms(cmount2);
340
  ASSERT_EQ(ceph_ll_lookup(cmount2, root, filename, &file, &stx, 0, 0, perms), 0);
341

  
342
  ASSERT_EQ(ceph_ll_open(cmount2, file, O_WRONLY, &fh, perms), 0);
343
  ASSERT_EQ(ceph_ll_write(cmount2, fh, 0, sizeof(filename), filename), sizeof(filename));
344
  ASSERT_EQ(ceph_ll_close(cmount2, fh), 0);
345

  
346
  ASSERT_EQ(ceph_ll_open(cmount2, file, O_RDONLY, &fh, perms), 0);
347

  
348
  /* Break delegation */
349
  std::atomic_bool recalled(false);
350
  ASSERT_EQ(ceph_ll_delegation(cmount2, fh, CEPH_DELEGATION_RD, dummy_deleg_cb, &recalled), 0);
351
  ASSERT_EQ(ceph_ll_read(cmount2, fh, 0, sizeof(filename), filename), sizeof(filename));
352
  ASSERT_EQ(ceph_ll_getattr(cmount2, file, &stx, CEPH_STATX_ALL_STATS, 0, perms), 0);
353
  std::atomic_bool opened(false);
354
  std::thread breaker1(open_breaker_func, cmount1, filename, O_WRONLY, &opened);
355
  do {
356
    ASSERT_EQ(ceph_ll_getattr(cmount2, file, &stx, CEPH_STATX_ALL_STATS, 0, perms), 0);
357
    usleep(1000);
358
  } while (!recalled.load());
359
  ASSERT_EQ(opened.load(), false);
360
  ASSERT_EQ(ceph_ll_getattr(cmount2, file, &stx, CEPH_STATX_ALL_STATS, 0, perms), 0);
361
  ASSERT_EQ(ceph_ll_delegation(cmount2, fh, CEPH_DELEGATION_NONE, dummy_deleg_cb, nullptr), 0);
362
  breaker1.join();
363
  ASSERT_EQ(ceph_ll_close(cmount2, fh), 0);
364
  ceph_unmount(cmount2);
365
  ceph_release(cmount2);
366
  ceph_unmount(cmount1);
367
  ceph_release(cmount1);
368
}
305
-