Skip to content

Commit

Permalink
Add support for changed rados_write API.
Browse files Browse the repository at this point in the history
Seems from version 0.68 to 0.69 the rados_write
function all of a sudden gives back 0 when succeeded and
no longer the actual bytes it wrote. As we also want to
support the old API it now checks the LIBRADOS_VERSION_CODE
  • Loading branch information
Marco van Wieringen committed Feb 17, 2015
1 parent 2ce0c0c commit 4fdcca0
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 deletions src/stored/backends/rados_device.c
Expand Up @@ -268,34 +268,58 @@ ssize_t rados_device::d_read(int fd, void *buffer, size_t count)

/*
* Write data to a volume using librados.
*
* Seems the API changed everything earlier then 0.69 returns bytes written.
*/
#if LIBRADOS_VERSION_CODE <= 17408
ssize_t rados_device::d_write(int fd, const void *buffer, size_t count)
{
if (m_ctx) {
int nr_written;

nr_written = rados_write(m_ctx, getVolCatName(), (char *)buffer, count, m_offset);

if (nr_written >= 0) {
m_offset += nr_written;
return nr_written;
} else {
errno = -nr_written;
return -1;
}
} else {
errno = EBADF;
return -1;
}
}
#else
ssize_t rados_device::d_write(int fd, const void *buffer, size_t count)
{
if (m_ctx) {
int status;

#ifdef HAVE_RADOS_STRIPER
if (m_striper) {
nr_written = rados_striper_write(m_striper, getVolCatName(), (char *)buffer, count, m_offset);
status = rados_striper_write(m_striper, getVolCatName(), (char *)buffer, count, m_offset);
} else {
#endif
nr_written = rados_write(m_ctx, getVolCatName(), (char *)buffer, count, m_offset);
status = rados_write(m_ctx, getVolCatName(), (char *)buffer, count, m_offset);
#ifdef HAVE_RADOS_STRIPER
}
#endif

if (nr_written >= 0) {
m_offset += nr_written;
return nr_written;
if (status == 0) {
m_offset += count;
return count;
} else {
errno = -nr_written;
errno = -status;
return -1;
}
} else {
errno = EBADF;
return -1;
}
}
#endif

int rados_device::d_close(int fd)
{
Expand Down

0 comments on commit 4fdcca0

Please sign in to comment.