* [PATCH 0/5] xl cleanup and docs
@ 2017-03-01 10:24 Wei Liu
2017-03-01 10:24 ` [PATCH 1/5] CONTRIBUTING: list xl in inbound license section Wei Liu
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: Wei Liu @ 2017-03-01 10:24 UTC (permalink / raw)
To: Xen-devel; +Cc: Wei Liu, Ian Jackson
Wei Liu (5):
CONTRIBUTING: list xl in inbound license section
xl: add CODING_STYLE
xl: remove declaration of ctx in c files
xl: lift common_domname declaration to xl.h
xl: lift logfile declaration to xl.h
CONTRIBUTING | 1 +
tools/xl/CODING_STYLE | 203 ++++++++++++++++++++++++++++++++++++++++++++++++
tools/xl/xl.h | 2 +
tools/xl/xl_flask.c | 2 -
tools/xl/xl_migrate.c | 2 -
tools/xl/xl_misc.c | 2 -
tools/xl/xl_utils.c | 3 -
tools/xl/xl_vmcontrol.c | 4 -
8 files changed, 206 insertions(+), 13 deletions(-)
create mode 100644 tools/xl/CODING_STYLE
--
2.11.0
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/5] CONTRIBUTING: list xl in inbound license section
2017-03-01 10:24 [PATCH 0/5] xl cleanup and docs Wei Liu
@ 2017-03-01 10:24 ` Wei Liu
2017-03-01 10:24 ` [PATCH 2/5] xl: add CODING_STYLE Wei Liu
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Wei Liu @ 2017-03-01 10:24 UTC (permalink / raw)
To: Xen-devel; +Cc: Wei Liu, Ian Jackson
Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
CONTRIBUTING | 1 +
1 file changed, 1 insertion(+)
diff --git a/CONTRIBUTING b/CONTRIBUTING
index 4456170af6..cfee8f1567 100644
--- a/CONTRIBUTING
+++ b/CONTRIBUTING
@@ -16,6 +16,7 @@ Most notably:
- tools/blktap2 : BSD-Modified
- tools/libxc : LGPL v2.1
- tools/libxl : LGPL v2.1
+ - tools/xl : LGPL v2.1
- xen/include/public : MIT license
When creating new components and directories that contain a
--
2.11.0
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/5] xl: add CODING_STYLE
2017-03-01 10:24 [PATCH 0/5] xl cleanup and docs Wei Liu
2017-03-01 10:24 ` [PATCH 1/5] CONTRIBUTING: list xl in inbound license section Wei Liu
@ 2017-03-01 10:24 ` Wei Liu
2017-03-01 10:24 ` [PATCH 3/5] xl: remove declaration of ctx in c files Wei Liu
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Wei Liu @ 2017-03-01 10:24 UTC (permalink / raw)
To: Xen-devel; +Cc: Wei Liu, Ian Jackson
Copy the one in libxl, remove the irrelevant bits about libxl. Replace
libxl with xl where appropriate.
Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
tools/xl/CODING_STYLE | 203 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 203 insertions(+)
create mode 100644 tools/xl/CODING_STYLE
diff --git a/tools/xl/CODING_STYLE b/tools/xl/CODING_STYLE
new file mode 100644
index 0000000000..27ba5b8c84
--- /dev/null
+++ b/tools/xl/CODING_STYLE
@@ -0,0 +1,203 @@
+XL CODING STYLE
+========================
+
+
+AN APOLOGY AND WARNING
+----------------------
+
+Much of the code in xl does not yet follow this coding style
+document in every respect. However, new code is expected to conform.
+
+Patches to improve the style of existing code are welcome. Please
+separate these out from functional changes.
+
+If it is not feasible to conform fully to the style while patching old
+code, without doing substantial style reengineering first, we may
+accept patches which contain nonconformant elements, provided that
+they don't make the coding style problem worse overall.
+
+In this case, the new code should conform to the prevailing style in
+the area being touched.
+
+ERROR HANDLING
+--------------
+
+Unless, there are good reasons to do otherwise, the following error
+handling and cleanup paradigm should be used:
+
+ * All local variables referring to resources which might need
+ cleaning up are declared at the top of the function, and
+ initialised to a sentinel value indicating "nothing allocated".
+ For example,
+ libxl_evgen_disk_eject *evg = NULL;
+ int nullfd = -1;
+
+ * If the function is to return a libxl error value, `rc' is
+ used to contain the error code, but it is NOT initialised:
+ int rc;
+
+ * There is only one error cleanup path out of the function. It
+ starts with a label `out:'. That error cleanup path checks for
+ each allocated resource and frees it iff necessary. It then
+ returns rc. For example,
+ out:
+ if (evg) libxl__evdisable_disk_eject(gc, evg);
+ if (nullfd >= 0) close(nullfd);
+ return rc;
+
+ * Function calls which might fail (ie most function calls) are
+ handled by putting the return/status value into a variable, and
+ then checking it in a separate statement:
+ char *dompath = libxl__xs_get_dompath(gc, bl->domid);
+ if (!dompath) { rc = ERROR_FAIL; goto out; }
+
+ * If a resource is freed in the main body of the function (for
+ example, in a loop), the corresponding variable has to be reset to
+ the sentinel at the point where it's freed.
+
+Whether to use the `out' path for successful returns as well as error
+returns is a matter of taste and convenience for the specific
+function.
+
+If you reuse the `out' path for successful returns, there may be
+resources which are to be returned to the caller rather than freed.
+In that case you have to reset the local variable to `nothing here',
+to avoid the resource being freed on the out path. That resetting
+should be done immediately after the resource value is stored at the
+applicable _r function parameter (or equivalent). Do not test `rc' in
+the out section, to discover whether to free things.
+
+The uses of the single-line formatting in the examples above are
+permitted exceptions to the usual xl code formatting rules.
+
+FORMATTING AND NAMING
+---------------------
+
+Blatantly copied from qemu and linux with few modifications.
+
+
+1. Whitespace
+
+Of course, the most important aspect in any coding style is whitespace.
+Crusty old coders who have trouble spotting the glasses on their noses
+can tell the difference between a tab and eight spaces from a distance
+of approximately fifteen parsecs. Many a flamewar have been fought and
+lost on this issue.
+
+Libxenlight indents are four spaces. Tabs are never used, except in
+Makefiles where they have been irreversibly coded into the syntax.
+Spaces of course are superior to tabs because:
+
+ - You have just one way to specify whitespace, not two. Ambiguity breeds
+ mistakes.
+ - The confusion surrounding 'use tabs to indent, spaces to justify' is gone.
+ - Tab indents push your code to the right, making your screen seriously
+ unbalanced.
+ - Tabs will be rendered incorrectly on editors who are misconfigured not
+ to use tab stops of eight positions.
+ - Tabs are rendered badly in patches, causing off-by-one errors in almost
+ every line.
+ - It is the libxenlight coding style.
+
+Do not leave whitespace dangling off the ends of lines.
+
+
+2. Line width
+
+Lines are limited to 75-80 characters.
+
+Rationale:
+ - Some people like to tile their 24" screens with a 6x4 matrix of 80x24
+ xterms and use vi in all of them. The best way to punish them is to
+ let them keep doing it.
+ - Code and especially patches is much more readable if limited to a sane
+ line length. Eighty is traditional.
+ - It is the libxenlight coding style.
+
+
+3. Naming
+
+C is a Spartan language, and so should your naming be. Unlike Modula-2
+and Pascal programmers, C programmers do not use cute names like
+ThisVariableIsATemporaryCounter. A C programmer would call that
+variable "tmp", which is much easier to write, and not the least more
+difficult to understand.
+
+HOWEVER, while mixed-case names are frowned upon, descriptive names for
+global variables are a must. To call a global function "foo" is a
+shooting offense.
+
+GLOBAL variables (to be used only if you _really_ need them) need to
+have descriptive names, as do global functions. If you have a function
+that counts the number of active users, you should call that
+"count_active_users()" or similar, you should _not_ call it "cntusr()".
+
+Encoding the type of a function into the name (so-called Hungarian
+notation) is brain damaged - the compiler knows the types anyway and can
+check those, and it only confuses the programmer.
+
+LOCAL variable names should be short, and to the point. If you have
+some random integer loop counter, it should probably be called "i".
+Calling it "loop_counter" is non-productive, if there is no chance of it
+being mis-understood. Similarly, "tmp" can be just about any type of
+variable that is used to hold a temporary value.
+
+Local variables used to store return values should have descriptive name
+like "rc" or "ret". Following the same reasoning the label used as exit
+path should be called "out".
+
+Function arguments which are used to return values to the caller
+should be suffixed `_r' or `_out'.
+
+Variables, type names and function names are
+lower_case_with_underscores.
+Xl should avoid using libxl_ and libxl__ as prefix for its own function
+names.
+
+4. Statements
+
+Don't put multiple statements on a single line.
+Don't put multiple assignments on a single line either.
+Error code paths with an if statement and a goto or a return on the same
+line are allowed. Examples:
+
+ if (rc) goto out;
+ if (rc < 0) return;
+
+Xl coding style is super simple. Avoid tricky expressions.
+
+
+5. Block structure
+
+Every indented statement is braced, but blocks that contain just one
+statement may have the braces omitted. To avoid confusion, either all
+the blocks in an if...else chain have braces, or none of them do.
+
+The opening brace is on the line that contains the control flow
+statement that introduces the new block; the closing brace is on the
+same line as the else keyword, or on a line by itself if there is no
+else keyword. Examples:
+
+ if (a == 5) {
+ printf("a was 5.\n");
+ } else if (a == 6) {
+ printf("a was 6.\n");
+ } else {
+ printf("a was something else entirely.\n");
+ }
+
+ if (a == 5)
+ printf("a was 5.\n");
+
+An exception is the opening brace for a function; for reasons of tradition
+and clarity it comes on a line by itself:
+
+ void a_function(void)
+ {
+ do_something();
+ }
+
+Rationale: a consistent (except for functions...) bracing style reduces
+ambiguity and avoids needless churn when lines are added or removed.
+Furthermore, it is the libxenlight coding style.
+
--
2.11.0
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 3/5] xl: remove declaration of ctx in c files
2017-03-01 10:24 [PATCH 0/5] xl cleanup and docs Wei Liu
2017-03-01 10:24 ` [PATCH 1/5] CONTRIBUTING: list xl in inbound license section Wei Liu
2017-03-01 10:24 ` [PATCH 2/5] xl: add CODING_STYLE Wei Liu
@ 2017-03-01 10:24 ` Wei Liu
2017-03-01 10:24 ` [PATCH 4/5] xl: lift common_domname declaration to xl.h Wei Liu
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Wei Liu @ 2017-03-01 10:24 UTC (permalink / raw)
To: Xen-devel; +Cc: Wei Liu, Ian Jackson
There is already one in xl.h.
No functional change.
Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
tools/xl/xl_flask.c | 2 --
tools/xl/xl_vmcontrol.c | 1 -
2 files changed, 3 deletions(-)
diff --git a/tools/xl/xl_flask.c b/tools/xl/xl_flask.c
index 804165c6a8..523769750b 100644
--- a/tools/xl/xl_flask.c
+++ b/tools/xl/xl_flask.c
@@ -23,8 +23,6 @@
#include "xl.h"
-extern libxl_ctx *ctx;
-
int main_getenforce(int argc, char **argv)
{
int ret;
diff --git a/tools/xl/xl_vmcontrol.c b/tools/xl/xl_vmcontrol.c
index 9b9d55c481..a3f27ad786 100644
--- a/tools/xl/xl_vmcontrol.c
+++ b/tools/xl/xl_vmcontrol.c
@@ -30,7 +30,6 @@
#include "xl_utils.h"
#include "xl_parse.h"
-extern libxl_ctx *ctx;
extern int logfile;
extern const char *common_domname;
--
2.11.0
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 4/5] xl: lift common_domname declaration to xl.h
2017-03-01 10:24 [PATCH 0/5] xl cleanup and docs Wei Liu
` (2 preceding siblings ...)
2017-03-01 10:24 ` [PATCH 3/5] xl: remove declaration of ctx in c files Wei Liu
@ 2017-03-01 10:24 ` Wei Liu
2017-03-01 10:24 ` [PATCH 5/5] xl: lift logfile " Wei Liu
2017-03-02 12:56 ` [PATCH 0/5] xl cleanup and docs Ian Jackson
5 siblings, 0 replies; 7+ messages in thread
From: Wei Liu @ 2017-03-01 10:24 UTC (permalink / raw)
To: Xen-devel; +Cc: Wei Liu, Ian Jackson
No functional change.
Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
tools/xl/xl.h | 1 +
tools/xl/xl_migrate.c | 2 --
tools/xl/xl_misc.c | 2 --
tools/xl/xl_utils.c | 1 -
tools/xl/xl_vmcontrol.c | 1 -
5 files changed, 1 insertion(+), 6 deletions(-)
diff --git a/tools/xl/xl.h b/tools/xl/xl.h
index 65b89ce717..3869776395 100644
--- a/tools/xl/xl.h
+++ b/tools/xl/xl.h
@@ -210,6 +210,7 @@ int main_qemu_monitor_command(int argc, char **argv);
void help(const char *command);
+extern const char *common_domname;
extern struct cmd_spec cmd_table[];
extern int cmdtable_len;
/* Look up a command in the table, allowing unambiguous truncation */
diff --git a/tools/xl/xl_migrate.c b/tools/xl/xl_migrate.c
index 28fb8230b6..065bd66aea 100644
--- a/tools/xl/xl_migrate.c
+++ b/tools/xl/xl_migrate.c
@@ -30,8 +30,6 @@
#include "xl_utils.h"
#include "xl_parse.h"
-extern const char *common_domname;
-
#ifndef LIBXL_HAVE_NO_SUSPEND_RESUME
static pid_t create_migration_child(const char *rune, int *send_fd,
diff --git a/tools/xl/xl_misc.c b/tools/xl/xl_misc.c
index 70fcc3026b..9037e2b2f0 100644
--- a/tools/xl/xl_misc.c
+++ b/tools/xl/xl_misc.c
@@ -23,8 +23,6 @@
#include "xl_utils.h"
#include "xl_parse.h"
-extern const char *common_domname;
-
static void button_press(uint32_t domid, const char *b)
{
libxl_trigger trigger;
diff --git a/tools/xl/xl_utils.c b/tools/xl/xl_utils.c
index 481b7bb50f..f79f08029f 100644
--- a/tools/xl/xl_utils.c
+++ b/tools/xl/xl_utils.c
@@ -28,7 +28,6 @@
#include "xl_utils.h"
extern int logfile;
-extern const char *common_domname;
void dolog(const char *file, int line, const char *func, char *fmt, ...)
{
diff --git a/tools/xl/xl_vmcontrol.c b/tools/xl/xl_vmcontrol.c
index a3f27ad786..81a9af7705 100644
--- a/tools/xl/xl_vmcontrol.c
+++ b/tools/xl/xl_vmcontrol.c
@@ -31,7 +31,6 @@
#include "xl_parse.h"
extern int logfile;
-extern const char *common_domname;
static int fd_lock = -1;
--
2.11.0
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 5/5] xl: lift logfile declaration to xl.h
2017-03-01 10:24 [PATCH 0/5] xl cleanup and docs Wei Liu
` (3 preceding siblings ...)
2017-03-01 10:24 ` [PATCH 4/5] xl: lift common_domname declaration to xl.h Wei Liu
@ 2017-03-01 10:24 ` Wei Liu
2017-03-02 12:56 ` [PATCH 0/5] xl cleanup and docs Ian Jackson
5 siblings, 0 replies; 7+ messages in thread
From: Wei Liu @ 2017-03-01 10:24 UTC (permalink / raw)
To: Xen-devel; +Cc: Wei Liu, Ian Jackson
No functional change.
Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
tools/xl/xl.h | 1 +
tools/xl/xl_utils.c | 2 --
tools/xl/xl_vmcontrol.c | 2 --
3 files changed, 1 insertion(+), 4 deletions(-)
diff --git a/tools/xl/xl.h b/tools/xl/xl.h
index 3869776395..1ad07261f2 100644
--- a/tools/xl/xl.h
+++ b/tools/xl/xl.h
@@ -218,6 +218,7 @@ struct cmd_spec *cmdtable_lookup(const char *s);
extern libxl_ctx *ctx;
extern xentoollog_logger_stdiostream *logger;
+extern int logfile;
void xl_ctx_alloc(void);
diff --git a/tools/xl/xl_utils.c b/tools/xl/xl_utils.c
index f79f08029f..4503ac7ea0 100644
--- a/tools/xl/xl_utils.c
+++ b/tools/xl/xl_utils.c
@@ -27,8 +27,6 @@
#include "xl.h"
#include "xl_utils.h"
-extern int logfile;
-
void dolog(const char *file, int line, const char *func, char *fmt, ...)
{
va_list ap;
diff --git a/tools/xl/xl_vmcontrol.c b/tools/xl/xl_vmcontrol.c
index 81a9af7705..0ad6e0bcbb 100644
--- a/tools/xl/xl_vmcontrol.c
+++ b/tools/xl/xl_vmcontrol.c
@@ -30,8 +30,6 @@
#include "xl_utils.h"
#include "xl_parse.h"
-extern int logfile;
-
static int fd_lock = -1;
static void pause_domain(uint32_t domid)
--
2.11.0
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 0/5] xl cleanup and docs
2017-03-01 10:24 [PATCH 0/5] xl cleanup and docs Wei Liu
` (4 preceding siblings ...)
2017-03-01 10:24 ` [PATCH 5/5] xl: lift logfile " Wei Liu
@ 2017-03-02 12:56 ` Ian Jackson
5 siblings, 0 replies; 7+ messages in thread
From: Ian Jackson @ 2017-03-02 12:56 UTC (permalink / raw)
To: Wei Liu; +Cc: Xen-devel
Wei Liu writes ("[PATCH 0/5] xl cleanup and docs"):
> Wei Liu (5):
> CONTRIBUTING: list xl in inbound license section
> xl: add CODING_STYLE
> xl: remove declaration of ctx in c files
> xl: lift common_domname declaration to xl.h
> xl: lift logfile declaration to xl.h
All five
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2017-03-02 12:56 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-03-01 10:24 [PATCH 0/5] xl cleanup and docs Wei Liu
2017-03-01 10:24 ` [PATCH 1/5] CONTRIBUTING: list xl in inbound license section Wei Liu
2017-03-01 10:24 ` [PATCH 2/5] xl: add CODING_STYLE Wei Liu
2017-03-01 10:24 ` [PATCH 3/5] xl: remove declaration of ctx in c files Wei Liu
2017-03-01 10:24 ` [PATCH 4/5] xl: lift common_domname declaration to xl.h Wei Liu
2017-03-01 10:24 ` [PATCH 5/5] xl: lift logfile " Wei Liu
2017-03-02 12:56 ` [PATCH 0/5] xl cleanup and docs Ian Jackson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).