Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
add support for rados_striper functions in rados_device.c where it cu…
…rrently dosn't exist

Signed-off-by: Marco van Wieringen <marco.van.wieringen@bareos.com>
  • Loading branch information
matt01 authored and Marco van Wieringen committed Feb 11, 2016
1 parent cdfc6b7 commit 6bc9461
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 11 deletions.
88 changes: 77 additions & 11 deletions src/stored/backends/rados_device.c
Expand Up @@ -263,7 +263,15 @@ int rados_device::d_open(const char *pathname, int flags, int mode)
/*
* See if the object already exists.
*/
#ifdef HAVE_RADOS_STRIPER
if (m_stripe_volume) {
status = rados_striper_stat(m_striper, m_virtual_filename, &object_size, &object_mtime);
} else {
status = rados_stat(m_ctx, m_virtual_filename, &object_size, &object_mtime);
}
#else
status = rados_stat(m_ctx, m_virtual_filename, &object_size, &object_mtime);
#endif

/*
* See if the O_CREAT flag is set.
Expand All @@ -278,8 +286,8 @@ int rados_device::d_open(const char *pathname, int flags, int mode)
*/
#ifdef HAVE_RADOS_STRIPER
if (m_stripe_volume) {
rados_striper_write(m_ctx, m_virtual_filename, " ", 1, 0);
rados_striper_trunc(m_ctx, m_virtual_filename, 0);
rados_striper_write(m_striper, m_virtual_filename, " ", 1, 0);
rados_striper_trunc(m_striper, m_virtual_filename, 0);
} else {
#endif
rados_write(m_ctx, m_virtual_filename, " ", 1, 0);
Expand Down Expand Up @@ -319,7 +327,7 @@ int rados_device::d_open(const char *pathname, int flags, int mode)
ssize_t rados_device::read_object_data(boffset_t offset, char *buffer, size_t count)
{
#ifdef HAVE_RADOS_STRIPER
if (m_striper) {
if (m_stripe_volume) {
return rados_striper_read(m_striper, m_virtual_filename, buffer, count, offset);
} else {
#endif
Expand Down Expand Up @@ -429,6 +437,20 @@ int rados_device::d_ioctl(int fd, ioctl_req_t request, char *op)
return -1;
}

#ifdef HAVE_RADOS_STRIPER
ssize_t rados_device::striper_volume_size()
{
uint64_t object_size;
time_t object_mtime;

if (rados_striper_stat(m_striper, m_virtual_filename, &object_size, &object_mtime) == 0) {
return object_size;
} else {
return -1;
}
}
#endif

ssize_t rados_device::volume_size()
{
uint64_t object_size;
Expand All @@ -453,7 +475,16 @@ boffset_t rados_device::d_lseek(DCR *dcr, boffset_t offset, int whence)
case SEEK_END: {
ssize_t filesize;

#ifdef HAVE_RADOS_STRIPER
if (m_stripe_volume) {
filesize = striper_volume_size();
} else {
filesize = volume_size();
}
#else
filesize = volume_size();
#endif

if (filesize >= 0) {
m_offset = filesize + offset;
} else {
Expand All @@ -468,23 +499,50 @@ boffset_t rados_device::d_lseek(DCR *dcr, boffset_t offset, int whence)
return m_offset;
}

bool rados_device::truncate_volume(DCR *dcr)
#ifdef HAVE_RADOS_STRIPER
bool rados_device::truncate_striper_volume(DCR *dcr)
{
int status;
uint64_t object_size;
time_t object_mtime;
berrno be;

#ifdef HAVE_RADOS_STRIPER
if (m_stripe_volume) {
status = rados_striper_trunc(m_ctx, m_virtual_filename, 0);
} else {
#endif
status = rados_trunc(m_ctx, m_virtual_filename, 0);
#ifdef HAVE_RADOS_STRIPER
status = rados_striper_trunc(m_striper, m_virtual_filename, 0);
if (status < 0) {
Mmsg2(errmsg, _("Unable to truncate device %s. ERR=%s\n"), prt_name, be.bstrerror(-status));
Emsg0(M_FATAL, 0, errmsg);
return false;
}

status = rados_striper_stat(m_striper, m_virtual_filename, &object_size, &object_mtime);
if (status < 0) {
Mmsg2(errmsg, _("Unable to stat volume %s. ERR=%s\n"), m_virtual_filename, be.bstrerror(-status));
Dmsg1(100, "%s", errmsg);
return false;
}

if (object_size != 0) { /* rados_trunc() didn't work. */
status = rados_striper_remove(m_striper, m_virtual_filename);
if (status < 0) {
Mmsg2(errmsg, _("Unable to remove volume %s. ERR=%s\n"), m_virtual_filename, be.bstrerror(-status));
Dmsg1(100, "%s", errmsg);
return false;
}
}

m_offset = 0;
return true;
}
#endif

bool rados_device::truncate_volume(DCR *dcr)
{
int status;
uint64_t object_size;
time_t object_mtime;
berrno be;

status = rados_trunc(m_ctx, m_virtual_filename, 0);
if (status < 0) {
Mmsg2(errmsg, _("Unable to truncate device %s. ERR=%s\n"), prt_name, be.bstrerror(-status));
Emsg0(M_FATAL, 0, errmsg);
Expand Down Expand Up @@ -514,7 +572,15 @@ bool rados_device::truncate_volume(DCR *dcr)
bool rados_device::d_truncate(DCR *dcr)
{
if (m_ctx) {
#ifdef HAVE_RADOS_STRIPER
if (m_stripe_volume) {
return truncate_striper_volume(dcr);
} else {
return truncate_volume(dcr);
}
#else
return truncate_volume(dcr);
#endif
}

return true;
Expand Down
6 changes: 6 additions & 0 deletions src/stored/backends/rados_device.h
Expand Up @@ -77,7 +77,13 @@ class rados_device: public DEVICE {
*/
ssize_t read_object_data(boffset_t offset, char *buffer, size_t count);
ssize_t write_object_data(boffset_t offset, char *buffer, size_t count);
#ifdef HAVE_RADOS_STRIPER
ssize_t striper_volume_size();
#endif
ssize_t volume_size();
#ifdef HAVE_RADOS_STRIPER
bool truncate_striper_volume(DCR *dcr);
#endif
bool truncate_volume(DCR *dcr);

public:
Expand Down

0 comments on commit 6bc9461

Please sign in to comment.