Coding Guidelines

All Lustre developers should follow the guidelines in this page very strictly to avoid problems during code merges later on. Please make the required changes to the default formatting rules in the editor you use to comply to the guidelines below.

Guidelines
1. There should be no tabs in any files. 1. Blocks should be indented by 8 spaces. 1. New files should contain the following along with the license boilerplate. This will cause vim and emacs to use spaces instead of tabs for indenting. If you use a different editor, it also needs to be set to use spaces for indening Lustre code.

1. All lines should wrap at 80 characters. If it's getting too hard to wrap there, you probably need to break it up into more functions. In some cases, it is acceptable to remove a few spaces between function arguments to avoid overflowing onto the next line. 1. Don't have spaces or tabs on blank lines or at the end of lines. 1. Don't use "inline" unless you're doing something so performance critical that the function call overhead will make a difference -- in other words: never. It makes debugging harder.

All of our wrapping, parenthesis, brace placement, etc. rules are basically Linux kernel rules, which are basically K&R. For those of you in need of a refresher, great detail is provided below.

Great detail
a. When you wrap, the next line should start after the parenthesis:

a. If you're wrapping put the operators at the end of the line, and if there are no parentheses indent 8 more:

a. Binary and ternary (but not unary) operators should be separated from their arguments by one space.

a. Function calls should be nestled against the parentheses, the parentheses should crowd the arguments, and one space after commas:

a. All if, for, while, etc. expressions should be separated by a space from the parenthesis, one space after the semicolons:

a. Opening braces should be on the same line as the line that introduces the block, except for function calls. Closing braces get their own line, except for "else".

a. If one part of a compound if block has braces, all should.

a. When you make a macro, protect those who might call it by using do/while and parentheses; line up your backslashes:

a. If you nest preprocessor commands, use spaces to visually delineate:

a. For very long #ifdefs include the conditional with each #endif to make it readable:

a. Comments should have the leading /* on the same line as the comment, and the trailing */ at the end of the last comment line. Intermediate lines should start with a * aligned with the first line's *:

a. Function declarations absolutely should NOT go into .c files, unless they are forward declarations for static functions that can't otherwise be moved before the caller. Instead, the declaration should go into the most "local" header available (preferrably *_internal.h for a given piece of code).

a. Structure and constant declarations should not be declared in multiple places. Put the struct into the most "local" header possible. If it is something that is passed over the wire it needs to go into lustre_idl.h, and needs to be correctly swabbed when the RPC message is unpacked.

a. The types and printf/printk formats used by Lustre code are:


 * FrontPage