[Devel] Self-comment code

Kir Kolyshkin kir at openvz.org
Sun Apr 28 22:15:08 PDT 2013


On 04/28/2013 08:31 PM, Igor Podlesny wrote:
> ---
>   src/lib/fs_simfs.c |   13 +++++++------
>   1 file changed, 7 insertions(+), 6 deletions(-)
>
> diff --git a/src/lib/fs_simfs.c b/src/lib/fs_simfs.c
> index bc4bf9f..438c1f1 100644
> --- a/src/lib/fs_simfs.c
> +++ b/src/lib/fs_simfs.c
> @@ -31,34 +31,35 @@
>   
>   int vps_is_mounted(const char *root, const char *private)
>   {
> -	struct stat st1, st2;
> +	struct stat st_root, st_parent;
>   	char parent[PATH_MAX];
>   
>   	if (!root || !private)
>   		return -1;
>   
> -	if (stat(root, &st1)) {
> +	if (stat(root, &st_root)) {
>   		logger(-1, errno, "stat(%s)", root);
>   		return -1;
>   	}
>   
>   	snprintf(parent, sizeof(parent), "%s/..", root);
> -	if (stat(parent, &st2)) {
> +	if (stat(parent, &st_parent)) {
>   		logger(-1, errno, "stat(%s)", parent);
>   		return -1;
>   	}
>   
>   	/* Check for real mount (simfs or ploop) */
> -	if (st1.st_dev != st2.st_dev)
> +	if (st_root.st_dev != st_parent.st_dev)
>   		return 1;

This "self-comment" thing works just fine so far.
>   
>   	/* Check for bind mount (upstream case) */
> -	if (stat(private, &st2)) {
> +	if (stat(private, &st_parent)) {

oops

>   		logger(-1, errno, "stat(%s)", private);
>   		return -1;
>   	}
>   
> -	return (st1.st_dev == st2.st_dev) && (st1.st_ino == st2.st_ino);
> +	return (st_root.st_dev == st_parent.st_dev) &&
> +		(st_root.st_ino == st_parent.st_ino);
>   }

As you see, this is no longer "st_parent" but rather "st_private",
so you are actually confusing reviewers by calling it st_parent
(and it was kinda OK before when we were calling it st2).

Feel free to redo this patch with three variables declared if you like,
compiler should optimize it away anyway.
>   
>   static char *fs_name = "simfs";




More information about the Devel mailing list