From: Alex Elder <elder@inktank.com>
To: "ceph-devel@vger.kernel.org" <ceph-devel@vger.kernel.org>
Subject: [PATCH 3/4] libceph: clean up ceph_osd_new_request()
Date: Fri, 29 Mar 2013 16:32:27 -0500 [thread overview]
Message-ID: <5156086B.7070002@inktank.com> (raw)
In-Reply-To: <5156080E.9040603@inktank.com>
All callers of ceph_osd_new_request() pass either CEPH_OSD_OP_READ
or CEPH_OSD_OP_WRITE as the opcode value. The function assumes it
by filling in the extent fields in the ops array it builds. So just
assert that is the case, and don't bother calling op_has_extent()
before filling in the first osd operation in the array.
Define some local variables to gather the information to fill into
the first op, and then fill in the op array all in one place.
Signed-off-by: Alex Elder <elder@inktank.com>
---
net/ceph/osd_client.c | 50
++++++++++++++++++++++---------------------------
1 file changed, 22 insertions(+), 28 deletions(-)
diff --git a/net/ceph/osd_client.c b/net/ceph/osd_client.c
index 0eb417b..7136060 100644
--- a/net/ceph/osd_client.c
+++ b/net/ceph/osd_client.c
@@ -32,12 +32,6 @@ static void __unregister_linger_request(struct
ceph_osd_client *osdc,
static void __send_request(struct ceph_osd_client *osdc,
struct ceph_osd_request *req);
-static int op_has_extent(int op)
-{
- return (op == CEPH_OSD_OP_READ ||
- op == CEPH_OSD_OP_WRITE);
-}
-
/*
* Implement client access to distributed object storage cluster.
*
@@ -554,22 +548,15 @@ struct ceph_osd_request
*ceph_osdc_new_request(struct ceph_osd_client *osdc,
{
struct ceph_osd_req_op ops[2];
struct ceph_osd_request *req;
- unsigned int num_op = 1;
+ unsigned int num_op = do_sync ? 2 : 1;
u64 objnum = 0;
u64 objoff = 0;
u64 objlen = 0;
+ u32 object_size;
+ u64 object_base;
int r;
- memset(&ops, 0, sizeof ops);
-
- ops[0].op = opcode;
- ops[0].extent.truncate_seq = truncate_seq;
- ops[0].extent.truncate_size = truncate_size;
-
- if (do_sync) {
- ops[1].op = CEPH_OSD_OP_STARTSYNC;
- num_op++;
- }
+ BUG_ON(opcode != CEPH_OSD_OP_READ && opcode != CEPH_OSD_OP_WRITE);
req = ceph_osdc_alloc_request(osdc, snapc, num_op, use_mempool,
GFP_NOFS);
@@ -584,21 +571,28 @@ struct ceph_osd_request
*ceph_osdc_new_request(struct ceph_osd_client *osdc,
return ERR_PTR(r);
}
- if (op_has_extent(ops[0].op)) {
- u32 osize = le32_to_cpu(layout->fl_object_size);
- ops[0].extent.offset = objoff;
- ops[0].extent.length = objlen;
- if (ops[0].extent.truncate_size <= off - objoff) {
- ops[0].extent.truncate_size = 0;
- } else {
- ops[0].extent.truncate_size -= off - objoff;
- if (ops[0].extent.truncate_size > osize)
- ops[0].extent.truncate_size = osize;
- }
+ object_size = le32_to_cpu(layout->fl_object_size);
+ object_base = off - objoff;
+ if (truncate_size <= object_base) {
+ truncate_size = 0;
+ } else {
+ truncate_size -= object_base;
+ if (truncate_size > object_size)
+ truncate_size = object_size;
}
+
+ memset(&ops, 0, sizeof ops);
+ ops[0].op = opcode;
+ ops[0].extent.offset = objoff;
+ ops[0].extent.length = objlen;
+ ops[0].extent.truncate_size = truncate_size;
+ ops[0].extent.truncate_seq = truncate_seq;
if (ops[0].op == CEPH_OSD_OP_WRITE)
ops[0].payload_len = *plen;
+ if (do_sync)
+ ops[1].op = CEPH_OSD_OP_STARTSYNC;
+
req->r_file_layout = *layout; /* keep a copy */
snprintf(req->r_oid, sizeof(req->r_oid), "%llx.%08llx",
--
1.7.9.5
next prev parent reply other threads:[~2013-03-29 21:32 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-29 21:30 [PATCH 0/4] libceph: use op formatter for ceph_osdc_new_request() Alex Elder
2013-03-29 21:31 ` [PATCH 1/4] libceph: pass offset and length out of calc_layout() Alex Elder
2013-03-29 21:32 ` [PATCH 2/4] libceph: don't update op in calc_layout() Alex Elder
2013-03-29 21:32 ` Alex Elder [this message]
2013-03-29 21:32 ` [PATCH 4/4] libceph: use osd_req_op_extent_init() Alex Elder
2013-04-03 18:48 ` [PATCH 0/4] libceph: use op formatter for ceph_osdc_new_request() 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=5156086B.7070002@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.