Skip to contentSkip to conversation

chunkd: use port xxx82 to build

PATCH Rick Peralta 2 participants 2 messages Aug 12, 2009 – Aug 13, 2009

lore
Share & tools
lore
#0 lore raw

There is code to byte swap in the network stack. ntoh() and friends should do the job.

FYI: ntoh() and friends are usually wrappers, often many layers) for other code.

- Rick

Quoted 62 lines

From: Jeff Garzik <[email protected]>
Sent: Aug 10, 2009 1:37 PM
To: Pete Zaitcev <[email protected]>
Cc: Rick Peralta <[email protected]>, Project Hail List <[email protected]>
Subject: Re: [Patch] chunkd: use port xxx82 to build

Quoted 37 lines · Pete Zaitcev
Quoted 3 lines · Rick Peralta

I was looking from net_write() & net_read() to see where they were called and what was passed to them. struct chunksrv_req & struct chunksrv_resp_get seem to be the primary structures.

I didn't know how serious you were about it, so I went ahead and looked at the endian stuff. The immediate issue - the hang of basic-object - was addressed with the following fix:

server/object.c +1 -1
index 4eb62f7..6ea1500 100644
@@ -290,7 +290,7 @@ bool object_get(struct client *cli, bool want_body)
 
 	cli->in_len = obj->size;
 
-	resp->req.data_len = GUINT32_TO_LE(obj->size);
+	resp->req.data_len = GUINT64_TO_LE((uint64_t)obj->size);
 	memcpy(resp->req.checksum, obj->hashstr, sizeof(obj->hashstr));
 	resp->req.checksum[sizeof(obj->hashstr)] = 0;
 	resp->mtime = GUINT64_TO_LE(obj->mtime);
server/server.c +1 -1
index 2ad3db2..161dc67 100644
@@ -639,7 +639,7 @@ static bool cli_resp_xml(struct client *cli, GList *content)
 {
 	int rc;
 	bool rcb;
-	int content_len = strlist_len(content);
+	size_t content_len = strlist_len(content);
 	struct chunksrv_req *resp = NULL;
 
 	resp = malloc(sizeof(*resp));

server/server.c static bool cli_resp_xml(struct client *cli, GList *content) · line 655

Quoted 7 lines
server/server.c +1 -1
@@ -650,7 +650,7 @@ static bool cli_resp_xml(struct client *cli, GList *content)
 
 	memcpy(resp, &cli->creq, sizeof(cli->creq));
 
-	resp->data_len = GUINT64_TO_LE(content_len);
+	resp->data_len = GUINT64_TO_LE((uint64_t)content_len);
 
 	cli->state = evt_recycle;

I think type-safety should win the day. So, I am going to work on a set of 'static inline' functions that wrap GUINT* macros. We shouldn't need to add casts to achieve type promotion, in that case.

I think I will name them le32_to_cpu, cpu_to_le16, le64_to_cpu, etc. :)

Jeff

#1 lore raw
Quoted 1 line · Rick Peralta

There is code to byte swap in the network stack. ntoh() and friends should do the job.

Unfortunately that isn't the best solution for us, for a few reasons:

* There is no 64-bit variant, which we need.

* The system platform definitions of ntohl() etc. can vary between macros and function calls depending on compiler's -O settings, which complicates debugging (at least for me).

* ntohl() forces big endian. Given the current landscape of commodity hardware, I intentionally chose little endian over big endian. That will completely eliminate byte-swapping for the primary platforms' byte order.

We use the GLib byte order facilities, which provide little endian variants and are portable (along with the rest of GLib) across modern platforms. But GUINT*_{FROM,TO}_LE macros come with the minor disadvantages of all macros, namely a lack of type safety, problems with multiple evaluation, etc.

Regards,

Jeff