From: Alex Elder <elder@inktank.com>
To: "ceph-devel@vger.kernel.org" <ceph-devel@vger.kernel.org>
Subject: [PATCH REPOST 2/2] rbd: only get snap context for write requests
Date: Thu, 03 Jan 2013 16:54:17 -0600 [thread overview]
Message-ID: <50E60C19.9060305@inktank.com> (raw)
In-Reply-To: <50E60BD0.30408@inktank.com>
Right now we get the snapshot context for an rbd image (under
protection of the header semaphore) for every request processed.
There's no need to get the snap context if we're doing a read,
so avoid doing so in that case.
Note that we no longer need to hold the header semaphore to
check the rbd_dev's existence flag.
Signed-off-by: Alex Elder <elder@inktank.com>
---
drivers/block/rbd.c | 36 ++++++++++++++++++++----------------
1 file changed, 20 insertions(+), 16 deletions(-)
diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index a3b0d43..fd6a708 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -1331,7 +1331,7 @@ static int rbd_do_op(struct request *rq,
} else {
opcode = CEPH_OSD_OP_READ;
flags = CEPH_OSD_FLAG_READ;
- snapc = NULL;
+ rbd_assert(!snapc);
snapid = rbd_dev->spec->snap_id;
payload_len = 0;
}
@@ -1661,22 +1661,25 @@ static void rbd_rq_fn(struct request_queue *q)
}
spin_unlock_irq(q->queue_lock);
- /* Stop writes to a read-only device */
-
- result = -EROFS;
- if (read_only && rq_data_dir(rq) == WRITE)
- goto out_end_request;
-
- /* Grab a reference to the snapshot context */
-
- down_read(&rbd_dev->header_rwsem);
- if (atomic_read(&rbd_dev->exists)) {
+ /* Write requests need a reference to the snapshot context */
+
+ if (rq_data_dir(rq) == WRITE) {
+ result = -EROFS;
+ if (read_only) /* Can't write to a read-only device */
+ goto out_end_request;
+
+ /*
+ * Note that each osd request will take its
+ * own reference to the snapshot context
+ * supplied. The reference we take here
+ * just guarantees the one we provide stays
+ * valid.
+ */
+ down_read(&rbd_dev->header_rwsem);
snapc = ceph_get_snap_context(rbd_dev->header.snapc);
+ up_read(&rbd_dev->header_rwsem);
rbd_assert(snapc != NULL);
- }
- up_read(&rbd_dev->header_rwsem);
-
- if (!snapc) {
+ } else if (!atomic_read(&rbd_dev->exists)) {
rbd_assert(rbd_dev->spec->snap_id != CEPH_NOSNAP);
dout("request for non-existent snapshot");
result = -ENXIO;
@@ -1687,7 +1690,8 @@ static void rbd_rq_fn(struct request_queue *q)
blk_rq_pos(rq) * SECTOR_SIZE,
blk_rq_bytes(rq), rq->bio);
out_end_request:
- ceph_put_snap_context(snapc);
+ if (snapc)
+ ceph_put_snap_context(snapc);
spin_lock_irq(q->queue_lock);
if (result < 0)
__blk_end_request_all(rq, result);
--
1.7.9.5
next prev parent reply other threads:[~2013-01-03 22:54 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-03 22:53 [PATCH REPOST 0/2] rbd: only get snap context for write requests Alex Elder
2013-01-03 22:53 ` [PATCH REPOST 1/2] rbd: make exists flag atomic Alex Elder
2013-01-16 0:29 ` Josh Durgin
2013-01-03 22:54 ` Alex Elder [this message]
2013-01-16 1:23 ` [PATCH REPOST 2/2] rbd: only get snap context for write requests Josh Durgin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=50E60C19.9060305@inktank.com \
--to=elder@inktank.com \
--cc=ceph-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.