Ceph-Rados
view release on metacpan or search on metacpan
979899100101102103104105106107108109110111112113114115116117118119120121122123124125
CODE:
buf = (const char *)SvPV(data, len);
err = rados_append(io, oid, buf, len);
if
(err < 0)
croak(
"cannot append to object '%s': %s"
, oid, strerror(-err));
RETVAL = err == 0;
OUTPUT:
RETVAL
void
_stat(io, oid)
rados_ioctx_t io
const char * oid
PREINIT:
size_t size;
time_t mtime;
int
err;
PPCODE:
err = rados_stat(io, oid,
&size
,
&mtime
);
if
(err < 0)
croak(
"cannot stat object '%s': %s"
, oid, strerror(-err));
XPUSHs(sv_2mortal(newSVuv(size)));
XPUSHs(sv_2mortal(newSVuv(mtime)));
SV *
_read(io, oid, len, off = 0)
rados_ioctx_t io
const char * oid
153154155156157158159160161162163164165166167168169170171172173
size_t psize;
time_t pmtime;
int
err;
INIT:
PerlIO * io = IoOFP(sv_2io(fh));
int
chk_sz = 1024 * 1024;
Newx(buf, chk_sz, char);
CODE:
if
((0 == len) || debug) {
//
stat
and determine
read
length
err = rados_stat(ioctx, oid,
&psize
,
&pmtime
);
if
(err < 0)
croak(
"cannot stat object '%s': %s"
, oid, strerror(-err));
}
if
(0 == len)
len = psize-off;
if
(debug)
printf
(
"preparing to write from %s to FH, %zu bytes\n"
, oid, len);
for
(bufpos=off; bufpos<len+off; bufpos+=chk_sz) {
// logic is
'will bufpos move past ien+off next cycle'
buflen = len+off < bufpos+chk_sz ? len % chk_sz : chk_sz;
lib/Ceph/Rados.pm view on Meta::CPAN
90919293949596979899100101102103104105106107108109110
my
$cluster
= Ceph::Rados->new(
'admin'
);
$cluster
->set_config_file;
$cluster
->set_config_option(
keyring
=>
'/etc/ceph/ceph.client.admin.keyring'
);
$cluster
->
connect
;
my
$io
=
$cluster
->io(
'testing_pool'
);
$io
->
write
(
'greeting'
,
'hello'
);
my
$stored_data
=
$io
->
read
(
'greeting'
,10);
my
(
$len
,
$mtime
) =
$io
->
stat
(
'greeting'
);
$io
->
delete
(
'greeting'
);
my
$list
=
$io
->list;
while
(
my
$entry
=
$list
->
next
) {
"Found $entry\n"
;
}
=head1 DESCRIPTION
This module provides a very limited subset of the librados API,
lib/Ceph/Rados/IO.pm view on Meta::CPAN
949596979899100101102103104105106107108109110111112113114}
sub
read_handle_perl {
my
(
$self
,
$oid
,
$handle
,
$len
,
$off
) =
@_
;
my
$is_filehandle
= openhandle(
$handle
);
my
$is_writable_object
= blessed(
$handle
) and
$handle
->can(
'write'
);
Carp::confess
"Called with neither an open filehandle equivalent nor an object with a \`write\` method"
unless
$is_filehandle
or
$is_writable_object
;
$off
//= 0;
if
(!
$len
) {
(
$len
,
undef
) =
$self
->_stat(
$oid
);
}
my
$count
= 0;
#
for
(
my
$pos
=
$off
;
$pos
<=
$len
+
$off
;
$pos
+=
$DEFAULT_OSD_MAX_WRITE
) {
my
$chunk
;
if
(
$pos
+
$DEFAULT_OSD_MAX_WRITE
>
$len
) {
$chunk
=
$len
%
$DEFAULT_OSD_MAX_WRITE
;
}
else
{
$chunk
=
$DEFAULT_OSD_MAX_WRITE
;
}
lib/Ceph/Rados/IO.pm view on Meta::CPAN
132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
}
else
{
Carp::confess
"Called with neither an open filehandle equivalent nor an object with a \`write\` method"
;
}
}
sub
read
{
my
(
$self
,
$oid
,
$len
,
$off
) =
@_
;
# if undefined is passed as len, we stat the obj first to get the correct len
if
(!
defined
(
$len
)) {
(
$len
,
undef
) =
$self
->
stat
(
$oid
);
}
$off
||= 0;
$self
->_read(
$oid
,
$len
,
$off
);
}
sub
stat
{
my
(
$self
,
$oid
) =
@_
;
$self
->_stat(
$oid
);
}
sub
pool_required_alignment {
my
(
$self
) =
@_
;
return
$self
->_pool_required_alignment();
}
sub
mtime {
my
(
$self
,
$oid
) =
@_
;
my
(
undef
,
$mtime
) =
$self
->
stat
(
$oid
);
$mtime
;
}
sub
size {
my
(
$self
,
$oid
) =
@_
;
my
(
$size
,
undef
) =
$self
->
stat
(
$oid
);
$size
;
}
# Autoload methods go after =cut, and are processed by the autosplit program.
1;
__END__
# Below is stub documentation for your module. You'd better edit it!
=head1 NAME
lib/Ceph/Rados/IO.pm view on Meta::CPAN
190191192193194195196197198199200201202203204205206207208209210211212=head2 write_data(oid, data)
=head2 write_handle(oid, handle)
As L<write_data()>, but explicitly declaring the source type.
=head2 append(oid, data)
Wraps C<rados_append()>. Appends data to the ceph object with the supplied ID. Data must be a perl scalar, not a handle. Returns 1 on success. Croaks on failure.
=head2 stat(oid)
Wraps C<rados_stat()>. Returns a 2-element list of (filesize, mtime) for the ceph object with the supplied ID.
=head2 read(oid, len=filesize, offset=0)
Wraps C<rados_read()>. Read data from the ceph object with the supplied ID, and return the data read. Croaks on failure.
=head2 read_handle(oid, handle)
As C<read()>, but writes the data directly to the supplied handle instead of returning it.
=head2 remove(oid)
t/100_raw_api_crud.t view on Meta::CPAN
293031323334353637383940414243444546474849ok(
$io
->
write
(
$filename
,
$content
),
"Write object"
);
ok(
$io
->mtime(
$filename
),
"Get file mod time"
);
my
$length
;
ok(
$length
=
$io
->size(
$filename
),
"Get file size"
);
is(
$length
,
length
(
$content
),
"Get correct size"
);
$length
=
length
(
$content
);
# just to be sure following tests don't fail if above does
ok(
my
$stored_data
=
$io
->
read
(
$filename
,
$length
),
"Read $length bytes from object"
);
is(
$stored_data
,
$content
,
"Get back content ok"
);
ok(
my
$stored_data2
=
$io
->
read
(
$filename
),
"Read unknown bytes from object"
);
is(
$stored_data2
,
$content
,
"Get back content ok without read size"
);
ok(
my
(
$stat_size
,
$stat_mtime
) =
$io
->
stat
(
$filename
),
"Stat object"
);
is(
$stat_size
,
$length
,
"Stat size is same as content length"
);
ok(
$list
=
$io
->list,
"Opened list context"
);
my
$match
= 0;
while
(
my
$entry
=
$list
->
next
) {
#diag "Found $entry";
$match
= 1
if
$entry
eq
$filename
;
}
ok(
$match
,
"List contains written file"
);
ok(
$io
->remove(
$filename
),
"Remove object"
);
lives_ok {
undef
$list
}
"Closed list context"
;
( run in 1.361 second using v1.01-cache-2.11-cpan-49f99fa48dc )