[OpenAFS] Re: [OpenAFS-devel] exposing RPC code<->name mappings via rxgen extension, a library, and a new utility

Felix Frank Felix.Frank@Desy.de
Tue, 5 May 2009 10:12:49 +0200 (CEST)


  This message is in MIME format.  The first part should be readable text,
  while the remaining parts are likely unreadable without MIME-aware tools.

--579669762-1509803715-1241511170=:21930
Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed

Hi all,

I'm reviving this thread for the benefit of RxOSD integration.

On Thu, 15 Jan 2009, Jeffrey Hutzelman wrote:

> --On Thursday, January 15, 2009 02:00:09 PM -0500 Steven Jenkins 
> <steven.jenkins@gmail.com> wrote:
>
>> I would like to expose RPC code<->name mappings so that other programs
>> within OpenAFS can avoid hard-coding the mappings, as well as be able
>> to export them to the users (who might find them useful in debugging
>> network traces, for example, where their particular tool does not know
>> what a particular opcode corresponds to). From a user-level, it would
>> work as follows:
>> 
>> $ translate_rpc -name PR_INewEntry
>> 500

<snip>

>
> 1) Translation of opcodes to names could be done by an array lookup, but it 
> shouldn't be, because the required array will generally be quite large and 
> very sparse.  Instead, you should emit a _function_ which uses the same logic 
> as the ExecuteRequest function already emitted by rxgen, and which handles 
> large gaps in the opcode space in a reasonably efficient way.
>
> 2) Translation of names to opcode cannot be done by an array lookup, because 
> this is C, not awk or python, and strings cannot be used as array indices. 
> Again, I recommend actually emitting a function which does the required 
> translation.  This won't be like anything currently in OpenAFS, but shouldn't 
> be too hard to construct.  I recommend looking at using gperf to generate a 
> perfect hash table for each set of procedures.

I can see how a translate_rpc program could use a name -> RPC number
translation, but not the server binaries. The former should be a simple
script or program powered by a simple lookup table as suggested below.
Do we need proper functions that do that?

The only translation server or admin command binaries should need is
number -> name, as far as I can see it.

> It should be possible to get rxgen to produce these functions for any 
> interface, and preferably in a separate file from any of its other outputs, 
> so that they may be collected together into a library that has no other 
> dependencies.  I would also very much like to see a mode in which rxgen emits 
> a simple table of opcode numbers and procedure names, one per line. This 
> would be useful in constructing a standalone lookup tool that reads one table 
> per RPC interface (similar to something I've already done for com_err 
> tables), and may also be of use to the registrars in constructing some of the 
> procedure number tables we currently don't have.

Simple table can be generated using the attached patch. It's an awful lot 
of copy-paste and I'm not sure if it's valid. I'm also not yet sure
how to generate lookup functions. I have two approaches in mind:

1. make uses the lookup tables to feed gperf, and a custom script adds actual
    translation functions
2. rxgen receives another mode that generates functions which rely on gperf
    generated hash tables

Is that about what you had in mind?
Further suggestions/criticism?

Cheers
  - Felix
--579669762-1509803715-1241511170=:21930
Content-Type: TEXT/PLAIN; charset=US-ASCII; name=rpc-lookup-tables.patch
Content-Transfer-Encoding: BASE64
Content-Description: 
Content-Disposition: attachment; filename=rpc-lookup-tables.patch

SW5kZXg6IHNyYy9yeGdlbi9ycGNfc2Nhbi5jDQo9PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09DQotLS0gc3JjL3J4Z2VuL3JwY19zY2FuLmMJKHJldmlzaW9uIDY0
NikNCisrKyBzcmMvcnhnZW4vcnBjX3NjYW4uYwkocmV2aXNpb24gNjQ4KQ0K
QEAgLTU3LDYgKzU3LDcgQEANCiBpbnQgcHVzaGVkID0gMDsJCQkvKiBpcyBh
IHRva2VuIHB1c2hlZCAqLw0KIHRva2VuIGxhc3R0b2s7CQkJLyogbGFzdCB0
b2tlbiwgaWYgcHVzaGVkICovDQogaW50IHNjYW5fcHJpbnQgPSAxOw0KK2lu
dCBwdXRfZGlyZWN0aXZlcyA9IDE7CQkvKiBzZXQgdG8gMCB0byBzdXBwcmVz
cyBwcmludGRpcmVjdGl2ZSgpcyAqLw0KIA0KIC8qIHN0YXRpYyBwcm90b3R5
cGVzICovDQogc3RhdGljIHZvaWQgZmluZHN0cmNvbnN0KGNoYXIgKipzdHIs
IGNoYXIgKip2YWwpOw0KQEAgLTQ3MCw2ICs0NzEsOCBAQA0KIHZvaWQNCiBw
cmludGRpcmVjdGl2ZShjaGFyICpsaW5lKQ0KIHsNCisgICAgaWYgKCAhcHV0
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