From: Jeff Layton Date: Mon, 1 Aug 2016 13:01:14 +0000 (-0400) Subject: test: add a link count test X-Git-Tag: ses5-milestone5~230^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=e8a898925afeb9f04883fa9a5fe081a3eeaedd3e;p=ceph.git test: add a link count test ...and use the lowlevel calls to emulate what ganesha would do. In particular, it dumps its inode from the cache after an unlink. So do a second lookup afterward and verify that the nlink field in the struct stat is valid. Signed-off-by: Jeff Layton --- diff --git a/src/test/libcephfs/test.cc b/src/test/libcephfs/test.cc index efb3a88555ed..2bf7ec1357e0 100644 --- a/src/test/libcephfs/test.cc +++ b/src/test/libcephfs/test.cc @@ -1374,3 +1374,37 @@ TEST(LibCephFS, OpenNoClose) { // shutdown should force close opened file/dir ceph_shutdown(cmount); } + +TEST(LibCephFS, Nlink) { + struct ceph_mount_info *cmount; + ASSERT_EQ(ceph_create(&cmount, NULL), 0); + ASSERT_EQ(ceph_conf_read_file(cmount, NULL), 0); + ASSERT_EQ(0, ceph_conf_parse_env(cmount, NULL)); + ASSERT_EQ(ceph_mount(cmount, "/"), 0); + + Inode *root, *dir, *file; + + ASSERT_EQ(ceph_ll_lookup_root(cmount, &root), 0); + + char dirname[32], filename[32], linkname[32]; + sprintf(dirname, "nlinkdir%x", getpid()); + sprintf(filename, "nlinkorig%x", getpid()); + sprintf(linkname, "nlinklink%x", getpid()); + + struct stat st; + Fh *fh; + + ASSERT_EQ(ceph_ll_mkdir(cmount, root, dirname, 0755, &st, &dir, getuid(), getgid()), 0); + ASSERT_EQ(ceph_ll_create(cmount, dir, filename, 0666, O_RDWR|O_CREAT|O_EXCL, + &st, &file, &fh, getuid(), getgid()), 0); + ASSERT_EQ(st.st_nlink, (nlink_t)1); + + ASSERT_EQ(ceph_ll_link(cmount, file, dir, linkname, &st, getuid(), getgid()), 0); + ASSERT_EQ(st.st_nlink, (nlink_t)2); + + ASSERT_EQ(ceph_ll_unlink(cmount, dir, linkname, getuid(), getgid()), 0); + ASSERT_EQ(ceph_ll_lookup(cmount, dir, filename, &st, &file, getuid(), getgid()), 0); + ASSERT_EQ(st.st_nlink, (nlink_t)1); + + ceph_shutdown(cmount); +}