Skip to contentSkip to conversation

chunkd: use port xxx82 to build

PATCH Rick Peralta 3 participants 6 messages Aug 7, 2009 – Aug 12, 2009

lore
Share & tools
lore
#0 lore raw

Hi Jeff,

Here are the notes on the endian notes. On first blush it looks like the basic problems are related to I/O and structure alignment. Correcting the structure (in the compiler) might be enough (if is supports endian pragmas or some such. The traditional way is to hard code endian conversions of the data before it goes out over the network and converting back on return. There are macros in the networking code that do the core byte swaping function. 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. Where to optimally put the changes is less clear.

I cobbled on a VM to get the PPC vm working. It seemed to boot, but needed more configuration than I had time to dope out. I was cool to see a mini-laptop (using the atom processor) run windows (yetch), support a VM running Fedora, support a VM running PPC code! I'm thinking a DVD could still run in the background, on an external monitor...

- Rick

Quoted 29 lines

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

Quoted 10 lines · Pete Zaitcev
Quoted 5 lines · Jeff Garzik

Speaking of chunkd...

I don't think I will have time this week to fix chunkd's failure on big endian machines. If you (or anyone else listening...) have an opportunity to look into that, that would be most helpful.

This looks like an ideal opportunity for Rick to read the code with a specific goal in mind, if he doesn't mind me saying so.

CC'd :)

Quoted 1 line

Do we have a bug number for it?

https://bugzilla.redhat.com/show_bug.cgi?id=514651

Jeff

#1 lore raw
Quoted 3 lines · Rick Peralta

Hi Jeff,

Here are the notes on the endian notes. On first blush it looks like the basic problems are related to I/O and structure alignment. Correcting the structure (in the compiler) might be enough (if is supports endian pragmas or some such. The traditional way is to hard code endian conversions of the data before it goes out over the network and converting back on return. There are macros in the networking code that do the core byte swaping function. 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. Where to optimally put the changes is less clear.

In struct chunksrv_req, only one member has the possibility of endian problems: data_len. And it appears to me that this is already properly converted:

Quoted 10 lines

[jgarzik@bd chunkd]$ grep -w data_len */*.[ch]
include/chunk_msg.h: uint64_t data_len; /* len of addn'l data */
lib/chunkdc.c: *plen = GUINT64_FROM_LE(resp.req.data_len);
lib/chunkdc.c: req.data_len = GUINT64_TO_LE(content_len);
lib/chunkdc.c: req.data_len = GUINT64_TO_LE(cont_len);
lib/chunkdc.c: content_len = GUINT64_FROM_LE(resp.req.data_len);
server/object.c: uint64_t content_len = GUINT64_FROM_LE(cli->creq.data_len);
server/object.c: resp->req.data_len = GUINT32_TO_LE(obj->size);
server/server.c: resp->data_len = GUINT64_TO_LE(content_len);
server/server.c: (long long) GUINT64_FROM_LE(req->data_len));

In struct chunksrv_resp_get, the only possibility of endian problem with is the 'mtime' struct member, which is only referenced once in server/object.c (the other uses are native-endian internal variables):

Quoted 9 lines

[jgarzik@bd chunkd]$ grep -w mtime */*.[ch]
include/chunk_msg.h: uint64_t mtime;
lib/chunkdc.c: if (!net_read(stc, &resp.mtime, sizeof(resp) - sizeof(resp.req)))
server/be-fs.c: obj->bo.mtime = st.st_mtime;
server/be-fs.c: ve->mtime = st.st_mtime;
server/chunkd.h: time_t mtime;
server/chunkd.h: time_t mtime; /* obj last-mod time */
server/object.c: resp->mtime = GUINT64_TO_LE(obj->mtime);
server/server.c: time2str(timestr, ve->mtime),

What are the "basic problems of I/O and structure alignment"?

Quoted 1 line

I cobbled on a VM to get the PPC vm working. It seemed to boot, but needed more configuration than I had time to dope out. I was cool to see a mini-laptop (using the atom processor) run windows (yetch), support a VM running Fedora, support a VM running PPC code! I'm thinking a DVD could still run in the background, on an external monitor...

Great!

Jeff

#2 lore raw
In reply to Rick Peralta
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 +2 -2
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));
@@ -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;
 

We have two problems above:

#1 the result of byteswap must not be allowed to be type-promoted,
sign-extended, or otherwise changed by the language. Only bit-to-bit assignment will do. Therefore, we must only use 64-bit conversions when assigning to req->data_len.

#2 for some reason swapping of a 32-bit value does not work either,
I suspect clipping when shifting. So I had to fix that too.

With the above, basic-object passes, test advance further, and then large-object fails like so:

test failed on line 134

        rcb = stc_get_start(stc, key, &rfd, &len);
        OK(len == (N_BUFS * BUFSZ));   <------- fails. how much is len?

Curiously, it fails on 32-bit PPC only and works on ppc64.

With this, I'm going to quit stepping on your toes and go work on CLD interface for Chunkd, then data replication in tabled. Sorry for the interference.

Good luck,
-- Pete

#3 lore raw
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

#4 lore raw
Quoted 3 lines · Jeff Garzik

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.

Sounds like a good idea, because we have better things to do than carefuly type-match everything and then never, ever, change any data sizes. But perhaps a fierce urgency is not in it.

-- Pete

#5 lore raw
In reply to Pete Zaitcev
Quoted 6 lines · Pete Zaitcev

test failed on line 134

        rcb = stc_get_start(stc, key, &rfd, &len);
        OK(len == (N_BUFS * BUFSZ));   <------- fails. how much is len?

Curiously, it fails on 32-bit PPC only and works on ppc64.

This is solved upstream, now, too: 'len' was a size_t, while stc_get_start wanted a uint64_t.

Jeff