Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

librbd: sync flush should re-use existing async flush logic #18403

Merged
merged 2 commits into from
Oct 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 5 additions & 4 deletions qa/workunits/rbd/journal.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,17 @@ test_rbd_journal()
rbd snap create ${image1}@test
restore_commit_position ${journal1}
# check that commit position is properly updated: the journal should contain
# 12 entries (10 AioWrite + 1 SnapCreate + 1 OpFinish) and commit
# position set to tid=11
# 14 entries (2 AioFlush + 10 AioWrite + 1 SnapCreate + 1 OpFinish) and
# commit position set to tid=14
rbd journal inspect --image ${image1} --verbose | awk '
/AioFlush/ {a++} # match: "event_type": "AioFlush",
/AioWrite/ {w++} # match: "event_type": "AioWrite",
/SnapCreate/ {s++} # match: "event_type": "SnapCreate",
/OpFinish/ {f++} # match: "event_type": "OpFinish",
/entries inspected/ {t=$1; e=$4} # match: 12 entries inspected, 0 errors
/entries inspected/ {t=$1; e=$4} # match: 14 entries inspected, 0 errors
{print} # for diagnostic
END {
if (w != 10 || s != 1 || f != 1 || t != 12 || e != 0) exit(1)
if (a != 2 || w != 10 || s != 1 || f != 1 || t != 14 || e != 0) exit(1)
}
'

Expand Down
3 changes: 1 addition & 2 deletions src/librbd/ImageCtx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,7 @@ struct C_InvalidateCache : public Context {
plb.add_u64_counter(l_librbd_discard_bytes, "discard_bytes", "Discarded data");
plb.add_time_avg(l_librbd_discard_latency, "discard_latency", "Discard latency");
plb.add_u64_counter(l_librbd_flush, "flush", "Flushes");
plb.add_u64_counter(l_librbd_aio_flush, "aio_flush", "Async flushes");
plb.add_time_avg(l_librbd_aio_flush_latency, "aio_flush_latency", "Latency of async flushes");
plb.add_time_avg(l_librbd_flush_latency, "flush_latency", "Latency of flushes");
plb.add_u64_counter(l_librbd_ws, "ws", "WriteSames");
plb.add_u64_counter(l_librbd_ws_bytes, "ws_bytes", "WriteSame data");
plb.add_time_avg(l_librbd_ws_latency, "ws_latency", "WriteSame latency");
Expand Down
3 changes: 2 additions & 1 deletion src/librbd/LibrbdAdminSocketHook.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "librbd/ImageCtx.h"
#include "librbd/LibrbdAdminSocketHook.h"
#include "librbd/internal.h"
#include "librbd/io/ImageRequestWQ.h"

#define dout_subsys ceph_subsys_rbd
#undef dout_prefix
Expand All @@ -24,7 +25,7 @@ class FlushCacheCommand : public LibrbdAdminSocketCommand {
explicit FlushCacheCommand(ImageCtx *ictx) : ictx(ictx) {}

bool call(stringstream *ss) override {
int r = flush(ictx);
int r = ictx->io_work_queue->flush();
if (r < 0) {
*ss << "flush: " << cpp_strerror(r);
return false;
Expand Down
22 changes: 0 additions & 22 deletions src/librbd/internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2221,28 +2221,6 @@ int validate_pool(IoCtx &io_ctx, CephContext *cct) {
return 0;
}

int flush(ImageCtx *ictx)
{
CephContext *cct = ictx->cct;
ldout(cct, 20) << "flush " << ictx << dendl;

int r = ictx->state->refresh_if_required();
if (r < 0) {
return r;
}

ictx->user_flushed();
C_SaferCond ctx;
{
RWLock::RLocker owner_locker(ictx->owner_lock);
ictx->flush(&ctx);
}
r = ctx.wait();

ictx->perfcounter->inc(l_librbd_flush);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dillaman Are you going to leave "flush" counter unused?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, in "qa/workunits/rbd/test_admin_socket.sh" we have a test that checks "flush" perfcounter is updated after "flush" admin socket command.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah -- I thought it was already covered here [1] but it's for AIO flush. I'll combine them in the next push.

[1]

image_ctx.perfcounter->inc(l_librbd_aio_flush);

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... consolidated

return r;
}

int invalidate_cache(ImageCtx *ictx)
{
CephContext *cct = ictx->cct;
Expand Down
5 changes: 1 addition & 4 deletions src/librbd/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ enum {
l_librbd_discard_bytes,
l_librbd_discard_latency,
l_librbd_flush,

l_librbd_aio_flush,
l_librbd_aio_flush_latency,
l_librbd_flush_latency,
l_librbd_ws,
l_librbd_ws_bytes,
l_librbd_ws_latency,
Expand Down Expand Up @@ -205,7 +203,6 @@ namespace librbd {
void readahead(ImageCtx *ictx,
const vector<pair<uint64_t,uint64_t> >& image_extents);

int flush(ImageCtx *ictx);
int invalidate_cache(ImageCtx *ictx);
int poll_io_events(ImageCtx *ictx, io::AioCompletion **comps, int numcomp);
int metadata_list(ImageCtx *ictx, const string &last, uint64_t max, map<string, bufferlist> *pairs);
Expand Down
2 changes: 1 addition & 1 deletion src/librbd/io/AioCompletion.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void AioCompletion::complete() {
case AIO_TYPE_DISCARD:
ictx->perfcounter->tinc(l_librbd_discard_latency, elapsed); break;
case AIO_TYPE_FLUSH:
ictx->perfcounter->tinc(l_librbd_aio_flush_latency, elapsed); break;
ictx->perfcounter->tinc(l_librbd_flush_latency, elapsed); break;
case AIO_TYPE_WRITESAME:
ictx->perfcounter->tinc(l_librbd_ws_latency, elapsed); break;
case AIO_TYPE_COMPARE_AND_WRITE:
Expand Down
2 changes: 1 addition & 1 deletion src/librbd/io/ImageRequest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ void ImageFlushRequest<I>::send_request() {
aio_comp->put();
}

image_ctx.perfcounter->inc(l_librbd_aio_flush);
image_ctx.perfcounter->inc(l_librbd_flush);
}

template <typename I>
Expand Down
17 changes: 17 additions & 0 deletions src/librbd/io/ImageRequestWQ.cc
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,23 @@ ssize_t ImageRequestWQ<I>::compare_and_write(uint64_t off, uint64_t len,
return len;
}

template <typename I>
int ImageRequestWQ<I>::flush() {
CephContext *cct = m_image_ctx.cct;
ldout(cct, 20) << "ictx=" << &m_image_ctx << dendl;

C_SaferCond cond;
AioCompletion *c = AioCompletion::create(&cond);
aio_flush(c, false);

int r = cond.wait();
if (r < 0) {
return r;
}

return 0;
}

template <typename I>
void ImageRequestWQ<I>::aio_read(AioCompletion *c, uint64_t off, uint64_t len,
ReadResult &&read_result, int op_flags,
Expand Down
1 change: 1 addition & 0 deletions src/librbd/io/ImageRequestWQ.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class ImageRequestWQ
ssize_t compare_and_write(uint64_t off, uint64_t len,
bufferlist &&cmp_bl, bufferlist &&bl,
uint64_t *mismatch_off, int op_flags);
int flush();

void aio_read(AioCompletion *c, uint64_t off, uint64_t len,
ReadResult &&read_result, int op_flags, bool native_async=true);
Expand Down
4 changes: 2 additions & 2 deletions src/librbd/librbd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1729,7 +1729,7 @@ namespace librbd {
{
ImageCtx *ictx = (ImageCtx *)ctx;
tracepoint(librbd, flush_enter, ictx, ictx->name.c_str(), ictx->snap_name.c_str(), ictx->read_only);
int r = librbd::flush(ictx);
int r = ictx->io_work_queue->flush();
tracepoint(librbd, flush_exit, r);
return r;
}
Expand Down Expand Up @@ -3771,7 +3771,7 @@ extern "C" int rbd_flush(rbd_image_t image)
{
librbd::ImageCtx *ictx = (librbd::ImageCtx *)image;
tracepoint(librbd, flush_enter, ictx, ictx->name.c_str(), ictx->snap_name.c_str(), ictx->read_only);
int r = librbd::flush(ictx);
int r = ictx->io_work_queue->flush();
tracepoint(librbd, flush_exit, r);
return r;
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/librbd/test_internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,7 @@ TEST_F(TestInternal, WriteFullCopyup) {
bl.append(std::string(1 << ictx->order, '1'));
ASSERT_EQ((ssize_t)bl.length(),
ictx->io_work_queue->write(0, bl.length(), bufferlist{bl}, 0));
ASSERT_EQ(0, librbd::flush(ictx));
ASSERT_EQ(0, ictx->io_work_queue->flush());

ASSERT_EQ(0, create_snapshot("snap1", true));

Expand Down
17 changes: 13 additions & 4 deletions src/tools/rbd/action/Bench.cc
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,12 @@ int do_bench(librbd::Image& image, io_type_t io_type,
return -EINVAL;
}

int r = image.flush();
if (r < 0 && (r != -EROFS || io_type != IO_TYPE_READ)) {
std::cerr << "rbd: failed to flush: " << cpp_strerror(r) << std::endl;
return r;
}

rbd_bencher b(&image, io_type, io_size);

std::cout << "bench "
Expand Down Expand Up @@ -316,10 +322,13 @@ int do_bench(librbd::Image& image, io_type_t io_type,
}
}
b.wait_for(0);
int r = image.flush();
if (r < 0) {
std::cerr << "Error flushing data at the end: " << cpp_strerror(r)
<< std::endl;

if (io_type != IO_TYPE_READ) {
r = image.flush();
if (r < 0) {
std::cerr << "rbd: failed to flush at the end: " << cpp_strerror(r)
<< std::endl;
}
}

utime_t now = ceph_clock_now();
Expand Down