diff --git a/node-binding/addon.cc b/node-binding/addon.cc index 3cbc32c2..480edf91 100644 --- a/node-binding/addon.cc +++ b/node-binding/addon.cc @@ -16,6 +16,9 @@ NAN_MODULE_INIT(InitAddon) Nan::SetPrototypeMethod(tpl, "write", NodeVitastor::Write); Nan::SetPrototypeMethod(tpl, "sync", NodeVitastor::Sync); Nan::SetPrototypeMethod(tpl, "read_bitmap", NodeVitastor::ReadBitmap); + Nan::SetPrototypeMethod(tpl, "on_ready", NodeVitastor::OnReady); + Nan::SetPrototypeMethod(tpl, "get_min_io_size", NodeVitastor::GetMinIoSize); + Nan::SetPrototypeMethod(tpl, "get_max_atomic_write_size", NodeVitastor::GetMaxAtomicWriteSize); //Nan::SetPrototypeMethod(tpl, "destroy", NodeVitastor::Destroy); Nan::Set(target, Nan::New("Client").ToLocalChecked(), Nan::GetFunction(tpl).ToLocalChecked()); diff --git a/node-binding/client.cc b/node-binding/client.cc index f86ee06b..43db7b25 100644 --- a/node-binding/client.cc +++ b/node-binding/client.cc @@ -267,6 +267,53 @@ static void on_error(NodeVitastorRequest *req, Nan::Callback & nanCallback, long nanCallback.Call(1, args, req); } +// on_ready(callback(err)) +NAN_METHOD(NodeVitastor::OnReady) +{ + TRACE("NodeVitastor::OnReady"); + if (info.Length() < 1) + Nan::ThrowError("Not enough arguments to on_ready(callback(err))"); + NodeVitastor* self = Nan::ObjectWrap::Unwrap(info.This()); + v8::Local callback = info[0].As(); + auto req = new NodeVitastorRequest(self, callback); + self->Ref(); + vitastor_c_on_ready(self->c, on_ready_finish, req); +} + +void NodeVitastor::on_ready_finish(void *opaque, long retval) +{ + TRACE("NodeVitastor::on_ready_finish"); + auto req = (NodeVitastorRequest*)opaque; + auto self = req->cli; + Nan::HandleScope scope; + Nan::Callback nanCallback(Nan::New(req->callback)); + nanCallback.Call(0, NULL, req); + self->Unref(); + delete req; +} + +// get_min_io_size(pool_id) +NAN_METHOD(NodeVitastor::GetMinIoSize) +{ + TRACE("NodeVitastor::GetMinIoSize"); + if (info.Length() < 1) + Nan::ThrowError("Not enough arguments to get_min_io_size(pool_id)"); + NodeVitastor* self = Nan::ObjectWrap::Unwrap(info.This()); + uint64_t pool = get_ui64(info[0]); + info.GetReturnValue().Set(Nan::New(vitastor_c_inode_get_bitmap_granularity(self->c, INODE_WITH_POOL(pool, 1)))); +} + +// get_max_atomic_write_size(pool_id) +NAN_METHOD(NodeVitastor::GetMaxAtomicWriteSize) +{ + TRACE("NodeVitastor::GetMaxAtomicWriteSize"); + if (info.Length() < 1) + Nan::ThrowError("Not enough arguments to get_max_atomic_write_size(pool_id)"); + NodeVitastor* self = Nan::ObjectWrap::Unwrap(info.This()); + uint64_t pool = get_ui64(info[0]); + info.GetReturnValue().Set(Nan::New(vitastor_c_inode_get_block_size(self->c, INODE_WITH_POOL(pool, 1)))); +} + void NodeVitastor::on_read_finish(void *opaque, long retval, uint64_t version) { TRACE("NodeVitastor::on_read_finish"); diff --git a/node-binding/client.h b/node-binding/client.h index 2c807be4..cd10dbd0 100644 --- a/node-binding/client.h +++ b/node-binding/client.h @@ -15,14 +15,20 @@ class NodeVitastor: public Nan::ObjectWrap public: // constructor({ ...config }) static NAN_METHOD(Create); - // read(pool, inode, offset, len, callback(err, buffer, version)) + // read(pool_id, inode, offset, len, callback(err, buffer, version)) static NAN_METHOD(Read); - // write(pool, inode, offset, buf: Buffer | Buffer[], { version }?, callback(err)) + // write(pool_id, inode, offset, buf: Buffer | Buffer[], { version }?, callback(err)) static NAN_METHOD(Write); // sync(callback(err)) static NAN_METHOD(Sync); - // read_bitmap(pool, inode, offset, len, with_parents, callback(err, bitmap_buffer)) + // read_bitmap(pool_id, inode, offset, len, with_parents, callback(err, bitmap_buffer)) static NAN_METHOD(ReadBitmap); + // on_ready(callback(err)) + static NAN_METHOD(OnReady); + // get_min_io_size(pool_id) + static NAN_METHOD(GetMinIoSize); + // get_max_atomic_write_size(pool_id) + static NAN_METHOD(GetMaxAtomicWriteSize); // // destroy() // static NAN_METHOD(Destroy); @@ -37,6 +43,7 @@ private: static void on_io_readable(uv_poll_t* handle, int status, int revents); static void on_read_finish(void *opaque, long retval, uint64_t version); + static void on_ready_finish(void *opaque, long retval); static void on_write_finish(void *opaque, long retval); static void on_read_bitmap_finish(void *opaque, long retval, uint8_t *bitmap); diff --git a/src/client/vitastor_c.cpp b/src/client/vitastor_c.cpp index c91e9476..f6fe95b9 100644 --- a/src/client/vitastor_c.cpp +++ b/src/client/vitastor_c.cpp @@ -222,6 +222,14 @@ int vitastor_c_is_ready(vitastor_c *client) return client->cli->is_ready(); } +void vitastor_c_on_ready(vitastor_c *client, VitastorIOHandler cb, void *opaque) +{ + client->cli->on_ready([=]() + { + cb(opaque, 0); + }); +} + void vitastor_c_uring_wait_ready(vitastor_c *client) { while (!client->cli->is_ready()) diff --git a/src/client/vitastor_c.h b/src/client/vitastor_c.h index 613a7bd8..f5b1788d 100644 --- a/src/client/vitastor_c.h +++ b/src/client/vitastor_c.h @@ -51,6 +51,7 @@ vitastor_c *vitastor_c_create_epoll_json(const char **options, int options_len); void* vitastor_c_get_internal_client(vitastor_c *client); void vitastor_c_destroy(vitastor_c *client); int vitastor_c_is_ready(vitastor_c *client); +void vitastor_c_on_ready(vitastor_c *client, VitastorIOHandler cb, void *opaque); int vitastor_c_uring_register_eventfd(vitastor_c *client); void vitastor_c_uring_wait_ready(vitastor_c *client); void vitastor_c_uring_handle_events(vitastor_c *client);