Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client: check if Fh is readable when processing a read #7209

Merged
merged 2 commits into from Jan 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/client/Client.cc
Expand Up @@ -7405,6 +7405,8 @@ int Client::_read(Fh *f, int64_t offset, uint64_t size, bufferlist *bl)
const md_config_t *conf = cct->_conf;
Inode *in = f->inode.get();

if ((f->mode & CEPH_FILE_MODE_RD) == 0)
return -EBADF;
//bool lazy = f->mode == CEPH_FILE_MODE_LAZY;

bool movepos = false;
Expand Down
34 changes: 34 additions & 0 deletions src/test/libcephfs/test.cc
Expand Up @@ -66,6 +66,40 @@ TEST(LibCephFS, OpenEmptyComponent) {
ceph_shutdown(cmount);
}

TEST(LibCephFS, OpenReadWrite) {
struct ceph_mount_info *cmount;
ASSERT_EQ(0, ceph_create(&cmount, NULL));
ASSERT_EQ(0, ceph_conf_read_file(cmount, NULL));
ASSERT_EQ(0, ceph_conf_parse_env(cmount, NULL));
ASSERT_EQ(0, ceph_mount(cmount, "/"));

char c_path[1024];
sprintf(c_path, "test_open_rdwr_%d", getpid());
int fd = ceph_open(cmount, c_path, O_WRONLY|O_CREAT, 0666);
ASSERT_LT(0, fd);

const char *out_buf = "hello world";
size_t size = strlen(out_buf);
char in_buf[100];
ASSERT_EQ(ceph_write(cmount, fd, out_buf, size, 0), size);
ASSERT_EQ(ceph_read(cmount, fd, in_buf, sizeof(in_buf), 0), -EBADF);
ASSERT_EQ(0, ceph_close(cmount, fd));

fd = ceph_open(cmount, c_path, O_RDONLY, 0);
ASSERT_LT(0, fd);
ASSERT_EQ(ceph_write(cmount, fd, out_buf, size, 0), -EBADF);
ASSERT_EQ(ceph_read(cmount, fd, in_buf, sizeof(in_buf), 0), size);
ASSERT_EQ(0, ceph_close(cmount, fd));

fd = ceph_open(cmount, c_path, O_RDWR, 0);
ASSERT_LT(0, fd);
ASSERT_EQ(ceph_write(cmount, fd, out_buf, size, 0), size);
ASSERT_EQ(ceph_read(cmount, fd, in_buf, sizeof(in_buf), 0), size);
ASSERT_EQ(0, ceph_close(cmount, fd));

ceph_shutdown(cmount);
}

TEST(LibCephFS, MountNonExist) {

struct ceph_mount_info *cmount;
Expand Down