tout(cct) << "fchmod" << std::endl;
tout(cct) << fd << std::endl;
tout(cct) << mode << std::endl;
- assert(fd_map.count(fd));
- Fh *f = fd_map[fd];
+ Fh *f = get_filehandle(fd);
+ if (!f)
+ return -EBADF;
struct stat attr;
attr.st_mode = mode;
return _setattr(f->inode, &attr, CEPH_SETATTR_MODE);
tout(cct) << "close" << std::endl;
tout(cct) << fd << std::endl;
- assert(fd_map.count(fd));
- Fh *fh = fd_map[fd];
+ Fh *fh = get_filehandle(fd);
+ if (!fh)
+ return -EBADF;
_release_fh(fh);
fd_map.erase(fd);
ldout(cct, 3) << "close exit(" << fd << ")" << dendl;
tout(cct) << offset << std::endl;
tout(cct) << whence << std::endl;
- assert(fd_map.count(fd));
- Fh *f = fd_map[fd];
+ Fh *f = get_filehandle(fd);
+ if (!f)
+ return -EBADF;
return _lseek(f, offset, whence);
}
tout(cct) << size << std::endl;
tout(cct) << offset << std::endl;
- assert(fd_map.count(fd));
- Fh *f = fd_map[fd];
+ Fh *f = get_filehandle(fd);
+ if (!f)
+ return -EBADF;
bufferlist bl;
int r = _read(f, offset, size, &bl);
ldout(cct, 3) << "read(" << fd << ", " << (void*)buf << ", " << size << ", " << offset << ") = " << r << dendl;
tout(cct) << size << std::endl;
tout(cct) << offset << std::endl;
- assert(fd_map.count(fd));
- Fh *fh = fd_map[fd];
+ Fh *fh = get_filehandle(fd);
+ if (!fh)
+ return -EBADF;
int r = _write(fh, offset, size, buf);
ldout(cct, 3) << "write(" << fd << ", \"...\", " << size << ", " << offset << ") = " << r << dendl;
return r;
tout(cct) << fd << std::endl;
tout(cct) << length << std::endl;
- assert(fd_map.count(fd));
- Fh *f = fd_map[fd];
+ Fh *f = get_filehandle(fd);
+ if (!f)
+ return -EBADF;
struct stat attr;
attr.st_size = length;
return _setattr(f->inode, &attr, CEPH_SETATTR_SIZE);
tout(cct) << fd << std::endl;
tout(cct) << syncdataonly << std::endl;
- assert(fd_map.count(fd));
- Fh *f = fd_map[fd];
+ Fh *f = get_filehandle(fd);
+ if (!f)
+ return -EBADF;
int r = _fsync(f, syncdataonly);
ldout(cct, 3) << "fsync(" << fd << ", " << syncdataonly << ") = " << r << dendl;
return r;
tout(cct) << "fstat" << std::endl;
tout(cct) << fd << std::endl;
- assert(fd_map.count(fd));
- Fh *f = fd_map[fd];
+ Fh *f = get_filehandle(fd);
+ if (!f)
+ return -EBADF;
int r = _getattr(f->inode, -1);
if (r < 0)
return r;
ldout(cct, 3) << "op: client->lazyio_propogate(" << fd
<< ", " << offset << ", " << count << ")" << dendl;
- assert(fd_map.count(fd));
- Fh *f = fd_map[fd];
+ Fh *f = get_filehandle(fd);
+ if (!f)
+ return -EBADF;
// for now
_fsync(f, true);
ldout(cct, 3) << "op: client->lazyio_synchronize(" << fd
<< ", " << offset << ", " << count << ")" << dendl;
- assert(fd_map.count(fd));
- Fh *f = fd_map[fd];
+ Fh *f = get_filehandle(fd);
+ if (!f)
+ return -EBADF;
Inode *in = f->inode;
_fsync(f, true);
{
Mutex::Locker lock(client_lock);
- assert(fd_map.count(fd));
- Fh *f = fd_map[fd];
+ Fh *f = get_filehandle(fd);
+ if (!f)
+ return -EBADF;
Inode *in = f->inode;
*lp = in->layout;
{
Mutex::Locker lock(client_lock);
- assert(fd_map.count(fd));
- Fh *f = fd_map[fd];
+ Fh *f = get_filehandle(fd);
+ if (!f)
+ return -EBADF;
Inode *in = f->inode;
// which object?
{
Mutex::Locker lock(client_lock);
- assert(fd_map.count(fd));
- Fh *f = fd_map[fd];
+ Fh *f = get_filehandle(fd);
+ if (!f)
+ return -EBADF;
Inode *in = f->inode;
// map to a list of extents
ceph_shutdown(cmount);
}
+TEST(LibCephFS, BadFileDesc) {
+ struct ceph_mount_info *cmount;
+ ASSERT_EQ(ceph_create(&cmount, NULL), 0);
+ ASSERT_EQ(ceph_conf_read_file(cmount, NULL), 0);
+ ASSERT_EQ(ceph_mount(cmount, NULL), 0);
+
+ ASSERT_EQ(ceph_fchmod(cmount, -1, 0655), -EBADF);
+ ASSERT_EQ(ceph_close(cmount, -1), -EBADF);
+ ASSERT_EQ(ceph_lseek(cmount, -1, 0, SEEK_SET), -EBADF);
+ char buf[0];
+ ASSERT_EQ(ceph_read(cmount, -1, buf, 0, 0), -EBADF);
+ ASSERT_EQ(ceph_write(cmount, -1, buf, 0, 0), -EBADF);
+
+ ASSERT_EQ(ceph_ftruncate(cmount, -1, 0), -EBADF);
+ ASSERT_EQ(ceph_fsync(cmount, -1, 0), -EBADF);
+
+ struct stat stat;
+ ASSERT_EQ(ceph_fstat(cmount, -1, &stat), -EBADF);
+
+ struct sockaddr_storage addr;
+ ASSERT_EQ(ceph_get_file_stripe_address(cmount, -1, 0, &addr, 1), -EBADF);
+
+ ASSERT_EQ(ceph_get_file_stripe_unit(cmount, -1), -EBADF);
+ ASSERT_EQ(ceph_get_file_pool(cmount, -1), -EBADF);
+ ASSERT_EQ(ceph_get_file_replication(cmount, -1), -EBADF);
+}