From: Sage Weil Date: Thu, 8 Oct 2015 19:32:10 +0000 (-0400) Subject: librados: add set_alloc_hint2 with flags X-Git-Tag: v11.0.0~466^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=018c8bcc2542f76dc8c09fc816f0b21f88619688;p=ceph.git librados: add set_alloc_hint2 with flags Flags indicate expected future access pattern so the OSD can behave accordingly. Signed-off-by: Sage Weil --- diff --git a/src/include/rados/librados.h b/src/include/rados/librados.h index 502c97522e6e..b3d4818374ea 100644 --- a/src/include/rados/librados.h +++ b/src/include/rados/librados.h @@ -127,6 +127,24 @@ enum { }; /** @} */ +/** + * @name Alloc hint flags + * Flags for rados_write_op_alloc_hint2() and rados_set_alloc_hint2() + * indicating future IO patterns. + * @{ + */ +enum { + LIBRADOS_ALLOC_HINT_SEQUENTIAL_WRITE = 1, + LIBRADOS_ALLOC_HINT_RANDOM_WRITE = 2, + LIBRADOS_ALLOC_HINT_FLAG_SEQUENTIAL_READ = 4, + LIBRADOS_ALLOC_HINT_FLAG_RANDOM_READ = 8, + LIBRADOS_ALLOC_HINT_FLAG_APPEND_ONLY = 16, + LIBRADOS_ALLOC_HINT_FLAG_IMMUTABLE = 32, + LIBRADOS_ALLOC_HINT_FLAG_SHORTLIVED = 64, + LIBRADOS_ALLOC_HINT_FLAG_LONGLIVED = 128, +}; +/** @} */ + /* * snap id contants */ @@ -2399,6 +2417,25 @@ CEPH_RADOS_API int rados_set_alloc_hint(rados_ioctx_t io, const char *o, uint64_t expected_object_size, uint64_t expected_write_size); +/** + * Set allocation hint for an object + * + * This is an advisory operation, it will always succeed (as if it was + * submitted with a LIBRADOS_OP_FLAG_FAILOK flag set) and is not + * guaranteed to do anything on the backend. + * + * @param io the pool the object is in + * @param o the name of the object + * @param expected_object_size expected size of the object, in bytes + * @param expected_write_size expected size of writes to the object, in bytes + * @param flags hints about future IO patterns + * @returns 0 on success, negative error code on failure + */ +CEPH_RADOS_API int rados_set_alloc_hint2(rados_ioctx_t io, const char *o, + uint64_t expected_object_size, + uint64_t expected_write_size, + uint32_t flags); + /** @} Hints */ /** @@ -2660,6 +2697,19 @@ CEPH_RADOS_API void rados_write_op_set_alloc_hint(rados_write_op_t write_op, uint64_t expected_object_size, uint64_t expected_write_size); +/** + * Set allocation hint for an object + * + * @param write_op operation to add this action to + * @param expected_object_size expected size of the object, in bytes + * @param expected_write_size expected size of writes to the object, in bytes + * @param flags hints about future IO patterns + */ +CEPH_RADOS_API void rados_write_op_set_alloc_hint2(rados_write_op_t write_op, + uint64_t expected_object_size, + uint64_t expected_write_size, + uint32_t flags); + /** * Perform a write operation synchronously * @param write_op operation to perform diff --git a/src/include/rados/librados.hpp b/src/include/rados/librados.hpp index 5c6abdb63f0e..599f34f6b427 100644 --- a/src/include/rados/librados.hpp +++ b/src/include/rados/librados.hpp @@ -280,6 +280,20 @@ namespace librados OPERATION_FULL_TRY = LIBRADOS_OPERATION_FULL_TRY, }; + /* + * Alloc hint flags for the alloc_hint operation. + */ + enum AllocHintFlags { + ALLOC_HINT_SEQUENTIAL_WRITE = 1, + ALLOC_HINT_RANDOM_WRITE = 2, + ALLOC_HINT_FLAG_SEQUENTIAL_READ = 4, + ALLOC_HINT_FLAG_RANDOM_READ = 8, + ALLOC_HINT_FLAG_APPEND_ONLY = 16, + ALLOC_HINT_FLAG_IMMUTABLE = 32, + ALLOC_HINT_FLAG_SHORTLIVED = 64, + ALLOC_HINT_FLAG_LONGLIVED = 128, + }; + /* * ObjectOperation : compound object operation * Batch multiple object operations into a single request, to be applied @@ -448,9 +462,13 @@ namespace librados * * @param expected_object_size expected size of the object, in bytes * @param expected_write_size expected size of writes to the object, in bytes + * @param flags flags () */ void set_alloc_hint(uint64_t expected_object_size, uint64_t expected_write_size); + void set_alloc_hint2(uint64_t expected_object_size, + uint64_t expected_write_size, + uint32_t flags); /** * Pin/unpin an object in cache tier @@ -1082,6 +1100,10 @@ namespace librados int set_alloc_hint(const std::string& o, uint64_t expected_object_size, uint64_t expected_write_size); + int set_alloc_hint2(const std::string& o, + uint64_t expected_object_size, + uint64_t expected_write_size, + uint32_t flags); // assert version for next sync operations void set_assert_version(uint64_t ver); diff --git a/src/librados/IoCtxImpl.cc b/src/librados/IoCtxImpl.cc index ccbf897aac9e..358d56153532 100644 --- a/src/librados/IoCtxImpl.cc +++ b/src/librados/IoCtxImpl.cc @@ -1622,11 +1622,12 @@ int librados::IoCtxImpl::aio_notify(const object_t& oid, AioCompletionImpl *c, int librados::IoCtxImpl::set_alloc_hint(const object_t& oid, uint64_t expected_object_size, - uint64_t expected_write_size) + uint64_t expected_write_size, + uint32_t flags) { ::ObjectOperation wr; prepare_assert_ops(&wr); - wr.set_alloc_hint(expected_object_size, expected_write_size); + wr.set_alloc_hint(expected_object_size, expected_write_size, flags); return operate(oid, &wr, NULL); } diff --git a/src/librados/IoCtxImpl.h b/src/librados/IoCtxImpl.h index e76ae7c5a3a4..02c906eb6610 100644 --- a/src/librados/IoCtxImpl.h +++ b/src/librados/IoCtxImpl.h @@ -253,7 +253,8 @@ struct librados::IoCtxImpl { int set_alloc_hint(const object_t& oid, uint64_t expected_object_size, - uint64_t expected_write_size); + uint64_t expected_write_size, + uint32_t flags); version_t last_version(); void set_assert_version(uint64_t ver); diff --git a/src/librados/librados.cc b/src/librados/librados.cc index aa18fd0e2c1d..904349ed03f5 100644 --- a/src/librados/librados.cc +++ b/src/librados/librados.cc @@ -553,7 +553,15 @@ void librados::ObjectWriteOperation::set_alloc_hint( uint64_t expected_write_size) { ::ObjectOperation *o = &impl->o; - o->set_alloc_hint(expected_object_size, expected_write_size); + o->set_alloc_hint(expected_object_size, expected_write_size, 0); +} +void librados::ObjectWriteOperation::set_alloc_hint2( + uint64_t expected_object_size, + uint64_t expected_write_size, + uint32_t flags) +{ + ::ObjectOperation *o = &impl->o; + o->set_alloc_hint(expected_object_size, expected_write_size, flags); } void librados::ObjectWriteOperation::cache_pin() @@ -1961,7 +1969,17 @@ int librados::IoCtx::set_alloc_hint(const std::string& o, { object_t oid(o); return io_ctx_impl->set_alloc_hint(oid, expected_object_size, - expected_write_size); + expected_write_size, 0); +} + +int librados::IoCtx::set_alloc_hint2(const std::string& o, + uint64_t expected_object_size, + uint64_t expected_write_size, + uint32_t flags) +{ + object_t oid(o); + return io_ctx_impl->set_alloc_hint(oid, expected_object_size, + expected_write_size, flags); } void librados::IoCtx::set_assert_version(uint64_t ver) @@ -4676,11 +4694,26 @@ extern "C" int rados_set_alloc_hint(rados_ioctx_t io, const char *o, tracepoint(librados, rados_set_alloc_hint_enter, io, o, expected_object_size, expected_write_size); librados::IoCtxImpl *ctx = (librados::IoCtxImpl *)io; object_t oid(o); - int retval = ctx->set_alloc_hint(oid, expected_object_size, expected_write_size); + int retval = ctx->set_alloc_hint(oid, expected_object_size, + expected_write_size, 0); tracepoint(librados, rados_set_alloc_hint_exit, retval); return retval; } +extern "C" int rados_set_alloc_hint2(rados_ioctx_t io, const char *o, + uint64_t expected_object_size, + uint64_t expected_write_size, + uint32_t flags) +{ + tracepoint(librados, rados_set_alloc_hint2_enter, io, o, expected_object_size, expected_write_size, flags); + librados::IoCtxImpl *ctx = (librados::IoCtxImpl *)io; + object_t oid(o); + int retval = ctx->set_alloc_hint(oid, expected_object_size, + expected_write_size, flags); + tracepoint(librados, rados_set_alloc_hint2_exit, retval); + return retval; +} + extern "C" int rados_lock_exclusive(rados_ioctx_t io, const char * o, const char * name, const char * cookie, const char * desc, struct timeval * duration, @@ -5039,10 +5072,22 @@ extern "C" void rados_write_op_set_alloc_hint(rados_write_op_t write_op, { tracepoint(librados, rados_write_op_set_alloc_hint_enter, write_op, expected_object_size, expected_write_size); ((::ObjectOperation *)write_op)->set_alloc_hint(expected_object_size, - expected_write_size); + expected_write_size, 0); tracepoint(librados, rados_write_op_set_alloc_hint_exit); } +extern "C" void rados_write_op_set_alloc_hint2(rados_write_op_t write_op, + uint64_t expected_object_size, + uint64_t expected_write_size, + uint32_t flags) +{ + tracepoint(librados, rados_write_op_set_alloc_hint2_enter, write_op, expected_object_size, expected_write_size, flags); + ((::ObjectOperation *)write_op)->set_alloc_hint(expected_object_size, + expected_write_size, + flags); + tracepoint(librados, rados_write_op_set_alloc_hint2_exit); +} + extern "C" int rados_write_op_operate(rados_write_op_t write_op, rados_ioctx_t io, const char *oid, diff --git a/src/osdc/Objecter.h b/src/osdc/Objecter.h index 163e7db384cb..612b8fdf186f 100644 --- a/src/osdc/Objecter.h +++ b/src/osdc/Objecter.h @@ -215,10 +215,12 @@ struct ObjectOperation { ::encode(cookie, osd_op.indata); } void add_alloc_hint(int op, uint64_t expected_object_size, - uint64_t expected_write_size) { + uint64_t expected_write_size, + uint32_t flags) { OSDOp& osd_op = add_op(op); osd_op.op.alloc_hint.expected_object_size = expected_object_size; osd_op.op.alloc_hint.expected_write_size = expected_write_size; + osd_op.op.alloc_hint.flags = flags; } // ------ @@ -1089,9 +1091,10 @@ struct ObjectOperation { } void set_alloc_hint(uint64_t expected_object_size, - uint64_t expected_write_size ) { + uint64_t expected_write_size, + uint32_t flags) { add_alloc_hint(CEPH_OSD_OP_SETALLOCHINT, expected_object_size, - expected_write_size); + expected_write_size, flags); // CEPH_OSD_OP_SETALLOCHINT op is advisory and therefore deemed // not worth a feature bit. Set FAILOK per-op flag to make diff --git a/src/tracing/librados.tp b/src/tracing/librados.tp index 8afe1e29ebf4..c4aaf4cedc65 100644 --- a/src/tracing/librados.tp +++ b/src/tracing/librados.tp @@ -2583,6 +2583,30 @@ TRACEPOINT_EVENT(librados, rados_set_alloc_hint_exit, ) ) +TRACEPOINT_EVENT(librados, rados_set_alloc_hint2_enter, + TP_ARGS( + rados_ioctx_t, ioctx, + const char*, oid, + uint64_t, expected_object_size, + uint64_t, expected_write_size, + uint32_t, flags), + TP_FIELDS( + ctf_integer_hex(rados_ioctx_t, ioctx, ioctx) + ctf_string(oid, oid) + ctf_integer(uint64_t, expected_object_size, expected_object_size) + ctf_integer(uint64_t, expected_write_size, expected_write_size) + ctf_integer(uint32_t, flags, flags) + ) +) + +TRACEPOINT_EVENT(librados, rados_set_alloc_hint2_exit, + TP_ARGS( + int, retval), + TP_FIELDS( + ctf_integer(int, retval, retval) + ) +) + TRACEPOINT_EVENT(librados, rados_lock_exclusive_enter, TP_ARGS( rados_ioctx_t, ioctx, @@ -3114,6 +3138,25 @@ TRACEPOINT_EVENT(librados, rados_write_op_set_alloc_hint_exit, TP_FIELDS() ) +TRACEPOINT_EVENT(librados, rados_write_op_set_alloc_hint2_enter, + TP_ARGS( + rados_write_op_t, op, + uint64_t, expected_object_size, + uint64_t, expected_write_size, + uint32_t, flags), + TP_FIELDS( + ctf_integer_hex(rados_write_op_t, op, op) + ctf_integer(uint64_t, expected_object_size, expected_object_size) + ctf_integer(uint64_t, expected_write_size, expected_write_size) + ctf_integer(uint32_t, flags, flags) + ) +) + +TRACEPOINT_EVENT(librados, rados_write_op_set_alloc_hint2_exit, + TP_ARGS(), + TP_FIELDS() +) + TRACEPOINT_EVENT(librados, rados_write_op_operate_enter, TP_ARGS( rados_write_op_t, op,